@measured/puck 0.11.0-canary.f9033e2 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -234,33 +234,28 @@ The current DropZone implementation has certain rules and limitations:
234
234
  3. You can't drag between DropZones that don't share a parent (or _area_)
235
235
  4. Your mouse must be directly over a DropZone for a collision to be detected
236
236
 
237
- ## Adaptors
237
+ ## External fields
238
238
 
239
- Adaptors can be used to import data from a third-party API, such as a headless CMS.
239
+ External fields can be used to import data from a third-party API, such as a headless CMS.
240
240
 
241
241
  ### Example
242
242
 
243
- The `external` field type enables us to use an adaptor to query data from a third party API:
243
+ The `external` field type enables us to query data from a third party API:
244
244
 
245
245
  ```tsx
246
- const myAdaptor = {
247
- name: "My adaptor",
248
- fetchList: async () => {
249
- const response = await fetch("https://www.example.com/api");
250
-
251
- return {
252
- text: response.json().text,
253
- };
254
- },
255
- };
256
-
257
246
  const config = {
258
247
  components: {
259
248
  HeadingBlock: {
260
249
  fields: {
261
250
  myData: {
262
251
  type: "external",
263
- adaptor: myAdaptor,
252
+ fetchList: async () => {
253
+ const response = await fetch("https://www.example.com/api");
254
+
255
+ return {
256
+ text: response.json().text,
257
+ };
258
+ },
264
259
  },
265
260
  },
266
261
  render: ({ myData }) => {
@@ -271,7 +266,7 @@ const config = {
271
266
  };
272
267
  ```
273
268
 
274
- When the user interacts with this adaptor, they'll be presented with a list of items to choose from. Once they select an item, the value will be mapped onto the prop. In this case, `myData`.
269
+ When the user interacts with this external field, they'll be presented with a list of items to choose from. Once they select an item, the value will be mapped onto the prop. In this case, `myData`.
275
270
 
276
271
  ## Dynamic prop resolution
277
272
 
@@ -317,29 +312,25 @@ const config = {
317
312
  };
318
313
  ```
319
314
 
320
- ##### Combining with adaptors
315
+ ##### Combining with external fields
321
316
 
322
- A more advanced pattern is to combine the `resolveData` method with the adaptors to dynamically fetch data when rendering the component.
317
+ A more advanced pattern is to combine the `resolveData` method with `external` fields to dynamically fetch data when rendering the component.
323
318
 
324
319
  ```tsx
