@player-tools/dsl 0.4.0-next.2 → 0.4.0-next.3
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/index.cjs.js +176 -113
- package/dist/index.d.ts +64 -11
- package/dist/index.esm.js +177 -114
- package/package.json +1 -3
- package/src/compiler/compiler.ts +69 -32
- package/src/compiler/schema.ts +37 -20
- package/src/compiler/types.ts +49 -2
- package/src/components.tsx +42 -17
- package/src/string-templates/index.ts +5 -1
- package/src/template.tsx +8 -0
- package/src/types.ts +8 -0
- package/src/utils.tsx +31 -14
package/dist/index.cjs.js
CHANGED
|
@@ -7,7 +7,6 @@ var flattenChildren = require('react-flatten-children');
|
|
|
7
7
|
var mergeRefs = require('react-merge-refs');
|
|
8
8
|
var reactJsonReconciler = require('react-json-reconciler');
|
|
9
9
|
var player = require('@player-ui/player');
|
|
10
|
-
var signale = require('signale');
|
|
11
10
|
var dequal = require('dequal');
|
|
12
11
|
var tapableTs = require('tapable-ts');
|
|
13
12
|
var sourceMapJs = require('source-map-js');
|
|
@@ -17,7 +16,6 @@ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'defau
|
|
|
17
16
|
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
18
17
|
var flattenChildren__default = /*#__PURE__*/_interopDefaultLegacy(flattenChildren);
|
|
19
18
|
var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
|
|
20
|
-
var signale__default = /*#__PURE__*/_interopDefaultLegacy(signale);
|
|
21
19
|
|
|
22
20
|
const IDSuffixContext = React__default["default"].createContext("root");
|
|
23
21
|
const IndexSuffixStopContext = React__default["default"].createContext(false);
|
|
@@ -83,25 +81,25 @@ const OptionalIDSuffixProvider = (props) => {
|
|
|
83
81
|
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, props.children);
|
|
84
82
|
};
|
|
85
83
|
|
|
86
|
-
var __defProp$
|
|
87
|
-
var __defProps$
|
|
88
|
-
var __getOwnPropDescs$
|
|
89
|
-
var __getOwnPropSymbols$
|
|
90
|
-
var __hasOwnProp$
|
|
91
|
-
var __propIsEnum$
|
|
92
|
-
var __defNormalProp$
|
|
93
|
-
var __spreadValues$
|
|
84
|
+
var __defProp$5 = Object.defineProperty;
|
|
85
|
+
var __defProps$4 = Object.defineProperties;
|
|
86
|
+
var __getOwnPropDescs$4 = Object.getOwnPropertyDescriptors;
|
|
87
|
+
var __getOwnPropSymbols$5 = Object.getOwnPropertySymbols;
|
|
88
|
+
var __hasOwnProp$5 = Object.prototype.hasOwnProperty;
|
|
89
|
+
var __propIsEnum$5 = Object.prototype.propertyIsEnumerable;
|
|
90
|
+
var __defNormalProp$5 = (obj, key, value) => key in obj ? __defProp$5(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
91
|
+
var __spreadValues$5 = (a, b) => {
|
|
94
92
|
for (var prop in b || (b = {}))
|
|
95
|
-
if (__hasOwnProp$
|
|
96
|
-
__defNormalProp$
|
|
97
|
-
if (__getOwnPropSymbols$
|
|
98
|
-
for (var prop of __getOwnPropSymbols$
|
|
99
|
-
if (__propIsEnum$
|
|
100
|
-
__defNormalProp$
|
|
93
|
+
if (__hasOwnProp$5.call(b, prop))
|
|
94
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
95
|
+
if (__getOwnPropSymbols$5)
|
|
96
|
+
for (var prop of __getOwnPropSymbols$5(b)) {
|
|
97
|
+
if (__propIsEnum$5.call(b, prop))
|
|
98
|
+
__defNormalProp$5(a, prop, b[prop]);
|
|
101
99
|
}
|
|
102
100
|
return a;
|
|
103
101
|
};
|
|
104
|
-
var __spreadProps$
|
|
102
|
+
var __spreadProps$4 = (a, b) => __defProps$4(a, __getOwnPropDescs$4(b));
|
|
105
103
|
const OpaqueIdentifier = Symbol("TemplateStringType");
|
|
106
104
|
const TemplateStringComponent = (props) => {
|
|
107
105
|
return React__default["default"].createElement("value", {
|
|
@@ -132,7 +130,7 @@ const createTemplateInstance = (options) => {
|
|
|
132
130
|
const element = React__default["default"].createElement(TemplateStringComponent, {
|
|
133
131
|
value: toString()
|
|
134
132
|
}, null);
|
|
135
|
-
return __spreadProps$
|
|
133
|
+
return __spreadProps$4(__spreadValues$5({}, element), {
|
|
136
134
|
[OpaqueIdentifier]: true,
|
|
137
135
|
toString,
|
|
138
136
|
toValue,
|
|
@@ -142,7 +140,7 @@ const createTemplateInstance = (options) => {
|
|
|
142
140
|
});
|
|
143
141
|
};
|
|
144
142
|
const createBindingTemplateInstance = (options) => {
|
|
145
|
-
const templateInstance = createTemplateInstance(__spreadProps$
|
|
143
|
+
const templateInstance = createTemplateInstance(__spreadProps$4(__spreadValues$5({}, options), {
|
|
146
144
|
toRefString: (context, value) => {
|
|
147
145
|
return `{{${value}}}`;
|
|
148
146
|
}
|
|
@@ -151,7 +149,7 @@ const createBindingTemplateInstance = (options) => {
|
|
|
151
149
|
return templateInstance;
|
|
152
150
|
};
|
|
153
151
|
const createExpressionTemplateInstance = (options) => {
|
|
154
|
-
const templateInstance = createTemplateInstance(__spreadProps$
|
|
152
|
+
const templateInstance = createTemplateInstance(__spreadProps$4(__spreadValues$5({}, options), {
|
|
155
153
|
toRefString: (contextOptions, value) => {
|
|
156
154
|
if ((contextOptions == null ? void 0 : contextOptions.nestedContext) === "expression") {
|
|
157
155
|
return value;
|
|
@@ -178,54 +176,60 @@ const expression = (strings, ...nested) => {
|
|
|
178
176
|
});
|
|
179
177
|
};
|
|
180
178
|
const isTemplateStringInstance = (val) => {
|
|
181
|
-
return typeof val === "object" && val[OpaqueIdentifier] === true;
|
|
179
|
+
return val !== null && typeof val === "object" && val[OpaqueIdentifier] === true;
|
|
182
180
|
};
|
|
183
181
|
|
|
184
|
-
var __defProp$
|
|
185
|
-
var __defProps$
|
|
186
|
-
var __getOwnPropDescs$
|
|
187
|
-
var __getOwnPropSymbols$
|
|
188
|
-
var __hasOwnProp$
|
|
189
|
-
var __propIsEnum$
|
|
190
|
-
var __defNormalProp$
|
|
191
|
-
var __spreadValues$
|
|
182
|
+
var __defProp$4 = Object.defineProperty;
|
|
183
|
+
var __defProps$3 = Object.defineProperties;
|
|
184
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
185
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
186
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
187
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
188
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
189
|
+
var __spreadValues$4 = (a, b) => {
|
|
192
190
|
for (var prop in b || (b = {}))
|
|
193
|
-
if (__hasOwnProp$
|
|
194
|
-
__defNormalProp$
|
|
195
|
-
if (__getOwnPropSymbols$
|
|
196
|
-
for (var prop of __getOwnPropSymbols$
|
|
197
|
-
if (__propIsEnum$
|
|
198
|
-
__defNormalProp$
|
|
191
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
192
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
193
|
+
if (__getOwnPropSymbols$4)
|
|
194
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
195
|
+
if (__propIsEnum$4.call(b, prop))
|
|
196
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
199
197
|
}
|
|
200
198
|
return a;
|
|
201
199
|
};
|
|
202
|
-
var __spreadProps$
|
|
200
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
203
201
|
function toArray(val) {
|
|
204
202
|
return Array.isArray(val) ? val : [val];
|
|
205
203
|
}
|
|
206
|
-
function toJsonElement(value,
|
|
207
|
-
|
|
204
|
+
function toJsonElement(value, indexOrKey, options) {
|
|
205
|
+
var _a;
|
|
206
|
+
const indexProp = typeof indexOrKey === "number" ? { key: indexOrKey } : null;
|
|
208
207
|
if (Array.isArray(value)) {
|
|
209
|
-
return /* @__PURE__ */ React__default["default"].createElement("array", __spreadValues$
|
|
208
|
+
return /* @__PURE__ */ React__default["default"].createElement("array", __spreadValues$4({}, indexProp), value.map((item, idx) => toJsonElement(item, idx, options)));
|
|
210
209
|
}
|
|
211
210
|
if (isTemplateStringInstance(value)) {
|
|
212
|
-
|
|
211
|
+
if (typeof indexOrKey === "string" && ((_a = options == null ? void 0 : options.propertiesToSkip) == null ? void 0 : _a.includes(indexOrKey))) {
|
|
212
|
+
return /* @__PURE__ */ React__default["default"].createElement("value", __spreadValues$4({}, indexProp), value.toValue());
|
|
213
|
+
}
|
|
214
|
+
return /* @__PURE__ */ React__default["default"].createElement("value", __spreadValues$4({}, indexProp), value.toRefString());
|
|
213
215
|
}
|
|
214
216
|
if (typeof value === "object" && value !== null) {
|
|
215
|
-
return /* @__PURE__ */ React__default["default"].createElement("obj", __spreadValues$
|
|
217
|
+
return /* @__PURE__ */ React__default["default"].createElement("obj", __spreadValues$4({}, indexProp), Object.keys(value).map((key) => /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
216
218
|
key,
|
|
217
219
|
name: key
|
|
218
|
-
}, toJsonElement(value[key]))));
|
|
220
|
+
}, toJsonElement(value[key], key, options))));
|
|
219
221
|
}
|
|
220
|
-
return /* @__PURE__ */ React__default["default"].createElement("value", __spreadProps$
|
|
222
|
+
return /* @__PURE__ */ React__default["default"].createElement("value", __spreadProps$3(__spreadValues$4({}, indexProp), {
|
|
221
223
|
value
|
|
222
224
|
}));
|
|
223
225
|
}
|
|
224
|
-
function toJsonProperties(value) {
|
|
225
|
-
return Object.keys(value).map((key) =>
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
226
|
+
function toJsonProperties(value, options = { propertiesToSkip: ["applicability"] }) {
|
|
227
|
+
return Object.keys(value).map((key) => {
|
|
228
|
+
return /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
229
|
+
key,
|
|
230
|
+
name: key
|
|
231
|
+
}, toJsonElement(value[key], key, options));
|
|
232
|
+
});
|
|
229
233
|
}
|
|
230
234
|
function normalizeText(options) {
|
|
231
235
|
const { node, TextComp } = options;
|
|
@@ -246,36 +250,36 @@ function normalizeToCollection(options) {
|
|
|
246
250
|
}
|
|
247
251
|
return /* @__PURE__ */ React__default["default"].createElement(CollectionComp, null, node);
|
|
248
252
|
}
|
|
249
|
-
return normalizeText(__spreadProps$
|
|
253
|
+
return normalizeText(__spreadProps$3(__spreadValues$4({}, options), { node }));
|
|
250
254
|
}
|
|
251
255
|
|
|
252
|
-
var __defProp$
|
|
253
|
-
var __defProps$
|
|
254
|
-
var __getOwnPropDescs$
|
|
255
|
-
var __getOwnPropSymbols$
|
|
256
|
-
var __hasOwnProp$
|
|
257
|
-
var __propIsEnum$
|
|
258
|
-
var __defNormalProp$
|
|
259
|
-
var __spreadValues$
|
|
256
|
+
var __defProp$3 = Object.defineProperty;
|
|
257
|
+
var __defProps$2 = Object.defineProperties;
|
|
258
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
259
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
260
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
261
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
262
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
263
|
+
var __spreadValues$3 = (a, b) => {
|
|
260
264
|
for (var prop in b || (b = {}))
|
|
261
|
-
if (__hasOwnProp$
|
|
262
|
-
__defNormalProp$
|
|
263
|
-
if (__getOwnPropSymbols$
|
|
264
|
-
for (var prop of __getOwnPropSymbols$
|
|
265
|
-
if (__propIsEnum$
|
|
266
|
-
__defNormalProp$
|
|
265
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
266
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
267
|
+
if (__getOwnPropSymbols$3)
|
|
268
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
269
|
+
if (__propIsEnum$3.call(b, prop))
|
|
270
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
267
271
|
}
|
|
268
272
|
return a;
|
|
269
273
|
};
|
|
270
|
-
var __spreadProps$
|
|
274
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
271
275
|
var __objRest = (source, exclude) => {
|
|
272
276
|
var target = {};
|
|
273
277
|
for (var prop in source)
|
|
274
|
-
if (__hasOwnProp$
|
|
278
|
+
if (__hasOwnProp$3.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
275
279
|
target[prop] = source[prop];
|
|
276
|
-
if (source != null && __getOwnPropSymbols$
|
|
277
|
-
for (var prop of __getOwnPropSymbols$
|
|
278
|
-
if (exclude.indexOf(prop) < 0 && __propIsEnum$
|
|
280
|
+
if (source != null && __getOwnPropSymbols$3)
|
|
281
|
+
for (var prop of __getOwnPropSymbols$3(source)) {
|
|
282
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$3.call(source, prop))
|
|
279
283
|
target[prop] = source[prop];
|
|
280
284
|
}
|
|
281
285
|
return target;
|
|
@@ -301,7 +305,7 @@ const Asset = React__default["default"].forwardRef((props, ref) => {
|
|
|
301
305
|
const slotContext = React__default["default"].useContext(SlotContext);
|
|
302
306
|
const localRef = React__default["default"].useRef(null);
|
|
303
307
|
const Wrapper = (slotContext == null ? void 0 : slotContext.wrapInAsset) ? AssetWrapper : React__default["default"].Fragment;
|
|
304
|
-
return /* @__PURE__ */ React__default["default"].createElement(Wrapper, __spreadValues$
|
|
308
|
+
return /* @__PURE__ */ React__default["default"].createElement(Wrapper, __spreadValues$3({
|
|
305
309
|
ref: (slotContext == null ? void 0 : slotContext.wrapInAsset) ? mergeRefs__default["default"]([ref, localRef]) : void 0
|
|
306
310
|
}, (slotContext == null ? void 0 : slotContext.wrapInAsset) && (slotContext == null ? void 0 : slotContext.additionalProperties) ? slotContext == null ? void 0 : slotContext.additionalProperties : {}), /* @__PURE__ */ React__default["default"].createElement(OptionalIDSuffixProvider, {
|
|
307
311
|
wrapperRef: localRef
|
|
@@ -318,13 +322,28 @@ const Asset = React__default["default"].forwardRef((props, ref) => {
|
|
|
318
322
|
}, type), applicability !== void 0 && /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
319
323
|
name: "applicability"
|
|
320
324
|
}, /* @__PURE__ */ React__default["default"].createElement("value", {
|
|
321
|
-
value: typeof applicability === "boolean" ? applicability : applicability.
|
|
325
|
+
value: typeof applicability === "boolean" ? applicability : applicability.toValue()
|
|
322
326
|
})), toJsonProperties(rest), children)))));
|
|
323
327
|
});
|
|
324
328
|
Asset.defaultProps = {
|
|
325
329
|
id: void 0,
|
|
326
330
|
children: void 0
|
|
327
331
|
};
|
|
332
|
+
const View = React__default["default"].forwardRef((props, ref) => {
|
|
333
|
+
const _a = props, { validation, children } = _a, rest = __objRest(_a, ["validation", "children"]);
|
|
334
|
+
return /* @__PURE__ */ React__default["default"].createElement(Asset, __spreadValues$3({
|
|
335
|
+
ref
|
|
336
|
+
}, rest), validation && /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
337
|
+
key: "validation",
|
|
338
|
+
name: "validation"
|
|
339
|
+
}, toJsonElement(validation, "validation", {
|
|
340
|
+
propertiesToSkip: ["ref"]
|
|
341
|
+
})), children);
|
|
342
|
+
});
|
|
343
|
+
View.defaultProps = {
|
|
344
|
+
id: void 0,
|
|
345
|
+
children: void 0
|
|
346
|
+
};
|
|
328
347
|
const Slot = (props) => {
|
|
329
348
|
var _a, _b;
|
|
330
349
|
const { TextComp, CollectionComp } = props;
|
|
@@ -360,31 +379,31 @@ const Slot = (props) => {
|
|
|
360
379
|
function createSlot(options) {
|
|
361
380
|
return (props) => {
|
|
362
381
|
const _a = props, { children } = _a, other = __objRest(_a, ["children"]);
|
|
363
|
-
return /* @__PURE__ */ React__default["default"].createElement(Slot, __spreadProps$
|
|
382
|
+
return /* @__PURE__ */ React__default["default"].createElement(Slot, __spreadProps$2(__spreadValues$3({}, options), {
|
|
364
383
|
additionalProperties: other
|
|
365
384
|
}), children);
|
|
366
385
|
};
|
|
367
386
|
}
|
|
368
387
|
|
|
369
|
-
var __defProp$
|
|
370
|
-
var __defProps = Object.defineProperties;
|
|
371
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
372
|
-
var __getOwnPropSymbols$
|
|
373
|
-
var __hasOwnProp$
|
|
374
|
-
var __propIsEnum$
|
|
375
|
-
var __defNormalProp$
|
|
376
|
-
var __spreadValues$
|
|
388
|
+
var __defProp$2 = Object.defineProperty;
|
|
389
|
+
var __defProps$1 = Object.defineProperties;
|
|
390
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
391
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
392
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
393
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
394
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
395
|
+
var __spreadValues$2 = (a, b) => {
|
|
377
396
|
for (var prop in b || (b = {}))
|
|
378
|
-
if (__hasOwnProp$
|
|
379
|
-
__defNormalProp$
|
|
380
|
-
if (__getOwnPropSymbols$
|
|
381
|
-
for (var prop of __getOwnPropSymbols$
|
|
382
|
-
if (__propIsEnum$
|
|
383
|
-
__defNormalProp$
|
|
397
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
398
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
399
|
+
if (__getOwnPropSymbols$2)
|
|
400
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
401
|
+
if (__propIsEnum$2.call(b, prop))
|
|
402
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
384
403
|
}
|
|
385
404
|
return a;
|
|
386
405
|
};
|
|
387
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
406
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
388
407
|
const SwitchContext = React__default["default"].createContext({});
|
|
389
408
|
const Switch = (props) => {
|
|
390
409
|
const slotContext = React__default["default"].useContext(SlotContext);
|
|
@@ -392,7 +411,7 @@ const Switch = (props) => {
|
|
|
392
411
|
return /* @__PURE__ */ React__default["default"].createElement("obj", {
|
|
393
412
|
ref: propertyNode
|
|
394
413
|
}, /* @__PURE__ */ React__default["default"].createElement(SwitchContext.Provider, {
|
|
395
|
-
value: __spreadProps(__spreadValues$
|
|
414
|
+
value: __spreadProps$1(__spreadValues$2({}, props), {
|
|
396
415
|
TextComp: slotContext == null ? void 0 : slotContext.TextComp,
|
|
397
416
|
CollectionComp: slotContext == null ? void 0 : slotContext.CollectionComp
|
|
398
417
|
})
|
|
@@ -444,7 +463,7 @@ const Case = (props) => {
|
|
|
444
463
|
})), /* @__PURE__ */ React__default["default"].createElement(IDSuffixProvider, {
|
|
445
464
|
suffix: `${switchContext.isDynamic ? "dynamicSwitch" : "staticSwitch"}-${caseIndex}`
|
|
446
465
|
}, /* @__PURE__ */ React__default["default"].createElement(SlotContext.Provider, {
|
|
447
|
-
value: slotContext ? __spreadProps(__spreadValues$
|
|
466
|
+
value: slotContext ? __spreadProps$1(__spreadValues$2({}, slotContext), { wrapInAsset: false }) : void 0
|
|
448
467
|
}, /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
449
468
|
name: "asset"
|
|
450
469
|
}, normalizeToCollection({
|
|
@@ -516,7 +535,9 @@ const getParentProperty = (node) => {
|
|
|
516
535
|
}
|
|
517
536
|
};
|
|
518
537
|
const Template = (props) => {
|
|
538
|
+
var _a;
|
|
519
539
|
const baseContext = React__default["default"].useContext(TemplateContext);
|
|
540
|
+
const dynamicProp = (_a = props.dynamic) != null ? _a : false;
|
|
520
541
|
const [outputProp, setOutputProp] = React__default["default"].useState(props.output);
|
|
521
542
|
const proxyRef = React__default["default"].useRef(null);
|
|
522
543
|
const valueRef = React__default["default"].useRef(null);
|
|
@@ -551,19 +572,40 @@ const Template = (props) => {
|
|
|
551
572
|
name: "output"
|
|
552
573
|
}, outputProp), /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
553
574
|
name: "value"
|
|
554
|
-
}, props.children)
|
|
575
|
+
}, props.children), dynamicProp && /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
576
|
+
name: "dynamic"
|
|
577
|
+
}, toJsonElement(dynamicProp))))), outputElement), /* @__PURE__ */ React__default["default"].createElement("value", {
|
|
555
578
|
ref: valueRef,
|
|
556
579
|
value: void 0
|
|
557
580
|
}));
|
|
558
581
|
};
|
|
559
582
|
|
|
583
|
+
var __defProp$1 = Object.defineProperty;
|
|
584
|
+
var __defProps = Object.defineProperties;
|
|
585
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
586
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
587
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
588
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
589
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
590
|
+
var __spreadValues$1 = (a, b2) => {
|
|
591
|
+
for (var prop in b2 || (b2 = {}))
|
|
592
|
+
if (__hasOwnProp$1.call(b2, prop))
|
|
593
|
+
__defNormalProp$1(a, prop, b2[prop]);
|
|
594
|
+
if (__getOwnPropSymbols$1)
|
|
595
|
+
for (var prop of __getOwnPropSymbols$1(b2)) {
|
|
596
|
+
if (__propIsEnum$1.call(b2, prop))
|
|
597
|
+
__defNormalProp$1(a, prop, b2[prop]);
|
|
598
|
+
}
|
|
599
|
+
return a;
|
|
600
|
+
};
|
|
601
|
+
var __spreadProps = (a, b2) => __defProps(a, __getOwnPropDescs(b2));
|
|
560
602
|
const bindingSymbol = Symbol("binding");
|
|
561
603
|
const SchemaTypeName = Symbol("Schema Rename");
|
|
562
604
|
const isTypeDef = (property) => {
|
|
563
605
|
return property.type !== void 0;
|
|
564
606
|
};
|
|
565
607
|
class SchemaGenerator {
|
|
566
|
-
constructor() {
|
|
608
|
+
constructor(logger) {
|
|
567
609
|
this.hooks = {
|
|
568
610
|
createSchemaNode: new tapableTs.SyncWaterfallHook()
|
|
569
611
|
};
|
|
@@ -572,10 +614,10 @@ class SchemaGenerator {
|
|
|
572
614
|
ROOT: {}
|
|
573
615
|
};
|
|
574
616
|
this.children = [];
|
|
575
|
-
this.
|
|
617
|
+
this.generatedDataTypes.clear();
|
|
576
618
|
Object.keys(schema).forEach((property) => {
|
|
577
619
|
const subType = schema[property];
|
|
578
|
-
newSchema.ROOT[property] = this.hooks.createSchemaNode.call(this.
|
|
620
|
+
newSchema.ROOT[property] = this.hooks.createSchemaNode.call(this.processChild(property, subType), subType);
|
|
579
621
|
});
|
|
580
622
|
while (this.children.length > 0) {
|
|
581
623
|
const c = this.children.pop();
|
|
@@ -586,7 +628,7 @@ class SchemaGenerator {
|
|
|
586
628
|
const typeDef = {};
|
|
587
629
|
Object.keys(child).forEach((property) => {
|
|
588
630
|
const subType = child[property];
|
|
589
|
-
typeDef[property] = this.hooks.createSchemaNode.call(this.
|
|
631
|
+
typeDef[property] = this.hooks.createSchemaNode.call(this.processChild(property, subType), subType);
|
|
590
632
|
});
|
|
591
633
|
newSchema[name] = typeDef;
|
|
592
634
|
}
|
|
@@ -598,17 +640,18 @@ class SchemaGenerator {
|
|
|
598
640
|
};
|
|
599
641
|
};
|
|
600
642
|
this.children = [];
|
|
601
|
-
this.
|
|
643
|
+
this.generatedDataTypes = new Map();
|
|
644
|
+
this.logger = logger != null ? logger : console;
|
|
602
645
|
}
|
|
603
|
-
|
|
604
|
-
var _a, _b;
|
|
646
|
+
processChild(property, subType) {
|
|
647
|
+
var _a, _b, _c;
|
|
605
648
|
if (isTypeDef(subType)) {
|
|
606
649
|
return subType;
|
|
607
650
|
}
|
|
608
651
|
let intermediateType;
|
|
609
652
|
if (Array.isArray(subType)) {
|
|
610
653
|
if (subType.length > 1) {
|
|
611
|
-
|
|
654
|
+
this.logger.warn(`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`);
|
|
612
655
|
}
|
|
613
656
|
const subTypeName = (_a = subType[0][SchemaTypeName]) != null ? _a : property;
|
|
614
657
|
intermediateType = this.makePlaceholderArrayType(subTypeName);
|
|
@@ -618,13 +661,23 @@ class SchemaGenerator {
|
|
|
618
661
|
intermediateType = this.makePlaceholderType(subTypeName);
|
|
619
662
|
this.children.push({ name: intermediateType.type, child: subType });
|
|
620
663
|
}
|
|
621
|
-
if (this.
|
|
622
|
-
|
|
623
|
-
|
|
664
|
+
if (this.generatedDataTypes.has(intermediateType.type)) {
|
|
665
|
+
const generatedType = this.generatedDataTypes.get(intermediateType.type);
|
|
666
|
+
if (!dequal.dequal(subType, (_c = this.generatedDataTypes.get(intermediateType.type)) == null ? void 0 : _c.node)) {
|
|
667
|
+
generatedType.count += 1;
|
|
668
|
+
const newIntermediateType = __spreadProps(__spreadValues$1({}, intermediateType), {
|
|
669
|
+
type: `${intermediateType.type}${generatedType.count}`
|
|
670
|
+
});
|
|
671
|
+
this.logger.warn(`WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`);
|
|
672
|
+
intermediateType = newIntermediateType;
|
|
673
|
+
this.children.pop();
|
|
674
|
+
this.children.push({ name: intermediateType.type, child: subType });
|
|
624
675
|
}
|
|
625
|
-
this.children.pop();
|
|
626
676
|
}
|
|
627
|
-
this.
|
|
677
|
+
this.generatedDataTypes.set(intermediateType.type, {
|
|
678
|
+
node: subType,
|
|
679
|
+
count: 1
|
|
680
|
+
});
|
|
628
681
|
return intermediateType;
|
|
629
682
|
}
|
|
630
683
|
makePlaceholderArrayType(typeName) {
|
|
@@ -756,10 +809,14 @@ const mergeSourceMaps = (sourceMaps, generated) => {
|
|
|
756
809
|
return generator.toString();
|
|
757
810
|
};
|
|
758
811
|
class DSLCompiler {
|
|
759
|
-
constructor() {
|
|
812
|
+
constructor(logger) {
|
|
760
813
|
this.hooks = {
|
|
761
|
-
schemaGenerator: new tapableTs.SyncHook()
|
|
814
|
+
schemaGenerator: new tapableTs.SyncHook(),
|
|
815
|
+
preProcessFlow: new tapableTs.AsyncSeriesWaterfallHook(),
|
|
816
|
+
postProcessFlow: new tapableTs.AsyncSeriesWaterfallHook(),
|
|
817
|
+
onEnd: new tapableTs.AsyncSeriesHook()
|
|
762
818
|
};
|
|
819
|
+
this.logger = logger != null ? logger : console;
|
|
763
820
|
}
|
|
764
821
|
serialize(value) {
|
|
765
822
|
return __async(this, null, function* () {
|
|
@@ -767,6 +824,8 @@ class DSLCompiler {
|
|
|
767
824
|
if (typeof value !== "object" || value === null) {
|
|
768
825
|
throw new Error("Unable to serialize non-object");
|
|
769
826
|
}
|
|
827
|
+
const schemaGenerator = new SchemaGenerator(this.logger);
|
|
828
|
+
this.hooks.schemaGenerator.call(schemaGenerator);
|
|
770
829
|
if (React__default["default"].isValidElement(value)) {
|
|
771
830
|
const { jsonValue, sourceMap } = yield reactJsonReconciler.render(value, {
|
|
772
831
|
collectSourceMap: true
|
|
@@ -777,9 +836,10 @@ class DSLCompiler {
|
|
|
777
836
|
contentType: "view"
|
|
778
837
|
};
|
|
779
838
|
}
|
|
780
|
-
|
|
839
|
+
const preProcessedValue = yield this.hooks.preProcessFlow.call(value);
|
|
840
|
+
if ("navigation" in preProcessedValue) {
|
|
781
841
|
const allSourceMaps = [];
|
|
782
|
-
const copiedValue = __spreadValues({},
|
|
842
|
+
const copiedValue = __spreadValues({}, preProcessedValue);
|
|
783
843
|
copiedValue.views = yield Promise.all((_b = (_a = copiedValue == null ? void 0 : copiedValue.views) == null ? void 0 : _a.map((node) => __async(this, null, function* () {
|
|
784
844
|
const { jsonValue, sourceMap, stringValue } = yield reactJsonReconciler.render(node, {
|
|
785
845
|
collectSourceMap: true
|
|
@@ -796,13 +856,13 @@ class DSLCompiler {
|
|
|
796
856
|
}
|
|
797
857
|
return jsonValue;
|
|
798
858
|
}))) != null ? _b : []);
|
|
799
|
-
if ("navigation" in
|
|
800
|
-
Object.entries(
|
|
859
|
+
if ("navigation" in preProcessedValue) {
|
|
860
|
+
Object.entries(preProcessedValue.navigation).forEach(([navKey, node]) => {
|
|
801
861
|
if (typeof node === "object") {
|
|
802
862
|
Object.entries(node).forEach(([nodeKey, flowNode]) => {
|
|
803
863
|
var _a2, _b2, _c, _d;
|
|
804
864
|
if (flowNode && typeof flowNode === "object" && "state_type" in flowNode && flowNode.state_type === "VIEW" && React__default["default"].isValidElement(flowNode.ref)) {
|
|
805
|
-
const actualViewIndex = (_b2 = (_a2 =
|
|
865
|
+
const actualViewIndex = (_b2 = (_a2 = preProcessedValue.views) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b2.call(_a2, flowNode.ref);
|
|
806
866
|
if (actualViewIndex !== void 0 && actualViewIndex > -1) {
|
|
807
867
|
const actualId = (_d = (_c = copiedValue.views) == null ? void 0 : _c[actualViewIndex]) == null ? void 0 : _d.id;
|
|
808
868
|
copiedValue.navigation[navKey][nodeKey].ref = actualId;
|
|
@@ -811,20 +871,22 @@ class DSLCompiler {
|
|
|
811
871
|
});
|
|
812
872
|
}
|
|
813
873
|
});
|
|
874
|
+
if ("schema" in preProcessedValue) {
|
|
875
|
+
copiedValue.schema = schemaGenerator.toSchema(copiedValue.schema);
|
|
876
|
+
}
|
|
814
877
|
copiedValue.navigation = parseNavigationExpressions(copiedValue.navigation);
|
|
815
878
|
}
|
|
816
879
|
if (value) {
|
|
880
|
+
const postProcessFlow = yield this.hooks.postProcessFlow.call(copiedValue);
|
|
817
881
|
return {
|
|
818
|
-
value:
|
|
882
|
+
value: postProcessFlow,
|
|
819
883
|
contentType: "flow",
|
|
820
884
|
sourceMap: mergeSourceMaps(allSourceMaps, JSON.stringify(copiedValue, null, 2))
|
|
821
885
|
};
|
|
822
886
|
}
|
|
823
887
|
}
|
|
824
|
-
const schemaGenerator = new SchemaGenerator();
|
|
825
|
-
this.hooks.schemaGenerator.call(schemaGenerator);
|
|
826
888
|
return {
|
|
827
|
-
value: schemaGenerator.toSchema(
|
|
889
|
+
value: schemaGenerator.toSchema(preProcessedValue),
|
|
828
890
|
contentType: "schema"
|
|
829
891
|
};
|
|
830
892
|
});
|
|
@@ -848,6 +910,7 @@ exports.Switch = Switch;
|
|
|
848
910
|
exports.Template = Template;
|
|
849
911
|
exports.TemplateContext = TemplateContext;
|
|
850
912
|
exports.TemplateStringComponent = TemplateStringComponent;
|
|
913
|
+
exports.View = View;
|
|
851
914
|
exports.binding = binding;
|
|
852
915
|
exports.createSlot = createSlot;
|
|
853
916
|
exports.expression = expression;
|