polymatica-widget 2.1.10 → 2.1.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/__internal__/constants.d.ts +1 -0
- package/__internal__/constants.js +4 -0
- package/__internal__/widget-options-tools.d.ts +4 -0
- package/__internal__/widget-options-tools.js +63 -0
- package/__internal__/widget-options.d.ts +43 -10
- package/__internal__/widget-options.js +7 -61
- package/config.d.ts +41 -21
- package/config.js +24 -12
- package/package.json +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const widgetOptionsTargetKey = "6ba1fa0f-7eab-49f8-80ef-0fed376661e2";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { WidgetOption, WidgetOptionType } from "./widget-options";
|
|
2
|
+
export declare function setWidgetOptionsTarget(options: WidgetOption[]): void;
|
|
3
|
+
export declare function valueConversion(type: WidgetOptionType, source: any): any;
|
|
4
|
+
export declare function getSpan(source?: number): number;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSpan = exports.valueConversion = exports.setWidgetOptionsTarget = void 0;
|
|
4
|
+
const config_1 = require("../config");
|
|
5
|
+
const constants_1 = require("./constants");
|
|
6
|
+
const widget_options_1 = require("./widget-options");
|
|
7
|
+
function setWidgetOptionsTarget(options) {
|
|
8
|
+
globalThis[constants_1.widgetOptionsTargetKey] = options;
|
|
9
|
+
}
|
|
10
|
+
exports.setWidgetOptionsTarget = setWidgetOptionsTarget;
|
|
11
|
+
function valueConversion(type, source) {
|
|
12
|
+
switch (type) {
|
|
13
|
+
case widget_options_1.WidgetOptionType.Text:
|
|
14
|
+
case widget_options_1.WidgetOptionType.Title:
|
|
15
|
+
return source ? String(source) : "";
|
|
16
|
+
case widget_options_1.WidgetOptionType.Number:
|
|
17
|
+
case widget_options_1.WidgetOptionType.Range:
|
|
18
|
+
return source ? parseFloat(source) : 0;
|
|
19
|
+
case widget_options_1.WidgetOptionType.Integer:
|
|
20
|
+
return source ? parseInt(source, 10) : 0;
|
|
21
|
+
case widget_options_1.WidgetOptionType.Interval:
|
|
22
|
+
if (source)
|
|
23
|
+
return {
|
|
24
|
+
from: parseFloat(source.from) || 0,
|
|
25
|
+
to: parseFloat(source.to) || 0,
|
|
26
|
+
};
|
|
27
|
+
return { from: 0, to: 0 };
|
|
28
|
+
case widget_options_1.WidgetOptionType.Date:
|
|
29
|
+
case widget_options_1.WidgetOptionType.DateTime:
|
|
30
|
+
return parseDate(source);
|
|
31
|
+
case widget_options_1.WidgetOptionType.Time:
|
|
32
|
+
return source || "00:00";
|
|
33
|
+
case widget_options_1.WidgetOptionType.DateInterval:
|
|
34
|
+
if (source)
|
|
35
|
+
return {
|
|
36
|
+
from: parseDate(source.from),
|
|
37
|
+
to: parseDate(source.to),
|
|
38
|
+
};
|
|
39
|
+
return { from: new Date(), to: new Date() };
|
|
40
|
+
case widget_options_1.WidgetOptionType.ColorPicker:
|
|
41
|
+
case widget_options_1.WidgetOptionType.Radio:
|
|
42
|
+
case widget_options_1.WidgetOptionType.Select:
|
|
43
|
+
return source;
|
|
44
|
+
case widget_options_1.WidgetOptionType.Checkbox:
|
|
45
|
+
return Boolean(source);
|
|
46
|
+
default:
|
|
47
|
+
return "";
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
exports.valueConversion = valueConversion;
|
|
51
|
+
function parseDate(source) {
|
|
52
|
+
const data = new Date(source);
|
|
53
|
+
return isNaN(data.valueOf()) ? new Date() : data;
|
|
54
|
+
}
|
|
55
|
+
function getSpan(source) {
|
|
56
|
+
const span = source | 0;
|
|
57
|
+
if (span > config_1.STEP)
|
|
58
|
+
return config_1.STEP;
|
|
59
|
+
if (span <= 0)
|
|
60
|
+
return config_1.STEP;
|
|
61
|
+
return span;
|
|
62
|
+
}
|
|
63
|
+
exports.getSpan = getSpan;
|
|
@@ -4,6 +4,8 @@ export declare enum WidgetOptionType {
|
|
|
4
4
|
Label = "label",
|
|
5
5
|
Spacer = "spacer",
|
|
6
6
|
LineHorizontal = "line-horizontal",
|
|
7
|
+
Tabs = "tabs",
|
|
8
|
+
TabPanels = "tab-panels",
|
|
7
9
|
Text = "text",
|
|
8
10
|
Number = "number",
|
|
9
11
|
Integer = "integer",
|
|
@@ -14,22 +16,53 @@ export declare enum WidgetOptionType {
|
|
|
14
16
|
DateTime = "datetime",
|
|
15
17
|
DateInterval = "date-interval",
|
|
16
18
|
Checkbox = "checkbox",
|
|
19
|
+
ColorPicker = "color-picker",
|
|
17
20
|
Radio = "radio",
|
|
18
21
|
RadioButtons = "radio-buttons",
|
|
19
22
|
Select = "select",
|
|
20
|
-
|
|
23
|
+
Suggestion = "suggestion",
|
|
24
|
+
Button = "button"
|
|
21
25
|
}
|
|
22
|
-
export interface
|
|
26
|
+
export interface WidgetOption {
|
|
23
27
|
type: WidgetOptionType;
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
28
|
+
}
|
|
29
|
+
export interface Label extends WidgetOption {
|
|
30
|
+
type: WidgetOptionType.Title | WidgetOptionType.Label;
|
|
31
|
+
label: Text;
|
|
32
|
+
hint?: Text;
|
|
33
|
+
}
|
|
34
|
+
export interface Spacer extends WidgetOption {
|
|
35
|
+
type: WidgetOptionType.Spacer;
|
|
36
|
+
span: number;
|
|
37
|
+
}
|
|
38
|
+
export interface Tabs extends WidgetOption {
|
|
39
|
+
type: WidgetOptionType.Tabs;
|
|
40
|
+
labels: {
|
|
27
41
|
label: Text;
|
|
28
|
-
value: string
|
|
42
|
+
value: string;
|
|
29
43
|
}[];
|
|
44
|
+
}
|
|
45
|
+
export interface TabPanels extends WidgetOption {
|
|
46
|
+
type: WidgetOptionType.TabPanels;
|
|
47
|
+
items: Record<string, () => void>;
|
|
48
|
+
}
|
|
49
|
+
export interface Control extends WidgetOption {
|
|
50
|
+
type: WidgetOptionType.Text | WidgetOptionType.Number | WidgetOptionType.Integer | WidgetOptionType.Range | WidgetOptionType.Interval | WidgetOptionType.Date | WidgetOptionType.Time | WidgetOptionType.DateTime | WidgetOptionType.DateInterval | WidgetOptionType.Checkbox | WidgetOptionType.ColorPicker;
|
|
51
|
+
key: string;
|
|
52
|
+
label: Text;
|
|
30
53
|
span?: number;
|
|
31
54
|
}
|
|
32
|
-
export
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
55
|
+
export interface ControlWithOptions extends WidgetOption {
|
|
56
|
+
type: WidgetOptionType.Radio | WidgetOptionType.RadioButtons | WidgetOptionType.Select | WidgetOptionType.Suggestion;
|
|
57
|
+
key: string;
|
|
58
|
+
label: Text;
|
|
59
|
+
options: {
|
|
60
|
+
label: Text;
|
|
61
|
+
value: string | number | boolean;
|
|
62
|
+
}[];
|
|
63
|
+
}
|
|
64
|
+
export interface Button extends WidgetOption {
|
|
65
|
+
type: WidgetOptionType.Button;
|
|
66
|
+
label: Text;
|
|
67
|
+
target: string;
|
|
68
|
+
}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const config_1 = require("../config");
|
|
3
|
+
exports.WidgetOptionType = void 0;
|
|
5
4
|
var WidgetOptionType;
|
|
6
5
|
(function (WidgetOptionType) {
|
|
7
6
|
// Layout
|
|
@@ -9,6 +8,8 @@ var WidgetOptionType;
|
|
|
9
8
|
WidgetOptionType["Label"] = "label";
|
|
10
9
|
WidgetOptionType["Spacer"] = "spacer";
|
|
11
10
|
WidgetOptionType["LineHorizontal"] = "line-horizontal";
|
|
11
|
+
WidgetOptionType["Tabs"] = "tabs";
|
|
12
|
+
WidgetOptionType["TabPanels"] = "tab-panels";
|
|
12
13
|
// Controls
|
|
13
14
|
WidgetOptionType["Text"] = "text";
|
|
14
15
|
WidgetOptionType["Number"] = "number";
|
|
@@ -20,66 +21,11 @@ var WidgetOptionType;
|
|
|
20
21
|
WidgetOptionType["DateTime"] = "datetime";
|
|
21
22
|
WidgetOptionType["DateInterval"] = "date-interval";
|
|
22
23
|
WidgetOptionType["Checkbox"] = "checkbox";
|
|
24
|
+
WidgetOptionType["ColorPicker"] = "color-picker";
|
|
23
25
|
WidgetOptionType["Radio"] = "radio";
|
|
24
26
|
WidgetOptionType["RadioButtons"] = "radio-buttons";
|
|
25
27
|
WidgetOptionType["Select"] = "select";
|
|
26
|
-
WidgetOptionType["
|
|
28
|
+
WidgetOptionType["Suggestion"] = "suggestion";
|
|
29
|
+
// Actions
|
|
30
|
+
WidgetOptionType["Button"] = "button";
|
|
27
31
|
})(WidgetOptionType = exports.WidgetOptionType || (exports.WidgetOptionType = {}));
|
|
28
|
-
exports.widgetOptionsTargetKey = "6ba1fa0f-7eab-49f8-80ef-0fed376661e2";
|
|
29
|
-
function setWidgetOptionsTarget(options) {
|
|
30
|
-
globalThis[exports.widgetOptionsTargetKey] = options;
|
|
31
|
-
}
|
|
32
|
-
exports.setWidgetOptionsTarget = setWidgetOptionsTarget;
|
|
33
|
-
function valueConversion(type, source) {
|
|
34
|
-
switch (type) {
|
|
35
|
-
case WidgetOptionType.Text:
|
|
36
|
-
case WidgetOptionType.Title:
|
|
37
|
-
return source ? String(source) : "";
|
|
38
|
-
case WidgetOptionType.Number:
|
|
39
|
-
case WidgetOptionType.Range:
|
|
40
|
-
return source ? parseFloat(source) : 0;
|
|
41
|
-
case WidgetOptionType.Integer:
|
|
42
|
-
return source ? parseInt(source, 10) : 0;
|
|
43
|
-
case WidgetOptionType.Interval:
|
|
44
|
-
if (source)
|
|
45
|
-
return {
|
|
46
|
-
from: parseFloat(source.from) || 0,
|
|
47
|
-
to: parseFloat(source.to) || 0,
|
|
48
|
-
};
|
|
49
|
-
return { from: 0, to: 0 };
|
|
50
|
-
case WidgetOptionType.Date:
|
|
51
|
-
case WidgetOptionType.DateTime:
|
|
52
|
-
return parseDate(source);
|
|
53
|
-
case WidgetOptionType.Time:
|
|
54
|
-
return source || "00:00";
|
|
55
|
-
case WidgetOptionType.DateInterval:
|
|
56
|
-
if (source)
|
|
57
|
-
return {
|
|
58
|
-
from: parseDate(source.from),
|
|
59
|
-
to: parseDate(source.to),
|
|
60
|
-
};
|
|
61
|
-
return { from: new Date(), to: new Date() };
|
|
62
|
-
case WidgetOptionType.ColorPicker:
|
|
63
|
-
case WidgetOptionType.Radio:
|
|
64
|
-
case WidgetOptionType.Select:
|
|
65
|
-
return source;
|
|
66
|
-
case WidgetOptionType.Checkbox:
|
|
67
|
-
return Boolean(source);
|
|
68
|
-
default:
|
|
69
|
-
return "";
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
exports.valueConversion = valueConversion;
|
|
73
|
-
function parseDate(source) {
|
|
74
|
-
const data = new Date(source);
|
|
75
|
-
return isNaN(data.valueOf()) ? new Date() : data;
|
|
76
|
-
}
|
|
77
|
-
function getSpan(source) {
|
|
78
|
-
const span = source | 0;
|
|
79
|
-
if (span > config_1.STEP)
|
|
80
|
-
return config_1.STEP;
|
|
81
|
-
if (span <= 0)
|
|
82
|
-
return config_1.STEP;
|
|
83
|
-
return span;
|
|
84
|
-
}
|
|
85
|
-
exports.getSpan = getSpan;
|
package/config.d.ts
CHANGED
|
@@ -51,30 +51,42 @@ export interface Block {
|
|
|
51
51
|
aggregation?: boolean;
|
|
52
52
|
max?: number;
|
|
53
53
|
}
|
|
54
|
+
interface CommonOptionsConfig {
|
|
55
|
+
change?(options: Options): void;
|
|
56
|
+
onAction?(target: string): void;
|
|
57
|
+
default: Options;
|
|
58
|
+
defaultInvalid?: boolean;
|
|
59
|
+
validators?: OptionsValidation;
|
|
60
|
+
}
|
|
54
61
|
export interface OptionsConfig {
|
|
55
|
-
options: {
|
|
56
|
-
change?: (options: Options) => void;
|
|
62
|
+
options: (CommonOptionsConfig & {
|
|
57
63
|
render(options: Options): void;
|
|
58
|
-
default: Options;
|
|
59
|
-
validators?: OptionsValidation;
|
|
60
64
|
dataDependent?: false;
|
|
61
|
-
} | {
|
|
62
|
-
change?: (options: Options) => void;
|
|
65
|
+
}) | (CommonOptionsConfig & {
|
|
63
66
|
render(options: Options, data: unknown): void;
|
|
64
|
-
default: Options;
|
|
65
|
-
validators?: OptionsValidation;
|
|
66
67
|
dataDependent: true;
|
|
67
|
-
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
export interface OptionsValidation {
|
|
71
|
+
[key: string]: OptionsValidator;
|
|
72
|
+
}
|
|
73
|
+
export interface OptionsValidator {
|
|
74
|
+
(value: any): Text | null;
|
|
68
75
|
}
|
|
69
76
|
export declare const STEP = 24;
|
|
70
|
-
export declare function title(label: Text,
|
|
71
|
-
|
|
72
|
-
}): void;
|
|
73
|
-
export declare function label(label: Text, params?: {
|
|
74
|
-
hint: Text;
|
|
75
|
-
}): void;
|
|
77
|
+
export declare function title(label: Text, hint?: Text): void;
|
|
78
|
+
export declare function label(label: Text, hint?: Text): void;
|
|
76
79
|
export declare function spacer(span: number): void;
|
|
77
80
|
export declare function line(): void;
|
|
81
|
+
export declare function tabs(params: {
|
|
82
|
+
labels: {
|
|
83
|
+
label: Text;
|
|
84
|
+
value: string;
|
|
85
|
+
}[];
|
|
86
|
+
}): void;
|
|
87
|
+
export declare function tabPanels(params: {
|
|
88
|
+
items: Record<string, () => void>;
|
|
89
|
+
}): void;
|
|
78
90
|
export declare function text(params: {
|
|
79
91
|
key: string;
|
|
80
92
|
label: Text;
|
|
@@ -147,14 +159,22 @@ export declare function select(params: {
|
|
|
147
159
|
}[];
|
|
148
160
|
span?: number;
|
|
149
161
|
}): void;
|
|
162
|
+
export declare function suggestion(params: {
|
|
163
|
+
key: string;
|
|
164
|
+
label: Text;
|
|
165
|
+
options: {
|
|
166
|
+
label: Text;
|
|
167
|
+
value: string;
|
|
168
|
+
}[];
|
|
169
|
+
span?: number;
|
|
170
|
+
}): void;
|
|
150
171
|
export declare function colorPicker(params: {
|
|
151
172
|
key: string;
|
|
152
173
|
label: Text;
|
|
153
174
|
span?: number;
|
|
154
175
|
}): void;
|
|
155
|
-
export
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
}
|
|
176
|
+
export declare function button(params: {
|
|
177
|
+
label: Text;
|
|
178
|
+
target: string;
|
|
179
|
+
}): void;
|
|
180
|
+
export {};
|
package/config.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.colorPicker = exports.select = exports.radioButton = exports.radio = exports.checkbox = exports.dateTime = exports.time = exports.date = exports.interval = exports.range = exports.integer = exports.number = exports.text = exports.line = exports.spacer = exports.label = exports.title = exports.STEP = exports.Method = exports.Size = void 0;
|
|
3
|
+
exports.button = exports.colorPicker = exports.suggestion = exports.select = exports.radioButton = exports.radio = exports.checkbox = exports.dateTime = exports.time = exports.date = exports.interval = exports.range = exports.integer = exports.number = exports.text = exports.tabPanels = exports.tabs = exports.line = exports.spacer = exports.label = exports.title = exports.STEP = exports.Method = exports.Size = void 0;
|
|
4
|
+
const constants_1 = require("./__internal__/constants");
|
|
4
5
|
const widget_options_1 = require("./__internal__/widget-options");
|
|
5
6
|
// enums
|
|
6
7
|
var Size;
|
|
@@ -18,25 +19,19 @@ var Method;
|
|
|
18
19
|
// widget options
|
|
19
20
|
exports.STEP = 24;
|
|
20
21
|
// layout
|
|
21
|
-
function title(label,
|
|
22
|
-
const options = [];
|
|
23
|
-
if (params === null || params === void 0 ? void 0 : params.hint)
|
|
24
|
-
options.push({ label: params.hint, value: 0 });
|
|
22
|
+
function title(label, hint) {
|
|
25
23
|
push({
|
|
26
24
|
type: widget_options_1.WidgetOptionType.Title,
|
|
27
25
|
label,
|
|
28
|
-
|
|
26
|
+
hint,
|
|
29
27
|
});
|
|
30
28
|
}
|
|
31
29
|
exports.title = title;
|
|
32
|
-
function label(label,
|
|
33
|
-
const options = [];
|
|
34
|
-
if (params === null || params === void 0 ? void 0 : params.hint)
|
|
35
|
-
options.push({ label: params.hint, value: 0 });
|
|
30
|
+
function label(label, hint) {
|
|
36
31
|
push({
|
|
37
32
|
type: widget_options_1.WidgetOptionType.Label,
|
|
38
33
|
label,
|
|
39
|
-
|
|
34
|
+
hint,
|
|
40
35
|
});
|
|
41
36
|
}
|
|
42
37
|
exports.label = label;
|
|
@@ -48,6 +43,14 @@ function line() {
|
|
|
48
43
|
push({ type: widget_options_1.WidgetOptionType.LineHorizontal });
|
|
49
44
|
}
|
|
50
45
|
exports.line = line;
|
|
46
|
+
function tabs(params) {
|
|
47
|
+
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Tabs }));
|
|
48
|
+
}
|
|
49
|
+
exports.tabs = tabs;
|
|
50
|
+
function tabPanels(params) {
|
|
51
|
+
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.TabPanels }));
|
|
52
|
+
}
|
|
53
|
+
exports.tabPanels = tabPanels;
|
|
51
54
|
// controls
|
|
52
55
|
function text(params) {
|
|
53
56
|
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Text }));
|
|
@@ -97,11 +100,20 @@ function select(params) {
|
|
|
97
100
|
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Select }));
|
|
98
101
|
}
|
|
99
102
|
exports.select = select;
|
|
103
|
+
function suggestion(params) {
|
|
104
|
+
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Select }));
|
|
105
|
+
}
|
|
106
|
+
exports.suggestion = suggestion;
|
|
100
107
|
function colorPicker(params) {
|
|
101
108
|
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.ColorPicker }));
|
|
102
109
|
}
|
|
103
110
|
exports.colorPicker = colorPicker;
|
|
111
|
+
// actions
|
|
112
|
+
function button(params) {
|
|
113
|
+
push(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Button }));
|
|
114
|
+
}
|
|
115
|
+
exports.button = button;
|
|
104
116
|
function push(option) {
|
|
105
|
-
const target = globalThis[
|
|
117
|
+
const target = globalThis[constants_1.widgetOptionsTargetKey];
|
|
106
118
|
target.push(option);
|
|
107
119
|
}
|