@player-devtools/client 0.0.2-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,354 @@
1
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx
2
+ import React, { useRef } from "react";
3
+ import { useReactPlayer } from "@player-ui/react";
4
+ import { useEffect as useEffect2 } from "react";
5
+ import { ErrorBoundary } from "react-error-boundary";
6
+ import {
7
+ Card,
8
+ CardBody,
9
+ CardHeader,
10
+ ChakraProvider,
11
+ Container,
12
+ extendTheme,
13
+ Flex,
14
+ FormControl,
15
+ FormLabel,
16
+ Heading,
17
+ Select,
18
+ Text
19
+ } from "@chakra-ui/react";
20
+ import { ThemeProvider, useDarkMode } from "@devtools-ds/themes";
21
+
22
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts
23
+ var INITIAL_FLOW = {
24
+ id: "initial-flow",
25
+ views: [
26
+ {
27
+ id: "view-1",
28
+ type: "text",
29
+ value: "connecting..."
30
+ }
31
+ ],
32
+ navigation: {
33
+ BEGIN: "FLOW_1",
34
+ FLOW_1: {
35
+ startState: "VIEW_1",
36
+ VIEW_1: {
37
+ state_type: "VIEW",
38
+ ref: "view-1",
39
+ transitions: {}
40
+ }
41
+ }
42
+ }
43
+ };
44
+ var INITIAL_EXTENSION_STATE = {
45
+ current: {
46
+ player: null,
47
+ plugin: null
48
+ },
49
+ players: {}
50
+ };
51
+
52
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
53
+ import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
54
+ import { PubSubPlugin } from "@player-ui/pubsub-plugin";
55
+ import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
56
+ import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
57
+ import { DataChangeListenerPlugin } from "@player-ui/data-change-listener-plugin";
58
+ import {
59
+ ConsoleLogger
60
+ } from "@player-ui/react";
61
+ var LogForwarder = class {
62
+ constructor() {
63
+ this.name = "Log";
64
+ }
65
+ apply(player) {
66
+ player.logger.addHandler(new ConsoleLogger("trace", console));
67
+ }
68
+ applyReact(reactPlayer) {
69
+ this.apply(reactPlayer.player);
70
+ }
71
+ };
72
+ var PUBSUB_PLUGIN = new PubSubPlugin();
73
+ var PLAYER_PLUGINS = [
74
+ new CommonTypesPlugin(),
75
+ new CommonExpressionsPlugin(),
76
+ new DataChangeListenerPlugin(),
77
+ new DevtoolsUIAssetsPlugin(),
78
+ new LogForwarder(),
79
+ PUBSUB_PLUGIN
80
+ ];
81
+
82
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
83
+ import { Messenger } from "@player-devtools/messenger";
84
+ import { useCallback, useEffect, useMemo, useReducer } from "react";
85
+
86
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts
87
+ import { dsetAssign } from "@player-devtools/utils";
88
+ import { produce } from "immer";
89
+ var reducer = (state, transaction) => {
90
+ switch (transaction.type) {
91
+ case "PLAYER_DEVTOOLS_PLAYER_INIT":
92
+ return produce(state, (draft) => {
93
+ const {
94
+ sender,
95
+ payload: { plugins }
96
+ } = transaction;
97
+ const [plugin] = Object.values(plugins);
98
+ if (!plugin) return;
99
+ draft.current.player = sender;
100
+ draft.current.plugin = draft.current.plugin || plugin.id;
101
+ dsetAssign(draft, ["players", sender, "plugins"], plugins, true);
102
+ dsetAssign(draft.players, [sender, "active"], true);
103
+ });
104
+ case "PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE":
105
+ return produce(state, (draft) => {
106
+ const {
107
+ sender,
108
+ payload: { flow, pluginID }
109
+ } = transaction;
110
+ dsetAssign(
111
+ draft,
112
+ ["players", sender, "plugins", pluginID, "flow"],
113
+ flow
114
+ );
115
+ });
116
+ case "PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE":
117
+ return produce(state, (draft) => {
118
+ const {
119
+ sender,
120
+ payload: { data, pluginID }
121
+ } = transaction;
122
+ dsetAssign(
123
+ draft,
124
+ ["players", sender, "plugins", pluginID, "flow", "data"],
125
+ data
126
+ );
127
+ });
128
+ case "MESSENGER_EVENT_BATCH":
129
+ return transaction.payload.events.reduce(reducer, state);
130
+ case "PLAYER_DEVTOOLS_PLAYER_STOPPED":
131
+ return produce(state, (draft) => {
132
+ const { sender } = transaction;
133
+ dsetAssign(draft, ["players", sender, "active"], false);
134
+ });
135
+ case "PLAYER_DEVTOOLS_PLAYER_SELECTED":
136
+ return produce(state, (draft) => {
137
+ const { playerID } = transaction.payload;
138
+ draft.current.player = playerID;
139
+ });
140
+ case "PLAYER_DEVTOOLS_PLUGIN_SELECTED":
141
+ return produce(state, (draft) => {
142
+ const { pluginID } = transaction.payload;
143
+ draft.current.plugin = pluginID;
144
+ });
145
+ default:
146
+ return state;
147
+ }
148
+ };
149
+
150
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
151
+ var NOOP_ID = -1;
152
+ var useExtensionState = ({
153
+ communicationLayer
154
+ }) => {
155
+ const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);
156
+ const messengerOptions = useMemo(
157
+ () => ({
158
+ context: "devtools",
159
+ target: "player",
160
+ messageCallback: (message) => {
161
+ dispatch(message);
162
+ },
163
+ ...communicationLayer,
164
+ logger: console
165
+ }),
166
+ [dispatch, communicationLayer]
167
+ );
168
+ const messenger = useMemo(
169
+ () => new Messenger(messengerOptions),
170
+ [messengerOptions]
171
+ );
172
+ useEffect(() => {
173
+ return () => {
174
+ messenger.destroy();
175
+ };
176
+ }, []);
177
+ const selectPlayer = useCallback(
178
+ (playerID) => {
179
+ dispatch({
180
+ id: NOOP_ID,
181
+ sender: "internal",
182
+ context: "devtools",
183
+ _messenger_: false,
184
+ timestamp: Date.now(),
185
+ type: "PLAYER_DEVTOOLS_PLAYER_SELECTED",
186
+ payload: {
187
+ playerID
188
+ }
189
+ });
190
+ messenger.sendMessage({
191
+ type: "PLAYER_DEVTOOLS_PLUGIN_INTERACTION",
192
+ payload: {
193
+ type: "player-selected",
194
+ payload: playerID
195
+ }
196
+ });
197
+ },
198
+ [dispatch]
199
+ );
200
+ const selectPlugin = useCallback(
201
+ (pluginID) => {
202
+ dispatch({
203
+ id: NOOP_ID,
204
+ sender: "internal",
205
+ context: "devtools",
206
+ _messenger_: false,
207
+ timestamp: Date.now(),
208
+ type: "PLAYER_DEVTOOLS_PLUGIN_SELECTED",
209
+ payload: {
210
+ pluginID
211
+ }
212
+ });
213
+ },
214
+ [dispatch]
215
+ );
216
+ const handleInteraction = useCallback(
217
+ ({
218
+ type,
219
+ payload
220
+ }) => {
221
+ messenger.sendMessage({
222
+ type: "PLAYER_DEVTOOLS_PLUGIN_INTERACTION",
223
+ payload: {
224
+ type,
225
+ payload
226
+ },
227
+ ...state.current.player ? { target: state.current.player } : {}
228
+ });
229
+ },
230
+ [messenger]
231
+ );
232
+ return { state, selectPlayer, selectPlugin, handleInteraction };
233
+ };
234
+
235
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts
236
+ import { dequal } from "dequal";
237
+ var flowDiff = ({
238
+ curr,
239
+ next
240
+ }) => {
241
+ const currCopy = { ...curr, data: null };
242
+ const nextCopy = { ...next, data: null };
243
+ const baseFlowIsEqual = dequal(currCopy, nextCopy);
244
+ if (!baseFlowIsEqual) {
245
+ return { change: "flow", value: next };
246
+ }
247
+ const currData = curr.data;
248
+ const nextData = next.data;
249
+ const dataIsEqual = dequal(currData, nextData);
250
+ if (!dataIsEqual) {
251
+ return { change: "data", value: nextData };
252
+ }
253
+ return null;
254
+ };
255
+
256
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx
257
+ var fallbackRender = ({
258
+ error
259
+ }) => {
260
+ return /* @__PURE__ */ React.createElement(Container, { centerContent: true }, /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(Heading, null, "Ops, something went wrong.")), /* @__PURE__ */ React.createElement(CardBody, null, /* @__PURE__ */ React.createElement(Text, { as: "pre" }, error.message))));
261
+ };
262
+ var Panel = ({ communicationLayer, baseTheme }) => {
263
+ const { state, selectPlayer, selectPlugin, handleInteraction } = useExtensionState({
264
+ communicationLayer
265
+ });
266
+ const { reactPlayer, playerState } = useReactPlayer({
267
+ plugins: PLAYER_PLUGINS
268
+ });
269
+ const dataController = useRef(null);
270
+ const currentFlow = useRef(null);
271
+ useEffect2(() => {
272
+ reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
273
+ dataController.current = new WeakRef(d);
274
+ });
275
+ }, [reactPlayer]);
276
+ useEffect2(() => {
277
+ PUBSUB_PLUGIN.subscribe("*", (type, payload) => {
278
+ handleInteraction({
279
+ type,
280
+ payload
281
+ });
282
+ });
283
+ }, []);
284
+ useEffect2(() => {
285
+ const { player, plugin } = state.current;
286
+ const flow = player && plugin ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW : INITIAL_FLOW;
287
+ if (!currentFlow.current) {
288
+ currentFlow.current = flow;
289
+ reactPlayer.start(flow);
290
+ return;
291
+ }
292
+ const diff = flowDiff({
293
+ curr: currentFlow.current,
294
+ next: flow
295
+ });
296
+ if (diff) {
297
+ const { change, value } = diff;
298
+ if (change === "flow") {
299
+ currentFlow.current = value;
300
+ reactPlayer.start(value);
301
+ } else if (change === "data") {
302
+ if (dataController.current) {
303
+ dataController.current.deref()?.set(value);
304
+ } else {
305
+ reactPlayer.start(flow);
306
+ }
307
+ }
308
+ }
309
+ }, [reactPlayer, state]);
310
+ const isDarkMode = useDarkMode();
311
+ const colorMode = isDarkMode ? "dark" : "light";
312
+ const config = {
313
+ initialColorMode: colorMode,
314
+ useSystemColorMode: true
315
+ };
316
+ const theme = extendTheme({ config, ...baseTheme });
317
+ const Component = reactPlayer.Component;
318
+ return /* @__PURE__ */ React.createElement(ChakraProvider, { resetCSS: false, theme }, /* @__PURE__ */ React.createElement(ThemeProvider, { theme: "chrome", colorScheme: colorMode }, /* @__PURE__ */ React.createElement(ErrorBoundary, { fallbackRender }, /* @__PURE__ */ React.createElement(
319
+ Flex,
320
+ {
321
+ direction: "column",
322
+ h: "100vh",
323
+ alignItems: "normal",
324
+ overflow: "scroll"
325
+ },
326
+ state.current.player ? /* @__PURE__ */ React.createElement(Flex, { direction: "column", gap: "20px" }, /* @__PURE__ */ React.createElement(Flex, { gap: "16px" }, /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Player"), /* @__PURE__ */ React.createElement(
327
+ Select,
328
+ {
329
+ id: "player",
330
+ value: state.current.player || "",
331
+ onChange: (event) => selectPlayer(event.target.value)
332
+ },
333
+ Object.keys(state.players).map((playerID) => /* @__PURE__ */ React.createElement("option", { key: playerID, value: playerID }, playerID))
334
+ )), /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Plugin"), /* @__PURE__ */ React.createElement(
335
+ Select,
336
+ {
337
+ id: "plugin",
338
+ value: state.current.plugin || "",
339
+ onChange: (event) => selectPlugin(event.target.value)
340
+ },
341
+ Object.keys(
342
+ state.players[state.current.player]?.plugins ?? []
343
+ ).map((pluginID) => /* @__PURE__ */ React.createElement("option", { key: pluginID, value: pluginID }, pluginID))
344
+ ))), /* @__PURE__ */ React.createElement(Flex, { width: "100%" }, playerState.status === "error" ? fallbackRender({
345
+ error: playerState.error,
346
+ resetErrorBoundary: () => {
347
+ }
348
+ }) : /* @__PURE__ */ React.createElement(Component, null)), /* @__PURE__ */ React.createElement("details", null, /* @__PURE__ */ React.createElement("summary", null, "Debug"), /* @__PURE__ */ React.createElement("pre", { style: { maxHeight: "30vh", overflow: "scroll" } }, JSON.stringify(state, null, 2)))) : /* @__PURE__ */ React.createElement(Flex, { justifyContent: "center", padding: "6" }, /* @__PURE__ */ React.createElement(Text, null, "No Player-UI instance or devtools plugin detected. Visit", " ", /* @__PURE__ */ React.createElement("a", { href: "https://player-ui.github.io/" }, "https://player-ui.github.io/"), " ", "for more info."))
349
+ ))));
350
+ };
351
+ export {
352
+ Panel
353
+ };
354
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,354 @@
1
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx
2
+ import React, { useRef } from "react";
3
+ import { useReactPlayer } from "@player-ui/react";
4
+ import { useEffect as useEffect2 } from "react";
5
+ import { ErrorBoundary } from "react-error-boundary";
6
+ import {
7
+ Card,
8
+ CardBody,
9
+ CardHeader,
10
+ ChakraProvider,
11
+ Container,
12
+ extendTheme,
13
+ Flex,
14
+ FormControl,
15
+ FormLabel,
16
+ Heading,
17
+ Select,
18
+ Text
19
+ } from "@chakra-ui/react";
20
+ import { ThemeProvider, useDarkMode } from "@devtools-ds/themes";
21
+
22
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts
23
+ var INITIAL_FLOW = {
24
+ id: "initial-flow",
25
+ views: [
26
+ {
27
+ id: "view-1",
28
+ type: "text",
29
+ value: "connecting..."
30
+ }
31
+ ],
32
+ navigation: {
33
+ BEGIN: "FLOW_1",
34
+ FLOW_1: {
35
+ startState: "VIEW_1",
36
+ VIEW_1: {
37
+ state_type: "VIEW",
38
+ ref: "view-1",
39
+ transitions: {}
40
+ }
41
+ }
42
+ }
43
+ };
44
+ var INITIAL_EXTENSION_STATE = {
45
+ current: {
46
+ player: null,
47
+ plugin: null
48
+ },
49
+ players: {}
50
+ };
51
+
52
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
53
+ import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
54
+ import { PubSubPlugin } from "@player-ui/pubsub-plugin";
55
+ import { CommonExpressionsPlugin } from "@player-ui/common-expressions-plugin";
56
+ import { CommonTypesPlugin } from "@player-ui/common-types-plugin";
57
+ import { DataChangeListenerPlugin } from "@player-ui/data-change-listener-plugin";
58
+ import {
59
+ ConsoleLogger
60
+ } from "@player-ui/react";
61
+ var LogForwarder = class {
62
+ constructor() {
63
+ this.name = "Log";
64
+ }
65
+ apply(player) {
66
+ player.logger.addHandler(new ConsoleLogger("trace", console));
67
+ }
68
+ applyReact(reactPlayer) {
69
+ this.apply(reactPlayer.player);
70
+ }
71
+ };
72
+ var PUBSUB_PLUGIN = new PubSubPlugin();
73
+ var PLAYER_PLUGINS = [
74
+ new CommonTypesPlugin(),
75
+ new CommonExpressionsPlugin(),
76
+ new DataChangeListenerPlugin(),
77
+ new DevtoolsUIAssetsPlugin(),
78
+ new LogForwarder(),
79
+ PUBSUB_PLUGIN
80
+ ];
81
+
82
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
83
+ import { Messenger } from "@player-devtools/messenger";
84
+ import { useCallback, useEffect, useMemo, useReducer } from "react";
85
+
86
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts
87
+ import { dsetAssign } from "@player-devtools/utils";
88
+ import { produce } from "immer";
89
+ var reducer = (state, transaction) => {
90
+ switch (transaction.type) {
91
+ case "PLAYER_DEVTOOLS_PLAYER_INIT":
92
+ return produce(state, (draft) => {
93
+ const {
94
+ sender,
95
+ payload: { plugins }
96
+ } = transaction;
97
+ const [plugin] = Object.values(plugins);
98
+ if (!plugin) return;
99
+ draft.current.player = sender;
100
+ draft.current.plugin = draft.current.plugin || plugin.id;
101
+ dsetAssign(draft, ["players", sender, "plugins"], plugins, true);
102
+ dsetAssign(draft.players, [sender, "active"], true);
103
+ });
104
+ case "PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE":
105
+ return produce(state, (draft) => {
106
+ const {
107
+ sender,
108
+ payload: { flow, pluginID }
109
+ } = transaction;
110
+ dsetAssign(
111
+ draft,
112
+ ["players", sender, "plugins", pluginID, "flow"],
113
+ flow
114
+ );
115
+ });
116
+ case "PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE":
117
+ return produce(state, (draft) => {
118
+ const {
119
+ sender,
120
+ payload: { data, pluginID }
121
+ } = transaction;
122
+ dsetAssign(
123
+ draft,
124
+ ["players", sender, "plugins", pluginID, "flow", "data"],
125
+ data
126
+ );
127
+ });
128
+ case "MESSENGER_EVENT_BATCH":
129
+ return transaction.payload.events.reduce(reducer, state);
130
+ case "PLAYER_DEVTOOLS_PLAYER_STOPPED":
131
+ return produce(state, (draft) => {
132
+ const { sender } = transaction;
133
+ dsetAssign(draft, ["players", sender, "active"], false);
134
+ });
135
+ case "PLAYER_DEVTOOLS_PLAYER_SELECTED":
136
+ return produce(state, (draft) => {
137
+ const { playerID } = transaction.payload;
138
+ draft.current.player = playerID;
139
+ });
140
+ case "PLAYER_DEVTOOLS_PLUGIN_SELECTED":
141
+ return produce(state, (draft) => {
142
+ const { pluginID } = transaction.payload;
143
+ draft.current.plugin = pluginID;
144
+ });
145
+ default:
146
+ return state;
147
+ }
148
+ };
149
+
150
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
151
+ var NOOP_ID = -1;
152
+ var useExtensionState = ({
153
+ communicationLayer
154
+ }) => {
155
+ const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);
156
+ const messengerOptions = useMemo(
157
+ () => ({
158
+ context: "devtools",
159
+ target: "player",
160
+ messageCallback: (message) => {
161
+ dispatch(message);
162
+ },
163
+ ...communicationLayer,
164
+ logger: console
165
+ }),
166
+ [dispatch, communicationLayer]
167
+ );
168
+ const messenger = useMemo(
169
+ () => new Messenger(messengerOptions),
170
+ [messengerOptions]
171
+ );
172
+ useEffect(() => {
173
+ return () => {
174
+ messenger.destroy();
175
+ };
176
+ }, []);
177
+ const selectPlayer = useCallback(
178
+ (playerID) => {
179
+ dispatch({
180
+ id: NOOP_ID,
181
+ sender: "internal",
182
+ context: "devtools",
183
+ _messenger_: false,
184
+ timestamp: Date.now(),
185
+ type: "PLAYER_DEVTOOLS_PLAYER_SELECTED",
186
+ payload: {
187
+ playerID
188
+ }
189
+ });
190
+ messenger.sendMessage({
191
+ type: "PLAYER_DEVTOOLS_PLUGIN_INTERACTION",
192
+ payload: {
193
+ type: "player-selected",
194
+ payload: playerID
195
+ }
196
+ });
197
+ },
198
+ [dispatch]
199
+ );
200
+ const selectPlugin = useCallback(
201
+ (pluginID) => {
202
+ dispatch({
203
+ id: NOOP_ID,
204
+ sender: "internal",
205
+ context: "devtools",
206
+ _messenger_: false,
207
+ timestamp: Date.now(),
208
+ type: "PLAYER_DEVTOOLS_PLUGIN_SELECTED",
209
+ payload: {
210
+ pluginID
211
+ }
212
+ });
213
+ },
214
+ [dispatch]
215
+ );
216
+ const handleInteraction = useCallback(
217
+ ({
218
+ type,
219
+ payload
220
+ }) => {
221
+ messenger.sendMessage({
222
+ type: "PLAYER_DEVTOOLS_PLUGIN_INTERACTION",
223
+ payload: {
224
+ type,
225
+ payload
226
+ },
227
+ ...state.current.player ? { target: state.current.player } : {}
228
+ });
229
+ },
230
+ [messenger]
231
+ );
232
+ return { state, selectPlayer, selectPlugin, handleInteraction };
233
+ };
234
+
235
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts
236
+ import { dequal } from "dequal";
237
+ var flowDiff = ({
238
+ curr,
239
+ next
240
+ }) => {
241
+ const currCopy = { ...curr, data: null };
242
+ const nextCopy = { ...next, data: null };
243
+ const baseFlowIsEqual = dequal(currCopy, nextCopy);
244
+ if (!baseFlowIsEqual) {
245
+ return { change: "flow", value: next };
246
+ }
247
+ const currData = curr.data;
248
+ const nextData = next.data;
249
+ const dataIsEqual = dequal(currData, nextData);
250
+ if (!dataIsEqual) {
251
+ return { change: "data", value: nextData };
252
+ }
253
+ return null;
254
+ };
255
+
256
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx
257
+ var fallbackRender = ({
258
+ error
259
+ }) => {
260
+ return /* @__PURE__ */ React.createElement(Container, { centerContent: true }, /* @__PURE__ */ React.createElement(Card, null, /* @__PURE__ */ React.createElement(CardHeader, null, /* @__PURE__ */ React.createElement(Heading, null, "Ops, something went wrong.")), /* @__PURE__ */ React.createElement(CardBody, null, /* @__PURE__ */ React.createElement(Text, { as: "pre" }, error.message))));
261
+ };
262
+ var Panel = ({ communicationLayer, baseTheme }) => {
263
+ const { state, selectPlayer, selectPlugin, handleInteraction } = useExtensionState({
264
+ communicationLayer
265
+ });
266
+ const { reactPlayer, playerState } = useReactPlayer({
267
+ plugins: PLAYER_PLUGINS
268
+ });
269
+ const dataController = useRef(null);
270
+ const currentFlow = useRef(null);
271
+ useEffect2(() => {
272
+ reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
273
+ dataController.current = new WeakRef(d);
274
+ });
275
+ }, [reactPlayer]);
276
+ useEffect2(() => {
277
+ PUBSUB_PLUGIN.subscribe("*", (type, payload) => {
278
+ handleInteraction({
279
+ type,
280
+ payload
281
+ });
282
+ });
283
+ }, []);
284
+ useEffect2(() => {
285
+ const { player, plugin } = state.current;
286
+ const flow = player && plugin ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW : INITIAL_FLOW;
287
+ if (!currentFlow.current) {
288
+ currentFlow.current = flow;
289
+ reactPlayer.start(flow);
290
+ return;
291
+ }
292
+ const diff = flowDiff({
293
+ curr: currentFlow.current,
294
+ next: flow
295
+ });
296
+ if (diff) {
297
+ const { change, value } = diff;
298
+ if (change === "flow") {
299
+ currentFlow.current = value;
300
+ reactPlayer.start(value);
301
+ } else if (change === "data") {
302
+ if (dataController.current) {
303
+ dataController.current.deref()?.set(value);
304
+ } else {
305
+ reactPlayer.start(flow);
306
+ }
307
+ }
308
+ }
309
+ }, [reactPlayer, state]);
310
+ const isDarkMode = useDarkMode();
311
+ const colorMode = isDarkMode ? "dark" : "light";
312
+ const config = {
313
+ initialColorMode: colorMode,
314
+ useSystemColorMode: true
315
+ };
316
+ const theme = extendTheme({ config, ...baseTheme });
317
+ const Component = reactPlayer.Component;
318
+ return /* @__PURE__ */ React.createElement(ChakraProvider, { resetCSS: false, theme }, /* @__PURE__ */ React.createElement(ThemeProvider, { theme: "chrome", colorScheme: colorMode }, /* @__PURE__ */ React.createElement(ErrorBoundary, { fallbackRender }, /* @__PURE__ */ React.createElement(
319
+ Flex,
320
+ {
321
+ direction: "column",
322
+ h: "100vh",
323
+ alignItems: "normal",
324
+ overflow: "scroll"
325
+ },
326
+ state.current.player ? /* @__PURE__ */ React.createElement(Flex, { direction: "column", gap: "20px" }, /* @__PURE__ */ React.createElement(Flex, { gap: "16px" }, /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Player"), /* @__PURE__ */ React.createElement(
327
+ Select,
328
+ {
329
+ id: "player",
330
+ value: state.current.player || "",
331
+ onChange: (event) => selectPlayer(event.target.value)
332
+ },
333
+ Object.keys(state.players).map((playerID) => /* @__PURE__ */ React.createElement("option", { key: playerID, value: playerID }, playerID))
334
+ )), /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Plugin"), /* @__PURE__ */ React.createElement(
335
+ Select,
336
+ {
337
+ id: "plugin",
338
+ value: state.current.plugin || "",
339
+ onChange: (event) => selectPlugin(event.target.value)
340
+ },
341
+ Object.keys(
342
+ state.players[state.current.player]?.plugins ?? []
343
+ ).map((pluginID) => /* @__PURE__ */ React.createElement("option", { key: pluginID, value: pluginID }, pluginID))
344
+ ))), /* @__PURE__ */ React.createElement(Flex, { width: "100%" }, playerState.status === "error" ? fallbackRender({
345
+ error: playerState.error,
346
+ resetErrorBoundary: () => {
347
+ }
348
+ }) : /* @__PURE__ */ React.createElement(Component, null)), /* @__PURE__ */ React.createElement("details", null, /* @__PURE__ */ React.createElement("summary", null, "Debug"), /* @__PURE__ */ React.createElement("pre", { style: { maxHeight: "30vh", overflow: "scroll" } }, JSON.stringify(state, null, 2)))) : /* @__PURE__ */ React.createElement(Flex, { justifyContent: "center", padding: "6" }, /* @__PURE__ */ React.createElement(Text, null, "No Player-UI instance or devtools plugin detected. Visit", " ", /* @__PURE__ */ React.createElement("a", { href: "https://player-ui.github.io/" }, "https://player-ui.github.io/"), " ", "for more info."))
349
+ ))));
350
+ };
351
+ export {
352
+ Panel
353
+ };
354
+ //# sourceMappingURL=index.mjs.map