@player-ui/player 0.4.0 → 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.
Files changed (47) hide show
  1. package/dist/index.cjs.js +795 -390
  2. package/dist/index.d.ts +238 -81
  3. package/dist/index.esm.js +787 -388
  4. package/dist/player.dev.js +4768 -5282
  5. package/dist/player.prod.js +1 -1
  6. package/package.json +12 -3
  7. package/src/binding/binding.ts +8 -0
  8. package/src/binding/index.ts +14 -4
  9. package/src/binding/resolver.ts +1 -1
  10. package/src/binding-grammar/custom/index.ts +17 -9
  11. package/src/controllers/constants/index.ts +9 -5
  12. package/src/controllers/{data.ts → data/controller.ts} +60 -61
  13. package/src/controllers/data/index.ts +1 -0
  14. package/src/controllers/data/utils.ts +42 -0
  15. package/src/controllers/flow/controller.ts +16 -12
  16. package/src/controllers/flow/flow.ts +6 -1
  17. package/src/controllers/index.ts +1 -1
  18. package/src/controllers/validation/binding-tracker.ts +42 -19
  19. package/src/controllers/validation/controller.ts +359 -145
  20. package/src/controllers/view/asset-transform.ts +4 -1
  21. package/src/controllers/view/controller.ts +20 -3
  22. package/src/data/dependency-tracker.ts +14 -0
  23. package/src/data/local-model.ts +25 -1
  24. package/src/data/model.ts +55 -8
  25. package/src/data/noop-model.ts +2 -0
  26. package/src/expressions/evaluator-functions.ts +24 -2
  27. package/src/expressions/evaluator.ts +37 -33
  28. package/src/expressions/index.ts +1 -0
  29. package/src/expressions/parser.ts +53 -27
  30. package/src/expressions/types.ts +23 -5
  31. package/src/expressions/utils.ts +19 -0
  32. package/src/player.ts +47 -48
  33. package/src/plugins/default-exp-plugin.ts +57 -0
  34. package/src/plugins/flow-exp-plugin.ts +2 -2
  35. package/src/schema/schema.ts +28 -9
  36. package/src/string-resolver/index.ts +25 -9
  37. package/src/types.ts +6 -3
  38. package/src/validator/binding-map-splice.ts +59 -0
  39. package/src/validator/index.ts +1 -0
  40. package/src/validator/types.ts +11 -3
  41. package/src/validator/validation-middleware.ts +38 -4
  42. package/src/view/parser/index.ts +51 -3
  43. package/src/view/plugins/applicability.ts +1 -1
  44. package/src/view/plugins/string-resolver.ts +8 -4
  45. package/src/view/plugins/template-plugin.ts +1 -6
  46. package/src/view/resolver/index.ts +119 -54
  47. package/src/view/resolver/types.ts +48 -7
package/dist/index.d.ts CHANGED
@@ -58,6 +58,13 @@ interface BindingParserOptions {
58
58
  * Get the result of evaluating an expression
59
59
  */
60
60
  evaluate: (exp: string) => any;
61
+ /**
62
+ * Without readOnly, if a binding such as this is used: arr[key='does not exist'],
63
+ * then an object with that key will be created.
64
+ * This is done to make assignment such as arr[key='abc'].val = 'foo' work smoothly.
65
+ * Setting readOnly to true will prevent this behavior, avoiding unintended data changes.
66
+ */
67
+ readOnly?: boolean;
61
68
  }
62
69
  declare type Getter = (path: BindingInstance) => any;
63
70
  declare type RawBindingSegment = number | string;
@@ -116,6 +123,8 @@ declare function getBindingSegments(binding: BindingLike): Array<string | number
116
123
  declare function findInArray<T extends Record<string | number, object>>(array: Array<T>, key: string | number, value: T): number | undefined;
117
124
 
118
125
  declare const SIMPLE_BINDING_REGEX: RegExp;
126
+ declare const BINDING_BRACKETS_REGEX: RegExp;
127
+ declare type BeforeResolveNodeContext = Required<NormalizedResult> & ResolveBindingASTOptions;
119
128
  /** A parser for creating bindings from a string */
120
129
  declare class BindingParser {
121
130
  private cache;
@@ -123,7 +132,7 @@ declare class BindingParser {
123
132
  private parserOptions;
124
133
  hooks: {
125
134
  skipOptimization: SyncBailHook<[string], boolean, Record<string, any>>;
126
- beforeResolveNode: SyncWaterfallHook<[AnyNode, Required<NormalizedResult> & ResolveBindingASTOptions], Record<string, any>>;
135
+ beforeResolveNode: SyncWaterfallHook<[AnyNode, BeforeResolveNodeContext], Record<string, any>>;
127
136
  };
128
137
  constructor(options?: Partial<BindingParserOptions>);
129
138
  /**
@@ -178,16 +187,19 @@ interface DataModelOptions {
178
187
  interface DataModelWithParser<Options = DataModelOptions> {
179
188
  get(binding: BindingLike, options?: Options): any;
180
189
  set(transaction: [BindingLike, any][], options?: Options): Updates;
190
+ delete(binding: BindingLike, options?: Options): void;
181
191
  }
182
192
  interface DataModelImpl<Options = DataModelOptions> {
183
193
  get(binding: BindingInstance, options?: Options): any;
184
194
  set(transaction: BatchSetTransaction, options?: Options): Updates;
195
+ delete(binding: BindingInstance, options?: Options): void;
185
196
  }
186
197
  interface DataModelMiddleware {
187
198
  /** The name of the middleware */
188
199
  name?: string;
189
200
  set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl): Updates;
190
201
  get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): any;
