@vixoniccom/modules 2.11.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 (59) hide show
  1. package/.vscode/settings.json +3 -0
  2. package/CHANGELOG.md +264 -0
  3. package/dist/index.d.ts +6 -0
  4. package/dist/index.js +31 -0
  5. package/dist/lib/base.d.ts +36 -0
  6. package/dist/lib/base.js +58 -0
  7. package/dist/lib/containers/dynamic-matrix.d.ts +48 -0
  8. package/dist/lib/containers/dynamic-matrix.js +76 -0
  9. package/dist/lib/containers/group.d.ts +21 -0
  10. package/dist/lib/containers/group.js +47 -0
  11. package/dist/lib/containers/index.d.ts +6 -0
  12. package/dist/lib/containers/index.js +13 -0
  13. package/dist/lib/containers/list.d.ts +66 -0
  14. package/dist/lib/containers/list.js +105 -0
  15. package/dist/lib/errors.d.ts +22 -0
  16. package/dist/lib/errors.js +23 -0
  17. package/dist/lib/index.d.ts +29 -0
  18. package/dist/lib/index.js +128 -0
  19. package/dist/lib/inputs/autocomplete.d.ts +31 -0
  20. package/dist/lib/inputs/autocomplete.js +49 -0
  21. package/dist/lib/inputs/color-picker.d.ts +23 -0
  22. package/dist/lib/inputs/color-picker.js +42 -0
  23. package/dist/lib/inputs/date-input.d.ts +35 -0
  24. package/dist/lib/inputs/date-input.js +78 -0
  25. package/dist/lib/inputs/index.d.ts +24 -0
  26. package/dist/lib/inputs/index.js +49 -0
  27. package/dist/lib/inputs/number-input.d.ts +29 -0
  28. package/dist/lib/inputs/number-input.js +53 -0
  29. package/dist/lib/inputs/select-asset-kna.d.ts +34 -0
  30. package/dist/lib/inputs/select-asset-kna.js +50 -0
  31. package/dist/lib/inputs/select-input.d.ts +18 -0
  32. package/dist/lib/inputs/select-input.js +29 -0
  33. package/dist/lib/inputs/service-input.d.ts +27 -0
  34. package/dist/lib/inputs/service-input.js +41 -0
  35. package/dist/lib/inputs/slider.d.ts +33 -0
  36. package/dist/lib/inputs/slider.js +51 -0
  37. package/dist/lib/inputs/switch.d.ts +21 -0
  38. package/dist/lib/inputs/switch.js +39 -0
  39. package/dist/lib/inputs/text-area.d.ts +20 -0
  40. package/dist/lib/inputs/text-area.js +37 -0
  41. package/dist/lib/inputs/text-format.d.ts +28 -0
  42. package/dist/lib/inputs/text-format.js +37 -0
  43. package/dist/lib/inputs/text-input.d.ts +34 -0
  44. package/dist/lib/inputs/text-input.js +64 -0
  45. package/dist/lib/ui/index.d.ts +4 -0
  46. package/dist/lib/ui/index.js +5 -0
  47. package/dist/lib/ui/label.d.ts +18 -0
  48. package/dist/lib/ui/label.js +30 -0
  49. package/dist/lib/utils/index.d.ts +1 -0
  50. package/dist/lib/utils/index.js +22 -0
  51. package/dist/lib/utils/typeDefs.d.ts +7 -0
  52. package/dist/lib/utils/typeDefs.js +18 -0
  53. package/dist/lib/utils/validation.d.ts +7 -0
  54. package/dist/lib/utils/validation.js +26 -0
  55. package/dist/lib/values.d.ts +21 -0
  56. package/dist/lib/values.js +86 -0
  57. package/dist/lib/visibility.d.ts +2 -0
  58. package/dist/lib/visibility.js +20 -0
  59. package/package.json +22 -0
