@rulecms/widget-angular 0.1.0
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 +7 -0
- package/README.md +125 -0
- package/fesm2022/rulecms-widget-angular.mjs +3465 -0
- package/fesm2022/rulecms-widget-angular.mjs.map +1 -0
- package/index.d.ts +6 -0
- package/lib/fetch/fetch-rule-cms-widget.d.ts +23 -0
- package/lib/fetch/fetch-rule-cms-widget.d.ts.map +1 -0
- package/lib/fetch/resolve-widget-libraries.d.ts +16 -0
- package/lib/fetch/resolve-widget-libraries.d.ts.map +1 -0
- package/lib/helpers/background-image-types.d.ts +24 -0
- package/lib/helpers/background-image-types.d.ts.map +1 -0
- package/lib/helpers/border-types.d.ts +22 -0
- package/lib/helpers/border-types.d.ts.map +1 -0
- package/lib/helpers/box-shadow-types.d.ts +25 -0
- package/lib/helpers/box-shadow-types.d.ts.map +1 -0
- package/lib/helpers/box-spacing-style-attribute-entries.d.ts +4 -0
- package/lib/helpers/box-spacing-style-attribute-entries.d.ts.map +1 -0
- package/lib/helpers/box-spacing-types.d.ts +31 -0
- package/lib/helpers/box-spacing-types.d.ts.map +1 -0
- package/lib/helpers/cloudinary-image-url.d.ts +20 -0
- package/lib/helpers/cloudinary-image-url.d.ts.map +1 -0
- package/lib/helpers/collect-component-instance-paths.d.ts +16 -0
- package/lib/helpers/collect-component-instance-paths.d.ts.map +1 -0
- package/lib/helpers/constants.d.ts +5 -0
- package/lib/helpers/constants.d.ts.map +1 -0
- package/lib/helpers/css-classes.d.ts +13 -0
- package/lib/helpers/css-classes.d.ts.map +1 -0
- package/lib/helpers/css-color-types.d.ts +18 -0
- package/lib/helpers/css-color-types.d.ts.map +1 -0
- package/lib/helpers/css-enum-types.d.ts +41 -0
- package/lib/helpers/css-enum-types.d.ts.map +1 -0
- package/lib/helpers/css-variable-types.d.ts +33 -0
- package/lib/helpers/css-variable-types.d.ts.map +1 -0
- package/lib/helpers/derive-display-flex-if-needed.d.ts +13 -0
- package/lib/helpers/derive-display-flex-if-needed.d.ts.map +1 -0
- package/lib/helpers/format-background-image-styles.d.ts +12 -0
- package/lib/helpers/format-background-image-styles.d.ts.map +1 -0
- package/lib/helpers/format-border-styles.d.ts +9 -0
- package/lib/helpers/format-border-styles.d.ts.map +1 -0
- package/lib/helpers/format-box-shadow-styles.d.ts +8 -0
- package/lib/helpers/format-box-shadow-styles.d.ts.map +1 -0
- package/lib/helpers/format-box-spacing-styles.d.ts +11 -0
- package/lib/helpers/format-box-spacing-styles.d.ts.map +1 -0
- package/lib/helpers/format-css-color-styles.d.ts +8 -0
- package/lib/helpers/format-css-color-styles.d.ts.map +1 -0
- package/lib/helpers/format-css-enum-styles.d.ts +7 -0
- package/lib/helpers/format-css-enum-styles.d.ts.map +1 -0
- package/lib/helpers/format-css-length-styles.d.ts +9 -0
- package/lib/helpers/format-css-length-styles.d.ts.map +1 -0
- package/lib/helpers/format-line-height-styles.d.ts +8 -0
- package/lib/helpers/format-line-height-styles.d.ts.map +1 -0
- package/lib/helpers/format-opacity-styles.d.ts +8 -0
- package/lib/helpers/format-opacity-styles.d.ts.map +1 -0
- package/lib/helpers/format-spacing-side-value.d.ts +4 -0
- package/lib/helpers/format-spacing-side-value.d.ts.map +1 -0
- package/lib/helpers/get-column-attributes.d.ts +26 -0
- package/lib/helpers/get-column-attributes.d.ts.map +1 -0
- package/lib/helpers/get-component-attributes-and-styles.d.ts +23 -0
- package/lib/helpers/get-component-attributes-and-styles.d.ts.map +1 -0
- package/lib/helpers/get-default-dimension-attributes.d.ts +9 -0
- package/lib/helpers/get-default-dimension-attributes.d.ts.map +1 -0
- package/lib/helpers/get-device-type-based-attributes.d.ts +10 -0
- package/lib/helpers/get-device-type-based-attributes.d.ts.map +1 -0
- package/lib/helpers/get-merged-attributes.d.ts +11 -0
- package/lib/helpers/get-merged-attributes.d.ts.map +1 -0
- package/lib/helpers/has-items.d.ts +3 -0
- package/lib/helpers/has-items.d.ts.map +1 -0
- package/lib/helpers/index.d.ts +40 -0
- package/lib/helpers/index.d.ts.map +1 -0
- package/lib/helpers/line-height-types.d.ts +12 -0
- package/lib/helpers/line-height-types.d.ts.map +1 -0
- package/lib/helpers/object-style-attribute-registry.d.ts +44 -0
- package/lib/helpers/object-style-attribute-registry.d.ts.map +1 -0
- package/lib/helpers/opacity-types.d.ts +9 -0
- package/lib/helpers/opacity-types.d.ts.map +1 -0
- package/lib/helpers/resolve-row-styles.d.ts +23 -0
- package/lib/helpers/resolve-row-styles.d.ts.map +1 -0
- package/lib/helpers/resolve-widget-container-styles.d.ts +55 -0
- package/lib/helpers/resolve-widget-container-styles.d.ts.map +1 -0
- package/lib/helpers/resolve-widget-instance-props.d.ts +18 -0
- package/lib/helpers/resolve-widget-instance-props.d.ts.map +1 -0
- package/lib/helpers/types.d.ts +131 -0
- package/lib/helpers/types.d.ts.map +1 -0
- package/lib/helpers/warn-unmatched-component-props.d.ts +30 -0
- package/lib/helpers/warn-unmatched-component-props.d.ts.map +1 -0
- package/lib/helpers-display/dimension-wrapper-styles.d.ts +7 -0
- package/lib/helpers-display/dimension-wrapper-styles.d.ts.map +1 -0
- package/lib/helpers-display/resolve-no-container.d.ts +14 -0
- package/lib/helpers-display/resolve-no-container.d.ts.map +1 -0
- package/lib/helpers-display/resolve-renders-own-element.d.ts +15 -0
- package/lib/helpers-display/resolve-renders-own-element.d.ts.map +1 -0
- package/lib/id-utils/collection-col-type-prefix.d.ts +2 -0
- package/lib/id-utils/collection-col-type-prefix.d.ts.map +1 -0
- package/lib/id-utils/dev-client-token.d.ts +33 -0
- package/lib/id-utils/dev-client-token.d.ts.map +1 -0
- package/lib/id-utils/drag-item-id-helper.d.ts +9 -0
- package/lib/id-utils/drag-item-id-helper.d.ts.map +1 -0
- package/lib/id-utils/get-collection-id-for-collection-type.d.ts +2 -0
- package/lib/id-utils/get-collection-id-for-collection-type.d.ts.map +1 -0
- package/lib/id-utils/get-name-and-instance-id-from-widget-key.d.ts +6 -0
- package/lib/id-utils/get-name-and-instance-id-from-widget-key.d.ts.map +1 -0
- package/lib/id-utils/get-name-for-widget-key.d.ts +5 -0
- package/lib/id-utils/get-name-for-widget-key.d.ts.map +1 -0
- package/lib/id-utils/get-widget-key-for-collection.d.ts +16 -0
- package/lib/id-utils/get-widget-key-for-collection.d.ts.map +1 -0
- package/lib/id-utils/index.d.ts +11 -0
- package/lib/id-utils/index.d.ts.map +1 -0
- package/lib/id-utils/published-key-utilities.d.ts +24 -0
- package/lib/id-utils/published-key-utilities.d.ts.map +1 -0
- package/lib/id-utils/types.d.ts +25 -0
- package/lib/id-utils/types.d.ts.map +1 -0
- package/lib/id-utils/version-utilities.d.ts +7 -0
- package/lib/id-utils/version-utilities.d.ts.map +1 -0
- package/lib/library-registry/ComponentLibraryRegistry.d.ts +17 -0
- package/lib/library-registry/ComponentLibraryRegistry.d.ts.map +1 -0
- package/lib/library-registry/collect-referenced-library-ids.d.ts +20 -0
- package/lib/library-registry/collect-referenced-library-ids.d.ts.map +1 -0
- package/lib/library-registry/index.d.ts +5 -0
- package/lib/library-registry/index.d.ts.map +1 -0
- package/lib/library-registry/resolve-key.d.ts +16 -0
- package/lib/library-registry/resolve-key.d.ts.map +1 -0
- package/lib/library-registry/types.d.ts +142 -0
- package/lib/library-registry/types.d.ts.map +1 -0
- package/lib/provider/rule-cms-widget-context.service.d.ts +11 -0
- package/lib/provider/rule-cms-widget-context.service.d.ts.map +1 -0
- package/lib/provider/rule-cms-widget-provider.component.d.ts +26 -0
- package/lib/provider/rule-cms-widget-provider.component.d.ts.map +1 -0
- package/lib/render/breakpoint-variant-render.component.d.ts +21 -0
- package/lib/render/breakpoint-variant-render.component.d.ts.map +1 -0
- package/lib/render/breakpoint-variant-styles.d.ts +2 -0
- package/lib/render/breakpoint-variant-styles.d.ts.map +1 -0
- package/lib/render/display-component.component.d.ts +27 -0
- package/lib/render/display-component.component.d.ts.map +1 -0
- package/lib/render/display-device-type.d.ts +5 -0
- package/lib/render/display-device-type.d.ts.map +1 -0
- package/lib/render/embed-in-row.component.d.ts +21 -0
- package/lib/render/embed-in-row.component.d.ts.map +1 -0
- package/lib/render/embed-in-vertical-container.component.d.ts +24 -0
- package/lib/render/embed-in-vertical-container.component.d.ts.map +1 -0
- package/lib/render/get-components-plugin-from-plugins.d.ts +11 -0
- package/lib/render/get-components-plugin-from-plugins.d.ts.map +1 -0
- package/lib/render/has-device-divergent-values.d.ts +6 -0
- package/lib/render/has-device-divergent-values.d.ts.map +1 -0
- package/lib/render/render-components-for-device.component.d.ts +20 -0
- package/lib/render/render-components-for-device.component.d.ts.map +1 -0
- package/lib/render/render-components-inner.component.d.ts +33 -0
- package/lib/render/render-components-inner.component.d.ts.map +1 -0
- package/lib/render/render-components.component.d.ts +26 -0
- package/lib/render/render-components.component.d.ts.map +1 -0
- package/lib/render/types.d.ts +43 -0
- package/lib/render/types.d.ts.map +1 -0
- package/lib/widget/prepare-rule-cms-widget-data.d.ts +4 -0
- package/lib/widget/prepare-rule-cms-widget-data.d.ts.map +1 -0
- package/lib/widget/resolve-source-components-plugin.d.ts +19 -0
- package/lib/widget/resolve-source-components-plugin.d.ts.map +1 -0
- package/lib/widget/rule-cms-widget.component.d.ts +66 -0
- package/lib/widget/rule-cms-widget.component.d.ts.map +1 -0
- package/lib/widget/rule-cms-widget.styles.d.ts +9 -0
- package/lib/widget/rule-cms-widget.styles.d.ts.map +1 -0
- package/lib/widget/widget-data.types.d.ts +47 -0
- package/lib/widget/widget-data.types.d.ts.map +1 -0
- package/package.json +43 -0
- package/public-api.d.ts +22 -0
- package/public-api.d.ts.map +1 -0
- package/rulecms-widget-angular.d.ts.map +1 -0
|
@@ -0,0 +1,3465 @@
|
|
|
1
|
+
import * as i0 from '@angular/core';
|
|
2
|
+
import { Injectable, Input, Component, HostBinding, ErrorHandler, Optional, Inject } from '@angular/core';
|
|
3
|
+
import { NgComponentOutlet, NgStyle } from '@angular/common';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The reserved id for the default component library. Configs that carry no
|
|
7
|
+
* libraryId on a component resolve to it, preserving backward compatibility.
|
|
8
|
+
*/
|
|
9
|
+
const DEFAULT_LIBRARY_ID = 'default';
|
|
10
|
+
/**
|
|
11
|
+
* Maps a component's (libraryId, type) pair to its key in the composed
|
|
12
|
+
* components map. The default library keeps bare (unnamespaced) keys so
|
|
13
|
+
* existing configs resolve unchanged; every other library is namespaced as
|
|
14
|
+
* "libraryId/type" so identical local types across tenants never collide.
|
|
15
|
+
*
|
|
16
|
+
* Never apply this to collection types — collections are not components and
|
|
17
|
+
* are not namespaced.
|
|
18
|
+
*/
|
|
19
|
+
function resolveKey(libraryId, type) {
|
|
20
|
+
if (!libraryId?.length || libraryId === DEFAULT_LIBRARY_ID) {
|
|
21
|
+
return type;
|
|
22
|
+
}
|
|
23
|
+
return `${libraryId}/${type}`;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// NOTE: this message intentionally does not name the concrete default-library
|
|
27
|
+
// package — the dist guardrail forbids ANY occurrence of it in build output
|
|
28
|
+
// (dependency inversion). The migration guide carries the exact install and
|
|
29
|
+
// registration commands.
|
|
30
|
+
const MISSING_DEFAULT_LIBRARY_MESSAGE = 'RuleCMS widget: this widget config uses components from the default component ' +
|
|
31
|
+
'library, but no "default" library is registered. The default library is ' +
|
|
32
|
+
'registered by the consumer app: add the RuleCMS default source components ' +
|
|
33
|
+
'package as a direct dependency and register it, e.g. ' +
|
|
34
|
+
'libraries: { default: sourceComponentsModule } (statically imported for SSR) or ' +
|
|
35
|
+
"libraries: { default: () => import('<default source components package>') }. " +
|
|
36
|
+
'See the @rulecms/widget-angular README.';
|
|
37
|
+
function isComponentLibraryModule(value) {
|
|
38
|
+
if (!value || typeof value !== 'object') {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const candidate = value;
|
|
42
|
+
return (!!candidate.manifest &&
|
|
43
|
+
typeof candidate.manifest === 'object' &&
|
|
44
|
+
!!candidate.components &&
|
|
45
|
+
typeof candidate.components === 'object' &&
|
|
46
|
+
!Array.isArray(candidate.components));
|
|
47
|
+
}
|
|
48
|
+
function normalizeResolvedModule(resolved) {
|
|
49
|
+
if (isComponentLibraryModule(resolved)) {
|
|
50
|
+
return resolved;
|
|
51
|
+
}
|
|
52
|
+
const withDefault = resolved;
|
|
53
|
+
if (isComponentLibraryModule(withDefault?.default)) {
|
|
54
|
+
return withDefault.default;
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
function requiredLibraryIds(referenced) {
|
|
59
|
+
return referenced.usesDefaultLibrary
|
|
60
|
+
? [DEFAULT_LIBRARY_ID, ...referenced.libraryIds]
|
|
61
|
+
: [...referenced.libraryIds];
|
|
62
|
+
}
|
|
63
|
+
function assertDefaultLibraryRegistered({ registrations, referenced }) {
|
|
64
|
+
if (referenced.usesDefaultLibrary && !registrations?.[DEFAULT_LIBRARY_ID]) {
|
|
65
|
+
throw new Error(MISSING_DEFAULT_LIBRARY_MESSAGE);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Composes loaded library modules into the single plugin the render pipeline
|
|
70
|
+
* consumes. Default library entries keep bare keys; all other libraries are
|
|
71
|
+
* namespaced "libraryId/type" (see resolve-key.ts).
|
|
72
|
+
*/
|
|
73
|
+
function composeSourceComponentsPlugin(modules) {
|
|
74
|
+
const components = {};
|
|
75
|
+
for (const [libraryId, module] of modules) {
|
|
76
|
+
const isDefault = libraryId === DEFAULT_LIBRARY_ID;
|
|
77
|
+
for (const [type, entry] of Object.entries(module.components)) {
|
|
78
|
+
components[isDefault ? type : `${libraryId}/${type}`] = entry;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return { components };
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Creates a per-provider/per-widget registry instance.
|
|
85
|
+
*
|
|
86
|
+
* Cache semantics: loads are keyed by libraryId for the instance's lifetime —
|
|
87
|
+
* the first successful load wins, so re-renders with structurally identical
|
|
88
|
+
* inline registration maps perform zero new loads (registration thunks are
|
|
89
|
+
* invoked at most once per id per instance).
|
|
90
|
+
*/
|
|
91
|
+
function createComponentLibraryRegistry() {
|
|
92
|
+
const loaded = new Map();
|
|
93
|
+
const pending = new Map();
|
|
94
|
+
const failed = new Map();
|
|
95
|
+
// Composed-plugin cache so repeated renders get a stable plugin object.
|
|
96
|
+
const composed = new Map();
|
|
97
|
+
let loadedVersion = 0;
|
|
98
|
+
function storeLoadedModule(libraryId, module) {
|
|
99
|
+
if (loaded.get(libraryId) === module) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (module.manifest?.id && module.manifest.id !== libraryId) {
|
|
103
|
+
console.warn(`RuleCMS widget: component library registered as "${libraryId}" declares ` +
|
|
104
|
+
`manifest id "${module.manifest.id}". The registered id wins for resolution.`);
|
|
105
|
+
}
|
|
106
|
+
loaded.set(libraryId, module);
|
|
107
|
+
loadedVersion += 1;
|
|
108
|
+
}
|
|
109
|
+
function composeFromLoaded(referenced) {
|
|
110
|
+
const ids = requiredLibraryIds(referenced);
|
|
111
|
+
const cacheKey = [...ids].sort().join('|');
|
|
112
|
+
const cached = composed.get(cacheKey);
|
|
113
|
+
if (cached && cached.loadedVersion === loadedVersion) {
|
|
114
|
+
return cached.plugin;
|
|
115
|
+
}
|
|
116
|
+
const modules = new Map();
|
|
117
|
+
for (const id of ids) {
|
|
118
|
+
const module = loaded.get(id);
|
|
119
|
+
if (module) {
|
|
120
|
+
modules.set(id, module);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
const plugin = composeSourceComponentsPlugin(modules);
|
|
124
|
+
composed.set(cacheKey, { loadedVersion, plugin });
|
|
125
|
+
return plugin;
|
|
126
|
+
}
|
|
127
|
+
function resolveSync(params) {
|
|
128
|
+
assertDefaultLibraryRegistered(params);
|
|
129
|
+
const { registrations, referenced } = params;
|
|
130
|
+
for (const id of requiredLibraryIds(referenced)) {
|
|
131
|
+
if (loaded.has(id) || failed.has(id)) {
|
|
132
|
+
continue;
|
|
133
|
+
}
|
|
134
|
+
const registration = registrations?.[id];
|
|
135
|
+
if (!registration) {
|
|
136
|
+
console.error(`RuleCMS widget: no component library registered for libraryId "${id}"; ` +
|
|
137
|
+
'its components will not render.');
|
|
138
|
+
failed.set(id, new Error(`No registration for libraryId "${id}"`));
|
|
139
|
+
continue;
|
|
140
|
+
}
|
|
141
|
+
if (typeof registration === 'function') {
|
|
142
|
+
// Thunk not loaded yet — async resolution required.
|
|
143
|
+
return null;
|
|
144
|
+
}
|
|
145
|
+
storeLoadedModule(id, registration);
|
|
146
|
+
}
|
|
147
|
+
return composeFromLoaded(referenced);
|
|
148
|
+
}
|
|
149
|
+
async function resolve(params) {
|
|
150
|
+
assertDefaultLibraryRegistered(params);
|
|
151
|
+
const { registrations, referenced } = params;
|
|
152
|
+
const ids = requiredLibraryIds(referenced);
|
|
153
|
+
await Promise.all(ids.map(async (id) => {
|
|
154
|
+
if (loaded.has(id) || failed.has(id)) {
|
|
155
|
+
return;
|
|
156
|
+
}
|
|
157
|
+
const registration = registrations?.[id];
|
|
158
|
+
if (!registration) {
|
|
159
|
+
console.error(`RuleCMS widget: no component library registered for libraryId "${id}"; ` +
|
|
160
|
+
'its components will not render.');
|
|
161
|
+
failed.set(id, new Error(`No registration for libraryId "${id}"`));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
if (typeof registration !== 'function') {
|
|
165
|
+
storeLoadedModule(id, registration);
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
let load = pending.get(id);
|
|
169
|
+
if (!load) {
|
|
170
|
+
load = registration()
|
|
171
|
+
.then((resolved) => {
|
|
172
|
+
const module = normalizeResolvedModule(resolved);
|
|
173
|
+
if (!module) {
|
|
174
|
+
throw new Error(`Registration for libraryId "${id}" did not resolve to a ` +
|
|
175
|
+
'ComponentLibraryModule (expected { manifest, components }).');
|
|
176
|
+
}
|
|
177
|
+
storeLoadedModule(id, module);
|
|
178
|
+
})
|
|
179
|
+
.catch((error) => {
|
|
180
|
+
// Per-library error isolation: record and continue; the other
|
|
181
|
+
// libraries keep rendering and this one falls back per component.
|
|
182
|
+
failed.set(id, error);
|
|
183
|
+
console.error(`RuleCMS widget: failed to load component library "${id}":`, error);
|
|
184
|
+
})
|
|
185
|
+
.finally(() => {
|
|
186
|
+
pending.delete(id);
|
|
187
|
+
});
|
|
188
|
+
pending.set(id, load);
|
|
189
|
+
}
|
|
190
|
+
await load;
|
|
191
|
+
}));
|
|
192
|
+
return composeFromLoaded(referenced);
|
|
193
|
+
}
|
|
194
|
+
return { resolveSync, resolve };
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
// Types needed by render-components
|
|
198
|
+
const PageViewTypes = {
|
|
199
|
+
Preview: 'Preview',
|
|
200
|
+
Compose: 'Compose',
|
|
201
|
+
RenderedPage: 'RenderedPage',
|
|
202
|
+
};
|
|
203
|
+
// this could also be a value that specifies the type of the component
|
|
204
|
+
// all the possible values are not added here as it is very dynamic and depends on the component being added to the compose area
|
|
205
|
+
const DisplayItemTypes = {
|
|
206
|
+
DroppableBox: 'droppable-box'
|
|
207
|
+
};
|
|
208
|
+
const JustifyContentTypes = {
|
|
209
|
+
FlexStart: 'flex-start',
|
|
210
|
+
FlexEnd: 'flex-end',
|
|
211
|
+
Center: 'center',
|
|
212
|
+
SpaceBetween: 'space-between',
|
|
213
|
+
SpaceAround: 'space-around',
|
|
214
|
+
SpaceEvenly: 'space-evenly',
|
|
215
|
+
};
|
|
216
|
+
const AlignContentTypes = {
|
|
217
|
+
FlexStart: 'flex-start',
|
|
218
|
+
FlexEnd: 'flex-end',
|
|
219
|
+
Center: 'center',
|
|
220
|
+
SpaceBetween: 'space-between',
|
|
221
|
+
SpaceAround: 'space-around',
|
|
222
|
+
SpaceEvenly: 'space-evenly',
|
|
223
|
+
Stretch: 'stretch',
|
|
224
|
+
};
|
|
225
|
+
const cssAttrArrayKey = 'cssAttrArray';
|
|
226
|
+
const DeviceDisplayTypes = {
|
|
227
|
+
Phone: 'phone',
|
|
228
|
+
Tablet: 'tablet',
|
|
229
|
+
Desktop: 'desktop',
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// Type definitions for ID and name parsing utilities
|
|
233
|
+
const DragItemIdPrefixTypes = {
|
|
234
|
+
ComposerComponent: "ComposerWidget",
|
|
235
|
+
Collection: "Collection",
|
|
236
|
+
MoveComponentHandle: "MoveWidgetHandle",
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const COLLECTION_TYPE_PREFIX = `${DragItemIdPrefixTypes.Collection}_`;
|
|
240
|
+
|
|
241
|
+
/** Prefix on RulesCMS client tokens for Development / non-publishable environments. */
|
|
242
|
+
const DEV_CLIENT_TOKEN_PREFIX = 'dev.';
|
|
243
|
+
/** Live draft API host — RulesCMS production (never relative / local). */
|
|
244
|
+
const RULECMS_API_ORIGIN = 'https://rulecms.com';
|
|
245
|
+
/** Published (cached) API host. */
|
|
246
|
+
const WIDGET_CACHE_API_ORIGIN = 'https://widget-cache.rulecms.com';
|
|
247
|
+
/** Published (cached) client API path. */
|
|
248
|
+
const PUBLISHED_WIDGET_API_PATH = '/api/v1/c/widget/get';
|
|
249
|
+
/** Live draft client API path — no cache; reads the widget table directly. */
|
|
250
|
+
const DEV_WIDGET_API_PATH = '/api/v1/c/dev/widget/get';
|
|
251
|
+
function isDevClientToken(token) {
|
|
252
|
+
return typeof token === 'string' && token.startsWith(DEV_CLIENT_TOKEN_PREFIX);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Resolves the API origin. Consumers should not need to set `endpoint` —
|
|
256
|
+
* Development tokens hit RulesCMS; published tokens hit widget-cache.
|
|
257
|
+
* An explicit `endpoint` is only an override (e.g. tests).
|
|
258
|
+
*/
|
|
259
|
+
function resolveWidgetApiOrigin(token, endpoint) {
|
|
260
|
+
if (endpoint) {
|
|
261
|
+
return endpoint.replace(/\/$/, '');
|
|
262
|
+
}
|
|
263
|
+
return isDevClientToken(token) ? RULECMS_API_ORIGIN : WIDGET_CACHE_API_ORIGIN;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Builds the widget fetch URL. Development tokens (`dev.…`) hit the uncached
|
|
267
|
+
* draft endpoint with `widgetKey`; everything else uses the published API.
|
|
268
|
+
*/
|
|
269
|
+
function buildWidgetFetchUrl({ publishedKey, token, endpoint, }) {
|
|
270
|
+
const isDev = isDevClientToken(token);
|
|
271
|
+
const apiPath = isDev ? DEV_WIDGET_API_PATH : PUBLISHED_WIDGET_API_PATH;
|
|
272
|
+
const queryParams = isDev
|
|
273
|
+
? new URLSearchParams({ widgetKey: publishedKey, token })
|
|
274
|
+
: new URLSearchParams({ publishedKey, token });
|
|
275
|
+
const origin = resolveWidgetApiOrigin(token, endpoint);
|
|
276
|
+
return `${origin}${apiPath}?${queryParams.toString()}`;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const getDragItemId = ({ id, prefix }) => {
|
|
280
|
+
return `${prefix}_${id}`;
|
|
281
|
+
};
|
|
282
|
+
const getDragItemPrefixAndId = (combinedVal) => {
|
|
283
|
+
if (!combinedVal?.length || !combinedVal.includes("_")) {
|
|
284
|
+
console.error(`Invalid drag item id: ${combinedVal}. Type does not exist.`);
|
|
285
|
+
return undefined;
|
|
286
|
+
}
|
|
287
|
+
return getIdAndPrefix(combinedVal);
|
|
288
|
+
};
|
|
289
|
+
const typeHasPrefix = (type) => {
|
|
290
|
+
return type.includes("_");
|
|
291
|
+
};
|
|
292
|
+
const getIdAndPrefix = (combinedVal) => {
|
|
293
|
+
const firstUnderscoreIndex = combinedVal.indexOf("_");
|
|
294
|
+
const prefix = combinedVal.substring(0, firstUnderscoreIndex);
|
|
295
|
+
// after publishing, ids could have more than this one _, so make sure
|
|
296
|
+
// to not lose the rest of the id by splitting on the first _
|
|
297
|
+
const itemId = combinedVal.substring(firstUnderscoreIndex + 1);
|
|
298
|
+
return {
|
|
299
|
+
prefix: prefix,
|
|
300
|
+
id: itemId,
|
|
301
|
+
};
|
|
302
|
+
};
|
|
303
|
+
|
|
304
|
+
const getCollectionIdForCollectionType = (componentType) => {
|
|
305
|
+
const hasPrefix = typeHasPrefix(componentType);
|
|
306
|
+
if (!hasPrefix) {
|
|
307
|
+
return undefined;
|
|
308
|
+
}
|
|
309
|
+
const prefixAndId = getDragItemPrefixAndId(componentType);
|
|
310
|
+
const isCollection = prefixAndId?.prefix === DragItemIdPrefixTypes.Collection;
|
|
311
|
+
if (!isCollection) {
|
|
312
|
+
console.error('getCollectionIdForCollectionType - Invalid component type: ${componentType}. Invalid prefix type.');
|
|
313
|
+
}
|
|
314
|
+
return prefixAndId?.id;
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// key can be in two formats
|
|
318
|
+
// 1. name$collectionId
|
|
319
|
+
// 2. name$collectionId@parentId
|
|
320
|
+
const getNameAndInstanceIdFromWidgetKey = (widgetKey) => {
|
|
321
|
+
if (!widgetKey?.length) {
|
|
322
|
+
console.error('getNameAndInstanceIdFromWidgetKey: Missing widget key');
|
|
323
|
+
return;
|
|
324
|
+
}
|
|
325
|
+
const split = widgetKey.split('$');
|
|
326
|
+
if (split.length < 2) {
|
|
327
|
+
console.error('getNameAndInstanceIdFromWidgetKey: Invalid widget key format');
|
|
328
|
+
return;
|
|
329
|
+
}
|
|
330
|
+
const name = split[0];
|
|
331
|
+
const parentIdExists = split[1].includes('@');
|
|
332
|
+
if (!parentIdExists) {
|
|
333
|
+
return { name, instanceId: split[1] };
|
|
334
|
+
}
|
|
335
|
+
const idSplit = split[1].split('@');
|
|
336
|
+
return { name, instanceId: idSplit[0], parentId: idSplit[1] };
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// key can be in two formats
|
|
340
|
+
// 1. name$collectionId
|
|
341
|
+
// 2. name$collectionId@parentId
|
|
342
|
+
const getNameFromWidgetKey = (widgetKey) => {
|
|
343
|
+
if (!widgetKey?.length) {
|
|
344
|
+
return { errorMessage: 'getNameFromWidgetKey: Missing widget key' };
|
|
345
|
+
}
|
|
346
|
+
const split = widgetKey.split('$');
|
|
347
|
+
if (split.length < 2) {
|
|
348
|
+
return { errorMessage: 'getNameFromWidgetKey: Invalid widget key format' };
|
|
349
|
+
}
|
|
350
|
+
return { name: split[0] };
|
|
351
|
+
};
|
|
352
|
+
|
|
353
|
+
// returns a key in two formats
|
|
354
|
+
// name$collectionId
|
|
355
|
+
// name$collectionId@parentId
|
|
356
|
+
const getWidgetKeyForCollection = (collection) => {
|
|
357
|
+
if (!collection) {
|
|
358
|
+
return { error: 'getWidgetKeyForCollection: Missing collection' };
|
|
359
|
+
}
|
|
360
|
+
if (!collection.name?.length) {
|
|
361
|
+
return { error: 'getWidgetKeyForCollection: Missing collection name' };
|
|
362
|
+
}
|
|
363
|
+
const name = collection.name?.trim().toLowerCase();
|
|
364
|
+
if (!collection.id?.length) {
|
|
365
|
+
return { error: 'getWidgetKeyForCollection: Missing collection id' };
|
|
366
|
+
}
|
|
367
|
+
const parentIdExists = collection.parentId?.length;
|
|
368
|
+
const idPart = parentIdExists ? `${collection.id}@${collection.parentId}` : `${collection.id}`;
|
|
369
|
+
return { data: `${name}$${idPart}` };
|
|
370
|
+
};
|
|
371
|
+
// returns a key in two formats for published collections
|
|
372
|
+
// name$publishedKey
|
|
373
|
+
// name$publishedKey@parentId
|
|
374
|
+
const getWidgetKeyForPublishedCollection = (collection) => {
|
|
375
|
+
if (!collection) {
|
|
376
|
+
return { error: 'getWidgetKeyForPublishedCollection: Missing collection' };
|
|
377
|
+
}
|
|
378
|
+
if (!collection.name?.length) {
|
|
379
|
+
return { error: 'getWidgetKeyForPublishedCollection: Missing collection name' };
|
|
380
|
+
}
|
|
381
|
+
const name = collection.name?.trim().toLowerCase();
|
|
382
|
+
if (!collection.publishedKey?.length) {
|
|
383
|
+
return { error: 'getWidgetKeyForPublishedCollection: Missing collection publishedKey' };
|
|
384
|
+
}
|
|
385
|
+
const parentIdExists = collection.parentId?.length;
|
|
386
|
+
const idPart = parentIdExists ? `${collection.publishedKey}@${collection.parentId}` : `${collection.publishedKey}`;
|
|
387
|
+
return { data: `${name}$${idPart}` };
|
|
388
|
+
};
|
|
389
|
+
/**
|
|
390
|
+
* Returns a key in the format of collectionId or Collection_collectionName$collectionId@parentId or Collection_collectionName$collectionId
|
|
391
|
+
* @param collection - The collection to get the key for
|
|
392
|
+
* @returns The key in the format of collectionId or collectionId@parentId
|
|
393
|
+
*/
|
|
394
|
+
const getWidgetKeyForCollectionWithPrefix = (collection) => {
|
|
395
|
+
const key = getWidgetKeyForCollection(collection);
|
|
396
|
+
return `${COLLECTION_TYPE_PREFIX}${key.data}`;
|
|
397
|
+
};
|
|
398
|
+
/**
|
|
399
|
+
* Returns a key for published collections in the format of PublishedCollection_collectionName$publishedKey@parentId or PublishedCollection_collectionName$publishedKey
|
|
400
|
+
* @param collection - The published collection to get the key for
|
|
401
|
+
* @returns The key in the format of PublishedCollection_collectionName$publishedKey or PublishedCollection_collectionName$publishedKey@parentId
|
|
402
|
+
*/
|
|
403
|
+
const getWidgetKeyForPublishedCollectionWithPrefix = (collection) => {
|
|
404
|
+
const key = getWidgetKeyForPublishedCollection(collection);
|
|
405
|
+
return `${COLLECTION_TYPE_PREFIX}${key.data}`;
|
|
406
|
+
};
|
|
407
|
+
|
|
408
|
+
/**
|
|
409
|
+
* Character used to join environmentId and resource key when generating published keys
|
|
410
|
+
*/
|
|
411
|
+
const PUBLISHED_KEY_SEPARATOR = '---';
|
|
412
|
+
/**
|
|
413
|
+
* Character used to separate embedded published key from its parent
|
|
414
|
+
*/
|
|
415
|
+
const EMBEDDED_KEY_SEPARATOR = '___';
|
|
416
|
+
/**
|
|
417
|
+
* Generates a published key using the format: {environmentId}---{originalKey}
|
|
418
|
+
* @param environmentId - The environment ID
|
|
419
|
+
* @param originalKey - The original resource key
|
|
420
|
+
* @returns The generated published key
|
|
421
|
+
*/
|
|
422
|
+
function generatePublishedKey(environmentId, originalKey) {
|
|
423
|
+
return `${environmentId}${PUBLISHED_KEY_SEPARATOR}${originalKey}`;
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Generates a published key for embedded resources using the format: {environmentId}---{originalKey}___{instanceId}
|
|
427
|
+
* @param environmentId - The environment ID
|
|
428
|
+
* @param originalKey - The original resource key
|
|
429
|
+
* @param instanceId - The instance ID of the unpublished collection
|
|
430
|
+
* @returns The generated published key for embedded resource
|
|
431
|
+
*/
|
|
432
|
+
function generatePublishedKeyForEmbedded(environmentId, originalKey, instanceId) {
|
|
433
|
+
const publishedKey = generatePublishedKey(environmentId, originalKey);
|
|
434
|
+
return `${publishedKey}${EMBEDDED_KEY_SEPARATOR}${instanceId}`;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
/**
|
|
438
|
+
* Increments a semantic version string by incrementing the patch number
|
|
439
|
+
* @param currentVersion - Current version string (e.g., "1.0.0")
|
|
440
|
+
* @returns Incremented version string (e.g., "1.0.1")
|
|
441
|
+
*/
|
|
442
|
+
function incrementVersion(currentVersion) {
|
|
443
|
+
const parts = currentVersion.split('.');
|
|
444
|
+
if (parts.length !== 3) {
|
|
445
|
+
throw new Error(`Invalid version format: ${currentVersion}. Expected format: x.y.z`);
|
|
446
|
+
}
|
|
447
|
+
const major = parts[0];
|
|
448
|
+
const minor = parts[1];
|
|
449
|
+
const patch = parseInt(parts[2], 10);
|
|
450
|
+
if (isNaN(patch)) {
|
|
451
|
+
throw new Error(`Invalid patch version: ${parts[2]}. Expected a number.`);
|
|
452
|
+
}
|
|
453
|
+
return `${major}.${minor}.${patch + 1}`;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
/**
|
|
457
|
+
* Scans a widget config (display item list + all collections, including
|
|
458
|
+
* embedded ones) and returns the set of library ids it references.
|
|
459
|
+
*
|
|
460
|
+
* CRITICAL scaling property: resolution is config-scoped — only the libraries
|
|
461
|
+
* returned here are ever loaded, never the consumer's whole registration map.
|
|
462
|
+
*
|
|
463
|
+
* Prefixed types (collections / drag items) are not components and never
|
|
464
|
+
* contribute a library reference; a component column with no libraryId (or
|
|
465
|
+
* the reserved "default" id) references the default library.
|
|
466
|
+
*/
|
|
467
|
+
function collectReferencedLibraryIds({ displayItemList, widgetCollections, }) {
|
|
468
|
+
const libraryIds = new Set();
|
|
469
|
+
let usesDefaultLibrary = false;
|
|
470
|
+
const visitItems = (items) => {
|
|
471
|
+
if (!items?.rows?.length) {
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
474
|
+
for (const row of items.rows) {
|
|
475
|
+
if (!row?.columns?.length) {
|
|
476
|
+
continue;
|
|
477
|
+
}
|
|
478
|
+
for (const col of row.columns) {
|
|
479
|
+
if (col.collection) {
|
|
480
|
+
visitItems(col.collection.collectionRows);
|
|
481
|
+
}
|
|
482
|
+
if (!col.type || col.type === DisplayItemTypes.DroppableBox) {
|
|
483
|
+
continue;
|
|
484
|
+
}
|
|
485
|
+
if (typeHasPrefix(col.type)) {
|
|
486
|
+
// Collection (or other drag-item) reference — not a component.
|
|
487
|
+
continue;
|
|
488
|
+
}
|
|
489
|
+
if (!col.libraryId?.length || col.libraryId === DEFAULT_LIBRARY_ID) {
|
|
490
|
+
usesDefaultLibrary = true;
|
|
491
|
+
}
|
|
492
|
+
else {
|
|
493
|
+
libraryIds.add(col.libraryId);
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
};
|
|
498
|
+
visitItems(displayItemList);
|
|
499
|
+
for (const collection of Object.values(widgetCollections ?? {})) {
|
|
500
|
+
visitItems(collection?.collectionRows);
|
|
501
|
+
}
|
|
502
|
+
return { libraryIds: Array.from(libraryIds), usesDefaultLibrary };
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
class RuleCMSWidgetContextService {
|
|
506
|
+
constructor() {
|
|
507
|
+
this.token = '';
|
|
508
|
+
this.libraryRegistry = createComponentLibraryRegistry();
|
|
509
|
+
}
|
|
510
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetContextService, deps: [], target: i0.ɵɵFactoryTarget.Injectable }); }
|
|
511
|
+
static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetContextService }); }
|
|
512
|
+
}
|
|
513
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetContextService, decorators: [{
|
|
514
|
+
type: Injectable
|
|
515
|
+
}] });
|
|
516
|
+
|
|
517
|
+
class RuleCMSWidgetProviderComponent {
|
|
518
|
+
constructor(context) {
|
|
519
|
+
this.context = context;
|
|
520
|
+
}
|
|
521
|
+
ngOnChanges(_changes) {
|
|
522
|
+
this.context.token = this.token;
|
|
523
|
+
this.context.endpoint = this.endpoint;
|
|
524
|
+
this.context.libraries = this.libraries;
|
|
525
|
+
}
|
|
526
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetProviderComponent, deps: [{ token: RuleCMSWidgetContextService }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
527
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: RuleCMSWidgetProviderComponent, isStandalone: true, selector: "rulecms-widget-provider", inputs: { token: "token", endpoint: "endpoint", libraries: "libraries" }, host: { styleAttribute: "display: contents" }, providers: [RuleCMSWidgetContextService], usesOnChanges: true, ngImport: i0, template: `<ng-content />`, isInline: true }); }
|
|
528
|
+
}
|
|
529
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetProviderComponent, decorators: [{
|
|
530
|
+
type: Component,
|
|
531
|
+
args: [{
|
|
532
|
+
selector: 'rulecms-widget-provider',
|
|
533
|
+
standalone: true,
|
|
534
|
+
template: `<ng-content />`,
|
|
535
|
+
host: { style: 'display: contents' },
|
|
536
|
+
providers: [RuleCMSWidgetContextService],
|
|
537
|
+
}]
|
|
538
|
+
}], ctorParameters: () => [{ type: RuleCMSWidgetContextService }], propDecorators: { token: [{
|
|
539
|
+
type: Input,
|
|
540
|
+
args: [{ required: true }]
|
|
541
|
+
}], endpoint: [{
|
|
542
|
+
type: Input
|
|
543
|
+
}], libraries: [{
|
|
544
|
+
type: Input
|
|
545
|
+
}] } });
|
|
546
|
+
|
|
547
|
+
// Device display width constants
|
|
548
|
+
const defaultPageWidth = "1200px";
|
|
549
|
+
const phoneModeWidth = "500px";
|
|
550
|
+
const tabletModeWidth = "820px";
|
|
551
|
+
const desktopModeWidth = defaultPageWidth;
|
|
552
|
+
|
|
553
|
+
// Builds Cloudinary delivery URLs for background images.
|
|
554
|
+
//
|
|
555
|
+
// This mirrors source-components-react's build-cloudinary-image-urls, which
|
|
556
|
+
// cannot be imported here: that package is a devDependency of this one, and
|
|
557
|
+
// widget-react deliberately ships with almost no runtime dependencies.
|
|
558
|
+
//
|
|
559
|
+
// `f_auto,q_auto` lets Cloudinary pick format and quality; `c_limit` scales
|
|
560
|
+
// down but never upscales past the original asset.
|
|
561
|
+
/** The cloud that hosts both team uploads and the shared RuleCMS library. */
|
|
562
|
+
const DEFAULT_CLOUDINARY_CLOUD_NAME = 'rulecms';
|
|
563
|
+
// Wide enough for a full-bleed background on a large display without shipping a
|
|
564
|
+
// multi-thousand-pixel original. A CSS background cannot use srcset, and
|
|
565
|
+
// image-set() selects on device pixel ratio rather than viewport width, so one
|
|
566
|
+
// width is served per device bucket; per-device art direction comes from the
|
|
567
|
+
// phone/tablet/desktop leaves instead.
|
|
568
|
+
const DEFAULT_BACKGROUND_WIDTH = 1920;
|
|
569
|
+
const defaultTransformations = {
|
|
570
|
+
f: 'auto',
|
|
571
|
+
q: 'auto',
|
|
572
|
+
c: 'limit',
|
|
573
|
+
};
|
|
574
|
+
// A public id is interpolated into `url(...)` inside an inline style, so it must
|
|
575
|
+
// not be able to close the url() call or the surrounding quotes. Cloudinary ids
|
|
576
|
+
// are folder-ish paths ("images/<uuid>/<name>"), which this covers without
|
|
577
|
+
// admitting quotes, parentheses, whitespace or backslashes.
|
|
578
|
+
const CLOUDINARY_PUBLIC_ID_PATTERN = /^[A-Za-z0-9][A-Za-z0-9._\-/]*$/;
|
|
579
|
+
const CLOUDINARY_PUBLIC_ID_MAX_LENGTH = 300;
|
|
580
|
+
const CLOUDINARY_CLOUD_NAME_PATTERN = /^[A-Za-z0-9][A-Za-z0-9_-]*$/;
|
|
581
|
+
const CLOUDINARY_CLOUD_NAME_MAX_LENGTH = 100;
|
|
582
|
+
// Same containment rule as the public id. https only: a widget embedded on an
|
|
583
|
+
// https page has its http subresources blocked as mixed content anyway.
|
|
584
|
+
const SAFE_IMAGE_URL_PATTERN = /^https:\/\/[^\s"'()\\<>]+$/;
|
|
585
|
+
const SAFE_IMAGE_URL_MAX_LENGTH = 2000;
|
|
586
|
+
const TRANSFORMATION_STRING_PATTERN = /^[A-Za-z0-9_,.:\-/]*$/;
|
|
587
|
+
const TRANSFORMATION_STRING_MAX_LENGTH = 300;
|
|
588
|
+
const isCloudinaryPublicId = (value) => typeof value === 'string' &&
|
|
589
|
+
value.length <= CLOUDINARY_PUBLIC_ID_MAX_LENGTH &&
|
|
590
|
+
CLOUDINARY_PUBLIC_ID_PATTERN.test(value);
|
|
591
|
+
const isCloudinaryCloudName = (value) => typeof value === 'string' &&
|
|
592
|
+
value.length <= CLOUDINARY_CLOUD_NAME_MAX_LENGTH &&
|
|
593
|
+
CLOUDINARY_CLOUD_NAME_PATTERN.test(value);
|
|
594
|
+
const isSafeImageUrl = (value) => typeof value === 'string' &&
|
|
595
|
+
value.length <= SAFE_IMAGE_URL_MAX_LENGTH &&
|
|
596
|
+
SAFE_IMAGE_URL_PATTERN.test(value);
|
|
597
|
+
const isCloudinaryTransformationString = (value) => typeof value === 'string' &&
|
|
598
|
+
value.length <= TRANSFORMATION_STRING_MAX_LENGTH &&
|
|
599
|
+
TRANSFORMATION_STRING_PATTERN.test(value);
|
|
600
|
+
const serializeTransformations = (transformations) => Object.entries(transformations)
|
|
601
|
+
.map(([key, value]) => `${key}_${value}`)
|
|
602
|
+
.join(',');
|
|
603
|
+
// Accepts the raw Cloudinary string form ("c_fill,g_auto") and parses it into an
|
|
604
|
+
// object so it merges over the defaults the same way object input does — a user
|
|
605
|
+
// c_fill cleanly replaces the default c_limit rather than appending to it.
|
|
606
|
+
const parseTransformationString = (value) => {
|
|
607
|
+
const result = {};
|
|
608
|
+
for (const entry of value.split(',')) {
|
|
609
|
+
const trimmed = entry.trim();
|
|
610
|
+
const separatorIndex = trimmed.indexOf('_');
|
|
611
|
+
if (separatorIndex <= 0) {
|
|
612
|
+
continue;
|
|
613
|
+
}
|
|
614
|
+
result[trimmed.slice(0, separatorIndex)] = trimmed.slice(separatorIndex + 1);
|
|
615
|
+
}
|
|
616
|
+
return result;
|
|
617
|
+
};
|
|
618
|
+
const buildCloudinaryBackgroundUrl = ({ publicId, cloudName = DEFAULT_CLOUDINARY_CLOUD_NAME, transformations, width = DEFAULT_BACKGROUND_WIDTH, }) => {
|
|
619
|
+
const userTransformations = typeof transformations === 'string'
|
|
620
|
+
? parseTransformationString(transformations)
|
|
621
|
+
: transformations;
|
|
622
|
+
// A user-supplied width would desync from the device bucket this URL is being
|
|
623
|
+
// built for, so `w` stays owned by the caller.
|
|
624
|
+
const merged = {
|
|
625
|
+
...defaultTransformations,
|
|
626
|
+
...userTransformations,
|
|
627
|
+
w: width,
|
|
628
|
+
};
|
|
629
|
+
// encodeURI preserves the slashes that are part of a public id while escaping
|
|
630
|
+
// unsafe characters.
|
|
631
|
+
return encodeURI(`https://res.cloudinary.com/${cloudName}/image/upload/${serializeTransformations(merged)}/${publicId}`);
|
|
632
|
+
};
|
|
633
|
+
|
|
634
|
+
// CSS custom property ("design token") references for style attribute leaves.
|
|
635
|
+
//
|
|
636
|
+
// Composer users can switch any CSS-valued control from a literal value to a
|
|
637
|
+
// token so the embedding application's design system supplies the value at
|
|
638
|
+
// runtime. We never check that the custom property exists: it usually only
|
|
639
|
+
// exists in the consuming app, not in RuleCMS.
|
|
640
|
+
//
|
|
641
|
+
// The token rides along as an optional `cssVariable` prop on the existing leaf
|
|
642
|
+
// rather than as a new leaf shape, so nothing about the stored value types
|
|
643
|
+
// changes for callers that do not care about tokens. When present, the token
|
|
644
|
+
// always wins over the literal value on the same leaf — hand-authored JSON can
|
|
645
|
+
// carry both, and the token is the more specific intent.
|
|
646
|
+
const CSS_VARIABLE_NAME_PATTERN = /^--[A-Za-z0-9_-]+$/;
|
|
647
|
+
// Long enough for deeply namespaced design tokens, short enough that a pasted
|
|
648
|
+
// stylesheet cannot land in a style attribute.
|
|
649
|
+
const CSS_VARIABLE_NAME_MAX_LENGTH = 200;
|
|
650
|
+
const isCssVariableName = (value) => {
|
|
651
|
+
if (typeof value !== 'string') {
|
|
652
|
+
return false;
|
|
653
|
+
}
|
|
654
|
+
const trimmed = value.trim();
|
|
655
|
+
return (trimmed.length <= CSS_VARIABLE_NAME_MAX_LENGTH && CSS_VARIABLE_NAME_PATTERN.test(trimmed));
|
|
656
|
+
};
|
|
657
|
+
/** `--brand-space-md` → `var(--brand-space-md)` */
|
|
658
|
+
const formatCssVariable = (name) => `var(${name.trim()})`;
|
|
659
|
+
/**
|
|
660
|
+
* Reads the token off any leaf shape. Returns undefined when the leaf carries
|
|
661
|
+
* no token; `null` counts as absent the same way it does elsewhere in this
|
|
662
|
+
* pipeline.
|
|
663
|
+
*/
|
|
664
|
+
const getCssVariableFromLeaf = (leaf) => {
|
|
665
|
+
if (typeof leaf !== 'object' || leaf === null || Array.isArray(leaf)) {
|
|
666
|
+
return undefined;
|
|
667
|
+
}
|
|
668
|
+
const candidate = leaf.cssVariable;
|
|
669
|
+
if (candidate === undefined || candidate === null) {
|
|
670
|
+
return undefined;
|
|
671
|
+
}
|
|
672
|
+
return isCssVariableName(candidate) ? candidate.trim() : undefined;
|
|
673
|
+
};
|
|
674
|
+
/**
|
|
675
|
+
* True when a leaf declares a `cssVariable` that fails validation. Such leaves
|
|
676
|
+
* are rejected outright instead of silently falling back to the literal value:
|
|
677
|
+
* a typo in a token should drop the property, not resurrect a number the user
|
|
678
|
+
* thought they had replaced.
|
|
679
|
+
*/
|
|
680
|
+
const hasInvalidCssVariable = (leaf) => {
|
|
681
|
+
if (typeof leaf !== 'object' || leaf === null || Array.isArray(leaf)) {
|
|
682
|
+
return false;
|
|
683
|
+
}
|
|
684
|
+
const candidate = leaf.cssVariable;
|
|
685
|
+
if (candidate === undefined || candidate === null) {
|
|
686
|
+
return false;
|
|
687
|
+
}
|
|
688
|
+
return !isCssVariableName(candidate);
|
|
689
|
+
};
|
|
690
|
+
/** One React style entry from a leaf's token, or undefined when it has none. */
|
|
691
|
+
const formatCssVariableStyles = (leaf, cssProperty) => {
|
|
692
|
+
const name = getCssVariableFromLeaf(leaf);
|
|
693
|
+
return name ? { [cssProperty]: formatCssVariable(name) } : undefined;
|
|
694
|
+
};
|
|
695
|
+
|
|
696
|
+
const isBackgroundImageValue = (value) => {
|
|
697
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
if (hasInvalidCssVariable(value)) {
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
// A token wins over the literal beside it — see isCssColorValue.
|
|
704
|
+
if (getCssVariableFromLeaf(value)) {
|
|
705
|
+
return true;
|
|
706
|
+
}
|
|
707
|
+
const candidate = value;
|
|
708
|
+
if (candidate.source === 'none') {
|
|
709
|
+
return true;
|
|
710
|
+
}
|
|
711
|
+
if (candidate.source === 'url') {
|
|
712
|
+
return isSafeImageUrl(candidate.url);
|
|
713
|
+
}
|
|
714
|
+
if (candidate.source === 'cloudinary') {
|
|
715
|
+
if (!isCloudinaryPublicId(candidate.publicId)) {
|
|
716
|
+
return false;
|
|
717
|
+
}
|
|
718
|
+
if (candidate.cloudName !== undefined &&
|
|
719
|
+
candidate.cloudName !== null &&
|
|
720
|
+
!isCloudinaryCloudName(candidate.cloudName)) {
|
|
721
|
+
return false;
|
|
722
|
+
}
|
|
723
|
+
return (candidate.transformations === undefined ||
|
|
724
|
+
candidate.transformations === null ||
|
|
725
|
+
isCloudinaryTransformationString(candidate.transformations));
|
|
726
|
+
}
|
|
727
|
+
return false;
|
|
728
|
+
};
|
|
729
|
+
|
|
730
|
+
// Generic "box spacing" value shape shared by 4-sided CSS properties
|
|
731
|
+
// (margin today, padding later). Sides mirror the resolution-map convention
|
|
732
|
+
// one level down: `allSides` is preferred over the individual sides, the same
|
|
733
|
+
// way `all` is preferred over phone/tablet/desktop.
|
|
734
|
+
const spacingLengthUnits = ['px', '%', 'em', 'rem', 'vh', 'vw'];
|
|
735
|
+
const spacingKeywords = ['inherit', 'unset'];
|
|
736
|
+
const boxSpacingSideKeys = ['allSides', 'top', 'right', 'bottom', 'left'];
|
|
737
|
+
const isSpacingSideValue = (value, capabilities = {}) => {
|
|
738
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
739
|
+
return false;
|
|
740
|
+
}
|
|
741
|
+
const candidate = value;
|
|
742
|
+
if (hasInvalidCssVariable(value)) {
|
|
743
|
+
return false;
|
|
744
|
+
}
|
|
745
|
+
// A token wins over whatever literal value sits beside it, so the literal
|
|
746
|
+
// half is not validated at all — a preserved (or hand-typed) number cannot
|
|
747
|
+
// invalidate a leaf the user is driving from a design token. Capabilities
|
|
748
|
+
// are not enforced either: the property's own token vocabulary decides what
|
|
749
|
+
// is legal, and only the consuming app knows that.
|
|
750
|
+
if (getCssVariableFromLeaf(value)) {
|
|
751
|
+
return true;
|
|
752
|
+
}
|
|
753
|
+
if (candidate.unit === 'auto') {
|
|
754
|
+
return capabilities.allowAuto !== false;
|
|
755
|
+
}
|
|
756
|
+
if (candidate.unit === 'keyword') {
|
|
757
|
+
return (capabilities.allowKeywords !== false &&
|
|
758
|
+
spacingKeywords.includes(candidate.keyword));
|
|
759
|
+
}
|
|
760
|
+
if (spacingLengthUnits.includes(candidate.unit)) {
|
|
761
|
+
if (typeof candidate.value !== 'number' || !Number.isFinite(candidate.value)) {
|
|
762
|
+
return false;
|
|
763
|
+
}
|
|
764
|
+
return capabilities.allowNegative !== false || candidate.value >= 0;
|
|
765
|
+
}
|
|
766
|
+
return false;
|
|
767
|
+
};
|
|
768
|
+
// A value is a valid box-spacing object when it is a plain object and every
|
|
769
|
+
// side key that is present holds a valid side value. Malformed values should
|
|
770
|
+
// be ignored by callers (graceful degradation for old/new payload mixes).
|
|
771
|
+
const isBoxSpacingValue = (value, capabilities = {}) => {
|
|
772
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
773
|
+
return false;
|
|
774
|
+
}
|
|
775
|
+
const candidate = value;
|
|
776
|
+
for (const sideKey of boxSpacingSideKeys) {
|
|
777
|
+
const sideValue = candidate[sideKey];
|
|
778
|
+
if (sideValue === undefined || sideValue === null) {
|
|
779
|
+
continue;
|
|
780
|
+
}
|
|
781
|
+
if (!isSpacingSideValue(sideValue, capabilities)) {
|
|
782
|
+
return false;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
return true;
|
|
786
|
+
};
|
|
787
|
+
|
|
788
|
+
const colorKeywordAllowlist = [...spacingKeywords, 'transparent', 'currentColor'];
|
|
789
|
+
// Hex (#rgb, #rrggbb, #rrggbbaa) or rgb()/rgba()/hsl()/hsla()
|
|
790
|
+
const cssColorStringPattern = /^(#([0-9a-fA-F]{3}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})|rgba?\([^)]+\)|hsla?\([^)]+\))$/;
|
|
791
|
+
const isCssColorValue = (value) => {
|
|
792
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
const candidate = value;
|
|
796
|
+
if (hasInvalidCssVariable(value)) {
|
|
797
|
+
return false;
|
|
798
|
+
}
|
|
799
|
+
// A token wins over the literal colour beside it — see isSpacingSideValue.
|
|
800
|
+
if (getCssVariableFromLeaf(value)) {
|
|
801
|
+
return true;
|
|
802
|
+
}
|
|
803
|
+
if (candidate.unit === 'keyword') {
|
|
804
|
+
return colorKeywordAllowlist.includes(candidate.keyword);
|
|
805
|
+
}
|
|
806
|
+
if (candidate.unit === 'color') {
|
|
807
|
+
return typeof candidate.value === 'string' && cssColorStringPattern.test(candidate.value.trim());
|
|
808
|
+
}
|
|
809
|
+
return false;
|
|
810
|
+
};
|
|
811
|
+
const formatCssColorValue = (value) => {
|
|
812
|
+
const cssVariable = getCssVariableFromLeaf(value);
|
|
813
|
+
if (cssVariable) {
|
|
814
|
+
return formatCssVariable(cssVariable);
|
|
815
|
+
}
|
|
816
|
+
if (!('unit' in value)) {
|
|
817
|
+
return '';
|
|
818
|
+
}
|
|
819
|
+
if (value.unit === 'keyword') {
|
|
820
|
+
return value.keyword;
|
|
821
|
+
}
|
|
822
|
+
return value.value.trim();
|
|
823
|
+
};
|
|
824
|
+
|
|
825
|
+
const isCssEnumValue = (value, allowedValues) => {
|
|
826
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
827
|
+
return !hasInvalidCssVariable(value) && !!getCssVariableFromLeaf(value);
|
|
828
|
+
}
|
|
829
|
+
if (typeof value !== 'string' || !value.length) {
|
|
830
|
+
return false;
|
|
831
|
+
}
|
|
832
|
+
if (allowedValues.includes(value)) {
|
|
833
|
+
return true;
|
|
834
|
+
}
|
|
835
|
+
return spacingKeywords.includes(value);
|
|
836
|
+
};
|
|
837
|
+
// Curated font stacks for column typography (picker-only; not free text).
|
|
838
|
+
const fontFamilyAllowlist = [
|
|
839
|
+
'system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif',
|
|
840
|
+
'Georgia, "Times New Roman", Times, serif',
|
|
841
|
+
'ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace',
|
|
842
|
+
'Arial, Helvetica, sans-serif',
|
|
843
|
+
'"Helvetica Neue", Helvetica, Arial, sans-serif',
|
|
844
|
+
'Verdana, Geneva, sans-serif',
|
|
845
|
+
];
|
|
846
|
+
const fontWeightAllowlist = [
|
|
847
|
+
'normal',
|
|
848
|
+
'bold',
|
|
849
|
+
'100',
|
|
850
|
+
'200',
|
|
851
|
+
'300',
|
|
852
|
+
'400',
|
|
853
|
+
'500',
|
|
854
|
+
'600',
|
|
855
|
+
'700',
|
|
856
|
+
'800',
|
|
857
|
+
'900',
|
|
858
|
+
];
|
|
859
|
+
const fontStyleAllowlist = ['normal', 'italic', 'oblique'];
|
|
860
|
+
const textAlignAllowlist = [
|
|
861
|
+
'left',
|
|
862
|
+
'center',
|
|
863
|
+
'right',
|
|
864
|
+
'justify',
|
|
865
|
+
'start',
|
|
866
|
+
'end',
|
|
867
|
+
];
|
|
868
|
+
const textDecorationAllowlist = [
|
|
869
|
+
'none',
|
|
870
|
+
'underline',
|
|
871
|
+
'line-through',
|
|
872
|
+
'overline',
|
|
873
|
+
];
|
|
874
|
+
const textTransformAllowlist = [
|
|
875
|
+
'none',
|
|
876
|
+
'uppercase',
|
|
877
|
+
'lowercase',
|
|
878
|
+
'capitalize',
|
|
879
|
+
];
|
|
880
|
+
/** Shared by overflow / overflow-x / overflow-y. */
|
|
881
|
+
const overflowAllowlist = [
|
|
882
|
+
'visible',
|
|
883
|
+
'hidden',
|
|
884
|
+
'scroll',
|
|
885
|
+
'auto',
|
|
886
|
+
'clip',
|
|
887
|
+
];
|
|
888
|
+
/** Column flex layout — matches row Horizontal Alignment options. */
|
|
889
|
+
const justifyContentAllowlist = [
|
|
890
|
+
'flex-start',
|
|
891
|
+
'flex-end',
|
|
892
|
+
'center',
|
|
893
|
+
'space-between',
|
|
894
|
+
'space-around',
|
|
895
|
+
'space-evenly',
|
|
896
|
+
];
|
|
897
|
+
/** Column flex layout — matches row Vertical Alignment options. */
|
|
898
|
+
const alignItemsAllowlist = [
|
|
899
|
+
'flex-start',
|
|
900
|
+
'flex-end',
|
|
901
|
+
'center',
|
|
902
|
+
'baseline',
|
|
903
|
+
'stretch',
|
|
904
|
+
];
|
|
905
|
+
const flexWrapAllowlist = ['wrap', 'nowrap'];
|
|
906
|
+
/** Column flex layout — matches row Align Content options. */
|
|
907
|
+
const alignContentAllowlist = [
|
|
908
|
+
'flex-start',
|
|
909
|
+
'flex-end',
|
|
910
|
+
'center',
|
|
911
|
+
'space-between',
|
|
912
|
+
'space-around',
|
|
913
|
+
'space-evenly',
|
|
914
|
+
'stretch',
|
|
915
|
+
];
|
|
916
|
+
const flexDirectionAllowlist = [
|
|
917
|
+
'row',
|
|
918
|
+
'row-reverse',
|
|
919
|
+
'column',
|
|
920
|
+
'column-reverse',
|
|
921
|
+
];
|
|
922
|
+
/**
|
|
923
|
+
* Background painting, set alongside background-image. Keyword-only: a
|
|
924
|
+
* background without `cover`/`center` usually reads as broken, and these are the
|
|
925
|
+
* choices that fix it. Lengths and percentages are deliberately out of scope so
|
|
926
|
+
* the editor stays a picker.
|
|
927
|
+
*/
|
|
928
|
+
const backgroundSizeAllowlist = ['cover', 'contain', 'auto'];
|
|
929
|
+
const backgroundPositionAllowlist = [
|
|
930
|
+
'center center',
|
|
931
|
+
'center top',
|
|
932
|
+
'center bottom',
|
|
933
|
+
'left center',
|
|
934
|
+
'left top',
|
|
935
|
+
'left bottom',
|
|
936
|
+
'right center',
|
|
937
|
+
'right top',
|
|
938
|
+
'right bottom',
|
|
939
|
+
];
|
|
940
|
+
const backgroundRepeatAllowlist = [
|
|
941
|
+
'no-repeat',
|
|
942
|
+
'repeat',
|
|
943
|
+
'repeat-x',
|
|
944
|
+
'repeat-y',
|
|
945
|
+
'space',
|
|
946
|
+
'round',
|
|
947
|
+
];
|
|
948
|
+
/**
|
|
949
|
+
* Style keys that, when present on the flattened column styles, cause
|
|
950
|
+
* `display: flex` to be derived at render time. Gap alone is intentionally
|
|
951
|
+
* excluded — it does not force flex.
|
|
952
|
+
*/
|
|
953
|
+
const FLEX_LAYOUT_STYLE_KEYS_THAT_DERIVE_DISPLAY = [
|
|
954
|
+
'justifyContent',
|
|
955
|
+
'alignItems',
|
|
956
|
+
'flexWrap',
|
|
957
|
+
'alignContent',
|
|
958
|
+
'flexDirection',
|
|
959
|
+
];
|
|
960
|
+
|
|
961
|
+
const borderStyleKeywords = [
|
|
962
|
+
'none',
|
|
963
|
+
'solid',
|
|
964
|
+
'dashed',
|
|
965
|
+
'dotted',
|
|
966
|
+
'double',
|
|
967
|
+
'groove',
|
|
968
|
+
'ridge',
|
|
969
|
+
'inset',
|
|
970
|
+
'outset',
|
|
971
|
+
];
|
|
972
|
+
const isBorderStyleValue = (value) => {
|
|
973
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
974
|
+
return !hasInvalidCssVariable(value) && !!getCssVariableFromLeaf(value);
|
|
975
|
+
}
|
|
976
|
+
return borderStyleKeywords.includes(value);
|
|
977
|
+
};
|
|
978
|
+
const isBorderValue = (value) => {
|
|
979
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
980
|
+
return false;
|
|
981
|
+
}
|
|
982
|
+
const candidate = value;
|
|
983
|
+
if (hasInvalidCssVariable(value)) {
|
|
984
|
+
return false;
|
|
985
|
+
}
|
|
986
|
+
// Whole-border token wins over every part, so the parts go unvalidated.
|
|
987
|
+
if (getCssVariableFromLeaf(value)) {
|
|
988
|
+
return true;
|
|
989
|
+
}
|
|
990
|
+
if (candidate.width !== undefined &&
|
|
991
|
+
candidate.width !== null &&
|
|
992
|
+
!isSpacingSideValue(candidate.width, { allowAuto: false, allowNegative: false })) {
|
|
993
|
+
return false;
|
|
994
|
+
}
|
|
995
|
+
if (candidate.style !== undefined && candidate.style !== null && !isBorderStyleValue(candidate.style)) {
|
|
996
|
+
return false;
|
|
997
|
+
}
|
|
998
|
+
if (candidate.color !== undefined && candidate.color !== null && !isCssColorValue(candidate.color)) {
|
|
999
|
+
return false;
|
|
1000
|
+
}
|
|
1001
|
+
return true;
|
|
1002
|
+
};
|
|
1003
|
+
|
|
1004
|
+
// Shadow lengths are plain CSS lengths only: `auto` and the inherit/unset
|
|
1005
|
+
// keywords are invalid inside the box-shadow shorthand. Offsets and spread
|
|
1006
|
+
// may be negative; the blur radius may not.
|
|
1007
|
+
const offsetOrSpreadCapabilities = {
|
|
1008
|
+
allowAuto: false,
|
|
1009
|
+
allowKeywords: false,
|
|
1010
|
+
allowNegative: true,
|
|
1011
|
+
};
|
|
1012
|
+
const blurCapabilities = {
|
|
1013
|
+
allowAuto: false,
|
|
1014
|
+
allowKeywords: false,
|
|
1015
|
+
allowNegative: false,
|
|
1016
|
+
};
|
|
1017
|
+
const isBoxShadowValue = (value) => {
|
|
1018
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
1019
|
+
return false;
|
|
1020
|
+
}
|
|
1021
|
+
const candidate = value;
|
|
1022
|
+
if (hasInvalidCssVariable(value)) {
|
|
1023
|
+
return false;
|
|
1024
|
+
}
|
|
1025
|
+
// Whole-shadow token wins over every part, so the parts go unvalidated.
|
|
1026
|
+
if (getCssVariableFromLeaf(value)) {
|
|
1027
|
+
return true;
|
|
1028
|
+
}
|
|
1029
|
+
for (const lengthKey of ['offsetX', 'offsetY', 'spread']) {
|
|
1030
|
+
const entry = candidate[lengthKey];
|
|
1031
|
+
if (entry !== undefined &&
|
|
1032
|
+
entry !== null &&
|
|
1033
|
+
!isSpacingSideValue(entry, offsetOrSpreadCapabilities)) {
|
|
1034
|
+
return false;
|
|
1035
|
+
}
|
|
1036
|
+
}
|
|
1037
|
+
if (candidate.blur !== undefined &&
|
|
1038
|
+
candidate.blur !== null &&
|
|
1039
|
+
!isSpacingSideValue(candidate.blur, blurCapabilities)) {
|
|
1040
|
+
return false;
|
|
1041
|
+
}
|
|
1042
|
+
if (candidate.color !== undefined && candidate.color !== null && !isCssColorValue(candidate.color)) {
|
|
1043
|
+
return false;
|
|
1044
|
+
}
|
|
1045
|
+
if (candidate.inset !== undefined && candidate.inset !== null && typeof candidate.inset !== 'boolean') {
|
|
1046
|
+
return false;
|
|
1047
|
+
}
|
|
1048
|
+
return true;
|
|
1049
|
+
};
|
|
1050
|
+
/**
|
|
1051
|
+
* A leaf renders a shadow only when at least one length or the color is set;
|
|
1052
|
+
* `inset` alone describes nothing visible.
|
|
1053
|
+
*/
|
|
1054
|
+
const hasBoxShadowLeaf = (value) => {
|
|
1055
|
+
if (!value) {
|
|
1056
|
+
return false;
|
|
1057
|
+
}
|
|
1058
|
+
// `null` counts as absent for the token, matching getCssVariableFromLeaf:
|
|
1059
|
+
// clearing a token in the editor can store null rather than deleting the key,
|
|
1060
|
+
// and a leaf holding only a cleared token describes nothing.
|
|
1061
|
+
return ((value.cssVariable !== undefined && value.cssVariable !== null) ||
|
|
1062
|
+
value.offsetX !== undefined ||
|
|
1063
|
+
value.offsetY !== undefined ||
|
|
1064
|
+
value.blur !== undefined ||
|
|
1065
|
+
value.spread !== undefined ||
|
|
1066
|
+
value.color !== undefined);
|
|
1067
|
+
};
|
|
1068
|
+
|
|
1069
|
+
const isLineHeightValue = (value) => {
|
|
1070
|
+
if (typeof value !== 'object' || value === null || Array.isArray(value)) {
|
|
1071
|
+
return false;
|
|
1072
|
+
}
|
|
1073
|
+
const candidate = value;
|
|
1074
|
+
if (hasInvalidCssVariable(value)) {
|
|
1075
|
+
return false;
|
|
1076
|
+
}
|
|
1077
|
+
if (getCssVariableFromLeaf(value)) {
|
|
1078
|
+
return true;
|
|
1079
|
+
}
|
|
1080
|
+
if (candidate.unit === 'number') {
|
|
1081
|
+
return (typeof candidate.value === 'number' &&
|
|
1082
|
+
Number.isFinite(candidate.value) &&
|
|
1083
|
+
candidate.value > 0);
|
|
1084
|
+
}
|
|
1085
|
+
return isSpacingSideValue(value, { allowAuto: false, allowNegative: false });
|
|
1086
|
+
};
|
|
1087
|
+
|
|
1088
|
+
const isOpacityValue = (value) => {
|
|
1089
|
+
if (typeof value === 'object' && value !== null && !Array.isArray(value)) {
|
|
1090
|
+
return !hasInvalidCssVariable(value) && !!getCssVariableFromLeaf(value);
|
|
1091
|
+
}
|
|
1092
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0 && value <= 1;
|
|
1093
|
+
};
|
|
1094
|
+
|
|
1095
|
+
/**
|
|
1096
|
+
* One validated background image leaf into a `backgroundImage` style entry.
|
|
1097
|
+
* Returns {} for anything malformed so an old or hand-edited payload drops the
|
|
1098
|
+
* property rather than throwing inside a customer's app.
|
|
1099
|
+
*
|
|
1100
|
+
* The guard has already rejected anything that could close the `url()` call or
|
|
1101
|
+
* its quotes, so the value is safe to interpolate.
|
|
1102
|
+
*/
|
|
1103
|
+
const formatBackgroundImageStyles = (value) => {
|
|
1104
|
+
if (!isBackgroundImageValue(value)) {
|
|
1105
|
+
return {};
|
|
1106
|
+
}
|
|
1107
|
+
const cssVariable = getCssVariableFromLeaf(value);
|
|
1108
|
+
if (cssVariable) {
|
|
1109
|
+
// The token supplies the whole property, so it names a full `url(...)` or
|
|
1110
|
+
// gradient in the embedding app, not a bare image address.
|
|
1111
|
+
return { backgroundImage: formatCssVariable(cssVariable) };
|
|
1112
|
+
}
|
|
1113
|
+
// With no token present the guard has already narrowed the leaf to one of the
|
|
1114
|
+
// three literal sources, so there is no unreachable fallback arm here.
|
|
1115
|
+
const literal = value;
|
|
1116
|
+
if (literal.source === 'none') {
|
|
1117
|
+
return { backgroundImage: 'none' };
|
|
1118
|
+
}
|
|
1119
|
+
if (literal.source === 'url') {
|
|
1120
|
+
return { backgroundImage: `url("${literal.url}")` };
|
|
1121
|
+
}
|
|
1122
|
+
return {
|
|
1123
|
+
backgroundImage: `url("${buildCloudinaryBackgroundUrl({
|
|
1124
|
+
publicId: literal.publicId,
|
|
1125
|
+
cloudName: literal.cloudName,
|
|
1126
|
+
transformations: literal.transformations,
|
|
1127
|
+
})}")`,
|
|
1128
|
+
};
|
|
1129
|
+
};
|
|
1130
|
+
|
|
1131
|
+
/** Formats one validated SpacingSideValue into a CSS length/keyword string. */
|
|
1132
|
+
const formatSpacingSideValue = (side) => {
|
|
1133
|
+
const cssVariable = getCssVariableFromLeaf(side);
|
|
1134
|
+
if (cssVariable) {
|
|
1135
|
+
return formatCssVariable(cssVariable);
|
|
1136
|
+
}
|
|
1137
|
+
if (!('unit' in side)) {
|
|
1138
|
+
return '';
|
|
1139
|
+
}
|
|
1140
|
+
if (side.unit === 'auto') {
|
|
1141
|
+
return 'auto';
|
|
1142
|
+
}
|
|
1143
|
+
if (side.unit === 'keyword') {
|
|
1144
|
+
return side.keyword;
|
|
1145
|
+
}
|
|
1146
|
+
return `${side.value}${side.unit}`;
|
|
1147
|
+
};
|
|
1148
|
+
|
|
1149
|
+
/**
|
|
1150
|
+
* Border object → longhand React style keys only. Malformed values return {}.
|
|
1151
|
+
* A whole-border design token is the sole shorthand case: it emits `border`
|
|
1152
|
+
* alone, so shorthand and longhands never land in the same style object.
|
|
1153
|
+
*/
|
|
1154
|
+
const formatBorderStyles = (value) => {
|
|
1155
|
+
if (!isBorderValue(value)) {
|
|
1156
|
+
return {};
|
|
1157
|
+
}
|
|
1158
|
+
const wholeBorderToken = getCssVariableFromLeaf(value);
|
|
1159
|
+
if (wholeBorderToken) {
|
|
1160
|
+
return { border: formatCssVariable(wholeBorderToken) };
|
|
1161
|
+
}
|
|
1162
|
+
const styles = {};
|
|
1163
|
+
if (value.width) {
|
|
1164
|
+
styles.borderWidth = formatSpacingSideValue(value.width);
|
|
1165
|
+
}
|
|
1166
|
+
if (value.style) {
|
|
1167
|
+
const styleToken = getCssVariableFromLeaf(value.style);
|
|
1168
|
+
styles.borderStyle = styleToken ? formatCssVariable(styleToken) : value.style;
|
|
1169
|
+
}
|
|
1170
|
+
if (value.color) {
|
|
1171
|
+
styles.borderColor = formatCssColorValue(value.color);
|
|
1172
|
+
}
|
|
1173
|
+
return styles;
|
|
1174
|
+
};
|
|
1175
|
+
|
|
1176
|
+
const formatShadowLength = (length) => length ? formatSpacingSideValue(length) : '0px';
|
|
1177
|
+
/**
|
|
1178
|
+
* Box-shadow object → the boxShadow style key. Missing lengths default to
|
|
1179
|
+
* 0px so a partially filled leaf still renders. Malformed values return {}.
|
|
1180
|
+
*/
|
|
1181
|
+
const formatBoxShadowStyles = (value) => {
|
|
1182
|
+
if (!isBoxShadowValue(value) || !hasBoxShadowLeaf(value)) {
|
|
1183
|
+
return {};
|
|
1184
|
+
}
|
|
1185
|
+
const wholeShadowToken = getCssVariableFromLeaf(value);
|
|
1186
|
+
if (wholeShadowToken) {
|
|
1187
|
+
return { boxShadow: formatCssVariable(wholeShadowToken) };
|
|
1188
|
+
}
|
|
1189
|
+
const parts = [
|
|
1190
|
+
formatShadowLength(value.offsetX),
|
|
1191
|
+
formatShadowLength(value.offsetY),
|
|
1192
|
+
formatShadowLength(value.blur),
|
|
1193
|
+
formatShadowLength(value.spread),
|
|
1194
|
+
];
|
|
1195
|
+
if (value.color) {
|
|
1196
|
+
parts.push(formatCssColorValue(value.color));
|
|
1197
|
+
}
|
|
1198
|
+
if (value.inset) {
|
|
1199
|
+
parts.unshift('inset');
|
|
1200
|
+
}
|
|
1201
|
+
return { boxShadow: parts.join(' ') };
|
|
1202
|
+
};
|
|
1203
|
+
|
|
1204
|
+
const capitalize = (word) => `${word.charAt(0).toUpperCase()}${word.slice(1)}`;
|
|
1205
|
+
/**
|
|
1206
|
+
* Converts a stored box-spacing object into React style entries for the given
|
|
1207
|
+
* CSS property, e.g. formatBoxSpacingStyles(value, 'margin') returns
|
|
1208
|
+
* { margin } (when allSides is set) or { marginTop, marginRight, ... } for the
|
|
1209
|
+
* sides that are defined. Invalid/malformed values return {} so old or
|
|
1210
|
+
* corrupted payloads degrade gracefully instead of crashing the renderer.
|
|
1211
|
+
*/
|
|
1212
|
+
const formatBoxSpacingStyles = (value, cssProperty) => {
|
|
1213
|
+
if (!isBoxSpacingValue(value)) {
|
|
1214
|
+
return {};
|
|
1215
|
+
}
|
|
1216
|
+
// allSides wins, mirroring how `all` wins over per-device values
|
|
1217
|
+
if (value.allSides) {
|
|
1218
|
+
return { [cssProperty]: formatSpacingSideValue(value.allSides) };
|
|
1219
|
+
}
|
|
1220
|
+
const styles = {};
|
|
1221
|
+
for (const sideKey of ['top', 'right', 'bottom', 'left']) {
|
|
1222
|
+
const sideValue = value[sideKey];
|
|
1223
|
+
if (!sideValue) {
|
|
1224
|
+
continue;
|
|
1225
|
+
}
|
|
1226
|
+
styles[`${cssProperty}${capitalize(sideKey)}`] = formatSpacingSideValue(sideValue);
|
|
1227
|
+
}
|
|
1228
|
+
return styles;
|
|
1229
|
+
};
|
|
1230
|
+
|
|
1231
|
+
/**
|
|
1232
|
+
* Color leaf → one React style entry (backgroundColor, color, ...).
|
|
1233
|
+
* Malformed values return {}.
|
|
1234
|
+
*/
|
|
1235
|
+
const formatCssColorStyles = (value, cssProperty) => {
|
|
1236
|
+
if (!isCssColorValue(value)) {
|
|
1237
|
+
return {};
|
|
1238
|
+
}
|
|
1239
|
+
return { [cssProperty]: formatCssColorValue(value) };
|
|
1240
|
+
};
|
|
1241
|
+
|
|
1242
|
+
/**
|
|
1243
|
+
* Enum / keyword leaf → one React style entry. Malformed values return {}.
|
|
1244
|
+
*/
|
|
1245
|
+
const formatCssEnumStyles = (value, cssProperty, allowedValues) => {
|
|
1246
|
+
if (!isCssEnumValue(value, allowedValues)) {
|
|
1247
|
+
return {};
|
|
1248
|
+
}
|
|
1249
|
+
const cssVariable = getCssVariableFromLeaf(value);
|
|
1250
|
+
if (cssVariable) {
|
|
1251
|
+
return { [cssProperty]: formatCssVariable(cssVariable) };
|
|
1252
|
+
}
|
|
1253
|
+
return { [cssProperty]: value };
|
|
1254
|
+
};
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Single length/keyword leaf → one React style entry
|
|
1258
|
+
* (width, height, gap, borderRadius, ...). Malformed values return {}.
|
|
1259
|
+
*/
|
|
1260
|
+
const formatCssLengthStyles = (value, cssProperty, capabilities = {}) => {
|
|
1261
|
+
if (!isSpacingSideValue(value, capabilities)) {
|
|
1262
|
+
return {};
|
|
1263
|
+
}
|
|
1264
|
+
return { [cssProperty]: formatSpacingSideValue(value) };
|
|
1265
|
+
};
|
|
1266
|
+
|
|
1267
|
+
/**
|
|
1268
|
+
* Line-height leaf → React `lineHeight` (number for unitless, string for lengths
|
|
1269
|
+
* and design tokens).
|
|
1270
|
+
*/
|
|
1271
|
+
const formatLineHeightStyles = (value) => {
|
|
1272
|
+
if (!isLineHeightValue(value)) {
|
|
1273
|
+
return {};
|
|
1274
|
+
}
|
|
1275
|
+
const cssVariable = getCssVariableFromLeaf(value);
|
|
1276
|
+
if (cssVariable) {
|
|
1277
|
+
return { lineHeight: formatCssVariable(cssVariable) };
|
|
1278
|
+
}
|
|
1279
|
+
if ('unit' in value && value.unit === 'number') {
|
|
1280
|
+
return { lineHeight: value.value };
|
|
1281
|
+
}
|
|
1282
|
+
return { lineHeight: formatSpacingSideValue(value) };
|
|
1283
|
+
};
|
|
1284
|
+
|
|
1285
|
+
/**
|
|
1286
|
+
* Opacity leaf is a finite number in [0, 1] or a design token.
|
|
1287
|
+
* Malformed values return {}.
|
|
1288
|
+
*/
|
|
1289
|
+
const formatOpacityStyles = (value) => {
|
|
1290
|
+
if (!isOpacityValue(value)) {
|
|
1291
|
+
return {};
|
|
1292
|
+
}
|
|
1293
|
+
const cssVariable = getCssVariableFromLeaf(value);
|
|
1294
|
+
if (cssVariable) {
|
|
1295
|
+
return { opacity: formatCssVariable(cssVariable) };
|
|
1296
|
+
}
|
|
1297
|
+
return { opacity: value };
|
|
1298
|
+
};
|
|
1299
|
+
|
|
1300
|
+
const objectStyleAttributeRegistry = {
|
|
1301
|
+
// Box spacing (4-sided)
|
|
1302
|
+
'margin-3-resolutions': { kind: 'boxSpacing', cssProperty: 'margin' },
|
|
1303
|
+
'padding-3-resolutions': { kind: 'boxSpacing', cssProperty: 'padding' },
|
|
1304
|
+
// Border (compound — longhands only)
|
|
1305
|
+
'border-3-resolutions': { kind: 'border' },
|
|
1306
|
+
// Box shadow (compound — offsets, blur, spread, color, inset)
|
|
1307
|
+
'box-shadow-3-resolutions': { kind: 'boxShadow' },
|
|
1308
|
+
// Single length / keyword
|
|
1309
|
+
'border-radius-3-resolutions': {
|
|
1310
|
+
kind: 'length',
|
|
1311
|
+
cssProperty: 'borderRadius',
|
|
1312
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1313
|
+
},
|
|
1314
|
+
'width-3-resolutions': {
|
|
1315
|
+
kind: 'length',
|
|
1316
|
+
cssProperty: 'width',
|
|
1317
|
+
capabilities: { allowAuto: true, allowNegative: false },
|
|
1318
|
+
},
|
|
1319
|
+
'height-3-resolutions': {
|
|
1320
|
+
kind: 'length',
|
|
1321
|
+
cssProperty: 'height',
|
|
1322
|
+
capabilities: { allowAuto: true, allowNegative: false },
|
|
1323
|
+
},
|
|
1324
|
+
'min-width-3-resolutions': {
|
|
1325
|
+
kind: 'length',
|
|
1326
|
+
cssProperty: 'minWidth',
|
|
1327
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1328
|
+
},
|
|
1329
|
+
'max-width-3-resolutions': {
|
|
1330
|
+
kind: 'length',
|
|
1331
|
+
cssProperty: 'maxWidth',
|
|
1332
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1333
|
+
},
|
|
1334
|
+
'min-height-3-resolutions': {
|
|
1335
|
+
kind: 'length',
|
|
1336
|
+
cssProperty: 'minHeight',
|
|
1337
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1338
|
+
},
|
|
1339
|
+
'max-height-3-resolutions': {
|
|
1340
|
+
kind: 'length',
|
|
1341
|
+
cssProperty: 'maxHeight',
|
|
1342
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1343
|
+
},
|
|
1344
|
+
'gap-3-resolutions': {
|
|
1345
|
+
kind: 'length',
|
|
1346
|
+
cssProperty: 'gap',
|
|
1347
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1348
|
+
},
|
|
1349
|
+
// Flex layout — display:flex is derived at render when any of these (not
|
|
1350
|
+
// gap alone) is set. See deriveDisplayFlexIfNeeded.
|
|
1351
|
+
'justify-content-3-resolutions': {
|
|
1352
|
+
kind: 'enum',
|
|
1353
|
+
cssProperty: 'justifyContent',
|
|
1354
|
+
allowedValues: justifyContentAllowlist,
|
|
1355
|
+
},
|
|
1356
|
+
'align-items-3-resolutions': {
|
|
1357
|
+
kind: 'enum',
|
|
1358
|
+
cssProperty: 'alignItems',
|
|
1359
|
+
allowedValues: alignItemsAllowlist,
|
|
1360
|
+
},
|
|
1361
|
+
'flex-wrap-3-resolutions': {
|
|
1362
|
+
kind: 'enum',
|
|
1363
|
+
cssProperty: 'flexWrap',
|
|
1364
|
+
allowedValues: flexWrapAllowlist,
|
|
1365
|
+
},
|
|
1366
|
+
'align-content-3-resolutions': {
|
|
1367
|
+
kind: 'enum',
|
|
1368
|
+
cssProperty: 'alignContent',
|
|
1369
|
+
allowedValues: alignContentAllowlist,
|
|
1370
|
+
},
|
|
1371
|
+
'flex-direction-3-resolutions': {
|
|
1372
|
+
kind: 'enum',
|
|
1373
|
+
cssProperty: 'flexDirection',
|
|
1374
|
+
allowedValues: flexDirectionAllowlist,
|
|
1375
|
+
},
|
|
1376
|
+
// Overflow — shorthand and longhands are independent attributes; when
|
|
1377
|
+
// both are set, the browser's cascade decides the effective overflow.
|
|
1378
|
+
'overflow-3-resolutions': {
|
|
1379
|
+
kind: 'enum',
|
|
1380
|
+
cssProperty: 'overflow',
|
|
1381
|
+
allowedValues: overflowAllowlist,
|
|
1382
|
+
},
|
|
1383
|
+
'overflow-x-3-resolutions': {
|
|
1384
|
+
kind: 'enum',
|
|
1385
|
+
cssProperty: 'overflowX',
|
|
1386
|
+
allowedValues: overflowAllowlist,
|
|
1387
|
+
},
|
|
1388
|
+
'overflow-y-3-resolutions': {
|
|
1389
|
+
kind: 'enum',
|
|
1390
|
+
cssProperty: 'overflowY',
|
|
1391
|
+
allowedValues: overflowAllowlist,
|
|
1392
|
+
},
|
|
1393
|
+
// Color
|
|
1394
|
+
'background-color-3-resolutions': { kind: 'color', cssProperty: 'backgroundColor' },
|
|
1395
|
+
'color-3-resolutions': { kind: 'color', cssProperty: 'color' },
|
|
1396
|
+
// Background image and the painting properties that go with it. Independent
|
|
1397
|
+
// attributes rather than one compound value: only the image needs a bespoke
|
|
1398
|
+
// leaf, and each is separately per-device.
|
|
1399
|
+
'background-image-3-resolutions': { kind: 'backgroundImage' },
|
|
1400
|
+
'background-size-3-resolutions': {
|
|
1401
|
+
kind: 'enum',
|
|
1402
|
+
cssProperty: 'backgroundSize',
|
|
1403
|
+
allowedValues: backgroundSizeAllowlist,
|
|
1404
|
+
},
|
|
1405
|
+
'background-position-3-resolutions': {
|
|
1406
|
+
kind: 'enum',
|
|
1407
|
+
cssProperty: 'backgroundPosition',
|
|
1408
|
+
allowedValues: backgroundPositionAllowlist,
|
|
1409
|
+
},
|
|
1410
|
+
'background-repeat-3-resolutions': {
|
|
1411
|
+
kind: 'enum',
|
|
1412
|
+
cssProperty: 'backgroundRepeat',
|
|
1413
|
+
allowedValues: backgroundRepeatAllowlist,
|
|
1414
|
+
},
|
|
1415
|
+
// Opacity (0–1 number)
|
|
1416
|
+
'opacity-3-resolutions': { kind: 'opacity' },
|
|
1417
|
+
// Typography — applied on the column wrapper; text inherits
|
|
1418
|
+
'font-family-3-resolutions': {
|
|
1419
|
+
kind: 'enum',
|
|
1420
|
+
cssProperty: 'fontFamily',
|
|
1421
|
+
allowedValues: fontFamilyAllowlist,
|
|
1422
|
+
},
|
|
1423
|
+
'font-size-3-resolutions': {
|
|
1424
|
+
kind: 'length',
|
|
1425
|
+
cssProperty: 'fontSize',
|
|
1426
|
+
capabilities: { allowAuto: false, allowNegative: false },
|
|
1427
|
+
},
|
|
1428
|
+
'font-weight-3-resolutions': {
|
|
1429
|
+
kind: 'enum',
|
|
1430
|
+
cssProperty: 'fontWeight',
|
|
1431
|
+
allowedValues: fontWeightAllowlist,
|
|
1432
|
+
},
|
|
1433
|
+
'font-style-3-resolutions': {
|
|
1434
|
+
kind: 'enum',
|
|
1435
|
+
cssProperty: 'fontStyle',
|
|
1436
|
+
allowedValues: fontStyleAllowlist,
|
|
1437
|
+
},
|
|
1438
|
+
'line-height-3-resolutions': { kind: 'lineHeight' },
|
|
1439
|
+
'letter-spacing-3-resolutions': {
|
|
1440
|
+
kind: 'length',
|
|
1441
|
+
cssProperty: 'letterSpacing',
|
|
1442
|
+
capabilities: { allowAuto: false, allowNegative: true },
|
|
1443
|
+
},
|
|
1444
|
+
'text-align-3-resolutions': {
|
|
1445
|
+
kind: 'enum',
|
|
1446
|
+
cssProperty: 'textAlign',
|
|
1447
|
+
allowedValues: textAlignAllowlist,
|
|
1448
|
+
},
|
|
1449
|
+
'text-decoration-3-resolutions': {
|
|
1450
|
+
kind: 'enum',
|
|
1451
|
+
cssProperty: 'textDecoration',
|
|
1452
|
+
allowedValues: textDecorationAllowlist,
|
|
1453
|
+
},
|
|
1454
|
+
'text-transform-3-resolutions': {
|
|
1455
|
+
kind: 'enum',
|
|
1456
|
+
cssProperty: 'textTransform',
|
|
1457
|
+
allowedValues: textTransformAllowlist,
|
|
1458
|
+
},
|
|
1459
|
+
};
|
|
1460
|
+
/**
|
|
1461
|
+
* Formats a flattened leaf for a registered object-style attribute into React
|
|
1462
|
+
* style entries. Returns {} when the attribute is unknown or the leaf is
|
|
1463
|
+
* malformed (graceful degradation).
|
|
1464
|
+
*/
|
|
1465
|
+
const formatObjectStyleAttribute = (attributeName, leaf) => {
|
|
1466
|
+
const entry = objectStyleAttributeRegistry[attributeName];
|
|
1467
|
+
if (!entry) {
|
|
1468
|
+
return {};
|
|
1469
|
+
}
|
|
1470
|
+
switch (entry.kind) {
|
|
1471
|
+
case 'boxSpacing':
|
|
1472
|
+
return formatBoxSpacingStyles(leaf, entry.cssProperty);
|
|
1473
|
+
case 'length':
|
|
1474
|
+
return formatCssLengthStyles(leaf, entry.cssProperty, entry.capabilities);
|
|
1475
|
+
case 'border':
|
|
1476
|
+
return formatBorderStyles(leaf);
|
|
1477
|
+
case 'boxShadow':
|
|
1478
|
+
return formatBoxShadowStyles(leaf);
|
|
1479
|
+
case 'color':
|
|
1480
|
+
return formatCssColorStyles(leaf, entry.cssProperty);
|
|
1481
|
+
case 'opacity':
|
|
1482
|
+
return formatOpacityStyles(leaf);
|
|
1483
|
+
case 'enum':
|
|
1484
|
+
return formatCssEnumStyles(leaf, entry.cssProperty, entry.allowedValues);
|
|
1485
|
+
case 'lineHeight':
|
|
1486
|
+
return formatLineHeightStyles(leaf);
|
|
1487
|
+
case 'backgroundImage':
|
|
1488
|
+
return formatBackgroundImageStyles(leaf);
|
|
1489
|
+
default:
|
|
1490
|
+
return {};
|
|
1491
|
+
}
|
|
1492
|
+
};
|
|
1493
|
+
|
|
1494
|
+
// Derived from the unified object-style registry so box-spacing callers and
|
|
1495
|
+
// the registry stay in sync. Prefer objectStyleAttributeRegistry for new code.
|
|
1496
|
+
const boxSpacingStyleAttributeEntries = Object.fromEntries(Object.entries(objectStyleAttributeRegistry)
|
|
1497
|
+
.filter(([, entry]) => entry.kind === 'boxSpacing')
|
|
1498
|
+
.map(([attributeName, entry]) => [
|
|
1499
|
+
attributeName,
|
|
1500
|
+
entry.cssProperty,
|
|
1501
|
+
]));
|
|
1502
|
+
|
|
1503
|
+
const isSetStyleValue$1 = (value) => value !== undefined && value !== null && value !== '';
|
|
1504
|
+
/**
|
|
1505
|
+
* When a column has any flex-layout style (justify-content, align-items,
|
|
1506
|
+
* flex-wrap, align-content, flex-direction), ensure `display: flex` so those
|
|
1507
|
+
* properties take effect. Gap alone does not force flex.
|
|
1508
|
+
*
|
|
1509
|
+
* Pure / non-mutating: returns a new object when display is added.
|
|
1510
|
+
*/
|
|
1511
|
+
const deriveDisplayFlexIfNeeded = (styles) => {
|
|
1512
|
+
if (!styles) {
|
|
1513
|
+
return {};
|
|
1514
|
+
}
|
|
1515
|
+
const hasFlexLayoutProp = FLEX_LAYOUT_STYLE_KEYS_THAT_DERIVE_DISPLAY.some(key => isSetStyleValue$1(styles[key]));
|
|
1516
|
+
if (!hasFlexLayoutProp) {
|
|
1517
|
+
return styles;
|
|
1518
|
+
}
|
|
1519
|
+
if (styles.display === 'flex') {
|
|
1520
|
+
return styles;
|
|
1521
|
+
}
|
|
1522
|
+
return { ...styles, display: 'flex' };
|
|
1523
|
+
};
|
|
1524
|
+
|
|
1525
|
+
const getDefaultDimensionAttributes = ({ dbEntryType, libraryId, sourceComponentsPlugin, }) => {
|
|
1526
|
+
if (!dbEntryType?.length) {
|
|
1527
|
+
return;
|
|
1528
|
+
}
|
|
1529
|
+
// Get defaultAttributeValues directly from the specific component's entry.
|
|
1530
|
+
// Lookup key is namespaced by libraryId, same as the render lookup — a
|
|
1531
|
+
// customer-library component must get ITS defaults, not the default
|
|
1532
|
+
// library's (or none).
|
|
1533
|
+
const component = sourceComponentsPlugin.components[resolveKey(libraryId, dbEntryType)];
|
|
1534
|
+
if (!component) {
|
|
1535
|
+
return;
|
|
1536
|
+
}
|
|
1537
|
+
// Guard for runtime data from external library modules
|
|
1538
|
+
if (!('defaultAttributeValues' in component)) {
|
|
1539
|
+
return;
|
|
1540
|
+
}
|
|
1541
|
+
const displayComponent = component;
|
|
1542
|
+
const defaultDimensionStyleEntries = displayComponent.defaultAttributeValues;
|
|
1543
|
+
if (!defaultDimensionStyleEntries?.length) {
|
|
1544
|
+
return;
|
|
1545
|
+
}
|
|
1546
|
+
// return in the same format as the user stored attributes are stored
|
|
1547
|
+
return defaultDimensionStyleEntries.reduce((acc, curr) => {
|
|
1548
|
+
return {
|
|
1549
|
+
...acc,
|
|
1550
|
+
[curr.name]: curr.defaultValues,
|
|
1551
|
+
};
|
|
1552
|
+
}, {});
|
|
1553
|
+
};
|
|
1554
|
+
|
|
1555
|
+
const getDeviceTypeBasedAttributes = ({ deviceDisplayType, componentAttributes, }) => {
|
|
1556
|
+
// there may not be any component attributes
|
|
1557
|
+
if (!componentAttributes) {
|
|
1558
|
+
return;
|
|
1559
|
+
}
|
|
1560
|
+
const style = {};
|
|
1561
|
+
const componentAttributesSpecificToDeviceType = {};
|
|
1562
|
+
// for each component attribute, check if it is of a type where we can get back a value that is
|
|
1563
|
+
// based on the device type (phone, tablet, desktop)
|
|
1564
|
+
for (const [key, valuesForEachDeviceType] of Object.entries(componentAttributes)) {
|
|
1565
|
+
// leave out the non device specific attributes
|
|
1566
|
+
if (!key.includes("3-resolutions")) {
|
|
1567
|
+
continue;
|
|
1568
|
+
}
|
|
1569
|
+
// there should be stored values for this entry in the format { phone: value, tablet: value, desktop: value, all: value }
|
|
1570
|
+
if (!valuesForEachDeviceType) {
|
|
1571
|
+
continue;
|
|
1572
|
+
}
|
|
1573
|
+
// Check if 'all' attribute is set first, otherwise use device-specific value
|
|
1574
|
+
// This allows components to use the same value for all resolutions
|
|
1575
|
+
const allValue = valuesForEachDeviceType['all'];
|
|
1576
|
+
const deviceSpecificValue = (allValue !== null && allValue !== undefined)
|
|
1577
|
+
? allValue // Use 'all' if it exists
|
|
1578
|
+
: valuesForEachDeviceType[deviceDisplayType.toLowerCase()]; // Otherwise use device-specific
|
|
1579
|
+
// the entry should be made for all componentAttributesSpecificToDeviceType
|
|
1580
|
+
// entry should be there even if it is undefined for a non style type attribute
|
|
1581
|
+
// to prevent an object being defined. All entries should be flattened to a key value pair
|
|
1582
|
+
componentAttributesSpecificToDeviceType[key] = deviceSpecificValue;
|
|
1583
|
+
// Object-valued style attributes (margin, padding, border, width, ...)
|
|
1584
|
+
// expand via the registry into React inline style entries
|
|
1585
|
+
if (objectStyleAttributeRegistry[key]) {
|
|
1586
|
+
Object.assign(style, formatObjectStyleAttribute(key, deviceSpecificValue));
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
// return the objects only if it has some entries
|
|
1590
|
+
return Object.keys(style).length || Object.keys(componentAttributesSpecificToDeviceType).length
|
|
1591
|
+
? {
|
|
1592
|
+
styles: Object.keys(style).length ? style : undefined,
|
|
1593
|
+
componentAttributesSpecificToDeviceType: Object.keys(componentAttributesSpecificToDeviceType).length
|
|
1594
|
+
? componentAttributesSpecificToDeviceType
|
|
1595
|
+
: undefined,
|
|
1596
|
+
}
|
|
1597
|
+
: undefined;
|
|
1598
|
+
};
|
|
1599
|
+
|
|
1600
|
+
const getMergedAttributes = ({ defaultAttributes, userModifiedAttributes, }) => {
|
|
1601
|
+
// there may not be any default styles
|
|
1602
|
+
if (!defaultAttributes) {
|
|
1603
|
+
return userModifiedAttributes;
|
|
1604
|
+
}
|
|
1605
|
+
// there may not be any user modified styles
|
|
1606
|
+
if (!userModifiedAttributes) {
|
|
1607
|
+
return defaultAttributes;
|
|
1608
|
+
}
|
|
1609
|
+
return { ...defaultAttributes, ...userModifiedAttributes };
|
|
1610
|
+
};
|
|
1611
|
+
|
|
1612
|
+
/**
|
|
1613
|
+
* Reads a column's persisted attribute map during the persisted-key
|
|
1614
|
+
* migration from `widgetAttributes` to `componentAttributes`.
|
|
1615
|
+
*
|
|
1616
|
+
* Published payloads historically stored per-column attributes under
|
|
1617
|
+
* `widgetAttributes`; the composer now writes `componentAttributes` for
|
|
1618
|
+
* new/edited content while old payloads keep `widgetAttributes` forever.
|
|
1619
|
+
* Every read of the persisted field must go through this helper so both
|
|
1620
|
+
* generations of payloads render.
|
|
1621
|
+
*
|
|
1622
|
+
* Precedence is per-column and wholesale: when `componentAttributes` is
|
|
1623
|
+
* present it wins outright — values from a stale `widgetAttributes` on the
|
|
1624
|
+
* same column must NOT leak through, so there is no key-by-key merging.
|
|
1625
|
+
*/
|
|
1626
|
+
function getColumnAttributes(col) {
|
|
1627
|
+
return col.componentAttributes ?? col.widgetAttributes;
|
|
1628
|
+
}
|
|
1629
|
+
|
|
1630
|
+
function getComponentAttributesAndStyles({ col, deviceDisplayType, isComposeMode, sourceComponentsPlugin, }) {
|
|
1631
|
+
const userModifiedAttributes = getColumnAttributes(col);
|
|
1632
|
+
const defaultAttributes = getDefaultDimensionAttributes({
|
|
1633
|
+
dbEntryType: col.type,
|
|
1634
|
+
libraryId: col.libraryId,
|
|
1635
|
+
sourceComponentsPlugin,
|
|
1636
|
+
}) || [];
|
|
1637
|
+
// merge default and user's saved attributes
|
|
1638
|
+
// prefer user's modified attributes over default styles
|
|
1639
|
+
const componentAttributes = getMergedAttributes({
|
|
1640
|
+
defaultAttributes,
|
|
1641
|
+
userModifiedAttributes,
|
|
1642
|
+
});
|
|
1643
|
+
const { styles, componentAttributesSpecificToDeviceType } = getDeviceTypeBasedAttributes({
|
|
1644
|
+
deviceDisplayType,
|
|
1645
|
+
componentAttributes,
|
|
1646
|
+
}) || {
|
|
1647
|
+
styles: undefined,
|
|
1648
|
+
componentAttributesSpecificToDeviceType: undefined,
|
|
1649
|
+
};
|
|
1650
|
+
let componentStyles = {};
|
|
1651
|
+
const childAttr = {};
|
|
1652
|
+
if (styles) {
|
|
1653
|
+
// we might need to apply some styles to the wrapper and some child styles to the component to support that
|
|
1654
|
+
for (const [key, value] of Object.entries(styles)) {
|
|
1655
|
+
if (isComposeMode && childAttr[key]) {
|
|
1656
|
+
// For now, we're not handling wrapper styles in this helper
|
|
1657
|
+
// This logic can be extended if needed
|
|
1658
|
+
}
|
|
1659
|
+
else {
|
|
1660
|
+
// TODO: This logic is not taking into account whether the style needs to be on the parent or the child
|
|
1661
|
+
componentStyles = {
|
|
1662
|
+
...componentStyles,
|
|
1663
|
+
[key]: value,
|
|
1664
|
+
};
|
|
1665
|
+
}
|
|
1666
|
+
}
|
|
1667
|
+
}
|
|
1668
|
+
let componentAttributesBasedOnDevice = getColumnAttributes(col);
|
|
1669
|
+
// if key contains '3-resolutions' in its name, we need to flatten the component attributes to a key value pair specific to the device
|
|
1670
|
+
for (const key in componentAttributesSpecificToDeviceType) {
|
|
1671
|
+
if (key.includes('3-resolutions')) {
|
|
1672
|
+
// flatten the component attributes to a key value pair specific to the device
|
|
1673
|
+
componentAttributesBasedOnDevice = {
|
|
1674
|
+
...(getColumnAttributes(col) || {}),
|
|
1675
|
+
...(componentAttributesSpecificToDeviceType || {}),
|
|
1676
|
+
};
|
|
1677
|
+
break;
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
return {
|
|
1681
|
+
componentAttributesBasedOnDevice,
|
|
1682
|
+
componentStyles: deriveDisplayFlexIfNeeded(componentStyles),
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
|
|
1686
|
+
const hasItems = (items) => {
|
|
1687
|
+
const rows = items?.rows || [];
|
|
1688
|
+
for (const row of rows) {
|
|
1689
|
+
if ((row?.columns || []).length > 0) {
|
|
1690
|
+
return true;
|
|
1691
|
+
}
|
|
1692
|
+
}
|
|
1693
|
+
return items?.containerAttributes && Object.keys(items.containerAttributes).length > 0;
|
|
1694
|
+
};
|
|
1695
|
+
|
|
1696
|
+
const DEFAULT_ROW_GAP = `var(--sl-spacing-x-small)`;
|
|
1697
|
+
/**
|
|
1698
|
+
* True when the row should mount a real flex wrapper so styles have a DOM
|
|
1699
|
+
* target — matching the column idea that assigned attributes imply a container.
|
|
1700
|
+
*/
|
|
1701
|
+
function rowBasedPropertiesAreAssigned(row) {
|
|
1702
|
+
if (row?.horizontalAlignment ||
|
|
1703
|
+
row?.verticalAlignment ||
|
|
1704
|
+
row?.flexWrap ||
|
|
1705
|
+
row?.gap ||
|
|
1706
|
+
row?.alignContent) {
|
|
1707
|
+
return true;
|
|
1708
|
+
}
|
|
1709
|
+
return !!(row?.rowAttributes && Object.keys(row.rowAttributes).length > 0);
|
|
1710
|
+
}
|
|
1711
|
+
function isRowHiddenForDevice({ row, deviceDisplayType, }) {
|
|
1712
|
+
const resolved = getDeviceTypeBasedAttributes({
|
|
1713
|
+
deviceDisplayType,
|
|
1714
|
+
componentAttributes: row.rowAttributes,
|
|
1715
|
+
});
|
|
1716
|
+
return (resolved?.componentAttributesSpecificToDeviceType?.['hide-component-3-resolutions'] === 'true');
|
|
1717
|
+
}
|
|
1718
|
+
/**
|
|
1719
|
+
* Flatten rowAttributes for the device, then overlay layout defaults with
|
|
1720
|
+
* fallback to legacy first-class fields on DisplayItemRow.
|
|
1721
|
+
*/
|
|
1722
|
+
function resolveRowStyles({ row, deviceDisplayType, isComposeMode, }) {
|
|
1723
|
+
const fromAttributes = getDeviceTypeBasedAttributes({
|
|
1724
|
+
deviceDisplayType,
|
|
1725
|
+
componentAttributes: row.rowAttributes,
|
|
1726
|
+
})?.styles || {};
|
|
1727
|
+
// Layout keys resolve with attribute-first, then legacy first-class fallback.
|
|
1728
|
+
// Property order matches the historical EmbedInRowIfRequired inline styles
|
|
1729
|
+
// so published DOM / snapshots stay stable when only defaults apply.
|
|
1730
|
+
const justifyContent = fromAttributes.justifyContent ??
|
|
1731
|
+
row.horizontalAlignment ??
|
|
1732
|
+
JustifyContentTypes.Center;
|
|
1733
|
+
const alignItems = fromAttributes.alignItems ??
|
|
1734
|
+
row.verticalAlignment ??
|
|
1735
|
+
JustifyContentTypes.Center;
|
|
1736
|
+
const flexDirection = fromAttributes.flexDirection ?? 'row';
|
|
1737
|
+
const gap = fromAttributes.gap ?? row.gap ?? DEFAULT_ROW_GAP;
|
|
1738
|
+
const flexWrap = isComposeMode
|
|
1739
|
+
? 'nowrap'
|
|
1740
|
+
: (fromAttributes.flexWrap ?? row.flexWrap ?? 'nowrap');
|
|
1741
|
+
const alignContent = fromAttributes.alignContent ?? row.alignContent ?? undefined;
|
|
1742
|
+
const layoutKeys = new Set([
|
|
1743
|
+
'justifyContent',
|
|
1744
|
+
'alignItems',
|
|
1745
|
+
'flexDirection',
|
|
1746
|
+
'gap',
|
|
1747
|
+
'flexWrap',
|
|
1748
|
+
'alignContent',
|
|
1749
|
+
'display',
|
|
1750
|
+
]);
|
|
1751
|
+
const otherAttributeStyles = {};
|
|
1752
|
+
for (const [key, value] of Object.entries(fromAttributes)) {
|
|
1753
|
+
if (!layoutKeys.has(key)) {
|
|
1754
|
+
otherAttributeStyles[key] = value;
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
const style = {
|
|
1758
|
+
display: 'flex',
|
|
1759
|
+
flexDirection,
|
|
1760
|
+
gap,
|
|
1761
|
+
flexWrap,
|
|
1762
|
+
justifyContent,
|
|
1763
|
+
alignItems,
|
|
1764
|
+
...otherAttributeStyles,
|
|
1765
|
+
};
|
|
1766
|
+
if (alignContent !== undefined) {
|
|
1767
|
+
style.alignContent = alignContent;
|
|
1768
|
+
}
|
|
1769
|
+
return style;
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
const CSS_CLASSES_ATTRIBUTE_NAME = 'css-classes-3-resolutions';
|
|
1773
|
+
const MAX_LENGTH = 500;
|
|
1774
|
+
// eslint-disable-next-line no-control-regex
|
|
1775
|
+
const CONTROL_CHARS_PATTERN = /[\x00-\x1f\x7f]/g;
|
|
1776
|
+
/**
|
|
1777
|
+
* Untrusted leaf from a persisted payload -> a safe class string, or undefined.
|
|
1778
|
+
*
|
|
1779
|
+
* This is a passthrough, not a validator: RuleCMS forms no opinion about what a
|
|
1780
|
+
* host app's class names look like, so tokens are never checked against a
|
|
1781
|
+
* pattern. The only work done here is hygiene — whitespace, de-duplication,
|
|
1782
|
+
* and a length cap — so the same string can be trusted to sit in a `className`
|
|
1783
|
+
* attribute. Never throws and never logs; anything that isn't a non-empty
|
|
1784
|
+
* string after normalization becomes `undefined`.
|
|
1785
|
+
*/
|
|
1786
|
+
const normalizeCssClasses = (value) => {
|
|
1787
|
+
if (typeof value !== 'string') {
|
|
1788
|
+
return undefined;
|
|
1789
|
+
}
|
|
1790
|
+
const seen = new Set();
|
|
1791
|
+
const tokens = [];
|
|
1792
|
+
for (const rawToken of value.split(/\s+/)) {
|
|
1793
|
+
const token = rawToken.replace(CONTROL_CHARS_PATTERN, '');
|
|
1794
|
+
if (!token) {
|
|
1795
|
+
continue;
|
|
1796
|
+
}
|
|
1797
|
+
if (seen.has(token)) {
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
seen.add(token);
|
|
1801
|
+
tokens.push(token);
|
|
1802
|
+
}
|
|
1803
|
+
if (!tokens.length) {
|
|
1804
|
+
return undefined;
|
|
1805
|
+
}
|
|
1806
|
+
// Cap the total length by dropping whole overflowing tokens rather than
|
|
1807
|
+
// truncating mid-token, which could otherwise leave a mangled class name.
|
|
1808
|
+
let result = '';
|
|
1809
|
+
for (const token of tokens) {
|
|
1810
|
+
const next = result ? `${result} ${token}` : token;
|
|
1811
|
+
if (next.length > MAX_LENGTH) {
|
|
1812
|
+
break;
|
|
1813
|
+
}
|
|
1814
|
+
result = next;
|
|
1815
|
+
}
|
|
1816
|
+
return result.length ? result : undefined;
|
|
1817
|
+
};
|
|
1818
|
+
|
|
1819
|
+
const HIDE_WIDGET_ATTRIBUTE_NAME = 'hide-component-3-resolutions';
|
|
1820
|
+
/**
|
|
1821
|
+
* Widget-level settings the editing canvas must not apply.
|
|
1822
|
+
*
|
|
1823
|
+
* The canvas is a drag-and-drop surface, not a scaled preview. A widget pinned
|
|
1824
|
+
* to 400px, inset by margin, or clipped by overflow leaves the author with
|
|
1825
|
+
* nowhere to drop the next component, and a hidden widget leaves nothing to
|
|
1826
|
+
* edit at all. Preview and consuming apps apply every one of these.
|
|
1827
|
+
*
|
|
1828
|
+
* Flex layout, gap, colors, typography, opacity and CSS classes are absent
|
|
1829
|
+
* deliberately: they change how the canvas looks without taking away the room
|
|
1830
|
+
* or the affordances the author needs to keep working.
|
|
1831
|
+
*/
|
|
1832
|
+
const WIDGET_ATTRIBUTES_IGNORED_IN_COMPOSE_MODE = [
|
|
1833
|
+
'width-3-resolutions',
|
|
1834
|
+
'min-width-3-resolutions',
|
|
1835
|
+
'max-width-3-resolutions',
|
|
1836
|
+
'height-3-resolutions',
|
|
1837
|
+
'min-height-3-resolutions',
|
|
1838
|
+
'max-height-3-resolutions',
|
|
1839
|
+
'margin-3-resolutions',
|
|
1840
|
+
'padding-3-resolutions',
|
|
1841
|
+
'border-3-resolutions',
|
|
1842
|
+
'border-radius-3-resolutions',
|
|
1843
|
+
'box-shadow-3-resolutions',
|
|
1844
|
+
'overflow-3-resolutions',
|
|
1845
|
+
'overflow-x-3-resolutions',
|
|
1846
|
+
'overflow-y-3-resolutions',
|
|
1847
|
+
HIDE_WIDGET_ATTRIBUTE_NAME,
|
|
1848
|
+
];
|
|
1849
|
+
const ignoredInComposeMode = new Set(WIDGET_ATTRIBUTES_IGNORED_IN_COMPOSE_MODE);
|
|
1850
|
+
/**
|
|
1851
|
+
* True when the author asked for the whole widget to be hidden at this device
|
|
1852
|
+
* width. Callers must skip this in compose mode — see
|
|
1853
|
+
* WIDGET_ATTRIBUTES_IGNORED_IN_COMPOSE_MODE.
|
|
1854
|
+
*/
|
|
1855
|
+
function isWidgetHiddenForDevice({ containerAttributes, deviceDisplayType, }) {
|
|
1856
|
+
const resolved = getDeviceTypeBasedAttributes({
|
|
1857
|
+
deviceDisplayType,
|
|
1858
|
+
componentAttributes: containerAttributes,
|
|
1859
|
+
});
|
|
1860
|
+
return (resolved?.componentAttributesSpecificToDeviceType?.[HIDE_WIDGET_ATTRIBUTE_NAME] === 'true');
|
|
1861
|
+
}
|
|
1862
|
+
/**
|
|
1863
|
+
* Flatten the widget's own containerAttributes for the device into inline
|
|
1864
|
+
* styles plus author CSS classes, dropping the settings the canvas cannot
|
|
1865
|
+
* honour while in compose mode.
|
|
1866
|
+
*
|
|
1867
|
+
* The legacy raw `cssAttrArray` container CSS is untouched by this: it is not a
|
|
1868
|
+
* `*-3-resolutions` key, so it never reaches here and keeps being emitted as a
|
|
1869
|
+
* scoped style tag by EmbedInVerticalContainerIfRequired.
|
|
1870
|
+
*/
|
|
1871
|
+
function resolveWidgetContainerStyles({ containerAttributes, deviceDisplayType, isComposeMode, }) {
|
|
1872
|
+
if (!containerAttributes) {
|
|
1873
|
+
return { styles: {} };
|
|
1874
|
+
}
|
|
1875
|
+
const applicable = isComposeMode
|
|
1876
|
+
? Object.fromEntries(Object.entries(containerAttributes).filter(([key]) => !ignoredInComposeMode.has(key)))
|
|
1877
|
+
: containerAttributes;
|
|
1878
|
+
const resolved = getDeviceTypeBasedAttributes({
|
|
1879
|
+
deviceDisplayType,
|
|
1880
|
+
componentAttributes: applicable,
|
|
1881
|
+
});
|
|
1882
|
+
return {
|
|
1883
|
+
styles: resolved?.styles ?? {},
|
|
1884
|
+
cssClasses: normalizeCssClasses(resolved?.componentAttributesSpecificToDeviceType?.[CSS_CLASSES_ATTRIBUTE_NAME]),
|
|
1885
|
+
};
|
|
1886
|
+
}
|
|
1887
|
+
/**
|
|
1888
|
+
* True when the widget carries settings that need a real DOM element to land
|
|
1889
|
+
* on, so the vertical container has to be emitted even where it would
|
|
1890
|
+
* otherwise collapse away. Mirrors rowBasedPropertiesAreAssigned.
|
|
1891
|
+
*/
|
|
1892
|
+
function widgetBasedPropertiesAreAssigned(widgetContainerStyles) {
|
|
1893
|
+
return (Object.keys(widgetContainerStyles.styles).length > 0 ||
|
|
1894
|
+
!!widgetContainerStyles.cssClasses);
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
const COMPONENT_PROPS_PATH_SEPARATOR = '/';
|
|
1898
|
+
/**
|
|
1899
|
+
* Picks the host-supplied props for one component instance out of the
|
|
1900
|
+
* `componentProps` map.
|
|
1901
|
+
*
|
|
1902
|
+
* `ancestorColumnIds` are the columns holding the enclosing collections,
|
|
1903
|
+
* outermost first; `columnId` is the instance's own column. A key matches when
|
|
1904
|
+
* its segments are the tail of that path, which is what lets a bare column id
|
|
1905
|
+
* address every copy of a repeated collection while a longer path narrows to
|
|
1906
|
+
* one. Longest match wins, so a specific path always beats a bare id.
|
|
1907
|
+
*/
|
|
1908
|
+
function resolveWidgetInstanceProps({ componentProps, ancestorColumnIds, columnId, }) {
|
|
1909
|
+
if (!componentProps || !columnId) {
|
|
1910
|
+
return undefined;
|
|
1911
|
+
}
|
|
1912
|
+
const path = [...(ancestorColumnIds ?? []), columnId];
|
|
1913
|
+
// Longest suffix first: 'parent/child' must win over a bare 'child'.
|
|
1914
|
+
for (let start = 0; start < path.length; start += 1) {
|
|
1915
|
+
const key = path.slice(start).join(COMPONENT_PROPS_PATH_SEPARATOR);
|
|
1916
|
+
const match = componentProps[key];
|
|
1917
|
+
if (match) {
|
|
1918
|
+
return match;
|
|
1919
|
+
}
|
|
1920
|
+
}
|
|
1921
|
+
return undefined;
|
|
1922
|
+
}
|
|
1923
|
+
|
|
1924
|
+
/**
|
|
1925
|
+
* Every component instance in a config, as the `/`-joined column-id path that
|
|
1926
|
+
* `componentProps` keys are matched against. Collections contribute their
|
|
1927
|
+
* holding column to the path rather than a path of their own.
|
|
1928
|
+
*
|
|
1929
|
+
* Only used to tell a host that a key it supplied addresses nothing; the
|
|
1930
|
+
* render path resolves props directly and never needs this list.
|
|
1931
|
+
*/
|
|
1932
|
+
function collectComponentInstancePaths({ displayItemList, widgetCollections, }) {
|
|
1933
|
+
const paths = [];
|
|
1934
|
+
const walk = (items, ancestorColumnIds) => {
|
|
1935
|
+
if (!items?.rows?.length) {
|
|
1936
|
+
return;
|
|
1937
|
+
}
|
|
1938
|
+
for (const row of items.rows) {
|
|
1939
|
+
for (const column of row.columns) {
|
|
1940
|
+
if (!column.id || column.type === DisplayItemTypes.DroppableBox) {
|
|
1941
|
+
continue;
|
|
1942
|
+
}
|
|
1943
|
+
const collectionId = getCollectionIdForCollectionType(column.type);
|
|
1944
|
+
if (collectionId?.length) {
|
|
1945
|
+
const collection = column.collection ?? widgetCollections?.[collectionId];
|
|
1946
|
+
// A collection embedded in itself would recurse forever; the column
|
|
1947
|
+
// ids already on the path are the ones being expanded right now.
|
|
1948
|
+
if (collection && !ancestorColumnIds.includes(column.id)) {
|
|
1949
|
+
walk(collection.collectionRows, [...ancestorColumnIds, column.id]);
|
|
1950
|
+
}
|
|
1951
|
+
continue;
|
|
1952
|
+
}
|
|
1953
|
+
paths.push([...ancestorColumnIds, column.id].join(COMPONENT_PROPS_PATH_SEPARATOR));
|
|
1954
|
+
}
|
|
1955
|
+
}
|
|
1956
|
+
};
|
|
1957
|
+
walk(displayItemList, []);
|
|
1958
|
+
return paths;
|
|
1959
|
+
}
|
|
1960
|
+
|
|
1961
|
+
function keyMatchesAnyPath(key, paths) {
|
|
1962
|
+
const suffix = `${COMPONENT_PROPS_PATH_SEPARATOR}${key}`;
|
|
1963
|
+
return paths.some((path) => path === key || path.endsWith(suffix));
|
|
1964
|
+
}
|
|
1965
|
+
/**
|
|
1966
|
+
* Names the `componentProps` keys that address no component in this config.
|
|
1967
|
+
*
|
|
1968
|
+
* A key that matches nothing is silent at render time — the props are simply
|
|
1969
|
+
* never handed to anything — and the usual causes are a typo, a column that
|
|
1970
|
+
* was deleted and re-added with a fresh id, or a path whose parent segment is
|
|
1971
|
+
* wrong. Returns the offending keys so the caller decides how to report them.
|
|
1972
|
+
*/
|
|
1973
|
+
function findUnmatchedComponentPropsKeys({ componentProps, displayItemList, widgetCollections, }) {
|
|
1974
|
+
const keys = componentProps ? Object.keys(componentProps) : [];
|
|
1975
|
+
if (!keys.length) {
|
|
1976
|
+
return [];
|
|
1977
|
+
}
|
|
1978
|
+
const paths = collectComponentInstancePaths({
|
|
1979
|
+
displayItemList,
|
|
1980
|
+
widgetCollections,
|
|
1981
|
+
});
|
|
1982
|
+
return keys.filter((key) => !keyMatchesAnyPath(key, paths));
|
|
1983
|
+
}
|
|
1984
|
+
/**
|
|
1985
|
+
* Development-only console warning for `componentProps` keys that address
|
|
1986
|
+
* nothing. Silent in production: a stale key is a wiring mistake to catch
|
|
1987
|
+
* while building, not noise on a customer's page.
|
|
1988
|
+
*/
|
|
1989
|
+
function warnUnmatchedComponentProps({ componentProps, displayItemList, widgetCollections, publishedKey, }) {
|
|
1990
|
+
if (process.env.NODE_ENV === 'production') {
|
|
1991
|
+
return;
|
|
1992
|
+
}
|
|
1993
|
+
const unmatched = findUnmatchedComponentPropsKeys({
|
|
1994
|
+
componentProps,
|
|
1995
|
+
displayItemList,
|
|
1996
|
+
widgetCollections,
|
|
1997
|
+
});
|
|
1998
|
+
if (!unmatched.length) {
|
|
1999
|
+
return;
|
|
2000
|
+
}
|
|
2001
|
+
console.warn(`RuleCMSWidget "${publishedKey}": componentProps ${unmatched
|
|
2002
|
+
.map((key) => `"${key}"`)
|
|
2003
|
+
.join(', ')} ${unmatched.length === 1 ? 'matches' : 'match'} no component ` +
|
|
2004
|
+
'in this widget, so those props were not passed to anything. Keys are ' +
|
|
2005
|
+
'column ids from the widget config — the composer\'s Modify drawer shows ' +
|
|
2006
|
+
'the id of the selected component.');
|
|
2007
|
+
}
|
|
2008
|
+
|
|
2009
|
+
function isResolutionObject(value) {
|
|
2010
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2011
|
+
}
|
|
2012
|
+
function resolutionValuesDiffer(values) {
|
|
2013
|
+
if (values.all !== undefined && values.all !== null) {
|
|
2014
|
+
return false;
|
|
2015
|
+
}
|
|
2016
|
+
const phone = values.phone;
|
|
2017
|
+
const tablet = values.tablet;
|
|
2018
|
+
const desktop = values.desktop;
|
|
2019
|
+
return phone !== tablet || phone !== desktop || tablet !== desktop;
|
|
2020
|
+
}
|
|
2021
|
+
function scanItemsForDivergence(items) {
|
|
2022
|
+
if (!items?.rows?.length) {
|
|
2023
|
+
return false;
|
|
2024
|
+
}
|
|
2025
|
+
for (const row of items.rows) {
|
|
2026
|
+
if (scanAttributeBagForDivergence(row.rowAttributes)) {
|
|
2027
|
+
return true;
|
|
2028
|
+
}
|
|
2029
|
+
for (const column of row.columns) {
|
|
2030
|
+
if (scanAttributeBagForDivergence(getColumnAttributes(column))) {
|
|
2031
|
+
return true;
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
}
|
|
2035
|
+
return false;
|
|
2036
|
+
}
|
|
2037
|
+
function scanAttributeBagForDivergence(attributes) {
|
|
2038
|
+
if (!attributes) {
|
|
2039
|
+
return false;
|
|
2040
|
+
}
|
|
2041
|
+
for (const [key, value] of Object.entries(attributes)) {
|
|
2042
|
+
if (!key.includes('3-resolutions') || !isResolutionObject(value)) {
|
|
2043
|
+
continue;
|
|
2044
|
+
}
|
|
2045
|
+
if (key === 'hide-component-3-resolutions') {
|
|
2046
|
+
const hideValues = value;
|
|
2047
|
+
const isHidden = (entry) => entry === 'true' || entry === true;
|
|
2048
|
+
if (isHidden(hideValues.phone) !== isHidden(hideValues.tablet) ||
|
|
2049
|
+
isHidden(hideValues.phone) !== isHidden(hideValues.desktop)) {
|
|
2050
|
+
return true;
|
|
2051
|
+
}
|
|
2052
|
+
continue;
|
|
2053
|
+
}
|
|
2054
|
+
if (resolutionValuesDiffer(value)) {
|
|
2055
|
+
return true;
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2058
|
+
return false;
|
|
2059
|
+
}
|
|
2060
|
+
/** True when any component attribute varies by phone/tablet/desktop. */
|
|
2061
|
+
function hasDeviceDivergentValues(displayItemList, widgetCollections) {
|
|
2062
|
+
if (scanItemsForDivergence(displayItemList)) {
|
|
2063
|
+
return true;
|
|
2064
|
+
}
|
|
2065
|
+
for (const collection of Object.values(widgetCollections)) {
|
|
2066
|
+
if (scanItemsForDivergence(collection.collectionRows)) {
|
|
2067
|
+
return true;
|
|
2068
|
+
}
|
|
2069
|
+
}
|
|
2070
|
+
return false;
|
|
2071
|
+
}
|
|
2072
|
+
|
|
2073
|
+
// Matches useDisplayDeviceType breakpoints: phone <= 500px, tablet <= 820px, desktop > 820px
|
|
2074
|
+
const phoneMax = parseInt(phoneModeWidth, 10);
|
|
2075
|
+
const tabletMax = parseInt(tabletModeWidth, 10);
|
|
2076
|
+
const tabletMin = phoneMax + 1;
|
|
2077
|
+
const desktopMin = tabletMax + 1;
|
|
2078
|
+
function buildBreakpointVariantStyles(scopeId) {
|
|
2079
|
+
const phone = `.${scopeId}-phone`;
|
|
2080
|
+
const tablet = `.${scopeId}-tablet`;
|
|
2081
|
+
const desktop = `.${scopeId}-desktop`;
|
|
2082
|
+
return `
|
|
2083
|
+
${phone}, ${tablet}, ${desktop} { display: none; }
|
|
2084
|
+
@media (max-width: ${phoneMax}px) { ${phone} { display: block; } }
|
|
2085
|
+
@media (min-width: ${tabletMin}px) and (max-width: ${tabletMax}px) { ${tablet} { display: block; } }
|
|
2086
|
+
@media (min-width: ${desktopMin}px) { ${desktop} { display: block; } }
|
|
2087
|
+
`.trim();
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
/**
|
|
2091
|
+
* Extracts the (already composed) source components plugin from the plugins
|
|
2092
|
+
* object the pipeline receives. Throws if it is missing or malformed.
|
|
2093
|
+
*
|
|
2094
|
+
* Named to avoid confusion with component-library factories: this does not
|
|
2095
|
+
* build a plugin, it validates and returns the one that was injected.
|
|
2096
|
+
*/
|
|
2097
|
+
function getComponentsPluginFromPlugins(plugins) {
|
|
2098
|
+
// Source components plugin is always required
|
|
2099
|
+
if (!plugins) {
|
|
2100
|
+
throw new Error('Source components plugin is required, but no plugins were provided');
|
|
2101
|
+
}
|
|
2102
|
+
// Get the source components plugin directly from the key-value object
|
|
2103
|
+
const sourceComponentsPlugin = plugins.sourceComponents;
|
|
2104
|
+
if (!sourceComponentsPlugin) {
|
|
2105
|
+
throw new Error('Source components plugin is required, but was not found in plugins object');
|
|
2106
|
+
}
|
|
2107
|
+
// Validate that all required properties are present
|
|
2108
|
+
if (!sourceComponentsPlugin.components) {
|
|
2109
|
+
throw new Error('Source components plugin is missing required property: components');
|
|
2110
|
+
}
|
|
2111
|
+
// Validate that components is an object
|
|
2112
|
+
if (typeof sourceComponentsPlugin.components !== 'object' ||
|
|
2113
|
+
sourceComponentsPlugin.components === null ||
|
|
2114
|
+
Array.isArray(sourceComponentsPlugin.components)) {
|
|
2115
|
+
throw new Error('Source components plugin components must be an object (Record<string, LibraryComponentEntry>)');
|
|
2116
|
+
}
|
|
2117
|
+
return sourceComponentsPlugin;
|
|
2118
|
+
}
|
|
2119
|
+
|
|
2120
|
+
let verticalContainerSeq = 0;
|
|
2121
|
+
class EmbedInVerticalContainerComponent {
|
|
2122
|
+
constructor() {
|
|
2123
|
+
this.isComposeMode = false;
|
|
2124
|
+
this.showDropContainers = false;
|
|
2125
|
+
this.isWithinCollection = false;
|
|
2126
|
+
this.deviceDisplayType = 'Desktop';
|
|
2127
|
+
this.cssString = '';
|
|
2128
|
+
this.scopedCss = '';
|
|
2129
|
+
this.scopeClass = `rulecms-vc-${++verticalContainerSeq}`;
|
|
2130
|
+
this.wrap = false;
|
|
2131
|
+
this.hidden = false;
|
|
2132
|
+
this.wrapperClass = '';
|
|
2133
|
+
this.wrapperStyle = {};
|
|
2134
|
+
}
|
|
2135
|
+
get hiddenAttr() {
|
|
2136
|
+
return this.hidden ? '' : null;
|
|
2137
|
+
}
|
|
2138
|
+
get hostClass() {
|
|
2139
|
+
return this.wrap ? this.wrapperClass : '';
|
|
2140
|
+
}
|
|
2141
|
+
get hostStyle() {
|
|
2142
|
+
if (this.hidden) {
|
|
2143
|
+
return { display: 'none' };
|
|
2144
|
+
}
|
|
2145
|
+
if (this.wrap) {
|
|
2146
|
+
return this.wrapperStyle;
|
|
2147
|
+
}
|
|
2148
|
+
return { display: 'contents' };
|
|
2149
|
+
}
|
|
2150
|
+
ngOnChanges() {
|
|
2151
|
+
const containerCss = this.displayItemList.containerAttributes?.[cssAttrArrayKey] || [];
|
|
2152
|
+
this.cssString = containerCss.join(';\n');
|
|
2153
|
+
this.scopedCss = this.cssString
|
|
2154
|
+
? `.${this.scopeClass} {\n${this.cssString}\n}`
|
|
2155
|
+
: '';
|
|
2156
|
+
this.hidden =
|
|
2157
|
+
!this.isComposeMode &&
|
|
2158
|
+
isWidgetHiddenForDevice({
|
|
2159
|
+
containerAttributes: this.displayItemList.containerAttributes,
|
|
2160
|
+
deviceDisplayType: this.deviceDisplayType,
|
|
2161
|
+
});
|
|
2162
|
+
const widgetContainerStyles = resolveWidgetContainerStyles({
|
|
2163
|
+
containerAttributes: this.displayItemList.containerAttributes,
|
|
2164
|
+
deviceDisplayType: this.deviceDisplayType,
|
|
2165
|
+
isComposeMode: this.isComposeMode,
|
|
2166
|
+
});
|
|
2167
|
+
const hasWidgetStyles = widgetBasedPropertiesAreAssigned(widgetContainerStyles);
|
|
2168
|
+
this.wrap =
|
|
2169
|
+
(this.isComposeMode && !this.isWithinCollection) ||
|
|
2170
|
+
this.showDropContainers ||
|
|
2171
|
+
containerCss.length > 0 ||
|
|
2172
|
+
hasWidgetStyles ||
|
|
2173
|
+
hasMoreThanOneRows(this.isComposeMode, this.displayItemList.rows, this.isWithinCollection);
|
|
2174
|
+
this.wrapperClass = [this.cssString ? this.scopeClass : undefined, widgetContainerStyles.cssClasses]
|
|
2175
|
+
.filter(Boolean)
|
|
2176
|
+
.join(' ');
|
|
2177
|
+
this.wrapperStyle = {
|
|
2178
|
+
...(containerCss.some((entry) => entry.toLowerCase().startsWith('height:'))
|
|
2179
|
+
? {}
|
|
2180
|
+
: { height: this.isWithinCollection ? 'auto' : '100%' }),
|
|
2181
|
+
display: 'flex',
|
|
2182
|
+
flexDirection: 'column',
|
|
2183
|
+
...widgetContainerStyles.styles,
|
|
2184
|
+
};
|
|
2185
|
+
}
|
|
2186
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: EmbedInVerticalContainerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2187
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: EmbedInVerticalContainerComponent, isStandalone: true, selector: "rulecms-embed-vertical", inputs: { displayItemList: "displayItemList", isComposeMode: "isComposeMode", showDropContainers: "showDropContainers", isWithinCollection: "isWithinCollection", deviceDisplayType: "deviceDisplayType" }, host: { properties: { "attr.hidden": "this.hiddenAttr", "class": "this.hostClass", "style": "this.hostStyle" } }, usesOnChanges: true, ngImport: i0, template: `
|
|
2188
|
+
@if (cssString) {
|
|
2189
|
+
<style [innerText]="scopedCss"></style>
|
|
2190
|
+
}
|
|
2191
|
+
<ng-content />
|
|
2192
|
+
`, isInline: true }); }
|
|
2193
|
+
}
|
|
2194
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: EmbedInVerticalContainerComponent, decorators: [{
|
|
2195
|
+
type: Component,
|
|
2196
|
+
args: [{
|
|
2197
|
+
selector: 'rulecms-embed-vertical',
|
|
2198
|
+
standalone: true,
|
|
2199
|
+
template: `
|
|
2200
|
+
@if (cssString) {
|
|
2201
|
+
<style [innerText]="scopedCss"></style>
|
|
2202
|
+
}
|
|
2203
|
+
<ng-content />
|
|
2204
|
+
`,
|
|
2205
|
+
}]
|
|
2206
|
+
}], propDecorators: { displayItemList: [{
|
|
2207
|
+
type: Input,
|
|
2208
|
+
args: [{ required: true }]
|
|
2209
|
+
}], isComposeMode: [{
|
|
2210
|
+
type: Input
|
|
2211
|
+
}], showDropContainers: [{
|
|
2212
|
+
type: Input
|
|
2213
|
+
}], isWithinCollection: [{
|
|
2214
|
+
type: Input
|
|
2215
|
+
}], deviceDisplayType: [{
|
|
2216
|
+
type: Input
|
|
2217
|
+
}], hiddenAttr: [{
|
|
2218
|
+
type: HostBinding,
|
|
2219
|
+
args: ['attr.hidden']
|
|
2220
|
+
}], hostClass: [{
|
|
2221
|
+
type: HostBinding,
|
|
2222
|
+
args: ['class']
|
|
2223
|
+
}], hostStyle: [{
|
|
2224
|
+
type: HostBinding,
|
|
2225
|
+
args: ['style']
|
|
2226
|
+
}] } });
|
|
2227
|
+
function hasMoreThanOneRows(isComposeMode, rowsOfItems, isWithinCollection) {
|
|
2228
|
+
const oneRowCount = isComposeMode && !isWithinCollection ? 3 : 1;
|
|
2229
|
+
return !!rowsOfItems?.length && rowsOfItems.length > oneRowCount;
|
|
2230
|
+
}
|
|
2231
|
+
|
|
2232
|
+
class EmbedInRowComponent {
|
|
2233
|
+
constructor() {
|
|
2234
|
+
this.isComposeMode = false;
|
|
2235
|
+
this.showDropContainers = false;
|
|
2236
|
+
this.isWithinCollection = false;
|
|
2237
|
+
this.deviceDisplayType = 'Desktop';
|
|
2238
|
+
this.hidden = false;
|
|
2239
|
+
this.wrap = false;
|
|
2240
|
+
this.style = {};
|
|
2241
|
+
this.cssClasses = '';
|
|
2242
|
+
}
|
|
2243
|
+
get hiddenAttr() {
|
|
2244
|
+
return this.hidden ? '' : null;
|
|
2245
|
+
}
|
|
2246
|
+
get hostClass() {
|
|
2247
|
+
return this.wrap ? this.cssClasses : '';
|
|
2248
|
+
}
|
|
2249
|
+
get hostStyle() {
|
|
2250
|
+
if (this.hidden) {
|
|
2251
|
+
return { display: 'none' };
|
|
2252
|
+
}
|
|
2253
|
+
if (this.wrap) {
|
|
2254
|
+
return this.style;
|
|
2255
|
+
}
|
|
2256
|
+
return { display: 'contents' };
|
|
2257
|
+
}
|
|
2258
|
+
ngOnChanges() {
|
|
2259
|
+
this.hidden =
|
|
2260
|
+
!this.isComposeMode &&
|
|
2261
|
+
isRowHiddenForDevice({ row: this.row, deviceDisplayType: this.deviceDisplayType });
|
|
2262
|
+
this.wrap =
|
|
2263
|
+
this.showDropContainers ||
|
|
2264
|
+
rowBasedPropertiesAreAssigned(this.row) ||
|
|
2265
|
+
hasMoreThanOneChildren(this.isComposeMode, this.row, this.isWithinCollection);
|
|
2266
|
+
this.style = resolveRowStyles({
|
|
2267
|
+
row: this.row,
|
|
2268
|
+
deviceDisplayType: this.deviceDisplayType,
|
|
2269
|
+
isComposeMode: this.isComposeMode,
|
|
2270
|
+
});
|
|
2271
|
+
const resolvedRowAttributes = getDeviceTypeBasedAttributes({
|
|
2272
|
+
deviceDisplayType: this.deviceDisplayType,
|
|
2273
|
+
componentAttributes: this.row.rowAttributes,
|
|
2274
|
+
});
|
|
2275
|
+
this.cssClasses =
|
|
2276
|
+
normalizeCssClasses(resolvedRowAttributes?.componentAttributesSpecificToDeviceType?.[CSS_CLASSES_ATTRIBUTE_NAME]) ?? '';
|
|
2277
|
+
}
|
|
2278
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: EmbedInRowComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2279
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: EmbedInRowComponent, isStandalone: true, selector: "rulecms-embed-row", inputs: { row: "row", isComposeMode: "isComposeMode", showDropContainers: "showDropContainers", isWithinCollection: "isWithinCollection", deviceDisplayType: "deviceDisplayType" }, host: { properties: { "attr.hidden": "this.hiddenAttr", "class": "this.hostClass", "style": "this.hostStyle" } }, usesOnChanges: true, ngImport: i0, template: `<ng-content />`, isInline: true }); }
|
|
2280
|
+
}
|
|
2281
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: EmbedInRowComponent, decorators: [{
|
|
2282
|
+
type: Component,
|
|
2283
|
+
args: [{
|
|
2284
|
+
selector: 'rulecms-embed-row',
|
|
2285
|
+
standalone: true,
|
|
2286
|
+
template: `<ng-content />`,
|
|
2287
|
+
}]
|
|
2288
|
+
}], propDecorators: { row: [{
|
|
2289
|
+
type: Input,
|
|
2290
|
+
args: [{ required: true }]
|
|
2291
|
+
}], isComposeMode: [{
|
|
2292
|
+
type: Input
|
|
2293
|
+
}], showDropContainers: [{
|
|
2294
|
+
type: Input
|
|
2295
|
+
}], isWithinCollection: [{
|
|
2296
|
+
type: Input
|
|
2297
|
+
}], deviceDisplayType: [{
|
|
2298
|
+
type: Input
|
|
2299
|
+
}], hiddenAttr: [{
|
|
2300
|
+
type: HostBinding,
|
|
2301
|
+
args: ['attr.hidden']
|
|
2302
|
+
}], hostClass: [{
|
|
2303
|
+
type: HostBinding,
|
|
2304
|
+
args: ['class']
|
|
2305
|
+
}], hostStyle: [{
|
|
2306
|
+
type: HostBinding,
|
|
2307
|
+
args: ['style']
|
|
2308
|
+
}] } });
|
|
2309
|
+
function hasMoreThanOneChildren(isComposeMode, row, isWithinCollection) {
|
|
2310
|
+
const oneColumnCount = isComposeMode && !isWithinCollection ? 3 : 1;
|
|
2311
|
+
return !!row?.columns?.length && row.columns.length > oneColumnCount;
|
|
2312
|
+
}
|
|
2313
|
+
|
|
2314
|
+
// Layout styles that belong on the column wrapper (not the component itself)
|
|
2315
|
+
// for noContainer components, whose cards ignore styleProps. Keys must cover
|
|
2316
|
+
// every style produced by objectStyleAttributeRegistry formatters — missing
|
|
2317
|
+
// keys are silently dropped for r-text and similar cards.
|
|
2318
|
+
const DIMENSION_STYLE_KEYS = [
|
|
2319
|
+
'minWidth',
|
|
2320
|
+
'maxWidth',
|
|
2321
|
+
'minHeight',
|
|
2322
|
+
'maxHeight',
|
|
2323
|
+
'margin',
|
|
2324
|
+
'marginTop',
|
|
2325
|
+
'marginRight',
|
|
2326
|
+
'marginBottom',
|
|
2327
|
+
'marginLeft',
|
|
2328
|
+
'padding',
|
|
2329
|
+
'paddingTop',
|
|
2330
|
+
'paddingRight',
|
|
2331
|
+
'paddingBottom',
|
|
2332
|
+
'paddingLeft',
|
|
2333
|
+
'borderWidth',
|
|
2334
|
+
'borderStyle',
|
|
2335
|
+
'borderColor',
|
|
2336
|
+
// Whole-border design token: the one case where the shorthand is emitted
|
|
2337
|
+
'border',
|
|
2338
|
+
'borderRadius',
|
|
2339
|
+
'boxShadow',
|
|
2340
|
+
'width',
|
|
2341
|
+
'height',
|
|
2342
|
+
'gap',
|
|
2343
|
+
// Flex layout (display is derived when any flex layout prop is set)
|
|
2344
|
+
'display',
|
|
2345
|
+
'justifyContent',
|
|
2346
|
+
'alignItems',
|
|
2347
|
+
'flexWrap',
|
|
2348
|
+
'alignContent',
|
|
2349
|
+
'flexDirection',
|
|
2350
|
+
'overflow',
|
|
2351
|
+
'overflowX',
|
|
2352
|
+
'overflowY',
|
|
2353
|
+
'backgroundColor',
|
|
2354
|
+
'backgroundImage',
|
|
2355
|
+
'backgroundSize',
|
|
2356
|
+
'backgroundPosition',
|
|
2357
|
+
'backgroundRepeat',
|
|
2358
|
+
'opacity',
|
|
2359
|
+
// Typography (inherited by text descendants from the column wrapper)
|
|
2360
|
+
'fontFamily',
|
|
2361
|
+
'fontSize',
|
|
2362
|
+
'fontWeight',
|
|
2363
|
+
'fontStyle',
|
|
2364
|
+
'color',
|
|
2365
|
+
'lineHeight',
|
|
2366
|
+
'letterSpacing',
|
|
2367
|
+
'textAlign',
|
|
2368
|
+
'textDecoration',
|
|
2369
|
+
'textTransform',
|
|
2370
|
+
];
|
|
2371
|
+
const isSetStyleValue = (value) => value !== undefined && value !== null && value !== '';
|
|
2372
|
+
const pickDimensionStyles = (styleProps) => {
|
|
2373
|
+
if (!styleProps) {
|
|
2374
|
+
return {};
|
|
2375
|
+
}
|
|
2376
|
+
return DIMENSION_STYLE_KEYS.reduce((acc, key) => {
|
|
2377
|
+
const value = styleProps[key];
|
|
2378
|
+
if (isSetStyleValue(value)) {
|
|
2379
|
+
acc[key] = value;
|
|
2380
|
+
}
|
|
2381
|
+
return acc;
|
|
2382
|
+
}, {});
|
|
2383
|
+
};
|
|
2384
|
+
const omitDimensionStyles = (styleProps) => {
|
|
2385
|
+
if (!styleProps) {
|
|
2386
|
+
return undefined;
|
|
2387
|
+
}
|
|
2388
|
+
const result = { ...styleProps };
|
|
2389
|
+
for (const key of DIMENSION_STYLE_KEYS) {
|
|
2390
|
+
delete result[key];
|
|
2391
|
+
}
|
|
2392
|
+
return Object.keys(result).length ? result : undefined;
|
|
2393
|
+
};
|
|
2394
|
+
const hasDimensionStyles = (dimensionStyles) => Object.keys(dimensionStyles).length > 0;
|
|
2395
|
+
|
|
2396
|
+
/**
|
|
2397
|
+
* Decides whether a component needs the dimension-style wrapper div.
|
|
2398
|
+
*
|
|
2399
|
+
* A component library may answer per render by exposing `resolveNoContainer`,
|
|
2400
|
+
* which takes precedence over the static `noContainer` flag on the same entry.
|
|
2401
|
+
* Libraries that expose neither keep the historical default of `false`.
|
|
2402
|
+
*
|
|
2403
|
+
* A resolver that throws or returns a non-boolean is a bug in the library, not
|
|
2404
|
+
* a reason to fail the page: it is reported and the static flag is used
|
|
2405
|
+
* instead.
|
|
2406
|
+
*/
|
|
2407
|
+
const resolveNoContainer = (entry, context) => {
|
|
2408
|
+
const staticNoContainer = entry?.noContainer ?? false;
|
|
2409
|
+
const resolver = entry?.resolveNoContainer;
|
|
2410
|
+
if (typeof resolver !== 'function') {
|
|
2411
|
+
return staticNoContainer;
|
|
2412
|
+
}
|
|
2413
|
+
try {
|
|
2414
|
+
const resolved = resolver(context);
|
|
2415
|
+
if (typeof resolved === 'boolean') {
|
|
2416
|
+
return resolved;
|
|
2417
|
+
}
|
|
2418
|
+
console.error(`resolveNoContainer: component "${entry?.id}" returned ${typeof resolved} instead of a boolean; falling back to noContainer=${staticNoContainer}`);
|
|
2419
|
+
}
|
|
2420
|
+
catch (error) {
|
|
2421
|
+
console.error(`resolveNoContainer: component "${entry?.id}" threw; falling back to noContainer=${staticNoContainer}`, error);
|
|
2422
|
+
}
|
|
2423
|
+
return staticNoContainer;
|
|
2424
|
+
};
|
|
2425
|
+
|
|
2426
|
+
/**
|
|
2427
|
+
* Decides whether a card's own root element can carry a `className` — i.e.
|
|
2428
|
+
* whether the renderer can hand the card a class instead of wrapping it in a
|
|
2429
|
+
* fresh `div` to carry one.
|
|
2430
|
+
*
|
|
2431
|
+
* Absence of a resolver defaults to `false`: a library that predates this
|
|
2432
|
+
* contract gets a wrapper div instead, which is one extra element but never
|
|
2433
|
+
* loses the class.
|
|
2434
|
+
*
|
|
2435
|
+
* A resolver that throws or returns a non-boolean is a bug in the library,
|
|
2436
|
+
* not a reason to fail the page: it is reported and `false` is used instead.
|
|
2437
|
+
*/
|
|
2438
|
+
const resolveRendersOwnElement = (entry, context) => {
|
|
2439
|
+
const resolver = entry?.resolveRendersOwnElement;
|
|
2440
|
+
if (typeof resolver !== 'function') {
|
|
2441
|
+
return false;
|
|
2442
|
+
}
|
|
2443
|
+
try {
|
|
2444
|
+
const resolved = resolver(context);
|
|
2445
|
+
if (typeof resolved === 'boolean') {
|
|
2446
|
+
return resolved;
|
|
2447
|
+
}
|
|
2448
|
+
console.error(`resolveRendersOwnElement: component "${entry?.id}" returned ${typeof resolved} instead of a boolean; falling back to false`);
|
|
2449
|
+
}
|
|
2450
|
+
catch (error) {
|
|
2451
|
+
console.error(`resolveRendersOwnElement: component "${entry?.id}" threw; falling back to false`, error);
|
|
2452
|
+
}
|
|
2453
|
+
return false;
|
|
2454
|
+
};
|
|
2455
|
+
|
|
2456
|
+
class DisplayComponentComponent {
|
|
2457
|
+
constructor() {
|
|
2458
|
+
this.card = null;
|
|
2459
|
+
this.cardInputs = {};
|
|
2460
|
+
this.needsWrapper = false;
|
|
2461
|
+
this.rendersOwnElement = false;
|
|
2462
|
+
this.wrapperStyle = {};
|
|
2463
|
+
}
|
|
2464
|
+
ngOnChanges() {
|
|
2465
|
+
const matchingEntry = this.components[resolveKey(this.libraryId, this.componentType)];
|
|
2466
|
+
const Card = matchingEntry?.card;
|
|
2467
|
+
if (!Card) {
|
|
2468
|
+
console.error(`DisplayComponent: Component with type ${this.componentType}${this.libraryId ? ` (library "${this.libraryId}")` : ''} not found in components`);
|
|
2469
|
+
this.card = null;
|
|
2470
|
+
return;
|
|
2471
|
+
}
|
|
2472
|
+
const noContainerContext = {
|
|
2473
|
+
componentAttributes: this.componentAttributes,
|
|
2474
|
+
styleProps: this.styleProps,
|
|
2475
|
+
};
|
|
2476
|
+
const noContainer = resolveNoContainer(matchingEntry, noContainerContext);
|
|
2477
|
+
const dimensionStyles = pickDimensionStyles(this.styleProps);
|
|
2478
|
+
const componentStyleProps = noContainer ? omitDimensionStyles(this.styleProps) : this.styleProps;
|
|
2479
|
+
this.cssClasses = normalizeCssClasses(this.componentAttributes?.[CSS_CLASSES_ATTRIBUTE_NAME]);
|
|
2480
|
+
this.needsWrapper = noContainer && hasDimensionStyles(dimensionStyles);
|
|
2481
|
+
this.rendersOwnElement = !noContainer || resolveRendersOwnElement(matchingEntry, noContainerContext);
|
|
2482
|
+
const cardClassName = !this.needsWrapper && this.rendersOwnElement ? this.cssClasses : undefined;
|
|
2483
|
+
this.wrapperStyle = dimensionStyles;
|
|
2484
|
+
this.wrapperClass = this.cssClasses;
|
|
2485
|
+
this.card = Card;
|
|
2486
|
+
this.cardInputs = {
|
|
2487
|
+
componentAttributes: this.componentAttributes,
|
|
2488
|
+
styleProps: componentStyleProps,
|
|
2489
|
+
className: cardClassName,
|
|
2490
|
+
widgetInstanceProps: this.widgetInstanceProps,
|
|
2491
|
+
};
|
|
2492
|
+
}
|
|
2493
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: DisplayComponentComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2494
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: DisplayComponentComponent, isStandalone: true, selector: "rulecms-display-component", inputs: { componentType: "componentType", libraryId: "libraryId", componentAttributes: "componentAttributes", components: "components", styleProps: "styleProps", widgetInstanceProps: "widgetInstanceProps" }, host: { styleAttribute: "display: contents" }, usesOnChanges: true, ngImport: i0, template: `
|
|
2495
|
+
@if (card) {
|
|
2496
|
+
@if (needsWrapper) {
|
|
2497
|
+
<div [class]="wrapperClass || undefined" [ngStyle]="wrapperStyle">
|
|
2498
|
+
<ng-container *ngComponentOutlet="card; inputs: cardInputs" />
|
|
2499
|
+
</div>
|
|
2500
|
+
} @else if (!rendersOwnElement && cssClasses) {
|
|
2501
|
+
<div [class]="cssClasses">
|
|
2502
|
+
<ng-container *ngComponentOutlet="card; inputs: cardInputs" />
|
|
2503
|
+
</div>
|
|
2504
|
+
} @else {
|
|
2505
|
+
<ng-container *ngComponentOutlet="card; inputs: cardInputs" />
|
|
2506
|
+
}
|
|
2507
|
+
}
|
|
2508
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: NgComponentOutlet, selector: "[ngComponentOutlet]", inputs: ["ngComponentOutlet", "ngComponentOutletInputs", "ngComponentOutletInjector", "ngComponentOutletContent", "ngComponentOutletNgModule", "ngComponentOutletNgModuleFactory"], exportAs: ["ngComponentOutlet"] }, { kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }] }); }
|
|
2509
|
+
}
|
|
2510
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: DisplayComponentComponent, decorators: [{
|
|
2511
|
+
type: Component,
|
|
2512
|
+
args: [{
|
|
2513
|
+
selector: 'rulecms-display-component',
|
|
2514
|
+
standalone: true,
|
|
2515
|
+
imports: [NgComponentOutlet, NgStyle],
|
|
2516
|
+
template: `
|
|
2517
|
+
@if (card) {
|
|
2518
|
+
@if (needsWrapper) {
|
|
2519
|
+
<div [class]="wrapperClass || undefined" [ngStyle]="wrapperStyle">
|
|
2520
|
+
<ng-container *ngComponentOutlet="card; inputs: cardInputs" />
|
|
2521
|
+
</div>
|
|
2522
|
+
} @else if (!rendersOwnElement && cssClasses) {
|
|
2523
|
+
<div [class]="cssClasses">
|
|
2524
|
+
<ng-container *ngComponentOutlet="card; inputs: cardInputs" />
|
|
2525
|
+
</div>
|
|
2526
|
+
} @else {
|
|
2527
|
+
<ng-container *ngComponentOutlet="card; inputs: cardInputs" />
|
|
2528
|
+
}
|
|
2529
|
+
}
|
|
2530
|
+
`,
|
|
2531
|
+
host: { style: 'display: contents' },
|
|
2532
|
+
}]
|
|
2533
|
+
}], propDecorators: { componentType: [{
|
|
2534
|
+
type: Input,
|
|
2535
|
+
args: [{ required: true }]
|
|
2536
|
+
}], libraryId: [{
|
|
2537
|
+
type: Input
|
|
2538
|
+
}], componentAttributes: [{
|
|
2539
|
+
type: Input
|
|
2540
|
+
}], components: [{
|
|
2541
|
+
type: Input,
|
|
2542
|
+
args: [{ required: true }]
|
|
2543
|
+
}], styleProps: [{
|
|
2544
|
+
type: Input
|
|
2545
|
+
}], widgetInstanceProps: [{
|
|
2546
|
+
type: Input
|
|
2547
|
+
}] } });
|
|
2548
|
+
|
|
2549
|
+
class RenderComponentsInnerComponent {
|
|
2550
|
+
constructor() {
|
|
2551
|
+
this.isComposeMode = false;
|
|
2552
|
+
this.isWithinCollection = false;
|
|
2553
|
+
this.showDropContainers = false;
|
|
2554
|
+
}
|
|
2555
|
+
get components() {
|
|
2556
|
+
return getComponentsPluginFromPlugins(this.plugins).components;
|
|
2557
|
+
}
|
|
2558
|
+
isRenderableColumn(col) {
|
|
2559
|
+
if (this.isComposeMode && col.type === DisplayItemTypes.DroppableBox) {
|
|
2560
|
+
return false;
|
|
2561
|
+
}
|
|
2562
|
+
const { componentAttributesBasedOnDevice, componentStyles } = getComponentAttributesAndStyles({
|
|
2563
|
+
col,
|
|
2564
|
+
deviceDisplayType: this.deviceDisplayType,
|
|
2565
|
+
isComposeMode: this.isComposeMode,
|
|
2566
|
+
sourceComponentsPlugin: getComponentsPluginFromPlugins(this.plugins),
|
|
2567
|
+
});
|
|
2568
|
+
const isHidden = !!componentAttributesBasedOnDevice &&
|
|
2569
|
+
componentAttributesBasedOnDevice['hide-component-3-resolutions'] === 'true';
|
|
2570
|
+
if (!this.isComposeMode && isHidden) {
|
|
2571
|
+
return false;
|
|
2572
|
+
}
|
|
2573
|
+
// stash for template helpers — computed again in columnView
|
|
2574
|
+
void componentStyles;
|
|
2575
|
+
return true;
|
|
2576
|
+
}
|
|
2577
|
+
columnView(col) {
|
|
2578
|
+
const { componentAttributesBasedOnDevice, componentStyles } = getComponentAttributesAndStyles({
|
|
2579
|
+
col,
|
|
2580
|
+
deviceDisplayType: this.deviceDisplayType,
|
|
2581
|
+
isComposeMode: this.isComposeMode,
|
|
2582
|
+
sourceComponentsPlugin: getComponentsPluginFromPlugins(this.plugins),
|
|
2583
|
+
});
|
|
2584
|
+
return {
|
|
2585
|
+
componentAttributes: componentAttributesBasedOnDevice,
|
|
2586
|
+
styleProps: componentStyles,
|
|
2587
|
+
};
|
|
2588
|
+
}
|
|
2589
|
+
collectionFor(col) {
|
|
2590
|
+
const collectionId = getCollectionIdForCollectionType(col.type);
|
|
2591
|
+
if (!collectionId?.length) {
|
|
2592
|
+
return null;
|
|
2593
|
+
}
|
|
2594
|
+
const collection = col.collection ?? this.widgetCollections[collectionId];
|
|
2595
|
+
if (!collection) {
|
|
2596
|
+
throw new Error(`DisplayCollection - Collection with ID ${collectionId} not found in widgetCollections. Available collections: ${Object.keys(this.widgetCollections).join(', ')}`);
|
|
2597
|
+
}
|
|
2598
|
+
if (!collection.collectionRows || !hasItems(collection.collectionRows)) {
|
|
2599
|
+
return null;
|
|
2600
|
+
}
|
|
2601
|
+
return collection.collectionRows;
|
|
2602
|
+
}
|
|
2603
|
+
childAncestorIds(columnId) {
|
|
2604
|
+
return [...(this.ancestorColumnIds ?? []), columnId];
|
|
2605
|
+
}
|
|
2606
|
+
instanceProps(columnId) {
|
|
2607
|
+
return resolveWidgetInstanceProps({
|
|
2608
|
+
componentProps: this.componentProps,
|
|
2609
|
+
ancestorColumnIds: this.ancestorColumnIds,
|
|
2610
|
+
columnId,
|
|
2611
|
+
});
|
|
2612
|
+
}
|
|
2613
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RenderComponentsInnerComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2614
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: RenderComponentsInnerComponent, isStandalone: true, selector: "rulecms-render-inner", inputs: { displayItemList: "displayItemList", isComposeMode: "isComposeMode", isWithinCollection: "isWithinCollection", widgetCollections: "widgetCollections", showDropContainers: "showDropContainers", reduxDeviceDisplayType: "reduxDeviceDisplayType", plugins: "plugins", deviceDisplayType: "deviceDisplayType", componentProps: "componentProps", ancestorColumnIds: "ancestorColumnIds" }, host: { styleAttribute: "display: contents" }, ngImport: i0, template: `
|
|
2615
|
+
<rulecms-embed-vertical
|
|
2616
|
+
[displayItemList]="displayItemList"
|
|
2617
|
+
[isComposeMode]="isComposeMode"
|
|
2618
|
+
[showDropContainers]="showDropContainers"
|
|
2619
|
+
[isWithinCollection]="isWithinCollection"
|
|
2620
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2621
|
+
>
|
|
2622
|
+
@for (row of displayItemList.rows; track row.id) {
|
|
2623
|
+
<rulecms-embed-row
|
|
2624
|
+
[row]="row"
|
|
2625
|
+
[isComposeMode]="isComposeMode"
|
|
2626
|
+
[showDropContainers]="showDropContainers"
|
|
2627
|
+
[isWithinCollection]="isWithinCollection"
|
|
2628
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2629
|
+
>
|
|
2630
|
+
@for (col of row.columns; track col.id) {
|
|
2631
|
+
@if (isRenderableColumn(col)) {
|
|
2632
|
+
@if (collectionFor(col); as collectionItems) {
|
|
2633
|
+
<rulecms-render-inner
|
|
2634
|
+
[displayItemList]="collectionItems"
|
|
2635
|
+
[isComposeMode]="isComposeMode"
|
|
2636
|
+
[isWithinCollection]="true"
|
|
2637
|
+
[widgetCollections]="widgetCollections"
|
|
2638
|
+
[showDropContainers]="showDropContainers"
|
|
2639
|
+
[reduxDeviceDisplayType]="reduxDeviceDisplayType"
|
|
2640
|
+
[plugins]="plugins"
|
|
2641
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2642
|
+
[componentProps]="componentProps"
|
|
2643
|
+
[ancestorColumnIds]="childAncestorIds(col.id)"
|
|
2644
|
+
/>
|
|
2645
|
+
} @else {
|
|
2646
|
+
<rulecms-display-component
|
|
2647
|
+
[componentType]="col.type"
|
|
2648
|
+
[libraryId]="col.libraryId"
|
|
2649
|
+
[componentAttributes]="columnView(col).componentAttributes"
|
|
2650
|
+
[components]="components"
|
|
2651
|
+
[styleProps]="columnView(col).styleProps"
|
|
2652
|
+
[widgetInstanceProps]="instanceProps(col.id)"
|
|
2653
|
+
/>
|
|
2654
|
+
}
|
|
2655
|
+
}
|
|
2656
|
+
}
|
|
2657
|
+
</rulecms-embed-row>
|
|
2658
|
+
}
|
|
2659
|
+
</rulecms-embed-vertical>
|
|
2660
|
+
`, isInline: true, dependencies: [{ kind: "component", type: RenderComponentsInnerComponent, selector: "rulecms-render-inner", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "deviceDisplayType", "componentProps", "ancestorColumnIds"] }, { kind: "component", type: EmbedInVerticalContainerComponent, selector: "rulecms-embed-vertical", inputs: ["displayItemList", "isComposeMode", "showDropContainers", "isWithinCollection", "deviceDisplayType"] }, { kind: "component", type: EmbedInRowComponent, selector: "rulecms-embed-row", inputs: ["row", "isComposeMode", "showDropContainers", "isWithinCollection", "deviceDisplayType"] }, { kind: "component", type: DisplayComponentComponent, selector: "rulecms-display-component", inputs: ["componentType", "libraryId", "componentAttributes", "components", "styleProps", "widgetInstanceProps"] }] }); }
|
|
2661
|
+
}
|
|
2662
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RenderComponentsInnerComponent, decorators: [{
|
|
2663
|
+
type: Component,
|
|
2664
|
+
args: [{
|
|
2665
|
+
selector: 'rulecms-render-inner',
|
|
2666
|
+
standalone: true,
|
|
2667
|
+
imports: [EmbedInVerticalContainerComponent, EmbedInRowComponent, DisplayComponentComponent],
|
|
2668
|
+
template: `
|
|
2669
|
+
<rulecms-embed-vertical
|
|
2670
|
+
[displayItemList]="displayItemList"
|
|
2671
|
+
[isComposeMode]="isComposeMode"
|
|
2672
|
+
[showDropContainers]="showDropContainers"
|
|
2673
|
+
[isWithinCollection]="isWithinCollection"
|
|
2674
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2675
|
+
>
|
|
2676
|
+
@for (row of displayItemList.rows; track row.id) {
|
|
2677
|
+
<rulecms-embed-row
|
|
2678
|
+
[row]="row"
|
|
2679
|
+
[isComposeMode]="isComposeMode"
|
|
2680
|
+
[showDropContainers]="showDropContainers"
|
|
2681
|
+
[isWithinCollection]="isWithinCollection"
|
|
2682
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2683
|
+
>
|
|
2684
|
+
@for (col of row.columns; track col.id) {
|
|
2685
|
+
@if (isRenderableColumn(col)) {
|
|
2686
|
+
@if (collectionFor(col); as collectionItems) {
|
|
2687
|
+
<rulecms-render-inner
|
|
2688
|
+
[displayItemList]="collectionItems"
|
|
2689
|
+
[isComposeMode]="isComposeMode"
|
|
2690
|
+
[isWithinCollection]="true"
|
|
2691
|
+
[widgetCollections]="widgetCollections"
|
|
2692
|
+
[showDropContainers]="showDropContainers"
|
|
2693
|
+
[reduxDeviceDisplayType]="reduxDeviceDisplayType"
|
|
2694
|
+
[plugins]="plugins"
|
|
2695
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2696
|
+
[componentProps]="componentProps"
|
|
2697
|
+
[ancestorColumnIds]="childAncestorIds(col.id)"
|
|
2698
|
+
/>
|
|
2699
|
+
} @else {
|
|
2700
|
+
<rulecms-display-component
|
|
2701
|
+
[componentType]="col.type"
|
|
2702
|
+
[libraryId]="col.libraryId"
|
|
2703
|
+
[componentAttributes]="columnView(col).componentAttributes"
|
|
2704
|
+
[components]="components"
|
|
2705
|
+
[styleProps]="columnView(col).styleProps"
|
|
2706
|
+
[widgetInstanceProps]="instanceProps(col.id)"
|
|
2707
|
+
/>
|
|
2708
|
+
}
|
|
2709
|
+
}
|
|
2710
|
+
}
|
|
2711
|
+
</rulecms-embed-row>
|
|
2712
|
+
}
|
|
2713
|
+
</rulecms-embed-vertical>
|
|
2714
|
+
`,
|
|
2715
|
+
host: { style: 'display: contents' },
|
|
2716
|
+
}]
|
|
2717
|
+
}], propDecorators: { displayItemList: [{
|
|
2718
|
+
type: Input,
|
|
2719
|
+
args: [{ required: true }]
|
|
2720
|
+
}], isComposeMode: [{
|
|
2721
|
+
type: Input
|
|
2722
|
+
}], isWithinCollection: [{
|
|
2723
|
+
type: Input
|
|
2724
|
+
}], widgetCollections: [{
|
|
2725
|
+
type: Input,
|
|
2726
|
+
args: [{ required: true }]
|
|
2727
|
+
}], showDropContainers: [{
|
|
2728
|
+
type: Input
|
|
2729
|
+
}], reduxDeviceDisplayType: [{
|
|
2730
|
+
type: Input
|
|
2731
|
+
}], plugins: [{
|
|
2732
|
+
type: Input,
|
|
2733
|
+
args: [{ required: true }]
|
|
2734
|
+
}], deviceDisplayType: [{
|
|
2735
|
+
type: Input,
|
|
2736
|
+
args: [{ required: true }]
|
|
2737
|
+
}], componentProps: [{
|
|
2738
|
+
type: Input
|
|
2739
|
+
}], ancestorColumnIds: [{
|
|
2740
|
+
type: Input
|
|
2741
|
+
}] } });
|
|
2742
|
+
|
|
2743
|
+
class RenderComponentsForDeviceComponent {
|
|
2744
|
+
constructor() {
|
|
2745
|
+
this.isComposeMode = false;
|
|
2746
|
+
this.isWithinCollection = false;
|
|
2747
|
+
this.showDropContainers = false;
|
|
2748
|
+
}
|
|
2749
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RenderComponentsForDeviceComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2750
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: RenderComponentsForDeviceComponent, isStandalone: true, selector: "rulecms-render-for-device", inputs: { displayItemList: "displayItemList", isComposeMode: "isComposeMode", isWithinCollection: "isWithinCollection", widgetCollections: "widgetCollections", showDropContainers: "showDropContainers", reduxDeviceDisplayType: "reduxDeviceDisplayType", deviceDisplayType: "deviceDisplayType", plugins: "plugins", componentProps: "componentProps", ancestorColumnIds: "ancestorColumnIds" }, host: { styleAttribute: "display: contents" }, ngImport: i0, template: `
|
|
2751
|
+
@if (displayItemList?.rows?.length) {
|
|
2752
|
+
<rulecms-render-inner
|
|
2753
|
+
[displayItemList]="displayItemList"
|
|
2754
|
+
[isComposeMode]="isComposeMode"
|
|
2755
|
+
[isWithinCollection]="isWithinCollection"
|
|
2756
|
+
[widgetCollections]="widgetCollections"
|
|
2757
|
+
[showDropContainers]="showDropContainers"
|
|
2758
|
+
[reduxDeviceDisplayType]="reduxDeviceDisplayType"
|
|
2759
|
+
[plugins]="plugins"
|
|
2760
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2761
|
+
[componentProps]="componentProps"
|
|
2762
|
+
[ancestorColumnIds]="ancestorColumnIds"
|
|
2763
|
+
/>
|
|
2764
|
+
}
|
|
2765
|
+
`, isInline: true, dependencies: [{ kind: "component", type: RenderComponentsInnerComponent, selector: "rulecms-render-inner", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "deviceDisplayType", "componentProps", "ancestorColumnIds"] }] }); }
|
|
2766
|
+
}
|
|
2767
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RenderComponentsForDeviceComponent, decorators: [{
|
|
2768
|
+
type: Component,
|
|
2769
|
+
args: [{
|
|
2770
|
+
selector: 'rulecms-render-for-device',
|
|
2771
|
+
standalone: true,
|
|
2772
|
+
imports: [RenderComponentsInnerComponent],
|
|
2773
|
+
template: `
|
|
2774
|
+
@if (displayItemList?.rows?.length) {
|
|
2775
|
+
<rulecms-render-inner
|
|
2776
|
+
[displayItemList]="displayItemList"
|
|
2777
|
+
[isComposeMode]="isComposeMode"
|
|
2778
|
+
[isWithinCollection]="isWithinCollection"
|
|
2779
|
+
[widgetCollections]="widgetCollections"
|
|
2780
|
+
[showDropContainers]="showDropContainers"
|
|
2781
|
+
[reduxDeviceDisplayType]="reduxDeviceDisplayType"
|
|
2782
|
+
[plugins]="plugins"
|
|
2783
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2784
|
+
[componentProps]="componentProps"
|
|
2785
|
+
[ancestorColumnIds]="ancestorColumnIds"
|
|
2786
|
+
/>
|
|
2787
|
+
}
|
|
2788
|
+
`,
|
|
2789
|
+
host: { style: 'display: contents' },
|
|
2790
|
+
}]
|
|
2791
|
+
}], propDecorators: { displayItemList: [{
|
|
2792
|
+
type: Input,
|
|
2793
|
+
args: [{ required: true }]
|
|
2794
|
+
}], isComposeMode: [{
|
|
2795
|
+
type: Input
|
|
2796
|
+
}], isWithinCollection: [{
|
|
2797
|
+
type: Input
|
|
2798
|
+
}], widgetCollections: [{
|
|
2799
|
+
type: Input,
|
|
2800
|
+
args: [{ required: true }]
|
|
2801
|
+
}], showDropContainers: [{
|
|
2802
|
+
type: Input
|
|
2803
|
+
}], reduxDeviceDisplayType: [{
|
|
2804
|
+
type: Input
|
|
2805
|
+
}], deviceDisplayType: [{
|
|
2806
|
+
type: Input,
|
|
2807
|
+
args: [{ required: true }]
|
|
2808
|
+
}], plugins: [{
|
|
2809
|
+
type: Input,
|
|
2810
|
+
args: [{ required: true }]
|
|
2811
|
+
}], componentProps: [{
|
|
2812
|
+
type: Input
|
|
2813
|
+
}], ancestorColumnIds: [{
|
|
2814
|
+
type: Input
|
|
2815
|
+
}] } });
|
|
2816
|
+
|
|
2817
|
+
const DEVICE_VARIANTS = ['Phone', 'Tablet', 'Desktop'];
|
|
2818
|
+
let breakpointSeq = 0;
|
|
2819
|
+
class BreakpointVariantRenderComponent {
|
|
2820
|
+
constructor() {
|
|
2821
|
+
this.devices = DEVICE_VARIANTS;
|
|
2822
|
+
this.divergent = false;
|
|
2823
|
+
this.variantStyles = '';
|
|
2824
|
+
this.resolvedScopeId = `rulecms-bp-${++breakpointSeq}`;
|
|
2825
|
+
}
|
|
2826
|
+
ngOnChanges() {
|
|
2827
|
+
this.resolvedScopeId = this.scopeIdInput ?? this.resolvedScopeId;
|
|
2828
|
+
this.divergent = hasDeviceDivergentValues(this.displayItemList, this.widgetCollections);
|
|
2829
|
+
this.variantStyles = buildBreakpointVariantStyles(this.resolvedScopeId);
|
|
2830
|
+
}
|
|
2831
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: BreakpointVariantRenderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2832
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: BreakpointVariantRenderComponent, isStandalone: true, selector: "rulecms-breakpoint-variants", inputs: { displayItemList: "displayItemList", widgetCollections: "widgetCollections", plugins: "plugins", componentProps: "componentProps", scopeIdInput: "scopeIdInput" }, host: { styleAttribute: "display: contents" }, usesOnChanges: true, ngImport: i0, template: `
|
|
2833
|
+
@if (!divergent) {
|
|
2834
|
+
<rulecms-render-for-device
|
|
2835
|
+
[displayItemList]="displayItemList"
|
|
2836
|
+
[isComposeMode]="false"
|
|
2837
|
+
[isWithinCollection]="false"
|
|
2838
|
+
[widgetCollections]="widgetCollections"
|
|
2839
|
+
[showDropContainers]="false"
|
|
2840
|
+
reduxDeviceDisplayType="desktop"
|
|
2841
|
+
deviceDisplayType="Desktop"
|
|
2842
|
+
[plugins]="plugins"
|
|
2843
|
+
[componentProps]="componentProps"
|
|
2844
|
+
/>
|
|
2845
|
+
} @else {
|
|
2846
|
+
<style [innerText]="variantStyles"></style>
|
|
2847
|
+
@for (device of devices; track device) {
|
|
2848
|
+
<div [class]="resolvedScopeId + '-' + device.toLowerCase()">
|
|
2849
|
+
<rulecms-render-for-device
|
|
2850
|
+
[displayItemList]="displayItemList"
|
|
2851
|
+
[isComposeMode]="false"
|
|
2852
|
+
[isWithinCollection]="false"
|
|
2853
|
+
[widgetCollections]="widgetCollections"
|
|
2854
|
+
[showDropContainers]="false"
|
|
2855
|
+
reduxDeviceDisplayType="desktop"
|
|
2856
|
+
[deviceDisplayType]="device"
|
|
2857
|
+
[plugins]="plugins"
|
|
2858
|
+
[componentProps]="componentProps"
|
|
2859
|
+
/>
|
|
2860
|
+
</div>
|
|
2861
|
+
}
|
|
2862
|
+
}
|
|
2863
|
+
`, isInline: true, dependencies: [{ kind: "component", type: RenderComponentsForDeviceComponent, selector: "rulecms-render-for-device", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "deviceDisplayType", "plugins", "componentProps", "ancestorColumnIds"] }] }); }
|
|
2864
|
+
}
|
|
2865
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: BreakpointVariantRenderComponent, decorators: [{
|
|
2866
|
+
type: Component,
|
|
2867
|
+
args: [{
|
|
2868
|
+
selector: 'rulecms-breakpoint-variants',
|
|
2869
|
+
standalone: true,
|
|
2870
|
+
imports: [RenderComponentsForDeviceComponent],
|
|
2871
|
+
template: `
|
|
2872
|
+
@if (!divergent) {
|
|
2873
|
+
<rulecms-render-for-device
|
|
2874
|
+
[displayItemList]="displayItemList"
|
|
2875
|
+
[isComposeMode]="false"
|
|
2876
|
+
[isWithinCollection]="false"
|
|
2877
|
+
[widgetCollections]="widgetCollections"
|
|
2878
|
+
[showDropContainers]="false"
|
|
2879
|
+
reduxDeviceDisplayType="desktop"
|
|
2880
|
+
deviceDisplayType="Desktop"
|
|
2881
|
+
[plugins]="plugins"
|
|
2882
|
+
[componentProps]="componentProps"
|
|
2883
|
+
/>
|
|
2884
|
+
} @else {
|
|
2885
|
+
<style [innerText]="variantStyles"></style>
|
|
2886
|
+
@for (device of devices; track device) {
|
|
2887
|
+
<div [class]="resolvedScopeId + '-' + device.toLowerCase()">
|
|
2888
|
+
<rulecms-render-for-device
|
|
2889
|
+
[displayItemList]="displayItemList"
|
|
2890
|
+
[isComposeMode]="false"
|
|
2891
|
+
[isWithinCollection]="false"
|
|
2892
|
+
[widgetCollections]="widgetCollections"
|
|
2893
|
+
[showDropContainers]="false"
|
|
2894
|
+
reduxDeviceDisplayType="desktop"
|
|
2895
|
+
[deviceDisplayType]="device"
|
|
2896
|
+
[plugins]="plugins"
|
|
2897
|
+
[componentProps]="componentProps"
|
|
2898
|
+
/>
|
|
2899
|
+
</div>
|
|
2900
|
+
}
|
|
2901
|
+
}
|
|
2902
|
+
`,
|
|
2903
|
+
host: { style: 'display: contents' },
|
|
2904
|
+
}]
|
|
2905
|
+
}], propDecorators: { displayItemList: [{
|
|
2906
|
+
type: Input,
|
|
2907
|
+
args: [{ required: true }]
|
|
2908
|
+
}], widgetCollections: [{
|
|
2909
|
+
type: Input,
|
|
2910
|
+
args: [{ required: true }]
|
|
2911
|
+
}], plugins: [{
|
|
2912
|
+
type: Input,
|
|
2913
|
+
args: [{ required: true }]
|
|
2914
|
+
}], componentProps: [{
|
|
2915
|
+
type: Input
|
|
2916
|
+
}], scopeIdInput: [{
|
|
2917
|
+
type: Input
|
|
2918
|
+
}] } });
|
|
2919
|
+
|
|
2920
|
+
function resolveDisplayDeviceType(isPhone, isTablet, reduxDeviceDisplayType) {
|
|
2921
|
+
if (isPhone) {
|
|
2922
|
+
return 'Phone';
|
|
2923
|
+
}
|
|
2924
|
+
if (isTablet) {
|
|
2925
|
+
return 'Tablet';
|
|
2926
|
+
}
|
|
2927
|
+
const deviceType = reduxDeviceDisplayType?.toLowerCase() || 'desktop';
|
|
2928
|
+
if (deviceType === 'phone') {
|
|
2929
|
+
return 'Phone';
|
|
2930
|
+
}
|
|
2931
|
+
if (deviceType === 'tablet') {
|
|
2932
|
+
return 'Tablet';
|
|
2933
|
+
}
|
|
2934
|
+
return 'Desktop';
|
|
2935
|
+
}
|
|
2936
|
+
const PHONE_MEDIA_QUERY = `(max-width: ${phoneModeWidth})`;
|
|
2937
|
+
const TABLET_MEDIA_QUERY = `(max-width: ${tabletModeWidth})`;
|
|
2938
|
+
|
|
2939
|
+
class RenderComponentsComponent {
|
|
2940
|
+
constructor() {
|
|
2941
|
+
this.isComposeMode = false;
|
|
2942
|
+
this.isWithinCollection = false;
|
|
2943
|
+
this.showDropContainers = false;
|
|
2944
|
+
this.deviceDisplayType = 'Desktop';
|
|
2945
|
+
this.onChange = () => this.updateDeviceType();
|
|
2946
|
+
}
|
|
2947
|
+
ngOnInit() {
|
|
2948
|
+
if (typeof matchMedia === 'function') {
|
|
2949
|
+
this.phoneQuery = matchMedia(PHONE_MEDIA_QUERY);
|
|
2950
|
+
this.tabletQuery = matchMedia(TABLET_MEDIA_QUERY);
|
|
2951
|
+
this.phoneQuery.addEventListener('change', this.onChange);
|
|
2952
|
+
this.tabletQuery.addEventListener('change', this.onChange);
|
|
2953
|
+
}
|
|
2954
|
+
this.updateDeviceType();
|
|
2955
|
+
}
|
|
2956
|
+
ngOnDestroy() {
|
|
2957
|
+
this.phoneQuery?.removeEventListener('change', this.onChange);
|
|
2958
|
+
this.tabletQuery?.removeEventListener('change', this.onChange);
|
|
2959
|
+
}
|
|
2960
|
+
updateDeviceType() {
|
|
2961
|
+
this.deviceDisplayType = resolveDisplayDeviceType(this.phoneQuery?.matches ?? false, this.tabletQuery?.matches ?? false, this.reduxDeviceDisplayType);
|
|
2962
|
+
}
|
|
2963
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RenderComponentsComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
2964
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: RenderComponentsComponent, isStandalone: true, selector: "rulecms-render-components", inputs: { displayItemList: "displayItemList", isComposeMode: "isComposeMode", isWithinCollection: "isWithinCollection", widgetCollections: "widgetCollections", showDropContainers: "showDropContainers", reduxDeviceDisplayType: "reduxDeviceDisplayType", plugins: "plugins", componentProps: "componentProps" }, host: { styleAttribute: "display: contents" }, ngImport: i0, template: `
|
|
2965
|
+
<rulecms-render-for-device
|
|
2966
|
+
[displayItemList]="displayItemList"
|
|
2967
|
+
[isComposeMode]="isComposeMode"
|
|
2968
|
+
[isWithinCollection]="isWithinCollection"
|
|
2969
|
+
[widgetCollections]="widgetCollections"
|
|
2970
|
+
[showDropContainers]="showDropContainers"
|
|
2971
|
+
[reduxDeviceDisplayType]="reduxDeviceDisplayType"
|
|
2972
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2973
|
+
[plugins]="plugins"
|
|
2974
|
+
[componentProps]="componentProps"
|
|
2975
|
+
/>
|
|
2976
|
+
`, isInline: true, dependencies: [{ kind: "component", type: RenderComponentsForDeviceComponent, selector: "rulecms-render-for-device", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "deviceDisplayType", "plugins", "componentProps", "ancestorColumnIds"] }] }); }
|
|
2977
|
+
}
|
|
2978
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RenderComponentsComponent, decorators: [{
|
|
2979
|
+
type: Component,
|
|
2980
|
+
args: [{
|
|
2981
|
+
selector: 'rulecms-render-components',
|
|
2982
|
+
standalone: true,
|
|
2983
|
+
imports: [RenderComponentsForDeviceComponent],
|
|
2984
|
+
template: `
|
|
2985
|
+
<rulecms-render-for-device
|
|
2986
|
+
[displayItemList]="displayItemList"
|
|
2987
|
+
[isComposeMode]="isComposeMode"
|
|
2988
|
+
[isWithinCollection]="isWithinCollection"
|
|
2989
|
+
[widgetCollections]="widgetCollections"
|
|
2990
|
+
[showDropContainers]="showDropContainers"
|
|
2991
|
+
[reduxDeviceDisplayType]="reduxDeviceDisplayType"
|
|
2992
|
+
[deviceDisplayType]="deviceDisplayType"
|
|
2993
|
+
[plugins]="plugins"
|
|
2994
|
+
[componentProps]="componentProps"
|
|
2995
|
+
/>
|
|
2996
|
+
`,
|
|
2997
|
+
host: { style: 'display: contents' },
|
|
2998
|
+
}]
|
|
2999
|
+
}], propDecorators: { displayItemList: [{
|
|
3000
|
+
type: Input,
|
|
3001
|
+
args: [{ required: true }]
|
|
3002
|
+
}], isComposeMode: [{
|
|
3003
|
+
type: Input
|
|
3004
|
+
}], isWithinCollection: [{
|
|
3005
|
+
type: Input
|
|
3006
|
+
}], widgetCollections: [{
|
|
3007
|
+
type: Input,
|
|
3008
|
+
args: [{ required: true }]
|
|
3009
|
+
}], showDropContainers: [{
|
|
3010
|
+
type: Input
|
|
3011
|
+
}], reduxDeviceDisplayType: [{
|
|
3012
|
+
type: Input
|
|
3013
|
+
}], plugins: [{
|
|
3014
|
+
type: Input,
|
|
3015
|
+
args: [{ required: true }]
|
|
3016
|
+
}], componentProps: [{
|
|
3017
|
+
type: Input
|
|
3018
|
+
}] } });
|
|
3019
|
+
|
|
3020
|
+
function transformChildCollections(childCollections) {
|
|
3021
|
+
const transformed = {};
|
|
3022
|
+
Object.entries(childCollections).forEach(([key, collection]) => {
|
|
3023
|
+
const collectionToUse = { ...collection };
|
|
3024
|
+
if (collectionToUse.itemList) {
|
|
3025
|
+
try {
|
|
3026
|
+
collectionToUse.collectionRows =
|
|
3027
|
+
typeof collectionToUse.itemList === 'string'
|
|
3028
|
+
? JSON.parse(collectionToUse.itemList)
|
|
3029
|
+
: collectionToUse.itemList;
|
|
3030
|
+
}
|
|
3031
|
+
catch (error) {
|
|
3032
|
+
console.error(`Failed to parse itemList for collection ${key}:`, error);
|
|
3033
|
+
collectionToUse.collectionRows = { rows: [] };
|
|
3034
|
+
}
|
|
3035
|
+
}
|
|
3036
|
+
let collectionKey = `${collectionToUse.name}$${key}`;
|
|
3037
|
+
if (collectionToUse.parentId) {
|
|
3038
|
+
collectionKey = `${collectionKey}@${collectionToUse.parentId}`;
|
|
3039
|
+
}
|
|
3040
|
+
transformed[collectionKey] = collectionToUse;
|
|
3041
|
+
});
|
|
3042
|
+
return transformed;
|
|
3043
|
+
}
|
|
3044
|
+
function parseDisplayItemList(widget) {
|
|
3045
|
+
return typeof widget.itemList === 'string'
|
|
3046
|
+
? JSON.parse(widget.itemList)
|
|
3047
|
+
: widget.itemList;
|
|
3048
|
+
}
|
|
3049
|
+
/** Transform raw widget API data into render-ready displayItemList + collections. */
|
|
3050
|
+
function prepareRuleCMSWidgetData(raw) {
|
|
3051
|
+
return {
|
|
3052
|
+
displayItemList: parseDisplayItemList(raw.widget),
|
|
3053
|
+
widgetCollections: transformChildCollections(raw.childCollections),
|
|
3054
|
+
...(raw.libraries ? { libraries: raw.libraries } : {}),
|
|
3055
|
+
};
|
|
3056
|
+
}
|
|
3057
|
+
|
|
3058
|
+
function resolveSourceComponentsPluginSync(params) {
|
|
3059
|
+
const registry = params.registry ?? createComponentLibraryRegistry();
|
|
3060
|
+
const referenced = collectReferencedLibraryIds({
|
|
3061
|
+
displayItemList: params.displayItemList,
|
|
3062
|
+
widgetCollections: params.widgetCollections,
|
|
3063
|
+
});
|
|
3064
|
+
return registry.resolveSync({ registrations: params.libraries, referenced });
|
|
3065
|
+
}
|
|
3066
|
+
function resolveSourceComponentsPlugin(params) {
|
|
3067
|
+
const registry = params.registry ?? createComponentLibraryRegistry();
|
|
3068
|
+
const referenced = collectReferencedLibraryIds({
|
|
3069
|
+
displayItemList: params.displayItemList,
|
|
3070
|
+
widgetCollections: params.widgetCollections,
|
|
3071
|
+
});
|
|
3072
|
+
return registry.resolve({ registrations: params.libraries, referenced });
|
|
3073
|
+
}
|
|
3074
|
+
|
|
3075
|
+
const loadingContainerStyle = {
|
|
3076
|
+
display: 'flex',
|
|
3077
|
+
justifyContent: 'center',
|
|
3078
|
+
alignItems: 'center',
|
|
3079
|
+
padding: '3rem',
|
|
3080
|
+
color: '#e2e8f0',
|
|
3081
|
+
};
|
|
3082
|
+
const spinnerContainerStyle = {
|
|
3083
|
+
display: 'flex',
|
|
3084
|
+
alignItems: 'center',
|
|
3085
|
+
gap: '1rem',
|
|
3086
|
+
};
|
|
3087
|
+
const spinnerStyle = {
|
|
3088
|
+
width: '40px',
|
|
3089
|
+
height: '40px',
|
|
3090
|
+
border: '4px solid #4a5568',
|
|
3091
|
+
borderTopColor: '#63b3ed',
|
|
3092
|
+
borderRadius: '50%',
|
|
3093
|
+
animation: 'spin 1s linear infinite',
|
|
3094
|
+
};
|
|
3095
|
+
const errorContainerStyle = {
|
|
3096
|
+
padding: '1.5rem',
|
|
3097
|
+
backgroundColor: '#742a2a',
|
|
3098
|
+
border: '1px solid #9b2c2c',
|
|
3099
|
+
borderRadius: '8px',
|
|
3100
|
+
color: '#fed7d7',
|
|
3101
|
+
};
|
|
3102
|
+
const errorTitleStyle = {
|
|
3103
|
+
fontSize: '16px',
|
|
3104
|
+
fontWeight: '600',
|
|
3105
|
+
marginBottom: '0.5rem',
|
|
3106
|
+
color: '#feb2b2',
|
|
3107
|
+
};
|
|
3108
|
+
const errorMessageStyle = {
|
|
3109
|
+
fontSize: '14px',
|
|
3110
|
+
color: '#fed7d7',
|
|
3111
|
+
};
|
|
3112
|
+
const globalStyles = `
|
|
3113
|
+
@keyframes spin {
|
|
3114
|
+
from {
|
|
3115
|
+
transform: rotate(0deg);
|
|
3116
|
+
}
|
|
3117
|
+
to {
|
|
3118
|
+
transform: rotate(360deg);
|
|
3119
|
+
}
|
|
3120
|
+
}
|
|
3121
|
+
`;
|
|
3122
|
+
const RULECMS_PUBLISHED_KEY_ATTRIBUTE = 'data-rulecms-published-key';
|
|
3123
|
+
|
|
3124
|
+
class RuleCMSWidgetComponent {
|
|
3125
|
+
constructor(context, errorHandler) {
|
|
3126
|
+
this.context = context;
|
|
3127
|
+
this.errorHandler = errorHandler;
|
|
3128
|
+
/**
|
|
3129
|
+
* `'client-fetch'` (default) fetches in the browser.
|
|
3130
|
+
* `'pre-fetched'` renders `initialData` with CSS breakpoint variants.
|
|
3131
|
+
*/
|
|
3132
|
+
this.mode = 'client-fetch';
|
|
3133
|
+
this.publishedKeyAttribute = RULECMS_PUBLISHED_KEY_ATTRIBUTE;
|
|
3134
|
+
this.loadingContainerStyle = loadingContainerStyle;
|
|
3135
|
+
this.spinnerContainerStyle = spinnerContainerStyle;
|
|
3136
|
+
this.spinnerStyle = spinnerStyle;
|
|
3137
|
+
this.errorContainerStyle = errorContainerStyle;
|
|
3138
|
+
this.errorTitleStyle = errorTitleStyle;
|
|
3139
|
+
this.errorMessageStyle = errorMessageStyle;
|
|
3140
|
+
this.loading = false;
|
|
3141
|
+
this.error = null;
|
|
3142
|
+
this.preparedData = null;
|
|
3143
|
+
this.sourceComponentsPlugin = null;
|
|
3144
|
+
this.useBreakpointVariants = false;
|
|
3145
|
+
this.abortController = null;
|
|
3146
|
+
this.lastFetchKey = null;
|
|
3147
|
+
this.stylesInjected = false;
|
|
3148
|
+
}
|
|
3149
|
+
get plugins() {
|
|
3150
|
+
return { sourceComponents: this.sourceComponentsPlugin ?? undefined };
|
|
3151
|
+
}
|
|
3152
|
+
ngOnInit() {
|
|
3153
|
+
this.syncFromInputs();
|
|
3154
|
+
}
|
|
3155
|
+
ngOnChanges(_changes) {
|
|
3156
|
+
this.syncFromInputs();
|
|
3157
|
+
}
|
|
3158
|
+
ngOnDestroy() {
|
|
3159
|
+
this.abortController?.abort();
|
|
3160
|
+
}
|
|
3161
|
+
syncFromInputs() {
|
|
3162
|
+
this.useBreakpointVariants = this.mode === 'pre-fetched';
|
|
3163
|
+
if (this.mode === 'pre-fetched') {
|
|
3164
|
+
this.preparedData = this.initialData ?? null;
|
|
3165
|
+
this.loading = false;
|
|
3166
|
+
this.error = null;
|
|
3167
|
+
this.resolveLibraries();
|
|
3168
|
+
this.warnUnmatched();
|
|
3169
|
+
return;
|
|
3170
|
+
}
|
|
3171
|
+
this.ensureSpinnerStyles();
|
|
3172
|
+
this.fetchClient();
|
|
3173
|
+
}
|
|
3174
|
+
resolveLibraries() {
|
|
3175
|
+
if (!this.preparedData) {
|
|
3176
|
+
this.sourceComponentsPlugin = null;
|
|
3177
|
+
return;
|
|
3178
|
+
}
|
|
3179
|
+
const libraries = this.libraries ?? this.context?.libraries;
|
|
3180
|
+
const registry = this.context?.libraryRegistry;
|
|
3181
|
+
try {
|
|
3182
|
+
const sync = resolveSourceComponentsPluginSync({
|
|
3183
|
+
displayItemList: this.preparedData.displayItemList,
|
|
3184
|
+
widgetCollections: this.preparedData.widgetCollections,
|
|
3185
|
+
libraries,
|
|
3186
|
+
registry,
|
|
3187
|
+
});
|
|
3188
|
+
if (sync) {
|
|
3189
|
+
this.sourceComponentsPlugin = sync;
|
|
3190
|
+
return;
|
|
3191
|
+
}
|
|
3192
|
+
void resolveSourceComponentsPlugin({
|
|
3193
|
+
displayItemList: this.preparedData.displayItemList,
|
|
3194
|
+
widgetCollections: this.preparedData.widgetCollections,
|
|
3195
|
+
libraries,
|
|
3196
|
+
registry,
|
|
3197
|
+
}).then((plugin) => {
|
|
3198
|
+
this.sourceComponentsPlugin = plugin;
|
|
3199
|
+
});
|
|
3200
|
+
}
|
|
3201
|
+
catch (error) {
|
|
3202
|
+
this.errorHandler?.handleError(error);
|
|
3203
|
+
throw error;
|
|
3204
|
+
}
|
|
3205
|
+
}
|
|
3206
|
+
warnUnmatched() {
|
|
3207
|
+
if (!this.preparedData) {
|
|
3208
|
+
return;
|
|
3209
|
+
}
|
|
3210
|
+
warnUnmatchedComponentProps({
|
|
3211
|
+
componentProps: this.componentProps,
|
|
3212
|
+
displayItemList: this.preparedData.displayItemList,
|
|
3213
|
+
widgetCollections: this.preparedData.widgetCollections,
|
|
3214
|
+
publishedKey: this.publishedKey,
|
|
3215
|
+
});
|
|
3216
|
+
}
|
|
3217
|
+
fetchClient() {
|
|
3218
|
+
const token = this.token ?? this.context?.token;
|
|
3219
|
+
const endpoint = this.endpoint ?? this.context?.endpoint;
|
|
3220
|
+
if (!this.publishedKey || !token) {
|
|
3221
|
+
this.error = !this.publishedKey
|
|
3222
|
+
? isDevClientToken(token)
|
|
3223
|
+
? 'Widget key is required'
|
|
3224
|
+
: 'Published key is required'
|
|
3225
|
+
: 'Token is required. Provide it either directly as an input ([token]) or via rulecms-widget-provider.';
|
|
3226
|
+
this.preparedData = null;
|
|
3227
|
+
return;
|
|
3228
|
+
}
|
|
3229
|
+
const fetchKey = `${this.publishedKey}|${token}`;
|
|
3230
|
+
if (this.lastFetchKey === fetchKey && this.preparedData) {
|
|
3231
|
+
this.resolveLibraries();
|
|
3232
|
+
return;
|
|
3233
|
+
}
|
|
3234
|
+
this.abortController?.abort();
|
|
3235
|
+
this.abortController = new AbortController();
|
|
3236
|
+
const signal = this.abortController.signal;
|
|
3237
|
+
this.lastFetchKey = fetchKey;
|
|
3238
|
+
this.loading = true;
|
|
3239
|
+
this.error = null;
|
|
3240
|
+
const url = buildWidgetFetchUrl({ publishedKey: this.publishedKey, token, endpoint });
|
|
3241
|
+
fetch(url, {
|
|
3242
|
+
method: 'GET',
|
|
3243
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3244
|
+
...(isDevClientToken(token) ? { cache: 'no-store' } : {}),
|
|
3245
|
+
signal,
|
|
3246
|
+
})
|
|
3247
|
+
.then(async (response) => {
|
|
3248
|
+
if (response.ok) {
|
|
3249
|
+
const data = await response.json();
|
|
3250
|
+
if (data.success) {
|
|
3251
|
+
this.preparedData = prepareRuleCMSWidgetData(data.data);
|
|
3252
|
+
this.error = null;
|
|
3253
|
+
this.resolveLibraries();
|
|
3254
|
+
this.warnUnmatched();
|
|
3255
|
+
}
|
|
3256
|
+
else {
|
|
3257
|
+
this.error = 'Failed to fetch widget data';
|
|
3258
|
+
this.preparedData = null;
|
|
3259
|
+
}
|
|
3260
|
+
}
|
|
3261
|
+
else {
|
|
3262
|
+
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
3263
|
+
this.error = errorData.error || `Request failed with status ${response.status}`;
|
|
3264
|
+
this.preparedData = null;
|
|
3265
|
+
}
|
|
3266
|
+
})
|
|
3267
|
+
.catch((err) => {
|
|
3268
|
+
if (err instanceof DOMException && err.name === 'AbortError') {
|
|
3269
|
+
return;
|
|
3270
|
+
}
|
|
3271
|
+
console.error('Error fetching widget:', err);
|
|
3272
|
+
this.error = 'Failed to fetch widget';
|
|
3273
|
+
this.preparedData = null;
|
|
3274
|
+
})
|
|
3275
|
+
.finally(() => {
|
|
3276
|
+
this.loading = false;
|
|
3277
|
+
});
|
|
3278
|
+
}
|
|
3279
|
+
ensureSpinnerStyles() {
|
|
3280
|
+
if (this.stylesInjected || typeof document === 'undefined') {
|
|
3281
|
+
return;
|
|
3282
|
+
}
|
|
3283
|
+
const styleId = 'rulecms-widget-spinner-styles';
|
|
3284
|
+
if (!document.getElementById(styleId)) {
|
|
3285
|
+
const style = document.createElement('style');
|
|
3286
|
+
style.id = styleId;
|
|
3287
|
+
style.textContent = globalStyles;
|
|
3288
|
+
document.head.appendChild(style);
|
|
3289
|
+
}
|
|
3290
|
+
this.stylesInjected = true;
|
|
3291
|
+
}
|
|
3292
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, deps: [{ token: RuleCMSWidgetContextService, optional: true }, { token: ErrorHandler, optional: true }], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3293
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: RuleCMSWidgetComponent, isStandalone: true, selector: "rulecms-widget", inputs: { publishedKey: "publishedKey", token: "token", endpoint: "endpoint", mode: "mode", initialData: "initialData", libraries: "libraries", componentProps: "componentProps" }, host: { styleAttribute: "display: contents" }, usesOnChanges: true, ngImport: i0, template: `
|
|
3294
|
+
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
3295
|
+
@if (mode !== 'pre-fetched' && loading) {
|
|
3296
|
+
<div [ngStyle]="loadingContainerStyle">
|
|
3297
|
+
<div [ngStyle]="spinnerContainerStyle">
|
|
3298
|
+
<div [ngStyle]="spinnerStyle"></div>
|
|
3299
|
+
</div>
|
|
3300
|
+
</div>
|
|
3301
|
+
} @else if (mode !== 'pre-fetched' && error) {
|
|
3302
|
+
<div [ngStyle]="errorContainerStyle">
|
|
3303
|
+
<div [ngStyle]="errorTitleStyle">Error Loading Widget</div>
|
|
3304
|
+
<div [ngStyle]="errorMessageStyle">{{ error }}</div>
|
|
3305
|
+
</div>
|
|
3306
|
+
} @else if (mode !== 'pre-fetched' && !preparedData) {
|
|
3307
|
+
<div [ngStyle]="errorContainerStyle">
|
|
3308
|
+
<div [ngStyle]="errorTitleStyle">No Widget Data</div>
|
|
3309
|
+
<div [ngStyle]="errorMessageStyle">No widget data available</div>
|
|
3310
|
+
</div>
|
|
3311
|
+
} @else if (sourceComponentsPlugin && preparedData) {
|
|
3312
|
+
@if (useBreakpointVariants) {
|
|
3313
|
+
<rulecms-breakpoint-variants
|
|
3314
|
+
[displayItemList]="preparedData.displayItemList"
|
|
3315
|
+
[widgetCollections]="preparedData.widgetCollections"
|
|
3316
|
+
[plugins]="plugins"
|
|
3317
|
+
[componentProps]="componentProps"
|
|
3318
|
+
/>
|
|
3319
|
+
} @else {
|
|
3320
|
+
<rulecms-render-components
|
|
3321
|
+
[displayItemList]="preparedData.displayItemList"
|
|
3322
|
+
[isComposeMode]="false"
|
|
3323
|
+
[isWithinCollection]="false"
|
|
3324
|
+
[widgetCollections]="preparedData.widgetCollections"
|
|
3325
|
+
[showDropContainers]="false"
|
|
3326
|
+
reduxDeviceDisplayType="desktop"
|
|
3327
|
+
[plugins]="plugins"
|
|
3328
|
+
[componentProps]="componentProps"
|
|
3329
|
+
/>
|
|
3330
|
+
}
|
|
3331
|
+
}
|
|
3332
|
+
</span>
|
|
3333
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: BreakpointVariantRenderComponent, selector: "rulecms-breakpoint-variants", inputs: ["displayItemList", "widgetCollections", "plugins", "componentProps", "scopeIdInput"] }, { kind: "component", type: RenderComponentsComponent, selector: "rulecms-render-components", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "componentProps"] }] }); }
|
|
3334
|
+
}
|
|
3335
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, decorators: [{
|
|
3336
|
+
type: Component,
|
|
3337
|
+
args: [{
|
|
3338
|
+
selector: 'rulecms-widget',
|
|
3339
|
+
standalone: true,
|
|
3340
|
+
imports: [NgStyle, BreakpointVariantRenderComponent, RenderComponentsComponent],
|
|
3341
|
+
template: `
|
|
3342
|
+
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
3343
|
+
@if (mode !== 'pre-fetched' && loading) {
|
|
3344
|
+
<div [ngStyle]="loadingContainerStyle">
|
|
3345
|
+
<div [ngStyle]="spinnerContainerStyle">
|
|
3346
|
+
<div [ngStyle]="spinnerStyle"></div>
|
|
3347
|
+
</div>
|
|
3348
|
+
</div>
|
|
3349
|
+
} @else if (mode !== 'pre-fetched' && error) {
|
|
3350
|
+
<div [ngStyle]="errorContainerStyle">
|
|
3351
|
+
<div [ngStyle]="errorTitleStyle">Error Loading Widget</div>
|
|
3352
|
+
<div [ngStyle]="errorMessageStyle">{{ error }}</div>
|
|
3353
|
+
</div>
|
|
3354
|
+
} @else if (mode !== 'pre-fetched' && !preparedData) {
|
|
3355
|
+
<div [ngStyle]="errorContainerStyle">
|
|
3356
|
+
<div [ngStyle]="errorTitleStyle">No Widget Data</div>
|
|
3357
|
+
<div [ngStyle]="errorMessageStyle">No widget data available</div>
|
|
3358
|
+
</div>
|
|
3359
|
+
} @else if (sourceComponentsPlugin && preparedData) {
|
|
3360
|
+
@if (useBreakpointVariants) {
|
|
3361
|
+
<rulecms-breakpoint-variants
|
|
3362
|
+
[displayItemList]="preparedData.displayItemList"
|
|
3363
|
+
[widgetCollections]="preparedData.widgetCollections"
|
|
3364
|
+
[plugins]="plugins"
|
|
3365
|
+
[componentProps]="componentProps"
|
|
3366
|
+
/>
|
|
3367
|
+
} @else {
|
|
3368
|
+
<rulecms-render-components
|
|
3369
|
+
[displayItemList]="preparedData.displayItemList"
|
|
3370
|
+
[isComposeMode]="false"
|
|
3371
|
+
[isWithinCollection]="false"
|
|
3372
|
+
[widgetCollections]="preparedData.widgetCollections"
|
|
3373
|
+
[showDropContainers]="false"
|
|
3374
|
+
reduxDeviceDisplayType="desktop"
|
|
3375
|
+
[plugins]="plugins"
|
|
3376
|
+
[componentProps]="componentProps"
|
|
3377
|
+
/>
|
|
3378
|
+
}
|
|
3379
|
+
}
|
|
3380
|
+
</span>
|
|
3381
|
+
`,
|
|
3382
|
+
host: { style: 'display: contents' },
|
|
3383
|
+
}]
|
|
3384
|
+
}], ctorParameters: () => [{ type: RuleCMSWidgetContextService, decorators: [{
|
|
3385
|
+
type: Optional
|
|
3386
|
+
}] }, { type: i0.ErrorHandler, decorators: [{
|
|
3387
|
+
type: Optional
|
|
3388
|
+
}, {
|
|
3389
|
+
type: Inject,
|
|
3390
|
+
args: [ErrorHandler]
|
|
3391
|
+
}] }], propDecorators: { publishedKey: [{
|
|
3392
|
+
type: Input,
|
|
3393
|
+
args: [{ required: true }]
|
|
3394
|
+
}], token: [{
|
|
3395
|
+
type: Input
|
|
3396
|
+
}], endpoint: [{
|
|
3397
|
+
type: Input
|
|
3398
|
+
}], mode: [{
|
|
3399
|
+
type: Input
|
|
3400
|
+
}], initialData: [{
|
|
3401
|
+
type: Input
|
|
3402
|
+
}], libraries: [{
|
|
3403
|
+
type: Input
|
|
3404
|
+
}], componentProps: [{
|
|
3405
|
+
type: Input
|
|
3406
|
+
}] } });
|
|
3407
|
+
|
|
3408
|
+
class FetchRuleCMSWidgetError extends Error {
|
|
3409
|
+
constructor(message, status) {
|
|
3410
|
+
super(message);
|
|
3411
|
+
this.name = 'FetchRuleCMSWidgetError';
|
|
3412
|
+
this.status = status;
|
|
3413
|
+
}
|
|
3414
|
+
}
|
|
3415
|
+
/** Fetch widget JSON on the server (or at build time) and return render-ready data. */
|
|
3416
|
+
async function fetchRuleCMSWidget(params) {
|
|
3417
|
+
const { publishedKey, token, endpoint, fetchOptions } = params;
|
|
3418
|
+
if (!publishedKey) {
|
|
3419
|
+
throw new FetchRuleCMSWidgetError(isDevClientToken(token) ? 'Widget key is required' : 'Published key is required');
|
|
3420
|
+
}
|
|
3421
|
+
if (!token) {
|
|
3422
|
+
throw new FetchRuleCMSWidgetError('Token is required');
|
|
3423
|
+
}
|
|
3424
|
+
const url = buildWidgetFetchUrl({ publishedKey, token, endpoint });
|
|
3425
|
+
const response = await fetch(url, {
|
|
3426
|
+
method: 'GET',
|
|
3427
|
+
headers: { 'Content-Type': 'application/json' },
|
|
3428
|
+
...(isDevClientToken(token) ? { cache: 'no-store' } : {}),
|
|
3429
|
+
...fetchOptions,
|
|
3430
|
+
});
|
|
3431
|
+
if (!response.ok) {
|
|
3432
|
+
const errorData = await response.json().catch(() => ({ error: 'Unknown error' }));
|
|
3433
|
+
throw new FetchRuleCMSWidgetError(errorData.error || `Request failed with status ${response.status}`, response.status);
|
|
3434
|
+
}
|
|
3435
|
+
const data = await response.json();
|
|
3436
|
+
if (!data.success) {
|
|
3437
|
+
throw new FetchRuleCMSWidgetError('Failed to fetch widget data');
|
|
3438
|
+
}
|
|
3439
|
+
return prepareRuleCMSWidgetData(data.data);
|
|
3440
|
+
}
|
|
3441
|
+
|
|
3442
|
+
/**
|
|
3443
|
+
* Server-side resolve helper: loads only the component libraries the given
|
|
3444
|
+
* widget config references and returns the composed plugin.
|
|
3445
|
+
*
|
|
3446
|
+
* The result contains Angular component classes and must not be serialized
|
|
3447
|
+
* across a process boundary. For pre-fetched SSR pages, register eagerly
|
|
3448
|
+
* imported modules via `RuleCMSWidgetProvider` / inputs instead.
|
|
3449
|
+
*/
|
|
3450
|
+
async function resolveWidgetLibraries(params) {
|
|
3451
|
+
const { data, libraries } = params;
|
|
3452
|
+
const referenced = collectReferencedLibraryIds({
|
|
3453
|
+
displayItemList: data.displayItemList,
|
|
3454
|
+
widgetCollections: data.widgetCollections,
|
|
3455
|
+
});
|
|
3456
|
+
const registry = createComponentLibraryRegistry();
|
|
3457
|
+
return registry.resolve({ registrations: libraries, referenced });
|
|
3458
|
+
}
|
|
3459
|
+
|
|
3460
|
+
/**
|
|
3461
|
+
* Generated bundle index. Do not edit.
|
|
3462
|
+
*/
|
|
3463
|
+
|
|
3464
|
+
export { AlignContentTypes, BreakpointVariantRenderComponent, COLLECTION_TYPE_PREFIX, COMPONENT_PROPS_PATH_SEPARATOR, CSS_CLASSES_ATTRIBUTE_NAME, CSS_VARIABLE_NAME_MAX_LENGTH, CSS_VARIABLE_NAME_PATTERN, DEFAULT_CLOUDINARY_CLOUD_NAME, DEFAULT_LIBRARY_ID, DEFAULT_ROW_GAP, DEV_CLIENT_TOKEN_PREFIX, DEV_WIDGET_API_PATH, DeviceDisplayTypes, DisplayComponentComponent, DisplayItemTypes, DragItemIdPrefixTypes, EMBEDDED_KEY_SEPARATOR, FLEX_LAYOUT_STYLE_KEYS_THAT_DERIVE_DISPLAY, FetchRuleCMSWidgetError, HIDE_WIDGET_ATTRIBUTE_NAME, JustifyContentTypes, PUBLISHED_KEY_SEPARATOR, PUBLISHED_WIDGET_API_PATH, PageViewTypes, RULECMS_API_ORIGIN, RULECMS_PUBLISHED_KEY_ATTRIBUTE, RenderComponentsComponent, RenderComponentsForDeviceComponent, RenderComponentsInnerComponent, RuleCMSWidgetComponent, RuleCMSWidgetContextService, RuleCMSWidgetProviderComponent, WIDGET_ATTRIBUTES_IGNORED_IN_COMPOSE_MODE, WIDGET_CACHE_API_ORIGIN, alignContentAllowlist, alignItemsAllowlist, backgroundPositionAllowlist, backgroundRepeatAllowlist, backgroundSizeAllowlist, borderStyleKeywords, boxSpacingSideKeys, boxSpacingStyleAttributeEntries, buildCloudinaryBackgroundUrl, buildWidgetFetchUrl, collectComponentInstancePaths, collectReferencedLibraryIds, composeSourceComponentsPlugin, createComponentLibraryRegistry, cssAttrArrayKey, defaultPageWidth, deriveDisplayFlexIfNeeded, desktopModeWidth, fetchRuleCMSWidget, findUnmatchedComponentPropsKeys, flexDirectionAllowlist, flexWrapAllowlist, fontFamilyAllowlist, fontStyleAllowlist, fontWeightAllowlist, formatBackgroundImageStyles, formatBorderStyles, formatBoxShadowStyles, formatBoxSpacingStyles, formatCssColorStyles, formatCssColorValue, formatCssEnumStyles, formatCssLengthStyles, formatCssVariable, formatCssVariableStyles, formatLineHeightStyles, formatObjectStyleAttribute, formatOpacityStyles, formatSpacingSideValue, generatePublishedKey, generatePublishedKeyForEmbedded, getCollectionIdForCollectionType, getColumnAttributes, getComponentAttributesAndStyles, getComponentsPluginFromPlugins, getCssVariableFromLeaf, getDefaultDimensionAttributes, getDeviceTypeBasedAttributes, getDragItemId, getDragItemPrefixAndId, getIdAndPrefix, getMergedAttributes, getNameAndInstanceIdFromWidgetKey, getNameFromWidgetKey, getWidgetKeyForCollection, getWidgetKeyForCollectionWithPrefix, getWidgetKeyForPublishedCollection, getWidgetKeyForPublishedCollectionWithPrefix, hasBoxShadowLeaf, hasDeviceDivergentValues, hasInvalidCssVariable, hasItems, incrementVersion, isBackgroundImageValue, isBorderStyleValue, isBorderValue, isBoxShadowValue, isBoxSpacingValue, isCloudinaryCloudName, isCloudinaryPublicId, isCloudinaryTransformationString, isCssColorValue, isCssEnumValue, isCssVariableName, isDevClientToken, isLineHeightValue, isOpacityValue, isRowHiddenForDevice, isSafeImageUrl, isSpacingSideValue, isWidgetHiddenForDevice, justifyContentAllowlist, normalizeCssClasses, objectStyleAttributeRegistry, overflowAllowlist, phoneModeWidth, prepareRuleCMSWidgetData, resolveKey, resolveRowStyles, resolveWidgetApiOrigin, resolveWidgetContainerStyles, resolveWidgetInstanceProps, resolveWidgetLibraries, rowBasedPropertiesAreAssigned, spacingKeywords, spacingLengthUnits, tabletModeWidth, textAlignAllowlist, textDecorationAllowlist, textTransformAllowlist, typeHasPrefix, warnUnmatchedComponentProps, widgetBasedPropertiesAreAssigned };
|
|
3465
|
+
//# sourceMappingURL=rulecms-widget-angular.mjs.map
|