@nordcraft/core 1.0.74 → 1.0.76

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.
Files changed (62) hide show
  1. package/README.md +5 -1
  2. package/dist/api/LegacyToddleApi.d.ts +17 -16
  3. package/dist/api/LegacyToddleApi.js.map +1 -1
  4. package/dist/api/ToddleApiV2.d.ts +46 -45
  5. package/dist/api/ToddleApiV2.js.map +1 -1
  6. package/dist/api/api.d.ts +16 -15
  7. package/dist/api/api.js +3 -3
  8. package/dist/api/api.js.map +1 -1
  9. package/dist/api/apiTypes.d.ts +68 -68
  10. package/dist/api/headers.d.ts +6 -5
  11. package/dist/api/headers.js.map +1 -1
  12. package/dist/component/ToddleComponent.d.ts +11 -11
  13. package/dist/component/ToddleComponent.js +2 -2
  14. package/dist/component/ToddleComponent.js.map +1 -1
  15. package/dist/component/actionUtils.d.ts +2 -2
  16. package/dist/component/actionUtils.js +1 -0
  17. package/dist/component/actionUtils.js.map +1 -1
  18. package/dist/component/component.types.d.ts +140 -140
  19. package/dist/component/component.types.js.map +1 -1
  20. package/dist/component/schemas/zod-schemas.d.ts +4 -0
  21. package/dist/component/schemas/zod-schemas.js +1106 -0
  22. package/dist/component/schemas/zod-schemas.js.map +1 -0
  23. package/dist/formula/formula.d.ts +14 -14
  24. package/dist/formula/formula.js +1 -1
  25. package/dist/formula/formula.js.map +1 -1
  26. package/dist/formula/formulaTypes.d.ts +10 -9
  27. package/dist/formula/formulaUtils.d.ts +11 -10
  28. package/dist/formula/formulaUtils.js +8 -2
  29. package/dist/formula/formulaUtils.js.map +1 -1
  30. package/dist/styling/customProperty.d.ts +2 -1
  31. package/dist/styling/customProperty.js.map +1 -1
  32. package/dist/styling/style.css.js +2 -2
  33. package/dist/styling/style.css.js.map +1 -1
  34. package/dist/styling/theme.d.ts +3 -2
  35. package/dist/styling/theme.js.map +1 -1
  36. package/dist/styling/variantSelector.d.ts +36 -35
  37. package/dist/styling/variantSelector.js.map +1 -1
  38. package/dist/types.d.ts +16 -15
  39. package/dist/utils/collections.d.ts +2 -1
  40. package/dist/utils/collections.js.map +1 -1
  41. package/dist/utils/getNodeSelector.d.ts +4 -3
  42. package/dist/utils/getNodeSelector.js.map +1 -1
  43. package/package.json +4 -1
  44. package/src/api/LegacyToddleApi.ts +2 -1
  45. package/src/api/ToddleApiV2.ts +2 -1
  46. package/src/api/api.ts +10 -9
  47. package/src/api/apiTypes.ts +73 -70
  48. package/src/api/headers.ts +7 -5
  49. package/src/component/ToddleComponent.ts +2 -2
  50. package/src/component/actionUtils.ts +3 -2
  51. package/src/component/component.types.ts +136 -131
  52. package/src/component/schemas/zod-schemas.ts +1535 -0
  53. package/src/formula/formula.ts +21 -18
  54. package/src/formula/formulaTypes.ts +12 -9
  55. package/src/formula/formulaUtils.ts +20 -13
  56. package/src/styling/customProperty.ts +2 -1
  57. package/src/styling/style.css.ts +6 -3
  58. package/src/styling/theme.ts +3 -2
  59. package/src/styling/variantSelector.ts +36 -35
  60. package/src/types.ts +27 -15
  61. package/src/utils/collections.ts +2 -1
  62. package/src/utils/getNodeSelector.ts +4 -3
@@ -2,67 +2,70 @@ import type { ApiStatus, ComponentAPI, LegacyApiStatus } from '../api/apiTypes'
2
2
  import type { Formula } from '../formula/formula'
3
3
  import type { StyleTokenCategory } from '../styling/theme'
4
4
  import type { StyleVariant } from '../styling/variantSelector'
5
- import type { NordcraftMetadata, RequireFields } from '../types'
5
+ import type { NordcraftMetadata, Nullable, RequireFields } from '../types'
6
6
 
7
7
  interface ListItem {
8
8
  Item: unknown
9
9
  Index: number
10
- Parent?: ListItem
10
+ Parent?: Nullable<ListItem>
11
11
  }
12
12
 
