@lowdefy/blocks-aggrid 5.0.0 → 5.2.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.
@@ -0,0 +1,68 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React from 'react';
16
+ import { type } from '@lowdefy/helpers';
17
+ import NullCell from './NullCell.js';
18
+ const DEFAULT_THRESHOLDS = [
19
+ 20,
20
+ 40,
21
+ 60,
22
+ 80
23
+ ];
24
+ const DEFAULT_COLORS = [
25
+ 'var(--ant-color-error)',
26
+ 'var(--ant-color-warning)',
27
+ 'var(--ant-color-gold, var(--ant-color-warning))',
28
+ 'var(--ant-color-info)',
29
+ 'var(--ant-color-success)'
30
+ ];
31
+ function pickColor(value, thresholds, colors) {
32
+ for(let i = 0; i < thresholds.length; i += 1){
33
+ if (value < thresholds[i]) return colors[i];
34
+ }
35
+ return colors[colors.length - 1];
36
+ }
37
+ function ProgressCell(params) {
38
+ const { value, cellConfig } = params;
39
+ if (type.isNone(value) || value === '') {
40
+ return /*#__PURE__*/ React.createElement(NullCell, {
41
+ placeholder: cellConfig?.nullLabel ?? 'None'
42
+ });
43
+ }
44
+ const num = Number(value);
45
+ if (Number.isNaN(num)) {
46
+ return /*#__PURE__*/ React.createElement(NullCell, null);
47
+ }
48
+ const thresholds = type.isArray(cellConfig?.thresholds) ? cellConfig.thresholds : DEFAULT_THRESHOLDS;
49
+ const colors = type.isArray(cellConfig?.colors) ? cellConfig.colors : DEFAULT_COLORS;
50
+ const color = pickColor(num, thresholds, colors);
51
+ const suffix = cellConfig?.suffix ?? '%';
52
+ const style = {
53
+ display: 'inline-flex',
54
+ alignItems: 'center',
55
+ padding: 'var(--ant-padding-xxs, 4px) var(--ant-padding-xs, 8px)',
56
+ borderRadius: 'var(--ant-border-radius-sm, 4px)',
57
+ fontSize: 'var(--ant-font-size-sm, 12px)',
58
+ fontWeight: 600,
59
+ lineHeight: 1,
60
+ color,
61
+ background: `color-mix(in srgb, ${color} 12%, transparent)`,
62
+ border: `1px solid color-mix(in srgb, ${color} 30%, transparent)`
63
+ };
64
+ return /*#__PURE__*/ React.createElement("span", {
65
+ style: style
66
+ }, num, suffix);
67
+ }
68
+ export default ProgressCell;
@@ -0,0 +1,67 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import React from 'react';
16
+ import { type } from '@lowdefy/helpers';
17
+ import NullCell from './NullCell.js';
18
+ import { resolvePath } from './resolveFieldRefs.js';
19
+ const ANTD_TAG_COLOR_TOKENS = {
20
+ red: 'var(--ant-color-error)',
21
+ volcano: 'var(--ant-color-volcano, var(--ant-color-error))',
22
+ orange: 'var(--ant-color-warning)',
23
+ gold: 'var(--ant-color-gold, var(--ant-color-warning))',
24
+ yellow: 'var(--ant-color-warning)',
25
+ lime: 'var(--ant-color-lime, var(--ant-color-success))',
26
+ green: 'var(--ant-color-success)',
27
+ cyan: 'var(--ant-color-cyan, var(--ant-color-info))',
28
+ blue: 'var(--ant-color-info)',
29
+ geekblue: 'var(--ant-color-geekblue, var(--ant-color-info))',
30
+ purple: 'var(--ant-color-purple, var(--ant-color-info))',
31
+ magenta: 'var(--ant-color-magenta, var(--ant-color-error))',
32
+ default: 'var(--ant-color-text-secondary)'
33
+ };
34
+ function resolveColor(value) {
35
+ if (type.isNone(value)) return ANTD_TAG_COLOR_TOKENS.default;
36
+ return ANTD_TAG_COLOR_TOKENS[value] ?? value;
37
+ }
38
+ function TagCell(params) {
39
+ const { value, data, cellConfig } = params;
40
+ if (type.isNone(value) || value === '') {
41
+ return /*#__PURE__*/ React.createElement(NullCell, null);
42
+ }
43
+ const { colorMap, colorFrom, default: defaultColor } = cellConfig ?? {};
44
+ let color;
45
+ if (type.isString(colorFrom)) {
46
+ color = resolvePath(colorFrom, data);
47
+ } else if (type.isObject(colorMap)) {
48
+ color = colorMap[value];
49
+ }
50
+ const resolved = resolveColor(color ?? defaultColor);
51
+ const style = {
52
+ display: 'inline-flex',
53
+ alignItems: 'center',
54
+ padding: 'var(--ant-padding-xxs, 4px) var(--ant-padding-xs, 8px)',
55
+ borderRadius: 'var(--ant-border-radius-sm, 4px)',
56
+ fontSize: 'var(--ant-font-size-sm, 12px)',
57
+ fontWeight: 600,
58
+ lineHeight: 1,
59
+ color: resolved,
60
+ background: `color-mix(in srgb, ${resolved} 12%, transparent)`,
61
+ border: `1px solid color-mix(in srgb, ${resolved} 30%, transparent)`
62
+ };
63
+ return /*#__PURE__*/ React.createElement("span", {
64
+ style: style
65
+ }, String(value));
66
+ }
67
+ export default TagCell;
@@ -0,0 +1,34 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import TagCell from './TagCell.js';
16
+ import AvatarCell from './AvatarCell.js';
17
+ import LinkCell from './LinkCell.js';
18
+ import DateCell from './DateCell.js';
19
+ import BooleanCell from './BooleanCell.js';
20
+ import ProgressCell from './ProgressCell.js';
21
+ import NumberCell from './NumberCell.js';
22
+ const CELL_RENDERERS = {
23
+ tag: TagCell,
24
+ avatar: AvatarCell,
25
+ link: LinkCell,
26
+ date: DateCell,
27
+ boolean: BooleanCell,
28
+ progress: ProgressCell,
29
+ number: NumberCell
30
+ };
31
+ function getCellRenderer(type) {
32
+ return CELL_RENDERERS[type];
33
+ }
34
+ export { CELL_RENDERERS, getCellRenderer };
@@ -0,0 +1,40 @@
1
+ /*
2
+ Copyright 2020-2026 Lowdefy, Inc
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+ */ import { get, type } from '@lowdefy/helpers';
16
+ function resolvePath(path, data) {
17
+ if (type.isNone(path)) return undefined;
18
+ if (!type.isString(path)) return path;
19
+ return get(data, path);
20
+ }
21
+ function resolveUrlQuery(urlQuery, data) {
22
+ if (!type.isObject(urlQuery)) return undefined;
23
+ const resolved = {};
24
+ Object.keys(urlQuery).forEach((key)=>{
25
+ resolved[key] = resolvePath(urlQuery[key], data);
26
+ });
27
+ return resolved;
28
+ }
29
+ function resolveLink(link, data) {
30
+ if (!type.isObject(link)) return undefined;
31
+ return {
32
+ pageId: link.pageId,
33
+ href: link.href,
34
+ back: link.back,
35
+ home: link.home,
36
+ newTab: link.newTab,
37
+ urlQuery: resolveUrlQuery(link.urlQuery, data)
38
+ };
39
+ }
40
+ export { resolvePath, resolveUrlQuery, resolveLink };
@@ -1,5 +1,5 @@
1
1
  /*
2
- Copyright 2021 Lowdefy, Inc
2
+ Copyright 2020-2026 Lowdefy, Inc
3
3
 
4
4
  Licensed under the Apache License, Version 2.0 (the "License");
5
5
  you may not use this file except in compliance with the License.
@@ -14,13 +14,85 @@
14
14
  limitations under the License.
15
15
  */ import { renderHtml } from '@lowdefy/block-utils';
