@sitecore-content-sdk/react 2.2.1 → 2.3.0-beta.atoms.20260721120640

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 (77) hide show
  1. package/dist/cjs/atoms/catalog-serializer.js +43 -0
  2. package/dist/cjs/atoms/create-ncc.js +75 -0
  3. package/dist/cjs/atoms/define-atoms-catalog.js +44 -0
  4. package/dist/cjs/atoms/define-atoms-registry.js +36 -0
  5. package/dist/cjs/atoms/field-schemas.js +88 -0
  6. package/dist/cjs/atoms/index.js +35 -0
  7. package/dist/cjs/atoms/re-exports.js +24 -0
  8. package/dist/cjs/atoms/schema-utils.js +19 -0
  9. package/dist/cjs/atoms/types.js +2 -0
  10. package/dist/cjs/components/DesignLibrary/DesignLibrary.js +8 -2
  11. package/dist/cjs/components/DesignLibrary/DesignLibraryLowCodeComponent.js +109 -0
  12. package/dist/cjs/components/DesignLibrary/StudioComponentServerWrapper.js +93 -0
  13. package/dist/cjs/components/DesignLibrary/StudioComponentWrapper.js +62 -0
  14. package/dist/cjs/components/DesignLibrary/index.js +3 -1
  15. package/dist/cjs/components/Placeholder/placeholder-utils.js +14 -3
  16. package/dist/cjs/components/SitecoreProvider.js +4 -2
  17. package/dist/cjs/index.js +14 -2
  18. package/dist/esm/atoms/catalog-serializer.js +40 -0
  19. package/dist/esm/atoms/create-ncc.js +39 -0
  20. package/dist/esm/atoms/define-atoms-catalog.js +41 -0
  21. package/dist/esm/atoms/define-atoms-registry.js +33 -0
  22. package/dist/esm/atoms/field-schemas.js +79 -0
  23. package/dist/esm/atoms/index.js +7 -0
  24. package/dist/esm/atoms/re-exports.js +21 -0
  25. package/dist/esm/atoms/schema-utils.js +16 -0
  26. package/dist/esm/atoms/types.js +1 -0
  27. package/dist/esm/components/DesignLibrary/DesignLibrary.js +8 -2
  28. package/dist/esm/components/DesignLibrary/DesignLibraryLowCodeComponent.js +71 -0
  29. package/dist/esm/components/DesignLibrary/StudioComponentServerWrapper.js +86 -0
  30. package/dist/esm/components/DesignLibrary/StudioComponentWrapper.js +25 -0
  31. package/dist/esm/components/DesignLibrary/index.js +1 -0
  32. package/dist/esm/components/Image.js +1 -1
  33. package/dist/esm/components/Link.js +1 -1
  34. package/dist/esm/components/Placeholder/placeholder-utils.js +14 -3
  35. package/dist/esm/components/SitecoreProvider.js +4 -2
  36. package/dist/esm/index.js +3 -2
  37. package/package.json +9 -7
  38. package/types/atoms/catalog-serializer.d.ts +11 -0
  39. package/types/atoms/catalog-serializer.d.ts.map +1 -0
  40. package/types/atoms/create-ncc.d.ts +24 -0
  41. package/types/atoms/create-ncc.d.ts.map +1 -0
  42. package/types/atoms/define-atoms-catalog.d.ts +65 -0
  43. package/types/atoms/define-atoms-catalog.d.ts.map +1 -0
  44. package/types/atoms/define-atoms-registry.d.ts +33 -0
  45. package/types/atoms/define-atoms-registry.d.ts.map +1 -0
  46. package/types/atoms/field-schemas.d.ts +120 -0
  47. package/types/atoms/field-schemas.d.ts.map +1 -0
  48. package/types/atoms/index.d.ts +9 -0
  49. package/types/atoms/index.d.ts.map +1 -0
  50. package/types/atoms/re-exports.d.ts +22 -0
  51. package/types/atoms/re-exports.d.ts.map +1 -0
  52. package/types/atoms/schema-utils.d.ts +20 -0
  53. package/types/atoms/schema-utils.d.ts.map +1 -0
  54. package/types/atoms/types.d.ts +78 -0
  55. package/types/atoms/types.d.ts.map +1 -0
  56. package/types/components/DesignLibrary/DesignLibrary.d.ts.map +1 -1
  57. package/types/components/DesignLibrary/DesignLibraryLowCodeComponent.d.ts +13 -0
  58. package/types/components/DesignLibrary/DesignLibraryLowCodeComponent.d.ts.map +1 -0
  59. package/types/components/DesignLibrary/StudioComponentServerWrapper.d.ts +33 -0
  60. package/types/components/DesignLibrary/StudioComponentServerWrapper.d.ts.map +1 -0
  61. package/types/components/DesignLibrary/StudioComponentWrapper.d.ts +25 -0
  62. package/types/components/DesignLibrary/StudioComponentWrapper.d.ts.map +1 -0
  63. package/types/components/DesignLibrary/index.d.ts +1 -0
  64. package/types/components/DesignLibrary/index.d.ts.map +1 -1
  65. package/types/components/Image.d.ts +37 -1
  66. package/types/components/Image.d.ts.map +1 -1
  67. package/types/components/Link.d.ts +24 -1
  68. package/types/components/Link.d.ts.map +1 -1
  69. package/types/components/Placeholder/placeholder-utils.d.ts.map +1 -1
  70. package/types/components/RichText.d.ts +8 -1
  71. package/types/components/RichText.d.ts.map +1 -1
  72. package/types/components/SitecoreProvider.d.ts +11 -0
  73. package/types/components/SitecoreProvider.d.ts.map +1 -1
  74. package/types/components/Text.d.ts +8 -1
  75. package/types/components/Text.d.ts.map +1 -1
  76. package/types/index.d.ts +7 -6
  77. package/types/index.d.ts.map +1 -1
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.serializeCatalog = serializeCatalog;
4
+ /**
5
+ * Serialize a json-render Catalog into the payload shape expected by Design Studio.
6
+ * @param { Catalog<any, AtomsCatalogInput> } catalog - The json-render Catalog to serialize
7
+ * @returns Serialized catalog for the Design Library event
8
+ * @internal
9
+ */
10
+ function serializeCatalog(catalog) {
11
+ const { version, components, actions } = catalog.data;
12
+ const serializedComponents = Object.entries(components).map(([name, component]) => {
13
+ var _a;
14
+ const serializedComponent = {
15
+ name,
16
+ propsSchema: component.props.toJSONSchema(),
17
+ description: component.description,
18
+ slots: (_a = component.slots) !== null && _a !== void 0 ? _a : ['default'],
19
+ allowedChildren: component.allowedChildren,
20
+ allowedParents: component.allowedParents,
21
+ example: component.example,
22
+ };
23
+ if (component.version)
24
+ serializedComponent.version = component.version;
25
+ return serializedComponent;
26
+ });
27
+ const serializedActions = Object.entries(actions).map(([name, action]) => {
28
+ const serializedAction = {
29
+ name,
30
+ description: action.description,
31
+ };
32
+ if (action.params)
33
+ serializedAction.paramsSchema = action.params.toJSONSchema();
34
+ return serializedAction;
35
+ });
36
+ const serializedCatalog = {
37
+ components: serializedComponents,
38
+ actions: serializedActions,
39
+ };
40
+ if (version)
41
+ serializedCatalog.version = version;
42
+ return serializedCatalog;
43
+ }
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ 'use client';
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.createNCC = createNCC;
38
+ const react_1 = __importStar(require("react"));
39
+ const react_2 = require("@json-render/react");
40
+ const react_3 = require("@json-render/react");
41
+ const SitecoreProvider_1 = require("../components/SitecoreProvider");
42
+ /**
43
+ * Creates a React functional component that renders the given Component Layout document
44
+ * using json-render's Renderer. The document's flat element map is passed as a spec.
45
+ * @param {Document} doc - Component Layout document (flat spec format)
46
+ * @param {DefineRegistryResult} registryResult - The registry from defineAtomsRegistry
47
+ * @returns {FC<NCCProps>} FC that accepts runtime props merged into spec state
48
+ * @internal
49
+ */
50
+ function createNCC(doc, registryResult) {
51
+ var _a;
52
+ const { registry, handlers } = registryResult;
53
+ const initialState = Object.assign({}, ((_a = doc.state) !== null && _a !== void 0 ? _a : {}));
54
+ const Generated = ({ fields, params }) => {
55
+ const { atomsConfig } = (0, SitecoreProvider_1.useSitecore)();
56
+ const [store] = (0, react_1.useState)(() => (0, react_3.createStateStore)(Object.assign(Object.assign({}, initialState), { fields,
57
+ params })));
58
+ (0, react_1.useEffect)(() => {
59
+ const snapshot = store.getSnapshot();
60
+ store.update({
61
+ fields: Object.assign(Object.assign({}, snapshot.fields), fields),
62
+ params: Object.assign(Object.assign({}, snapshot.params), params),
63
+ });
64
+ }, [fields, params, store]);
65
+ const [resolvedHandlers] = (0, react_1.useState)(() => handlers(() => (updater) => store.update(updater(store.getSnapshot())), () => store.getSnapshot()));
66
+ return (react_1.default.createElement("div", { className: `component ${(params === null || params === void 0 ? void 0 : params.styles) || ''}`, id: (params === null || params === void 0 ? void 0 : params.RenderingIdentifier) || '' },
67
+ react_1.default.createElement(react_2.StateProvider, { store: store },
68
+ react_1.default.createElement(react_2.VisibilityProvider, null,
69
+ react_1.default.createElement(react_2.ActionProvider, { handlers: resolvedHandlers, navigate: atomsConfig === null || atomsConfig === void 0 ? void 0 : atomsConfig.navigate },
70
+ react_1.default.createElement(react_2.ValidationProvider, null,
71
+ react_1.default.createElement(react_2.Renderer, { spec: doc, registry: registry })))))));
72
+ };
73
+ Generated.displayName = doc.name;
74
+ return Generated;
75
+ }
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.defineAtomsCatalog = defineAtomsCatalog;
4
+ const core_1 = require("@json-render/core");
5
+ const react_1 = require("@json-render/react");
6
+ /**
7
+ * Define an atoms catalog from component and action definitions.
8
+ *
9
+ * Pass component/action definitions exactly as json-render expects them.
10
+ * The returned catalog carries full type information so `defineAtomsRegistry`
11
+ * can infer props per component.
12
+ * @param {T} input - Catalog input with `components` and optionally `actions`
13
+ * @returns A typed json-render Catalog
14
+ * @example
15
+ * ```ts
16
+ * import { z } from 'zod';
17
+ * import { defineAtomsCatalog } from '@sitecore-content-sdk/react';
18
+ *
19
+ * const catalog = defineAtomsCatalog({
20
+ * components: {
21
+ * Button: {
22
+ * props: z.object({ label: z.string(), variant: z.enum(['primary', 'secondary']) }),
23
+ * description: 'A clickable button',
24
+ * slots: ['default'],
25
+ * },
26
+ * Card: {
27
+ * props: z.object({ title: z.string() }),
28
+ * description: 'A content card',
29
+ * slots: ['default'],
30
+ * },
31
+ * },
32
+ * actions: {
33
+ * submit: {
34
+ * params: z.object({ formId: z.string() }),
35
+ * description: 'Submit a form',
36
+ * },
37
+ * },
38
+ * });
39
+ * ```
40
+ * @public
41
+ */
42
+ function defineAtomsCatalog(input) {
43
+ return (0, core_1.defineCatalog)(react_1.schema, input);
44
+ }
@@ -0,0 +1,36 @@
1
+ "use strict";
2
+ 'use client';
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.defineAtomsRegistry = void 0;
5
+ const react_1 = require("@json-render/react");
6
+ /**
7
+ * Define an atoms registry that maps catalog definitions to React implementations.
8
+ *
9
+ * Each component receives `{ props, children, emit, on, bindings, loading }`
10
+ * @param catalog - The catalog created by defineAtomsCatalog
11
+ * @param options - Component and action implementations
12
+ * @returns Registry result with component registry and action handlers
13
+ * @example
14
+ *
15
+ * ```tsx
16
+ * import { defineAtomsRegistry } from '@sitecore-content-sdk/react';
17
+ *
18
+ * const { registry, handlers, executeAction } = defineAtomsRegistry(catalog, {
19
+ * components: {
20
+ * Button: ({ props, children, emit }) => (
21
+ * <button onClick={() => emit('press')}>{props.label}{children}</button>
22
+ * ),
23
+ * Card: ({ props, children }) => (
24
+ * <div className="card"><h2>{props.title}</h2>{children}</div>
25
+ * ),
26
+ * },
27
+ * actions: {
28
+ * submit: async (params) => {
29
+ * await fetch('/api/submit', { method: 'POST', body: JSON.stringify(params) });
30
+ * },
31
+ * },
32
+ * });
33
+ * ```
34
+ * @public
35
+ */
36
+ exports.defineAtomsRegistry = react_1.defineRegistry;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fileFieldSchema = exports.imageFieldSchema = exports.linkFieldSchema = exports.dateFieldSchema = exports.richTextFieldSchema = exports.textFieldSchema = void 0;
4
+ /** Zod schemas for Sitecore field types, for use in defineAtomsCatalog prop definitions. */
5
+ const zod_1 = require("zod");
6
+ const schema_utils_1 = require("./schema-utils");
7
+ /**
8
+ * Zod schema for a Sitecore Single-Line Text.
9
+ * Mirrors the Sitecore Text component (`Text.tsx` in `@sitecore-content-sdk/react`).
10
+ * @param {z.ZodRawShape} [extra] - Optional additional shape to merge into the schema.
11
+ * @returns A ZodObject with `value?: string | number` and DS control/fieldType hints attached.
12
+ * @public
13
+ */
14
+ const textFieldSchema = (extra) => (0, schema_utils_1.withPropMeta)(zod_1.z.object(Object.assign({ value: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional() }, extra)), { control: 'Single-Line Text', fieldType: 'Text' });
15
+ exports.textFieldSchema = textFieldSchema;
16
+ /**
17
+ * Zod schema for a Sitecore Rich Text field.
18
+ * Mirrors the Sitecore Rich Text component (`RichText.tsx` in `@sitecore-content-sdk/react`).
19
+ * @param {z.ZodRawShape} [extra] - Optional additional shape to merge into the schema.
20
+ * @returns A ZodObject with `value?: string` and DS control/fieldType hints attached.
21
+ * @public
22
+ */
23
+ const richTextFieldSchema = (extra) => (0, schema_utils_1.withPropMeta)(zod_1.z.object(Object.assign({ value: zod_1.z.string().optional() }, extra)), { control: 'Rich Text', fieldType: 'RichText' });
24
+ exports.richTextFieldSchema = richTextFieldSchema;
25
+ /**
26
+ * Zod schema for a Sitecore Date field.
27
+ * Mirrors the field shape used in the Date component (`Date.tsx` in `@sitecore-content-sdk/react`).
28
+ * @param {z.ZodRawShape} [extra] - Optional additional shape to merge into the schema.
29
+ * @returns A ZodObject with `value?: string` and DS control/fieldType hints attached.
30
+ * @public
31
+ */
32
+ const dateFieldSchema = (extra) => (0, schema_utils_1.withPropMeta)(zod_1.z.object(Object.assign({ value: zod_1.z.string().optional() }, extra)), { control: 'Date', fieldType: 'Date' });
33
+ exports.dateFieldSchema = dateFieldSchema;
34
+ /**
35
+ * Zod schema for a Sitecore Link field.
36
+ * Mirrors the Sitecore Link component (`Link.tsx` in `@sitecore-content-sdk/react`).
37
+ * The inner value object uses `z.looseObject` to allow arbitrary Sitecore-added attributes,
38
+ * matching the `[attributeName: string]: unknown` index signature on `LinkFieldValue`.
39
+ * @param {z.ZodRawShape} [extra] - Optional additional shape to merge into the outer schema.
40
+ * @returns A ZodObject with `value: LinkFieldValue` and DS control/fieldType hints attached.
41
+ * @public
42
+ */
43
+ const linkFieldSchema = (extra) => (0, schema_utils_1.withPropMeta)(zod_1.z.object(Object.assign({ value: zod_1.z.looseObject({
44
+ href: zod_1.z.string().optional(),
45
+ className: zod_1.z.string().optional(),
46
+ class: zod_1.z.string().optional(),
47
+ title: zod_1.z.string().optional(),
48
+ target: zod_1.z.string().optional(),
49
+ text: zod_1.z.string().optional(),
50
+ anchor: zod_1.z.string().optional(),
51
+ querystring: zod_1.z.string().optional(),
52
+ linktype: zod_1.z.string().optional(),
53
+ }) }, extra)), { control: 'Link', fieldType: 'Link' });
54
+ exports.linkFieldSchema = linkFieldSchema;
55
+ /**
56
+ * Zod schema for a Sitecore Image field.
57
+ * Mirrors the Sitecore Image component (`Image.tsx` in `@sitecore-content-sdk/react`).
58
+ * The inner value object uses `z.looseObject` to allow arbitrary HTML attributes,
59
+ * matching the `[attributeName: string]: unknown` index signature on `ImageFieldValue`.
60
+ * @param {z.ZodRawShape} [extra] - Optional additional shape to merge into the outer schema.
61
+ * @returns A ZodObject with `value?: ImageFieldValue` and DS control/fieldType hints attached.
62
+ * @public
63
+ */
64
+ const imageFieldSchema = (extra) => (0, schema_utils_1.withPropMeta)(zod_1.z.object(Object.assign({ value: zod_1.z
65
+ .looseObject({
66
+ src: zod_1.z.string().optional(),
67
+ alt: zod_1.z.string().optional(),
68
+ width: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
69
+ height: zod_1.z.union([zod_1.z.string(), zod_1.z.number()]).optional(),
70
+ class: zod_1.z.string().optional(),
71
+ })
72
+ .optional() }, extra)), { control: 'Image', fieldType: 'Image' });
73
+ exports.imageFieldSchema = imageFieldSchema;
74
+ /**
75
+ * Zod schema for a Sitecore File field.
76
+ * Mirrors the Sitecore File component (`File.tsx` in `@sitecore-content-sdk/react`).
77
+ * The inner value object uses `z.looseObject` to allow arbitrary extra properties,
78
+ * matching the `[propName: string]: unknown` index signature on `FileFieldValue`.
79
+ * @param {z.ZodRawShape} [extra] - Optional additional shape to merge into the outer schema.
80
+ * @returns A ZodObject with `value: FileFieldValue` and DS control/fieldType hints attached.
81
+ * @public
82
+ */
83
+ const fileFieldSchema = (extra) => (0, schema_utils_1.withPropMeta)(zod_1.z.object(Object.assign({ value: zod_1.z.looseObject({
84
+ src: zod_1.z.string().optional(),
85
+ title: zod_1.z.string().optional(),
86
+ displayName: zod_1.z.string().optional(),
87
+ }) }, extra)), { control: 'File', fieldType: 'File' });
88
+ exports.fileFieldSchema = fileFieldSchema;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createNCC = exports.fileFieldSchema = exports.imageFieldSchema = exports.linkFieldSchema = exports.dateFieldSchema = exports.richTextFieldSchema = exports.textFieldSchema = exports.withPropMeta = exports.serializeCatalog = exports.defineAtomsRegistry = exports.defineAtomsCatalog = void 0;
18
+ var define_atoms_catalog_1 = require("./define-atoms-catalog");
19
+ Object.defineProperty(exports, "defineAtomsCatalog", { enumerable: true, get: function () { return define_atoms_catalog_1.defineAtomsCatalog; } });
20
+ var define_atoms_registry_1 = require("./define-atoms-registry");
21
+ Object.defineProperty(exports, "defineAtomsRegistry", { enumerable: true, get: function () { return define_atoms_registry_1.defineAtomsRegistry; } });
22
+ var catalog_serializer_1 = require("./catalog-serializer");
23
+ Object.defineProperty(exports, "serializeCatalog", { enumerable: true, get: function () { return catalog_serializer_1.serializeCatalog; } });
24
+ var schema_utils_1 = require("./schema-utils");
25
+ Object.defineProperty(exports, "withPropMeta", { enumerable: true, get: function () { return schema_utils_1.withPropMeta; } });
26
+ var field_schemas_1 = require("./field-schemas");
27
+ Object.defineProperty(exports, "textFieldSchema", { enumerable: true, get: function () { return field_schemas_1.textFieldSchema; } });
28
+ Object.defineProperty(exports, "richTextFieldSchema", { enumerable: true, get: function () { return field_schemas_1.richTextFieldSchema; } });
29
+ Object.defineProperty(exports, "dateFieldSchema", { enumerable: true, get: function () { return field_schemas_1.dateFieldSchema; } });
30
+ Object.defineProperty(exports, "linkFieldSchema", { enumerable: true, get: function () { return field_schemas_1.linkFieldSchema; } });
31
+ Object.defineProperty(exports, "imageFieldSchema", { enumerable: true, get: function () { return field_schemas_1.imageFieldSchema; } });
32
+ Object.defineProperty(exports, "fileFieldSchema", { enumerable: true, get: function () { return field_schemas_1.fileFieldSchema; } });
33
+ var create_ncc_1 = require("./create-ncc");
34
+ Object.defineProperty(exports, "createNCC", { enumerable: true, get: function () { return create_ncc_1.createNCC; } });
35
+ __exportStar(require("./re-exports"), exports);
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useBoundProp = void 0;
4
+ const react_1 = require("@json-render/react");
5
+ /**
6
+ * Hook for two-way bound props. Returns `[value, setValue]` where:
7
+ *
8
+ * - `value` is the already-resolved prop value (passed through from render props)
9
+ * - `setValue` writes back to the bound state path (no-op if not bound)
10
+ *
11
+ * Designed to work with the `bindings` map that the renderer provides when
12
+ * a prop uses `{ $bindState: "/path" }` or `{ $bindItem: "field" }`.
13
+ * @example
14
+ * ```tsx
15
+ * import { useBoundProp } from '@sitecore-content-sdk/react';
16
+ *
17
+ * const Input: ComponentRenderer = ({ props, bindings }) => {
18
+ * const [value, setValue] = useBoundProp<string>(props.value, bindings?.value);
19
+ * return <input value={value ?? ""} onChange={(e) => setValue(e.target.value)} />;
20
+ * };
21
+ * ```
22
+ * @public
23
+ */
24
+ exports.useBoundProp = react_1.useBoundProp;
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.withPropMeta = withPropMeta;
4
+ const META_KEY = 'meta';
5
+ /**
6
+ * Attach editor hint (e.g. control type, fieldType) to a prop schema. Metadata is stored under a key that
7
+ * survives JSON Schema conversion for Design Studio.
8
+ * @param {import('zod').ZodType} schema - Zod type for the prop
9
+ * @param {PropMeta} meta - Editor metadata (e.g. control, fieldType)
10
+ * @returns The same Zod type with meta attached (or schema unchanged if .meta is not callable)
11
+ * @public
12
+ */
13
+ function withPropMeta(schema, meta) {
14
+ const s = schema;
15
+ if (typeof s.meta === 'function') {
16
+ return s.meta({ [META_KEY]: meta });
17
+ }
18
+ return schema;
19
+ }
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -46,6 +46,8 @@ const SitecoreProvider_1 = require("../../components/SitecoreProvider");
46
46
  const Placeholder_1 = require("../Placeholder");
