@vixoniccom/modules 2.11.0 → 2.12.0-dev.2

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 (59) hide show
  1. package/.vscode/settings.json +2 -2
  2. package/CHANGELOG.md +289 -264
  3. package/dist/index.d.ts +6 -6
  4. package/dist/index.js +32 -31
  5. package/dist/lib/base.d.ts +28 -36
  6. package/dist/lib/base.js +63 -58
  7. package/dist/lib/containers/dynamic-matrix.d.ts +48 -48
  8. package/dist/lib/containers/dynamic-matrix.js +85 -76
  9. package/dist/lib/containers/group.d.ts +21 -21
  10. package/dist/lib/containers/group.js +56 -47
  11. package/dist/lib/containers/index.d.ts +6 -6
  12. package/dist/lib/containers/index.js +14 -13
  13. package/dist/lib/containers/list.d.ts +66 -66
  14. package/dist/lib/containers/list.js +114 -105
  15. package/dist/lib/errors.d.ts +22 -22
  16. package/dist/lib/errors.js +24 -23
  17. package/dist/lib/index.d.ts +29 -29
  18. package/dist/lib/index.js +136 -128
  19. package/dist/lib/inputs/autocomplete.d.ts +31 -31
  20. package/dist/lib/inputs/autocomplete.js +55 -49
  21. package/dist/lib/inputs/color-picker.d.ts +23 -23
  22. package/dist/lib/inputs/color-picker.js +48 -42
  23. package/dist/lib/inputs/date-input.d.ts +35 -35
  24. package/dist/lib/inputs/date-input.js +87 -78
  25. package/dist/lib/inputs/index.d.ts +24 -24
  26. package/dist/lib/inputs/index.js +52 -49
  27. package/dist/lib/inputs/number-input.d.ts +29 -29
  28. package/dist/lib/inputs/number-input.js +62 -53
  29. package/dist/lib/inputs/select-asset-kna.d.ts +34 -34
  30. package/dist/lib/inputs/select-asset-kna.js +56 -50
  31. package/dist/lib/inputs/select-input.d.ts +18 -18
  32. package/dist/lib/inputs/select-input.js +35 -29
  33. package/dist/lib/inputs/service-input.d.ts +27 -27
  34. package/dist/lib/inputs/service-input.js +47 -41
  35. package/dist/lib/inputs/slider.d.ts +33 -33
  36. package/dist/lib/inputs/slider.js +57 -51
  37. package/dist/lib/inputs/switch.d.ts +21 -21
  38. package/dist/lib/inputs/switch.js +45 -39
  39. package/dist/lib/inputs/text-area.d.ts +20 -20
  40. package/dist/lib/inputs/text-area.js +46 -37
  41. package/dist/lib/inputs/text-format.d.ts +28 -28
  42. package/dist/lib/inputs/text-format.js +43 -37
  43. package/dist/lib/inputs/text-input.d.ts +34 -34
  44. package/dist/lib/inputs/text-input.js +73 -64
  45. package/dist/lib/ui/index.d.ts +4 -4
  46. package/dist/lib/ui/index.js +6 -5
  47. package/dist/lib/ui/label.d.ts +18 -18
  48. package/dist/lib/ui/label.js +36 -30
  49. package/dist/lib/utils/index.d.ts +2 -1
  50. package/dist/lib/utils/index.js +28 -22
  51. package/dist/lib/utils/typeDefs.d.ts +7 -7
  52. package/dist/lib/utils/typeDefs.js +19 -18
  53. package/dist/lib/utils/validation.d.ts +7 -7
  54. package/dist/lib/utils/validation.js +27 -26
  55. package/dist/lib/values.d.ts +21 -21
  56. package/dist/lib/values.js +92 -86
  57. package/dist/lib/visibility.d.ts +2 -2
  58. package/dist/lib/visibility.js +21 -20
  59. package/package.json +23 -22
