@rulecms/widget-angular 0.4.0 → 0.6.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 +251 -2
- package/fesm2022/rulecms-widget-angular.mjs.map +1 -1
- package/lib/project-css-classes/format-project-css-classes-stylesheet.d.ts +14 -0
- package/lib/project-css-classes/format-project-css-classes-stylesheet.d.ts.map +1 -0
- package/lib/project-css-classes/include-project-css-classes-on-published-widget.d.ts +7 -0
- package/lib/project-css-classes/include-project-css-classes-on-published-widget.d.ts.map +1 -0
- package/lib/project-css-classes/project-css-classes-stylesheet.component.d.ts +14 -0
- package/lib/project-css-classes/project-css-classes-stylesheet.component.d.ts.map +1 -0
- 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 +12 -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 +27 -0
- package/lib/widget/widget-data.types.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -3373,6 +3373,225 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
|
|
|
3373
3373
|
type: Input
|
|
3374
3374
|
}] } });
|
|
3375
3375
|
|
|
3376
|
+
/**
|
|
3377
|
+
* Missing/undefined on a widget GET payload means include — the default, and
|
|
3378
|
+
* the shape older clients already understand. Only an explicit `false` turns
|
|
3379
|
+
* emission off, even if `classDefinitions` is still present on the payload.
|
|
3380
|
+
*/
|
|
3381
|
+
function shouldIncludeClassDefinitionsOnPublishedWidget(includeClassDefinitions) {
|
|
3382
|
+
return includeClassDefinitions !== false;
|
|
3383
|
+
}
|
|
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$1 = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
3390
|
+
/** Escape a class name for use after `.` (`/` → `\/`). */
|
|
3391
|
+
const escapeCssClassName = (name) => name.replace(/[^A-Za-z0-9_-]/g, (char) => `\\${char}`);
|
|
3392
|
+
const REJECTED_IN_BODY = ['</', '<script', '@import', 'javascript:', 'vbscript:', 'expression('];
|
|
3393
|
+
// eslint-disable-next-line no-control-regex -- control characters are what this matches
|
|
3394
|
+
const REJECTED_CONTROL_CHARACTERS = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/;
|
|
3395
|
+
const DISALLOWED_IN_NAME = /[\s{};"]/;
|
|
3396
|
+
const ALLOWED_NAME = /^[A-Za-z0-9_:%./[\]%-]+$/;
|
|
3397
|
+
const isBraceBalanced = (value) => {
|
|
3398
|
+
let depth = 0;
|
|
3399
|
+
for (const char of value) {
|
|
3400
|
+
if (char === '{') {
|
|
3401
|
+
depth += 1;
|
|
3402
|
+
}
|
|
3403
|
+
else if (char === '}') {
|
|
3404
|
+
depth -= 1;
|
|
3405
|
+
if (depth < 0) {
|
|
3406
|
+
return false;
|
|
3407
|
+
}
|
|
3408
|
+
}
|
|
3409
|
+
}
|
|
3410
|
+
return depth === 0;
|
|
3411
|
+
};
|
|
3412
|
+
const isCssClassName = (value) => {
|
|
3413
|
+
const name = value.startsWith('.') ? value.slice(1) : value;
|
|
3414
|
+
if (!name || name.length > 200 || name.startsWith('.') || DISALLOWED_IN_NAME.test(name)) {
|
|
3415
|
+
return false;
|
|
3416
|
+
}
|
|
3417
|
+
return ALLOWED_NAME.test(name);
|
|
3418
|
+
};
|
|
3419
|
+
const isCssClassDeclarationBody = (value) => {
|
|
3420
|
+
const trimmed = value.trim();
|
|
3421
|
+
if (!trimmed || trimmed.length > 4000) {
|
|
3422
|
+
return false;
|
|
3423
|
+
}
|
|
3424
|
+
if (REJECTED_CONTROL_CHARACTERS.test(trimmed) || !isBraceBalanced(trimmed)) {
|
|
3425
|
+
return false;
|
|
3426
|
+
}
|
|
3427
|
+
const lowered = trimmed.toLowerCase();
|
|
3428
|
+
return !REJECTED_IN_BODY.some((rejected) => lowered.includes(rejected));
|
|
3429
|
+
};
|
|
3430
|
+
const sanitizeForStylesheet$1 = (classes) => {
|
|
3431
|
+
if (!classes) {
|
|
3432
|
+
return {};
|
|
3433
|
+
}
|
|
3434
|
+
const sanitized = {};
|
|
3435
|
+
for (const [rawName, rawValue] of Object.entries(classes)) {
|
|
3436
|
+
const name = rawName.startsWith('.') ? rawName.slice(1) : rawName.trim();
|
|
3437
|
+
if (!isCssClassName(name) || typeof rawValue !== 'string') {
|
|
3438
|
+
continue;
|
|
3439
|
+
}
|
|
3440
|
+
const value = rawValue.trim();
|
|
3441
|
+
if (!isCssClassDeclarationBody(value)) {
|
|
3442
|
+
continue;
|
|
3443
|
+
}
|
|
3444
|
+
sanitized[name] = value;
|
|
3445
|
+
}
|
|
3446
|
+
return sanitized;
|
|
3447
|
+
};
|
|
3448
|
+
const indentDeclarationBody = (body) => body
|
|
3449
|
+
.split('\n')
|
|
3450
|
+
.map((line) => ` ${line}`)
|
|
3451
|
+
.join('\n');
|
|
3452
|
+
/**
|
|
3453
|
+
* Descendant class rules under this widget’s published-key span.
|
|
3454
|
+
* Empty / flag-off / unsanitary catalogs return null so the caller omits `<style>`.
|
|
3455
|
+
*/
|
|
3456
|
+
const formatProjectCssClassesStylesheet = (publishedKey, classes, includeClassDefinitions) => {
|
|
3457
|
+
if (!shouldIncludeClassDefinitionsOnPublishedWidget(includeClassDefinitions)) {
|
|
3458
|
+
return null;
|
|
3459
|
+
}
|
|
3460
|
+
const sanitized = sanitizeForStylesheet$1(classes);
|
|
3461
|
+
const names = Object.keys(sanitized);
|
|
3462
|
+
if (names.length === 0 || !publishedKey) {
|
|
3463
|
+
return null;
|
|
3464
|
+
}
|
|
3465
|
+
const ancestor = `[data-rulecms-published-key="${escapeCssAttributeValue$1(publishedKey)}"]`;
|
|
3466
|
+
return names
|
|
3467
|
+
.sort((left, right) => left.localeCompare(right))
|
|
3468
|
+
.map((name) => `${ancestor} .${escapeCssClassName(name)} {\n${indentDeclarationBody(sanitized[name])}\n}`)
|
|
3469
|
+
.join('\n');
|
|
3470
|
+
};
|
|
3471
|
+
|
|
3472
|
+
/**
|
|
3473
|
+
* Emits one scoped `<style data-rulecms-project-class-definitions>` from the
|
|
3474
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
3475
|
+
*/
|
|
3476
|
+
class ProjectCssClassesStylesheetComponent {
|
|
3477
|
+
get css() {
|
|
3478
|
+
return formatProjectCssClassesStylesheet(this.publishedKey, this.classes);
|
|
3479
|
+
}
|
|
3480
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssClassesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3481
|
+
static { this.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "19.2.25", type: ProjectCssClassesStylesheetComponent, isStandalone: true, selector: "rulecms-project-css-classes-stylesheet", inputs: { publishedKey: "publishedKey", classes: "classes" }, ngImport: i0, template: `
|
|
3482
|
+
@if (css) {
|
|
3483
|
+
<style data-rulecms-project-class-definitions="" [innerText]="css"></style>
|
|
3484
|
+
}
|
|
3485
|
+
`, isInline: true }); }
|
|
3486
|
+
}
|
|
3487
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssClassesStylesheetComponent, decorators: [{
|
|
3488
|
+
type: Component,
|
|
3489
|
+
args: [{
|
|
3490
|
+
selector: 'rulecms-project-css-classes-stylesheet',
|
|
3491
|
+
standalone: true,
|
|
3492
|
+
template: `
|
|
3493
|
+
@if (css) {
|
|
3494
|
+
<style data-rulecms-project-class-definitions="" [innerText]="css"></style>
|
|
3495
|
+
}
|
|
3496
|
+
`,
|
|
3497
|
+
}]
|
|
3498
|
+
}], propDecorators: { publishedKey: [{
|
|
3499
|
+
type: Input,
|
|
3500
|
+
args: [{ required: true }]
|
|
3501
|
+
}], classes: [{
|
|
3502
|
+
type: Input
|
|
3503
|
+
}] } });
|
|
3504
|
+
|
|
3505
|
+
/**
|
|
3506
|
+
* When true, a non-empty `cssVariables` object on the widget GET payload is
|
|
3507
|
+
* emitted as one scoped `<style>` on the published widget.
|
|
3508
|
+
*
|
|
3509
|
+
* TODO: project setting — the customer turns this off if the host stylesheet
|
|
3510
|
+
* already defines these tokens. Hardcoded on for this iteration.
|
|
3511
|
+
*
|
|
3512
|
+
* Class definitions (`classDefinitions` / `includeClassDefinitions` on the
|
|
3513
|
+
* same GET) are a separate catalog; see `project-css-classes/`.
|
|
3514
|
+
*/
|
|
3515
|
+
const INCLUDE_PROJECT_CSS_VARIABLES_ON_PUBLISHED_WIDGET = true;
|
|
3516
|
+
|
|
3517
|
+
/**
|
|
3518
|
+
* Attribute-selector escape so a published key cannot break out of
|
|
3519
|
+
* `[data-rulecms-published-key="…"]`. `CSS.escape` is not assumed (SSR / Node).
|
|
3520
|
+
*/
|
|
3521
|
+
const escapeCssAttributeValue = (value) => value.replace(/\\/g, '\\\\').replace(/"/g, '\\"');
|
|
3522
|
+
const REJECTED_IN_EMITTED_VALUE = /[{};]/;
|
|
3523
|
+
const sanitizeForStylesheet = (variables) => {
|
|
3524
|
+
if (!variables) {
|
|
3525
|
+
return {};
|
|
3526
|
+
}
|
|
3527
|
+
const sanitized = {};
|
|
3528
|
+
for (const [rawName, rawValue] of Object.entries(variables)) {
|
|
3529
|
+
if (!isCssVariableName(rawName) || typeof rawValue !== 'string') {
|
|
3530
|
+
continue;
|
|
3531
|
+
}
|
|
3532
|
+
const value = rawValue.trim();
|
|
3533
|
+
if (value === '' || REJECTED_IN_EMITTED_VALUE.test(value)) {
|
|
3534
|
+
continue;
|
|
3535
|
+
}
|
|
3536
|
+
sanitized[rawName.trim()] = value;
|
|
3537
|
+
}
|
|
3538
|
+
return sanitized;
|
|
3539
|
+
};
|
|
3540
|
+
/**
|
|
3541
|
+
* One rule: custom properties on the first boxed children of this widget’s
|
|
3542
|
+
* published-key span. Empty / flag-off / unsanitary catalogs return null so
|
|
3543
|
+
* the caller omits the `<style>` tag.
|
|
3544
|
+
*/
|
|
3545
|
+
const formatProjectCssVariablesStylesheet = (publishedKey, variables) => {
|
|
3546
|
+
if (!INCLUDE_PROJECT_CSS_VARIABLES_ON_PUBLISHED_WIDGET) {
|
|
3547
|
+
return null;
|
|
3548
|
+
}
|
|
3549
|
+
const sanitized = sanitizeForStylesheet(variables);
|
|
3550
|
+
const names = Object.keys(sanitized);
|
|
3551
|
+
if (names.length === 0 || !publishedKey) {
|
|
3552
|
+
return null;
|
|
3553
|
+
}
|
|
3554
|
+
const selector = `[data-rulecms-published-key="${escapeCssAttributeValue(publishedKey)}"] > *`;
|
|
3555
|
+
const declarations = names
|
|
3556
|
+
.sort((left, right) => left.localeCompare(right))
|
|
3557
|
+
.map((name) => ` ${name}: ${sanitized[name]};`)
|
|
3558
|
+
.join('\n');
|
|
3559
|
+
return `${selector} {\n${declarations}\n}`;
|
|
3560
|
+
};
|
|
3561
|
+
|
|
3562
|
+
/**
|
|
3563
|
+
* Emits one scoped `<style data-rulecms-project-css-variables>` from the
|
|
3564
|
+
* project catalog, or nothing when the catalog is empty / unsanitary.
|
|
3565
|
+
*/
|
|
3566
|
+
class ProjectCssVariablesStylesheetComponent {
|
|
3567
|
+
get css() {
|
|
3568
|
+
return formatProjectCssVariablesStylesheet(this.publishedKey, this.variables);
|
|
3569
|
+
}
|
|
3570
|
+
static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, deps: [], target: i0.ɵɵFactoryTarget.Component }); }
|
|
3571
|
+
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: `
|
|
3572
|
+
@if (css) {
|
|
3573
|
+
<style data-rulecms-project-css-variables="" [innerText]="css"></style>
|
|
3574
|
+
}
|
|
3575
|
+
`, isInline: true }); }
|
|
3576
|
+
}
|
|
3577
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: ProjectCssVariablesStylesheetComponent, decorators: [{
|
|
3578
|
+
type: Component,
|
|
3579
|
+
args: [{
|
|
3580
|
+
selector: 'rulecms-project-css-variables-stylesheet',
|
|
3581
|
+
standalone: true,
|
|
3582
|
+
template: `
|
|
3583
|
+
@if (css) {
|
|
3584
|
+
<style data-rulecms-project-css-variables="" [innerText]="css"></style>
|
|
3585
|
+
}
|
|
3586
|
+
`,
|
|
3587
|
+
}]
|
|
3588
|
+
}], propDecorators: { publishedKey: [{
|
|
3589
|
+
type: Input,
|
|
3590
|
+
args: [{ required: true }]
|
|
3591
|
+
}], variables: [{
|
|
3592
|
+
type: Input
|
|
3593
|
+
}] } });
|
|
3594
|
+
|
|
3376
3595
|
function transformChildCollections(childCollections) {
|
|
3377
3596
|
const transformed = {};
|
|
3378
3597
|
Object.entries(childCollections).forEach(([key, collection]) => {
|
|
@@ -3408,6 +3627,14 @@ function prepareRuleCMSWidgetData(raw) {
|
|
|
3408
3627
|
displayItemList: parseDisplayItemList(raw.widget),
|
|
3409
3628
|
widgetCollections: transformChildCollections(raw.childCollections),
|
|
3410
3629
|
...(raw.libraries ? { libraries: raw.libraries } : {}),
|
|
3630
|
+
...(raw.cssVariables && Object.keys(raw.cssVariables).length > 0
|
|
3631
|
+
? { cssVariables: raw.cssVariables }
|
|
3632
|
+
: {}),
|
|
3633
|
+
...(shouldIncludeClassDefinitionsOnPublishedWidget(raw.includeClassDefinitions) &&
|
|
3634
|
+
raw.classDefinitions &&
|
|
3635
|
+
Object.keys(raw.classDefinitions).length > 0
|
|
3636
|
+
? { classDefinitions: raw.classDefinitions }
|
|
3637
|
+
: {}),
|
|
3411
3638
|
};
|
|
3412
3639
|
}
|
|
3413
3640
|
|
|
@@ -3648,6 +3875,14 @@ class RuleCMSWidgetComponent {
|
|
|
3648
3875
|
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
3876
|
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
3877
|
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
3878
|
+
<rulecms-project-css-variables-stylesheet
|
|
3879
|
+
[publishedKey]="publishedKey"
|
|
3880
|
+
[variables]="preparedData?.cssVariables"
|
|
3881
|
+
/>
|
|
3882
|
+
<rulecms-project-css-classes-stylesheet
|
|
3883
|
+
[publishedKey]="publishedKey"
|
|
3884
|
+
[classes]="preparedData?.classDefinitions"
|
|
3885
|
+
/>
|
|
3651
3886
|
@if (mode !== 'pre-fetched' && loading) {
|
|
3652
3887
|
<div [ngStyle]="loadingContainerStyle">
|
|
3653
3888
|
<div [ngStyle]="spinnerContainerStyle">
|
|
@@ -3688,16 +3923,30 @@ class RuleCMSWidgetComponent {
|
|
|
3688
3923
|
}
|
|
3689
3924
|
}
|
|
3690
3925
|
</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"] }] }); }
|
|
3926
|
+
`, 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"] }, { kind: "component", type: ProjectCssClassesStylesheetComponent, selector: "rulecms-project-css-classes-stylesheet", inputs: ["publishedKey", "classes"] }] }); }
|
|
3692
3927
|
}
|
|
3693
3928
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: RuleCMSWidgetComponent, decorators: [{
|
|
3694
3929
|
type: Component,
|
|
3695
3930
|
args: [{
|
|
3696
3931
|
selector: 'rulecms-widget',
|
|
3697
3932
|
standalone: true,
|
|
3698
|
-
imports: [
|
|
3933
|
+
imports: [
|
|
3934
|
+
NgStyle,
|
|
3935
|
+
BreakpointVariantRenderComponent,
|
|
3936
|
+
RenderComponentsComponent,
|
|
3937
|
+
ProjectCssVariablesStylesheetComponent,
|
|
3938
|
+
ProjectCssClassesStylesheetComponent,
|
|
3939
|
+
],
|
|
3699
3940
|
template: `
|
|
3700
3941
|
<span [attr.data-rulecms-published-key]="publishedKey" style="display: contents">
|
|
3942
|
+
<rulecms-project-css-variables-stylesheet
|
|
3943
|
+
[publishedKey]="publishedKey"
|
|
3944
|
+
[variables]="preparedData?.cssVariables"
|
|
3945
|
+
/>
|
|
3946
|
+
<rulecms-project-css-classes-stylesheet
|
|
3947
|
+
[publishedKey]="publishedKey"
|
|
3948
|
+
[classes]="preparedData?.classDefinitions"
|
|
3949
|
+
/>
|
|
3701
3950
|
@if (mode !== 'pre-fetched' && loading) {
|
|
3702
3951
|
<div [ngStyle]="loadingContainerStyle">
|
|
3703
3952
|
<div [ngStyle]="spinnerContainerStyle">
|