325
- const myAdaptor = {
326
- name: "My adaptor",
327
- fetchList: async () => {
328
- const response = await fetch("https://www.example.com/api");
329
-
330
- return {
331
- id: response.json().id,
332
- };
333
- },
334
- };
335
-
336
320
  const config = {
337
321
  components: {
338
322
  HeadingBlock: {
339
323
  fields: {
340
324
  myData: {
341
325
  type: "external",
342
- adaptor: myAdaptor,
326
+ placeholder: "Select from example.com",
327
+ fetchList: async () => {
328
+ const response = await fetch("https://www.example.com/api");
329
+
330
+ return {
331
+ id: response.json().id,
332
+ };
333
+ },
343
334
  },
344
335
  title: {
345
336
  type: "text",
@@ -481,14 +472,12 @@ A `Field` represents a user input field shown in the Puck interface.
481
472
 
482
473
  ### External Fields
483
474
 
484
- External fields can be used to load content from an external content repository, like Strapi.js, using an `Adaptor`.
475
+ External fields can be used to load content from an external content repository, like Strapi.js.
485
476
 
486
477
  - **type** (`"external"`)
487
- - **adaptor** (`Adaptor`): Content adaptor responsible for fetching data to show in the table
488
- - **name** (`string`): The human-readable name of the adaptor
489
- - **fetchList** (`(adaptorParams: object) => object`): Fetch content from a third-party API and return an array
490
- - **mapProp** (`(selectedItem: object) => object`): Map the selected item into another shape
491
- - **adaptorParams** (`object`): Paramaters passed to the adaptor
478
+ - **placeholder** (`string`): A placeholder for the external field button
479
+ - **fetchList** (`() => object`): Fetch content from a third-party API and return an array
480
+ - **mapProp** (`(selectedItem: object) => object`): Map the selected item into another shape
492
481
 
493
482
  ### Custom Fields
494
483
 
package/dist/index.css CHANGED
@@ -634,13 +634,13 @@
634
634
  }
635
635
 
636
636
  /* css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css/#css-module-data */
637
- ._ExternalInput_ufl4h_1 {
637
+ ._ExternalInput_z7jih_1 {
638
638
  font-family: var(--puck-font-stack);
639
639
  }
640
- ._ExternalInput-actions_ufl4h_5 {
640
+ ._ExternalInput-actions_z7jih_5 {
641
641
  display: flex;
642
642
  }
643
- ._ExternalInput-button_ufl4h_9 {
643
+ ._ExternalInput-button_z7jih_9 {
644
644
  display: flex;
645
645
  gap: 8px;
646
646
  align-items: center;
@@ -657,20 +657,20 @@
657
657
  overflow: hidden;
658
658
  flex-grow: 1;
659
659
  }
660
- ._ExternalInput-button_ufl4h_9:hover,
661
- ._ExternalInput-detachButton_ufl4h_28:hover {
660
+ ._ExternalInput-button_z7jih_9:hover,
661
+ ._ExternalInput-detachButton_z7jih_28:hover {
662
662
  cursor: pointer;
663
663
  background: var(--puck-color-azure-9);
664
664
  color: var(--puck-color-azure-4);
665
665
  z-index: 1;
666
666
  }
667
- ._ExternalInput--hasData_ufl4h_35 ._ExternalInput-button_ufl4h_9 {
667
+ ._ExternalInput--dataSelected_z7jih_35 ._ExternalInput-button_z7jih_9 {
668
668
  color: var(--puck-color-grey-2);
669
669
  display: block;
670
670
  border-top-right-radius: 0px;
671
671
  border-bottom-right-radius: 0px;
672
672
  }
673
- ._ExternalInput-detachButton_ufl4h_28 {
673
+ ._ExternalInput-detachButton_z7jih_28 {
674
674
  border: 1px solid var(--puck-color-grey-8);
675
675
  border-top-right-radius: 4px;
676
676
  border-bottom-right-radius: 4px;
@@ -683,54 +683,87 @@
683
683
  padding: 8px 12px;
684
684
  margin-left: -1px;
685
685
  }
686
- ._ExternalInput-masthead_ufl4h_56 {
686
+ ._ExternalInputModal_z7jih_56 {
687
+ display: flex;
688
+ flex-direction: column;
689
+ position: relative;
690
+ max-height: 90vh;
691
+ }
692
+ ._ExternalInputModal-masthead_z7jih_63 {
687
693
  background-color: white;
688
694
  padding: 32px 24px;
689
695
  }
690
- ._ExternalInput-modalTableWrapper_ufl4h_61 {
691
- overflow-x: scroll;
692
- overflow-y: scroll;
696
+ ._ExternalInputModal-tableWrapper_z7jih_68 {
697
+ overflow-x: auto;
698
+ overflow-y: auto;
693
699
  flex-grow: 1;
694
700
  }
695
- ._ExternalInput-table_ufl4h_67 {
701
+ ._ExternalInputModal-table_z7jih_68 {
702
+ border-collapse: unset;
696
703
  border-spacing: 0px;
697
704
  color: var(--puck-color-neutral-4);
698
705
  position: relative;
706
+ z-index: 0;
699
707
  }
700
- ._ExternalInput-table_ufl4h_67 thead {
708
+ ._ExternalInputModal-thead_z7jih_82 {
701
709
  position: sticky;
702
710
  top: 0;
711
+ z-index: 1;
703
712
  }
704
- ._ExternalInput-table_ufl4h_67 th {
713
+ ._ExternalInputModal-th_z7jih_82 {
705
714
  border-bottom: 1px solid var(--puck-color-grey-8);
706
715
  border-top: 1px solid var(--puck-color-grey-8);
707
716
  font-weight: 700;
708
717
  padding: 16px 24px;
709
718
  opacity: 0.9;
710
719
  }
711
- ._ExternalInput-table_ufl4h_67 td {
720
+ ._ExternalInputModal-td_z7jih_96 {
721
+ font-family: var(--puck-font-stack);
712
722
  padding: 16px 24px;
713
723
  }
714
- ._ExternalInput-table_ufl4h_67 tr:nth-of-type(n) {
724
+ ._ExternalInputModal-tr_z7jih_101:nth-of-type(n) {
715
725
  background-color: white;
716
726
  }
717
- ._ExternalInput-table_ufl4h_67 tr:nth-of-type(2n) {
727
+ ._ExternalInputModal-tr_z7jih_101:nth-of-type(2n) {
718
728
  background-color: var(--puck-color-grey-10);
719
729
  }
720
- ._ExternalInput-table_ufl4h_67 tr td:first-of-type {
730
+ ._ExternalInputModal-tr_z7jih_101 ._ExternalInputModal-td_z7jih_96:first-of-type {
721
731
  font-weight: 500;
722
732
  }
723
- ._ExternalInput-table_ufl4h_67 tbody tr:hover {
733
+ ._ExternalInputModal-tbody_z7jih_113 ._ExternalInputModal-tr_z7jih_101:hover {
724
734
  background: var(--puck-color-grey-11);
725
735
  color: var(--puck-color-azure-4);
726
736
  cursor: pointer;
727
737
  position: relative;
728
738
  margin-left: -5px;
729
739
  }
730
- ._ExternalInput-table_ufl4h_67 tbody tr:hover td:first-of-type {
740
+ ._ExternalInputModal-tbody_z7jih_113 ._ExternalInputModal-tr_z7jih_101:hover ._ExternalInputModal-td_z7jih_96:first-of-type {
731
741
  border-left: 4px solid var(--puck-color-azure-4);
732
742
  padding-left: 20px;
733
743
  }
744
+ ._ExternalInputModal-tableWrapper_z7jih_68 {
745
+ display: none;
746
+ }
747
+ ._ExternalInputModal--hasData_z7jih_132 ._ExternalInputModal-tableWrapper_z7jih_68 {
748
+ display: block;
749
+ }
750
+ ._ExternalInputModal-loadingBanner_z7jih_136 {
751
+ display: none;
752
+ background-color: white;
753
+ padding: 64px;
754
+ align-items: center;
755
+ justify-content: center;
756
+ }
757
+ ._ExternalInputModal--isLoading_z7jih_144 ._ExternalInputModal-loadingBanner_z7jih_136 {
758
+ display: flex;
759
+ }
760
+ ._ExternalInputModal-noContentBanner_z7jih_148 {
761
+ display: none;
762
+ }
763
+ ._ExternalInputModal--loaded_z7jih_152:not(._ExternalInputModal--hasData_z7jih_132) ._ExternalInputModal-noContentBanner_z7jih_148 {
764
+ display: block;
765
+ padding: 24px;
766
+ }
734
767
 
735
768
  /* css-module:/home/runner/work/puck/puck/packages/core/components/Modal/styles.module.css/#css-module-data */
736
769
  ._Modal_hx2u6_1 {
@@ -761,41 +794,40 @@
761
794
  }
762
795
 
763
796
  /* css-module:/home/runner/work/puck/puck/packages/core/components/Heading/styles.module.css/#css-module-data */
764
- ._Heading_7sjz7_1 {
797
+ ._Heading_1bvy5_1 {
765
798
  display: block;
766
799
  color: var(--puck-color-black);
767
800
  font-family: var(--puck-font-stack);
768
801
  font-weight: 700;
769
802
  margin: 0;
770
- word-break: break-word;
771
803
  }
772
- ._Heading_7sjz7_1 b {
804
+ ._Heading_1bvy5_1 b {
773
805
  font-weight: 700;
774
806
  }
775
- ._Heading--xxxxl_7sjz7_14 {
807
+ ._Heading--xxxxl_1bvy5_13 {
776
808
  font-size: var(--puck-font-size-xxxxl);
777
809
  letter-spacing: 0.08ch;
778
810
  font-weight: 800;
779
811
  }
780
- ._Heading--xxxl_7sjz7_20 {
812
+ ._Heading--xxxl_1bvy5_19 {
781
813
  font-size: var(--puck-font-size-xxxl);
782
814
  }
783
- ._Heading--xxl_7sjz7_24 {
815
+ ._Heading--xxl_1bvy5_23 {
784
816
  font-size: var(--puck-font-size-xxl);
785
817
  }
786
- ._Heading--xl_7sjz7_28 {
818
+ ._Heading--xl_1bvy5_27 {
787
819
  font-size: var(--puck-font-size-xl);
788
820
  }
789
- ._Heading--l_7sjz7_32 {
821
+ ._Heading--l_1bvy5_31 {
790
822
  font-size: var(--puck-font-size-l);
791
823
  }
792
- ._Heading--m_7sjz7_36 {
824
+ ._Heading--m_1bvy5_35 {
793
825
  font-size: var(--puck-font-size-m);
794
826
  }
795
- ._Heading--s_7sjz7_40 {
827
+ ._Heading--s_1bvy5_39 {
796
828
  font-size: var(--puck-font-size-s);
797
829
  }
798
- ._Heading--xs_7sjz7_44 {
830
+ ._Heading--xs_1bvy5_43 {
799
831
  font-size: var(--puck-font-size-xs);
800
832
  }
801
833
 
package/dist/index.d.ts CHANGED
@@ -8,11 +8,6 @@ type ItemSelector = {
8
8
  zone?: string;
9
9
  };
10
10
 
11
- type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
12
- name: string;
13
- fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
14
- mapProp?: (value: TableShape) => PropShape;
15
- };
16
11
  type WithPuckProps<Props> = Props & {
17
12
  id: string;
18
13
  };
@@ -41,16 +36,33 @@ type ArrayField<Props extends {
41
36
  defaultItemProps?: Props[0];
42
37
  getItemSummary?: (item: Props[0], index?: number) => string;
43
38
  };
44
- type ExternalField<Props extends {
39
+ type Adaptor<AdaptorParams = {}, TableShape extends Record<string, any> = {}, PropShape = TableShape> = {
40
+ name: string;
41
+ fetchList: (adaptorParams?: AdaptorParams) => Promise<TableShape[] | null>;
42
+ mapProp?: (value: TableShape) => PropShape;
43
+ };
44
+ type ExternalFieldWithAdaptor<Props extends {
45
45
  [key: string]: any;
46
46
  } = {
47
47
  [key: string]: any;
48
48
  }> = BaseField & {
49
49
  type: "external";
50
+ placeholder?: string;
50
51
  adaptor: Adaptor<any, any, Props>;
51
52
  adaptorParams?: object;
52
53
  getItemSummary: (item: Props, index?: number) => string;
53
54
  };
55
+ type ExternalField<Props extends {
56
+ [key: string]: any;
57
+ } = {
58
+ [key: string]: any;
59
+ }> = BaseField & {
60
+ type: "external";
61
+ placeholder?: string;
62
+ fetchList: () => Promise<any[] | null>;
63
+ mapProp?: (value: any) => Props;
64
+ getItemSummary: (item: Props, index?: number) => string;
65
+ };
54
66
  type CustomField<Props extends {
55
67
  [key: string]: any;
56
68
  } = {
@@ -69,7 +81,7 @@ type Field<Props extends {
69
81
  [key: string]: any;
70
82
  } = {
71
83
  [key: string]: any;
72
- }> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | CustomField;
84
+ }> = TextField | SelectField | ArrayField<Props> | ExternalField<Props> | ExternalFieldWithAdaptor<Props> | CustomField;
73
85
  type DefaultRootProps = {
74
86
  title?: string;
75
87
  [key: string]: any;
@@ -362,4 +374,4 @@ declare const FieldLabel: ({ children, icon, label, el, readOnly, className, }:
362
374
  className?: string | undefined;
363
375
  }) => react_jsx_runtime.JSX.Element;
364
376
 
365
- export { Adaptor, AppState, ArrayField, ArrayState, BaseData, BaseField, Button, ComponentConfig, ComponentData, Config, Content, CustomField, Data, DefaultComponentProps, DefaultRootProps, DefaultRootRenderProps, DropZone, DropZoneProvider, ExternalField, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, RootData, RootDataWithProps, RootDataWithoutProps, SelectField, TextField, UiState, dropZoneContext, resolveAllData };
377
+ export { Adaptor, AppState, ArrayField, ArrayState, BaseData, BaseField, Button, ComponentConfig, ComponentData, Config, Content, CustomField, Data, DefaultComponentProps, DefaultRootProps, DefaultRootRenderProps, DropZone, DropZoneProvider, ExternalField, ExternalFieldWithAdaptor, Field, FieldLabel, Fields, IconButton, ItemWithId, MappedItem, Puck, Render, RootData, RootDataWithProps, RootDataWithoutProps, SelectField, TextField, UiState, dropZoneContext, resolveAllData };
package/dist/index.js CHANGED
@@ -32372,7 +32372,7 @@ var IconButton = ({
32372
32372
 
32373
32373
  // components/Puck/index.tsx
32374
32374
  init_react_import();
32375
- var import_react37 = require("react");
32375
+ var import_react39 = require("react");
32376
32376
  var import_react_beautiful_dnd5 = require("react-beautiful-dnd");
32377
32377
 
32378
32378
  // components/InputOrGroup/index.tsx
@@ -32382,6 +32382,9 @@ init_react_import();
32382
32382
  init_react_import();
32383
32383
  var styles_module_default3 = { "Input": "_Input_1kw16_1", "Input-label": "_Input-label_1kw16_27", "Input-labelIcon": "_Input-labelIcon_1kw16_34", "Input-disabledIcon": "_Input-disabledIcon_1kw16_40", "Input-input": "_Input-input_1kw16_45", "Input--readOnly": "_Input--readOnly_1kw16_66", "Input-radioGroupItems": "_Input-radioGroupItems_1kw16_78", "Input-radio": "_Input-radio_1kw16_78", "Input-radioInner": "_Input-radioInner_1kw16_95", "Input-radioInput": "_Input-radioInput_1kw16_117" };
32384
32384
 
32385
+ // components/InputOrGroup/index.tsx
32386
+ var import_react31 = require("react");
32387
+
32385
32388
  // components/InputOrGroup/fields/index.tsx
32386
32389
  init_react_import();
32387
32390
 
@@ -32701,6 +32704,7 @@ var DefaultField = ({
32701
32704
 
32702
32705
  // components/InputOrGroup/fields/ExternalField/index.tsx
32703
32706
  init_react_import();
32707
+ var import_react30 = require("react");
32704
32708
 
32705
32709
  // components/ExternalInput/index.tsx
32706
32710
  init_react_import();
@@ -32708,7 +32712,7 @@ var import_react29 = require("react");
32708
32712
 
32709
32713
  // css-module:/home/runner/work/puck/puck/packages/core/components/ExternalInput/styles.module.css#css-module
32710
32714
  init_react_import();
32711
- var styles_module_default6 = { "ExternalInput": "_ExternalInput_ufl4h_1", "ExternalInput-actions": "_ExternalInput-actions_ufl4h_5", "ExternalInput-button": "_ExternalInput-button_ufl4h_9", "ExternalInput-detachButton": "_ExternalInput-detachButton_ufl4h_28", "ExternalInput--hasData": "_ExternalInput--hasData_ufl4h_35", "ExternalInput-masthead": "_ExternalInput-masthead_ufl4h_56", "ExternalInput-modalTableWrapper": "_ExternalInput-modalTableWrapper_ufl4h_61", "ExternalInput-table": "_ExternalInput-table_ufl4h_67" };
32715
+ var styles_module_default6 = { "ExternalInput": "_ExternalInput_z7jih_1", "ExternalInput-actions": "_ExternalInput-actions_z7jih_5", "ExternalInput-button": "_ExternalInput-button_z7jih_9", "ExternalInput-detachButton": "_ExternalInput-detachButton_z7jih_28", "ExternalInput--dataSelected": "_ExternalInput--dataSelected_z7jih_35", "ExternalInputModal": "_ExternalInputModal_z7jih_56", "ExternalInputModal-masthead": "_ExternalInputModal-masthead_z7jih_63", "ExternalInputModal-tableWrapper": "_ExternalInputModal-tableWrapper_z7jih_68", "ExternalInputModal-table": "_ExternalInputModal-table_z7jih_68", "ExternalInputModal-thead": "_ExternalInputModal-thead_z7jih_82", "ExternalInputModal-th": "_ExternalInputModal-th_z7jih_82", "ExternalInputModal-td": "_ExternalInputModal-td_z7jih_96", "ExternalInputModal-tr": "_ExternalInputModal-tr_z7jih_101", "ExternalInputModal-tbody": "_ExternalInputModal-tbody_z7jih_113", "ExternalInputModal--hasData": "_ExternalInputModal--hasData_z7jih_132", "ExternalInputModal-loadingBanner": "_ExternalInputModal-loadingBanner_z7jih_136", "ExternalInputModal--isLoading": "_ExternalInputModal--isLoading_z7jih_144", "ExternalInputModal-noContentBanner": "_ExternalInputModal-noContentBanner_z7jih_148", "ExternalInputModal--loaded": "_ExternalInputModal--loaded_z7jih_152" };
32712
32716
 
32713
32717
  // components/Modal/index.tsx
32714
32718
  init_react_import();
@@ -32748,7 +32752,7 @@ init_react_import();
32748
32752
 
32749
32753
  // css-module:/home/runner/work/puck/puck/packages/core/components/Heading/styles.module.css#css-module
32750
32754
  init_react_import();
32751
- var styles_module_default8 = { "Heading": "_Heading_7sjz7_1", "Heading--xxxxl": "_Heading--xxxxl_7sjz7_14", "Heading--xxxl": "_Heading--xxxl_7sjz7_20", "Heading--xxl": "_Heading--xxl_7sjz7_24", "Heading--xl": "_Heading--xl_7sjz7_28", "Heading--l": "_Heading--l_7sjz7_32", "Heading--m": "_Heading--m_7sjz7_36", "Heading--s": "_Heading--s_7sjz7_40", "Heading--xs": "_Heading--xs_7sjz7_44" };
32755
+ var styles_module_default8 = { "Heading": "_Heading_1bvy5_1", "Heading--xxxxl": "_Heading--xxxxl_1bvy5_13", "Heading--xxxl": "_Heading--xxxl_1bvy5_19", "Heading--xxl": "_Heading--xxl_1bvy5_23", "Heading--xl": "_Heading--xl_1bvy5_27", "Heading--l": "_Heading--l_1bvy5_31", "Heading--m": "_Heading--m_1bvy5_35", "Heading--s": "_Heading--s_1bvy5_39", "Heading--xs": "_Heading--xs_1bvy5_43" };
32752
32756
 
32753
32757
  // components/Heading/index.tsx
32754
32758
  var import_jsx_runtime12 = require("react/jsx-runtime");
@@ -32767,17 +32771,21 @@ var Heading = ({ children, rank, size = "m" }) => {
32767
32771
  };
32768
32772
 
32769
32773
  // components/ExternalInput/index.tsx
32774
+ var import_react_spinners4 = require("react-spinners");
32770
32775
  var import_jsx_runtime13 = require("react/jsx-runtime");
32771
32776
  var getClassName10 = get_class_name_factory_default("ExternalInput", styles_module_default6);
32777
+ var getClassNameModal = get_class_name_factory_default("ExternalInputModal", styles_module_default6);
32778
+ var dataCache = {};
32772
32779
  var ExternalInput = ({
32773
32780
  field,
32774
32781
  onChange,
32775
- value = null
32782
+ value = null,
32783
+ name
32776
32784
  }) => {
32777
- const { mapProp = (val) => val } = field.adaptor || {};
32785
+ const { mapProp = (val) => val } = field || {};
32778
32786
  const [data, setData] = (0, import_react29.useState)([]);
32779
32787
  const [isOpen, setOpen] = (0, import_react29.useState)(false);
32780
- const [selectedData, setSelectedData] = (0, import_react29.useState)(value);
32788
+ const [isLoading, setIsLoading] = (0, import_react29.useState)(true);
32781
32789
  const keys = (0, import_react29.useMemo)(() => {
32782
32790
  const validKeys = /* @__PURE__ */ new Set();
32783
32791
  for (const item of data) {
@@ -32791,22 +32799,19 @@ var ExternalInput = ({
32791
32799
  }, [data]);
32792
32800
  (0, import_react29.useEffect)(() => {
32793
32801
  (() => __async(void 0, null, function* () {
32794
- if (field.adaptor) {
32795
- const listData = yield field.adaptor.fetchList(field.adaptorParams);
32796
- if (listData) {
32797
- setData(listData);
32798
- }
32802
+ const listData = dataCache[name] || (yield field.fetchList());
32803
+ if (listData) {
32804
+ setData(listData);
32805
+ setIsLoading(false);
32806
+ dataCache[name] = listData;
32799
32807
  }
32800
32808
  }))();
32801
- }, [field.adaptor, field.adaptorParams]);
32802
- if (!field.adaptor) {
32803
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { children: "Incorrectly configured" });
32804
- }
32809
+ }, []);
32805
32810
  return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
32806
32811
  "div",
32807
32812
  {
32808
32813
  className: getClassName10({
32809
- hasData: !!selectedData,
32814
+ dataSelected: !!value,
32810
32815
  modalVisible: isOpen
32811
32816
  }),
32812
32817
  children: [
@@ -32816,48 +32821,64 @@ var ExternalInput = ({
32816
32821
  {
32817
32822
  onClick: () => setOpen(true),
32818
32823
  className: getClassName10("button"),
32819
- children: selectedData ? field.getItemSummary ? field.getItemSummary(selectedData) : `${field.adaptor.name} item` : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
32824
+ children: value ? field.getItemSummary ? field.getItemSummary(value) : "External item" : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
32820
32825
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(link_default, { size: "16" }),
32821
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
32822
- "Select from ",
32823
- field.adaptor.name
32824
- ] })
32826
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: field.placeholder })
32825
32827
  ] })
32826
32828
  }
32827
32829
  ),
32828
- selectedData && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
32830
+ value && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
32829
32831
  "button",
32830
32832
  {
32831
32833
  className: getClassName10("detachButton"),
32832
32834
  onClick: () => {
32833
- setSelectedData(null);
32834
32835
  onChange(null);
32835
32836
  },
32836
32837
  children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(unlock_default, { size: 16 })
32837
32838
  }
32838
32839
  )
32839
32840
  ] }),
32840
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(Modal, { onClose: () => setOpen(false), isOpen, children: [
32841
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassName10("masthead"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Heading, { rank: 2, size: "xxl", children: "Select content" }) }),
32842
- data.length ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassName10("modalTableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("table", { className: getClassName10("table"), children: [
32843
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tr", { children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { style: { textAlign: "left" }, children: key }, key)) }) }),
32844
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tbody", { children: data.map((item, i) => {
32845
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
32846
- "tr",
32847
- {
32848
- style: { whiteSpace: "nowrap" },
32849
- onClick: (e) => {
32850
- onChange(mapProp(item));
32851
- setOpen(false);
32852
- setSelectedData(mapProp(item));
32841
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Modal, { onClose: () => setOpen(false), isOpen, children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
32842
+ "div",
32843
+ {
32844
+ className: getClassNameModal({
32845
+ isLoading,
32846
+ loaded: !isLoading,
32847
+ hasData: !!data
32848
+ }),
32849
+ children: [
32850
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassNameModal("masthead"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(Heading, { rank: 2, size: "xxl", children: "Select content" }) }),
32851
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassNameModal("tableWrapper"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("table", { className: getClassNameModal("table"), children: [
32852
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("thead", { className: getClassNameModal("thead"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tr", { className: getClassNameModal("tr"), children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
32853
+ "th",
32854
+ {
32855
+ className: getClassNameModal("th"),
32856
+ style: { textAlign: "left" },
32857
+ children: key
32853
32858
  },
32854
- children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { children: item[key] }, key))
32855
- },
32856
- i
32857
- );
32858
- }) })
32859
- ] }) }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { style: { padding: 24 }, children: "No content" })
32860
- ] })
32859
+ key
32860
+ )) }) }),
32861
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tbody", { className: getClassNameModal("tbody"), children: data.map((item, i) => {
32862
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
32863
+ "tr",
32864
+ {
32865
+ style: { whiteSpace: "nowrap" },
32866
+ className: getClassNameModal("tr"),
32867
+ onClick: (e) => {
32868
+ onChange(mapProp(item));
32869
+ setOpen(false);
32870
+ },
32871
+ children: keys.map((key) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: getClassNameModal("td"), children: item[key] }, key))
32872
+ },
32873
+ i
32874
+ );
32875
+ }) })
32876
+ ] }) }),
32877
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassNameModal("noContentBanner"), children: "No content" }),
32878
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: getClassNameModal("loadingBanner"), children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_react_spinners4.ClipLoader, { size: 24 }) })
32879
+ ]
32880
+ }
32881
+ ) })
32861
32882
  ]
