vgapp 1.4.7 → 1.4.9

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 (85) hide show
  1. package/README.md +24 -2
  2. package/app/modules/base-module.js +14 -2
  3. package/app/modules/module-fn.js +5 -4
  4. package/app/modules/vgalert/js/vgalert.js +21 -1
  5. package/app/modules/vgalert/scss/vgalert.scss +48 -0
  6. package/app/modules/vgdropdown/js/vgdropdown.js +58 -27
  7. package/app/modules/vgfilepreview/js/renderers/video-modal.js +5 -1
  8. package/app/modules/vgfilepreview/js/renderers/video.js +6 -1
  9. package/app/modules/vgfilepreview/js/vgfilepreview.js +5 -1
  10. package/app/modules/vgfiles/js/base.js +14 -5
  11. package/app/modules/vgfiles/js/droppable.js +37 -31
  12. package/app/modules/vgfiles/js/vgfiles.js +5 -2
  13. package/app/modules/vgfiles/scss/_variables.scss +3 -1
  14. package/app/modules/vgfiles/scss/vgfiles.scss +55 -10
  15. package/app/modules/vgformsender/js/vgformsender.js +5 -2
  16. package/app/modules/vgloadmore/js/vgloadmore.js +35 -7
  17. package/app/modules/vgnestable/js/vgnestable.js +140 -0
  18. package/app/modules/vgnestable/scss/_variables.scss +16 -9
  19. package/app/modules/vgnestable/scss/vgnestable.scss +35 -2
  20. package/app/modules/vgtable/index.js +3 -0
  21. package/app/modules/vgtable/js/_columns.js +567 -0
  22. package/app/modules/vgtable/js/_expandable.js +242 -0
  23. package/app/modules/vgtable/js/_filters.js +264 -0
  24. package/app/modules/vgtable/js/_fixed-columns.js +249 -0
  25. package/app/modules/vgtable/js/_i18n.js +75 -0
  26. package/app/modules/vgtable/js/_options.js +428 -0
  27. package/app/modules/vgtable/js/_pagination.js +491 -0
  28. package/app/modules/vgtable/js/_panning.js +124 -0
  29. package/app/modules/vgtable/js/_params-groups.js +21 -0
  30. package/app/modules/vgtable/js/_remote.js +395 -0
  31. package/app/modules/vgtable/js/_row-reorder.js +268 -0
  32. package/app/modules/vgtable/js/_search.js +134 -0
  33. package/app/modules/vgtable/js/_selection.js +113 -0
  34. package/app/modules/vgtable/js/_skeleton.js +123 -0
  35. package/app/modules/vgtable/js/_sorting.js +340 -0
  36. package/app/modules/vgtable/js/_states.js +143 -0
  37. package/app/modules/vgtable/js/_sticky-header.js +193 -0
  38. package/app/modules/vgtable/js/_url-state.js +178 -0
  39. package/app/modules/vgtable/js/vgtable.js +1444 -0
  40. package/app/modules/vgtable/readme.md +922 -0
  41. package/app/modules/vgtable/scss/_columns.scss +52 -0
  42. package/app/modules/vgtable/scss/_expandable.scss +54 -0
  43. package/app/modules/vgtable/scss/_fixed-columns.scss +117 -0
  44. package/app/modules/vgtable/scss/_pagination.scss +191 -0
  45. package/app/modules/vgtable/scss/_row-reorder.scss +45 -0
  46. package/app/modules/vgtable/scss/_skeleton.scss +65 -0
  47. package/app/modules/vgtable/scss/_sorting.scss +89 -0
  48. package/app/modules/vgtable/scss/_states.scss +70 -0
  49. package/app/modules/vgtable/scss/_sticky-header.scss +121 -0
  50. package/app/modules/vgtable/scss/_variables.scss +296 -0
  51. package/app/modules/vgtable/scss/vgtable.scss +206 -0
  52. package/app/utils/js/components/placement.js +64 -10
  53. package/app/vgapp.js +3 -3
  54. package/build/vgapp.css +1 -1
  55. package/build/vgapp.css.map +1 -1
  56. package/build/vgapp.js +1 -1
  57. package/build/vgapp.js.map +1 -1
  58. package/index.js +1 -1
  59. package/index.scss +3 -3
  60. package/package.json +5 -5
  61. package/app/modules/vgdynamictable/index.js +0 -4
  62. package/app/modules/vgdynamictable/js/editable.js +0 -438
  63. package/app/modules/vgdynamictable/js/expandable.js +0 -248
  64. package/app/modules/vgdynamictable/js/filters.js +0 -450
  65. package/app/modules/vgdynamictable/js/fixed.js +0 -566
  66. package/app/modules/vgdynamictable/js/options.js +0 -650
  67. package/app/modules/vgdynamictable/js/pagination.js +0 -623
  68. package/app/modules/vgdynamictable/js/search.js +0 -82
  69. package/app/modules/vgdynamictable/js/skeleton.js +0 -144
  70. package/app/modules/vgdynamictable/js/sortable.js +0 -442
  71. package/app/modules/vgdynamictable/js/summary-footer.js +0 -284
  72. package/app/modules/vgdynamictable/js/table-remote.js +0 -821
  73. package/app/modules/vgdynamictable/js/table-state.js +0 -243
  74. package/app/modules/vgdynamictable/js/table-url-state.js +0 -444
  75. package/app/modules/vgdynamictable/js/utils/common.js +0 -48
  76. package/app/modules/vgdynamictable/js/vgdynamictable.js +0 -3870
  77. package/app/modules/vgdynamictable/js/viewport.js +0 -322
  78. package/app/modules/vgdynamictable/readme.md +0 -251
  79. package/app/modules/vgdynamictable/scss/_actions.scss +0 -196
  80. package/app/modules/vgdynamictable/scss/_pagination.scss +0 -186
  81. package/app/modules/vgdynamictable/scss/_skeleton.scss +0 -63
  82. package/app/modules/vgdynamictable/scss/_sortable.scss +0 -66
  83. package/app/modules/vgdynamictable/scss/_table.scss +0 -137
  84. package/app/modules/vgdynamictable/scss/_variables.scss +0 -138
  85. package/app/modules/vgdynamictable/scss/vgdynamictable.scss +0 -264
