-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from player-ui/console-ds
Console, Table and Stacked View
- Loading branch information
Showing
56 changed files
with
1,889 additions
and
326 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
load("@npm//:defs.bzl", "npm_link_all_packages") | ||
load("@rules_player//javascript:defs.bzl", "js_pipeline") | ||
load("//helpers:defs.bzl", "tsup_config", "vitest_config") | ||
|
||
npm_link_all_packages(name = "node_modules") | ||
|
||
tsup_config(name = "tsup_config") | ||
|
||
vitest_config(name = "vitest_config") | ||
|
||
js_pipeline( | ||
package_name = "@devtools-ui/console", | ||
test_deps = [ | ||
":node_modules", | ||
"//:vitest_config", | ||
], | ||
deps = [ | ||
":node_modules/@devtools-ui/collection", | ||
":node_modules/@devtools-ui/text", | ||
"//:node_modules/@chakra-ui/react", | ||
"//:node_modules/@emotion/react", | ||
"//:node_modules/@emotion/styled", | ||
"//:node_modules/@player-tools/dsl", | ||
"//:node_modules/@player-ui/asset-transform-plugin", | ||
"//:node_modules/@player-ui/player", | ||
"//:node_modules/@player-ui/react", | ||
"//:node_modules/@player-ui/types", | ||
"//:node_modules/@types/react", | ||
"//:node_modules/dlv", | ||
"//:node_modules/eslint-plugin-storybook", | ||
"//:node_modules/framer-motion", | ||
"//:node_modules/react", | ||
"//:node_modules/@devtools-ds/console" | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
# @devtools-ui/console | ||
|
||
## Overview | ||
|
||
`@devtools-ui/console` is a component package designed to be leveraged by a [Player-UI assets plugin](https://player-ui.github.io/next/plugins). | ||
|
||
It provides a [Console]([TODO: add link to storybook]) component that can be used to [TODO: define component features]. | ||
|
||
This package is part of a mono-repo built with Bazel, ensuring fast and reliable builds. | ||
|
||
## Installation | ||
|
||
To install `@devtools-ui/console`, you can use pnpm or yarn: | ||
|
||
```sh | ||
pnpm i @devtools-ui/console | ||
``` | ||
|
||
or | ||
|
||
```sh | ||
yarn add @devtools-ui/console | ||
``` | ||
|
||
## Usage | ||
|
||
You can leverage this asset through the `@devtools-ui/plugin`: | ||
|
||
```ts | ||
import { Console } from "@devtools-ui/plugin"; | ||
|
||
// and use it to define your Player-UI content: | ||
myFlow = { | ||
id: "my_flow", | ||
views: [<Console exp={e`my_expression`} binding={b`my_binding`} />], | ||
}; | ||
``` | ||
|
||
For more information on how to author Player-UI content using DSL, please check our [Player-UI docs](https://player-ui.github.io/next/dsl#tsxjsx-content-authoring-player-dsl). | ||
|
||
Or, your can leverage this asset in your own plugin: | ||
|
||
```ts | ||
// TransformPlugin.ts | ||
import type { Player, PlayerPlugin } from "@player-ui/player"; | ||
import { AssetTransformPlugin } from "@player-ui/asset-transform-plugin"; | ||
import { consoleTransform } from "@devtools-ui/console"; | ||
|
||
export class TransformsPlugin implements PlayerPlugin { | ||
name = "my-plugin-transforms"; | ||
|
||
apply(player: Player) { | ||
player.registerPlugin( | ||
new AssetTransformPlugin([[{ type: "console" }, consoleTransform]]) | ||
); | ||
} | ||
} | ||
``` | ||
|
||
```ts | ||
// AssetRegistryPlugin.ts | ||
import React from "react"; | ||
import type { Player } from "@player-ui/player"; | ||
import type { | ||
ExtendedPlayerPlugin, | ||
ReactPlayer, | ||
ReactPlayerPlugin, | ||
} from "@player-ui/react"; | ||
import { AssetProviderPlugin } from "@player-ui/asset-provider-plugin-react"; | ||
import { TransformsPlugin } from "./TransformPlugin"; | ||
import { ConsoleAsset, ConsoleComponent } from "@devtools-ui/console"; | ||
|
||
export class AssetsRegistryPlugin | ||
implements ReactPlayerPlugin, ExtendedPlayerPlugin<[ConsoleAsset]> | ||
{ | ||
name = "my-plugin"; | ||
|
||
applyReact(reactPlayer: ReactPlayer) { | ||
reactPlayer.registerPlugin( | ||
new AssetProviderPlugin([["console", ConsoleComponent]]) | ||
); | ||
} | ||
|
||
apply(player: Player) { | ||
player.registerPlugin(new TransformsPlugin()); | ||
} | ||
} | ||
``` | ||
|
||
## Contributing | ||
|
||
We welcome contributions to `@devtools-ui/console`! Please see the [CONTRIBUTING.md](TODO: link to the file) file for more information on how to contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"name": "@devtools-ui/console", | ||
"version": "0.0.0-PLACEHOLDER", | ||
"main": "src/index.ts", | ||
"dependencies": { | ||
"@devtools-ui/text": "workspace:*", | ||
"@devtools-ui/collection": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from "react"; | ||
import { Console } from "@devtools-ds/console"; | ||
import type { TransformedConsole } from "../types"; | ||
|
||
export const ConsoleComponent = (props: TransformedConsole) => { | ||
const { evaluate, history } = props; | ||
|
||
return <Console execute={evaluate} history={history} />; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import React from "react"; | ||
import { describe, expect, test } from "vitest"; | ||
import { render, expression as e, binding as b } from "@player-tools/dsl"; | ||
import { Console } from "../"; | ||
|
||
describe("DSL: Console", () => { | ||
test("Renders console", async () => { | ||
const rendered = await render( | ||
<Console exp={e`my_expression`} binding={b`my_binding`} /> | ||
); | ||
|
||
expect(rendered.jsonValue).toStrictEqual({ | ||
id: "root", | ||
type: "console", | ||
exp: "my_expression", | ||
binding: "my_binding", | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import React from "react"; | ||
import { | ||
AssetPropsWithChildren, | ||
Asset, | ||
isTemplateStringInstance, | ||
BindingTemplateInstance, | ||
} from "@player-tools/dsl"; | ||
import type { ConsoleAsset } from "../types"; | ||
|
||
/** | ||
* Defines the component DSL representation for the Console asset, | ||
* a component that emulates a REPL environment that you see in browsers. | ||
*/ | ||
export const Console = ( | ||
props: Omit<AssetPropsWithChildren<ConsoleAsset>, "binding"> & { | ||
/** Binding as template string */ | ||
binding: BindingTemplateInstance; | ||
} | ||
) => { | ||
const { exp, binding } = props; | ||
|
||
// Extracting the exp value from the props | ||
let expValue: ConsoleAsset["exp"]; | ||
|
||
if (isTemplateStringInstance(exp)) { | ||
expValue = exp.toValue(); | ||
} else if (Array.isArray(exp)) { | ||
expValue = exp.map((e) => (typeof e === "string" ? e : e.toValue())); | ||
} else if (exp) { | ||
expValue = exp; | ||
} | ||
|
||
return ( | ||
<Asset type="console"> | ||
{exp && <property name="exp">{expValue}</property>} | ||
{binding && <property name="binding">{binding.toValue()}</property>} | ||
</Asset> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export * from "./types"; | ||
export * from "./component"; | ||
export * from "./dsl"; | ||
export * from "./transform"; |
Oops, something went wrong.