@player-tools/devtools-client 0.5.3-next.0 → 0.6.0-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.
@@ -1,218 +1,315 @@
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
+ var INITIAL_FLOW = {
25
+ id: "initial-flow",
26
+ views: [
27
+ {
28
+ id: "view-1",
29
+ type: "text",
30
+ value: "connecting..."
31
+ }
32
+ ],
33
+ navigation: {
34
+ BEGIN: "FLOW_1",
35
+ FLOW_1: {
36
+ startState: "VIEW_1",
37
+ VIEW_1: {
38
+ state_type: "VIEW",
39
+ ref: "view-1",
40
+ transitions: {}
41
+ }
42
+ }
24
43
  }
25
- return next(action);
26
44
  };
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
- });
45
+ var INITIAL_EXTENSION_STATE = {
46
+ current: {
47
+ player: null,
48
+ plugin: null
49
+ },
50
+ players: {}
51
+ };
36
52
 
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
- }, {});
53
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/plugins/index.ts
54
+ import DevtoolsUIAssetsPlugin from "@devtools-ui/plugin";
55
+ import { PubSubPlugin } from "@player-ui/pubsub-plugin";
56
+ var PUBSUB_PLUGIN = new PubSubPlugin();
57
+ var PLAYER_PLUGINS = [
58
+ new DevtoolsUIAssetsPlugin(),
59
+ PUBSUB_PLUGIN
60
+ ];
54
61
 
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
- }
77
- );
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
- }
62
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
63
+ import { Messenger } from "@player-tools/devtools-messenger";
64
+ import { useCallback, useEffect, useMemo, useReducer } from "react";
65
+
66
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/reducer.ts
67
+ import { dset } from "dset/merge";
68
+ import { produce } from "immer";
69
+ var reducer = (state, transaction) => {
70
+ switch (transaction.type) {
71
+ case "PLAYER_DEVTOOLS_PLAYER_INIT":
72
+ return produce(state, (draft) => {
73
+ const {
74
+ sender,
75
+ payload: { plugins }
76
+ } = transaction;
77
+ const { player, plugin } = draft.current;
78
+ if (!player && !plugin) {
79
+ dset(draft, ["current", "player"], sender);
80
+ dset(
81
+ draft,
82
+ ["current", "plugin"],
83
+ plugins[Object.keys(plugins)[0]].id
84
+ );
85
+ }
86
+ dset(draft, ["players", sender, "plugins"], plugins);
87
+ dset(draft, ["players", sender, "active"], true);
88
+ });
89
+ case "PLAYER_DEVTOOLS_PLUGIN_FLOW_CHANGE":
90
+ return produce(state, (draft) => {
91
+ const {
92
+ sender,
93
+ payload: { flow, pluginID }
94
+ } = transaction;
95
+ dset(draft, ["players", sender, "plugins", pluginID, "flow"], flow);
96
+ });
97
+ case "PLAYER_DEVTOOLS_PLUGIN_DATA_CHANGE":
98
+ return produce(state, (draft) => {
99
+ const {
100
+ sender,
101
+ payload: { data, pluginID }
102
+ } = transaction;
103
+ dset(
104
+ draft,
105
+ ["players", sender, "plugins", pluginID, "flow", "data"],
106
+ data
107
+ );
108
+ });
109
+ case "MESSENGER_EVENT_BATCH":
110
+ return produce(state, (draft) => {
111
+ return transaction.payload.events.reduce(reducer, draft);
112
+ });
113
+ case "PLAYER_DEVTOOLS_PLAYER_STOPPED":
114
+ return produce(state, (draft) => {
115
+ const { sender } = transaction;
116
+ dset(draft, ["players", sender, "active"], false);
117
+ });
118
+ case "PLAYER_DEVTOOLS_PLAYER_SELECTED":
119
+ return produce(state, (draft) => {
120
+ const { playerID } = transaction.payload;
121
+ dset(draft, ["current", "player"], playerID);
122
+ });
123
+ case "PLAYER_DEVTOOLS_PLUGIN_SELECTED":
124
+ return produce(state, (draft) => {
125
+ const { pluginID } = transaction.payload;
126
+ dset(draft, ["current", "plugin"], pluginID);
127
+ });
128
+ default:
129
+ return state;
130
+ }
131
+ };
132
+
133
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/state/index.ts
134
+ var NOOP_ID = -1;
135
+ var useExtensionState = ({
136
+ communicationLayer
137
+ }) => {
138
+ const [state, dispatch] = useReducer(reducer, INITIAL_EXTENSION_STATE);
139
+ const messengerOptions = useMemo(
140
+ () => ({
141
+ context: "devtools",
142
+ target: "player",
143
+ messageCallback: (message) => {
144
+ dispatch(message);
145
+ },
146
+ ...communicationLayer,
147
+ logger: console
148
+ }),
149
+ [dispatch, communicationLayer]
87
150
  );
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
- }
151
+ const messenger = useMemo(
152
+ () => new Messenger(messengerOptions),
153
+ [messengerOptions]
107
154
  );
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 ?? ""
155
+ useEffect(() => {
156
+ return () => {
157
+ messenger.destroy();
158
+ };
159
+ }, []);
160
+ const selectPlayer = useCallback(
161
+ (playerID) => {
162
+ dispatch({
163
+ id: NOOP_ID,
164
+ sender: "internal",
165
+ context: "devtools",
166
+ _messenger_: false,
167
+ timestamp: Date.now(),
168
+ type: "PLAYER_DEVTOOLS_PLAYER_SELECTED",
169
+ payload: {
170
+ playerID
171
+ }
119
172
  });
120
- }
173
+ },
174
+ [dispatch]
121
175
  );
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
- }
176
+ const selectPlugin = useCallback(
177
+ (pluginID) => {
178
+ dispatch({
179
+ id: NOOP_ID,
180
+ sender: "internal",
181
+ context: "devtools",
182
+ _messenger_: false,
183
+ timestamp: Date.now(),
184
+ type: "PLAYER_DEVTOOLS_PLUGIN_SELECTED",
185
+ payload: {
186
+ pluginID
187
+ }
188
+ });
189
+ },
190
+ [dispatch]
130
191
  );
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
- }
192
+ const handleInteraction = useCallback(
193
+ ({
194
+ type,
195
+ payload
196
+ }) => {
197
+ messenger.sendMessage({
198
+ type: "PLAYER_DEVTOOLS_PLUGIN_INTERACTION",
199
+ payload: {
200
+ type,
201
+ payload
202
+ }
203
+ });
204
+ },
205
+ [messenger]
139
206
  );
