px-jspreadsheet-ce 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +292 -0
  3. package/dist/index.d.ts +2382 -0
  4. package/dist/index.js +11286 -0
  5. package/dist/index.js.map +1 -0
  6. package/dist/jspreadsheet.css +723 -0
  7. package/dist/jspreadsheet.themes.css +104 -0
  8. package/package.json +57 -0
  9. package/src/index.js +95 -0
  10. package/src/test.js +50 -0
  11. package/src/utils/cells.js +36 -0
  12. package/src/utils/columns.js +742 -0
  13. package/src/utils/comments.js +87 -0
  14. package/src/utils/config.js +46 -0
  15. package/src/utils/copyPaste.js +438 -0
  16. package/src/utils/data.js +419 -0
  17. package/src/utils/dispatch.js +115 -0
  18. package/src/utils/download.js +38 -0
  19. package/src/utils/editor.js +430 -0
  20. package/src/utils/events.js +1639 -0
  21. package/src/utils/factory.js +216 -0
  22. package/src/utils/filter.js +128 -0
  23. package/src/utils/footer.js +51 -0
  24. package/src/utils/freeze.js +19 -0
  25. package/src/utils/headers.js +74 -0
  26. package/src/utils/helpers.js +409 -0
  27. package/src/utils/history.js +336 -0
  28. package/src/utils/internal.js +1299 -0
  29. package/src/utils/internalHelpers.js +96 -0
  30. package/src/utils/keys.js +406 -0
  31. package/src/utils/lazyLoading.js +143 -0
  32. package/src/utils/libraryBase.js +5 -0
  33. package/src/utils/merges.js +275 -0
  34. package/src/utils/meta.js +81 -0
  35. package/src/utils/orderBy.js +185 -0
  36. package/src/utils/pagination.js +181 -0
  37. package/src/utils/rows.js +624 -0
  38. package/src/utils/search.js +83 -0
  39. package/src/utils/selection.js +744 -0
  40. package/src/utils/style.js +147 -0
  41. package/src/utils/toolbar.js +566 -0
  42. package/src/utils/version.js +9 -0
  43. package/src/utils/worksheets.js +731 -0
  44. package/src/webcomponent.js +59 -0
