polymatica-widget 0.7.2 → 2.0.4

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/README.md CHANGED
@@ -1,3 +1,6 @@
1
1
  # Polymatica Widget SDK
2
2
 
3
+ ![build: passing](https://raw.githubusercontent.com/git@gitlab.ptnl.moscow:constructor/platform/polymatica-widget/master/badges/build.svg)
4
+ ![license: ISC](https://raw.githubusercontent.com/git@gitlab.ptnl.moscow:constructor/platform/polymatica-widget/master/badges/license.svg)
5
+
3
6
  > Pre-Alpha
@@ -1,5 +1,8 @@
1
1
  import { Text } from '../locale';
2
2
  export declare enum WidgetOptionType {
3
+ Title = "title",
4
+ Label = "label",
5
+ Spacer = "spacer",
3
6
  Text = "text",
4
7
  Number = "number",
5
8
  Integer = "integer",
@@ -8,18 +11,17 @@ export declare enum WidgetOptionType {
8
11
  Date = "date",
9
12
  Time = "time",
10
13
  DateTime = "datetime",
11
- DateInterval = "dateinterval",
14
+ DateInterval = "date-interval",
12
15
  Checkbox = "checkbox",
13
16
  Radio = "radio",
17
+ RadioButtons = "radio-buttons",
14
18
  Select = "select",
15
- ColorPicker = "color-picker",
16
- Title = "title"
19
+ ColorPicker = "color-picker"
17
20
  }
18
21
  export interface WidgetOptionConfig {
19
22
  type: WidgetOptionType;
20
- key: string;
21
- label: Text;
22
- defaultValue?: any;
23
+ key?: string;
24
+ label?: Text;
23
25
  options?: {
24
26
  label: Text;
25
27
  value: string | number | boolean;
@@ -4,6 +4,11 @@ exports.getSpan = exports.valueConversion = exports.WidgetOptionType = void 0;
4
4
  const widget_config_1 = require("../widget-config");
5
5
  var WidgetOptionType;
6
6
  (function (WidgetOptionType) {
7
+ // Layout
8
+ WidgetOptionType["Title"] = "title";
9
+ WidgetOptionType["Label"] = "label";
10
+ WidgetOptionType["Spacer"] = "spacer";
11
+ // Controls
7
12
  WidgetOptionType["Text"] = "text";
8
13
  WidgetOptionType["Number"] = "number";
9
14
  WidgetOptionType["Integer"] = "integer";
@@ -12,16 +17,17 @@ var WidgetOptionType;
12
17
  WidgetOptionType["Date"] = "date";
13
18
  WidgetOptionType["Time"] = "time";
14
19
  WidgetOptionType["DateTime"] = "datetime";
15
- WidgetOptionType["DateInterval"] = "dateinterval";
20
+ WidgetOptionType["DateInterval"] = "date-interval";
16
21
  WidgetOptionType["Checkbox"] = "checkbox";
17
22
  WidgetOptionType["Radio"] = "radio";
23
+ WidgetOptionType["RadioButtons"] = "radio-buttons";
18
24
  WidgetOptionType["Select"] = "select";
19
25
  WidgetOptionType["ColorPicker"] = "color-picker";
20
- WidgetOptionType["Title"] = "title";
21
26
  })(WidgetOptionType = exports.WidgetOptionType || (exports.WidgetOptionType = {}));
22
27
  function valueConversion(type, source) {
23
28
  switch (type) {
24
29
  case WidgetOptionType.Text:
30
+ case WidgetOptionType.Title:
25
31
  return source ? String(source) : '';
26
32
  case WidgetOptionType.Number:
27
33
  case WidgetOptionType.Range:
package/package.json CHANGED
@@ -1,11 +1,11 @@
1
1
  {
2
- "name": "polymatica-widget",
3
- "version": "0.7.2",
4
- "description": "SDK для создания виджетов для модуля Dashboard платформы Polymatica",
5
- "keywords": [],
6
- "license": "ISC",
7
- "main": "index.js",
8
- "dependencies": {
9
- "logical-not": "^1.0.9"
10
- }
2
+ "name": "polymatica-widget",
3
+ "version": "2.0.4",
4
+ "description": "SDK для создания виджетов для платформы Polymatica",
5
+ "keywords": [],
6
+ "license": "ISC",
7
+ "main": "index.js",
8
+ "dependencies": {
9
+ "logical-not": "^1.0.9"
10
+ }
11
11
  }
@@ -1,157 +1,102 @@
1
- import { ColumnType } from './dataset';
2
1
  import { Text } from './locale';
3
2
  import { Options } from './widget';
4
- import { Block } from './__internal__/widget-config';
5
3
  import { WidgetOptionConfig } from './__internal__/widget-options';
6
4
  export declare enum DataQueryMethod {
7
- Table = "table",
8
- Aggregate = "aggregate"
9
- }
10
- export declare enum AggregateFunction {
11
- Group = "group",
12
- Sum = "sum",
13
- Average = "avg",
14
- Min = "min",
15
- Max = "max",
16
- First = "first",
17
- Last = "last"
18
- }
19
- export declare enum Icon {
20
- AxisX = "ico://axis-x",
21
- AxisY = "ico://axis-y",
22
- Value = "ico://value-column",
23
- Filter = "ico://filter",
24
- Sort = "ico://sort",
25
- Heatmap = "ico://heatmap",
26
- Drilldown = "ico://drilldown"
5
+ Aggregate = "aggregate",
6
+ Pivot = "pivot",
7
+ Table = "table"
27
8
  }
28
9
  export interface WidgetConfig {
29
10
  data?: {
30
- view: DataConfigView | (DataConfigView & WithKey)[];
31
- request?: DataRequest;
11
+ config: DataConfig | (DataConfig & WithKey)[];
32
12
  };
33
13
  options?: {
34
- view: GetWidgetOptionsView;
14
+ provider: GetWidgetOptionsConfig;
35
15
  default: Options;
36
- validation?: OptionsValidation;
16
+ validators?: OptionsValidation;
37
17
  };
38
18
  }
39
- export interface DataConfigView {
40
- blocks: Block[];
19
+ export interface DataConfig {
41
20
  method: DataQueryMethod;
21
+ blocks: Block[];
42
22
  label?: Text;
43
23
  validation?: {
44
24
  requiredSome?: string[];
45
25
  requiredEvery?: string[];
46
26
  };
47
- repeatable?: boolean;
48
- min?: number;
49
- max?: number;
50
- pagination?: boolean;
27
+ interactable?: boolean;
28
+ drilldown?: {
29
+ source: string;
30
+ };
31
+ heatmap?: boolean | {
32
+ targets: string[];
33
+ };
34
+ repeatable?: boolean | {
35
+ min?: number;
36
+ max?: number;
37
+ };
51
38
  }
52
39
  export interface WithKey {
53
40
  key: string;
54
41
  }
55
- export interface DataConfigItem {
56
- blocks: Block[];
57
- method: DataQueryMethod;
58
- rowsLimit: number;
59
- pagination?: boolean;
60
- }
61
- export declare type DataConfig = DataConfigItem | DataConfigItem[] | {
62
- [key: string]: DataConfigItem | DataConfigItem[];
63
- };
64
- export interface DataRequest {
65
- (viewConfig: DataConfig, options: Options): DataConfig;
66
- }
67
- export declare function data(params: {
42
+ export interface Block {
68
43
  key: string;
69
44
  label: Text;
70
45
  icon?: string;
71
- aggregateFunction?: AggregateFunction;
72
- columnTypes?: ColumnType[];
73
- max?: number;
74
- }): Block;
75
- export declare function filter(params?: {
76
- label?: Text;
77
- icon?: Icon | string;
78
- }): Block;
79
- export declare function sort(params?: {
80
- label?: Text;
81
- icon?: Icon | string;
82
- }): Block;
83
- export declare function heatmap(params?: {
84
- label?: Text;
85
- icon?: Icon | string;
86
- max?: number;
87
- }): Block;
88
- export declare function drilldown(params: {
89
- source: string;
90
- additionalFilterSources?: string[];
91
- label?: Text;
92
- icon?: Icon | string;
46
+ aggregation?: boolean;
93
47
  max?: number;
94
- }): Block;
95
- export declare function rowsLimit(params?: {
96
- label?: Text;
97
- }): Block;
98
- export declare const STEP = 48;
99
- export interface GetWidgetOptionsView {
100
- (options: Options, dataConfig?: DataConfig): WidgetOptionConfig[];
101
48
  }
49
+ export declare const STEP = 24;
50
+ export interface GetWidgetOptionsConfig {
51
+ (options: Options): WidgetOptionConfig[];
52
+ }
53
+ export declare function title(label: Text): WidgetOptionConfig;
54
+ export declare function label(label: Text): WidgetOptionConfig;
55
+ export declare function spacer(span: number): WidgetOptionConfig;
102
56
  export declare function text(params: {
103
57
  key: string;
104
58
  label: Text;
105
59
  span?: number;
106
- defaultValue?: string;
107
60
  }): WidgetOptionConfig;
108
61
  export declare function number(params: {
109
62
  key: string;
110
63
  label: Text;
111
64
  span?: number;
112
- defaultValue?: string;
113
65
  }): WidgetOptionConfig;
114
66
  export declare function integer(params: {
115
67
  key: string;
116
68
  label: Text;
117
69
  span?: number;
118
- defaultValue?: string;
119
70
  }): WidgetOptionConfig;
120
71
  export declare function range(params: {
121
72
  key: string;
122
73
  label: Text;
123
74
  span?: number;
124
- defaultValue?: string;
125
75
  }): WidgetOptionConfig;
126
76
  export declare function interval(params: {
127
77
  key: string;
128
78
  label: Text;
129
79
  span?: number;
130
- defaultValue?: string;
131
80
  }): WidgetOptionConfig;
132
81
  export declare function date(params: {
133
82
  key: string;
134
83
  label: Text;
135
84
  span?: number;
136
- defaultValue?: string;
137
85
  }): WidgetOptionConfig;
138
86
  export declare function time(params: {
139
87
  key: string;
140
88
  label: Text;
141
89
  span?: number;
142
- defaultValue?: string;
143
90
  }): WidgetOptionConfig;
144
91
  export declare function dateTime(params: {
145
92
  key: string;
146
93
  label: Text;
147
94
  span?: number;
148
- defaultValue?: string;
149
95
  }): WidgetOptionConfig;
150
96
  export declare function checkbox(params: {
151
97
  key: string;
152
98
  label: Text;
153
99
  span?: number;
154
- defaultValue?: boolean;
155
100
  }): WidgetOptionConfig;
156
101
  export declare function radio(params: {
157
102
  key: string;
@@ -161,7 +106,15 @@ export declare function radio(params: {
161
106
  value: string;
162
107
  }[];
163
108
  span?: number;
164
- defaultValue?: string;
109
+ }): WidgetOptionConfig;
110
+ export declare function radioButton(params: {
111
+ key: string;
112
+ label: Text;
113
+ options: {
114
+ label: Text;
115
+ value: string;
116
+ }[];
117
+ span?: number;
165
118
  }): WidgetOptionConfig;
166
119
  export declare function select(params: {
167
120
  key: string;
@@ -171,15 +124,12 @@ export declare function select(params: {
171
124
  value: string;
172
125
  }[];
173
126
  span?: number;
174
- defaultValue?: string;
175
127
  }): WidgetOptionConfig;
176
128
  export declare function colorPicker(params: {
177
129
  key: string;
178
130
  label: Text;
179
131
  span?: number;
180
- defaultValue?: string;
181
132
  }): WidgetOptionConfig;
182
- export declare function title(label: Text, description?: Text): WidgetOptionConfig;
183
133
  export interface OptionsValidation {
184
134
  [key: string]: OptionsValidator;
185
135
  }
package/widget-config.js CHANGED
@@ -1,102 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.title = exports.colorPicker = exports.select = exports.radio = exports.checkbox = exports.dateTime = exports.time = exports.date = exports.interval = exports.range = exports.integer = exports.number = exports.text = exports.STEP = exports.rowsLimit = exports.drilldown = exports.heatmap = exports.sort = exports.filter = exports.data = exports.Icon = exports.AggregateFunction = exports.DataQueryMethod = void 0;
4
- const widget_config_1 = require("./__internal__/widget-config");
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;
5
4
  const widget_options_1 = require("./__internal__/widget-options");
6
5
  // enums
7
6
  var DataQueryMethod;
8
7
  (function (DataQueryMethod) {
9
- DataQueryMethod["Table"] = "table";
10
8
  DataQueryMethod["Aggregate"] = "aggregate";
9
+ DataQueryMethod["Pivot"] = "pivot";
10
+ DataQueryMethod["Table"] = "table";
11
11
  })(DataQueryMethod = exports.DataQueryMethod || (exports.DataQueryMethod = {}));
12
- var AggregateFunction;
13
- (function (AggregateFunction) {
14
- AggregateFunction["Group"] = "group";
15
- AggregateFunction["Sum"] = "sum";
16
- AggregateFunction["Average"] = "avg";
17
- AggregateFunction["Min"] = "min";
18
- AggregateFunction["Max"] = "max";
19
- AggregateFunction["First"] = "first";
20
- AggregateFunction["Last"] = "last";
21
- })(AggregateFunction = exports.AggregateFunction || (exports.AggregateFunction = {}));
22
- var Icon;
23
- (function (Icon) {
24
- Icon["AxisX"] = "ico://axis-x";
25
- Icon["AxisY"] = "ico://axis-y";
26
- Icon["Value"] = "ico://value-column";
27
- Icon["Filter"] = "ico://filter";
28
- Icon["Sort"] = "ico://sort";
29
- Icon["Heatmap"] = "ico://heatmap";
30
- Icon["Drilldown"] = "ico://drilldown";
31
- })(Icon = exports.Icon || (exports.Icon = {}));
32
- // blocks
33
- function data(params) {
34
- return Object.assign({ type: widget_config_1.BlockType.Data }, params);
35
- }
36
- exports.data = data;
37
- function filter(params = {}) {
38
- return {
39
- type: widget_config_1.BlockType.Filter,
40
- label: params.label || {
41
- ru: 'Фильтры',
42
- en: 'Filters',
43
- },
44
- icon: params.icon || Icon.Filter,
45
- key: '',
46
- };
47
- }
48
- exports.filter = filter;
49
- function sort(params = {}) {
50
- return {
51
- type: widget_config_1.BlockType.Sort,
52
- label: params.label || {
53
- ru: 'Сортировка',
54
- en: 'Sort',
55
- },
56
- icon: params.icon || Icon.Sort,
57
- key: '',
58
- };
59
- }
60
- exports.sort = sort;
61
- function heatmap(params = {}) {
62
- return {
63
- type: widget_config_1.BlockType.Heatmap,
64
- label: params.label || {
65
- ru: 'Тепловая карта',
66
- en: 'Heatmap',
67
- },
68
- icon: params.icon || Icon.Heatmap,
69
- max: params.max || 0,
70
- key: '',
71
- };
72
- }
73
- exports.heatmap = heatmap;
74
- function drilldown(params) {
75
- return {
76
- type: widget_config_1.BlockType.Drilldown,
77
- key: (0, widget_config_1.decodeDrilldownData)(params.source, params.additionalFilterSources || []),
78
- label: params.label || {
79
- ru: 'Drilldown',
80
- en: 'Drilldown',
81
- },
82
- icon: params.icon || Icon.Drilldown,
83
- max: params.max || 4,
84
- };
85
- }
86
- exports.drilldown = drilldown;
87
- function rowsLimit(params = {}) {
88
- return {
89
- type: widget_config_1.BlockType.RowsLimit,
90
- label: params.label || {
91
- ru: 'Количество записей на странице',
92
- en: 'Rows limit',
93
- },
94
- key: '',
95
- };
96
- }
97
- exports.rowsLimit = rowsLimit;
98
- // widget optiosn
99
- exports.STEP = 48;
12
+ // widget options
13
+ exports.STEP = 24;
14
+ // layout
15
+ function title(label) {
16
+ return { type: widget_options_1.WidgetOptionType.Title, label };
17
+ }
18
+ exports.title = title;
19
+ function label(label) {
20
+ return { type: widget_options_1.WidgetOptionType.Label, label };
21
+ }
22
+ exports.label = label;
23
+ function spacer(span) {
24
+ return { type: widget_options_1.WidgetOptionType.Spacer, span };
25
+ }
26
+ exports.spacer = spacer;
27
+ // controls
100
28
  function text(params) {
101
29
  return Object.assign({ type: widget_options_1.WidgetOptionType.Text }, params);
102
30
  }
@@ -137,6 +65,10 @@ function radio(params) {
137
65
  return Object.assign({ type: widget_options_1.WidgetOptionType.Radio }, params);
138
66
  }
139
67
  exports.radio = radio;
68
+ function radioButton(params) {
69
+ return Object.assign({ type: widget_options_1.WidgetOptionType.RadioButtons }, params);
70
+ }
71
+ exports.radioButton = radioButton;
140
72
  function select(params) {
141
73
  return Object.assign({ type: widget_options_1.WidgetOptionType.Select }, params);
142
74
  }
@@ -145,12 +77,3 @@ function colorPicker(params) {
145
77
  return Object.assign({ type: widget_options_1.WidgetOptionType.ColorPicker }, params);
146
78
  }
147
79
  exports.colorPicker = colorPicker;
148
- function title(label, description) {
149
- return {
150
- type: widget_options_1.WidgetOptionType.Title,
151
- label,
152
- defaultValue: description,
153
- key: '',
154
- };
155
- }
156
- exports.title = title;
@@ -1,25 +0,0 @@
1
- import { Text } from '../locale';
2
- import { ColumnType } from '../dataset';
3
- import { AggregateFunction } from '../widget-config';
4
- export declare enum BlockType {
5
- Data = "data",
6
- Filter = "filter",
7
- Sort = "sort",
8
- Heatmap = "heatmap",
9
- Drilldown = "drilldown",
10
- RowsLimit = "rows-limit"
11
- }
12
- export interface Block {
13
- type: BlockType;
14
- key: string;
15
- label: Text;
16
- icon?: string;
17
- aggregateFunction?: AggregateFunction;
18
- columnTypes?: ColumnType[];
19
- max?: number;
20
- }
21
- export declare function decodeDrilldownData(source: string, additionalFilterSources: string[]): string;
22
- export declare function encodeDrilldownData(key: string): {
23
- source: string;
24
- additionalFilterSources: string[];
25
- };
@@ -1,43 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.encodeDrilldownData = exports.decodeDrilldownData = exports.BlockType = void 0;
4
- // enums
5
- var BlockType;
6
- (function (BlockType) {
7
- BlockType["Data"] = "data";
8
- BlockType["Filter"] = "filter";
9
- BlockType["Sort"] = "sort";
10
- BlockType["Heatmap"] = "heatmap";
11
- BlockType["Drilldown"] = "drilldown";
12
- BlockType["RowsLimit"] = "rows-limit";
13
- })(BlockType = exports.BlockType || (exports.BlockType = {}));
14
- function decodeDrilldownData(source, additionalFilterSources) {
15
- const keyParts = [length(source.length), source];
16
- additionalFilterSources.forEach(item => keyParts.push(length(item.length), item));
17
- return keyParts.join('');
18
- function length(value) {
19
- if (value > 0xff)
20
- throw new RangeError();
21
- return value > 0xf
22
- ? `0x${value.toString(16)}`
23
- : `0x0${value.toString(16)}`;
24
- }
25
- }
26
- exports.decodeDrilldownData = decodeDrilldownData;
27
- function encodeDrilldownData(key) {
28
- const parts = [];
29
- parse();
30
- const [source, ...additionalFilterSources] = parts;
31
- return {
32
- source,
33
- additionalFilterSources,
34
- };
35
- function parse(offset = 0) {
36
- const start = offset + 4;
37
- const end = start + parseInt(key.slice(offset, start));
38
- parts.push(key.slice(start, end));
39
- if (end < key.length)
40
- parse(end);
41
- }
42
- }
43
- exports.encodeDrilldownData = encodeDrilldownData;