@player-tools/devtools-client 0.5.3--canary.90.2515 → 0.5.3--canary.100.2570
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 +10 -8
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +10 -8
- package/dist/index.mjs +10 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/constants/index.ts +1 -10
- package/src/helpers/flowDiff.ts +9 -0
- package/src/panel/index.tsx +28 -6
- package/src/plugins/index.ts +10 -0
- package/src/state/__tests__/reducer.test.ts +362 -0
- package/src/state/index.ts +13 -1
- package/types/constants/index.d.ts +1 -4
- package/types/helpers/flowDiff.d.ts +9 -0
- package/types/panel/index.d.ts +22 -4
- package/types/plugins/index.d.ts +5 -0
- package/types/state/index.d.ts +8 -1
package/dist/cjs/index.cjs
CHANGED
|
@@ -43,13 +43,6 @@ var import_react6 = require("@chakra-ui/react");
|
|
|
43
43
|
var import_themes = require("@devtools-ds/themes");
|
|
44
44
|
|
|
45
45
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts
|
|
46
|
-
var import_plugin = __toESM(require("@devtools-ui/plugin"));
|
|
47
|
-
var import_pubsub_plugin = require("@player-ui/pubsub-plugin");
|
|
48
|
-
var PUBSUB_PLUGIN = new import_pubsub_plugin.PubSubPlugin();
|
|
49
|
-
var PLAYER_PLUGINS = [
|
|
50
|
-
new import_plugin.default(),
|
|
51
|
-
PUBSUB_PLUGIN
|
|
52
|
-
];
|
|
53
46
|
var INITIAL_FLOW = {
|
|
54
47
|
id: "initial-flow",
|
|
55
48
|
views: [
|
|
@@ -79,6 +72,15 @@ var INITIAL_EXTENSION_STATE = {
|
|
|
79
72
|
players: {}
|
|
80
73
|
};
|
|
81
74
|
|
|
75
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
|
|
76
|
+
var import_plugin = __toESM(require("@devtools-ui/plugin"));
|
|
77
|
+
var import_pubsub_plugin = require("@player-ui/pubsub-plugin");
|
|
78
|
+
var PUBSUB_PLUGIN = new import_pubsub_plugin.PubSubPlugin();
|
|
79
|
+
var PLAYER_PLUGINS = [
|
|
80
|
+
new import_plugin.default(),
|
|
81
|
+
PUBSUB_PLUGIN
|
|
82
|
+
];
|
|
83
|
+
|
|
82
84
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
|
|
83
85
|
var import_devtools_messenger = require("@player-tools/devtools-messenger");
|
|
84
86
|
var import_react = require("react");
|
|
@@ -274,7 +276,7 @@ var Panel = ({
|
|
|
274
276
|
const dataController = (0, import_react3.useRef)(null);
|
|
275
277
|
const currentFlow = (0, import_react3.useRef)(null);
|
|
276
278
|
(0, import_react5.useEffect)(() => {
|
|
277
|
-
reactPlayer.player.hooks.dataController.tap("panel", (d) => {
|
|
279
|
+
reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
|
|
278
280
|
dataController.current = new WeakRef(d);
|
|
279
281
|
});
|
|
280
282
|
}, [reactPlayer]);
|
package/dist/cjs/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/theme.ts"],"sourcesContent":["export { Panel } from \"./panel\";\n","import React, { useRef } from \"react\";\nimport type { MessengerOptions } from \"@player-tools/devtools-types\";\nimport type { ExtensionSupportedEvents } from \"@player-tools/devtools-types\";\nimport { DataController, Flow, useReactPlayer } from \"@player-ui/react\";\nimport { useEffect } from \"react\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport {\n Card,\n CardBody,\n CardHeader,\n ChakraProvider,\n Container,\n Flex,\n FormControl,\n FormLabel,\n Heading,\n HStack,\n Select,\n Text,\n VStack,\n} from \"@chakra-ui/react\";\nimport { ThemeProvider } from \"@devtools-ds/themes\";\n\nimport { INITIAL_FLOW, PLAYER_PLUGINS, PUBSUB_PLUGIN } from \"../constants\";\nimport { useExtensionState } from \"../state\";\nimport { flowDiff } from \"../helpers/flowDiff\";\nimport { theme } from \"./theme\";\n\nconst fallbackRender: ErrorBoundary[\"props\"][\"fallbackRender\"] = ({\n error,\n}) => {\n return (\n <Container centerContent>\n <Card>\n <CardHeader>\n <Heading>Ops, something went wrong.</Heading>\n </CardHeader>\n </Card>\n <CardBody>\n <Text as=\"pre\">{error.message}</Text>\n </CardBody>\n </Container>\n );\n};\n\n/**\n * Panel component\n *\n * devtools plugin authors can define their plugins content using DSL and have it rendered here\n */\nexport const Panel = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n readonly communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const { state, selectPlayer, selectPlugin, handleInteraction } =\n useExtensionState({\n communicationLayer,\n });\n\n const { reactPlayer } = useReactPlayer({\n plugins: PLAYER_PLUGINS,\n });\n\n const dataController = useRef<WeakRef<DataController> | null>(null);\n\n const currentFlow = useRef<Flow | null>(null);\n\n useEffect(() => {\n reactPlayer.player.hooks.dataController.tap(\"panel\", (d) => {\n dataController.current = new WeakRef(d);\n });\n }, [reactPlayer]);\n\n useEffect(() => {\n // we subscribe to all messages from the devtools plugin\n // so the plugin author can define their own events\n PUBSUB_PLUGIN.subscribe(\"*\", (type: string, payload: string) => {\n handleInteraction({\n type,\n payload,\n });\n });\n }, []);\n\n useEffect(() => {\n const { player, plugin } = state.current;\n\n const flow =\n player && plugin\n ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW\n : INITIAL_FLOW;\n\n if (!currentFlow.current) {\n currentFlow.current = flow;\n reactPlayer.start(flow);\n return;\n }\n\n const diff = flowDiff({\n curr: currentFlow.current as Flow,\n next: flow,\n });\n\n if (diff) {\n const { change, value } = diff;\n\n if (change === \"flow\") {\n currentFlow.current = value;\n reactPlayer.start(value);\n } else if (change === \"data\") {\n dataController.current\n ? dataController.current\n .deref()\n ?.set(value as Record<string, unknown>)\n : reactPlayer.start(flow);\n }\n }\n }, [reactPlayer, state]);\n\n const Component = reactPlayer.Component as React.FC;\n\n return (\n <ChakraProvider theme={theme}>\n <ThemeProvider colorScheme=\"dark\">\n <ErrorBoundary fallbackRender={fallbackRender}>\n <VStack w=\"100vw\" h=\"100vh\">\n {state.current.player ? (\n <Flex direction=\"column\" marginTop=\"4\">\n <HStack spacing=\"4\">\n <FormControl>\n <FormLabel>Player</FormLabel>\n <Select\n id=\"player\"\n value={state.current.player || \"\"}\n onChange={(event) => selectPlayer(event.target.value)}\n >\n {Object.keys(state.players).map((playerID) => (\n <option key={playerID} value={playerID}>\n {playerID}\n </option>\n ))}\n </Select>\n </FormControl>\n <FormControl>\n <FormLabel>Plugin</FormLabel>\n <Select\n id=\"plugin\"\n value={state.current.plugin || \"\"}\n onChange={(event) => selectPlugin(event.target.value)}\n >\n {Object.keys(\n state.players[state.current.player].plugins\n ).map((pluginID) => (\n <option key={pluginID} value={pluginID}>\n {pluginID}\n </option>\n ))}\n </Select>\n </FormControl>\n </HStack>\n <Container marginY=\"6\">\n <Component />\n </Container>\n <details>\n <summary>Debug</summary>\n <pre>{JSON.stringify(state, null, 2)}</pre>\n </details>\n </Flex>\n ) : (\n <Flex justifyContent=\"center\" padding=\"6\">\n <Text>\n No Player-UI instance or devtools plugin detected. Visit{\" \"}\n <a href=\"https://player-ui.github.io/\">\n https://player-ui.github.io/\n </a>{\" \"}\n for more info.\n </Text>\n </Flex>\n )}\n </VStack>\n </ErrorBoundary>\n </ThemeProvider>\n </ChakraProvider>\n );\n};\n","import type { ExtensionState } from \"@player-tools/devtools-types\";\nimport type { Flow, ReactPlayerPlugin } from \"@player-ui/react\";\nimport DevtoolsUIAssetsPlugin from \"@devtools-ui/plugin\";\nimport { PubSubPlugin } from \"@player-ui/pubsub-plugin\";\n\nexport const PUBSUB_PLUGIN = new PubSubPlugin();\n\nexport const PLAYER_PLUGINS: ReactPlayerPlugin[] = [\n new DevtoolsUIAssetsPlugin(),\n PUBSUB_PLUGIN,\n];\n\nexport const INITIAL_FLOW: Flow = {\n id: \"initial-flow\",\n views: [\n {\n id: \"view-1\",\n type: \"text\",\n value: \"connecting...\",\n },\n ],\n navigation: {\n BEGIN: \"FLOW_1\",\n FLOW_1: {\n startState: \"VIEW_1\",\n VIEW_1: {\n state_type: \"VIEW\",\n ref: \"view-1\",\n transitions: {},\n },\n },\n },\n};\n\nexport const INITIAL_EXTENSION_STATE: ExtensionState = {\n current: {\n player: null,\n plugin: null,\n },\n players: {},\n};\n","import { Messenger } from \"@player-tools/devtools-messenger\";\nimport type {\n ExtensionSupportedEvents,\n MessengerOptions,\n} from \"@player-tools/devtools-types\";\nimport { useCallback, useEffect, useMemo, useReducer } from \"react\";\n\nimport { INITIAL_EXTENSION_STATE } from \"../constants\";\nimport { reducer } from \"./reducer\";\n\nconst NOOP_ID = -1;\n\n/** Extension state */\nexport const useExtensionState = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);\n\n const messengerOptions = useMemo<MessengerOptions<ExtensionSupportedEvents>>(\n () => ({\n context: \"devtools\",\n target: \"player\",\n messageCallback: (message) => {\n dispatch(message);\n },\n ...communicationLayer,\n logger: console,\n }),\n [dispatch, communicationLayer]\n );\n\n const messenger = useMemo(\n () => new Messenger(messengerOptions),\n [messengerOptions]\n );\n\n useEffect(() => {\n return () => {\n messenger.destroy();\n };\n }, []);\n\n const selectPlayer = useCallback(\n (playerID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLAYER_SELECTED\",\n payload: {\n playerID,\n },\n });\n },\n [dispatch]\n );\n\n const selectPlugin = useCallback(\n (pluginID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\",\n payload: {\n pluginID,\n },\n });\n },\n [dispatch]\n );\n\n const handleInteraction = useCallback(\n ({\n type,\n payload,\n }: {\n /** interaction type */\n type: string;\n /** interaction payload */\n payload?: string;\n }) => {\n messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type,\n payload,\n },\n });\n },\n [messenger]\n );\n\n return { state, selectPlayer, selectPlugin, handleInteraction };\n};\n","import type {\n ExtensionState,\n ExtensionSupportedEvents,\n Transaction,\n} from \"@player-tools/devtools-types\";\nimport { dset } from \"dset/merge\";\nimport { produce } from \"immer\";\n\n/** Extension state reducer */\nexport const reducer = (\n state: ExtensionState,\n transaction: Transaction<ExtensionSupportedEvents>\n): ExtensionState => {\n switch (transaction.type) {\n case \"PLAYER_DEVTOOLS_PLAYER_INIT\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { plugins },\n } = transaction;\n const { player, plugin } = draft.current;\n\n if (!player && !plugin) {\n // if there is no player and plugin selected, select the first one:\n dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n plugins[Object.keys(plugins)[0]].id\n );\n }\n\n dset(draft, [\"players\", sender, \"plugins\"], plugins);\n dset(draft, [\"players\", sender, \"active\"], true);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { flow, pluginID },\n } = transaction;\n\n dset(draft, [\"players\", sender, \"plugins\", pluginID, \"flow\"], flow);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { data, pluginID },\n } = transaction;\n dset(\n draft,\n [\"players\", sender, \"plugins\", pluginID, \"flow\", \"data\"],\n data\n );\n });\n case \"MESSENGER_EVENT_BATCH\":\n return produce(state, (draft) => {\n return transaction.payload.events.reduce(reducer, draft);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_STOPPED\":\n return produce(state, (draft) => {\n const { sender } = transaction;\n\n dset(draft, [\"players\", sender, \"active\"], false);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_SELECTED\":\n return produce(state, (draft) => {\n const { playerID } = transaction.payload;\n dset(draft, [\"current\", \"player\"], playerID);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\":\n return produce(state, (draft) => {\n const { pluginID } = transaction.payload;\n dset(draft, [\"current\", \"plugin\"], pluginID);\n });\n default:\n return state;\n }\n};\n","import type { Flow } from \"@player-ui/react\";\nimport { dequal } from \"dequal\";\n\nexport const flowDiff = ({\n curr,\n next,\n}: {\n curr: Flow;\n next: Flow;\n}):\n | { change: \"data\"; value: Flow[\"data\"] }\n | { change: \"flow\"; value: Flow }\n | null => {\n // compare flows except for the `data` property\n const currCopy = { ...curr, data: null };\n const nextCopy = { ...next, data: null };\n\n const baseFlowIsEqual = dequal(currCopy, nextCopy);\n\n if (!baseFlowIsEqual) {\n return { change: \"flow\", value: next };\n }\n\n // compare data\n const currData = curr.data;\n const nextData = next.data;\n\n const dataIsEqual = dequal(currData, nextData);\n\n if (!dataIsEqual) {\n return { change: \"data\", value: nextData };\n }\n\n return null;\n};\n","import { extendTheme, type ThemeConfig } from \"@chakra-ui/react\";\n\nconst config: ThemeConfig = {\n initialColorMode: \"dark\",\n useSystemColorMode: false,\n};\n\nexport const theme = extendTheme({ config });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8B;AAG9B,IAAAA,gBAAqD;AACrD,IAAAA,gBAA0B;AAC1B,kCAA8B;AAC9B,IAAAA,gBAcO;AACP,oBAA8B;;;ACnB9B,oBAAmC;AACnC,2BAA6B;AAEtB,IAAM,gBAAgB,IAAI,kCAAa;AAEvC,IAAM,iBAAsC;AAAA,EACjD,IAAI,cAAAC,QAAuB;AAAA,EAC3B;AACF;AAEO,IAAM,eAAqB;AAAA,EAChC,IAAI;AAAA,EACJ,OAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,MACN,YAAY;AAAA,MACZ,QAAQ;AAAA,QACN,YAAY;AAAA,QACZ,KAAK;AAAA,QACL,aAAa,CAAC;AAAA,MAChB;AAAA,IACF;AAAA,EACF;AACF;AAEO,IAAM,0BAA0C;AAAA,EACrD,SAAS;AAAA,IACP,QAAQ;AAAA,IACR,QAAQ;AAAA,EACV;AAAA,EACA,SAAS,CAAC;AACZ;;;ACxCA,gCAA0B;AAK1B,mBAA4D;;;ACA5D,mBAAqB;AACrB,mBAAwB;AAGjB,IAAM,UAAU,CACrB,OACA,gBACmB;AACnB,UAAQ,YAAY,MAAM;AAAA,IACxB,KAAK;AACH,iBAAO,sBAAQ,OAAO,CAAC,UAAU;AAC/B,cAAM;AAAA,UACJ;AAAA,UACA,SAAS,EAAE,QAAQ;AAAA,QACrB,IAAI;AACJ,cA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BAAAA,QAAA,cAAC,eAAU,CACb,GACA,8BAAAA,QAAA,cAAC,iBACC,8BAAAA,QAAA,cAAC,iBAAQ,OAAK,GACd,8BAAAA,QAAA,cAAC,aAAK,KAAK,UAAU,OAAO,MAAM,CAAC,CAAE,CACvC,CACF,IAEA,8BAAAA,QAAA,cAAC,sBAAK,gBAAe,UAAS,SAAQ,OACpC,8BAAAA,QAAA,cAAC,0BAAK,4DACqD,KACzD,8BAAAA,QAAA,cAAC,OAAE,MAAK,kCAA+B,8BAEvC,GAAK,KAAI,gBAEX,CACF,CAEJ,CACF,CACF,CACF;AAEJ;","names":["import_react","DevtoolsUIAssetsPlugin","import_react","React"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts","../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/theme.ts"],"sourcesContent":["export { Panel } from \"./panel\";\n","import React, { useRef } from \"react\";\nimport type {\n MessengerOptions,\n ExtensionSupportedEvents,\n} from \"@player-tools/devtools-types\";\nimport { DataController, Flow, useReactPlayer } from \"@player-ui/react\";\nimport { useEffect } from \"react\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport {\n Card,\n CardBody,\n CardHeader,\n ChakraProvider,\n Container,\n Flex,\n FormControl,\n FormLabel,\n Heading,\n HStack,\n Select,\n Text,\n VStack,\n} from \"@chakra-ui/react\";\nimport { ThemeProvider } from \"@devtools-ds/themes\";\n\nimport { INITIAL_FLOW } from \"../constants\";\nimport { PLAYER_PLUGINS, PUBSUB_PLUGIN } from \"../plugins\";\nimport { useExtensionState } from \"../state\";\nimport { flowDiff } from \"../helpers/flowDiff\";\nimport { theme } from \"./theme\";\n\nconst fallbackRender: ErrorBoundary[\"props\"][\"fallbackRender\"] = ({\n error,\n}) => {\n return (\n <Container centerContent>\n <Card>\n <CardHeader>\n <Heading>Ops, something went wrong.</Heading>\n </CardHeader>\n </Card>\n <CardBody>\n <Text as=\"pre\">{error.message}</Text>\n </CardBody>\n </Container>\n );\n};\n\n/**\n * Panel Component\n *\n * This component serves as the main container for the devtools plugin content defined by plugin authors using Player-UI DSL.\n *\n * Props:\n * - `communicationLayer`: An object that allows communication between the devtools and the Player-UI plugins,\n * enabling the exchange of data and events.\n *\n * Features:\n * - Error Handling: Utilizes the `ErrorBoundary` component from `react-error-boundary` to gracefully handle and display errors\n * that may occur during the rendering of the plugin's content.\n * - State Management: Integrates with custom hooks such as `useExtensionState` to manage the state of the plugin and its components.\n * - Player Integration: Uses the `useReactPlayer` hook from `player-ui/react` to render interactive player components based on the\n * DSL defined by the plugin authors.\n *\n * Example Usage:\n * ```tsx\n * <Panel communicationLayer={myCommunicationLayer} />\n * ```\n *\n * Note: The `communicationLayer` prop is essential for the proper functioning of the `Panel` component, as it enables the necessary\n * communication and data exchange with the player-ui/react library.\n */\nexport const Panel = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n readonly communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const { state, selectPlayer, selectPlugin, handleInteraction } =\n useExtensionState({\n communicationLayer,\n });\n\n const { reactPlayer } = useReactPlayer({\n plugins: PLAYER_PLUGINS,\n });\n\n const dataController = useRef<WeakRef<DataController> | null>(null);\n\n const currentFlow = useRef<Flow | null>(null);\n\n useEffect(() => {\n reactPlayer.player.hooks.dataController.tap(\"devtools-panel\", (d) => {\n dataController.current = new WeakRef(d);\n });\n }, [reactPlayer]);\n\n useEffect(() => {\n // we subscribe to all messages from the devtools plugin\n // so the plugin author can define their own events\n PUBSUB_PLUGIN.subscribe(\"*\", (type: string, payload: string) => {\n handleInteraction({\n type,\n payload,\n });\n });\n }, []);\n\n useEffect(() => {\n const { player, plugin } = state.current;\n\n const flow =\n player && plugin\n ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW\n : INITIAL_FLOW;\n\n if (!currentFlow.current) {\n currentFlow.current = flow;\n reactPlayer.start(flow);\n return;\n }\n\n const diff = flowDiff({\n curr: currentFlow.current as Flow,\n next: flow,\n });\n\n if (diff) {\n const { change, value } = diff;\n\n if (change === \"flow\") {\n currentFlow.current = value;\n reactPlayer.start(value);\n } else if (change === \"data\") {\n dataController.current\n ? dataController.current\n .deref()\n ?.set(value as Record<string, unknown>)\n : reactPlayer.start(flow);\n }\n }\n }, [reactPlayer, state]);\n\n const Component = reactPlayer.Component as React.FC;\n\n return (\n <ChakraProvider theme={theme}>\n <ThemeProvider colorScheme=\"dark\">\n <ErrorBoundary fallbackRender={fallbackRender}>\n <VStack w=\"100vw\" h=\"100vh\">\n {state.current.player ? (\n <Flex direction=\"column\" marginTop=\"4\">\n <HStack spacing=\"4\">\n <FormControl>\n <FormLabel>Player</FormLabel>\n <Select\n id=\"player\"\n value={state.current.player || \"\"}\n onChange={(event) => selectPlayer(event.target.value)}\n >\n {Object.keys(state.players).map((playerID) => (\n <option key={playerID} value={playerID}>\n {playerID}\n </option>\n ))}\n </Select>\n </FormControl>\n <FormControl>\n <FormLabel>Plugin</FormLabel>\n <Select\n id=\"plugin\"\n value={state.current.plugin || \"\"}\n onChange={(event) => selectPlugin(event.target.value)}\n >\n {Object.keys(\n state.players[state.current.player].plugins\n ).map((pluginID) => (\n <option key={pluginID} value={pluginID}>\n {pluginID}\n </option>\n ))}\n </Select>\n </FormControl>\n </HStack>\n <Container marginY=\"6\">\n <Component />\n </Container>\n <details>\n <summary>Debug</summary>\n <pre>{JSON.stringify(state, null, 2)}</pre>\n </details>\n </Flex>\n ) : (\n <Flex justifyContent=\"center\" padding=\"6\">\n <Text>\n No Player-UI instance or devtools plugin detected. Visit{\" \"}\n <a href=\"https://player-ui.github.io/\">\n https://player-ui.github.io/\n </a>{\" \"}\n for more info.\n </Text>\n </Flex>\n )}\n </VStack>\n </ErrorBoundary>\n </ThemeProvider>\n </ChakraProvider>\n );\n};\n","import type { ExtensionState } from \"@player-tools/devtools-types\";\nimport type { Flow } from \"@player-ui/react\";\n\nexport const INITIAL_FLOW: Flow = {\n id: \"initial-flow\",\n views: [\n {\n id: \"view-1\",\n type: \"text\",\n value: \"connecting...\",\n },\n ],\n navigation: {\n BEGIN: \"FLOW_1\",\n FLOW_1: {\n startState: \"VIEW_1\",\n VIEW_1: {\n state_type: \"VIEW\",\n ref: \"view-1\",\n transitions: {},\n },\n },\n },\n};\n\nexport const INITIAL_EXTENSION_STATE: ExtensionState = {\n current: {\n player: null,\n plugin: null,\n },\n players: {},\n};\n","import DevtoolsUIAssetsPlugin from \"@devtools-ui/plugin\";\nimport { PubSubPlugin } from \"@player-ui/pubsub-plugin\";\nimport type { ReactPlayerPlugin } from \"@player-ui/react\";\n\nexport const PUBSUB_PLUGIN = new PubSubPlugin();\n\nexport const PLAYER_PLUGINS: ReactPlayerPlugin[] = [\n new DevtoolsUIAssetsPlugin(),\n PUBSUB_PLUGIN,\n];\n","import { Messenger } from \"@player-tools/devtools-messenger\";\nimport type {\n ExtensionSupportedEvents,\n MessengerOptions,\n} from \"@player-tools/devtools-types\";\nimport { useCallback, useEffect, useMemo, useReducer } from \"react\";\n\nimport { INITIAL_EXTENSION_STATE } from \"../constants\";\nimport { reducer } from \"./reducer\";\n\nconst NOOP_ID = -1;\n\n/**\n * Custom React hook for managing the state of the devtools extension.\n *\n * This hook initializes the extension's state and sets up a communication layer\n * using the `Messenger` class. It provides methods to select a player or plugin,\n * and handle interactions, which dispatch actions to update the state accordingly.\n *\n */\nexport const useExtensionState = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);\n\n const messengerOptions = useMemo<MessengerOptions<ExtensionSupportedEvents>>(\n () => ({\n context: \"devtools\",\n target: \"player\",\n messageCallback: (message) => {\n dispatch(message);\n },\n ...communicationLayer,\n logger: console,\n }),\n [dispatch, communicationLayer]\n );\n\n const messenger = useMemo(\n () => new Messenger(messengerOptions),\n [messengerOptions]\n );\n\n useEffect(() => {\n return () => {\n messenger.destroy();\n };\n }, []);\n\n const selectPlayer = useCallback(\n (playerID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLAYER_SELECTED\",\n payload: {\n playerID,\n },\n });\n },\n [dispatch]\n );\n\n const selectPlugin = useCallback(\n (pluginID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\",\n payload: {\n pluginID,\n },\n });\n },\n [dispatch]\n );\n\n /**\n * Plugin authors can add interactive elements to the Player-UI content by leveraging\n * the pub-sub plugin and having the handle interaction proxy the message to the inspected\n * Player-UI instance.\n */\n const handleInteraction = useCallback(\n ({\n type,\n payload,\n }: {\n /** interaction type */\n type: string;\n /** interaction payload */\n payload?: string;\n }) => {\n messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type,\n payload,\n },\n });\n },\n [messenger]\n );\n\n return { state, selectPlayer, selectPlugin, handleInteraction };\n};\n","import type {\n ExtensionState,\n ExtensionSupportedEvents,\n Transaction,\n} from \"@player-tools/devtools-types\";\nimport { dset } from \"dset/merge\";\nimport { produce } from \"immer\";\n\n/** Extension state reducer */\nexport const reducer = (\n state: ExtensionState,\n transaction: Transaction<ExtensionSupportedEvents>\n): ExtensionState => {\n switch (transaction.type) {\n case \"PLAYER_DEVTOOLS_PLAYER_INIT\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { plugins },\n } = transaction;\n const { player, plugin } = draft.current;\n\n if (!player && !plugin) {\n // if there is no player and plugin selected, select the first one:\n dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n plugins[Object.keys(plugins)[0]].id\n );\n }\n\n dset(draft, [\"players\", sender, \"plugins\"], plugins);\n dset(draft, [\"players\", sender, \"active\"], true);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { flow, pluginID },\n } = transaction;\n\n dset(draft, [\"players\", sender, \"plugins\", pluginID, \"flow\"], flow);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { data, pluginID },\n } = transaction;\n dset(\n draft,\n [\"players\", sender, \"plugins\", pluginID, \"flow\", \"data\"],\n data\n );\n });\n case \"MESSENGER_EVENT_BATCH\":\n return produce(state, (draft) => {\n return transaction.payload.events.reduce(reducer, draft);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_STOPPED\":\n return produce(state, (draft) => {\n const { sender } = transaction;\n\n dset(draft, [\"players\", sender, \"active\"], false);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_SELECTED\":\n return produce(state, (draft) => {\n const { playerID } = transaction.payload;\n dset(draft, [\"current\", \"player\"], playerID);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\":\n return produce(state, (draft) => {\n const { pluginID } = transaction.payload;\n dset(draft, [\"current\", \"plugin\"], pluginID);\n });\n default:\n return state;\n }\n};\n","import type { Flow } from \"@player-ui/react\";\nimport { dequal } from \"dequal\";\n\n/**\n * Compares two Flow objects and identifies if there's a change in their structure or data.\n *\n * This function takes two Flow objects as input, `curr` (current) and `next` (next), and compares them\n * to determine if there's a change in the flow's structure or its data. If there's a change in the flow's\n * structure (excluding the `data` property), it returns an object indicating a \"flow\" change along with the\n * new flow. If there's a change in the `data` property, it returns an object indicating a \"data\" change along\n * with the new data. If there are no changes, it returns null.\n */\nexport const flowDiff = ({\n curr,\n next,\n}: {\n curr: Flow;\n next: Flow;\n}):\n | { change: \"data\"; value: Flow[\"data\"] }\n | { change: \"flow\"; value: Flow }\n | null => {\n // compare flows except for the `data` property\n const currCopy = { ...curr, data: null };\n const nextCopy = { ...next, data: null };\n\n const baseFlowIsEqual = dequal(currCopy, nextCopy);\n\n if (!baseFlowIsEqual) {\n return { change: \"flow\", value: next };\n }\n\n // compare data\n const currData = curr.data;\n const nextData = next.data;\n\n const dataIsEqual = dequal(currData, nextData);\n\n if (!dataIsEqual) {\n return { change: \"data\", value: nextData };\n }\n\n return null;\n};\n","import { extendTheme, type ThemeConfig } from \"@chakra-ui/react\";\n\nconst config: ThemeConfig = {\n initialColorMode: \"dark\",\n useSystemColorMode: false,\n};\n\nexport const theme = extendTheme({ config });\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,IAAAA,gBAA8B;AAK9B,IAAAA,gBAAqD;AACrD,IAAAA,gBAA0B;AAC1B,kCAA8B;AAC9B,IAAAA,gBAcO;AACP,oBAA8B;;;ACpBvB,IAAM,eAAqB;AAAA,EAChC,IAAI;AAAA,EACJ,OAAO;AAAA,IACL;AAAA,MACE,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,OAAO;AAAA,IACT;AAAA,EACF;AAAA,EACA,YAAY;AAAA,IACV,OAAO;AAAA,IACP,QAAQ;AAAA,MACN,YAAY;AAAA,MACZ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C,UAAU,aAAa,MAAM,OAAO,KAAK;AAAA;AAAA,IAEnD,OAAO,KAAK,MAAM,OAAO,EAAE,IAAI,CAAC,aAC/B,8BAAAA,QAAA,cAAC,YAAO,KAAK,UAAU,OAAO,YAC3B,QACH,CACD;AAAA,EACH,CACF,GACA,8BAAAA,QAAA,cAAC,iCACC,8BAAAA,QAAA,cAAC,+BAAU,QAAM,GACjB,8BAAAA,QAAA;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH,OAAO,MAAM,QAAQ,UAAU;AAAA,MAC/B,UAAU,CAAC,UAAU,aAAa,MAAM,OAAO,KAAK;AAAA;AAAA,IAEnD,OAAO;AAAA,MACN,MAAM,QAAQ,MAAM,QAAQ,MAAM,EAAE;AAAA,IACtC,EAAE,IAAI,CAAC,aACL,8BAAAA,QAAA,cAAC,YAAO,KAAK,UAAU,OAAO,YAC3B,QACH,CACD;AAAA,EACH,CACF,CACF,GACA,8BAAAA,QAAA,cAAC,2BAAU,SAAQ,OACjB,8BAAAA,QAAA,cAAC,eAAU,CACb,GACA,8BAAAA,QAAA,cAAC,iBACC,8BAAAA,QAAA,cAAC,iBAAQ,OAAK,GACd,8BAAAA,QAAA,cAAC,aAAK,KAAK,UAAU,OAAO,MAAM,CAAC,CAAE,CACvC,CACF,IAEA,8BAAAA,QAAA,cAAC,sBAAK,gBAAe,UAAS,SAAQ,OACpC,8BAAAA,QAAA,cAAC,0BAAK,4DACqD,KACzD,8BAAAA,QAAA,cAAC,OAAE,MAAK,kCAA+B,8BAEvC,GAAK,KAAI,gBAEX,CACF,CAEJ,CACF,CACF,CACF;AAEJ;","names":["import_react","DevtoolsUIAssetsPlugin","import_react","React"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -21,13 +21,6 @@ import {
|
|
|
21
21
|
import { ThemeProvider } from "@devtools-ds/themes";
|
|
22
22
|
|
|
23
23
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts
|
|
24
|
-
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
25
|
-
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
26
|
-
var PUBSUB_PLUGIN = new PubSubPlugin();
|
|
27
|
-
var PLAYER_PLUGINS = [
|
|
28
|
-
new DevtoolsUIAssetsPlugin(),
|
|
29
|
-
PUBSUB_PLUGIN
|
|
30
|
-
];
|
|
31
24
|
var INITIAL_FLOW = {
|
|
32
25
|
id: "initial-flow",
|
|
33
26
|
views: [
|
|
@@ -57,6 +50,15 @@ var INITIAL_EXTENSION_STATE = {
|
|
|
57
50
|
players: {}
|
|
58
51
|
};
|
|
59
52
|
|
|
53
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
|
|
54
|
+
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
55
|
+
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
56
|
+
var PUBSUB_PLUGIN = new PubSubPlugin();
|
|
57
|
+
var PLAYER_PLUGINS = [
|
|
58
|
+
new DevtoolsUIAssetsPlugin(),
|
|
59
|
+
PUBSUB_PLUGIN
|
|
60
|
+
];
|
|
61
|
+
|
|
60
62
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
|
|
61
63
|
import { Messenger } from "@player-tools/devtools-messenger";
|
|
62
64
|
import { useCallback, useEffect, useMemo, useReducer } from "react";
|
|
@@ -252,7 +254,7 @@ var Panel = ({
|
|
|
252
254
|
const dataController = useRef(null);
|
|
253
255
|
const currentFlow = useRef(null);
|
|
254
256
|
useEffect2(() => {
|
|
255
|
-
reactPlayer.player.hooks.dataController.tap("panel", (d) => {
|
|
257
|
+
reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
|
|
256
258
|
dataController.current = new WeakRef(d);
|
|
257
259
|
});
|
|
258
260
|
}, [reactPlayer]);
|
package/dist/index.mjs
CHANGED
|
@@ -21,13 +21,6 @@ import {
|
|
|
21
21
|
import { ThemeProvider } from "@devtools-ds/themes";
|
|
22
22
|
|
|
23
23
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts
|
|
24
|
-
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
25
|
-
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
26
|
-
var PUBSUB_PLUGIN = new PubSubPlugin();
|
|
27
|
-
var PLAYER_PLUGINS = [
|
|
28
|
-
new DevtoolsUIAssetsPlugin(),
|
|
29
|
-
PUBSUB_PLUGIN
|
|
30
|
-
];
|
|
31
24
|
var INITIAL_FLOW = {
|
|
32
25
|
id: "initial-flow",
|
|
33
26
|
views: [
|
|
@@ -57,6 +50,15 @@ var INITIAL_EXTENSION_STATE = {
|
|
|
57
50
|
players: {}
|
|
58
51
|
};
|
|
59
52
|
|
|
53
|
+
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
|
|
54
|
+
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
55
|
+
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
56
|
+
var PUBSUB_PLUGIN = new PubSubPlugin();
|
|
57
|
+
var PLAYER_PLUGINS = [
|
|
58
|
+
new DevtoolsUIAssetsPlugin(),
|
|
59
|
+
PUBSUB_PLUGIN
|
|
60
|
+
];
|
|
61
|
+
|
|
60
62
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
|
|
61
63
|
import { Messenger } from "@player-tools/devtools-messenger";
|
|
62
64
|
import { useCallback, useEffect, useMemo, useReducer } from "react";
|
|
@@ -252,7 +254,7 @@ var Panel = ({
|
|
|
252
254
|
const dataController = useRef(null);
|
|
253
255
|
const currentFlow = useRef(null);
|
|
254
256
|
useEffect2(() => {
|
|
255
|
-
reactPlayer.player.hooks.dataController.tap("panel", (d) => {
|
|
257
|
+
reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
|
|
256
258
|
dataController.current = new WeakRef(d);
|
|
257
259
|
});
|
|
258
260
|
}, [reactPlayer]);
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/theme.ts"],"sourcesContent":["import React, { useRef } from \"react\";\nimport type { MessengerOptions } from \"@player-tools/devtools-types\";\nimport type { ExtensionSupportedEvents } from \"@player-tools/devtools-types\";\nimport { DataController, Flow, useReactPlayer } from \"@player-ui/react\";\nimport { useEffect } from \"react\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport {\n Card,\n CardBody,\n CardHeader,\n ChakraProvider,\n Container,\n Flex,\n FormControl,\n FormLabel,\n Heading,\n HStack,\n Select,\n Text,\n VStack,\n} from \"@chakra-ui/react\";\nimport { ThemeProvider } from \"@devtools-ds/themes\";\n\nimport { INITIAL_FLOW, PLAYER_PLUGINS, PUBSUB_PLUGIN } from \"../constants\";\nimport { useExtensionState } from \"../state\";\nimport { flowDiff } from \"../helpers/flowDiff\";\nimport { theme } from \"./theme\";\n\nconst fallbackRender: ErrorBoundary[\"props\"][\"fallbackRender\"] = ({\n error,\n}) => {\n return (\n <Container centerContent>\n <Card>\n <CardHeader>\n <Heading>Ops, something went wrong.</Heading>\n </CardHeader>\n </Card>\n <CardBody>\n <Text as=\"pre\">{error.message}</Text>\n </CardBody>\n </Container>\n );\n};\n\n/**\n * Panel component\n *\n * devtools plugin authors can define their plugins content using DSL and have it rendered here\n */\nexport const Panel = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n readonly communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const { state, selectPlayer, selectPlugin, handleInteraction } =\n useExtensionState({\n communicationLayer,\n });\n\n const { reactPlayer } = useReactPlayer({\n plugins: PLAYER_PLUGINS,\n });\n\n const dataController = useRef<WeakRef<DataController> | null>(null);\n\n const currentFlow = useRef<Flow | null>(null);\n\n useEffect(() => {\n reactPlayer.player.hooks.dataController.tap(\"panel\", (d) => {\n dataController.current = new WeakRef(d);\n });\n }, [reactPlayer]);\n\n useEffect(() => {\n // we subscribe to all messages from the devtools plugin\n // so the plugin author can define their own events\n PUBSUB_PLUGIN.subscribe(\"*\", (type: string, payload: string) => {\n handleInteraction({\n type,\n payload,\n });\n });\n }, []);\n\n useEffect(() => {\n const { player, plugin } = state.current;\n\n const flow =\n player && plugin\n ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW\n : INITIAL_FLOW;\n\n if (!currentFlow.current) {\n currentFlow.current = flow;\n reactPlayer.start(flow);\n return;\n }\n\n const diff = flowDiff({\n curr: currentFlow.current as Flow,\n next: flow,\n });\n\n if (diff) {\n const { change, value } = diff;\n\n if (change === \"flow\") {\n currentFlow.current = value;\n reactPlayer.start(value);\n } else if (change === \"data\") {\n dataController.current\n ? dataController.current\n .deref()\n ?.set(value as Record<string, unknown>)\n : reactPlayer.start(flow);\n }\n }\n }, [reactPlayer, state]);\n\n const Component = reactPlayer.Component as React.FC;\n\n return (\n <ChakraProvider theme={theme}>\n <ThemeProvider colorScheme=\"dark\">\n <ErrorBoundary fallbackRender={fallbackRender}>\n <VStack w=\"100vw\" h=\"100vh\">\n {state.current.player ? (\n <Flex direction=\"column\" marginTop=\"4\">\n <HStack spacing=\"4\">\n <FormControl>\n <FormLabel>Player</FormLabel>\n <Select\n id=\"player\"\n value={state.current.player || \"\"}\n onChange={(event) => selectPlayer(event.target.value)}\n >\n {Object.keys(state.players).map((playerID) => (\n <option key={playerID} value={playerID}>\n {playerID}\n </option>\n ))}\n </Select>\n </FormControl>\n <FormControl>\n <FormLabel>Plugin</FormLabel>\n <Select\n id=\"plugin\"\n value={state.current.plugin || \"\"}\n onChange={(event) => selectPlugin(event.target.value)}\n >\n {Object.keys(\n state.players[state.current.player].plugins\n ).map((pluginID) => (\n <option key={pluginID} value={pluginID}>\n {pluginID}\n </option>\n ))}\n </Select>\n </FormControl>\n </HStack>\n <Container marginY=\"6\">\n <Component />\n </Container>\n <details>\n <summary>Debug</summary>\n <pre>{JSON.stringify(state, null, 2)}</pre>\n </details>\n </Flex>\n ) : (\n <Flex justifyContent=\"center\" padding=\"6\">\n <Text>\n No Player-UI instance or devtools plugin detected. Visit{\" \"}\n <a href=\"https://player-ui.github.io/\">\n https://player-ui.github.io/\n </a>{\" \"}\n for more info.\n </Text>\n </Flex>\n )}\n </VStack>\n </ErrorBoundary>\n </ThemeProvider>\n </ChakraProvider>\n );\n};\n","import type { ExtensionState } from \"@player-tools/devtools-types\";\nimport type { Flow, ReactPlayerPlugin } from \"@player-ui/react\";\nimport DevtoolsUIAssetsPlugin from \"@devtools-ui/plugin\";\nimport { PubSubPlugin } from \"@player-ui/pubsub-plugin\";\n\nexport const PUBSUB_PLUGIN = new PubSubPlugin();\n\nexport const PLAYER_PLUGINS: ReactPlayerPlugin[] = [\n new DevtoolsUIAssetsPlugin(),\n PUBSUB_PLUGIN,\n];\n\nexport const INITIAL_FLOW: Flow = {\n id: \"initial-flow\",\n views: [\n {\n id: \"view-1\",\n type: \"text\",\n value: \"connecting...\",\n },\n ],\n navigation: {\n BEGIN: \"FLOW_1\",\n FLOW_1: {\n startState: \"VIEW_1\",\n VIEW_1: {\n state_type: \"VIEW\",\n ref: \"view-1\",\n transitions: {},\n },\n },\n },\n};\n\nexport const INITIAL_EXTENSION_STATE: ExtensionState = {\n current: {\n player: null,\n plugin: null,\n },\n players: {},\n};\n","import { Messenger } from \"@player-tools/devtools-messenger\";\nimport type {\n ExtensionSupportedEvents,\n MessengerOptions,\n} from \"@player-tools/devtools-types\";\nimport { useCallback, useEffect, useMemo, useReducer } from \"react\";\n\nimport { INITIAL_EXTENSION_STATE } from \"../constants\";\nimport { reducer } from \"./reducer\";\n\nconst NOOP_ID = -1;\n\n/** Extension state */\nexport const useExtensionState = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);\n\n const messengerOptions = useMemo<MessengerOptions<ExtensionSupportedEvents>>(\n () => ({\n context: \"devtools\",\n target: \"player\",\n messageCallback: (message) => {\n dispatch(message);\n },\n ...communicationLayer,\n logger: console,\n }),\n [dispatch, communicationLayer]\n );\n\n const messenger = useMemo(\n () => new Messenger(messengerOptions),\n [messengerOptions]\n );\n\n useEffect(() => {\n return () => {\n messenger.destroy();\n };\n }, []);\n\n const selectPlayer = useCallback(\n (playerID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLAYER_SELECTED\",\n payload: {\n playerID,\n },\n });\n },\n [dispatch]\n );\n\n const selectPlugin = useCallback(\n (pluginID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\",\n payload: {\n pluginID,\n },\n });\n },\n [dispatch]\n );\n\n const handleInteraction = useCallback(\n ({\n type,\n payload,\n }: {\n /** interaction type */\n type: string;\n /** interaction payload */\n payload?: string;\n }) => {\n messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type,\n payload,\n },\n });\n },\n [messenger]\n );\n\n return { state, selectPlayer, selectPlugin, handleInteraction };\n};\n","import type {\n ExtensionState,\n ExtensionSupportedEvents,\n Transaction,\n} from \"@player-tools/devtools-types\";\nimport { dset } from \"dset/merge\";\nimport { produce } from \"immer\";\n\n/** Extension state reducer */\nexport const reducer = (\n state: ExtensionState,\n transaction: Transaction<ExtensionSupportedEvents>\n): ExtensionState => {\n switch (transaction.type) {\n case \"PLAYER_DEVTOOLS_PLAYER_INIT\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { plugins },\n } = transaction;\n const { player, plugin } = draft.current;\n\n if (!player && !plugin) {\n // if there is no player and plugin selected, select the first one:\n dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n plugins[Object.keys(plugins)[0]].id\n );\n }\n\n dset(draft, [\"players\", sender, \"plugins\"], plugins);\n dset(draft, [\"players\", sender, \"active\"], true);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { flow, pluginID },\n } = transaction;\n\n dset(draft, [\"players\", sender, \"plugins\", pluginID, \"flow\"], flow);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { data, pluginID },\n } = transaction;\n dset(\n draft,\n [\"players\", sender, \"plugins\", pluginID, \"flow\", \"data\"],\n data\n );\n });\n case \"MESSENGER_EVENT_BATCH\":\n return produce(state, (draft) => {\n return transaction.payload.events.reduce(reducer, draft);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_STOPPED\":\n return produce(state, (draft) => {\n const { sender } = transaction;\n\n dset(draft, [\"players\", sender, \"active\"], false);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_SELECTED\":\n return produce(state, (draft) => {\n const { playerID } = transaction.payload;\n dset(draft, [\"current\", \"player\"], playerID);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\":\n return produce(state, (draft) => {\n const { pluginID } = transaction.payload;\n dset(draft, [\"current\", \"plugin\"], pluginID);\n });\n default:\n return state;\n }\n};\n","import type { Flow } from \"@player-ui/react\";\nimport { dequal } from \"dequal\";\n\nexport const flowDiff = ({\n curr,\n next,\n}: {\n curr: Flow;\n next: Flow;\n}):\n | { change: \"data\"; value: Flow[\"data\"] }\n | { change: \"flow\"; value: Flow }\n | null => {\n // compare flows except for the `data` property\n const currCopy = { ...curr, data: null };\n const nextCopy = { ...next, data: null };\n\n const baseFlowIsEqual = dequal(currCopy, nextCopy);\n\n if (!baseFlowIsEqual) {\n return { change: \"flow\", value: next };\n }\n\n // compare data\n const currData = curr.data;\n const nextData = next.data;\n\n const dataIsEqual = dequal(currData, nextData);\n\n if (!dataIsEqual) {\n return { change: \"data\", value: nextData };\n }\n\n return null;\n};\n","import { extendTheme, type ThemeConfig } from \"@chakra-ui/react\";\n\nconst config: ThemeConfig = {\n initialColorMode: \"dark\",\n useSystemColorMode: false,\n};\n\nexport const theme = extendTheme({ config });\n"],"mappings":";AAAA,OAAO,SAAS,cAAc;AAG9B,SAA+B,sBAAsB;AACrD,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAS,qBAAqB;;;ACnB9B,OAAO,4BAA4B;AACnC,SAAS,oBAAoB;AAEtB,IAAM,gBAAgB,IAAI,aAAa;AAEvC,IAAM,iBAAsC;AAAA,EACjD,IAAI,uBAAuB;AAAA,EAC3B;AACF;AAEO,IAAM,eAAqB;AAAA,EAChC,IAAI;AAAA,EACJ,OAAO;AAAA,IACL;AAAA,MAC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iBAAU,QAAM,GACjB;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH,OAAO,MAAM,QAAQ,UAAU;AAAA,MAC/B,UAAU,CAAC,UAAU,aAAa,MAAM,OAAO,KAAK;AAAA;AAAA,IAEnD,OAAO;AAAA,MACN,MAAM,QAAQ,MAAM,QAAQ,MAAM,EAAE;AAAA,IACtC,EAAE,IAAI,CAAC,aACL,oCAAC,YAAO,KAAK,UAAU,OAAO,YAC3B,QACH,CACD;AAAA,EACH,CACF,CACF,GACA,oCAAC,aAAU,SAAQ,OACjB,oCAAC,eAAU,CACb,GACA,oCAAC,iBACC,oCAAC,iBAAQ,OAAK,GACd,oCAAC,aAAK,KAAK,UAAU,OAAO,MAAM,CAAC,CAAE,CACvC,CACF,IAEA,oCAAC,QAAK,gBAAe,UAAS,SAAQ,OACpC,oCAAC,YAAK,4DACqD,KACzD,oCAAC,OAAE,MAAK,kCAA+B,8BAEvC,GAAK,KAAI,gBAEX,CACF,CAEJ,CACF,CACF,CACF;AAEJ;","names":["useEffect","useEffect"]}
|
|
1
|
+
{"version":3,"sources":["../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts","../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/theme.ts"],"sourcesContent":["import React, { useRef } from \"react\";\nimport type {\n MessengerOptions,\n ExtensionSupportedEvents,\n} from \"@player-tools/devtools-types\";\nimport { DataController, Flow, useReactPlayer } from \"@player-ui/react\";\nimport { useEffect } from \"react\";\nimport { ErrorBoundary } from \"react-error-boundary\";\nimport {\n Card,\n CardBody,\n CardHeader,\n ChakraProvider,\n Container,\n Flex,\n FormControl,\n FormLabel,\n Heading,\n HStack,\n Select,\n Text,\n VStack,\n} from \"@chakra-ui/react\";\nimport { ThemeProvider } from \"@devtools-ds/themes\";\n\nimport { INITIAL_FLOW } from \"../constants\";\nimport { PLAYER_PLUGINS, PUBSUB_PLUGIN } from \"../plugins\";\nimport { useExtensionState } from \"../state\";\nimport { flowDiff } from \"../helpers/flowDiff\";\nimport { theme } from \"./theme\";\n\nconst fallbackRender: ErrorBoundary[\"props\"][\"fallbackRender\"] = ({\n error,\n}) => {\n return (\n <Container centerContent>\n <Card>\n <CardHeader>\n <Heading>Ops, something went wrong.</Heading>\n </CardHeader>\n </Card>\n <CardBody>\n <Text as=\"pre\">{error.message}</Text>\n </CardBody>\n </Container>\n );\n};\n\n/**\n * Panel Component\n *\n * This component serves as the main container for the devtools plugin content defined by plugin authors using Player-UI DSL.\n *\n * Props:\n * - `communicationLayer`: An object that allows communication between the devtools and the Player-UI plugins,\n * enabling the exchange of data and events.\n *\n * Features:\n * - Error Handling: Utilizes the `ErrorBoundary` component from `react-error-boundary` to gracefully handle and display errors\n * that may occur during the rendering of the plugin's content.\n * - State Management: Integrates with custom hooks such as `useExtensionState` to manage the state of the plugin and its components.\n * - Player Integration: Uses the `useReactPlayer` hook from `player-ui/react` to render interactive player components based on the\n * DSL defined by the plugin authors.\n *\n * Example Usage:\n * ```tsx\n * <Panel communicationLayer={myCommunicationLayer} />\n * ```\n *\n * Note: The `communicationLayer` prop is essential for the proper functioning of the `Panel` component, as it enables the necessary\n * communication and data exchange with the player-ui/react library.\n */\nexport const Panel = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n readonly communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const { state, selectPlayer, selectPlugin, handleInteraction } =\n useExtensionState({\n communicationLayer,\n });\n\n const { reactPlayer } = useReactPlayer({\n plugins: PLAYER_PLUGINS,\n });\n\n const dataController = useRef<WeakRef<DataController> | null>(null);\n\n const currentFlow = useRef<Flow | null>(null);\n\n useEffect(() => {\n reactPlayer.player.hooks.dataController.tap(\"devtools-panel\", (d) => {\n dataController.current = new WeakRef(d);\n });\n }, [reactPlayer]);\n\n useEffect(() => {\n // we subscribe to all messages from the devtools plugin\n // so the plugin author can define their own events\n PUBSUB_PLUGIN.subscribe(\"*\", (type: string, payload: string) => {\n handleInteraction({\n type,\n payload,\n });\n });\n }, []);\n\n useEffect(() => {\n const { player, plugin } = state.current;\n\n const flow =\n player && plugin\n ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW\n : INITIAL_FLOW;\n\n if (!currentFlow.current) {\n currentFlow.current = flow;\n reactPlayer.start(flow);\n return;\n }\n\n const diff = flowDiff({\n curr: currentFlow.current as Flow,\n next: flow,\n });\n\n if (diff) {\n const { change, value } = diff;\n\n if (change === \"flow\") {\n currentFlow.current = value;\n reactPlayer.start(value);\n } else if (change === \"data\") {\n dataController.current\n ? dataController.current\n .deref()\n ?.set(value as Record<string, unknown>)\n : reactPlayer.start(flow);\n }\n }\n }, [reactPlayer, state]);\n\n const Component = reactPlayer.Component as React.FC;\n\n return (\n <ChakraProvider theme={theme}>\n <ThemeProvider colorScheme=\"dark\">\n <ErrorBoundary fallbackRender={fallbackRender}>\n <VStack w=\"100vw\" h=\"100vh\">\n {state.current.player ? (\n <Flex direction=\"column\" marginTop=\"4\">\n <HStack spacing=\"4\">\n <FormControl>\n <FormLabel>Player</FormLabel>\n <Select\n id=\"player\"\n value={state.current.player || \"\"}\n onChange={(event) => selectPlayer(event.target.value)}\n >\n {Object.keys(state.players).map((playerID) => (\n <option key={playerID} value={playerID}>\n {playerID}\n </option>\n ))}\n </Select>\n </FormControl>\n <FormControl>\n <FormLabel>Plugin</FormLabel>\n <Select\n id=\"plugin\"\n value={state.current.plugin || \"\"}\n onChange={(event) => selectPlugin(event.target.value)}\n >\n {Object.keys(\n state.players[state.current.player].plugins\n ).map((pluginID) => (\n <option key={pluginID} value={pluginID}>\n {pluginID}\n </option>\n ))}\n </Select>\n </FormControl>\n </HStack>\n <Container marginY=\"6\">\n <Component />\n </Container>\n <details>\n <summary>Debug</summary>\n <pre>{JSON.stringify(state, null, 2)}</pre>\n </details>\n </Flex>\n ) : (\n <Flex justifyContent=\"center\" padding=\"6\">\n <Text>\n No Player-UI instance or devtools plugin detected. Visit{\" \"}\n <a href=\"https://player-ui.github.io/\">\n https://player-ui.github.io/\n </a>{\" \"}\n for more info.\n </Text>\n </Flex>\n )}\n </VStack>\n </ErrorBoundary>\n </ThemeProvider>\n </ChakraProvider>\n );\n};\n","import type { ExtensionState } from \"@player-tools/devtools-types\";\nimport type { Flow } from \"@player-ui/react\";\n\nexport const INITIAL_FLOW: Flow = {\n id: \"initial-flow\",\n views: [\n {\n id: \"view-1\",\n type: \"text\",\n value: \"connecting...\",\n },\n ],\n navigation: {\n BEGIN: \"FLOW_1\",\n FLOW_1: {\n startState: \"VIEW_1\",\n VIEW_1: {\n state_type: \"VIEW\",\n ref: \"view-1\",\n transitions: {},\n },\n },\n },\n};\n\nexport const INITIAL_EXTENSION_STATE: ExtensionState = {\n current: {\n player: null,\n plugin: null,\n },\n players: {},\n};\n","import DevtoolsUIAssetsPlugin from \"@devtools-ui/plugin\";\nimport { PubSubPlugin } from \"@player-ui/pubsub-plugin\";\nimport type { ReactPlayerPlugin } from \"@player-ui/react\";\n\nexport const PUBSUB_PLUGIN = new PubSubPlugin();\n\nexport const PLAYER_PLUGINS: ReactPlayerPlugin[] = [\n new DevtoolsUIAssetsPlugin(),\n PUBSUB_PLUGIN,\n];\n","import { Messenger } from \"@player-tools/devtools-messenger\";\nimport type {\n ExtensionSupportedEvents,\n MessengerOptions,\n} from \"@player-tools/devtools-types\";\nimport { useCallback, useEffect, useMemo, useReducer } from \"react\";\n\nimport { INITIAL_EXTENSION_STATE } from \"../constants\";\nimport { reducer } from \"./reducer\";\n\nconst NOOP_ID = -1;\n\n/**\n * Custom React hook for managing the state of the devtools extension.\n *\n * This hook initializes the extension's state and sets up a communication layer\n * using the `Messenger` class. It provides methods to select a player or plugin,\n * and handle interactions, which dispatch actions to update the state accordingly.\n *\n */\nexport const useExtensionState = ({\n communicationLayer,\n}: {\n /** the communication layer to use for the extension */\n communicationLayer: Pick<\n MessengerOptions<ExtensionSupportedEvents>,\n \"sendMessage\" | \"addListener\" | \"removeListener\"\n >;\n}) => {\n const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);\n\n const messengerOptions = useMemo<MessengerOptions<ExtensionSupportedEvents>>(\n () => ({\n context: \"devtools\",\n target: \"player\",\n messageCallback: (message) => {\n dispatch(message);\n },\n ...communicationLayer,\n logger: console,\n }),\n [dispatch, communicationLayer]\n );\n\n const messenger = useMemo(\n () => new Messenger(messengerOptions),\n [messengerOptions]\n );\n\n useEffect(() => {\n return () => {\n messenger.destroy();\n };\n }, []);\n\n const selectPlayer = useCallback(\n (playerID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLAYER_SELECTED\",\n payload: {\n playerID,\n },\n });\n },\n [dispatch]\n );\n\n const selectPlugin = useCallback(\n (pluginID: string) => {\n dispatch({\n id: NOOP_ID,\n sender: \"internal\",\n context: \"devtools\",\n _messenger_: false,\n timestamp: Date.now(),\n type: \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\",\n payload: {\n pluginID,\n },\n });\n },\n [dispatch]\n );\n\n /**\n * Plugin authors can add interactive elements to the Player-UI content by leveraging\n * the pub-sub plugin and having the handle interaction proxy the message to the inspected\n * Player-UI instance.\n */\n const handleInteraction = useCallback(\n ({\n type,\n payload,\n }: {\n /** interaction type */\n type: string;\n /** interaction payload */\n payload?: string;\n }) => {\n messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type,\n payload,\n },\n });\n },\n [messenger]\n );\n\n return { state, selectPlayer, selectPlugin, handleInteraction };\n};\n","import type {\n ExtensionState,\n ExtensionSupportedEvents,\n Transaction,\n} from \"@player-tools/devtools-types\";\nimport { dset } from \"dset/merge\";\nimport { produce } from \"immer\";\n\n/** Extension state reducer */\nexport const reducer = (\n state: ExtensionState,\n transaction: Transaction<ExtensionSupportedEvents>\n): ExtensionState => {\n switch (transaction.type) {\n case \"PLAYER_DEVTOOLS_PLAYER_INIT\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { plugins },\n } = transaction;\n const { player, plugin } = draft.current;\n\n if (!player && !plugin) {\n // if there is no player and plugin selected, select the first one:\n dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n plugins[Object.keys(plugins)[0]].id\n );\n }\n\n dset(draft, [\"players\", sender, \"plugins\"], plugins);\n dset(draft, [\"players\", sender, \"active\"], true);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { flow, pluginID },\n } = transaction;\n\n dset(draft, [\"players\", sender, \"plugins\", pluginID, \"flow\"], flow);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE\":\n return produce(state, (draft) => {\n const {\n sender,\n payload: { data, pluginID },\n } = transaction;\n dset(\n draft,\n [\"players\", sender, \"plugins\", pluginID, \"flow\", \"data\"],\n data\n );\n });\n case \"MESSENGER_EVENT_BATCH\":\n return produce(state, (draft) => {\n return transaction.payload.events.reduce(reducer, draft);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_STOPPED\":\n return produce(state, (draft) => {\n const { sender } = transaction;\n\n dset(draft, [\"players\", sender, \"active\"], false);\n });\n case \"PLAYER_DEVTOOLS_PLAYER_SELECTED\":\n return produce(state, (draft) => {\n const { playerID } = transaction.payload;\n dset(draft, [\"current\", \"player\"], playerID);\n });\n case \"PLAYER_DEVTOOLS_PLUGIN_SELECTED\":\n return produce(state, (draft) => {\n const { pluginID } = transaction.payload;\n dset(draft, [\"current\", \"plugin\"], pluginID);\n });\n default:\n return state;\n }\n};\n","import type { Flow } from \"@player-ui/react\";\nimport { dequal } from \"dequal\";\n\n/**\n * Compares two Flow objects and identifies if there's a change in their structure or data.\n *\n * This function takes two Flow objects as input, `curr` (current) and `next` (next), and compares them\n * to determine if there's a change in the flow's structure or its data. If there's a change in the flow's\n * structure (excluding the `data` property), it returns an object indicating a \"flow\" change along with the\n * new flow. If there's a change in the `data` property, it returns an object indicating a \"data\" change along\n * with the new data. If there are no changes, it returns null.\n */\nexport const flowDiff = ({\n curr,\n next,\n}: {\n curr: Flow;\n next: Flow;\n}):\n | { change: \"data\"; value: Flow[\"data\"] }\n | { change: \"flow\"; value: Flow }\n | null => {\n // compare flows except for the `data` property\n const currCopy = { ...curr, data: null };\n const nextCopy = { ...next, data: null };\n\n const baseFlowIsEqual = dequal(currCopy, nextCopy);\n\n if (!baseFlowIsEqual) {\n return { change: \"flow\", value: next };\n }\n\n // compare data\n const currData = curr.data;\n const nextData = next.data;\n\n const dataIsEqual = dequal(currData, nextData);\n\n if (!dataIsEqual) {\n return { change: \"data\", value: nextData };\n }\n\n return null;\n};\n","import { extendTheme, type ThemeConfig } from \"@chakra-ui/react\";\n\nconst config: ThemeConfig = {\n initialColorMode: \"dark\",\n useSystemColorMode: false,\n};\n\nexport const theme = extendTheme({ config });\n"],"mappings":";AAAA,OAAO,SAAS,cAAc;AAK9B,SAA+B,sBAAsB;AACrD,SAAS,aAAAA,kBAAiB;AAC1B,SAAS,qBAAqB;AAC9B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;A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,MACH,OAAO,MAAM,QAAQ,UAAU;AAAA,MAC/B,UAAU,CAAC,UAAU,aAAa,MAAM,OAAO,KAAK;AAAA;AAAA,IAEnD,OAAO,KAAK,MAAM,OAAO,EAAE,IAAI,CAAC,aAC/B,oCAAC,YAAO,KAAK,UAAU,OAAO,YAC3B,QACH,CACD;AAAA,EACH,CACF,GACA,oCAAC,mBACC,oCAAC,iBAAU,QAAM,GACjB;AAAA,IAAC;AAAA;AAAA,MACC,IAAG;AAAA,MACH,OAAO,MAAM,QAAQ,UAAU;AAAA,MAC/B,UAAU,CAAC,UAAU,aAAa,MAAM,OAAO,KAAK;AAAA;AAAA,IAEnD,OAAO;AAAA,MACN,MAAM,QAAQ,MAAM,QAAQ,MAAM,EAAE;AAAA,IACtC,EAAE,IAAI,CAAC,aACL,oCAAC,YAAO,KAAK,UAAU,OAAO,YAC3B,QACH,CACD;AAAA,EACH,CACF,CACF,GACA,oCAAC,aAAU,SAAQ,OACjB,oCAAC,eAAU,CACb,GACA,oCAAC,iBACC,oCAAC,iBAAQ,OAAK,GACd,oCAAC,aAAK,KAAK,UAAU,OAAO,MAAM,CAAC,CAAE,CACvC,CACF,IAEA,oCAAC,QAAK,gBAAe,UAAS,SAAQ,OACpC,oCAAC,YAAK,4DACqD,KACzD,oCAAC,OAAE,MAAK,kCAA+B,8BAEvC,GAAK,KAAI,gBAEX,CACF,CAEJ,CACF,CACF,CACF;AAEJ;","names":["useEffect","useEffect"]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@player-tools/devtools-client",
|
|
3
|
-
"version": "0.5.3--canary.
|
|
3
|
+
"version": "0.5.3--canary.100.2570",
|
|
4
4
|
"main": "dist/cjs/index.cjs",
|
|
5
5
|
"dependencies": {
|
|
6
|
-
"@player-tools/devtools-messenger": "0.5.3--canary.
|
|
7
|
-
"@player-tools/devtools-types": "0.5.3--canary.
|
|
6
|
+
"@player-tools/devtools-messenger": "0.5.3--canary.100.2570",
|
|
7
|
+
"@player-tools/devtools-types": "0.5.3--canary.100.2570",
|
|
8
8
|
"@chakra-ui/react": "2.8.2",
|
|
9
9
|
"@player-ui/pubsub-plugin": "0.7.2-next.4",
|
|
10
10
|
"@player-ui/react": "0.7.2-next.4",
|
package/src/constants/index.ts
CHANGED
|
@@ -1,14 +1,5 @@
|
|
|
1
1
|
import type { ExtensionState } from "@player-tools/devtools-types";
|
|
2
|
-
import type { Flow
|
|
3
|
-
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
4
|
-
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
5
|
-
|
|
6
|
-
export const PUBSUB_PLUGIN = new PubSubPlugin();
|
|
7
|
-
|
|
8
|
-
export const PLAYER_PLUGINS: ReactPlayerPlugin[] = [
|
|
9
|
-
new DevtoolsUIAssetsPlugin(),
|
|
10
|
-
PUBSUB_PLUGIN,
|
|
11
|
-
];
|
|
2
|
+
import type { Flow } from "@player-ui/react";
|
|
12
3
|
|
|
13
4
|
export const INITIAL_FLOW: Flow = {
|
|
14
5
|
id: "initial-flow",
|
package/src/helpers/flowDiff.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import type { Flow } from "@player-ui/react";
|
|
2
2
|
import { dequal } from "dequal";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Compares two Flow objects and identifies if there's a change in their structure or data.
|
|
6
|
+
*
|
|
7
|
+
* This function takes two Flow objects as input, `curr` (current) and `next` (next), and compares them
|
|
8
|
+
* to determine if there's a change in the flow's structure or its data. If there's a change in the flow's
|
|
9
|
+
* structure (excluding the `data` property), it returns an object indicating a "flow" change along with the
|
|
10
|
+
* new flow. If there's a change in the `data` property, it returns an object indicating a "data" change along
|
|
11
|
+
* with the new data. If there are no changes, it returns null.
|
|
12
|
+
*/
|
|
4
13
|
export const flowDiff = ({
|
|
5
14
|
curr,
|
|
6
15
|
next,
|
package/src/panel/index.tsx
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import React, { useRef } from "react";
|
|
2
|
-
import type {
|
|
3
|
-
|
|
2
|
+
import type {
|
|
3
|
+
MessengerOptions,
|
|
4
|
+
ExtensionSupportedEvents,
|
|
5
|
+
} from "@player-tools/devtools-types";
|
|
4
6
|
import { DataController, Flow, useReactPlayer } from "@player-ui/react";
|
|
5
7
|
import { useEffect } from "react";
|
|
6
8
|
import { ErrorBoundary } from "react-error-boundary";
|
|
@@ -21,7 +23,8 @@ import {
|
|
|
21
23
|
} from "@chakra-ui/react";
|
|
22
24
|
import { ThemeProvider } from "@devtools-ds/themes";
|
|
23
25
|
|
|
24
|
-
import { INITIAL_FLOW
|
|
26
|
+
import { INITIAL_FLOW } from "../constants";
|
|
27
|
+
import { PLAYER_PLUGINS, PUBSUB_PLUGIN } from "../plugins";
|
|
25
28
|
import { useExtensionState } from "../state";
|
|
26
29
|
import { flowDiff } from "../helpers/flowDiff";
|
|
27
30
|
import { theme } from "./theme";
|
|
@@ -44,9 +47,28 @@ const fallbackRender: ErrorBoundary["props"]["fallbackRender"] = ({
|
|
|
44
47
|
};
|
|
45
48
|
|
|
46
49
|
/**
|
|
47
|
-
* Panel
|
|
50
|
+
* Panel Component
|
|
48
51
|
*
|
|
49
|
-
*
|
|
52
|
+
* This component serves as the main container for the devtools plugin content defined by plugin authors using Player-UI DSL.
|
|
53
|
+
*
|
|
54
|
+
* Props:
|
|
55
|
+
* - `communicationLayer`: An object that allows communication between the devtools and the Player-UI plugins,
|
|
56
|
+
* enabling the exchange of data and events.
|
|
57
|
+
*
|
|
58
|
+
* Features:
|
|
59
|
+
* - Error Handling: Utilizes the `ErrorBoundary` component from `react-error-boundary` to gracefully handle and display errors
|
|
60
|
+
* that may occur during the rendering of the plugin's content.
|
|
61
|
+
* - State Management: Integrates with custom hooks such as `useExtensionState` to manage the state of the plugin and its components.
|
|
62
|
+
* - Player Integration: Uses the `useReactPlayer` hook from `player-ui/react` to render interactive player components based on the
|
|
63
|
+
* DSL defined by the plugin authors.
|
|
64
|
+
*
|
|
65
|
+
* Example Usage:
|
|
66
|
+
* ```tsx
|
|
67
|
+
* <Panel communicationLayer={myCommunicationLayer} />
|
|
68
|
+
* ```
|
|
69
|
+
*
|
|
70
|
+
* Note: The `communicationLayer` prop is essential for the proper functioning of the `Panel` component, as it enables the necessary
|
|
71
|
+
* communication and data exchange with the player-ui/react library.
|
|
50
72
|
*/
|
|
51
73
|
export const Panel = ({
|
|
52
74
|
communicationLayer,
|
|
@@ -71,7 +93,7 @@ export const Panel = ({
|
|
|
71
93
|
const currentFlow = useRef<Flow | null>(null);
|
|
72
94
|
|
|
73
95
|
useEffect(() => {
|
|
74
|
-
reactPlayer.player.hooks.dataController.tap("panel", (d) => {
|
|
96
|
+
reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
|
|
75
97
|
dataController.current = new WeakRef(d);
|
|
76
98
|
});
|
|
77
99
|
}, [reactPlayer]);
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
2
|
+
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
3
|
+
import type { ReactPlayerPlugin } from "@player-ui/react";
|
|
4
|
+
|
|
5
|
+
export const PUBSUB_PLUGIN = new PubSubPlugin();
|
|
6
|
+
|
|
7
|
+
export const PLAYER_PLUGINS: ReactPlayerPlugin[] = [
|
|
8
|
+
new DevtoolsUIAssetsPlugin(),
|
|
9
|
+
PUBSUB_PLUGIN,
|
|
10
|
+
];
|
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
import { describe, expect, test } from "vitest";
|
|
2
|
+
import type {
|
|
3
|
+
Transaction,
|
|
4
|
+
DevtoolsDataChangeEvent,
|
|
5
|
+
PlayerInitEvent,
|
|
6
|
+
DevtoolsFlowChangeEvent,
|
|
7
|
+
DevtoolsEventsBatchEvent,
|
|
8
|
+
PlayerStoppedEvent,
|
|
9
|
+
ExtensionSelectedPlayerEvent,
|
|
10
|
+
ExtensionSelectedPluginEvent,
|
|
11
|
+
} from "@player-tools/devtools-types";
|
|
12
|
+
import { reducer } from "../reducer";
|
|
13
|
+
import { INITIAL_EXTENSION_STATE, INITIAL_FLOW } from "../../constants";
|
|
14
|
+
|
|
15
|
+
const mockPlayerInitTransaction: Transaction<PlayerInitEvent> = {
|
|
16
|
+
id: 1,
|
|
17
|
+
timestamp: Date.now(),
|
|
18
|
+
sender: "sender-id",
|
|
19
|
+
target: "target-id",
|
|
20
|
+
context: "player",
|
|
21
|
+
_messenger_: true,
|
|
22
|
+
type: "PLAYER_DEVTOOLS_PLAYER_INIT",
|
|
23
|
+
payload: {
|
|
24
|
+
plugins: {
|
|
25
|
+
"plugin-id": {
|
|
26
|
+
id: "plugin-id",
|
|
27
|
+
description: "Plugin Description",
|
|
28
|
+
flow: INITIAL_FLOW,
|
|
29
|
+
name: "Plugin Name",
|
|
30
|
+
version: "1.0.0",
|
|
31
|
+
},
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
const mockPlayerFlowChangeTransaction: Transaction<DevtoolsFlowChangeEvent> = {
|
|
37
|
+
id: 2,
|
|
38
|
+
timestamp: Date.now(),
|
|
39
|
+
sender: "sender-id",
|
|
40
|
+
target: "target-id",
|
|
41
|
+
context: "player",
|
|
42
|
+
_messenger_: true,
|
|
43
|
+
type: "PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE",
|
|
44
|
+
payload: {
|
|
45
|
+
flow: {
|
|
46
|
+
...INITIAL_FLOW,
|
|
47
|
+
data: {
|
|
48
|
+
key: "value",
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
pluginID: "plugin-id",
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const mockPluginDataChangeTransaction: Transaction<DevtoolsDataChangeEvent> = {
|
|
56
|
+
id: 2,
|
|
57
|
+
timestamp: Date.now(),
|
|
58
|
+
sender: "sender-id",
|
|
59
|
+
target: "target-id",
|
|
60
|
+
context: "player",
|
|
61
|
+
_messenger_: true,
|
|
62
|
+
type: "PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE",
|
|
63
|
+
payload: {
|
|
64
|
+
data: {
|
|
65
|
+
key: "value",
|
|
66
|
+
},
|
|
67
|
+
pluginID: "plugin-id",
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const mockEventBatchTransaction: Transaction<DevtoolsEventsBatchEvent> = {
|
|
72
|
+
id: 4,
|
|
73
|
+
timestamp: Date.now(),
|
|
74
|
+
sender: "sender-id",
|
|
75
|
+
target: "target-id",
|
|
76
|
+
context: "player",
|
|
77
|
+
_messenger_: true,
|
|
78
|
+
type: "MESSENGER_EVENT_BATCH",
|
|
79
|
+
payload: {
|
|
80
|
+
events: [
|
|
81
|
+
mockPlayerInitTransaction,
|
|
82
|
+
mockPlayerFlowChangeTransaction,
|
|
83
|
+
mockPluginDataChangeTransaction,
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const mockPlayerStoppedTransaction: Transaction<PlayerStoppedEvent> = {
|
|
89
|
+
id: 5,
|
|
90
|
+
timestamp: Date.now(),
|
|
91
|
+
sender: "sender-id",
|
|
92
|
+
target: "target-id",
|
|
93
|
+
context: "player",
|
|
94
|
+
_messenger_: true,
|
|
95
|
+
type: "PLAYER_DEVTOOLS_PLAYER_STOPPED",
|
|
96
|
+
payload: null,
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const mockPlayerSelectedTransaction: Transaction<ExtensionSelectedPlayerEvent> =
|
|
100
|
+
{
|
|
101
|
+
id: 6,
|
|
102
|
+
timestamp: Date.now(),
|
|
103
|
+
sender: "sender-id",
|
|
104
|
+
target: "target-id",
|
|
105
|
+
context: "player",
|
|
106
|
+
_messenger_: true,
|
|
107
|
+
type: "PLAYER_DEVTOOLS_PLAYER_SELECTED",
|
|
108
|
+
payload: {
|
|
109
|
+
playerID: "player-id",
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const mockPluginSelectedTransaction: Transaction<ExtensionSelectedPluginEvent> =
|
|
114
|
+
{
|
|
115
|
+
id: 7,
|
|
116
|
+
timestamp: Date.now(),
|
|
117
|
+
sender: "sender-id",
|
|
118
|
+
target: "target-id",
|
|
119
|
+
context: "player",
|
|
120
|
+
_messenger_: true,
|
|
121
|
+
type: "PLAYER_DEVTOOLS_PLUGIN_SELECTED",
|
|
122
|
+
payload: {
|
|
123
|
+
pluginID: "plugin-id",
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
describe("reducer", () => {
|
|
128
|
+
test("PLAYER_DEVTOOLS_PLAYER_INIT", () => {
|
|
129
|
+
const newState = reducer(
|
|
130
|
+
INITIAL_EXTENSION_STATE,
|
|
131
|
+
mockPlayerInitTransaction
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
135
|
+
{
|
|
136
|
+
"current": {
|
|
137
|
+
"player": "sender-id",
|
|
138
|
+
"plugin": "plugin-id",
|
|
139
|
+
},
|
|
140
|
+
"players": {
|
|
141
|
+
"sender-id": {
|
|
142
|
+
"active": true,
|
|
143
|
+
"plugins": {
|
|
144
|
+
"plugin-id": {
|
|
145
|
+
"description": "Plugin Description",
|
|
146
|
+
"flow": {
|
|
147
|
+
"id": "initial-flow",
|
|
148
|
+
"navigation": {
|
|
149
|
+
"BEGIN": "FLOW_1",
|
|
150
|
+
"FLOW_1": {
|
|
151
|
+
"VIEW_1": {
|
|
152
|
+
"ref": "view-1",
|
|
153
|
+
"state_type": "VIEW",
|
|
154
|
+
"transitions": {},
|
|
155
|
+
},
|
|
156
|
+
"startState": "VIEW_1",
|
|
157
|
+
},
|
|
158
|
+
},
|
|
159
|
+
"views": [
|
|
160
|
+
{
|
|
161
|
+
"id": "view-1",
|
|
162
|
+
"type": "text",
|
|
163
|
+
"value": "connecting...",
|
|
164
|
+
},
|
|
165
|
+
],
|
|
166
|
+
},
|
|
167
|
+
"id": "plugin-id",
|
|
168
|
+
"name": "Plugin Name",
|
|
169
|
+
"version": "1.0.0",
|
|
170
|
+
},
|
|
171
|
+
},
|
|
172
|
+
},
|
|
173
|
+
},
|
|
174
|
+
}
|
|
175
|
+
`);
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test("PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE", () => {
|
|
179
|
+
const newState = reducer(
|
|
180
|
+
INITIAL_EXTENSION_STATE,
|
|
181
|
+
mockPlayerFlowChangeTransaction
|
|
182
|
+
);
|
|
183
|
+
|
|
184
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
185
|
+
{
|
|
186
|
+
"current": {
|
|
187
|
+
"player": null,
|
|
188
|
+
"plugin": null,
|
|
189
|
+
},
|
|
190
|
+
"players": {
|
|
191
|
+
"sender-id": {
|
|
192
|
+
"plugins": {
|
|
193
|
+
"plugin-id": {
|
|
194
|
+
"flow": {
|
|
195
|
+
"data": {
|
|
196
|
+
"key": "value",
|
|
197
|
+
},
|
|
198
|
+
"id": "initial-flow",
|
|
199
|
+
"navigation": {
|
|
200
|
+
"BEGIN": "FLOW_1",
|
|
201
|
+
"FLOW_1": {
|
|
202
|
+
"VIEW_1": {
|
|
203
|
+
"ref": "view-1",
|
|
204
|
+
"state_type": "VIEW",
|
|
205
|
+
"transitions": {},
|
|
206
|
+
},
|
|
207
|
+
"startState": "VIEW_1",
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
"views": [
|
|
211
|
+
{
|
|
212
|
+
"id": "view-1",
|
|
213
|
+
"type": "text",
|
|
214
|
+
"value": "connecting...",
|
|
215
|
+
},
|
|
216
|
+
],
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
}
|
|
223
|
+
`);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
test("PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE", () => {
|
|
227
|
+
const newState = reducer(
|
|
228
|
+
INITIAL_EXTENSION_STATE,
|
|
229
|
+
mockPluginDataChangeTransaction
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
233
|
+
{
|
|
234
|
+
"current": {
|
|
235
|
+
"player": null,
|
|
236
|
+
"plugin": null,
|
|
237
|
+
},
|
|
238
|
+
"players": {
|
|
239
|
+
"sender-id": {
|
|
240
|
+
"plugins": {
|
|
241
|
+
"plugin-id": {
|
|
242
|
+
"flow": {
|
|
243
|
+
"data": {
|
|
244
|
+
"key": "value",
|
|
245
|
+
},
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
},
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
}
|
|
252
|
+
`);
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
test("MESSENGER_EVENT_BATCH", () => {
|
|
256
|
+
const newState = reducer(
|
|
257
|
+
INITIAL_EXTENSION_STATE,
|
|
258
|
+
mockEventBatchTransaction
|
|
259
|
+
);
|
|
260
|
+
|
|
261
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
262
|
+
{
|
|
263
|
+
"current": {
|
|
264
|
+
"player": "sender-id",
|
|
265
|
+
"plugin": "plugin-id",
|
|
266
|
+
},
|
|
267
|
+
"players": {
|
|
268
|
+
"sender-id": {
|
|
269
|
+
"active": true,
|
|
270
|
+
"plugins": {
|
|
271
|
+
"plugin-id": {
|
|
272
|
+
"description": "Plugin Description",
|
|
273
|
+
"flow": {
|
|
274
|
+
"data": {
|
|
275
|
+
"key": "value",
|
|
276
|
+
},
|
|
277
|
+
"id": "initial-flow",
|
|
278
|
+
"navigation": {
|
|
279
|
+
"BEGIN": "FLOW_1",
|
|
280
|
+
"FLOW_1": {
|
|
281
|
+
"VIEW_1": {
|
|
282
|
+
"ref": "view-1",
|
|
283
|
+
"state_type": "VIEW",
|
|
284
|
+
"transitions": {},
|
|
285
|
+
},
|
|
286
|
+
"startState": "VIEW_1",
|
|
287
|
+
},
|
|
288
|
+
},
|
|
289
|
+
"views": [
|
|
290
|
+
{
|
|
291
|
+
"id": "view-1",
|
|
292
|
+
"type": "text",
|
|
293
|
+
"value": "connecting...",
|
|
294
|
+
},
|
|
295
|
+
],
|
|
296
|
+
},
|
|
297
|
+
"id": "plugin-id",
|
|
298
|
+
"name": "Plugin Name",
|
|
299
|
+
"version": "1.0.0",
|
|
300
|
+
},
|
|
301
|
+
},
|
|
302
|
+
},
|
|
303
|
+
},
|
|
304
|
+
}
|
|
305
|
+
`);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
test("PLAYER_DEVTOOLS_PLAYER_STOPPED", () => {
|
|
309
|
+
const newState = reducer(
|
|
310
|
+
INITIAL_EXTENSION_STATE,
|
|
311
|
+
mockPlayerStoppedTransaction
|
|
312
|
+
);
|
|
313
|
+
|
|
314
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
315
|
+
{
|
|
316
|
+
"current": {
|
|
317
|
+
"player": null,
|
|
318
|
+
"plugin": null,
|
|
319
|
+
},
|
|
320
|
+
"players": {
|
|
321
|
+
"sender-id": {
|
|
322
|
+
"active": false,
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
}
|
|
326
|
+
`);
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
test("PLAYER_DEVTOOLS_PLAYER_SELECTED", () => {
|
|
330
|
+
const newState = reducer(
|
|
331
|
+
INITIAL_EXTENSION_STATE,
|
|
332
|
+
mockPlayerSelectedTransaction
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
336
|
+
{
|
|
337
|
+
"current": {
|
|
338
|
+
"player": "player-id",
|
|
339
|
+
"plugin": null,
|
|
340
|
+
},
|
|
341
|
+
"players": {},
|
|
342
|
+
}
|
|
343
|
+
`);
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
test("PLAYER_DEVTOOLS_PLUGIN_SELECTED", () => {
|
|
347
|
+
const newState = reducer(
|
|
348
|
+
INITIAL_EXTENSION_STATE,
|
|
349
|
+
mockPluginSelectedTransaction
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
expect(newState).toMatchInlineSnapshot(`
|
|
353
|
+
{
|
|
354
|
+
"current": {
|
|
355
|
+
"player": null,
|
|
356
|
+
"plugin": "plugin-id",
|
|
357
|
+
},
|
|
358
|
+
"players": {},
|
|
359
|
+
}
|
|
360
|
+
`);
|
|
361
|
+
});
|
|
362
|
+
});
|
package/src/state/index.ts
CHANGED
|
@@ -10,7 +10,14 @@ import { reducer } from "./reducer";
|
|
|
10
10
|
|
|
11
11
|
const NOOP_ID = -1;
|
|
12
12
|
|
|
13
|
-
/**
|
|
13
|
+
/**
|
|
14
|
+
* Custom React hook for managing the state of the devtools extension.
|
|
15
|
+
*
|
|
16
|
+
* This hook initializes the extension's state and sets up a communication layer
|
|
17
|
+
* using the `Messenger` class. It provides methods to select a player or plugin,
|
|
18
|
+
* and handle interactions, which dispatch actions to update the state accordingly.
|
|
19
|
+
*
|
|
20
|
+
*/
|
|
14
21
|
export const useExtensionState = ({
|
|
15
22
|
communicationLayer,
|
|
16
23
|
}: {
|
|
@@ -80,6 +87,11 @@ export const useExtensionState = ({
|
|
|
80
87
|
[dispatch]
|
|
81
88
|
);
|
|
82
89
|
|
|
90
|
+
/**
|
|
91
|
+
* Plugin authors can add interactive elements to the Player-UI content by leveraging
|
|
92
|
+
* the pub-sub plugin and having the handle interaction proxy the message to the inspected
|
|
93
|
+
* Player-UI instance.
|
|
94
|
+
*/
|
|
83
95
|
const handleInteraction = useCallback(
|
|
84
96
|
({
|
|
85
97
|
type,
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import type { ExtensionState } from "@player-tools/devtools-types";
|
|
2
|
-
import type { Flow
|
|
3
|
-
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
4
|
-
export declare const PUBSUB_PLUGIN: PubSubPlugin;
|
|
5
|
-
export declare const PLAYER_PLUGINS: ReactPlayerPlugin[];
|
|
2
|
+
import type { Flow } from "@player-ui/react";
|
|
6
3
|
export declare const INITIAL_FLOW: Flow;
|
|
7
4
|
export declare const INITIAL_EXTENSION_STATE: ExtensionState;
|
|
8
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,4 +1,13 @@
|
|
|
1
1
|
import type { Flow } from "@player-ui/react";
|
|
2
|
+
/**
|
|
3
|
+
* Compares two Flow objects and identifies if there's a change in their structure or data.
|
|
4
|
+
*
|
|
5
|
+
* This function takes two Flow objects as input, `curr` (current) and `next` (next), and compares them
|
|
6
|
+
* to determine if there's a change in the flow's structure or its data. If there's a change in the flow's
|
|
7
|
+
* structure (excluding the `data` property), it returns an object indicating a "flow" change along with the
|
|
8
|
+
* new flow. If there's a change in the `data` property, it returns an object indicating a "data" change along
|
|
9
|
+
* with the new data. If there are no changes, it returns null.
|
|
10
|
+
*/
|
|
2
11
|
export declare const flowDiff: ({ curr, next, }: {
|
|
3
12
|
curr: Flow;
|
|
4
13
|
next: Flow;
|
package/types/panel/index.d.ts
CHANGED
|
@@ -1,10 +1,28 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { MessengerOptions } from "@player-tools/devtools-types";
|
|
3
|
-
import type { ExtensionSupportedEvents } from "@player-tools/devtools-types";
|
|
2
|
+
import type { MessengerOptions, ExtensionSupportedEvents } from "@player-tools/devtools-types";
|
|
4
3
|
/**
|
|
5
|
-
* Panel
|
|
4
|
+
* Panel Component
|
|
6
5
|
*
|
|
7
|
-
*
|
|
6
|
+
* This component serves as the main container for the devtools plugin content defined by plugin authors using Player-UI DSL.
|
|
7
|
+
*
|
|
8
|
+
* Props:
|
|
9
|
+
* - `communicationLayer`: An object that allows communication between the devtools and the Player-UI plugins,
|
|
10
|
+
* enabling the exchange of data and events.
|
|
11
|
+
*
|
|
12
|
+
* Features:
|
|
13
|
+
* - Error Handling: Utilizes the `ErrorBoundary` component from `react-error-boundary` to gracefully handle and display errors
|
|
14
|
+
* that may occur during the rendering of the plugin's content.
|
|
15
|
+
* - State Management: Integrates with custom hooks such as `useExtensionState` to manage the state of the plugin and its components.
|
|
16
|
+
* - Player Integration: Uses the `useReactPlayer` hook from `player-ui/react` to render interactive player components based on the
|
|
17
|
+
* DSL defined by the plugin authors.
|
|
18
|
+
*
|
|
19
|
+
* Example Usage:
|
|
20
|
+
* ```tsx
|
|
21
|
+
* <Panel communicationLayer={myCommunicationLayer} />
|
|
22
|
+
* ```
|
|
23
|
+
*
|
|
24
|
+
* Note: The `communicationLayer` prop is essential for the proper functioning of the `Panel` component, as it enables the necessary
|
|
25
|
+
* communication and data exchange with the player-ui/react library.
|
|
8
26
|
*/
|
|
9
27
|
export declare const Panel: ({ communicationLayer, }: {
|
|
10
28
|
/** the communication layer to use for the extension */
|
package/types/state/index.d.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import type { ExtensionSupportedEvents, MessengerOptions } from "@player-tools/devtools-types";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Custom React hook for managing the state of the devtools extension.
|
|
4
|
+
*
|
|
5
|
+
* This hook initializes the extension's state and sets up a communication layer
|
|
6
|
+
* using the `Messenger` class. It provides methods to select a player or plugin,
|
|
7
|
+
* and handle interactions, which dispatch actions to update the state accordingly.
|
|
8
|
+
*
|
|
9
|
+
*/
|
|
3
10
|
export declare const useExtensionState: ({ communicationLayer, }: {
|
|
4
11
|
/** the communication layer to use for the extension */
|
|
5
12
|
communicationLayer: Pick<MessengerOptions<ExtensionSupportedEvents>, "sendMessage" | "addListener" | "removeListener">;
|