UNPKG

@light-sheet/react

Version:

FortuneSheet is a drop-in javascript spreadsheet library that provides rich features like Excel and Google Sheets

282 lines (277 loc) 11.6 kB
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } } function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } import React, { useCallback, useContext, useEffect, useState } from "react"; import "./index.css"; import { locale, setConditionRules } from "@light-sheet/core"; import produce from "immer"; import WorkbookContext from "../../context"; import { useDialog } from "../../hooks/useDialog"; var ConditionRules = function ConditionRules(_ref) { var type = _ref.type; var _useContext = useContext(WorkbookContext), context = _useContext.context, setContext = _useContext.setContext; var _useDialog = useDialog(), hideDialog = _useDialog.hideDialog; var _locale = locale(context), conditionformat = _locale.conditionformat, button = _locale.button, protection = _locale.protection, generalDialog = _locale.generalDialog; var _useState = useState({ textColor: "#000000", cellColor: "#000000" }), _useState2 = _slicedToArray(_useState, 2), colorRules = _useState2[0], setColorRules = _useState2[1]; // 开启鼠标选区 // const dataSelectRange = useCallback( // (selectType: string) => { // hideDialog(); // setContext((ctx) => { // ctx.conditionRules.textColor.color = colorRules.textColor; // ctx.conditionRules.cellColor.color = colorRules.cellColor; // ctx.rangeDialog!.show = true; // ctx.rangeDialog!.type = selectType; // ctx.rangeDialog!.rangeTxt = ctx.conditionRules.rulesValue; // ctx.rangeDialog!.singleSelect = true; // }); // }, // [colorRules.cellColor, colorRules.textColor, hideDialog, setContext] // ); var close = useCallback(function (closeType) { if (closeType === "confirm") { setContext(function (ctx) { ctx.conditionRules.textColor.color = colorRules.textColor; ctx.conditionRules.cellColor.color = colorRules.cellColor; setConditionRules(ctx, protection, generalDialog, conditionformat, ctx.conditionRules); }); } setContext(function (ctx) { ctx.conditionRules = { rulesType: "", rulesValue: "", textColor: { check: true, color: "#000000" }, cellColor: { check: true, color: "#000000" }, betweenValue: { value1: "", value2: "" }, dateValue: "", repeatValue: "0", projectValue: "10" }; }); hideDialog(); }, [colorRules, conditionformat, generalDialog, hideDialog, protection, setContext]); // rulesValue初始化 useEffect(function () { setContext(function (ctx) { ctx.conditionRules.rulesType = type; if (!ctx.rangeDialog) return; var rangeDialogType = ctx.rangeDialog.type; var rangeT = ctx.rangeDialog.rangeTxt; if (rangeDialogType === "conditionRulesbetween1") { ctx.conditionRules.betweenValue.value1 = rangeT; } else if (rangeDialogType === "conditionRulesbetween2") { ctx.conditionRules.betweenValue.value2 = rangeT; } else if (rangeDialogType.indexOf("conditionRules") >= 0) { ctx.conditionRules.rulesValue = rangeT; } else if (rangeDialogType === "") { ctx.conditionRules = { rulesType: type, rulesValue: "", textColor: { check: true, color: "#000000" }, cellColor: { check: true, color: "#000000" }, betweenValue: { value1: "", value2: "" }, dateValue: "", repeatValue: "0", projectValue: "10" }; } ctx.rangeDialog.type = ""; ctx.rangeDialog.rangeTxt = ""; }); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); return /*#__PURE__*/React.createElement("div", { className: "condition-rules" }, /*#__PURE__*/React.createElement("div", { className: "condition-rules-title" }, conditionformat["conditionformat_".concat(type)]), /*#__PURE__*/React.createElement("div", { className: "conditin-rules-value" }, conditionformat["conditionformat_".concat(type, "_title")]), (type === "greaterThan" || type === "lessThan" || type === "equal" || type === "textContains") && /*#__PURE__*/React.createElement("div", { className: "condition-rules-inpbox" }, /*#__PURE__*/React.createElement("input", { className: "condition-rules-input", type: "text", value: context.conditionRules.rulesValue, onChange: function onChange(e) { var value = e.target.value; setContext(function (ctx) { ctx.conditionRules.rulesValue = value; }); } })), type === "between" && /*#__PURE__*/React.createElement("div", { className: "condition-rules-between-box" }, /*#__PURE__*/React.createElement("div", { className: "condition-rules-between-inpbox" }, /*#__PURE__*/React.createElement("input", { className: "condition-rules-between-input", type: "text", value: context.conditionRules.betweenValue.value1, onChange: function onChange(e) { var value = e.target.value; setContext(function (ctx) { ctx.conditionRules.betweenValue.value1 = value; }); } })), /*#__PURE__*/React.createElement("span", { style: { margin: "0px 4px" } }, conditionformat.to), /*#__PURE__*/React.createElement("div", { className: "condition-rules-between-inpbox" }, /*#__PURE__*/React.createElement("input", { className: "condition-rules-between-input", type: "text", value: context.conditionRules.betweenValue.value2, onChange: function onChange(e) { var value = e.target.value; setContext(function (ctx) { ctx.conditionRules.betweenValue.value2 = value; }); } }))), type === "occurrenceDate" && /*#__PURE__*/React.createElement("div", { className: "condition-rules-inpbox" }, /*#__PURE__*/React.createElement("input", { type: "date", className: "condition-rules-date", value: context.conditionRules.dateValue, onChange: function onChange(e) { var value = e.target.value; setContext(function (ctx) { ctx.conditionRules.dateValue = value; }); } })), type === "duplicateValue" && /*#__PURE__*/React.createElement("select", { className: "condition-rules-select", onChange: function onChange(e) { var value = e.target.value; setContext(function (ctx) { ctx.conditionRules.repeatValue = value; }); } }, /*#__PURE__*/React.createElement("option", { value: "0" }, conditionformat.duplicateValue), /*#__PURE__*/React.createElement("option", { value: "1" }, conditionformat.uniqueValue)), (type === "top10" || type === "top10_percent" || type === "last10" || type === "last10_percent") && /*#__PURE__*/React.createElement("div", { className: "condition-rules-project-box" }, type === "top10" || type === "top10_percent" ? conditionformat.top : conditionformat.last, /*#__PURE__*/React.createElement("input", { className: "condition-rules-project-input", type: "number", value: context.conditionRules.projectValue, onChange: function onChange(e) { var value = e.target.value; setContext(function (ctx) { ctx.conditionRules.projectValue = value; }); } }), type === "top10" || type === "last10" ? conditionformat.oneself : "%"), /*#__PURE__*/React.createElement("div", { className: "condition-rules-set-title" }, "".concat(conditionformat.setAs, "\uFF1A")), /*#__PURE__*/React.createElement("div", { className: "condition-rules-setbox" }, /*#__PURE__*/React.createElement("div", { className: "condition-rules-set" }, /*#__PURE__*/React.createElement("div", { className: "condition-rules-color" }, /*#__PURE__*/React.createElement("input", { id: "checkTextColor", type: "checkbox", className: "condition-rules-check", checked: context.conditionRules.textColor.check, onChange: function onChange(e) { var checked = e.target.checked; setContext(function (ctx) { ctx.conditionRules.textColor.check = checked; }); } }), /*#__PURE__*/React.createElement("label", { htmlFor: "checkTextColor", className: "condition-rules-label" }, conditionformat.textColor), /*#__PURE__*/React.createElement("input", { type: "color", className: "condition-rules-select-color", value: colorRules.textColor, onChange: function onChange(e) { var value = e.target.value; setColorRules(produce(function (draft) { draft.textColor = value; })); } }))), /*#__PURE__*/React.createElement("div", { className: "condition-rules-set" }, /*#__PURE__*/React.createElement("div", { className: "condition-rules-color" }, /*#__PURE__*/React.createElement("input", { id: "checkCellColor", type: "checkbox", className: "condition-rules-check", checked: context.conditionRules.cellColor.check, onChange: function onChange(e) { var checked = e.target.checked; setContext(function (ctx) { ctx.conditionRules.cellColor.check = checked; }); } }), /*#__PURE__*/React.createElement("label", { htmlFor: "checkCellColor", className: "condition-rules-label" }, conditionformat.cellColor), /*#__PURE__*/React.createElement("input", { type: "color", className: "condition-rules-select-color", value: colorRules.cellColor, onChange: function onChange(e) { var value = e.target.value; setColorRules(produce(function (draft) { draft.cellColor = value; })); } })))), /*#__PURE__*/React.createElement("div", { className: "button-basic button-primary", onClick: function onClick() { // hideDialog(); close("confirm"); }, tabIndex: 0 }, button.confirm), /*#__PURE__*/React.createElement("div", { className: "button-basic button-close", onClick: function onClick() { // hideDialog(); close("close"); }, tabIndex: 0 }, button.cancel)); }; export default ConditionRules;