@crediblemark/build 0.22.0

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.
Files changed (52) hide show
  1. package/LICENSE +21 -0
  2. package/dist/Editor-XZF6CWVW.css +404 -0
  3. package/dist/Editor-ZC67OU2A.mjs +205 -0
  4. package/dist/Render-JBFI6HYN.mjs +55 -0
  5. package/dist/Render-WCX4AXOX.css +102 -0
  6. package/dist/actions-CEH_5LMY.d.mts +838 -0
  7. package/dist/actions-CEH_5LMY.d.ts +838 -0
  8. package/dist/chunk-3AJBFQU4.mjs +560 -0
  9. package/dist/chunk-4SQOX3ZQ.mjs +476 -0
  10. package/dist/chunk-B4BOBGYB.mjs +42 -0
  11. package/dist/chunk-CDMESQDA.mjs +148 -0
  12. package/dist/chunk-DSXRK4QJ.mjs +704 -0
  13. package/dist/chunk-GUJDGRSM.mjs +469 -0
  14. package/dist/chunk-HHBUU7WF.mjs +35 -0
  15. package/dist/chunk-IJHL7BIR.mjs +11 -0
  16. package/dist/chunk-PHGC6QYB.mjs +105 -0
  17. package/dist/chunk-QF3GD5WQ.mjs +65 -0
  18. package/dist/chunk-U2NVBXAC.mjs +2064 -0
  19. package/dist/chunk-VFD76OD5.mjs +55 -0
  20. package/dist/chunk-VGDMWS44.mjs +107 -0
  21. package/dist/chunk-VKBVSWU3.mjs +8538 -0
  22. package/dist/chunk-YH7AXYKP.mjs +109 -0
  23. package/dist/full-ABQQRJAO.css +301 -0
  24. package/dist/full-LJRK5736.mjs +94 -0
  25. package/dist/index-CkSfgrvw.d.ts +117 -0
  26. package/dist/index-Cxwg4vUV.d.mts +117 -0
  27. package/dist/index.css +2576 -0
  28. package/dist/index.d.mts +310 -0
  29. package/dist/index.d.ts +310 -0
  30. package/dist/index.js +15012 -0
  31. package/dist/index.mjs +83 -0
  32. package/dist/internal.d.mts +27 -0
  33. package/dist/internal.d.ts +27 -0
  34. package/dist/internal.js +960 -0
  35. package/dist/internal.mjs +13 -0
  36. package/dist/loaded-DWCENJKQ.mjs +55 -0
  37. package/dist/loaded-N7VXUR4O.mjs +59 -0
  38. package/dist/loaded-NE2PIHUQ.mjs +56 -0
  39. package/dist/loaded-SMEIWWHS.css +87 -0
  40. package/dist/no-external.css +2574 -0
  41. package/dist/no-external.d.mts +21 -0
  42. package/dist/no-external.d.ts +21 -0
  43. package/dist/no-external.js +15012 -0
  44. package/dist/no-external.mjs +83 -0
  45. package/dist/rsc.css +102 -0
  46. package/dist/rsc.d.mts +27 -0
  47. package/dist/rsc.d.ts +27 -0
  48. package/dist/rsc.js +1466 -0
  49. package/dist/rsc.mjs +147 -0
  50. package/dist/walk-tree-B4ZvMfxS.d.ts +29 -0
  51. package/dist/walk-tree-C78ZVz19.d.mts +29 -0
  52. package/package.json +145 -0
