@leankylin-sheet/react 7.0.10 → 7.0.11

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.
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ import "./index.css";
3
+ export declare const CustomFormat: React.FC<{
4
+ onCancel: () => void;
5
+ }>;
package/dist/index.css CHANGED
@@ -3176,28 +3176,68 @@ label {
3176
3176
  background-color: #fff;
3177
3177
  border: 1px solid #ccc;
3178
3178
  }
3179
- .listBox {
3179
+ #leankylin-custom-format {
3180
+ width: 360px;
3181
+ }
3182
+
3183
+ .custom-format-input-row {
3180
3184
  display: flex;
3181
- justify-content: space-between;
3185
+ align-items: center;
3182
3186
  }
3183
3187
 
3184
- .inpbox {
3185
- margin-bottom: 10px;
3188
+ .custom-format-label {
3189
+ flex-shrink: 0;
3186
3190
  }
3187
3191
 
3188
- .decimal-places-input {
3189
- width: 70px;
3192
+ .custom-format-input {
3193
+ flex: 1;
3194
+ height: 28px;
3195
+ padding: 0 8px;
3196
+ border: 1px solid #d4d4d4;
3197
+ border-radius: 2px;
3198
+ outline: none;
3190
3199
  }
3191
3200
 
3201
+ .custom-format-input:focus {
3202
+ border-color: #1a73e8;
3203
+ }
3192
3204
 
3193
- .format-list {
3194
- width: 300px;
3195
- height: 170px;
3205
+ .custom-format-list {
3206
+ margin-top: 12px;
3196
3207
  border: 1px solid #d4d4d4;
3197
- overflow-y: scroll;
3208
+ border-radius: 2px;
3209
+ font-size: 12px;
3210
+ }
3211
+
3212
+ .custom-format-list-header {
3213
+ background: #f5f6f7;
3214
+ font-weight: 600;
3215
+ cursor: default;
3216
+ }
3217
+
3218
+ .custom-format-list-body {
3219
+ height: 180px;
3220
+ overflow-y: auto;
3221
+ }
3222
+
3223
+ .custom-format-list-row {
3224
+ display: flex;
3225
+ justify-content: space-between;
3226
+ padding: 4px 10px;
3227
+ cursor: pointer;
3198
3228
  }
3199
3229
 
3230
+ .custom-format-list-row > div:last-child {
3231
+ color: #888;
3232
+ }
3233
+
3234
+ .custom-format-list-row:hover {
3235
+ background: #f0f4ff;
3236
+ }
3200
3237
 
3238
+ .custom-format-list-row.on {
3239
+ background: #e3edfd;
3240
+ }
3201
3241
 
3202
3242
  .leankylin-fx-editor {
3203
3243
  display: flex;
@@ -3176,28 +3176,68 @@ label {
3176
3176
  background-color: #fff;
3177
3177
  border: 1px solid #ccc;
3178
3178
  }
3179
- .listBox {
3179
+ #leankylin-custom-format {
3180
+ width: 360px;
3181
+ }
3182
+
3183
+ .custom-format-input-row {
3180
3184
  display: flex;
3181
- justify-content: space-between;
3185
+ align-items: center;
3182
3186
  }
3183
3187
 
3184
- .inpbox {
3185
- margin-bottom: 10px;
3188
+ .custom-format-label {
3189
+ flex-shrink: 0;
3186
3190
  }
3187
3191
 
3188
- .decimal-places-input {
3189
- width: 70px;
3192
+ .custom-format-input {
3193
+ flex: 1;
3194
+ height: 28px;
3195
+ padding: 0 8px;
3196
+ border: 1px solid #d4d4d4;
3197
+ border-radius: 2px;
3198
+ outline: none;
3190
3199
  }
3191
3200
 
3201
+ .custom-format-input:focus {
3202
+ border-color: #1a73e8;
3203
+ }
3192
3204
 
3193
- .format-list {
3194
- width: 300px;
3195
- height: 170px;
3205
+ .custom-format-list {
3206
+ margin-top: 12px;
3196
3207
  border: 1px solid #d4d4d4;
3197
- overflow-y: scroll;
3208
+ border-radius: 2px;
3209
+ font-size: 12px;
3210
+ }
3211
+
3212
+ .custom-format-list-header {
3213
+ background: #f5f6f7;
3214
+ font-weight: 600;
3215
+ cursor: default;
3216
+ }
3217
+
3218
+ .custom-format-list-body {
3219
+ height: 180px;
3220
+ overflow-y: auto;
3221
+ }
3222
+
3223
+ .custom-format-list-row {
3224
+ display: flex;
3225
+ justify-content: space-between;
3226
+ padding: 4px 10px;
3227
+ cursor: pointer;
3198
3228
  }
3199
3229
 
3230
+ .custom-format-list-row > div:last-child {
3231
+ color: #888;
3232
+ }
3233
+
3234
+ .custom-format-list-row:hover {
3235
+ background: #f0f4ff;
3236
+ }
3200
3237
 
3238
+ .custom-format-list-row.on {
3239
+ background: #e3edfd;
3240
+ }
3201
3241
 
3202
3242
  .leankylin-fx-editor {
3203
3243
  display: flex;
package/dist/index.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { defaultContext, defaultSettings, getSheetIndex, colLocationByIndex, fixPositionOnFrozenCells, colLocation, getFlowdata, isAllowEdit, handleColumnHeaderMouseDown, handleColSizeHandleMouseDown, handleColFreezeHandleMouseDown, handleContextMenu, selectTitlesMap, selectTitlesRange, fixColumnStyleOverflowInFreeze, rowLocationByIndex, rowLocation, handleRowHeaderMouseDown, handleRowSizeHandleMouseDown, handleRowFreezeHandleMouseDown, fixRowStyleOverflowInFreeze, functionHTMLGenerate, locale, getCellValue, createRangeHightlight, isInlineStringCell, getInlineStringHTML, valueShowEs, escapeHTMLTag, escapeScriptTag, isShowHidenCR, cancelNormalSelected, moveHighlightCell, updateCell, israngeseleciton, handleFormulaInput, onSearchDialogMoveStart, replaceAll, replace, searchAll, searchNext, changeSheet, normalizeSelection, scrollToHighlightCell, chatatABC, getCellHyperlink, isLinkValid, getRangetxt, goToLink, replaceHtml, removeHyperlink, onRangeSelectionModalMoveStart, saveHyperlink, createFilterOptions, onImageMoveStart, onImageResizeStart, showComments, setEditingComment, onCommentBoxMoveStart, onCommentBoxResizeStart, confirmMessage, getRangeByTxt, getDropdownList, setCellValue, setConditionRules, mergeBorder, setDropcownValue, handleCellAreaMouseDown, handleCellAreaMouseMove, handleCellAreaDragOver, handleCellDrop, handleCellAreaDoubleClick, selectAll, showLinkCard, getCellRowColumn, handleOverlayMouseMove, handleOverlayMouseUp, handleKeydownForZoom, handleOverlayTouchStart, handleOverlayTouchMove, handleOverlayTouchEnd, PAINT_MODEL_CURSOR, onCellsMoveStart, createDropCellRange, handleDropCellDoubleClick, updateContextWithSheetData, updateContextWithCanvas, initFreeze, Canvas, handleGlobalWheel, setCaretPosition, getDataArr, updateMoreCell, getRegStr, getOptionValue, getSelectRange, applyLocation, updateItem, update, normalizedCellAttr, updateFormat, handleTextSize, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, showImgChooser, insertImage, editComment, deleteComment, showHideComment, showHideAllComments, newComment, handleSum, autoSelectionFormula, handleMerge, handleBorder, handleFreeze, handleSort, createFilter, clearFilter, toolbarItemSelectedFunc, toolbarItemClickHandler, handleTextColor, handleTextBackground, getDataBySelectionNoCopy, getInlineStringNoStyle, rangeHightlightselected, editSheetName, setNextSheet, MAX_ZOOM_RATIO, MIN_ZOOM_RATIO, addSheet, indexToColumnChar, sortSelection, handleCopy, insertRowCol, deleteRowCol, hideSelected, showSelected, api, removeActiveImage, deleteSelectedCellText, jfrefreshgrid, handleLink, deleteSheet, opToPatch, orderbydatafiler, getFilterColumnValues, getFilterColumnColors, saveFilter, cancelActiveImgItem, patchToOp, filterPatch, inverseRowColOptions, ensureSheetIndex, initSheetIndex, handleGlobalKeyDown, handlePasteByLeanklin, groupValuesRefresh } from '@leankylin-sheet/core';
1
+ import { defaultContext, defaultSettings, getSheetIndex, colLocationByIndex, fixPositionOnFrozenCells, colLocation, getFlowdata, isAllowEdit, handleColumnHeaderMouseDown, handleColSizeHandleMouseDown, handleColFreezeHandleMouseDown, handleContextMenu, selectTitlesMap, selectTitlesRange, fixColumnStyleOverflowInFreeze, rowLocationByIndex, rowLocation, handleRowHeaderMouseDown, handleRowSizeHandleMouseDown, handleRowFreezeHandleMouseDown, fixRowStyleOverflowInFreeze, functionHTMLGenerate, locale, getCellValue, createRangeHightlight, isInlineStringCell, getInlineStringHTML, valueShowEs, escapeHTMLTag, escapeScriptTag, isShowHidenCR, cancelNormalSelected, moveHighlightCell, updateCell, israngeseleciton, handleFormulaInput, onSearchDialogMoveStart, replaceAll, replace, searchAll, searchNext, changeSheet, normalizeSelection, scrollToHighlightCell, chatatABC, getCellHyperlink, isLinkValid, getRangetxt, goToLink, replaceHtml, removeHyperlink, onRangeSelectionModalMoveStart, saveHyperlink, createFilterOptions, onImageMoveStart, onImageResizeStart, showComments, setEditingComment, onCommentBoxMoveStart, onCommentBoxResizeStart, confirmMessage, getRangeByTxt, getDropdownList, setCellValue, setConditionRules, mergeBorder, setDropcownValue, handleCellAreaMouseDown, handleCellAreaMouseMove, handleCellAreaDragOver, handleCellDrop, handleCellAreaDoubleClick, selectAll, showLinkCard, getCellRowColumn, handleOverlayMouseMove, handleOverlayMouseUp, handleKeydownForZoom, handleOverlayTouchStart, handleOverlayTouchMove, handleOverlayTouchEnd, PAINT_MODEL_CURSOR, onCellsMoveStart, createDropCellRange, handleDropCellDoubleClick, updateContextWithSheetData, updateContextWithCanvas, initFreeze, Canvas, handleGlobalWheel, setCaretPosition, getDataArr, updateMoreCell, getRegStr, getOptionValue, getSelectRange, applyLocation, updateItem, normalizedCellAttr, updateFormat, handleTextSize, handleHorizontalAlign, handleVerticalAlign, handleScreenShot, showImgChooser, insertImage, editComment, deleteComment, showHideComment, showHideAllComments, newComment, handleSum, autoSelectionFormula, handleMerge, handleBorder, handleFreeze, handleSort, createFilter, clearFilter, toolbarItemSelectedFunc, toolbarItemClickHandler, handleTextColor, handleTextBackground, getDataBySelectionNoCopy, getInlineStringNoStyle, rangeHightlightselected, editSheetName, setNextSheet, MAX_ZOOM_RATIO, MIN_ZOOM_RATIO, addSheet, indexToColumnChar, sortSelection, handleCopy, insertRowCol, deleteRowCol, hideSelected, showSelected, api, removeActiveImage, deleteSelectedCellText, jfrefreshgrid, handleLink, deleteSheet, opToPatch, orderbydatafiler, getFilterColumnValues, getFilterColumnColors, saveFilter, cancelActiveImgItem, patchToOp, filterPatch, inverseRowColOptions, ensureSheetIndex, initSheetIndex, handleGlobalKeyDown, handlePasteByLeanklin, groupValuesRefresh } from '@leankylin-sheet/core';
2
2
  import { useInViewport, useMemoizedFn, useThrottleFn } from 'ahooks';
3
3
  import React, { useContext, useRef, useState, useMemo, useCallback, useEffect, useLayoutEffect, useImperativeHandle } from 'react';
4
4
  import produce, { applyPatches, enablePatches, produceWithPatches } from 'immer';
@@ -6493,64 +6493,51 @@ var CustomBorder = function CustomBorder(_ref) {
6493
6493
  })))));
6494
6494
  };
6495
6495
 
6496
- var FormatSearch = function FormatSearch(_ref) {
6497
- var type = _ref.type,
6498
- _onCancel = _ref.onCancel;
6496
+ var CustomFormat = function CustomFormat(_ref) {
6497
+ var _onCancel = _ref.onCancel;
6499
6498
  var _useContext = useContext(WorkbookContext),
6500
6499
  context = _useContext.context,
6501
6500
  setContext = _useContext.setContext,
6502
6501
  cellInput = _useContext.refs.cellInput;
6503
- var _useState = useState(2),
6502
+ var _useState = useState(function () {
6503
+ var _context$luckysheet_s, _flowdata$row;
6504
+ var flowdata = getFlowdata(context);
6505
+ var firstSelection = (_context$luckysheet_s = context.luckysheet_select_save) === null || _context$luckysheet_s === void 0 ? void 0 : _context$luckysheet_s[0];
6506
+ var row = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
6507
+ var col = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
6508
+ var cell = flowdata != null && row != null && col != null ? (_flowdata$row = flowdata[row]) === null || _flowdata$row === void 0 ? void 0 : _flowdata$row[col] : undefined;
6509
+ var ct = cell == null ? undefined : normalizedCellAttr(cell, "ct");
6510
+ return (ct === null || ct === void 0 ? void 0 : ct.fa) != null && ct.fa !== "fmtOtherSelf" ? ct.fa : "#0.00";
6511
+ }),
6504
6512
  _useState2 = _slicedToArray(_useState, 2),
6505
- decimalPlace = _useState2[0],
6506
- setDecimalPlace = _useState2[1];
6507
- var _useState3 = useState(0),
6508
- _useState4 = _slicedToArray(_useState3, 2),
6509
- selectedFormatIndex = _useState4[0],
6510
- setSelectedFormatIndex = _useState4[1];
6513
+ formatStr = _useState2[0],
6514
+ setFormatStr = _useState2[1];
6511
6515
  var _locale = locale(context),
6512
6516
  button = _locale.button,
6513
6517
  format = _locale.format,
6514
- currencyDetail = _locale.currencyDetail,
6515
- dateFmtList = _locale.dateFmtList;
6518
+ defaultFmt = _locale.defaultFmt;
6516
6519
  var _useDialog = useDialog(),
6517
6520
  showDialog = _useDialog.showDialog;
6518
- var toolbarFormatAll = useMemo(function () {
6519
- return {
6520
- currency: currencyDetail,
6521
- date: dateFmtList,
6522
- number: []
6523
- };
6524
- }, [currencyDetail, dateFmtList]);
6525
- var toolbarFormat = useMemo(function () {
6526
- return toolbarFormatAll[type];
6527
- }, [toolbarFormatAll, type]);
6528
- var tips = _.get(format, type);
6521
+ var presetFmtList = useMemo(function () {
6522
+ return defaultFmt.filter(function (v) {
6523
+ return v.value !== "split" && v.value !== "fmtOtherSelf";
6524
+ });
6525
+ }, [defaultFmt]);
6529
6526
  var onConfirm = useCallback(function () {
6530
- if (decimalPlace < 0 || decimalPlace > 9) {
6527
+ var fmt = formatStr.trim();
6528
+ if (fmt === "" || fmt === "fmtOtherSelf") {
6531
6529
  _onCancel();
6532
- showDialog(format.tipDecimalPlaces, "ok");
6530
+ showDialog(format.tipCustomFormat, "ok");
6533
6531
  return;
6534
6532
  }
6535
6533
  setContext(function (ctx) {
6536
- var index = getSheetIndex(ctx, ctx.currentSheetId);
6537
- if (_.isNil(index)) return;
6538
- var selectedFormat = toolbarFormat[selectedFormatIndex].value;
6539
- _.forEach(ctx.luckysheet_select_save, function (selection) {
6540
- for (var r = selection.row[0]; r <= selection.row[1]; r += 1) {
6541
- for (var c = selection.column[0]; c <= selection.column[1]; c += 1) {
6542
- var _ctx$luckysheetfile$i, _ctx$luckysheetfile$i2, _ctx$luckysheetfile$i3, _ctx$luckysheetfile$i4;
6543
- if (((_ctx$luckysheetfile$i = ctx.luckysheetfile[index].data) === null || _ctx$luckysheetfile$i === void 0 ? void 0 : _ctx$luckysheetfile$i[r][c]) && ((_ctx$luckysheetfile$i2 = ctx.luckysheetfile[index].data) === null || _ctx$luckysheetfile$i2 === void 0 ? void 0 : (_ctx$luckysheetfile$i3 = _ctx$luckysheetfile$i2[r][c]) === null || _ctx$luckysheetfile$i3 === void 0 ? void 0 : (_ctx$luckysheetfile$i4 = _ctx$luckysheetfile$i3.ct) === null || _ctx$luckysheetfile$i4 === void 0 ? void 0 : _ctx$luckysheetfile$i4.t) === "n") {
6544
- var zero = 0;
6545
- ctx.luckysheetfile[index].data[r][c].ct.fa = "".concat(selectedFormat).concat(zero.toFixed(decimalPlace));
6546
- ctx.luckysheetfile[index].data[r][c].m = update("".concat(selectedFormat).concat(zero.toFixed(decimalPlace)), ctx.luckysheetfile[index].data[r][c].v);
6547
- }
6548
- }
6549
- }
6550
- });
6534
+ var d = getFlowdata(ctx);
6535
+ if (d == null) return;
6536
+ updateFormat(ctx, cellInput.current, d, "ct", fmt);
6537
+ cancelNormalSelected(ctx);
6551
6538
  _onCancel();
6552
6539
  });
6553
- }, [_onCancel, decimalPlace, format.tipDecimalPlaces, selectedFormatIndex, setContext, showDialog, toolbarFormat]);
6540
+ }, [_onCancel, cellInput, format.tipCustomFormat, formatStr, setContext, showDialog]);
6554
6541
  var onCancel = useCallback(function () {
6555
6542
  setContext(function (ctx) {
6556
6543
  cancelNormalSelected(ctx);
@@ -6560,50 +6547,45 @@ var FormatSearch = function FormatSearch(_ref) {
6560
6547
  });
6561
6548
  _onCancel();
6562
6549
  }, [_onCancel, cellInput, setContext]);
6563
- return /*#__PURE__*/React.createElement("div", {
6564
- id: "luckysheet-search-format"
6565
- }, /*#__PURE__*/React.createElement("div", {
6566
- className: "listbox",
6567
- style: {
6568
- height: 200
6550
+ var onKeyDown = useCallback(function (e) {
6551
+ if (e.key === "Enter") {
6552
+ onConfirm();
6569
6553
  }
6554
+ }, [onConfirm]);
6555
+ return /*#__PURE__*/React.createElement("div", {
6556
+ id: "leankylin-custom-format"
6570
6557
  }, /*#__PURE__*/React.createElement("div", {
6571
- style: {
6572
- marginBottom: 16
6573
- }
6574
- }, tips, format.format, "\uFF1A"), /*#__PURE__*/React.createElement("div", {
6575
- className: "inpbox",
6576
- style: type === "currency" ? {
6577
- display: "block"
6578
- } : {
6579
- display: "none"
6580
- }
6581
- }, format.decimalPlaces, "\uFF1A", /*#__PURE__*/React.createElement("input", {
6582
- className: "decimal-places-input",
6583
- id: "decimal-places-input",
6584
- min: 0,
6585
- max: 9,
6586
- defaultValue: 2,
6587
- type: "number",
6558
+ className: "custom-format-input-row"
6559
+ }, /*#__PURE__*/React.createElement("span", {
6560
+ className: "custom-format-label"
6561
+ }, format.customFormat, "\uFF1A"), /*#__PURE__*/React.createElement("input", {
6562
+ className: "custom-format-input",
6563
+ autoFocus: true,
6564
+ placeholder: format.customFormatExample,
6565
+ value: formatStr,
6588
6566
  onChange: function onChange(e) {
6589
- setDecimalPlace(parseInt(e.target.value, 10));
6590
- }
6567
+ return setFormatStr(e.target.value);
6568
+ },
6569
+ onKeyDown: onKeyDown
6591
6570
  })), /*#__PURE__*/React.createElement("div", {
6592
- className: "format-list"
6593
- }, toolbarFormat.map(function (v, index) {
6571
+ className: "custom-format-list"
6572
+ }, /*#__PURE__*/React.createElement("div", {
6573
+ className: "custom-format-list-row custom-format-list-header"
6574
+ }, /*#__PURE__*/React.createElement("div", null, format.customFormatName), /*#__PURE__*/React.createElement("div", null, format.format)), /*#__PURE__*/React.createElement("div", {
6575
+ className: "custom-format-list-body"
6576
+ }, presetFmtList.map(function (v) {
6594
6577
  return /*#__PURE__*/React.createElement("div", {
6595
- className: "listBox".concat(index === selectedFormatIndex ? " on" : ""),
6596
- key: v.name,
6578
+ className: "custom-format-list-row".concat(v.value === formatStr ? " on" : ""),
6579
+ key: v.value,
6580
+ title: v.example,
6597
6581
  onClick: function onClick() {
6598
- setSelectedFormatIndex(index);
6582
+ return setFormatStr(v.value);
6599
6583
  }
6600
- }, /*#__PURE__*/React.createElement("div", null, v.name), /*#__PURE__*/React.createElement("div", null, v.value));
6584
+ }, /*#__PURE__*/React.createElement("div", null, v.text), /*#__PURE__*/React.createElement("div", null, v.value));
6601
6585
  }))), /*#__PURE__*/React.createElement("div", {
6602
6586
  className: "leankylin-dialog-box-button-container",
6603
- style: type === "currency" ? {
6604
- marginTop: 40
6605
- } : {
6606
- marginTop: 30
6587
+ style: {
6588
+ marginTop: 20
6607
6589
  }
6608
6590
  }, /*#__PURE__*/React.createElement("div", {
6609
6591
  className: "leankylin-message-box-button button-primary",
@@ -6661,7 +6643,6 @@ var Toolbar = function Toolbar(_ref) {
6661
6643
  findAndReplace = _locale.findAndReplace,
6662
6644
  comment = _locale.comment,
6663
6645
  fontarray = _locale.fontarray;
6664
- var toolbarFormat = locale(context).format;
6665
6646
  var sheetWidth = context.luckysheetTableContentHW[0];
6666
6647
  var _useState5 = useState("#000000"),
6667
6648
  _useState6 = _slicedToArray(_useState5, 2),
@@ -6818,44 +6799,13 @@ var Toolbar = function Toolbar(_ref) {
6818
6799
  if (value === "fmtOtherSelf") {
6819
6800
  return /*#__PURE__*/React.createElement(Option, {
6820
6801
  key: value,
6821
- onMouseEnter: function onMouseEnter(e) {
6822
- return showSubMenu(e, "more-format");
6823
- },
6824
- onMouseLeave: function onMouseLeave(e) {
6825
- return hideSubMenu(e, "more-format");
6826
- }
6827
- }, /*#__PURE__*/React.createElement("div", {
6828
- className: "leankylin-toolbar-menu-line"
6829
- }, /*#__PURE__*/React.createElement("div", null, text), /*#__PURE__*/React.createElement(SVGIcon, {
6830
- name: "rightArrow",
6831
- width: 14
6832
- })), /*#__PURE__*/React.createElement("div", {
6833
- className: "more-format toolbar-item-sub-menu leankylin-toolbar-select",
6834
- style: {
6835
- display: "none",
6836
- width: 150,
6837
- bottom: 10,
6838
- top: undefined
6839
- }
6840
- }, [{
6841
- text: toolbarFormat.moreCurrency,
6842
- onclick: function onclick() {
6843
- showDialog( /*#__PURE__*/React.createElement(FormatSearch, {
6844
- onCancel: hideDialog,
6845
- type: "currency"
6802
+ onClick: function onClick() {
6803
+ showDialog( /*#__PURE__*/React.createElement(CustomFormat, {
6804
+ onCancel: hideDialog
6846
6805
  }));
6847
6806
  setOpen(false);
6848
6807
  }
6849
- }].map(function (v) {
6850
- return /*#__PURE__*/React.createElement("div", {
6851
- className: "set-background-item leankylin-toolbar-select-option",
6852
- key: v.text,
6853
- onClick: function onClick() {
6854
- v.onclick();
6855
- setOpen(false);
6856
- }
6857
- }, v.text);
6858
- })));
6808
+ }, text);
6859
6809
  }
6860
6810
  return /*#__PURE__*/React.createElement(Option, {
6861
6811
  key: value,
@@ -7720,7 +7670,7 @@ var Toolbar = function Toolbar(_ref) {
7720
7670
  });
7721
7671
  }
7722
7672
  });
7723
- }, [toolbar, cell, setContext, refs.cellInput, refs.fxInput, refs.globalCache, defaultFmt, align, handleUndo, handleRedo, flowdata, formula, showDialog, hideDialog, merge, border, freezen, screenshot, sort, textWrap, rotation, filter, splitText, findAndReplace, context.luckysheet_select_save, context.defaultFontSize, context.allowEdit, context.luckysheetPaintModelOn, comment, fontarray, hideSubMenu, showSubMenu, refs.canvas, customColor, customStyle, toolbarFormat.moreCurrency]);
7673
+ }, [toolbar, cell, setContext, refs.cellInput, refs.fxInput, refs.globalCache, defaultFmt, align, handleUndo, handleRedo, flowdata, formula, showDialog, hideDialog, merge, border, freezen, screenshot, sort, textWrap, rotation, filter, splitText, findAndReplace, context.luckysheet_select_save, context.defaultFontSize, context.allowEdit, context.luckysheetPaintModelOn, comment, fontarray, hideSubMenu, showSubMenu, refs.canvas, customColor, customStyle]);
7724
7674
  return /*#__PURE__*/React.createElement("div", {
7725
7675
  ref: containerRef,
7726
7676
  className: "leankylin-toolbar"
package/dist/index.js CHANGED
@@ -6503,64 +6503,51 @@ var CustomBorder = function CustomBorder(_ref) {
6503
6503
  })))));
6504
6504
  };
6505
6505
 
6506
- var FormatSearch = function FormatSearch(_ref) {
6507
- var type = _ref.type,
6508
- _onCancel = _ref.onCancel;
6506
+ var CustomFormat = function CustomFormat(_ref) {
6507
+ var _onCancel = _ref.onCancel;
6509
6508
  var _useContext = React.useContext(WorkbookContext),
6510
6509
  context = _useContext.context,
6511
6510
  setContext = _useContext.setContext,
6512
6511
  cellInput = _useContext.refs.cellInput;
6513
- var _useState = React.useState(2),
6512
+ var _useState = React.useState(function () {
6513
+ var _context$luckysheet_s, _flowdata$row;
6514
+ var flowdata = core.getFlowdata(context);
6515
+ var firstSelection = (_context$luckysheet_s = context.luckysheet_select_save) === null || _context$luckysheet_s === void 0 ? void 0 : _context$luckysheet_s[0];
6516
+ var row = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.row_focus;
6517
+ var col = firstSelection === null || firstSelection === void 0 ? void 0 : firstSelection.column_focus;
6518
+ var cell = flowdata != null && row != null && col != null ? (_flowdata$row = flowdata[row]) === null || _flowdata$row === void 0 ? void 0 : _flowdata$row[col] : undefined;
6519
+ var ct = cell == null ? undefined : core.normalizedCellAttr(cell, "ct");
6520
+ return (ct === null || ct === void 0 ? void 0 : ct.fa) != null && ct.fa !== "fmtOtherSelf" ? ct.fa : "#0.00";
6521
+ }),
6514
6522
  _useState2 = _slicedToArray(_useState, 2),
6515
- decimalPlace = _useState2[0],
6516
- setDecimalPlace = _useState2[1];
6517
- var _useState3 = React.useState(0),
6518
- _useState4 = _slicedToArray(_useState3, 2),
6519
- selectedFormatIndex = _useState4[0],
6520
- setSelectedFormatIndex = _useState4[1];
6523
+ formatStr = _useState2[0],
6524
+ setFormatStr = _useState2[1];
6521
6525
  var _locale = core.locale(context),
6522
6526
  button = _locale.button,
6523
6527
  format = _locale.format,
6524
- currencyDetail = _locale.currencyDetail,
6525
- dateFmtList = _locale.dateFmtList;
6528
+ defaultFmt = _locale.defaultFmt;
6526
6529
  var _useDialog = useDialog(),
6527
6530
  showDialog = _useDialog.showDialog;
6528
- var toolbarFormatAll = React.useMemo(function () {
6529
- return {
6530
- currency: currencyDetail,
6531
- date: dateFmtList,
6532
- number: []
6533
- };
6534
- }, [currencyDetail, dateFmtList]);
6535
- var toolbarFormat = React.useMemo(function () {
6536
- return toolbarFormatAll[type];
6537
- }, [toolbarFormatAll, type]);
6538
- var tips = ___default['default'].get(format, type);
6531
+ var presetFmtList = React.useMemo(function () {
6532
+ return defaultFmt.filter(function (v) {
6533
+ return v.value !== "split" && v.value !== "fmtOtherSelf";
6534
+ });
6535
+ }, [defaultFmt]);
6539
6536
  var onConfirm = React.useCallback(function () {
6540
- if (decimalPlace < 0 || decimalPlace > 9) {
6537
+ var fmt = formatStr.trim();
6538
+ if (fmt === "" || fmt === "fmtOtherSelf") {
6541
6539
  _onCancel();
6542
- showDialog(format.tipDecimalPlaces, "ok");
6540
+ showDialog(format.tipCustomFormat, "ok");
6543
6541
  return;
6544
6542
  }
6545
6543
  setContext(function (ctx) {
6546
- var index = core.getSheetIndex(ctx, ctx.currentSheetId);
6547
- if (___default['default'].isNil(index)) return;
6548
- var selectedFormat = toolbarFormat[selectedFormatIndex].value;
6549
- ___default['default'].forEach(ctx.luckysheet_select_save, function (selection) {
6550
- for (var r = selection.row[0]; r <= selection.row[1]; r += 1) {
6551
- for (var c = selection.column[0]; c <= selection.column[1]; c += 1) {
6552
- var _ctx$luckysheetfile$i, _ctx$luckysheetfile$i2, _ctx$luckysheetfile$i3, _ctx$luckysheetfile$i4;
6553
- if (((_ctx$luckysheetfile$i = ctx.luckysheetfile[index].data) === null || _ctx$luckysheetfile$i === void 0 ? void 0 : _ctx$luckysheetfile$i[r][c]) && ((_ctx$luckysheetfile$i2 = ctx.luckysheetfile[index].data) === null || _ctx$luckysheetfile$i2 === void 0 ? void 0 : (_ctx$luckysheetfile$i3 = _ctx$luckysheetfile$i2[r][c]) === null || _ctx$luckysheetfile$i3 === void 0 ? void 0 : (_ctx$luckysheetfile$i4 = _ctx$luckysheetfile$i3.ct) === null || _ctx$luckysheetfile$i4 === void 0 ? void 0 : _ctx$luckysheetfile$i4.t) === "n") {
6554
- var zero = 0;
6555
- ctx.luckysheetfile[index].data[r][c].ct.fa = "".concat(selectedFormat).concat(zero.toFixed(decimalPlace));
6556
- ctx.luckysheetfile[index].data[r][c].m = core.update("".concat(selectedFormat).concat(zero.toFixed(decimalPlace)), ctx.luckysheetfile[index].data[r][c].v);
6557
- }
6558
- }
6559
- }
6560
- });
6544
+ var d = core.getFlowdata(ctx);
6545
+ if (d == null) return;
6546
+ core.updateFormat(ctx, cellInput.current, d, "ct", fmt);
6547
+ core.cancelNormalSelected(ctx);
6561
6548
  _onCancel();
6562
6549
  });
6563
- }, [_onCancel, decimalPlace, format.tipDecimalPlaces, selectedFormatIndex, setContext, showDialog, toolbarFormat]);
6550
+ }, [_onCancel, cellInput, format.tipCustomFormat, formatStr, setContext, showDialog]);
6564
6551
  var onCancel = React.useCallback(function () {
6565
6552
  setContext(function (ctx) {
6566
6553
  core.cancelNormalSelected(ctx);
@@ -6570,50 +6557,45 @@ var FormatSearch = function FormatSearch(_ref) {
6570
6557
  });
6571
6558
  _onCancel();
6572
6559
  }, [_onCancel, cellInput, setContext]);
6573
- return /*#__PURE__*/React__default['default'].createElement("div", {
6574
- id: "luckysheet-search-format"
6575
- }, /*#__PURE__*/React__default['default'].createElement("div", {
6576
- className: "listbox",
6577
- style: {
6578
- height: 200
6560
+ var onKeyDown = React.useCallback(function (e) {
6561
+ if (e.key === "Enter") {
6562
+ onConfirm();
6579
6563
  }
6564
+ }, [onConfirm]);
6565
+ return /*#__PURE__*/React__default['default'].createElement("div", {
6566
+ id: "leankylin-custom-format"
6580
6567
  }, /*#__PURE__*/React__default['default'].createElement("div", {
6581
- style: {
6582
- marginBottom: 16
6583
- }
6584
- }, tips, format.format, "\uFF1A"), /*#__PURE__*/React__default['default'].createElement("div", {
6585
- className: "inpbox",
6586
- style: type === "currency" ? {
6587
- display: "block"
6588
- } : {
6589
- display: "none"
6590
- }
6591
- }, format.decimalPlaces, "\uFF1A", /*#__PURE__*/React__default['default'].createElement("input", {
6592
- className: "decimal-places-input",
6593
- id: "decimal-places-input",
6594
- min: 0,
6595
- max: 9,
6596
- defaultValue: 2,
6597
- type: "number",
6568
+ className: "custom-format-input-row"
6569
+ }, /*#__PURE__*/React__default['default'].createElement("span", {
6570
+ className: "custom-format-label"
6571
+ }, format.customFormat, "\uFF1A"), /*#__PURE__*/React__default['default'].createElement("input", {
6572
+ className: "custom-format-input",
6573
+ autoFocus: true,
6574
+ placeholder: format.customFormatExample,
6575
+ value: formatStr,
6598
6576
  onChange: function onChange(e) {
6599
- setDecimalPlace(parseInt(e.target.value, 10));
6600
- }
6577
+ return setFormatStr(e.target.value);
6578
+ },
6579
+ onKeyDown: onKeyDown
6601
6580
  })), /*#__PURE__*/React__default['default'].createElement("div", {
6602
- className: "format-list"
6603
- }, toolbarFormat.map(function (v, index) {
6581
+ className: "custom-format-list"
6582
+ }, /*#__PURE__*/React__default['default'].createElement("div", {
6583
+ className: "custom-format-list-row custom-format-list-header"
6584
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, format.customFormatName), /*#__PURE__*/React__default['default'].createElement("div", null, format.format)), /*#__PURE__*/React__default['default'].createElement("div", {
6585
+ className: "custom-format-list-body"
6586
+ }, presetFmtList.map(function (v) {
6604
6587
  return /*#__PURE__*/React__default['default'].createElement("div", {
6605
- className: "listBox".concat(index === selectedFormatIndex ? " on" : ""),
6606
- key: v.name,
6588
+ className: "custom-format-list-row".concat(v.value === formatStr ? " on" : ""),
6589
+ key: v.value,
6590
+ title: v.example,
6607
6591
  onClick: function onClick() {
6608
- setSelectedFormatIndex(index);
6592
+ return setFormatStr(v.value);
6609
6593
  }
6610
- }, /*#__PURE__*/React__default['default'].createElement("div", null, v.name), /*#__PURE__*/React__default['default'].createElement("div", null, v.value));
6594
+ }, /*#__PURE__*/React__default['default'].createElement("div", null, v.text), /*#__PURE__*/React__default['default'].createElement("div", null, v.value));
6611
6595
  }))), /*#__PURE__*/React__default['default'].createElement("div", {
6612
6596
  className: "leankylin-dialog-box-button-container",
6613
- style: type === "currency" ? {
6614
- marginTop: 40
6615
- } : {
6616
- marginTop: 30
6597
+ style: {
6598
+ marginTop: 20
6617
6599
  }
6618
6600
  }, /*#__PURE__*/React__default['default'].createElement("div", {
6619
6601
  className: "leankylin-message-box-button button-primary",
@@ -6671,7 +6653,6 @@ var Toolbar = function Toolbar(_ref) {
6671
6653
  findAndReplace = _locale.findAndReplace,
6672
6654
  comment = _locale.comment,
6673
6655
  fontarray = _locale.fontarray;
6674
- var toolbarFormat = core.locale(context).format;
6675
6656
  var sheetWidth = context.luckysheetTableContentHW[0];
6676
6657
  var _useState5 = React.useState("#000000"),
6677
6658
  _useState6 = _slicedToArray(_useState5, 2),
@@ -6828,44 +6809,13 @@ var Toolbar = function Toolbar(_ref) {
6828
6809
  if (value === "fmtOtherSelf") {
6829
6810
  return /*#__PURE__*/React__default['default'].createElement(Option, {
6830
6811
  key: value,
6831
- onMouseEnter: function onMouseEnter(e) {
6832
- return showSubMenu(e, "more-format");
6833
- },
6834
- onMouseLeave: function onMouseLeave(e) {
6835
- return hideSubMenu(e, "more-format");
6836
- }
6837
- }, /*#__PURE__*/React__default['default'].createElement("div", {
6838
- className: "leankylin-toolbar-menu-line"
6839
- }, /*#__PURE__*/React__default['default'].createElement("div", null, text), /*#__PURE__*/React__default['default'].createElement(SVGIcon, {
6840
- name: "rightArrow",
6841
- width: 14
6842
- })), /*#__PURE__*/React__default['default'].createElement("div", {
6843
- className: "more-format toolbar-item-sub-menu leankylin-toolbar-select",
6844
- style: {
6845
- display: "none",
6846
- width: 150,
6847
- bottom: 10,
6848
- top: undefined
6849
- }
6850
- }, [{
6851
- text: toolbarFormat.moreCurrency,
6852
- onclick: function onclick() {
6853
- showDialog( /*#__PURE__*/React__default['default'].createElement(FormatSearch, {
6854
- onCancel: hideDialog,
6855
- type: "currency"
6812
+ onClick: function onClick() {
6813
+ showDialog( /*#__PURE__*/React__default['default'].createElement(CustomFormat, {
6814
+ onCancel: hideDialog
6856
6815
  }));
6857
6816
  setOpen(false);
6858
6817
  }
6859
- }].map(function (v) {
6860
- return /*#__PURE__*/React__default['default'].createElement("div", {
6861
- className: "set-background-item leankylin-toolbar-select-option",
6862
- key: v.text,
6863
- onClick: function onClick() {
6864
- v.onclick();
6865
- setOpen(false);
6866
- }
6867
- }, v.text);
6868
- })));
6818
+ }, text);
6869
6819
  }
6870
6820
  return /*#__PURE__*/React__default['default'].createElement(Option, {
6871
6821
  key: value,
@@ -7730,7 +7680,7 @@ var Toolbar = function Toolbar(_ref) {
7730
7680
  });
7731
7681
  }
7732
7682
  });
7733
- }, [toolbar, cell, setContext, refs.cellInput, refs.fxInput, refs.globalCache, defaultFmt, align, handleUndo, handleRedo, flowdata, formula, showDialog, hideDialog, merge, border, freezen, screenshot, sort, textWrap, rotation, filter, splitText, findAndReplace, context.luckysheet_select_save, context.defaultFontSize, context.allowEdit, context.luckysheetPaintModelOn, comment, fontarray, hideSubMenu, showSubMenu, refs.canvas, customColor, customStyle, toolbarFormat.moreCurrency]);
7683
+ }, [toolbar, cell, setContext, refs.cellInput, refs.fxInput, refs.globalCache, defaultFmt, align, handleUndo, handleRedo, flowdata, formula, showDialog, hideDialog, merge, border, freezen, screenshot, sort, textWrap, rotation, filter, splitText, findAndReplace, context.luckysheet_select_save, context.defaultFontSize, context.allowEdit, context.luckysheetPaintModelOn, comment, fontarray, hideSubMenu, showSubMenu, refs.canvas, customColor, customStyle]);
7734
7684
  return /*#__PURE__*/React__default['default'].createElement("div", {
7735
7685
  ref: containerRef,
7736
7686
  className: "leankylin-toolbar"