@player-devtools/basic-plugin 1.0.1-next.0 → 1.1.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.
@@ -20,15 +20,24 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/index.ts
21
21
  var src_exports = {};
22
22
  __export(src_exports, {
23
- BasicDevtoolsPlugin: () => BasicDevtoolsPlugin
23
+ BasicDevtoolsPlugin: () => BasicDevtoolsPlugin,
24
+ playerConfigContextKey: () => playerConfigContextKey
24
25
  });
25
26
  module.exports = __toCommonJS(src_exports);
26
27
 
27
28
  // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts
28
29
  var import_basic_plugin_content = require("@player-devtools/basic-plugin-content");
29
30
  var import_plugin = require("@player-devtools/plugin");
30
- var import_utils = require("@player-devtools/utils");
31
- var import_immer = require("immer");
31
+ var import_context_plugin2 = require("@player-ui/context-plugin");
32
+
33
+ // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/context.ts
34
+ var import_context_plugin = require("@player-ui/context-plugin");
35
+ var playerConfigContextKey = (0, import_context_plugin.defineContextKey)(
36
+ "devtools.player.config",
37
+ "Player version and the names of its registered plugins"
38
+ );
39
+
40
+ // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts
32
41
  var BasicDevtoolsPlugin = class extends import_plugin.DevtoolsPlugin {
33
42
  constructor(options) {
34
43
  super({
@@ -39,26 +48,44 @@ var BasicDevtoolsPlugin = class extends import_plugin.DevtoolsPlugin {
39
48
  this.data = {};
40
49
  this.playerConfig = {};
41
50
  this.logs = [];
51
+ /** Subscriptions are tied to the context plugin they were made on, which differs per Player */
52
+ this.subscriptions = [];
42
53
  }
43
54
  apply(player) {
44
55
  this.logger = new WeakRef(player.logger);
45
56
  if (!this.checkIfDevtoolsIsActive()) return;
46
57
  super.apply(player);
47
- this.playerConfig = {
58
+ const context = (0, import_context_plugin2.getContextPlugin)(player);
59
+ if (!player.getPlugins().some((p) => p.name === "state-context")) {
60
+ player.registerPlugin(new import_context_plugin2.StateContextPlugin());
61
+ }
62
+ this.subscriptions.forEach(
63
+ ({ context: previous, token }) => previous.unsubscribe(token)
64
+ );
65
+ this.subscriptions = [
66
+ {
67
+ context,
68
+ token: context.subscribe(playerConfigContextKey, (playerConfig) => {
69
+ if (!playerConfig) return;
70
+ this.playerConfig = { ...playerConfig };
71
+ this.dispatchDataUpdate({ playerConfig: this.playerConfig });
72
+ })
73
+ },
74
+ {
75
+ context,
76
+ token: context.subscribe(import_context_plugin2.dataContextKey, (model) => {
77
+ this.data = {
78
+ data: model === void 0 ? model : JSON.parse(JSON.stringify(model))
79
+ };
80
+ this.dispatchDataUpdate({ data: this.data });
81
+ })
82
+ }
83
+ ];
84
+ const publishConfig = () => context.set(playerConfigContextKey, {
48
85
  version: player.getVersion(),
49
86
  plugins: player.getPlugins().map((plugin) => plugin.name)
50
- };
51
- this.dispatchDataUpdate({ playerConfig: this.playerConfig });
52
- player.hooks.dataController.tap(this.name, (dataController) => {
53
- dataController.hooks.onUpdate.tap(this.name, (updates) => {
54
- this.data = (0, import_immer.produce)(this.data, (draft) => {
55
- updates.forEach(({ binding, newValue }) => {
56
- (0, import_utils.dsetAssign)(draft, ["data", ...binding.asArray()], newValue);
57
- });
58
- });
59
- this.dispatchDataUpdate({ data: this.data });
60
- });
61
87
  });
88
+ publishConfig();
62
89
  player.logger.hooks.log.tap(this.name, (severity, message) => {
63
90
  this.logs = [...this.logs, { severity, message }];
64
91
  this.dispatchDataUpdate({ logs: this.logs });
@@ -67,9 +94,7 @@ var BasicDevtoolsPlugin = class extends import_plugin.DevtoolsPlugin {
67
94
  this.flow = JSON.parse(JSON.stringify(f));
68
95
  this.dispatchDataUpdate({ flow: this.flow });
69
96
  });
70
- player.hooks.view.tap(this.name, (view) => {
71
- this.view = new WeakRef(view);
72
- });
97
+ player.hooks.onStart.tap(this.name, publishConfig);
73
98
  player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {
74
99
  this.expressionEvaluator = new WeakRef(evaluator);
75
100
  });
@@ -134,6 +159,7 @@ var BasicDevtoolsPlugin = class extends import_plugin.DevtoolsPlugin {
134
159
  };
135
160
  // Annotate the CommonJS export names for ESM import in node:
136
161
  0 && (module.exports = {
137
- BasicDevtoolsPlugin
162
+ BasicDevtoolsPlugin,
163
+ playerConfigContextKey
138
164
  });
139
165
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/index.ts","../../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts"],"sourcesContent":["export { BasicDevtoolsPlugin } from \"./plugin\";\n","import {\n INTERACTIONS,\n BasicPluginData,\n} from \"@player-devtools/basic-plugin-content\";\nimport {\n DevtoolsPlugin,\n DevtoolsPluginOptions,\n generateUUID,\n} from \"@player-devtools/plugin\";\nimport type { DevtoolsPluginInteractionEvent } from \"@player-devtools/types\";\nimport { dsetAssign } from \"@player-devtools/utils\";\nimport type {\n DataController,\n ExpressionEvaluator,\n Flow,\n Player,\n ViewInstance,\n Logger,\n} from \"@player-ui/player\";\nimport { produce } from \"immer\";\n\nimport { Evaluation } from \"./types\";\n\n/** Taps into the Player and ReactPlayer hooks and leverage the WrapperComponent to define and process the content. */\nexport class BasicDevtoolsPlugin extends DevtoolsPlugin {\n constructor(options: Omit<DevtoolsPluginOptions, \"pluginData\">) {\n super({\n ...options,\n pluginData: BasicPluginData,\n });\n }\n\n name = \"BasicDevtoolsPlugin\";\n\n data: Record<string, unknown> = {};\n\n playerConfig: Record<string, unknown> = {};\n\n logs: {\n severity: string;\n message: unknown;\n }[] = [];\n\n flow?: Flow;\n\n logger?: WeakRef<Logger>;\n\n expressionEvaluator?: WeakRef<ExpressionEvaluator>;\n\n view?: WeakRef<ViewInstance>;\n\n dataController?: WeakRef<DataController>;\n\n overrideFlow?: Player[\"start\"];\n\n apply(player: Player): void {\n this.logger = new WeakRef(player.logger);\n\n if (!this.checkIfDevtoolsIsActive()) return;\n\n super.apply(player);\n\n // Config\n this.playerConfig = {\n version: player.getVersion(),\n plugins: player.getPlugins().map((plugin) => plugin.name),\n };\n\n this.dispatchDataUpdate({ playerConfig: this.playerConfig });\n\n // Data\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.onUpdate.tap(this.name, (updates) => {\n this.data = produce(this.data, (draft) => {\n updates.forEach(({ binding, newValue }) => {\n dsetAssign(draft, [\"data\", ...binding.asArray()], newValue);\n });\n });\n\n this.dispatchDataUpdate({ data: this.data });\n });\n });\n\n player.logger.hooks.log.tap(this.name, (severity, message) => {\n this.logs = [...this.logs, { severity, message }];\n\n this.dispatchDataUpdate({ logs: this.logs });\n });\n\n // Flow\n player.hooks.onStart.tap(this.name, (f) => {\n this.flow = JSON.parse(JSON.stringify(f));\n\n this.dispatchDataUpdate({ flow: this.flow });\n });\n\n // View\n player.hooks.view.tap(this.name, (view) => {\n this.view = new WeakRef(view);\n });\n\n // Expression evaluator\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n this.expressionEvaluator = new WeakRef(evaluator);\n });\n\n // Override flow\n this.overrideFlow = player.start.bind(player);\n }\n\n private evaluateExpression(expression: string): Evaluation {\n const evaluator = this.expressionEvaluator?.deref();\n\n if (!evaluator) {\n return {\n id: generateUUID(),\n severity: \"error\",\n result: \"Expression evaluator not available\",\n expression,\n };\n }\n\n try {\n evaluator.hooks.onError.intercept({\n call: (error: Error) => {\n throw error;\n },\n });\n\n const evaluatorResult = evaluator.evaluate(expression);\n\n return {\n id: generateUUID(),\n result: evaluatorResult,\n expression,\n };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : String(error ?? \"Something went wrong\");\n return {\n id: generateUUID(),\n severity: \"error\",\n result: message,\n expression,\n };\n }\n }\n\n processInteraction(interaction: DevtoolsPluginInteractionEvent): void {\n // invokes mobile specific handlers\n super.processInteraction(interaction);\n\n const {\n payload: { type, payload },\n } = interaction;\n if (\n type === INTERACTIONS.EVALUATE_EXPRESSION &&\n this.expressionEvaluator &&\n payload\n ) {\n const result = this.evaluateExpression(payload);\n const current: Array<Evaluation> =\n (this.store.getState()?.plugins?.[this.pluginID]?.flow?.data\n ?.history as Array<Evaluation>) || [];\n\n this.dispatchDataUpdate({ history: [...current, result] });\n\n return;\n }\n\n if (type === INTERACTIONS.OVERRIDE_FLOW && payload && this.overrideFlow) {\n let newFlow: Flow | undefined;\n\n try {\n newFlow = JSON.parse(payload);\n } catch (e) {\n this.logger?.deref()?.error(this.name, \"Error parsing new flow\", e);\n }\n\n if (newFlow) {\n this.overrideFlow(newFlow);\n }\n\n return;\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kCAGO;AACP,oBAIO;AAEP,mBAA2B;AAS3B,mBAAwB;AAKjB,IAAM,sBAAN,cAAkC,6BAAe;AAAA,EACtD,YAAY,SAAoD;AAC9D,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,YAAY;AAAA,IACd,CAAC;AAGH,gBAAO;AAEP,gBAAgC,CAAC;AAEjC,wBAAwC,CAAC;AAEzC,gBAGM,CAAC;AAAA,EAXP;AAAA,EAyBA,MAAM,QAAsB;AAC1B,SAAK,SAAS,IAAI,QAAQ,OAAO,MAAM;AAEvC,QAAI,CAAC,KAAK,wBAAwB,EAAG;AAErC,UAAM,MAAM,MAAM;AAGlB,SAAK,eAAe;AAAA,MAClB,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS,OAAO,WAAW,EAAE,IAAI,CAAC,WAAW,OAAO,IAAI;AAAA,IAC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["../../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/index.ts","../../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts","../../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/context.ts"],"sourcesContent":["export { BasicDevtoolsPlugin } from \"./plugin\";\nexport { playerConfigContextKey, type PlayerConfig } from \"./context\";\n","import {\n INTERACTIONS,\n BasicPluginData,\n} from \"@player-devtools/basic-plugin-content\";\nimport {\n DevtoolsPlugin,\n DevtoolsPluginOptions,\n generateUUID,\n} from \"@player-devtools/plugin\";\nimport type { DevtoolsPluginInteractionEvent } from \"@player-devtools/types\";\nimport {\n StateContextPlugin,\n dataContextKey,\n getContextPlugin,\n type ContextPlugin,\n type SubscriptionToken,\n} from \"@player-ui/context-plugin\";\nimport type {\n ExpressionEvaluator,\n Flow,\n Player,\n Logger,\n} from \"@player-ui/player\";\n\nimport { playerConfigContextKey, type PlayerConfig } from \"./context\";\nimport { Evaluation } from \"./types\";\n\n/** Taps into the Player and ReactPlayer hooks and leverage the WrapperComponent to define and process the content. */\nexport class BasicDevtoolsPlugin extends DevtoolsPlugin {\n constructor(options: Omit<DevtoolsPluginOptions, \"pluginData\">) {\n super({\n ...options,\n pluginData: BasicPluginData,\n });\n }\n\n name = \"BasicDevtoolsPlugin\";\n\n data: Record<string, unknown> = {};\n\n playerConfig: Partial<PlayerConfig> = {};\n\n logs: {\n severity: string;\n message: unknown;\n }[] = [];\n\n flow?: Flow;\n\n logger?: WeakRef<Logger>;\n\n expressionEvaluator?: WeakRef<ExpressionEvaluator>;\n\n /** Subscriptions are tied to the context plugin they were made on, which differs per Player */\n private subscriptions: Array<{\n context: ContextPlugin;\n token: SubscriptionToken;\n }> = [];\n\n overrideFlow?: Player[\"start\"];\n\n apply(player: Player): void {\n this.logger = new WeakRef(player.logger);\n\n if (!this.checkIfDevtoolsIsActive()) return;\n\n super.apply(player);\n\n // State is read from the context plugin rather than tapping Player hooks directly\n const context = getContextPlugin(player);\n\n if (!player.getPlugins().some((p) => p.name === \"state-context\")) {\n player.registerPlugin(new StateContextPlugin());\n }\n\n // Subscriptions persist across flows on the context plugin, so drop any\n // left by an earlier apply of this plugin, on whichever Player it was.\n this.subscriptions.forEach(({ context: previous, token }) =>\n previous.unsubscribe(token),\n );\n\n this.subscriptions = [\n {\n context,\n token: context.subscribe(playerConfigContextKey, (playerConfig) => {\n // The context clears at flow end; keep the last known config until republished\n if (!playerConfig) return;\n\n this.playerConfig = { ...playerConfig };\n this.dispatchDataUpdate({ playerConfig: this.playerConfig });\n }),\n },\n {\n context,\n token: context.subscribe(dataContextKey, (model) => {\n // The model is Player's live data model, so clone it rather than let immer freeze it\n this.data = {\n data:\n model === undefined ? model : JSON.parse(JSON.stringify(model)),\n };\n this.dispatchDataUpdate({ data: this.data });\n }),\n },\n ];\n\n // The context store is reset when a flow ends, so republish on each start\n const publishConfig = () =>\n context.set(playerConfigContextKey, {\n version: player.getVersion(),\n plugins: player.getPlugins().map((plugin) => plugin.name),\n });\n\n publishConfig();\n\n player.logger.hooks.log.tap(this.name, (severity, message) => {\n this.logs = [...this.logs, { severity, message }];\n\n this.dispatchDataUpdate({ logs: this.logs });\n });\n\n // Flow\n player.hooks.onStart.tap(this.name, (f) => {\n this.flow = JSON.parse(JSON.stringify(f));\n\n this.dispatchDataUpdate({ flow: this.flow });\n });\n\n player.hooks.onStart.tap(this.name, publishConfig);\n\n // Expression evaluator\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n this.expressionEvaluator = new WeakRef(evaluator);\n });\n\n // Override flow\n this.overrideFlow = player.start.bind(player);\n }\n\n private evaluateExpression(expression: string): Evaluation {\n const evaluator = this.expressionEvaluator?.deref();\n\n if (!evaluator) {\n return {\n id: generateUUID(),\n severity: \"error\",\n result: \"Expression evaluator not available\",\n expression,\n };\n }\n\n try {\n evaluator.hooks.onError.intercept({\n call: (error: Error) => {\n throw error;\n },\n });\n\n const evaluatorResult = evaluator.evaluate(expression);\n\n return {\n id: generateUUID(),\n result: evaluatorResult,\n expression,\n };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : String(error ?? \"Something went wrong\");\n return {\n id: generateUUID(),\n severity: \"error\",\n result: message,\n expression,\n };\n }\n }\n\n processInteraction(interaction: DevtoolsPluginInteractionEvent): void {\n // invokes mobile specific handlers\n super.processInteraction(interaction);\n\n const {\n payload: { type, payload },\n } = interaction;\n if (\n type === INTERACTIONS.EVALUATE_EXPRESSION &&\n this.expressionEvaluator &&\n payload\n ) {\n const result = this.evaluateExpression(payload);\n const current: Array<Evaluation> =\n (this.store.getState()?.plugins?.[this.pluginID]?.flow?.data\n ?.history as Array<Evaluation>) || [];\n\n this.dispatchDataUpdate({ history: [...current, result] });\n\n return;\n }\n\n if (type === INTERACTIONS.OVERRIDE_FLOW && payload && this.overrideFlow) {\n let newFlow: Flow | undefined;\n\n try {\n newFlow = JSON.parse(payload);\n } catch (e) {\n this.logger?.deref()?.error(this.name, \"Error parsing new flow\", e);\n }\n\n if (newFlow) {\n this.overrideFlow(newFlow);\n }\n\n return;\n }\n }\n}\n","import { defineContextKey } from \"@player-ui/context-plugin\";\n\n/** Player version and the names of the plugins registered on it. */\nexport interface PlayerConfig {\n version: string;\n plugins: string[];\n}\n\n/** Published by the basic devtools plugin so other context consumers can read the Player config. */\nexport const playerConfigContextKey = defineContextKey<PlayerConfig>(\n \"devtools.player.config\",\n \"Player version and the names of its registered plugins\",\n);\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,kCAGO;AACP,oBAIO;AAEP,IAAAA,yBAMO;;;AChBP,4BAAiC;AAS1B,IAAM,6BAAyB;AAAA,EACpC;AAAA,EACA;AACF;;;ADgBO,IAAM,sBAAN,cAAkC,6BAAe;AAAA,EACtD,YAAY,SAAoD;AAC9D,UAAM;AAAA,MACJ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,EACF;AAAA,EAEA,mBAAmB,aAAmD;AAEpE,UAAM,mBAAmB,WAAW;AAEpC,UAAM;AAAA,MACJ,SAAS,EAAE,MAAM,QAAQ;AAAA,IAC3B,IAAI;AACJ,QACE,SAAS,yCAAa,uBACtB,KAAK,uBACL,SACA;AACA,YAAM,SAAS,KAAK,mBAAmB,OAAO;AAC9C,YAAM,UACH,KAAK,MAAM,SAAS,GAAG,UAAU,KAAK,QAAQ,GAAG,MAAM,MACpD,WAAiC,CAAC;AAExC,WAAK,mBAAmB,EAAE,SAAS,CAAC,GAAG,SAAS,MAAM,EAAE,CAAC;AAEzD;AAAA,IACF;AAEA,QAAI,SAAS,yCAAa,iBAAiB,WAAW,KAAK,cAAc;AACvE,UAAI;AAEJ,UAAI;AACF,kBAAU,KAAK,MAAM,OAAO;AAAA,MAC9B,SAAS,GAAG;AACV,aAAK,QAAQ,MAAM,GAAG,MAAM,KAAK,MAAM,0BAA0B,CAAC;AAAA,MACpE;AAEA,UAAI,SAAS;AACX,aAAK,aAAa,OAAO;AAAA,MAC3B;AAEA;AAAA,IACF;AAAA,EACF;AACF;","names":["import_context_plugin"]}
@@ -7,8 +7,20 @@ import {
7
7
  DevtoolsPlugin,
8
8
  generateUUID
9
9
  } from "@player-devtools/plugin";
10
- import { dsetAssign } from "@player-devtools/utils";
11
- import { produce } from "immer";
10
+ import {
11
+ StateContextPlugin,
12
+ dataContextKey,
13
+ getContextPlugin
14
+ } from "@player-ui/context-plugin";
15
+
16
+ // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/context.ts
17
+ import { defineContextKey } from "@player-ui/context-plugin";
18
+ var playerConfigContextKey = defineContextKey(
19
+ "devtools.player.config",
20
+ "Player version and the names of its registered plugins"
21
+ );
22
+
23
+ // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts
12
24
  var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
13
25
  constructor(options) {
14
26
  super({
@@ -19,26 +31,44 @@ var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
19
31
  this.data = {};
20
32
  this.playerConfig = {};
21
33
  this.logs = [];
34
+ /** Subscriptions are tied to the context plugin they were made on, which differs per Player */
35
+ this.subscriptions = [];
22
36
  }
23
37
  apply(player) {
24
38
  this.logger = new WeakRef(player.logger);
25
39
  if (!this.checkIfDevtoolsIsActive()) return;
26
40
  super.apply(player);
27
- this.playerConfig = {
41
+ const context = getContextPlugin(player);
42
+ if (!player.getPlugins().some((p) => p.name === "state-context")) {
43
+ player.registerPlugin(new StateContextPlugin());
44
+ }
45
+ this.subscriptions.forEach(
46
+ ({ context: previous, token }) => previous.unsubscribe(token)
47
+ );
48
+ this.subscriptions = [
49
+ {
50
+ context,
51
+ token: context.subscribe(playerConfigContextKey, (playerConfig) => {
52
+ if (!playerConfig) return;
53
+ this.playerConfig = { ...playerConfig };
54
+ this.dispatchDataUpdate({ playerConfig: this.playerConfig });
55
+ })
56
+ },
57
+ {
58
+ context,
59
+ token: context.subscribe(dataContextKey, (model) => {
60
+ this.data = {
61
+ data: model === void 0 ? model : JSON.parse(JSON.stringify(model))
62
+ };
63
+ this.dispatchDataUpdate({ data: this.data });
64
+ })
65
+ }
66
+ ];
67
+ const publishConfig = () => context.set(playerConfigContextKey, {
28
68
  version: player.getVersion(),
29
69
  plugins: player.getPlugins().map((plugin) => plugin.name)
30
- };
31
- this.dispatchDataUpdate({ playerConfig: this.playerConfig });
32
- player.hooks.dataController.tap(this.name, (dataController) => {
33
- dataController.hooks.onUpdate.tap(this.name, (updates) => {
34
- this.data = produce(this.data, (draft) => {
35
- updates.forEach(({ binding, newValue }) => {
36
- dsetAssign(draft, ["data", ...binding.asArray()], newValue);
37
- });
38
- });
39
- this.dispatchDataUpdate({ data: this.data });
40
- });
41
70
  });
71
+ publishConfig();
42
72
  player.logger.hooks.log.tap(this.name, (severity, message) => {
43
73
  this.logs = [...this.logs, { severity, message }];
44
74
  this.dispatchDataUpdate({ logs: this.logs });
@@ -47,9 +77,7 @@ var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
47
77
  this.flow = JSON.parse(JSON.stringify(f));
48
78
  this.dispatchDataUpdate({ flow: this.flow });
49
79
  });
50
- player.hooks.view.tap(this.name, (view) => {
51
- this.view = new WeakRef(view);
52
- });
80
+ player.hooks.onStart.tap(this.name, publishConfig);
53
81
  player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {
54
82
  this.expressionEvaluator = new WeakRef(evaluator);
55
83
  });
@@ -113,6 +141,7 @@ var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
113
141
  }
114
142
  };
115
143
  export {
116
- BasicDevtoolsPlugin
144
+ BasicDevtoolsPlugin,
145
+ playerConfigContextKey
117
146
  };
118
147
  //# sourceMappingURL=index.mjs.map
package/dist/index.mjs CHANGED
@@ -7,8 +7,20 @@ import {
7
7
  DevtoolsPlugin,
8
8
  generateUUID
9
9
  } from "@player-devtools/plugin";
10
- import { dsetAssign } from "@player-devtools/utils";
11
- import { produce } from "immer";
10
+ import {
11
+ StateContextPlugin,
12
+ dataContextKey,
13
+ getContextPlugin
14
+ } from "@player-ui/context-plugin";
15
+
16
+ // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/context.ts
17
+ import { defineContextKey } from "@player-ui/context-plugin";
18
+ var playerConfigContextKey = defineContextKey(
19
+ "devtools.player.config",
20
+ "Player version and the names of its registered plugins"
21
+ );
22
+
23
+ // ../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts
12
24
  var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
13
25
  constructor(options) {
14
26
  super({
@@ -19,26 +31,44 @@ var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
19
31
  this.data = {};
20
32
  this.playerConfig = {};
21
33
  this.logs = [];
34
+ /** Subscriptions are tied to the context plugin they were made on, which differs per Player */
35
+ this.subscriptions = [];
22
36
  }
23
37
  apply(player) {
24
38
  this.logger = new WeakRef(player.logger);
25
39
  if (!this.checkIfDevtoolsIsActive()) return;
26
40
  super.apply(player);
27
- this.playerConfig = {
41
+ const context = getContextPlugin(player);
42
+ if (!player.getPlugins().some((p) => p.name === "state-context")) {
43
+ player.registerPlugin(new StateContextPlugin());
44
+ }
45
+ this.subscriptions.forEach(
46
+ ({ context: previous, token }) => previous.unsubscribe(token)
47
+ );
48
+ this.subscriptions = [
49
+ {
50
+ context,
51
+ token: context.subscribe(playerConfigContextKey, (playerConfig) => {
52
+ if (!playerConfig) return;
53
+ this.playerConfig = { ...playerConfig };
54
+ this.dispatchDataUpdate({ playerConfig: this.playerConfig });
55
+ })
56
+ },
57
+ {
58
+ context,
59
+ token: context.subscribe(dataContextKey, (model) => {
60
+ this.data = {
61
+ data: model === void 0 ? model : JSON.parse(JSON.stringify(model))
62
+ };
63
+ this.dispatchDataUpdate({ data: this.data });
64
+ })
65
+ }
66
+ ];
67
+ const publishConfig = () => context.set(playerConfigContextKey, {
28
68
  version: player.getVersion(),
29
69
  plugins: player.getPlugins().map((plugin) => plugin.name)
30
- };
31
- this.dispatchDataUpdate({ playerConfig: this.playerConfig });
32
- player.hooks.dataController.tap(this.name, (dataController) => {
33
- dataController.hooks.onUpdate.tap(this.name, (updates) => {
34
- this.data = produce(this.data, (draft) => {
35
- updates.forEach(({ binding, newValue }) => {
36
- dsetAssign(draft, ["data", ...binding.asArray()], newValue);
37
- });
38
- });
39
- this.dispatchDataUpdate({ data: this.data });
40
- });
41
70
  });
71
+ publishConfig();
42
72
  player.logger.hooks.log.tap(this.name, (severity, message) => {
43
73
  this.logs = [...this.logs, { severity, message }];
44
74
  this.dispatchDataUpdate({ logs: this.logs });
@@ -47,9 +77,7 @@ var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
47
77
  this.flow = JSON.parse(JSON.stringify(f));
48
78
  this.dispatchDataUpdate({ flow: this.flow });
49
79
  });
50
- player.hooks.view.tap(this.name, (view) => {
51
- this.view = new WeakRef(view);
52
- });
80
+ player.hooks.onStart.tap(this.name, publishConfig);
53
81
  player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {
54
82
  this.expressionEvaluator = new WeakRef(evaluator);
55
83
  });
@@ -113,6 +141,7 @@ var BasicDevtoolsPlugin = class extends DevtoolsPlugin {
113
141
  }
114
142
  };
115
143
  export {
116
- BasicDevtoolsPlugin
144
+ BasicDevtoolsPlugin,
145
+ playerConfigContextKey
117
146
  };
118
147
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts"],"sourcesContent":["import {\n INTERACTIONS,\n BasicPluginData,\n} from \"@player-devtools/basic-plugin-content\";\nimport {\n DevtoolsPlugin,\n DevtoolsPluginOptions,\n generateUUID,\n} from \"@player-devtools/plugin\";\nimport type { DevtoolsPluginInteractionEvent } from \"@player-devtools/types\";\nimport { dsetAssign } from \"@player-devtools/utils\";\nimport type {\n DataController,\n ExpressionEvaluator,\n Flow,\n Player,\n ViewInstance,\n Logger,\n} from \"@player-ui/player\";\nimport { produce } from \"immer\";\n\nimport { Evaluation } from \"./types\";\n\n/** Taps into the Player and ReactPlayer hooks and leverage the WrapperComponent to define and process the content. */\nexport class BasicDevtoolsPlugin extends DevtoolsPlugin {\n constructor(options: Omit<DevtoolsPluginOptions, \"pluginData\">) {\n super({\n ...options,\n pluginData: BasicPluginData,\n });\n }\n\n name = \"BasicDevtoolsPlugin\";\n\n data: Record<string, unknown> = {};\n\n playerConfig: Record<string, unknown> = {};\n\n logs: {\n severity: string;\n message: unknown;\n }[] = [];\n\n flow?: Flow;\n\n logger?: WeakRef<Logger>;\n\n expressionEvaluator?: WeakRef<ExpressionEvaluator>;\n\n view?: WeakRef<ViewInstance>;\n\n dataController?: WeakRef<DataController>;\n\n overrideFlow?: Player[\"start\"];\n\n apply(player: Player): void {\n this.logger = new WeakRef(player.logger);\n\n if (!this.checkIfDevtoolsIsActive()) return;\n\n super.apply(player);\n\n // Config\n this.playerConfig = {\n version: player.getVersion(),\n plugins: player.getPlugins().map((plugin) => plugin.name),\n };\n\n this.dispatchDataUpdate({ playerConfig: this.playerConfig });\n\n // Data\n player.hooks.dataController.tap(this.name, (dataController) => {\n dataController.hooks.onUpdate.tap(this.name, (updates) => {\n this.data = produce(this.data, (draft) => {\n updates.forEach(({ binding, newValue }) => {\n dsetAssign(draft, [\"data\", ...binding.asArray()], newValue);\n });\n });\n\n this.dispatchDataUpdate({ data: this.data });\n });\n });\n\n player.logger.hooks.log.tap(this.name, (severity, message) => {\n this.logs = [...this.logs, { severity, message }];\n\n this.dispatchDataUpdate({ logs: this.logs });\n });\n\n // Flow\n player.hooks.onStart.tap(this.name, (f) => {\n this.flow = JSON.parse(JSON.stringify(f));\n\n this.dispatchDataUpdate({ flow: this.flow });\n });\n\n // View\n player.hooks.view.tap(this.name, (view) => {\n this.view = new WeakRef(view);\n });\n\n // Expression evaluator\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n this.expressionEvaluator = new WeakRef(evaluator);\n });\n\n // Override flow\n this.overrideFlow = player.start.bind(player);\n }\n\n private evaluateExpression(expression: string): Evaluation {\n const evaluator = this.expressionEvaluator?.deref();\n\n if (!evaluator) {\n return {\n id: generateUUID(),\n severity: \"error\",\n result: \"Expression evaluator not available\",\n expression,\n };\n }\n\n try {\n evaluator.hooks.onError.intercept({\n call: (error: Error) => {\n throw error;\n },\n });\n\n const evaluatorResult = evaluator.evaluate(expression);\n\n return {\n id: generateUUID(),\n result: evaluatorResult,\n expression,\n };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : String(error ?? \"Something went wrong\");\n return {\n id: generateUUID(),\n severity: \"error\",\n result: message,\n expression,\n };\n }\n }\n\n processInteraction(interaction: DevtoolsPluginInteractionEvent): void {\n // invokes mobile specific handlers\n super.processInteraction(interaction);\n\n const {\n payload: { type, payload },\n } = interaction;\n if (\n type === INTERACTIONS.EVALUATE_EXPRESSION &&\n this.expressionEvaluator &&\n payload\n ) {\n const result = this.evaluateExpression(payload);\n const current: Array<Evaluation> =\n (this.store.getState()?.plugins?.[this.pluginID]?.flow?.data\n ?.history as Array<Evaluation>) || [];\n\n this.dispatchDataUpdate({ history: [...current, result] });\n\n return;\n }\n\n if (type === INTERACTIONS.OVERRIDE_FLOW && payload && this.overrideFlow) {\n let newFlow: Flow | undefined;\n\n try {\n newFlow = JSON.parse(payload);\n } catch (e) {\n this.logger?.deref()?.error(this.name, \"Error parsing new flow\", e);\n }\n\n if (newFlow) {\n this.overrideFlow(newFlow);\n }\n\n return;\n }\n }\n}\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AAEP,SAAS,kBAAkB;AAS3B,SAAS,eAAe;AAKjB,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,YAAY,SAAoD;AAC9D,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,YAAY;AAAA,IACd,CAAC;AAGH,gBAAO;AAEP,gBAAgC,CAAC;AAEjC,wBAAwC,CAAC;AAEzC,gBAGM,CAAC;AAAA,EAXP;AAAA,EAyBA,MAAM,QAAsB;AAC1B,SAAK,SAAS,IAAI,QAAQ,OAAO,MAAM;AAEvC,QAAI,CAAC,KAAK,wBAAwB,EAAG;AAErC,UAAM,MAAM,MAAM;AAGlB,SAAK,eAAe;AAAA,MAClB,SAAS,OAAO,WAAW;AAAA,MAC3B,SAAS,OAAO,WAAW,EAAE,IAAI,CAAC,WAAW,OAAO,IAAI;AAAA,IAC1D;AAEA,SAAK,mBAAmB,EAAE,cAAc,KAAK,aAAa,CAAC;AAG3D,WAAO,MAAM,eAAe,IAAI,KAAK,MAAM,CAAC,mBAAmB;AAC7D,qBAAe,MAAM,SAAS,IAAI,KAAK,MAAM,CAAC,YAAY;AACxD,aAAK,OAAO,QAAQ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A,MACF,CAAC;AAED,YAAM,kBAAkB,UAAU,SAAS,UAAU;AAErD,aAAO;AAAA,QACL,IAAI,aAAa;AAAA,QACjB,QAAQ;AAAA,QACR;AAAA,MACF;AAAA,IACF,SAAS,OAAO;AACd,YAAM,UACJ,iBAAiB,QACb,MAAM,UACN,OAAO,SAAS,sBAAsB;AAC5C,aAAO;AAAA,QACL,IAAI,aAAa;AAAA,QACjB,UAAU;AAAA,QACV,QAAQ;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,mBAAmB,aAAmD;AAEpE,UAAM,mBAAmB,WAAW;AAEpC,UAAM;AAAA,MACJ,SAAS,EAAE,MAAM,QAAQ;AAAA,IAC3B,IAAI;AACJ,QACE,SAAS,aAAa,uBACtB,KAAK,uBACL,SACA;AACA,YAAM,SAAS,KAAK,mBAAmB,OAAO;AAC9C,YAAM,UACH,KAAK,MAAM,SAAS,GAAG,UAAU,KAAK,QAAQ,GAAG,MAAM,MACpD,WAAiC,CAAC;AAExC,WAAK,mBAAmB,EAAE,SAAS,CAAC,GAAG,SAAS,MAAM,EAAE,CAAC;AAEzD;AAAA,IACF;AAEA,QAAI,SAAS,aAAa,iBAAiB,WAAW,KAAK,cAAc;AACvE,UAAI;AAEJ,UAAI;AACF,kBAAU,KAAK,MAAM,OAAO;AAAA,MAC9B,SAAS,GAAG;AACV,aAAK,QAAQ,MAAM,GAAG,MAAM,KAAK,MAAM,0BAA0B,CAAC;AAAA,MACpE;AAEA,UAAI,SAAS;AACX,aAAK,aAAa,OAAO;AAAA,MAC3B;AAEA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/plugin.ts","../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/devtools/plugins/basic/core/src/context.ts"],"sourcesContent":["import {\n INTERACTIONS,\n BasicPluginData,\n} from \"@player-devtools/basic-plugin-content\";\nimport {\n DevtoolsPlugin,\n DevtoolsPluginOptions,\n generateUUID,\n} from \"@player-devtools/plugin\";\nimport type { DevtoolsPluginInteractionEvent } from \"@player-devtools/types\";\nimport {\n StateContextPlugin,\n dataContextKey,\n getContextPlugin,\n type ContextPlugin,\n type SubscriptionToken,\n} from \"@player-ui/context-plugin\";\nimport type {\n ExpressionEvaluator,\n Flow,\n Player,\n Logger,\n} from \"@player-ui/player\";\n\nimport { playerConfigContextKey, type PlayerConfig } from \"./context\";\nimport { Evaluation } from \"./types\";\n\n/** Taps into the Player and ReactPlayer hooks and leverage the WrapperComponent to define and process the content. */\nexport class BasicDevtoolsPlugin extends DevtoolsPlugin {\n constructor(options: Omit<DevtoolsPluginOptions, \"pluginData\">) {\n super({\n ...options,\n pluginData: BasicPluginData,\n });\n }\n\n name = \"BasicDevtoolsPlugin\";\n\n data: Record<string, unknown> = {};\n\n playerConfig: Partial<PlayerConfig> = {};\n\n logs: {\n severity: string;\n message: unknown;\n }[] = [];\n\n flow?: Flow;\n\n logger?: WeakRef<Logger>;\n\n expressionEvaluator?: WeakRef<ExpressionEvaluator>;\n\n /** Subscriptions are tied to the context plugin they were made on, which differs per Player */\n private subscriptions: Array<{\n context: ContextPlugin;\n token: SubscriptionToken;\n }> = [];\n\n overrideFlow?: Player[\"start\"];\n\n apply(player: Player): void {\n this.logger = new WeakRef(player.logger);\n\n if (!this.checkIfDevtoolsIsActive()) return;\n\n super.apply(player);\n\n // State is read from the context plugin rather than tapping Player hooks directly\n const context = getContextPlugin(player);\n\n if (!player.getPlugins().some((p) => p.name === \"state-context\")) {\n player.registerPlugin(new StateContextPlugin());\n }\n\n // Subscriptions persist across flows on the context plugin, so drop any\n // left by an earlier apply of this plugin, on whichever Player it was.\n this.subscriptions.forEach(({ context: previous, token }) =>\n previous.unsubscribe(token),\n );\n\n this.subscriptions = [\n {\n context,\n token: context.subscribe(playerConfigContextKey, (playerConfig) => {\n // The context clears at flow end; keep the last known config until republished\n if (!playerConfig) return;\n\n this.playerConfig = { ...playerConfig };\n this.dispatchDataUpdate({ playerConfig: this.playerConfig });\n }),\n },\n {\n context,\n token: context.subscribe(dataContextKey, (model) => {\n // The model is Player's live data model, so clone it rather than let immer freeze it\n this.data = {\n data:\n model === undefined ? model : JSON.parse(JSON.stringify(model)),\n };\n this.dispatchDataUpdate({ data: this.data });\n }),\n },\n ];\n\n // The context store is reset when a flow ends, so republish on each start\n const publishConfig = () =>\n context.set(playerConfigContextKey, {\n version: player.getVersion(),\n plugins: player.getPlugins().map((plugin) => plugin.name),\n });\n\n publishConfig();\n\n player.logger.hooks.log.tap(this.name, (severity, message) => {\n this.logs = [...this.logs, { severity, message }];\n\n this.dispatchDataUpdate({ logs: this.logs });\n });\n\n // Flow\n player.hooks.onStart.tap(this.name, (f) => {\n this.flow = JSON.parse(JSON.stringify(f));\n\n this.dispatchDataUpdate({ flow: this.flow });\n });\n\n player.hooks.onStart.tap(this.name, publishConfig);\n\n // Expression evaluator\n player.hooks.expressionEvaluator.tap(this.name, (evaluator) => {\n this.expressionEvaluator = new WeakRef(evaluator);\n });\n\n // Override flow\n this.overrideFlow = player.start.bind(player);\n }\n\n private evaluateExpression(expression: string): Evaluation {\n const evaluator = this.expressionEvaluator?.deref();\n\n if (!evaluator) {\n return {\n id: generateUUID(),\n severity: \"error\",\n result: \"Expression evaluator not available\",\n expression,\n };\n }\n\n try {\n evaluator.hooks.onError.intercept({\n call: (error: Error) => {\n throw error;\n },\n });\n\n const evaluatorResult = evaluator.evaluate(expression);\n\n return {\n id: generateUUID(),\n result: evaluatorResult,\n expression,\n };\n } catch (error) {\n const message =\n error instanceof Error\n ? error.message\n : String(error ?? \"Something went wrong\");\n return {\n id: generateUUID(),\n severity: \"error\",\n result: message,\n expression,\n };\n }\n }\n\n processInteraction(interaction: DevtoolsPluginInteractionEvent): void {\n // invokes mobile specific handlers\n super.processInteraction(interaction);\n\n const {\n payload: { type, payload },\n } = interaction;\n if (\n type === INTERACTIONS.EVALUATE_EXPRESSION &&\n this.expressionEvaluator &&\n payload\n ) {\n const result = this.evaluateExpression(payload);\n const current: Array<Evaluation> =\n (this.store.getState()?.plugins?.[this.pluginID]?.flow?.data\n ?.history as Array<Evaluation>) || [];\n\n this.dispatchDataUpdate({ history: [...current, result] });\n\n return;\n }\n\n if (type === INTERACTIONS.OVERRIDE_FLOW && payload && this.overrideFlow) {\n let newFlow: Flow | undefined;\n\n try {\n newFlow = JSON.parse(payload);\n } catch (e) {\n this.logger?.deref()?.error(this.name, \"Error parsing new flow\", e);\n }\n\n if (newFlow) {\n this.overrideFlow(newFlow);\n }\n\n return;\n }\n }\n}\n","import { defineContextKey } from \"@player-ui/context-plugin\";\n\n/** Player version and the names of the plugins registered on it. */\nexport interface PlayerConfig {\n version: string;\n plugins: string[];\n}\n\n/** Published by the basic devtools plugin so other context consumers can read the Player config. */\nexport const playerConfigContextKey = defineContextKey<PlayerConfig>(\n \"devtools.player.config\",\n \"Player version and the names of its registered plugins\",\n);\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EACA;AAAA,OACK;AACP;AAAA,EACE;AAAA,EAEA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;AChBP,SAAS,wBAAwB;AAS1B,IAAM,yBAAyB;AAAA,EACpC;AAAA,EACA;AACF;;;ADgBO,IAAM,sBAAN,cAAkC,eAAe;AAAA,EACtD,YAAY,SAAoD;AAC9D,UAAM;AAAA,MACJ,GAAG;AAAA,MACH,YAAY;AAAA,IACd,CAAC;AAGH,gBAAO;AAEP,gBAAgC,CAAC;AAEjC,wBAAsC,CAAC;AAEvC,gBAGM,CAAC;AASP;AAAA,SAAQ,gBAGH,CAAC;AAAA,EAvBN;AAAA,EA2BA,MAAM,QAAsB;AAC1B,SAAK,SAAS,IAAI,QAAQ,OAAO,MAAM;AAEvC,QAAI,CAAC,KAAK,wBAAwB,EAAG;AAErC,UAAM,MAAM,MAAM;AAGlB,UAAM,UAAU,iBA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AAmB,EAAE,SAAS,CAAC,GAAG,SAAS,MAAM,EAAE,CAAC;AAEzD;AAAA,IACF;AAEA,QAAI,SAAS,aAAa,iBAAiB,WAAW,KAAK,cAAc;AACvE,UAAI;AAEJ,UAAI;AACF,kBAAU,KAAK,MAAM,OAAO;AAAA,MAC9B,SAAS,GAAG;AACV,aAAK,QAAQ,MAAM,GAAG,MAAM,KAAK,MAAM,0BAA0B,CAAC;AAAA,MACpE;AAEA,UAAI,SAAS;AACX,aAAK,aAAa,OAAO;AAAA,MAC3B;AAEA;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -6,21 +6,18 @@
6
6
  "types"
7
7
  ],
8
8
  "name": "@player-devtools/basic-plugin",
9
- "version": "1.0.1-next.0",
9
+ "version": "1.1.0-next.0",
10
10
  "main": "dist/cjs/index.cjs",
11
11
  "dependencies": {
12
- "@player-devtools/basic-plugin-content": "1.0.1-next.0",
13
- "@player-devtools/messenger": "1.0.1-next.0",
14
- "@player-devtools/plugin": "1.0.1-next.0",
15
- "@player-devtools/types": "1.0.1-next.0",
16
- "@player-devtools/utils": "1.0.1-next.0",
12
+ "@player-devtools/basic-plugin-content": "1.1.0-next.0",
13
+ "@player-devtools/messenger": "1.1.0-next.0",
14
+ "@player-devtools/plugin": "1.1.0-next.0",
15
+ "@player-devtools/types": "1.1.0-next.0",
17
16
  "@devtools-ui/plugin": "0.4.1",
17
+ "@player-ui/context-plugin": "1.3.0",
18
18
  "@player-ui/player": "1.3.0",
19
19
  "@types/react": "^18.2.51",
20
20
  "@swc/core": "1.3.74",
21
- "dequal": "^2.0.2",
22
- "dset": "^3.1.3",
23
- "immer": "^10.0.3",
24
21
  "tslib": "^2.6.2"
25
22
  },
26
23
  "module": "dist/index.legacy-esm.js",
@@ -0,0 +1,219 @@
1
+ // Integration test: runs the plugin against a real Player and context plugin, so nothing is mocked.
2
+ import { describe, it, expect, beforeEach, vi } from "vitest";
3
+ import { Player } from "@player-ui/player";
4
+ import {
5
+ ContextPlugin,
6
+ dataContextKey,
7
+ flowIdContextKey,
8
+ flowStateContextKey,
9
+ getContextPlugin,
10
+ playerStateContextKey,
11
+ playerStatusContextKey,
12
+ viewIdContextKey,
13
+ } from "@player-ui/context-plugin";
14
+ import type { Flow } from "@player-ui/player";
15
+ import { BasicDevtoolsPlugin } from "../plugin";
16
+ import { playerConfigContextKey } from "../context";
17
+
18
+ const makeFlow = (): Flow => ({
19
+ id: "test-flow",
20
+ views: [{ id: "view-1", type: "info" }],
21
+ data: { name: "initial" },
22
+ navigation: {
23
+ BEGIN: "FLOW_1",
24
+ FLOW_1: {
25
+ startState: "VIEW_1",
26
+ VIEW_1: {
27
+ state_type: "VIEW",
28
+ ref: "view-1",
29
+ transitions: { "*": "END_Done" },
30
+ },
31
+ END_Done: { state_type: "END", outcome: "done" },
32
+ },
33
+ },
34
+ });
35
+
36
+ const getPluginData = (plugin: BasicDevtoolsPlugin) =>
37
+ plugin.store.getState().plugins[plugin.pluginID]?.flow?.data as
38
+ | Record<string, unknown>
39
+ | undefined;
40
+
41
+ describe("BasicDevtoolsPlugin", () => {
42
+ let plugin: BasicDevtoolsPlugin;
43
+ let player: Player;
44
+
45
+ beforeEach(() => {
46
+ plugin = new BasicDevtoolsPlugin({
47
+ playerID: "test-id",
48
+ handler: {
49
+ processInteraction: vi.fn(),
50
+ checkIfDevtoolsIsActive: () => true,
51
+ },
52
+ });
53
+ player = new Player({ plugins: [plugin] });
54
+ });
55
+
56
+ it("does not subscribe to the context plugin when devtools is inactive", () => {
57
+ const inactive = new BasicDevtoolsPlugin({
58
+ playerID: "inactive-id",
59
+ handler: {
60
+ processInteraction: vi.fn(),
61
+ checkIfDevtoolsIsActive: () => false,
62
+ },
63
+ });
64
+ const inactivePlayer = new Player({ plugins: [inactive] });
65
+
66
+ expect(
67
+ inactivePlayer.findPlugin<ContextPlugin>(ContextPlugin.Symbol),
68
+ ).toBeUndefined();
69
+ expect(getPluginData(inactive)).toBeUndefined();
70
+ });
71
+
72
+ it("publishes the player config to the context and the store before a flow starts", () => {
73
+ const context = getContextPlugin(player);
74
+ const config = context.get(playerConfigContextKey);
75
+
76
+ expect(config?.version).toBe(player.getVersion());
77
+ expect(config?.plugins).toContain("BasicDevtoolsPlugin");
78
+ expect(getPluginData(plugin)?.playerConfig).toEqual(config);
79
+ });
80
+
81
+ it("reuses a context plugin that is already registered", () => {
82
+ const existing = new ContextPlugin();
83
+ const sharedPlayer = new Player({
84
+ plugins: [
85
+ existing,
86
+ new BasicDevtoolsPlugin({
87
+ playerID: "shared-id",
88
+ handler: {
89
+ processInteraction: vi.fn(),
90
+ checkIfDevtoolsIsActive: () => true,
91
+ },
92
+ }),
93
+ ],
94
+ });
95
+
96
+ expect(existing.get(playerConfigContextKey)?.version).toBe(
97
+ sharedPlayer.getVersion(),
98
+ );
99
+ expect(
100
+ sharedPlayer.getPlugins().filter((p) => p.name === "context"),
101
+ ).toHaveLength(1);
102
+ });
103
+
104
+ it("exposes the state context keys and the devtools config key from the same context", () => {
105
+ player.start(makeFlow());
106
+ const context = getContextPlugin(player);
107
+
108
+ // Keys written by StateContextPlugin
109
+ expect(context.get(flowIdContextKey)).toBe("test-flow");
110
+ expect(context.get(flowStateContextKey)).toBe("VIEW_1");
111
+ expect(context.get(viewIdContextKey)).toBe("view-1");
112
+ expect(context.get(dataContextKey)).toEqual({ name: "initial" });
113
+ expect(context.get(playerStatusContextKey)).toBe("in-progress");
114
+
115
+ // Key written by the devtools plugin
116
+ expect(context.get(playerConfigContextKey)?.version).toBe(
117
+ player.getVersion(),
118
+ );
119
+
120
+ // The roll-up carries the state, including the actions, next to the config key
121
+ const state = context.get(playerStateContextKey);
122
+ expect(state?.flow?.id).toBe("test-flow");
123
+ expect(state?.view?.id).toBe("view-1");
124
+ expect(state?.data?.model).toEqual({ name: "initial" });
125
+ expect(typeof state?.data?.set).toBe("function");
126
+ expect(typeof state?.flow?.transition).toBe("function");
127
+ });
128
+
129
+ it("only registers one state context plugin", () => {
130
+ const names = player.getPlugins().map((p) => p.name);
131
+
132
+ expect(names.filter((name) => name === "state-context")).toHaveLength(1);
133
+ });
134
+
135
+ it("republishes the player config for the next flow after a flow ends", async () => {
136
+ const context = getContextPlugin(player);
137
+ const completed = player.start(makeFlow());
138
+ const state = player.getState();
139
+ if (state.status !== "in-progress") throw new Error("flow not started");
140
+ state.controllers.flow.transition("next");
141
+ await completed;
142
+ // Player fires onEnd in a `finally` after the flow result resolves
143
+ await new Promise((resolve) => setTimeout(resolve, 0));
144
+
145
+ // The context store is reset when the flow ends
146
+ expect(context.get(playerConfigContextKey)).toBeUndefined();
147
+
148
+ player.start(makeFlow());
149
+
150
+ expect(context.get(playerConfigContextKey)?.version).toBe(
151
+ player.getVersion(),
152
+ );
153
+ expect(getPluginData(plugin)?.playerConfig).toEqual(
154
+ context.get(playerConfigContextKey),
155
+ );
156
+ });
157
+
158
+ it("does not freeze the flow data owned by Player", () => {
159
+ const flow = makeFlow();
160
+ player.start(flow);
161
+ const state = player.getState();
162
+ if (state.status !== "in-progress") throw new Error("flow not started");
163
+ state.controllers.data.set([["name", "updated"]]);
164
+
165
+ expect(Object.isFrozen(flow.data)).toBe(false);
166
+ expect(Object.isFrozen(getPluginData(plugin)?.data)).toBe(true);
167
+ expect(() => state.controllers.data.set([["name", "again"]])).not.toThrow();
168
+ });
169
+
170
+ it("stops publishing from a Player's context once applied to another Player", () => {
171
+ const secondPlayer = new Player({ plugins: [plugin] });
172
+
173
+ secondPlayer.start({
174
+ ...makeFlow(),
175
+ data: { name: "second" },
176
+ });
177
+ expect(getPluginData(plugin)?.data).toEqual({ data: { name: "second" } });
178
+
179
+ // The first Player's context is no longer subscribed to by the plugin
180
+ player.start(makeFlow());
181
+
182
+ expect(getPluginData(plugin)?.data).toEqual({ data: { name: "second" } });
183
+ });
184
+
185
+ it("dispatches the data model from the context, including the initial data", () => {
186
+ player.start(makeFlow());
187
+
188
+ expect(getPluginData(plugin)?.data).toEqual({ data: { name: "initial" } });
189
+ });
190
+
191
+ it("dispatches data model updates", () => {
192
+ player.start(makeFlow());
193
+ const state = player.getState();
194
+ if (state.status !== "in-progress") throw new Error("flow not started");
195
+
196
+ state.controllers.data.set([["name", "updated"]]);
197
+
198
+ expect(getPluginData(plugin)?.data).toEqual({ data: { name: "updated" } });
199
+ expect(getContextPlugin(player).get(dataContextKey)).toEqual({
200
+ name: "updated",
201
+ });
202
+ });
203
+
204
+ it("dispatches a clone of the flow on start", () => {
205
+ const flow = makeFlow();
206
+ player.start(flow);
207
+
208
+ expect(getPluginData(plugin)?.flow).toEqual(flow);
209
+ expect(plugin.flow).not.toBe(flow);
210
+ });
211
+
212
+ it("dispatches logs", () => {
213
+ player.logger.warn("something happened");
214
+
215
+ expect(getPluginData(plugin)?.logs).toEqual([
216
+ { severity: "warn", message: ["something happened"] },
217
+ ]);
218
+ });
219
+ });
package/src/context.ts ADDED
@@ -0,0 +1,13 @@
1
+ import { defineContextKey } from "@player-ui/context-plugin";
2
+
3
+ /** Player version and the names of the plugins registered on it. */
4
+ export interface PlayerConfig {
5
+ version: string;
6
+ plugins: string[];
7
+ }
8
+
9
+ /** Published by the basic devtools plugin so other context consumers can read the Player config. */
10
+ export const playerConfigContextKey = defineContextKey<PlayerConfig>(
11
+ "devtools.player.config",
12
+ "Player version and the names of its registered plugins",
13
+ );
package/src/index.ts CHANGED
@@ -1 +1,2 @@
1
1
  export { BasicDevtoolsPlugin } from "./plugin";
2
+ export { playerConfigContextKey, type PlayerConfig } from "./context";