@sitecore-jss/sitecore-jss 21.1.1 → 21.2.0-canary.1

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/README.md CHANGED
@@ -2,9 +2,9 @@
2
2
 
3
3
  This module is provided as a part of Sitecore JavaScript Rendering SDK. It contains the core JSS APIs (layout service) and utilities.
4
4
 
5
+ <!---
6
+ @TODO: Update to version 20.0.0 docs before release
7
+ -->
8
+ [Documentation](https://doc.sitecore.com/xp/en/developers/hd/190/sitecore-headless-development/sitecore-javascript-rendering-sdks--jss-.html)
5
9
 
6
- [Documentation (Experience Platform)](https://doc.sitecore.com/xp/en/developers/hd/210/sitecore-headless-development/sitecore-javascript-rendering-sdks--jss-.html)
7
-
8
- [Documentation (XM Cloud)](https://doc.sitecore.com/xmc/en/developers/xm-cloud/sitecore-javascript-rendering-sdks--jss-.html)
9
-
10
- [API reference documentation](/ref-docs/sitecore-jss/)
10
+ [API reference documentation](/ref-docs/sitecore-jss/).
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFEAASLibraryStylesheetLinks = void 0;
4
+ var themes_1 = require("./themes");
5
+ Object.defineProperty(exports, "getFEAASLibraryStylesheetLinks", { enumerable: true, get: function () { return themes_1.getFEAASLibraryStylesheetLinks; } });
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getStylesheetUrl = exports.getFEAASLibraryStylesheetLinks = exports.FEAAS_SERVER_URL = void 0;
4
+ const layout_1 = require("../layout");
5
+ /**
6
+ * Pattern for library ids
7
+ * @example -library--foo
8
+ */
9
+ const FEAAS_LIBRARY_ID_REGEX = /-library--([^\s]+)/;
10
+ exports.FEAAS_SERVER_URL = 'https://feaas.blob.core.windows.net';
11
+ /**
12
+ * Walks through rendering tree and returns list of links of all FEAAS Component Library Stylesheets that are used
13
+ * @param {LayoutServiceData} layoutData Layout service data
14
+ * @param {string} [serverUrl] server URL, default is @see {FEAAS_SERVER_URL} url
15
+ * @returns {HTMLLink[]} library stylesheet links
16
+ */
17
+ function getFEAASLibraryStylesheetLinks(layoutData, serverUrl) {
18
+ const ids = new Set();
19
+ if (!layoutData.sitecore.route)
20
+ return [];
21
+ traverseComponent(layoutData.sitecore.route, ids);
22
+ return [...ids].map((id) => ({ href: exports.getStylesheetUrl(id, serverUrl), rel: 'style' }));
23
+ }
24
+ exports.getFEAASLibraryStylesheetLinks = getFEAASLibraryStylesheetLinks;
25
+ const getStylesheetUrl = (id, serverUrl) => `${serverUrl || exports.FEAAS_SERVER_URL}/styles/${id}/published.css`;
26
+ exports.getStylesheetUrl = getStylesheetUrl;
27
+ /**
28
+ * Traverse placeholder and components to add library ids
29
+ * @param {Array<ComponentRendering | HtmlElementRendering>} components
30
+ * @param {Set<string>} ids library ids
31
+ */
32
+ const traversePlaceholder = (components, ids) => {
33
+ components.map((component) => {
34
+ const rendering = component;
35
+ return traverseComponent(rendering, ids);
36
+ });
37
+ };
38
+ /**
39
+ * Traverse component and children to add library ids
40
+ * @param {RouteData | ComponentRendering | HtmlElementRendering} component component data
41
+ * @param {Set<string>} ids library ids
42
+ */
43
+ const traverseComponent = (component, ids) => {
44
+ var _a, _b;
45
+ let libraryId = undefined;
46
+ if ('fields' in component && component.fields) {
47
+ // LibraryID in css class name takes precedence over LibraryId attribute
48
+ libraryId =
49
+ ((_a = layout_1.getFieldValue(component.fields, 'CSSStyles', '').match(FEAAS_LIBRARY_ID_REGEX)) === null || _a === void 0 ? void 0 : _a[1]) ||
50
+ layout_1.getFieldValue(component.fields, 'LibraryId', '') ||
51
+ undefined;
52
+ // HTMLRendering its class attribute
53
+ }
54
+ else if ('attributes' in component && typeof component.attributes.class === 'string') {
55
+ libraryId = (_b = component.attributes.class.match(FEAAS_LIBRARY_ID_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
56
+ }
57
+ if (libraryId) {
58
+ ids.add(libraryId);
59
+ }
60
+ const placeholders = component.placeholders || {};
61
+ Object.keys(placeholders).forEach((placeholder) => {
62
+ traversePlaceholder(placeholders[placeholder], ids);
63
+ });
64
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -0,0 +1 @@
1
+ export { getFEAASLibraryStylesheetLinks } from './themes';
@@ -0,0 +1,59 @@
1
+ import { getFieldValue, } from '../layout';
2
+ /**
3
+ * Pattern for library ids
4
+ * @example -library--foo
5
+ */
6
+ const FEAAS_LIBRARY_ID_REGEX = /-library--([^\s]+)/;
7
+ export const FEAAS_SERVER_URL = 'https://feaas.blob.core.windows.net';
8
+ /**
9
+ * Walks through rendering tree and returns list of links of all FEAAS Component Library Stylesheets that are used
10
+ * @param {LayoutServiceData} layoutData Layout service data
11
+ * @param {string} [serverUrl] server URL, default is @see {FEAAS_SERVER_URL} url
12
+ * @returns {HTMLLink[]} library stylesheet links
13
+ */
14
+ export function getFEAASLibraryStylesheetLinks(layoutData, serverUrl) {
15
+ const ids = new Set();
16
+ if (!layoutData.sitecore.route)
17
+ return [];
18
+ traverseComponent(layoutData.sitecore.route, ids);
19
+ return [...ids].map((id) => ({ href: getStylesheetUrl(id, serverUrl), rel: 'style' }));
20
+ }
21
+ export const getStylesheetUrl = (id, serverUrl) => `${serverUrl || FEAAS_SERVER_URL}/styles/${id}/published.css`;
22
+ /**
23
+ * Traverse placeholder and components to add library ids
24
+ * @param {Array<ComponentRendering | HtmlElementRendering>} components
25
+ * @param {Set<string>} ids library ids
26
+ */
27
+ const traversePlaceholder = (components, ids) => {
28
+ components.map((component) => {
29
+ const rendering = component;
30
+ return traverseComponent(rendering, ids);
31
+ });
32
+ };
33
+ /**
34
+ * Traverse component and children to add library ids
35
+ * @param {RouteData | ComponentRendering | HtmlElementRendering} component component data
36
+ * @param {Set<string>} ids library ids
37
+ */
38
+ const traverseComponent = (component, ids) => {
39
+ var _a, _b;
40
+ let libraryId = undefined;
41
+ if ('fields' in component && component.fields) {
42
+ // LibraryID in css class name takes precedence over LibraryId attribute
43
+ libraryId =
44
+ ((_a = getFieldValue(component.fields, 'CSSStyles', '').match(FEAAS_LIBRARY_ID_REGEX)) === null || _a === void 0 ? void 0 : _a[1]) ||
45
+ getFieldValue(component.fields, 'LibraryId', '') ||
46
+ undefined;
47
+ // HTMLRendering its class attribute
48
+ }
49
+ else if ('attributes' in component && typeof component.attributes.class === 'string') {
50
+ libraryId = (_b = component.attributes.class.match(FEAAS_LIBRARY_ID_REGEX)) === null || _b === void 0 ? void 0 : _b[1];
51
+ }
52
+ if (libraryId) {
53
+ ids.add(libraryId);
54
+ }
55
+ const placeholders = component.placeholders || {};
56
+ Object.keys(placeholders).forEach((placeholder) => {
57
+ traversePlaceholder(placeholders[placeholder], ids);
58
+ });
59
+ };
@@ -0,0 +1 @@
1
+ export {};
package/feaas.d.ts ADDED
@@ -0,0 +1 @@
1
+ export * from './types/feaas/index';
package/feaas.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./dist/cjs/feaas/index');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sitecore-jss/sitecore-jss",
3
- "version": "21.1.1",
3
+ "version": "21.2.0-canary.1",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "sideEffects": false,
@@ -45,7 +45,7 @@
45
45
  "chai-string": "^1.5.0",
46
46
  "del-cli": "^5.0.0",
47
47
  "eslint": "^7.15.0",
48
- "mocha": "^9.1.3",
48
+ "mocha": "^10.2.0",
49
49
  "nock": "^13.0.5",
50
50
  "nyc": "^15.1.0",
51
51
  "ts-node": "^8.4.1",
@@ -64,7 +64,7 @@
64
64
  },
65
65
  "description": "",
66
66
  "types": "types/index.d.ts",
67
- "gitHead": "ae9d7fc994fa11061b5a164ff6a86b3ccf845a4c",
67
+ "gitHead": "dc42835a8d9241ab050938f45c795a795a1a190a",
68
68
  "files": [
69
69
  "dist",
70
70
  "types",
@@ -0,0 +1 @@
1
+ export { getFEAASLibraryStylesheetLinks } from './themes';
@@ -0,0 +1,11 @@
1
+ import { LayoutServiceData } from '../layout';
2
+ import { HTMLLink } from '../models';
3
+ export declare const FEAAS_SERVER_URL = "https://feaas.blob.core.windows.net";
4
+ /**
5
+ * Walks through rendering tree and returns list of links of all FEAAS Component Library Stylesheets that are used
6
+ * @param {LayoutServiceData} layoutData Layout service data
7
+ * @param {string} [serverUrl] server URL, default is @see {FEAAS_SERVER_URL} url
8
+ * @returns {HTMLLink[]} library stylesheet links
9
+ */
10
+ export declare function getFEAASLibraryStylesheetLinks(layoutData: LayoutServiceData, serverUrl?: string): HTMLLink[];
11
+ export declare const getStylesheetUrl: (id: string, serverUrl?: string | undefined) => string;
package/types/index.d.ts CHANGED
@@ -5,4 +5,5 @@ export { GraphQLClient, GraphQLRequestClient, GraphQLRequestClientConfig, } from
5
5
  export { AxiosDataFetcher, AxiosDataFetcherConfig } from './axios-fetcher';
6
6
  export { AxiosResponse } from 'axios';
7
7
  export { NativeDataFetcher, NativeDataFetcherConfig } from './native-fetcher';
8
+ export { HTMLLink } from './models';
8
9
  export { constants };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Html <link> tag data model
3
+ */
4
+ export declare type HTMLLink = {
5
+ [key: string]: unknown;
6
+ } & Pick<HTMLLinkElement, 'rel' | 'href'>;