@measured/puck 0.11.0-canary.6145c32 → 0.11.0-canary.c8c02fd

Sign up to get free protection for your applications and to get access to all the features.
package/README.md CHANGED
@@ -111,10 +111,11 @@ The plugin API follows a React paradigm. Each plugin passed to the Puck editor c
111
111
  - `renderRoot` (`Component`): Render the root node of the preview content
112
112
  - `renderRootFields` (`Component`): Render the root fields
113
113
  - `renderFields` (`Component`): Render the fields for the currently selected component
114
+ - `renderComponentList` (`Component`): Render the component list
114
115
 
115
116
  Each render function receives three props:
116
117
 
117
- - **children** (`ReactNode`): The normal contents of the root or field. You must render this.
118
+ - **children** (`ReactNode`): The normal contents of the root or field. You must render this if provided.
118
119
  - **state** (`AppState`): The current application state, including data and UI state
119
120
  - **dispatch** (`(action: PuckAction) => void`): The Puck dispatcher, used for making data changes or updating the UI. See the [action definitions](https://github.com/measuredco/puck/blob/main/packages/core/reducer/actions.tsx) for a full reference of available mutations.
120
121
 
@@ -241,6 +242,7 @@ The `<Puck>` component renders the Puck editor.
241
242
  - **data** (`Data`): Initial data to render
242
243
  - **onChange** (`(Data) => void` [optional]): Callback that triggers when the user makes a change
243
244
  - **onPublish** (`(Data) => void` [optional]): Callback that triggers when the user hits the "Publish" button
245
+ - **renderComponentList** (`Component` [optional]): Render function for wrapping the component list
244
246
  - **renderHeader** (`Component` [optional]): Render function for overriding the Puck header component
245
247
  - **renderHeaderActions** (`Component` [optional]): Render function for overriding the Puck header actions. Use a fragment.
246
248
  - **headerTitle** (`string` [optional]): Set the title shown in the header title
@@ -275,6 +277,12 @@ The `Config` object describes which components Puck should render, how they shou
275
277
  - **fields** (`Field`): The Field objects describing the input data stored against this component.
276
278
  - **render** (`Component`): Render function for your React component. Receives props as defined in fields.
277
279
  - **defaultProps** (`object` [optional]): Default props to pass to your component. Will show in fields.
280
+ - **categories** (`object`): Component categories for rendering in the side bar or restricting in DropZones
281
+ - **[categoryName]** (`object`)
282
+ - **components** (`sting[]`, [optional]): Array containing the names of components in this category
283
+ - **title** (`sting`, [optional]): Title of the category
284
+ - **visible** (`boolean`, [optional]): Whether or not the category should be visible in the side bar
285
+ - **defaultExpanded** (`boolean`, [optional]): Whether or not the category should be expanded in the side bar by default
278
286
 
279
287
  ### `Field`
280
288
 
@@ -307,6 +315,11 @@ The `AppState` object stores the puck application state.
307
315
  - **leftSideBarVisible** (boolean): Whether or not the left side bar is visible
308
316
  - **itemSelector** (object): An object describing which item is selected
309
317
  - **arrayState** (object): An object describing the internal state of array items
318
+ - **componentList** (object): An object describing the component list. Similar shape to `Config.categories`.
319
+ - **components** (`sting[]`, [optional]): Array containing the names of components in this category
320
+ - **title** (`sting`, [optional]): Title of the category
321
+ - **visible** (`boolean`, [optional]): Whether or not the category is visible in the side bar
322
+ - **expanded** (`boolean`, [optional]): Whether or not the category is expanded in the side bar
310
323
 
311
324
  ### `Data`
312
325
 
package/dist/index.css CHANGED
@@ -475,17 +475,17 @@
475
475
  }
476
476
 
477
477
  /* css-module:/home/runner/work/puck/puck/packages/core/components/InputOrGroup/fields/ArrayField/styles.module.css/#css-module-data */
