@omegagrid/grid-core 0.10.91 → 0.10.93

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.
@@ -4,19 +4,37 @@ import { ColumnModel } from "./columnModel";
4
4
  import { ConditionalFormatItemSource } from "./conditionalFormats";
5
5
  import { CellModel } from "./cellModel";
6
6
  import { CellRange } from "../common";
7
+ /** @deprecated use MatchItem */
7
8
  export type ThemeItemCondtion = {
8
9
  property?: keyof CellModel;
9
10
  value?: unknown;
10
11
  };
12
+ export type MatchValue = string | number | boolean | RegExp;
13
+ export type MatchItem = {
14
+ /** matched model property (rows/columns: e.g. 'name', 'level', 'index'; cells: any CellModel property) */
15
+ property: string;
16
+ /**
17
+ * Expected value(s); an array matches when ANY of the values matches (OR).
18
+ * String/RegExp values of the 'name' property use the nameToRegExp conventions.
19
+ */
20
+ value: MatchValue | MatchValue[];
21
+ };
11
22
  export type ThemeItem = Omit<ConditionalFormatItemSource, 'ranges'> & {
23
+ /** @deprecated use matches */
12
24
  conditions?: ThemeItemCondtion[];
25
+ /**
26
+ * Model matchers (rows/columns match node properties, cells match cell
27
+ * properties): all items of an array must match (AND); the OR lives in
28
+ * each item's value array.
29
+ */
30
+ matches?: MatchItem | MatchItem[];
13
31
  };
