@jxsuite/studio 0.19.0 → 0.20.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/dist/studio.css +98 -98
  2. package/dist/studio.js +12577 -12183
  3. package/dist/studio.js.map +146 -144
  4. package/dist/workers/editor.worker.js +79 -79
  5. package/dist/workers/json.worker.js +109 -109
  6. package/dist/workers/ts.worker.js +82 -82
  7. package/package.json +17 -6
  8. package/src/browse/browse.js +25 -19
  9. package/src/canvas/canvas-diff.js +24 -16
  10. package/src/canvas/canvas-helpers.js +24 -19
  11. package/src/canvas/canvas-live-render.js +94 -39
  12. package/src/canvas/canvas-render.js +119 -73
  13. package/src/canvas/canvas-utils.js +38 -15
  14. package/src/canvas/nested-site-style.js +50 -0
  15. package/src/editor/component-inline-edit.js +14 -13
  16. package/src/editor/content-inline-edit.js +22 -10
  17. package/src/editor/context-menu.js +1 -1
  18. package/src/editor/convert-to-component.js +12 -10
  19. package/src/editor/inline-edit.js +66 -28
  20. package/src/editor/insertion-helper.js +16 -12
  21. package/src/editor/shortcuts.js +4 -2
  22. package/src/editor/slash-menu.js +6 -4
  23. package/src/files/components.js +1 -1
  24. package/src/files/file-ops.js +37 -16
  25. package/src/files/files.js +78 -52
  26. package/src/github/github-auth.js +122 -0
  27. package/src/github/github-publish.js +115 -0
  28. package/src/markdown/md-convert.js +172 -107
  29. package/src/new-project/new-project-modal.js +204 -0
  30. package/src/panels/activity-bar.js +22 -20
  31. package/src/panels/ai-panel.js +399 -0
  32. package/src/panels/block-action-bar.js +5 -5
  33. package/src/panels/canvas-dnd.js +8 -2
  34. package/src/panels/data-explorer.js +19 -13
  35. package/src/panels/dnd.js +144 -92
  36. package/src/panels/editors.js +55 -35
  37. package/src/panels/elements-panel.js +33 -19
  38. package/src/panels/events-panel.js +15 -10
  39. package/src/panels/git-panel.js +469 -98
  40. package/src/panels/head-panel.js +121 -81
  41. package/src/panels/imports-panel.js +88 -64
  42. package/src/panels/layers-panel.js +64 -43
  43. package/src/panels/left-panel.js +85 -47
  44. package/src/panels/overlays.js +1 -0
  45. package/src/panels/panel-events.js +45 -30
  46. package/src/panels/preview-render.js +23 -18
  47. package/src/panels/properties-panel.js +365 -249
  48. package/src/panels/pseudo-preview.js +2 -2
  49. package/src/panels/quick-search.js +7 -5
  50. package/src/panels/right-panel.js +26 -2
  51. package/src/panels/shared.js +4 -4
  52. package/src/panels/signals-panel.js +295 -166
  53. package/src/panels/statusbar.js +4 -4
  54. package/src/panels/style-inputs.js +67 -35
  55. package/src/panels/style-panel.js +233 -132
  56. package/src/panels/style-utils.js +34 -16
  57. package/src/panels/stylebook-layers-panel.js +12 -10
  58. package/src/panels/stylebook-panel.js +134 -66
  59. package/src/panels/toolbar.js +333 -109
  60. package/src/panels/welcome-screen.js +121 -0
  61. package/src/platform.js +2 -4
  62. package/src/platforms/devserver.js +113 -7
  63. package/src/resize-edges.js +98 -0
  64. package/src/services/cem-export.js +12 -7
  65. package/src/services/code-services.js +30 -12
  66. package/src/settings/content-types-editor.js +7 -7
  67. package/src/settings/css-vars-editor.js +30 -24
  68. package/src/settings/defs-editor.js +12 -7
  69. package/src/settings/general-settings.js +85 -3
  70. package/src/settings/head-editor.js +30 -24
  71. package/src/settings/schema-field-ui.js +58 -39
  72. package/src/site-context.js +41 -31
  73. package/src/state.js +70 -29
  74. package/src/store.js +21 -26
  75. package/src/studio.js +103 -81
  76. package/src/tabs/tab.js +67 -43
  77. package/src/tabs/transact.js +23 -13
  78. package/src/ui/button-group.js +24 -24
  79. package/src/ui/color-selector.js +28 -23
  80. package/src/ui/field-row.js +3 -3
  81. package/src/ui/icons.js +2 -2
  82. package/src/ui/media-picker.js +7 -7
  83. package/src/ui/spectrum.js +5 -1
  84. package/src/ui/unit-selector.js +18 -16
  85. package/src/ui/value-selector.js +21 -15
  86. package/src/ui/widgets.js +22 -19
  87. package/src/utils/canvas-media.js +5 -4
  88. package/src/utils/edit-display.js +31 -20
  89. package/src/utils/google-fonts.js +11 -11
  90. package/src/utils/inherited-style.js +9 -8
  91. package/src/utils/studio-utils.js +7 -7
  92. package/src/view.js +58 -1
  93. package/src/workspace/workspace.js +10 -7
