@player-ui/types-provider-plugin 0.8.0--canary.307.9621 → 0.8.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,158 @@
1
+ "use strict";
2
+ function _array_like_to_array(arr, len) {
3
+ if (len == null || len > arr.length) len = arr.length;
4
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
+ return arr2;
6
+ }
7
+ function _array_with_holes(arr) {
8
+ if (Array.isArray(arr)) return arr;
9
+ }
10
+ function _class_call_check(instance, Constructor) {
11
+ if (!(instance instanceof Constructor)) {
12
+ throw new TypeError("Cannot call a class as a function");
13
+ }
14
+ }
15
+ function _defineProperties(target, props) {
16
+ for(var i = 0; i < props.length; i++){
17
+ var descriptor = props[i];
18
+ descriptor.enumerable = descriptor.enumerable || false;
19
+ descriptor.configurable = true;
20
+ if ("value" in descriptor) descriptor.writable = true;
21
+ Object.defineProperty(target, descriptor.key, descriptor);
22
+ }
23
+ }
24
+ function _create_class(Constructor, protoProps, staticProps) {
25
+ if (protoProps) _defineProperties(Constructor.prototype, protoProps);
26
+ if (staticProps) _defineProperties(Constructor, staticProps);
27
+ return Constructor;
28
+ }
29
+ function _iterable_to_array_limit(arr, i) {
30
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
31
+ if (_i == null) return;
32
+ var _arr = [];
33
+ var _n = true;
34
+ var _d = false;
35
+ var _s, _e;
36
+ try {
37
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
38
+ _arr.push(_s.value);
39
+ if (i && _arr.length === i) break;
40
+ }
41
+ } catch (err) {
42
+ _d = true;
43
+ _e = err;
44
+ } finally{
45
+ try {
46
+ if (!_n && _i["return"] != null) _i["return"]();
47
+ } finally{
48
+ if (_d) throw _e;
49
+ }
50
+ }
51
+ return _arr;
52
+ }
53
+ function _non_iterable_rest() {
54
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
55
+ }
56
+ function _sliced_to_array(arr, i) {
57
+ return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
58
+ }
59
+ function _unsupported_iterable_to_array(o, minLen) {
60
+ if (!o) return;
61
+ if (typeof o === "string") return _array_like_to_array(o, minLen);
62
+ var n = Object.prototype.toString.call(o).slice(8, -1);
63
+ if (n === "Object" && o.constructor) n = o.constructor.name;
64
+ if (n === "Map" || n === "Set") return Array.from(n);
65
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
66
+ }
67
+ var TypesProviderPlugin = function() {
68
+ var __defProp = Object.defineProperty;
69
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
70
+ var __getOwnPropNames = Object.getOwnPropertyNames;
71
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
72
+ var __export = function(target, all) {
73
+ for(var name in all)__defProp(target, name, {
74
+ get: all[name],
75
+ enumerable: true
76
+ });
77
+ };
78
+ var __copyProps = function(to, from, except, desc) {
79
+ if (from && typeof from === "object" || typeof from === "function") {
80
+ var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined;
81
+ try {
82
+ var _loop = function() {
83
+ var key = _step.value;
84
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
85
+ get: function() {
86
+ return from[key];
87
+ },
88
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
89
+ });
90
+ };
91
+ for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop();
92
+ } catch (err) {
93
+ _didIteratorError = true;
94
+ _iteratorError = err;
95
+ } finally{
96
+ try {
97
+ if (!_iteratorNormalCompletion && _iterator.return != null) {
98
+ _iterator.return();
99
+ }
100
+ } finally{
101
+ if (_didIteratorError) {
102
+ throw _iteratorError;
103
+ }
104
+ }
105
+ }
106
+ }
107
+ return to;
108
+ };
109
+ var __toCommonJS = function(mod) {
110
+ return __copyProps(__defProp({}, "__esModule", {
111
+ value: true
112
+ }), mod);
113
+ };
114
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts
115
+ var src_exports = {};
116
+ __export(src_exports, {
117
+ TypesProviderPlugin: function() {
118
+ return TypesProviderPlugin;
119
+ }
120
+ });
121
+ var TypesProviderPlugin = /*#__PURE__*/ function() {
122
+ function TypesProviderPlugin(config) {
123
+ _class_call_check(this, TypesProviderPlugin);
124
+ this.name = "TypesProviderPlugin";
125
+ this.config = config;
126
+ }
127
+ _create_class(TypesProviderPlugin, [
128
+ {
129
+ key: "apply",
130
+ value: function apply(player) {
131
+ var _this = this;
132
+ player.hooks.schema.tap(this.name, function(schema) {
133
+ if (_this.config.types) {
134
+ schema.addDataTypes(_this.config.types);
135
+ }
136
+ if (_this.config.formats) {
137
+ schema.addFormatters(_this.config.formats);
138
+ }
139
+ });
140
+ if (this.config.validators) {
141
+ player.hooks.validationController.tap(this.name, function(validationController) {
142
+ validationController.hooks.createValidatorRegistry.tap(_this.name, function(validationRegistry) {
143
+ var _this_config_validators;
144
+ (_this_config_validators = _this.config.validators) === null || _this_config_validators === void 0 ? void 0 : _this_config_validators.forEach(function(param) {
145
+ var _param = _sliced_to_array(param, 2), name = _param[0], handler = _param[1];
146
+ validationRegistry.register(name, handler);
147
+ });
148
+ });
149
+ });
150
+ }
151
+ }
152
+ }
153
+ ]);
154
+ return TypesProviderPlugin;
155
+ }();
156
+ return __toCommonJS(src_exports);
157
+ }();
158
+ //# sourceMappingURL=index.global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AA4BO,MAAM,sBAAN,MAAkD;AAAA,IAKvD,YAAY,QAAqB;AAJjC,kBAAO;AAKL,WAAK,SAAS;AAAA,IAChB;AAAA,IAEA,MAAM,QAAgB;AACpB,aAAO,MAAM,OAAO,IAAI,KAAK,MAAM,CAAC,WAAW;AAC7C,YAAI,KAAK,OAAO,OAAO;AACrB,iBAAO,aAAa,KAAK,OAAO,KAAK;AAAA,QACvC;AAEA,YAAI,KAAK,OAAO,SAAS;AACvB,iBAAO,cAAc,KAAK,OAAO,OAAO;AAAA,QAC1C;AAAA,MACF,CAAC;AAED,UAAI,KAAK,OAAO,YAAY;AAC1B,eAAO,MAAM,qBAAqB;AAAA,UAChC,KAAK;AAAA,UACL,CAAC,yBAAyB;AACxB,iCAAqB,MAAM,wBAAwB;AAAA,cACjD,KAAK;AAAA,cACL,CAAC,uBAAuB;AACtB,qBAAK,OAAO,YAAY,QAAQ,CAAC,CAAC,MAAM,OAAO,MAAM;AACnD,qCAAmB,SAAS,MAAM,OAAO;AAAA,gBAC3C,CAAC;AAAA,cACH;AAAA,YACF;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF","sourcesContent":["import type {\n Player,\n PlayerPlugin,\n ValidatorFunction,\n FormatType,\n Schema,\n} from \"@player-ui/player\";\n\nexport interface TypesConfig {\n /**\n * DataTypes to expose to Player instance.\n * The schema definition in authored content can reference these to get common functionality across types\n */\n types?: Array<Schema.DataType<any>>;\n\n /**\n * Custom validators to add to this player instance.\n * Anything defined here will be available for use in any DataType or view-validation\n */\n validators?: Array<[string, ValidatorFunction<any>]>;\n\n /** A list of formats (and handler functions) to expose to DataTypes */\n formats?: Array<FormatType<any, any, any>>;\n}\n\n/**\n * The TypesProvider plugin provides an easy way for users to expose custom validators, DataTypes, or formatters to the content\n */\nexport class TypesProviderPlugin implements PlayerPlugin {\n name = \"TypesProviderPlugin\";\n\n private config: TypesConfig;\n\n constructor(config: TypesConfig) {\n this.config = config;\n }\n\n apply(player: Player) {\n player.hooks.schema.tap(this.name, (schema) => {\n if (this.config.types) {\n schema.addDataTypes(this.config.types);\n }\n\n if (this.config.formats) {\n schema.addFormatters(this.config.formats);\n }\n });\n\n if (this.config.validators) {\n player.hooks.validationController.tap(\n this.name,\n (validationController) => {\n validationController.hooks.createValidatorRegistry.tap(\n this.name,\n (validationRegistry) => {\n this.config.validators?.forEach(([name, handler]) => {\n validationRegistry.register(name, handler);\n });\n },\n );\n },\n );\n }\n }\n}\n"]}
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts
21
+ var src_exports = {};
22
+ __export(src_exports, {
23
+ TypesProviderPlugin: () => TypesProviderPlugin
24
+ });
25
+ module.exports = __toCommonJS(src_exports);
26
+ var TypesProviderPlugin = class {
27
+ constructor(config) {
28
+ this.name = "TypesProviderPlugin";
29
+ this.config = config;
30
+ }
31
+ apply(player) {
32
+ player.hooks.schema.tap(this.name, (schema) => {
33
+ if (this.config.types) {
34
+ schema.addDataTypes(this.config.types);
35
+ }
36
+ if (this.config.formats) {
37
+ schema.addFormatters(this.config.formats);
38
+ }
39
+ });
40
+ if (this.config.validators) {
41
+ player.hooks.validationController.tap(
42
+ this.name,
43
+ (validationController) => {
44
+ validationController.hooks.createValidatorRegistry.tap(
45
+ this.name,
46
+ (validationRegistry) => {
47
+ this.config.validators?.forEach(([name, handler]) => {
48
+ validationRegistry.register(name, handler);
49
+ });
50
+ }
51
+ );
52
+ }
53
+ );
54
+ }
55
+ }
56
+ };
57
+ // Annotate the CommonJS export names for ESM import in node:
58
+ 0 && (module.exports = {
59
+ TypesProviderPlugin
60
+ });
61
+ //# sourceMappingURL=index.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts"],"sourcesContent":["import type {\n Player,\n PlayerPlugin,\n ValidatorFunction,\n FormatType,\n Schema,\n} from \"@player-ui/player\";\n\nexport interface TypesConfig {\n /**\n * DataTypes to expose to Player instance.\n * The schema definition in authored content can reference these to get common functionality across types\n */\n types?: Array<Schema.DataType<any>>;\n\n /**\n * Custom validators to add to this player instance.\n * Anything defined here will be available for use in any DataType or view-validation\n */\n validators?: Array<[string, ValidatorFunction<any>]>;\n\n /** A list of formats (and handler functions) to expose to DataTypes */\n formats?: Array<FormatType<any, any, any>>;\n}\n\n/**\n * The TypesProvider plugin provides an easy way for users to expose custom validators, DataTypes, or formatters to the content\n */\nexport class TypesProviderPlugin implements PlayerPlugin {\n name = \"TypesProviderPlugin\";\n\n private config: TypesConfig;\n\n constructor(config: TypesConfig) {\n this.config = config;\n }\n\n apply(player: Player) {\n player.hooks.schema.tap(this.name, (schema) => {\n if (this.config.types) {\n schema.addDataTypes(this.config.types);\n }\n\n if (this.config.formats) {\n schema.addFormatters(this.config.formats);\n }\n });\n\n if (this.config.validators) {\n player.hooks.validationController.tap(\n this.name,\n (validationController) => {\n validationController.hooks.createValidatorRegistry.tap(\n this.name,\n (validationRegistry) => {\n this.config.validators?.forEach(([name, handler]) => {\n validationRegistry.register(name, handler);\n });\n },\n );\n },\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA4BO,IAAM,sBAAN,MAAkD;AAAA,EAKvD,YAAY,QAAqB;AAJjC,gBAAO;AAKL,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,QAAgB;AACpB,WAAO,MAAM,OAAO,IAAI,KAAK,MAAM,CAAC,WAAW;AAC7C,UAAI,KAAK,OAAO,OAAO;AACrB,eAAO,aAAa,KAAK,OAAO,KAAK;AAAA,MACvC;AAEA,UAAI,KAAK,OAAO,SAAS;AACvB,eAAO,cAAc,KAAK,OAAO,OAAO;AAAA,MAC1C;AAAA,IACF,CAAC;AAED,QAAI,KAAK,OAAO,YAAY;AAC1B,aAAO,MAAM,qBAAqB;AAAA,QAChC,KAAK;AAAA,QACL,CAAC,yBAAyB;AACxB,+BAAqB,MAAM,wBAAwB;AAAA,YACjD,KAAK;AAAA,YACL,CAAC,uBAAuB;AACtB,mBAAK,OAAO,YAAY,QAAQ,CAAC,CAAC,MAAM,OAAO,MAAM;AACnD,mCAAmB,SAAS,MAAM,OAAO;AAAA,cAC3C,CAAC;AAAA,YACH;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
@@ -0,0 +1,36 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts
2
+ var TypesProviderPlugin = class {
3
+ constructor(config) {
4
+ this.name = "TypesProviderPlugin";
5
+ this.config = config;
6
+ }
7
+ apply(player) {
8
+ player.hooks.schema.tap(this.name, (schema) => {
9
+ if (this.config.types) {
10
+ schema.addDataTypes(this.config.types);
11
+ }
12
+ if (this.config.formats) {
13
+ schema.addFormatters(this.config.formats);
14
+ }
15
+ });
16
+ if (this.config.validators) {
17
+ player.hooks.validationController.tap(
18
+ this.name,
19
+ (validationController) => {
20
+ validationController.hooks.createValidatorRegistry.tap(
21
+ this.name,
22
+ (validationRegistry) => {
23
+ this.config.validators?.forEach(([name, handler]) => {
24
+ validationRegistry.register(name, handler);
25
+ });
26
+ }
27
+ );
28
+ }
29
+ );
30
+ }
31
+ }
32
+ };
33
+ export {
34
+ TypesProviderPlugin
35
+ };
36
+ //# sourceMappingURL=index.mjs.map
package/dist/index.mjs ADDED
@@ -0,0 +1,36 @@
1
+ // ../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts
2
+ var TypesProviderPlugin = class {
3
+ constructor(config) {
4
+ this.name = "TypesProviderPlugin";
5
+ this.config = config;
6
+ }
7
+ apply(player) {
8
+ player.hooks.schema.tap(this.name, (schema) => {
9
+ if (this.config.types) {
10
+ schema.addDataTypes(this.config.types);
11
+ }
12
+ if (this.config.formats) {
13
+ schema.addFormatters(this.config.formats);
14
+ }
15
+ });
16
+ if (this.config.validators) {
17
+ player.hooks.validationController.tap(
18
+ this.name,
19
+ (validationController) => {
20
+ validationController.hooks.createValidatorRegistry.tap(
21
+ this.name,
22
+ (validationRegistry) => {
23
+ this.config.validators?.forEach(([name, handler]) => {
24
+ validationRegistry.register(name, handler);
25
+ });
26
+ }
27
+ );
28
+ }
29
+ );
30
+ }
31
+ }
32
+ };
33
+ export {
34
+ TypesProviderPlugin
35
+ };
36
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../../../../../execroot/_main/bazel-out/k8-fastbuild/bin/plugins/types-provider/core/src/index.ts"],"sourcesContent":["import type {\n Player,\n PlayerPlugin,\n ValidatorFunction,\n FormatType,\n Schema,\n} from \"@player-ui/player\";\n\nexport interface TypesConfig {\n /**\n * DataTypes to expose to Player instance.\n * The schema definition in authored content can reference these to get common functionality across types\n */\n types?: Array<Schema.DataType<any>>;\n\n /**\n * Custom validators to add to this player instance.\n * Anything defined here will be available for use in any DataType or view-validation\n */\n validators?: Array<[string, ValidatorFunction<any>]>;\n\n /** A list of formats (and handler functions) to expose to DataTypes */\n formats?: Array<FormatType<any, any, any>>;\n}\n\n/**\n * The TypesProvider plugin provides an easy way for users to expose custom validators, DataTypes, or formatters to the content\n */\nexport class TypesProviderPlugin implements PlayerPlugin {\n name = \"TypesProviderPlugin\";\n\n private config: TypesConfig;\n\n constructor(config: TypesConfig) {\n this.config = config;\n }\n\n apply(player: Player) {\n player.hooks.schema.tap(this.name, (schema) => {\n if (this.config.types) {\n schema.addDataTypes(this.config.types);\n }\n\n if (this.config.formats) {\n schema.addFormatters(this.config.formats);\n }\n });\n\n if (this.config.validators) {\n player.hooks.validationController.tap(\n this.name,\n (validationController) => {\n validationController.hooks.createValidatorRegistry.tap(\n this.name,\n (validationRegistry) => {\n this.config.validators?.forEach(([name, handler]) => {\n validationRegistry.register(name, handler);\n });\n },\n );\n },\n );\n }\n }\n}\n"],"mappings":";AA4BO,IAAM,sBAAN,MAAkD;AAAA,EAKvD,YAAY,QAAqB;AAJjC,gBAAO;AAKL,SAAK,SAAS;AAAA,EAChB;AAAA,EAEA,MAAM,QAAgB;AACpB,WAAO,MAAM,OAAO,IAAI,KAAK,MAAM,CAAC,WAAW;AAC7C,UAAI,KAAK,OAAO,OAAO;AACrB,eAAO,aAAa,KAAK,OAAO,KAAK;AAAA,MACvC;AAEA,UAAI,KAAK,OAAO,SAAS;AACvB,eAAO,cAAc,KAAK,OAAO,OAAO;AAAA,MAC1C;AAAA,IACF,CAAC;AAED,QAAI,KAAK,OAAO,YAAY;AAC1B,aAAO,MAAM,qBAAqB;AAAA,QAChC,KAAK;AAAA,QACL,CAAC,yBAAyB;AACxB,+BAAqB,MAAM,wBAAwB;AAAA,YACjD,KAAK;AAAA,YACL,CAAC,uBAAuB;AACtB,mBAAK,OAAO,YAAY,QAAQ,CAAC,CAAC,MAAM,OAAO,MAAM;AACnD,mCAAmB,SAAS,MAAM,OAAO;AAAA,cAC3C,CAAC;AAAA,YACH;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;","names":[]}
package/package.json CHANGED
@@ -1,67 +1,35 @@
1
1
  {
2
2
  "name": "@player-ui/types-provider-plugin",
3
- "version": "0.8.0--canary.307.9621",
4
- "private": false,
5
- "publishConfig": {
6
- "registry": "https://registry.npmjs.org"
7
- },
3
+ "version": "0.8.0-next.0",
4
+ "main": "dist/cjs/index.cjs",
8
5
  "peerDependencies": {
9
- "@player-ui/player": "0.8.0--canary.307.9621"
6
+ "@player-ui/player": "0.8.0-next.0"
10
7
  },
11
- "dependencies": {
12
- "tapable-ts": "^0.2.3",
13
- "@babel/runtime": "7.15.4"
8
+ "devDependencies": {
9
+ "@player-ui/partial-match-registry": "workspace:*",
10
+ "@player-ui/asset-transform-plugin": "workspace:*",
11
+ "@player-ui/make-flow": "workspace:*"
14
12
  },
15
- "main": "dist/index.cjs.js",
16
- "module": "dist/index.esm.js",
17
- "typings": "dist/index.d.ts",
13
+ "module": "dist/index.legacy-esm.js",
14
+ "types": "types/index.d.ts",
15
+ "bundle": "dist/TypesProviderPlugin.native.js",
18
16
  "sideEffects": false,
19
- "license": "MIT",
20
- "repository": {
21
- "type": "git",
22
- "url": "https://github.com/player-ui/player-ui"
23
- },
24
- "bugs": {
25
- "url": "https://github.com/player-ui/player-ui/issues"
26
- },
27
- "homepage": "https://player-ui.github.io",
28
- "contributors": [
29
- {
30
- "name": "Adam Dierkens",
31
- "url": "https://github.com/adierkens"
32
- },
33
- {
34
- "name": "Spencer Hamm",
35
- "url": "https://github.com/spentacular"
36
- },
37
- {
38
- "name": "Harris Borawski",
39
- "url": "https://github.com/hborawski"
40
- },
41
- {
42
- "name": "Jeremiah Zucker",
43
- "url": "https://github.com/sugarmanz"
44
- },
45
- {
46
- "name": "Ketan Reddy",
47
- "url": "https://github.com/KetanReddy"
48
- },
49
- {
50
- "name": "Brocollie08",
51
- "url": "https://github.com/brocollie08"
52
- },
53
- {
54
- "name": "Kelly Harrop",
55
- "url": "https://github.com/kharrop"
56
- },
57
- {
58
- "name": "Alejandro Fimbres",
59
- "url": "https://github.com/lexfm"
60
- },
61
- {
62
- "name": "Rafael Campos",
63
- "url": "https://github.com/rafbcampos"
17
+ "exports": {
18
+ "./package.json": "./package.json",
19
+ "./dist/index.css": "./dist/index.css",
20
+ ".": {
21
+ "types": "./types/index.d.ts",
22
+ "import": "./dist/index.mjs",
23
+ "default": "./dist/cjs/index.cjs"
64
24
  }
25
+ },
26
+ "files": [
27
+ "dist",
28
+ "src",
29
+ "types"
65
30
  ],
66
- "bundle": "./dist/types-provider-plugin.prod.js"
31
+ "dependencies": {
32
+ "tapable-ts": "^0.2.3",
33
+ "tslib": "^2.6.2"
34
+ }
67
35
  }
@@ -0,0 +1,191 @@
1
+ import { expect, test, describe, vitest } from "vitest";
2
+ import type { InProgressState, Flow, FormatType } from "@player-ui/player";
3
+ import { Player } from "@player-ui/player";
4
+ import { makeFlow } from "@player-ui/make-flow";
5
+ import { Registry } from "@player-ui/partial-match-registry";
6
+ import { AssetTransformPlugin } from "@player-ui/asset-transform-plugin";
7
+ import { TypesProviderPlugin } from "..";
8
+
9
+ const inputTransformPlugin = new AssetTransformPlugin(
10
+ new Registry([
11
+ [
12
+ { type: "input" },
13
+ (value, options) => {
14
+ return {
15
+ ...value,
16
+ validation: options.validation?.get(value.binding, { track: true }),
17
+ dataType: options.validation?.type(value.binding)?.type,
18
+ set: (val: any) => {
19
+ options.data.model.set([[value.binding, val]]);
20
+ },
21
+ };
22
+ },
23
+ ],
24
+ ]),
25
+ );
26
+
27
+ test("adds custom types", async () => {
28
+ const flowWithCustomTypes = makeFlow({
29
+ id: "view-1",
30
+ type: "input",
31
+ binding: "foo.bar",
32
+ });
33
+
34
+ flowWithCustomTypes.schema = {
35
+ ROOT: {
36
+ foo: {
37
+ type: "FooType",
38
+ },
39
+ },
40
+ FooType: {
41
+ bar: {
42
+ type: "CustomType",
43
+ },
44
+ },
45
+ };
46
+
47
+ const player = new Player({
48
+ plugins: [
49
+ inputTransformPlugin,
50
+ new TypesProviderPlugin({
51
+ types: [
52
+ {
53
+ type: "CustomType",
54
+ validation: [
55
+ {
56
+ type: "customValidation",
57
+ props: "stuff",
58
+ },
59
+ ],
60
+ },
61
+ ],
62
+ validators: [
63
+ [
64
+ "customValidation",
65
+ (context, value, options) => {
66
+ if (value !== options.props) {
67
+ return {
68
+ message: "thats not good",
69
+ };
70
+ }
71
+ },
72
+ ],
73
+ ],
74
+ }),
75
+ ],
76
+ });
77
+ player.start(flowWithCustomTypes);
78
+
79
+ const getLastUpdate = () =>
80
+ (player.getState() as InProgressState).controllers.view.currentView
81
+ ?.lastUpdate;
82
+
83
+ let input = getLastUpdate();
84
+ expect(input?.dataType).toBe("CustomType");
85
+
86
+ input?.set("not right");
87
+
88
+ await vitest.waitFor(() => {
89
+ input = getLastUpdate();
90
+ expect(input?.validation.message).toBe("thats not good");
91
+ });
92
+
93
+ input?.set("stuff");
94
+
95
+ await vitest.waitFor(() => {
96
+ input = getLastUpdate();
97
+ expect(input?.validation).toBe(undefined);
98
+ });
99
+ });
100
+
101
+ describe("formatting", () => {
102
+ const flowWithDataTypes: Flow = {
103
+ id: "tst",
104
+ views: [],
105
+ schema: {
106
+ ROOT: {
107
+ foo: {
108
+ type: "NumberType",
109
+ },
110
+ },
111
+ NumberType: {
112
+ num: {
113
+ type: "BaseType",
114
+ format: {
115
+ type: "number",
116
+ decimalPlaces: 2,
117
+ },
118
+ default: 500,
119
+ },
120
+ },
121
+ },
122
+ navigation: {
123
+ BEGIN: "FLOW_1",
124
+ FLOW_1: {
125
+ startState: "EXT_1",
126
+ EXT_1: {
127
+ state_type: "EXTERNAL",
128
+ ref: "wait",
129
+ transitions: {},
130
+ },
131
+ },
132
+ },
133
+ };
134
+
135
+ /** Quick formatter for a number -> string */
136
+ const numberFormat: FormatType<
137
+ number,
138
+ string,
139
+ {
140
+ /** number of decimal place to preserve when converting to a string */
141
+ decimalPlaces: number;
142
+ }
143
+ > = {
144
+ name: "number",
145
+ format(val, options) {
146
+ return typeof val === "string"
147
+ ? val
148
+ : val.toFixed(options?.decimalPlaces);
149
+ },
150
+ deformat(val) {
151
+ return typeof val === "string" ? parseFloat(val) : val;
152
+ },
153
+ };
154
+
155
+ test("it formats things", () => {
156
+ const player = new Player({
157
+ plugins: [
158
+ new TypesProviderPlugin({
159
+ formats: [numberFormat],
160
+ }),
161
+ ],
162
+ });
163
+
164
+ player.start({
165
+ ...flowWithDataTypes,
166
+ data: { foo: { num: 500 } },
167
+ });
168
+ const state = player.getState() as InProgressState;
169
+
170
+ expect(
171
+ state.controllers.data.get("foo.num", { formatted: true }),
172
+ ).toStrictEqual("500.00");
173
+ });
174
+
175
+ test("it formats things with default types", () => {
176
+ const player = new Player({
177
+ plugins: [
178
+ new TypesProviderPlugin({
179
+ formats: [numberFormat],
180
+ }),
181
+ ],
182
+ });
183
+
184
+ player.start(flowWithDataTypes);
185
+ const state = player.getState() as InProgressState;
186
+
187
+ expect(
188
+ state.controllers.data.get("foo.num", { formatted: true }),
189
+ ).toStrictEqual("500.00");
190
+ });
191
+ });
package/src/index.ts CHANGED
@@ -3,8 +3,8 @@ import type {
3
3
  PlayerPlugin,
4
4
  ValidatorFunction,
5
5
  FormatType,
6
- } from '@player-ui/player';
7
- import type { Schema } from '@player-ui/types';
6
+ Schema,
7
+ } from "@player-ui/player";
8
8
 
9
9
  export interface TypesConfig {
10
10
  /**
@@ -27,7 +27,7 @@ export interface TypesConfig {
27
27
  * The TypesProvider plugin provides an easy way for users to expose custom validators, DataTypes, or formatters to the content
28
28
  */
29
29
  export class TypesProviderPlugin implements PlayerPlugin {
30
- name = 'TypesProviderPlugin';
30
+ name = "TypesProviderPlugin";
31
31
 
32
32
  private config: TypesConfig;
33
33
 
@@ -56,9 +56,9 @@ export class TypesProviderPlugin implements PlayerPlugin {
56
56
  this.config.validators?.forEach(([name, handler]) => {
57
57
  validationRegistry.register(name, handler);
58
58
  });
59
- }
59
+ },
60
60
  );
61
- }
61
+ },
62
62
  );
