polymatica-widget 2.0.18 → 2.1.0

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  ISC License
2
2
 
3
- Copyright 2021 Polymatica
3
+ Copyright 2021-2022 Polymatica
4
4
 
5
5
  Permission to use, copy, modify, and/or distribute this software for any
6
6
  purpose with or without fee is hereby granted, provided that the above
package/README.md CHANGED
@@ -1,6 +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)
3
+ ![build: success](https://raw.githubusercontent.com/git@gitlab.ptnl.moscow:constructor/platform/polymatica-widget/master/badges/build.svg)
4
4
  ![license: ISC](https://raw.githubusercontent.com/git@gitlab.ptnl.moscow:constructor/platform/polymatica-widget/master/badges/license.svg)
5
5
 
6
6
  > Pre-Alpha
@@ -1,4 +1,4 @@
1
- import { Text } from '../locale';
1
+ import { Text } from "../locale";
2
2
  export declare enum WidgetOptionType {
3
3
  Title = "title",
4
4
  Label = "label",
@@ -29,7 +29,7 @@ function valueConversion(type, source) {
29
29
  switch (type) {
30
30
  case WidgetOptionType.Text:
31
31
  case WidgetOptionType.Title:
32
- return source ? String(source) : '';
32
+ return source ? String(source) : "";
33
33
  case WidgetOptionType.Number:
34
34
  case WidgetOptionType.Range:
35
35
  return source ? parseFloat(source) : 0;
@@ -46,7 +46,7 @@ function valueConversion(type, source) {
46
46
  case WidgetOptionType.DateTime:
47
47
  return parseDate(source);
48
48
  case WidgetOptionType.Time:
49
- return source || '00:00';
49
+ return source || "00:00";
50
50
  case WidgetOptionType.DateInterval:
51
51
  if (source)
52
52
  return {
@@ -61,7 +61,7 @@ function valueConversion(type, source) {
61
61
  case WidgetOptionType.Checkbox:
62
62
  return Boolean(source);
63
63
  default:
64
- return '';
64
+ return "";
65
65
  }
66
66
  }
67
67
  exports.valueConversion = valueConversion;
package/config.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { Column } from './dataset';
2
- import { Text } from './locale';
3
- import { Options } from './widget';
4
- import { WidgetOptionConfig } from './__internal__/widget-options';
1
+ import { ColumnType } from "./dataset";
2
+ import { Text } from "./locale";
3
+ import { Options } from "./widget";
4
+ import { WidgetOptionConfig } from "./__internal__/widget-options";
5
5
  export declare enum Size {
6
6
  Small = "small",
7
7
  Medium = "medium",
@@ -16,13 +16,14 @@ export interface WidgetConfig {
16
16
  label: Text;
17
17
  icon: string;
18
18
  size: Size | [Size, Size];
19
+ useTranslations?: boolean;
19
20
  }
20
21
  export interface SingleData {
21
- data: DataConfig;
22
+ data: DataConfig | (DataConfig & Repeatable);
22
23
  }
23
- export declare type MultiData<DataItemKeys extends string, RepeatableKeys extends DataItemKeys = never> = {
24
+ export declare type MultiData<DataItemKeys extends string> = {
24
25
  data: {
25
- [Key in DataItemKeys]: Key extends RepeatableKeys ? DataConfig & Repeatable : DataConfig;
26
+ [Key in DataItemKeys]: DataConfig | (DataConfig & Repeatable);
26
27
  };
27
28
  };
28
29
  export interface Repeatable {
@@ -54,26 +55,28 @@ export interface Block {
54
55
  }
55
56
  export interface OptionsConfig {
56
57
  options: {
57
- provider: OptionsProvider;
58
+ provider(options: Options, data: unknown): Option[];
58
59
  default: Options;
59
60
  validators?: OptionsValidation;
60
61
  };
61
62
  }
62
- declare class Option {
63
- readonly config: WidgetOptionConfig;
64
- constructor(_: symbol, config: WidgetOptionConfig);
65
- }
66
- export declare const STEP = 24;
67
- export declare type OptionsProvider<Data extends SelectedData | SelectedMultiData<string> | SelectedMultiData<any, string> | undefined = undefined> = (options: Options, data: Data) => Option[];
68
- export interface SelectedData {
69
- columns: Column[];
70
- columnsByBlock: {
63
+ export declare type DataFromConfig<T> = T extends SingleData & Repeatable ? Data[] : T extends SingleData ? Data : T extends MultiData<infer DataItemKeys> ? {
64
+ [Key in DataItemKeys]: T["data"][Key] extends Repeatable ? Data[] : Data;
65
+ } : never;
66
+ interface Data {
67
+ readonly columns: Column[];
68
+ readonly columnsByBlock: {
71
69
  [blockKey: string]: Column[];
72
70
  };
73
71
  }
74
- export declare type SelectedMultiData<DataItemKeys extends string, RepeatableKeys extends DataItemKeys = never> = {
75
- [Key in DataItemKeys]: Key extends RepeatableKeys ? SelectedData[] : SelectedData;
76
- };
72
+ interface Column {
73
+ readonly name: string;
74
+ readonly type: ColumnType;
75
+ }
76
+ declare class Option {
77
+ constructor(config: WidgetOptionConfig);
78
+ }
79
+ export declare const STEP = 24;
77
80
  export declare function title(label: Text, params?: {
78
81
  hint: Text;
79
82
  }): Option;
package/config.js CHANGED
@@ -16,14 +16,12 @@ var Method;
16
16
  Method["PivotTable"] = "pivot";
17
17
  })(Method = exports.Method || (exports.Method = {}));
18
18
  // widget options
19
- const token = Symbol();
20
19
  class Option {
21
- constructor(_, config) {
22
- if (_ !== token)
23
- throw '';
24
- Object.defineProperty(this, 'config', {
25
- get() {
26
- return Object.seal(config);
20
+ constructor(config) {
21
+ const value = Object.seal(config);
22
+ Object.defineProperty(this, "toJSON", {
23
+ value() {
24
+ return value;
27
25
  },
28
26
  });
29
27
  }
@@ -34,22 +32,22 @@ function title(label, params) {
34
32
  const options = [];
35
33
  if (params === null || params === void 0 ? void 0 : params.hint)
36
34
  options.push({ label: params.hint, value: 0 });
37
- return new Option(token, { type: widget_options_1.WidgetOptionType.Title, label });
35
+ return new Option({ type: widget_options_1.WidgetOptionType.Title, label });
38
36
  }
39
37
  exports.title = title;
40
38
  function label(label, params) {
41
39
  const options = [];
42
40
  if (params === null || params === void 0 ? void 0 : params.hint)
43
41
  options.push({ label: params.hint, value: 0 });
44
- return new Option(token, { type: widget_options_1.WidgetOptionType.Label, label, options });
42
+ return new Option({ type: widget_options_1.WidgetOptionType.Label, label, options });
45
43
  }
46
44
  exports.label = label;
47
45
  function spacer(span) {
48
- return new Option(token, { type: widget_options_1.WidgetOptionType.Spacer, span });
46
+ return new Option({ type: widget_options_1.WidgetOptionType.Spacer, span });
49
47
  }
50
48
  exports.spacer = spacer;
51
49
  function line() {
52
- return new Option(token, {
50
+ return new Option({
53
51
  type: widget_options_1.WidgetOptionType.LineHorizontal,
54
52
  span: 0,
55
53
  });
@@ -57,54 +55,54 @@ function line() {
57
55
  exports.line = line;
58
56
  // controls
59
57
  function text(params) {
60
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Text }, params));
58
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Text }));
61
59
  }
62
60
  exports.text = text;
63
61
  function number(params) {
64
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Number }, params));
62
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Number }));
65
63
  }
66
64
  exports.number = number;
67
65
  function integer(params) {
68
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Integer }, params));
66
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Integer }));
69
67
  }
