@amplifyup/sdk 0.1.62 → 0.1.63
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/README.md +401 -12
- package/dist/{AmplifyRenderer-BQ8-H2H4.d.ts → AmplifyRenderer-Bwob7ICJ.d.ts} +23 -4
- package/dist/{AmplifyRenderer-W7eqltSj.d.mts → AmplifyRenderer-TawbUIKZ.d.mts} +23 -4
- package/dist/AmplifyRenderer.d.mts +1 -1
- package/dist/AmplifyRenderer.d.ts +1 -1
- package/dist/AmplifyRenderer.js +70 -0
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +70 -0
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -0
- package/dist/index.mjs.map +1 -1
- package/dist/react.d.mts +45 -11
- package/dist/react.d.ts +45 -11
- package/dist/react.js +310 -75
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +310 -76
- package/dist/react.mjs.map +1 -1
- package/dist/server.js +37 -0
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +37 -0
- package/dist/server.mjs.map +1 -1
- package/package.json +1 -1
package/dist/react.js
CHANGED
|
@@ -434,6 +434,21 @@ function isPortableImageShape(value) {
|
|
|
434
434
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
435
435
|
return "url" in value;
|
|
436
436
|
}
|
|
437
|
+
function isEntryRefItem(value) {
|
|
438
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
439
|
+
const rec = value;
|
|
440
|
+
return typeof rec.id === "string" && rec.id.trim().length > 0 || typeof rec._id === "string" && rec._id.trim().length > 0 || typeof rec.docId === "string" && rec.docId.trim().length > 0;
|
|
441
|
+
}
|
|
442
|
+
function isRepeaterArray(value) {
|
|
443
|
+
if (!Array.isArray(value) || value.length === 0) return false;
|
|
444
|
+
const sample = value.find((item) => item != null);
|
|
445
|
+
if (sample === void 0) return false;
|
|
446
|
+
if (typeof sample !== "object" || Array.isArray(sample)) return false;
|
|
447
|
+
if (isPortableImageShape(sample)) return false;
|
|
448
|
+
if (isEntryRefItem(sample)) return false;
|
|
449
|
+
if (sample.$$typeof) return false;
|
|
450
|
+
return true;
|
|
451
|
+
}
|
|
437
452
|
function joinPath(prefix, key) {
|
|
438
453
|
return prefix ? `${prefix}.${key}` : key;
|
|
439
454
|
}
|
|
@@ -450,9 +465,21 @@ function toFieldEnvelopes(source, prefix = "") {
|
|
|
450
465
|
for (const [key, raw] of Object.entries(input)) {
|
|
451
466
|
const path = joinPath(prefix, key);
|
|
452
467
|
if (isFieldEnvelope(raw)) {
|
|
468
|
+
const inner = raw.value;
|
|
469
|
+
if (isRepeaterArray(inner)) {
|
|
470
|
+
out[key] = {
|
|
471
|
+
value: envelopeRepeaterItems(inner, raw.name || path),
|
|
472
|
+
name: raw.name || path
|
|
473
|
+
};
|
|
474
|
+
continue;
|
|
475
|
+
}
|
|
453
476
|
out[key] = { value: raw.value ?? null, name: raw.name || path };
|
|
454
477
|
continue;
|
|
455
478
|
}
|
|
479
|
+
if (isRepeaterArray(raw)) {
|
|
480
|
+
out[key] = { value: envelopeRepeaterItems(raw, path), name: path };
|
|
481
|
+
continue;
|
|
482
|
+
}
|
|
456
483
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
457
484
|
out[key] = toFieldEnvelopes(raw, path);
|
|
458
485
|
continue;
|
|
@@ -461,6 +488,16 @@ function toFieldEnvelopes(source, prefix = "") {
|
|
|
461
488
|
}
|
|
462
489
|
return brandFields(out);
|
|
463
490
|
}
|
|
491
|
+
function envelopeRepeaterItems(items, prefix) {
|
|
492
|
+
return items.map((item, i) => {
|
|
493
|
+
const path = joinPath(prefix, String(i));
|
|
494
|
+
if (isBrandedFields(item)) return item;
|
|
495
|
+
if (item && typeof item === "object" && !Array.isArray(item)) {
|
|
496
|
+
return toFieldEnvelopes(item, path);
|
|
497
|
+
}
|
|
498
|
+
return toFieldEnvelopes({}, path);
|
|
499
|
+
});
|
|
500
|
+
}
|
|
464
501
|
function attachFieldEnvelopes(props) {
|
|
465
502
|
const raw = props && typeof props === "object" ? { ...props } : {};
|
|
466
503
|
if (isBrandedFields(raw.fields)) return raw;
|
|
@@ -487,6 +524,14 @@ function envelopePageConfig(page) {
|
|
|
487
524
|
}
|
|
488
525
|
function collectFieldPatches(props) {
|
|
489
526
|
const out = [];
|
|
527
|
+
const walkRepeater = (items, prefix) => {
|
|
528
|
+
items.forEach((item, i) => {
|
|
529
|
+
const itemPath = joinPath(prefix, String(i));
|
|
530
|
+
if (isBrandedFields(item) || item && typeof item === "object" && !Array.isArray(item) && !isFieldEnvelope(item)) {
|
|
531
|
+
walk(item, itemPath);
|
|
532
|
+
}
|
|
533
|
+
});
|
|
534
|
+
};
|
|
490
535
|
const walk = (obj, prefix) => {
|
|
491
536
|
for (const [key, raw] of Object.entries(obj)) {
|
|
492
537
|
if (key === "fields" && raw && typeof raw === "object" && !Array.isArray(raw) && !isFieldEnvelope(raw)) {
|
|
@@ -495,9 +540,17 @@ function collectFieldPatches(props) {
|
|
|
495
540
|
}
|
|
496
541
|
const path = joinPath(prefix, key);
|
|
497
542
|
if (isFieldEnvelope(raw)) {
|
|
543
|
+
if (isRepeaterArray(raw.value)) {
|
|
544
|
+
walkRepeater(raw.value, raw.name || path);
|
|
545
|
+
continue;
|
|
546
|
+
}
|
|
498
547
|
out.push({ name: raw.name || path, value: raw.value });
|
|
499
548
|
continue;
|
|
500
549
|
}
|
|
550
|
+
if (isRepeaterArray(raw)) {
|
|
551
|
+
walkRepeater(raw, path);
|
|
552
|
+
continue;
|
|
553
|
+
}
|
|
501
554
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
502
555
|
walk(raw, path);
|
|
503
556
|
continue;
|
|
@@ -510,6 +563,37 @@ function collectFieldPatches(props) {
|
|
|
510
563
|
}
|
|
511
564
|
return out;
|
|
512
565
|
}
|
|
566
|
+
function unwrapFieldsBag(item) {
|
|
567
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) return {};
|
|
568
|
+
const out = {};
|
|
569
|
+
for (const [key, raw] of Object.entries(item)) {
|
|
570
|
+
if (isFieldEnvelope(raw)) {
|
|
571
|
+
out[key] = raw.value;
|
|
572
|
+
continue;
|
|
573
|
+
}
|
|
574
|
+
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !isEntryRefItem(raw) && !raw.$$typeof) {
|
|
575
|
+
out[key] = unwrapFieldsBag(raw);
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
out[key] = raw;
|
|
579
|
+
}
|
|
580
|
+
return out;
|
|
581
|
+
}
|
|
582
|
+
function resolveCollectionItems(field, overlay) {
|
|
583
|
+
const name = typeof field?.name === "string" ? field.name : "";
|
|
584
|
+
const raw = overlay !== void 0 ? overlay : field?.value;
|
|
585
|
+
const list = Array.isArray(raw) ? raw : isFieldEnvelope(raw) && Array.isArray(raw.value) ? raw.value : [];
|
|
586
|
+
if (list.length === 0) return [];
|
|
587
|
+
if (isRepeaterArray(list) || list.every((item) => isBrandedFields(item))) {
|
|
588
|
+
return envelopeRepeaterItems(list, name);
|
|
589
|
+
}
|
|
590
|
+
return envelopeRepeaterItems(
|
|
591
|
+
list.map(
|
|
592
|
+
(item) => item && typeof item === "object" && !Array.isArray(item) ? item : {}
|
|
593
|
+
),
|
|
594
|
+
name
|
|
595
|
+
);
|
|
596
|
+
}
|
|
513
597
|
function resolveEditableBinding(field, value, name) {
|
|
514
598
|
if (isFieldEnvelope(field)) {
|
|
515
599
|
return { name: field.name, value: field.value, requiresName: false };
|
|
@@ -3623,6 +3707,16 @@ var ComposerFieldStore = class {
|
|
|
3623
3707
|
if (set.size === 0) this.listeners.delete(name);
|
|
3624
3708
|
};
|
|
3625
3709
|
}
|
|
3710
|
+
keys() {
|
|
3711
|
+
return [...this.values.keys()];
|
|
3712
|
+
}
|
|
3713
|
+
delete(name) {
|
|
3714
|
+
if (!name || !this.values.has(name)) return;
|
|
3715
|
+
this.values.delete(name);
|
|
3716
|
+
const set = this.listeners.get(name);
|
|
3717
|
+
if (!set) return;
|
|
3718
|
+
for (const fn of set) fn();
|
|
3719
|
+
}
|
|
3626
3720
|
};
|
|
3627
3721
|
var ComposerStoreContext = React2.createContext(null);
|
|
3628
3722
|
function matchesNode(eventNodeId, layoutNodeId) {
|
|
@@ -3643,6 +3737,13 @@ function ComposerProvider({
|
|
|
3643
3737
|
if (!fieldName || typeof fieldName !== "string") return;
|
|
3644
3738
|
if (!matchesNode(nodeId, layoutNodeId)) return;
|
|
3645
3739
|
store.set(fieldName, value);
|
|
3740
|
+
if (value && typeof value === "object") {
|
|
3741
|
+
for (const patch of collectFieldPatches(
|
|
3742
|
+
toFieldEnvelopes({ [fieldName]: value })
|
|
3743
|
+
)) {
|
|
3744
|
+
store.set(patch.name, patch.value);
|
|
3745
|
+
}
|
|
3746
|
+
}
|
|
3646
3747
|
};
|
|
3647
3748
|
const applyProps = (nextProps, nodeId) => {
|
|
3648
3749
|
if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
|
|
@@ -3697,6 +3798,9 @@ function useComposerFieldValue(name, fallback) {
|
|
|
3697
3798
|
const overlay = React2.useSyncExternalStore(subscribe, getSnapshot, () => void 0);
|
|
3698
3799
|
return overlay !== void 0 ? overlay : fallback;
|
|
3699
3800
|
}
|
|
3801
|
+
function useComposerStore() {
|
|
3802
|
+
return React2.useContext(ComposerStoreContext);
|
|
3803
|
+
}
|
|
3700
3804
|
function MaybeComposerProvider({
|
|
3701
3805
|
enabled,
|
|
3702
3806
|
layoutNodeId,
|
|
@@ -4360,6 +4464,21 @@ function AmplifyPageContent({
|
|
|
4360
4464
|
}
|
|
4361
4465
|
);
|
|
4362
4466
|
}
|
|
4467
|
+
|
|
4468
|
+
// src/composer-edit-mode.ts
|
|
4469
|
+
function isComposerEditMode() {
|
|
4470
|
+
if (typeof window === "undefined") return false;
|
|
4471
|
+
return isComposerPreview() && window.__AMPLIFYUP_EVENT_SELECTION__ !== true;
|
|
4472
|
+
}
|
|
4473
|
+
function subscribeComposerEdit(onStoreChange) {
|
|
4474
|
+
if (typeof window === "undefined") return () => {
|
|
4475
|
+
};
|
|
4476
|
+
window.addEventListener("amplifyup:composer-edit", onStoreChange);
|
|
4477
|
+
return () => window.removeEventListener("amplifyup:composer-edit", onStoreChange);
|
|
4478
|
+
}
|
|
4479
|
+
function getComposerEditModeServer() {
|
|
4480
|
+
return false;
|
|
4481
|
+
}
|
|
4363
4482
|
var ComponentContext = React2.createContext(null);
|
|
4364
4483
|
function ComponentContextProvider({
|
|
4365
4484
|
children,
|
|
@@ -4461,10 +4580,6 @@ function Slot({
|
|
|
4461
4580
|
}
|
|
4462
4581
|
);
|
|
4463
4582
|
}
|
|
4464
|
-
function isComposerEditMode() {
|
|
4465
|
-
if (typeof window === "undefined") return false;
|
|
4466
|
-
return isComposerPreview() && window.__AMPLIFYUP_EVENT_SELECTION__ !== true;
|
|
4467
|
-
}
|
|
4468
4583
|
function isLikelyNonTextFieldName(name) {
|
|
4469
4584
|
const n = name.toLowerCase();
|
|
4470
4585
|
return n.includes("href") || n.includes("url") || n.includes("src") || n.includes("image") || n.includes("icon") || n.includes("overlay") || n.includes("color");
|
|
@@ -4499,17 +4614,11 @@ function canInlineEditRichText(name, value) {
|
|
|
4499
4614
|
}
|
|
4500
4615
|
return true;
|
|
4501
4616
|
}
|
|
4502
|
-
function subscribeComposerEdit(onStoreChange) {
|
|
4503
|
-
if (typeof window === "undefined") return () => {
|
|
4504
|
-
};
|
|
4505
|
-
window.addEventListener("amplifyup:composer-edit", onStoreChange);
|
|
4506
|
-
return () => window.removeEventListener("amplifyup:composer-edit", onStoreChange);
|
|
4507
|
-
}
|
|
4508
4617
|
function useComposerEditMode() {
|
|
4509
4618
|
return React2.useSyncExternalStore(
|
|
4510
4619
|
subscribeComposerEdit,
|
|
4511
4620
|
isComposerEditMode,
|
|
4512
|
-
|
|
4621
|
+
getComposerEditModeServer
|
|
4513
4622
|
);
|
|
4514
4623
|
}
|
|
4515
4624
|
function useBoundField(field, value, name, component) {
|
|
@@ -4577,23 +4686,20 @@ function ComposerInlineField({
|
|
|
4577
4686
|
name,
|
|
4578
4687
|
value,
|
|
4579
4688
|
className,
|
|
4580
|
-
render,
|
|
4581
4689
|
layoutNodeId,
|
|
4582
4690
|
componentId,
|
|
4583
4691
|
rich = false
|
|
4584
4692
|
}) {
|
|
4585
|
-
const [editing, setEditing] = React2.useState(false);
|
|
4586
4693
|
const [focused, setFocused] = React2.useState(false);
|
|
4587
4694
|
const elRef = React2.useRef(null);
|
|
4588
4695
|
const storedEmpty = isComposerEmptyText(value);
|
|
4589
4696
|
const text = storedEmpty ? "" : formatFieldValue(value);
|
|
4590
4697
|
const hint = COMPOSER_EMPTY_FIELD_HINT;
|
|
4591
4698
|
const idleDisplay = storedEmpty ? hint : text;
|
|
4592
|
-
const
|
|
4593
|
-
const showHint = storedEmpty && !focused && !showRendered;
|
|
4699
|
+
const showHint = storedEmpty && !focused;
|
|
4594
4700
|
React2.useEffect(() => {
|
|
4595
4701
|
const el = elRef.current;
|
|
4596
|
-
if (!el
|
|
4702
|
+
if (!el) return;
|
|
4597
4703
|
if (document.activeElement === el) return;
|
|
4598
4704
|
if (el.querySelector(
|
|
4599
4705
|
"input, button, select, textarea, form, svg, iframe, img"
|
|
@@ -4602,24 +4708,10 @@ function ComposerInlineField({
|
|
|
4602
4708
|
}
|
|
4603
4709
|
const next = idleDisplay || "";
|
|
4604
4710
|
if (el.textContent !== next) el.textContent = next;
|
|
4605
|
-
}, [idleDisplay
|
|
4606
|
-
React2.useEffect(() => {
|
|
4607
|
-
if (!editing || !elRef.current) return;
|
|
4608
|
-
const el = elRef.current;
|
|
4609
|
-
if (storedEmpty) {
|
|
4610
|
-
el.textContent = "";
|
|
4611
|
-
el.focus();
|
|
4612
|
-
placeCaret(el, true);
|
|
4613
|
-
return;
|
|
4614
|
-
}
|
|
4615
|
-
el.textContent = idleDisplay || "";
|
|
4616
|
-
el.focus();
|
|
4617
|
-
placeCaret(el, false);
|
|
4618
|
-
}, [editing, storedEmpty, idleDisplay]);
|
|
4711
|
+
}, [idleDisplay]);
|
|
4619
4712
|
const finishEdit = () => {
|
|
4620
4713
|
const raw = (elRef.current?.innerText ?? "").replace(/\u00a0/g, " ").replace(/\n+$/g, "");
|
|
4621
4714
|
const next = raw.trim() === "" ? "" : raw;
|
|
4622
|
-
setEditing(false);
|
|
4623
4715
|
setFocused(false);
|
|
4624
4716
|
if (storedEmpty && next === "") {
|
|
4625
4717
|
if (elRef.current) elRef.current.textContent = hint;
|
|
@@ -4653,7 +4745,7 @@ function ComposerInlineField({
|
|
|
4653
4745
|
"data-amplifyup-field-type": rich ? "richtext" : "text",
|
|
4654
4746
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
4655
4747
|
"data-amplifyup-empty-hint": showHint ? "true" : void 0,
|
|
4656
|
-
contentEditable: !rich
|
|
4748
|
+
contentEditable: !rich,
|
|
4657
4749
|
suppressContentEditableWarning: true,
|
|
4658
4750
|
role: "textbox",
|
|
4659
4751
|
tabIndex: 0,
|
|
@@ -4668,9 +4760,6 @@ function ComposerInlineField({
|
|
|
4668
4760
|
openRichEditor(event);
|
|
4669
4761
|
return;
|
|
4670
4762
|
}
|
|
4671
|
-
if (render) {
|
|
4672
|
-
setEditing(true);
|
|
4673
|
-
}
|
|
4674
4763
|
},
|
|
4675
4764
|
onFocus: () => {
|
|
4676
4765
|
if (!isComposerEditMode()) return;
|
|
@@ -4684,7 +4773,6 @@ function ComposerInlineField({
|
|
|
4684
4773
|
el.textContent = "";
|
|
4685
4774
|
placeCaret(el, true);
|
|
4686
4775
|
}
|
|
4687
|
-
if (render) setEditing(true);
|
|
4688
4776
|
},
|
|
4689
4777
|
onBlur: rich ? void 0 : finishEdit,
|
|
4690
4778
|
onKeyDown: (event) => {
|
|
@@ -4696,7 +4784,6 @@ function ComposerInlineField({
|
|
|
4696
4784
|
if (event.key === "Escape") {
|
|
4697
4785
|
event.preventDefault();
|
|
4698
4786
|
if (elRef.current) elRef.current.textContent = idleDisplay || "";
|
|
4699
|
-
setEditing(false);
|
|
4700
4787
|
setFocused(false);
|
|
4701
4788
|
event.currentTarget.blur();
|
|
4702
4789
|
}
|
|
@@ -4710,8 +4797,7 @@ function ComposerInlineField({
|
|
|
4710
4797
|
// Do not force `inline` — that overrides Tailwind `block` and parks
|
|
4711
4798
|
// an empty-field hint on the same line as a sibling that has a value.
|
|
4712
4799
|
opacity: showHint ? 0.5 : void 0
|
|
4713
|
-
}
|
|
4714
|
-
children: showRendered ? render(value) : null
|
|
4800
|
+
}
|
|
4715
4801
|
}
|
|
4716
4802
|
);
|
|
4717
4803
|
}
|
|
@@ -4790,35 +4876,8 @@ function warnProjectionProps(component, hasField, hasValue, name) {
|
|
|
4790
4876
|
function hasOwnProp(props, key) {
|
|
4791
4877
|
return Object.prototype.hasOwnProperty.call(props, key);
|
|
4792
4878
|
}
|
|
4793
|
-
function isLinkListItem(value) {
|
|
4794
|
-
return !!value && typeof value === "object" && !Array.isArray(value);
|
|
4795
|
-
}
|
|
4796
|
-
function renderLinkList(items, className) {
|
|
4797
|
-
const links = items.filter(isLinkListItem).filter((item) => {
|
|
4798
|
-
const label = typeof item.label === "string" ? item.label.trim() : "";
|
|
4799
|
-
const href = typeof item.href === "string" ? item.href.trim() : "";
|
|
4800
|
-
return !!(label || href);
|
|
4801
|
-
});
|
|
4802
|
-
if (links.length === 0) return null;
|
|
4803
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: links.map((item, index) => {
|
|
4804
|
-
const label = typeof item.label === "string" && item.label.trim() ? item.label : typeof item.href === "string" ? item.href : "Link";
|
|
4805
|
-
const href = typeof item.href === "string" && item.href.trim() ? item.href : "#";
|
|
4806
|
-
const style = typeof item.style === "string" ? item.style.trim() : "";
|
|
4807
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4808
|
-
"a",
|
|
4809
|
-
{
|
|
4810
|
-
href,
|
|
4811
|
-
target: item.openInNewTab ? "_blank" : void 0,
|
|
4812
|
-
rel: item.openInNewTab ? "noreferrer" : void 0,
|
|
4813
|
-
"data-amplifyup-action-style": style || void 0,
|
|
4814
|
-
children: label
|
|
4815
|
-
},
|
|
4816
|
-
typeof item._key === "string" && item._key ? item._key : `${href}-${index}`
|
|
4817
|
-
);
|
|
4818
|
-
}) });
|
|
4819
|
-
}
|
|
4820
4879
|
function Field(props) {
|
|
4821
|
-
const { field, value, name, className
|
|
4880
|
+
const { field, value, name, className } = props;
|
|
4822
4881
|
const context = React2.useContext(ComponentContext);
|
|
4823
4882
|
const composerEdit = useComposerEditMode();
|
|
4824
4883
|
const hasField = isFieldEnvelope(field);
|
|
@@ -4828,6 +4887,9 @@ function Field(props) {
|
|
|
4828
4887
|
if (!hasField && !hasValue && !name) {
|
|
4829
4888
|
return null;
|
|
4830
4889
|
}
|
|
4890
|
+
if (Array.isArray(fieldValue)) {
|
|
4891
|
+
return null;
|
|
4892
|
+
}
|
|
4831
4893
|
const empty = isComposerEmptyText(fieldValue);
|
|
4832
4894
|
if (composerEdit && editName && context && canInlineEdit(editName, fieldValue)) {
|
|
4833
4895
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4836,7 +4898,6 @@ function Field(props) {
|
|
|
4836
4898
|
name: editName,
|
|
4837
4899
|
value: fieldValue,
|
|
4838
4900
|
className,
|
|
4839
|
-
render: empty ? void 0 : render,
|
|
4840
4901
|
layoutNodeId: context.layoutNodeId,
|
|
4841
4902
|
componentId: context.componentId,
|
|
4842
4903
|
rich: looksLikeRichCanvasField(editName)
|
|
@@ -4844,17 +4905,190 @@ function Field(props) {
|
|
|
4844
4905
|
);
|
|
4845
4906
|
}
|
|
4846
4907
|
if (empty) return null;
|
|
4847
|
-
if (render) {
|
|
4848
|
-
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: render(fieldValue) });
|
|
4849
|
-
}
|
|
4850
|
-
if (Array.isArray(fieldValue)) {
|
|
4851
|
-
const list = renderLinkList(fieldValue, className);
|
|
4852
|
-
if (list) return list;
|
|
4853
|
-
}
|
|
4854
4908
|
const text = formatFieldValue(fieldValue);
|
|
4855
4909
|
if (!text) return null;
|
|
4856
4910
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: text });
|
|
4857
4911
|
}
|
|
4912
|
+
var COMPOSER_EMPTY_COLLECTION_HINT = "Click here to add an item";
|
|
4913
|
+
function CollectionChromeButton({
|
|
4914
|
+
label,
|
|
4915
|
+
onClick
|
|
4916
|
+
}) {
|
|
4917
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4918
|
+
"button",
|
|
4919
|
+
{
|
|
4920
|
+
type: "button",
|
|
4921
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
4922
|
+
onClick: (event) => {
|
|
4923
|
+
event.preventDefault();
|
|
4924
|
+
event.stopPropagation();
|
|
4925
|
+
onClick();
|
|
4926
|
+
},
|
|
4927
|
+
style: {
|
|
4928
|
+
fontSize: 11,
|
|
4929
|
+
lineHeight: 1.2,
|
|
4930
|
+
padding: "4px 8px",
|
|
4931
|
+
border: "1px solid color-mix(in srgb, currentColor 28%, transparent)",
|
|
4932
|
+
borderRadius: 6,
|
|
4933
|
+
background: "transparent",
|
|
4934
|
+
cursor: "pointer",
|
|
4935
|
+
color: "inherit"
|
|
4936
|
+
},
|
|
4937
|
+
children: label
|
|
4938
|
+
}
|
|
4939
|
+
);
|
|
4940
|
+
}
|
|
4941
|
+
function Collection({
|
|
4942
|
+
field,
|
|
4943
|
+
children,
|
|
4944
|
+
className
|
|
4945
|
+
}) {
|
|
4946
|
+
const context = React2.useContext(ComponentContext);
|
|
4947
|
+
const store = useComposerStore();
|
|
4948
|
+
const composerEdit = useComposerEditMode();
|
|
4949
|
+
const name = isFieldEnvelope(field) ? field.name : "";
|
|
4950
|
+
const overlay = useComposerFieldValue(name, void 0);
|
|
4951
|
+
const items = resolveCollectionItems(field, overlay);
|
|
4952
|
+
const writeItems = (nextPlain) => {
|
|
4953
|
+
if (name && store) {
|
|
4954
|
+
const prefixed = name ? store.keys().filter((key) => key === name || key.startsWith(`${name}.`)) : [];
|
|
4955
|
+
for (const key of prefixed) store.delete(key);
|
|
4956
|
+
store.set(name, nextPlain);
|
|
4957
|
+
for (const patch of collectFieldPatches(
|
|
4958
|
+
toFieldEnvelopes({ [name]: nextPlain })
|
|
4959
|
+
)) {
|
|
4960
|
+
store.set(patch.name, patch.value);
|
|
4961
|
+
}
|
|
4962
|
+
}
|
|
4963
|
+
commitComposerField(
|
|
4964
|
+
context?.layoutNodeId,
|
|
4965
|
+
context?.componentId,
|
|
4966
|
+
name,
|
|
4967
|
+
nextPlain
|
|
4968
|
+
);
|
|
4969
|
+
};
|
|
4970
|
+
const plainItems = () => items.map((item, index) => {
|
|
4971
|
+
const base = unwrapFieldsBag(item);
|
|
4972
|
+
if (!store || !name) return base;
|
|
4973
|
+
const out = { ...base };
|
|
4974
|
+
for (const key of Object.keys(out)) {
|
|
4975
|
+
const overlayValue = store.get(`${name}.${index}.${key}`);
|
|
4976
|
+
if (overlayValue !== void 0) out[key] = overlayValue;
|
|
4977
|
+
}
|
|
4978
|
+
return out;
|
|
4979
|
+
});
|
|
4980
|
+
const addItem = () => writeItems([...plainItems(), {}]);
|
|
4981
|
+
const removeItem = (index) => writeItems(plainItems().filter((_, i) => i !== index));
|
|
4982
|
+
const moveItem = (index, delta) => {
|
|
4983
|
+
const next = plainItems();
|
|
4984
|
+
const target = index + delta;
|
|
4985
|
+
if (target < 0 || target >= next.length) return;
|
|
4986
|
+
const swap = next[index];
|
|
4987
|
+
next[index] = next[target];
|
|
4988
|
+
next[target] = swap;
|
|
4989
|
+
writeItems(next);
|
|
4990
|
+
};
|
|
4991
|
+
if (!composerEdit) {
|
|
4992
|
+
if (items.length === 0) return null;
|
|
4993
|
+
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, style: { display: "contents" }, children: items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsx(React2__default.default.Fragment, { children: children(item, index) }, item && typeof item === "object" ? `${name}.${index}` : index)) });
|
|
4994
|
+
}
|
|
4995
|
+
if (items.length === 0) {
|
|
4996
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4997
|
+
"span",
|
|
4998
|
+
{
|
|
4999
|
+
className,
|
|
5000
|
+
"data-amplifyup-collection": name || void 0,
|
|
5001
|
+
"data-amplifyup-collection-empty": "true",
|
|
5002
|
+
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
5003
|
+
role: "button",
|
|
5004
|
+
tabIndex: 0,
|
|
5005
|
+
onMouseDown: (event) => event.stopPropagation(),
|
|
5006
|
+
onClick: (event) => {
|
|
5007
|
+
event.preventDefault();
|
|
5008
|
+
event.stopPropagation();
|
|
5009
|
+
addItem();
|
|
5010
|
+
},
|
|
5011
|
+
onKeyDown: (event) => {
|
|
5012
|
+
if (event.key === "Enter" || event.key === " ") {
|
|
5013
|
+
event.preventDefault();
|
|
5014
|
+
addItem();
|
|
5015
|
+
}
|
|
5016
|
+
},
|
|
5017
|
+
style: {
|
|
5018
|
+
display: "block",
|
|
5019
|
+
cursor: "pointer",
|
|
5020
|
+
outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
|
|
5021
|
+
outlineOffset: 2,
|
|
5022
|
+
minHeight: "3em",
|
|
5023
|
+
opacity: 0.5
|
|
5024
|
+
},
|
|
5025
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(EmptySlotHint, { label: COMPOSER_EMPTY_COLLECTION_HINT, compact: true })
|
|
5026
|
+
}
|
|
5027
|
+
);
|
|
5028
|
+
}
|
|
5029
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5030
|
+
"span",
|
|
5031
|
+
{
|
|
5032
|
+
className,
|
|
5033
|
+
"data-amplifyup-collection": name || void 0,
|
|
5034
|
+
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
5035
|
+
style: { display: "flex", flexDirection: "column", gap: 8 },
|
|
5036
|
+
children: [
|
|
5037
|
+
items.map((item, index) => /* @__PURE__ */ jsxRuntime.jsxs(
|
|
5038
|
+
"span",
|
|
5039
|
+
{
|
|
5040
|
+
"data-amplifyup-collection-item": `${name}.${index}`,
|
|
5041
|
+
style: {
|
|
5042
|
+
display: "block",
|
|
5043
|
+
outline: "1px dashed color-mix(in srgb, currentColor 28%, transparent)",
|
|
5044
|
+
outlineOffset: 2,
|
|
5045
|
+
padding: 8
|
|
5046
|
+
},
|
|
5047
|
+
children: [
|
|
5048
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
5049
|
+
"span",
|
|
5050
|
+
{
|
|
5051
|
+
style: {
|
|
5052
|
+
display: "flex",
|
|
5053
|
+
gap: 6,
|
|
5054
|
+
justifyContent: "flex-end",
|
|
5055
|
+
marginBottom: 8
|
|
5056
|
+
},
|
|
5057
|
+
children: [
|
|
5058
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5059
|
+
CollectionChromeButton,
|
|
5060
|
+
{
|
|
5061
|
+
label: "Move up",
|
|
5062
|
+
onClick: () => moveItem(index, -1)
|
|
5063
|
+
}
|
|
5064
|
+
),
|
|
5065
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5066
|
+
CollectionChromeButton,
|
|
5067
|
+
{
|
|
5068
|
+
label: "Move down",
|
|
5069
|
+
onClick: () => moveItem(index, 1)
|
|
5070
|
+
}
|
|
5071
|
+
),
|
|
5072
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
5073
|
+
CollectionChromeButton,
|
|
5074
|
+
{
|
|
5075
|
+
label: "Remove",
|
|
5076
|
+
onClick: () => removeItem(index)
|
|
5077
|
+
}
|
|
5078
|
+
)
|
|
5079
|
+
]
|
|
5080
|
+
}
|
|
5081
|
+
),
|
|
5082
|
+
children(item, index)
|
|
5083
|
+
]
|
|
5084
|
+
},
|
|
5085
|
+
`${name}.${index}`
|
|
5086
|
+
)),
|
|
5087
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { children: /* @__PURE__ */ jsxRuntime.jsx(CollectionChromeButton, { label: "Add item", onClick: addItem }) })
|
|
5088
|
+
]
|
|
5089
|
+
}
|
|
5090
|
+
);
|
|
5091
|
+
}
|
|
4858
5092
|
function markdownToHtml(markdown) {
|
|
4859
5093
|
try {
|
|
4860
5094
|
const result = marked.marked.parse(markdown, { async: false });
|
|
@@ -5246,6 +5480,7 @@ function useAmplifyUp() {
|
|
|
5246
5480
|
exports.AmplifyPageContent = AmplifyPageContent;
|
|
5247
5481
|
exports.AmplifyRenderer = AmplifyRenderer;
|
|
5248
5482
|
exports.AmplifyUpProvider = AmplifyUpProvider;
|
|
5483
|
+
exports.Collection = Collection;
|
|
5249
5484
|
exports.ComponentContextProvider = ComponentContextProvider;
|
|
5250
5485
|
exports.ComposerProvider = ComposerProvider;
|
|
5251
5486
|
exports.Field = Field;
|