@fusion.dev/helix-headless 0.238.1 → 0.240.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/api.json +1 -1
- package/custom-elements.json +1 -1
- package/dist/column-manager/index.d.ts +1 -0
- package/dist/column-manager/index.js +1 -0
- package/dist/column-manager/root/column-manager-root.d.ts +137 -0
- package/dist/column-manager/root/column-manager-root.js +253 -0
- package/dist/data-table/binding.d.ts +85 -0
- package/dist/data-table/binding.js +58 -0
- package/dist/data-table/edit.d.ts +47 -0
- package/dist/data-table/edit.js +60 -0
- package/dist/data-table/events/before-cell-commit.d.ts +16 -0
- package/dist/data-table/events/before-cell-commit.js +11 -0
- package/dist/data-table/events/before-cell-edit.d.ts +13 -0
- package/dist/data-table/events/before-cell-edit.js +11 -0
- package/dist/data-table/events/before-export.d.ts +15 -0
- package/dist/data-table/events/before-export.js +11 -0
- package/dist/data-table/events/before-view-change.d.ts +16 -0
- package/dist/data-table/events/before-view-change.js +11 -0
- package/dist/data-table/events/cell-commit.d.ts +12 -0
- package/dist/data-table/events/cell-commit.js +11 -0
- package/dist/data-table/events/cell-edit.d.ts +11 -0
- package/dist/data-table/events/cell-edit.js +11 -0
- package/dist/data-table/events/details.d.ts +47 -0
- package/dist/data-table/events/export.d.ts +11 -0
- package/dist/data-table/events/export.js +11 -0
- package/dist/data-table/events/index.d.ts +18 -2
- package/dist/data-table/events/index.js +17 -1
- package/dist/data-table/events/view-change.d.ts +12 -0
- package/dist/data-table/events/view-change.js +11 -0
- package/dist/data-table/export.d.ts +43 -0
- package/dist/data-table/export.js +26 -0
- package/dist/data-table/index.d.ts +2 -0
- package/dist/data-table/index.js +2 -0
- package/dist/data-table/root/data-table-root.d.ts +406 -26
- package/dist/data-table/root/data-table-root.js +959 -30
- package/dist/data-table/view.d.ts +124 -0
- package/dist/data-table/view.js +249 -0
- package/dist/data-table/xlsx/index.d.ts +27 -0
- package/dist/data-table/xlsx/index.js +119 -0
- package/dist/date-input/root/date-input-root.d.ts +7 -0
- package/dist/date-input/root/date-input-root.js +9 -1
- package/dist/editor/root/editor-root.d.ts +106 -7
- package/dist/editor/root/editor-root.js +273 -50
- package/dist/element-events.generated.js +9 -0
- package/dist/filter-input/root/filter-input-root.d.ts +31 -0
- package/dist/filter-input/root/filter-input-root.js +94 -12
- package/dist/filter-input/table.d.ts +64 -0
- package/dist/filter-input/table.js +76 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/input/root/input-root.d.ts +7 -0
- package/dist/input/root/input-root.js +9 -1
- package/dist/navigation/root/navigation-root.d.ts +115 -1
- package/dist/navigation/root/navigation-root.js +220 -8
- package/dist/number-input/root/number-input-root.d.ts +7 -0
- package/dist/number-input/root/number-input-root.js +9 -1
- package/dist/quick-filters/events/before-view-save.d.ts +14 -0
- package/dist/quick-filters/events/before-view-save.js +11 -0
- package/dist/quick-filters/events/details.d.ts +10 -0
- package/dist/quick-filters/events/details.js +1 -0
- package/dist/quick-filters/events/index.d.ts +16 -0
- package/dist/quick-filters/events/index.js +9 -0
- package/dist/quick-filters/events/view-save.d.ts +11 -0
- package/dist/quick-filters/events/view-save.js +11 -0
- package/dist/quick-filters/filter/quick-filter.d.ts +48 -0
- package/dist/quick-filters/filter/quick-filter.js +33 -0
- package/dist/quick-filters/index.d.ts +3 -0
- package/dist/quick-filters/index.js +3 -0
- package/dist/quick-filters/root/quick-filters-root.d.ts +118 -0
- package/dist/quick-filters/root/quick-filters-root.js +183 -0
- package/dist/selection-bar/index.d.ts +1 -0
- package/dist/selection-bar/index.js +1 -0
- package/dist/selection-bar/root/selection-bar-root.d.ts +65 -0
- package/dist/selection-bar/root/selection-bar-root.js +44 -0
- package/dist/table/column/table-column.d.ts +82 -0
- package/dist/table/column/table-column.js +54 -0
- package/dist/table/column-type.d.ts +7 -0
- package/dist/table/column-type.js +1 -0
- package/dist/table-export/index.d.ts +1 -0
- package/dist/table-export/index.js +1 -0
- package/dist/table-export/root/table-export-root.d.ts +132 -0
- package/dist/table-export/root/table-export-root.js +233 -0
- package/dist/view-panel/index.d.ts +1 -0
- package/dist/view-panel/index.js +1 -0
- package/dist/view-panel/root/view-panel-root.d.ts +132 -0
- package/dist/view-panel/root/view-panel-root.js +209 -0
- package/examples.json +1 -1
- package/lint.json +1 -1
- package/package.json +5 -5
- package/types/jsx.d.ts +1353 -10
- package/types/svelte.d.ts +6 -0
- package/types/vue.d.ts +651 -6
- package/types/words.d.ts +325 -5
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { CellEditDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* A reader asked to edit a cell, with Enter, F2, a double click, or by typing.
|
|
4
|
+
*
|
|
5
|
+
* Cancelable: cancel it to keep the cell as it is, such as for a row that is
|
|
6
|
+
* locked on your server.
|
|
7
|
+
*
|
|
8
|
+
* @followedBy helix-cell-edit
|
|
9
|
+
*/
|
|
10
|
+
export declare class HelixBeforeCellEditEvent extends CustomEvent<CellEditDetail> {
|
|
11
|
+
static readonly eventName = "helix-before-cell-edit";
|
|
12
|
+
constructor(detail: CellEditDetail);
|
|
13
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class HelixBeforeCellEditEvent extends CustomEvent {
|
|
2
|
+
static { this.eventName = 'helix-before-cell-edit'; }
|
|
3
|
+
constructor(detail) {
|
|
4
|
+
super(HelixBeforeCellEditEvent.eventName, {
|
|
5
|
+
bubbles: true,
|
|
6
|
+
cancelable: true,
|
|
7
|
+
composed: true,
|
|
8
|
+
detail,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { ExportDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* A reader asked for a file of the table's rows, or a script called
|
|
4
|
+
* `download`.
|
|
5
|
+
*
|
|
6
|
+
* Cancelable: cancel it to make the file on your server, from the view and
|
|
7
|
+
* the choices in `detail`, as a table in `server` mode has to, since it holds
|
|
8
|
+
* one page. Left alone, the table makes the file and the browser saves it.
|
|
9
|
+
*
|
|
10
|
+
* @followedBy helix-export
|
|
11
|
+
*/
|
|
12
|
+
export declare class HelixBeforeExportEvent extends CustomEvent<ExportDetail> {
|
|
13
|
+
static readonly eventName = "helix-before-export";
|
|
14
|
+
constructor(detail: ExportDetail);
|
|
15
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class HelixBeforeExportEvent extends CustomEvent {
|
|
2
|
+
static { this.eventName = 'helix-before-export'; }
|
|
3
|
+
constructor(detail) {
|
|
4
|
+
super(HelixBeforeExportEvent.eventName, {
|
|
5
|
+
bubbles: true,
|
|
6
|
+
cancelable: true,
|
|
7
|
+
composed: true,
|
|
8
|
+
detail,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { ViewChangeDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* The table's view is about to change: the search, a filter, the sort, the
|
|
4
|
+
* columns or the page size.
|
|
5
|
+
*
|
|
6
|
+
* Sent before the event for the one part that changes, such as
|
|
7
|
+
* `helix-before-sort`, and for a call to `requestView`. Cancelable: cancel it
|
|
8
|
+
* to keep the view as it is, fetch the rows for `detail.view` from a server,
|
|
9
|
+
* and set `view`, `rows` and `total` yourself.
|
|
10
|
+
*
|
|
11
|
+
* @followedBy helix-view-change
|
|
12
|
+
*/
|
|
13
|
+
export declare class HelixBeforeViewChangeEvent extends CustomEvent<ViewChangeDetail> {
|
|
14
|
+
static readonly eventName = "helix-before-view-change";
|
|
15
|
+
constructor(detail: ViewChangeDetail);
|
|
16
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export class HelixBeforeViewChangeEvent extends CustomEvent {
|
|
2
|
+
static { this.eventName = 'helix-before-view-change'; }
|
|
3
|
+
constructor(detail) {
|
|
4
|
+
super(HelixBeforeViewChangeEvent.eventName, {
|
|
5
|
+
bubbles: true,
|
|
6
|
+
cancelable: true,
|
|
7
|
+
composed: true,
|
|
8
|
+
detail,
|
|
9
|
+
});
|
|
10
|
+
}
|
|
11
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { CellCommitDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* A cell's new value was saved into its row.
|
|
4
|
+
*
|
|
5
|
+
* The notification after `helix-before-cell-commit`, sent when nobody refused
|
|
6
|
+
* it and every check passed. `rows` already holds a copy of the row with the
|
|
7
|
+
* new value. Not cancelable: the decision was the request's.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HelixCellCommitEvent extends CustomEvent<CellCommitDetail> {
|
|
10
|
+
static readonly eventName = "helix-cell-commit";
|
|
11
|
+
constructor(detail: CellCommitDetail);
|
|
12
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CellEditDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* A cell opened for an edit.
|
|
4
|
+
*
|
|
5
|
+
* The notification after `helix-before-cell-edit`, sent when nobody refused
|
|
6
|
+
* it. Not cancelable: the decision was the request's.
|
|
7
|
+
*/
|
|
8
|
+
export declare class HelixCellEditEvent extends CustomEvent<CellEditDetail> {
|
|
9
|
+
static readonly eventName = "helix-cell-edit";
|
|
10
|
+
constructor(detail: CellEditDetail);
|
|
11
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { DataTableView } from '../view.js';
|
|
1
2
|
/** Detail carried by `helix-before-column-toggle` and `helix-column-toggle`. */
|
|
2
3
|
export interface ColumnToggleDetail {
|
|
3
4
|
/** The `field` of the column. */
|
|
@@ -10,3 +11,49 @@ export interface FollowDetail {
|
|
|
10
11
|
/** The path, query, and hash the link names, ready for a router. */
|
|
11
12
|
href: string;
|
|
12
13
|
}
|
|
14
|
+
/** Detail carried by `helix-before-view-change` and `helix-view-change`. */
|
|
15
|
+
export interface ViewChangeDetail {
|
|
16
|
+
/** The whole view after the change, as JSON. */
|
|
17
|
+
value: string;
|
|
18
|
+
/** The whole view after the change. */
|
|
19
|
+
view: DataTableView;
|
|
20
|
+
}
|
|
21
|
+
/** Detail carried by `helix-before-export` and `helix-export`. */
|
|
22
|
+
export interface ExportDetail {
|
|
23
|
+
/** Which columns go in: the `visible` ones or `all`. */
|
|
24
|
+
columns: 'all' | 'visible';
|
|
25
|
+
/** How many rows go in. */
|
|
26
|
+
count: number;
|
|
27
|
+
/** The name the file is saved under, such as `invoices.csv`. */
|
|
28
|
+
filename: string;
|
|
29
|
+
/** The kind of file. */
|
|
30
|
+
format: 'csv' | 'json' | 'tsv' | 'xlsx';
|
|
31
|
+
/** Which rows go in: the `selected` ones, the `filtered` ones, or `all`. */
|
|
32
|
+
rows: 'all' | 'filtered' | 'selected';
|
|
33
|
+
/** Whether the values are written as the cells show them or as the rows hold them. */
|
|
34
|
+
values: 'raw' | 'shown';
|
|
35
|
+
/** The table's whole view, which a server reads to make the same rows. */
|
|
36
|
+
view: DataTableView;
|
|
37
|
+
}
|
|
38
|
+
/** Detail carried by `helix-before-cell-edit`. */
|
|
39
|
+
export interface CellEditDetail {
|
|
40
|
+
/** The column's `field`. */
|
|
41
|
+
field: string;
|
|
42
|
+
/** The row's key: its `row-key` value, or its place in the result. */
|
|
43
|
+
key: string;
|
|
44
|
+
/** The row. */
|
|
45
|
+
row: Readonly<Record<string, unknown>>;
|
|
46
|
+
/** The value the cell holds now. */
|
|
47
|
+
value: unknown;
|
|
48
|
+
}
|
|
49
|
+
/** Detail carried by `helix-before-cell-commit` and `helix-cell-commit`. */
|
|
50
|
+
export interface CellCommitDetail extends CellEditDetail {
|
|
51
|
+
/** The value the cell held before the edit. */
|
|
52
|
+
previous: unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Holds the save until a promise settles, such as a check on your server.
|
|
55
|
+
* Resolve it to a message to refuse the value with that message, and the
|
|
56
|
+
* cell stays open on it. Only on `helix-before-cell-commit`.
|
|
57
|
+
*/
|
|
58
|
+
waitUntil: (check: PromiseLike<string | undefined | void>) => void;
|
|
59
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExportDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* The table made a file of its rows, and the browser is saving it.
|
|
4
|
+
*
|
|
5
|
+
* The notification after `helix-before-export`, sent when nobody refused it.
|
|
6
|
+
* Not cancelable: the decision was the request's.
|
|
7
|
+
*/
|
|
8
|
+
export declare class HelixExportEvent extends CustomEvent<ExportDetail> {
|
|
9
|
+
static readonly eventName = "helix-export";
|
|
10
|
+
constructor(detail: ExportDetail);
|
|
11
|
+
}
|
|
@@ -1,14 +1,30 @@
|
|
|
1
|
+
import { HelixBeforeCellCommitEvent } from './before-cell-commit.js';
|
|
2
|
+
import { HelixBeforeCellEditEvent } from './before-cell-edit.js';
|
|
1
3
|
import { HelixBeforeColumnToggleEvent } from './before-column-toggle.js';
|
|
4
|
+
import { HelixBeforeExportEvent } from './before-export.js';
|
|
2
5
|
import { HelixBeforeFollowEvent } from './before-follow.js';
|
|
6
|
+
import { HelixBeforeViewChangeEvent } from './before-view-change.js';
|
|
7
|
+
import { HelixCellCommitEvent } from './cell-commit.js';
|
|
8
|
+
import { HelixCellEditEvent } from './cell-edit.js';
|
|
3
9
|
import { HelixColumnToggleEvent } from './column-toggle.js';
|
|
10
|
+
import { HelixExportEvent } from './export.js';
|
|
4
11
|
import { HelixFollowEvent } from './follow.js';
|
|
5
|
-
|
|
6
|
-
export {
|
|
12
|
+
import { HelixViewChangeEvent } from './view-change.js';
|
|
13
|
+
export type { CellCommitDetail, CellEditDetail, ColumnToggleDetail, ExportDetail, FollowDetail, ViewChangeDetail, } from './details.js';
|
|
14
|
+
export { HelixBeforeCellCommitEvent, HelixBeforeCellEditEvent, HelixBeforeColumnToggleEvent, HelixBeforeExportEvent, HelixBeforeFollowEvent, HelixBeforeViewChangeEvent, HelixCellCommitEvent, HelixCellEditEvent, HelixColumnToggleEvent, HelixExportEvent, HelixFollowEvent, HelixViewChangeEvent, };
|
|
7
15
|
declare const registry: {
|
|
16
|
+
readonly HelixBeforeCellCommitEvent: typeof HelixBeforeCellCommitEvent;
|
|
17
|
+
readonly HelixBeforeCellEditEvent: typeof HelixBeforeCellEditEvent;
|
|
8
18
|
readonly HelixBeforeColumnToggleEvent: typeof HelixBeforeColumnToggleEvent;
|
|
19
|
+
readonly HelixBeforeExportEvent: typeof HelixBeforeExportEvent;
|
|
9
20
|
readonly HelixBeforeFollowEvent: typeof HelixBeforeFollowEvent;
|
|
21
|
+
readonly HelixBeforeViewChangeEvent: typeof HelixBeforeViewChangeEvent;
|
|
22
|
+
readonly HelixCellCommitEvent: typeof HelixCellCommitEvent;
|
|
23
|
+
readonly HelixCellEditEvent: typeof HelixCellEditEvent;
|
|
10
24
|
readonly HelixColumnToggleEvent: typeof HelixColumnToggleEvent;
|
|
25
|
+
readonly HelixExportEvent: typeof HelixExportEvent;
|
|
11
26
|
readonly HelixFollowEvent: typeof HelixFollowEvent;
|
|
27
|
+
readonly HelixViewChangeEvent: typeof HelixViewChangeEvent;
|
|
12
28
|
};
|
|
13
29
|
type Registry = typeof registry;
|
|
14
30
|
type DataTableEventMap = {
|
|
@@ -1,13 +1,29 @@
|
|
|
1
1
|
import { registerEventNames } from '@fusion.dev/helix-core';
|
|
2
|
+
import { HelixBeforeCellCommitEvent } from './before-cell-commit.js';
|
|
3
|
+
import { HelixBeforeCellEditEvent } from './before-cell-edit.js';
|
|
2
4
|
import { HelixBeforeColumnToggleEvent } from './before-column-toggle.js';
|
|
5
|
+
import { HelixBeforeExportEvent } from './before-export.js';
|
|
3
6
|
import { HelixBeforeFollowEvent } from './before-follow.js';
|
|
7
|
+
import { HelixBeforeViewChangeEvent } from './before-view-change.js';
|
|
8
|
+
import { HelixCellCommitEvent } from './cell-commit.js';
|
|
9
|
+
import { HelixCellEditEvent } from './cell-edit.js';
|
|
4
10
|
import { HelixColumnToggleEvent } from './column-toggle.js';
|
|
11
|
+
import { HelixExportEvent } from './export.js';
|
|
5
12
|
import { HelixFollowEvent } from './follow.js';
|
|
6
|
-
|
|
13
|
+
import { HelixViewChangeEvent } from './view-change.js';
|
|
14
|
+
export { HelixBeforeCellCommitEvent, HelixBeforeCellEditEvent, HelixBeforeColumnToggleEvent, HelixBeforeExportEvent, HelixBeforeFollowEvent, HelixBeforeViewChangeEvent, HelixCellCommitEvent, HelixCellEditEvent, HelixColumnToggleEvent, HelixExportEvent, HelixFollowEvent, HelixViewChangeEvent, };
|
|
7
15
|
const registry = {
|
|
16
|
+
HelixBeforeCellCommitEvent,
|
|
17
|
+
HelixBeforeCellEditEvent,
|
|
8
18
|
HelixBeforeColumnToggleEvent,
|
|
19
|
+
HelixBeforeExportEvent,
|
|
9
20
|
HelixBeforeFollowEvent,
|
|
21
|
+
HelixBeforeViewChangeEvent,
|
|
22
|
+
HelixCellCommitEvent,
|
|
23
|
+
HelixCellEditEvent,
|
|
10
24
|
HelixColumnToggleEvent,
|
|
25
|
+
HelixExportEvent,
|
|
11
26
|
HelixFollowEvent,
|
|
27
|
+
HelixViewChangeEvent,
|
|
12
28
|
};
|
|
13
29
|
registerEventNames(Object.values(registry).map((one) => one.eventName));
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ViewChangeDetail } from './details.js';
|
|
2
|
+
/**
|
|
3
|
+
* The table's view changed.
|
|
4
|
+
*
|
|
5
|
+
* The notification after `helix-before-view-change`, sent when nobody refused
|
|
6
|
+
* it, with the view now in force. Not cancelable: the decision was the
|
|
7
|
+
* request's.
|
|
8
|
+
*/
|
|
9
|
+
export declare class HelixViewChangeEvent extends CustomEvent<ViewChangeDetail> {
|
|
10
|
+
static readonly eventName = "helix-view-change";
|
|
11
|
+
constructor(detail: ViewChangeDetail);
|
|
12
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Writing a Data Table's rows out as text: CSV, TSV, or JSON.
|
|
3
|
+
*
|
|
4
|
+
* String handling with no DOM in it, so the pure spec covers it directly. The
|
|
5
|
+
* table decides which rows, columns, and values go in, and this writes them.
|
|
6
|
+
*/
|
|
7
|
+
/** Which rows an export holds. */
|
|
8
|
+
export type ExportRows = 'all' | 'filtered' | 'selected';
|
|
9
|
+
/** Which columns an export holds. */
|
|
10
|
+
export type ExportColumns = 'all' | 'visible';
|
|
11
|
+
/** Whether an export holds the values as the cells show them, or the values in the rows. */
|
|
12
|
+
export type ExportValues = 'raw' | 'shown';
|
|
13
|
+
/** The kind of file an export writes. `xlsx` needs the `data-table/xlsx` entry. */
|
|
14
|
+
export type ExportFormat = 'csv' | 'json' | 'tsv' | 'xlsx';
|
|
15
|
+
/** What to export. Each part left out takes its default: the filtered rows, the visible columns, the values as shown, and CSV. */
|
|
16
|
+
export interface ExportOptions {
|
|
17
|
+
columns?: ExportColumns | undefined;
|
|
18
|
+
format?: ExportFormat | undefined;
|
|
19
|
+
rows?: ExportRows | undefined;
|
|
20
|
+
values?: ExportValues | undefined;
|
|
21
|
+
}
|
|
22
|
+
/** The rows and columns an export holds, before they are written. */
|
|
23
|
+
export interface ExportData {
|
|
24
|
+
/** Each column's field, in order. */
|
|
25
|
+
fields: string[];
|
|
26
|
+
/** Each column's heading, in order. */
|
|
27
|
+
headings: string[];
|
|
28
|
+
/** Each row's values, in the columns' order. */
|
|
29
|
+
rows: unknown[][];
|
|
30
|
+
}
|
|
31
|
+
/** The type a file of each format is served as. */
|
|
32
|
+
export declare const EXPORT_TYPES: Record<ExportFormat, string>;
|
|
33
|
+
/**
|
|
34
|
+
* A text value a spreadsheet would run as a formula, quoted as text.
|
|
35
|
+
*
|
|
36
|
+
* A cell opening with `=`, `+`, `-` or `@` is a formula to a spreadsheet, and a
|
|
37
|
+
* result is often something a reader did not write, so those values gain a
|
|
38
|
+
* leading apostrophe, the mark spreadsheets read as text. Numbers are left
|
|
39
|
+
* alone, so a negative one stays a number.
|
|
40
|
+
*/
|
|
41
|
+
export declare const guardFormula: (value: unknown) => string;
|
|
42
|
+
/** Writes the rows as CSV, TSV, or JSON. JSON is an array of objects keyed by field. */
|
|
43
|
+
export declare const exportText: (data: ExportData, format: Exclude<ExportFormat, 'xlsx'>) => string;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const EXPORT_TYPES = {
|
|
2
|
+
csv: 'text/csv',
|
|
3
|
+
json: 'application/json',
|
|
4
|
+
tsv: 'text/tab-separated-values',
|
|
5
|
+
xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
6
|
+
};
|
|
7
|
+
export const guardFormula = (value) => {
|
|
8
|
+
if (value === undefined || value === null) {
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
const text = value instanceof Date ? value.toISOString() : String(value);
|
|
12
|
+
return typeof value === 'string' && /^[=+\-@\t\r]/.test(text) ? `'${text}` : text;
|
|
13
|
+
};
|
|
14
|
+
const csvCell = (value) => {
|
|
15
|
+
const text = guardFormula(value);
|
|
16
|
+
return /[",\r\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
17
|
+
};
|
|
18
|
+
const tsvCell = (value) => guardFormula(value).replace(/[\t\r\n]+/g, ' ');
|
|
19
|
+
export const exportText = (data, format) => {
|
|
20
|
+
if (format === 'json') {
|
|
21
|
+
return JSON.stringify(data.rows.map((row) => Object.fromEntries(data.fields.map((field, at) => [field, row[at] ?? null]))), null, 2);
|
|
22
|
+
}
|
|
23
|
+
const cell = format === 'tsv' ? tsvCell : csvCell;
|
|
24
|
+
const separator = format === 'tsv' ? '\t' : ',';
|
|
25
|
+
return [data.headings, ...data.rows].map((line) => line.map(cell).join(separator)).join('\r\n');
|
|
26
|
+
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
export { type Axis, cycle, type DataRow, filter, format, ordered, parse, type Sort, sort, window_, } from '@fusion.dev/helix-core';
|
|
2
2
|
export * from './events/index.js';
|
|
3
|
+
export * from './export.js';
|
|
3
4
|
export { HelixHeadlessDataTable } from './root/data-table-root.js';
|
|
5
|
+
export * from './view.js';
|
package/dist/data-table/index.js
CHANGED