70
68
  exports.integer = integer;
71
69
  function range(params) {
72
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Range }, params));
70
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Range }));
73
71
  }
74
72
  exports.range = range;
75
73
  function interval(params) {
76
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Interval }, params));
74
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Interval }));
77
75
  }
78
76
  exports.interval = interval;
79
77
  function date(params) {
80
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Date }, params));
78
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Date }));
81
79
  }
82
80
  exports.date = date;
83
81
  function time(params) {
84
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Time }, params));
82
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Time }));
85
83
  }
86
84
  exports.time = time;
87
85
  function dateTime(params) {
88
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.DateTime }, params));
86
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.DateTime }));
89
87
  }
90
88
  exports.dateTime = dateTime;
91
89
  function checkbox(params) {
92
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Checkbox }, params));
90
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Checkbox }));
93
91
  }
94
92
  exports.checkbox = checkbox;
95
93
  function radio(params) {
96
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Radio }, params));
94
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Radio }));
97
95
  }
98
96
  exports.radio = radio;
99
97
  function radioButton(params) {
100
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.RadioButtons }, params));
98
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.RadioButtons }));
101
99
  }
102
100
  exports.radioButton = radioButton;
103
101
  function select(params) {
104
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.Select }, params));
102
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.Select }));
105
103
  }
