@conloca/cms-spa 0.1.4-rc.1 → 0.1.4-rc.2

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.
@@ -0,0 +1,52 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ //#region src/page-schemas.ts
4
+ const getSharedState = () => {
5
+ if (typeof window !== "undefined") {
6
+ if (!window.__PAGE_SCHEMAS_STATE__) window.__PAGE_SCHEMAS_STATE__ = {
7
+ schemas: {},
8
+ subscribers: /* @__PURE__ */ new Set()
9
+ };
10
+ return window.__PAGE_SCHEMAS_STATE__;
11
+ }
12
+ return {
13
+ schemas: {},
14
+ subscribers: /* @__PURE__ */ new Set()
15
+ };
16
+ };
17
+ /**
18
+ * Set the page schemas for all pathname prefixes.
19
+ * Called by the virtual module that loads user's schema definitions.
20
+ * Notifies all subscribers of the change (enables HMR).
21
+ */
22
+ function setPageSchemas(schemas) {
23
+ const state = getSharedState();
24
+ state.schemas = schemas;
25
+ state.subscribers.forEach((fn) => fn(schemas));
26
+ }
27
+ /**
28
+ * Get the current page schemas synchronously.
29
+ */
30
+ function getPageSchemas() {
31
+ return getSharedState().schemas;
32
+ }
33
+ /**
34
+ * React hook to subscribe to page schema changes.
35
+ * Returns the current schemas and updates when they change (HMR support).
36
+ */
37
+ function usePageSchemas() {
38
+ const [schemas, setSchemas] = useState(() => getSharedState().schemas);
39
+ useEffect(() => {
40
+ const state = getSharedState();
41
+ if (state.schemas !== schemas) setSchemas(state.schemas);
42
+ state.subscribers.add(setSchemas);
43
+ return () => {
44
+ state.subscribers.delete(setSchemas);
45
+ };
46
+ }, []);
47
+ return schemas;
48
+ }
49
+
50
+ //#endregion
51
+ export { setPageSchemas as n, usePageSchemas as r, getPageSchemas as t };
52
+ //# sourceMappingURL=page-schemas-CyCRM6JQ.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"page-schemas-CyCRM6JQ.mjs","names":[],"sources":["../src/page-schemas.ts"],"sourcesContent":["import { useEffect, useState } from 'react';\nimport type { z } from 'zod';\n\n/**\n * Type for a collection of page schemas.\n * Each key is a pathname prefix (e.g. '/blog/'), value is the Zod schema for that page's metadata.\n */\nexport type PageSchemas = Record<string, z.ZodObject<z.ZodRawShape>>;\n\n/**\n * Shared state for page schemas across module instances.\n * Uses window to ensure virtual modules and bundled code share the same state.\n */\n\ninterface SharedPageSchemaState {\n schemas: PageSchemas;\n subscribers: Set<(schemas: PageSchemas) => void>;\n}\n\nconst getSharedState = (): SharedPageSchemaState => {\n if (typeof window !== 'undefined') {\n if (!(window as any).__PAGE_SCHEMAS_STATE__) {\n (window as any).__PAGE_SCHEMAS_STATE__ = {\n schemas: {},\n subscribers: new Set(),\n };\n }\n return (window as any).__PAGE_SCHEMAS_STATE__;\n }\n // SSR fallback\n return { schemas: {}, subscribers: new Set() };\n};\n\n/**\n * Set the page schemas for all pathname prefixes.\n * Called by the virtual module that loads user's schema definitions.\n * Notifies all subscribers of the change (enables HMR).\n */\nexport function setPageSchemas(schemas: PageSchemas): void {\n const state = getSharedState();\n state.schemas = schemas;\n state.subscribers.forEach((fn) => fn(schemas));\n}\n\n/**\n * Get the current page schemas synchronously.\n */\nexport function getPageSchemas(): PageSchemas {\n return getSharedState().schemas;\n}\n\n/**\n * React hook to subscribe to page schema changes.\n * Returns the current schemas and updates when they change (HMR support).\n */\nexport function usePageSchemas(): PageSchemas {\n const [schemas, setSchemas] = useState(() => getSharedState().schemas);\n\n useEffect(() => {\n const state = getSharedState();\n\n // Update immediately in case schemas changed between render and effect\n if (state.schemas !== schemas) {\n setSchemas(state.schemas);\n }\n\n state.subscribers.add(setSchemas);\n return () => {\n state.subscribers.delete(setSchemas);\n };\n }, []);\n\n return schemas;\n}\n"],"mappings":";;;AAmBA,MAAM,uBAA8C;AAClD,KAAI,OAAO,WAAW,aAAa;AACjC,MAAI,CAAE,OAAe,uBACnB,CAAC,OAAe,yBAAyB;GACvC,SAAS,EAAE;GACX,6BAAa,IAAI,KAAK;GACvB;AAEH,SAAQ,OAAe;;AAGzB,QAAO;EAAE,SAAS,EAAE;EAAE,6BAAa,IAAI,KAAK;EAAE;;;;;;;AAQhD,SAAgB,eAAe,SAA4B;CACzD,MAAM,QAAQ,gBAAgB;AAC9B,OAAM,UAAU;AAChB,OAAM,YAAY,SAAS,OAAO,GAAG,QAAQ,CAAC;;;;;AAMhD,SAAgB,iBAA8B;AAC5C,QAAO,gBAAgB,CAAC;;;;;;AAO1B,SAAgB,iBAA8B;CAC5C,MAAM,CAAC,SAAS,cAAc,eAAe,gBAAgB,CAAC,QAAQ;AAEtE,iBAAgB;EACd,MAAM,QAAQ,gBAAgB;AAG9B,MAAI,MAAM,YAAY,QACpB,YAAW,MAAM,QAAQ;AAG3B,QAAM,YAAY,IAAI,WAAW;AACjC,eAAa;AACX,SAAM,YAAY,OAAO,WAAW;;IAErC,EAAE,CAAC;AAEN,QAAO"}
@@ -1,52 +1,3 @@
1
- import { useEffect, useState } from "react";
1
+ import { n as setPageSchemas, r as usePageSchemas, t as getPageSchemas } from "./page-schemas-CyCRM6JQ.mjs";
2
2
 
