@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.
@@ -65,6 +65,14 @@
65
65
  rows: 'The displayed rows after sorting.',
66
66
  sort: 'The sort column state.'
67
67
  }
68
+ },
69
+ onCellLink: {
70
+ description: 'Triggered when a built-in `cell.type: link` (or avatar with `link`) cell is clicked. Wire to a `Link` action with `params: { _event: link }` to navigate.',
71
+ event: {
72
+ link: 'The resolved link config (pageId/href/urlQuery/back/home/newTab).',
73
+ row: 'The row data.',
74
+ value: 'The cell value.'
75
+ }
68
76
  }
69
77
  },
70
78
  properties: {
@@ -87,6 +95,21 @@
87
95
  type: 'string',
88
96
  description: 'The data field to use in `getRowId` which results in Row Selection being maintained across Row Data changes (assuming the Row exists in both sets). See Ag Grid docs for more details (https://www.ag-grid.com/react-data-grid/data-update-row-data/).'
89
97
  },
98
+ enableBrowserTooltips: {
99
+ type: 'boolean',
100
+ default: false,
101
+ description: "Set to `true` to use the browser native `title` attribute tooltips instead of AG Grid's styled tooltip component."
102
+ },
103
+ tooltipShowDelay: {
104
+ type: 'number',
105
+ default: 2000,
106
+ description: 'The delay in milliseconds before a tooltip is shown. Not applied when `enableBrowserTooltips` is `true`.'
107
+ },
108
+ tooltipHideDelay: {
109
+ type: 'number',
110
+ default: 10000,
111
+ description: 'The delay in milliseconds before a tooltip is hidden. Not applied when `enableBrowserTooltips` is `true`.'
112
+ },
90
113
  defaultColDef: {
91
114
  type: 'object',
92
115
  description: 'Column properties which get applied to all columns. See all (https://www.ag-grid.com/javascript-data-grid/column-properties/).'
@@ -138,6 +161,243 @@
138
161
  'string'
139
162
  ],
140
163
  description: 'A function (using the `_function` operator) or expression to format a value, should return a string. Not used for CSV export or copy to clipboard, only for UI cell rendering.'
