@json-layout/vocabulary 0.14.0 → 0.15.0

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 (46) hide show
  1. package/package.json +5 -5
  2. package/src/components/compile-types.js +61 -0
  3. package/src/components/index.js +226 -0
  4. package/src/components/types.ts +378 -0
  5. package/src/index.js +3 -0
  6. package/src/layout-keyword/index.js +9 -2
  7. package/src/layout-keyword/schema.js +67 -62
  8. package/src/layout-keyword/schema.json +35 -50
  9. package/src/layout-keyword/types.ts +111 -42
  10. package/src/normalize.js +92 -53
  11. package/src/normalized-layout/index.js +18 -64
  12. package/src/normalized-layout/schema.js +235 -762
  13. package/src/normalized-layout/schema.json +118 -324
  14. package/src/normalized-layout/types.ts +163 -233
  15. package/src/types.ts +11 -0
  16. package/src/validate.js +42 -0
  17. package/types/components/compile-types.d.ts +13 -0
  18. package/types/components/compile-types.d.ts.map +1 -0
  19. package/types/components/index.d.ts +52 -0
  20. package/types/components/index.d.ts.map +1 -0
  21. package/types/components/types.d.ts +329 -0
  22. package/types/components/types.d.ts.map +1 -0
  23. package/types/index.d.ts +2 -0
  24. package/types/index.d.ts.map +1 -1
  25. package/types/layout-keyword/index.d.ts +6 -1
  26. package/types/layout-keyword/index.d.ts.map +1 -1
  27. package/types/layout-keyword/schema.d.ts +43 -26
  28. package/types/layout-keyword/types.d.ts +111 -18
  29. package/types/layout-keyword/types.d.ts.map +1 -1
  30. package/types/normalize.d.ts +3 -2
  31. package/types/normalize.d.ts.map +1 -1
  32. package/types/normalized-layout/index.d.ts +19 -65
  33. package/types/normalized-layout/index.d.ts.map +1 -1
  34. package/types/normalized-layout/schema.d.ts +171 -526
  35. package/types/normalized-layout/types.d.ts +163 -208
  36. package/types/normalized-layout/types.d.ts.map +1 -1
  37. package/types/types.d.ts +10 -0
  38. package/types/types.d.ts.map +1 -1
  39. package/types/validate.d.ts +8 -0
  40. package/types/validate.d.ts.map +1 -0
  41. package/src/layout-keyword/validate.js +0 -2
  42. package/src/normalized-layout/validate.js +0 -3
  43. package/types/layout-keyword/validate.d.ts +0 -23
  44. package/types/layout-keyword/validate.d.ts.map +0 -1
  45. package/types/normalized-layout/validate.d.ts +0 -23
  46. package/types/normalized-layout/validate.d.ts.map +0 -1
@@ -1,10 +1,12 @@
1
- import validate from './validate.js'
2
1
  import schema from './schema.js'
2
+ import {ajv} from '../validate.js'
3
3
 
4
4
  /**
5
5
  * @typedef {import('./types.js').LayoutKeyword} LayoutKeyword
6
6
  * @typedef {import('./types.js').ComponentName} ComponentName
7
7
  * @typedef {import('./types.js').PartialChildren} PartialChildren
8
+ * @typedef {import('./types.js').PartialChild} PartialChild
9
+ * @typedef {import('./types.js').PartialChildComposite} PartialChildComposite
8
10
  * @typedef {import('./types.js').PartialSwitch} PartialSwitch
9
11
  * @typedef {import('./types.js').PartialCompObject} PartialCompObject
10
12
  * @typedef {import('./types.js').PartialGetItems} PartialGetItems
@@ -17,7 +19,7 @@ import schema from './schema.js'
17
19
  * @typedef {{ errors: any, (layoutKeyword: any): layoutKeyword is LayoutKeyword }} ValidateLayoutKeyword
18
20
  */
19
21
 
