@player-ui/player 1.1.0-next.1 → 1.1.0-next.3
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.
- package/dist/Player.native.js +71 -49
- package/dist/Player.native.js.map +1 -1
- package/dist/cjs/index.cjs +67 -45
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/index.legacy-esm.js +68 -46
- package/dist/index.mjs +68 -46
- package/dist/index.mjs.map +1 -1
- package/package.json +4 -4
- package/src/__tests__/player.test.ts +173 -0
- package/src/__tests__/transform-content.test.ts +131 -0
- package/src/controllers/data/utils.ts +1 -1
- package/src/controllers/validation/controller.ts +53 -47
- package/src/player.ts +28 -5
- package/src/types.ts +41 -1
- package/src/validator/validation-middleware.ts +5 -0
- package/types/controllers/validation/controller.d.ts +1 -0
- package/types/player.d.ts +2 -3
- package/types/types.d.ts +39 -1
- package/types/validator/validation-middleware.d.ts +2 -0
package/dist/index.legacy-esm.js
CHANGED
|
@@ -2628,6 +2628,10 @@ var ValidationMiddleware = class {
|
|
|
2628
2628
|
);
|
|
2629
2629
|
return next?.delete(binding, options);
|
|
2630
2630
|
}
|
|
2631
|
+
/** Clears any invalid values staged in the shadow model */
|
|
2632
|
+
reset() {
|
|
2633
|
+
this.shadowModelPaths.clear();
|
|
2634
|
+
}
|
|
2631
2635
|
};
|
|
2632
2636
|
|
|
2633
2637
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/validator/registry.ts
|
|
@@ -3467,6 +3471,44 @@ var ValidationController = class {
|
|
|
3467
3471
|
}
|
|
3468
3472
|
/** Return the middleware for the data-model to stop propagation of invalid data */
|
|
3469
3473
|
getDataMiddleware() {
|
|
3474
|
+
const validationMiddleware = new ValidationMiddleware(
|
|
3475
|
+
(binding) => {
|
|
3476
|
+
if (!this.options) {
|
|
3477
|
+
return;
|
|
3478
|
+
}
|
|
3479
|
+
this.updateValidationsForBinding(binding, "change", this.options);
|
|
3480
|
+
const strongValidation = this.getValidationForBinding(binding);
|
|
3481
|
+
if (strongValidation?.get()?.severity === "error") {
|
|
3482
|
+
return strongValidation.get();
|
|
3483
|
+
}
|
|
3484
|
+
const newInvalidBindings = /* @__PURE__ */ new Set();
|
|
3485
|
+
this.validations.forEach((weakValidation, strongBinding) => {
|
|
3486
|
+
if (caresAboutDataChanges(
|
|
3487
|
+
/* @__PURE__ */ new Set([binding]),
|
|
3488
|
+
weakValidation.weakBindings
|
|
3489
|
+
) && weakValidation?.get()?.severity === "error") {
|
|
3490
|
+
weakValidation?.weakBindings.forEach((weakBinding) => {
|
|
3491
|
+
if (weakBinding === strongBinding) {
|
|
3492
|
+
newInvalidBindings.add({
|
|
3493
|
+
binding: weakBinding,
|
|
3494
|
+
isStrong: true
|
|
3495
|
+
});
|
|
3496
|
+
} else {
|
|
3497
|
+
newInvalidBindings.add({
|
|
3498
|
+
binding: weakBinding,
|
|
3499
|
+
isStrong: false
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
});
|
|
3505
|
+
if (newInvalidBindings.size > 0) {
|
|
3506
|
+
return newInvalidBindings;
|
|
3507
|
+
}
|
|
3508
|
+
},
|
|
3509
|
+
{ logger: new ProxyLogger(() => this.options?.logger) }
|
|
3510
|
+
);
|
|
3511
|
+
this.validationMiddleware = validationMiddleware;
|
|
3470
3512
|
return [
|
|
3471
3513
|
{
|
|
3472
3514
|
set: (transaction, options, next) => {
|
|
@@ -3483,43 +3525,7 @@ var ValidationController = class {
|
|
|
3483
3525
|
return next?.delete(binding, options);
|
|
3484
3526
|
}
|
|
3485
3527
|
},
|
|
3486
|
-
|
|
3487
|
-
(binding) => {
|
|
3488
|
-
if (!this.options) {
|
|
3489
|
-
return;
|
|
3490
|
-
}
|
|
3491
|
-
this.updateValidationsForBinding(binding, "change", this.options);
|
|
3492
|
-
const strongValidation = this.getValidationForBinding(binding);
|
|
3493
|
-
if (strongValidation?.get()?.severity === "error") {
|
|
3494
|
-
return strongValidation.get();
|
|
3495
|
-
}
|
|
3496
|
-
const newInvalidBindings = /* @__PURE__ */ new Set();
|
|
3497
|
-
this.validations.forEach((weakValidation, strongBinding) => {
|
|
3498
|
-
if (caresAboutDataChanges(
|
|
3499
|
-
/* @__PURE__ */ new Set([binding]),
|
|
3500
|
-
weakValidation.weakBindings
|
|
3501
|
-
) && weakValidation?.get()?.severity === "error") {
|
|
3502
|
-
weakValidation?.weakBindings.forEach((weakBinding) => {
|
|
3503
|
-
if (weakBinding === strongBinding) {
|
|
3504
|
-
newInvalidBindings.add({
|
|
3505
|
-
binding: weakBinding,
|
|
3506
|
-
isStrong: true
|
|
3507
|
-
});
|
|
3508
|
-
} else {
|
|
3509
|
-
newInvalidBindings.add({
|
|
3510
|
-
binding: weakBinding,
|
|
3511
|
-
isStrong: false
|
|
3512
|
-
});
|
|
3513
|
-
}
|
|
3514
|
-
});
|
|
3515
|
-
}
|
|
3516
|
-
});
|
|
3517
|
-
if (newInvalidBindings.size > 0) {
|
|
3518
|
-
return newInvalidBindings;
|
|
3519
|
-
}
|
|
3520
|
-
},
|
|
3521
|
-
{ logger: new ProxyLogger(() => this.options?.logger) }
|
|
3522
|
-
)
|
|
3528
|
+
validationMiddleware
|
|
3523
3529
|
];
|
|
3524
3530
|
}
|
|
3525
3531
|
getValidationProviders() {
|
|
@@ -3550,9 +3556,10 @@ var ValidationController = class {
|
|
|
3550
3556
|
reset() {
|
|
3551
3557
|
this.validations.clear();
|
|
3552
3558
|
this.tracker = void 0;
|
|
3559
|
+
this.validationMiddleware?.reset();
|
|
3553
3560
|
}
|
|
3554
3561
|
onView(view) {
|
|
3555
|
-
this.
|
|
3562
|
+
this.reset();
|
|
3556
3563
|
if (!this.options) {
|
|
3557
3564
|
return;
|
|
3558
3565
|
}
|
|
@@ -5634,7 +5641,7 @@ var AssetTransformCorePlugin = class {
|
|
|
5634
5641
|
import { setIn as setIn7 } from "timm";
|
|
5635
5642
|
import deferred from "p-defer";
|
|
5636
5643
|
import queueMicrotask2 from "queue-microtask";
|
|
5637
|
-
import { SyncHook as SyncHook10, SyncWaterfallHook as SyncWaterfallHook11 } from "tapable-ts";
|
|
5644
|
+
import { SyncBailHook as SyncBailHook7, SyncHook as SyncHook10, SyncWaterfallHook as SyncWaterfallHook11 } from "tapable-ts";
|
|
5638
5645
|
|
|
5639
5646
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/plugins/flow-exp-plugin.ts
|
|
5640
5647
|
var FlowExpPlugin = class {
|
|
@@ -5714,8 +5721,8 @@ var NOT_STARTED_STATE = {
|
|
|
5714
5721
|
};
|
|
5715
5722
|
|
|
5716
5723
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/player.ts
|
|
5717
|
-
var PLAYER_VERSION = true ? "1.1.0-next.
|
|
5718
|
-
var COMMIT = true ? "
|
|
5724
|
+
var PLAYER_VERSION = true ? "1.1.0-next.3" : "unknown";
|
|
5725
|
+
var COMMIT = true ? "234b74972b29ff0fa11655411dc3cd9d8a98de2a" : "unknown";
|
|
5719
5726
|
var _Player = class _Player {
|
|
5720
5727
|
constructor(config) {
|
|
5721
5728
|
this.logger = new TapableLogger();
|
|
@@ -5734,7 +5741,8 @@ var _Player = class _Player {
|
|
|
5734
5741
|
state: new SyncHook10(),
|
|
5735
5742
|
onStart: new SyncHook10(),
|
|
5736
5743
|
onEnd: new SyncHook10(),
|
|
5737
|
-
resolveFlowContent: new SyncWaterfallHook11()
|
|
5744
|
+
resolveFlowContent: new SyncWaterfallHook11(),
|
|
5745
|
+
transformContent: new SyncBailHook7()
|
|
5738
5746
|
};
|
|
5739
5747
|
if (config?.logger) {
|
|
5740
5748
|
this.logger.addHandler(config.logger);
|
|
@@ -5748,6 +5756,10 @@ var _Player = class _Player {
|
|
|
5748
5756
|
this.config.plugins?.forEach((plugin) => {
|
|
5749
5757
|
plugin.apply(this);
|
|
5750
5758
|
});
|
|
5759
|
+
this.hooks.transformContent.tap(
|
|
5760
|
+
"player",
|
|
5761
|
+
(payload, meta) => meta.format === "player" ? payload : void 0
|
|
5762
|
+
);
|
|
5751
5763
|
}
|
|
5752
5764
|
/** Returns currently registered plugins */
|
|
5753
5765
|
getPlugins() {
|
|
@@ -6028,8 +6040,18 @@ var _Player = class _Player {
|
|
|
6028
6040
|
}
|
|
6029
6041
|
};
|
|
6030
6042
|
}
|
|
6031
|
-
async start(payload) {
|
|
6032
|
-
const
|
|
6043
|
+
async start(payload, options) {
|
|
6044
|
+
const meta = {
|
|
6045
|
+
format: options?.format ?? "player",
|
|
6046
|
+
version: options?.version
|
|
6047
|
+
};
|
|
6048
|
+
const flow = this.hooks.transformContent.call(payload, meta);
|
|
6049
|
+
if (!flow) {
|
|
6050
|
+
throw new Error(
|
|
6051
|
+
`Player.start received content with format "${meta.format}" that no plugin transformed into a Flow.`
|
|
6052
|
+
);
|
|
6053
|
+
}
|
|
6054
|
+
const ref = Symbol(flow.id ?? "payload");
|
|
6033
6055
|
const maybeUpdateState = (newState) => {
|
|
6034
6056
|
if (this.state.ref !== ref) {
|
|
6035
6057
|
this.logger.warn(
|
|
@@ -6045,7 +6067,7 @@ var _Player = class _Player {
|
|
|
6045
6067
|
ref
|
|
6046
6068
|
});
|
|
6047
6069
|
try {
|
|
6048
|
-
const { state, start } = this.setupFlow(
|
|
6070
|
+
const { state, start } = this.setupFlow(flow);
|
|
6049
6071
|
this.setState({
|
|
6050
6072
|
ref,
|
|
6051
6073
|
...state
|
|
@@ -6067,7 +6089,7 @@ var _Player = class _Player {
|
|
|
6067
6089
|
const errorState = {
|
|
6068
6090
|
status: "error",
|
|
6069
6091
|
ref,
|
|
6070
|
-
flow
|
|
6092
|
+
flow,
|
|
6071
6093
|
error
|
|
6072
6094
|
};
|
|
6073
6095
|
maybeUpdateState(errorState);
|
package/dist/index.mjs
CHANGED
|
@@ -2628,6 +2628,10 @@ var ValidationMiddleware = class {
|
|
|
2628
2628
|
);
|
|
2629
2629
|
return next?.delete(binding, options);
|
|
2630
2630
|
}
|
|
2631
|
+
/** Clears any invalid values staged in the shadow model */
|
|
2632
|
+
reset() {
|
|
2633
|
+
this.shadowModelPaths.clear();
|
|
2634
|
+
}
|
|
2631
2635
|
};
|
|
2632
2636
|
|
|
2633
2637
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/validator/registry.ts
|
|
@@ -3467,6 +3471,44 @@ var ValidationController = class {
|
|
|
3467
3471
|
}
|
|
3468
3472
|
/** Return the middleware for the data-model to stop propagation of invalid data */
|
|
3469
3473
|
getDataMiddleware() {
|
|
3474
|
+
const validationMiddleware = new ValidationMiddleware(
|
|
3475
|
+
(binding) => {
|
|
3476
|
+
if (!this.options) {
|
|
3477
|
+
return;
|
|
3478
|
+
}
|
|
3479
|
+
this.updateValidationsForBinding(binding, "change", this.options);
|
|
3480
|
+
const strongValidation = this.getValidationForBinding(binding);
|
|
3481
|
+
if (strongValidation?.get()?.severity === "error") {
|
|
3482
|
+
return strongValidation.get();
|
|
3483
|
+
}
|
|
3484
|
+
const newInvalidBindings = /* @__PURE__ */ new Set();
|
|
3485
|
+
this.validations.forEach((weakValidation, strongBinding) => {
|
|
3486
|
+
if (caresAboutDataChanges(
|
|
3487
|
+
/* @__PURE__ */ new Set([binding]),
|
|
3488
|
+
weakValidation.weakBindings
|
|
3489
|
+
) && weakValidation?.get()?.severity === "error") {
|
|
3490
|
+
weakValidation?.weakBindings.forEach((weakBinding) => {
|
|
3491
|
+
if (weakBinding === strongBinding) {
|
|
3492
|
+
newInvalidBindings.add({
|
|
3493
|
+
binding: weakBinding,
|
|
3494
|
+
isStrong: true
|
|
3495
|
+
});
|
|
3496
|
+
} else {
|
|
3497
|
+
newInvalidBindings.add({
|
|
3498
|
+
binding: weakBinding,
|
|
3499
|
+
isStrong: false
|
|
3500
|
+
});
|
|
3501
|
+
}
|
|
3502
|
+
});
|
|
3503
|
+
}
|
|
3504
|
+
});
|
|
3505
|
+
if (newInvalidBindings.size > 0) {
|
|
3506
|
+
return newInvalidBindings;
|
|
3507
|
+
}
|
|
3508
|
+
},
|
|
3509
|
+
{ logger: new ProxyLogger(() => this.options?.logger) }
|
|
3510
|
+
);
|
|
3511
|
+
this.validationMiddleware = validationMiddleware;
|
|
3470
3512
|
return [
|
|
3471
3513
|
{
|
|
3472
3514
|
set: (transaction, options, next) => {
|
|
@@ -3483,43 +3525,7 @@ var ValidationController = class {
|
|
|
3483
3525
|
return next?.delete(binding, options);
|
|
3484
3526
|
}
|
|
3485
3527
|
},
|
|
3486
|
-
|
|
3487
|
-
(binding) => {
|
|
3488
|
-
if (!this.options) {
|
|
3489
|
-
return;
|
|
3490
|
-
}
|
|
3491
|
-
this.updateValidationsForBinding(binding, "change", this.options);
|
|
3492
|
-
const strongValidation = this.getValidationForBinding(binding);
|
|
3493
|
-
if (strongValidation?.get()?.severity === "error") {
|
|
3494
|
-
return strongValidation.get();
|
|
3495
|
-
}
|
|
3496
|
-
const newInvalidBindings = /* @__PURE__ */ new Set();
|
|
3497
|
-
this.validations.forEach((weakValidation, strongBinding) => {
|
|
3498
|
-
if (caresAboutDataChanges(
|
|
3499
|
-
/* @__PURE__ */ new Set([binding]),
|
|
3500
|
-
weakValidation.weakBindings
|
|
3501
|
-
) && weakValidation?.get()?.severity === "error") {
|
|
3502
|
-
weakValidation?.weakBindings.forEach((weakBinding) => {
|
|
3503
|
-
if (weakBinding === strongBinding) {
|
|
3504
|
-
newInvalidBindings.add({
|
|
3505
|
-
binding: weakBinding,
|
|
3506
|
-
isStrong: true
|
|
3507
|
-
});
|
|
3508
|
-
} else {
|
|
3509
|
-
newInvalidBindings.add({
|
|
3510
|
-
binding: weakBinding,
|
|
3511
|
-
isStrong: false
|
|
3512
|
-
});
|
|
3513
|
-
}
|
|
3514
|
-
});
|
|
3515
|
-
}
|
|
3516
|
-
});
|
|
3517
|
-
if (newInvalidBindings.size > 0) {
|
|
3518
|
-
return newInvalidBindings;
|
|
3519
|
-
}
|
|
3520
|
-
},
|
|
3521
|
-
{ logger: new ProxyLogger(() => this.options?.logger) }
|
|
3522
|
-
)
|
|
3528
|
+
validationMiddleware
|
|
3523
3529
|
];
|
|
3524
3530
|
}
|
|
3525
3531
|
getValidationProviders() {
|
|
@@ -3550,9 +3556,10 @@ var ValidationController = class {
|
|
|
3550
3556
|
reset() {
|
|
3551
3557
|
this.validations.clear();
|
|
3552
3558
|
this.tracker = void 0;
|
|
3559
|
+
this.validationMiddleware?.reset();
|
|
3553
3560
|
}
|
|
3554
3561
|
onView(view) {
|
|
3555
|
-
this.
|
|
3562
|
+
this.reset();
|
|
3556
3563
|
if (!this.options) {
|
|
3557
3564
|
return;
|
|
3558
3565
|
}
|
|
@@ -5634,7 +5641,7 @@ var AssetTransformCorePlugin = class {
|
|
|
5634
5641
|
import { setIn as setIn7 } from "timm";
|
|
5635
5642
|
import deferred from "p-defer";
|
|
5636
5643
|
import queueMicrotask2 from "queue-microtask";
|
|
5637
|
-
import { SyncHook as SyncHook10, SyncWaterfallHook as SyncWaterfallHook11 } from "tapable-ts";
|
|
5644
|
+
import { SyncBailHook as SyncBailHook7, SyncHook as SyncHook10, SyncWaterfallHook as SyncWaterfallHook11 } from "tapable-ts";
|
|
5638
5645
|
|
|
5639
5646
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/plugins/flow-exp-plugin.ts
|
|
5640
5647
|
var FlowExpPlugin = class {
|
|
@@ -5714,8 +5721,8 @@ var NOT_STARTED_STATE = {
|
|
|
5714
5721
|
};
|
|
5715
5722
|
|
|
5716
5723
|
// ../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/core/player/src/player.ts
|
|
5717
|
-
var PLAYER_VERSION = true ? "1.1.0-next.
|
|
5718
|
-
var COMMIT = true ? "
|
|
5724
|
+
var PLAYER_VERSION = true ? "1.1.0-next.3" : "unknown";
|
|
5725
|
+
var COMMIT = true ? "234b74972b29ff0fa11655411dc3cd9d8a98de2a" : "unknown";
|
|
5719
5726
|
var _Player = class _Player {
|
|
5720
5727
|
constructor(config) {
|
|
5721
5728
|
this.logger = new TapableLogger();
|
|
@@ -5734,7 +5741,8 @@ var _Player = class _Player {
|
|
|
5734
5741
|
state: new SyncHook10(),
|
|
5735
5742
|
onStart: new SyncHook10(),
|
|
5736
5743
|
onEnd: new SyncHook10(),
|
|
5737
|
-
resolveFlowContent: new SyncWaterfallHook11()
|
|
5744
|
+
resolveFlowContent: new SyncWaterfallHook11(),
|
|
5745
|
+
transformContent: new SyncBailHook7()
|
|
5738
5746
|
};
|
|
5739
5747
|
if (config?.logger) {
|
|
5740
5748
|
this.logger.addHandler(config.logger);
|
|
@@ -5748,6 +5756,10 @@ var _Player = class _Player {
|
|
|
5748
5756
|
this.config.plugins?.forEach((plugin) => {
|
|
5749
5757
|
plugin.apply(this);
|
|
5750
5758
|
});
|
|
5759
|
+
this.hooks.transformContent.tap(
|
|
5760
|
+
"player",
|
|
5761
|
+
(payload, meta) => meta.format === "player" ? payload : void 0
|
|
5762
|
+
);
|
|
5751
5763
|
}
|
|
5752
5764
|
/** Returns currently registered plugins */
|
|
5753
5765
|
getPlugins() {
|
|
@@ -6028,8 +6040,18 @@ var _Player = class _Player {
|
|
|
6028
6040
|
}
|
|
6029
6041
|
};
|
|
6030
6042
|
}
|
|
6031
|
-
async start(payload) {
|
|
6032
|
-
const
|
|
6043
|
+
async start(payload, options) {
|
|
6044
|
+
const meta = {
|
|
6045
|
+
format: options?.format ?? "player",
|
|
6046
|
+
version: options?.version
|
|
6047
|
+
};
|
|
6048
|
+
const flow = this.hooks.transformContent.call(payload, meta);
|
|
6049
|
+
if (!flow) {
|
|
6050
|
+
throw new Error(
|
|
6051
|
+
`Player.start received content with format "${meta.format}" that no plugin transformed into a Flow.`
|
|
6052
|
+
);
|
|
6053
|
+
}
|
|
6054
|
+
const ref = Symbol(flow.id ?? "payload");
|
|
6033
6055
|
const maybeUpdateState = (newState) => {
|
|
6034
6056
|
if (this.state.ref !== ref) {
|
|
6035
6057
|
this.logger.warn(
|
|
@@ -6045,7 +6067,7 @@ var _Player = class _Player {
|
|
|
6045
6067
|
ref
|
|
6046
6068
|
});
|
|
6047
6069
|
try {
|
|
6048
|
-
const { state, start } = this.setupFlow(
|
|
6070
|
+
const { state, start } = this.setupFlow(flow);
|
|
6049
6071
|
this.setState({
|
|
6050
6072
|
ref,
|
|
6051
6073
|
...state
|
|
@@ -6067,7 +6089,7 @@ var _Player = class _Player {
|
|
|
6067
6089
|
const errorState = {
|
|
6068
6090
|
status: "error",
|
|
6069
6091
|
ref,
|
|
6070
|
-
flow
|
|
6092
|
+
flow,
|
|
6071
6093
|
error
|
|
6072
6094
|
};
|
|
6073
6095
|
maybeUpdateState(errorState);
|