@progress/kendo-react-spreadsheet 6.1.1-dev.202311151536 → 7.0.0-develop.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 (147) hide show
  1. package/FormulaInput.d.ts +9 -0
  2. package/LICENSE.md +1 -1
  3. package/List.d.ts +9 -0
  4. package/NameBox.d.ts +9 -0
  5. package/SheetsBar.d.ts +8 -0
  6. package/{dist/npm/Spreadsheet.d.ts → Spreadsheet.d.ts} +4 -0
  7. package/{dist/npm/SpreadsheetProps.d.ts → SpreadsheetProps.d.ts} +5 -2
  8. package/dist/cdn/js/kendo-react-spreadsheet.js +5 -1
  9. package/index.d.ts +8 -0
  10. package/index.js +5 -0
  11. package/index.mjs +1357 -0
  12. package/{dist/npm/messages.d.ts → messages.d.ts} +4 -0
  13. package/package-metadata.d.ts +9 -0
  14. package/package.json +43 -57
  15. package/{dist/npm/tools → tools}/adjustDecimals.d.ts +4 -0
  16. package/{dist/npm/tools → tools}/align.d.ts +4 -0
  17. package/tools/backgroundColor.d.ts +14 -0
  18. package/tools/bold.d.ts +14 -0
  19. package/tools/cleanFormat.d.ts +15 -0
  20. package/tools/defaultTools.d.ts +9 -0
  21. package/tools/export.d.ts +15 -0
  22. package/tools/fontFamily.d.ts +15 -0
  23. package/{dist/es/tools → tools}/fontSize.d.ts +4 -0
  24. package/tools/format.d.ts +15 -0
  25. package/{dist/es/tools → tools}/gridLines.d.ts +4 -0
  26. package/{dist/es/tools → tools}/index.d.ts +5 -1
  27. package/tools/italic.d.ts +14 -0
  28. package/tools/open.d.ts +15 -0
  29. package/tools/redo.d.ts +14 -0
  30. package/{dist/npm/tools → tools}/tableTools.d.ts +4 -0
  31. package/tools/textColor.d.ts +14 -0
  32. package/{dist/es/tools → tools}/textWrap.d.ts +4 -0
  33. package/tools/underline.d.ts +14 -0
  34. package/tools/undo.d.ts +14 -0
  35. package/{dist/npm/tools → tools}/utils.d.ts +4 -0
  36. package/about.md +0 -3
  37. package/dist/es/FormulaInput.d.ts +0 -5
  38. package/dist/es/FormulaInput.js +0 -116
  39. package/dist/es/List.d.ts +0 -5
  40. package/dist/es/List.js +0 -22
  41. package/dist/es/NameBox.d.ts +0 -5
  42. package/dist/es/NameBox.js +0 -91
  43. package/dist/es/SheetsBar.d.ts +0 -5
  44. package/dist/es/SheetsBar.js +0 -246
  45. package/dist/es/Spreadsheet.d.ts +0 -47
  46. package/dist/es/Spreadsheet.js +0 -286
  47. package/dist/es/SpreadsheetProps.d.ts +0 -189
  48. package/dist/es/SpreadsheetProps.js +0 -2
  49. package/dist/es/main.d.ts +0 -4
  50. package/dist/es/main.js +0 -4
  51. package/dist/es/messages.d.ts +0 -110
  52. package/dist/es/messages.js +0 -310
  53. package/dist/es/package-metadata.d.ts +0 -5
  54. package/dist/es/package-metadata.js +0 -11
  55. package/dist/es/tools/adjustDecimals.d.ts +0 -20
  56. package/dist/es/tools/adjustDecimals.js +0 -39
  57. package/dist/es/tools/align.d.ts +0 -44
  58. package/dist/es/tools/align.js +0 -96
  59. package/dist/es/tools/backgroundColor.d.ts +0 -11
  60. package/dist/es/tools/backgroundColor.js +0 -15
  61. package/dist/es/tools/bold.d.ts +0 -11
  62. package/dist/es/tools/bold.js +0 -9
  63. package/dist/es/tools/cleanFormat.d.ts +0 -11
  64. package/dist/es/tools/cleanFormat.js +0 -17
  65. package/dist/es/tools/defaultTools.d.ts +0 -5
  66. package/dist/es/tools/defaultTools.js +0 -66
  67. package/dist/es/tools/export.d.ts +0 -11
  68. package/dist/es/tools/export.js +0 -19
  69. package/dist/es/tools/fontFamily.d.ts +0 -11
  70. package/dist/es/tools/fontFamily.js +0 -21
  71. package/dist/es/tools/fontSize.js +0 -82
  72. package/dist/es/tools/format.d.ts +0 -11
  73. package/dist/es/tools/format.js +0 -26
  74. package/dist/es/tools/gridLines.js +0 -25
  75. package/dist/es/tools/index.js +0 -18
  76. package/dist/es/tools/italic.d.ts +0 -11
  77. package/dist/es/tools/italic.js +0 -9
  78. package/dist/es/tools/open.d.ts +0 -11
  79. package/dist/es/tools/open.js +0 -36
  80. package/dist/es/tools/redo.d.ts +0 -11
  81. package/dist/es/tools/redo.js +0 -9
  82. package/dist/es/tools/tableTools.d.ts +0 -64
  83. package/dist/es/tools/tableTools.js +0 -102
  84. package/dist/es/tools/textColor.d.ts +0 -11
  85. package/dist/es/tools/textColor.js +0 -15
  86. package/dist/es/tools/textWrap.js +0 -26
  87. package/dist/es/tools/underline.d.ts +0 -11
  88. package/dist/es/tools/underline.js +0 -9
  89. package/dist/es/tools/undo.d.ts +0 -11
  90. package/dist/es/tools/undo.js +0 -9
  91. package/dist/es/tools/utils.d.ts +0 -91
  92. package/dist/es/tools/utils.js +0 -102
  93. package/dist/npm/FormulaInput.d.ts +0 -5
  94. package/dist/npm/FormulaInput.js +0 -119
  95. package/dist/npm/List.d.ts +0 -5
  96. package/dist/npm/List.js +0 -25
  97. package/dist/npm/NameBox.d.ts +0 -5
  98. package/dist/npm/NameBox.js +0 -94
  99. package/dist/npm/SheetsBar.d.ts +0 -5
  100. package/dist/npm/SheetsBar.js +0 -250
  101. package/dist/npm/Spreadsheet.js +0 -289
  102. package/dist/npm/SpreadsheetProps.js +0 -9
  103. package/dist/npm/main.d.ts +0 -4
  104. package/dist/npm/main.js +0 -39
  105. package/dist/npm/messages.js +0 -313
  106. package/dist/npm/package-metadata.d.ts +0 -5
  107. package/dist/npm/package-metadata.js +0 -14
  108. package/dist/npm/tools/adjustDecimals.js +0 -42
  109. package/dist/npm/tools/align.js +0 -100
  110. package/dist/npm/tools/backgroundColor.d.ts +0 -11
  111. package/dist/npm/tools/backgroundColor.js +0 -18
  112. package/dist/npm/tools/bold.d.ts +0 -11
  113. package/dist/npm/tools/bold.js +0 -12
  114. package/dist/npm/tools/cleanFormat.d.ts +0 -11
  115. package/dist/npm/tools/cleanFormat.js +0 -21
  116. package/dist/npm/tools/defaultTools.d.ts +0 -5
  117. package/dist/npm/tools/defaultTools.js +0 -69
  118. package/dist/npm/tools/export.d.ts +0 -11
  119. package/dist/npm/tools/export.js +0 -23
  120. package/dist/npm/tools/fontFamily.d.ts +0 -11
  121. package/dist/npm/tools/fontFamily.js +0 -25
  122. package/dist/npm/tools/fontSize.d.ts +0 -39
  123. package/dist/npm/tools/fontSize.js +0 -86
  124. package/dist/npm/tools/format.d.ts +0 -11
  125. package/dist/npm/tools/format.js +0 -30
  126. package/dist/npm/tools/gridLines.d.ts +0 -15
  127. package/dist/npm/tools/gridLines.js +0 -29
  128. package/dist/npm/tools/index.d.ts +0 -19
  129. package/dist/npm/tools/index.js +0 -34
  130. package/dist/npm/tools/italic.d.ts +0 -11
  131. package/dist/npm/tools/italic.js +0 -12
  132. package/dist/npm/tools/open.d.ts +0 -11
  133. package/dist/npm/tools/open.js +0 -40
  134. package/dist/npm/tools/redo.d.ts +0 -11
  135. package/dist/npm/tools/redo.js +0 -12
  136. package/dist/npm/tools/tableTools.js +0 -105
  137. package/dist/npm/tools/textColor.d.ts +0 -11
  138. package/dist/npm/tools/textColor.js +0 -18
  139. package/dist/npm/tools/textWrap.d.ts +0 -15
  140. package/dist/npm/tools/textWrap.js +0 -30
  141. package/dist/npm/tools/underline.d.ts +0 -11
  142. package/dist/npm/tools/underline.js +0 -12
  143. package/dist/npm/tools/undo.d.ts +0 -11
  144. package/dist/npm/tools/undo.js +0 -12
  145. package/dist/npm/tools/utils.js +0 -108
  146. package/dist/systemjs/kendo-react-spreadsheet.js +0 -1
  147. package/e2e-next/basic.tests.ts +0 -24