13
13
  export interface ComponentData {
14
- Location?: {
15
- page?: string
14
+ Location?: Nullable<{
15
+ page?: Nullable<string>
16
16
  path: string
17
17
  // params is a combination of path and query parameters
18
- params: Record<string, string | null>
19
- query: Record<string, string | null>
18
+ params: Record<string, Nullable<string>>
19
+ query: Record<string, Nullable<string>>
20
20
  hash: string
21
- }
21
+ }>
22
22
  Attributes: Record<string, unknown>
23
- Variables?: Record<string, unknown>
24
- Contexts?: Record<string, Record<string, unknown>>
25
- 'URL parameters'?: Record<string, string | null>
23
+ Variables?: Nullable<Record<string, unknown>>
24
+ Contexts?: Nullable<Record<string, Record<string, unknown>>>
25
+ 'URL parameters'?: Nullable<Record<string, Nullable<string>>>
26
26
  // { path: { docs: null }, query: { embed: everything } }
27
- 'Route parameters'?: {
28
- path: Record<string, string | null>
29
- query: Record<string, string | null>
30
- }
31
- Apis?: Record<
32
- string,
33
- LegacyApiStatus | (ApiStatus & { inputs?: Record<string, unknown> })
27
+ 'Route parameters'?: Nullable<{
28
+ path: Record<string, Nullable<string>>
29
+ query: Record<string, Nullable<string>>
30
+ }>
31
+ Apis?: Nullable<
32
+ Record<
33
+ string,
34
+ | LegacyApiStatus
35
+ | (ApiStatus & { inputs?: Nullable<Record<string, unknown>> })
36
+ >
34
37
  >
35
- Args?: unknown
36
- Parameters?: Record<string, unknown>
37
- Event?: unknown
38
- ListItem?: ListItem
38
+ Args?: Nullable<unknown>
39
+ Parameters?: Nullable<Record<string, unknown>>
40
+ Event?: Nullable<unknown>
41
+ ListItem?: Nullable<ListItem>
39
42
  }
40
43
 
41
44
  export interface AnimationKeyframe {
42
45
  position: number
43
46
  key: string
44
47
  value: string
45
- easing?: never
48
+ easing?: Nullable<never>
46
49
  }
47
50
 
48
- export type NodeStyleModel = Record<string, string>
51
+ export type NodeStyleModel = Record<string, string | number>
49
52
 
50
53
  export interface TextNodeModel {
51
- id?: string | null
54
+ id?: Nullable<string>
52
55
  type: 'text'
53
- condition?: Formula | null
54
- repeat?: Formula | null
55
- slot?: string | null
56
- repeatKey?: Formula | null
56
+ condition?: Nullable<Formula>
57
+ repeat?: Nullable<Formula>
58
+ slot?: Nullable<string>
59
+ repeatKey?: Nullable<Formula>
57
60
  value: Formula
58
- children?: undefined
61
+ children?: Nullable<never>
59
62
  }
60
63
 
61
64
  export type CustomPropertyName = `--${string}`
62
65
 
63
66
  export type CustomProperty = {
64
67
  formula: Formula
65
- unit?: string | null
68
+ unit?: Nullable<string>
66
69
  }
67
70
 
