@measured/puck 0.20.0-canary.755737e8 → 0.20.0-canary.f768aab9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,29 +1,33 @@
1
- # Puck
1
+ <br /><br /><br />
2
2
 
3
- The visual editor for React.
3
+ <div align="center">
4
4
 
5
- <p align="left">
6
- <a aria-label="NPM version" href="https://www.npmjs.com/package/@measured/puck">
7
- <img alt="" src="https://img.shields.io/npm/v/@measured/puck.svg?style=for-the-badge&labelColor=000000">
8
- </a>
9
- <a aria-label="License" href="https://github.com/measuredco/puck/blob/main/LICENSE">
10
- <img alt="" src="https://img.shields.io/npm/l/@measured/puck.svg?style=for-the-badge&labelColor=000000">
11
- </a>
12
- <a aria-label="Join the community on Discord" href="https://discord.gg/D9e4E3MQVZ">
13
- <img alt="" src="https://img.shields.io/badge/Join%20the%20Discord-blueviolet.svg?style=for-the-badge&logo=Discord&labelColor=000000&logoWidth=20">
14
- </a>
15
- <a aria-label="Browse the awesome-puck community repo" href="https://github.com/measuredco/awesome-puck">
16
- <img alt="" src="https://img.shields.io/badge/repo-awesome--puck-fc60a8.svg?style=for-the-badge&labelColor=000000&logoWidth=20">
17
- </a>
18
- </p>
5
+ <a href="https://puckeditor.com">
6
+ <picture>
7
+ <source media="(prefers-color-scheme: dark)" srcset="https://res.cloudinary.com/die3nptcg/image/upload/Puck_Logo_White_RGB_j2rwgg.svg" height="100px" aria-label="Puck logo">
8
+ <img src="https://res.cloudinary.com/die3nptcg/image/upload/Puck_Logo_Black_RGB_dqsjag.svg" height="100px" aria-label="Puck logo">
9
+ </picture>
10
+ </a>
19
11
 
20
- ## Demo
12
+ _The visual editor for React_
21
13
 
