@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.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
'use client';
|
|
2
|
-
import React2, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, Component, useMemo,
|
|
2
|
+
import React2, { createContext, memo, useState, useEffect, Fragment as Fragment$1, useContext, useRef, Component, useMemo, useSyncExternalStore, useCallback } from 'react';
|
|
3
3
|
import { jsx, Fragment, jsxs } from 'react/jsx-runtime';
|
|
4
4
|
import { marked } from 'marked';
|
|
5
5
|
|
|
@@ -407,6 +407,16 @@ function isComposerPreview() {
|
|
|
407
407
|
|
|
408
408
|
// src/field-envelope.ts
|
|
409
409
|
var FIELDS_BRAND = Symbol("amplifyup.fields");
|
|
410
|
+
var IDENTIFIER_KEYS = /* @__PURE__ */ new Set([
|
|
411
|
+
"id",
|
|
412
|
+
"_id",
|
|
413
|
+
"slug",
|
|
414
|
+
"key",
|
|
415
|
+
"_key",
|
|
416
|
+
"docId",
|
|
417
|
+
"_type",
|
|
418
|
+
"type"
|
|
419
|
+
]);
|
|
410
420
|
function isBrandedFields(value) {
|
|
411
421
|
return !!value && typeof value === "object" && FIELDS_BRAND in value;
|
|
412
422
|
}
|
|
@@ -424,25 +434,88 @@ function isFieldEnvelope(value) {
|
|
|
424
434
|
const rec = value;
|
|
425
435
|
return typeof rec.name === "string" && "value" in rec && !("url" in rec);
|
|
426
436
|
}
|
|
427
|
-
function
|
|
428
|
-
|
|
429
|
-
return "url" in value;
|
|
437
|
+
function isPageResourceSentinel(value) {
|
|
438
|
+
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value.__amplifyupPageResource === "string";
|
|
430
439
|
}
|
|
431
|
-
function
|
|
440
|
+
function isPortableImageShape(value) {
|
|
432
441
|
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
442
|
+
if ("url" in value) return true;
|
|
433
443
|
const rec = value;
|
|
434
|
-
return
|
|
444
|
+
return rec._type === "image" || rec.asset != null;
|
|
445
|
+
}
|
|
446
|
+
function isIdentifierKey(key) {
|
|
447
|
+
return IDENTIFIER_KEYS.has(key);
|
|
435
448
|
}
|
|
436
|
-
function
|
|
449
|
+
function isRecordList(value) {
|
|
437
450
|
if (!Array.isArray(value) || value.length === 0) return false;
|
|
438
451
|
const sample = value.find((item) => item != null);
|
|
439
452
|
if (sample === void 0) return false;
|
|
440
453
|
if (typeof sample !== "object" || Array.isArray(sample)) return false;
|
|
441
454
|
if (isPortableImageShape(sample)) return false;
|
|
442
|
-
if (isEntryRefItem(sample)) return false;
|
|
443
455
|
if (sample.$$typeof) return false;
|
|
444
456
|
return true;
|
|
445
457
|
}
|
|
458
|
+
function isFieldRef(value) {
|
|
459
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
460
|
+
const rec = value;
|
|
461
|
+
return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity && typeof rec.id === "string" && !!rec.id;
|
|
462
|
+
}
|
|
463
|
+
function isListOwner(value) {
|
|
464
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
465
|
+
const rec = value;
|
|
466
|
+
return typeof rec.providerId === "string" && !!rec.providerId && typeof rec.entity === "string" && !!rec.entity;
|
|
467
|
+
}
|
|
468
|
+
function isReadOnlyRowField(value) {
|
|
469
|
+
return isFieldEnvelope(value) && value.readOnly === true && !value.ref;
|
|
470
|
+
}
|
|
471
|
+
function composerStoreKey(name, ref, layoutNodeId) {
|
|
472
|
+
if (isFieldRef(ref)) {
|
|
473
|
+
return `record:${ref.providerId}:${ref.entity}:${ref.id}:${name}`;
|
|
474
|
+
}
|
|
475
|
+
return layoutNodeId ? `page:${layoutNodeId}:${name}` : name;
|
|
476
|
+
}
|
|
477
|
+
function listOwnerFromConnection(conn) {
|
|
478
|
+
if (!conn || typeof conn !== "object") return void 0;
|
|
479
|
+
if (conn.mode === "query") {
|
|
480
|
+
const providerId = String(conn.spec?.providerId || "").trim();
|
|
481
|
+
const entity = String(conn.spec?.entity || "").trim();
|
|
482
|
+
return providerId && entity ? { providerId, entity } : void 0;
|
|
483
|
+
}
|
|
484
|
+
if (conn.mode === "item" || conn.mode === "items") {
|
|
485
|
+
const providerId = String(conn.providerId || "").trim();
|
|
486
|
+
const entity = String(conn.entity || "").trim();
|
|
487
|
+
return providerId && entity ? { providerId, entity } : void 0;
|
|
488
|
+
}
|
|
489
|
+
return void 0;
|
|
490
|
+
}
|
|
491
|
+
function listOwnerFromSpec(spec) {
|
|
492
|
+
const providerId = String(spec?.providerId || "").trim();
|
|
493
|
+
const entity = String(spec?.entity || "").trim();
|
|
494
|
+
return providerId && entity ? { providerId, entity } : void 0;
|
|
495
|
+
}
|
|
496
|
+
function isEnvelopeSources(value) {
|
|
497
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) return false;
|
|
498
|
+
const rec = value;
|
|
499
|
+
return rec.connections != null || rec.reads != null;
|
|
500
|
+
}
|
|
501
|
+
function normalizeEnvelopeSources(sources) {
|
|
502
|
+
if (!sources) return {};
|
|
503
|
+
if (isEnvelopeSources(sources) && !("mode" in sources)) {
|
|
504
|
+
return sources;
|
|
505
|
+
}
|
|
506
|
+
return { connections: sources };
|
|
507
|
+
}
|
|
508
|
+
function listOwnerForField(fieldName, props, sources) {
|
|
509
|
+
const { connections, reads } = normalizeEnvelopeSources(sources);
|
|
510
|
+
const resourceName = reads?.[fieldName]?.resource || fieldName;
|
|
511
|
+
const fromConn = listOwnerFromConnection(connections?.[resourceName]);
|
|
512
|
+
if (fromConn) return fromConn;
|
|
513
|
+
const paging = props?.[`${fieldName}Pagination`];
|
|
514
|
+
if (paging && typeof paging === "object" && !Array.isArray(paging)) {
|
|
515
|
+
return listOwnerFromSpec(paging.spec);
|
|
516
|
+
}
|
|
517
|
+
return void 0;
|
|
518
|
+
}
|
|
446
519
|
function joinPath(prefix, key) {
|
|
447
520
|
return prefix ? `${prefix}.${key}` : key;
|
|
448
521
|
}
|
|
@@ -450,61 +523,105 @@ function emptyValue(raw) {
|
|
|
450
523
|
if (raw === void 0) return null;
|
|
451
524
|
return raw;
|
|
452
525
|
}
|
|
453
|
-
function
|
|
526
|
+
function rowId(raw) {
|
|
527
|
+
const candidates = [raw.id, raw._id, raw.docId, raw.key, raw._key];
|
|
528
|
+
for (const c of candidates) {
|
|
529
|
+
if (typeof c === "string" && c.trim()) return c;
|
|
530
|
+
}
|
|
531
|
+
return "";
|
|
532
|
+
}
|
|
533
|
+
function withLeaf(envelope, scope) {
|
|
534
|
+
if (isFieldRef(scope?.ref)) envelope.ref = scope.ref;
|
|
535
|
+
else if (scope?.readOnly) envelope.readOnly = true;
|
|
536
|
+
return envelope;
|
|
537
|
+
}
|
|
538
|
+
function toFieldEnvelopes(source, prefix = "", scope) {
|
|
539
|
+
const ctx = isFieldRef(scope) ? { ref: scope } : scope || {};
|
|
454
540
|
const input = source && typeof source === "object" && !Array.isArray(source) ? source : {};
|
|
455
541
|
if (isBrandedFields(input)) {
|
|
456
542
|
return input;
|
|
457
543
|
}
|
|
458
544
|
const out = {};
|
|
459
545
|
for (const [key, raw] of Object.entries(input)) {
|
|
546
|
+
if (isIdentifierKey(key) && (typeof raw === "string" || raw == null)) {
|
|
547
|
+
out[key] = raw ?? "";
|
|
548
|
+
continue;
|
|
549
|
+
}
|
|
460
550
|
const path = joinPath(prefix, key);
|
|
551
|
+
if (isPageResourceSentinel(raw)) {
|
|
552
|
+
out[key] = withLeaf({ value: raw, name: path }, ctx);
|
|
553
|
+
continue;
|
|
554
|
+
}
|
|
461
555
|
if (isFieldEnvelope(raw)) {
|
|
462
556
|
const inner = raw.value;
|
|
463
|
-
if (
|
|
557
|
+
if (isRecordList(inner)) {
|
|
558
|
+
const owner = ctx.owners?.(key);
|
|
464
559
|
out[key] = {
|
|
465
|
-
value:
|
|
560
|
+
value: envelopeListRows(inner, owner),
|
|
466
561
|
name: raw.name || path
|
|
467
562
|
};
|
|
468
563
|
continue;
|
|
469
564
|
}
|
|
470
|
-
out[key] =
|
|
565
|
+
out[key] = withLeaf(
|
|
566
|
+
{ value: raw.value ?? null, name: raw.name || path },
|
|
567
|
+
raw.ref ? { ref: raw.ref } : ctx
|
|
568
|
+
);
|
|
471
569
|
continue;
|
|
472
570
|
}
|
|
473
|
-
if (
|
|
474
|
-
|
|
571
|
+
if (isRecordList(raw)) {
|
|
572
|
+
const owner = ctx.owners?.(key);
|
|
573
|
+
out[key] = { value: envelopeListRows(raw, owner), name: path };
|
|
475
574
|
continue;
|
|
476
575
|
}
|
|
477
576
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
478
|
-
out[key] = toFieldEnvelopes(raw, path);
|
|
577
|
+
out[key] = toFieldEnvelopes(raw, path, ctx);
|
|
479
578
|
continue;
|
|
480
579
|
}
|
|
481
|
-
out[key] = { value: emptyValue(raw), name: path };
|
|
580
|
+
out[key] = withLeaf({ value: emptyValue(raw), name: path }, ctx);
|
|
482
581
|
}
|
|
483
582
|
return brandFields(out);
|
|
484
583
|
}
|
|
485
|
-
function
|
|
486
|
-
return items.map((item
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
584
|
+
function envelopeListRows(items, owner) {
|
|
585
|
+
return items.map((item) => envelopeListRow(item, owner));
|
|
586
|
+
}
|
|
587
|
+
function envelopeListRow(item, owner) {
|
|
588
|
+
if (isBrandedFields(item) && typeof item.id === "string") {
|
|
589
|
+
return item;
|
|
590
|
+
}
|
|
591
|
+
const raw = item && typeof item === "object" && !Array.isArray(item) ? item : {};
|
|
592
|
+
const id = rowId(raw);
|
|
593
|
+
const ref = isListOwner(owner) && id ? { providerId: owner.providerId, entity: owner.entity, id } : void 0;
|
|
594
|
+
const fields = toFieldEnvelopes(raw, "", {
|
|
595
|
+
ref,
|
|
596
|
+
readOnly: !ref
|
|
493
597
|
});
|
|
598
|
+
const row = fields;
|
|
599
|
+
if (typeof row.id !== "string") {
|
|
600
|
+
row.id = id;
|
|
601
|
+
}
|
|
602
|
+
return row;
|
|
494
603
|
}
|
|
495
|
-
function attachFieldEnvelopes(props) {
|
|
604
|
+
function attachFieldEnvelopes(props, sources) {
|
|
496
605
|
const raw = props && typeof props === "object" ? { ...props } : {};
|
|
497
606
|
if (isBrandedFields(raw.fields)) return raw;
|
|
498
607
|
const { fields: existing, ...content } = raw;
|
|
499
608
|
const source = existing && typeof existing === "object" && !isFieldEnvelope(existing) ? existing : content;
|
|
500
|
-
return {
|
|
609
|
+
return {
|
|
610
|
+
...raw,
|
|
611
|
+
fields: toFieldEnvelopes(source, "", {
|
|
612
|
+
owners: (fieldName) => listOwnerForField(fieldName, source, sources)
|
|
613
|
+
})
|
|
614
|
+
};
|
|
501
615
|
}
|
|
502
616
|
function walkLayoutNodes(nodes) {
|
|
503
617
|
if (!Array.isArray(nodes)) return;
|
|
504
618
|
for (const node of nodes) {
|
|
505
619
|
if (!node || typeof node !== "object") continue;
|
|
506
620
|
const rec = node;
|
|
507
|
-
rec.props = attachFieldEnvelopes(rec.props
|
|
621
|
+
rec.props = attachFieldEnvelopes(rec.props, {
|
|
622
|
+
connections: rec.resources,
|
|
623
|
+
reads: rec.reads
|
|
624
|
+
});
|
|
508
625
|
for (const slot of rec.slots || []) {
|
|
509
626
|
walkLayoutNodes(slot.children);
|
|
510
627
|
}
|
|
@@ -518,31 +635,36 @@ function envelopePageConfig(page) {
|
|
|
518
635
|
}
|
|
519
636
|
function collectFieldPatches(props) {
|
|
520
637
|
const out = [];
|
|
521
|
-
const
|
|
522
|
-
|
|
523
|
-
const itemPath = joinPath(prefix, String(i));
|
|
638
|
+
const walkRows = (items) => {
|
|
639
|
+
for (const item of items) {
|
|
524
640
|
if (isBrandedFields(item) || item && typeof item === "object" && !Array.isArray(item) && !isFieldEnvelope(item)) {
|
|
525
|
-
walk(item,
|
|
641
|
+
walk(item, "");
|
|
526
642
|
}
|
|
527
|
-
}
|
|
643
|
+
}
|
|
528
644
|
};
|
|
529
645
|
const walk = (obj, prefix) => {
|
|
530
646
|
for (const [key, raw] of Object.entries(obj)) {
|
|
647
|
+
if (isIdentifierKey(key)) continue;
|
|
531
648
|
if (key === "fields" && raw && typeof raw === "object" && !Array.isArray(raw) && !isFieldEnvelope(raw)) {
|
|
532
649
|
walk(raw, prefix);
|
|
533
650
|
continue;
|
|
534
651
|
}
|
|
535
652
|
const path = joinPath(prefix, key);
|
|
536
653
|
if (isFieldEnvelope(raw)) {
|
|
537
|
-
if (
|
|
538
|
-
|
|
654
|
+
if (isRecordList(raw.value)) {
|
|
655
|
+
walkRows(raw.value);
|
|
539
656
|
continue;
|
|
540
657
|
}
|
|
541
|
-
|
|
658
|
+
const patch = {
|
|
659
|
+
name: raw.name || path,
|
|
660
|
+
value: raw.value
|
|
661
|
+
};
|
|
662
|
+
if (raw.ref) patch.ref = raw.ref;
|
|
663
|
+
out.push(patch);
|
|
542
664
|
continue;
|
|
543
665
|
}
|
|
544
|
-
if (
|
|
545
|
-
|
|
666
|
+
if (isRecordList(raw)) {
|
|
667
|
+
walkRows(raw);
|
|
546
668
|
continue;
|
|
547
669
|
}
|
|
548
670
|
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !raw.$$typeof) {
|
|
@@ -557,40 +679,14 @@ function collectFieldPatches(props) {
|
|
|
557
679
|
}
|
|
558
680
|
return out;
|
|
559
681
|
}
|
|
560
|
-
function unwrapFieldsBag(item) {
|
|
561
|
-
if (!item || typeof item !== "object" || Array.isArray(item)) return {};
|
|
562
|
-
const out = {};
|
|
563
|
-
for (const [key, raw] of Object.entries(item)) {
|
|
564
|
-
if (isFieldEnvelope(raw)) {
|
|
565
|
-
out[key] = raw.value;
|
|
566
|
-
continue;
|
|
567
|
-
}
|
|
568
|
-
if (raw && typeof raw === "object" && !Array.isArray(raw) && !isPortableImageShape(raw) && !isEntryRefItem(raw) && !raw.$$typeof) {
|
|
569
|
-
out[key] = unwrapFieldsBag(raw);
|
|
570
|
-
continue;
|
|
571
|
-
}
|
|
572
|
-
out[key] = raw;
|
|
573
|
-
}
|
|
574
|
-
return out;
|
|
575
|
-
}
|
|
576
|
-
function resolveCollectionItems(field, overlay) {
|
|
577
|
-
const name = typeof field?.name === "string" ? field.name : "";
|
|
578
|
-
const raw = overlay !== void 0 ? overlay : field?.value;
|
|
579
|
-
const list = Array.isArray(raw) ? raw : isFieldEnvelope(raw) && Array.isArray(raw.value) ? raw.value : [];
|
|
580
|
-
if (list.length === 0) return [];
|
|
581
|
-
if (isRepeaterArray(list) || list.every((item) => isBrandedFields(item))) {
|
|
582
|
-
return envelopeRepeaterItems(list, name);
|
|
583
|
-
}
|
|
584
|
-
return envelopeRepeaterItems(
|
|
585
|
-
list.map(
|
|
586
|
-
(item) => item && typeof item === "object" && !Array.isArray(item) ? item : {}
|
|
587
|
-
),
|
|
588
|
-
name
|
|
589
|
-
);
|
|
590
|
-
}
|
|
591
682
|
function resolveEditableBinding(field, value, name) {
|
|
592
683
|
if (isFieldEnvelope(field)) {
|
|
593
|
-
return {
|
|
684
|
+
return {
|
|
685
|
+
name: field.name,
|
|
686
|
+
value: field.value,
|
|
687
|
+
ref: field.ref,
|
|
688
|
+
requiresName: false
|
|
689
|
+
};
|
|
594
690
|
}
|
|
595
691
|
return {
|
|
596
692
|
name: name || "",
|
|
@@ -761,7 +857,7 @@ function mergeEventContext(properties, attached) {
|
|
|
761
857
|
};
|
|
762
858
|
}
|
|
763
859
|
var PAGE_RESOURCE_MARKER = "__amplifyupPageResource";
|
|
764
|
-
function
|
|
860
|
+
function isPageResourceSentinel2(value) {
|
|
765
861
|
return !!value && typeof value === "object" && !Array.isArray(value) && typeof value[PAGE_RESOURCE_MARKER] === "string";
|
|
766
862
|
}
|
|
767
863
|
function getByDotPath(source, path) {
|
|
@@ -777,7 +873,7 @@ function getByDotPath(source, path) {
|
|
|
777
873
|
return cur;
|
|
778
874
|
}
|
|
779
875
|
function hydratePageResourceValue(value, fields) {
|
|
780
|
-
if (!
|
|
876
|
+
if (!isPageResourceSentinel2(value)) return value;
|
|
781
877
|
if (!fields) return null;
|
|
782
878
|
if (value.path) return getByDotPath(fields, value.path) ?? null;
|
|
783
879
|
return fields;
|
|
@@ -789,7 +885,7 @@ function hydrateFieldsBag(bag, fields) {
|
|
|
789
885
|
const env = val;
|
|
790
886
|
out[key] = {
|
|
791
887
|
name: env.name,
|
|
792
|
-
value:
|
|
888
|
+
value: isPageResourceSentinel2(env.value) ? hydratePageResourceValue(env.value, fields) : env.value
|
|
793
889
|
};
|
|
794
890
|
continue;
|
|
795
891
|
}
|
|
@@ -797,7 +893,7 @@ function hydrateFieldsBag(bag, fields) {
|
|
|
797
893
|
out[key] = hydrateFieldsBag(val, fields);
|
|
798
894
|
continue;
|
|
799
895
|
}
|
|
800
|
-
out[key] =
|
|
896
|
+
out[key] = isPageResourceSentinel2(val) ? hydratePageResourceValue(val, fields) : val;
|
|
801
897
|
}
|
|
802
898
|
return out;
|
|
803
899
|
}
|
|
@@ -810,7 +906,7 @@ function hydratePageResourceProps(props, fields) {
|
|
|
810
906
|
}
|
|
811
907
|
for (const [key, val] of Object.entries(out)) {
|
|
812
908
|
if (key === "fields") continue;
|
|
813
|
-
if (
|
|
909
|
+
if (isPageResourceSentinel2(val)) {
|
|
814
910
|
out[key] = hydratePageResourceValue(val, fields);
|
|
815
911
|
}
|
|
816
912
|
}
|
|
@@ -949,7 +1045,10 @@ async function fetchEdgeResolve(options) {
|
|
|
949
1045
|
return envelopeResolvedPayload(body);
|
|
950
1046
|
}
|
|
951
1047
|
function envelopeResolvedComponent(node) {
|
|
952
|
-
node.props = attachFieldEnvelopes(node.props
|
|
1048
|
+
node.props = attachFieldEnvelopes(node.props, {
|
|
1049
|
+
connections: node.resources,
|
|
1050
|
+
reads: node.reads
|
|
1051
|
+
});
|
|
953
1052
|
if (!node.children) return;
|
|
954
1053
|
for (const kids of Object.values(node.children)) {
|
|
955
1054
|
for (const child of kids || []) envelopeResolvedComponent(child);
|
|
@@ -1208,7 +1307,7 @@ async function fetchEdgeQuery(options) {
|
|
|
1208
1307
|
async function queryContent(options) {
|
|
1209
1308
|
const target = resolveAmplifyUpTarget({ configTarget: options.target });
|
|
1210
1309
|
const { edgeUrl } = resolveAmplifyUpUrls(target);
|
|
1211
|
-
|
|
1310
|
+
const raw = await fetchEdgeQuery({
|
|
1212
1311
|
edgeUrl,
|
|
1213
1312
|
trackingId: options.trackingId,
|
|
1214
1313
|
route: options.route,
|
|
@@ -1217,6 +1316,13 @@ async function queryContent(options) {
|
|
|
1217
1316
|
fetch: options.fetch,
|
|
1218
1317
|
signal: options.signal
|
|
1219
1318
|
});
|
|
1319
|
+
return {
|
|
1320
|
+
...raw,
|
|
1321
|
+
results: envelopeListRows(
|
|
1322
|
+
raw.results,
|
|
1323
|
+
listOwnerFromSpec(options.spec)
|
|
1324
|
+
)
|
|
1325
|
+
};
|
|
1220
1326
|
}
|
|
1221
1327
|
function nextPageSpec(pagination) {
|
|
1222
1328
|
return { ...pagination.spec, offset: pagination.nextOffset };
|
|
@@ -3713,44 +3819,50 @@ var ComposerFieldStore = class {
|
|
|
3713
3819
|
}
|
|
3714
3820
|
};
|
|
3715
3821
|
var ComposerStoreContext = createContext(null);
|
|
3716
|
-
|
|
3717
|
-
|
|
3718
|
-
|
|
3719
|
-
}
|
|
3720
|
-
return true;
|
|
3822
|
+
var ComposerNodeContext = createContext(void 0);
|
|
3823
|
+
function applyComposerPatch(store, name, value, ref, layoutNodeId) {
|
|
3824
|
+
store.set(composerStoreKey(name, ref, layoutNodeId), value);
|
|
3721
3825
|
}
|
|
3722
3826
|
function ComposerProvider({
|
|
3723
|
-
layoutNodeId,
|
|
3724
3827
|
children
|
|
3725
3828
|
}) {
|
|
3829
|
+
const existing = useContext(ComposerStoreContext);
|
|
3726
3830
|
const storeRef = useRef(null);
|
|
3727
3831
|
if (!storeRef.current) storeRef.current = new ComposerFieldStore();
|
|
3728
|
-
const store = storeRef.current;
|
|
3832
|
+
const store = existing || storeRef.current;
|
|
3729
3833
|
useEffect(() => {
|
|
3730
|
-
|
|
3834
|
+
if (existing) return;
|
|
3835
|
+
const applyField = (fieldName, value, nodeId, ref) => {
|
|
3731
3836
|
if (!fieldName || typeof fieldName !== "string") return;
|
|
3732
|
-
|
|
3733
|
-
|
|
3734
|
-
|
|
3735
|
-
for (const patch of collectFieldPatches(
|
|
3736
|
-
toFieldEnvelopes({ [fieldName]: value })
|
|
3737
|
-
)) {
|
|
3738
|
-
store.set(patch.name, patch.value);
|
|
3739
|
-
}
|
|
3740
|
-
}
|
|
3837
|
+
const fieldRef = isFieldRef(ref) ? ref : void 0;
|
|
3838
|
+
const layoutNodeId = typeof nodeId === "string" && nodeId ? nodeId : void 0;
|
|
3839
|
+
applyComposerPatch(store, fieldName, value, fieldRef, layoutNodeId);
|
|
3741
3840
|
};
|
|
3742
3841
|
const applyProps = (nextProps, nodeId) => {
|
|
3743
3842
|
if (!nextProps || typeof nextProps !== "object" || Array.isArray(nextProps)) {
|
|
3744
3843
|
return;
|
|
3745
3844
|
}
|
|
3746
|
-
|
|
3747
|
-
for (const patch of collectFieldPatches(
|
|
3748
|
-
|
|
3845
|
+
const layoutNodeId = typeof nodeId === "string" && nodeId ? nodeId : void 0;
|
|
3846
|
+
for (const patch of collectFieldPatches(
|
|
3847
|
+
nextProps
|
|
3848
|
+
)) {
|
|
3849
|
+
applyComposerPatch(
|
|
3850
|
+
store,
|
|
3851
|
+
patch.name,
|
|
3852
|
+
patch.value,
|
|
3853
|
+
patch.ref,
|
|
3854
|
+
patch.ref ? void 0 : layoutNodeId
|
|
3855
|
+
);
|
|
3749
3856
|
}
|
|
3750
3857
|
};
|
|
3751
3858
|
const onPatch = (event) => {
|
|
3752
3859
|
const detail = event.detail || {};
|
|
3753
|
-
applyField(
|
|
3860
|
+
applyField(
|
|
3861
|
+
detail.fieldName,
|
|
3862
|
+
detail.value,
|
|
3863
|
+
detail.layoutNodeId,
|
|
3864
|
+
detail.ref
|
|
3865
|
+
);
|
|
3754
3866
|
};
|
|
3755
3867
|
const onPropsPatch = (event) => {
|
|
3756
3868
|
const detail = event.detail || {};
|
|
@@ -3762,7 +3874,12 @@ function ComposerProvider({
|
|
|
3762
3874
|
return;
|
|
3763
3875
|
}
|
|
3764
3876
|
if (event.data?.type !== "AMPLIFYUP_FIELD_PATCH") return;
|
|
3765
|
-
applyField(
|
|
3877
|
+
applyField(
|
|
3878
|
+
event.data.fieldName,
|
|
3879
|
+
event.data.value,
|
|
3880
|
+
event.data.layoutNodeId,
|
|
3881
|
+
event.data.ref
|
|
3882
|
+
);
|
|
3766
3883
|
};
|
|
3767
3884
|
window.addEventListener("amplifyup:field-patch", onPatch);
|
|
3768
3885
|
window.addEventListener("amplifyup:props-patch", onPropsPatch);
|
|
@@ -3772,29 +3889,29 @@ function ComposerProvider({
|
|
|
3772
3889
|
window.removeEventListener("amplifyup:props-patch", onPropsPatch);
|
|
3773
3890
|
window.removeEventListener("message", onMessage);
|
|
3774
3891
|
};
|
|
3775
|
-
}, [
|
|
3892
|
+
}, [existing, store]);
|
|
3893
|
+
if (existing) return /* @__PURE__ */ jsx(Fragment, { children });
|
|
3776
3894
|
return /* @__PURE__ */ jsx(ComposerStoreContext.Provider, { value: store, children });
|
|
3777
3895
|
}
|
|
3778
|
-
function useComposerFieldValue(name, fallback) {
|
|
3896
|
+
function useComposerFieldValue(name, fallback, ref) {
|
|
3779
3897
|
const store = useContext(ComposerStoreContext);
|
|
3898
|
+
const layoutNodeId = useContext(ComposerNodeContext);
|
|
3899
|
+
const key = composerStoreKey(name, ref, layoutNodeId);
|
|
3780
3900
|
const subscribe = useCallback(
|
|
3781
3901
|
(onStoreChange) => {
|
|
3782
3902
|
if (!store || !name) return () => {
|
|
3783
3903
|
};
|
|
3784
|
-
return store.subscribe(
|
|
3904
|
+
return store.subscribe(key, onStoreChange);
|
|
3785
3905
|
},
|
|
3786
|
-
[store, name]
|
|
3906
|
+
[store, name, key]
|
|
3787
3907
|
);
|
|
3788
3908
|
const getSnapshot = useCallback(() => {
|
|
3789
3909
|
if (!store || !name) return void 0;
|
|
3790
|
-
return store.get(
|
|
3791
|
-
}, [store, name]);
|
|
3910
|
+
return store.get(key);
|
|
3911
|
+
}, [store, name, key]);
|
|
3792
3912
|
const overlay = useSyncExternalStore(subscribe, getSnapshot, () => void 0);
|
|
3793
3913
|
return overlay !== void 0 ? overlay : fallback;
|
|
3794
3914
|
}
|
|
3795
|
-
function useComposerStore() {
|
|
3796
|
-
return useContext(ComposerStoreContext);
|
|
3797
|
-
}
|
|
3798
3915
|
function MaybeComposerProvider({
|
|
3799
3916
|
enabled,
|
|
3800
3917
|
layoutNodeId,
|
|
@@ -3802,7 +3919,7 @@ function MaybeComposerProvider({
|
|
|
3802
3919
|
}) {
|
|
3803
3920
|
const content = useMemo(() => children, [children]);
|
|
3804
3921
|
if (!enabled) return /* @__PURE__ */ jsx(Fragment, { children: content });
|
|
3805
|
-
return /* @__PURE__ */ jsx(ComposerProvider, { layoutNodeId, children });
|
|
3922
|
+
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx(ComposerNodeContext.Provider, { value: layoutNodeId, children }) });
|
|
3806
3923
|
}
|
|
3807
3924
|
function nodeRenderProps(node) {
|
|
3808
3925
|
const settings = node.settings || {};
|
|
@@ -4260,7 +4377,7 @@ function AmplifyRendererInner({
|
|
|
4260
4377
|
if (layoutTree.length === 0) {
|
|
4261
4378
|
return /* @__PURE__ */ jsx("main", { children: emptyComponent || /* @__PURE__ */ jsx("div", { className: "container mx-auto px-4 py-16", children: /* @__PURE__ */ jsx("p", { className: "text-muted-foreground", children: "No content configured for this page." }) }) });
|
|
4262
4379
|
}
|
|
4263
|
-
return /* @__PURE__ */ jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsx(
|
|
4380
|
+
return /* @__PURE__ */ jsx(ComposerProvider, { children: /* @__PURE__ */ jsx("main", { children: composerPreview || isComposerPreview() ? /* @__PURE__ */ jsx(
|
|
4264
4381
|
"div",
|
|
4265
4382
|
{
|
|
4266
4383
|
"data-slot-id": "main",
|
|
@@ -4269,7 +4386,7 @@ function AmplifyRendererInner({
|
|
|
4269
4386
|
"data-slot-empty": layoutTree.length === 0 ? "true" : void 0,
|
|
4270
4387
|
children: layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id))
|
|
4271
4388
|
}
|
|
4272
|
-
) : layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id)) });
|
|
4389
|
+
) : layoutTree.map((node) => /* @__PURE__ */ jsx(Fragment$1, { children: renderNode(node) }, node.id)) }) });
|
|
4273
4390
|
}
|
|
4274
4391
|
var AmplifyRenderer = memo(AmplifyRendererInner);
|
|
4275
4392
|
function AddComponentIcon({ size = 28 }) {
|
|
@@ -4622,10 +4739,10 @@ function useBoundField(field, value, name, component) {
|
|
|
4622
4739
|
`[AmplifyUp SDK] ${component} value={\u2026} requires name="\u2026" for computed values`
|
|
4623
4740
|
);
|
|
4624
4741
|
}
|
|
4625
|
-
const fieldValue = useComposerFieldValue(bound.name, bound.value);
|
|
4626
|
-
return { editName: bound.name, fieldValue };
|
|
4742
|
+
const fieldValue = useComposerFieldValue(bound.name, bound.value, bound.ref);
|
|
4743
|
+
return { editName: bound.name, fieldValue, ref: bound.ref };
|
|
4627
4744
|
}
|
|
4628
|
-
function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
4745
|
+
function commitComposerField(layoutNodeId, componentId, name, value, ref) {
|
|
4629
4746
|
if (typeof window === "undefined" || window.parent === window) return;
|
|
4630
4747
|
window.parent.postMessage(
|
|
4631
4748
|
{
|
|
@@ -4633,7 +4750,8 @@ function commitComposerField(layoutNodeId, componentId, name, value) {
|
|
|
4633
4750
|
layoutNodeId,
|
|
4634
4751
|
componentId,
|
|
4635
4752
|
fieldName: name,
|
|
4636
|
-
value
|
|
4753
|
+
value,
|
|
4754
|
+
...ref ? { ref } : {}
|
|
4637
4755
|
},
|
|
4638
4756
|
"*"
|
|
4639
4757
|
);
|
|
@@ -4658,6 +4776,7 @@ function requestCanvasRichTextEdit(opts) {
|
|
|
4658
4776
|
componentId: opts.componentId,
|
|
4659
4777
|
fieldName: opts.name,
|
|
4660
4778
|
value: opts.value,
|
|
4779
|
+
...opts.fieldRef ? { ref: opts.fieldRef } : {},
|
|
4661
4780
|
bounds: {
|
|
4662
4781
|
top: rect.top,
|
|
4663
4782
|
left: rect.left,
|
|
@@ -4682,6 +4801,7 @@ function ComposerInlineField({
|
|
|
4682
4801
|
className,
|
|
4683
4802
|
layoutNodeId,
|
|
4684
4803
|
componentId,
|
|
4804
|
+
fieldRef,
|
|
4685
4805
|
rich = false
|
|
4686
4806
|
}) {
|
|
4687
4807
|
const [focused, setFocused] = useState(false);
|
|
@@ -4710,12 +4830,12 @@ function ComposerInlineField({
|
|
|
4710
4830
|
if (storedEmpty && next === "") {
|
|
4711
4831
|
if (elRef.current) elRef.current.textContent = hint;
|
|
4712
4832
|
if (typeof value === "string" && EMPTY_FIELD_PLACEHOLDERS.has(value.trim())) {
|
|
4713
|
-
commitComposerField(layoutNodeId, componentId, name, "");
|
|
4833
|
+
commitComposerField(layoutNodeId, componentId, name, "", fieldRef);
|
|
4714
4834
|
}
|
|
4715
4835
|
return;
|
|
4716
4836
|
}
|
|
4717
4837
|
if (next === text) return;
|
|
4718
|
-
commitComposerField(layoutNodeId, componentId, name, next);
|
|
4838
|
+
commitComposerField(layoutNodeId, componentId, name, next, fieldRef);
|
|
4719
4839
|
};
|
|
4720
4840
|
const openRichEditor = (event) => {
|
|
4721
4841
|
if (!isComposerEditMode() || !elRef.current) return;
|
|
@@ -4727,7 +4847,8 @@ function ComposerInlineField({
|
|
|
4727
4847
|
layoutNodeId,
|
|
4728
4848
|
componentId,
|
|
4729
4849
|
name,
|
|
4730
|
-
value: source
|
|
4850
|
+
value: source,
|
|
4851
|
+
fieldRef
|
|
4731
4852
|
});
|
|
4732
4853
|
};
|
|
4733
4854
|
return /* @__PURE__ */ jsx(
|
|
@@ -4738,6 +4859,9 @@ function ComposerInlineField({
|
|
|
4738
4859
|
"data-amplifyup-field": name,
|
|
4739
4860
|
"data-amplifyup-field-type": rich ? "richtext" : "text",
|
|
4740
4861
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
4862
|
+
"data-amplifyup-ref-provider": fieldRef?.providerId || void 0,
|
|
4863
|
+
"data-amplifyup-ref-entity": fieldRef?.entity || void 0,
|
|
4864
|
+
"data-amplifyup-ref-id": fieldRef?.id || void 0,
|
|
4741
4865
|
"data-amplifyup-empty-hint": showHint ? "true" : void 0,
|
|
4742
4866
|
contentEditable: !rich,
|
|
4743
4867
|
suppressContentEditableWarning: true,
|
|
@@ -4802,7 +4926,8 @@ function ComposerInlineHtml({
|
|
|
4802
4926
|
className,
|
|
4803
4927
|
Tag = "div",
|
|
4804
4928
|
layoutNodeId,
|
|
4805
|
-
componentId
|
|
4929
|
+
componentId,
|
|
4930
|
+
fieldRef
|
|
4806
4931
|
}) {
|
|
4807
4932
|
const elRef = useRef(null);
|
|
4808
4933
|
useEffect(() => {
|
|
@@ -4819,7 +4944,8 @@ function ComposerInlineHtml({
|
|
|
4819
4944
|
layoutNodeId,
|
|
4820
4945
|
componentId,
|
|
4821
4946
|
name,
|
|
4822
|
-
value: sourceValue
|
|
4947
|
+
value: sourceValue,
|
|
4948
|
+
fieldRef
|
|
4823
4949
|
});
|
|
4824
4950
|
};
|
|
4825
4951
|
return React2.createElement(Tag, {
|
|
@@ -4828,6 +4954,9 @@ function ComposerInlineHtml({
|
|
|
4828
4954
|
"data-amplifyup-field": name,
|
|
4829
4955
|
"data-amplifyup-field-type": "richtext",
|
|
4830
4956
|
"data-amplifyup-node-id": layoutNodeId || void 0,
|
|
4957
|
+
"data-amplifyup-ref-provider": fieldRef?.providerId || void 0,
|
|
4958
|
+
"data-amplifyup-ref-entity": fieldRef?.entity || void 0,
|
|
4959
|
+
"data-amplifyup-ref-id": fieldRef?.id || void 0,
|
|
4831
4960
|
dangerouslySetInnerHTML: { __html: html },
|
|
4832
4961
|
onMouseDown: (event) => {
|
|
4833
4962
|
event.stopPropagation();
|
|
@@ -4859,6 +4988,40 @@ function formatFieldValue(value) {
|
|
|
4859
4988
|
}
|
|
4860
4989
|
return "";
|
|
4861
4990
|
}
|
|
4991
|
+
var FIELD_SCALAR_HINT = "Field expects a scalar field. Did you mean <Field field={post.title} />?";
|
|
4992
|
+
function warnNotScalarField(component, field, fieldValue) {
|
|
4993
|
+
if (process.env.NODE_ENV === "production") return false;
|
|
4994
|
+
if (isBrandedFields(field)) {
|
|
4995
|
+
console.error(`[AmplifyUp SDK] ${component}: ${FIELD_SCALAR_HINT}`);
|
|
4996
|
+
return true;
|
|
4997
|
+
}
|
|
4998
|
+
if (isFieldEnvelope(field) && Array.isArray(field.value)) {
|
|
4999
|
+
console.error(`[AmplifyUp SDK] ${component}: ${FIELD_SCALAR_HINT}`);
|
|
5000
|
+
return true;
|
|
5001
|
+
}
|
|
5002
|
+
if (Array.isArray(fieldValue)) {
|
|
5003
|
+
console.error(`[AmplifyUp SDK] ${component}: ${FIELD_SCALAR_HINT}`);
|
|
5004
|
+
return true;
|
|
5005
|
+
}
|
|
5006
|
+
return false;
|
|
5007
|
+
}
|
|
5008
|
+
var warnedReadOnlyFields = /* @__PURE__ */ new Set();
|
|
5009
|
+
function warnReadOnlyRowField(name) {
|
|
5010
|
+
if (process.env.NODE_ENV === "production") return;
|
|
5011
|
+
const key = name || "(unnamed)";
|
|
5012
|
+
if (warnedReadOnlyFields.has(key)) return;
|
|
5013
|
+
warnedReadOnlyFields.add(key);
|
|
5014
|
+
console.warn(
|
|
5015
|
+
`[AmplifyUp SDK] ${key} has no write target; rendered read-only.`
|
|
5016
|
+
);
|
|
5017
|
+
}
|
|
5018
|
+
function canComposerBind(field, ref, editName) {
|
|
5019
|
+
if (isReadOnlyRowField(field) || isFieldEnvelope(field) && field.readOnly) {
|
|
5020
|
+
warnReadOnlyRowField(editName || (isFieldEnvelope(field) ? field.name : ""));
|
|
5021
|
+
return false;
|
|
5022
|
+
}
|
|
5023
|
+
return true;
|
|
5024
|
+
}
|
|
4862
5025
|
function warnProjectionProps(component, hasField, hasValue, name) {
|
|
4863
5026
|
if (process.env.NODE_ENV === "production") return;
|
|
4864
5027
|
if (!hasField && !hasValue && !name) {
|
|
@@ -4876,16 +5039,20 @@ function Field(props) {
|
|
|
4876
5039
|
const composerEdit = useComposerEditMode();
|
|
4877
5040
|
const hasField = isFieldEnvelope(field);
|
|
4878
5041
|
const hasValue = hasOwnProp(props, "value");
|
|
4879
|
-
const { editName, fieldValue } = useBoundField(field, value, name, "Field");
|
|
5042
|
+
const { editName, fieldValue, ref } = useBoundField(field, value, name, "Field");
|
|
4880
5043
|
warnProjectionProps("Field", hasField, hasValue, name);
|
|
5044
|
+
if (warnNotScalarField("Field", field, fieldValue)) {
|
|
5045
|
+
return null;
|
|
5046
|
+
}
|
|
4881
5047
|
if (!hasField && !hasValue && !name) {
|
|
4882
5048
|
return null;
|
|
4883
5049
|
}
|
|
4884
|
-
if (Array.isArray(fieldValue)) {
|
|
5050
|
+
if (isBrandedFields(field) || Array.isArray(fieldValue)) {
|
|
4885
5051
|
return null;
|
|
4886
5052
|
}
|
|
4887
5053
|
const empty = isComposerEmptyText(fieldValue);
|
|
4888
|
-
|
|
5054
|
+
const bindComposer = composerEdit && editName && context && canInlineEdit(editName, fieldValue) && canComposerBind(field, ref, editName);
|
|
5055
|
+
if (bindComposer) {
|
|
4889
5056
|
return /* @__PURE__ */ jsx(
|
|
4890
5057
|
ComposerInlineField,
|
|
4891
5058
|
{
|
|
@@ -4894,6 +5061,7 @@ function Field(props) {
|
|
|
4894
5061
|
className,
|
|
4895
5062
|
layoutNodeId: context.layoutNodeId,
|
|
4896
5063
|
componentId: context.componentId,
|
|
5064
|
+
fieldRef: ref,
|
|
4897
5065
|
rich: looksLikeRichCanvasField(editName)
|
|
4898
5066
|
}
|
|
4899
5067
|
);
|
|
@@ -4903,186 +5071,6 @@ function Field(props) {
|
|
|
4903
5071
|
if (!text) return null;
|
|
4904
5072
|
return /* @__PURE__ */ jsx("span", { className, children: text });
|
|
4905
5073
|
}
|
|
4906
|
-
var COMPOSER_EMPTY_COLLECTION_HINT = "Click here to add an item";
|
|
4907
|
-
function CollectionChromeButton({
|
|
4908
|
-
label,
|
|
4909
|
-
onClick
|
|
4910
|
-
}) {
|
|
4911
|
-
return /* @__PURE__ */ jsx(
|
|
4912
|
-
"button",
|
|
4913
|
-
{
|
|
4914
|
-
type: "button",
|
|
4915
|
-
onMouseDown: (event) => event.stopPropagation(),
|
|
4916
|
-
onClick: (event) => {
|
|
4917
|
-
event.preventDefault();
|
|
4918
|
-
event.stopPropagation();
|
|
4919
|
-
onClick();
|
|
4920
|
-
},
|
|
4921
|
-
style: {
|
|
4922
|
-
fontSize: 11,
|
|
4923
|
-
lineHeight: 1.2,
|
|
4924
|
-
padding: "4px 8px",
|
|
4925
|
-
border: "1px solid color-mix(in srgb, currentColor 28%, transparent)",
|
|
4926
|
-
borderRadius: 6,
|
|
4927
|
-
background: "transparent",
|
|
4928
|
-
cursor: "pointer",
|
|
4929
|
-
color: "inherit"
|
|
4930
|
-
},
|
|
4931
|
-
children: label
|
|
4932
|
-
}
|
|
4933
|
-
);
|
|
4934
|
-
}
|
|
4935
|
-
function Collection({
|
|
4936
|
-
field,
|
|
4937
|
-
children,
|
|
4938
|
-
className
|
|
4939
|
-
}) {
|
|
4940
|
-
const context = useContext(ComponentContext);
|
|
4941
|
-
const store = useComposerStore();
|
|
4942
|
-
const composerEdit = useComposerEditMode();
|
|
4943
|
-
const name = isFieldEnvelope(field) ? field.name : "";
|
|
4944
|
-
const overlay = useComposerFieldValue(name, void 0);
|
|
4945
|
-
const items = resolveCollectionItems(field, overlay);
|
|
4946
|
-
const writeItems = (nextPlain) => {
|
|
4947
|
-
if (name && store) {
|
|
4948
|
-
const prefixed = name ? store.keys().filter((key) => key === name || key.startsWith(`${name}.`)) : [];
|
|
4949
|
-
for (const key of prefixed) store.delete(key);
|
|
4950
|
-
store.set(name, nextPlain);
|
|
4951
|
-
for (const patch of collectFieldPatches(
|
|
4952
|
-
toFieldEnvelopes({ [name]: nextPlain })
|
|
4953
|
-
)) {
|
|
4954
|
-
store.set(patch.name, patch.value);
|
|
4955
|
-
}
|
|
4956
|
-
}
|
|
4957
|
-
commitComposerField(
|
|
4958
|
-
context?.layoutNodeId,
|
|
4959
|
-
context?.componentId,
|
|
4960
|
-
name,
|
|
4961
|
-
nextPlain
|
|
4962
|
-
);
|
|
4963
|
-
};
|
|
4964
|
-
const plainItems = () => items.map((item, index) => {
|
|
4965
|
-
const base = unwrapFieldsBag(item);
|
|
4966
|
-
if (!store || !name) return base;
|
|
4967
|
-
const out = { ...base };
|
|
4968
|
-
for (const key of Object.keys(out)) {
|
|
4969
|
-
const overlayValue = store.get(`${name}.${index}.${key}`);
|
|
4970
|
-
if (overlayValue !== void 0) out[key] = overlayValue;
|
|
4971
|
-
}
|
|
4972
|
-
return out;
|
|
4973
|
-
});
|
|
4974
|
-
const addItem = () => writeItems([...plainItems(), {}]);
|
|
4975
|
-
const removeItem = (index) => writeItems(plainItems().filter((_, i) => i !== index));
|
|
4976
|
-
const moveItem = (index, delta) => {
|
|
4977
|
-
const next = plainItems();
|
|
4978
|
-
const target = index + delta;
|
|
4979
|
-
if (target < 0 || target >= next.length) return;
|
|
4980
|
-
const swap = next[index];
|
|
4981
|
-
next[index] = next[target];
|
|
4982
|
-
next[target] = swap;
|
|
4983
|
-
writeItems(next);
|
|
4984
|
-
};
|
|
4985
|
-
if (!composerEdit) {
|
|
4986
|
-
if (items.length === 0) return null;
|
|
4987
|
-
return /* @__PURE__ */ jsx("span", { className, style: { display: "contents" }, children: items.map((item, index) => /* @__PURE__ */ jsx(React2.Fragment, { children: children(item, index) }, item && typeof item === "object" ? `${name}.${index}` : index)) });
|
|
4988
|
-
}
|
|
4989
|
-
if (items.length === 0) {
|
|
4990
|
-
return /* @__PURE__ */ jsx(
|
|
4991
|
-
"span",
|
|
4992
|
-
{
|
|
4993
|
-
className,
|
|
4994
|
-
"data-amplifyup-collection": name || void 0,
|
|
4995
|
-
"data-amplifyup-collection-empty": "true",
|
|
4996
|
-
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
4997
|
-
role: "button",
|
|
4998
|
-
tabIndex: 0,
|
|
4999
|
-
onMouseDown: (event) => event.stopPropagation(),
|
|
5000
|
-
onClick: (event) => {
|
|
5001
|
-
event.preventDefault();
|
|
5002
|
-
event.stopPropagation();
|
|
5003
|
-
addItem();
|
|
5004
|
-
},
|
|
5005
|
-
onKeyDown: (event) => {
|
|
5006
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
5007
|
-
event.preventDefault();
|
|
5008
|
-
addItem();
|
|
5009
|
-
}
|
|
5010
|
-
},
|
|
5011
|
-
style: {
|
|
5012
|
-
display: "block",
|
|
5013
|
-
cursor: "pointer",
|
|
5014
|
-
outline: "1px dashed color-mix(in srgb, currentColor 40%, transparent)",
|
|
5015
|
-
outlineOffset: 2,
|
|
5016
|
-
minHeight: "3em",
|
|
5017
|
-
opacity: 0.5
|
|
5018
|
-
},
|
|
5019
|
-
children: /* @__PURE__ */ jsx(EmptySlotHint, { label: COMPOSER_EMPTY_COLLECTION_HINT, compact: true })
|
|
5020
|
-
}
|
|
5021
|
-
);
|
|
5022
|
-
}
|
|
5023
|
-
return /* @__PURE__ */ jsxs(
|
|
5024
|
-
"span",
|
|
5025
|
-
{
|
|
5026
|
-
className,
|
|
5027
|
-
"data-amplifyup-collection": name || void 0,
|
|
5028
|
-
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
5029
|
-
style: { display: "flex", flexDirection: "column", gap: 8 },
|
|
5030
|
-
children: [
|
|
5031
|
-
items.map((item, index) => /* @__PURE__ */ jsxs(
|
|
5032
|
-
"span",
|
|
5033
|
-
{
|
|
5034
|
-
"data-amplifyup-collection-item": `${name}.${index}`,
|
|
5035
|
-
style: {
|
|
5036
|
-
display: "block",
|
|
5037
|
-
outline: "1px dashed color-mix(in srgb, currentColor 28%, transparent)",
|
|
5038
|
-
outlineOffset: 2,
|
|
5039
|
-
padding: 8
|
|
5040
|
-
},
|
|
5041
|
-
children: [
|
|
5042
|
-
/* @__PURE__ */ jsxs(
|
|
5043
|
-
"span",
|
|
5044
|
-
{
|
|
5045
|
-
style: {
|
|
5046
|
-
display: "flex",
|
|
5047
|
-
gap: 6,
|
|
5048
|
-
justifyContent: "flex-end",
|
|
5049
|
-
marginBottom: 8
|
|
5050
|
-
},
|
|
5051
|
-
children: [
|
|
5052
|
-
/* @__PURE__ */ jsx(
|
|
5053
|
-
CollectionChromeButton,
|
|
5054
|
-
{
|
|
5055
|
-
label: "Move up",
|
|
5056
|
-
onClick: () => moveItem(index, -1)
|
|
5057
|
-
}
|
|
5058
|
-
),
|
|
5059
|
-
/* @__PURE__ */ jsx(
|
|
5060
|
-
CollectionChromeButton,
|
|
5061
|
-
{
|
|
5062
|
-
label: "Move down",
|
|
5063
|
-
onClick: () => moveItem(index, 1)
|
|
5064
|
-
}
|
|
5065
|
-
),
|
|
5066
|
-
/* @__PURE__ */ jsx(
|
|
5067
|
-
CollectionChromeButton,
|
|
5068
|
-
{
|
|
5069
|
-
label: "Remove",
|
|
5070
|
-
onClick: () => removeItem(index)
|
|
5071
|
-
}
|
|
5072
|
-
)
|
|
5073
|
-
]
|
|
5074
|
-
}
|
|
5075
|
-
),
|
|
5076
|
-
children(item, index)
|
|
5077
|
-
]
|
|
5078
|
-
},
|
|
5079
|
-
`${name}.${index}`
|
|
5080
|
-
)),
|
|
5081
|
-
/* @__PURE__ */ jsx("span", { children: /* @__PURE__ */ jsx(CollectionChromeButton, { label: "Add item", onClick: addItem }) })
|
|
5082
|
-
]
|
|
5083
|
-
}
|
|
5084
|
-
);
|
|
5085
|
-
}
|
|
5086
5074
|
function markdownToHtml(markdown) {
|
|
5087
5075
|
try {
|
|
5088
5076
|
const result = marked.parse(markdown, { async: false });
|
|
@@ -5106,7 +5094,7 @@ function RichText(props) {
|
|
|
5106
5094
|
const hasField = isFieldEnvelope(field);
|
|
5107
5095
|
const hasValueProp = hasOwnProp(props, "value") || childrenValue !== void 0;
|
|
5108
5096
|
const boundValue = hasOwnProp(props, "value") ? value : childrenValue !== void 0 ? childrenValue : value;
|
|
5109
|
-
const { editName, fieldValue } = useBoundField(
|
|
5097
|
+
const { editName, fieldValue, ref } = useBoundField(
|
|
5110
5098
|
field,
|
|
5111
5099
|
boundValue,
|
|
5112
5100
|
name,
|
|
@@ -5116,7 +5104,10 @@ function RichText(props) {
|
|
|
5116
5104
|
return null;
|
|
5117
5105
|
}
|
|
5118
5106
|
warnProjectionProps("RichText", hasField, hasValueProp, name);
|
|
5119
|
-
|
|
5107
|
+
if (warnNotScalarField("RichText", field, fieldValue)) {
|
|
5108
|
+
return null;
|
|
5109
|
+
}
|
|
5110
|
+
const canEdit = !!context && canInlineEditRichText(editName, fieldValue) && canComposerBind(field, ref, editName);
|
|
5120
5111
|
if (isComposerEmptyText(fieldValue)) {
|
|
5121
5112
|
if (composerEdit && canEdit) {
|
|
5122
5113
|
return /* @__PURE__ */ jsx(
|
|
@@ -5127,6 +5118,7 @@ function RichText(props) {
|
|
|
5127
5118
|
className,
|
|
5128
5119
|
layoutNodeId: context?.layoutNodeId,
|
|
5129
5120
|
componentId: context?.componentId,
|
|
5121
|
+
fieldRef: ref,
|
|
5130
5122
|
rich: true
|
|
5131
5123
|
}
|
|
5132
5124
|
);
|
|
@@ -5158,7 +5150,8 @@ function RichText(props) {
|
|
|
5158
5150
|
className,
|
|
5159
5151
|
Tag,
|
|
5160
5152
|
layoutNodeId: context?.layoutNodeId,
|
|
5161
|
-
componentId: context?.componentId
|
|
5153
|
+
componentId: context?.componentId,
|
|
5154
|
+
fieldRef: ref
|
|
5162
5155
|
}
|
|
5163
5156
|
);
|
|
5164
5157
|
}
|
|
@@ -5174,6 +5167,38 @@ function imageSrc(value) {
|
|
|
5174
5167
|
if (isPortableImageValue(value)) return value.url.trim();
|
|
5175
5168
|
return "";
|
|
5176
5169
|
}
|
|
5170
|
+
function leafText(field) {
|
|
5171
|
+
if (isFieldEnvelope(field)) return field.value;
|
|
5172
|
+
return field;
|
|
5173
|
+
}
|
|
5174
|
+
function coerceImageField(field, value, name) {
|
|
5175
|
+
if (isFieldEnvelope(field)) return { field, value, name };
|
|
5176
|
+
if (!isBrandedFields(field) || !field || typeof field !== "object") {
|
|
5177
|
+
return { field: void 0, value, name };
|
|
5178
|
+
}
|
|
5179
|
+
const bag = field;
|
|
5180
|
+
const urlField = bag.url;
|
|
5181
|
+
const urlName = isFieldEnvelope(urlField) && typeof urlField.name === "string" ? urlField.name.replace(/\.url$/, "") : "";
|
|
5182
|
+
const editName = urlName || name || "";
|
|
5183
|
+
if (!editName) return { field: void 0, value, name };
|
|
5184
|
+
const ref = isFieldEnvelope(urlField) ? urlField.ref : void 0;
|
|
5185
|
+
const width = leafText(bag.width);
|
|
5186
|
+
const height = leafText(bag.height);
|
|
5187
|
+
return {
|
|
5188
|
+
field: {
|
|
5189
|
+
value: {
|
|
5190
|
+
url: String(leafText(urlField) ?? ""),
|
|
5191
|
+
alt: leafText(bag.alt),
|
|
5192
|
+
...typeof width === "number" ? { width } : {},
|
|
5193
|
+
...typeof height === "number" ? { height } : {}
|
|
5194
|
+
},
|
|
5195
|
+
name: editName,
|
|
5196
|
+
...ref ? { ref } : {}
|
|
5197
|
+
},
|
|
5198
|
+
value,
|
|
5199
|
+
name: editName
|
|
5200
|
+
};
|
|
5201
|
+
}
|
|
5177
5202
|
function Image(props) {
|
|
5178
5203
|
const {
|
|
5179
5204
|
field,
|
|
@@ -5186,12 +5211,22 @@ function Image(props) {
|
|
|
5186
5211
|
...imgProps
|
|
5187
5212
|
} = props;
|
|
5188
5213
|
const context = useContext(ComponentContext);
|
|
5189
|
-
const
|
|
5214
|
+
const coerced = coerceImageField(field, value, name);
|
|
5215
|
+
const boundField = coerced.field;
|
|
5216
|
+
const hasField = isFieldEnvelope(boundField);
|
|
5190
5217
|
const hasValue = hasOwnProp(props, "value");
|
|
5191
|
-
const { editName, fieldValue } = useBoundField(
|
|
5218
|
+
const { editName, fieldValue, ref } = useBoundField(
|
|
5219
|
+
boundField,
|
|
5220
|
+
coerced.value,
|
|
5221
|
+
coerced.name,
|
|
5222
|
+
"Image"
|
|
5223
|
+
);
|
|
5192
5224
|
const composerEdit = useComposerEditMode();
|
|
5193
|
-
warnProjectionProps("Image", hasField, hasValue, name);
|
|
5194
|
-
if (!
|
|
5225
|
+
warnProjectionProps("Image", hasField || isBrandedFields(field), hasValue, coerced.name || name);
|
|
5226
|
+
if (!isBrandedFields(field) && warnNotScalarField("Image", boundField, fieldValue)) {
|
|
5227
|
+
return null;
|
|
5228
|
+
}
|
|
5229
|
+
if (!hasField && !hasValue && !name && !editName) {
|
|
5195
5230
|
return null;
|
|
5196
5231
|
}
|
|
5197
5232
|
const src = imageSrc(fieldValue);
|
|
@@ -5199,10 +5234,13 @@ function Image(props) {
|
|
|
5199
5234
|
const alt = altProp ?? portable?.alt ?? "";
|
|
5200
5235
|
const width = widthProp ?? portable?.width;
|
|
5201
5236
|
const height = heightProp ?? portable?.height;
|
|
5202
|
-
const fieldAttrs = composerEdit && editName ? {
|
|
5237
|
+
const fieldAttrs = composerEdit && editName && canComposerBind(boundField, ref, editName) ? {
|
|
5203
5238
|
"data-amplifyup-field": editName,
|
|
5204
5239
|
"data-amplifyup-field-type": "image",
|
|
5205
|
-
"data-amplifyup-node-id": context?.layoutNodeId || void 0
|
|
5240
|
+
"data-amplifyup-node-id": context?.layoutNodeId || void 0,
|
|
5241
|
+
"data-amplifyup-ref-provider": ref?.providerId || void 0,
|
|
5242
|
+
"data-amplifyup-ref-entity": ref?.entity || void 0,
|
|
5243
|
+
"data-amplifyup-ref-id": ref?.id || void 0
|
|
5206
5244
|
} : null;
|
|
5207
5245
|
if (composerEdit && !editName && (hasField || hasValue)) {
|
|
5208
5246
|
console.warn(
|
|
@@ -5471,6 +5509,6 @@ function useAmplifyUp() {
|
|
|
5471
5509
|
return context;
|
|
5472
5510
|
}
|
|
5473
5511
|
|
|
5474
|
-
export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider,
|
|
5512
|
+
export { AmplifyPageContent, AmplifyRenderer, AmplifyUpProvider, ComponentContextProvider, ComposerProvider, Field, Image, MaybeComposerProvider, QueryContentError, RichText, SelectVariantsError, Slot, attachFieldEnvelopes, composerStoreKey, envelopeListRows, isBrandedFields, isComposerPreview, isFieldEnvelope, isPreviewRequest, isReadOnlyRowField, isWorkingContentRequest, listOwnerFromSpec, nextPageSpec, queryContent, searchSpec, selectVariants, toFieldEnvelopes, useAmplifyUp };
|
|
5475
5513
|
//# sourceMappingURL=react.mjs.map
|
|
5476
5514
|
//# sourceMappingURL=react.mjs.map
|