@amplifyup/sdk 0.1.26 → 0.1.27
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/AmplifyRenderer.js +24 -0
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +24 -0
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +24 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react.js +209 -2
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +210 -3
- package/dist/react.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -1783,6 +1783,12 @@ Available Console Commands:
|
|
|
1783
1783
|
return;
|
|
1784
1784
|
}
|
|
1785
1785
|
try {
|
|
1786
|
+
if (event.data?.type === "AMPLIFYUP_FIELD_PATCH") {
|
|
1787
|
+
window.dispatchEvent(
|
|
1788
|
+
new CustomEvent("amplifyup:field-patch", { detail: event.data })
|
|
1789
|
+
);
|
|
1790
|
+
return;
|
|
1791
|
+
}
|
|
1786
1792
|
if (event.data?.type === "COMPONENT_DELETABLE_STATUS") {
|
|
1787
1793
|
const { componentId, deletable, nodeId } = event.data;
|
|
1788
1794
|
const element = document.querySelector(`[data-component-id="${componentId}"]`);
|
|
@@ -1969,6 +1975,10 @@ Available Console Commands:
|
|
|
1969
1975
|
setEventSelectionMode(enabled) {
|
|
1970
1976
|
if (typeof document === "undefined") return;
|
|
1971
1977
|
this.eventSelectionMode = enabled;
|
|
1978
|
+
if (typeof window !== "undefined") {
|
|
1979
|
+
window.__AMPLIFYUP_EVENT_SELECTION__ = enabled;
|
|
1980
|
+
window.dispatchEvent(new CustomEvent("amplifyup:composer-edit"));
|
|
1981
|
+
}
|
|
1972
1982
|
if (this.eventSelectionClickHandler) {
|
|
1973
1983
|
document.removeEventListener("click", this.eventSelectionClickHandler, true);
|
|
1974
1984
|
this.eventSelectionClickHandler = null;
|
|
@@ -2206,6 +2216,14 @@ Available Console Commands:
|
|
|
2206
2216
|
el.classList.add("amplifyup-selected");
|
|
2207
2217
|
}
|
|
2208
2218
|
});
|
|
2219
|
+
if (typeof window !== "undefined") {
|
|
2220
|
+
window.__AMPLIFYUP_COMPOSER_EDIT__ = highlightComponents;
|
|
2221
|
+
window.dispatchEvent(
|
|
2222
|
+
new CustomEvent("amplifyup:composer-edit", {
|
|
2223
|
+
detail: { enabled: highlightComponents }
|
|
2224
|
+
})
|
|
2225
|
+
);
|
|
2226
|
+
}
|
|
2209
2227
|
}
|
|
2210
2228
|
/** Document-level drag/drop for cross-iframe drags from Composer sidebar. */
|
|
2211
2229
|
setupComposerDragDrop() {
|
|
@@ -2514,6 +2532,12 @@ Available Console Commands:
|
|
|
2514
2532
|
const clearSelection = opts?.clearSelection !== false;
|
|
2515
2533
|
this.highlightingEnabled = false;
|
|
2516
2534
|
this.teardownComposerDragDrop();
|
|
2535
|
+
if (opts?.clearSelection !== false && typeof window !== "undefined") {
|
|
2536
|
+
window.__AMPLIFYUP_COMPOSER_EDIT__ = false;
|
|
2537
|
+
window.dispatchEvent(
|
|
2538
|
+
new CustomEvent("amplifyup:composer-edit", { detail: { enabled: false } })
|
|
2539
|
+
);
|
|
2540
|
+
}
|
|
2517
2541
|
if (this.mutationObserver) {
|
|
2518
2542
|
this.mutationObserver.disconnect();
|
|
2519
2543
|
this.mutationObserver = null;
|
|
@@ -3381,6 +3405,152 @@ function Slot({
|
|
|
3381
3405
|
}
|
|
3382
3406
|
);
|
|
3383
3407
|
}
|
|
3408
|
+
function isComposerEditMode() {
|
|
3409
|
+
if (typeof window === "undefined") return false;
|
|
3410
|
+
return isComposerPreview() && window.__AMPLIFYUP_COMPOSER_EDIT__ === true && window.__AMPLIFYUP_EVENT_SELECTION__ !== true;
|
|
3411
|
+
}
|
|
3412
|
+
function isLikelyNonTextFieldName(name) {
|
|
3413
|
+
const n = name.toLowerCase();
|
|
3414
|
+
return n.includes("href") || n.includes("url") || n.includes("src") || n.includes("image") || n.includes("icon") || n.includes("overlay") || n.includes("color");
|
|
3415
|
+
}
|
|
3416
|
+
function canInlineEdit(name, value) {
|
|
3417
|
+
if (isLikelyNonTextFieldName(name)) return false;
|
|
3418
|
+
if (value !== void 0 && value !== null && typeof value === "object") {
|
|
3419
|
+
return false;
|
|
3420
|
+
}
|
|
3421
|
+
if (typeof value === "boolean") return false;
|
|
3422
|
+
return true;
|
|
3423
|
+
}
|
|
3424
|
+
function useComposerEditMode() {
|
|
3425
|
+
const [enabled, setEnabled] = react.useState(false);
|
|
3426
|
+
react.useEffect(() => {
|
|
3427
|
+
const sync = () => setEnabled(isComposerEditMode());
|
|
3428
|
+
sync();
|
|
3429
|
+
window.addEventListener("amplifyup:composer-edit", sync);
|
|
3430
|
+
return () => window.removeEventListener("amplifyup:composer-edit", sync);
|
|
3431
|
+
}, []);
|
|
3432
|
+
return enabled;
|
|
3433
|
+
}
|
|
3434
|
+
function useFieldOverlay(layoutNodeId, name, source) {
|
|
3435
|
+
const [overlay, setOverlay] = react.useState(void 0);
|
|
3436
|
+
react.useEffect(() => {
|
|
3437
|
+
const onPatch = (event) => {
|
|
3438
|
+
const detail = event.detail || {};
|
|
3439
|
+
if (detail.fieldName !== name) return;
|
|
3440
|
+
if (detail.layoutNodeId && layoutNodeId && String(detail.layoutNodeId) !== String(layoutNodeId)) {
|
|
3441
|
+
return;
|
|
3442
|
+
}
|
|
3443
|
+
setOverlay(detail.value);
|
|
3444
|
+
};
|
|
3445
|
+
window.addEventListener("amplifyup:field-patch", onPatch);
|
|
3446
|
+
return () => window.removeEventListener("amplifyup:field-patch", onPatch);
|
|
3447
|
+
}, [layoutNodeId, name]);
|
|
3448
|
+
return overlay !== void 0 ? overlay : source;
|
|
3449
|
+
}
|
|
3450
|
+
function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
3451
|
+
if (typeof window === "undefined" || window.parent === window) return;
|
|
3452
|
+
window.parent.postMessage(
|
|
3453
|
+
{
|
|
3454
|
+
type: "AMPLIFYUP_FIELD_COMMIT",
|
|
3455
|
+
layoutNodeId,
|
|
3456
|
+
componentId,
|
|
3457
|
+
fieldName: name,
|
|
3458
|
+
value
|
|
3459
|
+
},
|
|
3460
|
+
"*"
|
|
3461
|
+
);
|
|
3462
|
+
}
|
|
3463
|
+
function ComposerInlineField({
|
|
3464
|
+
name,
|
|
3465
|
+
value,
|
|
3466
|
+
fallback,
|
|
3467
|
+
className,
|
|
3468
|
+
render,
|
|
3469
|
+
layoutNodeId,
|
|
3470
|
+
componentId
|
|
3471
|
+
}) {
|
|
3472
|
+
const [editing, setEditing] = react.useState(false);
|
|
3473
|
+
const elRef = react.useRef(null);
|
|
3474
|
+
const text = formatFieldValue(value);
|
|
3475
|
+
const fallbackText = typeof fallback === "string" || typeof fallback === "number" ? String(fallback) : "";
|
|
3476
|
+
const display = text || fallbackText;
|
|
3477
|
+
const showRendered = !!render && !editing;
|
|
3478
|
+
react.useEffect(() => {
|
|
3479
|
+
const el = elRef.current;
|
|
3480
|
+
if (!el || showRendered) return;
|
|
3481
|
+
if (document.activeElement === el) return;
|
|
3482
|
+
const next = display || "";
|
|
3483
|
+
if (el.textContent !== next) el.textContent = next;
|
|
3484
|
+
}, [display, showRendered]);
|
|
3485
|
+
react.useEffect(() => {
|
|
3486
|
+
if (!editing || !elRef.current) return;
|
|
3487
|
+
const el = elRef.current;
|
|
3488
|
+
el.textContent = display || "";
|
|
3489
|
+
el.focus();
|
|
3490
|
+
const range = document.createRange();
|
|
3491
|
+
range.selectNodeContents(el);
|
|
3492
|
+
const sel = window.getSelection();
|
|
3493
|
+
sel?.removeAllRanges();
|
|
3494
|
+
sel?.addRange(range);
|
|
3495
|
+
}, [editing]);
|
|
3496
|
+
const finishEdit = () => {
|
|
3497
|
+
const raw = (elRef.current?.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "");
|
|
3498
|
+
const next = raw.trim() === "" ? "" : raw;
|
|
3499
|
+
setEditing(false);
|
|
3500
|
+
if (next === text) return;
|
|
3501
|
+
if (!text && next === fallbackText) return;
|
|
3502
|
+
commitComposerField(layoutNodeId, componentId, name, next);
|
|
3503
|
+
};
|
|
3504
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3505
|
+
"span",
|
|
3506
|
+
{
|
|
3507
|
+
ref: elRef,
|
|
3508
|
+
className,
|
|
3509
|
+
"data-amplifyup-field": name,
|
|
3510
|
+
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
3511
|
+
contentEditable: !showRendered,
|
|
3512
|
+
suppressContentEditableWarning: true,
|
|
3513
|
+
role: "textbox",
|
|
3514
|
+
tabIndex: 0,
|
|
3515
|
+
onMouseDown: (event) => {
|
|
3516
|
+
event.stopPropagation();
|
|
3517
|
+
},
|
|
3518
|
+
onClick: (event) => {
|
|
3519
|
+
const link = event.target?.closest?.("a");
|
|
3520
|
+
if (link) event.preventDefault();
|
|
3521
|
+
if (render && isComposerEditMode()) {
|
|
3522
|
+
setEditing(true);
|
|
3523
|
+
}
|
|
3524
|
+
},
|
|
3525
|
+
onFocus: () => {
|
|
3526
|
+
if (!isComposerEditMode()) return;
|
|
3527
|
+
if (render) setEditing(true);
|
|
3528
|
+
},
|
|
3529
|
+
onBlur: finishEdit,
|
|
3530
|
+
onKeyDown: (event) => {
|
|
3531
|
+
event.stopPropagation();
|
|
3532
|
+
if (event.key === "Enter" && !event.shiftKey) {
|
|
3533
|
+
event.preventDefault();
|
|
3534
|
+
event.currentTarget.blur();
|
|
3535
|
+
}
|
|
3536
|
+
if (event.key === "Escape") {
|
|
3537
|
+
event.preventDefault();
|
|
3538
|
+
if (elRef.current) elRef.current.textContent = display || "";
|
|
3539
|
+
setEditing(false);
|
|
3540
|
+
event.currentTarget.blur();
|
|
3541
|
+
}
|
|
3542
|
+
},
|
|
3543
|
+
style: {
|
|
3544
|
+
cursor: "text",
|
|
3545
|
+
outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
|
|
3546
|
+
outlineOffset: "2px",
|
|
3547
|
+
minWidth: "1ch",
|
|
3548
|
+
display: render ? void 0 : "inline"
|
|
3549
|
+
},
|
|
3550
|
+
children: showRendered ? value != null && value !== "" ? render(value) : fallback ?? display : null
|
|
3551
|
+
}
|
|
3552
|
+
);
|
|
3553
|
+
}
|
|
3384
3554
|
function formatFieldValue(value) {
|
|
3385
3555
|
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
3386
3556
|
return String(value);
|
|
@@ -3407,11 +3577,30 @@ function Field({
|
|
|
3407
3577
|
render
|
|
3408
3578
|
}) {
|
|
3409
3579
|
const context = react.useContext(ComponentContext);
|
|
3580
|
+
const composerEdit = useComposerEditMode();
|
|
3581
|
+
const fieldValue = useFieldOverlay(
|
|
3582
|
+
context?.layoutNodeId,
|
|
3583
|
+
name,
|
|
3584
|
+
context?.props?.[name]
|
|
3585
|
+
);
|
|
3410
3586
|
if (!context) {
|
|
3411
3587
|
console.warn(`[AmplifyUp SDK] Field "${name}" used outside ComponentContextProvider`);
|
|
3412
3588
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
3413
3589
|
}
|
|
3414
|
-
|
|
3590
|
+
if (composerEdit && canInlineEdit(name, fieldValue)) {
|
|
3591
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3592
|
+
ComposerInlineField,
|
|
3593
|
+
{
|
|
3594
|
+
name,
|
|
3595
|
+
value: fieldValue,
|
|
3596
|
+
fallback,
|
|
3597
|
+
className,
|
|
3598
|
+
render,
|
|
3599
|
+
layoutNodeId: context.layoutNodeId,
|
|
3600
|
+
componentId: context.componentId
|
|
3601
|
+
}
|
|
3602
|
+
);
|
|
3603
|
+
}
|
|
3415
3604
|
if (fieldValue === void 0 || fieldValue === null) {
|
|
3416
3605
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: fallback }) : null;
|
|
3417
3606
|
}
|
|
@@ -3439,11 +3628,29 @@ function RichText({
|
|
|
3439
3628
|
as: Tag = "div"
|
|
3440
3629
|
}) {
|
|
3441
3630
|
const context = react.useContext(ComponentContext);
|
|
3631
|
+
const composerEdit = useComposerEditMode();
|
|
3632
|
+
const fieldValue = useFieldOverlay(
|
|
3633
|
+
context?.layoutNodeId,
|
|
3634
|
+
name,
|
|
3635
|
+
context?.props?.[name]
|
|
3636
|
+
);
|
|
3442
3637
|
if (!context) {
|
|
3443
3638
|
console.warn(`[AmplifyUp SDK] RichText "${name}" used outside ComponentContextProvider`);
|
|
3444
3639
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: fallback }) : null;
|
|
3445
3640
|
}
|
|
3446
|
-
|
|
3641
|
+
if (composerEdit && canInlineEdit(name, fieldValue)) {
|
|
3642
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
3643
|
+
ComposerInlineField,
|
|
3644
|
+
{
|
|
3645
|
+
name,
|
|
3646
|
+
value: fieldValue,
|
|
3647
|
+
fallback,
|
|
3648
|
+
className,
|
|
3649
|
+
layoutNodeId: context.layoutNodeId,
|
|
3650
|
+
componentId: context.componentId
|
|
3651
|
+
}
|
|
3652
|
+
);
|
|
3653
|
+
}
|
|
3447
3654
|
if (fieldValue === void 0 || fieldValue === null || fieldValue === "") {
|
|
3448
3655
|
return fallback ? /* @__PURE__ */ jsxRuntime.jsx(Tag, { className, children: fallback }) : null;
|
|
3449
3656
|
}
|