68
71
  /**
@@ -72,54 +75,54 @@ export type StyleVariable = {
72
75
  category: StyleTokenCategory
73
76
  name: string
74
77
  formula: Formula
75
- unit?: string
78
+ unit?: Nullable<string>
76
79
  }
77
80
 
78
81
  export interface ElementNodeModel {
79
- id?: string
82
+ id?: Nullable<string>
80
83
  type: 'element'
81
- slot?: string
82
- condition?: Formula | null
83
- repeat?: Formula | null
84
- repeatKey?: Formula | null
84
+ slot?: Nullable<string>
85
+ condition?: Nullable<Formula>
86
+ repeat?: Nullable<Formula>
87
+ repeatKey?: Nullable<Formula>
85
88
  tag: string
86
89
  attrs: Partial<Record<string, Formula>>
87
- style?: NodeStyleModel | null
88
- variants?: StyleVariant[] | null
89
- animations?: Record<string, Record<string, AnimationKeyframe>>
90
+ style?: Nullable<NodeStyleModel>
91
+ variants?: Nullable<StyleVariant[]>
92
+ animations?: Nullable<Record<string, Record<string, AnimationKeyframe>>>
90
93
  children: string[]
91
- events: Partial<Record<string, EventModel | null>>
92
- classes?: Record<string, { formula?: Formula }> | null
93
- 'style-variables'?: Array<StyleVariable>
94
- customProperties?: Record<CustomPropertyName, CustomProperty>
94
+ events: Partial<Record<string, Nullable<EventModel>>>
95
+ classes?: Nullable<Record<string, { formula?: Nullable<Formula> }>>
96
+ 'style-variables'?: Nullable<Array<StyleVariable>>
97
+ customProperties?: Nullable<Record<CustomPropertyName, CustomProperty>>
95
98
  }
96
99
 
97
100
  export interface ComponentNodeModel {
98
- id?: string
101
+ id?: Nullable<string>
99
102
  type: 'component'
100
- slot?: string
101
- path?: string
103
+ slot?: Nullable<string>
104
+ path?: Nullable<string>
102
105
  name: string
103
- package?: string
104
- condition?: Formula | null
105
- repeat?: Formula | null
106
- repeatKey?: Formula | null
107
- style?: NodeStyleModel | null
108
- variants?: StyleVariant[] | null
109
- animations?: Record<string, Record<string, AnimationKeyframe>>
106
+ package?: Nullable<string>
107
+ condition?: Nullable<Formula>
108
+ repeat?: Nullable<Formula>
109
+ repeatKey?: Nullable<Formula>
110
+ style?: Nullable<NodeStyleModel>
111
+ variants?: Nullable<StyleVariant[]>
112
+ animations?: Nullable<Record<string, Record<string, AnimationKeyframe>>>
110
113
  attrs: Record<string, Formula>
111
114
  children: string[]
112
115
  events: Record<string, EventModel>
113
- customProperties?: Record<CustomPropertyName, CustomProperty>
116
+ customProperties?: Nullable<Record<CustomPropertyName, CustomProperty>>
114
117
  }
115
118
 
116
119
  export interface SlotNodeModel {
117
120
  type: 'slot'
118
- slot?: string
119
- name?: string
120
- condition?: Formula | null
121
- repeat?: undefined | null
122
- repeatKey?: undefined | null
121
+ slot?: Nullable<string>
122
+ name?: Nullable<string>
123
+ condition?: Nullable<Formula>
124
+ repeat?: Nullable<never>
125
+ repeatKey?: Nullable<never>
123
126
  children: string[]
124
127
  }
125
128
  export type NodeModel =
@@ -131,29 +134,29 @@ export type NodeModel =
131
134
  export interface MetaEntry {
132
135
  tag: HeadTagTypes
133
136
  attrs: Record<string, Formula>
134
- content?: Formula | null
135
- index?: number | null
137
+ content?: Nullable<Formula>
138
+ index?: Nullable<number>
136
139
  }
137
140
 
138
141
  export interface StaticPathSegment {
139
142
  type: 'static'
140
- optional?: boolean
141
- testValue?: undefined
143
+ optional?: Nullable<boolean>
144
+ testValue?: Nullable<never>
142
145
  name: string
143
146
  }
144
147
 
145
148
  export interface DynamicPathSegment {
146
149
  type: 'param'
147
150
  testValue: string
148
- optional?: boolean
151
+ optional?: Nullable<boolean>
149
152
  name: string
150
153
  }
151
154
 
152
155
  export type MediaQuery = {
153
- 'min-width'?: string
154
- 'max-width'?: string
155
- 'min-height'?: string
156
- 'max-height'?: string
156
+ 'min-width'?: Nullable<string>
157
+ 'max-width'?: Nullable<string>
158
+ 'min-height'?: Nullable<string>
159
+ 'max-height'?: Nullable<string>
157
160
  }
158
161
 
159
162
  export interface Component {
@@ -164,54 +167,56 @@ export interface Component {
164
167
  * @default undefined (version 1)
165
168
  * @deprecated - we are no longer using version 2 components, but we are keeping this field for backwards compatibility
166
169
  */
167
- version?: 2 | null
170
+ version?: Nullable<2>
168
171
  // @deprecated - use route->path instead
