@nordcraft/runtime 1.0.58 → 1.0.59

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.
@@ -35,7 +35,10 @@ describe('CustomPropertyStyleSheet', () => {
35
35
  mediaQuery: { 'max-width': '600px' },
36
36
  })('256px');
37
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; } }');
38
+ expect(instance.getStyleSheet().cssRules[0].cssText).toBe(`\
39
+ @media (max-width: 600px) {
40
+ .my-class { --my-property: 256px; }
41
+ }`);
39
42
  });
40
43
  test('it unregisters a property', () => {
41
44
  const instance = new CustomPropertyStyleSheet(document);
@@ -56,11 +59,17 @@ describe('CustomPropertyStyleSheet', () => {
56
59
  });
57
60
  setter('256px');
58
61
  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; } }');
62
+ expect(instance.getStyleSheet().cssRules[0].cssText).toBe(`\
63
+ @media (max-width: 600px) {
64
+ .my-class-with-media { --my-property-with-media: 256px; }
65
+ }`);
60
66
  instance.unregisterProperty('.my-class-with-media', '--my-property-with-media', {
61
67
  mediaQuery: { 'max-width': '600px' },
62
68
  });
63
- expect(instance.getStyleSheet().cssRules[0].cssText).toBe('@media (max-width: 600px) { .my-class-with-media { } }');
69
+ expect(instance.getStyleSheet().cssRules[0].cssText).toBe(`\
70
+ @media (max-width: 600px) {
71
+ .my-class-with-media { }
72
+ }`);
64
73
  });
65
74
  });
66
75
  //# sourceMappingURL=CustomPropertyStyleSheet.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"CustomPropertyStyleSheet.test.js","sourceRoot":"","sources":["../../src/styles/CustomPropertyStyleSheet.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,EAA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Q,CAAC,aAAa,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CACvD;;;EAGJ,CACG,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;;;EAGJ,CACG,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
package/package.json CHANGED
@@ -4,13 +4,13 @@
4
4
  "type": "module",
5
5
  "homepage": "https://github.com/nordcraftengine/nordcraft",
6
6
  "dependencies": {
7
- "@nordcraft/core": "1.0.58",
8
- "@nordcraft/std-lib": "1.0.58",
7
+ "@nordcraft/core": "1.0.59",
8
+ "@nordcraft/std-lib": "1.0.59",
9
9
  "fast-deep-equal": "3.1.3",
10
10
  "path-to-regexp": "6.3.0"
11
11
  },
12
12
  "devDependencies": {
13
- "@happy-dom/global-registrator": "18.0.1"
13
+ "@happy-dom/global-registrator": "20.0.8"
14
14
  },
15
15
  "scripts": {
16
16
  "build": "tsc && bun scripts/build.js",
@@ -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.58"
24
+ "version": "1.0.59"
25
25
  }
