@sheetwrite/svelte 0.6.1 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -32,6 +32,12 @@ import "@sheetwrite/svelte/styles.css";
32
32
 
33
33
  WASM initializes on client mount. Use `fallback` while loading, `onInitializationError` for failures, and `wasmSource` for an explicit source.
34
34
 
35
+ ## New in 0.7.0
36
+
37
+ - Install add-ons once with `initSheetwrite({ addons: [...] })` from `@sheetwrite/core` before the component mounts. The `addons` prop gives one grid its own add-on settings, such as `addons={{ queries: { fetchSource } }}`. See [Add-on registration](https://www.sheetwrite.dev/docs/start/upgrade-to-0-7-0/#add-on-registration).
38
+ - Enable the Keyboard shortcuts panel with `config={{ keyboardSettings: true }}`, and store the user's keys from `onKeyBindingsChange`. The compact ribbon is `config={{ ribbon: { mode: "compact" } }}`.
39
+ - Sort moves the cells; `grid.setViewSort` is the display-only sort. Columns without a `type` use the new `general` type. See the [0.7.0 release notes](https://www.sheetwrite.dev/docs/releases/0.7.0/) and the [upgrade guide](https://www.sheetwrite.dev/docs/start/upgrade-to-0-7-0/).
40
+
35
41
  ## New in 0.6.0
36
42
 
37
43
  - Enable the opt-in ribbon with `config={{ ribbon: true }}`. It loads only when requested. See [Toolbar and ribbon](https://www.sheetwrite.dev/docs/features/grid/toolbar-and-ribbon/).
@@ -55,9 +61,9 @@ The bindable `grid` is published before
55
61
  `onReady({ grid, generation, reason })` and clears during replacement or
56
62
  unmount. Reset-bound inputs are `workbook`, `data`, `datasource`,
57
63
  `datasourceStorage`, `presentation`, `editors`, `protectionResolver`,
58
- `mutationPolicy`, `transactionResourceLimits`, `renderer`, `workerUrl`, and
59
- `renderers`; `theme`, `readOnly`, `config`, `overscan`, and `minColumns` update
60
- live.
64
+ `mutationPolicy`, `transactionResourceLimits`, `hyperlinkActivation`, `addons`,
65
+ `renderer`, `workerUrl`, and `renderers`; `theme`, `readOnly`, `config`,
66
+ `overscan`, and `minColumns` update live.
61
67
 
62
68
  Readiness observes the latest committed live options, including changes while
63
69
  WASM initialization is pending. A throwing ready callback retires the new Grid;
@@ -65,13 +71,13 @@ consumer errors are not initialization failures. Omitted `renderer` and
65
71
  `"canvas"` are equivalent. Changing an explicit `wasmSource` after readiness
66
72
  preserves the Grid and retains the loader's first-source warning.
67
73
 
68
- Grid callbacks are `onGridChange`, `onViewportChange`, `onSelectionChange`, `onEditBegin`, `onEditCommit`, `onSearch`, `onCommandStateChange`, `onActiveSheetChange`, `onMutationRejected`, `onRendererFallback`, `onDatasourceError`, and `onExportError`.
74
+ Grid callbacks are `onGridChange`, `onRowDelta`, `onViewportChange`, `onSelectionChange`, `onEditBegin`, `onEditCommit`, `onSearch`, `onCommandStateChange`, `onActiveSheetChange`, `onMutationRejected`, `onRendererFallback`, `onDatasourceError`, `onExportError`, and `onKeyBindingsChange`.
69
75
 
70
76
  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
77
 
72
78
  XLSX is not installed by this adapter. If the toolbar configuration enables
73
- XLSX export, install `@sheetwrite/xlsx` and import
74
- `@sheetwrite/xlsx/register` before the action (or lazily inside its handler).
79
+ XLSX export, install `@sheetwrite/xlsx` and call
80
+ `initSheetwrite({ addons: [xlsxAddon()] })` before the action (or lazily inside its handler).
75
81
  CSV/TSV require no optional package.
76
82
 
77
83
  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.6.1",
3
+ "version": "0.7.1",
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.6.1"
62
+ "@sheetwrite/core": "0.7.1"
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
- onReady,
52
- onInitializationError,
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
- ...hostAttributes
55
+ ...host_attributes
55
56
  }: Props = $props();
56
57
 
57
58
  let host: HTMLDivElement;
58
59
  let loading = $state(!isSheetwriteReady());
59
60
 
60
- function forwardCommandStateChange(
61
- event: Parameters<NonNullable<typeof onCommandStateChange>>[0],
61
+ function forward_command_state_change(
62
+ event: Parameters<NonNullable<typeof on_command_state_change>>[0],
62
63
  ): void {
63
- onCommandStateChange?.(event);
64
+ on_command_state_change?.(event);
64
65
  }
65
66
 
66
67
  const handlers: GridAdapterEventHandlers = {
67
- onGridChange: (event: Parameters<NonNullable<typeof onGridChange>>[0]) => onGridChange?.(event),
68
- onRowDelta: (event: Parameters<NonNullable<typeof onRowDelta>>[0]) => onRowDelta?.(event),
69
- onSelectionChange: (event: Parameters<NonNullable<typeof onSelectionChange>>[0]) =>
70
- onSelectionChange?.(event),
71
- onViewportChange: (event: Parameters<NonNullable<typeof onViewportChange>>[0]) =>
72
- onViewportChange?.(event),
73
- onEditBegin: (event: Parameters<NonNullable<typeof onEditBegin>>[0]) => onEditBegin?.(event),
74
- onEditCommit: (event: Parameters<NonNullable<typeof onEditCommit>>[0]) => onEditCommit?.(event),
75
- onSearch: (event: Parameters<NonNullable<typeof onSearch>>[0]) => onSearch?.(event),
76
- onActiveSheetChange: (event: Parameters<NonNullable<typeof onActiveSheetChange>>[0]) =>
77
- onActiveSheetChange?.(event),
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 onCommandStateChange === undefined ? undefined : forwardCommandStateChange;
84
+ return on_command_state_change === undefined ? undefined : forward_command_state_change;
82
85
  },
83
- onMutationRejected: (event: Parameters<NonNullable<typeof onMutationRejected>>[0]) =>
84
- onMutationRejected?.(event),
85
- onRendererFallback: (event: Parameters<NonNullable<typeof onRendererFallback>>[0]) =>
86
- onRendererFallback?.(event),
87
- onDatasourceError: (event: Parameters<NonNullable<typeof onDatasourceError>>[0]) =>
88
- onDatasourceError?.(event),
89
- onExportError: (event: Parameters<NonNullable<typeof onExportError>>[0]) =>
90
- onExportError?.(event),
91
- onReady: (event: Parameters<NonNullable<typeof onReady>>[0]) => onReady?.(event),
92
- onInitializationError: (error: Parameters<NonNullable<typeof onInitializationError>>[0]) =>
93
- onInitializationError?.(error),
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(nextGrid) {
98
- grid = nextGrid ?? undefined;
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, workerUrl, presentation,
112
- protectionResolver, mutationPolicy, transactionResourceLimits, hyperlinkActivation,
113
- renderers, editors, theme, readOnly, overscan, minColumns, config,
114
- },
115
- rowBridge,
116
- wasmSource,
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
- {...hostAttributes}
142
+ {...host_attributes}
133
143
  bind:this={host}
134
- class={["sheetwrite", hostAttributes.class]}
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}
@@ -1,4 +1,3 @@
1
- import type { Grid } from "@sheetwrite/core";
2
1
  import type { Component } from "svelte";
3
2
  import type { SheetwriteGridProps } from "./props.js";
4
3
 
@@ -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(createSimpleGridInput({ columns, defaultRows, sheetName }));
20
- let rowBridge = $derived(
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
- ...(getRowId === undefined ? {} : { getRowId }),
25
- ...(createRowId === undefined ? {} : { createRowId }),
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 resolvedProps = $derived.by(() => {
29
- const forwarded = { ...props, ...input, rowBridge };
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 {...resolvedProps} bind:grid />
37
+ <GridComponent {...resolved_props} bind:grid />
@@ -1,8 +1,27 @@
1
1
  import type { CellScalar } from "@sheetwrite/core";
2
- import type { Component } from "svelte";
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: Component<SheetwriteProps<Record<string, CellScalar>>, {}, "grid">;
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
- /** Datasource storage policy. */
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
- /** Named custom cell renderers. */
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 UI control configuration. */
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";
@@ -0,0 +1 @@
1
+ @import "@sheetwrite/core/styles/find.css";
@@ -0,0 +1 @@
1
+ @import "@sheetwrite/core/styles/formula-help.css";
@@ -0,0 +1 @@
1
+ @import "@sheetwrite/core/styles/grid.css";
@@ -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";
@@ -0,0 +1 @@
1
+ @import "@sheetwrite/core/styles/tabs.css";