@progress/kendo-react-spreadsheet 5.14.0-dev.202305151331

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 (119) hide show
  1. package/LICENSE.md +11 -0
  2. package/NOTICE.txt +117 -0
  3. package/README.md +46 -0
  4. package/about.md +3 -0
  5. package/dist/cdn/js/kendo-react-spreadsheet.js +1 -0
  6. package/dist/es/FormulaInput.d.ts +5 -0
  7. package/dist/es/FormulaInput.js +116 -0
  8. package/dist/es/List.d.ts +5 -0
  9. package/dist/es/List.js +17 -0
  10. package/dist/es/NameBox.d.ts +5 -0
  11. package/dist/es/NameBox.js +88 -0
  12. package/dist/es/SheetsBar.d.ts +5 -0
  13. package/dist/es/SheetsBar.js +233 -0
  14. package/dist/es/Spreadsheet.d.ts +3 -0
  15. package/dist/es/Spreadsheet.js +206 -0
  16. package/dist/es/SpreadsheetProps.d.ts +104 -0
  17. package/dist/es/SpreadsheetProps.js +1 -0
  18. package/dist/es/main.d.ts +3 -0
  19. package/dist/es/main.js +2 -0
  20. package/dist/es/messages.d.ts +76 -0
  21. package/dist/es/messages.js +208 -0
  22. package/dist/es/package-metadata.d.ts +5 -0
  23. package/dist/es/package-metadata.js +11 -0
  24. package/dist/es/tools/align.d.ts +9 -0
  25. package/dist/es/tools/align.js +39 -0
  26. package/dist/es/tools/backgroundColor.d.ts +5 -0
  27. package/dist/es/tools/backgroundColor.js +12 -0
  28. package/dist/es/tools/bold.d.ts +5 -0
  29. package/dist/es/tools/bold.js +5 -0
  30. package/dist/es/tools/defaultTools.d.ts +2 -0
  31. package/dist/es/tools/defaultTools.js +42 -0
  32. package/dist/es/tools/export.d.ts +5 -0
  33. package/dist/es/tools/export.js +16 -0
  34. package/dist/es/tools/fontFamily.d.ts +5 -0
  35. package/dist/es/tools/fontFamily.js +18 -0
  36. package/dist/es/tools/fontSize.d.ts +5 -0
  37. package/dist/es/tools/fontSize.js +20 -0
  38. package/dist/es/tools/format.d.ts +5 -0
  39. package/dist/es/tools/format.js +23 -0
  40. package/dist/es/tools/gridLines.d.ts +6 -0
  41. package/dist/es/tools/gridLines.js +22 -0
  42. package/dist/es/tools/index.d.ts +17 -0
  43. package/dist/es/tools/index.js +17 -0
  44. package/dist/es/tools/italic.d.ts +5 -0
  45. package/dist/es/tools/italic.js +5 -0
  46. package/dist/es/tools/open.d.ts +5 -0
  47. package/dist/es/tools/open.js +33 -0
  48. package/dist/es/tools/redo.d.ts +5 -0
  49. package/dist/es/tools/redo.js +5 -0
  50. package/dist/es/tools/tableTools.d.ts +20 -0
  51. package/dist/es/tools/tableTools.js +72 -0
  52. package/dist/es/tools/textColor.d.ts +5 -0
  53. package/dist/es/tools/textColor.js +12 -0
  54. package/dist/es/tools/textWrap.d.ts +6 -0
  55. package/dist/es/tools/textWrap.js +23 -0
  56. package/dist/es/tools/underline.d.ts +5 -0
  57. package/dist/es/tools/underline.js +5 -0
  58. package/dist/es/tools/undo.d.ts +5 -0
  59. package/dist/es/tools/undo.js +5 -0
  60. package/dist/es/tools/utils.d.ts +79 -0
  61. package/dist/es/tools/utils.js +102 -0
  62. package/dist/npm/FormulaInput.d.ts +5 -0
  63. package/dist/npm/FormulaInput.js +119 -0
  64. package/dist/npm/List.d.ts +5 -0
  65. package/dist/npm/List.js +20 -0
  66. package/dist/npm/NameBox.d.ts +5 -0
  67. package/dist/npm/NameBox.js +91 -0
  68. package/dist/npm/SheetsBar.d.ts +5 -0
  69. package/dist/npm/SheetsBar.js +237 -0
  70. package/dist/npm/Spreadsheet.d.ts +3 -0
  71. package/dist/npm/Spreadsheet.js +209 -0
  72. package/dist/npm/SpreadsheetProps.d.ts +104 -0
  73. package/dist/npm/SpreadsheetProps.js +2 -0
  74. package/dist/npm/main.d.ts +3 -0
  75. package/dist/npm/main.js +20 -0
  76. package/dist/npm/messages.d.ts +76 -0
  77. package/dist/npm/messages.js +211 -0
  78. package/dist/npm/package-metadata.d.ts +5 -0
  79. package/dist/npm/package-metadata.js +14 -0
  80. package/dist/npm/tools/align.d.ts +9 -0
  81. package/dist/npm/tools/align.js +43 -0
  82. package/dist/npm/tools/backgroundColor.d.ts +5 -0
  83. package/dist/npm/tools/backgroundColor.js +15 -0
  84. package/dist/npm/tools/bold.d.ts +5 -0
  85. package/dist/npm/tools/bold.js +8 -0
  86. package/dist/npm/tools/defaultTools.d.ts +2 -0
  87. package/dist/npm/tools/defaultTools.js +45 -0
  88. package/dist/npm/tools/export.d.ts +5 -0
  89. package/dist/npm/tools/export.js +20 -0
  90. package/dist/npm/tools/fontFamily.d.ts +5 -0
  91. package/dist/npm/tools/fontFamily.js +22 -0
  92. package/dist/npm/tools/fontSize.d.ts +5 -0
  93. package/dist/npm/tools/fontSize.js +24 -0
  94. package/dist/npm/tools/format.d.ts +5 -0
  95. package/dist/npm/tools/format.js +27 -0
  96. package/dist/npm/tools/gridLines.d.ts +6 -0
  97. package/dist/npm/tools/gridLines.js +26 -0
  98. package/dist/npm/tools/index.d.ts +17 -0
  99. package/dist/npm/tools/index.js +33 -0
  100. package/dist/npm/tools/italic.d.ts +5 -0
  101. package/dist/npm/tools/italic.js +8 -0
  102. package/dist/npm/tools/open.d.ts +5 -0
  103. package/dist/npm/tools/open.js +37 -0
  104. package/dist/npm/tools/redo.d.ts +5 -0
  105. package/dist/npm/tools/redo.js +8 -0
  106. package/dist/npm/tools/tableTools.d.ts +20 -0
  107. package/dist/npm/tools/tableTools.js +75 -0
  108. package/dist/npm/tools/textColor.d.ts +5 -0
  109. package/dist/npm/tools/textColor.js +15 -0
  110. package/dist/npm/tools/textWrap.d.ts +6 -0
  111. package/dist/npm/tools/textWrap.js +27 -0
  112. package/dist/npm/tools/underline.d.ts +5 -0
  113. package/dist/npm/tools/underline.js +8 -0
  114. package/dist/npm/tools/undo.d.ts +5 -0
  115. package/dist/npm/tools/undo.js +8 -0
  116. package/dist/npm/tools/utils.d.ts +79 -0
  117. package/dist/npm/tools/utils.js +108 -0
  118. package/dist/systemjs/kendo-react-spreadsheet.js +1 -0
  119. package/package.json +78 -0
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export declare const FormulaInput: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
@@ -0,0 +1,116 @@
1
+ import * as React from 'react';
2
+ import { Popup } from '@progress/kendo-react-popup';
3
+ import { List } from './List';
4
+ import { classNames } from '@progress/kendo-react-common';
5
+ /**
6
+ * @hidden
7
+ */
8
+ export const FormulaInput = React.forwardRef((props, ref) => {
9
+ const [showPopup, setShowPopup] = React.useState(false);
10
+ const [popupContentKey, setPopupContentKey] = React.useState(0);
11
+ const [data, setData] = React.useState([]);
12
+ const memo = React.useMemo(() => ({}), []);
13
+ memo.showPopup = showPopup;
14
+ memo.popupContentKey = popupContentKey;
15
+ memo.data = data;
16
+ const target = React.useRef(null);
17
+ const elementRef = React.useRef(null);
18
+ const listRef = React.useRef(null);
19
+ const focusedItem = React.useCallback(() => {
20
+ if (listRef.current && listRef.current.element) {
21
+ return listRef.current.element.querySelector('.k-focus');
22
+ }
23
+ }, []);
24
+ const unfocus = React.useCallback(() => {
25
+ const focused = focusedItem();
26
+ if (focused) {
27
+ focused.classList.remove('k-focus');
28
+ }
29
+ }, []);
30
+ const focusNext = React.useCallback((dir) => {
31
+ const items = Array.from((listRef.current && listRef.current.element.children) || []);
32
+ const focused = focusedItem();
33
+ let next;
34
+ if (focused) {
35
+ const index = items.indexOf(focused);
36
+ focused.classList.remove('k-focus');
37
+ next = items[index + dir] ? items[index + dir] : (dir === 1 ? items[0] : items[items.length - 1]);
38
+ }
39
+ else {
40
+ next = (dir === 1 ? items[0] : items[items.length - 1]);
41
+ }
42
+ if (next) {
43
+ next.classList.add('k-focus');
44
+ }
45
+ }, []);
46
+ React.useImperativeHandle(target, () => ({
47
+ element: elementRef.current,
48
+ props,
49
+ popup: {
50
+ open: () => {
51
+ setShowPopup(true);
52
+ },
53
+ close: () => {
54
+ setShowPopup(false);
55
+ },
56
+ position: () => {
57
+ setPopupContentKey(memo.popupContentKey + 1);
58
+ },
59
+ visible: () => {
60
+ return memo.showPopup;
61
+ }
62
+ },
63
+ list: {
64
+ get element() { return listRef.current && listRef.current.element; },
65
+ data: (d) => {
66
+ if (d) {
67
+ setData(d);
68
+ }
69
+ else {
70
+ return memo.data;
71
+ }
72
+ },
73
+ value: () => { return {}; },
74
+ focus: () => {
75
+ const items = Array.from((listRef.current && listRef.current.element && listRef.current.element.children) || []);
76
+ return items.indexOf(focusedItem());
77
+ },
78
+ // select: (x) => {
79
+ // console.log('select', x);
80
+ // },
81
+ focusNext: () => {
82
+ focusNext(1);
83
+ },
84
+ focusPrev: () => {
85
+ focusNext(-1);
86
+ },
87
+ focusFirst: () => {
88
+ const list = listRef.current && listRef.current.element;
89
+ if (list && list.children.item(0)) {
90
+ unfocus();
91
+ list.children.item(0).classList.add('k-focus');
92
+ }
93
+ },
94
+ focusLast: () => {
95
+ const list = listRef.current && listRef.current.element;
96
+ if (list && list.children.length) {
97
+ unfocus();
98
+ list.children.item(list.children.length - 1).classList.add('k-focus');
99
+ }
100
+ },
101
+ itemClick: (handler) => { memo.itemClick = handler; }
102
+ }
103
+ }), []);
104
+ React.useImperativeHandle(ref, () => target.current, []);
105
+ const onItemClick = React.useCallback((value) => {
106
+ if (memo.itemClick) {
107
+ memo.itemClick(value);
108
+ }
109
+ }, []);
110
+ return (React.createElement(React.Fragment, null,
111
+ React.createElement("div", { className: classNames('k-spreadsheet-formula-input', props.className), contentEditable: "true", spellCheck: "false", style: { whiteSpace: 'pre' }, ref: elementRef }),
112
+ React.createElement(Popup, { show: showPopup, anchor: elementRef.current, animate: { openDuration: 100, closeDuration: 100 }, contentKey: popupContentKey },
113
+ React.createElement(List, { data: data, ref: listRef, onItemClick: onItemClick }))));
114
+ });
115
+ FormulaInput.displayName = 'FormulaInput';
116
+ FormulaInput.propTypes = {};
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export declare const List: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
@@ -0,0 +1,17 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export const List = React.forwardRef((props, ref) => {
6
+ const target = React.useRef(null);
7
+ const ulRef = React.useRef(null);
8
+ React.useImperativeHandle(target, () => ({
9
+ element: ulRef.current,
10
+ props
11
+ }));
12
+ React.useImperativeHandle(ref, () => target.current);
13
+ return (React.createElement("ul", { ref: ulRef, className: "k-spreadsheet-formula-list k-list-ul k-popup k-group k-reset", onMouseDown: e => e.preventDefault() }, props.data.map((item) => (React.createElement("li", { key: item.text, className: "k-list-item", onClick: () => props.onItemClick(item.value) },
14
+ React.createElement("span", { className: "k-list-item-text" }, item.text))))));
15
+ });
16
+ List.displayName = 'List';
17
+ List.propTypes = {};
@@ -0,0 +1,5 @@
1
+ import * as React from 'react';
2
+ /**
3
+ * @hidden
4
+ */
5
+ export declare const NameBox: React.ForwardRefExoticComponent<Omit<any, "ref"> & React.RefAttributes<any>>;
@@ -0,0 +1,88 @@
1
+ import * as React from 'react';
2
+ import { ComboBox } from '@progress/kendo-react-dropdowns';
3
+ import { IconWrap } from '@progress/kendo-react-common';
4
+ import { xIcon } from '@progress/kendo-svg-icons';
5
+ import { useLocalization } from '@progress/kendo-react-intl';
6
+ import { keys, messages } from './messages';
7
+ /**
8
+ * @hidden
9
+ */
10
+ export const NameBox = React.forwardRef((props, ref) => {
11
+ const target = React.useRef(null);
12
+ const comboboxRef = React.useRef(null);
13
+ const [data, setData] = React.useState([]);
14
+ const [open, setOpen] = React.useState(false);
15
+ const [value, setValue] = React.useState('');
16
+ const memo = React.useMemo(() => ({}), []);
17
+ memo.data = data;
18
+ React.useImperativeHandle(target, () => ({
19
+ value: (val) => {
20
+ if (val === undefined) {
21
+ const item = comboboxRef.current && comboboxRef.current.value;
22
+ return item ? (item.name || item) : item;
23
+ }
24
+ else {
25
+ setValue(val || '');
26
+ }
27
+ }
28
+ }), []);
29
+ React.useImperativeHandle(ref, () => target.current, []);
30
+ const onDelete = React.useCallback((name) => {
31
+ const editor = props.nameEditor();
32
+ if (editor) {
33
+ editor.trigger('delete', { name });
34
+ }
35
+ }, []);
36
+ const itemRender = React.useCallback((li, itemProps) => {
37
+ const itemChildren = (React.createElement(React.Fragment, null,
38
+ li.props.children,
39
+ React.createElement("span", { role: 'button', className: 'k-button-delete', onClick: () => onDelete(itemProps.dataItem[itemProps.textField]), onMouseDown: e => e.preventDefault(), onPointerDown: e => e.preventDefault(), "data-role": "delete" },
40
+ React.createElement(IconWrap, { name: 'x', icon: xIcon }))));
41
+ return React.cloneElement(li, li.props, itemChildren);
42
+ }, []);
43
+ const listNoDataRender = React.useCallback((el) => React.cloneElement(el, Object.assign({}, el.props), React.createElement("div", null)), []);
44
+ const onOpen = React.useCallback((event) => {
45
+ if (event.syntheticEvent && event.syntheticEvent.type === 'change') {
46
+ return;
47
+ }
48
+ const editor = props.nameEditor();
49
+ if (editor) {
50
+ setData(editor.readData());
51
+ setOpen(true);
52
+ }
53
+ }, []);
54
+ const onClose = React.useCallback(() => {
55
+ setOpen(false);
56
+ }, []);
57
+ const onChange = React.useCallback((event) => {
58
+ if (event.syntheticEvent.target.closest('[data-role]')) {
59
+ return;
60
+ }
61
+ const editor = props.nameEditor();
62
+ if (editor && event.value) {
63
+ editor.trigger('select', { name: event.value.name });
64
+ setValue(event.value.name);
65
+ }
66
+ }, []);
67
+ const onKeyDown = React.useCallback((event) => {
68
+ const editor = props.nameEditor();
69
+ if (editor) {
70
+ if (event.key === 'Enter') {
71
+ const name = event.target.value;
72
+ editor.trigger('enter', { value: name });
73
+ setValue(name);
74
+ }
75
+ else if (event.key === 'Escape') {
76
+ editor.trigger('cancel');
77
+ setValue(memo.prevValue);
78
+ }
79
+ }
80
+ }, []);
81
+ const onFocus = React.useCallback((event) => {
82
+ memo.prevValue = event.value.name;
83
+ }, []);
84
+ return (React.createElement("div", { className: "k-spreadsheet-name-editor", onKeyDown: onKeyDown },
85
+ React.createElement(ComboBox, { ref: comboboxRef, title: useLocalization().toLanguageString(keys.nameBox, messages[keys.nameBox]), popupSettings: { className: 'k-spreadsheet-names-popup' }, clearButton: false, dataItemKey: "name", textField: "name", itemRender: itemRender, data: data, value: value ? (data.find((d) => d.name === name) || { name: value }) : null, onChange: onChange, opened: open, onOpen: onOpen, onClose: onClose, onFocus: onFocus, listNoDataRender: listNoDataRender, allowCustom: true })));
86
+ });
87
+ NameBox.displayName = 'NameBox';
88
+ NameBox.propTypes = {};
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ /**
3
+ * @hidden
4
+ */
5
+ export declare const SheetsBar: (props: any) => JSX.Element;
@@ -0,0 +1,233 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import * as React from 'react';
13
+ import { Button } from '@progress/kendo-react-buttons';
14
+ import { IconWrap, classNames, guid } from '@progress/kendo-react-common';
15
+ import { Sortable } from '@progress/kendo-react-sortable';
16
+ import { xIcon, plusIcon } from '@progress/kendo-svg-icons';
17
+ import { useLocalization } from '@progress/kendo-react-intl';
18
+ import { keys, messages } from './messages';
19
+ const contextDefaultValue = {
20
+ onSelect: (() => { }),
21
+ onDelete: (() => { }),
22
+ onEnterEdit: (() => { }),
23
+ onCancelEdit: (() => { }),
24
+ onExitEdit: (() => { }),
25
+ onEdit: (() => { })
26
+ };
27
+ const ItemsContext = React.createContext(contextDefaultValue);
28
+ const TabItem = (props) => {
29
+ const dataItem = props.dataItem;
30
+ const { onSelect, onDelete, onEnterEdit, onExitEdit, onCancelEdit, onEdit } = React.useContext(ItemsContext);
31
+ const onClick = React.useCallback((e) => {
32
+ if (e.target instanceof HTMLElement && e.target.nodeName === 'INPUT') {
33
+ return;
34
+ }
35
+ onSelect.call(undefined, dataItem, e);
36
+ }, [dataItem, onSelect]);
37
+ const onClickDelete = React.useCallback((e) => {
38
+ onDelete.call(undefined, dataItem, e);
39
+ }, [dataItem, onDelete]);
40
+ const onDoubleClick = React.useCallback((e) => {
41
+ if (e.target instanceof HTMLElement && e.target.nodeName === 'INPUT') {
42
+ return;
43
+ }
44
+ onEnterEdit.call(undefined, dataItem, e);
45
+ }, [dataItem, onEnterEdit]);
46
+ const onInputBlur = React.useCallback((e) => {
47
+ onExitEdit.call(undefined, dataItem, e);
48
+ }, [dataItem, onExitEdit]);
49
+ const onInputKeyDown = React.useCallback((e) => {
50
+ if (e.key === 'Enter') {
51
+ onExitEdit.call(undefined, dataItem, e);
52
+ }
53
+ else if (e.key === 'Escape') {
54
+ onCancelEdit.call(undefined, dataItem, e);
55
+ }
56
+ }, [dataItem, onExitEdit, onCancelEdit]);
57
+ const onInputChange = React.useCallback((e) => {
58
+ onEdit.call(undefined, Object.assign(Object.assign({}, dataItem), { text: e.target.value }), e);
59
+ }, [dataItem, onEdit]);
60
+ return (React.createElement("li", Object.assign({ style: props.style }, props.attributes, { ref: props.forwardRef, role: 'tab', className: classNames('k-item k-tabstrip-item', {
61
+ 'k-disabled': props.isDisabled,
62
+ 'k-active k-state-tab-on-top k-spreadsheet-sheets-bar-active': dataItem.active,
63
+ 'k-spreadsheet-sheets-bar-inactive': !dataItem.active,
64
+ 'k-first': dataItem.first,
65
+ 'k-last': dataItem.last
66
+ }), onClick: onClick, onDoubleClick: onDoubleClick }), dataItem.inEdit ? (React.createElement("input", { type: 'text', className: 'k-textbox k-spreadsheet-sheets-editor', value: dataItem.text, onChange: onInputChange, maxLength: 50, autoFocus: true, onBlur: onInputBlur, onKeyDown: onInputKeyDown })) : (React.createElement(React.Fragment, null,
67
+ React.createElement("span", { className: 'k-link' }, dataItem.text),
68
+ (dataItem.first && dataItem.last) ? null :
69
+ React.createElement("span", { className: "k-link k-spreadsheet-sheets-remove", onClick: onClickDelete },
70
+ React.createElement(IconWrap, { name: "x", icon: xIcon }))))));
71
+ };
72
+ const TabsList = React.forwardRef((props, ref) => {
73
+ const { children, className } = props, restProps = __rest(props, ["children", "className"]);
74
+ return (React.createElement("ul", Object.assign({ className: classNames('k-tabstrip-items k-reset', className), role: 'tablist' }, restProps, { ref: ref }), children));
75
+ });
76
+ TabsList.displayName = 'TabsList';
77
+ const Tabs = (props) => {
78
+ const { sheets, setSheets, onSheetSelect, onSheetDelete, onSheetEdit, onSheetReorderEnd } = props;
79
+ const [inEditItem, setInEditItem] = React.useState(null);
80
+ const dragging = React.useRef(false);
81
+ const prevIndex = React.useRef(-1);
82
+ const updateData = React.useCallback((d) => {
83
+ setSheets(d.map((item, index, array) => (Object.assign(Object.assign({}, item), { first: index === 0, last: index === array.length - 1 }))));
84
+ }, []);
85
+ const onDragOver = React.useCallback((event) => {
86
+ updateData(event.newState);
87
+ // const { prevIndex, nextIndex } = event;
88
+ }, [updateData, onSheetReorderEnd]);
89
+ const onNavigate = React.useCallback((event) => {
90
+ onSheetReorderEnd.call(undefined, event);
91
+ }, [onSheetReorderEnd]);
92
+ const onDragStart = React.useCallback((e) => {
93
+ dragging.current = true;
94
+ prevIndex.current = e.prevIndex;
95
+ }, []);
96
+ const onDragEnd = React.useCallback((event) => {
97
+ setTimeout(() => {
98
+ dragging.current = false;
99
+ }, 50);
100
+ onSheetReorderEnd.call(undefined, Object.assign(Object.assign({}, event), { prevIndex: prevIndex.current }));
101
+ }, []);
102
+ const onSelect = React.useCallback((dataItem, e) => {
103
+ if (!dragging.current) {
104
+ onSheetSelect.call(undefined, dataItem, e);
105
+ }
106
+ }, [onSheetSelect]);
107
+ const onDelete = React.useCallback((dataItem, e) => {
108
+ e.stopPropagation();
109
+ onSheetDelete.call(undefined, dataItem);
110
+ }, [sheets, onSheetDelete]);
111
+ const onEnterEdit = React.useCallback((dataItem, e) => {
112
+ e.stopPropagation();
113
+ e.preventDefault();
114
+ const newData = sheets.map((item) => (Object.assign(Object.assign({}, item), { active: item.id === dataItem.id, inEdit: item.id === dataItem.id })));
115
+ setSheets(newData);
116
+ setInEditItem(Object.assign({}, dataItem));
117
+ }, [sheets]);
118
+ const onCancelEdit = React.useCallback((_dataItem, e) => {
119
+ e.stopPropagation();
120
+ e.preventDefault();
121
+ const newData = sheets.map((item) => (Object.assign(Object.assign({}, item), { inEdit: false, text: item.inEdit && inEditItem ? inEditItem.text : item.text })));
122
+ setSheets(newData);
123
+ setInEditItem(null);
124
+ }, [sheets, inEditItem]);
125
+ const onExitEdit = React.useCallback((dataItem, e) => {
126
+ e.stopPropagation();
127
+ e.preventDefault();
128
+ const newData = sheets.map((item) => (Object.assign(Object.assign({}, item), { inEdit: false })));
129
+ const index = sheets.findIndex((i) => i.id === dataItem.id);
130
+ setSheets(newData);
131
+ setInEditItem(null);
132
+ onSheetEdit.call(undefined, dataItem, index);
133
+ }, [sheets, onSheetEdit]);
134
+ const onEdit = React.useCallback((dataItem, e) => {
135
+ e.stopPropagation();
136
+ e.preventDefault();
137
+ const newData = sheets.map((item) => (Object.assign(Object.assign({}, item), { text: dataItem.id === item.id ? dataItem.text : item.text })));
138
+ setSheets(newData);
139
+ }, [sheets]);
140
+ return (React.createElement("div", { className: 'k-spreadsheet-sheets-items k-tabstrip k-floatwrap k-tabstrip-bottom' },
141
+ React.createElement("div", { className: 'k-tabstrip-items-wrapper k-hstack' },
142
+ React.createElement(ItemsContext.Provider, { value: { onSelect, onDelete, onEnterEdit, onCancelEdit, onExitEdit, onEdit } },
143
+ React.createElement(Sortable, { idField: 'id', data: sheets, itemUI: TabItem, itemsWrapUI: TabsList, onDragOver: onDragOver, onNavigate: onNavigate, onDragStart: onDragStart, onDragEnd: onDragEnd })))));
144
+ };
145
+ const mapSheets = (sheets, active) => sheets.map((sheet, i, arr) => ({
146
+ text: sheet.name(),
147
+ id: guid(),
148
+ first: i === 0,
149
+ last: i === arr.length - 1,
150
+ active: sheet.name() === active
151
+ }));
152
+ /**
153
+ * @hidden
154
+ */
155
+ export const SheetsBar = (props) => {
156
+ const { spreadsheetRef } = props;
157
+ const [sheets, setSheets] = React.useState([]);
158
+ const activeSheet = React.useRef((sheets.find((s) => s.active) || {}).text);
159
+ const selectActiveSheet = React.useCallback(() => {
160
+ if (spreadsheetRef.current) {
161
+ spreadsheetRef.current.view.sheetsbar.onSheetSelect(activeSheet.current);
162
+ setSheets(mapSheets(spreadsheetRef.current.sheets(), activeSheet.current));
163
+ }
164
+ }, []);
165
+ const onUpdate = React.useCallback(() => {
166
+ if (spreadsheetRef.current) {
167
+ const sh = spreadsheetRef.current.sheets();
168
+ if (!sh.find((s) => s.name() === activeSheet.current)) {
169
+ activeSheet.current = sh[sh.length - 1].name();
170
+ }
171
+ selectActiveSheet();
172
+ }
173
+ }, []);
174
+ React.useEffect(() => {
175
+ if (spreadsheetRef.current) {
176
+ activeSheet.current = spreadsheetRef.current.sheets()[0].name();
177
+ selectActiveSheet();
178
+ spreadsheetRef.current.view.bind('update', onUpdate);
179
+ }
180
+ return () => {
181
+ if (spreadsheetRef.current) {
182
+ spreadsheetRef.current.view.unbind('update', onUpdate);
183
+ }
184
+ };
185
+ }, [spreadsheetRef.current]);
186
+ const onSelect = React.useCallback((dataItem) => {
187
+ if (activeSheet.current !== dataItem.text) {
188
+ activeSheet.current = dataItem.text;
189
+ selectActiveSheet();
190
+ }
191
+ }, []);
192
+ const onAddSheet = React.useCallback(() => {
193
+ if (spreadsheetRef.current) {
194
+ spreadsheetRef.current.view.sheetsbar.onAddSelect();
195
+ const spSheets = spreadsheetRef.current.sheets();
196
+ activeSheet.current = spSheets[spSheets.length - 1].name();
197
+ selectActiveSheet();
198
+ }
199
+ }, []);
200
+ const onSheetDelete = React.useCallback((dataItem) => {
201
+ if (spreadsheetRef.current) {
202
+ if (activeSheet.current === dataItem.text) {
203
+ const curSheets = spreadsheetRef.current.sheets();
204
+ const index = curSheets.findIndex((s) => s.name() === dataItem.text);
205
+ const active = curSheets[index + 1] || curSheets[index - 1];
206
+ activeSheet.current = active ? active.name() : '';
207
+ }
208
+ spreadsheetRef.current.view.sheetsbar.onSheetRemove(dataItem.text);
209
+ selectActiveSheet();
210
+ }
211
+ }, []);
212
+ const onSheetRename = React.useCallback((dataItem, index) => {
213
+ if (spreadsheetRef.current) {
214
+ let text = dataItem.text;
215
+ const curSheets = spreadsheetRef.current.sheets();
216
+ if (!text || curSheets.find((s) => s.name() === text)) {
217
+ text = curSheets[index].name();
218
+ }
219
+ spreadsheetRef.current.view.sheetsbar.onSheetRename(text, index);
220
+ activeSheet.current = text;
221
+ selectActiveSheet();
222
+ }
223
+ }, []);
224
+ const onSheetReorderEnd = React.useCallback((event) => {
225
+ if (spreadsheetRef.current) {
226
+ const { prevIndex, nextIndex } = event;
227
+ spreadsheetRef.current.view.sheetsbar.onSheetReorderEnd({ oldIndex: prevIndex, newIndex: nextIndex });
228
+ }
229
+ }, []);
230
+ return (React.createElement("div", { className: "k-spreadsheet-sheets-bar" },
231
+ React.createElement(Button, { fillMode: "flat", icon: "plus", title: useLocalization().toLanguageString(keys.addNewSheet, messages[keys.addNewSheet]), svgIcon: plusIcon, onClick: onAddSheet }),
232
+ React.createElement(Tabs, { sheets: sheets, setSheets: setSheets, onSheetSelect: onSelect, onSheetDelete: onSheetDelete, onSheetEdit: onSheetRename, onSheetReorderEnd: onSheetReorderEnd })));
233
+ };
@@ -0,0 +1,3 @@
1
+ import * as React from 'react';
2
+ import { SpreadsheetProps, SpreadsheetHandle } from './SpreadsheetProps';
3
+ export declare const Spreadsheet: React.ForwardRefExoticComponent<SpreadsheetProps & React.RefAttributes<SpreadsheetHandle | null>>;