Skip to content

Commit 175a19a

Browse files
authored
Improve handling of package.json and other hidden files in Playground (#461)
* Bump Playground and handle "hidden" correctly on save * Fix styles casting bug in example
1 parent 584049b commit 175a19a

File tree

9 files changed

+383
-505
lines changed

9 files changed

+383
-505
lines changed

packages/lit-dev-api/package-lock.json

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lit-dev-content/package-lock.json

Lines changed: 213 additions & 253 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/lit-dev-content/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
"lit": "^2.0.0-pre.1",
6161
"lit-element": "^2.3.1",
6262
"lit-html": "^1.2.1",
63-
"playground-elements": "^0.12.0",
63+
"playground-elements": "^0.12.1",
6464
"tarts": "^1.0.0",
6565
"tslib": "^2.2.0"
6666
}

packages/lit-dev-content/samples/base.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"files": {
33
"package.json": {
4-
"content": "{\"dependencies\":{\"lit\":\"^2.0.0-rc.2\",\"@lit/reactive-element\":\"^1.0.0-rc.2\",\"lit-element\":\"^3.0.0-rc.2\",\"lit-html\":\"^2.0.0-rc.3\"}}",
4+
"content": "{\n \"dependencies\": {\n \"lit\": \"^2.0.0-rc.2\",\n \"@lit/reactive-element\": \"^1.0.0-rc.2\",\n \"lit-element\": \"^3.0.0-rc.2\",\n \"lit-html\": \"^2.0.0-rc.3\"\n }\n}",
55
"hidden": true
66
}
77
}

packages/lit-dev-content/samples/docs/components/style/superstyles/super-element.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {LitElement, html, css} from 'lit';
1+
import {LitElement, html, css, CSSResultGroup} from 'lit';
22
import {customElement} from 'lit/decorators.js';
33

44
@customElement('super-element')
@@ -8,7 +8,7 @@ export class SuperElement extends LitElement {
88
border: 1px solid gray;
99
padding: 8px;
1010
}
11-
`;
11+
` as CSSResultGroup;
1212
protected render() {
1313
return html`
1414
<div>Content</div>

packages/lit-dev-content/src/pages/playground.ts

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ import 'playground-elements/playground-ide.js';
1111
import Tar from 'tarts';
1212
import {Snackbar} from '@material/mwc-snackbar';
1313

14+
interface CompactProjectFile {
15+
name: string;
16+
content: string;
17+
hidden?: true;
18+
}
19+
1420
// TODO(aomarks) This whole thing should probably be a custom element.
1521
window.addEventListener('DOMContentLoaded', () => {
1622
/**
@@ -67,13 +73,23 @@ window.addEventListener('DOMContentLoaded', () => {
6773
const shareSnackbar = $('#shareSnackbar')! as Snackbar;
6874

6975
const share = async () => {
70-
// No need to include contentType (inferred) or undefined label (unused).
71-
const files = Object.entries(project.config?.files ?? {}).map(
72-
([name, file]) => ({
76+
const files = [];
77+
for (const [name, {content, hidden}] of Object.entries(
78+
project.config?.files ?? {}
79+
)) {
80+
// We don't directly encode the Playground project's files data structure
81+
// because we want something more compact to reduce URL bloat. There's no
82+
// need to include contentType (will be inferred from filename) or labels
83+
// (unused), and hidden should be omitted instead of false.
84+
const compactFile: CompactProjectFile = {
7385
name,
74-
content: file.content,
75-
})
76-
);
86+
content: content ?? '',
87+
};
88+
if (hidden) {
89+
compactFile.hidden = true;
90+
}
91+
files.push(compactFile);
92+
}
7793
const base64 = encodeSafeBase64(JSON.stringify(files));
7894
window.location.hash = '#project=' + base64;
7995
await navigator.clipboard.writeText(window.location.toString());
@@ -101,7 +117,7 @@ window.addEventListener('DOMContentLoaded', () => {
101117
const hash = window.location.hash;
102118
const params = new URLSearchParams(hash.slice(1));
103119

104-
let urlFiles: Array<{name: string; content: string}> | undefined;
120+
let urlFiles: Array<CompactProjectFile> | undefined;
105121
const base64 = params.get('project');
106122
if (base64) {
107123
try {
@@ -122,7 +138,7 @@ window.addEventListener('DOMContentLoaded', () => {
122138
project.config = {
123139
extends: '/samples/base.json',
124140
files: Object.fromEntries(
125-
urlFiles.map(({name, content}) => [name, {content}])
141+
urlFiles.map(({name, content, hidden}) => [name, {content, hidden}])
126142
),
127143
};
128144
} else {

packages/lit-dev-server/package-lock.json

Lines changed: 21 additions & 72 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)