202
+ delete?(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): void;
191
203
  reset?(): void;
192
204
  }
193
205
  /** Wrap the inputs of the DataModel with calls to parse raw binding inputs */
@@ -212,6 +224,7 @@ declare class PipelinedDataModel implements DataModelImpl {
212
224
  reset(model?: {}): void;
213
225
  set(transaction: BatchSetTransaction, options?: DataModelOptions): Updates;
214
226
  get(binding: BindingInstance, options?: DataModelOptions): any;
227
+ delete(binding: BindingInstance, options?: DataModelOptions): void;
215
228
  }
216
229
 
217
230
  declare type DependencySets = 'core' | 'children';
@@ -250,6 +263,7 @@ declare class DependencyMiddleware extends DependencyTracker implements DataMode
250
263
  constructor();
251
264
  set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl | undefined): Updates;
252
265
  get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl | undefined): any;
266
+ delete(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl | undefined): void | undefined;
253
267
  }
254
268
  /** A data-model that tracks dependencies of read/written data */
255
269
  declare class DependencyModel<Options = DataModelOptions> extends DependencyTracker implements DataModelImpl<Options> {
@@ -257,6 +271,7 @@ declare class DependencyModel<Options = DataModelOptions> extends DependencyTrac
257
271
  constructor(rootModel: DataModelImpl<Options>);
258
272
  set(transaction: BatchSetTransaction, options?: Options): Updates;
259
273
  get(binding: BindingInstance, options?: Options): any;
274
+ delete(binding: BindingInstance, options?: Options): void;
260
275
  }
261
276
 
262
277
  /**
@@ -266,6 +281,7 @@ declare class DependencyModel<Options = DataModelOptions> extends DependencyTrac
266
281
  declare class NOOPDataModel implements DataModelImpl {
267
282
  get(): undefined;
268
283
  set(): never[];
284
+ delete(): void;
269
285
  }
270
286
  /** You only really need 1 instance of the NOOP model */
271
287
  declare const NOOP_MODEL: NOOPDataModel;
@@ -281,6 +297,7 @@ declare class LocalModel implements DataModelImpl {
281
297
  reset(model?: {}): void;
282
298
  get(binding?: BindingInstance): any;
283
299
  set(transaction: BatchSetTransaction): Updates;
300
+ delete(binding: BindingInstance): void;
284
301
  }
285
302
 
286
303
  declare type LogFn = (...args: Array<any>) => void;
@@ -349,8 +366,13 @@ declare class ProxyLogger implements Logger {
349
366
  readonly error: (...args: any[]) => void;
350
367
  }
351
368
 
369
+ declare type ExpressionObjectType = {
370
+ /** The expression to eval */
371
+ value: BasicExpressionTypes;
372
+ };
352
373
  declare type ExpressionLiteralType = string | number | boolean | undefined | null;
353
- declare type ExpressionType = object | ExpressionLiteralType | Array<ExpressionLiteralType> | ExpressionNode;
374
+ declare type BasicExpressionTypes = ExpressionLiteralType | ExpressionObjectType | Array<ExpressionLiteralType | ExpressionObjectType>;
375
+ declare type ExpressionType = BasicExpressionTypes | ExpressionNode;
354
376
  interface OperatorProcessingOptions {
355
377
  /**
356
378
  * When set to a falsy value, the arguments passed to the handler will be raw AST Nodes
@@ -391,6 +413,11 @@ interface BaseNode<T> {
391
413
  __id: typeof ExpNodeOpaqueIdentifier;
392
414
  /** The location of the node in the source expression string */
393
415
  location?: NodeLocation;
416
+ /**
417
+ * The error that occurred while parsing this node
418
+ * This is only set if the parsing mode is set to non-strict
419
+ */
420
+ error?: Error;
394
421
  }
395
422
  /** A helper interface for nodes that container left and right children */
