@handsontable/angular-wrapper 0.0.0-next-c272dd6-20261013 → 0.0.0-next-a26137c-20261014

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.
@@ -1,50 +1,64 @@
1
- import * as i0 from '@angular/core';
2
- import { ViewContainerRef, ViewChild, Input, ChangeDetectionStrategy, Component, createComponent, Directive, EventEmitter, Output, HostBinding, Injectable, InjectionToken, Inject, inject, DestroyRef, ElementRef, ViewEncapsulation, NgModule } from '@angular/core';
3
- import { takeUntilDestroyed } from '@angular/core/rxjs-interop';
4
- import Handsontable from 'handsontable/base';
5
- import { take, skip } from 'rxjs/operators';
6
- import { editorFactory } from 'handsontable/editors/factory';
7
- import { baseRenderer, rendererFactory, registerRenderer } from 'handsontable/renderers';
8
- import { BehaviorSubject } from 'rxjs';
9
-
10
- /**
11
- * Component representing a placeholder for a custom editor in Handsontable.
12
- * It is used only within the wrapper.
13
- */
14
- class CustomEditorPlaceholderComponent {
15
- /** The top position of the editor. */
16
- top;
17
- /** The left position of the editor. */
18
- left;
19
- /** The height of the editor. */
20
- height;
21
- /** The width of the editor. */
22
- width;
23
- set isVisible(value) {
24
- this._isVisible = value;
25
- }
26
- placeholderCustomClass = 'handsontableInputHolder ht_clone_master';
27
- /** The reference to the component instance of the editor. */
28
- set componentRef(hotEditorComponentRef) {
29
- if (hotEditorComponentRef) {
30
- this.container.insert(hotEditorComponentRef.hostView);
31
- }
32
- }
33
- /** The container for the editor's input placeholder. */
34
- container;
35
- /** The display style of the editor. */
36
- get display() {
37
- return this._isVisible ? 'block' : 'none';
38
- }
39
- _isVisible = false;
40
- /**
41
- * Detaches the container from the Handsontable.
42
- */
43
- detachEditor() {
44
- this.container.detach();
45
- }
46
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: CustomEditorPlaceholderComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
47
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: CustomEditorPlaceholderComponent, isStandalone: true, selector: "ng-component", inputs: { top: "top", left: "left", height: "height", width: "width", isVisible: "isVisible", placeholderCustomClass: "placeholderCustomClass", componentRef: "componentRef" }, viewQueries: [{ propertyName: "container", first: true, predicate: ["inputPlaceholder"], descendants: true, read: ViewContainerRef, static: true }], ngImport: i0, template: ` <div
1
+ import * as i0 from "@angular/core";
2
+ import { ChangeDetectionStrategy, Component, DestroyRef, Directive, ElementRef, EventEmitter, HostBinding, Inject, Injectable, InjectionToken, Input, NgModule, Output, ViewChild, ViewContainerRef, ViewEncapsulation, createComponent, inject } from "@angular/core";
3
+ import { takeUntilDestroyed } from "@angular/core/rxjs-interop";
4
+ import Handsontable from "handsontable/base";
5
+ import { skip, take } from "rxjs/operators";
6
+ import { editorFactory } from "handsontable/editors/factory";
7
+ import { baseRenderer, registerRenderer, rendererFactory } from "handsontable/renderers";
8
+ import { BehaviorSubject } from "rxjs";
9
+ var CustomEditorPlaceholderComponent = class CustomEditorPlaceholderComponent {
10
+ top;
11
+ left;
12
+ height;
13
+ width;
14
+ set isVisible(value) {
15
+ this._isVisible = value;
16
+ }
17
+ placeholderCustomClass = "handsontableInputHolder ht_clone_master";
18
+ set componentRef(hotEditorComponentRef) {
19
+ if (hotEditorComponentRef) this.container.insert(hotEditorComponentRef.hostView);
20
+ }
21
+ container;
22
+ get display() {
23
+ return this._isVisible ? "block" : "none";
24
+ }
25
+ _isVisible = false;
26
+ detachEditor() {
27
+ this.container.detach();
28
+ }
29
+ static ɵfac = i0.ɵɵngDeclareFactory({
30
+ minVersion: "12.0.0",
31
+ version: "22.2.2",
32
+ ngImport: i0,
33
+ type: CustomEditorPlaceholderComponent,
34
+ deps: [],
35
+ target: i0.ɵɵFactoryTarget.Component
36
+ });
37
+ static ɵcmp = i0.ɵɵngDeclareComponent({
38
+ minVersion: "14.0.0",
39
+ version: "22.2.2",
40
+ type: CustomEditorPlaceholderComponent,
41
+ isStandalone: true,
42
+ selector: "ng-component",
43
+ inputs: {
44
+ top: "top",
45
+ left: "left",
46
+ height: "height",
47
+ width: "width",
48
+ isVisible: "isVisible",
49
+ placeholderCustomClass: "placeholderCustomClass",
50
+ componentRef: "componentRef"
51
+ },
52
+ viewQueries: [{
53
+ propertyName: "container",
54
+ first: true,
55
+ predicate: ["inputPlaceholder"],
56
+ descendants: true,
57
+ read: ViewContainerRef,
58
+ static: true
59
+ }],
60
+ ngImport: i0,
61
+ template: ` <div
48
62
  [class]="placeholderCustomClass"
49
63
  [style.display]="display"
50
64
  [style.width.px]="width"
@@ -55,12 +69,20 @@ class CustomEditorPlaceholderComponent {
55
69
  [style.left.px]="left"
56
70
  >
57
71
  <ng-template #inputPlaceholder></ng-template>
58
- </div>`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
59
- }
60
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: CustomEditorPlaceholderComponent, decorators: [{
61
- type: Component,
62
- args: [{
63
- template: ` <div
72
+ </div>`,
73
+ isInline: true,
74
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
75
+ });
76
+ };
77
+ i0.ɵɵngDeclareClassMetadata({
78
+ minVersion: "12.0.0",
79
+ version: "22.2.2",
80
+ ngImport: i0,
81
+ type: CustomEditorPlaceholderComponent,
82
+ decorators: [{
83
+ type: Component,
84
+ args: [{
85
+ template: ` <div
64
86
  [class]="placeholderCustomClass"
65
87
  [style.display]="display"
66
88
  [style.width.px]="width"
@@ -72,1558 +94,1179 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImpo
72
94
  >
73
95
  <ng-template #inputPlaceholder></ng-template>
74
96
  </div>`,
75
- changeDetection: ChangeDetectionStrategy.OnPush,
76
- standalone: true,
77
- }]
78
- }], propDecorators: { top: [{
79
- type: Input
80
- }], left: [{
81
- type: Input
82
- }], height: [{
83
- type: Input
84
- }], width: [{
85
- type: Input
86
- }], isVisible: [{
87
- type: Input
88
- }], placeholderCustomClass: [{
89
- type: Input
90
- }], componentRef: [{
91
- type: Input
92
- }], container: [{
93
- type: ViewChild,
94
- args: ['inputPlaceholder', { read: ViewContainerRef, static: true }]
95
- }] } });
96
-
97
- /**
98
- * Adapter for BaseEditor from Handsontable.
99
- */
100
- class BaseEditorAdapter extends Handsontable.editors.BaseEditor {
101
- /** Reference to the custom editor component. */
102
- _componentRef;
103
- /** Reference to the editor placeholder component. */
104
- _editorPlaceHolderRef;
105
- /** Flag indicating whether the placeholder is ready. */
106
- _isPlaceholderReady = false;
107
- /** Subscription for the finish edit event. */
108
- _finishEditSubscription;
109
- /** Subscription for the cancel edit event. */
110
- _cancelEditSubscription;
111
- /**
112
- * Creates an instance of BaseEditorAdapter.
113
- * @param instance The Handsontable instance.
114
- */
115
- constructor(instance) {
116
- super(instance);
117
- this.hot.addHook('afterRowResize', this.onAfterRowResize.bind(this));
118
- this.hot.addHook('afterColumnResize', this.onAfterColumnResize.bind(this));
119
- this.hot.addHook('afterDestroy', this.onAfterDestroy.bind(this));
120
- }
121
- /**
122
- * Prepares the editor for editing. Parameters are passed from Handsontable.
123
- * @param row The row index.
124
- * @param column The column index.
125
- * @param prop The property name.
126
- * @param TD The table cell element.
127
- * @param originalValue The original value of the cell.
128
- * @param cellProperties The cell properties.
129
- */
130
- prepare(row, column, prop, TD, originalValue, cellProperties) {
131
- if (!this.isOpened()) {
132
- super.prepare(row, column, prop, TD, originalValue, cellProperties);
133
- const columnMeta = this.hot.getColumnMeta(column);
134
- if (!this._isPlaceholderReady) {
135
- this.createEditorPlaceholder(columnMeta._environmentInjector);
136
- this._isPlaceholderReady = true;
137
- }
138
- this._componentRef = columnMeta._editorComponentReference;
139
- this.cleanupSubscriptions();
140
- this._finishEditSubscription = this._componentRef.instance.finishEdit
141
- .pipe(take(1))
142
- .subscribe(() => {
143
- this.finishEditing();
144
- });
145
- this._cancelEditSubscription = this._componentRef.instance.cancelEdit
146
- .pipe(take(1))
147
- .subscribe(() => {
148
- this.cancelChanges();
149
- });
150
- }
151
- }
152
- /**
153
- * Closes the editor. This event is triggered by Handsontable.
154
- */
155
- close() {
156
- if (this.isOpened()) {
157
- this.resetEditorState();
158
- this._editorPlaceHolderRef?.changeDetectorRef.detectChanges();
159
- this._editorPlaceHolderRef?.instance.detachEditor();
160
- this._componentRef?.instance.onClose();
161
- }
162
- }
163
- /**
164
- * Focuses the editor. This event is triggered by Handsontable.
165
- */
166
- focus() {
167
- this._componentRef?.instance.onFocus();
168
- }
169
- /**
170
- * Gets the value from the editor.
171
- * @returns The value from the editor.
172
- */
173
- getValue() {
174
- return this._componentRef?.instance?.getValue();
175
- }
176
- /**
177
- * Opens the editor. This event is triggered by Handsontable.
178
- * When opening, we set the shortcut context to 'editor'.
179
- * This allows the built-in keyboard shortcuts to operate within the editor.
180
- * @param event The event that triggered the opening of the editor.
181
- * @remarks When entering edit mode using double-click, keyboard shortcuts do not work.
182
- */
183
- open(event) {
184
- this.hot.getShortcutManager().setActiveContextName('editor');
185
- this.applyPropsToEditor();
186
- this._componentRef?.instance.onOpen(event);
187
- }
188
- /**
189
- * Sets the value for the custom editor.
190
- * @param newValue The value to set.
191
- */
192
- setValue(newValue) {
193
- this._componentRef?.instance?.setValue(newValue);
194
- this._componentRef?.changeDetectorRef.detectChanges();
195
- }
196
- /**
197
- * Applies properties to the custom editor and editor placeholder.
198
- */
199
- applyPropsToEditor() {
200
- if (!this._componentRef || !this._editorPlaceHolderRef) {
201
- return;
202
- }
203
- const rect = this.getEditedCellRect();
204
- if (!this.isInFullEditMode()) {
205
- this._componentRef.instance.setValue(null);
206
- }
207
- this._componentRef.setInput('originalValue', this.originalValue);
208
- this._componentRef.setInput('row', this.row);
209
- this._componentRef.setInput('column', this.col);
210
- this._componentRef.setInput('prop', this.prop);
211
- this._componentRef.setInput('cellProperties', this.cellProperties);
212
- this._editorPlaceHolderRef.setInput('top', rect.top);
213
- this._editorPlaceHolderRef.setInput('left', rect.start);
214
- this._editorPlaceHolderRef.setInput('height', rect.height);
215
- this._editorPlaceHolderRef.setInput('width', rect.width);
216
- this._editorPlaceHolderRef.setInput('isVisible', true);
217
- this._editorPlaceHolderRef.setInput('componentRef', this._componentRef);
218
- this._editorPlaceHolderRef.changeDetectorRef.detectChanges();
219
- }
220
- /**
221
- * Creates the editor placeholder and append it to hot rootElement.
222
- * @param injector The environment injector.
223
- */
224
- createEditorPlaceholder(injector) {
225
- this._editorPlaceHolderRef = createComponent(CustomEditorPlaceholderComponent, {
226
- environmentInjector: injector,
227
- });
228
- this.hot.rootElement.appendChild(this._editorPlaceHolderRef.location.nativeElement);
229
- }
230
- /**
231
- * Handles the after column resize event.
232
- * Helps adjust the editor size to the column size and update its position.
233
- */
234
- onAfterColumnResize() {
235
- if (this.isOpened()) {
236
- this.applyPropsToEditor();
237
- }
238
- }
239
- /**
240
- * Handles the after row resize event.
241
- * Helps adjust the editor size to the column size and update its position.
242
- */
243
- onAfterRowResize() {
244
- if (this.isOpened()) {
245
- this.applyPropsToEditor();
246
- }
247
- }
248
- /**
249
- * Handles the after destroy event.
250
- */
251
- onAfterDestroy() {
252
- this.cleanupSubscriptions();
253
- this._editorPlaceHolderRef?.destroy();
254
- }
255
- /**
256
- * Unsubscribes the finish/cancel edit subscriptions if they are still active.
257
- * Without this, destroying the table while an editor was prepared but never
258
- * finished/canceled leaves the `take(1)` subscriptions hanging (they never emit).
259
- */
260
- cleanupSubscriptions() {
261
- if (this._finishEditSubscription) {
262
- this._finishEditSubscription.unsubscribe();
263
- this._finishEditSubscription = undefined;
264
- }
265
- if (this._cancelEditSubscription) {
266
- this._cancelEditSubscription.unsubscribe();
267
- this._cancelEditSubscription = undefined;
268
- }
269
- }
270
- /**
271
- * Resets the editor placeholder state.
272
- * We need to reset the editor placeholder state because we use it
273
- * to store multiple references to the custom editor.
274
- */
275
- resetEditorState() {
276
- if (!this._editorPlaceHolderRef) {
277
- return;
278
- }
279
- this._editorPlaceHolderRef.setInput('top', undefined);
280
- this._editorPlaceHolderRef.setInput('left', undefined);
281
- this._editorPlaceHolderRef.setInput('height', undefined);
282
- this._editorPlaceHolderRef.setInput('width', undefined);
283
- this._editorPlaceHolderRef.setInput('isVisible', false);
284
- this._editorPlaceHolderRef.setInput('componentRef', undefined);
285
- }
286
- }
287
-
288
- /**
289
- * Shared base directive for HotCellRendererComponent and HotCellRendererAdvancedComponent.
290
- * Holds all @Input() properties and getProps() that both renderer variants share.
291
- *
292
- * @template TValue - The type of the rendered cell value.
293
- * @template TProps - The type of additional renderer properties.
294
- */
295
- class HotCellRendererBase {
296
- value = '';
297
- instance;
298
- td;
299
- row;
300
- col;
301
- prop;
302
- cellProperties;
303
- getProps() {
304
- return this.cellProperties?.rendererProps ?? {};
305
- }
306
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellRendererBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
307
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: HotCellRendererBase, isStandalone: true, inputs: { value: "value", instance: "instance", td: "td", row: "row", col: "col", prop: "prop", cellProperties: "cellProperties" }, ngImport: i0 });
308
- }
309
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellRendererBase, decorators: [{
310
- type: Directive
311
- }], propDecorators: { value: [{
312
- type: Input
313
- }], instance: [{
314
- type: Input
315
- }], td: [{
316
- type: Input
317
- }], row: [{
318
- type: Input
319
- }], col: [{
320
- type: Input
321
- }], prop: [{
322
- type: Input
323
- }], cellProperties: [{
324
- type: Input
325
- }] } });
326
-
327
- /**
328
- * Abstract base component for creating custom cell renderer components for Handsontable.
329
- *
330
- * Extend this component and provide your own template to implement a custom renderer.
331
- * Value type is limited to primitives (`string | number | boolean`).
332
- * For object and array values use {@link HotCellRendererAdvancedComponent}.
333
- *
334
- * @template TValue - The type of the component renderer.
335
- * @template TProps - The type of additional renderer properties.
336
- */
337
- class HotCellRendererComponent extends HotCellRendererBase {
338
- static RENDERER_MARKER = Symbol('HotCellRendererComponent');
339
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellRendererComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
340
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: HotCellRendererComponent, isStandalone: true, selector: "hot-cell-renderer", usesInheritance: true, ngImport: i0, template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
341
- }
342
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellRendererComponent, decorators: [{
343
- type: Component,
344
- args: [{
345
- selector: 'hot-cell-renderer',
346
- template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`,
347
- standalone: true,
348
- changeDetection: ChangeDetectionStrategy.OnPush,
349
- }]
350
- }] });
351
-
352
- /**
353
- * Shared base directive for HotCellEditorComponent and HotCellEditorAdvancedComponent.
354
- * Holds all @Input(), @Output() and @HostBinding() declarations that both editor variants share.
355
- *
356
- * @template T - The type of the edited cell value.
357
- */
358
- class HotCellEditorBase {
359
- heightFitParentContainer = 100;
360
- widthFitParentContainer = 100;
361
- row;
362
- column;
363
- prop;
364
- originalValue;
365
- cellProperties;
366
- finishEdit = new EventEmitter();
367
- cancelEdit = new EventEmitter();
368
- value;
369
- getValue() {
370
- return this.value;
371
- }
372
- setValue(value) {
373
- this.value = value;
374
- }
375
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellEditorBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
376
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: HotCellEditorBase, isStandalone: true, inputs: { row: "row", column: "column", prop: "prop", originalValue: "originalValue", cellProperties: "cellProperties" }, outputs: { finishEdit: "finishEdit", cancelEdit: "cancelEdit" }, host: { properties: { "style.height.%": "this.heightFitParentContainer", "style.width.%": "this.widthFitParentContainer" } }, ngImport: i0 });
377
- }
378
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellEditorBase, decorators: [{
379
- type: Directive
380
- }], propDecorators: { heightFitParentContainer: [{
381
- type: HostBinding,
382
- args: ['style.height.%']
383
- }], widthFitParentContainer: [{
384
- type: HostBinding,
385
- args: ['style.width.%']
386
- }], row: [{
387
- type: Input
388
- }], column: [{
389
- type: Input
390
- }], prop: [{
391
- type: Input
392
- }], originalValue: [{
393
- type: Input
394
- }], cellProperties: [{
395
- type: Input
396
- }], finishEdit: [{
397
- type: Output
398
- }], cancelEdit: [{
399
- type: Output
400
- }] } });
401
-
402
- /**
403
- * Abstract class representing a basic Handsontable cell editor in Angular.
404
- *
405
- * Extend this class and decorate the subclass with `@Component()` to implement a custom editor.
406
- * Value type is limited to primitives (`string | number | boolean`).
407
- * For object and array values use {@link HotCellEditorAdvancedComponent}.
408
- */
409
- class HotCellEditorComponent extends HotCellEditorBase {
410
- static EDITOR_MARKER = Symbol('HotCellEditorComponent');
411
- /** The tabindex attribute for the editor. */
412
- tabindex = -1;
413
- /** The data-hot-input attribute for the editor. */
414
- dataHotInput = '';
415
- /** The handsontableInput class for the editor. */
416
- handsontableInputClass = true;
417
- /** Event triggered by Handsontable on closing the editor. */
418
- onClose() { }
419
- /** Event triggered by Handsontable on opening the editor. */
420
- onOpen(event) { }
421
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellEditorComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
422
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: HotCellEditorComponent, isStandalone: true, host: { properties: { "attr.tabindex": "this.tabindex", "attr.data-hot-input": "this.dataHotInput", "class.handsontableInput": "this.handsontableInputClass" } }, usesInheritance: true, ngImport: i0 });
423
- }
424
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellEditorComponent, decorators: [{
425
- type: Directive
426
- }], propDecorators: { tabindex: [{
427
- type: HostBinding,
428
- args: ['attr.tabindex']
429
- }], dataHotInput: [{
430
- type: HostBinding,
431
- args: ['attr.data-hot-input']
432
- }], handsontableInputClass: [{
433
- type: HostBinding,
434
- args: ['class.handsontableInput']
435
- }] } });
436
-
437
- /**
438
- * Factory function to create a custom Handsontable editor adapter for Angular components.
439
- *
440
- * This adapter integrates Angular components with Handsontable's editor system using the new
441
- * editorFactory API, allowing you to use Angular components as custom cell editors while
442
- * maintaining full Angular lifecycle management and change detection.
443
- *
444
- * @returns A custom editor class that can be used in Handsontable column settings.
445
- *
446
- */
97
+ changeDetection: ChangeDetectionStrategy.OnPush,
98
+ standalone: true
99
+ }]
100
+ }],
101
+ propDecorators: {
102
+ top: [{ type: Input }],
103
+ left: [{ type: Input }],
104
+ height: [{ type: Input }],
105
+ width: [{ type: Input }],
106
+ isVisible: [{ type: Input }],
107
+ placeholderCustomClass: [{ type: Input }],
108
+ componentRef: [{ type: Input }],
109
+ container: [{
110
+ type: ViewChild,
111
+ args: ["inputPlaceholder", {
112
+ read: ViewContainerRef,
113
+ static: true
114
+ }]
115
+ }]
116
+ }
117
+ });
118
+ var BaseEditorAdapter = class extends Handsontable.editors.BaseEditor {
119
+ _componentRef;
120
+ _editorPlaceHolderRef;
121
+ _isPlaceholderReady = false;
122
+ _finishEditSubscription;
123
+ _cancelEditSubscription;
124
+ constructor(instance) {
125
+ super(instance);
126
+ this.hot.addHook("afterRowResize", this.onAfterRowResize.bind(this));
127
+ this.hot.addHook("afterColumnResize", this.onAfterColumnResize.bind(this));
128
+ this.hot.addHook("afterDestroy", this.onAfterDestroy.bind(this));
129
+ }
130
+ prepare(row, column, prop, TD, originalValue, cellProperties) {
131
+ if (!this.isOpened()) {
132
+ super.prepare(row, column, prop, TD, originalValue, cellProperties);
133
+ const columnMeta = this.hot.getColumnMeta(column);
134
+ if (!this._isPlaceholderReady) {
135
+ this.createEditorPlaceholder(columnMeta._environmentInjector);
136
+ this._isPlaceholderReady = true;
137
+ }
138
+ this._componentRef = columnMeta._editorComponentReference;
139
+ this.cleanupSubscriptions();
140
+ this._finishEditSubscription = this._componentRef.instance.finishEdit.pipe(take(1)).subscribe(() => {
141
+ this.finishEditing();
142
+ });
143
+ this._cancelEditSubscription = this._componentRef.instance.cancelEdit.pipe(take(1)).subscribe(() => {
144
+ this.cancelChanges();
145
+ });
146
+ }
147
+ }
148
+ close() {
149
+ if (this.isOpened()) {
150
+ this.resetEditorState();
151
+ this._editorPlaceHolderRef?.changeDetectorRef.detectChanges();
152
+ this._editorPlaceHolderRef?.instance.detachEditor();
153
+ this._componentRef?.instance.onClose();
154
+ }
155
+ }
156
+ focus() {
157
+ this._componentRef?.instance.onFocus();
158
+ }
159
+ getValue() {
160
+ return this._componentRef?.instance?.getValue();
161
+ }
162
+ open(event) {
163
+ this.hot.getShortcutManager().setActiveContextName("editor");
164
+ this.applyPropsToEditor();
165
+ this._componentRef?.instance.onOpen(event);
166
+ }
167
+ setValue(newValue) {
168
+ this._componentRef?.instance?.setValue(newValue);
169
+ this._componentRef?.changeDetectorRef.detectChanges();
170
+ }
171
+ applyPropsToEditor() {
172
+ if (!this._componentRef || !this._editorPlaceHolderRef) return;
173
+ const rect = this.getEditedCellRect();
174
+ if (!this.isInFullEditMode()) this._componentRef.instance.setValue(null);
175
+ this._componentRef.setInput("originalValue", this.originalValue);
176
+ this._componentRef.setInput("row", this.row);
177
+ this._componentRef.setInput("column", this.col);
178
+ this._componentRef.setInput("prop", this.prop);
179
+ this._componentRef.setInput("cellProperties", this.cellProperties);
180
+ this._editorPlaceHolderRef.setInput("top", rect.top);
181
+ this._editorPlaceHolderRef.setInput("left", rect.start);
182
+ this._editorPlaceHolderRef.setInput("height", rect.height);
183
+ this._editorPlaceHolderRef.setInput("width", rect.width);
184
+ this._editorPlaceHolderRef.setInput("isVisible", true);
185
+ this._editorPlaceHolderRef.setInput("componentRef", this._componentRef);
186
+ this._editorPlaceHolderRef.changeDetectorRef.detectChanges();
187
+ }
188
+ createEditorPlaceholder(injector) {
189
+ this._editorPlaceHolderRef = createComponent(CustomEditorPlaceholderComponent, { environmentInjector: injector });
190
+ this.hot.rootElement.appendChild(this._editorPlaceHolderRef.location.nativeElement);
191
+ }
192
+ onAfterColumnResize() {
193
+ if (this.isOpened()) this.applyPropsToEditor();
194
+ }
195
+ onAfterRowResize() {
196
+ if (this.isOpened()) this.applyPropsToEditor();
197
+ }
198
+ onAfterDestroy() {
199
+ this.cleanupSubscriptions();
200
+ this._editorPlaceHolderRef?.destroy();
201
+ }
202
+ cleanupSubscriptions() {
203
+ if (this._finishEditSubscription) {
204
+ this._finishEditSubscription.unsubscribe();
205
+ this._finishEditSubscription = void 0;
206
+ }
207
+ if (this._cancelEditSubscription) {
208
+ this._cancelEditSubscription.unsubscribe();
209
+ this._cancelEditSubscription = void 0;
210
+ }
211
+ }
212
+ resetEditorState() {
213
+ if (!this._editorPlaceHolderRef) return;
214
+ this._editorPlaceHolderRef.setInput("top", void 0);
215
+ this._editorPlaceHolderRef.setInput("left", void 0);
216
+ this._editorPlaceHolderRef.setInput("height", void 0);
217
+ this._editorPlaceHolderRef.setInput("width", void 0);
218
+ this._editorPlaceHolderRef.setInput("isVisible", false);
219
+ this._editorPlaceHolderRef.setInput("componentRef", void 0);
220
+ }
221
+ };
222
+ var HotCellRendererBase = class HotCellRendererBase {
223
+ value = "";
224
+ instance;
225
+ td;
226
+ row;
227
+ col;
228
+ prop;
229
+ cellProperties;
230
+ getProps() {
231
+ return this.cellProperties?.rendererProps ?? {};
232
+ }
233
+ static ɵfac = i0.ɵɵngDeclareFactory({
234
+ minVersion: "12.0.0",
235
+ version: "22.2.2",
236
+ ngImport: i0,
237
+ type: HotCellRendererBase,
238
+ deps: [],
239
+ target: i0.ɵɵFactoryTarget.Directive
240
+ });
241
+ static ɵdir = i0.ɵɵngDeclareDirective({
242
+ minVersion: "14.0.0",
243
+ version: "22.2.2",
244
+ type: HotCellRendererBase,
245
+ isStandalone: true,
246
+ inputs: {
247
+ value: "value",
248
+ instance: "instance",
249
+ td: "td",
250
+ row: "row",
251
+ col: "col",
252
+ prop: "prop",
253
+ cellProperties: "cellProperties"
254
+ },
255
+ ngImport: i0
256
+ });
257
+ };
258
+ i0.ɵɵngDeclareClassMetadata({
259
+ minVersion: "12.0.0",
260
+ version: "22.2.2",
261
+ ngImport: i0,
262
+ type: HotCellRendererBase,
263
+ decorators: [{ type: Directive }],
264
+ propDecorators: {
265
+ value: [{ type: Input }],
266
+ instance: [{ type: Input }],
267
+ td: [{ type: Input }],
268
+ row: [{ type: Input }],
269
+ col: [{ type: Input }],
270
+ prop: [{ type: Input }],
271
+ cellProperties: [{ type: Input }]
272
+ }
273
+ });
274
+ var HotCellRendererComponent = class HotCellRendererComponent extends HotCellRendererBase {
275
+ static RENDERER_MARKER = Symbol("HotCellRendererComponent");
276
+ static ɵfac = i0.ɵɵngDeclareFactory({
277
+ minVersion: "12.0.0",
278
+ version: "22.2.2",
279
+ ngImport: i0,
280
+ type: HotCellRendererComponent,
281
+ deps: null,
282
+ target: i0.ɵɵFactoryTarget.Component
283
+ });
284
+ static ɵcmp = i0.ɵɵngDeclareComponent({
285
+ minVersion: "14.0.0",
286
+ version: "22.2.2",
287
+ type: HotCellRendererComponent,
288
+ isStandalone: true,
289
+ selector: "hot-cell-renderer",
290
+ usesInheritance: true,
291
+ ngImport: i0,
292
+ template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`,
293
+ isInline: true,
294
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
295
+ });
296
+ };
297
+ i0.ɵɵngDeclareClassMetadata({
298
+ minVersion: "12.0.0",
299
+ version: "22.2.2",
300
+ ngImport: i0,
301
+ type: HotCellRendererComponent,
302
+ decorators: [{
303
+ type: Component,
304
+ args: [{
305
+ selector: "hot-cell-renderer",
306
+ template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`,
307
+ standalone: true,
308
+ changeDetection: ChangeDetectionStrategy.OnPush
309
+ }]
310
+ }]
311
+ });
312
+ var HotCellEditorBase = class HotCellEditorBase {
313
+ heightFitParentContainer = 100;
314
+ widthFitParentContainer = 100;
315
+ row;
316
+ column;
317
+ prop;
318
+ originalValue;
319
+ cellProperties;
320
+ finishEdit = new EventEmitter();
321
+ cancelEdit = new EventEmitter();
322
+ value;
323
+ getValue() {
324
+ return this.value;
325
+ }
326
+ setValue(value) {
327
+ this.value = value;
328
+ }
329
+ static ɵfac = i0.ɵɵngDeclareFactory({
330
+ minVersion: "12.0.0",
331
+ version: "22.2.2",
332
+ ngImport: i0,
333
+ type: HotCellEditorBase,
334
+ deps: [],
335
+ target: i0.ɵɵFactoryTarget.Directive
336
+ });
337
+ static ɵdir = i0.ɵɵngDeclareDirective({
338
+ minVersion: "14.0.0",
339
+ version: "22.2.2",
340
+ type: HotCellEditorBase,
341
+ isStandalone: true,
342
+ inputs: {
343
+ row: "row",
344
+ column: "column",
345
+ prop: "prop",
346
+ originalValue: "originalValue",
347
+ cellProperties: "cellProperties"
348
+ },
349
+ outputs: {
350
+ finishEdit: "finishEdit",
351
+ cancelEdit: "cancelEdit"
352
+ },
353
+ host: { properties: {
354
+ "style.height.%": "this.heightFitParentContainer",
355
+ "style.width.%": "this.widthFitParentContainer"
356
+ } },
357
+ ngImport: i0
358
+ });
359
+ };
360
+ i0.ɵɵngDeclareClassMetadata({
361
+ minVersion: "12.0.0",
362
+ version: "22.2.2",
363
+ ngImport: i0,
364
+ type: HotCellEditorBase,
365
+ decorators: [{ type: Directive }],
366
+ propDecorators: {
367
+ heightFitParentContainer: [{
368
+ type: HostBinding,
369
+ args: ["style.height.%"]
370
+ }],
371
+ widthFitParentContainer: [{
372
+ type: HostBinding,
373
+ args: ["style.width.%"]
374
+ }],
375
+ row: [{ type: Input }],
376
+ column: [{ type: Input }],
377
+ prop: [{ type: Input }],
378
+ originalValue: [{ type: Input }],
379
+ cellProperties: [{ type: Input }],
380
+ finishEdit: [{ type: Output }],
381
+ cancelEdit: [{ type: Output }]
382
+ }
383
+ });
384
+ var HotCellEditorComponent = class HotCellEditorComponent extends HotCellEditorBase {
385
+ static EDITOR_MARKER = Symbol("HotCellEditorComponent");
386
+ tabindex = -1;
387
+ dataHotInput = "";
388
+ handsontableInputClass = true;
389
+ onClose() {}
390
+ onOpen(event) {}
391
+ static ɵfac = i0.ɵɵngDeclareFactory({
392
+ minVersion: "12.0.0",
393
+ version: "22.2.2",
394
+ ngImport: i0,
395
+ type: HotCellEditorComponent,
396
+ deps: null,
397
+ target: i0.ɵɵFactoryTarget.Directive
398
+ });
399
+ static ɵdir = i0.ɵɵngDeclareDirective({
400
+ minVersion: "14.0.0",
401
+ version: "22.2.2",
402
+ type: HotCellEditorComponent,
403
+ isStandalone: true,
404
+ host: { properties: {
405
+ "attr.tabindex": "this.tabindex",
406
+ "attr.data-hot-input": "this.dataHotInput",
407
+ "class.handsontableInput": "this.handsontableInputClass"
408
+ } },
409
+ usesInheritance: true,
410
+ ngImport: i0
411
+ });
412
+ };
413
+ i0.ɵɵngDeclareClassMetadata({
414
+ minVersion: "12.0.0",
415
+ version: "22.2.2",
416
+ ngImport: i0,
417
+ type: HotCellEditorComponent,
418
+ decorators: [{ type: Directive }],
419
+ propDecorators: {
420
+ tabindex: [{
421
+ type: HostBinding,
422
+ args: ["attr.tabindex"]
423
+ }],
424
+ dataHotInput: [{
425
+ type: HostBinding,
426
+ args: ["attr.data-hot-input"]
427
+ }],
428
+ handsontableInputClass: [{
429
+ type: HostBinding,
430
+ args: ["class.handsontableInput"]
431
+ }]
432
+ }
433
+ });
447
434
  const FactoryEditorAdapter = (componentRef) => editorFactory({
448
- position: componentRef.instance.position,
449
- shortcuts: componentRef.instance.shortcuts,
450
- shortcutsGroup: componentRef.instance.shortcutsGroup,
451
- config: componentRef.instance.config,
452
- init(editor) {
453
- editor._componentRef = componentRef;
454
- editor._editorPlaceHolderRef = undefined;
455
- editor._finishEditSubscription = undefined;
456
- editor._cancelEditSubscription = undefined;
457
- createEditorPlaceholder(editor, editor.hot._angularEnvironmentInjector);
458
- editor.input = editor._editorPlaceHolderRef?.location.nativeElement ?? document.createElement('div');
459
- editor._afterRowResizeCallback = () => {
460
- if (editor.isOpened()) {
461
- applyPropsToEditor(editor);
462
- }
463
- };
464
- editor._afterColumnResizeCallback = () => {
465
- if (editor.isOpened()) {
466
- applyPropsToEditor(editor);
467
- }
468
- };
469
- editor._afterDestroyCallback = () => {
470
- cleanupSubscriptions(editor);
471
- if (editor._editorPlaceHolderRef) {
472
- editor._editorPlaceHolderRef.destroy();
473
- }
474
- };
475
- // Hooks are automatically removed by Handsontable on table destroy
476
- editor.hot.addHook('afterRowResize', editor._afterRowResizeCallback);
477
- editor.hot.addHook('afterColumnResize', editor._afterColumnResizeCallback);
478
- editor.hot.addHook('afterDestroy', editor._afterDestroyCallback);
479
- },
480
- afterInit: (editor) => editor._componentRef.instance.afterInit?.(editor),
481
- beforeOpen: (editor, context) => {
482
- cleanupSubscriptions(editor);
483
- applyPropsToEditor(editor);
484
- editor._finishEditSubscription = editor._componentRef.instance.finishEdit.pipe(take(1)).subscribe(() => {
485
- editor.finishEditing();
486
- });
487
- editor._cancelEditSubscription = editor._componentRef.instance.cancelEdit.pipe(take(1)).subscribe(() => {
488
- editor.cancelChanges();
489
- });
490
- editor._componentRef.instance.beforeOpen?.(editor, context);
491
- },
492
- afterOpen: (editor, event) => {
493
- editor._componentRef.instance.afterOpen?.(editor, event);
494
- },
495
- onFocus: (editor) => editor._componentRef.instance.onFocus?.(editor),
496
- afterClose: (editor) => {
497
- resetEditorState(editor);
498
- editor._editorPlaceHolderRef?.changeDetectorRef.detectChanges();
499
- editor._editorPlaceHolderRef?.instance.detachEditor();
500
- editor._componentRef.instance.afterClose?.(editor);
501
- },
502
- getValue: (editor) => editor._componentRef.instance.getValue(),
503
- setValue: (editor, value) => {
504
- editor.value = value;
505
- editor._componentRef.instance.setValue(value);
506
- editor._componentRef.changeDetectorRef.detectChanges();
507
- },
435
+ position: componentRef.instance.position,
436
+ shortcuts: componentRef.instance.shortcuts,
437
+ shortcutsGroup: componentRef.instance.shortcutsGroup,
438
+ config: componentRef.instance.config,
439
+ init(editor) {
440
+ editor._componentRef = componentRef;
441
+ editor._editorPlaceHolderRef = void 0;
442
+ editor._finishEditSubscription = void 0;
443
+ editor._cancelEditSubscription = void 0;
444
+ createEditorPlaceholder(editor, editor.hot._angularEnvironmentInjector);
445
+ editor.input = editor._editorPlaceHolderRef?.location.nativeElement ?? document.createElement("div");
446
+ editor._afterRowResizeCallback = () => {
447
+ if (editor.isOpened()) applyPropsToEditor(editor);
448
+ };
449
+ editor._afterColumnResizeCallback = () => {
450
+ if (editor.isOpened()) applyPropsToEditor(editor);
451
+ };
452
+ editor._afterDestroyCallback = () => {
453
+ cleanupSubscriptions(editor);
454
+ if (editor._editorPlaceHolderRef) editor._editorPlaceHolderRef.destroy();
455
+ };
456
+ editor.hot.addHook("afterRowResize", editor._afterRowResizeCallback);
457
+ editor.hot.addHook("afterColumnResize", editor._afterColumnResizeCallback);
458
+ editor.hot.addHook("afterDestroy", editor._afterDestroyCallback);
459
+ },
460
+ afterInit: (editor) => editor._componentRef.instance.afterInit?.(editor),
461
+ beforeOpen: (editor, context) => {
462
+ cleanupSubscriptions(editor);
463
+ applyPropsToEditor(editor);
464
+ editor._finishEditSubscription = editor._componentRef.instance.finishEdit.pipe(take(1)).subscribe(() => {
465
+ editor.finishEditing();
466
+ });
467
+ editor._cancelEditSubscription = editor._componentRef.instance.cancelEdit.pipe(take(1)).subscribe(() => {
468
+ editor.cancelChanges();
469
+ });
470
+ editor._componentRef.instance.beforeOpen?.(editor, context);
471
+ },
472
+ afterOpen: (editor, event) => {
473
+ editor._componentRef.instance.afterOpen?.(editor, event);
474
+ },
475
+ onFocus: (editor) => editor._componentRef.instance.onFocus?.(editor),
476
+ afterClose: (editor) => {
477
+ resetEditorState(editor);
478
+ editor._editorPlaceHolderRef?.changeDetectorRef.detectChanges();
479
+ editor._editorPlaceHolderRef?.instance.detachEditor();
480
+ editor._componentRef.instance.afterClose?.(editor);
481
+ },
482
+ getValue: (editor) => editor._componentRef.instance.getValue(),
483
+ setValue: (editor, value) => {
484
+ editor.value = value;
485
+ editor._componentRef.instance.setValue(value);
486
+ editor._componentRef.changeDetectorRef.detectChanges();
487
+ }
508
488
  });
