@player-tools/dsl 0.0.2-next.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/README.md +9 -0
- package/dist/index.cjs.js +865 -0
- package/dist/index.d.ts +324 -0
- package/dist/index.esm.js +818 -0
- package/package.json +51 -0
- package/src/auto-id.tsx +136 -0
- package/src/compiler/compiler.ts +219 -0
- package/src/compiler/index.ts +2 -0
- package/src/compiler/schema.ts +250 -0
- package/src/compiler/types.ts +18 -0
- package/src/components.tsx +234 -0
- package/src/index.ts +10 -0
- package/src/string-templates/index.ts +172 -0
- package/src/switch.tsx +136 -0
- package/src/template.tsx +186 -0
- package/src/types.ts +81 -0
- package/src/utils.tsx +109 -0
|
@@ -0,0 +1,865 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var flattenChildren = require('react-flatten-children');
|
|
7
|
+
var mergeRefs = require('react-merge-refs');
|
|
8
|
+
var reactJsonReconciler = require('react-json-reconciler');
|
|
9
|
+
var signale = require('signale');
|
|
10
|
+
var dequal = require('dequal');
|
|
11
|
+
var tapableTs = require('tapable-ts');
|
|
12
|
+
var sourceMapJs = require('source-map-js');
|
|
13
|
+
|
|
14
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
15
|
+
|
|
16
|
+
var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
|
|
17
|
+
var flattenChildren__default = /*#__PURE__*/_interopDefaultLegacy(flattenChildren);
|
|
18
|
+
var mergeRefs__default = /*#__PURE__*/_interopDefaultLegacy(mergeRefs);
|
|
19
|
+
var signale__default = /*#__PURE__*/_interopDefaultLegacy(signale);
|
|
20
|
+
|
|
21
|
+
const IDSuffixContext = React__default["default"].createContext("root");
|
|
22
|
+
const IndexSuffixStopContext = React__default["default"].createContext(false);
|
|
23
|
+
const useGetIdPrefix = () => {
|
|
24
|
+
return React__default["default"].useContext(IDSuffixContext);
|
|
25
|
+
};
|
|
26
|
+
const IDSuffixProvider = (props) => {
|
|
27
|
+
const currentPrefix = useGetIdPrefix();
|
|
28
|
+
return /* @__PURE__ */ React__default["default"].createElement(IDSuffixContext.Provider, {
|
|
29
|
+
value: [
|
|
30
|
+
currentPrefix === "root" ? void 0 : currentPrefix,
|
|
31
|
+
props.suffix
|
|
32
|
+
].filter(Boolean).join("-")
|
|
33
|
+
}, props.children);
|
|
34
|
+
};
|
|
35
|
+
const IDProvider = (props) => {
|
|
36
|
+
if (props.id) {
|
|
37
|
+
return /* @__PURE__ */ React__default["default"].createElement(IDSuffixContext.Provider, {
|
|
38
|
+
value: props.id
|
|
39
|
+
}, props.children);
|
|
40
|
+
}
|
|
41
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, props.children);
|
|
42
|
+
};
|
|
43
|
+
const useIndexInSlot = (ref) => {
|
|
44
|
+
const [index, setIndex] = React__default["default"].useState(-1);
|
|
45
|
+
const slotContext = React__default["default"].useContext(SlotContext);
|
|
46
|
+
React__default["default"].useEffect(() => {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
if (!(slotContext == null ? void 0 : slotContext.isArray)) {
|
|
49
|
+
throw new Error("Cannot get index in non-array slot");
|
|
50
|
+
}
|
|
51
|
+
if (ref.current && ((_b = (_a = slotContext == null ? void 0 : slotContext.ref.current) == null ? void 0 : _a.valueNode) == null ? void 0 : _b.type) === "array") {
|
|
52
|
+
const allChildren = reactJsonReconciler.flattenNodes(slotContext.ref.current.valueNode.children);
|
|
53
|
+
const foundIndex = allChildren.indexOf(ref.current);
|
|
54
|
+
if (foundIndex !== index) {
|
|
55
|
+
setIndex(foundIndex);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}, [index, ref, slotContext == null ? void 0 : slotContext.isArray, slotContext == null ? void 0 : slotContext.ref]);
|
|
59
|
+
return index;
|
|
60
|
+
};
|
|
61
|
+
const IDSuffixIndexProvider = (props) => {
|
|
62
|
+
var _a;
|
|
63
|
+
const slotIndex = useIndexInSlot(props.wrapperRef);
|
|
64
|
+
const stopIndex = React__default["default"].useContext(IndexSuffixStopContext);
|
|
65
|
+
if (stopIndex) {
|
|
66
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, props.children);
|
|
67
|
+
}
|
|
68
|
+
return /* @__PURE__ */ React__default["default"].createElement(IDSuffixProvider, {
|
|
69
|
+
suffix: (_a = props.templateIndex) != null ? _a : String(slotIndex)
|
|
70
|
+
}, /* @__PURE__ */ React__default["default"].createElement(IndexSuffixStopContext.Provider, {
|
|
71
|
+
value: true
|
|
72
|
+
}, props.children));
|
|
73
|
+
};
|
|
74
|
+
const OptionalIDSuffixProvider = (props) => {
|
|
75
|
+
const slotContext = React__default["default"].useContext(SlotContext);
|
|
76
|
+
if (slotContext == null ? void 0 : slotContext.isArray) {
|
|
77
|
+
return /* @__PURE__ */ React__default["default"].createElement(IDSuffixIndexProvider, {
|
|
78
|
+
wrapperRef: props.wrapperRef,
|
|
79
|
+
templateIndex: props.templateIndex
|
|
80
|
+
}, props.children);
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, props.children);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
var __defProp$4 = Object.defineProperty;
|
|
86
|
+
var __defProps$3 = Object.defineProperties;
|
|
87
|
+
var __getOwnPropDescs$3 = Object.getOwnPropertyDescriptors;
|
|
88
|
+
var __getOwnPropSymbols$4 = Object.getOwnPropertySymbols;
|
|
89
|
+
var __hasOwnProp$4 = Object.prototype.hasOwnProperty;
|
|
90
|
+
var __propIsEnum$4 = Object.prototype.propertyIsEnumerable;
|
|
91
|
+
var __defNormalProp$4 = (obj, key, value) => key in obj ? __defProp$4(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
92
|
+
var __spreadValues$4 = (a, b) => {
|
|
93
|
+
for (var prop in b || (b = {}))
|
|
94
|
+
if (__hasOwnProp$4.call(b, prop))
|
|
95
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
96
|
+
if (__getOwnPropSymbols$4)
|
|
97
|
+
for (var prop of __getOwnPropSymbols$4(b)) {
|
|
98
|
+
if (__propIsEnum$4.call(b, prop))
|
|
99
|
+
__defNormalProp$4(a, prop, b[prop]);
|
|
100
|
+
}
|
|
101
|
+
return a;
|
|
102
|
+
};
|
|
103
|
+
var __spreadProps$3 = (a, b) => __defProps$3(a, __getOwnPropDescs$3(b));
|
|
104
|
+
const OpaqueIdentifier = Symbol("TemplateStringType");
|
|
105
|
+
const TemplateStringComponent = (props) => {
|
|
106
|
+
return React__default["default"].createElement("value", {
|
|
107
|
+
value: props.value
|
|
108
|
+
}, null);
|
|
109
|
+
};
|
|
110
|
+
const createTemplateInstance = (options) => {
|
|
111
|
+
const value = options.strings.reduce((sum, next, i) => {
|
|
112
|
+
var _a;
|
|
113
|
+
const element2 = options.other[i];
|
|
114
|
+
if (typeof element2 === "string") {
|
|
115
|
+
return sum + next + element2;
|
|
116
|
+
}
|
|
117
|
+
return sum + next + ((_a = element2 == null ? void 0 : element2.toRefString(options)) != null ? _a : "");
|
|
118
|
+
}, "");
|
|
119
|
+
const toString = () => {
|
|
120
|
+
return options.toRefString({}, value);
|
|
121
|
+
};
|
|
122
|
+
const toValue = () => {
|
|
123
|
+
return value;
|
|
124
|
+
};
|
|
125
|
+
const element = React__default["default"].createElement(TemplateStringComponent, {
|
|
126
|
+
value: toString()
|
|
127
|
+
}, null);
|
|
128
|
+
return __spreadProps$3(__spreadValues$4({}, element), {
|
|
129
|
+
[OpaqueIdentifier]: true,
|
|
130
|
+
toString,
|
|
131
|
+
toValue,
|
|
132
|
+
toRefString: (refStringOptions) => {
|
|
133
|
+
return options.toRefString(refStringOptions, value);
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
};
|
|
137
|
+
const createBindingTemplateInstance = (options) => {
|
|
138
|
+
const templateInstance = createTemplateInstance(__spreadProps$3(__spreadValues$4({}, options), {
|
|
139
|
+
toRefString: (context, value) => {
|
|
140
|
+
return `{{${value}}}`;
|
|
141
|
+
}
|
|
142
|
+
}));
|
|
143
|
+
templateInstance.__type = "binding";
|
|
144
|
+
return templateInstance;
|
|
145
|
+
};
|
|
146
|
+
const createExpressionTemplateInstance = (options) => {
|
|
147
|
+
const templateInstance = createTemplateInstance(__spreadProps$3(__spreadValues$4({}, options), {
|
|
148
|
+
toRefString: (contextOptions, value) => {
|
|
149
|
+
if ((contextOptions == null ? void 0 : contextOptions.nestedContext) === "expression") {
|
|
150
|
+
return value;
|
|
151
|
+
}
|
|
152
|
+
const inBinding = (contextOptions == null ? void 0 : contextOptions.nestedContext) === "binding";
|
|
153
|
+
return `${inBinding ? "`" : "@["}${value}${inBinding ? "`" : "]@"}`;
|
|
154
|
+
}
|
|
155
|
+
}));
|
|
156
|
+
templateInstance.__type = "expression";
|
|
157
|
+
return templateInstance;
|
|
158
|
+
};
|
|
159
|
+
const binding = (strings, ...nested) => {
|
|
160
|
+
return createBindingTemplateInstance({
|
|
161
|
+
strings,
|
|
162
|
+
other: nested,
|
|
163
|
+
nestedContext: "binding"
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
const expression = (strings, ...nested) => {
|
|
167
|
+
return createExpressionTemplateInstance({
|
|
168
|
+
strings,
|
|
169
|
+
other: nested,
|
|
170
|
+
nestedContext: "expression"
|
|
171
|
+
});
|
|
172
|
+
};
|
|
173
|
+
const isTemplateStringInstance = (val) => {
|
|
174
|
+
return typeof val === "object" && val[OpaqueIdentifier] === true;
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
var __defProp$3 = Object.defineProperty;
|
|
178
|
+
var __defProps$2 = Object.defineProperties;
|
|
179
|
+
var __getOwnPropDescs$2 = Object.getOwnPropertyDescriptors;
|
|
180
|
+
var __getOwnPropSymbols$3 = Object.getOwnPropertySymbols;
|
|
181
|
+
var __hasOwnProp$3 = Object.prototype.hasOwnProperty;
|
|
182
|
+
var __propIsEnum$3 = Object.prototype.propertyIsEnumerable;
|
|
183
|
+
var __defNormalProp$3 = (obj, key, value) => key in obj ? __defProp$3(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
184
|
+
var __spreadValues$3 = (a, b) => {
|
|
185
|
+
for (var prop in b || (b = {}))
|
|
186
|
+
if (__hasOwnProp$3.call(b, prop))
|
|
187
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
188
|
+
if (__getOwnPropSymbols$3)
|
|
189
|
+
for (var prop of __getOwnPropSymbols$3(b)) {
|
|
190
|
+
if (__propIsEnum$3.call(b, prop))
|
|
191
|
+
__defNormalProp$3(a, prop, b[prop]);
|
|
192
|
+
}
|
|
193
|
+
return a;
|
|
194
|
+
};
|
|
195
|
+
var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
|
|
196
|
+
function toArray(val) {
|
|
197
|
+
return Array.isArray(val) ? val : [val];
|
|
198
|
+
}
|
|
199
|
+
function toJsonElement(value, index) {
|
|
200
|
+
const keyProp = index === void 0 ? null : { key: index };
|
|
201
|
+
if (Array.isArray(value)) {
|
|
202
|
+
return /* @__PURE__ */ React__default["default"].createElement("array", __spreadValues$3({}, keyProp), value.map((item, idx) => toJsonElement(item, idx)));
|
|
203
|
+
}
|
|
204
|
+
if (isTemplateStringInstance(value)) {
|
|
205
|
+
return /* @__PURE__ */ React__default["default"].createElement("value", __spreadValues$3({}, keyProp), value.toRefString());
|
|
206
|
+
}
|
|
207
|
+
if (typeof value === "object" && value !== null) {
|
|
208
|
+
return /* @__PURE__ */ React__default["default"].createElement("obj", __spreadValues$3({}, keyProp), Object.keys(value).map((key) => /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
209
|
+
key,
|
|
210
|
+
name: key
|
|
211
|
+
}, toJsonElement(value[key]))));
|
|
212
|
+
}
|
|
213
|
+
return /* @__PURE__ */ React__default["default"].createElement("value", __spreadProps$2(__spreadValues$3({}, keyProp), {
|
|
214
|
+
value
|
|
215
|
+
}));
|
|
216
|
+
}
|
|
217
|
+
function toJsonProperties(value) {
|
|
218
|
+
return Object.keys(value).map((key) => /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
219
|
+
key,
|
|
220
|
+
name: key
|
|
221
|
+
}, toJsonElement(value[key])));
|
|
222
|
+
}
|
|
223
|
+
function normalizeText(options) {
|
|
224
|
+
const { node, TextComp } = options;
|
|
225
|
+
const nodeArr = React__default["default"].Children.toArray(node);
|
|
226
|
+
if (nodeArr.every((n) => React__default["default"].isValidElement(n) && n.type !== TemplateStringComponent)) {
|
|
227
|
+
return node;
|
|
228
|
+
}
|
|
229
|
+
if (TextComp) {
|
|
230
|
+
return /* @__PURE__ */ React__default["default"].createElement(TextComp, null, nodeArr);
|
|
231
|
+
}
|
|
232
|
+
throw new Error(`Tried to convert node to Text Asset, but no Component was supplied.`);
|
|
233
|
+
}
|
|
234
|
+
function normalizeToCollection(options) {
|
|
235
|
+
const { node, CollectionComp } = options;
|
|
236
|
+
if (React__default["default"].Children.count(node) > 1 && React__default["default"].Children.toArray(node).every((n) => typeof n !== "string")) {
|
|
237
|
+
if (!CollectionComp) {
|
|
238
|
+
throw new Error(`Tried to convert array to a collection asset, but no Component was given.`);
|
|
239
|
+
}
|
|
240
|
+
return /* @__PURE__ */ React__default["default"].createElement(CollectionComp, null, node);
|
|
241
|
+
}
|
|
242
|
+
return normalizeText(__spreadProps$2(__spreadValues$3({}, options), { node }));
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
var __defProp$2 = Object.defineProperty;
|
|
246
|
+
var __defProps$1 = Object.defineProperties;
|
|
247
|
+
var __getOwnPropDescs$1 = Object.getOwnPropertyDescriptors;
|
|
248
|
+
var __getOwnPropSymbols$2 = Object.getOwnPropertySymbols;
|
|
249
|
+
var __hasOwnProp$2 = Object.prototype.hasOwnProperty;
|
|
250
|
+
var __propIsEnum$2 = Object.prototype.propertyIsEnumerable;
|
|
251
|
+
var __defNormalProp$2 = (obj, key, value) => key in obj ? __defProp$2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
252
|
+
var __spreadValues$2 = (a, b) => {
|
|
253
|
+
for (var prop in b || (b = {}))
|
|
254
|
+
if (__hasOwnProp$2.call(b, prop))
|
|
255
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
256
|
+
if (__getOwnPropSymbols$2)
|
|
257
|
+
for (var prop of __getOwnPropSymbols$2(b)) {
|
|
258
|
+
if (__propIsEnum$2.call(b, prop))
|
|
259
|
+
__defNormalProp$2(a, prop, b[prop]);
|
|
260
|
+
}
|
|
261
|
+
return a;
|
|
262
|
+
};
|
|
263
|
+
var __spreadProps$1 = (a, b) => __defProps$1(a, __getOwnPropDescs$1(b));
|
|
264
|
+
var __objRest = (source, exclude) => {
|
|
265
|
+
var target = {};
|
|
266
|
+
for (var prop in source)
|
|
267
|
+
if (__hasOwnProp$2.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
268
|
+
target[prop] = source[prop];
|
|
269
|
+
if (source != null && __getOwnPropSymbols$2)
|
|
270
|
+
for (var prop of __getOwnPropSymbols$2(source)) {
|
|
271
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum$2.call(source, prop))
|
|
272
|
+
target[prop] = source[prop];
|
|
273
|
+
}
|
|
274
|
+
return target;
|
|
275
|
+
};
|
|
276
|
+
const SlotContext = React__default["default"].createContext(void 0);
|
|
277
|
+
const AssetWrapper = React__default["default"].forwardRef((props, ref) => {
|
|
278
|
+
const _a = props, { children } = _a, rest = __objRest(_a, ["children"]);
|
|
279
|
+
return /* @__PURE__ */ React__default["default"].createElement("obj", {
|
|
280
|
+
ref
|
|
281
|
+
}, toJsonProperties(rest), /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
282
|
+
name: "asset"
|
|
283
|
+
}, children));
|
|
284
|
+
});
|
|
285
|
+
const GeneratedIDProperty = (props) => {
|
|
286
|
+
var _a;
|
|
287
|
+
const currentPrefixId = useGetIdPrefix();
|
|
288
|
+
return /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
289
|
+
name: "id"
|
|
290
|
+
}, (_a = props.id) != null ? _a : currentPrefixId);
|
|
291
|
+
};
|
|
292
|
+
const Asset = React__default["default"].forwardRef((props, ref) => {
|
|
293
|
+
const _a = props, { id, type, applicability, children } = _a, rest = __objRest(_a, ["id", "type", "applicability", "children"]);
|
|
294
|
+
const slotContext = React__default["default"].useContext(SlotContext);
|
|
295
|
+
const localRef = React__default["default"].useRef(null);
|
|
296
|
+
const Wrapper = (slotContext == null ? void 0 : slotContext.wrapInAsset) ? AssetWrapper : React__default["default"].Fragment;
|
|
297
|
+
return /* @__PURE__ */ React__default["default"].createElement(Wrapper, __spreadValues$2({
|
|
298
|
+
ref: (slotContext == null ? void 0 : slotContext.wrapInAsset) ? mergeRefs__default["default"]([ref, localRef]) : void 0
|
|
299
|
+
}, (slotContext == null ? void 0 : slotContext.wrapInAsset) && (slotContext == null ? void 0 : slotContext.additionalProperties) ? slotContext == null ? void 0 : slotContext.additionalProperties : {}), /* @__PURE__ */ React__default["default"].createElement(OptionalIDSuffixProvider, {
|
|
300
|
+
wrapperRef: localRef
|
|
301
|
+
}, /* @__PURE__ */ React__default["default"].createElement(SlotContext.Provider, {
|
|
302
|
+
value: void 0
|
|
303
|
+
}, /* @__PURE__ */ React__default["default"].createElement(IDProvider, {
|
|
304
|
+
id
|
|
305
|
+
}, /* @__PURE__ */ React__default["default"].createElement("obj", {
|
|
306
|
+
ref: (slotContext == null ? void 0 : slotContext.wrapInAsset) ? void 0 : mergeRefs__default["default"]([ref, localRef])
|
|
307
|
+
}, /* @__PURE__ */ React__default["default"].createElement(GeneratedIDProperty, {
|
|
308
|
+
id
|
|
309
|
+
}), /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
310
|
+
name: "type"
|
|
311
|
+
}, type), applicability !== void 0 && /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
312
|
+
name: "applicability"
|
|
313
|
+
}, /* @__PURE__ */ React__default["default"].createElement("value", {
|
|
314
|
+
value: typeof applicability === "boolean" ? applicability : applicability.toRefString()
|
|
315
|
+
})), toJsonProperties(rest), children)))));
|
|
316
|
+
});
|
|
317
|
+
Asset.defaultProps = {
|
|
318
|
+
id: void 0,
|
|
319
|
+
children: void 0
|
|
320
|
+
};
|
|
321
|
+
const Slot = (props) => {
|
|
322
|
+
var _a, _b;
|
|
323
|
+
const { TextComp, CollectionComp } = props;
|
|
324
|
+
const children = flattenChildren__default["default"](props.children);
|
|
325
|
+
const propRef = React__default["default"].useRef(null);
|
|
326
|
+
return /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
327
|
+
ref: propRef,
|
|
328
|
+
name: props.name
|
|
329
|
+
}, /* @__PURE__ */ React__default["default"].createElement(IDSuffixProvider, {
|
|
330
|
+
suffix: props.name
|
|
331
|
+
}, /* @__PURE__ */ React__default["default"].createElement(IndexSuffixStopContext.Provider, {
|
|
332
|
+
value: false
|
|
333
|
+
}, /* @__PURE__ */ React__default["default"].createElement(SlotContext.Provider, {
|
|
334
|
+
value: {
|
|
335
|
+
ref: propRef,
|
|
336
|
+
propertyName: props.name,
|
|
337
|
+
wrapInAsset: (_a = props.wrapInAsset) != null ? _a : false,
|
|
338
|
+
isArray: (_b = props.isArray) != null ? _b : false,
|
|
339
|
+
additionalProperties: props.additionalProperties,
|
|
340
|
+
TextComp,
|
|
341
|
+
CollectionComp
|
|
342
|
+
}
|
|
343
|
+
}, props.isArray && /* @__PURE__ */ React__default["default"].createElement("array", null, React__default["default"].Children.map(children, (child, index) => {
|
|
344
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, {
|
|
345
|
+
key: `${props.name}-${index}`
|
|
346
|
+
}, normalizeText({ node: child, TextComp }));
|
|
347
|
+
})), !props.isArray && normalizeToCollection({
|
|
348
|
+
node: children,
|
|
349
|
+
TextComp,
|
|
350
|
+
CollectionComp
|
|
351
|
+
})))));
|
|
352
|
+
};
|
|
353
|
+
function createSlot(options) {
|
|
354
|
+
return (props) => {
|
|
355
|
+
const _a = props, { children } = _a, other = __objRest(_a, ["children"]);
|
|
356
|
+
return /* @__PURE__ */ React__default["default"].createElement(Slot, __spreadProps$1(__spreadValues$2({}, options), {
|
|
357
|
+
additionalProperties: other
|
|
358
|
+
}), children);
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
var __defProp$1 = Object.defineProperty;
|
|
363
|
+
var __defProps = Object.defineProperties;
|
|
364
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
365
|
+
var __getOwnPropSymbols$1 = Object.getOwnPropertySymbols;
|
|
366
|
+
var __hasOwnProp$1 = Object.prototype.hasOwnProperty;
|
|
367
|
+
var __propIsEnum$1 = Object.prototype.propertyIsEnumerable;
|
|
368
|
+
var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
369
|
+
var __spreadValues$1 = (a, b) => {
|
|
370
|
+
for (var prop in b || (b = {}))
|
|
371
|
+
if (__hasOwnProp$1.call(b, prop))
|
|
372
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
373
|
+
if (__getOwnPropSymbols$1)
|
|
374
|
+
for (var prop of __getOwnPropSymbols$1(b)) {
|
|
375
|
+
if (__propIsEnum$1.call(b, prop))
|
|
376
|
+
__defNormalProp$1(a, prop, b[prop]);
|
|
377
|
+
}
|
|
378
|
+
return a;
|
|
379
|
+
};
|
|
380
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
381
|
+
const SwitchContext = React__default["default"].createContext({});
|
|
382
|
+
const Switch = (props) => {
|
|
383
|
+
const slotContext = React__default["default"].useContext(SlotContext);
|
|
384
|
+
const propertyNode = React__default["default"].useRef(null);
|
|
385
|
+
return /* @__PURE__ */ React__default["default"].createElement("obj", {
|
|
386
|
+
ref: propertyNode
|
|
387
|
+
}, /* @__PURE__ */ React__default["default"].createElement(SwitchContext.Provider, {
|
|
388
|
+
value: __spreadProps(__spreadValues$1({}, props), {
|
|
389
|
+
TextComp: slotContext == null ? void 0 : slotContext.TextComp,
|
|
390
|
+
CollectionComp: slotContext == null ? void 0 : slotContext.CollectionComp
|
|
391
|
+
})
|
|
392
|
+
}, /* @__PURE__ */ React__default["default"].createElement(OptionalIDSuffixProvider, {
|
|
393
|
+
wrapperRef: propertyNode
|
|
394
|
+
}, /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
395
|
+
name: props.isDynamic ? "dynamicSwitch" : "staticSwitch"
|
|
396
|
+
}, /* @__PURE__ */ React__default["default"].createElement(SlotContext.Provider, {
|
|
397
|
+
value: void 0
|
|
398
|
+
}, /* @__PURE__ */ React__default["default"].createElement("array", null, props.children))))), (slotContext == null ? void 0 : slotContext.additionalProperties) && toJsonProperties(slotContext.additionalProperties));
|
|
399
|
+
};
|
|
400
|
+
const findParentArray = (node) => {
|
|
401
|
+
if (node.type === "array") {
|
|
402
|
+
return node;
|
|
403
|
+
}
|
|
404
|
+
if (node.parent) {
|
|
405
|
+
return findParentArray(node.parent);
|
|
406
|
+
}
|
|
407
|
+
throw new Error("can't find parent array");
|
|
408
|
+
};
|
|
409
|
+
const findArrayIndex = (node) => {
|
|
410
|
+
const parentArray = findParentArray(node);
|
|
411
|
+
const allSearch = reactJsonReconciler.flattenNodes(parentArray.children);
|
|
412
|
+
return allSearch.indexOf(node);
|
|
413
|
+
};
|
|
414
|
+
const Case = (props) => {
|
|
415
|
+
const slotContext = React__default["default"].useContext(SlotContext);
|
|
416
|
+
const switchContext = React__default["default"].useContext(SwitchContext);
|
|
417
|
+
const [caseIndex, setCaseIndex] = React__default["default"].useState(-1);
|
|
418
|
+
const caseNode = React__default["default"].useRef(null);
|
|
419
|
+
React__default["default"].useLayoutEffect(() => {
|
|
420
|
+
if (caseNode.current) {
|
|
421
|
+
const index = findArrayIndex(caseNode.current);
|
|
422
|
+
if (index !== caseIndex) {
|
|
423
|
+
setCaseIndex(index);
|
|
424
|
+
}
|
|
425
|
+
}
|
|
426
|
+
}, [caseIndex]);
|
|
427
|
+
let expValue = true;
|
|
428
|
+
if (props.exp !== void 0) {
|
|
429
|
+
expValue = isTemplateStringInstance(props.exp) ? props.exp.toValue() : props.exp;
|
|
430
|
+
}
|
|
431
|
+
return /* @__PURE__ */ React__default["default"].createElement("obj", {
|
|
432
|
+
ref: caseNode
|
|
433
|
+
}, /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
434
|
+
name: "case"
|
|
435
|
+
}, /* @__PURE__ */ React__default["default"].createElement("value", {
|
|
436
|
+
value: expValue
|
|
437
|
+
})), /* @__PURE__ */ React__default["default"].createElement(IDSuffixProvider, {
|
|
438
|
+
suffix: `${switchContext.isDynamic ? "dynamicSwitch" : "staticSwitch"}-${caseIndex}`
|
|
439
|
+
}, /* @__PURE__ */ React__default["default"].createElement(SlotContext.Provider, {
|
|
440
|
+
value: slotContext ? __spreadProps(__spreadValues$1({}, slotContext), { wrapInAsset: false }) : void 0
|
|
441
|
+
}, /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
442
|
+
name: "asset"
|
|
443
|
+
}, normalizeToCollection({
|
|
444
|
+
node: props.children,
|
|
445
|
+
TextComp: switchContext == null ? void 0 : switchContext.TextComp,
|
|
446
|
+
CollectionComp: switchContext == null ? void 0 : switchContext.CollectionComp
|
|
447
|
+
})))));
|
|
448
|
+
};
|
|
449
|
+
Switch.Case = Case;
|
|
450
|
+
|
|
451
|
+
const TemplateContext = React__default["default"].createContext({
|
|
452
|
+
depth: 0
|
|
453
|
+
});
|
|
454
|
+
function addTemplateToObject(obj, templateObj, templateParentNodeType) {
|
|
455
|
+
var _a;
|
|
456
|
+
let templateProp = obj.properties.find((p) => {
|
|
457
|
+
var _a2;
|
|
458
|
+
return p.keyNode.value === "template" && ((_a2 = p.valueNode) == null ? void 0 : _a2.type) === "array";
|
|
459
|
+
});
|
|
460
|
+
if (!templateProp) {
|
|
461
|
+
templateProp = new reactJsonReconciler.PropertyNode(new reactJsonReconciler.ValueNode("template"), new reactJsonReconciler.ArrayNode());
|
|
462
|
+
templateProp.parent = obj;
|
|
463
|
+
obj.properties.push(templateProp);
|
|
464
|
+
}
|
|
465
|
+
const templateItems = templateProp.valueNode;
|
|
466
|
+
templateItems.items.push(templateObj);
|
|
467
|
+
templateObj.parent = templateItems;
|
|
468
|
+
const templateParentProp = obj.properties.find((p) => {
|
|
469
|
+
var _a2;
|
|
470
|
+
return p.keyNode.value === templateParentNodeType && ((_a2 = p.valueNode) == null ? void 0 : _a2.type) === "array";
|
|
471
|
+
});
|
|
472
|
+
if (templateParentProp) {
|
|
473
|
+
const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);
|
|
474
|
+
const templateParentValueNode = (_a = obj.properties[indexOfTemplateParent]) == null ? void 0 : _a.valueNode;
|
|
475
|
+
if (templateParentValueNode) {
|
|
476
|
+
const templateParentArray = reactJsonReconciler.toJSON(templateParentValueNode);
|
|
477
|
+
if (Array.isArray(templateParentArray) && templateParentArray.length === 0) {
|
|
478
|
+
obj.properties.splice(indexOfTemplateParent, 1);
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
return () => {
|
|
483
|
+
templateItems.items = templateItems.items.filter((t) => t !== templateObj);
|
|
484
|
+
if (templateItems.children.length === 0 && templateProp) {
|
|
485
|
+
obj.properties.splice(obj.properties.indexOf(templateProp, 1));
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
}
|
|
489
|
+
const TemplateProvider = (props) => {
|
|
490
|
+
const baseContext = React__default["default"].useContext(TemplateContext);
|
|
491
|
+
return /* @__PURE__ */ React__default["default"].createElement(TemplateContext.Provider, {
|
|
492
|
+
value: { depth: baseContext.depth + 1 }
|
|
493
|
+
}, props.children);
|
|
494
|
+
};
|
|
495
|
+
const getParentObject = (node) => {
|
|
496
|
+
if (node.type === "object") {
|
|
497
|
+
return node;
|
|
498
|
+
}
|
|
499
|
+
if (node.parent) {
|
|
500
|
+
return getParentObject(node.parent);
|
|
501
|
+
}
|
|
502
|
+
};
|
|
503
|
+
const getParentProperty = (node) => {
|
|
504
|
+
if (node.type === "property") {
|
|
505
|
+
return node;
|
|
506
|
+
}
|
|
507
|
+
if (node.parent) {
|
|
508
|
+
return getParentProperty(node.parent);
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
const Template = (props) => {
|
|
512
|
+
const baseContext = React__default["default"].useContext(TemplateContext);
|
|
513
|
+
const [outputProp, setOutputProp] = React__default["default"].useState(props.output);
|
|
514
|
+
const proxyRef = React__default["default"].useRef(null);
|
|
515
|
+
const valueRef = React__default["default"].useRef(null);
|
|
516
|
+
const outputElement = React__default["default"].useMemo(() => new reactJsonReconciler.ProxyNode(), []);
|
|
517
|
+
React__default["default"].useLayoutEffect(() => {
|
|
518
|
+
const propNode = proxyRef.current && getParentProperty(proxyRef.current);
|
|
519
|
+
if (outputProp === void 0 && propNode) {
|
|
520
|
+
setOutputProp(propNode.keyNode.value);
|
|
521
|
+
}
|
|
522
|
+
}, [proxyRef, outputProp]);
|
|
523
|
+
React__default["default"].useEffect(() => {
|
|
524
|
+
const templateObj = outputElement.items[0];
|
|
525
|
+
if (proxyRef.current) {
|
|
526
|
+
const parentObject = getParentObject(proxyRef.current);
|
|
527
|
+
if (!parentObject) {
|
|
528
|
+
throw new Error("Unable to find parent to add template to");
|
|
529
|
+
}
|
|
530
|
+
if (!outputProp) {
|
|
531
|
+
return;
|
|
532
|
+
}
|
|
533
|
+
return addTemplateToObject(parentObject, templateObj, outputProp);
|
|
534
|
+
}
|
|
535
|
+
}, [proxyRef, outputProp, outputElement.items]);
|
|
536
|
+
return /* @__PURE__ */ React__default["default"].createElement("proxy", {
|
|
537
|
+
ref: proxyRef
|
|
538
|
+
}, reactJsonReconciler.createPortal(/* @__PURE__ */ React__default["default"].createElement(OptionalIDSuffixProvider, {
|
|
539
|
+
wrapperRef: valueRef,
|
|
540
|
+
templateIndex: `_index${baseContext.depth === 0 ? "" : baseContext.depth}_`
|
|
541
|
+
}, /* @__PURE__ */ React__default["default"].createElement(TemplateProvider, null, /* @__PURE__ */ React__default["default"].createElement("object", null, /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
542
|
+
name: "data"
|
|
543
|
+
}, props.data.toValue()), /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
544
|
+
name: "output"
|
|
545
|
+
}, outputProp), /* @__PURE__ */ React__default["default"].createElement("property", {
|
|
546
|
+
name: "value"
|
|
547
|
+
}, props.children)))), outputElement), /* @__PURE__ */ React__default["default"].createElement("value", {
|
|
548
|
+
ref: valueRef,
|
|
549
|
+
value: void 0
|
|
550
|
+
}));
|
|
551
|
+
};
|
|
552
|
+
|
|
553
|
+
const bindingSymbol = Symbol("binding");
|
|
554
|
+
const SchemaTypeName = Symbol("Schema Rename");
|
|
555
|
+
const isTypeDef = (property) => {
|
|
556
|
+
return property.type !== void 0;
|
|
557
|
+
};
|
|
558
|
+
class SchemaGenerator {
|
|
559
|
+
constructor() {
|
|
560
|
+
this.hooks = {
|
|
561
|
+
createSchemaNode: new tapableTs.SyncWaterfallHook()
|
|
562
|
+
};
|
|
563
|
+
this.toSchema = (schema) => {
|
|
564
|
+
const newSchema = {
|
|
565
|
+
ROOT: {}
|
|
566
|
+
};
|
|
567
|
+
this.children = [];
|
|
568
|
+
this.generatedDataTypeNames.clear();
|
|
569
|
+
Object.keys(schema).forEach((property) => {
|
|
570
|
+
const subType = schema[property];
|
|
571
|
+
newSchema.ROOT[property] = this.hooks.createSchemaNode.call(this.processChildren(property, subType), subType);
|
|
572
|
+
});
|
|
573
|
+
while (this.children.length > 0) {
|
|
574
|
+
const c = this.children.pop();
|
|
575
|
+
if (c === void 0) {
|
|
576
|
+
break;
|
|
577
|
+
}
|
|
578
|
+
const { name, child } = c;
|
|
579
|
+
const typeDef = {};
|
|
580
|
+
Object.keys(child).forEach((property) => {
|
|
581
|
+
const subType = child[property];
|
|
582
|
+
typeDef[property] = this.hooks.createSchemaNode.call(this.processChildren(property, subType), subType);
|
|
583
|
+
});
|
|
584
|
+
newSchema[name] = typeDef;
|
|
585
|
+
}
|
|
586
|
+
return newSchema;
|
|
587
|
+
};
|
|
588
|
+
this.makePlaceholderType = (typeName) => {
|
|
589
|
+
return {
|
|
590
|
+
type: `${typeName}Type`
|
|
591
|
+
};
|
|
592
|
+
};
|
|
593
|
+
this.children = [];
|
|
594
|
+
this.generatedDataTypeNames = new Map();
|
|
595
|
+
}
|
|
596
|
+
processChildren(property, subType) {
|
|
597
|
+
var _a, _b;
|
|
598
|
+
if (isTypeDef(subType)) {
|
|
599
|
+
return subType;
|
|
600
|
+
}
|
|
601
|
+
let intermediateType;
|
|
602
|
+
if (Array.isArray(subType)) {
|
|
603
|
+
if (subType.length > 1) {
|
|
604
|
+
signale__default["default"].warn(`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`);
|
|
605
|
+
}
|
|
606
|
+
const subTypeName = (_a = subType[0][SchemaTypeName]) != null ? _a : property;
|
|
607
|
+
intermediateType = this.makePlaceholderArrayType(subTypeName);
|
|
608
|
+
this.children.push({ name: intermediateType.type, child: subType[0] });
|
|
609
|
+
} else {
|
|
610
|
+
const subTypeName = (_b = subType[SchemaTypeName]) != null ? _b : property;
|
|
611
|
+
intermediateType = this.makePlaceholderType(subTypeName);
|
|
612
|
+
this.children.push({ name: intermediateType.type, child: subType });
|
|
613
|
+
}
|
|
614
|
+
if (this.generatedDataTypeNames.has(intermediateType.type)) {
|
|
615
|
+
if (!dequal.dequal(subType, this.generatedDataTypeNames.get(intermediateType.type))) {
|
|
616
|
+
throw new Error(`Error: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes`);
|
|
617
|
+
}
|
|
618
|
+
this.children.pop();
|
|
619
|
+
}
|
|
620
|
+
this.generatedDataTypeNames.set(intermediateType.type, subType);
|
|
621
|
+
return intermediateType;
|
|
622
|
+
}
|
|
623
|
+
makePlaceholderArrayType(typeName) {
|
|
624
|
+
return {
|
|
625
|
+
type: `${typeName}Type`,
|
|
626
|
+
isArray: true
|
|
627
|
+
};
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
function makeBindingsForObject(obj, arrayAccessorKeys = ["_index_"]) {
|
|
631
|
+
const accessor = (paths) => {
|
|
632
|
+
const bindingMap = new WeakMap();
|
|
633
|
+
return {
|
|
634
|
+
ownKeys(target) {
|
|
635
|
+
return Reflect.ownKeys(target);
|
|
636
|
+
},
|
|
637
|
+
get(target, key) {
|
|
638
|
+
const bindingKeys = Object.keys(target);
|
|
639
|
+
if (!bindingMap.has(target)) {
|
|
640
|
+
bindingMap.set(target, binding`${paths.join(".")}`);
|
|
641
|
+
}
|
|
642
|
+
if (key === bindingSymbol) {
|
|
643
|
+
return paths;
|
|
644
|
+
}
|
|
645
|
+
if (Array.isArray(target) && (arrayAccessorKeys.includes(key) || typeof key === "number")) {
|
|
646
|
+
return new Proxy(target[0], accessor(paths.concat([key])));
|
|
647
|
+
}
|
|
648
|
+
if (bindingKeys.includes(key) && typeof target[key] === "object") {
|
|
649
|
+
return new Proxy(target[key], accessor(paths.concat([key])));
|
|
650
|
+
}
|
|
651
|
+
const createdInstance = bindingMap.get(target);
|
|
652
|
+
return createdInstance == null ? void 0 : createdInstance[key];
|
|
653
|
+
}
|
|
654
|
+
};
|
|
655
|
+
};
|
|
656
|
+
return new Proxy(obj, accessor([]));
|
|
657
|
+
}
|
|
658
|
+
const getBindingFromObject = (obj) => {
|
|
659
|
+
const baseBindings = obj[bindingSymbol];
|
|
660
|
+
if (!Array.isArray(baseBindings) || baseBindings.length === 0) {
|
|
661
|
+
throw new Error(`Unable to get binding for ${obj}`);
|
|
662
|
+
}
|
|
663
|
+
return binding`${baseBindings.join(".")}`;
|
|
664
|
+
};
|
|
665
|
+
const getBindingStringFromObject = (obj) => {
|
|
666
|
+
return getBindingFromObject(obj).toString();
|
|
667
|
+
};
|
|
668
|
+
const getRefStringFromObject = (obj) => {
|
|
669
|
+
return getBindingFromObject(obj).toRefString();
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
var __defProp = Object.defineProperty;
|
|
673
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
674
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
675
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
676
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
677
|
+
var __spreadValues = (a, b) => {
|
|
678
|
+
for (var prop in b || (b = {}))
|
|
679
|
+
if (__hasOwnProp.call(b, prop))
|
|
680
|
+
__defNormalProp(a, prop, b[prop]);
|
|
681
|
+
if (__getOwnPropSymbols)
|
|
682
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
683
|
+
if (__propIsEnum.call(b, prop))
|
|
684
|
+
__defNormalProp(a, prop, b[prop]);
|
|
685
|
+
}
|
|
686
|
+
return a;
|
|
687
|
+
};
|
|
688
|
+
var __async = (__this, __arguments, generator) => {
|
|
689
|
+
return new Promise((resolve, reject) => {
|
|
690
|
+
var fulfilled = (value) => {
|
|
691
|
+
try {
|
|
692
|
+
step(generator.next(value));
|
|
693
|
+
} catch (e) {
|
|
694
|
+
reject(e);
|
|
695
|
+
}
|
|
696
|
+
};
|
|
697
|
+
var rejected = (value) => {
|
|
698
|
+
try {
|
|
699
|
+
step(generator.throw(value));
|
|
700
|
+
} catch (e) {
|
|
701
|
+
reject(e);
|
|
702
|
+
}
|
|
703
|
+
};
|
|
704
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
705
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
706
|
+
});
|
|
707
|
+
};
|
|
708
|
+
const parseNavigationExpressions = (nav) => {
|
|
709
|
+
function replaceExpWithStr(obj) {
|
|
710
|
+
function convExp(value) {
|
|
711
|
+
return value && typeof value === "object" && value.__type === "expression" ? value.toValue() : replaceExpWithStr(value);
|
|
712
|
+
}
|
|
713
|
+
if (Array.isArray(obj)) {
|
|
714
|
+
return obj.map(convExp);
|
|
715
|
+
}
|
|
716
|
+
if (typeof obj === "object") {
|
|
717
|
+
return Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, convExp(value)]));
|
|
718
|
+
}
|
|
719
|
+
return obj;
|
|
720
|
+
}
|
|
721
|
+
return replaceExpWithStr(nav);
|
|
722
|
+
};
|
|
723
|
+
const mergeSourceMaps = (sourceMaps, generated) => {
|
|
724
|
+
const generator = new sourceMapJs.SourceMapGenerator();
|
|
725
|
+
sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {
|
|
726
|
+
const generatedLineOffset = generated.split("\n").findIndex((line) => line.includes(offsetIndexSearch));
|
|
727
|
+
const sourceLineOffset = source.split("\n").findIndex((line) => line.includes(offsetIndexSearch));
|
|
728
|
+
const lineOffset = generatedLineOffset - sourceLineOffset;
|
|
729
|
+
const generatedLine = generated.split("\n")[generatedLineOffset];
|
|
730
|
+
const sourceLine = source.split("\n")[sourceLineOffset];
|
|
731
|
+
const generatedColumn = generatedLine.indexOf(offsetIndexSearch);
|
|
732
|
+
const sourceColumn = sourceLine.indexOf(offsetIndexSearch);
|
|
733
|
+
const columnOffset = generatedColumn - sourceColumn;
|
|
734
|
+
const consumer = new sourceMapJs.SourceMapConsumer(JSON.parse(sourceMap));
|
|
735
|
+
consumer.eachMapping((mapping) => {
|
|
736
|
+
generator.addMapping({
|
|
737
|
+
generated: {
|
|
738
|
+
line: mapping.generatedLine + lineOffset,
|
|
739
|
+
column: mapping.generatedColumn + columnOffset
|
|
740
|
+
},
|
|
741
|
+
original: {
|
|
742
|
+
line: mapping.originalLine,
|
|
743
|
+
column: mapping.originalColumn
|
|
744
|
+
},
|
|
745
|
+
source: mapping.source
|
|
746
|
+
});
|
|
747
|
+
});
|
|
748
|
+
});
|
|
749
|
+
return generator.toString();
|
|
750
|
+
};
|
|
751
|
+
class DSLCompiler {
|
|
752
|
+
constructor() {
|
|
753
|
+
this.hooks = {
|
|
754
|
+
schemaGenerator: new tapableTs.SyncHook()
|
|
755
|
+
};
|
|
756
|
+
}
|
|
757
|
+
serialize(value) {
|
|
758
|
+
return __async(this, null, function* () {
|
|
759
|
+
var _a, _b;
|
|
760
|
+
if (typeof value !== "object" || value === null) {
|
|
761
|
+
throw new Error("Unable to serialize non-object");
|
|
762
|
+
}
|
|
763
|
+
if (React__default["default"].isValidElement(value)) {
|
|
764
|
+
const { jsonValue, sourceMap } = yield reactJsonReconciler.render(value, {
|
|
765
|
+
collectSourceMap: true
|
|
766
|
+
});
|
|
767
|
+
return {
|
|
768
|
+
value: jsonValue,
|
|
769
|
+
sourceMap,
|
|
770
|
+
contentType: "view"
|
|
771
|
+
};
|
|
772
|
+
}
|
|
773
|
+
if ("navigation" in value) {
|
|
774
|
+
const allSourceMaps = [];
|
|
775
|
+
const copiedValue = __spreadValues({}, value);
|
|
776
|
+
copiedValue.views = yield Promise.all((_b = (_a = copiedValue == null ? void 0 : copiedValue.views) == null ? void 0 : _a.map((node) => __async(this, null, function* () {
|
|
777
|
+
const { jsonValue, sourceMap, stringValue } = yield reactJsonReconciler.render(node, {
|
|
778
|
+
collectSourceMap: true
|
|
779
|
+
});
|
|
780
|
+
if (sourceMap) {
|
|
781
|
+
const searchIdLine = stringValue.split("\n").find((line) => line.includes(`"id": "${jsonValue.id}"`));
|
|
782
|
+
if (searchIdLine) {
|
|
783
|
+
allSourceMaps.push({
|
|
784
|
+
sourceMap,
|
|
785
|
+
offsetIndexSearch: searchIdLine,
|
|
786
|
+
source: stringValue
|
|
787
|
+
});
|
|
788
|
+
}
|
|
789
|
+
}
|
|
790
|
+
return jsonValue;
|
|
791
|
+
}))) != null ? _b : []);
|
|
792
|
+
if ("navigation" in value) {
|
|
793
|
+
Object.entries(value.navigation).forEach(([navKey, node]) => {
|
|
794
|
+
if (typeof node === "object") {
|
|
795
|
+
Object.entries(node).forEach(([nodeKey, flowNode]) => {
|
|
796
|
+
var _a2, _b2, _c, _d;
|
|
797
|
+
if (flowNode && typeof flowNode === "object" && "state_type" in flowNode && flowNode.state_type === "VIEW" && React__default["default"].isValidElement(flowNode.ref)) {
|
|
798
|
+
const actualViewIndex = (_b2 = (_a2 = value.views) == null ? void 0 : _a2.indexOf) == null ? void 0 : _b2.call(_a2, flowNode.ref);
|
|
799
|
+
if (actualViewIndex !== void 0 && actualViewIndex > -1) {
|
|
800
|
+
const actualId = (_d = (_c = copiedValue.views) == null ? void 0 : _c[actualViewIndex]) == null ? void 0 : _d.id;
|
|
801
|
+
copiedValue.navigation[navKey][nodeKey].ref = actualId;
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
});
|
|
805
|
+
}
|
|
806
|
+
});
|
|
807
|
+
copiedValue.navigation = parseNavigationExpressions(copiedValue.navigation);
|
|
808
|
+
}
|
|
809
|
+
if (value) {
|
|
810
|
+
return {
|
|
811
|
+
value: copiedValue,
|
|
812
|
+
contentType: "flow",
|
|
813
|
+
sourceMap: mergeSourceMaps(allSourceMaps, JSON.stringify(copiedValue, null, 2))
|
|
814
|
+
};
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
const schemaGenerator = new SchemaGenerator();
|
|
818
|
+
this.hooks.schemaGenerator.call(schemaGenerator);
|
|
819
|
+
return {
|
|
820
|
+
value: schemaGenerator.toSchema(value),
|
|
821
|
+
contentType: "schema"
|
|
822
|
+
};
|
|
823
|
+
});
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
exports.Asset = Asset;
|
|
828
|
+
exports.AssetWrapper = AssetWrapper;
|
|
829
|
+
exports.DSLCompiler = DSLCompiler;
|
|
830
|
+
exports.GeneratedIDProperty = GeneratedIDProperty;
|
|
831
|
+
exports.IDProvider = IDProvider;
|
|
832
|
+
exports.IDSuffixIndexProvider = IDSuffixIndexProvider;
|
|
833
|
+
exports.IDSuffixProvider = IDSuffixProvider;
|
|
834
|
+
exports.IndexSuffixStopContext = IndexSuffixStopContext;
|
|
835
|
+
exports.OptionalIDSuffixProvider = OptionalIDSuffixProvider;
|
|
836
|
+
exports.SchemaGenerator = SchemaGenerator;
|
|
837
|
+
exports.SchemaTypeName = SchemaTypeName;
|
|
838
|
+
exports.Slot = Slot;
|
|
839
|
+
exports.SlotContext = SlotContext;
|
|
840
|
+
exports.Switch = Switch;
|
|
841
|
+
exports.Template = Template;
|
|
842
|
+
exports.TemplateContext = TemplateContext;
|
|
843
|
+
exports.TemplateStringComponent = TemplateStringComponent;
|
|
844
|
+
exports.binding = binding;
|
|
845
|
+
exports.createSlot = createSlot;
|
|
846
|
+
exports.expression = expression;
|
|
847
|
+
exports.getBindingFromObject = getBindingFromObject;
|
|
848
|
+
exports.getBindingStringFromObject = getBindingStringFromObject;
|
|
849
|
+
exports.getRefStringFromObject = getRefStringFromObject;
|
|
850
|
+
exports.isTemplateStringInstance = isTemplateStringInstance;
|
|
851
|
+
exports.makeBindingsForObject = makeBindingsForObject;
|
|
852
|
+
exports.normalizeText = normalizeText;
|
|
853
|
+
exports.normalizeToCollection = normalizeToCollection;
|
|
854
|
+
exports.toArray = toArray;
|
|
855
|
+
exports.toJsonElement = toJsonElement;
|
|
856
|
+
exports.toJsonProperties = toJsonProperties;
|
|
857
|
+
exports.useGetIdPrefix = useGetIdPrefix;
|
|
858
|
+
exports.useIndexInSlot = useIndexInSlot;
|
|
859
|
+
Object.keys(reactJsonReconciler).forEach(function (k) {
|
|
860
|
+
if (k !== 'default' && !exports.hasOwnProperty(k)) Object.defineProperty(exports, k, {
|
|
861
|
+
enumerable: true,
|
|
862
|
+
get: function () { return reactJsonReconciler[k]; }
|
|
863
|
+
});
|
|
864
|
+
});
|
|
865
|
+
//# sourceMappingURL=index.cjs.js.map
|