package/dist/index.js CHANGED
@@ -1,31 +1,32 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var lib_1 = require("./lib");
4
- exports.Configuration = lib_1.Configuration;
5
- var errors_1 = require("./lib/errors");
6
- exports.Errors = errors_1.Errors;
7
- var inputs_1 = require("./lib/inputs");
8
- exports.Autocomplete = inputs_1.Autocomplete;
9
- exports.ColorPicker = inputs_1.ColorPicker;
10
- exports.DateInput = inputs_1.DateInput;
11
- exports.NumberInput = inputs_1.NumberInput;
12
- exports.SelectAssetKna = inputs_1.SelectAssetKna;
13
- exports.SelectInput = inputs_1.SelectInput;
14
- exports.Switch = inputs_1.Switch;
15
- exports.Slider = inputs_1.Slider;
16
- exports.TextArea = inputs_1.TextArea;
17
- exports.TextFormat = inputs_1.TextFormat;
18
- exports.TextInput = inputs_1.TextInput;
19
- exports.ServiceInput = inputs_1.ServiceInput;
20
- exports.isInput = inputs_1.isInput;
21
- exports.isInputInstance = inputs_1.isInputInstance;
22
- var ui_1 = require("./lib/ui");
23
- exports.Label = ui_1.Label;
24
- var containers_1 = require("./lib/containers");
25
- exports.Group = containers_1.Group;
26
- exports.List = containers_1.List;
27
- exports.DynamicMatrix = containers_1.DynamicMatrix;
28
- var values_1 = require("./lib/values");
29
- exports.RangeValue = values_1.RangeValue;
30
- exports.DateRangeValue = values_1.DateRangeValue;
31
- exports.NumberRangeValue = values_1.NumberRangeValue;
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.NumberRangeValue = exports.DateRangeValue = exports.RangeValue = exports.DynamicMatrix = exports.List = exports.Group = exports.Label = exports.isInputInstance = exports.isInput = exports.ServiceInput = exports.TextInput = exports.TextFormat = exports.TextArea = exports.Slider = exports.Switch = exports.SelectInput = exports.SelectAssetKna = exports.NumberInput = exports.DateInput = exports.ColorPicker = exports.Autocomplete = exports.Errors = exports.Configuration = void 0;
4
+ var lib_1 = require("./lib");
5
+ Object.defineProperty(exports, "Configuration", { enumerable: true, get: function () { return lib_1.Configuration; } });
6
+ var errors_1 = require("./lib/errors");
7
+ Object.defineProperty(exports, "Errors", { enumerable: true, get: function () { return errors_1.Errors; } });
8
+ var inputs_1 = require("./lib/inputs");
9
+ Object.defineProperty(exports, "Autocomplete", { enumerable: true, get: function () { return inputs_1.Autocomplete; } });
10
+ Object.defineProperty(exports, "ColorPicker", { enumerable: true, get: function () { return inputs_1.ColorPicker; } });
11
+ Object.defineProperty(exports, "DateInput", { enumerable: true, get: function () { return inputs_1.DateInput; } });
12
+ Object.defineProperty(exports, "NumberInput", { enumerable: true, get: function () { return inputs_1.NumberInput; } });
13
+ Object.defineProperty(exports, "SelectAssetKna", { enumerable: true, get: function () { return inputs_1.SelectAssetKna; } });
14
+ Object.defineProperty(exports, "SelectInput", { enumerable: true, get: function () { return inputs_1.SelectInput; } });
15
+ Object.defineProperty(exports, "Switch", { enumerable: true, get: function () { return inputs_1.Switch; } });
16
+ Object.defineProperty(exports, "Slider", { enumerable: true, get: function () { return inputs_1.Slider; } });
17
+ Object.defineProperty(exports, "TextArea", { enumerable: true, get: function () { return inputs_1.TextArea; } });
18
+ Object.defineProperty(exports, "TextFormat", { enumerable: true, get: function () { return inputs_1.TextFormat; } });
19
+ Object.defineProperty(exports, "TextInput", { enumerable: true, get: function () { return inputs_1.TextInput; } });
20
+ Object.defineProperty(exports, "ServiceInput", { enumerable: true, get: function () { return inputs_1.ServiceInput; } });
21
+ Object.defineProperty(exports, "isInput", { enumerable: true, get: function () { return inputs_1.isInput; } });
22
+ Object.defineProperty(exports, "isInputInstance", { enumerable: true, get: function () { return inputs_1.isInputInstance; } });
23
+ var ui_1 = require("./lib/ui");
24
+ Object.defineProperty(exports, "Label", { enumerable: true, get: function () { return ui_1.Label; } });
25
+ var containers_1 = require("./lib/containers");
26
+ Object.defineProperty(exports, "Group", { enumerable: true, get: function () { return containers_1.Group; } });
27
+ Object.defineProperty(exports, "List", { enumerable: true, get: function () { return containers_1.List; } });
28
+ Object.defineProperty(exports, "DynamicMatrix", { enumerable: true, get: function () { return containers_1.DynamicMatrix; } });
29
+ var values_1 = require("./lib/values");
30
+ Object.defineProperty(exports, "RangeValue", { enumerable: true, get: function () { return values_1.RangeValue; } });
31
+ Object.defineProperty(exports, "DateRangeValue", { enumerable: true, get: function () { return values_1.DateRangeValue; } });
32
+ Object.defineProperty(exports, "NumberRangeValue", { enumerable: true, get: function () { return values_1.NumberRangeValue; } });
@@ -1,36 +1,28 @@
1
- import { InputValue } from "./inputs";
2
- import { ValueError, SimpleValueError } from "./errors";
3
- import { Configuration } from ".";
4
- export declare type Diff<T extends string, U extends string> = ({
5
- [P in T]: P;
6
- } & {
7
- [P in U]: never;
8
- } & {
9
- [x: string]: never;
10
- })[T];
11
- export declare type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
12
- export interface IBaseElement {
13
- readonly id: string;
14
- readonly label: string;
15
- readonly show?: string;
16
- }
17
- export interface IInput extends IBaseElement {
18
- }
19
- export declare abstract class ConfigurationElement {
20
- readonly abstract type: string;
21
- static readonly type: string;
22
- protected show?: string;
23
- shouldShow(values: Configuration.Value): boolean;
24
- }
25
- export declare abstract class BaseElement extends ConfigurationElement implements IBaseElement {
26
- readonly id: string;
27
- readonly label: string;
28
- readonly show?: string;
29
- constructor({id, label, show}: IInput);
30
- }
31
- export declare abstract class Input<V extends InputValue = InputValue, E extends ValueError = ValueError> extends BaseElement {
32
- validate: (value: V, ctx: Configuration.Value) => (SimpleValueError<"invalidValue"> | E)[];
33
- abstract validateInput(value: V | undefined): E[];
34
- abstract isValidValue(value?: any): value is V;
35
- abstract valueTypeDef: () => string;
36
- }
1
+ import { InputValue } from "./inputs";
2
+ import { ValueError } from "./errors";
3
+ import { Configuration } from ".";
4
+ export interface IBaseElement {
5
+ readonly id: string;
6
+ readonly label: string;
7
+ readonly show?: string;
8
+ }
9
+ export interface IInput extends IBaseElement {
10
+ }
11
+ export declare abstract class ConfigurationElement {
12
+ abstract readonly type: string;
13
+ static readonly type: string;
14
+ protected show?: string;
15
+ shouldShow(values: Configuration.Value): boolean;
16
+ }
17
+ export declare abstract class BaseElement extends ConfigurationElement implements IBaseElement {
18
+ readonly id: string;
19
+ readonly label: string;
20
+ readonly show?: string;
21
+ constructor({ id, label, show }: IInput);
22
+ }
23
+ export declare abstract class Input<V extends InputValue = InputValue, E extends ValueError = ValueError> extends BaseElement {
24
+ validate: (value: V, ctx: Configuration.Value) => (E | ValueError.InvalidValue)[];
25
+ abstract validateInput(value: V | undefined): E[];
26
+ abstract isValidValue(value?: any): value is V;
27
+ abstract valueTypeDef: () => string;
28
+ }
package/dist/lib/base.js CHANGED
@@ -1,58 +1,63 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
- return function (d, b) {
7
- extendStatics(d, b);
8
- function __() { this.constructor = d; }
9
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10
- };
11
- })();
12
- Object.defineProperty(exports, "__esModule", { value: true });
13
- var visibility_1 = require("./visibility");
14
- var ConfigurationElement = (function () {
15
- function ConfigurationElement() {
16
- this.type = '';
17
- }
18
- ConfigurationElement.prototype.shouldShow = function (values) {
19
- return visibility_1.shouldBeVisible(this, values);
20
- };
21
- return ConfigurationElement;
22
- }());
23
- exports.ConfigurationElement = ConfigurationElement;
24
- var BaseElement = (function (_super) {
25
- __extends(BaseElement, _super);
26
- function BaseElement(_a) {
27
- var id = _a.id, label = _a.label, show = _a.show;
28
- var _this = _super.call(this) || this;
29
- _this.id = id;
30
- _this.label = label;
31
- _this.show = show;
32
- return _this;
33
- }
34
- return BaseElement;
35
- }(ConfigurationElement));
36
- exports.BaseElement = BaseElement;
37
- var Input = (function (_super) {
38
- __extends(Input, _super);
39
- function Input() {
40
- var _this = _super !== null && _super.apply(this, arguments) || this;
41
- _this.validate = function (value, ctx) {
42
- var show = _this.shouldShow(ctx);
43
- if (!show)
44
- return [];
45
- var errors = [];
46
- if (value !== undefined && !_this.isValidValue(value)) {
47
- errors = errors.concat([{ type: 'invalidValue' }]);
48
- }
49
- else {
50
- errors = errors.concat(_this.validateInput(value));
51
- }
52
- return errors;
53
- };
54
- return _this;
55
- }
56
- return Input;
57
- }(BaseElement));
58
- exports.Input = Input;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.Input = exports.BaseElement = exports.ConfigurationElement = void 0;
19
+ var visibility_1 = require("./visibility");
20
+ var ConfigurationElement = /** @class */ (function () {
21
+ function ConfigurationElement() {
22
+ }
23
+ ConfigurationElement.prototype.shouldShow = function (values) {
24
+ return visibility_1.shouldBeVisible(this, values);
25
+ };
26
+ return ConfigurationElement;
27
+ }());
28
+ exports.ConfigurationElement = ConfigurationElement;
29
+ var BaseElement = /** @class */ (function (_super) {
30
+ __extends(BaseElement, _super);
31
+ function BaseElement(_a) {
32
+ var id = _a.id, label = _a.label, show = _a.show;
33
+ var _this = _super.call(this) || this;
34
+ _this.id = id;
35
+ _this.label = label;
36
+ _this.show = show;
37
+ return _this;
38
+ }
39
+ return BaseElement;
40
+ }(ConfigurationElement));
41
+ exports.BaseElement = BaseElement;
42
+ var Input = /** @class */ (function (_super) {
43
+ __extends(Input, _super);
44
+ function Input() {
45
+ var _this = _super !== null && _super.apply(this, arguments) || this;
46
+ _this.validate = function (value, ctx) {
47
+ var show = _this.shouldShow(ctx);
48
+ if (!show)
49
+ return [];
50
+ var errors = [];
51
+ if (value !== undefined && !_this.isValidValue(value)) {
52
+ errors = errors.concat([{ type: 'invalidValue' }]);
53
+ }
54
+ else {
55
+ errors = errors.concat(_this.validateInput(value));
56
+ }
57
+ return errors;
58
+ };
59
+ return _this;
60
+ }
61
+ return Input;
62
+ }(BaseElement));
63
+ exports.Input = Input;
@@ -1,48 +1,48 @@
1
- import { Omit, BaseElement, IBaseElement } from '../base';
2
- import { List } from './list';
3
- import { InputComponent } from '../inputs';
4
- import { UIComponent } from '../ui';
5
- import { TypeDefMap } from '../utils/typeDefs';
6
- import { ErrorsMap, Errors } from '../errors';
7
- import { Configuration } from '..';
8
- export declare type DisplayClass = '2-lines' | '1-line';
9
- export declare type DisplayAttributes = {
10
- title: string;
11
- subtitle?: string;
12
- };
13
- export interface IDynamicMatrix extends IBaseElement {
14
- listIds: (string | List)[];
15
- itemSchema: (InputComponent | UIComponent)[];
16
- description?: string;
17
- }
18
- export interface ListJSON extends Omit<IDynamicMatrix, 'itemSchema'> {
19
- itemSchema: {
20
- type: string;
21
- }[];
22
- }
23
- export declare type MatrixItem = {
24
- [key: string]: any;
25
- };
26
- export declare namespace DynamicMatrix {
27
- type Value = {
28
- [key: string]: DynamicMatrix.Value | MatrixItem;
29
- };
30
- type ItemValue = MatrixItem;
31
- type Error = {
32
- type: 'InvalidValue';
33
- };
34
- }
35
- export declare class DynamicMatrix extends BaseElement {
36
- static readonly type: string;
37
- type: string;
38
- readonly listIds: string[];
39
- readonly itemSchema: (InputComponent | UIComponent)[];
40
- readonly description?: string;
41
- constructor(options: IDynamicMatrix);
42
- validate(value: DynamicMatrix.Value | undefined, ctx: Configuration.Value): ErrorsMap | DynamicMatrix.Error[];
43
- validateItem(value: DynamicMatrix.ItemValue, ctx: Configuration.Value): Errors<DynamicMatrix.Error>;
44
- isValidValue(v: any): v is DynamicMatrix.Value;
45
- valueTypeDef: () => TypeDefMap;
46
- static fromJSON(value: ListJSON): DynamicMatrix;
47
- static isInstance(instance: any): instance is DynamicMatrix;
48
- }
1
+ import { BaseElement, IBaseElement } from '../base';
2
+ import { List } from './list';
3
+ import { InputComponent } from '../inputs';
4
+ import { UIComponent } from '../ui';
5
+ import { TypeDefMap } from '../utils/typeDefs';
6
+ import { ErrorsMap, Errors } from '../errors';
7
+ import { Configuration } from '..';
8
+ export declare type DisplayClass = '2-lines' | '1-line';
9
+ export declare type DisplayAttributes = {
10
+ title: string;
11
+ subtitle?: string;
12
+ };
13
+ export interface IDynamicMatrix extends IBaseElement {
14
+ listIds: (string | List)[];
15
+ itemSchema: (InputComponent | UIComponent)[];
16
+ description?: string;
17
+ }
18
+ export interface ListJSON extends Omit<IDynamicMatrix, 'itemSchema'> {
19
+ itemSchema: {
20
+ type: string;
21
+ }[];
22
+ }
23
+ export declare type MatrixItem = {
24
+ [key: string]: any;
25
+ };
26
+ export declare namespace DynamicMatrix {
27
+ type Value = {
28
+ [key: string]: DynamicMatrix.Value | MatrixItem;
29
+ };
30
+ type ItemValue = MatrixItem;
31
+ type Error = {
32
+ type: 'InvalidValue';
33
+ };
34
+ }
35
+ export declare class DynamicMatrix extends BaseElement {
36
+ static readonly type = "dynamic-matrix";
37
+ type: string;
38
+ readonly listIds: string[];
39
+ readonly itemSchema: (InputComponent | UIComponent)[];
40
+ readonly description?: string;
41
+ constructor(options: IDynamicMatrix);
42
+ validate(value: DynamicMatrix.Value | undefined, ctx: Configuration.Value): ErrorsMap | DynamicMatrix.Error[];
43
+ validateItem(value: DynamicMatrix.ItemValue, ctx: Configuration.Value): Errors<DynamicMatrix.Error>;
44
+ isValidValue(v: any): v is DynamicMatrix.Value;
45
+ valueTypeDef: () => TypeDefMap;
46
+ static fromJSON(value: ListJSON): DynamicMatrix;
47
+ static isInstance(instance: any): instance is DynamicMatrix;
48
+ }
@@ -1,76 +1,85 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = Object.setPrototypeOf ||
4
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
5
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
6
- return function (d, b) {
7
- extendStatics(d, b);
8
- function __() { this.constructor = d; }
9
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
10
- };
11
- })();
12
- var __assign = (this && this.__assign) || Object.assign || function(t) {
13
- for (var s, i = 1, n = arguments.length; i < n; i++) {
14
- s = arguments[i];
15
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
16
- t[p] = s[p];
17
- }
18
- return t;
19
- };
20
- Object.defineProperty(exports, "__esModule", { value: true });
21
- var base_1 = require("../base");
22
- var inputs_1 = require("../inputs");
23
- var utils_1 = require("../utils");
24
- var typeDefs_1 = require("../utils/typeDefs");
25
- var DynamicMatrix = (function (_super) {
26
- __extends(DynamicMatrix, _super);
27
- function DynamicMatrix(options) {
28
- var _this = _super.call(this, options) || this;
29
- _this.type = DynamicMatrix.type;
30
- _this.valueTypeDef = function () {
31
- var declarations = [];
32
- declarations = declarations.concat(typeDefs_1.getDefsFromInputs(_this.itemSchema.filter(inputs_1.isInput)));
33
- return {
34
- id: _this.id,
35
- typeDef: _this.listIds.map(function (id) { return "{ [key: string]: "; }).join('') + " {" + typeDefs_1.defsMapToString(declarations) + "}" + _this.listIds.map(function (id) { return ' }'; }).join('')
36
- };
37
- };
38
- _this.listIds = options.listIds.map(function (list) { return typeof list === 'string' ? list : list.id; });
39
- _this.itemSchema = options.itemSchema;
40
- _this.description = options.description;
41
- return _this;
42
- }
43
- DynamicMatrix.prototype.validate = function (value, ctx) {
44
- // No value, then is valid.
45
- if (!value)
46
- return {};
47
- // Not a valid value.
48
- if (!this.isValidValue(value))
49
- return [{ type: 'InvalidValue' }];
50
- else
51
- return {};
52
- };
53
- DynamicMatrix.prototype.validateItem = function (value, ctx) {
54
- var itemErrors = {};
55
- this.itemSchema.forEach(function (input) {
56
- if (inputs_1.isInput(input)) {
57
- itemErrors[input.id] = input.validate(value[input.id], ctx);
58
- }
59
- });
60
- return itemErrors;
61
- };
62
- DynamicMatrix.prototype.isValidValue = function (v) {
63
- return v && typeof v === 'object';
64
- };
65
- DynamicMatrix.fromJSON = function (value) {
66
- return new DynamicMatrix(__assign({}, value, { itemSchema: value.itemSchema.map(function (i) {
67
- return utils_1.createComponentFromJSON(i.type, i);
68
- }) }));
69
- };
70
- DynamicMatrix.isInstance = function (instance) {
71
- return instance.type === DynamicMatrix.type;
72
- };
73
- DynamicMatrix.type = 'dynamic-matrix';
74
- return DynamicMatrix;
75
- }(base_1.BaseElement));
76
- exports.DynamicMatrix = DynamicMatrix;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.DynamicMatrix = void 0;
30
+ var base_1 = require("../base");
31
+ var inputs_1 = require("../inputs");
32
+ var typeDefs_1 = require("../utils/typeDefs");
33
+ var DynamicMatrix = /** @class */ (function (_super) {
34
+ __extends(DynamicMatrix, _super);
35
+ function DynamicMatrix(options) {
36
+ var _this = _super.call(this, options) || this;
37
+ _this.type = DynamicMatrix.type;
38
+ _this.valueTypeDef = function () {
39
+ var declarations = [];
40
+ declarations = declarations.concat(typeDefs_1.getDefsFromInputs(_this.itemSchema.filter(inputs_1.isInput)));
41
+ return {
42
+ id: _this.id,
43
+ typeDef: _this.listIds.map(function (id) { return "{ [key: string]: "; }).join('') + " {" + typeDefs_1.defsMapToString(declarations) + "}" + _this.listIds.map(function (id) { return ' }'; }).join('')
44
+ };
45
+ };
46
+ _this.listIds = options.listIds.map(function (list) { return typeof list === 'string' ? list : list.id; });
47
+ _this.itemSchema = options.itemSchema;
48
+ _this.description = options.description;
49
+ return _this;
50
+ }
51
+ DynamicMatrix.prototype.validate = function (value, ctx) {
52
+ // No value, then is valid.
53
+ if (!value)
54
+ return {};
55
+ // Not a valid value.
56
+ if (!this.isValidValue(value))
57
+ return [{ type: 'InvalidValue' }];
58
+ else
59
+ return {};
60
+ };
61
+ DynamicMatrix.prototype.validateItem = function (value, ctx) {
62
+ var itemErrors = {};
63
+ this.itemSchema.forEach(function (input) {
64
+ if (inputs_1.isInput(input)) {
65
+ itemErrors[input.id] = input.validate(value[input.id], ctx);
66
+ }
67
+ });
68
+ return itemErrors;
69
+ };
70
+ DynamicMatrix.prototype.isValidValue = function (v) {
71
+ return v && typeof v === 'object';
72
+ };
73
+ DynamicMatrix.fromJSON = function (value) {
74
+ var createComponentFromJSON = require('../utils').default;
75
+ return new DynamicMatrix(__assign(__assign({}, value), { itemSchema: value.itemSchema.map(function (i) {
76
+ return createComponentFromJSON(i.type, i);
77
+ }) }));
78
+ };
79
+ DynamicMatrix.isInstance = function (instance) {
80
+ return instance.type === DynamicMatrix.type;
81
+ };
82
+ DynamicMatrix.type = 'dynamic-matrix';
83
+ return DynamicMatrix;
84
+ }(base_1.BaseElement));
85
+ exports.DynamicMatrix = DynamicMatrix;
@@ -1,21 +1,21 @@
1
- import { IBaseElement, BaseElement } from '../base';
2
- import { InputComponent } from '../inputs';
3
- import { UIComponent } from '../ui';
4
- import { TypeDefMap } from '../utils/typeDefs';
5
- export interface IGroup extends IBaseElement {
6
- items: (InputComponent | UIComponent)[];
7
- }
8
- export interface GroupJSON extends IBaseElement {
9
- items: {
10
- type: string;
11
- }[];
12
- }
13
- export declare class Group extends BaseElement {
14
- static readonly type: string;
15
- type: string;
16
- readonly items: (InputComponent | UIComponent)[];
17
- constructor(options: IGroup);
18
- valueTypeDef: () => TypeDefMap[];
19
- static fromJSON(value: GroupJSON): Group;
20
- static isInstance(instance: any): instance is Group;
21
- }
1
+ import { IBaseElement, BaseElement } from '../base';
2
+ import { InputComponent } from '../inputs';
3
+ import { UIComponent } from '../ui';
4
+ import { TypeDefMap } from '../utils/typeDefs';
5
+ export interface IGroup extends IBaseElement {
6
+ items: (InputComponent | UIComponent)[];
7
+ }
8
+ export interface GroupJSON extends IBaseElement {
9
+ items: {
10
+ type: string;
11
+ }[];
12
+ }
13
+ export declare class Group extends BaseElement {
14
+ static readonly type = "group";
15
+ type: string;
16
+ readonly items: (InputComponent | UIComponent)[];
17
+ constructor(options: IGroup);
18
+ valueTypeDef: () => TypeDefMap[];
19
+ static fromJSON(value: GroupJSON): Group;
20
+ static isInstance(instance: any): instance is Group;
21
+ }