509
- /**
510
- * Creates the editor placeholder component.
511
- * @param editor The editor instance.
512
- * @param injector The environment injector from Angular.
513
- */
514
489
  function createEditorPlaceholder(editor, injector) {
515
- if (!injector) {
516
- return;
517
- }
518
- editor._editorPlaceHolderRef = createComponent(CustomEditorPlaceholderComponent, {
519
- environmentInjector: injector,
520
- });
490
+ if (!injector) return;
491
+ editor._editorPlaceHolderRef = createComponent(CustomEditorPlaceholderComponent, { environmentInjector: injector });
521
492
  }
522
- /**
523
- * Applies properties to the custom Angular editor and editor placeholder.
524
- * Updates position, size, and cell context information.
525
- * @param editor The editor instance.
526
- */
527
493
  function applyPropsToEditor(editor) {
528
- if (!editor._componentRef || !editor._editorPlaceHolderRef) {
529
- return;
530
- }
531
- editor._componentRef.setInput('originalValue', editor.originalValue);
532
- editor._componentRef.setInput('row', editor.row);
533
- editor._componentRef.setInput('column', editor.col);
534
- editor._componentRef.setInput('prop', editor.prop);
535
- editor._componentRef.setInput('cellProperties', editor.cellProperties);
536
- const rect = editor.hot.getCell(editor.row, editor.col)?.getBoundingClientRect();
537
- editor._editorPlaceHolderRef.setInput('placeholderCustomClass', '');
538
- editor._editorPlaceHolderRef.setInput('height', rect?.height ?? 0);
539
- editor._editorPlaceHolderRef.setInput('width', rect?.width ?? 0);
540
- editor._editorPlaceHolderRef.setInput('isVisible', true);
541
- editor._editorPlaceHolderRef.setInput('componentRef', editor._componentRef);
542
- editor._editorPlaceHolderRef.changeDetectorRef.detectChanges();
494
+ if (!editor._componentRef || !editor._editorPlaceHolderRef) return;
495
+ editor._componentRef.setInput("originalValue", editor.originalValue);
496
+ editor._componentRef.setInput("row", editor.row);
497
+ editor._componentRef.setInput("column", editor.col);
498
+ editor._componentRef.setInput("prop", editor.prop);
499
+ editor._componentRef.setInput("cellProperties", editor.cellProperties);
500
+ const rect = editor.hot.getCell(editor.row, editor.col)?.getBoundingClientRect();
501
+ editor._editorPlaceHolderRef.setInput("placeholderCustomClass", "");
502
+ editor._editorPlaceHolderRef.setInput("height", rect?.height ?? 0);
503
+ editor._editorPlaceHolderRef.setInput("width", rect?.width ?? 0);
504
+ editor._editorPlaceHolderRef.setInput("isVisible", true);
505
+ editor._editorPlaceHolderRef.setInput("componentRef", editor._componentRef);
506
+ editor._editorPlaceHolderRef.changeDetectorRef.detectChanges();
543
507
  }
