@sitecore-content-sdk/content 1.5.0-canary.5
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/LICENSE.txt +202 -0
- package/README.md +7 -0
- package/client.d.ts +1 -0
- package/codegen.d.ts +1 -0
- package/config-cli.d.ts +1 -0
- package/config.d.ts +1 -0
- package/dist/cjs/client/edge-proxy.js +24 -0
- package/dist/cjs/client/index.js +14 -0
- package/dist/cjs/client/models.js +2 -0
- package/dist/cjs/client/sitecore-client.js +420 -0
- package/dist/cjs/client/utils.js +53 -0
- package/dist/cjs/config/define-config.js +195 -0
- package/dist/cjs/config/index.js +7 -0
- package/dist/cjs/config/models.js +12 -0
- package/dist/cjs/config-cli/define-cli-config.js +23 -0
- package/dist/cjs/config-cli/index.js +7 -0
- package/dist/cjs/config-cli/models.js +8 -0
- package/dist/cjs/constants.js +12 -0
- package/dist/cjs/debug.js +21 -0
- package/dist/cjs/editing/codegen/index.js +14 -0
- package/dist/cjs/editing/codegen/preview.js +277 -0
- package/dist/cjs/editing/component-layout-service.js +62 -0
- package/dist/cjs/editing/design-library.js +184 -0
- package/dist/cjs/editing/editing-service.js +81 -0
- package/dist/cjs/editing/index.js +33 -0
- package/dist/cjs/editing/models.js +44 -0
- package/dist/cjs/editing/utils.js +105 -0
- package/dist/cjs/form/form.js +81 -0
- package/dist/cjs/form/index.js +7 -0
- package/dist/cjs/i18n/dictionary-service.js +144 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/i18n/utils.js +16 -0
- package/dist/cjs/index.js +47 -0
- package/dist/cjs/layout/content-styles.js +73 -0
- package/dist/cjs/layout/index.js +24 -0
- package/dist/cjs/layout/layout-service.js +68 -0
- package/dist/cjs/layout/models.js +39 -0
- package/dist/cjs/layout/themes.js +77 -0
- package/dist/cjs/layout/utils.js +117 -0
- package/dist/cjs/media/index.js +38 -0
- package/dist/cjs/media/media-api.js +100 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/personalize/index.js +15 -0
- package/dist/cjs/personalize/layout-personalizer.js +98 -0
- package/dist/cjs/personalize/personalize-service.js +109 -0
- package/dist/cjs/personalize/utils.js +143 -0
- package/dist/cjs/site/error-pages-service.js +82 -0
- package/dist/cjs/site/index.js +26 -0
- package/dist/cjs/site/models.js +2 -0
- package/dist/cjs/site/redirects-service.js +109 -0
- package/dist/cjs/site/robots-service.js +74 -0
- package/dist/cjs/site/site-resolver.js +73 -0
- package/dist/cjs/site/siteinfo-service.js +94 -0
- package/dist/cjs/site/sitemap-xml-service.js +92 -0
- package/dist/cjs/site/sitepath-service.js +201 -0
- package/dist/cjs/site/utils.js +55 -0
- package/dist/cjs/sitecore-service-base.js +33 -0
- package/dist/cjs/tools/codegen/component-generation.js +49 -0
- package/dist/cjs/tools/codegen/extract-files.js +105 -0
- package/dist/cjs/tools/codegen/import-map.js +411 -0
- package/dist/cjs/tools/codegen/utils.js +418 -0
- package/dist/cjs/tools/generate-map.js +2 -0
- package/dist/cjs/tools/generateSites.js +59 -0
- package/dist/cjs/tools/index.js +30 -0
- package/dist/cjs/tools/scaffold.js +62 -0
- package/dist/cjs/tools/templating/components.js +96 -0
- package/dist/cjs/tools/templating/index.js +6 -0
- package/dist/esm/client/edge-proxy.js +19 -0
- package/dist/esm/client/index.js +4 -0
- package/dist/esm/client/models.js +1 -0
- package/dist/esm/client/sitecore-client.js +416 -0
- package/dist/esm/client/utils.js +49 -0
- package/dist/esm/config/define-config.js +189 -0
- package/dist/esm/config/index.js +2 -0
- package/dist/esm/config/models.js +9 -0
- package/dist/esm/config-cli/define-cli-config.js +19 -0
- package/dist/esm/config-cli/index.js +2 -0
- package/dist/esm/config-cli/models.js +5 -0
- package/dist/esm/constants.js +9 -0
- package/dist/esm/debug.js +19 -0
- package/dist/esm/editing/codegen/index.js +1 -0
- package/dist/esm/editing/codegen/preview.js +263 -0
- package/dist/esm/editing/component-layout-service.js +55 -0
- package/dist/esm/editing/design-library.js +172 -0
- package/dist/esm/editing/editing-service.js +74 -0
- package/dist/esm/editing/index.js +6 -0
- package/dist/esm/editing/models.js +41 -0
- package/dist/esm/editing/utils.js +98 -0
- package/dist/esm/form/form.js +72 -0
- package/dist/esm/form/index.js +1 -0
- package/dist/esm/i18n/dictionary-service.js +137 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/i18n/utils.js +13 -0
- package/dist/esm/index.js +5 -0
- package/dist/esm/layout/content-styles.js +65 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +61 -0
- package/dist/esm/layout/models.js +36 -0
- package/dist/esm/layout/themes.js +72 -0
- package/dist/esm/layout/utils.js +109 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +90 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/personalize/index.js +3 -0
- package/dist/esm/personalize/layout-personalizer.js +93 -0
- package/dist/esm/personalize/personalize-service.js +102 -0
- package/dist/esm/personalize/utils.js +135 -0
- package/dist/esm/site/error-pages-service.js +75 -0
- package/dist/esm/site/index.js +8 -0
- package/dist/esm/site/models.js +1 -0
- package/dist/esm/site/redirects-service.js +102 -0
- package/dist/esm/site/robots-service.js +67 -0
- package/dist/esm/site/site-resolver.js +69 -0
- package/dist/esm/site/siteinfo-service.js +87 -0
- package/dist/esm/site/sitemap-xml-service.js +85 -0
- package/dist/esm/site/sitepath-service.js +193 -0
- package/dist/esm/site/utils.js +49 -0
- package/dist/esm/sitecore-service-base.js +29 -0
- package/dist/esm/tools/codegen/component-generation.js +44 -0
- package/dist/esm/tools/codegen/extract-files.js +99 -0
- package/dist/esm/tools/codegen/import-map.js +368 -0
- package/dist/esm/tools/codegen/utils.js +373 -0
- package/dist/esm/tools/generate-map.js +1 -0
- package/dist/esm/tools/generateSites.js +52 -0
- package/dist/esm/tools/index.js +6 -0
- package/dist/esm/tools/scaffold.js +54 -0
- package/dist/esm/tools/templating/components.js +59 -0
- package/dist/esm/tools/templating/index.js +1 -0
- package/editing.d.ts +1 -0
- package/i18n.d.ts +1 -0
- package/layout.d.ts +1 -0
- package/media.d.ts +1 -0
- package/package.json +157 -0
- package/personalize.d.ts +1 -0
- package/site.d.ts +1 -0
- package/tools.d.ts +1 -0
- package/types/client/edge-proxy.d.ts +17 -0
- package/types/client/edge-proxy.d.ts.map +1 -0
- package/types/client/index.d.ts +7 -0
- package/types/client/index.d.ts.map +1 -0
- package/types/client/models.d.ts +21 -0
- package/types/client/models.d.ts.map +1 -0
- package/types/client/sitecore-client.d.ts +338 -0
- package/types/client/sitecore-client.d.ts.map +1 -0
- package/types/client/utils.d.ts +15 -0
- package/types/client/utils.d.ts.map +1 -0
- package/types/config/define-config.d.ts +20 -0
- package/types/config/define-config.d.ts.map +1 -0
- package/types/config/index.d.ts +3 -0
- package/types/config/index.d.ts.map +1 -0
- package/types/config/models.d.ts +287 -0
- package/types/config/models.d.ts.map +1 -0
- package/types/config-cli/define-cli-config.d.ts +9 -0
- package/types/config-cli/define-cli-config.d.ts.map +1 -0
- package/types/config-cli/index.d.ts +3 -0
- package/types/config-cli/index.d.ts.map +1 -0
- package/types/config-cli/models.d.ts +6 -0
- package/types/config-cli/models.d.ts.map +1 -0
- package/types/constants.d.ts +10 -0
- package/types/constants.d.ts.map +1 -0
- package/types/debug.d.ts +19 -0
- package/types/debug.d.ts.map +1 -0
- package/types/editing/codegen/index.d.ts +2 -0
- package/types/editing/codegen/index.d.ts.map +1 -0
- package/types/editing/codegen/preview.d.ts +256 -0
- package/types/editing/codegen/preview.d.ts.map +1 -0
- package/types/editing/component-layout-service.d.ts +84 -0
- package/types/editing/component-layout-service.d.ts.map +1 -0
- package/types/editing/design-library.d.ts +111 -0
- package/types/editing/design-library.d.ts.map +1 -0
- package/types/editing/editing-service.d.ts +71 -0
- package/types/editing/editing-service.d.ts.map +1 -0
- package/types/editing/index.d.ts +7 -0
- package/types/editing/index.d.ts.map +1 -0
- package/types/editing/models.d.ts +103 -0
- package/types/editing/models.d.ts.map +1 -0
- package/types/editing/utils.d.ts +82 -0
- package/types/editing/utils.d.ts.map +1 -0
- package/types/form/form.d.ts +25 -0
- package/types/form/form.d.ts.map +1 -0
- package/types/form/index.d.ts +2 -0
- package/types/form/index.d.ts.map +1 -0
- package/types/i18n/dictionary-service.d.ts +133 -0
- package/types/i18n/dictionary-service.d.ts.map +1 -0
- package/types/i18n/index.d.ts +3 -0
- package/types/i18n/index.d.ts.map +1 -0
- package/types/i18n/utils.d.ts +9 -0
- package/types/i18n/utils.d.ts.map +1 -0
- package/types/index.d.ts +7 -0
- package/types/index.d.ts.map +1 -0
- package/types/layout/content-styles.d.ts +20 -0
- package/types/layout/content-styles.d.ts.map +1 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/index.d.ts.map +1 -0
- package/types/layout/layout-service.d.ts +45 -0
- package/types/layout/layout-service.d.ts.map +1 -0
- package/types/layout/models.d.ts +174 -0
- package/types/layout/models.d.ts.map +1 -0
- package/types/layout/themes.d.ts +13 -0
- package/types/layout/themes.d.ts.map +1 -0
- package/types/layout/utils.d.ts +56 -0
- package/types/layout/utils.d.ts.map +1 -0
- package/types/media/index.d.ts +3 -0
- package/types/media/index.d.ts.map +1 -0
- package/types/media/media-api.d.ts +60 -0
- package/types/media/media-api.d.ts.map +1 -0
- package/types/models.d.ts +32 -0
- package/types/models.d.ts.map +1 -0
- package/types/personalize/index.d.ts +4 -0
- package/types/personalize/index.d.ts.map +1 -0
- package/types/personalize/layout-personalizer.d.ts +29 -0
- package/types/personalize/layout-personalizer.d.ts.map +1 -0
- package/types/personalize/personalize-service.d.ts +89 -0
- package/types/personalize/personalize-service.d.ts.map +1 -0
- package/types/personalize/utils.d.ts +78 -0
- package/types/personalize/utils.d.ts.map +1 -0
- package/types/site/error-pages-service.d.ts +64 -0
- package/types/site/error-pages-service.d.ts.map +1 -0
- package/types/site/index.d.ts +10 -0
- package/types/site/index.d.ts.map +1 -0
- package/types/site/models.d.ts +23 -0
- package/types/site/models.d.ts.map +1 -0
- package/types/site/redirects-service.d.ts +91 -0
- package/types/site/redirects-service.d.ts.map +1 -0
- package/types/site/robots-service.d.ts +57 -0
- package/types/site/robots-service.d.ts.map +1 -0
- package/types/site/site-resolver.d.ts +28 -0
- package/types/site/site-resolver.d.ts.map +1 -0
- package/types/site/siteinfo-service.d.ts +64 -0
- package/types/site/siteinfo-service.d.ts.map +1 -0
- package/types/site/sitemap-xml-service.d.ts +63 -0
- package/types/site/sitemap-xml-service.d.ts.map +1 -0
- package/types/site/sitepath-service.d.ts +137 -0
- package/types/site/sitepath-service.d.ts.map +1 -0
- package/types/site/utils.d.ts +41 -0
- package/types/site/utils.d.ts.map +1 -0
- package/types/sitecore-service-base.d.ts +31 -0
- package/types/sitecore-service-base.d.ts.map +1 -0
- package/types/tools/codegen/component-generation.d.ts +50 -0
- package/types/tools/codegen/component-generation.d.ts.map +1 -0
- package/types/tools/codegen/extract-files.d.ts +24 -0
- package/types/tools/codegen/extract-files.d.ts.map +1 -0
- package/types/tools/codegen/import-map.d.ts +103 -0
- package/types/tools/codegen/import-map.d.ts.map +1 -0
- package/types/tools/codegen/utils.d.ts +76 -0
- package/types/tools/codegen/utils.d.ts.map +1 -0
- package/types/tools/generate-map.d.ts +36 -0
- package/types/tools/generate-map.d.ts.map +1 -0
- package/types/tools/generateSites.d.ts +25 -0
- package/types/tools/generateSites.d.ts.map +1 -0
- package/types/tools/index.d.ts +8 -0
- package/types/tools/index.d.ts.map +1 -0
- package/types/tools/scaffold.d.ts +27 -0
- package/types/tools/scaffold.d.ts.map +1 -0
- package/types/tools/templating/components.d.ts +104 -0
- package/types/tools/templating/components.d.ts.map +1 -0
- package/types/tools/templating/index.d.ts +2 -0
- package/types/tools/templating/index.d.ts.map +1 -0
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ComponentTemplateType = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Enumeration of default component templates
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
var ComponentTemplateType;
|
|
9
|
+
(function (ComponentTemplateType) {
|
|
10
|
+
ComponentTemplateType["BYOC"] = "byoc";
|
|
11
|
+
ComponentTemplateType["DEFAULT"] = "default";
|
|
12
|
+
})(ComponentTemplateType || (exports.ComponentTemplateType = ComponentTemplateType = {}));
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.defineCliConfig = void 0;
|
|
4
|
+
const validateConfig = (cliConfig) => {
|
|
5
|
+
var _a, _b, _c, _d;
|
|
6
|
+
if (!((_b = (_a = cliConfig.build) === null || _a === void 0 ? void 0 : _a.commands) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
7
|
+
throw new Error('Configuration error: build commands should be defined in sitecore.cli.config');
|
|
8
|
+
}
|
|
9
|
+
if (!((_d = (_c = cliConfig.scaffold) === null || _c === void 0 ? void 0 : _c.templates) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
10
|
+
throw new Error('Configuration error: scaffold templates should be defined in sitecore.cli.config');
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Accepts a `SitecoreCliConfigInput` object and returns Sitecore Content SDK CLI configuration, updated with required default values
|
|
15
|
+
* @param {SitecoreCliConfigInput} cliConfig the cli configuration provided by the application
|
|
16
|
+
* @returns {SitecoreCliConfig} full sitecore cli configuration to use with cli
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
const defineCliConfig = (cliConfig) => {
|
|
20
|
+
validateConfig(cliConfig);
|
|
21
|
+
return cliConfig;
|
|
22
|
+
};
|
|
23
|
+
exports.defineCliConfig = defineCliConfig;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SITECORE_CLI_MODE_ENV_VAR = exports.defineCliConfig = void 0;
|
|
4
|
+
var define_cli_config_1 = require("./define-cli-config");
|
|
5
|
+
Object.defineProperty(exports, "defineCliConfig", { enumerable: true, get: function () { return define_cli_config_1.defineCliConfig; } });
|
|
6
|
+
var models_1 = require("./models");
|
|
7
|
+
Object.defineProperty(exports, "SITECORE_CLI_MODE_ENV_VAR", { enumerable: true, get: function () { return models_1.SITECORE_CLI_MODE_ENV_VAR; } });
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SITECORE_CLI_MODE_ENV_VAR = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Environment variable to indicate that the application is running in CLI mode
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
exports.SITECORE_CLI_MODE_ENV_VAR = 'SITECORE_CLI_MODE';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HIDDEN_RENDERING_NAME = exports.languageError = exports.siteNameError = void 0;
|
|
4
|
+
/** @private */
|
|
5
|
+
exports.siteNameError = 'The site name must be a non-empty string';
|
|
6
|
+
/** @private */
|
|
7
|
+
exports.languageError = 'The language must be a non-empty string';
|
|
8
|
+
/**
|
|
9
|
+
* Hidden rendering name
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
exports.HIDDEN_RENDERING_NAME = 'Hidden Rendering';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
4
|
+
/**
|
|
5
|
+
* Debug module for content package
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
const debug = {
|
|
9
|
+
form: (0, core_1.debugModule)(`${core_1.debugNamespace}:form`),
|
|
10
|
+
layout: (0, core_1.debugModule)(`${core_1.debugNamespace}:layout`),
|
|
11
|
+
dictionary: (0, core_1.debugModule)(`${core_1.debugNamespace}:dictionary`),
|
|
12
|
+
editing: (0, core_1.debugModule)(`${core_1.debugNamespace}:editing`),
|
|
13
|
+
sitemap: (0, core_1.debugModule)(`${core_1.debugNamespace}:sitemap`),
|
|
14
|
+
multisite: (0, core_1.debugModule)(`${core_1.debugNamespace}:multisite`),
|
|
15
|
+
robots: (0, core_1.debugModule)(`${core_1.debugNamespace}:robots`),
|
|
16
|
+
redirects: (0, core_1.debugModule)(`${core_1.debugNamespace}:redirects`),
|
|
17
|
+
personalize: (0, core_1.debugModule)(`${core_1.debugNamespace}:personalize`),
|
|
18
|
+
locale: (0, core_1.debugModule)(`${core_1.debugNamespace}:locale`),
|
|
19
|
+
errorpages: (0, core_1.debugModule)(`${core_1.debugNamespace}:errorpages`),
|
|
20
|
+
};
|
|
21
|
+
exports.default = debug;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DesignLibraryPreviewError = exports.sendErrorEvent = exports.createComponentInstance = exports.addStyleElement = exports.getImportMapInfo = exports.getDesignLibraryImportMapEvent = exports.getDesignLibraryComponentPropsEvent = exports.getDesignLibraryComponentPreviewErrorEvent = exports.addServerComponentPreviewHandler = exports.addComponentPreviewHandler = void 0;
|
|
4
|
+
var preview_1 = require("./preview");
|
|
5
|
+
Object.defineProperty(exports, "addComponentPreviewHandler", { enumerable: true, get: function () { return preview_1.addComponentPreviewHandler; } });
|
|
6
|
+
Object.defineProperty(exports, "addServerComponentPreviewHandler", { enumerable: true, get: function () { return preview_1.addServerComponentPreviewHandler; } });
|
|
7
|
+
Object.defineProperty(exports, "getDesignLibraryComponentPreviewErrorEvent", { enumerable: true, get: function () { return preview_1.getDesignLibraryComponentPreviewErrorEvent; } });
|
|
8
|
+
Object.defineProperty(exports, "getDesignLibraryComponentPropsEvent", { enumerable: true, get: function () { return preview_1.getDesignLibraryComponentPropsEvent; } });
|
|
9
|
+
Object.defineProperty(exports, "getDesignLibraryImportMapEvent", { enumerable: true, get: function () { return preview_1.getDesignLibraryImportMapEvent; } });
|
|
10
|
+
Object.defineProperty(exports, "getImportMapInfo", { enumerable: true, get: function () { return preview_1.getImportMapInfo; } });
|
|
11
|
+
Object.defineProperty(exports, "addStyleElement", { enumerable: true, get: function () { return preview_1.addStyleElement; } });
|
|
12
|
+
Object.defineProperty(exports, "createComponentInstance", { enumerable: true, get: function () { return preview_1.createComponentInstance; } });
|
|
13
|
+
Object.defineProperty(exports, "sendErrorEvent", { enumerable: true, get: function () { return preview_1.sendErrorEvent; } });
|
|
14
|
+
Object.defineProperty(exports, "DesignLibraryPreviewError", { enumerable: true, get: function () { return preview_1.DesignLibraryPreviewError; } });
|
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.sendErrorEvent = exports.createComponentInstance = exports.addServerComponentPreviewHandler = exports.addComponentPreviewHandler = exports.DesignLibraryPreviewError = void 0;
|
|
4
|
+
exports.buildComponentDependencies = buildComponentDependencies;
|
|
5
|
+
exports.addStyleElement = addStyleElement;
|
|
6
|
+
exports.getDesignLibraryComponentPreviewErrorEvent = getDesignLibraryComponentPreviewErrorEvent;
|
|
7
|
+
exports.getDesignLibraryComponentPropsEvent = getDesignLibraryComponentPropsEvent;
|
|
8
|
+
exports.getDesignLibraryImportMapEvent = getDesignLibraryImportMapEvent;
|
|
9
|
+
exports.getImportMapInfo = getImportMapInfo;
|
|
10
|
+
exports.isImportEntryInfoArray = isImportEntryInfoArray;
|
|
11
|
+
const design_library_1 = require("../design-library");
|
|
12
|
+
/**
|
|
13
|
+
* Event to send import map to design library
|
|
14
|
+
*/
|
|
15
|
+
const DESIGN_LIBRARY_IMPORT_MAP_EVENT_NAME = 'component:generation:import-map';
|
|
16
|
+
/**
|
|
17
|
+
* Event to send component props to design library
|
|
18
|
+
*/
|
|
19
|
+
const DESIGN_LIBRARY_COMPONENT_PROPS_EVENT_NAME = 'component:generation:component-props';
|
|
20
|
+
/**
|
|
21
|
+
* Event to receive component data from design library
|
|
22
|
+
*/
|
|
23
|
+
const DESIGN_LIBRARY_COMPONENT_PREVIEW_EVENT_NAME = 'component:generation:component-preview';
|
|
24
|
+
/**
|
|
25
|
+
* Event to send component error to design library
|
|
26
|
+
*/
|
|
27
|
+
const DESIGN_LIBRARY_COMPONENT_PREVIEW_ERROR_EVENT_NAME = 'component:generation:component-preview-error';
|
|
28
|
+
/**
|
|
29
|
+
* Enumeration of error types for the design library preview.
|
|
30
|
+
* @internal
|
|
31
|
+
*/
|
|
32
|
+
var DesignLibraryPreviewError;
|
|
33
|
+
(function (DesignLibraryPreviewError) {
|
|
34
|
+
/**
|
|
35
|
+
* Error occurred during component rendering.
|
|
36
|
+
*/
|
|
37
|
+
DesignLibraryPreviewError["Render"] = "render";
|
|
38
|
+
/**
|
|
39
|
+
* Error occurred during component and event handlers initialization.
|
|
40
|
+
*/
|
|
41
|
+
DesignLibraryPreviewError["RenderInit"] = "render-init";
|
|
42
|
+
})(DesignLibraryPreviewError || (exports.DesignLibraryPreviewError = DesignLibraryPreviewError = {}));
|
|
43
|
+
/**
|
|
44
|
+
* Builds the component dependencies from the component imports and the import map.
|
|
45
|
+
* @param {ComponentImport[]} componentImports - The component imports.
|
|
46
|
+
* @param {ImportEntry[]} importMap - The import map to be used for the component.
|
|
47
|
+
* @returns {Array<{ name: string; value: unknown }>} The component dependencies.
|
|
48
|
+
*/
|
|
49
|
+
function buildComponentDependencies(componentImports, importMap) {
|
|
50
|
+
const successful = [];
|
|
51
|
+
const missing = {
|
|
52
|
+
modules: [],
|
|
53
|
+
exports: [],
|
|
54
|
+
};
|
|
55
|
+
componentImports.forEach((componentImport) => {
|
|
56
|
+
const moduleEntry = importMap.find((entry) => entry.module === componentImport.module);
|
|
57
|
+
if (!moduleEntry) {
|
|
58
|
+
missing.modules.push({
|
|
59
|
+
module: componentImport.module,
|
|
60
|
+
alias: componentImport.alias,
|
|
61
|
+
});
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
const exportEntry = moduleEntry.exports.find((exp) => exp.name === componentImport.export);
|
|
65
|
+
if (!exportEntry) {
|
|
66
|
+
missing.exports.push({
|
|
67
|
+
alias: componentImport.alias,
|
|
68
|
+
export: componentImport.export,
|
|
69
|
+
module: componentImport.module,
|
|
70
|
+
});
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
73
|
+
return successful.push({
|
|
74
|
+
name: componentImport.alias,
|
|
75
|
+
value: exportEntry.value,
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
return {
|
|
79
|
+
successful,
|
|
80
|
+
missing,
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Adds the browser-side event handler for 'component:generation:component-preview' message used in Design Library
|
|
85
|
+
* The event should contain the component code, styles and imports.
|
|
86
|
+
* @param {ImportEntry[]} importMap - The import map to be used for the component.
|
|
87
|
+
* @param {Function} callback callback to be called after component is received
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
const addComponentPreviewHandler = (importMap, callback) => {
|
|
91
|
+
if (!window)
|
|
92
|
+
return;
|
|
93
|
+
const handler = (e) => {
|
|
94
|
+
const eventArgs = e.data;
|
|
95
|
+
try {
|
|
96
|
+
if (!(0, design_library_1.validateEvent)(e, DESIGN_LIBRARY_COMPONENT_PREVIEW_EVENT_NAME)) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
console.debug('Component Library: message received', eventArgs);
|
|
100
|
+
const Component = (0, exports.createComponentInstance)(importMap, eventArgs);
|
|
101
|
+
addStyleElement(eventArgs.message.styles.content);
|
|
102
|
+
callback(null, Component);
|
|
103
|
+
}
|
|
104
|
+
catch (error) {
|
|
105
|
+
(0, exports.sendErrorEvent)(eventArgs.message.uid, error, DesignLibraryPreviewError.RenderInit);
|
|
106
|
+
callback(error, null);
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
window.addEventListener('message', handler);
|
|
110
|
+
const unsubscribe = () => {
|
|
111
|
+
window.removeEventListener('message', handler);
|
|
112
|
+
};
|
|
113
|
+
return unsubscribe;
|
|
114
|
+
};
|
|
115
|
+
exports.addComponentPreviewHandler = addComponentPreviewHandler;
|
|
116
|
+
/**
|
|
117
|
+
* Adds the browser-side event handler for 'component:generation:component-preview' message used in Design Library for server components
|
|
118
|
+
* The event should contain the component code, styles and imports.
|
|
119
|
+
* @param {Function} callback callback to be called after component is received
|
|
120
|
+
* @internal
|
|
121
|
+
*/
|
|
122
|
+
const addServerComponentPreviewHandler = (callback) => {
|
|
123
|
+
const handler = (e) => {
|
|
124
|
+
if (!(0, design_library_1.validateEvent)(e, DESIGN_LIBRARY_COMPONENT_PREVIEW_EVENT_NAME)) {
|
|
125
|
+
return;
|
|
126
|
+
}
|
|
127
|
+
console.debug('Component Library: message received', e.data);
|
|
128
|
+
callback(e.data);
|
|
129
|
+
};
|
|
130
|
+
window.addEventListener('message', handler);
|
|
131
|
+
const unsubscribe = () => {
|
|
132
|
+
window.removeEventListener('message', handler);
|
|
133
|
+
};
|
|
134
|
+
return unsubscribe;
|
|
135
|
+
};
|
|
136
|
+
exports.addServerComponentPreviewHandler = addServerComponentPreviewHandler;
|
|
137
|
+
/**
|
|
138
|
+
* Adds <style> element in the document head with the provided CSS.
|
|
139
|
+
* If an existing style element with the id "content-sdk-style-preview" is found, it is removed
|
|
140
|
+
* to prevent duplicates
|
|
141
|
+
* @param {string} stylesContent - The raw CSS text to inject into the style element.
|
|
142
|
+
* @internal
|
|
143
|
+
*/
|
|
144
|
+
function addStyleElement(stylesContent) {
|
|
145
|
+
const styleId = 'content-sdk-style-preview';
|
|
146
|
+
const styleElement = document.getElementById(styleId);
|
|
147
|
+
// remove existing style element if it exists to avoid duplicates
|
|
148
|
+
if (styleElement) {
|
|
149
|
+
styleElement.remove();
|
|
150
|
+
}
|
|
151
|
+
// create new style element and attach it to DOM
|
|
152
|
+
const style = document.createElement('style');
|
|
153
|
+
style.setAttribute('id', styleId);
|
|
154
|
+
style.innerHTML = stylesContent;
|
|
155
|
+
document.head.appendChild(style);
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Dynamically creates a React component instance from provided importMap and from code, styles, and dependencies provided in the preview event.
|
|
159
|
+
* @param {ImportEntry[]} importMap - The import map containing module and export references that might be injected as dependencies in the provided code.
|
|
160
|
+
* @param {ComponentPreviewEventArgs} previewEventArgs - The event arguments containing the component code, styles, and import definitions.
|
|
161
|
+
* @returns The dynamically created React component instance.
|
|
162
|
+
* @throws If any required modules or exports are missing from the import map, an error is thrown describing the missing dependencies.
|
|
163
|
+
* @internal
|
|
164
|
+
*/
|
|
165
|
+
const createComponentInstance = (importMap, previewEventArgs) => {
|
|
166
|
+
const { message } = previewEventArgs;
|
|
167
|
+
const dependencies = buildComponentDependencies(message.imports, importMap);
|
|
168
|
+
if (dependencies.missing.modules.length > 0 || dependencies.missing.exports.length > 0) {
|
|
169
|
+
let errorMessage = '';
|
|
170
|
+
dependencies.missing.modules.forEach((mod) => {
|
|
171
|
+
errorMessage += `Missing module: '${mod.module}' with alias: '${mod.alias}'\n`;
|
|
172
|
+
});
|
|
173
|
+
dependencies.missing.exports.forEach((exp) => {
|
|
174
|
+
const alias = exp.export !== exp.alias ? ` with alias: '${exp.alias}'` : '';
|
|
175
|
+
errorMessage += `Missing export: '${exp.export}' from module: '${exp.module}'${alias}\n`;
|
|
176
|
+
});
|
|
177
|
+
throw errorMessage;
|
|
178
|
+
}
|
|
179
|
+
const importNames = dependencies.successful.map((entry) => entry.name);
|
|
180
|
+
const importInstances = dependencies.successful.map((entry) => entry.value);
|
|
181
|
+
const exports = { Component: null };
|
|
182
|
+
const componentFn = new Function('exports', message.styles.styleImport.name, ...importNames, message.code.content);
|
|
183
|
+
// Function will set exports.Component
|
|
184
|
+
componentFn(exports, message.styles.styleImport.content, ...importInstances);
|
|
185
|
+
return exports.Component;
|
|
186
|
+
};
|
|
187
|
+
exports.createComponentInstance = createComponentInstance;
|
|
188
|
+
/**
|
|
189
|
+
* Generates a DesignLibraryComponentPreviewErrorEvent with the given uid and error.
|
|
190
|
+
* @param {string} uid - The unique identifier for the event.
|
|
191
|
+
* @param {unknown} error - The error to be sent.
|
|
192
|
+
* @param {DesignLibraryPreviewError} type - The type of error.
|
|
193
|
+
* @returns An object representing the DesignLibraryComponentPreviewErrorEvent.
|
|
194
|
+
* @internal
|
|
195
|
+
*/
|
|
196
|
+
function getDesignLibraryComponentPreviewErrorEvent(uid, error, type) {
|
|
197
|
+
return {
|
|
198
|
+
name: DESIGN_LIBRARY_COMPONENT_PREVIEW_ERROR_EVENT_NAME,
|
|
199
|
+
message: { uid, error, type },
|
|
200
|
+
};
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Generates a DesignLibraryComponentPropsEvent with the given uid, fields and parameters.
|
|
204
|
+
* @param {string} uid - The unique identifier for the event.
|
|
205
|
+
* @param {ComponentFields} fields - The fields of the component.
|
|
206
|
+
* @param {ComponentParams} parameters - The parameters of the component.
|
|
207
|
+
* @returns An object representing the DesignLibraryComponentPropsEvent.
|
|
208
|
+
* @internal
|
|
209
|
+
*/
|
|
210
|
+
function getDesignLibraryComponentPropsEvent(uid, fields = {}, parameters = {}) {
|
|
211
|
+
return {
|
|
212
|
+
name: DESIGN_LIBRARY_COMPONENT_PROPS_EVENT_NAME,
|
|
213
|
+
message: {
|
|
214
|
+
uid,
|
|
215
|
+
fields,
|
|
216
|
+
parameters,
|
|
217
|
+
},
|
|
218
|
+
};
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Generates a DesignLibraryImportMapEvent with the given uid and importMap.
|
|
222
|
+
* @param {string} uid - The unique identifier for the event.
|
|
223
|
+
* @param {ImportEntry[]} importMap - The imports map to be sent.
|
|
224
|
+
* @returns An object representing the DesignLibraryImportMapEvent.
|
|
225
|
+
* @internal
|
|
226
|
+
*/
|
|
227
|
+
function getDesignLibraryImportMapEvent(uid, importMap) {
|
|
228
|
+
const importMapPayload = isImportEntryInfoArray(importMap)
|
|
229
|
+
? importMap
|
|
230
|
+
: getImportMapInfo(importMap);
|
|
231
|
+
return {
|
|
232
|
+
name: DESIGN_LIBRARY_IMPORT_MAP_EVENT_NAME,
|
|
233
|
+
message: {
|
|
234
|
+
uid,
|
|
235
|
+
importMap: importMapPayload,
|
|
236
|
+
},
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Generates the payload for the import map to be sent to design library.
|
|
241
|
+
* @param {ImportEntry[]} importMap - The imports map to be sent.
|
|
242
|
+
* @internal
|
|
243
|
+
*/
|
|
244
|
+
function getImportMapInfo(importMap) {
|
|
245
|
+
return importMap.map((entry) => ({
|
|
246
|
+
module: entry.module,
|
|
247
|
+
exports: entry.exports.map((exp) => exp.name),
|
|
248
|
+
}));
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Type guard for ImportEntryInfo[]
|
|
252
|
+
* @param {unknown} data import entry data to check
|
|
253
|
+
* @returns true if the data is ImportEntryInfo array
|
|
254
|
+
*/
|
|
255
|
+
function isImportEntryInfoArray(data) {
|
|
256
|
+
return (Array.isArray(data) &&
|
|
257
|
+
data.length > 0 &&
|
|
258
|
+
typeof data[0].module === 'string' &&
|
|
259
|
+
Array.isArray(data[0].exports) &&
|
|
260
|
+
typeof data[0].exports[0] === 'string');
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Sends a component preview error event to the design library
|
|
264
|
+
* @param {string} uid - The unique identifier of the component that's being edited.
|
|
265
|
+
* @param {unknown} error - The error object or message to be sent.
|
|
266
|
+
* @param {DesignLibraryPreviewError} type - The type of error, as defined in DesignLibraryPreviewError.
|
|
267
|
+
* @internal
|
|
268
|
+
*/
|
|
269
|
+
const sendErrorEvent = (uid, error, type) => {
|
|
270
|
+
const errorEvent = getDesignLibraryComponentPreviewErrorEvent(uid, error, type);
|
|
271
|
+
console.error('Component Library: sending error event', errorEvent);
|
|
272
|
+
if (typeof window !== 'undefined') {
|
|
273
|
+
const target = window.parent && window.parent !== window ? window.parent : window;
|
|
274
|
+
target.postMessage(errorEvent, '*');
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
exports.sendErrorEvent = sendErrorEvent;
|
|
@@ -0,0 +1,62 @@
|
|
|
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.ComponentLayoutService = void 0;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
+
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
9
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
10
|
+
const models_1 = require("./models");
|
|
11
|
+
const { SITECORE_EDGE_URL_DEFAULT } = core_1.constants;
|
|
12
|
+
/**
|
|
13
|
+
* REST service that enables Design Library functionality.
|
|
14
|
+
* Returns layout data for a single rendered component.
|
|
15
|
+
* @public
|
|
16
|
+
*/
|
|
17
|
+
class ComponentLayoutService {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.config = config;
|
|
20
|
+
}
|
|
21
|
+
fetchComponentData(params, fetchOptions) {
|
|
22
|
+
// Choose the correct Edge ID per environment
|
|
23
|
+
const sitecoreContextId = this.config.contextId || this.config.clientContextId;
|
|
24
|
+
if (!sitecoreContextId) {
|
|
25
|
+
throw new Error(`ComponentLayoutService misconfigured: contextId is missing.
|
|
26
|
+
Provide contextId on the server, and clientContextId in the browser if you need to full client-side functionality.`);
|
|
27
|
+
}
|
|
28
|
+
const fetcher = new core_1.NativeDataFetcher({ debugger: debug_1.default.layout });
|
|
29
|
+
debug_1.default.layout('fetching component with uid %s for %s %s %s %s', params.componentUid, params.itemId, params.language, params.siteName, params.dataSourceId);
|
|
30
|
+
return fetcher
|
|
31
|
+
.get(this.getFetchUrl(params), Object.assign(Object.assign({}, fetchOptions), { headers: Object.assign(Object.assign({}, fetchOptions === null || fetchOptions === void 0 ? void 0 : fetchOptions.headers), { 'x-sitecore-contextid': sitecoreContextId, sc_editMode: `${params.mode === models_1.DesignLibraryMode.Metadata}` }) }))
|
|
32
|
+
.then((response) => response.data)
|
|
33
|
+
.catch((error) => {
|
|
34
|
+
var _a;
|
|
35
|
+
if (((_a = error.response) === null || _a === void 0 ? void 0 : _a.status) === 404) {
|
|
36
|
+
return error.response.data;
|
|
37
|
+
}
|
|
38
|
+
throw error;
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
getComponentFetchParams(params) {
|
|
42
|
+
// strip undefined fields
|
|
43
|
+
return JSON.parse(JSON.stringify({
|
|
44
|
+
item: params.itemId,
|
|
45
|
+
uid: params.componentUid,
|
|
46
|
+
dataSourceId: params.dataSourceId,
|
|
47
|
+
renderingItemId: params.renderingId,
|
|
48
|
+
version: params.version,
|
|
49
|
+
sc_site: params.siteName,
|
|
50
|
+
sc_lang: params.language || 'en',
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Get the fetch URL for the partial layout data endpoint
|
|
55
|
+
* @param {ComponentLayoutRequestParams} params - The parameters for the request
|
|
56
|
+
* @returns {string} The fetch URL for the component data
|
|
57
|
+
*/
|
|
58
|
+
getFetchUrl(params) {
|
|
59
|
+
return (0, tools_1.resolveUrl)(`${this.config.edgeUrl || SITECORE_EDGE_URL_DEFAULT}/layout/component`, this.getComponentFetchParams(params));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
exports.ComponentLayoutService = ComponentLayoutService;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.postToDesignLibrary = exports.updateComponent = exports.updateComponentHandler = exports.validateEvent = exports.validateOrigin = exports.addComponentUpdateHandler = exports.DesignLibraryStatus = exports.COMPONENT_UPDATE_CACHE_KEY_PREFIX = void 0;
|
|
4
|
+
exports.getDesignLibraryStatusEvent = getDesignLibraryStatusEvent;
|
|
5
|
+
exports.getDesignLibraryScriptLink = getDesignLibraryScriptLink;
|
|
6
|
+
exports.isDesignLibraryMode = isDesignLibraryMode;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
+
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
9
|
+
const models_1 = require("./models");
|
|
10
|
+
const { SITECORE_EDGE_URL_DEFAULT } = core_1.constants;
|
|
11
|
+
/**
|
|
12
|
+
* Event to be sent when report status to design library
|
|
13
|
+
*/
|
|
14
|
+
const DESIGN_LIBRARY_STATUS_EVENT_NAME = 'component:status';
|
|
15
|
+
/**
|
|
16
|
+
* Prefix for component update cache keys
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
exports.COMPONENT_UPDATE_CACHE_KEY_PREFIX = 'component-update-';
|
|
20
|
+
/**
|
|
21
|
+
* Enumeration of statuses for the design library.
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
var DesignLibraryStatus;
|
|
25
|
+
(function (DesignLibraryStatus) {
|
|
26
|
+
DesignLibraryStatus["READY"] = "ready";
|
|
27
|
+
DesignLibraryStatus["RENDERED"] = "rendered";
|
|
28
|
+
})(DesignLibraryStatus || (exports.DesignLibraryStatus = DesignLibraryStatus = {}));
|
|
29
|
+
/**
|
|
30
|
+
* Adds the browser-side event handler for 'component:update' message used in Design Library
|
|
31
|
+
* The event should update a component on page by uid, with fields and params from event args
|
|
32
|
+
* @param {ComponentRendering} rootComponent root component displayed for Design Library page
|
|
33
|
+
* @param {Function} successCallback callback to be called after successful component update
|
|
34
|
+
* @internal
|
|
35
|
+
*/
|
|
36
|
+
const addComponentUpdateHandler = (rootComponent, successCallback) => {
|
|
37
|
+
if (!window)
|
|
38
|
+
return;
|
|
39
|
+
const handler = (e) => (0, exports.updateComponentHandler)(e, rootComponent, successCallback);
|
|
40
|
+
window.addEventListener('message', handler);
|
|
41
|
+
// the power to remove handler outside of this function, if needed
|
|
42
|
+
const unsubscribe = () => {
|
|
43
|
+
window.removeEventListener('message', handler);
|
|
44
|
+
};
|
|
45
|
+
return unsubscribe;
|
|
46
|
+
};
|
|
47
|
+
exports.addComponentUpdateHandler = addComponentUpdateHandler;
|
|
48
|
+
const validateOrigin = (event) => {
|
|
49
|
+
// TODO: use `EDITING_ALLOWED_ORIGINS.concat(getAllowedOriginsFromEnv())` later
|
|
50
|
+
// nextjs's JSS_ALLOWED_ORIGINS is not available on the client, need to use NEXT_PUBLIC_ variable, but it's a breaking change for Deploy
|
|
51
|
+
const allowedOrigins = ['*'];
|
|
52
|
+
return allowedOrigins.some((origin) => origin === event.origin ||
|
|
53
|
+
new RegExp('^' + origin.replace('.', '\\.').replace(/\*/g, '.*') + '$').test(event.origin));
|
|
54
|
+
};
|
|
55
|
+
exports.validateOrigin = validateOrigin;
|
|
56
|
+
/**
|
|
57
|
+
* Validates that a MessageEvent has the expected event name and required data.
|
|
58
|
+
* Logs debug information when validation fails due to invalid origin.
|
|
59
|
+
* @param {MessageEvent} e - The message event to validate.
|
|
60
|
+
* @param {string} eventName - The expected event name to match against e.data.name.
|
|
61
|
+
* @returns {boolean} True if the event has a valid origin, data object, and matching event name; otherwise false.
|
|
62
|
+
*/
|
|
63
|
+
const validateEvent = (e, eventName) => {
|
|
64
|
+
if (!e.origin || !e.data || e.data.name !== eventName) {
|
|
65
|
+
// avoid extra noise in logs
|
|
66
|
+
if (!(0, exports.validateOrigin)(e)) {
|
|
67
|
+
console.debug('Component Library: event skipped - invalid origin: message %s from origin %s', e.data.name, e.origin);
|
|
68
|
+
}
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
};
|
|
73
|
+
exports.validateEvent = validateEvent;
|
|
74
|
+
const updateComponentHandler = (e, rootComponent, successCallback) => {
|
|
75
|
+
var _a;
|
|
76
|
+
const eventArgs = e.data;
|
|
77
|
+
if (!e.origin || !eventArgs || eventArgs.name !== 'component:update') {
|
|
78
|
+
// avoid extra noise in logs
|
|
79
|
+
if (!(0, exports.validateOrigin)(e)) {
|
|
80
|
+
console.debug('Component Library: event skipped: message %s from origin %s', eventArgs.name, e.origin);
|
|
81
|
+
}
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (!((_a = eventArgs.details) === null || _a === void 0 ? void 0 : _a.uid)) {
|
|
85
|
+
console.debug('Received component:update event without uid, aborting event handler...');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const findComponent = (root) => {
|
|
89
|
+
var _a, _b;
|
|
90
|
+
if (((_a = root.uid) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === ((_b = eventArgs.details) === null || _b === void 0 ? void 0 : _b.uid.toLowerCase()))
|
|
91
|
+
return root;
|
|
92
|
+
if (root.placeholders) {
|
|
93
|
+
for (const plhName of Object.keys(root.placeholders)) {
|
|
94
|
+
for (const rendering of root.placeholders[plhName]) {
|
|
95
|
+
const result = findComponent(rendering);
|
|
96
|
+
if (result)
|
|
97
|
+
return result;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
};
|
|
103
|
+
const componentToUpdate = findComponent(rootComponent);
|
|
104
|
+
if (componentToUpdate) {
|
|
105
|
+
console.debug('Found component with uid %s to update. Update fields: %o. Update params: %o.', eventArgs.details.uid, eventArgs.details.fields, eventArgs.details.params);
|
|
106
|
+
(0, exports.updateComponent)(componentToUpdate, eventArgs.details.fields, eventArgs.details.params);
|
|
107
|
+
if (successCallback)
|
|
108
|
+
successCallback(rootComponent);
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
console.debug('Rendering with uid %s not found', eventArgs.details.uid);
|
|
112
|
+
}
|
|
113
|
+
// strictly for testing
|
|
114
|
+
return rootComponent;
|
|
115
|
+
};
|
|
116
|
+
exports.updateComponentHandler = updateComponentHandler;
|
|
117
|
+
/**
|
|
118
|
+
* Updates a component's fields and params with the provided values.
|
|
119
|
+
* @param {ComponentRendering<ComponentFields>} component - The component to update.
|
|
120
|
+
* @param {ComponentFields | undefined} fields - The fields to merge into the component.
|
|
121
|
+
* @param {ComponentParams | undefined} params - The params to merge into the component.
|
|
122
|
+
* @internal
|
|
123
|
+
*/
|
|
124
|
+
const updateComponent = (component, fields, params) => {
|
|
125
|
+
if (fields) {
|
|
126
|
+
component.fields = Object.assign(Object.assign({}, component.fields), fields);
|
|
127
|
+
}
|
|
128
|
+
if (params) {
|
|
129
|
+
component.params = Object.assign(Object.assign({}, component.params), params);
|
|
130
|
+
}
|
|
131
|
+
};
|
|
132
|
+
exports.updateComponent = updateComponent;
|
|
133
|
+
/**
|
|
134
|
+
* Generates a DesignLibraryStatusEvent with the given status and uid.
|
|
135
|
+
* @param {DesignLibraryStatus} status - The status of rendering.
|
|
136
|
+
* @param {string} uid - The unique identifier for the event.
|
|
137
|
+
* @returns An object representing the DesignLibraryStatusEvent.
|
|
138
|
+
* @internal
|
|
139
|
+
*/
|
|
140
|
+
function getDesignLibraryStatusEvent(status, uid) {
|
|
141
|
+
return {
|
|
142
|
+
name: DESIGN_LIBRARY_STATUS_EVENT_NAME,
|
|
143
|
+
message: {
|
|
144
|
+
status,
|
|
145
|
+
uid,
|
|
146
|
+
},
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Generates the URL for the design library script link.
|
|
151
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
152
|
+
* @returns The full URL to the design library script.
|
|
153
|
+
* @internal
|
|
154
|
+
*/
|
|
155
|
+
function getDesignLibraryScriptLink(sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) {
|
|
156
|
+
return `${(0, tools_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/files/designlibrary/lib/rh-lib-script.js`;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Checks if the given mode is a Design Library mode.
|
|
160
|
+
* @param {unknown} mode - The mode to check.
|
|
161
|
+
* @returns {boolean} True if the mode is a Design Library mode, false otherwise.
|
|
162
|
+
* @internal
|
|
163
|
+
*/
|
|
164
|
+
function isDesignLibraryMode(mode) {
|
|
165
|
+
return mode === models_1.DesignLibraryMode.Normal || mode === models_1.DesignLibraryMode.Metadata;
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Sends an event to the Design Library
|
|
169
|
+
* @param {DesignLibraryEvent} evt - The event object to send.
|
|
170
|
+
* @internal
|
|
171
|
+
*/
|
|
172
|
+
const postToDesignLibrary = (evt) => {
|
|
173
|
+
if (typeof window === 'undefined')
|
|
174
|
+
return;
|
|
175
|
+
const target = window.parent && window.parent !== window ? window.parent : window;
|
|
176
|
+
try {
|
|
177
|
+
console.log('Component Library: sending event', evt.name, evt);
|
|
178
|
+
target.postMessage(evt, '*');
|
|
179
|
+
}
|
|
180
|
+
catch (err) {
|
|
181
|
+
console.error('Component Library: postMessage failed', err, evt);
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
exports.postToDesignLibrary = postToDesignLibrary;
|