@stonecrop/atable 0.15.0 → 0.16.1
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/assets/index.css +1 -1
- package/dist/atable.d.ts +4 -0
- package/dist/atable.js +692 -680
- package/dist/atable.js.map +1 -1
- package/dist/src/schemaToColumns.d.ts +4 -0
- package/dist/src/schemaToColumns.d.ts.map +1 -1
- package/dist/src/schemaToColumns.js +10 -0
- package/dist/src/stores/table.d.ts.map +1 -1
- package/dist/src/stores/table.js +14 -4
- package/dist/src/utils.d.ts +6 -0
- package/dist/src/utils.d.ts.map +1 -1
- package/dist/src/utils.js +15 -0
- package/package.json +4 -4
- package/src/components/ATableColumnFilter.vue +1 -0
- package/src/schemaToColumns.ts +11 -0
- package/src/stores/table.ts +14 -4
- package/src/utils.ts +15 -0
|
@@ -15,6 +15,10 @@ import type { TableColumn } from './types';
|
|
|
15
15
|
* - A synchronous `format` function is added (unless the field already has one) that handles
|
|
16
16
|
* both bare ID strings and pre-resolved `{ id, displayText }` objects.
|
|
17
17
|
*
|
|
18
|
+
* For quantity fields — those whose `component` carries the `'quantity'` category — without an
|
|
19
|
+
* explicit `format`, a synchronous `format` is added that renders the `{ qty, uom }` value (see
|
|
20
|
+
* `QuantityValue` in `@stonecrop/aform`) as `"<qty> <uom>"`.
|
|
21
|
+
*
|
|
18
22
|
* @public
|
|
19
23
|
*/
|
|
20
24
|
export declare function schemaToColumns(schema: ColumnSchema[]): TableColumn[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemaToColumns.d.ts","sourceRoot":"","sources":["../../src/schemaToColumns.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemaToColumns.d.ts","sourceRoot":"","sources":["../../src/schemaToColumns.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AAErD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAG1C;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,YAAY,EAAE,GAAG,WAAW,EAAE,CA8BrE"}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { componentCategory } from '@stonecrop/schema';
|
|
2
|
+
import { formatQuantity } from './utils';
|
|
1
3
|
/**
|
|
2
4
|
* Convert an array of doctype field descriptors into ATable column definitions.
|
|
3
5
|
*
|
|
@@ -13,6 +15,10 @@
|
|
|
13
15
|
* - A synchronous `format` function is added (unless the field already has one) that handles
|
|
14
16
|
* both bare ID strings and pre-resolved `{ id, displayText }` objects.
|
|
15
17
|
*
|
|
18
|
+
* For quantity fields — those whose `component` carries the `'quantity'` category — without an
|
|
19
|
+
* explicit `format`, a synchronous `format` is added that renders the `{ qty, uom }` value (see
|
|
20
|
+
* `QuantityValue` in `@stonecrop/aform`) as `"<qty> <uom>"`.
|
|
21
|
+
*
|
|
16
22
|
* @public
|
|
17
23
|
*/
|
|
18
24
|
export function schemaToColumns(schema) {
|
|
@@ -36,6 +42,10 @@ export function schemaToColumns(schema) {
|
|
|
36
42
|
};
|
|
37
43
|
}
|
|
38
44
|
}
|
|
45
|
+
// Quantity fields: render the composite { qty, uom } value as "<qty> <uom>".
|
|
46
|
+
if (componentCategory(rest.component) === 'quantity' && !rest.format) {
|
|
47
|
+
col.format = formatQuantity;
|
|
48
|
+
}
|
|
39
49
|
return col;
|
|
40
50
|
});
|
|
41
51
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../src/stores/table.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,aAAa,EAAiB,MAAM,KAAK,CAAA;AAEvD,OAAO,KAAK,EACX,WAAW,EACX,gBAAgB,EAChB,cAAc,EACd,YAAY,EACZ,cAAc,EACd,WAAW,EACX,WAAW,EACX,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,MAAM,UA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MAAM,KAAG,GAAG;oCA6HtB,MAAM,YAAY,MAAM;kCA6I1B,MAAM;;;;;;;;;;;;;;;;kCAxIN,MAAM,YAAY,MAAM,SAAS,GAAG;8BA4IxC,MAAM;;;;;;;;;;;;iCAhPH,WAAW,KAAG,aAAa;mCAwCzB,MAAM;+BAyVV,MAAM,YAAY,OAAO,CAAC,QAAQ,CAAC,KAAG,MAAM;+BAW5C,MAAM,YAAY,OAAO,CAAC,QAAQ,CAAC,KAAG,MAAM;2BA7WhD,MAAM;6BAKJ,MAAM;yBAmXV,MAAM,WAAW,MAAM,KAAG,OAAO;2CArOf,gBAAgB;gCAlB3B,YAAY;6BA7If,MAAM,YAAY,MAAM;4BAhDzB,MAAM,YAAY,MAAM,SAAS,GAAG;4BAoBpC,MAAM,YAAY,MAAM,SAAS,MAAM;0BAmRzC,MAAM,UAAU,WAAW;6BAtBxB,MAAM;gCA5LH,MAAM;2CAqIK,MAAM;gCAlBjB,MAAM;4BAjCV,cAAc;0BAvJhB,QAAQ,EAAE;+kBAwiBxC,CAAA"}
|
package/dist/src/stores/table.js
CHANGED
|
@@ -1,7 +1,15 @@
|
|
|
1
1
|
import { defineStore } from 'pinia';
|
|
2
2
|
import { componentCategory } from '@stonecrop/schema';
|
|
3
3
|
import { computed, ref } from 'vue';
|
|
4
|
-
import { generateHash } from '../utils';
|
|
4
|
+
import { formatQuantity, generateHash } from '../utils';
|
|
5
|
+
// Quantity columns hold a composite `{ qty, uom, ... }` value (see `QuantityValue` in
|
|
6
|
+
// `@stonecrop/aform`); numeric comparisons (filtering, sorting) operate on `qty`.
|
|
7
|
+
function toComparableNumber(cellValue) {
|
|
8
|
+
if (cellValue !== null && typeof cellValue === 'object' && 'qty' in cellValue) {
|
|
9
|
+
return Number(cellValue.qty);
|
|
10
|
+
}
|
|
11
|
+
return Number(cellValue);
|
|
12
|
+
}
|
|
5
13
|
function isNodeOpen(rowIndex, treeDisplay) {
|
|
6
14
|
const row = treeDisplay[rowIndex];
|
|
7
15
|
if (row.isRoot) {
|
|
@@ -31,7 +39,7 @@ function applyFilter(cellValue, filter, column) {
|
|
|
31
39
|
return searchableText.toLowerCase().includes(String(value).toLowerCase());
|
|
32
40
|
}
|
|
33
41
|
case 'number': {
|
|
34
|
-
const numValue =
|
|
42
|
+
const numValue = toComparableNumber(cellValue);
|
|
35
43
|
const filterNum = Number(value);
|
|
36
44
|
return !isNaN(numValue) && !isNaN(filterNum) && numValue === filterNum;
|
|
37
45
|
}
|
|
@@ -281,8 +289,8 @@ export const createTableStore = (initData) => {
|
|
|
281
289
|
aVal = '';
|
|
282
290
|
if (bVal === null || bVal === undefined)
|
|
283
291
|
bVal = '';
|
|
284
|
-
const aNum =
|
|
285
|
-
const bNum =
|
|
292
|
+
const aNum = toComparableNumber(aVal);
|
|
293
|
+
const bNum = toComparableNumber(bVal);
|
|
286
294
|
const isNumeric = !isNaN(aNum) && !isNaN(bNum) && aVal !== '' && bVal !== '';
|
|
287
295
|
if (isNumeric) {
|
|
288
296
|
return direction === 'asc' ? aNum - bNum : bNum - aNum;
|
|
@@ -419,6 +427,8 @@ export const createTableStore = (initData) => {
|
|
|
419
427
|
return value != null ? new Date(String(value)).toLocaleDateString() : value;
|
|
420
428
|
if (category === 'datetime')
|
|
421
429
|
return value != null ? new Date(String(value)).toLocaleString() : value;
|
|
430
|
+
if (category === 'quantity')
|
|
431
|
+
return formatQuantity(value);
|
|
422
432
|
return value;
|
|
423
433
|
}
|
|
424
434
|
if (typeof format === 'function') {
|
package/dist/src/utils.d.ts
CHANGED
|
@@ -1,3 +1,9 @@
|
|
|
1
1
|
export declare const isHtmlString: (htmlString: string) => boolean;
|
|
2
2
|
export declare const generateHash: (length?: number) => string;
|
|
3
|
+
/**
|
|
4
|
+
* Render a composite quantity value (`{ qty, uom }`, see `QuantityValue` in `@stonecrop/aform`)
|
|
5
|
+
* as `"<qty> <uom>"`. Shared by the two paths a quantity column can reach formatting through:
|
|
6
|
+
* the `format` that `schemaToColumns` attaches, and the table store's category-based default.
|
|
7
|
+
*/
|
|
8
|
+
export declare const formatQuantity: (value: any) => string;
|
|
3
9
|
//# sourceMappingURL=utils.d.ts.map
|
package/dist/src/utils.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,YAAY,MAAM,YAG9C,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,eAAU,WAEtC,CAAA"}
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utils.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,YAAY,GAAI,YAAY,MAAM,YAG9C,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,eAAU,WAEtC,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,cAAc,GAAI,OAAO,GAAG,KAAG,MAQ3C,CAAA"}
|
package/dist/src/utils.js
CHANGED
|
@@ -5,3 +5,18 @@ export const isHtmlString = (htmlString) => {
|
|
|
5
5
|
export const generateHash = (length = 8) => {
|
|
6
6
|
return Array.from({ length }, () => Math.floor(Math.random() * 16).toString(16)).join('');
|
|
7
7
|
};
|
|
8
|
+
/**
|
|
9
|
+
* Render a composite quantity value (`{ qty, uom }`, see `QuantityValue` in `@stonecrop/aform`)
|
|
10
|
+
* as `"<qty> <uom>"`. Shared by the two paths a quantity column can reach formatting through:
|
|
11
|
+
* the `format` that `schemaToColumns` attaches, and the table store's category-based default.
|
|
12
|
+
*/
|
|
13
|
+
export const formatQuantity = (value) => {
|
|
14
|
+
if (value === null || value === undefined)
|
|
15
|
+
return '';
|
|
16
|
+
if (typeof value === 'object') {
|
|
17
|
+
const qty = value.qty ?? '';
|
|
18
|
+
const uom = value.uom ?? '';
|
|
19
|
+
return uom ? `${qty} ${uom}`.trim() : String(qty);
|
|
20
|
+
}
|
|
21
|
+
return String(value);
|
|
22
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@stonecrop/atable",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.16.1",
|
|
4
4
|
"description": "Advanced data table component for Stonecrop",
|
|
5
5
|
"bugs": {
|
|
6
6
|
"url": "https://github.com/agritheory/stonecrop/issues"
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"@vueuse/components": "^14.2.1",
|
|
37
37
|
"@vueuse/core": "^14.2.1",
|
|
38
|
-
"@stonecrop/schema": "0.
|
|
39
|
-
"@stonecrop/themes": "0.
|
|
40
|
-
"@stonecrop/utilities": "0.
|
|
38
|
+
"@stonecrop/schema": "0.16.1",
|
|
39
|
+
"@stonecrop/themes": "0.16.1",
|
|
40
|
+
"@stonecrop/utilities": "0.16.1"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@microsoft/api-documenter": "^7.30.5",
|
package/src/schemaToColumns.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
import { componentCategory } from '@stonecrop/schema'
|
|
1
2
|
import type { ColumnSchema } from '@stonecrop/schema'
|
|
2
3
|
|
|
3
4
|
import type { TableColumn } from './types'
|
|
5
|
+
import { formatQuantity } from './utils'
|
|
4
6
|
|
|
5
7
|
/**
|
|
6
8
|
* Convert an array of doctype field descriptors into ATable column definitions.
|
|
@@ -17,6 +19,10 @@ import type { TableColumn } from './types'
|
|
|
17
19
|
* - A synchronous `format` function is added (unless the field already has one) that handles
|
|
18
20
|
* both bare ID strings and pre-resolved `{ id, displayText }` objects.
|
|
19
21
|
*
|
|
22
|
+
* For quantity fields — those whose `component` carries the `'quantity'` category — without an
|
|
23
|
+
* explicit `format`, a synchronous `format` is added that renders the `{ qty, uom }` value (see
|
|
24
|
+
* `QuantityValue` in `@stonecrop/aform`) as `"<qty> <uom>"`.
|
|
25
|
+
*
|
|
20
26
|
* @public
|
|
21
27
|
*/
|
|
22
28
|
export function schemaToColumns(schema: ColumnSchema[]): TableColumn[] {
|
|
@@ -42,6 +48,11 @@ export function schemaToColumns(schema: ColumnSchema[]): TableColumn[] {
|
|
|
42
48
|
}
|
|
43
49
|
}
|
|
44
50
|
|
|
51
|
+
// Quantity fields: render the composite { qty, uom } value as "<qty> <uom>".
|
|
52
|
+
if (componentCategory(rest.component) === 'quantity' && !rest.format) {
|
|
53
|
+
col.format = formatQuantity
|
|
54
|
+
}
|
|
55
|
+
|
|
45
56
|
return col
|
|
46
57
|
})
|
|
47
58
|
}
|
package/src/stores/table.ts
CHANGED
|
@@ -14,7 +14,7 @@ import type {
|
|
|
14
14
|
TableModal,
|
|
15
15
|
TableRow,
|
|
16
16
|
} from '../types'
|
|
17
|
-
import { generateHash } from '../utils'
|
|
17
|
+
import { formatQuantity, generateHash } from '../utils'
|
|
18
18
|
|
|
19
19
|
/**
|
|
20
20
|
* Represents the state of a single filter
|
|
@@ -35,6 +35,15 @@ export interface FilterState {
|
|
|
35
35
|
*/
|
|
36
36
|
export type FilterStateRecord = Record<number, FilterState>
|
|
37
37
|
|
|
38
|
+
// Quantity columns hold a composite `{ qty, uom, ... }` value (see `QuantityValue` in
|
|
39
|
+
// `@stonecrop/aform`); numeric comparisons (filtering, sorting) operate on `qty`.
|
|
40
|
+
function toComparableNumber(cellValue: unknown): number {
|
|
41
|
+
if (cellValue !== null && typeof cellValue === 'object' && 'qty' in cellValue) {
|
|
42
|
+
return Number(cellValue.qty)
|
|
43
|
+
}
|
|
44
|
+
return Number(cellValue)
|
|
45
|
+
}
|
|
46
|
+
|
|
38
47
|
function isNodeOpen(rowIndex: number, treeDisplay: TableDisplay[]): boolean {
|
|
39
48
|
const row = treeDisplay[rowIndex]
|
|
40
49
|
if (row.isRoot) {
|
|
@@ -71,7 +80,7 @@ function applyFilter(cellValue: any, filter: FilterState, column: TableColumn):
|
|
|
71
80
|
}
|
|
72
81
|
|
|
73
82
|
case 'number': {
|
|
74
|
-
const numValue =
|
|
83
|
+
const numValue = toComparableNumber(cellValue)
|
|
75
84
|
const filterNum = Number(value)
|
|
76
85
|
return !isNaN(numValue) && !isNaN(filterNum) && numValue === filterNum
|
|
77
86
|
}
|
|
@@ -361,8 +370,8 @@ export const createTableStore = (initData: {
|
|
|
361
370
|
if (aVal === null || aVal === undefined) aVal = ''
|
|
362
371
|
if (bVal === null || bVal === undefined) bVal = ''
|
|
363
372
|
|
|
364
|
-
const aNum =
|
|
365
|
-
const bNum =
|
|
373
|
+
const aNum = toComparableNumber(aVal)
|
|
374
|
+
const bNum = toComparableNumber(bVal)
|
|
366
375
|
const isNumeric = !isNaN(aNum) && !isNaN(bNum) && aVal !== '' && bVal !== ''
|
|
367
376
|
|
|
368
377
|
if (isNumeric) {
|
|
@@ -521,6 +530,7 @@ export const createTableStore = (initData: {
|
|
|
521
530
|
if (category === 'boolean') return value ? '✓' : '✗'
|
|
522
531
|
if (category === 'date') return value != null ? new Date(String(value)).toLocaleDateString() : value
|
|
523
532
|
if (category === 'datetime') return value != null ? new Date(String(value)).toLocaleString() : value
|
|
533
|
+
if (category === 'quantity') return formatQuantity(value)
|
|
524
534
|
return value
|
|
525
535
|
}
|
|
526
536
|
|
package/src/utils.ts
CHANGED
|
@@ -6,3 +6,18 @@ export const isHtmlString = (htmlString: string) => {
|
|
|
6
6
|
export const generateHash = (length = 8) => {
|
|
7
7
|
return Array.from({ length }, () => Math.floor(Math.random() * 16).toString(16)).join('')
|
|
8
8
|
}
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Render a composite quantity value (`{ qty, uom }`, see `QuantityValue` in `@stonecrop/aform`)
|
|
12
|
+
* as `"<qty> <uom>"`. Shared by the two paths a quantity column can reach formatting through:
|
|
13
|
+
* the `format` that `schemaToColumns` attaches, and the table store's category-based default.
|
|
14
|
+
*/
|
|
15
|
+
export const formatQuantity = (value: any): string => {
|
|
16
|
+
if (value === null || value === undefined) return ''
|
|
17
|
+
if (typeof value === 'object') {
|
|
18
|
+
const qty = value.qty ?? ''
|
|
19
|
+
const uom = value.uom ?? ''
|
|
20
|
+
return uom ? `${qty} ${uom}`.trim() : String(qty)
|
|
21
|
+
}
|
|
22
|
+
return String(value)
|
|
23
|
+
}
|