478
- ._ArrayField_zp334_5 {
478
+ ._ArrayField_32vor_5 {
479
479
  display: flex;
480
480
  flex-direction: column;
481
481
  background-color: var(--puck-color-grey-8);
482
482
  border: 1px solid var(--puck-color-grey-8);
483
483
  border-radius: 4px;
484
484
  }
485
- ._ArrayField--isDraggingFrom_zp334_13 {
485
+ ._ArrayField--isDraggingFrom_32vor_13 {
486
486
  background-color: var(--puck-color-azure-9);
487
487
  }
488
- ._ArrayField-addButton_zp334_17 {
488
+ ._ArrayField-addButton_32vor_17 {
489
489
  background-color: white;
490
490
  border: none;
491
491
  border-radius: 4px;
@@ -498,37 +498,37 @@
498
498
  padding: 16px;
499
499
  text-align: left;
500
500
  }
501
- ._ArrayField--hasItems_zp334_31 > ._ArrayField-addButton_zp334_17 {
501
+ ._ArrayField--hasItems_32vor_31 > ._ArrayField-addButton_32vor_17 {
502
502
  border-top-left-radius: 0;
503
503
  border-top-right-radius: 0;
504
504
  }
505
- ._ArrayField_zp334_5:not(._ArrayField--isDraggingFrom_zp334_13) > ._ArrayField-addButton_zp334_17:hover {
505
+ ._ArrayField_32vor_5:not(._ArrayField--isDraggingFrom_32vor_13) > ._ArrayField-addButton_32vor_17:hover {
506
506
  background: var(--puck-color-azure-9);
507
507
  color: var(--puck-color-azure-4);
508
508
  }
509
- ._ArrayFieldItem_zp334_45 {
509
+ ._ArrayFieldItem_32vor_45 {
510
510
  background: white;
511
511
  border-top-left-radius: 4px;
512
512
  border-top-right-radius: 4px;
513
513
  display: block;
514
514
  margin-bottom: 1px;
515
515
  }
516
- ._ArrayField--isDraggingFrom_zp334_13 > ._ArrayFieldItem_zp334_45:not(._ArrayFieldItem--isDragging_zp334_53) {
516
+ ._ArrayField--isDraggingFrom_32vor_13 > ._ArrayFieldItem_32vor_45:not(._ArrayFieldItem--isDragging_32vor_53) {
517
517
  border-bottom: 1px solid var(--puck-color-grey-8);
518
518
  margin-bottom: 0;
519
519
  }
520
- ._ArrayFieldItem--isExpanded_zp334_58 {
520
+ ._ArrayFieldItem--isExpanded_32vor_58 {
521
521
  border-bottom: 0;
522
522
  outline: 1px solid var(--puck-color-azure-6);
523
523
  }
524
- ._ArrayFieldItem--isDragging_zp334_53 {
524
+ ._ArrayFieldItem--isDragging_32vor_53 {
525
525
  box-shadow: rgba(140, 152, 164, 0.25) 0 3px 6px 0;
526
526
  }
527
- ._ArrayFieldItem_zp334_45 + ._ArrayFieldItem_zp334_45 {
527
+ ._ArrayFieldItem_32vor_45 + ._ArrayFieldItem_32vor_45 {
528
528
  border-top-left-radius: 0;
529
529
  border-top-right-radius: 0;
530
530
  }
531
- ._ArrayFieldItem-summary_zp334_72 {
531
+ ._ArrayFieldItem-summary_32vor_72 {
532
532
  color: var(--puck-color-grey-3);
533
533
  display: flex;
534
534
  align-items: center;
@@ -539,48 +539,45 @@
539
539
  position: relative;
540
540
  overflow: hidden;
541
541
  }
542
- ._ArrayFieldItem--isExpanded_zp334_58 > ._ArrayFieldItem-summary_zp334_72 {
542
+ ._ArrayFieldItem--isExpanded_32vor_58 > ._ArrayFieldItem-summary_32vor_72 {
543
543
  font-weight: 600;
544
544
  }
545
- ._ArrayFieldItem_zp334_45:first-of-type > ._ArrayFieldItem-summary_zp334_72 {
545
+ ._ArrayFieldItem_32vor_45:first-of-type > ._ArrayFieldItem-summary_32vor_72 {
546
546
  border-top-left-radius: 4px;
547
547
  border-top-right-radius: 4px;
548
548
  }
549
- ._ArrayFieldItem-summary_zp334_72:hover,
550
- ._ArrayFieldItem--isExpanded_zp334_58 > ._ArrayFieldItem-summary_zp334_72 {
549
+ ._ArrayFieldItem-summary_32vor_72:hover,
550
+ ._ArrayFieldItem--isExpanded_32vor_58 > ._ArrayFieldItem-summary_32vor_72 {
551
551
  background: var(--puck-color-azure-9);
552
552
  cursor: pointer;
553
553
  color: var(--puck-color-azure-4);
554
554
  }
555
- ._ArrayFieldItem-summary_zp334_72::-webkit-details-marker {
555
+ ._ArrayFieldItem-body_32vor_100 {
556
556
  display: none;
557
557
  }
558
- ._ArrayFieldItem-body_zp334_104 {
559
- display: none;
560
- }
561
- ._ArrayFieldItem--isExpanded_zp334_58 > ._ArrayFieldItem-body_zp334_104 {
558
+ ._ArrayFieldItem--isExpanded_32vor_58 > ._ArrayFieldItem-body_32vor_100 {
562
559
  display: block;
563
560
  }
564
- ._ArrayFieldItem-fieldset_zp334_112 {
561
+ ._ArrayFieldItem-fieldset_32vor_108 {
565
562
  border: none;
566
563
  border-top: 1px solid var(--puck-color-grey-8);
567
564
  margin: 0;
568
565
  padding: 16px;
569
566
  }
570
- ._ArrayFieldItem-rhs_zp334_119 {
567
+ ._ArrayFieldItem-rhs_32vor_115 {
571
568
  display: flex;
572
569
  gap: 8px;
573
570
  align-items: center;
574
571
  }
575
- ._ArrayFieldItem-actions_zp334_125 {
572
+ ._ArrayFieldItem-actions_32vor_121 {
576
573
  display: flex;
577
574
  gap: 8px;
578
575
  opacity: 0;
579
576
  }
580
- ._ArrayFieldItem-summary_zp334_72:hover > ._ArrayFieldItem-rhs_zp334_119 > ._ArrayFieldItem-actions_zp334_125 {
577
+ ._ArrayFieldItem-summary_32vor_72:hover > ._ArrayFieldItem-rhs_32vor_115 > ._ArrayFieldItem-actions_32vor_121 {
581
578
  opacity: 1;
582
579
  }
583
- ._ArrayFieldItem-action_zp334_125:hover {
580
+ ._ArrayFieldItem-action_32vor_121:hover {
584
581
  background: var(--puck-color-grey-9);
585
582
  border-radius: 4px;
586
583
  color: var(--puck-color-blue);
@@ -723,11 +720,44 @@
723
720
  }
724
721
 
725
722
  /* css-module:/home/runner/work/puck/puck/packages/core/components/ComponentList/styles.module.css/#css-module-data */
726
- ._ComponentList_bvy0z_1 {
723
+ ._ComponentList_3rdy2_1 {
727
724
  font-family: var(--puck-font-stack);
728
725
  max-width: 100%;
729
726
  }
730
- ._ComponentList-item_bvy0z_6 {
727
+ ._ComponentList--isExpanded_3rdy2_6 + ._ComponentList_3rdy2_1 {
728
+ margin-top: 12px;
729
+ }
730
+ ._ComponentList-content_3rdy2_10 {
731
+ display: none;
732
+ }
733
+ ._ComponentList--isExpanded_3rdy2_6 > ._ComponentList-content_3rdy2_10 {
734
+ display: block;
735
+ }
736
+ ._ComponentList-title_3rdy2_18 {
737
+ color: var(--puck-color-grey-4);
738
+ display: flex;
739
+ font-size: var(--puck-font-size-xxxs);
740
+ list-style: none;
741
+ padding: 8px;
742
+ text-transform: uppercase;
743
+ gap: 4px;
744
+ border-radius: 4px;
745
+ }
746
+ ._ComponentList--isExpanded_3rdy2_6 ._ComponentList-title_3rdy2_18 {
747
+ margin-bottom: 4px;
748
+ }
749
+ ._ComponentList-title_3rdy2_18:hover {
750
+ background-color: var(--puck-color-azure-9);
751
+ color: var(--puck-color-azure-4);
752
+ cursor: pointer;
753
+ }
754
+ ._ComponentList-titleIcon_3rdy2_39 {
755
+ margin-left: auto;
756
+ }
757
+ ._ComponentListItem_3rdy2_43:last-of-type ._ComponentListItem-draggable_3rdy2_43 {
758
+ margin-bottom: 0px;
759
+ }
760
+ ._ComponentListItem-draggable_3rdy2_43 {
731
761
  background: white;
732
762
  padding: 12px;
733
763
  display: flex;
@@ -740,13 +770,10 @@
740
770
  cursor: grab;
741
771
  margin-bottom: 12px;
742
772
  }
743
- ._ComponentList-item_bvy0z_6:last-of-type {
744
- margin-bottom: 0px;
745
- }
746
- ._ComponentList-itemIcon_bvy0z_24 {
773
+ ._ComponentListItemIcon_3rdy2_61 {
747
774
  color: var(--puck-color-grey-4);
748
775
  }
749
- ._ComponentList_bvy0z_1:not(._ComponentList--isDraggingFrom_bvy0z_28) ._ComponentList-item_bvy0z_6:hover {
776
+ ._ComponentList_3rdy2_1:not(._ComponentList--isDraggingFrom_3rdy2_65) ._ComponentListItem-draggable_3rdy2_43:hover {
750
777
  background-color: var(--puck-color-azure-9);
751
778
  color: var(--puck-color-azure-4);
752
779
  }
package/dist/index.d.ts CHANGED
@@ -64,11 +64,20 @@ type ComponentConfig<ComponentProps extends DefaultComponentProps = DefaultCompo
64
64
  defaultProps?: DefaultProps;
65
65
  fields?: Fields<ComponentProps>;
66
66
  };
67
+ type Category<ComponentName> = {
68
+ components?: ComponentName[];
69
+ title?: string;
70
+ visible?: boolean;
71
+ defaultExpanded?: boolean;
72
+ };
67
73
  type Config<Props extends {
68
74
  [key: string]: any;
69
75
  } = {
70
76
  [key: string]: any;
71
- }, RootProps extends DefaultRootProps = DefaultRootProps> = {
77
+ }, RootProps extends DefaultRootProps = DefaultRootProps, CategoryName extends string = string> = {
78
+ categories?: Record<CategoryName, Category<keyof Props>> & {
79
+ other?: Category<Props>;
80
+ };
72
81
  components: {
73
82
  [ComponentName in keyof Props]: ComponentConfig<Props[ComponentName], Props[ComponentName]>;
74
83
  };
@@ -115,6 +124,12 @@ type UiState = {
115
124
  leftSideBarVisible: boolean;
116
125
  itemSelector: ItemSelector | null;
117
126
  arrayState: Record<string, ArrayState | undefined>;
127
+ componentList: Record<string, {
128
+ components?: string[];
129
+ title?: string;
130
+ visible?: boolean;
131
+ expanded?: boolean;
132
+ }>;
118
133
  };
119
134
  type AppState = {
120
135
  data: Data;
@@ -265,12 +280,17 @@ type Plugin = {
265
280
  }) => ReactElement<any>;
266
281
  };
267
282
 
268
- declare function Puck({ config, data: initialData, onChange, onPublish, plugins, renderHeader, renderHeaderActions, headerTitle, headerPath, }: {
283
+ declare function Puck({ config, data: initialData, onChange, onPublish, plugins, renderComponentList, renderHeader, renderHeaderActions, headerTitle, headerPath, }: {
269
284
  config: Config;
270
285
  data: Data;
271
286
  onChange?: (data: Data) => void;
272
287
  onPublish: (data: Data) => void;
273
288
  plugins?: Plugin[];
289
+ renderComponentList?: (props: {
290
+ children: ReactNode;
291
+ dispatch: (action: PuckAction) => void;
292
+ state: AppState;
293
+ }) => ReactElement;
274
294
  renderHeader?: (props: {
275
295
  children: ReactNode;
276
296
  dispatch: (action: PuckAction) => void;