@revolist/svelte-datagrid 4.29.1 → 4.30.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/component-templates.md +16 -22
- package/dist/component-template.d.ts +6 -9
- package/dist/renderer.d.ts +4 -1
- package/dist/svelte-datagrid.js +12 -41
- package/dist/svelte-datagrid.umd.cjs +11 -40
- package/lib/component-template.ts +10 -39
- package/lib/renderer.ts +6 -9
- package/package.json +2 -2
package/component-templates.md
CHANGED
|
@@ -1,28 +1,22 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Framework content templates
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
normal Svelte context map and registers owner cleanup. The helper reuses the
|
|
5
|
-
existing `SvelteTemplateConstructor` and reactive-props implementation.
|
|
3
|
+
`useTemplates()` is a thin wrapper around the existing framework `Template` factory. It returns ordinary template callbacks for cells, master rows, Kanban cards, and Gantt labels. There is no outlet or separate mounting protocol.
|
|
6
4
|
|
|
7
|
-
```
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
```ts
|
|
6
|
+
import { useTemplates } from '@revolist/svelte-datagrid';
|
|
7
|
+
import type { CellTemplateProp } from '@revolist/revogrid';
|
|
8
|
+
|
|
9
|
+
const templates = useTemplates();
|
|
10
|
+
const content = templates.template<CellTemplateProp>(MyCell, {
|
|
11
|
+
props: context => ({ item: context.model }),
|
|
12
|
+
key: context => context.model.id,
|
|
13
|
+
});
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
reactive objects/stores for updates, following normal Svelte semantics.
|
|
16
|
+
Without `props`, the component receives a `context` prop/input. The optional `key` selects record identity when hosts are reused. Supply a stable key for cells whose records may reorder. Mapped props are recomputed when the product invokes the callback, and omitted props are cleared.
|
|
17
|
+
|
|
18
|
+
Use the returned callback directly as `column.cellTemplate`, `masterRow.template`, `customization.cardContent`, or `gantt.visuals.taskBarContent`. Product progress, resize, dependency, selection and drag controls remain outside the custom content. The legacy Gantt content hook takes precedence. Exports retain the default product representation.
|
|
20
19
|
|
|
21
|
-
|
|
22
|
-
`masterRow.template` for master details, `customization.cardContent` for Kanban,
|
|
23
|
-
and `gantt.visuals.taskBarContent` for Gantt labels. Offscreen content unmounts;
|
|
24
|
-
keep durable state in app data. `dispose()` releases owned instances. Product
|
|
25
|
-
controls and default exports remain unchanged.
|
|
20
|
+
Call useTemplates during component initialization. It captures Svelte context and delegates to the existing SvelteTemplateConstructor.
|
|
26
21
|
|
|
27
|
-
Existing `Template
|
|
28
|
-
New helpers require the new Core exports; release Core before dependent products.
|
|
22
|
+
Templates use the existing renderer’s ref cleanup and product caching behavior; `useTemplates` adds no lifecycle management. Existing `Template` and editor signatures remain available; their default cell prop shape is unchanged.
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { Component } from 'svelte';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}
|
|
9
|
-
/** Call during component initialization to capture the normal Svelte context. */
|
|
10
|
-
export declare function useTemplates(): SvelteTemplateOwner;
|
|
2
|
+
import { Template } from './renderer';
|
|
3
|
+
/** Bind the existing template factory for use on any content surface. */
|
|
4
|
+
export declare function useTemplates(): {
|
|
5
|
+
template<C>(component: Component<any>, options?: Parameters<typeof Template<any, C>>[2]): (h: import('@revolist/revogrid').HyperFunc<import('@revolist/revogrid').VNode>, p: C, addition?: any) => import('@revolist/revogrid').VNode;
|
|
6
|
+
};
|
|
7
|
+
export type SvelteTemplateOwner = ReturnType<typeof useTemplates>;
|
package/dist/renderer.d.ts
CHANGED
|
@@ -19,4 +19,7 @@ export declare function SvelteTemplateConstructor<T extends Record<string, any>>
|
|
|
19
19
|
/**
|
|
20
20
|
* Render a Svelte component in a RevoGrid column cell template.
|
|
21
21
|
*/
|
|
22
|
-
export declare const Template: <TProps extends Record<string, any> = SvelteCellProps>(SvelteComponent: Component<TProps>, customProps?: Partial<TProps
|
|
22
|
+
export declare const Template: <TProps extends Record<string, any> = SvelteCellProps, C = CellTemplateProp | ColumnDataSchemaModel | ColumnTemplateProp>(SvelteComponent: Component<TProps>, customProps?: Partial<TProps>, options?: {
|
|
23
|
+
props?: (context: C) => Record<string, any>;
|
|
24
|
+
key?: (context: C) => string | number;
|
|
25
|
+
}, context?: Map<any, any> | undefined) => (h: HyperFunc<VNode>, p: C, addition?: any) => VNode;
|
package/dist/svelte-datagrid.js
CHANGED
|
@@ -2,7 +2,7 @@ import { defineCustomElements } from "@revolist/revogrid/loader";
|
|
|
2
2
|
import "svelte/internal/disclose-version";
|
|
3
3
|
import "svelte/internal/flags/legacy";
|
|
4
4
|
import * as $ from "svelte/internal/client";
|
|
5
|
-
import { createEventDispatcher, flushSync, getAllContexts, mount,
|
|
5
|
+
import { createEventDispatcher, flushSync, getAllContexts, mount, onMount, unmount } from "svelte";
|
|
6
6
|
export * from "@revolist/revogrid/loader";
|
|
7
7
|
// lib/components/RevoGrid.ts
|
|
8
8
|
var root = $.from_html(`<revo-grid><!></revo-grid>`, 2);
|
|
@@ -326,15 +326,14 @@ function SvelteTemplateConstructor(el, SvelteComponent, initialProps, lastEl = n
|
|
|
326
326
|
/**
|
|
327
327
|
* Render a Svelte component in a RevoGrid column cell template.
|
|
328
328
|
*/
|
|
329
|
-
var Template = (SvelteComponent, customProps) => {
|
|
330
|
-
const context = getCurrentContext();
|
|
329
|
+
var Template = (SvelteComponent, customProps, options, context = getCurrentContext()) => {
|
|
331
330
|
return (h, p, addition) => {
|
|
332
|
-
const props = {
|
|
333
|
-
...customProps
|
|
331
|
+
const props = options?.props ? options.props(p) : {
|
|
332
|
+
...customProps,
|
|
334
333
|
...p,
|
|
335
334
|
addition
|
|
336
335
|
};
|
|
337
|
-
const key = `${p.prop}-${p.rowIndex || 0}`;
|
|
336
|
+
const key = options?.key?.(p) ?? `${p.prop}-${p.rowIndex || 0}`;
|
|
338
337
|
let lastEl = null;
|
|
339
338
|
return h("span", {
|
|
340
339
|
key,
|
|
@@ -403,42 +402,14 @@ var Editor = (EditorComponent) => {
|
|
|
403
402
|
};
|
|
404
403
|
};
|
|
405
404
|
// lib/component-template.ts
|
|
406
|
-
/**
|
|
405
|
+
/** Bind the existing template factory for use on any content surface. */
|
|
407
406
|
function useTemplates() {
|
|
408
407
|
const context = getAllContexts();
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
kind: "revo-component-template",
|
|
416
|
-
mount(host, value) {
|
|
417
|
-
if (disposed) throw new Error("Cannot mount a template from a disposed Svelte template owner.");
|
|
418
|
-
const instance = SvelteTemplateConstructor(host, component, props(value), null, context);
|
|
419
|
-
let destroyed = false;
|
|
420
|
-
const destroy = () => {
|
|
421
|
-
if (destroyed) return;
|
|
422
|
-
destroyed = true;
|
|
423
|
-
destroyers.delete(destroy);
|
|
424
|
-
instance.destroy();
|
|
425
|
-
};
|
|
426
|
-
destroyers.add(destroy);
|
|
427
|
-
return {
|
|
428
|
-
update(next) {
|
|
429
|
-
if (!destroyed && !disposed) instance.update(props(next));
|
|
430
|
-
},
|
|
431
|
-
destroy
|
|
432
|
-
};
|
|
433
|
-
}
|
|
434
|
-
};
|
|
435
|
-
},
|
|
436
|
-
dispose() {
|
|
437
|
-
disposed = true;
|
|
438
|
-
for (const destroy of destroyers) destroy();
|
|
439
|
-
}
|
|
440
|
-
};
|
|
441
|
-
onDestroy(owner.dispose);
|
|
442
|
-
return owner;
|
|
408
|
+
return { template(component, options) {
|
|
409
|
+
return Template(component, void 0, {
|
|
410
|
+
...options,
|
|
411
|
+
props: options?.props ?? ((context) => ({ context }))
|
|
412
|
+
}, context);
|
|
413
|
+
} };
|
|
443
414
|
}
|
|
444
415
|
export { Editor, RevoGrid, SvelteEditorAdapter, SvelteTemplateConstructor, Template, useTemplates };
|
|
@@ -353,15 +353,14 @@
|
|
|
353
353
|
/**
|
|
354
354
|
* Render a Svelte component in a RevoGrid column cell template.
|
|
355
355
|
*/
|
|
356
|
-
var Template = (SvelteComponent, customProps) => {
|
|
357
|
-
const context = getCurrentContext();
|
|
356
|
+
var Template = (SvelteComponent, customProps, options, context = getCurrentContext()) => {
|
|
358
357
|
return (h, p, addition) => {
|
|
359
|
-
const props = {
|
|
360
|
-
...customProps
|
|
358
|
+
const props = options?.props ? options.props(p) : {
|
|
359
|
+
...customProps,
|
|
361
360
|
...p,
|
|
362
361
|
addition
|
|
363
362
|
};
|
|
364
|
-
const key = `${p.prop}-${p.rowIndex || 0}`;
|
|
363
|
+
const key = options?.key?.(p) ?? `${p.prop}-${p.rowIndex || 0}`;
|
|
365
364
|
let lastEl = null;
|
|
366
365
|
return h("span", {
|
|
367
366
|
key,
|
|
@@ -430,43 +429,15 @@
|
|
|
430
429
|
};
|
|
431
430
|
};
|
|
432
431
|
// lib/component-template.ts
|
|
433
|
-
/**
|
|
432
|
+
/** Bind the existing template factory for use on any content surface. */
|
|
434
433
|
function useTemplates() {
|
|
435
434
|
const context = (0, svelte.getAllContexts)();
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
kind: "revo-component-template",
|
|
443
|
-
mount(host, value) {
|
|
444
|
-
if (disposed) throw new Error("Cannot mount a template from a disposed Svelte template owner.");
|
|
445
|
-
const instance = SvelteTemplateConstructor(host, component, props(value), null, context);
|
|
446
|
-
let destroyed = false;
|
|
447
|
-
const destroy = () => {
|
|
448
|
-
if (destroyed) return;
|
|
449
|
-
destroyed = true;
|
|
450
|
-
destroyers.delete(destroy);
|
|
451
|
-
instance.destroy();
|
|
452
|
-
};
|
|
453
|
-
destroyers.add(destroy);
|
|
454
|
-
return {
|
|
455
|
-
update(next) {
|
|
456
|
-
if (!destroyed && !disposed) instance.update(props(next));
|
|
457
|
-
},
|
|
458
|
-
destroy
|
|
459
|
-
};
|
|
460
|
-
}
|
|
461
|
-
};
|
|
462
|
-
},
|
|
463
|
-
dispose() {
|
|
464
|
-
disposed = true;
|
|
465
|
-
for (const destroy of destroyers) destroy();
|
|
466
|
-
}
|
|
467
|
-
};
|
|
468
|
-
(0, svelte.onDestroy)(owner.dispose);
|
|
469
|
-
return owner;
|
|
435
|
+
return { template(component, options) {
|
|
436
|
+
return Template(component, void 0, {
|
|
437
|
+
...options,
|
|
438
|
+
props: options?.props ?? ((context) => ({ context }))
|
|
439
|
+
}, context);
|
|
440
|
+
} };
|
|
470
441
|
}
|
|
471
442
|
exports.Editor = Editor;
|
|
472
443
|
exports.RevoGrid = RevoGrid;
|
|
@@ -1,44 +1,15 @@
|
|
|
1
|
-
import { getAllContexts,
|
|
2
|
-
import
|
|
3
|
-
import { SvelteTemplateConstructor } from './renderer';
|
|
1
|
+
import { getAllContexts, type Component } from 'svelte';
|
|
2
|
+
import { Template } from './renderer';
|
|
4
3
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
props?: (context: C) => Record<string, any>;
|
|
8
|
-
}): ComponentTemplate<C>;
|
|
9
|
-
dispose(): void;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/** Call during component initialization to capture the normal Svelte context. */
|
|
13
|
-
export function useTemplates(): SvelteTemplateOwner {
|
|
4
|
+
/** Bind the existing template factory for use on any content surface. */
|
|
5
|
+
export function useTemplates() {
|
|
14
6
|
const context = getAllContexts();
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
const props = (value: C) => options?.props ? options.props(value) : { context: value };
|
|
20
|
-
return {
|
|
21
|
-
kind: 'revo-component-template',
|
|
22
|
-
mount(host, value) {
|
|
23
|
-
if (disposed) throw new Error('Cannot mount a template from a disposed Svelte template owner.');
|
|
24
|
-
const instance = SvelteTemplateConstructor(host, component, props(value), null, context)!;
|
|
25
|
-
let destroyed = false;
|
|
26
|
-
const destroy = () => {
|
|
27
|
-
if (destroyed) return;
|
|
28
|
-
destroyed = true;
|
|
29
|
-
destroyers.delete(destroy);
|
|
30
|
-
instance.destroy();
|
|
31
|
-
};
|
|
32
|
-
destroyers.add(destroy);
|
|
33
|
-
return {
|
|
34
|
-
update(next) { if (!destroyed && !disposed) instance.update(props(next)); },
|
|
35
|
-
destroy,
|
|
36
|
-
};
|
|
37
|
-
},
|
|
38
|
-
};
|
|
7
|
+
return {
|
|
8
|
+
template<C>(component: Component<any>, options?: Parameters<typeof Template<any, C>>[2]) {
|
|
9
|
+
const adapted = { ...options, props: options?.props ?? ((context: C) => ({ context })) };
|
|
10
|
+
return Template<any, C>(component, undefined, adapted, context);
|
|
39
11
|
},
|
|
40
|
-
dispose() { disposed = true; for (const destroy of destroyers) destroy(); },
|
|
41
12
|
};
|
|
42
|
-
onDestroy(owner.dispose);
|
|
43
|
-
return owner;
|
|
44
13
|
}
|
|
14
|
+
|
|
15
|
+
export type SvelteTemplateOwner = ReturnType<typeof useTemplates>;
|
package/lib/renderer.ts
CHANGED
|
@@ -82,23 +82,20 @@ export function SvelteTemplateConstructor<T extends Record<string, any>>(
|
|
|
82
82
|
/**
|
|
83
83
|
* Render a Svelte component in a RevoGrid column cell template.
|
|
84
84
|
*/
|
|
85
|
-
export const Template = <TProps extends Record<string, any> = SvelteCellProps>(
|
|
85
|
+
export const Template = <TProps extends Record<string, any> = SvelteCellProps, C = CellTemplateProp | ColumnDataSchemaModel | ColumnTemplateProp>(
|
|
86
86
|
SvelteComponent: Component<TProps>,
|
|
87
87
|
customProps?: Partial<TProps>,
|
|
88
|
+
options?: { props?: (context: C) => Record<string, any>; key?: (context: C) => string | number },
|
|
89
|
+
context = getCurrentContext(),
|
|
88
90
|
) => {
|
|
89
|
-
const context = getCurrentContext();
|
|
90
91
|
|
|
91
92
|
return (
|
|
92
93
|
h: HyperFunc<VNode>,
|
|
93
|
-
p:
|
|
94
|
+
p: C,
|
|
94
95
|
addition?: any,
|
|
95
96
|
) => {
|
|
96
|
-
const props = {
|
|
97
|
-
|
|
98
|
-
...p,
|
|
99
|
-
addition,
|
|
100
|
-
} as unknown as TProps;
|
|
101
|
-
const key = `${p.prop}-${p.rowIndex || 0}`;
|
|
97
|
+
const props = (options?.props ? options.props(p) : { ...customProps, ...p, addition }) as TProps;
|
|
98
|
+
const key = options?.key?.(p) ?? `${(p as any).prop}-${(p as any).rowIndex || 0}`;
|
|
102
99
|
let lastEl: RenderedComponent<TProps> | null = null;
|
|
103
100
|
|
|
104
101
|
return h('span', {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revolist/svelte-datagrid",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.30.0",
|
|
4
4
|
"description": "Svelte DataGrid Spreadsheet component with native cell render support",
|
|
5
5
|
"main": "./dist/svelte-datagrid.umd.cjs",
|
|
6
6
|
"module": "./dist/svelte-datagrid.js",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"vite-plugin-dts": "^5.0.1"
|
|
75
75
|
},
|
|
76
76
|
"dependencies": {
|
|
77
|
-
"@revolist/revogrid": "4.
|
|
77
|
+
"@revolist/revogrid": "4.30.0"
|
|
78
78
|
},
|
|
79
79
|
"publishConfig": {
|
|
80
80
|
"access": "public"
|