106
104
  exports.select = select;
107
105
  function colorPicker(params) {
108
- return new Option(token, Object.assign({ type: widget_options_1.WidgetOptionType.ColorPicker }, params));
106
+ return new Option(Object.assign(Object.assign({}, params), { type: widget_options_1.WidgetOptionType.ColorPicker }));
109
107
  }
110
108
  exports.colorPicker = colorPicker;
package/dataset.d.ts CHANGED
@@ -6,12 +6,29 @@ export declare enum ColumnType {
6
6
  Object = "object",
7
7
  Boolean = "boolean"
8
8
  }
9
+ export interface Dataset {
10
+ readonly columns: Column[];
11
+ readonly columnsByBlock: {
12
+ [blockKey: string]: Column[];
13
+ };
14
+ readonly rows: DatasetRow[];
15
+ readonly heatmap: {
16
+ [path: Column["path"]]: Heatmap;
17
+ };
18
+ readonly events: {
19
+ onHighlight: (rowIndexArray: number[]) => void;
20
+ };
21
+ }
22
+ export interface Heatmap {
23
+ getColor(value: number): string;
24
+ }
9
25
  export interface DatasetRow {
10
26
  [path: string]: any;
11
27
  }
12
28
  export interface Column {
13
- type: ColumnType;
14
- name: string;
15
- path: string;
29
+ readonly type: ColumnType;
30
+ readonly name: string;
31
+ readonly path: string;
16
32
  interact(rowIndex: number): void;
33
+ format(value: any): string;
17
34
  }
package/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- export * from './dataset';
2
- export * from './declare';
3
- export * from './locale';
4
- export * from './theme';
5
- export * from './widget';
1
+ export * from "./dataset";
2
+ export * from "./locale";
3
+ export * from "./provide-data";
4
+ export * from "./theme";
5
+ export * from "./widget";
package/index.js CHANGED
@@ -15,7 +15,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./dataset"), exports);
18
- __exportStar(require("./declare"), exports);
19
18
  __exportStar(require("./locale"), exports);
19
+ __exportStar(require("./provide-data"), exports);
20
20
  __exportStar(require("./theme"), exports);
21
21
  __exportStar(require("./widget"), exports);
package/locale.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export declare type Locale = 'ru' | 'en';
1
+ export declare type Locale = "ru" | "en";
2
2
  export declare type Text = Record<Locale, string>;
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "polymatica-widget",
3
- "version": "2.0.18",
3
+ "version": "2.1.0",
4
4
  "description": "SDK для создания виджетов для платформы Polymatica",
5
5
  "keywords": [],
6
6
  "license": "ISC",
7
7
  "main": "index.js",
8
8
  "dependencies": {
9
- "-": "^0.0.1",
10
- "D": "^1.0.0",
11
- "logical-not": "^1.0.9"
9
+ "logical-not": "^1.0.9",
10
+ "polymatica-jsx": "^1.0.0"
12
11
  }
13
12
  }