@@ -0,0 +1,147 @@
1
+ import dispatch from './dispatch.js';
2
+ import { getColumnNameFromId, getIdFromColumnName } from './internalHelpers.js';
3
+ import { setHistory } from './history.js';
4
+
5
+ /**
6
+ * Get style information from cell(s)
7
+ *
8
+ * @return integer
9
+ */
10
+ export const getStyle = function (cell, key) {
11
+ const obj = this;
12
+
13
+ // Cell
14
+ if (!cell) {
15
+ // Control vars
16
+ const data = {};
17
+
18
+ // Column and row length
19
+ const x = obj.options.data[0].length;
20
+ const y = obj.options.data.length;
21
+
22
+ // Go through the columns to get the data
23
+ for (let j = 0; j < y; j++) {
24
+ for (let i = 0; i < x; i++) {
25
+ // Value
26
+ const v = key ? obj.records[j][i].element.style[key] : obj.records[j][i].element.getAttribute('style');
27
+
28
+ // Any meta data for this column?
29
+ if (v) {
30
+ // Column name
31
+ const k = getColumnNameFromId([i, j]);
32
+ // Value
33
+ data[k] = v;
34
+ }
35
+ }
36
+ }
37
+
38
+ return data;
39
+ } else {
40
+ cell = getIdFromColumnName(cell, true);
41
+
42
+ return key ? obj.records[cell[1]][cell[0]].element.style[key] : obj.records[cell[1]][cell[0]].element.getAttribute('style');
43
+ }
44
+ };
45
+
46
+ /**
47
+ * Set meta information to cell(s)
48
+ *
49
+ * @return integer
50
+ */
51
+ export const setStyle = function (o, k, v, force, ignoreHistoryAndEvents) {
52
+ const obj = this;
53
+
54
+ const newValue = {};
55
+ const oldValue = {};
56
+
57
+ // Apply style
58
+ const applyStyle = function (cellId, key, value) {
59
+ // Position
60
+ const cell = getIdFromColumnName(cellId, true);
61
+
62
+ if (obj.records[cell[1]] && obj.records[cell[1]][cell[0]] && (obj.records[cell[1]][cell[0]].element.classList.contains('readonly') == false || force)) {
63
+ // Current value
64
+ const currentValue = obj.records[cell[1]][cell[0]].element.style[key];
65
+
66
+ // Change layout
67
+ if (currentValue == value && !force) {
68
+ value = '';
69
+ obj.records[cell[1]][cell[0]].element.style[key] = '';
70
+ } else {
71
+ obj.records[cell[1]][cell[0]].element.style[key] = value;
72
+ }
73
+
74
+ // History
75
+ if (!oldValue[cellId]) {
76
+ oldValue[cellId] = [];
77
+ }
78
+ if (!newValue[cellId]) {
79
+ newValue[cellId] = [];
80
+ }
81
+
82
+ oldValue[cellId].push([key + ':' + currentValue]);
83
+ newValue[cellId].push([key + ':' + value]);
84
+ }
85
+ };
86
+
87
+ if (k && v) {
88
+ // Get object from string
89
+ if (typeof o == 'string') {
90
+ applyStyle(o, k, v);
91
+ }
92
+ } else {
93
+ const keys = Object.keys(o);
94
+ for (let i = 0; i < keys.length; i++) {
95
+ let style = o[keys[i]];
96
+ if (typeof style !== 'string') {
97
+ continue;
98
+ }
99
+ // 遍历样式表
100
+ const styles = style.split(';');
101
+ for (let j = 0; j < styles.length; j++) {
102
+ if (typeof styles[j] !== 'string') {
103
+ continue;
104
+ }
105
+ const [k, v] = styles[j].split(':');
106
+ // Apply value
107
+ if (style[j][0].trim()) {
108
+ applyStyle(keys[i], k.trim(), v);
109
+ }
110
+ }
111
+ }
112
+ }
113
+
114
+ let keys = Object.keys(oldValue);
115
+ for (let i = 0; i < keys.length; i++) {
116
+ oldValue[keys[i]] = oldValue[keys[i]].join(';');
117
+ }
118
+ keys = Object.keys(newValue);
119
+ for (let i = 0; i < keys.length; i++) {
120
+ newValue[keys[i]] = newValue[keys[i]].join(';');
121
+ }
122
+
123
+ if (!ignoreHistoryAndEvents) {
124
+ // Keeping history of changes
125
+ setHistory.call(obj, {
126
+ action: 'setStyle',
127
+ oldValue: oldValue,
128
+ newValue: newValue,
129
+ });
130
+ }
131
+
132
+ dispatch.call(obj, 'onchangestyle', obj, newValue);
133
+ };
134
+
135
+ export const resetStyle = function (o, ignoreHistoryAndEvents) {
136
+ const obj = this;
137
+
138
+ const keys = Object.keys(o);
139
+ for (let i = 0; i < keys.length; i++) {
140
+ // Position
141
+ const cell = getIdFromColumnName(keys[i], true);
142
+ if (obj.records[cell[1]] && obj.records[cell[1]][cell[0]]) {
143
+ obj.records[cell[1]][cell[0]].element.setAttribute('style', '');
144
+ }
145
+ }
146
+ obj.setStyle(o, null, null, null, ignoreHistoryAndEvents);
147
+ };
@@ -0,0 +1,566 @@
1
+ import jSuites from 'jsuites';
2
+ import { getCellNameFromCoords } from './helpers.js';
3
+ import { getWorksheetInstance } from './internal.js';
4
+
5
+ const setItemStatus = function (toolbarItem, worksheet) {
6
+ if (worksheet.options.editable != false) {
7
+ toolbarItem.classList.remove('jtoolbar-disabled');
8
+ } else {
9
+ toolbarItem.classList.add('jtoolbar-disabled');
10
+ }
11
+ };
12
+
13
+ export const getDefault = function () {
14
+ const items = [];
15
+ const spreadsheet = this;
16
+
17
+ const getActive = function () {
18
+ return getWorksheetInstance.call(spreadsheet);
19
+ };
20
+
21
+ items.push({
22
+ content: 'undo',
23
+ onclick: function () {
24
+ const worksheet = getActive();
25
+
26
+ worksheet.undo();
27
+ },
28
+ });
29
+
30
+ items.push({
31
+ content: 'redo',
32
+ onclick: function () {
33
+ const worksheet = getActive();
34
+
35
+ worksheet.redo();
36
+ },
37
+ });
38
+
39
+ items.push({
40
+ content: 'save',
41
+ onclick: function () {
42
+ const worksheet = getActive();
43
+
44
+ if (worksheet) {
45
+ worksheet.download();
46
+ }
47
+ },
48
+ });
49
+
50
+ items.push({
51
+ type: 'divisor',
52
+ });
53
+
54
+ items.push({
55
+ type: 'select',
56
+ width: '120px',
57
+ options: ['Default', 'Verdana', 'Arial', 'Courier New'],
58
+ render: function (e) {
59
+ return '<span style="font-family:' + e + '">' + e + '</span>';
60
+ },
61
+ onchange: function (a, b, c, d, e) {
62
+ const worksheet = getActive();
63
+
64
+ let cells = worksheet.getSelected(true);
65
+ if (cells) {
66
+ let value = !e ? '' : d;
67
+
68
+ worksheet.setStyle(
69
+ Object.fromEntries(
70
+ cells.map(function (cellName) {
71
+ return [cellName, 'font-family: ' + value];
72
+ })
73
+ )
74
+ );
75
+ }
76
+ },
77
+ updateState: function (a, b, toolbarItem) {
78
+ setItemStatus(toolbarItem, getActive());
79
+ },
80
+ });
81
+
82
+ items.push({
83
+ type: 'select',
84
+ width: '48px',
85
+ content: 'format_size',
86
+ options: ['x-small', 'small', 'medium', 'large', 'x-large'],
87
+ render: function (e) {
88
+ return '<span style="font-size:' + e + '">' + e + '</span>';
89
+ },
90
+ onchange: function (a, b, c, value) {
91
+ const worksheet = getActive();
92
+
93
+ let cells = worksheet.getSelected(true);
94
+ if (cells) {
95
+ worksheet.setStyle(
96
+ Object.fromEntries(
97
+ cells.map(function (cellName) {
98
+ return [cellName, 'font-size: ' + value];
99
+ })
100
+ )
101
+ );
102
+ }
103
+ },
104
+ updateState: function (a, b, toolbarItem) {
105
+ setItemStatus(toolbarItem, getActive());
106
+ },
107
+ });
108
+
109
+ items.push({
110
+ type: 'select',
111
+ options: ['left', 'center', 'right', 'justify'],
112
+ render: function (e) {
113
+ return '<i class="material-icons">format_align_' + e + '</i>';
114
+ },
115
+ onchange: function (a, b, c, value) {
116
+ const worksheet = getActive();
117
+
118
+ let cells = worksheet.getSelected(true);
119
+ if (cells) {
120
+ worksheet.setStyle(
121
+ Object.fromEntries(
122
+ cells.map(function (cellName) {
123
+ return [cellName, 'text-align: ' + value];
124
+ })
125
+ )
126
+ );
127
+ }
128
+ },
129
+ updateState: function (a, b, toolbarItem) {
130
+ setItemStatus(toolbarItem, getActive());
131
+ },
132
+ });
133
+
134
+ items.push({
135
+ content: 'format_bold',
136
+ onclick: function () {
137
+ const worksheet = getActive();
138
+
139
+ let cells = worksheet.getSelected(true);
140
+ if (cells) {
141
+ worksheet.setStyle(
142
+ Object.fromEntries(
143
+ cells.map(function (cellName) {
144
+ return [cellName, 'font-weight:bold'];
145
+ })
146
+ )
147
+ );
148
+ }
149
+ },
150
+ updateState: function (a, b, toolbarItem) {
151
+ setItemStatus(toolbarItem, getActive());
152
+ },
153
+ });
154
+
155
+ items.push({
156
+ type: 'color',
157
+ content: 'format_color_text',
158
+ k: 'color',
159
+ updateState: function (a, b, toolbarItem) {
160
+ setItemStatus(toolbarItem, getActive());
161
+ },
162
+ });
163
+
164
+ items.push({
165
+ type: 'color',
166
+ content: 'format_color_fill',
167
+ k: 'background-color',
168
+ updateState: function (a, b, toolbarItem, d) {
169
+ setItemStatus(toolbarItem, getActive());
170
+ },
171
+ });
172
+
173
+ let verticalAlign = ['top', 'middle', 'bottom'];
174
+
175
+ items.push({
176
+ type: 'select',
177
+ options: ['vertical_align_top', 'vertical_align_center', 'vertical_align_bottom'],
178
+ render: function (e) {
179
+ return '<i class="material-icons">' + e + '</i>';
180
+ },
181
+ value: 1,
182
+ onchange: function (a, b, c, d, value) {
183
+ const worksheet = getActive();
184
+
185
+ let cells = worksheet.getSelected(true);
186
+ if (cells) {
187
+ worksheet.setStyle(
188
+ Object.fromEntries(
189
+ cells.map(function (cellName) {
190
+ return [cellName, 'vertical-align: ' + verticalAlign[value]];
191
+ })
192
+ )
193
+ );
194
+ }
195
+ },
196
+ updateState: function (a, b, toolbarItem) {
197
+ setItemStatus(toolbarItem, getActive());
198
+ },
199
+ });
200
+
201
+ items.push({
202
+ content: 'web',
203
+ tooltip: jSuites.translate('Merge the selected cells'),
204
+ onclick: function () {
205
+ const worksheet = getActive();
206
+
207
+ if (worksheet.selectedCell && confirm(jSuites.translate('The merged cells will retain the value of the top-left cell only. Are you sure?'))) {
208
+ const selectedRange = [
209
+ Math.min(worksheet.selectedCell[0], worksheet.selectedCell[2]),
210
+ Math.min(worksheet.selectedCell[1], worksheet.selectedCell[3]),
211
+ Math.max(worksheet.selectedCell[0], worksheet.selectedCell[2]),
212
+ Math.max(worksheet.selectedCell[1], worksheet.selectedCell[3]),
213
+ ];
214
+
215
+ let cell = getCellNameFromCoords(selectedRange[0], selectedRange[1]);
216
+ if (worksheet.records[selectedRange[1]][selectedRange[0]].element.getAttribute('data-merged')) {
217
+ worksheet.removeMerge(cell);
218
+ } else {
219
+ let colspan = selectedRange[2] - selectedRange[0] + 1;
220
+ let rowspan = selectedRange[3] - selectedRange[1] + 1;
221
+
222
+ if (colspan !== 1 || rowspan !== 1) {
223
+ worksheet.setMerge(cell, colspan, rowspan);
224
+ }
225
+ }
226
+ }
227
+ },
228
+ updateState: function (a, b, toolbarItem) {
229
+ setItemStatus(toolbarItem, getActive());
230
+ },
231
+ });
232
+
233
+ items.push({
234
+ type: 'select',
235
+ options: [
236
+ 'border_all',
237
+ 'border_outer',
238
+ 'border_inner',
239
+ 'border_horizontal',
240
+ 'border_vertical',
241
+ 'border_left',
242
+ 'border_top',
243
+ 'border_right',
244
+ 'border_bottom',
245
+ 'border_clear',
246
+ ],
247
+ columns: 5,
248
+ render: function (e) {
249
+ return '<i class="material-icons">' + e + '</i>';
250
+ },
251
+ right: true,
252
+ onchange: function (a, b, c, d) {
253
+ const worksheet = getActive();
254
+
255
+ if (worksheet.selectedCell) {
256
+ const selectedRange = [
257
+ Math.min(worksheet.selectedCell[0], worksheet.selectedCell[2]),
258
+ Math.min(worksheet.selectedCell[1], worksheet.selectedCell[3]),
259
+ Math.max(worksheet.selectedCell[0], worksheet.selectedCell[2]),
260
+ Math.max(worksheet.selectedCell[1], worksheet.selectedCell[3]),
261
+ ];
262
+
263
+ let type = d;
264
+
265
+ if (selectedRange) {
266
+ // Default options
267
+ let thickness = b.thickness || 1;
268
+ let color = b.color || 'black';
269
+ const borderStyle = b.style || 'solid';
270
+
271
+ if (borderStyle === 'double') {
272
+ thickness += 2;
273
+ }
274
+
275
+ let style = {};
276
+
277
+ // Matrix
278
+ let px = selectedRange[0];
279
+ let py = selectedRange[1];
280
+ let ux = selectedRange[2];
281
+ let uy = selectedRange[3];
282
+
283
+ const setBorder = function (columnName, i, j) {
284
+ let border = ['', '', '', ''];
285
+
286
+ if (
287
+ ((type === 'border_top' || type === 'border_outer') && j === py) ||
288
+ ((type === 'border_inner' || type === 'border_horizontal') && j > py) ||
289
+ type === 'border_all'
290
+ ) {
291
+ border[0] = 'border-top: ' + thickness + 'px ' + borderStyle + ' ' + color;
292
+ } else {
293
+ border[0] = 'border-top: ';
294
+ }
295
+
296
+ if ((type === 'border_all' || type === 'border_right' || type === 'border_outer') && i === ux) {
297
+ border[1] = 'border-right: ' + thickness + 'px ' + borderStyle + ' ' + color;
298
+ } else {
299
+ border[1] = 'border-right: ';
300
+ }
301
+
302
+ if ((type === 'border_all' || type === 'border_bottom' || type === 'border_outer') && j === uy) {
303
+ border[2] = 'border-bottom: ' + thickness + 'px ' + borderStyle + ' ' + color;
304
+ } else {
305
+ border[2] = 'border-bottom: ';
306
+ }
307
+
308
+ if (
309
+ ((type === 'border_left' || type === 'border_outer') && i === px) ||
310
+ ((type === 'border_inner' || type === 'border_vertical') && i > px) ||
311
+ type === 'border_all'
312
+ ) {
313
+ border[3] = 'border-left: ' + thickness + 'px ' + borderStyle + ' ' + color;
314
+ } else {
315
+ border[3] = 'border-left: ';
316
+ }
317
+
318
+ style[columnName] = border.join(';');
319
+ };
320
+
321
+ for (let j = selectedRange[1]; j <= selectedRange[3]; j++) {
322
+ // Row - py - uy
323
+ for (let i = selectedRange[0]; i <= selectedRange[2]; i++) {
324
+ // Col - px - ux
325
+ setBorder(getCellNameFromCoords(i, j), i, j);
326
+
327
+ if (worksheet.records[j][i].element.getAttribute('data-merged')) {
328
+ setBorder(getCellNameFromCoords(selectedRange[0], selectedRange[1]), i, j);
329
+ }
330
+ }
331
+ }
332
+
333
+ if (Object.keys(style)) {
334
+ worksheet.setStyle(style);
335
+ }
336
+ }
337
+ }
338
+ },
339
+ onload: function (a, b) {
340
+ // Border color
341
+ let container = document.createElement('div');
342
+ let div = document.createElement('div');
343
+ container.appendChild(div);
344
+
345
+ let colorPicker = jSuites.color(div, {
346
+ closeOnChange: false,
347
+ onchange: function (o, v) {
348
+ o.parentNode.children[1].style.color = v;
349
+ b.color = v;
350
+ },
351
+ });
352
+
353
+ let i = document.createElement('i');
354
+ i.classList.add('material-icons');
355
+ i.innerHTML = 'color_lens';
356
+ i.onclick = function () {
357
+ colorPicker.open();
358
+ };
359
+ container.appendChild(i);
360
+ a.children[1].appendChild(container);
361
+
362
+ div = document.createElement('div');
363
+ jSuites.picker(div, {
364
+ type: 'select',
365
+ data: [1, 2, 3, 4, 5],
366
+ render: function (e) {
367
+ return '<div style="height: ' + e + 'px; width: 30px; background-color: black;"></div>';
368
+ },
369
+ onchange: function (a, k, c, d) {
370
+ b.thickness = d;
371
+ },
372
+ width: '50px',
373
+ });
374
+ a.children[1].appendChild(div);
375
+
376
+ const borderStylePicker = document.createElement('div');
377
+ jSuites.picker(borderStylePicker, {
378
+ type: 'select',
379
+ data: ['solid', 'dotted', 'dashed', 'double'],
380
+ render: function (e) {
381
+ if (e === 'double') {
382
+ return '<div style="width: 30px; border-top: 3px ' + e + ' black;"></div>';
383
+ }
384
+ return '<div style="width: 30px; border-top: 2px ' + e + ' black;"></div>';
385
+ },
386
+ onchange: function (a, k, c, d) {
387
+ b.style = d;
388
+ },
389
+ width: '50px',
390
+ });
391
+ a.children[1].appendChild(borderStylePicker);
392
+
393
+ div = document.createElement('div');
394
+ div.style.flex = '1';
395
+ a.children[1].appendChild(div);
396
+ },
397
+ updateState: function (a, b, toolbarItem) {
398
+ setItemStatus(toolbarItem, getActive());
399
+ },
400
+ });
401
+
402
+ items.push({
403
+ type: 'divisor',
404
+ });
405
+
406
+ items.push({
407
+ content: 'fullscreen',
408
+ tooltip: 'Toggle Fullscreen',
409
+ onclick: function (a, b, c) {
410
+ if (c.children[0].textContent === 'fullscreen') {
411
+ spreadsheet.fullscreen(true);
412
+ c.children[0].textContent = 'fullscreen_exit';
413
+ } else {
414
+ spreadsheet.fullscreen(false);
415
+ c.children[0].textContent = 'fullscreen';
416
+ }
417
+ },
418
+ updateState: function (a, b, c, d) {
419
+ if (d.parent.config.fullscreen === true) {
420
+ c.children[0].textContent = 'fullscreen_exit';
421
+ } else {
422
+ c.children[0].textContent = 'fullscreen';
423
+ }
424
+ },
425
+ });
426
+
427
+ return items;
428
+ };
429
+
430
+ const adjustToolbarSettingsForJSuites = function (toolbar) {
431
+ const spreadsheet = this;
432
+
433
+ const items = toolbar.items;
434
+
435
+ for (let i = 0; i < items.length; i++) {
436
+ // Tooltip
437
+ if (items[i].tooltip) {
438
+ items[i].title = items[i].tooltip;
439
+
440
+ delete items[i].tooltip;
441
+ }
442
+
443
+ if (items[i].type == 'select') {
444
+ if (items[i].options) {
445
+ items[i].data = items[i].options;
446
+ delete items[i].options;
447
+ } else {
448
+ items[i].data = items[i].v;
449
+ delete items[i].v;
450
+
451
+ if (items[i].k && !items[i].onchange) {
452
+ items[i].onchange = function (el, config, value) {
453
+ const worksheet = getWorksheetInstance.call(spreadsheet);
454
+
455
+ const cells = worksheet.getSelected(true);
456
+
457
+ worksheet.setStyle(
458
+ Object.fromEntries(
459
+ cells.map(function (cellName) {
460
+ return [cellName, items[i].k + ': ' + value];
461
+ })
462
+ )
463
+ );
464
+ };
465
+ }
466
+ }
467
+ } else if (items[i].type == 'color') {
468
+ items[i].type = 'i';
469
+
470
+ items[i].onclick = function (a, b, c) {
471
+ if (!c.color) {
472
+ jSuites.color(c, {
473
+ onchange: function (o, v) {
474
+ const worksheet = getWorksheetInstance.call(spreadsheet);
475
+
476
+ const cells = worksheet.getSelected(true);
477
+
478
+ worksheet.setStyle(
479
+ Object.fromEntries(
480
+ cells.map(function (cellName) {
481
+ return [cellName, items[i].k + ': ' + v];
482
+ })
483
+ )
484
+ );
485
+ },
486
+ onopen: function (o) {
487
+ o.color.select('');
488
+ },
489
+ });
490
+
491
+ c.color.open();
492
+ }
493
+ };
494
+ }
495
+ }
496
+ };
497
+
498
+ /**
499
+ * Create toolbar
500
+ */
501
+ export const createToolbar = function (toolbar) {
502
+ const spreadsheet = this;
503
+
504
+ const toolbarElement = document.createElement('div');
505
+ toolbarElement.classList.add('jss_toolbar');
506
+
507
+ adjustToolbarSettingsForJSuites.call(spreadsheet, toolbar);
508
+
509
+ if (typeof spreadsheet.plugins === 'object') {
510
+ Object.entries(spreadsheet.plugins).forEach(function ([, plugin]) {
511
+ if (typeof plugin.toolbar === 'function') {
512
+ const result = plugin.toolbar(toolbar);
513
+
514
+ if (result) {
515
+ toolbar = result;
516
+ }
517
+ }
518
+ });
519
+ }
520
+
521
+ jSuites.toolbar(toolbarElement, toolbar);
522
+
523
+ return toolbarElement;
524
+ };
525
+
526
+ export const updateToolbar = function (worksheet) {
527
+ if (worksheet.parent.toolbar) {
528
+ worksheet.parent.toolbar.toolbar.update(worksheet);
529
+ }
530
+ };
531
+
532
+ export const showToolbar = function () {
533
+ const spreadsheet = this;
534
+
535
+ if (spreadsheet.config.toolbar && !spreadsheet.toolbar) {
536
+ let toolbar;
537
+
538
+ if (Array.isArray(spreadsheet.config.toolbar)) {
539
+ toolbar = {
540
+ items: spreadsheet.config.toolbar,
541
+ };
542
+ } else if (typeof spreadsheet.config.toolbar === 'object') {
543
+ toolbar = spreadsheet.config.toolbar;
544
+ } else {
545
+ toolbar = {
546
+ items: getDefault.call(spreadsheet),
547
+ };
548
+
549
+ if (typeof spreadsheet.config.toolbar === 'function') {
550
+ toolbar = spreadsheet.config.toolbar(toolbar);
551
+ }
552
+ }
553
+
554
+ spreadsheet.toolbar = spreadsheet.element.insertBefore(createToolbar.call(spreadsheet, toolbar), spreadsheet.element.children[1]);
555
+ }
556
+ };
557
+
558
+ export const hideToolbar = function () {
559
+ const spreadsheet = this;
560
+
561
+ if (spreadsheet.toolbar) {
562
+ spreadsheet.toolbar.parentNode.removeChild(spreadsheet.toolbar);
563
+
564
+ delete spreadsheet.toolbar;
565
+ }
566
+ };