@player-tools/dsl 0.5.0--canary.62.1176 → 0.5.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +973 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/index.legacy-esm.js +910 -0
- package/dist/index.mjs +910 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +27 -33
- package/src/__tests__/asset-api.test.tsx +354 -0
- package/src/__tests__/edge-cases.test.tsx +81 -0
- package/src/__tests__/helpers/asset-library.tsx +371 -0
- package/src/__tests__/helpers/mock-data-refs.ts +21 -0
- package/src/__tests__/json.test.ts +12 -0
- package/src/__tests__/jsx.test.tsx +138 -0
- package/src/__tests__/schema.test.tsx +378 -0
- package/src/__tests__/switch.test.tsx +251 -0
- package/src/__tests__/template.test.tsx +294 -0
- package/src/__tests__/view-api.test.tsx +46 -0
- package/src/auto-id.tsx +10 -10
- package/src/compiler/__tests__/compiler.test.tsx +264 -0
- package/src/compiler/__tests__/schema.test.ts +127 -0
- package/src/compiler/compiler.ts +50 -46
- package/src/compiler/index.ts +3 -3
- package/src/compiler/schema.ts +29 -25
- package/src/compiler/types.ts +15 -12
- package/src/compiler/utils.ts +7 -7
- package/src/components.tsx +17 -12
- package/src/index.ts +11 -11
- package/src/string-templates/__tests__/binding.test.ts +87 -0
- package/src/string-templates/__tests__/edge-cases.test.ts +6 -0
- package/src/string-templates/__tests__/expression.test.ts +9 -0
- package/src/string-templates/__tests__/react.test.tsx +75 -0
- package/src/string-templates/index.ts +40 -22
- package/src/switch.tsx +12 -12
- package/src/template.tsx +38 -34
- package/src/types.ts +5 -5
- package/src/utils.tsx +8 -8
- package/types/auto-id.d.ts +33 -0
- package/types/compiler/compiler.d.ts +27 -0
- package/types/compiler/index.d.ts +4 -0
- package/types/compiler/schema.d.ts +61 -0
- package/types/compiler/types.d.ts +55 -0
- package/types/compiler/utils.d.ts +4 -0
- package/types/components.d.ts +90 -0
- package/types/index.d.ts +12 -0
- package/types/string-templates/index.d.ts +50 -0
- package/types/switch.d.ts +19 -0
- package/types/template.d.ts +20 -0
- package/types/types.d.ts +42 -0
- package/types/utils.d.ts +33 -0
- package/README.md +0 -9
- package/dist/index.cjs.js +0 -990
- package/dist/index.d.ts +0 -404
- package/dist/index.esm.js +0 -923
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { JsonNode } from "react-json-reconciler";
|
|
3
|
+
import type { WithChildren } from "./types";
|
|
4
|
+
export declare const IndexSuffixStopContext: React.Context<boolean>;
|
|
5
|
+
/** Get the generated id */
|
|
6
|
+
export declare const useGetIdPrefix: () => string;
|
|
7
|
+
/** Add a suffix to a generated id */
|
|
8
|
+
export declare const IDSuffixProvider: (props: WithChildren<{
|
|
9
|
+
/** The suffix to append */
|
|
10
|
+
suffix: string;
|
|
11
|
+
}>) => React.JSX.Element;
|
|
12
|
+
/** Override the generated id with the supplied one */
|
|
13
|
+
export declare const IDProvider: (props: WithChildren<{
|
|
14
|
+
/** The new id to use */
|
|
15
|
+
id?: string;
|
|
16
|
+
}>) => React.JSX.Element;
|
|
17
|
+
/** Get the index of an item in a slot */
|
|
18
|
+
export declare const useIndexInSlot: (ref: React.RefObject<JsonNode>) => number;
|
|
19
|
+
/** Add the index to the id path when in an array slot */
|
|
20
|
+
export declare const IDSuffixIndexProvider: (props: WithChildren<{
|
|
21
|
+
/** The ref to use */
|
|
22
|
+
wrapperRef: React.RefObject<JsonNode>;
|
|
23
|
+
/** if the suffix is in a template, the id to use */
|
|
24
|
+
templateIndex?: string;
|
|
25
|
+
}>) => React.JSX.Element;
|
|
26
|
+
/** Wrap a slot with the index if in an array slot */
|
|
27
|
+
export declare const OptionalIDSuffixProvider: (props: WithChildren<{
|
|
28
|
+
/** The ref to walk upwards and use as an index */
|
|
29
|
+
wrapperRef: React.RefObject<JsonNode>;
|
|
30
|
+
/** if the suffix is in a template, the id to use */
|
|
31
|
+
templateIndex?: string;
|
|
32
|
+
}>) => React.JSX.Element;
|
|
33
|
+
//# sourceMappingURL=auto-id.d.ts.map
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Flow } from "@player-ui/types";
|
|
2
|
+
import { AsyncSeriesHook, AsyncSeriesWaterfallHook, SyncHook } from "tapable-ts";
|
|
3
|
+
import type { LoggingInterface, CompilerReturn, SerializeContext } from "./types";
|
|
4
|
+
import { SchemaGenerator } from "./schema";
|
|
5
|
+
/**
|
|
6
|
+
* Argument passed to the DSLCompiler onEnd hook
|
|
7
|
+
* Defined as an object so additional fields can be added later without breaking API
|
|
8
|
+
* */
|
|
9
|
+
export interface OnEndArg {
|
|
10
|
+
/** target output directory **/
|
|
11
|
+
output: string;
|
|
12
|
+
}
|
|
13
|
+
/** A compiler for transforming DSL content into JSON */
|
|
14
|
+
export declare class DSLCompiler {
|
|
15
|
+
readonly logger: LoggingInterface;
|
|
16
|
+
hooks: {
|
|
17
|
+
schemaGenerator: SyncHook<[SchemaGenerator], Record<string, any>>;
|
|
18
|
+
preProcessFlow: AsyncSeriesWaterfallHook<[object], Record<string, any>>;
|
|
19
|
+
postProcessFlow: AsyncSeriesWaterfallHook<[Flow<import("@player-ui/types").Asset<string>>], Record<string, any>>;
|
|
20
|
+
onEnd: AsyncSeriesHook<[OnEndArg], Record<string, any>>;
|
|
21
|
+
};
|
|
22
|
+
private schemaGenerator?;
|
|
23
|
+
constructor(logger?: LoggingInterface);
|
|
24
|
+
/** Convert an object (flow, view, schema, etc) into it's JSON representation */
|
|
25
|
+
serialize(value: unknown, context?: SerializeContext): Promise<CompilerReturn>;
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Schema } from "@player-ui/types";
|
|
2
|
+
import { SyncWaterfallHook } from "tapable-ts";
|
|
3
|
+
import type { LoggingInterface } from "..";
|
|
4
|
+
import type { BindingTemplateInstance } from "../string-templates";
|
|
5
|
+
/** Symbol to indicate that a schema node should be generated with a different name */
|
|
6
|
+
export declare const SchemaTypeName: unique symbol;
|
|
7
|
+
/**
|
|
8
|
+
* Generator for `Schema.Schema` Objects
|
|
9
|
+
*/
|
|
10
|
+
export declare class SchemaGenerator {
|
|
11
|
+
private children;
|
|
12
|
+
private generatedDataTypes;
|
|
13
|
+
private logger;
|
|
14
|
+
hooks: {
|
|
15
|
+
createSchemaNode: SyncWaterfallHook<[node: Schema.DataType<unknown>, originalProperty: Record<string | symbol, unknown>], Record<string, any>>;
|
|
16
|
+
};
|
|
17
|
+
constructor(logger?: LoggingInterface);
|
|
18
|
+
/**
|
|
19
|
+
* Converts an object to a `Schema.Schema` representation
|
|
20
|
+
* Note: uses iteration to prevent potentially very deep recursion on large objects
|
|
21
|
+
*/
|
|
22
|
+
toSchema: (schema: any) => Schema.Schema;
|
|
23
|
+
/**
|
|
24
|
+
* Processes the children of an object Node
|
|
25
|
+
* Newly discovered children get added to the provided array
|
|
26
|
+
*/
|
|
27
|
+
private processChild;
|
|
28
|
+
/**
|
|
29
|
+
* Make an intermediate `Schema.DataType` object given a name
|
|
30
|
+
*/
|
|
31
|
+
private makePlaceholderType;
|
|
32
|
+
/**
|
|
33
|
+
* Make an intermediate `Schema.DataType` object with array support given a name
|
|
34
|
+
*/
|
|
35
|
+
private makePlaceholderArrayType;
|
|
36
|
+
}
|
|
37
|
+
export type MakeArrayIntoIndexRef<T extends any[]> = {
|
|
38
|
+
[key: number]: MakeBindingRefable<T[0]>;
|
|
39
|
+
/** Used when referencing bindings from within a template */
|
|
40
|
+
_index_: MakeBindingRefable<T[0]>;
|
|
41
|
+
} & BindingTemplateInstance;
|
|
42
|
+
export type MakeBindingRefable<T> = {
|
|
43
|
+
[P in keyof T]: T[P] extends object[] ? MakeArrayIntoIndexRef<T[P]> : T[P] extends unknown[] ? T[P] : MakeBindingRefable<T[P]>;
|
|
44
|
+
} & BindingTemplateInstance;
|
|
45
|
+
/**
|
|
46
|
+
* Adds bindings to an object so that the object can be directly used in JSX
|
|
47
|
+
*/
|
|
48
|
+
export declare function makeBindingsForObject<Type>(obj: Type, arrayAccessorKeys?: string[]): MakeBindingRefable<Type>;
|
|
49
|
+
/**
|
|
50
|
+
* Generates binding for an object property
|
|
51
|
+
*/
|
|
52
|
+
export declare const getBindingFromObject: (obj: any) => BindingTemplateInstance;
|
|
53
|
+
/**
|
|
54
|
+
* Returns the binding string from an object path
|
|
55
|
+
*/
|
|
56
|
+
export declare const getBindingStringFromObject: (obj: any) => string;
|
|
57
|
+
/**
|
|
58
|
+
* Returns the ref string from an object path
|
|
59
|
+
*/
|
|
60
|
+
export declare const getRefStringFromObject: (obj: any) => string;
|
|
61
|
+
//# sourceMappingURL=schema.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Schema, Navigation, Flow, Expression, ExpressionObject, NavigationFlow, NavigationFlowState, NavigationFlowViewState } from "@player-ui/types";
|
|
3
|
+
import type { JsonType } from "react-json-reconciler";
|
|
4
|
+
import type { RemoveUnknownIndex, AddUnknownIndex } from "../types";
|
|
5
|
+
export type NavigationFlowReactViewState = Omit<NavigationFlowViewState, "ref"> & {
|
|
6
|
+
/** The view element */
|
|
7
|
+
ref: React.ReactElement | string;
|
|
8
|
+
};
|
|
9
|
+
export type NavFlowState = Exclude<NavigationFlowState, NavigationFlowViewState> | NavigationFlowReactViewState;
|
|
10
|
+
export type NavigationFlowWithReactView = Pick<NavigationFlow, "startState" | "onStart" | "onEnd"> & {
|
|
11
|
+
[key: string]: undefined | string | Expression | ExpressionObject | NavFlowState;
|
|
12
|
+
};
|
|
13
|
+
export type NavigationWithReactViews = Pick<Navigation, "BEGIN"> & Record<string, string | NavigationFlowWithReactView>;
|
|
14
|
+
export type FlowWithoutUnknown = RemoveUnknownIndex<Flow>;
|
|
15
|
+
export type FlowWithReactViews = AddUnknownIndex<Omit<FlowWithoutUnknown, "views" | "navigation"> & {
|
|
16
|
+
/** An array of JSX view elements */
|
|
17
|
+
views?: Array<React.ReactElement>;
|
|
18
|
+
/** The navigation element */
|
|
19
|
+
navigation?: NavigationWithReactViews;
|
|
20
|
+
}>;
|
|
21
|
+
export type DSLFlow = Omit<FlowWithReactViews, "schema"> & {
|
|
22
|
+
/** A DSL compliant schema */
|
|
23
|
+
schema?: DSLSchema;
|
|
24
|
+
};
|
|
25
|
+
export interface DSLSchema {
|
|
26
|
+
[key: string]: Schema.DataType | DSLSchema;
|
|
27
|
+
}
|
|
28
|
+
export type SerializeType = "view" | "flow" | "schema" | "navigation";
|
|
29
|
+
export type SerializablePlayerExportTypes = React.ReactElement | FlowWithReactViews | Schema.Schema | Navigation;
|
|
30
|
+
export type LoggingInterface = Pick<Console, "warn" | "error" | "log">;
|
|
31
|
+
export type CompilationResult = {
|
|
32
|
+
/** What type of file is generated */
|
|
33
|
+
contentType: string;
|
|
34
|
+
/** The output path */
|
|
35
|
+
outputFile: string;
|
|
36
|
+
/** the input file */
|
|
37
|
+
inputFile: string;
|
|
38
|
+
};
|
|
39
|
+
export type CompilerReturn = {
|
|
40
|
+
/** the JSON value of the source */
|
|
41
|
+
value: JsonType | undefined;
|
|
42
|
+
/** The sourcemap of the content */
|
|
43
|
+
sourceMap?: string;
|
|
44
|
+
};
|
|
45
|
+
/** The different type of default content items the compiler handles */
|
|
46
|
+
declare const DefaultCompilerContentTypes: readonly ["view", "flow", "schema"];
|
|
47
|
+
export type DefaultCompilerContentType = (typeof DefaultCompilerContentTypes)[number];
|
|
48
|
+
/** Helper function to determine whether a content type is compiler default */
|
|
49
|
+
export declare function isDefaultCompilerContentType(t: string): t is DefaultCompilerContentType;
|
|
50
|
+
export interface SerializeContext {
|
|
51
|
+
/** The type of the content being compiled */
|
|
52
|
+
type: DefaultCompilerContentType;
|
|
53
|
+
}
|
|
54
|
+
export {};
|
|
55
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { DefaultCompilerContentType } from "./types";
|
|
2
|
+
/** Basic way of identifying the type of file based on the default content export */
|
|
3
|
+
export declare const fingerprintContent: (content: unknown, filename?: string) => DefaultCompilerContentType | undefined;
|
|
4
|
+
//# sourceMappingURL=utils.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ObjectNode, PropertyNode } from "react-json-reconciler";
|
|
3
|
+
import type { PlayerApplicability, WithChildren } from "./types";
|
|
4
|
+
export type AssetProps = PlayerApplicability & {
|
|
5
|
+
/** id of the asset */
|
|
6
|
+
id?: string;
|
|
7
|
+
/** the asset type */
|
|
8
|
+
type: string;
|
|
9
|
+
/** Any other properties on the asset */
|
|
10
|
+
children?: React.ReactNode;
|
|
11
|
+
/** other things that we don't know about */
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
export declare const SlotContext: React.Context<{
|
|
15
|
+
/** The property name for the slot */
|
|
16
|
+
propertyName: string;
|
|
17
|
+
/** If the slot represents an array */
|
|
18
|
+
isArray: boolean;
|
|
19
|
+
/** If the items in the slot should be wrapped in an "asset" object */
|
|
20
|
+
wrapInAsset: boolean;
|
|
21
|
+
/** Other props to add to the slot */
|
|
22
|
+
additionalProperties?: any;
|
|
23
|
+
/** The ref to the property node */
|
|
24
|
+
ref: React.RefObject<PropertyNode>;
|
|
25
|
+
/** A text component if we hit a string but expect an asset */
|
|
26
|
+
TextComp?: React.ComponentType<{}> | undefined;
|
|
27
|
+
/** A component to create a collection asset is we get an array but need a single element */
|
|
28
|
+
CollectionComp?: React.ComponentType<{}> | undefined;
|
|
29
|
+
} | undefined>;
|
|
30
|
+
/**
|
|
31
|
+
* Wraps the children in an `asset` object.
|
|
32
|
+
* Additional props are added to the top level object
|
|
33
|
+
*/
|
|
34
|
+
export declare const AssetWrapper: React.ForwardRefExoticComponent<Omit<WithChildren<{
|
|
35
|
+
[key: string]: unknown;
|
|
36
|
+
}>, "ref"> & React.RefAttributes<ObjectNode>>;
|
|
37
|
+
/** Create a ID property for a node */
|
|
38
|
+
export declare const GeneratedIDProperty: (props: {
|
|
39
|
+
/** the id to use if supplied by the user */
|
|
40
|
+
id?: string;
|
|
41
|
+
}) => React.JSX.Element;
|
|
42
|
+
/** An asset */
|
|
43
|
+
export declare const Asset: React.ForwardRefExoticComponent<Omit<AssetProps, "ref"> & React.RefAttributes<ObjectNode>>;
|
|
44
|
+
export declare const View: React.ForwardRefExoticComponent<Omit<PlayerApplicability & {
|
|
45
|
+
[key: string]: unknown;
|
|
46
|
+
/** id of the asset */
|
|
47
|
+
id?: string | undefined;
|
|
48
|
+
/** the asset type */
|
|
49
|
+
type: string;
|
|
50
|
+
/** Any other properties on the asset */
|
|
51
|
+
children?: React.ReactNode;
|
|
52
|
+
} & import("@player-ui/types").Asset<string> & {
|
|
53
|
+
validation?: import("@player-ui/types").Validation.CrossfieldReference[] | undefined;
|
|
54
|
+
}, "ref"> & React.RefAttributes<ObjectNode>>;
|
|
55
|
+
/** A component to generate a named property slot */
|
|
56
|
+
export declare const Slot: (props: {
|
|
57
|
+
/** The name of the slot */
|
|
58
|
+
name: string;
|
|
59
|
+
/** if the slot is an array or single object */
|
|
60
|
+
isArray?: boolean;
|
|
61
|
+
/** if each item should be wrapped in an asset */
|
|
62
|
+
wrapInAsset?: boolean;
|
|
63
|
+
/** Any children to render in the slot */
|
|
64
|
+
children?: React.ReactNode;
|
|
65
|
+
/** Other properties to add to the slot */
|
|
66
|
+
additionalProperties?: any;
|
|
67
|
+
/** A text component if we hit a string but expect an asset */
|
|
68
|
+
TextComp?: React.ComponentType;
|
|
69
|
+
/** A component to create a collection asset is we get an array but need a single element */
|
|
70
|
+
CollectionComp?: React.ComponentType;
|
|
71
|
+
}) => React.JSX.Element;
|
|
72
|
+
/** Create a slot for a given property */
|
|
73
|
+
export declare function createSlot<SlotProps = unknown>(options: {
|
|
74
|
+
/** The name of the slot */
|
|
75
|
+
name: string;
|
|
76
|
+
/** if the slot is an array or single object */
|
|
77
|
+
isArray?: boolean;
|
|
78
|
+
/** if each item should be wrapped in an asset */
|
|
79
|
+
wrapInAsset?: boolean;
|
|
80
|
+
/** Any children to render in the slot */
|
|
81
|
+
children?: React.ReactNode;
|
|
82
|
+
/** A text component if we hit a string but expect an asset */
|
|
83
|
+
TextComp?: React.ComponentType;
|
|
84
|
+
/** A component to create a collection asset is we get an array but need a single element */
|
|
85
|
+
CollectionComp?: React.ComponentType;
|
|
86
|
+
}): (props: {
|
|
87
|
+
/** An object to include in this property */
|
|
88
|
+
children?: React.ReactNode;
|
|
89
|
+
} & SlotProps) => React.JSX.Element;
|
|
90
|
+
//# sourceMappingURL=components.d.ts.map
|
package/types/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from "./components";
|
|
2
|
+
export * from "./auto-id";
|
|
3
|
+
export * from "./types";
|
|
4
|
+
export * from "./string-templates";
|
|
5
|
+
export * from "./utils";
|
|
6
|
+
export * from "./switch";
|
|
7
|
+
export * from "./template";
|
|
8
|
+
export * from "react-json-reconciler";
|
|
9
|
+
export * from "./compiler/schema";
|
|
10
|
+
export * from "./compiler";
|
|
11
|
+
export * from "./compiler/types";
|
|
12
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
export type TemplateInstanceRefStringContext = "binding" | "expression";
|
|
3
|
+
export interface TemplateRefStringOptions {
|
|
4
|
+
/** If this template string is inside of another binding or expression */
|
|
5
|
+
nestedContext?: TemplateInstanceRefStringContext;
|
|
6
|
+
}
|
|
7
|
+
export interface TemplateInstanceRefStringOptions {
|
|
8
|
+
/** The array of strings for the template */
|
|
9
|
+
strings: ReadonlyArray<string>;
|
|
10
|
+
/** the other data that's present in the template */
|
|
11
|
+
other: Array<string | TemplateStringType>;
|
|
12
|
+
/** If this template string is inside of another binding or expression */
|
|
13
|
+
nestedContext?: TemplateInstanceRefStringContext;
|
|
14
|
+
/** Convert the value to a reference nested in the given context */
|
|
15
|
+
toRefString: (options: TemplateRefStringOptions | undefined, value: string) => string;
|
|
16
|
+
}
|
|
17
|
+
declare const OpaqueIdentifier: unique symbol;
|
|
18
|
+
export type TemplateStringType = React.ReactElement & {
|
|
19
|
+
/** An identifier to show that this is a template type */
|
|
20
|
+
[OpaqueIdentifier]: true;
|
|
21
|
+
/** The value of the template string when in another string */
|
|
22
|
+
toString: () => string;
|
|
23
|
+
/** the raw value of the template string */
|
|
24
|
+
toValue: () => string;
|
|
25
|
+
/** the dereferenced value when used in another */
|
|
26
|
+
toRefString: (options?: TemplateRefStringOptions) => string;
|
|
27
|
+
};
|
|
28
|
+
export type BindingTemplateInstance = TemplateStringType & {
|
|
29
|
+
/** An identifier for a binding instance */
|
|
30
|
+
__type: "binding";
|
|
31
|
+
};
|
|
32
|
+
export type ExpressionTemplateInstance = TemplateStringType & {
|
|
33
|
+
/** The identifier for an expression instance */
|
|
34
|
+
__type: "expression";
|
|
35
|
+
};
|
|
36
|
+
/** A react component for rendering a template string type */
|
|
37
|
+
export declare const TemplateStringComponent: (props: {
|
|
38
|
+
/** The string value of the child template string */
|
|
39
|
+
value: string;
|
|
40
|
+
}) => React.ReactElement<{
|
|
41
|
+
value: string;
|
|
42
|
+
}, string | React.JSXElementConstructor<any>>;
|
|
43
|
+
/** A tagged-template constructor for a binding */
|
|
44
|
+
export declare const binding: (strings: TemplateStringsArray, ...nested: Array<TemplateStringType | string>) => BindingTemplateInstance;
|
|
45
|
+
/** A tagged-template constructor for an expression */
|
|
46
|
+
export declare const expression: (strings: TemplateStringsArray, ...nested: Array<ExpressionTemplateInstance | BindingTemplateInstance | string>) => ExpressionTemplateInstance;
|
|
47
|
+
/** Check if a value is a template string */
|
|
48
|
+
export declare const isTemplateStringInstance: (val: unknown) => val is BindingTemplateInstance | ExpressionTemplateInstance;
|
|
49
|
+
export {};
|
|
50
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PropsWithChildren } from "react";
|
|
2
|
+
import React from "react";
|
|
3
|
+
import type { BindingTemplateInstance, ExpressionTemplateInstance } from "./string-templates";
|
|
4
|
+
export interface SwitchProps {
|
|
5
|
+
/** defaults to a staticSwitch */
|
|
6
|
+
isDynamic?: boolean;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Switches allow users to fork content between 1 or more assets
|
|
10
|
+
*/
|
|
11
|
+
export declare const Switch: {
|
|
12
|
+
(props: PropsWithChildren<SwitchProps>): React.JSX.Element;
|
|
13
|
+
Case: (props: PropsWithChildren<CaseProps>) => React.JSX.Element;
|
|
14
|
+
};
|
|
15
|
+
export interface CaseProps {
|
|
16
|
+
/** the test for this case statement */
|
|
17
|
+
exp?: ExpressionTemplateInstance | BindingTemplateInstance | boolean;
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=switch.d.ts.map
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { BindingTemplateInstance } from "./string-templates";
|
|
3
|
+
export interface TemplateContextType {
|
|
4
|
+
/** The number of nested templates */
|
|
5
|
+
depth: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const TemplateContext: React.Context<TemplateContextType>;
|
|
8
|
+
export interface TemplateProps {
|
|
9
|
+
/** The source binding */
|
|
10
|
+
data: BindingTemplateInstance;
|
|
11
|
+
/** The target property */
|
|
12
|
+
output?: string;
|
|
13
|
+
/** The template value */
|
|
14
|
+
children: React.ReactNode;
|
|
15
|
+
/** boolean that specifies whether template should recompute when data changes */
|
|
16
|
+
dynamic?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A template allows users to dynamically map over an array of data */
|
|
19
|
+
export declare const Template: (props: TemplateProps) => React.JSX.Element;
|
|
20
|
+
//# sourceMappingURL=template.d.ts.map
|
package/types/types.d.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { Asset, Expression, Navigation as PlayerNav } from "@player-ui/types";
|
|
3
|
+
import type { BindingTemplateInstance, ExpressionTemplateInstance } from "./string-templates";
|
|
4
|
+
export type WithChildren<T = Record<string, unknown>> = T & {
|
|
5
|
+
/** child nodes */
|
|
6
|
+
children?: React.ReactNode;
|
|
7
|
+
};
|
|
8
|
+
export type RemoveUnknownIndex<T> = {
|
|
9
|
+
[P in keyof T as T[P] extends unknown ? unknown extends T[P] ? never : P : P]: T[P];
|
|
10
|
+
};
|
|
11
|
+
export type AddUnknownIndex<T> = T & {
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
/** Make an ID prop optional an a type */
|
|
15
|
+
export type OmitProp<T, K extends string> = {
|
|
16
|
+
[P in keyof T as P extends K ? never : P]: T[P];
|
|
17
|
+
};
|
|
18
|
+
export interface PlayerApplicability {
|
|
19
|
+
/** An expression to evaluate to determine if this node should appear in a view or not */
|
|
20
|
+
applicability?: BindingTemplateInstance | ExpressionTemplateInstance | boolean;
|
|
21
|
+
}
|
|
22
|
+
export type AssetPropsWithChildren<T extends Asset> = WithChildren<WithTemplateTypes<OmitProp<RemoveUnknownIndex<T>, "id" | "type"> & Partial<Pick<Asset, "id">>> & PlayerApplicability>;
|
|
23
|
+
export type SwapKeysToType<T, K extends keyof T, NewType> = {
|
|
24
|
+
[P in keyof T]: P extends K ? NewType : T[P];
|
|
25
|
+
};
|
|
26
|
+
export type WithTemplateTypes<T> = T extends Record<any, any> ? {
|
|
27
|
+
[P in keyof T]: WithTemplateTypes<T[P]>;
|
|
28
|
+
} : T | BindingTemplateInstance | ExpressionTemplateInstance;
|
|
29
|
+
type ValidKeys = "exp" | "onStart" | "onEnd";
|
|
30
|
+
type DeepReplace<T, Old, New> = {
|
|
31
|
+
[P in keyof T]: T[P] extends Old ? P extends ValidKeys ? New : DeepReplace<T[P], Old, New> : T[P] extends (infer R)[] ? DeepReplace<R, Old, New>[] : T[P] extends object ? DeepReplace<T[P], Old, New> : Extract<T[P], Old> extends Old ? DeepReplace<Extract<T[P], object>, Old, New> | Exclude<T[P], Old | object> | New : T[P];
|
|
32
|
+
};
|
|
33
|
+
export type Navigation = DeepReplace<PlayerNav, Expression, ExpressionTemplateInstance | ExpressionTemplateInstance[] | Expression>;
|
|
34
|
+
export interface toJsonOptions {
|
|
35
|
+
/**
|
|
36
|
+
* List of string keys that should not be parsed in a special way
|
|
37
|
+
* default is "applicability"
|
|
38
|
+
*/
|
|
39
|
+
propertiesToSkip?: string[];
|
|
40
|
+
}
|
|
41
|
+
export {};
|
|
42
|
+
//# sourceMappingURL=types.d.ts.map
|
package/types/utils.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { toJsonOptions } from "./types";
|
|
3
|
+
/** Get an array version of the value */
|
|
4
|
+
export declare function toArray<T>(val: T | Array<T>): Array<T>;
|
|
5
|
+
/** Create a component version */
|
|
6
|
+
export declare function toJsonElement(value: any, indexOrKey?: number | string, options?: toJsonOptions): React.ReactElement;
|
|
7
|
+
/** Create a fragment for the properties */
|
|
8
|
+
export declare function toJsonProperties(value: Record<string, any>, options?: toJsonOptions): React.JSX.Element[];
|
|
9
|
+
/** Create a text asset if needed */
|
|
10
|
+
export declare function normalizeText(options: {
|
|
11
|
+
/** The current node */
|
|
12
|
+
node: React.ReactNode;
|
|
13
|
+
/** A component to render a text asset */
|
|
14
|
+
TextComp?: React.ComponentType<any>;
|
|
15
|
+
}): React.ReactNode;
|
|
16
|
+
/** Create a collection if needed */
|
|
17
|
+
export declare function normalizeToCollection(options: {
|
|
18
|
+
/** the node to look at */
|
|
19
|
+
node: React.ReactNode;
|
|
20
|
+
/** A Text asset */
|
|
21
|
+
TextComp?: React.ComponentType;
|
|
22
|
+
/** A collection asset */
|
|
23
|
+
CollectionComp?: React.ComponentType<any>;
|
|
24
|
+
}): string | number | boolean | Iterable<React.ReactNode> | React.JSX.Element | null | undefined;
|
|
25
|
+
type ReactChildArray = ReturnType<typeof React.Children.toArray>;
|
|
26
|
+
/**
|
|
27
|
+
*
|
|
28
|
+
* Hoisted from https://github.com/gregberge/react-flatten-children/blob/master/src/index.tsx
|
|
29
|
+
* Peer dependencies were wrong and can't be reasonably patch it everywhere
|
|
30
|
+
*/
|
|
31
|
+
export declare function flattenChildren(children: React.ReactNode): ReactChildArray;
|
|
32
|
+
export {};
|
|
33
|
+
//# sourceMappingURL=utils.d.ts.map
|
package/README.md
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
# DSL
|
|
2
|
-
|
|
3
|
-
The `@player-ui/dsl` package provides the primitives and build tools to create Player Asset Component libraries, and statically generate Player JSON content using TSX.
|
|
4
|
-
|
|
5
|
-
## Asset Component Libraries
|
|
6
|
-
|
|
7
|
-
Similar to React, Vue, or other component libraries, in order for users to take advantage of the JSX capabilities, they need a library of common components to pull from.
|
|
8
|
-
|
|
9
|
-
As an asset author, you can create and share a library of `Components` for content authors to import and leverage.
|