@valbuild/react 0.39.0 → 0.41.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/declarations/src/stega/index.d.ts +1 -1
- package/dist/declarations/src/stega/stegaEncode.d.ts +133 -2
- package/package.json +4 -4
- package/stega/dist/valbuild-react-stega.browser.esm.js +69 -16
- package/stega/dist/valbuild-react-stega.cjs.dev.js +69 -15
- package/stega/dist/valbuild-react-stega.cjs.prod.js +69 -15
- package/stega/dist/valbuild-react-stega.esm.js +69 -16
- package/stega/dist/valbuild-react-stega.worker.esm.js +69 -16
@@ -1,2 +1,2 @@
|
|
1
1
|
export { autoTagJSX } from "./autoTagJSX.js";
|
2
|
-
export { stegaEncode, getModuleIds, type ValEncodedString, type StegaOfSource, } from "./stegaEncode.js";
|
2
|
+
export { stegaEncode, getModuleIds, stegaClean, type ValEncodedString, type StegaOfSource, } from "./stegaEncode.js";
|
@@ -12,14 +12,145 @@ declare const brand: unique symbol;
|
|
12
12
|
* where the content comes from for contextual editing.
|
13
13
|
*
|
14
14
|
*/
|
15
|
-
export type ValEncodedString = string & {
|
15
|
+
export type ValEncodedString = `${string}__VAL_ENCODED_STRING_INVISIBLE_CHARS` & {
|
16
|
+
/**
|
17
|
+
*
|
18
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
19
|
+
*
|
20
|
+
* Instead, get the raw string using `val.raw`
|
21
|
+
*
|
22
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
23
|
+
*
|
24
|
+
* @example
|
25
|
+
* val.raw(myEncodedString) // returns a normal string
|
26
|
+
*/
|
27
|
+
substring: never;
|
28
|
+
/**
|
29
|
+
*
|
30
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
31
|
+
*
|
32
|
+
* Instead, get the raw string using `val.raw`
|
33
|
+
*
|
34
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
35
|
+
*
|
36
|
+
* @example
|
37
|
+
* val.raw(myEncodedString) // returns a normal string
|
38
|
+
*/
|
39
|
+
match: never;
|
40
|
+
/**
|
41
|
+
*
|
42
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
43
|
+
*
|
44
|
+
* Instead, get the raw string using `val.raw`
|
45
|
+
*
|
46
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
47
|
+
*
|
48
|
+
* @example
|
49
|
+
* val.raw(myEncodedString) // returns a normal string
|
50
|
+
*/
|
51
|
+
charAt: never;
|
52
|
+
/**
|
53
|
+
*
|
54
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
55
|
+
*
|
56
|
+
* Instead, get the raw string using `val.raw`
|
57
|
+
*
|
58
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
59
|
+
*
|
60
|
+
* @example
|
61
|
+
* val.raw(myEncodedString) // returns a normal string
|
62
|
+
*/
|
63
|
+
charCodeAt: never;
|
64
|
+
/**
|
65
|
+
*
|
66
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
67
|
+
*
|
68
|
+
* Instead, get the raw string using `val.raw`
|
69
|
+
*
|
70
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
71
|
+
*
|
72
|
+
* @example
|
73
|
+
* val.raw(myEncodedString) // returns a normal string
|
74
|
+
*/
|
75
|
+
concat: never;
|
76
|
+
/**
|
77
|
+
*
|
78
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
79
|
+
*
|
80
|
+
* Instead, get the raw string using `val.raw`
|
81
|
+
*
|
82
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
83
|
+
*
|
84
|
+
* @example
|
85
|
+
* val.raw(myEncodedString) // returns a normal string
|
86
|
+
*/
|
87
|
+
indexOf: never;
|
88
|
+
/**
|
89
|
+
*
|
90
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
91
|
+
*
|
92
|
+
* Instead, get the raw string using `val.raw`
|
93
|
+
*
|
94
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
95
|
+
*
|
96
|
+
* @example
|
97
|
+
* val.raw(myEncodedString) // returns a normal string
|
98
|
+
*/
|
99
|
+
lastIndexOf: never;
|
100
|
+
/**
|
101
|
+
*
|
102
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
103
|
+
*
|
104
|
+
* Instead, get the raw string using `val.raw`
|
105
|
+
*
|
106
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
107
|
+
*
|
108
|
+
* @example
|
109
|
+
* val.raw(myEncodedString) // returns a normal string
|
110
|
+
*/
|
111
|
+
slice: never;
|
112
|
+
/**
|
113
|
+
*
|
114
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
115
|
+
*
|
116
|
+
* Instead, get the raw string using `val.raw`
|
117
|
+
*
|
118
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
119
|
+
*
|
120
|
+
* @example
|
121
|
+
* val.raw(myEncodedString) // returns a normal string
|
122
|
+
*/
|
123
|
+
toString: never;
|
124
|
+
/**
|
125
|
+
*
|
126
|
+
* NB: This is a Val ENCODED string, which means that you should not use this method.
|
127
|
+
*
|
128
|
+
* Instead, get the raw string using `val.raw`
|
129
|
+
*
|
130
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
131
|
+
*
|
132
|
+
* @example
|
133
|
+
* val.raw(myEncodedString) // returns a normal string
|
134
|
+
*/
|
135
|
+
/**
|
136
|
+
*
|
137
|
+
* NB: This is a Val ENCODED string, which means that you should not use length on it.
|
138
|
+
*
|
139
|
+
* Instead, get the raw string using `val.raw`
|
140
|
+
*
|
141
|
+
* @deprecated NB: This is a Val ENCODED string, which means that you should not use this method.
|
142
|
+
*
|
143
|
+
* @example
|
144
|
+
* val.raw(myEncodedString) // returns a normal string
|
145
|
+
*/
|
146
|
+
length: never;
|
16
147
|
[brand]: "ValEncodedString";
|
17
148
|
};
|
18
149
|
export type StegaOfSource<T extends Source> = Json extends T ? Json : T extends RichTextSource<infer O> ? RichText<O> : T extends FileSource ? {
|
19
150
|
url: ValEncodedString;
|
20
151
|
} : T extends SourceObject ? {
|
21
152
|
[key in keyof T]: StegaOfSource<T[key]>;
|
22
|
-
} : T extends SourceArray ? StegaOfSource<T[number]>[] : T extends RawString ? string :
|
153
|
+
} : T extends SourceArray ? StegaOfSource<T[number]>[] : T extends RawString ? string : string extends T ? ValEncodedString : T extends JsonPrimitive ? T : never;
|
23
154
|
export declare function stegaEncode(input: any, opts: {
|
24
155
|
getModule?: (moduleId: string) => any;
|
25
156
|
disabled?: boolean;
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@valbuild/react",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.41.0",
|
4
4
|
"private": false,
|
5
5
|
"description": "Val - React internal helpers",
|
6
6
|
"sideEffects": false,
|
@@ -9,9 +9,9 @@
|
|
9
9
|
"test": "jest"
|
10
10
|
},
|
11
11
|
"dependencies": {
|
12
|
-
"@valbuild/core": "~0.
|
13
|
-
"@valbuild/shared": "~0.
|
14
|
-
"@valbuild/ui": "~0.
|
12
|
+
"@valbuild/core": "~0.41.0",
|
13
|
+
"@valbuild/shared": "~0.41.0",
|
14
|
+
"@valbuild/ui": "~0.41.0",
|
15
15
|
"@vercel/stega": "^0.1.0",
|
16
16
|
"base64-arraybuffer": "^1.0.2",
|
17
17
|
"style-to-object": "^0.4.1"
|
@@ -101,6 +101,41 @@ function _objectSpread2(e) {
|
|
101
101
|
|
102
102
|
function stegaEncode(input, opts) {
|
103
103
|
function rec(sourceOrSelector, recOpts) {
|
104
|
+
if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isUnionSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
|
105
|
+
if (sourceOrSelector && _typeof(sourceOrSelector) === "object" && recOpts.schema.key) {
|
106
|
+
var _key = sourceOrSelector[recOpts.schema.key];
|
107
|
+
if (_key) {
|
108
|
+
var schema = recOpts.schema.items.find(function (s) {
|
109
|
+
if (isObjectSchema(s) && s.items && s.items[recOpts.schema.key]) {
|
110
|
+
var keySchema = s.items[recOpts.schema.key];
|
111
|
+
if (isLiteralSchema(keySchema)) {
|
112
|
+
return keySchema.value === _key;
|
113
|
+
} else {
|
114
|
+
console.warn("Expected literal schema at key in , but found: ", keySchema, {
|
115
|
+
key: _key,
|
116
|
+
schema: s
|
117
|
+
});
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
console.warn("Expected union containing object schema, but found: ", s);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
if (schema) {
|
124
|
+
return rec(sourceOrSelector, {
|
125
|
+
path: recOpts.path,
|
126
|
+
schema: schema
|
127
|
+
});
|
128
|
+
}
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
return rec(sourceOrSelector, {
|
132
|
+
path: recOpts.path,
|
133
|
+
schema: recOpts.schema.items.find(function (s) {
|
134
|
+
return isLiteralSchema(s) && s.value === sourceOrSelector;
|
135
|
+
})
|
136
|
+
});
|
137
|
+
}
|
138
|
+
}
|
104
139
|
if (_typeof(sourceOrSelector) === "object") {
|
105
140
|
if (!sourceOrSelector) {
|
106
141
|
return null;
|
@@ -110,7 +145,7 @@ function stegaEncode(input, opts) {
|
|
110
145
|
var newSchema = Internal.getSchema(sourceOrSelector);
|
111
146
|
return rec(opts.getModule && opts.getModule(selectorPath) || Internal.getSource(sourceOrSelector), opts.disabled ? undefined : {
|
112
147
|
path: selectorPath,
|
113
|
-
schema: newSchema
|
148
|
+
schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema.serialize()
|
114
149
|
});
|
115
150
|
}
|
116
151
|
if (VAL_EXTENSION in sourceOrSelector) {
|
@@ -141,28 +176,27 @@ function stegaEncode(input, opts) {
|
|
141
176
|
}
|
142
177
|
if (!Array.isArray(sourceOrSelector)) {
|
143
178
|
var res = {};
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
recOpts.schema.items[_key] // Object
|
179
|
+
var entries = Object.entries(sourceOrSelector);
|
180
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
181
|
+
var _entries$_i = _slicedToArray(_entries[_i], 2),
|
182
|
+
_key2 = _entries$_i[0],
|
183
|
+
value = _entries$_i[1];
|
184
|
+
res[_key2] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
|
185
|
+
path: Internal.createValPathOfItem(recOpts.path, _key2),
|
186
|
+
schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key2] : unknownSchema(recOpts.schema)
|
153
187
|
});
|
154
188
|
}
|
155
|
-
|
156
189
|
return res;
|
157
190
|
}
|
158
191
|
console.error("Could not transform source selector: ".concat(_typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
|
159
192
|
return sourceOrSelector;
|
160
193
|
}
|
161
194
|
if (typeof sourceOrSelector === "string") {
|
195
|
+
var _recOpts$schema, _recOpts$schema2;
|
162
196
|
if (!recOpts) {
|
163
197
|
return sourceOrSelector;
|
164
198
|
}
|
165
|
-
if (recOpts.schema.
|
199
|
+
if ((_recOpts$schema = recOpts.schema) !== null && _recOpts$schema !== void 0 && _recOpts$schema.raw || ((_recOpts$schema2 = recOpts.schema) === null || _recOpts$schema2 === void 0 ? void 0 : _recOpts$schema2.type) === "literal") {
|
166
200
|
return sourceOrSelector;
|
167
201
|
}
|
168
202
|
return vercelStegaCombine(sourceOrSelector, {
|
@@ -182,6 +216,25 @@ function stegaEncode(input, opts) {
|
|
182
216
|
}
|
183
217
|
return rec(input);
|
184
218
|
}
|
219
|
+
function isRecordSchema(schema) {
|
220
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "record";
|
221
|
+
}
|
222
|
+
function isLiteralSchema(schema) {
|
223
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "literal";
|
224
|
+
}
|
225
|
+
function unknownSchema(schema) {
|
226
|
+
console.debug("Found unknown schema", schema);
|
227
|
+
return schema;
|
228
|
+
}
|
229
|
+
function isUnionSchema(schema) {
|
230
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
|
231
|
+
}
|
232
|
+
function isObjectSchema(schema) {
|
233
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
|
234
|
+
}
|
235
|
+
function stegaClean(source) {
|
236
|
+
return vercelStegaSplit(source).cleaned;
|
237
|
+
}
|
185
238
|
function getModuleIds(input) {
|
186
239
|
var modules = new Set();
|
187
240
|
function rec(sourceOrSelector) {
|
@@ -209,9 +262,9 @@ function getModuleIds(input) {
|
|
209
262
|
return;
|
210
263
|
}
|
211
264
|
if (!Array.isArray(sourceOrSelector)) {
|
212
|
-
for (var _i2 = 0, _Object$
|
213
|
-
var _Object$
|
214
|
-
value = _Object$
|
265
|
+
for (var _i2 = 0, _Object$entries = Object.entries(sourceOrSelector); _i2 < _Object$entries.length; _i2++) {
|
266
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
267
|
+
value = _Object$entries$_i[1];
|
215
268
|
rec(value);
|
216
269
|
}
|
217
270
|
return;
|
@@ -232,4 +285,4 @@ function getModuleIds(input) {
|
|
232
285
|
return Array.from(modules);
|
233
286
|
}
|
234
287
|
|
235
|
-
export { autoTagJSX, getModuleIds, stegaEncode };
|
288
|
+
export { autoTagJSX, getModuleIds, stegaClean, stegaEncode };
|
@@ -111,6 +111,41 @@ function _objectSpread2(e) {
|
|
111
111
|
|
112
112
|
function stegaEncode(input, opts) {
|
113
113
|
function rec(sourceOrSelector, recOpts) {
|
114
|
+
if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isUnionSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
|
115
|
+
if (sourceOrSelector && _typeof._typeof(sourceOrSelector) === "object" && recOpts.schema.key) {
|
116
|
+
var _key = sourceOrSelector[recOpts.schema.key];
|
117
|
+
if (_key) {
|
118
|
+
var schema = recOpts.schema.items.find(function (s) {
|
119
|
+
if (isObjectSchema(s) && s.items && s.items[recOpts.schema.key]) {
|
120
|
+
var keySchema = s.items[recOpts.schema.key];
|
121
|
+
if (isLiteralSchema(keySchema)) {
|
122
|
+
return keySchema.value === _key;
|
123
|
+
} else {
|
124
|
+
console.warn("Expected literal schema at key in , but found: ", keySchema, {
|
125
|
+
key: _key,
|
126
|
+
schema: s
|
127
|
+
});
|
128
|
+
}
|
129
|
+
} else {
|
130
|
+
console.warn("Expected union containing object schema, but found: ", s);
|
131
|
+
}
|
132
|
+
});
|
133
|
+
if (schema) {
|
134
|
+
return rec(sourceOrSelector, {
|
135
|
+
path: recOpts.path,
|
136
|
+
schema: schema
|
137
|
+
});
|
138
|
+
}
|
139
|
+
}
|
140
|
+
} else {
|
141
|
+
return rec(sourceOrSelector, {
|
142
|
+
path: recOpts.path,
|
143
|
+
schema: recOpts.schema.items.find(function (s) {
|
144
|
+
return isLiteralSchema(s) && s.value === sourceOrSelector;
|
145
|
+
})
|
146
|
+
});
|
147
|
+
}
|
148
|
+
}
|
114
149
|
if (_typeof._typeof(sourceOrSelector) === "object") {
|
115
150
|
if (!sourceOrSelector) {
|
116
151
|
return null;
|
@@ -120,7 +155,7 @@ function stegaEncode(input, opts) {
|
|
120
155
|
var newSchema = core.Internal.getSchema(sourceOrSelector);
|
121
156
|
return rec(opts.getModule && opts.getModule(selectorPath) || core.Internal.getSource(sourceOrSelector), opts.disabled ? undefined : {
|
122
157
|
path: selectorPath,
|
123
|
-
schema: newSchema
|
158
|
+
schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema.serialize()
|
124
159
|
});
|
125
160
|
}
|
126
161
|
if (core.VAL_EXTENSION in sourceOrSelector) {
|
@@ -151,28 +186,27 @@ function stegaEncode(input, opts) {
|
|
151
186
|
}
|
152
187
|
if (!Array.isArray(sourceOrSelector)) {
|
153
188
|
var res = {};
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
recOpts.schema.items[_key] // Object
|
189
|
+
var entries = Object.entries(sourceOrSelector);
|
190
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
191
|
+
var _entries$_i = slicedToArray._slicedToArray(_entries[_i], 2),
|
192
|
+
_key2 = _entries$_i[0],
|
193
|
+
value = _entries$_i[1];
|
194
|
+
res[_key2] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
|
195
|
+
path: core.Internal.createValPathOfItem(recOpts.path, _key2),
|
196
|
+
schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key2] : unknownSchema(recOpts.schema)
|
163
197
|
});
|
164
198
|
}
|
165
|
-
|
166
199
|
return res;
|
167
200
|
}
|
168
201
|
console.error("Could not transform source selector: ".concat(_typeof._typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
|
169
202
|
return sourceOrSelector;
|
170
203
|
}
|
171
204
|
if (typeof sourceOrSelector === "string") {
|
205
|
+
var _recOpts$schema, _recOpts$schema2;
|
172
206
|
if (!recOpts) {
|
173
207
|
return sourceOrSelector;
|
174
208
|
}
|
175
|
-
if (recOpts.schema.
|
209
|
+
if ((_recOpts$schema = recOpts.schema) !== null && _recOpts$schema !== void 0 && _recOpts$schema.raw || ((_recOpts$schema2 = recOpts.schema) === null || _recOpts$schema2 === void 0 ? void 0 : _recOpts$schema2.type) === "literal") {
|
176
210
|
return sourceOrSelector;
|
177
211
|
}
|
178
212
|
return stega.vercelStegaCombine(sourceOrSelector, {
|
@@ -192,6 +226,25 @@ function stegaEncode(input, opts) {
|
|
192
226
|
}
|
193
227
|
return rec(input);
|
194
228
|
}
|
229
|
+
function isRecordSchema(schema) {
|
230
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "record";
|
231
|
+
}
|
232
|
+
function isLiteralSchema(schema) {
|
233
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "literal";
|
234
|
+
}
|
235
|
+
function unknownSchema(schema) {
|
236
|
+
console.debug("Found unknown schema", schema);
|
237
|
+
return schema;
|
238
|
+
}
|
239
|
+
function isUnionSchema(schema) {
|
240
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
|
241
|
+
}
|
242
|
+
function isObjectSchema(schema) {
|
243
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
|
244
|
+
}
|
245
|
+
function stegaClean(source) {
|
246
|
+
return stega.vercelStegaSplit(source).cleaned;
|
247
|
+
}
|
195
248
|
function getModuleIds(input) {
|
196
249
|
var modules = new Set();
|
197
250
|
function rec(sourceOrSelector) {
|
@@ -219,9 +272,9 @@ function getModuleIds(input) {
|
|
219
272
|
return;
|
220
273
|
}
|
221
274
|
if (!Array.isArray(sourceOrSelector)) {
|
222
|
-
for (var _i2 = 0, _Object$
|
223
|
-
var _Object$
|
224
|
-
value = _Object$
|
275
|
+
for (var _i2 = 0, _Object$entries = Object.entries(sourceOrSelector); _i2 < _Object$entries.length; _i2++) {
|
276
|
+
var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i2], 2),
|
277
|
+
value = _Object$entries$_i[1];
|
225
278
|
rec(value);
|
226
279
|
}
|
227
280
|
return;
|
@@ -244,4 +297,5 @@ function getModuleIds(input) {
|
|
244
297
|
|
245
298
|
exports.autoTagJSX = autoTagJSX;
|
246
299
|
exports.getModuleIds = getModuleIds;
|
300
|
+
exports.stegaClean = stegaClean;
|
247
301
|
exports.stegaEncode = stegaEncode;
|
@@ -111,6 +111,41 @@ function _objectSpread2(e) {
|
|
111
111
|
|
112
112
|
function stegaEncode(input, opts) {
|
113
113
|
function rec(sourceOrSelector, recOpts) {
|
114
|
+
if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isUnionSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
|
115
|
+
if (sourceOrSelector && _typeof._typeof(sourceOrSelector) === "object" && recOpts.schema.key) {
|
116
|
+
var _key = sourceOrSelector[recOpts.schema.key];
|
117
|
+
if (_key) {
|
118
|
+
var schema = recOpts.schema.items.find(function (s) {
|
119
|
+
if (isObjectSchema(s) && s.items && s.items[recOpts.schema.key]) {
|
120
|
+
var keySchema = s.items[recOpts.schema.key];
|
121
|
+
if (isLiteralSchema(keySchema)) {
|
122
|
+
return keySchema.value === _key;
|
123
|
+
} else {
|
124
|
+
console.warn("Expected literal schema at key in , but found: ", keySchema, {
|
125
|
+
key: _key,
|
126
|
+
schema: s
|
127
|
+
});
|
128
|
+
}
|
129
|
+
} else {
|
130
|
+
console.warn("Expected union containing object schema, but found: ", s);
|
131
|
+
}
|
132
|
+
});
|
133
|
+
if (schema) {
|
134
|
+
return rec(sourceOrSelector, {
|
135
|
+
path: recOpts.path,
|
136
|
+
schema: schema
|
137
|
+
});
|
138
|
+
}
|
139
|
+
}
|
140
|
+
} else {
|
141
|
+
return rec(sourceOrSelector, {
|
142
|
+
path: recOpts.path,
|
143
|
+
schema: recOpts.schema.items.find(function (s) {
|
144
|
+
return isLiteralSchema(s) && s.value === sourceOrSelector;
|
145
|
+
})
|
146
|
+
});
|
147
|
+
}
|
148
|
+
}
|
114
149
|
if (_typeof._typeof(sourceOrSelector) === "object") {
|
115
150
|
if (!sourceOrSelector) {
|
116
151
|
return null;
|
@@ -120,7 +155,7 @@ function stegaEncode(input, opts) {
|
|
120
155
|
var newSchema = core.Internal.getSchema(sourceOrSelector);
|
121
156
|
return rec(opts.getModule && opts.getModule(selectorPath) || core.Internal.getSource(sourceOrSelector), opts.disabled ? undefined : {
|
122
157
|
path: selectorPath,
|
123
|
-
schema: newSchema
|
158
|
+
schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema.serialize()
|
124
159
|
});
|
125
160
|
}
|
126
161
|
if (core.VAL_EXTENSION in sourceOrSelector) {
|
@@ -151,28 +186,27 @@ function stegaEncode(input, opts) {
|
|
151
186
|
}
|
152
187
|
if (!Array.isArray(sourceOrSelector)) {
|
153
188
|
var res = {};
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
recOpts.schema.items[_key] // Object
|
189
|
+
var entries = Object.entries(sourceOrSelector);
|
190
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
191
|
+
var _entries$_i = slicedToArray._slicedToArray(_entries[_i], 2),
|
192
|
+
_key2 = _entries$_i[0],
|
193
|
+
value = _entries$_i[1];
|
194
|
+
res[_key2] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
|
195
|
+
path: core.Internal.createValPathOfItem(recOpts.path, _key2),
|
196
|
+
schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key2] : unknownSchema(recOpts.schema)
|
163
197
|
});
|
164
198
|
}
|
165
|
-
|
166
199
|
return res;
|
167
200
|
}
|
168
201
|
console.error("Could not transform source selector: ".concat(_typeof._typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
|
169
202
|
return sourceOrSelector;
|
170
203
|
}
|
171
204
|
if (typeof sourceOrSelector === "string") {
|
205
|
+
var _recOpts$schema, _recOpts$schema2;
|
172
206
|
if (!recOpts) {
|
173
207
|
return sourceOrSelector;
|
174
208
|
}
|
175
|
-
if (recOpts.schema.
|
209
|
+
if ((_recOpts$schema = recOpts.schema) !== null && _recOpts$schema !== void 0 && _recOpts$schema.raw || ((_recOpts$schema2 = recOpts.schema) === null || _recOpts$schema2 === void 0 ? void 0 : _recOpts$schema2.type) === "literal") {
|
176
210
|
return sourceOrSelector;
|
177
211
|
}
|
178
212
|
return stega.vercelStegaCombine(sourceOrSelector, {
|
@@ -192,6 +226,25 @@ function stegaEncode(input, opts) {
|
|
192
226
|
}
|
193
227
|
return rec(input);
|
194
228
|
}
|
229
|
+
function isRecordSchema(schema) {
|
230
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "record";
|
231
|
+
}
|
232
|
+
function isLiteralSchema(schema) {
|
233
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "literal";
|
234
|
+
}
|
235
|
+
function unknownSchema(schema) {
|
236
|
+
console.debug("Found unknown schema", schema);
|
237
|
+
return schema;
|
238
|
+
}
|
239
|
+
function isUnionSchema(schema) {
|
240
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
|
241
|
+
}
|
242
|
+
function isObjectSchema(schema) {
|
243
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
|
244
|
+
}
|
245
|
+
function stegaClean(source) {
|
246
|
+
return stega.vercelStegaSplit(source).cleaned;
|
247
|
+
}
|
195
248
|
function getModuleIds(input) {
|
196
249
|
var modules = new Set();
|
197
250
|
function rec(sourceOrSelector) {
|
@@ -219,9 +272,9 @@ function getModuleIds(input) {
|
|
219
272
|
return;
|
220
273
|
}
|
221
274
|
if (!Array.isArray(sourceOrSelector)) {
|
222
|
-
for (var _i2 = 0, _Object$
|
223
|
-
var _Object$
|
224
|
-
value = _Object$
|
275
|
+
for (var _i2 = 0, _Object$entries = Object.entries(sourceOrSelector); _i2 < _Object$entries.length; _i2++) {
|
276
|
+
var _Object$entries$_i = slicedToArray._slicedToArray(_Object$entries[_i2], 2),
|
277
|
+
value = _Object$entries$_i[1];
|
225
278
|
rec(value);
|
226
279
|
}
|
227
280
|
return;
|
@@ -244,4 +297,5 @@ function getModuleIds(input) {
|
|
244
297
|
|
245
298
|
exports.autoTagJSX = autoTagJSX;
|
246
299
|
exports.getModuleIds = getModuleIds;
|
300
|
+
exports.stegaClean = stegaClean;
|
247
301
|
exports.stegaEncode = stegaEncode;
|
@@ -101,6 +101,41 @@ function _objectSpread2(e) {
|
|
101
101
|
|
102
102
|
function stegaEncode(input, opts) {
|
103
103
|
function rec(sourceOrSelector, recOpts) {
|
104
|
+
if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isUnionSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
|
105
|
+
if (sourceOrSelector && _typeof(sourceOrSelector) === "object" && recOpts.schema.key) {
|
106
|
+
var _key = sourceOrSelector[recOpts.schema.key];
|
107
|
+
if (_key) {
|
108
|
+
var schema = recOpts.schema.items.find(function (s) {
|
109
|
+
if (isObjectSchema(s) && s.items && s.items[recOpts.schema.key]) {
|
110
|
+
var keySchema = s.items[recOpts.schema.key];
|
111
|
+
if (isLiteralSchema(keySchema)) {
|
112
|
+
return keySchema.value === _key;
|
113
|
+
} else {
|
114
|
+
console.warn("Expected literal schema at key in , but found: ", keySchema, {
|
115
|
+
key: _key,
|
116
|
+
schema: s
|
117
|
+
});
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
console.warn("Expected union containing object schema, but found: ", s);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
if (schema) {
|
124
|
+
return rec(sourceOrSelector, {
|
125
|
+
path: recOpts.path,
|
126
|
+
schema: schema
|
127
|
+
});
|
128
|
+
}
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
return rec(sourceOrSelector, {
|
132
|
+
path: recOpts.path,
|
133
|
+
schema: recOpts.schema.items.find(function (s) {
|
134
|
+
return isLiteralSchema(s) && s.value === sourceOrSelector;
|
135
|
+
})
|
136
|
+
});
|
137
|
+
}
|
138
|
+
}
|
104
139
|
if (_typeof(sourceOrSelector) === "object") {
|
105
140
|
if (!sourceOrSelector) {
|
106
141
|
return null;
|
@@ -110,7 +145,7 @@ function stegaEncode(input, opts) {
|
|
110
145
|
var newSchema = Internal.getSchema(sourceOrSelector);
|
111
146
|
return rec(opts.getModule && opts.getModule(selectorPath) || Internal.getSource(sourceOrSelector), opts.disabled ? undefined : {
|
112
147
|
path: selectorPath,
|
113
|
-
schema: newSchema
|
148
|
+
schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema.serialize()
|
114
149
|
});
|
115
150
|
}
|
116
151
|
if (VAL_EXTENSION in sourceOrSelector) {
|
@@ -141,28 +176,27 @@ function stegaEncode(input, opts) {
|
|
141
176
|
}
|
142
177
|
if (!Array.isArray(sourceOrSelector)) {
|
143
178
|
var res = {};
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
recOpts.schema.items[_key] // Object
|
179
|
+
var entries = Object.entries(sourceOrSelector);
|
180
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
181
|
+
var _entries$_i = _slicedToArray(_entries[_i], 2),
|
182
|
+
_key2 = _entries$_i[0],
|
183
|
+
value = _entries$_i[1];
|
184
|
+
res[_key2] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
|
185
|
+
path: Internal.createValPathOfItem(recOpts.path, _key2),
|
186
|
+
schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key2] : unknownSchema(recOpts.schema)
|
153
187
|
});
|
154
188
|
}
|
155
|
-
|
156
189
|
return res;
|
157
190
|
}
|
158
191
|
console.error("Could not transform source selector: ".concat(_typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
|
159
192
|
return sourceOrSelector;
|
160
193
|
}
|
161
194
|
if (typeof sourceOrSelector === "string") {
|
195
|
+
var _recOpts$schema, _recOpts$schema2;
|
162
196
|
if (!recOpts) {
|
163
197
|
return sourceOrSelector;
|
164
198
|
}
|
165
|
-
if (recOpts.schema.
|
199
|
+
if ((_recOpts$schema = recOpts.schema) !== null && _recOpts$schema !== void 0 && _recOpts$schema.raw || ((_recOpts$schema2 = recOpts.schema) === null || _recOpts$schema2 === void 0 ? void 0 : _recOpts$schema2.type) === "literal") {
|
166
200
|
return sourceOrSelector;
|
167
201
|
}
|
168
202
|
return vercelStegaCombine(sourceOrSelector, {
|
@@ -182,6 +216,25 @@ function stegaEncode(input, opts) {
|
|
182
216
|
}
|
183
217
|
return rec(input);
|
184
218
|
}
|
219
|
+
function isRecordSchema(schema) {
|
220
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "record";
|
221
|
+
}
|
222
|
+
function isLiteralSchema(schema) {
|
223
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "literal";
|
224
|
+
}
|
225
|
+
function unknownSchema(schema) {
|
226
|
+
console.debug("Found unknown schema", schema);
|
227
|
+
return schema;
|
228
|
+
}
|
229
|
+
function isUnionSchema(schema) {
|
230
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
|
231
|
+
}
|
232
|
+
function isObjectSchema(schema) {
|
233
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
|
234
|
+
}
|
235
|
+
function stegaClean(source) {
|
236
|
+
return vercelStegaSplit(source).cleaned;
|
237
|
+
}
|
185
238
|
function getModuleIds(input) {
|
186
239
|
var modules = new Set();
|
187
240
|
function rec(sourceOrSelector) {
|
@@ -209,9 +262,9 @@ function getModuleIds(input) {
|
|
209
262
|
return;
|
210
263
|
}
|
211
264
|
if (!Array.isArray(sourceOrSelector)) {
|
212
|
-
for (var _i2 = 0, _Object$
|
213
|
-
var _Object$
|
214
|
-
value = _Object$
|
265
|
+
for (var _i2 = 0, _Object$entries = Object.entries(sourceOrSelector); _i2 < _Object$entries.length; _i2++) {
|
266
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
267
|
+
value = _Object$entries$_i[1];
|
215
268
|
rec(value);
|
216
269
|
}
|
217
270
|
return;
|
@@ -232,4 +285,4 @@ function getModuleIds(input) {
|
|
232
285
|
return Array.from(modules);
|
233
286
|
}
|
234
287
|
|
235
|
-
export { autoTagJSX, getModuleIds, stegaEncode };
|
288
|
+
export { autoTagJSX, getModuleIds, stegaClean, stegaEncode };
|
@@ -101,6 +101,41 @@ function _objectSpread2(e) {
|
|
101
101
|
|
102
102
|
function stegaEncode(input, opts) {
|
103
103
|
function rec(sourceOrSelector, recOpts) {
|
104
|
+
if (recOpts !== null && recOpts !== void 0 && recOpts.schema && isUnionSchema(recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema)) {
|
105
|
+
if (sourceOrSelector && _typeof(sourceOrSelector) === "object" && recOpts.schema.key) {
|
106
|
+
var _key = sourceOrSelector[recOpts.schema.key];
|
107
|
+
if (_key) {
|
108
|
+
var schema = recOpts.schema.items.find(function (s) {
|
109
|
+
if (isObjectSchema(s) && s.items && s.items[recOpts.schema.key]) {
|
110
|
+
var keySchema = s.items[recOpts.schema.key];
|
111
|
+
if (isLiteralSchema(keySchema)) {
|
112
|
+
return keySchema.value === _key;
|
113
|
+
} else {
|
114
|
+
console.warn("Expected literal schema at key in , but found: ", keySchema, {
|
115
|
+
key: _key,
|
116
|
+
schema: s
|
117
|
+
});
|
118
|
+
}
|
119
|
+
} else {
|
120
|
+
console.warn("Expected union containing object schema, but found: ", s);
|
121
|
+
}
|
122
|
+
});
|
123
|
+
if (schema) {
|
124
|
+
return rec(sourceOrSelector, {
|
125
|
+
path: recOpts.path,
|
126
|
+
schema: schema
|
127
|
+
});
|
128
|
+
}
|
129
|
+
}
|
130
|
+
} else {
|
131
|
+
return rec(sourceOrSelector, {
|
132
|
+
path: recOpts.path,
|
133
|
+
schema: recOpts.schema.items.find(function (s) {
|
134
|
+
return isLiteralSchema(s) && s.value === sourceOrSelector;
|
135
|
+
})
|
136
|
+
});
|
137
|
+
}
|
138
|
+
}
|
104
139
|
if (_typeof(sourceOrSelector) === "object") {
|
105
140
|
if (!sourceOrSelector) {
|
106
141
|
return null;
|
@@ -110,7 +145,7 @@ function stegaEncode(input, opts) {
|
|
110
145
|
var newSchema = Internal.getSchema(sourceOrSelector);
|
111
146
|
return rec(opts.getModule && opts.getModule(selectorPath) || Internal.getSource(sourceOrSelector), opts.disabled ? undefined : {
|
112
147
|
path: selectorPath,
|
113
|
-
schema: newSchema
|
148
|
+
schema: newSchema === null || newSchema === void 0 ? void 0 : newSchema.serialize()
|
114
149
|
});
|
115
150
|
}
|
116
151
|
if (VAL_EXTENSION in sourceOrSelector) {
|
@@ -141,28 +176,27 @@ function stegaEncode(input, opts) {
|
|
141
176
|
}
|
142
177
|
if (!Array.isArray(sourceOrSelector)) {
|
143
178
|
var res = {};
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
recOpts.schema.items[_key] // Object
|
179
|
+
var entries = Object.entries(sourceOrSelector);
|
180
|
+
for (var _i = 0, _entries = entries; _i < _entries.length; _i++) {
|
181
|
+
var _entries$_i = _slicedToArray(_entries[_i], 2),
|
182
|
+
_key2 = _entries$_i[0],
|
183
|
+
value = _entries$_i[1];
|
184
|
+
res[_key2] = rec(value, (recOpts === null || recOpts === void 0 ? void 0 : recOpts.schema) && {
|
185
|
+
path: Internal.createValPathOfItem(recOpts.path, _key2),
|
186
|
+
schema: isRecordSchema(recOpts.schema) ? recOpts.schema.item : isObjectSchema(recOpts.schema) ? recOpts.schema.items[_key2] : unknownSchema(recOpts.schema)
|
153
187
|
});
|
154
188
|
}
|
155
|
-
|
156
189
|
return res;
|
157
190
|
}
|
158
191
|
console.error("Could not transform source selector: ".concat(_typeof(sourceOrSelector), " (array: ").concat(Array.isArray(sourceOrSelector), ")"), sourceOrSelector);
|
159
192
|
return sourceOrSelector;
|
160
193
|
}
|
161
194
|
if (typeof sourceOrSelector === "string") {
|
195
|
+
var _recOpts$schema, _recOpts$schema2;
|
162
196
|
if (!recOpts) {
|
163
197
|
return sourceOrSelector;
|
164
198
|
}
|
165
|
-
if (recOpts.schema.
|
199
|
+
if ((_recOpts$schema = recOpts.schema) !== null && _recOpts$schema !== void 0 && _recOpts$schema.raw || ((_recOpts$schema2 = recOpts.schema) === null || _recOpts$schema2 === void 0 ? void 0 : _recOpts$schema2.type) === "literal") {
|
166
200
|
return sourceOrSelector;
|
167
201
|
}
|
168
202
|
return vercelStegaCombine(sourceOrSelector, {
|
@@ -182,6 +216,25 @@ function stegaEncode(input, opts) {
|
|
182
216
|
}
|
183
217
|
return rec(input);
|
184
218
|
}
|
219
|
+
function isRecordSchema(schema) {
|
220
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "record";
|
221
|
+
}
|
222
|
+
function isLiteralSchema(schema) {
|
223
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "literal";
|
224
|
+
}
|
225
|
+
function unknownSchema(schema) {
|
226
|
+
console.debug("Found unknown schema", schema);
|
227
|
+
return schema;
|
228
|
+
}
|
229
|
+
function isUnionSchema(schema) {
|
230
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "union";
|
231
|
+
}
|
232
|
+
function isObjectSchema(schema) {
|
233
|
+
return (schema === null || schema === void 0 ? void 0 : schema.type) === "object";
|
234
|
+
}
|
235
|
+
function stegaClean(source) {
|
236
|
+
return vercelStegaSplit(source).cleaned;
|
237
|
+
}
|
185
238
|
function getModuleIds(input) {
|
186
239
|
var modules = new Set();
|
187
240
|
function rec(sourceOrSelector) {
|
@@ -209,9 +262,9 @@ function getModuleIds(input) {
|
|
209
262
|
return;
|
210
263
|
}
|
211
264
|
if (!Array.isArray(sourceOrSelector)) {
|
212
|
-
for (var _i2 = 0, _Object$
|
213
|
-
var _Object$
|
214
|
-
value = _Object$
|
265
|
+
for (var _i2 = 0, _Object$entries = Object.entries(sourceOrSelector); _i2 < _Object$entries.length; _i2++) {
|
266
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2),
|
267
|
+
value = _Object$entries$_i[1];
|
215
268
|
rec(value);
|
216
269
|
}
|
217
270
|
return;
|
@@ -232,4 +285,4 @@ function getModuleIds(input) {
|
|
232
285
|
return Array.from(modules);
|
233
286
|
}
|
234
287
|
|
235
|
-
export { autoTagJSX, getModuleIds, stegaEncode };
|
288
|
+
export { autoTagJSX, getModuleIds, stegaClean, stegaEncode };
|