@@ -0,0 +1,66 @@
1
+ import { Omit, BaseElement, IBaseElement } from '../base';
2
+ import { RangeValue } from '../values';
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 IList extends IBaseElement {
14
+ id: string;
15
+ label: string;
16
+ itemSchema: (InputComponent | UIComponent)[];
17
+ itemDisplayClass: DisplayClass;
18
+ itemDisplayAttributes: DisplayAttributes;
19
+ description?: string;
20
+ range?: RangeValue;
21
+ sortable?: boolean;
22
+ showItemId?: boolean;
23
+ }
24
+ export interface ListJSON extends Omit<IList, 'itemSchema' | 'range'> {
25
+ range?: string;
26
+ itemSchema: {
27
+ type: string;
28
+ }[];
29
+ }
30
+ export declare type ListItem = {
31
+ [key: string]: any;
32
+ __id: string | undefined;
33
+ };
34
+ export declare namespace List {
35
+ type Value = ListItem[];
36
+ type ItemValue = ListItem;
37
+ type Error = {
38
+ type: 'ItemHasNoUniqueId';
39
+ } | {
40
+ type: 'InvalidListValue';
41
+ } | {
42
+ type: 'Min';
43
+ payload: number;
44
+ } | {
45
+ type: 'Max';
46
+ payload: number;
47
+ };
48
+ }
49
+ export declare class List extends BaseElement {
50
+ static readonly type: string;
51
+ type: string;
52
+ readonly itemSchema: (InputComponent | UIComponent)[];
53
+ readonly itemDisplayClass: DisplayClass;
54
+ readonly itemDisplayAttributes: DisplayAttributes;
55
+ readonly description?: string;
56
+ readonly range?: RangeValue;
57
+ readonly sortable?: boolean;
58
+ readonly showItemId?: boolean;
59
+ constructor(options: IList);
60
+ validate(value: List.Value | undefined, ctx: Configuration.Value): ErrorsMap | List.Error[];
61
+ validateItem(value: List.ItemValue, ctx: Configuration.Value): Errors<List.Error>;
62
+ isValidValue(v: any): v is List.Value;
63
+ valueTypeDef: () => TypeDefMap;
64
+ static fromJSON(value: ListJSON): List;
65
+ static isInstance(instance: any): instance is List;
66
+ }
@@ -0,0 +1,105 @@
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 values_1 = require("../values");
23
+ var inputs_1 = require("../inputs");
24
+ var utils_1 = require("../utils");
25
+ var typeDefs_1 = require("../utils/typeDefs");
26
+ var List = (function (_super) {
27
+ __extends(List, _super);
28
+ function List(options) {
29
+ var _this = _super.call(this, options) || this;
30
+ _this.type = List.type;
31
+ _this.valueTypeDef = function () {
32
+ var declarations = [];
33
+ declarations = declarations.concat(typeDefs_1.getDefsFromInputs(_this.itemSchema.filter(inputs_1.isInput)));
34
+ return {
35
+ id: _this.id,
36
+ typeDef: "{" + typeDefs_1.defsMapToString(declarations) + ", __id: string | undefined}[]"
37
+ };
38
+ };
39
+ _this.itemSchema = options.itemSchema;
40
+ _this.description = options.description;
41
+ _this.range = options.range;
42
+ _this.itemDisplayClass = options.itemDisplayClass;
43
+ _this.itemDisplayAttributes = options.itemDisplayAttributes;
44
+ _this.sortable = options.sortable;
45
+ _this.showItemId = options.showItemId;
46
+ return _this;
47
+ }
48
+ List.prototype.validate = function (value, ctx) {
49
+ var _this = this;
50
+ // Min
51
+ if (this.range && this.range.min) {
52
+ if (!value || value.length < this.range.min) {
53
+ return [{ type: 'Min', payload: this.range.min }];
54
+ }
55
+ }
56
+ // Max
57
+ if (this.range && this.range.max) {
58
+ if (value && value.length > this.range.max) {
59
+ return [{ type: 'Max', payload: this.range.max }];
60
+ }
61
+ }
62
+ // No value, then is valid.
63
+ if (!value)
64
+ return {};
65
+ // Not a valid value.
66
+ if (!this.isValidValue(value))
67
+ return [{ type: 'InvalidListValue' }];
68
+ var itemsErrors = {};
69
+ value && value.map(function (item, index) {
70
+ var itemErrors = _this.validateItem(item, ctx);
71
+ var itemId = item.__id || index;
72
+ itemsErrors[itemId] = itemErrors;
73
+ });
74
+ return itemsErrors;
75
+ };
76
+ List.prototype.validateItem = function (value, ctx) {
77
+ var itemError = {};
78
+ if (value.__id) {
79
+ var itemErrors_1 = {};
80
+ this.itemSchema.forEach(function (input) {
81
+ if (inputs_1.isInput(input)) {
82
+ itemErrors_1[input.id] = input.validate(value[input.id], ctx);
83
+ }
84
+ });
85
+ return itemErrors_1;
86
+ }
87
+ else {
88
+ return [{ type: 'ItemHasNoUniqueId' }];
89
+ }
90
+ };
91
+ List.prototype.isValidValue = function (v) {
92
+ return v && Array.isArray(v);
93
+ };
94
+ List.fromJSON = function (value) {
95
+ return new List(__assign({}, value, { range: value.range && values_1.RangeValue.fromJSON(value.range) || undefined, itemSchema: value.itemSchema.map(function (i) {
96
+ return utils_1.createComponentFromJSON(i.type, i);
97
+ }) }));
98
+ };
99
+ List.isInstance = function (instance) {
100
+ return instance.type === List.type;
101
+ };
102
+ List.type = 'list';
103
+ return List;
104
+ }(base_1.BaseElement));
105
+ exports.List = List;
@@ -0,0 +1,22 @@
1
+ export declare namespace ValueError {
2
+ type Required = SimpleValueError<'required'>;
3
+ type Min = PayloadValueError<'min', number>;
4
+ type Max = PayloadValueError<'max', number>;
5
+ type InvalidValue = SimpleValueError<'invalidValue'>;
6
+ }
7
+ export interface SimpleValueError<E extends string> {
8
+ type: E;
9
+ }
10
+ export interface PayloadValueError<E extends string, P> extends SimpleValueError<E> {
11
+ payload: P;
12
+ }
13
+ export declare type ValueError<E extends string = string, P = {}> = SimpleValueError<E> | PayloadValueError<E, P>;
14
+ export declare namespace Errors {
15
+ const isMap: (errors: Errors<ValueError<string, {}>>) => errors is ErrorsMap<ValueError<string, {}>>;
16
+ const isArray: (errors: Errors<ValueError<string, {}>>) => errors is ValueError<string, {}>[];
17
+ const any: (errors: ErrorsMap<ValueError<string, {}>> | ValueError<string, {}>[] | undefined) => boolean;
18
+ }
19
+ export declare type Errors<E extends ValueError = ValueError> = E[] | ErrorsMap;
20
+ export interface ErrorsMap<E extends ValueError = ValueError> {
21
+ [id: string]: Errors | undefined;
22
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var Errors;
4
+ (function (Errors) {
5
+ Errors.isMap = function (errors) {
6
+ return !Array.isArray(errors);
7
+ };
8
+ Errors.isArray = function (errors) {
9
+ return Array.isArray(errors);
10
+ };
11
+ Errors.any = function (errors) {
12
+ if (!errors)
13
+ return false;
14
+ if (Array.isArray(errors)) {
15
+ return errors.length > 0;
16
+ }
17
+ else {
18
+ return Object.keys(errors).some(function (k) {
19
+ return Errors.any(errors[k]);
20
+ });
21
+ }
22
+ };
23
+ })(Errors = exports.Errors || (exports.Errors = {}));
@@ -0,0 +1,29 @@
1
+ import { List, Group, DynamicMatrix } from './containers';
2
+ export { Group, List, DynamicMatrix };
3
+ import { InputValue } from './inputs';
4
+ import { ErrorsMap } from './errors';
5
+ export declare namespace Configuration {
6
+ type Value = {
7
+ [key: string]: InputValue;
8
+ };
9
+ type Options = {
10
+ schema: (Group | List | DynamicMatrix)[];
11
+ durationFormula?: string;
12
+ };
13
+ }
14
+ export declare class Configuration {
15
+ readonly schema: (Group | List | DynamicMatrix)[];
16
+ readonly durationFormula: string | undefined;
17
+ constructor(options: Configuration.Options);
18
+ validate(state: Configuration.Value): ErrorsMap;
19
+ toJSON(): {
20
+ durationFormula: string | undefined;
21
+ schema: (Group | List | DynamicMatrix)[];
22
+ };
23
+ getDuration(_values: Configuration.Value): number | undefined;
24
+ static fromJSON(input: any): Configuration;
25
+ readonly declarationFileString: string;
26
+ }
27
+ export * from './inputs';
28
+ export * from './ui';
29
+ export * from './values';
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ function __export(m) {
3
+ for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
4
+ }
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ var containers_1 = require("./containers");
7
+ exports.List = containers_1.List;
8
+ exports.Group = containers_1.Group;
9
+ exports.DynamicMatrix = containers_1.DynamicMatrix;
10
+ var typeDefs_1 = require("./utils/typeDefs");
11
+ var inputs_1 = require("./inputs");
12
+ var Configuration = (function () {
13
+ function Configuration(options) {
14
+ this.schema = options.schema;
15
+ this.durationFormula = options.durationFormula;
16
+ }
17
+ Configuration.prototype.validate = function (state) {
18
+ var errors = {};
19
+ this.schema.forEach(function (container) {
20
+ var visible = container.shouldShow(state);
21
+ if (visible === false)
22
+ return;
23
+ if (containers_1.Group.isInstance(container)) {
24
+ var groupErrors_1 = {};
25
+ // Validate each input in a group.
26
+ container.items.forEach(function (input) {
27
+ if (inputs_1.isInput(input)) {
28
+ var inputErrors = input.validate(state[input.id], state);
29
+ groupErrors_1[input.id] = inputErrors;
30
+ }
31
+ });
32
+ errors[container.id] = groupErrors_1;
33
+ }
34
+ else if (containers_1.List.isInstance(container)) {
35
+ // Validate the list.
36
+ errors[container.id] = container.validate(state[container.id], state);
37
+ }
38
+ else {
39
+ // Validate the dynamic matrix.
40
+ errors[container.id] = container.validate(state[container.id], state);
41
+ }
42
+ });
43
+ return errors;
44
+ };
45
+ Configuration.prototype.toJSON = function () {
46
+ var allIds = [];
47
+ this.schema.forEach(function (cont) {
48
+ allIds.push(cont.id);
49
+ if (containers_1.Group.isInstance(cont)) {
50
+ cont.items.forEach(function (item) {
51
+ if (item.hasOwnProperty('id'))
52
+ allIds.push(item.id);
53
+ });
54
+ }
55
+ });
56
+ var duplicatedIds = allIds.filter(function (e, i, s) { return s.indexOf(e) !== i; });
57
+ if (duplicatedIds.length > 0)
58
+ console.warn("Attention, your configuration has duplicated ids [\"" + duplicatedIds.join('", "') + "\"]. If it is not intentional please check it.");
59
+ return {
60
+ durationFormula: this.durationFormula,
61
+ schema: this.schema
62
+ };
63
+ };
64
+ Configuration.prototype.getDuration = function (_values) {
65
+ if (!this.durationFormula)
66
+ return undefined;
67
+ var jsEval = this.durationFormula;
68
+ try {
69
+ var regexp = new RegExp('{{(.*?)}}', 'ig');
70
+ jsEval = jsEval.replace(regexp, "_values.$1");
71
+ // tslint:disable-next-line
72
+ var time = eval(jsEval);
73
+ if (typeof time === 'number') {
74
+ // validate number
75
+ if (isNaN(time) || time < 4 || time >= 86400) {
76
+ console.warn("Computed time error: Number is not valid [" + time + "]");
77
+ return undefined;
78
+ }
79
+ return time;
80
+ }
81
+ else {
82
+ console.warn("Computed time error: Time expression result is not a number [\"" + typeof time + "\"]");
83
+ return undefined;
84
+ }
85
+ }
86
+ catch (e) {
87
+ console.warn('Computed time error: Unable to parse time expression:', jsEval, e);
88
+ return undefined;
89
+ }
90
+ };
91
+ Configuration.fromJSON = function (input) {
92
+ var schema = input.schema;
93
+ var durationFormula = input.durationFormula;
94
+ return new Configuration({
95
+ durationFormula: durationFormula,
96
+ schema: schema.map(function (i) {
97
+ switch (i.type) {
98
+ case containers_1.List.type:
99
+ return containers_1.List.fromJSON(i);
100
+ case containers_1.Group.type:
101
+ return containers_1.Group.fromJSON(i);
102
+ case containers_1.DynamicMatrix.type:
103
+ return containers_1.DynamicMatrix.fromJSON(i);
104
+ }
105
+ throw new Error("Invalid component type \"" + i.type + "\" in root configuration.");
106
+ })
107
+ });
108
+ };
109
+ Object.defineProperty(Configuration.prototype, "declarationFileString", {
110
+ get: function () {
111
+ var declarations = [];
112
+ this.schema.forEach(function (g) {
113
+ declarations = declarations.concat(g.valueTypeDef());
114
+ });
115
+ return "declare type VixonicData = {\n downloadsPath: string\n services: { [key: string]: { data?: any, updatedAt?: number } }\n parameters: VixonicParameters\n}\n\ndeclare type VixonicParameters = Partial<{\n " + typeDefs_1.defsMapToString(declarations) + "\n}>";
116
+ },
117
+ enumerable: true,
118
+ configurable: true
119
+ });
120
+ return Configuration;
121
+ }());
122
+ exports.Configuration = Configuration;
123
+ // Input components
124
+ __export(require("./inputs"));
125
+ // UI components
126
+ __export(require("./ui"));
127
+ // Values
128
+ __export(require("./values"));
@@ -0,0 +1,31 @@
1
+ import { Input, IInput } from '../base';
2
+ import { ValueError } from '../errors';
3
+ export interface IAutocomplete<T extends Autocomplete.Value> extends IInput {
4
+ items: AutocompleteItem<T>[];
5
+ description?: string;
6
+ required?: boolean;
7
+ defaultValue?: T;
8
+ }
9
+ export declare type AutocompleteItem<T> = {
10
+ label: string;
11
+ value: T;
12
+ };
13
+ export declare namespace Autocomplete {
14
+ type Error = ValueError.Required | ValueError.InvalidValue;
15
+ type Value = number | string;
16
+ }
17
+ export declare class Autocomplete<T extends Autocomplete.Value> extends Input<Autocomplete.Value, Autocomplete.Error> {
18
+ static type: string;
19
+ type: string;
20
+ readonly items: AutocompleteItem<T>[];
21
+ readonly description?: string;
22
+ readonly required?: boolean;
23
+ readonly multiple?: boolean;
24
+ readonly searchEnabled?: boolean;
25
+ readonly defaultValue?: T;
26
+ constructor(options: IAutocomplete<T>);
27
+ validateInput(value: T): Autocomplete.Error[];
28
+ isValidValue(value: any): value is T;
29
+ static fromJSON(value: IAutocomplete<any>): Autocomplete<any>;
30
+ valueTypeDef: () => string;
31
+ }
@@ -0,0 +1,49 @@
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 base_1 = require("../base");
14
+ var validation_1 = require("../utils/validation");
15
+ var Autocomplete = (function (_super) {
16
+ __extends(Autocomplete, _super);
17
+ function Autocomplete(options) {
18
+ var _this = _super.call(this, options) || this;
19
+ _this.type = Autocomplete.type;
20
+ _this.valueTypeDef = function () {
21
+ var options = _this.items.map(function (i) {
22
+ if (typeof i.value === 'string')
23
+ return "'" + i.value + "'";
24
+ else
25
+ return i.value.toString();
26
+ }).join(' | ');
27
+ return _this.multiple ? "(" + options + ")[]" : options;
28
+ };
29
+ _this.description = options.description;
30
+ _this.items = options.items;
31
+ _this.required = options.required;
32
+ _this.defaultValue = options.defaultValue;
33
+ return _this;
34
+ }
35
+ Autocomplete.prototype.validateInput = function (value) {
36
+ var errors = [];
37
+ errors = errors.concat(validation_1.Validator.required(value, this.required, true));
38
+ return errors;
39
+ };
40
+ Autocomplete.prototype.isValidValue = function (value) {
41
+ return Array.isArray(value) || typeof value === 'string' || typeof value === 'number';
42
+ };
43
+ Autocomplete.fromJSON = function (value) {
44
+ return new Autocomplete(value);
45
+ };
46
+ Autocomplete.type = 'autocomplete';
47
+ return Autocomplete;
48
+ }(base_1.Input));
49
+ exports.Autocomplete = Autocomplete;
@@ -0,0 +1,23 @@
1
+ import { Input, IInput } from '../base';
2
+ import { ValueError, SimpleValueError } from '../errors';
3
+ export interface IColorPicker extends IInput {
4
+ description?: string;
5
+ required?: boolean;
6
+ output?: 'hex' | 'rgba';
7
+ }
8
+ export declare namespace ColorPicker {
9
+ type Error = ValueError.Required | ValueError.InvalidValue;
10
+ type Value = string;
11
+ }
12
+ export declare class ColorPicker extends Input<ColorPicker.Value, ColorPicker.Error> {
13
+ static type: string;
14
+ type: string;
15
+ readonly description?: string;
16
+ readonly required?: boolean;
17
+ readonly output: 'hex' | 'rgba' | 'auto';
18
+ constructor(options: IColorPicker);
19
+ validateInput(value: string): (SimpleValueError<"required"> | SimpleValueError<"invalidValue">)[];
20
+ isValidValue(value: any): value is ColorPicker.Value;
21
+ static fromJSON: (value: IColorPicker) => ColorPicker;
22
+ valueTypeDef: () => string;
23
+ }
@@ -0,0 +1,42 @@
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 base_1 = require("../base");
14
+ var validation_1 = require("../utils/validation");
15
+ var ColorPicker = (function (_super) {
16
+ __extends(ColorPicker, _super);
17
+ function ColorPicker(options) {
18
+ var _this = _super.call(this, options) || this;
19
+ _this.type = ColorPicker.type;
20
+ _this.valueTypeDef = function () {
21
+ return "string";
22
+ };
23
+ _this.description = options.description;
24
+ _this.required = options.required;
25
+ _this.output = options.output || 'auto';
26
+ return _this;
27
+ }
28
+ ColorPicker.prototype.validateInput = function (value) {
29
+ var errors = [];
30
+ errors = errors.concat(validation_1.Validator.required(value, this.required));
31
+ return errors;
32
+ };
33
+ ColorPicker.prototype.isValidValue = function (value) {
34
+ return typeof value === 'string';
35
+ };
36
+ ColorPicker.type = 'color-picker';
37
+ ColorPicker.fromJSON = function (value) {
38
+ return new ColorPicker(value);
39
+ };
40
+ return ColorPicker;
41
+ }(base_1.Input));
42
+ exports.ColorPicker = ColorPicker;
@@ -0,0 +1,35 @@
1
+ import { Input, IInput, Omit } from '../base';
2
+ import { DateRangeValue } from '../values';
3
+ import { ValueError } from '../errors';
4
+ export interface IDateInput extends IInput {
5
+ description?: string;
6
+ required?: boolean;
7
+ range?: DateRangeValue;
8
+ mode?: Mode;
9
+ displayClass?: DisplayClass;
10
+ displayFormat?: string;
11
+ }
12
+ export declare type Mode = 'date' | 'datetime-local' | 'time';
13
+ export declare type DisplayClass = 'fromNow' | 'toNow' | 'default';
14
+ export interface DateInputJSON extends Omit<IDateInput, 'range'> {
15
+ range?: string;
16
+ }
17
+ export declare namespace DateInput {
18
+ type Error = ValueError.Required | ValueError.Max | ValueError.Min | ValueError.InvalidValue;
19
+ type Value = string;
20
+ }
21
+ export declare class DateInput extends Input<DateInput.Value, DateInput.Error> {
22
+ static type: string;
23
+ type: string;
24
+ readonly description?: string;
25
+ readonly required?: boolean;
26
+ readonly range?: DateRangeValue | undefined;
27
+ readonly mode?: Mode;
28
+ readonly displayClass?: DisplayClass;
29
+ readonly displayFormat?: string;
30
+ constructor(options: IDateInput);
31
+ validateInput(value: string): DateInput.Error[];
32
+ isValidValue(value: any): value is DateInput.Value;
33
+ static fromJSON(value: DateInputJSON): DateInput;
34
+ valueTypeDef: () => string;
35
+ }
@@ -0,0 +1,78 @@
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 values_1 = require("../values");
23
+ var validation_1 = require("../utils/validation");
24
+ var DateInput = (function (_super) {
25
+ __extends(DateInput, _super);
26
+ function DateInput(options) {
27
+ var _this = _super.call(this, options) || this;
28
+ _this.type = DateInput.type;
29
+ _this.valueTypeDef = function () { return 'string'; };
30
+ _this.description = options.description;
31
+ _this.required = options.required;
32
+ _this.range = options.range;
33
+ _this.mode = options.mode;
34
+ _this.displayClass = options.displayClass;
35
+ _this.displayFormat = options.displayFormat;
36
+ return _this;
37
+ }
38
+ DateInput.prototype.validateInput = function (value) {
39
+ var errors = [];
40
+ errors = errors.concat(validation_1.Validator.required(value, this.required));
41
+ if (this.range) {
42
+ if (this.mode !== 'time') {
43
+ var dateValue = new Date(value);
44
+ if (this.range.max) {
45
+ var max = new Date(this.range.max);
46
+ errors = errors.concat(validation_1.Validator.max(dateValue.getTime(), max.getTime()));
47
+ }
48
+ if (this.range.min) {
49
+ var min = new Date(this.range.min);
50
+ errors = errors.concat(validation_1.Validator.min(dateValue.getTime(), min.getTime()));
51
+ }
52
+ }
53
+ else {
54
+ var dateValue = value && Number(value.replace(':', ''));
55
+ if (typeof dateValue === 'number' && !isNaN(dateValue)) {
56
+ var min = this.range.min && Number(this.range.min.replace(':', ''));
57
+ if (typeof min === 'number' && !isNaN(min))
58
+ errors = errors.concat(validation_1.Validator.min(dateValue, min));
59
+ var max = this.range.max && Number(this.range.max.replace(':', ''));
60
+ if (typeof max === 'number' && !isNaN(max))
61
+ errors = errors.concat(validation_1.Validator.max(dateValue, max));
62
+ }
63
+ }
64
+ }
65
+ return errors;
66
+ };
67
+ DateInput.prototype.isValidValue = function (value) {
68
+ return this.mode === 'time'
69
+ ? typeof value === 'string'
70
+ : !isNaN(Date.parse(value));
71
+ };
72
+ DateInput.fromJSON = function (value) {
73
+ return new DateInput(__assign({}, value, { range: value.range && values_1.DateRangeValue.fromJSON(value.range) || undefined }));
74
+ };
75
+ DateInput.type = 'date-input';
76
+ return DateInput;
77
+ }(base_1.Input));
78
+ exports.DateInput = DateInput;
@@ -0,0 +1,24 @@
1
+ import { TextArea } from './text-area';
2
+ import { TextFormat } from './text-format';
3
+ import { TextInput } from './text-input';
4
+ import { Autocomplete } from './autocomplete';
5
+ import { SelectInput } from './select-input';
6
+ import { Switch } from './switch';
7
+ import { NumberInput } from './number-input';
8
+ import { ColorPicker } from './color-picker';
9
+ import { DateInput } from './date-input';
10
+ import { SelectAssetKna } from './select-asset-kna';
11
+ import { Slider } from './slider';
12
+ import { ServiceInput } from './service-input';
13
+ export { TextFormat, TextInput, SelectInput, Switch, TextArea, Autocomplete, NumberInput, ColorPicker, DateInput, SelectAssetKna, Slider, ServiceInput };
14
+ export declare type AnyJson = boolean | number | string | null | JsonArray | JsonMap | undefined;
15
+ export interface JsonMap {
16
+ [key: string]: AnyJson | undefined;
17
+ }
18
+ export interface JsonArray extends Array<AnyJson> {
19
+ }
20
+ export declare type InputValue = AnyJson;
21
+ export declare type InputComponent = TextInput | TextFormat | SelectInput<string | number> | TextArea | Switch | Autocomplete<string | number> | NumberInput | ColorPicker | DateInput | SelectAssetKna | Slider | ServiceInput;
22
+ export declare const allInputs: (typeof TextInput | typeof TextFormat | typeof Autocomplete | typeof Switch | typeof NumberInput | typeof ColorPicker | typeof DateInput | typeof SelectAssetKna | typeof Slider | typeof ServiceInput)[];
23
+ export declare const isInput: (arg: any) => arg is InputComponent;
24
+ export declare const isInputInstance: <T>(arg: any, type: string | string[]) => arg is T;