@@ -1,91 +0,0 @@
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
- const name = event.value.name;
64
- if (name !== value) {
65
- editor.trigger('select', { name });
66
- setValue(name);
67
- }
68
- }
69
- }, [value]);
70
- const onKeyDown = React.useCallback((event) => {
71
- const editor = props.nameEditor();
72
- if (editor) {
73
- if (event.key === 'Enter') {
74
- const name = event.target.value;
75
- editor.trigger('enter', { value: name });
76
- setValue(name);
77
- }
78
- else if (event.key === 'Escape') {
79
- editor.trigger('cancel');
80
- setValue(memo.prevValue);
81
- }
82
- }
83
- }, []);
84
- const onFocus = React.useCallback((event) => {
85
- memo.prevValue = event.value.name;
86
- }, []);
87
- return (React.createElement("div", { className: "k-spreadsheet-name-editor", onKeyDown: onKeyDown },
88
- React.createElement(ComboBox, { ref: comboboxRef, title: useLocalization().toLanguageString(keys.nameBox, messages[keys.nameBox]), popupSettings: { className: 'k-spreadsheet-names-popup' }, fillMode: "flat", 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 })));
89
- });
90
- NameBox.displayName = 'NameBox';
91
- NameBox.propTypes = {};
@@ -1,5 +0,0 @@
1
- /// <reference types="react" />
2
- /**
3
- * @hidden
4
- */
5
- export declare const SheetsBar: (props: any) => JSX.Element;
@@ -1,246 +0,0 @@
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
- if (spreadsheetRef.current.sheets().length) {
177
- activeSheet.current = spreadsheetRef.current.sheets()[0].name();
178
- selectActiveSheet();
179
- }
180
- spreadsheetRef.current.view.bind('update', onUpdate);
181
- }
182
- return () => {
183
- if (spreadsheetRef.current) {
184
- spreadsheetRef.current.view.unbind('update', onUpdate);
185
- }
186
- };
187
- }, [spreadsheetRef.current]);
188
- const onSelect = React.useCallback((dataItem) => {
189
- if (activeSheet.current !== dataItem.text) {
190
- activeSheet.current = dataItem.text;
191
- selectActiveSheet();
192
- }
193
- }, []);
194
- const onAddSheet = React.useCallback(() => {
195
- if (spreadsheetRef.current) {
196
- spreadsheetRef.current.view.sheetsbar.onAddSelect();
197
- const spSheets = spreadsheetRef.current.sheets();
198
- activeSheet.current = spSheets[spSheets.length - 1].name();
199
- selectActiveSheet();
200
- }
201
- }, []);
202
- const onSheetDelete = React.useCallback((dataItem) => {
203
- if (spreadsheetRef.current) {
204
- if (activeSheet.current === dataItem.text) {
205
- const curSheets = spreadsheetRef.current.sheets();
206
- const index = curSheets.findIndex((s) => s.name() === dataItem.text);
207
- const active = curSheets[index + 1] || curSheets[index - 1];
208
- activeSheet.current = active ? active.name() : '';
209
- }
210
- spreadsheetRef.current.view.sheetsbar.onSheetRemove(dataItem.text);
211
- selectActiveSheet();
212
- }
213
- }, []);
214
- const onSheetRename = React.useCallback((dataItem, index) => {
215
- if (spreadsheetRef.current) {
216
- let text = dataItem.text;
217
- const curSheets = spreadsheetRef.current.sheets();
218
- const active = curSheets[index];
219
- if (!text) {
220
- activeSheet.current = active.name();
221
- selectActiveSheet();
222
- return;
223
- }
224
- if (active && active.name() === text) {
225
- return;
226
- }
227
- if (curSheets.find((s) => s.name() === text)) {
228
- text = active.name();
229
- }
230
- spreadsheetRef.current.view.sheetsbar.onSheetRename(text, index);
231
- activeSheet.current = text;
232
- selectActiveSheet();
233
- }
234
- }, []);
235
- const onSheetReorderEnd = React.useCallback((event) => {
236
- if (spreadsheetRef.current) {
237
- const { prevIndex, nextIndex } = event;
238
- activeSheet.current = spreadsheetRef.current.sheets()[prevIndex].name();
239
- spreadsheetRef.current.view.sheetsbar.onSheetReorderEnd({ oldIndex: prevIndex, newIndex: nextIndex });
240
- selectActiveSheet();
241
- }
242
- }, []);
243
- return (React.createElement("div", { className: "k-spreadsheet-sheets-bar k-header" },
244
- React.createElement(Button, { fillMode: "flat", icon: "plus", className: "k-spreadsheet-sheets-bar-add", title: useLocalization().toLanguageString(keys.addNewSheet, messages[keys.addNewSheet]), svgIcon: plusIcon, onClick: onAddSheet }),
245
- React.createElement(Tabs, { sheets: sheets, setSheets: setSheets, onSheetSelect: onSelect, onSheetDelete: onSheetDelete, onSheetEdit: onSheetRename, onSheetReorderEnd: onSheetReorderEnd })));
246
- };
@@ -1,47 +0,0 @@
1
- import * as React from 'react';
2
- import { SpreadsheetProps, SpreadsheetHandle } from './SpreadsheetProps';
3
- /**
4
- * Represents the [KendoReact Spreadsheet component]({% slug overview_spreadsheet %}).
5
- *
6
- * Accepts properties of type [SpreadsheetProps]({% slug api_spreadsheet_spreadsheetprops %}).
7
- * Obtaining the ref will give you an object of type [SpreadsheetHandle]({% slug api_spreadsheet_spreadsheethandle %}).
8
- *
9
- * @example
10
- * ```jsx
11
- * const sheets = [
12
- * {
13
- * name: 'Food Order',
14
- * rows: [
15
- * {
16
- * cells: [
17
- * {
18
- * value: 216321,
19
- * textAlign: 'center',
20
- * },
21
- * ],
22
- * },
23
- * ],
24
- * columns: [
25
- * {
26
- * width: 100,
27
- * },
28
- * ],
29
- * },
30
- * ];
31
- * const App = () => {
32
- * return (
33
- * <Spreadsheet
34
- * style={{
35
- * width: "100%",
36
- * height: 680,
37
- * }}
38
- * defaultProps={{
39
- * sheets,
40
- * }}
41
- * />
42
- * );
43
- * };
44
- * ReactDOM.render(<App />, document.querySelector("my-app"));
45
- * ```
46
- */
47
- export declare const Spreadsheet: React.ForwardRefExoticComponent<SpreadsheetProps & React.RefAttributes<SpreadsheetHandle | null>>;
@@ -1,286 +0,0 @@
1
- import * as React from 'react';
2
- import * as PropTypes from 'prop-types';
3
- import { Button, ButtonGroup, Toolbar, ToolbarSeparator } from '@progress/kendo-react-buttons';
4
- import { TabStrip, TabStripTab } from '@progress/kendo-react-layout';
5
- import { Dialog, DialogActionsBar } from '@progress/kendo-react-dialogs';
6
- import { FormulaInput } from './FormulaInput';
7
- import { NameBox } from './NameBox';
8
- import { SheetsBar } from './SheetsBar';
9
- import { SpreadsheetWidget } from './SpreadsheetProps';
10
- import { defaultTabs } from './tools/defaultTools';
11
- import { IconWrap, classNames, validatePackage, shouldShowValidationUI, WatermarkOverlay } from '@progress/kendo-react-common';
12
- import { packageMetadata } from './package-metadata';
13
- import { formulaFxIcon } from '@progress/kendo-svg-icons';
14
- import { useInternationalization, useLocalization } from '@progress/kendo-react-intl';
15
- import { saveAs } from '@progress/kendo-file-saver';
16
- import { Workbook } from '@progress/kendo-ooxml';
17
- import { keys, messages } from './messages';
18
- const toolsFunctions = ['bold', 'italic', 'underline', 'fontFamily', 'fontSize', 'color', 'background', 'textAlign', 'verticalAlign', 'wrap', 'gridLines'];
19
- const toolsValueMap = {
20
- Bold: (state) => state.bold,
21
- Italic: (state) => state.italic,
22
- Underline: (state) => state.underline,
23
- FontFamily: (state) => state.fontFamily,
24
- FontSize: (state) => state.fontSize,
25
- IncreaseFontSize: (state) => state.fontSize,
26
- DecreaseFontSize: (state) => state.fontSize,
27
- TextColor: (state) => state.color,
28
- BackgroundColor: (state) => state.background,
29
- Alignment: (state) => ({ textAlign: state.textAlign, verticalAlign: state.verticalAlign }),
30
- AlignHorizontally: (state) => state.textAlign,
31
- AlignVertically: (state) => state.verticalAlign,
32
- TextWrap: (state) => state.wrap,
33
- GridLines: (state) => state.gridLines,
34
- AddColumnLeft: (state) => state.selectedHeaders,
35
- AddColumnRight: (state) => state.selectedHeaders,
36
- AddRowBelow: (state) => state.selectedHeaders,
37
- AddRowAbove: (state) => state.selectedHeaders,
38
- DeleteColumn: (state) => state.selectedHeaders,
39
- DeleteRow: (state) => state.selectedHeaders
40
- };
41
- const noInnerButton = ':not(.k-dropdownlist button)' +
42
- ':not(.k-combobox button)' +
43
- ':not(.k-upload-button)' +
44
- ':not(.k-colorpicker button)' +
45
- ':not(.k-split-button .k-split-button-arrow)';
46
- const toolbarButtons = [
47
- 'button' + noInnerButton,
48
- '.k-button-group > button' + noInnerButton,
49
- '.k-dropdownlist',
50
- '.k-combobox',
51
- '.k-colorpicker'
52
- ];
53
- /**
54
- * Represents the [KendoReact Spreadsheet component]({% slug overview_spreadsheet %}).
55
- *
56
- * Accepts properties of type [SpreadsheetProps]({% slug api_spreadsheet_spreadsheetprops %}).
57
- * Obtaining the ref will give you an object of type [SpreadsheetHandle]({% slug api_spreadsheet_spreadsheethandle %}).
58
- *
59
- * @example
60
- * ```jsx
61
- * const sheets = [
62
- * {
63
- * name: 'Food Order',
64
- * rows: [
65
- * {
66
- * cells: [
67
- * {
68
- * value: 216321,
69
- * textAlign: 'center',
70
- * },
71
- * ],
72
- * },
73
- * ],
74
- * columns: [
75
- * {
76
- * width: 100,
77
- * },
78
- * ],
79
- * },
80
- * ];
81
- * const App = () => {
82
- * return (
83
- * <Spreadsheet
84
- * style={{
85
- * width: "100%",
86
- * height: 680,
87
- * }}
88
- * defaultProps={{
89
- * sheets,
90
- * }}
91
- * />
92
- * );
93
- * };
94
- * ReactDOM.render(<App />, document.querySelector("my-app"));
95
- * ```
96
- */
97
- export const Spreadsheet = React.forwardRef((props, ref) => {
98
- validatePackage(packageMetadata);
99
- const showLicenseWatermark = shouldShowValidationUI(packageMetadata);
100
- const { toolbar = defaultTabs } = props;
101
- const toolbarTools = [];
102
- if (typeof toolbar === 'boolean') {
103
- toolbarTools.push(...(toolbar ? defaultTabs : []));
104
- }
105
- else {
106
- toolbarTools.push(...toolbar);
107
- }
108
- const [dialog, setDialog] = React.useState(null);
109
- const [tab, setTab] = React.useState(toolbarTools.findIndex(t => t.selected) || 0);
110
- const [_init, setInit] = React.useState(false);
111
- const elementRef = React.useRef(null);
112
- const formulaBarInputRef = React.useRef(null);
113
- const formulaCellInputRef = React.useRef(null);
114
- const nameBoxRef = React.useRef(null);
115
- const spreadsheetRef = React.useRef(null);
116
- const [toolsState, setToolsState] = React.useState({});
117
- const prevState = React.useRef({});
118
- prevState.current = toolsState;
119
- const propsRef = React.useRef({});
120
- propsRef.current = props;
121
- const loc = useLocalization();
122
- const onSelect = React.useCallback((event) => {
123
- if (propsRef.current.onSelect) {
124
- propsRef.current.onSelect.call(undefined, event);
125
- }
126
- }, []);
127
- const onChange = React.useCallback((event) => {
128
- if (propsRef.current.onChange) {
129
- propsRef.current.onChange.call(undefined, event);
130
- }
131
- }, []);
132
- const onChangeFormat = React.useCallback((event) => {
133
- if (propsRef.current.onChangeFormat) {
134
- propsRef.current.onChangeFormat.call(undefined, event);
135
- }
136
- }, []);
137
- const onExcelImport = React.useCallback((event) => {
138
- if (propsRef.current.onExcelImport) {
139
- propsRef.current.onExcelImport.call(undefined, event);
140
- }
141
- }, []);
142
- const onExcelExport = React.useCallback((event) => {
143
- if (propsRef.current.onExcelExport) {
144
- propsRef.current.onExcelExport.call(undefined, event);
145
- }
146
- }, []);
147
- const target = React.useRef(null);
148
- React.useImperativeHandle(target, () => ({
149
- element: elementRef.current,
150
- get instance() { return spreadsheetRef.current; },
151
- props,
152
- get view() { return spreadsheetRef.current.view; },
153
- get workbook() { return spreadsheetRef.current.workbook; },
154
- executeCommand(options) { var _a; (_a = spreadsheetRef.current) === null || _a === void 0 ? void 0 : _a.executeCommand(options); },
155
- fromJSON(json) { var _a; return (_a = spreadsheetRef.current) === null || _a === void 0 ? void 0 : _a.fromJSON(json); },
156
- toJSON() { return spreadsheetRef.current.toJSON(); },
157
- saveJSON() { return spreadsheetRef.current.saveJSON(); },
158
- fromFile(file) { return spreadsheetRef.current.fromFile(file); },
159
- saveAsExcel(options) {
160
- var _a;
161
- (_a = spreadsheetRef.current) === null || _a === void 0 ? void 0 : _a.saveAsExcel(Object.assign(Object.assign(Object.assign({}, spreadsheetRef.current.options.excel), { saveAs,
162
- Workbook }), options));
163
- },
164
- activeSheet(sheet) { var _a; return (_a = spreadsheetRef.current) === null || _a === void 0 ? void 0 : _a.activeSheet(sheet); },
165
- sheets() { return spreadsheetRef.current.sheets(); },
166
- refresh() { var _a; return (_a = spreadsheetRef.current) === null || _a === void 0 ? void 0 : _a.refresh(); }
167
- }), [props]);
168
- React.useImperativeHandle(ref, () => target.current);
169
- const nameEditor = React.useCallback(() => {
170
- return spreadsheetRef.current && spreadsheetRef.current.view.nameEditor;
171
- }, []);
172
- const onUpdateTools = React.useCallback((e) => {
173
- const state = {};
174
- toolsFunctions.forEach(tool => {
175
- if (typeof e.range[tool] === 'function') {
176
- state[tool] = e.range[tool]();
177
- }
178
- else if (tool === 'gridLines') {
179
- state[tool] = e.range.sheet().showGridLines();
180
- }
181
- });
182
- state.selectedHeaders = e.range.sheet().selectedHeaders();
183
- if (toolsFunctions.some(k => state[k] !== prevState.current[k]) ||
184
- state.selectedHeaders.allCols !== prevState.current.selectedHeaders.allCols ||
185
- state.selectedHeaders.allRows !== prevState.current.selectedHeaders.allRows) {
186
- setToolsState(state);
187
- }
188
- }, []);
189
- const onMessage = React.useCallback((e) => {
190
- const name = e.name;
191
- const key = keys[name];
192
- setDialog({
193
- title: e.title === 'Error' ? loc.toLanguageString(keys.error, messages[keys.error] || e.title) : e.title,
194
- message: key ? loc.toLanguageString(key, messages[key] || e.text) : e.text,
195
- close: e.close
196
- });
197
- }, []);
198
- const onDialogClose = React.useCallback(() => {
199
- setDialog(null);
200
- dialog === null || dialog === void 0 ? void 0 : dialog.close();
201
- }, [dialog]);
202
- const intl = useInternationalization();
203
- const localization = useLocalization();
204
- React.useEffect(() => {
205
- var _a;
206
- const options = Object.assign(Object.assign({}, props.defaultProps), { sheets: structuredClone((_a = props.defaultProps) === null || _a === void 0 ? void 0 : _a.sheets), messages: {
207
- workbook: {
208
- defaultSheetName: localization.toLanguageString(keys.defaultSheetName, messages[keys.defaultSheetName])
209
- }
210
- }, intl: {
211
- localeInfo: () => intl.localeInfo(),
212
- parseDate: (value, fmt) => intl.parseDate(value, fmt),
213
- toString: (value, fmt) => intl.toString(value, fmt),
214
- format: (fmt, ...values) => intl.format(fmt, ...values)
215
- }, formulaBarInputRef,
216
- formulaCellInputRef,
217
- nameBoxRef });
218
- const spreadsheet = new SpreadsheetWidget(elementRef.current, options);
219
- spreadsheetRef.current = spreadsheet;
220
- spreadsheet.bind('select', onSelect);
221
- spreadsheet.bind('change', onChange);
222
- spreadsheet.bind('changeFormat', onChangeFormat);
223
- spreadsheet.bind('excelImport', onExcelImport);
224
- spreadsheet.bind('excelExport', onExcelExport);
225
- spreadsheet.view.bind('update', onUpdateTools);
226
- spreadsheet.view.bind('message', onMessage);
227
- const sheet = spreadsheet.activeSheet();
228
- if (sheet) {
229
- onUpdateTools({ range: sheet.range(sheet.activeCell()) });
230
- }
231
- setInit(true);
232
- return () => {
233
- spreadsheet.destroy();
234
- };
235
- }, []);
236
- const renderTool = React.useCallback((Tool, index) => {
237
- const tool = (React.createElement(Tool, { spreadsheetRef: spreadsheetRef, value: toolsValueMap[Tool.displayName] ? toolsValueMap[Tool.displayName](toolsState) : undefined, key: index }));
238
- return tool.type === ToolbarSeparator ? React.createElement(Tool, { key: index }) : tool;
239
- }, [toolsState]);
240
- let tabstrip = null;
241
- if (toolbarTools.length) {
242
- tabstrip = (React.createElement(TabStrip, { selected: tab, animation: false, className: "k-floatwrap k-spreadsheet-tabstrip", style: { minHeight: 'auto' }, onSelect: e => setTab(e.selected) }, toolbarTools.map((tabData) => {
243
- const title = tabData.textKey ? localization.toLanguageString(tabData.textKey, messages[tabData.textKey]) : tabData.text;
244
- return (React.createElement(TabStripTab, { key: tabData.textKey || tabData.text, title: title },
245
- React.createElement(Toolbar, { buttons: toolbarButtons, className: 'k-spreadsheet-toolbar' }, tabData.tools.map((tool, index) => {
246
- if (Array.isArray(tool)) {
247
- return (React.createElement(ButtonGroup, { key: index }, tool.map((t, i) => renderTool(t, i))));
248
- }
249
- else {
250
- return renderTool(tool, index);
251
- }
252
- }))));
253
- })));
254
- }
255
- return (React.createElement("div", { ref: elementRef, style: props.style, className: classNames('k-widget k-spreadsheet', props.className), role: "application" },
256
- tabstrip,
257
- React.createElement("div", { className: "k-spreadsheet-action-bar" },
258
- React.createElement(NameBox, { ref: nameBoxRef, nameEditor: nameEditor }),
259
- React.createElement("div", { className: "k-spreadsheet-formula-bar" },
260
- React.createElement(IconWrap, { name: "formula-fx", icon: formulaFxIcon }),
261
- React.createElement(FormulaInput, { ref: formulaBarInputRef }))),
262
- React.createElement("div", { className: "k-spreadsheet-view" },
263
- React.createElement("div", { className: "k-spreadsheet-fixed-container" }),
264
- React.createElement("div", { className: "k-spreadsheet-scroller" },
265
- React.createElement("div", { className: "k-spreadsheet-view-size" })),
266
- React.createElement("div", { tabIndex: 0, className: "k-spreadsheet-clipboard", contentEditable: "true" }),
267
- React.createElement(FormulaInput, { ref: formulaCellInputRef, className: "k-spreadsheet-cell-editor" })),
268
- React.createElement(SheetsBar, { spreadsheetRef: spreadsheetRef }),
269
- dialog && (React.createElement(Dialog, { title: dialog.title, onClose: onDialogClose },
270
- React.createElement("div", null, dialog.message),
271
- React.createElement(DialogActionsBar, { layout: 'start' },
272
- React.createElement(Button, { themeColor: 'primary', onClick: onDialogClose, autoFocus: true }, loc.toLanguageString(keys.ok, messages[keys.ok]))))),
273
- showLicenseWatermark && React.createElement(WatermarkOverlay, null)));
274
- });
275
- Spreadsheet.displayName = 'KendoReactSpreadsheet';
276
- Spreadsheet.propTypes = {
277
- className: PropTypes.string,
278
- defaultProps: PropTypes.any,
279
- toolbar: PropTypes.oneOfType([PropTypes.bool, PropTypes.arrayOf(PropTypes.any)]),
280
- style: PropTypes.object,
281
- onSelect: PropTypes.func,
282
- onChange: PropTypes.func,
283
- onChangeFormat: PropTypes.func,
284
- onExcelImport: PropTypes.func,
285
- onExcelExport: PropTypes.func
286
- };