slickgrid-vue 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/dist/components/SlickgridVue.vue.d.ts +44 -0
  2. package/dist/components/slickgridVueProps.interface.d.ts +274 -0
  3. package/dist/constants.d.ts +23 -0
  4. package/dist/extensions/slickRowDetailView.d.ts +81 -0
  5. package/dist/global-grid-options.d.ts +5 -0
  6. package/dist/index.cjs +2 -0
  7. package/dist/index.cjs.map +1 -0
  8. package/dist/index.d.cts +12 -0
  9. package/dist/index.d.ts +12 -0
  10. package/dist/index.mjs +1286 -0
  11. package/dist/index.mjs.map +1 -0
  12. package/dist/models/gridOption.interface.d.ts +12 -0
  13. package/dist/models/index.d.ts +5 -0
  14. package/dist/models/rowDetailView.interface.d.ts +13 -0
  15. package/dist/models/viewModelBindableData.interface.d.ts +9 -0
  16. package/dist/models/viewModelBindableInputData.interface.d.ts +8 -0
  17. package/dist/models/vueGridInstance.interface.d.ts +39 -0
  18. package/dist/services/container.service.d.ts +6 -0
  19. package/dist/services/index.d.ts +3 -0
  20. package/dist/services/translater.service.d.ts +27 -0
  21. package/dist/services/utilities.d.ts +7 -0
  22. package/dist/services/vueUtils.d.ts +16 -0
  23. package/dist/slickgrid-config.d.ts +5 -0
  24. package/package.json +75 -0
  25. package/src/assets/vue.svg +1 -0
  26. package/src/components/SlickgridVue.vue +1638 -0
  27. package/src/components/slickgridVueProps.interface.ts +150 -0
  28. package/src/constants.ts +95 -0
  29. package/src/extensions/slickRowDetailView.ts +416 -0
  30. package/src/global-grid-options.ts +288 -0
  31. package/src/index.ts +34 -0
  32. package/src/models/gridOption.interface.ts +16 -0
  33. package/src/models/index.ts +5 -0
  34. package/src/models/rowDetailView.interface.ts +16 -0
  35. package/src/models/viewModelBindableData.interface.ts +10 -0
  36. package/src/models/viewModelBindableInputData.interface.ts +9 -0
  37. package/src/models/vueGridInstance.interface.ts +77 -0
  38. package/src/services/container.service.ts +13 -0
  39. package/src/services/index.ts +3 -0
  40. package/src/services/translater.service.ts +41 -0
  41. package/src/services/utilities.ts +18 -0
  42. package/src/services/vueUtils.ts +26 -0
  43. package/src/slickgrid-config.ts +10 -0
  44. package/src/vite-env.d.ts +1 -0
