@measured/puck 0.20.0-canary.7d869af1 → 0.20.0-canary.7ec3c0b9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/rsc.js CHANGED
@@ -34,12 +34,6 @@ var __objRest = (source, exclude) => {
34
34
  }
35
35
  return target;
36
36
  };
37
- var __esm = (fn, res) => function __init() {
38
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
39
- };
40
- var __commonJS = (cb, mod) => function __require() {
41
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
42
- };
43
37
  var __export = (target, all) => {
44
38
  for (var name in all)
45
39
  __defProp(target, name, { get: all[name], enumerable: true });
@@ -82,77 +76,6 @@ var __async = (__this, __arguments, generator) => {
82
76
  });
83
77
  };
84
78
 
85
- // ../tsup-config/react-import.js
86
- var import_react;
87
- var init_react_import = __esm({
88
- "../tsup-config/react-import.js"() {
89
- "use strict";
90
- import_react = __toESM(require("react"));
91
- }
92
- });
93
-
94
- // ../../node_modules/classnames/index.js
95
- var require_classnames = __commonJS({
96
- "../../node_modules/classnames/index.js"(exports2, module2) {
97
- "use strict";
98
- init_react_import();
99
- (function() {
100
- "use strict";
101
- var hasOwn = {}.hasOwnProperty;
102
- function classNames() {
103
- var classes = "";
104
- for (var i = 0; i < arguments.length; i++) {
105
- var arg = arguments[i];
106
- if (arg) {
107
- classes = appendClass(classes, parseValue(arg));
108
- }
109
- }
110
- return classes;
111
- }
112
- function parseValue(arg) {
113
- if (typeof arg === "string" || typeof arg === "number") {
114
- return arg;
115
- }
116
- if (typeof arg !== "object") {
117
- return "";
118
- }
119
- if (Array.isArray(arg)) {
120
- return classNames.apply(null, arg);
121
- }
122
- if (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes("[native code]")) {
123
- return arg.toString();
124
- }
125
- var classes = "";
126
- for (var key in arg) {
127
- if (hasOwn.call(arg, key) && arg[key]) {
128
- classes = appendClass(classes, key);
129
- }
130
- }
131
- return classes;
132
- }
133
- function appendClass(value, newClass) {
134
- if (!newClass) {
135
- return value;
136
- }
137
- if (value) {
138
- return value + " " + newClass;
139
- }
140
- return value + newClass;
141
- }
142
- if (typeof module2 !== "undefined" && module2.exports) {
143
- classNames.default = classNames;
144
- module2.exports = classNames;
145
- } else if (typeof define === "function" && typeof define.amd === "object" && define.amd) {
146
- define("classnames", [], function() {
147
- return classNames;
148
- });
149
- } else {
150
- window.classNames = classNames;
151
- }
152
- })();
153
- }
154
- });
155
-
156
79
  // bundle/rsc.tsx
157
80
  var rsc_exports = {};
158
81
  __export(rsc_exports, {
@@ -163,19 +86,16 @@ __export(rsc_exports, {
163
86
  walkTree: () => walkTree
164
87
  });
165
88
  module.exports = __toCommonJS(rsc_exports);
166
- init_react_import();
167
89
 
168
- // components/ServerRender/index.tsx
169
- init_react_import();
90
+ // ../tsup-config/react-import.js
91
+ var import_react = __toESM(require("react"));
170
92
 
171
93
  // lib/root-droppable-id.ts
172
- init_react_import();
173
94
  var rootAreaId = "root";
174
95
  var rootZone = "default-zone";
175
96
  var rootDroppableId = `${rootAreaId}:${rootZone}`;
176
97
 
177
98
  // lib/data/setup-zone.ts
178
- init_react_import();
179
99
  var setupZone = (data, zoneKey) => {
180
100
  if (zoneKey === rootDroppableId) {
181
101
  return data;
@@ -187,18 +107,10 @@ var setupZone = (data, zoneKey) => {
187
107
  return newData;
188
108
  };
189
109
 
190
- // lib/use-slots.tsx
191
- init_react_import();
192
-
193
110
  // lib/field-transforms/use-field-transforms.tsx
194
- init_react_import();
195
111
  var import_react2 = require("react");
196
112
 
197
- // lib/data/map-fields.ts
198
- init_react_import();
199
-
200
113
  // lib/data/default-slots.ts
201
- init_react_import();
202
114
  var defaultSlots = (value, fields) => Object.keys(fields).reduce(
203
115
  (acc, fieldName) => fields[fieldName].type === "slot" ? __spreadValues({ [fieldName]: [] }, acc) : acc,
204
116
  value
@@ -387,1740 +299,250 @@ function useFieldTransforms(config, item, transforms, readOnly, forceReadOnly) {
387
299
  return mergedProps;
388
300
  }
389
301
 
390
- // lib/field-transforms/default-transforms.tsx
391
- init_react_import();
392
-
393
- // components/InlineTextField/index.tsx
394
- init_react_import();
395
- var import_react8 = require("react");
396
-
397
- // lib/overlay-portal/index.tsx
398
- init_react_import();
399
- var registerOverlayPortal = (el, opts = {}) => {
400
- if (!el) return;
401
- const { disableDrag = false, disableDragOnFocus = true } = opts;
402
- const stopPropagation = (e) => {
403
- e.stopPropagation();
404
- };
405
- el.addEventListener("mouseover", stopPropagation, {
406
- capture: true
407
- });
408
- const onFocus = () => {
409
- setTimeout(() => {
410
- el.addEventListener("pointerdown", stopPropagation, {
411
- capture: true
412
- });
413
- }, 200);
414
- };
415
- const onBlur = () => {
416
- el.removeEventListener("pointerdown", stopPropagation, {
417
- capture: true
418
- });
419
- };
420
- if (disableDragOnFocus) {
421
- el.addEventListener("focus", onFocus, { capture: true });
422
- el.addEventListener("blur", onBlur, { capture: true });
423
- } else if (disableDrag) {
424
- el.addEventListener("pointerdown", stopPropagation, {
425
- capture: true
426
- });
302
+ // lib/field-transforms/default-transforms/slot-transform.tsx
303
+ var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
304
+ slot: ({ value: content, propName, field, isReadOnly }) => {
305
+ const render = isReadOnly ? renderSlotRender : renderSlotEdit;
306
+ const Slot = (dzProps) => render(__spreadProps(__spreadValues({
307
+ allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
308
+ disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
309
+ }, dzProps), {
310
+ zone: propName,
311
+ content
312
+ }));
313
+ return Slot;
427
314
  }
428
- el.setAttribute("data-puck-overlay-portal", "true");
429
- return () => {
430
- el.removeEventListener("mouseover", stopPropagation, {
431
- capture: true
432
- });
433
- if (disableDragOnFocus) {
434
- el.removeEventListener("focus", onFocus, { capture: true });
435
- el.removeEventListener("blur", onFocus, { capture: true });
436
- } else if (disableDrag) {
437
- el.removeEventListener("pointerdown", stopPropagation, {
438
- capture: true
439
- });
440
- }
441
- el.removeAttribute("data-puck-overlay-portal");
442
- };
443
- };
444
-
445
- // store/index.ts
446
- init_react_import();
447
-
448
- // reducer/index.ts
449
- init_react_import();
450
-
451
- // reducer/actions/set.ts
452
- init_react_import();
315
+ });
453
316
 
454
- // lib/data/walk-app-state.ts
455
- init_react_import();
317
+ // lib/use-slots.tsx
318
+ function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
319
+ return useFieldTransforms(
320
+ config,
321
+ item,
322
+ getSlotTransform(renderSlotEdit, renderSlotRender),
323
+ readOnly,
324
+ forceReadOnly
325
+ );
326
+ }
456
327
 
457
- // lib/data/for-related-zones.ts
458
- init_react_import();
328
+ // components/SlotRender/server.tsx
329
+ var import_react3 = require("react");
330
+ var import_jsx_runtime = require("react/jsx-runtime");
331
+ var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRender, __spreadValues({}, props));
332
+ var Item = ({
333
+ config,
334
+ item,
335
+ metadata
336
+ }) => {
337
+ const Component = config.components[item.type];
338
+ const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
339
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
340
+ Component.render,
341
+ __spreadProps(__spreadValues({}, props), {
342
+ puck: __spreadProps(__spreadValues({}, props.puck), {
343
+ renderDropZone: DropZoneRender,
344
+ metadata: metadata || {}
345
+ })
346
+ })
347
+ );
348
+ };
349
+ var SlotRender = (0, import_react3.forwardRef)(
350
+ function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
351
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className, style, ref, children: content.map((item) => {
352
+ if (!config.components[item.type]) {
353
+ return null;
354
+ }
355
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
356
+ Item,
357
+ {
358
+ config,
359
+ item,
360
+ metadata
361
+ },
362
+ item.props.id
363
+ );
364
+ }) });
365
+ }
366
+ );
459
367
 
