@player-tools/dsl 0.5.2-next.1 → 0.5.2

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.
@@ -169,9 +169,20 @@ var createTemplateInstance = (options) => {
169
169
  return sum + next + (element2?.toRefString(options) ?? "");
170
170
  }, "");
171
171
  if (options.nestedContext === "expression") {
172
- const parsedExpression = (0, import_player.parseExpression)(value, { strict: false });
173
- if (parsedExpression.error) {
174
- throw parsedExpression.error;
172
+ try {
173
+ (0, import_player.parseExpression)(value);
174
+ } catch (e) {
175
+ if (e instanceof Error) {
176
+ let message;
177
+ if ((0, import_player.isErrorWithLocation)(e)) {
178
+ message = `${e} in expression: \r
179
+ ${value.slice(0, e.index + 1) + "\u2588" + value.slice(e.index + 1)}`;
180
+ } else {
181
+ message = `${e} in expression ${value}`;
182
+ }
183
+ throw new Error(message);
184
+ }
185
+ throw new Error(`Unknown problem parsing expression ${e}`);
175
186
  }
176
187
  }
177
188
  const toString = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/auto-id.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/utils.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/switch.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/template.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/schema.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/compiler.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/utils.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/types.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./auto-id\";\nexport * from \"./types\";\nexport * from \"./string-templates\";\nexport * from \"./utils\";\nexport * from \"./switch\";\nexport * from \"./template\";\nexport * from \"react-json-reconciler\";\nexport * from \"./compiler/schema\";\nexport * from \"./compiler\";\nexport * from \"./compiler/types\";\n","import React from \"react\";\nimport type { ObjectNode, PropertyNode } from \"react-json-reconciler\";\nimport type { View as ViewType } from \"@player-ui/types\";\nimport type { PlayerApplicability, WithChildren } from \"./types\";\nimport {\n IDProvider,\n IDSuffixProvider,\n IndexSuffixStopContext,\n OptionalIDSuffixProvider,\n useGetIdPrefix,\n} from \"./auto-id\";\nimport {\n normalizeText,\n normalizeToCollection,\n toJsonElement,\n toJsonProperties,\n flattenChildren,\n mergeRefs,\n} from \"./utils\";\n\nexport type AssetProps = PlayerApplicability & {\n /** id of the asset */\n id?: string;\n\n /** the asset type */\n type: string;\n\n /** Any other properties on the asset */\n children?: React.ReactNode;\n\n /** other things that we don't know about */\n [key: string]: unknown;\n};\n\nexport const SlotContext = React.createContext<\n | {\n /** The property name for the slot */\n propertyName: string;\n /** If the slot represents an array */\n isArray: boolean;\n /** If the items in the slot should be wrapped in an \"asset\" object */\n wrapInAsset: boolean;\n /** Other props to add to the slot */\n additionalProperties?: any;\n /** The ref to the property node */\n ref: React.RefObject<PropertyNode>;\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n | undefined\n>(undefined);\n\n/**\n * Wraps the children in an `asset` object.\n * Additional props are added to the top level object\n */\nexport const AssetWrapper = React.forwardRef<\n ObjectNode,\n WithChildren<{ [key: string]: unknown }>\n>(function AssetWrapper(props, ref) {\n const { children, ...rest } = props;\n\n return (\n <obj ref={ref}>\n {toJsonProperties(rest)}\n <property name=\"asset\">{children}</property>\n </obj>\n );\n});\n\n/** Create a ID property for a node */\nexport const GeneratedIDProperty = (props: {\n /** the id to use if supplied by the user */\n id?: string;\n}) => {\n const currentPrefixId = useGetIdPrefix();\n return <property name=\"id\">{props.id ?? currentPrefixId}</property>;\n};\n\n/** An asset */\nexport const Asset = React.forwardRef<ObjectNode, AssetProps>((props, ref) => {\n const { id, type, applicability, children, ...rest } = props;\n const slotContext = React.useContext(SlotContext);\n const localRef = React.useRef<ObjectNode>(null);\n const Wrapper = slotContext?.wrapInAsset ? AssetWrapper : React.Fragment;\n\n return (\n <Wrapper\n ref={slotContext?.wrapInAsset ? mergeRefs([ref, localRef]) : undefined}\n {...(slotContext?.wrapInAsset && slotContext?.additionalProperties\n ? slotContext?.additionalProperties\n : {})}\n >\n <OptionalIDSuffixProvider wrapperRef={localRef}>\n <SlotContext.Provider value={undefined}>\n <IDProvider id={id}>\n <obj\n ref={\n slotContext?.wrapInAsset\n ? undefined\n : mergeRefs([ref, localRef])\n }\n >\n <GeneratedIDProperty id={id} />\n <property name=\"type\">{type}</property>\n {applicability !== undefined && (\n <property name=\"applicability\">\n <value\n value={\n typeof applicability === \"boolean\"\n ? applicability\n : applicability.toValue()\n }\n />\n </property>\n )}\n {toJsonProperties(rest)}\n {children}\n </obj>\n </IDProvider>\n </SlotContext.Provider>\n </OptionalIDSuffixProvider>\n </Wrapper>\n );\n});\n\nAsset.displayName = \"Asset\";\n\nAsset.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\nexport const View = React.forwardRef<ObjectNode, AssetProps & ViewType>(\n (props, ref) => {\n const { validation, children, ...rest } = props;\n\n return (\n <Asset ref={ref} {...rest}>\n {validation && (\n <property key=\"validation\" name=\"validation\">\n {toJsonElement(validation, \"validation\", {\n propertiesToSkip: [\"ref\"],\n })}\n </property>\n )}\n {children}\n </Asset>\n );\n }\n);\n\nView.displayName = \"View\";\n\nView.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\n/** A component to generate a named property slot */\nexport const Slot = (props: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** Other properties to add to the slot */\n additionalProperties?: any;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) => {\n const { TextComp, CollectionComp } = props;\n const children = flattenChildren(props.children);\n const propRef = React.useRef<PropertyNode>(null);\n\n return (\n <property ref={propRef} name={props.name}>\n <IDSuffixProvider suffix={props.name}>\n <IndexSuffixStopContext.Provider value={false}>\n <SlotContext.Provider\n value={{\n ref: propRef,\n propertyName: props.name,\n wrapInAsset: props.wrapInAsset ?? false,\n isArray: props.isArray ?? false,\n additionalProperties: props.additionalProperties,\n TextComp,\n CollectionComp,\n }}\n >\n {props.isArray && (\n <array>\n {React.Children.map(children, (child, index) => {\n return (\n // eslint-disable-next-line react/no-array-index-key\n <React.Fragment key={`${props.name}-${index}`}>\n {normalizeText({ node: child, TextComp })}\n </React.Fragment>\n );\n })}\n </array>\n )}\n\n {!props.isArray &&\n normalizeToCollection({\n node: children,\n TextComp,\n CollectionComp,\n })}\n </SlotContext.Provider>\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n </property>\n );\n};\n\n/** Create a slot for a given property */\nexport function createSlot<SlotProps = unknown>(options: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) {\n // eslint-disable-next-line react/display-name\n return (\n props: {\n /** An object to include in this property */\n children?: React.ReactNode;\n } & SlotProps\n ) => {\n const { children, ...other } = props;\n return (\n <Slot {...options} additionalProperties={other}>\n {children}\n </Slot>\n );\n };\n}\n","import React from \"react\";\nimport type { JsonNode } from \"react-json-reconciler\";\nimport { flattenNodes } from \"react-json-reconciler\";\nimport { SlotContext } from \"./components\";\nimport type { WithChildren } from \"./types\";\n\nconst IDSuffixContext = React.createContext<string>(\"root\");\n\nexport const IndexSuffixStopContext = React.createContext<boolean>(false);\n\n/** Get the generated id */\nexport const useGetIdPrefix = () => {\n return React.useContext(IDSuffixContext);\n};\n\n/** Add a suffix to a generated id */\nexport const IDSuffixProvider = (\n props: WithChildren<{\n /** The suffix to append */\n suffix: string;\n }>\n) => {\n const currentPrefix = useGetIdPrefix();\n\n return (\n <IDSuffixContext.Provider\n value={[\n currentPrefix === \"root\" ? undefined : currentPrefix,\n props.suffix,\n ]\n .filter(Boolean)\n .join(\"-\")}\n >\n {props.children}\n </IDSuffixContext.Provider>\n );\n};\n\n/** Override the generated id with the supplied one */\nexport const IDProvider = (\n props: WithChildren<{\n /** The new id to use */\n id?: string;\n }>\n) => {\n if (props.id) {\n return (\n <IDSuffixContext.Provider value={props.id}>\n {props.children}\n </IDSuffixContext.Provider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n\n/** Get the index of an item in a slot */\nexport const useIndexInSlot = (ref: React.RefObject<JsonNode>) => {\n const [index, setIndex] = React.useState(-1);\n const slotContext = React.useContext(SlotContext);\n\n React.useEffect(() => {\n if (!slotContext?.isArray) {\n throw new Error(\"Cannot get index in non-array slot\");\n }\n\n if (ref.current && slotContext?.ref.current?.valueNode?.type === \"array\") {\n const allChildren = flattenNodes(\n slotContext.ref.current.valueNode.children\n );\n const foundIndex = allChildren.indexOf(ref.current);\n\n if (foundIndex !== index) {\n setIndex(foundIndex);\n }\n }\n }, [index, ref, slotContext?.isArray, slotContext?.ref]);\n\n return index;\n};\n\n/** Add the index to the id path when in an array slot */\nexport const IDSuffixIndexProvider = (\n props: WithChildren<{\n /** The ref to use */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotIndex = useIndexInSlot(props.wrapperRef);\n\n const stopIndex = React.useContext(IndexSuffixStopContext);\n\n if (stopIndex) {\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n }\n\n return (\n <IDSuffixProvider suffix={props.templateIndex ?? String(slotIndex)}>\n <IndexSuffixStopContext.Provider value>\n {props.children}\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n );\n};\n\n/** Wrap a slot with the index if in an array slot */\nexport const OptionalIDSuffixProvider = (\n props: WithChildren<{\n /** The ref to walk upwards and use as an index */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotContext = React.useContext(SlotContext);\n\n if (slotContext?.isArray) {\n return (\n <IDSuffixIndexProvider\n wrapperRef={props.wrapperRef}\n templateIndex={props.templateIndex}\n >\n {props.children}\n </IDSuffixIndexProvider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n","import * as React from \"react\";\nimport {\n isTemplateStringInstance,\n TemplateStringComponent,\n} from \"./string-templates\";\nimport type { toJsonOptions } from \"./types\";\n\n/** Get an array version of the value */\nexport function toArray<T>(val: T | Array<T>): Array<T> {\n return Array.isArray(val) ? val : [val];\n}\n\n/** Create a component version */\nexport function toJsonElement(\n value: any,\n indexOrKey?: number | string,\n options?: toJsonOptions\n): React.ReactElement {\n const indexProp = typeof indexOrKey === \"number\" ? { key: indexOrKey } : null;\n\n if (Array.isArray(value)) {\n return (\n <array {...indexProp}>\n {value.map((item, idx) => toJsonElement(item, idx, options))}\n </array>\n );\n }\n\n /** Allow users to pass in BindingTemplateInstance and ExpressionTemplateInstance directly without turning them into strings first */\n if (isTemplateStringInstance(value)) {\n if (\n typeof indexOrKey === \"string\" &&\n options?.propertiesToSkip?.includes(indexOrKey)\n ) {\n return <value {...indexProp}>{value.toValue()}</value>;\n }\n\n return <value {...indexProp}>{value.toRefString()}</value>;\n }\n\n if (typeof value === \"object\" && value !== null) {\n return (\n <obj {...indexProp}>\n {Object.keys(value).map((key) => (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n ))}\n </obj>\n );\n }\n\n return <value {...indexProp} value={value} />;\n}\n\n/** Create a fragment for the properties */\nexport function toJsonProperties(\n value: Record<string, any>,\n options: toJsonOptions = { propertiesToSkip: [\"applicability\"] }\n) {\n return Object.keys(value).map((key) => {\n return (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n );\n });\n}\n\n/** Create a text asset if needed */\nexport function normalizeText(options: {\n /** The current node */\n node: React.ReactNode;\n\n /** A component to render a text asset */\n TextComp?: React.ComponentType<any>;\n}): React.ReactNode {\n const { node, TextComp } = options;\n\n const nodeArr = React.Children.toArray(node);\n\n if (\n nodeArr.every(\n (n) => React.isValidElement(n) && n.type !== TemplateStringComponent\n )\n ) {\n return node;\n }\n\n if (TextComp) {\n return <TextComp>{nodeArr}</TextComp>;\n }\n\n throw new Error(\n `Tried to convert node to Text Asset, but no Component was supplied.`\n );\n}\n\n/** Create a collection if needed */\nexport function normalizeToCollection(options: {\n /** the node to look at */\n node: React.ReactNode;\n\n /** A Text asset */\n TextComp?: React.ComponentType;\n\n /** A collection asset */\n CollectionComp?: React.ComponentType<any>;\n}) {\n const { node, CollectionComp } = options;\n\n if (\n React.Children.count(node) > 1 &&\n React.Children.toArray(node).every((n) => typeof n !== \"string\")\n ) {\n if (!CollectionComp) {\n throw new Error(\n `Tried to convert array to a collection asset, but no Component was given.`\n );\n }\n\n return <CollectionComp>{node}</CollectionComp>;\n }\n\n return normalizeText({ ...options, node });\n}\n\ntype ReactChildArray = ReturnType<typeof React.Children.toArray>;\n\n/**\n *\n * Hoisted from https://github.com/gregberge/react-flatten-children/blob/master/src/index.tsx\n * Peer dependencies were wrong and can't be reasonably patch it everywhere\n */\nexport function flattenChildren(children: React.ReactNode): ReactChildArray {\n const childrenArray = React.Children.toArray(children);\n return childrenArray.reduce((flatChildren: ReactChildArray, child) => {\n if ((child as React.ReactElement<any>).type === React.Fragment) {\n return flatChildren.concat(\n flattenChildren((child as React.ReactElement<any>).props.children)\n );\n }\n\n flatChildren.push(child);\n\n return flatChildren;\n }, []);\n}\n/**\n * Hoisted from https://github.com/gregberge/react-merge-refs/blob/main/src/index.tsx\n * Published packages are ESM only or have bad esm distributions causing issues when\n * used in an esm environment\n */\nexport function mergeRefs<T = any>(\n refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>\n): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref != null) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n });\n };\n}\n\n/** Generates object reference properties from the provided object */\nexport function getObjectReferences<\n OriginalPropertiesObject extends Record<string, unknown>,\n ReferencesPropertyObject extends Record<string, unknown>\n>(propertiesObject: OriginalPropertiesObject): ReferencesPropertyObject {\n const result: any = {};\n\n for (const itemProp in propertiesObject) {\n if (Object.prototype.hasOwnProperty.call(propertiesObject, itemProp)) {\n const refName = `${itemProp}Ref`;\n result[refName as keyof ReferencesPropertyObject] = { type: itemProp };\n }\n }\n\n return result;\n}\n","import * as React from \"react\";\nimport { parseExpression } from \"@player-ui/player\";\n\nexport type TemplateInstanceRefStringContext = \"binding\" | \"expression\";\nexport interface TemplateRefStringOptions {\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n}\nexport interface TemplateInstanceRefStringOptions {\n /** The array of strings for the template */\n strings: ReadonlyArray<string>;\n /** the other data that's present in the template */\n other: Array<string | TemplateStringType>;\n\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n\n /** Convert the value to a reference nested in the given context */\n toRefString: (\n options: TemplateRefStringOptions | undefined,\n value: string\n ) => string;\n}\n\nconst OpaqueIdentifier = Symbol(\"TemplateStringType\");\n\nexport type TemplateStringType = React.ReactElement & {\n /** An identifier to show that this is a template type */\n [OpaqueIdentifier]: true;\n /** The value of the template string when in another string */\n toString: () => string;\n /** the raw value of the template string */\n toValue: () => string;\n /** the dereferenced value when used in another */\n toRefString: (options?: TemplateRefStringOptions) => string;\n};\n\nexport type BindingTemplateInstance = TemplateStringType & {\n /** An identifier for a binding instance */\n __type: \"binding\";\n};\n\nexport type ExpressionTemplateInstance = TemplateStringType & {\n /** The identifier for an expression instance */\n __type: \"expression\";\n};\n\n/** A react component for rendering a template string type */\nexport const TemplateStringComponent = (props: {\n /** The string value of the child template string */\n value: string;\n}) => {\n return React.createElement(\n \"value\",\n {\n value: props.value,\n },\n null\n );\n};\n\n/** The generic template string handler */\nconst createTemplateInstance = (\n options: TemplateInstanceRefStringOptions\n): TemplateStringType => {\n const value = options.strings.reduce((sum, next, i) => {\n const element = options.other[i];\n if (typeof element === \"string\") {\n return sum + next + element;\n }\n\n return sum + next + (element?.toRefString(options) ?? \"\");\n }, \"\");\n\n /** Try to parse the expression as valid */\n if (options.nestedContext === \"expression\") {\n const parsedExpression = parseExpression(value, { strict: false });\n if (parsedExpression.error) {\n throw parsedExpression.error;\n }\n }\n\n /** get the unwrapped version */\n const toString = () => {\n return options.toRefString({}, value);\n };\n\n /** get the raw value of the template */\n const toValue = () => {\n return value;\n };\n\n /** This lets us use it directly as a child element in React */\n const element = React.createElement(\n TemplateStringComponent,\n {\n value: toString(),\n },\n null\n ) as TemplateStringType;\n\n return {\n ...element,\n [OpaqueIdentifier]: true,\n toString,\n toValue,\n toRefString: (refStringOptions?: TemplateRefStringOptions) => {\n return options.toRefString(refStringOptions, value);\n },\n };\n};\n\n/** Helper for Iterating the binding to add a dynamic numeric value to each index found */\nconst addBindingIndexes = (binding: string): string => {\n let currentIndex = 0;\n\n return binding.replace(/_index_/g, () => {\n const result = `_index${currentIndex > 0 ? currentIndex : \"\"}_`;\n currentIndex += 1;\n\n return result;\n });\n};\n\n/** Creating an instance of a handler for bindings */\nconst createBindingTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n): BindingTemplateInstance => {\n const templateInstance = createTemplateInstance({\n ...options,\n strings: options.strings.map((element: string) =>\n addBindingIndexes(element)\n ),\n other: options.other.map((element) =>\n typeof element === \"string\" ? addBindingIndexes(element) : element\n ),\n toRefString: (context, value) => {\n return `{{${value}}}`;\n },\n }) as BindingTemplateInstance;\n\n templateInstance.__type = \"binding\";\n\n return templateInstance;\n};\n\n/** Creating an instance of a handler for bindings */\nconst createExpressionTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n) => {\n const templateInstance = createTemplateInstance({\n ...options,\n toRefString: (contextOptions, value) => {\n if (contextOptions?.nestedContext === \"expression\") {\n return value;\n }\n\n const inBinding = contextOptions?.nestedContext === \"binding\";\n return `${inBinding ? \"`\" : \"@[\"}${value}${inBinding ? \"`\" : \"]@\"}`;\n },\n }) as ExpressionTemplateInstance;\n\n templateInstance.__type = \"expression\";\n\n return templateInstance;\n};\n\n/** A tagged-template constructor for a binding */\nexport const binding = (\n strings: TemplateStringsArray,\n ...nested: Array<TemplateStringType | string>\n): BindingTemplateInstance => {\n return createBindingTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"binding\",\n });\n};\n\n/** A tagged-template constructor for an expression */\nexport const expression = (\n strings: TemplateStringsArray,\n ...nested: Array<\n ExpressionTemplateInstance | BindingTemplateInstance | string\n >\n): ExpressionTemplateInstance => {\n return createExpressionTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"expression\",\n });\n};\n\n/** Check if a value is a template string */\nexport const isTemplateStringInstance = (\n val: unknown\n): val is ExpressionTemplateInstance | BindingTemplateInstance => {\n return (\n val !== null &&\n typeof val === \"object\" &&\n (val as any)[OpaqueIdentifier] === true\n );\n};\n","import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport type { ArrayNode, JsonNode, ObjectNode } from \"react-json-reconciler\";\nimport { flattenNodes, PropertyNode } from \"react-json-reconciler\";\nimport { SlotContext } from \".\";\nimport { IDSuffixProvider, OptionalIDSuffixProvider } from \"./auto-id\";\nimport type {\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n} from \"./string-templates\";\nimport { isTemplateStringInstance } from \"./string-templates\";\nimport { normalizeToCollection, toJsonProperties } from \"./utils\";\n\nexport interface SwitchProps {\n /** defaults to a staticSwitch */\n isDynamic?: boolean;\n}\n\nconst SwitchContext = React.createContext<\n SwitchProps & {\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n>({});\n\n/**\n * Switches allow users to fork content between 1 or more assets\n */\nexport const Switch = (props: PropsWithChildren<SwitchProps>) => {\n const slotContext = React.useContext(SlotContext);\n const propertyNode = React.useRef<ObjectNode>(null);\n\n return (\n <obj ref={propertyNode}>\n <SwitchContext.Provider\n value={{\n ...props,\n TextComp: slotContext?.TextComp,\n CollectionComp: slotContext?.CollectionComp,\n }}\n >\n <OptionalIDSuffixProvider wrapperRef={propertyNode}>\n <property name={props.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"}>\n <SlotContext.Provider value={undefined}>\n <array>{props.children}</array>\n </SlotContext.Provider>\n </property>\n </OptionalIDSuffixProvider>\n </SwitchContext.Provider>\n {slotContext?.additionalProperties &&\n toJsonProperties(slotContext.additionalProperties)}\n </obj>\n );\n};\n\nexport interface CaseProps {\n /** the test for this case statement */\n exp?: ExpressionTemplateInstance | BindingTemplateInstance | boolean;\n}\n\n/** Find the first parent array */\nconst findParentArray = (node: JsonNode): ArrayNode => {\n if (node.type === \"array\") {\n return node;\n }\n\n if (node.parent) {\n return findParentArray(node.parent);\n }\n\n throw new Error(\"can't find parent array\");\n};\n\n/** Find the index of the item in an array */\nconst findArrayIndex = (node: JsonNode): number => {\n const parentArray = findParentArray(node);\n const allSearch = flattenNodes(parentArray.children);\n return allSearch.indexOf(node);\n};\n\n/** A case for a switch */\nconst Case = (props: PropsWithChildren<CaseProps>) => {\n const slotContext = React.useContext(SlotContext);\n const switchContext = React.useContext(SwitchContext);\n const [caseIndex, setCaseIndex] = React.useState(-1);\n const caseNode = React.useRef<ObjectNode>(null);\n\n React.useLayoutEffect(() => {\n if (caseNode.current) {\n const index = findArrayIndex(caseNode.current);\n if (index !== caseIndex) {\n setCaseIndex(index);\n }\n }\n }, [caseIndex]);\n\n let expValue: string | boolean = true;\n\n if (props.exp !== undefined) {\n expValue = isTemplateStringInstance(props.exp)\n ? props.exp.toValue()\n : props.exp;\n }\n\n return (\n <obj ref={caseNode}>\n <property name=\"case\">\n <value value={expValue} />\n </property>\n <IDSuffixProvider\n suffix={`${\n switchContext.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"\n }-${caseIndex}`}\n >\n <SlotContext.Provider\n value={\n slotContext ? { ...slotContext, wrapInAsset: false } : undefined\n }\n >\n <property name=\"asset\">\n {normalizeToCollection({\n node: props.children,\n TextComp: switchContext?.TextComp,\n CollectionComp: switchContext?.CollectionComp,\n })}\n </property>\n </SlotContext.Provider>\n </IDSuffixProvider>\n </obj>\n );\n};\n\nSwitch.Case = Case;\n","import React from \"react\";\nimport type { ObjectNode, JsonNode } from \"react-json-reconciler\";\nimport {\n ArrayNode,\n PropertyNode,\n ValueNode,\n createPortal,\n ProxyNode,\n toJSON,\n} from \"react-json-reconciler\";\nimport { OptionalIDSuffixProvider } from \"./auto-id\";\nimport type { BindingTemplateInstance } from \"./string-templates\";\nimport type { WithChildren } from \"./types\";\nimport { toJsonElement } from \"./utils\";\n\nexport interface TemplateContextType {\n /** The number of nested templates */\n depth: number;\n}\n\nexport const TemplateContext = React.createContext<TemplateContextType>({\n depth: 0,\n});\n\nexport interface TemplateProps {\n /** The source binding */\n data: BindingTemplateInstance;\n\n /** The target property */\n output?: string;\n\n /** The template value */\n children: React.ReactNode;\n\n /** boolean that specifies whether template should recompute when data changes */\n dynamic?: boolean;\n}\n\n/** Add a template instance to the object */\nfunction addTemplateToObject(\n obj: ObjectNode,\n templateObj: ObjectNode,\n templateParentNodeType: string\n): () => void {\n // find a template property\n // add one if none exists\n\n let templateProp = obj.properties.find(\n (p) => p.keyNode.value === \"template\" && p.valueNode?.type === \"array\"\n );\n\n if (!templateProp) {\n templateProp = new PropertyNode(new ValueNode(\"template\"), new ArrayNode());\n templateProp.parent = obj;\n obj.properties.push(templateProp);\n }\n\n const templateItems = templateProp.valueNode as ArrayNode;\n\n templateItems.items.push(templateObj);\n // eslint-disable-next-line no-param-reassign\n templateObj.parent = templateItems;\n\n const templateParentProp = obj.properties.find(\n (p) =>\n p.keyNode.value === templateParentNodeType &&\n p.valueNode?.type === \"array\"\n );\n\n if (templateParentProp) {\n const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);\n const templateParentValueNode =\n obj.properties[indexOfTemplateParent]?.valueNode;\n if (templateParentValueNode) {\n const templateParentArray = toJSON(templateParentValueNode);\n\n // Delete the parent of template if it is an empty array\n if (\n Array.isArray(templateParentArray) &&\n templateParentArray.length === 0\n ) {\n obj.properties.splice(indexOfTemplateParent, 1);\n }\n }\n }\n\n return () => {\n // Remove the template item from the list\n templateItems.items = templateItems.items.filter((t) => t !== templateObj);\n\n // Clean up the whole template if it's removed\n if (templateItems.children.length === 0 && templateProp) {\n obj.properties.splice(obj.properties.indexOf(templateProp, 1));\n }\n };\n}\n\n/** Context provider wrapper to handle nested templates */\nconst TemplateProvider = (props: WithChildren) => {\n const baseContext = React.useContext(TemplateContext);\n\n return (\n <TemplateContext.Provider value={{ depth: baseContext.depth + 1 }}>\n {props.children}\n </TemplateContext.Provider>\n );\n};\n\n/** Find the first object node in the tree */\nconst getParentObject = (node: JsonNode): ObjectNode | undefined => {\n if (node.type === \"object\") {\n return node;\n }\n\n if (node.parent) {\n return getParentObject(node.parent);\n }\n};\n\n/** Find the property of the node on the parent */\nconst getParentProperty = (node: JsonNode): PropertyNode | undefined => {\n if (node.type === \"property\") {\n return node;\n }\n\n if (node.parent) {\n return getParentProperty(node.parent);\n }\n};\n\n/** A template allows users to dynamically map over an array of data */\nexport const Template = (props: TemplateProps) => {\n const baseContext = React.useContext(TemplateContext);\n const dynamicProp = props.dynamic ?? false;\n const [outputProp, setOutputProp] = React.useState<string | undefined>(\n props.output\n );\n const proxyRef = React.useRef<ProxyNode>(null);\n const valueRef = React.useRef<ValueNode>(null);\n const outputElement = React.useMemo(() => new ProxyNode(), []);\n\n React.useLayoutEffect(() => {\n // Get the output prop\n const propNode = proxyRef.current && getParentProperty(proxyRef.current);\n\n if (outputProp === undefined && propNode) {\n setOutputProp(propNode.keyNode.value);\n }\n }, [proxyRef, outputProp]);\n\n React.useEffect(() => {\n const templateObj = outputElement.items[0] as ObjectNode;\n if (proxyRef.current) {\n const parentObject = getParentObject(proxyRef.current);\n\n if (!parentObject) {\n throw new Error(\"Unable to find parent to add template to\");\n }\n\n if (!outputProp) {\n return;\n }\n\n // remove the template when unmounted\n return addTemplateToObject(parentObject, templateObj, outputProp);\n }\n }, [proxyRef, outputProp, outputElement.items]);\n\n return (\n <proxy ref={proxyRef}>\n <>\n {createPortal(\n <OptionalIDSuffixProvider\n wrapperRef={valueRef}\n templateIndex={`_index${\n baseContext.depth === 0 ? \"\" : baseContext.depth\n }_`}\n >\n <TemplateProvider>\n <object>\n <property name=\"data\">{props.data.toValue()}</property>\n <property name=\"output\">{outputProp}</property>\n <property name=\"value\">{props.children}</property>\n {dynamicProp && (\n <property name=\"dynamic\">\n {toJsonElement(dynamicProp)}\n </property>\n )}\n </object>\n </TemplateProvider>\n </OptionalIDSuffixProvider>,\n outputElement\n )}\n <value ref={valueRef} value={undefined} />\n </>\n </proxy>\n );\n};\n","import type { Schema, Language } from \"@player-ui/types\";\nimport { dequal } from \"dequal\";\nimport { SyncWaterfallHook } from \"tapable-ts\";\nimport type { LoggingInterface } from \"..\";\nimport { binding as b } from \"..\";\nimport type { BindingTemplateInstance } from \"../string-templates\";\n\nconst bindingSymbol = Symbol(\"binding\");\n\n/** Symbol to indicate that a schema node should be generated with a different name */\nexport const SchemaTypeName = Symbol(\"Schema Rename\");\n\ninterface SchemaChildren {\n /** Object property that will be used to create the intermediate type */\n name: string;\n\n /** Object properties children that will be parsed */\n child: object;\n}\n\ntype SchemaNode = (Schema.DataType | Language.DataTypeRef) & {\n /** Overwrite the name of the generated type */\n [SchemaTypeName]?: string;\n};\n\ninterface GeneratedDataType {\n /** The SchemaNode that was generated */\n node: SchemaNode;\n /** How many times it has been generated */\n count: number;\n}\n\n/**\n * Type Guard for the `Schema.DataType` and `Language.DataTypeRef` type\n * A bit hacky but since `Schema.Schema` must have a `Schema.DataType` as\n * the final product we have to call it that even if it is a `Language.DataTypeRef`\n */\nconst isTypeDef = (property: SchemaNode): property is Schema.DataType => {\n return (property as Schema.DataType).type !== undefined;\n};\n\n/**\n * Generator for `Schema.Schema` Objects\n */\nexport class SchemaGenerator {\n private children: Array<SchemaChildren>;\n private generatedDataTypes: Map<string, GeneratedDataType>;\n private logger: LoggingInterface;\n\n public hooks = {\n createSchemaNode: new SyncWaterfallHook<\n [\n node: Schema.DataType,\n originalProperty: Record<string | symbol, unknown>\n ]\n >(),\n };\n\n constructor(logger?: LoggingInterface) {\n this.children = [];\n this.generatedDataTypes = new Map();\n this.logger = logger ?? console;\n }\n\n /**\n * Converts an object to a `Schema.Schema` representation\n * Note: uses iteration to prevent potentially very deep recursion on large objects\n */\n public toSchema = (schema: any): Schema.Schema => {\n const newSchema: Schema.Schema = {\n ROOT: {},\n };\n\n this.children = [];\n this.generatedDataTypes.clear();\n\n Object.keys(schema).forEach((property) => {\n const subType = schema[property] as SchemaNode;\n newSchema.ROOT[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n\n while (this.children.length > 0) {\n const c = this.children.pop();\n if (c === undefined) {\n break;\n }\n\n const { name, child } = c;\n const typeDef = {} as any;\n\n Object.keys(child).forEach((property) => {\n const subType = (child as any)[property] as SchemaNode;\n typeDef[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n newSchema[name] = typeDef;\n }\n\n return newSchema;\n };\n\n /**\n * Processes the children of an object Node\n * Newly discovered children get added to the provided array\n */\n private processChild(property: string, subType: SchemaNode): Schema.DataType {\n if (isTypeDef(subType)) {\n return subType;\n }\n\n let intermediateType;\n let child;\n\n if (Array.isArray(subType)) {\n if (subType.length > 1) {\n this.logger.warn(\n `Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`\n );\n }\n\n const subTypeName = subType[0][SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderArrayType(subTypeName);\n [child] = subType;\n } else {\n const subTypeName = subType[SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderType(subTypeName);\n child = subType;\n }\n\n this.children.push({ name: intermediateType.type, child });\n\n if (this.generatedDataTypes.has(intermediateType.type)) {\n const generatedType = this.generatedDataTypes.get(\n intermediateType.type\n ) as GeneratedDataType;\n if (\n !dequal(\n child,\n this.generatedDataTypes.get(intermediateType.type)?.node as object\n )\n ) {\n generatedType.count += 1;\n const newIntermediateType = {\n ...intermediateType,\n type: `${intermediateType.type}${generatedType.count}`,\n };\n this.logger.warn(\n `WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`\n );\n intermediateType = newIntermediateType;\n this.children.pop();\n this.children.push({ name: intermediateType.type, child });\n }\n }\n\n this.generatedDataTypes.set(intermediateType.type, {\n node: subType,\n count: 1,\n });\n return intermediateType;\n }\n\n /**\n * Make an intermediate `Schema.DataType` object given a name\n */\n private makePlaceholderType = (typeName: string): Schema.DataType => {\n return {\n type: `${typeName}Type`,\n };\n };\n\n /**\n * Make an intermediate `Schema.DataType` object with array support given a name\n */\n private makePlaceholderArrayType(typeName: string): Schema.DataType {\n return {\n type: `${typeName}Type`,\n isArray: true,\n };\n }\n}\n\nexport type MakeArrayIntoIndexRef<T extends any[]> = {\n [key: number]: MakeBindingRefable<T[0]>;\n /** Used when referencing bindings from within a template */\n _index_: MakeBindingRefable<T[0]>;\n} & BindingTemplateInstance;\n\nexport type MakeBindingRefable<T> = {\n [P in keyof T]: T[P] extends object[]\n ? MakeArrayIntoIndexRef<T[P]>\n : T[P] extends unknown[]\n ? T[P]\n : MakeBindingRefable<T[P]>;\n} & BindingTemplateInstance;\n\n/**\n * Adds bindings to an object so that the object can be directly used in JSX\n */\nexport function makeBindingsForObject<Type>(\n obj: Type,\n arrayAccessorKeys = [\"_index_\"]\n): MakeBindingRefable<Type> {\n /** Proxy to track binding callbacks */\n const accessor = (paths: string[]) => {\n const bindingMap = new WeakMap<any, BindingTemplateInstance>();\n\n return {\n ownKeys(target: any) {\n return Reflect.ownKeys(target);\n },\n\n get(target: any, key: any): any {\n const bindingKeys = Object.keys(target);\n\n // If there is an array of primitives, just return a copy of that array\n if (\n Array.isArray(target[key]) &&\n target[key].length > 0 &&\n target[key].every((it: any) => typeof it !== \"object\")\n ) {\n return [...target[key]];\n }\n\n if (!bindingMap.has(target)) {\n bindingMap.set(target, b`${paths.join(\".\")}`);\n }\n\n if (key === bindingSymbol) {\n return paths;\n }\n\n if (\n Array.isArray(target) &&\n (arrayAccessorKeys.includes(key) || typeof key === \"number\")\n ) {\n return new Proxy(target[0], accessor(paths.concat([key])));\n }\n\n if (bindingKeys.includes(key) && typeof target[key] === \"object\") {\n return new Proxy(target[key], accessor(paths.concat([key])));\n }\n\n const createdInstance = bindingMap.get(target) as any;\n return createdInstance?.[key];\n },\n };\n };\n\n return new Proxy(obj, accessor([])) as MakeBindingRefable<Type>;\n}\n\n/**\n * Generates binding for an object property\n */\nexport const getBindingFromObject = (obj: any) => {\n const baseBindings = obj[bindingSymbol] as string[];\n if (!Array.isArray(baseBindings) || baseBindings.length === 0) {\n throw new Error(`Unable to get binding for ${obj}`);\n }\n\n return b`${baseBindings.join(\".\")}`;\n};\n\n/**\n * Returns the binding string from an object path\n */\nexport const getBindingStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toString();\n};\n\n/**\n * Returns the ref string from an object path\n */\nexport const getRefStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toRefString();\n};\n","import React from \"react\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport { SourceMapGenerator, SourceMapConsumer } from \"source-map-js\";\nimport { render } from \"react-json-reconciler\";\nimport type { Flow, View, Navigation as PlayerNav } from \"@player-ui/types\";\nimport {\n AsyncSeriesHook,\n AsyncSeriesWaterfallHook,\n SyncHook,\n} from \"tapable-ts\";\nimport { fingerprintContent } from \"./utils\";\nimport type {\n LoggingInterface,\n CompilerReturn,\n SerializeContext,\n} from \"./types\";\nimport type { Navigation } from \"../types\";\nimport { SchemaGenerator } from \"./schema\";\n\n/**\n * Argument passed to the DSLCompiler onEnd hook\n * Defined as an object so additional fields can be added later without breaking API\n * */\nexport interface OnEndArg {\n /** target output directory **/\n output: string;\n}\n\n/** Recursively find BindingTemplateInstance and call toValue on them */\nconst parseNavigationExpressions = (nav: Navigation): PlayerNav => {\n /** Same as above but signature changed */\n function replaceExpWithStr(obj: any): any {\n /** call toValue if BindingTemplateInstance otherwise continue */\n function convExp(value: any): any {\n return value && typeof value === \"object\" && value.__type === \"expression\"\n ? value.toValue() // exp, onStart, and onEnd don't need to be wrapped in @[]@\n : replaceExpWithStr(value);\n }\n\n if (Array.isArray(obj)) {\n return obj.map(convExp);\n }\n\n if (typeof obj === \"object\") {\n const copy = { ...obj };\n for (const [key, value] of Object.entries(copy)) {\n copy[key] = convExp(value);\n }\n\n return copy;\n }\n\n return obj;\n }\n\n return replaceExpWithStr(nav);\n};\n\ntype SourceMapList = Array<{\n /** The mappings of the original */\n sourceMap: string;\n /**\n * The id of the view we're indexing off of\n * This should be a unique global identifier within the generated code\n * e.g. `\"id\": \"view_0\",`\n */\n offsetIndexSearch: string;\n /** The generated source that produced the map */\n source: string;\n}>;\n\n/** Given a list of source maps for all generated views, merge them into 1 */\nconst mergeSourceMaps = (\n sourceMaps: SourceMapList,\n generated: string\n): string => {\n const generator = new SourceMapGenerator();\n sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {\n const generatedLineOffset = generated\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const sourceLineOffset = source\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const lineOffset = generatedLineOffset - sourceLineOffset;\n\n const generatedLine = generated.split(\"\\n\")[generatedLineOffset];\n const sourceLine = source.split(\"\\n\")[sourceLineOffset];\n\n const generatedColumn = generatedLine.indexOf(offsetIndexSearch);\n const sourceColumn = sourceLine.indexOf(offsetIndexSearch);\n const columnOffset = generatedColumn - sourceColumn;\n\n const consumer = new SourceMapConsumer(JSON.parse(sourceMap));\n consumer.eachMapping((mapping) => {\n generator.addMapping({\n generated: {\n line: mapping.generatedLine + lineOffset,\n column: mapping.generatedColumn + columnOffset,\n },\n original: {\n line: mapping.originalLine,\n column: mapping.originalColumn,\n },\n source: mapping.source,\n });\n });\n });\n\n return generator.toString();\n};\n\n/** A compiler for transforming DSL content into JSON */\nexport class DSLCompiler {\n public readonly logger: LoggingInterface;\n public hooks = {\n // Hook to access the schema generator instance when initialized\n schemaGenerator: new SyncHook<[SchemaGenerator]>(),\n // Hook to access pre-compilation object\n preProcessFlow: new AsyncSeriesWaterfallHook<[object]>(),\n // Hook to access post-compilation Flow before output is written\n postProcessFlow: new AsyncSeriesWaterfallHook<[Flow]>(),\n // Hook called after all files are compiled. Revives the output directory\n onEnd: new AsyncSeriesHook<[OnEndArg]>(),\n };\n\n private schemaGenerator?: SchemaGenerator;\n\n constructor(logger?: LoggingInterface) {\n this.logger = logger ?? console;\n }\n\n /** Convert an object (flow, view, schema, etc) into it's JSON representation */\n async serialize(\n value: unknown,\n context?: SerializeContext\n ): Promise<CompilerReturn> {\n if (typeof value !== \"object\" || value === null) {\n throw new Error(\"Unable to serialize non-object\");\n }\n\n const type = context?.type ? context.type : fingerprintContent(value);\n\n if (!this.schemaGenerator) {\n this.schemaGenerator = new SchemaGenerator(this.logger);\n this.hooks.schemaGenerator.call(this.schemaGenerator);\n }\n\n if (type === \"view\") {\n const { jsonValue, sourceMap } = await render(value as any, {\n collectSourceMap: true,\n });\n\n return {\n value: jsonValue,\n sourceMap,\n };\n }\n\n if (type === \"flow\") {\n // Source maps from all the nested views\n // Merge these together before returning\n const allSourceMaps: SourceMapList = [];\n\n // Assume this is a flow\n const copiedValue: Flow = {\n ...(value as any),\n };\n\n copiedValue.views = (await Promise.all(\n copiedValue?.views?.map(async (node: any) => {\n if (React.isValidElement(node)) {\n const { jsonValue, sourceMap, stringValue } = await render(node, {\n collectSourceMap: true,\n });\n\n if (sourceMap) {\n // Find the line that is the id of the view\n // Use that as the identifier for the sourcemap offset calc\n const searchIdLine = stringValue\n .split(\"\\n\")\n .find((line) =>\n line.includes(\n `\"id\": \"${(jsonValue as Record<string, string>).id}\"`\n )\n );\n\n if (searchIdLine) {\n allSourceMaps.push({\n sourceMap,\n offsetIndexSearch: searchIdLine,\n source: stringValue,\n });\n }\n }\n\n return jsonValue;\n }\n\n return node;\n }) ?? []\n )) as View[];\n\n // Go through the flow and sub out any view refs that are react elements w/ the right id\n if (\"navigation\" in value) {\n Object.entries((value as Flow).navigation).forEach(([navKey, node]) => {\n if (typeof node === \"object\") {\n Object.entries(node).forEach(([nodeKey, flowNode]) => {\n if (\n flowNode &&\n typeof flowNode === \"object\" &&\n \"state_type\" in flowNode &&\n flowNode.state_type === \"VIEW\" &&\n React.isValidElement(flowNode.ref)\n ) {\n const actualViewIndex = (value as Flow).views?.indexOf?.(\n flowNode.ref as any\n );\n\n if (actualViewIndex !== undefined && actualViewIndex > -1) {\n const actualId = copiedValue.views?.[actualViewIndex]?.id;\n\n (copiedValue as any).navigation[navKey][nodeKey].ref =\n actualId;\n }\n }\n });\n }\n });\n }\n\n if (\"schema\" in copiedValue) {\n copiedValue.schema = this.schemaGenerator.toSchema(copiedValue.schema);\n }\n\n copiedValue.navigation = parseNavigationExpressions(\n copiedValue.navigation\n );\n\n if (value) {\n const postProcessFlow = await this.hooks.postProcessFlow.call(\n copiedValue\n );\n\n return {\n value: postProcessFlow as JsonType,\n sourceMap: mergeSourceMaps(\n allSourceMaps,\n JSON.stringify(copiedValue, null, 2)\n ),\n };\n }\n }\n\n // Type has been set to \"schema\"\n return {\n value: this.schemaGenerator.toSchema(value) as JsonType,\n };\n }\n}\n","import React from \"react\";\nimport type { DefaultCompilerContentType } from \"./types\";\n\n/** Basic way of identifying the type of file based on the default content export */\nexport const fingerprintContent = (\n content: unknown,\n filename?: string\n): DefaultCompilerContentType | undefined => {\n if (content !== null || content !== undefined) {\n if (React.isValidElement(content as any)) {\n return \"view\";\n }\n\n if (typeof content === \"object\" && \"navigation\" in (content as any)) {\n return \"flow\";\n }\n\n if (!filename || filename.includes(\"schema\")) {\n return \"schema\";\n }\n }\n};\n","import type {\n Schema,\n Navigation,\n Flow,\n Expression,\n ExpressionObject,\n NavigationFlow,\n NavigationFlowState,\n NavigationFlowViewState,\n} from \"@player-ui/types\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport type { RemoveUnknownIndex, AddUnknownIndex } from \"../types\";\nimport type { DSLSchema } from \"../types\";\n\nexport type NavigationFlowReactViewState = Omit<\n NavigationFlowViewState,\n \"ref\"\n> & {\n /** The view element */\n ref: React.ReactElement | string;\n};\n\nexport type NavFlowState =\n | Exclude<NavigationFlowState, NavigationFlowViewState>\n | NavigationFlowReactViewState;\n\nexport type NavigationFlowWithReactView = Pick<\n NavigationFlow,\n \"startState\" | \"onStart\" | \"onEnd\"\n> & {\n [key: string]:\n | undefined\n | string\n | Expression\n | ExpressionObject\n | NavFlowState;\n};\n\nexport type NavigationWithReactViews = Pick<Navigation, \"BEGIN\"> &\n Record<string, string | NavigationFlowWithReactView>;\n\nexport type FlowWithoutUnknown = RemoveUnknownIndex<Flow>;\nexport type FlowWithReactViews = AddUnknownIndex<\n Omit<FlowWithoutUnknown, \"views\" | \"navigation\"> & {\n /** An array of JSX view elements */\n views?: Array<React.ReactElement>;\n\n /** The navigation element */\n navigation?: NavigationWithReactViews;\n }\n>;\n\nexport type DSLFlow = Omit<FlowWithReactViews, \"schema\"> & {\n /** A DSL compliant schema */\n schema?: DSLSchema;\n};\n\nexport type SerializeType = \"view\" | \"flow\" | \"schema\" | \"navigation\";\n\nexport type SerializablePlayerExportTypes =\n | React.ReactElement\n | FlowWithReactViews\n | Schema.Schema\n | Navigation;\n\nexport type LoggingInterface = Pick<Console, \"warn\" | \"error\" | \"log\">;\n\nexport type CompilationResult = {\n /** What type of file is generated */\n contentType: string;\n /** The output path */\n outputFile: string;\n /** the input file */\n inputFile: string;\n};\n\nexport type CompilerReturn = {\n /** the JSON value of the source */\n value: JsonType | undefined;\n\n /** The sourcemap of the content */\n sourceMap?: string;\n};\n\n/** The different type of default content items the compiler handles */\nconst DefaultCompilerContentTypes = [\"view\", \"flow\", \"schema\"] as const;\n\nexport type DefaultCompilerContentType =\n (typeof DefaultCompilerContentTypes)[number];\n\n/** Helper function to determine whether a content type is compiler default */\nexport function isDefaultCompilerContentType(\n t: string\n): t is DefaultCompilerContentType {\n return DefaultCompilerContentTypes.includes(t as DefaultCompilerContentType);\n}\n\nexport interface SerializeContext {\n /** The type of the content being compiled */\n type: DefaultCompilerContentType;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAAkB;;;ACAlB,mBAAkB;AAElB,mCAA6B;AAI7B,IAAM,kBAAkB,aAAAC,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H;AAEA,UAAI,YAAY,aAAa;AAC3B,oBAAY,SAAS,KAAK,gBAAgB,SAAS,YAAY,MAAM;AAAA,MACvE;AAEA,kBAAY,aAAa;AAAA,QACvB,YAAY;AAAA,MACd;AAEA,UAAI,OAAO;AACT,cAAM,kBAAkB,MAAM,KAAK,MAAM,gBAAgB;AAAA,UACvD;AAAA,QACF;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,WAAW;AAAA,YACT;AAAA,YACA,KAAK,UAAU,aAAa,MAAM,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,OAAO,KAAK,gBAAgB,SAAS,KAAK;AAAA,IAC5C;AAAA,EACF;AACF;;;AEhLA,IAAM,8BAA8B,CAAC,QAAQ,QAAQ,QAAQ;AAMtD,SAAS,6BACd,GACiC;AACjC,SAAO,4BAA4B,SAAS,CAA+B;AAC7E;","names":["import_react","React","React","React","element","binding","React","AssetWrapper","import_react","import_react_json_reconciler","React","import_react","import_react_json_reconciler","React","import_react","import_react_json_reconciler","import_tapable_ts","import_react","React","React"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/auto-id.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/utils.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/switch.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/template.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/schema.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/compiler.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/utils.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/types.ts"],"sourcesContent":["export * from \"./components\";\nexport * from \"./auto-id\";\nexport * from \"./types\";\nexport * from \"./string-templates\";\nexport * from \"./utils\";\nexport * from \"./switch\";\nexport * from \"./template\";\nexport * from \"react-json-reconciler\";\nexport * from \"./compiler/schema\";\nexport * from \"./compiler\";\nexport * from \"./compiler/types\";\n","import React from \"react\";\nimport type { ObjectNode, PropertyNode } from \"react-json-reconciler\";\nimport type { View as ViewType } from \"@player-ui/types\";\nimport type { PlayerApplicability, WithChildren } from \"./types\";\nimport {\n IDProvider,\n IDSuffixProvider,\n IndexSuffixStopContext,\n OptionalIDSuffixProvider,\n useGetIdPrefix,\n} from \"./auto-id\";\nimport {\n normalizeText,\n normalizeToCollection,\n toJsonElement,\n toJsonProperties,\n flattenChildren,\n mergeRefs,\n} from \"./utils\";\n\nexport type AssetProps = PlayerApplicability & {\n /** id of the asset */\n id?: string;\n\n /** the asset type */\n type: string;\n\n /** Any other properties on the asset */\n children?: React.ReactNode;\n\n /** other things that we don't know about */\n [key: string]: unknown;\n};\n\nexport const SlotContext = React.createContext<\n | {\n /** The property name for the slot */\n propertyName: string;\n /** If the slot represents an array */\n isArray: boolean;\n /** If the items in the slot should be wrapped in an \"asset\" object */\n wrapInAsset: boolean;\n /** Other props to add to the slot */\n additionalProperties?: any;\n /** The ref to the property node */\n ref: React.RefObject<PropertyNode>;\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n | undefined\n>(undefined);\n\n/**\n * Wraps the children in an `asset` object.\n * Additional props are added to the top level object\n */\nexport const AssetWrapper = React.forwardRef<\n ObjectNode,\n WithChildren<{ [key: string]: unknown }>\n>(function AssetWrapper(props, ref) {\n const { children, ...rest } = props;\n\n return (\n <obj ref={ref}>\n {toJsonProperties(rest)}\n <property name=\"asset\">{children}</property>\n </obj>\n );\n});\n\n/** Create a ID property for a node */\nexport const GeneratedIDProperty = (props: {\n /** the id to use if supplied by the user */\n id?: string;\n}) => {\n const currentPrefixId = useGetIdPrefix();\n return <property name=\"id\">{props.id ?? currentPrefixId}</property>;\n};\n\n/** An asset */\nexport const Asset = React.forwardRef<ObjectNode, AssetProps>((props, ref) => {\n const { id, type, applicability, children, ...rest } = props;\n const slotContext = React.useContext(SlotContext);\n const localRef = React.useRef<ObjectNode>(null);\n const Wrapper = slotContext?.wrapInAsset ? AssetWrapper : React.Fragment;\n\n return (\n <Wrapper\n ref={slotContext?.wrapInAsset ? mergeRefs([ref, localRef]) : undefined}\n {...(slotContext?.wrapInAsset && slotContext?.additionalProperties\n ? slotContext?.additionalProperties\n : {})}\n >\n <OptionalIDSuffixProvider wrapperRef={localRef}>\n <SlotContext.Provider value={undefined}>\n <IDProvider id={id}>\n <obj\n ref={\n slotContext?.wrapInAsset\n ? undefined\n : mergeRefs([ref, localRef])\n }\n >\n <GeneratedIDProperty id={id} />\n <property name=\"type\">{type}</property>\n {applicability !== undefined && (\n <property name=\"applicability\">\n <value\n value={\n typeof applicability === \"boolean\"\n ? applicability\n : applicability.toValue()\n }\n />\n </property>\n )}\n {toJsonProperties(rest)}\n {children}\n </obj>\n </IDProvider>\n </SlotContext.Provider>\n </OptionalIDSuffixProvider>\n </Wrapper>\n );\n});\n\nAsset.displayName = \"Asset\";\n\nAsset.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\nexport const View = React.forwardRef<ObjectNode, AssetProps & ViewType>(\n (props, ref) => {\n const { validation, children, ...rest } = props;\n\n return (\n <Asset ref={ref} {...rest}>\n {validation && (\n <property key=\"validation\" name=\"validation\">\n {toJsonElement(validation, \"validation\", {\n propertiesToSkip: [\"ref\"],\n })}\n </property>\n )}\n {children}\n </Asset>\n );\n }\n);\n\nView.displayName = \"View\";\n\nView.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\n/** A component to generate a named property slot */\nexport const Slot = (props: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** Other properties to add to the slot */\n additionalProperties?: any;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) => {\n const { TextComp, CollectionComp } = props;\n const children = flattenChildren(props.children);\n const propRef = React.useRef<PropertyNode>(null);\n\n return (\n <property ref={propRef} name={props.name}>\n <IDSuffixProvider suffix={props.name}>\n <IndexSuffixStopContext.Provider value={false}>\n <SlotContext.Provider\n value={{\n ref: propRef,\n propertyName: props.name,\n wrapInAsset: props.wrapInAsset ?? false,\n isArray: props.isArray ?? false,\n additionalProperties: props.additionalProperties,\n TextComp,\n CollectionComp,\n }}\n >\n {props.isArray && (\n <array>\n {React.Children.map(children, (child, index) => {\n return (\n // eslint-disable-next-line react/no-array-index-key\n <React.Fragment key={`${props.name}-${index}`}>\n {normalizeText({ node: child, TextComp })}\n </React.Fragment>\n );\n })}\n </array>\n )}\n\n {!props.isArray &&\n normalizeToCollection({\n node: children,\n TextComp,\n CollectionComp,\n })}\n </SlotContext.Provider>\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n </property>\n );\n};\n\n/** Create a slot for a given property */\nexport function createSlot<SlotProps = unknown>(options: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) {\n // eslint-disable-next-line react/display-name\n return (\n props: {\n /** An object to include in this property */\n children?: React.ReactNode;\n } & SlotProps\n ) => {\n const { children, ...other } = props;\n return (\n <Slot {...options} additionalProperties={other}>\n {children}\n </Slot>\n );\n };\n}\n","import React from \"react\";\nimport type { JsonNode } from \"react-json-reconciler\";\nimport { flattenNodes } from \"react-json-reconciler\";\nimport { SlotContext } from \"./components\";\nimport type { WithChildren } from \"./types\";\n\nconst IDSuffixContext = React.createContext<string>(\"root\");\n\nexport const IndexSuffixStopContext = React.createContext<boolean>(false);\n\n/** Get the generated id */\nexport const useGetIdPrefix = () => {\n return React.useContext(IDSuffixContext);\n};\n\n/** Add a suffix to a generated id */\nexport const IDSuffixProvider = (\n props: WithChildren<{\n /** The suffix to append */\n suffix: string;\n }>\n) => {\n const currentPrefix = useGetIdPrefix();\n\n return (\n <IDSuffixContext.Provider\n value={[\n currentPrefix === \"root\" ? undefined : currentPrefix,\n props.suffix,\n ]\n .filter(Boolean)\n .join(\"-\")}\n >\n {props.children}\n </IDSuffixContext.Provider>\n );\n};\n\n/** Override the generated id with the supplied one */\nexport const IDProvider = (\n props: WithChildren<{\n /** The new id to use */\n id?: string;\n }>\n) => {\n if (props.id) {\n return (\n <IDSuffixContext.Provider value={props.id}>\n {props.children}\n </IDSuffixContext.Provider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n\n/** Get the index of an item in a slot */\nexport const useIndexInSlot = (ref: React.RefObject<JsonNode>) => {\n const [index, setIndex] = React.useState(-1);\n const slotContext = React.useContext(SlotContext);\n\n React.useEffect(() => {\n if (!slotContext?.isArray) {\n throw new Error(\"Cannot get index in non-array slot\");\n }\n\n if (ref.current && slotContext?.ref.current?.valueNode?.type === \"array\") {\n const allChildren = flattenNodes(\n slotContext.ref.current.valueNode.children\n );\n const foundIndex = allChildren.indexOf(ref.current);\n\n if (foundIndex !== index) {\n setIndex(foundIndex);\n }\n }\n }, [index, ref, slotContext?.isArray, slotContext?.ref]);\n\n return index;\n};\n\n/** Add the index to the id path when in an array slot */\nexport const IDSuffixIndexProvider = (\n props: WithChildren<{\n /** The ref to use */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotIndex = useIndexInSlot(props.wrapperRef);\n\n const stopIndex = React.useContext(IndexSuffixStopContext);\n\n if (stopIndex) {\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n }\n\n return (\n <IDSuffixProvider suffix={props.templateIndex ?? String(slotIndex)}>\n <IndexSuffixStopContext.Provider value>\n {props.children}\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n );\n};\n\n/** Wrap a slot with the index if in an array slot */\nexport const OptionalIDSuffixProvider = (\n props: WithChildren<{\n /** The ref to walk upwards and use as an index */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotContext = React.useContext(SlotContext);\n\n if (slotContext?.isArray) {\n return (\n <IDSuffixIndexProvider\n wrapperRef={props.wrapperRef}\n templateIndex={props.templateIndex}\n >\n {props.children}\n </IDSuffixIndexProvider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n","import * as React from \"react\";\nimport {\n isTemplateStringInstance,\n TemplateStringComponent,\n} from \"./string-templates\";\nimport type { toJsonOptions } from \"./types\";\n\n/** Get an array version of the value */\nexport function toArray<T>(val: T | Array<T>): Array<T> {\n return Array.isArray(val) ? val : [val];\n}\n\n/** Create a component version */\nexport function toJsonElement(\n value: any,\n indexOrKey?: number | string,\n options?: toJsonOptions\n): React.ReactElement {\n const indexProp = typeof indexOrKey === \"number\" ? { key: indexOrKey } : null;\n\n if (Array.isArray(value)) {\n return (\n <array {...indexProp}>\n {value.map((item, idx) => toJsonElement(item, idx, options))}\n </array>\n );\n }\n\n /** Allow users to pass in BindingTemplateInstance and ExpressionTemplateInstance directly without turning them into strings first */\n if (isTemplateStringInstance(value)) {\n if (\n typeof indexOrKey === \"string\" &&\n options?.propertiesToSkip?.includes(indexOrKey)\n ) {\n return <value {...indexProp}>{value.toValue()}</value>;\n }\n\n return <value {...indexProp}>{value.toRefString()}</value>;\n }\n\n if (typeof value === \"object\" && value !== null) {\n return (\n <obj {...indexProp}>\n {Object.keys(value).map((key) => (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n ))}\n </obj>\n );\n }\n\n return <value {...indexProp} value={value} />;\n}\n\n/** Create a fragment for the properties */\nexport function toJsonProperties(\n value: Record<string, any>,\n options: toJsonOptions = { propertiesToSkip: [\"applicability\"] }\n) {\n return Object.keys(value).map((key) => {\n return (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n );\n });\n}\n\n/** Create a text asset if needed */\nexport function normalizeText(options: {\n /** The current node */\n node: React.ReactNode;\n\n /** A component to render a text asset */\n TextComp?: React.ComponentType<any>;\n}): React.ReactNode {\n const { node, TextComp } = options;\n\n const nodeArr = React.Children.toArray(node);\n\n if (\n nodeArr.every(\n (n) => React.isValidElement(n) && n.type !== TemplateStringComponent\n )\n ) {\n return node;\n }\n\n if (TextComp) {\n return <TextComp>{nodeArr}</TextComp>;\n }\n\n throw new Error(\n `Tried to convert node to Text Asset, but no Component was supplied.`\n );\n}\n\n/** Create a collection if needed */\nexport function normalizeToCollection(options: {\n /** the node to look at */\n node: React.ReactNode;\n\n /** A Text asset */\n TextComp?: React.ComponentType;\n\n /** A collection asset */\n CollectionComp?: React.ComponentType<any>;\n}) {\n const { node, CollectionComp } = options;\n\n if (\n React.Children.count(node) > 1 &&\n React.Children.toArray(node).every((n) => typeof n !== \"string\")\n ) {\n if (!CollectionComp) {\n throw new Error(\n `Tried to convert array to a collection asset, but no Component was given.`\n );\n }\n\n return <CollectionComp>{node}</CollectionComp>;\n }\n\n return normalizeText({ ...options, node });\n}\n\ntype ReactChildArray = ReturnType<typeof React.Children.toArray>;\n\n/**\n *\n * Hoisted from https://github.com/gregberge/react-flatten-children/blob/master/src/index.tsx\n * Peer dependencies were wrong and can't be reasonably patch it everywhere\n */\nexport function flattenChildren(children: React.ReactNode): ReactChildArray {\n const childrenArray = React.Children.toArray(children);\n return childrenArray.reduce((flatChildren: ReactChildArray, child) => {\n if ((child as React.ReactElement<any>).type === React.Fragment) {\n return flatChildren.concat(\n flattenChildren((child as React.ReactElement<any>).props.children)\n );\n }\n\n flatChildren.push(child);\n\n return flatChildren;\n }, []);\n}\n/**\n * Hoisted from https://github.com/gregberge/react-merge-refs/blob/main/src/index.tsx\n * Published packages are ESM only or have bad esm distributions causing issues when\n * used in an esm environment\n */\nexport function mergeRefs<T = any>(\n refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>\n): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref != null) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n });\n };\n}\n\n/** Generates object reference properties from the provided object */\nexport function getObjectReferences<\n OriginalPropertiesObject extends Record<string, unknown>,\n ReferencesPropertyObject extends Record<string, unknown>\n>(propertiesObject: OriginalPropertiesObject): ReferencesPropertyObject {\n const result: any = {};\n\n for (const itemProp in propertiesObject) {\n if (Object.prototype.hasOwnProperty.call(propertiesObject, itemProp)) {\n const refName = `${itemProp}Ref`;\n result[refName as keyof ReferencesPropertyObject] = { type: itemProp };\n }\n }\n\n return result;\n}\n","import * as React from \"react\";\nimport { parseExpression, isErrorWithLocation } from \"@player-ui/player\";\n\nexport type TemplateInstanceRefStringContext = \"binding\" | \"expression\";\nexport interface TemplateRefStringOptions {\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n}\nexport interface TemplateInstanceRefStringOptions {\n /** The array of strings for the template */\n strings: ReadonlyArray<string>;\n /** the other data that's present in the template */\n other: Array<string | TemplateStringType>;\n\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n\n /** Convert the value to a reference nested in the given context */\n toRefString: (\n options: TemplateRefStringOptions | undefined,\n value: string\n ) => string;\n}\n\nconst OpaqueIdentifier = Symbol(\"TemplateStringType\");\n\nexport type TemplateStringType = React.ReactElement & {\n /** An identifier to show that this is a template type */\n [OpaqueIdentifier]: true;\n /** The value of the template string when in another string */\n toString: () => string;\n /** the raw value of the template string */\n toValue: () => string;\n /** the dereferenced value when used in another */\n toRefString: (options?: TemplateRefStringOptions) => string;\n};\n\nexport type BindingTemplateInstance = TemplateStringType & {\n /** An identifier for a binding instance */\n __type: \"binding\";\n};\n\nexport type ExpressionTemplateInstance = TemplateStringType & {\n /** The identifier for an expression instance */\n __type: \"expression\";\n};\n\n/** A react component for rendering a template string type */\nexport const TemplateStringComponent = (props: {\n /** The string value of the child template string */\n value: string;\n}) => {\n return React.createElement(\n \"value\",\n {\n value: props.value,\n },\n null\n );\n};\n\n/** The generic template string handler */\nconst createTemplateInstance = (\n options: TemplateInstanceRefStringOptions\n): TemplateStringType => {\n const value = options.strings.reduce((sum, next, i) => {\n const element = options.other[i];\n if (typeof element === \"string\") {\n return sum + next + element;\n }\n\n return sum + next + (element?.toRefString(options) ?? \"\");\n }, \"\");\n\n /** Try to parse the expression as valid */\n if (options.nestedContext === \"expression\") {\n try {\n parseExpression(value);\n } catch (e) {\n if (e instanceof Error) {\n let message: string;\n if (isErrorWithLocation(e)) {\n message = `${e} in expression: \\r\\n ${\n value.slice(0, e.index + 1) + \"\\u2588\" + value.slice(e.index + 1)\n }`;\n } else {\n message = `${e} in expression ${value}`;\n }\n throw new Error(message);\n }\n\n throw new Error(`Unknown problem parsing expression ${e}`);\n }\n }\n\n /** get the unwrapped version */\n const toString = () => {\n return options.toRefString({}, value);\n };\n\n /** get the raw value of the template */\n const toValue = () => {\n return value;\n };\n\n /** This lets us use it directly as a child element in React */\n const element = React.createElement(\n TemplateStringComponent,\n {\n value: toString(),\n },\n null\n ) as TemplateStringType;\n\n return {\n ...element,\n [OpaqueIdentifier]: true,\n toString,\n toValue,\n toRefString: (refStringOptions?: TemplateRefStringOptions) => {\n return options.toRefString(refStringOptions, value);\n },\n };\n};\n\n/** Helper for Iterating the binding to add a dynamic numeric value to each index found */\nconst addBindingIndexes = (binding: string): string => {\n let currentIndex = 0;\n\n return binding.replace(/_index_/g, () => {\n const result = `_index${currentIndex > 0 ? currentIndex : \"\"}_`;\n currentIndex += 1;\n\n return result;\n });\n};\n\n/** Creating an instance of a handler for bindings */\nconst createBindingTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n): BindingTemplateInstance => {\n const templateInstance = createTemplateInstance({\n ...options,\n strings: options.strings.map((element: string) =>\n addBindingIndexes(element)\n ),\n other: options.other.map((element) =>\n typeof element === \"string\" ? addBindingIndexes(element) : element\n ),\n toRefString: (context, value) => {\n return `{{${value}}}`;\n },\n }) as BindingTemplateInstance;\n\n templateInstance.__type = \"binding\";\n\n return templateInstance;\n};\n\n/** Creating an instance of a handler for bindings */\nconst createExpressionTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n) => {\n const templateInstance = createTemplateInstance({\n ...options,\n toRefString: (contextOptions, value) => {\n if (contextOptions?.nestedContext === \"expression\") {\n return value;\n }\n\n const inBinding = contextOptions?.nestedContext === \"binding\";\n return `${inBinding ? \"`\" : \"@[\"}${value}${inBinding ? \"`\" : \"]@\"}`;\n },\n }) as ExpressionTemplateInstance;\n\n templateInstance.__type = \"expression\";\n\n return templateInstance;\n};\n\n/** A tagged-template constructor for a binding */\nexport const binding = (\n strings: TemplateStringsArray,\n ...nested: Array<TemplateStringType | string>\n): BindingTemplateInstance => {\n return createBindingTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"binding\",\n });\n};\n\n/** A tagged-template constructor for an expression */\nexport const expression = (\n strings: TemplateStringsArray,\n ...nested: Array<\n ExpressionTemplateInstance | BindingTemplateInstance | string\n >\n): ExpressionTemplateInstance => {\n return createExpressionTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"expression\",\n });\n};\n\n/** Check if a value is a template string */\nexport const isTemplateStringInstance = (\n val: unknown\n): val is ExpressionTemplateInstance | BindingTemplateInstance => {\n return (\n val !== null &&\n typeof val === \"object\" &&\n (val as any)[OpaqueIdentifier] === true\n );\n};\n","import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport type { ArrayNode, JsonNode, ObjectNode } from \"react-json-reconciler\";\nimport { flattenNodes, PropertyNode } from \"react-json-reconciler\";\nimport { SlotContext } from \".\";\nimport { IDSuffixProvider, OptionalIDSuffixProvider } from \"./auto-id\";\nimport type {\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n} from \"./string-templates\";\nimport { isTemplateStringInstance } from \"./string-templates\";\nimport { normalizeToCollection, toJsonProperties } from \"./utils\";\n\nexport interface SwitchProps {\n /** defaults to a staticSwitch */\n isDynamic?: boolean;\n}\n\nconst SwitchContext = React.createContext<\n SwitchProps & {\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n>({});\n\n/**\n * Switches allow users to fork content between 1 or more assets\n */\nexport const Switch = (props: PropsWithChildren<SwitchProps>) => {\n const slotContext = React.useContext(SlotContext);\n const propertyNode = React.useRef<ObjectNode>(null);\n\n return (\n <obj ref={propertyNode}>\n <SwitchContext.Provider\n value={{\n ...props,\n TextComp: slotContext?.TextComp,\n CollectionComp: slotContext?.CollectionComp,\n }}\n >\n <OptionalIDSuffixProvider wrapperRef={propertyNode}>\n <property name={props.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"}>\n <SlotContext.Provider value={undefined}>\n <array>{props.children}</array>\n </SlotContext.Provider>\n </property>\n </OptionalIDSuffixProvider>\n </SwitchContext.Provider>\n {slotContext?.additionalProperties &&\n toJsonProperties(slotContext.additionalProperties)}\n </obj>\n );\n};\n\nexport interface CaseProps {\n /** the test for this case statement */\n exp?: ExpressionTemplateInstance | BindingTemplateInstance | boolean;\n}\n\n/** Find the first parent array */\nconst findParentArray = (node: JsonNode): ArrayNode => {\n if (node.type === \"array\") {\n return node;\n }\n\n if (node.parent) {\n return findParentArray(node.parent);\n }\n\n throw new Error(\"can't find parent array\");\n};\n\n/** Find the index of the item in an array */\nconst findArrayIndex = (node: JsonNode): number => {\n const parentArray = findParentArray(node);\n const allSearch = flattenNodes(parentArray.children);\n return allSearch.indexOf(node);\n};\n\n/** A case for a switch */\nconst Case = (props: PropsWithChildren<CaseProps>) => {\n const slotContext = React.useContext(SlotContext);\n const switchContext = React.useContext(SwitchContext);\n const [caseIndex, setCaseIndex] = React.useState(-1);\n const caseNode = React.useRef<ObjectNode>(null);\n\n React.useLayoutEffect(() => {\n if (caseNode.current) {\n const index = findArrayIndex(caseNode.current);\n if (index !== caseIndex) {\n setCaseIndex(index);\n }\n }\n }, [caseIndex]);\n\n let expValue: string | boolean = true;\n\n if (props.exp !== undefined) {\n expValue = isTemplateStringInstance(props.exp)\n ? props.exp.toValue()\n : props.exp;\n }\n\n return (\n <obj ref={caseNode}>\n <property name=\"case\">\n <value value={expValue} />\n </property>\n <IDSuffixProvider\n suffix={`${\n switchContext.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"\n }-${caseIndex}`}\n >\n <SlotContext.Provider\n value={\n slotContext ? { ...slotContext, wrapInAsset: false } : undefined\n }\n >\n <property name=\"asset\">\n {normalizeToCollection({\n node: props.children,\n TextComp: switchContext?.TextComp,\n CollectionComp: switchContext?.CollectionComp,\n })}\n </property>\n </SlotContext.Provider>\n </IDSuffixProvider>\n </obj>\n );\n};\n\nSwitch.Case = Case;\n","import React from \"react\";\nimport type { ObjectNode, JsonNode } from \"react-json-reconciler\";\nimport {\n ArrayNode,\n PropertyNode,\n ValueNode,\n createPortal,\n ProxyNode,\n toJSON,\n} from \"react-json-reconciler\";\nimport { OptionalIDSuffixProvider } from \"./auto-id\";\nimport type { BindingTemplateInstance } from \"./string-templates\";\nimport type { WithChildren } from \"./types\";\nimport { toJsonElement } from \"./utils\";\n\nexport interface TemplateContextType {\n /** The number of nested templates */\n depth: number;\n}\n\nexport const TemplateContext = React.createContext<TemplateContextType>({\n depth: 0,\n});\n\nexport interface TemplateProps {\n /** The source binding */\n data: BindingTemplateInstance;\n\n /** The target property */\n output?: string;\n\n /** The template value */\n children: React.ReactNode;\n\n /** boolean that specifies whether template should recompute when data changes */\n dynamic?: boolean;\n}\n\n/** Add a template instance to the object */\nfunction addTemplateToObject(\n obj: ObjectNode,\n templateObj: ObjectNode,\n templateParentNodeType: string\n): () => void {\n // find a template property\n // add one if none exists\n\n let templateProp = obj.properties.find(\n (p) => p.keyNode.value === \"template\" && p.valueNode?.type === \"array\"\n );\n\n if (!templateProp) {\n templateProp = new PropertyNode(new ValueNode(\"template\"), new ArrayNode());\n templateProp.parent = obj;\n obj.properties.push(templateProp);\n }\n\n const templateItems = templateProp.valueNode as ArrayNode;\n\n templateItems.items.push(templateObj);\n // eslint-disable-next-line no-param-reassign\n templateObj.parent = templateItems;\n\n const templateParentProp = obj.properties.find(\n (p) =>\n p.keyNode.value === templateParentNodeType &&\n p.valueNode?.type === \"array\"\n );\n\n if (templateParentProp) {\n const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);\n const templateParentValueNode =\n obj.properties[indexOfTemplateParent]?.valueNode;\n if (templateParentValueNode) {\n const templateParentArray = toJSON(templateParentValueNode);\n\n // Delete the parent of template if it is an empty array\n if (\n Array.isArray(templateParentArray) &&\n templateParentArray.length === 0\n ) {\n obj.properties.splice(indexOfTemplateParent, 1);\n }\n }\n }\n\n return () => {\n // Remove the template item from the list\n templateItems.items = templateItems.items.filter((t) => t !== templateObj);\n\n // Clean up the whole template if it's removed\n if (templateItems.children.length === 0 && templateProp) {\n obj.properties.splice(obj.properties.indexOf(templateProp, 1));\n }\n };\n}\n\n/** Context provider wrapper to handle nested templates */\nconst TemplateProvider = (props: WithChildren) => {\n const baseContext = React.useContext(TemplateContext);\n\n return (\n <TemplateContext.Provider value={{ depth: baseContext.depth + 1 }}>\n {props.children}\n </TemplateContext.Provider>\n );\n};\n\n/** Find the first object node in the tree */\nconst getParentObject = (node: JsonNode): ObjectNode | undefined => {\n if (node.type === \"object\") {\n return node;\n }\n\n if (node.parent) {\n return getParentObject(node.parent);\n }\n};\n\n/** Find the property of the node on the parent */\nconst getParentProperty = (node: JsonNode): PropertyNode | undefined => {\n if (node.type === \"property\") {\n return node;\n }\n\n if (node.parent) {\n return getParentProperty(node.parent);\n }\n};\n\n/** A template allows users to dynamically map over an array of data */\nexport const Template = (props: TemplateProps) => {\n const baseContext = React.useContext(TemplateContext);\n const dynamicProp = props.dynamic ?? false;\n const [outputProp, setOutputProp] = React.useState<string | undefined>(\n props.output\n );\n const proxyRef = React.useRef<ProxyNode>(null);\n const valueRef = React.useRef<ValueNode>(null);\n const outputElement = React.useMemo(() => new ProxyNode(), []);\n\n React.useLayoutEffect(() => {\n // Get the output prop\n const propNode = proxyRef.current && getParentProperty(proxyRef.current);\n\n if (outputProp === undefined && propNode) {\n setOutputProp(propNode.keyNode.value);\n }\n }, [proxyRef, outputProp]);\n\n React.useEffect(() => {\n const templateObj = outputElement.items[0] as ObjectNode;\n if (proxyRef.current) {\n const parentObject = getParentObject(proxyRef.current);\n\n if (!parentObject) {\n throw new Error(\"Unable to find parent to add template to\");\n }\n\n if (!outputProp) {\n return;\n }\n\n // remove the template when unmounted\n return addTemplateToObject(parentObject, templateObj, outputProp);\n }\n }, [proxyRef, outputProp, outputElement.items]);\n\n return (\n <proxy ref={proxyRef}>\n <>\n {createPortal(\n <OptionalIDSuffixProvider\n wrapperRef={valueRef}\n templateIndex={`_index${\n baseContext.depth === 0 ? \"\" : baseContext.depth\n }_`}\n >\n <TemplateProvider>\n <object>\n <property name=\"data\">{props.data.toValue()}</property>\n <property name=\"output\">{outputProp}</property>\n <property name=\"value\">{props.children}</property>\n {dynamicProp && (\n <property name=\"dynamic\">\n {toJsonElement(dynamicProp)}\n </property>\n )}\n </object>\n </TemplateProvider>\n </OptionalIDSuffixProvider>,\n outputElement\n )}\n <value ref={valueRef} value={undefined} />\n </>\n </proxy>\n );\n};\n","import type { Schema, Language } from \"@player-ui/types\";\nimport { dequal } from \"dequal\";\nimport { SyncWaterfallHook } from \"tapable-ts\";\nimport type { LoggingInterface } from \"..\";\nimport { binding as b } from \"..\";\nimport type { BindingTemplateInstance } from \"../string-templates\";\n\nconst bindingSymbol = Symbol(\"binding\");\n\n/** Symbol to indicate that a schema node should be generated with a different name */\nexport const SchemaTypeName = Symbol(\"Schema Rename\");\n\ninterface SchemaChildren {\n /** Object property that will be used to create the intermediate type */\n name: string;\n\n /** Object properties children that will be parsed */\n child: object;\n}\n\ntype SchemaNode = (Schema.DataType | Language.DataTypeRef) & {\n /** Overwrite the name of the generated type */\n [SchemaTypeName]?: string;\n};\n\ninterface GeneratedDataType {\n /** The SchemaNode that was generated */\n node: SchemaNode;\n /** How many times it has been generated */\n count: number;\n}\n\n/**\n * Type Guard for the `Schema.DataType` and `Language.DataTypeRef` type\n * A bit hacky but since `Schema.Schema` must have a `Schema.DataType` as\n * the final product we have to call it that even if it is a `Language.DataTypeRef`\n */\nconst isTypeDef = (property: SchemaNode): property is Schema.DataType => {\n return (property as Schema.DataType).type !== undefined;\n};\n\n/**\n * Generator for `Schema.Schema` Objects\n */\nexport class SchemaGenerator {\n private children: Array<SchemaChildren>;\n private generatedDataTypes: Map<string, GeneratedDataType>;\n private logger: LoggingInterface;\n\n public hooks = {\n createSchemaNode: new SyncWaterfallHook<\n [\n node: Schema.DataType,\n originalProperty: Record<string | symbol, unknown>\n ]\n >(),\n };\n\n constructor(logger?: LoggingInterface) {\n this.children = [];\n this.generatedDataTypes = new Map();\n this.logger = logger ?? console;\n }\n\n /**\n * Converts an object to a `Schema.Schema` representation\n * Note: uses iteration to prevent potentially very deep recursion on large objects\n */\n public toSchema = (schema: any): Schema.Schema => {\n const newSchema: Schema.Schema = {\n ROOT: {},\n };\n\n this.children = [];\n this.generatedDataTypes.clear();\n\n Object.keys(schema).forEach((property) => {\n const subType = schema[property] as SchemaNode;\n newSchema.ROOT[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n\n while (this.children.length > 0) {\n const c = this.children.pop();\n if (c === undefined) {\n break;\n }\n\n const { name, child } = c;\n const typeDef = {} as any;\n\n Object.keys(child).forEach((property) => {\n const subType = (child as any)[property] as SchemaNode;\n typeDef[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n newSchema[name] = typeDef;\n }\n\n return newSchema;\n };\n\n /**\n * Processes the children of an object Node\n * Newly discovered children get added to the provided array\n */\n private processChild(property: string, subType: SchemaNode): Schema.DataType {\n if (isTypeDef(subType)) {\n return subType;\n }\n\n let intermediateType;\n let child;\n\n if (Array.isArray(subType)) {\n if (subType.length > 1) {\n this.logger.warn(\n `Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`\n );\n }\n\n const subTypeName = subType[0][SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderArrayType(subTypeName);\n [child] = subType;\n } else {\n const subTypeName = subType[SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderType(subTypeName);\n child = subType;\n }\n\n this.children.push({ name: intermediateType.type, child });\n\n if (this.generatedDataTypes.has(intermediateType.type)) {\n const generatedType = this.generatedDataTypes.get(\n intermediateType.type\n ) as GeneratedDataType;\n if (\n !dequal(\n child,\n this.generatedDataTypes.get(intermediateType.type)?.node as object\n )\n ) {\n generatedType.count += 1;\n const newIntermediateType = {\n ...intermediateType,\n type: `${intermediateType.type}${generatedType.count}`,\n };\n this.logger.warn(\n `WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`\n );\n intermediateType = newIntermediateType;\n this.children.pop();\n this.children.push({ name: intermediateType.type, child });\n }\n }\n\n this.generatedDataTypes.set(intermediateType.type, {\n node: subType,\n count: 1,\n });\n return intermediateType;\n }\n\n /**\n * Make an intermediate `Schema.DataType` object given a name\n */\n private makePlaceholderType = (typeName: string): Schema.DataType => {\n return {\n type: `${typeName}Type`,\n };\n };\n\n /**\n * Make an intermediate `Schema.DataType` object with array support given a name\n */\n private makePlaceholderArrayType(typeName: string): Schema.DataType {\n return {\n type: `${typeName}Type`,\n isArray: true,\n };\n }\n}\n\nexport type MakeArrayIntoIndexRef<T extends any[]> = {\n [key: number]: MakeBindingRefable<T[0]>;\n /** Used when referencing bindings from within a template */\n _index_: MakeBindingRefable<T[0]>;\n} & BindingTemplateInstance;\n\nexport type MakeBindingRefable<T> = {\n [P in keyof T]: T[P] extends object[]\n ? MakeArrayIntoIndexRef<T[P]>\n : T[P] extends unknown[]\n ? T[P]\n : MakeBindingRefable<T[P]>;\n} & BindingTemplateInstance;\n\n/**\n * Adds bindings to an object so that the object can be directly used in JSX\n */\nexport function makeBindingsForObject<Type>(\n obj: Type,\n arrayAccessorKeys = [\"_index_\"]\n): MakeBindingRefable<Type> {\n /** Proxy to track binding callbacks */\n const accessor = (paths: string[]) => {\n const bindingMap = new WeakMap<any, BindingTemplateInstance>();\n\n return {\n ownKeys(target: any) {\n return Reflect.ownKeys(target);\n },\n\n get(target: any, key: any): any {\n const bindingKeys = Object.keys(target);\n\n // If there is an array of primitives, just return a copy of that array\n if (\n Array.isArray(target[key]) &&\n target[key].length > 0 &&\n target[key].every((it: any) => typeof it !== \"object\")\n ) {\n return [...target[key]];\n }\n\n if (!bindingMap.has(target)) {\n bindingMap.set(target, b`${paths.join(\".\")}`);\n }\n\n if (key === bindingSymbol) {\n return paths;\n }\n\n if (\n Array.isArray(target) &&\n (arrayAccessorKeys.includes(key) || typeof key === \"number\")\n ) {\n return new Proxy(target[0], accessor(paths.concat([key])));\n }\n\n if (bindingKeys.includes(key) && typeof target[key] === \"object\") {\n return new Proxy(target[key], accessor(paths.concat([key])));\n }\n\n const createdInstance = bindingMap.get(target) as any;\n return createdInstance?.[key];\n },\n };\n };\n\n return new Proxy(obj, accessor([])) as MakeBindingRefable<Type>;\n}\n\n/**\n * Generates binding for an object property\n */\nexport const getBindingFromObject = (obj: any) => {\n const baseBindings = obj[bindingSymbol] as string[];\n if (!Array.isArray(baseBindings) || baseBindings.length === 0) {\n throw new Error(`Unable to get binding for ${obj}`);\n }\n\n return b`${baseBindings.join(\".\")}`;\n};\n\n/**\n * Returns the binding string from an object path\n */\nexport const getBindingStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toString();\n};\n\n/**\n * Returns the ref string from an object path\n */\nexport const getRefStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toRefString();\n};\n","import React from \"react\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport { SourceMapGenerator, SourceMapConsumer } from \"source-map-js\";\nimport { render } from \"react-json-reconciler\";\nimport type { Flow, View, Navigation as PlayerNav } from \"@player-ui/types\";\nimport {\n AsyncSeriesHook,\n AsyncSeriesWaterfallHook,\n SyncHook,\n} from \"tapable-ts\";\nimport { fingerprintContent } from \"./utils\";\nimport type {\n LoggingInterface,\n CompilerReturn,\n SerializeContext,\n} from \"./types\";\nimport type { Navigation } from \"../types\";\nimport { SchemaGenerator } from \"./schema\";\n\n/**\n * Argument passed to the DSLCompiler onEnd hook\n * Defined as an object so additional fields can be added later without breaking API\n * */\nexport interface OnEndArg {\n /** target output directory **/\n output: string;\n}\n\n/** Recursively find BindingTemplateInstance and call toValue on them */\nconst parseNavigationExpressions = (nav: Navigation): PlayerNav => {\n /** Same as above but signature changed */\n function replaceExpWithStr(obj: any): any {\n /** call toValue if BindingTemplateInstance otherwise continue */\n function convExp(value: any): any {\n return value && typeof value === \"object\" && value.__type === \"expression\"\n ? value.toValue() // exp, onStart, and onEnd don't need to be wrapped in @[]@\n : replaceExpWithStr(value);\n }\n\n if (Array.isArray(obj)) {\n return obj.map(convExp);\n }\n\n if (typeof obj === \"object\") {\n const copy = { ...obj };\n for (const [key, value] of Object.entries(copy)) {\n copy[key] = convExp(value);\n }\n\n return copy;\n }\n\n return obj;\n }\n\n return replaceExpWithStr(nav);\n};\n\ntype SourceMapList = Array<{\n /** The mappings of the original */\n sourceMap: string;\n /**\n * The id of the view we're indexing off of\n * This should be a unique global identifier within the generated code\n * e.g. `\"id\": \"view_0\",`\n */\n offsetIndexSearch: string;\n /** The generated source that produced the map */\n source: string;\n}>;\n\n/** Given a list of source maps for all generated views, merge them into 1 */\nconst mergeSourceMaps = (\n sourceMaps: SourceMapList,\n generated: string\n): string => {\n const generator = new SourceMapGenerator();\n sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {\n const generatedLineOffset = generated\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const sourceLineOffset = source\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const lineOffset = generatedLineOffset - sourceLineOffset;\n\n const generatedLine = generated.split(\"\\n\")[generatedLineOffset];\n const sourceLine = source.split(\"\\n\")[sourceLineOffset];\n\n const generatedColumn = generatedLine.indexOf(offsetIndexSearch);\n const sourceColumn = sourceLine.indexOf(offsetIndexSearch);\n const columnOffset = generatedColumn - sourceColumn;\n\n const consumer = new SourceMapConsumer(JSON.parse(sourceMap));\n consumer.eachMapping((mapping) => {\n generator.addMapping({\n generated: {\n line: mapping.generatedLine + lineOffset,\n column: mapping.generatedColumn + columnOffset,\n },\n original: {\n line: mapping.originalLine,\n column: mapping.originalColumn,\n },\n source: mapping.source,\n });\n });\n });\n\n return generator.toString();\n};\n\n/** A compiler for transforming DSL content into JSON */\nexport class DSLCompiler {\n public readonly logger: LoggingInterface;\n public hooks = {\n // Hook to access the schema generator instance when initialized\n schemaGenerator: new SyncHook<[SchemaGenerator]>(),\n // Hook to access pre-compilation object\n preProcessFlow: new AsyncSeriesWaterfallHook<[object]>(),\n // Hook to access post-compilation Flow before output is written\n postProcessFlow: new AsyncSeriesWaterfallHook<[Flow]>(),\n // Hook called after all files are compiled. Revives the output directory\n onEnd: new AsyncSeriesHook<[OnEndArg]>(),\n };\n\n private schemaGenerator?: SchemaGenerator;\n\n constructor(logger?: LoggingInterface) {\n this.logger = logger ?? console;\n }\n\n /** Convert an object (flow, view, schema, etc) into it's JSON representation */\n async serialize(\n value: unknown,\n context?: SerializeContext\n ): Promise<CompilerReturn> {\n if (typeof value !== \"object\" || value === null) {\n throw new Error(\"Unable to serialize non-object\");\n }\n\n const type = context?.type ? context.type : fingerprintContent(value);\n\n if (!this.schemaGenerator) {\n this.schemaGenerator = new SchemaGenerator(this.logger);\n this.hooks.schemaGenerator.call(this.schemaGenerator);\n }\n\n if (type === \"view\") {\n const { jsonValue, sourceMap } = await render(value as any, {\n collectSourceMap: true,\n });\n\n return {\n value: jsonValue,\n sourceMap,\n };\n }\n\n if (type === \"flow\") {\n // Source maps from all the nested views\n // Merge these together before returning\n const allSourceMaps: SourceMapList = [];\n\n // Assume this is a flow\n const copiedValue: Flow = {\n ...(value as any),\n };\n\n copiedValue.views = (await Promise.all(\n copiedValue?.views?.map(async (node: any) => {\n if (React.isValidElement(node)) {\n const { jsonValue, sourceMap, stringValue } = await render(node, {\n collectSourceMap: true,\n });\n\n if (sourceMap) {\n // Find the line that is the id of the view\n // Use that as the identifier for the sourcemap offset calc\n const searchIdLine = stringValue\n .split(\"\\n\")\n .find((line) =>\n line.includes(\n `\"id\": \"${(jsonValue as Record<string, string>).id}\"`\n )\n );\n\n if (searchIdLine) {\n allSourceMaps.push({\n sourceMap,\n offsetIndexSearch: searchIdLine,\n source: stringValue,\n });\n }\n }\n\n return jsonValue;\n }\n\n return node;\n }) ?? []\n )) as View[];\n\n // Go through the flow and sub out any view refs that are react elements w/ the right id\n if (\"navigation\" in value) {\n Object.entries((value as Flow).navigation).forEach(([navKey, node]) => {\n if (typeof node === \"object\") {\n Object.entries(node).forEach(([nodeKey, flowNode]) => {\n if (\n flowNode &&\n typeof flowNode === \"object\" &&\n \"state_type\" in flowNode &&\n flowNode.state_type === \"VIEW\" &&\n React.isValidElement(flowNode.ref)\n ) {\n const actualViewIndex = (value as Flow).views?.indexOf?.(\n flowNode.ref as any\n );\n\n if (actualViewIndex !== undefined && actualViewIndex > -1) {\n const actualId = copiedValue.views?.[actualViewIndex]?.id;\n\n (copiedValue as any).navigation[navKey][nodeKey].ref =\n actualId;\n }\n }\n });\n }\n });\n }\n\n if (\"schema\" in copiedValue) {\n copiedValue.schema = this.schemaGenerator.toSchema(copiedValue.schema);\n }\n\n copiedValue.navigation = parseNavigationExpressions(\n copiedValue.navigation\n );\n\n if (value) {\n const postProcessFlow = await this.hooks.postProcessFlow.call(\n copiedValue\n );\n\n return {\n value: postProcessFlow as JsonType,\n sourceMap: mergeSourceMaps(\n allSourceMaps,\n JSON.stringify(copiedValue, null, 2)\n ),\n };\n }\n }\n\n // Type has been set to \"schema\"\n return {\n value: this.schemaGenerator.toSchema(value) as JsonType,\n };\n }\n}\n","import React from \"react\";\nimport type { DefaultCompilerContentType } from \"./types\";\n\n/** Basic way of identifying the type of file based on the default content export */\nexport const fingerprintContent = (\n content: unknown,\n filename?: string\n): DefaultCompilerContentType | undefined => {\n if (content !== null || content !== undefined) {\n if (React.isValidElement(content as any)) {\n return \"view\";\n }\n\n if (typeof content === \"object\" && \"navigation\" in (content as any)) {\n return \"flow\";\n }\n\n if (!filename || filename.includes(\"schema\")) {\n return \"schema\";\n }\n }\n};\n","import type {\n Schema,\n Navigation,\n Flow,\n Expression,\n ExpressionObject,\n NavigationFlow,\n NavigationFlowState,\n NavigationFlowViewState,\n} from \"@player-ui/types\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport type { RemoveUnknownIndex, AddUnknownIndex } from \"../types\";\nimport type { DSLSchema } from \"../types\";\n\nexport type NavigationFlowReactViewState = Omit<\n NavigationFlowViewState,\n \"ref\"\n> & {\n /** The view element */\n ref: React.ReactElement | string;\n};\n\nexport type NavFlowState =\n | Exclude<NavigationFlowState, NavigationFlowViewState>\n | NavigationFlowReactViewState;\n\nexport type NavigationFlowWithReactView = Pick<\n NavigationFlow,\n \"startState\" | \"onStart\" | \"onEnd\"\n> & {\n [key: string]:\n | undefined\n | string\n | Expression\n | ExpressionObject\n | NavFlowState;\n};\n\nexport type NavigationWithReactViews = Pick<Navigation, \"BEGIN\"> &\n Record<string, string | NavigationFlowWithReactView>;\n\nexport type FlowWithoutUnknown = RemoveUnknownIndex<Flow>;\nexport type FlowWithReactViews = AddUnknownIndex<\n Omit<FlowWithoutUnknown, \"views\" | \"navigation\"> & {\n /** An array of JSX view elements */\n views?: Array<React.ReactElement>;\n\n /** The navigation element */\n navigation?: NavigationWithReactViews;\n }\n>;\n\nexport type DSLFlow = Omit<FlowWithReactViews, \"schema\"> & {\n /** A DSL compliant schema */\n schema?: DSLSchema;\n};\n\nexport type SerializeType = \"view\" | \"flow\" | \"schema\" | \"navigation\";\n\nexport type SerializablePlayerExportTypes =\n | React.ReactElement\n | FlowWithReactViews\n | Schema.Schema\n | Navigation;\n\nexport type LoggingInterface = Pick<Console, \"warn\" | \"error\" | \"log\">;\n\nexport type CompilationResult = {\n /** What type of file is generated */\n contentType: string;\n /** The output path */\n outputFile: string;\n /** the input file */\n inputFile: string;\n};\n\nexport type CompilerReturn = {\n /** the JSON value of the source */\n value: JsonType | undefined;\n\n /** The sourcemap of the content */\n sourceMap?: string;\n};\n\n/** The different type of default content items the compiler handles */\nconst DefaultCompilerContentTypes = [\"view\", \"flow\", \"schema\"] as const;\n\nexport type DefaultCompilerContentType =\n (typeof DefaultCompilerContentTypes)[number];\n\n/** Helper function to determine whether a content type is compiler default */\nexport function isDefaultCompilerContentType(\n t: string\n): t is DefaultCompilerContentType {\n return DefaultCompilerContentTypes.includes(t as DefaultCompilerContentType);\n}\n\nexport interface SerializeContext {\n /** The type of the content being compiled */\n type: DefaultCompilerContentType;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AA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,CAAC,CAAC,QAAQ,IAAI,MAAM;AACrE,cAAI,OAAO,SAAS,UAAU;AAC5B,mBAAO,QAAQ,IAAI,EAAE,QAAQ,CAAC,CAAC,SAAS,QAAQ,MAAM;AACpD,kBACE,YACA,OAAO,aAAa,YACpB,gBAAgB,YAChB,SAAS,eAAe,UACxB,cAAAA,QAAM,eAAe,SAAS,GAAG,GACjC;AACA,sBAAM,kBAAmB,MAAe,OAAO;AAAA,kBAC7C,SAAS;AAAA,gBACX;AAEA,oBAAI,oBAAoB,UAAa,kBAAkB,IAAI;AACzD,wBAAM,WAAW,YAAY,QAAQ,eAAe,GAAG;AAEvD,kBAAC,YAAoB,WAAW,MAAM,EAAE,OAAO,EAAE,MAC/C;AAAA,gBACJ;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAEA,UAAI,YAAY,aAAa;AAC3B,oBAAY,SAAS,KAAK,gBAAgB,SAAS,YAAY,MAAM;AAAA,MACvE;AAEA,kBAAY,aAAa;AAAA,QACvB,YAAY;AAAA,MACd;AAEA,UAAI,OAAO;AACT,cAAM,kBAAkB,MAAM,KAAK,MAAM,gBAAgB;AAAA,UACvD;AAAA,QACF;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,WAAW;AAAA,YACT;AAAA,YACA,KAAK,UAAU,aAAa,MAAM,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,OAAO,KAAK,gBAAgB,SAAS,KAAK;AAAA,IAC5C;AAAA,EACF;AACF;;;AEhLA,IAAM,8BAA8B,CAAC,QAAQ,QAAQ,QAAQ;AAMtD,SAAS,6BACd,GACiC;AACjC,SAAO,4BAA4B,SAAS,CAA+B;AAC7E;","names":["import_react","React","React","React","element","binding","React","AssetWrapper","import_react","import_react_json_reconciler","React","import_react","import_react_json_reconciler","React","import_react","import_react_json_reconciler","import_tapable_ts","import_react","React","React"]}
@@ -75,7 +75,7 @@ import * as React3 from "react";
75
75
 
76
76
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts
77
77
  import * as React2 from "react";
78
- import { parseExpression } from "@player-ui/player";
78
+ import { parseExpression, isErrorWithLocation } from "@player-ui/player";
79
79
  var OpaqueIdentifier = Symbol("TemplateStringType");
80
80
  var TemplateStringComponent = (props) => {
81
81
  return React2.createElement(
@@ -95,9 +95,20 @@ var createTemplateInstance = (options) => {
95
95
  return sum + next + (element2?.toRefString(options) ?? "");
96
96
  }, "");
97
97
  if (options.nestedContext === "expression") {
98
- const parsedExpression = parseExpression(value, { strict: false });
99
- if (parsedExpression.error) {
100
- throw parsedExpression.error;
98
+ try {
99
+ parseExpression(value);
100
+ } catch (e) {
101
+ if (e instanceof Error) {
102
+ let message;
103
+ if (isErrorWithLocation(e)) {
104
+ message = `${e} in expression: \r
105
+ ${value.slice(0, e.index + 1) + "\u2588" + value.slice(e.index + 1)}`;
106
+ } else {
107
+ message = `${e} in expression ${value}`;
108
+ }
109
+ throw new Error(message);
110
+ }
111
+ throw new Error(`Unknown problem parsing expression ${e}`);
101
112
  }
102
113
  }
103
114
  const toString = () => {
package/dist/index.mjs CHANGED
@@ -75,7 +75,7 @@ import * as React3 from "react";
75
75
 
76
76
  // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts
77
77
  import * as React2 from "react";
78
- import { parseExpression } from "@player-ui/player";
78
+ import { parseExpression, isErrorWithLocation } from "@player-ui/player";
79
79
  var OpaqueIdentifier = Symbol("TemplateStringType");
80
80
  var TemplateStringComponent = (props) => {
81
81
  return React2.createElement(
@@ -95,9 +95,20 @@ var createTemplateInstance = (options) => {
95
95
  return sum + next + (element2?.toRefString(options) ?? "");
96
96
  }, "");
97
97
  if (options.nestedContext === "expression") {
98
- const parsedExpression = parseExpression(value, { strict: false });
99
- if (parsedExpression.error) {
100
- throw parsedExpression.error;
98
+ try {
99
+ parseExpression(value);
100
+ } catch (e) {
101
+ if (e instanceof Error) {
102
+ let message;
103
+ if (isErrorWithLocation(e)) {
104
+ message = `${e} in expression: \r
105
+ ${value.slice(0, e.index + 1) + "\u2588" + value.slice(e.index + 1)}`;
106
+ } else {
107
+ message = `${e} in expression ${value}`;
108
+ }
109
+ throw new Error(message);
110
+ }
111
+ throw new Error(`Unknown problem parsing expression ${e}`);
101
112
  }
102
113
  }
103
114
  const toString = () => {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/auto-id.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/utils.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/switch.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/template.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/schema.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/compiler.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/utils.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/types.ts"],"sourcesContent":["import React from \"react\";\nimport type { ObjectNode, PropertyNode } from \"react-json-reconciler\";\nimport type { View as ViewType } from \"@player-ui/types\";\nimport type { PlayerApplicability, WithChildren } from \"./types\";\nimport {\n IDProvider,\n IDSuffixProvider,\n IndexSuffixStopContext,\n OptionalIDSuffixProvider,\n useGetIdPrefix,\n} from \"./auto-id\";\nimport {\n normalizeText,\n normalizeToCollection,\n toJsonElement,\n toJsonProperties,\n flattenChildren,\n mergeRefs,\n} from \"./utils\";\n\nexport type AssetProps = PlayerApplicability & {\n /** id of the asset */\n id?: string;\n\n /** the asset type */\n type: string;\n\n /** Any other properties on the asset */\n children?: React.ReactNode;\n\n /** other things that we don't know about */\n [key: string]: unknown;\n};\n\nexport const SlotContext = React.createContext<\n | {\n /** The property name for the slot */\n propertyName: string;\n /** If the slot represents an array */\n isArray: boolean;\n /** If the items in the slot should be wrapped in an \"asset\" object */\n wrapInAsset: boolean;\n /** Other props to add to the slot */\n additionalProperties?: any;\n /** The ref to the property node */\n ref: React.RefObject<PropertyNode>;\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n | undefined\n>(undefined);\n\n/**\n * Wraps the children in an `asset` object.\n * Additional props are added to the top level object\n */\nexport const AssetWrapper = React.forwardRef<\n ObjectNode,\n WithChildren<{ [key: string]: unknown }>\n>(function AssetWrapper(props, ref) {\n const { children, ...rest } = props;\n\n return (\n <obj ref={ref}>\n {toJsonProperties(rest)}\n <property name=\"asset\">{children}</property>\n </obj>\n );\n});\n\n/** Create a ID property for a node */\nexport const GeneratedIDProperty = (props: {\n /** the id to use if supplied by the user */\n id?: string;\n}) => {\n const currentPrefixId = useGetIdPrefix();\n return <property name=\"id\">{props.id ?? currentPrefixId}</property>;\n};\n\n/** An asset */\nexport const Asset = React.forwardRef<ObjectNode, AssetProps>((props, ref) => {\n const { id, type, applicability, children, ...rest } = props;\n const slotContext = React.useContext(SlotContext);\n const localRef = React.useRef<ObjectNode>(null);\n const Wrapper = slotContext?.wrapInAsset ? AssetWrapper : React.Fragment;\n\n return (\n <Wrapper\n ref={slotContext?.wrapInAsset ? mergeRefs([ref, localRef]) : undefined}\n {...(slotContext?.wrapInAsset && slotContext?.additionalProperties\n ? slotContext?.additionalProperties\n : {})}\n >\n <OptionalIDSuffixProvider wrapperRef={localRef}>\n <SlotContext.Provider value={undefined}>\n <IDProvider id={id}>\n <obj\n ref={\n slotContext?.wrapInAsset\n ? undefined\n : mergeRefs([ref, localRef])\n }\n >\n <GeneratedIDProperty id={id} />\n <property name=\"type\">{type}</property>\n {applicability !== undefined && (\n <property name=\"applicability\">\n <value\n value={\n typeof applicability === \"boolean\"\n ? applicability\n : applicability.toValue()\n }\n />\n </property>\n )}\n {toJsonProperties(rest)}\n {children}\n </obj>\n </IDProvider>\n </SlotContext.Provider>\n </OptionalIDSuffixProvider>\n </Wrapper>\n );\n});\n\nAsset.displayName = \"Asset\";\n\nAsset.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\nexport const View = React.forwardRef<ObjectNode, AssetProps & ViewType>(\n (props, ref) => {\n const { validation, children, ...rest } = props;\n\n return (\n <Asset ref={ref} {...rest}>\n {validation && (\n <property key=\"validation\" name=\"validation\">\n {toJsonElement(validation, \"validation\", {\n propertiesToSkip: [\"ref\"],\n })}\n </property>\n )}\n {children}\n </Asset>\n );\n }\n);\n\nView.displayName = \"View\";\n\nView.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\n/** A component to generate a named property slot */\nexport const Slot = (props: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** Other properties to add to the slot */\n additionalProperties?: any;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) => {\n const { TextComp, CollectionComp } = props;\n const children = flattenChildren(props.children);\n const propRef = React.useRef<PropertyNode>(null);\n\n return (\n <property ref={propRef} name={props.name}>\n <IDSuffixProvider suffix={props.name}>\n <IndexSuffixStopContext.Provider value={false}>\n <SlotContext.Provider\n value={{\n ref: propRef,\n propertyName: props.name,\n wrapInAsset: props.wrapInAsset ?? false,\n isArray: props.isArray ?? false,\n additionalProperties: props.additionalProperties,\n TextComp,\n CollectionComp,\n }}\n >\n {props.isArray && (\n <array>\n {React.Children.map(children, (child, index) => {\n return (\n // eslint-disable-next-line react/no-array-index-key\n <React.Fragment key={`${props.name}-${index}`}>\n {normalizeText({ node: child, TextComp })}\n </React.Fragment>\n );\n })}\n </array>\n )}\n\n {!props.isArray &&\n normalizeToCollection({\n node: children,\n TextComp,\n CollectionComp,\n })}\n </SlotContext.Provider>\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n </property>\n );\n};\n\n/** Create a slot for a given property */\nexport function createSlot<SlotProps = unknown>(options: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) {\n // eslint-disable-next-line react/display-name\n return (\n props: {\n /** An object to include in this property */\n children?: React.ReactNode;\n } & SlotProps\n ) => {\n const { children, ...other } = props;\n return (\n <Slot {...options} additionalProperties={other}>\n {children}\n </Slot>\n );\n };\n}\n","import React from \"react\";\nimport type { JsonNode } from \"react-json-reconciler\";\nimport { flattenNodes } from \"react-json-reconciler\";\nimport { SlotContext } from \"./components\";\nimport type { WithChildren } from \"./types\";\n\nconst IDSuffixContext = React.createContext<string>(\"root\");\n\nexport const IndexSuffixStopContext = React.createContext<boolean>(false);\n\n/** Get the generated id */\nexport const useGetIdPrefix = () => {\n return React.useContext(IDSuffixContext);\n};\n\n/** Add a suffix to a generated id */\nexport const IDSuffixProvider = (\n props: WithChildren<{\n /** The suffix to append */\n suffix: string;\n }>\n) => {\n const currentPrefix = useGetIdPrefix();\n\n return (\n <IDSuffixContext.Provider\n value={[\n currentPrefix === \"root\" ? undefined : currentPrefix,\n props.suffix,\n ]\n .filter(Boolean)\n .join(\"-\")}\n >\n {props.children}\n </IDSuffixContext.Provider>\n );\n};\n\n/** Override the generated id with the supplied one */\nexport const IDProvider = (\n props: WithChildren<{\n /** The new id to use */\n id?: string;\n }>\n) => {\n if (props.id) {\n return (\n <IDSuffixContext.Provider value={props.id}>\n {props.children}\n </IDSuffixContext.Provider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n\n/** Get the index of an item in a slot */\nexport const useIndexInSlot = (ref: React.RefObject<JsonNode>) => {\n const [index, setIndex] = React.useState(-1);\n const slotContext = React.useContext(SlotContext);\n\n React.useEffect(() => {\n if (!slotContext?.isArray) {\n throw new Error(\"Cannot get index in non-array slot\");\n }\n\n if (ref.current && slotContext?.ref.current?.valueNode?.type === \"array\") {\n const allChildren = flattenNodes(\n slotContext.ref.current.valueNode.children\n );\n const foundIndex = allChildren.indexOf(ref.current);\n\n if (foundIndex !== index) {\n setIndex(foundIndex);\n }\n }\n }, [index, ref, slotContext?.isArray, slotContext?.ref]);\n\n return index;\n};\n\n/** Add the index to the id path when in an array slot */\nexport const IDSuffixIndexProvider = (\n props: WithChildren<{\n /** The ref to use */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotIndex = useIndexInSlot(props.wrapperRef);\n\n const stopIndex = React.useContext(IndexSuffixStopContext);\n\n if (stopIndex) {\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n }\n\n return (\n <IDSuffixProvider suffix={props.templateIndex ?? String(slotIndex)}>\n <IndexSuffixStopContext.Provider value>\n {props.children}\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n );\n};\n\n/** Wrap a slot with the index if in an array slot */\nexport const OptionalIDSuffixProvider = (\n props: WithChildren<{\n /** The ref to walk upwards and use as an index */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotContext = React.useContext(SlotContext);\n\n if (slotContext?.isArray) {\n return (\n <IDSuffixIndexProvider\n wrapperRef={props.wrapperRef}\n templateIndex={props.templateIndex}\n >\n {props.children}\n </IDSuffixIndexProvider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n","import * as React from \"react\";\nimport {\n isTemplateStringInstance,\n TemplateStringComponent,\n} from \"./string-templates\";\nimport type { toJsonOptions } from \"./types\";\n\n/** Get an array version of the value */\nexport function toArray<T>(val: T | Array<T>): Array<T> {\n return Array.isArray(val) ? val : [val];\n}\n\n/** Create a component version */\nexport function toJsonElement(\n value: any,\n indexOrKey?: number | string,\n options?: toJsonOptions\n): React.ReactElement {\n const indexProp = typeof indexOrKey === \"number\" ? { key: indexOrKey } : null;\n\n if (Array.isArray(value)) {\n return (\n <array {...indexProp}>\n {value.map((item, idx) => toJsonElement(item, idx, options))}\n </array>\n );\n }\n\n /** Allow users to pass in BindingTemplateInstance and ExpressionTemplateInstance directly without turning them into strings first */\n if (isTemplateStringInstance(value)) {\n if (\n typeof indexOrKey === \"string\" &&\n options?.propertiesToSkip?.includes(indexOrKey)\n ) {\n return <value {...indexProp}>{value.toValue()}</value>;\n }\n\n return <value {...indexProp}>{value.toRefString()}</value>;\n }\n\n if (typeof value === \"object\" && value !== null) {\n return (\n <obj {...indexProp}>\n {Object.keys(value).map((key) => (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n ))}\n </obj>\n );\n }\n\n return <value {...indexProp} value={value} />;\n}\n\n/** Create a fragment for the properties */\nexport function toJsonProperties(\n value: Record<string, any>,\n options: toJsonOptions = { propertiesToSkip: [\"applicability\"] }\n) {\n return Object.keys(value).map((key) => {\n return (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n );\n });\n}\n\n/** Create a text asset if needed */\nexport function normalizeText(options: {\n /** The current node */\n node: React.ReactNode;\n\n /** A component to render a text asset */\n TextComp?: React.ComponentType<any>;\n}): React.ReactNode {\n const { node, TextComp } = options;\n\n const nodeArr = React.Children.toArray(node);\n\n if (\n nodeArr.every(\n (n) => React.isValidElement(n) && n.type !== TemplateStringComponent\n )\n ) {\n return node;\n }\n\n if (TextComp) {\n return <TextComp>{nodeArr}</TextComp>;\n }\n\n throw new Error(\n `Tried to convert node to Text Asset, but no Component was supplied.`\n );\n}\n\n/** Create a collection if needed */\nexport function normalizeToCollection(options: {\n /** the node to look at */\n node: React.ReactNode;\n\n /** A Text asset */\n TextComp?: React.ComponentType;\n\n /** A collection asset */\n CollectionComp?: React.ComponentType<any>;\n}) {\n const { node, CollectionComp } = options;\n\n if (\n React.Children.count(node) > 1 &&\n React.Children.toArray(node).every((n) => typeof n !== \"string\")\n ) {\n if (!CollectionComp) {\n throw new Error(\n `Tried to convert array to a collection asset, but no Component was given.`\n );\n }\n\n return <CollectionComp>{node}</CollectionComp>;\n }\n\n return normalizeText({ ...options, node });\n}\n\ntype ReactChildArray = ReturnType<typeof React.Children.toArray>;\n\n/**\n *\n * Hoisted from https://github.com/gregberge/react-flatten-children/blob/master/src/index.tsx\n * Peer dependencies were wrong and can't be reasonably patch it everywhere\n */\nexport function flattenChildren(children: React.ReactNode): ReactChildArray {\n const childrenArray = React.Children.toArray(children);\n return childrenArray.reduce((flatChildren: ReactChildArray, child) => {\n if ((child as React.ReactElement<any>).type === React.Fragment) {\n return flatChildren.concat(\n flattenChildren((child as React.ReactElement<any>).props.children)\n );\n }\n\n flatChildren.push(child);\n\n return flatChildren;\n }, []);\n}\n/**\n * Hoisted from https://github.com/gregberge/react-merge-refs/blob/main/src/index.tsx\n * Published packages are ESM only or have bad esm distributions causing issues when\n * used in an esm environment\n */\nexport function mergeRefs<T = any>(\n refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>\n): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref != null) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n });\n };\n}\n\n/** Generates object reference properties from the provided object */\nexport function getObjectReferences<\n OriginalPropertiesObject extends Record<string, unknown>,\n ReferencesPropertyObject extends Record<string, unknown>\n>(propertiesObject: OriginalPropertiesObject): ReferencesPropertyObject {\n const result: any = {};\n\n for (const itemProp in propertiesObject) {\n if (Object.prototype.hasOwnProperty.call(propertiesObject, itemProp)) {\n const refName = `${itemProp}Ref`;\n result[refName as keyof ReferencesPropertyObject] = { type: itemProp };\n }\n }\n\n return result;\n}\n","import * as React from \"react\";\nimport { parseExpression } from \"@player-ui/player\";\n\nexport type TemplateInstanceRefStringContext = \"binding\" | \"expression\";\nexport interface TemplateRefStringOptions {\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n}\nexport interface TemplateInstanceRefStringOptions {\n /** The array of strings for the template */\n strings: ReadonlyArray<string>;\n /** the other data that's present in the template */\n other: Array<string | TemplateStringType>;\n\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n\n /** Convert the value to a reference nested in the given context */\n toRefString: (\n options: TemplateRefStringOptions | undefined,\n value: string\n ) => string;\n}\n\nconst OpaqueIdentifier = Symbol(\"TemplateStringType\");\n\nexport type TemplateStringType = React.ReactElement & {\n /** An identifier to show that this is a template type */\n [OpaqueIdentifier]: true;\n /** The value of the template string when in another string */\n toString: () => string;\n /** the raw value of the template string */\n toValue: () => string;\n /** the dereferenced value when used in another */\n toRefString: (options?: TemplateRefStringOptions) => string;\n};\n\nexport type BindingTemplateInstance = TemplateStringType & {\n /** An identifier for a binding instance */\n __type: \"binding\";\n};\n\nexport type ExpressionTemplateInstance = TemplateStringType & {\n /** The identifier for an expression instance */\n __type: \"expression\";\n};\n\n/** A react component for rendering a template string type */\nexport const TemplateStringComponent = (props: {\n /** The string value of the child template string */\n value: string;\n}) => {\n return React.createElement(\n \"value\",\n {\n value: props.value,\n },\n null\n );\n};\n\n/** The generic template string handler */\nconst createTemplateInstance = (\n options: TemplateInstanceRefStringOptions\n): TemplateStringType => {\n const value = options.strings.reduce((sum, next, i) => {\n const element = options.other[i];\n if (typeof element === \"string\") {\n return sum + next + element;\n }\n\n return sum + next + (element?.toRefString(options) ?? \"\");\n }, \"\");\n\n /** Try to parse the expression as valid */\n if (options.nestedContext === \"expression\") {\n const parsedExpression = parseExpression(value, { strict: false });\n if (parsedExpression.error) {\n throw parsedExpression.error;\n }\n }\n\n /** get the unwrapped version */\n const toString = () => {\n return options.toRefString({}, value);\n };\n\n /** get the raw value of the template */\n const toValue = () => {\n return value;\n };\n\n /** This lets us use it directly as a child element in React */\n const element = React.createElement(\n TemplateStringComponent,\n {\n value: toString(),\n },\n null\n ) as TemplateStringType;\n\n return {\n ...element,\n [OpaqueIdentifier]: true,\n toString,\n toValue,\n toRefString: (refStringOptions?: TemplateRefStringOptions) => {\n return options.toRefString(refStringOptions, value);\n },\n };\n};\n\n/** Helper for Iterating the binding to add a dynamic numeric value to each index found */\nconst addBindingIndexes = (binding: string): string => {\n let currentIndex = 0;\n\n return binding.replace(/_index_/g, () => {\n const result = `_index${currentIndex > 0 ? currentIndex : \"\"}_`;\n currentIndex += 1;\n\n return result;\n });\n};\n\n/** Creating an instance of a handler for bindings */\nconst createBindingTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n): BindingTemplateInstance => {\n const templateInstance = createTemplateInstance({\n ...options,\n strings: options.strings.map((element: string) =>\n addBindingIndexes(element)\n ),\n other: options.other.map((element) =>\n typeof element === \"string\" ? addBindingIndexes(element) : element\n ),\n toRefString: (context, value) => {\n return `{{${value}}}`;\n },\n }) as BindingTemplateInstance;\n\n templateInstance.__type = \"binding\";\n\n return templateInstance;\n};\n\n/** Creating an instance of a handler for bindings */\nconst createExpressionTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n) => {\n const templateInstance = createTemplateInstance({\n ...options,\n toRefString: (contextOptions, value) => {\n if (contextOptions?.nestedContext === \"expression\") {\n return value;\n }\n\n const inBinding = contextOptions?.nestedContext === \"binding\";\n return `${inBinding ? \"`\" : \"@[\"}${value}${inBinding ? \"`\" : \"]@\"}`;\n },\n }) as ExpressionTemplateInstance;\n\n templateInstance.__type = \"expression\";\n\n return templateInstance;\n};\n\n/** A tagged-template constructor for a binding */\nexport const binding = (\n strings: TemplateStringsArray,\n ...nested: Array<TemplateStringType | string>\n): BindingTemplateInstance => {\n return createBindingTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"binding\",\n });\n};\n\n/** A tagged-template constructor for an expression */\nexport const expression = (\n strings: TemplateStringsArray,\n ...nested: Array<\n ExpressionTemplateInstance | BindingTemplateInstance | string\n >\n): ExpressionTemplateInstance => {\n return createExpressionTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"expression\",\n });\n};\n\n/** Check if a value is a template string */\nexport const isTemplateStringInstance = (\n val: unknown\n): val is ExpressionTemplateInstance | BindingTemplateInstance => {\n return (\n val !== null &&\n typeof val === \"object\" &&\n (val as any)[OpaqueIdentifier] === true\n );\n};\n","import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport type { ArrayNode, JsonNode, ObjectNode } from \"react-json-reconciler\";\nimport { flattenNodes, PropertyNode } from \"react-json-reconciler\";\nimport { SlotContext } from \".\";\nimport { IDSuffixProvider, OptionalIDSuffixProvider } from \"./auto-id\";\nimport type {\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n} from \"./string-templates\";\nimport { isTemplateStringInstance } from \"./string-templates\";\nimport { normalizeToCollection, toJsonProperties } from \"./utils\";\n\nexport interface SwitchProps {\n /** defaults to a staticSwitch */\n isDynamic?: boolean;\n}\n\nconst SwitchContext = React.createContext<\n SwitchProps & {\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n>({});\n\n/**\n * Switches allow users to fork content between 1 or more assets\n */\nexport const Switch = (props: PropsWithChildren<SwitchProps>) => {\n const slotContext = React.useContext(SlotContext);\n const propertyNode = React.useRef<ObjectNode>(null);\n\n return (\n <obj ref={propertyNode}>\n <SwitchContext.Provider\n value={{\n ...props,\n TextComp: slotContext?.TextComp,\n CollectionComp: slotContext?.CollectionComp,\n }}\n >\n <OptionalIDSuffixProvider wrapperRef={propertyNode}>\n <property name={props.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"}>\n <SlotContext.Provider value={undefined}>\n <array>{props.children}</array>\n </SlotContext.Provider>\n </property>\n </OptionalIDSuffixProvider>\n </SwitchContext.Provider>\n {slotContext?.additionalProperties &&\n toJsonProperties(slotContext.additionalProperties)}\n </obj>\n );\n};\n\nexport interface CaseProps {\n /** the test for this case statement */\n exp?: ExpressionTemplateInstance | BindingTemplateInstance | boolean;\n}\n\n/** Find the first parent array */\nconst findParentArray = (node: JsonNode): ArrayNode => {\n if (node.type === \"array\") {\n return node;\n }\n\n if (node.parent) {\n return findParentArray(node.parent);\n }\n\n throw new Error(\"can't find parent array\");\n};\n\n/** Find the index of the item in an array */\nconst findArrayIndex = (node: JsonNode): number => {\n const parentArray = findParentArray(node);\n const allSearch = flattenNodes(parentArray.children);\n return allSearch.indexOf(node);\n};\n\n/** A case for a switch */\nconst Case = (props: PropsWithChildren<CaseProps>) => {\n const slotContext = React.useContext(SlotContext);\n const switchContext = React.useContext(SwitchContext);\n const [caseIndex, setCaseIndex] = React.useState(-1);\n const caseNode = React.useRef<ObjectNode>(null);\n\n React.useLayoutEffect(() => {\n if (caseNode.current) {\n const index = findArrayIndex(caseNode.current);\n if (index !== caseIndex) {\n setCaseIndex(index);\n }\n }\n }, [caseIndex]);\n\n let expValue: string | boolean = true;\n\n if (props.exp !== undefined) {\n expValue = isTemplateStringInstance(props.exp)\n ? props.exp.toValue()\n : props.exp;\n }\n\n return (\n <obj ref={caseNode}>\n <property name=\"case\">\n <value value={expValue} />\n </property>\n <IDSuffixProvider\n suffix={`${\n switchContext.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"\n }-${caseIndex}`}\n >\n <SlotContext.Provider\n value={\n slotContext ? { ...slotContext, wrapInAsset: false } : undefined\n }\n >\n <property name=\"asset\">\n {normalizeToCollection({\n node: props.children,\n TextComp: switchContext?.TextComp,\n CollectionComp: switchContext?.CollectionComp,\n })}\n </property>\n </SlotContext.Provider>\n </IDSuffixProvider>\n </obj>\n );\n};\n\nSwitch.Case = Case;\n","import React from \"react\";\nimport type { ObjectNode, JsonNode } from \"react-json-reconciler\";\nimport {\n ArrayNode,\n PropertyNode,\n ValueNode,\n createPortal,\n ProxyNode,\n toJSON,\n} from \"react-json-reconciler\";\nimport { OptionalIDSuffixProvider } from \"./auto-id\";\nimport type { BindingTemplateInstance } from \"./string-templates\";\nimport type { WithChildren } from \"./types\";\nimport { toJsonElement } from \"./utils\";\n\nexport interface TemplateContextType {\n /** The number of nested templates */\n depth: number;\n}\n\nexport const TemplateContext = React.createContext<TemplateContextType>({\n depth: 0,\n});\n\nexport interface TemplateProps {\n /** The source binding */\n data: BindingTemplateInstance;\n\n /** The target property */\n output?: string;\n\n /** The template value */\n children: React.ReactNode;\n\n /** boolean that specifies whether template should recompute when data changes */\n dynamic?: boolean;\n}\n\n/** Add a template instance to the object */\nfunction addTemplateToObject(\n obj: ObjectNode,\n templateObj: ObjectNode,\n templateParentNodeType: string\n): () => void {\n // find a template property\n // add one if none exists\n\n let templateProp = obj.properties.find(\n (p) => p.keyNode.value === \"template\" && p.valueNode?.type === \"array\"\n );\n\n if (!templateProp) {\n templateProp = new PropertyNode(new ValueNode(\"template\"), new ArrayNode());\n templateProp.parent = obj;\n obj.properties.push(templateProp);\n }\n\n const templateItems = templateProp.valueNode as ArrayNode;\n\n templateItems.items.push(templateObj);\n // eslint-disable-next-line no-param-reassign\n templateObj.parent = templateItems;\n\n const templateParentProp = obj.properties.find(\n (p) =>\n p.keyNode.value === templateParentNodeType &&\n p.valueNode?.type === \"array\"\n );\n\n if (templateParentProp) {\n const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);\n const templateParentValueNode =\n obj.properties[indexOfTemplateParent]?.valueNode;\n if (templateParentValueNode) {\n const templateParentArray = toJSON(templateParentValueNode);\n\n // Delete the parent of template if it is an empty array\n if (\n Array.isArray(templateParentArray) &&\n templateParentArray.length === 0\n ) {\n obj.properties.splice(indexOfTemplateParent, 1);\n }\n }\n }\n\n return () => {\n // Remove the template item from the list\n templateItems.items = templateItems.items.filter((t) => t !== templateObj);\n\n // Clean up the whole template if it's removed\n if (templateItems.children.length === 0 && templateProp) {\n obj.properties.splice(obj.properties.indexOf(templateProp, 1));\n }\n };\n}\n\n/** Context provider wrapper to handle nested templates */\nconst TemplateProvider = (props: WithChildren) => {\n const baseContext = React.useContext(TemplateContext);\n\n return (\n <TemplateContext.Provider value={{ depth: baseContext.depth + 1 }}>\n {props.children}\n </TemplateContext.Provider>\n );\n};\n\n/** Find the first object node in the tree */\nconst getParentObject = (node: JsonNode): ObjectNode | undefined => {\n if (node.type === \"object\") {\n return node;\n }\n\n if (node.parent) {\n return getParentObject(node.parent);\n }\n};\n\n/** Find the property of the node on the parent */\nconst getParentProperty = (node: JsonNode): PropertyNode | undefined => {\n if (node.type === \"property\") {\n return node;\n }\n\n if (node.parent) {\n return getParentProperty(node.parent);\n }\n};\n\n/** A template allows users to dynamically map over an array of data */\nexport const Template = (props: TemplateProps) => {\n const baseContext = React.useContext(TemplateContext);\n const dynamicProp = props.dynamic ?? false;\n const [outputProp, setOutputProp] = React.useState<string | undefined>(\n props.output\n );\n const proxyRef = React.useRef<ProxyNode>(null);\n const valueRef = React.useRef<ValueNode>(null);\n const outputElement = React.useMemo(() => new ProxyNode(), []);\n\n React.useLayoutEffect(() => {\n // Get the output prop\n const propNode = proxyRef.current && getParentProperty(proxyRef.current);\n\n if (outputProp === undefined && propNode) {\n setOutputProp(propNode.keyNode.value);\n }\n }, [proxyRef, outputProp]);\n\n React.useEffect(() => {\n const templateObj = outputElement.items[0] as ObjectNode;\n if (proxyRef.current) {\n const parentObject = getParentObject(proxyRef.current);\n\n if (!parentObject) {\n throw new Error(\"Unable to find parent to add template to\");\n }\n\n if (!outputProp) {\n return;\n }\n\n // remove the template when unmounted\n return addTemplateToObject(parentObject, templateObj, outputProp);\n }\n }, [proxyRef, outputProp, outputElement.items]);\n\n return (\n <proxy ref={proxyRef}>\n <>\n {createPortal(\n <OptionalIDSuffixProvider\n wrapperRef={valueRef}\n templateIndex={`_index${\n baseContext.depth === 0 ? \"\" : baseContext.depth\n }_`}\n >\n <TemplateProvider>\n <object>\n <property name=\"data\">{props.data.toValue()}</property>\n <property name=\"output\">{outputProp}</property>\n <property name=\"value\">{props.children}</property>\n {dynamicProp && (\n <property name=\"dynamic\">\n {toJsonElement(dynamicProp)}\n </property>\n )}\n </object>\n </TemplateProvider>\n </OptionalIDSuffixProvider>,\n outputElement\n )}\n <value ref={valueRef} value={undefined} />\n </>\n </proxy>\n );\n};\n","export * from \"./components\";\nexport * from \"./auto-id\";\nexport * from \"./types\";\nexport * from \"./string-templates\";\nexport * from \"./utils\";\nexport * from \"./switch\";\nexport * from \"./template\";\nexport * from \"react-json-reconciler\";\nexport * from \"./compiler/schema\";\nexport * from \"./compiler\";\nexport * from \"./compiler/types\";\n","import type { Schema, Language } from \"@player-ui/types\";\nimport { dequal } from \"dequal\";\nimport { SyncWaterfallHook } from \"tapable-ts\";\nimport type { LoggingInterface } from \"..\";\nimport { binding as b } from \"..\";\nimport type { BindingTemplateInstance } from \"../string-templates\";\n\nconst bindingSymbol = Symbol(\"binding\");\n\n/** Symbol to indicate that a schema node should be generated with a different name */\nexport const SchemaTypeName = Symbol(\"Schema Rename\");\n\ninterface SchemaChildren {\n /** Object property that will be used to create the intermediate type */\n name: string;\n\n /** Object properties children that will be parsed */\n child: object;\n}\n\ntype SchemaNode = (Schema.DataType | Language.DataTypeRef) & {\n /** Overwrite the name of the generated type */\n [SchemaTypeName]?: string;\n};\n\ninterface GeneratedDataType {\n /** The SchemaNode that was generated */\n node: SchemaNode;\n /** How many times it has been generated */\n count: number;\n}\n\n/**\n * Type Guard for the `Schema.DataType` and `Language.DataTypeRef` type\n * A bit hacky but since `Schema.Schema` must have a `Schema.DataType` as\n * the final product we have to call it that even if it is a `Language.DataTypeRef`\n */\nconst isTypeDef = (property: SchemaNode): property is Schema.DataType => {\n return (property as Schema.DataType).type !== undefined;\n};\n\n/**\n * Generator for `Schema.Schema` Objects\n */\nexport class SchemaGenerator {\n private children: Array<SchemaChildren>;\n private generatedDataTypes: Map<string, GeneratedDataType>;\n private logger: LoggingInterface;\n\n public hooks = {\n createSchemaNode: new SyncWaterfallHook<\n [\n node: Schema.DataType,\n originalProperty: Record<string | symbol, unknown>\n ]\n >(),\n };\n\n constructor(logger?: LoggingInterface) {\n this.children = [];\n this.generatedDataTypes = new Map();\n this.logger = logger ?? console;\n }\n\n /**\n * Converts an object to a `Schema.Schema` representation\n * Note: uses iteration to prevent potentially very deep recursion on large objects\n */\n public toSchema = (schema: any): Schema.Schema => {\n const newSchema: Schema.Schema = {\n ROOT: {},\n };\n\n this.children = [];\n this.generatedDataTypes.clear();\n\n Object.keys(schema).forEach((property) => {\n const subType = schema[property] as SchemaNode;\n newSchema.ROOT[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n\n while (this.children.length > 0) {\n const c = this.children.pop();\n if (c === undefined) {\n break;\n }\n\n const { name, child } = c;\n const typeDef = {} as any;\n\n Object.keys(child).forEach((property) => {\n const subType = (child as any)[property] as SchemaNode;\n typeDef[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n newSchema[name] = typeDef;\n }\n\n return newSchema;\n };\n\n /**\n * Processes the children of an object Node\n * Newly discovered children get added to the provided array\n */\n private processChild(property: string, subType: SchemaNode): Schema.DataType {\n if (isTypeDef(subType)) {\n return subType;\n }\n\n let intermediateType;\n let child;\n\n if (Array.isArray(subType)) {\n if (subType.length > 1) {\n this.logger.warn(\n `Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`\n );\n }\n\n const subTypeName = subType[0][SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderArrayType(subTypeName);\n [child] = subType;\n } else {\n const subTypeName = subType[SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderType(subTypeName);\n child = subType;\n }\n\n this.children.push({ name: intermediateType.type, child });\n\n if (this.generatedDataTypes.has(intermediateType.type)) {\n const generatedType = this.generatedDataTypes.get(\n intermediateType.type\n ) as GeneratedDataType;\n if (\n !dequal(\n child,\n this.generatedDataTypes.get(intermediateType.type)?.node as object\n )\n ) {\n generatedType.count += 1;\n const newIntermediateType = {\n ...intermediateType,\n type: `${intermediateType.type}${generatedType.count}`,\n };\n this.logger.warn(\n `WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`\n );\n intermediateType = newIntermediateType;\n this.children.pop();\n this.children.push({ name: intermediateType.type, child });\n }\n }\n\n this.generatedDataTypes.set(intermediateType.type, {\n node: subType,\n count: 1,\n });\n return intermediateType;\n }\n\n /**\n * Make an intermediate `Schema.DataType` object given a name\n */\n private makePlaceholderType = (typeName: string): Schema.DataType => {\n return {\n type: `${typeName}Type`,\n };\n };\n\n /**\n * Make an intermediate `Schema.DataType` object with array support given a name\n */\n private makePlaceholderArrayType(typeName: string): Schema.DataType {\n return {\n type: `${typeName}Type`,\n isArray: true,\n };\n }\n}\n\nexport type MakeArrayIntoIndexRef<T extends any[]> = {\n [key: number]: MakeBindingRefable<T[0]>;\n /** Used when referencing bindings from within a template */\n _index_: MakeBindingRefable<T[0]>;\n} & BindingTemplateInstance;\n\nexport type MakeBindingRefable<T> = {\n [P in keyof T]: T[P] extends object[]\n ? MakeArrayIntoIndexRef<T[P]>\n : T[P] extends unknown[]\n ? T[P]\n : MakeBindingRefable<T[P]>;\n} & BindingTemplateInstance;\n\n/**\n * Adds bindings to an object so that the object can be directly used in JSX\n */\nexport function makeBindingsForObject<Type>(\n obj: Type,\n arrayAccessorKeys = [\"_index_\"]\n): MakeBindingRefable<Type> {\n /** Proxy to track binding callbacks */\n const accessor = (paths: string[]) => {\n const bindingMap = new WeakMap<any, BindingTemplateInstance>();\n\n return {\n ownKeys(target: any) {\n return Reflect.ownKeys(target);\n },\n\n get(target: any, key: any): any {\n const bindingKeys = Object.keys(target);\n\n // If there is an array of primitives, just return a copy of that array\n if (\n Array.isArray(target[key]) &&\n target[key].length > 0 &&\n target[key].every((it: any) => typeof it !== \"object\")\n ) {\n return [...target[key]];\n }\n\n if (!bindingMap.has(target)) {\n bindingMap.set(target, b`${paths.join(\".\")}`);\n }\n\n if (key === bindingSymbol) {\n return paths;\n }\n\n if (\n Array.isArray(target) &&\n (arrayAccessorKeys.includes(key) || typeof key === \"number\")\n ) {\n return new Proxy(target[0], accessor(paths.concat([key])));\n }\n\n if (bindingKeys.includes(key) && typeof target[key] === \"object\") {\n return new Proxy(target[key], accessor(paths.concat([key])));\n }\n\n const createdInstance = bindingMap.get(target) as any;\n return createdInstance?.[key];\n },\n };\n };\n\n return new Proxy(obj, accessor([])) as MakeBindingRefable<Type>;\n}\n\n/**\n * Generates binding for an object property\n */\nexport const getBindingFromObject = (obj: any) => {\n const baseBindings = obj[bindingSymbol] as string[];\n if (!Array.isArray(baseBindings) || baseBindings.length === 0) {\n throw new Error(`Unable to get binding for ${obj}`);\n }\n\n return b`${baseBindings.join(\".\")}`;\n};\n\n/**\n * Returns the binding string from an object path\n */\nexport const getBindingStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toString();\n};\n\n/**\n * Returns the ref string from an object path\n */\nexport const getRefStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toRefString();\n};\n","import React from \"react\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport { SourceMapGenerator, SourceMapConsumer } from \"source-map-js\";\nimport { render } from \"react-json-reconciler\";\nimport type { Flow, View, Navigation as PlayerNav } from \"@player-ui/types\";\nimport {\n AsyncSeriesHook,\n AsyncSeriesWaterfallHook,\n SyncHook,\n} from \"tapable-ts\";\nimport { fingerprintContent } from \"./utils\";\nimport type {\n LoggingInterface,\n CompilerReturn,\n SerializeContext,\n} from \"./types\";\nimport type { Navigation } from \"../types\";\nimport { SchemaGenerator } from \"./schema\";\n\n/**\n * Argument passed to the DSLCompiler onEnd hook\n * Defined as an object so additional fields can be added later without breaking API\n * */\nexport interface OnEndArg {\n /** target output directory **/\n output: string;\n}\n\n/** Recursively find BindingTemplateInstance and call toValue on them */\nconst parseNavigationExpressions = (nav: Navigation): PlayerNav => {\n /** Same as above but signature changed */\n function replaceExpWithStr(obj: any): any {\n /** call toValue if BindingTemplateInstance otherwise continue */\n function convExp(value: any): any {\n return value && typeof value === \"object\" && value.__type === \"expression\"\n ? value.toValue() // exp, onStart, and onEnd don't need to be wrapped in @[]@\n : replaceExpWithStr(value);\n }\n\n if (Array.isArray(obj)) {\n return obj.map(convExp);\n }\n\n if (typeof obj === \"object\") {\n const copy = { ...obj };\n for (const [key, value] of Object.entries(copy)) {\n copy[key] = convExp(value);\n }\n\n return copy;\n }\n\n return obj;\n }\n\n return replaceExpWithStr(nav);\n};\n\ntype SourceMapList = Array<{\n /** The mappings of the original */\n sourceMap: string;\n /**\n * The id of the view we're indexing off of\n * This should be a unique global identifier within the generated code\n * e.g. `\"id\": \"view_0\",`\n */\n offsetIndexSearch: string;\n /** The generated source that produced the map */\n source: string;\n}>;\n\n/** Given a list of source maps for all generated views, merge them into 1 */\nconst mergeSourceMaps = (\n sourceMaps: SourceMapList,\n generated: string\n): string => {\n const generator = new SourceMapGenerator();\n sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {\n const generatedLineOffset = generated\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const sourceLineOffset = source\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const lineOffset = generatedLineOffset - sourceLineOffset;\n\n const generatedLine = generated.split(\"\\n\")[generatedLineOffset];\n const sourceLine = source.split(\"\\n\")[sourceLineOffset];\n\n const generatedColumn = generatedLine.indexOf(offsetIndexSearch);\n const sourceColumn = sourceLine.indexOf(offsetIndexSearch);\n const columnOffset = generatedColumn - sourceColumn;\n\n const consumer = new SourceMapConsumer(JSON.parse(sourceMap));\n consumer.eachMapping((mapping) => {\n generator.addMapping({\n generated: {\n line: mapping.generatedLine + lineOffset,\n column: mapping.generatedColumn + columnOffset,\n },\n original: {\n line: mapping.originalLine,\n column: mapping.originalColumn,\n },\n source: mapping.source,\n });\n });\n });\n\n return generator.toString();\n};\n\n/** A compiler for transforming DSL content into JSON */\nexport class DSLCompiler {\n public readonly logger: LoggingInterface;\n public hooks = {\n // Hook to access the schema generator instance when initialized\n schemaGenerator: new SyncHook<[SchemaGenerator]>(),\n // Hook to access pre-compilation object\n preProcessFlow: new AsyncSeriesWaterfallHook<[object]>(),\n // Hook to access post-compilation Flow before output is written\n postProcessFlow: new AsyncSeriesWaterfallHook<[Flow]>(),\n // Hook called after all files are compiled. Revives the output directory\n onEnd: new AsyncSeriesHook<[OnEndArg]>(),\n };\n\n private schemaGenerator?: SchemaGenerator;\n\n constructor(logger?: LoggingInterface) {\n this.logger = logger ?? console;\n }\n\n /** Convert an object (flow, view, schema, etc) into it's JSON representation */\n async serialize(\n value: unknown,\n context?: SerializeContext\n ): Promise<CompilerReturn> {\n if (typeof value !== \"object\" || value === null) {\n throw new Error(\"Unable to serialize non-object\");\n }\n\n const type = context?.type ? context.type : fingerprintContent(value);\n\n if (!this.schemaGenerator) {\n this.schemaGenerator = new SchemaGenerator(this.logger);\n this.hooks.schemaGenerator.call(this.schemaGenerator);\n }\n\n if (type === \"view\") {\n const { jsonValue, sourceMap } = await render(value as any, {\n collectSourceMap: true,\n });\n\n return {\n value: jsonValue,\n sourceMap,\n };\n }\n\n if (type === \"flow\") {\n // Source maps from all the nested views\n // Merge these together before returning\n const allSourceMaps: SourceMapList = [];\n\n // Assume this is a flow\n const copiedValue: Flow = {\n ...(value as any),\n };\n\n copiedValue.views = (await Promise.all(\n copiedValue?.views?.map(async (node: any) => {\n if (React.isValidElement(node)) {\n const { jsonValue, sourceMap, stringValue } = await render(node, {\n collectSourceMap: true,\n });\n\n if (sourceMap) {\n // Find the line that is the id of the view\n // Use that as the identifier for the sourcemap offset calc\n const searchIdLine = stringValue\n .split(\"\\n\")\n .find((line) =>\n line.includes(\n `\"id\": \"${(jsonValue as Record<string, string>).id}\"`\n )\n );\n\n if (searchIdLine) {\n allSourceMaps.push({\n sourceMap,\n offsetIndexSearch: searchIdLine,\n source: stringValue,\n });\n }\n }\n\n return jsonValue;\n }\n\n return node;\n }) ?? []\n )) as View[];\n\n // Go through the flow and sub out any view refs that are react elements w/ the right id\n if (\"navigation\" in value) {\n Object.entries((value as Flow).navigation).forEach(([navKey, node]) => {\n if (typeof node === \"object\") {\n Object.entries(node).forEach(([nodeKey, flowNode]) => {\n if (\n flowNode &&\n typeof flowNode === \"object\" &&\n \"state_type\" in flowNode &&\n flowNode.state_type === \"VIEW\" &&\n React.isValidElement(flowNode.ref)\n ) {\n const actualViewIndex = (value as Flow).views?.indexOf?.(\n flowNode.ref as any\n );\n\n if (actualViewIndex !== undefined && actualViewIndex > -1) {\n const actualId = copiedValue.views?.[actualViewIndex]?.id;\n\n (copiedValue as any).navigation[navKey][nodeKey].ref =\n actualId;\n }\n }\n });\n }\n });\n }\n\n if (\"schema\" in copiedValue) {\n copiedValue.schema = this.schemaGenerator.toSchema(copiedValue.schema);\n }\n\n copiedValue.navigation = parseNavigationExpressions(\n copiedValue.navigation\n );\n\n if (value) {\n const postProcessFlow = await this.hooks.postProcessFlow.call(\n copiedValue\n );\n\n return {\n value: postProcessFlow as JsonType,\n sourceMap: mergeSourceMaps(\n allSourceMaps,\n JSON.stringify(copiedValue, null, 2)\n ),\n };\n }\n }\n\n // Type has been set to \"schema\"\n return {\n value: this.schemaGenerator.toSchema(value) as JsonType,\n };\n }\n}\n","import React from \"react\";\nimport type { DefaultCompilerContentType } from \"./types\";\n\n/** Basic way of identifying the type of file based on the default content export */\nexport const fingerprintContent = (\n content: unknown,\n filename?: string\n): DefaultCompilerContentType | undefined => {\n if (content !== null || content !== undefined) {\n if (React.isValidElement(content as any)) {\n return \"view\";\n }\n\n if (typeof content === \"object\" && \"navigation\" in (content as any)) {\n return \"flow\";\n }\n\n if (!filename || filename.includes(\"schema\")) {\n return \"schema\";\n }\n }\n};\n","import type {\n Schema,\n Navigation,\n Flow,\n Expression,\n ExpressionObject,\n NavigationFlow,\n NavigationFlowState,\n NavigationFlowViewState,\n} from \"@player-ui/types\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport type { RemoveUnknownIndex, AddUnknownIndex } from \"../types\";\nimport type { DSLSchema } from \"../types\";\n\nexport type NavigationFlowReactViewState = Omit<\n NavigationFlowViewState,\n \"ref\"\n> & {\n /** The view element */\n ref: React.ReactElement | string;\n};\n\nexport type NavFlowState =\n | Exclude<NavigationFlowState, NavigationFlowViewState>\n | NavigationFlowReactViewState;\n\nexport type NavigationFlowWithReactView = Pick<\n NavigationFlow,\n \"startState\" | \"onStart\" | \"onEnd\"\n> & {\n [key: string]:\n | undefined\n | string\n | Expression\n | ExpressionObject\n | NavFlowState;\n};\n\nexport type NavigationWithReactViews = Pick<Navigation, \"BEGIN\"> &\n Record<string, string | NavigationFlowWithReactView>;\n\nexport type FlowWithoutUnknown = RemoveUnknownIndex<Flow>;\nexport type FlowWithReactViews = AddUnknownIndex<\n Omit<FlowWithoutUnknown, \"views\" | \"navigation\"> & {\n /** An array of JSX view elements */\n views?: Array<React.ReactElement>;\n\n /** The navigation element */\n navigation?: NavigationWithReactViews;\n }\n>;\n\nexport type DSLFlow = Omit<FlowWithReactViews, \"schema\"> & {\n /** A DSL compliant schema */\n schema?: DSLSchema;\n};\n\nexport type SerializeType = \"view\" | \"flow\" | \"schema\" | \"navigation\";\n\nexport type SerializablePlayerExportTypes =\n | React.ReactElement\n | FlowWithReactViews\n | Schema.Schema\n | Navigation;\n\nexport type LoggingInterface = Pick<Console, \"warn\" | \"error\" | \"log\">;\n\nexport type CompilationResult = {\n /** What type of file is generated */\n contentType: string;\n /** The output path */\n outputFile: string;\n /** the input file */\n inputFile: string;\n};\n\nexport type CompilerReturn = {\n /** the JSON value of the source */\n value: JsonType | undefined;\n\n /** The sourcemap of the content */\n sourceMap?: string;\n};\n\n/** The different type of default content items the compiler handles */\nconst DefaultCompilerContentTypes = [\"view\", \"flow\", \"schema\"] as const;\n\nexport type DefaultCompilerContentType =\n (typeof DefaultCompilerContentTypes)[number];\n\n/** Helper function to determine whether a content type is compiler default */\nexport function isDefaultCompilerContentType(\n t: string\n): t is DefaultCompilerContentType {\n return DefaultCompilerContentTypes.includes(t as DefaultCompilerContentType);\n}\n\nexport interface SerializeContext {\n /** The type of the content being compiled */\n type: DefaultCompilerContentType;\n}\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACAlB,OAAO,WAAW;AAElB,SAAS,oBAAoB;AAI7B,IAAM,kBAAkB,MAAM,cAAsB,MAAM;AAEnD,IAAM,yBAAyB,MAAM,cAAuB,KAAK;AAGjE,IAAM,iBAAiB,MAAM;AAClC,SAAO,MAAM,WAAW,eAAe;AACzC;AAGO,IAAM,mBAAmB,CAC9B,UAIG;AACH,QAAM,gBAAgB,eAAe;AAErC,SACE;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC,OAAO;AAAA,QACL,kBAAkB,SAAS,SAAY;AAAA,QACvC,MAAM;AAAA,MACR,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AAAA;AAAA,IAEV,MAAM;AAAA,EACT;AAEJ;AAGO,IAAM,aAAa,CACxB,UAIG;AACH,MAAI,MAAM,IAAI;AACZ,WACE,oCAAC,gBAAgB,UAAhB,EAAyB,OAAO,MAAM,MACpC,MAAM,QACT;AAAA,EAEJ;AAGA,SAAO,0DAAG,MAAM,QAAS;AAC3B;AAGO,IAAM,iBAAiB,CAAC,QAAmC;AAChE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,EAAE;AA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eAAe,SAAS,GAAG,GACjC;AACA,sBAAM,kBAAmB,MAAe,OAAO;AAAA,kBAC7C,SAAS;AAAA,gBACX;AAEA,oBAAI,oBAAoB,UAAa,kBAAkB,IAAI;AACzD,wBAAM,WAAW,YAAY,QAAQ,eAAe,GAAG;AAEvD,kBAAC,YAAoB,WAAW,MAAM,EAAE,OAAO,EAAE,MAC/C;AAAA,gBACJ;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAEA,UAAI,YAAY,aAAa;AAC3B,oBAAY,SAAS,KAAK,gBAAgB,SAAS,YAAY,MAAM;AAAA,MACvE;AAEA,kBAAY,aAAa;AAAA,QACvB,YAAY;AAAA,MACd;AAEA,UAAI,OAAO;AACT,cAAM,kBAAkB,MAAM,KAAK,MAAM,gBAAgB;AAAA,UACvD;AAAA,QACF;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,WAAW;AAAA,YACT;AAAA,YACA,KAAK,UAAU,aAAa,MAAM,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,OAAO,KAAK,gBAAgB,SAAS,KAAK;AAAA,IAC5C;AAAA,EACF;AACF;;;AEhLA,IAAM,8BAA8B,CAAC,QAAQ,QAAQ,QAAQ;AAMtD,SAAS,6BACd,GACiC;AACjC,SAAO,4BAA4B,SAAS,CAA+B;AAC7E;","names":["React","React","React","element","binding","React","AssetWrapper","React","flattenNodes","React","flattenNodes","React","PropertyNode","React","PropertyNode","React","React","React"]}
1
+ {"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/components.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/auto-id.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/utils.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/string-templates/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/switch.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/template.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/schema.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/compiler.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/utils.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/language/dsl/src/compiler/types.ts"],"sourcesContent":["import React from \"react\";\nimport type { ObjectNode, PropertyNode } from \"react-json-reconciler\";\nimport type { View as ViewType } from \"@player-ui/types\";\nimport type { PlayerApplicability, WithChildren } from \"./types\";\nimport {\n IDProvider,\n IDSuffixProvider,\n IndexSuffixStopContext,\n OptionalIDSuffixProvider,\n useGetIdPrefix,\n} from \"./auto-id\";\nimport {\n normalizeText,\n normalizeToCollection,\n toJsonElement,\n toJsonProperties,\n flattenChildren,\n mergeRefs,\n} from \"./utils\";\n\nexport type AssetProps = PlayerApplicability & {\n /** id of the asset */\n id?: string;\n\n /** the asset type */\n type: string;\n\n /** Any other properties on the asset */\n children?: React.ReactNode;\n\n /** other things that we don't know about */\n [key: string]: unknown;\n};\n\nexport const SlotContext = React.createContext<\n | {\n /** The property name for the slot */\n propertyName: string;\n /** If the slot represents an array */\n isArray: boolean;\n /** If the items in the slot should be wrapped in an \"asset\" object */\n wrapInAsset: boolean;\n /** Other props to add to the slot */\n additionalProperties?: any;\n /** The ref to the property node */\n ref: React.RefObject<PropertyNode>;\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n | undefined\n>(undefined);\n\n/**\n * Wraps the children in an `asset` object.\n * Additional props are added to the top level object\n */\nexport const AssetWrapper = React.forwardRef<\n ObjectNode,\n WithChildren<{ [key: string]: unknown }>\n>(function AssetWrapper(props, ref) {\n const { children, ...rest } = props;\n\n return (\n <obj ref={ref}>\n {toJsonProperties(rest)}\n <property name=\"asset\">{children}</property>\n </obj>\n );\n});\n\n/** Create a ID property for a node */\nexport const GeneratedIDProperty = (props: {\n /** the id to use if supplied by the user */\n id?: string;\n}) => {\n const currentPrefixId = useGetIdPrefix();\n return <property name=\"id\">{props.id ?? currentPrefixId}</property>;\n};\n\n/** An asset */\nexport const Asset = React.forwardRef<ObjectNode, AssetProps>((props, ref) => {\n const { id, type, applicability, children, ...rest } = props;\n const slotContext = React.useContext(SlotContext);\n const localRef = React.useRef<ObjectNode>(null);\n const Wrapper = slotContext?.wrapInAsset ? AssetWrapper : React.Fragment;\n\n return (\n <Wrapper\n ref={slotContext?.wrapInAsset ? mergeRefs([ref, localRef]) : undefined}\n {...(slotContext?.wrapInAsset && slotContext?.additionalProperties\n ? slotContext?.additionalProperties\n : {})}\n >\n <OptionalIDSuffixProvider wrapperRef={localRef}>\n <SlotContext.Provider value={undefined}>\n <IDProvider id={id}>\n <obj\n ref={\n slotContext?.wrapInAsset\n ? undefined\n : mergeRefs([ref, localRef])\n }\n >\n <GeneratedIDProperty id={id} />\n <property name=\"type\">{type}</property>\n {applicability !== undefined && (\n <property name=\"applicability\">\n <value\n value={\n typeof applicability === \"boolean\"\n ? applicability\n : applicability.toValue()\n }\n />\n </property>\n )}\n {toJsonProperties(rest)}\n {children}\n </obj>\n </IDProvider>\n </SlotContext.Provider>\n </OptionalIDSuffixProvider>\n </Wrapper>\n );\n});\n\nAsset.displayName = \"Asset\";\n\nAsset.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\nexport const View = React.forwardRef<ObjectNode, AssetProps & ViewType>(\n (props, ref) => {\n const { validation, children, ...rest } = props;\n\n return (\n <Asset ref={ref} {...rest}>\n {validation && (\n <property key=\"validation\" name=\"validation\">\n {toJsonElement(validation, \"validation\", {\n propertiesToSkip: [\"ref\"],\n })}\n </property>\n )}\n {children}\n </Asset>\n );\n }\n);\n\nView.displayName = \"View\";\n\nView.defaultProps = {\n id: undefined,\n children: undefined,\n};\n\n/** A component to generate a named property slot */\nexport const Slot = (props: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** Other properties to add to the slot */\n additionalProperties?: any;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) => {\n const { TextComp, CollectionComp } = props;\n const children = flattenChildren(props.children);\n const propRef = React.useRef<PropertyNode>(null);\n\n return (\n <property ref={propRef} name={props.name}>\n <IDSuffixProvider suffix={props.name}>\n <IndexSuffixStopContext.Provider value={false}>\n <SlotContext.Provider\n value={{\n ref: propRef,\n propertyName: props.name,\n wrapInAsset: props.wrapInAsset ?? false,\n isArray: props.isArray ?? false,\n additionalProperties: props.additionalProperties,\n TextComp,\n CollectionComp,\n }}\n >\n {props.isArray && (\n <array>\n {React.Children.map(children, (child, index) => {\n return (\n // eslint-disable-next-line react/no-array-index-key\n <React.Fragment key={`${props.name}-${index}`}>\n {normalizeText({ node: child, TextComp })}\n </React.Fragment>\n );\n })}\n </array>\n )}\n\n {!props.isArray &&\n normalizeToCollection({\n node: children,\n TextComp,\n CollectionComp,\n })}\n </SlotContext.Provider>\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n </property>\n );\n};\n\n/** Create a slot for a given property */\nexport function createSlot<SlotProps = unknown>(options: {\n /** The name of the slot */\n name: string;\n\n /** if the slot is an array or single object */\n isArray?: boolean;\n\n /** if each item should be wrapped in an asset */\n wrapInAsset?: boolean;\n\n /** Any children to render in the slot */\n children?: React.ReactNode;\n\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n}) {\n // eslint-disable-next-line react/display-name\n return (\n props: {\n /** An object to include in this property */\n children?: React.ReactNode;\n } & SlotProps\n ) => {\n const { children, ...other } = props;\n return (\n <Slot {...options} additionalProperties={other}>\n {children}\n </Slot>\n );\n };\n}\n","import React from \"react\";\nimport type { JsonNode } from \"react-json-reconciler\";\nimport { flattenNodes } from \"react-json-reconciler\";\nimport { SlotContext } from \"./components\";\nimport type { WithChildren } from \"./types\";\n\nconst IDSuffixContext = React.createContext<string>(\"root\");\n\nexport const IndexSuffixStopContext = React.createContext<boolean>(false);\n\n/** Get the generated id */\nexport const useGetIdPrefix = () => {\n return React.useContext(IDSuffixContext);\n};\n\n/** Add a suffix to a generated id */\nexport const IDSuffixProvider = (\n props: WithChildren<{\n /** The suffix to append */\n suffix: string;\n }>\n) => {\n const currentPrefix = useGetIdPrefix();\n\n return (\n <IDSuffixContext.Provider\n value={[\n currentPrefix === \"root\" ? undefined : currentPrefix,\n props.suffix,\n ]\n .filter(Boolean)\n .join(\"-\")}\n >\n {props.children}\n </IDSuffixContext.Provider>\n );\n};\n\n/** Override the generated id with the supplied one */\nexport const IDProvider = (\n props: WithChildren<{\n /** The new id to use */\n id?: string;\n }>\n) => {\n if (props.id) {\n return (\n <IDSuffixContext.Provider value={props.id}>\n {props.children}\n </IDSuffixContext.Provider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n\n/** Get the index of an item in a slot */\nexport const useIndexInSlot = (ref: React.RefObject<JsonNode>) => {\n const [index, setIndex] = React.useState(-1);\n const slotContext = React.useContext(SlotContext);\n\n React.useEffect(() => {\n if (!slotContext?.isArray) {\n throw new Error(\"Cannot get index in non-array slot\");\n }\n\n if (ref.current && slotContext?.ref.current?.valueNode?.type === \"array\") {\n const allChildren = flattenNodes(\n slotContext.ref.current.valueNode.children\n );\n const foundIndex = allChildren.indexOf(ref.current);\n\n if (foundIndex !== index) {\n setIndex(foundIndex);\n }\n }\n }, [index, ref, slotContext?.isArray, slotContext?.ref]);\n\n return index;\n};\n\n/** Add the index to the id path when in an array slot */\nexport const IDSuffixIndexProvider = (\n props: WithChildren<{\n /** The ref to use */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotIndex = useIndexInSlot(props.wrapperRef);\n\n const stopIndex = React.useContext(IndexSuffixStopContext);\n\n if (stopIndex) {\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n }\n\n return (\n <IDSuffixProvider suffix={props.templateIndex ?? String(slotIndex)}>\n <IndexSuffixStopContext.Provider value>\n {props.children}\n </IndexSuffixStopContext.Provider>\n </IDSuffixProvider>\n );\n};\n\n/** Wrap a slot with the index if in an array slot */\nexport const OptionalIDSuffixProvider = (\n props: WithChildren<{\n /** The ref to walk upwards and use as an index */\n wrapperRef: React.RefObject<JsonNode>;\n\n /** if the suffix is in a template, the id to use */\n templateIndex?: string;\n }>\n) => {\n const slotContext = React.useContext(SlotContext);\n\n if (slotContext?.isArray) {\n return (\n <IDSuffixIndexProvider\n wrapperRef={props.wrapperRef}\n templateIndex={props.templateIndex}\n >\n {props.children}\n </IDSuffixIndexProvider>\n );\n }\n\n // eslint-disable-next-line react/jsx-no-useless-fragment\n return <>{props.children}</>;\n};\n","import * as React from \"react\";\nimport {\n isTemplateStringInstance,\n TemplateStringComponent,\n} from \"./string-templates\";\nimport type { toJsonOptions } from \"./types\";\n\n/** Get an array version of the value */\nexport function toArray<T>(val: T | Array<T>): Array<T> {\n return Array.isArray(val) ? val : [val];\n}\n\n/** Create a component version */\nexport function toJsonElement(\n value: any,\n indexOrKey?: number | string,\n options?: toJsonOptions\n): React.ReactElement {\n const indexProp = typeof indexOrKey === \"number\" ? { key: indexOrKey } : null;\n\n if (Array.isArray(value)) {\n return (\n <array {...indexProp}>\n {value.map((item, idx) => toJsonElement(item, idx, options))}\n </array>\n );\n }\n\n /** Allow users to pass in BindingTemplateInstance and ExpressionTemplateInstance directly without turning them into strings first */\n if (isTemplateStringInstance(value)) {\n if (\n typeof indexOrKey === \"string\" &&\n options?.propertiesToSkip?.includes(indexOrKey)\n ) {\n return <value {...indexProp}>{value.toValue()}</value>;\n }\n\n return <value {...indexProp}>{value.toRefString()}</value>;\n }\n\n if (typeof value === \"object\" && value !== null) {\n return (\n <obj {...indexProp}>\n {Object.keys(value).map((key) => (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n ))}\n </obj>\n );\n }\n\n return <value {...indexProp} value={value} />;\n}\n\n/** Create a fragment for the properties */\nexport function toJsonProperties(\n value: Record<string, any>,\n options: toJsonOptions = { propertiesToSkip: [\"applicability\"] }\n) {\n return Object.keys(value).map((key) => {\n return (\n <property key={key} name={key}>\n {toJsonElement(value[key], key, options)}\n </property>\n );\n });\n}\n\n/** Create a text asset if needed */\nexport function normalizeText(options: {\n /** The current node */\n node: React.ReactNode;\n\n /** A component to render a text asset */\n TextComp?: React.ComponentType<any>;\n}): React.ReactNode {\n const { node, TextComp } = options;\n\n const nodeArr = React.Children.toArray(node);\n\n if (\n nodeArr.every(\n (n) => React.isValidElement(n) && n.type !== TemplateStringComponent\n )\n ) {\n return node;\n }\n\n if (TextComp) {\n return <TextComp>{nodeArr}</TextComp>;\n }\n\n throw new Error(\n `Tried to convert node to Text Asset, but no Component was supplied.`\n );\n}\n\n/** Create a collection if needed */\nexport function normalizeToCollection(options: {\n /** the node to look at */\n node: React.ReactNode;\n\n /** A Text asset */\n TextComp?: React.ComponentType;\n\n /** A collection asset */\n CollectionComp?: React.ComponentType<any>;\n}) {\n const { node, CollectionComp } = options;\n\n if (\n React.Children.count(node) > 1 &&\n React.Children.toArray(node).every((n) => typeof n !== \"string\")\n ) {\n if (!CollectionComp) {\n throw new Error(\n `Tried to convert array to a collection asset, but no Component was given.`\n );\n }\n\n return <CollectionComp>{node}</CollectionComp>;\n }\n\n return normalizeText({ ...options, node });\n}\n\ntype ReactChildArray = ReturnType<typeof React.Children.toArray>;\n\n/**\n *\n * Hoisted from https://github.com/gregberge/react-flatten-children/blob/master/src/index.tsx\n * Peer dependencies were wrong and can't be reasonably patch it everywhere\n */\nexport function flattenChildren(children: React.ReactNode): ReactChildArray {\n const childrenArray = React.Children.toArray(children);\n return childrenArray.reduce((flatChildren: ReactChildArray, child) => {\n if ((child as React.ReactElement<any>).type === React.Fragment) {\n return flatChildren.concat(\n flattenChildren((child as React.ReactElement<any>).props.children)\n );\n }\n\n flatChildren.push(child);\n\n return flatChildren;\n }, []);\n}\n/**\n * Hoisted from https://github.com/gregberge/react-merge-refs/blob/main/src/index.tsx\n * Published packages are ESM only or have bad esm distributions causing issues when\n * used in an esm environment\n */\nexport function mergeRefs<T = any>(\n refs: Array<React.MutableRefObject<T> | React.LegacyRef<T> | undefined | null>\n): React.RefCallback<T> {\n return (value) => {\n refs.forEach((ref) => {\n if (typeof ref === \"function\") {\n ref(value);\n } else if (ref != null) {\n (ref as React.MutableRefObject<T | null>).current = value;\n }\n });\n };\n}\n\n/** Generates object reference properties from the provided object */\nexport function getObjectReferences<\n OriginalPropertiesObject extends Record<string, unknown>,\n ReferencesPropertyObject extends Record<string, unknown>\n>(propertiesObject: OriginalPropertiesObject): ReferencesPropertyObject {\n const result: any = {};\n\n for (const itemProp in propertiesObject) {\n if (Object.prototype.hasOwnProperty.call(propertiesObject, itemProp)) {\n const refName = `${itemProp}Ref`;\n result[refName as keyof ReferencesPropertyObject] = { type: itemProp };\n }\n }\n\n return result;\n}\n","import * as React from \"react\";\nimport { parseExpression, isErrorWithLocation } from \"@player-ui/player\";\n\nexport type TemplateInstanceRefStringContext = \"binding\" | \"expression\";\nexport interface TemplateRefStringOptions {\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n}\nexport interface TemplateInstanceRefStringOptions {\n /** The array of strings for the template */\n strings: ReadonlyArray<string>;\n /** the other data that's present in the template */\n other: Array<string | TemplateStringType>;\n\n /** If this template string is inside of another binding or expression */\n nestedContext?: TemplateInstanceRefStringContext;\n\n /** Convert the value to a reference nested in the given context */\n toRefString: (\n options: TemplateRefStringOptions | undefined,\n value: string\n ) => string;\n}\n\nconst OpaqueIdentifier = Symbol(\"TemplateStringType\");\n\nexport type TemplateStringType = React.ReactElement & {\n /** An identifier to show that this is a template type */\n [OpaqueIdentifier]: true;\n /** The value of the template string when in another string */\n toString: () => string;\n /** the raw value of the template string */\n toValue: () => string;\n /** the dereferenced value when used in another */\n toRefString: (options?: TemplateRefStringOptions) => string;\n};\n\nexport type BindingTemplateInstance = TemplateStringType & {\n /** An identifier for a binding instance */\n __type: \"binding\";\n};\n\nexport type ExpressionTemplateInstance = TemplateStringType & {\n /** The identifier for an expression instance */\n __type: \"expression\";\n};\n\n/** A react component for rendering a template string type */\nexport const TemplateStringComponent = (props: {\n /** The string value of the child template string */\n value: string;\n}) => {\n return React.createElement(\n \"value\",\n {\n value: props.value,\n },\n null\n );\n};\n\n/** The generic template string handler */\nconst createTemplateInstance = (\n options: TemplateInstanceRefStringOptions\n): TemplateStringType => {\n const value = options.strings.reduce((sum, next, i) => {\n const element = options.other[i];\n if (typeof element === \"string\") {\n return sum + next + element;\n }\n\n return sum + next + (element?.toRefString(options) ?? \"\");\n }, \"\");\n\n /** Try to parse the expression as valid */\n if (options.nestedContext === \"expression\") {\n try {\n parseExpression(value);\n } catch (e) {\n if (e instanceof Error) {\n let message: string;\n if (isErrorWithLocation(e)) {\n message = `${e} in expression: \\r\\n ${\n value.slice(0, e.index + 1) + \"\\u2588\" + value.slice(e.index + 1)\n }`;\n } else {\n message = `${e} in expression ${value}`;\n }\n throw new Error(message);\n }\n\n throw new Error(`Unknown problem parsing expression ${e}`);\n }\n }\n\n /** get the unwrapped version */\n const toString = () => {\n return options.toRefString({}, value);\n };\n\n /** get the raw value of the template */\n const toValue = () => {\n return value;\n };\n\n /** This lets us use it directly as a child element in React */\n const element = React.createElement(\n TemplateStringComponent,\n {\n value: toString(),\n },\n null\n ) as TemplateStringType;\n\n return {\n ...element,\n [OpaqueIdentifier]: true,\n toString,\n toValue,\n toRefString: (refStringOptions?: TemplateRefStringOptions) => {\n return options.toRefString(refStringOptions, value);\n },\n };\n};\n\n/** Helper for Iterating the binding to add a dynamic numeric value to each index found */\nconst addBindingIndexes = (binding: string): string => {\n let currentIndex = 0;\n\n return binding.replace(/_index_/g, () => {\n const result = `_index${currentIndex > 0 ? currentIndex : \"\"}_`;\n currentIndex += 1;\n\n return result;\n });\n};\n\n/** Creating an instance of a handler for bindings */\nconst createBindingTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n): BindingTemplateInstance => {\n const templateInstance = createTemplateInstance({\n ...options,\n strings: options.strings.map((element: string) =>\n addBindingIndexes(element)\n ),\n other: options.other.map((element) =>\n typeof element === \"string\" ? addBindingIndexes(element) : element\n ),\n toRefString: (context, value) => {\n return `{{${value}}}`;\n },\n }) as BindingTemplateInstance;\n\n templateInstance.__type = \"binding\";\n\n return templateInstance;\n};\n\n/** Creating an instance of a handler for bindings */\nconst createExpressionTemplateInstance = (\n options: Omit<TemplateInstanceRefStringOptions, \"toRefString\">\n) => {\n const templateInstance = createTemplateInstance({\n ...options,\n toRefString: (contextOptions, value) => {\n if (contextOptions?.nestedContext === \"expression\") {\n return value;\n }\n\n const inBinding = contextOptions?.nestedContext === \"binding\";\n return `${inBinding ? \"`\" : \"@[\"}${value}${inBinding ? \"`\" : \"]@\"}`;\n },\n }) as ExpressionTemplateInstance;\n\n templateInstance.__type = \"expression\";\n\n return templateInstance;\n};\n\n/** A tagged-template constructor for a binding */\nexport const binding = (\n strings: TemplateStringsArray,\n ...nested: Array<TemplateStringType | string>\n): BindingTemplateInstance => {\n return createBindingTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"binding\",\n });\n};\n\n/** A tagged-template constructor for an expression */\nexport const expression = (\n strings: TemplateStringsArray,\n ...nested: Array<\n ExpressionTemplateInstance | BindingTemplateInstance | string\n >\n): ExpressionTemplateInstance => {\n return createExpressionTemplateInstance({\n strings,\n other: nested,\n nestedContext: \"expression\",\n });\n};\n\n/** Check if a value is a template string */\nexport const isTemplateStringInstance = (\n val: unknown\n): val is ExpressionTemplateInstance | BindingTemplateInstance => {\n return (\n val !== null &&\n typeof val === \"object\" &&\n (val as any)[OpaqueIdentifier] === true\n );\n};\n","import type { PropsWithChildren } from \"react\";\nimport React from \"react\";\nimport type { ArrayNode, JsonNode, ObjectNode } from \"react-json-reconciler\";\nimport { flattenNodes, PropertyNode } from \"react-json-reconciler\";\nimport { SlotContext } from \".\";\nimport { IDSuffixProvider, OptionalIDSuffixProvider } from \"./auto-id\";\nimport type {\n BindingTemplateInstance,\n ExpressionTemplateInstance,\n} from \"./string-templates\";\nimport { isTemplateStringInstance } from \"./string-templates\";\nimport { normalizeToCollection, toJsonProperties } from \"./utils\";\n\nexport interface SwitchProps {\n /** defaults to a staticSwitch */\n isDynamic?: boolean;\n}\n\nconst SwitchContext = React.createContext<\n SwitchProps & {\n /** A text component if we hit a string but expect an asset */\n TextComp?: React.ComponentType;\n\n /** A component to create a collection asset is we get an array but need a single element */\n CollectionComp?: React.ComponentType;\n }\n>({});\n\n/**\n * Switches allow users to fork content between 1 or more assets\n */\nexport const Switch = (props: PropsWithChildren<SwitchProps>) => {\n const slotContext = React.useContext(SlotContext);\n const propertyNode = React.useRef<ObjectNode>(null);\n\n return (\n <obj ref={propertyNode}>\n <SwitchContext.Provider\n value={{\n ...props,\n TextComp: slotContext?.TextComp,\n CollectionComp: slotContext?.CollectionComp,\n }}\n >\n <OptionalIDSuffixProvider wrapperRef={propertyNode}>\n <property name={props.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"}>\n <SlotContext.Provider value={undefined}>\n <array>{props.children}</array>\n </SlotContext.Provider>\n </property>\n </OptionalIDSuffixProvider>\n </SwitchContext.Provider>\n {slotContext?.additionalProperties &&\n toJsonProperties(slotContext.additionalProperties)}\n </obj>\n );\n};\n\nexport interface CaseProps {\n /** the test for this case statement */\n exp?: ExpressionTemplateInstance | BindingTemplateInstance | boolean;\n}\n\n/** Find the first parent array */\nconst findParentArray = (node: JsonNode): ArrayNode => {\n if (node.type === \"array\") {\n return node;\n }\n\n if (node.parent) {\n return findParentArray(node.parent);\n }\n\n throw new Error(\"can't find parent array\");\n};\n\n/** Find the index of the item in an array */\nconst findArrayIndex = (node: JsonNode): number => {\n const parentArray = findParentArray(node);\n const allSearch = flattenNodes(parentArray.children);\n return allSearch.indexOf(node);\n};\n\n/** A case for a switch */\nconst Case = (props: PropsWithChildren<CaseProps>) => {\n const slotContext = React.useContext(SlotContext);\n const switchContext = React.useContext(SwitchContext);\n const [caseIndex, setCaseIndex] = React.useState(-1);\n const caseNode = React.useRef<ObjectNode>(null);\n\n React.useLayoutEffect(() => {\n if (caseNode.current) {\n const index = findArrayIndex(caseNode.current);\n if (index !== caseIndex) {\n setCaseIndex(index);\n }\n }\n }, [caseIndex]);\n\n let expValue: string | boolean = true;\n\n if (props.exp !== undefined) {\n expValue = isTemplateStringInstance(props.exp)\n ? props.exp.toValue()\n : props.exp;\n }\n\n return (\n <obj ref={caseNode}>\n <property name=\"case\">\n <value value={expValue} />\n </property>\n <IDSuffixProvider\n suffix={`${\n switchContext.isDynamic ? \"dynamicSwitch\" : \"staticSwitch\"\n }-${caseIndex}`}\n >\n <SlotContext.Provider\n value={\n slotContext ? { ...slotContext, wrapInAsset: false } : undefined\n }\n >\n <property name=\"asset\">\n {normalizeToCollection({\n node: props.children,\n TextComp: switchContext?.TextComp,\n CollectionComp: switchContext?.CollectionComp,\n })}\n </property>\n </SlotContext.Provider>\n </IDSuffixProvider>\n </obj>\n );\n};\n\nSwitch.Case = Case;\n","import React from \"react\";\nimport type { ObjectNode, JsonNode } from \"react-json-reconciler\";\nimport {\n ArrayNode,\n PropertyNode,\n ValueNode,\n createPortal,\n ProxyNode,\n toJSON,\n} from \"react-json-reconciler\";\nimport { OptionalIDSuffixProvider } from \"./auto-id\";\nimport type { BindingTemplateInstance } from \"./string-templates\";\nimport type { WithChildren } from \"./types\";\nimport { toJsonElement } from \"./utils\";\n\nexport interface TemplateContextType {\n /** The number of nested templates */\n depth: number;\n}\n\nexport const TemplateContext = React.createContext<TemplateContextType>({\n depth: 0,\n});\n\nexport interface TemplateProps {\n /** The source binding */\n data: BindingTemplateInstance;\n\n /** The target property */\n output?: string;\n\n /** The template value */\n children: React.ReactNode;\n\n /** boolean that specifies whether template should recompute when data changes */\n dynamic?: boolean;\n}\n\n/** Add a template instance to the object */\nfunction addTemplateToObject(\n obj: ObjectNode,\n templateObj: ObjectNode,\n templateParentNodeType: string\n): () => void {\n // find a template property\n // add one if none exists\n\n let templateProp = obj.properties.find(\n (p) => p.keyNode.value === \"template\" && p.valueNode?.type === \"array\"\n );\n\n if (!templateProp) {\n templateProp = new PropertyNode(new ValueNode(\"template\"), new ArrayNode());\n templateProp.parent = obj;\n obj.properties.push(templateProp);\n }\n\n const templateItems = templateProp.valueNode as ArrayNode;\n\n templateItems.items.push(templateObj);\n // eslint-disable-next-line no-param-reassign\n templateObj.parent = templateItems;\n\n const templateParentProp = obj.properties.find(\n (p) =>\n p.keyNode.value === templateParentNodeType &&\n p.valueNode?.type === \"array\"\n );\n\n if (templateParentProp) {\n const indexOfTemplateParent = obj.properties.indexOf(templateParentProp, 1);\n const templateParentValueNode =\n obj.properties[indexOfTemplateParent]?.valueNode;\n if (templateParentValueNode) {\n const templateParentArray = toJSON(templateParentValueNode);\n\n // Delete the parent of template if it is an empty array\n if (\n Array.isArray(templateParentArray) &&\n templateParentArray.length === 0\n ) {\n obj.properties.splice(indexOfTemplateParent, 1);\n }\n }\n }\n\n return () => {\n // Remove the template item from the list\n templateItems.items = templateItems.items.filter((t) => t !== templateObj);\n\n // Clean up the whole template if it's removed\n if (templateItems.children.length === 0 && templateProp) {\n obj.properties.splice(obj.properties.indexOf(templateProp, 1));\n }\n };\n}\n\n/** Context provider wrapper to handle nested templates */\nconst TemplateProvider = (props: WithChildren) => {\n const baseContext = React.useContext(TemplateContext);\n\n return (\n <TemplateContext.Provider value={{ depth: baseContext.depth + 1 }}>\n {props.children}\n </TemplateContext.Provider>\n );\n};\n\n/** Find the first object node in the tree */\nconst getParentObject = (node: JsonNode): ObjectNode | undefined => {\n if (node.type === \"object\") {\n return node;\n }\n\n if (node.parent) {\n return getParentObject(node.parent);\n }\n};\n\n/** Find the property of the node on the parent */\nconst getParentProperty = (node: JsonNode): PropertyNode | undefined => {\n if (node.type === \"property\") {\n return node;\n }\n\n if (node.parent) {\n return getParentProperty(node.parent);\n }\n};\n\n/** A template allows users to dynamically map over an array of data */\nexport const Template = (props: TemplateProps) => {\n const baseContext = React.useContext(TemplateContext);\n const dynamicProp = props.dynamic ?? false;\n const [outputProp, setOutputProp] = React.useState<string | undefined>(\n props.output\n );\n const proxyRef = React.useRef<ProxyNode>(null);\n const valueRef = React.useRef<ValueNode>(null);\n const outputElement = React.useMemo(() => new ProxyNode(), []);\n\n React.useLayoutEffect(() => {\n // Get the output prop\n const propNode = proxyRef.current && getParentProperty(proxyRef.current);\n\n if (outputProp === undefined && propNode) {\n setOutputProp(propNode.keyNode.value);\n }\n }, [proxyRef, outputProp]);\n\n React.useEffect(() => {\n const templateObj = outputElement.items[0] as ObjectNode;\n if (proxyRef.current) {\n const parentObject = getParentObject(proxyRef.current);\n\n if (!parentObject) {\n throw new Error(\"Unable to find parent to add template to\");\n }\n\n if (!outputProp) {\n return;\n }\n\n // remove the template when unmounted\n return addTemplateToObject(parentObject, templateObj, outputProp);\n }\n }, [proxyRef, outputProp, outputElement.items]);\n\n return (\n <proxy ref={proxyRef}>\n <>\n {createPortal(\n <OptionalIDSuffixProvider\n wrapperRef={valueRef}\n templateIndex={`_index${\n baseContext.depth === 0 ? \"\" : baseContext.depth\n }_`}\n >\n <TemplateProvider>\n <object>\n <property name=\"data\">{props.data.toValue()}</property>\n <property name=\"output\">{outputProp}</property>\n <property name=\"value\">{props.children}</property>\n {dynamicProp && (\n <property name=\"dynamic\">\n {toJsonElement(dynamicProp)}\n </property>\n )}\n </object>\n </TemplateProvider>\n </OptionalIDSuffixProvider>,\n outputElement\n )}\n <value ref={valueRef} value={undefined} />\n </>\n </proxy>\n );\n};\n","export * from \"./components\";\nexport * from \"./auto-id\";\nexport * from \"./types\";\nexport * from \"./string-templates\";\nexport * from \"./utils\";\nexport * from \"./switch\";\nexport * from \"./template\";\nexport * from \"react-json-reconciler\";\nexport * from \"./compiler/schema\";\nexport * from \"./compiler\";\nexport * from \"./compiler/types\";\n","import type { Schema, Language } from \"@player-ui/types\";\nimport { dequal } from \"dequal\";\nimport { SyncWaterfallHook } from \"tapable-ts\";\nimport type { LoggingInterface } from \"..\";\nimport { binding as b } from \"..\";\nimport type { BindingTemplateInstance } from \"../string-templates\";\n\nconst bindingSymbol = Symbol(\"binding\");\n\n/** Symbol to indicate that a schema node should be generated with a different name */\nexport const SchemaTypeName = Symbol(\"Schema Rename\");\n\ninterface SchemaChildren {\n /** Object property that will be used to create the intermediate type */\n name: string;\n\n /** Object properties children that will be parsed */\n child: object;\n}\n\ntype SchemaNode = (Schema.DataType | Language.DataTypeRef) & {\n /** Overwrite the name of the generated type */\n [SchemaTypeName]?: string;\n};\n\ninterface GeneratedDataType {\n /** The SchemaNode that was generated */\n node: SchemaNode;\n /** How many times it has been generated */\n count: number;\n}\n\n/**\n * Type Guard for the `Schema.DataType` and `Language.DataTypeRef` type\n * A bit hacky but since `Schema.Schema` must have a `Schema.DataType` as\n * the final product we have to call it that even if it is a `Language.DataTypeRef`\n */\nconst isTypeDef = (property: SchemaNode): property is Schema.DataType => {\n return (property as Schema.DataType).type !== undefined;\n};\n\n/**\n * Generator for `Schema.Schema` Objects\n */\nexport class SchemaGenerator {\n private children: Array<SchemaChildren>;\n private generatedDataTypes: Map<string, GeneratedDataType>;\n private logger: LoggingInterface;\n\n public hooks = {\n createSchemaNode: new SyncWaterfallHook<\n [\n node: Schema.DataType,\n originalProperty: Record<string | symbol, unknown>\n ]\n >(),\n };\n\n constructor(logger?: LoggingInterface) {\n this.children = [];\n this.generatedDataTypes = new Map();\n this.logger = logger ?? console;\n }\n\n /**\n * Converts an object to a `Schema.Schema` representation\n * Note: uses iteration to prevent potentially very deep recursion on large objects\n */\n public toSchema = (schema: any): Schema.Schema => {\n const newSchema: Schema.Schema = {\n ROOT: {},\n };\n\n this.children = [];\n this.generatedDataTypes.clear();\n\n Object.keys(schema).forEach((property) => {\n const subType = schema[property] as SchemaNode;\n newSchema.ROOT[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n\n while (this.children.length > 0) {\n const c = this.children.pop();\n if (c === undefined) {\n break;\n }\n\n const { name, child } = c;\n const typeDef = {} as any;\n\n Object.keys(child).forEach((property) => {\n const subType = (child as any)[property] as SchemaNode;\n typeDef[property] = this.hooks.createSchemaNode.call(\n this.processChild(property, subType),\n subType as any\n );\n });\n newSchema[name] = typeDef;\n }\n\n return newSchema;\n };\n\n /**\n * Processes the children of an object Node\n * Newly discovered children get added to the provided array\n */\n private processChild(property: string, subType: SchemaNode): Schema.DataType {\n if (isTypeDef(subType)) {\n return subType;\n }\n\n let intermediateType;\n let child;\n\n if (Array.isArray(subType)) {\n if (subType.length > 1) {\n this.logger.warn(\n `Type ${property} has multiple types in array, should only contain one top level object type. Only taking first defined type`\n );\n }\n\n const subTypeName = subType[0][SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderArrayType(subTypeName);\n [child] = subType;\n } else {\n const subTypeName = subType[SchemaTypeName] ?? property;\n intermediateType = this.makePlaceholderType(subTypeName);\n child = subType;\n }\n\n this.children.push({ name: intermediateType.type, child });\n\n if (this.generatedDataTypes.has(intermediateType.type)) {\n const generatedType = this.generatedDataTypes.get(\n intermediateType.type\n ) as GeneratedDataType;\n if (\n !dequal(\n child,\n this.generatedDataTypes.get(intermediateType.type)?.node as object\n )\n ) {\n generatedType.count += 1;\n const newIntermediateType = {\n ...intermediateType,\n type: `${intermediateType.type}${generatedType.count}`,\n };\n this.logger.warn(\n `WARNING: Generated two intermediate types with the name: ${intermediateType.type} that are of different shapes, using artificial type ${newIntermediateType.type}`\n );\n intermediateType = newIntermediateType;\n this.children.pop();\n this.children.push({ name: intermediateType.type, child });\n }\n }\n\n this.generatedDataTypes.set(intermediateType.type, {\n node: subType,\n count: 1,\n });\n return intermediateType;\n }\n\n /**\n * Make an intermediate `Schema.DataType` object given a name\n */\n private makePlaceholderType = (typeName: string): Schema.DataType => {\n return {\n type: `${typeName}Type`,\n };\n };\n\n /**\n * Make an intermediate `Schema.DataType` object with array support given a name\n */\n private makePlaceholderArrayType(typeName: string): Schema.DataType {\n return {\n type: `${typeName}Type`,\n isArray: true,\n };\n }\n}\n\nexport type MakeArrayIntoIndexRef<T extends any[]> = {\n [key: number]: MakeBindingRefable<T[0]>;\n /** Used when referencing bindings from within a template */\n _index_: MakeBindingRefable<T[0]>;\n} & BindingTemplateInstance;\n\nexport type MakeBindingRefable<T> = {\n [P in keyof T]: T[P] extends object[]\n ? MakeArrayIntoIndexRef<T[P]>\n : T[P] extends unknown[]\n ? T[P]\n : MakeBindingRefable<T[P]>;\n} & BindingTemplateInstance;\n\n/**\n * Adds bindings to an object so that the object can be directly used in JSX\n */\nexport function makeBindingsForObject<Type>(\n obj: Type,\n arrayAccessorKeys = [\"_index_\"]\n): MakeBindingRefable<Type> {\n /** Proxy to track binding callbacks */\n const accessor = (paths: string[]) => {\n const bindingMap = new WeakMap<any, BindingTemplateInstance>();\n\n return {\n ownKeys(target: any) {\n return Reflect.ownKeys(target);\n },\n\n get(target: any, key: any): any {\n const bindingKeys = Object.keys(target);\n\n // If there is an array of primitives, just return a copy of that array\n if (\n Array.isArray(target[key]) &&\n target[key].length > 0 &&\n target[key].every((it: any) => typeof it !== \"object\")\n ) {\n return [...target[key]];\n }\n\n if (!bindingMap.has(target)) {\n bindingMap.set(target, b`${paths.join(\".\")}`);\n }\n\n if (key === bindingSymbol) {\n return paths;\n }\n\n if (\n Array.isArray(target) &&\n (arrayAccessorKeys.includes(key) || typeof key === \"number\")\n ) {\n return new Proxy(target[0], accessor(paths.concat([key])));\n }\n\n if (bindingKeys.includes(key) && typeof target[key] === \"object\") {\n return new Proxy(target[key], accessor(paths.concat([key])));\n }\n\n const createdInstance = bindingMap.get(target) as any;\n return createdInstance?.[key];\n },\n };\n };\n\n return new Proxy(obj, accessor([])) as MakeBindingRefable<Type>;\n}\n\n/**\n * Generates binding for an object property\n */\nexport const getBindingFromObject = (obj: any) => {\n const baseBindings = obj[bindingSymbol] as string[];\n if (!Array.isArray(baseBindings) || baseBindings.length === 0) {\n throw new Error(`Unable to get binding for ${obj}`);\n }\n\n return b`${baseBindings.join(\".\")}`;\n};\n\n/**\n * Returns the binding string from an object path\n */\nexport const getBindingStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toString();\n};\n\n/**\n * Returns the ref string from an object path\n */\nexport const getRefStringFromObject = (obj: any) => {\n return getBindingFromObject(obj).toRefString();\n};\n","import React from \"react\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport { SourceMapGenerator, SourceMapConsumer } from \"source-map-js\";\nimport { render } from \"react-json-reconciler\";\nimport type { Flow, View, Navigation as PlayerNav } from \"@player-ui/types\";\nimport {\n AsyncSeriesHook,\n AsyncSeriesWaterfallHook,\n SyncHook,\n} from \"tapable-ts\";\nimport { fingerprintContent } from \"./utils\";\nimport type {\n LoggingInterface,\n CompilerReturn,\n SerializeContext,\n} from \"./types\";\nimport type { Navigation } from \"../types\";\nimport { SchemaGenerator } from \"./schema\";\n\n/**\n * Argument passed to the DSLCompiler onEnd hook\n * Defined as an object so additional fields can be added later without breaking API\n * */\nexport interface OnEndArg {\n /** target output directory **/\n output: string;\n}\n\n/** Recursively find BindingTemplateInstance and call toValue on them */\nconst parseNavigationExpressions = (nav: Navigation): PlayerNav => {\n /** Same as above but signature changed */\n function replaceExpWithStr(obj: any): any {\n /** call toValue if BindingTemplateInstance otherwise continue */\n function convExp(value: any): any {\n return value && typeof value === \"object\" && value.__type === \"expression\"\n ? value.toValue() // exp, onStart, and onEnd don't need to be wrapped in @[]@\n : replaceExpWithStr(value);\n }\n\n if (Array.isArray(obj)) {\n return obj.map(convExp);\n }\n\n if (typeof obj === \"object\") {\n const copy = { ...obj };\n for (const [key, value] of Object.entries(copy)) {\n copy[key] = convExp(value);\n }\n\n return copy;\n }\n\n return obj;\n }\n\n return replaceExpWithStr(nav);\n};\n\ntype SourceMapList = Array<{\n /** The mappings of the original */\n sourceMap: string;\n /**\n * The id of the view we're indexing off of\n * This should be a unique global identifier within the generated code\n * e.g. `\"id\": \"view_0\",`\n */\n offsetIndexSearch: string;\n /** The generated source that produced the map */\n source: string;\n}>;\n\n/** Given a list of source maps for all generated views, merge them into 1 */\nconst mergeSourceMaps = (\n sourceMaps: SourceMapList,\n generated: string\n): string => {\n const generator = new SourceMapGenerator();\n sourceMaps.forEach(({ sourceMap, offsetIndexSearch, source }) => {\n const generatedLineOffset = generated\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const sourceLineOffset = source\n .split(\"\\n\")\n .findIndex((line) => line.includes(offsetIndexSearch));\n\n const lineOffset = generatedLineOffset - sourceLineOffset;\n\n const generatedLine = generated.split(\"\\n\")[generatedLineOffset];\n const sourceLine = source.split(\"\\n\")[sourceLineOffset];\n\n const generatedColumn = generatedLine.indexOf(offsetIndexSearch);\n const sourceColumn = sourceLine.indexOf(offsetIndexSearch);\n const columnOffset = generatedColumn - sourceColumn;\n\n const consumer = new SourceMapConsumer(JSON.parse(sourceMap));\n consumer.eachMapping((mapping) => {\n generator.addMapping({\n generated: {\n line: mapping.generatedLine + lineOffset,\n column: mapping.generatedColumn + columnOffset,\n },\n original: {\n line: mapping.originalLine,\n column: mapping.originalColumn,\n },\n source: mapping.source,\n });\n });\n });\n\n return generator.toString();\n};\n\n/** A compiler for transforming DSL content into JSON */\nexport class DSLCompiler {\n public readonly logger: LoggingInterface;\n public hooks = {\n // Hook to access the schema generator instance when initialized\n schemaGenerator: new SyncHook<[SchemaGenerator]>(),\n // Hook to access pre-compilation object\n preProcessFlow: new AsyncSeriesWaterfallHook<[object]>(),\n // Hook to access post-compilation Flow before output is written\n postProcessFlow: new AsyncSeriesWaterfallHook<[Flow]>(),\n // Hook called after all files are compiled. Revives the output directory\n onEnd: new AsyncSeriesHook<[OnEndArg]>(),\n };\n\n private schemaGenerator?: SchemaGenerator;\n\n constructor(logger?: LoggingInterface) {\n this.logger = logger ?? console;\n }\n\n /** Convert an object (flow, view, schema, etc) into it's JSON representation */\n async serialize(\n value: unknown,\n context?: SerializeContext\n ): Promise<CompilerReturn> {\n if (typeof value !== \"object\" || value === null) {\n throw new Error(\"Unable to serialize non-object\");\n }\n\n const type = context?.type ? context.type : fingerprintContent(value);\n\n if (!this.schemaGenerator) {\n this.schemaGenerator = new SchemaGenerator(this.logger);\n this.hooks.schemaGenerator.call(this.schemaGenerator);\n }\n\n if (type === \"view\") {\n const { jsonValue, sourceMap } = await render(value as any, {\n collectSourceMap: true,\n });\n\n return {\n value: jsonValue,\n sourceMap,\n };\n }\n\n if (type === \"flow\") {\n // Source maps from all the nested views\n // Merge these together before returning\n const allSourceMaps: SourceMapList = [];\n\n // Assume this is a flow\n const copiedValue: Flow = {\n ...(value as any),\n };\n\n copiedValue.views = (await Promise.all(\n copiedValue?.views?.map(async (node: any) => {\n if (React.isValidElement(node)) {\n const { jsonValue, sourceMap, stringValue } = await render(node, {\n collectSourceMap: true,\n });\n\n if (sourceMap) {\n // Find the line that is the id of the view\n // Use that as the identifier for the sourcemap offset calc\n const searchIdLine = stringValue\n .split(\"\\n\")\n .find((line) =>\n line.includes(\n `\"id\": \"${(jsonValue as Record<string, string>).id}\"`\n )\n );\n\n if (searchIdLine) {\n allSourceMaps.push({\n sourceMap,\n offsetIndexSearch: searchIdLine,\n source: stringValue,\n });\n }\n }\n\n return jsonValue;\n }\n\n return node;\n }) ?? []\n )) as View[];\n\n // Go through the flow and sub out any view refs that are react elements w/ the right id\n if (\"navigation\" in value) {\n Object.entries((value as Flow).navigation).forEach(([navKey, node]) => {\n if (typeof node === \"object\") {\n Object.entries(node).forEach(([nodeKey, flowNode]) => {\n if (\n flowNode &&\n typeof flowNode === \"object\" &&\n \"state_type\" in flowNode &&\n flowNode.state_type === \"VIEW\" &&\n React.isValidElement(flowNode.ref)\n ) {\n const actualViewIndex = (value as Flow).views?.indexOf?.(\n flowNode.ref as any\n );\n\n if (actualViewIndex !== undefined && actualViewIndex > -1) {\n const actualId = copiedValue.views?.[actualViewIndex]?.id;\n\n (copiedValue as any).navigation[navKey][nodeKey].ref =\n actualId;\n }\n }\n });\n }\n });\n }\n\n if (\"schema\" in copiedValue) {\n copiedValue.schema = this.schemaGenerator.toSchema(copiedValue.schema);\n }\n\n copiedValue.navigation = parseNavigationExpressions(\n copiedValue.navigation\n );\n\n if (value) {\n const postProcessFlow = await this.hooks.postProcessFlow.call(\n copiedValue\n );\n\n return {\n value: postProcessFlow as JsonType,\n sourceMap: mergeSourceMaps(\n allSourceMaps,\n JSON.stringify(copiedValue, null, 2)\n ),\n };\n }\n }\n\n // Type has been set to \"schema\"\n return {\n value: this.schemaGenerator.toSchema(value) as JsonType,\n };\n }\n}\n","import React from \"react\";\nimport type { DefaultCompilerContentType } from \"./types\";\n\n/** Basic way of identifying the type of file based on the default content export */\nexport const fingerprintContent = (\n content: unknown,\n filename?: string\n): DefaultCompilerContentType | undefined => {\n if (content !== null || content !== undefined) {\n if (React.isValidElement(content as any)) {\n return \"view\";\n }\n\n if (typeof content === \"object\" && \"navigation\" in (content as any)) {\n return \"flow\";\n }\n\n if (!filename || filename.includes(\"schema\")) {\n return \"schema\";\n }\n }\n};\n","import type {\n Schema,\n Navigation,\n Flow,\n Expression,\n ExpressionObject,\n NavigationFlow,\n NavigationFlowState,\n NavigationFlowViewState,\n} from \"@player-ui/types\";\nimport type { JsonType } from \"react-json-reconciler\";\nimport type { RemoveUnknownIndex, AddUnknownIndex } from \"../types\";\nimport type { DSLSchema } from \"../types\";\n\nexport type NavigationFlowReactViewState = Omit<\n NavigationFlowViewState,\n \"ref\"\n> & {\n /** The view element */\n ref: React.ReactElement | string;\n};\n\nexport type NavFlowState =\n | Exclude<NavigationFlowState, NavigationFlowViewState>\n | NavigationFlowReactViewState;\n\nexport type NavigationFlowWithReactView = Pick<\n NavigationFlow,\n \"startState\" | \"onStart\" | \"onEnd\"\n> & {\n [key: string]:\n | undefined\n | string\n | Expression\n | ExpressionObject\n | NavFlowState;\n};\n\nexport type NavigationWithReactViews = Pick<Navigation, \"BEGIN\"> &\n Record<string, string | NavigationFlowWithReactView>;\n\nexport type FlowWithoutUnknown = RemoveUnknownIndex<Flow>;\nexport type FlowWithReactViews = AddUnknownIndex<\n Omit<FlowWithoutUnknown, \"views\" | \"navigation\"> & {\n /** An array of JSX view elements */\n views?: Array<React.ReactElement>;\n\n /** The navigation element */\n navigation?: NavigationWithReactViews;\n }\n>;\n\nexport type DSLFlow = Omit<FlowWithReactViews, \"schema\"> & {\n /** A DSL compliant schema */\n schema?: DSLSchema;\n};\n\nexport type SerializeType = \"view\" | \"flow\" | \"schema\" | \"navigation\";\n\nexport type SerializablePlayerExportTypes =\n | React.ReactElement\n | FlowWithReactViews\n | Schema.Schema\n | Navigation;\n\nexport type LoggingInterface = Pick<Console, \"warn\" | \"error\" | \"log\">;\n\nexport type CompilationResult = {\n /** What type of file is generated */\n contentType: string;\n /** The output path */\n outputFile: string;\n /** the input file */\n inputFile: string;\n};\n\nexport type CompilerReturn = {\n /** the JSON value of the source */\n value: JsonType | undefined;\n\n /** The sourcemap of the content */\n sourceMap?: string;\n};\n\n/** The different type of default content items the compiler handles */\nconst DefaultCompilerContentTypes = [\"view\", \"flow\", \"schema\"] as const;\n\nexport type DefaultCompilerContentType =\n (typeof DefaultCompilerContentTypes)[number];\n\n/** Helper function to determine whether a content type is compiler default */\nexport function isDefaultCompilerContentType(\n t: string\n): t is DefaultCompilerContentType {\n return DefaultCompilerContentTypes.includes(t as DefaultCompilerContentType);\n}\n\nexport interface SerializeContext {\n /** The type of the content being compiled */\n type: DefaultCompilerContentType;\n}\n"],"mappings":";AAAA,OAAOA,YAAW;;;ACAlB,OAAO,WAAW;AAElB,SAAS,oBAAoB;AAI7B,IAAM,kBAAkB,MAAM,cAAsB,MAAM;AAEnD,IAAM,yBAAyB,MAAM,cAAuB,KAAK;AAGjE,IAAM,iBAAiB,MAAM;AAClC,SAAO,MAAM,WAAW,eAAe;AACzC;AAGO,IAAM,mBAAmB,CAC9B,UAIG;AACH,QAAM,gBAAgB,eAAe;AAErC,SACE;AAAA,IAAC,gBAAgB;AAAA,IAAhB;AAAA,MACC,OAAO;AAAA,QACL,kBAAkB,SAAS,SAAY;AAAA,QACvC,MAAM;AAAA,MACR,EACG,OAAO,OAAO,EACd,KAAK,GAAG;AAAA;AAAA,IAEV,MAAM;AAAA,EACT;AAEJ;AAGO,IAAM,aAAa,CACxB,UAIG;AACH,MAAI,MAAM,IAAI;AACZ,WACE,oCAAC,gBAAgB,UAAhB,EAAyB,OAAO,MAAM,MACpC,MAAM,QACT;AAAA,EAEJ;AAGA,SAAO,0DAAG,MAAM,QAAS;AAC3B;AAGO,IAAM,iBAAiB,CAAC,QAAmC;AAChE,QAAM,CAAC,OAAO,QAAQ,IAAI,MAAM,SAAS,EAAE;AAC3C,QAAM,cAAc,MAAM,WAAW,WAAW;AAEhD,QAAM,UAAU,MAAM;AACpB,QAAI,CAAC,aAAa,SAAS;AACzB,YAAM,IAAI,MAAM,oCAAoC;AAAA,IACtD;AAEA,QAAI,IAAI,WAAW,aAAa,IAAI,SAAS,WAAW,SAAS,SAAS;AACxE,YAAM,cAAc;AAAA,QAClB,YAAY,IAAI,QAAQ,UAAU;AAAA,MACpC;AACA,YAAM,aAAa,YAAY,QAAQ,IAAI,OAAO;AAElD,UAAI,eAAe,OAAO;AACxB,iBAAS,UAAU;AAAA,MACrB;AAAA,IACF;AAAA,EAC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AAAA,gBACX;AAEA,oBAAI,oBAAoB,UAAa,kBAAkB,IAAI;AACzD,wBAAM,WAAW,YAAY,QAAQ,eAAe,GAAG;AAEvD,kBAAC,YAAoB,WAAW,MAAM,EAAE,OAAO,EAAE,MAC/C;AAAA,gBACJ;AAAA,cACF;AAAA,YACF,CAAC;AAAA,UACH;AAAA,QACF,CAAC;AAAA,MACH;AAEA,UAAI,YAAY,aAAa;AAC3B,oBAAY,SAAS,KAAK,gBAAgB,SAAS,YAAY,MAAM;AAAA,MACvE;AAEA,kBAAY,aAAa;AAAA,QACvB,YAAY;AAAA,MACd;AAEA,UAAI,OAAO;AACT,cAAM,kBAAkB,MAAM,KAAK,MAAM,gBAAgB;AAAA,UACvD;AAAA,QACF;AAEA,eAAO;AAAA,UACL,OAAO;AAAA,UACP,WAAW;AAAA,YACT;AAAA,YACA,KAAK,UAAU,aAAa,MAAM,CAAC;AAAA,UACrC;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO;AAAA,MACL,OAAO,KAAK,gBAAgB,SAAS,KAAK;AAAA,IAC5C;AAAA,EACF;AACF;;;AEhLA,IAAM,8BAA8B,CAAC,QAAQ,QAAQ,QAAQ;AAMtD,SAAS,6BACd,GACiC;AACjC,SAAO,4BAA4B,SAAS,CAA+B;AAC7E;","names":["React","React","React","element","binding","React","AssetWrapper","React","flattenNodes","React","flattenNodes","React","PropertyNode","React","PropertyNode","React","React","React"]}
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@player-tools/dsl",
3
- "version": "0.5.2-next.1",
3
+ "version": "0.5.2",
4
4
  "main": "dist/cjs/index.cjs",
5
5
  "module": "dist/index.legacy-esm.js",
6
6
  "types": "types/index.d.ts",
7
7
  "sideEffects": false,
8
8
  "exports": {
9
9
  "./package.json": "./package.json",
10
+ "./dist/index.css": "./dist/index.css",
10
11
  ".": {
11
12
  "types": "./types/index.d.ts",
12
13
  "import": "./dist/index.mjs",
@@ -19,8 +20,8 @@
19
20
  "types"
20
21
  ],
21
22
  "dependencies": {
22
- "@player-ui/player": "0.7.1-next.0",
23
- "@player-ui/types": "0.7.1-next.0",
23
+ "@player-ui/player": "0.7.2-next.4",
24
+ "@player-ui/types": "0.7.2-next.4",
24
25
  "@types/mkdirp": "^1.0.2",
25
26
  "chalk": "^4.0.1",
26
27
  "command-line-application": "^0.10.1",
@@ -33,7 +34,7 @@
33
34
  "source-map-js": "^1.0.2",
34
35
  "tapable-ts": "^0.2.4",
35
36
  "ts-node": "^10.4.0",
36
- "typescript": "4.8.4",
37
+ "typescript": "^5.4.4",
37
38
  "tslib": "^2.6.2"
38
39
  },
39
40
  "peerDependencies": {
@@ -7,3 +7,12 @@ test("works with nested expressions", () => {
7
7
 
8
8
  expect(exp2.toString()).toBe(`@[conditional(foo() == bar())]@`);
9
9
  });
10
+
11
+ test("throws errors for syntactically wrong expressions", () => {
12
+ expect(() => {
13
+ const exp = e`something(1,2`;
14
+ }).toThrowErrorMatchingInlineSnapshot(`
15
+ [Error: Error: Expected ) at character 13 in expression:
16
+ something(1,2█]
17
+ `);
18
+ });
@@ -1,5 +1,5 @@
1
1
  import * as React from "react";
2
- import { parseExpression } from "@player-ui/player";
2
+ import { parseExpression, isErrorWithLocation } from "@player-ui/player";
3
3
 
4
4
  export type TemplateInstanceRefStringContext = "binding" | "expression";
5
5
  export interface TemplateRefStringOptions {
@@ -74,9 +74,22 @@ const createTemplateInstance = (
74
74
 
75
75
  /** Try to parse the expression as valid */
76
76
  if (options.nestedContext === "expression") {
77
- const parsedExpression = parseExpression(value, { strict: false });
78
- if (parsedExpression.error) {
79
- throw parsedExpression.error;
77
+ try {
78
+ parseExpression(value);
79
+ } catch (e) {
80
+ if (e instanceof Error) {
81
+ let message: string;
82
+ if (isErrorWithLocation(e)) {
83
+ message = `${e} in expression: \r\n ${
84
+ value.slice(0, e.index + 1) + "\u2588" + value.slice(e.index + 1)
85
+ }`;
86
+ } else {
87
+ message = `${e} in expression ${value}`;
88
+ }
89
+ throw new Error(message);
90
+ }
91
+
92
+ throw new Error(`Unknown problem parsing expression ${e}`);
80
93
  }
81
94
  }
82
95