@slicemachine/adapter-next 0.0.7 → 0.0.9
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/dist/lib/upsertGlobalContentTypes.cjs +1 -1
- package/dist/lib/upsertGlobalContentTypes.cjs.map +1 -1
- package/dist/lib/upsertGlobalContentTypes.js +1 -1
- package/dist/lib/upsertGlobalContentTypes.js.map +1 -1
- package/dist/simulator/SliceSimulator.cjs +2 -11
- package/dist/simulator/SliceSimulator.cjs.map +1 -1
- package/dist/simulator/SliceSimulator.d.ts +3 -3
- package/dist/simulator/SliceSimulator.js +2 -11
- package/dist/simulator/SliceSimulator.js.map +1 -1
- package/package.json +1 -1
- package/src/lib/upsertGlobalContentTypes.ts +1 -1
- package/src/simulator/SliceSimulator.tsx +3 -16
|
@@ -23,7 +23,7 @@ function _interopNamespaceDefault(e) {
|
|
|
23
23
|
const fs__namespace = /* @__PURE__ */ _interopNamespaceDefault(fs);
|
|
24
24
|
const path__namespace = /* @__PURE__ */ _interopNamespaceDefault(path);
|
|
25
25
|
const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
26
|
-
const filePath = helpers.joinPathFromRoot("
|
|
26
|
+
const filePath = helpers.joinPathFromRoot("prismicio.d.ts");
|
|
27
27
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
28
28
|
actions.readAllCustomTypeModels(),
|
|
29
29
|
actions.readAllSliceModels()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"actions\" | \"helpers\" | \"options\"\n>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"
|
|
1
|
+
{"version":3,"file":"upsertGlobalContentTypes.cjs","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"actions\" | \"helpers\" | \"options\"\n>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"prismicio.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors","generateTypes","NON_EDITABLE_FILE_BANNER","fs","path"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;AAoBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,cAC0C;AACpC,QAAA,WAAW,QAAQ,iBAAiB,gBAAgB;AAE1D,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAWC,iBAAAA,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,EAAA,CACD;AAED,aAAW,GAAGC;;EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAAC,cAAG,MAAMC,gBAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAAD,cAAG,UAAU,UAAU,QAAQ;AACtC;;"}
|
|
@@ -3,7 +3,7 @@ import * as fs from "node:fs/promises";
|
|
|
3
3
|
import * as path from "node:path";
|
|
4
4
|
import { NON_EDITABLE_FILE_BANNER } from "../constants.js";
|
|
5
5
|
const upsertGlobalContentTypes = async ({ actions, helpers, options }) => {
|
|
6
|
-
const filePath = helpers.joinPathFromRoot("
|
|
6
|
+
const filePath = helpers.joinPathFromRoot("prismicio.d.ts");
|
|
7
7
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] = await Promise.all([
|
|
8
8
|
actions.readAllCustomTypeModels(),
|
|
9
9
|
actions.readAllSliceModels()
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"actions\" | \"helpers\" | \"options\"\n>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"
|
|
1
|
+
{"version":3,"file":"upsertGlobalContentTypes.js","sources":["../../../src/lib/upsertGlobalContentTypes.ts"],"sourcesContent":["import type { SliceMachineContext } from \"@slicemachine/plugin-kit\";\nimport { generateTypes } from \"prismic-ts-codegen\";\nimport * as fs from \"node:fs/promises\";\nimport * as path from \"node:path\";\n\nimport type { PluginOptions } from \"../types\";\nimport { NON_EDITABLE_FILE_BANNER } from \"../constants\";\n\n/**\n * Arguments for `upsertGlobalContentTypes()`.\n */\ntype UpsertGlobalTypesArgs = Pick<\n\tSliceMachineContext<PluginOptions>,\n\t\"actions\" | \"helpers\" | \"options\"\n>;\n\n/**\n * Creates a globally accessible TypeScript file containing types representing\n * the Prismic repository's content.\n */\nexport const upsertGlobalContentTypes = async ({\n\tactions,\n\thelpers,\n\toptions,\n}: UpsertGlobalTypesArgs): Promise<void> => {\n\tconst filePath = helpers.joinPathFromRoot(\"prismicio.d.ts\");\n\n\tconst [customTypeModelDescriptors, sharedSliceModelDescriptors] =\n\t\tawait Promise.all([\n\t\t\tactions.readAllCustomTypeModels(),\n\t\t\tactions.readAllSliceModels(),\n\t\t]);\n\n\tconst customTypeModels = customTypeModelDescriptors.map(\n\t\t(customTypeModelDescriptors) => {\n\t\t\treturn customTypeModelDescriptors.model;\n\t\t},\n\t);\n\tconst sharedSliceModels = sharedSliceModelDescriptors.map(\n\t\t(sharedSliceModelDescriptors) => {\n\t\t\treturn sharedSliceModelDescriptors.model;\n\t\t},\n\t);\n\n\tlet contents = generateTypes({\n\t\tcustomTypeModels,\n\t\tsharedSliceModels,\n\t\tclientIntegration: {\n\t\t\tincludeCreateClientInterface: true,\n\t\t\tincludeContentNamespace: true,\n\t\t},\n\t});\n\n\tcontents = `${NON_EDITABLE_FILE_BANNER}\\n\\n${contents}`;\n\n\tif (options.format) {\n\t\tcontents = await helpers.format(contents, filePath);\n\t}\n\n\tawait fs.mkdir(path.dirname(filePath), { recursive: true });\n\tawait fs.writeFile(filePath, contents);\n};\n"],"names":["customTypeModelDescriptors","sharedSliceModelDescriptors"],"mappings":";;;;AAoBO,MAAM,2BAA2B,OAAO,EAC9C,SACA,SACA,cAC0C;AACpC,QAAA,WAAW,QAAQ,iBAAiB,gBAAgB;AAE1D,QAAM,CAAC,4BAA4B,2BAA2B,IAC7D,MAAM,QAAQ,IAAI;AAAA,IACjB,QAAQ,wBAAyB;AAAA,IACjC,QAAQ,mBAAoB;AAAA,EAAA,CAC5B;AAEF,QAAM,mBAAmB,2BAA2B,IACnD,CAACA,gCAA8B;AAC9B,WAAOA,4BAA2B;AAAA,EAAA,CAClC;AAEF,QAAM,oBAAoB,4BAA4B,IACrD,CAACC,iCAA+B;AAC/B,WAAOA,6BAA4B;AAAA,EAAA,CACnC;AAGF,MAAI,WAAW,cAAc;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,mBAAmB;AAAA,MAClB,8BAA8B;AAAA,MAC9B,yBAAyB;AAAA,IACzB;AAAA,EAAA,CACD;AAED,aAAW,GAAG;AAAA;AAAA,EAA+B;AAE7C,MAAI,QAAQ,QAAQ;AACnB,eAAW,MAAM,QAAQ,OAAO,UAAU,QAAQ;AAAA,EAClD;AAEK,QAAA,GAAG,MAAM,KAAK,QAAQ,QAAQ,GAAG,EAAE,WAAW,KAAA,CAAM;AACpD,QAAA,GAAG,UAAU,UAAU,QAAQ;AACtC;"}
|
|
@@ -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,
|
|
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(
|
|
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/
|
|
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/
|
|
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,
|
|
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,
|
|
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(
|
|
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/
|
|
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/package.json
CHANGED
|
@@ -23,7 +23,7 @@ export const upsertGlobalContentTypes = async ({
|
|
|
23
23
|
helpers,
|
|
24
24
|
options,
|
|
25
25
|
}: UpsertGlobalTypesArgs): Promise<void> => {
|
|
26
|
-
const filePath = helpers.joinPathFromRoot("
|
|
26
|
+
const filePath = helpers.joinPathFromRoot("prismicio.d.ts");
|
|
27
27
|
|
|
28
28
|
const [customTypeModelDescriptors, sharedSliceModelDescriptors] =
|
|
29
29
|
await Promise.all([
|
|
@@ -28,7 +28,7 @@ export type SliceSimulatorProps = {
|
|
|
28
28
|
* @example
|
|
29
29
|
*
|
|
30
30
|
* ```tsx
|
|
31
|
-
* import { SliceSimulator } from "@slicemachine/adapter-next/
|
|
31
|
+
* import { SliceSimulator } from "@slicemachine/adapter-next/simulator";
|
|
32
32
|
* import { SliceZone } from "@prismicio/react";
|
|
33
33
|
*
|
|
34
34
|
* import { components } from "../slices";
|
|
@@ -42,11 +42,10 @@ export type SliceSimulatorProps = {
|
|
|
42
42
|
*/
|
|
43
43
|
sliceZone: (props: SliceSimulatorSliceZoneProps) => JSX.Element;
|
|
44
44
|
className?: string;
|
|
45
|
-
} & BaseSliceSimulatorProps
|
|
45
|
+
} & Omit<BaseSliceSimulatorProps, "state">;
|
|
46
46
|
|
|
47
47
|
export const SliceSimulator = ({
|
|
48
48
|
sliceZone: SliceZoneComp,
|
|
49
|
-
state,
|
|
50
49
|
background,
|
|
51
50
|
zIndex,
|
|
52
51
|
className,
|
|
@@ -59,8 +58,6 @@ export const SliceSimulator = ({
|
|
|
59
58
|
const [slices, setSlices] = React.useState(() => getDefaultSlices());
|
|
60
59
|
const [message, setMessage] = React.useState(() => getDefaultMessage());
|
|
61
60
|
|
|
62
|
-
const resolvedState = state || defaultProps.state;
|
|
63
|
-
|
|
64
61
|
React.useEffect(() => {
|
|
65
62
|
coreManager.stateManager.on(
|
|
66
63
|
StateManagerEventType.ManagedState,
|
|
@@ -84,7 +81,7 @@ export const SliceSimulator = ({
|
|
|
84
81
|
"simulator-message",
|
|
85
82
|
);
|
|
86
83
|
|
|
87
|
-
coreManager.init(
|
|
84
|
+
coreManager.init(defaultProps.state);
|
|
88
85
|
|
|
89
86
|
return () => {
|
|
90
87
|
coreManager.stateManager.off(
|
|
@@ -104,16 +101,6 @@ export const SliceSimulator = ({
|
|
|
104
101
|
};
|
|
105
102
|
}, []);
|
|
106
103
|
|
|
107
|
-
// Update state on HMR
|
|
108
|
-
const didMount = React.useRef(false);
|
|
109
|
-
React.useEffect(() => {
|
|
110
|
-
if (didMount.current) {
|
|
111
|
-
coreManager.stateManager.reload(resolvedState);
|
|
112
|
-
} else {
|
|
113
|
-
didMount.current = true;
|
|
114
|
-
}
|
|
115
|
-
}, [resolvedState]);
|
|
116
|
-
|
|
117
104
|
return (
|
|
118
105
|
<div
|
|
119
106
|
className={[simulatorClass, className].filter(Boolean).join(" ")}
|