460
- // lib/get-zone-id.ts
461
- init_react_import();
462
- var getZoneId = (zoneCompound) => {
463
- if (!zoneCompound) {
464
- return [];
368
+ // components/ServerRender/index.tsx
369
+ var import_jsx_runtime2 = require("react/jsx-runtime");
370
+ function DropZoneRender({
371
+ zone,
372
+ data,
373
+ areaId = "root",
374
+ config,
375
+ metadata = {}
376
+ }) {
377
+ let zoneCompound = rootDroppableId;
378
+ let content = (data == null ? void 0 : data.content) || [];
379
+ if (!data || !config) {
380
+ return null;
465
381
  }
466
- if (zoneCompound && zoneCompound.indexOf(":") > -1) {
467
- return zoneCompound.split(":");
382
+ if (areaId !== rootAreaId && zone !== rootZone) {
383
+ zoneCompound = `${areaId}:${zone}`;
384
+ content = setupZone(data, zoneCompound).zones[zoneCompound];
468
385
  }
469
- return [rootDroppableId, zoneCompound];
470
- };
471
-
472
- // lib/data/for-related-zones.ts
473
- function forRelatedZones(item, data, cb, path = []) {
474
- Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
475
- const [parentId] = getZoneId(zoneCompound);
476
- if (parentId === item.props.id) {
477
- cb(path, zoneCompound, content);
386
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_jsx_runtime2.Fragment, { children: content.map((item) => {
387
+ const Component = config.components[item.type];
388
+ const props = __spreadProps(__spreadValues({}, item.props), {
389
+ puck: {
390
+ renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
391
+ DropZoneRender,
392
+ {
393
+ zone: zone2,
394
+ data,
395
+ areaId: item.props.id,
396
+ config,
397
+ metadata
398
+ }
399
+ ),
400
+ metadata,
401
+ dragRef: null,
402
+ isEditing: false
403
+ }
404
+ });
405
+ const renderItem = __spreadProps(__spreadValues({}, item), { props });
406
+ const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
407
+ if (Component) {
408
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
478
409
  }
410
+ return null;
411
+ }) });
412
+ }
413
+ function Render({
414
+ config,
415
+ data,
416
+ metadata = {}
417
+ }) {
418
+ var _a;
419
+ const rootProps = "props" in data.root ? data.root.props : data.root;
420
+ const title = rootProps.title || "";
421
+ const props = __spreadProps(__spreadValues({}, rootProps), {
422
+ puck: {
423
+ renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
424
+ DropZoneRender,
425
+ {
426
+ zone,
427
+ data,
428
+ config,
429
+ metadata
430
+ }
431
+ ),
432
+ isEditing: false,
433
+ dragRef: null,
434
+ metadata
435
+ },
436
+ title,
437
+ editMode: false,
438
+ id: "puck-root"
479
439
  });
440
+ const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
441
+ if ((_a = config.root) == null ? void 0 : _a.render) {
442
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
443
+ DropZoneRender,
444
+ {
445
+ config,
446
+ data,
447
+ zone: rootZone,
448
+ metadata
449
+ }
450
+ ) }));
451
+ }
452
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
453
+ DropZoneRender,
454
+ {
455
+ config,
456
+ data,
457
+ zone: rootZone,
458
+ metadata
459
+ }
460
+ );
480
461
  }
481
462
 
482
- // lib/data/flatten-node.ts
483
- init_react_import();
484
- var import_flat = __toESM(require("flat"));
485
-
486
- // lib/data/strip-slots.ts
487
- init_react_import();
488
- var stripSlots = (data, config) => {
489
- return mapFields(data, { slot: () => null }, config);
490
- };
491
-
492
- // lib/data/flatten-node.ts
493
- var { flatten: flatten2, unflatten } = import_flat.default;
494
- var flattenNode = (node, config) => {
495
- return __spreadProps(__spreadValues({}, node), {
496
- props: flatten2(stripSlots(node, config).props)
497
- });
463
+ // lib/get-changed.ts
464
+ var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
465
+ var getChanged = (newItem, oldItem) => {
466
+ return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
467
+ const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
468
+ const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
469
+ return __spreadProps(__spreadValues({}, acc), {
470
+ [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
471
+ });
472
+ }, {}) : {};
498
473
  };
499
474
 