164
+ },
165
+ tooltipField: {
166
+ type: 'string',
167
+ description: "The field of the row object to read the tooltip value from. When set, hovering a cell shows a tooltip with that value using the grid's default tooltip component."
168
+ },
169
+ tooltipValueGetter: {
170
+ type: 'object',
171
+ description: 'Provide a function (using the `_function` operator) that returns the tooltip value for a cell. Overrides `tooltipField`.'
172
+ },
173
+ tooltipComponent: {
174
+ type: 'object',
175
+ description: 'Provide a custom tooltip component. See AG Grid tooltip component docs (https://www.ag-grid.com/react-data-grid/component-tooltip/).'
176
+ },
177
+ ellipsis: {
178
+ type: 'number',
179
+ description: 'Line-clamp count for long text. Automatically enables `wrapText` and `autoHeight` and applies the `.lf-ellipsis-N` class (1–6).'
180
+ },
181
+ cell: {
182
+ type: 'object',
183
+ description: 'Built-in cell renderer. Takes precedence over `cellRenderer` when `type` is set. Field-valued keys (e.g. `nameField`, `srcField`, `urlQuery.*`) are row-data paths.',
184
+ properties: {
185
+ type: {
186
+ type: 'string',
187
+ enum: [
188
+ 'tag',
189
+ 'avatar',
190
+ 'link',
191
+ 'date',
192
+ 'boolean',
193
+ 'progress',
194
+ 'number'
195
+ ],
196
+ description: 'The built-in renderer to use.'
197
+ },
198
+ colorMap: {
199
+ type: 'object',
200
+ description: 'Tag: map of cell value → color (antd tag color name or hex). Used when `cell.type: tag`.'
201
+ },
202
+ colorFrom: {
203
+ type: 'string',
204
+ description: 'Tag: row-data path to a color value. Takes precedence over `colorMap`.'
205
+ },
206
+ default: {
207
+ type: 'string',
208
+ description: 'Tag: fallback color for values not in `colorMap`.'
209
+ },
210
+ nameField: {
211
+ type: 'string',
212
+ description: 'Avatar: row-data path for the name label.'
213
+ },
214
+ srcField: {
215
+ type: 'string',
216
+ description: 'Avatar: row-data path for the image src (optional).'
217
+ },
218
+ idField: {
219
+ type: 'string',
220
+ description: 'Avatar: row-data path for an id used to seed initials colour.'
221
+ },
222
+ shape: {
223
+ type: 'string',
224
+ enum: [
225
+ 'circle',
226
+ 'square'
227
+ ],
228
+ description: 'Avatar shape. Defaults to `circle`.'
229
+ },
230
+ link: {
231
+ type: 'object',
232
+ description: 'Avatar/Link: navigation config. Emits `onCellLink` on click. `pageId`/`href`/`back`/`home`/`newTab` are literal; `urlQuery` values are row-data paths.'
233
+ },
234
+ pageId: {
235
+ type: 'string',
236
+ description: 'Link: target page id (literal).'
237
+ },
238
+ href: {
239
+ type: 'string',
240
+ description: 'Link: literal href (overrides `pageId`).'
241
+ },
242
+ back: {
243
+ type: 'boolean',
244
+ description: 'Link: navigate back.'
245
+ },
246
+ home: {
247
+ type: 'boolean',
248
+ description: 'Link: navigate home.'
249
+ },
250
+ newTab: {
251
+ type: 'boolean',
252
+ description: 'Link: open in a new tab.'
253
+ },
254
+ urlQuery: {
255
+ type: 'object',
256
+ description: 'Link: query params. Each value is a row-data path.'
257
+ },
258
+ labelField: {
259
+ type: 'string',
260
+ description: 'Link: row-data path for the visible label (falls back to cell value).'
261
+ },
262
+ format: {
263
+ type: 'string',
264
+ description: 'Date: dayjs format string. Default `YYYY-MM-DD HH:mm`.'
265
+ },
266
+ relative: {
267
+ type: 'boolean',
268
+ description: 'Date: render as relative time (e.g. "3 hours ago").'
269
+ },
270
+ trueLabel: {
271
+ type: 'string',
272
+ description: 'Boolean: label when truthy.'
273
+ },
274
+ falseLabel: {
275
+ type: 'string',
276
+ description: 'Boolean: label when falsy.'
277
+ },
278
+ trueColor: {
279
+ type: 'string',
280
+ description: 'Boolean: CSS colour when truthy.'
281
+ },
282
+ falseColor: {
283
+ type: 'string',
284
+ description: 'Boolean: CSS colour when falsy.'
285
+ },
286
+ thresholds: {
287
+ type: 'array',
288
+ description: 'Progress: threshold values (ascending). Each threshold defines where the next colour starts.',
289
+ items: {
290
+ type: 'number'
291
+ }
292
+ },
293
+ colors: {
294
+ type: 'array',
295
+ description: 'Progress: colour per bucket (length = thresholds.length + 1).',
296
+ items: {
297
+ type: 'string'
298
+ }
299
+ },
300
+ suffix: {
301
+ type: 'string',
302
+ description: 'Number/Progress: literal suffix appended after the formatted value. Default `%` for progress.'
303
+ },
304
+ nullLabel: {
305
+ type: 'string',
306
+ description: 'Progress: label when value is null. Default `None`.'
307
+ },
308
+ format: {
309
+ type: 'string',
310
+ description: 'Number: `number` (default), `currency`, `percent`, or `compact` (K/M/B). Date: dayjs format string (default `YYYY-MM-DD HH:mm`).'
311
+ },
312
+ locale: {
313
+ type: 'string',
314
+ description: 'Number: BCP 47 locale for `Intl.NumberFormat` (e.g. `en-US`, `de-DE`). Defaults to browser.'
315
+ },
316
+ currency: {
317
+ type: 'string',
318
+ description: 'Number: ISO 4217 currency code when `format: currency`. Default `USD`.'
319
+ },
320
+ currencyDisplay: {
321
+ type: 'string',
322
+ enum: [
323
+ 'symbol',
324
+ 'narrowSymbol',
325
+ 'code',
326
+ 'name'
327
+ ],
328
+ description: 'Number: currency display style when `format: currency`.'
329
+ },
330
+ decimals: {
331
+ type: 'number',
332
+ description: 'Number: fixed number of fraction digits (sets both `minimumFractionDigits` and `maximumFractionDigits`).'
333
+ },
334
+ minDecimals: {
335
+ type: 'number',
336
+ description: 'Number: `Intl.NumberFormat` `minimumFractionDigits`.'
337
+ },
338
+ maxDecimals: {
339
+ type: 'number',
340
+ description: 'Number: `Intl.NumberFormat` `maximumFractionDigits`.'
341
+ },
342
+ notation: {
343
+ type: 'string',
344
+ enum: [
345
+ 'standard',
346
+ 'scientific',
347
+ 'engineering',
348
+ 'compact'
349
+ ],
350
+ description: 'Number: `Intl.NumberFormat` notation. `compact` format sets this automatically.'
351
+ },
352
+ useGrouping: {
353
+ type: 'boolean',
354
+ default: true,
355
+ description: 'Number: include thousands separators.'
356
+ },
357
+ negative: {
358
+ type: 'string',
359
+ enum: [
360
+ 'minus',
361
+ 'parentheses'
362
+ ],
363
+ default: 'minus',
364
+ description: 'Number: how to render negative numbers — `minus` (default) or `parentheses` for accounting.'
365
+ },
366
+ signColor: {
367
+ type: 'boolean',
368
+ default: false,
369
+ description: 'Number: when true, positives use `positiveColor` (default success token), negatives use `negativeColor` (default error token).'
370
+ },
371
+ positiveColor: {
372
+ type: 'string',
373
+ description: 'Number: CSS colour when value > 0 (requires `signColor: true`).'
374
+ },
375
+ negativeColor: {
376
+ type: 'string',
377
+ description: 'Number: CSS colour when value < 0 (requires `signColor: true`).'
378
+ },
379
+ zeroColor: {
380
+ type: 'string',
381
+ description: 'Number: CSS colour when value === 0 (requires `signColor: true`).'
382
+ },
383
+ color: {
384
+ type: 'string',
385
+ description: 'Number: CSS colour applied to all values (overridden by `signColor`).'
386
+ },
387
+ prefix: {
388
+ type: 'string',
389
+ description: 'Number: literal prefix (e.g. `Δ `, `~`).'
390
+ },
391
+ align: {
392
+ type: 'string',
393
+ enum: [
394
+ 'left',
395
+ 'center',
396
+ 'right'
397
+ ],
398
+ description: 'Cell horizontal alignment. Defaults to `right` for `cell.type: number`. Sets `cellStyle.justifyContent` and `ag-*-aligned-header` on the header.'
399
+ }
400
+ }
141
401
  }
