@revolist/svelte-datagrid 4.29.0 → 4.29.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 +5 -0
- package/component-templates.md +28 -0
- package/dist/component-template.d.ts +10 -0
- package/dist/index.d.ts +1 -0
- package/dist/svelte-datagrid.js +47 -14
- package/dist/svelte-datagrid.umd.cjs +47 -14
- package/lib/component-template.ts +44 -0
- package/lib/index.ts +2 -0
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# Component content templates
|
|
2
|
+
|
|
3
|
+
Call `useTemplates()` during component initialization. It captures the
|
|
4
|
+
normal Svelte context map and registers owner cleanup. The helper reuses the
|
|
5
|
+
existing `SvelteTemplateConstructor` and reactive-props implementation.
|
|
6
|
+
|
|
7
|
+
```svelte
|
|
8
|
+
<script lang="ts">
|
|
9
|
+
import { useTemplates } from '@revolist/svelte-datagrid';
|
|
10
|
+
import Card from './Card.svelte';
|
|
11
|
+
const templates = useTemplates();
|
|
12
|
+
const cardContent = templates.template<MyCardContext>(Card);
|
|
13
|
+
</script>
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
No outlet is needed. Components receive a `context` prop; optional
|
|
17
|
+
`{ props: context => ({ item: context.card }) }` maps existing props. Updates
|
|
18
|
+
replace props, including deleting omitted props. Context providers should expose
|
|
19
|
+
reactive objects/stores for updates, following normal Svelte semantics.
|
|
20
|
+
|
|
21
|
+
Use Core `asCellTemplate(definition, { key: p => p.model.id })` for cells,
|
|
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.
|
|
26
|
+
|
|
27
|
+
Existing `Template`, `SvelteTemplateConstructor` and editor APIs remain supported.
|
|
28
|
+
New helpers require the new Core exports; release Core before dependent products.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Component } from 'svelte';
|
|
2
|
+
import { ComponentTemplate } from '@revolist/revogrid';
|
|
3
|
+
export interface SvelteTemplateOwner {
|
|
4
|
+
template<C>(component: Component<any>, options?: {
|
|
5
|
+
props?: (context: C) => Record<string, any>;
|
|
6
|
+
}): ComponentTemplate<C>;
|
|
7
|
+
dispose(): void;
|
|
8
|
+
}
|
|
9
|
+
/** Call during component initialization to capture the normal Svelte context. */
|
|
10
|
+
export declare function useTemplates(): SvelteTemplateOwner;
|
package/dist/index.d.ts
CHANGED
|
@@ -3,3 +3,4 @@ export * from '@revolist/revogrid/loader';
|
|
|
3
3
|
export * from './revogrid';
|
|
4
4
|
export { Template, SvelteTemplateConstructor, type RenderedComponent, type SvelteCellProps, type SvelteElement, } from './renderer';
|
|
5
5
|
export { Editor, type EditorType, SvelteEditorAdapter } from './editor';
|
|
6
|
+
export { useTemplates, type SvelteTemplateOwner } from './component-template';
|
package/dist/svelte-datagrid.js
CHANGED
|
@@ -2,9 +2,9 @@ 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, onMount, unmount } from "svelte";
|
|
5
|
+
import { createEventDispatcher, flushSync, getAllContexts, mount, onDestroy, 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);
|
|
9
9
|
function RevoGrid($$anchor, $$props) {
|
|
10
10
|
$.push($$props, false);
|
|
@@ -269,11 +269,9 @@ function RevoGrid($$anchor, $$props) {
|
|
|
269
269
|
$.bind_prop($$props, "getWebComponent", getWebComponent);
|
|
270
270
|
return $.pop($$exports);
|
|
271
271
|
}
|
|
272
|
-
|
|
273
|
-
//#region lib/revogrid.ts
|
|
272
|
+
// lib/revogrid.ts
|
|
274
273
|
defineCustomElements();
|
|
275
|
-
|
|
276
|
-
//#region lib/reactive-props.svelte.ts
|
|
274
|
+
// lib/reactive-props.svelte.ts
|
|
277
275
|
function createReactiveProps(initialProps) {
|
|
278
276
|
const props = $.proxy({ ...initialProps });
|
|
279
277
|
return {
|
|
@@ -284,8 +282,7 @@ function createReactiveProps(initialProps) {
|
|
|
284
282
|
}
|
|
285
283
|
};
|
|
286
284
|
}
|
|
287
|
-
|
|
288
|
-
//#region lib/renderer.ts
|
|
285
|
+
// lib/renderer.ts
|
|
289
286
|
function getCurrentContext() {
|
|
290
287
|
try {
|
|
291
288
|
return getAllContexts();
|
|
@@ -347,8 +344,7 @@ var Template = (SvelteComponent, customProps) => {
|
|
|
347
344
|
});
|
|
348
345
|
};
|
|
349
346
|
};
|
|
350
|
-
|
|
351
|
-
//#region lib/editor.adapter.ts
|
|
347
|
+
// lib/editor.adapter.ts
|
|
352
348
|
var SvelteEditorAdapter = class {
|
|
353
349
|
EditorComponent;
|
|
354
350
|
column;
|
|
@@ -397,8 +393,7 @@ var SvelteEditorAdapter = class {
|
|
|
397
393
|
});
|
|
398
394
|
}
|
|
399
395
|
};
|
|
400
|
-
|
|
401
|
-
//#region lib/editor.ts
|
|
396
|
+
// lib/editor.ts
|
|
402
397
|
/**
|
|
403
398
|
* Create an editor constructor from a Svelte component.
|
|
404
399
|
*/
|
|
@@ -407,5 +402,43 @@ var Editor = (EditorComponent) => {
|
|
|
407
402
|
return new SvelteEditorAdapter(EditorComponent, column, save, close);
|
|
408
403
|
};
|
|
409
404
|
};
|
|
410
|
-
|
|
411
|
-
|
|
405
|
+
// lib/component-template.ts
|
|
406
|
+
/** Call during component initialization to capture the normal Svelte context. */
|
|
407
|
+
function useTemplates() {
|
|
408
|
+
const context = getAllContexts();
|
|
409
|
+
const destroyers = /* @__PURE__ */ new Set();
|
|
410
|
+
let disposed = false;
|
|
411
|
+
const owner = {
|
|
412
|
+
template(component, options) {
|
|
413
|
+
const props = (value) => options?.props ? options.props(value) : { context: value };
|
|
414
|
+
return {
|
|
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;
|
|
443
|
+
}
|
|
444
|
+
export { Editor, RevoGrid, SvelteEditorAdapter, SvelteTemplateConstructor, Template, useTemplates };
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.SvelteDatagrid = {}, global._revolist_revogrid_loader, global.svelte_internal_disclose_version, global.svelte_internal_flags_legacy, global.svelte_internal_client, global.svelte));
|
|
10
10
|
})(this, function(exports, _revolist_revogrid_loader, svelte_internal_disclose_version, svelte_internal_flags_legacy, svelte_internal_client, svelte) {
|
|
11
11
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
12
|
-
|
|
12
|
+
// \0rolldown/runtime.js
|
|
13
13
|
var __create = Object.create;
|
|
14
14
|
var __defProp = Object.defineProperty;
|
|
15
15
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
@@ -30,9 +30,8 @@
|
|
|
30
30
|
value: mod,
|
|
31
31
|
enumerable: true
|
|
32
32
|
}) : target, mod));
|
|
33
|
-
//#endregion
|
|
34
33
|
svelte_internal_client = __toESM(svelte_internal_client, 1);
|
|
35
|
-
|
|
34
|
+
// lib/components/RevoGrid.ts
|
|
36
35
|
var root = svelte_internal_client.from_html(`<revo-grid><!></revo-grid>`, 2);
|
|
37
36
|
function RevoGrid($$anchor, $$props) {
|
|
38
37
|
svelte_internal_client.push($$props, false);
|
|
@@ -297,11 +296,9 @@
|
|
|
297
296
|
svelte_internal_client.bind_prop($$props, "getWebComponent", getWebComponent);
|
|
298
297
|
return svelte_internal_client.pop($$exports);
|
|
299
298
|
}
|
|
300
|
-
|
|
301
|
-
//#region lib/revogrid.ts
|
|
299
|
+
// lib/revogrid.ts
|
|
302
300
|
(0, _revolist_revogrid_loader.defineCustomElements)();
|
|
303
|
-
|
|
304
|
-
//#region lib/reactive-props.svelte.ts
|
|
301
|
+
// lib/reactive-props.svelte.ts
|
|
305
302
|
function createReactiveProps(initialProps) {
|
|
306
303
|
const props = svelte_internal_client.proxy({ ...initialProps });
|
|
307
304
|
return {
|
|
@@ -312,8 +309,7 @@
|
|
|
312
309
|
}
|
|
313
310
|
};
|
|
314
311
|
}
|
|
315
|
-
|
|
316
|
-
//#region lib/renderer.ts
|
|
312
|
+
// lib/renderer.ts
|
|
317
313
|
function getCurrentContext() {
|
|
318
314
|
try {
|
|
319
315
|
return (0, svelte.getAllContexts)();
|
|
@@ -375,8 +371,7 @@
|
|
|
375
371
|
});
|
|
376
372
|
};
|
|
377
373
|
};
|
|
378
|
-
|
|
379
|
-
//#region lib/editor.adapter.ts
|
|
374
|
+
// lib/editor.adapter.ts
|
|
380
375
|
var SvelteEditorAdapter = class {
|
|
381
376
|
EditorComponent;
|
|
382
377
|
column;
|
|
@@ -425,8 +420,7 @@
|
|
|
425
420
|
});
|
|
426
421
|
}
|
|
427
422
|
};
|
|
428
|
-
|
|
429
|
-
//#region lib/editor.ts
|
|
423
|
+
// lib/editor.ts
|
|
430
424
|
/**
|
|
431
425
|
* Create an editor constructor from a Svelte component.
|
|
432
426
|
*/
|
|
@@ -435,12 +429,51 @@
|
|
|
435
429
|
return new SvelteEditorAdapter(EditorComponent, column, save, close);
|
|
436
430
|
};
|
|
437
431
|
};
|
|
438
|
-
|
|
432
|
+
// lib/component-template.ts
|
|
433
|
+
/** Call during component initialization to capture the normal Svelte context. */
|
|
434
|
+
function useTemplates() {
|
|
435
|
+
const context = (0, svelte.getAllContexts)();
|
|
436
|
+
const destroyers = /* @__PURE__ */ new Set();
|
|
437
|
+
let disposed = false;
|
|
438
|
+
const owner = {
|
|
439
|
+
template(component, options) {
|
|
440
|
+
const props = (value) => options?.props ? options.props(value) : { context: value };
|
|
441
|
+
return {
|
|
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;
|
|
470
|
+
}
|
|
439
471
|
exports.Editor = Editor;
|
|
440
472
|
exports.RevoGrid = RevoGrid;
|
|
441
473
|
exports.SvelteEditorAdapter = SvelteEditorAdapter;
|
|
442
474
|
exports.SvelteTemplateConstructor = SvelteTemplateConstructor;
|
|
443
475
|
exports.Template = Template;
|
|
476
|
+
exports.useTemplates = useTemplates;
|
|
444
477
|
Object.keys(_revolist_revogrid_loader).forEach(function(k) {
|
|
445
478
|
if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
|
|
446
479
|
enumerable: true,
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { getAllContexts, onDestroy, type Component } from 'svelte';
|
|
2
|
+
import type { ComponentTemplate } from '@revolist/revogrid';
|
|
3
|
+
import { SvelteTemplateConstructor } from './renderer';
|
|
4
|
+
|
|
5
|
+
export interface SvelteTemplateOwner {
|
|
6
|
+
template<C>(component: Component<any>, options?: {
|
|
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 {
|
|
14
|
+
const context = getAllContexts();
|
|
15
|
+
const destroyers = new Set<() => void>();
|
|
16
|
+
let disposed = false;
|
|
17
|
+
const owner: SvelteTemplateOwner = {
|
|
18
|
+
template<C>(component: Component<any>, options?: { props?: (context: C) => Record<string, any> }): ComponentTemplate<C> {
|
|
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
|
+
};
|
|
39
|
+
},
|
|
40
|
+
dispose() { disposed = true; for (const destroy of destroyers) destroy(); },
|
|
41
|
+
};
|
|
42
|
+
onDestroy(owner.dispose);
|
|
43
|
+
return owner;
|
|
44
|
+
}
|
package/lib/index.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@revolist/svelte-datagrid",
|
|
3
|
-
"version": "4.29.
|
|
3
|
+
"version": "4.29.1",
|
|
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",
|
|
@@ -15,7 +15,8 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist/",
|
|
18
|
-
"lib/"
|
|
18
|
+
"lib/",
|
|
19
|
+
"component-templates.md"
|
|
19
20
|
],
|
|
20
21
|
"scripts": {
|
|
21
22
|
"dev": "vite",
|
|
@@ -73,7 +74,7 @@
|
|
|
73
74
|
"vite-plugin-dts": "^5.0.1"
|
|
74
75
|
},
|
|
75
76
|
"dependencies": {
|
|
76
|
-
"@revolist/revogrid": "4.29.
|
|
77
|
+
"@revolist/revogrid": "4.29.1"
|
|
77
78
|
},
|
|
78
79
|
"publishConfig": {
|
|
79
80
|
"access": "public"
|