@rulecms/widget-angular 0.4.0 → 0.5.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/fesm2022/rulecms-widget-angular.mjs +105 -2
- package/fesm2022/rulecms-widget-angular.mjs.map +1 -1
- package/lib/project-css-variables/format-project-css-variables-stylesheet.d.ts +13 -0
- package/lib/project-css-variables/format-project-css-variables-stylesheet.d.ts.map +1 -0
- package/lib/project-css-variables/include-project-css-variables-on-published-widget.d.ts +9 -0
- package/lib/project-css-variables/include-project-css-variables-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-variables/project-css-variables-stylesheet.component.d.ts +14 -0
- package/lib/project-css-variables/project-css-variables-stylesheet.component.d.ts.map +1 -0
- package/lib/widget/prepare-rule-cms-widget-data.d.ts.map +1 -1
- package/lib/widget/rule-cms-widget.component.d.ts.map +1 -1
- package/lib/widget/widget-data.types.d.ts +12 -0
- package/lib/widget/widget-data.types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3373,6 +3373,93 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
3373
3373
|
type: Input
|
|
3374
3374
|
}] } });
|
|
3375
3375
|
|
|
3376
|
+
/**
|
|
3377
|
+
* When true, a non-empty `cssVariables` object on the widget GET payload is
|
|
3378
|
+
* emitted as one scoped `<style>` on the published widget.
|
|
3379
|
+
*
|
|
3380
|
+
* TODO: project setting — the customer turns this off if the host stylesheet
|
|
3381
|
+
* already defines these tokens. Hardcoded on for this iteration.
|
|
3382
|
+
*/
|
|
3383
|
+
const INCLUDE_PROJECT_CSS_VARIABLES_ON_PUBLISHED_WIDGET = true;
|
|
3384
|
+
|
|
3385
|
+
/**
|
|
3386
|
+
* Attribute-selector escape so a published key cannot break out of
|
|
3387
|
+
* `[data-rulecms-published-key="…"]`. `CSS.escape` is not assumed (SSR / Node).
|
|
3388
|
+
*/
|
|
3389
|
+
const escapeCssAttributeValue = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
3390
|
+
const REJECTED_IN_EMITTED_VALUE = /[{};]/;
|
|
3391
|
+
const sanitizeForStylesheet = (variables) => {
|
|
3392
|
+
if (!variables) {
|
|
3393
|
+
return {};
|
|
3394
|
+
}
|
|
3395
|
+
const sanitized = {};
|
|
3396
|
+
for (const [rawName, rawValue] of Object.entries(variables)) {
|
|
3397
|
+
if (!isCssVariableName(rawName) || typeof rawValue !== 'string') {
|
|
3398
|
+
continue;
|
|
3399
|
+
}
|
|
3400
|
+
const value = rawValue.trim();
|
|
3401
|
+
if (value === '' || REJECTED_IN_EMITTED_VALUE.test(value)) {
|
|
3402
|
+
continue;
|
|
3403
|
+
}
|
|
3404
|
+
sanitized[rawName.trim()] = value;
|
|
3405
|
+
}
|
|
3406
|
+
return sanitized;
|
|
3407
|
+
};
|
|
3408
|
+
/**
|
|
3409
|
+
* One rule: custom properties on the first boxed children of this widget’s
|
|
3410
|
+
* published-key span. Empty / flag-off / unsanitary catalogs return null so
|
|
3411
|
+
* the caller omits the `<style>` tag.
|
|
3412
|
+
*/
|
|
3413
|
+
const formatProjectCssVariablesStylesheet = (publishedKey, variables) => {
|
|
3414
|
+
if (!INCLUDE_PROJECT_CSS_VARIABLES_ON_PUBLISHED_WIDGET) {
|
|
3415
|
+
return null;
|
|
3416
|
+
}
|
|
3417
|
+
const sanitized = sanitizeForStylesheet(variables);
|
|
3418
|
+
const names = Object.keys(sanitized);
|
|
3419
|
+
if (names.length === 0 || !publishedKey) {
|
|
3420
|
+
return null;
|
|
3421
|
+
}
|
|
3422
|
+
const selector = `[data-rulecms-published-key="${escapeCssAttributeValue(publishedKey)}"] > *`;
|
|
3423
|
+
const declarations = names
|
|
3424
|
+
.sort((left, right) => left.localeCompare(right))
|
|
3425
|
+
.map((name) => ` ${name}: ${sanitized[name]};`)
|
|
3426
|
+
.join('\n');
|
|
3427
|
+
return `${selector} {\n${declarations}\n}`;
|
|
3428
|
+
};
|
|
3429
|
+
|
|
3430
|
+
/**
|
|
3431
|
+
* Emits one scoped `<style data-rulecms-project-css-variables>` from the
|
|
3432
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
3433
|
+
*/
|
|
3434
|
+
class ProjectCssVariablesStylesheetComponent {
|
|
3435
|
+
get css() {
|
|
3436
|
+
return formatProjectCssVariablesStylesheet(this.publishedKey, this.variables);
|
|
3437
|
+
}
|
|
3438
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3439
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssVariablesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-variables-stylesheet", inputs: { publishedKey: "publishedKey", variables: "variables" }, ngImport: i0, template: `
|
|
3440
|
+
@if (css) {
|
|
3441
|
+
<style data-rulecms-project-css-variables="" [innerText]="css"></style>
|
|
3442
|
+
}
|
|
3443
|
+
`, isInline: true }); }
|
|
3444
|
+
}
|
|
3445
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, decorators: [{
|
|
3446
|
+
type: Component,
|
|
3447
|
+
args: [{
|
|
3448
|
+
selector: 'rulecms-project-css-variables-stylesheet',
|
|
3449
|
+
standalone: true,
|
|
3450
|
+
template: `
|
|
3451
|
+
@if (css) {
|
|
3452
|
+
<style data-rulecms-project-css-variables="" [innerText]="css"></style>
|
|
3453
|
+
}
|
|
3454
|
+
`,
|
|
3455
|
+
}]
|
|
3456
|
+
}], propDecorators: { publishedKey: [{
|
|
3457
|
+
type: Input,
|
|
3458
|
+
args: [{ required: true }]
|
|
3459
|
+
}], variables: [{
|
|
3460
|
+
type: Input
|
|
3461
|
+
}] } });
|
|
3462
|
+
|
|
3376
3463
|
function transformChildCollections(childCollections) {
|
|
3377
3464
|
const transformed = {};
|
|
3378
3465
|
Object.entries(childCollections).forEach(([key, collection]) => {
|
|
@@ -3408,6 +3495,9 @@ function prepareRuleCMSWidgetData(raw) {
|
|
|
3408
3495
|
displayItemList: parseDisplayItemList(raw.widget),
|
|
3409
3496
|
widgetCollections: transformChildCollections(raw.childCollections),
|
|
3410
3497
|
...(raw.libraries ? { libraries: raw.libraries } : {}),
|
|
3498
|
+
...(raw.cssVariables && Object.keys(raw.cssVariables).length > 0
|
|
3499
|
+
? { cssVariables: raw.cssVariables }
|
|
3500
|
+
: {}),
|
|
3411
3501
|
};
|
|
3412
3502
|
}
|
|
3413
3503
|
|
|
@@ -3648,6 +3738,10 @@ class RuleCMSWidgetComponent {
|
|
|
3648
3738
|
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 }); }
|
|
3649
3739
|
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", mounts: "mounts" }, host: { styleAttribute: "display: contents" }, usesOnChanges: true, ngImport: i0, template: `
|
|
3650
3740
|
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
3741
|
+
<rulecms-project-css-variables-stylesheet
|
|
3742
|
+
[publishedKey]="publishedKey"
|
|
3743
|
+
[variables]="preparedData?.cssVariables"
|
|
3744
|
+
/>
|
|
3651
3745
|
@if (mode !== 'pre-fetched' && loading) {
|
|
3652
3746
|
<div [ngStyle]="loadingContainerStyle">
|
|
3653
3747
|
<div [ngStyle]="spinnerContainerStyle">
|
|
@@ -3688,16 +3782,25 @@ class RuleCMSWidgetComponent {
|
|
|
3688
3782
|
}
|
|
3689
3783
|
}
|
|
3690
3784
|
</span>
|
|
3691
|
-
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: BreakpointVariantRenderComponent, selector: "rulecms-breakpoint-variants", inputs: ["displayItemList", "widgetCollections", "plugins", "componentProps", "mounts", "scopeIdInput"] }, { kind: "component", type: RenderComponentsComponent, selector: "rulecms-render-components", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "componentProps", "mounts"] }] }); }
|
|
3785
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { kind: "component", type: BreakpointVariantRenderComponent, selector: "rulecms-breakpoint-variants", inputs: ["displayItemList", "widgetCollections", "plugins", "componentProps", "mounts", "scopeIdInput"] }, { kind: "component", type: RenderComponentsComponent, selector: "rulecms-render-components", inputs: ["displayItemList", "isComposeMode", "isWithinCollection", "widgetCollections", "showDropContainers", "reduxDeviceDisplayType", "plugins", "componentProps", "mounts"] }, { kind: "component", type: ProjectCssVariablesStylesheetComponent, selector: "rulecms-project-css-variables-stylesheet", inputs: ["publishedKey", "variables"] }] }); }
|
|
3692
3786
|
}
|
|
3693
3787
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, decorators: [{
|
|
3694
3788
|
type: Component,
|
|
3695
3789
|
args: [{
|
|
3696
3790
|
selector: 'rulecms-widget',
|
|
3697
3791
|
standalone: true,
|
|
3698
|
-
imports: [
|
|
3792
|
+
imports: [
|
|
3793
|
+
NgStyle,
|
|
3794
|
+
BreakpointVariantRenderComponent,
|
|
3795
|
+
RenderComponentsComponent,
|
|
3796
|
+
ProjectCssVariablesStylesheetComponent,
|
|
3797
|
+
],
|
|
3699
3798
|
template: `
|
|
3700
3799
|
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
3800
|
+
<rulecms-project-css-variables-stylesheet
|
|
3801
|
+
[publishedKey]="publishedKey"
|
|
3802
|
+
[variables]="preparedData?.cssVariables"
|
|
3803
|
+
/>
|
|
3701
3804
|
@if (mode !== 'pre-fetched' && loading) {
|
|
3702
3805
|
<div [ngStyle]="loadingContainerStyle">
|
|
3703
3806
|
<div [ngStyle]="spinnerContainerStyle">
|