32862
32883
  }
32863
32884
  );
@@ -32872,7 +32893,17 @@ var ExternalField = ({
32872
32893
  name,
32873
32894
  label
32874
32895
  }) => {
32875
- if (field.type !== "external" || !field.adaptor) {
32896
+ var _a, _b, _c;
32897
+ const validField = field;
32898
+ const deprecatedField = field;
32899
+ (0, import_react30.useEffect)(() => {
32900
+ if (deprecatedField.adaptor) {
32901
+ console.error(
32902
+ "Warning: The `adaptor` API is deprecated. Please use updated APIs on the `external` field instead. This will be a breaking change in a future release."
32903
+ );
32904
+ }
32905
+ }, []);
32906
+ if (field.type !== "external") {
32876
32907
  return null;
32877
32908
  }
32878
32909
  return /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
@@ -32881,7 +32912,24 @@ var ExternalField = ({
32881
32912
  label: label || name,
32882
32913
  icon: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(link_default, { size: 16 }),
32883
32914
  el: "div",
32884
- children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(ExternalInput, { field, onChange, value })
32915
+ children: /* @__PURE__ */ (0, import_jsx_runtime14.jsx)(
32916
+ ExternalInput,
32917
+ {
32918
+ name,
32919
+ field: __spreadProps(__spreadValues({}, validField), {
32920
+ // DEPRECATED
32921
+ placeholder: ((_a = deprecatedField.adaptor) == null ? void 0 : _a.name) ? `Select from ${deprecatedField.adaptor.name}` : validField.placeholder,
32922
+ mapProp: ((_b = deprecatedField.adaptor) == null ? void 0 : _b.mapProp) || validField.mapProp,
32923
+ fetchList: ((_c = deprecatedField.adaptor) == null ? void 0 : _c.fetchList) ? () => __async(void 0, null, function* () {
32924
+ return yield deprecatedField.adaptor.fetchList(
32925
+ deprecatedField.adaptorParams
32926
+ );
32927
+ }) : validField.fetchList
32928
+ }),
32929
+ onChange,
32930
+ value
32931
+ }
32932
+ )
32885
32933
  }
32886
32934
  );
32887
32935
  };
@@ -33021,6 +33069,7 @@ var TextareaField = ({
33021
33069
  };
33022
33070
 
33023
33071
  // components/InputOrGroup/index.tsx
33072
+ var import_use_debounce2 = require("use-debounce");
33024
33073
  var import_jsx_runtime18 = require("react/jsx-runtime");
33025
33074
  var getClassName14 = get_class_name_factory_default("Input", styles_module_default3);
33026
33075
  var FieldLabel = ({
@@ -33061,36 +33110,52 @@ var FieldLabelInternal = ({
33061
33110
  }
33062
33111
  );
33063
33112
  };
33064
- var InputOrGroup = (props) => {
33065
- const { name, field, value, onChange, readOnly } = props;
33113
+ var InputOrGroup = (_a) => {
33114
+ var _b = _a, { onChange } = _b, props = __objRest(_b, ["onChange"]);
33115
+ const { name, field, value, readOnly } = props;
33116
+ const [localValue, setLocalValue] = (0, import_react31.useState)(value);
33117
+ const [localValueDb] = (0, import_use_debounce2.useDebounce)(localValue, 50, { leading: true });
33118
+ (0, import_react31.useEffect)(() => {
33119
+ if (value !== localValueDb) {
33120
+ onChange(localValueDb);
33121
+ }
33122
+ }, [localValueDb]);
33123
+ const onChangeLocal = (0, import_react31.useCallback)((val) => {
33124
+ setLocalValue(val);
33125
+ }, []);
33126
+ (0, import_react31.useEffect)(() => {
33127
+ setLocalValue(value);
33128
+ }, [value]);
33129
+ const localProps = {
33130
+ value: localValue,
33131
+ onChange: onChangeLocal
33132
+ };
33066
33133
  if (field.type === "array") {
33067
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ArrayField, __spreadValues({}, props));
33134
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ArrayField, __spreadValues(__spreadValues({}, props), localProps));
33068
33135
  }
33069
33136
  if (field.type === "external") {
33070
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ExternalField, __spreadValues({}, props));
33137
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(ExternalField, __spreadValues(__spreadValues({}, props), localProps));
33071
33138
  }
33072
33139
  if (field.type === "select") {
33073
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SelectField, __spreadValues({}, props));
33140
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(SelectField, __spreadValues(__spreadValues({}, props), localProps));
33074
33141
  }
33075
33142
  if (field.type === "textarea") {
33076
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TextareaField, __spreadValues({}, props));
33143
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(TextareaField, __spreadValues(__spreadValues({}, props), localProps));
33077
33144
  }