544
- /**
545
- * Resets the editor placeholder state.
546
- * Clears all positioning and visibility settings.
547
- * @param editor The editor instance.
548
- */
549
508
  function resetEditorState(editor) {
550
- if (!editor._editorPlaceHolderRef) {
551
- return;
552
- }
553
- editor._editorPlaceHolderRef.setInput('top', undefined);
554
- editor._editorPlaceHolderRef.setInput('left', undefined);
555
- editor._editorPlaceHolderRef.setInput('height', undefined);
556
- editor._editorPlaceHolderRef.setInput('width', undefined);
557
- editor._editorPlaceHolderRef.setInput('isVisible', false);
558
- editor._editorPlaceHolderRef.setInput('componentRef', undefined);
509
+ if (!editor._editorPlaceHolderRef) return;
510
+ editor._editorPlaceHolderRef.setInput("top", void 0);
511
+ editor._editorPlaceHolderRef.setInput("left", void 0);
512
+ editor._editorPlaceHolderRef.setInput("height", void 0);
513
+ editor._editorPlaceHolderRef.setInput("width", void 0);
514
+ editor._editorPlaceHolderRef.setInput("isVisible", false);
515
+ editor._editorPlaceHolderRef.setInput("componentRef", void 0);
559
516
  }
560
- /**
561
- * Cleans up existing subscriptions.
562
- * @param editor The editor instance.
563
- */
564
517
  function cleanupSubscriptions(editor) {
565
- if (editor._finishEditSubscription) {
566
- editor._finishEditSubscription.unsubscribe();
567
- editor._finishEditSubscription = undefined;
568
- }
569
- if (editor._cancelEditSubscription) {
570
- editor._cancelEditSubscription.unsubscribe();
571
- editor._cancelEditSubscription = undefined;
572
- }
573
- }
574
-
575
- /**
576
- * Abstract base component for creating advanced custom cell renderer components for Handsontable.
577
- *
578
- * Extend this component and provide your own template to implement a custom renderer.
579
- * Unlike {@link HotCellRendererComponent}, this variant also accepts object and array values.
580
- *
581
- * @template TValue - The type of the component renderer.
582
- * @template TProps - The type of additional renderer properties.
583
- */
584
- class HotCellRendererAdvancedComponent extends HotCellRendererBase {
585
- static RENDERER_MARKER = Symbol('HotCellRendererAdvancedComponent');
586
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellRendererAdvancedComponent, deps: null, target: i0.ɵɵFactoryTarget.Component });
587
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: HotCellRendererAdvancedComponent, isStandalone: true, selector: "hot-cell-renderer-advanced", usesInheritance: true, ngImport: i0, template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`, isInline: true, changeDetection: i0.ChangeDetectionStrategy.OnPush });
588
- }
589
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellRendererAdvancedComponent, decorators: [{
590
- type: Component,
591
- args: [{
592
- selector: 'hot-cell-renderer-advanced',
593
- template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`,
594
- standalone: true,
595
- changeDetection: ChangeDetectionStrategy.OnPush,
596
- }]
597
- }] });
598
-
599
- /**
600
- * Abstract class representing an advanced Handsontable cell editor in Angular.
601
- *
602
- * Extend this class and decorate the subclass with `@Component()` to implement a custom editor.
603
- * Unlike {@link HotCellEditorComponent}, this variant also accepts object and array values
604
- * and provides additional lifecycle hooks and positioning options.
605
- */
606
- class HotCellEditorAdvancedComponent extends HotCellEditorBase {
607
- static EDITOR_MARKER = Symbol('HotCellEditorAdvancedComponent');
608
- /** Event triggered by Handsontable on focusing the editor. Available in advanced mode. */
609
- onFocus(editor) { }
610
- /** The position of the editor in the DOM. Available in advanced mode. */
611
- position = 'container';
612
- /** The shortcuts available for the editor. Available in advanced mode. */
613
- shortcuts;
614
- /** The group name for the shortcuts. Available in advanced mode. */
615
- shortcutsGroup;
616
- /** Configuration object. Available in advanced mode. */
617
- config;
618
- /** Lifecycle hook called after the editor is opened. Available in advanced mode. */
619
- afterOpen(editor, event) { }
620
- /** Lifecycle hook called after the editor is closed. Available in advanced mode. */
621
- afterClose(editor) { }
622
- /** Lifecycle hook called after the editor is initialized. Available in advanced mode. */
623
- afterInit(editor) { }
624
- /** Lifecycle hook called before the editor is opened. Available in advanced mode. */
625
- beforeOpen(editor, { row, col, prop, td, originalValue, cellProperties, }) { }
626
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellEditorAdvancedComponent, deps: null, target: i0.ɵɵFactoryTarget.Directive });
627
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "19.2.25", type: HotCellEditorAdvancedComponent, isStandalone: true, usesInheritance: true, ngImport: i0 });
518
+ if (editor._finishEditSubscription) {
519
+ editor._finishEditSubscription.unsubscribe();
520
+ editor._finishEditSubscription = void 0;
521
+ }
522
+ if (editor._cancelEditSubscription) {
523
+ editor._cancelEditSubscription.unsubscribe();
524
+ editor._cancelEditSubscription = void 0;
525
+ }
628
526
  }
