@nordcraft/runtime 1.0.32 → 1.0.33
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/dist/components/createComponent.js +40 -0
- package/dist/components/createComponent.js.map +1 -1
- package/dist/components/createElement.js +39 -3
- package/dist/components/createElement.js.map +1 -1
- package/dist/custom-element.main.esm.js +34 -28
- package/dist/custom-element.main.esm.js.map +4 -4
- package/dist/editor-preview.main.js +19 -0
- package/dist/editor-preview.main.js.map +1 -1
- package/dist/page.main.esm.js +3 -3
- package/dist/page.main.esm.js.map +4 -4
- package/dist/styles/CustomPropertyStyleSheet.d.ts +34 -0
- package/dist/styles/CustomPropertyStyleSheet.js +109 -0
- package/dist/styles/CustomPropertyStyleSheet.js.map +1 -0
- package/dist/styles/CustomPropertyStyleSheet.test.d.ts +1 -0
- package/dist/styles/CustomPropertyStyleSheet.test.js +66 -0
- package/dist/styles/CustomPropertyStyleSheet.test.js.map +1 -0
- package/dist/styles/style.js +23 -0
- package/dist/styles/style.js.map +1 -1
- package/dist/utils/omitStyle.js +3 -1
- package/dist/utils/omitStyle.js.map +1 -1
- package/dist/utils/subscribeCustomProperty.d.ts +8 -0
- package/dist/utils/subscribeCustomProperty.js +9 -0
- package/dist/utils/subscribeCustomProperty.js.map +1 -0
- package/package.json +3 -3
- package/src/components/createComponent.ts +48 -0
- package/src/components/createElement.ts +52 -3
- package/src/editor-preview.main.ts +27 -0
- package/src/styles/CustomPropertyStyleSheet.test.ts +104 -0
- package/src/styles/CustomPropertyStyleSheet.ts +163 -0
- package/src/styles/style.ts +33 -0
- package/src/utils/omitStyle.ts +10 -2
- package/src/utils/subscribeCustomProperty.ts +41 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { MediaQuery } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
/**
|
|
3
|
+
* CustomPropertyStyleSheet is a utility class that manages CSS custom properties
|
|
4
|
+
* (variables) in a dedicated CSSStyleSheet. It allows for efficient registration,
|
|
5
|
+
* updating, and removal of style properties as fast as setting style properties.
|
|
6
|
+
*
|
|
7
|
+
* It abstracts the complexity of managing CSS rules via. indexing and
|
|
8
|
+
* provides a simple API to register and unregister style properties for specific
|
|
9
|
+
* selectors.
|
|
10
|
+
*/
|
|
11
|
+
export declare class CustomPropertyStyleSheet {
|
|
12
|
+
private styleSheet;
|
|
13
|
+
private ruleMap;
|
|
14
|
+
constructor(styleSheet?: CSSStyleSheet | null);
|
|
15
|
+
/**
|
|
16
|
+
* @returns A function to update the property value efficiently.
|
|
17
|
+
*/
|
|
18
|
+
registerProperty(selector: string, name: string, options?: {
|
|
19
|
+
mediaQuery?: MediaQuery;
|
|
20
|
+
startingStyle?: boolean;
|
|
21
|
+
}): (newValue: string) => void;
|
|
22
|
+
unregisterProperty(selector: string, name: string, options?: {
|
|
23
|
+
mediaQuery?: MediaQuery;
|
|
24
|
+
startingStyle?: boolean;
|
|
25
|
+
}): void;
|
|
26
|
+
getStyleSheet(): CSSStyleSheet;
|
|
27
|
+
/**
|
|
28
|
+
* Maps all selectors to their rule index. This is used to map the initial
|
|
29
|
+
* SSR style variable values to their selectors.
|
|
30
|
+
*/
|
|
31
|
+
private hydrateFromBase;
|
|
32
|
+
private static selectorFromCSSRule;
|
|
33
|
+
private static getFullSelector;
|
|
34
|
+
}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CustomPropertyStyleSheet is a utility class that manages CSS custom properties
|
|
3
|
+
* (variables) in a dedicated CSSStyleSheet. It allows for efficient registration,
|
|
4
|
+
* updating, and removal of style properties as fast as setting style properties.
|
|
5
|
+
*
|
|
6
|
+
* It abstracts the complexity of managing CSS rules via. indexing and
|
|
7
|
+
* provides a simple API to register and unregister style properties for specific
|
|
8
|
+
* selectors.
|
|
9
|
+
*/
|
|
10
|
+
export class CustomPropertyStyleSheet {
|
|
11
|
+
styleSheet;
|
|
12
|
+
// Selector to rule index mapping
|
|
13
|
+
ruleMap;
|
|
14
|
+
constructor(styleSheet) {
|
|
15
|
+
if (styleSheet) {
|
|
16
|
+
this.styleSheet = styleSheet;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.styleSheet = new CSSStyleSheet();
|
|
20
|
+
document.adoptedStyleSheets.push(this.getStyleSheet());
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @returns A function to update the property value efficiently.
|
|
25
|
+
*/
|
|
26
|
+
registerProperty(selector, name, options) {
|
|
27
|
+
this.ruleMap ??= this.hydrateFromBase();
|
|
28
|
+
const fullSelector = CustomPropertyStyleSheet.getFullSelector(selector, options);
|
|
29
|
+
// Check if the selector already exists
|
|
30
|
+
let rule = this.ruleMap.get(fullSelector);
|
|
31
|
+
if (!rule) {
|
|
32
|
+
const ruleIndex = this.styleSheet.insertRule(fullSelector);
|
|
33
|
+
let newRule = this.styleSheet.cssRules[ruleIndex];
|
|
34
|
+
// We are only interested in the dynamic style, so get the actual style rule, not media or other nested rules. Loop until we are at the bottom most rule.
|
|
35
|
+
while (newRule.cssRules &&
|
|
36
|
+
newRule.cssRules.length > 0) {
|
|
37
|
+
newRule = newRule.cssRules[0];
|
|
38
|
+
}
|
|
39
|
+
rule = newRule;
|
|
40
|
+
this.ruleMap.set(fullSelector, rule);
|
|
41
|
+
}
|
|
42
|
+
return (value) => {
|
|
43
|
+
rule.style.setProperty(name, value);
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
unregisterProperty(selector, name, options) {
|
|
47
|
+
if (!this.ruleMap) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
const fullSelector = CustomPropertyStyleSheet.getFullSelector(selector, options);
|
|
51
|
+
// We only clean up the property, as we assume that the rule will be reused.
|
|
52
|
+
this.ruleMap.get(fullSelector)?.style.removeProperty(name);
|
|
53
|
+
}
|
|
54
|
+
getStyleSheet() {
|
|
55
|
+
return this.styleSheet;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Maps all selectors to their rule index. This is used to map the initial
|
|
59
|
+
* SSR style variable values to their selectors.
|
|
60
|
+
*/
|
|
61
|
+
hydrateFromBase() {
|
|
62
|
+
const ruleIndex = new Map();
|
|
63
|
+
for (let i = 0; i < this.styleSheet.cssRules.length; i++) {
|
|
64
|
+
let rule = this.styleSheet.cssRules[i];
|
|
65
|
+
const selector = CustomPropertyStyleSheet.selectorFromCSSRule(rule);
|
|
66
|
+
// Get last part of the selector, which is the actual selector we are interested in
|
|
67
|
+
while (rule.cssRules &&
|
|
68
|
+
rule.cssRules.length > 0) {
|
|
69
|
+
rule = rule.cssRules[0];
|
|
70
|
+
}
|
|
71
|
+
ruleIndex.set(selector, rule);
|
|
72
|
+
}
|
|
73
|
+
return ruleIndex;
|
|
74
|
+
}
|
|
75
|
+
static selectorFromCSSRule(rule) {
|
|
76
|
+
switch (rule.constructor.name) {
|
|
77
|
+
case 'CSSStyleRule':
|
|
78
|
+
// For these rules, we just return (potentially with subrules if any cssRules exist)
|
|
79
|
+
return `${rule.selectorText} { ${Array.from(rule.cssRules)
|
|
80
|
+
.map(CustomPropertyStyleSheet.selectorFromCSSRule)
|
|
81
|
+
.join(', ')}}`;
|
|
82
|
+
case 'CSSStartingStyleRule':
|
|
83
|
+
return `@starting-style { ${Array.from(rule.cssRules)
|
|
84
|
+
.map(CustomPropertyStyleSheet.selectorFromCSSRule)
|
|
85
|
+
.join(', ')}}`;
|
|
86
|
+
case 'CSSMediaRule':
|
|
87
|
+
return `@media ${rule.media.mediaText} { ${Array.from(rule.cssRules)
|
|
88
|
+
.map(CustomPropertyStyleSheet.selectorFromCSSRule)
|
|
89
|
+
.join(', ')}}`;
|
|
90
|
+
case 'CSSNestedDeclarations':
|
|
91
|
+
return '';
|
|
92
|
+
default:
|
|
93
|
+
// eslint-disable-next-line no-console
|
|
94
|
+
console.warn(`Unsupported CSS rule type: ${rule.constructor.name}. Returning empty selector.`);
|
|
95
|
+
return '';
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
static getFullSelector(selector, options) {
|
|
99
|
+
let result = selector + (options?.startingStyle ? ' { @starting-style { }}' : ' { }');
|
|
100
|
+
if (options?.mediaQuery) {
|
|
101
|
+
result = `@media (${Object.entries(options.mediaQuery)
|
|
102
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
103
|
+
.filter(Boolean)
|
|
104
|
+
.join(') and (')}) { ${result}}`;
|
|
105
|
+
}
|
|
106
|
+
return result;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
//# sourceMappingURL=CustomPropertyStyleSheet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomPropertyStyleSheet.js","sourceRoot":"","sources":["../../src/styles/CustomPropertyStyleSheet.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,OAAO,wBAAwB;IAC3B,UAAU,CAAe;IAEjC,iCAAiC;IACzB,OAAO,CAA+D;IAE9E,YAAY,UAAiC;QAC3C,IAAI,UAAU,EAAE,CAAC;YACf,IAAI,CAAC,UAAU,GAAG,UAAU,CAAA;QAC9B,CAAC;aAAM,CAAC;YACN,IAAI,CAAC,UAAU,GAAG,IAAI,aAAa,EAAE,CAAA;YACrC,QAAQ,CAAC,kBAAkB,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,CAAC,CAAA;QACxD,CAAC;IACH,CAAC;IAED;;OAEG;IACI,gBAAgB,CACrB,QAAgB,EAChB,IAAY,EACZ,OAGC;QAED,IAAI,CAAC,OAAO,KAAK,IAAI,CAAC,eAAe,EAAE,CAAA;QACvC,MAAM,YAAY,GAAG,wBAAwB,CAAC,eAAe,CAC3D,QAAQ,EACR,OAAO,CACR,CAAA;QAED,uCAAuC;QACvC,IAAI,IAAI,GAAG,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC,CAAA;QACzC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,SAAS,GAAG,IAAI,CAAC,U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AA;gBACD,OAAO,EAAE,CAAA;QACb,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,eAAe,CAC5B,QAAgB,EAChB,OAGC;QAED,IAAI,MAAM,GACR,QAAQ,GAAG,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,yBAAyB,CAAC,CAAC,CAAC,MAAM,CAAC,CAAA;QAC1E,IAAI,OAAO,EAAE,UAAU,EAAE,CAAC;YACxB,MAAM,GAAG,WAAW,MAAM,CAAC,OAAO,CAAC,OAAO,CAAC,UAAU,CAAC;iBACnD,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,KAAK,EAAE,CAAC;iBACzC,MAAM,CAAC,OAAO,CAAC;iBACf,IAAI,CAAC,SAAS,CAAC,OAAO,MAAM,GAAG,CAAA;QACpC,CAAC;QAED,OAAO,MAAM,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { describe, expect, test } from 'bun:test';
|
|
2
|
+
import { CustomPropertyStyleSheet } from './CustomPropertyStyleSheet';
|
|
3
|
+
describe('CustomPropertyStyleSheet', () => {
|
|
4
|
+
test('it creates a new stylesheet', () => {
|
|
5
|
+
const instance = new CustomPropertyStyleSheet();
|
|
6
|
+
expect(instance).toBeInstanceOf(CustomPropertyStyleSheet);
|
|
7
|
+
expect(instance.getStyleSheet().cssRules).toHaveLength(0);
|
|
8
|
+
});
|
|
9
|
+
test('it adds a property definition', () => {
|
|
10
|
+
const instance = new CustomPropertyStyleSheet();
|
|
11
|
+
instance.registerProperty('.my-class', '--my-property');
|
|
12
|
+
expect(instance.getStyleSheet().cssRules.length).toBe(1);
|
|
13
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { }');
|
|
14
|
+
});
|
|
15
|
+
test('it puts different selectors in different rules', () => {
|
|
16
|
+
const instance = new CustomPropertyStyleSheet();
|
|
17
|
+
instance.registerProperty('.my-class', '--my-property')('256px');
|
|
18
|
+
instance.registerProperty('.my-other-class', '--my-property')('256px');
|
|
19
|
+
expect(instance.getStyleSheet().cssRules.length).toBe(2);
|
|
20
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { --my-property: 256px; }');
|
|
21
|
+
expect(instance.getStyleSheet().cssRules[1].cssText).toBe('.my-other-class { --my-property: 256px; }');
|
|
22
|
+
});
|
|
23
|
+
test('it can update properties', () => {
|
|
24
|
+
const instance = new CustomPropertyStyleSheet();
|
|
25
|
+
const setter = instance.registerProperty('.my-class', '--my-property');
|
|
26
|
+
setter('256px');
|
|
27
|
+
expect(instance.getStyleSheet().cssRules.length).toBe(1);
|
|
28
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { --my-property: 256px; }');
|
|
29
|
+
setter('inherit');
|
|
30
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { --my-property: inherit; }');
|
|
31
|
+
});
|
|
32
|
+
test('it works with media queries', () => {
|
|
33
|
+
const instance = new CustomPropertyStyleSheet();
|
|
34
|
+
instance.registerProperty('.my-class', '--my-property', {
|
|
35
|
+
mediaQuery: { 'max-width': '600px' },
|
|
36
|
+
})('256px');
|
|
37
|
+
expect(instance.getStyleSheet().cssRules.length).toBe(1);
|
|
38
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('@media (max-width: 600px) { .my-class { --my-property: 256px; } }');
|
|
39
|
+
});
|
|
40
|
+
test('it unregisters a property', () => {
|
|
41
|
+
const instance = new CustomPropertyStyleSheet();
|
|
42
|
+
const setter = instance.registerProperty('.my-class', '--my-property');
|
|
43
|
+
setter('256px');
|
|
44
|
+
const setter2 = instance.registerProperty('.my-class', '--my-other-property');
|
|
45
|
+
setter2('512px');
|
|
46
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { --my-property: 256px; --my-other-property: 512px; }');
|
|
47
|
+
instance.unregisterProperty('.my-class', '--my-property');
|
|
48
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { --my-other-property: 512px; }');
|
|
49
|
+
instance.unregisterProperty('.my-class', '--my-other-property');
|
|
50
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { }');
|
|
51
|
+
});
|
|
52
|
+
test('it unregisters a property with media queries', () => {
|
|
53
|
+
const instance = new CustomPropertyStyleSheet();
|
|
54
|
+
const setter = instance.registerProperty('.my-class-with-media', '--my-property-with-media', {
|
|
55
|
+
mediaQuery: { 'max-width': '600px' },
|
|
56
|
+
});
|
|
57
|
+
setter('256px');
|
|
58
|
+
expect(instance.getStyleSheet().cssRules.length).toBe(1);
|
|
59
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('@media (max-width: 600px) { .my-class-with-media { --my-property-with-media: 256px; } }');
|
|
60
|
+
instance.unregisterProperty('.my-class-with-media', '--my-property-with-media', {
|
|
61
|
+
mediaQuery: { 'max-width': '600px' },
|
|
62
|
+
});
|
|
63
|
+
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('@media (max-width: 600px) { .my-class-with-media { } }');
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
//# sourceMappingURL=CustomPropertyStyleSheet.test.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CustomPropertyStyleSheet.test.js","sourceRoot":"","sources":["../../src/styles/CustomPropertyStyleSheet.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,UAAU,CAAA;AACjD,OAAO,EAAE,wBAAwB,EAAE,MAAM,4BAA4B,CAAA;AAErE,QAAQ,CAAC,0BAA0B,EAAE,GAAG,EAAE;IACxC,IAAI,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACvC,MAAM,QAAQ,GAAG,IAAI,wBAAwB,EAAE,CAAA;QAC/C,MAAM,CAAC,QAAQ,CAAC,CAAC,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a,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CACvD,yFAAyF,CAC1F,CAAA;QAED,QAAQ,CAAC,kBAAkB,CACzB,sBAAsB,EACtB,0BAA0B,EAC1B;YACE,UAAU,EAAE,EAAE,WAAW,EAAE,OAAO,EAAE;SACrC,CACF,CAAA;QACD,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CACvD,yDAAyD,CAC1D,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
|
package/dist/styles/style.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getClassName, toValidClassName, } from '@nordcraft/core/dist/styling/className';
|
|
2
|
+
import { syntaxNodeToPropertyAtDefinition, } from '@nordcraft/core/dist/styling/customProperty';
|
|
2
3
|
import { kebabCase } from '@nordcraft/core/dist/styling/style.css';
|
|
3
4
|
import { variantSelector } from '@nordcraft/core/dist/styling/variantSelector';
|
|
4
5
|
import { omitKeys } from '@nordcraft/core/dist/utils/collections';
|
|
@@ -45,6 +46,7 @@ export const SIZE_PROPERTIES = new Set([
|
|
|
45
46
|
'outline-width',
|
|
46
47
|
]);
|
|
47
48
|
export const insertStyles = (parent, root, components) => {
|
|
49
|
+
const registeredCustomProperties = new Map();
|
|
48
50
|
const getNodeStyles = (node, classHash) => {
|
|
49
51
|
const style = omitKeys(node.style ?? {}, [
|
|
50
52
|
'variants',
|
|
@@ -104,6 +106,27 @@ ${node.animations
|
|
|
104
106
|
})
|
|
105
107
|
.join('\n')
|
|
106
108
|
: ''}
|
|
109
|
+
${[
|
|
110
|
+
...Object.entries(node.customProperties ?? {}),
|
|
111
|
+
...(node.variants?.flatMap((variant) => Object.entries(variant.customProperties ?? {})) ?? []),
|
|
112
|
+
]
|
|
113
|
+
.map(([customPropertyName, customProperty]) => {
|
|
114
|
+
const existingCustomProperty = registeredCustomProperties.get(customPropertyName);
|
|
115
|
+
if (existingCustomProperty) {
|
|
116
|
+
// Warn if the style variable is already registered with a different syntax, as registration is global.
|
|
117
|
+
// The editor should also report an Error-level issue.
|
|
118
|
+
if (existingCustomProperty.type === 'primitive' &&
|
|
119
|
+
customProperty.syntax.type === 'primitive' &&
|
|
120
|
+
existingCustomProperty.name !== customProperty.syntax.name) {
|
|
121
|
+
// eslint-disable-next-line no-console
|
|
122
|
+
console.warn(`Custom property "${customPropertyName}" is already registered with a different syntax: "${existingCustomProperty.name}".`);
|
|
123
|
+
}
|
|
124
|
+
return '';
|
|
125
|
+
}
|
|
126
|
+
registeredCustomProperties.set(customPropertyName, customProperty.syntax);
|
|
127
|
+
return syntaxNodeToPropertyAtDefinition(customPropertyName, customProperty);
|
|
128
|
+
})
|
|
129
|
+
.join('\n')}
|
|
107
130
|
`));
|
|
108
131
|
return styleElem;
|
|
109
132
|
};
|
package/dist/styles/style.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"style.js","sourceRoot":"","sources":["../../src/styles/style.ts"],"names":[],"mappings":"AAMA,OAAO,EACL,YAAY,EACZ,gBAAgB,GACjB,MAAM,wCAAwC,CAAA;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,wCAAwC,CAAA;AAClE,OAAO,EAAE,eAAe,EAAE,MAAM,8CAA8C,CAAA;AAC9E,OAAO,EAAE,QAAQ,EAAE,MAAM,wCAAwC,CAAA;AAEjE,MAAM,kBAAkB,GAAG;IACzB,KAAK,EAAE,IAAI;IACX,KAAK,EAAE,GAAG;IACV,MAAM,EAAE,GAAG;CACZ,CAAA;AAED,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IACrC,OAAO;IACP,WAAW;IACX,WAAW;IACX,QAAQ;IACR,YAAY;IACZ,YAAY;IACZ,QAAQ;IACR,YAAY;IACZ,aAAa;IACb,eAAe;IACf,cAAc;IACd,SAAS;IACT,aAAa;IACb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=== 'element' || node.type === 'component') &&
|
|
5
5
|
nodeId !== 'root') {
|
|
6
6
|
delete node.style;
|
|
7
|
-
delete node.variants;
|
|
8
7
|
delete node.animations;
|
|
8
|
+
node.variants = node.variants?.map(({ customProperties }) => ({
|
|
9
|
+
customProperties,
|
|
10
|
+
}));
|
|
9
11
|
}
|
|
10
12
|
});
|
|
11
13
|
return clone;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"omitStyle.js","sourceRoot":"","sources":["../../src/utils/omitStyle.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"omitStyle.js","sourceRoot":"","sources":["../../src/utils/omitStyle.ts"],"names":[],"mappings":"AAKA,MAAM,UAAU,4BAA4B,CAC1C,SAAY;IAEZ,MAAM,KAAK,GAAG,eAAe,CAAC,SAAS,CAAC,CAAA;IACxC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;QAC5D,IACE,CAAC,IAAI,CAAC,IAAI,KAAK,SAAS,IAAI,IAAI,CAAC,IAAI,KAAK,WAAW,CAAC;YACtD,MAAM,KAAK,MAAM,EACjB,CAAC;YACD,OAAO,IAAI,CAAC,KAAK,CAAA;YACjB,OAAO,IAAI,CAAC,UAAU,CAAA;YACtB,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,QAAQ,EAAE,GAAG,CAChC,CAAC,EAAE,gBAAgB,EAAE,EAAE,EAAE,CACvB,CAAC;gBACC,gBAAgB;aACjB,CAAiB,CACrB,CAAA;QACH,CAAC;IACH,CAAC,CAAC,CAAA;IAEF,OAAO,KAAK,CAAA;AACd,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { StyleVariant } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
import type { Signal } from '../signal/signal';
|
|
3
|
+
export declare function subscribeCustomProperty({ selector, customPropertyName, signal, variant, }: {
|
|
4
|
+
selector: string;
|
|
5
|
+
customPropertyName: string;
|
|
6
|
+
signal: Signal<string>;
|
|
7
|
+
variant?: StyleVariant;
|
|
8
|
+
}): void;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { CUSTOM_PROPERTIES_STYLESHEET_ID } from '@nordcraft/core/dist/styling/theme.const';
|
|
2
|
+
import { CustomPropertyStyleSheet } from '../styles/CustomPropertyStyleSheet';
|
|
3
|
+
const CUSTOM_PROPERTIES_STYLESHEET = new CustomPropertyStyleSheet(document.getElementById(CUSTOM_PROPERTIES_STYLESHEET_ID)?.sheet);
|
|
4
|
+
export function subscribeCustomProperty({ selector, customPropertyName, signal, variant, }) {
|
|
5
|
+
signal.subscribe(CUSTOM_PROPERTIES_STYLESHEET.registerProperty(selector, customPropertyName, variant), {
|
|
6
|
+
destroy: () => CUSTOM_PROPERTIES_STYLESHEET.unregisterProperty(selector, customPropertyName, variant),
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=subscribeCustomProperty.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subscribeCustomProperty.js","sourceRoot":"","sources":["../../src/utils/subscribeCustomProperty.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAA;AAC1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAA;AAE7E,MAAM,4BAA4B,GAAG,IAAI,wBAAwB,CAE7D,QAAQ,CAAC,cAAc,CAAC,+BAA+B,CAGxD,EAAE,KAAK,CACT,CAAA;AAED,MAAM,UAAU,uBAAuB,CAAC,EACtC,QAAQ,EACR,kBAAkB,EAClB,MAAM,EACN,OAAO,GAMR;IACC,MAAM,CAAC,SAAS,CACd,4BAA4B,CAAC,gBAAgB,CAC3C,QAAQ,EACR,kBAAkB,EAClB,OAAO,CACR,EACD;QACE,OAAO,EAAE,GAAG,EAAE,CACZ,4BAA4B,CAAC,kBAAkB,CAC7C,QAAQ,EACR,kBAAkB,EAClB,OAAO,CACR;KACJ,CACF,CAAA;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -4,8 +4,8 @@
|
|
|
4
4
|
"type": "module",
|
|
5
5
|
"homepage": "https://github.com/nordcraftengine/nordcraft",
|
|
6
6
|
"dependencies": {
|
|
7
|
-
"@nordcraft/core": "1.0.
|
|
8
|
-
"@nordcraft/std-lib": "1.0.
|
|
7
|
+
"@nordcraft/core": "1.0.33",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.33",
|
|
9
9
|
"fast-deep-equal": "3.1.3",
|
|
10
10
|
"path-to-regexp": "6.3.0"
|
|
11
11
|
},
|
|
@@ -21,5 +21,5 @@
|
|
|
21
21
|
"files": ["dist", "src"],
|
|
22
22
|
"main": "dist/page.main.js",
|
|
23
23
|
"types": "dist/page.main.d.ts",
|
|
24
|
-
"version": "1.0.
|
|
24
|
+
"version": "1.0.33"
|
|
25
25
|
}
|
|
@@ -6,6 +6,7 @@ import type {
|
|
|
6
6
|
} from '@nordcraft/core/dist/component/component.types'
|
|
7
7
|
import { applyFormula } from '@nordcraft/core/dist/formula/formula'
|
|
8
8
|
import { mapObject } from '@nordcraft/core/dist/utils/collections'
|
|
9
|
+
import { getNodeSelector } from '@nordcraft/core/dist/utils/getNodeSelector'
|
|
9
10
|
import { isDefined } from '@nordcraft/core/dist/utils/util'
|
|
10
11
|
import { isContextApiV2 } from '../api/apiUtils'
|
|
11
12
|
import { createLegacyAPI } from '../api/createAPI'
|
|
@@ -18,6 +19,7 @@ import type { Signal } from '../signal/signal'
|
|
|
18
19
|
import { signal } from '../signal/signal'
|
|
19
20
|
import type { ComponentChild, ComponentContext, ContextApi } from '../types'
|
|
20
21
|
import { createFormulaCache } from '../utils/createFormulaCache'
|
|
22
|
+
import { subscribeCustomProperty } from '../utils/subscribeCustomProperty'
|
|
21
23
|
import { renderComponent } from './renderComponent'
|
|
22
24
|
|
|
23
25
|
export type RenderComponentNodeProps = {
|
|
@@ -68,6 +70,52 @@ export function createComponent({
|
|
|
68
70
|
: value?.value,
|
|
69
71
|
])
|
|
70
72
|
})
|
|
73
|
+
Object.entries(node.customProperties ?? {}).forEach(
|
|
74
|
+
([customPropertyName, customProperty]) =>
|
|
75
|
+
subscribeCustomProperty({
|
|
76
|
+
selector: getNodeSelector(path, {
|
|
77
|
+
componentName: ctx.component.name,
|
|
78
|
+
nodeId: node.id,
|
|
79
|
+
}),
|
|
80
|
+
signal: dataSignal.map((data) => {
|
|
81
|
+
return applyFormula(customProperty.formula, {
|
|
82
|
+
data,
|
|
83
|
+
component: ctx.component,
|
|
84
|
+
formulaCache: ctx.formulaCache,
|
|
85
|
+
root: ctx.root,
|
|
86
|
+
package: ctx.package,
|
|
87
|
+
toddle: ctx.toddle,
|
|
88
|
+
env: ctx.env,
|
|
89
|
+
})
|
|
90
|
+
}),
|
|
91
|
+
customPropertyName,
|
|
92
|
+
}),
|
|
93
|
+
)
|
|
94
|
+
node.variants?.forEach((variant) => {
|
|
95
|
+
Object.entries(variant.customProperties ?? {}).forEach(
|
|
96
|
+
([customPropertyName, customProperty]) =>
|
|
97
|
+
subscribeCustomProperty({
|
|
98
|
+
selector: getNodeSelector(path, {
|
|
99
|
+
componentName: ctx.component.name,
|
|
100
|
+
nodeId: node.id,
|
|
101
|
+
variant,
|
|
102
|
+
}),
|
|
103
|
+
signal: dataSignal.map((data) =>
|
|
104
|
+
applyFormula(customProperty.formula, {
|
|
105
|
+
data,
|
|
106
|
+
component: ctx.component,
|
|
107
|
+
formulaCache: ctx.formulaCache,
|
|
108
|
+
root: ctx.root,
|
|
109
|
+
package: ctx.package,
|
|
110
|
+
toddle: ctx.toddle,
|
|
111
|
+
env: ctx.env,
|
|
112
|
+
}),
|
|
113
|
+
),
|
|
114
|
+
customPropertyName,
|
|
115
|
+
variant,
|
|
116
|
+
}),
|
|
117
|
+
)
|
|
118
|
+
})
|
|
71
119
|
|
|
72
120
|
const componentDataSignal = signal<ComponentData>({
|
|
73
121
|
Location: dataSignal.get().Location,
|
|
@@ -8,12 +8,14 @@ import {
|
|
|
8
8
|
getClassName,
|
|
9
9
|
toValidClassName,
|
|
10
10
|
} from '@nordcraft/core/dist/styling/className'
|
|
11
|
+
import { getNodeSelector } from '@nordcraft/core/dist/utils/getNodeSelector'
|
|
11
12
|
import { isDefined, toBoolean } from '@nordcraft/core/dist/utils/util'
|
|
12
13
|
import { handleAction } from '../events/handleAction'
|
|
13
14
|
import type { Signal } from '../signal/signal'
|
|
14
15
|
import { getDragData } from '../utils/getDragData'
|
|
15
16
|
import { getElementTagName } from '../utils/getElementTagName'
|
|
16
17
|
import { setAttribute } from '../utils/setAttribute'
|
|
18
|
+
import { subscribeCustomProperty } from '../utils/subscribeCustomProperty'
|
|
17
19
|
import type { NodeRenderer } from './createNode'
|
|
18
20
|
import { createNode } from './createNode'
|
|
19
21
|
|
|
@@ -130,8 +132,9 @@ export function createElement({
|
|
|
130
132
|
setupAttribute()
|
|
131
133
|
}
|
|
132
134
|
})
|
|
133
|
-
node['style-variables']?.forEach((
|
|
134
|
-
const
|
|
135
|
+
node['style-variables']?.forEach((styleVariable) => {
|
|
136
|
+
const { name, formula, unit } = styleVariable
|
|
137
|
+
const signal = dataSignal.map((data) => {
|
|
135
138
|
const value = applyFormula(formula, {
|
|
136
139
|
data,
|
|
137
140
|
component: ctx.component,
|
|
@@ -143,8 +146,54 @@ export function createElement({
|
|
|
143
146
|
})
|
|
144
147
|
return unit ? value + unit : value
|
|
145
148
|
})
|
|
146
|
-
|
|
149
|
+
|
|
150
|
+
signal.subscribe((value) => elem.style.setProperty(`--${name}`, value))
|
|
147
151
|
})
|
|
152
|
+
|
|
153
|
+
Object.entries(node.customProperties ?? {}).forEach(
|
|
154
|
+
([customPropertyName, { formula }]) =>
|
|
155
|
+
subscribeCustomProperty({
|
|
156
|
+
customPropertyName,
|
|
157
|
+
selector: getNodeSelector(path),
|
|
158
|
+
signal: dataSignal.map((data) =>
|
|
159
|
+
applyFormula(formula, {
|
|
160
|
+
data,
|
|
161
|
+
component: ctx.component,
|
|
162
|
+
formulaCache: ctx.formulaCache,
|
|
163
|
+
root: ctx.root,
|
|
164
|
+
package: ctx.package,
|
|
165
|
+
toddle: ctx.toddle,
|
|
166
|
+
env: ctx.env,
|
|
167
|
+
}),
|
|
168
|
+
),
|
|
169
|
+
}),
|
|
170
|
+
)
|
|
171
|
+
|
|
172
|
+
node.variants?.forEach((variant) => {
|
|
173
|
+
Object.entries(variant.customProperties ?? {}).forEach(
|
|
174
|
+
([customPropertyName, { formula }]) => {
|
|
175
|
+
subscribeCustomProperty({
|
|
176
|
+
customPropertyName,
|
|
177
|
+
selector: getNodeSelector(path, {
|
|
178
|
+
variant,
|
|
179
|
+
}),
|
|
180
|
+
variant,
|
|
181
|
+
signal: dataSignal.map((data) =>
|
|
182
|
+
applyFormula(formula, {
|
|
183
|
+
data,
|
|
184
|
+
component: ctx.component,
|
|
185
|
+
formulaCache: ctx.formulaCache,
|
|
186
|
+
root: ctx.root,
|
|
187
|
+
package: ctx.package,
|
|
188
|
+
toddle: ctx.toddle,
|
|
189
|
+
env: ctx.env,
|
|
190
|
+
}),
|
|
191
|
+
),
|
|
192
|
+
})
|
|
193
|
+
},
|
|
194
|
+
)
|
|
195
|
+
})
|
|
196
|
+
|
|
148
197
|
Object.values(node.events).forEach((event) => {
|
|
149
198
|
const handler = (e: Event) => {
|
|
150
199
|
event.actions.forEach((action) => {
|
|
@@ -8,6 +8,7 @@ import type {
|
|
|
8
8
|
Component,
|
|
9
9
|
ComponentData,
|
|
10
10
|
MetaEntry,
|
|
11
|
+
StyleVariant,
|
|
11
12
|
} from '@nordcraft/core/dist/component/component.types'
|
|
12
13
|
import { isPageComponent } from '@nordcraft/core/dist/component/isPageComponent'
|
|
13
14
|
import type {
|
|
@@ -1058,6 +1059,27 @@ export const createRoot = (
|
|
|
1058
1059
|
] ?? { style: {} }
|
|
1059
1060
|
// Add a style element specific to the selected element which
|
|
1060
1061
|
// is only applied when the preview is in design mode
|
|
1062
|
+
const styleVariantCustomProperties = Object.entries(
|
|
1063
|
+
(selectedStyleVariant as StyleVariant).customProperties ?? {},
|
|
1064
|
+
)
|
|
1065
|
+
.map(([customPropertyName, customProperty]) => ({
|
|
1066
|
+
name: customPropertyName,
|
|
1067
|
+
value: applyFormula(customProperty.formula, {
|
|
1068
|
+
data: {
|
|
1069
|
+
Attributes: dataSignal.get().Attributes,
|
|
1070
|
+
Variables: dataSignal.get().Variables,
|
|
1071
|
+
Contexts: ctxDataSignal?.get().Contexts ?? {},
|
|
1072
|
+
},
|
|
1073
|
+
component: getCurrentComponent(),
|
|
1074
|
+
root: ctx?.root,
|
|
1075
|
+
formulaCache: {},
|
|
1076
|
+
package: ctx?.package,
|
|
1077
|
+
toddle: window.toddle,
|
|
1078
|
+
env,
|
|
1079
|
+
} as FormulaContext),
|
|
1080
|
+
}))
|
|
1081
|
+
.filter(({ value }) => value !== undefined)
|
|
1082
|
+
|
|
1061
1083
|
const styleElem = document.createElement('style')
|
|
1062
1084
|
styleElem.setAttribute('data-hash', selectedNodeId)
|
|
1063
1085
|
styleElem.appendChild(
|
|
@@ -1066,6 +1088,11 @@ export const createRoot = (
|
|
|
1066
1088
|
${styleToCss({
|
|
1067
1089
|
...nodeLookup.node.style,
|
|
1068
1090
|
...selectedStyleVariant.style,
|
|
1091
|
+
...Object.fromEntries(
|
|
1092
|
+
styleVariantCustomProperties.map(
|
|
1093
|
+
({ name, value }) => [name, value],
|
|
1094
|
+
),
|
|
1095
|
+
),
|
|
1069
1096
|
})}
|
|
1070
1097
|
}
|
|
1071
1098
|
`),
|