14
32
  export type ThemeAxisItem = ThemeItem & {
15
- /** style will apply on cells with specific row/column index */
33
+ /** @deprecated use matches - style will apply on cells with specific row/column index */
16
34
  index?: number;
17
- /** style will apply on cells with specific row/column level */
35
+ /** @deprecated use matches - style will apply on cells with specific row/column level */
18
36
  level?: number;
19
- /** style will apply on cells their names are matching regular expression */
37
+ /** @deprecated use matches - style will apply on cells their names are matching regular expression */
20
38
  name?: string | RegExp;
21
39
  /** axis property priority */
22
40
  priority?: number;
@@ -39,6 +57,12 @@ export type TableTheme = {
39
57
  /** styles for rows */
40
58
  rows?: ThemeRowItem[];
41
59
  };
60
+ /**
61
+ * Name matcher: a RegExp is used as is, a '/'-delimited string is a regular
62
+ * expression as written, any other string matches the whole node name with
63
+ * '*' as a wildcard (the rest escaped).
64
+ */
65
+ export declare function nameToRegExp(name: string | RegExp): RegExp;
42
66
  export declare function applyCellTheme(theme: TableTheme, model: GridModel, range?: CellRange): void;
43
67
  export declare function applyColumnTheme(theme: TableTheme, model: GridModel, columns?: ColumnModel[]): void;
44
68
  export declare function applyRowTheme(theme: TableTheme, model: GridModel, rows?: RowModel[]): void;
@@ -1 +1 @@
1
- {"version":3,"file":"tableTheme.d.ts","sourceRoot":"","sources":["../../src/model/tableTheme.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AACtC,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EAAE,2BAA2B,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,MAAM,MAAM,iBAAiB,GAAG;IAC/B,QAAQ,CAAC,EAAE,MAAM,SAAS,CAAC;IAC3B,KAAK,CAAC,EAAE,OAAO,CAAC;CAChB,CAAA;AAED,MAAM,MAAM,SAAS,GAAG,IAAI,CAAC,2BAA2B,EAAE,QAAQ,CAAC,GAAG;IACrE,UAAU,CAAC,EAAE,iBAAiB,EAAE,CAAA;CAChC,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACvC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,4EAA4E;IAC5E,IAAI,CAAC,EAAE,MAAM,GAAC,MAAM,CAAC;IACrB,6BAA6B;IAC7B,QAAQ,CAAC,EAAE,MAAM,CAAC;CAClB,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,aAAa,GAAG;IAC1C,iBAA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,IAAI,CAAC,EAAE,YAAY,EAAE,CAAC;CACtB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAC,MAAM,GAAG,MAAM,CAWxD;AA4ED,wBAAgB,cAAc,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,KAAK,CAAC,EAAE,SAAS,QAuBpF;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,EAAE,WAAW,EAAE,QAE5F;AAED,wBAAgB,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,EAAE,QAAQ,EAAE,QAEnF;AAED,wBAAgB,UAAU,CAAC,KAAK,EAAE,UAAU,EAAE,KAAK,EAAE,SAAS,QAI7D"}
@@ -1,4 +1,38 @@
1
+ /* eslint-disable @typescript-eslint/no-explicit-any */
1
2
  import { utils } from "@omegagrid/core";
3
+ /**
4
+ * Name matcher: a RegExp is used as is, a '/'-delimited string is a regular
5
+ * expression as written, any other string matches the whole node name with
6
+ * '*' as a wildcard (the rest escaped).
7
+ */
8
+ export function nameToRegExp(name) {
9
+ if (name instanceof RegExp)
10
+ return name;
11
+ const value = String(name);
12
+ if (value.length > 2 && value.startsWith('/') && value.endsWith('/')) {
13
+ try {
14
+ return new RegExp(value.slice(1, -1));
15
+ }
16
+ catch {
17
+ // fall through to the wildcard form
18
+ }
19
+ }
20
+ return new RegExp(`^${value.split('*').map(part => utils.escapeRegExp(part)).join('.*')}$`);
21
+ }
22
+ /**
23
+ * Shared evaluator of the theme matchers (axis item matches and cell conditions):
24
+ * the target's property must equal one of the expected values; string/RegExp values
25
+ * of the 'name' property are matched through the nameToRegExp conventions.
26
+ */
27
+ function matchProperty(target, match) {
28
+ if (!match.property)
29
+ return match.value == null;
30
+ const actual = target[match.property];
31
+ const values = Array.isArray(match.value) ? match.value : [match.value];
32
+ return values.some(value => match.property == 'name' && (typeof value === 'string' || value instanceof RegExp)
33
+ ? nameToRegExp(value).test(String(actual ?? ''))
34
+ : actual == value);
35
+ }
2
36
  function getLevelMap(nodes) {
3
37
  const map = new Map();
4
38
  for (const node of nodes) {
@@ -14,18 +48,24 @@ function applyAxisTheme(theme, model, type, tableElements) {
14
48
  const themeItems = theme[type] ?? [];
15
49
  for (const item of themeItems) {
16
50
  let effectiveNodes;
17
- if (item.index > -1) {
18
- effectiveNodes = [nodes[item.index]];
19
- }
20
- else if (item.level > -1) {
21
- effectiveNodes = levelMap.get(item.level);
51
+ if (item.matches) {
52
+ const matchItems = Array.isArray(item.matches) ? item.matches : [item.matches];
53
+ effectiveNodes = nodes.filter(node => matchItems.every(match => matchProperty(node, match)));
22
54
  }
23
55
  else {
24
- effectiveNodes = nodes;
25
- }
26
- if (item.name) {
27
- const nameRegExp = item.name instanceof RegExp ? item.name : new RegExp(utils.escapeRegExp(item.name));
28
- effectiveNodes = effectiveNodes.filter(node => nameRegExp.test(node.name));
56
+ if (item.index > -1) {
57
+ effectiveNodes = [nodes[item.index]];
58
+ }
59
+ else if (item.level > -1) {
60
+ effectiveNodes = levelMap.get(item.level);
61
+ }
62
+ else {
63
+ effectiveNodes = nodes;
64
+ }
65
+ if (item.name) {
66
+ const nameRegExp = nameToRegExp(item.name);
67
+ effectiveNodes = effectiveNodes.filter(node => nameRegExp.test(node.name));
68
+ }
29
69
  }
30
70
  effectiveNodes?.forEach(node => {
31
71
  if (item.priority != null)
@@ -47,20 +87,20 @@ function applyAxisTheme(theme, model, type, tableElements) {
47
87
  });
48
88
  }
49
89
  }
50
- function matchConditions(conditions, cell) {
51
- for (const condition of conditions) {
52
- if (cell[condition.property] != condition.value)
53
- return false;
54
- }
55
- return true;
90
+ /** matchers of a theme item - matches takes precedence over the deprecated conditions */
91
+ function getMatchItems(item) {
92
+ if (item.matches)
93
+ return Array.isArray(item.matches) ? item.matches : [item.matches];
94
+ return item.conditions;
56
95
  }
57
96
  export function applyCellTheme(theme, model, range) {
58
97
  const themeItems = theme.cells ?? [];
59
98
  for (const item of themeItems) {
60
- if (item.conditions?.length) {
99
+ const matchItems = getMatchItems(item);
100
+ if (matchItems?.length) {
61
101
  const iterator = model.getRangeIterator(range ?? model.gridRange);
62
102
  for (const cell of iterator) {
63
- if (matchConditions(item.conditions, cell)) {
103
+ if (matchItems.every(match => matchProperty(cell, match))) {
64
104
  cell.style = model.styles.add(item.style).id;
65
105
  }
66
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"tableTheme.js","sourceRoot":"","sources":["../../src/model/tableTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAQ,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAiD9C,SAAS,WAAW,CAA8B,KAAU;IAC3D,MAAM,GAAG,GAAG,IAAI,GAAG,EAAe,CAAC;IACnC,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC1B,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC;YAAE,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;QAClD,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChC,CAAC;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED,SAAS,cAAc,CAAC,KAAiB,EAAE,KAAgB,EAAE,IAAsB,EAAE,aAAwC;IAC5H,MAAM,KAAK,GAAG,aAAa,IAAI,CAAC,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC7E,MAAM,QAAQ,GAAG,WAAW,CAAuB,KAAK,CAAC,CAAC;IAC1D,MAAM,UAAU,GAAG,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;IAErC,KAAK,MAAM,IAAI,IAAI,UAAU,EAA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QACF,CAAC;aAAM,IAAI,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,qBAAqB;YAC5C,KAAK,CAAC,kBAAkB,CAAC,GAAG,CAAC,MAAM,CAAC,MAAM,CAAC;gBAC1C,MAAM,EAAE,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO;aAC9D,EAAE,IAAI,CAAC,CAAC,CAAC;QACX,CAAC;aAAM,CAAC,CAAC,gBAAgB;YACxB,KAAK,MAAM,MAAM,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;gBACpC,IAAI,MAAM,CAAC,KAAK,IAAI,IAAI;oBAAE,SAAS;gBACnC,MAAM,CAAC,KAAK,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC;YAChD,CAAC;QACF,CAAC;IACF,CAAC;AACF,CAAC;AAED,MAAM,UAAU,gBAAgB,CAAC,KAAiB,EAAE,KAAgB,EAAE,OAAuB;IAC5F,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,KAAgB,EAAE,IAAiB;IACnF,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,KAAgB;IAC7D,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7B,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC/B,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["import { tree, utils } from \"@omegagrid/core\";\nimport { GridModel } from \"./gridModel\";\nimport { RowModel } from \"./rowModel\";\nimport { ColumnModel } from \"./columnModel\";\nimport { ConditionalFormatItemSource } from \"./conditionalFormats\";\nimport { CellModel } from \"./cellModel\";\nimport { CellRange } from \"../common\";\n\nexport type ThemeItemCondtion = {\n\tproperty?: keyof CellModel;\n\tvalue?: unknown;\n}\n\nexport type ThemeItem = Omit<ConditionalFormatItemSource, 'ranges'> & {\n\tconditions?: ThemeItemCondtion[]\n};\n\nexport type ThemeAxisItem = ThemeItem & {\n\t/** style will apply on cells with specific row/column index */\n\tindex?: number;\n\t/** style will apply on cells with specific row/column level */\n\tlevel?: number;\n\t/** style will apply on cells their names are matching regular expression */\n\tname?: string|RegExp;\n\t/** axis property priority */\n\tpriority?: number;\n}\n\nexport type ThemeRowItem = ThemeAxisItem & {\n\t/** row height */\n\theight?: number;\n}\n\nexport type ThemeColumnItem = ThemeAxisItem & {\n\t/** column width */\n\twidth?: number;\n}\n\nexport type TableTheme = {\n\t/** theme name */\n\tname: string;\n\t/** styles for cells */\n\tcells?: ThemeItem[],\n\t/** styles for columns */\n\tcolumns?: ThemeColumnItem[],\n\t/** styles for rows */\n\trows?: ThemeRowItem[],\n}\n\nfunction getLevelMap<T extends tree.TreeNodeType>(nodes: T[]) {\n\tconst map = new Map<number, T[]>();\n\tfor (const node of nodes) {\n\t\tif (!map.has(node.level)) map.set(node.level, []);\n\t\tmap.get(node.level).push(node);\n\t}\n\treturn map;\n}\n\nfunction applyAxisTheme(theme: TableTheme, model: GridModel, type: 'rows'|'columns', tableElements?: (RowModel|ColumnModel)[]) {\n\tconst nodes = tableElements ?? (type == 'rows' ? model.rows : model.columns);\n\tconst levelMap = getLevelMap<RowModel|ColumnModel>(nodes);\n\tconst themeItems = theme[type] ?? [];\n\n\tfor (const item of themeItems) {\n\t\tlet effectiveNodes: (RowModel|ColumnModel)[];\n\t\tif (item.index > -1) {\n\t\t\teffectiveNodes = [nodes[item.index]];\n\t\t} else if (item.level > -1) {\n\t\t\teffectiveNodes = levelMap.get(item.level);\n\t\t} else {\n\t\t\teffectiveNodes = nodes;\n\t\t}\n\n\t\tif (item.name) {\n\t\t\tconst nameRegExp = item.name instanceof RegExp ? item.name : new RegExp(utils.escapeRegExp(item.name));\n\t\t\teffectiveNodes = effectiveNodes.filter(node => nameRegExp.test(node.name));\n\t\t}\n\n\t\teffectiveNodes?.forEach(node => {\n\t\t\tif (item.priority != null) node.priority = item.priority;\n\n\t\t\tif (item.type) { // conditional format\n\t\t\t\tmodel.conditionalFormats.add(Object.assign({\n\t\t\t\t\tranges: `${node.address}:${node.address}`\n\t\t\t\t}, item));\n\t\t\t} else { // static format\n\t\t\t\tnode.style = model.styles.add(item.style).id;\n\n\t\t\t\tif (type == 'rows' && (item as ThemeRowItem).height != null) {\n\t\t\t\t\t(node as RowModel).height = (item as ThemeRowItem).height;\n\t\t\t\t} else if (type == 'columns' && (item as ThemeColumnItem).width != null) {\n\t\t\t\t\t(node as ColumnModel).width = (item as ThemeColumnItem).width;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n}\n\nfunction matchConditions(conditions: ThemeItemCondtion[], cell: CellModel) {\n\tfor (const condition of conditions) {\n\t\tif (cell[condition.property] != condition.value) return false;\n\t}\n\treturn true;\n}\n\nexport function applyCellTheme(theme: TableTheme, model: GridModel, range?: CellRange) {\n\tconst themeItems = theme.cells ?? [];\n\n\tfor (const item of themeItems) {\n\t\tif (item.conditions?.length) {\n\t\t\tconst iterator = model.getRangeIterator(range ?? model.gridRange);\n\t\t\tfor (const cell of iterator) {\n\t\t\t\tif (matchConditions(item.conditions, cell)) {\n\t\t\t\t\tcell.style = model.styles.add(item.style).id;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (item.type) { // conditional format\n\t\t\tmodel.conditionalFormats.add(Object.assign({\n\t\t\t\tranges: 'A:' + model.columns[model.columns.length - 1].address\n\t\t\t}, item));\n\t\t} else { // static format\n\t\t\tfor (const column of model.columns) {\n\t\t\t\tif (column.style != null) continue;\n\t\t\t\tcolumn.style = model.styles.add(item.style).id;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function applyColumnTheme(theme: TableTheme, model: GridModel, columns?: ColumnModel[]) {\n\tapplyAxisTheme(theme, model, 'columns', columns);\n}\n\nexport function applyRowTheme(theme: TableTheme, model: GridModel, rows?: RowModel[]) {\n\tapplyAxisTheme(theme, model, 'rows', rows);\n}\n\nexport function applyTheme(theme: TableTheme, model: GridModel) {\n\tapplyCellTheme(theme, model);\n\tapplyColumnTheme(theme, model);\n\tapplyRowTheme(theme, model);\n}"]}
1
+ {"version":3,"file":"tableTheme.js","sourceRoot":"","sources":["../../src/model/tableTheme.ts"],"names":[],"mappings":"AAAA,uDAAuD;AAEvD,OAAO,EAAQ,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAqE9C;;;;GAIG;AACH,MAAM,UAAU,YAAY,CAAC,IAAmB;IAC/C,IAAI,IAAI,YAAY,MAAM;QAAE,OAAO,IAAI,CAAC;IACxC,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;QACtE,IAAI,CAAC;YACJ,OAAO,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACvC,CAAC;QAAC,MAAM,CAAC;YACR,oCAAoC;QACrC,CAAC;IACF,CAAC;IACD,OAAO,IAAI,MAAM,CAAC,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC7F,CAAC;AAED;;;;GAIG;AACH,SAAS,aAAa,CAAC,MAAW,EAAE,KAA2C;IAC9E,IAAI,CAAC,KAAK,CAAC,QAAQ;QAAE,OAAO,KAA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,CAAC,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,CAAC,CAAC;AAClD,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,KAAiB,EAAE,KAAgB,EAAE,IAAiB;IACnF,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;AAC5C,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,KAAiB,EAAE,KAAgB;IAC7D,cAAc,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC7B,gBAAgB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAC/B,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AAC7B,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\n\nimport { tree, utils } from \"@omegagrid/core\";\nimport { GridModel } from \"./gridModel\";\nimport { RowModel } from \"./rowModel\";\nimport { ColumnModel } from \"./columnModel\";\nimport { ConditionalFormatItemSource } from \"./conditionalFormats\";\nimport { CellModel } from \"./cellModel\";\nimport { CellRange } from \"../common\";\n\n/** @deprecated use MatchItem */\nexport type ThemeItemCondtion = {\n\tproperty?: keyof CellModel;\n\tvalue?: unknown;\n}\n\nexport type MatchValue = string|number|boolean|RegExp;\n\nexport type MatchItem = {\n\t/** matched model property (rows/columns: e.g. 'name', 'level', 'index'; cells: any CellModel property) */\n\tproperty: string;\n\t/**\n\t * Expected value(s); an array matches when ANY of the values matches (OR).\n\t * String/RegExp values of the 'name' property use the nameToRegExp conventions.\n\t */\n\tvalue: MatchValue|MatchValue[];\n}\n\nexport type ThemeItem = Omit<ConditionalFormatItemSource, 'ranges'> & {\n\t/** @deprecated use matches */\n\tconditions?: ThemeItemCondtion[];\n\t/**\n\t * Model matchers (rows/columns match node properties, cells match cell\n\t * properties): all items of an array must match (AND); the OR lives in\n\t * each item's value array.\n\t */\n\tmatches?: MatchItem|MatchItem[];\n};\n\nexport type ThemeAxisItem = ThemeItem & {\n\t/** @deprecated use matches - style will apply on cells with specific row/column index */\n\tindex?: number;\n\t/** @deprecated use matches - style will apply on cells with specific row/column level */\n\tlevel?: number;\n\t/** @deprecated use matches - style will apply on cells their names are matching regular expression */\n\tname?: string|RegExp;\n\t/** axis property priority */\n\tpriority?: number;\n}\n\nexport type ThemeRowItem = ThemeAxisItem & {\n\t/** row height */\n\theight?: number;\n}\n\nexport type ThemeColumnItem = ThemeAxisItem & {\n\t/** column width */\n\twidth?: number;\n}\n\nexport type TableTheme = {\n\t/** theme name */\n\tname: string;\n\t/** styles for cells */\n\tcells?: ThemeItem[],\n\t/** styles for columns */\n\tcolumns?: ThemeColumnItem[],\n\t/** styles for rows */\n\trows?: ThemeRowItem[],\n}\n\n/**\n * Name matcher: a RegExp is used as is, a '/'-delimited string is a regular\n * expression as written, any other string matches the whole node name with\n * '*' as a wildcard (the rest escaped).\n */\nexport function nameToRegExp(name: string|RegExp): RegExp {\n\tif (name instanceof RegExp) return name;\n\tconst value = String(name);\n\tif (value.length > 2 && value.startsWith('/') && value.endsWith('/')) {\n\t\ttry {\n\t\t\treturn new RegExp(value.slice(1, -1));\n\t\t} catch {\n\t\t\t// fall through to the wildcard form\n\t\t}\n\t}\n\treturn new RegExp(`^${value.split('*').map(part => utils.escapeRegExp(part)).join('.*')}$`);\n}\n\n/**\n * Shared evaluator of the theme matchers (axis item matches and cell conditions):\n * the target's property must equal one of the expected values; string/RegExp values\n * of the 'name' property are matched through the nameToRegExp conventions.\n */\nfunction matchProperty(target: any, match: {property?: string, value?: unknown}): boolean {\n\tif (!match.property) return match.value == null;\n\tconst actual = target[match.property];\n\tconst values = Array.isArray(match.value) ? match.value : [match.value];\n\treturn values.some(value => match.property == 'name' && (typeof value === 'string' || value instanceof RegExp)\n\t\t? nameToRegExp(value).test(String(actual ?? ''))\n\t\t: actual == value);\n}\n\nfunction getLevelMap<T extends tree.TreeNodeType>(nodes: T[]) {\n\tconst map = new Map<number, T[]>();\n\tfor (const node of nodes) {\n\t\tif (!map.has(node.level)) map.set(node.level, []);\n\t\tmap.get(node.level).push(node);\n\t}\n\treturn map;\n}\n\nfunction applyAxisTheme(theme: TableTheme, model: GridModel, type: 'rows'|'columns', tableElements?: (RowModel|ColumnModel)[]) {\n\tconst nodes = tableElements ?? (type == 'rows' ? model.rows : model.columns);\n\tconst levelMap = getLevelMap<RowModel|ColumnModel>(nodes);\n\tconst themeItems = theme[type] ?? [];\n\n\tfor (const item of themeItems) {\n\t\tlet effectiveNodes: (RowModel|ColumnModel)[];\n\t\tif (item.matches) {\n\t\t\tconst matchItems = Array.isArray(item.matches) ? item.matches : [item.matches];\n\t\t\teffectiveNodes = nodes.filter(node => matchItems.every(match => matchProperty(node, match)));\n\t\t} else {\n\t\t\tif (item.index > -1) {\n\t\t\t\teffectiveNodes = [nodes[item.index]];\n\t\t\t} else if (item.level > -1) {\n\t\t\t\teffectiveNodes = levelMap.get(item.level);\n\t\t\t} else {\n\t\t\t\teffectiveNodes = nodes;\n\t\t\t}\n\n\t\t\tif (item.name) {\n\t\t\t\tconst nameRegExp = nameToRegExp(item.name);\n\t\t\t\teffectiveNodes = effectiveNodes.filter(node => nameRegExp.test(node.name));\n\t\t\t}\n\t\t}\n\n\t\teffectiveNodes?.forEach(node => {\n\t\t\tif (item.priority != null) node.priority = item.priority;\n\n\t\t\tif (item.type) { // conditional format\n\t\t\t\tmodel.conditionalFormats.add(Object.assign({\n\t\t\t\t\tranges: `${node.address}:${node.address}`\n\t\t\t\t}, item));\n\t\t\t} else { // static format\n\t\t\t\tnode.style = model.styles.add(item.style).id;\n\n\t\t\t\tif (type == 'rows' && (item as ThemeRowItem).height != null) {\n\t\t\t\t\t(node as RowModel).height = (item as ThemeRowItem).height;\n\t\t\t\t} else if (type == 'columns' && (item as ThemeColumnItem).width != null) {\n\t\t\t\t\t(node as ColumnModel).width = (item as ThemeColumnItem).width;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t}\n}\n\n/** matchers of a theme item - matches takes precedence over the deprecated conditions */\nfunction getMatchItems(item: ThemeItem): {property?: string, value?: unknown}[]|undefined {\n\tif (item.matches) return Array.isArray(item.matches) ? item.matches : [item.matches];\n\treturn item.conditions;\n}\n\nexport function applyCellTheme(theme: TableTheme, model: GridModel, range?: CellRange) {\n\tconst themeItems = theme.cells ?? [];\n\n\tfor (const item of themeItems) {\n\t\tconst matchItems = getMatchItems(item);\n\t\tif (matchItems?.length) {\n\t\t\tconst iterator = model.getRangeIterator(range ?? model.gridRange);\n\t\t\tfor (const cell of iterator) {\n\t\t\t\tif (matchItems.every(match => matchProperty(cell, match))) {\n\t\t\t\t\tcell.style = model.styles.add(item.style).id;\n\t\t\t\t}\n\t\t\t}\n\t\t} else if (item.type) { // conditional format\n\t\t\tmodel.conditionalFormats.add(Object.assign({\n\t\t\t\tranges: 'A:' + model.columns[model.columns.length - 1].address\n\t\t\t}, item));\n\t\t} else { // static format\n\t\t\tfor (const column of model.columns) {\n\t\t\t\tif (column.style != null) continue;\n\t\t\t\tcolumn.style = model.styles.add(item.style).id;\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport function applyColumnTheme(theme: TableTheme, model: GridModel, columns?: ColumnModel[]) {\n\tapplyAxisTheme(theme, model, 'columns', columns);\n}\n\nexport function applyRowTheme(theme: TableTheme, model: GridModel, rows?: RowModel[]) {\n\tapplyAxisTheme(theme, model, 'rows', rows);\n}\n\nexport function applyTheme(theme: TableTheme, model: GridModel) {\n\tapplyCellTheme(theme, model);\n\tapplyColumnTheme(theme, model);\n\tapplyRowTheme(theme, model);\n}"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omegagrid/grid-core",
3
- "version": "0.10.91",
3
+ "version": "0.10.93",
4
4
  "license": "UNLICENSED",
5
5
  "description": "Grid model, no ui components",
6
6
  "main": "./dist/index.js",
@@ -28,8 +28,8 @@
28
28
  "generate-functions-docs": "node ./scripts/generate-functions-docs.cjs"
29
29
  },
30
30
  "dependencies": {
31
- "@omegagrid/core": "^0.10.91",
32
- "@omegagrid/localize": "^0.10.91",
31
+ "@omegagrid/core": "^0.10.93",
32
+ "@omegagrid/localize": "^0.10.93",
33
33
  "@stdlib/stats": "^0.0.13",
34
34
  "color": "^4.2.3",
35
35
  "date-fns": "^3.2.0",