@player-ui/context-plugin 0.16.0--canary.891.38194

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,621 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ ContextPlugin: () => ContextPlugin,
24
+ ContextPluginSymbol: () => ContextPluginSymbol,
25
+ StateContextPlugin: () => StateContextPlugin,
26
+ dataContextKey: () => dataContextKey,
27
+ defineContextKey: () => defineContextKey,
28
+ flowIdContextKey: () => flowIdContextKey,
29
+ flowStateContextKey: () => flowStateContextKey,
30
+ getContextPlugin: () => getContextPlugin,
31
+ nameOfContextKey: () => nameOfContextKey,
32
+ playerStateContextKey: () => playerStateContextKey,
33
+ playerStatusContextKey: () => playerStatusContextKey,
34
+ resolveContextKeySymbol: () => resolveContextKeySymbol,
35
+ setDataActionKey: () => setDataActionKey,
36
+ transitionActionKey: () => transitionActionKey,
37
+ validationContextKey: () => validationContextKey,
38
+ viewContextKey: () => viewContextKey,
39
+ viewIdContextKey: () => viewIdContextKey
40
+ });
41
+ module.exports = __toCommonJS(src_exports);
42
+
43
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/plugin.ts
44
+ var import_tapable_ts = require("tapable-ts");
45
+
46
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/key.ts
47
+ var KEY_NAMESPACE = "player-ui.context.";
48
+ var defineContextKey = (name, description) => ({
49
+ symbol: Symbol.for(`${KEY_NAMESPACE}${name}`),
50
+ description
51
+ });
52
+ var resolveContextKeySymbol = (name) => Symbol.for(`${KEY_NAMESPACE}${name}`);
53
+ var nameOfContextKey = (key) => {
54
+ const k = Symbol.keyFor(key.symbol);
55
+ if (!k || !k.startsWith(KEY_NAMESPACE))
56
+ return void 0;
57
+ return k.slice(KEY_NAMESPACE.length);
58
+ };
59
+
60
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/store.ts
61
+ var deepFreezeEntry = (entry) => {
62
+ Object.freeze(entry);
63
+ return entry;
64
+ };
65
+ var tombstone = (description) => () => {
66
+ throw new Error(
67
+ `[ContextPlugin] Action "${description}" is no longer valid \u2014 its flow has ended`
68
+ );
69
+ };
70
+ var tombstoneFunctions = (value, description) => {
71
+ if (typeof value === "function") {
72
+ return tombstone(description);
73
+ }
74
+ if (Array.isArray(value)) {
75
+ return value.map((item) => tombstoneFunctions(item, description));
76
+ }
77
+ if (value !== null && typeof value === "object") {
78
+ const out = {};
79
+ for (const [k, v] of Object.entries(value)) {
80
+ out[k] = tombstoneFunctions(v, description);
81
+ }
82
+ return out;
83
+ }
84
+ return value;
85
+ };
86
+ var ContextStore = class {
87
+ constructor() {
88
+ this.entries = /* @__PURE__ */ new Map();
89
+ /** source symbol -> set of target symbols (reverse index for invalidation). */
90
+ this.dependents = /* @__PURE__ */ new Map();
91
+ }
92
+ register(key) {
93
+ if (this.entries.has(key.symbol)) {
94
+ return false;
95
+ }
96
+ this.entries.set(key.symbol, { key, hasLiteral: false });
97
+ return true;
98
+ }
99
+ set(key, value) {
100
+ const existing = this.entries.get(key.symbol);
101
+ if (existing) {
102
+ existing.hasLiteral = true;
103
+ existing.literal = value;
104
+ existing.key = key;
105
+ } else {
106
+ this.entries.set(key.symbol, {
107
+ key,
108
+ hasLiteral: true,
109
+ literal: value
110
+ });
111
+ }
112
+ }
113
+ registerTransform(key, transform) {
114
+ const existing = this.entries.get(key.symbol);
115
+ const previousSources = existing?.transform?.sources;
116
+ if (previousSources) {
117
+ for (const src of previousSources) {
118
+ this.dependents.get(src.symbol)?.delete(key.symbol);
119
+ }
120
+ }
121
+ const stored = {
122
+ sources: transform.sources,
123
+ compute: transform.compute
124
+ };
125
+ if (existing) {
126
+ existing.transform = stored;
127
+ existing.key = key;
128
+ } else {
129
+ this.entries.set(key.symbol, {
130
+ key,
131
+ hasLiteral: false,
132
+ transform: stored
133
+ });
134
+ }
135
+ for (const src of transform.sources) {
136
+ let set = this.dependents.get(src.symbol);
137
+ if (!set) {
138
+ set = /* @__PURE__ */ new Set();
139
+ this.dependents.set(src.symbol, set);
140
+ }
141
+ set.add(key.symbol);
142
+ }
143
+ return { previousSources };
144
+ }
145
+ get(key) {
146
+ return this.compute(key.symbol);
147
+ }
148
+ has(key) {
149
+ const entry = this.entries.get(key.symbol);
150
+ return Boolean(entry && (entry.hasLiteral || entry.transform));
151
+ }
152
+ /** Return the keys that depend on the given source key (direct dependents only). */
153
+ dependentsOf(sourceSymbol) {
154
+ const set = this.dependents.get(sourceSymbol);
155
+ if (!set || set.size === 0) {
156
+ return [];
157
+ }
158
+ const out = [];
159
+ for (const targetSymbol of set) {
160
+ const target = this.entries.get(targetSymbol);
161
+ if (target) {
162
+ out.push(target.key);
163
+ }
164
+ }
165
+ return out;
166
+ }
167
+ list() {
168
+ const out = [];
169
+ for (const entry of this.entries.values()) {
170
+ out.push({
171
+ symbol: entry.key.symbol,
172
+ description: entry.key.description,
173
+ hasValue: entry.hasLiteral,
174
+ hasTransform: Boolean(entry.transform)
175
+ });
176
+ }
177
+ return out;
178
+ }
179
+ freeze(meta) {
180
+ const frozenEntries = [];
181
+ for (const entry of this.entries.values()) {
182
+ if (!entry.hasLiteral && !entry.transform) {
183
+ continue;
184
+ }
185
+ const computed = this.compute(entry.key.symbol);
186
+ const value = tombstoneFunctions(computed, entry.key.description);
187
+ frozenEntries.push(
188
+ deepFreezeEntry({
189
+ symbol: entry.key.symbol,
190
+ name: nameOfContextKey(entry.key),
191
+ description: entry.key.description,
192
+ value
193
+ })
194
+ );
195
+ }
196
+ const bySymbol = new Map(frozenEntries.map((e) => [e.symbol, e.value]));
197
+ const snapshot = {
198
+ flowId: meta.flowId,
199
+ endedAt: meta.endedAt,
200
+ entries: Object.freeze(frozenEntries),
201
+ get(key) {
202
+ return bySymbol.get(key.symbol);
203
+ }
204
+ };
205
+ return Object.freeze(snapshot);
206
+ }
207
+ compute(sym) {
208
+ const entry = this.entries.get(sym);
209
+ if (!entry)
210
+ return void 0;
211
+ if (entry.hasLiteral)
212
+ return entry.literal;
213
+ if (!entry.transform)
214
+ return void 0;
215
+ const reader = (otherKey) => this.compute(otherKey.symbol);
216
+ return entry.transform.compute(reader);
217
+ }
218
+ };
219
+
220
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/history.ts
221
+ var ContextHistory = class {
222
+ constructor() {
223
+ this.stack = [];
224
+ }
225
+ push(snapshot) {
226
+ this.stack.push(snapshot);
227
+ }
228
+ entries() {
229
+ return this.stack;
230
+ }
231
+ size() {
232
+ return this.stack.length;
233
+ }
234
+ clear() {
235
+ this.stack = [];
236
+ }
237
+ };
238
+
239
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/symbols.ts
240
+ var ContextPluginSymbol = Symbol.for("ContextPlugin");
241
+
242
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/plugin.ts
243
+ var subscriptionCounter = 0;
244
+ var _ContextPlugin = class _ContextPlugin {
245
+ constructor() {
246
+ this.name = "context";
247
+ this.symbol = _ContextPlugin.Symbol;
248
+ this.hooks = {
249
+ onSet: new import_tapable_ts.SyncHook(),
250
+ resolveValue: new import_tapable_ts.SyncWaterfallHook(),
251
+ onRegister: new import_tapable_ts.SyncHook(),
252
+ onFlowFrozen: new import_tapable_ts.SyncHook()
253
+ };
254
+ this.transforms = /* @__PURE__ */ new Map();
255
+ this.perKeySubs = /* @__PURE__ */ new Map();
256
+ this.globalSubs = /* @__PURE__ */ new Map();
257
+ this.tokenIndex = /* @__PURE__ */ new Map();
258
+ this.store = new ContextStore();
259
+ this.historyStack = new ContextHistory();
260
+ }
261
+ apply(player) {
262
+ const existing = player.findPlugin(ContextPluginSymbol);
263
+ if (existing !== void 0 && existing !== this) {
264
+ this.store = existing.store;
265
+ this.historyStack = existing.historyStack;
266
+ this.transforms = existing.transforms;
267
+ this.perKeySubs = existing.perKeySubs;
268
+ this.globalSubs = existing.globalSubs;
269
+ this.tokenIndex = existing.tokenIndex;
270
+ return;
271
+ }
272
+ player.hooks.onStart.tap(this.name, (flow) => {
273
+ this.currentFlowId = flow?.id;
274
+ });
275
+ player.hooks.onEnd.tap(this.name, () => {
276
+ const snapshot = this.store.freeze({
277
+ flowId: this.currentFlowId,
278
+ endedAt: Date.now()
279
+ });
280
+ this.historyStack.push(snapshot);
281
+ this.hooks.onFlowFrozen.call(snapshot);
282
+ this.rotateStore();
283
+ this.currentFlowId = void 0;
284
+ });
285
+ }
286
+ register(key) {
287
+ const added = this.store.register(key);
288
+ if (added) {
289
+ this.hooks.onRegister.call(key);
290
+ }
291
+ }
292
+ set(key, value) {
293
+ const isFirstSighting = !this.store.has(key);
294
+ this.store.set(key, value);
295
+ if (isFirstSighting) {
296
+ this.hooks.onRegister.call(key);
297
+ }
298
+ this.notify(key, value);
299
+ const dependents = this.store.dependentsOf(key.symbol);
300
+ for (const dep of dependents) {
301
+ const computed = this.store.get(dep);
302
+ this.notify(dep, computed);
303
+ }
304
+ }
305
+ get(key) {
306
+ const raw = this.store.get(key);
307
+ const resolved = this.hooks.resolveValue.call(raw, key);
308
+ return resolved;
309
+ }
310
+ has(key) {
311
+ return this.store.has(key);
312
+ }
313
+ registerTransform(key, transform) {
314
+ const isFirstSighting = !this.store.has(key);
315
+ this.store.registerTransform(key, transform);
316
+ this.transforms.set(key.symbol, {
317
+ key,
318
+ transform: {
319
+ sources: transform.sources,
320
+ compute: transform.compute
321
+ }
322
+ });
323
+ if (isFirstSighting) {
324
+ this.hooks.onRegister.call(key);
325
+ }
326
+ }
327
+ subscribe(key, handler) {
328
+ const token = this.nextToken();
329
+ let bucket = this.perKeySubs.get(key.symbol);
330
+ if (!bucket) {
331
+ bucket = /* @__PURE__ */ new Map();
332
+ this.perKeySubs.set(key.symbol, bucket);
333
+ }
334
+ bucket.set(token, handler);
335
+ this.tokenIndex.set(token, key.symbol);
336
+ return token;
337
+ }
338
+ subscribeAll(handler) {
339
+ const token = this.nextToken();
340
+ this.globalSubs.set(token, handler);
341
+ this.tokenIndex.set(token, void 0);
342
+ return token;
343
+ }
344
+ unsubscribe(token) {
345
+ const owner = this.tokenIndex.get(token);
346
+ if (owner === void 0) {
347
+ this.globalSubs.delete(token);
348
+ } else {
349
+ this.perKeySubs.get(owner)?.delete(token);
350
+ }
351
+ this.tokenIndex.delete(token);
352
+ }
353
+ list() {
354
+ return this.store.list();
355
+ }
356
+ history() {
357
+ return this.historyStack.entries();
358
+ }
359
+ snapshot() {
360
+ return this.store.freeze({
361
+ flowId: this.currentFlowId,
362
+ endedAt: Date.now()
363
+ });
364
+ }
365
+ /**
366
+ * Bridge-friendly: set a value by string name. Used by native wrappers that
367
+ * cannot construct a `ContextKey` object directly.
368
+ */
369
+ setByName(name, description, value) {
370
+ this.set(this.ensureNamedKey(name, description), value);
371
+ }
372
+ /** Bridge-friendly: get a value by string name. */
373
+ getByName(name) {
374
+ return this.get(this.ensureNamedKey(name));
375
+ }
376
+ /** Bridge-friendly: check presence by string name. */
377
+ hasByName(name) {
378
+ return this.has(this.ensureNamedKey(name));
379
+ }
380
+ /** Bridge-friendly: subscribe by string name. */
381
+ subscribeByName(name, description, handler) {
382
+ return this.subscribe(
383
+ this.ensureNamedKey(name, description),
384
+ (value) => handler(value, name)
385
+ );
386
+ }
387
+ /**
388
+ * Bridge-friendly: subscribe to all updates. The handler receives the
389
+ * key's resolved name (or undefined for non-namespaced keys).
390
+ */
391
+ subscribeAllByName(handler) {
392
+ return this.subscribeAll(
393
+ (value, key) => handler(value, nameOfContextKey(key), key.description)
394
+ );
395
+ }
396
+ ensureNamedKey(name, description) {
397
+ return defineContextKey(name, description ?? name);
398
+ }
399
+ notify(key, value) {
400
+ this.hooks.onSet.call(key, value);
401
+ const bucket = this.perKeySubs.get(key.symbol);
402
+ if (bucket) {
403
+ for (const handler of bucket.values()) {
404
+ handler(value, key);
405
+ }
406
+ }
407
+ for (const handler of this.globalSubs.values()) {
408
+ handler(value, key);
409
+ }
410
+ }
411
+ rotateStore() {
412
+ this.store = new ContextStore();
413
+ for (const { key, transform } of this.transforms.values()) {
414
+ this.store.registerTransform(key, transform);
415
+ }
416
+ }
417
+ nextToken() {
418
+ subscriptionCounter += 1;
419
+ return `ctx_${subscriptionCounter}`;
420
+ }
421
+ };
422
+ _ContextPlugin.Symbol = ContextPluginSymbol;
423
+ var ContextPlugin = _ContextPlugin;
424
+
425
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/utils.ts
426
+ function getContextPlugin(player) {
427
+ const existing = player.findPlugin(ContextPluginSymbol);
428
+ const plugin = existing ?? new ContextPlugin();
429
+ if (!existing) {
430
+ player.registerPlugin(plugin);
431
+ }
432
+ return plugin;
433
+ }
434
+
435
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/context/core/src/state-plugin.ts
436
+ var flowIdContextKey = defineContextKey(
437
+ "player.flow.id",
438
+ "Identifier of the running flow"
439
+ );
440
+ var flowStateContextKey = defineContextKey(
441
+ "player.flow.state",
442
+ "Name of the current FSM state in the running flow"
443
+ );
444
+ var viewIdContextKey = defineContextKey(
445
+ "player.view.id",
446
+ "Identifier of the currently-resolved view"
447
+ );
448
+ var viewContextKey = defineContextKey(
449
+ "player.view",
450
+ "Full resolved view object for the current FSM state"
451
+ );
452
+ var dataContextKey = defineContextKey(
453
+ "player.data",
454
+ "Full data model tree for the running flow"
455
+ );
456
+ var playerStatusContextKey = defineContextKey(
457
+ "player.status",
458
+ "Player flow status: not-started, in-progress, completed, or error"
459
+ );
460
+ var validationContextKey = defineContextKey(
461
+ "player.validation",
462
+ "Validation state for the running view, keyed by binding"
463
+ );
464
+ var setDataActionKey = defineContextKey(
465
+ "player.data.set",
466
+ "Set a value in the Player data model at the given binding"
467
+ );
468
+ var transitionActionKey = defineContextKey(
469
+ "player.flow.transition",
470
+ "Transition the current flow using the given transition value"
471
+ );
472
+ var playerStateContextKey = defineContextKey(
473
+ "player.state",
474
+ "Aggregated snapshot of every Player runtime context entry"
475
+ );
476
+ var StateContextPlugin = class {
477
+ constructor() {
478
+ this.name = "state-context";
479
+ }
480
+ apply(player) {
481
+ const ctx = getContextPlugin(player);
482
+ let validationController;
483
+ const publishValidation = () => {
484
+ if (!validationController)
485
+ return;
486
+ const byBinding = {};
487
+ let canTransition = true;
488
+ validationController.getBindings().forEach((binding) => {
489
+ const all = validationController.getValidationForBinding(binding)?.getAll() ?? [];
490
+ if (all.length === 0)
491
+ return;
492
+ byBinding[binding.asString()] = all.map((v) => ({
493
+ severity: v.severity,
494
+ message: v.message,
495
+ displayTarget: v.displayTarget,
496
+ blocking: v.blocking
497
+ }));
498
+ if (all.some((v) => v.blocking)) {
499
+ canTransition = false;
500
+ }
501
+ });
502
+ ctx.set(validationContextKey, { canTransition, byBinding });
503
+ };
504
+ ctx.register(flowIdContextKey);
505
+ ctx.register(flowStateContextKey);
506
+ ctx.register(viewIdContextKey);
507
+ ctx.register(viewContextKey);
508
+ ctx.register(dataContextKey);
509
+ ctx.register(playerStatusContextKey);
510
+ ctx.register(validationContextKey);
511
+ ctx.register(setDataActionKey);
512
+ ctx.register(transitionActionKey);
513
+ ctx.registerTransform(playerStateContextKey, {
514
+ sources: [
515
+ flowIdContextKey,
516
+ flowStateContextKey,
517
+ viewIdContextKey,
518
+ viewContextKey,
519
+ dataContextKey,
520
+ playerStatusContextKey,
521
+ validationContextKey,
522
+ setDataActionKey,
523
+ transitionActionKey
524
+ ],
525
+ compute: (read) => ({
526
+ status: read(playerStatusContextKey),
527
+ flow: {
528
+ id: read(flowIdContextKey),
529
+ state: read(flowStateContextKey),
530
+ transition: read(transitionActionKey)
531
+ },
532
+ view: {
533
+ id: read(viewIdContextKey),
534
+ resolved: read(viewContextKey)
535
+ },
536
+ data: {
537
+ model: read(dataContextKey),
538
+ set: read(setDataActionKey)
539
+ },
540
+ validation: read(validationContextKey) ?? {
541
+ canTransition: true,
542
+ byBinding: {}
543
+ }
544
+ })
545
+ });
546
+ player.hooks.onStart.tap(this.name, (flow) => {
547
+ if (flow?.id) {
548
+ ctx.set(flowIdContextKey, flow.id);
549
+ }
550
+ });
551
+ player.hooks.state.tap(this.name, (state) => {
552
+ ctx.set(playerStatusContextKey, state.status);
553
+ });
554
+ player.hooks.flowController.tap(this.name, (flowController) => {
555
+ const transition = (value) => flowController.transition(value);
556
+ ctx.set(transitionActionKey, transition);
557
+ flowController.hooks.flow.tap(this.name, (flowInstance) => {
558
+ const recordState = () => {
559
+ const name = flowInstance.currentState?.name;
560
+ if (name) {
561
+ ctx.set(flowStateContextKey, name);
562
+ }
563
+ };
564
+ recordState();
565
+ flowInstance.hooks.afterTransition.tap(this.name, recordState);
566
+ });
567
+ });
568
+ player.hooks.validationController.tap(this.name, (vc) => {
569
+ validationController = vc;
570
+ publishValidation();
571
+ });
572
+ player.hooks.viewController.tap(this.name, (viewController) => {
573
+ viewController.hooks.view.tap(this.name, (view) => {
574
+ const id = view.initialView?.id;
575
+ if (id) {
576
+ ctx.set(viewIdContextKey, id);
577
+ }
578
+ view.hooks.onUpdate.tap(this.name, (resolved) => {
579
+ ctx.set(viewContextKey, resolved);
580
+ if (resolved?.id) {
581
+ ctx.set(viewIdContextKey, resolved.id);
582
+ }
583
+ publishValidation();
584
+ });
585
+ });
586
+ });
587
+ player.hooks.dataController.tap(this.name, (dataController) => {
588
+ const setData = (binding, value) => {
589
+ dataController.set([[binding, value]]);
590
+ };
591
+ ctx.set(setDataActionKey, setData);
592
+ const publish = () => {
593
+ ctx.set(dataContextKey, dataController.serialize());
594
+ publishValidation();
595
+ };
596
+ dataController.hooks.onUpdate.tap(this.name, publish);
597
+ publish();
598
+ });
599
+ }
600
+ };
601
+ // Annotate the CommonJS export names for ESM import in node:
602
+ 0 && (module.exports = {
603
+ ContextPlugin,
604
+ ContextPluginSymbol,
605
+ StateContextPlugin,
606
+ dataContextKey,
607
+ defineContextKey,
608
+ flowIdContextKey,
609
+ flowStateContextKey,
610
+ getContextPlugin,
611
+ nameOfContextKey,
612
+ playerStateContextKey,
613
+ playerStatusContextKey,
614
+ resolveContextKeySymbol,
615
+ setDataActionKey,
616
+ transitionActionKey,
617
+ validationContextKey,
618
+ viewContextKey,
619
+ viewIdContextKey
620
+ });
621
+ //# sourceMappingURL=index.cjs.map