@qrvey/widget-configurability 0.0.0-beta.4589 → 0.0.0-beta.4684

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.
Files changed (48) hide show
  1. package/README.md +75 -0
  2. package/dist/cjs/index.js +12 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/metadata/customization-docs.js +200 -0
  5. package/dist/cjs/metadata/customization-docs.js.map +1 -0
  6. package/dist/cjs/metadata/customization-metadata.js +297 -0
  7. package/dist/cjs/metadata/customization-metadata.js.map +1 -0
  8. package/dist/cjs/metadata/index.js +14 -0
  9. package/dist/cjs/metadata/index.js.map +1 -0
  10. package/dist/cjs/metadata/labels/chart-panel.defaults.js +15 -0
  11. package/dist/cjs/metadata/labels/chart-panel.defaults.js.map +1 -0
  12. package/dist/cjs/metadata/labels/chart-panel.labels.js +469 -0
  13. package/dist/cjs/metadata/labels/chart-panel.labels.js.map +1 -0
  14. package/dist/cjs/metadata/labels/dashboard.defaults.js +441 -0
  15. package/dist/cjs/metadata/labels/dashboard.defaults.js.map +1 -0
  16. package/dist/cjs/metadata/labels/dashboard.labels.js +1086 -0
  17. package/dist/cjs/metadata/labels/dashboard.labels.js.map +1 -0
  18. package/dist/cjs/metadata/labels/submodule.labels.js +11 -0
  19. package/dist/cjs/metadata/labels/submodule.labels.js.map +1 -0
  20. package/dist/cjs/metadata/metadata.models.js +3 -0
  21. package/dist/cjs/metadata/metadata.models.js.map +1 -0
  22. package/dist/cjs/models/remote.models.js +3 -0
  23. package/dist/cjs/models/remote.models.js.map +1 -0
  24. package/dist/cjs/models/validation.models.js +3 -0
  25. package/dist/cjs/models/validation.models.js.map +1 -0
  26. package/dist/cjs/remote/remote-customization.loader.js +213 -0
  27. package/dist/cjs/remote/remote-customization.loader.js.map +1 -0
  28. package/dist/cjs/structural-manager.js +35 -2
  29. package/dist/cjs/structural-manager.js.map +1 -1
  30. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  31. package/dist/cjs/utils/defaults.helpers.js +3 -0
  32. package/dist/cjs/utils/defaults.helpers.js.map +1 -1
  33. package/dist/cjs/utils/layers.helpers.js +178 -0
  34. package/dist/cjs/utils/layers.helpers.js.map +1 -0
  35. package/dist/cjs/utils/logger.helpers.js +10 -0
  36. package/dist/cjs/utils/logger.helpers.js.map +1 -0
  37. package/dist/cjs/utils/scope.helpers.js +4 -1
  38. package/dist/cjs/utils/scope.helpers.js.map +1 -1
  39. package/dist/cjs/validation/customization.validator.js +366 -0
  40. package/dist/cjs/validation/customization.validator.js.map +1 -0
  41. package/dist/esm/index.mjs +846 -28
  42. package/dist/esm/index.mjs.map +1 -1
  43. package/dist/esm/metadata.mjs +4539 -0
  44. package/dist/esm/metadata.mjs.map +1 -0
  45. package/dist/types/index.d.ts +97 -88
  46. package/dist/types/metadata.d.ts +125 -0
  47. package/dist/types/structure.models-BqVB4VLP.d.ts +89 -0
  48. package/package.json +7 -1
package/README.md CHANGED
@@ -117,11 +117,85 @@ function buildStructure(
117
117
  widget: Widget,
118
118
  customization?: WidgetCustomization,
119
119
  version?: WidgetVersion,
120
+ options?: BuildStructureOptions,
120
121
  ): WidgetStructureInstance
