@sitecore-content-sdk/core 0.1.0-beta.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/LICENSE.txt +202 -0
- package/README.md +11 -0
- package/dist/cjs/cache-client.js +54 -0
- package/dist/cjs/constants.js +13 -0
- package/dist/cjs/data-fetcher.js +33 -0
- package/dist/cjs/debug.js +43 -0
- package/dist/cjs/editing/component-library.js +104 -0
- package/dist/cjs/editing/graphql-editing-service.js +186 -0
- package/dist/cjs/editing/index.js +23 -0
- package/dist/cjs/editing/models.js +23 -0
- package/dist/cjs/editing/rest-component-layout-service.js +76 -0
- package/dist/cjs/editing/utils.js +86 -0
- package/dist/cjs/graphql/app-root-query.js +73 -0
- package/dist/cjs/graphql/graphql-edge-proxy.js +21 -0
- package/dist/cjs/graphql/index.js +13 -0
- package/dist/cjs/graphql/search-service.js +61 -0
- package/dist/cjs/graphql-request-client.js +152 -0
- package/dist/cjs/i18n/dictionary-service.js +45 -0
- package/dist/cjs/i18n/graphql-dictionary-service.js +136 -0
- package/dist/cjs/i18n/index.js +7 -0
- package/dist/cjs/index.js +55 -0
- package/dist/cjs/layout/content-styles.js +70 -0
- package/dist/cjs/layout/graphql-layout-service.js +86 -0
- package/dist/cjs/layout/index.js +24 -0
- package/dist/cjs/layout/layout-service.js +9 -0
- package/dist/cjs/layout/models.js +35 -0
- package/dist/cjs/layout/themes.js +74 -0
- package/dist/cjs/layout/utils.js +110 -0
- package/dist/cjs/media/index.js +38 -0
- package/dist/cjs/media/media-api.js +96 -0
- package/dist/cjs/models.js +2 -0
- package/dist/cjs/native-fetcher.js +200 -0
- package/dist/cjs/personalize/graphql-personalize-service.js +114 -0
- package/dist/cjs/personalize/index.js +14 -0
- package/dist/cjs/personalize/layout-personalizer.js +97 -0
- package/dist/cjs/personalize/utils.js +136 -0
- package/dist/cjs/site/graphql-error-pages-service.js +89 -0
- package/dist/cjs/site/graphql-redirects-service.js +105 -0
- package/dist/cjs/site/graphql-robots-service.js +83 -0
- package/dist/cjs/site/graphql-siteinfo-service.js +107 -0
- package/dist/cjs/site/graphql-sitemap-service.js +93 -0
- package/dist/cjs/site/index.js +22 -0
- package/dist/cjs/site/site-resolver.js +79 -0
- package/dist/cjs/site/utils.js +43 -0
- package/dist/cjs/utils/env.js +26 -0
- package/dist/cjs/utils/index.js +20 -0
- package/dist/cjs/utils/is-server.js +10 -0
- package/dist/cjs/utils/timeout-promise.js +31 -0
- package/dist/cjs/utils/utils.js +222 -0
- package/dist/esm/cache-client.js +50 -0
- package/dist/esm/constants.js +10 -0
- package/dist/esm/data-fetcher.js +28 -0
- package/dist/esm/debug.js +36 -0
- package/dist/esm/editing/component-library.js +98 -0
- package/dist/esm/editing/graphql-editing-service.js +179 -0
- package/dist/esm/editing/index.js +5 -0
- package/dist/esm/editing/models.js +20 -0
- package/dist/esm/editing/rest-component-layout-service.js +72 -0
- package/dist/esm/editing/utils.js +76 -0
- package/dist/esm/graphql/app-root-query.js +69 -0
- package/dist/esm/graphql/graphql-edge-proxy.js +16 -0
- package/dist/esm/graphql/index.js +4 -0
- package/dist/esm/graphql/search-service.js +57 -0
- package/dist/esm/graphql-request-client.js +144 -0
- package/dist/esm/i18n/dictionary-service.js +41 -0
- package/dist/esm/i18n/graphql-dictionary-service.js +129 -0
- package/dist/esm/i18n/index.js +2 -0
- package/dist/esm/index.js +9 -0
- package/dist/esm/layout/content-styles.js +62 -0
- package/dist/esm/layout/graphql-layout-service.js +79 -0
- package/dist/esm/layout/index.js +6 -0
- package/dist/esm/layout/layout-service.js +5 -0
- package/dist/esm/layout/models.js +32 -0
- package/dist/esm/layout/themes.js +69 -0
- package/dist/esm/layout/utils.js +102 -0
- package/dist/esm/media/index.js +2 -0
- package/dist/esm/media/media-api.js +86 -0
- package/dist/esm/models.js +1 -0
- package/dist/esm/native-fetcher.js +193 -0
- package/dist/esm/personalize/graphql-personalize-service.js +107 -0
- package/dist/esm/personalize/index.js +3 -0
- package/dist/esm/personalize/layout-personalizer.js +92 -0
- package/dist/esm/personalize/utils.js +128 -0
- package/dist/esm/site/graphql-error-pages-service.js +82 -0
- package/dist/esm/site/graphql-redirects-service.js +98 -0
- package/dist/esm/site/graphql-robots-service.js +76 -0
- package/dist/esm/site/graphql-siteinfo-service.js +100 -0
- package/dist/esm/site/graphql-sitemap-service.js +86 -0
- package/dist/esm/site/index.js +7 -0
- package/dist/esm/site/site-resolver.js +75 -0
- package/dist/esm/site/utils.js +37 -0
- package/dist/esm/utils/env.js +22 -0
- package/dist/esm/utils/index.js +3 -0
- package/dist/esm/utils/is-server.js +8 -0
- package/dist/esm/utils/timeout-promise.js +28 -0
- package/dist/esm/utils/utils.js +207 -0
- package/editing.d.ts +1 -0
- package/editing.js +1 -0
- package/graphql.d.ts +1 -0
- package/graphql.js +1 -0
- package/i18n.d.ts +1 -0
- package/i18n.js +1 -0
- package/layout.d.ts +1 -0
- package/layout.js +1 -0
- package/media.d.ts +1 -0
- package/media.js +1 -0
- package/package.json +76 -0
- package/personalize.d.ts +1 -0
- package/personalize.js +1 -0
- package/site.d.ts +1 -0
- package/site.js +1 -0
- package/types/cache-client.d.ts +64 -0
- package/types/constants.d.ts +7 -0
- package/types/data-fetcher.d.ts +34 -0
- package/types/debug.d.ts +26 -0
- package/types/editing/component-library.d.ts +48 -0
- package/types/editing/graphql-editing-service.d.ts +90 -0
- package/types/editing/index.d.ts +6 -0
- package/types/editing/models.d.ts +52 -0
- package/types/editing/rest-component-layout-service.d.ts +100 -0
- package/types/editing/utils.d.ts +70 -0
- package/types/graphql/app-root-query.d.ts +32 -0
- package/types/graphql/graphql-edge-proxy.d.ts +15 -0
- package/types/graphql/index.d.ts +4 -0
- package/types/graphql/search-service.d.ts +95 -0
- package/types/graphql-request-client.d.ts +159 -0
- package/types/i18n/dictionary-service.d.ts +56 -0
- package/types/i18n/graphql-dictionary-service.d.ts +94 -0
- package/types/i18n/index.d.ts +2 -0
- package/types/index.d.ts +8 -0
- package/types/layout/content-styles.d.ts +18 -0
- package/types/layout/graphql-layout-service.d.ts +58 -0
- package/types/layout/index.d.ts +6 -0
- package/types/layout/layout-service.d.ts +19 -0
- package/types/layout/models.d.ts +145 -0
- package/types/layout/themes.d.ts +11 -0
- package/types/layout/utils.d.ts +40 -0
- package/types/media/index.d.ts +2 -0
- package/types/media/media-api.d.ts +55 -0
- package/types/models.d.ts +6 -0
- package/types/native-fetcher.d.ts +121 -0
- package/types/personalize/graphql-personalize-service.d.ts +80 -0
- package/types/personalize/index.d.ts +3 -0
- package/types/personalize/layout-personalizer.d.ts +27 -0
- package/types/personalize/utils.d.ts +69 -0
- package/types/site/graphql-error-pages-service.d.ts +57 -0
- package/types/site/graphql-redirects-service.d.ts +68 -0
- package/types/site/graphql-robots-service.d.ts +49 -0
- package/types/site/graphql-siteinfo-service.d.ts +70 -0
- package/types/site/graphql-sitemap-service.d.ts +55 -0
- package/types/site/index.d.ts +7 -0
- package/types/site/site-resolver.d.ts +27 -0
- package/types/site/utils.d.ts +24 -0
- package/types/utils/env.d.ts +7 -0
- package/types/utils/index.d.ts +3 -0
- package/types/utils/is-server.d.ts +6 -0
- package/types/utils/timeout-promise.d.ts +17 -0
- package/types/utils/utils.d.ts +71 -0
- package/utils.d.ts +1 -0
- package/utils.js +1 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GraphQLDictionaryService = exports.queryError = void 0;
|
|
16
|
+
const dictionary_service_1 = require("./dictionary-service");
|
|
17
|
+
const app_root_query_1 = require("../graphql/app-root-query");
|
|
18
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
19
|
+
/** @private */
|
|
20
|
+
exports.queryError = 'Valid value for rootItemId not provided and failed to auto-resolve app root item.';
|
|
21
|
+
/** @default */
|
|
22
|
+
const siteQuery = /* GraphQL */ `
|
|
23
|
+
query DictionarySiteQuery(
|
|
24
|
+
$siteName: String!
|
|
25
|
+
$language: String!
|
|
26
|
+
$pageSize: Int = 500
|
|
27
|
+
$after: String
|
|
28
|
+
) {
|
|
29
|
+
site {
|
|
30
|
+
siteInfo(site: $siteName) {
|
|
31
|
+
dictionary(language: $language, first: $pageSize, after: $after) {
|
|
32
|
+
pageInfo {
|
|
33
|
+
endCursor
|
|
34
|
+
hasNext
|
|
35
|
+
}
|
|
36
|
+
results {
|
|
37
|
+
key
|
|
38
|
+
value
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
`;
|
|
45
|
+
/**
|
|
46
|
+
* Service that fetch dictionary data using Sitecore's GraphQL API.
|
|
47
|
+
* @augments DictionaryServiceBase
|
|
48
|
+
* @mixes SearchQueryService<DictionaryQueryResult>
|
|
49
|
+
*/
|
|
50
|
+
class GraphQLDictionaryService extends dictionary_service_1.DictionaryServiceBase {
|
|
51
|
+
/**
|
|
52
|
+
* Creates an instance of graphQL dictionary service with the provided options
|
|
53
|
+
* @param {GraphQLDictionaryService} options instance
|
|
54
|
+
*/
|
|
55
|
+
constructor(options) {
|
|
56
|
+
super(options);
|
|
57
|
+
this.options = options;
|
|
58
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Fetches dictionary data for internalization. Uses search query by default
|
|
62
|
+
* @param {string} language the language to fetch
|
|
63
|
+
* @returns {Promise<DictionaryPhrases>} dictionary phrases
|
|
64
|
+
* @throws {Error} if the app root was not found for the specified site and language.
|
|
65
|
+
*/
|
|
66
|
+
fetchDictionaryData(language) {
|
|
67
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const cacheKey = this.options.siteName + language;
|
|
69
|
+
const cachedValue = this.getCacheValue(cacheKey);
|
|
70
|
+
if (cachedValue) {
|
|
71
|
+
debug_1.default.dictionary('using cached dictionary data for %s %s', language, this.options.siteName);
|
|
72
|
+
return cachedValue;
|
|
73
|
+
}
|
|
74
|
+
const phrases = yield this.fetchWithSiteQuery(language);
|
|
75
|
+
this.setCacheValue(cacheKey, phrases);
|
|
76
|
+
return phrases;
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Fetches dictionary data with site query
|
|
81
|
+
* This is the default behavior for XMCloud deployments. Uses `siteQuery` to retrieve data.
|
|
82
|
+
* @param {string} language the language to fetch
|
|
83
|
+
* @returns {Promise<DictionaryPhrases>} dictionary phrases
|
|
84
|
+
*/
|
|
85
|
+
fetchWithSiteQuery(language) {
|
|
86
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const phrases = {};
|
|
89
|
+
debug_1.default.dictionary('fetching dictionary data for %s %s', language, this.options.siteName);
|
|
90
|
+
let results = [];
|
|
91
|
+
let hasNext = true;
|
|
92
|
+
let after = '';
|
|
93
|
+
if (!this.options.siteName) {
|
|
94
|
+
throw new RangeError(app_root_query_1.siteNameError);
|
|
95
|
+
}
|
|
96
|
+
if (!language) {
|
|
97
|
+
throw new RangeError(app_root_query_1.languageError);
|
|
98
|
+
}
|
|
99
|
+
while (hasNext) {
|
|
100
|
+
const fetchResponse = yield this.graphQLClient.request(siteQuery, {
|
|
101
|
+
siteName: this.options.siteName,
|
|
102
|
+
language,
|
|
103
|
+
pageSize: this.options.pageSize,
|
|
104
|
+
after,
|
|
105
|
+
});
|
|
106
|
+
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) {
|
|
107
|
+
results = results.concat(fetchResponse.site.siteInfo.dictionary.results);
|
|
108
|
+
after = fetchResponse.site.siteInfo.dictionary.pageInfo.endCursor;
|
|
109
|
+
hasNext = fetchResponse.site.siteInfo.dictionary.pageInfo.hasNext;
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
hasNext = false;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
results.forEach((item) => (phrases[item.key] = item.value));
|
|
116
|
+
return phrases;
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Gets a GraphQL client that can make requests to the API. Uses graphql-request as the default
|
|
121
|
+
* library for fetching graphql data (@see GraphQLRequestClient). Override this method if you
|
|
122
|
+
* want to use something else.
|
|
123
|
+
* @returns {GraphQLClient} implementation
|
|
124
|
+
*/
|
|
125
|
+
getGraphQLClient() {
|
|
126
|
+
if (!this.options.clientFactory) {
|
|
127
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
128
|
+
}
|
|
129
|
+
return this.options.clientFactory({
|
|
130
|
+
debugger: debug_1.default.dictionary,
|
|
131
|
+
retries: this.options.retries,
|
|
132
|
+
retryStrategy: this.options.retryStrategy,
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.GraphQLDictionaryService = GraphQLDictionaryService;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.GraphQLDictionaryService = exports.DictionaryServiceBase = void 0;
|
|
4
|
+
var dictionary_service_1 = require("./dictionary-service");
|
|
5
|
+
Object.defineProperty(exports, "DictionaryServiceBase", { enumerable: true, get: function () { return dictionary_service_1.DictionaryServiceBase; } });
|
|
6
|
+
var graphql_dictionary_service_1 = require("./graphql-dictionary-service");
|
|
7
|
+
Object.defineProperty(exports, "GraphQLDictionaryService", { enumerable: true, get: function () { return graphql_dictionary_service_1.GraphQLDictionaryService; } });
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// NOTE: all imports are now named as to not make breaking changes
|
|
3
|
+
// and to keep react-native working with cjs modules.
|
|
4
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
5
|
+
if (k2 === undefined) k2 = k;
|
|
6
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
7
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
8
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
9
|
+
}
|
|
10
|
+
Object.defineProperty(o, k2, desc);
|
|
11
|
+
}) : (function(o, m, k, k2) {
|
|
12
|
+
if (k2 === undefined) k2 = k;
|
|
13
|
+
o[k2] = m[k];
|
|
14
|
+
}));
|
|
15
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
16
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
17
|
+
}) : function(o, v) {
|
|
18
|
+
o["default"] = v;
|
|
19
|
+
});
|
|
20
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
21
|
+
var ownKeys = function(o) {
|
|
22
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
23
|
+
var ar = [];
|
|
24
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
25
|
+
return ar;
|
|
26
|
+
};
|
|
27
|
+
return ownKeys(o);
|
|
28
|
+
};
|
|
29
|
+
return function (mod) {
|
|
30
|
+
if (mod && mod.__esModule) return mod;
|
|
31
|
+
var result = {};
|
|
32
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
33
|
+
__setModuleDefault(result, mod);
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
})();
|
|
37
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
38
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
39
|
+
};
|
|
40
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
41
|
+
exports.constants = exports.NativeDataFetcher = exports.ClientError = exports.MemoryCacheClient = exports.GraphQLRequestClient = exports.DefaultRetryStrategy = exports.enableDebug = exports.debug = void 0;
|
|
42
|
+
const constants = __importStar(require("./constants"));
|
|
43
|
+
exports.constants = constants;
|
|
44
|
+
var debug_1 = require("./debug");
|
|
45
|
+
Object.defineProperty(exports, "debug", { enumerable: true, get: function () { return __importDefault(debug_1).default; } });
|
|
46
|
+
Object.defineProperty(exports, "enableDebug", { enumerable: true, get: function () { return debug_1.enableDebug; } });
|
|
47
|
+
var graphql_request_client_1 = require("./graphql-request-client");
|
|
48
|
+
Object.defineProperty(exports, "DefaultRetryStrategy", { enumerable: true, get: function () { return graphql_request_client_1.DefaultRetryStrategy; } });
|
|
49
|
+
Object.defineProperty(exports, "GraphQLRequestClient", { enumerable: true, get: function () { return graphql_request_client_1.GraphQLRequestClient; } });
|
|
50
|
+
var cache_client_1 = require("./cache-client");
|
|
51
|
+
Object.defineProperty(exports, "MemoryCacheClient", { enumerable: true, get: function () { return cache_client_1.MemoryCacheClient; } });
|
|
52
|
+
var graphql_request_1 = require("graphql-request");
|
|
53
|
+
Object.defineProperty(exports, "ClientError", { enumerable: true, get: function () { return graphql_request_1.ClientError; } });
|
|
54
|
+
var native_fetcher_1 = require("./native-fetcher");
|
|
55
|
+
Object.defineProperty(exports, "NativeDataFetcher", { enumerable: true, get: function () { return native_fetcher_1.NativeDataFetcher; } });
|
|
@@ -0,0 +1,70 @@
|
|
|
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 constants_1 = require("../constants");
|
|
5
|
+
/**
|
|
6
|
+
* Regular expression to check if the content styles are used in the field value
|
|
7
|
+
*/
|
|
8
|
+
const CLASS_REGEXP = /class=".*(\bck-content\b).*"/g;
|
|
9
|
+
/**
|
|
10
|
+
* Get the content styles link to be loaded from the Sitecore Edge Platform
|
|
11
|
+
* @param {LayoutServiceData} layoutData Layout service data
|
|
12
|
+
* @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
|
|
13
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
14
|
+
* @returns {HTMLLink | null} content styles link, null if no styles are used in layout
|
|
15
|
+
*/
|
|
16
|
+
const getContentStylesheetLink = (layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => {
|
|
17
|
+
if (!layoutData.sitecore.route)
|
|
18
|
+
return null;
|
|
19
|
+
const config = { loadStyles: false };
|
|
20
|
+
(0, exports.traverseComponent)(layoutData.sitecore.route, config);
|
|
21
|
+
if (!config.loadStyles)
|
|
22
|
+
return null;
|
|
23
|
+
return {
|
|
24
|
+
href: (0, exports.getContentStylesheetUrl)(sitecoreEdgeContextId, sitecoreEdgeUrl),
|
|
25
|
+
rel: 'stylesheet',
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
exports.getContentStylesheetLink = getContentStylesheetLink;
|
|
29
|
+
const getContentStylesheetUrl = (sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => `${sitecoreEdgeUrl}/v1/files/pages/styles/content-styles.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
30
|
+
exports.getContentStylesheetUrl = getContentStylesheetUrl;
|
|
31
|
+
const traversePlaceholder = (components, config) => {
|
|
32
|
+
if (config.loadStyles)
|
|
33
|
+
return;
|
|
34
|
+
components.forEach((component) => {
|
|
35
|
+
(0, exports.traverseComponent)(component, config);
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.traversePlaceholder = traversePlaceholder;
|
|
39
|
+
const traverseField = (field, config) => {
|
|
40
|
+
if (!field || config.loadStyles)
|
|
41
|
+
return;
|
|
42
|
+
if ('value' in field && typeof field.value === 'string') {
|
|
43
|
+
config.loadStyles = CLASS_REGEXP.test(field.value);
|
|
44
|
+
}
|
|
45
|
+
else if ('fields' in field) {
|
|
46
|
+
Object.values(field.fields).forEach((field) => {
|
|
47
|
+
(0, exports.traverseField)(field, config);
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
else if (Array.isArray(field)) {
|
|
51
|
+
field.forEach((field) => {
|
|
52
|
+
(0, exports.traverseField)(field, config);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.traverseField = traverseField;
|
|
57
|
+
const traverseComponent = (component, config) => {
|
|
58
|
+
if (config.loadStyles)
|
|
59
|
+
return;
|
|
60
|
+
if ('fields' in component && component.fields) {
|
|
61
|
+
Object.values(component.fields).forEach((field) => {
|
|
62
|
+
(0, exports.traverseField)(field, config);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
const placeholders = component.placeholders || {};
|
|
66
|
+
Object.keys(placeholders).forEach((placeholder) => {
|
|
67
|
+
(0, exports.traversePlaceholder)(placeholders[placeholder], config);
|
|
68
|
+
});
|
|
69
|
+
};
|
|
70
|
+
exports.traverseComponent = traverseComponent;
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.GraphQLLayoutService = exports.GRAPHQL_LAYOUT_QUERY_NAME = void 0;
|
|
16
|
+
const layout_service_1 = require("./layout-service");
|
|
17
|
+
const debug_1 = __importDefault(require("../debug"));
|
|
18
|
+
exports.GRAPHQL_LAYOUT_QUERY_NAME = 'JssLayoutQuery';
|
|
19
|
+
/**
|
|
20
|
+
* Service that fetch layout data using Sitecore's GraphQL API.
|
|
21
|
+
* @augments LayoutServiceBase
|
|
22
|
+
* @mixes GraphQLRequestClient
|
|
23
|
+
*/
|
|
24
|
+
class GraphQLLayoutService extends layout_service_1.LayoutServiceBase {
|
|
25
|
+
/**
|
|
26
|
+
* Fetch layout data using the Sitecore GraphQL endpoint.
|
|
27
|
+
* @param {GraphQLLayoutServiceConfig} serviceConfig configuration
|
|
28
|
+
*/
|
|
29
|
+
constructor(serviceConfig) {
|
|
30
|
+
super();
|
|
31
|
+
this.serviceConfig = serviceConfig;
|
|
32
|
+
this.graphQLClient = this.getGraphQLClient();
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Fetch layout data for an item.
|
|
36
|
+
* @param {string} itemPath item path to fetch layout data for.
|
|
37
|
+
* @param {string} [language] the language to fetch layout data for.
|
|
38
|
+
* @returns {Promise<LayoutServiceData>} layout service data
|
|
39
|
+
*/
|
|
40
|
+
fetchLayoutData(itemPath, language) {
|
|
41
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
42
|
+
var _a, _b;
|
|
43
|
+
const query = this.getLayoutQuery(itemPath, language);
|
|
44
|
+
debug_1.default.layout('fetching layout data for %s %s %s', itemPath, language, this.serviceConfig.siteName);
|
|
45
|
+
const data = yield this.graphQLClient.request(query);
|
|
46
|
+
// If `rendered` is empty -> not found
|
|
47
|
+
return (((_b = (_a = data === null || data === void 0 ? void 0 : data.layout) === null || _a === void 0 ? void 0 : _a.item) === null || _b === void 0 ? void 0 : _b.rendered) || {
|
|
48
|
+
sitecore: { context: { pageEditing: false, language }, route: null },
|
|
49
|
+
});
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets a GraphQL client that can make requests to the API.
|
|
54
|
+
* @returns {GraphQLClient} implementation
|
|
55
|
+
*/
|
|
56
|
+
getGraphQLClient() {
|
|
57
|
+
if (!this.serviceConfig.clientFactory) {
|
|
58
|
+
throw new Error('clientFactory needs to be provided when initializing GraphQL client.');
|
|
59
|
+
}
|
|
60
|
+
return this.serviceConfig.clientFactory({
|
|
61
|
+
debugger: debug_1.default.layout,
|
|
62
|
+
retries: this.serviceConfig.retries,
|
|
63
|
+
retryStrategy: this.serviceConfig.retryStrategy,
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Returns GraphQL Layout query
|
|
68
|
+
* @param {string} itemPath page route
|
|
69
|
+
* @param {string} [language] language
|
|
70
|
+
* @returns {string} GraphQL query
|
|
71
|
+
*/
|
|
72
|
+
getLayoutQuery(itemPath, language) {
|
|
73
|
+
const languageVariable = language ? `, language:"${language}"` : '';
|
|
74
|
+
const layoutQuery = this.serviceConfig.formatLayoutQuery
|
|
75
|
+
? this.serviceConfig.formatLayoutQuery(this.serviceConfig.siteName, itemPath, language)
|
|
76
|
+
: `layout(site:"${this.serviceConfig.siteName}", routePath:"${itemPath}"${languageVariable})`;
|
|
77
|
+
return `query ${exports.GRAPHQL_LAYOUT_QUERY_NAME} {
|
|
78
|
+
${layoutQuery}{
|
|
79
|
+
item {
|
|
80
|
+
rendered
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}`;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.GraphQLLayoutService = GraphQLLayoutService;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getComponentLibraryStylesheetLinks = exports.GRAPHQL_LAYOUT_QUERY_NAME = exports.GraphQLLayoutService = exports.getContentStylesheetLink = exports.EMPTY_DATE_FIELD_VALUE = exports.getDynamicPlaceholderPattern = exports.isDynamicPlaceholder = exports.isFieldValueEmpty = exports.getChildPlaceholder = exports.getFieldValue = exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.EditMode = exports.LayoutServicePageState = void 0;
|
|
4
|
+
// layout
|
|
5
|
+
var models_1 = require("./models");
|
|
6
|
+
Object.defineProperty(exports, "LayoutServicePageState", { enumerable: true, get: function () { return models_1.LayoutServicePageState; } });
|
|
7
|
+
Object.defineProperty(exports, "EditMode", { enumerable: true, get: function () { return models_1.EditMode; } });
|
|
8
|
+
Object.defineProperty(exports, "RenderingType", { enumerable: true, get: function () { return models_1.RenderingType; } });
|
|
9
|
+
Object.defineProperty(exports, "EDITING_COMPONENT_PLACEHOLDER", { enumerable: true, get: function () { return models_1.EDITING_COMPONENT_PLACEHOLDER; } });
|
|
10
|
+
Object.defineProperty(exports, "EDITING_COMPONENT_ID", { enumerable: true, get: function () { return models_1.EDITING_COMPONENT_ID; } });
|
|
11
|
+
var utils_1 = require("./utils");
|
|
12
|
+
Object.defineProperty(exports, "getFieldValue", { enumerable: true, get: function () { return utils_1.getFieldValue; } });
|
|
13
|
+
Object.defineProperty(exports, "getChildPlaceholder", { enumerable: true, get: function () { return utils_1.getChildPlaceholder; } });
|
|
14
|
+
Object.defineProperty(exports, "isFieldValueEmpty", { enumerable: true, get: function () { return utils_1.isFieldValueEmpty; } });
|
|
15
|
+
Object.defineProperty(exports, "isDynamicPlaceholder", { enumerable: true, get: function () { return utils_1.isDynamicPlaceholder; } });
|
|
16
|
+
Object.defineProperty(exports, "getDynamicPlaceholderPattern", { enumerable: true, get: function () { return utils_1.getDynamicPlaceholderPattern; } });
|
|
17
|
+
Object.defineProperty(exports, "EMPTY_DATE_FIELD_VALUE", { enumerable: true, get: function () { return utils_1.EMPTY_DATE_FIELD_VALUE; } });
|
|
18
|
+
var content_styles_1 = require("./content-styles");
|
|
19
|
+
Object.defineProperty(exports, "getContentStylesheetLink", { enumerable: true, get: function () { return content_styles_1.getContentStylesheetLink; } });
|
|
20
|
+
var graphql_layout_service_1 = require("./graphql-layout-service");
|
|
21
|
+
Object.defineProperty(exports, "GraphQLLayoutService", { enumerable: true, get: function () { return graphql_layout_service_1.GraphQLLayoutService; } });
|
|
22
|
+
Object.defineProperty(exports, "GRAPHQL_LAYOUT_QUERY_NAME", { enumerable: true, get: function () { return graphql_layout_service_1.GRAPHQL_LAYOUT_QUERY_NAME; } });
|
|
23
|
+
var themes_1 = require("./themes");
|
|
24
|
+
Object.defineProperty(exports, "getComponentLibraryStylesheetLinks", { enumerable: true, get: function () { return themes_1.getComponentLibraryStylesheetLinks; } });
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.LayoutServiceBase = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Base abstraction to implement custom layout service
|
|
6
|
+
*/
|
|
7
|
+
class LayoutServiceBase {
|
|
8
|
+
}
|
|
9
|
+
exports.LayoutServiceBase = LayoutServiceBase;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EDITING_COMPONENT_ID = exports.EDITING_COMPONENT_PLACEHOLDER = exports.RenderingType = exports.EditMode = exports.LayoutServicePageState = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* Layout Service page state enum
|
|
6
|
+
* library mode would render a single component
|
|
7
|
+
*/
|
|
8
|
+
var LayoutServicePageState;
|
|
9
|
+
(function (LayoutServicePageState) {
|
|
10
|
+
LayoutServicePageState["Preview"] = "preview";
|
|
11
|
+
LayoutServicePageState["Edit"] = "edit";
|
|
12
|
+
LayoutServicePageState["Normal"] = "normal";
|
|
13
|
+
})(LayoutServicePageState || (exports.LayoutServicePageState = LayoutServicePageState = {}));
|
|
14
|
+
/**
|
|
15
|
+
* Represents the edit mode for rendering content in Sitecore Editors
|
|
16
|
+
*/
|
|
17
|
+
var EditMode;
|
|
18
|
+
(function (EditMode) {
|
|
19
|
+
EditMode["Metadata"] = "metadata";
|
|
20
|
+
})(EditMode || (exports.EditMode = EditMode = {}));
|
|
21
|
+
/**
|
|
22
|
+
* Editing rendering type
|
|
23
|
+
*/
|
|
24
|
+
var RenderingType;
|
|
25
|
+
(function (RenderingType) {
|
|
26
|
+
RenderingType["Component"] = "component";
|
|
27
|
+
})(RenderingType || (exports.RenderingType = RenderingType = {}));
|
|
28
|
+
/**
|
|
29
|
+
* Static placeholder name used for component rendering
|
|
30
|
+
*/
|
|
31
|
+
exports.EDITING_COMPONENT_PLACEHOLDER = 'editing-componentmode-placeholder';
|
|
32
|
+
/**
|
|
33
|
+
* Id of wrapper for component rendering
|
|
34
|
+
*/
|
|
35
|
+
exports.EDITING_COMPONENT_ID = 'editing-component';
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getStylesheetUrl = void 0;
|
|
4
|
+
exports.getComponentLibraryStylesheetLinks = getComponentLibraryStylesheetLinks;
|
|
5
|
+
const _1 = require(".");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
/**
|
|
8
|
+
* Pattern for library ids
|
|
9
|
+
* @example -library--foo
|
|
10
|
+
*/
|
|
11
|
+
const STYLES_LIBRARY_ID_REGEX = /-library--([^\s]+)/;
|
|
12
|
+
/**
|
|
13
|
+
* Walks through rendering tree and returns list of links of all FEAAS, BYOC or SXA Component Library Stylesheets that are used
|
|
14
|
+
* @param {LayoutServiceData} layoutData Layout service data
|
|
15
|
+
* @param {string} sitecoreEdgeContextId Sitecore Edge Context ID
|
|
16
|
+
* @param {string} [sitecoreEdgeUrl] Sitecore Edge Platform URL. Default is https://edge-platform.sitecorecloud.io
|
|
17
|
+
* @returns {HTMLLink[]} library stylesheet links
|
|
18
|
+
*/
|
|
19
|
+
function getComponentLibraryStylesheetLinks(layoutData, sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) {
|
|
20
|
+
const ids = new Set();
|
|
21
|
+
if (!layoutData.sitecore.route)
|
|
22
|
+
return [];
|
|
23
|
+
traverseComponent(layoutData.sitecore.route, ids);
|
|
24
|
+
return [...ids].map((id) => ({
|
|
25
|
+
href: (0, exports.getStylesheetUrl)(id, sitecoreEdgeContextId, sitecoreEdgeUrl),
|
|
26
|
+
rel: 'stylesheet',
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
const getStylesheetUrl = (id, sitecoreEdgeContextId, sitecoreEdgeUrl = constants_1.SITECORE_EDGE_URL_DEFAULT) => {
|
|
30
|
+
return `${sitecoreEdgeUrl}/v1/files/components/styles/${id}.css?sitecoreContextId=${sitecoreEdgeContextId}`;
|
|
31
|
+
};
|
|
32
|
+
exports.getStylesheetUrl = getStylesheetUrl;
|
|
33
|
+
/**
|
|
34
|
+
* Traverse placeholder and components to add library ids
|
|
35
|
+
* @param {ComponentRendering[]} components
|
|
36
|
+
* @param {Set<string>} ids library ids
|
|
37
|
+
*/
|
|
38
|
+
const traversePlaceholder = (components, ids) => {
|
|
39
|
+
components.map((component) => {
|
|
40
|
+
return traverseComponent(component, ids);
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* Traverse component and children to add library ids
|
|
45
|
+
* @param {RouteData | ComponentRendering | HtmlElementRendering} component component data
|
|
46
|
+
* @param {Set<string>} ids library ids
|
|
47
|
+
*/
|
|
48
|
+
const traverseComponent = (component, ids) => {
|
|
49
|
+
var _a, _b, _c, _d, _e, _f;
|
|
50
|
+
let libraryId = undefined;
|
|
51
|
+
if ('params' in component && component.params) {
|
|
52
|
+
// LibraryID in css class name takes precedence over LibraryId attribute
|
|
53
|
+
libraryId =
|
|
54
|
+
((_b = (_a = component.params.CSSStyles) === null || _a === void 0 ? void 0 : _a.match(STYLES_LIBRARY_ID_REGEX)) === null || _b === void 0 ? void 0 : _b[1]) ||
|
|
55
|
+
((_d = (_c = component.params.Styles) === null || _c === void 0 ? void 0 : _c.match(STYLES_LIBRARY_ID_REGEX)) === null || _d === void 0 ? void 0 : _d[1]) ||
|
|
56
|
+
component.params.LibraryId ||
|
|
57
|
+
undefined;
|
|
58
|
+
}
|
|
59
|
+
// if params are empty we try to fall back to data source
|
|
60
|
+
if (!libraryId && 'fields' in component && component.fields) {
|
|
61
|
+
libraryId =
|
|
62
|
+
((_e = (0, _1.getFieldValue)(component.fields, 'CSSStyles', '').match(STYLES_LIBRARY_ID_REGEX)) === null || _e === void 0 ? void 0 : _e[1]) ||
|
|
63
|
+
((_f = (0, _1.getFieldValue)(component.fields, 'Styles', '').match(STYLES_LIBRARY_ID_REGEX)) === null || _f === void 0 ? void 0 : _f[1]) ||
|
|
64
|
+
(0, _1.getFieldValue)(component.fields, 'LibraryId', '') ||
|
|
65
|
+
undefined;
|
|
66
|
+
}
|
|
67
|
+
if (libraryId) {
|
|
68
|
+
ids.add(libraryId);
|
|
69
|
+
}
|
|
70
|
+
const placeholders = component.placeholders || {};
|
|
71
|
+
Object.keys(placeholders).forEach((placeholder) => {
|
|
72
|
+
traversePlaceholder(placeholders[placeholder], ids);
|
|
73
|
+
});
|
|
74
|
+
};
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.EMPTY_DATE_FIELD_VALUE = exports.isDynamicPlaceholder = exports.getDynamicPlaceholderPattern = void 0;
|
|
4
|
+
exports.getFieldValue = getFieldValue;
|
|
5
|
+
exports.getChildPlaceholder = getChildPlaceholder;
|
|
6
|
+
exports.isFieldValueEmpty = isFieldValueEmpty;
|
|
7
|
+
/**
|
|
8
|
+
* @param {ComponentRendering | Fields} renderingOrFields the rendering or fields object to extract the field from
|
|
9
|
+
* @param {string} fieldName the name of the field to extract
|
|
10
|
+
* @param {T} [defaultValue] the default value to return if the field is not defined
|
|
11
|
+
* @returns {Field | T} the field value or the default value if the field is not defined
|
|
12
|
+
*/
|
|
13
|
+
// eslint-disable-next-line no-redeclare
|
|
14
|
+
function getFieldValue(renderingOrFields, fieldName, defaultValue) {
|
|
15
|
+
if (!renderingOrFields || !fieldName) {
|
|
16
|
+
return defaultValue;
|
|
17
|
+
}
|
|
18
|
+
const fields = renderingOrFields;
|
|
19
|
+
const field = fields[fieldName];
|
|
20
|
+
if (field && typeof field.value !== 'undefined') {
|
|
21
|
+
return field.value;
|
|
22
|
+
}
|
|
23
|
+
const rendering = renderingOrFields;
|
|
24
|
+
if (!rendering.fields ||
|
|
25
|
+
!rendering.fields[fieldName] ||
|
|
26
|
+
typeof rendering.fields[fieldName].value === 'undefined') {
|
|
27
|
+
return defaultValue;
|
|
28
|
+
}
|
|
29
|
+
return rendering.fields[fieldName].value;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Gets rendering definitions in a given child placeholder under a current rendering.
|
|
33
|
+
* @param {ComponentRendering} rendering
|
|
34
|
+
* @param {string} placeholderName
|
|
35
|
+
* @returns {ComponentRendering[]} child placeholder
|
|
36
|
+
*/
|
|
37
|
+
function getChildPlaceholder(rendering, placeholderName) {
|
|
38
|
+
if (!rendering ||
|
|
39
|
+
!placeholderName ||
|
|
40
|
+
!rendering.placeholders ||
|
|
41
|
+
!rendering.placeholders[placeholderName]) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
return rendering.placeholders[placeholderName];
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Returns a regular expression pattern for a dynamic placeholder name.
|
|
48
|
+
* @param {string} placeholder Placeholder name with a dynamic segment (e.g. 'main-{*}')
|
|
49
|
+
* @returns Regular expression pattern for the dynamic segment
|
|
50
|
+
*/
|
|
51
|
+
const getDynamicPlaceholderPattern = (placeholder) => {
|
|
52
|
+
return new RegExp(`^${placeholder.replace(/\{\*\}+/i, '\\d+')}$`);
|
|
53
|
+
};
|
|
54
|
+
exports.getDynamicPlaceholderPattern = getDynamicPlaceholderPattern;
|
|
55
|
+
/**
|
|
56
|
+
* Checks if the placeholder name is dynamic.
|
|
57
|
+
* @param {string} placeholder Placeholder name
|
|
58
|
+
* @returns True if the placeholder name is dynamic
|
|
59
|
+
*/
|
|
60
|
+
const isDynamicPlaceholder = (placeholder) => placeholder.indexOf('{*}') !== -1;
|
|
61
|
+
exports.isDynamicPlaceholder = isDynamicPlaceholder;
|
|
62
|
+
/**
|
|
63
|
+
* The default value for an empty Date field.
|
|
64
|
+
* This value is defined as a default one by .NET
|
|
65
|
+
*/
|
|
66
|
+
exports.EMPTY_DATE_FIELD_VALUE = '0001-01-01T00:00:00Z';
|
|
67
|
+
/**
|
|
68
|
+
* Determines if the passed in field object's value is empty.
|
|
69
|
+
* @param {GenericFieldValue | Partial<Field>} field the field object.
|
|
70
|
+
* Partial<T> type is used here because _field.value_ could be required or optional for the different field types
|
|
71
|
+
*/
|
|
72
|
+
function isFieldValueEmpty(field) {
|
|
73
|
+
const isImageFieldEmpty = (fieldValue) => !fieldValue.src;
|
|
74
|
+
const isFileFieldEmpty = (fieldValue) => !fieldValue.src;
|
|
75
|
+
const isLinkFieldEmpty = (fieldValue) => !fieldValue.href;
|
|
76
|
+
const isDateFieldEmpty = (fieldValue) => {
|
|
77
|
+
if (typeof fieldValue === 'string') {
|
|
78
|
+
return fieldValue === exports.EMPTY_DATE_FIELD_VALUE;
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
return !(typeof (fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getMonth) === 'function' &&
|
|
82
|
+
!isNaN(fieldValue === null || fieldValue === void 0 ? void 0 : fieldValue.getMonth()));
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
const isEmpty = (fieldValue) => {
|
|
86
|
+
if (fieldValue === null || fieldValue === undefined) {
|
|
87
|
+
return true;
|
|
88
|
+
}
|
|
89
|
+
if (typeof fieldValue === 'object') {
|
|
90
|
+
return (isImageFieldEmpty(fieldValue) &&
|
|
91
|
+
isFileFieldEmpty(fieldValue) &&
|
|
92
|
+
isLinkFieldEmpty(fieldValue) &&
|
|
93
|
+
isDateFieldEmpty(fieldValue));
|
|
94
|
+
}
|
|
95
|
+
else if (typeof fieldValue === 'number' || typeof fieldValue === 'boolean') {
|
|
96
|
+
// Avoid returning true for 0 and false values
|
|
97
|
+
return false;
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
return !fieldValue || isDateFieldEmpty(fieldValue);
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
if (!field)
|
|
104
|
+
return true;
|
|
105
|
+
const dynamicField = field;
|
|
106
|
+
if (dynamicField.value !== undefined) {
|
|
107
|
+
return isEmpty(dynamicField.value);
|
|
108
|
+
}
|
|
109
|
+
return isEmpty(field);
|
|
110
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.mediaApi = void 0;
|
|
37
|
+
const mediaApi = __importStar(require("./media-api"));
|
|
38
|
+
exports.mediaApi = mediaApi;
|