@@ -42,7 +42,7 @@ export function createElement({
42
42
  }
43
43
 
44
44
  // Explicitly setting a namespace has precedence over inferring it from the tag
45
- if (node.attrs['xmlns'] && node.attrs['xmlns'].type === 'value') {
45
+ if (node.attrs['xmlns']?.type === 'value') {
46
46
  namespace = String(node.attrs['xmlns'].value) as SupportedNamespaces
47
47
  }
48
48
 
@@ -216,7 +216,6 @@ export function createNode({
216
216
  Key,
217
217
  },
218
218
  }
219
-
220
219
  let childKey = node.repeatKey
221
220
  ? applyFormula(node.repeatKey, {
222
221
  data: childData,
@@ -0,0 +1,17 @@
1
+ export const isInputTarget = (event: Event) => {
2
+ const target = event.target
3
+ if (target instanceof HTMLElement) {
4
+ if (
5
+ target.tagName === 'INPUT' ||
6
+ target.tagName === 'TEXTAREA' ||
7
+ target.tagName === 'SELECT' ||
8
+ target.tagName === 'STYLE-EDITOR'
9
+ ) {
10
+ return true
11
+ }
12
+ if (target.contentEditable?.toLocaleLowerCase() === 'true') {
13
+ return true
14
+ }
15
+ }
16
+ return false
17
+ }
@@ -0,0 +1,16 @@
1
+ import type { Component } from '@nordcraft/core/dist/component/component.types'
2
+ import { valueFormula } from '@nordcraft/core/dist/formula/formulaUtils'
3
+
4
+ /**
5
+ * Modifies all link nodes on a component
6
+ * NOTE: alters in place
7
+ */
8
+ export const updateComponentLinks = (component: Component) => {
9
+ // Find all links and add target="_blank" to them
10
+ Object.entries(component.nodes ?? {}).forEach(([_, node]) => {
11
+ if (node.type === 'element' && node.tag === 'a') {
12
+ node.attrs['target'] = valueFormula('_blank')
13
+ }
14
+ })
15
+ return component
16
+ }
@@ -0,0 +1,21 @@
1
+ export function getRectData(selectedNode: Element | null | undefined) {
2
+ if (!selectedNode) {
3
+ return null
4
+ }
5
+
6
+ const { borderRadius, rotate } = window.getComputedStyle(selectedNode)
7
+ const rect: DOMRect = selectedNode.getBoundingClientRect()
8
+
9
+ return {
10
+ left: rect.left,
11
+ right: rect.right,
12
+ top: rect.top,
13
+ bottom: rect.bottom,
14
+ width: rect.width,
15
+ height: rect.height,
16
+ x: rect.x,
17
+ y: rect.y,
18
+ borderRadius: borderRadius.split(' '),
19
+ rotate,
20
+ }
21
+ }
@@ -0,0 +1,271 @@
1
+ import type {
2
+ AnimationKeyframe,
3
+ Component,
4
+ ComponentData,
5
+ } from '@nordcraft/core/dist/component/component.types'
6
+ import type { PluginFormula } from '@nordcraft/core/dist/formula/formulaTypes'
7
+ import type { OldTheme, Theme } from '@nordcraft/core/dist/styling/theme'
8
+ import type {
9
+ FormulaHandlerV2,
10
+ PluginAction,
11
+ PluginActionV2,
12
+ } from '@nordcraft/core/dist/types'
13
+ import type { getRectData } from './overlay'
14
+
15
+ export type NordcraftPreviewEvent =
16
+ | {
17
+ type: 'style_variant_changed'
18
+ variantIndex: number | null
19
+ }
20
+ | {
21
+ type: 'component'
22
+ component: Component
23
+ }
24
+ | { type: 'components'; components: Component[] }
25
+ | {
26
+ type: 'packages'
27
+ packages: Record<
28
+ string,
29
+ {
30
+ components: Record<string, Component>
31
+ formulas: Record<
32
+ string,
33
+ PluginFormula<FormulaHandlerV2> | PluginFormula<string>
34
+ >
35
+ actions: Record<string, PluginActionV2 | PluginAction>
36
+ manifest: {
37
+ name: string
38
+ // commit represents the commit hash (version) of the package
39
+ commit: string
40
+ }
41
+ }
42
+ >
43
+ }
44
+ | {
45
+ type: 'global_formulas'
46
+ formulas: Record<
47
+ string,
48
+ PluginFormula<FormulaHandlerV2> | PluginFormula<string>
49
+ >
50
+ }
51
+ | {
52
+ type: 'global_actions'
53
+ actions: Record<string, PluginActionV2 | PluginAction>
54
+ }
55
+ | { type: 'theme'; theme: Record<string, OldTheme | Theme> }
56
+ | { type: 'mode'; mode: 'design' | 'test' }
57
+ | { type: 'attrs'; attrs: Record<string, unknown> }
58
+ | { type: 'selection'; selectedNodeId: string | null }
59
+ | { type: 'highlight'; highlightedNodeId: string | null }
60
+ | {
61
+ type: 'click' | 'mousemove' | 'dblclick'
62
+ metaKey: boolean
63
+ x: number
64
+ y: number
65
+ }
66
+ | { type: 'report_document_scroll_size' }
67
+ | { type: 'update_inner_text'; innerText: string }
68
+ | { type: 'reload' }
69
+ | { type: 'fetch_api'; apiKey: string }
70
+ | { type: 'introspect_qraphql_api'; apiKey: string }
71
+ | { type: 'drag-started'; x: number; y: number }
72
+ | { type: 'drag-ended'; canceled?: true }
73
+ | { type: 'keydown'; key: string; altKey: boolean; metaKey: boolean }
74
+ | { type: 'keyup'; key: string; altKey: boolean; metaKey: boolean }
75
+ | {
76
+ type: 'get_computed_style'
77
+ styles?: string[]
78
+ }
79
+ | {
80
+ type: 'set_timeline_keyframes'
81
+ keyframes: Record<string, AnimationKeyframe> | null
82
+ }
83
+ | {
84
+ type: 'set_timeline_time'
85
+ time: number | null
86
+ timingFunction:
87
+ | 'linear'
88
+ | 'ease'
89
+ | 'ease-in'
90
+ | 'ease-out'
91
+ | 'ease-in-out'
92
+ | 'step-start'
93
+ | 'step-end'
94
+ | string
95
+ | undefined
96
+ fillMode: 'none' | 'forwards' | 'backwards' | 'both' | undefined
97
+ }
98
+ | {
99
+ type: 'preview_style'
100
+ styles: Record<string, string> | null
101
+ theme?: {
102
+ key: string
103
+ value: Theme
104
+ }
105
+ }
106
+ | {
107
+ type: 'preview_theme'
108
+ theme: string | null
109
+ }
110
+
111
+ export type EditorPostMessageType =
112
+ | {
113
+ type: 'textComputedStyle'
114
+ computedStyle: Record<string, string>
115
+ }
116
+ | {
117
+ type: 'selection'
118
+ selectedNodeId: string | null
119
+ }
120
+ | {
121
+ type: 'highlight'
122
+ highlightedNodeId: string | null
123
+ }
124
+ | {
125
+ type: 'navigate'
126
+ name: string
127
+ }
128
+ | {
129
+ type: 'documentScrollSize'
130
+ scrollHeight: number
131
+ scrollWidth: number
132
+ }
133
+ | {
134
+ type: 'nodeMoved'
135
+ copy: boolean
136
+ parent?: string | null
137
+ index?: number
138
+ }
139
+ | {
140
+ type: 'computedStyle'
141
+ computedStyle: Record<string, string>
142
+ }
143
+ | {
144
+ type: 'style'
145
+ time: string
146
+ }
147
+ | {
148
+ type: 'component event'
149
+ event: any
150
+ time: string
151
+ data: any
152
+ }
153
+ | {
154
+ type: 'keydown'
155
+ event: {
156
+ key: string
157
+ metaKey: boolean
158
+ shiftKey: boolean
159
+ altKey: boolean
160
+ }
161
+ }
162
+ | {
163
+ type: 'keyup'
164
+ event: {
165
+ key: string
166
+ metaKey: boolean
167
+ shiftKey: boolean
168
+ altKey: boolean
169
+ }
170
+ }
171
+ | {
172
+ type: 'keypress'
173
+ event: {
174
+ key: string
175
+ metaKey: boolean
176
+ shiftKey: boolean
177
+ altKey: boolean
178
+ }
179
+ }
180
+ | { type: 'data'; data: ComponentData }
181
+ | {
182
+ type: 'selectionRect'
183
+ rect: ReturnType<typeof getRectData>
184
+ }
185
+ | {
186
+ type: 'highlightRect'
187
+ rect: ReturnType<typeof getRectData>
188
+ }
189
+ | {
190
+ type: 'introspectionResult'
191
+ data: any
192
+ apiKey: string
193
+ }
194
+
195
+ export type DragState = {
196
+ /**
197
+ * Dragging elements within the initial container is a reorder operation while dragging elements outside the initial container is an insert operation.
198
+ * While they share some common properties, we need to differentiate between the two to handle them differently.
199
+ */
200
+ mode: 'reorder' | 'insert'
201
+ elementType: 'element' | 'component' | 'text'
202
+ copy?: HTMLElement
203
+ element: HTMLElement
204
+ repeatedNodes: HTMLElement[]
205
+ offset: Point
206
+ lastCursorPosition: Point
207
+ initialContainer: HTMLElement
208
+ initialNextSibling: Element | null
209
+ initialRect: DOMRect
210
+ reorderPermutations: Array<{
211
+ nextSibling: Node | null
212
+ rect: DOMRect
213
+ }>
214
+ isTransitioning: boolean
215
+ selectedInsertAreaIndex?: number
216
+ insertAreas?: Array<InsertArea>
217
+ destroying: boolean
218
+ }
219
+
220
+ export type InsertArea = {
221
+ layout: 'block' | 'inline'
222
+ parent: Element
223
+ index: number
224
+ center: Point
225
+ size: number
226
+ direction: 1 | -1
227
+ }
228
+
229
+ export type Point = { x: number; y: number }
230
+ export type Line = { x1: number; y1: number; x2: number; y2: number }
231
+
232
+ /**
233
+ * Styles required for rendering the same exact text again somewhere else (on a overlay rect in the editor)
234
+ */
235
+ export enum TextNodeComputedStyles {
236
+ // Caret color is important as it is the only visible part of the text node (when text is not highlighted)
237
+ CARET_COLOR = 'caret-color',
238
+ DISPLAY = 'display',
239
+ FONT_FAMILY = 'font-family',
240
+ FONT_SIZE = 'font-size',
241
+ FONT_WEIGHT = 'font-weight',
242
+ FONT_STYLE = 'font-style',
243
+ FONT_VARIANT = 'font-variant',
244
+ FONT_STRETCH = 'font-stretch',
245
+ LINE_HEIGHT = 'line-height',
246
+ TEXT_ALIGN = 'text-align',
247
+ TEXT_TRANSFORM = 'text-transform',
248
+ LETTER_SPACING = 'letter-spacing',
249
+ WHITE_SPACE = 'white-space',
250
+ WORD_SPACING = 'word-spacing',
251
+ TEXT_INDENT = 'text-indent',
252
+ TEXT_OVERFLOW = 'text-overflow',
253
+ TEXT_RENDERING = 'text-rendering',
254
+ WORD_BREAK = 'word-break',
255
+ WORD_WRAP = 'word-wrap',
256
+ DIRECTION = 'direction',
257
+ UNICODE_BIDI = 'unicode-bidi',
258
+ VERTICAL_ALIGN = 'vertical-align',
259
+ FONT_KERNING = 'font-kerning',
260
+ FONT_FEATURE_SETTINGS = 'font-feature-settings',
261
+ FONT_VARIATION_SETTINGS = 'font-variation-settings',
262
+ FONT_SMOOTHING = '-webkit-font-smoothing',
263
+ ANTI_ALIASING = '-moz-osx-font-smoothing',
264
+ FONT_OPTICAL_SIZING = 'font-optical-sizing',
265
+ TAB_SIZE = 'tab-size',
266
+ HYPHENS = 'hyphens',
267
+ TEXT_ORIENTATION = 'text-orientation',
268
+ WRITING_MODE = 'writing-mode',
269
+ LINE_BREAK = 'line-break',
270
+ OVERFLOW_WRAP = 'overflow-wrap',
271
+ }