20
- export const /** @type {ValidateLayoutKeyword} */ validateLayoutKeyword = /** @type {any} */ (validate)
22
+ export const /** @type {ValidateLayoutKeyword} */ validateLayoutKeyword = /** @type {any} */ (ajv.getSchema(schema.$id))
21
23
 
22
24
  export const layoutKeywordSchema = /** @type {any} */ (schema)
23
25
 
@@ -36,6 +38,11 @@ export function isPartialChildren (layoutKeyword) {
36
38
  return Array.isArray(layoutKeyword)
37
39
  }
38
40
 
41
+ /** @type {(partialChild: PartialChild) => partialChild is PartialChildComposite} */
42
+ export function isPartialChildComposite (partialChild) {
43
+ return typeof partialChild !== 'string' && "children" in partialChild
44
+ }
45
+
39
46
  /** @type {(layoutKeyword: LayoutKeyword) => layoutKeyword is PartialCompObject} */
40
47
  export function isPartialCompObject (layoutKeyword) {
41
48
  return typeof layoutKeyword === 'object' && !Array.isArray(layoutKeyword)
@@ -2,25 +2,27 @@
2
2
  // raw schema
3
3
  export default {
4
4
  "$id": "https://json-layout.github.io/layout-keyword",
5
- "title": "layout keyword",
6
- "errorMessage": {
7
- "anyOf": "layout keyword must be a string with a valid component name, or a more complete object definition, or an array of children, or a switch structure"
8
- },
9
- "anyOf": [
10
- {
11
- "$ref": "#/$defs/comp-name"
12
- },
13
- {
14
- "$ref": "#/$defs/partial-children"
15
- },
16
- {
17
- "$ref": "#/$defs/partial-comp-object"
18
- },
19
- {
20
- "$ref": "#/$defs/partial-switch"
21
- }
22
- ],
23
5
  "$defs": {
6
+ "layout-keyword": {
7
+ "title": "layout keyword",
8
+ "errorMessage": {
9
+ "anyOf": "layout keyword must be a string with a valid component name, or a more complete object definition, or an array of children, or a switch structure"
10
+ },
11
+ "anyOf": [
12
+ {
13
+ "$ref": "#/$defs/comp-name"
14
+ },
15
+ {
16
+ "$ref": "#/$defs/partial-children"
17
+ },
18
+ {
19
+ "$ref": "#/$defs/partial-comp-object"
20
+ },
21
+ {
22
+ "$ref": "#/$defs/partial-switch"
23
+ }
24
+ ]
25
+ },
24
26
  "partial-switch": {
25
27
  "type": "object",
26
28
  "required": [
@@ -148,40 +150,14 @@ export default {
148
150
  },
149
151
  "comp-name": {
150
152
  "title": "component name",
151
- "type": "string",
152
- "errorMessage": {
153
- "enum": "component name is unknown"
154
- },
155
- "enum": [
156
- "none",
157
- "text-field",
158
- "number-field",
159
- "textarea",
160
- "markdown",
161
- "checkbox",
162
- "switch",
163
- "slider",
164
- "date-picker",
165
- "date-time-picker",
166
- "time-picker",
167
- "color-picker",
168
- "combobox",
169
- "number-combobox",
170
- "section",
171
- "list",
172
- "select",
173
- "autocomplete",
174
- "tabs",
175
- "vertical-tabs",
176
- "expansion-panels",
177
- "stepper",
178
- "one-of-select",
179
- "file-input"
180
- ]
153
+ "type": "string"
181
154
  },
182
- "partial-child": {
155
+ "partial-child-ref": {
183
156
  "type": "object",
184
- "unevaluatedProperties": false,
157
+ "required": [
158
+ "key"
159
+ ],
160
+ "additionalProperties": false,
185
161
  "properties": {
186
162
  "key": {
187
163
  "type": [
@@ -192,25 +168,54 @@ export default {
192
168
  "cols": {
193
169
  "$ref": "#/$defs/partial-cols"
194
170
  }
195
- },
196
- "allOf": [
171
+ }
172
+ },
173
+ "partial-child-composite": {
174
+ "type": "object",
175
+ "required": [
176
+ "children"
177
+ ],
178
+ "properties": {
179
+ "comp": {
180
+ "type": "string"
181
+ },
182
+ "title": {
183
+ "type": [
184
+ "string",
185
+ "null"
186
+ ]
187
+ },
188
+ "subtitle": {
189
+ "type": [
190
+ "string",
191
+ "null"
192
+ ]
193
+ },
194
+ "children": {
195
+ "$ref": "#/$defs/partial-children"
196
+ },
197
+ "cols": {
198
+ "$ref": "#/$defs/partial-cols"
199
+ }
200
+ }
201
+ },
202
+ "partial-child": {
203
+ "anyOf": [
197
204
  {
198
- "$ref": "#/$defs/partial-comp-object"
205
+ "type": "string"
206
+ },
207
+ {
208
+ "$ref": "#/$defs/partial-child-ref"
199
209
  },
200
- {}
210
+ {
211
+ "$ref": "#/$defs/partial-child-composite"
212
+ }
201
213
  ]
202
214
  },
203
215
  "partial-children": {
204
216
  "type": "array",
205
217
  "items": {
206
- "oneOf": [
207
- {
208
- "type": "string"
209
- },
210
- {
211
- "$ref": "#/$defs/partial-child"
212
- }
213
- ]
218
+ "$ref": "#/$defs/partial-child"
214
219
  }
215
220
  },
216
221
  "partial-expression": {
@@ -1,16 +1,18 @@
1
1
  {
2
2
  "$id": "https://json-layout.github.io/layout-keyword",
3
- "title": "layout keyword",
4
- "errorMessage": {
5
- "anyOf": "layout keyword must be a string with a valid component name, or a more complete object definition, or an array of children, or a switch structure"
6
- },
7
- "anyOf": [
8
- {"$ref": "#/$defs/comp-name"},
9
- {"$ref": "#/$defs/partial-children"},
10
- {"$ref": "#/$defs/partial-comp-object"},
11
- {"$ref": "#/$defs/partial-switch"}
12
- ],
13
3
  "$defs": {
4
+ "layout-keyword": {
5
+ "title": "layout keyword",
6
+ "errorMessage": {
7
+ "anyOf": "layout keyword must be a string with a valid component name, or a more complete object definition, or an array of children, or a switch structure"
8
+ },
9
+ "anyOf": [
10
+ {"$ref": "#/$defs/comp-name"},
11
+ {"$ref": "#/$defs/partial-children"},
12
+ {"$ref": "#/$defs/partial-comp-object"},
13
+ {"$ref": "#/$defs/partial-switch"}
14
+ ]
15
+ },
14
16
  "partial-switch": {
15
17
  "type": "object",
16
18
  "required": ["switch"],
@@ -61,56 +63,39 @@
61
63
  },
62
64
  "comp-name": {
63
65
  "title": "component name",
64
- "type": "string",
65
- "errorMessage": {
66
- "enum": "component name is unknown"
67
- },
68
- "enum": [
69
- "none",
70
- "text-field",
71
- "number-field",
72
- "textarea",
73
- "markdown",
74
- "checkbox",
75
- "switch",
76
- "slider",
77
- "date-picker",
78
- "date-time-picker",
79
- "time-picker",
80
- "color-picker",
81
- "combobox",
82
- "number-combobox",
83
- "section",
84
- "list",
85
- "select",
86
- "autocomplete",
87
- "tabs",
88
- "vertical-tabs",
89
- "expansion-panels",
90
- "stepper",
91
- "one-of-select",
92
- "file-input"
93
- ]
66
+ "type": "string"
94
67
  },
95
- "partial-child": {
68
+ "partial-child-ref": {
96
69
  "type": "object",
97
- "unevaluatedProperties": false,
70
+ "required": ["key"],
71
+ "additionalProperties": false,
98
72
  "properties": {
99
73
  "key": {"type": ["string", "integer"]},
100
74
  "cols": {"$ref": "#/$defs/partial-cols"}
101
- },
102
- "allOf": [
103
- {"$ref": "#/$defs/partial-comp-object"},
104
- {}
75
+ }
76
+ },
77
+ "partial-child-composite": {
78
+ "type": "object",
79
+ "required": ["children"],
80
+ "properties": {
81
+ "comp": {"type": "string"},
82
+ "title": {"type": ["string", "null"]},
83
+ "subtitle": {"type": ["string", "null"]},
84
+ "children": {"$ref": "#/$defs/partial-children"},
85
+ "cols": {"$ref": "#/$defs/partial-cols"}
86
+ }
87
+ },
88
+ "partial-child": {
89
+ "anyOf": [
90
+ {"type": "string"},
91
+ {"$ref": "#/$defs/partial-child-ref"},
92
+ {"$ref": "#/$defs/partial-child-composite"}
105
93
  ]
106
94
  },
107
95
  "partial-children": {
108
96
  "type": "array",
109
97
  "items": {
110
- "oneOf": [
111
- {"type": "string"},
112
- {"$ref": "#/$defs/partial-child"}
113
- ]
98
+ "$ref": "#/$defs/partial-child"
114
99
  }
115
100
  },
116
101
  "partial-expression": {
@@ -1,36 +1,42 @@
1
+ /**
2
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
3
+ * via the `definition` "layout-keyword".
4
+ */
1
5
  export type LayoutKeyword = ComponentName | PartialChildren | PartialCompObject | PartialSwitch;
2
- export type ComponentName =
3
- | "none"
4
- | "text-field"
5
- | "number-field"
6
- | "textarea"
7
- | "markdown"
8
- | "checkbox"
9
- | "switch"
10
- | "slider"
11
- | "date-picker"
12
- | "date-time-picker"
13
- | "time-picker"
14
- | "color-picker"
15
- | "combobox"
16
- | "number-combobox"
17
- | "section"
18
- | "list"
19
- | "select"
20
- | "autocomplete"
21
- | "tabs"
22
- | "vertical-tabs"
23
- | "expansion-panels"
24
- | "stepper"
25
- | "one-of-select"
26
- | "file-input";
27
- export type PartialChild = PartialChild1 & {
28
- key?: string | number;
29
- cols?: PartialCols;
30
- [k: string]: unknown;
31
- };
32
- export type PartialChild1 = PartialCompObject & unknown;
6
+ /**
7
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
8
+ * via the `definition` "comp-name".
9
+ */
10
+ export type ComponentName = string;
11
+ /**
12
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
13
+ * via the `definition` "partial-child".
14
+ */
15
+ export type PartialChild = string | PartialChildRef | PartialChildComposite;
16
+ /**
17
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
18
+ * via the `definition` "partial-cols".
19
+ */
20
+ export type PartialCols = PartialColsNumber | PartialColsObj;
21
+ /**
22
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
23
+ * via the `definition` "partial-cols-number".
24
+ */
25
+ export type PartialColsNumber = number;
26
+ /**
27
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
28
+ * via the `definition` "partial-children".
29
+ */
30
+ export type PartialChildren = PartialChild[];
31
+ /**
32
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
33
+ * via the `definition` "partial-expression".
34
+ */
33
35
  export type PartialExpression = string | PartialExpressionObj;
36
+ /**
37
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
38
+ * via the `definition` "partial-select-item".
39
+ */
34
40
  export type PartialSelectItem =
35
41
  | string
36
42
  | {
@@ -39,7 +45,15 @@ export type PartialSelectItem =
39
45
  value?: unknown;
40
46
  [k: string]: unknown;
41
47
  };
48
+ /**
49
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
50
+ * via the `definition` "partial-get-items".
51
+ */
42
52
  export type PartialGetItems = string | PartialGetItemsObj;
53
+ /**
54
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
55
+ * via the `definition` "partial-get-items-obj".
56
+ */
43
57
  export type PartialGetItemsObj = {
44
58
  itemTitle?: PartialExpression;
45
59
  itemKey?: PartialExpression;
@@ -54,15 +68,54 @@ export type PartialGetItemsObj = {
54
68
  | PartialExpressionObj
55
69
  | PartialGetItemsFetch
56
70
  );
57
- export type PartialCols = PartialColsNumber | PartialColsObj;
58
- export type PartialColsNumber = number;
59
71
  /**
60
72
  * This interface was referenced by `undefined`'s JSON-Schema definition
61
73
  * via the `patternProperty` ".*".
74
+ *
75
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
76
+ * via the `definition` "partial-slot".
62
77
  */
63
78
  export type PartialSlot = string | PartialSlotText | PartialSlotMarkdown | PartialSlotName;
64
- export type PartialChildren = (string | PartialChild)[];
65
79
 
80
+ export interface HttpsJsonLayoutGithubIoLayoutKeyword {
81
+ [k: string]: unknown;
82
+ }
83
+ /**
84
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
85
+ * via the `definition` "partial-child-ref".
86
+ */
87
+ export interface PartialChildRef {
88
+ key: string | number;
89
+ cols?: PartialCols;
90
+ }
91
+ /**
92
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
93
+ * via the `definition` "partial-cols-obj".
94
+ */
95
+ export interface PartialColsObj {
96
+ xs?: PartialColsNumber;
97
+ sm?: PartialColsNumber;
98
+ md?: PartialColsNumber;
99
+ lg?: PartialColsNumber;
100
+ xl?: PartialColsNumber;
101
+ xxl?: PartialColsNumber;
102
+ }
103
+ /**
104
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
105
+ * via the `definition` "partial-child-composite".
106
+ */
107
+ export interface PartialChildComposite {
108
+ comp?: string;
109
+ title?: string | null;
110
+ subtitle?: string | null;
111
+ children: PartialChildren;
112
+ cols?: PartialCols;
113
+ [k: string]: unknown;
114
+ }
115
+ /**
116
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
117
+ * via the `definition` "partial-comp-object".
118
+ */
66
119
  export interface PartialCompObject {
67
120
  comp?: ComponentName;
68
121
  help?: string;
@@ -100,32 +153,48 @@ export interface PartialCompObject {
100
153
  separator?: string;
101
154
  [k: string]: unknown;
102
155
  }
156
+ /**
157
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
158
+ * via the `definition` "partial-expression-obj".
159
+ */
103
160
  export interface PartialExpressionObj {
104
161
  type?: "js-fn" | "js-eval" | "js-tpl";
105
162
  expr: string;
106
163
  [k: string]: unknown;
107
164
  }
165
+ /**
166
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
167
+ * via the `definition` "partial-get-items-fetch".
168
+ */
108
169
  export interface PartialGetItemsFetch {
109
170
  url: PartialExpression;
110
171
  [k: string]: unknown;
111
172
  }
112
- export interface PartialColsObj {
113
- xs?: PartialColsNumber;
114
- sm?: PartialColsNumber;
115
- md?: PartialColsNumber;
116
- lg?: PartialColsNumber;
117
- xl?: PartialColsNumber;
118
- xxl?: PartialColsNumber;
119
- }
173
+ /**
174
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
175
+ * via the `definition` "partial-slot-text".
176
+ */
120
177
  export interface PartialSlotText {
121
178
  text: string;
122
179
  }
180
+ /**
181
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
182
+ * via the `definition` "partial-slot-markdown".
183
+ */
123
184
  export interface PartialSlotMarkdown {
124
185
  markdown: string;
125
186
  }
187
+ /**
188
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
189
+ * via the `definition` "partial-slot-name".
190
+ */
126
191
  export interface PartialSlotName {
127
192
  name: string;
128
193
  }
194
+ /**
195
+ * This interface was referenced by `HttpsJsonLayoutGithubIoLayoutKeyword`'s JSON-Schema
196
+ * via the `definition` "partial-switch".
197
+ */
129
198
  export interface PartialSwitch {
130
199
  switch: PartialCompObject[];
131
200
  }