22
- Visit https://demo.puckeditor.com/edit to try the demo.
14
+ [Documentation](https://puckeditor.com/docs) • [Demo](https://demo.puckeditor.com/edit) [Discord](https://discord.gg/V9mDAhuxyZ) [Contributing](https://github.com/puckeditor/puck/blob/main/CONTRIBUTING.md)
23
15
 
24
- ## Documentation
16
+ ⭐️ Enjoying Puck? Please [leave a star](https://github.com/puckeditor/puck)!
25
17
 
26
- Visit https://puckeditor.com to view the full documentation.
18
+ <br />
19
+
20
+ [![GIF showing a page being created in the Puck Editor, with components being added, arranged, and customized in real time](https://github.com/user-attachments/assets/25e1ae25-ca5e-450f-afa0-01816830b731)](https://demo.puckeditor.com/edit)
21
+
22
+ </div>
23
+
24
+ ## What is Puck?
25
+
26
+ Puck is a modular, open-source visual editor for React.js. You can use Puck to build custom drag-and-drop experiences with your own application and React components.
27
+
28
+ Because Puck is just a React component, it plays well with all React.js environments, including Next.js. You own your data and there’s no vendor lock-in.
29
+
30
+ Puck is also [licensed under MIT](https://github.com/puckeditor/puck?tab=MIT-1-ov-file#readme), making it suitable for both internal systems and commercial applications.
27
31
 
28
32
  ## Quick start
29
33
 
@@ -871,8 +871,8 @@ var migrations = [
871
871
  return data;
872
872
  },
873
873
  // Migrate zones to slots
874
- (data, config) => {
875
- var _a;
874
+ (data, config, migrationOptions) => {
875
+ var _a, _b;
876
876
  if (!config) return data;
877
877
  console.log("Migrating DropZones to slots...");
878
878
  const updatedItems = {};
@@ -880,13 +880,13 @@ var migrations = [
880
880
  const { indexes } = walkAppState(appState, config);
881
881
  const deletedCompounds = [];
882
882
  walkAppState(appState, config, (content, zoneCompound, zoneType) => {
883
- var _a2, _b, _c;
883
+ var _a2, _b2, _c;
884
884
  if (zoneType === "dropzone") {
885
885
  const [id, slotName] = zoneCompound.split(":");
886
886
  const nodeData = indexes.nodes[id].data;
887
887
  const componentType = nodeData.type;
888
888
  const configForComponent = id === "root" ? config.root : config.components[componentType];
889
- if (((_b = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b.type) === "slot") {
889
+ if (((_b2 = (_a2 = configForComponent == null ? void 0 : configForComponent.fields) == null ? void 0 : _a2[slotName]) == null ? void 0 : _b2.type) === "slot") {
890
890
  updatedItems[id] = __spreadProps(__spreadValues({}, nodeData), {
891
891
  props: __spreadProps(__spreadValues(__spreadValues({}, nodeData.props), (_c = updatedItems[id]) == null ? void 0 : _c.props), {
892
892
  [slotName]: content
@@ -915,7 +915,49 @@ var migrations = [
915
915
  );
916
916
  (_a2 = updated.data.zones) == null ? true : delete _a2[zoneCompound];
917
917
  });
918
- Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
918
+ if (migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) {
919
+ const unmigratedZonesGrouped = {};
920
+ Object.keys((_a = updated.data.zones) != null ? _a : {}).forEach((zoneCompound) => {
921
+ var _a2;
922
+ const [componentId, propName] = zoneCompound.split(":");
923
+ const content = (_a2 = updated.data.zones) == null ? void 0 : _a2[zoneCompound];
924
+ if (!content) {
925
+ return;
926
+ }
927
+ if (!unmigratedZonesGrouped[componentId]) {
928
+ unmigratedZonesGrouped[componentId] = {};
929
+ }
930
+ if (!unmigratedZonesGrouped[componentId][propName]) {
931
+ unmigratedZonesGrouped[componentId][propName] = content;
932
+ }
933
+ });
934
+ Object.keys(unmigratedZonesGrouped).forEach((componentId) => {
935
+ updated.data = walkTree(updated.data, config, (content) => {
936
+ return content.map((child) => {
937
+ var _a2;
938
+ if (child.props.id !== componentId) {
939
+ return child;
940
+ }
941
+ const migrateFn = (_a2 = migrationOptions == null ? void 0 : migrationOptions.migrateDynamicZonesForComponent) == null ? void 0 : _a2[child.type];
942
+ if (!migrateFn) {
943
+ return child;
944
+ }
945
+ const zones = unmigratedZonesGrouped[componentId];
946
+ const migratedProps = migrateFn(child.props, zones);
947
+ Object.keys(zones).forEach((propName) => {
948
+ var _a3;
949
+ const zoneCompound = `${componentId}:${propName}`;
950
+ console.log(`\u2713 Success: Migrated "${zoneCompound}" DropZone`);
951
+ (_a3 = updated.data.zones) == null ? true : delete _a3[zoneCompound];
952
+ });
953
+ return __spreadProps(__spreadValues({}, child), {
954
+ props: migratedProps
955
+ });
956
+ });
957
+ });
958
+ });
959
+ }
960
+ Object.keys((_b = updated.data.zones) != null ? _b : {}).forEach((zoneCompound) => {
919
961
  const [_, propName] = zoneCompound.split(":");
920
962
  throw new Error(
921
963
  `Could not migrate DropZone "${zoneCompound}" to slot field. No slot exists with the name "${propName}".`
@@ -925,9 +967,9 @@ var migrations = [
925
967
  return updated.data;
926
968
  }
927
969
  ];
928
- function migrate(data, config) {
970
+ function migrate(data, config, migrationOptions) {
929
971
  return migrations == null ? void 0 : migrations.reduce(
930
- (acc, migration) => migration(acc, config),
972
+ (acc, migration) => migration(acc, config, migrationOptions),
931
973
  data
932
974
  );
933
975
  }