@sitecore-content-sdk/core 0.1.0-beta.26 → 0.1.0-beta.29

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.
@@ -107,7 +107,7 @@ class SitecoreClient {
107
107
  headLinks.push(contentStyles);
108
108
  }
109
109
  if (enableThemes) {
110
- headLinks.push(...(0, layout_1.getComponentLibraryStylesheetLinks)(layoutData, contextId, edgeUrl));
110
+ headLinks.push(...(0, layout_1.getDesignLibraryStylesheetLinks)(layoutData, contextId, edgeUrl));
111
111
  }
112
112
  return headLinks;
113
113
  }
@@ -167,16 +167,16 @@ class SitecoreClient {
167
167
  return page;
168
168
  }
169
169
  /**
170
- * Get component library page details for Component Library mode of your app
171
- * @param {ComponentLibraryRenderPreviewData} componentLibData preview data set in 'library' mode of the app
170
+ * Get design library page details for Design Library mode of your app
171
+ * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
172
172
  * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
173
- * @returns {Page} preview page for Component Library
173
+ * @returns {Page} preview page for Design Library
174
174
  */
175
- async getComponentLibraryData(componentLibData, fetchOptions) {
175
+ async getDesignLibraryData(designLibData, fetchOptions) {
176
176
  if (!this.initOptions.api.local) {
177
177
  throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
178
178
  }
179
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = componentLibData;
179
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = designLibData;
180
180
  const componentData = await this.componentService.fetchComponentData({
181
181
  siteName: site,
182
182
  itemId,
@@ -191,10 +191,10 @@ class SitecoreClient {
191
191
  language,
192
192
  }, fetchOptions);
193
193
  if (!componentData) {
194
- throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(componentLibData)}`);
194
+ throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}`);
195
195
  }
196
196
  const page = {
197
- locale: componentLibData.language,
197
+ locale: designLibData.language,
198
198
  layout: componentData,
199
199
  dictionary: dictionaryData,
200
200
  };
package/dist/cjs/debug.js CHANGED
@@ -29,6 +29,7 @@ exports.enableDebug = enableDebug;
29
29
  */
30
30
  exports.default = {
31
31
  common: (0, debug_1.default)(`${rootNamespace}:common`),
32
+ form: (0, debug_1.default)(`${rootNamespace}:form`),
32
33
  http: (0, debug_1.default)(`${rootNamespace}:http`),
33
34
  layout: (0, debug_1.default)(`${rootNamespace}:layout`),
34
35
  dictionary: (0, debug_1.default)(`${rootNamespace}:dictionary`),
@@ -1,23 +1,23 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.ComponentLibraryStatus = exports.COMPONENT_LIBRARY_STATUS_EVENT_NAME = void 0;
4
- exports.getComponentLibraryStatusEvent = getComponentLibraryStatusEvent;
3
+ exports.updateComponentHandler = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.DESIGN_LIBRARY_STATUS_EVENT_NAME = void 0;
4
+ exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
5
5
  /**
6
- * Event to be sent when report status to component library
6
+ * Event to be sent when report status to design library
7
7
  */
8
- exports.COMPONENT_LIBRARY_STATUS_EVENT_NAME = 'component:status';
8
+ exports.DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
9
9
  /**
10
- * Enumeration of statuses for the component library.
10
+ * Enumeration of statuses for the design library.
11
11
  */
12
- var ComponentLibraryStatus;
13
- (function (ComponentLibraryStatus) {
14
- ComponentLibraryStatus["READY"] = "ready";
15
- ComponentLibraryStatus["RENDERED"] = "rendered";
16
- })(ComponentLibraryStatus || (exports.ComponentLibraryStatus = ComponentLibraryStatus = {}));
12
+ var DesignLibraryStatus;
13
+ (function (DesignLibraryStatus) {
14
+ DesignLibraryStatus["READY"] = "ready";
15
+ DesignLibraryStatus["RENDERED"] = "rendered";
16
+ })(DesignLibraryStatus || (exports.DesignLibraryStatus = DesignLibraryStatus = {}));
17
17
  /**
18
- * Adds the browser-side event handler for 'component:update' message used in Component Library
18
+ * Adds the browser-side event handler for 'component:update' message used in Design Library
19
19
  * The event should update a component on page by uid, with fields and params from event args
20
- * @param {ComponentRendering} rootComponent root component displayed for Component Library page
20
+ * @param {ComponentRendering} rootComponent root component displayed for Design Library page
21
21
  * @param {Function} successCallback callback to be called after successful component update
22
22
  */
23
23
  const addComponentUpdateHandler = (rootComponent, successCallback) => {
@@ -88,14 +88,14 @@ const updateComponentHandler = (e, rootComponent, successCallback) => {
88
88
  };
89
89
  exports.updateComponentHandler = updateComponentHandler;
90
90
  /**
91
- * Generates a ComponentLibraryStatusEvent with the given status and uid.
92
- * @param {ComponentLibraryStatus} status - The status of rendering.
91
+ * Generates a DesignLibraryStatusEvent with the given status and uid.
92
+ * @param {DesignLibraryStatus} status - The status of rendering.
93
93
  * @param {string} uid - The unique identifier for the event.
94
- * @returns An object representing the ComponentLibraryStatusEvent.
94
+ * @returns An object representing the DesignLibraryStatusEvent.
95
95
  */
96
- function getComponentLibraryStatusEvent(status, uid) {
96
+ function getDesignLibraryStatusEvent(status, uid) {
97
97
  return {
98
- name: exports.COMPONENT_LIBRARY_STATUS_EVENT_NAME,
98
+ name: exports.DESIGN_LIBRARY_STATUS_EVENT_NAME,
99
99
  message: {
100
100
  status,
101
101
  uid,
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentLibraryStatusEvent = exports.ComponentLibraryStatus = exports.addComponentUpdateHandler = exports.MetadataKind = exports.LayoutKind = exports.RestComponentLayoutService = exports.PAGES_EDITING_MARKER = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getJssPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.GraphQLEditingService = void 0;
3
+ exports.getDesignLibraryStatusEvent = exports.DesignLibraryStatus = exports.addComponentUpdateHandler = exports.MetadataKind = exports.LayoutKind = exports.RestComponentLayoutService = exports.PAGES_EDITING_MARKER = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getJssPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.GraphQLEditingService = void 0;
4
4
  var graphql_editing_service_1 = require("./graphql-editing-service");
5
5
  Object.defineProperty(exports, "GraphQLEditingService", { enumerable: true, get: function () { return graphql_editing_service_1.GraphQLEditingService; } });
6
6
  var utils_1 = require("./utils");
@@ -17,7 +17,7 @@ Object.defineProperty(exports, "RestComponentLayoutService", { enumerable: true,
17
17
  var models_1 = require("./models");
18
18
  Object.defineProperty(exports, "LayoutKind", { enumerable: true, get: function () { return models_1.LayoutKind; } });
19
19
  Object.defineProperty(exports, "MetadataKind", { enumerable: true, get: function () { return models_1.MetadataKind; } });
20
- var component_library_1 = require("./component-library");
21
- Object.defineProperty(exports, "addComponentUpdateHandler", { enumerable: true, get: function () { return component_library_1.addComponentUpdateHandler; } });
22
- Object.defineProperty(exports, "ComponentLibraryStatus", { enumerable: true, get: function () { return component_library_1.ComponentLibraryStatus; } });
23
- Object.defineProperty(exports, "getComponentLibraryStatusEvent", { enumerable: true, get: function () { return component_library_1.getComponentLibraryStatusEvent; } });
20
+ var design_library_1 = require("./design-library");
21
+ Object.defineProperty(exports, "addComponentUpdateHandler", { enumerable: true, get: function () { return design_library_1.addComponentUpdateHandler; } });
22
+ Object.defineProperty(exports, "DesignLibraryStatus", { enumerable: true, get: function () { return design_library_1.DesignLibraryStatus; } });
23
+ Object.defineProperty(exports, "getDesignLibraryStatusEvent", { enumerable: true, get: function () { return design_library_1.getDesignLibraryStatusEvent; } });
@@ -4,7 +4,7 @@ exports.RestComponentLayoutService = void 0;
4
4
  const __1 = require("..");
5
5
  const data_fetcher_1 = require("../data-fetcher");
6
6
  /**
7
- * REST service that enables Component Library functioality
7
+ * REST service that enables Design Library functioality
8
8
  * Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
9
9
  * Returns layoutData for one single rendered component
10
10
  */
@@ -0,0 +1,78 @@
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.subscribeToFormSubmitEvent = exports.executeScriptElements = exports.loadForm = void 0;
7
+ const browser_1 = require("@sitecore-cloudsdk/events/browser");
8
+ const client_1 = require("../client");
9
+ const debug_1 = __importDefault(require("../debug"));
10
+ /**
11
+ * Fetches the form markup from the Sitecore Edge service and renders it in the component's template.
12
+ * @param {string} contextId - The unique identifier of the current context
13
+ * @param {string} formId - The unique identifier of the form
14
+ * @param {string} [edgeUrl] - The URL of the Sitecore Edge Platform
15
+ */
16
+ const loadForm = async (contextId, formId, edgeUrl) => {
17
+ if (!contextId) {
18
+ debug_1.default.form('Form was not able to render since context id was not provided');
19
+ return '';
20
+ }
21
+ const url = (0, client_1.getEdgeProxyFormsUrl)(contextId, formId, edgeUrl);
22
+ try {
23
+ debug_1.default.form(`Fetching form data from ${url}`);
24
+ const rsp = await fetch(url, {
25
+ method: 'GET',
26
+ cache: 'no-cache',
27
+ });
28
+ if (rsp.status !== 200) {
29
+ throw new Error('Failed to fetch form data');
30
+ }
31
+ const content = await rsp.text();
32
+ debug_1.default.form(`Form data fetch response: ${content}`);
33
+ return content;
34
+ }
35
+ catch (error) {
36
+ debug_1.default.form(`Form '${formId}' was not able to render`, error);
37
+ throw error;
38
+ }
39
+ };
40
+ exports.loadForm = loadForm;
41
+ /**
42
+ * When you set the innerHTML property of an element, the browser does not execute any <script> tags included in the HTML string
43
+ * This method ensures that any <script> elements within the loaded HTML are executed.
44
+ * It re-creates the script elements and appends the to the component's template, then removes old script elements to avoid duplication.
45
+ * @param {HTMLElement} rootElement - The root element to execute script elements within
46
+ */
47
+ const executeScriptElements = (rootElement) => {
48
+ const scriptElements = rootElement.querySelectorAll('script');
49
+ if (!scriptElements) {
50
+ return;
51
+ }
52
+ Array.from(scriptElements).forEach((scriptElement) => {
53
+ var _a;
54
+ const clonedElement = document.createElement('script');
55
+ Array.from(scriptElement.attributes).forEach((attribute) => {
56
+ clonedElement.setAttribute(attribute.name, attribute.value);
57
+ });
58
+ clonedElement.text = scriptElement.text;
59
+ (_a = scriptElement === null || scriptElement === void 0 ? void 0 : scriptElement.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(clonedElement, scriptElement);
60
+ });
61
+ };
62
+ exports.executeScriptElements = executeScriptElements;
63
+ /**
64
+ * Subscribes to the Form event and then sends data to CloudSDK.
65
+ * This listener captures interactions such as form views or submissions
66
+ * @param {HTMLElement} formElement - The form element to subscribe to events on
67
+ * @param {string} [componentId] - The unique identifier of the component
68
+ */
69
+ const subscribeToFormSubmitEvent = (formElement, componentId) => {
70
+ formElement.addEventListener('form:engage', ((e) => {
71
+ const { formId, name } = e.detail;
72
+ if (formId && name) {
73
+ debug_1.default.form('Sending form event', formId, name);
74
+ (0, browser_1.form)(formId, name, (componentId === null || componentId === void 0 ? void 0 : componentId.replace(/-/g, '')) || '');
75
+ }
76
+ }));
77
+ };
78
+ exports.subscribeToFormSubmitEvent = subscribeToFormSubmitEvent;
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.subscribeToFormSubmitEvent = exports.loadForm = exports.executeScriptElements = void 0;
4
+ var form_1 = require("./form");
5
+ Object.defineProperty(exports, "executeScriptElements", { enumerable: true, get: function () { return form_1.executeScriptElements; } });
6
+ Object.defineProperty(exports, "loadForm", { enumerable: true, get: function () { return form_1.loadForm; } });
7
+ Object.defineProperty(exports, "subscribeToFormSubmitEvent", { enumerable: true, get: function () { return form_1.subscribeToFormSubmitEvent; } });
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getComponentLibraryStylesheetLinks = exports.GRAPHQL_LAYOUT_QUERY_NAME = exports.GraphQLLayoutService = exports.getContentStylesheetLink = exports.EMPTY_DATE_FIELD_VALUE = exports.getDynamicPlaceholderPattern = exports.isDynamicPlaceholder = exports.isFieldValueEmpty = exports.getChildPlaceholder = exports.getFieldValue = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.EditMode = exports.LayoutServicePageState = void 0;
3
+ exports.getDesignLibraryStylesheetLinks = exports.GRAPHQL_LAYOUT_QUERY_NAME = exports.GraphQLLayoutService = exports.getContentStylesheetLink = exports.EMPTY_DATE_FIELD_VALUE = exports.getDynamicPlaceholderPattern = exports.isDynamicPlaceholder = exports.isFieldValueEmpty = exports.getChildPlaceholder = exports.getFieldValue = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.EditMode = exports.LayoutServicePageState = void 0;
4
4
  // layout
5
5
  var models_1 = require("./models");
6
6
  Object.defineProperty(exports, "LayoutServicePageState", { enumerable: true, get: function () { return models_1.LayoutServicePageState; } });
@@ -21,4 +21,4 @@ var graphql_layout_service_1 = require("./graphql-layout-service");
21
21
  Object.defineProperty(exports, "GraphQLLayoutService", { enumerable: true, get: function () { return graphql_layout_service_1.GraphQLLayoutService; } });
22
22
  Object.defineProperty(exports, "GRAPHQL_LAYOUT_QUERY_NAME", { enumerable: true, get: function () { return graphql_layout_service_1.GRAPHQL_LAYOUT_QUERY_NAME; } });
23
23
  var themes_1 = require("./themes");
24
- Object.defineProperty(exports, "getComponentLibraryStylesheetLinks", { enumerable: true, get: function () { return themes_1.getComponentLibraryStylesheetLinks; } });
24
+ Object.defineProperty(exports, "getDesignLibraryStylesheetLinks", { enumerable: true, get: function () { return themes_1.getDesignLibraryStylesheetLinks; } });
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getStylesheetUrl = void 0;
4
- exports.getComponentLibraryStylesheetLinks = getComponentLibraryStylesheetLinks;
4
+ exports.getDesignLibraryStylesheetLinks = getDesignLibraryStylesheetLinks;
5
5
  const _1 = require(".");
6
6
  const constants_1 = require("../constants");
7
7
  /**
@@ -10,13 +10,13 @@ const constants_1 = require("../constants");
10
10
  */
11
11
  const STYLES_LIBRARY_ID_REGEX = /-library--([^\s]+)/;
12
12
  /**
13
- * Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Component Library Stylesheets that are used
13
+ * Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Design Library Stylesheets that are used
14
14
  * @param {LayoutServiceData} layoutData Layout service data
15
15
  * @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
16
16
  * @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
17
17
  * @returns {HTMLLink[]} library stylesheet links
18
18
  */
19
- function getComponentLibraryStylesheetLinks(layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) {
19
+ function getDesignLibraryStylesheetLinks(layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) {
20
20
  const ids = new Set();
21
21
  if (!layoutData.sitecore.route)
22
22
  return [];
@@ -1,6 +1,6 @@
1
1
  import { GraphQLEditingService, RestComponentLayoutService, } from '../editing';
2
2
  import { GraphQLDictionaryService } from '../i18n';
3
- import { getComponentLibraryStylesheetLinks, getContentStylesheetLink, GraphQLLayoutService, } from '../layout';
3
+ import { getDesignLibraryStylesheetLinks, getContentStylesheetLink, GraphQLLayoutService, } from '../layout';
4
4
  import { getGroomedVariantIds } from '../personalize/utils';
5
5
  import { personalizeLayout } from '../personalize/layout-personalizer';
6
6
  import { SiteResolver, GraphQLErrorPagesService, GraphQLSitePathService, } from '../site';
@@ -104,7 +104,7 @@ export class SitecoreClient {
104
104
  headLinks.push(contentStyles);
105
105
  }
106
106
  if (enableThemes) {
107
- headLinks.push(...getComponentLibraryStylesheetLinks(layoutData, contextId, edgeUrl));
107
+ headLinks.push(...getDesignLibraryStylesheetLinks(layoutData, contextId, edgeUrl));
108
108
  }
109
109
  return headLinks;
110
110
  }
@@ -164,16 +164,16 @@ export class SitecoreClient {
164
164
  return page;
165
165
  }
166
166
  /**
167
- * Get component library page details for Component Library mode of your app
168
- * @param {ComponentLibraryRenderPreviewData} componentLibData preview data set in 'library' mode of the app
167
+ * Get design library page details for Design Library mode of your app
168
+ * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
169
169
  * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
170
- * @returns {Page} preview page for Component Library
170
+ * @returns {Page} preview page for Design Library
171
171
  */
172
- async getComponentLibraryData(componentLibData, fetchOptions) {
172
+ async getDesignLibraryData(designLibData, fetchOptions) {
173
173
  if (!this.initOptions.api.local) {
174
174
  throw new Error('Component Library requires Sitecore apiHost and apiKey to be provided');
175
175
  }
176
- const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = componentLibData;
176
+ const { itemId, componentUid, site, language, renderingId, dataSourceId, version, } = designLibData;
177
177
  const componentData = await this.componentService.fetchComponentData({
178
178
  siteName: site,
179
179
  itemId,
@@ -188,10 +188,10 @@ export class SitecoreClient {
188
188
  language,
189
189
  }, fetchOptions);
190
190
  if (!componentData) {
191
- throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(componentLibData)}`);
191
+ throw new Error(`Unable to fetch editing data for preview ${JSON.stringify(designLibData)}`);
192
192
  }
193
193
  const page = {
194
- locale: componentLibData.language,
194
+ locale: designLibData.language,
195
195
  layout: componentData,
196
196
  dictionary: dictionaryData,
197
197
  };
package/dist/esm/debug.js CHANGED
@@ -22,6 +22,7 @@ export const enableDebug = (namespaces) => debug.enable(namespaces);
22
22
  */
23
23
  export default {
24
24
  common: debug(`${rootNamespace}:common`),
25
+ form: debug(`${rootNamespace}:form`),
25
26
  http: debug(`${rootNamespace}:http`),
26
27
  layout: debug(`${rootNamespace}:layout`),
27
28
  dictionary: debug(`${rootNamespace}:dictionary`),
@@ -1,19 +1,19 @@
1
1
  /**
2
- * Event to be sent when report status to component library
2
+ * Event to be sent when report status to design library
3
3
  */
4
- export const COMPONENT_LIBRARY_STATUS_EVENT_NAME = 'component:status';
4
+ export const DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
5
5
  /**
6
- * Enumeration of statuses for the component library.
6
+ * Enumeration of statuses for the design library.
7
7
  */
8
- export var ComponentLibraryStatus;
9
- (function (ComponentLibraryStatus) {
10
- ComponentLibraryStatus["READY"] = "ready";
11
- ComponentLibraryStatus["RENDERED"] = "rendered";
12
- })(ComponentLibraryStatus || (ComponentLibraryStatus = {}));
8
+ export var DesignLibraryStatus;
9
+ (function (DesignLibraryStatus) {
10
+ DesignLibraryStatus["READY"] = "ready";
11
+ DesignLibraryStatus["RENDERED"] = "rendered";
12
+ })(DesignLibraryStatus || (DesignLibraryStatus = {}));
13
13
  /**
14
- * Adds the browser-side event handler for 'component:update' message used in Component Library
14
+ * Adds the browser-side event handler for 'component:update' message used in Design Library
15
15
  * The event should update a component on page by uid, with fields and params from event args
16
- * @param {ComponentRendering} rootComponent root component displayed for Component Library page
16
+ * @param {ComponentRendering} rootComponent root component displayed for Design Library page
17
17
  * @param {Function} successCallback callback to be called after successful component update
18
18
  */
19
19
  export const addComponentUpdateHandler = (rootComponent, successCallback) => {
@@ -82,14 +82,14 @@ export const updateComponentHandler = (e, rootComponent, successCallback) => {
82
82
  return rootComponent;
83
83
  };
84
84
  /**
85
- * Generates a ComponentLibraryStatusEvent with the given status and uid.
86
- * @param {ComponentLibraryStatus} status - The status of rendering.
85
+ * Generates a DesignLibraryStatusEvent with the given status and uid.
86
+ * @param {DesignLibraryStatus} status - The status of rendering.
87
87
  * @param {string} uid - The unique identifier for the event.
88
- * @returns An object representing the ComponentLibraryStatusEvent.
88
+ * @returns An object representing the DesignLibraryStatusEvent.
89
89
  */
90
- export function getComponentLibraryStatusEvent(status, uid) {
90
+ export function getDesignLibraryStatusEvent(status, uid) {
91
91
  return {
92
- name: COMPONENT_LIBRARY_STATUS_EVENT_NAME,
92
+ name: DESIGN_LIBRARY_STATUS_EVENT_NAME,
93
93
  message: {
94
94
  status,
95
95
  uid,
@@ -2,4 +2,4 @@ export { GraphQLEditingService } from './graphql-editing-service';
2
2
  export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, getJssPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, PAGES_EDITING_MARKER, } from './utils';
3
3
  export { RestComponentLayoutService, } from './rest-component-layout-service';
4
4
  export { LayoutKind, MetadataKind, } from './models';
5
- export { addComponentUpdateHandler, ComponentLibraryStatus, getComponentLibraryStatusEvent, } from './component-library';
5
+ export { addComponentUpdateHandler, DesignLibraryStatus, getDesignLibraryStatusEvent, } from './design-library';
@@ -1,7 +1,7 @@
1
1
  import { debug, NativeDataFetcher } from '..';
2
2
  import { fetchData } from '../data-fetcher';
3
3
  /**
4
- * REST service that enables Component Library functioality
4
+ * REST service that enables Design Library functioality
5
5
  * Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
6
6
  * Returns layoutData for one single rendered component
7
7
  */
@@ -0,0 +1,69 @@
1
+ import { form } from '@sitecore-cloudsdk/events/browser';
2
+ import { getEdgeProxyFormsUrl } from '../client';
3
+ import debug from '../debug';
4
+ /**
5
+ * Fetches the form markup from the Sitecore Edge service and renders it in the component's template.
6
+ * @param {string} contextId - The unique identifier of the current context
7
+ * @param {string} formId - The unique identifier of the form
8
+ * @param {string} [edgeUrl] - The URL of the Sitecore Edge Platform
9
+ */
10
+ export const loadForm = async (contextId, formId, edgeUrl) => {
11
+ if (!contextId) {
12
+ debug.form('Form was not able to render since context id was not provided');
13
+ return '';
14
+ }
15
+ const url = getEdgeProxyFormsUrl(contextId, formId, edgeUrl);
16
+ try {
17
+ debug.form(`Fetching form data from ${url}`);
18
+ const rsp = await fetch(url, {
19
+ method: 'GET',
20
+ cache: 'no-cache',
21
+ });
22
+ if (rsp.status !== 200) {
23
+ throw new Error('Failed to fetch form data');
24
+ }
25
+ const content = await rsp.text();
26
+ debug.form(`Form data fetch response: ${content}`);
27
+ return content;
28
+ }
29
+ catch (error) {
30
+ debug.form(`Form '${formId}' was not able to render`, error);
31
+ throw error;
32
+ }
33
+ };
34
+ /**
35
+ * When you set the innerHTML property of an element, the browser does not execute any <script> tags included in the HTML string
36
+ * This method ensures that any <script> elements within the loaded HTML are executed.
37
+ * It re-creates the script elements and appends the to the component's template, then removes old script elements to avoid duplication.
38
+ * @param {HTMLElement} rootElement - The root element to execute script elements within
39
+ */
40
+ export const executeScriptElements = (rootElement) => {
41
+ const scriptElements = rootElement.querySelectorAll('script');
42
+ if (!scriptElements) {
43
+ return;
44
+ }
45
+ Array.from(scriptElements).forEach((scriptElement) => {
46
+ var _a;
47
+ const clonedElement = document.createElement('script');
48
+ Array.from(scriptElement.attributes).forEach((attribute) => {
49
+ clonedElement.setAttribute(attribute.name, attribute.value);
50
+ });
51
+ clonedElement.text = scriptElement.text;
52
+ (_a = scriptElement === null || scriptElement === void 0 ? void 0 : scriptElement.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(clonedElement, scriptElement);
53
+ });
54
+ };
55
+ /**
56
+ * Subscribes to the Form event and then sends data to CloudSDK.
57
+ * This listener captures interactions such as form views or submissions
58
+ * @param {HTMLElement} formElement - The form element to subscribe to events on
59
+ * @param {string} [componentId] - The unique identifier of the component
60
+ */
61
+ export const subscribeToFormSubmitEvent = (formElement, componentId) => {
62
+ formElement.addEventListener('form:engage', ((e) => {
63
+ const { formId, name } = e.detail;
64
+ if (formId && name) {
65
+ debug.form('Sending form event', formId, name);
66
+ form(formId, name, (componentId === null || componentId === void 0 ? void 0 : componentId.replace(/-/g, '')) || '');
67
+ }
68
+ }));
69
+ };
@@ -0,0 +1 @@
1
+ export { executeScriptElements, loadForm, subscribeToFormSubmitEvent } from './form';
@@ -3,4 +3,4 @@ export { LayoutServicePageState, EditMode, RenderingType, EDITING_COMPONENT_PLAC
3
3
  export { getFieldValue, getChildPlaceholder, isFieldValueEmpty, isDynamicPlaceholder, getDynamicPlaceholderPattern, EMPTY_DATE_FIELD_VALUE, } from './utils';
4
4
  export { getContentStylesheetLink } from './content-styles';
5
5
  export { GraphQLLayoutService, GRAPHQL_LAYOUT_QUERY_NAME, } from './graphql-layout-service';
6
- export { getComponentLibraryStylesheetLinks } from './themes';
6
+ export { getDesignLibraryStylesheetLinks } from './themes';
@@ -6,13 +6,13 @@ import { SITECORE_EDGE_URL_DEFAULT } from '../constants';
6
6
  */
7
7
  const STYLES_LIBRARY_ID_REGEX = /-library--([^\s]+)/;
8
8
  /**
9
- * Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Component Library Stylesheets that are used
9
+ * Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Design Library Stylesheets that are used
10
10
  * @param {LayoutServiceData} layoutData Layout service data
11
11
  * @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
12
12
  * @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
13
13
  * @returns {HTMLLink[]} library stylesheet links
14
14
  */
15
- export function getComponentLibraryStylesheetLinks(layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
15
+ export function getDesignLibraryStylesheetLinks(layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
16
16
  const ids = new Set();
17
17
  if (!layoutData.sitecore.route)
18
18
  return [];
package/form.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/form/index';
package/form.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/form/index');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-content-sdk/core",
3
- "version": "0.1.0-beta.26",
3
+ "version": "0.1.0-beta.29",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -15,7 +15,7 @@
15
15
  "test": "mocha \"./src/**/*.test.ts\"",
16
16
  "prepublishOnly": "npm run build",
17
17
  "coverage": "nyc npm test",
18
- "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/config/index.ts --entryPoints src/client/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --entryPoints src/tools/index.ts --githubPages false"
18
+ "generate-docs": "npx typedoc --plugin typedoc-plugin-markdown --outputFileStrategy Members --parametersFormat table --readme none --out ../../ref-docs/core --entryPoints src/index.ts --entryPoints src/config/index.ts --entryPoints src/form/index.ts --entryPoints src/client/index.ts --entryPoints src/i18n/index.ts --entryPoints src/layout/index.ts --entryPoints src/media/index.ts --entryPoints src/personalize/index.ts --entryPoints src/site/index.ts --entryPoints src/tracking/index.ts --entryPoints src/utils/index.ts --entryPoints src/editing/index.ts --entryPoints src/tools/index.ts --githubPages false"
19
19
  },
20
20
  "engines": {
21
21
  "node": ">=22"
@@ -34,13 +34,16 @@
34
34
  "url": "https://github.com/sitecore/jss/issues"
35
35
  },
36
36
  "devDependencies": {
37
+ "@sitecore-cloudsdk/events": "^0.4.2",
37
38
  "@types/chai": "^5.0.1",
38
39
  "@types/chai-spies": "^1.0.6",
39
40
  "@types/chai-string": "^1.4.5",
40
41
  "@types/debug": "^4.1.12",
42
+ "@types/jsdom": "^21.1.7",
41
43
  "@types/memory-cache": "^0.2.6",
42
44
  "@types/mocha": "^10.0.1",
43
45
  "@types/node": "^22.12.0",
46
+ "@types/proxyquire": "^1.3.31",
44
47
  "@types/sinon": "^17.0.3",
45
48
  "@types/url-parse": "1.4.11",
46
49
  "chai": "^4.2.0",
@@ -49,6 +52,7 @@
49
52
  "del-cli": "^6.0.0",
50
53
  "eslint": "^8.56.0",
51
54
  "eslint-plugin-jsdoc": "48.7.0",
55
+ "jsdom": "^26.0.0",
52
56
  "mocha": "^11.1.0",
53
57
  "nock": "14.0.0-beta.7",
54
58
  "nyc": "^17.1.0",
@@ -58,6 +62,9 @@
58
62
  "tsx": "^4.19.2",
59
63
  "typescript": "~5.7.3"
60
64
  },
65
+ "peerDependencies": {
66
+ "@sitecore-cloudsdk/events": "^0.4.2"
67
+ },
61
68
  "dependencies": {
62
69
  "chalk": "^4.1.2",
63
70
  "debug": "^4.4.0",
@@ -68,7 +75,7 @@
68
75
  },
69
76
  "description": "",
70
77
  "types": "types/index.d.ts",
71
- "gitHead": "534f88bad88d588fc2be201ae29c1b065a539e8e",
78
+ "gitHead": "2f4fef1dfc43acdc0221efb4287f62970c24c61b",
72
79
  "files": [
73
80
  "dist",
74
81
  "types",
@@ -1,4 +1,4 @@
1
- import { ComponentLibraryRenderPreviewData, EditingPreviewData, GraphQLEditingService, RestComponentLayoutService } from '../editing';
1
+ import { DesignLibraryRenderPreviewData, EditingPreviewData, GraphQLEditingService, RestComponentLayoutService } from '../editing';
2
2
  import { GraphQLRequestClientFactory } from '../graphql-request-client';
3
3
  import { DictionaryPhrases, GraphQLDictionaryService } from '../i18n';
4
4
  import { GraphQLLayoutService, LayoutServiceData, RouteOptions } from '../layout';
@@ -163,12 +163,12 @@ export declare class SitecoreClient implements BaseSitecoreClient {
163
163
  */
164
164
  getPreview(previewData: EditingPreviewData | undefined, fetchOptions?: FetchOptions): Promise<Page | null>;
165
165
  /**
166
- * Get component library page details for Component Library mode of your app
167
- * @param {ComponentLibraryRenderPreviewData} componentLibData preview data set in 'library' mode of the app
166
+ * Get design library page details for Design Library mode of your app
167
+ * @param {DesignLibraryRenderPreviewData} designLibData preview data set in 'library' mode of the app
168
168
  * @param {FetchOptions} [fetchOptions] Additional fetch fetch options to override GraphQL requests (like retries and fetch)
169
- * @returns {Page} preview page for Component Library
169
+ * @returns {Page} preview page for Design Library
170
170
  */
171
- getComponentLibraryData(componentLibData: ComponentLibraryRenderPreviewData, fetchOptions?: FetchOptions): Promise<Page>;
171
+ getDesignLibraryData(designLibData: DesignLibraryRenderPreviewData, fetchOptions?: FetchOptions): Promise<Page>;
172
172
  /**
173
173
  * Retrieves the static paths for pages based on the given languages.
174
174
  * @param {string[]} [languages] - An optional array of language codes to generate paths for.
package/types/debug.d.ts CHANGED
@@ -11,6 +11,7 @@ export declare const enableDebug: (namespaces: string) => void;
11
11
  */
12
12
  declare const _default: {
13
13
  common: debug.Debugger;
14
+ form: debug.Debugger;
14
15
  http: debug.Debugger;
15
16
  layout: debug.Debugger;
16
17
  dictionary: debug.Debugger;
@@ -1,27 +1,27 @@
1
1
  import { ComponentRendering, Field, GenericFieldValue } from '../layout/models';
2
2
  /**
3
- * Event to be sent when report status to component library
3
+ * Event to be sent when report status to design library
4
4
  */
5
- export declare const COMPONENT_LIBRARY_STATUS_EVENT_NAME = "component:status";
5
+ export declare const DESIGN_LIBRARY_STATUS_EVENT_NAME = "component:status";
6
6
  /**
7
7
  * Represents an event indicating the status of a component in the library.
8
8
  */
9
- export interface ComponentLibraryStatusEvent {
10
- name: typeof COMPONENT_LIBRARY_STATUS_EVENT_NAME;
9
+ export interface DesignLibraryStatusEvent {
10
+ name: typeof DESIGN_LIBRARY_STATUS_EVENT_NAME;
11
11
  message: {
12
12
  status: 'ready' | 'rendered';
13
13
  uid: string;
14
14
  };
15
15
  }
16
16
  /**
17
- * Enumeration of statuses for the component library.
17
+ * Enumeration of statuses for the design library.
18
18
  */
19
- export declare enum ComponentLibraryStatus {
19
+ export declare enum DesignLibraryStatus {
20
20
  READY = "ready",
21
21
  RENDERED = "rendered"
22
22
  }
23
23
  /**
24
- * Event args for Component Library `update` event
24
+ * Event args for Design Library `update` event
25
25
  */
26
26
  export interface ComponentUpdateEventArgs {
27
27
  name: string;
@@ -32,17 +32,17 @@ export interface ComponentUpdateEventArgs {
32
32
  };
33
33
  }
34
34
  /**
35
- * Adds the browser-side event handler for 'component:update' message used in Component Library
35
+ * Adds the browser-side event handler for 'component:update' message used in Design Library
36
36
  * The event should update a component on page by uid, with fields and params from event args
37
- * @param {ComponentRendering} rootComponent root component displayed for Component Library page
37
+ * @param {ComponentRendering} rootComponent root component displayed for Design Library page
38
38
  * @param {Function} successCallback callback to be called after successful component update
39
39
  */
40
40
  export declare const addComponentUpdateHandler: (rootComponent: ComponentRendering, successCallback?: (updatedRootComponent: ComponentRendering) => void) => (() => void) | undefined;
41
41
  export declare const updateComponentHandler: (e: MessageEvent, rootComponent: ComponentRendering, successCallback?: (updatedRootComponent: ComponentRendering) => void) => ComponentRendering<import("../layout/models").ComponentFields> | undefined;
42
42
  /**
43
- * Generates a ComponentLibraryStatusEvent with the given status and uid.
44
- * @param {ComponentLibraryStatus} status - The status of rendering.
43
+ * Generates a DesignLibraryStatusEvent with the given status and uid.
44
+ * @param {DesignLibraryStatus} status - The status of rendering.
45
45
  * @param {string} uid - The unique identifier for the event.
46
- * @returns An object representing the ComponentLibraryStatusEvent.
46
+ * @returns An object representing the DesignLibraryStatusEvent.
47
47
  */
48
- export declare function getComponentLibraryStatusEvent(status: ComponentLibraryStatus, uid: string): ComponentLibraryStatusEvent;
48
+ export declare function getDesignLibraryStatusEvent(status: DesignLibraryStatus, uid: string): DesignLibraryStatusEvent;
@@ -2,5 +2,5 @@ export { GraphQLEditingService } from './graphql-editing-service';
2
2
  export { DEFAULT_PLACEHOLDER_UID, PagesEditor, isEditorActive, resetEditorChromes, Metadata, getJssPagesClientData, EDITING_ALLOWED_ORIGINS, QUERY_PARAM_EDITING_SECRET, PAGES_EDITING_MARKER, ComponentUpdateEventArgs, } from './utils';
3
3
  export { RestComponentLayoutService, ComponentLayoutRequestParams, } from './rest-component-layout-service';
4
4
  export { EditingRenderQueryParams, RenderComponentQueryParams } from './models';
5
- export { LayoutKind, MetadataKind, EditingPreviewData, ComponentLibraryRenderPreviewData, } from './models';
6
- export { addComponentUpdateHandler, ComponentLibraryStatus, ComponentLibraryStatusEvent, getComponentLibraryStatusEvent, } from './component-library';
5
+ export { LayoutKind, MetadataKind, EditingPreviewData, DesignLibraryRenderPreviewData, } from './models';
6
+ export { addComponentUpdateHandler, DesignLibraryStatus, DesignLibraryStatusEvent, getDesignLibraryStatusEvent, } from './design-library';
@@ -63,9 +63,9 @@ export type EditingPreviewData = {
63
63
  layoutKind?: LayoutKind;
64
64
  };
65
65
  /**
66
- * Data for Component Library rendering mode
66
+ * Data for Design Library rendering mode
67
67
  */
68
- export interface ComponentLibraryRenderPreviewData {
68
+ export interface DesignLibraryRenderPreviewData {
69
69
  site: string;
70
70
  itemId: string;
71
71
  renderingId: string;
@@ -37,7 +37,7 @@ export type RestLayoutServiceConfig = {
37
37
  configurationName?: string;
38
38
  };
39
39
  /**
40
- * Params for requesting component data from service in Component Library mode
40
+ * Params for requesting component data from service in Design Library mode
41
41
  */
42
42
  export interface ComponentLayoutRequestParams {
43
43
  /**
@@ -75,7 +75,7 @@ export interface ComponentLayoutRequestParams {
75
75
  siteName?: string;
76
76
  }
77
77
  /**
78
- * REST service that enables Component Library functioality
78
+ * REST service that enables Design Library functioality
79
79
  * Makes a request to /sitecore/api/layout/component in 'library' mode in Pages.
80
80
  * Returns layoutData for one single rendered component
81
81
  */
@@ -17,7 +17,7 @@ export declare const PAGES_EDITING_MARKER = "jss-hrz-editing";
17
17
  */
18
18
  export declare const EDITING_ALLOWED_ORIGINS: string[];
19
19
  /**
20
- * Event args for Component Library `update` event
20
+ * Event args for Design Library `update` event
21
21
  */
22
22
  export interface ComponentUpdateEventArgs {
23
23
  name: string;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Fetches the form markup from the Sitecore Edge service and renders it in the component's template.
3
+ * @param {string} contextId - The unique identifier of the current context
4
+ * @param {string} formId - The unique identifier of the form
5
+ * @param {string} [edgeUrl] - The URL of the Sitecore Edge Platform
6
+ */
7
+ export declare const loadForm: (contextId: string, formId: string, edgeUrl?: string) => Promise<string>;
8
+ /**
9
+ * When you set the innerHTML property of an element, the browser does not execute any <script> tags included in the HTML string
10
+ * This method ensures that any <script> elements within the loaded HTML are executed.
11
+ * It re-creates the script elements and appends the to the component's template, then removes old script elements to avoid duplication.
12
+ * @param {HTMLElement} rootElement - The root element to execute script elements within
13
+ */
14
+ export declare const executeScriptElements: (rootElement: HTMLElement) => void;
15
+ /**
16
+ * Subscribes to the Form event and then sends data to CloudSDK.
17
+ * This listener captures interactions such as form views or submissions
18
+ * @param {HTMLElement} formElement - The form element to subscribe to events on
19
+ * @param {string} [componentId] - The unique identifier of the component
20
+ */
21
+ export declare const subscribeToFormSubmitEvent: (formElement: HTMLElement, componentId?: string) => void;
@@ -0,0 +1 @@
1
+ export { executeScriptElements, loadForm, subscribeToFormSubmitEvent } from './form';
@@ -2,4 +2,4 @@ export { LayoutServiceData, LayoutServicePageState, LayoutServiceContext, Layout
2
2
  export { getFieldValue, getChildPlaceholder, isFieldValueEmpty, isDynamicPlaceholder, getDynamicPlaceholderPattern, EMPTY_DATE_FIELD_VALUE, } from './utils';
3
3
  export { getContentStylesheetLink } from './content-styles';
4
4
  export { GraphQLLayoutService, GraphQLLayoutServiceConfig, GRAPHQL_LAYOUT_QUERY_NAME, } from './graphql-layout-service';
5
- export { getComponentLibraryStylesheetLinks } from './themes';
5
+ export { getDesignLibraryStylesheetLinks } from './themes';
@@ -1,11 +1,11 @@
1
1
  import { LayoutServiceData } from '.';
2
2
  import { HTMLLink } from '../models';
3
3
  /**
4
- * Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Component Library Stylesheets that are used
4
+ * Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Design Library Stylesheets that are used
5
5
  * @param {LayoutServiceData} layoutData Layout service data
6
6
  * @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
7
7
  * @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
8
8
  * @returns {HTMLLink[]} library stylesheet links
9
9
  */
10
- export declare function getComponentLibraryStylesheetLinks(layoutData: LayoutServiceData, sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string): HTMLLink[];
10
+ export declare function getDesignLibraryStylesheetLinks(layoutData: LayoutServiceData, sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string): HTMLLink[];
11
11
  export declare const getStylesheetUrl: (id: string, sitecoreEdgeContextId: string, sitecoreEdgeUrl?: string) => string;