polymatica-widget 0.7.0 → 2.0.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.
- package/LICENSE +15 -0
- package/README.md +6 -0
- package/__internal__/io.d.ts +55 -0
- package/__internal__/io.js +16 -0
- package/__internal__/widget-options.d.ts +32 -0
- package/__internal__/widget-options.js +79 -0
- package/config.d.ts +5 -0
- package/config.js +2 -0
- package/dataset.d.ts +16 -0
- package/dataset.js +13 -0
- package/declare.d.ts +1 -0
- package/declare.js +122 -0
- package/index.d.ts +7 -0
- package/index.js +19 -1
- package/locale.d.ts +2 -0
- package/locale.js +2 -0
- package/package.json +7 -4
- package/theme.d.ts +13 -0
- package/theme.js +2 -0
- package/widget-config.d.ts +129 -0
- package/widget-config.js +78 -0
- package/widget.d.ts +47 -0
- package/widget.js +10 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
ISC License
|
|
2
|
+
|
|
3
|
+
Copyright 2021 Polymatica
|
|
4
|
+
|
|
5
|
+
Permission to use, copy, modify, and/or distribute this software for any
|
|
6
|
+
purpose with or without fee is hereby granted, provided that the above
|
|
7
|
+
copyright notice and this permission notice appear in all copies.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
10
|
+
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
11
|
+
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
12
|
+
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
13
|
+
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
14
|
+
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
15
|
+
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
# Polymatica Widget SDK
|
|
2
|
+
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
6
|
+
> Pre-Alpha
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { Locale } from '../locale';
|
|
2
|
+
import { Theme } from '../theme';
|
|
3
|
+
import { Dataset, Options } from '../widget';
|
|
4
|
+
export declare enum Input {
|
|
5
|
+
Change = "poly.input.change",
|
|
6
|
+
ChangeLang = "poly.input.changeLang",
|
|
7
|
+
ChangeTheme = "poly.input.changeTheme",
|
|
8
|
+
Highlight = "poly.input.highlight"
|
|
9
|
+
}
|
|
10
|
+
export declare enum Output {
|
|
11
|
+
Init = "poly.output.init",
|
|
12
|
+
Ready = "poly.output.ready",
|
|
13
|
+
Interact = "poly.output.interact"
|
|
14
|
+
}
|
|
15
|
+
export declare type InputDataset = Omit<Dataset, 'interact' | 'events'> & {
|
|
16
|
+
datasetId: number;
|
|
17
|
+
};
|
|
18
|
+
export interface InputSingleData {
|
|
19
|
+
readonly dataset: InputDataset;
|
|
20
|
+
}
|
|
21
|
+
export interface InputMultiData {
|
|
22
|
+
readonly datasets: {
|
|
23
|
+
[datasetKey: string]: InputDataset;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
export declare type InputRepeatable<T extends InputSingleData | InputMultiData> = T extends InputSingleData ? {
|
|
27
|
+
readonly datasets: InputDataset[];
|
|
28
|
+
} : {
|
|
29
|
+
readonly datasets: {
|
|
30
|
+
[datasetKey: string]: InputDataset | InputDataset[];
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export declare type InputData = InputSingleData | InputMultiData | InputRepeatable<InputSingleData> | InputRepeatable<InputMultiData>;
|
|
34
|
+
export interface InputParameter extends Record<Input, any> {
|
|
35
|
+
[Input.Change]: [InputData, Options];
|
|
36
|
+
[Input.ChangeLang]: Locale;
|
|
37
|
+
[Input.ChangeTheme]: Theme;
|
|
38
|
+
[Input.Highlight]: {
|
|
39
|
+
datasetId: number;
|
|
40
|
+
rowIndexArray: number[];
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
export interface OutputParameter extends Record<Output, any> {
|
|
44
|
+
[Output.Init]: void;
|
|
45
|
+
[Output.Ready]: void;
|
|
46
|
+
[Output.Interact]: {
|
|
47
|
+
datasetId: number;
|
|
48
|
+
dataIndex: number;
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
export interface OutputData {
|
|
52
|
+
token: string;
|
|
53
|
+
type: Output;
|
|
54
|
+
payload?: any;
|
|
55
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Output = exports.Input = void 0;
|
|
4
|
+
var Input;
|
|
5
|
+
(function (Input) {
|
|
6
|
+
Input["Change"] = "poly.input.change";
|
|
7
|
+
Input["ChangeLang"] = "poly.input.changeLang";
|
|
8
|
+
Input["ChangeTheme"] = "poly.input.changeTheme";
|
|
9
|
+
Input["Highlight"] = "poly.input.highlight";
|
|
10
|
+
})(Input = exports.Input || (exports.Input = {}));
|
|
11
|
+
var Output;
|
|
12
|
+
(function (Output) {
|
|
13
|
+
Output["Init"] = "poly.output.init";
|
|
14
|
+
Output["Ready"] = "poly.output.ready";
|
|
15
|
+
Output["Interact"] = "poly.output.interact";
|
|
16
|
+
})(Output = exports.Output || (exports.Output = {}));
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Text } from '../locale';
|
|
2
|
+
export declare enum WidgetOptionType {
|
|
3
|
+
Title = "title",
|
|
4
|
+
Label = "label",
|
|
5
|
+
Spacer = "spacer",
|
|
6
|
+
Text = "text",
|
|
7
|
+
Number = "number",
|
|
8
|
+
Integer = "integer",
|
|
9
|
+
Range = "range",
|
|
10
|
+
Interval = "interval",
|
|
11
|
+
Date = "date",
|
|
12
|
+
Time = "time",
|
|
13
|
+
DateTime = "datetime",
|
|
14
|
+
DateInterval = "date-interval",
|
|
15
|
+
Checkbox = "checkbox",
|
|
16
|
+
Radio = "radio",
|
|
17
|
+
RadioButtons = "radio-buttons",
|
|
18
|
+
Select = "select",
|
|
19
|
+
ColorPicker = "color-picker"
|
|
20
|
+
}
|
|
21
|
+
export interface WidgetOptionConfig {
|
|
22
|
+
type: WidgetOptionType;
|
|
23
|
+
key?: string;
|
|
24
|
+
label?: Text;
|
|
25
|
+
options?: {
|
|
26
|
+
label: Text;
|
|
27
|
+
value: string | number | boolean;
|
|
28
|
+
}[];
|
|
29
|
+
span?: number;
|
|
30
|
+
}
|
|
31
|
+
export declare function valueConversion(type: WidgetOptionType, source: any): any;
|
|
32
|
+
export declare function getSpan(source?: number): number;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getSpan = exports.valueConversion = exports.WidgetOptionType = void 0;
|
|
4
|
+
const widget_config_1 = require("../widget-config");
|
|
5
|
+
var WidgetOptionType;
|
|
6
|
+
(function (WidgetOptionType) {
|
|
7
|
+
// Layout
|
|
8
|
+
WidgetOptionType["Title"] = "title";
|
|
9
|
+
WidgetOptionType["Label"] = "label";
|
|
10
|
+
WidgetOptionType["Spacer"] = "spacer";
|
|
11
|
+
// Controls
|
|
12
|
+
WidgetOptionType["Text"] = "text";
|
|
13
|
+
WidgetOptionType["Number"] = "number";
|
|
14
|
+
WidgetOptionType["Integer"] = "integer";
|
|
15
|
+
WidgetOptionType["Range"] = "range";
|
|
16
|
+
WidgetOptionType["Interval"] = "interval";
|
|
17
|
+
WidgetOptionType["Date"] = "date";
|
|
18
|
+
WidgetOptionType["Time"] = "time";
|
|
19
|
+
WidgetOptionType["DateTime"] = "datetime";
|
|
20
|
+
WidgetOptionType["DateInterval"] = "date-interval";
|
|
21
|
+
WidgetOptionType["Checkbox"] = "checkbox";
|
|
22
|
+
WidgetOptionType["Radio"] = "radio";
|
|
23
|
+
WidgetOptionType["RadioButtons"] = "radio-buttons";
|
|
24
|
+
WidgetOptionType["Select"] = "select";
|
|
25
|
+
WidgetOptionType["ColorPicker"] = "color-picker";
|
|
26
|
+
})(WidgetOptionType = exports.WidgetOptionType || (exports.WidgetOptionType = {}));
|
|
27
|
+
function valueConversion(type, source) {
|
|
28
|
+
switch (type) {
|
|
29
|
+
case WidgetOptionType.Text:
|
|
30
|
+
case WidgetOptionType.Title:
|
|
31
|
+
return source ? String(source) : '';
|
|
32
|
+
case WidgetOptionType.Number:
|
|
33
|
+
case WidgetOptionType.Range:
|
|
34
|
+
return source ? parseFloat(source) : 0;
|
|
35
|
+
case WidgetOptionType.Integer:
|
|
36
|
+
return source ? parseInt(source, 10) : 0;
|
|
37
|
+
case WidgetOptionType.Interval:
|
|
38
|
+
if (source)
|
|
39
|
+
return {
|
|
40
|
+
from: parseFloat(source.from) || 0,
|
|
41
|
+
to: parseFloat(source.to) || 0,
|
|
42
|
+
};
|
|
43
|
+
return { from: 0, to: 0 };
|
|
44
|
+
case WidgetOptionType.Date:
|
|
45
|
+
case WidgetOptionType.DateTime:
|
|
46
|
+
return parseDate(source);
|
|
47
|
+
case WidgetOptionType.Time:
|
|
48
|
+
return source || '00:00';
|
|
49
|
+
case WidgetOptionType.DateInterval:
|
|
50
|
+
if (source)
|
|
51
|
+
return {
|
|
52
|
+
from: parseDate(source.from),
|
|
53
|
+
to: parseDate(source.to),
|
|
54
|
+
};
|
|
55
|
+
return { from: new Date(), to: new Date() };
|
|
56
|
+
case WidgetOptionType.ColorPicker:
|
|
57
|
+
case WidgetOptionType.Radio:
|
|
58
|
+
case WidgetOptionType.Select:
|
|
59
|
+
return source;
|
|
60
|
+
case WidgetOptionType.Checkbox:
|
|
61
|
+
return Boolean(source);
|
|
62
|
+
default:
|
|
63
|
+
return '';
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
exports.valueConversion = valueConversion;
|
|
67
|
+
function parseDate(source) {
|
|
68
|
+
const data = new Date(source);
|
|
69
|
+
return isNaN(data.valueOf()) ? new Date() : data;
|
|
70
|
+
}
|
|
71
|
+
function getSpan(source) {
|
|
72
|
+
const span = source | 0;
|
|
73
|
+
if (span > widget_config_1.STEP)
|
|
74
|
+
return widget_config_1.STEP;
|
|
75
|
+
if (span < 0)
|
|
76
|
+
return 0;
|
|
77
|
+
return span;
|
|
78
|
+
}
|
|
79
|
+
exports.getSpan = getSpan;
|
package/config.d.ts
ADDED
package/config.js
ADDED
package/dataset.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare enum ColumnType {
|
|
2
|
+
String = "string",
|
|
3
|
+
Number = "number",
|
|
4
|
+
Date = "date",
|
|
5
|
+
Array = "array",
|
|
6
|
+
Object = "object",
|
|
7
|
+
Boolean = "boolean"
|
|
8
|
+
}
|
|
9
|
+
export interface DatasetRow {
|
|
10
|
+
[path: string]: any;
|
|
11
|
+
}
|
|
12
|
+
export interface Column {
|
|
13
|
+
type: ColumnType;
|
|
14
|
+
name: string;
|
|
15
|
+
path: string;
|
|
16
|
+
}
|
package/dataset.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// enums
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
+
exports.ColumnType = void 0;
|
|
5
|
+
var ColumnType;
|
|
6
|
+
(function (ColumnType) {
|
|
7
|
+
ColumnType["String"] = "string";
|
|
8
|
+
ColumnType["Number"] = "number";
|
|
9
|
+
ColumnType["Date"] = "date";
|
|
10
|
+
ColumnType["Array"] = "array";
|
|
11
|
+
ColumnType["Object"] = "object";
|
|
12
|
+
ColumnType["Boolean"] = "boolean";
|
|
13
|
+
})(ColumnType = exports.ColumnType || (exports.ColumnType = {}));
|
package/declare.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function Declare(): ClassDecorator;
|
package/declare.js
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.Declare = void 0;
|
|
15
|
+
const logical_not_1 = require("logical-not");
|
|
16
|
+
const io_1 = require("./__internal__/io");
|
|
17
|
+
const datasetMap = new Map();
|
|
18
|
+
function Declare() {
|
|
19
|
+
return (T) => {
|
|
20
|
+
const instance = new T();
|
|
21
|
+
const token = readFromUrl('token');
|
|
22
|
+
Object.assign(instance, {
|
|
23
|
+
options: {},
|
|
24
|
+
ready() {
|
|
25
|
+
output(token, io_1.Output.Ready);
|
|
26
|
+
},
|
|
27
|
+
});
|
|
28
|
+
let inited = false;
|
|
29
|
+
input(io_1.Input.Change, ([data, options]) => {
|
|
30
|
+
provideTo(instance, data, token);
|
|
31
|
+
set(instance, 'options', options);
|
|
32
|
+
if ((0, logical_not_1.not)(inited)) {
|
|
33
|
+
inited = true;
|
|
34
|
+
call(instance, 'init');
|
|
35
|
+
}
|
|
36
|
+
call(instance, 'onChange');
|
|
37
|
+
});
|
|
38
|
+
input(io_1.Input.ChangeLang, lang => {
|
|
39
|
+
set(instance, 'lang', lang);
|
|
40
|
+
if (inited)
|
|
41
|
+
call(instance, 'onLangChange');
|
|
42
|
+
});
|
|
43
|
+
input(io_1.Input.ChangeTheme, theme => {
|
|
44
|
+
set(instance, 'theme', theme);
|
|
45
|
+
if (inited)
|
|
46
|
+
call(instance, 'onThemeChange');
|
|
47
|
+
});
|
|
48
|
+
input(io_1.Input.Highlight, ({ datasetId, rowIndexArray }) => {
|
|
49
|
+
const dataset = datasetMap.get(datasetId);
|
|
50
|
+
dataset === null || dataset === void 0 ? void 0 : dataset.events.onHighlight(rowIndexArray);
|
|
51
|
+
});
|
|
52
|
+
output(token, io_1.Output.Init);
|
|
53
|
+
return T;
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
exports.Declare = Declare;
|
|
57
|
+
function provideTo(widget, source, token) {
|
|
58
|
+
datasetMap.clear();
|
|
59
|
+
if ('dataset' in source) {
|
|
60
|
+
const { dataset } = source;
|
|
61
|
+
Object.assign(widget, {
|
|
62
|
+
dataset: transform(dataset, token),
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
if (Array.isArray(source)) {
|
|
67
|
+
const { datasets } = source;
|
|
68
|
+
Object.assign(widget, {
|
|
69
|
+
datasets: datasets.map(dataset => transform(dataset, token)),
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
const datasets = {};
|
|
74
|
+
Object.entries(source).forEach(([key, item]) => {
|
|
75
|
+
if (Array.isArray(item)) {
|
|
76
|
+
datasets[key] = item.map(dataset => transform(dataset, token));
|
|
77
|
+
}
|
|
78
|
+
else {
|
|
79
|
+
datasets[key] = transform(item, token);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
Object.assign(widget, { datasets });
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function transform(source, token) {
|
|
87
|
+
const { datasetId } = source, slice = __rest(source, ["datasetId"]);
|
|
88
|
+
const dataset = Object.assign(Object.assign({}, slice), { interact(dataIndex) {
|
|
89
|
+
output(token, io_1.Output.Interact, {
|
|
90
|
+
datasetId,
|
|
91
|
+
dataIndex,
|
|
92
|
+
});
|
|
93
|
+
}, events: {
|
|
94
|
+
onHighlight() { },
|
|
95
|
+
} });
|
|
96
|
+
datasetMap.set(datasetId, dataset);
|
|
97
|
+
return dataset;
|
|
98
|
+
}
|
|
99
|
+
function set(instance, key, value) {
|
|
100
|
+
instance[key] = value;
|
|
101
|
+
}
|
|
102
|
+
function call(instance, method) {
|
|
103
|
+
if (typeof instance[method] === 'function')
|
|
104
|
+
instance[method]();
|
|
105
|
+
}
|
|
106
|
+
function input(type, callback) {
|
|
107
|
+
window.addEventListener('message', ({ data }) => {
|
|
108
|
+
if (data.type === type)
|
|
109
|
+
callback(data.payload);
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
function output(token, type, payload) {
|
|
113
|
+
const message = { type, token, payload };
|
|
114
|
+
window.parent.postMessage(message, '*');
|
|
115
|
+
}
|
|
116
|
+
function readFromUrl(key) {
|
|
117
|
+
const startsWith = key + '=';
|
|
118
|
+
const source = window.location.search
|
|
119
|
+
.split(/[?&]/)
|
|
120
|
+
.find(item => item.startsWith(startsWith));
|
|
121
|
+
return source ? source.slice(startsWith.length) : '';
|
|
122
|
+
}
|
package/index.d.ts
ADDED
package/index.js
CHANGED
|
@@ -1 +1,19 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./config"), exports);
|
|
14
|
+
__exportStar(require("./dataset"), exports);
|
|
15
|
+
__exportStar(require("./declare"), exports);
|
|
16
|
+
__exportStar(require("./locale"), exports);
|
|
17
|
+
__exportStar(require("./theme"), exports);
|
|
18
|
+
__exportStar(require("./widget-config"), exports);
|
|
19
|
+
__exportStar(require("./widget"), exports);
|
package/locale.d.ts
ADDED
package/locale.js
ADDED
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "polymatica-widget",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "SDK для создания виджетов для
|
|
3
|
+
"version": "2.0.2",
|
|
4
|
+
"description": "SDK для создания виджетов для платформы Polymatica",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"license": "ISC",
|
|
7
|
-
"main": "index.js"
|
|
8
|
-
|
|
7
|
+
"main": "index.js",
|
|
8
|
+
"dependencies": {
|
|
9
|
+
"logical-not": "^1.0.9"
|
|
10
|
+
}
|
|
11
|
+
}
|
package/theme.d.ts
ADDED
package/theme.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { Text } from './locale';
|
|
2
|
+
import { Options } from './widget';
|
|
3
|
+
import { WidgetOptionConfig } from './__internal__/widget-options';
|
|
4
|
+
export declare enum DataQueryMethod {
|
|
5
|
+
Table = "table",
|
|
6
|
+
Aggregate = "aggregate"
|
|
7
|
+
}
|
|
8
|
+
export interface WidgetConfig {
|
|
9
|
+
data?: DataConfig | (DataConfig & WithKey)[];
|
|
10
|
+
options?: {
|
|
11
|
+
config: GetWidgetOptionsConfig;
|
|
12
|
+
default: Options;
|
|
13
|
+
validation?: OptionsValidation;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface DataConfig {
|
|
17
|
+
method: DataQueryMethod;
|
|
18
|
+
blocks: Block[];
|
|
19
|
+
label?: Text;
|
|
20
|
+
validation?: {
|
|
21
|
+
requiredSome?: string[];
|
|
22
|
+
requiredEvery?: string[];
|
|
23
|
+
};
|
|
24
|
+
iterable?: boolean;
|
|
25
|
+
heatmap?: boolean;
|
|
26
|
+
repeatable?: boolean;
|
|
27
|
+
min?: number;
|
|
28
|
+
max?: number;
|
|
29
|
+
pagination?: boolean;
|
|
30
|
+
}
|
|
31
|
+
export interface WithKey {
|
|
32
|
+
key: string;
|
|
33
|
+
}
|
|
34
|
+
export interface Block {
|
|
35
|
+
key: string;
|
|
36
|
+
label: Text;
|
|
37
|
+
icon?: string;
|
|
38
|
+
max?: number;
|
|
39
|
+
}
|
|
40
|
+
export declare const STEP = 24;
|
|
41
|
+
export interface GetWidgetOptionsConfig {
|
|
42
|
+
(options: Options): WidgetOptionConfig[];
|
|
43
|
+
}
|
|
44
|
+
export declare function title(label: Text): WidgetOptionConfig;
|
|
45
|
+
export declare function label(label: Text): WidgetOptionConfig;
|
|
46
|
+
export declare function spacer(span: number): WidgetOptionConfig;
|
|
47
|
+
export declare function text(params: {
|
|
48
|
+
key: string;
|
|
49
|
+
label: Text;
|
|
50
|
+
span?: number;
|
|
51
|
+
}): WidgetOptionConfig;
|
|
52
|
+
export declare function number(params: {
|
|
53
|
+
key: string;
|
|
54
|
+
label: Text;
|
|
55
|
+
span?: number;
|
|
56
|
+
}): WidgetOptionConfig;
|
|
57
|
+
export declare function integer(params: {
|
|
58
|
+
key: string;
|
|
59
|
+
label: Text;
|
|
60
|
+
span?: number;
|
|
61
|
+
}): WidgetOptionConfig;
|
|
62
|
+
export declare function range(params: {
|
|
63
|
+
key: string;
|
|
64
|
+
label: Text;
|
|
65
|
+
span?: number;
|
|
66
|
+
}): WidgetOptionConfig;
|
|
67
|
+
export declare function interval(params: {
|
|
68
|
+
key: string;
|
|
69
|
+
label: Text;
|
|
70
|
+
span?: number;
|
|
71
|
+
}): WidgetOptionConfig;
|
|
72
|
+
export declare function date(params: {
|
|
73
|
+
key: string;
|
|
74
|
+
label: Text;
|
|
75
|
+
span?: number;
|
|
76
|
+
}): WidgetOptionConfig;
|
|
77
|
+
export declare function time(params: {
|
|
78
|
+
key: string;
|
|
79
|
+
label: Text;
|
|
80
|
+
span?: number;
|
|
81
|
+
}): WidgetOptionConfig;
|
|
82
|
+
export declare function dateTime(params: {
|
|
83
|
+
key: string;
|
|
84
|
+
label: Text;
|
|
85
|
+
span?: number;
|
|
86
|
+
}): WidgetOptionConfig;
|
|
87
|
+
export declare function checkbox(params: {
|
|
88
|
+
key: string;
|
|
89
|
+
label: Text;
|
|
90
|
+
span?: number;
|
|
91
|
+
}): WidgetOptionConfig;
|
|
92
|
+
export declare function radio(params: {
|
|
93
|
+
key: string;
|
|
94
|
+
label: Text;
|
|
95
|
+
options: {
|
|
96
|
+
label: Text;
|
|
97
|
+
value: string;
|
|
98
|
+
}[];
|
|
99
|
+
span?: number;
|
|
100
|
+
}): WidgetOptionConfig;
|
|
101
|
+
export declare function radioButton(params: {
|
|
102
|
+
key: string;
|
|
103
|
+
label: Text;
|
|
104
|
+
options: {
|
|
105
|
+
label: Text;
|
|
106
|
+
value: string;
|
|
107
|
+
}[];
|
|
108
|
+
span?: number;
|
|
109
|
+
}): WidgetOptionConfig;
|
|
110
|
+
export declare function select(params: {
|
|
111
|
+
key: string;
|
|
112
|
+
label: Text;
|
|
113
|
+
options: {
|
|
114
|
+
label: Text;
|
|
115
|
+
value: string;
|
|
116
|
+
}[];
|
|
117
|
+
span?: number;
|
|
118
|
+
}): WidgetOptionConfig;
|
|
119
|
+
export declare function colorPicker(params: {
|
|
120
|
+
key: string;
|
|
121
|
+
label: Text;
|
|
122
|
+
span?: number;
|
|
123
|
+
}): WidgetOptionConfig;
|
|
124
|
+
export interface OptionsValidation {
|
|
125
|
+
[key: string]: OptionsValidator;
|
|
126
|
+
}
|
|
127
|
+
export interface OptionsValidator {
|
|
128
|
+
(value: any): Text | null;
|
|
129
|
+
}
|
package/widget-config.js
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
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.spacer = exports.label = exports.title = exports.STEP = exports.DataQueryMethod = void 0;
|
|
4
|
+
const widget_options_1 = require("./__internal__/widget-options");
|
|
5
|
+
// enums
|
|
6
|
+
var DataQueryMethod;
|
|
7
|
+
(function (DataQueryMethod) {
|
|
8
|
+
DataQueryMethod["Table"] = "table";
|
|
9
|
+
DataQueryMethod["Aggregate"] = "aggregate";
|
|
10
|
+
})(DataQueryMethod = exports.DataQueryMethod || (exports.DataQueryMethod = {}));
|
|
11
|
+
// widget options
|
|
12
|
+
exports.STEP = 24;
|
|
13
|
+
// layout
|
|
14
|
+
function title(label) {
|
|
15
|
+
return { type: widget_options_1.WidgetOptionType.Title, label };
|
|
16
|
+
}
|
|
17
|
+
exports.title = title;
|
|
18
|
+
function label(label) {
|
|
19
|
+
return { type: widget_options_1.WidgetOptionType.Label, label };
|
|
20
|
+
}
|
|
21
|
+
exports.label = label;
|
|
22
|
+
function spacer(span) {
|
|
23
|
+
return { type: widget_options_1.WidgetOptionType.Spacer, span };
|
|
24
|
+
}
|
|
25
|
+
exports.spacer = spacer;
|
|
26
|
+
// controls
|
|
27
|
+
function text(params) {
|
|
28
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Text }, params);
|
|
29
|
+
}
|
|
30
|
+
exports.text = text;
|
|
31
|
+
function number(params) {
|
|
32
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Number }, params);
|
|
33
|
+
}
|
|
34
|
+
exports.number = number;
|
|
35
|
+
function integer(params) {
|
|
36
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Integer }, params);
|
|
37
|
+
}
|
|
38
|
+
exports.integer = integer;
|
|
39
|
+
function range(params) {
|
|
40
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Range }, params);
|
|
41
|
+
}
|
|
42
|
+
exports.range = range;
|
|
43
|
+
function interval(params) {
|
|
44
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Interval }, params);
|
|
45
|
+
}
|
|
46
|
+
exports.interval = interval;
|
|
47
|
+
function date(params) {
|
|
48
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Date }, params);
|
|
49
|
+
}
|
|
50
|
+
exports.date = date;
|
|
51
|
+
function time(params) {
|
|
52
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Time }, params);
|
|
53
|
+
}
|
|
54
|
+
exports.time = time;
|
|
55
|
+
function dateTime(params) {
|
|
56
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.DateTime }, params);
|
|
57
|
+
}
|
|
58
|
+
exports.dateTime = dateTime;
|
|
59
|
+
function checkbox(params) {
|
|
60
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Checkbox }, params);
|
|
61
|
+
}
|
|
62
|
+
exports.checkbox = checkbox;
|
|
63
|
+
function radio(params) {
|
|
64
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Radio }, params);
|
|
65
|
+
}
|
|
66
|
+
exports.radio = radio;
|
|
67
|
+
function radioButton(params) {
|
|
68
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.RadioButtons }, params);
|
|
69
|
+
}
|
|
70
|
+
exports.radioButton = radioButton;
|
|
71
|
+
function select(params) {
|
|
72
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.Select }, params);
|
|
73
|
+
}
|
|
74
|
+
exports.select = select;
|
|
75
|
+
function colorPicker(params) {
|
|
76
|
+
return Object.assign({ type: widget_options_1.WidgetOptionType.ColorPicker }, params);
|
|
77
|
+
}
|
|
78
|
+
exports.colorPicker = colorPicker;
|
package/widget.d.ts
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Column, DatasetRow } from './dataset';
|
|
2
|
+
import { Locale } from './locale';
|
|
3
|
+
import { Theme } from './theme';
|
|
4
|
+
export declare abstract class Widget {
|
|
5
|
+
readonly options: Options;
|
|
6
|
+
readonly theme: Theme;
|
|
7
|
+
readonly lang: Locale;
|
|
8
|
+
ready(): void;
|
|
9
|
+
init(): void;
|
|
10
|
+
abstract onChange(): void;
|
|
11
|
+
onThemeChange(): void;
|
|
12
|
+
onLangChange(): void;
|
|
13
|
+
}
|
|
14
|
+
export interface SingleData {
|
|
15
|
+
readonly dataset: Dataset;
|
|
16
|
+
}
|
|
17
|
+
export interface MultiData {
|
|
18
|
+
readonly datasets: {
|
|
19
|
+
[datasetKey: string]: Dataset;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
export declare type Repeatable<T extends SingleData | MultiData> = T extends SingleData ? {
|
|
23
|
+
readonly datasets: Dataset[];
|
|
24
|
+
} : {
|
|
25
|
+
readonly datasets: {
|
|
26
|
+
[datasetKey: string]: Dataset | Dataset[];
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
export interface Dataset {
|
|
30
|
+
columns: Column[];
|
|
31
|
+
columnsByBlock: {
|
|
32
|
+
[blockKey: string]: Column[];
|
|
33
|
+
};
|
|
34
|
+
rows: DatasetRow[];
|
|
35
|
+
heatmap: HeatmapItem[];
|
|
36
|
+
interact(rowIndex: number): void;
|
|
37
|
+
events: {
|
|
38
|
+
onHighlight: (rowIndexArray: number[]) => void;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
export interface HeatmapItem {
|
|
42
|
+
column: Column;
|
|
43
|
+
getColor(value: number): string;
|
|
44
|
+
}
|
|
45
|
+
export interface Options {
|
|
46
|
+
[key: string]: any;
|
|
47
|
+
}
|