@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,81 @@
|
|
|
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.EditingService = exports.query = void 0;
|
|
7
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
8
|
+
const models_1 = require("./models");
|
|
9
|
+
/**
|
|
10
|
+
* GraphQL query for fetching editing data.
|
|
11
|
+
*/
|
|
12
|
+
exports.query = `
|
|
13
|
+
query EditingQuery($itemId: String!, $language: String!, $version: String) {
|
|
14
|
+
item(path: $itemId, language: $language, version: $version) {
|
|
15
|
+
rendered
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`;
|
|
19
|
+
/**
|
|
20
|
+
* Service for fetching editing data from Sitecore using the Sitecore's GraphQL API.
|
|
21
|
+
* Expected to be used in XMCloud Pages preview (editing) Metadata Edit Mode.
|
|
22
|
+
* @public
|
|
23
|
+
*/
|
|
24
|
+
class EditingService {
|
|
25
|
+
/**
|
|
26
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
27
|
+
* @param {EditingServiceConfig} serviceConfig configuration
|
|
28
|
+
*/
|
|
29
|
+
constructor(serviceConfig) {
|
|
30
|
+
this.serviceConfig = serviceConfig;
|
|
31
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Fetches editing data. Provides the layout data and dictionary phrases
|
|
35
|
+
* @param {object} variables - The parameters for fetching editing data.
|
|
36
|
+
* @param {string} variables.itemId - The item id (path) to fetch layout data for.
|
|
37
|
+
* @param {string} variables.language - The language to fetch layout data for.
|
|
38
|
+
* @param {string} variables.mode - The editing mode to fetch layout data for.
|
|
39
|
+
* @param {string} [variables.version] - The version of the item (optional).
|
|
40
|
+
* @param {LayoutKind} [variables.layoutKind] - The final or shared layout variant.
|
|
41
|
+
* @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
|
|
42
|
+
* @returns {Promise} The layout data and dictionary phrases.
|
|
43
|
+
*/
|
|
44
|
+
async fetchEditingData({ itemId, language, version, layoutKind = models_1.LayoutKind.Final, mode }, fetchOptions) {
|
|
45
|
+
var _a;
|
|
46
|
+
debug_1.default.editing('fetching editing data for %s %s %s %s', itemId, language, version, layoutKind);
|
|
47
|
+
if (!language) {
|
|
48
|
+
throw new RangeError('The language must be a non-empty string');
|
|
49
|
+
}
|
|
50
|
+
const editModeHeader = mode === 'edit' ? 'true' : 'false';
|
|
51
|
+
const editingData = await this.graphQLClient.request(exports.query, {
|
|
52
|
+
itemId,
|
|
53
|
+
version,
|
|
54
|
+
language,
|
|
55
|
+
}, Object.assign(Object.assign({}, fetchOptions), { headers: {
|
|
56
|
+
sc_layoutKind: layoutKind,
|
|
57
|
+
sc_editMode: editModeHeader,
|
|
58
|
+
} }));
|
|
59
|
+
return {
|
|
60
|
+
layoutData: ((_a = editingData === null || editingData === void 0 ? void 0 : editingData.item) === null || _a === void 0 ? void 0 : _a.rendered) || {
|
|
61
|
+
sitecore: {
|
|
62
|
+
context: { pageEditing: true, language },
|
|
63
|
+
route: null,
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
70
|
+
* @returns {GraphQLClient} implementation
|
|
71
|
+
*/
|
|
72
|
+
getGraphQLClient() {
|
|
73
|
+
if (!this.serviceConfig.clientFactory) {
|
|
74
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
75
|
+
}
|
|
76
|
+
return this.serviceConfig.clientFactory({
|
|
77
|
+
debugger: debug_1.default.editing,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
exports.EditingService = EditingService;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.updateComponent = exports.COMPONENT_UPDATE_CACHE_KEY_PREFIX = exports.postToDesignLibrary = exports.isDesignLibraryMode = exports.getDesignLibraryScriptLink = exports.getDesignLibraryStatusEvent = exports.DesignLibraryStatus = exports.addComponentUpdateHandler = exports.DesignLibraryMode = exports.MetadataKind = exports.LayoutKind = exports.DesignLibraryVariantGeneration = exports.ComponentLayoutService = exports.PREVIEW_KEY = exports.PAGES_EDITING_MARKER = exports.INVALID_SECRET_HTML_MESSAGE = exports.QUERY_PARAM_EDITING_SECRET = exports.EDITING_ALLOWED_ORIGINS = exports.getContentSdkPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.DEFAULT_PLACEHOLDER_UID = exports.EditingService = void 0;
|
|
4
|
+
var editing_service_1 = require("./editing-service");
|
|
5
|
+
Object.defineProperty(exports, "EditingService", { enumerable: true, get: function () { return editing_service_1.EditingService; } });
|
|
6
|
+
var utils_1 = require("./utils");
|
|
7
|
+
Object.defineProperty(exports, "DEFAULT_PLACEHOLDER_UID", { enumerable: true, get: function () { return utils_1.DEFAULT_PLACEHOLDER_UID; } });
|
|
8
|
+
Object.defineProperty(exports, "PagesEditor", { enumerable: true, get: function () { return utils_1.PagesEditor; } });
|
|
9
|
+
Object.defineProperty(exports, "isEditorActive", { enumerable: true, get: function () { return utils_1.isEditorActive; } });
|
|
10
|
+
Object.defineProperty(exports, "resetEditorChromes", { enumerable: true, get: function () { return utils_1.resetEditorChromes; } });
|
|
11
|
+
Object.defineProperty(exports, "getContentSdkPagesClientData", { enumerable: true, get: function () { return utils_1.getContentSdkPagesClientData; } });
|
|
12
|
+
Object.defineProperty(exports, "EDITING_ALLOWED_ORIGINS", { enumerable: true, get: function () { return utils_1.EDITING_ALLOWED_ORIGINS; } });
|
|
13
|
+
Object.defineProperty(exports, "QUERY_PARAM_EDITING_SECRET", { enumerable: true, get: function () { return utils_1.QUERY_PARAM_EDITING_SECRET; } });
|
|
14
|
+
Object.defineProperty(exports, "INVALID_SECRET_HTML_MESSAGE", { enumerable: true, get: function () { return utils_1.INVALID_SECRET_HTML_MESSAGE; } });
|
|
15
|
+
Object.defineProperty(exports, "PAGES_EDITING_MARKER", { enumerable: true, get: function () { return utils_1.PAGES_EDITING_MARKER; } });
|
|
16
|
+
Object.defineProperty(exports, "PREVIEW_KEY", { enumerable: true, get: function () { return utils_1.PREVIEW_KEY; } });
|
|
17
|
+
var component_layout_service_1 = require("./component-layout-service");
|
|
18
|
+
Object.defineProperty(exports, "ComponentLayoutService", { enumerable: true, get: function () { return component_layout_service_1.ComponentLayoutService; } });
|
|
19
|
+
var models_1 = require("./models");
|
|
20
|
+
Object.defineProperty(exports, "DesignLibraryVariantGeneration", { enumerable: true, get: function () { return models_1.DesignLibraryVariantGeneration; } });
|
|
21
|
+
var models_2 = require("./models");
|
|
22
|
+
Object.defineProperty(exports, "LayoutKind", { enumerable: true, get: function () { return models_2.LayoutKind; } });
|
|
23
|
+
Object.defineProperty(exports, "MetadataKind", { enumerable: true, get: function () { return models_2.MetadataKind; } });
|
|
24
|
+
Object.defineProperty(exports, "DesignLibraryMode", { enumerable: true, get: function () { return models_2.DesignLibraryMode; } });
|
|
25
|
+
var design_library_1 = require("./design-library");
|
|
26
|
+
Object.defineProperty(exports, "addComponentUpdateHandler", { enumerable: true, get: function () { return design_library_1.addComponentUpdateHandler; } });
|
|
27
|
+
Object.defineProperty(exports, "DesignLibraryStatus", { enumerable: true, get: function () { return design_library_1.DesignLibraryStatus; } });
|
|
28
|
+
Object.defineProperty(exports, "getDesignLibraryStatusEvent", { enumerable: true, get: function () { return design_library_1.getDesignLibraryStatusEvent; } });
|
|
29
|
+
Object.defineProperty(exports, "getDesignLibraryScriptLink", { enumerable: true, get: function () { return design_library_1.getDesignLibraryScriptLink; } });
|
|
30
|
+
Object.defineProperty(exports, "isDesignLibraryMode", { enumerable: true, get: function () { return design_library_1.isDesignLibraryMode; } });
|
|
31
|
+
Object.defineProperty(exports, "postToDesignLibrary", { enumerable: true, get: function () { return design_library_1.postToDesignLibrary; } });
|
|
32
|
+
Object.defineProperty(exports, "COMPONENT_UPDATE_CACHE_KEY_PREFIX", { enumerable: true, get: function () { return design_library_1.COMPONENT_UPDATE_CACHE_KEY_PREFIX; } });
|
|
33
|
+
Object.defineProperty(exports, "updateComponent", { enumerable: true, get: function () { return design_library_1.updateComponent; } });
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DesignLibraryVariantGeneration = exports.DesignLibraryMode = exports.MetadataKind = exports.LayoutKind = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Represents the Editing Layout variant.
|
|
6
|
+
* - shared - shared layout
|
|
7
|
+
* - final - final layout
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
var LayoutKind;
|
|
11
|
+
(function (LayoutKind) {
|
|
12
|
+
LayoutKind["Final"] = "final";
|
|
13
|
+
LayoutKind["Shared"] = "shared";
|
|
14
|
+
})(LayoutKind || (exports.LayoutKind = LayoutKind = {}));
|
|
15
|
+
/**
|
|
16
|
+
* Represents the kind of metadata element.
|
|
17
|
+
* - open - starting chrome element
|
|
18
|
+
* - close - closing chrome element
|
|
19
|
+
* @internal
|
|
20
|
+
*/
|
|
21
|
+
var MetadataKind;
|
|
22
|
+
(function (MetadataKind) {
|
|
23
|
+
MetadataKind["Open"] = "open";
|
|
24
|
+
MetadataKind["Close"] = "close";
|
|
25
|
+
})(MetadataKind || (exports.MetadataKind = MetadataKind = {}));
|
|
26
|
+
/**
|
|
27
|
+
* Represents the mode of the Design Library
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
var DesignLibraryMode;
|
|
31
|
+
(function (DesignLibraryMode) {
|
|
32
|
+
/** Normal mode */
|
|
33
|
+
DesignLibraryMode["Normal"] = "library";
|
|
34
|
+
/** Metadata mode */
|
|
35
|
+
DesignLibraryMode["Metadata"] = "library-metadata";
|
|
36
|
+
})(DesignLibraryMode || (exports.DesignLibraryMode = DesignLibraryMode = {}));
|
|
37
|
+
/**
|
|
38
|
+
* Variant generation mode for Design Library
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
41
|
+
var DesignLibraryVariantGeneration;
|
|
42
|
+
(function (DesignLibraryVariantGeneration) {
|
|
43
|
+
DesignLibraryVariantGeneration["Variant"] = "variant";
|
|
44
|
+
})(DesignLibraryVariantGeneration || (exports.DesignLibraryVariantGeneration = DesignLibraryVariantGeneration = {}));
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getContentSdkPagesClientData = exports.resetEditorChromes = exports.isEditorActive = exports.PagesEditor = exports.ChromeRediscoveryGlobalFunctionName = exports.EDITING_ALLOWED_ORIGINS = exports.PAGES_EDITING_MARKER = exports.PREVIEW_KEY = exports.INVALID_SECRET_HTML_MESSAGE = exports.QUERY_PARAM_EDITING_SECRET = exports.DEFAULT_PLACEHOLDER_UID = void 0;
|
|
4
|
+
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
5
|
+
/**
|
|
6
|
+
* Default value of uid for root placeholder when uid is not present.
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
exports.DEFAULT_PLACEHOLDER_UID = '00000000-0000-0000-0000-000000000000';
|
|
10
|
+
/**
|
|
11
|
+
* Query parameter for editing secret
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
exports.QUERY_PARAM_EDITING_SECRET = 'secret';
|
|
15
|
+
/**
|
|
16
|
+
* HTML returned for invalid or missing secret
|
|
17
|
+
* @internal
|
|
18
|
+
*/
|
|
19
|
+
exports.INVALID_SECRET_HTML_MESSAGE = '<html><body>Missing or invalid secret</body></html>';
|
|
20
|
+
/**
|
|
21
|
+
* Key to identify whether the app is running in Sitecore Preview mode
|
|
22
|
+
* @internal
|
|
23
|
+
*/
|
|
24
|
+
exports.PREVIEW_KEY = 'sc_preview';
|
|
25
|
+
/**
|
|
26
|
+
* ID to be used as a marker for a script rendered in XMC Pages
|
|
27
|
+
* Should identify app is in XM Cloud Pages editing mode
|
|
28
|
+
* @internal
|
|
29
|
+
*/
|
|
30
|
+
exports.PAGES_EDITING_MARKER = 'jss-hrz-editing';
|
|
31
|
+
/**
|
|
32
|
+
* Default allowed origins for editing requests. This is used to enforce CORS, CSP headers.
|
|
33
|
+
* @internal
|
|
34
|
+
*/
|
|
35
|
+
exports.EDITING_ALLOWED_ORIGINS = [
|
|
36
|
+
'https://pages.sitecorecloud.io',
|
|
37
|
+
'https://xmapps.sitecorecloud.io',
|
|
38
|
+
'https://designlibrary.sitecorecloud.io',
|
|
39
|
+
];
|
|
40
|
+
/**
|
|
41
|
+
* Copy of chrome rediscovery contract from Horizon (chrome-rediscovery.contract.ts)
|
|
42
|
+
*/
|
|
43
|
+
exports.ChromeRediscoveryGlobalFunctionName = {
|
|
44
|
+
name: 'Sitecore.Horizon.ResetChromes',
|
|
45
|
+
};
|
|
46
|
+
/**
|
|
47
|
+
* Static utility class for Sitecore Pages Editor
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
class PagesEditor {
|
|
51
|
+
/**
|
|
52
|
+
* Determines whether the current execution context is within a Pages Editor.
|
|
53
|
+
* Pages Editor environment can be identified only in the browser
|
|
54
|
+
* @returns true if executing within a Pages Editor
|
|
55
|
+
*/
|
|
56
|
+
static isActive() {
|
|
57
|
+
if ((0, tools_1.isServer)()) {
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
// Check for Chromes mode
|
|
61
|
+
const chromesCheck = window.location.search.indexOf('sc_headless_mode=edit') > -1;
|
|
62
|
+
// Content SDK will render a content-sdk-exclusive script element in Metadata mode to indicate edit mode in Pages
|
|
63
|
+
return chromesCheck || !!window.document.getElementById(exports.PAGES_EDITING_MARKER);
|
|
64
|
+
}
|
|
65
|
+
static resetChromes() {
|
|
66
|
+
if ((0, tools_1.isServer)()) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
// Reset chromes in Pages
|
|
70
|
+
window[exports.ChromeRediscoveryGlobalFunctionName.name] &&
|
|
71
|
+
window[exports.ChromeRediscoveryGlobalFunctionName.name]();
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.PagesEditor = PagesEditor;
|
|
75
|
+
/**
|
|
76
|
+
* Determines whether the current execution context is within a Sitecore editor.
|
|
77
|
+
* Sitecore Editor environment can be identified only in the browser
|
|
78
|
+
* @returns true if executing within a Sitecore editor
|
|
79
|
+
* @public
|
|
80
|
+
*/
|
|
81
|
+
const isEditorActive = () => {
|
|
82
|
+
return PagesEditor.isActive();
|
|
83
|
+
};
|
|
84
|
+
exports.isEditorActive = isEditorActive;
|
|
85
|
+
/**
|
|
86
|
+
* Resets Sitecore editor "chromes"
|
|
87
|
+
* @public
|
|
88
|
+
*/
|
|
89
|
+
const resetEditorChromes = () => {
|
|
90
|
+
if (PagesEditor.isActive()) {
|
|
91
|
+
PagesEditor.resetChromes();
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
exports.resetEditorChromes = resetEditorChromes;
|
|
95
|
+
/**
|
|
96
|
+
* Gets extra Content SDK clientData scripts to render in XMC Pages in addition to clientData from Pages itself
|
|
97
|
+
* @returns {Record} collection of clientData
|
|
98
|
+
* @internal
|
|
99
|
+
*/
|
|
100
|
+
const getContentSdkPagesClientData = () => {
|
|
101
|
+
const clientData = {};
|
|
102
|
+
clientData[exports.PAGES_EDITING_MARKER] = {};
|
|
103
|
+
return clientData;
|
|
104
|
+
};
|
|
105
|
+
exports.getContentSdkPagesClientData = getContentSdkPagesClientData;
|
|
@@ -0,0 +1,81 @@
|
|
|
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
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
const loadForm = async (contextId, formId, edgeUrl) => {
|
|
18
|
+
if (!contextId) {
|
|
19
|
+
debug_1.default.form('Form was not able to render since context id was not provided');
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
const url = (0, client_1.getEdgeProxyFormsUrl)(contextId, formId, edgeUrl);
|
|
23
|
+
try {
|
|
24
|
+
debug_1.default.form(`Fetching form data from ${url}`);
|
|
25
|
+
const rsp = await fetch(url, {
|
|
26
|
+
method: 'GET',
|
|
27
|
+
cache: 'no-cache',
|
|
28
|
+
});
|
|
29
|
+
if (rsp.status !== 200) {
|
|
30
|
+
throw new Error('Failed to fetch form data');
|
|
31
|
+
}
|
|
32
|
+
const content = await rsp.text();
|
|
33
|
+
debug_1.default.form(`Form data fetch response: ${content}`);
|
|
34
|
+
return content;
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
debug_1.default.form(`Form '${formId}' was not able to render`, error);
|
|
38
|
+
throw error;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
exports.loadForm = loadForm;
|
|
42
|
+
/**
|
|
43
|
+
* When you set the innerHTML property of an element, the browser does not execute any <script> tags included in the HTML string
|
|
44
|
+
* This method ensures that any <script> elements within the loaded HTML are executed.
|
|
45
|
+
* It re-creates the script elements and appends the to the component's template, then removes old script elements to avoid duplication.
|
|
46
|
+
* @param {HTMLElement} rootElement - The root element to execute script elements within
|
|
47
|
+
* @internal
|
|
48
|
+
*/
|
|
49
|
+
const executeScriptElements = (rootElement) => {
|
|
50
|
+
const scriptElements = rootElement.querySelectorAll('script');
|
|
51
|
+
if (!scriptElements) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
Array.from(scriptElements).forEach((scriptElement) => {
|
|
55
|
+
var _a;
|
|
56
|
+
const clonedElement = document.createElement('script');
|
|
57
|
+
Array.from(scriptElement.attributes).forEach((attribute) => {
|
|
58
|
+
clonedElement.setAttribute(attribute.name, attribute.value);
|
|
59
|
+
});
|
|
60
|
+
clonedElement.text = scriptElement.text;
|
|
61
|
+
(_a = scriptElement === null || scriptElement === void 0 ? void 0 : scriptElement.parentNode) === null || _a === void 0 ? void 0 : _a.replaceChild(clonedElement, scriptElement);
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
exports.executeScriptElements = executeScriptElements;
|
|
65
|
+
/**
|
|
66
|
+
* Subscribes to the Form event
|
|
67
|
+
* This listener captures interactions such as form views or submissions
|
|
68
|
+
* @param {HTMLElement} formElement - The form element to subscribe to events on
|
|
69
|
+
* @param {string} [componentId] - The unique identifier of the component
|
|
70
|
+
* @internal
|
|
71
|
+
*/
|
|
72
|
+
const subscribeToFormSubmitEvent = (formElement, componentId) => {
|
|
73
|
+
formElement.addEventListener('form:engage', ((e) => {
|
|
74
|
+
const { formId, name } = e.detail;
|
|
75
|
+
if (formId && name) {
|
|
76
|
+
debug_1.default.form('Sending form event', formId, name);
|
|
77
|
+
(0, browser_1.form)(formId, name, (componentId === null || componentId === void 0 ? void 0 : componentId.replace(/-/g, '')) || '');
|
|
78
|
+
}
|
|
79
|
+
}));
|
|
80
|
+
};
|
|
81
|
+
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; } });
|
|
@@ -0,0 +1,144 @@
|
|
|
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.DictionaryService = exports.queryError = void 0;
|
|
7
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
8
|
+
const constants_1 = require("../constants");
|
|
9
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
10
|
+
/** @private */
|
|
11
|
+
exports.queryError = 'Valid value for rootItemId not provided and failed to auto-resolve app root item.';
|
|
12
|
+
/** @default */
|
|
13
|
+
const siteQuery = /* GraphQL */ `
|
|
14
|
+
query DictionarySiteQuery(
|
|
15
|
+
$siteName: String!
|
|
16
|
+
$language: String!
|
|
17
|
+
$pageSize: Int = 500
|
|
18
|
+
$after: String
|
|
19
|
+
) {
|
|
20
|
+
site {
|
|
21
|
+
siteInfo(site: $siteName) {
|
|
22
|
+
dictionary(language: $language, first: $pageSize, after: $after) {
|
|
23
|
+
pageInfo {
|
|
24
|
+
endCursor
|
|
25
|
+
hasNext
|
|
26
|
+
}
|
|
27
|
+
results {
|
|
28
|
+
key
|
|
29
|
+
value
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
`;
|
|
36
|
+
/**
|
|
37
|
+
* Service that fetch dictionary data using Sitecore's GraphQL API.
|
|
38
|
+
* @augments DictionaryServiceBase
|
|
39
|
+
* @mixes SearchQueryService<DictionaryQueryResult>
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
class DictionaryService {
|
|
43
|
+
/**
|
|
44
|
+
* Creates an instance of graphQL dictionary service with the provided options
|
|
45
|
+
* @param {DictionaryService} options instance
|
|
46
|
+
*/
|
|
47
|
+
constructor(options) {
|
|
48
|
+
this.options = options;
|
|
49
|
+
this.cache = this.getCacheClient();
|
|
50
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Fetches dictionary data for internalization. Uses search query by default
|
|
54
|
+
* @param {string} language the language to fetch
|
|
55
|
+
* @param {string} site site name to fetch data for.
|
|
56
|
+
* @param {FetchOptions} [fetchOptions] Options to override graphQL client details like retries and fetch implementation
|
|
57
|
+
* @returns {Promise<DictionaryPhrases>} dictionary phrases
|
|
58
|
+
* @throws {Error} if the app root was not found for the specified site and language.
|
|
59
|
+
*/
|
|
60
|
+
async fetchDictionaryData(language, site, fetchOptions) {
|
|
61
|
+
var _a, _b;
|
|
62
|
+
const cacheKey = site + language;
|
|
63
|
+
const cachedValue = this.getCacheValue(cacheKey);
|
|
64
|
+
if (cachedValue) {
|
|
65
|
+
debug_1.default.dictionary('using cached dictionary data for %s %s', language, site);
|
|
66
|
+
return cachedValue;
|
|
67
|
+
}
|
|
68
|
+
const phrases = {};
|
|
69
|
+
debug_1.default.dictionary('fetching dictionary data for %s %s', language, site);
|
|
70
|
+
let results = [];
|
|
71
|
+
let hasNext = true;
|
|
72
|
+
let after = '';
|
|
73
|
+
if (!site) {
|
|
74
|
+
throw new RangeError(constants_1.siteNameError);
|
|
75
|
+
}
|
|
76
|
+
if (!language) {
|
|
77
|
+
throw new RangeError(constants_1.languageError);
|
|
78
|
+
}
|
|
79
|
+
while (hasNext) {
|
|
80
|
+
const fetchResponse = await this.graphQLClient.request(siteQuery, {
|
|
81
|
+
siteName: site,
|
|
82
|
+
language,
|
|
83
|
+
pageSize: this.options.pageSize,
|
|
84
|
+
after,
|
|
85
|
+
}, fetchOptions);
|
|
86
|
+
if ((_b = (_a = fetchResponse === null || fetchResponse === void 0 ? void 0 : fetchResponse.site) === null || _a === void 0 ? void 0 : _a.siteInfo) === null || _b === void 0 ? void 0 : _b.dictionary) {
|
|
87
|
+
results = results.concat(fetchResponse.site.siteInfo.dictionary.results);
|
|
88
|
+
after = fetchResponse.site.siteInfo.dictionary.pageInfo.endCursor;
|
|
89
|
+
hasNext = fetchResponse.site.siteInfo.dictionary.pageInfo.hasNext;
|
|
90
|
+
}
|
|
91
|
+
else {
|
|
92
|
+
hasNext = false;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
results.forEach((item) => (phrases[item.key] = item.value));
|
|
96
|
+
this.setCacheValue(cacheKey, phrases);
|
|
97
|
+
return phrases;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Caches a @see DictionaryPhrases value for the specified cache key.
|
|
101
|
+
* @param {string} key The cache key.
|
|
102
|
+
* @param {DictionaryPhrases} value The value to cache.
|
|
103
|
+
* @returns The value added to the cache.
|
|
104
|
+
* @mixes CacheClient<DictionaryPhrases>
|
|
105
|
+
*/
|
|
106
|
+
setCacheValue(key, value) {
|
|
107
|
+
return this.cache.setCacheValue(key, value);
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Retrieves a @see DictionaryPhrases value from the cache.
|
|
111
|
+
* @param {string} key The cache key.
|
|
112
|
+
* @returns The @see DictionaryPhrases value, or null if the specified key is not found in the cache.
|
|
113
|
+
*/
|
|
114
|
+
getCacheValue(key) {
|
|
115
|
+
return this.cache.getCacheValue(key);
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets a cache client that can cache data. Uses memory-cache as the default
|
|
119
|
+
* library for caching (@see MemoryCacheClient). Override this method if you
|
|
120
|
+
* want to use something else.
|
|
121
|
+
* @returns {CacheClient} implementation
|
|
122
|
+
*/
|
|
123
|
+
getCacheClient() {
|
|
124
|
+
return new core_1.MemoryCacheClient(this.options);
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
128
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
129
|
+
* want to use something else.
|
|
130
|
+
* @returns {GraphQLClient} implementation
|
|
131
|
+
*/
|
|
132
|
+
getGraphQLClient() {
|
|
133
|
+
var _a, _b;
|
|
134
|
+
if (!this.options.clientFactory) {
|
|
135
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
136
|
+
}
|
|
137
|
+
return this.options.clientFactory({
|
|
138
|
+
debugger: debug_1.default.dictionary,
|
|
139
|
+
retries: (_a = this.options.retries) === null || _a === void 0 ? void 0 : _a.count,
|
|
140
|
+
retryStrategy: (_b = this.options.retries) === null || _b === void 0 ? void 0 : _b.retryStrategy,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
exports.DictionaryService = DictionaryService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocaleRewrite = exports.DictionaryService = void 0;
|
|
4
|
+
var dictionary_service_1 = require("./dictionary-service");
|
|
5
|
+
Object.defineProperty(exports, "DictionaryService", { enumerable: true, get: function () { return dictionary_service_1.DictionaryService; } });
|
|
6
|
+
var utils_1 = require("./utils");
|
|
7
|
+
Object.defineProperty(exports, "getLocaleRewrite", { enumerable: true, get: function () { return utils_1.getLocaleRewrite; } });
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getLocaleRewrite = getLocaleRewrite;
|
|
4
|
+
/**
|
|
5
|
+
* Get a locale rewrite path for given pathname
|
|
6
|
+
* @param {string} pathname the pathname
|
|
7
|
+
* @param {string} locale the site data to include in the rewrite
|
|
8
|
+
* @returns {string} the rewrite path
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
function getLocaleRewrite(pathname, locale) {
|
|
12
|
+
if (pathname === '/')
|
|
13
|
+
return `/${locale}`;
|
|
14
|
+
const path = pathname.startsWith('/') ? pathname : '/' + pathname;
|
|
15
|
+
return `/${locale}${path}`;
|
|
16
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
36
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
37
|
+
};
|
|
38
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
|
+
exports.HIDDEN_RENDERING_NAME = exports.defineConfig = exports.form = exports.debug = void 0;
|
|
40
|
+
const form = __importStar(require("./form"));
|
|
41
|
+
exports.form = form;
|
|
42
|
+
var debug_1 = require("./debug");
|
|
43
|
+
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return __importDefault(debug_1).default; } });
|
|
44
|
+
var config_1 = require("./config");
|
|
45
|
+
Object.defineProperty(exports, "defineConfig", { enumerable: true, get: function () { return config_1.defineConfig; } });
|
|
46
|
+
var constants_1 = require("./constants");
|
|
47
|
+
Object.defineProperty(exports, "HIDDEN_RENDERING_NAME", { enumerable: true, get: function () { return constants_1.HIDDEN_RENDERING_NAME; } });
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.traverseComponent = exports.traverseField = exports.traversePlaceholder = exports.getContentStylesheetUrl = exports.getContentStylesheetLink = void 0;
|
|
4
|
+
const tools_1 = require("@sitecore-content-sdk/core/tools");
|
|
5
|
+
const core_1 = require("@sitecore-content-sdk/core");
|
|
6
|
+
const { SITECORE_EDGE_URL_DEFAULT } = core_1.constants;
|
|
7
|
+
/**
|
|
8
|
+
* Regular expression to check if the content styles are used in the field value
|
|
9
|
+
*/
|
|
10
|
+
const CLASS_REGEXP = /class=".*(\bck-content\b).*"/g;
|
|
11
|
+
/**
|
|
12
|
+
* Get the content styles link to be loaded from the Sitecore Edge Platform
|
|
13
|
+
* @param {LayoutServiceData} layoutData Layout service data
|
|
14
|
+
* @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
|
|
15
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
16
|
+
* @returns {HTMLLink | null} content styles link, null if no styles are used in layout
|
|
17
|
+
* @public
|
|
18
|
+
*/
|
|
19
|
+
const getContentStylesheetLink = (layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => {
|
|
20
|
+
if (!layoutData.sitecore.route)
|
|
21
|
+
return null;
|
|
22
|
+
const config = { loadStyles: false };
|
|
23
|
+
(0, exports.traverseComponent)(layoutData.sitecore.route, config);
|
|
24
|
+
if (!config.loadStyles)
|
|
25
|
+
return null;
|
|
26
|
+
return {
|
|
27
|
+
href: (0, exports.getContentStylesheetUrl)(sitecoreEdgeContextId, sitecoreEdgeUrl),
|
|
28
|
+
rel: 'stylesheet',
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
exports.getContentStylesheetLink = getContentStylesheetLink;
|
|
32
|
+
const getContentStylesheetUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = SITECORE_EDGE_URL_DEFAULT) => `${(0, tools_1.normalizeUrl)(sitecoreEdgeUrl)}/v1/files/pages/styles/content-styles.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
33
|
+
exports.getContentStylesheetUrl = getContentStylesheetUrl;
|
|
34
|
+
const traversePlaceholder = (components, config) => {
|
|
35
|
+
if (config.loadStyles)
|
|
36
|
+
return;
|
|
37
|
+
components.forEach((component) => {
|
|
38
|
+
(0, exports.traverseComponent)(component, config);
|
|
39
|
+
});
|
|
40
|
+
};
|
|
41
|
+
exports.traversePlaceholder = traversePlaceholder;
|
|
42
|
+
const traverseField = (field, config) => {
|
|
43
|
+
if (!field || typeof field !== 'object' || config.loadStyles)
|
|
44
|
+
return;
|
|
45
|
+
if ('value' in field && typeof field.value === 'string') {
|
|
46
|
+
config.loadStyles = CLASS_REGEXP.test(field.value);
|
|
47
|
+
}
|
|
48
|
+
else if ('fields' in field) {
|
|
49
|
+
Object.values(field.fields).forEach((field) => {
|
|
50
|
+
(0, exports.traverseField)(field, config);
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
else if (Array.isArray(field)) {
|
|
54
|
+
field.forEach((field) => {
|
|
55
|
+
(0, exports.traverseField)(field, config);
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
exports.traverseField = traverseField;
|
|
60
|
+
const traverseComponent = (component, config) => {
|
|
61
|
+
if (config.loadStyles)
|
|
62
|
+
return;
|
|
63
|
+
if ('fields' in component && component.fields) {
|
|
64
|
+
Object.values(component.fields).forEach((field) => {
|
|
65
|
+
(0, exports.traverseField)(field, config);
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const placeholders = component.placeholders || {};
|
|
69
|
+
Object.keys(placeholders).forEach((placeholder) => {
|
|
70
|
+
(0, exports.traversePlaceholder)(placeholders[placeholder], config);
|
|
71
|
+
});
|
|
72
|
+
};
|
|
73
|
+
exports.traverseComponent = traverseComponent;
|