33078
33145
  if (field.type === "radio") {
33079
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RadioField, __spreadValues({}, props));
33146
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(RadioField, __spreadValues(__spreadValues({}, props), localProps));
33080
33147
  }
33081
33148
  if (field.type === "custom") {
33082
33149
  if (!field.render) {
33083
33150
  return null;
33084
33151
  }
33085
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: getClassName14(), children: field.render({
33152
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)("div", { className: getClassName14(), children: field.render(__spreadValues({
33086
33153
  field,
33087
33154
  name,
33088
- value,
33089
- onChange,
33090
33155
  readOnly
33091
- }) });
33156
+ }, localProps)) });
33092
33157
  }
33093
- return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DefaultField, __spreadValues({}, props));
33158
+ return /* @__PURE__ */ (0, import_jsx_runtime18.jsx)(DefaultField, __spreadValues(__spreadValues({}, props), localProps));
33094
33159
  };
33095
33160
 
33096
33161
  // components/ComponentList/index.tsx
@@ -33187,10 +33252,10 @@ ComponentList.Item = ComponentListItem;
33187
33252
 
33188
33253
  // lib/use-placeholder-style.ts
33189
33254
  init_react_import();
33190
- var import_react30 = require("react");
33255
+ var import_react32 = require("react");
33191
33256
  var usePlaceholderStyle = () => {
33192
33257
  const queryAttr = "data-rbd-drag-handle-draggable-id";
33193
- const [placeholderStyle, setPlaceholderStyle] = (0, import_react30.useState)();
33258
+ const [placeholderStyle, setPlaceholderStyle] = (0, import_react32.useState)();
33194
33259
  const onDragStartOrUpdate = (draggedItem) => {
33195
33260
  var _a;
33196
33261
  const draggableId = draggedItem.draggableId;
@@ -33242,7 +33307,7 @@ var styles_module_default10 = { "SidebarSection": "_SidebarSection_r7dv3_1", "Si
33242
33307
 
33243
33308
  // lib/use-breadcrumbs.ts
33244
33309
  init_react_import();
33245
- var import_react31 = require("react");
33310
+ var import_react33 = require("react");
33246
33311
  var convertPathDataToBreadcrumbs = (selectedItem, pathData, data) => {
33247
33312
  const id = selectedItem ? selectedItem == null ? void 0 : selectedItem.props.id : "";
33248
33313
  const currentPathData = pathData && id && pathData[id] ? __spreadValues({}, pathData[id]) : { label: "Page", path: [] };
@@ -33292,8 +33357,8 @@ var useBreadcrumbs = (renderCount) => {
33292
33357
  state: { data },
33293
33358
  selectedItem
33294
33359
  } = useAppContext();
33295
- const dzContext = (0, import_react31.useContext)(dropZoneContext);
33296
- return (0, import_react31.useMemo)(() => {
33360
+ const dzContext = (0, import_react33.useContext)(dropZoneContext);
33361
+ return (0, import_react33.useMemo)(() => {
33297
33362
  const breadcrumbs = convertPathDataToBreadcrumbs(
33298
33363
  selectedItem,
33299
33364
  dzContext == null ? void 0 : dzContext.pathData,
@@ -33307,7 +33372,7 @@ var useBreadcrumbs = (renderCount) => {
33307
33372
  };
33308
33373
 
33309
33374
  // components/SidebarSection/index.tsx
33310
- var import_react_spinners4 = require("react-spinners");
33375
+ var import_react_spinners5 = require("react-spinners");
33311
33376
  var import_jsx_runtime20 = require("react/jsx-runtime");
33312
33377
  var getClassName16 = get_class_name_factory_default("SidebarSection", styles_module_default10);
33313
33378
  var SidebarSection = ({
@@ -33336,7 +33401,7 @@ var SidebarSection = ({
33336
33401
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName16("heading"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(Heading, { rank: 2, size: "xs", children: title }) })
33337
33402
  ] }) }),
33338
33403
  /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName16("content"), children }),
33339
- isLoading && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_spinners4.ClipLoader, {}) })
33404
+ isLoading && /* @__PURE__ */ (0, import_jsx_runtime20.jsx)("div", { className: getClassName16("loadingOverlay"), children: /* @__PURE__ */ (0, import_jsx_runtime20.jsx)(import_react_spinners5.ClipLoader, {}) })
33340
33405
  ] });