63
63
  }
64
64
  }
@@ -1,7 +1,5 @@
1
- import { ValidatorFunction, FormatType, PlayerPlugin, Player } from '@player-ui/player';
2
- import { Schema } from '@player-ui/types';
3
-
4
- interface TypesConfig {
1
+ import type { Player, PlayerPlugin, ValidatorFunction, FormatType, Schema } from "@player-ui/player";
2
+ export interface TypesConfig {
5
3
  /**
6
4
  * DataTypes to expose to Player instance.
7
5
  * The schema definition in authored content can reference these to get common functionality across types
@@ -18,11 +16,10 @@ interface TypesConfig {
18
16
  /**
19
17
  * The TypesProvider plugin provides an easy way for users to expose custom validators, DataTypes, or formatters to the content
20
18
  */
21
- declare class TypesProviderPlugin implements PlayerPlugin {
19
+ export declare class TypesProviderPlugin implements PlayerPlugin {
22
20
  name: string;
23
21
  private config;
24
22
  constructor(config: TypesConfig);
25
23
  apply(player: Player): void;
26
24
  }
27
-
28
- export { TypesConfig, TypesProviderPlugin };
25
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.cjs.js DELETED
@@ -1,33 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- class TypesProviderPlugin {
6
- constructor(config) {
7
- this.name = "TypesProviderPlugin";
8
- this.config = config;
9
- }
10
- apply(player) {
11
- player.hooks.schema.tap(this.name, (schema) => {
12
- if (this.config.types) {
13
- schema.addDataTypes(this.config.types);
14
- }
15
- if (this.config.formats) {
16
- schema.addFormatters(this.config.formats);
17
- }
18
- });
19
- if (this.config.validators) {
20
- player.hooks.validationController.tap(this.name, (validationController) => {
21
- validationController.hooks.createValidatorRegistry.tap(this.name, (validationRegistry) => {
22
- var _a;
23
- (_a = this.config.validators) == null ? void 0 : _a.forEach(([name, handler]) => {
24
- validationRegistry.register(name, handler);
25
- });
26
- });
27
- });
28
- }
29
- }
30
- }
31
-
32
- exports.TypesProviderPlugin = TypesProviderPlugin;
33
- //# sourceMappingURL=index.cjs.js.map
package/dist/index.esm.js DELETED
@@ -1,29 +0,0 @@
1
- class TypesProviderPlugin {
2
- constructor(config) {
3
- this.name = "TypesProviderPlugin";
4
- this.config = config;
5
- }
6
- apply(player) {
7
- player.hooks.schema.tap(this.name, (schema) => {
8
- if (this.config.types) {
9
- schema.addDataTypes(this.config.types);
10
- }
11
- if (this.config.formats) {
12
- schema.addFormatters(this.config.formats);
13
- }
14
- });
15
- if (this.config.validators) {
16
- player.hooks.validationController.tap(this.name, (validationController) => {
17
- validationController.hooks.createValidatorRegistry.tap(this.name, (validationRegistry) => {
18
- var _a;
19
- (_a = this.config.validators) == null ? void 0 : _a.forEach(([name, handler]) => {
20
- validationRegistry.register(name, handler);
21
- });
22
- });
23
- });
24
- }
25
- }
26
- }
27
-
28
- export { TypesProviderPlugin };
29
- //# sourceMappingURL=index.esm.js.map
@@ -1,143 +0,0 @@
1
- (function webpackUniversalModuleDefinition(root, factory) {
2
- if(typeof exports === 'object' && typeof module === 'object')
3
- module.exports = factory();
4
- else if(typeof define === 'function' && define.amd)
5
- define([], factory);
6
- else if(typeof exports === 'object')
7
- exports["TypesProviderPlugin"] = factory();
8
- else
9
- root["TypesProviderPlugin"] = factory();
10
- })(this, function() {
11
- return /******/ (function(modules) { // webpackBootstrap
12
- /******/ // The module cache
13
- /******/ var installedModules = {};
14
- /******/
15
- /******/ // The require function
16
- /******/ function __webpack_require__(moduleId) {
17
- /******/
18
- /******/ // Check if module is in cache
19
- /******/ if(installedModules[moduleId]) {
20
- /******/ return installedModules[moduleId].exports;
21
- /******/ }
22
- /******/ // Create a new module (and put it into the cache)
23
- /******/ var module = installedModules[moduleId] = {
24
- /******/ i: moduleId,
25
- /******/ l: false,
26
- /******/ exports: {}
27
- /******/ };
28
- /******/
29
- /******/ // Execute the module function
30
- /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
31
- /******/
32
- /******/ // Flag the module as loaded
33
- /******/ module.l = true;
34
- /******/
35
- /******/ // Return the exports of the module
36
- /******/ return module.exports;
37
- /******/ }
38
- /******/
39
- /******/
40
- /******/ // expose the modules object (__webpack_modules__)
41
- /******/ __webpack_require__.m = modules;
42
- /******/
43
- /******/ // expose the module cache
44
- /******/ __webpack_require__.c = installedModules;
45
- /******/
46
- /******/ // define getter function for harmony exports
47
- /******/ __webpack_require__.d = function(exports, name, getter) {
48
- /******/ if(!__webpack_require__.o(exports, name)) {
49
- /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
50
- /******/ }
51
- /******/ };
52
- /******/
53
- /******/ // define __esModule on exports
54
- /******/ __webpack_require__.r = function(exports) {
55
- /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
56
- /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
57
- /******/ }
58
- /******/ Object.defineProperty(exports, '__esModule', { value: true });
59
- /******/ };
60
- /******/
61
- /******/ // create a fake namespace object
62
- /******/ // mode & 1: value is a module id, require it
63
- /******/ // mode & 2: merge all properties of value into the ns
64
- /******/ // mode & 4: return value when already ns object
65
- /******/ // mode & 8|1: behave like require
66
- /******/ __webpack_require__.t = function(value, mode) {
67
- /******/ if(mode & 1) value = __webpack_require__(value);
68
- /******/ if(mode & 8) return value;
69
- /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
70
- /******/ var ns = Object.create(null);
71
- /******/ __webpack_require__.r(ns);
72
- /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
73
- /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
74
- /******/ return ns;
75
- /******/ };
76
- /******/
77
- /******/ // getDefaultExport function for compatibility with non-harmony modules
78
- /******/ __webpack_require__.n = function(module) {
79
- /******/ var getter = module && module.__esModule ?
80
- /******/ function getDefault() { return module['default']; } :
81
- /******/ function getModuleExports() { return module; };
82
- /******/ __webpack_require__.d(getter, 'a', getter);
83
- /******/ return getter;
84
- /******/ };
85
- /******/
86
- /******/ // Object.prototype.hasOwnProperty.call
87
- /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
88
- /******/
89
- /******/ // __webpack_public_path__
90
- /******/ __webpack_require__.p = "";
91
- /******/
92
- /******/
93
- /******/ // Load entry module and return exports
94
- /******/ return __webpack_require__(__webpack_require__.s = "./bazel-out/k8-fastbuild/bin/plugins/types-provider/core/dist/index.esm.js");
95
- /******/ })
96
- /************************************************************************/
97
- /******/ ({
98
-
99
- /***/ "./bazel-out/k8-fastbuild/bin/plugins/types-provider/core/dist/index.esm.js":
100
- /*!**********************************************************************************!*\
101
- !*** ./bazel-out/k8-fastbuild/bin/plugins/types-provider/core/dist/index.esm.js ***!
102
- \**********************************************************************************/
103
- /*! exports provided: TypesProviderPlugin */
104
- /***/ (function(module, __webpack_exports__, __webpack_require__) {
105
-
106
- "use strict";
107
- __webpack_require__.r(__webpack_exports__);
108
- /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "TypesProviderPlugin", function() { return TypesProviderPlugin; });
109
- class TypesProviderPlugin {
110
- constructor(config) {
111
- this.name = "TypesProviderPlugin";
112
- this.config = config;
113
- }
114
- apply(player) {
115
- player.hooks.schema.tap(this.name, (schema) => {
116
- if (this.config.types) {
117
- schema.addDataTypes(this.config.types);
118
- }
119
- if (this.config.formats) {
120
- schema.addFormatters(this.config.formats);
121
- }
122
- });
123
- if (this.config.validators) {
124
- player.hooks.validationController.tap(this.name, (validationController) => {
125
- validationController.hooks.createValidatorRegistry.tap(this.name, (validationRegistry) => {
126
- var _a;
127
- (_a = this.config.validators) == null ? void 0 : _a.forEach(([name, handler]) => {
128
- validationRegistry.register(name, handler);
129
- });
130
- });
131
- });
132
- }
133
- }
134
- }
135
-
136
-
137
- //# sourceMappingURL=index.esm.js.map
138
-
139
-
140
- /***/ })
141
-
142
- /******/ });
143
- });
@@ -1 +0,0 @@
1
- !function(e,t){"object"===typeof exports&&"object"===typeof module?module.exports=t():"function"===typeof define&&define.amd?define([],t):"object"===typeof exports?exports.TypesProviderPlugin=t():e.TypesProviderPlugin=t()}(this,(function(){return function(e){var t={};function r(o){if(t[o])return t[o].exports;var n=t[o]={i:o,l:!1,exports:{}};return e[o].call(n.exports,n,n.exports,r),n.l=!0,n.exports}return r.m=e,r.c=t,r.d=function(e,t,o){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},r.r=function(e){"undefined"!==typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"===typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(r.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var n in e)r.d(o,n,function(t){return e[t]}.bind(null,n));return o},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=0)}([function(e,t,r){"use strict";r.r(t),r.d(t,"TypesProviderPlugin",(function(){return o}));class o{constructor(e){this.name="TypesProviderPlugin",this.config=e}apply(e){e.hooks.schema.tap(this.name,(e=>{this.config.types&&e.addDataTypes(this.config.types),this.config.formats&&e.addFormatters(this.config.formats)})),this.config.validators&&e.hooks.validationController.tap(this.name,(e=>{e.hooks.createValidatorRegistry.tap(this.name,(e=>{var t;null==(t=this.config.validators)||t.forEach((([t,r])=>{e.register(t,r)}))}))}))}}}])}));