169
- page?: string | null // page url /projects/:id - only for pages
170
- route?: PageRoute | null
171
- attributes: Record<string, ComponentAttribute>
172
- variables: Record<string, ComponentVariable>
173
- formulas?: Record<string, ComponentFormula> | null
174
- contexts?: Record<
175
- // `componentName` or `packageName/componentName` if the context comes from a different package than the component itself
176
- string,
177
- ComponentContext
178
- > | null
179
- workflows?: Record<string, ComponentWorkflow> | null
180
- apis: Record<string, ComponentAPI>
181
- nodes: Record<string, NodeModel>
182
- events?: ComponentEvent[] | null
183
- onLoad?: EventModel | null
184
- onAttributeChange?: EventModel | null
172
+ page?: Nullable<string> // page url /projects/:id - only for pages
173
+ route?: Nullable<PageRoute>
174
+ attributes?: Nullable<Record<string, ComponentAttribute>>
175
+ variables?: Nullable<Record<string, ComponentVariable>>
176
+ formulas?: Nullable<Record<string, ComponentFormula>>
177
+ contexts?: Nullable<
178
+ Record<
179
+ // `componentName` or `packageName/componentName` if the context comes from a different package than the component itself
180
+ string,
181
+ ComponentContext
182
+ >
183
+ >
184
+ workflows?: Nullable<Record<string, ComponentWorkflow>>
185
+ apis?: Nullable<Record<string, ComponentAPI>>
186
+ nodes?: Nullable<Record<string, NodeModel>>
187
+ events?: Nullable<ComponentEvent[]>
188
+ onLoad?: Nullable<EventModel>
189
+ onAttributeChange?: Nullable<EventModel>
185
190
  // exported indicates that a component is exported in a package
186
- exported?: boolean | null
187
- customElement?: {
191
+ exported?: Nullable<boolean>
192
+ customElement?: Nullable<{
188
193
  // Later, we will add information about allowed origins here
189
- enabled?: Formula
190
- }
194
+ enabled?: Nullable<Formula>
195
+ }>
191
196
  }
192
197
 
193
198
  export interface ComponentFormula extends NordcraftMetadata {
194
199
  name: string
195
- arguments?: Array<{ name: string; testValue: any }> | null
196
- memoize?: boolean
197
- exposeInContext?: boolean
200
+ arguments?: Nullable<Array<{ name: string; testValue: any }>>
201
+ memoize?: Nullable<boolean>
202
+ exposeInContext?: Nullable<boolean>
198
203
  formula: Formula
199
204
  }
200
205
 
201
206
  export interface ComponentWorkflow extends NordcraftMetadata {
202
207
  name: string
203
208
  parameters: Array<{ name: string; testValue: any }>
204
- callbacks?: Array<{ name: string; testValue: any }>
209
+ callbacks?: Nullable<Array<{ name: string; testValue: any }>>
205
210
  actions: ActionModel[]
206
- exposeInContext?: boolean
207
- testValue?: unknown
211
+ exposeInContext?: Nullable<boolean>
212
+ testValue?: Nullable<unknown>
208
213
  }
209
214
 
210
215
  export interface ComponentContext {
211
216
  formulas: string[]
212
217
  workflows: string[]
213
- componentName?: string
214
- package?: string
218
+ componentName?: Nullable<string>
219
+ package?: Nullable<string>
215
220
  }
216
221
 
217
222
  export type PageComponent = RequireFields<Component, 'route'>