629
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotCellEditorAdvancedComponent, decorators: [{
630
- type: Directive
631
- }] });
632
-
633
- const INVALID_RENDERER_WARNING = 'The provided renderer component was not recognized as a valid custom renderer. ' +
634
- 'It must either extend HotCellRendererComponent or be a valid TemplateRef. ' +
635
- 'Please ensure that your custom renderer is implemented correctly and imported from the proper source.';
636
- const INVALID_ADVANCED_RENDERER_WARNING = 'The provided renderer component was not recognized as a valid custom renderer. ' +
637
- 'It must either extend HotCellRendererAdvancedComponent. ' +
638
- 'Please ensure that your custom renderer is implemented correctly and imported from the proper source.';
639
- // Renderer component inputs, listed once at module scope so the per-cell render path can set them
640
- // without allocating a fresh key array (via Object.keys) on every cell of every render frame.
527
+ var HotCellRendererAdvancedComponent = class HotCellRendererAdvancedComponent extends HotCellRendererBase {
528
+ static RENDERER_MARKER = Symbol("HotCellRendererAdvancedComponent");
529
+ static ɵfac = i0.ɵɵngDeclareFactory({
530
+ minVersion: "12.0.0",
531
+ version: "22.2.2",
532
+ ngImport: i0,
533
+ type: HotCellRendererAdvancedComponent,
534
+ deps: null,
535
+ target: i0.ɵɵFactoryTarget.Component
536
+ });
537
+ static ɵcmp = i0.ɵɵngDeclareComponent({
538
+ minVersion: "14.0.0",
539
+ version: "22.2.2",
540
+ type: HotCellRendererAdvancedComponent,
541
+ isStandalone: true,
542
+ selector: "hot-cell-renderer-advanced",
543
+ usesInheritance: true,
544
+ ngImport: i0,
545
+ template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`,
546
+ isInline: true,
547
+ changeDetection: i0.ChangeDetectionStrategy.OnPush
548
+ });
549
+ };
550
+ i0.ɵɵngDeclareClassMetadata({
551
+ minVersion: "12.0.0",
552
+ version: "22.2.2",
553
+ ngImport: i0,
554
+ type: HotCellRendererAdvancedComponent,
555
+ decorators: [{
556
+ type: Component,
557
+ args: [{
558
+ selector: "hot-cell-renderer-advanced",
559
+ template: `<!-- This is an abstract component. Extend this component and provide your own template. -->`,
560
+ standalone: true,
561
+ changeDetection: ChangeDetectionStrategy.OnPush
562
+ }]
563
+ }]
564
+ });
565
+ var HotCellEditorAdvancedComponent = class HotCellEditorAdvancedComponent extends HotCellEditorBase {
566
+ static EDITOR_MARKER = Symbol("HotCellEditorAdvancedComponent");
567
+ onFocus(editor) {}
568
+ position = "container";
569
+ shortcuts;
570
+ shortcutsGroup;
571
+ config;
572
+ afterOpen(editor, event) {}
573
+ afterClose(editor) {}
574
+ afterInit(editor) {}
575
+ beforeOpen(editor, { row, col, prop, td, originalValue, cellProperties }) {}
576
+ static ɵfac = i0.ɵɵngDeclareFactory({
577
+ minVersion: "12.0.0",
578
+ version: "22.2.2",
579
+ ngImport: i0,
580
+ type: HotCellEditorAdvancedComponent,
581
+ deps: null,
582
+ target: i0.ɵɵFactoryTarget.Directive
583
+ });
584
+ static ɵdir = i0.ɵɵngDeclareDirective({
585
+ minVersion: "14.0.0",
586
+ version: "22.2.2",
587
+ type: HotCellEditorAdvancedComponent,
588
+ isStandalone: true,
589
+ usesInheritance: true,
590
+ ngImport: i0
591
+ });
592
+ };
593
+ i0.ɵɵngDeclareClassMetadata({
594
+ minVersion: "12.0.0",
595
+ version: "22.2.2",
596
+ ngImport: i0,
597
+ type: HotCellEditorAdvancedComponent,
598
+ decorators: [{ type: Directive }]
599
+ });
600
+ const INVALID_RENDERER_WARNING = "The provided renderer component was not recognized as a valid custom renderer. It must either extend HotCellRendererComponent or be a valid TemplateRef. Please ensure that your custom renderer is implemented correctly and imported from the proper source.";
601
+ const INVALID_ADVANCED_RENDERER_WARNING = "The provided renderer component was not recognized as a valid custom renderer. It must either extend HotCellRendererAdvancedComponent. Please ensure that your custom renderer is implemented correctly and imported from the proper source.";
641
602
  const RENDERER_INPUT_KEYS = [
642
- 'instance', 'td', 'row', 'col', 'prop', 'value', 'cellProperties',
603
+ "instance",
604
+ "td",
605
+ "row",
606
+ "col",
607
+ "prop",
608
+ "value",
609
+ "cellProperties"
643
610
  ];
644
- /**
645
- * Type guard that checks if the given object is a TemplateRef.
646
- *
647
- * @param obj - The object to check.
648
- * @returns True if the object is a TemplateRef; otherwise, false.
649
- */
650
611
  function isTemplateRef(obj) {
651
- return !!obj && typeof obj.createEmbeddedView === 'function';
612
+ return !!obj && typeof obj.createEmbeddedView === "function";
652
613
  }
653
- /**
654
- * Type guard to check if an object is an instance of HotCellRendererComponent.
655
- *
656
- * @param obj - The object to check.
657
- * @returns True if the object is a HotCellRendererComponent, false otherwise.
658
- */
659
614
  function isHotCellRendererComponent(obj) {
660
- return obj?.RENDERER_MARKER === HotCellRendererComponent.RENDERER_MARKER;
615
+ return obj?.RENDERER_MARKER === HotCellRendererComponent.RENDERER_MARKER;
661
616
  }
662
- /**
663
- * Type guard to check if an object is an instance of HotCellRendererAdvancedComponent.
664
- *
665
- * @param obj - The object to check.
666
- * @returns True if the object is a HotCellRendererAdvancedComponent, false otherwise.
667
- */
668
617
  function isAdvancedHotCellRendererComponent(obj) {
669
- return obj?.RENDERER_MARKER === HotCellRendererAdvancedComponent.RENDERER_MARKER;
670
- }
671
- /**
672
- * Service for dynamically creating Angular components or templates as custom renderers for Handsontable.
673
- *
674
- * This service allows you to create a renderer function that wraps a given Angular component or TemplateRef
675
- * so that it can be used as a Handsontable renderer.
676
- *
677
- * @example
678
- * const customRenderer = dynamicComponentService.createRendererFromComponent(MyRendererComponent, { someProp: value });
679
- * // Use customRenderer in your Handsontable configuration
680
- */
681
- class DynamicComponentService {
682
- appRef;
683
- environmentInjector;
684
- // Track Angular component refs and embedded views keyed by the TD element they are attached to.
685
- // When a cell is re-rendered the previous component is destroyed before a new one is created.
686
- _tdComponentRefs = new WeakMap();
687
- _tdEmbeddedViews = new WeakMap();
688
- // Per-instance registries of every renderer ref/view currently attached to the application.
689
- // The WeakMaps above only allow per-TD lookup; these sets let us sweep refs whose TD was dropped
690
- // from Handsontable's virtual viewport (scrolling, updateData), which would otherwise stay
691
- // attached to ApplicationRef forever and leak both memory and change-detection work.
692
- //
693
- // The registries are scoped per Handsontable instance (not one global set) because this service
694
- // is a root singleton shared by every <hot-table>. A global sweep would scan the cells of every
695
- // table on the page on each `afterViewRender`, i.e. on every scroll frame of any one of them.
696
- // Keying by instance bounds each sweep to the cells of the table that actually re-rendered.
697
- _instanceComponentRefs = new WeakMap();
698
- _instanceEmbeddedViews = new WeakMap();
699
- // Instances we already wired the sweep hook into, so each instance is hooked at most once.
700
- _hookedInstances = new WeakSet();
701
- constructor(appRef, environmentInjector) {
702
- this.appRef = appRef;
703
- this.environmentInjector = environmentInjector;
704
- }
705
- /**
706
- * Creates a custom renderer function for Handsontable from an Angular component or TemplateRef.
707
- * The generated renderer function will be used by Handsontable to render cell content.
708
- *
709
- * @param component - The Angular component type or TemplateRef to use as renderer.
710
- * @param componentProps - An object containing additional properties to use by the renderer.
711
- * @param register - If true, registers the renderer with Handsontable using the component's name.
712
- * @returns A renderer function that can be used in Handsontable's configuration.
713
- */
714
- createRendererFromComponent(component, componentProps = {}, register = false) {
715
- let registered = false;
716
- return (instance, td, row, col, prop, value, cellProperties) => {
717
- const properties = {
718
- value,
719
- instance,
720
- td,
721
- row,
722
- col,
723
- prop,
724
- cellProperties,
725
- };
726
- cellProperties.rendererProps = componentProps;
727
- baseRenderer.call(this, instance, td, row, col, prop, value, cellProperties);
728
- this.registerSweepHook(instance);
729
- if (isTemplateRef(component)) {
730
- // Embedded views carry a per-render context, so they are always rebuilt.
731
- this.replaceCellContent(instance, td);
732
- const embeddedView = this.attachTemplateToElement(component, td, properties);
733
- this.trackEmbeddedView(instance, td, embeddedView);
734
- }
735
- else if (isHotCellRendererComponent(component)) {
736
- this.renderComponent(td, component, properties);
737
- }
738
- else {
739
- console.warn(INVALID_RENDERER_WARNING);
740
- }
741
- if (register && !registered && isHotCellRendererComponent(component)) {
742
- Handsontable.renderers.registerRenderer(component.name, component);
743
- registered = true;
744
- }
745
- return td;
746
- };
747
- }
748
- /**
749
- * Creates a custom renderer function using rendererFactory from Handsontable.
750
- * This is an alternative implementation that uses the factory pattern.
751
- *
752
- * @param component - The Angular component type to use as renderer.
753
- * @param componentProps - An object containing additional properties to use by the renderer.
754
- * @param register - If true, registers the renderer with Handsontable using the component's name.
755
- * @returns A renderer function that can be used in Handsontable's configuration.
756
- */
757
- createRendererWithFactory(component, componentProps = {}, register = false) {
758
- let registered = false;
759
- return rendererFactory(({ instance, td, row, column, prop, value, cellProperties }) => {
760
- const properties = {
761
- value,
762
- instance,
763
- td,
764
- row,
765
- col: column,
766
- prop,
767
- cellProperties,
768
- };
769
- cellProperties.rendererProps = componentProps;
770
- // Apply the base renderer so the TD gets the same base classes/attributes as the
771
- // createRendererFromComponent path (rendererFactory itself does not call it).
772
- baseRenderer.call(this, instance, td, row, column, prop, value, cellProperties);
773
- this.registerSweepHook(instance);
774
- if (isAdvancedHotCellRendererComponent(component)) {
775
- this.renderComponent(td, component, properties);
776
- }
777
- else {
778
- console.warn(INVALID_ADVANCED_RENDERER_WARNING);
779
- }
780
- if (register && !registered && isAdvancedHotCellRendererComponent(component)) {
781
- registerRenderer(component.name, component);
782
- registered = true;
783
- }
784
- });
785
- }
786
- /**
787
- * Destroys all renderer components and embedded views attached to cells within a container element.
788
- * Must be called before destroying the Handsontable instance to prevent Angular component leaks.
789
- *
790
- * @param container - The root DOM element of the Handsontable instance.
791
- * @param instance - The Handsontable instance whose registries should be torn down. When omitted
792
- * (e.g. test stubs), only refs reachable through TDs still in the container are destroyed.
793
- */
794
- cleanupContainer(container, instance) {
795
- const compRefs = instance ? this._instanceComponentRefs.get(instance) : undefined;
796
- const embViews = instance ? this._instanceEmbeddedViews.get(instance) : undefined;
797
- container.querySelectorAll('td').forEach((td) => {
798
- const compRef = this._tdComponentRefs.get(td);
799
- if (compRef) {
800
- this.destroyComponent(compRef);
801
- this._tdComponentRefs.delete(td);
802
- compRefs?.delete(compRef);
803
- }
804
- const embView = this._tdEmbeddedViews.get(td);
805
- if (embView) {
806
- this.destroyEmbeddedView(embView);
807
- this._tdEmbeddedViews.delete(td);
808
- embViews?.delete(embView);
809
- }
810
- });
811
- // The loop above only reaches TDs still present in the container. Refs for cells already
812
- // dropped from the viewport (but not yet swept) would otherwise be orphaned once this
813
- // instance's afterViewRender hook is gone after destroy. Tear down whatever is left and drop
814
- // the per-instance registries so a repeated cleanup call is a no-op. (Entries removed in the
815
- // loop above are already gone from these sets, so nothing is destroyed twice.)
816
- compRefs?.forEach((ref) => this.destroyComponent(ref));
817
- embViews?.forEach((view) => this.destroyEmbeddedView(view));
818
- if (instance) {
819
- this._instanceComponentRefs.delete(instance);
820
- this._instanceEmbeddedViews.delete(instance);
821
- }
822
- }
823
- /**
824
- * Registers a one-time `afterViewRender` hook on the given Handsontable instance that sweeps
825
- * renderer refs whose TD is no longer connected to the document. Handsontable recycles a pool of
826
- * TD elements while virtualizing rows; cells that leave the viewport are never re-rendered, so
827
- * without this sweep their Angular components stay attached to ApplicationRef and leak.
828
- *
829
- * Guarded against instances that do not expose `addHook` (e.g. test stubs).
830
- *
831
- * @param instance - The Handsontable instance whose render cycle drives the sweep.
832
- */
833
- registerSweepHook(instance) {
834
- if (this._hookedInstances.has(instance) || typeof instance?.addHook !== 'function') {
835
- return;
836
- }
837
- this._hookedInstances.add(instance);
838
- instance.addHook('afterViewRender', () => this.sweepDetachedViews(instance));
839
- }
840
- /**
841
- * Destroys every renderer ref/view tracked for the given instance whose root node is no longer
842
- * attached to the document.
843
- *
844
- * @param instance - The Handsontable instance whose registries should be swept.
845
- */
846
- sweepDetachedViews(instance) {
847
- const compRefs = this._instanceComponentRefs.get(instance);
848
- compRefs?.forEach((ref) => {
849
- if (!this.isViewConnected(ref.hostView)) {
850
- this.destroyComponent(ref);
851
- compRefs.delete(ref);
852
- }
853
- });
854
- const embViews = this._instanceEmbeddedViews.get(instance);
855
- embViews?.forEach((view) => {
856
- if (!this.isViewConnected(view)) {
857
- this.destroyEmbeddedView(view);
858
- embViews.delete(view);
859
- }
860
- });
861
- }
862
- /**
863
- * @returns True if any of the view's root nodes is still connected to the document.
864
- */
865
- isViewConnected(view) {
866
- return view.rootNodes.some((node) => !!node?.isConnected);
867
- }
868
- /**
869
- * Destroys the renderer ref/view previously attached to a cell and clears the cell content,
870
- * so a fresh renderer can take over the TD without leaking the old one.
871
- *
872
- * @param instance - The Handsontable instance owning the cell, used to update its registries.
873
- * @param td - The table cell whose previous content should be torn down.
874
- */
875
- replaceCellContent(instance, td) {
876
- const prevRef = this._tdComponentRefs.get(td);
877
- if (prevRef) {
878
- this.destroyComponent(prevRef);
879
- this._tdComponentRefs.delete(td);
880
- this._instanceComponentRefs.get(instance)?.delete(prevRef);
881
- }
882
- const prevView = this._tdEmbeddedViews.get(td);
883
- if (prevView) {
884
- this.destroyEmbeddedView(prevView);
885
- this._tdEmbeddedViews.delete(td);
886
- this._instanceEmbeddedViews.get(instance)?.delete(prevView);
887
- }
888
- // Not `innerHTML = ''`: that reads as "assign nothing", but `innerHTML` is a Trusted
889
- // Types sink whatever the value, so under `require-trusted-types-for 'script'` an empty
890
- // string throws exactly like markup would.
891
- td.replaceChildren();
892
- }
893
- /**
894
- * Tracks a component ref both by its TD (for fast replacement) and in the instance registry
895
- * (for sweeping and full teardown).
896
- */
897
- trackComponentRef(instance, td, ref) {
898
- this._tdComponentRefs.set(td, ref);
899
- this.registryFor(this._instanceComponentRefs, instance).add(ref);
900
- }
901
- /**
902
- * Tracks an embedded view both by its TD (for fast replacement) and in the instance registry
903
- * (for sweeping and full teardown).
904
- */
905
- trackEmbeddedView(instance, td, view) {
906
- this._tdEmbeddedViews.set(td, view);
907
- this.registryFor(this._instanceEmbeddedViews, instance).add(view);
908
- }
909
- /**
910
- * Returns the per-instance registry set for the given instance, creating it on first use.
911
- */
912
- registryFor(registry, instance) {
913
- let set = registry.get(instance);
914
- if (!set) {
915
- set = new Set();
916
- registry.set(instance, set);
917
- }
918
- return set;
919
- }
920
- /**
921
- * Attaches an embedded view created from a TemplateRef to a given DOM element.
922
- *
923
- * @param template - The TemplateRef to create an embedded view from.
924
- * @param tdEl - The target DOM element (a table cell) to which the view will be appended.
925
- * @param properties - Context object providing properties to be used within the template.
926
- * @returns The created EmbeddedViewRef so the caller can track and destroy it later.
927
- */
928
- attachTemplateToElement(template, tdEl, properties) {
929
- const embeddedView = template.createEmbeddedView({
930
- $implicit: properties.value,
931
- ...properties,
932
- });
933
- embeddedView.detectChanges();
934
- embeddedView.rootNodes.forEach((node) => {
935
- tdEl.appendChild(node);
936
- });
937
- return embeddedView;
938
- }
939
- /**
940
- * Dynamically creates an Angular component of the given type.
941
- *
942
- * @param component - The Angular component type to be created.
943
- * @param rendererParameters - An object containing input properties to assign to the component instance.
944
- * @returns The ComponentRef of the dynamically created component.
945
- */
946
- createComponent(component, rendererParameters) {
947
- const componentRef = createComponent(component, {
948
- environmentInjector: this.environmentInjector,
949
- });
950
- this.applyInputs(componentRef, rendererParameters);
951
- componentRef.changeDetectorRef.detectChanges();
952
- this.appRef.attachView(componentRef.hostView);
953
- return componentRef;
954
- }
955
- /**
956
- * Renders an Angular component into the given cell, recycling the component already attached to
957
- * the TD when it is of the same type. Handsontable recycles its pool of TD elements heavily while
958
- * virtualizing rows, so recreating an Angular component on every re-render would cause needless
959
- * teardown/instantiation churn and GC pressure. When the type matches we only refresh the inputs.
960
- *
961
- * @param td - The target table cell.
962
- * @param component - The renderer component type to render.
963
- * @param properties - The renderer parameters to feed as component inputs.
964
- */
965
- renderComponent(td, component, properties) {
966
- const prevRef = this._tdComponentRefs.get(td);
967
- if (prevRef &&
968
- prevRef.componentType === component &&
969
- this.isViewConnected(prevRef.hostView)) {
970
- this.applyInputs(prevRef, properties);
971
- prevRef.changeDetectorRef.detectChanges();
972
- return;
973
- }
974
- this.replaceCellContent(properties.instance, td);
975
- const componentRef = this.createComponent(component, properties);
976
- this.attachComponentToElement(componentRef, td);
977
- this.trackComponentRef(properties.instance, td, componentRef);
978
- }
979
- /**
980
- * Assigns every renderer parameter as an input on the given component ref.
981
- *
982
- * @param componentRef - The component ref whose inputs should be set.
983
- * @param rendererParameters - The renderer parameters to assign.
984
- */
985
- applyInputs(componentRef, rendererParameters) {
986
- RENDERER_INPUT_KEYS.forEach((key) => {
987
- componentRef.setInput(key, rendererParameters[key]);
988
- });
989
- }
990
- /**
991
- * Attaches a dynamically created component's view to a specified DOM container element.
992
- *
993
- * @param componentRef - The reference to the dynamically created component.
994
- * @param container - The target DOM element to which the component's root node will be appended.
995
- */
996
- attachComponentToElement(componentRef, container) {
997
- componentRef.hostView.rootNodes.forEach((node) => {
998
- container.appendChild(node);
999
- });
1000
- }
1001
- /**
1002
- * Destroys a dynamically created component and detaches its view from the Angular application.
1003
- *
1004
- * Idempotent: a TD recycled after `sweepDetachedViews` already destroyed its ref still maps to that
1005
- * stale ref in `_tdComponentRefs`, so the next render path may reach this with an already-destroyed
1006
- * ref. Guarding on `destroyed` skips the redundant detach/destroy instead of relying on Angular's
1007
- * internal no-op behavior.
1008
- *
1009
- * @param componentRef - The reference to the component to be destroyed.
1010
- */
1011
- destroyComponent(componentRef) {
1012
- const hostView = componentRef.hostView;
1013
- if (hostView.destroyed) {
1014
- return;
1015
- }
1016
- this.appRef.detachView(hostView);
1017
- componentRef.destroy();
1018
- }
1019
- /**
1020
- * Destroys an embedded view. Idempotent for the same reason as {@link destroyComponent}: a recycled
1021
- * TD can still map to an already-destroyed view in `_tdEmbeddedViews`.
1022
- *
1023
- * @param view - The embedded view to destroy.
1024
- */
1025
- destroyEmbeddedView(view) {
1026
- if (view.destroyed) {
1027
- return;
1028
- }
1029
- view.destroy();
1030
- }
1031
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: DynamicComponentService, deps: [{ token: i0.ApplicationRef }, { token: i0.EnvironmentInjector }], target: i0.ɵɵFactoryTarget.Injectable });
1032
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: DynamicComponentService, providedIn: 'root' });
618
+ return obj?.RENDERER_MARKER === HotCellRendererAdvancedComponent.RENDERER_MARKER;
1033
619
  }
1034
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: DynamicComponentService, decorators: [{
1035
- type: Injectable,
1036
- args: [{
1037
- providedIn: 'root',
1038
- }]
1039
- }], ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.EnvironmentInjector }] });
1040
-
620
+ var DynamicComponentService = class DynamicComponentService {
621
+ appRef;
622
+ environmentInjector;
623
+ _tdComponentRefs = /* @__PURE__ */ new WeakMap();
624
+ _tdEmbeddedViews = /* @__PURE__ */ new WeakMap();
625
+ _instanceComponentRefs = /* @__PURE__ */ new WeakMap();
626
+ _instanceEmbeddedViews = /* @__PURE__ */ new WeakMap();
627
+ _hookedInstances = /* @__PURE__ */ new WeakSet();
628
+ constructor(appRef, environmentInjector) {
629
+ this.appRef = appRef;
630
+ this.environmentInjector = environmentInjector;
631
+ }
632
+ createRendererFromComponent(component, componentProps = {}, register = false) {
633
+ let registered = false;
634
+ return (instance, td, row, col, prop, value, cellProperties) => {
635
+ const properties = {
636
+ value,
637
+ instance,
638
+ td,
639
+ row,
640
+ col,
641
+ prop,
642
+ cellProperties
643
+ };
644
+ cellProperties.rendererProps = componentProps;
645
+ baseRenderer.call(this, instance, td, row, col, prop, value, cellProperties);
646
+ this.registerSweepHook(instance);
647
+ if (isTemplateRef(component)) {
648
+ this.replaceCellContent(instance, td);
649
+ const embeddedView = this.attachTemplateToElement(component, td, properties);
650
+ this.trackEmbeddedView(instance, td, embeddedView);
651
+ } else if (isHotCellRendererComponent(component)) this.renderComponent(td, component, properties);
652
+ else console.warn(INVALID_RENDERER_WARNING);
653
+ if (register && !registered && isHotCellRendererComponent(component)) {
654
+ Handsontable.renderers.registerRenderer(component.name, component);
655
+ registered = true;
656
+ }
657
+ return td;
658
+ };
659
+ }
660
+ createRendererWithFactory(component, componentProps = {}, register = false) {
661
+ let registered = false;
662
+ return rendererFactory(({ instance, td, row, column, prop, value, cellProperties }) => {
663
+ const properties = {
664
+ value,
665
+ instance,
666
+ td,
667
+ row,
668
+ col: column,
669
+ prop,
670
+ cellProperties
671
+ };
672
+ cellProperties.rendererProps = componentProps;
673
+ baseRenderer.call(this, instance, td, row, column, prop, value, cellProperties);
674
+ this.registerSweepHook(instance);
675
+ if (isAdvancedHotCellRendererComponent(component)) this.renderComponent(td, component, properties);
676
+ else console.warn(INVALID_ADVANCED_RENDERER_WARNING);
677
+ if (register && !registered && isAdvancedHotCellRendererComponent(component)) {
678
+ registerRenderer(component.name, component);
679
+ registered = true;
680
+ }
681
+ });
682
+ }
683
+ cleanupContainer(container, instance) {
684
+ const compRefs = instance ? this._instanceComponentRefs.get(instance) : void 0;
685
+ const embViews = instance ? this._instanceEmbeddedViews.get(instance) : void 0;
686
+ container.querySelectorAll("td").forEach((td) => {
687
+ const compRef = this._tdComponentRefs.get(td);
688
+ if (compRef) {
689
+ this.destroyComponent(compRef);
690
+ this._tdComponentRefs.delete(td);
691
+ compRefs?.delete(compRef);
692
+ }
693
+ const embView = this._tdEmbeddedViews.get(td);
694
+ if (embView) {
695
+ this.destroyEmbeddedView(embView);
696
+ this._tdEmbeddedViews.delete(td);
697
+ embViews?.delete(embView);
698
+ }
699
+ });
700
+ compRefs?.forEach((ref) => this.destroyComponent(ref));
701
+ embViews?.forEach((view) => this.destroyEmbeddedView(view));
702
+ if (instance) {
703
+ this._instanceComponentRefs.delete(instance);
704
+ this._instanceEmbeddedViews.delete(instance);
705
+ }
706
+ }
707
+ registerSweepHook(instance) {
708
+ if (this._hookedInstances.has(instance) || typeof instance?.addHook !== "function") return;
709
+ this._hookedInstances.add(instance);
710
+ instance.addHook("afterViewRender", () => this.sweepDetachedViews(instance));
711
+ }
712
+ sweepDetachedViews(instance) {
713
+ const compRefs = this._instanceComponentRefs.get(instance);
714
+ compRefs?.forEach((ref) => {
715
+ if (!this.isViewConnected(ref.hostView)) {
716
+ this.destroyComponent(ref);
717
+ compRefs.delete(ref);
718
+ }
719
+ });
720
+ const embViews = this._instanceEmbeddedViews.get(instance);
721
+ embViews?.forEach((view) => {
722
+ if (!this.isViewConnected(view)) {
723
+ this.destroyEmbeddedView(view);
724
+ embViews.delete(view);
725
+ }
726
+ });
727
+ }
728
+ isViewConnected(view) {
729
+ return view.rootNodes.some((node) => !!node?.isConnected);
730
+ }
731
+ replaceCellContent(instance, td) {
732
+ const prevRef = this._tdComponentRefs.get(td);
733
+ if (prevRef) {
734
+ this.destroyComponent(prevRef);
735
+ this._tdComponentRefs.delete(td);
736
+ this._instanceComponentRefs.get(instance)?.delete(prevRef);
737
+ }
738
+ const prevView = this._tdEmbeddedViews.get(td);
739
+ if (prevView) {
740
+ this.destroyEmbeddedView(prevView);
741
+ this._tdEmbeddedViews.delete(td);
742
+ this._instanceEmbeddedViews.get(instance)?.delete(prevView);
743
+ }
744
+ td.replaceChildren();
745
+ }
746
+ trackComponentRef(instance, td, ref) {
747
+ this._tdComponentRefs.set(td, ref);
748
+ this.registryFor(this._instanceComponentRefs, instance).add(ref);
749
+ }
750
+ trackEmbeddedView(instance, td, view) {
751
+ this._tdEmbeddedViews.set(td, view);
752
+ this.registryFor(this._instanceEmbeddedViews, instance).add(view);
753
+ }
754
+ registryFor(registry, instance) {
755
+ let set = registry.get(instance);
756
+ if (!set) {
757
+ set = /* @__PURE__ */ new Set();
758
+ registry.set(instance, set);
759
+ }
760
+ return set;
761
+ }
762
+ attachTemplateToElement(template, tdEl, properties) {
763
+ const embeddedView = template.createEmbeddedView({
764
+ $implicit: properties.value,
765
+ ...properties
766
+ });
767
+ embeddedView.detectChanges();
768
+ embeddedView.rootNodes.forEach((node) => {
769
+ tdEl.appendChild(node);
770
+ });
771
+ return embeddedView;
772
+ }
773
+ createComponent(component, rendererParameters) {
774
+ const componentRef = createComponent(component, { environmentInjector: this.environmentInjector });
775
+ this.applyInputs(componentRef, rendererParameters);
776
+ componentRef.changeDetectorRef.detectChanges();
777
+ this.appRef.attachView(componentRef.hostView);
778
+ return componentRef;
779
+ }
780
+ renderComponent(td, component, properties) {
781
+ const prevRef = this._tdComponentRefs.get(td);
782
+ if (prevRef && prevRef.componentType === component && this.isViewConnected(prevRef.hostView)) {
783
+ this.applyInputs(prevRef, properties);
784
+ prevRef.changeDetectorRef.detectChanges();
785
+ return;
786
+ }
787
+ this.replaceCellContent(properties.instance, td);
788
+ const componentRef = this.createComponent(component, properties);
789
+ this.attachComponentToElement(componentRef, td);
790
+ this.trackComponentRef(properties.instance, td, componentRef);
791
+ }
792
+ applyInputs(componentRef, rendererParameters) {
793
+ RENDERER_INPUT_KEYS.forEach((key) => {
794
+ componentRef.setInput(key, rendererParameters[key]);
795
+ });
796
+ }
797
+ attachComponentToElement(componentRef, container) {
798
+ componentRef.hostView.rootNodes.forEach((node) => {
799
+ container.appendChild(node);
800
+ });
801
+ }
802
+ destroyComponent(componentRef) {
803
+ const hostView = componentRef.hostView;
804
+ if (hostView.destroyed) return;
805
+ this.appRef.detachView(hostView);
806
+ componentRef.destroy();
807
+ }
808
+ destroyEmbeddedView(view) {
809
+ if (view.destroyed) return;
810
+ view.destroy();
811
+ }
812
+ static ɵfac = i0.ɵɵngDeclareFactory({
813
+ minVersion: "12.0.0",
814
+ version: "22.2.2",
815
+ ngImport: i0,
816
+ type: DynamicComponentService,
817
+ deps: [{ token: i0.ApplicationRef }, { token: i0.EnvironmentInjector }],
818
+ target: i0.ɵɵFactoryTarget.Injectable
819
+ });
820
+ static ɵprov = i0.ɵɵngDeclareInjectable({
821
+ minVersion: "12.0.0",
822
+ version: "22.2.2",
823
+ ngImport: i0,
824
+ type: DynamicComponentService,
825
+ providedIn: "root"
826
+ });
827
+ };
828
+ i0.ɵɵngDeclareClassMetadata({
829
+ minVersion: "12.0.0",
830
+ version: "22.2.2",
831
+ ngImport: i0,
832
+ type: DynamicComponentService,
833
+ decorators: [{
834
+ type: Injectable,
835
+ args: [{ providedIn: "root" }]
836
+ }],
837
+ ctorParameters: () => [{ type: i0.ApplicationRef }, { type: i0.EnvironmentInjector }]
838
+ });
1041
839
  const AVAILABLE_HOOKS_SET = new Set(Handsontable.hooks.getRegistered());
1042
- const HOT_ZONE_WRAPPED = Symbol('hotZoneWrapped');
1043
- /**
1044
- * Service to resolve and apply custom settings for Handsontable settings object.
1045
- */
1046
- class HotSettingsResolver {
1047
- dynamicComponentService;
1048
- environmentInjector;
1049
- ngZone;
1050
- constructor(dynamicComponentService, environmentInjector, ngZone) {
1051
- this.dynamicComponentService = dynamicComponentService;
1052
- this.environmentInjector = environmentInjector;
1053
- this.ngZone = ngZone;
1054
- }
1055
- /**
1056
- * Applies custom settings to the provided GridSettings.
1057
- * @param settings The original grid settings.
1058
- * @param previousColumns The previously resolved columns (from the prior settings cycle). When
1059
- * supplied, an editor component already created for a column whose editor type is unchanged is
1060
- * recycled instead of being recreated, avoiding needless Angular component teardown/rebuild.
1061
- * @returns The merged grid settings with custom settings applied.
1062
- */
1063
- applyCustomSettings(settings, previousColumns) {
1064
- // Shallow-clone the user settings (and each column) before mutating. Otherwise we would
1065
- // write generated renderers/editors and `_editorComponentReference` straight onto the
1066
- // caller's objects. When the same settings/columns are shared across two <hot-table>
1067
- // instances, the second resolution would overwrite the first instance's editor refs,
1068
- // leaking them and cross-wiring a single editor component between tables.
1069
- const mergedSettings = { ...settings };
1070
- if (Array.isArray(mergedSettings.columns)) {
1071
- mergedSettings.columns = mergedSettings.columns.map((column) => ({ ...column }));
1072
- }
1073
- this.updateColumnRendererForGivenCustomRenderer(mergedSettings);
1074
- this.updateColumnEditorForGivenCustomEditor(mergedSettings, previousColumns);
1075
- this.updateColumnValidatorForGivenCustomValidator(mergedSettings);
1076
- this.wrapHooksInNgZone(mergedSettings);
1077
- return mergedSettings;
1078
- }
1079
- /**
1080
- * Ensures that hook callbacks in the provided grid settings run inside Angular's zone.
1081
- *
1082
- * @param settings The original grid settings.
1083
- */
1084
- wrapHooksInNgZone(settings) {
1085
- const ngZone = this.ngZone;
1086
- // Iterate only the keys actually present in settings instead of all ~100 registered HOT hooks.
1087
- Object.keys(settings).forEach((key) => {
1088
- if (!AVAILABLE_HOOKS_SET.has(key)) {
1089
- return;
1090
- }
1091
- const option = settings[key];
1092
- if (typeof option === 'function' && !option[HOT_ZONE_WRAPPED]) {
1093
- const wrapped = function (...args) {
1094
- return ngZone.run(() => option.apply(this, args));
1095
- };
1096
- wrapped[HOT_ZONE_WRAPPED] = true;
1097
- settings[key] = wrapped;
1098
- }
1099
- });
1100
- }
1101
- /**
1102
- * Updates the column renderer for columns with a custom renderer.
1103
- * @param mergedSettings The merged grid settings.
1104
- */
1105
- updateColumnRendererForGivenCustomRenderer(mergedSettings) {
1106
- if (!Array.isArray(mergedSettings?.columns)) {
1107
- return;
1108
- }
1109
- mergedSettings?.columns
1110
- ?.filter((settings) => this.isCustomRenderer(settings.renderer))
1111
- ?.forEach((cellSettings) => {
1112
- const renderer = cellSettings.renderer;
1113
- const props = cellSettings.rendererProps ?? {};
1114
- if (this.isAdvancedRendererComponentRefType(renderer)) {
1115
- cellSettings.renderer = this.dynamicComponentService.createRendererWithFactory(renderer, props);
1116
- }
1117
- else if (this.isRendererComponentRefType(renderer) || this.isTemplateRef(renderer)) {
1118
- cellSettings.renderer = this.dynamicComponentService.createRendererFromComponent(renderer, props);
1119
- }
1120
- });
1121
- }
1122
- /**
1123
- * Updates the column editor for columns with a custom editor.
1124
- *
1125
- * Iterates by original column index (not a filtered subset) so each column can be matched against
1126
- * the column at the same index in `previousColumns` for editor-component recycling.
1127
- *
1128
- * @param mergedSettings The merged grid settings.
1129
- * @param previousColumns The previously resolved columns, used to recycle editor components.
1130
- */
1131
- updateColumnEditorForGivenCustomEditor(mergedSettings, previousColumns) {
1132
- if (!Array.isArray(mergedSettings?.columns)) {
1133
- return;
1134
- }
1135
- mergedSettings.columns.forEach((cellSettings, index) => {
1136
- const isAdvanced = this.isAdvancedEditorComponentRefType(cellSettings.editor);
1137
- const isBasic = this.isEditorComponentRefType(cellSettings.editor);
1138
- if (!isAdvanced && !isBasic) {
1139
- return;
1140
- }
1141
- const editorType = cellSettings.editor;
1142
- const reusableRef = this.reusableEditorRef(previousColumns?.[index], cellSettings, editorType);
1143
- const internalSettings = cellSettings;
1144
- // Recycle the editor component from the previous settings cycle when the same editor type
1145
- // sits at the same column index AND the same logical column (by `data`) still occupies it.
1146
- // Recreating it on every settings change would tear down and rebuild an Angular component
1147
- // (and its DOM/internal state) for no reason. The reused ref is carried into the new column;
1148
- // HotTableComponent.ngOnChanges detects it by identity and skips destroying it.
1149
- const component = reusableRef ?? createComponent(editorType, {
1150
- environmentInjector: this.environmentInjector,
1151
- });
1152
- internalSettings._editorComponentReference = component;
1153
- if (isAdvanced) {
1154
- cellSettings.editor = FactoryEditorAdapter(component);
1155
- }
1156
- else {
1157
- internalSettings._environmentInjector = this.environmentInjector;
1158
- cellSettings.editor = BaseEditorAdapter;
1159
- }
1160
- });
1161
- }
1162
- /**
1163
- * Returns the previous column's editor component ref when it can be reused for the new column, or
1164
- * `undefined` to signal a fresh component is needed.
1165
- *
1166
- * A ref is only recycled when, at the same index, both the editor component type AND the logical
1167
- * column identity (its `data` binding) are unchanged. The component-type check alone would already
1168
- * be functionally safe — a Handsontable editor is not per-cell rendered state but a single
1169
- * on-demand component that `BaseEditorAdapter`/`FactoryEditorAdapter` re-prepare on every edit
1170
- * (`prepare()` re-reads the ref from the *current* column meta and `applyPropsToEditor()` re-applies
1171
- * the full cell context on each `open()`). The extra `data` check is a defensive guard: when columns
1172
- * are reordered/shortened so a *different* logical column lands on an index, we build a fresh editor
1173
- * rather than carry the previous column's instance over, so no custom editor that caches
1174
- * column-specific config at construction can leak stale state into the new cell.
1175
- *
1176
- * @param previousColumn The column at the same index in the previous settings cycle.
1177
- * @param currentColumn The column now occupying this index.
1178
- * @param editorType The editor component type requested for the new column.
1179
- */
1180
- reusableEditorRef(previousColumn, currentColumn, editorType) {
1181
- const previousRef = previousColumn?._editorComponentReference;
1182
- if (!previousRef || previousRef.componentType !== editorType) {
1183
- return undefined;
1184
- }
1185
- // Same logical column still occupies this index. Columns without a `data` binding are identified
1186
- // purely by position, so two `undefined` data values compare equal and recycle as before.
1187
- const sameLogicalColumn = previousColumn?.data ===
1188
- currentColumn.data;
1189
- return sameLogicalColumn ? previousRef : undefined;
1190
- }
1191
- /**
1192
- * Updates the column validator for columns with a custom validator.
1193
- * @param mergedSettings The merged grid settings.
1194
- */
1195
- updateColumnValidatorForGivenCustomValidator(mergedSettings) {
1196
- if (!Array.isArray(mergedSettings?.columns)) {
1197
- return;
1198
- }
1199
- mergedSettings?.columns
1200
- ?.filter((settings) => this.isCustomValidatorFn(settings.validator))
1201
- ?.forEach((cellSettings) => {
1202
- const customValidatorFn = cellSettings.validator;
1203
- cellSettings.validator = (value, callback) => {
1204
- callback(customValidatorFn(value));
1205
- };
1206
- });
1207
- }
1208
- isCustomValidatorFn(validator) {
1209
- return typeof validator === 'function' && validator.length === 1;
1210
- }
1211
- isEditorComponentRefType(editor) {
1212
- // ecmp - we need it to check if the editor is a component
1213
- return typeof editor === 'function' &&
1214
- !!editor?.ɵcmp &&
1215
- editor?.EDITOR_MARKER === HotCellEditorComponent.EDITOR_MARKER;
1216
- }
1217
- isAdvancedEditorComponentRefType(editor) {
1218
- // ecmp - we need it to check if the editor is a component
1219
- return typeof editor === 'function' &&
1220
- !!editor?.ɵcmp &&
1221
- editor?.EDITOR_MARKER === HotCellEditorAdvancedComponent.EDITOR_MARKER;
1222
- }
1223
- isRendererComponentRefType(renderer) {
1224
- // ecmp - we need it to check if the renderer is a component
1225
- return typeof renderer === 'function' &&
1226
- !!renderer?.ɵcmp &&
1227
- renderer?.RENDERER_MARKER === HotCellRendererComponent.RENDERER_MARKER;
1228
- }
1229
- isAdvancedRendererComponentRefType(renderer) {
1230
- // ecmp - we need it to check if the renderer is a component
1231
- return typeof renderer === 'function' &&
1232
- !!renderer?.ɵcmp &&
1233
- renderer?.RENDERER_MARKER === HotCellRendererAdvancedComponent.RENDERER_MARKER;
1234
- }
1235
- isTemplateRef(renderer) {
1236
- return renderer && typeof renderer.createEmbeddedView === 'function';
1237
- }
1238
- isCustomRenderer(renderer) {
1239
- return this.isRendererComponentRefType(renderer) ||
1240
- this.isTemplateRef(renderer) ||
1241
- this.isAdvancedRendererComponentRefType(renderer);
1242
- }
1243
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotSettingsResolver, deps: [{ token: DynamicComponentService }, { token: i0.EnvironmentInjector }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
1244
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotSettingsResolver });
1245
- }
1246
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotSettingsResolver, decorators: [{
1247
- type: Injectable
1248
- }], ctorParameters: () => [{ type: DynamicComponentService }, { type: i0.EnvironmentInjector }, { type: i0.NgZone }] });
1249
-
1250
- /**
1251
- * A constant representing the non-commercial and evaluation license.
1252
- * */
1253
- const NON_COMMERCIAL_LICENSE = 'non-commercial-and-evaluation';
1254
- /**
1255
- * Type representing a theme name.
1256
- * Possible values include predefined themes and any custom string.
1257
- */
840
+ const HOT_ZONE_WRAPPED = Symbol("hotZoneWrapped");
841
+ var HotSettingsResolver = class HotSettingsResolver {
842
+ dynamicComponentService;
843
+ environmentInjector;
844
+ ngZone;
845
+ constructor(dynamicComponentService, environmentInjector, ngZone) {
846
+ this.dynamicComponentService = dynamicComponentService;
847
+ this.environmentInjector = environmentInjector;
848
+ this.ngZone = ngZone;
849
+ }
850
+ applyCustomSettings(settings, previousColumns) {
851
+ const mergedSettings = { ...settings };
852
+ if (Array.isArray(mergedSettings.columns)) mergedSettings.columns = mergedSettings.columns.map((column) => ({ ...column }));
853
+ this.updateColumnRendererForGivenCustomRenderer(mergedSettings);
854
+ this.updateColumnEditorForGivenCustomEditor(mergedSettings, previousColumns);
855
+ this.updateColumnValidatorForGivenCustomValidator(mergedSettings);
856
+ this.wrapHooksInNgZone(mergedSettings);
857
+ return mergedSettings;
858
+ }
859
+ wrapHooksInNgZone(settings) {
860
+ const ngZone = this.ngZone;
861
+ Object.keys(settings).forEach((key) => {
862
+ if (!AVAILABLE_HOOKS_SET.has(key)) return;
863
+ const option = settings[key];
864
+ if (typeof option === "function" && !option[HOT_ZONE_WRAPPED]) {
865
+ const wrapped = function(...args) {
866
+ return ngZone.run(() => option.apply(this, args));
867
+ };
868
+ wrapped[HOT_ZONE_WRAPPED] = true;
869
+ settings[key] = wrapped;
870
+ }
871
+ });
872
+ }
873
+ updateColumnRendererForGivenCustomRenderer(mergedSettings) {
874
+ if (!Array.isArray(mergedSettings?.columns)) return;
875
+ mergedSettings?.columns?.filter((settings) => this.isCustomRenderer(settings.renderer))?.forEach((cellSettings) => {
876
+ const renderer = cellSettings.renderer;
877
+ const props = cellSettings.rendererProps ?? {};
878
+ if (this.isAdvancedRendererComponentRefType(renderer)) cellSettings.renderer = this.dynamicComponentService.createRendererWithFactory(renderer, props);
879
+ else if (this.isRendererComponentRefType(renderer) || this.isTemplateRef(renderer)) cellSettings.renderer = this.dynamicComponentService.createRendererFromComponent(renderer, props);
880
+ });
881
+ }
882
+ updateColumnEditorForGivenCustomEditor(mergedSettings, previousColumns) {
883
+ if (!Array.isArray(mergedSettings?.columns)) return;
884
+ mergedSettings.columns.forEach((cellSettings, index) => {
885
+ const isAdvanced = this.isAdvancedEditorComponentRefType(cellSettings.editor);
886
+ const isBasic = this.isEditorComponentRefType(cellSettings.editor);
887
+ if (!isAdvanced && !isBasic) return;
888
+ const editorType = cellSettings.editor;
889
+ const reusableRef = this.reusableEditorRef(previousColumns?.[index], cellSettings, editorType);
890
+ const internalSettings = cellSettings;
891
+ const component = reusableRef ?? createComponent(editorType, { environmentInjector: this.environmentInjector });
892
+ internalSettings._editorComponentReference = component;
893
+ if (isAdvanced) cellSettings.editor = FactoryEditorAdapter(component);
894
+ else {
895
+ internalSettings._environmentInjector = this.environmentInjector;
896
+ cellSettings.editor = BaseEditorAdapter;
897
+ }
898
+ });
899
+ }
900
+ reusableEditorRef(previousColumn, currentColumn, editorType) {
901
+ const previousRef = previousColumn?._editorComponentReference;
902
+ if (!previousRef || previousRef.componentType !== editorType) return;
903
+ return previousColumn?.data === currentColumn.data ? previousRef : void 0;
904
+ }
905
+ updateColumnValidatorForGivenCustomValidator(mergedSettings) {
906
+ if (!Array.isArray(mergedSettings?.columns)) return;
907
+ mergedSettings?.columns?.filter((settings) => this.isCustomValidatorFn(settings.validator))?.forEach((cellSettings) => {
908
+ const customValidatorFn = cellSettings.validator;
909
+ cellSettings.validator = (value, callback) => {
910
+ callback(customValidatorFn(value));
911
+ };
912
+ });
913
+ }
914
+ isCustomValidatorFn(validator) {
915
+ return typeof validator === "function" && validator.length === 1;
916
+ }
917
+ isEditorComponentRefType(editor) {
918
+ return typeof editor === "function" && !!editor?.ɵcmp && editor?.EDITOR_MARKER === HotCellEditorComponent.EDITOR_MARKER;
919
+ }
920
+ isAdvancedEditorComponentRefType(editor) {
921
+ return typeof editor === "function" && !!editor?.ɵcmp && editor?.EDITOR_MARKER === HotCellEditorAdvancedComponent.EDITOR_MARKER;
922
+ }
923
+ isRendererComponentRefType(renderer) {
924
+ return typeof renderer === "function" && !!renderer?.ɵcmp && renderer?.RENDERER_MARKER === HotCellRendererComponent.RENDERER_MARKER;
925
+ }
926
+ isAdvancedRendererComponentRefType(renderer) {
927
+ return typeof renderer === "function" && !!renderer?.ɵcmp && renderer?.RENDERER_MARKER === HotCellRendererAdvancedComponent.RENDERER_MARKER;
928
+ }
929
+ isTemplateRef(renderer) {
930
+ return renderer && typeof renderer.createEmbeddedView === "function";
931
+ }
932
+ isCustomRenderer(renderer) {
933
+ return this.isRendererComponentRefType(renderer) || this.isTemplateRef(renderer) || this.isAdvancedRendererComponentRefType(renderer);
934
+ }
935
+ static ɵfac = i0.ɵɵngDeclareFactory({
936
+ minVersion: "12.0.0",
937
+ version: "22.2.2",
938
+ ngImport: i0,
939
+ type: HotSettingsResolver,
940
+ deps: [
941
+ { token: DynamicComponentService },
942
+ { token: i0.EnvironmentInjector },
943
+ { token: i0.NgZone }
944
+ ],
945
+ target: i0.ɵɵFactoryTarget.Injectable
946
+ });
947
+ static ɵprov = i0.ɵɵngDeclareInjectable({
948
+ minVersion: "12.0.0",
949
+ version: "22.2.2",
950
+ ngImport: i0,
951
+ type: HotSettingsResolver
952
+ });
953
+ };
954
+ i0.ɵɵngDeclareClassMetadata({
955
+ minVersion: "12.0.0",
956
+ version: "22.2.2",
957
+ ngImport: i0,
958
+ type: HotSettingsResolver,
959
+ decorators: [{ type: Injectable }],
960
+ ctorParameters: () => [
961
+ { type: DynamicComponentService },
962
+ { type: i0.EnvironmentInjector },
963
+ { type: i0.NgZone }
964
+ ]
965
+ });
966
+ const NON_COMMERCIAL_LICENSE = "non-commercial-and-evaluation";
1258
967
  var PredefinedTheme;
1259
- (function (PredefinedTheme) {
1260
- PredefinedTheme["Main"] = "ht-theme-main";
1261
- PredefinedTheme["MainDark"] = "ht-theme-main-dark";
1262
- PredefinedTheme["MainDarkAuto"] = "ht-theme-main-dark-auto";
1263
- PredefinedTheme["Horizon"] = "ht-theme-horizon";
1264
- PredefinedTheme["HorizonDark"] = "ht-theme-horizon-dark";
1265
- PredefinedTheme["HorizonDarkAuto"] = "ht-theme-horizon-dark-auto";
968
+ (function(PredefinedTheme) {
969
+ PredefinedTheme["Main"] = "ht-theme-main";
970
+ PredefinedTheme["MainDark"] = "ht-theme-main-dark";
971
+ PredefinedTheme["MainDarkAuto"] = "ht-theme-main-dark-auto";
972
+ PredefinedTheme["Horizon"] = "ht-theme-horizon";
973
+ PredefinedTheme["HorizonDark"] = "ht-theme-horizon-dark";
974
+ PredefinedTheme["HorizonDarkAuto"] = "ht-theme-horizon-dark-auto";
1266
975
  })(PredefinedTheme || (PredefinedTheme = {}));
1267
- /**
1268
- * Injection token for providing a global default configuration.
1269
- */
1270
- const HOT_GLOBAL_CONFIG = new InjectionToken('HOT_GLOBAL_CONFIG', {
1271
- providedIn: 'root',
1272
- factory: () => ({})
976
+ const HOT_GLOBAL_CONFIG = new InjectionToken("HOT_GLOBAL_CONFIG", {
977
+ providedIn: "root",
978
+ factory: () => ({})
1273
979
  });
1274
- /**
1275
- * Service for configuring Handsontable settings.
1276
- * This service allows setting and retrieving global configuration.
1277
- */
1278
- class HotGlobalConfigService {
1279
- /**
1280
- * The default configuration object for Handsontable.
1281
- *
1282
- * This object is used as the initial value for the configuration BehaviorSubject.
1283
- * It can be overridden by a global configuration provided through the
1284
- * {@link HOT_GLOBAL_CONFIG} injection token.
1285
- *
1286
- * @private
1287
- * @type {HotGlobalConfig}
1288
- */
1289
- defaultConfig = {};
1290
- /**
1291
- * A BehaviorSubject that holds the current Handsontable configuration.
1292
- *
1293
- * New configuration values can be emitted by calling next() on this subject.
1294
- * This allows subscribers to react to configuration changes dynamically.
1295
- *
1296
- * @private
1297
- * @type {BehaviorSubject<HotGlobalConfig>}
1298
- */
1299
- configSubject = new BehaviorSubject(this.defaultConfig);
1300
- /**
1301
- * An Observable stream of the current Handsontable configuration.
1302
- *
1303
- * Components can subscribe to this observable to receive updates whenever the configuration changes.
1304
- *
1305
- * @returns The configuration as an observable stream.
1306
- */
1307
- get config$() {
1308
- return this.configSubject.asObservable();
1309
- }
1310
- constructor(globalConfig) {
1311
- // Merge global configuration (if provided) into defaultConfig immutably.
1312
- this.defaultConfig = { ...this.defaultConfig, ...globalConfig };
1313
- this.configSubject.next(this.defaultConfig);
1314
- }
1315
- /**
1316
- * Sets the global configuration for Handsontable.
1317
- *
1318
- * @param config - An object containing configuration options.
1319
- * Each Handsontable instance can override this configuration by providing its own settings.
1320
- */
1321
- setConfig(config) {
1322
- this.configSubject.next({ ...this.defaultConfig, ...config });
1323
- }
1324
- /**
1325
- * Retrieves the current Handsontable configuration.
1326
- *
1327
- * @returns An object with the current settings.
1328
- */
1329
- getConfig() {
1330
- return this.configSubject.value;
1331
- }
1332
- /**
1333
- * Resets the configuration to the default settings.
1334
- * This method updates the configuration BehaviorSubject with the default configuration.
1335
- */
1336
- resetConfig() {
1337
- this.configSubject.next({ ...this.defaultConfig });
1338
- }
1339
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotGlobalConfigService, deps: [{ token: HOT_GLOBAL_CONFIG }], target: i0.ɵɵFactoryTarget.Injectable });
1340
- static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotGlobalConfigService, providedIn: 'root' });
1341
- }
1342
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotGlobalConfigService, decorators: [{
1343
- type: Injectable,
1344
- args: [{
1345
- providedIn: 'root',
1346
- }]
1347
- }], ctorParameters: () => [{ type: undefined, decorators: [{
1348
- type: Inject,
1349
- args: [HOT_GLOBAL_CONFIG]
1350
- }] }] });
1351
-
1352
- const HOT_DESTROYED_WARNING = 'The Handsontable instance bound to this component was destroyed and cannot be' + ' used properly.';
1353
- /**
1354
- * The size options that discard the sizes stored by the manual resize plugins when they are passed
1355
- * to `updateSettings()`.
1356
- */
1357
- const SIZE_SETTING_KEYS = new Set(['rowHeights', 'minRowHeights', 'colWidths']);
1358
- /**
1359
- * Compares two size option values. Both hold a number, a string, a function or an array of numbers
1360
- * or strings, so an element-wise walk is enough - and it is what makes a value written inline in a
1361
- * template, which is a new array on every change detection run, compare as unchanged.
1362
- *
1363
- * A function is compared by reference only. It states no fixed size, and the core plugins ignore it
1364
- * when deciding whether the sizes were re-declared, so forwarding it changes nothing either way.
1365
- *
1366
- * @param currentValue The value the grid currently holds.
1367
- * @param newValue The value coming from the `settings` input.
1368
- * @returns `true` when the two state the same sizes.
1369
- */
980
+ var HotGlobalConfigService = class HotGlobalConfigService {
981
+ defaultConfig = {};
982
+ configSubject = new BehaviorSubject(this.defaultConfig);
983
+ get config$() {
984
+ return this.configSubject.asObservable();
985
+ }
986
+ constructor(globalConfig) {
987
+ this.defaultConfig = {
988
+ ...this.defaultConfig,
989
+ ...globalConfig
990
+ };
991
+ this.configSubject.next(this.defaultConfig);
992
+ }
993
+ setConfig(config) {
994
+ this.configSubject.next({
995
+ ...this.defaultConfig,
996
+ ...config
997
+ });
998
+ }
999
+ getConfig() {
1000
+ return this.configSubject.value;
1001
+ }
1002
+ resetConfig() {
1003
+ this.configSubject.next({ ...this.defaultConfig });
1004
+ }
1005
+ static ɵfac = i0.ɵɵngDeclareFactory({
1006
+ minVersion: "12.0.0",
1007
+ version: "22.2.2",
1008
+ ngImport: i0,
1009
+ type: HotGlobalConfigService,
1010
+ deps: [{ token: HOT_GLOBAL_CONFIG }],
1011
+ target: i0.ɵɵFactoryTarget.Injectable
1012
+ });
1013
+ static ɵprov = i0.ɵɵngDeclareInjectable({
1014
+ minVersion: "12.0.0",
1015
+ version: "22.2.2",
1016
+ ngImport: i0,
1017
+ type: HotGlobalConfigService,
1018
+ providedIn: "root"
1019
+ });
1020
+ };
1021
+ i0.ɵɵngDeclareClassMetadata({
1022
+ minVersion: "12.0.0",
1023
+ version: "22.2.2",
1024
+ ngImport: i0,
1025
+ type: HotGlobalConfigService,
1026
+ decorators: [{
1027
+ type: Injectable,
1028
+ args: [{ providedIn: "root" }]
1029
+ }],
1030
+ ctorParameters: () => [{
1031
+ type: void 0,
1032
+ decorators: [{
1033
+ type: Inject,
1034
+ args: [HOT_GLOBAL_CONFIG]
1035
+ }]
1036
+ }]
1037
+ });
1038
+ const HOT_DESTROYED_WARNING = "The Handsontable instance bound to this component was destroyed and cannot be used properly.";
1039
+ const SIZE_SETTING_KEYS = /* @__PURE__ */ new Set([
1040
+ "rowHeights",
1041
+ "minRowHeights",
1042
+ "colWidths"
1043
+ ]);
1370
1044
  function isSameSizeSetting(currentValue, newValue) {
1371
- if (currentValue === newValue) {
1372
- return true;
1373
- }
1374
- if (Array.isArray(currentValue) && Array.isArray(newValue)) {
1375
- return currentValue.length === newValue.length &&
1376
- currentValue.every((value, index) => value === newValue[index]);
1377
- }
1378
- return false;
1045
+ if (currentValue === newValue) return true;
1046
+ if (Array.isArray(currentValue) && Array.isArray(newValue)) return currentValue.length === newValue.length && currentValue.every((value, index) => value === newValue[index]);
1047
+ return false;
1379
1048
  }
1380
- /**
1381
- * The class that makes the container and the host fill their parent. The component styles below
1382
- * spell the same name, because decorator metadata must stay statically analyzable.
1383
- */
1384
- const FILL_HEIGHT_CLASS_NAME = 'ht-fill-height';
1385
- /**
1386
- * A `height` that resolves against the container: a percentage, or a `var()` that may hold one.
1387
- * The core treats the same two as container-driven in `utils/rootSize.ts`, together with units that
1388
- * resolve against the viewport or a query container, which do not depend on the container here.
1389
- */
1049
+ const FILL_HEIGHT_CLASS_NAME = "ht-fill-height";
1390
1050
  const RELATIVE_HEIGHT_PATTERN = /%|\bvar\(/i;
1391
- class HotTableComponent {
1392
- _hotSettingsResolver;
1393
- _hotConfig;
1394
- ngZone;
1395
- environmentInjector;
1396
- _dynamicComponentService;
1397
- // component inputs
1398
- /** The data for the Handsontable instance. */
1399
- data = null;
1400
- /** The settings for the Handsontable instance. */
1401
- settings = {};
1402
- /** The container element for the Handsontable instance. */
1403
- container;
1404
- /** The Handsontable instance. */
1405
- __hotInstance = null;
1406
- _destroyRef = inject(DestroyRef);
1407
- _host = inject(ElementRef);
1408
- constructor(_hotSettingsResolver, _hotConfig, ngZone, environmentInjector, _dynamicComponentService) {
1409
- this._hotSettingsResolver = _hotSettingsResolver;
1410
- this._hotConfig = _hotConfig;
1411
- this.ngZone = ngZone;
1412
- this.environmentInjector = environmentInjector;
1413
- this._dynamicComponentService = _dynamicComponentService;
1414
- }
1415
- /**
1416
- * Gets the Handsontable instance.
1417
- * @returns The Handsontable instance or `null` if it's not yet been created or has been destroyed.
1418
- */
1419
- get hotInstance() {
1420
- if (!this.__hotInstance || !this.__hotInstance.isDestroyed) {
1421
- // Will return the Handsontable instance or `null` if it's not yet been created.
1422
- return this.__hotInstance;
1423
- }
1424
- else {
1425
- console.warn(HOT_DESTROYED_WARNING);
1426
- return null;
1427
- }
1428
- }
1429
- /**
1430
- * Sets the Handsontable instance.
1431
- * @param hotInstance The Handsontable instance to set.
1432
- */
1433
- set hotInstance(hotInstance) {
1434
- this.__hotInstance = hotInstance;
1435
- }
1436
- /**
1437
- * Initializes the Handsontable instance after the view has been initialized.
1438
- * The initial settings of the table are also prepared here
1439
- */
1440
- ngAfterViewInit() {
1441
- let options = this._hotSettingsResolver.applyCustomSettings(this.settings);
1442
- const negotiatedSettings = this.getNegotiatedSettings(options);
1443
- options = { ...options, ...negotiatedSettings, ...(this.data != null ? { data: this.data } : {}) };
1444
- this.ngZone.runOutsideAngular(() => {
1445
- this.hotInstance = new Handsontable.Core(this.container.nativeElement, options);
1446
- this.hotInstance._angularEnvironmentInjector = this.environmentInjector;
1447
- // Registered before `init()`, so the hook also sees the initial `height`, before the first render.
1448
- this.hotInstance.addHook('beforeHeightChange', (height) => {
1449
- this.toggleFillHeight(height);
1450
- return height;
1451
- });
1452
- this.hotInstance.init();
1453
- });
1454
- this._hotConfig.config$.pipe(skip(1), takeUntilDestroyed(this._destroyRef)).subscribe((config) => {
1455
- if (this.hotInstance) {
1456
- const negotiatedSettings = this.getNegotiatedSettings(this.settings);
1457
- this.updateHotTable(negotiatedSettings);
1458
- }
1459
- });
1460
- }
1461
- ngOnChanges(changes) {
1462
- if (this.hotInstance === null) {
1463
- return;
1464
- }
1465
- if (changes.settings && !changes.settings.firstChange) {
1466
- // Capture old editor refs before applying new settings so HOT can close any active editor first.
1467
- const prevColumns = this.__hotInstance?.getSettings().columns;
1468
- const prevColumnsArray = Array.isArray(prevColumns) ? prevColumns : undefined;
1469
- // Pass the previous columns so unchanged editor types recycle their existing component
1470
- // instead of creating a fresh one on every settings change.
1471
- const newOptions = this._hotSettingsResolver.applyCustomSettings(changes.settings.currentValue, prevColumnsArray);
1472
- // updateHotTable closes any active editor via HOT.updateSettings before we destroy old refs.
1473
- this.updateHotTable(newOptions);
1474
- // Only destroy old editor refs when new settings actually replace columns.
1475
- // If newOptions has no columns, HOT keeps the old column objects active — destroying
1476
- // their refs would crash FactoryEditorAdapter / BaseEditorAdapter on next edit.
1477
- if (prevColumnsArray && Array.isArray(newOptions.columns)) {
1478
- // Refs recycled into the new columns must survive — destroy only the ones left behind.
1479
- const reusedRefs = new Set(newOptions.columns
1480
- .map((column) => column._editorComponentReference)
1481
- .filter((ref) => !!ref));
1482
- prevColumnsArray.forEach((column) => {
1483
- if (column._editorComponentReference && !reusedRefs.has(column._editorComponentReference)) {
1484
- column._editorComponentReference.destroy();
1485
- }
1486
- });
1487
- }
1488
- }
1489
- if (changes.data && !changes.data.firstChange) {
1490
- this.hotInstance?.updateData(changes.data.currentValue);
1491
- }
1492
- }
1493
- /**
1494
- * Destroys the Handsontable instance and clears the columns from custom editors.
1495
- */
1496
- ngOnDestroy() {
1497
- this.ngZone.runOutsideAngular(() => {
1498
- if (!this.__hotInstance || this.__hotInstance.isDestroyed) {
1499
- return;
1500
- }
1501
- // Destroy renderer Angular components attached to table cells before HOT removes the DOM.
1502
- if (this.container) {
1503
- this._dynamicComponentService.cleanupContainer(this.container.nativeElement, this.__hotInstance);
1504
- }
1505
- const columns = this.__hotInstance.getSettings().columns;
1506
- if (columns && Array.isArray(columns)) {
1507
- columns.forEach((column) => {
1508
- if (column._editorComponentReference) {
1509
- column._editorComponentReference.destroy();
1510
- }
1511
- });
1512
- }
1513
- this.__hotInstance.destroy();
1514
- });
1515
- }
1516
- /**
1517
- * Makes the container and the `<hot-table>` host fill their parent when the grid `height` is
1518
- * relative.
1519
- *
1520
- * The core puts its root wrapper inside the container, and the `height: 100%` of the grid content
1521
- * resolves against the container. An auto-height container makes that `100%` collapse to `0px`, so
1522
- * the container has to pass the height of its parent through. React and Vue always do. Here it
1523
- * happens only for a relative `height` (`%` or `var()`), so grids with other heights keep their
1524
- * layout. The rule is a zero-specificity `:where()`, so any CSS of the app overrides it.
1525
- *
1526
- * @param height The value the `beforeHeightChange` hook received. It is the result of a `height`
1527
- * function, and it is `null` when the `height` is reset.
1528
- */
1529
- toggleFillHeight(height) {
1530
- const fillHeight = typeof height === 'string' && RELATIVE_HEIGHT_PATTERN.test(height);
1531
- this.container.nativeElement.classList.toggle(FILL_HEIGHT_CLASS_NAME, fillHeight);
1532
- this._host.nativeElement.classList.toggle(FILL_HEIGHT_CLASS_NAME, fillHeight);
1533
- }
1534
- /**
1535
- * Updates the Handsontable instance with new settings.
1536
- * @param newSettings The new settings to apply to the Handsontable instance.
1537
- */
1538
- updateHotTable(newSettings) {
1539
- if (!this.hotInstance) {
1540
- return;
1541
- }
1542
- const currentSettings = this.hotInstance.getSettings();
1543
- const initOnlySettingKeys = new Set(currentSettings?._initOnlySettings ?? []);
1544
- const filteredSettings = {};
1545
- for (const key of Object.keys(newSettings)) {
1546
- if (initOnlySettingKeys.has(key)) {
1547
- continue;
1548
- }
1549
- // `ngOnChanges` fires for the whole settings object, so every key is re-passed whenever any
1550
- // one of them changes. Passing `rowHeights` or `colWidths` re-declares the sizes and discards
1551
- // the ones the user produced by dragging, so an unchanged value must not be forwarded.
1552
- if (SIZE_SETTING_KEYS.has(key) &&
1553
- isSameSizeSetting(currentSettings?.[key], newSettings[key])) {
1554
- continue;
1555
- }
1556
- filteredSettings[key] = newSettings[key];
1557
- }
1558
- this.ngZone.runOutsideAngular(() => {
1559
- this.hotInstance?.updateSettings(filteredSettings, false);
1560
- });
1561
- }
1562
- /**
1563
- * Merges the provided Handsontable grid settings with the global configuration.
1564
- *
1565
- * This method retrieves the global configuration from the HotGlobalConfigService and negotiates the final
1566
- * Handsontable settings by giving precedence to the provided settings.
1567
- * Additionally, the `layoutDirection` is only merged if the Handsontable instance has not yet been initialized.
1568
- *
1569
- * @param settings - The grid settings provided by the user or component.
1570
- * @returns The final negotiated grid settings after merging with global defaults.
1571
- */
1572
- getNegotiatedSettings(settings) {
1573
- const hotConfig = this._hotConfig.getConfig();
1574
- const negotiatedSettings = {};
1575
- negotiatedSettings.licenseKey = settings.licenseKey ?? hotConfig.license;
1576
- negotiatedSettings.language = settings.language ?? hotConfig.language;
1577
- const theme = settings.theme ?? hotConfig.theme;
1578
- const themeName = settings.themeName ?? hotConfig.themeName;
1579
- if (theme !== undefined) {
1580
- negotiatedSettings.theme = theme;
1581
- }
1582
- else if (themeName) {
1583
- negotiatedSettings.themeName = themeName;
1584
- }
1585
- // settings that can be set only before the Handsontable instance is initialized
1586
- if (!this.__hotInstance) {
1587
- negotiatedSettings.layoutDirection = settings.layoutDirection ?? hotConfig.layoutDirection;
1588
- }
1589
- return negotiatedSettings;
1590
- }
1591
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotTableComponent, deps: [{ token: HotSettingsResolver }, { token: HotGlobalConfigService }, { token: i0.NgZone }, { token: i0.EnvironmentInjector }, { token: DynamicComponentService }], target: i0.ɵɵFactoryTarget.Component });
1592
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "19.2.25", type: HotTableComponent, isStandalone: true, selector: "hot-table", inputs: { data: "data", settings: "settings" }, providers: [HotSettingsResolver], viewQueries: [{ propertyName: "container", first: true, predicate: ["container"], descendants: true }], usesOnChanges: true, ngImport: i0, template: '<div #container></div>', isInline: true, styles: [":host{display:block}:where(hot-table.ht-fill-height,hot-table>div.ht-fill-height){height:100%}\n"], encapsulation: i0.ViewEncapsulation.None });
1593
- }
1594
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotTableComponent, decorators: [{
1595
- type: Component,
1596
- args: [{ selector: 'hot-table', template: '<div #container></div>', encapsulation: ViewEncapsulation.None, providers: [HotSettingsResolver], styles: [":host{display:block}:where(hot-table.ht-fill-height,hot-table>div.ht-fill-height){height:100%}\n"] }]
1597
- }], ctorParameters: () => [{ type: HotSettingsResolver }, { type: HotGlobalConfigService }, { type: i0.NgZone }, { type: i0.EnvironmentInjector }, { type: DynamicComponentService }], propDecorators: { data: [{
1598
- type: Input
1599
- }], settings: [{
1600
- type: Input
1601
- }], container: [{
1602
- type: ViewChild,
1603
- args: ['container', { static: false }]
1604
- }] } });
1605
-
1606
- class HotTableModule {
1607
- static version = '0.0.0-next-c272dd6-20261013';
1608
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotTableModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1609
- static ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "14.0.0", version: "19.2.25", ngImport: i0, type: HotTableModule, imports: [HotTableComponent], exports: [HotTableComponent] });
1610
- static ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotTableModule });
1611
- }
1612
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "19.2.25", ngImport: i0, type: HotTableModule, decorators: [{
1613
- type: NgModule,
1614
- args: [{
1615
- imports: [HotTableComponent],
1616
- exports: [HotTableComponent],
1617
- }]
1618
- }] });
1619
-
1620
- /*
1621
- * Public API Surface of hot-table
1622
- */
1623
-
1624
- /**
1625
- * Generated bundle index. Do not edit.
1626
- */
1627
-
1051
+ var HotTableComponent = class HotTableComponent {
1052
+ _hotSettingsResolver;
1053
+ _hotConfig;
1054
+ ngZone;
1055
+ environmentInjector;
1056
+ _dynamicComponentService;
1057
+ data = null;
1058
+ settings = {};
1059
+ container;
1060
+ __hotInstance = null;
1061
+ _destroyRef = inject(DestroyRef);
1062
+ _host = inject(ElementRef);
1063
+ constructor(_hotSettingsResolver, _hotConfig, ngZone, environmentInjector, _dynamicComponentService) {
1064
+ this._hotSettingsResolver = _hotSettingsResolver;
1065
+ this._hotConfig = _hotConfig;
1066
+ this.ngZone = ngZone;
1067
+ this.environmentInjector = environmentInjector;
1068
+ this._dynamicComponentService = _dynamicComponentService;
1069
+ }
1070
+ get hotInstance() {
1071
+ if (!this.__hotInstance || !this.__hotInstance.isDestroyed) return this.__hotInstance;
1072
+ else {
1073
+ console.warn(HOT_DESTROYED_WARNING);
1074
+ return null;
1075
+ }
1076
+ }
1077
+ set hotInstance(hotInstance) {
1078
+ this.__hotInstance = hotInstance;
1079
+ }
1080
+ ngAfterViewInit() {
1081
+ let options = this._hotSettingsResolver.applyCustomSettings(this.settings);
1082
+ const negotiatedSettings = this.getNegotiatedSettings(options);
1083
+ options = {
1084
+ ...options,
1085
+ ...negotiatedSettings,
1086
+ ...this.data != null ? { data: this.data } : {}
1087
+ };
1088
+ this.ngZone.runOutsideAngular(() => {
1089
+ this.hotInstance = new Handsontable.Core(this.container.nativeElement, options);
1090
+ this.hotInstance._angularEnvironmentInjector = this.environmentInjector;
1091
+ this.hotInstance.addHook("beforeHeightChange", (height) => {
1092
+ this.toggleFillHeight(height);
1093
+ return height;
1094
+ });
1095
+ this.hotInstance.init();
1096
+ });
1097
+ this._hotConfig.config$.pipe(skip(1), takeUntilDestroyed(this._destroyRef)).subscribe((config) => {
1098
+ if (this.hotInstance) {
1099
+ const negotiatedSettings = this.getNegotiatedSettings(this.settings);
1100
+ this.updateHotTable(negotiatedSettings);
1101
+ }
1102
+ });
1103
+ }
1104
+ ngOnChanges(changes) {
1105
+ if (this.hotInstance === null) return;
1106
+ if (changes.settings && !changes.settings.firstChange) {
1107
+ const prevColumns = this.__hotInstance?.getSettings().columns;
1108
+ const prevColumnsArray = Array.isArray(prevColumns) ? prevColumns : void 0;
1109
+ const newOptions = this._hotSettingsResolver.applyCustomSettings(changes.settings.currentValue, prevColumnsArray);
1110
+ this.updateHotTable(newOptions);
1111
+ if (prevColumnsArray && Array.isArray(newOptions.columns)) {
1112
+ const reusedRefs = new Set(newOptions.columns.map((column) => column._editorComponentReference).filter((ref) => !!ref));
1113
+ prevColumnsArray.forEach((column) => {
1114
+ if (column._editorComponentReference && !reusedRefs.has(column._editorComponentReference)) column._editorComponentReference.destroy();
1115
+ });
1116
+ }
1117
+ }
1118
+ if (changes.data && !changes.data.firstChange) this.hotInstance?.updateData(changes.data.currentValue);
1119
+ }
1120
+ ngOnDestroy() {
1121
+ this.ngZone.runOutsideAngular(() => {
1122
+ if (!this.__hotInstance || this.__hotInstance.isDestroyed) return;
1123
+ if (this.container) this._dynamicComponentService.cleanupContainer(this.container.nativeElement, this.__hotInstance);
1124
+ const columns = this.__hotInstance.getSettings().columns;
1125
+ if (columns && Array.isArray(columns)) columns.forEach((column) => {
1126
+ if (column._editorComponentReference) column._editorComponentReference.destroy();
1127
+ });
1128
+ this.__hotInstance.destroy();
1129
+ });
1130
+ }
1131
+ toggleFillHeight(height) {
1132
+ const fillHeight = typeof height === "string" && RELATIVE_HEIGHT_PATTERN.test(height);
1133
+ this.container.nativeElement.classList.toggle(FILL_HEIGHT_CLASS_NAME, fillHeight);
1134
+ this._host.nativeElement.classList.toggle(FILL_HEIGHT_CLASS_NAME, fillHeight);
1135
+ }
1136
+ updateHotTable(newSettings) {
1137
+ if (!this.hotInstance) return;
1138
+ const currentSettings = this.hotInstance.getSettings();
1139
+ const initOnlySettingKeys = new Set(currentSettings?._initOnlySettings ?? []);
1140
+ const filteredSettings = {};
1141
+ for (const key of Object.keys(newSettings)) {
1142
+ if (initOnlySettingKeys.has(key)) continue;
1143
+ if (SIZE_SETTING_KEYS.has(key) && isSameSizeSetting(currentSettings?.[key], newSettings[key])) continue;
1144
+ filteredSettings[key] = newSettings[key];
1145
+ }
1146
+ this.ngZone.runOutsideAngular(() => {
1147
+ this.hotInstance?.updateSettings(filteredSettings, false);
1148
+ });
1149
+ }
1150
+ getNegotiatedSettings(settings) {
1151
+ const hotConfig = this._hotConfig.getConfig();
1152
+ const negotiatedSettings = {};
1153
+ negotiatedSettings.licenseKey = settings.licenseKey ?? hotConfig.license;
1154
+ negotiatedSettings.language = settings.language ?? hotConfig.language;
1155
+ const theme = settings.theme ?? hotConfig.theme;
1156
+ const themeName = settings.themeName ?? hotConfig.themeName;
1157
+ if (theme !== void 0) negotiatedSettings.theme = theme;
1158
+ else if (themeName) negotiatedSettings.themeName = themeName;
1159
+ if (!this.__hotInstance) negotiatedSettings.layoutDirection = settings.layoutDirection ?? hotConfig.layoutDirection;
1160
+ return negotiatedSettings;
1161
+ }
1162
+ static ɵfac = i0.ɵɵngDeclareFactory({
1163
+ minVersion: "12.0.0",
1164
+ version: "22.2.2",
1165
+ ngImport: i0,
1166
+ type: HotTableComponent,
1167
+ deps: [
1168
+ { token: HotSettingsResolver },
1169
+ { token: HotGlobalConfigService },
1170
+ { token: i0.NgZone },
1171
+ { token: i0.EnvironmentInjector },
1172
+ { token: DynamicComponentService }
1173
+ ],
1174
+ target: i0.ɵɵFactoryTarget.Component
1175
+ });
1176
+ static ɵcmp = i0.ɵɵngDeclareComponent({
1177
+ minVersion: "14.0.0",
1178
+ version: "22.2.2",
1179
+ type: HotTableComponent,
1180
+ isStandalone: true,
1181
+ selector: "hot-table",
1182
+ inputs: {
1183
+ data: "data",
1184
+ settings: "settings"
1185
+ },
1186
+ providers: [HotSettingsResolver],
1187
+ viewQueries: [{
1188
+ propertyName: "container",
1189
+ first: true,
1190
+ predicate: ["container"],
1191
+ descendants: true
1192
+ }],
1193
+ usesOnChanges: true,
1194
+ ngImport: i0,
1195
+ template: "<div #container></div>",
1196
+ isInline: true,
1197
+ styles: [":host{display:block}:where(hot-table.ht-fill-height,hot-table>div.ht-fill-height){height:100%}\n"],
1198
+ encapsulation: i0.ViewEncapsulation.None
1199
+ });
1200
+ };
1201
+ i0.ɵɵngDeclareClassMetadata({
1202
+ minVersion: "12.0.0",
1203
+ version: "22.2.2",
1204
+ ngImport: i0,
1205
+ type: HotTableComponent,
1206
+ decorators: [{
1207
+ type: Component,
1208
+ args: [{
1209
+ selector: "hot-table",
1210
+ template: "<div #container></div>",
1211
+ encapsulation: ViewEncapsulation.None,
1212
+ providers: [HotSettingsResolver],
1213
+ styles: [":host{display:block}:where(hot-table.ht-fill-height,hot-table>div.ht-fill-height){height:100%}\n"]
1214
+ }]
1215
+ }],
1216
+ ctorParameters: () => [
1217
+ { type: HotSettingsResolver },
1218
+ { type: HotGlobalConfigService },
1219
+ { type: i0.NgZone },
1220
+ { type: i0.EnvironmentInjector },
1221
+ { type: DynamicComponentService }
1222
+ ],
1223
+ propDecorators: {
1224
+ data: [{ type: Input }],
1225
+ settings: [{ type: Input }],
1226
+ container: [{
1227
+ type: ViewChild,
1228
+ args: ["container", { static: false }]
1229
+ }]
1230
+ }
1231
+ });
1232
+ var HotTableModule = class HotTableModule {
1233
+ static version = "0.0.0-next-a26137c-20261014";
1234
+ static ɵfac = i0.ɵɵngDeclareFactory({
1235
+ minVersion: "12.0.0",
1236
+ version: "22.2.2",
1237
+ ngImport: i0,
1238
+ type: HotTableModule,
1239
+ deps: [],
1240
+ target: i0.ɵɵFactoryTarget.NgModule
1241
+ });
1242
+ static ɵmod = i0.ɵɵngDeclareNgModule({
1243
+ minVersion: "14.0.0",
1244
+ version: "22.2.2",
1245
+ ngImport: i0,
1246
+ type: HotTableModule,
1247
+ imports: [HotTableComponent],
1248
+ exports: [HotTableComponent]
1249
+ });
1250
+ static ɵinj = i0.ɵɵngDeclareInjector({
1251
+ minVersion: "12.0.0",
1252
+ version: "22.2.2",
1253
+ ngImport: i0,
1254
+ type: HotTableModule
1255
+ });
1256
+ };
1257
+ i0.ɵɵngDeclareClassMetadata({
1258
+ minVersion: "12.0.0",
1259
+ version: "22.2.2",
1260
+ ngImport: i0,
1261
+ type: HotTableModule,
1262
+ decorators: [{
1263
+ type: NgModule,
1264
+ args: [{
1265
+ imports: [HotTableComponent],
1266
+ exports: [HotTableComponent]
1267
+ }]
1268
+ }]
1269
+ });
1628
1270
  export { DynamicComponentService, HOT_DESTROYED_WARNING, HOT_GLOBAL_CONFIG, HotCellEditorAdvancedComponent, HotCellEditorComponent, HotCellRendererAdvancedComponent, HotCellRendererComponent, HotGlobalConfigService, HotSettingsResolver, HotTableComponent, HotTableModule, INVALID_ADVANCED_RENDERER_WARNING, INVALID_RENDERER_WARNING, NON_COMMERCIAL_LICENSE, PredefinedTheme, isAdvancedHotCellRendererComponent, isHotCellRendererComponent, isTemplateRef };
1629
- //# sourceMappingURL=handsontable-angular-wrapper.mjs.map
1271
+
1272
+ //# sourceMappingURL=handsontable-angular-wrapper.mjs.map