@measured/puck 0.19.0-canary.f96dc87b → 0.19.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.
@@ -1,4 +1,4 @@
1
- import { CSSProperties, ReactElement, JSX, ReactNode } from 'react';
1
+ import { CSSProperties, ReactElement, ReactNode, JSX } from 'react';
2
2
 
3
3
  type ItemSelector = {
4
4
  index: number;
@@ -23,6 +23,8 @@ type FieldOptions = Array<FieldOption> | ReadonlyArray<FieldOption>;
23
23
  type BaseField = {
24
24
  label?: string;
25
25
  labelIcon?: ReactElement;
26
+ metadata?: Metadata;
27
+ visible?: boolean;
26
28
  };
27
29
  type TextField = BaseField & {
28
30
  type: "text";
@@ -109,16 +111,22 @@ type ExternalField<Props extends {
109
111
  filterFields?: Record<string, Field>;
110
112
  initialFilters?: Record<string, any>;
111
113
  };
112
- type CustomField<Props extends any = {}> = BaseField & {
114
+ type CustomFieldRender<Value extends any> = (props: {
115
+ field: CustomField<Value>;
116
+ name: string;
117
+ id: string;
118
+ value: Value;
119
+ onChange: (value: Value) => void;
120
+ readOnly?: boolean;
121
+ }) => ReactElement;
122
+ type CustomField<Value extends any> = BaseField & {
113
123
  type: "custom";
114
- render: (props: {
115
- field: CustomField<Props>;
116
- name: string;
117
- id: string;
118
- value: Props;
119
- onChange: (value: Props) => void;
120
- readOnly?: boolean;
121
- }) => ReactElement;
124
+ render: CustomFieldRender<Value>;
125
+ };
126
+ type SlotField = BaseField & {
127
+ type: "slot";
128
+ allow?: string[];
129
+ disallow?: string[];
122
130
  };
123
131
  type Field<Props extends any = any> = TextField | NumberField | TextareaField | SelectField | RadioField | ArrayField<Props extends {
124
132
  [key: string]: any;
@@ -128,7 +136,7 @@ type Field<Props extends any = any> = TextField | NumberField | TextareaField |
128
136
  [key: string]: any;
129
137
  } ? Props : any> | ExternalFieldWithAdaptor<Props extends {
130
138
  [key: string]: any;
131
- } ? Props : any> | CustomField<Props>;
139
+ } ? Props : any> | CustomField<Props> | SlotField;
132
140
  type Fields<ComponentProps extends DefaultComponentProps = DefaultComponentProps> = {
133
141
  [PropName in keyof Omit<ComponentProps, "editMode">]: Field<ComponentProps[PropName]>;
134
142
  };
@@ -140,7 +148,14 @@ type FieldProps<F = Field<any>, ValueType = any> = {
140
148
  readOnly?: boolean;
141
149
  };
142
150
 
143
- type PuckComponent<Props> = (props: WithId<WithPuckProps<Props>>) => JSX.Element;
151
+ type SlotComponent = (props?: Omit<DropZoneProps, "zone">) => ReactNode;
152
+ type PuckComponent<Props> = (props: WithId<WithPuckProps<{
153
+ [K in keyof Props]: WithDeepSlots<Props[K], SlotComponent>;
154
+ }>>) => JSX.Element;
155
+ type ResolveDataTrigger = "insert" | "replace" | "load" | "force";
156
+ type WithPartialProps<T, Props extends DefaultComponentProps> = Omit<T, "props"> & {
157
+ props?: Partial<Props>;
158
+ };
144
159
  type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponentProps, FieldProps extends DefaultComponentProps = RenderProps, DataShape = Omit<ComponentData<FieldProps>, "type">> = {
145
160
  render: PuckComponent<RenderProps>;
146
161
  label?: string;
@@ -149,7 +164,9 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
149
164
  permissions?: Partial<Permissions>;
150
165
  inline?: boolean;
151
166
  resolveFields?: (data: DataShape, params: {
152
- changed: Partial<Record<keyof FieldProps, boolean>>;
167
+ changed: Partial<Record<keyof FieldProps, boolean> & {
168
+ id: string;
169
+ }>;
153
170
  fields: Fields<FieldProps>;
154
171
  lastFields: Fields<FieldProps>;
155
172
  lastData: DataShape | null;
@@ -157,24 +174,25 @@ type ComponentConfig<RenderProps extends DefaultComponentProps = DefaultComponen
157
174
  parent: ComponentData | null;
158
175
  }) => Promise<Fields<FieldProps>> | Fields<FieldProps>;
159
176
  resolveData?: (data: DataShape, params: {
160
- changed: Partial<Record<keyof FieldProps, boolean>>;
177
+ changed: Partial<Record<keyof FieldProps, boolean> & {
178
+ id: string;
179
+ }>;
161
180
  lastData: DataShape | null;
162
181
  metadata: Metadata;
163
- }) => Promise<{
164
- props?: Partial<FieldProps>;
165
- readOnly?: Partial<Record<keyof FieldProps, boolean>>;
166
- }> | {
167
- props?: Partial<FieldProps>;
168
- readOnly?: Partial<Record<keyof FieldProps, boolean>>;
169
- };
182
+ trigger: ResolveDataTrigger;
183
+ }) => Promise<WithPartialProps<DataShape, FieldProps>> | WithPartialProps<DataShape, FieldProps>;
170
184
  resolvePermissions?: (data: DataShape, params: {
171
- changed: Partial<Record<keyof FieldProps, boolean>>;
185
+ changed: Partial<Record<keyof FieldProps, boolean> & {
186
+ id: string;
187
+ }>;
172
188
  lastPermissions: Partial<Permissions>;
173
189
  permissions: Partial<Permissions>;
174
190
  appState: AppState;
175
191
  lastData: DataShape | null;
176
192
  }) => Promise<Partial<Permissions>> | Partial<Permissions>;
193
+ metadata?: Metadata;
177
194
  };