@@ -3,6 +3,8 @@
3
3
  * completion provider for state scope variables.
4
4
  */
5
5
 
6
+ /** @typedef {import("../services/code-services.js").OxLintDiagnostic} OxLintDiagnostic */
7
+
6
8
  import * as monaco from "monaco-editor/esm/vs/editor/editor.api.js";
7
9
  import { html, render as litRender, nothing } from "lit-html";
8
10
  import { ref } from "lit-html/directives/ref.js";
@@ -13,12 +15,15 @@ import { transactDoc, mutateUpdateDef, mutateUpdateProperty } from "../tabs/tran
13
15
  import { view } from "../view.js";
14
16
  import { codeService, setLintMarkers, getFunctionArgs } from "../services/code-services.js";
15
17
 
16
- function getFunctionBody(/** @type {any} */ editing) {
18
+ /** @typedef {{ type: "def"; defName: string } | { type: "event"; path: JxPath; eventKey: string }} EditingTarget */
19
+
20
+ /** @param {EditingTarget | null | undefined} editing */
21
+ function getFunctionBody(editing) {
17
22
  const document = activeTab.value?.doc.document;
18
- if (editing.type === "def") {
23
+ if (editing?.type === "def") {
19
24
  return document?.state?.[editing.defName]?.body || "";
20
- } else if (editing.type === "event") {
21
- const node = getNodeAtPath(document, editing.path);
25
+ } else if (editing?.type === "event") {
26
+ const node = getNodeAtPath(/** @type {JxMutableNode} */ (document), editing.path);
22
27
  return node?.[editing.eventKey]?.body || "";
23
28
  }
24
29
  return "";
@@ -26,7 +31,9 @@ function getFunctionBody(/** @type {any} */ editing) {
26
31
 
27
32
  /** @param {() => void} closeFunctionEditor */
28
33
  export function renderFunctionEditor(closeFunctionEditor) {
29
- const editing = activeTab.value?.session.ui.editingFunction;
34
+ const editing = /** @type {EditingTarget | null | undefined} */ (
35
+ activeTab.value?.session.ui.editingFunction
36
+ );
30
37
 
31
38
  // If editor already exists and matches current target, just sync value
32
39
  if (view.functionEditor && view.functionEditor._editingTarget === JSON.stringify(editing)) {
@@ -66,7 +73,7 @@ export function renderFunctionEditor(closeFunctionEditor) {
66
73
 
67
74
  const tab = activeTab.value;
68
75
  const docName = tab?.documentPath?.split("/").pop() || tab?.doc.document?.tagName || "document";
69
- const ed = /** @type {any} */ (editing);
76
+ const ed = /** @type {EditingTarget} */ (editing);
70
77
  const funcLabel = ed.type === "def" ? `ƒ ${ed.defName}` : `ƒ ${ed.eventKey}`;
71
78
 
72
79
  // Editor container
@@ -94,22 +101,29 @@ export function renderFunctionEditor(closeFunctionEditor) {
94
101
  );
95
102
 
96
103
  const body = getFunctionBody(editing);
97
- const args = getFunctionArgs(editing, activeTab.value?.doc.document);
98
-
99
- view.functionEditor = monaco.editor.create(/** @type {any} */ (editorContainer), {
100
- value: body,
101
- language: "javascript",
102
- theme: "vs-dark",
103
- automaticLayout: true,
104
- minimap: { enabled: false },
105
- fontSize: 12,
106
- fontFamily: "'SF Mono', 'Fira Code', 'Consolas', monospace",
107
- lineNumbers: "on",
108
- scrollBeyondLastLine: false,
109
- wordWrap: "on",
110
- tabSize: 2,
111
- });
104
+ const args = getFunctionArgs(
105
+ /** @type {EditingTarget} */ (editing),
106
+ activeTab.value?.doc.document,
107
+ );
108
+
109
+ view.functionEditor = monaco.editor.create(
110
+ /** @type {HTMLElement} */ (/** @type {unknown} */ (editorContainer)),
111
+ {
112
+ value: body,
113
+ language: "javascript",
114
+ theme: "vs-dark",
115
+ automaticLayout: true,
116
+ minimap: { enabled: false },
117
+ fontSize: 12,
118
+ fontFamily: "'SF Mono', 'Fira Code', 'Consolas', monospace",
119
+ lineNumbers: "on",
120
+ scrollBeyondLastLine: false,
121
+ wordWrap: "on",
122
+ tabSize: 2,
123
+ },
124
+ );
112
125
  view.functionEditor._editingTarget = JSON.stringify(editing);
126
+ const editor = view.functionEditor;
113
127
 
114
128
  // Format on open — show pretty-printed code, then run initial lint
115
129
  codeService("format", { code: body, args }).then((result) => {
@@ -120,29 +134,32 @@ export function renderFunctionEditor(closeFunctionEditor) {
120
134
  });
121
135
  codeService("lint", { code: body, args }).then((result) => {
122
136
  if (result?.diagnostics && view.functionEditor)
123
- setLintMarkers(view.functionEditor, result.diagnostics);
137
+ setLintMarkers(view.functionEditor, /** @type {OxLintDiagnostic[]} */ (result.diagnostics));
124
138
  });
125
139
 
126
140
  // Debounced sync back to state + lint on edit
127
- /** @type {any} */
141
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
128
142
  let syncDebounce;
129
- /** @type {any} */
143
+ /** @type {ReturnType<typeof setTimeout> | undefined} */
130
144
  let lintDebounce;
131
145
  let lintGen = 0;
132
- view.functionEditor.onDidChangeModelContent(() => {
133
- if (view.functionEditor._ignoreNextChange) {
134
- view.functionEditor._ignoreNextChange = false;
146
+ editor.onDidChangeModelContent(() => {
147
+ if (editor._ignoreNextChange) {
148
+ editor._ignoreNextChange = false;
135
149
  return;
136
150
  }
137
151
 
138
152
  clearTimeout(syncDebounce);
139
153
  syncDebounce = setTimeout(() => {
140
- const newBody = view.functionEditor.getValue();
141
- const ed = /** @type {any} */ (editing);
154
+ const newBody = editor.getValue();
155
+ const ed = /** @type {EditingTarget} */ (editing);
142
156
  if (ed.type === "def") {
143
157
  transactDoc(activeTab.value, (t) => mutateUpdateDef(t, ed.defName, { body: newBody }));
144
158
  } else if (ed.type === "event") {
145
- const node = getNodeAtPath(activeTab.value?.doc.document, ed.path);
159
+ const node = getNodeAtPath(
160
+ /** @type {JxMutableNode} */ (activeTab.value?.doc.document),
161
+ ed.path,
162
+ );
146
163
  const current = node?.[ed.eventKey] || {};
147
164
  transactDoc(activeTab.value, (t) =>
148
165
  mutateUpdateProperty(t, ed.path, ed.eventKey, {
@@ -158,11 +175,14 @@ export function renderFunctionEditor(closeFunctionEditor) {
158
175
  clearTimeout(lintDebounce);
159
176
  lintDebounce = setTimeout(() => {
160
177
  const gen = ++lintGen;
161
- const currentCode = view.functionEditor.getValue();
178
+ const currentCode = editor.getValue();
162
179
  codeService("lint", { code: currentCode, args }).then((result) => {
163
180
  if (gen !== lintGen) return;
164
181
  if (result?.diagnostics && view.functionEditor)
165
- setLintMarkers(view.functionEditor, result.diagnostics);
182
+ setLintMarkers(
183
+ view.functionEditor,
184
+ /** @type {OxLintDiagnostic[]} */ (result.diagnostics),
185
+ );
166
186
  });
167
187
  }, 750);
168
188
  });
@@ -187,11 +207,11 @@ export function registerFunctionCompletions() {
187
207
  const suggestions = Object.entries(defs).map(([key, def]) => {
188
208
  let kind = monaco.languages.CompletionItemKind.Variable;
189
209
  if (
190
- /** @type {any} */ (def)?.$prototype === "Function" ||
191
- /** @type {any} */ (def)?.$handler
210
+ /** @type {JxPrototypeDef} */ (def)?.$prototype === "Function" ||
211
+ /** @type {{ $handler?: unknown }} */ (def)?.$handler
192
212
  )
193
213
  kind = monaco.languages.CompletionItemKind.Function;
194
- else if (/** @type {any} */ (def)?.$prototype)
214
+ else if (/** @type {JxPrototypeDef} */ (def)?.$prototype)
195
215
  kind = monaco.languages.CompletionItemKind.Property;
196
216
  return {
197
217
  label: `state.${key}`,
@@ -8,17 +8,23 @@ import { view } from "../view.js";
8
8
  import { getEffectiveElements } from "../site-context.js";
9
9
  import { componentRegistry } from "../files/components.js";
10
10
 
11
+ /** @typedef {import("../files/components.js").ComponentEntry} ComponentEntry */
12
+
11
13
  /**
12
- * @param {{ webdata: any; defaultDef: (tag: string) => any; rerender: () => void }} ctx
14
+ * @param {{
15
+ * webdata: { elements: Record<string, { tag: string }[]> };
16
+ * defaultDef: (tag: string) => JxMutableNode;
17
+ * rerender: () => void;
18
+ * }} ctx
13
19
  * @returns {import("lit-html").TemplateResult}
14
20
  */
15
21
  export function renderElementsTemplate(ctx) {
16
22
  const tab = activeTab.value;
17
23
 
18
24
  const categories = Object.entries(ctx.webdata.elements).map(
19
- (/** @type {any} */ [category, elements]) => {
25
+ (/** @type {[string, { tag: string }[]]} */ [category, elements]) => {
20
26
  const filtered = view.elementsFilter
21
- ? elements.filter((/** @type {any} */ e) => e.tag.includes(view.elementsFilter))
27
+ ? elements.filter((/** @type {{ tag: string }} */ e) => e.tag.includes(view.elementsFilter))
22
28
  : elements;
23
29
  if (filtered.length === 0) return nothing;
24
30
 
@@ -26,12 +32,13 @@ export function renderElementsTemplate(ctx) {
26
32
  <sp-accordion-item
27
33
  label=${category}
28
34
  ?open=${!view.elementsCollapsed.has(category)}
29
- @sp-accordion-item-toggle=${(/** @type {any} */ e) => {
30
- if (e.target.open) view.elementsCollapsed.delete(category);
35
+ @sp-accordion-item-toggle=${(/** @type {Event} */ e) => {
36
+ if (/** @type {HTMLElement & { open: boolean }} */ (e.target).open)
37
+ view.elementsCollapsed.delete(category);
31
38
  else view.elementsCollapsed.add(category);
32
39
  }}
33
40
  >
34
- ${filtered.map((/** @type {any} */ { tag }) => {
41
+ ${filtered.map((/** @type {{ tag: string }} */ { tag }) => {
35
42
  const def = ctx.defaultDef(tag);
36
43
  return html`
37
44
  <div
@@ -57,13 +64,15 @@ export function renderElementsTemplate(ctx) {
57
64
  },
58
65
  );
59
66
 
60
- const effectiveEls = getEffectiveElements(tab?.doc.document?.$elements);
67
+ const effectiveEls = getEffectiveElements(
68
+ /** @type {(string | JxElement)[] | undefined} */ (tab?.doc.document?.$elements),
69
+ );
61
70
  /** @type {Set<string>} */
62
71
  const enabledTags = new Set();
63
72
  for (const entry of effectiveEls) {
64
73
  if (typeof entry !== "string") continue;
65
74
  const comp = componentRegistry.find(
66
- (/** @type {any} */ c) =>
75
+ (/** @type {ComponentEntry} */ c) =>
67
76
  c.source === "npm" && c.modulePath && entry === `${c.package}/${c.modulePath}`,
68
77
  );
69
78
  if (comp) {
@@ -77,9 +86,11 @@ export function renderElementsTemplate(ctx) {
77
86
  const compsFiltered =
78
87
  componentRegistry.length > 0
79
88
  ? componentRegistry
80
- .filter((/** @type {any} */ c) => c.source !== "npm" || enabledTags.has(c.tagName))
81
89
  .filter(
82
- (/** @type {any} */ c) =>
90
+ (/** @type {ComponentEntry} */ c) => c.source !== "npm" || enabledTags.has(c.tagName),
91
+ )
92
+ .filter(
93
+ (/** @type {ComponentEntry} */ c) =>
83
94
  !view.elementsFilter || c.tagName.toLowerCase().includes(view.elementsFilter),
84
95
  )
85
96
  : [];
@@ -90,14 +101,15 @@ export function renderElementsTemplate(ctx) {
90
101
  <sp-accordion-item
91
102
  label="Components"
92
103
  ?open=${!view.elementsCollapsed.has("Components")}
93
- @sp-accordion-item-toggle=${(/** @type {any} */ e) => {
94
- if (e.target.open) view.elementsCollapsed.delete("Components");
104
+ @sp-accordion-item-toggle=${(/** @type {Event} */ e) => {
105
+ if (/** @type {HTMLElement & { open: boolean }} */ (e.target).open)
106
+ view.elementsCollapsed.delete("Components");
95
107
  else view.elementsCollapsed.add("Components");
96
108
  }}
97
109
  >
98
110
  <div class="components-section">
99
111
  ${compsFiltered.map(
100
- (/** @type {any} */ comp) => html`
112
+ (/** @type {ComponentEntry} */ comp) => html`
101
113
  <div
102
114
  class="element-card"
103
115
  data-component-tag=${comp.tagName}
@@ -112,10 +124,12 @@ export function renderElementsTemplate(ctx) {
112
124
  const instanceDef = {
113
125
  tagName: comp.tagName,
114
126
  $props: Object.fromEntries(
115
- (comp.props || []).map((/** @type {any} */ p) => [
116
- p.name,
117
- p.default !== undefined ? p.default : "",
118
- ]),
127
+ (comp.props || []).map(
128
+ (/** @type {{ name: string; default?: unknown }} */ p) => [
129
+ p.name,
130
+ p.default !== undefined ? p.default : "",
131
+ ],
132
+ ),
119
133
  ),
120
134
  };
121
135
  transactDoc(t, (tr) =>
@@ -142,8 +156,8 @@ export function renderElementsTemplate(ctx) {
142
156
  size="s"
143
157
  placeholder="Filter elements…"
144
158
  value=${view.elementsFilter}
145
- @input=${(/** @type {any} */ e) => {
146
- view.elementsFilter = e.target.value.toLowerCase();
159
+ @input=${(/** @type {Event} */ e) => {
160
+ view.elementsFilter = /** @type {HTMLInputElement} */ (e.target).value.toLowerCase();
147
161
  ctx.rerender();
148
162
  }}
149
163
  ></sp-search>
@@ -33,7 +33,7 @@ export function eventsSidebarTemplate(helpers) {
33
33
  );
34
34
 
35
35
  // Declared CEM events (custom element docs)
36
- /** @type {any} */
36
+ /** @type {unknown} */
37
37
  let declaredEventsT = nothing;
38
38
  if (isCustomElementDoc()) {
39
39
  const allEmits = [];
@@ -86,8 +86,8 @@ export function eventsSidebarTemplate(helpers) {
86
86
  size="s"
87
87
  class="event-name"
88
88
  .value=${live(evKey)}
89
- @change=${(/** @type {any} */ e) => {
90
- const newKey = e.target.value;
89
+ @change=${(/** @type {Event} */ e) => {
90
+ const newKey = /** @type {HTMLInputElement} */ (e.target).value;
91
91
  if (newKey && newKey !== evKey) {
92
92
  transactDoc(activeTab.value, (t) => {
93
93
  mutateUpdateProperty(t, selection, evKey, undefined);
@@ -104,8 +104,8 @@ export function eventsSidebarTemplate(helpers) {
104
104
  size="s"
105
105
  class="event-mode"
106
106
  .value=${live(isInline ? "inline" : "ref")}
107
- @change=${(/** @type {any} */ e) => {
108
- if (e.target.value === "inline") {
107
+ @change=${(/** @type {Event} */ e) => {
108
+ if (/** @type {HTMLInputElement} */ (e.target).value === "inline") {
109
109
  transactDoc(activeTab.value, (t) =>
110
110
  mutateUpdateProperty(t, selection, evKey, {
111
111
  $prototype: "Function",
@@ -149,11 +149,11 @@ export function eventsSidebarTemplate(helpers) {
149
149
  grows
150
150
  placeholder="// handler body"
151
151
  .value=${live(evVal.body || "")}
152
- @input=${(/** @type {any} */ e) => {
152
+ @input=${(/** @type {Event} */ e) => {
153
153
  transactDoc(activeTab.value, (t) =>
154
154
  mutateUpdateProperty(t, selection, evKey, {
155
155
  $prototype: "Function",
156
- body: e.target.value,
156
+ body: /** @type {HTMLInputElement} */ (e.target).value,
157
157
  parameters: evVal.parameters || [],
158
158
  }),
159
159
  );
@@ -181,10 +181,15 @@ export function eventsSidebarTemplate(helpers) {
181
181
  size="s"
182
182
  class="event-handler"
183
183
  .value=${live(evVal.$ref || "__none__")}
184
- @change=${(/** @type {any} */ e) => {
185
- if (e.target.value && e.target.value !== "__none__") {
184
+ @change=${(/** @type {Event} */ e) => {
185
+ if (
186
+ /** @type {HTMLInputElement} */ (e.target).value &&
187
+ /** @type {HTMLInputElement} */ (e.target).value !== "__none__"
188
+ ) {
186
189
  transactDoc(activeTab.value, (t) =>
187
- mutateUpdateProperty(t, selection, evKey, { $ref: e.target.value }),
190
+ mutateUpdateProperty(t, selection, evKey, {
191
+ $ref: /** @type {HTMLInputElement} */ (e.target).value,
192
+ }),
188
193
  );
189
194
  } else {
190
195
  transactDoc(activeTab.value, (t) =>