16
16
  import { type } from '@lowdefy/helpers';
17
+ import { getCellRenderer } from './cellRenderers/index.js';
18
+ import createEllipsisCell from './cellRenderers/EllipsisCell.js';
19
+ function applyEllipsis(colDef, ellipsis) {
20
+ if (!type.isInt(ellipsis) || ellipsis < 1) return colDef;
21
+ const clampClass = `lf-ellipsis-${Math.min(ellipsis, 6)}`;
22
+ const existingClass = colDef.cellClass;
23
+ const nextClass = type.isString(existingClass) ? `${existingClass} ${clampClass}` : type.isArray(existingClass) ? [
24
+ ...existingClass,
25
+ clampClass
26
+ ] : clampClass;
27
+ const next = {
28
+ ...colDef,
29
+ wrapText: colDef.wrapText ?? true,
30
+ autoHeight: colDef.autoHeight ?? true,
31
+ cellClass: nextClass
32
+ };
33
+ // Install a wrapping renderer that owns the clamp DOM — reliable against
34
+ // ag-grid's internal cell wrappers. Skip if a cellRenderer is already set
35
+ // (user or built-in cell.type takes precedence and can opt in via CSS).
36
+ if (!colDef.cellRenderer) {
37
+ next.cellRenderer = createEllipsisCell(ellipsis);
38
+ }
39
+ return next;
40
+ }
41
+ const JUSTIFY_MAP = {
42
+ left: 'flex-start',
43
+ center: 'center',
44
+ right: 'flex-end'
45
+ };
46
+ const HEADER_ALIGN_CLASS = {
47
+ left: 'ag-left-aligned-header',
48
+ center: 'ag-center-aligned-header',
49
+ right: 'ag-right-aligned-header'
50
+ };
51
+ function applyAlignment(colDef, cell) {
52
+ if (!type.isObject(cell)) return colDef;
53
+ const align = cell.align ?? (cell.type === 'number' ? 'right' : undefined);
54
+ if (!align || !JUSTIFY_MAP[align]) return colDef;
55
+ const cellStyle = {
56
+ ...type.isObject(colDef.cellStyle) ? colDef.cellStyle : {}
57
+ };
58
+ if (type.isNone(cellStyle.justifyContent)) cellStyle.justifyContent = JUSTIFY_MAP[align];
59
+ const headerClass = type.isString(colDef.headerClass) ? `${colDef.headerClass} ${HEADER_ALIGN_CLASS[align]}` : type.isArray(colDef.headerClass) ? [
60
+ ...colDef.headerClass,
61
+ HEADER_ALIGN_CLASS[align]
62
+ ] : HEADER_ALIGN_CLASS[align];
63
+ return {
64
+ ...colDef,
65
+ cellStyle,
66
+ headerClass
67
+ };
68
+ }
69
+ function buildCellRenderer({ cell, methods }) {
70
+ const Renderer = getCellRenderer(cell?.type);
71
+ if (!Renderer) return undefined;
72
+ // ag-grid calls the renderer as a React function component when returned directly.
73
+ return function CellRendererAdapter(params) {
74
+ return Renderer({
75
+ ...params,
76
+ cellConfig: cell,
77
+ methods
78
+ });
79
+ };
80
+ }
17
81
  function recProcessColDefs(columnDefs, methods) {
18
82
  return columnDefs.map((col)=>{
19
83
  const newColDef = {};
20
84
  if (type.isArray(col.children)) {
21
85
  newColDef.children = recProcessColDefs(col.children, methods);
22
86
  }
23
- if (type.isFunction(col.cellRenderer)) {
87
+ if (type.isObject(col.cell) && type.isString(col.cell.type)) {
88
+ const renderer = buildCellRenderer({
89
+ cell: col.cell,
90
+ methods
91
+ });
92
+ if (renderer) {
93
+ newColDef.cellRenderer = renderer;
94
+ }
95
+ } else if (type.isFunction(col.cellRenderer)) {
24
96
  newColDef.cellRenderer = (params)=>{
25
97
  return renderHtml({
26
98
  html: col.cellRenderer(params),
@@ -28,10 +100,15 @@ function recProcessColDefs(columnDefs, methods) {
28
100
  });
29
101
  };
30
102
  }
31
- return {
103
+ const merged = {
32
104
  ...col,
33
105
  ...newColDef
34
106
  };
107
+ // `cell` is our config object — ag-grid would ignore it, but strip to keep colDef clean.
108
+ delete merged.cell;
109
+ delete merged.ellipsis;
110
+ const aligned = applyAlignment(merged, col.cell);
111
+ return applyEllipsis(aligned, col.ellipsis);
35
112
  });
36
113
  }
37
114
  function processColDefs(columnDefs = [], methods) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lowdefy/blocks-aggrid",
3
- "version": "5.0.0",
3
+ "version": "5.2.0",
4
4
  "license": "Apache-2.0",
5
5
  "description": "AgGrid Blocks for Lowdefy.",
6
6
  "homepage": "https://lowdefy.com",
@@ -49,16 +49,19 @@
49
49
  "@ag-grid-community/csv-export": "30.2.0",
50
50
  "@ag-grid-community/react": "30.2.0",
51
51
  "@ag-grid-community/styles": "30.2.0",
52
- "@lowdefy/block-utils": "5.0.0",
53
- "@lowdefy/helpers": "5.0.0"
52
+ "@lowdefy/block-utils": "5.2.0",
53
+ "@lowdefy/helpers": "5.2.0"
54
54
  },
55
55
  "peerDependencies": {
56
+ "@ant-design/icons": ">=6",
57
+ "antd": ">=6",
58
+ "dayjs": ">=1.11",
56
59
  "react": ">=18",
57
60
  "react-dom": ">=18"
58
61
  },
59
62
  "devDependencies": {
60
- "@lowdefy/block-dev-e2e": "5.0.0",
61
- "@lowdefy/e2e-utils": "5.0.0",
63
+ "@lowdefy/block-dev-e2e": "5.2.0",
64
+ "@lowdefy/e2e-utils": "5.2.0",
62
65
  "@playwright/test": "1.50.1",
63
66
  "@swc/cli": "0.8.0",
64
67
  "@swc/core": "1.15.18",