plmt-constructor-sdk 0.13.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/__internal__/config.d.ts +53 -0
- package/__internal__/config.js +46 -0
- package/__internal__/dataset.d.ts +19 -0
- package/__internal__/dataset.js +12 -0
- package/__internal__/theme.d.ts +13 -0
- package/__internal__/theme.js +112 -0
- package/__internal__/view-settings.d.ts +24 -0
- package/__internal__/view-settings.js +50 -0
- package/__internal__/widget-io.d.ts +56 -0
- package/__internal__/widget-io.js +21 -0
- package/__internal__/widget-provide-data.d.ts +4 -0
- package/__internal__/widget-provide-data.js +112 -0
- package/__internal__/widget.d.ts +64 -0
- package/__internal__/widget.js +64 -0
- package/config.d.ts +142 -0
- package/config.js +198 -0
- package/data.d.ts +62 -0
- package/data.js +51 -0
- package/declare.d.ts +20 -0
- package/declare.js +131 -0
- package/index.d.ts +2 -0
- package/index.js +18 -0
- package/package.json +8 -0
- package/theme.d.ts +26 -0
- package/theme.js +19 -0
- package/widget.d.ts +63 -0
- package/widget.js +24 -0
package/config.d.ts
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* К помощью конфигурация настраивается получение данных
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module Конфигурация
|
|
6
|
+
*/
|
|
7
|
+
import { ColumnType } from './data';
|
|
8
|
+
import { DataSettings as WidgetDataSettings, DataSettingsMap as WidgetDataSettingsMap, ViewSettings } from './widget';
|
|
9
|
+
import { configDataBlock_Server } from './__internal__/config';
|
|
10
|
+
import { viewSettingsItemValue } from './__internal__/view-settings';
|
|
11
|
+
export declare enum DataQueryMethod {
|
|
12
|
+
Table = "table",
|
|
13
|
+
Aggregate = "aggregate"
|
|
14
|
+
}
|
|
15
|
+
export declare enum DataQueryFunction {
|
|
16
|
+
Group = "group",
|
|
17
|
+
Sum = "sum",
|
|
18
|
+
Average = "avg",
|
|
19
|
+
Min = "min",
|
|
20
|
+
Max = "max",
|
|
21
|
+
First = "first",
|
|
22
|
+
Last = "last"
|
|
23
|
+
}
|
|
24
|
+
export declare enum BlockIcon {
|
|
25
|
+
AxisX = "sys:axis-x",
|
|
26
|
+
AxisY = "sys:axis-y",
|
|
27
|
+
Value = "sys:value-column"
|
|
28
|
+
}
|
|
29
|
+
export declare type Locale = 'ru' | 'en';
|
|
30
|
+
export declare type Text = Record<Locale, string>;
|
|
31
|
+
export interface Config {
|
|
32
|
+
label: Text;
|
|
33
|
+
icon: string;
|
|
34
|
+
documentation: ConfigDocumentation;
|
|
35
|
+
dataSettings: Omit<DataSettings, 'key'> | DataSettings[];
|
|
36
|
+
}
|
|
37
|
+
export interface ConfigDocumentation {
|
|
38
|
+
readme: string;
|
|
39
|
+
assetsDirectory: string;
|
|
40
|
+
images: string[];
|
|
41
|
+
}
|
|
42
|
+
export interface DataSettings {
|
|
43
|
+
method: DataQueryMethod;
|
|
44
|
+
key: string;
|
|
45
|
+
label?: Text;
|
|
46
|
+
min?: number;
|
|
47
|
+
max?: number;
|
|
48
|
+
validation?: {
|
|
49
|
+
requiredSome?: string[];
|
|
50
|
+
requiredEvery?: string[];
|
|
51
|
+
};
|
|
52
|
+
blocks: Block[];
|
|
53
|
+
}
|
|
54
|
+
export declare class Block {
|
|
55
|
+
private [configDataBlock_Server];
|
|
56
|
+
constructor(_: symbol);
|
|
57
|
+
}
|
|
58
|
+
export declare function block(params: {
|
|
59
|
+
key: string;
|
|
60
|
+
dataQueryFunction: DataQueryFunction;
|
|
61
|
+
label: Text;
|
|
62
|
+
columnTypes?: ColumnType[];
|
|
63
|
+
icon?: BlockIcon | string;
|
|
64
|
+
max?: number;
|
|
65
|
+
}): Block;
|
|
66
|
+
export declare function filter(params?: {
|
|
67
|
+
label?: Text;
|
|
68
|
+
icon?: BlockIcon | string;
|
|
69
|
+
}): Block;
|
|
70
|
+
export declare function sort(params?: {
|
|
71
|
+
label?: Text;
|
|
72
|
+
icon?: BlockIcon | string;
|
|
73
|
+
}): Block;
|
|
74
|
+
export declare function colorize(params?: {
|
|
75
|
+
label?: Text;
|
|
76
|
+
icon?: BlockIcon | string;
|
|
77
|
+
max?: number;
|
|
78
|
+
}): Block;
|
|
79
|
+
export declare function drilldown(params: {
|
|
80
|
+
source: string;
|
|
81
|
+
additionalFilterSources?: string[];
|
|
82
|
+
label?: Text;
|
|
83
|
+
}): Block;
|
|
84
|
+
export interface CreateViewSettings<DataSettings extends WidgetDataSettings | WidgetDataSettingsMap> {
|
|
85
|
+
(settings: {
|
|
86
|
+
dataSettings: DataSettings;
|
|
87
|
+
viewSettings: ViewSettings;
|
|
88
|
+
}): ViewSettingsItem[];
|
|
89
|
+
}
|
|
90
|
+
export declare type ViewSettingsValidator = (value: any) => Text | null;
|
|
91
|
+
export interface ViewSettingsValidation {
|
|
92
|
+
[key: string]: ViewSettingsValidator;
|
|
93
|
+
}
|
|
94
|
+
export declare class ViewSettingsItem {
|
|
95
|
+
private [viewSettingsItemValue];
|
|
96
|
+
constructor(_: symbol);
|
|
97
|
+
}
|
|
98
|
+
export declare function input(params: {
|
|
99
|
+
key: string;
|
|
100
|
+
label: Text;
|
|
101
|
+
span?: number;
|
|
102
|
+
defaultValue?: string;
|
|
103
|
+
}): ViewSettingsItem;
|
|
104
|
+
export declare function textArea(params: {
|
|
105
|
+
key: string;
|
|
106
|
+
label: Text;
|
|
107
|
+
span?: number;
|
|
108
|
+
defaultValue?: string;
|
|
109
|
+
}): ViewSettingsItem;
|
|
110
|
+
export declare function checkbox(params: {
|
|
111
|
+
key: string;
|
|
112
|
+
label: Text;
|
|
113
|
+
span?: number;
|
|
114
|
+
defaultValue?: boolean;
|
|
115
|
+
}): ViewSettingsItem;
|
|
116
|
+
export declare function radio(params: {
|
|
117
|
+
key: string;
|
|
118
|
+
label: Text;
|
|
119
|
+
options: {
|
|
120
|
+
label: Text;
|
|
121
|
+
value: string;
|
|
122
|
+
}[];
|
|
123
|
+
span?: number;
|
|
124
|
+
defaultValue?: string;
|
|
125
|
+
}): ViewSettingsItem;
|
|
126
|
+
export declare function select(params: {
|
|
127
|
+
key: string;
|
|
128
|
+
label: Text;
|
|
129
|
+
options: {
|
|
130
|
+
label: Text;
|
|
131
|
+
value: string;
|
|
132
|
+
}[];
|
|
133
|
+
span?: number;
|
|
134
|
+
defaultValue?: string;
|
|
135
|
+
}): ViewSettingsItem;
|
|
136
|
+
export declare function colorPicker(params: {
|
|
137
|
+
key: string;
|
|
138
|
+
label: Text;
|
|
139
|
+
span?: number;
|
|
140
|
+
defaultValue?: string;
|
|
141
|
+
}): ViewSettingsItem;
|
|
142
|
+
export declare function title(label: any): ViewSettingsItem;
|
package/config.js
ADDED
|
@@ -0,0 +1,198 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* К помощью конфигурация настраивается получение данных
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module Конфигурация
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.title = exports.colorPicker = exports.select = exports.radio = exports.checkbox = exports.textArea = exports.input = exports.ViewSettingsItem = exports.drilldown = exports.colorize = exports.sort = exports.filter = exports.block = exports.Block = exports.BlockIcon = exports.DataQueryFunction = exports.DataQueryMethod = void 0;
|
|
10
|
+
const data_1 = require("./data");
|
|
11
|
+
const config_1 = require("./__internal__/config");
|
|
12
|
+
const dataset_1 = require("./__internal__/dataset");
|
|
13
|
+
const view_settings_1 = require("./__internal__/view-settings");
|
|
14
|
+
// enums
|
|
15
|
+
var DataQueryMethod;
|
|
16
|
+
(function (DataQueryMethod) {
|
|
17
|
+
DataQueryMethod["Table"] = "table";
|
|
18
|
+
DataQueryMethod["Aggregate"] = "aggregate";
|
|
19
|
+
})(DataQueryMethod = exports.DataQueryMethod || (exports.DataQueryMethod = {}));
|
|
20
|
+
var DataQueryFunction;
|
|
21
|
+
(function (DataQueryFunction) {
|
|
22
|
+
DataQueryFunction["Group"] = "group";
|
|
23
|
+
DataQueryFunction["Sum"] = "sum";
|
|
24
|
+
DataQueryFunction["Average"] = "avg";
|
|
25
|
+
DataQueryFunction["Min"] = "min";
|
|
26
|
+
DataQueryFunction["Max"] = "max";
|
|
27
|
+
DataQueryFunction["First"] = "first";
|
|
28
|
+
DataQueryFunction["Last"] = "last";
|
|
29
|
+
})(DataQueryFunction = exports.DataQueryFunction || (exports.DataQueryFunction = {}));
|
|
30
|
+
var BlockIcon;
|
|
31
|
+
(function (BlockIcon) {
|
|
32
|
+
BlockIcon["AxisX"] = "sys:axis-x";
|
|
33
|
+
BlockIcon["AxisY"] = "sys:axis-y";
|
|
34
|
+
BlockIcon["Value"] = "sys:value-column";
|
|
35
|
+
})(BlockIcon = exports.BlockIcon || (exports.BlockIcon = {}));
|
|
36
|
+
// blocks
|
|
37
|
+
const token = Symbol();
|
|
38
|
+
class Block {
|
|
39
|
+
constructor(_) {
|
|
40
|
+
if (_ !== token)
|
|
41
|
+
throw new Error('Illigal constructor');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
exports.Block = Block;
|
|
45
|
+
function createBlock(source) {
|
|
46
|
+
return Object.assign(new Block(token), {
|
|
47
|
+
[config_1.configDataBlock_Server]: {
|
|
48
|
+
type: source.type,
|
|
49
|
+
key: source.key,
|
|
50
|
+
label: source.label,
|
|
51
|
+
icon: source.icon || '',
|
|
52
|
+
data_type: source.data_type,
|
|
53
|
+
max: source.max || 0,
|
|
54
|
+
function: source.function || null,
|
|
55
|
+
},
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
function block(params) {
|
|
59
|
+
const columnTypes = params.columnTypes || [];
|
|
60
|
+
const hasNumberType = columnTypes.includes(data_1.ColumnType.Number);
|
|
61
|
+
let columnType;
|
|
62
|
+
switch (columnTypes.length) {
|
|
63
|
+
case 0:
|
|
64
|
+
columnType = dataset_1.DatasetColumnType_Server.Any;
|
|
65
|
+
break;
|
|
66
|
+
case 1:
|
|
67
|
+
columnType = hasNumberType
|
|
68
|
+
? dataset_1.DatasetColumnType_Server.Fact
|
|
69
|
+
: dataset_1.DatasetColumnType_Server.Dimension;
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
columnType = hasNumberType
|
|
73
|
+
? dataset_1.DatasetColumnType_Server.Any
|
|
74
|
+
: dataset_1.DatasetColumnType_Server.Dimension;
|
|
75
|
+
}
|
|
76
|
+
return createBlock({
|
|
77
|
+
type: config_1.ConfigDataBlockType_Server.Column,
|
|
78
|
+
key: params.key,
|
|
79
|
+
label: params.label,
|
|
80
|
+
icon: params.icon,
|
|
81
|
+
max: params.max,
|
|
82
|
+
function: params.dataQueryFunction,
|
|
83
|
+
data_type: columnType,
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
exports.block = block;
|
|
87
|
+
function filter(params = {}) {
|
|
88
|
+
return createBlock({
|
|
89
|
+
type: config_1.ConfigDataBlockType_Server.Filter,
|
|
90
|
+
key: config_1.blockFilterKey,
|
|
91
|
+
label: params.label || {
|
|
92
|
+
ru: 'Фильтры',
|
|
93
|
+
en: 'Filters',
|
|
94
|
+
},
|
|
95
|
+
icon: params.icon || BlockIcon.Value,
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
exports.filter = filter;
|
|
99
|
+
function sort(params = {}) {
|
|
100
|
+
return createBlock({
|
|
101
|
+
type: config_1.ConfigDataBlockType_Server.Sort,
|
|
102
|
+
key: config_1.blockSortKey,
|
|
103
|
+
label: params.label || {
|
|
104
|
+
ru: 'Сортировка',
|
|
105
|
+
en: 'Sort',
|
|
106
|
+
},
|
|
107
|
+
icon: params.icon || BlockIcon.Value,
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
exports.sort = sort;
|
|
111
|
+
function colorize(params = {}) {
|
|
112
|
+
return createBlock({
|
|
113
|
+
type: config_1.ConfigDataBlockType_Server.Colorizer,
|
|
114
|
+
key: config_1.blockColorizeKey,
|
|
115
|
+
label: params.label || {
|
|
116
|
+
ru: 'Цветовая дифференциация',
|
|
117
|
+
en: 'Colors',
|
|
118
|
+
},
|
|
119
|
+
icon: params.icon || BlockIcon.Value,
|
|
120
|
+
max: params.max || 0,
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
exports.colorize = colorize;
|
|
124
|
+
function drilldown(params) {
|
|
125
|
+
return createBlock({
|
|
126
|
+
type: config_1.ConfigDataBlockType_Server.Drilldown,
|
|
127
|
+
key: (0, config_1.decodeDrilldownData)(params.source, params.additionalFilterSources || []),
|
|
128
|
+
label: params.label || {
|
|
129
|
+
ru: 'Drilldown',
|
|
130
|
+
en: 'Drilldown',
|
|
131
|
+
},
|
|
132
|
+
icon: BlockIcon.Value,
|
|
133
|
+
max: 4,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
exports.drilldown = drilldown;
|
|
137
|
+
class ViewSettingsItem {
|
|
138
|
+
constructor(_) {
|
|
139
|
+
if (_ !== token)
|
|
140
|
+
throw new Error('Illigal constructor');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
exports.ViewSettingsItem = ViewSettingsItem;
|
|
144
|
+
function createViewSettingsItem(value) {
|
|
145
|
+
return Object.assign(new ViewSettingsItem(token), {
|
|
146
|
+
[view_settings_1.viewSettingsItemValue]: value,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
function input(params) {
|
|
150
|
+
return createViewSettingsItem({
|
|
151
|
+
type: view_settings_1.ViewSettingsItemType.Input,
|
|
152
|
+
...params,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
exports.input = input;
|
|
156
|
+
function textArea(params) {
|
|
157
|
+
return createViewSettingsItem({
|
|
158
|
+
type: view_settings_1.ViewSettingsItemType.TextArea,
|
|
159
|
+
...params,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
exports.textArea = textArea;
|
|
163
|
+
function checkbox(params) {
|
|
164
|
+
return createViewSettingsItem({
|
|
165
|
+
type: view_settings_1.ViewSettingsItemType.Checkbox,
|
|
166
|
+
...params,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
exports.checkbox = checkbox;
|
|
170
|
+
function radio(params) {
|
|
171
|
+
return createViewSettingsItem({
|
|
172
|
+
type: view_settings_1.ViewSettingsItemType.Radio,
|
|
173
|
+
...params,
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
exports.radio = radio;
|
|
177
|
+
function select(params) {
|
|
178
|
+
return createViewSettingsItem({
|
|
179
|
+
type: view_settings_1.ViewSettingsItemType.Select,
|
|
180
|
+
...params,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
exports.select = select;
|
|
184
|
+
function colorPicker(params) {
|
|
185
|
+
return createViewSettingsItem({
|
|
186
|
+
type: view_settings_1.ViewSettingsItemType.ColorPicker,
|
|
187
|
+
...params,
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
exports.colorPicker = colorPicker;
|
|
191
|
+
function title(label) {
|
|
192
|
+
return createViewSettingsItem({
|
|
193
|
+
type: view_settings_1.ViewSettingsItemType.Title,
|
|
194
|
+
key: '',
|
|
195
|
+
label,
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
exports.title = title;
|
package/data.d.ts
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Для выборки данных, а также управлением фильтрами и сортировкой...
|
|
3
|
+
*
|
|
4
|
+
* @packageDocumentation
|
|
5
|
+
* @module Работа с данными
|
|
6
|
+
*/
|
|
7
|
+
export declare enum ColumnType {
|
|
8
|
+
String = "string",
|
|
9
|
+
Number = "number",
|
|
10
|
+
Boolean = "boolean",
|
|
11
|
+
Date = "date",
|
|
12
|
+
Array = "array",
|
|
13
|
+
Object = "object"
|
|
14
|
+
}
|
|
15
|
+
export declare enum FilterMethod {
|
|
16
|
+
Equal = "equally",
|
|
17
|
+
NotEqual = "not_equal",
|
|
18
|
+
GreaterThen = "gt",
|
|
19
|
+
LessThen = "lt",
|
|
20
|
+
GreaterThenOrEqual = "gte",
|
|
21
|
+
LessThenOrEqual = "lte",
|
|
22
|
+
Period = "period",
|
|
23
|
+
DateList = "date_list",
|
|
24
|
+
InList = "in_list",
|
|
25
|
+
NotInList = "nin_list",
|
|
26
|
+
StartsOnIndex = "starts_on_i",
|
|
27
|
+
StartsOn = "starts_on",
|
|
28
|
+
EndsOnIndex = "ends_on_i",
|
|
29
|
+
EndsOn = "ends_on",
|
|
30
|
+
ContainsIndex = "contains_i",
|
|
31
|
+
Contains = "contains",
|
|
32
|
+
NotContainIndex = "not_contain_i",
|
|
33
|
+
NotContain = "not_contain"
|
|
34
|
+
}
|
|
35
|
+
export declare enum SortDirection {
|
|
36
|
+
Asc = "ASC",
|
|
37
|
+
Desc = "DESC"
|
|
38
|
+
}
|
|
39
|
+
export declare enum Target {
|
|
40
|
+
Self = "self",
|
|
41
|
+
Other = "other",
|
|
42
|
+
All = "all"
|
|
43
|
+
}
|
|
44
|
+
export interface DataItem {
|
|
45
|
+
[path: string]: any;
|
|
46
|
+
}
|
|
47
|
+
export interface Column {
|
|
48
|
+
type: ColumnType;
|
|
49
|
+
id: number;
|
|
50
|
+
name: string;
|
|
51
|
+
path: string;
|
|
52
|
+
format: (value: any) => string;
|
|
53
|
+
}
|
|
54
|
+
export interface Filter {
|
|
55
|
+
column: Column;
|
|
56
|
+
method: FilterMethod;
|
|
57
|
+
value: string | number | string[] | number[];
|
|
58
|
+
}
|
|
59
|
+
export interface Sort {
|
|
60
|
+
column: Column;
|
|
61
|
+
direction: SortDirection;
|
|
62
|
+
}
|
package/data.js
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Для выборки данных, а также управлением фильтрами и сортировкой...
|
|
4
|
+
*
|
|
5
|
+
* @packageDocumentation
|
|
6
|
+
* @module Работа с данными
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Target = exports.SortDirection = exports.FilterMethod = exports.ColumnType = void 0;
|
|
10
|
+
// enums
|
|
11
|
+
var ColumnType;
|
|
12
|
+
(function (ColumnType) {
|
|
13
|
+
ColumnType["String"] = "string";
|
|
14
|
+
ColumnType["Number"] = "number";
|
|
15
|
+
ColumnType["Boolean"] = "boolean";
|
|
16
|
+
ColumnType["Date"] = "date";
|
|
17
|
+
ColumnType["Array"] = "array";
|
|
18
|
+
ColumnType["Object"] = "object";
|
|
19
|
+
})(ColumnType = exports.ColumnType || (exports.ColumnType = {}));
|
|
20
|
+
var FilterMethod;
|
|
21
|
+
(function (FilterMethod) {
|
|
22
|
+
FilterMethod["Equal"] = "equally";
|
|
23
|
+
FilterMethod["NotEqual"] = "not_equal";
|
|
24
|
+
FilterMethod["GreaterThen"] = "gt";
|
|
25
|
+
FilterMethod["LessThen"] = "lt";
|
|
26
|
+
FilterMethod["GreaterThenOrEqual"] = "gte";
|
|
27
|
+
FilterMethod["LessThenOrEqual"] = "lte";
|
|
28
|
+
FilterMethod["Period"] = "period";
|
|
29
|
+
FilterMethod["DateList"] = "date_list";
|
|
30
|
+
FilterMethod["InList"] = "in_list";
|
|
31
|
+
FilterMethod["NotInList"] = "nin_list";
|
|
32
|
+
FilterMethod["StartsOnIndex"] = "starts_on_i";
|
|
33
|
+
FilterMethod["StartsOn"] = "starts_on";
|
|
34
|
+
FilterMethod["EndsOnIndex"] = "ends_on_i";
|
|
35
|
+
FilterMethod["EndsOn"] = "ends_on";
|
|
36
|
+
FilterMethod["ContainsIndex"] = "contains_i";
|
|
37
|
+
FilterMethod["Contains"] = "contains";
|
|
38
|
+
FilterMethod["NotContainIndex"] = "not_contain_i";
|
|
39
|
+
FilterMethod["NotContain"] = "not_contain";
|
|
40
|
+
})(FilterMethod = exports.FilterMethod || (exports.FilterMethod = {}));
|
|
41
|
+
var SortDirection;
|
|
42
|
+
(function (SortDirection) {
|
|
43
|
+
SortDirection["Asc"] = "ASC";
|
|
44
|
+
SortDirection["Desc"] = "DESC";
|
|
45
|
+
})(SortDirection = exports.SortDirection || (exports.SortDirection = {}));
|
|
46
|
+
var Target;
|
|
47
|
+
(function (Target) {
|
|
48
|
+
Target["Self"] = "self";
|
|
49
|
+
Target["Other"] = "other";
|
|
50
|
+
Target["All"] = "all";
|
|
51
|
+
})(Target = exports.Target || (exports.Target = {}));
|
package/declare.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Для того, чтобы виджет получал и управлял данными,
|
|
3
|
+
* класс виджета необходимо декорировать функцией Declare:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Declare, Widget } from 'ptnl-constructor-sdk';
|
|
7
|
+
*
|
|
8
|
+
* @Declare()
|
|
9
|
+
* class MyWidget extends Widget {}
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @packageDocumentation
|
|
13
|
+
* @module Регистрация виджета
|
|
14
|
+
*/
|
|
15
|
+
/**
|
|
16
|
+
* Функция-декоратор
|
|
17
|
+
*/
|
|
18
|
+
export declare function Declare(params?: {
|
|
19
|
+
provideCssVariables: boolean;
|
|
20
|
+
}): ClassDecorator;
|
package/declare.js
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Для того, чтобы виджет получал и управлял данными,
|
|
4
|
+
* класс виджета необходимо декорировать функцией Declare:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Declare, Widget } from 'ptnl-constructor-sdk';
|
|
8
|
+
*
|
|
9
|
+
* @Declare()
|
|
10
|
+
* class MyWidget extends Widget {}
|
|
11
|
+
* ```
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
* @module Регистрация виджета
|
|
15
|
+
*/
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.Declare = void 0;
|
|
18
|
+
const logical_not_1 = require("logical-not");
|
|
19
|
+
const data_1 = require("./data");
|
|
20
|
+
const widget_io_1 = require("./__internal__/widget-io");
|
|
21
|
+
const widget_provide_data_1 = require("./__internal__/widget-provide-data");
|
|
22
|
+
const theme_1 = require("./__internal__/theme");
|
|
23
|
+
const widget_1 = require("./__internal__/widget");
|
|
24
|
+
/**
|
|
25
|
+
* Функция-декоратор
|
|
26
|
+
*/
|
|
27
|
+
function Declare(params) {
|
|
28
|
+
if ((0, logical_not_1.not)(params))
|
|
29
|
+
params = {
|
|
30
|
+
provideCssVariables: false,
|
|
31
|
+
};
|
|
32
|
+
return (T) => {
|
|
33
|
+
const instance = new T();
|
|
34
|
+
const token = readFromUrl('token');
|
|
35
|
+
const uid = readFromUrl('uid');
|
|
36
|
+
if (uid) {
|
|
37
|
+
instance.uid = uid;
|
|
38
|
+
}
|
|
39
|
+
Object.assign(instance, {
|
|
40
|
+
viewSettings: {},
|
|
41
|
+
ready() {
|
|
42
|
+
output(token, widget_io_1.Output.Ready);
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
const dataSettingsMethods = {
|
|
46
|
+
setFilter(filter, rowIndex, target = data_1.Target.Self) {
|
|
47
|
+
filter = { ...filter };
|
|
48
|
+
filter.column = { ...filter.column };
|
|
49
|
+
delete filter.column.format;
|
|
50
|
+
output(token, widget_io_1.Output.SetFilter, {
|
|
51
|
+
filter,
|
|
52
|
+
target,
|
|
53
|
+
rowIndex,
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
removeFilterAt(index) {
|
|
57
|
+
output(token, widget_io_1.Output.RemoveFilterAt, {
|
|
58
|
+
index,
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
setSort(sort, target = data_1.Target.Self) {
|
|
62
|
+
if (sort) {
|
|
63
|
+
sort = { ...sort };
|
|
64
|
+
sort.column = { ...sort.column };
|
|
65
|
+
delete sort.column.format;
|
|
66
|
+
}
|
|
67
|
+
output(token, widget_io_1.Output.SetSort, { sort, target });
|
|
68
|
+
},
|
|
69
|
+
removeSortAt(index) {
|
|
70
|
+
output(token, widget_io_1.Output.RemoveSortAt, {
|
|
71
|
+
index,
|
|
72
|
+
});
|
|
73
|
+
},
|
|
74
|
+
interact(dataIndex) {
|
|
75
|
+
output(token, widget_io_1.Output.Interact, {
|
|
76
|
+
dataOptionId: this.id,
|
|
77
|
+
dataIndex,
|
|
78
|
+
});
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
let inited = false;
|
|
82
|
+
input(widget_io_1.Input.Change, (widgetRepresent) => {
|
|
83
|
+
(0, widget_provide_data_1.provideDataTo)(instance, widgetRepresent, dataSettingsMethods);
|
|
84
|
+
if ((0, logical_not_1.not)(inited)) {
|
|
85
|
+
inited = true;
|
|
86
|
+
if (typeof instance.onInit === 'function') {
|
|
87
|
+
instance.onInit();
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
if (typeof instance.onChange === 'function') {
|
|
91
|
+
instance.onChange();
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
input(widget_io_1.Input.ChangeLang, (lang) => {
|
|
95
|
+
instance.lang = lang;
|
|
96
|
+
if (instance.onLangChange && inited)
|
|
97
|
+
instance.onLangChange();
|
|
98
|
+
});
|
|
99
|
+
input(widget_io_1.Input.ChangeTheme, (value) => {
|
|
100
|
+
instance.theme = value.theme;
|
|
101
|
+
if (params.provideCssVariables)
|
|
102
|
+
(0, theme_1.provideCssVariables)(value);
|
|
103
|
+
if (instance.onThemeChange && inited)
|
|
104
|
+
instance.onThemeChange();
|
|
105
|
+
});
|
|
106
|
+
input(widget_io_1.Input.ChangeOtherFilters, (source) => (0, widget_1.dispatchChangeOtherFilters)(instance, source));
|
|
107
|
+
input(widget_io_1.Input.ChangeWidgetRenderEnv, (value) => {
|
|
108
|
+
instance.renderEnv = value;
|
|
109
|
+
});
|
|
110
|
+
output(token, widget_io_1.Output.Init);
|
|
111
|
+
return T;
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
exports.Declare = Declare;
|
|
115
|
+
function input(type, callback) {
|
|
116
|
+
window.addEventListener('message', ({ data }) => {
|
|
117
|
+
if (data.type === type)
|
|
118
|
+
callback(data.payload);
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function output(token, type, payload) {
|
|
122
|
+
const message = { type, token, payload };
|
|
123
|
+
window.parent.postMessage(message, '*');
|
|
124
|
+
}
|
|
125
|
+
function readFromUrl(key) {
|
|
126
|
+
const startsWith = key + '=';
|
|
127
|
+
const source = window.location.search
|
|
128
|
+
.split(/[?&]/)
|
|
129
|
+
.find((item) => item.startsWith(startsWith));
|
|
130
|
+
return source ? source.slice(startsWith.length) : '';
|
|
131
|
+
}
|
package/index.d.ts
ADDED
package/index.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./declare"), exports);
|
|
18
|
+
__exportStar(require("./widget"), exports);
|
package/package.json
ADDED
package/theme.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Для получения текущей темы, виджет должен имплементировать
|
|
3
|
+
* интерфейс OnThemeChange:
|
|
4
|
+
*
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { Declare, Widget, OnThemeChange } from 'ptnl-constructor-sdk';
|
|
7
|
+
* import { Theme } from 'ptnl-constructor-sdk/theme';
|
|
8
|
+
*
|
|
9
|
+
* @Declare()
|
|
10
|
+
* class MyWidget extends Widget implements OnThemeChange {
|
|
11
|
+
* onThemeChange(theme: Theme): void {}
|
|
12
|
+
* }
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @packageDocumentation
|
|
16
|
+
* @module Работа с темами
|
|
17
|
+
*/
|
|
18
|
+
export interface Theme {
|
|
19
|
+
background: string;
|
|
20
|
+
backgroundBright: string;
|
|
21
|
+
backgroundTint: string[];
|
|
22
|
+
colorize: string[][];
|
|
23
|
+
colors: string[];
|
|
24
|
+
text: string;
|
|
25
|
+
textTint: string[];
|
|
26
|
+
}
|
package/theme.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Для получения текущей темы, виджет должен имплементировать
|
|
4
|
+
* интерфейс OnThemeChange:
|
|
5
|
+
*
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { Declare, Widget, OnThemeChange } from 'ptnl-constructor-sdk';
|
|
8
|
+
* import { Theme } from 'ptnl-constructor-sdk/theme';
|
|
9
|
+
*
|
|
10
|
+
* @Declare()
|
|
11
|
+
* class MyWidget extends Widget implements OnThemeChange {
|
|
12
|
+
* onThemeChange(theme: Theme): void {}
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*
|
|
16
|
+
* @packageDocumentation
|
|
17
|
+
* @module Работа с темами
|
|
18
|
+
*/
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|