207
+ return { state, selectPlayer, selectPlugin, handleInteraction };
140
208
  };
141
209
 
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;
210
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/helpers/flowDiff.ts
211
+ import { dequal } from "dequal";
212
+ var flowDiff = ({
213
+ curr,
214
+ next
215
+ }) => {
216
+ const currCopy = { ...curr, data: null };
217
+ const nextCopy = { ...next, data: null };
218
+ const baseFlowIsEqual = dequal(currCopy, nextCopy);
219
+ if (!baseFlowIsEqual) {
220
+ return { change: "flow", value: next };
188
221
  }
189
- }
222
+ const currData = curr.data;
223
+ const nextData = next.data;
224
+ const dataIsEqual = dequal(currData, nextData);
225
+ if (!dataIsEqual) {
226
+ return { change: "data", value: nextData };
227
+ }
228
+ return null;
229
+ };
190
230
 
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
- }, {});
231
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/theme.ts
232
+ import { extendTheme } from "@chakra-ui/react";
233
+ var config = {
234
+ initialColorMode: "dark",
235
+ useSystemColorMode: false
236
+ };
237
+ var theme = extendTheme({ config });
201
238
 
202
- // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/index.ts
203
- export * from "@player-tools/devtools-common";
239
+ // ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/client/src/panel/index.tsx
240
+ var fallbackRender = ({
241
+ error
242
+ }) => {
243
+ 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)));
244
+ };
245
+ var Panel = ({
246
+ communicationLayer
247
+ }) => {
248
+ const { state, selectPlayer, selectPlugin, handleInteraction } = useExtensionState({
249
+ communicationLayer
250
+ });
251
+ const { reactPlayer } = useReactPlayer({
252
+ plugins: PLAYER_PLUGINS
253
+ });
254
+ const dataController = useRef(null);
255
+ const currentFlow = useRef(null);
256
+ useEffect2(() => {
257
+ reactPlayer.player.hooks.dataController.tap("devtools-panel", (d) => {
258
+ dataController.current = new WeakRef(d);
259
+ });
260
+ }, [reactPlayer]);
261
+ useEffect2(() => {
262
+ PUBSUB_PLUGIN.subscribe("*", (type, payload) => {
263
+ handleInteraction({
264
+ type,
265
+ payload
266
+ });
267
+ });
268
+ }, []);
269
+ useEffect2(() => {
270
+ const { player, plugin } = state.current;
271
+ const flow = player && plugin ? state.players[player]?.plugins?.[plugin]?.flow || INITIAL_FLOW : INITIAL_FLOW;
272
+ if (!currentFlow.current) {
273
+ currentFlow.current = flow;
274
+ reactPlayer.start(flow);
275
+ return;
276
+ }
277
+ const diff = flowDiff({
278
+ curr: currentFlow.current,
279
+ next: flow
280
+ });
281
+ if (diff) {
282
+ const { change, value } = diff;
283
+ if (change === "flow") {
284
+ currentFlow.current = value;
285
+ reactPlayer.start(value);
286
+ } else if (change === "data") {
287
+ dataController.current ? dataController.current.deref()?.set(value) : reactPlayer.start(flow);
288
+ }
289
+ }
290
+ }, [reactPlayer, state]);
291
+ const Component = reactPlayer.Component;
292
+ 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(
293
+ Select,
294
+ {
295
+ id: "player",
296
+ value: state.current.player || "",
297
+ onChange: (event) => selectPlayer(event.target.value)
298
+ },
299
+ Object.keys(state.players).map((playerID) => /* @__PURE__ */ React.createElement("option", { key: playerID, value: playerID }, playerID))
300
+ )), /* @__PURE__ */ React.createElement(FormControl, null, /* @__PURE__ */ React.createElement(FormLabel, null, "Plugin"), /* @__PURE__ */ React.createElement(
301
+ Select,
302
+ {
303
+ id: "plugin",
304
+ value: state.current.plugin || "",
305
+ onChange: (event) => selectPlugin(event.target.value)
306
+ },
307
+ Object.keys(
308
+ state.players[state.current.player].plugins
309
+ ).map((pluginID) => /* @__PURE__ */ React.createElement("option", { key: pluginID, value: pluginID }, pluginID))
310
+ ))), /* @__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."))))));
311
+ };
204
312
  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
313
+ Panel
217
314
  };
218
315
  //# sourceMappingURL=index.mjs.map