@measured/puck 0.19.0-canary.226c08da → 0.19.0-canary.22f5e3a3
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/{chunk-44RES7IE.mjs → chunk-DDGE2CCN.mjs} +329 -20
- package/dist/index.d.mts +9 -5
- package/dist/index.d.ts +9 -5
- package/dist/index.js +62 -24
- package/dist/index.mjs +48 -314
- package/dist/rsc.d.mts +2 -2
- package/dist/rsc.d.ts +2 -2
- package/dist/rsc.js +326 -33
- package/dist/rsc.mjs +3 -1
- package/dist/{walk-tree-CM-cu7GU.d.mts → walk-tree-DOB5QZVq.d.mts} +9 -7
- package/dist/{walk-tree-CM-cu7GU.d.ts → walk-tree-DOB5QZVq.d.ts} +9 -7
- package/package.json +1 -1
@@ -356,6 +356,316 @@ function Render({
|
|
356
356
|
);
|
357
357
|
}
|
358
358
|
|
359
|
+
// lib/migrate.ts
|
360
|
+
init_react_import();
|
361
|
+
|
362
|
+
// store/default-app-state.ts
|
363
|
+
init_react_import();
|
364
|
+
|
365
|
+
// components/ViewportControls/default-viewports.ts
|
366
|
+
init_react_import();
|
367
|
+
var defaultViewports = [
|
368
|
+
{ width: 360, height: "auto", icon: "Smartphone", label: "Small" },
|
369
|
+
{ width: 768, height: "auto", icon: "Tablet", label: "Medium" },
|
370
|
+
{ width: 1280, height: "auto", icon: "Monitor", label: "Large" }
|
371
|
+
];
|
372
|
+
|
373
|
+
// store/default-app-state.ts
|
374
|
+
var defaultAppState = {
|
375
|
+
data: { content: [], root: {}, zones: {} },
|
376
|
+
ui: {
|
377
|
+
leftSideBarVisible: true,
|
378
|
+
rightSideBarVisible: true,
|
379
|
+
arrayState: {},
|
380
|
+
itemSelector: null,
|
381
|
+
componentList: {},
|
382
|
+
isDragging: false,
|
383
|
+
previewMode: "edit",
|
384
|
+
viewports: {
|
385
|
+
current: {
|
386
|
+
width: defaultViewports[0].width,
|
387
|
+
height: defaultViewports[0].height || "auto"
|
388
|
+
},
|
389
|
+
options: [],
|
390
|
+
controlsVisible: true
|
391
|
+
},
|
392
|
+
field: { focus: null }
|
393
|
+
},
|
394
|
+
indexes: {
|
395
|
+
nodes: {},
|
396
|
+
zones: {}
|
397
|
+
}
|
398
|
+
};
|
399
|
+
|
400
|
+
// lib/data/walk-app-state.ts
|
401
|
+
init_react_import();
|
402
|
+
|
403
|
+
// lib/data/for-each-slot.ts
|
404
|
+
init_react_import();
|
405
|
+
var forEachSlot = (item, cb, recursive = false, isSlot2 = isSlot) => {
|
406
|
+
const props = item.props || {};
|
407
|
+
const propKeys = Object.keys(props);
|
408
|
+
for (let i = 0; i < propKeys.length; i++) {
|
409
|
+
const propKey = propKeys[i];
|
410
|
+
const itemType = "type" in item ? item.type : "root";
|
411
|
+
if (isSlot2(itemType, propKey, props[propKey])) {
|
412
|
+
const content = props[propKey];
|
413
|
+
cb(props.id, propKey, content);
|
414
|
+
if (recursive) {
|
415
|
+
content.forEach(
|
416
|
+
(childItem) => __async(void 0, null, function* () {
|
417
|
+
return forEachSlot(childItem, cb, true, isSlot2);
|
418
|
+
})
|
419
|
+
);
|
420
|
+
}
|
421
|
+
}
|
422
|
+
}
|
423
|
+
};
|
424
|
+
|
425
|
+
// lib/data/for-related-zones.ts
|
426
|
+
init_react_import();
|
427
|
+
|
428
|
+
// lib/get-zone-id.ts
|
429
|
+
init_react_import();
|
430
|
+
var getZoneId = (zoneCompound) => {
|
431
|
+
if (!zoneCompound) {
|
432
|
+
return [];
|
433
|
+
}
|
434
|
+
if (zoneCompound && zoneCompound.indexOf(":") > -1) {
|
435
|
+
return zoneCompound.split(":");
|
436
|
+
}
|
437
|
+
return [rootDroppableId, zoneCompound];
|
438
|
+
};
|
439
|
+
|
440
|
+
// lib/data/for-related-zones.ts
|
441
|
+
function forRelatedZones(item, data, cb, path = []) {
|
442
|
+
Object.entries(data.zones || {}).forEach(([zoneCompound, content]) => {
|
443
|
+
const [parentId] = getZoneId(zoneCompound);
|
444
|
+
if (parentId === item.props.id) {
|
445
|
+
cb(path, zoneCompound, content);
|
446
|
+
}
|
447
|
+
});
|
448
|
+
}
|
449
|
+
|
450
|
+
// lib/data/strip-slots.ts
|
451
|
+
init_react_import();
|
452
|
+
var stripSlots = (data) => {
|
453
|
+
return __spreadProps(__spreadValues({}, data), {
|
454
|
+
props: Object.entries(data.props).reduce(
|
455
|
+
(acc, [propKey, propVal]) => {
|
456
|
+
if (isSlot(propVal)) {
|
457
|
+
return acc;
|
458
|
+
}
|
459
|
+
return __spreadProps(__spreadValues({}, acc), { [propKey]: propVal });
|
460
|
+
},
|
461
|
+
{ id: data.props.id }
|
462
|
+
)
|
463
|
+
});
|
464
|
+
};
|
465
|
+
|
466
|
+
// lib/data/walk-app-state.ts
|
467
|
+
function walkAppState(state, config, mapContent = (content) => content, mapNodeOrSkip = (item) => item) {
|
468
|
+
var _a;
|
469
|
+
let newZones = {};
|
470
|
+
const newZoneIndex = {};
|
471
|
+
const newNodeIndex = {};
|
472
|
+
const processContent = (path, zoneCompound, content, zoneType, newId) => {
|
473
|
+
var _a2;
|
474
|
+
const [parentId] = zoneCompound.split(":");
|
475
|
+
const mappedContent = ((_a2 = mapContent(content, zoneCompound, zoneType)) != null ? _a2 : content) || [];
|
476
|
+
const [_2, zone] = zoneCompound.split(":");
|
477
|
+
const newZoneCompound = `${newId || parentId}:${zone}`;
|
478
|
+
const newContent2 = mappedContent.map(
|
479
|
+
(zoneChild, index) => processItem(zoneChild, [...path, newZoneCompound], index)
|
480
|
+
);
|
481
|
+
newZoneIndex[newZoneCompound] = {
|
482
|
+
contentIds: newContent2.map((item) => item.props.id),
|
483
|
+
type: zoneType
|
484
|
+
};
|
485
|
+
return [newZoneCompound, newContent2];
|
486
|
+
};
|
487
|
+
const processRelatedZones = (item, newId, initialPath) => {
|
488
|
+
forRelatedZones(
|
489
|
+
item,
|
490
|
+
state.data,
|
491
|
+
(relatedPath, relatedZoneCompound, relatedContent) => {
|
492
|
+
const [zoneCompound, newContent2] = processContent(
|
493
|
+
relatedPath,
|
494
|
+
relatedZoneCompound,
|
495
|
+
relatedContent,
|
496
|
+
"dropzone",
|
497
|
+
newId
|
498
|
+
);
|
499
|
+
newZones[zoneCompound] = newContent2;
|
500
|
+
},
|
501
|
+
initialPath
|
502
|
+
);
|
503
|
+
};
|
504
|
+
const processItem = (item, path, index) => {
|
505
|
+
const mappedItem = mapNodeOrSkip(item, path, index);
|
506
|
+
if (!mappedItem) return item;
|
507
|
+
const id = mappedItem.props.id;
|
508
|
+
const newProps = __spreadValues({}, mappedItem.props);
|
509
|
+
forEachSlot(
|
510
|
+
mappedItem,
|
511
|
+
(parentId2, slotId, content) => {
|
512
|
+
const zoneCompound = `${parentId2}:${slotId}`;
|
513
|
+
const [_2, newContent2] = processContent(
|
514
|
+
path,
|
515
|
+
zoneCompound,
|
516
|
+
content,
|
517
|
+
"slot",
|
518
|
+
parentId2
|
519
|
+
);
|
520
|
+
newProps[slotId] = newContent2;
|
521
|
+
},
|
522
|
+
false,
|
523
|
+
createIsSlotConfig(config)
|
524
|
+
);
|
525
|
+
processRelatedZones(item, id, path);
|
526
|
+
const newItem = __spreadProps(__spreadValues({}, item), { props: newProps });
|
527
|
+
const thisZoneCompound = path[path.length - 1];
|
528
|
+
const [parentId, zone] = thisZoneCompound ? thisZoneCompound.split(":") : [null, ""];
|
529
|
+
newNodeIndex[id] = {
|
530
|
+
data: newItem,
|
531
|
+
flatData: stripSlots(newItem),
|
532
|
+
path,
|
533
|
+
parentId,
|
534
|
+
zone
|
535
|
+
};
|
536
|
+
const finalData = __spreadProps(__spreadValues({}, newItem), { props: __spreadValues({}, newItem.props) });
|
537
|
+
if (newProps.id === "root") {
|
538
|
+
delete finalData["type"];
|
539
|
+
delete finalData.props["id"];
|
540
|
+
}
|
541
|
+
return finalData;
|
542
|
+
};
|
543
|
+
const zones = state.data.zones || {};
|
544
|
+
const [_, newContent] = processContent(
|
545
|
+
[],
|
546
|
+
rootDroppableId,
|
547
|
+
state.data.content,
|
548
|
+
"root"
|
549
|
+
);
|
550
|
+
const processedContent = newContent;
|
551
|
+
const zonesAlreadyProcessed = Object.keys(newZones);
|
552
|
+
Object.keys(zones || {}).forEach((zoneCompound) => {
|
553
|
+
const [parentId] = zoneCompound.split(":");
|
554
|
+
if (zonesAlreadyProcessed.includes(zoneCompound)) {
|
555
|
+
return;
|
556
|
+
}
|
557
|
+
const [_2, newContent2] = processContent(
|
558
|
+
[rootDroppableId],
|
559
|
+
zoneCompound,
|
560
|
+
zones[zoneCompound],
|
561
|
+
"dropzone",
|
562
|
+
parentId
|
563
|
+
);
|
564
|
+
newZones[zoneCompound] = newContent2;
|
565
|
+
}, newZones);
|
566
|
+
const processedRoot = processItem(
|
567
|
+
{
|
568
|
+
type: "root",
|
569
|
+
props: __spreadProps(__spreadValues({}, (_a = state.data.root.props) != null ? _a : state.data.root), { id: "root" })
|
570
|
+
},
|
571
|
+
[],
|
572
|
+
-1
|
573
|
+
);
|
574
|
+
const root = __spreadProps(__spreadValues({}, state.data.root), {
|
575
|
+
props: processedRoot.props
|
576
|
+
});
|
577
|
+
return __spreadProps(__spreadValues({}, state), {
|
578
|
+
data: {
|
579
|
+
root,
|
580
|
+
content: processedContent,
|
581
|
+
zones: __spreadValues(__spreadValues({}, state.data.zones), newZones)
|
582
|
+
},
|
583
|
+
indexes: {
|
584
|
+
nodes: __spreadValues(__spreadValues({}, state.indexes.nodes), newNodeIndex),
|
585
|
+
zones: __spreadValues(__spreadValues({}, state.indexes.zones), newZoneIndex)
|
586
|
+
}
|
587
|
+
});
|
588
|
+
}
|
589
|
+
|
590
|
+
// lib/migrate.ts
|
591
|
+
var migrations = [
|
592
|
+
// Migrate root to root.props
|
593
|
+
(data) => {
|
594
|
+
const rootProps = data.root.props || data.root;
|
595
|
+
if (Object.keys(data.root).length > 0 && !data.root.props) {
|
596
|
+
console.warn(
|
597
|
+
"Migration applied: Root props moved from `root` to `root.props`."
|
598
|
+
);
|
599
|
+
return __spreadProps(__spreadValues({}, data), {
|
600
|
+
root: {
|
601
|
+
props: __spreadValues({}, rootProps)
|
602
|
+
}
|
603
|
+
});
|
604
|
+
}
|
605
|
+
return data;
|
606
|
+
},
|
607
|
+
// Migrate zones to slots
|
608
|
+
(data, config) => {
|
609
|
+
var _a;
|
610
|
+
if (!config) return data;
|
611
|
+
console.log("Migrating DropZones to slots...");
|
612
|
+
const updatedItems = {};
|
613
|
+
const appState = __spreadProps(__spreadValues({}, defaultAppState), { data });
|
614
|
+
const { indexes } = walkAppState(appState, config);
|
615
|
+
const deletedCompounds = [];
|
616
|
+
walkAppState(appState, config, (content, zoneCompound, zoneType) => {
|
617
|
+
var _a2, _b;
|
618
|
+
if (zoneType === "dropzone") {
|
619
|
+
const [id, slotName] = zoneCompound.split(":");
|
620
|
+
const nodeData = indexes.nodes[id].data;
|
621
|
+
const componentType = nodeData.type;
|
622
|
+
const configForComponent = id === "root" ? config.root : config.components[componentType];
|
623
|
+
if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
|
624
|
+
updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
|
625
|
+
props: __spreadProps(__spreadValues({}, nodeData.props), {
|
626
|
+
[slotName]: content
|
627
|
+
})
|
628
|
+
});
|
629
|
+
deletedCompounds.push(zoneCompound);
|
630
|
+
}
|
631
|
+
return content;
|
632
|
+
}
|
633
|
+
return content;
|
634
|
+
});
|
635
|
+
const updated = walkAppState(
|
636
|
+
appState,
|
637
|
+
config,
|
638
|
+
(content) => content,
|
639
|
+
(item) => {
|
640
|
+
var _a2;
|
641
|
+
return (_a2 = updatedItems[item.props.id]) != null ? _a2 : item;
|
642
|
+
}
|
643
|
+
);
|
644
|
+
deletedCompounds.forEach((zoneCompound) => {
|
645
|
+
var _a2;
|
646
|
+
const [_, propName] = zoneCompound.split(":");
|
647
|
+
console.log(
|
648
|
+
`\u2713 Success: Migrated "${zoneCompound}" from DropZone to slot field "${propName}"`
|
649
|
+
);
|
650
|
+
(_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
|
651
|
+
});
|
652
|
+
Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
|
653
|
+
const [_, propName] = zoneCompound.split(":");
|
654
|
+
throw new Error(
|
655
|
+
`Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
|
656
|
+
);
|
657
|
+
});
|
658
|
+
delete updated.data.zones;
|
659
|
+
return updated.data;
|
660
|
+
}
|
661
|
+
];
|
662
|
+
function migrate(data, config) {
|
663
|
+
return migrations == null ? void 0 : migrations.reduce(
|
664
|
+
(acc, migration) => migration(acc, config),
|
665
|
+
data
|
666
|
+
);
|
667
|
+
}
|
668
|
+
|
359
669
|
// lib/transform-props.ts
|
360
670
|
init_react_import();
|
361
671
|
|
@@ -367,11 +677,13 @@ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
|
367
677
|
});
|
368
678
|
|
369
679
|
// lib/transform-props.ts
|
370
|
-
function transformProps(data, propTransforms) {
|
680
|
+
function transformProps(data, propTransforms, config = { components: {} }) {
|
371
681
|
const mapItem = (item) => {
|
372
682
|
if (propTransforms[item.type]) {
|
373
683
|
return __spreadProps(__spreadValues({}, item), {
|
374
|
-
props:
|
684
|
+
props: __spreadValues({
|
685
|
+
id: item.props.id
|
686
|
+
}, propTransforms[item.type](item.props))
|
375
687
|
});
|
376
688
|
}
|
377
689
|
return item;
|
@@ -380,23 +692,18 @@ function transformProps(data, propTransforms) {
|
|
380
692
|
const rootProps = defaultedData.root.props || defaultedData.root;
|
381
693
|
let newRoot = __spreadValues({}, defaultedData.root);
|
382
694
|
if (propTransforms["root"]) {
|
383
|
-
|
384
|
-
newRoot.props = propTransforms["root"](rootProps);
|
385
|
-
} else {
|
386
|
-
newRoot = propTransforms["root"](rootProps);
|
387
|
-
}
|
695
|
+
newRoot.props = propTransforms["root"](rootProps);
|
388
696
|
}
|
389
|
-
const
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
return afterPropTransforms;
|
697
|
+
const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
|
698
|
+
const updatedData = walkTree(
|
699
|
+
dataWithUpdatedRoot,
|
700
|
+
config,
|
701
|
+
(content) => content.map(mapItem)
|
702
|
+
);
|
703
|
+
if (!defaultedData.root.props) {
|
704
|
+
updatedData.root = updatedData.root.props;
|
705
|
+
}
|
706
|
+
return updatedData;
|
400
707
|
}
|
401
708
|
|
402
709
|
// lib/resolve-all-data.ts
|
@@ -548,19 +855,21 @@ export {
|
|
548
855
|
__toESM,
|
549
856
|
__async,
|
550
857
|
init_react_import,
|
551
|
-
isSlot,
|
552
|
-
createIsSlotConfig,
|
553
858
|
rootAreaId,
|
554
859
|
rootZone,
|
555
860
|
rootDroppableId,
|
861
|
+
walkAppState,
|
556
862
|
walkTree,
|
557
863
|
setupZone,
|
864
|
+
defaultViewports,
|
558
865
|
getChanged,
|
559
866
|
resolveComponentData,
|
867
|
+
defaultAppState,
|
560
868
|
useSlots,
|
561
869
|
Render,
|
562
870
|
SlotRenderPure,
|
563
871
|
SlotRender,
|
872
|
+
migrate,
|
564
873
|
transformProps,
|
565
874
|
resolveAllData
|
566
875
|
};
|
package/dist/index.d.mts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-
|
2
|
-
export {
|
1
|
+
import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-DOB5QZVq.mjs';
|
2
|
+
export { _ as Adaptor, Y as ArrayField, t as ArrayState, ab as AsFieldProps, B as BaseData, K as BaseField, G as ComponentDataMap, z as ComponentDataOptionalId, J as Content, a2 as CustomField, a1 as CustomFieldRender, a8 as DefaultComponentProps, a5 as DefaultRootFieldProps, a7 as DefaultRootProps, a6 as DefaultRootRenderProps, m as Direction, n as DragAxis, a0 as ExternalField, $ as ExternalFieldWithAdaptor, ad as ExtractPropsFromConfig, ae as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, E as MappedItem, N as NumberField, Z as ObjectField, q as OverrideKey, u as PuckComponent, a4 as PuckContext, X as RadioField, v as RootConfig, y as RootData, x as RootDataWithoutProps, Q as SelectField, S as Slot, a3 as SlotField, T as TextField, L as TextareaField, o as Viewport, ac as WithChildren, a9 as WithId, aa as WithPuckProps, W as WithSlotProps, af as migrate, p as overrideKeys, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DOB5QZVq.mjs';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import * as react from 'react';
|
5
5
|
import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
|
@@ -247,8 +247,6 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
|
|
247
247
|
metadata?: Metadata;
|
248
248
|
}): react_jsx_runtime.JSX.Element;
|
249
249
|
|
250
|
-
declare function migrate(data: Data, config?: Config): Data;
|
251
|
-
|
252
250
|
type WithGet<T> = T & {
|
253
251
|
get: () => T;
|
254
252
|
};
|
@@ -286,5 +284,11 @@ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConf
|
|
286
284
|
*/
|
287
285
|
declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
|
288
286
|
declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
|
287
|
+
/**
|
288
|
+
* Get the latest state without relying on a render
|
289
|
+
*
|
290
|
+
* @returns PuckApi
|
291
|
+
*/
|
292
|
+
declare function useGetPuck(): () => UsePuckStore<Config>;
|
289
293
|
|
290
|
-
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck,
|
294
|
+
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, renderContext, useGetPuck, usePuck };
|
package/dist/index.d.ts
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-
|
2
|
-
export {
|
1
|
+
import { H as History, P as Permissions, C as ComponentData, a as Config, U as UserGenerics, F as Fields, b as PuckAction, R as RootDataWithProps, c as ResolveDataTrigger, d as Plugin, O as Overrides, V as Viewports, I as IframeConfig, e as UiState, f as ComponentConfig, A as AppState, M as Metadata, g as Field, h as FieldProps, D as DropZoneProps, i as Data, j as OnAction, k as InitialHistory, l as ItemSelector } from './walk-tree-DOB5QZVq.js';
|
2
|
+
export { _ as Adaptor, Y as ArrayField, t as ArrayState, ab as AsFieldProps, B as BaseData, K as BaseField, G as ComponentDataMap, z as ComponentDataOptionalId, J as Content, a2 as CustomField, a1 as CustomFieldRender, a8 as DefaultComponentProps, a5 as DefaultRootFieldProps, a7 as DefaultRootProps, a6 as DefaultRootRenderProps, m as Direction, n as DragAxis, a0 as ExternalField, $ as ExternalFieldWithAdaptor, ad as ExtractPropsFromConfig, ae as ExtractRootPropsFromConfig, r as FieldRenderFunctions, s as ItemWithId, E as MappedItem, N as NumberField, Z as ObjectField, q as OverrideKey, u as PuckComponent, a4 as PuckContext, X as RadioField, v as RootConfig, y as RootData, x as RootDataWithoutProps, Q as SelectField, S as Slot, a3 as SlotField, T as TextField, L as TextareaField, o as Viewport, ac as WithChildren, a9 as WithId, aa as WithPuckProps, W as WithSlotProps, af as migrate, p as overrideKeys, ah as resolveAllData, ag as transformProps, w as walkTree } from './walk-tree-DOB5QZVq.js';
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
4
4
|
import * as react from 'react';
|
5
5
|
import react__default, { ReactNode, SyntheticEvent, ReactElement } from 'react';
|
@@ -247,8 +247,6 @@ declare function Render<UserConfig extends Config = Config, G extends UserGeneri
|
|
247
247
|
metadata?: Metadata;
|
248
248
|
}): react_jsx_runtime.JSX.Element;
|
249
249
|
|
250
|
-
declare function migrate(data: Data, config?: Config): Data;
|
251
|
-
|
252
250
|
type WithGet<T> = T & {
|
253
251
|
get: () => T;
|
254
252
|
};
|
@@ -286,5 +284,11 @@ type UsePuckStore<UserConfig extends Config = Config> = WithGet<PuckApi<UserConf
|
|
286
284
|
*/
|
287
285
|
declare function createUsePuck<UserConfig extends Config = Config>(): <T = PuckApi<UserConfig>>(selector: (state: UsePuckStore<UserConfig>) => T) => T;
|
288
286
|
declare function usePuck<UserConfig extends Config = Config>(): UsePuckStore<UserConfig>;
|
287
|
+
/**
|
288
|
+
* Get the latest state without relying on a render
|
289
|
+
*
|
290
|
+
* @returns PuckApi
|
291
|
+
*/
|
292
|
+
declare function useGetPuck(): () => UsePuckStore<Config>;
|
289
293
|
|
290
|
-
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck,
|
294
|
+
export { Action, ActionBar, AppState, AutoField, Button, ComponentConfig, ComponentData, Config, Data, Drawer, DropZone, Field, FieldLabel, FieldProps, Fields, Group, History, IconButton, IframeConfig, InitialHistory, Label, Metadata, OnAction, Overrides, Permissions, Plugin, Puck, PuckAction, type PuckApi, Render, ResolveDataTrigger, RootDataWithProps, UiState, type UsePuckData, UserGenerics, Viewports, createUsePuck, renderContext, useGetPuck, usePuck };
|
package/dist/index.js
CHANGED
@@ -174,6 +174,7 @@ __export(core_exports, {
|
|
174
174
|
renderContext: () => renderContext,
|
175
175
|
resolveAllData: () => resolveAllData,
|
176
176
|
transformProps: () => transformProps,
|
177
|
+
useGetPuck: () => useGetPuck,
|
177
178
|
usePuck: () => usePuck,
|
178
179
|
walkTree: () => walkTree
|
179
180
|
});
|
@@ -2179,7 +2180,8 @@ var toRoot = (item) => {
|
|
2179
2180
|
return { props: {}, readOnly };
|
2180
2181
|
};
|
2181
2182
|
|
2182
|
-
// store/
|
2183
|
+
// store/default-app-state.ts
|
2184
|
+
init_react_import();
|
2183
2185
|
var defaultAppState = {
|
2184
2186
|
data: { content: [], root: {}, zones: {} },
|
2185
2187
|
ui: {
|
@@ -2205,6 +2207,8 @@ var defaultAppState = {
|
|
2205
2207
|
zones: {}
|
2206
2208
|
}
|
2207
2209
|
};
|
2210
|
+
|
2211
|
+
// store/index.ts
|
2208
2212
|
var defaultPageFields = {
|
2209
2213
|
title: { type: "text" }
|
2210
2214
|
};
|
@@ -4251,6 +4255,23 @@ function useContextStore(context, selector) {
|
|
4251
4255
|
// components/DraggableComponent/index.tsx
|
4252
4256
|
var import_shallow2 = require("zustand/react/shallow");
|
4253
4257
|
var import_sortable2 = require("@dnd-kit/react/sortable");
|
4258
|
+
|
4259
|
+
// lib/accumulate-transform.ts
|
4260
|
+
init_react_import();
|
4261
|
+
function accumulateTransform(el) {
|
4262
|
+
let matrix = new DOMMatrixReadOnly();
|
4263
|
+
let n = el.parentElement;
|
4264
|
+
while (n && n !== document.documentElement) {
|
4265
|
+
const t = getComputedStyle(n).transform;
|
4266
|
+
if (t && t !== "none") {
|
4267
|
+
matrix = new DOMMatrixReadOnly(t).multiply(matrix);
|
4268
|
+
}
|
4269
|
+
n = n.parentElement;
|
4270
|
+
}
|
4271
|
+
return { scaleX: matrix.a, scaleY: matrix.d };
|
4272
|
+
}
|
4273
|
+
|
4274
|
+
// components/DraggableComponent/index.tsx
|
4254
4275
|
var import_jsx_runtime20 = require("react/jsx-runtime");
|
4255
4276
|
var getClassName16 = get_class_name_factory_default("DraggableComponent", styles_module_default11);
|
4256
4277
|
var DEBUG2 = false;
|
@@ -4390,11 +4411,16 @@ var DraggableComponent = ({
|
|
4390
4411
|
x: deepScrollPosition.x - portalScroll.x - ((_b = portalContainerRect == null ? void 0 : portalContainerRect.left) != null ? _b : 0),
|
4391
4412
|
y: deepScrollPosition.y - portalScroll.y - ((_c = portalContainerRect == null ? void 0 : portalContainerRect.top) != null ? _c : 0)
|
4392
4413
|
};
|
4414
|
+
const untransformed = {
|
4415
|
+
height: ref.current.offsetHeight,
|
4416
|
+
width: ref.current.offsetWidth
|
4417
|
+
};
|
4418
|
+
const transform = accumulateTransform(ref.current);
|
4393
4419
|
const style2 = {
|
4394
|
-
left: `${rect.left + scroll.x}px`,
|
4395
|
-
top: `${rect.top + scroll.y}px`,
|
4396
|
-
height: `${
|
4397
|
-
width: `${
|
4420
|
+
left: `${(rect.left + scroll.x) / transform.scaleX}px`,
|
4421
|
+
top: `${(rect.top + scroll.y) / transform.scaleY}px`,
|
4422
|
+
height: `${untransformed.height}px`,
|
4423
|
+
width: `${untransformed.width}px`
|
4398
4424
|
};
|
4399
4425
|
return style2;
|
4400
4426
|
}, [ref.current]);
|
@@ -6108,6 +6134,13 @@ var DragDropContextClient = ({
|
|
6108
6134
|
dragMode.current = isNewComponent ? "new" : "existing";
|
6109
6135
|
initialSelector.current = void 0;
|
6110
6136
|
zoneStore.setState({ draggedItem: event.operation.source });
|
6137
|
+
dispatch({
|
6138
|
+
type: "setUi",
|
6139
|
+
ui: {
|
6140
|
+
isDragging: true
|
6141
|
+
},
|
6142
|
+
recordHistory: false
|
6143
|
+
});
|
6111
6144
|
},
|
6112
6145
|
children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(ZoneStoreProvider, { store: zoneStore, children: /* @__PURE__ */ (0, import_jsx_runtime26.jsx)(DropZoneProvider, { value: nextContextValue, children }) })
|
6113
6146
|
}
|
@@ -7981,6 +8014,13 @@ function usePuck() {
|
|
7981
8014
|
}, []);
|
7982
8015
|
return createUsePuck()((s) => s);
|
7983
8016
|
}
|
8017
|
+
function useGetPuck() {
|
8018
|
+
const usePuckApi = (0, import_react53.useContext)(UsePuckStoreContext);
|
8019
|
+
if (!usePuckApi) {
|
8020
|
+
throw new Error("usePuckGet must be used inside <Puck>.");
|
8021
|
+
}
|
8022
|
+
return usePuckApi.getState;
|
8023
|
+
}
|
7984
8024
|
|
7985
8025
|
// components/Puck/index.tsx
|
7986
8026
|
var import_fast_deep_equal2 = __toESM(require("fast-deep-equal"));
|
@@ -8438,7 +8478,7 @@ var migrations = [
|
|
8438
8478
|
const [id, slotName] = zoneCompound.split(":");
|
8439
8479
|
const nodeData = indexes.nodes[id].data;
|
8440
8480
|
const componentType = nodeData.type;
|
8441
|
-
const configForComponent = config.components[componentType];
|
8481
|
+
const configForComponent = id === "root" ? config.root : config.components[componentType];
|
8442
8482
|
if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
|
8443
8483
|
updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
|
8444
8484
|
props: __spreadProps(__spreadValues({}, nodeData.props), {
|
@@ -8496,11 +8536,13 @@ var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
|
|
8496
8536
|
});
|
8497
8537
|
|
8498
8538
|
// lib/transform-props.ts
|
8499
|
-
function transformProps(data, propTransforms) {
|
8539
|
+
function transformProps(data, propTransforms, config = { components: {} }) {
|
8500
8540
|
const mapItem = (item) => {
|
8501
8541
|
if (propTransforms[item.type]) {
|
8502
8542
|
return __spreadProps(__spreadValues({}, item), {
|
8503
|
-
props:
|
8543
|
+
props: __spreadValues({
|
8544
|
+
id: item.props.id
|
8545
|
+
}, propTransforms[item.type](item.props))
|
8504
8546
|
});
|
8505
8547
|
}
|
8506
8548
|
return item;
|
@@ -8509,23 +8551,18 @@ function transformProps(data, propTransforms) {
|
|
8509
8551
|
const rootProps = defaultedData.root.props || defaultedData.root;
|
8510
8552
|
let newRoot = __spreadValues({}, defaultedData.root);
|
8511
8553
|
if (propTransforms["root"]) {
|
8512
|
-
|
8513
|
-
newRoot.props = propTransforms["root"](rootProps);
|
8514
|
-
} else {
|
8515
|
-
newRoot = propTransforms["root"](rootProps);
|
8516
|
-
}
|
8554
|
+
newRoot.props = propTransforms["root"](rootProps);
|
8517
8555
|
}
|
8518
|
-
const
|
8519
|
-
|
8520
|
-
|
8521
|
-
|
8522
|
-
|
8523
|
-
|
8524
|
-
|
8525
|
-
|
8526
|
-
|
8527
|
-
|
8528
|
-
return afterPropTransforms;
|
8556
|
+
const dataWithUpdatedRoot = __spreadProps(__spreadValues({}, defaultedData), { root: newRoot });
|
8557
|
+
const updatedData = walkTree(
|
8558
|
+
dataWithUpdatedRoot,
|
8559
|
+
config,
|
8560
|
+
(content) => content.map(mapItem)
|
8561
|
+
);
|
8562
|
+
if (!defaultedData.root.props) {
|
8563
|
+
updatedData.root = updatedData.root.props;
|
8564
|
+
}
|
8565
|
+
return updatedData;
|
8529
8566
|
}
|
8530
8567
|
|
8531
8568
|
// lib/resolve-all-data.ts
|
@@ -8610,6 +8647,7 @@ function resolveAllData(_0, _1) {
|
|
8610
8647
|
renderContext,
|
8611
8648
|
resolveAllData,
|
8612
8649
|
transformProps,
|
8650
|
+
useGetPuck,
|
8613
8651
|
usePuck,
|
8614
8652
|
walkTree
|
8615
8653
|
});
|