@nordcraft/runtime 1.0.32 → 1.0.34
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 +44 -0
- package/dist/components/createComponent.js.map +1 -1
- package/dist/components/createElement.js +47 -3
- package/dist/components/createElement.js.map +1 -1
- package/dist/custom-element.main.esm.js +31 -25
- package/dist/custom-element.main.esm.js.map +4 -4
- package/dist/debug/panicScreen.d.ts +6 -0
- package/dist/debug/panicScreen.js +25 -0
- package/dist/debug/panicScreen.js.map +1 -0
- package/dist/debug/sendEditorToast.d.ts +3 -0
- package/dist/debug/sendEditorToast.js +9 -0
- package/dist/debug/sendEditorToast.js.map +1 -0
- package/dist/editor-preview.main.js +84 -29
- 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 +35 -0
- package/dist/styles/CustomPropertyStyleSheet.js +118 -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 +11 -0
- package/dist/utils/subscribeCustomProperty.js +16 -0
- package/dist/utils/subscribeCustomProperty.js.map +1 -0
- package/package.json +3 -3
- package/src/components/createComponent.ts +52 -0
- package/src/components/createElement.ts +61 -3
- package/src/debug/panicScreen.ts +37 -0
- package/src/debug/sendEditorToast.ts +19 -0
- package/src/editor-preview.main.ts +108 -40
- package/src/styles/CustomPropertyStyleSheet.test.ts +104 -0
- package/src/styles/CustomPropertyStyleSheet.ts +180 -0
- package/src/styles/style.ts +33 -0
- package/src/utils/omitStyle.ts +10 -2
- package/src/utils/subscribeCustomProperty.ts +54 -0
|
@@ -0,0 +1,35 @@
|
|
|
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(root: Document | ShadowRoot, 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
|
+
deepClean?: boolean;
|
|
26
|
+
}): void;
|
|
27
|
+
getStyleSheet(): CSSStyleSheet;
|
|
28
|
+
/**
|
|
29
|
+
* Maps all selectors to their rule index. This is used to map the initial
|
|
30
|
+
* SSR style variable values to their selectors.
|
|
31
|
+
*/
|
|
32
|
+
private hydrateFromBase;
|
|
33
|
+
private static selectorFromCSSRule;
|
|
34
|
+
private static getFullSelector;
|
|
35
|
+
}
|
|
@@ -0,0 +1,118 @@
|
|
|
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(root, styleSheet) {
|
|
15
|
+
if (styleSheet) {
|
|
16
|
+
this.styleSheet = styleSheet;
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
this.styleSheet = new CSSStyleSheet();
|
|
20
|
+
root.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, this.styleSheet.cssRules.length);
|
|
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
|
+
const rule = this.ruleMap.get(fullSelector);
|
|
52
|
+
if (!rule) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
rule.style.removeProperty(name);
|
|
56
|
+
// Cleaning up empty selectors is probably not necessary in production and may have performance implications.
|
|
57
|
+
// However, it is required for the editor-preview as it is a dynamic environment and things may get reordered and canvas reused.
|
|
58
|
+
if (options?.deepClean && rule.style.length === 0) {
|
|
59
|
+
this.styleSheet.deleteRule(Array.from(this.ruleMap.keys()).indexOf(fullSelector));
|
|
60
|
+
this.ruleMap.delete(fullSelector);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
getStyleSheet() {
|
|
64
|
+
return this.styleSheet;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Maps all selectors to their rule index. This is used to map the initial
|
|
68
|
+
* SSR style variable values to their selectors.
|
|
69
|
+
*/
|
|
70
|
+
hydrateFromBase() {
|
|
71
|
+
const ruleIndex = new Map();
|
|
72
|
+
for (let i = 0; i < this.styleSheet.cssRules.length; i++) {
|
|
73
|
+
let rule = this.styleSheet.cssRules[i];
|
|
74
|
+
const selector = CustomPropertyStyleSheet.selectorFromCSSRule(rule);
|
|
75
|
+
// Get last part of the selector, which is the actual selector we are interested in
|
|
76
|
+
while (rule.cssRules &&
|
|
77
|
+
rule.cssRules.length > 0) {
|
|
78
|
+
rule = rule.cssRules[0];
|
|
79
|
+
}
|
|
80
|
+
ruleIndex.set(selector, rule);
|
|
81
|
+
}
|
|
82
|
+
return ruleIndex;
|
|
83
|
+
}
|
|
84
|
+
static selectorFromCSSRule(rule) {
|
|
85
|
+
switch (rule.constructor.name) {
|
|
86
|
+
case 'CSSStyleRule':
|
|
87
|
+
// For these rules, we just return (potentially with subrules if any cssRules exist)
|
|
88
|
+
return `${rule.selectorText} { ${Array.from(rule.cssRules)
|
|
89
|
+
.map(CustomPropertyStyleSheet.selectorFromCSSRule)
|
|
90
|
+
.join(', ')}}`;
|
|
91
|
+
case 'CSSStartingStyleRule':
|
|
92
|
+
return `@starting-style { ${Array.from(rule.cssRules)
|
|
93
|
+
.map(CustomPropertyStyleSheet.selectorFromCSSRule)
|
|
94
|
+
.join(', ')}}`;
|
|
95
|
+
case 'CSSMediaRule':
|
|
96
|
+
return `@media ${rule.media.mediaText} { ${Array.from(rule.cssRules)
|
|
97
|
+
.map(CustomPropertyStyleSheet.selectorFromCSSRule)
|
|
98
|
+
.join(', ')}}`;
|
|
99
|
+
case 'CSSNestedDeclarations':
|
|
100
|
+
return '';
|
|
101
|
+
default:
|
|
102
|
+
// eslint-disable-next-line no-console
|
|
103
|
+
console.warn(`Unsupported CSS rule type: ${rule.constructor.name}. Returning empty selector.`);
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
static getFullSelector(selector, options) {
|
|
108
|
+
let result = selector + (options?.startingStyle ? ' { @starting-style { }}' : ' { }');
|
|
109
|
+
if (options?.mediaQuery) {
|
|
110
|
+
result = `@media (${Object.entries(options.mediaQuery)
|
|
111
|
+
.map(([key, value]) => `${key}: ${value}`)
|
|
112
|
+
.filter(Boolean)
|
|
113
|
+
.join(') and (')}) { ${result}}`;
|
|
114
|
+
}
|
|
115
|
+
return result;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
//# 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,IAA2B,EAAE,UAAiC;QACxE,IAAI,UAAU,EAAE,C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AAC,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(document);
|
|
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(document);
|
|
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(document);
|
|
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(document);
|
|
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(document);
|
|
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(document);
|
|
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(document);
|
|
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,CAAC,QAAQ,CAAC,CAAA;QACvD,MAAM,CAAC,QAAQ,CAAC,CAAC,cAAc,CAAC,wBAAwB,CAAC,CAAA;QACzD,MAAM,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,CAAA;IAC3D,CAAC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ACvD,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,cAAc;IACd,gBAAgB;IAChB,eAAe;IACf,KAAK;IACL,OAAO;IACP,OAAO;IACP,e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G;QACL,MAAM;MACR,CAAA;IACJ,CAAC;IAED,OAAO;IACL,QAAQ;MACN,MAAM;;EAGV,eAAe,CAAC,MAAM,GAAG,CAAC;QACxB,CAAC,CAAC;IACF,QAAQ;MACN,eAAe;aACd,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,KAAK,CAAC,EAAE,EAAE;YAClB,QAAQ,KAAK,EAAE,CAAC;gBACd,KAAK,MAAM;oBACT,OAAO,WAAW,CAAA;gBACpB,KAAK,MAAM;oBACT,OAAO,YAAY,CAAA;gBACrB;oBACE,OAAO,EAAE,CAAA;YACb,CAAC;QACH,CAAC,CAAC;aACD,IAAI,CAAC,IAAI,CAAC;;CAEhB;QACG,CAAC,CAAC,EACN;CACC,CAAA;AACD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,UAAU,GAAG,CAAC,KAAqB,EAAE,EAAE;IAClD,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC;SACzB,GAAG,CAAC,CAAC,CAAC,QAAQ,EAAE,KAAK,CAAC,EAAE,EAAE;QACzB,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAA;QACxC,MAAM,aAAa,GACjB,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,KAAK,MAAM,CAAC,KAAK,CAAC;YACvC,eAAe,CAAC,GAAG,CAAC,YAAY,CAAC;YAC/B,CAAC,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI;YAC1B,CAAC,CAAC,KAAK,CAAA;QACX,OAAO,GAAG,YAAY,IAAI,aAAa,GAAG,CAAA;IAC5C,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAA;AACf,CAAC,CAAA"}
|
package/dist/utils/omitStyle.js
CHANGED
|
@@ -4,8 +4,10 @@ export function omitSubnodeStyleForComponent(component) {
|
|
|
4
4
|
if ((node.type === '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,11 @@
|
|
|
1
|
+
import type { StyleVariant } from '@nordcraft/core/dist/component/component.types';
|
|
2
|
+
import type { Signal } from '../signal/signal';
|
|
3
|
+
import type { Runtime } from '@nordcraft/core/dist/types';
|
|
4
|
+
export declare function subscribeCustomProperty({ selector, customPropertyName, signal, variant, root, runtime, }: {
|
|
5
|
+
selector: string;
|
|
6
|
+
customPropertyName: string;
|
|
7
|
+
signal: Signal<string>;
|
|
8
|
+
variant?: StyleVariant;
|
|
9
|
+
root: Document | ShadowRoot;
|
|
10
|
+
runtime: Runtime;
|
|
11
|
+
}): void;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { CUSTOM_PROPERTIES_STYLESHEET_ID } from '@nordcraft/core/dist/styling/theme.const';
|
|
2
|
+
import { CustomPropertyStyleSheet } from '../styles/CustomPropertyStyleSheet';
|
|
3
|
+
let customPropertiesStylesheet;
|
|
4
|
+
export function subscribeCustomProperty({ selector, customPropertyName, signal, variant, root, runtime, }) {
|
|
5
|
+
customPropertiesStylesheet ??= new CustomPropertyStyleSheet(root, root.getElementById(CUSTOM_PROPERTIES_STYLESHEET_ID)?.sheet);
|
|
6
|
+
signal.subscribe(customPropertiesStylesheet.registerProperty(selector, customPropertyName, variant), {
|
|
7
|
+
destroy: () => {
|
|
8
|
+
customPropertiesStylesheet?.unregisterProperty(selector, customPropertyName, {
|
|
9
|
+
deepClean: runtime === 'preview',
|
|
10
|
+
mediaQuery: variant?.mediaQuery,
|
|
11
|
+
startingStyle: variant?.startingStyle,
|
|
12
|
+
});
|
|
13
|
+
},
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
//# 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;AAE1F,OAAO,EAAE,wBAAwB,EAAE,MAAM,oCAAoC,CAAA;AAE7E,IAAI,0BAAgE,CAAA;AAEpE,MAAM,UAAU,uBAAuB,CAAC,EACtC,QAAQ,EACR,kBAAkB,EAClB,MAAM,EACN,OAAO,EACP,IAAI,EACJ,OAAO,GAQR;IACC,0BAA0B,KAAK,IAAI,wBAAwB,CACzD,IAAI,EAEF,IAAI,CAAC,cAAc,CAAC,+BAA+B,CAGpD,EAAE,KAAK,CACT,CAAA;IAED,MAAM,CAAC,SAAS,CACd,0BAA0B,CAAC,gBAAgB,CACzC,QAAQ,EACR,kBAAkB,EAClB,OAAO,CACR,EACD;QACE,OAAO,EAAE,GAAG,EAAE;YACZ,0BAA0B,EAAE,kBAAkB,CAC5C,QAAQ,EACR,kBAAkB,EAClB;gBACE,SAAS,EAAE,OAAO,KAAK,SAAS;gBAChC,UAAU,EAAE,OAAO,EAAE,UAAU;gBAC/B,aAAa,EAAE,OAAO,EAAE,aAAa;aACtC,CACF,CAAA;QACH,CAAC;KACF,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.34",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.34",
|
|
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.34"
|
|
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,56 @@ 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
|
+
root: ctx.root,
|
|
93
|
+
runtime: ctx.env.runtime,
|
|
94
|
+
}),
|
|
95
|
+
)
|
|
96
|
+
node.variants?.forEach((variant) => {
|
|
97
|
+
Object.entries(variant.customProperties ?? {}).forEach(
|
|
98
|
+
([customPropertyName, customProperty]) =>
|
|
99
|
+
subscribeCustomProperty({
|
|
100
|
+
selector: getNodeSelector(path, {
|
|
101
|
+
componentName: ctx.component.name,
|
|
102
|
+
nodeId: node.id,
|
|
103
|
+
variant,
|
|
104
|
+
}),
|
|
105
|
+
signal: dataSignal.map((data) =>
|
|
106
|
+
applyFormula(customProperty.formula, {
|
|
107
|
+
data,
|
|
108
|
+
component: ctx.component,
|
|
109
|
+
formulaCache: ctx.formulaCache,
|
|
110
|
+
root: ctx.root,
|
|
111
|
+
package: ctx.package,
|
|
112
|
+
toddle: ctx.toddle,
|
|
113
|
+
env: ctx.env,
|
|
114
|
+
}),
|
|
115
|
+
),
|
|
116
|
+
customPropertyName,
|
|
117
|
+
variant,
|
|
118
|
+
root: ctx.root,
|
|
119
|
+
runtime: ctx.env.runtime,
|
|
120
|
+
}),
|
|
121
|
+
)
|
|
122
|
+
})
|
|
71
123
|
|
|
72
124
|
const componentDataSignal = signal<ComponentData>({
|
|
73
125
|
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,63 @@ 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))
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
Object.entries(node.customProperties ?? {}).forEach(
|
|
154
|
+
([customPropertyName, { formula }]) =>
|
|
155
|
+
subscribeCustomProperty({
|
|
156
|
+
customPropertyName,
|
|
157
|
+
selector:
|
|
158
|
+
ctx.env.runtime === 'custom-element' &&
|
|
159
|
+
ctx.isRootComponent &&
|
|
160
|
+
path === '0'
|
|
161
|
+
? `${getNodeSelector(path)}, :host`
|
|
162
|
+
: getNodeSelector(path),
|
|
163
|
+
signal: dataSignal.map((data) =>
|
|
164
|
+
applyFormula(formula, {
|
|
165
|
+
data,
|
|
166
|
+
component: ctx.component,
|
|
167
|
+
formulaCache: ctx.formulaCache,
|
|
168
|
+
root: ctx.root,
|
|
169
|
+
package: ctx.package,
|
|
170
|
+
toddle: ctx.toddle,
|
|
171
|
+
env: ctx.env,
|
|
172
|
+
}),
|
|
173
|
+
),
|
|
174
|
+
root: ctx.root,
|
|
175
|
+
runtime: ctx.env.runtime,
|
|
176
|
+
}),
|
|
177
|
+
)
|
|
178
|
+
|
|
179
|
+
node.variants?.forEach((variant) => {
|
|
180
|
+
Object.entries(variant.customProperties ?? {}).forEach(
|
|
181
|
+
([customPropertyName, { formula }]) => {
|
|
182
|
+
subscribeCustomProperty({
|
|
183
|
+
customPropertyName,
|
|
184
|
+
selector: getNodeSelector(path, {
|
|
185
|
+
variant,
|
|
186
|
+
}),
|
|
187
|
+
variant,
|
|
188
|
+
signal: dataSignal.map((data) =>
|
|
189
|
+
applyFormula(formula, {
|
|
190
|
+
data,
|
|
191
|
+
component: ctx.component,
|
|
192
|
+
formulaCache: ctx.formulaCache,
|
|
193
|
+
root: ctx.root,
|
|
194
|
+
package: ctx.package,
|
|
195
|
+
toddle: ctx.toddle,
|
|
196
|
+
env: ctx.env,
|
|
197
|
+
}),
|
|
198
|
+
),
|
|
199
|
+
root: ctx.root,
|
|
200
|
+
runtime: ctx.env.runtime,
|
|
201
|
+
})
|
|
202
|
+
},
|
|
203
|
+
)
|
|
147
204
|
})
|
|
205
|
+
|
|
148
206
|
Object.values(node.events).forEach((event) => {
|
|
149
207
|
const handler = (e: Event) => {
|
|
150
208
|
event.actions.forEach((action) => {
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export const createPanicScreen = ({
|
|
2
|
+
name,
|
|
3
|
+
message,
|
|
4
|
+
isPage,
|
|
5
|
+
cause,
|
|
6
|
+
}: {
|
|
7
|
+
name: string
|
|
8
|
+
message: string
|
|
9
|
+
isPage?: boolean
|
|
10
|
+
cause?: unknown
|
|
11
|
+
}) => {
|
|
12
|
+
let content = getContent(name, message, isPage)
|
|
13
|
+
|
|
14
|
+
// Easter egg for RangeError
|
|
15
|
+
if (cause instanceof RangeError) {
|
|
16
|
+
for (let i = 0; i < 10; i++) {
|
|
17
|
+
content += `<div style="transform-origin: 15% 15%; scale: ${1 / (i * 0.225 + 1.225)}; font-size: ${22 / ((i * 0.6) ** 2 + 1)}px">${getContent(name, message, isPage)}</div>`
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return document.createRange().createContextualFragment(`
|
|
22
|
+
<main style="background-color: blue; color: white; font-family: 'Courier New', monospace; font-weight: 100; display: flex; justify-content: flex-start; align-items: flex-start; margin: 0px; padding: 0px;">
|
|
23
|
+
<div style="display: flex; flex-direction: column; justify-content: space-between; align-items: flex-start; height: 100vh;">
|
|
24
|
+
<div style="display: flex; flex-direction: column; gap: 20px; padding: 80px; font-size: 22px;">
|
|
25
|
+
${content}
|
|
26
|
+
</div>
|
|
27
|
+
</div>
|
|
28
|
+
<div style="position:fixed; pointer-events: none; width: 100vw; height: 100vh; background-image: linear-gradient(0deg, rgba(0,0,0,0) 25%, rgba(0,0,0,0.33) 25%, rgba(0,0,0,0.33) 50%, rgba(0,0,0,0) 50%, rgba(0,0,0,0) 75%, rgba(0,0,0,0.33) 75%, rgba(0,0,0,0.33) 100%); background-size: 4px 4px;"></div>
|
|
29
|
+
<div style="position:fixed; pointer-events: none; width: 100vw; height: 100vh; background-image: radial-gradient(ellipse at center, rgba(0,0,0,0) 50%, rgba(0,0,0,0.25) 100%);"></div>
|
|
30
|
+
</main>
|
|
31
|
+
`)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const getContent = (name: string, message: string, isPage?: boolean) => `
|
|
35
|
+
<h1 style="display: inline; font-size: 1em; background: white; color: blue; padding: 0.4em 0.8em;">${name}</h1>
|
|
36
|
+
<p style="font-size: 0.8em;">The ${isPage ? 'page' : 'component'} could not be rendered. Fix the issue and try again. Join our <a style="color:white" href="https://discord.gg/nordcraft" target="_blank">Discord</a> for help.</p>
|
|
37
|
+
<p style="font-size: 0.81em;">Error Message: ${message}</p>`
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export function sendEditorToast(
|
|
2
|
+
title: string,
|
|
3
|
+
message: string,
|
|
4
|
+
{
|
|
5
|
+
type = 'neutral',
|
|
6
|
+
}: {
|
|
7
|
+
type?: 'neutral' | 'warning' | 'critical'
|
|
8
|
+
},
|
|
9
|
+
) {
|
|
10
|
+
window.parent?.postMessage(
|
|
11
|
+
{
|
|
12
|
+
type: 'emitToast',
|
|
13
|
+
toastType: type,
|
|
14
|
+
title,
|
|
15
|
+
message,
|
|
16
|
+
},
|
|
17
|
+
'*',
|
|
18
|
+
)
|
|
19
|
+
}
|