@omegagrid/grid-core 0.10.2 → 0.10.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/dist/__generated/functions.d.ts +4 -0
- package/dist/__generated/functions.d.ts.map +1 -0
- package/dist/__generated/functions.js +45 -0
- package/dist/__generated/functions.js.map +1 -0
- package/dist/calculations/autofill.d.ts +7 -0
- package/dist/calculations/autofill.d.ts.map +1 -0
- package/dist/calculations/autofill.js +84 -0
- package/dist/calculations/autofill.js.map +1 -0
- package/dist/calculations/conditions.d.ts +4 -0
- package/dist/calculations/conditions.d.ts.map +1 -0
- package/dist/calculations/conditions.js +41 -0
- package/dist/calculations/conditions.js.map +1 -0
- package/dist/calculations/context.d.ts +53 -0
- package/dist/calculations/context.d.ts.map +1 -0
- package/dist/calculations/context.js +85 -0
- package/dist/calculations/context.js.map +1 -0
- package/dist/calculations/formula.d.ts +89 -0
- package/dist/calculations/formula.d.ts.map +1 -0
- package/dist/calculations/formula.js +443 -0
- package/dist/calculations/formula.js.map +1 -0
- package/dist/calculations/functions/dates.d.ts +13 -0
- package/dist/calculations/functions/dates.d.ts.map +1 -0
- package/dist/calculations/functions/dates.js +58 -0
- package/dist/calculations/functions/dates.js.map +1 -0
- package/dist/calculations/functions/index.d.ts +11 -0
- package/dist/calculations/functions/index.d.ts.map +1 -0
- package/dist/calculations/functions/index.js +21 -0
- package/dist/calculations/functions/index.js.map +1 -0
- package/dist/calculations/functions/logical.d.ts +11 -0
- package/dist/calculations/functions/logical.d.ts.map +1 -0
- package/dist/calculations/functions/logical.js +50 -0
- package/dist/calculations/functions/logical.js.map +1 -0
- package/dist/calculations/functions/lookup.d.ts +18 -0
- package/dist/calculations/functions/lookup.d.ts.map +1 -0
- package/dist/calculations/functions/lookup.js +169 -0
- package/dist/calculations/functions/lookup.js.map +1 -0
- package/dist/calculations/functions/math.d.ts +72 -0
- package/dist/calculations/functions/math.d.ts.map +1 -0
- package/dist/calculations/functions/math.js +182 -0
- package/dist/calculations/functions/math.js.map +1 -0
- package/dist/calculations/functions/special.d.ts +2 -0
- package/dist/calculations/functions/special.d.ts.map +1 -0
- package/dist/calculations/functions/special.js +51 -0
- package/dist/calculations/functions/special.js.map +1 -0
- package/dist/calculations/functions/statistical.d.ts +7 -0
- package/dist/calculations/functions/statistical.d.ts.map +1 -0
- package/dist/calculations/functions/statistical.js +47 -0
- package/dist/calculations/functions/statistical.js.map +1 -0
- package/dist/calculations/functions/text.d.ts +29 -0
- package/dist/calculations/functions/text.d.ts.map +1 -0
- package/dist/calculations/functions/text.js +58 -0
- package/dist/calculations/functions/text.js.map +1 -0
- package/dist/calculations/helpers.d.ts +13 -0
- package/dist/calculations/helpers.d.ts.map +1 -0
- package/dist/calculations/helpers.js +32 -0
- package/dist/calculations/helpers.js.map +1 -0
- package/dist/calculations/index.d.ts +7 -0
- package/dist/calculations/index.d.ts.map +1 -0
- package/dist/calculations/index.js +7 -0
- package/dist/calculations/index.js.map +1 -0
- package/dist/calculations/operators.d.ts +19 -0
- package/dist/calculations/operators.d.ts.map +1 -0
- package/dist/calculations/operators.js +58 -0
- package/dist/calculations/operators.js.map +1 -0
- package/dist/calculations/tokenization.d.ts +36 -0
- package/dist/calculations/tokenization.d.ts.map +1 -0
- package/dist/calculations/tokenization.js +203 -0
- package/dist/calculations/tokenization.js.map +1 -0
- package/dist/common/index.d.ts +2 -0
- package/dist/common/index.d.ts.map +1 -0
- package/dist/common/index.js +2 -0
- package/dist/common/index.js.map +1 -0
- package/dist/common/range.d.ts +66 -0
- package/dist/common/range.d.ts.map +1 -0
- package/dist/common/range.js +222 -0
- package/dist/common/range.js.map +1 -0
- package/dist/constants.d.ts +68 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +127 -0
- package/dist/constants.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/model/calculationModel.d.ts +30 -0
- package/dist/model/calculationModel.d.ts.map +1 -0
- package/dist/model/calculationModel.js +206 -0
- package/dist/model/calculationModel.js.map +1 -0
- package/dist/model/cellModel.d.ts +134 -0
- package/dist/model/cellModel.d.ts.map +1 -0
- package/dist/model/cellModel.js +371 -0
- package/dist/model/cellModel.js.map +1 -0
- package/dist/model/columnModel.d.ts +160 -0
- package/dist/model/columnModel.d.ts.map +1 -0
- package/dist/model/columnModel.js +159 -0
- package/dist/model/columnModel.js.map +1 -0
- package/dist/model/commentModel.d.ts +58 -0
- package/dist/model/commentModel.d.ts.map +1 -0
- package/dist/model/commentModel.js +81 -0
- package/dist/model/commentModel.js.map +1 -0
- package/dist/model/conditionalFormats.d.ts +104 -0
- package/dist/model/conditionalFormats.d.ts.map +1 -0
- package/dist/model/conditionalFormats.js +414 -0
- package/dist/model/conditionalFormats.js.map +1 -0
- package/dist/model/cssStyle.d.ts +20 -0
- package/dist/model/cssStyle.d.ts.map +1 -0
- package/dist/model/cssStyle.js +301 -0
- package/dist/model/cssStyle.js.map +1 -0
- package/dist/model/dependencies.d.ts +30 -0
- package/dist/model/dependencies.d.ts.map +1 -0
- package/dist/model/dependencies.js +139 -0
- package/dist/model/dependencies.js.map +1 -0
- package/dist/model/dependencyModel.d.ts +9 -0
- package/dist/model/dependencyModel.d.ts.map +1 -0
- package/dist/model/dependencyModel.js +9 -0
- package/dist/model/dependencyModel.js.map +1 -0
- package/dist/model/elementModel.d.ts +103 -0
- package/dist/model/elementModel.d.ts.map +1 -0
- package/dist/model/elementModel.js +181 -0
- package/dist/model/elementModel.js.map +1 -0
- package/dist/model/filterModel.d.ts +35 -0
- package/dist/model/filterModel.d.ts.map +1 -0
- package/dist/model/filterModel.js +153 -0
- package/dist/model/filterModel.js.map +1 -0
- package/dist/model/gridModel.d.ts +181 -0
- package/dist/model/gridModel.d.ts.map +1 -0
- package/dist/model/gridModel.js +797 -0
- package/dist/model/gridModel.js.map +1 -0
- package/dist/model/groupModel.d.ts +26 -0
- package/dist/model/groupModel.d.ts.map +1 -0
- package/dist/model/groupModel.js +112 -0
- package/dist/model/groupModel.js.map +1 -0
- package/dist/model/history.d.ts +24 -0
- package/dist/model/history.d.ts.map +1 -0
- package/dist/model/history.js +35 -0
- package/dist/model/history.js.map +1 -0
- package/dist/model/index.d.ts +23 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +23 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/iterableRange.d.ts +49 -0
- package/dist/model/iterableRange.d.ts.map +1 -0
- package/dist/model/iterableRange.js +108 -0
- package/dist/model/iterableRange.js.map +1 -0
- package/dist/model/merges.d.ts +34 -0
- package/dist/model/merges.d.ts.map +1 -0
- package/dist/model/merges.js +123 -0
- package/dist/model/merges.js.map +1 -0
- package/dist/model/namingModel.d.ts +25 -0
- package/dist/model/namingModel.d.ts.map +1 -0
- package/dist/model/namingModel.js +77 -0
- package/dist/model/namingModel.js.map +1 -0
- package/dist/model/options.d.ts +257 -0
- package/dist/model/options.d.ts.map +1 -0
- package/dist/model/options.js +35 -0
- package/dist/model/options.js.map +1 -0
- package/dist/model/rowModel.d.ts +104 -0
- package/dist/model/rowModel.d.ts.map +1 -0
- package/dist/model/rowModel.js +155 -0
- package/dist/model/rowModel.js.map +1 -0
- package/dist/model/selectionModel.d.ts +19 -0
- package/dist/model/selectionModel.d.ts.map +1 -0
- package/dist/model/selectionModel.js +40 -0
- package/dist/model/selectionModel.js.map +1 -0
- package/dist/model/sortingModel.d.ts +46 -0
- package/dist/model/sortingModel.d.ts.map +1 -0
- package/dist/model/sortingModel.js +157 -0
- package/dist/model/sortingModel.js.map +1 -0
- package/dist/model/style.d.ts +90 -0
- package/dist/model/style.d.ts.map +1 -0
- package/dist/model/style.js +34 -0
- package/dist/model/style.js.map +1 -0
- package/dist/model/styleModel.d.ts +22 -0
- package/dist/model/styleModel.d.ts.map +1 -0
- package/dist/model/styleModel.js +91 -0
- package/dist/model/styleModel.js.map +1 -0
- package/dist/model/tableTheme.d.ts +46 -0
- package/dist/model/tableTheme.d.ts.map +1 -0
- package/dist/model/tableTheme.js +93 -0
- package/dist/model/tableTheme.js.map +1 -0
- package/dist/model/validations.d.ts +5 -0
- package/dist/model/validations.d.ts.map +1 -0
- package/dist/model/validations.js +24 -0
- package/dist/model/validations.js.map +1 -0
- package/dist/sparklines/index.d.ts +2 -0
- package/dist/sparklines/index.d.ts.map +1 -0
- package/dist/sparklines/index.js +2 -0
- package/dist/sparklines/index.js.map +1 -0
- package/dist/sparklines/sparklines.d.ts +59 -0
- package/dist/sparklines/sparklines.d.ts.map +1 -0
- package/dist/sparklines/sparklines.js +176 -0
- package/dist/sparklines/sparklines.js.map +1 -0
- package/dist/types.d.ts +103 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +4 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +11 -0
- package/dist/utils.js.map +1 -0
- package/package.json +3 -3
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { ComponentAdapter, numbers, ValueFormatter, CustomProperties } from "@omegagrid/core";
|
|
2
|
+
import { CellType, CellValidation, CellValidationSource, CommentRenderer, Renderer, StyleSource } from "../types";
|
|
3
|
+
import { GridModel } from "./gridModel";
|
|
4
|
+
import { Style, StylePropertyKey } from "./style";
|
|
5
|
+
/**
|
|
6
|
+
* Source object type for grid element.
|
|
7
|
+
* Common ancestor for ColumnSource, RowSource and CellSource.
|
|
8
|
+
*/
|
|
9
|
+
export type ElementSource = {
|
|
10
|
+
/** cell type */
|
|
11
|
+
t?: CellType;
|
|
12
|
+
/** style */
|
|
13
|
+
s?: StyleSource;
|
|
14
|
+
/** enable cell editing */
|
|
15
|
+
e?: boolean;
|
|
16
|
+
/** number format */
|
|
17
|
+
z?: numbers.NumberFormatString;
|
|
18
|
+
/** formula */
|
|
19
|
+
f?: string;
|
|
20
|
+
/** range name */
|
|
21
|
+
name?: string;
|
|
22
|
+
/** custom properties */
|
|
23
|
+
props?: CustomProperties;
|
|
24
|
+
/** cell editor content */
|
|
25
|
+
content?: unknown;
|
|
26
|
+
/** cell editor adapter */
|
|
27
|
+
adapter?: ComponentAdapter;
|
|
28
|
+
/** enable cell commenting */
|
|
29
|
+
commentable?: boolean;
|
|
30
|
+
/** enable cell clicking */
|
|
31
|
+
clickable?: boolean;
|
|
32
|
+
/** cell renderer */
|
|
33
|
+
renderer?: Renderer;
|
|
34
|
+
/** cell renderer applied after initial renderer */
|
|
35
|
+
afterRenderer?: Renderer;
|
|
36
|
+
/** comment content renderer */
|
|
37
|
+
commentRenderer?: CommentRenderer;
|
|
38
|
+
/** cell value validation options */
|
|
39
|
+
validation?: CellValidationSource;
|
|
40
|
+
};
|
|
41
|
+
export declare class ElementModel {
|
|
42
|
+
readonly model: GridModel;
|
|
43
|
+
get address(): string;
|
|
44
|
+
protected _renderer: Renderer;
|
|
45
|
+
get renderer(): Renderer;
|
|
46
|
+
set renderer(renderer: Renderer);
|
|
47
|
+
protected _afterRenderer: Renderer;
|
|
48
|
+
get afterRenderer(): Renderer;
|
|
49
|
+
set afterRenderer(afterRenderer: Renderer);
|
|
50
|
+
protected _commentRenderer: CommentRenderer;
|
|
51
|
+
get commentRenderer(): CommentRenderer;
|
|
52
|
+
set commentRenderer(commentRenderer: CommentRenderer);
|
|
53
|
+
protected _type: CellType;
|
|
54
|
+
get type(): CellType;
|
|
55
|
+
set type(v: CellType);
|
|
56
|
+
protected _name: string;
|
|
57
|
+
get name(): string;
|
|
58
|
+
set name(v: string);
|
|
59
|
+
protected _style: number;
|
|
60
|
+
get style(): number;
|
|
61
|
+
set style(v: number);
|
|
62
|
+
protected _commentable: boolean;
|
|
63
|
+
get commentable(): boolean;
|
|
64
|
+
set commentable(v: boolean);
|
|
65
|
+
protected _clickable: boolean;
|
|
66
|
+
get clickable(): boolean;
|
|
67
|
+
set clickable(v: boolean);
|
|
68
|
+
protected _editable: boolean;
|
|
69
|
+
get editable(): boolean;
|
|
70
|
+
set editable(v: boolean);
|
|
71
|
+
protected _validation: CellValidation;
|
|
72
|
+
get validation(): CellValidation;
|
|
73
|
+
set validation(v: CellValidation);
|
|
74
|
+
protected _formula: string;
|
|
75
|
+
get hasFormula(): boolean;
|
|
76
|
+
get formula(): string;
|
|
77
|
+
set formula(v: string);
|
|
78
|
+
get value2(): string | unknown;
|
|
79
|
+
protected _editorContent: unknown;
|
|
80
|
+
get editorContent(): unknown;
|
|
81
|
+
set editorContent(v: unknown);
|
|
82
|
+
protected _adapter: ComponentAdapter;
|
|
83
|
+
get adapter(): ComponentAdapter;
|
|
84
|
+
set adapter(v: ComponentAdapter);
|
|
85
|
+
protected _properties: CustomProperties;
|
|
86
|
+
get properties(): CustomProperties;
|
|
87
|
+
set properties(v: CustomProperties);
|
|
88
|
+
getProperty(key: string): unknown;
|
|
89
|
+
setProperty(key: string, value: unknown): void;
|
|
90
|
+
protected _valueFormatter: ValueFormatter;
|
|
91
|
+
protected _format: numbers.NumberFormatString;
|
|
92
|
+
get format(): numbers.NumberFormatString;
|
|
93
|
+
set format(v: numbers.NumberFormatString);
|
|
94
|
+
get valueFormatter(): ValueFormatter;
|
|
95
|
+
constructor(model: GridModel, source?: ElementSource);
|
|
96
|
+
populate(source: ElementSource): void;
|
|
97
|
+
update(source: ElementSource): ElementSource;
|
|
98
|
+
getSourceData(): ElementSource;
|
|
99
|
+
setStyleProperties(props: Record<StylePropertyKey, unknown>, updateEixistingStyle?: boolean): void;
|
|
100
|
+
removeStyleProperties(props: string[]): void;
|
|
101
|
+
get composedStyle(): Style;
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=elementModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementModel.d.ts","sourceRoot":"","sources":["../../src/model/elementModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAS,MAAM,iBAAiB,CAAC;AAErG,OAA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1B;CAED"}
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { utils } from "@omegagrid/core";
|
|
2
|
+
import { prefixFormula } from "../calculations";
|
|
3
|
+
import { normalizeCellValidation } from "./validations";
|
|
4
|
+
export class ElementModel {
|
|
5
|
+
get address() { return null; }
|
|
6
|
+
get renderer() { return this._renderer; }
|
|
7
|
+
set renderer(renderer) { this._renderer = renderer; }
|
|
8
|
+
get afterRenderer() { return this._afterRenderer; }
|
|
9
|
+
set afterRenderer(afterRenderer) { this._afterRenderer = afterRenderer; }
|
|
10
|
+
get commentRenderer() { return this._commentRenderer; }
|
|
11
|
+
set commentRenderer(commentRenderer) { this._commentRenderer = commentRenderer; }
|
|
12
|
+
get type() { return this._type; }
|
|
13
|
+
set type(v) { this._type = v; }
|
|
14
|
+
get name() { return this._name; }
|
|
15
|
+
set name(v) { this._name = v; }
|
|
16
|
+
get style() { return this._style; }
|
|
17
|
+
set style(v) { this._style = v; }
|
|
18
|
+
get commentable() { return this._commentable; }
|
|
19
|
+
set commentable(v) { this._commentable = v; }
|
|
20
|
+
get clickable() { return this._clickable; }
|
|
21
|
+
set clickable(v) { this._clickable = v; }
|
|
22
|
+
get editable() { return this._editable; }
|
|
23
|
+
set editable(v) { this._editable = v; }
|
|
24
|
+
get validation() { return this._validation; }
|
|
25
|
+
set validation(v) { this._validation = v; }
|
|
26
|
+
get hasFormula() { return !!this._formula; }
|
|
27
|
+
get formula() { return this._formula; }
|
|
28
|
+
set formula(v) { this._formula = v ? v.replace(/^=/, '') : null; }
|
|
29
|
+
get value2() { return this.hasFormula ? prefixFormula(this.formula) : null; }
|
|
30
|
+
get editorContent() { return this._editorContent; }
|
|
31
|
+
set editorContent(v) { this._editorContent = v; }
|
|
32
|
+
get adapter() { return this._adapter; }
|
|
33
|
+
set adapter(v) { this._adapter = v; }
|
|
34
|
+
get properties() { return this._properties; }
|
|
35
|
+
set properties(v) { this._properties = v; }
|
|
36
|
+
getProperty(key) { return this._properties?.[key]; }
|
|
37
|
+
setProperty(key, value) {
|
|
38
|
+
if (!this._properties)
|
|
39
|
+
this._properties = {};
|
|
40
|
+
this._properties[key] = value;
|
|
41
|
+
}
|
|
42
|
+
get format() { return this._format; }
|
|
43
|
+
set format(v) {
|
|
44
|
+
this._format = v;
|
|
45
|
+
this._valueFormatter = null;
|
|
46
|
+
}
|
|
47
|
+
///TODO: implement date formatter
|
|
48
|
+
get valueFormatter() {
|
|
49
|
+
return this._valueFormatter;
|
|
50
|
+
}
|
|
51
|
+
constructor(model, source) {
|
|
52
|
+
this.model = model;
|
|
53
|
+
this._type = null;
|
|
54
|
+
this._clickable = false;
|
|
55
|
+
if (source)
|
|
56
|
+
this.populate(source);
|
|
57
|
+
}
|
|
58
|
+
populate(source) {
|
|
59
|
+
this._renderer = source.renderer;
|
|
60
|
+
this._afterRenderer = source.afterRenderer;
|
|
61
|
+
this._commentRenderer = source.commentRenderer;
|
|
62
|
+
this._name = source.name;
|
|
63
|
+
this._type = source.t;
|
|
64
|
+
this._editorContent = source.content;
|
|
65
|
+
this._adapter = source.adapter;
|
|
66
|
+
this._format = source.z;
|
|
67
|
+
this._formula = source.f;
|
|
68
|
+
this._editable = source.e;
|
|
69
|
+
this._commentable = source.commentable;
|
|
70
|
+
this._clickable = source.clickable;
|
|
71
|
+
this._validation = source.validation ? normalizeCellValidation(source.validation) : null;
|
|
72
|
+
this._properties = source.props;
|
|
73
|
+
this._style = source.s == null ? null : this.model.styles.add(source.s)?.id;
|
|
74
|
+
}
|
|
75
|
+
update(source) {
|
|
76
|
+
const updatedProps = {};
|
|
77
|
+
if ('renderer' in source) {
|
|
78
|
+
updatedProps.renderer = this._renderer;
|
|
79
|
+
this._renderer = source.renderer;
|
|
80
|
+
}
|
|
81
|
+
if ('afterRenderer' in source) {
|
|
82
|
+
this._afterRenderer = source.afterRenderer;
|
|
83
|
+
}
|
|
84
|
+
if ('commentRenderer' in source) {
|
|
85
|
+
this._commentRenderer = source.commentRenderer;
|
|
86
|
+
}
|
|
87
|
+
if ('name' in source) {
|
|
88
|
+
updatedProps.name = this._name;
|
|
89
|
+
this._name = source.name;
|
|
90
|
+
}
|
|
91
|
+
if ('t' in source) {
|
|
92
|
+
updatedProps.t = this._type;
|
|
93
|
+
this._type = source.t;
|
|
94
|
+
}
|
|
95
|
+
if ('content' in source) {
|
|
96
|
+
updatedProps.content = this._editorContent;
|
|
97
|
+
this._editorContent = source.content;
|
|
98
|
+
}
|
|
99
|
+
if ('adapter' in source) {
|
|
100
|
+
updatedProps.adapter = this._adapter;
|
|
101
|
+
this._adapter = source.adapter;
|
|
102
|
+
}
|
|
103
|
+
if ('z' in source) {
|
|
104
|
+
updatedProps.z = this._format;
|
|
105
|
+
this._format = source.z;
|
|
106
|
+
}
|
|
107
|
+
if ('f' in source) {
|
|
108
|
+
updatedProps.f = this._formula;
|
|
109
|
+
this._formula = source.f;
|
|
110
|
+
}
|
|
111
|
+
if ('e' in source) {
|
|
112
|
+
updatedProps.e = this._editable;
|
|
113
|
+
this._editable = source.e;
|
|
114
|
+
}
|
|
115
|
+
if ('commentable' in source) {
|
|
116
|
+
updatedProps.commentable = this._commentable;
|
|
117
|
+
this._commentable = source.commentable;
|
|
118
|
+
}
|
|
119
|
+
if ('clickable' in source) {
|
|
120
|
+
updatedProps.clickable = this._clickable;
|
|
121
|
+
this._clickable = source.clickable;
|
|
122
|
+
}
|
|
123
|
+
if ('validation' in source) {
|
|
124
|
+
updatedProps.validation = this._validation;
|
|
125
|
+
this._validation = normalizeCellValidation(source.validation);
|
|
126
|
+
}
|
|
127
|
+
if ('props' in source) {
|
|
128
|
+
updatedProps.props = this._properties;
|
|
129
|
+
this._properties = source.props;
|
|
130
|
+
}
|
|
131
|
+
if ('s' in source) {
|
|
132
|
+
const styleId = this.model.styles.add(source.s).id;
|
|
133
|
+
if (this._style !== styleId) {
|
|
134
|
+
updatedProps.s = this._style;
|
|
135
|
+
this._style = styleId;
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return updatedProps;
|
|
139
|
+
}
|
|
140
|
+
getSourceData() {
|
|
141
|
+
const data = {};
|
|
142
|
+
if (this._type != null)
|
|
143
|
+
data.t = this._type;
|
|
144
|
+
if (this._format != null)
|
|
145
|
+
data.z = this._format;
|
|
146
|
+
if (this._formula != null)
|
|
147
|
+
data.f = this._formula;
|
|
148
|
+
if (this._editable != null)
|
|
149
|
+
data.e = this._editable;
|
|
150
|
+
if (this._commentable != null)
|
|
151
|
+
data.commentable = this._commentable;
|
|
152
|
+
if (this._clickable != null)
|
|
153
|
+
data.clickable = this._clickable;
|
|
154
|
+
if (this._properties)
|
|
155
|
+
data.props = utils.cloneDeep(this._properties);
|
|
156
|
+
if (this._editorContent != null)
|
|
157
|
+
data.content = utils.isObject(this._editorContent)
|
|
158
|
+
? utils.cloneDeep(this._editorContent) : this._editorContent;
|
|
159
|
+
if (this._style != null)
|
|
160
|
+
data.s = this._style;
|
|
161
|
+
if (this._name != null)
|
|
162
|
+
data.name = this._name;
|
|
163
|
+
return data;
|
|
164
|
+
}
|
|
165
|
+
setStyleProperties(props, updateEixistingStyle = false) {
|
|
166
|
+
if (updateEixistingStyle) {
|
|
167
|
+
this.style = this.model.styles.set(this.style, props).id;
|
|
168
|
+
}
|
|
169
|
+
else {
|
|
170
|
+
this.style = this.model.styles.duplicate(this.style, props).id;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
removeStyleProperties(props) {
|
|
174
|
+
if (this.style !== null)
|
|
175
|
+
this.model.styles.unset(this.style, props);
|
|
176
|
+
}
|
|
177
|
+
get composedStyle() {
|
|
178
|
+
return this.model.styles.get(this.style);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
//# sourceMappingURL=elementModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"elementModel.js","sourceRoot":"","sources":["../../src/model/elementModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+D,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACrG,OAAO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AAK,CAAC,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,EAAE,CAAC;QAChE,CAAC;IACF,CAAC;IAED,qBAAqB,CAAC,KAAe;QACpC,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI;YAAE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IACrE,CAAC;IAED,IAAI,aAAa;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAC1C,CAAC;CAED","sourcesContent":["import { ComponentAdapter, numbers, ValueFormatter, CustomProperties, utils } from \"@omegagrid/core\";\nimport { prefixFormula } from \"../calculations\";\nimport { CellType, CellValidation, CellValidationSource, CommentRenderer, Renderer, StyleSource } from \"../types\";\nimport { CSSStyle } from \"./cssStyle\";\nimport { GridModel } from \"./gridModel\";\nimport { Style, StylePropertyKey } from \"./style\";\nimport { normalizeCellValidation } from \"./validations\";\n\n/** \n * Source object type for grid element.\n * Common ancestor for ColumnSource, RowSource and CellSource.\n */\nexport type ElementSource = {\n\t/** cell type */\n\tt?: CellType,\n\t/** style */\n\ts?: StyleSource,\n\t/** enable cell editing */\n\te?: boolean,\n\t/** number format */\n\tz?: numbers.NumberFormatString,\n\t/** formula */\n\tf?: string,\n\t/** range name */\n\tname?: string,\n\t/** custom properties */\n\tprops?: CustomProperties,\n\t/** cell editor content */\n\tcontent?: unknown,\n\t/** cell editor adapter */\n\tadapter?: ComponentAdapter,\n\t/** enable cell commenting */\n\tcommentable?: boolean,\n\t/** enable cell clicking */\n\tclickable?: boolean,\n\t/** cell renderer */\n\trenderer?: Renderer,\n\t/** cell renderer applied after initial renderer */\n\tafterRenderer?: Renderer,\n\t/** comment content renderer */\n\tcommentRenderer?: CommentRenderer,\n\t/** cell value validation options */\n\tvalidation?: CellValidationSource\n}\n\nexport class ElementModel {\n\n\tget address(): string { return null }\n\t\n\tprotected _renderer: Renderer;\n\tget renderer() { return this._renderer }\n\tset renderer(renderer: Renderer) { this._renderer = renderer }\n\n\tprotected _afterRenderer: Renderer;\n\tget afterRenderer() { return this._afterRenderer }\n\tset afterRenderer(afterRenderer: Renderer) { this._afterRenderer = afterRenderer }\n\n\tprotected _commentRenderer: CommentRenderer;\n\tget commentRenderer() { return this._commentRenderer }\n\tset commentRenderer(commentRenderer: CommentRenderer) { this._commentRenderer = commentRenderer }\n\t\n\tprotected _type: CellType = null;\n\tget type() { return this._type }\n\tset type(v: CellType) { this._type = v }\n\n\tprotected _name: string;\n\tget name() { return this._name }\n\tset name(v: string) { this._name = v }\n\n\tprotected _style: number;\n\tget style() { return this._style }\n\tset style(v: number) { this._style = v }\n\n\tprotected _commentable: boolean;\n\tget commentable() { return this._commentable }\n\tset commentable(v: boolean) { this._commentable = v }\n\n\tprotected _clickable = false;\n\tget clickable() { return this._clickable }\n\tset clickable(v: boolean) { this._clickable = v }\n\n\tprotected _editable: boolean;\n\tget editable() { return this._editable }\n\tset editable(v: boolean) { this._editable = v }\n\n\tprotected _validation: CellValidation;\n\tget validation() { return this._validation }\n\tset validation(v: CellValidation) { this._validation = v }\n\n\tprotected _formula: string;\n\tget hasFormula() { return !!this._formula }\n\tget formula() { return this._formula }\n\tset formula(v: string) { this._formula = v ? v.replace(/^=/, '') : null }\n\n\tget value2(): string|unknown { return this.hasFormula ? prefixFormula(this.formula) : null }\n\n\tprotected _editorContent: unknown;\n\tget editorContent() { return this._editorContent }\n\tset editorContent(v: unknown) { this._editorContent = v }\n\n\tprotected _adapter: ComponentAdapter;\n\tget adapter() { return this._adapter }\n\tset adapter(v: ComponentAdapter) { this._adapter = v }\n\n\tprotected _properties: CustomProperties;\n\tget properties() { return this._properties }\n\tset properties(v: CustomProperties) { this._properties = v }\n\n\tgetProperty(key: string) { return this._properties?.[key] }\n\tsetProperty(key: string, value: unknown) {\n\t\tif (!this._properties) this._properties = {};\n\t\tthis._properties[key] = value;\n\t}\n\n\tprotected _valueFormatter: ValueFormatter;\n\tprotected _format: numbers.NumberFormatString;\n\tget format() { return this._format }\n\tset format(v: numbers.NumberFormatString) {\n\t\tthis._format = v;\n\t\tthis._valueFormatter = null;\n\t}\n\n\t///TODO: implement date formatter\n\tget valueFormatter(): ValueFormatter {\n\t\treturn this._valueFormatter;\n\t}\n\n\tconstructor(public readonly model: GridModel, source?: ElementSource) {\n\t\tif (source) this.populate(source);\n\t}\n\n\tpopulate(source: ElementSource) {\n\t\tthis._renderer = source.renderer;\n\t\tthis._afterRenderer = source.afterRenderer;\n\t\tthis._commentRenderer = source.commentRenderer;\n\t\tthis._name = source.name;\n\t\tthis._type = source.t;\n\t\tthis._editorContent = source.content;\n\t\tthis._adapter = source.adapter;\n\t\tthis._format = source.z;\n\t\tthis._formula = source.f;\n\t\tthis._editable = source.e;\n\t\tthis._commentable = source.commentable;\n\t\tthis._clickable = source.clickable;\n\t\tthis._validation = source.validation ? normalizeCellValidation(source.validation) : null;\n\t\tthis._properties = source.props;\n\t\tthis._style = source.s == null ? null : this.model.styles.add(source.s)?.id;\n\t}\n\n\tupdate(source: ElementSource) {\n\t\tconst updatedProps = {} as ElementSource;\n\t\tif ('renderer' in source) { updatedProps.renderer = this._renderer; this._renderer = source.renderer; }\n\t\tif ('afterRenderer' in source) { this._afterRenderer = source.afterRenderer; }\n\t\tif ('commentRenderer' in source) { this._commentRenderer = source.commentRenderer; }\n\t\tif ('name' in source) { updatedProps.name = this._name; this._name = source.name; }\n\t\tif ('t' in source) { updatedProps.t = this._type; this._type = source.t; }\n\t\tif ('content' in source) { updatedProps.content = this._editorContent; this._editorContent = source.content; }\n\t\tif ('adapter' in source) { updatedProps.adapter = this._adapter; this._adapter = source.adapter; }\n\t\tif ('z' in source) { updatedProps.z = this._format; this._format = source.z; }\n\t\tif ('f' in source) { updatedProps.f = this._formula; this._formula = source.f; }\n\t\tif ('e' in source) { updatedProps.e = this._editable; this._editable = source.e; }\n\t\tif ('commentable' in source) { updatedProps.commentable = this._commentable; this._commentable = source.commentable; }\n\t\tif ('clickable' in source) { updatedProps.clickable = this._clickable; this._clickable = source.clickable; }\n\t\tif ('validation' in source) { updatedProps.validation = this._validation; this._validation = normalizeCellValidation(source.validation); }\n\t\tif ('props' in source) { updatedProps.props = this._properties; this._properties = source.props; }\n\t\tif ('s' in source) {\n\t\t\tconst styleId = this.model.styles.add(source.s as string|Style|CSSStyle).id;\n\t\t\tif (this._style !== styleId) { updatedProps.s = this._style; this._style = styleId; }\n\t\t}\n\t\treturn updatedProps;\n\t}\n\n\tgetSourceData() {\n\t\tconst data = {} as ElementSource;\n\t\tif (this._type != null) data.t = this._type;\n\t\tif (this._format != null) data.z = this._format;\n\t\tif (this._formula != null) data.f = this._formula;\n\t\tif (this._editable != null) data.e = this._editable;\n\t\tif (this._commentable != null) data.commentable = this._commentable;\n\t\tif (this._clickable != null) data.clickable = this._clickable;\n\t\tif (this._properties) data.props = utils.cloneDeep(this._properties);\n\t\tif (this._editorContent != null) data.content = utils.isObject(this._editorContent) \n\t\t\t? utils.cloneDeep(this._editorContent) : this._editorContent;\n\t\tif (this._style != null) data.s = this._style;\n\t\tif (this._name != null) data.name = this._name;\n\t\treturn data;\n\t}\n\t\t\n\tsetStyleProperties(props: Record<StylePropertyKey, unknown>, updateEixistingStyle = false) {\n\t\tif (updateEixistingStyle) {\n\t\t\tthis.style = this.model.styles.set(this.style, props).id;\n\t\t} else {\n\t\t\tthis.style = this.model.styles.duplicate(this.style, props).id;\n\t\t}\n\t}\n\n\tremoveStyleProperties(props: string[]) {\n\t\tif (this.style !== null) this.model.styles.unset(this.style, props);\n\t}\n\n\tget composedStyle() : Style {\n\t\treturn this.model.styles.get(this.style);\n\t}\n\n}"]}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { KeyValue } from "@omegagrid/core";
|
|
2
|
+
import { CellModel } from "./cellModel";
|
|
3
|
+
import { GridModel } from "./gridModel";
|
|
4
|
+
import { CellType, FilterValue } from "../types";
|
|
5
|
+
export type FilterMatcher = (cell: CellModel) => boolean;
|
|
6
|
+
export type FilterSettings = {
|
|
7
|
+
c: number;
|
|
8
|
+
term: FilterValue;
|
|
9
|
+
};
|
|
10
|
+
export declare const createTextMatcher: <TItem>(term: string, property: keyof TItem) => (item: TItem) => boolean;
|
|
11
|
+
export declare const createBoolMatcher: <TItem>(term: boolean, property: keyof TItem) => (item: TItem) => boolean;
|
|
12
|
+
export declare const createMultiMatcher: <TItem>(term: KeyValue[], property: keyof TItem) => (item: TItem) => boolean;
|
|
13
|
+
export declare const createMultiMultiMatcher: <TItem>(_term: KeyValue[], _property: keyof TItem) => (_item: TItem) => boolean;
|
|
14
|
+
export declare const createCellMatcher: (type: CellType, term: FilterValue, property: keyof CellModel) => (item: CellModel) => boolean;
|
|
15
|
+
export declare class FilterEvent extends Event {
|
|
16
|
+
constructor();
|
|
17
|
+
}
|
|
18
|
+
export declare class FilterModel extends EventTarget {
|
|
19
|
+
readonly model: GridModel;
|
|
20
|
+
custom: boolean;
|
|
21
|
+
private colMap;
|
|
22
|
+
private _settings;
|
|
23
|
+
get settings(): FilterSettings[] | null;
|
|
24
|
+
set settings(v: FilterSettings[] | null);
|
|
25
|
+
constructor(model: GridModel, settings?: FilterSettings[] | null);
|
|
26
|
+
/**
|
|
27
|
+
* Get filtering settings for specified column
|
|
28
|
+
* @param c column index
|
|
29
|
+
*/
|
|
30
|
+
get(c: number): FilterSettings;
|
|
31
|
+
filter(filter: FilterSettings, dispatchEvent?: boolean): void;
|
|
32
|
+
applyFilter(dispatchEvent?: boolean): void;
|
|
33
|
+
resetFilter(dispatchEvent?: boolean): void;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=filterModel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterModel.d.ts","sourceRoot":"","sources":["../../src/model/filterModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAoB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gB,KAAK,EAAE,SAAS,EAChC,QAAQ,GAAE,cAAc,EAAE,GAAC,IAAW;IAMvC;;;OAGG;IACH,GAAG,CAAC,CAAC,EAAE,MAAM;IAIb,MAAM,CAAC,MAAM,EAAE,cAAc,EAAE,aAAa,UAAO;IA4BnD,WAAW,CAAC,aAAa,UAAO;IAoDhC,WAAW,CAAC,aAAa,UAAO;CAQhC"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import { log, tree, utils } from "@omegagrid/core";
|
|
2
|
+
export const createTextMatcher = (term, property) => {
|
|
3
|
+
const regex = new RegExp(`${utils.escapeRegExp(term)}`, 'ig');
|
|
4
|
+
return (item) => {
|
|
5
|
+
regex.lastIndex = 0;
|
|
6
|
+
return regex.test(utils.removeAccents((item[property] ?? "").toString()));
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export const createBoolMatcher = (term, property) => {
|
|
10
|
+
return (item) => !!item[property] === term;
|
|
11
|
+
};
|
|
12
|
+
export const createMultiMatcher = (term, property) => {
|
|
13
|
+
const keys = term.map(t => t.key?.toString());
|
|
14
|
+
return (item) => {
|
|
15
|
+
return item[property] == null ? false : keys.includes(item[property].toString());
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export const createMultiMultiMatcher = (_term, _property) => {
|
|
19
|
+
return (_item) => false;
|
|
20
|
+
};
|
|
21
|
+
export const createCellMatcher = (type, term, property) => {
|
|
22
|
+
property = property ?? 'value';
|
|
23
|
+
if (type === 'b')
|
|
24
|
+
return createBoolMatcher(term, property);
|
|
25
|
+
else if (type === 's' && Array.isArray(term))
|
|
26
|
+
return createMultiMatcher(term, 'value');
|
|
27
|
+
else if (type === 's')
|
|
28
|
+
return createTextMatcher((term?.toString()), 'formattedValue');
|
|
29
|
+
else if (type === 'm' && Array.isArray(term))
|
|
30
|
+
return createMultiMultiMatcher(term, property);
|
|
31
|
+
else if (type === 'd')
|
|
32
|
+
return createTextMatcher((term?.toString()), 'formattedValue');
|
|
33
|
+
return createTextMatcher((term?.toString()), property);
|
|
34
|
+
};
|
|
35
|
+
export class FilterEvent extends Event {
|
|
36
|
+
constructor() {
|
|
37
|
+
super('filter', { bubbles: false, cancelable: true, composed: true });
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
export class FilterModel extends EventTarget {
|
|
41
|
+
get settings() { return this._settings; }
|
|
42
|
+
set settings(v) {
|
|
43
|
+
this._settings = v || [];
|
|
44
|
+
this.colMap.clear();
|
|
45
|
+
if (this.settings.length > 0) {
|
|
46
|
+
this.settings.forEach((s, i) => this.colMap.set(s.c, i));
|
|
47
|
+
this.applyFilter();
|
|
48
|
+
log.getLogger().info(`filtering applied: ${JSON.stringify(this.settings)}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
constructor(model, settings = null) {
|
|
52
|
+
super();
|
|
53
|
+
this.model = model;
|
|
54
|
+
this.custom = false;
|
|
55
|
+
this.colMap = new Map();
|
|
56
|
+
this._settings = [];
|
|
57
|
+
this.settings = settings;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Get filtering settings for specified column
|
|
61
|
+
* @param c column index
|
|
62
|
+
*/
|
|
63
|
+
get(c) {
|
|
64
|
+
return this.colMap.has(c) ? this.settings[this.colMap.get(c)] : null;
|
|
65
|
+
}
|
|
66
|
+
filter(filter, dispatchEvent = true) {
|
|
67
|
+
const filterSetting = this.get(filter.c);
|
|
68
|
+
const empty = filter.term === null || filter.term === '';
|
|
69
|
+
if (filterSetting && empty) {
|
|
70
|
+
// remove
|
|
71
|
+
this.settings.splice(this.colMap.get(filter.c), 1);
|
|
72
|
+
this.colMap.delete(filter.c);
|
|
73
|
+
}
|
|
74
|
+
else if (filterSetting) {
|
|
75
|
+
// update
|
|
76
|
+
filterSetting.term = filter.term;
|
|
77
|
+
}
|
|
78
|
+
else if (!empty) {
|
|
79
|
+
// add
|
|
80
|
+
this.colMap.set(filter.c, this.settings.length);
|
|
81
|
+
this.settings.push(filter);
|
|
82
|
+
}
|
|
83
|
+
if (!this.custom) {
|
|
84
|
+
if (this.settings.length > 0) {
|
|
85
|
+
this.applyFilter(false);
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
this.resetFilter(false);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
if (dispatchEvent)
|
|
92
|
+
this.dispatchEvent(new FilterEvent());
|
|
93
|
+
}
|
|
94
|
+
applyFilter(dispatchEvent = true) {
|
|
95
|
+
const cellMatchers = [];
|
|
96
|
+
this.settings.forEach((s) => {
|
|
97
|
+
const column = this.model.columns[s.c];
|
|
98
|
+
cellMatchers.push({ c: s.c, matcher: createCellMatcher(column.type, s.term, column.filter?.property) });
|
|
99
|
+
});
|
|
100
|
+
const count = cellMatchers.length;
|
|
101
|
+
const rowMatcher = (row) => {
|
|
102
|
+
if (!row.filterable)
|
|
103
|
+
return true;
|
|
104
|
+
for (let i = 0; i < count; i++) {
|
|
105
|
+
if (!cellMatchers[i].matcher(row.cell(cellMatchers[i].c))) {
|
|
106
|
+
return false;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
111
|
+
const includeParents = this.model.options.filters?.includeParents ?? true;
|
|
112
|
+
const includeChildren = this.model.options.filters?.includeChildren ?? true;
|
|
113
|
+
const visitedRows = new Set();
|
|
114
|
+
this.model.rows.forEach(row => {
|
|
115
|
+
const visited = visitedRows.has(row.index);
|
|
116
|
+
if (rowMatcher(row)) {
|
|
117
|
+
row.filterState = tree.FilterState.Matched;
|
|
118
|
+
if (includeParents) {
|
|
119
|
+
row.walkUp((parent) => {
|
|
120
|
+
if (visitedRows.has(parent.index) && parent.filterState > 0)
|
|
121
|
+
return false;
|
|
122
|
+
parent.filterState = tree.FilterState.ChildMatched;
|
|
123
|
+
visitedRows.add(parent.index);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
if (includeChildren) {
|
|
127
|
+
row.walk((child) => {
|
|
128
|
+
if (visitedRows.has(child.index) && child.filterState > 0)
|
|
129
|
+
return false;
|
|
130
|
+
child.filterState = tree.FilterState.ParentMatched;
|
|
131
|
+
visitedRows.add(child.index);
|
|
132
|
+
});
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
else if (!visited) {
|
|
136
|
+
row.filterState = tree.FilterState.Filtered;
|
|
137
|
+
}
|
|
138
|
+
visitedRows.add(row.index);
|
|
139
|
+
});
|
|
140
|
+
this.model.indexRows();
|
|
141
|
+
if (dispatchEvent)
|
|
142
|
+
this.dispatchEvent(new FilterEvent());
|
|
143
|
+
}
|
|
144
|
+
resetFilter(dispatchEvent = true) {
|
|
145
|
+
this.settings = [];
|
|
146
|
+
this.colMap.clear();
|
|
147
|
+
this.model.rows.forEach(row => row.filterState = tree.FilterState.Matched);
|
|
148
|
+
this.model.indexRows();
|
|
149
|
+
if (dispatchEvent)
|
|
150
|
+
this.dispatchEvent(new FilterEvent());
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=filterModel.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filterModel.js","sourceRoot":"","sources":["../../src/model/filterModel.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAc7D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAQ,IAAY,EAAE,QAAqB,EAAE,EAAE;IAC/E,MAAM,KAAK,GAAG,IAAI,MAAM,CAAC,GAAG,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IAC9D,OAAO,CAAC,IAAW,EAAE,EAAE;QACtB,KAAK,CAAC,SAAS,GAAG,CAAC,CAAC;QACpB,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,CAAC;IAC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AAC,IAAI,KAAK,CAAC,WAAW,GAAG,CAAC;4BAAE,OAAO,KAAK,CAAC;wBACxE,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC;wBACnD,WAAW,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;oBAC9B,CAAC,CAAC,CAAC;gBACJ,CAAC;YACF,CAAC;iBAAM,IAAI,CAAC,OAAO,EAAE,CAAC;gBACrB,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC;YAC7C,CAAC;YAED,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC5B,CAAC,CAAC,CAAC;QAEH,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACvB,IAAI,aAAa;YAAE,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA;IACzD,CAAC;IAED,WAAW,CAAC,aAAa,GAAG,IAAI;QAC/B,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;QACnB,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;QACpB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;QAC3E,IAAI,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QACvB,IAAI,aAAa;YAAE,IAAI,CAAC,aAAa,CAAC,IAAI,WAAW,EAAE,CAAC,CAAA;IACzD,CAAC;CAED","sourcesContent":["import { KeyValue, log, tree, utils } from \"@omegagrid/core\";\nimport { CellModel } from \"./cellModel\";\nimport { GridModel } from \"./gridModel\";\nimport { RowModel } from \"./rowModel\";\nimport { FilterOptions } from \"./options\";\nimport { CellType, FilterValue } from \"../types\";\n\nexport type FilterMatcher = (cell: CellModel) => boolean;\n\nexport type FilterSettings = {\n\tc: number;\n\tterm: FilterValue;\n};\n\nexport const createTextMatcher = <TItem>(term: string, property: keyof TItem) => {\n\tconst regex = new RegExp(`${utils.escapeRegExp(term)}`, 'ig');\n\treturn (item: TItem) => {\n\t\tregex.lastIndex = 0;\n\t\treturn regex.test(utils.removeAccents((item[property] ?? \"\").toString()));\n\t}\n};\n\nexport const createBoolMatcher = <TItem>(term: boolean, property: keyof TItem) => {\n\treturn (item: TItem) => !!item[property] === term;\n};\n\nexport const createMultiMatcher = <TItem>(term: KeyValue[], property: keyof TItem) => {\n\tconst keys = term.map(t => t.key?.toString());\n\treturn (item: TItem) => {\n\t\treturn item[property] == null ? false : keys.includes(item[property].toString());\n\t};\n};\n\nexport const createMultiMultiMatcher = <TItem>(_term: KeyValue[], _property: keyof TItem) => {\n\treturn (_item: TItem) => false;\n};\n\nexport const createCellMatcher = (type: CellType, term: FilterValue, property: keyof CellModel) => {\n\tproperty = property ?? 'value';\n\tif (type === 'b') return createBoolMatcher<CellModel>(term as boolean, property);\n\telse if (type === 's' && Array.isArray(term)) return createMultiMatcher<CellModel>((term as KeyValue[]), 'value');\n\telse if (type === 's') return createTextMatcher<CellModel>((term?.toString()), 'formattedValue');\n\telse if (type === 'm' && Array.isArray(term)) return createMultiMultiMatcher<CellModel>((term as KeyValue[]), property);\n\telse if (type === 'd') return createTextMatcher<CellModel>((term?.toString()) as string, 'formattedValue');\n\treturn createTextMatcher<CellModel>((term?.toString()) as string, property);\n}\n\nexport class FilterEvent extends Event {\n\tconstructor() {\n\t\tsuper('filter', {bubbles: false, cancelable: true, composed: true});\n\t}\n}\n\nexport class FilterModel extends EventTarget {\n\t\n\tpublic custom = false;\n\n\tprivate colMap = new Map<number, number>();\n\tprivate _settings: FilterSettings[] = [];\n\tget settings() { return this._settings }\n\tset settings(v: FilterSettings[]|null) {\n\t\tthis._settings = v || [];\n\t\tthis.colMap.clear();\n\t\tif (this.settings.length > 0) {\n\t\t\tthis.settings.forEach((s, i) => this.colMap.set(s.c, i));\n\t\t\tthis.applyFilter();\n\t\t\tlog.getLogger().info(`filtering applied: ${JSON.stringify(this.settings)}`);\n\t\t}\n\t}\n\n\tconstructor(\n\t\tpublic readonly model: GridModel,\n\t\tsettings: FilterSettings[]|null = null\n\t) {\n\t\tsuper();\n\t\tthis.settings = settings;\n\t}\n\n\t/**\n\t * Get filtering settings for specified column\n\t * @param c column index\n\t */\n\tget(c: number) {\n\t\treturn this.colMap.has(c) ? this.settings[this.colMap.get(c)] : null;\n\t}\n\n\tfilter(filter: FilterSettings, dispatchEvent = true) {\n\t\tconst filterSetting = this.get(filter.c);\n\t\tconst empty = filter.term === null || filter.term === '';\n\n\t\tif (filterSetting && empty) {\n\t\t\t// remove\n\t\t\tthis.settings.splice(this.colMap.get(filter.c), 1);\n\t\t\tthis.colMap.delete(filter.c);\n\t\t} else if (filterSetting) {\n\t\t\t// update\n\t\t\tfilterSetting.term = filter.term;\n\t\t} else if (!empty) {\n\t\t\t// add\n\t\t\tthis.colMap.set(filter.c, this.settings.length);\n\t\t\tthis.settings.push(filter);\n\t\t}\n\n\t\tif (!this.custom) {\n\t\t\tif (this.settings.length > 0) {\n\t\t\t\tthis.applyFilter(false);\n\t\t\t} else {\n\t\t\t\tthis.resetFilter(false);\n\t\t\t}\n\t\t}\n\n\t\tif (dispatchEvent) this.dispatchEvent(new FilterEvent())\n\t}\n\n\tapplyFilter(dispatchEvent = true) {\n\t\tconst cellMatchers: {c: number, matcher: FilterMatcher}[] = [];\n\t\tthis.settings.forEach((s) => {\n\t\t\tconst column = this.model.columns[s.c];\n\t\t\tcellMatchers.push({c: s.c, matcher: createCellMatcher(column.type, s.term, column.filter?.property)});\n\t\t});\n\n\t\tconst count = cellMatchers.length;\n\t\tconst rowMatcher = (row: RowModel) => {\n\t\t\tif (!row.filterable) return true;\n\t\t\tfor (let i = 0; i < count; i++) {\n\t\t\t\tif (!cellMatchers[i].matcher(row.cell(cellMatchers[i].c))) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn true;\n\t\t};\n\n\t\tconst includeParents = (this.model.options.filters as FilterOptions)?.includeParents ?? true;\n\t\tconst includeChildren = (this.model.options.filters as FilterOptions)?.includeChildren ?? true;\n\n\t\tconst visitedRows = new Set<number>();\n\t\tthis.model.rows.forEach(row => {\n\t\t\tconst visited = visitedRows.has(row.index);\n\n\t\t\tif (rowMatcher(row)) {\n\t\t\t\trow.filterState = tree.FilterState.Matched;\n\t\t\t\tif (includeParents) {\n\t\t\t\t\trow.walkUp((parent: RowModel) => {\n\t\t\t\t\t\tif (visitedRows.has(parent.index) && parent.filterState > 0) return false;\n\t\t\t\t\t\tparent.filterState = tree.FilterState.ChildMatched;\n\t\t\t\t\t\tvisitedRows.add(parent.index);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tif (includeChildren) {\n\t\t\t\t\trow.walk((child: RowModel) => {\n\t\t\t\t\t\tif (visitedRows.has(child.index) && child.filterState > 0) return false;\n\t\t\t\t\t\tchild.filterState = tree.FilterState.ParentMatched;\n\t\t\t\t\t\tvisitedRows.add(child.index);\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t} else if (!visited) {\n\t\t\t\trow.filterState = tree.FilterState.Filtered;\n\t\t\t}\n\n\t\t\tvisitedRows.add(row.index);\n\t\t});\n\n\t\tthis.model.indexRows();\n\t\tif (dispatchEvent) this.dispatchEvent(new FilterEvent())\n\t}\n\n\tresetFilter(dispatchEvent = true) {\n\t\tthis.settings = [];\n\t\tthis.colMap.clear();\n\t\tthis.model.rows.forEach(row => row.filterState = tree.FilterState.Matched);\n\t\tthis.model.indexRows();\n\t\tif (dispatchEvent) this.dispatchEvent(new FilterEvent())\n\t}\n\n}"]}
|