@nordcraft/runtime 1.0.33 → 1.0.35
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 +4 -0
- package/dist/components/createComponent.js.map +1 -1
- package/dist/components/createElement.js +9 -1
- package/dist/components/createElement.js.map +1 -1
- package/dist/components/createNode.js +3 -3
- package/dist/components/createNode.js.map +1 -1
- package/dist/custom-element.main.esm.js +17 -17
- 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/graphql.d.ts +12 -0
- package/dist/editor/graphql.js +150 -0
- package/dist/editor/graphql.js.map +1 -0
- package/dist/editor-preview.main.js +142 -71
- 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 +2 -1
- package/dist/styles/CustomPropertyStyleSheet.js +14 -5
- package/dist/styles/CustomPropertyStyleSheet.js.map +1 -1
- package/dist/styles/CustomPropertyStyleSheet.test.js +7 -7
- package/dist/styles/CustomPropertyStyleSheet.test.js.map +1 -1
- package/dist/utils/subscribeCustomProperty.d.ts +4 -1
- package/dist/utils/subscribeCustomProperty.js +11 -4
- package/dist/utils/subscribeCustomProperty.js.map +1 -1
- package/package.json +3 -3
- package/src/components/createComponent.ts +4 -0
- package/src/components/createElement.ts +10 -1
- package/src/components/createNode.ts +3 -3
- package/src/debug/panicScreen.ts +37 -0
- package/src/debug/sendEditorToast.ts +19 -0
- package/src/editor/graphql.ts +167 -0
- package/src/editor-preview.main.ts +319 -215
- package/src/styles/CustomPropertyStyleSheet.test.ts +7 -7
- package/src/styles/CustomPropertyStyleSheet.ts +22 -5
- package/src/utils/subscribeCustomProperty.ts +25 -12
|
@@ -11,7 +11,7 @@ import type { MediaQuery } from '@nordcraft/core/dist/component/component.types'
|
|
|
11
11
|
export declare class CustomPropertyStyleSheet {
|
|
12
12
|
private styleSheet;
|
|
13
13
|
private ruleMap;
|
|
14
|
-
constructor(styleSheet?: CSSStyleSheet | null);
|
|
14
|
+
constructor(root: Document | ShadowRoot, styleSheet?: CSSStyleSheet | null);
|
|
15
15
|
/**
|
|
16
16
|
* @returns A function to update the property value efficiently.
|
|
17
17
|
*/
|
|
@@ -22,6 +22,7 @@ export declare class CustomPropertyStyleSheet {
|
|
|
22
22
|
unregisterProperty(selector: string, name: string, options?: {
|
|
23
23
|
mediaQuery?: MediaQuery;
|
|
24
24
|
startingStyle?: boolean;
|
|
25
|
+
deepClean?: boolean;
|
|
25
26
|
}): void;
|
|
26
27
|
getStyleSheet(): CSSStyleSheet;
|
|
27
28
|
/**
|
|
@@ -11,13 +11,13 @@ export class CustomPropertyStyleSheet {
|
|
|
11
11
|
styleSheet;
|
|
12
12
|
// Selector to rule index mapping
|
|
13
13
|
ruleMap;
|
|
14
|
-
constructor(styleSheet) {
|
|
14
|
+
constructor(root, styleSheet) {
|
|
15
15
|
if (styleSheet) {
|
|
16
16
|
this.styleSheet = styleSheet;
|
|
17
17
|
}
|
|
18
18
|
else {
|
|
19
19
|
this.styleSheet = new CSSStyleSheet();
|
|
20
|
-
|
|
20
|
+
root.adoptedStyleSheets.push(this.getStyleSheet());
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
@@ -29,7 +29,7 @@ export class CustomPropertyStyleSheet {
|
|
|
29
29
|
// Check if the selector already exists
|
|
30
30
|
let rule = this.ruleMap.get(fullSelector);
|
|
31
31
|
if (!rule) {
|
|
32
|
-
const ruleIndex = this.styleSheet.insertRule(fullSelector);
|
|
32
|
+
const ruleIndex = this.styleSheet.insertRule(fullSelector, this.styleSheet.cssRules.length);
|
|
33
33
|
let newRule = this.styleSheet.cssRules[ruleIndex];
|
|
34
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
35
|
while (newRule.cssRules &&
|
|
@@ -48,8 +48,17 @@ export class CustomPropertyStyleSheet {
|
|
|
48
48
|
return;
|
|
49
49
|
}
|
|
50
50
|
const fullSelector = CustomPropertyStyleSheet.getFullSelector(selector, options);
|
|
51
|
-
|
|
52
|
-
|
|
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
|
+
}
|
|
53
62
|
}
|
|
54
63
|
getStyleSheet() {
|
|
55
64
|
return this.styleSheet;
|
|
@@ -1 +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;
|
|
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,CAAC;YACf,IAAI,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AC,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"}
|
|
@@ -2,18 +2,18 @@ import { describe, expect, test } from 'bun:test';
|
|
|
2
2
|
import { CustomPropertyStyleSheet } from './CustomPropertyStyleSheet';
|
|
3
3
|
describe('CustomPropertyStyleSheet', () => {
|
|
4
4
|
test('it creates a new stylesheet', () => {
|
|
5
|
-
const instance = new CustomPropertyStyleSheet();
|
|
5
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
6
6
|
expect(instance).toBeInstanceOf(CustomPropertyStyleSheet);
|
|
7
7
|
expect(instance.getStyleSheet().cssRules).toHaveLength(0);
|
|
8
8
|
});
|
|
9
9
|
test('it adds a property definition', () => {
|
|
10
|
-
const instance = new CustomPropertyStyleSheet();
|
|
10
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
11
11
|
instance.registerProperty('.my-class', '--my-property');
|
|
12
12
|
expect(instance.getStyleSheet().cssRules.length).toBe(1);
|
|
13
13
|
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { }');
|
|
14
14
|
});
|
|
15
15
|
test('it puts different selectors in different rules', () => {
|
|
16
|
-
const instance = new CustomPropertyStyleSheet();
|
|
16
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
17
17
|
instance.registerProperty('.my-class', '--my-property')('256px');
|
|
18
18
|
instance.registerProperty('.my-other-class', '--my-property')('256px');
|
|
19
19
|
expect(instance.getStyleSheet().cssRules.length).toBe(2);
|
|
@@ -21,7 +21,7 @@ describe('CustomPropertyStyleSheet', () => {
|
|
|
21
21
|
expect(instance.getStyleSheet().cssRules[1].cssText).toBe('.my-other-class { --my-property: 256px; }');
|
|
22
22
|
});
|
|
23
23
|
test('it can update properties', () => {
|
|
24
|
-
const instance = new CustomPropertyStyleSheet();
|
|
24
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
25
25
|
const setter = instance.registerProperty('.my-class', '--my-property');
|
|
26
26
|
setter('256px');
|
|
27
27
|
expect(instance.getStyleSheet().cssRules.length).toBe(1);
|
|
@@ -30,7 +30,7 @@ describe('CustomPropertyStyleSheet', () => {
|
|
|
30
30
|
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { --my-property: inherit; }');
|
|
31
31
|
});
|
|
32
32
|
test('it works with media queries', () => {
|
|
33
|
-
const instance = new CustomPropertyStyleSheet();
|
|
33
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
34
34
|
instance.registerProperty('.my-class', '--my-property', {
|
|
35
35
|
mediaQuery: { 'max-width': '600px' },
|
|
36
36
|
})('256px');
|
|
@@ -38,7 +38,7 @@ describe('CustomPropertyStyleSheet', () => {
|
|
|
38
38
|
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('@media (max-width: 600px) { .my-class { --my-property: 256px; } }');
|
|
39
39
|
});
|
|
40
40
|
test('it unregisters a property', () => {
|
|
41
|
-
const instance = new CustomPropertyStyleSheet();
|
|
41
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
42
42
|
const setter = instance.registerProperty('.my-class', '--my-property');
|
|
43
43
|
setter('256px');
|
|
44
44
|
const setter2 = instance.registerProperty('.my-class', '--my-other-property');
|
|
@@ -50,7 +50,7 @@ describe('CustomPropertyStyleSheet', () => {
|
|
|
50
50
|
expect(instance.getStyleSheet().cssRules[0].cssText).toBe('.my-class { }');
|
|
51
51
|
});
|
|
52
52
|
test('it unregisters a property with media queries', () => {
|
|
53
|
-
const instance = new CustomPropertyStyleSheet();
|
|
53
|
+
const instance = new CustomPropertyStyleSheet(document);
|
|
54
54
|
const setter = instance.registerProperty('.my-class-with-media', '--my-property-with-media', {
|
|
55
55
|
mediaQuery: { 'max-width': '600px' },
|
|
56
56
|
});
|
|
@@ -1 +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,
|
|
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,CAAC,CAAA;IAEF,IAAI,CAAC,+BAA+B,EAAE,GAAG,EAAE;QACzC,MAAM,QAAQ,GAAG,IAAI,wBAAwB,CAAC,QAAQ,CAAC,C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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"}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import type { StyleVariant } from '@nordcraft/core/dist/component/component.types';
|
|
2
2
|
import type { Signal } from '../signal/signal';
|
|
3
|
-
|
|
3
|
+
import type { Runtime } from '@nordcraft/core/dist/types';
|
|
4
|
+
export declare function subscribeCustomProperty({ selector, customPropertyName, signal, variant, root, runtime, }: {
|
|
4
5
|
selector: string;
|
|
5
6
|
customPropertyName: string;
|
|
6
7
|
signal: Signal<string>;
|
|
7
8
|
variant?: StyleVariant;
|
|
9
|
+
root: Document | ShadowRoot;
|
|
10
|
+
runtime: Runtime;
|
|
8
11
|
}): void;
|
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
import { CUSTOM_PROPERTIES_STYLESHEET_ID } from '@nordcraft/core/dist/styling/theme.const';
|
|
2
2
|
import { CustomPropertyStyleSheet } from '../styles/CustomPropertyStyleSheet';
|
|
3
|
-
|
|
4
|
-
export function subscribeCustomProperty({ selector, customPropertyName, signal, variant, }) {
|
|
5
|
-
|
|
6
|
-
|
|
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
|
+
},
|
|
7
14
|
});
|
|
8
15
|
}
|
|
9
16
|
//# sourceMappingURL=subscribeCustomProperty.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subscribeCustomProperty.js","sourceRoot":"","sources":["../../src/utils/subscribeCustomProperty.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,+BAA+B,EAAE,MAAM,0CAA0C,CAAA;
|
|
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.35",
|
|
8
|
+
"@nordcraft/std-lib": "1.0.35",
|
|
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.35"
|
|
25
25
|
}
|
|
@@ -89,6 +89,8 @@ export function createComponent({
|
|
|
89
89
|
})
|
|
90
90
|
}),
|
|
91
91
|
customPropertyName,
|
|
92
|
+
root: ctx.root,
|
|
93
|
+
runtime: ctx.env.runtime,
|
|
92
94
|
}),
|
|
93
95
|
)
|
|
94
96
|
node.variants?.forEach((variant) => {
|
|
@@ -113,6 +115,8 @@ export function createComponent({
|
|
|
113
115
|
),
|
|
114
116
|
customPropertyName,
|
|
115
117
|
variant,
|
|
118
|
+
root: ctx.root,
|
|
119
|
+
runtime: ctx.env.runtime,
|
|
116
120
|
}),
|
|
117
121
|
)
|
|
118
122
|
})
|
|
@@ -154,7 +154,12 @@ export function createElement({
|
|
|
154
154
|
([customPropertyName, { formula }]) =>
|
|
155
155
|
subscribeCustomProperty({
|
|
156
156
|
customPropertyName,
|
|
157
|
-
selector:
|
|
157
|
+
selector:
|
|
158
|
+
ctx.env.runtime === 'custom-element' &&
|
|
159
|
+
ctx.isRootComponent &&
|
|
160
|
+
path === '0'
|
|
161
|
+
? `${getNodeSelector(path)}, :host`
|
|
162
|
+
: getNodeSelector(path),
|
|
158
163
|
signal: dataSignal.map((data) =>
|
|
159
164
|
applyFormula(formula, {
|
|
160
165
|
data,
|
|
@@ -166,6 +171,8 @@ export function createElement({
|
|
|
166
171
|
env: ctx.env,
|
|
167
172
|
}),
|
|
168
173
|
),
|
|
174
|
+
root: ctx.root,
|
|
175
|
+
runtime: ctx.env.runtime,
|
|
169
176
|
}),
|
|
170
177
|
)
|
|
171
178
|
|
|
@@ -189,6 +196,8 @@ export function createElement({
|
|
|
189
196
|
env: ctx.env,
|
|
190
197
|
}),
|
|
191
198
|
),
|
|
199
|
+
root: ctx.root,
|
|
200
|
+
runtime: ctx.env.runtime,
|
|
192
201
|
})
|
|
193
202
|
},
|
|
194
203
|
)
|
|
@@ -121,14 +121,14 @@ export function createNode({
|
|
|
121
121
|
|
|
122
122
|
if (!parentElement || ctx.root.contains(parentElement) === false) {
|
|
123
123
|
console.error(
|
|
124
|
-
`Conditional: Parent element does not exist for "${path}" This is likely due to the DOM being modified outside of
|
|
124
|
+
`Conditional: Parent element does not exist for "${path}" This is likely due to the DOM being modified outside of Nordcraft.`,
|
|
125
125
|
)
|
|
126
126
|
return
|
|
127
127
|
}
|
|
128
128
|
|
|
129
129
|
if (parentElement.querySelector(`[data-id="${path}"]`)) {
|
|
130
130
|
console.warn(
|
|
131
|
-
`Conditional: Element with data-id="${path}" already exists. This is likely due to the DOM being modified outside of
|
|
131
|
+
`Conditional: Element with data-id="${path}" already exists. This is likely due to the DOM being modified outside of Nordcraft`,
|
|
132
132
|
)
|
|
133
133
|
return
|
|
134
134
|
}
|
|
@@ -315,7 +315,7 @@ export function createNode({
|
|
|
315
315
|
|
|
316
316
|
if (!parentElement || ctx.root.contains(parentElement) === false) {
|
|
317
317
|
console.error(
|
|
318
|
-
`Repeat: Parent element does not exist for ${path}. This is likely due to the DOM being modified outside of
|
|
318
|
+
`Repeat: Parent element does not exist for ${path}. This is likely due to the DOM being modified outside of Nordcraft.`,
|
|
319
319
|
)
|
|
320
320
|
return
|
|
321
321
|
}
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createApiRequest,
|
|
3
|
+
HttpMethodsWithAllowedBody,
|
|
4
|
+
} from '@nordcraft/core/dist/api/api'
|
|
5
|
+
import { ApiMethod, type ApiRequest } from '@nordcraft/core/dist/api/apiTypes'
|
|
6
|
+
import type { FormulaContext } from '@nordcraft/core/dist/formula/formula'
|
|
7
|
+
import { PROXY_URL_HEADER } from '@nordcraft/core/dist/utils/url'
|
|
8
|
+
|
|
9
|
+
const INTROSPECTION_QUERY = `\
|
|
10
|
+
query IntrospectionQuery {
|
|
11
|
+
__schema {
|
|
12
|
+
queryType { ...FullType }
|
|
13
|
+
mutationType { ...FullType }
|
|
14
|
+
subscriptionType { ...FullType }
|
|
15
|
+
types {
|
|
16
|
+
...FullType
|
|
17
|
+
}
|
|
18
|
+
directives {
|
|
19
|
+
name
|
|
20
|
+
description
|
|
21
|
+
locations
|
|
22
|
+
args {
|
|
23
|
+
...InputValue
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
fragment FullType on __Type {
|
|
29
|
+
kind
|
|
30
|
+
name
|
|
31
|
+
description
|
|
32
|
+
fields(includeDeprecated: true) {
|
|
33
|
+
name
|
|
34
|
+
description
|
|
35
|
+
args {
|
|
36
|
+
...InputValue
|
|
37
|
+
}
|
|
38
|
+
type {
|
|
39
|
+
...TypeRef
|
|
40
|
+
}
|
|
41
|
+
isDeprecated
|
|
42
|
+
deprecationReason
|
|
43
|
+
}
|
|
44
|
+
inputFields {
|
|
45
|
+
...InputValue
|
|
46
|
+
}
|
|
47
|
+
interfaces {
|
|
48
|
+
...TypeRef
|
|
49
|
+
}
|
|
50
|
+
enumValues(includeDeprecated: true) {
|
|
51
|
+
name
|
|
52
|
+
description
|
|
53
|
+
isDeprecated
|
|
54
|
+
deprecationReason
|
|
55
|
+
}
|
|
56
|
+
possibleTypes {
|
|
57
|
+
...TypeRef
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
fragment InputValue on __InputValue {
|
|
61
|
+
name
|
|
62
|
+
description
|
|
63
|
+
type { ...TypeRef }
|
|
64
|
+
defaultValue
|
|
65
|
+
}
|
|
66
|
+
fragment TypeRef on __Type {
|
|
67
|
+
kind
|
|
68
|
+
name
|
|
69
|
+
ofType {
|
|
70
|
+
kind
|
|
71
|
+
name
|
|
72
|
+
ofType {
|
|
73
|
+
kind
|
|
74
|
+
name
|
|
75
|
+
ofType {
|
|
76
|
+
kind
|
|
77
|
+
name
|
|
78
|
+
ofType {
|
|
79
|
+
kind
|
|
80
|
+
name
|
|
81
|
+
ofType {
|
|
82
|
+
kind
|
|
83
|
+
name
|
|
84
|
+
ofType {
|
|
85
|
+
kind
|
|
86
|
+
name
|
|
87
|
+
ofType {
|
|
88
|
+
kind
|
|
89
|
+
name
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
}`
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Run an introspection query for an existing API
|
|
101
|
+
* The introspection will usually be a POST request, but we use the method
|
|
102
|
+
* from the original API to support other methods.
|
|
103
|
+
*/
|
|
104
|
+
export const introspectApiRequest = async ({
|
|
105
|
+
api,
|
|
106
|
+
componentName,
|
|
107
|
+
formulaContext,
|
|
108
|
+
}: {
|
|
109
|
+
api: ApiRequest
|
|
110
|
+
componentName: string
|
|
111
|
+
formulaContext: FormulaContext
|
|
112
|
+
}) => {
|
|
113
|
+
const { url, requestSettings } = createApiRequest({
|
|
114
|
+
api: {
|
|
115
|
+
...(api as ApiRequest),
|
|
116
|
+
// Default to a POST request if the method of the original API doesn't support a body
|
|
117
|
+
// The introspection query should never be initiated in that case though
|
|
118
|
+
method: HttpMethodsWithAllowedBody.includes(api.method ?? ApiMethod.POST)
|
|
119
|
+
? api.method
|
|
120
|
+
: ApiMethod.POST,
|
|
121
|
+
// Overwrite the body with a default introspection query (in a value formula)
|
|
122
|
+
body: {
|
|
123
|
+
type: 'value',
|
|
124
|
+
value: { query: INTROSPECTION_QUERY },
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
baseUrl: window.origin,
|
|
128
|
+
defaultHeaders: undefined,
|
|
129
|
+
formulaContext,
|
|
130
|
+
})
|
|
131
|
+
// We must proxy to be able to include cookies
|
|
132
|
+
const proxyUrl = `/.toddle/omvej/components/${encodeURIComponent(
|
|
133
|
+
componentName,
|
|
134
|
+
)}/apis/${encodeURIComponent(componentName)}:${encodeURIComponent(api.name)}`
|
|
135
|
+
const headers = new Headers(requestSettings.headers)
|
|
136
|
+
headers.set(
|
|
137
|
+
PROXY_URL_HEADER,
|
|
138
|
+
decodeURIComponent(url.href.replace(/\+/g, ' ')),
|
|
139
|
+
)
|
|
140
|
+
requestSettings.headers = headers
|
|
141
|
+
const response = await fetch(proxyUrl, {
|
|
142
|
+
...requestSettings,
|
|
143
|
+
// Set credentials to what was set on the original API
|
|
144
|
+
credentials:
|
|
145
|
+
api.client?.credentials &&
|
|
146
|
+
['include', 'same-origin', 'omit'].includes(api.client.credentials)
|
|
147
|
+
? api.client.credentials
|
|
148
|
+
: // Default to same-origin
|
|
149
|
+
undefined,
|
|
150
|
+
})
|
|
151
|
+
try {
|
|
152
|
+
const data = await response.json()
|
|
153
|
+
if (response.ok) {
|
|
154
|
+
return data
|
|
155
|
+
} else {
|
|
156
|
+
// eslint-disable-next-line no-console
|
|
157
|
+
console.error('Failed to introspect API:', api.name, data)
|
|
158
|
+
// Return a generic error message if introspection failed
|
|
159
|
+
return { error: data?.message ?? 'Failed to parse introspection result' }
|
|
160
|
+
}
|
|
161
|
+
} catch (e) {
|
|
162
|
+
// eslint-disable-next-line no-console
|
|
163
|
+
console.error('Failed to parses API response:', api.name, e)
|
|
164
|
+
// Return a generic error message if introspection failed
|
|
165
|
+
return { error: `Failed to introspect API: ${api.name}` }
|
|
166
|
+
}
|
|
167
|
+
}
|