@universal-material/data-grid 0.2.0 → 0.3.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.
- package/README.md +1 -1
- package/custom-elements.json +114 -15
- package/dist/data/data-source.d.ts +6 -2
- package/dist/data/data-source.js.map +1 -1
- package/dist/export-xlsx/index.d.ts +2 -1
- package/dist/export-xlsx/index.js +4 -2
- package/dist/export-xlsx/index.js.map +1 -1
- package/dist/features/column-chooser.js +1 -1
- package/dist/features/column-chooser.js.map +1 -1
- package/dist/features/filter-row.d.ts +1 -0
- package/dist/features/filter-row.js +13 -8
- package/dist/features/filter-row.js.map +1 -1
- package/dist/features/header-filter.d.ts +4 -1
- package/dist/features/header-filter.js +7 -5
- package/dist/features/header-filter.js.map +1 -1
- package/dist/grid-column-def.d.ts +45 -11
- package/dist/grid-column-def.js +6 -2
- package/dist/grid-column-def.js.map +1 -1
- package/dist/grid-column.d.ts +23 -5
- package/dist/grid-column.js +32 -5
- package/dist/grid-column.js.map +1 -1
- package/dist/grid-i18n.js +14 -14
- package/dist/grid-i18n.js.map +1 -1
- package/dist/grid.d.ts +31 -10
- package/dist/grid.js +255 -55
- package/dist/grid.js.map +1 -1
- package/dist/grid.min.js +457 -418
- package/dist/grid.styles.js +42 -6
- package/dist/grid.styles.js.map +1 -1
- package/dist/render/cell.js +5 -2
- package/dist/render/cell.js.map +1 -1
- package/dist/row-model/columns.d.ts +21 -3
- package/dist/row-model/columns.js +14 -4
- package/dist/row-model/columns.js.map +1 -1
- package/dist/row-model/filter.d.ts +19 -4
- package/dist/row-model/filter.js +29 -9
- package/dist/row-model/filter.js.map +1 -1
- package/dist/row-model/format.js +1 -1
- package/dist/row-model/format.js.map +1 -1
- package/dist/state/grid-state.d.ts +2 -2
- package/dist/state/grid-state.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -79,7 +79,7 @@ A self-contained bundle (Lit included) is published for CDNs. An import map lets
|
|
|
79
79
|
<script type="importmap">
|
|
80
80
|
{
|
|
81
81
|
"imports": {
|
|
82
|
-
"@universal-material/data-grid": "https://cdn.jsdelivr.net/npm/@universal-material/data-grid@0.
|
|
82
|
+
"@universal-material/data-grid": "https://cdn.jsdelivr.net/npm/@universal-material/data-grid@0.3/dist/grid.min.js"
|
|
83
83
|
}
|
|
84
84
|
}
|
|
85
85
|
</script>
|
package/custom-elements.json
CHANGED
|
@@ -57,7 +57,11 @@
|
|
|
57
57
|
"name": "--u-grid-toolbar-inline-padding"
|
|
58
58
|
},
|
|
59
59
|
{
|
|
60
|
-
"description": "
|
|
60
|
+
"description": "Space between the bar items and between its lines (a `gap` value). Default `8px`. A change at runtime applies at the next toolbar layout (resize or item change).",
|
|
61
|
+
"name": "--u-grid-toolbar-gap"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"description": "Minimum height of the column header cells (rows with `header-wrap` grow). Default `46px`.",
|
|
61
65
|
"name": "--u-grid-header-cell-height"
|
|
62
66
|
},
|
|
63
67
|
{
|
|
@@ -197,11 +201,11 @@
|
|
|
197
201
|
"name": "--u-grid-drop-indicator-width"
|
|
198
202
|
},
|
|
199
203
|
{
|
|
200
|
-
"description": "Invisible resize
|
|
204
|
+
"description": "Invisible resize area at the end of each header cell, over its end padding (the header buttons reach up to it). Default `8px`.",
|
|
201
205
|
"name": "--u-grid-resize-handle-width"
|
|
202
206
|
},
|
|
203
207
|
{
|
|
204
|
-
"description": "Size of the \"⋮\"
|
|
208
|
+
"description": "Size of the header \"⋮\" and filter buttons, side by side. Default `24px` (WCAG 2.5.8; below it, add spacing).",
|
|
205
209
|
"name": "--u-grid-column-header-menu-button-size"
|
|
206
210
|
},
|
|
207
211
|
{
|
|
@@ -265,7 +269,7 @@
|
|
|
265
269
|
"name": "--u-grid-load-panel-background-color"
|
|
266
270
|
},
|
|
267
271
|
{
|
|
268
|
-
"description": "Color of the placeholders in rows still loading.",
|
|
272
|
+
"description": "Color of the placeholders in rows still loading (remote rows, or `loading` with no rows).",
|
|
269
273
|
"name": "--u-grid-skeleton-row-color"
|
|
270
274
|
},
|
|
271
275
|
{
|
|
@@ -355,7 +359,7 @@
|
|
|
355
359
|
"name": "selection-checkbox"
|
|
356
360
|
},
|
|
357
361
|
{
|
|
358
|
-
"description": "The cell rendered in the empty state.",
|
|
362
|
+
"description": "The cell rendered in the empty state, or the \"Loading…\" cell while `loading` has no rows.",
|
|
359
363
|
"name": "no-data"
|
|
360
364
|
},
|
|
361
365
|
{
|
|
@@ -579,11 +583,11 @@
|
|
|
579
583
|
"name": "page-info"
|
|
580
584
|
},
|
|
581
585
|
{
|
|
582
|
-
"description": "The load panel shown while a data source loads.",
|
|
586
|
+
"description": "The load panel shown while a data source loads or `loading` is set (with rows).",
|
|
583
587
|
"name": "load-panel"
|
|
584
588
|
},
|
|
585
589
|
{
|
|
586
|
-
"description": "Rows of a remote source not loaded yet (with `row`).",
|
|
590
|
+
"description": "Rows of a remote source not loaded yet (with `row`), or placeholder rows while `loading` has no rows.",
|
|
587
591
|
"name": "skeleton-row"
|
|
588
592
|
},
|
|
589
593
|
{
|
|
@@ -685,6 +689,26 @@
|
|
|
685
689
|
"default": "null",
|
|
686
690
|
"description": "Builds the empty state (property only) shown when there are no rows to\nshow; `ctx.filtered` tells a filter/search hid every item. Without it,\nthe translated \"No data\" text."
|
|
687
691
|
},
|
|
692
|
+
{
|
|
693
|
+
"kind": "field",
|
|
694
|
+
"name": "loading",
|
|
695
|
+
"type": {
|
|
696
|
+
"text": "boolean"
|
|
697
|
+
},
|
|
698
|
+
"default": "false",
|
|
699
|
+
"description": "Shows the grid as loading, for `items` you are still fetching. With rows\non screen, the load panel (`::part(load-panel)`) covers them; with no rows\nyet, a \"Loading…\" row and placeholder rows (`::part(skeleton-row)`) take\nthe place of the empty state (`noDataRenderer` is not called). Placeholder\nrows are never data: not exported, selected, counted or focusable by API.\nDoes not fire `u-grid-loading`/`u-grid-load`; with `dataSource`, it adds\nto the source's own loading state (the getter returns only what you set).",
|
|
700
|
+
"attribute": "loading"
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
"kind": "field",
|
|
704
|
+
"name": "headerWrap",
|
|
705
|
+
"type": {
|
|
706
|
+
"text": "boolean"
|
|
707
|
+
},
|
|
708
|
+
"default": "false",
|
|
709
|
+
"description": "Wraps the column header labels in several lines instead of an ellipsis\n(the header row grows; `--u-grid-header-cell-height` is its minimum). A\ncolumn's `headerWrap` wins. Auto-size measures the label in one line. If\nthe toolbar and the headers take more than half of the visible height,\nthe headers stop sticking (WCAG 2.4.11).",
|
|
710
|
+
"attribute": "header-wrap"
|
|
711
|
+
},
|
|
688
712
|
{
|
|
689
713
|
"kind": "field",
|
|
690
714
|
"name": "detailRenderer",
|
|
@@ -1174,7 +1198,7 @@
|
|
|
1174
1198
|
"type": {
|
|
1175
1199
|
"text": "GridFilterExpression | null"
|
|
1176
1200
|
},
|
|
1177
|
-
"description": "Column filter (property only): a serializable expression such as\n`[['age', '>', 30], 'and', ['name', 'contains', 'an']]`. The filter row\nand the header filter read and write it, so it always holds the current\nfilter. The grid keeps a frozen
|
|
1201
|
+
"description": "Column filter (property only): a serializable expression such as\n`[['age', '>', 30], 'and', ['name', 'contains', 'an']]`. The filter row\nand the header filter read and write it, so it always holds the current\nfilter. A condition refers to its column by `path` or, for a computed\ncolumn (`valueGetter` without `path`), by `name`. The grid keeps a frozen\ncopy (never the host array). Setting it does not fire `u-grid-filter-change`."
|
|
1178
1202
|
},
|
|
1179
1203
|
{
|
|
1180
1204
|
"kind": "field",
|
|
@@ -2017,7 +2041,7 @@
|
|
|
2017
2041
|
"text": "GridFilterExpression | null"
|
|
2018
2042
|
}
|
|
2019
2043
|
},
|
|
2020
|
-
"description": "The effective filter: `filterValue` `and` the search, as an expression\n(copy). The search becomes `[
|
|
2044
|
+
"description": "The effective filter: `filterValue` `and` the search, as an expression\n(copy). The search becomes `[field, 'contains', text]` (`field`: the\n`path`, or the `name` of a computed column) joined by `or`\nover the visible filterable columns (number and date columns included:\n`contains` matches their displayed text). `null` without filter."
|
|
2021
2045
|
},
|
|
2022
2046
|
{
|
|
2023
2047
|
"kind": "method",
|
|
@@ -2818,6 +2842,24 @@
|
|
|
2818
2842
|
"description": "Groups start expanded. INITIAL default: afterwards expansion is grid\nstate (`expandGroup`, `expandAllGroups`…); changing it resets that state.",
|
|
2819
2843
|
"fieldName": "autoExpandGroups"
|
|
2820
2844
|
},
|
|
2845
|
+
{
|
|
2846
|
+
"name": "loading",
|
|
2847
|
+
"type": {
|
|
2848
|
+
"text": "boolean"
|
|
2849
|
+
},
|
|
2850
|
+
"default": "false",
|
|
2851
|
+
"description": "Shows the grid as loading, for `items` you are still fetching. With rows\non screen, the load panel (`::part(load-panel)`) covers them; with no rows\nyet, a \"Loading…\" row and placeholder rows (`::part(skeleton-row)`) take\nthe place of the empty state (`noDataRenderer` is not called). Placeholder\nrows are never data: not exported, selected, counted or focusable by API.\nDoes not fire `u-grid-loading`/`u-grid-load`; with `dataSource`, it adds\nto the source's own loading state (the getter returns only what you set).",
|
|
2852
|
+
"fieldName": "loading"
|
|
2853
|
+
},
|
|
2854
|
+
{
|
|
2855
|
+
"name": "header-wrap",
|
|
2856
|
+
"type": {
|
|
2857
|
+
"text": "boolean"
|
|
2858
|
+
},
|
|
2859
|
+
"default": "false",
|
|
2860
|
+
"description": "Wraps the column header labels in several lines instead of an ellipsis\n(the header row grows; `--u-grid-header-cell-height` is its minimum). A\ncolumn's `headerWrap` wins. Auto-size measures the label in one line. If\nthe toolbar and the headers take more than half of the visible height,\nthe headers stop sticking (WCAG 2.4.11).",
|
|
2861
|
+
"fieldName": "headerWrap"
|
|
2862
|
+
},
|
|
2821
2863
|
{
|
|
2822
2864
|
"name": "auto-expand-rows",
|
|
2823
2865
|
"type": {
|
|
@@ -3964,7 +4006,7 @@
|
|
|
3964
4006
|
"text": "string"
|
|
3965
4007
|
},
|
|
3966
4008
|
"default": "''",
|
|
3967
|
-
"description": "Stable id of the column in the grid state (`getState`, `stateStorage`)\nand in string column references (`summary` items look it up before\n`path`). Default: `path`. A column without `name` and `path` is
|
|
4009
|
+
"description": "Stable id of the column in the grid state (`getState`, `stateStorage`)\nand in string column references (`summary` items look it up before\n`path`) and, for a column without `path`, in filter conditions\n(`filterValue`). Default: `path`. A column without `name` and `path` is\nleft out of the state.",
|
|
3968
4010
|
"attribute": "name"
|
|
3969
4011
|
},
|
|
3970
4012
|
{
|
|
@@ -4048,9 +4090,29 @@
|
|
|
4048
4090
|
"text": "GridColumnBooleanDisplay | null"
|
|
4049
4091
|
},
|
|
4050
4092
|
"default": "null",
|
|
4051
|
-
"description": "`text` (default)
|
|
4093
|
+
"description": "`text` (default), `icon` (read-only check/cross icon) or `check` (check\nicon for `true`, nothing visible for `false`) for boolean columns.",
|
|
4052
4094
|
"attribute": "boolean-display"
|
|
4053
4095
|
},
|
|
4096
|
+
{
|
|
4097
|
+
"kind": "field",
|
|
4098
|
+
"name": "trueText",
|
|
4099
|
+
"type": {
|
|
4100
|
+
"text": "string | null"
|
|
4101
|
+
},
|
|
4102
|
+
"default": "null",
|
|
4103
|
+
"description": "Text of `true` in this boolean column (cell, icon name, group row, filters,\ncopy/paste, summaries, export). Empty or unset: the language's `trueText`;\na fixed text, it does not follow `language`.",
|
|
4104
|
+
"attribute": "true-text"
|
|
4105
|
+
},
|
|
4106
|
+
{
|
|
4107
|
+
"kind": "field",
|
|
4108
|
+
"name": "falseText",
|
|
4109
|
+
"type": {
|
|
4110
|
+
"text": "string | null"
|
|
4111
|
+
},
|
|
4112
|
+
"default": "null",
|
|
4113
|
+
"description": "Text of `false` in this boolean column, like `trueText`. Empty or unset: the language's `falseText`.",
|
|
4114
|
+
"attribute": "false-text"
|
|
4115
|
+
},
|
|
4054
4116
|
{
|
|
4055
4117
|
"kind": "field",
|
|
4056
4118
|
"name": "wrap",
|
|
@@ -4061,6 +4123,16 @@
|
|
|
4061
4123
|
"description": "Wraps the text in several lines instead of an ellipsis (`wrap=\"false\"` turns it off).",
|
|
4062
4124
|
"attribute": "wrap"
|
|
4063
4125
|
},
|
|
4126
|
+
{
|
|
4127
|
+
"kind": "field",
|
|
4128
|
+
"name": "headerWrap",
|
|
4129
|
+
"type": {
|
|
4130
|
+
"text": "boolean | null"
|
|
4131
|
+
},
|
|
4132
|
+
"default": "null",
|
|
4133
|
+
"description": "Wraps the header label in several lines (`header-wrap`); `header-wrap=\"false\"`\nturns off the grid's `header-wrap` for this column. Unset: the grid's.",
|
|
4134
|
+
"attribute": "header-wrap"
|
|
4135
|
+
},
|
|
4064
4136
|
{
|
|
4065
4137
|
"kind": "field",
|
|
4066
4138
|
"name": "minWidth",
|
|
@@ -4206,7 +4278,7 @@
|
|
|
4206
4278
|
"text": "boolean | null"
|
|
4207
4279
|
},
|
|
4208
4280
|
"default": "null",
|
|
4209
|
-
"description": "Allows filtering by this column (filter row, header filter and, by\ndefault, the search panel). Default (`null`): `true`
|
|
4281
|
+
"description": "Allows filtering by this column (filter row, header filter and, by\ndefault, the search panel). Default (`null`): `true` with a `path`, or\nwith a `valueGetter` and a `name` (not with remote filtering).\n`filterable=\"false\"` disables it.",
|
|
4210
4282
|
"attribute": "filterable"
|
|
4211
4283
|
},
|
|
4212
4284
|
{
|
|
@@ -4327,7 +4399,7 @@
|
|
|
4327
4399
|
"text": "string"
|
|
4328
4400
|
},
|
|
4329
4401
|
"default": "''",
|
|
4330
|
-
"description": "Stable id of the column in the grid state (`getState`, `stateStorage`)\nand in string column references (`summary` items look it up before\n`path`). Default: `path`. A column without `name` and `path` is
|
|
4402
|
+
"description": "Stable id of the column in the grid state (`getState`, `stateStorage`)\nand in string column references (`summary` items look it up before\n`path`) and, for a column without `path`, in filter conditions\n(`filterValue`). Default: `path`. A column without `name` and `path` is\nleft out of the state.",
|
|
4331
4403
|
"fieldName": "name"
|
|
4332
4404
|
},
|
|
4333
4405
|
{
|
|
@@ -4354,9 +4426,27 @@
|
|
|
4354
4426
|
"text": "GridColumnBooleanDisplay | null"
|
|
4355
4427
|
},
|
|
4356
4428
|
"default": "null",
|
|
4357
|
-
"description": "`text` (default)
|
|
4429
|
+
"description": "`text` (default), `icon` (read-only check/cross icon) or `check` (check\nicon for `true`, nothing visible for `false`) for boolean columns.",
|
|
4358
4430
|
"fieldName": "booleanDisplay"
|
|
4359
4431
|
},
|
|
4432
|
+
{
|
|
4433
|
+
"name": "true-text",
|
|
4434
|
+
"type": {
|
|
4435
|
+
"text": "string | null"
|
|
4436
|
+
},
|
|
4437
|
+
"default": "null",
|
|
4438
|
+
"description": "Text of `true` in this boolean column (cell, icon name, group row, filters,\ncopy/paste, summaries, export). Empty or unset: the language's `trueText`;\na fixed text, it does not follow `language`.",
|
|
4439
|
+
"fieldName": "trueText"
|
|
4440
|
+
},
|
|
4441
|
+
{
|
|
4442
|
+
"name": "false-text",
|
|
4443
|
+
"type": {
|
|
4444
|
+
"text": "string | null"
|
|
4445
|
+
},
|
|
4446
|
+
"default": "null",
|
|
4447
|
+
"description": "Text of `false` in this boolean column, like `trueText`. Empty or unset: the language's `falseText`.",
|
|
4448
|
+
"fieldName": "falseText"
|
|
4449
|
+
},
|
|
4360
4450
|
{
|
|
4361
4451
|
"name": "wrap",
|
|
4362
4452
|
"type": {
|
|
@@ -4366,6 +4456,15 @@
|
|
|
4366
4456
|
"description": "Wraps the text in several lines instead of an ellipsis (`wrap=\"false\"` turns it off).",
|
|
4367
4457
|
"fieldName": "wrap"
|
|
4368
4458
|
},
|
|
4459
|
+
{
|
|
4460
|
+
"name": "header-wrap",
|
|
4461
|
+
"type": {
|
|
4462
|
+
"text": "boolean | null"
|
|
4463
|
+
},
|
|
4464
|
+
"default": "null",
|
|
4465
|
+
"description": "Wraps the header label in several lines (`header-wrap`); `header-wrap=\"false\"`\nturns off the grid's `header-wrap` for this column. Unset: the grid's.",
|
|
4466
|
+
"fieldName": "headerWrap"
|
|
4467
|
+
},
|
|
4369
4468
|
{
|
|
4370
4469
|
"name": "min-width",
|
|
4371
4470
|
"type": {
|
|
@@ -4480,7 +4579,7 @@
|
|
|
4480
4579
|
"text": "boolean | null"
|
|
4481
4580
|
},
|
|
4482
4581
|
"default": "null",
|
|
4483
|
-
"description": "Allows filtering by this column (filter row, header filter and, by\ndefault, the search panel). Default (`null`): `true`
|
|
4582
|
+
"description": "Allows filtering by this column (filter row, header filter and, by\ndefault, the search panel). Default (`null`): `true` with a `path`, or\nwith a `valueGetter` and a `name` (not with remote filtering).\n`filterable=\"false\"` disables it.",
|
|
4484
4583
|
"fieldName": "filterable"
|
|
4485
4584
|
},
|
|
4486
4585
|
{
|
|
@@ -43,9 +43,13 @@ export interface GridLoadOptions {
|
|
|
43
43
|
readonly take?: number;
|
|
44
44
|
/** Sorting, in priority order (grouped columns included, with the direction of their groups). */
|
|
45
45
|
readonly sort: readonly GridLoadSort[];
|
|
46
|
-
/**
|
|
46
|
+
/**
|
|
47
|
+
* Column filter `and` search — the same as `getCombinedFilter()`; `null` without filter.
|
|
48
|
+
* A condition refers to its column by `path` or, for a computed column (`valueGetter`
|
|
49
|
+
* without `path`, filterable only with `filterable: true`), by `name`: translate it.
|
|
50
|
+
*/
|
|
47
51
|
readonly filter: GridFilterExpression | null;
|
|
48
|
-
/** Column filter only (the `filterValue` property). */
|
|
52
|
+
/** Column filter only (the `filterValue` property; columns by `path` or `name`, as in `filter`). */
|
|
49
53
|
readonly filterValue: GridFilterExpression | null;
|
|
50
54
|
/** Raw search text (already part of `filter`), for servers with their own text search. */
|
|
51
55
|
readonly searchText: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-source.js","sourceRoot":"","sources":["../../src/data/data-source.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAgKvD,MAAM,CAAC,MAAM,SAAS,GAAgB,MAAM,CAAC,MAAM,CAAC;IAClD,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,KA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Q,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,EAAE,CAAC;QAC9F,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAErB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import type {\n GridFilterExpression,\n GridGroupPath,\n GridSortOrder,\n GridSummaryType,\n} from '../grid-column-def.js';\nimport { getValueByPath } from '../row-model/value.js';\n\n/** Key of a row read by `keyExpr`. */\nexport type GridRowKey = string | number;\n\n/** `keyExpr` of `<u-grid>`: a property `path` (dots allowed) or a function that returns the key of an item. */\nexport type GridKeyExpr<TItem = any> = string | ((item: TItem) => GridRowKey);\n\n/** How rows scroll: `virtual` (all rows, rendered on demand) or `infinite` (the next block loads at the end; `dataSource` only). */\nexport type GridScrollMode = 'virtual' | 'infinite';\n\n/** A column of `GridLoadOptions.sort`. */\nexport interface GridLoadSort {\n /** Column `path`. */\n readonly path: string;\n /** Direction. */\n readonly order: GridSortOrder;\n}\n\n/** A grouping level of `GridLoadOptions.group`, outermost first. */\nexport interface GridLoadGroup {\n /** Column `path`. */\n readonly path: string;\n /** Order of the group keys. */\n readonly order: GridSortOrder;\n /** `false`: return only the keys, counts and summaries of the level (`items: null`). The grid always asks `false`. */\n readonly expanded: boolean;\n}\n\n/** A summary the server computes (`totalSummary`, `groupSummary`). */\nexport interface GridLoadSummary {\n /** Column `path`. */\n readonly path: string;\n /** Aggregate (custom aggregate functions are never sent). */\n readonly type: GridSummaryType;\n /** The `name` of the summary item, when it has one. */\n readonly name?: string;\n}\n\n/**\n * What the grid asks the data source. Frozen data: the host builds the\n * request from it — the grid never builds URLs or queries. `filter`,\n * `filterValue`, `searchText` and the paths come from the user and must be\n * validated by the server (allow-list of paths and operations).\n */\nexport interface GridLoadOptions {\n /** Rows to skip (absent = from the start). */\n readonly skip?: number;\n /** Rows to return (absent = all). */\n readonly take?: number;\n /** Sorting, in priority order (grouped columns included, with the direction of their groups). */\n readonly sort: readonly GridLoadSort[];\n /** Column filter `and` search — the same as `getCombinedFilter()`; `null` without filter. */\n readonly filter: GridFilterExpression | null;\n /** Column filter only (the `filterValue` property). */\n readonly filterValue: GridFilterExpression | null;\n /** Raw search text (already part of `filter`), for servers with their own text search. */\n readonly searchText: string;\n /**\n * All grouping levels, outermost first (empty = not grouped). Return groups\n * (`GridLoadGroupResult[]`) of level `groupPath.length` while it is less than\n * `group.length`; items when it is equal.\n */\n readonly group: readonly GridLoadGroup[];\n /** Values of the open group, outermost first: only rows of that group (exact equality). `null` = all rows. */\n readonly groupPath: GridGroupPath | null;\n /** Return `totalCount`. */\n readonly requireTotalCount: boolean;\n /** Return `groupCount` (number of groups of the level). */\n readonly requireGroupCount: boolean;\n /** Summaries over all matching rows, returned in `GridLoadResult.summary` in this order. */\n readonly totalSummary: readonly GridLoadSummary[];\n /** Summaries of each returned group, in `GridLoadGroupResult.summary` in this order. */\n readonly groupSummary: readonly GridLoadSummary[];\n /** Tree data (`treeMode=\"flat\"`): which nodes to return; absent or `null` = a plain list. */\n readonly tree?: GridLoadTree | null;\n}\n\n/** `GridLoadOptions.tree`: what a tree asks the data source (items with their `parentKeyExpr`). */\nexport interface GridLoadTree {\n /**\n * Return the children of these nodes (`[rootParentKey]` = the root nodes;\n * keys as set — text when `root-parent-key` came from the attribute).\n * `null` = a remote filter is active: return the matching nodes AND all\n * their ancestors, at once.\n */\n readonly parentKeys: readonly (GridRowKey | null)[] | null;\n}\n\n/** A group returned when `GridLoadOptions.group` is not empty. */\nexport interface GridLoadGroupResult<TItem = any> {\n /** Group value. */\n key: unknown;\n /** Number of data rows in the group. */\n count: number;\n /** `null` (the grid always asks collapsed groups); items or subgroups are accepted and ignored. */\n items: readonly TItem[] | readonly GridLoadGroupResult<TItem>[] | null;\n /** Values of `groupSummary`, in its order. */\n summary?: readonly unknown[];\n}\n\n/** What `GridDataSource.load` resolves to. */\nexport interface GridLoadResult<TItem = any> {\n /** Items, or groups when `group` was not empty. */\n data: readonly TItem[] | readonly GridLoadGroupResult<TItem>[];\n /** Number of matching rows (when `requireTotalCount`). */\n totalCount?: number;\n /** Number of groups of the level (when `requireGroupCount`). */\n groupCount?: number;\n /** Values of `totalSummary`, in its order. */\n summary?: readonly unknown[];\n}\n\n/**\n * Data source of `<u-grid>`: the grid calls `load` and the host fetches the\n * data. `signal` aborts when the request is no longer needed (sorting,\n * filtering or grouping changed, `refresh()`, grid removed).\n */\nexport interface GridDataSource<TItem = any> {\n load(options: GridLoadOptions, signal: AbortSignal): Promise<GridLoadResult<TItem>>;\n}\n\n/**\n * Operations done by the server (`remoteOperations`). Remote `paging` or\n * `grouping` also turn on `filtering`, `sorting` and `summary`, and `paging`\n * turns on `grouping` (console warning); `summary` alone is ignored (the\n * grid has every row and computes it).\n */\nexport interface GridRemoteOperations {\n /** The server applies `filter` (or `filterValue` + `searchText`). */\n filtering?: boolean;\n /** The server applies `sort`. */\n sorting?: boolean;\n /** The server applies `skip`/`take` (rows load in blocks of `pageSize`). */\n paging?: boolean;\n /** The server returns groups (`group`, `groupPath`). */\n grouping?: boolean;\n /** The server computes `totalSummary`/`groupSummary` (with remote paging or grouping). */\n summary?: boolean;\n}\n\n/** Changes for `applyChanges()`: `update` and `remove` find rows by key (`keyExpr`). */\nexport interface GridDataChanges<TItem = any> {\n /** New items (appended to the loaded rows, or at their sorted place with `reshapeOnChanges`; with remote paging the rows reload). */\n add?: readonly TItem[];\n /** New versions of items (same key). */\n update?: readonly TItem[];\n /** Keys of the rows to remove. */\n remove?: readonly unknown[];\n}\n\n/** Operações remotas já normalizadas (dependências aplicadas). */\nexport interface RemoteFlags {\n filtering: boolean;\n sorting: boolean;\n paging: boolean;\n grouping: boolean;\n summary: boolean;\n}\n\nexport const NO_REMOTE: RemoteFlags = Object.freeze({\n filtering: false,\n sorting: false,\n paging: false,\n grouping: false,\n summary: false,\n});\n\n/**\n * Normaliza `remoteOperations`: paginação ou agrupamento no servidor exigem\n * filtrar e ordenar lá; paginar no servidor exige agrupar lá (os grupos\n * precisam de todas as linhas); resumo remoto só existe com paginação ou\n * agrupamento remotos (senão o grid tem todas as linhas e calcula).\n * `forced` lista o que foi ligado por dependência (para o aviso).\n */\nexport const normalizeRemoteOperations = (\n value: boolean | GridRemoteOperations | null | undefined,\n): { flags: RemoteFlags; forced: string[] } => {\n if (!value) {\n return { flags: NO_REMOTE, forced: [] };\n }\n\n if (value === true) {\n return { flags: { filtering: true, sorting: true, paging: true, grouping: true, summary: true }, forced: [] };\n }\n\n const forced: string[] = [];\n const flags: RemoteFlags = {\n filtering: !!value.filtering,\n sorting: !!value.sorting,\n paging: !!value.paging,\n grouping: !!value.grouping,\n summary: !!value.summary,\n };\n\n const force = (name: keyof RemoteFlags) => {\n if (!flags[name]) {\n flags[name] = true;\n forced.push(name);\n }\n };\n\n if (flags.paging) {\n force('grouping');\n }\n\n if (flags.paging || flags.grouping) {\n force('filtering');\n force('sorting');\n force('summary');\n } else {\n flags.summary = false;\n }\n\n return { flags, forced };\n};\n\n/** Leitor da chave de linha: `keyExpr` ou, sem ela, o próprio item. */\nexport const keyReader = (keyExpr: GridKeyExpr | null | undefined): (item: unknown) => unknown => {\n if (typeof keyExpr === 'function') {\n return keyExpr as (item: unknown) => unknown;\n }\n\n if (typeof keyExpr === 'string' && keyExpr) {\n if (!keyExpr.includes('.')) {\n return item => item === null || item === undefined ? undefined : (item as Record<string, unknown>)[keyExpr];\n }\n\n return item => getValueByPath(item, keyExpr);\n }\n\n return item => item;\n};\n\n/** Texto da chave para o `key` das linhas renderizadas (`1` e `\"1\"` são chaves diferentes). */\nexport const keyText = (key: unknown): string =>\n typeof key === 'string' ? `s${key}` : typeof key === 'number' ? `n${key}` : `${typeof key}:${String(key)}`;\n\n/** Congela opções em profundidade (arrays e objetos simples). */\nexport const deepFreeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value) && !(value instanceof Date)) {\n Object.freeze(value);\n\n for (const entry of Object.values(value)) {\n deepFreeze(entry);\n }\n }\n\n return value;\n};\n"]}
|
|
1
|
+
{"version":3,"file":"data-source.js","sourceRoot":"","sources":["../../src/data/data-source.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAoKvD,MAAM,CAAC,MAAM,SAAS,GAAgB,MAAM,CAAC,MAAM,CAAC;IAClD,SAAS,EAAE,KAAK;IAChB,OAAO,EAAE,KAAK;IACd,MAAM,EAAE,KAAK;IACb,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,KAAK;CACf,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,CACvC,KAAwD,EACd,EAAE;IAC5C,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAC1C,CAAC;IAED,IAAI,KAAK,KAAK,IAAI,EAAE,CAAC;QACnB,OAAO,EAAE,KAAK,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAChH,CAAC;IAED,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,KAAK,GAAgB;QACzB,SAAS,EAAE,CAAC,CAAC,KAAK,CAAC,SAAS;QAC5B,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO;QACxB,MAAM,EAAE,CAAC,CAAC,KAAK,CAAC,MAAM;QACtB,QAAQ,EAAE,CAAC,CAAC,KAAK,CAAC,QAAQ;QAC1B,OAAO,EAAE,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,OAAO,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC;AACtB,CAAC,CAAC;AAEF,+FAA+F;AAC/F,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,GAAY,EAAU,EAAE,CAC9C,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,GAAG,OAAO,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC;AAE7G,iEAAiE;AACjE,MAAM,CAAC,MAAM,UAAU,GAAG,CAAI,KAAQ,EAAK,EAAE;IAC3C,IAAI,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,YAAY,IAAI,CAAC,EAAE,CAAC;QAC9F,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QAErB,KAAK,MAAM,KAAK,IAAI,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC;YACzC,UAAU,CAAC,KAAK,CAAC,CAAC;QACpB,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC,CAAC","sourcesContent":["import type {\n GridFilterExpression,\n GridGroupPath,\n GridSortOrder,\n GridSummaryType,\n} from '../grid-column-def.js';\nimport { getValueByPath } from '../row-model/value.js';\n\n/** Key of a row read by `keyExpr`. */\nexport type GridRowKey = string | number;\n\n/** `keyExpr` of `<u-grid>`: a property `path` (dots allowed) or a function that returns the key of an item. */\nexport type GridKeyExpr<TItem = any> = string | ((item: TItem) => GridRowKey);\n\n/** How rows scroll: `virtual` (all rows, rendered on demand) or `infinite` (the next block loads at the end; `dataSource` only). */\nexport type GridScrollMode = 'virtual' | 'infinite';\n\n/** A column of `GridLoadOptions.sort`. */\nexport interface GridLoadSort {\n /** Column `path`. */\n readonly path: string;\n /** Direction. */\n readonly order: GridSortOrder;\n}\n\n/** A grouping level of `GridLoadOptions.group`, outermost first. */\nexport interface GridLoadGroup {\n /** Column `path`. */\n readonly path: string;\n /** Order of the group keys. */\n readonly order: GridSortOrder;\n /** `false`: return only the keys, counts and summaries of the level (`items: null`). The grid always asks `false`. */\n readonly expanded: boolean;\n}\n\n/** A summary the server computes (`totalSummary`, `groupSummary`). */\nexport interface GridLoadSummary {\n /** Column `path`. */\n readonly path: string;\n /** Aggregate (custom aggregate functions are never sent). */\n readonly type: GridSummaryType;\n /** The `name` of the summary item, when it has one. */\n readonly name?: string;\n}\n\n/**\n * What the grid asks the data source. Frozen data: the host builds the\n * request from it — the grid never builds URLs or queries. `filter`,\n * `filterValue`, `searchText` and the paths come from the user and must be\n * validated by the server (allow-list of paths and operations).\n */\nexport interface GridLoadOptions {\n /** Rows to skip (absent = from the start). */\n readonly skip?: number;\n /** Rows to return (absent = all). */\n readonly take?: number;\n /** Sorting, in priority order (grouped columns included, with the direction of their groups). */\n readonly sort: readonly GridLoadSort[];\n /**\n * Column filter `and` search — the same as `getCombinedFilter()`; `null` without filter.\n * A condition refers to its column by `path` or, for a computed column (`valueGetter`\n * without `path`, filterable only with `filterable: true`), by `name`: translate it.\n */\n readonly filter: GridFilterExpression | null;\n /** Column filter only (the `filterValue` property; columns by `path` or `name`, as in `filter`). */\n readonly filterValue: GridFilterExpression | null;\n /** Raw search text (already part of `filter`), for servers with their own text search. */\n readonly searchText: string;\n /**\n * All grouping levels, outermost first (empty = not grouped). Return groups\n * (`GridLoadGroupResult[]`) of level `groupPath.length` while it is less than\n * `group.length`; items when it is equal.\n */\n readonly group: readonly GridLoadGroup[];\n /** Values of the open group, outermost first: only rows of that group (exact equality). `null` = all rows. */\n readonly groupPath: GridGroupPath | null;\n /** Return `totalCount`. */\n readonly requireTotalCount: boolean;\n /** Return `groupCount` (number of groups of the level). */\n readonly requireGroupCount: boolean;\n /** Summaries over all matching rows, returned in `GridLoadResult.summary` in this order. */\n readonly totalSummary: readonly GridLoadSummary[];\n /** Summaries of each returned group, in `GridLoadGroupResult.summary` in this order. */\n readonly groupSummary: readonly GridLoadSummary[];\n /** Tree data (`treeMode=\"flat\"`): which nodes to return; absent or `null` = a plain list. */\n readonly tree?: GridLoadTree | null;\n}\n\n/** `GridLoadOptions.tree`: what a tree asks the data source (items with their `parentKeyExpr`). */\nexport interface GridLoadTree {\n /**\n * Return the children of these nodes (`[rootParentKey]` = the root nodes;\n * keys as set — text when `root-parent-key` came from the attribute).\n * `null` = a remote filter is active: return the matching nodes AND all\n * their ancestors, at once.\n */\n readonly parentKeys: readonly (GridRowKey | null)[] | null;\n}\n\n/** A group returned when `GridLoadOptions.group` is not empty. */\nexport interface GridLoadGroupResult<TItem = any> {\n /** Group value. */\n key: unknown;\n /** Number of data rows in the group. */\n count: number;\n /** `null` (the grid always asks collapsed groups); items or subgroups are accepted and ignored. */\n items: readonly TItem[] | readonly GridLoadGroupResult<TItem>[] | null;\n /** Values of `groupSummary`, in its order. */\n summary?: readonly unknown[];\n}\n\n/** What `GridDataSource.load` resolves to. */\nexport interface GridLoadResult<TItem = any> {\n /** Items, or groups when `group` was not empty. */\n data: readonly TItem[] | readonly GridLoadGroupResult<TItem>[];\n /** Number of matching rows (when `requireTotalCount`). */\n totalCount?: number;\n /** Number of groups of the level (when `requireGroupCount`). */\n groupCount?: number;\n /** Values of `totalSummary`, in its order. */\n summary?: readonly unknown[];\n}\n\n/**\n * Data source of `<u-grid>`: the grid calls `load` and the host fetches the\n * data. `signal` aborts when the request is no longer needed (sorting,\n * filtering or grouping changed, `refresh()`, grid removed).\n */\nexport interface GridDataSource<TItem = any> {\n load(options: GridLoadOptions, signal: AbortSignal): Promise<GridLoadResult<TItem>>;\n}\n\n/**\n * Operations done by the server (`remoteOperations`). Remote `paging` or\n * `grouping` also turn on `filtering`, `sorting` and `summary`, and `paging`\n * turns on `grouping` (console warning); `summary` alone is ignored (the\n * grid has every row and computes it).\n */\nexport interface GridRemoteOperations {\n /** The server applies `filter` (or `filterValue` + `searchText`). */\n filtering?: boolean;\n /** The server applies `sort`. */\n sorting?: boolean;\n /** The server applies `skip`/`take` (rows load in blocks of `pageSize`). */\n paging?: boolean;\n /** The server returns groups (`group`, `groupPath`). */\n grouping?: boolean;\n /** The server computes `totalSummary`/`groupSummary` (with remote paging or grouping). */\n summary?: boolean;\n}\n\n/** Changes for `applyChanges()`: `update` and `remove` find rows by key (`keyExpr`). */\nexport interface GridDataChanges<TItem = any> {\n /** New items (appended to the loaded rows, or at their sorted place with `reshapeOnChanges`; with remote paging the rows reload). */\n add?: readonly TItem[];\n /** New versions of items (same key). */\n update?: readonly TItem[];\n /** Keys of the rows to remove. */\n remove?: readonly unknown[];\n}\n\n/** Operações remotas já normalizadas (dependências aplicadas). */\nexport interface RemoteFlags {\n filtering: boolean;\n sorting: boolean;\n paging: boolean;\n grouping: boolean;\n summary: boolean;\n}\n\nexport const NO_REMOTE: RemoteFlags = Object.freeze({\n filtering: false,\n sorting: false,\n paging: false,\n grouping: false,\n summary: false,\n});\n\n/**\n * Normaliza `remoteOperations`: paginação ou agrupamento no servidor exigem\n * filtrar e ordenar lá; paginar no servidor exige agrupar lá (os grupos\n * precisam de todas as linhas); resumo remoto só existe com paginação ou\n * agrupamento remotos (senão o grid tem todas as linhas e calcula).\n * `forced` lista o que foi ligado por dependência (para o aviso).\n */\nexport const normalizeRemoteOperations = (\n value: boolean | GridRemoteOperations | null | undefined,\n): { flags: RemoteFlags; forced: string[] } => {\n if (!value) {\n return { flags: NO_REMOTE, forced: [] };\n }\n\n if (value === true) {\n return { flags: { filtering: true, sorting: true, paging: true, grouping: true, summary: true }, forced: [] };\n }\n\n const forced: string[] = [];\n const flags: RemoteFlags = {\n filtering: !!value.filtering,\n sorting: !!value.sorting,\n paging: !!value.paging,\n grouping: !!value.grouping,\n summary: !!value.summary,\n };\n\n const force = (name: keyof RemoteFlags) => {\n if (!flags[name]) {\n flags[name] = true;\n forced.push(name);\n }\n };\n\n if (flags.paging) {\n force('grouping');\n }\n\n if (flags.paging || flags.grouping) {\n force('filtering');\n force('sorting');\n force('summary');\n } else {\n flags.summary = false;\n }\n\n return { flags, forced };\n};\n\n/** Leitor da chave de linha: `keyExpr` ou, sem ela, o próprio item. */\nexport const keyReader = (keyExpr: GridKeyExpr | null | undefined): (item: unknown) => unknown => {\n if (typeof keyExpr === 'function') {\n return keyExpr as (item: unknown) => unknown;\n }\n\n if (typeof keyExpr === 'string' && keyExpr) {\n if (!keyExpr.includes('.')) {\n return item => item === null || item === undefined ? undefined : (item as Record<string, unknown>)[keyExpr];\n }\n\n return item => getValueByPath(item, keyExpr);\n }\n\n return item => item;\n};\n\n/** Texto da chave para o `key` das linhas renderizadas (`1` e `\"1\"` são chaves diferentes). */\nexport const keyText = (key: unknown): string =>\n typeof key === 'string' ? `s${key}` : typeof key === 'number' ? `n${key}` : `${typeof key}:${String(key)}`;\n\n/** Congela opções em profundidade (arrays e objetos simples). */\nexport const deepFreeze = <T>(value: T): T => {\n if (value && typeof value === 'object' && !Object.isFrozen(value) && !(value instanceof Date)) {\n Object.freeze(value);\n\n for (const entry of Object.values(value)) {\n deepFreeze(entry);\n }\n }\n\n return value;\n};\n"]}
|
|
@@ -56,7 +56,8 @@ export interface GridXlsxDownloadOptions<TWorkbook = ExcelJSWorkbook, TWorksheet
|
|
|
56
56
|
* header, group rows with the row outline of Excel, group footers and
|
|
57
57
|
* totals. Numbers, dates and booleans are typed cells with a number format
|
|
58
58
|
* close to the column `format`; columns with `displayValue`, a `format`
|
|
59
|
-
* function
|
|
59
|
+
* function, `booleanDisplay` or their own `trueText`/`falseText` are written
|
|
60
|
+
* as their displayed text. Text is
|
|
60
61
|
* always a text cell (never a formula).
|
|
61
62
|
*/
|
|
62
63
|
export declare const exportXlsx: <M extends ExcelJSModule>(grid: DataGrid, excelJS: M, options?: GridXlsxOptions<WorkbookOf<M>, WorksheetOf<M>>) => Promise<Blob>;
|
|
@@ -19,7 +19,8 @@ const PX_PER_CHAR = 7;
|
|
|
19
19
|
* header, group rows with the row outline of Excel, group footers and
|
|
20
20
|
* totals. Numbers, dates and booleans are typed cells with a number format
|
|
21
21
|
* close to the column `format`; columns with `displayValue`, a `format`
|
|
22
|
-
* function
|
|
22
|
+
* function, `booleanDisplay` or their own `trueText`/`falseText` are written
|
|
23
|
+
* as their displayed text. Text is
|
|
23
24
|
* always a text cell (never a formula).
|
|
24
25
|
*/
|
|
25
26
|
export const exportXlsx = async (grid, excelJS, options = {}) => {
|
|
@@ -102,7 +103,8 @@ const writerOf = (column, language) => {
|
|
|
102
103
|
const definition = column.column;
|
|
103
104
|
const text = { write: (_, value) => textCell(value) };
|
|
104
105
|
// O texto depende do item ou é ícone/texto traduzido: grava o que a tela mostra.
|
|
105
|
-
|
|
106
|
+
const ownBooleanText = dataType === 'boolean' && (definition.booleanDisplay || definition.trueText || definition.falseText);
|
|
107
|
+
if (!dataType || dataType === 'string' || definition.displayValue || typeof definition.format === 'function' || ownBooleanText) {
|
|
106
108
|
return text;
|
|
107
109
|
}
|
|
108
110
|
const format = definition.format;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/export-xlsx/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAwD7D,MAAM,SAAS,GAAG,mEAAmE,CAAC;AAEtF,4CAA4C;AAC5C,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,2EAA2E;AAC3E,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,IAAc,EACd,OAAU,EACV,UAA0D,EAAE,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,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,UAAU,EAAE,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Adaptador opcional de Excel (frente 12): `@universal-material/data-grid/export-xlsx`.\n *\n * O grid NÃO depende do ExcelJS: o hospedeiro importa a biblioteca e a\n * injeta (`exportXlsx(grid, ExcelJS)`). Este módulo só usa a API pública do\n * grid (`getExportData`) e tipos estruturais mínimos do ExcelJS — os\n * genéricos devolvem ao hospedeiro os tipos reais do módulo que ele passou.\n */\nimport { downloadBlob } from '../export/download.js';\nimport type { GridExportColumn, GridExporter, GridExportOptions, GridExportRow } from '../export/types.js';\nimport type { DataGrid } from '../grid.js';\nimport { toDate, toNumber } from '../row-model/format.js';\nimport { datePatternOf, numberFormatOf } from './formats.js';\n\n/** The part of an ExcelJS cell the adapter writes. */\nexport interface ExcelJSCell {\n value: unknown;\n numFmt?: string;\n}\n\n/** The part of an ExcelJS row the adapter writes. */\nexport interface ExcelJSRow {\n outlineLevel?: number;\n font?: unknown;\n getCell(index: number): ExcelJSCell;\n}\n\n/** The part of an ExcelJS worksheet the adapter uses. */\nexport interface ExcelJSWorksheet {\n addRow(values: unknown[]): ExcelJSRow;\n getColumn(index: number): { width?: number };\n mergeCells(top: number, left: number, bottom: number, right: number): void;\n properties: { outlineLevelRow?: number };\n}\n\n/** The part of an ExcelJS workbook the adapter uses. */\nexport interface ExcelJSWorkbook {\n addWorksheet(name?: string): ExcelJSWorksheet;\n xlsx: { writeBuffer(): Promise<ArrayBuffer | ArrayBufferView> };\n}\n\n/** The ExcelJS module (`import ExcelJS from 'exceljs'`), injected by the host. */\nexport interface ExcelJSModule {\n Workbook: new () => ExcelJSWorkbook;\n}\n\n/** Workbook type of the injected module. */\nexport type WorkbookOf<M extends ExcelJSModule> = InstanceType<M['Workbook']>;\n\n/** Worksheet type of the injected module. */\nexport type WorksheetOf<M extends ExcelJSModule> = ReturnType<WorkbookOf<M>['addWorksheet']>;\n\n/** Options of `exportXlsx()`. */\nexport interface GridXlsxOptions<TWorkbook = ExcelJSWorkbook, TWorksheet = ExcelJSWorksheet> extends GridExportOptions {\n /** Worksheet name. Default `Sheet1`. */\n sheetName?: string;\n /** First row with the column labels (bold). Default `true`. */\n includeHeaders?: boolean;\n /** Called after the rows are written and before the file is built: style or add to the sheet. */\n customize?: ((worksheet: TWorksheet, workbook: TWorkbook) => void | Promise<void>) | null;\n}\n\n/** Options of `downloadXlsx()`. */\nexport interface GridXlsxDownloadOptions<TWorkbook = ExcelJSWorkbook, TWorksheet = ExcelJSWorksheet> extends GridXlsxOptions<TWorkbook, TWorksheet> {\n /** Name of the downloaded file. Default `export.xlsx`. */\n fileName?: string;\n}\n\nconst XLSX_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n\n/** Níveis de outline que o Excel aceita. */\nconst MAX_OUTLINE = 7;\n\n/** px → largura de coluna do Excel (caracteres do \"0\" na fonte padrão). */\nconst PX_PER_CHAR = 7;\n\n/**\n * The rows the user sees (`grid.getExportData(options)`) in an Excel file:\n * header, group rows with the row outline of Excel, group footers and\n * totals. Numbers, dates and booleans are typed cells with a number format\n * close to the column `format`; columns with `displayValue`, a `format`\n * function or `booleanDisplay` are written as their displayed text. Text is\n * always a text cell (never a formula).\n */\nexport const exportXlsx = async <M extends ExcelJSModule>(\n grid: DataGrid,\n excelJS: M,\n options: GridXlsxOptions<WorkbookOf<M>, WorksheetOf<M>> = {},\n): Promise<Blob> => {\n const data = await grid.getExportData(options);\n options.signal?.throwIfAborted();\n\n const workbook = new excelJS.Workbook() as WorkbookOf<M>;\n const worksheet = workbook.addWorksheet(options.sheetName || 'Sheet1') as WorksheetOf<M>;\n\n writeSheet(worksheet, data.columns, data.rows, grid.language, options.includeHeaders !== false);\n await options.customize?.(worksheet, workbook);\n options.signal?.throwIfAborted();\n\n const buffer = await workbook.xlsx.writeBuffer();\n\n return new Blob([buffer as BlobPart], { type: XLSX_TYPE });\n};\n\n/** Builds the file (`exportXlsx`) and downloads it as `fileName` (default `export.xlsx`). */\nexport const downloadXlsx = async <M extends ExcelJSModule>(\n grid: DataGrid,\n excelJS: M,\n options: GridXlsxDownloadOptions<WorkbookOf<M>, WorksheetOf<M>> = {},\n): Promise<void> => {\n downloadBlob(await exportXlsx(grid, excelJS, options), options.fileName || 'export.xlsx');\n};\n\n/** Options of `createXlsxExporter()`: those of `downloadXlsx` without `selectedOnly` and `signal` (set by the grid). */\nexport type GridXlsxExporterOptions<TWorkbook = ExcelJSWorkbook, TWorksheet = ExcelJSWorksheet> = Omit<GridXlsxDownloadOptions<TWorkbook, TWorksheet>, 'selectedOnly' | 'signal'>;\n\n/**\n * The Excel entry of the grid export UI: `grid.xlsxExporter =\n * createXlsxExporter(ExcelJS, options)` (with `export-formats=\"csv xlsx\"`).\n * The grid passes `selectedOnly` (\"Export selected rows\") and an\n * `AbortSignal` (aborted when it disconnects).\n */\nexport const createXlsxExporter = <M extends ExcelJSModule>(\n excelJS: M,\n options: GridXlsxExporterOptions<WorkbookOf<M>, WorksheetOf<M>> = {},\n): GridExporter => (grid, { selectedOnly, signal }) => downloadXlsx(grid, excelJS, { ...options, selectedOnly, signal });\n\n// ----------------------------------------------------------------- planilha\n\n/** Como gravar cada coluna: tipado (com `numFmt`) ou o texto exibido. */\ninterface CellWriter {\n write(value: unknown, text: string): unknown;\n numFmt?: string;\n}\n\nconst writeSheet = (\n worksheet: ExcelJSWorksheet,\n columns: readonly GridExportColumn[],\n rows: readonly GridExportRow[],\n language: string | undefined,\n headers: boolean,\n): void => {\n const writers = columns.map(column => writerOf(column, language));\n const count = Math.max(columns.length, 1);\n let index = 0;\n let outline = 0;\n\n const add = (values: unknown[], level = 0, bold = false): ExcelJSRow => {\n const row = worksheet.addRow(values);\n index++;\n\n if (level) {\n row.outlineLevel = Math.min(level, MAX_OUTLINE);\n outline = Math.max(outline, row.outlineLevel);\n }\n\n if (bold) {\n row.font = { bold: true };\n }\n\n return row;\n };\n\n if (headers) {\n add(columns.map(column => column.label), 0, true);\n }\n\n for (const row of rows) {\n switch (row.rowType) {\n case 'data': {\n const added = add(row.values.map((value, i) => writers[i].write(value, row.texts[i])), row.level);\n\n writers.forEach((writer, i) => {\n if (writer.numFmt && added.getCell(i + 1).value !== null) {\n added.getCell(i + 1).numFmt = writer.numFmt;\n }\n });\n break;\n }\n\n case 'group': {\n add([row.label, ...row.texts.slice(1).map(textCell)], row.level, true);\n\n // Rótulo mesclado sobre as colunas quando não há resumo alinhado (como o DevExtreme).\n if (count > 1 && row.texts.every(text => !text)) {\n worksheet.mergeCells(index, 1, index, count);\n }\n\n break;\n }\n\n default:\n add(row.texts.map(textCell), row.level, row.rowType === 'total');\n }\n }\n\n columns.forEach((column, i) => {\n if (column.width) {\n worksheet.getColumn(i + 1).width = Math.max(Math.round(column.width / PX_PER_CHAR), 4);\n }\n });\n\n if (outline) {\n worksheet.properties.outlineLevelRow = outline;\n }\n};\n\nconst textCell = (text: string): string | null => text === '' ? null : text;\n\nconst writerOf = (column: GridExportColumn, language: string | undefined): CellWriter => {\n const { dataType } = column;\n const definition = column.column;\n const text: CellWriter = { write: (_, value) => textCell(value) };\n\n // O texto depende do item ou é ícone/texto traduzido: grava o que a tela mostra.\n if (!dataType || dataType === 'string' || definition.displayValue || typeof definition.format === 'function' || (dataType === 'boolean' && definition.booleanDisplay)) {\n return text;\n }\n\n const format = definition.format;\n\n if (dataType === 'number') {\n return {\n numFmt: numberFormatOf(format, language),\n write: (value, shown) => {\n const numeric = toNumber(value);\n\n if (typeof numeric === 'bigint') {\n return Number.isSafeInteger(Number(numeric)) ? Number(numeric) : textCell(shown);\n }\n\n return numeric !== undefined && Number.isFinite(numeric) ? numeric : textCell(shown);\n },\n };\n }\n\n if (dataType === 'boolean') {\n return { write: (value, shown) => typeof value === 'boolean' ? value : textCell(shown) };\n }\n\n return {\n numFmt: datePatternOf(dataType, language),\n write: (value, shown) => {\n const date = toDate(value);\n return date ? excelDate(date) : textCell(shown);\n },\n };\n};\n\n/**\n * O ExcelJS grava a data pelo instante UTC; a planilha não tem fuso, então\n * passa a hora LOCAL como se fosse UTC (senão 00:00 em UTC-3 vira 03:00).\n */\nconst excelDate = (date: Date): Date =>\n new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));\n"]}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/export-xlsx/index.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAGrD,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAwD7D,MAAM,SAAS,GAAG,mEAAmE,CAAC;AAEtF,4CAA4C;AAC5C,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB,2EAA2E;AAC3E,MAAM,WAAW,GAAG,CAAC,CAAC;AAEtB;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,KAAK,EAC7B,IAAc,EACd,OAAU,EACV,UAA0D,EAAE,EAC7C,EAAE;IACjB,MAAM,IAAI,GAAG,MAAM,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;IAC/C,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,CAAC;IAEjC,MAAM,QAAQ,GAAG,IAAI,OAAO,CAAC,QAAQ,EAAmB,CAAC;IACzD,MAAM,SAAS,GAAG,QAAQ,CAAC,YAAY,CAAC,OAAO,CAAC,SAAS,IAAI,QAAQ,CAAmB,CAAC;IAEzF,UAAU,CAAC,SA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AAC,eAAe,EAAE,CAAC,CAAC,CAAC","sourcesContent":["/**\n * Adaptador opcional de Excel (frente 12): `@universal-material/data-grid/export-xlsx`.\n *\n * O grid NÃO depende do ExcelJS: o hospedeiro importa a biblioteca e a\n * injeta (`exportXlsx(grid, ExcelJS)`). Este módulo só usa a API pública do\n * grid (`getExportData`) e tipos estruturais mínimos do ExcelJS — os\n * genéricos devolvem ao hospedeiro os tipos reais do módulo que ele passou.\n */\nimport { downloadBlob } from '../export/download.js';\nimport type { GridExportColumn, GridExporter, GridExportOptions, GridExportRow } from '../export/types.js';\nimport type { DataGrid } from '../grid.js';\nimport { toDate, toNumber } from '../row-model/format.js';\nimport { datePatternOf, numberFormatOf } from './formats.js';\n\n/** The part of an ExcelJS cell the adapter writes. */\nexport interface ExcelJSCell {\n value: unknown;\n numFmt?: string;\n}\n\n/** The part of an ExcelJS row the adapter writes. */\nexport interface ExcelJSRow {\n outlineLevel?: number;\n font?: unknown;\n getCell(index: number): ExcelJSCell;\n}\n\n/** The part of an ExcelJS worksheet the adapter uses. */\nexport interface ExcelJSWorksheet {\n addRow(values: unknown[]): ExcelJSRow;\n getColumn(index: number): { width?: number };\n mergeCells(top: number, left: number, bottom: number, right: number): void;\n properties: { outlineLevelRow?: number };\n}\n\n/** The part of an ExcelJS workbook the adapter uses. */\nexport interface ExcelJSWorkbook {\n addWorksheet(name?: string): ExcelJSWorksheet;\n xlsx: { writeBuffer(): Promise<ArrayBuffer | ArrayBufferView> };\n}\n\n/** The ExcelJS module (`import ExcelJS from 'exceljs'`), injected by the host. */\nexport interface ExcelJSModule {\n Workbook: new () => ExcelJSWorkbook;\n}\n\n/** Workbook type of the injected module. */\nexport type WorkbookOf<M extends ExcelJSModule> = InstanceType<M['Workbook']>;\n\n/** Worksheet type of the injected module. */\nexport type WorksheetOf<M extends ExcelJSModule> = ReturnType<WorkbookOf<M>['addWorksheet']>;\n\n/** Options of `exportXlsx()`. */\nexport interface GridXlsxOptions<TWorkbook = ExcelJSWorkbook, TWorksheet = ExcelJSWorksheet> extends GridExportOptions {\n /** Worksheet name. Default `Sheet1`. */\n sheetName?: string;\n /** First row with the column labels (bold). Default `true`. */\n includeHeaders?: boolean;\n /** Called after the rows are written and before the file is built: style or add to the sheet. */\n customize?: ((worksheet: TWorksheet, workbook: TWorkbook) => void | Promise<void>) | null;\n}\n\n/** Options of `downloadXlsx()`. */\nexport interface GridXlsxDownloadOptions<TWorkbook = ExcelJSWorkbook, TWorksheet = ExcelJSWorksheet> extends GridXlsxOptions<TWorkbook, TWorksheet> {\n /** Name of the downloaded file. Default `export.xlsx`. */\n fileName?: string;\n}\n\nconst XLSX_TYPE = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';\n\n/** Níveis de outline que o Excel aceita. */\nconst MAX_OUTLINE = 7;\n\n/** px → largura de coluna do Excel (caracteres do \"0\" na fonte padrão). */\nconst PX_PER_CHAR = 7;\n\n/**\n * The rows the user sees (`grid.getExportData(options)`) in an Excel file:\n * header, group rows with the row outline of Excel, group footers and\n * totals. Numbers, dates and booleans are typed cells with a number format\n * close to the column `format`; columns with `displayValue`, a `format`\n * function, `booleanDisplay` or their own `trueText`/`falseText` are written\n * as their displayed text. Text is\n * always a text cell (never a formula).\n */\nexport const exportXlsx = async <M extends ExcelJSModule>(\n grid: DataGrid,\n excelJS: M,\n options: GridXlsxOptions<WorkbookOf<M>, WorksheetOf<M>> = {},\n): Promise<Blob> => {\n const data = await grid.getExportData(options);\n options.signal?.throwIfAborted();\n\n const workbook = new excelJS.Workbook() as WorkbookOf<M>;\n const worksheet = workbook.addWorksheet(options.sheetName || 'Sheet1') as WorksheetOf<M>;\n\n writeSheet(worksheet, data.columns, data.rows, grid.language, options.includeHeaders !== false);\n await options.customize?.(worksheet, workbook);\n options.signal?.throwIfAborted();\n\n const buffer = await workbook.xlsx.writeBuffer();\n\n return new Blob([buffer as BlobPart], { type: XLSX_TYPE });\n};\n\n/** Builds the file (`exportXlsx`) and downloads it as `fileName` (default `export.xlsx`). */\nexport const downloadXlsx = async <M extends ExcelJSModule>(\n grid: DataGrid,\n excelJS: M,\n options: GridXlsxDownloadOptions<WorkbookOf<M>, WorksheetOf<M>> = {},\n): Promise<void> => {\n downloadBlob(await exportXlsx(grid, excelJS, options), options.fileName || 'export.xlsx');\n};\n\n/** Options of `createXlsxExporter()`: those of `downloadXlsx` without `selectedOnly` and `signal` (set by the grid). */\nexport type GridXlsxExporterOptions<TWorkbook = ExcelJSWorkbook, TWorksheet = ExcelJSWorksheet> = Omit<GridXlsxDownloadOptions<TWorkbook, TWorksheet>, 'selectedOnly' | 'signal'>;\n\n/**\n * The Excel entry of the grid export UI: `grid.xlsxExporter =\n * createXlsxExporter(ExcelJS, options)` (with `export-formats=\"csv xlsx\"`).\n * The grid passes `selectedOnly` (\"Export selected rows\") and an\n * `AbortSignal` (aborted when it disconnects).\n */\nexport const createXlsxExporter = <M extends ExcelJSModule>(\n excelJS: M,\n options: GridXlsxExporterOptions<WorkbookOf<M>, WorksheetOf<M>> = {},\n): GridExporter => (grid, { selectedOnly, signal }) => downloadXlsx(grid, excelJS, { ...options, selectedOnly, signal });\n\n// ----------------------------------------------------------------- planilha\n\n/** Como gravar cada coluna: tipado (com `numFmt`) ou o texto exibido. */\ninterface CellWriter {\n write(value: unknown, text: string): unknown;\n numFmt?: string;\n}\n\nconst writeSheet = (\n worksheet: ExcelJSWorksheet,\n columns: readonly GridExportColumn[],\n rows: readonly GridExportRow[],\n language: string | undefined,\n headers: boolean,\n): void => {\n const writers = columns.map(column => writerOf(column, language));\n const count = Math.max(columns.length, 1);\n let index = 0;\n let outline = 0;\n\n const add = (values: unknown[], level = 0, bold = false): ExcelJSRow => {\n const row = worksheet.addRow(values);\n index++;\n\n if (level) {\n row.outlineLevel = Math.min(level, MAX_OUTLINE);\n outline = Math.max(outline, row.outlineLevel);\n }\n\n if (bold) {\n row.font = { bold: true };\n }\n\n return row;\n };\n\n if (headers) {\n add(columns.map(column => column.label), 0, true);\n }\n\n for (const row of rows) {\n switch (row.rowType) {\n case 'data': {\n const added = add(row.values.map((value, i) => writers[i].write(value, row.texts[i])), row.level);\n\n writers.forEach((writer, i) => {\n if (writer.numFmt && added.getCell(i + 1).value !== null) {\n added.getCell(i + 1).numFmt = writer.numFmt;\n }\n });\n break;\n }\n\n case 'group': {\n add([row.label, ...row.texts.slice(1).map(textCell)], row.level, true);\n\n // Rótulo mesclado sobre as colunas quando não há resumo alinhado (como o DevExtreme).\n if (count > 1 && row.texts.every(text => !text)) {\n worksheet.mergeCells(index, 1, index, count);\n }\n\n break;\n }\n\n default:\n add(row.texts.map(textCell), row.level, row.rowType === 'total');\n }\n }\n\n columns.forEach((column, i) => {\n if (column.width) {\n worksheet.getColumn(i + 1).width = Math.max(Math.round(column.width / PX_PER_CHAR), 4);\n }\n });\n\n if (outline) {\n worksheet.properties.outlineLevelRow = outline;\n }\n};\n\nconst textCell = (text: string): string | null => text === '' ? null : text;\n\nconst writerOf = (column: GridExportColumn, language: string | undefined): CellWriter => {\n const { dataType } = column;\n const definition = column.column;\n const text: CellWriter = { write: (_, value) => textCell(value) };\n\n // O texto depende do item ou é ícone/texto traduzido: grava o que a tela mostra.\n const ownBooleanText = dataType === 'boolean' && (definition.booleanDisplay || definition.trueText || definition.falseText);\n\n if (!dataType || dataType === 'string' || definition.displayValue || typeof definition.format === 'function' || ownBooleanText) {\n return text;\n }\n\n const format = definition.format;\n\n if (dataType === 'number') {\n return {\n numFmt: numberFormatOf(format, language),\n write: (value, shown) => {\n const numeric = toNumber(value);\n\n if (typeof numeric === 'bigint') {\n return Number.isSafeInteger(Number(numeric)) ? Number(numeric) : textCell(shown);\n }\n\n return numeric !== undefined && Number.isFinite(numeric) ? numeric : textCell(shown);\n },\n };\n }\n\n if (dataType === 'boolean') {\n return { write: (value, shown) => typeof value === 'boolean' ? value : textCell(shown) };\n }\n\n return {\n numFmt: datePatternOf(dataType, language),\n write: (value, shown) => {\n const date = toDate(value);\n return date ? excelDate(date) : textCell(shown);\n },\n };\n};\n\n/**\n * O ExcelJS grava a data pelo instante UTC; a planilha não tem fuso, então\n * passa a hora LOCAL como se fosse UTC (senão 00:00 em UTC-3 vira 03:00).\n */\nconst excelDate = (date: Date): Date =>\n new Date(Date.UTC(date.getFullYear(), date.getMonth(), date.getDate(), date.getHours(), date.getMinutes(), date.getSeconds(), date.getMilliseconds()));\n"]}
|
|
@@ -31,7 +31,7 @@ const dragHandle = html `
|
|
|
31
31
|
<circle cx="9" cy="6" r="1.6"/><circle cx="15" cy="6" r="1.6"/><circle cx="9" cy="12" r="1.6"/><circle cx="15" cy="12" r="1.6"/><circle cx="9" cy="18" r="1.6"/><circle cx="15" cy="18" r="1.6"/>
|
|
32
32
|
</svg>`;
|
|
33
33
|
export const columnChooserIcon = html `
|
|
34
|
-
<svg xmlns="http://www.w3.org/2000/svg" height="
|
|
34
|
+
<svg xmlns="http://www.w3.org/2000/svg" height="24" width="24" viewBox="0 0 24 24" fill="currentColor" fill-rule="evenodd" aria-hidden="true">
|
|
35
35
|
<path d="M3 5h18v14H3zM5 7v10h3.5V7zm5.5 0v10h3V7zm5 0v10H19V7z"/>
|
|
36
36
|
</svg>`;
|
|
37
37
|
const REORDER_HINT_ID = 'column-chooser-reorder-hint';
|