polymatica-widget 2.0.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/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,6 +1,6 @@
1
1
  {
2
2
  "name": "polymatica-widget",
3
- "version": "2.0.0",
3
+ "version": "2.0.2",
4
4
  "description": "SDK для создания виджетов для платформы Polymatica",
5
5
  "keywords": [],
6
6
  "license": "ISC",
@@ -1,49 +1,28 @@
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
5
  Table = "table",
8
6
  Aggregate = "aggregate"
9
7
  }
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"
27
- }
28
8
  export interface WidgetConfig {
29
- data?: {
30
- view: DataConfigView | (DataConfigView & WithKey)[];
31
- request?: DataRequest;
32
- };
9
+ data?: DataConfig | (DataConfig & WithKey)[];
33
10
  options?: {
34
- view: GetWidgetOptionsView;
11
+ config: GetWidgetOptionsConfig;
35
12
  default: Options;
36
13
  validation?: OptionsValidation;
37
14
  };
38
15
  }
39
- export interface DataConfigView {
40
- blocks: Block[];
16
+ export interface DataConfig {
41
17
  method: DataQueryMethod;
18
+ blocks: Block[];
42
19
  label?: Text;
43
20
  validation?: {
44
21
  requiredSome?: string[];
45
22
  requiredEvery?: string[];
46
23
  };
24
+ iterable?: boolean;
25
+ heatmap?: boolean;
47
26
  repeatable?: boolean;
48
27
  min?: number;
49
28
  max?: number;
@@ -52,106 +31,63 @@ export interface DataConfigView {
52
31
  export interface WithKey {
53
32
  key: string;
54
33
  }
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: {
34
+ export interface Block {
68
35
  key: string;
69
36
  label: Text;
70
37
  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;
93
38
  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
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;
102
47
  export declare function text(params: {
103
48
  key: string;
104
49
  label: Text;
105
50
  span?: number;
106
- defaultValue?: string;
107
51
  }): WidgetOptionConfig;
108
52
  export declare function number(params: {
109
53
  key: string;
110
54
  label: Text;
111
55
  span?: number;
112
- defaultValue?: string;
113
56
  }): WidgetOptionConfig;
114
57
  export declare function integer(params: {
115
58
  key: string;
116
59
  label: Text;
117
60
  span?: number;
118
- defaultValue?: string;
119
61
  }): WidgetOptionConfig;
120
62
  export declare function range(params: {
121
63
  key: string;
122
64
  label: Text;
123
65
  span?: number;
124
- defaultValue?: string;
125
66
  }): WidgetOptionConfig;
126
67
  export declare function interval(params: {
127
68
  key: string;
128
69
  label: Text;
129
70
  span?: number;
130
- defaultValue?: string;
131
71
  }): WidgetOptionConfig;
132
72
  export declare function date(params: {
133
73
  key: string;
134
74
  label: Text;
135
75
  span?: number;
136
- defaultValue?: string;
137
76
  }): WidgetOptionConfig;
138
77
  export declare function time(params: {
139
78
  key: string;
140
79
  label: Text;
141
80
  span?: number;
142
- defaultValue?: string;
143
81
  }): WidgetOptionConfig;
144
82
  export declare function dateTime(params: {
145
83
  key: string;
146
84
  label: Text;
147
85
  span?: number;
148
- defaultValue?: string;
149
86
  }): WidgetOptionConfig;
150
87
  export declare function checkbox(params: {
151
88
  key: string;
152
89
  label: Text;
153
90
  span?: number;
154
- defaultValue?: boolean;
155
91
  }): WidgetOptionConfig;
156
92
  export declare function radio(params: {
157
93
  key: string;
@@ -161,7 +97,15 @@ export declare function radio(params: {
161
97
  value: string;
162
98
  }[];
163
99
  span?: number;
164
- defaultValue?: string;
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;
165
109
  }): WidgetOptionConfig;
166
110
  export declare function select(params: {
167
111
  key: string;
@@ -171,15 +115,12 @@ export declare function select(params: {
171
115
  value: string;
172
116
  }[];
173
117
  span?: number;
174
- defaultValue?: string;
175
118
  }): WidgetOptionConfig;
176
119
  export declare function colorPicker(params: {
177
120
  key: string;
178
121
  label: Text;
179
122
  span?: number;
180
- defaultValue?: string;
181
123
  }): WidgetOptionConfig;
182
- export declare function title(label: Text, description?: Text): WidgetOptionConfig;
183
124
  export interface OptionsValidation {
184
125
  [key: string]: OptionsValidator;
185
126
  }
package/widget-config.js CHANGED
@@ -1,7 +1,6 @@
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;
@@ -9,94 +8,22 @@ var DataQueryMethod;
9
8
  DataQueryMethod["Table"] = "table";
10
9
  DataQueryMethod["Aggregate"] = "aggregate";
11
10
  })(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;
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
100
27
  function text(params) {
101
28
  return Object.assign({ type: widget_options_1.WidgetOptionType.Text }, params);
102
29
  }
@@ -137,6 +64,10 @@ function radio(params) {
137
64
  return Object.assign({ type: widget_options_1.WidgetOptionType.Radio }, params);
138
65
  }
139
66
  exports.radio = radio;
67
+ function radioButton(params) {
68
+ return Object.assign({ type: widget_options_1.WidgetOptionType.RadioButtons }, params);
69
+ }
70
+ exports.radioButton = radioButton;
140
71
  function select(params) {
141
72
  return Object.assign({ type: widget_options_1.WidgetOptionType.Select }, params);
142
73
  }
@@ -145,12 +76,3 @@ function colorPicker(params) {
145
76
  return Object.assign({ type: widget_options_1.WidgetOptionType.ColorPicker }, params);
146
77
  }
147
78
  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;