142
402
  }
143
403
  }
@@ -0,0 +1,115 @@
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 { Avatar } from 'antd';
17
+ import { type } from '@lowdefy/helpers';
18
+ import NullCell from './NullCell.js';
19
+ import { resolveLink, resolvePath } from './resolveFieldRefs.js';
20
+ import { buildHref } from './LinkCell.js';
21
+ function initials(name) {
22
+ if (!type.isString(name) || name.length === 0) return '';
23
+ return name.trim().split(/\s+/).slice(0, 2).map((part)=>part[0]?.toUpperCase() ?? '').join('');
24
+ }
25
+ function colorSeed(id) {
26
+ if (type.isNone(id)) return 0;
27
+ const s = String(id);
28
+ let hash = 0;
29
+ for(let i = 0; i < s.length; i += 1)hash = hash * 31 + s.charCodeAt(i) >>> 0;
30
+ return hash;
31
+ }
32
+ const SEED_COLORS = [
33
+ 'var(--ant-color-info)',
34
+ 'var(--ant-color-success)',
35
+ 'var(--ant-color-warning)',
36
+ 'var(--ant-color-error)',
37
+ 'var(--ant-color-purple, var(--ant-color-info))',
38
+ 'var(--ant-color-cyan, var(--ant-color-info))',
39
+ 'var(--ant-color-magenta, var(--ant-color-error))'
40
+ ];
41
+ const rowStyle = {
42
+ display: 'inline-flex',
43
+ alignItems: 'center',
44
+ gap: 'var(--ant-margin-xs, 8px)',
45
+ maxWidth: '100%'
46
+ };
47
+ const labelStyle = {
48
+ overflow: 'hidden',
49
+ textOverflow: 'ellipsis',
50
+ whiteSpace: 'nowrap'
51
+ };
52
+ const linkStyle = {
53
+ ...labelStyle,
54
+ color: 'var(--ant-color-link)',
55
+ cursor: 'pointer'
56
+ };
57
+ function AvatarCell(params) {
58
+ const { value, data, cellConfig, methods } = params;
59
+ const name = type.isString(cellConfig?.nameField) ? resolvePath(cellConfig.nameField, data) : value;
60
+ const src = type.isString(cellConfig?.srcField) ? resolvePath(cellConfig.srcField, data) : undefined;
61
+ const id = type.isString(cellConfig?.idField) ? resolvePath(cellConfig.idField, data) : undefined;
62
+ if (type.isNone(name) && type.isNone(src)) {
63
+ return /*#__PURE__*/ React.createElement(NullCell, null);
64
+ }
65
+ const shape = cellConfig?.shape === 'square' ? 'square' : 'circle';
66
+ const size = 'var(--lf-avatar-size, var(--ant-control-height-sm, 24px))';
67
+ const fontSize = 'var(--lf-avatar-font-size, var(--ant-font-size-sm, 12px))';
68
+ const bg = SEED_COLORS[colorSeed(id ?? name) % SEED_COLORS.length];
69
+ const avatar = /*#__PURE__*/ React.createElement(Avatar, {
70
+ src: src || undefined,
71
+ shape: shape,
72
+ style: {
73
+ width: size,
74
+ height: size,
75
+ minWidth: size,
76
+ lineHeight: size,
77
+ fontSize,
78
+ backgroundColor: src ? undefined : bg,
79
+ color: 'var(--ant-color-text-light-solid, #fff)',
80
+ flexShrink: 0
81
+ }
82
+ }, initials(name));
83
+ const link = cellConfig?.link ? resolveLink(cellConfig.link, data) : undefined;
84
+ if (link) {
85
+ const href = buildHref(link);
86
+ const onClick = (event)=>{
87
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.button === 1) return;
88
+ if (link.newTab) return;
89
+ event.preventDefault();
90
+ methods?.triggerEvent?.({
91
+ name: 'onCellLink',
92
+ event: {
93
+ link,
94
+ row: data,
95
+ value
96
+ }
97
+ });
98
+ };
99
+ return /*#__PURE__*/ React.createElement("span", {
100
+ style: rowStyle
101
+ }, avatar, /*#__PURE__*/ React.createElement("a", {
102
+ href: href ?? '#',
103
+ style: linkStyle,
104
+ onClick: onClick,
105
+ target: link.newTab ? '_blank' : undefined,
106
+ rel: link.newTab ? 'noopener noreferrer' : undefined
107
+ }, String(name ?? '')));
108
+ }
109
+ return /*#__PURE__*/ React.createElement("span", {
110
+ style: rowStyle
111
+ }, avatar, /*#__PURE__*/ React.createElement("span", {
112
+ style: labelStyle
113
+ }, String(name ?? '')));
114
+ }
115
+ export default AvatarCell;
@@ -0,0 +1,31 @@
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
+ function BooleanCell(params) {
19
+ const { value, cellConfig } = params;
20
+ if (type.isNone(value)) return /*#__PURE__*/ React.createElement(NullCell, null);
21
+ const truthy = Boolean(value);
22
+ const label = truthy ? cellConfig?.trueLabel ?? 'Yes' : cellConfig?.falseLabel ?? 'No';
23
+ const color = truthy ? cellConfig?.trueColor ?? 'var(--ant-color-success)' : cellConfig?.falseColor ?? 'var(--ant-color-text-quaternary)';
24
+ return /*#__PURE__*/ React.createElement("span", {
25
+ style: {
26
+ color,
27
+ fontWeight: truthy ? 600 : 400
28
+ }
29
+ }, label);
30
+ }
31
+ export default BooleanCell;
@@ -0,0 +1,36 @@
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 dayjs from 'dayjs';
17
+ import relativeTime from 'dayjs/plugin/relativeTime.js';
18
+ import { type } from '@lowdefy/helpers';
19
+ import NullCell from './NullCell.js';
20
+ dayjs.extend(relativeTime);
21
+ const DEFAULT_FORMAT = 'YYYY-MM-DD HH:mm';
22
+ function DateCell(params) {
23
+ const { value, cellConfig } = params;
24
+ if (type.isNone(value) || value === '') {
25
+ return /*#__PURE__*/ React.createElement(NullCell, null);
26
+ }
27
+ const d = dayjs(value);
28
+ if (!d.isValid()) {
29
+ return /*#__PURE__*/ React.createElement(NullCell, {
30
+ placeholder: "—"
31
+ });
32
+ }
33
+ const text = cellConfig?.relative ? d.fromNow() : d.format(cellConfig?.format ?? DEFAULT_FORMAT);
34
+ return /*#__PURE__*/ React.createElement("span", null, text);
35
+ }
36
+ export default DateCell;
@@ -0,0 +1,37 @@
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
+ function createEllipsisCell(lines) {
18
+ const clamp = Math.max(1, Math.min(6, Math.floor(lines)));
19
+ const style = {
20
+ display: '-webkit-box',
21
+ WebkitBoxOrient: 'vertical',
22
+ WebkitLineClamp: clamp,
23
+ overflow: 'hidden',
24
+ whiteSpace: 'normal',
25
+ wordBreak: 'break-word',
26
+ width: '100%'
27
+ };
28
+ function EllipsisCell(params) {
29
+ const { value } = params;
30
+ if (type.isNone(value)) return null;
31
+ return /*#__PURE__*/ React.createElement("span", {
32
+ style: style
33
+ }, String(value));
34
+ }
35
+ return EllipsisCell;
36
+ }
37
+ export default createEllipsisCell;
@@ -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
+ import { resolveLink, resolveUrlQuery } from './resolveFieldRefs.js';
19
+ function buildHref(link) {
20
+ if (!type.isObject(link)) return undefined;
21
+ if (type.isString(link.href)) return link.href;
22
+ if (!type.isString(link.pageId)) return undefined;
23
+ const query = type.isObject(link.urlQuery) ? Object.entries(link.urlQuery).filter(([, v])=>!type.isNone(v)).map(([k, v])=>`${encodeURIComponent(k)}=${encodeURIComponent(String(v))}`).join('&') : '';
24
+ return `/${link.pageId}${query ? `?${query}` : ''}`;
25
+ }
26
+ const linkStyle = {
27
+ color: 'var(--ant-color-link)',
28
+ cursor: 'pointer',
29
+ textDecoration: 'none'
30
+ };
31
+ function LinkCell(params) {
32
+ const { value, data, cellConfig, methods } = params;
33
+ if (type.isNone(value) || value === '') {
34
+ return /*#__PURE__*/ React.createElement(NullCell, null);
35
+ }
36
+ const label = type.isString(cellConfig?.labelField) ? String(data?.[cellConfig.labelField] ?? value) : String(value);
37
+ const link = resolveLink({
38
+ pageId: cellConfig?.pageId,
39
+ href: cellConfig?.href,
40
+ back: cellConfig?.back,
41
+ home: cellConfig?.home,
42
+ newTab: cellConfig?.newTab,
43
+ urlQuery: cellConfig?.urlQuery
44
+ }, data);
45
+ const href = buildHref(link);
46
+ function onClick(event) {
47
+ if (event.metaKey || event.ctrlKey || event.shiftKey || event.button === 1) return;
48
+ if (cellConfig?.newTab) return;
49
+ event.preventDefault();
50
+ methods?.triggerEvent?.({
51
+ name: 'onCellLink',
52
+ event: {
53
+ link,
54
+ row: data,
55
+ value
56
+ }
57
+ });
58
+ }
59
+ return /*#__PURE__*/ React.createElement("a", {
60
+ href: href ?? '#',
61
+ style: linkStyle,
62
+ onClick: onClick,
63
+ target: cellConfig?.newTab ? '_blank' : undefined,
64
+ rel: cellConfig?.newTab ? 'noopener noreferrer' : undefined
65
+ }, label);
66
+ }
67
+ export { buildHref, resolveUrlQuery };
68
+ export default LinkCell;
@@ -0,0 +1,24 @@
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
+ const style = {
17
+ color: 'var(--ant-color-text-quaternary)'
18
+ };
19
+ function NullCell({ placeholder = '\u2014' }) {
20
+ return /*#__PURE__*/ React.createElement("span", {
21
+ style: style
22
+ }, placeholder);
23
+ }
24
+ export default NullCell;
@@ -0,0 +1,76 @@
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
+ function buildOptions(cellConfig = {}) {
19
+ const { format = 'number', decimals, minDecimals, maxDecimals, currency = 'USD', currencyDisplay = 'symbol', notation, useGrouping = true } = cellConfig;
20
+ const opts = {
21
+ useGrouping
22
+ };
23
+ if (format === 'currency') {
24
+ opts.style = 'currency';
25
+ opts.currency = currency;
26
+ opts.currencyDisplay = currencyDisplay;
27
+ } else if (format === 'percent') {
28
+ opts.style = 'percent';
29
+ } else if (format === 'compact') {
30
+ opts.notation = 'compact';
31
+ opts.compactDisplay = 'short';
32
+ } else {
33
+ opts.style = 'decimal';
34
+ }
35
+ if (notation && !opts.notation) opts.notation = notation;
36
+ if (type.isInt(decimals)) {
37
+ opts.minimumFractionDigits = decimals;
38
+ opts.maximumFractionDigits = decimals;
39
+ } else {
40
+ if (type.isInt(minDecimals)) opts.minimumFractionDigits = minDecimals;
41
+ if (type.isInt(maxDecimals)) opts.maximumFractionDigits = maxDecimals;
42
+ }
43
+ return opts;
44
+ }
45
+ function signColor(num, cellConfig) {
46
+ if (!cellConfig?.signColor) return cellConfig?.color;
47
+ if (num > 0) return cellConfig?.positiveColor ?? 'var(--ant-color-success)';
48
+ if (num < 0) return cellConfig?.negativeColor ?? 'var(--ant-color-error)';
49
+ return cellConfig?.zeroColor ?? cellConfig?.color;
50
+ }
51
+ function NumberCell(params) {
52
+ const { value, cellConfig } = params;
53
+ if (type.isNone(value) || value === '') return /*#__PURE__*/ React.createElement(NullCell, null);
54
+ const num = Number(value);
55
+ if (Number.isNaN(num)) return /*#__PURE__*/ React.createElement(NullCell, null);
56
+ const locale = cellConfig?.locale;
57
+ const opts = buildOptions(cellConfig);
58
+ const absText = new Intl.NumberFormat(locale, opts).format(Math.abs(num));
59
+ let text;
60
+ if (num < 0) {
61
+ text = cellConfig?.negative === 'parentheses' ? `(${absText})` : `-${absText}`;
62
+ } else {
63
+ text = absText;
64
+ }
65
+ const prefix = cellConfig?.prefix ?? '';
66
+ const suffix = cellConfig?.suffix ?? '';
67
+ const display = `${prefix}${text}${suffix}`;
68
+ const color = signColor(num, cellConfig);
69
+ const style = color ? {
70
+ color
71
+ } : undefined;
72
+ return /*#__PURE__*/ React.createElement("span", {
73
+ style: style
74
+ }, display);
75
+ }
76
+ export default NumberCell;