47
47
  const DesignLibraryErrorBoundary_1 = require("./DesignLibraryErrorBoundary");
48
48
  const ErrorBoundary_1 = require("../ErrorBoundary");
49
+ const atoms_1 = require("../../atoms");
50
+ const atoms_2 = require("@sitecore-content-sdk/content/atoms");
49
51
  let { getDesignLibraryImportMapEvent, getDesignLibraryComponentPropsEvent, addComponentPreviewHandler, sendErrorEvent, } = codegen;
50
52
  let { postToDesignLibrary } = editing;
51
53
  const __mockDependencies = (mocks) => {
@@ -70,7 +72,7 @@ exports.__mockDependencies = __mockDependencies;
70
72
  */
71
73
  const DesignLibrary = () => {
72
74
  var _a, _b;
73
- const { page, loadImportMap } = (0, SitecoreProvider_1.useSitecore)();
75
+ const { page, loadImportMap, atomsConfig } = (0, SitecoreProvider_1.useSitecore)();
74
76
  const route = page.layout.sitecore.route;
75
77
  const rendering = (_a = route === null || route === void 0 ? void 0 : route.placeholders[layout_1.EDITING_COMPONENT_PLACEHOLDER]) === null || _a === void 0 ? void 0 : _a[0];
76
78
  const uid = rendering === null || rendering === void 0 ? void 0 : rendering.uid;
@@ -143,6 +145,10 @@ const DesignLibrary = () => {
143
145
  });
144
146
  const importMapEvent = getDesignLibraryImportMapEvent(uid, importMap);
145
147
  postToDesignLibrary(importMapEvent);
148
+ if (atomsConfig === null || atomsConfig === void 0 ? void 0 : atomsConfig.catalog) {
149
+ const catalogPayload = (0, atoms_1.serializeCatalog)(atomsConfig.catalog);
150
+ postToDesignLibrary((0, atoms_2.getDesignLibraryAtomsCatalogEvent)(catalogPayload));
151
+ }
146
152
  const propsEvent = getDesignLibraryComponentPropsEvent(uid, propsState.fields, propsState.params);
147
153
  postToDesignLibrary(propsEvent);
148
154
  })();
