@jxsuite/studio 0.26.1 → 0.27.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.
- package/dist/studio.js +192 -53
- package/dist/studio.js.map +6 -6
- package/package.json +5 -5
- package/src/panels/canvas-dnd.ts +42 -21
- package/src/panels/dnd.ts +14 -3
- package/src/tabs/transact.ts +5 -1
- package/src/ui/media-picker.ts +192 -43
package/dist/studio.js
CHANGED
|
@@ -258468,6 +258468,8 @@ function redo(tab) {
|
|
|
258468
258468
|
}
|
|
258469
258469
|
function mutateInsertNode(tab, parentPath, index, nodeDef) {
|
|
258470
258470
|
const parent = getNodeAtPath(tab.doc.document, parentPath);
|
|
258471
|
+
if (!parent)
|
|
258472
|
+
return;
|
|
258471
258473
|
if (!parent.children)
|
|
258472
258474
|
parent.children = [];
|
|
258473
258475
|
parent.children.splice(index, 0, structuredClone(nodeDef));
|
|
@@ -258510,9 +258512,15 @@ function mutateMoveNode(tab, fromPath, toParentPath, toIndex) {
|
|
|
258510
258512
|
const doc = tab.doc.document;
|
|
258511
258513
|
const fromParentPath = parentElementPath(fromPath);
|
|
258512
258514
|
const fromIdx = childIndex(fromPath);
|
|
258515
|
+
if (!fromParentPath || typeof fromIdx !== "number")
|
|
258516
|
+
return;
|
|
258513
258517
|
const fromParent = getNodeAtPath(doc, fromParentPath);
|
|
258514
|
-
const [node] = fromParent.children.splice(fromIdx, 1);
|
|
258515
258518
|
const toParent = getNodeAtPath(doc, toParentPath);
|
|
258519
|
+
if (!fromParent || !Array.isArray(fromParent.children) || !toParent)
|
|
258520
|
+
return;
|
|
258521
|
+
const [node] = fromParent.children.splice(fromIdx, 1);
|
|
258522
|
+
if (node === undefined)
|
|
258523
|
+
return;
|
|
258516
258524
|
if (!toParent.children)
|
|
258517
258525
|
toParent.children = [];
|
|
258518
258526
|
let adjustedIndex = toIndex;
|
|
@@ -270752,6 +270760,7 @@ function renderExpressionEditor(node2, onChange, opts) {
|
|
|
270752
270760
|
// src/ui/media-picker.ts
|
|
270753
270761
|
init_lit_html();
|
|
270754
270762
|
init_live();
|
|
270763
|
+
init_ref();
|
|
270755
270764
|
init_platform3();
|
|
270756
270765
|
init_store();
|
|
270757
270766
|
var IMAGE_EXTENSIONS = new Set([
|
|
@@ -270812,13 +270821,142 @@ function invalidateMediaCache() {
|
|
|
270812
270821
|
mediaCache = [];
|
|
270813
270822
|
mediaCacheLoaded = false;
|
|
270814
270823
|
}
|
|
270824
|
+
var _popoverOnCommit = null;
|
|
270825
|
+
var _popoverAnchorEl = null;
|
|
270826
|
+
var _popoverFilterEl = null;
|
|
270827
|
+
var _popoverFilter = "";
|
|
270828
|
+
function dismissMediaPickerPopover() {
|
|
270829
|
+
_popoverFilter = "";
|
|
270830
|
+
_popoverOnCommit = null;
|
|
270831
|
+
_popoverAnchorEl = null;
|
|
270832
|
+
_popoverFilterEl = null;
|
|
270833
|
+
document.removeEventListener("keydown", onPopoverKeydown, true);
|
|
270834
|
+
document.removeEventListener("mousedown", onPopoverOutsideClick, true);
|
|
270835
|
+
render2(nothing, getLayerSlot("popover", "media-picker"));
|
|
270836
|
+
}
|
|
270837
|
+
function onPopoverKeydown(e) {
|
|
270838
|
+
if (e.key === "Escape") {
|
|
270839
|
+
dismissMediaPickerPopover();
|
|
270840
|
+
e.preventDefault();
|
|
270841
|
+
e.stopPropagation();
|
|
270842
|
+
}
|
|
270843
|
+
}
|
|
270844
|
+
function onPopoverOutsideClick(e) {
|
|
270845
|
+
const host = getLayerSlot("popover", "media-picker");
|
|
270846
|
+
if (!host.contains(e.target)) {
|
|
270847
|
+
dismissMediaPickerPopover();
|
|
270848
|
+
}
|
|
270849
|
+
}
|
|
270850
|
+
function renderMediaPickerPopover() {
|
|
270851
|
+
const host = getLayerSlot("popover", "media-picker");
|
|
270852
|
+
const rect = _popoverAnchorEl?.getBoundingClientRect();
|
|
270853
|
+
if (!rect)
|
|
270854
|
+
return;
|
|
270855
|
+
const query = _popoverFilter.toLowerCase();
|
|
270856
|
+
const filtered = query ? mediaCache.filter((m) => m.path.toLowerCase().includes(query) || m.name.toLowerCase().includes(query)) : mediaCache;
|
|
270857
|
+
const options = filtered.slice(0, 50);
|
|
270858
|
+
let left = rect.left;
|
|
270859
|
+
let top = rect.bottom + 4;
|
|
270860
|
+
const estimatedWidth = 280;
|
|
270861
|
+
const estimatedHeight = Math.min(options.length * 36 + 48, 360);
|
|
270862
|
+
if (left + estimatedWidth > window.innerWidth - 8) {
|
|
270863
|
+
left = Math.max(8, window.innerWidth - estimatedWidth - 8);
|
|
270864
|
+
}
|
|
270865
|
+
if (top + estimatedHeight > window.innerHeight - 8) {
|
|
270866
|
+
top = Math.max(8, rect.top - estimatedHeight - 4);
|
|
270867
|
+
}
|
|
270868
|
+
let _popoverEl2 = null;
|
|
270869
|
+
render2(html3`
|
|
270870
|
+
<sp-popover
|
|
270871
|
+
open
|
|
270872
|
+
${ref2((el) => {
|
|
270873
|
+
_popoverEl2 = el || null;
|
|
270874
|
+
})}
|
|
270875
|
+
style="position:fixed;left:${left}px;top:${top}px;z-index:30;max-height:360px;overflow-y:auto;min-width:240px"
|
|
270876
|
+
>
|
|
270877
|
+
<input
|
|
270878
|
+
class="media-picker-filter"
|
|
270879
|
+
type="text"
|
|
270880
|
+
placeholder="Search images…"
|
|
270881
|
+
autocomplete="off"
|
|
270882
|
+
style="display:block;width:100%;box-sizing:border-box;padding:6px 10px;border:none;border-bottom:1px solid var(--border, #444);outline:none;font-size:13px;background:transparent;color:inherit"
|
|
270883
|
+
${ref2((el) => {
|
|
270884
|
+
_popoverFilterEl = el || null;
|
|
270885
|
+
})}
|
|
270886
|
+
@input=${(e) => {
|
|
270887
|
+
_popoverFilter = e.target.value;
|
|
270888
|
+
renderMediaPickerPopover();
|
|
270889
|
+
}}
|
|
270890
|
+
@click=${(e) => e.stopPropagation()}
|
|
270891
|
+
/>
|
|
270892
|
+
<sp-menu
|
|
270893
|
+
style="min-width:220px"
|
|
270894
|
+
@change=${(e) => {
|
|
270895
|
+
_popoverOnCommit?.(e.target.value);
|
|
270896
|
+
dismissMediaPickerPopover();
|
|
270897
|
+
}}
|
|
270898
|
+
>
|
|
270899
|
+
${options.length ? options.map((m) => html3`
|
|
270900
|
+
<sp-menu-item value=${m.path}>
|
|
270901
|
+
${m.isImage ? html3`<img
|
|
270902
|
+
slot="icon"
|
|
270903
|
+
src=${m.path}
|
|
270904
|
+
alt=""
|
|
270905
|
+
style="width:24px;height:24px;object-fit:cover;border-radius:2px"
|
|
270906
|
+
/>` : nothing}
|
|
270907
|
+
${m.name}
|
|
270908
|
+
</sp-menu-item>
|
|
270909
|
+
`) : html3`<sp-menu-item disabled>No matches</sp-menu-item>`}
|
|
270910
|
+
${filtered.length > 50 ? html3`<sp-menu-item disabled>…${filtered.length - 50} more</sp-menu-item>` : nothing}
|
|
270911
|
+
</sp-menu>
|
|
270912
|
+
</sp-popover>
|
|
270913
|
+
`, host);
|
|
270914
|
+
requestAnimationFrame(() => {
|
|
270915
|
+
if (_popoverEl2) {
|
|
270916
|
+
const popoverRect = _popoverEl2.getBoundingClientRect();
|
|
270917
|
+
let adjLeft = popoverRect.left;
|
|
270918
|
+
let adjTop = popoverRect.top;
|
|
270919
|
+
let needsAdjust = false;
|
|
270920
|
+
if (popoverRect.right > window.innerWidth - 4) {
|
|
270921
|
+
adjLeft = Math.max(4, window.innerWidth - popoverRect.width - 4);
|
|
270922
|
+
needsAdjust = true;
|
|
270923
|
+
}
|
|
270924
|
+
if (popoverRect.bottom > window.innerHeight - 4) {
|
|
270925
|
+
adjTop = Math.max(4, window.innerHeight - popoverRect.height - 4);
|
|
270926
|
+
needsAdjust = true;
|
|
270927
|
+
}
|
|
270928
|
+
if (popoverRect.left < 4) {
|
|
270929
|
+
adjLeft = 4;
|
|
270930
|
+
needsAdjust = true;
|
|
270931
|
+
}
|
|
270932
|
+
if (popoverRect.top < 4) {
|
|
270933
|
+
adjTop = 4;
|
|
270934
|
+
needsAdjust = true;
|
|
270935
|
+
}
|
|
270936
|
+
if (needsAdjust) {
|
|
270937
|
+
_popoverEl2.style.left = `${adjLeft}px`;
|
|
270938
|
+
_popoverEl2.style.top = `${adjTop}px`;
|
|
270939
|
+
}
|
|
270940
|
+
}
|
|
270941
|
+
if (_popoverFilterEl)
|
|
270942
|
+
_popoverFilterEl.focus();
|
|
270943
|
+
});
|
|
270944
|
+
}
|
|
270945
|
+
function showMediaPickerPopover(anchorEl, onCommit) {
|
|
270946
|
+
dismissMediaPickerPopover();
|
|
270947
|
+
_popoverOnCommit = onCommit;
|
|
270948
|
+
_popoverAnchorEl = anchorEl;
|
|
270949
|
+
_popoverFilter = "";
|
|
270950
|
+
renderMediaPickerPopover();
|
|
270951
|
+
document.addEventListener("keydown", onPopoverKeydown, true);
|
|
270952
|
+
requestAnimationFrame(() => {
|
|
270953
|
+
document.addEventListener("mousedown", onPopoverOutsideClick, true);
|
|
270954
|
+
});
|
|
270955
|
+
}
|
|
270815
270956
|
function renderMediaPicker(prop, value2, onCommit) {
|
|
270816
270957
|
loadMediaCache();
|
|
270817
270958
|
const currentValue = value2 || "";
|
|
270818
270959
|
const isImage = IMAGE_EXTENSIONS.has(currentValue.slice(currentValue.lastIndexOf(".")).toLowerCase());
|
|
270819
|
-
const query = currentValue.toLowerCase();
|
|
270820
|
-
const filtered = query ? mediaCache.filter((m) => m.path.toLowerCase().includes(query) || m.name.toLowerCase().includes(query)) : mediaCache;
|
|
270821
|
-
const options = filtered.slice(0, 20);
|
|
270822
270960
|
return html3`
|
|
270823
270961
|
<div class="media-picker">
|
|
270824
270962
|
${isImage && currentValue ? html3`<img class="media-picker-thumb" src=${currentValue} alt="" />` : nothing}
|
|
@@ -270830,31 +270968,17 @@ function renderMediaPicker(prop, value2, onCommit) {
|
|
|
270830
270968
|
@focus=${() => loadMediaCache()}
|
|
270831
270969
|
></sp-textfield>
|
|
270832
270970
|
${mediaCache.length > 0 ? html3`
|
|
270833
|
-
<
|
|
270834
|
-
|
|
270835
|
-
|
|
270836
|
-
|
|
270837
|
-
|
|
270838
|
-
|
|
270839
|
-
|
|
270840
|
-
onCommit(e.target.value);
|
|
270971
|
+
<sp-action-button
|
|
270972
|
+
size="xs"
|
|
270973
|
+
quiet
|
|
270974
|
+
title="Browse media"
|
|
270975
|
+
@click=${(e) => {
|
|
270976
|
+
loadMediaCache();
|
|
270977
|
+
showMediaPickerPopover(e.currentTarget, onCommit);
|
|
270841
270978
|
}}
|
|
270842
|
-
|
|
270843
|
-
|
|
270844
|
-
|
|
270845
|
-
${m.isImage ? html3`<img
|
|
270846
|
-
slot="icon"
|
|
270847
|
-
src=${m.path}
|
|
270848
|
-
alt=""
|
|
270849
|
-
style="width:24px;height:24px;object-fit:cover;border-radius:2px"
|
|
270850
|
-
/>` : nothing}
|
|
270851
|
-
${m.name}
|
|
270852
|
-
</sp-menu-item>
|
|
270853
|
-
`)}
|
|
270854
|
-
${filtered.length > 20 ? html3`<sp-menu-item disabled>...${filtered.length - 20} more</sp-menu-item>` : nothing}
|
|
270855
|
-
</sp-menu>
|
|
270856
|
-
</sp-popover>
|
|
270857
|
-
</overlay-trigger>
|
|
270979
|
+
>
|
|
270980
|
+
<sp-icon-image slot="icon"></sp-icon-image>
|
|
270981
|
+
</sp-action-button>
|
|
270858
270982
|
` : nothing}
|
|
270859
270983
|
</div>
|
|
270860
270984
|
`;
|
|
@@ -272945,9 +273069,6 @@ function registerLayersDnD() {
|
|
|
272945
273069
|
onDrag({ self: self2 }) {
|
|
272946
273070
|
showLayerDropGap(row, self2.data, container);
|
|
272947
273071
|
},
|
|
272948
|
-
onDragLeave() {
|
|
272949
|
-
clearLayerDropGap(container);
|
|
272950
|
-
},
|
|
272951
273072
|
onDrop() {
|
|
272952
273073
|
clearLayerDropGap(container);
|
|
272953
273074
|
}
|
|
@@ -272955,6 +273076,11 @@ function registerLayersDnD() {
|
|
|
272955
273076
|
view.dndCleanups.push(cleanup);
|
|
272956
273077
|
});
|
|
272957
273078
|
const monitorCleanup = monitorForElements({
|
|
273079
|
+
onDropTargetChange({ location: location3 }) {
|
|
273080
|
+
const inner = location3.current.dropTargets[0];
|
|
273081
|
+
if (inner && !extractInstruction(inner.data))
|
|
273082
|
+
clearLayerDropGap(container);
|
|
273083
|
+
},
|
|
272958
273084
|
onDrop({ source, location: location3 }) {
|
|
272959
273085
|
clearLayerDropGap(container);
|
|
272960
273086
|
const target = location3.current.dropTargets[0];
|
|
@@ -273095,6 +273221,8 @@ function applyDropInstruction(instruction, srcData, targetPath) {
|
|
|
273095
273221
|
const fromPath = srcData.path;
|
|
273096
273222
|
const targetParent = parentElementPath(targetPath);
|
|
273097
273223
|
const targetIdx = childIndex(targetPath);
|
|
273224
|
+
if (instruction.type !== "make-child" && (!targetParent || typeof targetIdx !== "number"))
|
|
273225
|
+
return;
|
|
273098
273226
|
switch (instruction.type) {
|
|
273099
273227
|
case "reorder-above":
|
|
273100
273228
|
transactDoc(activeTab.value, (t) => mutateMoveNode(t, fromPath, targetParent, targetIdx));
|
|
@@ -273112,6 +273240,8 @@ function applyDropInstruction(instruction, srcData, targetPath) {
|
|
|
273112
273240
|
} else if (srcData.type === "block") {
|
|
273113
273241
|
const targetParent = parentElementPath(targetPath);
|
|
273114
273242
|
const targetIdx = childIndex(targetPath);
|
|
273243
|
+
if (instruction.type !== "make-child" && (!targetParent || typeof targetIdx !== "number"))
|
|
273244
|
+
return;
|
|
273115
273245
|
switch (instruction.type) {
|
|
273116
273246
|
case "reorder-above":
|
|
273117
273247
|
transactDoc(activeTab.value, (t) => mutateInsertNode(t, targetParent, targetIdx, structuredClone(srcData.fragment)));
|
|
@@ -273169,6 +273299,16 @@ var _activeDropEl = null;
|
|
|
273169
273299
|
function registerPanelDnD(panel) {
|
|
273170
273300
|
const { canvas, dropLine } = panel;
|
|
273171
273301
|
const allEls = canvas.querySelectorAll("*");
|
|
273302
|
+
const innermostCanvasTarget = (location3) => {
|
|
273303
|
+
const target = location3.current.dropTargets[0];
|
|
273304
|
+
if (!target)
|
|
273305
|
+
return null;
|
|
273306
|
+
const tEl = target.element;
|
|
273307
|
+
const tPath = target.data.path;
|
|
273308
|
+
if (!canvas.contains(tEl) || !Array.isArray(tPath))
|
|
273309
|
+
return null;
|
|
273310
|
+
return { el: tEl, path: tPath, isLeaf: !!target.data._isVoid };
|
|
273311
|
+
};
|
|
273172
273312
|
const monitorCleanup = monitorForElements({
|
|
273173
273313
|
onDragStart({ location: location3 }) {
|
|
273174
273314
|
view.lastDragInput = location3.current.input;
|
|
@@ -273180,8 +273320,27 @@ function registerPanelDnD(panel) {
|
|
|
273180
273320
|
},
|
|
273181
273321
|
onDrag({ location: location3 }) {
|
|
273182
273322
|
view.lastDragInput = location3.current.input;
|
|
273323
|
+
const target = innermostCanvasTarget(location3);
|
|
273324
|
+
if (target) {
|
|
273325
|
+
if (_activeDropEl && _activeDropEl !== target.el) {
|
|
273326
|
+
_activeDropEl.classList.remove("canvas-drop-target");
|
|
273327
|
+
}
|
|
273328
|
+
_activeDropEl = target.el;
|
|
273329
|
+
showCanvasDropIndicator(target.el, target.path, target.isLeaf, panel);
|
|
273330
|
+
} else if (location3.current.dropTargets.length > 0) {
|
|
273331
|
+
if (_activeDropEl && canvas.contains(_activeDropEl)) {
|
|
273332
|
+
_activeDropEl.classList.remove("canvas-drop-target");
|
|
273333
|
+
_activeDropEl = null;
|
|
273334
|
+
}
|
|
273335
|
+
dropLine.style.display = "none";
|
|
273336
|
+
}
|
|
273183
273337
|
},
|
|
273184
|
-
onDrop() {
|
|
273338
|
+
onDrop({ source, location: location3 }) {
|
|
273339
|
+
const target = innermostCanvasTarget(location3);
|
|
273340
|
+
if (target) {
|
|
273341
|
+
const { instruction, targetPath } = getCanvasDropResult(target.el, target.path, target.isLeaf);
|
|
273342
|
+
applyDropInstruction(instruction, source.data, targetPath);
|
|
273343
|
+
}
|
|
273185
273344
|
_activeDropEl?.classList.remove("canvas-drop-target");
|
|
273186
273345
|
_activeDropEl = null;
|
|
273187
273346
|
for (const p of canvasPanels) {
|
|
@@ -273216,26 +273375,6 @@ function registerPanelDnD(panel) {
|
|
|
273216
273375
|
},
|
|
273217
273376
|
getData() {
|
|
273218
273377
|
return { path: elPath, _isVoid: isLeaf2 };
|
|
273219
|
-
},
|
|
273220
|
-
onDragEnter({ location: location3 }) {
|
|
273221
|
-
view.lastDragInput = location3.current.input;
|
|
273222
|
-
if (_activeDropEl && _activeDropEl !== el) {
|
|
273223
|
-
_activeDropEl.classList.remove("canvas-drop-target");
|
|
273224
|
-
}
|
|
273225
|
-
_activeDropEl = el;
|
|
273226
|
-
showCanvasDropIndicator(el, elPath, isLeaf2, panel);
|
|
273227
|
-
},
|
|
273228
|
-
onDrag({ location: location3 }) {
|
|
273229
|
-
view.lastDragInput = location3.current.input;
|
|
273230
|
-
showCanvasDropIndicator(el, elPath, isLeaf2, panel);
|
|
273231
|
-
},
|
|
273232
|
-
onDragLeave() {},
|
|
273233
|
-
onDrop({ source }) {
|
|
273234
|
-
dropLine.style.display = "none";
|
|
273235
|
-
el.classList.remove("canvas-drop-target");
|
|
273236
|
-
_activeDropEl = null;
|
|
273237
|
-
const { instruction, targetPath } = getCanvasDropResult(el, elPath, isLeaf2);
|
|
273238
|
-
applyDropInstruction(instruction, source.data, targetPath);
|
|
273239
273378
|
}
|
|
273240
273379
|
});
|
|
273241
273380
|
view.canvasDndCleanups.push(cleanup);
|
|
@@ -312829,5 +312968,5 @@ effect(() => {
|
|
|
312829
312968
|
scheduleAutosave();
|
|
312830
312969
|
});
|
|
312831
312970
|
|
|
312832
|
-
//# debugId=
|
|
312971
|
+
//# debugId=F092D1FA9C946D1E64756E2164756E21
|
|
312833
312972
|
//# sourceMappingURL=studio.js.map
|