@player-tools/devtools-client 0.10.0-next.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/index.cjs +11 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +11 -1
- package/dist/index.mjs +11 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +9 -6
- package/src/panel/index.tsx +6 -6
- package/src/plugins/index.ts +6 -0
- package/src/state/__tests__/reducer.test.ts +7 -7
- package/src/state/index.ts +5 -5
- package/src/state/reducer.ts +3 -3
package/dist/cjs/index.cjs
CHANGED
|
@@ -75,8 +75,14 @@ var INITIAL_EXTENSION_STATE = {
|
|
|
75
75
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
|
|
76
76
|
var import_plugin = __toESM(require("@devtools-ui/plugin"));
|
|
77
77
|
var import_pubsub_plugin = require("@player-ui/pubsub-plugin");
|
|
78
|
+
var import_common_expressions_plugin = require("@player-ui/common-expressions-plugin");
|
|
79
|
+
var import_common_types_plugin = require("@player-ui/common-types-plugin");
|
|
80
|
+
var import_data_change_listener_plugin = require("@player-ui/data-change-listener-plugin");
|
|
78
81
|
var PUBSUB_PLUGIN = new import_pubsub_plugin.PubSubPlugin();
|
|
79
82
|
var PLAYER_PLUGINS = [
|
|
83
|
+
new import_common_types_plugin.CommonTypesPlugin(),
|
|
84
|
+
new import_common_expressions_plugin.CommonExpressionsPlugin(),
|
|
85
|
+
new import_data_change_listener_plugin.DataChangeListenerPlugin(),
|
|
80
86
|
new import_plugin.default(),
|
|
81
87
|
PUBSUB_PLUGIN
|
|
82
88
|
];
|
|
@@ -311,7 +317,11 @@ var Panel = ({
|
|
|
311
317
|
currentFlow.current = value;
|
|
312
318
|
reactPlayer.start(value);
|
|
313
319
|
} else if (change === "data") {
|
|
314
|
-
|
|
320
|
+
if (dataController.current) {
|
|
321
|
+
dataController.current.deref()?.set(value);
|
|
322
|
+
} else {
|
|
323
|
+
reactPlayer.start(flow);
|
|
324
|
+
}
|
|
315
325
|
}
|
|
316
326
|
}
|
|
317
327
|
}, [reactPlayer, state]);
|
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/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 Select,\n Text,\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 <Flex direction=\"column\" w=\"100vw\" h=\"100vh\" alignItems={\"normal\"}>\n {state.current.player ? (\n <Container minWidth={\"100%\"}>\n <Flex direction=\"column\" marginTop=\"4\">\n <Flex gap={\"8\"}>\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 </Flex>\n <Flex>\n <Component />\n </Flex>\n <details>\n <summary>Debug</summary>\n <pre style={{ maxHeight: \"30vh\", overflow: \"scroll\" }}>\n {JSON.stringify(state, null, 2)}\n </pre>\n </details>\n </Flex>\n </Container>\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 </Flex>\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 messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type: \"player-selected\",\n payload: 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 ...(state.current.player ? { target: state.current.player } : {}),\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 dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n draft.current.plugin || plugins[Object.keys(plugins)[0]].id\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,gBAYO;AACP,oBAA8B;;;AClBvB,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,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AA,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,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,0BACC,8BAAAA,QAAA,cAAC,eAAU,CACb,GACA,8BAAAA,QAAA,cAAC,iBACC,8BAAAA,QAAA,cAAC,iBAAQ,OAAK,GACd,8BAAAA,QAAA,cAAC,SAAI,OAAO,EAAE,WAAW,QAAQ,UAAU,SAAS,KACjD,KAAK,UAAU,OAAO,MAAM,CAAC,CAChC,CACF,CACF,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 Select,\n Text,\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 if (dataController.current) {\n dataController.current.deref()?.set(value as Record<string, unknown>);\n } else {\n reactPlayer.start(flow);\n }\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 <Flex direction=\"column\" w=\"100vw\" h=\"100vh\" alignItems={\"normal\"}>\n {state.current.player ? (\n <Container minWidth={\"100%\"}>\n <Flex direction=\"column\" marginTop=\"4\">\n <Flex gap={\"8\"}>\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 </Flex>\n <Flex>\n <Component />\n </Flex>\n <details>\n <summary>Debug</summary>\n <pre style={{ maxHeight: \"30vh\", overflow: \"scroll\" }}>\n {JSON.stringify(state, null, 2)}\n </pre>\n </details>\n </Flex>\n </Container>\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 </Flex>\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 { CommonExpressionsPlugin } from \"@player-ui/common-expressions-plugin\";\nimport { CommonTypesPlugin } from \"@player-ui/common-types-plugin\";\nimport { DataChangeListenerPlugin } from \"@player-ui/data-change-listener-plugin\";\nimport type { ReactPlayerPlugin } from \"@player-ui/react\";\n\nexport const PUBSUB_PLUGIN = new PubSubPlugin();\n\nexport const PLAYER_PLUGINS: ReactPlayerPlugin[] = [\n new CommonTypesPlugin(),\n new CommonExpressionsPlugin(),\n new DataChangeListenerPlugin(),\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 messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type: \"player-selected\",\n payload: 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 ...(state.current.player ? { target: state.current.player } : {}),\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 dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n draft.current.plugin || plugins[Object.keys(plugins)[0]].id,\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,gBAYO;AACP,oBAA8B;;;AClBvB,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;AAA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,CACF,CAEJ,CACF,CACF,CACF;AAEJ;","names":["import_react","DevtoolsUIAssetsPlugin","import_react","React"]}
|
package/dist/index.legacy-esm.js
CHANGED
|
@@ -51,8 +51,14 @@ var INITIAL_EXTENSION_STATE = {
|
|
|
51
51
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
|
|
52
52
|
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
53
53
|
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
54
|
+
import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
|
|
55
|
+
import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
|
|
56
|
+
import { DataChangeListenerPlugin } from "@player-ui/data-change-listener-plugin";
|
|
54
57
|
var PUBSUB_PLUGIN = new PubSubPlugin();
|
|
55
58
|
var PLAYER_PLUGINS = [
|
|
59
|
+
new CommonTypesPlugin(),
|
|
60
|
+
new CommonExpressionsPlugin(),
|
|
61
|
+
new DataChangeListenerPlugin(),
|
|
56
62
|
new DevtoolsUIAssetsPlugin(),
|
|
57
63
|
PUBSUB_PLUGIN
|
|
58
64
|
];
|
|
@@ -287,7 +293,11 @@ var Panel = ({
|
|
|
287
293
|
currentFlow.current = value;
|
|
288
294
|
reactPlayer.start(value);
|
|
289
295
|
} else if (change === "data") {
|
|
290
|
-
|
|
296
|
+
if (dataController.current) {
|
|
297
|
+
dataController.current.deref()?.set(value);
|
|
298
|
+
} else {
|
|
299
|
+
reactPlayer.start(flow);
|
|
300
|
+
}
|
|
291
301
|
}
|
|
292
302
|
}
|
|
293
303
|
}, [reactPlayer, state]);
|
package/dist/index.mjs
CHANGED
|
@@ -51,8 +51,14 @@ var INITIAL_EXTENSION_STATE = {
|
|
|
51
51
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
|
|
52
52
|
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
53
53
|
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
54
|
+
import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
|
|
55
|
+
import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
|
|
56
|
+
import { DataChangeListenerPlugin } from "@player-ui/data-change-listener-plugin";
|
|
54
57
|
var PUBSUB_PLUGIN = new PubSubPlugin();
|
|
55
58
|
var PLAYER_PLUGINS = [
|
|
59
|
+
new CommonTypesPlugin(),
|
|
60
|
+
new CommonExpressionsPlugin(),
|
|
61
|
+
new DataChangeListenerPlugin(),
|
|
56
62
|
new DevtoolsUIAssetsPlugin(),
|
|
57
63
|
PUBSUB_PLUGIN
|
|
58
64
|
];
|
|
@@ -287,7 +293,11 @@ var Panel = ({
|
|
|
287
293
|
currentFlow.current = value;
|
|
288
294
|
reactPlayer.start(value);
|
|
289
295
|
} else if (change === "data") {
|
|
290
|
-
|
|
296
|
+
if (dataController.current) {
|
|
297
|
+
dataController.current.deref()?.set(value);
|
|
298
|
+
} else {
|
|
299
|
+
reactPlayer.start(flow);
|
|
300
|
+
}
|
|
291
301
|
}
|
|
292
302
|
}
|
|
293
303
|
}, [reactPlayer, state]);
|
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/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 Select,\n Text,\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 <Flex direction=\"column\" w=\"100vw\" h=\"100vh\" alignItems={\"normal\"}>\n {state.current.player ? (\n <Container minWidth={\"100%\"}>\n <Flex direction=\"column\" marginTop=\"4\">\n <Flex gap={\"8\"}>\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 </Flex>\n <Flex>\n <Component />\n </Flex>\n <details>\n <summary>Debug</summary>\n <pre style={{ maxHeight: \"30vh\", overflow: \"scroll\" }}>\n {JSON.stringify(state, null, 2)}\n </pre>\n </details>\n </Flex>\n </Container>\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 </Flex>\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 messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type: \"player-selected\",\n payload: 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 ...(state.current.player ? { target: state.current.player } : {}),\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 dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n draft.current.plugin || plugins[Object.keys(plugins)[0]].id\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({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K,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 Select,\n Text,\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 if (dataController.current) {\n dataController.current.deref()?.set(value as Record<string, unknown>);\n } else {\n reactPlayer.start(flow);\n }\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 <Flex direction=\"column\" w=\"100vw\" h=\"100vh\" alignItems={\"normal\"}>\n {state.current.player ? (\n <Container minWidth={\"100%\"}>\n <Flex direction=\"column\" marginTop=\"4\">\n <Flex gap={\"8\"}>\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 </Flex>\n <Flex>\n <Component />\n </Flex>\n <details>\n <summary>Debug</summary>\n <pre style={{ maxHeight: \"30vh\", overflow: \"scroll\" }}>\n {JSON.stringify(state, null, 2)}\n </pre>\n </details>\n </Flex>\n </Container>\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 </Flex>\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 { CommonExpressionsPlugin } from \"@player-ui/common-expressions-plugin\";\nimport { CommonTypesPlugin } from \"@player-ui/common-types-plugin\";\nimport { DataChangeListenerPlugin } from \"@player-ui/data-change-listener-plugin\";\nimport type { ReactPlayerPlugin } from \"@player-ui/react\";\n\nexport const PUBSUB_PLUGIN = new PubSubPlugin();\n\nexport const PLAYER_PLUGINS: ReactPlayerPlugin[] = [\n new CommonTypesPlugin(),\n new CommonExpressionsPlugin(),\n new DataChangeListenerPlugin(),\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 messenger.sendMessage({\n type: \"PLAYER_DEVTOOLS_PLUGIN_INTERACTION\",\n payload: {\n type: \"player-selected\",\n payload: 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 ...(state.current.player ? { target: state.current.player } : {}),\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 dset(draft, [\"current\", \"player\"], sender);\n dset(\n draft,\n [\"current\", \"plugin\"],\n draft.current.plugin || plugins[Object.keys(plugins)[0]].id,\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,OACK;AACP,SAAS,qBAAqB;;;AClBvB,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,IAC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AU,UAAU,UACnB,oCAAC,QAAK,WAAU,UAAS,WAAU,OACjC,oCAAC,QAAK,KAAK,OACT,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,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,YACC,oCAAC,eAAU,CACb,GACA,oCAAC,iBACC,oCAAC,iBAAQ,OAAK,GACd,oCAAC,SAAI,OAAO,EAAE,WAAW,QAAQ,UAAU,SAAS,KACjD,KAAK,UAAU,OAAO,MAAM,CAAC,CAChC,CACF,CACF,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
|
@@ -6,15 +6,18 @@
|
|
|
6
6
|
"types"
|
|
7
7
|
],
|
|
8
8
|
"name": "@player-tools/devtools-client",
|
|
9
|
-
"version": "0.10.0
|
|
9
|
+
"version": "0.10.0",
|
|
10
10
|
"main": "dist/cjs/index.cjs",
|
|
11
11
|
"dependencies": {
|
|
12
|
-
"@player-tools/devtools-messenger": "0.10.0
|
|
13
|
-
"@player-tools/devtools-types": "0.10.0
|
|
12
|
+
"@player-tools/devtools-messenger": "0.10.0",
|
|
13
|
+
"@player-tools/devtools-types": "0.10.0",
|
|
14
14
|
"@chakra-ui/react": "2.8.2",
|
|
15
|
-
"@player-ui/pubsub-plugin": "0.
|
|
16
|
-
"@player-ui/react": "0.
|
|
17
|
-
"@
|
|
15
|
+
"@player-ui/pubsub-plugin": "0.10.4",
|
|
16
|
+
"@player-ui/react": "0.10.4",
|
|
17
|
+
"@player-ui/common-expressions-plugin": "0.10.4",
|
|
18
|
+
"@player-ui/common-types-plugin": "0.10.4",
|
|
19
|
+
"@player-ui/data-change-listener-plugin": "0.10.4",
|
|
20
|
+
"@devtools-ui/plugin": "0.4.0",
|
|
18
21
|
"@types/react": "^18.2.51",
|
|
19
22
|
"immer": "^10.0.3",
|
|
20
23
|
"dset": "^3.1.3",
|
package/src/panel/index.tsx
CHANGED
|
@@ -133,11 +133,11 @@ export const Panel = ({
|
|
|
133
133
|
currentFlow.current = value;
|
|
134
134
|
reactPlayer.start(value);
|
|
135
135
|
} else if (change === "data") {
|
|
136
|
-
dataController.current
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
136
|
+
if (dataController.current) {
|
|
137
|
+
dataController.current.deref()?.set(value as Record<string, unknown>);
|
|
138
|
+
} else {
|
|
139
|
+
reactPlayer.start(flow);
|
|
140
|
+
}
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
}, [reactPlayer, state]);
|
|
@@ -175,7 +175,7 @@ export const Panel = ({
|
|
|
175
175
|
onChange={(event) => selectPlugin(event.target.value)}
|
|
176
176
|
>
|
|
177
177
|
{Object.keys(
|
|
178
|
-
state.players[state.current.player].plugins
|
|
178
|
+
state.players[state.current.player].plugins,
|
|
179
179
|
).map((pluginID) => (
|
|
180
180
|
<option key={pluginID} value={pluginID}>
|
|
181
181
|
{pluginID}
|
package/src/plugins/index.ts
CHANGED
|
@@ -1,10 +1,16 @@
|
|
|
1
1
|
import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
|
|
2
2
|
import { PubSubPlugin } from "@player-ui/pubsub-plugin";
|
|
3
|
+
import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
|
|
4
|
+
import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
|
|
5
|
+
import { DataChangeListenerPlugin } from "@player-ui/data-change-listener-plugin";
|
|
3
6
|
import type { ReactPlayerPlugin } from "@player-ui/react";
|
|
4
7
|
|
|
5
8
|
export const PUBSUB_PLUGIN = new PubSubPlugin();
|
|
6
9
|
|
|
7
10
|
export const PLAYER_PLUGINS: ReactPlayerPlugin[] = [
|
|
11
|
+
new CommonTypesPlugin(),
|
|
12
|
+
new CommonExpressionsPlugin(),
|
|
13
|
+
new DataChangeListenerPlugin(),
|
|
8
14
|
new DevtoolsUIAssetsPlugin(),
|
|
9
15
|
PUBSUB_PLUGIN,
|
|
10
16
|
];
|
|
@@ -128,7 +128,7 @@ describe("reducer", () => {
|
|
|
128
128
|
test("PLAYER_DEVTOOLS_PLAYER_INIT", () => {
|
|
129
129
|
const newState = reducer(
|
|
130
130
|
INITIAL_EXTENSION_STATE,
|
|
131
|
-
mockPlayerInitTransaction
|
|
131
|
+
mockPlayerInitTransaction,
|
|
132
132
|
);
|
|
133
133
|
|
|
134
134
|
expect(newState).toMatchInlineSnapshot(`
|
|
@@ -178,7 +178,7 @@ describe("reducer", () => {
|
|
|
178
178
|
test("PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE", () => {
|
|
179
179
|
const newState = reducer(
|
|
180
180
|
INITIAL_EXTENSION_STATE,
|
|
181
|
-
mockPlayerFlowChangeTransaction
|
|
181
|
+
mockPlayerFlowChangeTransaction,
|
|
182
182
|
);
|
|
183
183
|
|
|
184
184
|
expect(newState).toMatchInlineSnapshot(`
|
|
@@ -226,7 +226,7 @@ describe("reducer", () => {
|
|
|
226
226
|
test("PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE", () => {
|
|
227
227
|
const newState = reducer(
|
|
228
228
|
INITIAL_EXTENSION_STATE,
|
|
229
|
-
mockPluginDataChangeTransaction
|
|
229
|
+
mockPluginDataChangeTransaction,
|
|
230
230
|
);
|
|
231
231
|
|
|
232
232
|
expect(newState).toMatchInlineSnapshot(`
|
|
@@ -255,7 +255,7 @@ describe("reducer", () => {
|
|
|
255
255
|
test("MESSENGER_EVENT_BATCH", () => {
|
|
256
256
|
const newState = reducer(
|
|
257
257
|
INITIAL_EXTENSION_STATE,
|
|
258
|
-
mockEventBatchTransaction
|
|
258
|
+
mockEventBatchTransaction,
|
|
259
259
|
);
|
|
260
260
|
|
|
261
261
|
expect(newState).toMatchInlineSnapshot(`
|
|
@@ -308,7 +308,7 @@ describe("reducer", () => {
|
|
|
308
308
|
test("PLAYER_DEVTOOLS_PLAYER_STOPPED", () => {
|
|
309
309
|
const newState = reducer(
|
|
310
310
|
INITIAL_EXTENSION_STATE,
|
|
311
|
-
mockPlayerStoppedTransaction
|
|
311
|
+
mockPlayerStoppedTransaction,
|
|
312
312
|
);
|
|
313
313
|
|
|
314
314
|
expect(newState).toMatchInlineSnapshot(`
|
|
@@ -329,7 +329,7 @@ describe("reducer", () => {
|
|
|
329
329
|
test("PLAYER_DEVTOOLS_PLAYER_SELECTED", () => {
|
|
330
330
|
const newState = reducer(
|
|
331
331
|
INITIAL_EXTENSION_STATE,
|
|
332
|
-
mockPlayerSelectedTransaction
|
|
332
|
+
mockPlayerSelectedTransaction,
|
|
333
333
|
);
|
|
334
334
|
|
|
335
335
|
expect(newState).toMatchInlineSnapshot(`
|
|
@@ -346,7 +346,7 @@ describe("reducer", () => {
|
|
|
346
346
|
test("PLAYER_DEVTOOLS_PLUGIN_SELECTED", () => {
|
|
347
347
|
const newState = reducer(
|
|
348
348
|
INITIAL_EXTENSION_STATE,
|
|
349
|
-
mockPluginSelectedTransaction
|
|
349
|
+
mockPluginSelectedTransaction,
|
|
350
350
|
);
|
|
351
351
|
|
|
352
352
|
expect(newState).toMatchInlineSnapshot(`
|
package/src/state/index.ts
CHANGED
|
@@ -39,12 +39,12 @@ export const useExtensionState = ({
|
|
|
39
39
|
...communicationLayer,
|
|
40
40
|
logger: console,
|
|
41
41
|
}),
|
|
42
|
-
[dispatch, communicationLayer]
|
|
42
|
+
[dispatch, communicationLayer],
|
|
43
43
|
);
|
|
44
44
|
|
|
45
45
|
const messenger = useMemo(
|
|
46
46
|
() => new Messenger(messengerOptions),
|
|
47
|
-
[messengerOptions]
|
|
47
|
+
[messengerOptions],
|
|
48
48
|
);
|
|
49
49
|
|
|
50
50
|
useEffect(() => {
|
|
@@ -75,7 +75,7 @@ export const useExtensionState = ({
|
|
|
75
75
|
},
|
|
76
76
|
});
|
|
77
77
|
},
|
|
78
|
-
[dispatch]
|
|
78
|
+
[dispatch],
|
|
79
79
|
);
|
|
80
80
|
|
|
81
81
|
const selectPlugin = useCallback(
|
|
@@ -92,7 +92,7 @@ export const useExtensionState = ({
|
|
|
92
92
|
},
|
|
93
93
|
});
|
|
94
94
|
},
|
|
95
|
-
[dispatch]
|
|
95
|
+
[dispatch],
|
|
96
96
|
);
|
|
97
97
|
|
|
98
98
|
/**
|
|
@@ -119,7 +119,7 @@ export const useExtensionState = ({
|
|
|
119
119
|
...(state.current.player ? { target: state.current.player } : {}),
|
|
120
120
|
});
|
|
121
121
|
},
|
|
122
|
-
[messenger]
|
|
122
|
+
[messenger],
|
|
123
123
|
);
|
|
124
124
|
|
|
125
125
|
return { state, selectPlayer, selectPlugin, handleInteraction };
|
package/src/state/reducer.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { produce } from "immer";
|
|
|
9
9
|
/** Extension state reducer */
|
|
10
10
|
export const reducer = (
|
|
11
11
|
state: ExtensionState,
|
|
12
|
-
transaction: Transaction<ExtensionSupportedEvents
|
|
12
|
+
transaction: Transaction<ExtensionSupportedEvents>,
|
|
13
13
|
): ExtensionState => {
|
|
14
14
|
switch (transaction.type) {
|
|
15
15
|
case "PLAYER_DEVTOOLS_PLAYER_INIT":
|
|
@@ -22,7 +22,7 @@ export const reducer = (
|
|
|
22
22
|
dset(
|
|
23
23
|
draft,
|
|
24
24
|
["current", "plugin"],
|
|
25
|
-
draft.current.plugin || plugins[Object.keys(plugins)[0]].id
|
|
25
|
+
draft.current.plugin || plugins[Object.keys(plugins)[0]].id,
|
|
26
26
|
);
|
|
27
27
|
|
|
28
28
|
dset(draft, ["players", sender, "plugins"], plugins);
|
|
@@ -46,7 +46,7 @@ export const reducer = (
|
|
|
46
46
|
dset(
|
|
47
47
|
draft,
|
|
48
48
|
["players", sender, "plugins", pluginID, "flow", "data"],
|
|
49
|
-
data
|
|
49
|
+
data,
|
|
50
50
|
);
|
|
51
51
|
});
|
|
52
52
|
case "MESSENGER_EVENT_BATCH":
|