396
423
  interface DirectionalNode {
@@ -478,6 +505,10 @@ declare type ExpressionNodeType = ExpressionNode['type'];
478
505
  interface HookOptions extends ExpressionContext {
479
506
  /** Given an expression node */
480
507
  resolveNode: (node: ExpressionNode) => any;
508
+ /** Enabling this flag skips calling the onError hook, and just throws errors back to the caller.
509
+ * The caller is responsible for handling the error.
510
+ */
511
+ throwErrors?: boolean;
481
512
  }
482
513
  declare type ExpressionEvaluatorOptions = Omit<HookOptions, 'resolveNode' | 'evaluate'>;
483
514
  declare type ExpressionEvaluatorFunction = (exp: ExpressionType, options?: ExpressionEvaluatorOptions) => any;
@@ -489,6 +520,10 @@ declare class ExpressionEvaluator {
489
520
  readonly hooks: {
490
521
  /** Resolve an AST node for an expression to a value */
491
522
  resolve: SyncWaterfallHook<[any, ExpressionNode, HookOptions], Record<string, any>>;
523
+ /** Gets the options that will be passed in calls to the resolve hook */
524
+ resolveOptions: SyncWaterfallHook<[HookOptions], Record<string, any>>;
525
+ /** Allows users to change the expression to be evaluated before processing */
526
+ beforeEvaluate: SyncWaterfallHook<[ExpressionType, HookOptions], Record<string, any>>;
492
527
  /**
493
528
  * An optional means of handling an error in the expression execution
494
529
  * Return true if handled, to stop propagation of the error
@@ -504,7 +539,7 @@ declare class ExpressionEvaluator {
504
539
  };
505
540
  reset(): void;
506
541
  constructor(defaultOptions: ExpressionEvaluatorOptions);
507
- evaluate(expression: ExpressionType, options?: ExpressionEvaluatorOptions): any;
542
+ evaluate(expr: ExpressionType, options?: ExpressionEvaluatorOptions): any;
508
543
  addExpressionFunction<T extends readonly unknown[], R>(name: string, handler: ExpressionHandler<T, R>): void;
509
544
  addBinaryOperator(operator: string, handler: BinaryOperator): void;
510
545
  addUnaryOperator(operator: string, handler: UnaryOperator): void;
@@ -519,6 +554,18 @@ declare class ExpressionEvaluator {
519
554
  declare function withoutContext<T extends unknown[], Return>(fn: (...args: T) => Return): ExpressionHandler<T, Return>;
520
555
  /** Get the node in the expression that's closest to the desired position */
521
556
  declare function findClosestNodeAtPosition(node: ExpressionNode, position: NodePosition): ExpressionNode | undefined;
557
+ /** Checks if the expression is a simple type */
558
+ declare function isObjectExpression(expr: ExpressionType): expr is ExpressionObjectType;
559
+
560
+ /**
561
+ * An expression to AST parser based on JSEP: http://jsep.from.so/
562
+ */
563
+
564
+ /** Parse out an expression from the string */
565
+ declare function parseExpression(expr: string, options?: {
566
+ /** If true (the default), will throw on invalid expressions */
567
+ strict?: boolean;
568
+ }): ExpressionNode;
522
569
 
523
570
  declare type FormatOptions = Omit<Formatting.Reference, 'type'>;
524
571
  /**
@@ -590,6 +637,8 @@ declare class FlowInstance {
590
637
  resolveTransitionNode: SyncWaterfallHook<[NavigationFlowState], Record<string, any>>;
591
638
  /** A callback when a transition from 1 state to another was made */
592
639
  transition: SyncHook<[NamedState | undefined, NamedState], Record<string, any>>;
640
+ /** A callback to run actions after a transition occurs */
641
+ afterTransition: SyncHook<[FlowInstance], Record<string, any>>;
593
642
  };
594
643
  constructor(id: string, flow: NavigationFlow, options?: {
595
644
  /** Logger instance to use */
@@ -757,24 +806,95 @@ declare class Parser {
757
806
  };
758
807
  parseView(value: AnyAssetType): Node.View;
759
808
  createASTNode(node: Node.Node | null, value: any): Node.Node | null;
809
+ /**
810
+ * Checks if there are templated values in the object
811
+ *
812
+ * @param obj - The Parsed Object to check to see if we have a template array type for
813
+ * @param localKey - The key being checked
814
+ */
815
+ private hasTemplateValues;
760
816
  parseObject(obj: object, type?: Node.ChildrenTypes, options?: ParseObjectOptions): Node.Node | null;
761
817
  }
762
818
 
819
+ interface ConstantsProvider {
820
+ /**
821
+ * Function to add constants to the providers store
822
+ * - @param data values to add to the constants store
823
+ */
824
+ addConstants(data: Record<string, any>, namespace: string): void;
825
+ /**
826
+ * Function to retrieve constants from the providers store
827
+ * - @param key Key used for the store access
828
+ * - @param namespace namespace values were loaded under (defined in the plugin)
829
+ * - @param fallback Optional - if key doesn't exist in namespace what to return (will return unknown if not provided)
830
+ */
831
+ getConstants(key: any, namespace: string, fallback?: any): any;
832
+ /**
833
+ * Function to set values to temporarily override certain keys in the perminant store
834
+ * - @param data values to override store with
835
+ * - @param namespace namespace to override
836
+ */
837
+ setTemporaryValues(data: any, namespace: string): void;
838
+ /**
839
+ * Clears any temporary values that were previously set
840
+ */
841
+ clearTemporaryValues(): void;
842
+ }
843
+ /**
844
+ * Key/Value store for constants and context for Player
845
+ */
846
+ declare class ConstantsController implements ConstantsProvider {
847
+ /**
848
+ * Data store is basically a map of namespaces to DataModels to provide some data isolation
849
+ */
850
+ private store;
851
+ /**
852
+ * Separate store for temporary flow specific overrides.
853
+ * They are kept in a separate data model to make clearing it easier between flows
854
+ * and so there is no confusion on what is static and what is temporary
855
+ */
856
+ private tempStore;
857
+ constructor();
858
+ addConstants(data: any, namespace: string): void;
859
+ getConstants(key: string, namespace: string, fallback?: any): any;
860
+ setTemporaryValues(data: any, namespace: string): void;
861
+ clearTemporaryValues(namespace?: string): void;
862
+ }
863
+
864
+ interface ValidationGetResolveOptions {
865
+ /**
866
+ * If we should ignore any non-blocking validations in the return
867
+ * @default true
868
+ */
869
+ ignoreNonBlocking?: boolean;
870
+ }
871
+ interface PlayerUtils {
872
+ findPlugin<Plugin = unknown>(symbol: symbol): Plugin | undefined;
873
+ }
763
874
  declare namespace Resolve {
764
875
  interface Validation {
765
876
  /** Fetch the data-type for the given binding */
766
877
  type(binding: BindingLike): Schema.DataType | undefined;
767
878
  /** Get all currently applicable validation errors */
768
- getAll(): Map<BindingInstance, ValidationResponse> | undefined;
879
+ getAll(options?: ValidationGetResolveOptions): Map<BindingInstance, ValidationResponse> | undefined;
769
880
  /** Internal Method to lookup if there is a validation for the given binding */
770
- _getValidationForBinding(binding: BindingLike): ValidationResponse | undefined;
881
+ _getValidationForBinding(binding: BindingLike): {
882
+ /** Get the validation for the given binding */
883
+ get: (options?: ValidationGetResolveOptions) => ValidationResponse | undefined;
884
+ /** Get all validations for the given binding */
885
+ getAll: (options?: ValidationGetResolveOptions) => Array<ValidationResponse>;
886
+ } | undefined;
771
887
  /** Get field level error for the specific binding */
772
888
  get(binding: BindingLike, options?: {
773
889
  /** If this binding should also be tracked for validations */
774
- track: boolean;
775
- }): ValidationResponse | undefined;
890
+ track?: boolean;
891
+ } & ValidationGetResolveOptions): ValidationResponse | undefined;
892
+ getValidationsForBinding(binding: BindingLike, options?: {
893
+ /** If this binding should also be tracked for validations */
894
+ track?: boolean;
895
+ } & ValidationGetResolveOptions): Array<ValidationResponse>;
776
896
  /** Get errors for all children regardless of section */
777
- getChildren(type: Validation.DisplayTarget): Array<ValidationResponse>;
897
+ getChildren(type?: Validation.DisplayTarget): Array<ValidationResponse>;
778
898
  /** Get errors for all children solely in this section */
779
899
  getValidationsForSection(): Array<ValidationResponse>;
780
900
  /** Track errors for this binding, and notify the node of changes */
@@ -788,6 +908,8 @@ declare namespace Resolve {
788
908
  interface BaseOptions {
789
909
  /** A logger to use */
790
910
  logger?: Logger;
911
+ /** Utils for various useful operations */
912
+ utils?: PlayerUtils;
791
913
  /** An optional set of validation features */
792
914
  validation?: Validation;
793
915
  /** Parse a raw valy into an AST node */
@@ -796,6 +918,8 @@ declare namespace Resolve {
796
918
  transition?: TransitionFunction;
797
919
  /** The hub for data invariants and metaData associated with the data model */
798
920
  schema: SchemaController;
921
+ /** The constants for messages */
922
+ constants?: ConstantsProvider;
799
923
  }
800
924
  interface NodeDataOptions {
801
925
  /** The data to set or get data from */
@@ -922,8 +1046,10 @@ declare class Resolver {
922
1046
  constructor(root: Node.Node, options: Resolve.ResolverOptions);
923
1047
  getSourceNode(convertedAST: Node.Node): Node.Node | undefined;
924
1048
  update(changes?: Set<BindingInstance>): any;
1049
+ getResolveCache(): Map<Node.Node, Resolve.ResolvedNode>;
925
1050
  private getNodeID;
926
1051
  private getPreviousResult;
1052
+ private cloneNode;
927
1053
  private computeTree;
928
1054
  }
929
1055
 
@@ -1056,6 +1182,8 @@ declare class Builder {
1056
1182
  interface BindingTracker {
1057
1183
  /** Get the bindings currently being tracked for validation */
1058
1184
  getBindings(): Set<BindingInstance>;
1185
+ /** Add a binding to the tracked set */
1186
+ trackBinding(binding: BindingInstance): void;
1059
1187
  }
1060
1188
  interface Options$1 {
1061
1189
  /** Parse a binding from a view */
@@ -1073,12 +1201,21 @@ declare class ValidationBindingTrackerViewPlugin implements ViewPlugin, BindingT
1073
1201
  constructor(options: Options$1);
1074
1202
  /** Fetch the tracked bindings in the current view */
1075
1203
  getBindings(): Set<BindingInstance>;
1204
+ /** Add a binding to the tracked set */
1205
+ trackBinding(binding: BindingInstance): void;
1076
1206
  /** Attach hooks to the given resolver */
1077
1207
  applyResolver(resolver: Resolver): void;
1078
1208
  apply(view: ViewInstance): void;
1079
1209
  }
1080
1210
 
1081
- declare type SimpleValidatorContext = Omit<ValidatorContext, 'validation'>;
1211
+ declare const SCHEMA_VALIDATION_PROVIDER_NAME = "schema";
1212
+ declare const VIEW_VALIDATION_PROVIDER_NAME = "view";
1213
+ declare const VALIDATION_PROVIDER_NAME_SYMBOL: unique symbol;
1214
+ declare type ValidationObjectWithSource = ValidationObjectWithHandler & {
1215
+ /** The name of the validation */
1216
+ [VALIDATION_PROVIDER_NAME_SYMBOL]: string;
1217
+ };
1218
+ declare type SimpleValidatorContext = Omit<ValidatorContext, 'validation' | 'schemaType'>;
1082
1219
  interface BaseActiveValidation<T> {
1083
1220
  /** The validation is being actively shown */
1084
1221
  state: 'active';
@@ -1097,7 +1234,9 @@ declare type StatefulWarning = {
1097
1234
  /** A common key to differentiate between errors and warnings */
1098
1235
  type: 'warning';
1099
1236
  /** The underlying validation this tracks */
1100
- value: ValidationObject;
1237
+ value: ValidationObjectWithSource;
1238
+ /** If this is currently preventing navigation from continuing */
1239
+ isBlockingNavigation: boolean;
1101
1240
  } & ({
1102
1241
  /** warnings start with no state, but can active or dismissed */
1103
1242
  state: 'none' | 'dismissed';
@@ -1107,24 +1246,29 @@ declare type StatefulError = {
1107
1246
  /** A common key to differentiate between errors and warnings */
1108
1247
  type: 'error';
1109
1248
  /** The underlying validation this tracks */
1110
- value: ValidationObject;
1249
+ value: ValidationObjectWithSource;
1250
+ /** If this is currently preventing navigation from continuing */
1251
+ isBlockingNavigation: boolean;
1111
1252
  } & ({
1112
1253
  /** Errors start with no state an can be activated */
1113
1254
  state: 'none';
1114
1255
  } | ActiveError);
1115
1256
  declare type StatefulValidationObject = StatefulWarning | StatefulError;
1116
- declare type ValidationRunner = (obj: ValidationObject) => {
1257
+ declare type ValidationRunner = (obj: ValidationObjectWithHandler) => {
1117
1258
  /** A validation message */
1118
1259
  message: string;
1119
1260
  } | undefined;
1120
1261
  /** A class that manages validating bindings across phases */
1121
1262
  declare class ValidatedBinding {
1122
- private currentPhase?;
1263
+ currentPhase?: Validation.Trigger;
1123
1264
  private applicableValidations;
1124
1265
  private validationsByState;
1266
+ get allValidations(): Array<StatefulValidationObject>;
1125
1267
  weakBindings: Set<BindingInstance>;
1126
1268
  private onDismiss?;
1127
- constructor(possibleValidations: Array<ValidationObject>, onDismiss?: () => void, log?: Logger, weakBindings?: Set<BindingInstance>);
1269
+ constructor(possibleValidations: Array<ValidationObjectWithSource>, onDismiss?: () => void, log?: Logger, weakBindings?: Set<BindingInstance>);
1270
+ private checkIfBlocking;
1271
+ getAll(): Array<ValidationResponse>;
1128
1272
  get(): ValidationResponse | undefined;
1129
1273
  private runApplicableValidations;
1130
1274
  update(phase: Validation.Trigger, canDismiss: boolean, runner: ValidationRunner): void;
@@ -1156,27 +1300,42 @@ declare class ValidationController implements BindingTracker {
1156
1300
  onAddValidation: SyncWaterfallHook<[ValidationResponse, BindingInstance], Record<string, any>>;
1157
1301
  /** The inverse of onAddValidation, this is called when a validation is removed from the list */
1158
1302
  onRemoveValidation: SyncWaterfallHook<[ValidationResponse, BindingInstance], Record<string, any>>;
1303
+ resolveValidationProviders: SyncWaterfallHook<[{
1304
+ /** The name of the provider */
1305
+ source: string;
1306
+ /** The provider itself */
1307
+ provider: ValidationProvider;
1308
+ }[]], {
1309
+ /** The view this is triggered for */
1310
+ view?: ViewInstance | undefined;
1311
+ }>;
1312
+ /** A hook called when a binding is added to the tracker */
1313
+ onTrackBinding: SyncHook<[BindingInstance], Record<string, any>>;
1159
1314
  };
1160
1315
  private tracker;
1161
1316
  private validations;
1162
1317
  private validatorRegistry?;
1163
1318
  private schema;
1164
1319
  private providers;
1320
+ private viewValidationProvider?;
1165
1321
  private options?;
1166
1322
  private weakBindingTracker;
1167
- private lastActiveBindings;
1168
1323
  constructor(schema: SchemaController, options?: SimpleValidatorContext);
1169
1324
  setOptions(options: SimpleValidatorContext): void;
1170
1325
  /** Return the middleware for the data-model to stop propagation of invalid data */
1171
1326
  getDataMiddleware(): Array<DataModelMiddleware>;
1327
+ private getValidationProviders;
1328
+ reset(): void;
1172
1329
  onView(view: ViewInstance): void;
1173
- private updateValidationsForBinding;
1174
- private validationRunner;
1330
+ updateValidationsForBinding(binding: BindingInstance, trigger: Validation.Trigger, validationContext?: SimpleValidatorContext, onDismiss?: () => void): void;
1331
+ validationRunner(validationObj: ValidationObjectWithHandler, binding: BindingInstance, context?: SimpleValidatorContext | undefined): {
1332
+ message: string;
1333
+ } | undefined;
1175
1334
  private updateValidationsForView;
1176
- private setCompare;
1177
1335
  private get activeBindings();
1178
1336
  getValidator(type: string): ValidatorFunction<unknown> | undefined;
1179
1337
  getBindings(): Set<BindingInstance>;
1338
+ trackBinding(binding: BindingInstance): void;
1180
1339
  /** Executes all known validations for the tracked bindings using the given model */
1181
1340
  validateView(trigger?: Validation.Trigger): {
1182
1341
  /** Indicating if the view can proceed without error */
@@ -1184,6 +1343,7 @@ declare class ValidationController implements BindingTracker {
1184
1343
  /** the validations that are preventing the view from continuing */
1185
1344
  validations?: Map<BindingInstance, ValidationResponse>;
1186
1345
  };
1346
+ /** Get the current tracked validation for the given binding */
1187
1347
  getValidationForBinding(binding: BindingInstance): ValidatedBinding | undefined;
1188
1348
  forView(parser: BindingFactory): Resolve.Validation;
1189
1349
  }
@@ -1219,6 +1379,16 @@ interface TransformFunctions {
1219
1379
  }
1220
1380
  declare type TransformRegistry = Registry<TransformFunctions>;
1221
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
+
1222
1392
  /** The status for a flow's execution state */
1223
1393
  declare type PlayerFlowStatus = 'not-started' | 'in-progress' | 'completed' | 'error';
1224
1394
  /** Common interface for the state of Player's flow execution */
@@ -1267,8 +1437,11 @@ declare type InProgressState = BaseFlowState<'in-progress'> & PlayerFlowExecutio
1267
1437
  };
1268
1438
  /** The flow completed properly */
1269
1439
  declare type CompletedState = BaseFlowState<'completed'> & PlayerFlowExecutionData & FlowResult & {
1270
- /** The top-level data-model for the flow */
1271
- dataModel: DataModelWithParser;
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
+ };
1272
1445
  };
1273
1446
  /** The flow finished but not successfully */
1274
1447
  declare type ErrorState = BaseFlowState<'error'> & {
@@ -1314,11 +1487,9 @@ declare class DataController implements DataModelWithParser<DataModelOptions> {
1314
1487
  set(transaction: RawSetTransaction, options?: DataModelOptions): Updates;
1315
1488
  private resolve;
1316
1489
  get(binding: BindingLike, options?: DataModelOptions): any;
1317
- delete(binding: BindingLike): void;
1318
- getTrash(): Set<BindingInstance>;
1319
- private addToTrash;
1320
- private deleteData;
1490
+ delete(binding: BindingLike, options?: DataModelOptions): void;
1321
1491
  serialize(): object;
1492
+ makeReadOnly(): ReadOnlyDataController;
1322
1493
  }
1323
1494
 
1324
1495
  interface ViewControllerOptions {
@@ -1365,51 +1536,6 @@ declare class AssetTransformCorePlugin {
1365
1536
  apply(viewController: ViewController): void;
1366
1537
  }
1367
1538
 
1368
- interface ConstantsProvider {
1369
- /**
1370
- * Function to add constants to the providers store
1371
- * - @param data values to add to the constants store
1372
- */
1373
- addConstants(data: Record<string, any>, namespace: string): void;
1374
- /**
1375
- * Function to retreive constants from the providers store
1376
- * - @param key Key used for the store access
1377
- * - @param namespace namespace values were loaded under (defined in the plugin)
1378
- * - @param fallback Optional - if key doesn't exist in namespace what to return (will return unknown if not provided)
1379
- */
1380
- getConstants(key: any, namespace: string, fallback?: any): any;
1381
- /**
1382
- * Function to set values to temporarily override certain keys in the perminant store
1383
- * - @param data values to override store with
1384
- * - @param namespace namespace to override
1385
- */
1386
- setTemporaryValues(data: any, namespace: string): void;
1387
- /**
1388
- * Clears any temporary values that were previously set
1389
- */
1390
- clearTemporaryValues(): void;
1391
- }
1392
- /**
1393
- * Key/Value store for constants and context for Player
1394
- */
1395
- declare class ConstantsController implements ConstantsProvider {
1396
- /**
1397
- * Data store is basically a map of namespaces to DataModels to provide some data isolation
1398
- */
1399
- private store;
1400
- /**
1401
- * Separate store for temporary flow specific overrides.
1402
- * They are kept in a separate data model to make clearing it easier between flows
1403
- * and so there is no confusion on what is static and what is temporary
1404
- */
1405
- private tempStore;
1406
- constructor();
1407
- addConstants(data: any, namespace: string): void;
1408
- getConstants(key: string, namespace: string, fallback?: any): any;
1409
- setTemporaryValues(data: any, namespace: string): void;
1410
- clearTemporaryValues(): void;
1411
- }
1412
-
1413
1539
  interface BaseValidationResponse<T = Validation.Severity> {
1414
1540
  /** The validation message to show to the user */
1415
1541
  message: string;
@@ -1430,9 +1556,13 @@ declare type ErrorValidationResponse = BaseValidationResponse<'error'>;
1430
1556
  declare type ValidationResponse = ErrorValidationResponse | WarningValidationResponse;
1431
1557
  declare type RequiredValidationKeys = 'severity' | 'trigger';
1432
1558
  declare type ValidationObject = Validation.Reference & Required<Pick<Validation.Reference, RequiredValidationKeys>>;
1559
+ declare type ValidationObjectWithHandler = ValidationObject & {
1560
+ /** A predefined handler for this validation object */
1561
+ handler?: ValidatorFunction;
1562
+ };
1433
1563
  interface ValidationProvider {
1434
- getValidationsForBinding?(binding: BindingInstance): Array<ValidationObject> | undefined;
1435
- getValidationsForView?(): Array<ValidationObject> | undefined;
1564
+ getValidationsForBinding?(binding: BindingInstance): Array<ValidationObjectWithHandler> | undefined;
1565
+ getValidationsForView?(): Array<ValidationObjectWithHandler> | undefined;
1436
1566
  }
1437
1567
  interface ValidatorContext {
1438
1568
  /** The data to set or get data from */
@@ -1447,6 +1577,8 @@ interface ValidatorContext {
1447
1577
  validation: ValidationObject;
1448
1578
  /** The constants for messages */
1449
1579
  constants: ConstantsProvider;
1580
+ /** The type in the schema that triggered the validation if there is one */
1581
+ schemaType: Schema.DataType | undefined;
1450
1582
  }
1451
1583
  declare type ValidatorFunction<Options = unknown> = (context: ValidatorContext, value: any, options?: Options) => Omit<BaseValidationResponse, 'severity'> | undefined;
1452
1584
 
@@ -1470,12 +1602,16 @@ declare class ValidationMiddleware implements DataModelMiddleware {
1470
1602
  validator: MiddlewareChecker;
1471
1603
  shadowModelPaths: Map<BindingInstance, any>;
1472
1604
  private logger?;
1605
+ private shouldIncludeInvalid?;
1473
1606
  constructor(validator: MiddlewareChecker, options?: {
1474
1607
  /** A logger instance */
1475
1608
  logger?: Logger;
1609
+ /** Optional function to include data staged in shadowModel */
1610
+ shouldIncludeInvalid?: (options?: DataModelOptions) => boolean;
1476
1611
  });
1477
1612
  set(transaction: BatchSetTransaction, options?: DataModelOptions, next?: DataModelImpl): Updates;
1478
1613
  get(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): any;
1614
+ delete(binding: BindingInstance, options?: DataModelOptions, next?: DataModelImpl): void | undefined;
1479
1615
  }
1480
1616
 
1481
1617
  /** A registry that tracks validators */
@@ -1488,8 +1624,17 @@ declare class ValidatorRegistry {
1488
1624
  register<T>(name: string, handler: ValidatorFunction<T>): void;
1489
1625
  }
1490
1626
 
1627
+ /**
1628
+ * Remove a binding, and any children from from the map
1629
+ * If the binding is an array-item, then it will be spliced from the array and the others will be shifted down
1630
+ *
1631
+ * @param sourceMap - A map of bindings to values
1632
+ * @param binding - The binding to remove from the map
1633
+ */
1634
+ declare function removeBindingAndChildrenFromMap<T>(sourceMap: Map<BindingInstance, T>, binding: BindingInstance): Map<BindingInstance, T>;
1635
+
1491
1636
  /** Expand the authored schema into a set of paths -> DataTypes */
1492
- declare function parse(schema: Schema.Schema): Map<string, Schema.DataType>;
1637
+ declare function parse(schema: Schema.Schema): Map<string, Schema.DataTypes>;
1493
1638
  /**
1494
1639
  * The Schema is the central hub for all data invariants, and metaData associated with the data-model itself
1495
1640
  * Outside of the types defined in the JSON payload, it doesn't manage or keep any state.
@@ -1498,18 +1643,18 @@ declare function parse(schema: Schema.Schema): Map<string, Schema.DataType>;
1498
1643
  declare class SchemaController implements ValidationProvider {
1499
1644
  private formatters;
1500
1645
  private types;
1501
- readonly schema: Map<string, Schema.DataType>;
1646
+ readonly schema: Map<string, Schema.DataTypes>;
1502
1647
  private bindingSchemaNormalizedCache;
1503
1648
  readonly hooks: {
1504
- resolveTypeForBinding: SyncWaterfallHook<[Schema.DataType<unknown> | undefined, BindingInstance], Record<string, any>>;
1649
+ resolveTypeForBinding: SyncWaterfallHook<[Schema.DataTypes | undefined, BindingInstance], Record<string, any>>;
1505
1650
  };
1506
1651
  constructor(schema?: Schema.Schema);
1507
1652
  addFormatters(fns: Array<FormatType<any, any, FormatOptions>>): void;
1508
1653
  addDataTypes(types: Array<Schema.DataType<any>>): void;
1509
1654
  getValidationsForBinding(binding: BindingInstance): Array<ValidationObject> | undefined;
1510
1655
  private normalizeBinding;
1511
- getType(binding: BindingInstance): Schema.DataType | undefined;
1512
- getApparentType(binding: BindingInstance): Schema.DataType | undefined;
1656
+ getType(binding: BindingInstance): Schema.DataTypes | undefined;
1657
+ getApparentType(binding: BindingInstance): Schema.DataTypes | undefined;
1513
1658
  getTypeDefinition(dataType: string): Schema.DataType<any> | undefined;
1514
1659
  getFormatterForType(formatReference: Formatting.Reference): FormatDefinition<unknown, unknown> | undefined;
1515
1660
  /**
@@ -1520,10 +1665,20 @@ declare class SchemaController implements ValidationProvider {
1520
1665
  }
1521
1666
 
1522
1667
  interface Options {
1523
- /** The model to use when resolving refs */
1524
- model: DataModelWithParser;
1525
- /** A function to evaluate an expression */
1526
- evaluate: (exp: Expression) => any;
1668
+ /**
1669
+ * The model to use when resolving refs
1670
+ * Passing `false` will skip trying to resolve any direct model refs ({{foo}})
1671
+ */
1672
+ model: false | DataModelWithParser;
1673
+ /**
1674
+ * A function to evaluate an expression
1675
+ * Passing `false` will skip trying to evaluate any expressions (@[ foo() ]@)
1676
+ */
1677
+ evaluate: false | ((exp: Expression) => any);
1678
+ /**
1679
+ * Optionaly resolve binding without formatting in case Type format applies
1680
+ */
1681
+ formatted?: boolean;
1527
1682
  }
1528
1683
  /** Search the given string for the coordinates of the next expression to resolve */
1529
1684
  declare function findNextExp(str: string): {
@@ -1550,6 +1705,8 @@ interface PlayerPlugin {
1550
1705
  */
1551
1706
  apply: (player: Player) => void;
1552
1707
  }
1708
+ interface ExtendedPlayerPlugin<Assets = void, Views = void, Expressions = void, DataTypes = void> {
1709
+ }
1553
1710
  interface PlayerConfigOptions {
1554
1711
  /** A set of plugins to load */
1555
1712
  plugins?: PlayerPlugin[];
@@ -1636,4 +1793,4 @@ declare class FlowExpPlugin implements PlayerPlugin {
1636
1793
  apply(player: Player): void;
1637
1794
  }
1638
1795
 
1639
- export { AnyAssetType, ApplicabilityPlugin, ArrayExpressionNode, AssetTransformCorePlugin, AssignmentNode, BaseFlowState, BaseNode, 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, ExpressionType, 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, ProxyLogger, ROOT_BINDING, RawBinding, RawBindingSegment, RawSetTransaction, RawSetType, Resolve, Resolver, SIMPLE_BINDING_REGEX, SchemaController, Severity, StatefulValidationObject, Store, StringResolverPlugin, StrongOrWeakBinding, SwitchPlugin, TapableLogger, TemplatePlugin, ThisNode, TransformFunction, TransformFunctions, TransformRegistry, TransitionFunction, TransitionOptions, UnaryNode, UnaryOperator, Updates, ValidationBindingTrackerViewPlugin, ValidationController, ValidationMiddleware, ValidationObject, ValidationProvider, ValidationResponse, ValidatorContext, ValidatorFunction, ValidatorRegistry, ViewController, ViewControllerOptions, ViewInstance, ViewPlugin, WarningValidationResponse, caresAboutDataChanges, constructModelForPipeline, findClosestNodeAtPosition, findInArray, findNextExp, getBindingSegments, isBinding, isExpressionNode, maybeConvertToNum, parse, 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 };