@servicetitan/dte-unlayer 0.92.0 → 0.94.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.
- package/dist/editor-core-source.d.ts +2 -2
- package/dist/editor-core-source.d.ts.map +1 -1
- package/dist/editor-core-source.js +2 -2
- package/dist/editor-core-source.js.map +1 -1
- package/dist/editor.js.map +1 -1
- package/dist/shared/schema.d.ts +6 -2
- package/dist/shared/schema.d.ts.map +1 -1
- package/dist/shared/schema.js +10 -6
- package/dist/shared/schema.js.map +1 -1
- package/package.json +1 -1
- package/src/editor-core-source.ts +2 -2
- package/src/editor.tsx +1 -1
- package/src/shared/schema.ts +21 -13
package/src/editor.tsx
CHANGED
package/src/shared/schema.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export type SchemaNodeAvailableTypes = 'object' | 'array' | 'string';
|
|
2
|
-
export const schemaNodeAvailableTypes = ['object', 'array', 'string'];
|
|
1
|
+
export type SchemaNodeAvailableTypes = 'object' | 'array' | 'string' | 'number';
|
|
2
|
+
export const schemaNodeAvailableTypes = ['object', 'array', 'string', 'number'];
|
|
3
3
|
|
|
4
4
|
export type SchemaNodeStringSubTypes = 'string' | 'text' | 'html' | 'image';
|
|
5
5
|
export const schemaNodeStringSubTypes = ['string', 'text', 'html', 'image'];
|
|
@@ -35,7 +35,11 @@ export interface SchemaSimpleString extends SchemaNodeProps {
|
|
|
35
35
|
subType?: SchemaNodeStringSubTypes;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
export
|
|
38
|
+
export interface SchemaSimpleNumber extends SchemaNodeProps {
|
|
39
|
+
type: 'number';
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export type SchemaSimple = SchemaSimpleString | SchemaSimpleNumber;
|
|
39
43
|
|
|
40
44
|
export const schemaArrayRootKey = '[]';
|
|
41
45
|
export type SchemaNode = SchemaObject | SchemaArray | SchemaSimple;
|
|
@@ -46,6 +50,8 @@ export const schemaIsArrayOfObjects = (node?: SchemaNode): node is SchemaArray =
|
|
|
46
50
|
export const schemaIsArray = (node?: SchemaNode): node is SchemaArray => node?.type === 'array';
|
|
47
51
|
export const schemaIsString = (node?: SchemaNode): node is SchemaSimpleString =>
|
|
48
52
|
node?.type === 'string';
|
|
53
|
+
export const schemaIsNumber = (node?: SchemaNode): node is SchemaSimpleNumber =>
|
|
54
|
+
node?.type === 'number';
|
|
49
55
|
export const schemaIsStringHtml = (node?: SchemaNode): node is SchemaSimpleString =>
|
|
50
56
|
node?.type === 'string' && node?.subType === 'html';
|
|
51
57
|
|
|
@@ -94,15 +100,15 @@ export const schemaFindParentNode = (schema: SchemaNode, key: string): SchemaNod
|
|
|
94
100
|
return keys.length
|
|
95
101
|
? schemaFindNode(schema, keys.join('.'))
|
|
96
102
|
: schemaIsObject(schema) && schema.properties[key]
|
|
97
|
-
|
|
98
|
-
|
|
103
|
+
? schema
|
|
104
|
+
: undefined;
|
|
99
105
|
};
|
|
100
106
|
|
|
101
107
|
export const schemaGetFieldKey = (fullKey: string): string => fullKey.split('.').pop() ?? '';
|
|
102
108
|
|
|
103
109
|
export const schemaBuildNode = (
|
|
104
110
|
type: SchemaNodeAvailableTypes,
|
|
105
|
-
arrayItemType?: SchemaNodeAvailableTypes
|
|
111
|
+
arrayItemType?: SchemaNodeAvailableTypes,
|
|
106
112
|
): SchemaNode => {
|
|
107
113
|
if (type === 'object') {
|
|
108
114
|
return { type: 'object', properties: {}, options: {} };
|
|
@@ -135,7 +141,7 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
135
141
|
nodeKey: string,
|
|
136
142
|
parentNodes: { key: string; title: string }[],
|
|
137
143
|
isArrayed: boolean,
|
|
138
|
-
dummyDataNode: any
|
|
144
|
+
dummyDataNode: any,
|
|
139
145
|
) => {
|
|
140
146
|
const nodeLabel = node.title ?? nodeKey;
|
|
141
147
|
const isArrayRoot = nodeKey === schemaArrayRootKey;
|
|
@@ -148,7 +154,7 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
148
154
|
fieldKey: nodeKey,
|
|
149
155
|
fullKey,
|
|
150
156
|
fullTitle,
|
|
151
|
-
title: node.title ?? isArrayed ? nodeLabel : fullTitle,
|
|
157
|
+
title: (node.title ?? isArrayed) ? nodeLabel : fullTitle,
|
|
152
158
|
node,
|
|
153
159
|
isArrayed,
|
|
154
160
|
isValue: !schemaIsObject(node) && !schemaIsArray(node),
|
|
@@ -174,7 +180,7 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
174
180
|
key,
|
|
175
181
|
nodeKey ? [...parentNodes, { key: nodeKey, title: nodeLabel }] : [],
|
|
176
182
|
isArrayed,
|
|
177
|
-
dummyDataObject
|
|
183
|
+
dummyDataObject,
|
|
178
184
|
);
|
|
179
185
|
}
|
|
180
186
|
} else if (schemaIsArray(node)) {
|
|
@@ -186,16 +192,18 @@ export const schemaBuildMap = (schema: SchemaObject): { map: SchemaMap; dummyDat
|
|
|
186
192
|
schemaArrayRootKey,
|
|
187
193
|
nodeKey ? [...parentNodes, { key: nodeKey, title: nodeLabel }] : [],
|
|
188
194
|
true,
|
|
189
|
-
dummyDataNode[nodeKey]
|
|
195
|
+
dummyDataNode[nodeKey],
|
|
190
196
|
);
|
|
191
197
|
} else if (nodeKey) {
|
|
198
|
+
const sampleData = node?.options?.sampleData;
|
|
192
199
|
const placeholder = node?.options?.placeholder;
|
|
200
|
+
const value = sampleData !== undefined ? sampleData : placeholder;
|
|
193
201
|
|
|
194
|
-
if (
|
|
202
|
+
if (value !== undefined) {
|
|
195
203
|
if (isArrayRoot) {
|
|
196
|
-
dummyDataNode.push?.(
|
|
204
|
+
dummyDataNode.push?.(value);
|
|
197
205
|
} else {
|
|
198
|
-
dummyDataNode[nodeKey] =
|
|
206
|
+
dummyDataNode[nodeKey] = value;
|
|
199
207
|
}
|
|
200
208
|
}
|
|
201
209
|
}
|