@player-tools/dsl 0.4.2-next.1 → 0.5.0-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/dist/cjs/index.cjs +973 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +910 -0
- package/dist/index.mjs +910 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +26 -31
- package/src/__tests__/asset-api.test.tsx +354 -0
- package/src/__tests__/edge-cases.test.tsx +81 -0
- package/src/__tests__/helpers/asset-library.tsx +371 -0
- package/src/__tests__/helpers/mock-data-refs.ts +21 -0
- package/src/__tests__/json.test.ts +12 -0
- package/src/__tests__/jsx.test.tsx +138 -0
- package/src/__tests__/schema.test.tsx +378 -0
- package/src/__tests__/switch.test.tsx +251 -0
- package/src/__tests__/template.test.tsx +294 -0
- package/src/__tests__/view-api.test.tsx +46 -0
- package/src/auto-id.tsx +10 -10
- package/src/compiler/__tests__/compiler.test.tsx +264 -0
- package/src/compiler/__tests__/schema.test.ts +127 -0
- package/src/compiler/compiler.ts +51 -47
- package/src/compiler/index.ts +3 -3
- package/src/compiler/schema.ts +29 -25
- package/src/compiler/types.ts +15 -12
- package/src/compiler/utils.ts +7 -7
- package/src/components.tsx +17 -12
- package/src/index.ts +11 -11
- package/src/string-templates/__tests__/binding.test.ts +87 -0
- package/src/string-templates/__tests__/edge-cases.test.ts +6 -0
- package/src/string-templates/__tests__/expression.test.ts +9 -0
- package/src/string-templates/__tests__/react.test.tsx +75 -0
- package/src/string-templates/index.ts +40 -22
- package/src/switch.tsx +12 -12
- package/src/template.tsx +38 -34
- package/src/types.ts +5 -5
- package/src/utils.tsx +10 -10
- package/types/auto-id.d.ts +33 -0
- package/types/compiler/compiler.d.ts +27 -0
- package/types/compiler/index.d.ts +4 -0
- package/types/compiler/schema.d.ts +61 -0
- package/types/compiler/types.d.ts +55 -0
- package/types/compiler/utils.d.ts +4 -0
- package/types/components.d.ts +90 -0
- package/types/index.d.ts +12 -0
- package/types/string-templates/index.d.ts +50 -0
- package/types/switch.d.ts +19 -0
- package/types/template.d.ts +20 -0
- package/types/types.d.ts +42 -0
- package/types/utils.d.ts +33 -0
- package/README.md +0 -9
- package/dist/index.cjs.js +0 -971
- package/dist/index.d.ts +0 -403
- package/dist/index.esm.js +0 -922
|
@@ -0,0 +1,973 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
21
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
+
mod
|
|
28
|
+
));
|
|
29
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
+
|
|
31
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/index.ts
|
|
32
|
+
var src_exports = {};
|
|
33
|
+
__export(src_exports, {
|
|
34
|
+
Asset: () => Asset,
|
|
35
|
+
AssetWrapper: () => AssetWrapper,
|
|
36
|
+
DSLCompiler: () => DSLCompiler,
|
|
37
|
+
GeneratedIDProperty: () => GeneratedIDProperty,
|
|
38
|
+
IDProvider: () => IDProvider,
|
|
39
|
+
IDSuffixIndexProvider: () => IDSuffixIndexProvider,
|
|
40
|
+
IDSuffixProvider: () => IDSuffixProvider,
|
|
41
|
+
IndexSuffixStopContext: () => IndexSuffixStopContext,
|
|
42
|
+
OptionalIDSuffixProvider: () => OptionalIDSuffixProvider,
|
|
43
|
+
SchemaGenerator: () => SchemaGenerator,
|
|
44
|
+
SchemaTypeName: () => SchemaTypeName,
|
|
45
|
+
Slot: () => Slot,
|
|
46
|
+
SlotContext: () => SlotContext,
|
|
47
|
+
Switch: () => Switch,
|
|
48
|
+
Template: () => Template,
|
|
49
|
+
TemplateContext: () => TemplateContext,
|
|
50
|
+
TemplateStringComponent: () => TemplateStringComponent,
|
|
51
|
+
View: () => View,
|
|
52
|
+
binding: () => binding,
|
|
53
|
+
createSlot: () => createSlot,
|
|
54
|
+
expression: () => expression,
|
|
55
|
+
fingerprintContent: () => fingerprintContent,
|
|
56
|
+
flattenChildren: () => flattenChildren,
|
|
57
|
+
getBindingFromObject: () => getBindingFromObject,
|
|
58
|
+
getBindingStringFromObject: () => getBindingStringFromObject,
|
|
59
|
+
getRefStringFromObject: () => getRefStringFromObject,
|
|
60
|
+
isDefaultCompilerContentType: () => isDefaultCompilerContentType,
|
|
61
|
+
isTemplateStringInstance: () => isTemplateStringInstance,
|
|
62
|
+
makeBindingsForObject: () => makeBindingsForObject,
|
|
63
|
+
normalizeText: () => normalizeText,
|
|
64
|
+
normalizeToCollection: () => normalizeToCollection,
|
|
65
|
+
toArray: () => toArray,
|
|
66
|
+
toJsonElement: () => toJsonElement,
|
|
67
|
+
toJsonProperties: () => toJsonProperties,
|
|
68
|
+
useGetIdPrefix: () => useGetIdPrefix,
|
|
69
|
+
useIndexInSlot: () => useIndexInSlot
|
|
70
|
+
});
|
|
71
|
+
module.exports = __toCommonJS(src_exports);
|
|
72
|
+
|
|
73
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx
|
|
74
|
+
var import_react2 = __toESM(require("react"));
|
|
75
|
+
var import_react_merge_refs = __toESM(require("react-merge-refs"));
|
|
76
|
+
|
|
77
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/auto-id.tsx
|
|
78
|
+
var import_react = __toESM(require("react"));
|
|
79
|
+
var import_react_json_reconciler = require("react-json-reconciler");
|
|
80
|
+
var IDSuffixContext = import_react.default.createContext("root");
|
|
81
|
+
var IndexSuffixStopContext = import_react.default.createContext(false);
|
|
82
|
+
var useGetIdPrefix = () => {
|
|
83
|
+
return import_react.default.useContext(IDSuffixContext);
|
|
84
|
+
};
|
|
85
|
+
var IDSuffixProvider = (props) => {
|
|
86
|
+
const currentPrefix = useGetIdPrefix();
|
|
87
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
88
|
+
IDSuffixContext.Provider,
|
|
89
|
+
{
|
|
90
|
+
value: [
|
|
91
|
+
currentPrefix === "root" ? void 0 : currentPrefix,
|
|
92
|
+
props.suffix
|
|
93
|
+
].filter(Boolean).join("-")
|
|
94
|
+
},
|
|
95
|
+
props.children
|
|
96
|
+
);
|
|
97
|
+
};
|
|
98
|
+
var IDProvider = (props) => {
|
|
99
|
+
if (props.id) {
|
|
100
|
+
return /* @__PURE__ */ import_react.default.createElement(IDSuffixContext.Provider, { value: props.id }, props.children);
|
|
101
|
+
}
|
|
102
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children);
|
|
103
|
+
};
|
|
104
|
+
var useIndexInSlot = (ref) => {
|
|
105
|
+
const [index, setIndex] = import_react.default.useState(-1);
|
|
106
|
+
const slotContext = import_react.default.useContext(SlotContext);
|
|
107
|
+
import_react.default.useEffect(() => {
|
|
108
|
+
if (!slotContext?.isArray) {
|
|
109
|
+
throw new Error("Cannot get index in non-array slot");
|
|
110
|
+
}
|
|
111
|
+
if (ref.current && slotContext?.ref.current?.valueNode?.type === "array") {
|
|
112
|
+
const allChildren = (0, import_react_json_reconciler.flattenNodes)(
|
|
113
|
+
slotContext.ref.current.valueNode.children
|
|
114
|
+
);
|
|
115
|
+
const foundIndex = allChildren.indexOf(ref.current);
|
|
116
|
+
if (foundIndex !== index) {
|
|
117
|
+
setIndex(foundIndex);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}, [index, ref, slotContext?.isArray, slotContext?.ref]);
|
|
121
|
+
return index;
|
|
122
|
+
};
|
|
123
|
+
var IDSuffixIndexProvider = (props) => {
|
|
124
|
+
const slotIndex = useIndexInSlot(props.wrapperRef);
|
|
125
|
+
const stopIndex = import_react.default.useContext(IndexSuffixStopContext);
|
|
126
|
+
if (stopIndex) {
|
|
127
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children);
|
|
128
|
+
}
|
|
129
|
+
return /* @__PURE__ */ import_react.default.createElement(IDSuffixProvider, { suffix: props.templateIndex ?? String(slotIndex) }, /* @__PURE__ */ import_react.default.createElement(IndexSuffixStopContext.Provider, { value: true }, props.children));
|
|
130
|
+
};
|
|
131
|
+
var OptionalIDSuffixProvider = (props) => {
|
|
132
|
+
const slotContext = import_react.default.useContext(SlotContext);
|
|
133
|
+
if (slotContext?.isArray) {
|
|
134
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
135
|
+
IDSuffixIndexProvider,
|
|
136
|
+
{
|
|
137
|
+
wrapperRef: props.wrapperRef,
|
|
138
|
+
templateIndex: props.templateIndex
|
|
139
|
+
},
|
|
140
|
+
props.children
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, props.children);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/utils.tsx
|
|
147
|
+
var React3 = __toESM(require("react"));
|
|
148
|
+
|
|
149
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts
|
|
150
|
+
var React2 = __toESM(require("react"));
|
|
151
|
+
var import_player = require("@player-ui/player");
|
|
152
|
+
var OpaqueIdentifier = Symbol("TemplateStringType");
|
|
153
|
+
var TemplateStringComponent = (props) => {
|
|
154
|
+
return React2.createElement(
|
|
155
|
+
"value",
|
|
156
|
+
{
|
|
157
|
+
value: props.value
|
|
158
|
+
},
|
|
159
|
+
null
|
|
160
|
+
);
|
|
161
|
+
};
|
|
162
|
+
var createTemplateInstance = (options) => {
|
|
163
|
+
const value = options.strings.reduce((sum, next, i) => {
|
|
164
|
+
const element2 = options.other[i];
|
|
165
|
+
if (typeof element2 === "string") {
|
|
166
|
+
return sum + next + element2;
|
|
167
|
+
}
|
|
168
|
+
return sum + next + (element2?.toRefString(options) ?? "");
|
|
169
|
+
}, "");
|
|
170
|
+
if (options.nestedContext === "expression") {
|
|
171
|
+
const parsedExpression = (0, import_player.parseExpression)(value, { strict: false });
|
|
172
|
+
if (parsedExpression.error) {
|
|
173
|
+
throw parsedExpression.error;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
const toString = () => {
|
|
177
|
+
return options.toRefString({}, value);
|
|
178
|
+
};
|
|
179
|
+
const toValue = () => {
|
|
180
|
+
return value;
|
|
181
|
+
};
|
|
182
|
+
const element = React2.createElement(
|
|
183
|
+
TemplateStringComponent,
|
|
184
|
+
{
|
|
185
|
+
value: toString()
|
|
186
|
+
},
|
|
187
|
+
null
|
|
188
|
+
);
|
|
189
|
+
return {
|
|
190
|
+
...element,
|
|
191
|
+
[OpaqueIdentifier]: true,
|
|
192
|
+
toString,
|
|
193
|
+
toValue,
|
|
194
|
+
toRefString: (refStringOptions) => {
|
|
195
|
+
return options.toRefString(refStringOptions, value);
|
|
196
|
+
}
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
var addBindingIndexes = (binding2) => {
|
|
200
|
+
let currentIndex = 0;
|
|
201
|
+
return binding2.replace(/_index_/g, () => {
|
|
202
|
+
const result = `_index${currentIndex > 0 ? currentIndex : ""}_`;
|
|
203
|
+
currentIndex += 1;
|
|
204
|
+
return result;
|
|
205
|
+
});
|
|
206
|
+
};
|
|
207
|
+
var createBindingTemplateInstance = (options) => {
|
|
208
|
+
const templateInstance = createTemplateInstance({
|
|
209
|
+
...options,
|
|
210
|
+
strings: options.strings.map(
|
|
211
|
+
(element) => addBindingIndexes(element)
|
|
212
|
+
),
|
|
213
|
+
other: options.other.map(
|
|
214
|
+
(element) => typeof element === "string" ? addBindingIndexes(element) : element
|
|
215
|
+
),
|
|
216
|
+
toRefString: (context, value) => {
|
|
217
|
+
return `{{${value}}}`;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
220
|
+
templateInstance.__type = "binding";
|
|
221
|
+
return templateInstance;
|
|
222
|
+
};
|
|
223
|
+
var createExpressionTemplateInstance = (options) => {
|
|
224
|
+
const templateInstance = createTemplateInstance({
|
|
225
|
+
...options,
|
|
226
|
+
toRefString: (contextOptions, value) => {
|
|
227
|
+
if (contextOptions?.nestedContext === "expression") {
|
|
228
|
+
return value;
|
|
229
|
+
}
|
|
230
|
+
const inBinding = contextOptions?.nestedContext === "binding";
|
|
231
|
+
return `${inBinding ? "`" : "@["}${value}${inBinding ? "`" : "]@"}`;
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
templateInstance.__type = "expression";
|
|
235
|
+
return templateInstance;
|
|
236
|
+
};
|
|
237
|
+
var binding = (strings, ...nested) => {
|
|
238
|
+
return createBindingTemplateInstance({
|
|
239
|
+
strings,
|
|
240
|
+
other: nested,
|
|
241
|
+
nestedContext: "binding"
|
|
242
|
+
});
|
|
243
|
+
};
|
|
244
|
+
var expression = (strings, ...nested) => {
|
|
245
|
+
return createExpressionTemplateInstance({
|
|
246
|
+
strings,
|
|
247
|
+
other: nested,
|
|
248
|
+
nestedContext: "expression"
|
|
249
|
+
});
|
|
250
|
+
};
|
|
251
|
+
var isTemplateStringInstance = (val) => {
|
|
252
|
+
return val !== null && typeof val === "object" && val[OpaqueIdentifier] === true;
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/utils.tsx
|
|
256
|
+
function toArray(val) {
|
|
257
|
+
return Array.isArray(val) ? val : [val];
|
|
258
|
+
}
|
|
259
|
+
function toJsonElement(value, indexOrKey, options) {
|
|
260
|
+
const indexProp = typeof indexOrKey === "number" ? { key: indexOrKey } : null;
|
|
261
|
+
if (Array.isArray(value)) {
|
|
262
|
+
return /* @__PURE__ */ React3.createElement("array", { ...indexProp }, value.map((item, idx) => toJsonElement(item, idx, options)));
|
|
263
|
+
}
|
|
264
|
+
if (isTemplateStringInstance(value)) {
|
|
265
|
+
if (typeof indexOrKey === "string" && options?.propertiesToSkip?.includes(indexOrKey)) {
|
|
266
|
+
return /* @__PURE__ */ React3.createElement("value", { ...indexProp }, value.toValue());
|
|
267
|
+
}
|
|
268
|
+
return /* @__PURE__ */ React3.createElement("value", { ...indexProp }, value.toRefString());
|
|
269
|
+
}
|
|
270
|
+
if (typeof value === "object" && value !== null) {
|
|
271
|
+
return /* @__PURE__ */ React3.createElement("obj", { ...indexProp }, Object.keys(value).map((key) => /* @__PURE__ */ React3.createElement("property", { key, name: key }, toJsonElement(value[key], key, options))));
|
|
272
|
+
}
|
|
273
|
+
return /* @__PURE__ */ React3.createElement("value", { ...indexProp, value });
|
|
274
|
+
}
|
|
275
|
+
function toJsonProperties(value, options = { propertiesToSkip: ["applicability"] }) {
|
|
276
|
+
return Object.keys(value).map((key) => {
|
|
277
|
+
return /* @__PURE__ */ React3.createElement("property", { key, name: key }, toJsonElement(value[key], key, options));
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
function normalizeText(options) {
|
|
281
|
+
const { node, TextComp } = options;
|
|
282
|
+
const nodeArr = React3.Children.toArray(node);
|
|
283
|
+
if (nodeArr.every(
|
|
284
|
+
(n) => React3.isValidElement(n) && n.type !== TemplateStringComponent
|
|
285
|
+
)) {
|
|
286
|
+
return node;
|
|
287
|
+
}
|
|
288
|
+
if (TextComp) {
|
|
289
|
+
return /* @__PURE__ */ React3.createElement(TextComp, null, nodeArr);
|
|
290
|
+
}
|
|
291
|
+
throw new Error(
|
|
292
|
+
`Tried to convert node to Text Asset, but no Component was supplied.`
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
function normalizeToCollection(options) {
|
|
296
|
+
const { node, CollectionComp } = options;
|
|
297
|
+
if (React3.Children.count(node) > 1 && React3.Children.toArray(node).every((n) => typeof n !== "string")) {
|
|
298
|
+
if (!CollectionComp) {
|
|
299
|
+
throw new Error(
|
|
300
|
+
`Tried to convert array to a collection asset, but no Component was given.`
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
return /* @__PURE__ */ React3.createElement(CollectionComp, null, node);
|
|
304
|
+
}
|
|
305
|
+
return normalizeText({ ...options, node });
|
|
306
|
+
}
|
|
307
|
+
function flattenChildren(children) {
|
|
308
|
+
const childrenArray = React3.Children.toArray(children);
|
|
309
|
+
return childrenArray.reduce((flatChildren, child) => {
|
|
310
|
+
if (child.type === React3.Fragment) {
|
|
311
|
+
return flatChildren.concat(
|
|
312
|
+
flattenChildren(child.props.children)
|
|
313
|
+
);
|
|
314
|
+
}
|
|
315
|
+
flatChildren.push(child);
|
|
316
|
+
return flatChildren;
|
|
317
|
+
}, []);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx
|
|
321
|
+
var SlotContext = import_react2.default.createContext(void 0);
|
|
322
|
+
var AssetWrapper = import_react2.default.forwardRef(function AssetWrapper2(props, ref) {
|
|
323
|
+
const { children, ...rest } = props;
|
|
324
|
+
return /* @__PURE__ */ import_react2.default.createElement("obj", { ref }, toJsonProperties(rest), /* @__PURE__ */ import_react2.default.createElement("property", { name: "asset" }, children));
|
|
325
|
+
});
|
|
326
|
+
var GeneratedIDProperty = (props) => {
|
|
327
|
+
const currentPrefixId = useGetIdPrefix();
|
|
328
|
+
return /* @__PURE__ */ import_react2.default.createElement("property", { name: "id" }, props.id ?? currentPrefixId);
|
|
329
|
+
};
|
|
330
|
+
var Asset = import_react2.default.forwardRef((props, ref) => {
|
|
331
|
+
const { id, type, applicability, children, ...rest } = props;
|
|
332
|
+
const slotContext = import_react2.default.useContext(SlotContext);
|
|
333
|
+
const localRef = import_react2.default.useRef(null);
|
|
334
|
+
const Wrapper = slotContext?.wrapInAsset ? AssetWrapper : import_react2.default.Fragment;
|
|
335
|
+
return /* @__PURE__ */ import_react2.default.createElement(
|
|
336
|
+
Wrapper,
|
|
337
|
+
{
|
|
338
|
+
ref: slotContext?.wrapInAsset ? (0, import_react_merge_refs.default)([ref, localRef]) : void 0,
|
|
339
|
+
...slotContext?.wrapInAsset && slotContext?.additionalProperties ? slotContext?.additionalProperties : {}
|
|
340
|
+
},
|
|
341
|
+
/* @__PURE__ */ import_react2.default.createElement(OptionalIDSuffixProvider, { wrapperRef: localRef }, /* @__PURE__ */ import_react2.default.createElement(SlotContext.Provider, { value: void 0 }, /* @__PURE__ */ import_react2.default.createElement(IDProvider, { id }, /* @__PURE__ */ import_react2.default.createElement(
|
|
342
|
+
"obj",
|
|
343
|
+
{
|
|
344
|
+
ref: slotContext?.wrapInAsset ? void 0 : (0, import_react_merge_refs.default)([ref, localRef])
|
|
345
|
+
},
|
|
346
|
+
/* @__PURE__ */ import_react2.default.createElement(GeneratedIDProperty, { id }),
|
|
347
|
+
/* @__PURE__ */ import_react2.default.createElement("property", { name: "type" }, type),
|
|
348
|
+
applicability !== void 0 && /* @__PURE__ */ import_react2.default.createElement("property", { name: "applicability" }, /* @__PURE__ */ import_react2.default.createElement(
|
|
349
|
+
"value",
|
|
350
|
+
{
|
|
351
|
+
value: typeof applicability === "boolean" ? applicability : applicability.toValue()
|
|
352
|
+
}
|
|
353
|
+
)),
|
|
354
|
+
toJsonProperties(rest),
|
|
355
|
+
children
|
|
356
|
+
))))
|
|
357
|
+
);
|
|
358
|
+
});
|
|
359
|
+
Asset.displayName = "Asset";
|
|
360
|
+
Asset.defaultProps = {
|
|
361
|
+
id: void 0,
|
|
362
|
+
children: void 0
|
|
363
|
+
};
|
|
364
|
+
var View = import_react2.default.forwardRef(
|
|
365
|
+
(props, ref) => {
|
|
366
|
+
const { validation, children, ...rest } = props;
|
|
367
|
+
return /* @__PURE__ */ import_react2.default.createElement(Asset, { ref, ...rest }, validation && /* @__PURE__ */ import_react2.default.createElement("property", { key: "validation", name: "validation" }, toJsonElement(validation, "validation", {
|
|
368
|
+
propertiesToSkip: ["ref"]
|
|
369
|
+
})), children);
|
|
370
|
+
}
|
|
371
|
+
);
|
|
372
|
+
View.displayName = "View";
|
|
373
|
+
View.defaultProps = {
|
|
374
|
+
id: void 0,
|
|
375
|
+
children: void 0
|
|
376
|
+
};
|
|
377
|
+
var Slot = (props) => {
|
|
378
|
+
const { TextComp, CollectionComp } = props;
|
|
379
|
+
const children = flattenChildren(props.children);
|
|
380
|
+
const propRef = import_react2.default.useRef(null);
|
|
381
|
+
return /* @__PURE__ */ import_react2.default.createElement("property", { ref: propRef, name: props.name }, /* @__PURE__ */ import_react2.default.createElement(IDSuffixProvider, { suffix: props.name }, /* @__PURE__ */ import_react2.default.createElement(IndexSuffixStopContext.Provider, { value: false }, /* @__PURE__ */ import_react2.default.createElement(
|
|
382
|
+
SlotContext.Provider,
|
|
383
|
+
{
|
|
384
|
+
value: {
|
|
385
|
+
ref: propRef,
|
|
386
|
+
propertyName: props.name,
|
|
387
|
+
wrapInAsset: props.wrapInAsset ?? false,
|
|
388
|
+
isArray: props.isArray ?? false,
|
|
389
|
+
additionalProperties: props.additionalProperties,
|
|
390
|
+
TextComp,
|
|
391
|
+
CollectionComp
|
|
392
|
+
}
|
|
393
|
+
},
|
|
394
|
+
props.isArray && /* @__PURE__ */ import_react2.default.createElement("array", null, import_react2.default.Children.map(children, (child, index) => {
|
|
395
|
+
return (
|
|
396
|
+
// eslint-disable-next-line react/no-array-index-key
|
|
397
|
+
/* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, { key: `${props.name}-${index}` }, normalizeText({ node: child, TextComp }))
|
|
398
|
+
);
|
|
399
|
+
})),
|
|
400
|
+
!props.isArray && normalizeToCollection({
|
|
401
|
+
node: children,
|
|
402
|
+
TextComp,
|
|
403
|
+
CollectionComp
|
|
404
|
+
})
|
|
405
|
+
))));
|
|
406
|
+
};
|
|
407
|
+
function createSlot(options) {
|
|
408
|
+
return (props) => {
|
|
409
|
+
const { children, ...other } = props;
|
|
410
|
+
return /* @__PURE__ */ import_react2.default.createElement(Slot, { ...options, additionalProperties: other }, children);
|
|
411
|
+
};
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/switch.tsx
|
|
415
|
+
var import_react3 = __toESM(require("react"));
|
|
416
|
+
var import_react_json_reconciler2 = require("react-json-reconciler");
|
|
417
|
+
var SwitchContext = import_react3.default.createContext({});
|
|
418
|
+
var Switch = (props) => {
|
|
419
|
+
const slotContext = import_react3.default.useContext(SlotContext);
|
|
420
|
+
const propertyNode = import_react3.default.useRef(null);
|
|
421
|
+
return /* @__PURE__ */ import_react3.default.createElement("obj", { ref: propertyNode }, /* @__PURE__ */ import_react3.default.createElement(
|
|
422
|
+
SwitchContext.Provider,
|
|
423
|
+
{
|
|
424
|
+
value: {
|
|
425
|
+
...props,
|
|
426
|
+
TextComp: slotContext?.TextComp,
|
|
427
|
+
CollectionComp: slotContext?.CollectionComp
|
|
428
|
+
}
|
|
429
|
+
},
|
|
430
|
+
/* @__PURE__ */ import_react3.default.createElement(OptionalIDSuffixProvider, { wrapperRef: propertyNode }, /* @__PURE__ */ import_react3.default.createElement("property", { name: props.isDynamic ? "dynamicSwitch" : "staticSwitch" }, /* @__PURE__ */ import_react3.default.createElement(SlotContext.Provider, { value: void 0 }, /* @__PURE__ */ import_react3.default.createElement("array", null, props.children))))
|
|
431
|
+
), slotContext?.additionalProperties && toJsonProperties(slotContext.additionalProperties));
|
|
432
|
+
};
|
|
433
|
+
var findParentArray = (node) => {
|
|
434
|
+
if (node.type === "array") {
|
|
435
|
+
return node;
|
|
436
|
+
}
|
|
437
|
+
if (node.parent) {
|
|
438
|
+
return findParentArray(node.parent);
|
|
439
|
+
}
|
|
440
|
+
throw new Error("can't find parent array");
|
|
441
|
+
};
|
|
442
|
+
var findArrayIndex = (node) => {
|
|
443
|
+
const parentArray = findParentArray(node);
|
|
444
|
+
const allSearch = (0, import_react_json_reconciler2.flattenNodes)(parentArray.children);
|
|
445
|
+
return allSearch.indexOf(node);
|
|
446
|
+
};
|
|
447
|
+
var Case = (props) => {
|
|
448
|
+
const slotContext = import_react3.default.useContext(SlotContext);
|
|
449
|
+
const switchContext = import_react3.default.useContext(SwitchContext);
|
|
450
|
+
const [caseIndex, setCaseIndex] = import_react3.default.useState(-1);
|
|
451
|
+
const caseNode = import_react3.default.useRef(null);
|
|
452
|
+
import_react3.default.useLayoutEffect(() => {
|
|
453
|
+
if (caseNode.current) {
|
|
454
|
+
const index = findArrayIndex(caseNode.current);
|
|
455
|
+
if (index !== caseIndex) {
|
|
456
|
+
setCaseIndex(index);
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}, [caseIndex]);
|
|
460
|
+
let expValue = true;
|
|
461
|
+
if (props.exp !== void 0) {
|
|
462
|
+
expValue = isTemplateStringInstance(props.exp) ? props.exp.toValue() : props.exp;
|
|
463
|
+
}
|
|
464
|
+
return /* @__PURE__ */ import_react3.default.createElement("obj", { ref: caseNode }, /* @__PURE__ */ import_react3.default.createElement("property", { name: "case" }, /* @__PURE__ */ import_react3.default.createElement("value", { value: expValue })), /* @__PURE__ */ import_react3.default.createElement(
|
|
465
|
+
IDSuffixProvider,
|
|
466
|
+
{
|
|
467
|
+
suffix: `${switchContext.isDynamic ? "dynamicSwitch" : "staticSwitch"}-${caseIndex}`
|
|
468
|
+
},
|
|
469
|
+
/* @__PURE__ */ import_react3.default.createElement(
|
|
470
|
+
SlotContext.Provider,
|
|
471
|
+
{
|
|
472
|
+
value: slotContext ? { ...slotContext, wrapInAsset: false } : void 0
|
|
473
|
+
},
|
|
474
|
+
/* @__PURE__ */ import_react3.default.createElement("property", { name: "asset" }, normalizeToCollection({
|
|
475
|
+
node: props.children,
|
|
476
|
+
TextComp: switchContext?.TextComp,
|
|
477
|
+
CollectionComp: switchContext?.CollectionComp
|
|
478
|
+
}))
|
|
479
|
+
)
|
|
480
|
+
));
|
|
481
|
+
};
|
|
482
|
+
Switch.Case = Case;
|
|
483
|
+
|
|
484
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/template.tsx
|
|
485
|
+
var import_react4 = __toESM(require("react"));
|
|
486
|
+
var import_react_json_reconciler3 = require("react-json-reconciler");
|
|
487
|
+
var TemplateContext = import_react4.default.createContext({
|
|
488
|
+
depth: 0
|
|
489
|
+
});
|
|
490
|
+
function addTemplateToObject(obj, templateObj, templateParentNodeType) {
|
|
491
|
+
let templateProp = obj.properties.find(
|
|
492
|
+
(p) => p.keyNode.value === "template" && p.valueNode?.type === "array"
|
|
493
|
+
);
|
|
494
|
+
if (!templateProp) {
|
|
495
|
+
templateProp = new import_react_json_reconciler3.PropertyNode(new import_react_json_reconciler3.ValueNode("template"), new import_react_json_reconciler3.ArrayNode());
|
|
496
|
+
templateProp.parent = obj;
|
|
497
|
+
obj.properties.push(templateProp);
|
|
498
|
+
}
|
|
499
|
+
const templateItems = templateProp.valueNode;
|
|
500
|
+
templateItems.items.push(templateObj);
|
|
501
|
+
templateObj.parent = templateItems;
|
|
502
|
+
const templateParentProp = obj.properties.find(
|
|
503
|
+
(p) => p.keyNode.value === templateParentNodeType && p.valueNode?.type === "array"
|
|
504
|
+
);
|
|
505
|
+
if (templateParentProp) {
|
|
506
|
+
const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);
|
|
507
|
+
const templateParentValueNode = obj.properties[indexOfTemplateParent]?.valueNode;
|
|
508
|
+
if (templateParentValueNode) {
|
|
509
|
+
const templateParentArray = (0, import_react_json_reconciler3.toJSON)(templateParentValueNode);
|
|
510
|
+
if (Array.isArray(templateParentArray) && templateParentArray.length === 0) {
|
|
511
|
+
obj.properties.splice(indexOfTemplateParent, 1);
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
return () => {
|
|
516
|
+
templateItems.items = templateItems.items.filter((t) => t !== templateObj);
|
|
517
|
+
if (templateItems.children.length === 0 && templateProp) {
|
|
518
|
+
obj.properties.splice(obj.properties.indexOf(templateProp, 1));
|
|
519
|
+
}
|
|
520
|
+
};
|
|
521
|
+
}
|
|
522
|
+
var TemplateProvider = (props) => {
|
|
523
|
+
const baseContext = import_react4.default.useContext(TemplateContext);
|
|
524
|
+
return /* @__PURE__ */ import_react4.default.createElement(TemplateContext.Provider, { value: { depth: baseContext.depth + 1 } }, props.children);
|
|
525
|
+
};
|
|
526
|
+
var getParentObject = (node) => {
|
|
527
|
+
if (node.type === "object") {
|
|
528
|
+
return node;
|
|
529
|
+
}
|
|
530
|
+
if (node.parent) {
|
|
531
|
+
return getParentObject(node.parent);
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var getParentProperty = (node) => {
|
|
535
|
+
if (node.type === "property") {
|
|
536
|
+
return node;
|
|
537
|
+
}
|
|
538
|
+
if (node.parent) {
|
|
539
|
+
return getParentProperty(node.parent);
|
|
540
|
+
}
|
|
541
|
+
};
|
|
542
|
+
var Template = (props) => {
|
|
543
|
+
const baseContext = import_react4.default.useContext(TemplateContext);
|
|
544
|
+
const dynamicProp = props.dynamic ?? false;
|
|
545
|
+
const [outputProp, setOutputProp] = import_react4.default.useState(
|
|
546
|
+
props.output
|
|
547
|
+
);
|
|
548
|
+
const proxyRef = import_react4.default.useRef(null);
|
|
549
|
+
const valueRef = import_react4.default.useRef(null);
|
|
550
|
+
const outputElement = import_react4.default.useMemo(() => new import_react_json_reconciler3.ProxyNode(), []);
|
|
551
|
+
import_react4.default.useLayoutEffect(() => {
|
|
552
|
+
const propNode = proxyRef.current && getParentProperty(proxyRef.current);
|
|
553
|
+
if (outputProp === void 0 && propNode) {
|
|
554
|
+
setOutputProp(propNode.keyNode.value);
|
|
555
|
+
}
|
|
556
|
+
}, [proxyRef, outputProp]);
|
|
557
|
+
import_react4.default.useEffect(() => {
|
|
558
|
+
const templateObj = outputElement.items[0];
|
|
559
|
+
if (proxyRef.current) {
|
|
560
|
+
const parentObject = getParentObject(proxyRef.current);
|
|
561
|
+
if (!parentObject) {
|
|
562
|
+
throw new Error("Unable to find parent to add template to");
|
|
563
|
+
}
|
|
564
|
+
if (!outputProp) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
return addTemplateToObject(parentObject, templateObj, outputProp);
|
|
568
|
+
}
|
|
569
|
+
}, [proxyRef, outputProp, outputElement.items]);
|
|
570
|
+
return /* @__PURE__ */ import_react4.default.createElement("proxy", { ref: proxyRef }, /* @__PURE__ */ import_react4.default.createElement(import_react4.default.Fragment, null, (0, import_react_json_reconciler3.createPortal)(
|
|
571
|
+
/* @__PURE__ */ import_react4.default.createElement(
|
|
572
|
+
OptionalIDSuffixProvider,
|
|
573
|
+
{
|
|
574
|
+
wrapperRef: valueRef,
|
|
575
|
+
templateIndex: `_index${baseContext.depth === 0 ? "" : baseContext.depth}_`
|
|
576
|
+
},
|
|
577
|
+
/* @__PURE__ */ import_react4.default.createElement(TemplateProvider, null, /* @__PURE__ */ import_react4.default.createElement("object", null, /* @__PURE__ */ import_react4.default.createElement("property", { name: "data" }, props.data.toValue()), /* @__PURE__ */ import_react4.default.createElement("property", { name: "output" }, outputProp), /* @__PURE__ */ import_react4.default.createElement("property", { name: "value" }, props.children), dynamicProp && /* @__PURE__ */ import_react4.default.createElement("property", { name: "dynamic" }, toJsonElement(dynamicProp))))
|
|
578
|
+
),
|
|
579
|
+
outputElement
|
|
580
|
+
), /* @__PURE__ */ import_react4.default.createElement("value", { ref: valueRef, value: void 0 })));
|
|
581
|
+
};
|
|
582
|
+
|
|
583
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/index.ts
|
|
584
|
+
__reExport(src_exports, require("react-json-reconciler"), module.exports);
|
|
585
|
+
|
|
586
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/schema.ts
|
|
587
|
+
var import_dequal = require("dequal");
|
|
588
|
+
var import_tapable_ts = require("tapable-ts");
|
|
589
|
+
var bindingSymbol = Symbol("binding");
|
|
590
|
+
var SchemaTypeName = Symbol("Schema Rename");
|
|
591
|
+
var isTypeDef = (property) => {
|
|
592
|
+
return property.type !== void 0;
|
|
593
|
+
};
|
|
594
|
+
var SchemaGenerator = class {
|
|
595
|
+
constructor(logger) {
|
|
596
|
+
this.hooks = {
|
|
597
|
+
createSchemaNode: new import_tapable_ts.SyncWaterfallHook()
|
|
598
|
+
};
|
|
599
|
+
/**
|
|
600
|
+
* Converts an object to a `Schema.Schema` representation
|
|
601
|
+
* Note: uses iteration to prevent potentially very deep recursion on large objects
|
|
602
|
+
*/
|
|
603
|
+
this.toSchema = (schema) => {
|
|
604
|
+
const newSchema = {
|
|
605
|
+
ROOT: {}
|
|
606
|
+
};
|
|
607
|
+
this.children = [];
|
|
608
|
+
this.generatedDataTypes.clear();
|
|
609
|
+
Object.keys(schema).forEach((property) => {
|
|
610
|
+
const subType = schema[property];
|
|
611
|
+
newSchema.ROOT[property] = this.hooks.createSchemaNode.call(
|
|
612
|
+
this.processChild(property, subType),
|
|
613
|
+
subType
|
|
614
|
+
);
|
|
615
|
+
});
|
|
616
|
+
while (this.children.length > 0) {
|
|
617
|
+
const c = this.children.pop();
|
|
618
|
+
if (c === void 0) {
|
|
619
|
+
break;
|
|
620
|
+
}
|
|
621
|
+
const { name, child } = c;
|
|
622
|
+
const typeDef = {};
|
|
623
|
+
Object.keys(child).forEach((property) => {
|
|
624
|
+
const subType = child[property];
|
|
625
|
+
typeDef[property] = this.hooks.createSchemaNode.call(
|
|
626
|
+
this.processChild(property, subType),
|
|
627
|
+
subType
|
|
628
|
+
);
|
|
629
|
+
});
|
|
630
|
+
newSchema[name] = typeDef;
|
|
631
|
+
}
|
|
632
|
+
return newSchema;
|
|
633
|
+
};
|
|
634
|
+
/**
|
|
635
|
+
* Make an intermediate `Schema.DataType` object given a name
|
|
636
|
+
*/
|
|
637
|
+
this.makePlaceholderType = (typeName) => {
|
|
638
|
+
return {
|
|
639
|
+
type: `${typeName}Type`
|
|
640
|
+
};
|
|
641
|
+
};
|
|
642
|
+
this.children = [];
|
|
643
|
+
this.generatedDataTypes = /* @__PURE__ */ new Map();
|
|
644
|
+
this.logger = logger ?? console;
|
|
645
|
+
}
|
|
646
|
+
/**
|
|
647
|
+
* Processes the children of an object Node
|
|
648
|
+
* Newly discovered children get added to the provided array
|
|
649
|
+
*/
|
|
650
|
+
processChild(property, subType) {
|
|
651
|
+
if (isTypeDef(subType)) {
|
|
652
|
+
return subType;
|
|
653
|
+
}
|
|
654
|
+
let intermediateType;
|
|
655
|
+
let child;
|
|
656
|
+
if (Array.isArray(subType)) {
|
|
657
|
+
if (subType.length > 1) {
|
|
658
|
+
this.logger.warn(
|
|
659
|
+
`Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`
|
|
660
|
+
);
|
|
661
|
+
}
|
|
662
|
+
const subTypeName = subType[0][SchemaTypeName] ?? property;
|
|
663
|
+
intermediateType = this.makePlaceholderArrayType(subTypeName);
|
|
664
|
+
[child] = subType;
|
|
665
|
+
} else {
|
|
666
|
+
const subTypeName = subType[SchemaTypeName] ?? property;
|
|
667
|
+
intermediateType = this.makePlaceholderType(subTypeName);
|
|
668
|
+
child = subType;
|
|
669
|
+
}
|
|
670
|
+
this.children.push({ name: intermediateType.type, child });
|
|
671
|
+
if (this.generatedDataTypes.has(intermediateType.type)) {
|
|
672
|
+
const generatedType = this.generatedDataTypes.get(
|
|
673
|
+
intermediateType.type
|
|
674
|
+
);
|
|
675
|
+
if (!(0, import_dequal.dequal)(
|
|
676
|
+
child,
|
|
677
|
+
this.generatedDataTypes.get(intermediateType.type)?.node
|
|
678
|
+
)) {
|
|
679
|
+
generatedType.count += 1;
|
|
680
|
+
const newIntermediateType = {
|
|
681
|
+
...intermediateType,
|
|
682
|
+
type: `${intermediateType.type}${generatedType.count}`
|
|
683
|
+
};
|
|
684
|
+
this.logger.warn(
|
|
685
|
+
`WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`
|
|
686
|
+
);
|
|
687
|
+
intermediateType = newIntermediateType;
|
|
688
|
+
this.children.pop();
|
|
689
|
+
this.children.push({ name: intermediateType.type, child });
|
|
690
|
+
}
|
|
691
|
+
}
|
|
692
|
+
this.generatedDataTypes.set(intermediateType.type, {
|
|
693
|
+
node: subType,
|
|
694
|
+
count: 1
|
|
695
|
+
});
|
|
696
|
+
return intermediateType;
|
|
697
|
+
}
|
|
698
|
+
/**
|
|
699
|
+
* Make an intermediate `Schema.DataType` object with array support given a name
|
|
700
|
+
*/
|
|
701
|
+
makePlaceholderArrayType(typeName) {
|
|
702
|
+
return {
|
|
703
|
+
type: `${typeName}Type`,
|
|
704
|
+
isArray: true
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
};
|
|
708
|
+
function makeBindingsForObject(obj, arrayAccessorKeys = ["_index_"]) {
|
|
709
|
+
const accessor = (paths) => {
|
|
710
|
+
const bindingMap = /* @__PURE__ */ new WeakMap();
|
|
711
|
+
return {
|
|
712
|
+
ownKeys(target) {
|
|
713
|
+
return Reflect.ownKeys(target);
|
|
714
|
+
},
|
|
715
|
+
get(target, key) {
|
|
716
|
+
const bindingKeys = Object.keys(target);
|
|
717
|
+
if (Array.isArray(target[key]) && target[key].length > 0 && target[key].every((it) => typeof it !== "object")) {
|
|
718
|
+
return [...target[key]];
|
|
719
|
+
}
|
|
720
|
+
if (!bindingMap.has(target)) {
|
|
721
|
+
bindingMap.set(target, binding`${paths.join(".")}`);
|
|
722
|
+
}
|
|
723
|
+
if (key === bindingSymbol) {
|
|
724
|
+
return paths;
|
|
725
|
+
}
|
|
726
|
+
if (Array.isArray(target) && (arrayAccessorKeys.includes(key) || typeof key === "number")) {
|
|
727
|
+
return new Proxy(target[0], accessor(paths.concat([key])));
|
|
728
|
+
}
|
|
729
|
+
if (bindingKeys.includes(key) && typeof target[key] === "object") {
|
|
730
|
+
return new Proxy(target[key], accessor(paths.concat([key])));
|
|
731
|
+
}
|
|
732
|
+
const createdInstance = bindingMap.get(target);
|
|
733
|
+
return createdInstance?.[key];
|
|
734
|
+
}
|
|
735
|
+
};
|
|
736
|
+
};
|
|
737
|
+
return new Proxy(obj, accessor([]));
|
|
738
|
+
}
|
|
739
|
+
var getBindingFromObject = (obj) => {
|
|
740
|
+
const baseBindings = obj[bindingSymbol];
|
|
741
|
+
if (!Array.isArray(baseBindings) || baseBindings.length === 0) {
|
|
742
|
+
throw new Error(`Unable to get binding for ${obj}`);
|
|
743
|
+
}
|
|
744
|
+
return binding`${baseBindings.join(".")}`;
|
|
745
|
+
};
|
|
746
|
+
var getBindingStringFromObject = (obj) => {
|
|
747
|
+
return getBindingFromObject(obj).toString();
|
|
748
|
+
};
|
|
749
|
+
var getRefStringFromObject = (obj) => {
|
|
750
|
+
return getBindingFromObject(obj).toRefString();
|
|
751
|
+
};
|
|
752
|
+
|
|
753
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/compiler.ts
|
|
754
|
+
var import_react6 = __toESM(require("react"));
|
|
755
|
+
var import_source_map_js = require("source-map-js");
|
|
756
|
+
var import_react_json_reconciler4 = require("react-json-reconciler");
|
|
757
|
+
var import_tapable_ts2 = require("tapable-ts");
|
|
758
|
+
|
|
759
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/utils.ts
|
|
760
|
+
var import_react5 = __toESM(require("react"));
|
|
761
|
+
var fingerprintContent = (content, filename) => {
|
|
762
|
+
if (content !== null || content !== void 0) {
|
|
763
|
+
if (import_react5.default.isValidElement(content)) {
|
|
764
|
+
return "view";
|
|
765
|
+
}
|
|
766
|
+
if (typeof content === "object" && "navigation" in content) {
|
|
767
|
+
return "flow";
|
|
768
|
+
}
|
|
769
|
+
if (!filename || filename.includes("schema")) {
|
|
770
|
+
return "schema";
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
};
|
|
774
|
+
|
|
775
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/compiler.ts
|
|
776
|
+
var parseNavigationExpressions = (nav) => {
|
|
777
|
+
function replaceExpWithStr(obj) {
|
|
778
|
+
function convExp(value) {
|
|
779
|
+
return value && typeof value === "object" && value.__type === "expression" ? value.toValue() : replaceExpWithStr(value);
|
|
780
|
+
}
|
|
781
|
+
if (Array.isArray(obj)) {
|
|
782
|
+
return obj.map(convExp);
|
|
783
|
+
}
|
|
784
|
+
if (typeof obj === "object") {
|
|
785
|
+
const copy = { ...obj };
|
|
786
|
+
for (const [key, value] of Object.entries(copy)) {
|
|
787
|
+
copy[key] = convExp(value);
|
|
788
|
+
}
|
|
789
|
+
return copy;
|
|
790
|
+
}
|
|
791
|
+
return obj;
|
|
792
|
+
}
|
|
793
|
+
return replaceExpWithStr(nav);
|
|
794
|
+
};
|
|
795
|
+
var mergeSourceMaps = (sourceMaps, generated) => {
|
|
796
|
+
const generator = new import_source_map_js.SourceMapGenerator();
|
|
797
|
+
sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {
|
|
798
|
+
const generatedLineOffset = generated.split("\n").findIndex((line) => line.includes(offsetIndexSearch));
|
|
799
|
+
const sourceLineOffset = source.split("\n").findIndex((line) => line.includes(offsetIndexSearch));
|
|
800
|
+
const lineOffset = generatedLineOffset - sourceLineOffset;
|
|
801
|
+
const generatedLine = generated.split("\n")[generatedLineOffset];
|
|
802
|
+
const sourceLine = source.split("\n")[sourceLineOffset];
|
|
803
|
+
const generatedColumn = generatedLine.indexOf(offsetIndexSearch);
|
|
804
|
+
const sourceColumn = sourceLine.indexOf(offsetIndexSearch);
|
|
805
|
+
const columnOffset = generatedColumn - sourceColumn;
|
|
806
|
+
const consumer = new import_source_map_js.SourceMapConsumer(JSON.parse(sourceMap));
|
|
807
|
+
consumer.eachMapping((mapping) => {
|
|
808
|
+
generator.addMapping({
|
|
809
|
+
generated: {
|
|
810
|
+
line: mapping.generatedLine + lineOffset,
|
|
811
|
+
column: mapping.generatedColumn + columnOffset
|
|
812
|
+
},
|
|
813
|
+
original: {
|
|
814
|
+
line: mapping.originalLine,
|
|
815
|
+
column: mapping.originalColumn
|
|
816
|
+
},
|
|
817
|
+
source: mapping.source
|
|
818
|
+
});
|
|
819
|
+
});
|
|
820
|
+
});
|
|
821
|
+
return generator.toString();
|
|
822
|
+
};
|
|
823
|
+
var DSLCompiler = class {
|
|
824
|
+
constructor(logger) {
|
|
825
|
+
this.hooks = {
|
|
826
|
+
// Hook to access the schema generator instance when initialized
|
|
827
|
+
schemaGenerator: new import_tapable_ts2.SyncHook(),
|
|
828
|
+
// Hook to access pre-compilation object
|
|
829
|
+
preProcessFlow: new import_tapable_ts2.AsyncSeriesWaterfallHook(),
|
|
830
|
+
// Hook to access post-compilation Flow before output is written
|
|
831
|
+
postProcessFlow: new import_tapable_ts2.AsyncSeriesWaterfallHook(),
|
|
832
|
+
// Hook called after all files are compiled. Revives the output directory
|
|
833
|
+
onEnd: new import_tapable_ts2.AsyncSeriesHook()
|
|
834
|
+
};
|
|
835
|
+
this.logger = logger ?? console;
|
|
836
|
+
}
|
|
837
|
+
/** Convert an object (flow, view, schema, etc) into it's JSON representation */
|
|
838
|
+
async serialize(value, context) {
|
|
839
|
+
if (typeof value !== "object" || value === null) {
|
|
840
|
+
throw new Error("Unable to serialize non-object");
|
|
841
|
+
}
|
|
842
|
+
const type = context?.type ? context.type : fingerprintContent(value);
|
|
843
|
+
if (!this.schemaGenerator) {
|
|
844
|
+
this.schemaGenerator = new SchemaGenerator(this.logger);
|
|
845
|
+
this.hooks.schemaGenerator.call(this.schemaGenerator);
|
|
846
|
+
}
|
|
847
|
+
if (type === "view") {
|
|
848
|
+
const { jsonValue, sourceMap } = await (0, import_react_json_reconciler4.render)(value, {
|
|
849
|
+
collectSourceMap: true
|
|
850
|
+
});
|
|
851
|
+
return {
|
|
852
|
+
value: jsonValue,
|
|
853
|
+
sourceMap
|
|
854
|
+
};
|
|
855
|
+
}
|
|
856
|
+
if (type === "flow") {
|
|
857
|
+
const allSourceMaps = [];
|
|
858
|
+
const copiedValue = {
|
|
859
|
+
...value
|
|
860
|
+
};
|
|
861
|
+
copiedValue.views = await Promise.all(
|
|
862
|
+
copiedValue?.views?.map(async (node) => {
|
|
863
|
+
if (import_react6.default.isValidElement(node)) {
|
|
864
|
+
const { jsonValue, sourceMap, stringValue } = await (0, import_react_json_reconciler4.render)(node, {
|
|
865
|
+
collectSourceMap: true
|
|
866
|
+
});
|
|
867
|
+
if (sourceMap) {
|
|
868
|
+
const searchIdLine = stringValue.split("\n").find(
|
|
869
|
+
(line) => line.includes(
|
|
870
|
+
`"id": "${jsonValue.id}"`
|
|
871
|
+
)
|
|
872
|
+
);
|
|
873
|
+
if (searchIdLine) {
|
|
874
|
+
allSourceMaps.push({
|
|
875
|
+
sourceMap,
|
|
876
|
+
offsetIndexSearch: searchIdLine,
|
|
877
|
+
source: stringValue
|
|
878
|
+
});
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
return jsonValue;
|
|
882
|
+
}
|
|
883
|
+
return node;
|
|
884
|
+
}) ?? []
|
|
885
|
+
);
|
|
886
|
+
if ("navigation" in value) {
|
|
887
|
+
Object.entries(value.navigation).forEach(([navKey, node]) => {
|
|
888
|
+
if (typeof node === "object") {
|
|
889
|
+
Object.entries(node).forEach(([nodeKey, flowNode]) => {
|
|
890
|
+
if (flowNode && typeof flowNode === "object" && "state_type" in flowNode && flowNode.state_type === "VIEW" && import_react6.default.isValidElement(flowNode.ref)) {
|
|
891
|
+
const actualViewIndex = value.views?.indexOf?.(
|
|
892
|
+
flowNode.ref
|
|
893
|
+
);
|
|
894
|
+
if (actualViewIndex !== void 0 && actualViewIndex > -1) {
|
|
895
|
+
const actualId = copiedValue.views?.[actualViewIndex]?.id;
|
|
896
|
+
copiedValue.navigation[navKey][nodeKey].ref = actualId;
|
|
897
|
+
}
|
|
898
|
+
}
|
|
899
|
+
});
|
|
900
|
+
}
|
|
901
|
+
});
|
|
902
|
+
}
|
|
903
|
+
if ("schema" in copiedValue) {
|
|
904
|
+
copiedValue.schema = this.schemaGenerator.toSchema(copiedValue.schema);
|
|
905
|
+
}
|
|
906
|
+
copiedValue.navigation = parseNavigationExpressions(
|
|
907
|
+
copiedValue.navigation
|
|
908
|
+
);
|
|
909
|
+
if (value) {
|
|
910
|
+
const postProcessFlow = await this.hooks.postProcessFlow.call(
|
|
911
|
+
copiedValue
|
|
912
|
+
);
|
|
913
|
+
return {
|
|
914
|
+
value: postProcessFlow,
|
|
915
|
+
sourceMap: mergeSourceMaps(
|
|
916
|
+
allSourceMaps,
|
|
917
|
+
JSON.stringify(copiedValue, null, 2)
|
|
918
|
+
)
|
|
919
|
+
};
|
|
920
|
+
}
|
|
921
|
+
}
|
|
922
|
+
return {
|
|
923
|
+
value: this.schemaGenerator.toSchema(value)
|
|
924
|
+
};
|
|
925
|
+
}
|
|
926
|
+
};
|
|
927
|
+
|
|
928
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/types.ts
|
|
929
|
+
var DefaultCompilerContentTypes = ["view", "flow", "schema"];
|
|
930
|
+
function isDefaultCompilerContentType(t) {
|
|
931
|
+
return DefaultCompilerContentTypes.includes(t);
|
|
932
|
+
}
|
|
933
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
934
|
+
0 && (module.exports = {
|
|
935
|
+
Asset,
|
|
936
|
+
AssetWrapper,
|
|
937
|
+
DSLCompiler,
|
|
938
|
+
GeneratedIDProperty,
|
|
939
|
+
IDProvider,
|
|
940
|
+
IDSuffixIndexProvider,
|
|
941
|
+
IDSuffixProvider,
|
|
942
|
+
IndexSuffixStopContext,
|
|
943
|
+
OptionalIDSuffixProvider,
|
|
944
|
+
SchemaGenerator,
|
|
945
|
+
SchemaTypeName,
|
|
946
|
+
Slot,
|
|
947
|
+
SlotContext,
|
|
948
|
+
Switch,
|
|
949
|
+
Template,
|
|
950
|
+
TemplateContext,
|
|
951
|
+
TemplateStringComponent,
|
|
952
|
+
View,
|
|
953
|
+
binding,
|
|
954
|
+
createSlot,
|
|
955
|
+
expression,
|
|
956
|
+
fingerprintContent,
|
|
957
|
+
flattenChildren,
|
|
958
|
+
getBindingFromObject,
|
|
959
|
+
getBindingStringFromObject,
|
|
960
|
+
getRefStringFromObject,
|
|
961
|
+
isDefaultCompilerContentType,
|
|
962
|
+
isTemplateStringInstance,
|
|
963
|
+
makeBindingsForObject,
|
|
964
|
+
normalizeText,
|
|
965
|
+
normalizeToCollection,
|
|
966
|
+
toArray,
|
|
967
|
+
toJsonElement,
|
|
968
|
+
toJsonProperties,
|
|
969
|
+
useGetIdPrefix,
|
|
970
|
+
useIndexInSlot,
|
|
971
|
+
...require("react-json-reconciler")
|
|
972
|
+
});
|
|
973
|
+
//# sourceMappingURL=index.cjs.map
|