@@ -0,0 +1,150 @@
1
+ import type {
2
+ DragRowMove,
3
+ ExtensionList,
4
+ OnActiveCellChangedEventArgs,
5
+ OnAddNewRowEventArgs,
6
+ OnAutosizeColumnsEventArgs,
7
+ OnBeforeAppendCellEventArgs,
8
+ OnBeforeCellEditorDestroyEventArgs,
9
+ OnBeforeColumnsResizeEventArgs,
10
+ OnBeforeEditCellEventArgs,
11
+ OnBeforeFooterRowCellDestroyEventArgs,
12
+ OnBeforeHeaderCellDestroyEventArgs,
13
+ OnBeforeHeaderRowCellDestroyEventArgs,
14
+ OnBeforeSetColumnsEventArgs,
15
+ OnCellChangeEventArgs,
16
+ OnCellCssStylesChangedEventArgs,
17
+ OnClickEventArgs,
18
+ OnColumnsDragEventArgs,
19
+ OnColumnsReorderedEventArgs,
20
+ OnColumnsResizeDblClickEventArgs,
21
+ OnColumnsResizedEventArgs,
22
+ OnCompositeEditorChangeEventArgs,
23
+ OnDblClickEventArgs,
24
+ OnFooterClickEventArgs,
25
+ OnFooterContextMenuEventArgs,
26
+ OnFooterRowCellRenderedEventArgs,
27
+ OnGroupCollapsedEventArgs,
28
+ OnGroupExpandedEventArgs,
29
+ OnHeaderCellRenderedEventArgs,
30
+ OnHeaderClickEventArgs,
31
+ OnHeaderContextMenuEventArgs,
32
+ OnHeaderMouseEventArgs,
33
+ OnHeaderRowCellRenderedEventArgs,
34
+ OnKeyDownEventArgs,
35
+ OnRenderedEventArgs,
36
+ OnRowCountChangedEventArgs,
37
+ OnRowsChangedEventArgs,
38
+ OnRowsOrCountChangedEventArgs,
39
+ OnScrollEventArgs,
40
+ OnSelectedRowsChangedEventArgs,
41
+ OnSetItemsCalledEventArgs,
42
+ OnSetOptionsEventArgs,
43
+ OnValidationErrorEventArgs,
44
+ PaginationChangedArgs,
45
+ PagingInfo,
46
+ SingleColumnSort,
47
+ SlickControlList,
48
+ SlickGrid,
49
+ SlickPluginList,
50
+ } from '@slickgrid-universal/common';
51
+ import type { Slot } from 'vue';
52
+
53
+ import type { SlickgridVueInstance } from '../models/index.js';
54
+
55
+ export interface SlickgridVueProps {
56
+ header?: Slot;
57
+ footer?: Slot;
58
+ extensions?: ExtensionList<SlickControlList | SlickPluginList>;
59
+ gridId: string;
60
+ instances?: SlickgridVueInstance;
61
+
62
+ // Custom Events list
63
+ // ---------------------
64
+ // NOTE: we need to add an extra "onOn" prefix to all events because of how VueJS handles events
65
+ // for example onOnClick can actually be used as "@onClick" event
66
+
67
+ // Slick Grid events
68
+ onOnActiveCellChanged?: (e: CustomEvent<{ eventData: any; args: OnActiveCellChangedEventArgs; }>) => void;
69
+ onOnActiveCellPositionChanged?: (e: CustomEvent<{ eventData: any; args: { grid: SlickGrid; }; }>) => void;
70
+ onOnAddNewRow?: (e: CustomEvent<{ eventData: any; args: OnAddNewRowEventArgs; }>) => void;
71
+ onOnAutosizeColumns?: (e: CustomEvent<{ eventData: any; args: OnAutosizeColumnsEventArgs; }>) => void;
72
+ onOnBeforeAppendCell?: (e: CustomEvent<{ eventData: any; args: OnBeforeAppendCellEventArgs; }>) => void;
73
+ onOnBeforeSearchChange?: (e: CustomEvent<{ eventData: any; args: OnCellChangeEventArgs; }>) => void;
74
+ onOnBeforeCellEditorDestroy?: (e: CustomEvent<{ eventData: any; args: OnBeforeCellEditorDestroyEventArgs; }>) => void;
75
+ onOnBeforeColumnsResize?: (e: CustomEvent<{ eventData: any; args: OnBeforeColumnsResizeEventArgs; }>) => void;
76
+ onOnBeforeDestroy?: (e: CustomEvent<{ eventData: any; args: { grid: SlickGrid; }; }>) => void;
77
+ onOnBeforeEditCell?: (e: CustomEvent<{ eventData: any; args: OnBeforeEditCellEventArgs; }>) => void;
78
+ onOnBeforeHeaderCellDestroy?: (e: CustomEvent<{ eventData: any; args: OnBeforeHeaderCellDestroyEventArgs; }>) => void;
79
+ onOnBeforeHeaderRowCellDestroy?: (e: CustomEvent<{ eventData: any; args: OnBeforeHeaderRowCellDestroyEventArgs; }>) => void;
80
+ onOnBeforeFooterRowCellDestroy?: (e: CustomEvent<{ eventData: any; args: OnBeforeFooterRowCellDestroyEventArgs; }>) => void;
81
+ onOnBeforeSetColumns?: (e: CustomEvent<{ eventData: any; args: OnBeforeSetColumnsEventArgs; }>) => void;
82
+ onOnBeforeSort?: (e: CustomEvent<{ eventData: any; args: SingleColumnSort; }>) => void;
83
+ onOnCellChange?: (e: CustomEvent<{ eventData: any; args: OnCellChangeEventArgs; }>) => void;
84
+ onOnCellCssStylesChanged?: (e: CustomEvent<{ eventData: any; args: OnCellCssStylesChangedEventArgs; }>) => void;
85
+ onOnClick?: (e: CustomEvent<{ eventData: any; args: OnClickEventArgs; }>) => void;
86
+ onOnColumnsDrag?: (e: CustomEvent<{ eventData: any; args: OnColumnsDragEventArgs; }>) => void;
87
+ onOnColumnsReordered?: (e: CustomEvent<{ eventData: any; args: OnColumnsReorderedEventArgs; }>) => void;
88
+ onOnColumnsResized?: (e: CustomEvent<{ eventData: any; args: OnColumnsResizedEventArgs; }>) => void;
89
+ onOnColumnsResizeDblClick?: (e: CustomEvent<{ eventData: any; args: OnColumnsResizeDblClickEventArgs; }>) => void;
90
+ onOnCompositeEditorChange?: (e: CustomEvent<{ eventData: any; args: OnCompositeEditorChangeEventArgs; }>) => void;
91
+ onOnContextMenu?: (e: CustomEvent<{ eventData: any; args: { grid: SlickGrid; }; }>) => void;
92
+ onOnDrag?: (e: CustomEvent<{ eventData: any; args: DragRowMove; }>) => void;
93
+ onOnDragEnd?: (e: CustomEvent<{ eventData: any; args: DragRowMove; }>) => void;
94
+ onOnDragInit?: (e: CustomEvent<{ eventData: any; args: DragRowMove; }>) => void;
95
+ onOnDragStart?: (e: CustomEvent<{ eventData: any; args: DragRowMove; }>) => void;
96
+ onOnDblClick?: (e: CustomEvent<{ eventData: any; args: OnDblClickEventArgs; }>) => void;
97
+ onOnFooterContextMenu?: (e: CustomEvent<{ eventData: any; args: OnFooterContextMenuEventArgs; }>) => void;
98
+ onOnFooterRowCellRendered?: (e: CustomEvent<{ eventData: any; args: OnFooterRowCellRenderedEventArgs; }>) => void;
99
+ onOnHeaderCellRendered?: (e: CustomEvent<{ eventData: any; args: OnHeaderCellRenderedEventArgs; }>) => void;
100
+ onOnFooterClick?: (e: CustomEvent<{ eventData: any; args: OnFooterClickEventArgs; }>) => void;
101
+ onOnHeaderClick?: (e: CustomEvent<{ eventData: any; args: OnHeaderClickEventArgs; }>) => void;
102
+ onOnHeaderContextMenu?: (e: CustomEvent<{ eventData: any; args: OnHeaderContextMenuEventArgs; }>) => void;
103
+ onOnHeaderMouseEnter?: (e: CustomEvent<{ eventData: any; args: OnHeaderMouseEventArgs; }>) => void;
104
+ onOnHeaderMouseLeave?: (e: CustomEvent<{ eventData: any; args: OnHeaderMouseEventArgs; }>) => void;
105
+ onOnHeaderRowCellRendered?: (e: CustomEvent<{ eventData: any; args: OnHeaderRowCellRenderedEventArgs; }>) => void;
106
+ onOnHeaderRowMouseEnter?: (e: CustomEvent<{ eventData: any; args: OnHeaderMouseEventArgs; }>) => void;
107
+ onOnHeaderRowMouseLeave?: (e: CustomEvent<{ eventData: any; args: OnHeaderMouseEventArgs; }>) => void;
108
+ onOnKeyDown?: (e: CustomEvent<{ eventData: any; args: OnKeyDownEventArgs; }>) => void;
109
+ onOnMouseEnter?: (e: CustomEvent<{ eventData: any; args: { grid: SlickGrid; }; }>) => void;
110
+ onOnMouseLeave?: (e: CustomEvent<{ eventData: any; args: { grid: SlickGrid; }; }>) => void;
111
+ onOnValidationError?: (e: CustomEvent<{ eventData: any; args: OnValidationErrorEventArgs; }>) => void;
112
+ onOnViewportChanged?: (e: CustomEvent<{ eventData: any; args: { grid: SlickGrid; }; }>) => void;
113
+ onOnRendered?: (e: CustomEvent<{ eventData: any; args: OnRenderedEventArgs; }>) => void;
114
+ onOnSelectedRowsChanged?: (e: CustomEvent<{ eventData: any; args: OnSelectedRowsChangedEventArgs; }>) => void;
115
+ onOnSetOptions?: (e: CustomEvent<{ eventData: any; args: OnSetOptionsEventArgs; }>) => void;
116
+ onOnScroll?: (e: CustomEvent<{ eventData: any; args: OnScrollEventArgs; }>) => void;
117
+ onOnSort?: (e: CustomEvent<{ eventData: any; args: SingleColumnSort; }>) => void;
118
+
119
+ // Slick DataView events
120
+ onOnBeforePagingInfoChanged?: (e: CustomEvent<{ eventData: any; args: PagingInfo; }>) => void;
121
+ onOnGroupExpanded?: (e: CustomEvent<{ eventData: any; args: OnGroupExpandedEventArgs; }>) => void;
122
+ onOnGroupCollapsed?: (e: CustomEvent<{ eventData: any; args: OnGroupCollapsedEventArgs; }>) => void;
123
+ onOnPagingInfoChanged?: (e: CustomEvent<{ eventData: any; args: PagingInfo; }>) => void;
124
+ onOnRowCountChanged?: (e: CustomEvent<{ eventData: any; args: OnRowCountChangedEventArgs; }>) => void;
125
+ onOnRowsChanged?: (e: CustomEvent<{ eventData: any; args: OnRowsChangedEventArgs; }>) => void;
126
+ onOnRowsOrCountChanged?: (e: CustomEvent<{ eventData: any; args: OnRowsOrCountChangedEventArgs; }>) => void;
127
+ onOnSetItemsCalled?: (e: CustomEvent<{ eventData: any; args: OnSetItemsCalledEventArgs; }>) => void;
128
+
129
+ // Slickgrid-Vue events
130
+ onOnAfterExportToExcel?: (e: CustomEvent<any>) => void;
131
+ onOnBeforePaginationChange?: (e: CustomEvent<any>) => void;
132
+ onOnBeforeExportToExcel?: (e: CustomEvent<any>) => void;
133
+ onOnBeforeFilterChange?: (e: CustomEvent<any>) => void;
134
+ onOnBeforeFilterClear?: (e: CustomEvent<any>) => void;
135
+ onOnBeforeSortChange?: (e: CustomEvent<any>) => void;
136
+ onOnBeforeToggleTreeCollapse?: (e: CustomEvent<any>) => void;
137
+ onOnFilterChanged?: (e: CustomEvent<any>) => void;
138
+ onOnFilterCleared?: (e: CustomEvent<any>) => void;
139
+ onOnItemDeleted?: (e: CustomEvent<any>) => void;
140
+ onOnGridStateChanged?: (e: CustomEvent<any>) => void;
141
+ onOnPaginationChanged?: (e: CustomEvent<PaginationChangedArgs>) => void;
142
+ onOnReactGridCreated?: (e: CustomEvent<any>) => void;
143
+ onOnSelectedRowIdsChanged?: (e: CustomEvent<any>) => void;
144
+ onOnSortChanged?: (e: CustomEvent<any>) => void;
145
+ onOnToggleTreeCollapsed?: (e: CustomEvent<any>) => void;
146
+ onOnTreeItemToggled?: (e: CustomEvent<any>) => void;
147
+ onOnTreeFullToggleEnd?: (e: CustomEvent<any>) => void;
148
+ onOnTreeFullToggleStart?: (e: CustomEvent<any>) => void;
149
+ onVueGridCreated?: (e: CustomEvent<SlickgridVueInstance>) => void;
150
+ }
@@ -0,0 +1,95 @@
1
+ import type { Locale } from '@slickgrid-universal/common';
2
+
3
+ export class Constants {
4
+ // English Locale texts when using only 1 Locale instead of I18N
5
+ static readonly locales: Locale = {
6
+ TEXT_ALL_SELECTED: 'All Selected',
7
+ TEXT_ALL_X_RECORDS_SELECTED: 'All {{x}} records selected',
8
+ TEXT_APPLY_MASS_UPDATE: 'Apply Mass Update',
9
+ TEXT_APPLY_TO_SELECTION: 'Update Selection',
10
+ TEXT_CANCEL: 'Cancel',
11
+ TEXT_CLEAR_ALL_FILTERS: 'Clear all Filters',
12
+ TEXT_CLEAR_ALL_GROUPING: 'Clear all Grouping',
13
+ TEXT_CLEAR_ALL_SORTING: 'Clear all Sorting',
14
+ TEXT_CLEAR_PINNING: 'Unfreeze Columns/Rows',
15
+ TEXT_CLONE: 'Clone',
16
+ TEXT_COLLAPSE_ALL_GROUPS: 'Collapse all Groups',
17
+ TEXT_CONTAINS: 'Contains',
18
+ TEXT_COLUMNS: 'Columns',
19
+ TEXT_COLUMN_RESIZE_BY_CONTENT: 'Resize by Content',
20
+ TEXT_COMMANDS: 'Commands',
21
+ TEXT_COPY: 'Copy',
22
+ TEXT_EQUALS: 'Equals',
23
+ TEXT_EQUAL_TO: 'Equal to',
24
+ TEXT_ENDS_WITH: 'Ends With',
25
+ TEXT_ERROR_EDITABLE_GRID_REQUIRED: 'Your grid must be editable in order to use the Composite Editor Modal.',
26
+ TEXT_ERROR_ENABLE_CELL_NAVIGATION_REQUIRED:
27
+ 'Composite Editor requires the flag "enableCellNavigation" to be set to True in your Grid Options.',
28
+ TEXT_ERROR_NO_CHANGES_DETECTED: 'Sorry we could not detect any changes.',
29
+ TEXT_ERROR_NO_EDITOR_FOUND: 'We could not find any Editor in your Column Definition.',
30
+ TEXT_ERROR_NO_RECORD_FOUND: 'No records selected for edit or clone operation.',
31
+ TEXT_ERROR_ROW_NOT_EDITABLE: 'Current row is not editable.',
32
+ TEXT_ERROR_ROW_SELECTION_REQUIRED: 'You must select some rows before trying to apply new value(s).',
33
+ TEXT_EXPAND_ALL_GROUPS: 'Expand all Groups',
34
+ TEXT_EXPORT_TO_CSV: 'Export in CSV format',
35
+ TEXT_EXPORT_TO_TEXT_FORMAT: 'Export in Text format (Tab delimited)',
36
+ TEXT_EXPORT_TO_EXCEL: 'Export to Excel',
37
+ TEXT_EXPORT_TO_TAB_DELIMITED: 'Export in Text format (Tab delimited)',
38
+ TEXT_FORCE_FIT_COLUMNS: 'Force fit columns',
39
+ TEXT_FREEZE_COLUMNS: 'Freeze Columns',
40
+ TEXT_GREATER_THAN: 'Greater than',
41
+ TEXT_GREATER_THAN_OR_EQUAL_TO: 'Greater than or equal to',
42
+ TEXT_GROUP_BY: 'Group By',
43
+ TEXT_HIDE_COLUMN: 'Hide Column',
44
+ TEXT_ITEMS: 'items',
45
+ TEXT_ITEMS_PER_PAGE: 'items per page',
46
+ TEXT_ITEMS_SELECTED: 'items selected',
47
+ TEXT_OF: 'of',
48
+ TEXT_OK: 'OK',
49
+ TEXT_LAST_UPDATE: 'Last Update',
50
+ TEXT_LESS_THAN: 'Less than',
51
+ TEXT_LESS_THAN_OR_EQUAL_TO: 'Less than or equal to',
52
+ TEXT_NO_ELEMENTS_FOUND: 'Aucun élément trouvé',
53
+ TEXT_NOT_CONTAINS: 'Not contains',
54
+ TEXT_NOT_EQUAL_TO: 'Not equal to',
55
+ TEXT_PAGE: 'Page',
56
+ TEXT_REFRESH_DATASET: 'Refresh Dataset',
57
+ TEXT_REMOVE_FILTER: 'Remove Filter',
58
+ TEXT_REMOVE_SORT: 'Remove Sort',
59
+ TEXT_SAVE: 'Save',
60
+ TEXT_SELECT_ALL: 'Select All',
61
+ TEXT_SYNCHRONOUS_RESIZE: 'Synchronous resize',
62
+ TEXT_SORT_ASCENDING: 'Sort Ascending',
63
+ TEXT_SORT_DESCENDING: 'Sort Descending',
64
+ TEXT_STARTS_WITH: 'Starts With',
65
+ TEXT_TOGGLE_DARK_MODE: 'Toggle Dark Mode',
66
+ TEXT_TOGGLE_FILTER_ROW: 'Toggle Filter Row',
67
+ TEXT_TOGGLE_PRE_HEADER_ROW: 'Toggle Pre-Header Row',
68
+ TEXT_X_OF_Y_SELECTED: '# of % selected',
69
+ TEXT_X_OF_Y_MASS_SELECTED: '{{x}} of {{y}} selected',
70
+ };
71
+
72
+ static readonly VALIDATION_REQUIRED_FIELD = 'Field is required';
73
+ static readonly VALIDATION_EDITOR_VALID_NUMBER = 'Please enter a valid number';
74
+ static readonly VALIDATION_EDITOR_VALID_INTEGER = 'Please enter a valid integer number';
75
+ static readonly VALIDATION_EDITOR_INTEGER_BETWEEN = 'Please enter a valid integer number between {{minValue}} and {{maxValue}}';
76
+ static readonly VALIDATION_EDITOR_INTEGER_MAX = 'Please enter a valid integer number that is lower than {{maxValue}}';
77
+ static readonly VALIDATION_EDITOR_INTEGER_MAX_INCLUSIVE =
78
+ 'Please enter a valid integer number that is lower than or equal to {{maxValue}}';
79
+ static readonly VALIDATION_EDITOR_INTEGER_MIN = 'Please enter a valid integer number that is greater than {{minValue}}';
80
+ static readonly VALIDATION_EDITOR_INTEGER_MIN_INCLUSIVE =
81
+ 'Please enter a valid integer number that is greater than or equal to {{minValue}}';
82
+ static readonly VALIDATION_EDITOR_NUMBER_BETWEEN = 'Please enter a valid number between {{minValue}} and {{maxValue}}';
83
+ static readonly VALIDATION_EDITOR_NUMBER_MAX = 'Please enter a valid number that is lower than {{maxValue}}';
84
+ static readonly VALIDATION_EDITOR_NUMBER_MAX_INCLUSIVE = 'Please enter a valid number that is lower than or equal to {{maxValue}}';
85
+ static readonly VALIDATION_EDITOR_NUMBER_MIN = 'Please enter a valid number that is greater than {{minValue}}';
86
+ static readonly VALIDATION_EDITOR_NUMBER_MIN_INCLUSIVE = 'Please enter a valid number that is greater than or equal to {{minValue}}';
87
+ static readonly VALIDATION_EDITOR_DECIMAL_BETWEEN = 'Please enter a valid number with a maximum of {{maxDecimal}} decimals';
88
+ static readonly VALIDATION_EDITOR_TEXT_LENGTH_BETWEEN =
89
+ 'Please make sure your text length is between {{minLength}} and {{maxLength}} characters';
90
+ static readonly VALIDATION_EDITOR_TEXT_MAX_LENGTH = 'Please make sure your text is less than {{maxLength}} characters';
91
+ static readonly VALIDATION_EDITOR_TEXT_MAX_LENGTH_INCLUSIVE =
92
+ 'Please make sure your text is less than or equal to {{maxLength}} characters';
93
+ static readonly VALIDATION_EDITOR_TEXT_MIN_LENGTH = 'Please make sure your text is more than {{minLength}} character(s)';
94
+ static readonly VALIDATION_EDITOR_TEXT_MIN_LENGTH_INCLUSIVE = 'Please make sure your text is at least {{minLength}} character(s)';
95
+ }
@@ -0,0 +1,416 @@
1
+ import {
2
+ addToArrayWhenNotExists,
3
+ type EventSubscription,
4
+ type OnBeforeRowDetailToggleArgs,
5
+ type OnRowBackToViewportRangeArgs,
6
+ SlickEventData,
7
+ type SlickEventHandler,
8
+ type SlickGrid,
9
+ SlickRowSelectionModel,
10
+ unsubscribeAll,
11
+ } from '@slickgrid-universal/common';
12
+ import { type EventPubSubService } from '@slickgrid-universal/event-pub-sub';
13
+ import { SlickRowDetailView as UniversalSlickRowDetailView } from '@slickgrid-universal/row-detail-view-plugin';
14
+ import { type App, type ComponentPublicInstance, createApp } from 'vue';
15
+
16
+ import type { GridOption, RowDetailView, ViewModelBindableInputData } from '../models/index.js';
17
+
18
+ const ROW_DETAIL_CONTAINER_PREFIX = 'container_';
19
+ const PRELOAD_CONTAINER_PREFIX = 'container_loading';
20
+
21
+ type AppData = Record<string, unknown>;
22
+ export interface CreatedView {
23
+ id: string | number;
24
+ dataContext: any;
25
+ app: App | null;
26
+ instance: ComponentPublicInstance | null;
27
+ }
28
+ // interface SRDV extends React.Component<Props, State>, UniversalSlickRowDetailView {}s
29
+
30
+ export class SlickRowDetailView extends UniversalSlickRowDetailView {
31
+ protected _component?: any;
32
+ protected _preloadComponent?: any;
33
+ protected _views: CreatedView[] = [];
34
+ protected _subscriptions: EventSubscription[] = [];
35
+ protected _userProcessFn?: (item: any) => Promise<any>;
36
+ protected gridContainerElement!: HTMLElement;
37
+
38
+ constructor(private readonly eventPubSubService: EventPubSubService) {
39
+ super(eventPubSubService);
40
+ }
41
+
42
+ get addonOptions() {
43
+ return this.getOptions();
44
+ }
45
+
46
+ protected get datasetIdPropName(): string {
47
+ return this.gridOptions.datasetIdPropertyName || 'id';
48
+ }
49
+
50
+ get eventHandler(): SlickEventHandler {
51
+ return this._eventHandler;
52
+ }
53
+ set eventHandler(eventHandler: SlickEventHandler) {
54
+ this._eventHandler = eventHandler;
55
+ }
56
+
57
+ get gridOptions(): GridOption {
58
+ return (this._grid?.getOptions() || {}) as GridOption;
59
+ }
60
+
61
+ get rowDetailViewOptions(): RowDetailView | undefined {
62
+ return this.gridOptions.rowDetailView;
63
+ }
64
+
65
+ /** Dispose of the RowDetailView Extension */
66
+ dispose() {
67
+ this.disposeAllViewComponents();
68
+ unsubscribeAll(this._subscriptions);
69
+ super.dispose();
70
+ }
71
+
72
+ /** Dispose of all the opened Row Detail Panels Components */
73
+ disposeAllViewComponents() {
74
+ if (Array.isArray(this._views)) {
75
+ this._views.forEach((view) => this.disposeViewComponent(view));
76
+ }
77
+ this._views = [];
78
+ }
79
+
80
+ /** Get the instance of the SlickGrid addon (control or plugin). */
81
+ getAddonInstance(): SlickRowDetailView | null {
82
+ return this;
83
+ }
84
+
85
+ init(grid: SlickGrid) {
86
+ this._grid = grid;
87
+ super.init(this._grid);
88
+ this.gridContainerElement = grid.getContainerNode();
89
+ this.register(grid?.getSelectionModel() as SlickRowSelectionModel);
90
+ }
91
+
92
+ /**
93
+ * Create the plugin before the Grid creation, else it will behave oddly.
94
+ * Mostly because the column definitions might change after the grid creation
95
+ */
96
+ register(rowSelectionPlugin?: SlickRowSelectionModel) {
97
+ if (typeof this.gridOptions.rowDetailView?.process === 'function') {
98
+ // we need to keep the user "process" method and replace it with our own execution method
99
+ // we do this because when we get the item detail, we need to call "onAsyncResponse.notify" for the plugin to work
100
+ this._userProcessFn = this.gridOptions.rowDetailView.process as (item: any) => Promise<any>; // keep user's process method
101
+ this.addonOptions.process = (item) => this.onProcessing(item); // replace process method & run our internal one
102
+ } else {
103
+ throw new Error('[Slickgrid-React] You need to provide a "process" function for the Row Detail Extension to work properly');
104
+ }
105
+
106
+ if (this._grid && this.gridOptions?.rowDetailView) {
107
+ // load the Preload & RowDetail Templates (could be straight HTML or React Components)
108
+ // when those are React Components, we need to create View Component & provide the html containers to the Plugin (preTemplate/postTemplate methods)
109
+ if (!this.gridOptions.rowDetailView.preTemplate) {
110
+ this._preloadComponent = this.gridOptions?.rowDetailView?.preloadComponent;
111
+ this.addonOptions.preTemplate = () => this._grid.sanitizeHtmlString(`<div class="${PRELOAD_CONTAINER_PREFIX}"></div>`) as string;
112
+ }
113
+ if (!this.gridOptions.rowDetailView.postTemplate) {
114
+ this._component = this.gridOptions?.rowDetailView?.viewComponent;
115
+ this.addonOptions.postTemplate = (itemDetail: any) => {
116
+ return this._grid.sanitizeHtmlString(
117
+ `<div class="${ROW_DETAIL_CONTAINER_PREFIX}${itemDetail[this.datasetIdPropName]}"></div>`
118
+ ) as string;
119
+ };
120
+ }
121
+
122
+ if (this._grid && this.gridOptions) {
123
+ // this also requires the Row Selection Model to be registered as well
124
+ if (!rowSelectionPlugin || !this._grid.getSelectionModel()) {
125
+ rowSelectionPlugin = new SlickRowSelectionModel(this.gridOptions.rowSelectionOptions || { selectActiveRow: true });
126
+ this._grid.setSelectionModel(rowSelectionPlugin);
127
+ }
128
+
129
+ // hook all events
130
+ if (this._grid && this.rowDetailViewOptions) {
131
+ if (this.rowDetailViewOptions.onExtensionRegistered) {
132
+ this.rowDetailViewOptions.onExtensionRegistered(this);
133
+ }
134
+
135
+ if (this.onAsyncResponse) {
136
+ this._eventHandler.subscribe(this.onAsyncResponse, (event, args) => {
137
+ if (typeof this.rowDetailViewOptions?.onAsyncResponse === 'function') {
138
+ this.rowDetailViewOptions.onAsyncResponse(event, args);
139
+ }
140
+ });
141
+ }
142
+
143
+ if (this.onAsyncEndUpdate) {
144
+ this._eventHandler.subscribe(this.onAsyncEndUpdate, async (event, args) => {
145
+ // triggers after backend called "onAsyncResponse.notify()"
146
+ await this.renderViewModel(args?.item);
147
+
148
+ if (typeof this.rowDetailViewOptions?.onAsyncEndUpdate === 'function') {
149
+ this.rowDetailViewOptions.onAsyncEndUpdate(event, args);
150
+ }
151
+ });
152
+ }
153
+
154
+ if (this.onAfterRowDetailToggle) {
155
+ this._eventHandler.subscribe(this.onAfterRowDetailToggle, async (event, args) => {
156
+ // display preload template & re-render all the other Detail Views after toggling
157
+ // the preload View will eventually go away once the data gets loaded after the "onAsyncEndUpdate" event
158
+ await this.renderPreloadView(args.item);
159
+ this.renderAllViewModels();
160
+
161
+ if (typeof this.rowDetailViewOptions?.onAfterRowDetailToggle === 'function') {
162
+ this.rowDetailViewOptions.onAfterRowDetailToggle(event, args);
163
+ }
164
+ });
165
+ }
166
+
167
+ if (this.onBeforeRowDetailToggle) {
168
+ this._eventHandler.subscribe(this.onBeforeRowDetailToggle, (event, args) => {
169
+ // before toggling row detail, we need to create View Component if it doesn't exist
170
+ this.handleOnBeforeRowDetailToggle(event, args);
171
+
172
+ if (typeof this.rowDetailViewOptions?.onBeforeRowDetailToggle === 'function') {
173
+ return this.rowDetailViewOptions.onBeforeRowDetailToggle(event, args);
174
+ }
175
+ return true;
176
+ });
177
+ }
178
+
179
+ if (this.onRowBackToViewportRange) {
180
+ this._eventHandler.subscribe(this.onRowBackToViewportRange, async (event, args) => {
181
+ // when row is back to viewport range, we will re-render the View Component(s)
182
+ await this.handleOnRowBackToViewportRange(event, args);
183
+
184
+ if (typeof this.rowDetailViewOptions?.onRowBackToViewportRange === 'function') {
185
+ this.rowDetailViewOptions.onRowBackToViewportRange(event, args);
186
+ }
187
+ });
188
+ }
189
+
190
+ if (this.onRowOutOfViewportRange) {
191
+ this._eventHandler.subscribe(this.onRowOutOfViewportRange, (event, args) => {
192
+ if (typeof this.rowDetailViewOptions?.onRowOutOfViewportRange === 'function') {
193
+ this.rowDetailViewOptions.onRowOutOfViewportRange(event, args);
194
+ }
195
+ });
196
+ }
197
+
198
+ // --
199
+ // hook some events needed by the Plugin itself
200
+
201
+ // we need to redraw the open detail views if we change column position (column reorder)
202
+ this.eventHandler.subscribe(this._grid.onColumnsReordered, this.redrawAllViewComponents.bind(this));
203
+
204
+ // on row selection changed, we also need to redraw
205
+ if (this.gridOptions.enableRowSelection || this.gridOptions.enableCheckboxSelector) {
206
+ this._eventHandler.subscribe(this._grid.onSelectedRowsChanged, this.redrawAllViewComponents.bind(this));
207
+ }
208
+
209
+ // on column sort/reorder, all row detail are collapsed so we can dispose of all the Views as well
210
+ this._eventHandler.subscribe(this._grid.onSort, this.disposeAllViewComponents.bind(this));
211
+
212
+ // on filter changed, we need to re-render all Views
213
+ this._subscriptions.push(
214
+ this.eventPubSubService?.subscribe(
215
+ ['onFilterChanged', 'onGridMenuColumnsChanged', 'onColumnPickerColumnsChanged'],
216
+ this.redrawAllViewComponents.bind(this)
217
+ ),
218
+ this.eventPubSubService?.subscribe(['onGridMenuClearAllFilters', 'onGridMenuClearAllSorting'], () =>
219
+ window.setTimeout(() => this.redrawAllViewComponents())
220
+ )
221
+ );
222
+ }
223
+ }
224
+ }
225
+
226
+ return this;
227
+ }
228
+
229
+ /** Redraw (re-render) all the expanded row detail View Components */
230
+ async redrawAllViewComponents() {
231
+ await Promise.all(this._views.map(async (x) => this.redrawViewComponent(x)));
232
+ }
233
+
234
+ /** Render all the expanded row detail View Components */
235
+ async renderAllViewModels() {
236
+ await Promise.all(this._views.filter((x) => x?.dataContext).map(async (x) => this.renderViewModel(x.dataContext)));
237
+ }
238
+
239
+ /** Redraw the necessary View Component */
240
+ async redrawViewComponent(view: CreatedView) {
241
+ const containerElement = this.gridContainerElement.getElementsByClassName(`${ROW_DETAIL_CONTAINER_PREFIX}${view.id}`);
242
+ if (containerElement?.length >= 0) {
243
+ await this.renderViewModel(view.dataContext);
244
+ }
245
+ }
246
+
247
+ /** Render (or re-render) the View Component (Row Detail) */
248
+ async renderPreloadView(item: any) {
249
+ const containerElements = this.gridContainerElement.getElementsByClassName(`${PRELOAD_CONTAINER_PREFIX}`);
250
+ if (this._preloadComponent && containerElements?.length) {
251
+ const viewObj = this._views.find((obj) => obj.id === item[this.datasetIdPropName]);
252
+ const bindableData = {
253
+ model: item,
254
+ addon: this,
255
+ grid: this._grid,
256
+ dataView: this.dataView,
257
+ // @deprecated @use `parentRef`
258
+ parent: this.rowDetailViewOptions?.parent,
259
+ parentRef: this.rowDetailViewOptions?.parent,
260
+ } as AppData & ViewModelBindableInputData;
261
+
262
+ const tmpDiv = document.createElement('div');
263
+ const app = createApp(this._preloadComponent, bindableData);
264
+ const instance = app.mount(tmpDiv) as ComponentPublicInstance;
265
+ bindableData.parent = instance;
266
+ containerElements[containerElements.length - 1]!.appendChild(instance.$el);
267
+
268
+ if (viewObj) {
269
+ viewObj.app = app;
270
+ viewObj.instance = instance;
271
+ }
272
+ }
273
+ }
274
+
275
+ /** Render (or re-render) the View Component (Row Detail) */
276
+ async renderViewModel(item: any) {
277
+ const containerElements = this.gridContainerElement.getElementsByClassName(
278
+ `${ROW_DETAIL_CONTAINER_PREFIX}${item[this.datasetIdPropName]}`
279
+ );
280
+ if (this._component && containerElements?.length) {
281
+ const viewObj = this._views.find((obj) => obj.id === item[this.datasetIdPropName]);
282
+ const bindableData = {
283
+ model: item,
284
+ addon: this,
285
+ grid: this._grid,
286
+ dataView: this.dataView,
287
+ // @deprecated @use `parentRef`
288
+ parent: this.rowDetailViewOptions?.parent,
289
+ parentRef: this.rowDetailViewOptions?.parent,
290
+ } as AppData & ViewModelBindableInputData;
291
+
292
+ // load our Row Detail React Component dynamically, typically we would want to use `root.render()` after the preload component (last argument below)
293
+ // BUT the root render doesn't seem to work and shows a blank element, so we'll use `createRoot()` every time even though it shows a console log in Dev
294
+ // that is the only way I got it working so let's use it anyway and console warnings are removed in production anyway
295
+ if (viewObj?.app) {
296
+ viewObj.app.unmount();
297
+ }
298
+ const tmpDiv = document.createElement('div');
299
+ const app = createApp(this._component, bindableData);
300
+ const instance = app.mount(tmpDiv) as ComponentPublicInstance;
301
+ bindableData.parent = app.component;
302
+ (containerElements[containerElements.length - 1] as HTMLElement).appendChild(instance.$el);
303
+ if (!viewObj) {
304
+ this.addViewInfoToViewsRef(item, app, instance);
305
+ }
306
+ }
307
+ }
308
+
309
+ // --
310
+ // protected functions
311
+ // ------------------
312
+
313
+ protected addViewInfoToViewsRef(item: any, app: App | null, instance: ComponentPublicInstance | null) {
314
+ const viewInfo: CreatedView = {
315
+ id: item[this.datasetIdPropName],
316
+ dataContext: item,
317
+ app,
318
+ instance,
319
+ };
320
+ const idPropName = this.gridOptions.datasetIdPropertyName || 'id';
321
+ addToArrayWhenNotExists(this._views, viewInfo, idPropName);
322
+ }
323
+
324
+ protected disposeViewComponent(expandedView: CreatedView): CreatedView | void {
325
+ if (expandedView) {
326
+ if (expandedView?.instance) {
327
+ const container = this.gridContainerElement.getElementsByClassName(`${ROW_DETAIL_CONTAINER_PREFIX}${this._views[0].id}`);
328
+ if (container?.length) {
329
+ expandedView.app?.unmount();
330
+ container[0].textContent = '';
331
+ return expandedView;
332
+ }
333
+ }
334
+ }
335
+ }
336
+
337
+ /**
338
+ * Just before the row get expanded or collapsed we will do the following
339
+ * First determine if the row is expanding or collapsing,
340
+ * if it's expanding we will add it to our View Components reference array if we don't already have it
341
+ * or if it's collapsing we will remove it from our View Components reference array
342
+ */
343
+ protected handleOnBeforeRowDetailToggle(_e: SlickEventData<OnBeforeRowDetailToggleArgs>, args: { grid: SlickGrid; item: any; }) {
344
+ // expanding
345
+ if (args?.item?.__collapsed) {
346
+ // expanding row detail
347
+ this.addViewInfoToViewsRef(args.item, null, null);
348
+ } else {
349
+ // collapsing, so dispose of the View
350
+ const foundViewIdx = this._views.findIndex((view: CreatedView) => view.id === args.item[this.datasetIdPropName]);
351
+ if (foundViewIdx >= 0 && this.disposeViewComponent(this._views[foundViewIdx])) {
352
+ this._views.splice(foundViewIdx, 1);
353
+ }
354
+ }
355
+ }
356
+
357
+ /** When Row comes back to Viewport Range, we need to redraw the View */
358
+ protected async handleOnRowBackToViewportRange(
359
+ _e: SlickEventData<OnRowBackToViewportRangeArgs>,
360
+ args: {
361
+ item: any;
362
+ rowId: string | number;
363
+ rowIndex: number;
364
+ expandedRows: (string | number)[];
365
+ rowIdsOutOfViewport: (string | number)[];
366
+ grid: SlickGrid;
367
+ }
368
+ ) {
369
+ if (args?.item) {
370
+ await this.redrawAllViewComponents();
371
+ }
372
+ }
373
+
374
+ /**
375
+ * notify the onAsyncResponse with the "args.item" (required property)
376
+ * the plugin will then use item to populate the row detail panel with the "postTemplate"
377
+ * @param item
378
+ */
379
+ protected notifyTemplate(item: any) {
380
+ if (this.onAsyncResponse) {
381
+ this.onAsyncResponse.notify({ item, itemDetail: item }, new SlickEventData(), this);
382
+ }
383
+ }
384
+
385
+ /**
386
+ * On Processing, we will notify the plugin with the new item detail once backend server call completes
387
+ * @param item
388
+ */
389
+ protected async onProcessing(item: any) {
390
+ if (item && typeof this._userProcessFn === 'function') {
391
+ let awaitedItemDetail: any;
392
+ const userProcessFn = this._userProcessFn(item);
393
+
394
+ // wait for the "userProcessFn", once resolved we will save it into the "collection"
395
+ const response: any | any[] = await userProcessFn;
396
+
397
+ if (this.datasetIdPropName in response) {
398
+ awaitedItemDetail = response; // from Promise
399
+ } else if (response instanceof Response && typeof response['json'] === 'function') {
400
+ awaitedItemDetail = await response['json'](); // from Fetch
401
+ } else if (response && response['content']) {
402
+ awaitedItemDetail = response['content']; // from http-client
403
+ }
404
+
405
+ if (!awaitedItemDetail || !(this.datasetIdPropName in awaitedItemDetail)) {
406
+ throw new Error(
407
+ '[Slickgrid-React] could not process the Row Detail, please make sure that your "process" callback ' +
408
+ '(a Promise or an HttpClient call returning an Observable) returns an item object that has an "${this.datasetIdPropName}" property'
409
+ );
410
+ }
411
+
412
+ // notify the plugin with the new item details
413
+ this.notifyTemplate(awaitedItemDetail || {});
414
+ }
415
+ }
416
+ }