@@ -0,0 +1,11 @@
1
+ import { MultiData, Repeatable, SingleData } from "./config";
2
+ import { Dataset } from "./dataset";
3
+ export declare type ProvideData<T> = T extends SingleData & Repeatable ? {
4
+ readonly datasets: Dataset[];
5
+ } : T extends SingleData ? {
6
+ readonly dataset: Dataset;
7
+ } : T extends MultiData<infer DataItemKeys> ? {
8
+ readonly datasets: {
9
+ [Key in DataItemKeys]: T["data"][Key] extends Repeatable ? Dataset[] : Dataset;
10
+ };
11
+ } : never;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
package/theme.d.ts CHANGED
@@ -1,8 +1,3 @@
1
1
  export interface Theme {
2
- text: {
3
- primary: string;
4
- secondary: string;
5
- };
6
2
  palette: string[];
7
- heatmap: string[][];
8
3
  }
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "experimentalDecorators": true,
4
+ "jsx": "react-jsx",
5
+ "jsxImportSource": "polymatica-jsx",
6
+ "lib": ["ES2022", "DOM"],
7
+ "module": "CommonJS",
8
+ "moduleResolution": "Node",
9
+ "strict": true,
10
+ "target": "ES2022",
11
+ "types": ["polymatica-jsx/types"]
12
+ },
13
+
14
+ "include": ["../../src"]
15
+ }
package/widget.d.ts CHANGED
@@ -1,48 +1,20 @@
1
- import { Column, DatasetRow } from './dataset';
2
- import { Locale } from './locale';
3
- import { Theme } from './theme';
1
+ import { JsxElement } from "polymatica-jsx";
2
+ import { Locale } from "./locale";
3
+ import { Theme } from "./theme";
4
4
  export declare abstract class Widget {
5
- readonly options: Options;
6
5
  readonly theme: Theme;
7
6
  readonly lang: Locale;
8
7
  readonly renderEnv: WidgetRenderEnv;
9
- ready(): void;
10
8
  init(): void;
11
- abstract onChange(): void;
9
+ ready(): void;
10
+ abstract render(): JsxElement;
11
+ onChange(): void;
12
12
  onThemeChange(): void;
13
13
  onLangChange(): void;
14
+ translate(key: string, interpolate?: any): string;
14
15
  }
