@guiexpert/svelte-table 4.1.84 → 5.1.86
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/ComponentRendererWrapper.d.ts +8 -2
- package/ComponentRendererWrapper.js +35 -0
- package/GuiexpertTable.svelte +102 -0
- package/GuiexpertTable.svelte.d.ts +53 -1
- package/LICENSE +21 -0
- package/README.md +29 -4
- package/index.d.ts +3 -2
- package/index.js +2 -5061
- package/package.json +19 -7
- package/index.cjs +0 -40
|
@@ -1,5 +1,11 @@
|
|
|
1
|
-
import { AreaIdent, AreaModelIf, CellRendererIf, DomServiceIf, RendererCleanupFnType } from
|
|
2
|
-
|
|
1
|
+
import { AreaIdent, AreaModelIf, CellRendererIf, DomServiceIf, RendererCleanupFnType } from "@guiexpert/table";
|
|
2
|
+
/**
|
|
3
|
+
* Renders a Svelte component into a table cell (Svelte 4 and 5).
|
|
4
|
+
* The component receives the props `cellDiv`, `rowIndex`, `columnIndex`, `areaIdent`, `areaModel` and `cellValue`.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* applyBodyRenderer(columnDefs[2], new ComponentRendererWrapper(GenderRendererComponent));
|
|
8
|
+
*/
|
|
3
9
|
export declare class ComponentRendererWrapper implements CellRendererIf {
|
|
4
10
|
private readonly Component;
|
|
5
11
|
constructor(Component: any);
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import * as svelte from "svelte";
|
|
2
|
+
// Svelte 5 exports mount()/unmount(); Svelte 4 components are classes (new Component(...), $destroy()).
|
|
3
|
+
const svelteApi = svelte;
|
|
4
|
+
const mount = svelteApi["mount"];
|
|
5
|
+
const unmount = svelteApi["unmount"];
|
|
6
|
+
/**
|
|
7
|
+
* Renders a Svelte component into a table cell (Svelte 4 and 5).
|
|
8
|
+
* The component receives the props `cellDiv`, `rowIndex`, `columnIndex`, `areaIdent`, `areaModel` and `cellValue`.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* applyBodyRenderer(columnDefs[2], new ComponentRendererWrapper(GenderRendererComponent));
|
|
12
|
+
*/
|
|
13
|
+
export class ComponentRendererWrapper {
|
|
14
|
+
constructor(Component) {
|
|
15
|
+
this.Component = Component;
|
|
16
|
+
}
|
|
17
|
+
render(cellDiv, rowIndex, columnIndex, areaIdent, areaModel, cellValue, _domService) {
|
|
18
|
+
const props = {
|
|
19
|
+
cellDiv,
|
|
20
|
+
rowIndex,
|
|
21
|
+
columnIndex,
|
|
22
|
+
areaIdent,
|
|
23
|
+
areaModel,
|
|
24
|
+
cellValue
|
|
25
|
+
};
|
|
26
|
+
if (typeof mount === "function" && typeof unmount === "function") {
|
|
27
|
+
const instance = mount(this.Component, { target: cellDiv, props });
|
|
28
|
+
return () => unmount(instance);
|
|
29
|
+
}
|
|
30
|
+
const c = new this.Component({ target: cellDiv, props });
|
|
31
|
+
return () => {
|
|
32
|
+
c.$destroy();
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
<!--
|
|
2
|
+
GuiexpertTable – Svelte wrapper of @guiexpert/table.
|
|
3
|
+
|
|
4
|
+
Shipped as Svelte source (not pre-compiled), so it is compiled by YOUR Svelte compiler and works with
|
|
5
|
+
Svelte 4 and Svelte 5. Written in plain JS (types in GuiexpertTable.svelte.d.ts) – no preprocessor needed.
|
|
6
|
+
|
|
7
|
+
Events: listen with `on:tableReady` / `on:mouseClicked` … (event payload in `e.detail`) or pass callback
|
|
8
|
+
props `onTableReady` / `onMouseClicked` … (payload directly; use these in Svelte 5 runes mode).
|
|
9
|
+
A new `tableModel` or `tableOptions` object re-creates the table (the previous one is destroyed).
|
|
10
|
+
-->
|
|
11
|
+
<script>
|
|
12
|
+
import { createEventDispatcher, onDestroy, onMount } from "svelte";
|
|
13
|
+
import { LicenseManager, SimpleDomService, TableOptions, TableScope } from "@guiexpert/table";
|
|
14
|
+
|
|
15
|
+
/** @type {import("@guiexpert/table").TableModelIf} */
|
|
16
|
+
export let tableModel;
|
|
17
|
+
/** @type {import("@guiexpert/table").TableOptionsIf | undefined} */
|
|
18
|
+
export let tableOptions = undefined;
|
|
19
|
+
/** @type {string | undefined} */
|
|
20
|
+
export let licenseKey = undefined;
|
|
21
|
+
|
|
22
|
+
/** @type {((api: import("@guiexpert/table").TableApi) => void) | undefined} */
|
|
23
|
+
export let onTableReady = undefined;
|
|
24
|
+
/** @type {((evt: import("@guiexpert/table").GeMouseEvent) => void) | undefined} */
|
|
25
|
+
export let onMouseClicked = undefined;
|
|
26
|
+
/** @type {((evt: import("@guiexpert/table").GeMouseEvent) => void) | undefined} */
|
|
27
|
+
export let onMouseMoved = undefined;
|
|
28
|
+
/** @type {((evt: import("@guiexpert/table").GeMouseEvent) => void) | undefined} */
|
|
29
|
+
export let onMouseDragging = undefined;
|
|
30
|
+
/** @type {((evt: import("@guiexpert/table").GeMouseEvent) => void) | undefined} */
|
|
31
|
+
export let onMouseDraggingEnd = undefined;
|
|
32
|
+
/** @type {((evt: import("@guiexpert/table").GeMouseEvent) => void) | undefined} */
|
|
33
|
+
export let onContextmenu = undefined;
|
|
34
|
+
/** @type {((rows: any[]) => void) | undefined} */
|
|
35
|
+
export let onCheckboxChanged = undefined;
|
|
36
|
+
/** @type {((evt: import("@guiexpert/table").GeModelChangeEvent) => void) | undefined} */
|
|
37
|
+
export let onModelChanged = undefined;
|
|
38
|
+
/** @type {((model: import("@guiexpert/table").SelectionModelIf) => void) | undefined} */
|
|
39
|
+
export let onSelectionChanged = undefined;
|
|
40
|
+
/** @type {((model: import("@guiexpert/table").FocusModelIf) => void) | undefined} */
|
|
41
|
+
export let onFocusChanged = undefined;
|
|
42
|
+
/** @type {((evt: import("@guiexpert/table").GeScrollEvent) => void) | undefined} */
|
|
43
|
+
export let onScroll = undefined;
|
|
44
|
+
|
|
45
|
+
const dispatch = createEventDispatcher();
|
|
46
|
+
|
|
47
|
+
/** @type {HTMLDivElement} */
|
|
48
|
+
let root;
|
|
49
|
+
/** @type {TableScope | undefined} */
|
|
50
|
+
let tableScope = undefined;
|
|
51
|
+
let mounted = false;
|
|
52
|
+
|
|
53
|
+
/** @type {import("@guiexpert/table").EventListenerIf} */
|
|
54
|
+
const listener = {
|
|
55
|
+
onSelectionChanged: (model) => { dispatch("selectionChanged", model); onSelectionChanged?.(model); },
|
|
56
|
+
onFocusChanged: (model) => { dispatch("focusChanged", model); onFocusChanged?.(model); },
|
|
57
|
+
onCheckboxChanged: (rows) => { dispatch("checkboxChanged", rows); onCheckboxChanged?.(rows); },
|
|
58
|
+
onContextmenu: (evt) => { dispatch("contextmenu", evt); onContextmenu?.(evt); },
|
|
59
|
+
onModelChanged: (evt) => { dispatch("modelChanged", evt); onModelChanged?.(evt); },
|
|
60
|
+
onMouseClicked: (evt) => { dispatch("mouseClicked", evt); onMouseClicked?.(evt); },
|
|
61
|
+
onMouseDragging: (evt) => { dispatch("mouseDragging", evt); onMouseDragging?.(evt); },
|
|
62
|
+
onMouseDraggingEnd: (evt) => { dispatch("mouseDraggingEnd", evt); onMouseDraggingEnd?.(evt); },
|
|
63
|
+
onMouseMoved: (evt) => { dispatch("mouseMoved", evt); onMouseMoved?.(evt); },
|
|
64
|
+
onScroll: (evt) => { dispatch("scroll", evt); onScroll?.(evt); }
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* @param {import("@guiexpert/table").TableModelIf} model
|
|
69
|
+
* @param {import("@guiexpert/table").TableOptionsIf | undefined} options
|
|
70
|
+
*/
|
|
71
|
+
function init(model, options) {
|
|
72
|
+
tableScope?.destroy();
|
|
73
|
+
tableScope = undefined;
|
|
74
|
+
if (!root || !model) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
tableScope = new TableScope(root, model, new SimpleDomService(), options ?? new TableOptions(), listener);
|
|
78
|
+
tableScope.firstInit();
|
|
79
|
+
const api = tableScope.getApi();
|
|
80
|
+
dispatch("tableReady", api);
|
|
81
|
+
onTableReady?.(api);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
onMount(() => {
|
|
85
|
+
mounted = true;
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
onDestroy(() => {
|
|
89
|
+
tableScope?.destroy();
|
|
90
|
+
tableScope = undefined;
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
// runs after mount and whenever a new tableModel / tableOptions object arrives
|
|
94
|
+
$: if (mounted) init(tableModel, tableOptions);
|
|
95
|
+
|
|
96
|
+
$: if (licenseKey) LicenseManager.getInstance().setLicenseKey(licenseKey);
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<div
|
|
100
|
+
bind:this={root}
|
|
101
|
+
class="ge-table"
|
|
102
|
+
style="width: 100%; height: 100%; background-color: transparent; padding: 0; margin: 0"></div>
|
|
@@ -1 +1,53 @@
|
|
|
1
|
-
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type {
|
|
3
|
+
FocusModelIf,
|
|
4
|
+
GeModelChangeEvent,
|
|
5
|
+
GeMouseEvent,
|
|
6
|
+
GeScrollEvent,
|
|
7
|
+
SelectionModelIf,
|
|
8
|
+
TableApi,
|
|
9
|
+
TableModelIf,
|
|
10
|
+
TableOptionsIf
|
|
11
|
+
} from "@guiexpert/table";
|
|
12
|
+
|
|
13
|
+
export interface GuiexpertTableProps {
|
|
14
|
+
tableModel: TableModelIf;
|
|
15
|
+
tableOptions?: TableOptionsIf;
|
|
16
|
+
licenseKey?: string;
|
|
17
|
+
/** Callback props – alternative to `on:…` (required in Svelte 5 runes mode). */
|
|
18
|
+
onTableReady?: (api: TableApi) => void;
|
|
19
|
+
onMouseClicked?: (evt: GeMouseEvent) => void;
|
|
20
|
+
onMouseMoved?: (evt: GeMouseEvent) => void;
|
|
21
|
+
onMouseDragging?: (evt: GeMouseEvent) => void;
|
|
22
|
+
onMouseDraggingEnd?: (evt: GeMouseEvent) => void;
|
|
23
|
+
onContextmenu?: (evt: GeMouseEvent) => void;
|
|
24
|
+
onCheckboxChanged?: (rows: any[]) => void;
|
|
25
|
+
onModelChanged?: (evt: GeModelChangeEvent) => void;
|
|
26
|
+
onSelectionChanged?: (model: SelectionModelIf) => void;
|
|
27
|
+
onFocusChanged?: (model: FocusModelIf) => void;
|
|
28
|
+
onScroll?: (evt: GeScrollEvent) => void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export interface GuiexpertTableEvents {
|
|
32
|
+
tableReady: CustomEvent<TableApi>;
|
|
33
|
+
mouseClicked: CustomEvent<GeMouseEvent>;
|
|
34
|
+
mouseMoved: CustomEvent<GeMouseEvent>;
|
|
35
|
+
mouseDragging: CustomEvent<GeMouseEvent>;
|
|
36
|
+
mouseDraggingEnd: CustomEvent<GeMouseEvent>;
|
|
37
|
+
contextmenu: CustomEvent<GeMouseEvent>;
|
|
38
|
+
checkboxChanged: CustomEvent<any[]>;
|
|
39
|
+
modelChanged: CustomEvent<GeModelChangeEvent>;
|
|
40
|
+
selectionChanged: CustomEvent<SelectionModelIf>;
|
|
41
|
+
focusChanged: CustomEvent<FocusModelIf>;
|
|
42
|
+
scroll: CustomEvent<GeScrollEvent>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Svelte wrapper of the GuiExpert Table (Svelte 4 and 5).
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* <GuiexpertTable {tableModel} {tableOptions} on:tableReady={(e) => api = e.detail} />
|
|
50
|
+
* <!-- Svelte 5 runes mode: -->
|
|
51
|
+
* <GuiexpertTable {tableModel} onTableReady={(api) => tableApi = api} />
|
|
52
|
+
*/
|
|
53
|
+
export default class GuiexpertTable extends SvelteComponent<GuiexpertTableProps, GuiexpertTableEvents, {}> {}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023-2026 Dr. Marc Kronberg (gui.expert)
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -7,7 +7,7 @@ This is the Svelte component of the GuiExpert Table Project.
|
|
|
7
7
|
|
|
8
8
|
This is the UI-agnostic table component for your next web app. 😊
|
|
9
9
|
|
|
10
|
-
<img src="https://raw.githubusercontent.com/guiexperttable/
|
|
10
|
+
<img src="https://raw.githubusercontent.com/guiexperttable/mono/main/apps/webpage-guiexpert/src/assets/screens/heatmap.png" width="50%">
|
|
11
11
|
|
|
12
12
|
### Features
|
|
13
13
|
- Handle large datasets easily
|
|
@@ -51,7 +51,10 @@ Add the following two NPM packages to your existing Svelte project (run this in
|
|
|
51
51
|
npm install --save @guiexpert/table @guiexpert/svelte-table
|
|
52
52
|
```
|
|
53
53
|
|
|
54
|
-
|
|
54
|
+
Works with **Svelte 4 and Svelte 5**: the package ships the component as Svelte source, which is compiled by your
|
|
55
|
+
own Svelte compiler (no preprocessor needed).
|
|
56
|
+
|
|
57
|
+
Add GuiexpertTable component to a template – Svelte 4 / legacy syntax:
|
|
55
58
|
|
|
56
59
|
```
|
|
57
60
|
<GuiexpertTable
|
|
@@ -59,9 +62,25 @@ Add GuiexpertTable component to a template:
|
|
|
59
62
|
on:tableReady={handleTableReady}
|
|
60
63
|
tableModel={tableModel}
|
|
61
64
|
tableOptions={tableOptions}
|
|
62
|
-
|
|
65
|
+
/>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Svelte 5 (runes mode) – use the callback props (payload directly, no `e.detail`):
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
<GuiexpertTable
|
|
72
|
+
{tableModel}
|
|
73
|
+
{tableOptions}
|
|
74
|
+
onTableReady={(api) => tableApi = api}
|
|
75
|
+
onMouseClicked={(evt) => console.info(evt.rowIndex, evt.columnIndex)}
|
|
76
|
+
/>
|
|
63
77
|
```
|
|
64
78
|
|
|
79
|
+
Callback props: `onTableReady`, `onMouseClicked`, `onMouseMoved`, `onMouseDragging`, `onMouseDraggingEnd`,
|
|
80
|
+
`onContextmenu`, `onCheckboxChanged`, `onModelChanged`, `onSelectionChanged`, `onFocusChanged`, `onScroll`
|
|
81
|
+
(the same names without `on` are dispatched as Svelte events). A new `tableModel` / `tableOptions` object
|
|
82
|
+
re-creates the table. Svelte components as cell renderers: `new ComponentRendererWrapper(MyCell)`.
|
|
83
|
+
|
|
65
84
|
Import the following classes in your component:
|
|
66
85
|
```
|
|
67
86
|
<script lang="ts">
|
|
@@ -69,7 +88,7 @@ Import the following classes in your component:
|
|
|
69
88
|
import { GuiexpertTable } from "@guiexpert/svelte-table";
|
|
70
89
|
import {
|
|
71
90
|
GeMouseEvent,
|
|
72
|
-
TableApi
|
|
91
|
+
TableApi,
|
|
73
92
|
TableFactory,
|
|
74
93
|
TableModelIf,
|
|
75
94
|
TableOptions,
|
|
@@ -101,3 +120,9 @@ Please refer to the [Documentation](https://gui.expert/doc) for further informat
|
|
|
101
120
|
|
|
102
121
|
|
|
103
122
|
|
|
123
|
+
|
|
124
|
+
## License
|
|
125
|
+
|
|
126
|
+
**Current releases: MIT License.** All currently published versions are free to use, modify and distribute – also in commercial and proprietary applications. See [LICENSE](https://github.com/guiexperttable/mono/blob/main/LICENSE).
|
|
127
|
+
|
|
128
|
+
**Future releases: possible dual licensing.** Dr. Marc Kronberg (gui.expert) reserves the right to publish future versions under different terms (e.g. open source for individuals and non-commercial use, commercial license for businesses). Versions already released under MIT remain MIT. Details: [gui.expert/license](https://gui.expert/license/).
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
export { default as GuiexpertTable } from
|
|
2
|
-
export {
|
|
1
|
+
export { default as GuiexpertTable } from "./GuiexpertTable.svelte";
|
|
2
|
+
export type { GuiexpertTableProps, GuiexpertTableEvents } from "./GuiexpertTable.svelte";
|
|
3
|
+
export { ComponentRendererWrapper } from "./ComponentRendererWrapper.js";
|