500
- // lib/data/walk-app-state.ts
501
- function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
502
- var _a;
503
- let newZones = {};
504
- const newZoneIndex = {};
505
- const newNodeIndex = {};
506
- const processContent = (path, zoneCompound, content, zoneType, newId) => {
507
- var _a2;
508
- const [parentId] = zoneCompound.split(":");
509
- const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
510
- const [_2, zone] = zoneCompound.split(":");
511
- const newZoneCompound = `${newId || parentId}:${zone}`;
512
- const newContent2 = mappedContent.map(
513
- (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
514
- );
515
- newZoneIndex[newZoneCompound] = {
516
- contentIds: newContent2.map((item) => item.props.id),
517
- type: zoneType
518
- };
519
- return [newZoneCompound, newContent2];
520
- };
521
- const processRelatedZones = (item, newId, initialPath) => {
522
- forRelatedZones(
523
- item,
524
- state.data,
525
- (relatedPath, relatedZoneCompound, relatedContent) => {
526
- const [zoneCompound, newContent2] = processContent(
527
- relatedPath,
528
- relatedZoneCompound,
529
- relatedContent,
530
- "dropzone",
531
- newId
532
- );
533
- newZones[zoneCompound] = newContent2;
534
- },
535
- initialPath
536
- );
537
- };
538
- const processItem = (item, path, index) => {
539
- const mappedItem = mapNodeOrSkip(item, path, index);
540
- if (!mappedItem) return item;
541
- const id = mappedItem.props.id;
542
- const newProps = __spreadProps(__spreadValues({}, mapFields(
543
- mappedItem,
544
- {
545
- slot: ({ value, parentId: parentId2, propPath }) => {
546
- const content = value;
547
- const zoneCompound = `${parentId2}:${propPath}`;
548
- const [_2, newContent2] = processContent(
549
- path,
550
- zoneCompound,
551
- content,
552
- "slot",
553
- parentId2
554
- );
555
- return newContent2;
556
- }
557
- },
558
- config
559
- ).props), {
560
- id
561
- });
562
- processRelatedZones(item, id, path);
563
- const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
564
- const thisZoneCompound = path[path.length - 1];
565
- const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
566
- newNodeIndex[id] = {
567
- data: newItem,
568
- flatData: flattenNode(newItem, config),
569
- path,
570
- parentId,
571
- zone
572
- };
573
- const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
574
- if (newProps.id === "root") {
575
- delete finalData["type"];
576
- delete finalData.props["id"];
577
- }
578
- return finalData;
579
- };
580
- const zones = state.data.zones || {};
581
- const [_, newContent] = processContent(
582
- [],
583
- rootDroppableId,
584
- state.data.content,
585
- "root"
586
- );
587
- const processedContent = newContent;
588
- const zonesAlreadyProcessed = Object.keys(newZones);
589
- Object.keys(zones || {}).forEach((zoneCompound) => {
590
- const [parentId] = zoneCompound.split(":");
591
- if (zonesAlreadyProcessed.includes(zoneCompound)) {
592
- return;
593
- }
594
- const [_2, newContent2] = processContent(
595
- [rootDroppableId],
596
- zoneCompound,
597
- zones[zoneCompound],
598
- "dropzone",
599
- parentId
600
- );
601
- newZones[zoneCompound] = newContent2;
602
- }, newZones);
603
- const processedRoot = processItem(
604
- {
605
- type: "root",
606
- props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
607
- },
608
- [],
609
- -1
610
- );
611
- const root = __spreadProps(__spreadValues({}, state.data.root), {
612
- props: processedRoot.props
613
- });
614
- return __spreadProps(__spreadValues({}, state), {
615
- data: {
616
- root,
617
- content: processedContent,
618
- zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
619
- },
620
- indexes: {
621
- nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
622
- zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
623
- }
624
- });
625
- }
626
-
627
- // reducer/actions/set.ts
628
- var setAction = (state, action, appStore) => {
629
- if (typeof action.state === "object") {
630
- const newState = __spreadValues(__spreadValues({}, state), action.state);
631
- if (action.state.indexes) {
632
- return newState;
633
- }
634
- console.warn(
635
- "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
636
- );
637
- return walkAppState(newState, appStore.config);
638
- }
639
- return __spreadValues(__spreadValues({}, state), action.state(state));
640
- };
641
-
642
- // reducer/actions/insert.ts
643
- init_react_import();
644
-
645
- // lib/data/insert.ts
646
- init_react_import();
647
- var insert = (list, index, item) => {
648
- const result = Array.from(list || []);
649
- result.splice(index, 0, item);
650
- return result;
651
- };
652
-
653
- // lib/generate-id.ts
654
- init_react_import();
655
- var import_uuid = require("uuid");
656
- var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
657
-
658
- // lib/data/get-ids-for-parent.ts
659
- init_react_import();
660
- var getIdsForParent = (zoneCompound, state) => {
661
- const [parentId] = zoneCompound.split(":");
662
- const node = state.indexes.nodes[parentId];
663
- return ((node == null ? void 0 : node.path) || []).map((p) => p.split(":")[0]);
664
- };
665
-
666
- // lib/data/populate-ids.ts
667
- init_react_import();
668
-
669
- // lib/data/walk-tree.ts
670
- init_react_import();
671
- function walkTree(data, config, callbackFn) {
672
- var _a, _b;
673
- const walkItem = (item) => {
674
- return mapFields(
675
- item,
676
- {
677
- slot: ({ value, parentId, propName }) => {
678
- var _a2;
679
- const content = value;
680
- return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
681
- }
682
- },
683
- config,
684
- true
685
- );
686
- };
687
- if ("props" in data) {
688
- return walkItem(data);
689
- }
690
- const _data = data;
691
- const zones = (_a = _data.zones) != null ? _a : {};
692
- const mappedContent = _data.content.map(walkItem);
693
- return {
694
- root: walkItem(_data.root),
695
- content: (_b = callbackFn(mappedContent, {
696
- parentId: "root",
697
- propName: "default-zone"
698
- })) != null ? _b : mappedContent,
699
- zones: Object.keys(zones).reduce(
700
- (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
701
- [zoneCompound]: zones[zoneCompound].map(walkItem)
702
- }),
703
- {}
704
- )
705
- };
706
- }
707
-
708
- // lib/data/populate-ids.ts
709
- var populateIds = (data, config, override = false) => {
710
- const id = generateId(data.type);
711
- return walkTree(
712
- __spreadProps(__spreadValues({}, data), {
713
- props: override ? __spreadProps(__spreadValues({}, data.props), { id }) : __spreadValues({}, data.props)
714
- }),
715
- config,
716
- (contents) => contents.map((item) => {
717
- const id2 = generateId(item.type);
718
- return __spreadProps(__spreadValues({}, item), {
719
- props: override ? __spreadProps(__spreadValues({}, item.props), { id: id2 }) : __spreadValues({ id: id2 }, item.props)
720
- });
721
- })
722
- );
723
- };
724
-
725
- // reducer/actions/insert.ts
726
- function insertAction(state, action, appStore) {
727
- const id = action.id || generateId(action.componentType);
728
- const emptyComponentData = populateIds(
729
- {
730
- type: action.componentType,
731
- props: __spreadProps(__spreadValues({}, appStore.config.components[action.componentType].defaultProps || {}), {
732
- id
733
- })
734
- },
735
- appStore.config
736
- );
737
- const [parentId] = action.destinationZone.split(":");
738
- const idsInPath = getIdsForParent(action.destinationZone, state);
739
- return walkAppState(
740
- state,
741
- appStore.config,
742
- (content, zoneCompound) => {
743
- if (zoneCompound === action.destinationZone) {
744
- return insert(
745
- content || [],
746
- action.destinationIndex,
747
- emptyComponentData
748
- );
749
- }
750
- return content;
751
- },
752
- (childItem, path) => {
753
- if (childItem.props.id === id || childItem.props.id === parentId) {
754
- return childItem;
755
- } else if (idsInPath.includes(childItem.props.id)) {
756
- return childItem;
757
- } else if (path.includes(action.destinationZone)) {
758
- return childItem;
759
- }
760
- return null;
761
- }
762
- );
763
- }
764
-
765
- // reducer/actions/replace.ts
766
- init_react_import();
767
- var replaceAction = (state, action, appStore) => {
768
- const [parentId] = action.destinationZone.split(":");
769
- const idsInPath = getIdsForParent(action.destinationZone, state);
770
- const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
771
- const idChanged = originalId !== action.data.props.id;
772
- if (idChanged) {
773
- throw new Error(
774
- `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
775
- );
776
- }
777
- const newSlotIds = [];
778
- const data = walkTree(action.data, appStore.config, (contents, opts) => {
779
- newSlotIds.push(`${opts.parentId}:${opts.propName}`);
780
- return contents.map((item) => {
781
- const id = generateId(item.type);
782
- return __spreadProps(__spreadValues({}, item), {
783
- props: __spreadValues({ id }, item.props)
784
- });
785
- });
786
- });
787
- const stateWithDeepSlotsRemoved = __spreadValues({}, state);
788
- Object.keys(state.indexes.zones).forEach((zoneCompound) => {
789
- const id = zoneCompound.split(":")[0];
790
- if (id === originalId) {
791
- if (!newSlotIds.includes(zoneCompound)) {
792
- delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
793
- }
794
- }
795
- });
796
- return walkAppState(
797
- stateWithDeepSlotsRemoved,
798
- appStore.config,
799
- (content, zoneCompound) => {
800
- const newContent = [...content];
801
- if (zoneCompound === action.destinationZone) {
802
- newContent[action.destinationIndex] = data;
803
- }
804
- return newContent;
805
- },
806
- (childItem, path) => {
807
- const pathIds = path.map((p) => p.split(":")[0]);
808
- if (childItem.props.id === data.props.id) {
809
- return data;
810
- } else if (childItem.props.id === parentId) {
811
- return childItem;
812
- } else if (idsInPath.indexOf(childItem.props.id) > -1) {
813
- return childItem;
814
- } else if (pathIds.indexOf(data.props.id) > -1) {
815
- return childItem;
816
- }
817
- return null;
818
- }
819
- );
820
- };
821
-
822
- // reducer/actions/replace-root.ts
823
- init_react_import();
824
- var replaceRootAction = (state, action, appStore) => {
825
- return walkAppState(
826
- state,
827
- appStore.config,
828
- (content) => content,
829
- (childItem) => {
830
- if (childItem.props.id === "root") {
831
- return __spreadProps(__spreadValues({}, childItem), {
832
- props: __spreadValues(__spreadValues({}, childItem.props), action.root.props),
833
- readOnly: action.root.readOnly
834
- });
835
- }
836
- return childItem;
837
- }
838
- );
839
- };
840
-
841
- // reducer/actions/duplicate.ts
842
- init_react_import();
843
-
844
- // lib/data/get-item.ts
845
- init_react_import();
846
- function getItem(selector, state) {
847
- var _a, _b;
848
- const zone = (_a = state.indexes.zones) == null ? void 0 : _a[selector.zone || rootDroppableId];
849
- return zone ? (_b = state.indexes.nodes[zone.contentIds[selector.index]]) == null ? void 0 : _b.data : void 0;
850
- }
851
-
852
- // reducer/actions/duplicate.ts
853
- function duplicateAction(state, action, appStore) {
854
- const item = getItem(
855
- { index: action.sourceIndex, zone: action.sourceZone },
856
- state
857
- );
858
- const idsInPath = getIdsForParent(action.sourceZone, state);
859
- const newItem = __spreadProps(__spreadValues({}, item), {
860
- props: __spreadProps(__spreadValues({}, item.props), {
861
- id: generateId(item.type)
862
- })
863
- });
864
- const modified = walkAppState(
865
- state,
866
- appStore.config,
867
- (content, zoneCompound) => {
868
- if (zoneCompound === action.sourceZone) {
869
- return insert(content, action.sourceIndex + 1, item);
870
- }
871
- return content;
872
- },
873
- (childItem, path, index) => {
874
- const zoneCompound = path[path.length - 1];
875
- const parents = path.map((p) => p.split(":")[0]);
876
- if (parents.indexOf(newItem.props.id) > -1) {
877
- return __spreadProps(__spreadValues({}, childItem), {
878
- props: __spreadProps(__spreadValues({}, childItem.props), {
879
- id: generateId(childItem.type)
880
- })
881
- });
882
- }
883
- if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
884
- return newItem;
885
- }
886
- const [sourceZoneParent] = action.sourceZone.split(":");
887
- if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
888
- return childItem;
889
- }
890
- return null;
891
- }
892
- );
893
- return __spreadProps(__spreadValues({}, modified), {
894
- ui: __spreadProps(__spreadValues({}, modified.ui), {
895
- itemSelector: {
896
- index: action.sourceIndex + 1,
897
- zone: action.sourceZone
898
- }
899
- })
900
- });
901
- }
902
-
903
- // reducer/actions/reorder.ts
904
- init_react_import();
905
-
906
- // reducer/actions/move.ts
907
- init_react_import();
908
-
909
- // lib/data/remove.ts
910
- init_react_import();
911
- var remove = (list, index) => {
912
- const result = Array.from(list);
913
- result.splice(index, 1);
914
- return result;
915
- };
916
-
917
- // reducer/actions/move.ts
918
- var moveAction = (state, action, appStore) => {
919
- if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
920
- return state;
921
- }
922
- const item = getItem(
923
- { zone: action.sourceZone, index: action.sourceIndex },
924
- state
925
- );
926
- if (!item) return state;
927
- const idsInSourcePath = getIdsForParent(action.sourceZone, state);
928
- const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
929
- return walkAppState(
930
- state,
931
- appStore.config,
932
- (content, zoneCompound) => {
933
- if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
934
- return insert(
935
- remove(content, action.sourceIndex),
936
- action.destinationIndex,
937
- item
938
- );
939
- } else if (zoneCompound === action.sourceZone) {
940
- return remove(content, action.sourceIndex);
941
- } else if (zoneCompound === action.destinationZone) {
942
- return insert(content, action.destinationIndex, item);
943
- }
944
- return content;
945
- },
946
- (childItem, path) => {
947
- const [sourceZoneParent] = action.sourceZone.split(":");
948
- const [destinationZoneParent] = action.destinationZone.split(":");
949
- const childId = childItem.props.id;
950
- if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
951
- return childItem;
952
- }
953
- return null;
954
- }
955
- );
956
- };
957
-
958
- // reducer/actions/reorder.ts
959
- var reorderAction = (state, action, appStore) => {
960
- return moveAction(
961
- state,
962
- {
963
- type: "move",
964
- sourceIndex: action.sourceIndex,
965
- sourceZone: action.destinationZone,
966
- destinationIndex: action.destinationIndex,
967
- destinationZone: action.destinationZone
968
- },
969
- appStore
970
- );
971
- };
972
-
973
- // reducer/actions/remove.ts
974
- init_react_import();
975
- var removeAction = (state, action, appStore) => {
976
- const item = getItem({ index: action.index, zone: action.zone }, state);
977
- const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
978
- (acc, [nodeId, nodeData]) => {
979
- const pathIds = nodeData.path.map((p) => p.split(":")[0]);
980
- if (pathIds.includes(item.props.id)) {
981
- return [...acc, nodeId];
982
- }
983
- return acc;
984
- },
985
- [item.props.id]
986
- );
987
- const newState = walkAppState(
988
- state,
989
- appStore.config,
990
- (content, zoneCompound) => {
991
- if (zoneCompound === action.zone) {
992
- return remove(content, action.index);
993
- }
994
- return content;
995
- }
996
- );
997
- Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
998
- const parentId = zoneCompound.split(":")[0];
999
- if (nodesToDelete.includes(parentId) && newState.data.zones) {
1000
- delete newState.data.zones[zoneCompound];
1001
- }
1002
- });
1003
- Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
1004
- const parentId = zoneCompound.split(":")[0];
1005
- if (nodesToDelete.includes(parentId)) {
1006
- delete newState.indexes.zones[zoneCompound];
1007
- }
1008
- });
1009
- nodesToDelete.forEach((id) => {
1010
- delete newState.indexes.nodes[id];
1011
- });
1012
- return newState;
1013
- };
1014
-
1015
- // reducer/actions/register-zone.ts
1016
- init_react_import();
1017
- var zoneCache = {};
1018
- function registerZoneAction(state, action) {
1019
- if (zoneCache[action.zone]) {
1020
- return __spreadProps(__spreadValues({}, state), {
1021
- data: __spreadProps(__spreadValues({}, state.data), {
1022
- zones: __spreadProps(__spreadValues({}, state.data.zones), {
1023
- [action.zone]: zoneCache[action.zone]
1024
- })
1025
- }),
1026
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
1027
- zones: __spreadProps(__spreadValues({}, state.indexes.zones), {
1028
- [action.zone]: __spreadProps(__spreadValues({}, state.indexes.zones[action.zone]), {
1029
- contentIds: zoneCache[action.zone].map((item) => item.props.id),
1030
- type: "dropzone"
1031
- })
1032
- })
1033
- })
1034
- });
1035
- }
1036
- return __spreadProps(__spreadValues({}, state), { data: setupZone(state.data, action.zone) });
1037
- }
1038
- function unregisterZoneAction(state, action) {
1039
- const _zones = __spreadValues({}, state.data.zones || {});
1040
- const zoneIndex = __spreadValues({}, state.indexes.zones || {});
1041
- if (_zones[action.zone]) {
1042
- zoneCache[action.zone] = _zones[action.zone];
1043
- delete _zones[action.zone];
1044
- }
1045
- delete zoneIndex[action.zone];
1046
- return __spreadProps(__spreadValues({}, state), {
1047
- data: __spreadProps(__spreadValues({}, state.data), {
1048
- zones: _zones
1049
- }),
1050
- indexes: __spreadProps(__spreadValues({}, state.indexes), {
1051
- zones: zoneIndex
1052
- })
1053
- });
1054
- }
1055
-
1056
- // reducer/actions/set-data.ts
1057
- init_react_import();
1058
- var setDataAction = (state, action, appStore) => {
1059
- if (typeof action.data === "object") {
1060
- console.warn(
1061
- "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
1062
- );
1063
- return walkAppState(
1064
- __spreadProps(__spreadValues({}, state), {
1065
- data: __spreadValues(__spreadValues({}, state.data), action.data)
1066
- }),
1067
- appStore.config
1068
- );
1069
- }
1070
- return walkAppState(
1071
- __spreadProps(__spreadValues({}, state), {
1072
- data: __spreadValues(__spreadValues({}, state.data), action.data(state.data))
1073
- }),
1074
- appStore.config
1075
- );
1076
- };
1077
-
1078
- // reducer/actions/set-ui.ts
1079
- init_react_import();
1080
- var setUiAction = (state, action) => {
1081
- if (typeof action.ui === "object") {
1082
- return __spreadProps(__spreadValues({}, state), {
1083
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui)
1084
- });
1085
- }
1086
- return __spreadProps(__spreadValues({}, state), {
1087
- ui: __spreadValues(__spreadValues({}, state.ui), action.ui(state.ui))
1088
- });
1089
- };
1090
-
1091
- // lib/data/make-state-public.ts
1092
- init_react_import();
1093
- var makeStatePublic = (state) => {
1094
- const { data, ui } = state;
1095
- return { data, ui };
1096
- };
1097
-
1098
- // reducer/actions.tsx
1099
- init_react_import();
1100
-
1101
- // reducer/index.ts
1102
- function storeInterceptor(reducer, record, onAction) {
1103
- return (state, action) => {
1104
- const newAppState = reducer(state, action);
1105
- const isValidType = ![
1106
- "registerZone",
1107
- "unregisterZone",
1108
- "setData",
1109
- "setUi",
1110
- "set"
1111
- ].includes(action.type);
1112
- if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
1113
- if (record) record(newAppState);
1114
- }
1115
- onAction == null ? void 0 : onAction(action, makeStatePublic(newAppState), makeStatePublic(state));
1116
- return newAppState;
1117
- };
1118
- }
1119
- function createReducer({
1120
- record,
1121
- onAction,
1122
- appStore
1123
- }) {
1124
- return storeInterceptor(
1125
- (state, action) => {
1126
- if (action.type === "set") {
1127
- return setAction(state, action, appStore);
1128
- }
1129
- if (action.type === "insert") {
1130
- return insertAction(state, action, appStore);
1131
- }
1132
- if (action.type === "replace") {
1133
- return replaceAction(state, action, appStore);
1134
- }
1135
- if (action.type === "replaceRoot") {
1136
- return replaceRootAction(state, action, appStore);
1137
- }
1138
- if (action.type === "duplicate") {
1139
- return duplicateAction(state, action, appStore);
1140
- }
1141
- if (action.type === "reorder") {
1142
- return reorderAction(state, action, appStore);
1143
- }
1144
- if (action.type === "move") {
1145
- return moveAction(state, action, appStore);
1146
- }
1147
- if (action.type === "remove") {
1148
- return removeAction(state, action, appStore);
1149
- }
1150
- if (action.type === "registerZone") {
1151
- return registerZoneAction(state, action);
1152
- }
1153
- if (action.type === "unregisterZone") {
1154
- return unregisterZoneAction(state, action);
1155
- }
1156
- if (action.type === "setData") {
1157
- return setDataAction(state, action, appStore);
1158
- }
1159
- if (action.type === "setUi") {
1160
- return setUiAction(state, action);
1161
- }
1162
- return state;
1163
- },
1164
- record,
1165
- onAction
1166
- );
1167
- }
1168
-
1169
- // components/ViewportControls/default-viewports.ts
1170
- init_react_import();
1171
- var defaultViewports = [
1172
- { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
1173
- { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
1174
- { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
1175
- ];
1176
-
1177
- // store/index.ts
1178
- var import_zustand2 = require("zustand");
1179
- var import_middleware2 = require("zustand/middleware");
1180
- var import_react7 = require("react");
1181
-
1182
- // store/slices/history.ts
1183
- init_react_import();
1184
- var import_react4 = require("react");
1185
-
1186
- // lib/use-hotkey.ts
1187
- init_react_import();
1188
- var import_react3 = require("react");
1189
- var import_zustand = require("zustand");
1190
- var import_middleware = require("zustand/middleware");
1191
- var useHotkeyStore = (0, import_zustand.create)()(
1192
- (0, import_middleware.subscribeWithSelector)((set) => ({
1193
- held: {},
1194
- hold: (key) => set((s) => s.held[key] ? s : { held: __spreadProps(__spreadValues({}, s.held), { [key]: true }) }),
1195
- release: (key) => set((s) => s.held[key] ? { held: __spreadProps(__spreadValues({}, s.held), { [key]: false }) } : s),
1196
- reset: (held = {}) => set(() => ({ held })),
1197
- triggers: {}
1198
- }))
1199
- );
1200
-
1201
- // store/slices/history.ts
1202
- var EMPTY_HISTORY_INDEX = 0;
1203
- function debounce(func, timeout = 300) {
1204
- let timer;
1205
- return (...args) => {
1206
- clearTimeout(timer);
1207
- timer = setTimeout(() => {
1208
- func(...args);
1209
- }, timeout);
1210
- };
1211
- }
1212
- var tidyState = (state) => {
1213
- return __spreadProps(__spreadValues({}, state), {
1214
- ui: __spreadProps(__spreadValues({}, state.ui), {
1215
- field: {
1216
- focus: null
1217
- }
1218
- })
1219
- });
1220
- };
1221
- var createHistorySlice = (set, get) => {
1222
- const record = debounce((state) => {
1223
- const { histories, index } = get().history;
1224
- const history = {
1225
- state,
1226
- id: generateId("history")
1227
- };
1228
- const newHistories = [...histories.slice(0, index + 1), history];
1229
- set({
1230
- history: __spreadProps(__spreadValues({}, get().history), {
1231
- histories: newHistories,
1232
- index: newHistories.length - 1
1233
- })
1234
- });
1235
- }, 250);
1236
- return {
1237
- initialAppState: {},
1238
- index: EMPTY_HISTORY_INDEX,
1239
- histories: [],
1240
- hasPast: () => get().history.index > EMPTY_HISTORY_INDEX,
1241
- hasFuture: () => get().history.index < get().history.histories.length - 1,
1242
- prevHistory: () => {
1243
- const { history } = get();
1244
- return history.hasPast() ? history.histories[history.index - 1] : null;
1245
- },
1246
- nextHistory: () => {
1247
- const s = get().history;
1248
- return s.hasFuture() ? s.histories[s.index + 1] : null;
1249
- },
1250
- currentHistory: () => get().history.histories[get().history.index],
1251
- back: () => {
1252
- var _a;
1253
- const { history, dispatch } = get();
1254
- if (history.hasPast()) {
1255
- const state = tidyState(
1256
- ((_a = history.prevHistory()) == null ? void 0 : _a.state) || history.initialAppState
1257
- );
1258
- dispatch({
1259
- type: "set",
1260
- state
1261
- });
1262
- set({ history: __spreadProps(__spreadValues({}, history), { index: history.index - 1 }) });
1263
- }
1264
- },
1265
- forward: () => {
1266
- var _a;
1267
- const { history, dispatch } = get();
1268
- if (history.hasFuture()) {
1269
- const state = (_a = history.nextHistory()) == null ? void 0 : _a.state;
1270
- dispatch({ type: "set", state: state ? tidyState(state) : {} });
1271
- set({ history: __spreadProps(__spreadValues({}, history), { index: history.index + 1 }) });
1272
- }
1273
- },
1274
- setHistories: (histories) => {
1275
- var _a;
1276
- const { dispatch, history } = get();
1277
- dispatch({
1278
- type: "set",
1279
- state: ((_a = histories[histories.length - 1]) == null ? void 0 : _a.state) || history.initialAppState
1280
- });
1281
- set({ history: __spreadProps(__spreadValues({}, history), { histories, index: histories.length - 1 }) });
1282
- },
1283
- setHistoryIndex: (index) => {
1284
- var _a;
1285
- const { dispatch, history } = get();
1286
- dispatch({
1287
- type: "set",
1288
- state: ((_a = history.histories[index]) == null ? void 0 : _a.state) || history.initialAppState
1289
- });
1290
- set({ history: __spreadProps(__spreadValues({}, history), { index }) });
1291
- },
1292
- record
1293
- };
1294
- };
1295
-
1296
- // store/slices/nodes.ts
1297
- init_react_import();
1298
- var createNodesSlice = (set, get) => ({
1299
- nodes: {},
1300
- registerNode: (id, node) => {
1301
- const s = get().nodes;
1302
- const emptyNode = {
1303
- id,
1304
- methods: {
1305
- sync: () => null,
1306
- hideOverlay: () => null,
1307
- showOverlay: () => null
1308
- },
1309
- element: null
1310
- };
1311
- const existingNode = s.nodes[id];
1312
- set({
1313
- nodes: __spreadProps(__spreadValues({}, s), {
1314
- nodes: __spreadProps(__spreadValues({}, s.nodes), {
1315
- [id]: __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, emptyNode), existingNode), node), {
1316
- id
1317
- })
1318
- })
1319
- })
1320
- });
1321
- },
1322
- unregisterNode: (id) => {
1323
- const s = get().nodes;
1324
- const existingNode = s.nodes[id];
1325
- if (existingNode) {
1326
- const newNodes = __spreadValues({}, s.nodes);
1327
- delete newNodes[id];
1328
- set({
1329
- nodes: __spreadProps(__spreadValues({}, s), {
1330
- nodes: newNodes
1331
- })
1332
- });
1333
- }
1334
- }
1335
- });
1336
-
1337
- // store/slices/permissions.ts
1338
- init_react_import();
1339
- var import_react5 = require("react");
1340
-
1341
- // lib/data/flatten-data.ts
1342
- init_react_import();
1343
- var flattenData = (state, config) => {
1344
- const data = [];
1345
- walkAppState(
1346
- state,
1347
- config,
1348
- (content) => content,
1349
- (item) => {
1350
- data.push(item);
1351
- return null;
1352
- }
1353
- );
1354
- return data;
1355
- };
1356
-
1357
- // lib/get-changed.ts
1358
- init_react_import();
1359
- var import_fast_deep_equal = __toESM(require("fast-deep-equal"));
1360
- var getChanged = (newItem, oldItem) => {
1361
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
1362
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
1363
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
1364
- return __spreadProps(__spreadValues({}, acc), {
1365
- [item]: !(0, import_fast_deep_equal.default)(oldItemProps[item], newItemProps[item])
1366
- });
1367
- }, {}) : {};
1368
- };
1369
-
1370
- // store/slices/permissions.ts
1371
- var createPermissionsSlice = (set, get) => {
1372
- const resolvePermissions = (..._0) => __async(void 0, [..._0], function* (params = {}, force) {
1373
- const { state, permissions, config } = get();
1374
- const { cache: cache2, globalPermissions } = permissions;
1375
- const resolveDataForItem = (item2, force2 = false) => __async(void 0, null, function* () {
1376
- var _a, _b, _c;
1377
- const { config: config2, state: appState, setComponentLoading } = get();
1378
- const componentConfig = item2.type === "root" ? config2.root : config2.components[item2.type];
1379
- if (!componentConfig) {
1380
- return;
1381
- }
1382
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig.permissions);
1383
- if (componentConfig.resolvePermissions) {
1384
- const changed = getChanged(item2, (_a = cache2[item2.props.id]) == null ? void 0 : _a.lastData);
1385
- if (Object.values(changed).some((el) => el === true) || force2) {
1386
- const clearTimeout2 = setComponentLoading(item2.props.id, true, 50);
1387
- const resolvedPermissions = yield componentConfig.resolvePermissions(
1388
- item2,
1389
- {
1390
- changed,
1391
- lastPermissions: ((_b = cache2[item2.props.id]) == null ? void 0 : _b.lastPermissions) || null,
1392
- permissions: initialPermissions,
1393
- appState: makeStatePublic(appState),
1394
- lastData: ((_c = cache2[item2.props.id]) == null ? void 0 : _c.lastData) || null
1395
- }
1396
- );
1397
- const latest = get().permissions;
1398
- set({
1399
- permissions: __spreadProps(__spreadValues({}, latest), {
1400
- cache: __spreadProps(__spreadValues({}, latest.cache), {
1401
- [item2.props.id]: {
1402
- lastData: item2,
1403
- lastPermissions: resolvedPermissions
1404
- }
1405
- }),
1406
- resolvedPermissions: __spreadProps(__spreadValues({}, latest.resolvedPermissions), {
1407
- [item2.props.id]: resolvedPermissions
1408
- })
1409
- })
1410
- });
1411
- clearTimeout2();
1412
- }
1413
- }
1414
- });
1415
- const resolveDataForRoot = (force2 = false) => {
1416
- const { state: appState } = get();
1417
- resolveDataForItem(
1418
- // Shim the root data in by conforming to component data shape
1419
- {
1420
- type: "root",
1421
- props: __spreadProps(__spreadValues({}, appState.data.root.props), { id: "root" })
1422
- },
1423
- force2
1424
- );
1425
- };
1426
- const { item, type, root } = params;
1427
- if (item) {
1428
- yield resolveDataForItem(item, force);
1429
- } else if (type) {
1430
- flattenData(state, config).filter((item2) => item2.type === type).map((item2) => __async(void 0, null, function* () {
1431
- yield resolveDataForItem(item2, force);
1432
- }));
1433
- } else if (root) {
1434
- resolveDataForRoot(force);
1435
- } else {
1436
- flattenData(state, config).map((item2) => __async(void 0, null, function* () {
1437
- yield resolveDataForItem(item2, force);
1438
- }));
1439
- }
1440
- });
1441
- const refreshPermissions = (params) => resolvePermissions(params, true);
1442
- return {
1443
- cache: {},
1444
- globalPermissions: {
1445
- drag: true,
1446
- edit: true,
1447
- delete: true,
1448
- duplicate: true,
1449
- insert: true
1450
- },
1451
- resolvedPermissions: {},
1452
- getPermissions: ({ item, type, root } = {}) => {
1453
- const { config, permissions } = get();
1454
- const { globalPermissions, resolvedPermissions } = permissions;
1455
- if (item) {
1456
- const componentConfig = config.components[item.type];
1457
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1458
- const resolvedForItem = resolvedPermissions[item.props.id];
1459
- return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1460
- } else if (type) {
1461
- const componentConfig = config.components[type];
1462
- return __spreadValues(__spreadValues({}, globalPermissions), componentConfig == null ? void 0 : componentConfig.permissions);
1463
- } else if (root) {
1464
- const rootConfig = config.root;
1465
- const initialPermissions = __spreadValues(__spreadValues({}, globalPermissions), rootConfig == null ? void 0 : rootConfig.permissions);
1466
- const resolvedForItem = resolvedPermissions["root"];
1467
- return resolvedForItem ? __spreadValues(__spreadValues({}, globalPermissions), resolvedForItem) : initialPermissions;
1468
- }
1469
- return globalPermissions;
1470
- },
1471
- resolvePermissions,
1472
- refreshPermissions
1473
- };
1474
- };
1475
-
1476
- // store/slices/fields.ts
1477
- init_react_import();
1478
- var import_react6 = require("react");
1479
- var createFieldsSlice = (_set, _get) => {
1480
- return {
1481
- fields: {},
1482
- loading: false,
1483
- lastResolvedData: {},
1484
- id: void 0
1485
- };
1486
- };
1487
-
1488
- // lib/resolve-component-data.ts
1489
- init_react_import();
1490
- var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
1491
- var cache = { lastChange: {} };
1492
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
1493
- const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
1494
- const resolvedItem = __spreadValues({}, item);
1495
- const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
1496
- const id = "id" in item.props ? item.props.id : "root";
1497
- if (shouldRunResolver) {
1498
- const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
1499
- if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
1500
- return { node: resolved, didChange: false };
1501
- }
1502
- const changed = getChanged(item, oldItem);
1503
- if (onResolveStart) {
1504
- onResolveStart(item);
1505
- }
1506
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
1507
- changed,
1508
- lastData: oldItem,
1509
- metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
1510
- trigger
1511
- });
1512
- resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
1513
- if (Object.keys(readOnly).length) {
1514
- resolvedItem.readOnly = readOnly;
1515
- }
1516
- }
1517
- let itemWithResolvedChildren = yield mapFields(
1518
- resolvedItem,
1519
- {
1520
- slot: (_02) => __async(void 0, [_02], function* ({ value }) {
1521
- const content = value;
1522
- return yield Promise.all(
1523
- content.map(
1524
- (childItem) => __async(void 0, null, function* () {
1525
- return (yield resolveComponentData(
1526
- childItem,
1527
- config,
1528
- metadata,
1529
- onResolveStart,
1530
- onResolveEnd,
1531
- trigger
1532
- )).node;
1533
- })
1534
- )
1535
- );
1536
- })
1537
- },
1538
- config
1539
- );
1540
- if (shouldRunResolver && onResolveEnd) {
1541
- onResolveEnd(resolvedItem);
1542
- }
1543
- cache.lastChange[id] = {
1544
- item,
1545
- resolved: itemWithResolvedChildren
1546
- };
1547
- return {
1548
- node: itemWithResolvedChildren,
1549
- didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
1550
- };
1551
- });
1552
-
1553
- // lib/data/to-root.ts
1554
- init_react_import();
1555
- var toRoot = (item) => {
1556
- if ("type" in item && item.type !== "root") {
1557
- throw new Error("Converting non-root item to root.");
1558
- }
1559
- const { readOnly } = item;
1560
- if (item.props) {
1561
- if ("id" in item.props) {
1562
- const _a = item.props, { id } = _a, props = __objRest(_a, ["id"]);
1563
- return { props, readOnly };
1564
- }
1565
- return { props: item.props, readOnly };
1566
- }
1567
- return { props: {}, readOnly };
1568
- };
1569
-
1570
- // store/default-app-state.ts
1571
- init_react_import();
1572
- var defaultAppState = {
1573
- data: { content: [], root: {}, zones: {} },
1574
- ui: {
1575
- leftSideBarVisible: true,
1576
- rightSideBarVisible: true,
1577
- arrayState: {},
1578
- itemSelector: null,
1579
- componentList: {},
1580
- isDragging: false,
1581
- previewMode: "edit",
1582
- viewports: {
1583
- current: {
1584
- width: defaultViewports[0].width,
1585
- height: defaultViewports[0].height || "auto"
1586
- },
1587
- options: [],
1588
- controlsVisible: true
1589
- },
1590
- field: { focus: null }
1591
- },
1592
- indexes: {
1593
- nodes: {},
1594
- zones: {}
1595
- }
1596
- };
1597
-
1598
- // store/index.ts
1599
- var defaultPageFields = {
1600
- title: { type: "text" }
1601
- };
1602
- var createAppStore = (initialAppStore) => (0, import_zustand2.create)()(
1603
- (0, import_middleware2.subscribeWithSelector)((set, get) => {
1604
- var _a, _b;
1605
- return __spreadProps(__spreadValues({
1606
- state: defaultAppState,
1607
- config: { components: {} },
1608
- componentState: {},
1609
- plugins: [],
1610
- overrides: {},
1611
- viewports: defaultViewports,
1612
- zoomConfig: {
1613
- autoZoom: 1,
1614
- rootHeight: 0,
1615
- zoom: 1
1616
- },
1617
- status: "LOADING",
1618
- iframe: {},
1619
- metadata: {},
1620
- fieldTransforms: {}
1621
- }, initialAppStore), {
1622
- fields: createFieldsSlice(set, get),
1623
- history: createHistorySlice(set, get),
1624
- nodes: createNodesSlice(set, get),
1625
- permissions: createPermissionsSlice(set, get),
1626
- getComponentConfig: (type) => {
1627
- var _a2;
1628
- const { config, selectedItem } = get();
1629
- const rootFields = ((_a2 = config.root) == null ? void 0 : _a2.fields) || defaultPageFields;
1630
- return type && type !== "root" ? config.components[type] : selectedItem ? config.components[selectedItem.type] : __spreadProps(__spreadValues({}, config.root), { fields: rootFields });
1631
- },
1632
- selectedItem: ((_a = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _a.ui.itemSelector) ? getItem(
1633
- (_b = initialAppStore == null ? void 0 : initialAppStore.state) == null ? void 0 : _b.ui.itemSelector,
1634
- initialAppStore.state
1635
- ) : null,
1636
- dispatch: (action) => set((s) => {
1637
- var _a2, _b2;
1638
- const { record } = get().history;
1639
- const dispatch = createReducer({
1640
- record,
1641
- appStore: s
1642
- });
1643
- const state = dispatch(s.state, action);
1644
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1645
- (_b2 = (_a2 = get()).onAction) == null ? void 0 : _b2.call(_a2, action, state, get().state);
1646
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1647
- }),
1648
- setZoomConfig: (zoomConfig) => set({ zoomConfig }),
1649
- setStatus: (status) => set({ status }),
1650
- setComponentState: (componentState) => set({ componentState }),
1651
- pendingLoadTimeouts: {},
1652
- setComponentLoading: (id, loading = true, defer = 0) => {
1653
- const { setComponentState, pendingLoadTimeouts } = get();
1654
- const loadId = generateId();
1655
- const setLoading = () => {
1656
- var _a2;
1657
- const { componentState } = get();
1658
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1659
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1660
- loadingCount: (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) + 1
1661
- })
1662
- }));
1663
- };
1664
- const unsetLoading = () => {
1665
- var _a2;
1666
- const { componentState } = get();
1667
- clearTimeout(timeout);
1668
- delete pendingLoadTimeouts[loadId];
1669
- set({ pendingLoadTimeouts });
1670
- setComponentState(__spreadProps(__spreadValues({}, componentState), {
1671
- [id]: __spreadProps(__spreadValues({}, componentState[id]), {
1672
- loadingCount: Math.max(
1673
- (((_a2 = componentState[id]) == null ? void 0 : _a2.loadingCount) || 0) - 1,
1674
- 0
1675
- )
1676
- })
1677
- }));
1678
- };
1679
- const timeout = setTimeout(() => {
1680
- if (loading) {
1681
- setLoading();
1682
- } else {
1683
- unsetLoading();
1684
- }
1685
- delete pendingLoadTimeouts[loadId];
1686
- set({ pendingLoadTimeouts });
1687
- }, defer);
1688
- set({
1689
- pendingLoadTimeouts: __spreadProps(__spreadValues({}, pendingLoadTimeouts), {
1690
- [id]: timeout
1691
- })
1692
- });
1693
- return unsetLoading;
1694
- },
1695
- unsetComponentLoading: (id) => {
1696
- const { setComponentLoading } = get();
1697
- setComponentLoading(id, false);
1698
- },
1699
- // Helper
1700
- setUi: (ui, recordHistory) => set((s) => {
1701
- const dispatch = createReducer({
1702
- record: () => {
1703
- },
1704
- appStore: s
1705
- });
1706
- const state = dispatch(s.state, {
1707
- type: "setUi",
1708
- ui,
1709
- recordHistory
1710
- });
1711
- const selectedItem = state.ui.itemSelector ? getItem(state.ui.itemSelector, state) : null;
1712
- return __spreadProps(__spreadValues({}, s), { state, selectedItem });
1713
- }),
1714
- resolveComponentData: (componentData, trigger) => __async(void 0, null, function* () {
1715
- const { config, metadata, setComponentLoading, permissions } = get();
1716
- const timeouts = {};
1717
- return yield resolveComponentData(
1718
- componentData,
1719
- config,
1720
- metadata,
1721
- (item) => {
1722
- const id = "id" in item.props ? item.props.id : "root";
1723
- timeouts[id] = setComponentLoading(id, true, 50);
1724
- },
1725
- (item) => __async(void 0, null, function* () {
1726
- const id = "id" in item.props ? item.props.id : "root";
1727
- if ("type" in item) {
1728
- yield permissions.refreshPermissions({ item });
1729
- } else {
1730
- yield permissions.refreshPermissions({ root: true });
1731
- }
1732
- timeouts[id]();
1733
- }),
1734
- trigger
1735
- );
1736
- }),
1737
- resolveAndCommitData: () => __async(void 0, null, function* () {
1738
- const { config, state, dispatch, resolveComponentData: resolveComponentData2 } = get();
1739
- walkAppState(
1740
- state,
1741
- config,
1742
- (content) => content,
1743
- (childItem) => {
1744
- resolveComponentData2(childItem, "load").then((resolved) => {
1745
- const { state: state2 } = get();
1746
- const node = state2.indexes.nodes[resolved.node.props.id];
1747
- if (node && resolved.didChange) {
1748
- if (resolved.node.props.id === "root") {
1749
- dispatch({
1750
- type: "replaceRoot",
1751
- root: toRoot(resolved.node)
1752
- });
1753
- } else {
1754
- const zoneCompound = `${node.parentId}:${node.zone}`;
1755
- const parentZone = state2.indexes.zones[zoneCompound];
1756
- const index = parentZone.contentIds.indexOf(
1757
- resolved.node.props.id
1758
- );
1759
- dispatch({
1760
- type: "replace",
1761
- data: resolved.node,
1762
- destinationIndex: index,
1763
- destinationZone: zoneCompound
1764
- });
1765
- }
1766
- }
1767
- });
1768
- return childItem;
1769
- }
1770
- );
1771
- })
1772
- });
1773
- })
1774
- );
1775
- var appStoreContext = (0, import_react7.createContext)(createAppStore());
1776
- function useAppStoreApi() {
1777
- return (0, import_react7.useContext)(appStoreContext);
1778
- }
1779
-
1780
- // css-module:/home/runner/work/puck/puck/packages/core/components/InlineTextField/styles.module.css#css-module
1781
- init_react_import();
1782
- var styles_module_default = { "InlineTextField": "_InlineTextField_ilw2a_1" };
1783
-
1784
- // lib/index.ts
1785
- init_react_import();
1786
-
1787
- // lib/filter.ts
1788
- init_react_import();
1789
-
1790
- // lib/get-class-name-factory.ts
1791
- init_react_import();
1792
- var import_classnames = __toESM(require_classnames());
1793
- var getClassNameFactory = (rootClass, styles, config = { baseClass: "" }) => (options = {}) => {
1794
- if (typeof options === "string") {
1795
- const descendant = options;
1796
- const style = styles[`${rootClass}-${descendant}`];
1797
- if (style) {
1798
- return config.baseClass + styles[`${rootClass}-${descendant}`] || "";
1799
- }
1800
- return "";
1801
- } else if (typeof options === "object") {
1802
- const modifiers = options;
1803
- const prefixedModifiers = {};
1804
- for (let modifier in modifiers) {
1805
- prefixedModifiers[styles[`${rootClass}--${modifier}`]] = modifiers[modifier];
1806
- }
1807
- const c = styles[rootClass];
1808
- return config.baseClass + (0, import_classnames.default)(__spreadValues({
1809
- [c]: !!c
1810
- }, prefixedModifiers));
1811
- } else {
1812
- return config.baseClass + styles[rootClass] || "";
1813
- }
1814
- };
1815
- var get_class_name_factory_default = getClassNameFactory;
1816
-
1817
- // lib/data/reorder.ts
1818
- init_react_import();
1819
-
1820
- // lib/data/replace.ts
1821
- init_react_import();
1822
-
1823
- // lib/use-reset-auto-zoom.ts
1824
- init_react_import();
1825
-
1826
- // lib/get-zoom-config.ts
1827
- init_react_import();
1828
-
1829
- // lib/data/set-deep.ts
1830
- init_react_import();
1831
- function setDeep(node, path, newVal) {
1832
- const parts = path.split(".");
1833
- const newNode = __spreadValues({}, node);
1834
- let cur = newNode;
1835
- for (let i = 0; i < parts.length; i++) {
1836
- const [prop, idxStr] = parts[i].replace("]", "").split("[");
1837
- const isLast = i === parts.length - 1;
1838
- if (idxStr !== void 0) {
1839
- if (!Array.isArray(cur[prop])) {
1840
- cur[prop] = [];
1841
- }
1842
- const idx = Number(idxStr);
1843
- if (isLast) {
1844
- cur[prop][idx] = newVal;
1845
- continue;
1846
- }
1847
- if (cur[prop][idx] === void 0) cur[prop][idx] = {};
1848
- cur = cur[prop][idx];
1849
- continue;
1850
- }
1851
- if (isLast) {
1852
- cur[prop] = newVal;
1853
- continue;
1854
- }
1855
- if (cur[prop] === void 0) {
1856
- cur[prop] = {};
1857
- }
1858
- cur = cur[prop];
1859
- }
1860
- return __spreadValues(__spreadValues({}, node), newNode);
1861
- }
1862
-
1863
- // components/InlineTextField/index.tsx
1864
- var import_jsx_runtime = require("react/jsx-runtime");
1865
- var getClassName = get_class_name_factory_default("InlineTextField", styles_module_default);
1866
- var InlineTextFieldInternal = ({
1867
- propPath,
1868
- componentId,
1869
- value,
1870
- isReadOnly,
1871
- opts = {}
1872
- }) => {
1873
- var _a;
1874
- const ref = (0, import_react8.useRef)(null);
1875
- const appStoreApi = useAppStoreApi();
1876
- const disableLineBreaks = (_a = opts.disableLineBreaks) != null ? _a : false;
1877
- (0, import_react8.useEffect)(() => {
1878
- const appStore = appStoreApi.getState();
1879
- const data = appStore.state.indexes.nodes[componentId].data;
1880
- const componentConfig = appStore.getComponentConfig(data.type);
1881
- if (!componentConfig) {
1882
- throw new Error(
1883
- `InlineTextField Error: No config defined for ${data.type}`
1884
- );
1885
- }
1886
- if (ref.current) {
1887
- if (value !== ref.current.innerText) {
1888
- ref.current.replaceChildren(value);
1889
- }
1890
- const cleanupPortal = registerOverlayPortal(ref.current);
1891
- const handleInput = (e) => __async(void 0, null, function* () {
1892
- var _a2;
1893
- const appStore2 = appStoreApi.getState();
1894
- const node = appStore2.state.indexes.nodes[componentId];
1895
- const zoneCompound = `${node.parentId}:${node.zone}`;
1896
- const index = (_a2 = appStore2.state.indexes.zones[zoneCompound]) == null ? void 0 : _a2.contentIds.indexOf(
1897
- componentId
1898
- );
1899
- const newProps = setDeep(node.data.props, propPath, e.target.innerText);
1900
- const resolvedData = yield appStore2.resolveComponentData(
1901
- __spreadProps(__spreadValues({}, node.data), { props: newProps }),
1902
- "replace"
1903
- );
1904
- appStore2.dispatch({
1905
- type: "replace",
1906
- data: resolvedData.node,
1907
- destinationIndex: index,
1908
- destinationZone: zoneCompound
1909
- });
1910
- });
1911
- ref.current.addEventListener("input", handleInput);
1912
- return () => {
1913
- var _a2;
1914
- (_a2 = ref.current) == null ? void 0 : _a2.removeEventListener("input", handleInput);
1915
- cleanupPortal == null ? void 0 : cleanupPortal();
1916
- };
475
+ // lib/resolve-component-data.ts
476
+ var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
477
+ var cache = { lastChange: {} };
478
+ var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd, trigger = "replace") {
479
+ const configForItem = "type" in item && item.type !== "root" ? config.components[item.type] : config.root;
480
+ const resolvedItem = __spreadValues({}, item);
481
+ const shouldRunResolver = (configForItem == null ? void 0 : configForItem.resolveData) && item.props;
482
+ const id = "id" in item.props ? item.props.id : "root";
483
+ if (shouldRunResolver) {
484
+ const { item: oldItem = null, resolved = {} } = cache.lastChange[id] || {};
485
+ if (item && (0, import_fast_deep_equal2.default)(item, oldItem)) {
486
+ return { node: resolved, didChange: false };
1917
487
  }
1918
- }, [appStoreApi, ref.current, value]);
1919
- const [isHovering, setIsHovering] = (0, import_react8.useState)(false);
1920
- const [isFocused, setIsFocused] = (0, import_react8.useState)(false);
1921
- return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
1922
- "span",
1923
- {
1924
- className: getClassName(),
1925
- ref,
1926
- contentEditable: isHovering || isFocused ? "plaintext-only" : "false",
1927
- onClick: (e) => {
1928
- e.preventDefault();
1929
- e.stopPropagation();
1930
- },
1931
- onClickCapture: (e) => {
1932
- e.preventDefault();
1933
- e.stopPropagation();
1934
- },
1935
- onKeyDown: (e) => {
1936
- if (disableLineBreaks && e.key === "Enter" || isReadOnly) {
1937
- e.preventDefault();
1938
- }
1939
- },
1940
- onMouseOverCapture: () => setIsHovering(true),
1941
- onMouseOutCapture: () => setIsHovering(false),
1942
- onFocus: () => setIsFocused(true),
1943
- onBlur: () => setIsFocused(false)
488
+ const changed = getChanged(item, oldItem);
489
+ if (onResolveStart) {
490
+ onResolveStart(item);
1944
491
  }
1945
- );
1946
- };
1947
- var InlineTextField = (0, import_react8.memo)(InlineTextFieldInternal);
1948
-
1949
- // lib/field-transforms/default-transforms.tsx
1950
- var import_jsx_runtime2 = require("react/jsx-runtime");
1951
- var getSlotTransform = (renderSlotEdit, renderSlotRender = renderSlotEdit) => ({
1952
- slot: ({ value: content, propName, field, isReadOnly }) => {
1953
- const render = isReadOnly ? renderSlotRender : renderSlotEdit;
1954
- const Slot = (dzProps) => render(__spreadProps(__spreadValues({
1955
- allow: (field == null ? void 0 : field.type) === "slot" ? field.allow : [],
1956
- disallow: (field == null ? void 0 : field.type) === "slot" ? field.disallow : []
1957
- }, dzProps), {
1958
- zone: propName,
1959
- content
1960
- }));
1961
- return Slot;
1962
- }
1963
- });
1964
-
1965
- // lib/use-slots.tsx
1966
- function useSlots(config, item, renderSlotEdit, renderSlotRender = renderSlotEdit, readOnly, forceReadOnly) {
1967
- return useFieldTransforms(
1968
- config,
1969
- item,
1970
- getSlotTransform(renderSlotEdit, renderSlotRender),
1971
- readOnly,
1972
- forceReadOnly
1973
- );
1974
- }
1975
-
1976
- // components/SlotRender/server.tsx
1977
- init_react_import();
1978
- var import_react9 = require("react");
1979
- var import_jsx_runtime3 = require("react/jsx-runtime");
1980
- var SlotRenderPure = (props) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SlotRender, __spreadValues({}, props));
1981
- var Item = ({
1982
- config,
1983
- item,
1984
- metadata
1985
- }) => {
1986
- const Component = config.components[item.type];
1987
- const props = useSlots(config, item, (slotProps) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, slotProps), { config, metadata })));
1988
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
1989
- Component.render,
1990
- __spreadProps(__spreadValues({}, props), {
1991
- puck: __spreadProps(__spreadValues({}, props.puck), {
1992
- renderDropZone: DropZoneRender,
1993
- metadata: metadata || {}
1994
- })
1995
- })
1996
- );
1997
- };
1998
- var SlotRender = (0, import_react9.forwardRef)(
1999
- function SlotRenderInternal({ className, style, content, config, metadata }, ref) {
2000
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, style, ref, children: content.map((item) => {
2001
- if (!config.components[item.type]) {
2002
- return null;
2003
- }
2004
- return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
2005
- Item,
2006
- {
2007
- config,
2008
- item,
2009
- metadata
2010
- },
2011
- item.props.id
2012
- );
2013
- }) });
2014
- }
2015
- );
2016
-
2017
- // components/ServerRender/index.tsx
2018
- var import_jsx_runtime4 = require("react/jsx-runtime");
2019
- function DropZoneRender({
2020
- zone,
2021
- data,
2022
- areaId = "root",
2023
- config,
2024
- metadata = {}
2025
- }) {
2026
- let zoneCompound = rootDroppableId;
2027
- let content = (data == null ? void 0 : data.content) || [];
2028
- if (!data || !config) {
2029
- return null;
2030
- }
2031
- if (areaId !== rootAreaId && zone !== rootZone) {
2032
- zoneCompound = `${areaId}:${zone}`;
2033
- content = setupZone(data, zoneCompound).zones[zoneCompound];
2034
- }
2035
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(import_jsx_runtime4.Fragment, { children: content.map((item) => {
2036
- const Component = config.components[item.type];
2037
- const props = __spreadProps(__spreadValues({}, item.props), {
2038
- puck: {
2039
- renderDropZone: ({ zone: zone2 }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2040
- DropZoneRender,
2041
- {
2042
- zone: zone2,
2043
- data,
2044
- areaId: item.props.id,
2045
- config,
2046
- metadata
2047
- }
2048
- ),
2049
- metadata,
2050
- dragRef: null,
2051
- isEditing: false
2052
- }
492
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
493
+ changed,
494
+ lastData: oldItem,
495
+ metadata: __spreadValues(__spreadValues({}, metadata), configForItem.metadata),
496
+ trigger
2053
497
  });
2054
- const renderItem = __spreadProps(__spreadValues({}, item), { props });
2055
- const propsWithSlots = useSlots(config, renderItem, (props2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
2056
- if (Component) {
2057
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(Component.render, __spreadValues({}, propsWithSlots), renderItem.props.id);
498
+ resolvedItem.props = __spreadValues(__spreadValues({}, item.props), resolvedProps);
499
+ if (Object.keys(readOnly).length) {
500
+ resolvedItem.readOnly = readOnly;
2058
501
  }
2059
- return null;
2060
- }) });
2061
- }
2062
- function Render({
2063
- config,
2064
- data,
2065
- metadata = {}
2066
- }) {
2067
- var _a;
2068
- const rootProps = "props" in data.root ? data.root.props : data.root;
2069
- const title = rootProps.title || "";
2070
- const props = __spreadProps(__spreadValues({}, rootProps), {
2071
- puck: {
2072
- renderDropZone: ({ zone }) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2073
- DropZoneRender,
2074
- {
2075
- zone,
2076
- data,
2077
- config,
2078
- metadata
2079
- }
2080
- ),
2081
- isEditing: false,
2082
- dragRef: null,
2083
- metadata
2084
- },
2085
- title,
2086
- editMode: false,
2087
- id: "puck-root"
2088
- });
2089
- const propsWithSlots = useSlots(config, { type: "root", props }, (props2) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(SlotRenderPure, __spreadProps(__spreadValues({}, props2), { config, metadata })));
2090
- if ((_a = config.root) == null ? void 0 : _a.render) {
2091
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(config.root.render, __spreadProps(__spreadValues({}, propsWithSlots), { children: /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2092
- DropZoneRender,
2093
- {
2094
- config,
2095
- data,
2096
- zone: rootZone,
2097
- metadata
2098
- }
2099
- ) }));
2100
502
  }
2101
- return /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
2102
- DropZoneRender,
503
+ let itemWithResolvedChildren = yield mapFields(
504
+ resolvedItem,
2103
505
  {
2104
- config,
2105
- data,
2106
- zone: rootZone,
2107
- metadata
2108
- }
506
+ slot: (_02) => __async(void 0, [_02], function* ({ value }) {
507
+ const content = value;
508
+ return yield Promise.all(
509
+ content.map(
510
+ (childItem) => __async(void 0, null, function* () {
511
+ return (yield resolveComponentData(
512
+ childItem,
513
+ config,
514
+ metadata,
515
+ onResolveStart,
516
+ onResolveEnd,
517
+ trigger
518
+ )).node;
519
+ })
520
+ )
521
+ );
522
+ })
523
+ },
524
+ config
2109
525
  );
2110
- }
2111
-
2112
- // lib/resolve-all-data.ts
2113
- init_react_import();
526
+ if (shouldRunResolver && onResolveEnd) {
527
+ onResolveEnd(resolvedItem);
528
+ }
529
+ cache.lastChange[id] = {
530
+ item,
531
+ resolved: itemWithResolvedChildren
532
+ };
533
+ return {
534
+ node: itemWithResolvedChildren,
535
+ didChange: !(0, import_fast_deep_equal2.default)(item, itemWithResolvedChildren)
536
+ };
537
+ });
2114
538
 
2115
539
  // lib/data/default-data.ts
2116
- init_react_import();
2117
540
  var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
2118
541
  root: data.root || {},
2119
542
  content: data.content || []
2120
543
  });
2121
544
 
2122
545
  // lib/data/to-component.ts
2123
- init_react_import();
2124
546
  var toComponent = (item) => {
2125
547
  return "type" in item ? item : __spreadProps(__spreadValues({}, item), {
2126
548
  props: __spreadProps(__spreadValues({}, item.props), { id: "root" }),
@@ -2178,8 +600,45 @@ function resolveAllData(_0, _1) {
2178
600
  });
2179
601
  }
2180
602
 
603
+ // lib/data/walk-tree.ts
604
+ function walkTree(data, config, callbackFn) {
605
+ var _a, _b;
606
+ const walkItem = (item) => {
607
+ return mapFields(
608
+ item,
609
+ {
610
+ slot: ({ value, parentId, propName }) => {
611
+ var _a2;
612
+ const content = value;
613
+ return (_a2 = callbackFn(content, { parentId, propName })) != null ? _a2 : content;
614
+ }
615
+ },
616
+ config,
617
+ true
618
+ );
619
+ };
620
+ if ("props" in data) {
621
+ return walkItem(data);
622
+ }
623
+ const _data = data;
624
+ const zones = (_a = _data.zones) != null ? _a : {};
625
+ const mappedContent = _data.content.map(walkItem);
626
+ return {
627
+ root: walkItem(_data.root),
628
+ content: (_b = callbackFn(mappedContent, {
629
+ parentId: "root",
630
+ propName: "default-zone"
631
+ })) != null ? _b : mappedContent,
632
+ zones: Object.keys(zones).reduce(
633
+ (acc, zoneCompound) => __spreadProps(__spreadValues({}, acc), {
634
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
635
+ }),
636
+ {}
637
+ )
638
+ };
639
+ }
640
+
2181
641
  // lib/transform-props.ts
2182
- init_react_import();
2183
642
  function transformProps(data, propTransforms, config = { components: {} }) {
2184
643
  const mapItem = (item) => {
2185
644
  if (propTransforms[item.type]) {
@@ -2209,8 +668,205 @@ function transformProps(data, propTransforms, config = { components: {} }) {
2209
668
  return updatedData;
2210
669
  }
2211
670
 
671
+ // components/ViewportControls/default-viewports.ts
672
+ var defaultViewports = [
673
+ { width: 360, height: "auto", icon: "Smartphone", label: "Small" },
674
+ { width: 768, height: "auto", icon: "Tablet", label: "Medium" },
675
+ { width: 1280, height: "auto", icon: "Monitor", label: "Large" }
676
+ ];
677
+
678
+ // store/default-app-state.ts
679
+ var defaultAppState = {
680
+ data: { content: [], root: {}, zones: {} },
681
+ ui: {
682
+ leftSideBarVisible: true,
683
+ rightSideBarVisible: true,
684
+ arrayState: {},
685
+ itemSelector: null,
686
+ componentList: {},
687
+ isDragging: false,
688
+ previewMode: "edit",
689
+ viewports: {
690
+ current: {
691
+ width: defaultViewports[0].width,
692
+ height: defaultViewports[0].height || "auto"
693
+ },
694
+ options: [],
695
+ controlsVisible: true
696
+ },
697
+ field: { focus: null }
698
+ },
699
+ indexes: {
700
+ nodes: {},
701
+ zones: {}
702
+ }
703
+ };
704
+
705
+ // lib/get-zone-id.ts
706
+ var getZoneId = (zoneCompound) => {
707
+ if (!zoneCompound) {
708
+ return [];
709
+ }
710
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
711
+ return zoneCompound.split(":");
712
+ }
713
+ return [rootDroppableId, zoneCompound];
714
+ };
715
+
716
+ // lib/data/for-related-zones.ts
717
+ function forRelatedZones(item, data, cb, path = []) {
718
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
719
+ const [parentId] = getZoneId(zoneCompound);
720
+ if (parentId === item.props.id) {
721
+ cb(path, zoneCompound, content);
722
+ }
723
+ });
724
+ }
725
+
726
+ // lib/data/flatten-node.ts
727
+ var import_flat = __toESM(require("flat"));
728
+
729
+ // lib/data/strip-slots.ts
730
+ var stripSlots = (data, config) => {
731
+ return mapFields(data, { slot: () => null }, config);
732
+ };
733
+
734
+ // lib/data/flatten-node.ts
735
+ var { flatten: flatten2, unflatten } = import_flat.default;
736
+ var flattenNode = (node, config) => {
737
+ return __spreadProps(__spreadValues({}, node), {
738
+ props: flatten2(stripSlots(node, config).props)
739
+ });
740
+ };
741
+
742
+ // lib/data/walk-app-state.ts
743
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
744
+ var _a;
745
+ let newZones = {};
746
+ const newZoneIndex = {};
747
+ const newNodeIndex = {};
748
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
749
+ var _a2;
750
+ const [parentId] = zoneCompound.split(":");
751
+ const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
752
+ const [_2, zone] = zoneCompound.split(":");
753
+ const newZoneCompound = `${newId || parentId}:${zone}`;
754
+ const newContent2 = mappedContent.map(
755
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
756
+ );
757
+ newZoneIndex[newZoneCompound] = {
758
+ contentIds: newContent2.map((item) => item.props.id),
759
+ type: zoneType
760
+ };
761
+ return [newZoneCompound, newContent2];
762
+ };
763
+ const processRelatedZones = (item, newId, initialPath) => {
764
+ forRelatedZones(
765
+ item,
766
+ state.data,
767
+ (relatedPath, relatedZoneCompound, relatedContent) => {
768
+ const [zoneCompound, newContent2] = processContent(
769
+ relatedPath,
770
+ relatedZoneCompound,
771
+ relatedContent,
772
+ "dropzone",
773
+ newId
774
+ );
775
+ newZones[zoneCompound] = newContent2;
776
+ },
777
+ initialPath
778
+ );
779
+ };
780
+ const processItem = (item, path, index) => {
781
+ const mappedItem = mapNodeOrSkip(item, path, index);
782
+ if (!mappedItem) return item;
783
+ const id = mappedItem.props.id;
784
+ const newProps = __spreadProps(__spreadValues({}, mapFields(
785
+ mappedItem,
786
+ {
787
+ slot: ({ value, parentId: parentId2, propPath }) => {
788
+ const content = value;
789
+ const zoneCompound = `${parentId2}:${propPath}`;
790
+ const [_2, newContent2] = processContent(
791
+ path,
792
+ zoneCompound,
793
+ content,
794
+ "slot",
795
+ parentId2
796
+ );
797
+ return newContent2;
798
+ }
799
+ },
800
+ config
801
+ ).props), {
802
+ id
803
+ });
804
+ processRelatedZones(item, id, path);
805
+ const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
806
+ const thisZoneCompound = path[path.length - 1];
807
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
808
+ newNodeIndex[id] = {
809
+ data: newItem,
810
+ flatData: flattenNode(newItem, config),
811
+ path,
812
+ parentId,
813
+ zone
814
+ };
815
+ const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
816
+ if (newProps.id === "root") {
817
+ delete finalData["type"];
818
+ delete finalData.props["id"];
819
+ }
820
+ return finalData;
821
+ };
822
+ const zones = state.data.zones || {};
823
+ const [_, newContent] = processContent(
824
+ [],
825
+ rootDroppableId,
826
+ state.data.content,
827
+ "root"
828
+ );
829
+ const processedContent = newContent;
830
+ const zonesAlreadyProcessed = Object.keys(newZones);
831
+ Object.keys(zones || {}).forEach((zoneCompound) => {
832
+ const [parentId] = zoneCompound.split(":");
833
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
834
+ return;
835
+ }
836
+ const [_2, newContent2] = processContent(
837
+ [rootDroppableId],
838
+ zoneCompound,
839
+ zones[zoneCompound],
840
+ "dropzone",
841
+ parentId
842
+ );
843
+ newZones[zoneCompound] = newContent2;
844
+ }, newZones);
845
+ const processedRoot = processItem(
846
+ {
847
+ type: "root",
848
+ props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
849
+ },
850
+ [],
851
+ -1
852
+ );
853
+ const root = __spreadProps(__spreadValues({}, state.data.root), {
854
+ props: processedRoot.props
855
+ });
856
+ return __spreadProps(__spreadValues({}, state), {
857
+ data: {
858
+ root,
859
+ content: processedContent,
860
+ zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
861
+ },
862
+ indexes: {
863
+ nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
864
+ zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
865
+ }
866
+ });
867
+ }
868
+
2212
869
  // lib/migrate.ts
2213
- init_react_import();
2214
870
  var migrations = [
2215
871
  // Migrate root to root.props
2216
872
  (data) => {
@@ -2338,12 +994,3 @@ function migrate(data, config, migrationOptions) {
2338
994
  transformProps,
2339
995
  walkTree
2340
996
  });
2341
- /*! Bundled license information:
2342
-
2343
- classnames/index.js:
2344
- (*!
2345
- Copyright (c) 2018 Jed Watson.
2346
- Licensed under the MIT License (MIT), see
2347
- http://jedwatson.github.io/classnames
2348
- *)
2349
- */