@@ -225,12 +230,12 @@ export interface PageRoute extends RouteDeclaration {
225
230
  // Information for the <head> element
226
231
  // only relevant for pages - not for regular
227
232
  // components
228
- info?: {
233
+ info?: Nullable<{
229
234
  // value for <html lang= > - defaults to 'en'
230
- language?: { formula: Formula }
235
+ language?: Nullable<{ formula: Formula }>
231
236
  // title (for <title>) - defaults to page name
232
- title?: { formula: Formula }
233
- description?: { formula: Formula }
237
+ title?: Nullable<{ formula: Formula }>
238
+ description?: Nullable<{ formula: Formula }>
234
239
  // links - only icon (+icon:16 and icon:32) for now:
235
240
  // - manifest
236
241
  // - mask-icon
@@ -239,8 +244,8 @@ export interface PageRoute extends RouteDeclaration {
239
244
  // - icon (32)
240
245
  // - icon (16)
241
246
  // cSpell:ignore Vhmkm
242
- icon?: { formula: Formula } // /cdn-cgi/imagedelivery/ZIty0Vhmkm0nD-fBKJrTZQ/my-icon
243
- charset?: { formula: Formula } // defaults to utf-8
247
+ icon?: Nullable<{ formula: Formula }> // /cdn-cgi/imagedelivery/ZIty0Vhmkm0nD-fBKJrTZQ/my-icon
248
+ charset?: Nullable<{ formula: Formula }> // defaults to utf-8
244
249
 
245
250
  // meta:
246
251
  // - viewport <meta name="viewport" content="width=device-width, initial-scale=1">
@@ -258,8 +263,8 @@ export interface PageRoute extends RouteDeclaration {
258
263
  // - twitter:card
259
264
  // - twitter:site
260
265
  // - twitter:creator
261
- meta?: Record<string, MetaEntry>
262
- }
266
+ meta?: Nullable<Record<string, MetaEntry>>
267
+ }>
263
268
  }
264
269
 
265
270
  export enum HeadTagTypes {
@@ -272,14 +277,14 @@ export enum HeadTagTypes {
272
277
 
273
278
  export interface EventModel {
274
279
  trigger: string
275
- actions: ActionModel[]
280
+ actions?: Nullable<ActionModel[]>
276
281
  }
277
282
 
278
283
  export interface CustomActionArgument {
279
284
  name: string
280
- formula?: Formula
281
- type?: any
282
- description?: string
285
+ formula?: Nullable<Formula>
286
+ type?: Nullable<any>
287
+ description?: Nullable<string>
283
288
  }
284
289
 
285
290
  export interface ActionModelActions {
@@ -288,23 +293,23 @@ export interface ActionModelActions {
288
293
 
289
294
  export interface CustomActionModel {
290
295
  // Some legacy custom actions use an undefined type
291
- type?: 'Custom'
292
- package?: string
296
+ type?: Nullable<'Custom'>
297
+ package?: Nullable<string>
293
298
  name: string
294
- description?: string
295
- group?: string
296
- data?: string | number | boolean | Formula
297
- arguments?: Partial<CustomActionArgument[]>
298
- events?: Record<string, ActionModelActions>
299
- version?: 2 | never
300
- label?: string
299
+ description?: Nullable<string>
300
+ group?: Nullable<string>
301
+ data?: Nullable<string | number | boolean | Formula>
302
+ arguments?: Nullable<Partial<CustomActionArgument[]>>
303
+ events?: Nullable<Record<string, ActionModelActions>>
304
+ version?: Nullable<2 | never>
305
+ label?: Nullable<string>
301
306
  }
302
307
 
303
308
  export interface SwitchActionModel {
304
309
  type: 'Switch'
305
- data?: string | number | boolean | Formula
310
+ data?: Nullable<string | number | boolean | Formula>
306
311
  cases: Array<{
307
- condition: Formula | null
312
+ condition: Nullable<Formula>
308
313
  actions: ActionModel[]
309
314
  }>
310
315
  default: ActionModelActions
@@ -313,48 +318,48 @@ export interface SwitchActionModel {
313
318
  export interface VariableActionModel {
314
319
  type: 'SetVariable'
315
320
  variable: string
316
- data: Formula | null
321
+ data: Nullable<Formula>
317
322
  }
318
323
  export interface FetchActionModel {
319
324
  type: 'Fetch'
320
325
  api: string
321
- inputs?: Record<string, { formula: Formula | null }>
326
+ inputs?: Nullable<Record<string, { formula: Nullable<Formula> }>>
322
327
  onSuccess: ActionModelActions
323
328
  onError: ActionModelActions
324
- onMessage?: ActionModelActions
329
+ onMessage?: Nullable<ActionModelActions>
325
330
  }
326
331
 
327
332
  export interface SetURLParameterAction {
328
333
  type: 'SetURLParameter'
329
334
  parameter: string
330
- data: Formula | null
331
- historyMode?: 'replace' | 'push' | null
335
+ data?: Nullable<Formula>
336
+ historyMode?: Nullable<'replace' | 'push'>
332
337
  }
333
338
 
334
339
  export interface SetMultiUrlParameterAction {
335
340
  type: 'SetURLParameters'
336
341
  parameters: Record<string, Formula>
337
- historyMode?: 'replace' | 'push' | null
342
+ historyMode?: Nullable<'replace' | 'push'>
338
343
  }
339
344
 
340
345
  export interface EventActionModel {
341
346
  type: 'TriggerEvent'
342
347
  event: string
343
- data: Formula | null
348
+ data?: Nullable<Formula>
344
349
  }
345
350
 
346
351
  export interface WorkflowActionModel {
347
352
  type: 'TriggerWorkflow'
348
353
  workflow: string
349
- parameters: Record<string, { formula?: Formula }> | null
350
- callbacks?: Record<string, { actions?: ActionModel[] | null }>
351
- contextProvider?: string
354
+ parameters: Record<string, { formula?: Nullable<Formula> }>
355
+ callbacks?: Nullable<Record<string, { actions?: Nullable<ActionModel[]> }>>
356
+ contextProvider?: Nullable<string>
352
357
  }
353
358
 
354
359
  export interface WorkflowCallbackActionModel {
355
360
  type: 'TriggerWorkflowCallback'
356
361
  event: string
357
- data: Formula | null
362
+ data?: Nullable<Formula>
358
363
  }
359
364
 
360
365
  export type ActionModel =