3
- //#region src/page-schemas.ts
4
- const getSharedState = () => {
5
- if (typeof window !== "undefined") {
6
- if (!window.__PAGE_SCHEMAS_STATE__) window.__PAGE_SCHEMAS_STATE__ = {
7
- schemas: {},
8
- subscribers: /* @__PURE__ */ new Set()
9
- };
10
- return window.__PAGE_SCHEMAS_STATE__;
11
- }
12
- return {
13
- schemas: {},
14
- subscribers: /* @__PURE__ */ new Set()
15
- };
16
- };
17
- /**
18
- * Set the page schemas for all pathname prefixes.
19
- * Called by the virtual module that loads user's schema definitions.
20
- * Notifies all subscribers of the change (enables HMR).
21
- */
22
- function setPageSchemas(schemas) {
23
- const state = getSharedState();
24
- state.schemas = schemas;
25
- state.subscribers.forEach((fn) => fn(schemas));
26
- }
27
- /**
28
- * Get the current page schemas synchronously.
29
- */
30
- function getPageSchemas() {
31
- return getSharedState().schemas;
32
- }
33
- /**
34
- * React hook to subscribe to page schema changes.
35
- * Returns the current schemas and updates when they change (HMR support).
36
- */
37
- function usePageSchemas() {
38
- const [schemas, setSchemas] = useState(() => getSharedState().schemas);
39
- useEffect(() => {
40
- const state = getSharedState();
41
- if (state.schemas !== schemas) setSchemas(state.schemas);
42
- state.subscribers.add(setSchemas);
43
- return () => {
44
- state.subscribers.delete(setSchemas);
45
- };
46
- }, []);
47
- return schemas;
48
- }
49
-
50
- //#endregion
51
- export { getPageSchemas, setPageSchemas, usePageSchemas };
52
- //# sourceMappingURL=page-schemas.mjs.map
3
+ export { getPageSchemas, setPageSchemas, usePageSchemas };