@player-tools/devtools-client 0.5.2-next.2 → 0.5.3--canary.90.2515

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.
@@ -1,218 +1,313 @@
1
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/redux/index.ts
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";
2
6
  import {
3
- clearStore,
4
- playerFlowStartAction,
5
- playerInitAction,
6
- playerRemoveAction,
7
- playerTimelineAction,
8
- playerViewUpdateAction,
9
- selectedPlayerAction
10
- } from "@player-tools/devtools-common";
7
+ Card,
8
+ CardBody,
9
+ CardHeader,
10
+ ChakraProvider,
11
+ Container,
12
+ Flex,
13
+ FormControl,
14
+ FormLabel,
15
+ Heading,
16
+ HStack,
17
+ Select,
18
+ Text,
19
+ VStack
20
+ } from "@chakra-ui/react";
21
+ import { ThemeProvider } from "@devtools-ds/themes";
11
22
 
12
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/redux/aliases.ts
13
- var GET_INFO_DETAILS = "GET_INFO_DETAILS";
14
- var GET_CONFIG_DETAILS = "GET_CONFIG_DETAILS";
15
- var GET_VIEW_DETAILS = "GET_VIEW_DETAILS";
16
- var GET_DATA_BINDING_DETAILS = "GET_DATA_BINDING_DETAILS";
17
- var GET_CONSOLE_EVAL = "GET_CONSOLE_EVAL";
18
- var START_PROFILER = "START_PROFILER";
19
- var STOP_PROFILER = "STOP_PROFILER";
20
- var _alias = (aliases) => () => (next) => (action) => {
21
- const alias = aliases[action.type];
22
- if (alias) {
23
- return next(alias(action));
23
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/constants/index.ts
24
+ import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
25
+ import { PubSubPlugin } from "@player-ui/pubsub-plugin";
26
+ var PUBSUB_PLUGIN = new PubSubPlugin();
27
+ var PLAYER_PLUGINS = [
28
+ new DevtoolsUIAssetsPlugin(),
29
+ PUBSUB_PLUGIN
30
+ ];
31
+ var INITIAL_FLOW = {
32
+ id: "initial-flow",
33
+ views: [
34
+ {
35
+ id: "view-1",
36
+ type: "text",
37
+ value: "connecting..."
38
+ }
39
+ ],
40
+ navigation: {
41
+ BEGIN: "FLOW_1",
42
+ FLOW_1: {
43
+ startState: "VIEW_1",
44
+ VIEW_1: {
45
+ state_type: "VIEW",
46
+ ref: "view-1",
47
+ transitions: {}
48
+ }
49
+ }
24
50
  }
25
- return next(action);
26
51
  };
27
- var buildAliases = (actions) => _alias({
28
- GET_INFO_DETAILS: (action) => actions["player-runtime-info-request"](action.payload),
29
- GET_CONFIG_DETAILS: (action) => actions["player-config-request"](action.payload),
30
- GET_VIEW_DETAILS: (action) => actions["player-view-details-request"](action.payload),
31
- GET_DATA_BINDING_DETAILS: (action) => actions["player-data-binding-details"](action.payload),
32
- GET_CONSOLE_EVAL: (action) => actions["player-execute-expression"](action.payload),
33
- START_PROFILER: (action) => actions["player-start-profiler-request"](action.payload),
34
- STOP_PROFILER: (action) => actions["player-stop-profiler-request"](action.payload)
35
- });
52
+ var INITIAL_EXTENSION_STATE = {
53
+ current: {
54
+ player: null,
55
+ plugin: null
56
+ },
57
+ players: {}
58
+ };
36
59
 
37
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/redux/actions.ts
38
- import { createAsyncThunk } from "@reduxjs/toolkit";
39
- import {
40
- Runtime,
41
- createLogger,
42
- BACKGROUND_SOURCE
43
- } from "@player-tools/devtools-common";
44
- var logger = createLogger(BACKGROUND_SOURCE);
45
- var buildRPCActions = (handlers) => Runtime.RuntimeRPCTypes.reduce((acc, rpcType) => {
46
- acc[rpcType] = createAsyncThunk(rpcType, async (params) => {
47
- logger.log(`Requesting ${rpcType}`, params);
48
- const data = await handlers[rpcType].call(params);
49
- logger.log(`Response from ${rpcType}`, data);
50
- return data;
51
- });
52
- return acc;
53
- }, {});
60
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
61
+ import { Messenger } from "@player-tools/devtools-messenger";
62
+ import { useCallback, useEffect, useMemo, useReducer } from "react";
54
63
 
55
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/redux/reducers.ts
56
- var buildPlayerReducerCallback = (actions) => (builder) => {
57
- builder.addCase(
58
- actions["player-runtime-info-request"].fulfilled,
59
- (state, action) => {
60
- const { activePlayers, selectedPlayerId } = state;
61
- if (!selectedPlayerId) {
62
- return;
63
- }
64
- const data = action.payload && Object.keys(action.payload).length > 0 ? action.payload : null;
65
- activePlayers[selectedPlayerId].flowInfo = data;
66
- }
67
- );
68
- builder.addCase(
69
- actions["player-config-request"].fulfilled,
70
- (state, action) => {
71
- const { activePlayers, selectedPlayerId } = state;
72
- if (!selectedPlayerId) {
73
- return;
74
- }
75
- activePlayers[selectedPlayerId].configState = action.payload;
76
- }
64
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts
65
+ import { dset } from "dset/merge";
66
+ import { produce } from "immer";
67
+ var reducer = (state, transaction) => {
68
+ switch (transaction.type) {
69
+ case "PLAYER_DEVTOOLS_PLAYER_INIT":
70
+ return produce(state, (draft) => {
71
+ const {
72
+ sender,
73
+ payload: { plugins }
74
+ } = transaction;
75
+ const { player, plugin } = draft.current;
76
+ if (!player && !plugin) {
77
+ dset(draft, ["current", "player"], sender);
78
+ dset(
79
+ draft,
80
+ ["current", "plugin"],
81
+ plugins[Object.keys(plugins)[0]].id
82
+ );
83
+ }
84
+ dset(draft, ["players", sender, "plugins"], plugins);
85
+ dset(draft, ["players", sender, "active"], true);
86
+ });
87
+ case "PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE":
88
+ return produce(state, (draft) => {
89
+ const {
90
+ sender,
91
+ payload: { flow, pluginID }
92
+ } = transaction;
93
+ dset(draft, ["players", sender, "plugins", pluginID, "flow"], flow);
94
+ });
95
+ case "PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE":
96
+ return produce(state, (draft) => {
97
+ const {
98
+ sender,
99
+ payload: { data, pluginID }
100
+ } = transaction;
101
+ dset(
102
+ draft,
103
+ ["players", sender, "plugins", pluginID, "flow", "data"],
104
+ data
105
+ );
106
+ });
107
+ case "MESSENGER_EVENT_BATCH":
108
+ return produce(state, (draft) => {
109
+ return transaction.payload.events.reduce(reducer, draft);
110
+ });
111
+ case "PLAYER_DEVTOOLS_PLAYER_STOPPED":
112
+ return produce(state, (draft) => {
113
+ const { sender } = transaction;
114
+ dset(draft, ["players", sender, "active"], false);
115
+ });
116
+ case "PLAYER_DEVTOOLS_PLAYER_SELECTED":
117
+ return produce(state, (draft) => {
118
+ const { playerID } = transaction.payload;
119
+ dset(draft, ["current", "player"], playerID);
120
+ });
121
+ case "PLAYER_DEVTOOLS_PLUGIN_SELECTED":
122
+ return produce(state, (draft) => {
123
+ const { pluginID } = transaction.payload;
124
+ dset(draft, ["current", "plugin"], pluginID);
125
+ });
126
+ default:
127
+ return state;
128
+ }
129
+ };
130
+
131
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
132
+ var NOOP_ID = -1;
133
+ var useExtensionState = ({
134
+ communicationLayer
135
+ }) => {
136
+ const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);
137
+ const messengerOptions = useMemo(
138
+ () => ({
139
+ context: "devtools",
140
+ target: "player",
141
+ messageCallback: (message) => {
142
+ dispatch(message);
143
+ },
144
+ ...communicationLayer,
145
+ logger: console
146
+ }),
147
+ [dispatch, communicationLayer]
77
148
  );
78
- builder.addCase(
79
- actions["player-view-details-request"].fulfilled,
80
- (state, action) => {
81
- const { activePlayers, selectedPlayerId } = state;
82
- if (!selectedPlayerId) {
83
- return;
84
- }
85
- activePlayers[selectedPlayerId].view = action.payload?.lastViewUpdate;
86
- }
149
+ const messenger = useMemo(
150
+ () => new Messenger(messengerOptions),
151
+ [messengerOptions]
87
152
  );
88
- builder.addCase(
89
- actions["player-data-binding-details"].fulfilled,
90
- (state, action) => {
91
- const {
92
- meta: {
93
- arg: { binding, playerID }
94
- },
95
- payload
96
- } = action;
97
- const { activePlayers } = state;
98
- if (!playerID || !activePlayers[playerID]) {
99
- return;
100
- }
101
- if (binding === "") {
102
- activePlayers[playerID].dataState.allBindings = payload;
103
- return;
104
- }
105
- activePlayers[playerID].dataState.selectedBinding = payload;
106
- }
107
- );
108
- builder.addCase(
109
- actions["player-execute-expression"].fulfilled,
110
- (state, action) => {
111
- const { activePlayers, selectedPlayerId } = state;
112
- if (!selectedPlayerId) {
113
- return;
114
- }
115
- activePlayers[selectedPlayerId].consoleState?.history?.push({
116
- id: action.meta.requestId,
117
- result: action.payload,
118
- expression: action.payload?.exp ?? ""
153
+ useEffect(() => {
154
+ return () => {
155
+ messenger.destroy();
156
+ };
157
+ }, []);
158
+ const selectPlayer = useCallback(
159
+ (playerID) => {
160
+ dispatch({
161
+ id: NOOP_ID,
162
+ sender: "internal",
163
+ context: "devtools",
164
+ _messenger_: false,
165
+ timestamp: Date.now(),
166
+ type: "PLAYER_DEVTOOLS_PLAYER_SELECTED",
167
+ payload: {
168
+ playerID
169
+ }
119
170
  });
120
- }
171
+ },
172
+ [dispatch]
121
173
  );
122
- builder.addCase(
123
- actions["player-start-profiler-request"].fulfilled,
124
- (state, action) => {
125
- const { activePlayers, selectedPlayerId } = state;
126
- if (!selectedPlayerId)
127
- return;
128
- activePlayers[selectedPlayerId].profilerInfo = action.payload?.data;
129
- }
174
+ const selectPlugin = useCallback(
175
+ (pluginID) => {
176
+ dispatch({
177
+ id: NOOP_ID,
178
+ sender: "internal",
179
+ context: "devtools",
180
+ _messenger_: false,
181
+ timestamp: Date.now(),
182
+ type: "PLAYER_DEVTOOLS_PLUGIN_SELECTED",
183
+ payload: {
184
+ pluginID
185
+ }
186
+ });
187
+ },
188
+ [dispatch]
130
189
  );
131
- builder.addCase(
132
- actions["player-stop-profiler-request"].fulfilled,
133
- (state, action) => {
134
- const { activePlayers, selectedPlayerId } = state;
135
- if (!selectedPlayerId)
136
- return;
137
- activePlayers[selectedPlayerId].profilerInfo = action.payload?.data;
138
- }
190
+ const handleInteraction = useCallback(
191
+ ({
192
+ type,
193
+ payload
194
+ }) => {
195
+ messenger.sendMessage({
196
+ type: "PLAYER_DEVTOOLS_PLUGIN_INTERACTION",
197
+ payload: {
198
+ type,
199
+ payload
200
+ }
201
+ });
202
+ },
203
+ [messenger]
139
204
  );
205
+ return { state, selectPlayer, selectPlugin, handleInteraction };
140
206
  };
141
207
 
142
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/redux/index.ts
143
- function handleMessage(store, message) {
144
- switch (message.type) {
145
- case "runtime-init":
146
- store.dispatch(clearStore());
147
- break;
148
- case "player-init":
149
- store.dispatch(playerInitAction(message));
150
- store.dispatch(selectedPlayerAction());
151
- break;
152
- case "player-removed":
153
- store.dispatch(playerRemoveAction(message.playerID));
154
- store.dispatch(selectedPlayerAction());
155
- break;
156
- case "player-flow-start":
157
- store.dispatch(playerFlowStartAction(message));
158
- store.dispatch(playerTimelineAction(message));
159
- store.dispatch({
160
- type: GET_DATA_BINDING_DETAILS,
161
- payload: { playerID: message.playerID, binding: "" }
162
- });
163
- break;
164
- case "player-log-event":
165
- store.dispatch(playerTimelineAction(message));
166
- break;
167
- case "player-view-update-event":
168
- store.dispatch(playerViewUpdateAction(message));
169
- break;
170
- case "player-data-change-event": {
171
- const { players } = store.getState();
172
- if (players.activePlayers[message.playerID] && players.activePlayers[message.playerID].dataState.selectedBinding) {
173
- store.dispatch({
174
- type: GET_DATA_BINDING_DETAILS,
175
- payload: message
176
- });
177
- }
178
- store.dispatch({
179
- type: GET_DATA_BINDING_DETAILS,
180
- payload: { playerID: message.playerID, binding: "" }
181
- });
182
- store.dispatch(playerTimelineAction(message));
183
- break;
184
- }
185
- default:
186
- console.warn(`Unhandled event: ${JSON.stringify(message)}`);
187
- break;
208
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts
209
+ import { dequal } from "dequal";
210
+ var flowDiff = ({
211
+ curr,
212
+ next
213
+ }) => {
214
+ const currCopy = { ...curr, data: null };
215
+ const nextCopy = { ...next, data: null };
216
+ const baseFlowIsEqual = dequal(currCopy, nextCopy);
217
+ if (!baseFlowIsEqual) {
218
+ return { change: "flow", value: next };
188
219
  }
189
- }
220
+ const currData = curr.data;
221
+ const nextData = next.data;
222
+ const dataIsEqual = dequal(currData, nextData);
223
+ if (!dataIsEqual) {
224
+ return { change: "data", value: nextData };
225
+ }
226
+ return null;
227
+ };
190
228
 
191
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/rpc/index.ts
192
- import {
193
- createRPCRequest,
194
- Runtime as Runtime2,
195
- PANEL_SOURCE
196
- } from "@player-tools/devtools-common";
197
- var buildRPCRequests = (onRequestMessage) => Runtime2.RuntimeRPCTypes.reduce((acc, rpcType) => {
198
- acc[rpcType] = createRPCRequest(rpcType, PANEL_SOURCE, onRequestMessage);
199
- return acc;
200
- }, {});
229
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/theme.ts
230
+ import { extendTheme } from "@chakra-ui/react";
231
+ var config = {
232
+ initialColorMode: "dark",
233
+ useSystemColorMode: false
234
+ };
235
+ var theme = extendTheme({ config });
201
236
 
202
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/index.ts
203
- export * from "@player-tools/devtools-common";
237
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx
238
+ var fallbackRender = ({
239
+ error
240
+ }) => {
241
+ 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)));
242
+ };
243
+ var Panel = ({
244
+ communicationLayer
245
+ }) => {
246
+ const { state, selectPlayer, selectPlugin, handleInteraction } = useExtensionState({
247
+ communicationLayer
248
+ });
249
+ const { reactPlayer } = useReactPlayer({
250
+ plugins: PLAYER_PLUGINS
251
+ });
252
+ const dataController = useRef(null);
253
+ const currentFlow = useRef(null);
254
+ useEffect2(() => {
255
+ reactPlayer.player.hooks.dataController.tap("panel", (d) => {
256
+ dataController.current = new WeakRef(d);
257
+ });
258
+ }, [reactPlayer]);
259
+ useEffect2(() => {
260
+ PUBSUB_PLUGIN.subscribe("*", (type, payload) => {
261
+ handleInteraction({
262
+ type,
263
+ payload
264
+ });
265
+ });
266
+ }, []);
267
+ useEffect2(() => {
268
+ const { player, plugin } = state.current;
269
+ const flow = player && plugin ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW : INITIAL_FLOW;
270
+ if (!currentFlow.current) {
271
+ currentFlow.current = flow;
272
+ reactPlayer.start(flow);
273
+ return;
274
+ }
275
+ const diff = flowDiff({
276
+ curr: currentFlow.current,
277
+ next: flow
278
+ });
279
+ if (diff) {
280
+ const { change, value } = diff;
281
+ if (change === "flow") {
282
+ currentFlow.current = value;
283
+ reactPlayer.start(value);
284
+ } else if (change === "data") {
285
+ dataController.current ? dataController.current.deref()?.set(value) : reactPlayer.start(flow);
286
+ }
287
+ }
288
+ }, [reactPlayer, state]);
289
+ const Component = reactPlayer.Component;
290
+ return /* @__PURE__ */ React.createElement(ChakraProvider, { theme }, /* @__PURE__ */ React.createElement(ThemeProvider, { colorScheme: "dark" }, /* @__PURE__ */ React.createElement(ErrorBoundary, { fallbackRender }, /* @__PURE__ */ React.createElement(VStack, { w: "100vw", h: "100vh" }, state.current.player ? /* @__PURE__ */ React.createElement(Flex, { direction: "column", marginTop: "4" }, /* @__PURE__ */ React.createElement(HStack, { spacing: "4" }, /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Player"), /* @__PURE__ */ React.createElement(
291
+ Select,
292
+ {
293
+ id: "player",
294
+ value: state.current.player || "",
295
+ onChange: (event) => selectPlayer(event.target.value)
296
+ },
297
+ Object.keys(state.players).map((playerID) => /* @__PURE__ */ React.createElement("option", { key: playerID, value: playerID }, playerID))
298
+ )), /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Plugin"), /* @__PURE__ */ React.createElement(
299
+ Select,
300
+ {
301
+ id: "plugin",
302
+ value: state.current.plugin || "",
303
+ onChange: (event) => selectPlugin(event.target.value)
304
+ },
305
+ Object.keys(
306
+ state.players[state.current.player].plugins
307
+ ).map((pluginID) => /* @__PURE__ */ React.createElement("option", { key: pluginID, value: pluginID }, pluginID))
308
+ ))), /* @__PURE__ */ React.createElement(Container, { marginY: "6" }, /* @__PURE__ */ React.createElement(Component, null)), /* @__PURE__ */ React.createElement("details", null, /* @__PURE__ */ React.createElement("summary", null, "Debug"), /* @__PURE__ */ React.createElement("pre", null, 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."))))));
309
+ };
204
310
  export {
205
- GET_CONFIG_DETAILS,
206
- GET_CONSOLE_EVAL,
207
- GET_DATA_BINDING_DETAILS,
208
- GET_INFO_DETAILS,
209
- GET_VIEW_DETAILS,
210
- START_PROFILER,
211
- STOP_PROFILER,
212
- buildAliases,
213
- buildPlayerReducerCallback,
214
- buildRPCActions,
215
- buildRPCRequests,
216
- handleMessage
311
+ Panel
217
312
  };
218
313
  //# sourceMappingURL=index.mjs.map