@sheetwrite/svelte 0.7.1 → 0.7.2
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/package.json +2 -2
- package/src/Grid.svelte +28 -3
- package/src/props.ts +7 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sheetwrite/svelte",
|
|
3
|
-
"version": "0.7.
|
|
3
|
+
"version": "0.7.2",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Svelte adapter for Sheetwrite.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -59,7 +59,7 @@
|
|
|
59
59
|
"svelte": ">=5"
|
|
60
60
|
},
|
|
61
61
|
"dependencies": {
|
|
62
|
-
"@sheetwrite/core": "0.7.
|
|
62
|
+
"@sheetwrite/core": "0.7.2"
|
|
63
63
|
},
|
|
64
64
|
"devDependencies": {
|
|
65
65
|
"svelte-check": "4.7.3",
|
package/src/Grid.svelte
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
type GridAdapterEventHandlers,
|
|
7
7
|
type GridPublicationAdapter,
|
|
8
8
|
gridSizeStyle,
|
|
9
|
+
gridSkeletonStyle,
|
|
9
10
|
} from "@sheetwrite/core/adapter";
|
|
10
11
|
import { untrack } from "svelte";
|
|
11
12
|
import type { SheetwriteGridProps as Props } from "./props.js";
|
|
@@ -35,6 +36,7 @@ let {
|
|
|
35
36
|
fill,
|
|
36
37
|
rowBridge: row_bridge,
|
|
37
38
|
fallback,
|
|
39
|
+
skeleton = true,
|
|
38
40
|
onGridChange: on_grid_change,
|
|
39
41
|
onRowDelta: on_row_delta,
|
|
40
42
|
onSelectionChange: on_selection_change,
|
|
@@ -47,6 +49,7 @@ let {
|
|
|
47
49
|
onMutationRejected: on_mutation_rejected,
|
|
48
50
|
onRendererFallback: on_renderer_fallback,
|
|
49
51
|
onDatasourceError: on_datasource_error,
|
|
52
|
+
onLoadingChange: on_loading_change,
|
|
50
53
|
onExportError: on_export_error,
|
|
51
54
|
onKeyBindingsChange: on_key_bindings_change,
|
|
52
55
|
onReady: on_ready,
|
|
@@ -56,7 +59,11 @@ let {
|
|
|
56
59
|
}: Props = $props();
|
|
57
60
|
|
|
58
61
|
let host: HTMLDivElement;
|
|
59
|
-
|
|
62
|
+
// On a page whose WASM is already initialized there is nothing to wait for:
|
|
63
|
+
// the grid paints in the same task, so the cover never shows.
|
|
64
|
+
let initialization_state = $state<"loading" | "ready" | "error">(
|
|
65
|
+
isSheetwriteReady() ? "ready" : "loading",
|
|
66
|
+
);
|
|
60
67
|
|
|
61
68
|
function forward_command_state_change(
|
|
62
69
|
event: Parameters<NonNullable<typeof on_command_state_change>>[0],
|
|
@@ -89,6 +96,8 @@ const handlers: GridAdapterEventHandlers = {
|
|
|
89
96
|
on_renderer_fallback?.(event),
|
|
90
97
|
onDatasourceError: (event: Parameters<NonNullable<typeof on_datasource_error>>[0]) =>
|
|
91
98
|
on_datasource_error?.(event),
|
|
99
|
+
onLoadingChange: (event: Parameters<NonNullable<typeof on_loading_change>>[0]) =>
|
|
100
|
+
on_loading_change?.(event),
|
|
92
101
|
onExportError: (event: Parameters<NonNullable<typeof on_export_error>>[0]) =>
|
|
93
102
|
on_export_error?.(event),
|
|
94
103
|
onKeyBindingsChange: (event: Parameters<NonNullable<typeof on_key_bindings_change>>[0]) =>
|
|
@@ -103,7 +112,7 @@ const lifetime = createAdapterGridController(handlers, {
|
|
|
103
112
|
grid = next_grid ?? undefined;
|
|
104
113
|
},
|
|
105
114
|
setInitializationState(state) {
|
|
106
|
-
|
|
115
|
+
initialization_state = state;
|
|
107
116
|
},
|
|
108
117
|
reportConsumerFailure(thrown) {
|
|
109
118
|
reportError(thrown);
|
|
@@ -136,6 +145,14 @@ $effect(() => {
|
|
|
136
145
|
$effect(() => () => untrack(() => lifetime.unmount()));
|
|
137
146
|
|
|
138
147
|
let sizing = $derived(gridSizeStyle({ height, fill }));
|
|
148
|
+
// The built-in skeleton, sized from the grid's options, when no fallback replaces it.
|
|
149
|
+
let skeleton_style = $derived(
|
|
150
|
+
fallback || !skeleton || initialization_state === "error"
|
|
151
|
+
? null
|
|
152
|
+
: Object.entries(gridSkeletonStyle({ workbook, theme, config, presentation }))
|
|
153
|
+
.map(([name, value]) => `${name}:${value}`)
|
|
154
|
+
.join(";"),
|
|
155
|
+
);
|
|
139
156
|
</script>
|
|
140
157
|
|
|
141
158
|
<div
|
|
@@ -146,5 +163,13 @@ let sizing = $derived(gridSizeStyle({ height, fill }));
|
|
|
146
163
|
style:height={sizing.height}
|
|
147
164
|
style:min-height={sizing.minHeight}
|
|
148
165
|
>
|
|
149
|
-
{#if
|
|
166
|
+
{#if initialization_state !== "ready" && (fallback || skeleton_style !== null)}
|
|
167
|
+
<div class="sheetwrite-fallback">
|
|
168
|
+
{#if fallback}{@render fallback()}{:else}<div
|
|
169
|
+
class="sheetwrite-skeleton"
|
|
170
|
+
aria-hidden="true"
|
|
171
|
+
style={skeleton_style}
|
|
172
|
+
></div>{/if}
|
|
173
|
+
</div>
|
|
174
|
+
{/if}
|
|
150
175
|
</div>
|
package/src/props.ts
CHANGED
|
@@ -61,8 +61,14 @@ export interface SheetwriteGridProps<Id extends RowBridgeId = RowBridgeId>
|
|
|
61
61
|
height?: number | string;
|
|
62
62
|
/** Fills the parent's available size. */
|
|
63
63
|
fill?: true;
|
|
64
|
-
/**
|
|
64
|
+
/**
|
|
65
|
+
* Content that covers the host while WASM loads and until the grid's first
|
|
66
|
+
* frame is painted, then fades out; also shown when initialization fails.
|
|
67
|
+
* Without it the adapter shows the built-in skeleton.
|
|
68
|
+
*/
|
|
65
69
|
fallback?: Snippet;
|
|
70
|
+
/** `false` shows nothing instead of the built-in skeleton while the grid loads. */
|
|
71
|
+
skeleton?: boolean;
|
|
66
72
|
/** Bindable live Grid, cleared on reset or unmount. */
|
|
67
73
|
grid?: Grid;
|
|
68
74
|
}
|