@slicemachine/adapter-next 0.0.8 → 0.0.10

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.
Files changed (89) hide show
  1. package/dist/hooks/command-init.cjs +191 -0
  2. package/dist/hooks/command-init.cjs.map +1 -0
  3. package/dist/hooks/command-init.d.ts +3 -0
  4. package/dist/hooks/command-init.js +173 -0
  5. package/dist/hooks/command-init.js.map +1 -0
  6. package/dist/hooks/sliceSimulator-setup-read.cjs +2 -0
  7. package/dist/hooks/sliceSimulator-setup-read.cjs.map +1 -1
  8. package/dist/hooks/sliceSimulator-setup-read.js +2 -0
  9. package/dist/hooks/sliceSimulator-setup-read.js.map +1 -1
  10. package/dist/lib/checkPathExists.cjs +30 -0
  11. package/dist/lib/checkPathExists.cjs.map +1 -0
  12. package/dist/lib/checkPathExists.d.ts +2 -0
  13. package/dist/lib/checkPathExists.js +13 -0
  14. package/dist/lib/checkPathExists.js.map +1 -0
  15. package/dist/lib/rejectIfNecessary.cjs.map +1 -1
  16. package/dist/lib/rejectIfNecessary.js.map +1 -1
  17. package/dist/lib/upsertSliceLibraryIndexFile.cjs +31 -10
  18. package/dist/lib/upsertSliceLibraryIndexFile.cjs.map +1 -1
  19. package/dist/lib/upsertSliceLibraryIndexFile.js +31 -10
  20. package/dist/lib/upsertSliceLibraryIndexFile.js.map +1 -1
  21. package/dist/node_modules/data-uri-to-buffer/dist/index.cjs.map +1 -1
  22. package/dist/node_modules/data-uri-to-buffer/dist/index.js.map +1 -1
  23. package/dist/node_modules/fetch-blob/file.cjs +6 -0
  24. package/dist/node_modules/fetch-blob/file.cjs.map +1 -1
  25. package/dist/node_modules/fetch-blob/file.js +6 -0
  26. package/dist/node_modules/fetch-blob/file.js.map +1 -1
  27. package/dist/node_modules/fetch-blob/index.cjs +48 -2
  28. package/dist/node_modules/fetch-blob/index.cjs.map +1 -1
  29. package/dist/node_modules/fetch-blob/index.js +48 -2
  30. package/dist/node_modules/fetch-blob/index.js.map +1 -1
  31. package/dist/node_modules/fetch-blob/streams.cjs.map +1 -1
  32. package/dist/node_modules/fetch-blob/streams.js.map +1 -1
  33. package/dist/node_modules/formdata-polyfill/esm.min.cjs.map +1 -1
  34. package/dist/node_modules/formdata-polyfill/esm.min.js.map +1 -1
  35. package/dist/node_modules/node-domexception/index.cjs.map +1 -1
  36. package/dist/node_modules/node-domexception/index.js.map +1 -1
  37. package/dist/node_modules/node-fetch/src/body.cjs +25 -0
  38. package/dist/node_modules/node-fetch/src/body.cjs.map +1 -1
  39. package/dist/node_modules/node-fetch/src/body.js +25 -0
  40. package/dist/node_modules/node-fetch/src/body.js.map +1 -1
  41. package/dist/node_modules/node-fetch/src/errors/base.cjs.map +1 -1
  42. package/dist/node_modules/node-fetch/src/errors/base.js.map +1 -1
  43. package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs +5 -0
  44. package/dist/node_modules/node-fetch/src/errors/fetch-error.cjs.map +1 -1
  45. package/dist/node_modules/node-fetch/src/errors/fetch-error.js +5 -0
  46. package/dist/node_modules/node-fetch/src/errors/fetch-error.js.map +1 -1
  47. package/dist/node_modules/node-fetch/src/headers.cjs +17 -0
  48. package/dist/node_modules/node-fetch/src/headers.cjs.map +1 -1
  49. package/dist/node_modules/node-fetch/src/headers.js +17 -0
  50. package/dist/node_modules/node-fetch/src/headers.js.map +1 -1
  51. package/dist/node_modules/node-fetch/src/index.cjs.map +1 -1
  52. package/dist/node_modules/node-fetch/src/index.js.map +1 -1
  53. package/dist/node_modules/node-fetch/src/request.cjs +13 -0
  54. package/dist/node_modules/node-fetch/src/request.cjs.map +1 -1
  55. package/dist/node_modules/node-fetch/src/request.js +13 -0
  56. package/dist/node_modules/node-fetch/src/request.js.map +1 -1
  57. package/dist/node_modules/node-fetch/src/response.cjs +13 -0
  58. package/dist/node_modules/node-fetch/src/response.cjs.map +1 -1
  59. package/dist/node_modules/node-fetch/src/response.js +13 -0
  60. package/dist/node_modules/node-fetch/src/response.js.map +1 -1
  61. package/dist/node_modules/node-fetch/src/utils/get-search.cjs.map +1 -1
  62. package/dist/node_modules/node-fetch/src/utils/get-search.js.map +1 -1
  63. package/dist/node_modules/node-fetch/src/utils/is.cjs.map +1 -1
  64. package/dist/node_modules/node-fetch/src/utils/is.js.map +1 -1
  65. package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs +6 -0
  66. package/dist/node_modules/node-fetch/src/utils/multipart-parser.cjs.map +1 -1
  67. package/dist/node_modules/node-fetch/src/utils/multipart-parser.js +6 -0
  68. package/dist/node_modules/node-fetch/src/utils/multipart-parser.js.map +1 -1
  69. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs +223 -0
  70. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.cjs.map +1 -1
  71. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js +223 -0
  72. package/dist/node_modules/web-streams-polyfill/dist/ponyfill.es2018.js.map +1 -1
  73. package/dist/plugin.cjs +4 -1
  74. package/dist/plugin.cjs.map +1 -1
  75. package/dist/plugin.js +4 -1
  76. package/dist/plugin.js.map +1 -1
  77. package/dist/simulator/SliceSimulator.cjs +2 -11
  78. package/dist/simulator/SliceSimulator.cjs.map +1 -1
  79. package/dist/simulator/SliceSimulator.d.ts +3 -3
  80. package/dist/simulator/SliceSimulator.js +2 -11
  81. package/dist/simulator/SliceSimulator.js.map +1 -1
  82. package/dist/types.d.ts +1 -0
  83. package/package.json +15 -15
  84. package/src/hooks/command-init.ts +221 -0
  85. package/src/lib/checkPathExists.ts +12 -0
  86. package/src/lib/upsertSliceLibraryIndexFile.ts +37 -9
  87. package/src/plugin.ts +4 -0
  88. package/src/simulator/SliceSimulator.tsx +3 -16
  89. package/src/types.ts +1 -0
package/dist/plugin.cjs CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const pluginKit = require("@slicemachine/plugin-kit");
4
4
  const _package = require("./package.json.cjs");
5
+ const commandInit = require("./hooks/command-init.cjs");
5
6
  const customTypeAssetDelete = require("./hooks/customType-asset-delete.cjs");
6
7
  const customTypeAssetRead = require("./hooks/customType-asset-read.cjs");
7
8
  const customTypeAssetUpdate = require("./hooks/customType-asset-update.cjs");