195
+ type RootConfig<RootProps extends DefaultComponentProps = any> = Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
178
196
  type Category<ComponentName> = {
179
197
  components?: ComponentName[];
180
198
  title?: string;
@@ -188,7 +206,7 @@ type Config<Props extends DefaultComponentProps = DefaultComponentProps, RootPro
188
206
  components: {
189
207
  [ComponentName in keyof Props]: Omit<ComponentConfig<Props[ComponentName], Props[ComponentName]>, "type">;
190
208
  };
191
- root?: Partial<ComponentConfig<WithChildren<RootProps>, AsFieldProps<RootProps>, RootData<AsFieldProps<RootProps>>>>;
209
+ root?: RootConfig<RootProps>;
192
210
  };
193
211
 
194
212
  type WithId<Props> = Props & {
@@ -204,7 +222,7 @@ type WithChildren<Props> = Props & {
204
222
  };
205
223
  type ExtractPropsFromConfig<UserConfig> = UserConfig extends Config<infer P, any, any> ? P : never;
206
224
  type ExtractRootPropsFromConfig<UserConfig> = UserConfig extends Config<any, infer P, any> ? P : never;
207
- type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends AppState<UserData> = AppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
225
+ type UserGenerics<UserConfig extends Config = Config, UserProps extends ExtractPropsFromConfig<UserConfig> = ExtractPropsFromConfig<UserConfig>, UserRootProps extends ExtractRootPropsFromConfig<UserConfig> = ExtractRootPropsFromConfig<UserConfig>, UserData extends Data<UserProps, UserRootProps> | Data = Data<UserProps, UserRootProps>, UserAppState extends PrivateAppState<UserData> = PrivateAppState<UserData>, UserComponentData extends ComponentData = UserData["content"][0]> = {
208
226
  UserConfig: UserConfig;
209
227
  UserProps: UserProps;
210
228
  UserRootProps: UserRootProps;
@@ -220,6 +238,7 @@ type PuckContext = {
220
238
  dragRef: ((element: Element | null) => void) | null;
221
239
  };
222
240
  type DefaultRootFieldProps = {
241
+ [key: string]: any;
223
242
  title?: string;
224
243
  };
225
244
  type DefaultRootRenderProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = WithPuckProps<WithChildren<Props>>;
@@ -240,23 +259,29 @@ type RootDataWithProps<Props extends DefaultComponentProps = DefaultRootFieldPro
240
259
  };
241
260
  type RootDataWithoutProps<Props extends DefaultComponentProps = DefaultRootFieldProps> = Props;
242
261
  type RootData<Props extends DefaultComponentProps = DefaultRootFieldProps> = Partial<RootDataWithProps<AsFieldProps<Props>>> & Partial<RootDataWithoutProps<Props>>;
243
- type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
262
+ type ComponentData<Props extends DefaultComponentProps = DefaultComponentProps, Name = string, AllProps extends Record<string, DefaultComponentProps> = Record<string, DefaultComponentProps>> = {
263
+ type: Name;
264
+ props: WithDeepSlots<WithId<Props>, Content<AllProps>>;
265
+ } & BaseData<Props>;
266
+ type ComponentDataOptionalId<Props extends DefaultComponentProps = DefaultComponentProps, Name = string> = {
244
267
  type: Name;
245
- props: WithId<Props>;
268
+ props: Props & {
269
+ id?: string;
270
+ };
246
271
  } & BaseData<Props>;
247
272
  type MappedItem = ComponentData;
248
- type ComponentDataMap<Props extends Record<string, DefaultComponentProps> = DefaultComponentProps> = {
249
- [K in keyof Props]: ComponentData<Props[K], K extends string ? K : never>;
250
- }[keyof Props];
273
+ type ComponentDataMap<AllProps extends DefaultAllProps = DefaultAllProps> = {
274
+ [K in keyof AllProps]: ComponentData<AllProps[K], K extends string ? K : never, AllProps>;
275
+ }[keyof AllProps];
251
276
  type Content<PropsMap extends {
252
- [key: string]: any;
277
+ [key: string]: DefaultComponentProps;
253
278
  } = {
254
- [key: string]: any;
279
+ [key: string]: DefaultComponentProps;
255
280
  }> = ComponentDataMap<PropsMap>[];
256
- type Data<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
257
- root: RootData<RootProps>;
258
- content: Content<Props>;
259
- zones?: Record<string, Content<Props>>;
281
+ type Data<AllProps extends DefaultAllProps = DefaultAllProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = {
282
+ root: WithDeepSlots<RootData<RootProps>, Content<AllProps>>;
283
+ content: Content<AllProps>;
284
+ zones?: Record<string, Content<AllProps>>;
260
285
  };
261
286
  type Metadata = {
262
287
  [key: string]: any;
@@ -300,6 +325,34 @@ type AppState<UserData extends Data = Data> = {
300
325
  ui: UiState;
301
326
  };
302
327
 
328
+ type ZoneType = "root" | "dropzone" | "slot";
329
+ type PuckNodeData = {
330
+ data: ComponentData;
331
+ flatData: ComponentData;
332
+ parentId: string | null;
333
+ zone: string;
334
+ path: string[];
335
+ };
336
+ type PuckZoneData = {
337
+ contentIds: string[];
338
+ type: ZoneType;
339
+ };
340
+ type NodeIndex = Record<string, PuckNodeData>;
341
+ type ZoneIndex = Record<string, PuckZoneData>;
342
+ type PrivateAppState<UserData extends Data = Data> = AppState<UserData> & {
343
+ indexes: {
344
+ nodes: NodeIndex;
345
+ zones: ZoneIndex;
346
+ };
347
+ };
348
+ type DefaultAllProps = Record<string, DefaultComponentProps>;
349
+ /**
350
+ * Recursively walk T and replace Slots with SlotComponents
351
+ */
352
+ type WithDeepSlots<T, SlotType = T> = T extends Slot ? SlotType : T extends (infer U)[] ? Array<WithDeepSlots<U, SlotType>> : T extends (infer U)[] ? WithDeepSlots<U, SlotType>[] : T extends object ? {
353
+ [K in keyof T]: WithDeepSlots<T[K], SlotType>;
354
+ } : T;
355
+
303
356
  type RenderFunc<Props extends {
304
357
  [key: string]: any;
305
358
  } = {
@@ -406,6 +459,14 @@ type InitialHistoryNoAppend<AS = Partial<AppState>> = {
406
459
  appendData?: false;
407
460
  };
408
461
  type InitialHistory<AS = Partial<AppState>> = InitialHistoryAppend<AS> | InitialHistoryNoAppend<AS>;
462
+ type Slot<Props extends {
463
+ [key: string]: DefaultComponentProps;
464
+ } = {
465
+ [key: string]: DefaultComponentProps;
466
+ }> = {
467
+ [K in keyof Props]: ComponentDataOptionalId<Props[K], K extends string ? K : never>;
468
+ }[keyof Props][];
469
+ type WithSlotProps<Target extends Record<string, any>, AllProps extends DefaultAllProps = DefaultAllProps, SlotType extends Content<AllProps> = Content<AllProps>> = WithDeepSlots<Target, SlotType>;
409
470
 
410
471
  type InsertAction = {
411
472
  type: "insert";
@@ -419,11 +480,17 @@ type DuplicateAction = {
419
480
  sourceIndex: number;
420
481
  sourceZone: string;
421
482
  };
422
- type ReplaceAction = {
483
+ type ReplaceAction<UserData extends Data = Data> = {
423
484
  type: "replace";
424
485
  destinationIndex: number;
425
486
  destinationZone: string;
426
- data: any;
487
+ data: ComponentData;
488
+ ui?: Partial<AppState<UserData>["ui"]>;
489
+ };
490
+ type ReplaceRootAction<UserData extends Data = Data> = {
491
+ type: "replaceRoot";
492
+ root: RootData;
493
+ ui?: Partial<AppState<UserData>["ui"]>;
427
494
  };
428
495
  type ReorderAction = {
429
496
  type: "reorder";
@@ -453,7 +520,7 @@ type SetDataAction = {
453
520
  };
454
521
  type SetAction<UserData extends Data = Data> = {
455
522
  type: "set";
456
- state: Partial<AppState<UserData>> | ((previous: AppState<UserData>) => Partial<AppState<UserData>>);
523
+ state: Partial<PrivateAppState<UserData>> | ((previous: PrivateAppState<UserData>) => Partial<PrivateAppState<UserData>>);
457
524
  };
458
525
  type RegisterZoneAction = {
459
526
  type: "registerZone";
@@ -465,7 +532,9 @@ type UnregisterZoneAction = {
465
532
  };
466
533
  type PuckAction = {
467
534
  recordHistory?: boolean;
468
- } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
535
+ } & (ReorderAction | InsertAction | MoveAction | ReplaceAction | ReplaceRootAction | RemoveAction | DuplicateAction | SetAction | SetDataAction | SetUiAction | RegisterZoneAction | UnregisterZoneAction);
536
+
537
+ declare function migrate(data: Data, config?: Config): Data;
469
538
 
470
539
  type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps> = Partial<{
471
540
  [ComponentName in keyof Props]: (props: Props[ComponentName] & {
@@ -476,8 +545,14 @@ type PropTransform<Props extends DefaultComponentProps = DefaultComponentProps,
476
545
  [key: string]: any;
477
546
  }) => RootProps;
478
547
  }>;
479
- declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>): Data;
548
+ declare function transformProps<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends DefaultComponentProps = DefaultRootFieldProps>(data: Partial<Data>, propTransforms: PropTransform<Props, RootProps>, config?: Config): Data;
480
549
 
481
550
  declare function resolveAllData<Props extends DefaultComponentProps = DefaultComponentProps, RootProps extends Record<string, any> = DefaultRootFieldProps>(data: Partial<Data>, config: Config, metadata?: Metadata, onResolveStart?: (item: ComponentData) => void, onResolveEnd?: (item: ComponentData) => void): Promise<Data<Props, RootProps>>;
482
551
 
483
- export { type DefaultComponentProps as $, type AppState as A, type BaseData as B, type Config as C, type DropZoneProps as D, type RadioField as E, type FieldProps as F, type ArrayField as G, type History as H, type IframeConfig as I, type ObjectField as J, type Adaptor as K, type ExternalFieldWithAdaptor as L, type Metadata as M, type NumberField as N, type OnAction as O, type Permissions as P, type ExternalField as Q, type RootDataWithProps as R, type SelectField as S, type TextField as T, type UserGenerics as U, type Viewports as V, type CustomField as W, type PuckContext as X, type DefaultRootFieldProps as Y, type DefaultRootRenderProps as Z, type DefaultRootProps as _, type Field as a, type WithId as a0, type WithPuckProps as a1, type AsFieldProps as a2, type WithChildren as a3, type ExtractPropsFromConfig as a4, type ExtractRootPropsFromConfig as a5, transformProps as a6, resolveAllData as a7, type Data as b, type UiState as c, type Plugin as d, type Overrides as e, type PuckAction as f, type InitialHistory as g, type ComponentData as h, type Fields as i, type ComponentConfig as j, type Direction as k, type DragAxis as l, type Viewport as m, type OverrideKey as n, overrideKeys as o, type FieldRenderFunctions as p, type ItemWithId as q, type ArrayState as r, type PuckComponent as s, type RootDataWithoutProps as t, type RootData as u, type MappedItem as v, type ComponentDataMap as w, type Content as x, type BaseField as y, type TextareaField as z };
552
+ type WalkTreeOptions = {
553
+ parentId: string;
554
+ propName: string;
555
+ };
556
+ declare function walkTree<T extends ComponentData | RootData | G["UserData"], UserConfig extends Config = Config, G extends UserGenerics<UserConfig> = UserGenerics<UserConfig>>(data: T, config: UserConfig, callbackFn: (data: Content, options: WalkTreeOptions) => Content | null | void): T;
557
+
558
+ export { type ExternalFieldWithAdaptor as $, type AppState as A, type BaseData as B, type ComponentData as C, type DropZoneProps as D, type MappedItem as E, type Fields as F, type ComponentDataMap as G, type History as H, type IframeConfig as I, type Content as J, type BaseField as K, type TextareaField as L, type Metadata as M, type NumberField as N, type Overrides as O, type Permissions as P, type SelectField as Q, type RootDataWithProps as R, type Slot as S, type TextField as T, type UserGenerics as U, type Viewports as V, type WithSlotProps as W, type RadioField as X, type ArrayField as Y, type ObjectField as Z, type Adaptor as _, type Config as a, type ExternalField as a0, type CustomFieldRender as a1, type CustomField as a2, type SlotField as a3, type PuckContext as a4, type DefaultRootFieldProps as a5, type DefaultRootRenderProps as a6, type DefaultRootProps as a7, type DefaultComponentProps as a8, type WithId as a9, type WithPuckProps as aa, type AsFieldProps as ab, type WithChildren as ac, type ExtractPropsFromConfig as ad, type ExtractRootPropsFromConfig as ae, migrate as af, transformProps as ag, resolveAllData as ah, type PuckAction as b, type ResolveDataTrigger as c, type Plugin as d, type UiState as e, type ComponentConfig as f, type Field as g, type FieldProps as h, type Data as i, type OnAction as j, type InitialHistory as k, type ItemSelector as l, type Direction as m, type DragAxis as n, type Viewport as o, overrideKeys as p, type OverrideKey as q, type FieldRenderFunctions as r, type ItemWithId as s, type ArrayState as t, type PuckComponent as u, type RootConfig as v, walkTree as w, type RootDataWithoutProps as x, type RootData as y, type ComponentDataOptionalId as z };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.19.0-canary.f96dc87b",
4
- "author": "Measured Corporation Ltd <hello@measured.co>",
3
+ "version": "0.19.0",
4
+ "author": "Chris Villa <chris@puckeditor.com>",
5
5
  "repository": "measuredco/puck",
6
6
  "bugs": "https://github.com/measuredco/puck/issues",
7
7
  "homepage": "https://puckeditor.com",
@@ -49,9 +49,12 @@
49
49
  "dist"
50
50
  ],
51
51
  "devDependencies": {
52
+ "@juggle/resize-observer": "^3.4.0",
53
+ "@testing-library/jest-dom": "^6.6.3",
52
54
  "@testing-library/react": "^16.1.0",
53
55
  "@types/deep-diff": "^1.0.3",
54
- "@types/jest": "^29.5.4",
56
+ "@types/flat": "^5.0.5",
57
+ "@types/jest": "^29.5.14",
55
58
  "@types/object-hash": "^3.0.6",
56
59
  "@types/react": "^19.0.1",
57
60
  "@types/react-dom": "^19.0.2",
@@ -59,20 +62,22 @@
59
62
  "css-box-model": "^1.2.1",
60
63
  "eslint": "^7.32.0",
61
64
  "eslint-config-custom": "*",
62
- "jest": "^29.6.4",
63
- "jest-environment-jsdom": "^29.6.4",
65
+ "identity-obj-proxy": "^3.0.0",
66
+ "jest": "^29.7.0",
67
+ "jest-environment-jsdom": "^30.0.0-beta.3",
64
68
  "lucide-react": "^0.468.0",
65
- "ts-jest": "^29.2.4",
69
+ "ts-jest": "^29.3.4",
66
70
  "tsconfig": "*",
67
71
  "tsup": "^8.2.4",
68
72
  "tsup-config": "*",
69
73
  "typescript": "^5.5.4"
70
74
  },
71
75
  "dependencies": {
72
- "@dnd-kit/helpers": "0.0.7-beta-20250130032138",
73
- "@dnd-kit/react": "0.0.7-beta-20250130032138",
76
+ "@dnd-kit/helpers": "0.1.18",
77
+ "@dnd-kit/react": "0.1.18",
74
78
  "deep-diff": "^1.0.2",
75
79
  "fast-deep-equal": "^3.1.3",
80
+ "flat": "^5.0.2",
76
81
  "object-hash": "^3.0.0",
77
82
  "react-hotkeys-hook": "^4.6.1",
78
83
  "use-debounce": "^9.0.4",
@@ -1,308 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __typeError = (msg) => {
12
- throw TypeError(msg);
13
- };
14
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
15
- var __spreadValues = (a, b) => {
16
- for (var prop in b || (b = {}))
17
- if (__hasOwnProp.call(b, prop))
18
- __defNormalProp(a, prop, b[prop]);
19
- if (__getOwnPropSymbols)
20
- for (var prop of __getOwnPropSymbols(b)) {
21
- if (__propIsEnum.call(b, prop))
22
- __defNormalProp(a, prop, b[prop]);
23
- }
24
- return a;
25
- };
26
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
- var __objRest = (source, exclude) => {
28
- var target = {};
29
- for (var prop in source)
30
- if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
31
- target[prop] = source[prop];
32
- if (source != null && __getOwnPropSymbols)
33
- for (var prop of __getOwnPropSymbols(source)) {
34
- if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
35
- target[prop] = source[prop];
36
- }
37
- return target;
38
- };
39
- var __esm = (fn, res) => function __init() {
40
- return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
41
- };
42
- var __commonJS = (cb, mod) => function __require() {
43
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
44
- };
45
- var __copyProps = (to, from, except, desc) => {
46
- if (from && typeof from === "object" || typeof from === "function") {
47
- for (let key of __getOwnPropNames(from))
48
- if (!__hasOwnProp.call(to, key) && key !== except)
49
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
50
- }
51
- return to;
52
- };
53
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
54
- // If the importer is in node compatibility mode or this is not an ESM
55
- // file that has been converted to a CommonJS file using a Babel-
56
- // compatible transform (i.e. "__esModule" has not been set), then set
57
- // "default" to the CommonJS "module.exports" for node compatibility.
58
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
59
- mod
60
- ));
61
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
62
- var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
63
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
64
- var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), setter ? setter.call(obj, value) : member.set(obj, value), value);
65
- var __async = (__this, __arguments, generator) => {
66
- return new Promise((resolve, reject) => {
67
- var fulfilled = (value) => {
68
- try {
69
- step(generator.next(value));
70
- } catch (e) {
71
- reject(e);
72
- }
73
- };
74
- var rejected = (value) => {
75
- try {
76
- step(generator.throw(value));
77
- } catch (e) {
78
- reject(e);
79
- }
80
- };
81
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
82
- step((generator = generator.apply(__this, __arguments)).next());
83
- });
84
- };
85
-
86
- // ../tsup-config/react-import.js
87
- import React from "react";
88
- var init_react_import = __esm({
89
- "../tsup-config/react-import.js"() {
90
- "use strict";
91
- }
92
- });
93
-
94
- // lib/transform-props.ts
95
- init_react_import();
96
-
97
- // lib/default-data.ts
98
- init_react_import();
99
- var defaultData = (data) => __spreadProps(__spreadValues({}, data), {
100
- root: data.root || {},
101
- content: data.content || []
102
- });
103
-
104
- // lib/transform-props.ts
105
- function transformProps(data, propTransforms) {
106
- const mapItem = (item) => {
107
- if (propTransforms[item.type]) {
108
- return __spreadProps(__spreadValues({}, item), {
109
- props: propTransforms[item.type](item.props)
110
- });
111
- }
112
- return item;
113
- };
114
- const defaultedData = defaultData(data);
115
- const rootProps = defaultedData.root.props || defaultedData.root;
116
- let newRoot = __spreadValues({}, defaultedData.root);
117
- if (propTransforms["root"]) {
118
- if (defaultedData.root.props) {
119
- newRoot.props = propTransforms["root"](rootProps);
120
- } else {
121
- newRoot = propTransforms["root"](rootProps);
122
- }
123
- }
124
- const afterPropTransforms = __spreadProps(__spreadValues({}, defaultedData), {
125
- root: newRoot,
126
- content: defaultedData.content.map(mapItem),
127
- zones: Object.keys(data.zones || {}).reduce(
128
- (acc, zoneKey) => __spreadProps(__spreadValues({}, acc), {
129
- [zoneKey]: data.zones[zoneKey].map(mapItem)
130
- }),
131
- {}
132
- )
133
- });
134
- return afterPropTransforms;
135
- }
136
-
137
- // lib/resolve-all-data.ts
138
- init_react_import();
139
-
140
- // lib/resolve-component-data.ts
141
- init_react_import();
142
-
143
- // lib/get-changed.ts
144
- init_react_import();
145
- var getChanged = (newItem, oldItem) => {
146
- return newItem ? Object.keys(newItem.props || {}).reduce((acc, item) => {
147
- const newItemProps = (newItem == null ? void 0 : newItem.props) || {};
148
- const oldItemProps = (oldItem == null ? void 0 : oldItem.props) || {};
149
- return __spreadProps(__spreadValues({}, acc), {
150
- [item]: oldItemProps[item] !== newItemProps[item]
151
- });
152
- }, {}) : {};
153
- };
154
-
155
- // lib/resolve-component-data.ts
156
- var cache = { lastChange: {} };
157
- var resolveAllComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (content, config, metadata = {}, onResolveStart, onResolveEnd) {
158
- return yield Promise.all(
159
- content.map((item) => __async(void 0, null, function* () {
160
- return yield resolveComponentData(
161
- item,
162
- config,
163
- metadata,
164
- onResolveStart,
165
- onResolveEnd
166
- );
167
- }))
168
- );
169
- });
170
- var resolveComponentData = (_0, _1, ..._2) => __async(void 0, [_0, _1, ..._2], function* (item, config, metadata = {}, onResolveStart, onResolveEnd) {
171
- const configForItem = config.components[item.type];
172
- if (configForItem.resolveData) {
173
- const { item: oldItem = null, resolved = {} } = cache.lastChange[item.props.id] || {};
174
- if (item && item === oldItem) {
175
- return resolved;
176
- }
177
- const changed = getChanged(item, oldItem);
178
- if (onResolveStart) {
179
- onResolveStart(item);
180
- }
181
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, {
182
- changed,
183
- lastData: oldItem,
184
- metadata
185
- });
186
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
187
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
188
- });
189
- if (Object.keys(readOnly).length) {
190
- resolvedItem.readOnly = readOnly;
191
- }
192
- cache.lastChange[item.props.id] = {
193
- item,
194
- resolved: resolvedItem
195
- };
196
- if (onResolveEnd) {
197
- onResolveEnd(resolvedItem);
198
- }
199
- return resolvedItem;
200
- }
201
- return item;
202
- });
203
-
204
- // lib/resolve-root-data.ts
205
- init_react_import();
206
- var cache2 = {};
207
- function resolveRootData(data, config, metadata) {
208
- return __async(this, null, function* () {
209
- var _a, _b, _c, _d, _e;
210
- if (((_a = config.root) == null ? void 0 : _a.resolveData) && data.root.props) {
211
- if (((_b = cache2.lastChange) == null ? void 0 : _b.original) === data.root) {
212
- return cache2.lastChange.resolved;
213
- }
214
- const changed = getChanged(data.root, (_c = cache2.lastChange) == null ? void 0 : _c.original);
215
- const rootWithProps = data.root;
216
- const resolvedRoot = yield (_e = config.root) == null ? void 0 : _e.resolveData(rootWithProps, {
217
- changed,
218
- lastData: ((_d = cache2.lastChange) == null ? void 0 : _d.original) || {},
219
- metadata: metadata || {}
220
- });
221
- cache2.lastChange = {
222
- original: data.root,
223
- resolved: resolvedRoot
224
- };
225
- return __spreadProps(__spreadValues(__spreadValues({}, data.root), resolvedRoot), {
226
- props: __spreadValues(__spreadValues({}, data.root.props), resolvedRoot.props)
227
- });
228
- }
229
- return data.root;
230
- });
231
- }
232
-
233
- // lib/resolve-all-data.ts
234
- function resolveAllData(_0, _1) {
235
- return __async(this, arguments, function* (data, config, metadata = {}, onResolveStart, onResolveEnd) {
236
- const defaultedData = defaultData(data);
237
- const dynamicRoot = yield resolveRootData(
238
- defaultedData,
239
- config,
240
- metadata
241
- );
242
- const { zones = {} } = data;
243
- const zoneKeys = Object.keys(zones);
244
- const resolvedZones = {};
245
- for (let i = 0; i < zoneKeys.length; i++) {
246
- const zoneKey = zoneKeys[i];
247
- resolvedZones[zoneKey] = yield resolveAllComponentData(
248
- zones[zoneKey],
249
- config,
250
- metadata,
251
- onResolveStart,
252
- onResolveEnd
253
- );
254
- }
255
- return __spreadProps(__spreadValues({}, defaultedData), {
256
- root: dynamicRoot,
257
- content: yield resolveAllComponentData(
258
- defaultedData.content,
259
- config,
260
- metadata,
261
- onResolveStart,
262
- onResolveEnd
263
- ),
264
- zones: resolvedZones
265
- });
266
- });
267
- }
268
-
269
- // lib/root-droppable-id.ts
270
- init_react_import();
271
- var rootAreaId = "root";
272
- var rootZone = "default-zone";
273
- var rootDroppableId = `${rootAreaId}:${rootZone}`;
274
-
275
- // lib/setup-zone.ts
276
- init_react_import();
277
- var setupZone = (data, zoneKey) => {
278
- if (zoneKey === rootDroppableId) {
279
- return data;
280
- }
281
- const newData = __spreadProps(__spreadValues({}, data), {
282
- zones: data.zones ? __spreadValues({}, data.zones) : {}
283
- });
284
- newData.zones[zoneKey] = newData.zones[zoneKey] || [];
285
- return newData;
286
- };
287
-
288
- export {
289
- __spreadValues,
290
- __spreadProps,
291
- __objRest,
292
- __commonJS,
293
- __toESM,
294
- __privateGet,
295
- __privateAdd,
296
- __privateSet,
297
- __async,
298
- init_react_import,
299
- rootAreaId,
300
- rootZone,
301
- rootDroppableId,
302
- setupZone,
303
- getChanged,
304
- resolveComponentData,
305
- resolveRootData,
306
- transformProps,
307
- resolveAllData
308
- };