@revolist/svelte-datagrid 4.29.0 → 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/README.md CHANGED
@@ -500,3 +500,8 @@ MIT
500
500
 
501
501
  ---
502
502
 
503
+
504
+ ### Component content templates
505
+
506
+ See [component templates](./component-templates.md) for framework components in
507
+ cells, master details, Kanban cards and Gantt labels. Existing template APIs remain supported.
@@ -0,0 +1,22 @@
1
+ # Framework content templates
2
+
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.
4
+
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
+ ```
15
+
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.
19
+
20
+ Call useTemplates during component initialization. It captures Svelte context and delegates to the existing SvelteTemplateConstructor.
21
+
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.
@@ -0,0 +1,7 @@
1
+ import { Component } from 'svelte';
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/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';
@@ -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>) => (h: HyperFunc<VNode>, p: ColumnDataSchemaModel | ColumnTemplateProp | CellTemplateProp, addition?: any) => VNode;
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;
@@ -4,7 +4,7 @@ import "svelte/internal/flags/legacy";
4
4
  import * as $ from "svelte/internal/client";
5
5
  import { createEventDispatcher, flushSync, getAllContexts, mount, onMount, unmount } from "svelte";
6
6
  export * from "@revolist/revogrid/loader";
7
- //#region lib/components/RevoGrid.ts
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
- //#endregion
273
- //#region lib/revogrid.ts
272
+ // lib/revogrid.ts
274
273
  defineCustomElements();
275
- //#endregion
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
- //#endregion
288
- //#region lib/renderer.ts
285
+ // lib/renderer.ts
289
286
  function getCurrentContext() {
290
287
  try {
291
288
  return getAllContexts();
@@ -329,15 +326,14 @@ function SvelteTemplateConstructor(el, SvelteComponent, initialProps, lastEl = n
329
326
  /**
330
327
  * Render a Svelte component in a RevoGrid column cell template.
331
328
  */
332
- var Template = (SvelteComponent, customProps) => {
333
- const context = getCurrentContext();
329
+ var Template = (SvelteComponent, customProps, options, context = getCurrentContext()) => {
334
330
  return (h, p, addition) => {
335
- const props = {
336
- ...customProps ?? {},
331
+ const props = options?.props ? options.props(p) : {
332
+ ...customProps,
337
333
  ...p,
338
334
  addition
339
335
  };
340
- const key = `${p.prop}-${p.rowIndex || 0}`;
336
+ const key = options?.key?.(p) ?? `${p.prop}-${p.rowIndex || 0}`;
341
337
  let lastEl = null;
342
338
  return h("span", {
343
339
  key,
@@ -347,8 +343,7 @@ var Template = (SvelteComponent, customProps) => {
347
343
  });
348
344
  };
349
345
  };
350
- //#endregion
351
- //#region lib/editor.adapter.ts
346
+ // lib/editor.adapter.ts
352
347
  var SvelteEditorAdapter = class {
353
348
  EditorComponent;
354
349
  column;
@@ -397,8 +392,7 @@ var SvelteEditorAdapter = class {
397
392
  });
398
393
  }
399
394
  };
400
- //#endregion
401
- //#region lib/editor.ts
395
+ // lib/editor.ts
402
396
  /**
403
397
  * Create an editor constructor from a Svelte component.
404
398
  */
@@ -407,5 +401,15 @@ var Editor = (EditorComponent) => {
407
401
  return new SvelteEditorAdapter(EditorComponent, column, save, close);
408
402
  };
409
403
  };
410
- //#endregion
411
- export { Editor, RevoGrid, SvelteEditorAdapter, SvelteTemplateConstructor, Template };
404
+ // lib/component-template.ts
405
+ /** Bind the existing template factory for use on any content surface. */
406
+ function useTemplates() {
407
+ const context = getAllContexts();
408
+ return { template(component, options) {
409
+ return Template(component, void 0, {
410
+ ...options,
411
+ props: options?.props ?? ((context) => ({ context }))
412
+ }, context);
413
+ } };
414
+ }
415
+ 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
- //#region \0rolldown/runtime.js
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
- //#region lib/components/RevoGrid.ts
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
- //#endregion
301
- //#region lib/revogrid.ts
299
+ // lib/revogrid.ts
302
300
  (0, _revolist_revogrid_loader.defineCustomElements)();
303
- //#endregion
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
- //#endregion
316
- //#region lib/renderer.ts
312
+ // lib/renderer.ts
317
313
  function getCurrentContext() {
318
314
  try {
319
315
  return (0, svelte.getAllContexts)();
@@ -357,15 +353,14 @@
357
353
  /**
358
354
  * Render a Svelte component in a RevoGrid column cell template.
359
355
  */
360
- var Template = (SvelteComponent, customProps) => {
361
- const context = getCurrentContext();
356
+ var Template = (SvelteComponent, customProps, options, context = getCurrentContext()) => {
362
357
  return (h, p, addition) => {
363
- const props = {
364
- ...customProps ?? {},
358
+ const props = options?.props ? options.props(p) : {
359
+ ...customProps,
365
360
  ...p,
366
361
  addition
367
362
  };
368
- const key = `${p.prop}-${p.rowIndex || 0}`;
363
+ const key = options?.key?.(p) ?? `${p.prop}-${p.rowIndex || 0}`;
369
364
  let lastEl = null;
370
365
  return h("span", {
371
366
  key,
@@ -375,8 +370,7 @@
375
370
  });
376
371
  };
377
372
  };
378
- //#endregion
379
- //#region lib/editor.adapter.ts
373
+ // lib/editor.adapter.ts
380
374
  var SvelteEditorAdapter = class {
381
375
  EditorComponent;
382
376
  column;
@@ -425,8 +419,7 @@
425
419
  });
426
420
  }
427
421
  };
428
- //#endregion
429
- //#region lib/editor.ts
422
+ // lib/editor.ts
430
423
  /**
431
424
  * Create an editor constructor from a Svelte component.
432
425
  */
@@ -435,12 +428,23 @@
435
428
  return new SvelteEditorAdapter(EditorComponent, column, save, close);
436
429
  };
437
430
  };
438
- //#endregion
431
+ // lib/component-template.ts
432
+ /** Bind the existing template factory for use on any content surface. */
433
+ function useTemplates() {
434
+ const context = (0, svelte.getAllContexts)();
435
+ return { template(component, options) {
436
+ return Template(component, void 0, {
437
+ ...options,
438
+ props: options?.props ?? ((context) => ({ context }))
439
+ }, context);
440
+ } };
441
+ }
439
442
  exports.Editor = Editor;
440
443
  exports.RevoGrid = RevoGrid;
441
444
  exports.SvelteEditorAdapter = SvelteEditorAdapter;
442
445
  exports.SvelteTemplateConstructor = SvelteTemplateConstructor;
443
446
  exports.Template = Template;
447
+ exports.useTemplates = useTemplates;
444
448
  Object.keys(_revolist_revogrid_loader).forEach(function(k) {
445
449
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
446
450
  enumerable: true,
@@ -0,0 +1,15 @@
1
+ import { getAllContexts, type Component } from 'svelte';
2
+ import { Template } from './renderer';
3
+
4
+ /** Bind the existing template factory for use on any content surface. */
5
+ export function useTemplates() {
6
+ const context = getAllContexts();
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);
11
+ },
12
+ };
13
+ }
14
+
15
+ export type SvelteTemplateOwner = ReturnType<typeof useTemplates>;
package/lib/index.ts CHANGED
@@ -9,3 +9,5 @@ export {
9
9
  type SvelteElement,
10
10
  } from './renderer';
11
11
  export { Editor, type EditorType, SvelteEditorAdapter } from './editor';
12
+
13
+ export { useTemplates, type SvelteTemplateOwner } from './component-template';
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: ColumnDataSchemaModel | ColumnTemplateProp | CellTemplateProp,
94
+ p: C,
94
95
  addition?: any,
95
96
  ) => {
96
- const props = {
97
- ...(customProps ?? {}),
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.29.0",
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",
@@ -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.0"
77
+ "@revolist/revogrid": "4.30.0"
77
78
  },
78
79
  "publishConfig": {
79
80
  "access": "public"