@jxsuite/studio 0.16.0 → 0.16.1

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jxsuite/studio",
3
- "version": "0.16.0",
3
+ "version": "0.16.1",
4
4
  "description": "Jx Studio — visual builder for Jx documents",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -390,38 +390,12 @@ export async function renderCanvasLive(gen, doc, canvasEl) {
390
390
  canvasEl.removeAttribute("data-content-mode");
391
391
  }
392
392
 
393
- // Resolve relative asset URLs through the PAL for environments that can't
394
- // serve project files natively (e.g. ElectroBun's views:// scheme).
395
- const platform = /** @type {any} */ (globalThis).__jxPlatform;
396
- if (platform?.resolveAssetUrl && docBase) {
397
- const mediaEls = el.querySelectorAll("img[src], video[src], source[src], video[poster]");
398
- for (const node of mediaEls) {
399
- for (const attr of ["src", "poster"]) {
400
- const val = node.getAttribute(attr);
401
- if (
402
- val &&
403
- !val.startsWith("data:") &&
404
- !val.startsWith("blob:") &&
405
- !val.startsWith("http")
406
- ) {
407
- try {
408
- const resolved = new URL(val, docBase).pathname.replace(/^\//, "");
409
- const dataUrl = await platform.resolveAssetUrl(resolved);
410
- if (dataUrl) node.setAttribute(attr, dataUrl);
411
- } catch {}
412
- }
413
- }
414
- }
415
- }
416
-
417
393
  canvasEl.appendChild(el);
394
+
418
395
  if (canvasMode === "design" || canvasMode === "edit") {
419
- // Custom element connectedCallbacks render children asynchronously —
420
- // sweep again after they've had a chance to run
421
396
  requestAnimationFrame(() => {
422
397
  const editingEl = getActiveElement();
423
398
  for (const child of canvasEl.querySelectorAll("*")) {
424
- // Preserve pointer-events on the actively-edited element
425
399
  if (view.componentInlineEdit && child === view.componentInlineEdit.el) continue;
426
400
  if (editingEl && child === editingEl) continue;
427
401
  /** @type {any} */ (child).style.pointerEvents = "none";
@@ -15,7 +15,7 @@ import { createState, projectState, setProjectState } from "../store.js";
15
15
  import { getPlatform } from "../platform.js";
16
16
  import { statusMessage } from "../panels/statusbar.js";
17
17
  import { loadComponentRegistry } from "./components.js";
18
- import { workspace, openTab, activateTab } from "../workspace/workspace.js";
18
+ import { workspace, openTab, activateTab, replaceAllTabs } from "../workspace/workspace.js";
19
19
  import { loadMarkdown } from "./file-ops.js";
20
20
  import { view } from "../view.js";
21
21
 
@@ -92,6 +92,8 @@ export async function openProject({ renderActivityBar, renderLeftPanel }) {
92
92
 
93
93
  const { config, handle } = result;
94
94
 
95
+ replaceAllTabs({ id: "initial", document: { tagName: "div", children: [] } });
96
+
95
97
  setProjectState({
96
98
  ...projectState,
97
99
  projectRoot: handle.root,
@@ -81,12 +81,14 @@ export function registerPanelEvents(panel) {
81
81
  document.elementsFromPoint(e.clientX, e.clientY),
82
82
  );
83
83
 
84
+ if (!tab) return;
85
+
84
86
  for (const el of elements) {
85
87
  if (canvas.contains(el) && el !== canvas) {
86
88
  // Layout element clicked — show layout info instead of selecting in page doc
87
89
  if (layoutElements.has(el)) {
88
90
  view.layoutSelection = { el, layoutPath: activeLayoutPath };
89
- activeTab.value.session.selection = null;
91
+ tab.session.selection = null;
90
92
  renderOnly("rightPanel");
91
93
  return;
92
94
  }
@@ -94,35 +96,35 @@ export function registerPanelEvents(panel) {
94
96
 
95
97
  const originalPath = elToPath.get(el);
96
98
  if (originalPath) {
97
- let path = bubbleInlinePath(tab?.doc.document, originalPath);
99
+ let path = bubbleInlinePath(tab.doc.document, originalPath);
98
100
  const newMedia = mediaName === "base" ? null : (mediaName ?? null);
99
101
 
100
102
  const resolvedEl = path === originalPath ? el : findCanvasElement(path, canvas) || el;
101
103
 
102
104
  if (
103
- pathsEqual(path, tab?.session.selection) &&
105
+ pathsEqual(path, tab.session.selection) &&
104
106
  isEditableBlock(resolvedEl) &&
105
- (canvasMode === "edit" || tab?.doc.mode === "content")
107
+ (canvasMode === "edit" || tab.doc.mode === "content")
106
108
  ) {
107
- activeTab.value.session.ui.activeMedia = newMedia;
109
+ tab.session.ui.activeMedia = newMedia;
108
110
  _ctx.enterInlineEdit(resolvedEl, path);
109
111
  return;
110
112
  }
111
113
 
112
- if (canvasMode === "design" && tab?.doc.mode !== "content") {
114
+ if (canvasMode === "design" && tab.doc.mode !== "content") {
113
115
  updateUi("pendingInlineEdit", { path, mediaName });
114
- activeTab.value.session.ui.activeMedia = newMedia;
115
- activeTab.value.session.selection = path;
116
+ tab.session.ui.activeMedia = newMedia;
117
+ tab.session.selection = path;
116
118
  return;
117
119
  }
118
120
 
119
- activeTab.value.session.ui.activeMedia = newMedia;
120
- activeTab.value.session.selection = path;
121
+ tab.session.ui.activeMedia = newMedia;
122
+ tab.session.selection = path;
121
123
  return;
122
124
  }
123
125
  }
124
126
  }
125
- activeTab.value.session.selection = null;
127
+ tab.session.selection = null;
126
128
  },
127
129
  opts,
128
130
  );
@@ -149,16 +151,18 @@ export function registerPanelEvents(panel) {
149
151
  document.elementsFromPoint(e.clientX, e.clientY),
150
152
  );
151
153
 
154
+ if (!tab) return;
155
+
152
156
  for (const el of elements) {
153
157
  if (canvas.contains(el) && el !== canvas) {
154
158
  const originalPath = elToPath.get(el);
155
159
  if (originalPath) {
156
- const path = bubbleInlinePath(tab?.doc.document, originalPath);
160
+ const path = bubbleInlinePath(tab.doc.document, originalPath);
157
161
  const resolvedEl = path === originalPath ? el : findCanvasElement(path, canvas) || el;
158
162
  if (isEditableBlock(resolvedEl)) {
159
163
  const newMedia = mediaName === "base" ? null : (mediaName ?? null);
160
- activeTab.value.session.ui.activeMedia = newMedia;
161
- activeTab.value.session.selection = path;
164
+ tab.session.ui.activeMedia = newMedia;
165
+ tab.session.selection = path;
162
166
  _ctx.enterInlineEdit(resolvedEl, path);
163
167
  return;
164
168
  }
@@ -217,18 +221,19 @@ export function registerPanelEvents(panel) {
217
221
  return;
218
222
  }
219
223
  const tab = activeTab.value;
224
+ if (!tab) return;
220
225
  const el = withPanelPointerEvents(() => document.elementFromPoint(e.clientX, e.clientY));
221
226
  if (el && canvas.contains(el) && el !== canvas) {
222
227
  let path = elToPath.get(el);
223
228
  if (path) {
224
- path = bubbleInlinePath(tab?.doc.document, path);
225
- if (!pathsEqual(path, tab?.session.hover)) {
226
- activeTab.value.session.hover = path;
229
+ path = bubbleInlinePath(tab.doc.document, path);
230
+ if (!pathsEqual(path, tab.session.hover)) {
231
+ tab.session.hover = path;
227
232
  renderOnly("overlays");
228
233
  }
229
234
  }
230
- } else if (tab?.session.hover) {
231
- activeTab.value.session.hover = null;
235
+ } else if (tab.session.hover) {
236
+ tab.session.hover = null;
232
237
  renderOnly("overlays");
233
238
  }
234
239
  },
@@ -222,16 +222,16 @@ function renderFrontmatterOnlyPanel() {
222
222
  fields.push({ field, entry: fieldSchema, value: fm[field] });
223
223
  }
224
224
  for (const [field, value] of Object.entries(fm)) {
225
- if (!schemaProps[field]) {
226
- fields.push({
227
- field,
228
- entry: { type: typeof value === "boolean" ? "boolean" : "string" },
229
- value,
230
- });
231
- }
225
+ if (schemaProps[field] || field.startsWith("$")) continue;
226
+ fields.push({
227
+ field,
228
+ entry: { type: typeof value === "boolean" ? "boolean" : "string" },
229
+ value,
230
+ });
232
231
  }
233
232
  } else {
234
233
  for (const [field, value] of Object.entries(fm)) {
234
+ if (field.startsWith("$")) continue;
235
235
  fields.push({
236
236
  field,
237
237
  entry: { type: typeof value === "boolean" ? "boolean" : "string" },
@@ -1656,16 +1656,16 @@ export function renderPropertiesPanelTemplate(ctx) {
1656
1656
  fields.push({ field, entry: fieldSchema, value: fm[field] });
1657
1657
  }
1658
1658
  for (const [field, value] of Object.entries(fm)) {
1659
- if (!schemaProps[field]) {
1660
- fields.push({
1661
- field,
1662
- entry: { type: typeof value === "boolean" ? "boolean" : "string" },
1663
- value,
1664
- });
1665
- }
1659
+ if (schemaProps[field] || field.startsWith("$")) continue;
1660
+ fields.push({
1661
+ field,
1662
+ entry: { type: typeof value === "boolean" ? "boolean" : "string" },
1663
+ value,
1664
+ });
1666
1665
  }
1667
1666
  } else {
1668
1667
  for (const [field, value] of Object.entries(fm)) {
1668
+ if (field.startsWith("$")) continue;
1669
1669
  fields.push({
1670
1670
  field,
1671
1671
  entry: { type: typeof value === "boolean" ? "boolean" : "string" },
@@ -84,6 +84,50 @@ export function closeTab(tabId) {
84
84
  }
85
85
  }
86
86
 
87
+ /** Close all open tabs, disposing each. Defers reactivity until fully cleared. */
88
+ export function closeAllTabs() {
89
+ const tabs = [...workspace.tabs.values()];
90
+ workspace.tabs.clear();
91
+ workspace.tabOrder = [];
92
+ workspace.activeTabId = null;
93
+ for (const tab of tabs) {
94
+ disposeTab(tab);
95
+ }
96
+ }
97
+
98
+ /**
99
+ * Replace all existing tabs with a new one atomically. Ensures activeTab is never null during the
100
+ * transition.
101
+ *
102
+ * @param {{
103
+ * id: string;
104
+ * documentPath?: string | null;
105
+ * document: Record<string, any>;
106
+ * frontmatter?: Record<string, unknown>;
107
+ * sourceFormat?: string | null;
108
+ * }} newTabOpts
109
+ * @returns {import("../tabs/tab.js").Tab}
110
+ */
111
+ export function replaceAllTabs(newTabOpts) {
112
+ const oldIds = [...workspace.tabs.keys()];
113
+ const oldTabs = [...workspace.tabs.values()];
114
+
115
+ const newTab = createTab(newTabOpts);
116
+ workspace.tabs.set(newTab.id, newTab);
117
+ workspace.activeTabId = newTab.id;
118
+ workspace.tabOrder = [newTab.id];
119
+
120
+ for (const id of oldIds) {
121
+ if (id === newTab.id) continue;
122
+ workspace.tabs.delete(id);
123
+ }
124
+ for (const tab of oldTabs) {
125
+ disposeTab(tab);
126
+ }
127
+
128
+ return newTab;
129
+ }
130
+
87
131
  /**
88
132
  * Switch to an existing tab.
89
133
  *