33341
33406
  };
33342
33407
 
@@ -33345,21 +33410,21 @@ init_react_import();
33345
33410
 
33346
33411
  // lib/use-puck-history.ts
33347
33412
  init_react_import();
33348
- var import_react33 = require("react");
33413
+ var import_react35 = require("react");
33349
33414
 
33350
33415
  // lib/use-action-history.ts
33351
33416
  init_react_import();
33352
- var import_react32 = require("react");
33417
+ var import_react34 = require("react");
33353
33418
  var EMPTY_HISTORY_INDEX = -1;
33354
33419
  function useActionHistory() {
33355
- const [histories, setHistories] = (0, import_react32.useState)([]);
33356
- const [currentHistoryIndex, setCurrentHistoryIndex] = (0, import_react32.useState)(EMPTY_HISTORY_INDEX);
33420
+ const [histories, setHistories] = (0, import_react34.useState)([]);
33421
+ const [currentHistoryIndex, setCurrentHistoryIndex] = (0, import_react34.useState)(EMPTY_HISTORY_INDEX);
33357
33422
  const currentHistory = histories[currentHistoryIndex];
33358
33423
  const canRewind = currentHistoryIndex > EMPTY_HISTORY_INDEX;
33359
33424
  const canForward = currentHistoryIndex < histories.length - 1;
33360
33425
  const record = (params) => {
33361
33426
  const history = __spreadValues({
33362
- id: Math.random().toString()
33427
+ id: generateId("history")
33363
33428
  }, params);
33364
33429
  setHistories((prev) => [
33365
33430
  ...prev.slice(0, currentHistoryIndex + 1),
@@ -33393,7 +33458,7 @@ function useActionHistory() {
33393
33458
  // lib/use-puck-history.ts
33394
33459
  var import_react_hotkeys_hook = require("react-hotkeys-hook");
33395
33460
  var import_event_emitter = __toESM(require("event-emitter"));
33396
- var import_use_debounce2 = require("use-debounce");
33461
+ var import_use_debounce3 = require("use-debounce");
33397
33462
  var DEBOUNCE_TIME = 250;
33398
33463
  var RECORD_DIFF = "RECORD_DIFF";
33399
33464
  var historyEmitter = (0, import_event_emitter.default)();
@@ -33423,8 +33488,8 @@ function usePuckHistory({
33423
33488
  (0, import_react_hotkeys_hook.useHotkeys)("meta+z", rewind, { preventDefault: true });
33424
33489
  (0, import_react_hotkeys_hook.useHotkeys)("meta+shift+z", forward, { preventDefault: true });
33425
33490
  (0, import_react_hotkeys_hook.useHotkeys)("meta+y", forward, { preventDefault: true });
33426
- const [snapshot] = (0, import_use_debounce2.useDebounce)(appState, DEBOUNCE_TIME);
33427
- const handleRecordDiff = (0, import_use_debounce2.useDebouncedCallback)((newAppState) => {
33491
+ const [snapshot] = (0, import_use_debounce3.useDebounce)(appState, DEBOUNCE_TIME);
33492
+ const handleRecordDiff = (0, import_use_debounce3.useDebouncedCallback)((newAppState) => {
33428
33493
  return _recordHistory({
33429
33494
  snapshot,
33430
33495
  newSnapshot: newAppState,
@@ -33432,7 +33497,7 @@ function usePuckHistory({
33432
33497
  dispatch
33433
33498
  });
33434
33499
  }, DEBOUNCE_TIME);
33435
- (0, import_react33.useEffect)(() => {
33500
+ (0, import_react35.useEffect)(() => {
33436
33501
  historyEmitter.on(RECORD_DIFF, handleRecordDiff);
33437
33502
  return () => {
33438
33503
  historyEmitter.off(RECORD_DIFF, handleRecordDiff);
@@ -33534,6 +33599,23 @@ var zoneCache = {};
33534
33599
  var addToZoneCache = (key, data) => {
33535
33600
  zoneCache[key] = data;
33536
33601
  };
33602
+ var replaceAction = (data, action) => {
33603
+ if (action.destinationZone === rootDroppableId) {
33604
+ return __spreadProps(__spreadValues({}, data), {
33605
+ content: replace(data.content, action.destinationIndex, action.data)
33606
+ });
33607
+ }
33608
+ const newData = setupZone(data, action.destinationZone);
33609
+ return __spreadProps(__spreadValues({}, newData), {
33610
+ zones: __spreadProps(__spreadValues({}, newData.zones), {
33611
+ [action.destinationZone]: replace(
33612
+ newData.zones[action.destinationZone],
33613
+ action.destinationIndex,
33614
+ action.data
33615
+ )
33616
+ })
33617
+ });
33618
+ };
33537
33619
  var reduceData = (data, action, config) => {
33538
33620
  if (action.type === "insert") {
33539
33621
  const emptyComponentData = {
@@ -33660,21 +33742,7 @@ var reduceData = (data, action, config) => {
33660
33742
  });
33661
33743
  }
33662
33744
  if (action.type === "replace") {
33663
- if (action.destinationZone === rootDroppableId) {
33664
- return __spreadProps(__spreadValues({}, data), {
33665
- content: replace(data.content, action.destinationIndex, action.data)
33666
- });
33667
- }
33668
- const newData = setupZone(data, action.destinationZone);
33669
- return __spreadProps(__spreadValues({}, newData), {
33670
- zones: __spreadProps(__spreadValues({}, newData.zones), {
33671
- [action.destinationZone]: replace(
33672
- newData.zones[action.destinationZone],
33673
- action.destinationIndex,
33674
- action.data
33675
- )
33676
- })
33677
- });
33745
+ return replaceAction(data, action);
33678
33746
  }
33679
33747
  if (action.type === "remove") {
33680
33748
  const item = getItem({ index: action.index, zone: action.zone }, data);
@@ -33785,7 +33853,7 @@ var scrollIntoView = (el) => {
33785
33853
  };
33786
33854
 
33787
33855
  // components/LayerTree/index.tsx
33788
- var import_react34 = require("react");
33856
+ var import_react36 = require("react");
33789
33857
 
33790
33858
  // lib/find-zones-for-area.ts
33791
33859
  init_react_import();
@@ -33823,7 +33891,7 @@ var LayerTree = ({
33823
33891
  label
33824
33892
  }) => {
33825
33893
  const zones = data.zones || {};
33826
- const ctx = (0, import_react34.useContext)(dropZoneContext);
33894
+ const ctx = (0, import_react36.useContext)(dropZoneContext);
33827
33895
  return /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)(import_jsx_runtime21.Fragment, { children: [
33828
33896
  label && /* @__PURE__ */ (0, import_jsx_runtime21.jsxs)("div", { className: getClassName17("zoneTitle"), children: [
33829
33897
  /* @__PURE__ */ (0, import_jsx_runtime21.jsx)("div", { className: getClassName17("zoneIcon"), children: /* @__PURE__ */ (0, import_jsx_runtime21.jsx)(layers_default, { size: "16" }) }),
@@ -33948,11 +34016,11 @@ var flushZones = (appState) => {
33948
34016
 
33949
34017
  // lib/use-component-list.tsx
33950
34018
  init_react_import();
33951
- var import_react35 = require("react");
34019
+ var import_react37 = require("react");
33952
34020
  var import_jsx_runtime22 = require("react/jsx-runtime");
33953
34021
  var useComponentList = (config, ui) => {
33954
- const [componentList, setComponentList] = (0, import_react35.useState)();
33955
- (0, import_react35.useEffect)(() => {
34022
+ const [componentList, setComponentList] = (0, import_react37.useState)();
34023
+ (0, import_react37.useEffect)(() => {
33956
34024
  var _a, _b, _c;
33957
34025
  if (Object.keys(ui.componentList).length > 0) {
33958
34026
  const matchedComponents = [];
@@ -34018,56 +34086,64 @@ var useComponentList = (config, ui) => {
34018
34086
 
34019
34087
  // lib/use-resolved-data.ts
34020
34088
  init_react_import();
34021
- var import_react36 = require("react");
34089
+ var import_react38 = require("react");
34022
34090
 
34023
- // lib/resolve-all-props.ts
34091
+ // lib/resolve-component-data.ts
34024
34092
  init_react_import();
34025
34093
  var cache = { lastChange: {} };
34026
- var resolveAllProps = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
34094
+ var resolveAllComponentData = (content, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
34027
34095
  return yield Promise.all(
34028
34096
  content.map((item) => __async(void 0, null, function* () {
34029
- const configForItem = config.components[item.type];
34030
- if (configForItem.resolveData) {
34031
- let changed = Object.keys(item.props).reduce(
34032
- (acc, item2) => __spreadProps(__spreadValues({}, acc), { [item2]: true }),
34033
- {}
34034
- );
34035
- if (cache.lastChange[item.props.id]) {
34036
- const { item: oldItem, resolved } = cache.lastChange[item.props.id];
34037
- if (oldItem === item) {
34038
- return resolved;
34039
- }
34040
- Object.keys(item.props).forEach((propName) => {
34041
- if (oldItem.props[propName] === item.props[propName]) {
34042
- changed[propName] = false;
34043
- }
34044
- });
34045
- }
34046
- if (onResolveStart) {
34047
- onResolveStart(item);
34048
- }
34049
- const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed });
34050
- const { readOnly: existingReadOnly = {} } = item || {};
34051
- const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
34052
- const resolvedItem = __spreadProps(__spreadValues({}, item), {
34053
- props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
34054
- });
34055
- if (Object.keys(newReadOnly).length) {
34056
- resolvedItem.readOnly = newReadOnly;
34057
- }
34058
- cache.lastChange[item.props.id] = {
34059
- item,
34060
- resolved: resolvedItem
34061
- };
34062
- if (onResolveEnd) {
34063
- onResolveEnd(resolvedItem);
34064
- }
34065
- return resolvedItem;
34066
- }
34067
- return item;
34097
+ return yield resolveComponentData(
34098
+ item,
34099
+ config,
34100
+ onResolveStart,
34101
+ onResolveEnd
34102
+ );
34068
34103
  }))
34069
34104
  );
34070
34105
  });
34106
+ var resolveComponentData = (item, config, onResolveStart, onResolveEnd) => __async(void 0, null, function* () {
34107
+ const configForItem = config.components[item.type];
34108
+ if (configForItem.resolveData) {
34109
+ let changed = Object.keys(item.props).reduce(
34110
+ (acc, item2) => __spreadProps(__spreadValues({}, acc), { [item2]: true }),
34111
+ {}
34112
+ );
34113
+ if (cache.lastChange[item.props.id]) {
34114
+ const { item: oldItem, resolved } = cache.lastChange[item.props.id];
34115
+ if (oldItem === item) {
34116
+ return resolved;
34117
+ }
34118
+ Object.keys(item.props).forEach((propName) => {
34119
+ if (oldItem.props[propName] === item.props[propName]) {
34120
+ changed[propName] = false;
34121
+ }
34122
+ });
34123
+ }
34124
+ if (onResolveStart) {
34125
+ onResolveStart(item);
34126
+ }
34127
+ const { props: resolvedProps, readOnly = {} } = yield configForItem.resolveData(item, { changed });
34128
+ const { readOnly: existingReadOnly = {} } = item || {};
34129
+ const newReadOnly = __spreadValues(__spreadValues({}, existingReadOnly), readOnly);
34130
+ const resolvedItem = __spreadProps(__spreadValues({}, item), {
34131
+ props: __spreadValues(__spreadValues({}, item.props), resolvedProps)
34132
+ });
34133
+ if (Object.keys(newReadOnly).length) {
34134
+ resolvedItem.readOnly = newReadOnly;
34135
+ }
34136
+ cache.lastChange[item.props.id] = {
34137
+ item,
34138
+ resolved: resolvedItem
34139
+ };
34140
+ if (onResolveEnd) {
34141
+ onResolveEnd(resolvedItem);
34142
+ }
34143
+ return resolvedItem;
34144
+ }
34145
+ return item;
34146
+ });
34071
34147
 
34072
34148
  // lib/apply-dynamic-props.ts
34073
34149
  init_react_import();
@@ -34125,55 +34201,81 @@ var resolveRootData = (data, config) => __async(void 0, null, function* () {
34125
34201
 
34126
34202
  // lib/use-resolved-data.ts
34127
34203
  var useResolvedData = (data, config, dispatch) => {
34128
- const [runResolversKey, setRunResolversKey] = (0, import_react36.useState)(0);
34129
- const [componentState, setComponentState] = (0, import_react36.useState)({});
34130
- const runResolvers = () => {
34131
- const flatContent = Object.keys(data.zones || {}).reduce((acc, zone) => [...acc, ...data.zones[zone]], data.content).filter((item) => !!config.components[item.type].resolveData);
34132
- resolveAllProps(
34133
- flatContent,
34134
- config,
34135
- (item) => {
34136
- setComponentState((prev) => __spreadProps(__spreadValues({}, prev), {
34137
- [item.props.id]: __spreadProps(__spreadValues({}, prev[item.props.id]), { loading: true })
34138
- }));
34139
- },
34140
- (item) => {
34204
+ const [{ resolverKey, newData }, setResolverState] = (0, import_react38.useState)({
34205
+ resolverKey: 0,
34206
+ newData: data
34207
+ });
34208
+ const [componentState, setComponentState] = (0, import_react38.useState)({});
34209
+ const deferredSetStates = {};
34210
+ const setComponentLoading = (0, import_react38.useCallback)(
34211
+ (id, loading, defer = 0) => {
34212
+ if (deferredSetStates[id]) {
34213
+ clearTimeout(deferredSetStates[id]);
34214
+ delete deferredSetStates[id];
34215
+ }
34216
+ const setLoading = deferredSetStates[id] = setTimeout(() => {
34141
34217
  setComponentState((prev) => __spreadProps(__spreadValues({}, prev), {
34142
- [item.props.id]: __spreadProps(__spreadValues({}, prev[item.props.id]), { loading: false })
34218
+ [id]: __spreadProps(__spreadValues({}, prev[id]), { loading })
34143
34219
  }));
34144
- }
34145
- ).then((dynamicContent) => __async(void 0, null, function* () {
34146
- setComponentState((prev) => __spreadProps(__spreadValues({}, prev), {
34147
- "puck-root": __spreadProps(__spreadValues({}, prev["puck-root"]), { loading: true })
34148
- }));
34149
- const dynamicRoot = yield resolveRootData(data, config);
34150
- setComponentState((prev) => __spreadProps(__spreadValues({}, prev), {
34151
- "puck-root": __spreadProps(__spreadValues({}, prev["puck-root"]), { loading: false })
34152
- }));
34153
- const newDynamicProps = dynamicContent.reduce(
34154
- (acc, item) => {
34155
- return __spreadProps(__spreadValues({}, acc), { [item.props.id]: item });
34156
- },
34157
- {}
34158
- );
34159
- const processed = applyDynamicProps(data, newDynamicProps, dynamicRoot);
34220
+ delete deferredSetStates[id];
34221
+ }, defer);
34222
+ },
34223
+ []
34224
+ );
34225
+ const runResolvers = () => __async(void 0, null, function* () {
34226
+ const flatContent = Object.keys(newData.zones || {}).reduce((acc, zone) => [...acc, ...newData.zones[zone]], newData.content).filter((item) => !!config.components[item.type].resolveData);
34227
+ const applyIfChange = (dynamicDataMap, dynamicRoot) => {
34228
+ const processed = applyDynamicProps(data, dynamicDataMap, dynamicRoot);
34160
34229
  const containsChanges = JSON.stringify(data) !== JSON.stringify(processed);
34161
34230
  if (containsChanges) {
34162
34231
  dispatch({
34163
34232
  type: "setData",
34164
- data: (prev) => applyDynamicProps(prev, newDynamicProps, dynamicRoot),
34165
- recordHistory: true
34233
+ data: (prev) => applyDynamicProps(prev, dynamicDataMap, dynamicRoot),
34234
+ recordHistory: resolverKey > 0
34166
34235
  });
34167
34236
  }
34168
- }));
34169
- };
34170
- (0, import_react36.useEffect)(() => {
34237
+ };
34238
+ const promises = [];
34239
+ promises.push(
34240
+ (() => __async(void 0, null, function* () {
34241
+ setComponentLoading("puck-root", true, 50);
34242
+ const dynamicRoot = yield resolveRootData(newData, config);
34243
+ applyIfChange({}, dynamicRoot);
34244
+ setComponentLoading("puck-root", false);
34245
+ }))()
34246
+ );
34247
+ flatContent.forEach((item) => {
34248
+ promises.push(
34249
+ (() => __async(void 0, null, function* () {
34250
+ const dynamicData = yield resolveComponentData(
34251
+ item,
34252
+ config,
34253
+ (item2) => {
34254
+ setComponentLoading(item2.props.id, true, 50);
34255
+ },
34256
+ (item2) => {
34257
+ deferredSetStates[item2.props.id];
34258
+ setComponentLoading(item2.props.id, false);
34259
+ }
34260
+ );
34261
+ const dynamicDataMap = { [item.props.id]: dynamicData };
34262
+ applyIfChange(dynamicDataMap);
34263
+ }))()
34264
+ );
34265
+ });
34266
+ yield Promise.all(promises);
34267
+ });
34268
+ (0, import_react38.useEffect)(() => {
34171
34269
  runResolvers();
34172
- }, [runResolversKey]);
34270
+ }, [resolverKey]);
34271
+ const resolveData = (0, import_react38.useCallback)((newData2 = data) => {
34272
+ setResolverState((curr) => ({
34273
+ resolverKey: curr.resolverKey + 1,
34274
+ newData: newData2
34275
+ }));
34276
+ }, []);
34173
34277
  return {
34174
- resolveData: () => {
34175
- setRunResolversKey((curr) => curr + 1);
34176
- },
34278
+ resolveData,
34177
34279
  componentState
34178
34280
  };
34179
34281
  };
@@ -34208,7 +34310,7 @@ function Puck({
34208
34310
  headerPath
34209
34311
  }) {
34210
34312
  var _a, _b;
34211
- const [reducer] = (0, import_react37.useState)(() => createReducer({ config }));
34313
+ const [reducer] = (0, import_react39.useState)(() => createReducer({ config }));
34212
34314
  const initialAppState = __spreadProps(__spreadValues({}, defaultAppState), {
34213
34315
  data: initialData,
34214
34316
  ui: __spreadProps(__spreadValues({}, defaultAppState.ui), {
@@ -34228,7 +34330,7 @@ function Puck({
34228
34330
  ) : {}
34229
34331
  })
34230
34332
  });
34231
- const [appState, dispatch] = (0, import_react37.useReducer)(
34333
+ const [appState, dispatch] = (0, import_react39.useReducer)(
34232
34334
  reducer,
34233
34335
  flushZones(initialAppState)
34234
34336
  );
@@ -34243,7 +34345,7 @@ function Puck({
34243
34345
  dispatch
34244
34346
  });
34245
34347
  const { itemSelector, leftSideBarVisible } = ui;
34246
- const setItemSelector = (0, import_react37.useCallback)(
34348
+ const setItemSelector = (0, import_react39.useCallback)(
34247
34349
  (newItemSelector) => {
34248
34350
  dispatch({
34249
34351
  type: "setUi",
@@ -34253,7 +34355,7 @@ function Puck({
34253
34355
  []
34254
34356
  );
34255
34357
  const selectedItem = itemSelector ? getItem(itemSelector, data) : null;
34256
- const Page = (0, import_react37.useCallback)(
34358
+ const Page = (0, import_react39.useCallback)(
34257
34359
  (pageProps) => {
34258
34360
  var _a2, _b2;
34259
34361
  return /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
@@ -34269,7 +34371,7 @@ function Puck({
34269
34371
  },
34270
34372
  [config.root]
34271
34373
  );
34272
- const PageFieldWrapper = (0, import_react37.useCallback)(
34374
+ const PageFieldWrapper = (0, import_react39.useCallback)(
34273
34375
  (props) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34274
34376
  PluginRenderer,
34275
34377
  {
@@ -34282,7 +34384,7 @@ function Puck({
34282
34384
  ),
34283
34385
  []
34284
34386
  );
34285
- const ComponentFieldWrapper = (0, import_react37.useCallback)(
34387
+ const ComponentFieldWrapper = (0, import_react39.useCallback)(
34286
34388
  (props) => /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34287
34389
  PluginRenderer,
34288
34390
  {
@@ -34295,7 +34397,7 @@ function Puck({
34295
34397
  ),
34296
34398
  []
34297
34399
  );
34298
- const ComponentListWrapper = (0, import_react37.useCallback)((props) => {
34400
+ const ComponentListWrapper = (0, import_react39.useCallback)((props) => {
34299
34401
  const children = /* @__PURE__ */ (0, import_jsx_runtime23.jsx)(
34300
34402
  PluginRenderer,
34301
34403
  {
@@ -34315,18 +34417,18 @@ function Puck({
34315
34417
  const FieldWrapper = itemSelector ? ComponentFieldWrapper : PageFieldWrapper;
34316
34418
  const rootFields = ((_a = config.root) == null ? void 0 : _a.fields) || defaultPageFields;
34317
34419
  let fields = selectedItem ? ((_b = config.components[selectedItem.type]) == null ? void 0 : _b.fields) || {} : rootFields;
34318
- (0, import_react37.useEffect)(() => {
34420
+ (0, import_react39.useEffect)(() => {
34319
34421
  if (onChange)
34320
34422
  onChange(data);
34321
34423
  }, [data]);
34322
34424
  const { onDragStartOrUpdate, placeholderStyle } = usePlaceholderStyle();
34323
- const [draggedItem, setDraggedItem] = (0, import_react37.useState)();
34425
+ const [draggedItem, setDraggedItem] = (0, import_react39.useState)();
34324
34426
  const componentList = useComponentList(config, appState.ui);
34325
34427
  const rootProps = data.root.props || data.root;
34326
- (0, import_react37.useEffect)(() => {
34428
+ (0, import_react39.useEffect)(() => {
34327
34429
  if (Object.keys(data.root).length > 0 && !data.root.props) {
34328
34430
  console.error(
34329
- "Warning: Defining props on `root` is deprecated. Please use `root.props`. This will be a breaking change in a future release "
34431
+ "Warning: Defining props on `root` is deprecated. Please use `root.props`. This will be a breaking change in a future release."
34330
34432
  );
34331
34433
  }
34332
34434
  }, []);
@@ -34678,6 +34780,7 @@ function Puck({
34678
34780
  children: Object.keys(fields).map((fieldName) => {
34679
34781
  const field = fields[fieldName];
34680
34782
  const onChange2 = (value) => {
34783
+ var _a3, _b3;
34681
34784
  let currentProps;
34682
34785
  if (selectedItem) {
34683
34786
  currentProps = selectedItem.props;
@@ -34688,26 +34791,35 @@ function Puck({
34688
34791
  [fieldName]: value
34689
34792
  });
34690
34793
  if (itemSelector) {
34691
- dispatch({
34794
+ const action = {
34692
34795
  type: "replace",
34693
34796
  destinationIndex: itemSelector.index,
34694
34797
  destinationZone: itemSelector.zone || rootDroppableId,
34695
34798
  data: __spreadProps(__spreadValues({}, selectedItem), { props: newProps })
34696
- });
34697
- resolveData();
34799
+ };
34800
+ if ((_a3 = config.components[selectedItem.type]) == null ? void 0 : _a3.resolveData) {
34801
+ resolveData(replaceAction(data, action));
34802
+ } else {
34803
+ dispatch(action);
34804
+ }
34698
34805
  } else {
34699
34806
  if (data.root.props) {
34700
- dispatch({
34701
- type: "setData",
34702
- data: { root: { props: { newProps } } }
34703
- });
34807
+ if ((_b3 = config.root) == null ? void 0 : _b3.resolveData) {
34808
+ resolveData(__spreadProps(__spreadValues({}, data), {
34809
+ root: { props: { newProps } }
34810
+ }));
34811
+ } else {
34812
+ dispatch({
34813
+ type: "setData",
34814
+ data: { root: { props: { newProps } } }
34815
+ });
34816
+ }
34704
34817
  } else {
34705
34818
  dispatch({
34706
34819
  type: "setData",
34707
34820
  data: { root: newProps }
34708
34821
  });
34709
34822
  }
34710
- resolveData();
34711
34823
  }
34712
34824
  };
34713
34825
  if (selectedItem && itemSelector) {
@@ -34790,7 +34902,7 @@ var resolveAllData = (data, config, onResolveStart, onResolveEnd) => __async(voi
34790
34902
  const resolvedZones = {};
34791
34903
  for (let i = 0; i < zoneKeys.length; i++) {
34792
34904
  const zoneKey = zoneKeys[i];
34793
- resolvedZones[zoneKey] = yield resolveAllProps(
34905
+ resolvedZones[zoneKey] = yield resolveAllComponentData(
34794
34906
  zones[zoneKey],
34795
34907
  config,
34796
34908
  onResolveStart,
@@ -34799,7 +34911,7 @@ var resolveAllData = (data, config, onResolveStart, onResolveEnd) => __async(voi
34799
34911
  }
34800
34912
  return __spreadProps(__spreadValues({}, data), {
34801
34913
  root: dynamicRoot,
34802
- content: yield resolveAllProps(
34914
+ content: yield resolveAllComponentData(
34803
34915
  data.content,
34804
34916
  config,
34805
34917
  onResolveStart,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@measured/puck",
3
- "version": "0.11.0-canary.f9033e2",
3
+ "version": "0.11.0",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",