@player-ui/player 0.4.0-next.9 → 0.4.1-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.
package/dist/index.cjs.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var types = require('@player-ui/types');
6
6
  var tapableTs = require('tapable-ts');
7
- var NestedError = require('nested-error-stacks');
7
+ var tsNestedError = require('ts-nested-error');
8
8
  var flatten$1 = require('arr-flatten');
9
9
  var P = require('parsimmon');
10
10
  var ebnf = require('ebnf');
@@ -17,7 +17,6 @@ var partialMatchRegistry = require('@player-ui/partial-match-registry');
17
17
 
18
18
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
19
19
 
20
- var NestedError__default = /*#__PURE__*/_interopDefaultLegacy(NestedError);
21
20
  var flatten__default = /*#__PURE__*/_interopDefaultLegacy(flatten$1);
22
21
  var P__default = /*#__PURE__*/_interopDefaultLegacy(P);
23
22
  var get__default = /*#__PURE__*/_interopDefaultLegacy(get);
@@ -106,7 +105,8 @@ const isIdentifierChar = (char) => {
106
105
  return false;
107
106
  }
108
107
  const charCode = char.charCodeAt(0);
109
- return charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || charCode === 95 || charCode === 45 || charCode === 64;
108
+ const matches = charCode === 32 || charCode === 34 || charCode === 39 || charCode === 40 || charCode === 41 || charCode === 42 || charCode === 46 || charCode === 61 || charCode === 91 || charCode === 93 || charCode === 96 || charCode === 123 || charCode === 125;
109
+ return !matches;
110
110
  };