@@ -27,9 +28,11 @@ const plugin = pluginKit.defineSliceMachinePlugin({
27
28
  name: _package.name
28
29
  },
29
30
  defaultOptions: {
30
- format: true
31
+ format: true,
32
+ lazyLoadSlices: true
31
33
  },
32
34
  setup({ hook }) {
35
+ hook("command:init", commandInit.commandInit);
33
36
  hook("slice:create", sliceCreate.sliceCreate);
34
37
  hook("slice:update", sliceUpdate.sliceUpdate);
35
38
  hook("slice:rename", sliceRename.sliceRename);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":["defineSliceMachinePlugin","pkgName","sliceCreate","sliceUpdate","sliceRename","sliceDelete","sliceRead","sliceAssetUpdate","sliceAssetDelete","sliceAssetRead","sliceLibraryRead","customTypeCreate","customTypeUpdate","customTypeRename","customTypeDelete","customTypeRead","customTypeAssetUpdate","customTypeAssetDelete","customTypeAssetRead","customTypeLibraryRead","snippetRead","sliceSimulatorSetupRead"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AA0BO,MAAM,SAASA,UAAAA,yBAAwC;AAAA,EAC7D,MAAM;AAAA,IACL,MAAMC,SAAA;AAAA,EACN;AAAA,EACD,gBAAgB;AAAA,IACf,QAAQ;AAAA,EACR;AAAA,EACD,MAAM,EAAE,QAAM;AACb,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,cAAcC,UAAAA,SAAS;AAC5B,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,oBAAoBC,eAAAA,cAAc;AACvC,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAE3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,oBAAoBC,eAAAA,cAAc;AACvC,SAAK,4BAA4BC,sBAAAA,qBAAqB;AACtD,SAAK,4BAA4BC,sBAAAA,qBAAqB;AACtD,SAAK,0BAA0BC,oBAAAA,mBAAmB;AAClD,SAAK,4BAA4BC,sBAAAA,qBAAqB;AAEtD,SAAK,gBAAgBC,YAAAA,WAAW;AAEhC,SAAK,8BAA8BC,wBAAAA,uBAAuB;AAAA,EAC3D;AACA,CAAA;;"}
1
+ {"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { commandInit } from \"./hooks/command-init\";\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t\tlazyLoadSlices: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"command:init\", commandInit);\n\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":["defineSliceMachinePlugin","pkgName","commandInit","sliceCreate","sliceUpdate","sliceRename","sliceDelete","sliceRead","sliceAssetUpdate","sliceAssetDelete","sliceAssetRead","sliceLibraryRead","customTypeCreate","customTypeUpdate","customTypeRename","customTypeDelete","customTypeRead","customTypeAssetUpdate","customTypeAssetDelete","customTypeAssetRead","customTypeLibraryRead","snippetRead","sliceSimulatorSetupRead"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,SAASA,UAAAA,yBAAwC;AAAA,EAC7D,MAAM;AAAA,IACL,MAAMC,SAAA;AAAA,EACN;AAAA,EACD,gBAAgB;AAAA,IACf,QAAQ;AAAA,IACR,gBAAgB;AAAA,EAChB;AAAA,EACD,MAAM,EAAE,QAAM;AACb,SAAK,gBAAgBC,YAAAA,WAAW;AAEhC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,gBAAgBC,YAAAA,WAAW;AAChC,SAAK,cAAcC,UAAAA,SAAS;AAC5B,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,oBAAoBC,eAAAA,cAAc;AACvC,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAE3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,sBAAsBC,iBAAAA,gBAAgB;AAC3C,SAAK,oBAAoBC,eAAAA,cAAc;AACvC,SAAK,4BAA4BC,sBAAAA,qBAAqB;AACtD,SAAK,4BAA4BC,sBAAAA,qBAAqB;AACtD,SAAK,0BAA0BC,oBAAAA,mBAAmB;AAClD,SAAK,4BAA4BC,sBAAAA,qBAAqB;AAEtD,SAAK,gBAAgBC,YAAAA,WAAW;AAEhC,SAAK,8BAA8BC,wBAAAA,uBAAuB;AAAA,EAC3D;AACA,CAAA;;"}
package/dist/plugin.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { defineSliceMachinePlugin } from "@slicemachine/plugin-kit";
2
2
  import { name } from "./package.json.js";
3
+ import { commandInit } from "./hooks/command-init.js";
3
4
  import { customTypeAssetDelete } from "./hooks/customType-asset-delete.js";
4
5
  import { customTypeAssetRead } from "./hooks/customType-asset-read.js";
5
6
  import { customTypeAssetUpdate } from "./hooks/customType-asset-update.js";
@@ -25,9 +26,11 @@ const plugin = defineSliceMachinePlugin({
25
26
  name
26
27
  },
27
28
  defaultOptions: {
28
- format: true
29
+ format: true,
30
+ lazyLoadSlices: true
29
31
  },
30
32
  setup({ hook }) {
33
+ hook("command:init", commandInit);
31
34
  hook("slice:create", sliceCreate);
32
35
  hook("slice:update", sliceUpdate);
33
36
  hook("slice:rename", sliceRename);
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA0BO,MAAM,SAAS,yBAAwC;AAAA,EAC7D,MAAM;AAAA,IACL;AAAA,EACA;AAAA,EACD,gBAAgB;AAAA,IACf,QAAQ;AAAA,EACR;AAAA,EACD,MAAM,EAAE,QAAM;AACb,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,cAAc,SAAS;AAC5B,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,oBAAoB,cAAc;AACvC,SAAK,sBAAsB,gBAAgB;AAE3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,oBAAoB,cAAc;AACvC,SAAK,4BAA4B,qBAAqB;AACtD,SAAK,4BAA4B,qBAAqB;AACtD,SAAK,0BAA0B,mBAAmB;AAClD,SAAK,4BAA4B,qBAAqB;AAEtD,SAAK,gBAAgB,WAAW;AAEhC,SAAK,8BAA8B,uBAAuB;AAAA,EAC3D;AACA,CAAA;"}
1
+ {"version":3,"file":"plugin.js","sources":["../../src/plugin.ts"],"sourcesContent":["import { defineSliceMachinePlugin } from \"@slicemachine/plugin-kit\";\n\nimport { name as pkgName } from \"../package.json\";\nimport { PluginOptions } from \"./types\";\n\nimport { commandInit } from \"./hooks/command-init\";\nimport { customTypeAssetDelete } from \"./hooks/customType-asset-delete\";\nimport { customTypeAssetRead } from \"./hooks/customType-asset-read\";\nimport { customTypeAssetUpdate } from \"./hooks/customType-asset-update\";\nimport { customTypeCreate } from \"./hooks/customType-create\";\nimport { customTypeDelete } from \"./hooks/customType-delete\";\nimport { customTypeLibraryRead } from \"./hooks/customTypeLibrary-read\";\nimport { customTypeRead } from \"./hooks/customType-read\";\nimport { customTypeRename } from \"./hooks/customType-rename\";\nimport { customTypeUpdate } from \"./hooks/customType-update\";\nimport { sliceAssetDelete } from \"./hooks/slice-asset-delete\";\nimport { sliceAssetRead } from \"./hooks/slice-asset-read\";\nimport { sliceAssetUpdate } from \"./hooks/slice-asset-update\";\nimport { sliceCreate } from \"./hooks/slice-create\";\nimport { sliceDelete } from \"./hooks/slice-delete\";\nimport { sliceLibraryRead } from \"./hooks/sliceLibrary-read\";\nimport { sliceRead } from \"./hooks/slice-read\";\nimport { sliceRename } from \"./hooks/slice-rename\";\nimport { sliceSimulatorSetupRead } from \"./hooks/sliceSimulator-setup-read\";\nimport { sliceUpdate } from \"./hooks/slice-update\";\nimport { snippetRead } from \"./hooks/snippet-read\";\n\nexport const plugin = defineSliceMachinePlugin<PluginOptions>({\n\tmeta: {\n\t\tname: pkgName,\n\t},\n\tdefaultOptions: {\n\t\tformat: true,\n\t\tlazyLoadSlices: true,\n\t},\n\tsetup({ hook }) {\n\t\thook(\"command:init\", commandInit);\n\n\t\thook(\"slice:create\", sliceCreate);\n\t\thook(\"slice:update\", sliceUpdate);\n\t\thook(\"slice:rename\", sliceRename);\n\t\thook(\"slice:delete\", sliceDelete);\n\t\thook(\"slice:read\", sliceRead);\n\t\thook(\"slice:asset:update\", sliceAssetUpdate);\n\t\thook(\"slice:asset:delete\", sliceAssetDelete);\n\t\thook(\"slice:asset:read\", sliceAssetRead);\n\t\thook(\"slice-library:read\", sliceLibraryRead);\n\n\t\thook(\"custom-type:create\", customTypeCreate);\n\t\thook(\"custom-type:update\", customTypeUpdate);\n\t\thook(\"custom-type:rename\", customTypeRename);\n\t\thook(\"custom-type:delete\", customTypeDelete);\n\t\thook(\"custom-type:read\", customTypeRead);\n\t\thook(\"custom-type:asset:update\", customTypeAssetUpdate);\n\t\thook(\"custom-type:asset:delete\", customTypeAssetDelete);\n\t\thook(\"custom-type:asset:read\", customTypeAssetRead);\n\t\thook(\"custom-type-library:read\", customTypeLibraryRead);\n\n\t\thook(\"snippet:read\", snippetRead);\n\n\t\thook(\"slice-simulator:setup:read\", sliceSimulatorSetupRead);\n\t},\n});\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA2BO,MAAM,SAAS,yBAAwC;AAAA,EAC7D,MAAM;AAAA,IACL;AAAA,EACA;AAAA,EACD,gBAAgB;AAAA,IACf,QAAQ;AAAA,IACR,gBAAgB;AAAA,EAChB;AAAA,EACD,MAAM,EAAE,QAAM;AACb,SAAK,gBAAgB,WAAW;AAEhC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,gBAAgB,WAAW;AAChC,SAAK,cAAc,SAAS;AAC5B,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,oBAAoB,cAAc;AACvC,SAAK,sBAAsB,gBAAgB;AAE3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,sBAAsB,gBAAgB;AAC3C,SAAK,oBAAoB,cAAc;AACvC,SAAK,4BAA4B,qBAAqB;AACtD,SAAK,4BAA4B,qBAAqB;AACtD,SAAK,0BAA0B,mBAAmB;AAClD,SAAK,4BAA4B,qBAAqB;AAEtD,SAAK,gBAAgB,WAAW;AAEhC,SAAK,8BAA8B,uBAAuB;AAAA,EAC3D;AACA,CAAA;"}
@@ -21,12 +21,11 @@ function _interopNamespaceDefault(e) {
21
21
  }
22
22
  const React__namespace = /* @__PURE__ */ _interopNamespaceDefault(React);
23
23
  const coreManager = new sliceSimulatorCore.CoreManager();
24
- const SliceSimulator = ({ sliceZone: SliceZoneComp, state, background, zIndex, className }) => {
24
+ const SliceSimulator = ({ sliceZone: SliceZoneComp, background, zIndex, className }) => {
25
25
  const defaultProps = sliceSimulatorCore.getDefaultProps();
26
26
  const [managedState, setManagedState] = React__namespace.useState(() => sliceSimulatorCore.getDefaultManagedState());
27
27
  const [slices, setSlices] = React__namespace.useState(() => sliceSimulatorCore.getDefaultSlices());
28
28
  const [message, setMessage] = React__namespace.useState(() => sliceSimulatorCore.getDefaultMessage());
29
- const resolvedState = state || defaultProps.state;
30
29
  React__namespace.useEffect(() => {
31
30
  coreManager.stateManager.on(sliceSimulatorCore.StateManagerEventType.ManagedState, (_managedState) => {
32
31
  setManagedState(_managedState);
@@ -37,21 +36,13 @@ const SliceSimulator = ({ sliceZone: SliceZoneComp, state, background, zIndex, c
37
36
  coreManager.stateManager.on(sliceSimulatorCore.StateManagerEventType.Message, (_message) => {
38
37
  setMessage(_message);
39
38
  }, "simulator-message");
40
- coreManager.init(resolvedState);
39
+ coreManager.init(defaultProps.state);
41
40
  return () => {
42
41
  coreManager.stateManager.off(sliceSimulatorCore.StateManagerEventType.ManagedState, "simulator-managed-state");
43
42
  coreManager.stateManager.off(sliceSimulatorCore.StateManagerEventType.Slices, "simulator-slices");
44
43
  coreManager.stateManager.off(sliceSimulatorCore.StateManagerEventType.Message, "simulator-message");
45
44
  };
46
45
  }, []);
47
- const didMount = React__namespace.useRef(false);
48
- React__namespace.useEffect(() => {
49
- if (didMount.current) {
50
- coreManager.stateManager.reload(resolvedState);
51
- } else {
52
- didMount.current = true;
53
- }
54
- }, [resolvedState]);
55
46
  return jsxRuntime.jsx("div", { className: [sliceSimulatorCore.simulatorClass, className].filter(Boolean).join(" "), style: {
56
47
  zIndex: typeof zIndex === "undefined" ? defaultProps.zIndex : zIndex ?? void 0,
57
48
  position: "fixed",
@@ -1 +1 @@
1
- {"version":3,"file":"SliceSimulator.cjs","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tCoreManager,\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n\tStateManagerEventType,\n\tStateManagerStatus,\n\tdisableEventHandler,\n\tgetDefaultManagedState,\n\tgetDefaultMessage,\n\tgetDefaultProps,\n\tgetDefaultSlices,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/slice-simulator-core\";\n\nconst coreManager = new CoreManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/SliceSimulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;\n\tclassName?: string;\n} & BaseSliceSimulatorProps;\n\nexport const SliceSimulator = ({\n\tsliceZone: SliceZoneComp,\n\tstate,\n\tbackground,\n\tzIndex,\n\tclassName,\n}: SliceSimulatorProps): JSX.Element => {\n\tconst defaultProps = getDefaultProps();\n\n\tconst [managedState, setManagedState] = React.useState(() =>\n\t\tgetDefaultManagedState(),\n\t);\n\tconst [slices, setSlices] = React.useState(() => getDefaultSlices());\n\tconst [message, setMessage] = React.useState(() => getDefaultMessage());\n\n\tconst resolvedState = state || defaultProps.state;\n\n\tReact.useEffect(() => {\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.ManagedState,\n\t\t\t(_managedState) => {\n\t\t\t\tsetManagedState(_managedState);\n\t\t\t},\n\t\t\t\"simulator-managed-state\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Message,\n\t\t\t(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tcoreManager.init(resolvedState);\n\n\t\treturn () => {\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.ManagedState,\n\t\t\t\t\"simulator-managed-state\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Slices,\n\t\t\t\t\"simulator-slices\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Message,\n\t\t\t\t\"simulator-message\",\n\t\t\t);\n\t\t};\n\t}, []);\n\n\t// Update state on HMR\n\tconst didMount = React.useRef(false);\n\tReact.useEffect(() => {\n\t\tif (didMount.current) {\n\t\t\tcoreManager.stateManager.reload(resolvedState);\n\t\t} else {\n\t\t\tdidMount.current = true;\n\t\t}\n\t}, [resolvedState]);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: zIndex ?? undefined,\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: background ?? undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : slices.length ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tstyle={\n\t\t\t\t\t\tmanagedState.status !== StateManagerStatus.Loaded\n\t\t\t\t\t\t\t? { display: \"none\" }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SliceZoneComp slices={slices} />\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"names":["CoreManager","getDefaultProps","React","getDefaultManagedState","getDefaultSlices","getDefaultMessage","StateManagerEventType","_jsx","simulatorClass","simulatorRootClass","StateManagerStatus","onClickHandler","disableEventHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,cAAc,IAAIA,mBAAAA;AA6BX,MAAA,iBAAiB,CAAC,EAC9B,WAAW,eACX,OACA,YACA,QACA,gBACsC;AACtC,QAAM,eAAeC,mBAAAA;AAEf,QAAA,CAAC,cAAc,eAAe,IAAIC,iBAAM,SAAS,MACtDC,2CAAwB;AAEnB,QAAA,CAAC,QAAQ,SAAS,IAAID,iBAAM,SAAS,MAAME,qCAAkB;AAC7D,QAAA,CAAC,SAAS,UAAU,IAAIF,iBAAM,SAAS,MAAMG,sCAAmB;AAEhE,QAAA,gBAAgB,SAAS,aAAa;AAE5CH,mBAAM,UAAU,MAAK;AACpB,gBAAY,aAAa,GACxBI,mBAAsB,sBAAA,cACtB,CAAC,kBAAiB;AACjB,sBAAgB,aAAa;AAAA,OAE9B,yBAAyB;AAE1B,gBAAY,aAAa,GACxBA,mBAAsB,sBAAA,QACtB,CAAC,YAAW;AACX,gBAAU,OAAO;AAAA,OAElB,kBAAkB;AAEnB,gBAAY,aAAa,GACxBA,mBAAsB,sBAAA,SACtB,CAAC,aAAY;AACZ,iBAAW,QAAQ;AAAA,OAEpB,mBAAmB;AAGpB,gBAAY,KAAK,aAAa;AAE9B,WAAO,MAAK;AACX,kBAAY,aAAa,IACxBA,mBAAsB,sBAAA,cACtB,yBAAyB;AAG1B,kBAAY,aAAa,IACxBA,mBAAsB,sBAAA,QACtB,kBAAkB;AAGnB,kBAAY,aAAa,IACxBA,mBAAsB,sBAAA,SACtB,mBAAmB;AAAA,IAAA;AAAA,EAGtB,GAAG,CAAE,CAAA;AAGC,QAAA,WAAWJ,iBAAM,OAAO,KAAK;AACnCA,mBAAM,UAAU,MAAK;AACpB,QAAI,SAAS,SAAS;AACT,kBAAA,aAAa,OAAO,aAAa;AAAA,IAAA,OACvC;AACN,eAAS,UAAU;AAAA,IACnB;AAAA,EAAA,GACC,CAAC,aAAa,CAAC;AAElB,SACCK,wBACC,WAAW,CAACC,mBAAAA,gBAAgB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAC/D,OAAO;AAAA,IACN,QACC,OAAO,WAAW,cACf,aAAa,SACb,UAAU;AAAA,IACd,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,YACC,OAAO,eAAe,cACnB,aAAa,aACb,cAAc;AAAA,EAAA,GAClB,UAEA,UACAD,eAAA,WAAA,EAAS,yBAAyB,EAAE,QAAQ,UAAa,CAAA,IACtD,OAAO,SACVA,WAAA,IAAA,OAAA,EACC,IAAG,QACH,WAAWE,mBACX,oBAAA,OACC,aAAa,WAAWC,mBAAA,mBAAmB,SACxC,EAAE,SAAS,WACX,QAEJ,gBAAgBC,mCAChB,iBACCC,mBAAAA,qBAAwD,UAGzDL,WAAA,IAAC,iBAAc,OAAA,CAAc,EACxB,CAAA,IACH,KAAA,CACC;AAER;;"}
1
+ {"version":3,"file":"SliceSimulator.cjs","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tCoreManager,\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n\tStateManagerEventType,\n\tStateManagerStatus,\n\tdisableEventHandler,\n\tgetDefaultManagedState,\n\tgetDefaultMessage,\n\tgetDefaultProps,\n\tgetDefaultSlices,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/slice-simulator-core\";\n\nconst coreManager = new CoreManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;\n\tclassName?: string;\n} & Omit<BaseSliceSimulatorProps, \"state\">;\n\nexport const SliceSimulator = ({\n\tsliceZone: SliceZoneComp,\n\tbackground,\n\tzIndex,\n\tclassName,\n}: SliceSimulatorProps): JSX.Element => {\n\tconst defaultProps = getDefaultProps();\n\n\tconst [managedState, setManagedState] = React.useState(() =>\n\t\tgetDefaultManagedState(),\n\t);\n\tconst [slices, setSlices] = React.useState(() => getDefaultSlices());\n\tconst [message, setMessage] = React.useState(() => getDefaultMessage());\n\n\tReact.useEffect(() => {\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.ManagedState,\n\t\t\t(_managedState) => {\n\t\t\t\tsetManagedState(_managedState);\n\t\t\t},\n\t\t\t\"simulator-managed-state\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Message,\n\t\t\t(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tcoreManager.init(defaultProps.state);\n\n\t\treturn () => {\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.ManagedState,\n\t\t\t\t\"simulator-managed-state\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Slices,\n\t\t\t\t\"simulator-slices\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Message,\n\t\t\t\t\"simulator-message\",\n\t\t\t);\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: zIndex ?? undefined,\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: background ?? undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : slices.length ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tstyle={\n\t\t\t\t\t\tmanagedState.status !== StateManagerStatus.Loaded\n\t\t\t\t\t\t\t? { display: \"none\" }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SliceZoneComp slices={slices} />\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"names":["CoreManager","getDefaultProps","React","getDefaultManagedState","getDefaultSlices","getDefaultMessage","StateManagerEventType","_jsx","simulatorClass","simulatorRootClass","StateManagerStatus","onClickHandler","disableEventHandler"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAiBA,MAAM,cAAc,IAAIA,mBAAAA;AA6BX,MAAA,iBAAiB,CAAC,EAC9B,WAAW,eACX,YACA,QACA,gBACsC;AACtC,QAAM,eAAeC,mBAAAA;AAEf,QAAA,CAAC,cAAc,eAAe,IAAIC,iBAAM,SAAS,MACtDC,2CAAwB;AAEnB,QAAA,CAAC,QAAQ,SAAS,IAAID,iBAAM,SAAS,MAAME,qCAAkB;AAC7D,QAAA,CAAC,SAAS,UAAU,IAAIF,iBAAM,SAAS,MAAMG,sCAAmB;AAEtEH,mBAAM,UAAU,MAAK;AACpB,gBAAY,aAAa,GACxBI,mBAAsB,sBAAA,cACtB,CAAC,kBAAiB;AACjB,sBAAgB,aAAa;AAAA,OAE9B,yBAAyB;AAE1B,gBAAY,aAAa,GACxBA,mBAAsB,sBAAA,QACtB,CAAC,YAAW;AACX,gBAAU,OAAO;AAAA,OAElB,kBAAkB;AAEnB,gBAAY,aAAa,GACxBA,mBAAsB,sBAAA,SACtB,CAAC,aAAY;AACZ,iBAAW,QAAQ;AAAA,OAEpB,mBAAmB;AAGR,gBAAA,KAAK,aAAa,KAAK;AAEnC,WAAO,MAAK;AACX,kBAAY,aAAa,IACxBA,mBAAsB,sBAAA,cACtB,yBAAyB;AAG1B,kBAAY,aAAa,IACxBA,mBAAsB,sBAAA,QACtB,kBAAkB;AAGnB,kBAAY,aAAa,IACxBA,mBAAsB,sBAAA,SACtB,mBAAmB;AAAA,IAAA;AAAA,EAGtB,GAAG,CAAE,CAAA;AAEL,SACCC,wBACC,WAAW,CAACC,mBAAAA,gBAAgB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAC/D,OAAO;AAAA,IACN,QACC,OAAO,WAAW,cACf,aAAa,SACb,UAAU;AAAA,IACd,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,YACC,OAAO,eAAe,cACnB,aAAa,aACb,cAAc;AAAA,EAAA,GAClB,UAEA,UACAD,eAAA,WAAA,EAAS,yBAAyB,EAAE,QAAQ,UAAa,CAAA,IACtD,OAAO,SACVA,WAAA,IAAA,OAAA,EACC,IAAG,QACH,WAAWE,mBACX,oBAAA,OACC,aAAa,WAAWC,mBAAA,mBAAmB,SACxC,EAAE,SAAS,WACX,QAEJ,gBAAgBC,mCAChB,iBACCC,mBAAAA,qBAAwD,UAGzDL,WAAA,IAAC,iBAAc,OAAA,CAAc,EACxB,CAAA,IACH,KAAA,CACC;AAER;;"}
@@ -9,7 +9,7 @@ export type SliceSimulatorProps = {
9
9
  * @example
10
10
  *
11
11
  * ```tsx
12
- * import { SliceSimulator } from "@slicemachine/adapter-next/SliceSimulator";
12
+ * import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
13
13
  * import { SliceZone } from "@prismicio/react";
14
14
  *
15
15
  * import { components } from "../slices";
@@ -23,5 +23,5 @@ export type SliceSimulatorProps = {
23
23
  */
24
24
  sliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;
25
25
  className?: string;
26
- } & BaseSliceSimulatorProps;
27
- export declare const SliceSimulator: ({ sliceZone: SliceZoneComp, state, background, zIndex, className, }: SliceSimulatorProps) => JSX.Element;
26
+ } & Omit<BaseSliceSimulatorProps, "state">;
27
+ export declare const SliceSimulator: ({ sliceZone: SliceZoneComp, background, zIndex, className, }: SliceSimulatorProps) => JSX.Element;
@@ -2,12 +2,11 @@ import { jsx } from "react/jsx-runtime";
2
2
  import * as React from "react";
3
3
  import { CoreManager, getDefaultProps, getDefaultManagedState, getDefaultSlices, getDefaultMessage, StateManagerEventType, simulatorClass, simulatorRootClass, StateManagerStatus, onClickHandler, disableEventHandler } from "@prismicio/slice-simulator-core";
4
4
  const coreManager = new CoreManager();
5
- const SliceSimulator = ({ sliceZone: SliceZoneComp, state, background, zIndex, className }) => {
5
+ const SliceSimulator = ({ sliceZone: SliceZoneComp, background, zIndex, className }) => {
6
6
  const defaultProps = getDefaultProps();
7
7
  const [managedState, setManagedState] = React.useState(() => getDefaultManagedState());
8
8
  const [slices, setSlices] = React.useState(() => getDefaultSlices());
9
9
  const [message, setMessage] = React.useState(() => getDefaultMessage());
10
- const resolvedState = state || defaultProps.state;
11
10
  React.useEffect(() => {
12
11
  coreManager.stateManager.on(StateManagerEventType.ManagedState, (_managedState) => {
13
12
  setManagedState(_managedState);
@@ -18,21 +17,13 @@ const SliceSimulator = ({ sliceZone: SliceZoneComp, state, background, zIndex, c
18
17
  coreManager.stateManager.on(StateManagerEventType.Message, (_message) => {
19
18
  setMessage(_message);
20
19
  }, "simulator-message");
21
- coreManager.init(resolvedState);
20
+ coreManager.init(defaultProps.state);
22
21
  return () => {
23
22
  coreManager.stateManager.off(StateManagerEventType.ManagedState, "simulator-managed-state");
24
23
  coreManager.stateManager.off(StateManagerEventType.Slices, "simulator-slices");
25
24
  coreManager.stateManager.off(StateManagerEventType.Message, "simulator-message");
26
25
  };
27
26
  }, []);
28
- const didMount = React.useRef(false);
29
- React.useEffect(() => {
30
- if (didMount.current) {
31
- coreManager.stateManager.reload(resolvedState);
32
- } else {
33
- didMount.current = true;
34
- }
35
- }, [resolvedState]);
36
27
  return jsx("div", { className: [simulatorClass, className].filter(Boolean).join(" "), style: {
37
28
  zIndex: typeof zIndex === "undefined" ? defaultProps.zIndex : zIndex ?? void 0,
38
29
  position: "fixed",
@@ -1 +1 @@
1
- {"version":3,"file":"SliceSimulator.js","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tCoreManager,\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n\tStateManagerEventType,\n\tStateManagerStatus,\n\tdisableEventHandler,\n\tgetDefaultManagedState,\n\tgetDefaultMessage,\n\tgetDefaultProps,\n\tgetDefaultSlices,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/slice-simulator-core\";\n\nconst coreManager = new CoreManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/SliceSimulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;\n\tclassName?: string;\n} & BaseSliceSimulatorProps;\n\nexport const SliceSimulator = ({\n\tsliceZone: SliceZoneComp,\n\tstate,\n\tbackground,\n\tzIndex,\n\tclassName,\n}: SliceSimulatorProps): JSX.Element => {\n\tconst defaultProps = getDefaultProps();\n\n\tconst [managedState, setManagedState] = React.useState(() =>\n\t\tgetDefaultManagedState(),\n\t);\n\tconst [slices, setSlices] = React.useState(() => getDefaultSlices());\n\tconst [message, setMessage] = React.useState(() => getDefaultMessage());\n\n\tconst resolvedState = state || defaultProps.state;\n\n\tReact.useEffect(() => {\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.ManagedState,\n\t\t\t(_managedState) => {\n\t\t\t\tsetManagedState(_managedState);\n\t\t\t},\n\t\t\t\"simulator-managed-state\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Message,\n\t\t\t(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tcoreManager.init(resolvedState);\n\n\t\treturn () => {\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.ManagedState,\n\t\t\t\t\"simulator-managed-state\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Slices,\n\t\t\t\t\"simulator-slices\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Message,\n\t\t\t\t\"simulator-message\",\n\t\t\t);\n\t\t};\n\t}, []);\n\n\t// Update state on HMR\n\tconst didMount = React.useRef(false);\n\tReact.useEffect(() => {\n\t\tif (didMount.current) {\n\t\t\tcoreManager.stateManager.reload(resolvedState);\n\t\t} else {\n\t\t\tdidMount.current = true;\n\t\t}\n\t}, [resolvedState]);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: zIndex ?? undefined,\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: background ?? undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : slices.length ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tstyle={\n\t\t\t\t\t\tmanagedState.status !== StateManagerStatus.Loaded\n\t\t\t\t\t\t\t? { display: \"none\" }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SliceZoneComp slices={slices} />\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"names":["_jsx"],"mappings":";;;AAiBA,MAAM,cAAc,IAAI;AA6BX,MAAA,iBAAiB,CAAC,EAC9B,WAAW,eACX,OACA,YACA,QACA,gBACsC;AACtC,QAAM,eAAe;AAEf,QAAA,CAAC,cAAc,eAAe,IAAI,MAAM,SAAS,MACtD,wBAAwB;AAEnB,QAAA,CAAC,QAAQ,SAAS,IAAI,MAAM,SAAS,MAAM,kBAAkB;AAC7D,QAAA,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,MAAM,mBAAmB;AAEhE,QAAA,gBAAgB,SAAS,aAAa;AAE5C,QAAM,UAAU,MAAK;AACpB,gBAAY,aAAa,GACxB,sBAAsB,cACtB,CAAC,kBAAiB;AACjB,sBAAgB,aAAa;AAAA,OAE9B,yBAAyB;AAE1B,gBAAY,aAAa,GACxB,sBAAsB,QACtB,CAAC,YAAW;AACX,gBAAU,OAAO;AAAA,OAElB,kBAAkB;AAEnB,gBAAY,aAAa,GACxB,sBAAsB,SACtB,CAAC,aAAY;AACZ,iBAAW,QAAQ;AAAA,OAEpB,mBAAmB;AAGpB,gBAAY,KAAK,aAAa;AAE9B,WAAO,MAAK;AACX,kBAAY,aAAa,IACxB,sBAAsB,cACtB,yBAAyB;AAG1B,kBAAY,aAAa,IACxB,sBAAsB,QACtB,kBAAkB;AAGnB,kBAAY,aAAa,IACxB,sBAAsB,SACtB,mBAAmB;AAAA,IAAA;AAAA,EAGtB,GAAG,CAAE,CAAA;AAGC,QAAA,WAAW,MAAM,OAAO,KAAK;AACnC,QAAM,UAAU,MAAK;AACpB,QAAI,SAAS,SAAS;AACT,kBAAA,aAAa,OAAO,aAAa;AAAA,IAAA,OACvC;AACN,eAAS,UAAU;AAAA,IACnB;AAAA,EAAA,GACC,CAAC,aAAa,CAAC;AAElB,SACCA,aACC,WAAW,CAAC,gBAAgB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAC/D,OAAO;AAAA,IACN,QACC,OAAO,WAAW,cACf,aAAa,SACb,UAAU;AAAA,IACd,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,YACC,OAAO,eAAe,cACnB,aAAa,aACb,cAAc;AAAA,EAAA,GAClB,UAEA,UACAA,IAAA,WAAA,EAAS,yBAAyB,EAAE,QAAQ,UAAa,CAAA,IACtD,OAAO,SACVA,IAAA,OAAA,EACC,IAAG,QACH,WAAW,oBACX,OACC,aAAa,WAAW,mBAAmB,SACxC,EAAE,SAAS,WACX,QAEJ,gBAAgB,gBAChB,iBACC,qBAAwD,UAGzDA,IAAC,iBAAc,OAAA,CAAc,EACxB,CAAA,IACH,KAAA,CACC;AAER;"}
1
+ {"version":3,"file":"SliceSimulator.js","sources":["../../../src/simulator/SliceSimulator.tsx"],"sourcesContent":["import * as React from \"react\";\nimport {\n\tCoreManager,\n\tSliceSimulatorProps as BaseSliceSimulatorProps,\n\tSliceSimulatorState,\n\tStateManagerEventType,\n\tStateManagerStatus,\n\tdisableEventHandler,\n\tgetDefaultManagedState,\n\tgetDefaultMessage,\n\tgetDefaultProps,\n\tgetDefaultSlices,\n\tonClickHandler,\n\tsimulatorClass,\n\tsimulatorRootClass,\n} from \"@prismicio/slice-simulator-core\";\n\nconst coreManager = new CoreManager();\n\nexport type SliceSimulatorSliceZoneProps = {\n\tslices: SliceSimulatorState[\"slices\"];\n};\n\nexport type SliceSimulatorProps = {\n\t/**\n\t * React component to render simulated Slices.\n\t *\n\t * @example\n\t *\n\t * ```tsx\n\t * import { SliceSimulator } from \"@slicemachine/adapter-next/simulator\";\n\t * import { SliceZone } from \"@prismicio/react\";\n\t *\n\t * import { components } from \"../slices\";\n\t *\n\t * <SliceSimulator\n\t * \tsliceZone={({ slices }) => (\n\t * \t\t<SliceZone slices={slices} components={components} />\n\t * \t)}\n\t * />;\n\t * ```\n\t */\n\tsliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;\n\tclassName?: string;\n} & Omit<BaseSliceSimulatorProps, \"state\">;\n\nexport const SliceSimulator = ({\n\tsliceZone: SliceZoneComp,\n\tbackground,\n\tzIndex,\n\tclassName,\n}: SliceSimulatorProps): JSX.Element => {\n\tconst defaultProps = getDefaultProps();\n\n\tconst [managedState, setManagedState] = React.useState(() =>\n\t\tgetDefaultManagedState(),\n\t);\n\tconst [slices, setSlices] = React.useState(() => getDefaultSlices());\n\tconst [message, setMessage] = React.useState(() => getDefaultMessage());\n\n\tReact.useEffect(() => {\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.ManagedState,\n\t\t\t(_managedState) => {\n\t\t\t\tsetManagedState(_managedState);\n\t\t\t},\n\t\t\t\"simulator-managed-state\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Slices,\n\t\t\t(_slices) => {\n\t\t\t\tsetSlices(_slices);\n\t\t\t},\n\t\t\t\"simulator-slices\",\n\t\t);\n\t\tcoreManager.stateManager.on(\n\t\t\tStateManagerEventType.Message,\n\t\t\t(_message) => {\n\t\t\t\tsetMessage(_message);\n\t\t\t},\n\t\t\t\"simulator-message\",\n\t\t);\n\n\t\tcoreManager.init(defaultProps.state);\n\n\t\treturn () => {\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.ManagedState,\n\t\t\t\t\"simulator-managed-state\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Slices,\n\t\t\t\t\"simulator-slices\",\n\t\t\t);\n\n\t\t\tcoreManager.stateManager.off(\n\t\t\t\tStateManagerEventType.Message,\n\t\t\t\t\"simulator-message\",\n\t\t\t);\n\t\t};\n\t}, []);\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[simulatorClass, className].filter(Boolean).join(\" \")}\n\t\t\tstyle={{\n\t\t\t\tzIndex:\n\t\t\t\t\ttypeof zIndex === \"undefined\"\n\t\t\t\t\t\t? defaultProps.zIndex\n\t\t\t\t\t\t: zIndex ?? undefined,\n\t\t\t\tposition: \"fixed\",\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\twidth: \"100%\",\n\t\t\t\theight: \"100vh\",\n\t\t\t\toverflow: \"auto\",\n\t\t\t\tbackground:\n\t\t\t\t\ttypeof background === \"undefined\"\n\t\t\t\t\t\t? defaultProps.background\n\t\t\t\t\t\t: background ?? undefined,\n\t\t\t}}\n\t\t>\n\t\t\t{message ? (\n\t\t\t\t<article dangerouslySetInnerHTML={{ __html: message }} />\n\t\t\t) : slices.length ? (\n\t\t\t\t<div\n\t\t\t\t\tid=\"root\"\n\t\t\t\t\tclassName={simulatorRootClass}\n\t\t\t\t\tstyle={\n\t\t\t\t\t\tmanagedState.status !== StateManagerStatus.Loaded\n\t\t\t\t\t\t\t? { display: \"none\" }\n\t\t\t\t\t\t\t: undefined\n\t\t\t\t\t}\n\t\t\t\t\tonClickCapture={onClickHandler as unknown as React.MouseEventHandler}\n\t\t\t\t\tonSubmitCapture={\n\t\t\t\t\t\tdisableEventHandler as unknown as React.FormEventHandler\n\t\t\t\t\t}\n\t\t\t\t>\n\t\t\t\t\t<SliceZoneComp slices={slices} />\n\t\t\t\t</div>\n\t\t\t) : null}\n\t\t</div>\n\t);\n};\n"],"names":["_jsx"],"mappings":";;;AAiBA,MAAM,cAAc,IAAI;AA6BX,MAAA,iBAAiB,CAAC,EAC9B,WAAW,eACX,YACA,QACA,gBACsC;AACtC,QAAM,eAAe;AAEf,QAAA,CAAC,cAAc,eAAe,IAAI,MAAM,SAAS,MACtD,wBAAwB;AAEnB,QAAA,CAAC,QAAQ,SAAS,IAAI,MAAM,SAAS,MAAM,kBAAkB;AAC7D,QAAA,CAAC,SAAS,UAAU,IAAI,MAAM,SAAS,MAAM,mBAAmB;AAEtE,QAAM,UAAU,MAAK;AACpB,gBAAY,aAAa,GACxB,sBAAsB,cACtB,CAAC,kBAAiB;AACjB,sBAAgB,aAAa;AAAA,OAE9B,yBAAyB;AAE1B,gBAAY,aAAa,GACxB,sBAAsB,QACtB,CAAC,YAAW;AACX,gBAAU,OAAO;AAAA,OAElB,kBAAkB;AAEnB,gBAAY,aAAa,GACxB,sBAAsB,SACtB,CAAC,aAAY;AACZ,iBAAW,QAAQ;AAAA,OAEpB,mBAAmB;AAGR,gBAAA,KAAK,aAAa,KAAK;AAEnC,WAAO,MAAK;AACX,kBAAY,aAAa,IACxB,sBAAsB,cACtB,yBAAyB;AAG1B,kBAAY,aAAa,IACxB,sBAAsB,QACtB,kBAAkB;AAGnB,kBAAY,aAAa,IACxB,sBAAsB,SACtB,mBAAmB;AAAA,IAAA;AAAA,EAGtB,GAAG,CAAE,CAAA;AAEL,SACCA,aACC,WAAW,CAAC,gBAAgB,SAAS,EAAE,OAAO,OAAO,EAAE,KAAK,GAAG,GAC/D,OAAO;AAAA,IACN,QACC,OAAO,WAAW,cACf,aAAa,SACb,UAAU;AAAA,IACd,UAAU;AAAA,IACV,KAAK;AAAA,IACL,MAAM;AAAA,IACN,OAAO;AAAA,IACP,QAAQ;AAAA,IACR,UAAU;AAAA,IACV,YACC,OAAO,eAAe,cACnB,aAAa,aACb,cAAc;AAAA,EAAA,GAClB,UAEA,UACAA,IAAA,WAAA,EAAS,yBAAyB,EAAE,QAAQ,UAAa,CAAA,IACtD,OAAO,SACVA,IAAA,OAAA,EACC,IAAG,QACH,WAAW,oBACX,OACC,aAAa,WAAW,mBAAmB,SACxC,EAAE,SAAS,WACX,QAEJ,gBAAgB,gBAChB,iBACC,qBAAwD,UAGzDA,IAAC,iBAAc,OAAA,CAAc,EACxB,CAAA,IACH,KAAA,CACC;AAER;"}
package/dist/types.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  export type PluginOptions = {
2
2
  format?: boolean;
3
+ lazyLoadSlices?: boolean;
3
4
  } & ({
4
5
  typescript?: false;
5
6
  jsxExtension?: boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@slicemachine/adapter-next",
3
- "version": "0.0.8",
3
+ "version": "0.0.10",
4
4
  "description": "Slice Machine adapter for Next.js.",
5
5
  "keywords": [
6
6
  "typescript",
@@ -59,7 +59,7 @@
59
59
  "dependencies": {
60
60
  "@prismicio/slice-simulator-core": "^0.2.7",
61
61
  "@prismicio/types": "^0.2.7",
62
- "@slicemachine/plugin-kit": "^0.1.8",
62
+ "@slicemachine/plugin-kit": "0.1.8-dev-plugins.12",
63
63
  "common-tags": "^1.8.2",
64
64
  "fs-extra": "^11.1.0",
65
65
  "node-fetch": "^3.3.0",
@@ -68,31 +68,31 @@
68
68
  },
69
69
  "devDependencies": {
70
70
  "@prismicio/mock": "^0.2.0",
71
- "@size-limit/preset-small-lib": "^8.1.0",
71
+ "@size-limit/preset-small-lib": "^8.2.4",
72
72
  "@types/common-tags": "^1.8.1",
73
- "@types/fs-extra": "^11.0.0",
73
+ "@types/fs-extra": "^11.0.1",
74
74
  "@types/prettier": "^2.7.2",
75
- "@types/react": "^18.0.26",
75
+ "@types/react": "^18.0.28",
76
76
  "@types/semver": "^7.3.13",
77
- "@typescript-eslint/eslint-plugin": "^5.48.1",
78
- "@typescript-eslint/parser": "^5.48.1",
79
- "@vitejs/plugin-react": "^3.0.1",
80
- "@vitest/coverage-c8": "^0.27.0",
81
- "eslint": "^8.31.0",
77
+ "@typescript-eslint/eslint-plugin": "^5.54.0",
78
+ "@typescript-eslint/parser": "^5.54.0",
79
+ "@vitejs/plugin-react": "^3.1.0",
80
+ "@vitest/coverage-c8": "^0.29.1",
81
+ "eslint": "^8.35.0",
82
82
  "eslint-config-prettier": "^8.6.0",
83
83
  "eslint-plugin-prettier": "^4.2.1",
84
84
  "eslint-plugin-tsdoc": "^0.2.17",
85
85
  "npm-run-all": "^4.1.5",
86
- "prettier": "^2.8.2",
86
+ "prettier": "^2.8.4",
87
87
  "prettier-plugin-jsdoc": "^0.4.2",
88
88
  "react": "^18.2.0",
89
- "size-limit": "^8.1.0",
89
+ "size-limit": "^8.2.4",
90
90
  "standard-version": "^9.5.0",
91
91
  "ts-morph": "^17.0.1",
92
- "typescript": "^4.9.4",
93
- "vite": "^4.0.4",
92
+ "typescript": "^4.9.5",
93
+ "vite": "^4.1.4",
94
94
  "vite-plugin-sdk": "^0.1.0",
95
- "vitest": "^0.27.0"
95
+ "vitest": "^0.29.1"
96
96
  },
97
97
  "peerDependencies": {
98
98
  "next": "^11 || ^12 || ^13",
@@ -0,0 +1,221 @@
1
+ import * as fs from "node:fs/promises";
2
+ import * as path from "node:path";
3
+ import type {
4
+ CommandInitHook,
5
+ CommandInitHookData,
6
+ SliceMachineContext,
7
+ } from "@slicemachine/plugin-kit";
8
+ import { stripIndent } from "common-tags";
9
+
10
+ import { checkPathExists } from "../lib/checkPathExists";
11
+ import { getJSOrTSXFileExtension } from "../lib/getJSOrTSXFileExtension";
12
+ import { rejectIfNecessary } from "../lib/rejectIfNecessary";
13
+
14
+ import type { PluginOptions } from "../types";
15
+
16
+ type InstallDependenciesArgs = {
17
+ installDependencies: CommandInitHookData["installDependencies"];
18
+ };
19
+
20
+ const installDependencies = async ({
21
+ installDependencies,
22
+ }: InstallDependenciesArgs) => {
23
+ await installDependencies({
24
+ dependencies: {
25
+ "@prismicio/client": "latest",
26
+ "@prismicio/next": "latest",
27
+ },
28
+ });
29
+
30
+ await installDependencies({
31
+ dependencies: {
32
+ "@prismicio/types": "latest",
33
+ },
34
+ dev: true,
35
+ });
36
+ };
37
+
38
+ type CreatePrismicIOFileArgs = SliceMachineContext<PluginOptions>;
39
+
40
+ const createPrismicIOFile = async ({
41
+ helpers,
42
+ options,
43
+ }: CreatePrismicIOFileArgs) => {
44
+ const filePath = helpers.joinPathFromRoot(
45
+ options.typescript ? "prismicio.ts" : "prismicio.js",
46
+ );
47
+
48
+ if (await checkPathExists(filePath)) {
49
+ return;
50
+ }
51
+
52
+ let contents: string;
53
+
54
+ if (options.typescript) {
55
+ contents = stripIndent`
56
+ import * as prismic from "@prismicio/client";
57
+ import * as prismicNext from "@prismicio/next";
58
+ import config from "./slicemachine.config.json";
59
+
60
+ /**
61
+ * The project's Prismic repository name.
62
+ */
63
+ export const repositoryName = config.repositoryName;
64
+
65
+ /**
66
+ * A list of Route Resolver objects that define how a document's \`url\` field
67
+ * is resolved.
68
+ *
69
+ * {@link https://prismic.io/docs/route-resolver#route-resolver}
70
+ */
71
+ // TODO: Update the routes array to match your project's route structure.
72
+ const routes: prismic.ClientConfig["routes"] = [
73
+ {
74
+ type: "homepage",
75
+ path: "/",
76
+ },
77
+ {
78
+ type: "page",
79
+ path: "/:uid",
80
+ },
81
+ ];
82
+
83
+ /**
84
+ * Creates a Prismic client for the project's repository. The client is used to
85
+ * query content from the Prismic API.
86
+ *
87
+ * @param config - Configuration for the Prismic client.
88
+ */
89
+ export const createClient = (config: prismicNext.CreateClientConfig = {}) => {
90
+ const client = prismic.createClient(repositoryName, {
91
+ routes,
92
+ ...config,
93
+ });
94
+
95
+ prismicNext.enableAutoPreviews({
96
+ client,
97
+ previewData: config.previewData,
98
+ req: config.req,
99
+ });
100
+
101
+ return client;
102
+ };
103
+ `;
104
+ } else {
105
+ contents = stripIndent`
106
+ import * as prismic from "@prismicio/client";
107
+ import * as prismicNext from "@prismicio/next";
108
+ import config from "./slicemachine.config.json";
109
+
110
+ /**
111
+ * The project's Prismic repository name.
112
+ */
113
+ export const repositoryName = config.repositoryName;
114
+
115
+ /**
116
+ * A list of Route Resolver objects that define how a document's \`url\` field
117
+ * is resolved.
118
+ *
119
+ * {@link https://prismic.io/docs/route-resolver#route-resolver}
120
+ *
121
+ * @type {prismic.ClientConfig["routes"]}
122
+ */
123
+ // TODO: Update the routes array to match your project's route structure.
124
+ const routes = [
125
+ {
126
+ type: "homepage",
127
+ path: "/",
128
+ },
129
+ {
130
+ type: "page",
131
+ path: "/:uid",
132
+ },
133
+ ];
134
+
135
+ /**
136
+ * Creates a Prismic client for the project's repository. The client is used to
137
+ * query content from the Prismic API.
138
+ *
139
+ * @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
140
+ */
141
+ export const createClient = (config = {}) => {
142
+ const client = prismic.createClient(repositoryName, {
143
+ routes,
144
+ ...config,
145
+ });
146
+
147
+ prismicNext.enableAutoPreviews({
148
+ client,
149
+ previewData: config.previewData,
150
+ req: config.req,
151
+ });
152
+
153
+ return client;
154
+ };
155
+ `;
156
+ }
157
+
158
+ if (options.format) {
159
+ contents = await helpers.format(contents, filePath);
160
+ }
161
+
162
+ await fs.writeFile(filePath, contents);
163
+ };
164
+
165
+ type CreateSliceSimulatorPageArgs = SliceMachineContext<PluginOptions>;
166
+
167
+ const createSliceSimulatorPage = async ({
168
+ helpers,
169
+ options,
170
+ }: CreateSliceSimulatorPageArgs) => {
171
+ const srcDirectoryExists = await checkPathExists(
172
+ helpers.joinPathFromRoot("src"),
173
+ );
174
+
175
+ const filePath = helpers.joinPathFromRoot(
176
+ srcDirectoryExists ? "src/pages" : "pages",
177
+ `slice-simulator.${getJSOrTSXFileExtension(options)}`,
178
+ );
179
+
180
+ if (await checkPathExists(filePath)) {
181
+ return;
182
+ }
183
+
184
+ await fs.mkdir(path.dirname(filePath), { recursive: true });
185
+
186
+ let contents = stripIndent`
187
+ import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
188
+ import { SliceZone } from "@prismicio/react";
189
+
190
+ import { components } from "../slices";
191
+
192
+ const SliceSimulatorPage = () => {
193
+ return (
194
+ <SliceSimulator
195
+ sliceZone={(props) => <SliceZone {...props} components={components} />}
196
+ />
197
+ );
198
+ };
199
+
200
+ export default SliceSimulatorPage;
201
+ `;
202
+
203
+ if (options.format) {
204
+ contents = await helpers.format(contents, filePath);
205
+ }
206
+
207
+ await fs.writeFile(filePath, contents);
208
+ };
209
+
210
+ export const commandInit: CommandInitHook<PluginOptions> = async (
211
+ { installDependencies: _installDependencies },
212
+ context,
213
+ ) => {
214
+ rejectIfNecessary(
215
+ await Promise.allSettled([
216
+ await installDependencies({ installDependencies: _installDependencies }),
217
+ await createPrismicIOFile(context),
218
+ await createSliceSimulatorPage(context),
219
+ ]),
220
+ );
221
+ };
@@ -0,0 +1,12 @@
1
+ import * as fs from "node:fs/promises";
2
+ import { PathLike } from "node:fs";
3
+
4
+ export const checkPathExists = async (path: PathLike): Promise<boolean> => {
5
+ try {
6
+ await fs.access(path);
7
+
8
+ return true;
9
+ } catch {
10
+ return false;
11
+ }
12
+ };
@@ -23,22 +23,50 @@ export const upsertSliceLibraryIndexFile = async (
23
23
  libraryID: args.libraryID,
24
24
  });
25
25
 
26
- let contents = stripIndent`
27
- ${NON_EDITABLE_FILE_BANNER}
26
+ let contents: string;
28
27
 
29
- import dynamic from 'next/dynamic'
28
+ if (args.options.lazyLoadSlices) {
29
+ contents = stripIndent`
30
+ ${NON_EDITABLE_FILE_BANNER}
31
+
32
+ import dynamic from 'next/dynamic'
33
+
34
+ export const components = {
35
+ ${slices
36
+ .map((slice) => {
37
+ const id = slice.model.id;
38
+ const dirName = pascalCase(slice.model.name);
39
+
40
+ return `${id}: dynamic(() => import('./${dirName}'))`;
41
+ })
42
+ .join(",\n")}
43
+ }
44
+ `;
45
+ } else {
46
+ contents = stripIndent`
47
+ ${NON_EDITABLE_FILE_BANNER}
30
48
 
31
- export const components = {
32
49
  ${slices
33
50
  .map((slice) => {
34
- const id = slice.model.id;
51
+ const componentName = pascalCase(slice.model.name);
35
52
  const dirName = pascalCase(slice.model.name);
36
53
 
37
- return `${id}: dynamic(() => import('./${dirName}'))`;
54
+ return `import ${componentName} from "./${dirName}";`;
38
55
  })
39
- .join(",\n")}
40
- }
41
- `;
56
+ .join("\n")}
57
+
58
+ export const components = {
59
+ ${slices
60
+ .map((slice) => {
61
+ const id = slice.model.id;
62
+ const componentName = pascalCase(slice.model.name);
63
+
64
+ return `${id}: ${componentName},`;
65
+ })
66
+ .join("\n")}
67
+ }
68
+ `;
69
+ }
42
70
 
43
71
  if (args.options.format) {
44
72
  contents = await args.helpers.format(contents, filePath);
package/src/plugin.ts CHANGED
@@ -3,6 +3,7 @@ import { defineSliceMachinePlugin } from "@slicemachine/plugin-kit";
3
3
  import { name as pkgName } from "../package.json";
4
4
  import { PluginOptions } from "./types";
5
5
 
6
+ import { commandInit } from "./hooks/command-init";
6
7
  import { customTypeAssetDelete } from "./hooks/customType-asset-delete";
7
8
  import { customTypeAssetRead } from "./hooks/customType-asset-read";
8
9
  import { customTypeAssetUpdate } from "./hooks/customType-asset-update";
@@ -30,8 +31,11 @@ export const plugin = defineSliceMachinePlugin<PluginOptions>({
30
31
  },
31
32
  defaultOptions: {
32
33
  format: true,
34
+ lazyLoadSlices: true,
33
35
  },
34
36
  setup({ hook }) {
37
+ hook("command:init", commandInit);
38
+
35
39
  hook("slice:create", sliceCreate);
36
40
  hook("slice:update", sliceUpdate);
37
41
  hook("slice:rename", sliceRename);