@amplifyup/sdk 0.1.63 → 0.1.65
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 +133 -88
- package/dist/AmplifyRenderer.d.mts +40 -4
- package/dist/AmplifyRenderer.d.ts +40 -4
- package/dist/AmplifyRenderer.js +198 -67
- package/dist/AmplifyRenderer.js.map +1 -1
- package/dist/AmplifyRenderer.mjs +199 -68
- package/dist/AmplifyRenderer.mjs.map +1 -1
- package/dist/index.d.mts +8 -3
- package/dist/index.d.ts +8 -3
- package/dist/index.js +146 -28
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +146 -28
- package/dist/index.mjs.map +1 -1
- package/dist/{query-3AXnQgzO.d.ts → query-BLjZYjHJ.d.ts} +4 -3
- package/dist/{query-DIZjc7st.d.mts → query-DuRilU_n.d.mts} +4 -3
- package/dist/react.d.mts +19 -30
- package/dist/react.d.ts +19 -30
- package/dist/react.js +353 -311
- package/dist/react.js.map +1 -1
- package/dist/react.mjs +350 -312
- package/dist/react.mjs.map +1 -1
- package/dist/server.d.mts +3 -3
- package/dist/server.d.ts +3 -3
- package/dist/server.js +146 -28
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +146 -28
- package/dist/server.mjs.map +1 -1
- package/dist/{types-Db_eLrfU.d.mts → types-C32MgOiv.d.mts} +96 -1
- package/dist/{types-Db_eLrfU.d.ts → types-C32MgOiv.d.ts} +96 -1
- package/package.json +1 -1
- package/dist/AmplifyRenderer-Bwob7ICJ.d.ts +0 -93
- package/dist/AmplifyRenderer-TawbUIKZ.d.mts +0 -93
package/dist/react.js
CHANGED
|
@@ -413,6 +413,16 @@ function isComposerPreview() {
|
|
|
413
413
|
|
|
414
414
|
// src/field-envelope.ts
|
|
415
415
|
var FIELDS_BRAND = Symbol("amplifyup.fields");
|
|
416
|
+
var IDENTIFIER_KEYS = /* @__PURE__ */ new Set([
|
|
417
|
+
"id",
|
|
418
|
+
"_id",
|
|
419
|
+
"slug",
|
|
420
|
+
"key",
|
|
421
|
+
"_key",
|
|
422
|
+
"docId",
|
|
423
|
+
"_type",
|
|
424
|
+
"type"
|
|
425
|
+
]);
|
|
416
426
|
function isBrandedFields(value) {
|
|
417
427
|
return !!value && typeof value === "object" && FIELDS_BRAND in value;
|
|
418
428
|
}
|
|
@@ -430,25 +440,88 @@ function isFieldEnvelope(value) {
|
|
|
430
440
|
const rec = value;
|
|
431
441
|
return typeof rec.name === "string" && "value" in rec && !("url" in rec);
|
|
432
442
|
}
|
|
433
|
-
function
|
|
434
|
-
|
|
435
|
-
return "url" in value;
|
|
443
|
+
function isPageResourceSentinel(value) {
|
|
444
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.__amplifyupPageResource === "string";
|
|
436
445
|
}
|
|
437
|
-
function
|
|
446
|
+
function isPortableImageShape(value) {
|
|
438
447
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
448
|
+
if ("url" in value) return true;
|
|
439
449
|
const rec = value;
|
|
440
|
-
return
|
|
450
|
+
return rec._type === "image" || rec.asset != null;
|
|
451
|
+
}
|
|
452
|
+
function isIdentifierKey(key) {
|
|
453
|
+
return IDENTIFIER_KEYS.has(key);
|
|
441
454
|
}
|
|
442
|
-
function
|
|
455
|
+
function isRecordList(value) {
|
|
443
456
|
if (!Array.isArray(value) || value.length === 0) return false;
|
|
444
457
|
const sample = value.find((item) => item != null);
|
|
445
458
|
if (sample === void 0) return false;
|
|
446
459
|
if (typeof sample !== "object" || Array.isArray(sample)) return false;
|
|
447
460
|
if (isPortableImageShape(sample)) return false;
|
|
448
|
-
if (isEntryRefItem(sample)) return false;
|
|
449
461
|
if (sample.$$typeof) return false;
|
|
450
462
|
return true;
|
|
451
463
|
}
|
|
464
|
+
function isFieldRef(value) {
|
|
465
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
466
|
+
const rec = value;
|
|
467
|
+
return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity && typeof rec.id === "string" && !!rec.id;
|
|
468
|
+
}
|
|
469
|
+
function isListOwner(value) {
|
|
470
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
471
|
+
const rec = value;
|
|
472
|
+
return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity;
|
|
473
|
+
}
|
|
474
|
+
function isReadOnlyRowField(value) {
|
|
475
|
+
return isFieldEnvelope(value) && value.readOnly === true && !value.ref;
|
|
476
|
+
}
|
|
477
|
+
function composerStoreKey(name, ref, layoutNodeId) {
|
|
478
|
+
if (isFieldRef(ref)) {
|
|
479
|
+
return `record:${ref.providerId}:${ref.entity}:${ref.id}:${name}`;
|
|
480
|
+
}
|
|
481
|
+
return layoutNodeId ? `page:${layoutNodeId}:${name}` : name;
|
|
482
|
+
}
|
|
483
|
+
function listOwnerFromConnection(conn) {
|
|
484
|
+
if (!conn || typeof conn !== "object") return void 0;
|
|
485
|
+
if (conn.mode === "query") {
|
|
486
|
+
const providerId = String(conn.spec?.providerId || "").trim();
|
|
487
|
+
const entity = String(conn.spec?.entity || "").trim();
|
|
488
|
+
return providerId && entity ? { providerId, entity } : void 0;
|
|
489
|
+
}
|
|
490
|
+
if (conn.mode === "item" || conn.mode === "items") {
|
|
491
|
+
const providerId = String(conn.providerId || "").trim();
|
|
492
|
+
const entity = String(conn.entity || "").trim();
|
|
493
|
+
return providerId && entity ? { providerId, entity } : void 0;
|
|
494
|
+
}
|
|
495
|
+
return void 0;
|
|
496
|
+
}
|
|
497
|
+
function listOwnerFromSpec(spec) {
|
|
498
|
+
const providerId = String(spec?.providerId || "").trim();
|
|
499
|
+
const entity = String(spec?.entity || "").trim();
|
|
500
|
+
return providerId && entity ? { providerId, entity } : void 0;
|
|
501
|
+
}
|
|
502
|
+
function isEnvelopeSources(value) {
|
|
503
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
504
|
+
const rec = value;
|
|
505
|
+
return rec.connections != null || rec.reads != null;
|
|
506
|
+
}
|
|
507
|
+
function normalizeEnvelopeSources(sources) {
|
|
508
|
+
if (!sources) return {};
|
|
509
|
+
if (isEnvelopeSources(sources) && !("mode" in sources)) {
|
|
510
|
+
return sources;
|
|
511
|
+
}
|
|
512
|
+
return { connections: sources };
|
|
513
|
+
}
|
|
514
|
+
function listOwnerForField(fieldName, props, sources) {
|
|
515
|
+
const { connections, reads } = normalizeEnvelopeSources(sources);
|
|
516
|
+
const resourceName = reads?.[fieldName]?.resource || fieldName;
|
|
517
|
+
const fromConn = listOwnerFromConnection(connections?.[resourceName]);
|
|
518
|
+
if (fromConn) return fromConn;
|
|
519
|
+
const paging = props?.[`${fieldName}Pagination`];
|
|
520
|
+
if (paging && typeof paging === "object" && !Array.isArray(paging)) {
|
|
521
|
+
return listOwnerFromSpec(paging.spec);
|
|
522
|
+
}
|
|
523
|
+
return void 0;
|
|
524
|
+
}
|
|
452
525
|
function joinPath(prefix, key) {
|
|
453
526
|
return prefix ? `${prefix}.${key}` : key;
|
|
454
527
|
}
|
|
@@ -456,61 +529,105 @@ function emptyValue(raw) {
|
|
|
456
529
|
if (raw === void 0) return null;
|
|
457
530
|
return raw;
|
|
458
531
|
}
|
|
459
|
-
function
|
|
532
|
+
function rowId(raw) {
|
|
533
|
+
const candidates = [raw.id, raw._id, raw.docId, raw.key, raw._key];
|
|
534
|
+
for (const c of candidates) {
|
|
535
|
+
if (typeof c === "string" && c.trim()) return c;
|
|
536
|
+
}
|
|
537
|
+
return "";
|
|
538
|
+
}
|
|
539
|
+
function withLeaf(envelope, scope) {
|
|
540
|
+
if (isFieldRef(scope?.ref)) envelope.ref = scope.ref;
|
|
541
|
+
else if (scope?.readOnly) envelope.readOnly = true;
|
|
542
|
+
return envelope;
|
|
543
|
+
}
|
|
544
|
+
function toFieldEnvelopes(source, prefix = "", scope) {
|
|
545
|
+
const ctx = isFieldRef(scope) ? { ref: scope } : scope || {};
|
|
460
546
|
const input = source && typeof source === "object" && !Array.isArray(source) ? source : {};
|
|
461
547
|
if (isBrandedFields(input)) {
|
|
462
548
|
return input;
|
|
463
549
|
}
|
|
464
550
|
const out = {};
|
|
465
551
|
for (const [key, raw] of Object.entries(input)) {
|
|
552
|
+
if (isIdentifierKey(key) && (typeof raw === "string" || raw == null)) {
|
|
553
|
+
out[key] = raw ?? "";
|
|
554
|
+
continue;
|
|
555
|
+
}
|
|
466
556
|
const path = joinPath(prefix, key);
|
|
557
|
+
if (isPageResourceSentinel(raw)) {
|
|
558
|
+
out[key] = withLeaf({ value: raw, name: path }, ctx);
|
|
559
|
+
continue;
|
|
560
|
+
}
|
|
467
561
|
if (isFieldEnvelope(raw)) {
|
|
468
562
|
const inner = raw.value;
|
|
469
|
-
if (
|
|
563
|
+
if (isRecordList(inner)) {
|
|
564
|
+
const owner = ctx.owners?.(key);
|
|
470
565
|
out[key] = {
|
|
471
|
-
value:
|
|
566
|
+
value: envelopeListRows(inner, owner),
|
|
472
567
|
name: raw.name || path
|
|
473
568
|
};
|
|
474
569
|
continue;
|
|
475
570
|
}
|
|
476
|
-
out[key] =
|
|
571
|
+
out[key] = withLeaf(
|
|
572
|
+
{ value: raw.value ?? null, name: raw.name || path },
|
|
573
|
+
raw.ref ? { ref: raw.ref } : ctx
|
|
574
|
+
);
|
|
477
575
|
continue;
|
|
478
576
|
}
|
|
479
|
-
if (
|
|
480
|
-
|
|
577
|
+
if (isRecordList(raw)) {
|
|
578
|
+
const owner = ctx.owners?.(key);
|
|
579
|
+
out[key] = { value: envelopeListRows(raw, owner), name: path };
|
|
481
580
|
continue;
|
|
482
581
|
}
|
|
483
582
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
484
|
-
out[key] = toFieldEnvelopes(raw, path);
|
|
583
|
+
out[key] = toFieldEnvelopes(raw, path, ctx);
|
|
485
584
|
continue;
|
|
486
585
|
}
|
|
487
|
-
out[key] = { value: emptyValue(raw), name: path };
|
|
586
|
+
out[key] = withLeaf({ value: emptyValue(raw), name: path }, ctx);
|
|
488
587
|
}
|
|
489
588
|
return brandFields(out);
|
|
490
589
|
}
|
|
491
|
-
function
|
|
492
|
-
return items.map((item
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
590
|
+
function envelopeListRows(items, owner) {
|
|
591
|
+
return items.map((item) => envelopeListRow(item, owner));
|
|
592
|
+
}
|
|
593
|
+
function envelopeListRow(item, owner) {
|
|
594
|
+
if (isBrandedFields(item) && typeof item.id === "string") {
|
|
595
|
+
return item;
|
|
596
|
+
}
|
|
597
|
+
const raw = item && typeof item === "object" && !Array.isArray(item) ? item : {};
|
|
598
|
+
const id = rowId(raw);
|
|
599
|
+
const ref = isListOwner(owner) && id ? { providerId: owner.providerId, entity: owner.entity, id } : void 0;
|
|
600
|
+
const fields = toFieldEnvelopes(raw, "", {
|
|
601
|
+
ref,
|
|
602
|
+
readOnly: !ref
|
|
499
603
|
});
|
|
604
|
+
const row = fields;
|
|
605
|
+
if (typeof row.id !== "string") {
|
|
606
|
+
row.id = id;
|
|
607
|
+
}
|
|
608
|
+
return row;
|
|
500
609
|
}
|
|
501
|
-
function attachFieldEnvelopes(props) {
|
|
610
|
+
function attachFieldEnvelopes(props, sources) {
|
|
502
611
|
const raw = props && typeof props === "object" ? { ...props } : {};
|
|
503
612
|
if (isBrandedFields(raw.fields)) return raw;
|
|
504
613
|
const { fields: existing, ...content } = raw;
|
|
505
614
|
const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
|
|
506
|
-
return {
|
|
615
|
+
return {
|
|
616
|
+
...raw,
|
|
617
|
+
fields: toFieldEnvelopes(source, "", {
|
|
618
|
+
owners: (fieldName) => listOwnerForField(fieldName, source, sources)
|
|
619
|
+
})
|
|
620
|
+
};
|
|
507
621
|
}
|
|
508
622
|
function walkLayoutNodes(nodes) {
|
|
509
623
|
if (!Array.isArray(nodes)) return;
|
|
510
624
|
for (const node of nodes) {
|
|
511
625
|
if (!node || typeof node !== "object") continue;
|
|
512
626
|
const rec = node;
|
|
513
|
-
rec.props = attachFieldEnvelopes(rec.props
|
|
627
|
+
rec.props = attachFieldEnvelopes(rec.props, {
|
|
628
|
+
connections: rec.resources,
|
|
629
|
+
reads: rec.reads
|
|
630
|
+
});
|
|
514
631
|
for (const slot of rec.slots || []) {
|
|
515
632
|
walkLayoutNodes(slot.children);
|
|
516
633
|
}
|
|
@@ -524,31 +641,36 @@ function envelopePageConfig(page) {
|
|
|
524
641
|
}
|
|
525
642
|
function collectFieldPatches(props) {
|
|
526
643
|
const out = [];
|
|
527
|
-
const
|
|
528
|
-
|
|
529
|
-
const itemPath = joinPath(prefix, String(i));
|
|
644
|
+
const walkRows = (items) => {
|
|
645
|
+
for (const item of items) {
|
|
530
646
|
if (isBrandedFields(item) || item && typeof item === "object" && !Array.isArray(item) && !isFieldEnvelope(item)) {
|
|
531
|
-
walk(item,
|
|
647
|
+
walk(item, "");
|
|
532
648
|
}
|
|
533
|
-
}
|
|
649
|
+
}
|
|
534
650
|
};
|
|
535
651
|
const walk = (obj, prefix) => {
|
|
536
652
|
for (const [key, raw] of Object.entries(obj)) {
|
|
653
|
+
if (isIdentifierKey(key)) continue;
|
|
537
654
|
if (key === "fields" && raw && typeof raw === "object" && !Array.isArray(raw) && !isFieldEnvelope(raw)) {
|
|
538
655
|
walk(raw, prefix);
|
|
539
656
|
continue;
|
|
540
657
|
}
|
|
541
658
|
const path = joinPath(prefix, key);
|
|
542
659
|
if (isFieldEnvelope(raw)) {
|
|
543
|
-
if (
|
|
544
|
-
|
|
660
|
+
if (isRecordList(raw.value)) {
|
|
661
|
+
walkRows(raw.value);
|
|
545
662
|
continue;
|
|
546
663
|
}
|
|
547
|
-
|
|
664
|
+
const patch = {
|
|
665
|
+
name: raw.name || path,
|
|
666
|
+
value: raw.value
|
|
667
|
+
};
|
|
668
|
+
if (raw.ref) patch.ref = raw.ref;
|
|
669
|
+
out.push(patch);
|
|
548
670
|
continue;
|
|
549
671
|
}
|
|
550
|
-
if (
|
|
551
|
-
|
|
672
|
+
if (isRecordList(raw)) {
|
|
673
|
+
walkRows(raw);
|
|
552
674
|
continue;
|
|
553
675
|
}
|
|
554
676
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
@@ -563,40 +685,14 @@ function collectFieldPatches(props) {
|
|
|
563
685
|
}
|
|
564
686
|
return out;
|
|
565
687
|
}
|
|
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
|
-
}
|
|
597
688
|
function resolveEditableBinding(field, value, name) {
|
|
598
689
|
if (isFieldEnvelope(field)) {
|
|
599
|
-
return {
|
|
690
|
+
return {
|
|
691
|
+
name: field.name,
|
|
692
|
+
value: field.value,
|
|
693
|
+
ref: field.ref,
|
|
694
|
+
requiresName: false
|
|
695
|
+
};
|
|
600
696
|
}
|
|
601
697
|
return {
|
|
602
698
|
name: name || "",
|
|
@@ -767,7 +863,7 @@ function mergeEventContext(properties, attached) {
|
|
|
767
863
|
};
|
|
768
864
|
}
|
|
769
865
|
var PAGE_RESOURCE_MARKER = "__amplifyupPageResource";
|
|
770
|
-
function
|
|
866
|
+
function isPageResourceSentinel2(value) {
|
|
771
867
|
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value[PAGE_RESOURCE_MARKER] === "string";
|
|
772
868
|
}
|
|
773
869
|
function getByDotPath(source, path) {
|
|
@@ -783,7 +879,7 @@ function getByDotPath(source, path) {
|
|
|
783
879
|
return cur;
|
|
784
880
|
}
|
|
785
881
|
function hydratePageResourceValue(value, fields) {
|
|
786
|
-
if (!
|
|
882
|
+
if (!isPageResourceSentinel2(value)) return value;
|
|
787
883
|
if (!fields) return null;
|
|
788
884
|
if (value.path) return getByDotPath(fields, value.path) ?? null;
|
|
789
885
|
return fields;
|
|
@@ -795,7 +891,7 @@ function hydrateFieldsBag(bag, fields) {
|
|
|
795
891
|
const env = val;
|
|
796
892
|
out[key] = {
|
|
797
893
|
name: env.name,
|
|
798
|
-
value:
|
|
894
|
+
value: isPageResourceSentinel2(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
|
|
799
895
|
};
|
|
800
896
|
continue;
|
|
801
897
|
}
|
|
@@ -803,7 +899,7 @@ function hydrateFieldsBag(bag, fields) {
|
|
|
803
899
|
out[key] = hydrateFieldsBag(val, fields);
|
|
804
900
|
continue;
|
|
805
901
|
}
|
|
806
|
-
out[key] =
|
|
902
|
+
out[key] = isPageResourceSentinel2(val) ? hydratePageResourceValue(val, fields) : val;
|
|
807
903
|
}
|
|
808
904
|
return out;
|
|
809
905
|
}
|
|
@@ -816,7 +912,7 @@ function hydratePageResourceProps(props, fields) {
|
|
|
816
912
|
}
|
|
817
913
|
for (const [key, val] of Object.entries(out)) {
|
|
818
914
|
if (key === "fields") continue;
|
|
819
|
-
if (
|
|
915
|
+
if (isPageResourceSentinel2(val)) {
|
|
820
916
|
out[key] = hydratePageResourceValue(val, fields);
|
|
821
917
|
}
|
|
822
918
|
}
|
|
@@ -955,7 +1051,10 @@ async function fetchEdgeResolve(options) {
|
|
|
955
1051
|
return envelopeResolvedPayload(body);
|
|
956
1052
|
}
|
|
957
1053
|
function envelopeResolvedComponent(node) {
|
|
958
|
-
node.props = attachFieldEnvelopes(node.props
|
|
1054
|
+
node.props = attachFieldEnvelopes(node.props, {
|
|
1055
|
+
connections: node.resources,
|
|
1056
|
+
reads: node.reads
|
|
1057
|
+
});
|
|
959
1058
|
if (!node.children) return;
|
|
960
1059
|
for (const kids of Object.values(node.children)) {
|
|
961
1060
|
for (const child of kids || []) envelopeResolvedComponent(child);
|
|
@@ -1214,7 +1313,7 @@ async function fetchEdgeQuery(options) {
|
|
|
1214
1313
|
async function queryContent(options) {
|
|
1215
1314
|
const target = resolveAmplifyUpTarget({ configTarget: options.target });
|
|
1216
1315
|
const { edgeUrl } = resolveAmplifyUpUrls(target);
|
|
1217
|
-
|
|
1316
|
+
const raw = await fetchEdgeQuery({
|
|
1218
1317
|
edgeUrl,
|
|
1219
1318
|
trackingId: options.trackingId,
|
|
1220
1319
|
route: options.route,
|
|
@@ -1223,6 +1322,13 @@ async function queryContent(options) {
|
|
|
1223
1322
|
fetch: options.fetch,
|
|
1224
1323
|
signal: options.signal
|
|
1225
1324
|
});
|
|
1325
|
+
return {
|
|
1326
|
+
...raw,
|
|
1327
|
+
results: envelopeListRows(
|
|
1328
|
+
raw.results,
|
|
1329
|
+
listOwnerFromSpec(options.spec)
|
|
1330
|
+
)
|
|
1331
|
+
};
|
|
1226
1332
|
}
|
|
1227
1333
|
function nextPageSpec(pagination) {
|
|
1228
1334
|
return { ...pagination.spec, offset: pagination.nextOffset };
|
|
@@ -3719,44 +3825,50 @@ var ComposerFieldStore = class {
|
|
|
3719
3825
|
}
|
|
3720
3826
|
};
|
|
3721
3827
|
var ComposerStoreContext = React2.createContext(null);
|
|
3722
|
-
|
|
3723
|
-
|
|
3724
|
-
|
|
3725
|
-
}
|
|
3726
|
-
return true;
|
|
3828
|
+
var ComposerNodeContext = React2.createContext(void 0);
|
|
3829
|
+
function applyComposerPatch(store, name, value, ref, layoutNodeId) {
|
|
3830
|
+
store.set(composerStoreKey(name, ref, layoutNodeId), value);
|
|
3727
3831
|
}
|
|
3728
3832
|
function ComposerProvider({
|
|
3729
|
-
layoutNodeId,
|
|
3730
3833
|
children
|
|
3731
3834
|
}) {
|
|
3835
|
+
const existing = React2.useContext(ComposerStoreContext);
|
|
3732
3836
|
const storeRef = React2.useRef(null);
|
|
3733
3837
|
if (!storeRef.current) storeRef.current = new ComposerFieldStore();
|
|
3734
|
-
const store = storeRef.current;
|
|
3838
|
+
const store = existing || storeRef.current;
|
|
3735
3839
|
React2.useEffect(() => {
|
|
3736
|
-
|
|
3840
|
+
if (existing) return;
|
|
3841
|
+
const applyField = (fieldName, value, nodeId, ref) => {
|
|
3737
3842
|
if (!fieldName || typeof fieldName !== "string") return;
|
|
3738
|
-
|
|
3739
|
-
|
|
3740
|
-
|
|
3741
|
-
for (const patch of collectFieldPatches(
|
|
3742
|
-
toFieldEnvelopes({ [fieldName]: value })
|
|
3743
|
-
)) {
|
|
3744
|
-
store.set(patch.name, patch.value);
|
|
3745
|
-
}
|
|
3746
|
-
}
|
|
3843
|
+
const fieldRef = isFieldRef(ref) ? ref : void 0;
|
|
3844
|
+
const layoutNodeId = typeof nodeId === "string" && nodeId ? nodeId : void 0;
|
|
3845
|
+
applyComposerPatch(store, fieldName, value, fieldRef, layoutNodeId);
|
|
3747
3846
|
};
|
|
3748
3847
|
const applyProps = (nextProps, nodeId) => {
|
|
3749
3848
|
if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
|
|
3750
3849
|
return;
|
|
3751
3850
|
}
|
|
3752
|
-
|
|
3753
|
-
for (const patch of collectFieldPatches(
|
|
3754
|
-
|
|
3851
|
+
const layoutNodeId = typeof nodeId === "string" && nodeId ? nodeId : void 0;
|
|
3852
|
+
for (const patch of collectFieldPatches(
|
|
3853
|
+
nextProps
|
|
3854
|
+
)) {
|
|
3855
|
+
applyComposerPatch(
|
|
3856
|
+
store,
|
|
3857
|
+
patch.name,
|
|
3858
|
+
patch.value,
|
|
3859
|
+
patch.ref,
|
|
3860
|
+
patch.ref ? void 0 : layoutNodeId
|
|
3861
|
+
);
|
|
3755
3862
|
}
|
|
3756
3863
|
};
|
|
3757
3864
|
const onPatch = (event) => {
|
|
3758
3865
|
const detail = event.detail || {};
|
|
3759
|
-
applyField(
|
|
3866
|
+
applyField(
|
|
3867
|
+
detail.fieldName,
|
|
3868
|
+
detail.value,
|
|
3869
|
+
detail.layoutNodeId,
|
|
3870
|
+
detail.ref
|
|
3871
|
+
);
|
|
3760
3872
|
};
|
|
3761
3873
|
const onPropsPatch = (event) => {
|
|
3762
3874
|
const detail = event.detail || {};
|
|
@@ -3768,7 +3880,12 @@ function ComposerProvider({
|
|
|
3768
3880
|
return;
|
|
3769
3881
|
}
|
|
3770
3882
|
if (event.data?.type !== "AMPLIFYUP_FIELD_PATCH") return;
|
|
3771
|
-
applyField(
|
|
3883
|
+
applyField(
|
|
3884
|
+
event.data.fieldName,
|
|
3885
|
+
event.data.value,
|
|
3886
|
+
event.data.layoutNodeId,
|
|
3887
|
+
event.data.ref
|
|
3888
|
+
);
|
|
3772
3889
|
};
|
|
3773
3890
|
window.addEventListener("amplifyup:field-patch", onPatch);
|
|
3774
3891
|
window.addEventListener("amplifyup:props-patch", onPropsPatch);
|
|
@@ -3778,29 +3895,29 @@ function ComposerProvider({
|
|
|
3778
3895
|
window.removeEventListener("amplifyup:props-patch", onPropsPatch);
|
|
3779
3896
|
window.removeEventListener("message", onMessage);
|
|
3780
3897
|
};
|
|
3781
|
-
}, [
|
|
3898
|
+
}, [existing, store]);
|
|
3899
|
+
if (existing) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
3782
3900
|
return /* @__PURE__ */ jsxRuntime.jsx(ComposerStoreContext.Provider, { value: store, children });
|
|
3783
3901
|
}
|
|
3784
|
-
function useComposerFieldValue(name, fallback) {
|
|
3902
|
+
function useComposerFieldValue(name, fallback, ref) {
|
|
3785
3903
|
const store = React2.useContext(ComposerStoreContext);
|
|
3904
|
+
const layoutNodeId = React2.useContext(ComposerNodeContext);
|
|
3905
|
+
const key = composerStoreKey(name, ref, layoutNodeId);
|
|
3786
3906
|
const subscribe = React2.useCallback(
|
|
3787
3907
|
(onStoreChange) => {
|
|
3788
3908
|
if (!store || !name) return () => {
|
|
3789
3909
|
};
|
|
3790
|
-
return store.subscribe(
|
|
3910
|
+
return store.subscribe(key, onStoreChange);
|
|
3791
3911
|
},
|
|
3792
|
-
[store, name]
|
|
3912
|
+
[store, name, key]
|
|
3793
3913
|
);
|
|
3794
3914
|
const getSnapshot = React2.useCallback(() => {
|
|
3795
3915
|
if (!store || !name) return void 0;
|
|
3796
|
-
return store.get(
|
|
3797
|
-
}, [store, name]);
|
|
3916
|
+
return store.get(key);
|
|
3917
|
+
}, [store, name, key]);
|
|
3798
3918
|
const overlay = React2.useSyncExternalStore(subscribe, getSnapshot, () => void 0);
|
|
3799
3919
|
return overlay !== void 0 ? overlay : fallback;
|
|
3800
3920
|
}
|
|
3801
|
-
function useComposerStore() {
|
|
3802
|
-
return React2.useContext(ComposerStoreContext);
|
|
3803
|
-
}
|
|
3804
3921
|
function MaybeComposerProvider({
|
|
3805
3922
|
enabled,
|
|
3806
3923
|
layoutNodeId,
|
|
@@ -3808,7 +3925,7 @@ function MaybeComposerProvider({
|
|
|
3808
3925
|
}) {
|
|
3809
3926
|
const content = React2.useMemo(() => children, [children]);
|
|
3810
3927
|
if (!enabled) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: content });
|
|
3811
|
-
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { layoutNodeId, children });
|
|
3928
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx(ComposerNodeContext.Provider, { value: layoutNodeId, children }) });
|
|
3812
3929
|
}
|
|
3813
3930
|
function nodeRenderProps(node) {
|
|
3814
3931
|
const settings = node.settings || {};
|
|
@@ -4266,7 +4383,7 @@ function AmplifyRendererInner({
|
|
|
4266
4383
|
if (layoutTree.length === 0) {
|
|
4267
4384
|
return /* @__PURE__ */ jsxRuntime.jsx("main", { children: emptyComponent || /* @__PURE__ */ jsxRuntime.jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsxRuntime.jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
|
|
4268
4385
|
}
|
|
4269
|
-
return /* @__PURE__ */ jsxRuntime.jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4386
|
+
return /* @__PURE__ */ jsxRuntime.jsx(ComposerProvider, { children: /* @__PURE__ */ jsxRuntime.jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsxRuntime.jsx(
|
|
4270
4387
|
"div",
|
|
4271
4388
|
{
|
|
4272
4389
|
"data-slot-id": "main",
|
|
@@ -4275,7 +4392,7 @@ function AmplifyRendererInner({
|
|
|
4275
4392
|
"data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
|
|
4276
4393
|
children: layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(React2.Fragment, { children: renderNode(node) }, node.id))
|
|
4277
4394
|
}
|
|
4278
|
-
) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(React2.Fragment, { children: renderNode(node) }, node.id)) });
|
|
4395
|
+
) : layoutTree.map((node) => /* @__PURE__ */ jsxRuntime.jsx(React2.Fragment, { children: renderNode(node) }, node.id)) }) });
|
|
4279
4396
|
}
|
|
4280
4397
|
var AmplifyRenderer = React2.memo(AmplifyRendererInner);
|
|
4281
4398
|
function AddComponentIcon({ size = 28 }) {
|
|
@@ -4628,10 +4745,10 @@ function useBoundField(field, value, name, component) {
|
|
|
4628
4745
|
`[AmplifyUp SDK] ${component} value={\u2026} requires name="\u2026" for computed values`
|
|
4629
4746
|
);
|
|
4630
4747
|
}
|
|
4631
|
-
const fieldValue = useComposerFieldValue(bound.name, bound.value);
|
|
4632
|
-
return { editName: bound.name, fieldValue };
|
|
4748
|
+
const fieldValue = useComposerFieldValue(bound.name, bound.value, bound.ref);
|
|
4749
|
+
return { editName: bound.name, fieldValue, ref: bound.ref };
|
|
4633
4750
|
}
|
|
4634
|
-
function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
4751
|
+
function commitComposerField(layoutNodeId, componentId, name, value, ref) {
|
|
4635
4752
|
if (typeof window === "undefined" || window.parent === window) return;
|
|
4636
4753
|
window.parent.postMessage(
|
|
4637
4754
|
{
|
|
@@ -4639,7 +4756,8 @@ function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
|
4639
4756
|
layoutNodeId,
|
|
4640
4757
|
componentId,
|
|
4641
4758
|
fieldName: name,
|
|
4642
|
-
value
|
|
4759
|
+
value,
|
|
4760
|
+
...ref ? { ref } : {}
|
|
4643
4761
|
},
|
|
4644
4762
|
"*"
|
|
4645
4763
|
);
|
|
@@ -4664,6 +4782,7 @@ function requestCanvasRichTextEdit(opts) {
|
|
|
4664
4782
|
componentId: opts.componentId,
|
|
4665
4783
|
fieldName: opts.name,
|
|
4666
4784
|
value: opts.value,
|
|
4785
|
+
...opts.fieldRef ? { ref: opts.fieldRef } : {},
|
|
4667
4786
|
bounds: {
|
|
4668
4787
|
top: rect.top,
|
|
4669
4788
|
left: rect.left,
|
|
@@ -4688,6 +4807,7 @@ function ComposerInlineField({
|
|
|
4688
4807
|
className,
|
|
4689
4808
|
layoutNodeId,
|
|
4690
4809
|
componentId,
|
|
4810
|
+
fieldRef,
|
|
4691
4811
|
rich = false
|
|
4692
4812
|
}) {
|
|
4693
4813
|
const [focused, setFocused] = React2.useState(false);
|
|
@@ -4716,12 +4836,12 @@ function ComposerInlineField({
|
|
|
4716
4836
|
if (storedEmpty && next === "") {
|
|
4717
4837
|
if (elRef.current) elRef.current.textContent = hint;
|
|
4718
4838
|
if (typeof value === "string" && EMPTY_FIELD_PLACEHOLDERS.has(value.trim())) {
|
|
4719
|
-
commitComposerField(layoutNodeId, componentId, name, "");
|
|
4839
|
+
commitComposerField(layoutNodeId, componentId, name, "", fieldRef);
|
|
4720
4840
|
}
|
|
4721
4841
|
return;
|
|
4722
4842
|
}
|
|
4723
4843
|
if (next === text) return;
|
|
4724
|
-
commitComposerField(layoutNodeId, componentId, name, next);
|
|
4844
|
+
commitComposerField(layoutNodeId, componentId, name, next, fieldRef);
|
|
4725
4845
|
};
|
|
4726
4846
|
const openRichEditor = (event) => {
|
|
4727
4847
|
if (!isComposerEditMode() || !elRef.current) return;
|
|
@@ -4733,7 +4853,8 @@ function ComposerInlineField({
|
|
|
4733
4853
|
layoutNodeId,
|
|
4734
4854
|
componentId,
|
|
4735
4855
|
name,
|
|
4736
|
-
value: source
|
|
4856
|
+
value: source,
|
|
4857
|
+
fieldRef
|
|
4737
4858
|
});
|
|
4738
4859
|
};
|
|
4739
4860
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -4744,6 +4865,9 @@ function ComposerInlineField({
|
|
|
4744
4865
|
"data-amplifyup-field": name,
|
|
4745
4866
|
"data-amplifyup-field-type": rich ? "richtext" : "text",
|
|
4746
4867
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
4868
|
+
"data-amplifyup-ref-provider": fieldRef?.providerId || void 0,
|
|
4869
|
+
"data-amplifyup-ref-entity": fieldRef?.entity || void 0,
|
|
4870
|
+
"data-amplifyup-ref-id": fieldRef?.id || void 0,
|
|
4747
4871
|
"data-amplifyup-empty-hint": showHint ? "true" : void 0,
|
|
4748
4872
|
contentEditable: !rich,
|
|
4749
4873
|
suppressContentEditableWarning: true,
|
|
@@ -4808,7 +4932,8 @@ function ComposerInlineHtml({
|
|
|
4808
4932
|
className,
|
|
4809
4933
|
Tag = "div",
|
|
4810
4934
|
layoutNodeId,
|
|
4811
|
-
componentId
|
|
4935
|
+
componentId,
|
|
4936
|
+
fieldRef
|
|
4812
4937
|
}) {
|
|
4813
4938
|
const elRef = React2.useRef(null);
|
|
4814
4939
|
React2.useEffect(() => {
|
|
@@ -4825,7 +4950,8 @@ function ComposerInlineHtml({
|
|
|
4825
4950
|
layoutNodeId,
|
|
4826
4951
|
componentId,
|
|
4827
4952
|
name,
|
|
4828
|
-
value: sourceValue
|
|
4953
|
+
value: sourceValue,
|
|
4954
|
+
fieldRef
|
|
4829
4955
|
});
|
|
4830
4956
|
};
|
|
4831
4957
|
return React2__default.default.createElement(Tag, {
|
|
@@ -4834,6 +4960,9 @@ function ComposerInlineHtml({
|
|
|
4834
4960
|
"data-amplifyup-field": name,
|
|
4835
4961
|
"data-amplifyup-field-type": "richtext",
|
|
4836
4962
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
4963
|
+
"data-amplifyup-ref-provider": fieldRef?.providerId || void 0,
|
|
4964
|
+
"data-amplifyup-ref-entity": fieldRef?.entity || void 0,
|
|
4965
|
+
"data-amplifyup-ref-id": fieldRef?.id || void 0,
|
|
4837
4966
|
dangerouslySetInnerHTML: { __html: html },
|
|
4838
4967
|
onMouseDown: (event) => {
|
|
4839
4968
|
event.stopPropagation();
|
|
@@ -4865,6 +4994,40 @@ function formatFieldValue(value) {
|
|
|
4865
4994
|
}
|
|
4866
4995
|
return "";
|
|
4867
4996
|
}
|
|
4997
|
+
var FIELD_SCALAR_HINT = "Field expects a scalar field. Did you mean <Field field={post.title} />?";
|
|
4998
|
+
function warnNotScalarField(component, field, fieldValue) {
|
|
4999
|
+
if (process.env.NODE_ENV === "production") return false;
|
|
5000
|
+
if (isBrandedFields(field)) {
|
|
5001
|
+
console.error(`[AmplifyUp SDK] ${component}: ${FIELD_SCALAR_HINT}`);
|
|
5002
|
+
return true;
|
|
5003
|
+
}
|
|
5004
|
+
if (isFieldEnvelope(field) && Array.isArray(field.value)) {
|
|
5005
|
+
console.error(`[AmplifyUp SDK] ${component}: ${FIELD_SCALAR_HINT}`);
|
|
5006
|
+
return true;
|
|
5007
|
+
}
|
|
5008
|
+
if (Array.isArray(fieldValue)) {
|
|
5009
|
+
console.error(`[AmplifyUp SDK] ${component}: ${FIELD_SCALAR_HINT}`);
|
|
5010
|
+
return true;
|
|
5011
|
+
}
|
|
5012
|
+
return false;
|
|
5013
|
+
}
|
|
5014
|
+
var warnedReadOnlyFields = /* @__PURE__ */ new Set();
|
|
5015
|
+
function warnReadOnlyRowField(name) {
|
|
5016
|
+
if (process.env.NODE_ENV === "production") return;
|
|
5017
|
+
const key = name || "(unnamed)";
|
|
5018
|
+
if (warnedReadOnlyFields.has(key)) return;
|
|
5019
|
+
warnedReadOnlyFields.add(key);
|
|
5020
|
+
console.warn(
|
|
5021
|
+
`[AmplifyUp SDK] ${key} has no write target; rendered read-only.`
|
|
5022
|
+
);
|
|
5023
|
+
}
|
|
5024
|
+
function canComposerBind(field, ref, editName) {
|
|
5025
|
+
if (isReadOnlyRowField(field) || isFieldEnvelope(field) && field.readOnly) {
|
|
5026
|
+
warnReadOnlyRowField(editName || (isFieldEnvelope(field) ? field.name : ""));
|
|
5027
|
+
return false;
|
|
5028
|
+
}
|
|
5029
|
+
return true;
|
|
5030
|
+
}
|
|
4868
5031
|
function warnProjectionProps(component, hasField, hasValue, name) {
|
|
4869
5032
|
if (process.env.NODE_ENV === "production") return;
|
|
4870
5033
|
if (!hasField && !hasValue && !name) {
|
|
@@ -4882,16 +5045,20 @@ function Field(props) {
|
|
|
4882
5045
|
const composerEdit = useComposerEditMode();
|
|
4883
5046
|
const hasField = isFieldEnvelope(field);
|
|
4884
5047
|
const hasValue = hasOwnProp(props, "value");
|
|
4885
|
-
const { editName, fieldValue } = useBoundField(field, value, name, "Field");
|
|
5048
|
+
const { editName, fieldValue, ref } = useBoundField(field, value, name, "Field");
|
|
4886
5049
|
warnProjectionProps("Field", hasField, hasValue, name);
|
|
5050
|
+
if (warnNotScalarField("Field", field, fieldValue)) {
|
|
5051
|
+
return null;
|
|
5052
|
+
}
|
|
4887
5053
|
if (!hasField && !hasValue && !name) {
|
|
4888
5054
|
return null;
|
|
4889
5055
|
}
|
|
4890
|
-
if (Array.isArray(fieldValue)) {
|
|
5056
|
+
if (isBrandedFields(field) || Array.isArray(fieldValue)) {
|
|
4891
5057
|
return null;
|
|
4892
5058
|
}
|
|
4893
5059
|
const empty = isComposerEmptyText(fieldValue);
|
|
4894
|
-
|
|
5060
|
+
const bindComposer = composerEdit && editName && context && canInlineEdit(editName, fieldValue) && canComposerBind(field, ref, editName);
|
|
5061
|
+
if (bindComposer) {
|
|
4895
5062
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
4896
5063
|
ComposerInlineField,
|
|
4897
5064
|
{
|
|
@@ -4900,6 +5067,7 @@ function Field(props) {
|
|
|
4900
5067
|
className,
|
|
4901
5068
|
layoutNodeId: context.layoutNodeId,
|
|
4902
5069
|
componentId: context.componentId,
|
|
5070
|
+
fieldRef: ref,
|
|
4903
5071
|
rich: looksLikeRichCanvasField(editName)
|
|
4904
5072
|
}
|
|
4905
5073
|
);
|
|
@@ -4909,186 +5077,6 @@ function Field(props) {
|
|
|
4909
5077
|
if (!text) return null;
|
|
4910
5078
|
return /* @__PURE__ */ jsxRuntime.jsx("span", { className, children: text });
|
|
4911
5079
|
}
|
|
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
|
-
}
|
|
5092
5080
|
function markdownToHtml(markdown) {
|
|
5093
5081
|
try {
|
|
5094
5082
|
const result = marked.marked.parse(markdown, { async: false });
|
|
@@ -5112,7 +5100,7 @@ function RichText(props) {
|
|
|
5112
5100
|
const hasField = isFieldEnvelope(field);
|
|
5113
5101
|
const hasValueProp = hasOwnProp(props, "value") || childrenValue !== void 0;
|
|
5114
5102
|
const boundValue = hasOwnProp(props, "value") ? value : childrenValue !== void 0 ? childrenValue : value;
|
|
5115
|
-
const { editName, fieldValue } = useBoundField(
|
|
5103
|
+
const { editName, fieldValue, ref } = useBoundField(
|
|
5116
5104
|
field,
|
|
5117
5105
|
boundValue,
|
|
5118
5106
|
name,
|
|
@@ -5122,7 +5110,10 @@ function RichText(props) {
|
|
|
5122
5110
|
return null;
|
|
5123
5111
|
}
|
|
5124
5112
|
warnProjectionProps("RichText", hasField, hasValueProp, name);
|
|
5125
|
-
|
|
5113
|
+
if (warnNotScalarField("RichText", field, fieldValue)) {
|
|
5114
|
+
return null;
|
|
5115
|
+
}
|
|
5116
|
+
const canEdit = !!context && canInlineEditRichText(editName, fieldValue) && canComposerBind(field, ref, editName);
|
|
5126
5117
|
if (isComposerEmptyText(fieldValue)) {
|
|
5127
5118
|
if (composerEdit && canEdit) {
|
|
5128
5119
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -5133,6 +5124,7 @@ function RichText(props) {
|
|
|
5133
5124
|
className,
|
|
5134
5125
|
layoutNodeId: context?.layoutNodeId,
|
|
5135
5126
|
componentId: context?.componentId,
|
|
5127
|
+
fieldRef: ref,
|
|
5136
5128
|
rich: true
|
|
5137
5129
|
}
|
|
5138
5130
|
);
|
|
@@ -5164,7 +5156,8 @@ function RichText(props) {
|
|
|
5164
5156
|
className,
|
|
5165
5157
|
Tag,
|
|
5166
5158
|
layoutNodeId: context?.layoutNodeId,
|
|
5167
|
-
componentId: context?.componentId
|
|
5159
|
+
componentId: context?.componentId,
|
|
5160
|
+
fieldRef: ref
|
|
5168
5161
|
}
|
|
5169
5162
|
);
|
|
5170
5163
|
}
|
|
@@ -5180,6 +5173,38 @@ function imageSrc(value) {
|
|
|
5180
5173
|
if (isPortableImageValue(value)) return value.url.trim();
|
|
5181
5174
|
return "";
|
|
5182
5175
|
}
|
|
5176
|
+
function leafText(field) {
|
|
5177
|
+
if (isFieldEnvelope(field)) return field.value;
|
|
5178
|
+
return field;
|
|
5179
|
+
}
|
|
5180
|
+
function coerceImageField(field, value, name) {
|
|
5181
|
+
if (isFieldEnvelope(field)) return { field, value, name };
|
|
5182
|
+
if (!isBrandedFields(field) || !field || typeof field !== "object") {
|
|
5183
|
+
return { field: void 0, value, name };
|
|
5184
|
+
}
|
|
5185
|
+
const bag = field;
|
|
5186
|
+
const urlField = bag.url;
|
|
5187
|
+
const urlName = isFieldEnvelope(urlField) && typeof urlField.name === "string" ? urlField.name.replace(/\.url$/, "") : "";
|
|
5188
|
+
const editName = urlName || name || "";
|
|
5189
|
+
if (!editName) return { field: void 0, value, name };
|
|
5190
|
+
const ref = isFieldEnvelope(urlField) ? urlField.ref : void 0;
|
|
5191
|
+
const width = leafText(bag.width);
|
|
5192
|
+
const height = leafText(bag.height);
|
|
5193
|
+
return {
|
|
5194
|
+
field: {
|
|
5195
|
+
value: {
|
|
5196
|
+
url: String(leafText(urlField) ?? ""),
|
|
5197
|
+
alt: leafText(bag.alt),
|
|
5198
|
+
...typeof width === "number" ? { width } : {},
|
|
5199
|
+
...typeof height === "number" ? { height } : {}
|
|
5200
|
+
},
|
|
5201
|
+
name: editName,
|
|
5202
|
+
...ref ? { ref } : {}
|
|
5203
|
+
},
|
|
5204
|
+
value,
|
|
5205
|
+
name: editName
|
|
5206
|
+
};
|
|
5207
|
+
}
|
|
5183
5208
|
function Image(props) {
|
|
5184
5209
|
const {
|
|
5185
5210
|
field,
|
|
@@ -5192,12 +5217,22 @@ function Image(props) {
|
|
|
5192
5217
|
...imgProps
|
|
5193
5218
|
} = props;
|
|
5194
5219
|
const context = React2.useContext(ComponentContext);
|
|
5195
|
-
const
|
|
5220
|
+
const coerced = coerceImageField(field, value, name);
|
|
5221
|
+
const boundField = coerced.field;
|
|
5222
|
+
const hasField = isFieldEnvelope(boundField);
|
|
5196
5223
|
const hasValue = hasOwnProp(props, "value");
|
|
5197
|
-
const { editName, fieldValue } = useBoundField(
|
|
5224
|
+
const { editName, fieldValue, ref } = useBoundField(
|
|
5225
|
+
boundField,
|
|
5226
|
+
coerced.value,
|
|
5227
|
+
coerced.name,
|
|
5228
|
+
"Image"
|
|
5229
|
+
);
|
|
5198
5230
|
const composerEdit = useComposerEditMode();
|
|
5199
|
-
warnProjectionProps("Image", hasField, hasValue, name);
|
|
5200
|
-
if (!
|
|
5231
|
+
warnProjectionProps("Image", hasField || isBrandedFields(field), hasValue, coerced.name || name);
|
|
5232
|
+
if (!isBrandedFields(field) && warnNotScalarField("Image", boundField, fieldValue)) {
|
|
5233
|
+
return null;
|
|
5234
|
+
}
|
|
5235
|
+
if (!hasField && !hasValue && !name && !editName) {
|
|
5201
5236
|
return null;
|
|
5202
5237
|
}
|
|
5203
5238
|
const src = imageSrc(fieldValue);
|
|
@@ -5205,10 +5240,13 @@ function Image(props) {
|
|
|
5205
5240
|
const alt = altProp ?? portable?.alt ?? "";
|
|
5206
5241
|
const width = widthProp ?? portable?.width;
|
|
5207
5242
|
const height = heightProp ?? portable?.height;
|
|
5208
|
-
const fieldAttrs = composerEdit && editName ? {
|
|
5243
|
+
const fieldAttrs = composerEdit && editName && canComposerBind(boundField, ref, editName) ? {
|
|
5209
5244
|
"data-amplifyup-field": editName,
|
|
5210
5245
|
"data-amplifyup-field-type": "image",
|
|
5211
|
-
"data-amplifyup-node-id": context?.layoutNodeId || void 0
|
|
5246
|
+
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
5247
|
+
"data-amplifyup-ref-provider": ref?.providerId || void 0,
|
|
5248
|
+
"data-amplifyup-ref-entity": ref?.entity || void 0,
|
|
5249
|
+
"data-amplifyup-ref-id": ref?.id || void 0
|
|
5212
5250
|
} : null;
|
|
5213
5251
|
if (composerEdit && !editName && (hasField || hasValue)) {
|
|
5214
5252
|
console.warn(
|
|
@@ -5480,7 +5518,6 @@ function useAmplifyUp() {
|
|
|
5480
5518
|
exports.AmplifyPageContent = AmplifyPageContent;
|
|
5481
5519
|
exports.AmplifyRenderer = AmplifyRenderer;
|
|
5482
5520
|
exports.AmplifyUpProvider = AmplifyUpProvider;
|
|
5483
|
-
exports.Collection = Collection;
|
|
5484
5521
|
exports.ComponentContextProvider = ComponentContextProvider;
|
|
5485
5522
|
exports.ComposerProvider = ComposerProvider;
|
|
5486
5523
|
exports.Field = Field;
|
|
@@ -5490,11 +5527,16 @@ exports.QueryContentError = QueryContentError;
|
|
|
5490
5527
|
exports.RichText = RichText;
|
|
5491
5528
|
exports.SelectVariantsError = SelectVariantsError;
|
|
5492
5529
|
exports.Slot = Slot;
|
|
5530
|
+
exports.attachFieldEnvelopes = attachFieldEnvelopes;
|
|
5531
|
+
exports.composerStoreKey = composerStoreKey;
|
|
5532
|
+
exports.envelopeListRows = envelopeListRows;
|
|
5493
5533
|
exports.isBrandedFields = isBrandedFields;
|
|
5494
5534
|
exports.isComposerPreview = isComposerPreview;
|
|
5495
5535
|
exports.isFieldEnvelope = isFieldEnvelope;
|
|
5496
5536
|
exports.isPreviewRequest = isPreviewRequest;
|
|
5537
|
+
exports.isReadOnlyRowField = isReadOnlyRowField;
|
|
5497
5538
|
exports.isWorkingContentRequest = isWorkingContentRequest;
|
|
5539
|
+
exports.listOwnerFromSpec = listOwnerFromSpec;
|
|
5498
5540
|
exports.nextPageSpec = nextPageSpec;
|
|
5499
5541
|
exports.queryContent = queryContent;
|
|
5500
5542
|
exports.searchSpec = searchSpec;
|