111
111
  const parse$1 = (path) => {
112
112
  let index = 1;
@@ -392,7 +392,7 @@ function resolveBindingAST(bindingPathNode, options, hooks) {
392
392
  try {
393
393
  return options.convertToPath(options.getValue(nestedResolvedValue.path));
394
394
  } catch (e) {
395
- throw new NestedError__default["default"](`Unable to resolve path segment: ${nestedResolvedValue.path}`, e);
395
+ throw new tsNestedError.NestedError(`Unable to resolve path segment: ${nestedResolvedValue.path}`, e);
396
396
  }
397
397
  }
398
398
  if (node.name === "Expression") {
@@ -400,7 +400,7 @@ function resolveBindingAST(bindingPathNode, options, hooks) {
400
400
  const actualValue = options.evaluate(node.value);
401
401
  return options.convertToPath(actualValue);
402
402
  } catch (e) {
403
- throw new NestedError__default["default"](`Unable to resolve path: ${node.value}`, e);
403
+ throw new tsNestedError.NestedError(`Unable to resolve path: ${node.value}`, e);
404
404
  }
405
405
  }
406
406
  throw new Error(`Unable to resolve value for node: ${node.name}`);
@@ -470,6 +470,8 @@ var __spreadValues$d = (a, b) => {
470
470
  return a;
471
471
  };
472
472
  const SIMPLE_BINDING_REGEX = /^[\w\-@]+(\.[\w\-@]+)*$/;
473
+ const BINDING_BRACKETS_REGEX = /[\s()*=`{}'"[\]]/;
474
+ const LAZY_BINDING_REGEX = /^[^.]+(\..+)*$/;
473
475
  const DEFAULT_OPTIONS = {
474
476
  get: () => {
475
477
  throw new Error("Not Implemented");
@@ -494,7 +496,7 @@ class BindingParser {
494
496
  }
495
497
  normalizePath(path, resolveOptions) {
496
498
  var _a, _b;
497
- if (path.match(SIMPLE_BINDING_REGEX) && this.hooks.skipOptimization.call(path) !== true) {
499
+ if (!BINDING_BRACKETS_REGEX.test(path) && LAZY_BINDING_REGEX.test(path) && this.hooks.skipOptimization.call(path) !== true) {
498
500
  return { path: path.split("."), updates: void 0 };
499
501
  }
500
502
  const ast = (_a = this.parseCache[path]) != null ? _a : parse$1(path);
@@ -505,7 +507,7 @@ class BindingParser {
505
507
  try {
506
508
  return resolveBindingAST(ast.path, resolveOptions, this.hooks);
507
509
  } catch (e) {
508
- throw new NestedError__default["default"](`Cannot resolve binding: ${path}`, e);
510
+ throw new tsNestedError.NestedError(`Cannot resolve binding: ${path}`, e);
509
511
  }
510
512
  }
511
513
  getBindingForNormalizedResult(normalized) {
@@ -3757,6 +3759,14 @@ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
3757
3759
  const SCHEMA_VALIDATION_PROVIDER_NAME = "schema";
3758
3760
  const VIEW_VALIDATION_PROVIDER_NAME = "view";
3759
3761
  const VALIDATION_PROVIDER_NAME_SYMBOL = Symbol.for("validation-provider-name");
3762
+ function isSubset(subset, containingSet) {
3763
+ if (subset.size > containingSet.size)
3764
+ return false;
3765
+ for (const entry of subset)
3766
+ if (!containingSet.has(entry))
3767
+ return false;
3768
+ return true;
3769
+ }
3760
3770
  function createStatefulValidationObject(obj) {
3761
3771
  return {
3762
3772
  value: obj,
@@ -3818,24 +3828,27 @@ class ValidatedBinding {
3818
3828
  });
3819
3829
  }
3820
3830
  }
3821
- runApplicableValidations(runner, canDismiss) {
3822
- this.applicableValidations = this.applicableValidations.map((obj) => {
3831
+ runApplicableValidations(runner, canDismiss, phase) {
3832
+ this.applicableValidations = this.applicableValidations.map((originalValue) => {
3823
3833
  var _a, _b, _c;
3824
- if (obj.state === "dismissed") {
3825
- return obj;
3834
+ if (originalValue.state === "dismissed") {
3835
+ return originalValue;
3826
3836
  }
3827
- const blocking = (_a = obj.value.blocking) != null ? _a : obj.value.severity === "warning" && "once" || true;
3837
+ const blocking = (_a = originalValue.value.blocking) != null ? _a : originalValue.value.severity === "warning" && "once" || true;
3838
+ const obj = timm.setIn(originalValue, ["value", "blocking"], blocking);
3828
3839
  const isBlockingNavigation = blocking === true || blocking === "once" && !canDismiss;
3829
- const dismissable = canDismiss && blocking === "once";
3830
- if (this.currentPhase === "navigation" && obj.state === "active" && dismissable) {
3840
+ if (phase === "navigation" && obj.state === "active" && obj.value.blocking !== true) {
3831
3841
  if (obj.value.severity === "warning") {
3832
3842
  const warn = obj;
3833
- if (warn.dismissable && warn.response.dismiss) {
3843
+ if (warn.dismissable && warn.response.dismiss && (warn.response.blocking !== "once" || !warn.response.blocking)) {
3834
3844
  warn.response.dismiss();
3835
3845
  } else {
3846
+ if ((warn == null ? void 0 : warn.response.blocking) === "once") {
3847
+ warn.response.blocking = false;
3848
+ }
3836
3849
  warn.dismissable = true;
3837
3850
  }
3838
- return obj;
3851
+ return warn;
3839
3852
  }
3840
3853
  }
3841
3854
  const response = runner(obj.value);
@@ -3844,7 +3857,7 @@ class ValidatedBinding {
3844
3857
  value: obj.value,
3845
3858
  state: response ? "active" : "none",
3846
3859
  isBlockingNavigation,
3847
- dismissable: obj.value.severity === "warning" && this.currentPhase === "navigation",
3860
+ dismissable: obj.value.severity === "warning" && phase === "navigation",
3848
3861
  response: response ? __spreadProps$2(__spreadValues$3({}, obj.value), {
3849
3862
  message: (_b = response.message) != null ? _b : "Something is broken",
3850
3863
  severity: obj.value.severity,
@@ -3862,11 +3875,12 @@ class ValidatedBinding {
3862
3875
  });
3863
3876
  }
3864
3877
  update(phase, canDismiss, runner) {
3878
+ const newApplicableValidations = [];
3865
3879
  if (phase === "load" && this.currentPhase !== void 0) {
3866
3880
  return;
3867
3881
  }
3868
3882
  if (this.currentPhase === "navigation" || phase === this.currentPhase) {
3869
- this.runApplicableValidations(runner, canDismiss);
3883
+ this.runApplicableValidations(runner, canDismiss, phase);
3870
3884
  return;
3871
3885
  }
3872
3886
  if (phase === "load") {
@@ -3879,14 +3893,19 @@ class ValidatedBinding {
3879
3893
  ...this.validationsByState.change
3880
3894
  ];
3881
3895
  } else if (phase === "navigation" && (this.currentPhase === "load" || this.currentPhase === "change")) {
3896
+ this.applicableValidations.forEach((element) => {
3897
+ if (!(element.type === "error" && element.state === "active" && element.isBlockingNavigation === false)) {
3898
+ newApplicableValidations.push(element);
3899
+ }
3900
+ });
3882
3901
  this.applicableValidations = [
3883
- ...this.applicableValidations,
3884
- ...this.currentPhase === "load" ? this.validationsByState.change : [],
3885
- ...this.validationsByState.navigation
3902
+ ...newApplicableValidations,
3903
+ ...this.validationsByState.navigation,
3904
+ ...this.currentPhase === "load" ? this.validationsByState.change : []
3886
3905
  ];
3887
3906
  this.currentPhase = "navigation";
3888
3907
  }
3889
- this.runApplicableValidations(runner, canDismiss);
3908
+ this.runApplicableValidations(runner, canDismiss, phase);
3890
3909
  }
3891
3910
  }
3892
3911
  class ValidationController {
@@ -4120,19 +4139,11 @@ class ValidationController {
4120
4139
  updateValidations(!isNavigationTrigger);
4121
4140
  if (isNavigationTrigger) {
4122
4141
  const { activeBindings } = this;
4123
- if (this.setCompare(lastActiveBindings, activeBindings)) {
4142
+ if (isSubset(activeBindings, lastActiveBindings)) {
4124
4143
  updateValidations(true);
4125
4144
  }
4126
4145
  }
4127
4146
  }
4128
- setCompare(set1, set2) {
4129
- if (set1.size !== set2.size)
4130
- return false;
4131
- for (const entry of set1)
4132
- if (!set2.has(entry))
4133
- return false;
4134
- return true;
4135
- }
4136
4147
  get activeBindings() {
4137
4148
  return new Set(Array.from(this.getBindings()).filter((b) => {
4138
4149
  var _a;
@@ -4480,6 +4491,25 @@ class ViewController {
4480
4491
  }
4481
4492
  }
4482
4493
 
4494
+ class ReadOnlyDataController {
4495
+ constructor(controller, logger) {
4496
+ this.controller = controller;
4497
+ this.logger = logger;
4498
+ }
4499
+ get(binding, options) {
4500
+ return this.controller.get(binding, options);
4501
+ }
4502
+ set(transaction, options) {
4503
+ var _a;
4504
+ (_a = this.logger) == null ? void 0 : _a.error("Error: Tried to set in a read only instance of the DataController");
4505
+ return [];
4506
+ }
4507
+ delete(binding, options) {
4508
+ var _a;
4509
+ (_a = this.logger) == null ? void 0 : _a.error("Error: Tried to delete in a read only instance of the DataController");
4510
+ }
4511
+ }
4512
+
4483
4513
  class DataController {
4484
4514
  constructor(model, options) {
4485
4515
  this.hooks = {
@@ -4604,6 +4634,9 @@ class DataController {
4604
4634
  serialize() {
4605
4635
  return this.hooks.serialize.call(this.get(""));
4606
4636
  }
4637
+ makeReadOnly() {
4638
+ return new ReadOnlyDataController(this, this.logger);
4639
+ }
4607
4640
  }
4608
4641
 
4609
4642
  var __defProp$1 = Object.defineProperty;
@@ -4783,8 +4816,8 @@ var __async = (__this, __arguments, generator) => {
4783
4816
  step((generator = generator.apply(__this, __arguments)).next());
4784
4817
  });
4785
4818
  };
4786
- const PLAYER_VERSION = "0.4.0-next.9";
4787
- const COMMIT = "e7681a2757fe0ab15d0c0e27c11d0ed33334d63f";
4819
+ const PLAYER_VERSION = "0.4.1-next.0";
4820
+ const COMMIT = "3fca14a3bf47195b400f5989a2f3ecbc5f73ac4b";
4788
4821
  const _Player = class {
4789
4822
  constructor(config) {
4790
4823
  this.logger = new TapableLogger();
@@ -5058,7 +5091,10 @@ const _Player = class {
5058
5091
  const endProps = {
5059
5092
  ref,
5060
5093
  status: "completed",
5061
- flow: state.flow
5094
+ flow: state.flow,
5095
+ controllers: {
5096
+ data: state.controllers.data.makeReadOnly()
5097
+ }
5062
5098
  };
5063
5099
  return maybeUpdateState(__spreadValues(__spreadValues({}, yield state.flowResult), endProps));
5064
5100
  } catch (error) {
@@ -5082,6 +5118,7 @@ Player.info = {
5082
5118
 
5083
5119
  exports.ApplicabilityPlugin = ApplicabilityPlugin;
5084
5120
  exports.AssetTransformCorePlugin = AssetTransformCorePlugin;
5121
+ exports.BINDING_BRACKETS_REGEX = BINDING_BRACKETS_REGEX;
5085
5122
  exports.BindingInstance = BindingInstance;
5086
5123
  exports.BindingParser = BindingParser;
5087
5124
  exports.Builder = Builder;
package/dist/index.d.ts CHANGED
@@ -123,6 +123,8 @@ declare function getBindingSegments(binding: BindingLike): Array<string | number
123
123
  declare function findInArray<T extends Record<string | number, object>>(array: Array<T>, key: string | number, value: T): number | undefined;
124
124
 
125
125
  declare const SIMPLE_BINDING_REGEX: RegExp;
126
+ declare const BINDING_BRACKETS_REGEX: RegExp;
127
+ declare type BeforeResolveNodeContext = Required<NormalizedResult> & ResolveBindingASTOptions;
126
128
  /** A parser for creating bindings from a string */
127
129
  declare class BindingParser {
128
130
  private cache;
@@ -130,7 +132,7 @@ declare class BindingParser {
130
132
  private parserOptions;
131
133
  hooks: {
132
134
  skipOptimization: SyncBailHook<[string], boolean, Record<string, any>>;
133
- beforeResolveNode: SyncWaterfallHook<[AnyNode, Required<NormalizedResult> & ResolveBindingASTOptions], Record<string, any>>;
135
+ beforeResolveNode: SyncWaterfallHook<[AnyNode, BeforeResolveNodeContext], Record<string, any>>;
134
136
  };
135
137
  constructor(options?: Partial<BindingParserOptions>);
136
138
  /**
@@ -1330,7 +1332,6 @@ declare class ValidationController implements BindingTracker {
1330
1332
  message: string;
1331
1333
  } | undefined;
1332
1334
  private updateValidationsForView;
1333
- private setCompare;
1334
1335
  private get activeBindings();
1335
1336
  getValidator(type: string): ValidatorFunction<unknown> | undefined;
1336
1337
  getBindings(): Set<BindingInstance>;
@@ -1378,6 +1379,16 @@ interface TransformFunctions {
1378
1379
  }
1379
1380
  declare type TransformRegistry = Registry<TransformFunctions>;
1380
1381
 
1382
+ /** Wrapper for the Data Controller Class that prevents writes */
1383
+ declare class ReadOnlyDataController implements DataModelWithParser<DataModelOptions> {
1384
+ private controller;
1385
+ private logger?;
1386
+ constructor(controller: DataController, logger?: Logger);
1387
+ get(binding: BindingLike, options?: DataModelOptions | undefined): any;
1388
+ set(transaction: [BindingLike, any][], options?: DataModelOptions | undefined): Updates;
1389
+ delete(binding: BindingLike, options?: DataModelOptions | undefined): void;
1390
+ }
1391
+
1381
1392
  /** The status for a flow's execution state */
1382
1393
  declare type PlayerFlowStatus = 'not-started' | 'in-progress' | 'completed' | 'error';
1383
1394
  /** Common interface for the state of Player's flow execution */
@@ -1425,7 +1436,13 @@ declare type InProgressState = BaseFlowState<'in-progress'> & PlayerFlowExecutio
1425
1436
  logger: Logger;
1426
1437
  };
1427
1438
  /** The flow completed properly */
1428
- declare type CompletedState = BaseFlowState<'completed'> & PlayerFlowExecutionData & FlowResult;
1439
+ declare type CompletedState = BaseFlowState<'completed'> & PlayerFlowExecutionData & FlowResult & {
1440
+ /** Readonly Player controllers to provide Player functionality after the flow has ended */
1441
+ controllers: {
1442
+ /** A read only instance of the Data Controller */
1443
+ data: ReadOnlyDataController;
1444
+ };
1445
+ };
1429
1446
  /** The flow finished but not successfully */
1430
1447
  declare type ErrorState = BaseFlowState<'error'> & {
1431
1448
  /** The currently executing flow */
@@ -1472,6 +1489,7 @@ declare class DataController implements DataModelWithParser<DataModelOptions> {
1472
1489
  get(binding: BindingLike, options?: DataModelOptions): any;
1473
1490
  delete(binding: BindingLike, options?: DataModelOptions): void;
1474
1491
  serialize(): object;
1492
+ makeReadOnly(): ReadOnlyDataController;
1475
1493
  }
1476
1494
 
1477
1495
  interface ViewControllerOptions {
@@ -1775,4 +1793,4 @@ declare class FlowExpPlugin implements PlayerPlugin {
1775
1793
  apply(player: Player): void;
1776
1794
  }
1777
1795
 
1778
- export { AnyAssetType, ApplicabilityPlugin, ArrayExpressionNode, AssetTransformCorePlugin, AssignmentNode, BaseFlowState, BaseNode, BasicExpressionTypes, BatchSetTransaction, BeforeTransformFunction, BinaryNode, BinaryOperator, BinaryOperatorAdvanced, BinaryOperatorBasic, BindingFactory, BindingInstance, BindingLike, BindingParser, BindingParserOptions, BindingTracker, Builder, CallExpressionNode, CompletedState, CompoundNode, ConditionalExpressionNode, ConsoleLogger, ConstantsController, ConstantsProvider, ControllerState, DataController, DataModelImpl, DataModelMiddleware, DataModelOptions, DataModelWithParser, DataPipeline, DependencyMiddleware, DependencyModel, DependencySets, DependencyTracker, DirectionalNode, EMPTY_NODE, ErrorState, ErrorValidationResponse, ExpNodeOpaqueIdentifier, ExpressionContext, ExpressionEvaluator, ExpressionEvaluatorFunction, ExpressionEvaluatorOptions, ExpressionHandler, ExpressionLiteralType, ExpressionNode, ExpressionNodeType, ExpressionObjectType, ExpressionType, ExtendedPlayerPlugin, FlowController, FlowExpPlugin, FlowInstance, FormatDefinition, FormatFunction, FormatHandler, FormatOptions, FormatType, Getter, HookOptions, IdentifierNode, InProgressState, LiteralNode, LocalModel, LocalStateStore, LogFn, Logger, LoggerProvider, LogicalNode, MemberExpressionNode, MiddlewareChecker, ModelRefNode, ModificationNode, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NamedState, Node, NodeLocation, NodePosition, NodeType, NoopLogger, NotStartedState, ObjectNode, OperatorProcessingOptions, Options, ParseObjectOptions, Parser, PipelinedDataModel, Player, PlayerConfigOptions, PlayerFlowExecutionData, PlayerFlowState, PlayerFlowStatus, PlayerInfo, PlayerPlugin, PlayerUtils, ProxyLogger, ROOT_BINDING, RawBinding, RawBindingSegment, RawSetTransaction, RawSetType, Resolve, Resolver, SCHEMA_VALIDATION_PROVIDER_NAME, SIMPLE_BINDING_REGEX, SchemaController, Severity, StatefulValidationObject, Store, StringResolverPlugin, StrongOrWeakBinding, SwitchPlugin, TapableLogger, TemplatePlugin, ThisNode, TransformFunction, TransformFunctions, TransformRegistry, TransitionFunction, TransitionOptions, UnaryNode, UnaryOperator, Updates, VALIDATION_PROVIDER_NAME_SYMBOL, VIEW_VALIDATION_PROVIDER_NAME, ValidationBindingTrackerViewPlugin, ValidationController, ValidationGetResolveOptions, ValidationMiddleware, ValidationObject, ValidationObjectWithHandler, ValidationObjectWithSource, ValidationProvider, ValidationResponse, ValidatorContext, ValidatorFunction, ValidatorRegistry, ViewController, ViewControllerOptions, ViewInstance, ViewPlugin, WarningValidationResponse, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, isObjectExpression, maybeConvertToNum, parse, parseExpression, removeBindingAndChildrenFromMap, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
1796
+ export { AnyAssetType, ApplicabilityPlugin, ArrayExpressionNode, AssetTransformCorePlugin, AssignmentNode, BINDING_BRACKETS_REGEX, BaseFlowState, BaseNode, BasicExpressionTypes, BatchSetTransaction, BeforeTransformFunction, BinaryNode, BinaryOperator, BinaryOperatorAdvanced, BinaryOperatorBasic, BindingFactory, BindingInstance, BindingLike, BindingParser, BindingParserOptions, BindingTracker, Builder, CallExpressionNode, CompletedState, CompoundNode, ConditionalExpressionNode, ConsoleLogger, ConstantsController, ConstantsProvider, ControllerState, DataController, DataModelImpl, DataModelMiddleware, DataModelOptions, DataModelWithParser, DataPipeline, DependencyMiddleware, DependencyModel, DependencySets, DependencyTracker, DirectionalNode, EMPTY_NODE, ErrorState, ErrorValidationResponse, ExpNodeOpaqueIdentifier, ExpressionContext, ExpressionEvaluator, ExpressionEvaluatorFunction, ExpressionEvaluatorOptions, ExpressionHandler, ExpressionLiteralType, ExpressionNode, ExpressionNodeType, ExpressionObjectType, ExpressionType, ExtendedPlayerPlugin, FlowController, FlowExpPlugin, FlowInstance, FormatDefinition, FormatFunction, FormatHandler, FormatOptions, FormatType, Getter, HookOptions, IdentifierNode, InProgressState, LiteralNode, LocalModel, LocalStateStore, LogFn, Logger, LoggerProvider, LogicalNode, MemberExpressionNode, MiddlewareChecker, ModelRefNode, ModificationNode, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NamedState, Node, NodeLocation, NodePosition, NodeType, NoopLogger, NotStartedState, ObjectNode, OperatorProcessingOptions, Options, ParseObjectOptions, Parser, PipelinedDataModel, Player, PlayerConfigOptions, PlayerFlowExecutionData, PlayerFlowState, PlayerFlowStatus, PlayerInfo, PlayerPlugin, PlayerUtils, ProxyLogger, ROOT_BINDING, RawBinding, RawBindingSegment, RawSetTransaction, RawSetType, Resolve, Resolver, SCHEMA_VALIDATION_PROVIDER_NAME, SIMPLE_BINDING_REGEX, SchemaController, Severity, StatefulValidationObject, Store, StringResolverPlugin, StrongOrWeakBinding, SwitchPlugin, TapableLogger, TemplatePlugin, ThisNode, TransformFunction, TransformFunctions, TransformRegistry, TransitionFunction, TransitionOptions, UnaryNode, UnaryOperator, Updates, VALIDATION_PROVIDER_NAME_SYMBOL, VIEW_VALIDATION_PROVIDER_NAME, ValidationBindingTrackerViewPlugin, ValidationController, ValidationGetResolveOptions, ValidationMiddleware, ValidationObject, ValidationObjectWithHandler, ValidationObjectWithSource, ValidationProvider, ValidationResponse, ValidatorContext, ValidatorFunction, ValidatorRegistry, ViewController, ViewControllerOptions, ViewInstance, ViewPlugin, WarningValidationResponse, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, isObjectExpression, maybeConvertToNum, parse, parseExpression, removeBindingAndChildrenFromMap, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
package/dist/index.esm.js CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from '@player-ui/types';
2
2
  import { SyncBailHook, SyncWaterfallHook, SyncHook } from 'tapable-ts';
3
- import NestedError from 'nested-error-stacks';
3
+ import { NestedError } from 'ts-nested-error';
4
4
  import flatten$1 from 'arr-flatten';
5
5
  import P from 'parsimmon';
6
6
  import { Grammars } from 'ebnf';
@@ -93,7 +93,8 @@ const isIdentifierChar = (char) => {
93
93
  return false;
94
94
  }
95
95
  const charCode = char.charCodeAt(0);
96
- return charCode >= 48 && charCode <= 57 || charCode >= 65 && charCode <= 90 || charCode >= 97 && charCode <= 122 || charCode === 95 || charCode === 45 || charCode === 64;
96
+ const matches = charCode === 32 || charCode === 34 || charCode === 39 || charCode === 40 || charCode === 41 || charCode === 42 || charCode === 46 || charCode === 61 || charCode === 91 || charCode === 93 || charCode === 96 || charCode === 123 || charCode === 125;
97
+ return !matches;
97
98
  };
98
99
  const parse$1 = (path) => {
99
100
  let index = 1;
@@ -457,6 +458,8 @@ var __spreadValues$d = (a, b) => {
457
458
  return a;
458
459
  };
459
460
  const SIMPLE_BINDING_REGEX = /^[\w\-@]+(\.[\w\-@]+)*$/;
461
+ const BINDING_BRACKETS_REGEX = /[\s()*=`{}'"[\]]/;
462
+ const LAZY_BINDING_REGEX = /^[^.]+(\..+)*$/;
460
463
  const DEFAULT_OPTIONS = {
461
464
  get: () => {
462
465
  throw new Error("Not Implemented");
@@ -481,7 +484,7 @@ class BindingParser {
481
484
  }
482
485
  normalizePath(path, resolveOptions) {
483
486
  var _a, _b;
484
- if (path.match(SIMPLE_BINDING_REGEX) && this.hooks.skipOptimization.call(path) !== true) {
487
+ if (!BINDING_BRACKETS_REGEX.test(path) && LAZY_BINDING_REGEX.test(path) && this.hooks.skipOptimization.call(path) !== true) {
485
488
  return { path: path.split("."), updates: void 0 };
486
489
  }
487
490
  const ast = (_a = this.parseCache[path]) != null ? _a : parse$1(path);
@@ -3744,6 +3747,14 @@ var __spreadProps$2 = (a, b) => __defProps$2(a, __getOwnPropDescs$2(b));
3744
3747
  const SCHEMA_VALIDATION_PROVIDER_NAME = "schema";
3745
3748
  const VIEW_VALIDATION_PROVIDER_NAME = "view";
3746
3749
  const VALIDATION_PROVIDER_NAME_SYMBOL = Symbol.for("validation-provider-name");
3750
+ function isSubset(subset, containingSet) {
3751
+ if (subset.size > containingSet.size)
3752
+ return false;
3753
+ for (const entry of subset)
3754
+ if (!containingSet.has(entry))
3755
+ return false;
3756
+ return true;
3757
+ }
3747
3758
  function createStatefulValidationObject(obj) {
3748
3759
  return {
3749
3760
  value: obj,
@@ -3805,24 +3816,27 @@ class ValidatedBinding {
3805
3816
  });
3806
3817
  }
3807
3818
  }
3808
- runApplicableValidations(runner, canDismiss) {
3809
- this.applicableValidations = this.applicableValidations.map((obj) => {
3819
+ runApplicableValidations(runner, canDismiss, phase) {
3820
+ this.applicableValidations = this.applicableValidations.map((originalValue) => {
3810
3821
  var _a, _b, _c;
3811
- if (obj.state === "dismissed") {
3812
- return obj;
3822
+ if (originalValue.state === "dismissed") {
3823
+ return originalValue;
3813
3824
  }
3814
- const blocking = (_a = obj.value.blocking) != null ? _a : obj.value.severity === "warning" && "once" || true;
3825
+ const blocking = (_a = originalValue.value.blocking) != null ? _a : originalValue.value.severity === "warning" && "once" || true;
3826
+ const obj = setIn(originalValue, ["value", "blocking"], blocking);
3815
3827
  const isBlockingNavigation = blocking === true || blocking === "once" && !canDismiss;
3816
- const dismissable = canDismiss && blocking === "once";
3817
- if (this.currentPhase === "navigation" && obj.state === "active" && dismissable) {
3828
+ if (phase === "navigation" && obj.state === "active" && obj.value.blocking !== true) {
3818
3829
  if (obj.value.severity === "warning") {
3819
3830
  const warn = obj;
3820
- if (warn.dismissable && warn.response.dismiss) {
3831
+ if (warn.dismissable && warn.response.dismiss && (warn.response.blocking !== "once" || !warn.response.blocking)) {
3821
3832
  warn.response.dismiss();
3822
3833
  } else {
3834
+ if ((warn == null ? void 0 : warn.response.blocking) === "once") {
3835
+ warn.response.blocking = false;
3836
+ }
3823
3837
  warn.dismissable = true;
3824
3838
  }
3825
- return obj;
3839
+ return warn;
3826
3840
  }
3827
3841
  }
3828
3842
  const response = runner(obj.value);
@@ -3831,7 +3845,7 @@ class ValidatedBinding {
3831
3845
  value: obj.value,
3832
3846
  state: response ? "active" : "none",
3833
3847
  isBlockingNavigation,
3834
- dismissable: obj.value.severity === "warning" && this.currentPhase === "navigation",
3848
+ dismissable: obj.value.severity === "warning" && phase === "navigation",
3835
3849
  response: response ? __spreadProps$2(__spreadValues$3({}, obj.value), {
3836
3850
  message: (_b = response.message) != null ? _b : "Something is broken",
3837
3851
  severity: obj.value.severity,
@@ -3849,11 +3863,12 @@ class ValidatedBinding {
3849
3863
  });
3850
3864
  }
3851
3865
  update(phase, canDismiss, runner) {
3866
+ const newApplicableValidations = [];
3852
3867
  if (phase === "load" && this.currentPhase !== void 0) {
3853
3868
  return;
3854
3869
  }
3855
3870
  if (this.currentPhase === "navigation" || phase === this.currentPhase) {
3856
- this.runApplicableValidations(runner, canDismiss);
3871
+ this.runApplicableValidations(runner, canDismiss, phase);
3857
3872
  return;
3858
3873
  }
3859
3874
  if (phase === "load") {
@@ -3866,14 +3881,19 @@ class ValidatedBinding {
3866
3881
  ...this.validationsByState.change
3867
3882
  ];
3868
3883
  } else if (phase === "navigation" && (this.currentPhase === "load" || this.currentPhase === "change")) {
3884
+ this.applicableValidations.forEach((element) => {
3885
+ if (!(element.type === "error" && element.state === "active" && element.isBlockingNavigation === false)) {
3886
+ newApplicableValidations.push(element);
3887
+ }
3888
+ });
3869
3889
  this.applicableValidations = [
3870
- ...this.applicableValidations,
3871
- ...this.currentPhase === "load" ? this.validationsByState.change : [],
3872
- ...this.validationsByState.navigation
3890
+ ...newApplicableValidations,
3891
+ ...this.validationsByState.navigation,
3892
+ ...this.currentPhase === "load" ? this.validationsByState.change : []
3873
3893
  ];
3874
3894
  this.currentPhase = "navigation";
3875
3895
  }
3876
- this.runApplicableValidations(runner, canDismiss);
3896
+ this.runApplicableValidations(runner, canDismiss, phase);
3877
3897
  }
3878
3898
  }
3879
3899
  class ValidationController {
@@ -4107,19 +4127,11 @@ class ValidationController {
4107
4127
  updateValidations(!isNavigationTrigger);
4108
4128
  if (isNavigationTrigger) {
4109
4129
  const { activeBindings } = this;
4110
- if (this.setCompare(lastActiveBindings, activeBindings)) {
4130
+ if (isSubset(activeBindings, lastActiveBindings)) {
4111
4131
  updateValidations(true);
4112
4132
  }
4113
4133
  }
4114
4134
  }
4115
- setCompare(set1, set2) {
4116
- if (set1.size !== set2.size)
4117
- return false;
4118
- for (const entry of set1)
4119
- if (!set2.has(entry))
4120
- return false;
4121
- return true;
4122
- }
4123
4135
  get activeBindings() {
4124
4136
  return new Set(Array.from(this.getBindings()).filter((b) => {
4125
4137
  var _a;
@@ -4467,6 +4479,25 @@ class ViewController {
4467
4479
  }
4468
4480
  }
4469
4481
 
4482
+ class ReadOnlyDataController {
4483
+ constructor(controller, logger) {
4484
+ this.controller = controller;
4485
+ this.logger = logger;
4486
+ }
4487
+ get(binding, options) {
4488
+ return this.controller.get(binding, options);
4489
+ }
4490
+ set(transaction, options) {
4491
+ var _a;
4492
+ (_a = this.logger) == null ? void 0 : _a.error("Error: Tried to set in a read only instance of the DataController");
4493
+ return [];
4494
+ }
4495
+ delete(binding, options) {
4496
+ var _a;
4497
+ (_a = this.logger) == null ? void 0 : _a.error("Error: Tried to delete in a read only instance of the DataController");
4498
+ }
4499
+ }
4500
+
4470
4501
  class DataController {
4471
4502
  constructor(model, options) {
4472
4503
  this.hooks = {
@@ -4591,6 +4622,9 @@ class DataController {
4591
4622
  serialize() {
4592
4623
  return this.hooks.serialize.call(this.get(""));
4593
4624
  }
4625
+ makeReadOnly() {
4626
+ return new ReadOnlyDataController(this, this.logger);
4627
+ }
4594
4628
  }
4595
4629
 
4596
4630
  var __defProp$1 = Object.defineProperty;
@@ -4770,8 +4804,8 @@ var __async = (__this, __arguments, generator) => {
4770
4804
  step((generator = generator.apply(__this, __arguments)).next());
4771
4805
  });
4772
4806
  };
4773
- const PLAYER_VERSION = "0.4.0-next.9";
4774
- const COMMIT = "e7681a2757fe0ab15d0c0e27c11d0ed33334d63f";
4807
+ const PLAYER_VERSION = "0.4.1-next.0";
4808
+ const COMMIT = "3fca14a3bf47195b400f5989a2f3ecbc5f73ac4b";
4775
4809
  const _Player = class {
4776
4810
  constructor(config) {
4777
4811
  this.logger = new TapableLogger();
@@ -5045,7 +5079,10 @@ const _Player = class {
5045
5079
  const endProps = {
5046
5080
  ref,
5047
5081
  status: "completed",
5048
- flow: state.flow
5082
+ flow: state.flow,
5083
+ controllers: {
5084
+ data: state.controllers.data.makeReadOnly()
5085
+ }
5049
5086
  };
5050
5087
  return maybeUpdateState(__spreadValues(__spreadValues({}, yield state.flowResult), endProps));
5051
5088
  } catch (error) {
@@ -5067,5 +5104,5 @@ Player.info = {
5067
5104
  commit: COMMIT
5068
5105
  };
5069
5106
 
5070
- export { ApplicabilityPlugin, AssetTransformCorePlugin, BindingInstance, BindingParser, Builder, ConsoleLogger, ConstantsController, DataController, DependencyMiddleware, DependencyModel, DependencyTracker, EMPTY_NODE, ExpNodeOpaqueIdentifier, ExpressionEvaluator, FlowController, FlowExpPlugin, FlowInstance, LocalModel, LocalStateStore, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NodeType, NoopLogger, Parser, PipelinedDataModel, Player, ProxyLogger, ROOT_BINDING, Resolver, SCHEMA_VALIDATION_PROVIDER_NAME, SIMPLE_BINDING_REGEX, SchemaController, StringResolverPlugin, SwitchPlugin, TapableLogger, TemplatePlugin, VALIDATION_PROVIDER_NAME_SYMBOL, VIEW_VALIDATION_PROVIDER_NAME, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidatorRegistry, ViewController, ViewInstance, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, isObjectExpression, maybeConvertToNum, parse, parseExpression, removeBindingAndChildrenFromMap, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
5107
+ export { ApplicabilityPlugin, AssetTransformCorePlugin, BINDING_BRACKETS_REGEX, BindingInstance, BindingParser, Builder, ConsoleLogger, ConstantsController, DataController, DependencyMiddleware, DependencyModel, DependencyTracker, EMPTY_NODE, ExpNodeOpaqueIdentifier, ExpressionEvaluator, FlowController, FlowExpPlugin, FlowInstance, LocalModel, LocalStateStore, NOOPDataModel, NOOP_MODEL, NOT_STARTED_STATE, NodeType, NoopLogger, Parser, PipelinedDataModel, Player, ProxyLogger, ROOT_BINDING, Resolver, SCHEMA_VALIDATION_PROVIDER_NAME, SIMPLE_BINDING_REGEX, SchemaController, StringResolverPlugin, SwitchPlugin, TapableLogger, TemplatePlugin, VALIDATION_PROVIDER_NAME_SYMBOL, VIEW_VALIDATION_PROVIDER_NAME, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidatorRegistry, ViewController, ViewInstance, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, isObjectExpression, maybeConvertToNum, parse, parseExpression, removeBindingAndChildrenFromMap, resolveDataRefs, resolveDataRefsInString, resolveExpressionsInString, severities, toModel, toNodeResolveOptions, withParser, withoutContext };
5071
5108
  //# sourceMappingURL=index.esm.js.map