121
122
  ```
122
123
 
123
124
  Throws an error if no matching configuration is found.
124
125
 
126
+ `options.layers` applies stored customizations before `customization`, in order, each over what the previous
127
+ one left: nothing removed by an earlier layer can come back, a `keep` of keys already removed empties its
128
+ level, and defaults merge by leaf key with the last layer winning. Without layers the result is unchanged.
129
+
130
+ ```ts
131
+ const result = await loadRemoteCustomization({ widget: 'dashboard', customizationId, domain, qvToken });
132
+ if (result.status === 'error') showConfigurationError();
133
+ const structure = buildStructure(Widget.DASHBOARD, inlineCustomization, undefined, {
134
+ layers: remoteCustomizationLayers(result),
135
+ });
136
+ ```
137
+
138
+ ### `loadRemoteCustomization`
139
+
140
+ Resolves the stored definition a widget uses as its base, falling back to `default` when the requested one does
141
+ not exist. It calls admin_api_manager: `GET /api/admin/v5/customizations/widgets/{widget}/{id}` or
142
+ `GET /api/admin/v5/customizations/widgets/{widget}?context=`. Returns
143
+ `{ status: 'found' | 'fallback' | 'none' | 'error', definition?, error? }`. A 404 means "not found" whatever its
144
+ body says; other error bodies are not read, only their status is reported. One request per URL is shared for
145
+ the life of the page. It uses the global `fetch`, sends `Authorization: Bearer` and/or `x-api-key` only to the
146
+ configured domain and never logs them.
147
+
148
+ ### Customization metadata (`@qrvey/widget-configurability/metadata`)
149
+
150
+ A separate entry point, so widgets do not ship the labels. Admin Center builds its switch tree from it:
151
+
152
+ - `getCustomizationTree(widget, { views, subModules? })`: the labelled tree of a view, or of the embedded widget
153
+ (`subModules: ['chartPanel']`), derived from the structure, so a new key appears and a removed one disappears.
154
+ - `getCustomizationTreeState(widget, customization, target)`: the same tree with `visible: true | false | 'mixed'`
155
+ per node, computed with the engine, and `lockedBy` on hidden nodes a switch cannot bring back (a keep, a wildcard,
156
+ a root verb, a hidden parent).
157
+ - `toggleCustomizationKey(customization, target, key, visible)`: the minimal change for one switch, in the remove
158
+ list of each target view (or of its submodule); it never touches keep, conditional, defaults or root verbs.
159
+
160
+ Labels are English only, looked up by full key path and then by leaf id; a guard spec fails when a key has no label
161
+ or a label names no key. A label may also carry `description`, `since` ('9.0', '9.2.PR.4'), `notes` and
162
+ `audience: 'partner' | 'internal'` (partner when absent), seeded from the DX Widget Config sheet (RB-7258).
163
+
164
+ The same entry generates the customization docs the sheet used to hold:
165
+
166
+ - `getCustomizationDocs(widget, options?)`: one flat entry per key per scope, each view (`design`) and each submodule
167
+ of the view (`design::chartPanel`), with `key`, `scope`, `parent`, `kind`, `label`, `description`, `since`, `notes`,
168
+ `audience` and the `defaults` the key owns. `options.views` and `options.subModules` filter the scopes.
169
+ - `getCustomizationDefaultDocs(widget, options?)`: every documented default with name, type, accepted values,
170
+ example and the key it belongs to (`null` for the ones that apply to the whole widget, like `customStyles`).
171
+
172
+ Both, and `getCustomizationTree`, read the structure in `options.structure` (and `options.subModuleStructures` by
173
+ submodule name) instead of the one this package ships, so a host can document the tree its release runs with:
174
+
175
+ ```ts
176
+ import { getWidgetConfig, Widget } from '@qrvey/widget-configurability';
177
+ import { getCustomizationDocs } from '@qrvey/widget-configurability/metadata';
178
+
179
+ const entries = getCustomizationDocs(Widget.DASHBOARD, {
180
+ structure: getWidgetConfig(Widget.DASHBOARD),
181
+ subModuleStructures: { chartPanel: getWidgetConfig(Widget.CHART_PANEL) },
182
+ });
183
+ ```
184
+
185
+ ### `validateCustomization`
186
+
187
+ Strict validation for writes (admin_api_manager and Admin Center use the same function):
188
+
189
+ ```ts
190
+ validateCustomization('dashboard', { views: { design: { remove: ['menuBar.file.qMnuDeleteDsh'] } } });
191
+ // { valid: false, errors: [{ path: ['views', 'design', 'remove', 0], code: 'UNKNOWN_KEY', severity: 'error',
192
+ // message: "Key 'menuBar.file.qMnuDeleteDsh' does not exist in the design view",
193
+ // suggestion: 'menuBar.file.qMnuDeleteDash' }] }
194
+ ```
195
+
196
+ At runtime nothing throws: unknown keys are ignored. A customization hides UI; it is not an authorization
197
+ mechanism.
198
+
125
199
  ---
126
200
 
127
201
  ### `WidgetStructureInstance`
@@ -133,6 +207,7 @@ Class that wraps a widget’s “view map” and provides helper methods:
133
207
  | `isVisible(key: string, state?: ConditionState): boolean` | Returns `true` if the key exists and its conditions (if any) are met |
134
208
  | `getChildMap(key: string): WidgetViewMap \| undefined` | If the key has a nested `childMap`, returns it; otherwise `undefined` |
135
209
  | `getSubmodule(module: string, view?: string): WidgetCustomization \| undefined` | Retrieves a specific sub-module customization under `subModules` |
210
+ | `getSubmoduleLayers(module: string, view?: string)` | Submodule customizations of the stored layers (`structureFromSubmodule` applies them) |
136
211
  | `getDefaults(key: string): Record<string, unknown> \| undefined` | Retrieves default settings for a given key (e.g. `assetList.defaults`) |
137
212
 
138
213
  ---
package/dist/cjs/index.js CHANGED
@@ -33,7 +33,7 @@ var __importStar = (this && this.__importStar) || (function () {
33
33
  };
34
34
  })();
35
35
  Object.defineProperty(exports, "__esModule", { value: true });
36
- exports.DashboardDoc = exports.hostKeepInheritance = exports.DOWNLOAD_MODAL_V1_KEYS = exports.DOWNLOAD_MODAL_V1_DEFAULTS = exports.structureFromSubmodule = exports.structureFrom = exports.scopeToCustomization = exports.isWidgetStructureScope = exports.extractCustomization = exports.validateDefaults = exports.validateBoolean = exports.DX_VALIDATOR_MAP = exports.DOWNLOAD_MODAL_VALIDATOR_MAP = exports.evaluateCondition = exports.checkConditions = exports.getWidgetStructure = exports.calculateViewMap = exports.calculateRootDefaults = exports.WIDGET_SUBMODULE_NAMES = exports.WIDGET_STRUCTURE_SCOPE_KIND = exports.WIDGET_STRUCTURE_SCOPE_FORMAT = exports.Widget = exports.getWidgetConfig = exports.buildStructure = exports.WidgetStructureInstance = exports.WidgetVersion = void 0;
36
+ exports.DashboardDoc = exports.remoteCustomizationLayers = exports.loadRemoteCustomization = exports.isValidCustomizationId = exports.clearRemoteCustomizationCache = exports.DEFAULT_CUSTOMIZATION_ID = exports.CUSTOMIZATIONS_API_PATH = exports.validateCustomization = exports.isEmptyCustomization = exports.formatCustomizationPath = exports.hostKeepInheritance = exports.DOWNLOAD_MODAL_V1_KEYS = exports.DOWNLOAD_MODAL_V1_DEFAULTS = exports.structureFromSubmodule = exports.structureFrom = exports.scopeToCustomization = exports.isWidgetStructureScope = exports.extractCustomization = exports.validateDefaults = exports.validateBoolean = exports.DX_VALIDATOR_MAP = exports.DOWNLOAD_MODAL_VALIDATOR_MAP = exports.evaluateCondition = exports.checkConditions = exports.getWidgetStructure = exports.calculateViewMap = exports.calculateRootDefaults = exports.WIDGET_SUBMODULE_NAMES = exports.WIDGET_STRUCTURE_SCOPE_KIND = exports.WIDGET_STRUCTURE_SCOPE_FORMAT = exports.Widget = exports.getWidgetConfig = exports.buildStructure = exports.WidgetStructureInstance = exports.WidgetVersion = void 0;
37
37
  const structure_constants_1 = require("./constants/structure.constants");
38
38
  Object.defineProperty(exports, "WidgetVersion", { enumerable: true, get: function () { return structure_constants_1.WidgetVersion; } });
39
39
  var structural_manager_1 = require("./structural-manager");
@@ -67,5 +67,16 @@ var download_modal_structure_v1_1 = require("./structures/download-modal.structu
67
67
  Object.defineProperty(exports, "DOWNLOAD_MODAL_V1_DEFAULTS", { enumerable: true, get: function () { return download_modal_structure_v1_1.DOWNLOAD_MODAL_V1_DEFAULTS; } });
68
68
  Object.defineProperty(exports, "DOWNLOAD_MODAL_V1_KEYS", { enumerable: true, get: function () { return download_modal_structure_v1_1.DOWNLOAD_MODAL_V1_KEYS; } });
69
69
  Object.defineProperty(exports, "hostKeepInheritance", { enumerable: true, get: function () { return download_modal_structure_v1_1.hostKeepInheritance; } });
70
+ var customization_validator_1 = require("./validation/customization.validator");
71
+ Object.defineProperty(exports, "formatCustomizationPath", { enumerable: true, get: function () { return customization_validator_1.formatCustomizationPath; } });
72
+ Object.defineProperty(exports, "isEmptyCustomization", { enumerable: true, get: function () { return customization_validator_1.isEmptyCustomization; } });
73
+ Object.defineProperty(exports, "validateCustomization", { enumerable: true, get: function () { return customization_validator_1.validateCustomization; } });
74
+ var remote_customization_loader_1 = require("./remote/remote-customization.loader");
75
+ Object.defineProperty(exports, "CUSTOMIZATIONS_API_PATH", { enumerable: true, get: function () { return remote_customization_loader_1.CUSTOMIZATIONS_API_PATH; } });
76
+ Object.defineProperty(exports, "DEFAULT_CUSTOMIZATION_ID", { enumerable: true, get: function () { return remote_customization_loader_1.DEFAULT_CUSTOMIZATION_ID; } });
77
+ Object.defineProperty(exports, "clearRemoteCustomizationCache", { enumerable: true, get: function () { return remote_customization_loader_1.clearRemoteCustomizationCache; } });
78
+ Object.defineProperty(exports, "isValidCustomizationId", { enumerable: true, get: function () { return remote_customization_loader_1.isValidCustomizationId; } });
79
+ Object.defineProperty(exports, "loadRemoteCustomization", { enumerable: true, get: function () { return remote_customization_loader_1.loadRemoteCustomization; } });
80
+ Object.defineProperty(exports, "remoteCustomizationLayers", { enumerable: true, get: function () { return remote_customization_loader_1.remoteCustomizationLayers; } });
70
81
  exports.DashboardDoc = __importStar(require("./doc/dashboard.structure.doc"));
71
82
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAgE;AA4BvD,8FA5BA,mCAAa,OA4BA;AAEtB,2DAI8B;AAH1B,6HAAA,uBAAuB,OAAA;AACvB,oHAAA,cAAc,OAAA;AACd,qHAAA,eAAe,OAAA;AAEnB,uEAKyC;AAJrC,6GAAA,MAAM,OAAA;AACN,oIAAA,6BAA6B,OAAA;AAC7B,kIAAA,2BAA2B,OAAA;AAC3B,6HAAA,sBAAsB,OAAA;AAE1B,iEAIoC;AAHhC,2HAAA,qBAAqB,OAAA;AACrB,sHAAA,gBAAgB,OAAA;AAChB,wHAAA,kBAAkB,OAAA;AAEtB,iEAAgF;AAAvE,qHAAA,eAAe,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAC3C,6DAKkC;AAJ9B,gIAAA,4BAA4B,OAAA;AAC5B,oHAAA,gBAAgB,OAAA;AAChB,mHAAA,eAAe,OAAA;AACf,oHAAA,gBAAgB,OAAA;AAEpB,uDAM+B;AAL3B,qHAAA,oBAAoB,OAAA;AACpB,uHAAA,sBAAsB,OAAA;AACtB,qHAAA,oBAAoB,OAAA;AACpB,8GAAA,aAAa,OAAA;AACb,uHAAA,sBAAsB,OAAA;AAG1B,wFAIkD;AAH9C,yIAAA,0BAA0B,OAAA;AAC1B,qIAAA,sBAAsB,OAAA;AACtB,kIAAA,mBAAmB,OAAA;AAIvB,8EAA8D"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,yEAAgE;AA0CvD,8FA1CA,mCAAa,OA0CA;AAEtB,2DAI8B;AAH1B,6HAAA,uBAAuB,OAAA;AACvB,oHAAA,cAAc,OAAA;AACd,qHAAA,eAAe,OAAA;AAEnB,uEAKyC;AAJrC,6GAAA,MAAM,OAAA;AACN,oIAAA,6BAA6B,OAAA;AAC7B,kIAAA,2BAA2B,OAAA;AAC3B,6HAAA,sBAAsB,OAAA;AAE1B,iEAIoC;AAHhC,2HAAA,qBAAqB,OAAA;AACrB,sHAAA,gBAAgB,OAAA;AAChB,wHAAA,kBAAkB,OAAA;AAEtB,iEAAgF;AAAvE,qHAAA,eAAe,OAAA;AAAE,uHAAA,iBAAiB,OAAA;AAC3C,6DAKkC;AAJ9B,gIAAA,4BAA4B,OAAA;AAC5B,oHAAA,gBAAgB,OAAA;AAChB,mHAAA,eAAe,OAAA;AACf,oHAAA,gBAAgB,OAAA;AAEpB,uDAM+B;AAL3B,qHAAA,oBAAoB,OAAA;AACpB,uHAAA,sBAAsB,OAAA;AACtB,qHAAA,oBAAoB,OAAA;AACpB,8GAAA,aAAa,OAAA;AACb,uHAAA,sBAAsB,OAAA;AAG1B,wFAIkD;AAH9C,yIAAA,0BAA0B,OAAA;AAC1B,qIAAA,sBAAsB,OAAA;AACtB,kIAAA,mBAAmB,OAAA;AAIvB,gFAI8C;AAH1C,kIAAA,uBAAuB,OAAA;AACvB,+HAAA,oBAAoB,OAAA;AACpB,gIAAA,qBAAqB,OAAA;AAEzB,oFAO8C;AAN1C,sIAAA,uBAAuB,OAAA;AACvB,uIAAA,wBAAwB,OAAA;AACxB,4IAAA,6BAA6B,OAAA;AAC7B,qIAAA,sBAAsB,OAAA;AACtB,sIAAA,uBAAuB,OAAA;AACvB,wIAAA,yBAAyB,OAAA;AAG7B,8EAA8D"}
@@ -0,0 +1,200 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCustomizationDocs = getCustomizationDocs;
4
+ exports.getCustomizationDefaultDocs = getCustomizationDefaultDocs;
5
+ const customization_metadata_1 = require("./customization-metadata");
6
+ const submodule_labels_1 = require("./labels/submodule.labels");
7
+ const configs_1 = require("../constants/configs");
8
+ const structure_constants_1 = require("../constants/structure.constants");
9
+ const structural_manager_1 = require("../structural-manager");
10
+ const structural_helpers_1 = require("../utils/structural.helpers");
11
+ const DEFAULT_AUDIENCE = 'partner';
12
+ const compact = (value) => Object.fromEntries(Object.entries(value).filter(([, field]) => field !== undefined));
13
+ const asObject = (value) => typeof value === 'object' && value !== null && !Array.isArray(value)
14
+ ? value
15
+ : {};
16
+ const viewPrefix = (view) => view ? `${view}${structure_constants_1.STRUCTURE_VIEW_NAME_SEPARATOR}` : '';
17
+ const parentOf = (key) => {
18
+ const index = key.lastIndexOf(structure_constants_1.STRUCTURE_SECTION_NAME_SEPARATOR);
19
+ return index < 0 ? undefined : key.slice(0, index);
20
+ };
21
+ const typeOf = (value) => {
22
+ if (value === undefined)
23
+ return undefined;
24
+ return Array.isArray(value) ? 'Array' : typeof value;
25
+ };
26
+ // The deepest key a default's path starts with: 'filterPanel.defaultView' belongs to filterPanel.
27
+ const ownerByPath = (name, keys) => keys
28
+ .filter((key) => name.startsWith(`${key}${structure_constants_1.STRUCTURE_SECTION_NAME_SEPARATOR}`))
29
+ .sort((left, right) => right.length - left.length)[0];
30
+ // The defaults a key's structure node sets itself: the names it adds or changes over what its parent (or the root) passes
31
+ // down, read from the engine's map so a section's defaults are not repeated on every key below it.
32
+ function declaredDefaults(widget, structure) {
33
+ const instance = new structural_manager_1.WidgetStructureInstance((0, structural_helpers_1.calculateViewMap)(structure));
34
+ const root = asObject(structure.defaults);
35
+ const declared = new Map();
36
+ const views = structure.views ? Object.keys(structure.views) : [undefined];
37
+ views.forEach((view) => (0, customization_metadata_1.structureKeysOf)(widget, view, undefined, {
38
+ structure,
39
+ }).forEach((key) => {
40
+ const parent = parentOf(key);
41
+ const inherited = parent
42
+ ? asObject(instance.getDefaults(viewPrefix(view) + parent))
43
+ : root;
44
+ Object.entries(asObject(instance.getDefaults(viewPrefix(view) + key)))
45
+ .filter(([name, value]) => !(name in inherited) ||
46
+ JSON.stringify(inherited[name]) !==
47
+ JSON.stringify(value))
48
+ .forEach(([name, value]) => declared.set(key, Object.assign(Object.assign({}, declared.get(key)), { [name]: value })));
49
+ }));
50
+ return declared;
51
+ }
52
+ /**
53
+ * The documented defaults of a widget: the structure's own (with the value it sets as example), the paths its validators
54
+ * check, and the docs written for it, which add description, version, notes, type and accepted values. Documented names
55
+ * come first, in the order the docs list them.
56
+ */
57
+ function defaultDocsOf(widget, structure, validators) {
58
+ var _a, _b;
59
+ const labels = (_b = (_a = customization_metadata_1.widgetMetadata[widget]) === null || _a === void 0 ? void 0 : _a.defaults) !== null && _b !== void 0 ? _b : {};
60
+ const values = new Map();
61
+ const declaredBy = new Map();
62
+ Object.entries(asObject(structure.defaults)).forEach(([name, value]) => values.set(name, value));
63
+ declaredDefaults(widget, structure).forEach((defaults, key) => Object.entries(defaults).forEach(([name, value]) => {
64
+ var _a;
65
+ if (!values.has(name))
66
+ values.set(name, value);
67
+ declaredBy.set(name, [...((_a = declaredBy.get(name)) !== null && _a !== void 0 ? _a : []), key]);
68
+ }));
69
+ const names = [
70
+ ...new Set([
71
+ ...Object.keys(labels),
72
+ ...values.keys(),
73
+ ...Object.keys(validators),
74
+ ]),
75
+ ];
76
+ const docs = names.map((name) => {
77
+ var _a, _b, _c;
78
+ const label = (_a = labels[name]) !== null && _a !== void 0 ? _a : {};
79
+ const value = values.get(name);
80
+ return compact({
81
+ name,
82
+ type: (_b = label.type) !== null && _b !== void 0 ? _b : typeOf(value),
83
+ values: label.values,
84
+ example: value === undefined ? label.example : JSON.stringify(value),
85
+ description: label.description,
86
+ since: label.since,
87
+ notes: label.notes,
88
+ audience: (_c = label.audience) !== null && _c !== void 0 ? _c : DEFAULT_AUDIENCE,
89
+ });
90
+ });
91
+ return { docs, declaredBy };
92
+ }
93
+ const validatorsOf = (widget, validationMap) => { var _a; return (_a = validationMap !== null && validationMap !== void 0 ? validationMap : configs_1.widgetValidators[widget]) !== null && _a !== void 0 ? _a : {}; };
94
+ // The defaults of each key of a scope: the ones its node declares, else the ones whose path starts with it.
95
+ function defaultsByKey({ docs, declaredBy }, keys) {
96
+ const byKey = new Map();
97
+ docs.forEach((doc) => {
98
+ var _a;
99
+ const declared = ((_a = declaredBy.get(doc.name)) !== null && _a !== void 0 ? _a : []).filter((key) => keys.includes(key));
100
+ const owners = declared.length
101
+ ? declared
102
+ : [ownerByPath(doc.name, keys)].filter((key) => !!key);
103
+ owners.forEach((key) => { var _a; return byKey.set(key, [...((_a = byKey.get(key)) !== null && _a !== void 0 ? _a : []), doc]); });
104
+ });
105
+ return byKey;
106
+ }
107
+ function flatten(widget, tree, scope, defaults) {
108
+ const keys = [];
109
+ const collect = (nodes) => nodes.forEach((node) => {
110
+ var _a;
111
+ keys.push(node.key);
112
+ collect((_a = node.children) !== null && _a !== void 0 ? _a : []);
113
+ });
114
+ collect(tree);
115
+ const byKey = defaultsByKey(defaults, keys);
116
+ // A key without an audience takes its section's, so an internal section keeps its keys out of the partner docs.
117
+ const walk = (nodes, parent, inherited) => nodes.flatMap((node) => {
118
+ var _a;
119
+ const { since, notes, audience } = (0, customization_metadata_1.getCustomizationLabel)(widget, node.key);
120
+ const own = audience !== null && audience !== void 0 ? audience : inherited;
121
+ const entry = compact({
122
+ key: node.key,
123
+ scope,
124
+ parent,
125
+ kind: node.kind,
126
+ label: node.label,
127
+ description: node.description,
128
+ since,
129
+ notes,
130
+ audience: own,
131
+ defaults: byKey.get(node.key),
132
+ });
133
+ return [entry, ...walk((_a = node.children) !== null && _a !== void 0 ? _a : [], node.key, own)];
134
+ });
135
+ return walk(tree, null, DEFAULT_AUDIENCE);
136
+ }
137
+ function subModuleEntry(widget, name, scope) {
138
+ var _a;
139
+ const key = `subModules${structure_constants_1.STRUCTURE_SECTION_NAME_SEPARATOR}${name}`;
140
+ const { label, description, since, notes, audience } = (_a = submodule_labels_1.SUBMODULE_LABELS[name]) !== null && _a !== void 0 ? _a : (0, customization_metadata_1.getCustomizationLabel)(widget, key);
141
+ return compact({
142
+ key,
143
+ scope,
144
+ parent: null,
145
+ kind: 'subModule',
146
+ label,
147
+ description,
148
+ since,
149
+ notes,
150
+ audience: audience !== null && audience !== void 0 ? audience : DEFAULT_AUDIENCE,
151
+ });
152
+ }
153
+ /**
154
+ * The customization keys of a widget as flat doc entries, one per key per scope: each view of the structure, then each
155
+ * submodule of the view ('design::chartPanel') with the keys its structure resolves to inside the host. Options may pass
156
+ * the structures to document, so a host can describe the tree it shipped with instead of this package's.
157
+ */
158
+ function getCustomizationDocs(widget, options = {}) {
159
+ const structure = (0, customization_metadata_1.structureRootOf)(widget, options);
160
+ const map = (0, structural_helpers_1.calculateViewMap)(structure);
161
+ const hostDefaults = defaultDocsOf(widget, structure, validatorsOf(widget, options.validationMap));
162
+ const views = structure.views
163
+ ? Object.keys(structure.views).filter((view) => !options.views || options.views.includes(view))
164
+ : [undefined];
165
+ return views.flatMap((view) => {
166
+ const scope = view !== null && view !== void 0 ? view : '';
167
+ const target = { views: view ? [view] : [] };
168
+ const entries = flatten(widget, (0, customization_metadata_1.getCustomizationTree)(widget, target, options), scope, hostDefaults);
169
+ Object.keys(asObject(map[`${viewPrefix(view)}subModules`]))
170
+ .filter((name) => !options.subModules || options.subModules.includes(name))
171
+ .forEach((name) => {
172
+ entries.push(subModuleEntry(widget, name, scope));
173
+ const embedded = (0, customization_metadata_1.findWidgetOfSubmodule)(name);
174
+ // A submodule no widget is registered for is listed, but has no keys to document.
175
+ if (!embedded)
176
+ return;
177
+ entries.push(...flatten(embedded, (0, customization_metadata_1.getCustomizationTree)(widget, Object.assign(Object.assign({}, target), { subModules: [name] }), options), view
178
+ ? `${view}${structure_constants_1.STRUCTURE_VIEW_NAME_SEPARATOR}${name}`
179
+ : name, defaultDocsOf(embedded, (0, customization_metadata_1.structureRootOf)(embedded, options, name), validatorsOf(embedded))));
180
+ });
181
+ return entries;
182
+ });
183
+ }
184
+ /**
185
+ * Every documented default of a widget, with the key it belongs to: the defaults no key owns (customStyles,
186
+ * unsavedChangesBehavior) apply to the whole widget and come with a null key.
187
+ */
188
+ function getCustomizationDefaultDocs(widget, options = {}) {
189
+ const structure = (0, customization_metadata_1.structureRootOf)(widget, options);
190
+ const { docs, declaredBy } = defaultDocsOf(widget, structure, validatorsOf(widget, options.validationMap));
191
+ const views = structure.views ? Object.keys(structure.views) : [undefined];
192
+ const keys = [
193
+ ...new Set(views.flatMap((view) => (0, customization_metadata_1.structureKeysOf)(widget, view, undefined, { structure }))),
194
+ ];
195
+ return docs.map((doc) => {
196
+ var _a, _b, _c;
197
+ return (Object.assign(Object.assign({}, doc), { key: (_c = (_b = (_a = declaredBy.get(doc.name)) === null || _a === void 0 ? void 0 : _a[0]) !== null && _b !== void 0 ? _b : ownerByPath(doc.name, keys)) !== null && _c !== void 0 ? _c : null }));
198
+ });
199
+ }
200
+ //# sourceMappingURL=customization-docs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"customization-docs.js","sourceRoot":"","sources":["../../../src/metadata/customization-docs.ts"],"names":[],"mappings":";;AAkPA,oDAwDC;AAMD,kEAyBC;AAzUD,qEAOkC;AAClC,gEAA6D;AAS7D,kDAAwD;AACxD,0EAI0C;AAE1C,8DAAgE;AAChE,oEAA+D;AAE/D,MAAM,gBAAgB,GAA0B,SAAS,CAAC;AAQ1D,MAAM,OAAO,GAAG,CAAmB,KAAQ,EAAK,EAAE,CAC9C,MAAM,CAAC,WAAW,CACd,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,KAAK,KAAK,SAAS,CAAC,CAC9D,CAAC;AAEX,MAAM,QAAQ,GAAG,CAAC,KAAc,EAA2B,EAAE,CACzD,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC;IAChE,CAAC,CAAE,KAAiC;IACpC,CAAC,CAAC,EAAE,CAAC;AAEb,MAAM,UAAU,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EAAE,IAAI,EAAE,SAAS,EAAE,EAAE,SAAS,EAAE,CAAC,CAC1D,CACJ;KACJ,CAAC;IACF,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE;;QAAC,OAAA,iCAClB,GAAG,KACN,GAAG,EACC,MAAA,MAAA,MAAA,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,0CAAG,CAAC,CAAC,mCAC7B,WAAW,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC,mCAC3B,IAAI,IACV,CAAA;KAAA,CAAC,CAAC;AACR,CAAC"}
@@ -0,0 +1,297 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.findWidgetOfSubmodule = exports.widgetMetadata = void 0;
15
+ exports.structureRootOf = structureRootOf;
16
+ exports.structureKeysOf = structureKeysOf;
17
+ exports.getCustomizationLabel = getCustomizationLabel;
18
+ exports.getCustomizationTree = getCustomizationTree;
19
+ exports.lockOf = lockOf;
20
+ exports.getCustomizationTreeState = getCustomizationTreeState;
21
+ exports.toggleCustomizationKey = toggleCustomizationKey;
22
+ const chart_panel_defaults_1 = require("./labels/chart-panel.defaults");
23
+ const chart_panel_labels_1 = require("./labels/chart-panel.labels");
24
+ const dashboard_defaults_1 = require("./labels/dashboard.defaults");
25
+ const dashboard_labels_1 = require("./labels/dashboard.labels");
26
+ const structure_constants_1 = require("../constants/structure.constants");
27
+ const structural_manager_1 = require("../structural-manager");
28
+ const scope_helpers_1 = require("../utils/scope.helpers");
29
+ const structural_helpers_1 = require("../utils/structural.helpers");
30
+ // Label maps by widget, and the docs of their defaults; a new widget adds its maps here and the guard spec checks them (3.7.1).
31
+ exports.widgetMetadata = {
32
+ [structure_constants_1.Widget.DASHBOARD]: {
33
+ labels: dashboard_labels_1.DASHBOARD_LABELS,
34
+ defaults: dashboard_defaults_1.DASHBOARD_DEFAULTS,
35
+ },
36
+ [structure_constants_1.Widget.CHART_PANEL]: {
37
+ labels: chart_panel_labels_1.CHART_PANEL_LABELS,
38
+ defaults: chart_panel_defaults_1.CHART_PANEL_DEFAULTS,
39
+ },
40
+ };
41
+ const findWidgetOfSubmodule = (name) => Object.keys(structure_constants_1.WIDGET_SUBMODULE_NAMES).find((key) => structure_constants_1.WIDGET_SUBMODULE_NAMES[key] === name);
42
+ exports.findWidgetOfSubmodule = findWidgetOfSubmodule;
43
+ const widgetOfSubmodule = (name) => {
44
+ const widget = (0, exports.findWidgetOfSubmodule)(name);
45
+ if (!widget)
46
+ throw new Error(`No widget registered for the submodule ${name}`);
47
+ return widget;
48
+ };
49
+ const isWidgetConfig = (source) => typeof source.version === 'string' &&
50
+ typeof source.baseStructure === 'object';
51
+ const rootOf = (source) => isWidgetConfig(source) ? source.baseStructure : source;
52
+ /**
53
+ * The structure to read for a widget, or for the widget a submodule name embeds: the caller's when it passes one (a host
54
+ * documenting the tree it released with), else the one this package ships.
55
+ */
56
+ function structureRootOf(widget, options = {}, subModule) {
57
+ var _a;
58
+ const source = subModule
59
+ ? (_a = options.subModuleStructures) === null || _a === void 0 ? void 0 : _a[subModule]
60
+ : options.structure;
61
+ if (source)
62
+ return rootOf(source);
63
+ return (0, structural_manager_1.getWidgetConfig)(widget, subModule ? undefined : options.version)
64
+ .baseStructure;
65
+ }
66
+ const asCustomization = (value) => typeof value === 'object' && value !== null && !Array.isArray(value)
67
+ ? value
68
+ : undefined;
69
+ // Keys of a target. A submodule's keys come from its structure under the customization its host declares for it, the way
70
+ // structureFromSubmodule builds it, so a host structure that removes a chart panel key leaves it out of the tree.
71
+ function resolveTarget(widget, target, options) {
72
+ var _a;
73
+ const subModules = (_a = target.subModules) !== null && _a !== void 0 ? _a : [];
74
+ const host = structureRootOf(widget, options);
75
+ const views = host.views ? target.views : [undefined];
76
+ if (!subModules.length) {
77
+ return {
78
+ widget,
79
+ keys: views.map((view) => structureKeysOf(widget, view, options.version, {
80
+ structure: host,
81
+ })),
82
+ };
83
+ }
84
+ const embedded = widgetOfSubmodule(subModules[subModules.length - 1]);
85
+ return {
86
+ widget: embedded,
87
+ keys: views.map((view) => {
88
+ let structure = host;
89
+ let customization;
90
+ let hostView = view;
91
+ subModules.forEach((name) => {
92
+ const instance = new structural_manager_1.WidgetStructureInstance((0, structural_helpers_1.calculateViewMap)(structure, customization));
93
+ customization = asCustomization(instance.getSubmodule(name, hostView));
94
+ structure = structureRootOf(widgetOfSubmodule(name), options, name);
95
+ hostView = structure.views ? view : undefined;
96
+ });
97
+ return structureKeysOf(embedded, hostView, undefined, {
98
+ structure,
99
+ customization,
100
+ });
101
+ }),
102
+ };
103
+ }
104
+ /**
105
+ * Keys of the structure in a view (or at the root), in structure order, without the view prefix. Reads the structure the
106
+ * options pass, under their customization, instead of the one this package ships when they set one.
107
+ */
108
+ function structureKeysOf(widget, view, version, options = {}) {
109
+ const map = (0, structural_helpers_1.calculateViewMap)(options.structure
110
+ ? rootOf(options.structure)
111
+ : (0, structural_manager_1.getWidgetConfig)(widget, version).baseStructure, options.customization);
112
+ const prefix = view ? `${view}${structure_constants_1.STRUCTURE_VIEW_NAME_SEPARATOR}` : '';
113
+ return Object.keys(map)
114
+ .filter((key) => view
115
+ ? key.startsWith(prefix)
116
+ : !key.includes(structure_constants_1.STRUCTURE_VIEW_NAME_SEPARATOR))
117
+ .map((key) => key.slice(prefix.length))
118
+ .filter((key) => key !== 'subModules');
119
+ }
120
+ const humanize = (id) => id
121
+ .replace(/^q(?=[A-Z])/, '')
122
+ .replace(/([a-z0-9])([A-Z])/g, '$1 $2')
123
+ .replace(/^./, (char) => char.toUpperCase());
124
+ /**
125
+ * Label of a key: full path first, then the leaf id; a humanized id when neither exists.
126
+ */
127
+ function getCustomizationLabel(widget, key) {
128
+ var _a, _b, _c, _d, _e;
129
+ const labels = (_b = (_a = exports.widgetMetadata[widget]) === null || _a === void 0 ? void 0 : _a.labels) !== null && _b !== void 0 ? _b : {};
130
+ const id = (_c = key.split(structure_constants_1.STRUCTURE_SECTION_NAME_SEPARATOR).pop()) !== null && _c !== void 0 ? _c : key;
131
+ return (_e = (_d = labels[key]) !== null && _d !== void 0 ? _d : labels[id]) !== null && _e !== void 0 ? _e : { label: humanize(id) };
132
+ }
133
+ /**
134
+ * The labelled tree of a target: a widget view, or the structure of the embedded widget when subModules is set. Options
135
+ * may pass the structures to read (CustomizationStructureOptions).
136
+ */
137
+ function getCustomizationTree(widget, target, options = {}) {
138
+ const resolved = resolveTarget(widget, target, options);
139
+ const ordered = [];
140
+ resolved.keys.forEach((keys) => keys.forEach((key) => {
141
+ if (!ordered.includes(key))
142
+ ordered.push(key);
143
+ }));
144
+ const roots = [];
145
+ const nodes = new Map();
146
+ const ensure = (key) => {
147
+ var _a;
148
+ const existing = nodes.get(key);
149
+ if (existing)
150
+ return existing;
151
+ const parts = key.split(structure_constants_1.STRUCTURE_SECTION_NAME_SEPARATOR);
152
+ const { label, description } = getCustomizationLabel(resolved.widget, key);
153
+ const node = Object.assign(Object.assign({ key, id: parts[parts.length - 1], label }, (description && { description })), { kind: 'item' });
154
+ nodes.set(key, node);
155
+ if (parts.length === 1) {
156
+ roots.push(node);
157
+ }
158
+ else {
159
+ const parent = ensure(parts.slice(0, -1).join(structure_constants_1.STRUCTURE_SECTION_NAME_SEPARATOR));
160
+ parent.kind = 'section';
161
+ parent.children = [...((_a = parent.children) !== null && _a !== void 0 ? _a : []), node];
162
+ }
163
+ return node;
164
+ };
165
+ ordered.forEach(ensure);
166
+ return roots;
167
+ }
168
+ function instanceFor(widget, customization, target, view) {
169
+ var _a;
170
+ let instance = (0, structural_manager_1.buildStructure)(widget, customization);
171
+ ((_a = target.subModules) !== null && _a !== void 0 ? _a : []).forEach((name) => {
172
+ instance = (0, scope_helpers_1.structureFromSubmodule)(instance, name, view);
173
+ });
174
+ return instance;
175
+ }
176
+ const matches = (pattern, key) => pattern === key ||
177
+ new RegExp(`^${pattern.replace(/\./g, '\\.').replace(/\*/g, '.*')}$`).test(key);
178
+ // The block where the tree's switches write, and the blocks above it whose rules a switch cannot undo.
179
+ function scopesOf(customization, target, view) {
180
+ var _a, _b, _c, _d, _e, _f;
181
+ const subModules = (_a = target.subModules) !== null && _a !== void 0 ? _a : [];
182
+ if (!subModules.length) {
183
+ return { own: (_b = customization === null || customization === void 0 ? void 0 : customization.views) === null || _b === void 0 ? void 0 : _b[view], root: customization };
184
+ }
185
+ const name = subModules[subModules.length - 1];
186
+ return {
187
+ own: (_e = (_d = (_c = customization === null || customization === void 0 ? void 0 : customization.views) === null || _c === void 0 ? void 0 : _c[view]) === null || _d === void 0 ? void 0 : _d.subModules) === null || _e === void 0 ? void 0 : _e[name],
188
+ root: (_f = customization === null || customization === void 0 ? void 0 : customization.subModules) === null || _f === void 0 ? void 0 : _f[name],
189
+ };
190
+ }
191
+ function lockOf(customization, target, view, key, hiddenParent) {
192
+ var _a, _b, _c, _d, _e, _f, _g;
193
+ const { own, root } = scopesOf(customization, target, view);
194
+ if (hiddenParent)
195
+ return { verb: 'remove', pattern: hiddenParent, scope: 'parent' };
196
+ if ((_a = own === null || own === void 0 ? void 0 : own.remove) === null || _a === void 0 ? void 0 : _a.includes(key))
197
+ return undefined;
198
+ const rootRemove = (_b = root === null || root === void 0 ? void 0 : root.remove) === null || _b === void 0 ? void 0 : _b.find((pattern) => matches(pattern, key));
199
+ if (rootRemove)
200
+ return { verb: 'remove', pattern: rootRemove, scope: 'root' };
201
+ const viewRemove = (_c = own === null || own === void 0 ? void 0 : own.remove) === null || _c === void 0 ? void 0 : _c.find((pattern) => matches(pattern, key));
202
+ if (viewRemove)
203
+ return { verb: 'remove', pattern: viewRemove, scope: 'view' };
204
+ if ((_d = root === null || root === void 0 ? void 0 : root.keep) === null || _d === void 0 ? void 0 : _d.length)
205
+ return { verb: 'keep', pattern: root.keep.join(', '), scope: 'root' };
206
+ if ((_e = own === null || own === void 0 ? void 0 : own.keep) === null || _e === void 0 ? void 0 : _e.length)
207
+ return { verb: 'keep', pattern: own.keep.join(', '), scope: 'view' };
208
+ // Hidden by something the switches do not write (a conditional, a submodule rule of the host).
209
+ return {
210
+ verb: 'remove',
211
+ pattern: key,
212
+ scope: ((_f = own === null || own === void 0 ? void 0 : own.conditional) === null || _f === void 0 ? void 0 : _f.length) || ((_g = root === null || root === void 0 ? void 0 : root.conditional) === null || _g === void 0 ? void 0 : _g.length)
213
+ ? 'conditional'
214
+ : 'view',
215
+ };
216
+ }
217
+ /**
218
+ * The tree with the visibility of each node for a customization, computed with the real engine. A node whose
219
+ * visibility differs between the target views is 'mixed'; a hidden node a switch cannot bring back is locked.
220
+ */
221
+ function getCustomizationTreeState(widget, customization, target) {
222
+ var _a;
223
+ const tree = getCustomizationTree(widget, target);
224
+ const embedded = !!((_a = target.subModules) === null || _a === void 0 ? void 0 : _a.length);
225
+ const instances = target.views.map((view) => ({
226
+ view,
227
+ instance: instanceFor(widget, customization, target, view),
228
+ }));
229
+ const isVisible = (instance, view, key) => instance.isVisible(embedded ? key : `${view}${structure_constants_1.STRUCTURE_VIEW_NAME_SEPARATOR}${key}`, {});
230
+ const walk = (nodes, hiddenParents) => nodes.map((node) => {
231
+ const states = instances.map(({ view, instance }) => isVisible(instance, view, node.key));
232
+ const visible = states.every(Boolean)
233
+ ? true
234
+ : states.some(Boolean)
235
+ ? 'mixed'
236
+ : false;
237
+ const locks = visible === false
238
+ ? instances.map(({ view }, index) => lockOf(customization, target, view, node.key, hiddenParents[index]))
239
+ : [];
240
+ const lockedBy = locks.length && locks.every(Boolean) ? locks[0] : undefined;
241
+ const childParents = states.map((state, index) => { var _a; return (_a = hiddenParents[index]) !== null && _a !== void 0 ? _a : (state ? undefined : node.key); });
242
+ const { children } = node, rest = __rest(node, ["children"]);
243
+ const stateNode = Object.assign(Object.assign({}, rest), { visible });
244
+ if (lockedBy)
245
+ stateNode.lockedBy = lockedBy;
246
+ if (children)
247
+ stateNode.children = walk(children, childParents);
248
+ return stateNode;
249
+ });
250
+ return walk(tree, instances.map(() => undefined));
251
+ }
252
+ const isEmptyObject = (value) => typeof value === 'object' &&
253
+ value !== null &&
254
+ !Array.isArray(value) &&
255
+ Object.keys(value).length === 0;
256
+ /**
257
+ * A new customization with the minimal change for one switch, applied to every view of the target. It only edits
258
+ * the remove list of each view (or of the submodule inside it), never keep, conditional, defaults or root verbs.
259
+ */
260
+ function toggleCustomizationKey(customization, target, key, visible) {
261
+ const result = JSON.parse(JSON.stringify(customization !== null && customization !== void 0 ? customization : {}));
262
+ target.views.forEach((view) => {
263
+ var _a, _b;
264
+ const chain = [
265
+ result,
266
+ ];
267
+ const step = (holder, name) => {
268
+ var _a;
269
+ holder[name] = (_a = holder[name]) !== null && _a !== void 0 ? _a : {};
270
+ chain.push(holder[name]);
271
+ return holder[name];
272
+ };
273
+ let block = step(step(result, 'views'), view);
274
+ ((_a = target.subModules) !== null && _a !== void 0 ? _a : []).forEach((name) => {
275
+ block = step(step(block, 'subModules'), name);
276
+ });
277
+ const remove = (_b = block.remove) !== null && _b !== void 0 ? _b : [];
278
+ if (!visible && !remove.includes(key))
279
+ block.remove = [...remove, key];
280
+ if (visible) {
281
+ const next = remove.filter((item) => item !== key);
282
+ if (next.length)
283
+ block.remove = next;
284
+ else
285
+ delete block.remove;
286
+ }
287
+ // Drops the empty objects this switch left behind, from the innermost out.
288
+ for (let index = chain.length - 1; index > 0; index--) {
289
+ const holder = chain[index - 1];
290
+ const name = Object.keys(holder).find((property) => holder[property] === chain[index]);
291
+ if (name && isEmptyObject(chain[index]))
292
+ delete holder[name];
293
+ }
294
+ });
295
+ return result;
296
+ }
297
+ //# sourceMappingURL=customization-metadata.js.map