@@ -0,0 +1,178 @@
1
+ /**
2
+ * Описание: единое состояние VGTable в query string.
3
+ * Возможности: чтение/запись page, perPage, одиночной и мультисортировки, search и filters, popstate и публичные события.
4
+ */
5
+ import EventHandler from "../../../utils/js/dom/event";
6
+
7
+
8
+ const EVENT_READ = 'urlstateread.vg.table';
9
+ const EVENT_WRITE = 'urlstatewrite.vg.table';
10
+ const EVENT_ERROR = 'urlstateerror.vg.table';
11
+
12
+ class _urlState {
13
+ constructor(table, options = {}, hooks = {}) {
14
+ this._table = table;
15
+ this._options = options;
16
+ this._hooks = hooks;
17
+ this._state = null;
18
+ this._boundPopState = this._handlePopState.bind(this);
19
+ }
20
+
21
+ init() {
22
+ if (this._options.listen !== false && typeof window !== 'undefined') {
23
+ window.addEventListener('popstate', this._boundPopState);
24
+ }
25
+ return this;
26
+ }
27
+
28
+ dispose() {
29
+ if (typeof window !== 'undefined') window.removeEventListener('popstate', this._boundPopState);
30
+ this._state = null;
31
+ }
32
+
33
+ read(source = 'api') {
34
+ if (typeof window === 'undefined') return this._emptyState();
35
+ try {
36
+ const params = new URLSearchParams(window.location.search || '');
37
+ const keys = this._keys();
38
+ const state = this._emptyState();
39
+ if (this._include('pagination')) {
40
+ state.present.page = params.has(keys.page);
41
+ state.present.perPage = params.has(keys.perPage);
42
+ state.page = this._positiveInt(params.get(keys.page), null);
43
+ state.perPage = this._positiveInt(params.get(keys.perPage), null);
44
+ }
45
+ if (this._include('sort')) {
46
+ state.present.sort = params.has(keys.sort) || params.has(keys.direction);
47
+ const fields = this._list(params.get(keys.sort));
48
+ const directions = this._list(params.get(keys.direction));
49
+ const sorts = fields.map((field, index) => ({
50
+ field,
51
+ direction: String(directions[index] || directions[0] || 'asc').toLowerCase() === 'desc' ? 'desc' : 'asc',
52
+ }));
53
+ state.sort = sorts.length ? Object.assign({}, sorts[0], {sorts}) : null;
54
+ }
55
+ if (this._include('search')) {
56
+ state.present.search = params.has(keys.search);
57
+ state.search = String(params.get(keys.search) || '');
58
+ }
59
+ if (this._include('filters')) this._filterFields().forEach((filter) => {
60
+ const valueKey = `${keys.filterPrefix}${filter}`;
61
+ const operatorKey = `${valueKey}_op`;
62
+ const values = params.getAll(valueKey);
63
+ if (values.length) {
64
+ state.filters[filter] = values.length === 1 ? values[0] : values;
65
+ state.present.filters = true;
66
+ }
67
+ if (params.has(operatorKey)) {
68
+ state.filters[`${filter}_op`] = params.get(operatorKey);
69
+ state.present.filters = true;
70
+ }
71
+ });
72
+ this._state = state;
73
+ EventHandler.trigger(this._table, EVENT_READ, {source, state: this.getState()});
74
+ return this.getState();
75
+ } catch (error) {
76
+ EventHandler.trigger(this._table, EVENT_ERROR, {source: 'read', error});
77
+ return this._emptyState();
78
+ }
79
+ }
80
+
81
+ write(state = {}) {
82
+ if (this._options.write === false || typeof window === 'undefined' || !window.history) return null;
83
+ try {
84
+ const url = new URL(window.location.href);
85
+ const keys = this._keys();
86
+ this._managedKeys().forEach((key) => url.searchParams.delete(key));
87
+ if (this._include('pagination')) {
88
+ this._set(url, keys.page, state.page || 1);
89
+ this._set(url, keys.perPage, state.perPage || '');
90
+ }
91
+ if (this._include('sort') && state.sort?.field) {
92
+ const sorts = Array.isArray(state.sort.sorts) && state.sort.sorts.length ? state.sort.sorts : [state.sort];
93
+ this._set(url, keys.sort, sorts.map((item) => item.field).filter(Boolean).join(','));
94
+ this._set(url, keys.direction, sorts.map((item) => item.direction === 'desc' ? 'desc' : 'asc').join(','));
95
+ }
96
+ if (this._include('search')) this._set(url, keys.search, state.search || '');
97
+ if (this._include('filters')) {
98
+ Object.entries(state.filters || {}).forEach(([key, value]) => {
99
+ const queryKey = `${keys.filterPrefix}${key}`;
100
+ (Array.isArray(value) ? value : [value]).forEach((item) => this._append(url, queryKey, item));
101
+ });
102
+ }
103
+ const next = `${url.pathname}${url.search}${url.hash}`;
104
+ const current = `${window.location.pathname}${window.location.search}${window.location.hash}`;
105
+ if (next !== current) window.history[this._options.mode === 'push' ? 'pushState' : 'replaceState']({}, '', next);
106
+ this._state = Object.assign({}, state);
107
+ EventHandler.trigger(this._table, EVENT_WRITE, {mode: this._options.mode, state: this.getState(), url: next});
108
+ return next;
109
+ } catch (error) {
110
+ EventHandler.trigger(this._table, EVENT_ERROR, {source: 'write', error});
111
+ return null;
112
+ }
113
+ }
114
+
115
+ getState() {
116
+ return this._state ? JSON.parse(JSON.stringify(this._state)) : null;
117
+ }
118
+
119
+ _handlePopState() {
120
+ this._hooks.apply?.(this.read('popstate'), {source: 'popstate', clearMissing: true});
121
+ }
122
+
123
+ _managedKeys() {
124
+ const keys = this._keys();
125
+ const managed = [];
126
+ if (this._include('pagination')) managed.push(keys.page, keys.perPage);
127
+ if (this._include('sort')) managed.push(keys.sort, keys.direction);
128
+ if (this._include('search')) managed.push(keys.search);
129
+ if (this._include('filters')) this._filterFields().forEach((filter) => managed.push(`${keys.filterPrefix}${filter}`, `${keys.filterPrefix}${filter}_op`));
130
+ return managed.filter(Boolean);
131
+ }
132
+
133
+ _filterFields() {
134
+ return this._hooks.getFilterFields?.() || [];
135
+ }
136
+
137
+ _keys() {
138
+ const source = this._options.keys || {};
139
+ const prefix = String(this._options.prefix || '');
140
+ return {
141
+ page: `${prefix}${source.page || 'page'}`,
142
+ perPage: `${prefix}${source.perPage || 'perPage'}`,
143
+ sort: `${prefix}${source.sort || 'sort'}`,
144
+ direction: `${prefix}${source.direction || 'dir'}`,
145
+ search: `${prefix}${source.search || 'search'}`,
146
+ filterPrefix: `${prefix}${source.filterPrefix || 'filter-'}`,
147
+ };
148
+ }
149
+
150
+ _include(key) {
151
+ return (this._options.include || {})[key] !== false;
152
+ }
153
+
154
+ _emptyState() {
155
+ return {page: null, perPage: null, sort: null, search: '', filters: {}, present: {page: false, perPage: false, sort: false, search: false, filters: false}};
156
+ }
157
+
158
+ _set(url, key, value) {
159
+ if (value === undefined || value === null || String(value) === '') return;
160
+ url.searchParams.set(key, String(value));
161
+ }
162
+
163
+ _append(url, key, value) {
164
+ if (value === undefined || value === null || String(value) === '') return;
165
+ url.searchParams.append(key, String(value));
166
+ }
167
+
168
+ _positiveInt(value, fallback) {
169
+ const parsed = Number.parseInt(value, 10);
170
+ return Number.isFinite(parsed) && parsed > 0 ? parsed : fallback;
171
+ }
172
+
173
+ _list(value) {
174
+ return String(value || '').split(',').map((item) => item.trim()).filter(Boolean);
175
+ }
176
+ }
177
+
178
+ export default _urlState;