@sheetwrite/svelte 0.6.0 → 0.7.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 +2 -2
- package/package.json +15 -4
- package/src/Grid.svelte +74 -64
- package/src/Grid.svelte.d.ts +0 -1
- package/src/Sheetwrite.svelte +16 -22
- package/src/Sheetwrite.svelte.d.ts +21 -2
- package/src/props.ts +6 -4
- package/styles/charts.css +1 -0
- package/styles/context-menu.css +1 -0
- package/styles/dashboard.css +1 -0
- package/styles/find.css +1 -0
- package/styles/formula-help.css +1 -0
- package/styles/grid.css +1 -0
- package/styles/icons.css +1 -0
- package/styles/panels.css +1 -0
- package/styles/ribbon.css +1 -0
- package/styles/tabs.css +1 -0
package/README.md
CHANGED
|
@@ -70,8 +70,8 @@ Grid callbacks are `onGridChange`, `onViewportChange`, `onSelectionChange`, `onE
|
|
|
70
70
|
For vanilla/preload control, use `initSheetwrite()` and `createGrid()` from `@sheetwrite/core`. See [installation](https://www.sheetwrite.dev/docs/start/installation/), [Svelte tutorial](https://www.sheetwrite.dev/docs/tutorials/excel-in-svelte/), and [collaboration](https://www.sheetwrite.dev/docs/features/collaboration/).
|
|
71
71
|
|
|
72
72
|
XLSX is not installed by this adapter. If the toolbar configuration enables
|
|
73
|
-
XLSX export, install `@sheetwrite/xlsx` and
|
|
74
|
-
|
|
73
|
+
XLSX export, install `@sheetwrite/xlsx` and call
|
|
74
|
+
`initSheetwrite({ addons: [xlsxAddon()] })` before the action (or lazily inside its handler).
|
|
75
75
|
CSV/TSV require no optional package.
|
|
76
76
|
|
|
77
77
|
For workbook streaming and kept XLSX parts, use the registered core workbook
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheetwrite/svelte",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte adapter for Sheetwrite.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -29,12 +29,23 @@
|
|
|
29
29
|
"types": "./src/index.ts",
|
|
30
30
|
"default": "./src/index.ts"
|
|
31
31
|
},
|
|
32
|
-
"./styles.css": "./styles.css"
|
|
32
|
+
"./styles.css": "./styles.css",
|
|
33
|
+
"./styles/grid.css": "./styles/grid.css",
|
|
34
|
+
"./styles/formula-help.css": "./styles/formula-help.css",
|
|
35
|
+
"./styles/find.css": "./styles/find.css",
|
|
36
|
+
"./styles/ribbon.css": "./styles/ribbon.css",
|
|
37
|
+
"./styles/panels.css": "./styles/panels.css",
|
|
38
|
+
"./styles/context-menu.css": "./styles/context-menu.css",
|
|
39
|
+
"./styles/tabs.css": "./styles/tabs.css",
|
|
40
|
+
"./styles/charts.css": "./styles/charts.css",
|
|
41
|
+
"./styles/icons.css": "./styles/icons.css",
|
|
42
|
+
"./styles/dashboard.css": "./styles/dashboard.css"
|
|
33
43
|
},
|
|
34
44
|
"files": [
|
|
35
45
|
"src/**/*.ts",
|
|
36
46
|
"src/**/*.svelte",
|
|
37
|
-
"styles.css"
|
|
47
|
+
"styles.css",
|
|
48
|
+
"styles/*.css"
|
|
38
49
|
],
|
|
39
50
|
"publishConfig": {
|
|
40
51
|
"access": "public",
|
|
@@ -48,7 +59,7 @@
|
|
|
48
59
|
"svelte": ">=5"
|
|
49
60
|
},
|
|
50
61
|
"dependencies": {
|
|
51
|
-
"@sheetwrite/core": "0.
|
|
62
|
+
"@sheetwrite/core": "0.7.0"
|
|
52
63
|
},
|
|
53
64
|
"devDependencies": {
|
|
54
65
|
"svelte-check": "4.7.3",
|
package/src/Grid.svelte
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { isSheetwriteReady } from "@sheetwrite/core";
|
|
2
|
+
import { type GridOptions, isSheetwriteReady } from "@sheetwrite/core";
|
|
3
3
|
import {
|
|
4
4
|
type AdapterGridInput,
|
|
5
5
|
createAdapterGridController,
|
|
@@ -10,92 +10,97 @@ import {
|
|
|
10
10
|
import { untrack } from "svelte";
|
|
11
11
|
import type { SheetwriteGridProps as Props } from "./props.js";
|
|
12
12
|
|
|
13
|
-
|
|
14
13
|
let {
|
|
15
14
|
workbook,
|
|
16
15
|
data,
|
|
17
16
|
datasource,
|
|
18
|
-
datasourceStorage,
|
|
17
|
+
datasourceStorage: datasource_storage,
|
|
19
18
|
renderer = "canvas",
|
|
20
|
-
workerUrl,
|
|
19
|
+
workerUrl: worker_url,
|
|
21
20
|
theme,
|
|
22
21
|
presentation,
|
|
23
|
-
readOnly,
|
|
24
|
-
protectionResolver,
|
|
25
|
-
mutationPolicy,
|
|
26
|
-
transactionResourceLimits,
|
|
27
|
-
hyperlinkActivation,
|
|
22
|
+
readOnly: read_only,
|
|
23
|
+
protectionResolver: protection_resolver,
|
|
24
|
+
mutationPolicy: mutation_policy,
|
|
25
|
+
transactionResourceLimits: transaction_resource_limits,
|
|
26
|
+
hyperlinkActivation: hyperlink_activation,
|
|
27
|
+
addons,
|
|
28
28
|
renderers,
|
|
29
29
|
editors,
|
|
30
30
|
overscan,
|
|
31
|
-
minColumns,
|
|
31
|
+
minColumns: min_columns,
|
|
32
32
|
config,
|
|
33
|
-
wasmSource,
|
|
33
|
+
wasmSource: wasm_source,
|
|
34
34
|
height,
|
|
35
35
|
fill,
|
|
36
|
-
rowBridge,
|
|
36
|
+
rowBridge: row_bridge,
|
|
37
37
|
fallback,
|
|
38
|
-
onGridChange,
|
|
39
|
-
onRowDelta,
|
|
40
|
-
onSelectionChange,
|
|
41
|
-
onViewportChange,
|
|
42
|
-
onEditBegin,
|
|
43
|
-
onEditCommit,
|
|
44
|
-
onSearch,
|
|
45
|
-
onActiveSheetChange,
|
|
46
|
-
onCommandStateChange,
|
|
47
|
-
onMutationRejected,
|
|
48
|
-
onRendererFallback,
|
|
49
|
-
onDatasourceError,
|
|
50
|
-
onExportError,
|
|
51
|
-
|
|
52
|
-
|
|
38
|
+
onGridChange: on_grid_change,
|
|
39
|
+
onRowDelta: on_row_delta,
|
|
40
|
+
onSelectionChange: on_selection_change,
|
|
41
|
+
onViewportChange: on_viewport_change,
|
|
42
|
+
onEditBegin: on_edit_begin,
|
|
43
|
+
onEditCommit: on_edit_commit,
|
|
44
|
+
onSearch: on_search,
|
|
45
|
+
onActiveSheetChange: on_active_sheet_change,
|
|
46
|
+
onCommandStateChange: on_command_state_change,
|
|
47
|
+
onMutationRejected: on_mutation_rejected,
|
|
48
|
+
onRendererFallback: on_renderer_fallback,
|
|
49
|
+
onDatasourceError: on_datasource_error,
|
|
50
|
+
onExportError: on_export_error,
|
|
51
|
+
onKeyBindingsChange: on_key_bindings_change,
|
|
52
|
+
onReady: on_ready,
|
|
53
|
+
onInitializationError: on_initialization_error,
|
|
53
54
|
grid = $bindable(),
|
|
54
|
-
...
|
|
55
|
+
...host_attributes
|
|
55
56
|
}: Props = $props();
|
|
56
57
|
|
|
57
58
|
let host: HTMLDivElement;
|
|
58
59
|
let loading = $state(!isSheetwriteReady());
|
|
59
60
|
|
|
60
|
-
function
|
|
61
|
-
event: Parameters<NonNullable<typeof
|
|
61
|
+
function forward_command_state_change(
|
|
62
|
+
event: Parameters<NonNullable<typeof on_command_state_change>>[0],
|
|
62
63
|
): void {
|
|
63
|
-
|
|
64
|
+
on_command_state_change?.(event);
|
|
64
65
|
}
|
|
65
66
|
|
|
66
67
|
const handlers: GridAdapterEventHandlers = {
|
|
67
|
-
onGridChange: (event: Parameters<NonNullable<typeof
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
onGridChange: (event: Parameters<NonNullable<typeof on_grid_change>>[0]) =>
|
|
69
|
+
on_grid_change?.(event),
|
|
70
|
+
onRowDelta: (event: Parameters<NonNullable<typeof on_row_delta>>[0]) => on_row_delta?.(event),
|
|
71
|
+
onSelectionChange: (event: Parameters<NonNullable<typeof on_selection_change>>[0]) =>
|
|
72
|
+
on_selection_change?.(event),
|
|
73
|
+
onViewportChange: (event: Parameters<NonNullable<typeof on_viewport_change>>[0]) =>
|
|
74
|
+
on_viewport_change?.(event),
|
|
75
|
+
onEditBegin: (event: Parameters<NonNullable<typeof on_edit_begin>>[0]) => on_edit_begin?.(event),
|
|
76
|
+
onEditCommit: (event: Parameters<NonNullable<typeof on_edit_commit>>[0]) =>
|
|
77
|
+
on_edit_commit?.(event),
|
|
78
|
+
onSearch: (event: Parameters<NonNullable<typeof on_search>>[0]) => on_search?.(event),
|
|
79
|
+
onActiveSheetChange: (event: Parameters<NonNullable<typeof on_active_sheet_change>>[0]) =>
|
|
80
|
+
on_active_sheet_change?.(event),
|
|
78
81
|
// The controller only subscribes to command state while this is defined, so
|
|
79
82
|
// absence must be visible instead of an always-present wrapper.
|
|
80
83
|
get onCommandStateChange() {
|
|
81
|
-
return
|
|
84
|
+
return on_command_state_change === undefined ? undefined : forward_command_state_change;
|
|
82
85
|
},
|
|
83
|
-
onMutationRejected: (event: Parameters<NonNullable<typeof
|
|
84
|
-
|
|
85
|
-
onRendererFallback: (event: Parameters<NonNullable<typeof
|
|
86
|
-
|
|
87
|
-
onDatasourceError: (event: Parameters<NonNullable<typeof
|
|
88
|
-
|
|
89
|
-
onExportError: (event: Parameters<NonNullable<typeof
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
86
|
+
onMutationRejected: (event: Parameters<NonNullable<typeof on_mutation_rejected>>[0]) =>
|
|
87
|
+
on_mutation_rejected?.(event),
|
|
88
|
+
onRendererFallback: (event: Parameters<NonNullable<typeof on_renderer_fallback>>[0]) =>
|
|
89
|
+
on_renderer_fallback?.(event),
|
|
90
|
+
onDatasourceError: (event: Parameters<NonNullable<typeof on_datasource_error>>[0]) =>
|
|
91
|
+
on_datasource_error?.(event),
|
|
92
|
+
onExportError: (event: Parameters<NonNullable<typeof on_export_error>>[0]) =>
|
|
93
|
+
on_export_error?.(event),
|
|
94
|
+
onKeyBindingsChange: (event: Parameters<NonNullable<typeof on_key_bindings_change>>[0]) =>
|
|
95
|
+
on_key_bindings_change?.(event),
|
|
96
|
+
onReady: (event: Parameters<NonNullable<typeof on_ready>>[0]) => on_ready?.(event),
|
|
97
|
+
onInitializationError: (error: Parameters<NonNullable<typeof on_initialization_error>>[0]) =>
|
|
98
|
+
on_initialization_error?.(error),
|
|
94
99
|
};
|
|
95
100
|
|
|
96
101
|
const lifetime = createAdapterGridController(handlers, {
|
|
97
|
-
publish(
|
|
98
|
-
grid =
|
|
102
|
+
publish(next_grid) {
|
|
103
|
+
grid = next_grid ?? undefined;
|
|
99
104
|
},
|
|
100
105
|
setInitializationState(state) {
|
|
101
106
|
loading = state !== "ready";
|
|
@@ -106,14 +111,19 @@ const lifetime = createAdapterGridController(handlers, {
|
|
|
106
111
|
} satisfies GridPublicationAdapter);
|
|
107
112
|
let attached = false;
|
|
108
113
|
$effect(() => {
|
|
114
|
+
// The props are destructured (with `renderer`'s default) for Svelte's reactivity,
|
|
115
|
+
// so the options are listed here rather than read by `extractGridOptions`;
|
|
116
|
+
// `satisfies` fails the typecheck when a GridOptions key is missing.
|
|
109
117
|
const input: AdapterGridInput = {
|
|
110
118
|
options: {
|
|
111
|
-
workbook, data, datasource, datasourceStorage, renderer,
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
119
|
+
workbook, data, datasource, datasourceStorage: datasource_storage, renderer,
|
|
120
|
+
workerUrl: worker_url, presentation, protectionResolver: protection_resolver,
|
|
121
|
+
mutationPolicy: mutation_policy, transactionResourceLimits: transaction_resource_limits,
|
|
122
|
+
hyperlinkActivation: hyperlink_activation, addons, renderers, editors, theme,
|
|
123
|
+
readOnly: read_only, overscan, minColumns: min_columns, config,
|
|
124
|
+
} satisfies Record<keyof GridOptions, unknown>,
|
|
125
|
+
rowBridge: row_bridge,
|
|
126
|
+
wasmSource: wasm_source,
|
|
117
127
|
};
|
|
118
128
|
untrack(() => {
|
|
119
129
|
if (attached) lifetime.update(input);
|
|
@@ -129,9 +139,9 @@ let sizing = $derived(gridSizeStyle({ height, fill }));
|
|
|
129
139
|
</script>
|
|
130
140
|
|
|
131
141
|
<div
|
|
132
|
-
{...
|
|
142
|
+
{...host_attributes}
|
|
133
143
|
bind:this={host}
|
|
134
|
-
class={["sheetwrite",
|
|
144
|
+
class={["sheetwrite", host_attributes.class]}
|
|
135
145
|
style:width={sizing.width}
|
|
136
146
|
style:height={sizing.height}
|
|
137
147
|
style:min-height={sizing.minHeight}
|
package/src/Grid.svelte.d.ts
CHANGED
package/src/Sheetwrite.svelte
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script lang="ts" generics="Row extends Record<string, CellScalar>, Id extends RowBridgeId = RowBridgeId">
|
|
2
2
|
import type { CellScalar } from "@sheetwrite/core";
|
|
3
|
-
import { createSimpleGridInput, createSimpleRowBridge } from "@sheetwrite/core/adapter";
|
|
3
|
+
import { assertGridSize, createSimpleGridInput, createSimpleRowBridge } from "@sheetwrite/core/adapter";
|
|
4
4
|
import type { RowBridgeId } from "@sheetwrite/core/adapter";
|
|
5
5
|
import GridComponent from "./Grid.svelte";
|
|
6
6
|
import type { SheetwriteGridProps, SheetwriteProps } from "./props.js";
|
|
@@ -9,35 +9,29 @@ type Props = SheetwriteProps<Row, Id>;
|
|
|
9
9
|
|
|
10
10
|
let {
|
|
11
11
|
columns,
|
|
12
|
-
defaultRows,
|
|
13
|
-
sheetName,
|
|
14
|
-
getRowId,
|
|
15
|
-
createRowId,
|
|
12
|
+
defaultRows: default_rows,
|
|
13
|
+
sheetName: sheet_name,
|
|
14
|
+
getRowId: get_row_id,
|
|
15
|
+
createRowId: create_row_id,
|
|
16
16
|
grid = $bindable(),
|
|
17
17
|
...props
|
|
18
18
|
}: Props = $props();
|
|
19
|
-
let input = $derived(
|
|
20
|
-
|
|
19
|
+
let input = $derived(
|
|
20
|
+
createSimpleGridInput({ columns, defaultRows: default_rows, sheetName: sheet_name }),
|
|
21
|
+
);
|
|
22
|
+
let row_bridge = $derived(
|
|
21
23
|
createSimpleRowBridge({
|
|
22
24
|
columns,
|
|
23
|
-
defaultRows,
|
|
24
|
-
...(
|
|
25
|
-
...(
|
|
25
|
+
defaultRows: default_rows,
|
|
26
|
+
...(get_row_id === undefined ? {} : { getRowId: get_row_id }),
|
|
27
|
+
...(create_row_id === undefined ? {} : { createRowId: create_row_id }),
|
|
26
28
|
}),
|
|
27
29
|
);
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
+
let resolved_props = $derived.by(() => {
|
|
31
|
+
assertGridSize({ height: props.height, fill: props.fill });
|
|
32
|
+
const forwarded = { ...props, ...input, rowBridge: row_bridge };
|
|
30
33
|
return forwarded as unknown as SheetwriteGridProps;
|
|
31
34
|
});
|
|
32
|
-
|
|
33
|
-
$effect(() => {
|
|
34
|
-
if (
|
|
35
|
-
(props.height === undefined && !props.fill) ||
|
|
36
|
-
(props.height !== undefined && props.fill)
|
|
37
|
-
) {
|
|
38
|
-
throw new Error("Sheetwrite: provide exactly one of height or fill");
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
35
|
</script>
|
|
42
36
|
|
|
43
|
-
<GridComponent {...
|
|
37
|
+
<GridComponent {...resolved_props} bind:grid />
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import type { CellScalar } from "@sheetwrite/core";
|
|
2
|
-
import type {
|
|
2
|
+
import type { RowBridgeId } from "@sheetwrite/core/adapter";
|
|
3
|
+
import type { ComponentConstructorOptions, ComponentInternals, SvelteComponent } from "svelte";
|
|
3
4
|
import type { SheetwriteProps } from "./props.js";
|
|
4
5
|
|
|
5
6
|
export type { SheetwriteProps } from "./props.js";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* The shape svelte2tsx gives a generic component. The constructor signature keeps `Row` and
|
|
10
|
+
* `Id` for Svelte's template checker, which drops the generics of a plain `Component`.
|
|
11
|
+
*/
|
|
12
|
+
interface SheetwriteComponent {
|
|
13
|
+
new <Row extends Record<string, CellScalar>, Id extends RowBridgeId = RowBridgeId>(
|
|
14
|
+
options: ComponentConstructorOptions<SheetwriteProps<Row, Id>>,
|
|
15
|
+
): SvelteComponent<SheetwriteProps<Row, Id>> & { $$bindings?: "grid" };
|
|
16
|
+
<Row extends Record<string, CellScalar>, Id extends RowBridgeId = RowBridgeId>(
|
|
17
|
+
this: void,
|
|
18
|
+
internals: ComponentInternals,
|
|
19
|
+
props: SheetwriteProps<Row, Id>,
|
|
20
|
+
): {};
|
|
21
|
+
element?: typeof HTMLElement;
|
|
22
|
+
z_$$bindings?: "grid";
|
|
23
|
+
}
|
|
24
|
+
|
|
6
25
|
/** Owns a sheet derived from `columns` and `defaultRows`. Bind `grid` for imperative access; it clears on reset or unmount. */
|
|
7
|
-
declare const Sheetwrite:
|
|
26
|
+
declare const Sheetwrite: SheetwriteComponent;
|
|
8
27
|
export default Sheetwrite;
|
package/src/props.ts
CHANGED
|
@@ -25,7 +25,7 @@ export interface SheetwriteGridProps<Id extends RowBridgeId = RowBridgeId>
|
|
|
25
25
|
rowBridge?: RowBridge<Id>;
|
|
26
26
|
/** Lazy visible-row provider. */
|
|
27
27
|
datasource?: GridOptions["datasource"];
|
|
28
|
-
/**
|
|
28
|
+
/** Allocation and cache policy for datasource storage. */
|
|
29
29
|
datasourceStorage?: GridOptions["datasourceStorage"];
|
|
30
30
|
/** Canvas or worker paint backend. */
|
|
31
31
|
renderer?: GridOptions["renderer"];
|
|
@@ -45,15 +45,17 @@ export interface SheetwriteGridProps<Id extends RowBridgeId = RowBridgeId>
|
|
|
45
45
|
transactionResourceLimits?: GridOptions["transactionResourceLimits"];
|
|
46
46
|
/** Controls link activation: emit an event, also navigate internally, or disable it. */
|
|
47
47
|
hyperlinkActivation?: GridOptions["hyperlinkActivation"];
|
|
48
|
-
/**
|
|
48
|
+
/** Settings for add-ons installed by `initSheetwrite`, keyed by add-on name; applied when the Grid is created. */
|
|
49
|
+
addons?: GridOptions["addons"];
|
|
50
|
+
/** Named custom cell renderers, registered when the Grid is created. */
|
|
49
51
|
renderers?: GridOptions["renderers"];
|
|
50
|
-
/** Named custom cell editors. */
|
|
52
|
+
/** Named custom cell editors, registered when the Grid is created. */
|
|
51
53
|
editors?: GridOptions["editors"];
|
|
52
54
|
/** Extra rows painted around the viewport. */
|
|
53
55
|
overscan?: GridOptions["overscan"];
|
|
54
56
|
/** Minimum column count with padding. */
|
|
55
57
|
minColumns?: GridOptions["minColumns"];
|
|
56
|
-
/** Built-in
|
|
58
|
+
/** Built-in toolbar, menu, keyboard, find and tab controls. */
|
|
57
59
|
config?: GridOptions["config"];
|
|
58
60
|
/** Host height as pixels or a CSS length. */
|
|
59
61
|
height?: number | string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/charts.css";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/context-menu.css";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/dashboard.css";
|
package/styles/find.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/find.css";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/formula-help.css";
|
package/styles/grid.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/grid.css";
|
package/styles/icons.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/icons.css";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/panels.css";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/ribbon.css";
|
package/styles/tabs.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
@import "@sheetwrite/core/styles/tabs.css";
|