@@ -0,0 +1,960 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // bundle/internal.ts
31
+ var internal_exports = {};
32
+ __export(internal_exports, {
33
+ createReducer: () => createReducer
34
+ });
35
+ module.exports = __toCommonJS(internal_exports);
36
+
37
+ // react-import.js
38
+ var import_react = __toESM(require("react"));
39
+
40
+ // lib/root-droppable-id.ts
41
+ var rootAreaId = "root";
42
+ var rootZone = "default-zone";
43
+ var rootDroppableId = `${rootAreaId}:${rootZone}`;
44
+
45
+ // lib/get-zone-id.ts
46
+ var getZoneId = (zoneCompound) => {
47
+ if (!zoneCompound) {
48
+ return [];
49
+ }
50
+ if (zoneCompound && zoneCompound.indexOf(":") > -1) {
51
+ return zoneCompound.split(":");
52
+ }
53
+ return [rootDroppableId, zoneCompound];
54
+ };
55
+
56
+ // lib/data/for-related-zones.ts
57
+ function forRelatedZones(item, data, cb, path = []) {
58
+ Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
59
+ const [parentId] = getZoneId(zoneCompound);
60
+ if (parentId === item.props.id) {
61
+ cb(path, zoneCompound, content);
62
+ }
63
+ });
64
+ }
65
+
66
+ // lib/data/default-slots.ts
67
+ var defaultSlots = (value, fields) => Object.keys(fields).reduce(
68
+ (acc, fieldName) => fields[fieldName].type === "slot" ? { [fieldName]: [], ...acc } : acc,
69
+ value
70
+ );
71
+
72
+ // lib/data/map-fields.ts
73
+ var isPromise = (v) => !!v && typeof v.then === "function";
74
+ var flatten = (values) => values.reduce((acc, item) => ({ ...acc, ...item }), {});
75
+ var containsPromise = (arr) => arr.some(isPromise);
76
+ var walkField = ({
77
+ value,
78
+ fields,
79
+ mappers,
80
+ propKey = "",
81
+ propPath = "",
82
+ id = "",
83
+ config,
84
+ recurseSlots = false
85
+ }) => {
86
+ const fieldType = fields[propKey]?.type;
87
+ const map = mappers[fieldType];
88
+ if (map && fieldType === "slot") {
89
+ const content = value || [];
90
+ const mappedContent = recurseSlots ? content.map((el) => {
91
+ const componentConfig = config.components[el.type];
92
+ if (!componentConfig) {
93
+ throw new Error(`Could not find component config for ${el.type}`);
94
+ }
95
+ const fields2 = componentConfig.fields ?? {};
96
+ return walkField({
97
+ value: { ...el, props: defaultSlots(el.props, fields2) },
98
+ fields: fields2,
99
+ mappers,
100
+ id: el.props.id,
101
+ config,
102
+ recurseSlots
103
+ });
104
+ }) : content;
105
+ if (containsPromise(mappedContent)) {
106
+ return Promise.all(mappedContent);
107
+ }
108
+ return map({
109
+ value: mappedContent,
110
+ parentId: id,
111
+ propName: propPath,
112
+ field: fields[propKey],
113
+ propPath
114
+ });
115
+ } else if (map && fields[propKey]) {
116
+ return map({
117
+ value,
118
+ parentId: id,
119
+ propName: propKey,
120
+ field: fields[propKey],
121
+ propPath
122
+ });
123
+ }
124
+ if (value && typeof value === "object") {
125
+ if (Array.isArray(value)) {
126
+ const arrayFields = fields[propKey]?.type === "array" ? fields[propKey].arrayFields : null;
127
+ if (!arrayFields) return value;
128
+ const newValue = value.map(
129
+ (el, idx) => walkField({
130
+ value: el,
131
+ fields: arrayFields,
132
+ mappers,
133
+ propKey,
134
+ propPath: `${propPath}[${idx}]`,
135
+ id,
136
+ config,
137
+ recurseSlots
138
+ })
139
+ );
140
+ if (containsPromise(newValue)) {
141
+ return Promise.all(newValue);
142
+ }
143
+ return newValue;
144
+ } else if ("$$typeof" in value) {
145
+ return value;
146
+ } else {
147
+ const objectFields = fields[propKey]?.type === "object" ? fields[propKey].objectFields : fields;
148
+ return walkObject({
149
+ value,
150
+ fields: objectFields,
151
+ mappers,
152
+ id,
153
+ getPropPath: (k) => `${propPath}.${k}`,
154
+ config,
155
+ recurseSlots
156
+ });
157
+ }
158
+ }
159
+ return value;
160
+ };
161
+ var walkObject = ({
162
+ value,
163
+ fields,
164
+ mappers,
165
+ id,
166
+ getPropPath,
167
+ config,
168
+ recurseSlots
169
+ }) => {
170
+ const newProps = Object.entries(value).map(([k, v]) => {
171
+ const opts = {
172
+ value: v,
173
+ fields,
174
+ mappers,
175
+ propKey: k,
176
+ propPath: getPropPath(k),
177
+ id,
178
+ config,
179
+ recurseSlots
180
+ };
181
+ const newValue = walkField(opts);
182
+ if (isPromise(newValue)) {
183
+ return newValue.then((resolvedValue) => ({
184
+ [k]: resolvedValue
185
+ }));
186
+ }
187
+ return {
188
+ [k]: newValue
189
+ };
190
+ }, {});
191
+ if (containsPromise(newProps)) {
192
+ return Promise.all(newProps).then(flatten);
193
+ }
194
+ return flatten(newProps);
195
+ };
196
+ function mapFields(item, mappers, config, recurseSlots = false, shouldDefaultSlots = true) {
197
+ const itemType = "type" in item ? item.type : "root";
198
+ const componentConfig = itemType === "root" ? config.root : config.components?.[itemType];
199
+ const newProps = walkObject({
200
+ value: shouldDefaultSlots ? defaultSlots(item.props ?? {}, componentConfig?.fields ?? {}) : item.props,
201
+ fields: componentConfig?.fields ?? {},
202
+ mappers,
203
+ id: item.props ? item.props.id ?? "root" : "root",
204
+ getPropPath: (k) => k,
205
+ config,
206
+ recurseSlots
207
+ });
208
+ if (isPromise(newProps)) {
209
+ return newProps.then((resolvedProps) => ({
210
+ ...item,
211
+ props: resolvedProps
212
+ }));
213
+ }
214
+ return {
215
+ ...item,
216
+ props: newProps
217
+ };
218
+ }
219
+
220
+ // lib/data/flatten-node.ts
221
+ var import_flat = __toESM(require("flat"));
222
+
223
+ // lib/data/strip-slots.ts
224
+ var stripSlots = (data, config) => {
225
+ return mapFields(data, { slot: () => null }, config);
226
+ };
227
+
228
+ // lib/data/flatten-node.ts
229
+ var { flatten: flatten2, unflatten } = import_flat.default;
230
+ var isPureObject = (val) => val != null && Object.prototype.toString.call(val) === "[object Object]";
231
+ var emptyArrayStr = "__credbuild_[]";
232
+ var emptyObjectStr = "__credbuild_{}";
233
+ function encodeEmptyObjects(props = {}) {
234
+ const result = {};
235
+ for (const key in props) {
236
+ if (!Object.prototype.hasOwnProperty.call(props, key)) continue;
237
+ const val = props[key];
238
+ if (Array.isArray(val) && val.length === 0) {
239
+ result[key] = emptyArrayStr;
240
+ } else if (isPureObject(val) && Object.keys(val).length === 0) {
241
+ result[key] = emptyObjectStr;
242
+ } else {
243
+ result[key] = val;
244
+ }
245
+ }
246
+ return result;
247
+ }
248
+ var flattenNode = (node, config) => {
249
+ return {
250
+ ...node,
251
+ props: encodeEmptyObjects(flatten2(stripSlots(node, config).props))
252
+ };
253
+ };
254
+
255
+ // lib/data/to-component.ts
256
+ var toComponent = (item) => {
257
+ return "type" in item ? item : {
258
+ ...item,
259
+ props: { ...item.props, id: "root" },
260
+ type: "root"
261
+ };
262
+ };
263
+
264
+ // lib/data/walk-app-state.ts
265
+ function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
266
+ let newZones = {};
267
+ const newZoneIndex = {};
268
+ const newNodeIndex = {};
269
+ const processContent = (path, zoneCompound, content, zoneType, newId) => {
270
+ const [parentId] = zoneCompound.split(":");
271
+ const mappedContent = (mapContent(content, zoneCompound, zoneType) ?? content) || [];
272
+ const [_2, zone] = zoneCompound.split(":");
273
+ const newZoneCompound = `${newId || parentId}:${zone}`;
274
+ const newContent2 = mappedContent.map(
275
+ (zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
276
+ );
277
+ newZoneIndex[newZoneCompound] = {
278
+ contentIds: newContent2.map((item) => item.props.id),
279
+ type: zoneType
280
+ };
281
+ return [newZoneCompound, newContent2];
282
+ };
283
+ const processRelatedZones = (item, newId, initialPath) => {
284
+ forRelatedZones(
285
+ item,
286
+ state.data,
287
+ (relatedPath, relatedZoneCompound, relatedContent) => {
288
+ const [zoneCompound, newContent2] = processContent(
289
+ relatedPath,
290
+ relatedZoneCompound,
291
+ relatedContent,
292
+ "dropzone",
293
+ newId
294
+ );
295
+ newZones[zoneCompound] = newContent2;
296
+ },
297
+ initialPath
298
+ );
299
+ };
300
+ const processItem = (item, path, index) => {
301
+ const mappedItem = mapNodeOrSkip(item, path, index);
302
+ if (!mappedItem) return item;
303
+ const id = mappedItem.props.id;
304
+ const newProps = {
305
+ ...mapFields(
306
+ mappedItem,
307
+ {
308
+ slot: ({ value, parentId: parentId2, propPath }) => {
309
+ const content = value;
310
+ const zoneCompound = `${parentId2}:${propPath}`;
311
+ const [_2, newContent2] = processContent(
312
+ path,
313
+ zoneCompound,
314
+ content,
315
+ "slot",
316
+ parentId2
317
+ );
318
+ return newContent2;
319
+ }
320
+ },
321
+ config
322
+ ).props,
323
+ id
324
+ };
325
+ processRelatedZones(item, id, path);
326
+ const newItem = { ...mappedItem, props: newProps };
327
+ const thisZoneCompound = path[path.length - 1];
328
+ const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
329
+ newNodeIndex[id] = {
330
+ data: newItem,
331
+ flatData: flattenNode(newItem, config),
332
+ path,
333
+ parentId,
334
+ zone
335
+ };
336
+ const finalData = { ...newItem, props: { ...newItem.props } };
337
+ if (newProps.id === "root") {
338
+ delete finalData["type"];
339
+ delete finalData.props["id"];
340
+ }
341
+ return finalData;
342
+ };
343
+ const zones = state.data.zones || {};
344
+ const [_, newContent] = processContent(
345
+ [],
346
+ rootDroppableId,
347
+ state.data.content,
348
+ "root"
349
+ );
350
+ const processedContent = newContent;
351
+ const zonesAlreadyProcessed = Object.keys(newZones);
352
+ Object.keys(zones || {}).forEach((zoneCompound) => {
353
+ const [parentId] = zoneCompound.split(":");
354
+ if (zonesAlreadyProcessed.includes(zoneCompound)) {
355
+ return;
356
+ }
357
+ const [_2, newContent2] = processContent(
358
+ [rootDroppableId],
359
+ zoneCompound,
360
+ zones[zoneCompound],
361
+ "dropzone",
362
+ parentId
363
+ );
364
+ newZones[zoneCompound] = newContent2;
365
+ }, newZones);
366
+ let rootAsComponent = toComponent({
367
+ props: { ...state.data.root.props ?? state.data.root }
368
+ });
369
+ if (state.data.root.readOnly) {
370
+ rootAsComponent.readOnly = state.data.root.readOnly;
371
+ }
372
+ const processedRoot = processItem(rootAsComponent, [], -1);
373
+ const root = {
374
+ ...state.data.root,
375
+ ...processedRoot
376
+ };
377
+ return {
378
+ ...state,
379
+ data: {
380
+ root,
381
+ content: processedContent,
382
+ zones: {
383
+ ...state.data.zones,
384
+ ...newZones
385
+ }
386
+ },
387
+ indexes: {
388
+ nodes: { ...state.indexes.nodes, ...newNodeIndex },
389
+ zones: { ...state.indexes.zones, ...newZoneIndex }
390
+ }
391
+ };
392
+ }
393
+
394
+ // reducer/actions/set.ts
395
+ var setAction = (state, action, appStore) => {
396
+ if (typeof action.state === "object") {
397
+ const newState = {
398
+ ...state,
399
+ ...action.state
400
+ };
401
+ if (action.state.indexes) {
402
+ return newState;
403
+ }
404
+ console.warn(
405
+ "`set` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
406
+ );
407
+ return walkAppState(newState, appStore.config);
408
+ }
409
+ return { ...state, ...action.state(state) };
410
+ };
411
+
412
+ // lib/data/insert.ts
413
+ var insert = (list, index, item) => {
414
+ const result = Array.from(list || []);
415
+ result.splice(index, 0, item);
416
+ return result;
417
+ };
418
+
419
+ // lib/generate-id.ts
420
+ var import_uuid = require("uuid");
421
+ var generateId = (type) => type ? `${type}-${(0, import_uuid.v4)()}` : (0, import_uuid.v4)();
422
+
423
+ // lib/data/get-ids-for-parent.ts
424
+ var getIdsForParent = (zoneCompound, state) => {
425
+ const [parentId] = zoneCompound.split(":");
426
+ const node = state.indexes.nodes[parentId];
427
+ return (node?.path || []).map((p) => p.split(":")[0]);
428
+ };
429
+
430
+ // lib/data/walk-tree.ts
431
+ function walkTree(data, config, callbackFn) {
432
+ const walkItem = (item) => {
433
+ return mapFields(
434
+ item,
435
+ {
436
+ slot: ({ value, parentId, propName }) => {
437
+ const content = value;
438
+ return callbackFn(content, { parentId, propName }) ?? content;
439
+ }
440
+ },
441
+ config,
442
+ true
443
+ );
444
+ };
445
+ if ("props" in data) {
446
+ return walkItem(data);
447
+ }
448
+ const _data = data;
449
+ const zones = _data.zones ?? {};
450
+ const mappedContent = _data.content.map(walkItem);
451
+ return {
452
+ root: walkItem(_data.root),
453
+ content: callbackFn(mappedContent, {
454
+ parentId: "root",
455
+ propName: "default-zone"
456
+ }) ?? mappedContent,
457
+ zones: Object.keys(zones).reduce(
458
+ (acc, zoneCompound) => ({
459
+ ...acc,
460
+ [zoneCompound]: zones[zoneCompound].map(walkItem)
461
+ }),
462
+ {}
463
+ )
464
+ };
465
+ }
466
+
467
+ // lib/data/populate-ids.ts
468
+ var populateIds = (data, config, override = false) => {
469
+ const id = generateId(data.type);
470
+ return walkTree(
471
+ {
472
+ ...data,
473
+ props: override ? { ...data.props, id } : { ...data.props }
474
+ },
475
+ config,
476
+ (contents) => contents.map((item) => {
477
+ const id2 = generateId(item.type);
478
+ return {
479
+ ...item,
480
+ props: override ? { ...item.props, id: id2 } : { id: id2, ...item.props }
481
+ };
482
+ })
483
+ );
484
+ };
485
+
486
+ // reducer/actions/insert.ts
487
+ function insertAction(state, action, appStore) {
488
+ const id = action.id || generateId(action.componentType);
489
+ const emptyComponentData = populateIds(
490
+ {
491
+ type: action.componentType,
492
+ props: {
493
+ ...appStore.config.components[action.componentType].defaultProps || {},
494
+ id
495
+ }
496
+ },
497
+ appStore.config
498
+ );
499
+ const [parentId] = action.destinationZone.split(":");
500
+ const idsInPath = getIdsForParent(action.destinationZone, state);
501
+ return walkAppState(
502
+ state,
503
+ appStore.config,
504
+ (content, zoneCompound) => {
505
+ if (zoneCompound === action.destinationZone) {
506
+ return insert(
507
+ content || [],
508
+ action.destinationIndex,
509
+ emptyComponentData
510
+ );
511
+ }
512
+ return content;
513
+ },
514
+ (childItem, path) => {
515
+ if (childItem.props.id === id || childItem.props.id === parentId) {
516
+ return childItem;
517
+ } else if (idsInPath.includes(childItem.props.id)) {
518
+ return childItem;
519
+ } else if (path.includes(action.destinationZone)) {
520
+ return childItem;
521
+ }
522
+ return null;
523
+ }
524
+ );
525
+ }
526
+
527
+ // reducer/actions/replace.ts
528
+ var replaceAction = (state, action, appStore) => {
529
+ const [parentId] = action.destinationZone.split(":");
530
+ const idsInPath = getIdsForParent(action.destinationZone, state);
531
+ const originalId = state.indexes.zones[action.destinationZone].contentIds[action.destinationIndex];
532
+ const idChanged = originalId !== action.data.props.id;
533
+ if (idChanged) {
534
+ throw new Error(
535
+ `Can't change the id during a replace action. Please us "remove" and "insert" to define a new node.`
536
+ );
537
+ }
538
+ const newSlotIds = [];
539
+ const data = walkTree(action.data, appStore.config, (contents, opts) => {
540
+ newSlotIds.push(`${opts.parentId}:${opts.propName}`);
541
+ return contents.map((item) => {
542
+ const id = generateId(item.type);
543
+ return {
544
+ ...item,
545
+ props: { id, ...item.props }
546
+ };
547
+ });
548
+ });
549
+ const stateWithDeepSlotsRemoved = {
550
+ ...state,
551
+ ui: { ...state.ui, ...action.ui }
552
+ };
553
+ Object.keys(state.indexes.zones).forEach((zoneCompound) => {
554
+ const id = zoneCompound.split(":")[0];
555
+ if (id === originalId) {
556
+ if (!newSlotIds.includes(zoneCompound)) {
557
+ delete stateWithDeepSlotsRemoved.indexes.zones[zoneCompound];
558
+ }
559
+ }
560
+ });
561
+ return walkAppState(
562
+ stateWithDeepSlotsRemoved,
563
+ appStore.config,
564
+ (content, zoneCompound) => {
565
+ const newContent = [...content];
566
+ if (zoneCompound === action.destinationZone) {
567
+ newContent[action.destinationIndex] = data;
568
+ }
569
+ return newContent;
570
+ },
571
+ (childItem, path) => {
572
+ const pathIds = path.map((p) => p.split(":")[0]);
573
+ if (childItem.props.id === data.props.id) {
574
+ return data;
575
+ } else if (childItem.props.id === parentId) {
576
+ return childItem;
577
+ } else if (idsInPath.indexOf(childItem.props.id) > -1) {
578
+ return childItem;
579
+ } else if (pathIds.indexOf(data.props.id) > -1) {
580
+ return childItem;
581
+ }
582
+ return null;
583
+ }
584
+ );
585
+ };
586
+
587
+ // reducer/actions/replace-root.ts
588
+ var replaceRootAction = (state, action, appStore) => {
589
+ return walkAppState(
590
+ state,
591
+ appStore.config,
592
+ (content) => content,
593
+ (childItem) => {
594
+ if (childItem.props.id === "root") {
595
+ return {
596
+ ...childItem,
597
+ props: { ...childItem.props, ...action.root.props },
598
+ readOnly: action.root.readOnly
599
+ };
600
+ }
601
+ return childItem;
602
+ }
603
+ );
604
+ };
605
+
606
+ // lib/data/get-item.ts
607
+ function getItem(selector, state) {
608
+ const zone = state.indexes.zones?.[selector.zone || rootDroppableId];
609
+ return zone ? state.indexes.nodes[zone.contentIds[selector.index]]?.data : void 0;
610
+ }
611
+
612
+ // reducer/actions/duplicate.ts
613
+ function duplicateAction(state, action, appStore) {
614
+ const item = getItem(
615
+ { index: action.sourceIndex, zone: action.sourceZone },
616
+ state
617
+ );
618
+ const idsInPath = getIdsForParent(action.sourceZone, state);
619
+ const newItem = {
620
+ ...item,
621
+ props: {
622
+ ...item.props,
623
+ id: generateId(item.type)
624
+ }
625
+ };
626
+ const modified = walkAppState(
627
+ state,
628
+ appStore.config,
629
+ (content, zoneCompound) => {
630
+ if (zoneCompound === action.sourceZone) {
631
+ return insert(content, action.sourceIndex + 1, item);
632
+ }
633
+ return content;
634
+ },
635
+ (childItem, path, index) => {
636
+ const zoneCompound = path[path.length - 1];
637
+ const parents = path.map((p) => p.split(":")[0]);
638
+ if (parents.indexOf(newItem.props.id) > -1) {
639
+ return {
640
+ ...childItem,
641
+ props: {
642
+ ...childItem.props,
643
+ id: generateId(childItem.type)
644
+ }
645
+ };
646
+ }
647
+ if (zoneCompound === action.sourceZone && index === action.sourceIndex + 1) {
648
+ return newItem;
649
+ }
650
+ const [sourceZoneParent] = action.sourceZone.split(":");
651
+ if (sourceZoneParent === childItem.props.id || idsInPath.indexOf(childItem.props.id) > -1) {
652
+ return childItem;
653
+ }
654
+ return null;
655
+ }
656
+ );
657
+ return {
658
+ ...modified,
659
+ ui: {
660
+ ...modified.ui,
661
+ itemSelector: {
662
+ index: action.sourceIndex + 1,
663
+ zone: action.sourceZone
664
+ }
665
+ }
666
+ };
667
+ }
668
+
669
+ // lib/data/remove.ts
670
+ var remove = (list, index) => {
671
+ const result = Array.from(list);
672
+ result.splice(index, 1);
673
+ return result;
674
+ };
675
+
676
+ // reducer/actions/move.ts
677
+ var moveAction = (state, action, appStore) => {
678
+ if (action.sourceZone === action.destinationZone && action.sourceIndex === action.destinationIndex) {
679
+ return state;
680
+ }
681
+ const item = getItem(
682
+ { zone: action.sourceZone, index: action.sourceIndex },
683
+ state
684
+ );
685
+ if (!item) return state;
686
+ const idsInSourcePath = getIdsForParent(action.sourceZone, state);
687
+ const idsInDestinationPath = getIdsForParent(action.destinationZone, state);
688
+ return walkAppState(
689
+ state,
690
+ appStore.config,
691
+ (content, zoneCompound) => {
692
+ if (zoneCompound === action.sourceZone && zoneCompound === action.destinationZone) {
693
+ return insert(
694
+ remove(content, action.sourceIndex),
695
+ action.destinationIndex,
696
+ item
697
+ );
698
+ } else if (zoneCompound === action.sourceZone) {
699
+ return remove(content, action.sourceIndex);
700
+ } else if (zoneCompound === action.destinationZone) {
701
+ return insert(content, action.destinationIndex, item);
702
+ }
703
+ return content;
704
+ },
705
+ (childItem, path) => {
706
+ const [sourceZoneParent] = action.sourceZone.split(":");
707
+ const [destinationZoneParent] = action.destinationZone.split(":");
708
+ const childId = childItem.props.id;
709
+ if (sourceZoneParent === childId || destinationZoneParent === childId || item.props.id === childId || idsInSourcePath.indexOf(childId) > -1 || idsInDestinationPath.indexOf(childId) > -1 || path.includes(action.destinationZone)) {
710
+ return childItem;
711
+ }
712
+ return null;
713
+ }
714
+ );
715
+ };
716
+
717
+ // reducer/actions/reorder.ts
718
+ var reorderAction = (state, action, appStore) => {
719
+ return moveAction(
720
+ state,
721
+ {
722
+ type: "move",
723
+ sourceIndex: action.sourceIndex,
724
+ sourceZone: action.destinationZone,
725
+ destinationIndex: action.destinationIndex,
726
+ destinationZone: action.destinationZone
727
+ },
728
+ appStore
729
+ );
730
+ };
731
+
732
+ // reducer/actions/remove.ts
733
+ var removeAction = (state, action, appStore) => {
734
+ const item = getItem({ index: action.index, zone: action.zone }, state);
735
+ const nodesToDelete = Object.entries(state.indexes.nodes).reduce(
736
+ (acc, [nodeId, nodeData]) => {
737
+ const pathIds = nodeData.path.map((p) => p.split(":")[0]);
738
+ if (pathIds.includes(item.props.id)) {
739
+ return [...acc, nodeId];
740
+ }
741
+ return acc;
742
+ },
743
+ [item.props.id]
744
+ );
745
+ const newState = walkAppState(
746
+ state,
747
+ appStore.config,
748
+ (content, zoneCompound) => {
749
+ if (zoneCompound === action.zone) {
750
+ return remove(content, action.index);
751
+ }
752
+ return content;
753
+ }
754
+ );
755
+ Object.keys(newState.data.zones || {}).forEach((zoneCompound) => {
756
+ const parentId = zoneCompound.split(":")[0];
757
+ if (nodesToDelete.includes(parentId) && newState.data.zones) {
758
+ delete newState.data.zones[zoneCompound];
759
+ }
760
+ });
761
+ Object.keys(newState.indexes.zones).forEach((zoneCompound) => {
762
+ const parentId = zoneCompound.split(":")[0];
763
+ if (nodesToDelete.includes(parentId)) {
764
+ delete newState.indexes.zones[zoneCompound];
765
+ }
766
+ });
767
+ nodesToDelete.forEach((id) => {
768
+ delete newState.indexes.nodes[id];
769
+ });
770
+ return newState;
771
+ };
772
+
773
+ // lib/data/setup-zone.ts
774
+ var setupZone = (data, zoneKey) => {
775
+ if (zoneKey === rootDroppableId) {
776
+ return data;
777
+ }
778
+ const newData = {
779
+ ...data,
780
+ zones: data.zones ? { ...data.zones } : {}
781
+ };
782
+ newData.zones[zoneKey] = newData.zones[zoneKey] || [];
783
+ return newData;
784
+ };
785
+
786
+ // reducer/actions/register-zone.ts
787
+ var zoneCache = {};
788
+ function registerZoneAction(state, action) {
789
+ if (zoneCache[action.zone]) {
790
+ return {
791
+ ...state,
792
+ data: {
793
+ ...state.data,
794
+ zones: {
795
+ ...state.data.zones,
796
+ [action.zone]: zoneCache[action.zone]
797
+ }
798
+ },
799
+ indexes: {
800
+ ...state.indexes,
801
+ zones: {
802
+ ...state.indexes.zones,
803
+ [action.zone]: {
804
+ ...state.indexes.zones[action.zone],
805
+ contentIds: zoneCache[action.zone].map((item) => item.props.id),
806
+ type: "dropzone"
807
+ }
808
+ }
809
+ }
810
+ };
811
+ }
812
+ return { ...state, data: setupZone(state.data, action.zone) };
813
+ }
814
+ function unregisterZoneAction(state, action) {
815
+ const _zones = { ...state.data.zones || {} };
816
+ const zoneIndex = { ...state.indexes.zones || {} };
817
+ if (_zones[action.zone]) {
818
+ zoneCache[action.zone] = _zones[action.zone];
819
+ delete _zones[action.zone];
820
+ }
821
+ delete zoneIndex[action.zone];
822
+ return {
823
+ ...state,
824
+ data: {
825
+ ...state.data,
826
+ zones: _zones
827
+ },
828
+ indexes: {
829
+ ...state.indexes,
830
+ zones: zoneIndex
831
+ }
832
+ };
833
+ }
834
+
835
+ // reducer/actions/set-data.ts
836
+ var setDataAction = (state, action, appStore) => {
837
+ if (typeof action.data === "object") {
838
+ console.warn(
839
+ "`setData` is expensive and may cause unnecessary re-renders. Consider using a more atomic action instead."
840
+ );
841
+ return walkAppState(
842
+ {
843
+ ...state,
844
+ data: {
845
+ ...state.data,
846
+ ...action.data
847
+ }
848
+ },
849
+ appStore.config
850
+ );
851
+ }
852
+ return walkAppState(
853
+ {
854
+ ...state,
855
+ data: {
856
+ ...state.data,
857
+ ...action.data(state.data)
858
+ }
859
+ },
860
+ appStore.config
861
+ );
862
+ };
863
+
864
+ // reducer/actions/set-ui.ts
865
+ var setUiAction = (state, action) => {
866
+ if (typeof action.ui === "object") {
867
+ return {
868
+ ...state,
869
+ ui: {
870
+ ...state.ui,
871
+ ...action.ui
872
+ }
873
+ };
874
+ }
875
+ return {
876
+ ...state,
877
+ ui: {
878
+ ...state.ui,
879
+ ...action.ui(state.ui)
880
+ }
881
+ };
882
+ };
883
+
884
+ // lib/data/make-state-public.ts
885
+ var makeStatePublic = (state) => {
886
+ const { data, ui } = state;
887
+ return { data, ui };
888
+ };
889
+
890
+ // reducer/index.ts
891
+ function storeInterceptor(reducer, record, onAction) {
892
+ return (state, action) => {
893
+ const newAppState = reducer(state, action);
894
+ const isValidType = ![
895
+ "registerZone",
896
+ "unregisterZone",
897
+ "setData",
898
+ "setUi",
899
+ "set"
900
+ ].includes(action.type);
901
+ if (typeof action.recordHistory !== "undefined" ? action.recordHistory : isValidType) {
902
+ if (record) record(newAppState);
903
+ }
904
+ onAction?.(action, makeStatePublic(newAppState), makeStatePublic(state));
905
+ return newAppState;
906
+ };
907
+ }
908
+ function createReducer({
909
+ record,
910
+ onAction,
911
+ appStore
912
+ }) {
913
+ return storeInterceptor(
914
+ (state, action) => {
915
+ if (action.type === "set") {
916
+ return setAction(state, action, appStore);
917
+ }
918
+ if (action.type === "insert") {
919
+ return insertAction(state, action, appStore);
920
+ }
921
+ if (action.type === "replace") {
922
+ return replaceAction(state, action, appStore);
923
+ }
924
+ if (action.type === "replaceRoot") {
925
+ return replaceRootAction(state, action, appStore);
926
+ }
927
+ if (action.type === "duplicate") {
928
+ return duplicateAction(state, action, appStore);
929
+ }
930
+ if (action.type === "reorder") {
931
+ return reorderAction(state, action, appStore);
932
+ }
933
+ if (action.type === "move") {
934
+ return moveAction(state, action, appStore);
935
+ }
936
+ if (action.type === "remove") {
937
+ return removeAction(state, action, appStore);
938
+ }
939
+ if (action.type === "registerZone") {
940
+ return registerZoneAction(state, action);
941
+ }
942
+ if (action.type === "unregisterZone") {
943
+ return unregisterZoneAction(state, action);
944
+ }
945
+ if (action.type === "setData") {
946
+ return setDataAction(state, action, appStore);
947
+ }
948
+ if (action.type === "setUi") {
949
+ return setUiAction(state, action);
950
+ }
951
+ return state;
952
+ },
953
+ record,
954
+ onAction
955
+ );
956
+ }
957
+ // Annotate the CommonJS export names for ESM import in node:
958
+ 0 && (module.exports = {
959
+ createReducer
960
+ });