@@ -151,7 +157,7 @@ const DesignLibrary = () => {
151
157
  cancelled = true;
152
158
  unsubscribe && unsubscribe();
153
159
  };
154
- }, [isDesignLibrary, isVariantGeneration, uid, loadImportMap, propsState]);
160
+ }, [isDesignLibrary, isVariantGeneration, uid, loadImportMap, propsState, atomsConfig]);
155
161
  return (react_1.default.createElement("main", null, isGeneratedComponentActive ? (react_1.default.createElement(DesignLibraryErrorBoundary_1.DesignLibraryErrorBoundary, { uid: uid, renderKey: renderKey },
156
162
  react_1.default.createElement(Placeholder_1.PlaceholderMetadata, { rendering: rendering },
157
163
  react_1.default.createElement(Component, { fields: propsState.fields, params: propsState.params, key: renderKey })))) : (react_1.default.createElement("div", { id: layout_1.EDITING_COMPONENT_ID }, route && (react_1.default.createElement(Placeholder_1.Placeholder, { name: layout_1.EDITING_COMPONENT_PLACEHOLDER, rendering: route, key: renderKey }))))));
@@ -0,0 +1,109 @@
1
+ "use strict";
2
+ 'use client';
3
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
4
+ if (k2 === undefined) k2 = k;
5
+ var desc = Object.getOwnPropertyDescriptor(m, k);
6
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
7
+ desc = { enumerable: true, get: function() { return m[k]; } };
8
+ }
9
+ Object.defineProperty(o, k2, desc);
10
+ }) : (function(o, m, k, k2) {
11
+ if (k2 === undefined) k2 = k;
12
+ o[k2] = m[k];
13
+ }));
14
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
15
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
16
+ }) : function(o, v) {
17
+ o["default"] = v;
18
+ });
19
+ var __importStar = (this && this.__importStar) || (function () {
20
+ var ownKeys = function(o) {
21
+ ownKeys = Object.getOwnPropertyNames || function (o) {
22
+ var ar = [];
23
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
24
+ return ar;
25
+ };
26
+ return ownKeys(o);
27
+ };
28
+ return function (mod) {
29
+ if (mod && mod.__esModule) return mod;
30
+ var result = {};
31
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
32
+ __setModuleDefault(result, mod);
33
+ return result;
34
+ };
35
+ })();
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.DesignLibraryLowCodeComponent = exports.__mockDependencies = void 0;
38
+ const react_1 = __importStar(require("react"));
39
+ const SitecoreProvider_1 = require("../SitecoreProvider");
40
+ const atoms_1 = require("../../atoms");
41
+ const StudioComponentWrapper_1 = require("./StudioComponentWrapper");
42
+ const editing = __importStar(require("@sitecore-content-sdk/content/editing"));
43
+ const atoms = __importStar(require("@sitecore-content-sdk/content/atoms"));
44
+ const __1 = require("../..");
45
+ let { postToDesignLibrary, getDesignLibraryStatusEvent, DesignLibraryStatus } = editing;
46
+ let { addDocumentUpdateHandler, getDesignLibraryAtomsCatalogEvent, sendAtomsErrorEvent, addComponentPropsUpdateHandler, } = atoms;
47
+ const __mockDependencies = (mocks) => {
48
+ if (mocks.postToDesignLibrary) {
49
+ postToDesignLibrary = mocks.postToDesignLibrary;
50
+ }
51
+ if (mocks.sendAtomsErrorEvent) {
52
+ sendAtomsErrorEvent = mocks.sendAtomsErrorEvent;
53
+ }
54
+ if (mocks.addDocumentUpdateHandler) {
55
+ addDocumentUpdateHandler = mocks.addDocumentUpdateHandler;
56
+ }
57
+ if (mocks.addComponentPropsUpdateHandler) {
58
+ addComponentPropsUpdateHandler = mocks.addComponentPropsUpdateHandler;
59
+ }
60
+ };
61
+ exports.__mockDependencies = __mockDependencies;
62
+ /**
63
+ * Design Library Low Code component.
64
+ *
65
+ * Facilitates the communication between the Design Studio and the Rendering Host when previewing a low code component built with the Atoms.
66
+ * - On mount, it serializes the atoms catalog and sends it to the Design Studio via the `atoms:catalog` event.
67
+ * - Receives Component model data updates via document update handler and renders the low code component
68
+ * via `StudioComponentWrapper` (same client path as Studio / NCC preview elsewhere).
69
+ * @internal
70
+ */
71
+ const DesignLibraryLowCodeComponent = () => {
72
+ var _a;
73
+ const { atomsConfig } = (0, SitecoreProvider_1.useSitecore)();
74
+ const [currentDocument, setCurrentDocument] = (0, react_1.useState)(null);
75
+ const [renderKey, setRenderKey] = (0, react_1.useState)(0);
76
+ const [fields, setFields] = (0, react_1.useState)();
77
+ const [params, setParams] = (0, react_1.useState)();
78
+ (0, react_1.useEffect)(() => {
79
+ postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.READY, 'low-code-component'));
80
+ }, []);
81
+ (0, react_1.useEffect)(() => {
82
+ const unsubscribe = addComponentPropsUpdateHandler((updatedFields, updatedParams) => {
83
+ setFields(updatedFields);
84
+ setParams(updatedParams);
85
+ });
86
+ return () => unsubscribe();
87
+ }, []);
88
+ (0, react_1.useEffect)(() => {
89
+ if (!(atomsConfig === null || atomsConfig === void 0 ? void 0 : atomsConfig.catalog)) {
90
+ sendAtomsErrorEvent('No atoms catalog provided', 'atoms-missing');
91
+ return;
92
+ }
93
+ const payload = (0, atoms_1.serializeCatalog)(atomsConfig.catalog);
94
+ postToDesignLibrary(getDesignLibraryAtomsCatalogEvent(payload));
95
+ const unsubDocumentUpdate = addDocumentUpdateHandler((updatedDocument) => {
96
+ setCurrentDocument(updatedDocument);
97
+ setRenderKey((k) => k + 1);
98
+ });
99
+ return () => unsubDocumentUpdate();
100
+ }, [atomsConfig]);
101
+ (0, react_1.useEffect)(() => {
102
+ if (renderKey === 0)
103
+ return;
104
+ postToDesignLibrary(getDesignLibraryStatusEvent(DesignLibraryStatus.RENDERED, 'low-code-component'));
105
+ }, [renderKey]);
106
+ return (react_1.default.createElement(__1.DesignLibraryErrorBoundary, { uid: (_a = currentDocument === null || currentDocument === void 0 ? void 0 : currentDocument.name) !== null && _a !== void 0 ? _a : 'design-library-low-code-component', renderKey: renderKey },
107
+ react_1.default.createElement(StudioComponentWrapper_1.StudioComponentWrapper, { document: currentDocument, fields: fields, params: params })));
108
+ };
109
+ exports.DesignLibraryLowCodeComponent = DesignLibraryLowCodeComponent;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.StudioComponentServerWrapper = void 0;
7
+ const react_1 = __importDefault(require("react"));
8
+ const StudioComponentWrapper_1 = require("./StudioComponentWrapper");
9
+ const core_1 = require("@sitecore-content-sdk/core");
10
+ const content_1 = require("@sitecore-content-sdk/content");
11
+ const tools_1 = require("@sitecore-content-sdk/core/tools");
12
+ /**
13
+ * Server component for Studio (NCC) components. Fetches the component layout
14
+ * `Document` from MMS server-side and renders the client `StudioComponentWrapper`.
15
+ * @param {StudioComponentServerWrapperProps} props incoming props
16
+ * @returns rendered `StudioComponentWrapper`
17
+ * @internal
18
+ */
19
+ const StudioComponentServerWrapper = async (props) => {
20
+ const componentRef = props.componentRef || '';
21
+ if (!componentRef)
22
+ return null;
23
+ const path = extractVariantPathFromComponentRef(componentRef, props.fieldNames);
24
+ if (!path)
25
+ return null;
26
+ const document = await fetchDocument(path);
27
+ if (!document)
28
+ return null;
29
+ return react_1.default.createElement(StudioComponentWrapper_1.StudioComponentWrapper, { document: document, fields: props.fields, params: props.params });
30
+ };
31
+ exports.StudioComponentServerWrapper = StudioComponentServerWrapper;
32
+ /**
33
+ * Extracts the variant path from a component reference.
34
+ * @param {string} componentRef The component reference string.
35
+ * @param {string} fieldNames The field names to extract the variant path for.
36
+ * @returns {string} The variant path.
37
+ * @internal
38
+ */
39
+ function extractVariantPathFromComponentRef(componentRef, fieldNames = 'default') {
40
+ const paths = componentRef.split('|').reduce((acc, part) => {
41
+ const path = part.trim();
42
+ const segments = path.split('/');
43
+ const variant = segments[segments.length - 1];
44
+ acc.set(variant, path);
45
+ return acc;
46
+ }, new Map());
47
+ const path = paths.get(fieldNames) || paths.get('default') || null;
48
+ if (!path) {
49
+ console.warn(`StudioComponentServerWrapper: failed to extract path from ComponentRef "${componentRef}" with fieldNames "${fieldNames}". ` +
50
+ 'Ensure the ComponentRef is in the expected format and that the correct fieldNames are provided.');
51
+ }
52
+ return path;
53
+ }
54
+ /**
55
+ * Prefix for MMS component paths in componentRef. The final URL will be resolved as `${host}/${MMS_COMPONENT_PATH_PREFIX}/${path}`.
56
+ */
57
+ const MMS_COMPONENT_PATH_PREFIX = 'mms';
58
+ /**
59
+ * Fetch a Studio component layout `Document` by reference.
60
+ * @param {string} path extracted component reference (path) from `params.ComponentRef`
61
+ * @returns {Promise<Document | null>} the resolved component layout, or `null` on missing path, fetch failure, or un-parseable body.
62
+ */
63
+ async function fetchDocument(path) {
64
+ let url;
65
+ try {
66
+ const pathWithMmsPrefix = path.startsWith('/')
67
+ ? `/${MMS_COMPONENT_PATH_PREFIX}${path}`
68
+ : `/${MMS_COMPONENT_PATH_PREFIX}/${path}`;
69
+ const hostURL = (0, tools_1.resolveEdgeUrl)();
70
+ url = new URL(pathWithMmsPrefix, hostURL).toString();
71
+ }
72
+ catch (err) {
73
+ console.error(`StudioComponentServerWrapper: failed to resolve component from "${path}"`, err);
74
+ return null;
75
+ }
76
+ let response;
77
+ try {
78
+ const fetcher = new core_1.NativeDataFetcher({ debugger: content_1.debug.layout });
79
+ response = await fetcher.get(url);
80
+ }
81
+ catch (error) {
82
+ console.error(`StudioComponentServerWrapper: failed to fetch component layout from ${url}`, error);
83
+ return null;
84
+ }
85
+ try {
86
+ const document = JSON.parse(response.data);
87
+ return document;
88
+ }
89
+ catch (err) {
90
+ console.error(`StudioComponentServerWrapper: failed to parse component layout response from ${url}`, err);
91
+ return null;
92
+ }
93
+ }