15
- export interface SingleData {
16
- readonly dataset: Dataset;
17
- }
18
- export interface MultiData<DataKeys extends string> {
19
- readonly datasets: Record<DataKeys, Dataset>;
20
- }
21
- export declare type Repeatable<Data extends SingleData | MultiData<string>, RepeatableKeys extends GetMultiDataKeys<Data> | never = never> = Data extends SingleData ? {
22
- readonly datasets: Dataset[];
23
- } : RepeatableKeys extends string ? {
24
- readonly datasets: Record<Exclude<GetMultiDataKeys<Data>, RepeatableKeys>, Dataset> & Record<RepeatableKeys, Dataset[]>;
25
- } : never;
26
- declare type GetMultiDataKeys<T> = T extends MultiData<infer U> ? U : never;
27
- export declare type Provide<T> = T extends {
28
- dataset: infer U;
29
- } ? U : T extends {
30
- datasets: infer U;
31
- } ? U : never;
32
- export interface Dataset {
33
- columns: Column[];
34
- columnsByBlock: {
35
- [blockKey: string]: Column[];
36
- };
37
- rows: DatasetRow[];
38
- heatmap: HeatmapItem[];
39
- events: {
40
- onHighlight: (rowIndexArray: number[]) => void;
41
- };
42
- }
43
- export interface HeatmapItem {
44
- column: Column;
45
- getColor(value: number): string;
16
+ export interface HasOptions {
17
+ readonly options: Options;
46
18
  }
47
19
  export interface Options {
48
20
  [key: string]: any;
@@ -51,4 +23,3 @@ export declare enum WidgetRenderEnv {
51
23
  Default = "default",
52
24
  Print = "print"
53
25
  }
54
- export {};
package/widget.js CHANGED
@@ -5,10 +5,18 @@ class Widget {
5
5
  constructor() {
6
6
  this.renderEnv = WidgetRenderEnv.Default;
7
7
  }
8
- ready() { }
9
8
  init() { }
10
- onThemeChange() { }
11
- onLangChange() { }
9
+ ready() { }
10
+ onChange() { }
11
+ onThemeChange() {
12
+ this.render();
13
+ }
14
+ onLangChange() {
15
+ this.render();
16
+ }
17
+ translate(key, interpolate) {
18
+ return "";
19
+ }
12
20
  }
13
21
  exports.Widget = Widget;
14
22
  var WidgetRenderEnv;
@@ -1,68 +0,0 @@
1
- import { Column } from '../dataset';
2
- import { Locale } from '../locale';
3
- import { Theme } from '../theme';
4
- import { Dataset, Options, WidgetRenderEnv } from '../widget';
5
- export declare enum Input {
6
- Change = "poly.input.change",
7
- ChangeWidgetRenderEnv = "poly.input.changeWidgetRenderEnv",
8
- ChangeLang = "poly.input.changeLang",
9
- ChangeTheme = "poly.input.changeTheme",
10
- Highlight = "poly.input.highlight",
11
- UnHighlight = "poly.input.unhighlight"
12
- }
13
- export declare enum Output {
14
- Init = "poly.output.init",
15
- Ready = "poly.output.ready",
16
- Interact = "poly.output.interact"
17
- }
18
- export declare type InputColumn = Omit<Column, 'interact'> & {
19
- columnId: number;
20
- };
21
- export declare type InputDataset = Omit<Dataset, 'columns' | 'columnsByBlock' | 'events'> & {
22
- datasetId: number;
23
- columns: InputColumn[];
24
- columnsByBlock: Record<string, number[]>;
25
- };
26
- export interface InputSingleData {
27
- readonly dataset: InputDataset;
28
- }
29
- export interface InputMultiData {
30
- readonly datasets: {
31
- [datasetKey: string]: InputDataset;
32
- };
33
- }
34
- export declare type InputRepeatable<T extends InputSingleData | InputMultiData> = T extends InputSingleData ? {
35
- readonly datasets: InputDataset[];
36
- } : {
37
- readonly datasets: {
38
- [datasetKey: string]: InputDataset | InputDataset[];
39
- };
40
- };
41
- export declare type InputData = InputSingleData | InputMultiData | InputRepeatable<InputSingleData> | InputRepeatable<InputMultiData>;
42
- export interface InputParameter extends Record<Input, any> {
43
- [Input.Change]: [InputData, Options];
44
- [Input.ChangeWidgetRenderEnv]: WidgetRenderEnv;
45
- [Input.ChangeLang]: Locale;
46
- [Input.ChangeTheme]: Theme;
47
- [Input.Highlight]: {
48
- datasetId: number;
49
- rowIndexArray: number[];
50
- };
51
- [Input.UnHighlight]: {
52
- datasetId: number;
53
- };
54
- }
55
- export interface OutputParameter extends Record<Output, any> {
56
- [Output.Init]: void;
57
- [Output.Ready]: void;
58
- [Output.Interact]: {
59
- datasetId: number;
60
- columnId: number;
61
- dataIndex: number;
62
- };
63
- }
64
- export interface OutputData {
65
- token: string;
66
- type: Output;
67
- payload?: any;
68
- }
@@ -1,18 +0,0 @@
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["ChangeWidgetRenderEnv"] = "poly.input.changeWidgetRenderEnv";
8
- Input["ChangeLang"] = "poly.input.changeLang";
9
- Input["ChangeTheme"] = "poly.input.changeTheme";
10
- Input["Highlight"] = "poly.input.highlight";
11
- Input["UnHighlight"] = "poly.input.unhighlight";
12
- })(Input = exports.Input || (exports.Input = {}));
13
- var Output;
14
- (function (Output) {
15
- Output["Init"] = "poly.output.init";
16
- Output["Ready"] = "poly.output.ready";
17
- Output["Interact"] = "poly.output.interact";
18
- })(Output = exports.Output || (exports.Output = {}));
package/declare.d.ts DELETED
@@ -1 +0,0 @@
1
- export declare function Declare(): ClassDecorator;
package/declare.js DELETED
@@ -1,141 +0,0 @@
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.ChangeWidgetRenderEnv, value => set(instance, 'renderEnv', value));
39
- input(io_1.Input.ChangeLang, lang => {
40
- set(instance, 'lang', lang);
41
- if (inited)
42
- call(instance, 'onLangChange');
43
- });
44
- input(io_1.Input.ChangeTheme, theme => {
45
- set(instance, 'theme', theme);
46
- if (inited)
47
- call(instance, 'onThemeChange');
48
- });
49
- input(io_1.Input.Highlight, ({ datasetId, rowIndexArray }) => {
50
- const dataset = datasetMap.get(datasetId);
51
- dataset === null || dataset === void 0 ? void 0 : dataset.events.onHighlight(rowIndexArray);
52
- });
53
- output(token, io_1.Output.Init);
54
- return T;
55
- };
56
- }
57
- exports.Declare = Declare;
58
- function provideTo(widget, source, token) {
59
- datasetMap.clear();
60
- if ('dataset' in source) {
61
- const { dataset } = source;
62
- Object.assign(widget, {
63
- dataset: transform(dataset, token),
64
- });
65
- }
66
- else {
67
- if (Array.isArray(source)) {
68
- const { datasets } = source;
69
- Object.assign(widget, {
70
- datasets: datasets.map(dataset => transform(dataset, token)),
71
- });
72
- }
73
- else {
74
- const datasets = {};
75
- Object.entries(source).forEach(([key, item]) => {
76
- if (Array.isArray(item)) {
77
- datasets[key] = item.map(dataset => transform(dataset, token));
78
- }
79
- else {
80
- datasets[key] = transform(item, token);
81
- }
82
- });
83
- Object.assign(widget, { datasets });
84
- }
85
- }
86
- }
87
- function transform(source, token) {
88
- const { datasetId, columns: sourceColumns, columnsByBlock: sourceColumnsByBlock } = source, slice = __rest(source, ["datasetId", "columns", "columnsByBlock"]);
89
- const columnsById = new Map();
90
- const columns = sourceColumns.map((_a) => {
91
- var { columnId } = _a, source = __rest(_a, ["columnId"]);
92
- const column = Object.assign(Object.assign({}, source), { interact(rowIndex) {
93
- output(token, io_1.Output.Interact, {
94
- datasetId,
95
- columnId,
96
- dataIndex: rowIndex,
97
- });
98
- } });
99
- columnsById.set(columnId, column);
100
- return column;
101
- });
102
- const columnsByBlock = {};
103
- Object.entries(sourceColumnsByBlock).forEach(([blockKey, columnIds]) => {
104
- columnsByBlock[blockKey] = [];
105
- columnIds.forEach(id => {
106
- const column = columnsById.get(id);
107
- if (column)
108
- columnsByBlock[blockKey].push(column);
109
- });
110
- });
111
- const dataset = Object.assign(Object.assign({}, slice), { columns,
112
- columnsByBlock, events: {
113
- onHighlight() { },
114
- } });
115
- datasetMap.set(datasetId, dataset);
116
- return dataset;
117
- }
118
- function set(instance, key, value) {
119
- instance[key] = value;
120
- }
121
- function call(instance, method) {
122
- if (typeof instance[method] === 'function')
123
- instance[method]();
124
- }
125
- function input(type, callback) {
126
- window.addEventListener('message', ({ data }) => {
127
- if (data.type === type)
128
- callback(data.payload);
129
- });
130
- }
131
- function output(token, type, payload) {
132
- const message = { type, token, payload };
133
- window.parent.postMessage(message, '*');
134
- }
135
- function readFromUrl(key) {
136
- const startsWith = key + '=';
137
- const source = window.location.search
138
- .split(/[?&]/)
139
- .find(item => item.startsWith(startsWith));
140
- return source ? source.slice(startsWith.length) : '';
141
- }