Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Docs] DSL docs additions #339

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/site/pages/dsl/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ const navigation: Navigation = {
},
};
```

_Note: The `Navigation` type we're importing here from the `@player-ui/types` package is different than the `Navigation` type from the `@player-tools/dsl` package. The former is the core definition for what the Navigation section of Player content is. The latter has specific replacements to take DSL constructs where normal objects would be defined._

### Bindings and Expressions

Both `binding` and `expression` in the JSX authoring leverages a tagged template, typically abbreviated as `b` and `e` respectively. In a similar fashion to using `css` or `graphql` in a JS file, this enables syntax-highlighting and validation of bindings and expressions within a JS file.
Expand Down
13 changes: 9 additions & 4 deletions docs/site/pages/dsl/schema.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,9 @@ and like this in the final schema:

A `DSLSchema` Type is provided in order be able to customize a set of the acceptable data types and validator functions to be used for authoring the DSL data schema in your workspace. This is useful as it allows content authors to get realtime feedback on their data schema. It can catch any structural issues that may produce an invalid schema at compile time or produce a schema that uses functionality thats not available at runtime.

We'll start out by importing the `DSLSchema` type and the relevant helper types and utilities from `@player-tools/dsl`. For this example we are importing the `common-types-plugin` in order to use its data types and validators. Our first step would be to generate the data type object types and references:
_Note: A ready-to-use DSLSchema type is shipped with `@player-ui/reference-assets-components`. This type is predefined with the `DataType` and `ValidatorFunction` references inferred from the `@player-ui/common-types-plugin`. Next, you'll be presented the steps in its creation for reference._

The first step to fill in the `DSLSchema` type with your integration specific values is importing the `DSLSchema` type and the relevant helper types and utilities from `@player-tools/dsl`. For this example we are importing the `@player-ui/common-types-plugin` in order to use its data types and validators. Our first step is to generate the `DataType` and `ValidatorFunction` object types and references:

```typescript
import {
Expand Down Expand Up @@ -229,14 +231,14 @@ We'll proceed generating the validation function types:
type commonValidatorRefs = ValidatorFunctionRefs<typeof commonValidators>
```

The final step is to provide the data Types set and validator function reference Types as generics for the `DataTypeReference` type which is the sole generic type we pass into the `DSLSchema` instance:
The final step is to provide the data Types set and validator function reference Types as generics for the `DataTypeReference` type which is the sole generic type passed into the `DSLSchema` instance:
```typescript
type CommonDSLSchema = DSLSchema<
DataTypeReference<typeof commonDataTypes, commonValidatorRefs>
>
```

Finally, this is how to use the custom schema type to type check your schema. By adding the `satisfies` keyword followed by your `DSLSchema` generated type, your editor's LSP will show if there is anything not compliant with the data types and validation functions we defined in the schema:
Finally, this is how to use the custom schema type to type check your schema. By adding the `satisfies` keyword followed by your `DSLSchema` generated type, your editor's LSP will show if there is anything not compliant with the data types and validation functions you defined in the schema:

```typescript
import { CommonDSLSchema, dataRefs } from "./MyTypes"
Expand All @@ -248,7 +250,7 @@ const exampleSchema = {
/** Simply using the BooleanTypeReference to define "firstPath" type to Boolean */
firstPath: BooleanTypeRef
secondPath: {
/** For adding custom validation for "secondPath", we pass an object definition with the data "type" property, which is "TextType" for this example */
/** For adding custom validation for "secondPath", define an object definition with the data "type" property, which is "TextType" for this example */
type: "TextType",
/** In the validation array open another object definition specifying the use of the "required" validator with the "type" property, with a custom "message" value */
validation: [
Expand All @@ -262,6 +264,9 @@ const exampleSchema = {
} satisfies CommonDSLSchema
```

_Note: The `satisfies` Typescript operator is used instead of type assignment (`exampleSchema:DSLSChema`), because `satisfies` doesn't lose the inferred type of your value by changing and broadening the type unlike using assignment, it simply type-checks, creating localised feedback if anything is incorrect._


# Using the Schema Object in JSX/TSX Content

As the schema is now a TypeScript obejct, you can now directly reference the schema anywhere in content. The `makeBindingsForObject()` function takes your schema object and constructs the bindings opaquely within the object. This allows the use of the native path in your authored content and for the actual underlying binding to be used when the content is compiled. Additionally, as the underlying bindings are exposed, can you can use the native object path with functions like `.toString()`, `.toValue()`, and `toRefString()` like you could with regular string template bindings.
Expand Down
2 changes: 1 addition & 1 deletion docs/site/pages/dsl/views.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Use the `isDynamic` flag to denote this should be a `dynamicSwitch` instead of a

```tsx
import React from 'react';
import { Switch } from '@player-ui/dsl';
import { Switch } from '@player-tools/dsl';

<Collection>
<Collection.Label>
Expand Down