@teppen/react-ui 1.7.0 → 1.7.2
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.
- package/dist/cjs/src/file-uploader/hook.js +1 -1
- package/dist/cjs/src/file-uploader/hook.js.map +1 -1
- package/dist/cjs/src/table/cell/ui/cell.js +1 -1
- package/dist/cjs/src/table/copy/components.js +2 -0
- package/dist/cjs/src/table/copy/components.js.map +1 -0
- package/dist/cjs/src/table/copy/hooks.js +1 -1
- package/dist/cjs/src/table/copy/hooks.js.map +1 -1
- package/dist/cjs/src/table/copy/provider.js +1 -1
- package/dist/cjs/src/table/copy/provider.js.map +1 -1
- package/dist/cjs/src/table/paste/hooks.js +1 -1
- package/dist/cjs/src/table/paste/hooks.js.map +1 -1
- package/dist/cjs/src/table/paste/logic.js +2 -0
- package/dist/cjs/src/table/paste/logic.js.map +1 -0
- package/dist/cjs/src/table/range/hooks.js +1 -1
- package/dist/cjs/src/table/range/hooks.js.map +1 -1
- package/dist/cjs/src/table/range/provider.js +1 -1
- package/dist/cjs/src/table/range/provider.js.map +1 -1
- package/dist/cjs/src/table/sheet/components.js +1 -1
- package/dist/cjs/src/table/sheet/components.js.map +1 -1
- package/dist/cjs/src/table/table/base.js +1 -1
- package/dist/esm/src/file-uploader/hook.js +1 -1
- package/dist/esm/src/file-uploader/hook.js.map +1 -1
- package/dist/esm/src/table/cell/ui/cell.js +1 -1
- package/dist/esm/src/table/copy/components.js +2 -0
- package/dist/esm/src/table/copy/components.js.map +1 -0
- package/dist/esm/src/table/copy/hooks.js +1 -1
- package/dist/esm/src/table/copy/hooks.js.map +1 -1
- package/dist/esm/src/table/copy/provider.js +1 -1
- package/dist/esm/src/table/copy/provider.js.map +1 -1
- package/dist/esm/src/table/paste/hooks.js +1 -1
- package/dist/esm/src/table/paste/hooks.js.map +1 -1
- package/dist/esm/src/table/paste/logic.js +2 -0
- package/dist/esm/src/table/paste/logic.js.map +1 -0
- package/dist/esm/src/table/range/hooks.js +1 -1
- package/dist/esm/src/table/range/hooks.js.map +1 -1
- package/dist/esm/src/table/range/provider.js +1 -1
- package/dist/esm/src/table/range/provider.js.map +1 -1
- package/dist/esm/src/table/sheet/components.js +1 -1
- package/dist/esm/src/table/sheet/components.js.map +1 -1
- package/dist/esm/src/table/table/base.js +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react"),i=["image/*","text/*","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.ms-outlook","application/json","application/xml","application/pdf","application/x-compressed","application/x-zip-compressed","application/x-gzip","application/x-bzip2","application/x-tar","application/x-rar-compressed","application/x-7z-compressed","application/zip"];exports.useFileUploader=function(
|
|
1
|
+
"use strict";var e=require("react"),i=["image/*","text/*","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.ms-outlook","application/json","application/xml","application/pdf","application/x-compressed","application/x-zip-compressed","application/x-gzip","application/x-bzip2","application/x-tar","application/x-rar-compressed","application/x-7z-compressed","application/zip"],a=[".msg"];exports.useFileUploader=function(n){var t=e.useRef(null),o=e.useState(!1),r=o[0],p=o[1],c=function(e){var t=function(e){var n=[],t=[];return e.forEach((function(e){var o=e.name.split(".").pop();o&&a.includes(".".concat(o))||i.some((function(i){return e.type.match(i)}))?n.push(e):t.push(e)})),{validFiles:n,rejectedFiles:t}}(e),o=t.validFiles,r=t.rejectedFiles;o.length>0&&n.addFiles(o),r.length>0&&n.onValidationError&&n.onValidationError(r)};return{inputProps:{ref:t,type:"file",multiple:!0,className:"hidden",accept:i.join(","),onChange:function(e){if(e.target.files){var i=Array.from(e.target.files);c(i)}}},isDragging:r,dropSpaceProps:{onClick:function(){var e;return null===(e=t.current)||void 0===e?void 0:e.click()},onDrop:function(e){if(e.preventDefault(),p(!1),e.dataTransfer.files){var i=Array.from(e.dataTransfer.files);c(i)}},onDragOver:function(e){e.preventDefault(),p(!0)},onDragLeave:function(e){p(!1)}}}};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../src/file-uploader/hook.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\n\ninterface IPropsFileUploader {\n addFiles: (files: File[]) => void;\n onValidationError?: (rejectedFiles: File[]) => void;\n}\n\ninterface IReturnFileUploader {\n inputProps: {\n ref: React.RefObject<HTMLInputElement>;\n type: \"file\";\n multiple?: boolean;\n accept?: string;\n className?: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n };\n isDragging: boolean;\n dropSpaceProps: {\n onClick?: React.MouseEventHandler;\n onDrop: (e: React.DragEvent) => void;\n onDragOver: (e: React.DragEvent) => void;\n onDragLeave: (e: React.DragEvent) => void;\n };\n}\n\nconst ACCEPTED_TYPES = [\n \"image/*\", // image\n \"text/*\", // .txt\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\", // .xlsx\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\", // .pptx\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\", // .docx\n \"application/vnd.ms-excel\", // .xls\n \"application/vnd.ms-outlook\", // .msg\n \"application/json\", // .json\n \"application/xml\", // .xml\n \"application/pdf\", // .pdf\n \"application/x-compressed\", // .tgz\n \"application/x-zip-compressed\", // .zip\n \"application/x-gzip\", // .gz\n \"application/x-bzip2\", // .bz2\n \"application/x-tar\", // .tar\n \"application/x-rar-compressed\", // .rar\n \"application/x-7z-compressed\", // .7z\n \"application/zip\", // .zip\n];\n\nexport function useFileUploader(\n props: IPropsFileUploader\n): IReturnFileUploader {\n const inputRef = useRef<HTMLInputElement>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n const validateFiles = (\n files: File[]\n ): { validFiles: File[]; rejectedFiles: File[] } => {\n const validFiles: File[] = [];\n const rejectedFiles: File[] = [];\n\n files.forEach((file) => {\n if (ACCEPTED_TYPES.some((type) => file.type.match(type))) {\n validFiles.push(file);\n } else {\n rejectedFiles.push(file);\n }\n });\n\n return { validFiles, rejectedFiles };\n };\n\n const addFiles = (files: File[]) => {\n const { validFiles, rejectedFiles } = validateFiles(files);\n if (validFiles.length > 0) {\n props.addFiles(validFiles);\n }\n if (rejectedFiles.length > 0 && props.onValidationError) {\n props.onValidationError(rejectedFiles);\n }\n };\n\n const handleDrop = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(false);\n if (e.dataTransfer.files) {\n const droppedFiles = Array.from(e.dataTransfer.files);\n addFiles(droppedFiles);\n }\n };\n\n const handleDragOver = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(true);\n };\n\n const handleDragLeave = (e: React.DragEvent) => {\n setIsDragging(false);\n };\n\n return {\n inputProps: {\n ref: inputRef,\n type: \"file\",\n multiple: true,\n className: \"hidden\",\n accept: ACCEPTED_TYPES.join(\",\"),\n onChange: (e) => {\n if (e.target.files) {\n const selectedFiles = Array.from(e.target.files);\n addFiles(selectedFiles);\n }\n },\n },\n isDragging,\n dropSpaceProps: {\n onClick: () => inputRef.current?.click(),\n onDrop: handleDrop,\n onDragOver: handleDragOver,\n onDragLeave: handleDragLeave,\n },\n };\n}\n"],"names":["ACCEPTED_TYPES","props","inputRef","useRef","_a","useState","isDragging","setIsDragging","addFiles","files","validFiles","rejectedFiles","forEach","file","some","type","match","push","validateFiles","length","onValidationError","inputProps","ref","multiple","className","accept","join","onChange","e","target","selectedFiles","Array","from","dropSpaceProps","onClick","current","click","onDrop","preventDefault","dataTransfer","droppedFiles","onDragOver","onDragLeave"],"mappings":"oCAyBMA,EAAiB,CACrB,UACA,SACA,oEACA,4EACA,0EACA,2BACA,6BACA,mBACA,kBACA,kBACA,2BACA,+BACA,qBACA,sBACA,oBACA,+BACA,8BACA,
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../src/file-uploader/hook.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\n\ninterface IPropsFileUploader {\n addFiles: (files: File[]) => void;\n onValidationError?: (rejectedFiles: File[]) => void;\n}\n\ninterface IReturnFileUploader {\n inputProps: {\n ref: React.RefObject<HTMLInputElement>;\n type: \"file\";\n multiple?: boolean;\n accept?: string;\n className?: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n };\n isDragging: boolean;\n dropSpaceProps: {\n onClick?: React.MouseEventHandler;\n onDrop: (e: React.DragEvent) => void;\n onDragOver: (e: React.DragEvent) => void;\n onDragLeave: (e: React.DragEvent) => void;\n };\n}\n\nconst ACCEPTED_TYPES = [\n \"image/*\", // image\n \"text/*\", // .txt\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\", // .xlsx\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\", // .pptx\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\", // .docx\n \"application/vnd.ms-excel\", // .xls\n \"application/vnd.ms-outlook\", // .msg\n \"application/json\", // .json\n \"application/xml\", // .xml\n \"application/pdf\", // .pdf\n \"application/x-compressed\", // .tgz\n \"application/x-zip-compressed\", // .zip\n \"application/x-gzip\", // .gz\n \"application/x-bzip2\", // .bz2\n \"application/x-tar\", // .tar\n \"application/x-rar-compressed\", // .rar\n \"application/x-7z-compressed\", // .7z\n \"application/zip\", // .zip\n];\n\nconst ALLOWED_EXTENSIONS = [\".msg\"];\n\nexport function useFileUploader(\n props: IPropsFileUploader\n): IReturnFileUploader {\n const inputRef = useRef<HTMLInputElement>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n const validateFiles = (\n files: File[]\n ): { validFiles: File[]; rejectedFiles: File[] } => {\n const validFiles: File[] = [];\n const rejectedFiles: File[] = [];\n\n files.forEach((file) => {\n const extension = file.name.split(\".\").pop();\n if (extension && ALLOWED_EXTENSIONS.includes(`.${extension}`)) {\n validFiles.push(file);\n return;\n }\n if (ACCEPTED_TYPES.some((type) => file.type.match(type))) {\n validFiles.push(file);\n } else {\n rejectedFiles.push(file);\n }\n });\n\n return { validFiles, rejectedFiles };\n };\n\n const addFiles = (files: File[]) => {\n const { validFiles, rejectedFiles } = validateFiles(files);\n if (validFiles.length > 0) {\n props.addFiles(validFiles);\n }\n if (rejectedFiles.length > 0 && props.onValidationError) {\n props.onValidationError(rejectedFiles);\n }\n };\n\n const handleDrop = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(false);\n if (e.dataTransfer.files) {\n const droppedFiles = Array.from(e.dataTransfer.files);\n addFiles(droppedFiles);\n }\n };\n\n const handleDragOver = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(true);\n };\n\n const handleDragLeave = (e: React.DragEvent) => {\n setIsDragging(false);\n };\n\n return {\n inputProps: {\n ref: inputRef,\n type: \"file\",\n multiple: true,\n className: \"hidden\",\n accept: ACCEPTED_TYPES.join(\",\"),\n onChange: (e) => {\n if (e.target.files) {\n const selectedFiles = Array.from(e.target.files);\n addFiles(selectedFiles);\n }\n },\n },\n isDragging,\n dropSpaceProps: {\n onClick: () => inputRef.current?.click(),\n onDrop: handleDrop,\n onDragOver: handleDragOver,\n onDragLeave: handleDragLeave,\n },\n };\n}\n"],"names":["ACCEPTED_TYPES","ALLOWED_EXTENSIONS","props","inputRef","useRef","_a","useState","isDragging","setIsDragging","addFiles","files","validFiles","rejectedFiles","forEach","file","extension","name","split","pop","includes","concat","some","type","match","push","validateFiles","length","onValidationError","inputProps","ref","multiple","className","accept","join","onChange","e","target","selectedFiles","Array","from","dropSpaceProps","onClick","current","click","onDrop","preventDefault","dataTransfer","droppedFiles","onDragOver","onDragLeave"],"mappings":"oCAyBMA,EAAiB,CACrB,UACA,SACA,oEACA,4EACA,0EACA,2BACA,6BACA,mBACA,kBACA,kBACA,2BACA,+BACA,qBACA,sBACA,oBACA,+BACA,8BACA,mBAGIC,EAAqB,CAAC,gCAEtB,SACJ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GAAc,EAChB,EAyBIyC,YAvBoB,SAACd,GACvB3B,GAAc,EAChB,GAwBF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var e=require("react/jsx-runtime"),o=require("../hooks.js");exports.TableCell=function(n){var s=o.useCell(n.id,n.row),l=s.type,t=s.component,i=s.onDoubleClick,c=s.onMouseDown,r=s.onMouseEnter;return e.jsx("td",{id:n.id,className:"".concat(n.cellFormatClassName," select-none"),onDoubleClick:n.isExistOnClickRow?void 0:i,onMouseDown:c,onMouseEnter:r,children:e.jsx("div",{className:"flex items-center gap-3 min-h-10 w-fit p-2 cursor-default",children:"component"===l?t:e.jsx("div",{onDoubleClick:i,children:e.jsx("p",{className:"cell-data text-left whitespace-nowrap",children:t})})})})};
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),o=require("../hooks.js");exports.TableCell=function(n){var s=o.useCell(n.id,n.row),l=s.type,t=s.component,i=s.onDoubleClick,c=s.onMouseDown,r=s.onMouseEnter;return e.jsx("td",{id:n.id,className:"".concat(n.cellFormatClassName," select-none"),onDoubleClick:n.isExistOnClickRow?void 0:i,onMouseDown:c,onMouseEnter:r,children:e.jsx("div",{className:"flex items-center gap-3 min-h-10 w-fit p-2 cursor-default",onClick:function(e){e.stopPropagation()},children:"component"===l?t:e.jsx("div",{onDoubleClick:i,children:e.jsx("p",{className:"cell-data text-left whitespace-nowrap",children:t})})})})};
|
|
3
3
|
//# sourceMappingURL=cell.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("./provider.js"),i=require("../libs/id-generator.js");exports.CopiedMessage=function(){var n=t.useState(!1),a=n[0],o=n[1],s=r.useCopyStateContext().copiedAt;if(t.useEffect((function(){if(s){o(!0);var e=setTimeout((function(){o(!1)}),1e3);return function(){o(!1),clearTimeout(e)}}}),[s]),!a)return e.jsx(e.Fragment,{});var u=document.getElementById(i.IdGenerator.getTableId());if(!u)return e.jsx(e.Fragment,{});var c=u.getBoundingClientRect(),d=c.right-120,f=c.bottom-50;return e.jsx("div",{className:"fixed z-[100] p-1 bg-gray-800 duration-300 pointer-events-none ".concat(a?"opacity-100":"opacity-0"),style:{top:f,left:d},children:e.jsx("p",{className:"text-white text-xs",children:"コピーしました!!!"})})};
|
|
2
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../../../src/table/copy/components.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { useCopyStateContext } from \"./provider\";\nimport { IdGenerator } from \"../libs\";\n\nexport function CopiedMessage() {\n const [isDisplay, setIsDisplay] = useState(false);\n const { copiedAt } = useCopyStateContext();\n\n useEffect(() => {\n if (copiedAt) {\n setIsDisplay(true);\n\n const timer = setTimeout(() => {\n setIsDisplay(false);\n }, 1000);\n\n return () => {\n setIsDisplay(false);\n clearTimeout(timer);\n };\n }\n }, [copiedAt]);\n\n if (!isDisplay) {\n return <></>;\n }\n\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!tableElement) {\n return <></>;\n }\n\n // テーブルの右下の位置を取得\n const rect = tableElement.getBoundingClientRect();\n const x = rect.right - 120;\n const y = rect.bottom - 50;\n\n return (\n <div\n className={`fixed z-[100] p-1 bg-gray-800 duration-300 pointer-events-none ${\n isDisplay ? \"opacity-100\" : \"opacity-0\"\n }`}\n style={{ top: y, left: x }}\n >\n <p className=\"text-white text-xs\">コピーしました!!!</p>\n </div>\n );\n}\n"],"names":["_a","useState","isDisplay","setIsDisplay","copiedAt","useCopyStateContext","useEffect","timer_1","setTimeout","clearTimeout","_jsx","tableElement","document","getElementById","IdGenerator","getTableId","rect","getBoundingClientRect","x","right","y","bottom","className","style","top","left","children","jsx"],"mappings":"oKAKQ,IAAAA,EAA4BC,EAAAA,UAAS,GAApCC,EAASF,EAAA,GAAEG,EAAYH,EAAA,GACtBI,EAAaC,iCAiBrB,GAfAC,EAAAA,WAAU,WACR,GAAIF,EAAU,CACZD,GAAa,GAEb,IAAMI,EAAQC,YAAW,WACvBL,GAAa,EACd,GAAE,KAEH,OAAO,WACLA,GAAa,GACbM,aAAaF,EACf,CACD,CACH,GAAG,CAACH,KAECF,EACH,OAAOQ,qBAGT,IAAMC,EAAeC,SAASC,eAAeC,EAAAA,YAAYC,cAEzD,IAAKJ,EACH,OAAOD,qBAIT,IAAMM,EAAOL,EAAaM,wBACpBC,EAAIF,EAAKG,MAAQ,IACjBC,EAAIJ,EAAKK,OAAS,GAExB,OACEX,MAAA,MAAA,CACEY,UAAW,yEACTpB,EAAY,cAAgB,aAE9BqB,MAAO,CAAEC,IAAKJ,EAAGK,KAAMP,GAEvBQ,SAAAhB,EAAAiB,IAAA,IAAA,CAAGL,UAAU,qBAAmCI,SAAA,gBAGtD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),n=require("react"),t=require("../range/provider.js"),s=function(n,t){switch(t.type){case"setRows":return e.__assign(e.__assign({},n),{rows:t.payload.rows});case"setCols":return e.__assign(e.__assign({},n),{cols:t.payload.cols});case"copied":return e.__assign(e.__assign({},n),{copiedAt:new Date});default:return n}};exports.useCopyReducer=function(r){var o=n.useReducer(s,e.__assign({},r)),a=o[0],i=o[1],c=t.useRangeStateContext(),u=n.useCallback((function(){if(c.isSelecting){var e=c.start.rowIndex<=c.end.rowIndex?c.start.rowIndex:c.end.rowIndex,n=c.start.rowIndex>=c.end.rowIndex?c.start.rowIndex:c.end.rowIndex,t=c.start.colIndex<=c.end.colIndex?c.start.colIndex:c.end.colIndex,s=c.start.colIndex>=c.end.colIndex?c.start.colIndex:c.end.colIndex,r=a.rows.slice(e,n+1).map((function(e){for(var n=[],r=function(t){var s=a.cols[t];if("number"==s.type||"string"==s.type)return n.push(e[s.key]),"continue";if("select"==s.type){var r=e[s.key];null==r||""===r?n.push(""):n.push(s.options.find((function(n){return n.value===e[s.key]})).label)}},o=t;o<=s;o++)r(o);return n})).map((function(e){return e.join("\t")})).join("\n");navigator.clipboard.writeText(r),i({type:"copied"})}}),[c,a.rows,a.cols]),d=n.useCallback((function(e){i({type:"setRows",payload:{rows:e}})}),[]);return{states:n.useMemo((function(){return{copiedAt:a.copiedAt}}),[a.copiedAt]),actions:n.useMemo((function(){return{copy:u,setRows:d}}),[u,d])}};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/copy/hooks.ts"],"sourcesContent":["import { useCallback, useMemo, useReducer } from \"react\";\nimport { useRangeStateContext } from \"../range/provider\";\nimport { TCopyReducer, TReturnCopyReducer } from \"./types\";\n\nconst reducer: TCopyReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n default:\n return state;\n }\n};\n\nexport function useCopyReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TReturnCopyReducer {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n });\n const range = useRangeStateContext();\n\n const copy = useCallback(() => {\n if (!range.isSelecting) {\n return;\n }\n\n const startRowIndex
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/copy/hooks.ts"],"sourcesContent":["import { useCallback, useMemo, useReducer } from \"react\";\nimport { useRangeStateContext } from \"../range/provider\";\nimport { TCopyReducer, TReturnCopyReducer } from \"./types\";\n\nconst reducer: TCopyReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n case \"copied\":\n return { ...state, copiedAt: new Date() };\n default:\n return state;\n }\n};\n\nexport function useCopyReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TReturnCopyReducer {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n });\n const range = useRangeStateContext();\n\n const copy = useCallback(() => {\n if (!range.isSelecting) {\n return;\n }\n\n const startRowIndex =\n range.start.rowIndex <= range.end.rowIndex\n ? range.start.rowIndex\n : range.end.rowIndex;\n const endRowIndex =\n range.start.rowIndex >= range.end.rowIndex\n ? range.start.rowIndex\n : range.end.rowIndex;\n const startColIndex =\n range.start.colIndex <= range.end.colIndex\n ? range.start.colIndex\n : range.end.colIndex;\n const endColIndex =\n range.start.colIndex >= range.end.colIndex\n ? range.start.colIndex\n : range.end.colIndex;\n\n const copiedData = state.rows\n .slice(startRowIndex, endRowIndex + 1)\n .map((row) => {\n const copiedRow = [];\n for (let i = startColIndex; i <= endColIndex; i++) {\n const col = state.cols[i];\n\n if (col.type == \"number\" || col.type == \"string\") {\n copiedRow.push(row[col.key]);\n continue;\n } else if (col.type == \"select\") {\n const value = row[col.key];\n\n if (value === null || value === undefined || value === \"\") {\n copiedRow.push(\"\");\n } else {\n copiedRow.push(\n col.options.find((option) => option.value === row[col.key])!\n .label\n );\n }\n }\n }\n return copiedRow;\n });\n\n const copiedDataString = copiedData.map((row) => row.join(\"\\t\")).join(\"\\n\");\n\n navigator.clipboard.writeText(copiedDataString);\n dispatch({ type: \"copied\" });\n }, [range, state.rows, state.cols]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const states = useMemo(\n () => ({\n copiedAt: state.copiedAt,\n }),\n [state.copiedAt]\n );\n\n const actions = useMemo(\n () => ({\n copy,\n setRows,\n }),\n [copy, setRows]\n );\n\n return {\n states,\n actions,\n };\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","copiedAt","Date","initial","_a","useReducer","dispatch","range","useRangeStateContext","copy","useCallback","isSelecting","startRowIndex","start","rowIndex","end","endRowIndex","startColIndex","colIndex","endColIndex","copiedDataString","slice","map","row","copiedRow","i","col","push","key","value","options","find","option","label","join","navigator","clipboard","writeText","setRows","states","useMemo","actions"],"mappings":"4HAIMA,EAAwB,SAACC,EAAOC,GACpC,OAAQA,EAAOC,MACb,IAAK,UACH,OAAYC,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOI,KAAMH,EAAOI,QAAQD,OAC1C,IAAK,UACH,OAAYD,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOM,KAAML,EAAOI,QAAQC,OAC1C,IAAK,SACH,OAAAH,EAAAA,SAAAA,WAAA,CAAA,EAAYH,GAAO,CAAAO,SAAU,IAAIC,OACnC,QACE,OAAOR,EAEb,yBAEM,SAAyBS,GAKvB,IAAAC,EAAoBC,EAAAA,WAAWZ,EAChCI,EAAAA,SAAA,CAAA,EAAAM,IADET,EAAKU,EAAA,GAAEE,OAGRC,EAAQC,EAAAA,uBAERC,EAAOC,EAAAA,aAAY,WACvB,GAAKH,EAAMI,YAAX,CAIA,IAAMC,EACJL,EAAMM,MAAMC,UAAYP,EAAMQ,IAAID,SAC9BP,EAAMM,MAAMC,SACZP,EAAMQ,IAAID,SACVE,EACJT,EAAMM,MAAMC,UAAYP,EAAMQ,IAAID,SAC9BP,EAAMM,MAAMC,SACZP,EAAMQ,IAAID,SACVG,EACJV,EAAMM,MAAMK,UAAYX,EAAMQ,IAAIG,SAC9BX,EAAMM,MAAMK,SACZX,EAAMQ,IAAIG,SACVC,EACJZ,EAAMM,MAAMK,UAAYX,EAAMQ,IAAIG,SAC9BX,EAAMM,MAAMK,SACZX,EAAMQ,IAAIG,SA4BVE,EA1Ba1B,EAAMI,KACtBuB,MAAMT,EAAeI,EAAc,GACnCM,KAAI,SAACC,GAEJ,IADA,IAAMC,EAAY,cACTC,GACP,IAAMC,EAAMhC,EAAMM,KAAKyB,GAEvB,GAAgB,UAAZC,EAAI9B,MAAgC,UAAZ8B,EAAI9B,YAC9B4B,EAAUG,KAAKJ,EAAIG,EAAIE,iBAElB,GAAgB,UAAZF,EAAI9B,KAAkB,CAC/B,IAAMiC,EAAQN,EAAIG,EAAIE,KAElBC,SAAmD,KAAVA,EAC3CL,EAAUG,KAAK,IAEfH,EAAUG,KACRD,EAAII,QAAQC,MAAK,SAACC,GAAW,OAAAA,EAAOH,QAAUN,EAAIG,EAAIE,IAAzB,IAC1BK,MAGR,GAjBMR,EAAIR,EAAeQ,GAAKN,EAAaM,MAArCA,GAmBT,OAAOD,CACT,IAEkCF,KAAI,SAACC,GAAQ,OAAAA,EAAIW,KAAK,KAAK,IAAEA,KAAK,MAEtEC,UAAUC,UAAUC,UAAUjB,GAC9Bd,EAAS,CAAEV,KAAM,UAhDhB,CAiDH,GAAG,CAACW,EAAOb,EAAMI,KAAMJ,EAAMM,OAEvBsC,EAAU5B,eAAY,SAACZ,GAC3BQ,EAAS,CAAEV,KAAM,UAAWG,QAAS,CAAED,KAAIA,IAC5C,GAAE,IAiBH,MAAO,CACLyC,OAhBaC,WACb,WAAM,MAAC,CACLvC,SAAUP,EAAMO,YAElB,CAACP,EAAMO,WAaPwC,QAVcD,WACd,WAAM,MAAC,CACL/B,KAAIA,EACJ6B,QAAOA,KAET,CAAC7B,EAAM6B,IAOX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("./hooks.js"),o=t.createContext({copiedAt:new Date}),n=t.createContext({copy:function(){},setRows:function(){}});exports.CopyProvider=function(t){var s=t.children,u=t.rows,c=t.cols,i=r.useCopyReducer({rows:u,cols:c}),a=i.states,x=i.actions;return e.jsx(o.Provider,{value:a,children:e.jsx(n.Provider,{value:x,children:s})})},exports.useCopyActionContext=function(){return t.useContext(n)},exports.useCopyStateContext=function(){return t.useContext(o)};
|
|
2
2
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/copy/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { TCopyActionContext } from \"./types\";\nimport { useCopyReducer } from \"./hooks\";\n\nconst CopyActionContext = createContext<TCopyActionContext>({\n copy: () => {},\n setRows: () => {},\n});\n\nexport function CopyProvider({\n children,\n rows,\n cols,\n}: {\n children: JSX.Element | JSX.Element[];\n rows: any[];\n cols: any[];\n}) {\n
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/copy/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { TCopyActionContext, TCopyStateContext } from \"./types\";\nimport { useCopyReducer } from \"./hooks\";\n\nconst CopyStateContext = createContext<TCopyStateContext>({\n copiedAt: new Date(),\n});\n\nconst CopyActionContext = createContext<TCopyActionContext>({\n copy: () => {},\n setRows: () => {},\n});\n\nexport function CopyProvider({\n children,\n rows,\n cols,\n}: {\n children: JSX.Element | JSX.Element[];\n rows: any[];\n cols: any[];\n}) {\n const { states, actions } = useCopyReducer({\n rows,\n cols,\n });\n return (\n <CopyStateContext.Provider value={states}>\n <CopyActionContext.Provider value={actions}>\n {children}\n </CopyActionContext.Provider>\n </CopyStateContext.Provider>\n );\n}\n\nexport function useCopyStateContext() {\n return useContext(CopyStateContext);\n}\n\nexport function useCopyActionContext() {\n return useContext(CopyActionContext);\n}\n"],"names":["CopyStateContext","createContext","copiedAt","Date","CopyActionContext","copy","setRows","_a","children","rows","cols","_b","useCopyReducer","states","actions","_jsx","Provider","value","jsx","useContext"],"mappings":"2FAIMA,EAAmBC,EAAAA,cAAiC,CACxDC,SAAU,IAAIC,OAGVC,EAAoBH,EAAAA,cAAkC,CAC1DI,KAAM,WAAQ,EACdC,QAAS,WAAQ,yBAGb,SAAuBC,GAC3B,IAAAC,aACAC,EAAIF,EAAAE,KACJC,EAAIH,EAAAG,KAMEC,EAAsBC,EAAAA,eAAe,CACzCH,KAAIA,EACJC,KAAIA,IAFEG,EAAMF,EAAAE,OAAEC,YAIhB,OACEC,EAAAA,IAACf,EAAiBgB,SAAS,CAAAC,MAAOJ,EAChCL,SAAAO,EAAAG,IAACd,EAAkBY,SAAS,CAAAC,MAAOH,WAChCN,KAIT,0CAOE,OAAOW,EAAAA,WAAWf,EACpB,yCALE,OAAOe,EAAAA,WAAWnB,EACpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react"),a=require("../sheet/providers.js"),
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react"),a=require("../sheet/providers.js"),s=require("../range/provider.js"),n=require("./logic.js"),o=function(t,a){switch(a.type){case"setRows":return e.__assign(e.__assign({},t),{rows:a.payload.rows});case"setCols":return e.__assign(e.__assign({},t),{cols:a.payload.cols});case"setColValidators":return e.__assign(e.__assign({},t),{colValidators:a.payload.colValidators});case"setOnUpdateRowFunction":return e.__assign(e.__assign({},t),{onUpdateRowFunction:a.payload.onUpdateRowFunction});case"onPaste":if(!t.isFocused)return t;var s=a.payload.pasteData,o=t.rows,r=t.cols,i=t.colValidators,u=t.start,c=t.end,l=t.onUpdateRowFunction,d=t.setRange;if(!l)return t;var p=n.paste({pasteData:s,pasteArea:{start:u,end:c},currentRows:o,currentCols:r,validators:i,tableArea:{start:{rowIndex:0,colIndex:0},end:{rowIndex:o.length-1,colIndex:r.length-1}}});return p.isError?("ValidationError"!==p.type&&"NoPasteData"!==p.type&&alert(p.message),t):(d({start:p.pasteRange.start,end:p.pasteRange.end}),e.__assign(e.__assign({},t),{updateParameters:{arguments:p.updateArgument,timing:t.updateParameters.timing+1}}));case"focus":return e.__assign(e.__assign({},t),{isFocused:!0,start:a.payload.start,end:a.payload.end});case"unfocus":return e.__assign(e.__assign({},t),{isFocused:!1})}};exports.usePasteReducer=function(n){var r=s.useRangeActionContext().setRange,i=t.useReducer(o,e.__assign(e.__assign({},n),{colValidators:{},isFocused:!1,updateParameters:{arguments:[],timing:0},setRange:r})),u=i[0],c=i[1],l=a.useColumnValidatesContext(),d=s.useRangeStateContext();t.useEffect((function(){d.isSelecting?c({type:"focus",payload:{start:d.start,end:d.end}}):c({type:"unfocus"})}),[d]);var p=t.useCallback((function(e){c({type:"setRows",payload:{rows:e}})}),[]),g=t.useCallback((function(e){c({type:"setCols",payload:{cols:e}})}),[]),f=t.useCallback((function(e){c({type:"setColValidators",payload:{colValidators:e}})}),[]);t.useEffect((function(){f(l)}),[l]);var _=t.useCallback((function(e){c({type:"setOnUpdateRowFunction",payload:{onUpdateRowFunction:e}})}),[]),m=t.useCallback((function(e){c({type:"onPaste",payload:{pasteData:e}})}),[]);return t.useEffect((function(){u.updateParameters.arguments.length>0&&u.updateParameters.arguments.forEach((function(e){var t,a=e.newRow,s=e.oldRow;null===(t=u.onUpdateRowFunction)||void 0===t||t.call(u,a,s)}))}),[u.updateParameters.timing,u.onUpdateRowFunction]),t.useEffect((function(){var e=function(e){if(d.isSelecting&&e.clipboardData){e.preventDefault();var t=e.clipboardData.getData("Text");m(t.replace(/\t/g,",").trim().replace(/\r\n/g,"\n").split("\n").map((function(e){return e.split(",")})))}};return document.addEventListener("paste",e),function(){document.removeEventListener("paste",e)}}),[d.isSelecting]),t.useMemo((function(){return{setRows:p,setCols:g,setColValidators:f,setOnUpdateRowFunction:_,onPaste:m}}),[])};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/paste/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useReducer } from \"react\";\nimport { TPasteReducer, TPasteReducerReturn } from \"./types\";\nimport { useColumnValidatesContext } from \"../sheet/providers\";\nimport { useRangeStateContext } from \"../range/provider\";\n\nconst reducer: TPasteReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n case \"setColValidators\":\n return { ...state, colValidators: action.payload.colValidators };\n case \"setOnUpdateRowFunction\":\n return {\n ...state,\n onUpdateRowFunction: action.payload.onUpdateRowFunction,\n };\n case \"onPaste\":\n if (!state.isFocused) {\n return state;\n }\n\n const { pasteData } = action.payload;\n const {\n rows,\n cols,\n colValidators,\n rowIndex,\n colIndex,\n onUpdateRowFunction,\n } = state;\n\n if (!onUpdateRowFunction) {\n return state;\n }\n\n const updateParameters = {\n arguments: [] as { newRow: any; oldRow: any }[],\n timing: state.updateParameters.timing + 1,\n };\n\n const rowLength = pasteData.length;\n const colLength = Math.max(...pasteData.map((row) => row.length));\n\n if (rowLength === 0 || colLength === 0) return state;\n\n if (pasteData.length + rowIndex > rows.length) {\n alert(\"貼り付け先の行数が足りません。\");\n return state;\n }\n\n for (let i = 0; i < colLength; i++) {\n const col = cols[colIndex + i];\n\n if (!col.editable) {\n alert(\n `編集できない列にデータを貼り付けることはできません。\\n\\n編集不可列: ${\n col.label ?? (col.key as string)\n }`\n );\n return state;\n }\n }\n\n if (colLength + colIndex > cols.length) {\n alert(\"貼り付け先の列数が足りません。\");\n return state;\n }\n\n for (let i = 0; i < rowLength; i++) {\n const pasteRow = pasteData[i];\n\n for (let j = 0; j < pasteRow.length; j++) {\n const pasteValue = pasteRow[j];\n const col = cols[colIndex + j];\n const validate = colValidators[col.key as string];\n\n if (!validate(pasteValue)) {\n return state;\n }\n }\n }\n\n pasteData.forEach((pasteRow, i) => {\n const row = { ...rows[rowIndex + i] };\n let checkUpdatedRow = false;\n\n pasteRow.forEach((pasteValue, j) => {\n const col = cols[colIndex + j];\n const value =\n col.type === \"number\"\n ? Number(pasteValue)\n : col.type === \"select\"\n ? pasteValue === \"\"\n ? \"\"\n : col.options.find((option) => option.label === pasteValue)!\n .value\n : pasteValue;\n if (row[col.key] !== value) {\n checkUpdatedRow = true;\n row[col.key] = value;\n }\n });\n\n if (checkUpdatedRow) {\n updateParameters.arguments.push({\n newRow: row,\n oldRow: rows[rowIndex + i],\n });\n }\n });\n\n if (updateParameters.arguments.length > 0) {\n return { ...state, updateParameters };\n } else {\n return state;\n }\n case \"focus\":\n return {\n ...state,\n isFocused: true,\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n };\n case \"unfocus\":\n return { ...state, isFocused: false };\n }\n};\n\nexport function usePasteReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TPasteReducerReturn {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n colValidators: {},\n isFocused: false,\n updateParameters: { arguments: [], timing: 0 },\n });\n const validators = useColumnValidatesContext();\n const range = useRangeStateContext();\n\n useEffect(() => {\n if (range.isSelecting) {\n dispatch({\n type: \"focus\",\n payload: {\n rowIndex: range.start.rowIndex,\n colIndex: range.start.colIndex,\n },\n });\n } else {\n dispatch({ type: \"unfocus\" });\n }\n }, [range]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const setCols = useCallback((cols: any[]) => {\n dispatch({ type: \"setCols\", payload: { cols } });\n }, []);\n\n const setColValidators = useCallback(\n (colValidators: { [key: string]: (value: any) => boolean }) => {\n dispatch({ type: \"setColValidators\", payload: { colValidators } });\n },\n []\n );\n\n useEffect(() => {\n setColValidators(validators);\n }, [validators]);\n\n const setOnUpdateRowFunction = useCallback(\n (onUpdateRowFunction?: (newRow: any, oldRow: any) => void) => {\n dispatch({\n type: \"setOnUpdateRowFunction\",\n payload: { onUpdateRowFunction },\n });\n },\n []\n );\n\n const onPaste = useCallback((pasteData: string[][]) => {\n dispatch({ type: \"onPaste\", payload: { pasteData } });\n }, []);\n\n useEffect(() => {\n if (state.updateParameters.arguments.length > 0) {\n state.updateParameters.arguments.forEach(({ newRow, oldRow }) => {\n state.onUpdateRowFunction?.(newRow, oldRow);\n });\n }\n }, [state.updateParameters.timing, state.onUpdateRowFunction]);\n\n useEffect(() => {\n const paste = (e: ClipboardEvent) => {\n if (!range.isSelecting) {\n return;\n }\n\n if (e.clipboardData) {\n e.preventDefault();\n const pastedData = e.clipboardData.getData(\"Text\");\n\n onPaste(\n pastedData\n .replace(/\\t/g, \",\")\n .trim()\n .replace(/\\r\\n/g, \"\\n\")\n .split(\"\\n\")\n .map((row) => row.split(\",\"))\n );\n }\n };\n\n document.addEventListener(\"paste\", paste);\n\n return () => {\n document.removeEventListener(\"paste\", paste);\n };\n }, [range.isSelecting]);\n\n const actions: TPasteReducerReturn = useMemo(\n () => ({\n setRows,\n setCols,\n setColValidators,\n setOnUpdateRowFunction,\n onPaste,\n }),\n []\n );\n\n return actions;\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","colValidators","onUpdateRowFunction","isFocused","pasteData","rows_1","cols_1","rowIndex_1","rowIndex","colIndex_1","colIndex","updateParameters_1","arguments","timing","updateParameters","rowLength","length","colLength","Math","max","apply","map","row","alert","i","col","editable","concat","_a","label","key","pasteRow","j","pasteValue","validate","forEach","checkUpdatedRow","value","Number","options","find","option","push","newRow","oldRow","initial","useReducer","dispatch","validators","useColumnValidatesContext","range","useRangeStateContext","useEffect","isSelecting","start","setRows","useCallback","setCols","setColValidators","setOnUpdateRowFunction","onPaste","_b","call","paste","e","clipboardData","preventDefault","pastedData","getData","replace","trim","split","document","addEventListener","removeEventListener","useMemo"],"mappings":"+JAKMA,EAAyB,SAACC,EAAOC,SACrC,OAAQA,EAAOC,MACb,IAAK,UACH,OAAYC,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOI,KAAMH,EAAOI,QAAQD,OAC1C,IAAK,UACH,OAAYD,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOM,KAAML,EAAOI,QAAQC,OAC1C,IAAK,mBACH,OAAYH,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOO,cAAeN,EAAOI,QAAQE,gBACnD,IAAK,yBACH,OACKJ,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IACHQ,oBAAqBP,EAAOI,QAAQG,sBAExC,IAAK,UACH,IAAKR,EAAMS,UACT,OAAO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D,KAAM,mBAAoBG,QAAS,CAAEE,cAAaA,IAC9D,GACD,IAGFmD,EAAAA,WAAU,WACRM,EAAiBV,EACnB,GAAG,CAACA,IAEJ,IAAMW,EAAyBH,eAC7B,SAACtD,GACC6C,EAAS,CACPnD,KAAM,yBACNG,QAAS,CAAEG,oBAAmBA,IAEjC,GACD,IAGI0D,EAAUJ,eAAY,SAACpD,GAC3B2C,EAAS,CAAEnD,KAAM,UAAWG,QAAS,CAAEK,UAASA,IACjD,GAAE,IAiDH,OA/CAgD,EAAAA,WAAU,WACJ1D,EAAMoB,iBAAiBF,UAAUI,OAAS,GAC5CtB,EAAMoB,iBAAiBF,UAAUuB,SAAQ,SAACP,SAAEe,EAAMf,EAAAe,OAAEC,EAAMhB,EAAAgB,OAC/B,QAAzBiB,EAAAnE,EAAMQ,2BAAmB,IAAA2D,GAAAA,EAAAC,KAAApE,EAAGiD,EAAQC,EACtC,GAEJ,GAAG,CAAClD,EAAMoB,iBAAiBD,OAAQnB,EAAMQ,sBAEzCkD,EAAAA,WAAU,WACR,IAAMW,EAAQ,SAACC,GACb,GAAKd,EAAMG,aAIPW,EAAEC,cAAe,CACnBD,EAAEE,iBACF,IAAMC,EAAaH,EAAEC,cAAcG,QAAQ,QAE3CR,EACEO,EACGE,QAAQ,MAAO,KACfC,OACAD,QAAQ,QAAS,MACjBE,MAAM,MACNlD,KAAI,SAACC,GAAQ,OAAAA,EAAIiD,MAAM,IAAI,IAEjC,CACH,EAIA,OAFAC,SAASC,iBAAiB,QAASV,GAE5B,WACLS,SAASE,oBAAoB,QAASX,EACxC,CACF,GAAG,CAACb,EAAMG,cAE2BsB,WACnC,WAAM,MAAC,CACLpB,QAAOA,EACPE,QAAOA,EACPC,iBAAgBA,EAChBC,uBAAsBA,EACtBC,QAAOA,EALH,GAON,GAIJ"}
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/paste/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useReducer } from \"react\";\nimport { TPasteReducer, TPasteReducerReturn } from \"./types\";\nimport { useColumnValidatesContext } from \"../sheet/providers\";\nimport { useRangeActionContext, useRangeStateContext } from \"../range/provider\";\nimport { paste } from \"./logic\";\n\nconst reducer: TPasteReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n case \"setColValidators\":\n return { ...state, colValidators: action.payload.colValidators };\n case \"setOnUpdateRowFunction\":\n return {\n ...state,\n onUpdateRowFunction: action.payload.onUpdateRowFunction,\n };\n case \"onPaste\":\n if (!state.isFocused) {\n return state;\n }\n\n const { pasteData } = action.payload;\n const {\n rows,\n cols,\n colValidators,\n start,\n end,\n onUpdateRowFunction,\n setRange,\n } = state;\n\n if (!onUpdateRowFunction) {\n return state;\n }\n\n const res = paste({\n pasteData,\n pasteArea: { start, end },\n currentRows: rows,\n currentCols: cols,\n validators: colValidators,\n tableArea: {\n start: {\n rowIndex: 0,\n colIndex: 0,\n },\n end: {\n rowIndex: rows.length - 1,\n colIndex: cols.length - 1,\n },\n },\n });\n\n if (res.isError) {\n if (res.type !== \"ValidationError\" && res.type !== \"NoPasteData\") {\n alert(res.message);\n }\n return state;\n }\n\n setRange({\n start: res.pasteRange.start,\n end: res.pasteRange.end,\n });\n\n return {\n ...state,\n updateParameters: {\n arguments: res.updateArgument,\n timing: state.updateParameters.timing + 1,\n },\n };\n case \"focus\":\n return {\n ...state,\n isFocused: true,\n start: action.payload.start,\n end: action.payload.end,\n };\n case \"unfocus\":\n return { ...state, isFocused: false };\n }\n};\n\nexport function usePasteReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TPasteReducerReturn {\n const { setRange } = useRangeActionContext();\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n colValidators: {},\n isFocused: false,\n updateParameters: { arguments: [], timing: 0 },\n setRange,\n });\n const validators = useColumnValidatesContext();\n const range = useRangeStateContext();\n\n useEffect(() => {\n if (range.isSelecting) {\n dispatch({\n type: \"focus\",\n payload: {\n start: range.start,\n end: range.end,\n },\n });\n } else {\n dispatch({ type: \"unfocus\" });\n }\n }, [range]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const setCols = useCallback((cols: any[]) => {\n dispatch({ type: \"setCols\", payload: { cols } });\n }, []);\n\n const setColValidators = useCallback(\n (colValidators: { [key: string]: (value: any) => boolean }) => {\n dispatch({ type: \"setColValidators\", payload: { colValidators } });\n },\n []\n );\n\n useEffect(() => {\n setColValidators(validators);\n }, [validators]);\n\n const setOnUpdateRowFunction = useCallback(\n (onUpdateRowFunction?: (newRow: any, oldRow: any) => void) => {\n dispatch({\n type: \"setOnUpdateRowFunction\",\n payload: { onUpdateRowFunction },\n });\n },\n []\n );\n\n const onPaste = useCallback((pasteData: string[][]) => {\n dispatch({ type: \"onPaste\", payload: { pasteData } });\n }, []);\n\n useEffect(() => {\n if (state.updateParameters.arguments.length > 0) {\n state.updateParameters.arguments.forEach(({ newRow, oldRow }) => {\n state.onUpdateRowFunction?.(newRow, oldRow);\n });\n }\n }, [state.updateParameters.timing, state.onUpdateRowFunction]);\n\n useEffect(() => {\n const paste = (e: ClipboardEvent) => {\n if (!range.isSelecting) {\n return;\n }\n\n if (e.clipboardData) {\n e.preventDefault();\n const pastedData = e.clipboardData.getData(\"Text\");\n\n onPaste(\n pastedData\n .replace(/\\t/g, \",\")\n .trim()\n .replace(/\\r\\n/g, \"\\n\")\n .split(\"\\n\")\n .map((row) => row.split(\",\"))\n );\n }\n };\n\n document.addEventListener(\"paste\", paste);\n\n return () => {\n document.removeEventListener(\"paste\", paste);\n };\n }, [range.isSelecting]);\n\n const actions: TPasteReducerReturn = useMemo(\n () => ({\n setRows,\n setCols,\n setColValidators,\n setOnUpdateRowFunction,\n onPaste,\n }),\n []\n );\n\n return actions;\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","colValidators","onUpdateRowFunction","isFocused","pasteData","start","end","setRange","res","paste","pasteArea","currentRows","currentCols","validators","tableArea","rowIndex","colIndex","length","isError","alert","message","pasteRange","updateParameters","arguments","updateArgument","timing","initial","useRangeActionContext","_a","useReducer","dispatch","useColumnValidatesContext","range","useRangeStateContext","useEffect","isSelecting","setRows","useCallback","setCols","setColValidators","setOnUpdateRowFunction","onPaste","forEach","newRow","oldRow","_b","call","e","clipboardData","preventDefault","pastedData","getData","replace","trim","split","map","row","document","addEventListener","removeEventListener","useMemo"],"mappings":"uLAMMA,EAAyB,SAACC,EAAOC,GACrC,OAAQA,EAAOC,MACb,IAAK,UACH,OAAYC,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOI,KAAMH,EAAOI,QAAQD,OAC1C,IAAK,UACH,OAAYD,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOM,KAAML,EAAOI,QAAQC,OAC1C,IAAK,mBACH,OAAYH,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IAAOO,cAAeN,EAAOI,QAAQE,gBACnD,IAAK,yBACH,OACKJ,WAAAA,EAAAA,SAAA,CAAA,EAAAH,IACHQ,oBAAqBP,EAAOI,QAAQG,sBAExC,IAAK,UACH,IAAKR,EAAMS,UACT,OAAOT,EAGD,IAAAU,EAAcT,EAAOI,kBAE3BD,EAOEJ,EAAKI,KANPE,EAMEN,EAAKM,KALPC,EAKEP,EAAKO,cAJPI,EAIEX,EAAKW,MAHPC,EAGEZ,MAFFQ,EAEER,sBADFa,EACEb,WAEJ,IAAKQ,EACH,OAAOR,EAGT,IAAMc,EAAMC,EAAAA,MAAM,CAChBL,UAASA,EACTM,UAAW,CAAEL,QAAOC,OACpBK,YAAab,EACbc,YAAaZ,EACba,WAAYZ,EACZa,UAAW,CACTT,MAAO,CACLU,SAAU,EACVC,SAAU,GAEZV,IAAK,CACHS,SAAUjB,EAAKmB,OAAS,EACxBD,SAAUhB,EAAKiB,OAAS,MAK9B,OAAIT,EAAIU,SAC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,cAAaA,IAC9D,GACD,IAGFiC,EAAAA,WAAU,WACRK,EAAiB1B,EACnB,GAAG,CAACA,IAEJ,IAAM2B,EAAyBH,eAC7B,SAACnC,GACC4B,EAAS,CACPlC,KAAM,yBACNG,QAAS,CAAEG,oBAAmBA,IAEjC,GACD,IAGIuC,EAAUJ,eAAY,SAACjC,GAC3B0B,EAAS,CAAElC,KAAM,UAAWG,QAAS,CAAEK,UAASA,IACjD,GAAE,IAiDH,OA/CA8B,EAAAA,WAAU,WACJxC,EAAM4B,iBAAiBC,UAAUN,OAAS,GAC5CvB,EAAM4B,iBAAiBC,UAAUmB,SAAQ,SAACd,SAAEe,EAAMf,EAAAe,OAAEC,EAAMhB,EAAAgB,OAC/B,QAAzBC,EAAAnD,EAAMQ,2BAAmB,IAAA2C,GAAAA,EAAAC,KAAApD,EAAGiD,EAAQC,EACtC,GAEJ,GAAG,CAAClD,EAAM4B,iBAAiBG,OAAQ/B,EAAMQ,sBAEzCgC,EAAAA,WAAU,WACR,IAAMzB,EAAQ,SAACsC,GACb,GAAKf,EAAMG,aAIPY,EAAEC,cAAe,CACnBD,EAAEE,iBACF,IAAMC,EAAaH,EAAEC,cAAcG,QAAQ,QAE3CV,EACES,EACGE,QAAQ,MAAO,KACfC,OACAD,QAAQ,QAAS,MACjBE,MAAM,MACNC,KAAI,SAACC,GAAQ,OAAAA,EAAIF,MAAM,IAAI,IAEjC,CACH,EAIA,OAFAG,SAASC,iBAAiB,QAASjD,GAE5B,WACLgD,SAASE,oBAAoB,QAASlD,EACxC,CACF,GAAG,CAACuB,EAAMG,cAE2ByB,WACnC,WAAM,MAAC,CACLxB,QAAOA,EACPE,QAAOA,EACPC,iBAAgBA,EAChBC,uBAAsBA,EACtBC,QAAOA,EALH,GAON,GAIJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js");exports.paste=function(r){var t,a=r.pasteData.length,s=Math.max.apply(Math,r.pasteData.map((function(e){return e.length})));if(0===a||0===s)return{isError:!0,type:"NoPasteData",message:"ペーストデータがありません。"};var n=r.pasteArea.end.rowIndex-r.pasteArea.start.rowIndex+1,o=r.pasteArea.end.colIndex-r.pasteArea.start.colIndex+1,l=n<a?a:n,p=o<s?s:o;if(l+r.pasteArea.start.rowIndex>r.currentRows.length)return{isError:!0,type:"OtherError",message:"貼り付け先の行数が足りません。"};if(p+r.pasteArea.start.colIndex>r.currentCols.length)return{isError:!0,type:"OtherError",message:"貼り付け先の列数が足りません。"};for(var d=0;d<p;d++){if(!(I=r.currentCols[r.pasteArea.start.colIndex+d]).editable)return{isError:!0,type:"OtherError",message:"編集できない列にデータを貼り付けることはできません。\n\n編集不可列: ".concat(null!==(t=I.label)&&void 0!==t?t:I.key)}}for(d=0;d<a;d++)for(var u=r.pasteData[d],c=0;c<p;c++){var i=c%u.length,x=u[i],I=r.currentCols[r.pasteArea.start.colIndex+c];if(!(0,r.validators[I.key])(x))return{isError:!0,type:"ValidationError",message:"バリデーションエラー: ".concat(x)}}var A=[];for(d=0;d<l;d++){u=r.pasteData[d%a];var f=e.__assign({},r.currentRows[r.pasteArea.start.rowIndex+d]),w=!1,g=function(e){var t=u[e%u.length],a=r.currentCols[r.pasteArea.start.colIndex+e],s="number"===a.type?Number(t):"select"===a.type?""===t?"":a.options.find((function(e){return e.label===t})).value:t;f[a.key]!==s&&(w=!0,f[a.key]=s)};for(c=0;c<p;c++)g(c);w&&A.push({newRow:f,oldRow:r.currentRows[r.pasteArea.start.rowIndex+d]})}return{isError:!1,updateArgument:A,pasteRange:{start:{rowIndex:r.pasteArea.start.rowIndex,colIndex:r.pasteArea.start.colIndex},end:{rowIndex:r.pasteArea.start.rowIndex+l-1,colIndex:r.pasteArea.start.colIndex+p-1}}}};
|
|
2
|
+
//# sourceMappingURL=logic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic.js","sources":["../../../../../src/table/paste/logic.ts"],"sourcesContent":["import { TTableColumn } from \"../table/type\";\n\ntype TPasteArgument = {\n pasteData: string[][];\n currentRows: any[];\n currentCols: TTableColumn<any>[];\n tableArea: {\n start: {\n rowIndex: number;\n colIndex: number;\n };\n end: {\n rowIndex: number;\n colIndex: number;\n };\n };\n pasteArea: {\n start: {\n rowIndex: number;\n colIndex: number;\n };\n end: {\n rowIndex: number;\n colIndex: number;\n };\n };\n validators: {\n [key: string]: (value: any) => boolean;\n };\n};\n\ntype TPasteResult =\n | {\n isError: true;\n type: \"ValidationError\" | \"NoPasteData\" | \"OtherError\";\n message: string;\n }\n | {\n isError: false;\n updateArgument: {\n newRow: any;\n oldRow: any;\n }[];\n pasteRange: {\n start: {\n rowIndex: number;\n colIndex: number;\n };\n end: {\n rowIndex: number;\n colIndex: number;\n };\n };\n };\n\nexport function paste(args: TPasteArgument): TPasteResult {\n // ペーストデータの行数と列数を取得\n const pasteDataRowLength = args.pasteData.length;\n const pasteDataColLength = Math.max(\n ...args.pasteData.map((row) => row.length)\n );\n\n // ペーストデータが空の場合は何もしない\n if (pasteDataRowLength === 0 || pasteDataColLength === 0) {\n return {\n isError: true,\n type: \"NoPasteData\",\n message: \"ペーストデータがありません。\",\n };\n }\n\n // Rangeの種類を取得\n const rangeRowLength =\n args.pasteArea.end.rowIndex - args.pasteArea.start.rowIndex + 1;\n const rangeColLength =\n args.pasteArea.end.colIndex - args.pasteArea.start.colIndex + 1;\n\n const pasteRowLength =\n rangeRowLength < pasteDataRowLength ? pasteDataRowLength : rangeRowLength;\n const pasteColLength =\n rangeColLength < pasteDataColLength ? pasteDataColLength : rangeColLength;\n\n // ペースト先の行数が足りない場合はエラー\n if (\n pasteRowLength + args.pasteArea.start.rowIndex >\n args.currentRows.length\n ) {\n return {\n isError: true,\n type: \"OtherError\",\n message: \"貼り付け先の行数が足りません。\",\n };\n }\n // ペースト先の列数が足りない場合はエラー\n if (\n pasteColLength + args.pasteArea.start.colIndex >\n args.currentCols.length\n ) {\n return {\n isError: true,\n type: \"OtherError\",\n message: \"貼り付け先の列数が足りません。\",\n };\n }\n\n // ペースト先の列に編集不可列が含まれている場合はエラー\n for (let i = 0; i < pasteColLength; i++) {\n const col = args.currentCols[args.pasteArea.start.colIndex + i];\n\n if (!col.editable) {\n return {\n isError: true,\n type: \"OtherError\",\n message: `編集できない列にデータを貼り付けることはできません。\\n\\n編集不可列: ${\n col.label ?? (col.key as string)\n }`,\n };\n }\n }\n\n // ペーストデータのバリデーション\n for (let i = 0; i < pasteDataRowLength; i++) {\n const pasteRow = args.pasteData[i];\n\n for (let j = 0; j < pasteColLength; j++) {\n const colIndexForData = j % pasteRow.length;\n const pasteValue = pasteRow[colIndexForData];\n const col = args.currentCols[args.pasteArea.start.colIndex + j];\n const validate = args.validators[col.key as string];\n\n if (!validate(pasteValue)) {\n return {\n isError: true,\n type: \"ValidationError\",\n message: `バリデーションエラー: ${pasteValue}`,\n };\n }\n }\n }\n\n const updateArguments: { newRow: any; oldRow: any }[] = [];\n\n // ペーストデータを反映\n for (let i = 0; i < pasteRowLength; i++) {\n const pasteRow = args.pasteData[i % pasteDataRowLength];\n const newRow = { ...args.currentRows[args.pasteArea.start.rowIndex + i] };\n let checkUpdatedRow = false;\n\n for (let j = 0; j < pasteColLength; j++) {\n const pasteValue = pasteRow[j % pasteRow.length];\n const col = args.currentCols[args.pasteArea.start.colIndex + j];\n const value =\n col.type === \"number\"\n ? Number(pasteValue)\n : col.type === \"select\"\n ? pasteValue === \"\"\n ? \"\"\n : col.options.find((option) => option.label === pasteValue)!.value\n : pasteValue;\n if (newRow[col.key] !== value) {\n checkUpdatedRow = true;\n newRow[col.key] = value;\n }\n }\n\n if (checkUpdatedRow) {\n updateArguments.push({\n newRow,\n oldRow: args.currentRows[args.pasteArea.start.rowIndex + i],\n });\n }\n }\n\n return {\n isError: false,\n updateArgument: updateArguments,\n pasteRange: {\n start: {\n rowIndex: args.pasteArea.start.rowIndex,\n colIndex: args.pasteArea.start.colIndex,\n },\n end: {\n rowIndex: args.pasteArea.start.rowIndex + pasteRowLength - 1,\n colIndex: args.pasteArea.start.colIndex + pasteColLength - 1,\n },\n },\n };\n}\n"],"names":["args","pasteDataRowLength","pasteData","length","pasteDataColLength","Math","max","map","row","isError","type","message","rangeRowLength","pasteArea","end","rowIndex","start","rangeColLength","colIndex","pasteRowLength","pasteColLength","currentRows","currentCols","i","col","editable","concat","_a","label","key","pasteRow","j","colIndexForData","pasteValue","validate","validators","updateArguments","newRow","__assign","checkUpdatedRow","value","Number","options","find","option","push","oldRow","updateArgument","pasteRange"],"mappings":"qFAuDM,SAAgBA,SAEdC,EAAqBD,EAAKE,UAAUC,OACpCC,EAAqBC,KAAKC,UAALD,KACtBL,EAAKE,UAAUK,KAAI,SAACC,GAAQ,OAAAA,EAAIL,MAAM,KAI3C,GAA2B,IAAvBF,GAAmD,IAAvBG,EAC9B,MAAO,CACLK,SAAS,EACTC,KAAM,cACNC,QAAS,kBAKb,IAAMC,EACJZ,EAAKa,UAAUC,IAAIC,SAAWf,EAAKa,UAAUG,MAAMD,SAAW,EAC1DE,EACJjB,EAAKa,UAAUC,IAAII,SAAWlB,EAAKa,UAAUG,MAAME,SAAW,EAE1DC,EACJP,EAAiBX,EAAqBA,EAAqBW,EACvDQ,EACJH,EAAiBb,EAAqBA,EAAqBa,EAG7D,GACEE,EAAiBnB,EAAKa,UAAUG,MAAMD,SACtCf,EAAKqB,YAAYlB,OAEjB,MAAO,CACLM,SAAS,EACTC,KAAM,aACNC,QAAS,mBAIb,GACES,EAAiBpB,EAAKa,UAAUG,MAAME,SACtClB,EAAKsB,YAAYnB,OAEjB,MAAO,CACLM,SAAS,EACTC,KAAM,aACNC,QAAS,mBAKb,IAAK,IAAIY,EAAI,EAAGA,EAAIH,EAAgBG,IAAK,CAGvC,KAFMC,EAAMxB,EAAKsB,YAAYtB,EAAKa,UAAUG,MAAME,SAAWK,IAEpDE,SACP,MAAO,CACLhB,SAAS,EACTC,KAAM,aACNC,QAAS,wCACPe,OAAc,QAAdC,EAAAH,EAAII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,MAAMD,SAC/BG,SAAUlB,EAAKa,UAAUG,MAAME,UAEjCJ,IAAK,CACHC,SAAUf,EAAKa,UAAUG,MAAMD,SAAWI,EAAiB,EAC3DD,SAAUlB,EAAKa,UAAUG,MAAME,SAAWE,EAAiB,IAInE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react"),n=require("../libs/id-generator.js");function i(e){return{maxColIndex:e.maxColIndex<-1?-1:e.maxColIndex,maxRowIndex:e.maxRowIndex<-1?-1:e.maxRowIndex}}function o(e){var t=e.rowIndex,n=e.colIndex;return t<0?t=0:e.constraint.maxRowIndex<t&&(t=e.constraint.maxRowIndex),n<0?n=0:e.constraint.maxColIndex<n&&(n=e.constraint.maxColIndex),{rowIndex:t,colIndex:n}}function s(e,t){return e.rowIndex===t.rowIndex&&e.colIndex===t.colIndex}var
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react"),n=require("../libs/id-generator.js");function i(e){return{maxColIndex:e.maxColIndex<-1?-1:e.maxColIndex,maxRowIndex:e.maxRowIndex<-1?-1:e.maxRowIndex}}function o(e){var t=e.rowIndex,n=e.colIndex;return t<0?t=0:e.constraint.maxRowIndex<t&&(t=e.constraint.maxRowIndex),n<0?n=0:e.constraint.maxColIndex<n&&(n=e.constraint.maxColIndex),{rowIndex:t,colIndex:n}}function s(e,t){return e.rowIndex===t.rowIndex&&e.colIndex===t.colIndex}var a={UP:{deltaRow:-1,deltaCol:0},DOWN:{deltaRow:1,deltaCol:0},LEFT:{deltaRow:0,deltaCol:-1},RIGHT:{deltaRow:0,deltaCol:1}};function r(e){var t=e.index,n=e.direction,i=e.constraint,s=a[n],r=s.deltaRow,d=s.deltaCol;return o({rowIndex:t.rowIndex+r,colIndex:t.colIndex+d,constraint:i})}var d=function(t,n){switch(n.type){case"setMax":return e.__assign(e.__assign({},t),{constraint:i(n.payload)});case"startSelectRange":var a=o({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return t.isSelecting&&s(t.start,a)&&s(t.end,a)&&t.inProgress?t:e.__assign(e.__assign({},t),{isSelecting:!0,inProgress:!0,start:a,end:a});case"moveSelectRange":if(!t.isSelecting||!t.inProgress)return t;var d=o({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return s(t.end,d)?t:e.__assign(e.__assign({},t),{end:d});case"endSelectRange":return t.isSelecting&&t.inProgress?e.__assign(e.__assign({},t),{inProgress:!1}):t;case"moveUp":return t.isSelecting?s(a=r({index:t.start,direction:"UP",constraint:t.constraint}),t.start)&&s(a,t.end)?t:e.__assign(e.__assign({},t),{start:a,end:a}):t;case"moveDown":return t.isSelecting?s(a=r({index:t.start,direction:"DOWN",constraint:t.constraint}),t.start)&&s(a,t.end)?t:e.__assign(e.__assign({},t),{start:a,end:a}):t;case"moveLeft":return t.isSelecting?s(a=r({index:t.start,direction:"LEFT",constraint:t.constraint}),t.start)&&s(a,t.end)?t:e.__assign(e.__assign({},t),{start:a,end:a}):t;case"moveRight":return t.isSelecting?s(a=r({index:t.start,direction:"RIGHT",constraint:t.constraint}),t.start)&&s(a,t.end)?t:e.__assign(e.__assign({},t),{start:a,end:a}):t;case"extendUp":return t.isSelecting?s(d=r({index:t.end,direction:"UP",constraint:t.constraint}),t.end)?t:e.__assign(e.__assign({},t),{end:d}):t;case"extendDown":return t.isSelecting?s(d=r({index:t.end,direction:"DOWN",constraint:t.constraint}),t.end)?t:e.__assign(e.__assign({},t),{end:d}):t;case"extendLeft":return t.isSelecting?s(d=r({index:t.end,direction:"LEFT",constraint:t.constraint}),t.end)?t:e.__assign(e.__assign({},t),{end:d}):t;case"extendRight":return t.isSelecting?s(d=r({index:t.end,direction:"RIGHT",constraint:t.constraint}),t.end)?t:e.__assign(e.__assign({},t),{end:d}):t;case"reset":return{constraint:t.constraint,isSelecting:!1};case"setRange":return e.__assign(e.__assign({},t),{isSelecting:!0,inProgress:!1,start:n.payload.start,end:n.payload.end})}};exports.rangeReducer=d,exports.useRangeReducer=function(){var o=t.useReducer(d,{constraint:i({maxColIndex:0,maxRowIndex:0}),isSelecting:!1}),s=o[0],a=o[1],r=t.useMemo((function(){return{setMax:function(e){a({type:"setMax",payload:e})},startSelectRange:function(e){a({type:"startSelectRange",payload:e})},moveSelectRange:function(e){a({type:"moveSelectRange",payload:e})},endSelectRange:function(){a({type:"endSelectRange"})},moveUp:function(){a({type:"moveUp"})},moveDown:function(){a({type:"moveDown"})},moveLeft:function(){a({type:"moveLeft"})},moveRight:function(){a({type:"moveRight"})},extendUp:function(){a({type:"extendUp"})},extendDown:function(){a({type:"extendDown"})},extendLeft:function(){a({type:"extendLeft"})},extendRight:function(){a({type:"extendRight"})},reset:function(){a({type:"reset"})},setRange:function(e){a({type:"setRange",payload:e})}}}),[]);return t.useEffect((function(){var e=function(e){var t=document.getElementById(n.IdGenerator.getTableId()),i=e.target;i instanceof Node&&(null==t?void 0:t.contains(i))||a({type:"reset"})};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[]),{state:t.useMemo((function(){if(!s.isSelecting)return s;var t=document.getElementById(n.IdGenerator.getTableCellId(s.start.rowIndex,s.start.colIndex)),i=document.getElementById(n.IdGenerator.getTableCellId(s.end.rowIndex,s.end.colIndex)),o=document.getElementById(n.IdGenerator.getTableId());if(!t||!i||!o)return a({type:"reset"}),{isSelecting:!1};var r=t.getBoundingClientRect(),d=i.getBoundingClientRect(),c=o.getBoundingClientRect(),l=c.top-o.scrollTop-window.scrollY,g=c.left-o.scrollLeft-window.scrollX,x={top:r.top-l,left:r.left-g,width:r.width,height:r.height},u={top:d.top-l,left:d.left-g,width:d.width,height:d.height};return{isSelecting:!0,start:e.__assign(e.__assign({},s.start),{xStart:x.left,xEnd:x.left+x.width,yStart:x.top,yEnd:x.top+x.height}),end:e.__assign(e.__assign({},s.end),{xStart:u.left,xEnd:u.left+u.width,yStart:u.top,yEnd:u.top+u.height}),rangeBox:{top:Math.min(x.top,u.top),left:Math.min(x.left,u.left),width:Math.abs(x.left-u.left)+(x.left<=u.left?u.width:x.width),height:Math.abs(x.top-u.top)+(x.top<=u.top?u.height:x.height)}}}),[s]),actions:r}};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/range/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useReducer } from \"react\";\nimport {\n IIndex,\n TRangeReducer,\n IRangeConstraint,\n TReturnRangeReducer,\n} from \"./type\";\nimport { IdGenerator } from \"../libs\";\n\nfunction newRangeConstraint(props: {\n maxColIndex: number;\n maxRowIndex: number;\n}): IRangeConstraint {\n return {\n maxColIndex: props.maxColIndex < -1 ? -1 : props.maxColIndex,\n maxRowIndex: props.maxRowIndex < -1 ? -1 : props.maxRowIndex,\n };\n}\n\nfunction newIndex(props: {\n rowIndex: number;\n colIndex: number;\n constraint: IRangeConstraint;\n}): IIndex {\n let rowIndex = props.rowIndex;\n let colIndex = props.colIndex;\n\n if (rowIndex < 0) {\n rowIndex = 0;\n } else if (props.constraint.maxRowIndex < rowIndex) {\n rowIndex = props.constraint.maxRowIndex;\n }\n\n if (colIndex < 0) {\n colIndex = 0;\n } else if (props.constraint.maxColIndex < colIndex) {\n colIndex = props.constraint.maxColIndex;\n }\n\n return { rowIndex, colIndex };\n}\n\nfunction equalIndex(a: IIndex, b: IIndex): boolean {\n return a.rowIndex === b.rowIndex && a.colIndex === b.colIndex;\n}\n\nconst MOVE_ACTION = {\n UP: { deltaRow: -1, deltaCol: 0 },\n DOWN: { deltaRow: 1, deltaCol: 0 },\n LEFT: { deltaRow: 0, deltaCol: -1 },\n RIGHT: { deltaRow: 0, deltaCol: 1 },\n} as const;\n\ntype TMoveAction = keyof typeof MOVE_ACTION;\n\nfunction moveIndex({\n index,\n direction,\n constraint,\n}: {\n index: IIndex;\n direction: TMoveAction;\n constraint: IRangeConstraint;\n}): IIndex {\n const { deltaRow, deltaCol } = MOVE_ACTION[direction];\n\n const newRow = index.rowIndex + deltaRow;\n const newCol = index.colIndex + deltaCol;\n\n return newIndex({\n rowIndex: newRow,\n colIndex: newCol,\n constraint,\n });\n}\n\nexport const rangeReducer: TRangeReducer = (state, action) => {\n switch (action.type) {\n /**\n * Actionが\"setMax\"の場合の説明:\n * - Actionのtypeが\"setMax\"の場合、選択範囲の最大値を設定します。\n * - payloadのmaxRowIndexとmaxColIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、constraintを新しい範囲制約に設定します。\n */\n case \"setMax\":\n return {\n ...state,\n constraint: newRangeConstraint(action.payload),\n };\n\n /**\n * Actionが\"start\"の場合の説明:\n * - Actionのtypeが\"start\"の場合、選択範囲の開始位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、isSelectingをtrueに設定し、startとendの位置をpayloadの位置に設定します。\n */\n case \"startSelectRange\": {\n const startIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (\n state.isSelecting &&\n equalIndex(state.start, startIndex) &&\n equalIndex(state.end, startIndex) &&\n state.inProgress\n ) {\n return state;\n }\n\n return {\n ...state,\n isSelecting: true,\n inProgress: true,\n start: startIndex,\n end: startIndex,\n };\n }\n\n case \"moveSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n const endIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (equalIndex(state.end, endIndex)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"end\"の場合の説明:\n * - Actionのtypeが\"end\"の場合、選択範囲の終了位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、endの位置をpayloadの位置に設定します。\n * - この場合、isSelectingはtrueのままです。\n */\n case \"endSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n return {\n ...state,\n inProgress: false,\n };\n }\n\n /**\n * Actionが\"moveUp\"の場合の説明:\n * - Actionのtypeが\"moveUp\"の場合、選択範囲を上に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に移動します。\n */\n case \"moveUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveDown\"の場合の説明:\n * - Actionのtypeが\"moveDown\"の場合、選択範囲を下に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に移動します。\n */\n case \"moveDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveLeft\"の場合の説明:\n * - Actionのtypeが\"moveLeft\"の場合、選択範囲を左に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に移動します。\n */\n case \"moveLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveRight\"の場合の説明:\n * - Actionのtypeが\"moveRight\"の場合、選択範囲を右に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に移動します。\n */\n case \"moveRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"extendUp\"の場合の説明:\n * - Actionのtypeが\"extendUp\"の場合、選択範囲を上に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に拡張します。\n */\n case \"extendUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendDown\"の場合の説明:\n * - Actionのtypeが\"extendDown\"の場合、選択範囲を下に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に拡張します。\n */\n case \"extendDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendLeft\"の場合の説明:\n * - Actionのtypeが\"extendLeft\"の場合、選択範囲を左に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に拡張します。\n */\n case \"extendLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendRight\"の場合の説明:\n * - Actionのtypeが\"extendRight\"の場合、選択範囲を右に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に拡張します。\n */\n case \"extendRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"reset\"の場合の説明:\n * - Actionのtypeが\"reset\"の場合、選択範囲をリセットします。\n * - isSelectingをfalseに設定します。\n */\n case \"reset\":\n return {\n constraint: state.constraint,\n isSelecting: false,\n };\n }\n};\n\nexport function useRangeReducer(): TReturnRangeReducer {\n const [state, dispatch] = useReducer(rangeReducer, {\n constraint: newRangeConstraint({ maxColIndex: 0, maxRowIndex: 0 }),\n isSelecting: false,\n });\n\n const actions = useMemo(\n () => ({\n setMax: (payload: { maxRowIndex: number; maxColIndex: number }) => {\n dispatch({ type: \"setMax\", payload });\n },\n startSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"startSelectRange\", payload });\n },\n moveSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"moveSelectRange\", payload });\n },\n endSelectRange: () => {\n dispatch({ type: \"endSelectRange\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n extendUp: () => {\n dispatch({ type: \"extendUp\" });\n },\n extendDown: () => {\n dispatch({ type: \"extendDown\" });\n },\n extendLeft: () => {\n dispatch({ type: \"extendLeft\" });\n },\n extendRight: () => {\n dispatch({ type: \"extendRight\" });\n },\n reset: () => {\n dispatch({ type: \"reset\" });\n },\n }),\n []\n );\n\n useEffect(() => {\n const onClickOutOfTable = (e: MouseEvent) => {\n const element = document.getElementById(IdGenerator.getTableId());\n const ele = e.target;\n if (ele instanceof Node && element?.contains(ele)) return;\n dispatch({ type: \"reset\" });\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfTable);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfTable);\n };\n }, []);\n\n const exState = useMemo<TReturnRangeReducer[\"state\"]>(() => {\n if (!state.isSelecting) {\n return state;\n }\n\n const startElement = document.getElementById(\n IdGenerator.getTableCellId(state.start.rowIndex, state.start.colIndex)\n );\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!startElement || !endElement || !tableElement) {\n dispatch({ type: \"reset\" });\n return { isSelecting: false };\n }\n\n const startRect = startElement.getBoundingClientRect();\n const endRect = endElement.getBoundingClientRect();\n const rectTable = tableElement.getBoundingClientRect();\n\n const adjustSize = {\n y: rectTable.top - tableElement.scrollTop - window.scrollY,\n x: rectTable.left - tableElement.scrollLeft - window.scrollX,\n };\n\n const startDivProps = {\n top: startRect.top - adjustSize.y,\n left: startRect.left - adjustSize.x,\n width: startRect.width,\n height: startRect.height,\n };\n\n const endDivProps = {\n top: endRect.top - adjustSize.y,\n left: endRect.left - adjustSize.x,\n width: endRect.width,\n height: endRect.height,\n };\n\n return {\n isSelecting: true,\n start: {\n ...state.start,\n xStart: startDivProps.left,\n xEnd: startDivProps.left + startDivProps.width,\n yStart: startDivProps.top,\n yEnd: startDivProps.top + startDivProps.height,\n },\n end: {\n ...state.end,\n xStart: endDivProps.left,\n xEnd: endDivProps.left + endDivProps.width,\n yStart: endDivProps.top,\n yEnd: endDivProps.top + endDivProps.height,\n },\n rangeBox: {\n top: Math.min(startDivProps.top, endDivProps.top),\n left: Math.min(startDivProps.left, endDivProps.left),\n width:\n Math.abs(startDivProps.left - endDivProps.left) +\n (startDivProps.left <= endDivProps.left\n ? endDivProps.width\n : startDivProps.width),\n height:\n Math.abs(startDivProps.top - endDivProps.top) +\n (startDivProps.top <= endDivProps.top\n ? endDivProps.height\n : startDivProps.height),\n },\n };\n }, [state]);\n\n return {\n state: exState,\n actions,\n };\n}\n"],"names":["newRangeConstraint","props","maxColIndex","maxRowIndex","newIndex","rowIndex","colIndex","constraint","equalIndex","a","b","MOVE_ACTION","UP","deltaRow","deltaCol","DOWN","LEFT","RIGHT","moveIndex","_a","index","direction","_b","rangeReducer","state","action","type","__assign","payload","startIndex","isSelecting","start","end","inProgress","endIndex","useReducer","dispatch","actions","useMemo","setMax","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","useEffect","onClickOutOfTable","e","element","document","getElementById","IdGenerator","getTableId","ele","target","Node","contains","addEventListener","removeEventListener","startElement","getTableCellId","endElement","tableElement","startRect","getBoundingClientRect","endRect","rectTable","adjustSize","top","scrollTop","window","scrollY","left","scrollLeft","scrollX","startDivProps","width","height","endDivProps","xStart","xEnd","yStart","yEnd","rangeBox","Math","min","abs"],"mappings":"+HASA,SAASA,EAAmBC,GAI1B,MAAO,CACLC,YAAaD,EAAMC,aAAe,GAAK,EAAID,EAAMC,YACjDC,YAAaF,EAAME,aAAe,GAAK,EAAIF,EAAME,YAErD,CA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AAMU,EAAYV,MACxCO,EAAcP,KAAOU,EAAYV,IAC9BU,EAAYD,OACZF,EAAcE,SAG1B,GAAG,CAAC5D,IAIFa,QAAOA,EAEX"}
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/range/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useReducer } from \"react\";\nimport {\n IIndex,\n TRangeReducer,\n IRangeConstraint,\n TReturnRangeReducer,\n} from \"./type\";\nimport { IdGenerator } from \"../libs\";\n\nfunction newRangeConstraint(props: {\n maxColIndex: number;\n maxRowIndex: number;\n}): IRangeConstraint {\n return {\n maxColIndex: props.maxColIndex < -1 ? -1 : props.maxColIndex,\n maxRowIndex: props.maxRowIndex < -1 ? -1 : props.maxRowIndex,\n };\n}\n\nfunction newIndex(props: {\n rowIndex: number;\n colIndex: number;\n constraint: IRangeConstraint;\n}): IIndex {\n let rowIndex = props.rowIndex;\n let colIndex = props.colIndex;\n\n if (rowIndex < 0) {\n rowIndex = 0;\n } else if (props.constraint.maxRowIndex < rowIndex) {\n rowIndex = props.constraint.maxRowIndex;\n }\n\n if (colIndex < 0) {\n colIndex = 0;\n } else if (props.constraint.maxColIndex < colIndex) {\n colIndex = props.constraint.maxColIndex;\n }\n\n return { rowIndex, colIndex };\n}\n\nfunction equalIndex(a: IIndex, b: IIndex): boolean {\n return a.rowIndex === b.rowIndex && a.colIndex === b.colIndex;\n}\n\nconst MOVE_ACTION = {\n UP: { deltaRow: -1, deltaCol: 0 },\n DOWN: { deltaRow: 1, deltaCol: 0 },\n LEFT: { deltaRow: 0, deltaCol: -1 },\n RIGHT: { deltaRow: 0, deltaCol: 1 },\n} as const;\n\ntype TMoveAction = keyof typeof MOVE_ACTION;\n\nfunction moveIndex({\n index,\n direction,\n constraint,\n}: {\n index: IIndex;\n direction: TMoveAction;\n constraint: IRangeConstraint;\n}): IIndex {\n const { deltaRow, deltaCol } = MOVE_ACTION[direction];\n\n const newRow = index.rowIndex + deltaRow;\n const newCol = index.colIndex + deltaCol;\n\n return newIndex({\n rowIndex: newRow,\n colIndex: newCol,\n constraint,\n });\n}\n\nexport const rangeReducer: TRangeReducer = (state, action) => {\n switch (action.type) {\n /**\n * Actionが\"setMax\"の場合の説明:\n * - Actionのtypeが\"setMax\"の場合、選択範囲の最大値を設定します。\n * - payloadのmaxRowIndexとmaxColIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、constraintを新しい範囲制約に設定します。\n */\n case \"setMax\":\n return {\n ...state,\n constraint: newRangeConstraint(action.payload),\n };\n\n /**\n * Actionが\"start\"の場合の説明:\n * - Actionのtypeが\"start\"の場合、選択範囲の開始位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、isSelectingをtrueに設定し、startとendの位置をpayloadの位置に設定します。\n */\n case \"startSelectRange\": {\n const startIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (\n state.isSelecting &&\n equalIndex(state.start, startIndex) &&\n equalIndex(state.end, startIndex) &&\n state.inProgress\n ) {\n return state;\n }\n\n return {\n ...state,\n isSelecting: true,\n inProgress: true,\n start: startIndex,\n end: startIndex,\n };\n }\n\n case \"moveSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n const endIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (equalIndex(state.end, endIndex)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"end\"の場合の説明:\n * - Actionのtypeが\"end\"の場合、選択範囲の終了位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、endの位置をpayloadの位置に設定します。\n * - この場合、isSelectingはtrueのままです。\n */\n case \"endSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n return {\n ...state,\n inProgress: false,\n };\n }\n\n /**\n * Actionが\"moveUp\"の場合の説明:\n * - Actionのtypeが\"moveUp\"の場合、選択範囲を上に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に移動します。\n */\n case \"moveUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveDown\"の場合の説明:\n * - Actionのtypeが\"moveDown\"の場合、選択範囲を下に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に移動します。\n */\n case \"moveDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveLeft\"の場合の説明:\n * - Actionのtypeが\"moveLeft\"の場合、選択範囲を左に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に移動します。\n */\n case \"moveLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveRight\"の場合の説明:\n * - Actionのtypeが\"moveRight\"の場合、選択範囲を右に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に移動します。\n */\n case \"moveRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"extendUp\"の場合の説明:\n * - Actionのtypeが\"extendUp\"の場合、選択範囲を上に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に拡張します。\n */\n case \"extendUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendDown\"の場合の説明:\n * - Actionのtypeが\"extendDown\"の場合、選択範囲を下に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に拡張します。\n */\n case \"extendDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendLeft\"の場合の説明:\n * - Actionのtypeが\"extendLeft\"の場合、選択範囲を左に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に拡張します。\n */\n case \"extendLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendRight\"の場合の説明:\n * - Actionのtypeが\"extendRight\"の場合、選択範囲を右に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に拡張します。\n */\n case \"extendRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"reset\"の場合の説明:\n * - Actionのtypeが\"reset\"の場合、選択範囲をリセットします。\n * - isSelectingをfalseに設定します。\n */\n case \"reset\":\n return {\n constraint: state.constraint,\n isSelecting: false,\n };\n\n /**\n * Actionが\"setRange\"の場合の説明:\n * - Actionのtypeが\"setRange\"の場合、選択範囲を設定します。\n * - payloadのstartとendの位置を設定します。\n */\n case \"setRange\":\n return {\n ...state,\n isSelecting: true,\n inProgress: false,\n start: action.payload.start,\n end: action.payload.end,\n };\n }\n};\n\nexport function useRangeReducer(): TReturnRangeReducer {\n const [state, dispatch] = useReducer(rangeReducer, {\n constraint: newRangeConstraint({ maxColIndex: 0, maxRowIndex: 0 }),\n isSelecting: false,\n });\n\n const actions = useMemo(\n () => ({\n setMax: (payload: { maxRowIndex: number; maxColIndex: number }) => {\n dispatch({ type: \"setMax\", payload });\n },\n startSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"startSelectRange\", payload });\n },\n moveSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"moveSelectRange\", payload });\n },\n endSelectRange: () => {\n dispatch({ type: \"endSelectRange\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n extendUp: () => {\n dispatch({ type: \"extendUp\" });\n },\n extendDown: () => {\n dispatch({ type: \"extendDown\" });\n },\n extendLeft: () => {\n dispatch({ type: \"extendLeft\" });\n },\n extendRight: () => {\n dispatch({ type: \"extendRight\" });\n },\n reset: () => {\n dispatch({ type: \"reset\" });\n },\n setRange: (payload: { start: IIndex; end: IIndex }) => {\n dispatch({ type: \"setRange\", payload });\n },\n }),\n []\n );\n\n useEffect(() => {\n const onClickOutOfTable = (e: MouseEvent) => {\n const element = document.getElementById(IdGenerator.getTableId());\n const ele = e.target;\n if (ele instanceof Node && element?.contains(ele)) return;\n dispatch({ type: \"reset\" });\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfTable);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfTable);\n };\n }, []);\n\n const exState = useMemo<TReturnRangeReducer[\"state\"]>(() => {\n if (!state.isSelecting) {\n return state;\n }\n\n const startElement = document.getElementById(\n IdGenerator.getTableCellId(state.start.rowIndex, state.start.colIndex)\n );\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!startElement || !endElement || !tableElement) {\n dispatch({ type: \"reset\" });\n return { isSelecting: false };\n }\n\n const startRect = startElement.getBoundingClientRect();\n const endRect = endElement.getBoundingClientRect();\n const rectTable = tableElement.getBoundingClientRect();\n\n const adjustSize = {\n y: rectTable.top - tableElement.scrollTop - window.scrollY,\n x: rectTable.left - tableElement.scrollLeft - window.scrollX,\n };\n\n const startDivProps = {\n top: startRect.top - adjustSize.y,\n left: startRect.left - adjustSize.x,\n width: startRect.width,\n height: startRect.height,\n };\n\n const endDivProps = {\n top: endRect.top - adjustSize.y,\n left: endRect.left - adjustSize.x,\n width: endRect.width,\n height: endRect.height,\n };\n\n return {\n isSelecting: true,\n start: {\n ...state.start,\n xStart: startDivProps.left,\n xEnd: startDivProps.left + startDivProps.width,\n yStart: startDivProps.top,\n yEnd: startDivProps.top + startDivProps.height,\n },\n end: {\n ...state.end,\n xStart: endDivProps.left,\n xEnd: endDivProps.left + endDivProps.width,\n yStart: endDivProps.top,\n yEnd: endDivProps.top + endDivProps.height,\n },\n rangeBox: {\n top: Math.min(startDivProps.top, endDivProps.top),\n left: Math.min(startDivProps.left, endDivProps.left),\n width:\n Math.abs(startDivProps.left - endDivProps.left) +\n (startDivProps.left <= endDivProps.left\n ? endDivProps.width\n : startDivProps.width),\n height:\n Math.abs(startDivProps.top - endDivProps.top) +\n (startDivProps.top <= endDivProps.top\n ? endDivProps.height\n : startDivProps.height),\n },\n };\n }, [state]);\n\n return {\n state: exState,\n actions,\n };\n}\n"],"names":["newRangeConstraint","props","maxColIndex","maxRowIndex","newIndex","rowIndex","colIndex","constraint","equalIndex","a","b","MOVE_ACTION","UP","deltaRow","deltaCol","DOWN","LEFT","RIGHT","moveIndex","_a","index","direction","_b","rangeReducer","state","action","type","__assign","payload","startIndex","isSelecting","start","end","inProgress","endIndex","useReducer","dispatch","actions","useMemo","setMax","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","setRange","useEffect","onClickOutOfTable","e","element","document","getElementById","IdGenerator","getTableId","ele","target","Node","contains","addEventListener","removeEventListener","startElement","getTableCellId","endElement","tableElement","startRect","getBoundingClientRect","endRect","rectTable","adjustSize","top","scrollTop","window","scrollY","left","scrollLeft","scrollX","startDivProps","width","height","endDivProps","xStart","xEnd","yStart","yEnd","rangeB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,EAAYN,KACpBQ,KAAMF,EAAYN,KAAOM,EAAYF,MACrCK,OAAQH,EAAYV,IACpBc,KAAMJ,EAAYV,IAAMU,EAAYD,SAEtCM,SAAU,CACRf,IAAKgB,KAAKC,IAAIV,EAAcP,IAAKU,EAAYV,KAC7CI,KAAMY,KAAKC,IAAIV,EAAcH,KAAMM,EAAYN,MAC/CI,MACEQ,KAAKE,IAAIX,EAAcH,KAAOM,EAAYN,OACzCG,EAAcH,MAAQM,EAAYN,KAC/BM,EAAYF,MACZD,EAAcC,OACpBC,OACEO,KAAKE,IAAIX,EAAcP,IAAMU,EAAYV,MACxCO,EAAcP,KAAOU,EAAYV,IAC9BU,EAAYD,OACZF,EAAcE,SAG1B,GAAG,CAAC7D,IAIFa,QAAOA,EAEX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),n=require("react/jsx-runtime"),t=require("react"),o=require("../lib/errors.js"),r=require("./hooks.js"),i=require("../table-property/provider.js"),s=require("../libs/id-generator.js"),a=t.createContext({isSelecting:!1}),u=t.createContext({setMax:o.NoImplementeFunction,startSelectRange:o.NoImplementeFunction,moveSelectRange:o.NoImplementeFunction,endSelectRange:o.NoImplementeFunction,moveUp:o.NoImplementeFunction,moveDown:o.NoImplementeFunction,moveLeft:o.NoImplementeFunction,moveRight:o.NoImplementeFunction,extendUp:o.NoImplementeFunction,extendDown:o.NoImplementeFunction,extendLeft:o.NoImplementeFunction,extendRight:o.NoImplementeFunction,reset:o.NoImplementeFunction,setRange:o.NoImplementeFunction});function l(){return t.useContext(a)}function c(){return t.useContext(u)}function d(){var e=c().setMax,o=i.useTablePropertyStateContext(),r=o.maxDisplayRowCount,s=o.maxDisplayColCount;return t.useEffect((function(){e({maxRowIndex:r-1,maxColIndex:s-1})}),[r,s]),n.jsx(n.Fragment,{})}exports.RangeProvider=function(e){var t=e.children,o=r.useRangeReducer(),i=o.state,s=o.actions;return n.jsx(a.Provider,{value:i,children:n.jsxs(u.Provider,{value:s,children:[n.jsx(d,{}),t]})})},exports.TestRange=function(e){var o=l();if(t.useEffect((function(){if(o.isSelecting){var e=document.getElementById(s.IdGenerator.getTableCellId(o.end.rowIndex,o.end.colIndex));e&&(e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),e.focus())}}),[o]),!o.isSelecting)return n.jsx(n.Fragment,{});var r=o.rangeBox,i=o.start,a=o.end;return i.xEnd<a.xEnd?a.xEnd:i.xEnd,i.yEnd<a.yEnd?a.yEnd:i.yEnd,n.jsx(n.Fragment,{children:n.jsx("div",{className:"absolute border border-gray-500 bg-gray-500 bg-opacity-10 ".concat(e.isCopied?"border-dashed":"border-solid"),style:{top:r.top,left:r.left,width:r.width,height:r.height,pointerEvents:"none"}})})},exports.useRangeActionContext=c,exports.useRangeContext=function(){return e.__assign(e.__assign({},l()),c())},exports.useRangeStateContext=l;
|
|
2
2
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/range/provider.tsx"],"sourcesContent":["import { createContext, useContext, useEffect } from \"react\";\nimport { TRangeActionContext, TRangeStateContext } from \"./type\";\nimport { NoImplementeFunction } from \"../lib/errors\";\nimport { useRangeReducer } from \"./hooks\";\nimport { useTablePropertyStateContext } from \"../table-property/provider\";\nimport { IdGenerator } from \"../libs\";\n\nconst RangeStateContext = createContext<TRangeStateContext>({\n isSelecting: false,\n});\n\nconst RangeActionContext = createContext<TRangeActionContext>({\n setMax: NoImplementeFunction,\n startSelectRange: NoImplementeFunction,\n moveSelectRange: NoImplementeFunction,\n endSelectRange: NoImplementeFunction,\n moveUp: NoImplementeFunction,\n moveDown: NoImplementeFunction,\n moveLeft: NoImplementeFunction,\n moveRight: NoImplementeFunction,\n extendUp: NoImplementeFunction,\n extendDown: NoImplementeFunction,\n extendLeft: NoImplementeFunction,\n extendRight: NoImplementeFunction,\n reset: NoImplementeFunction,\n});\n\nexport function useRangeStateContext() {\n return useContext(RangeStateContext);\n}\n\nexport function useRangeActionContext() {\n return useContext(RangeActionContext);\n}\n\nexport function useRangeContext() {\n return { ...useRangeStateContext(), ...useRangeActionContext() };\n}\n\nfunction EffectSetMax() {\n const { setMax } = useRangeActionContext();\n const { maxDisplayRowCount, maxDisplayColCount } =\n useTablePropertyStateContext();\n\n useEffect(() => {\n setMax({\n maxRowIndex: maxDisplayRowCount - 1,\n maxColIndex: maxDisplayColCount - 1,\n });\n }, [maxDisplayRowCount, maxDisplayColCount]);\n\n return <></>;\n}\n\nexport function TestRange(props: { isCopied?: boolean }) {\n const state = useRangeStateContext();\n\n useEffect(() => {\n if (state.isSelecting) {\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n\n if (endElement) {\n endElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n endElement.focus();\n }\n }\n }, [state]);\n\n if (!state.isSelecting) {\n return <></>;\n }\n\n const { rangeBox, start, end } = state;\n\n const clickboxPoint = {\n x: start.xEnd < end.xEnd ? end.xEnd : start.xEnd,\n y: start.yEnd < end.yEnd ? end.yEnd : start.yEnd,\n };\n\n return (\n <>\n <div\n className={`absolute border border-gray-500 ${\n props.isCopied ? \"border-dashed\" : \"border-solid\"\n }`}\n style={{\n top: rangeBox.top,\n left: rangeBox.left,\n width: rangeBox.width,\n height: rangeBox.height,\n pointerEvents: \"none\",\n }}\n ></div>\n <div\n className=\"absolute bg-gray-700\"\n style={{\n top: clickboxPoint.y - 5,\n left: clickboxPoint.x - 5,\n width: 10,\n height: 10,\n pointerEvents: \"none\",\n }}\n
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/range/provider.tsx"],"sourcesContent":["import { createContext, useContext, useEffect } from \"react\";\nimport { TRangeActionContext, TRangeStateContext } from \"./type\";\nimport { NoImplementeFunction } from \"../lib/errors\";\nimport { useRangeReducer } from \"./hooks\";\nimport { useTablePropertyStateContext } from \"../table-property/provider\";\nimport { IdGenerator } from \"../libs\";\n\nconst RangeStateContext = createContext<TRangeStateContext>({\n isSelecting: false,\n});\n\nconst RangeActionContext = createContext<TRangeActionContext>({\n setMax: NoImplementeFunction,\n startSelectRange: NoImplementeFunction,\n moveSelectRange: NoImplementeFunction,\n endSelectRange: NoImplementeFunction,\n moveUp: NoImplementeFunction,\n moveDown: NoImplementeFunction,\n moveLeft: NoImplementeFunction,\n moveRight: NoImplementeFunction,\n extendUp: NoImplementeFunction,\n extendDown: NoImplementeFunction,\n extendLeft: NoImplementeFunction,\n extendRight: NoImplementeFunction,\n reset: NoImplementeFunction,\n setRange: NoImplementeFunction,\n});\n\nexport function useRangeStateContext() {\n return useContext(RangeStateContext);\n}\n\nexport function useRangeActionContext() {\n return useContext(RangeActionContext);\n}\n\nexport function useRangeContext() {\n return { ...useRangeStateContext(), ...useRangeActionContext() };\n}\n\nfunction EffectSetMax() {\n const { setMax } = useRangeActionContext();\n const { maxDisplayRowCount, maxDisplayColCount } =\n useTablePropertyStateContext();\n\n useEffect(() => {\n setMax({\n maxRowIndex: maxDisplayRowCount - 1,\n maxColIndex: maxDisplayColCount - 1,\n });\n }, [maxDisplayRowCount, maxDisplayColCount]);\n\n return <></>;\n}\n\nexport function TestRange(props: { isCopied?: boolean }) {\n const state = useRangeStateContext();\n\n useEffect(() => {\n if (state.isSelecting) {\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n\n if (endElement) {\n endElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n endElement.focus();\n }\n }\n }, [state]);\n\n if (!state.isSelecting) {\n return <></>;\n }\n\n const { rangeBox, start, end } = state;\n\n const clickboxPoint = {\n x: start.xEnd < end.xEnd ? end.xEnd : start.xEnd,\n y: start.yEnd < end.yEnd ? end.yEnd : start.yEnd,\n };\n\n return (\n <>\n <div\n className={`absolute border border-gray-500 bg-gray-500 bg-opacity-10 ${\n props.isCopied ? \"border-dashed\" : \"border-solid\"\n }`}\n style={{\n top: rangeBox.top,\n left: rangeBox.left,\n width: rangeBox.width,\n height: rangeBox.height,\n pointerEvents: \"none\",\n }}\n ></div>\n {/* <div\n className=\"absolute bg-gray-700\"\n style={{\n top: clickboxPoint.y - 5,\n left: clickboxPoint.x - 5,\n width: 10,\n height: 10,\n pointerEvents: \"none\",\n }}\n /> */}\n </>\n );\n}\n\nexport function RangeProvider({\n children,\n}: {\n children: JSX.Element | JSX.Element[];\n}) {\n const { state, actions } = useRangeReducer();\n\n return (\n <RangeStateContext.Provider value={state}>\n <RangeActionContext.Provider value={actions}>\n <EffectSetMax />\n {children}\n </RangeActionContext.Provider>\n </RangeStateContext.Provider>\n );\n}\n"],"names":["RangeStateContext","createContext","isSelecting","RangeActionContext","setMax","NoImplementeFunction","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","setRange","useRangeStateContext","useContext","useRangeActionContext","EffectSetMax","_a","useTablePropertyStateContext","maxDisplayRowCount","maxDisplayColCount","useEffect","maxRowIndex","maxColIndex","_jsx","children","_b","useRangeReducer","state","actions","jsx","Provider","value","_jsxs","props","endElement","document","getElementById","IdGenerator","getTableCellId","end","rowIndex","colIndex","scrollIntoView","behavior","block","inline","focus","rangeBox","start","xEnd","yEnd","className","concat","isCopied","style","top","left","width","height","pointerEvents","__assign"],"mappings":"+PAOMA,EAAoBC,EAAAA,cAAkC,CAC1DC,aAAa,IAGTC,EAAqBF,EAAAA,cAAmC,CAC5DG,OAAQC,EAAoBA,qBAC5BC,iBAAkBD,EAAoBA,qBACtCE,gBAAiBF,EAAoBA,qBACrCG,eAAgBH,EAAoBA,qBACpCI,OAAQJ,EAAoBA,qBAC5BK,SAAUL,EAAoBA,qBAC9BM,SAAUN,EAAoBA,qBAC9BO,UAAWP,EA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X,EAAIW,KAAOX,EAAIW,KAAOF,EAAME,KAI5C3B,EAAAA,yBACEA,EACEM,IAAA,MAAA,CAAAsB,UAAW,6DACTC,OAAAnB,EAAMoB,SAAW,gBAAkB,gBAErCC,MAAO,CACLC,IAAKR,EAASQ,IACdC,KAAMT,EAASS,KACfC,MAAOV,EAASU,MAChBC,OAAQX,EAASW,OACjBC,cAAe,WAezB,qEA3EE,OAAAC,EAAAA,SAAAA,EAAAA,SAAA,CAAA,EAAYhD,KAA2BE,IACzC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("../checkbox/components.js"),o=require("../cell/ui/cell.js"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("../checkbox/components.js"),o=require("../cell/ui/cell.js"),i=require("../libs/id-generator.js"),a=require("../range/provider.js"),n=r.memo((function(r){var n=a.useRangeActionContext().reset,l=JSON.parse(r.dataString),c=r.conditionalFormattingString.split(",");return e.jsxs("tr",{className:"relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ".concat(r.onClickRow?"hover:cursor-pointer":""," ").concat(r.applyRowFormatting?r.applyRowFormatting(l):""),onClick:function(e){e.preventDefault(),r.onClickRow&&(r.onClickRow(l),n())},"data-testid":l.id,children:[r.existCheckbox&&e.jsx("td",{onClick:function(e){e.stopPropagation()},children:e.jsx(t.Checkbox,{row:l})}),r.cols.map((function(t,a){var n;return e.jsx(o.TableCell,{id:i.IdGenerator.getTableCellId(r.rowIndex,a),row:l,isExistOnClickRow:!!r.onClickRow,cellFormatClassName:c[a],editable:null!==(n=t.editable)&&void 0!==n&&n},t.key)}))]})}));exports.Row=n;
|
|
2
2
|
//# sourceMappingURL=components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../../../../src/table/sheet/components.tsx"],"sourcesContent":["import { memo } from \"react\";\nimport { DataRecord, TTableColumn } from \"../table/type\";\nimport { Checkbox } from \"../checkbox/components\";\nimport { TableCell } from \"../cell/ui/cell\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\ninterface TPropsRow<T extends DataRecord> {\n dataString: string;\n cols: TTableColumn<T>[];\n existCheckbox?: boolean;\n rowIndex: number;\n conditionalFormattingString: string;\n onClickRow?: (row: any) => void;\n applyRowFormatting?: (row: any) => string;\n}\n\nexport const Row = memo(function R<T extends DataRecord>(props: TPropsRow<T>) {\n const { reset } = useRangeActionContext();\n const row = JSON.parse(props.dataString);\n const conditionalFormatting = props.conditionalFormattingString.split(\",\");\n\n return (\n <tr\n className={`relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ${\n !!props.onClickRow ? \"hover:cursor-pointer\" : \"\"\n } ${props.applyRowFormatting ? props.applyRowFormatting(row) : \"\"}`}\n onClick={(e) => {\n e.preventDefault();\n\n if (!!props.onClickRow) {\n props.onClickRow(row);\n reset();\n }\n }}\n data-testid={row.id}\n >\n {props.existCheckbox && (\n <td>\n <Checkbox row={row} />\n </td>\n )}\n {props.cols.map((col, j) => {\n return (\n <TableCell\n key={col.key as string}\n id={IdGenerator.getTableCellId(props.rowIndex, j)}\n row={row}\n isExistOnClickRow={!!props.onClickRow}\n cellFormatClassName={conditionalFormatting[j]}\n editable={col.editable ?? false}\n />\n );\n })}\n </tr>\n );\n});\n"],"names":["Row","memo","props","reset","useRangeActionContext","row","JSON","parse","dataString","conditionalFormatting","conditionalFormattingString","split","_jsxs","className","concat","onClickRow","applyRowFormatting","onClick","e","preventDefault","id","
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../../../src/table/sheet/components.tsx"],"sourcesContent":["import { memo } from \"react\";\nimport { DataRecord, TTableColumn } from \"../table/type\";\nimport { Checkbox } from \"../checkbox/components\";\nimport { TableCell } from \"../cell/ui/cell\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\ninterface TPropsRow<T extends DataRecord> {\n dataString: string;\n cols: TTableColumn<T>[];\n existCheckbox?: boolean;\n rowIndex: number;\n conditionalFormattingString: string;\n onClickRow?: (row: any) => void;\n applyRowFormatting?: (row: any) => string;\n}\n\nexport const Row = memo(function R<T extends DataRecord>(props: TPropsRow<T>) {\n const { reset } = useRangeActionContext();\n const row = JSON.parse(props.dataString);\n const conditionalFormatting = props.conditionalFormattingString.split(\",\");\n\n return (\n <tr\n className={`relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ${\n !!props.onClickRow ? \"hover:cursor-pointer\" : \"\"\n } ${props.applyRowFormatting ? props.applyRowFormatting(row) : \"\"}`}\n onClick={(e) => {\n e.preventDefault();\n\n if (!!props.onClickRow) {\n props.onClickRow(row);\n reset();\n }\n }}\n data-testid={row.id}\n >\n {props.existCheckbox && (\n <td\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n <Checkbox row={row} />\n </td>\n )}\n {props.cols.map((col, j) => {\n return (\n <TableCell\n key={col.key as string}\n id={IdGenerator.getTableCellId(props.rowIndex, j)}\n row={row}\n isExistOnClickRow={!!props.onClickRow}\n cellFormatClassName={conditionalFormatting[j]}\n editable={col.editable ?? false}\n />\n );\n })}\n </tr>\n );\n});\n"],"names":["Row","memo","props","reset","useRangeActionContext","row","JSON","parse","dataString","conditionalFormatting","conditionalFormattingString","split","_jsxs","className","concat","onClickRow","applyRowFormatting","onClick","e","preventDefault","id","existCheckbox","_jsx","jsx","stopPropagation","children","Checkbox","cols","map","col","j","TableCell","IdGenerator","getTableCellId","rowIndex","isExistOnClickRow","cellFormatClassName","editable","_a","key"],"mappings":"iNAiBaA,EAAMC,EAAIA,MAAC,SAAiCC,GAC/C,IAAAC,EAAUC,gCACZC,EAAMC,KAAKC,MAAML,EAAMM,YACvBC,EAAwBP,EAAMQ,4BAA4BC,MAAM,KAEtE,OACEC,OACE,KAAA,CAAAC,UAAW,0JACTC,OAAEZ,EAAMa,WAAa,uBAAyB,GAC5C,KAAAD,OAAAZ,EAAMc,mBAAqBd,EAAMc,mBAAmBX,GAAO,IAC/DY,QAAS,SAACC,GACRA,EAAEC,iBAEIjB,EAAMa,aACVb,EAAMa,WAAWV,GACjBF,IAEH,EACY,cAAAE,EAAIe,aAEhBlB,EAAMmB,eACLC,EAAAC,IAAA,KAAA,CACEN,QAAS,SAACC,GACRA,EAAEM,iBACH,EAAAC,SAEDH,MAACI,EAAQA,SAAA,CAACrB,IAAKA,MAGlBH,EAAMyB,KAAKC,KAAI,SAACC,EAAKC,SACpB,OACER,EAAAA,IAACS,EAAAA,UAAS,CAERX,GAAIY,EAAWA,YAACC,eAAe/B,EAAMgC,SAAUJ,GAC/CzB,IAAKA,EACL8B,oBAAqBjC,EAAMa,WAC3BqB,oBAAqB3B,EAAsBqB,GAC3CO,SAAsB,UAAZR,EAAIQ,gBAAQ,IAAAC,GAAAA,GALjBT,EAAIU,UAWrB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),r=require("react/jsx-runtime"),o=require("./hook.js"),i=require("../header/header.js"),s=require("../pagenation/providers.js"),t=require("../pagenation/components.js"),n=require("../filter/provider.js"),l=require("../filter/components.js");require("../sort/icon.js");var a=require("../sort/provider.js"),d=require("../sheet/providers.js"),c=require("../checkbox/provider.js"),x=require("../checkbox/components.js"),
|
|
2
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),r=require("react/jsx-runtime"),o=require("./hook.js"),i=require("../header/header.js"),s=require("../pagenation/providers.js"),t=require("../pagenation/components.js"),n=require("../filter/provider.js"),l=require("../filter/components.js");require("../sort/icon.js");var a=require("../sort/provider.js"),d=require("../sheet/providers.js"),c=require("../checkbox/provider.js"),x=require("../checkbox/components.js"),j=require("../libs/id-generator.js"),u=require("../edit/provider.js"),h=require("../table-property/provider.js"),p=require("../operation/components/keyboard-setting.js"),g=require("../sheet/components.js"),v=require("../paste/provider.js"),m=require("../libs/conditional-formatting.js"),b=require("../edit/ui/editor.js"),w=require("../filter/hooks/selectedFilteringColumn/provider.js"),q=require("../range/provider.js"),y=require("../copy/provider.js"),C=require("../copy/components.js");function k(e){var s=o.useTable(e),n=s.cols,a=s.rowMaps,d=s.pageRowIds,c=w.useFilteringColumnStateContext(),u=q.useRangeActionContext().reset;return r.jsxs("div",{className:"w-full",children:[r.jsx("div",{className:"flex justify-end mb-1 mr-3",children:r.jsx(l.TableFilterRemoveButton,{children:r.jsx("p",{className:"text-xs underline text-gray-500 hover:text-gray-700",children:"全てのフィルタリング条件を解除する"})})}),r.jsxs("div",{id:j.IdGenerator.getTableId(),className:"relative h-full max-w-full max-h-[80vh] border border-gray-200 rounded-md overflow-auto",children:[r.jsx(q.TestRange,{}),r.jsx(b.Editor,{rowMaps:a,pageRowIds:d}),r.jsxs("table",{className:"table",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"sticky top-0 border-gray-200 z-20 bg-gray-200 text-gray-600 h-[32px]",onClick:function(e){e.stopPropagation(),u()},children:[e.checkbox&&r.jsx("th",{children:r.jsx(x.AllCheckbox,{rows:e.rows})}),n.map((function(e,o){return r.jsx(i.TableHeaderElement,{id:j.IdGenerator.getTableColId(o),col:e},e.key.toString())}))]})}),r.jsxs("tbody",{children:[!!c&&r.jsx("tr",{onClick:function(e){e.stopPropagation(),u()},children:r.jsx("td",{colSpan:n.length,className:"sticky top-8 left-0 bg-gray-300 w-full shadow-lg rounded-b-2xl z-20 p-0 overflow-hidden",children:r.jsx(l.TableFilterForm,{})})}),0===d.length&&r.jsx("tr",{children:r.jsx("td",{colSpan:n.length,className:"py-5",children:r.jsx("p",{className:"text-center font-bold text-lg",children:"NO DATA"})})}),d.map((function(o,i){return r.jsx(g.Row,{existCheckbox:!!e.checkbox,rowIndex:i,dataString:a[o].stringValue,cols:e.cols,onClickRow:e.onClickRow,applyRowFormatting:e.applyRowFormatting,conditionalFormattingString:m.generateFormattingString(a[o].data,n,e.conditionalFormattings)},o)}))]})]})]}),r.jsxs("div",{className:"mt-1",children:[r.jsx(t.DisplayRange,{}),r.jsx("div",{className:"mt-2",children:r.jsx(t.Pagenation,{})})]})]})}module.exports=function(o){var i,t,l;return r.jsx(n.FilterProvider,{children:r.jsx(a.SortProvider,{initialCondition:null===(i=o.initialCondition)||void 0===i?void 0:i.sort,children:r.jsx(s.PagenationProvider,{rowCount:o.rows.length,perPage:null===(l=null===(t=o.initialCondition)||void 0===t?void 0:t.pagenation)||void 0===l?void 0:l.rowCountPerPage,children:r.jsx(c.CheckboxProvider,{checkbox:o.checkbox,children:r.jsx(c.CheckboxStatusProvider,{checkboxCount:o.rows.length,children:r.jsx(d.ColumnsProvider,{cols:o.cols,errorHandler:o.errorHandler,children:r.jsx(u.EditProvider,{children:r.jsx(h.TablePropertyProvider,{children:r.jsx(q.RangeProvider,{children:r.jsxs(y.CopyProvider,{rows:o.rows,cols:o.cols,children:[r.jsx(C.CopiedMessage,{}),r.jsxs(v.PasteProvider,{rows:o.rows,cols:o.cols,onUpdateRowFunction:o.onUpdateRow,children:[r.jsx(p.KeyboardSetting,{}),r.jsx(k,e.__assign({},o))]})]})})})})})})})})})})};
|
|
3
3
|
//# sourceMappingURL=base.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useRef as i,useState as n}from"react";var
|
|
1
|
+
import{useRef as i,useState as n}from"react";var a=["image/*","text/*","application/vnd.openxmlformats-officedocument.spreadsheetml.sheet","application/vnd.openxmlformats-officedocument.presentationml.presentation","application/vnd.openxmlformats-officedocument.wordprocessingml.document","application/vnd.ms-excel","application/vnd.ms-outlook","application/json","application/xml","application/pdf","application/x-compressed","application/x-zip-compressed","application/x-gzip","application/x-bzip2","application/x-tar","application/x-rar-compressed","application/x-7z-compressed","application/zip"],e=[".msg"];function o(o){var t=i(null),r=n(!1),p=r[0],c=r[1],l=function(i){var n=function(i){var n=[],o=[];return i.forEach((function(i){var t=i.name.split(".").pop();t&&e.includes(".".concat(t))||a.some((function(n){return i.type.match(n)}))?n.push(i):o.push(i)})),{validFiles:n,rejectedFiles:o}}(i),t=n.validFiles,r=n.rejectedFiles;t.length>0&&o.addFiles(t),r.length>0&&o.onValidationError&&o.onValidationError(r)};return{inputProps:{ref:t,type:"file",multiple:!0,className:"hidden",accept:a.join(","),onChange:function(i){if(i.target.files){var n=Array.from(i.target.files);l(n)}}},isDragging:p,dropSpaceProps:{onClick:function(){var i;return null===(i=t.current)||void 0===i?void 0:i.click()},onDrop:function(i){if(i.preventDefault(),c(!1),i.dataTransfer.files){var n=Array.from(i.dataTransfer.files);l(n)}},onDragOver:function(i){i.preventDefault(),c(!0)},onDragLeave:function(i){c(!1)}}}}export{o as useFileUploader};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../src/file-uploader/hook.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\n\ninterface IPropsFileUploader {\n addFiles: (files: File[]) => void;\n onValidationError?: (rejectedFiles: File[]) => void;\n}\n\ninterface IReturnFileUploader {\n inputProps: {\n ref: React.RefObject<HTMLInputElement>;\n type: \"file\";\n multiple?: boolean;\n accept?: string;\n className?: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n };\n isDragging: boolean;\n dropSpaceProps: {\n onClick?: React.MouseEventHandler;\n onDrop: (e: React.DragEvent) => void;\n onDragOver: (e: React.DragEvent) => void;\n onDragLeave: (e: React.DragEvent) => void;\n };\n}\n\nconst ACCEPTED_TYPES = [\n \"image/*\", // image\n \"text/*\", // .txt\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\", // .xlsx\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\", // .pptx\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\", // .docx\n \"application/vnd.ms-excel\", // .xls\n \"application/vnd.ms-outlook\", // .msg\n \"application/json\", // .json\n \"application/xml\", // .xml\n \"application/pdf\", // .pdf\n \"application/x-compressed\", // .tgz\n \"application/x-zip-compressed\", // .zip\n \"application/x-gzip\", // .gz\n \"application/x-bzip2\", // .bz2\n \"application/x-tar\", // .tar\n \"application/x-rar-compressed\", // .rar\n \"application/x-7z-compressed\", // .7z\n \"application/zip\", // .zip\n];\n\nexport function useFileUploader(\n props: IPropsFileUploader\n): IReturnFileUploader {\n const inputRef = useRef<HTMLInputElement>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n const validateFiles = (\n files: File[]\n ): { validFiles: File[]; rejectedFiles: File[] } => {\n const validFiles: File[] = [];\n const rejectedFiles: File[] = [];\n\n files.forEach((file) => {\n if (ACCEPTED_TYPES.some((type) => file.type.match(type))) {\n validFiles.push(file);\n } else {\n rejectedFiles.push(file);\n }\n });\n\n return { validFiles, rejectedFiles };\n };\n\n const addFiles = (files: File[]) => {\n const { validFiles, rejectedFiles } = validateFiles(files);\n if (validFiles.length > 0) {\n props.addFiles(validFiles);\n }\n if (rejectedFiles.length > 0 && props.onValidationError) {\n props.onValidationError(rejectedFiles);\n }\n };\n\n const handleDrop = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(false);\n if (e.dataTransfer.files) {\n const droppedFiles = Array.from(e.dataTransfer.files);\n addFiles(droppedFiles);\n }\n };\n\n const handleDragOver = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(true);\n };\n\n const handleDragLeave = (e: React.DragEvent) => {\n setIsDragging(false);\n };\n\n return {\n inputProps: {\n ref: inputRef,\n type: \"file\",\n multiple: true,\n className: \"hidden\",\n accept: ACCEPTED_TYPES.join(\",\"),\n onChange: (e) => {\n if (e.target.files) {\n const selectedFiles = Array.from(e.target.files);\n addFiles(selectedFiles);\n }\n },\n },\n isDragging,\n dropSpaceProps: {\n onClick: () => inputRef.current?.click(),\n onDrop: handleDrop,\n onDragOver: handleDragOver,\n onDragLeave: handleDragLeave,\n },\n };\n}\n"],"names":["ACCEPTED_TYPES","useFileUploader","props","inputRef","useRef","_a","useState","isDragging","setIsDragging","addFiles","files","validFiles","rejectedFiles","forEach","file","some","type","match","push","validateFiles","length","onValidationError","inputProps","ref","multiple","className","accept","join","onChange","e","target","selectedFiles","Array","from","dropSpaceProps","onClick","current","click","onDrop","preventDefault","dataTransfer","droppedFiles","onDragOver","onDragLeave"],"mappings":"6CAyBA,IAAMA,EAAiB,CACrB,UACA,SACA,oEACA,4EACA,0EACA,2BACA,6BACA,mBACA,kBACA,kBACA,2BACA,+BACA,qBACA,sBACA,oBACA,+BACA,8BACA,
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../src/file-uploader/hook.ts"],"sourcesContent":["import { useRef, useState } from \"react\";\n\ninterface IPropsFileUploader {\n addFiles: (files: File[]) => void;\n onValidationError?: (rejectedFiles: File[]) => void;\n}\n\ninterface IReturnFileUploader {\n inputProps: {\n ref: React.RefObject<HTMLInputElement>;\n type: \"file\";\n multiple?: boolean;\n accept?: string;\n className?: string;\n onChange: React.ChangeEventHandler<HTMLInputElement>;\n };\n isDragging: boolean;\n dropSpaceProps: {\n onClick?: React.MouseEventHandler;\n onDrop: (e: React.DragEvent) => void;\n onDragOver: (e: React.DragEvent) => void;\n onDragLeave: (e: React.DragEvent) => void;\n };\n}\n\nconst ACCEPTED_TYPES = [\n \"image/*\", // image\n \"text/*\", // .txt\n \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\", // .xlsx\n \"application/vnd.openxmlformats-officedocument.presentationml.presentation\", // .pptx\n \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\", // .docx\n \"application/vnd.ms-excel\", // .xls\n \"application/vnd.ms-outlook\", // .msg\n \"application/json\", // .json\n \"application/xml\", // .xml\n \"application/pdf\", // .pdf\n \"application/x-compressed\", // .tgz\n \"application/x-zip-compressed\", // .zip\n \"application/x-gzip\", // .gz\n \"application/x-bzip2\", // .bz2\n \"application/x-tar\", // .tar\n \"application/x-rar-compressed\", // .rar\n \"application/x-7z-compressed\", // .7z\n \"application/zip\", // .zip\n];\n\nconst ALLOWED_EXTENSIONS = [\".msg\"];\n\nexport function useFileUploader(\n props: IPropsFileUploader\n): IReturnFileUploader {\n const inputRef = useRef<HTMLInputElement>(null);\n const [isDragging, setIsDragging] = useState(false);\n\n const validateFiles = (\n files: File[]\n ): { validFiles: File[]; rejectedFiles: File[] } => {\n const validFiles: File[] = [];\n const rejectedFiles: File[] = [];\n\n files.forEach((file) => {\n const extension = file.name.split(\".\").pop();\n if (extension && ALLOWED_EXTENSIONS.includes(`.${extension}`)) {\n validFiles.push(file);\n return;\n }\n if (ACCEPTED_TYPES.some((type) => file.type.match(type))) {\n validFiles.push(file);\n } else {\n rejectedFiles.push(file);\n }\n });\n\n return { validFiles, rejectedFiles };\n };\n\n const addFiles = (files: File[]) => {\n const { validFiles, rejectedFiles } = validateFiles(files);\n if (validFiles.length > 0) {\n props.addFiles(validFiles);\n }\n if (rejectedFiles.length > 0 && props.onValidationError) {\n props.onValidationError(rejectedFiles);\n }\n };\n\n const handleDrop = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(false);\n if (e.dataTransfer.files) {\n const droppedFiles = Array.from(e.dataTransfer.files);\n addFiles(droppedFiles);\n }\n };\n\n const handleDragOver = (e: React.DragEvent) => {\n e.preventDefault();\n setIsDragging(true);\n };\n\n const handleDragLeave = (e: React.DragEvent) => {\n setIsDragging(false);\n };\n\n return {\n inputProps: {\n ref: inputRef,\n type: \"file\",\n multiple: true,\n className: \"hidden\",\n accept: ACCEPTED_TYPES.join(\",\"),\n onChange: (e) => {\n if (e.target.files) {\n const selectedFiles = Array.from(e.target.files);\n addFiles(selectedFiles);\n }\n },\n },\n isDragging,\n dropSpaceProps: {\n onClick: () => inputRef.current?.click(),\n onDrop: handleDrop,\n onDragOver: handleDragOver,\n onDragLeave: handleDragLeave,\n },\n };\n}\n"],"names":["ACCEPTED_TYPES","ALLOWED_EXTENSIONS","useFileUploader","props","inputRef","useRef","_a","useState","isDragging","setIsDragging","addFiles","files","validFiles","rejectedFiles","forEach","file","extension","name","split","pop","includes","concat","some","type","match","push","validateFiles","length","onValidationError","inputProps","ref","multiple","className","accept","join","onChange","e","target","selectedFiles","Array","from","dropSpaceProps","onClick","current","click","onDrop","preventDefault","dataTransfer","droppedFiles","onDragOver","onDragLeave"],"mappings":"6CAyBA,IAAMA,EAAiB,CACrB,UACA,SACA,oEACA,4EACA,0EACA,2BACA,6BACA,mBACA,kBACA,kBACA,2BACA,+BACA,qBACA,sBACA,oBACA,+BACA,8BACA,mBAGIC,EAAqB,CAAC,QAEtB,SAAUC,EACdC,GAEA,IAAMC,EAAWC,EAAyB,MACpCC,EAA8BC,GAAS,GAAtCC,EAAUF,EAAA,GAAEG,EAAaH,EAAA,GAwB1BI,EAAW,SAACC,GACV,IAAAL,EAvBc,SACpBK,GAEA,IAAMC,EAAqB,GACrBC,EAAwB,GAe9B,OAbAF,EAAMG,SAAQ,SAACC,GACb,IAAMC,EAAYD,EAAKE,KAAKC,MAAM,KAAKC,MACnCH,GAAaf,EAAmBmB,SAAS,IAAAC,OAAIL,KAI7ChB,EAAesB,MAAK,SAACC,GAAS,OAAAR,EAAKQ,KAAKC,MAAMD,EAAK,IAHrDX,EAAWa,KAAKV,GAMhBF,EAAcY,KAAKV,EAEvB,IAEO,CAAEH,WAAUA,EAAEC,cAAaA,EACpC,CAGwCa,CAAcf,GAA5CC,EAAUN,EAAAM,WAAEC,EAAaP,EAAAO,cAC7BD,EAAWe,OAAS,GACtBxB,EAAMO,SAASE,GAEbC,EAAcc,OAAS,GAAKxB,EAAMyB,mBACpCzB,EAAMyB,kBAAkBf,EAE5B,EAoBA,MAAO,CACLgB,WAAY,CACVC,IAAK1B,EACLmB,KAAM,OACNQ,UAAU,EACVC,UAAW,SACXC,OAAQjC,EAAekC,KAAK,KAC5BC,SAAU,SAACC,GACT,GAAIA,EAAEC,OAAO1B,MAAO,CAClB,IAAM2B,EAAgBC,MAAMC,KAAKJ,EAAEC,OAAO1B,OAC1CD,EAAS4B,EACV,CACF,GAEH9B,WAAUA,EACViC,eAAgB,CACdC,QAAS,WAAM,IAAApC,EAAA,OAAkB,QAAlBA,EAAAF,EAASuC,eAAS,IAAArC,OAAA,EAAAA,EAAAsC,OAAO,EACxCC,OAnCe,SAACT,GAGlB,GAFAA,EAAEU,iBACFrC,GAAc,GACV2B,EAAEW,aAAapC,MAAO,CACxB,IAAMqC,EAAeT,MAAMC,KAAKJ,EAAEW,aAAapC,OAC/CD,EAASsC,EACV,CACH,EA6BIC,WA3BmB,SAACb,GACtBA,EAAEU,iBACFrC,GAAc,EAChB,EAyBIyC,YAvBoB,SAACd,GACvB3B,GAAc,EAChB,GAwBF"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as
|
|
2
|
+
import{jsx as o}from"react/jsx-runtime";import{useCell as e}from"../hooks.js";function n(n){var t=e(n.id,n.row),i=t.type,c=t.component,l=t.onDoubleClick,r=t.onMouseDown,s=t.onMouseEnter;return o("td",{id:n.id,className:"".concat(n.cellFormatClassName," select-none"),onDoubleClick:n.isExistOnClickRow?void 0:l,onMouseDown:r,onMouseEnter:s,children:o("div",{className:"flex items-center gap-3 min-h-10 w-fit p-2 cursor-default",onClick:function(o){o.stopPropagation()},children:"component"===i?c:o("div",{onDoubleClick:l,children:o("p",{className:"cell-data text-left whitespace-nowrap",children:c})})})})}export{n as TableCell};
|
|
3
3
|
//# sourceMappingURL=cell.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as t,Fragment as e}from"react/jsx-runtime";import{useState as r,useEffect as i}from"react";import{useCopyStateContext as o}from"./provider.js";import{IdGenerator as n}from"../libs/id-generator.js";function a(){var a=r(!1),c=a[0],m=a[1],u=o().copiedAt;if(i((function(){if(u){m(!0);var t=setTimeout((function(){m(!1)}),1e3);return function(){m(!1),clearTimeout(t)}}}),[u]),!c)return t(e,{});var f=document.getElementById(n.getTableId());if(!f)return t(e,{});var p=f.getBoundingClientRect(),d=p.right-120,s=p.bottom-50;return t("div",{className:"fixed z-[100] p-1 bg-gray-800 duration-300 pointer-events-none ".concat(c?"opacity-100":"opacity-0"),style:{top:s,left:d},children:t("p",{className:"text-white text-xs",children:"コピーしました!!!"})})}export{a as CopiedMessage};
|
|
2
|
+
//# sourceMappingURL=components.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../../../src/table/copy/components.tsx"],"sourcesContent":["import { useEffect, useState } from \"react\";\nimport { useCopyStateContext } from \"./provider\";\nimport { IdGenerator } from \"../libs\";\n\nexport function CopiedMessage() {\n const [isDisplay, setIsDisplay] = useState(false);\n const { copiedAt } = useCopyStateContext();\n\n useEffect(() => {\n if (copiedAt) {\n setIsDisplay(true);\n\n const timer = setTimeout(() => {\n setIsDisplay(false);\n }, 1000);\n\n return () => {\n setIsDisplay(false);\n clearTimeout(timer);\n };\n }\n }, [copiedAt]);\n\n if (!isDisplay) {\n return <></>;\n }\n\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!tableElement) {\n return <></>;\n }\n\n // テーブルの右下の位置を取得\n const rect = tableElement.getBoundingClientRect();\n const x = rect.right - 120;\n const y = rect.bottom - 50;\n\n return (\n <div\n className={`fixed z-[100] p-1 bg-gray-800 duration-300 pointer-events-none ${\n isDisplay ? \"opacity-100\" : \"opacity-0\"\n }`}\n style={{ top: y, left: x }}\n >\n <p className=\"text-white text-xs\">コピーしました!!!</p>\n </div>\n );\n}\n"],"names":["CopiedMessage","_a","useState","isDisplay","setIsDisplay","copiedAt","useCopyStateContext","useEffect","timer_1","setTimeout","clearTimeout","_jsx","tableElement","document","getElementById","IdGenerator","getTableId","rect","getBoundingClientRect","x","right","y","bottom","className","style","top","left","children"],"mappings":"yNAIgBA,IACR,IAAAC,EAA4BC,GAAS,GAApCC,EAASF,EAAA,GAAEG,EAAYH,EAAA,GACtBI,EAAaC,aAiBrB,GAfAC,GAAU,WACR,GAAIF,EAAU,CACZD,GAAa,GAEb,IAAMI,EAAQC,YAAW,WACvBL,GAAa,EACd,GAAE,KAEH,OAAO,WACLA,GAAa,GACbM,aAAaF,EACf,CACD,CACH,GAAG,CAACH,KAECF,EACH,OAAOQ,QAGT,IAAMC,EAAeC,SAASC,eAAeC,EAAYC,cAEzD,IAAKJ,EACH,OAAOD,QAIT,IAAMM,EAAOL,EAAaM,wBACpBC,EAAIF,EAAKG,MAAQ,IACjBC,EAAIJ,EAAKK,OAAS,GAExB,OACEX,EAAA,MAAA,CACEY,UAAW,yEACTpB,EAAY,cAAgB,aAE9BqB,MAAO,CAAEC,IAAKJ,EAAGK,KAAMP,GAEvBQ,SAAAhB,EAAA,IAAA,CAAGY,UAAU,qBAAmCI,SAAA,gBAGtD"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as
|
|
1
|
+
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as t,useCallback as n,useMemo as o}from"react";import{useRangeStateContext as r}from"../range/provider.js";var s=function(t,n){switch(n.type){case"setRows":return e(e({},t),{rows:n.payload.rows});case"setCols":return e(e({},t),{cols:n.payload.cols});case"copied":return e(e({},t),{copiedAt:new Date});default:return t}};function c(c){var d=t(s,e({},c)),i=d[0],a=d[1],u=r(),l=n((function(){if(u.isSelecting){var e=u.start.rowIndex<=u.end.rowIndex?u.start.rowIndex:u.end.rowIndex,t=u.start.rowIndex>=u.end.rowIndex?u.start.rowIndex:u.end.rowIndex,n=u.start.colIndex<=u.end.colIndex?u.start.colIndex:u.end.colIndex,o=u.start.colIndex>=u.end.colIndex?u.start.colIndex:u.end.colIndex,r=i.rows.slice(e,t+1).map((function(e){for(var t=[],r=function(n){var o=i.cols[n];if("number"==o.type||"string"==o.type)return t.push(e[o.key]),"continue";if("select"==o.type){var r=e[o.key];null==r||""===r?t.push(""):t.push(o.options.find((function(t){return t.value===e[o.key]})).label)}},s=n;s<=o;s++)r(s);return t})).map((function(e){return e.join("\t")})).join("\n");navigator.clipboard.writeText(r),a({type:"copied"})}}),[u,i.rows,i.cols]),p=n((function(e){a({type:"setRows",payload:{rows:e}})}),[]);return{states:o((function(){return{copiedAt:i.copiedAt}}),[i.copiedAt]),actions:o((function(){return{copy:l,setRows:p}}),[l,p])}}export{c as useCopyReducer};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/copy/hooks.ts"],"sourcesContent":["import { useCallback, useMemo, useReducer } from \"react\";\nimport { useRangeStateContext } from \"../range/provider\";\nimport { TCopyReducer, TReturnCopyReducer } from \"./types\";\n\nconst reducer: TCopyReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n default:\n return state;\n }\n};\n\nexport function useCopyReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TReturnCopyReducer {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n });\n const range = useRangeStateContext();\n\n const copy = useCallback(() => {\n if (!range.isSelecting) {\n return;\n }\n\n const startRowIndex
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/copy/hooks.ts"],"sourcesContent":["import { useCallback, useMemo, useReducer } from \"react\";\nimport { useRangeStateContext } from \"../range/provider\";\nimport { TCopyReducer, TReturnCopyReducer } from \"./types\";\n\nconst reducer: TCopyReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n case \"copied\":\n return { ...state, copiedAt: new Date() };\n default:\n return state;\n }\n};\n\nexport function useCopyReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TReturnCopyReducer {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n });\n const range = useRangeStateContext();\n\n const copy = useCallback(() => {\n if (!range.isSelecting) {\n return;\n }\n\n const startRowIndex =\n range.start.rowIndex <= range.end.rowIndex\n ? range.start.rowIndex\n : range.end.rowIndex;\n const endRowIndex =\n range.start.rowIndex >= range.end.rowIndex\n ? range.start.rowIndex\n : range.end.rowIndex;\n const startColIndex =\n range.start.colIndex <= range.end.colIndex\n ? range.start.colIndex\n : range.end.colIndex;\n const endColIndex =\n range.start.colIndex >= range.end.colIndex\n ? range.start.colIndex\n : range.end.colIndex;\n\n const copiedData = state.rows\n .slice(startRowIndex, endRowIndex + 1)\n .map((row) => {\n const copiedRow = [];\n for (let i = startColIndex; i <= endColIndex; i++) {\n const col = state.cols[i];\n\n if (col.type == \"number\" || col.type == \"string\") {\n copiedRow.push(row[col.key]);\n continue;\n } else if (col.type == \"select\") {\n const value = row[col.key];\n\n if (value === null || value === undefined || value === \"\") {\n copiedRow.push(\"\");\n } else {\n copiedRow.push(\n col.options.find((option) => option.value === row[col.key])!\n .label\n );\n }\n }\n }\n return copiedRow;\n });\n\n const copiedDataString = copiedData.map((row) => row.join(\"\\t\")).join(\"\\n\");\n\n navigator.clipboard.writeText(copiedDataString);\n dispatch({ type: \"copied\" });\n }, [range, state.rows, state.cols]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const states = useMemo(\n () => ({\n copiedAt: state.copiedAt,\n }),\n [state.copiedAt]\n );\n\n const actions = useMemo(\n () => ({\n copy,\n setRows,\n }),\n [copy, setRows]\n );\n\n return {\n states,\n actions,\n };\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","copiedAt","Date","useCopyReducer","initial","_a","useReducer","dispatch","range","useRangeStateContext","copy","useCallback","isSelecting","startRowIndex","start","rowIndex","end","endRowIndex","startColIndex","colIndex","endColIndex","copiedDataString","slice","map","row","copiedRow","i","col","push","key","value","options","find","option","label","join","navigator","clipboard","writeText","setRows","states","useMemo","actions"],"mappings":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D,EAAII,QAAQC,MAAK,SAACC,GAAW,OAAAA,EAAOH,QAAUN,EAAIG,EAAIE,IAAzB,IAC1BK,MAGR,GAjBMR,EAAIR,EAAeQ,GAAKN,EAAaM,MAArCA,GAmBT,OAAOD,CACT,IAEkCF,KAAI,SAACC,GAAQ,OAAAA,EAAIW,KAAK,KAAK,IAAEA,KAAK,MAEtEC,UAAUC,UAAUC,UAAUjB,GAC9Bd,EAAS,CAAEX,KAAM,UAhDhB,CAiDH,GAAG,CAACY,EAAOd,EAAMI,KAAMJ,EAAMM,OAEvBuC,EAAU5B,GAAY,SAACb,GAC3BS,EAAS,CAAEX,KAAM,UAAWG,QAAS,CAAED,KAAIA,IAC5C,GAAE,IAiBH,MAAO,CACL0C,OAhBaC,GACb,WAAM,MAAC,CACLxC,SAAUP,EAAMO,YAElB,CAACP,EAAMO,WAaPyC,QAVcD,GACd,WAAM,MAAC,CACL/B,KAAIA,EACJ6B,QAAOA,KAET,CAAC7B,EAAM6B,IAOX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as r}from"react/jsx-runtime";import{createContext as o,useContext as t}from"react";import{useCopyReducer as
|
|
1
|
+
import{jsx as r}from"react/jsx-runtime";import{createContext as o,useContext as t}from"react";import{useCopyReducer as e}from"./hooks.js";var n=o({copiedAt:new Date}),i=o({copy:function(){},setRows:function(){}});function c(o){var t=o.children,c=o.rows,s=o.cols,u=e({rows:c,cols:s}),a=u.states,f=u.actions;return r(n.Provider,{value:a,children:r(i.Provider,{value:f,children:t})})}function s(){return t(n)}function u(){return t(i)}export{c as CopyProvider,u as useCopyActionContext,s as useCopyStateContext};
|
|
2
2
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/copy/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { TCopyActionContext } from \"./types\";\nimport { useCopyReducer } from \"./hooks\";\n\nconst CopyActionContext = createContext<TCopyActionContext>({\n copy: () => {},\n setRows: () => {},\n});\n\nexport function CopyProvider({\n children,\n rows,\n cols,\n}: {\n children: JSX.Element | JSX.Element[];\n rows: any[];\n cols: any[];\n}) {\n
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/copy/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { TCopyActionContext, TCopyStateContext } from \"./types\";\nimport { useCopyReducer } from \"./hooks\";\n\nconst CopyStateContext = createContext<TCopyStateContext>({\n copiedAt: new Date(),\n});\n\nconst CopyActionContext = createContext<TCopyActionContext>({\n copy: () => {},\n setRows: () => {},\n});\n\nexport function CopyProvider({\n children,\n rows,\n cols,\n}: {\n children: JSX.Element | JSX.Element[];\n rows: any[];\n cols: any[];\n}) {\n const { states, actions } = useCopyReducer({\n rows,\n cols,\n });\n return (\n <CopyStateContext.Provider value={states}>\n <CopyActionContext.Provider value={actions}>\n {children}\n </CopyActionContext.Provider>\n </CopyStateContext.Provider>\n );\n}\n\nexport function useCopyStateContext() {\n return useContext(CopyStateContext);\n}\n\nexport function useCopyActionContext() {\n return useContext(CopyActionContext);\n}\n"],"names":["CopyStateContext","createContext","copiedAt","Date","CopyActionContext","copy","setRows","CopyProvider","_a","children","rows","cols","_b","useCopyReducer","states","actions","_jsx","Provider","value","useCopyStateContext","useContext","useCopyActionContext"],"mappings":"0IAIA,IAAMA,EAAmBC,EAAiC,CACxDC,SAAU,IAAIC,OAGVC,EAAoBH,EAAkC,CAC1DI,KAAM,WAAQ,EACdC,QAAS,WAAQ,IAGb,SAAUC,EAAaC,GAC3B,IAAAC,aACAC,EAAIF,EAAAE,KACJC,EAAIH,EAAAG,KAMEC,EAAsBC,EAAe,CACzCH,KAAIA,EACJC,KAAIA,IAFEG,EAAMF,EAAAE,OAAEC,YAIhB,OACEC,EAAChB,EAAiBiB,SAAS,CAAAC,MAAOJ,EAChCL,SAAAO,EAACZ,EAAkBa,SAAS,CAAAC,MAAOH,WAChCN,KAIT,UAEgBU,IACd,OAAOC,EAAWpB,EACpB,UAEgBqB,IACd,OAAOD,EAAWhB,EACpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as e,useEffect as
|
|
1
|
+
import{__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as e,useEffect as a,useCallback as o,useMemo as n}from"react";import{useColumnValidatesContext as r}from"../sheet/providers.js";import{useRangeActionContext as s,useRangeStateContext as i}from"../range/provider.js";import{paste as d}from"./logic.js";var c=function(e,a){switch(a.type){case"setRows":return t(t({},e),{rows:a.payload.rows});case"setCols":return t(t({},e),{cols:a.payload.cols});case"setColValidators":return t(t({},e),{colValidators:a.payload.colValidators});case"setOnUpdateRowFunction":return t(t({},e),{onUpdateRowFunction:a.payload.onUpdateRowFunction});case"onPaste":if(!e.isFocused)return e;var o=a.payload.pasteData,n=e.rows,r=e.cols,s=e.colValidators,i=e.start,c=e.end,u=e.onUpdateRowFunction,l=e.setRange;if(!u)return e;var p=d({pasteData:o,pasteArea:{start:i,end:c},currentRows:n,currentCols:r,validators:s,tableArea:{start:{rowIndex:0,colIndex:0},end:{rowIndex:n.length-1,colIndex:r.length-1}}});return p.isError?("ValidationError"!==p.type&&"NoPasteData"!==p.type&&alert(p.message),e):(l({start:p.pasteRange.start,end:p.pasteRange.end}),t(t({},e),{updateParameters:{arguments:p.updateArgument,timing:e.updateParameters.timing+1}}));case"focus":return t(t({},e),{isFocused:!0,start:a.payload.start,end:a.payload.end});case"unfocus":return t(t({},e),{isFocused:!1})}};function u(d){var u=s().setRange,l=e(c,t(t({},d),{colValidators:{},isFocused:!1,updateParameters:{arguments:[],timing:0},setRange:u})),p=l[0],m=l[1],f=r(),g=i();a((function(){g.isSelecting?m({type:"focus",payload:{start:g.start,end:g.end}}):m({type:"unfocus"})}),[g]);var w=o((function(t){m({type:"setRows",payload:{rows:t}})}),[]),y=o((function(t){m({type:"setCols",payload:{cols:t}})}),[]),R=o((function(t){m({type:"setColValidators",payload:{colValidators:t}})}),[]);a((function(){R(f)}),[f]);var v=o((function(t){m({type:"setOnUpdateRowFunction",payload:{onUpdateRowFunction:t}})}),[]),F=o((function(t){m({type:"onPaste",payload:{pasteData:t}})}),[]);return a((function(){p.updateParameters.arguments.length>0&&p.updateParameters.arguments.forEach((function(t){var e,a=t.newRow,o=t.oldRow;null===(e=p.onUpdateRowFunction)||void 0===e||e.call(p,a,o)}))}),[p.updateParameters.timing,p.onUpdateRowFunction]),a((function(){var t=function(t){if(g.isSelecting&&t.clipboardData){t.preventDefault();var e=t.clipboardData.getData("Text");F(e.replace(/\t/g,",").trim().replace(/\r\n/g,"\n").split("\n").map((function(t){return t.split(",")})))}};return document.addEventListener("paste",t),function(){document.removeEventListener("paste",t)}}),[g.isSelecting]),n((function(){return{setRows:w,setCols:y,setColValidators:R,setOnUpdateRowFunction:v,onPaste:F}}),[])}export{u as usePasteReducer};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/paste/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useReducer } from \"react\";\nimport { TPasteReducer, TPasteReducerReturn } from \"./types\";\nimport { useColumnValidatesContext } from \"../sheet/providers\";\nimport { useRangeStateContext } from \"../range/provider\";\n\nconst reducer: TPasteReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n case \"setColValidators\":\n return { ...state, colValidators: action.payload.colValidators };\n case \"setOnUpdateRowFunction\":\n return {\n ...state,\n onUpdateRowFunction: action.payload.onUpdateRowFunction,\n };\n case \"onPaste\":\n if (!state.isFocused) {\n return state;\n }\n\n const { pasteData } = action.payload;\n const {\n rows,\n cols,\n colValidators,\n rowIndex,\n colIndex,\n onUpdateRowFunction,\n } = state;\n\n if (!onUpdateRowFunction) {\n return state;\n }\n\n const updateParameters = {\n arguments: [] as { newRow: any; oldRow: any }[],\n timing: state.updateParameters.timing + 1,\n };\n\n const rowLength = pasteData.length;\n const colLength = Math.max(...pasteData.map((row) => row.length));\n\n if (rowLength === 0 || colLength === 0) return state;\n\n if (pasteData.length + rowIndex > rows.length) {\n alert(\"貼り付け先の行数が足りません。\");\n return state;\n }\n\n for (let i = 0; i < colLength; i++) {\n const col = cols[colIndex + i];\n\n if (!col.editable) {\n alert(\n `編集できない列にデータを貼り付けることはできません。\\n\\n編集不可列: ${\n col.label ?? (col.key as string)\n }`\n );\n return state;\n }\n }\n\n if (colLength + colIndex > cols.length) {\n alert(\"貼り付け先の列数が足りません。\");\n return state;\n }\n\n for (let i = 0; i < rowLength; i++) {\n const pasteRow = pasteData[i];\n\n for (let j = 0; j < pasteRow.length; j++) {\n const pasteValue = pasteRow[j];\n const col = cols[colIndex + j];\n const validate = colValidators[col.key as string];\n\n if (!validate(pasteValue)) {\n return state;\n }\n }\n }\n\n pasteData.forEach((pasteRow, i) => {\n const row = { ...rows[rowIndex + i] };\n let checkUpdatedRow = false;\n\n pasteRow.forEach((pasteValue, j) => {\n const col = cols[colIndex + j];\n const value =\n col.type === \"number\"\n ? Number(pasteValue)\n : col.type === \"select\"\n ? pasteValue === \"\"\n ? \"\"\n : col.options.find((option) => option.label === pasteValue)!\n .value\n : pasteValue;\n if (row[col.key] !== value) {\n checkUpdatedRow = true;\n row[col.key] = value;\n }\n });\n\n if (checkUpdatedRow) {\n updateParameters.arguments.push({\n newRow: row,\n oldRow: rows[rowIndex + i],\n });\n }\n });\n\n if (updateParameters.arguments.length > 0) {\n return { ...state, updateParameters };\n } else {\n return state;\n }\n case \"focus\":\n return {\n ...state,\n isFocused: true,\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n };\n case \"unfocus\":\n return { ...state, isFocused: false };\n }\n};\n\nexport function usePasteReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TPasteReducerReturn {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n colValidators: {},\n isFocused: false,\n updateParameters: { arguments: [], timing: 0 },\n });\n const validators = useColumnValidatesContext();\n const range = useRangeStateContext();\n\n useEffect(() => {\n if (range.isSelecting) {\n dispatch({\n type: \"focus\",\n payload: {\n rowIndex: range.start.rowIndex,\n colIndex: range.start.colIndex,\n },\n });\n } else {\n dispatch({ type: \"unfocus\" });\n }\n }, [range]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const setCols = useCallback((cols: any[]) => {\n dispatch({ type: \"setCols\", payload: { cols } });\n }, []);\n\n const setColValidators = useCallback(\n (colValidators: { [key: string]: (value: any) => boolean }) => {\n dispatch({ type: \"setColValidators\", payload: { colValidators } });\n },\n []\n );\n\n useEffect(() => {\n setColValidators(validators);\n }, [validators]);\n\n const setOnUpdateRowFunction = useCallback(\n (onUpdateRowFunction?: (newRow: any, oldRow: any) => void) => {\n dispatch({\n type: \"setOnUpdateRowFunction\",\n payload: { onUpdateRowFunction },\n });\n },\n []\n );\n\n const onPaste = useCallback((pasteData: string[][]) => {\n dispatch({ type: \"onPaste\", payload: { pasteData } });\n }, []);\n\n useEffect(() => {\n if (state.updateParameters.arguments.length > 0) {\n state.updateParameters.arguments.forEach(({ newRow, oldRow }) => {\n state.onUpdateRowFunction?.(newRow, oldRow);\n });\n }\n }, [state.updateParameters.timing, state.onUpdateRowFunction]);\n\n useEffect(() => {\n const paste = (e: ClipboardEvent) => {\n if (!range.isSelecting) {\n return;\n }\n\n if (e.clipboardData) {\n e.preventDefault();\n const pastedData = e.clipboardData.getData(\"Text\");\n\n onPaste(\n pastedData\n .replace(/\\t/g, \",\")\n .trim()\n .replace(/\\r\\n/g, \"\\n\")\n .split(\"\\n\")\n .map((row) => row.split(\",\"))\n );\n }\n };\n\n document.addEventListener(\"paste\", paste);\n\n return () => {\n document.removeEventListener(\"paste\", paste);\n };\n }, [range.isSelecting]);\n\n const actions: TPasteReducerReturn = useMemo(\n () => ({\n setRows,\n setCols,\n setColValidators,\n setOnUpdateRowFunction,\n onPaste,\n }),\n []\n );\n\n return actions;\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","colValidators","onUpdateRowFunction","isFocused","pasteData","rows_1","cols_1","rowIndex_1","rowIndex","colIndex_1","colIndex","updateParameters_1","arguments","timing","updateParameters","rowLength","length","colLength","Math","max","apply","map","row","alert","i","col","editable","concat","_a","label","key","pasteRow","j","pasteValue","validate","forEach","checkUpdatedRow","value","Number","options","find","option","push","newRow","oldRow","usePasteReducer","initial","useReducer","dispatch","validators","useColumnValidatesContext","range","useRangeStateContext","useEffect","isSelecting","start","setRows","useCallback","setCols","setColValidators","setOnUpdateRowFunction","onPaste","_b","call","paste","e","clipboardData","preventDefault","pastedData","getData","replace","trim","split","document","addEventListener","removeEventListener","useMemo"],"mappings":"kRAKA,IAAMA,EAAyB,SAACC,EAAOC,SACrC,OAAQA,EAAOC,MACb,IAAK,UACH,OAAYC,EAAAA,EAAA,CAAA,EAAAH,IAAOI,KAAMH,EAAOI,QAAQD,OAC1C,IAAK,UACH,OAAYD,EAAAA,EAAA,CAAA,EAAAH,IAAOM,KAAML,EAAOI,QAAQC,OAC1C,IAAK,mBACH,OAAYH,EAAAA,EAAA,CAAA,EAAAH,IAAOO,cAAeN,EAAOI,QAAQE,gBACnD,IAAK,yBACH,OACKJ,EAAAA,EAAA,CAAA,EAAAH,IACHQ,oBAAqBP,EAAOI,QAAQG,sBAExC,IAAK,UACH,IAAKR,EAAMS,UACT,OAAOT,EAGD,IAAAU,EAAcT,EAAOI,kBAE3BM,EAMEX,EAAKI,KALPQ,EAKEZ,EALEM,KACJC,EAIEP,EAAKO,cAHPM,EAGEb,EAHMc,SACRC,EAEEf,EAAKgB,SAET,IAFIhB,sBAGF,OAAOA,EAGT,IAAMiB,EAAmB,CACvBC,UAAW,GACXC,OAAQnB,EAAMoB,iBAAi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,IAiDH,OA/CAiD,GAAU,WACJ3D,EAAMoB,iBAAiBF,UAAUI,OAAS,GAC5CtB,EAAMoB,iBAAiBF,UAAUuB,SAAQ,SAACP,SAAEe,EAAMf,EAAAe,OAAEC,EAAMhB,EAAAgB,OAC/B,QAAzBkB,EAAApE,EAAMQ,2BAAmB,IAAA4D,GAAAA,EAAAC,KAAArE,EAAGiD,EAAQC,EACtC,GAEJ,GAAG,CAAClD,EAAMoB,iBAAiBD,OAAQnB,EAAMQ,sBAEzCmD,GAAU,WACR,IAAMW,EAAQ,SAACC,GACb,GAAKd,EAAMG,aAIPW,EAAEC,cAAe,CACnBD,EAAEE,iBACF,IAAMC,EAAaH,EAAEC,cAAcG,QAAQ,QAE3CR,EACEO,EACGE,QAAQ,MAAO,KACfC,OACAD,QAAQ,QAAS,MACjBE,MAAM,MACNnD,KAAI,SAACC,GAAQ,OAAAA,EAAIkD,MAAM,IAAI,IAEjC,CACH,EAIA,OAFAC,SAASC,iBAAiB,QAASV,GAE5B,WACLS,SAASE,oBAAoB,QAASX,EACxC,CACF,GAAG,CAACb,EAAMG,cAE2BsB,GACnC,WAAM,MAAC,CACLpB,QAAOA,EACPE,QAAOA,EACPC,iBAAgBA,EAChBC,uBAAsBA,EACtBC,QAAOA,EALH,GAON,GAIJ"}
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/paste/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo, useReducer } from \"react\";\nimport { TPasteReducer, TPasteReducerReturn } from \"./types\";\nimport { useColumnValidatesContext } from \"../sheet/providers\";\nimport { useRangeActionContext, useRangeStateContext } from \"../range/provider\";\nimport { paste } from \"./logic\";\n\nconst reducer: TPasteReducer = (state, action) => {\n switch (action.type) {\n case \"setRows\":\n return { ...state, rows: action.payload.rows };\n case \"setCols\":\n return { ...state, cols: action.payload.cols };\n case \"setColValidators\":\n return { ...state, colValidators: action.payload.colValidators };\n case \"setOnUpdateRowFunction\":\n return {\n ...state,\n onUpdateRowFunction: action.payload.onUpdateRowFunction,\n };\n case \"onPaste\":\n if (!state.isFocused) {\n return state;\n }\n\n const { pasteData } = action.payload;\n const {\n rows,\n cols,\n colValidators,\n start,\n end,\n onUpdateRowFunction,\n setRange,\n } = state;\n\n if (!onUpdateRowFunction) {\n return state;\n }\n\n const res = paste({\n pasteData,\n pasteArea: { start, end },\n currentRows: rows,\n currentCols: cols,\n validators: colValidators,\n tableArea: {\n start: {\n rowIndex: 0,\n colIndex: 0,\n },\n end: {\n rowIndex: rows.length - 1,\n colIndex: cols.length - 1,\n },\n },\n });\n\n if (res.isError) {\n if (res.type !== \"ValidationError\" && res.type !== \"NoPasteData\") {\n alert(res.message);\n }\n return state;\n }\n\n setRange({\n start: res.pasteRange.start,\n end: res.pasteRange.end,\n });\n\n return {\n ...state,\n updateParameters: {\n arguments: res.updateArgument,\n timing: state.updateParameters.timing + 1,\n },\n };\n case \"focus\":\n return {\n ...state,\n isFocused: true,\n start: action.payload.start,\n end: action.payload.end,\n };\n case \"unfocus\":\n return { ...state, isFocused: false };\n }\n};\n\nexport function usePasteReducer(initial: {\n rows: any[];\n cols: any[];\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TPasteReducerReturn {\n const { setRange } = useRangeActionContext();\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n colValidators: {},\n isFocused: false,\n updateParameters: { arguments: [], timing: 0 },\n setRange,\n });\n const validators = useColumnValidatesContext();\n const range = useRangeStateContext();\n\n useEffect(() => {\n if (range.isSelecting) {\n dispatch({\n type: \"focus\",\n payload: {\n start: range.start,\n end: range.end,\n },\n });\n } else {\n dispatch({ type: \"unfocus\" });\n }\n }, [range]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const setCols = useCallback((cols: any[]) => {\n dispatch({ type: \"setCols\", payload: { cols } });\n }, []);\n\n const setColValidators = useCallback(\n (colValidators: { [key: string]: (value: any) => boolean }) => {\n dispatch({ type: \"setColValidators\", payload: { colValidators } });\n },\n []\n );\n\n useEffect(() => {\n setColValidators(validators);\n }, [validators]);\n\n const setOnUpdateRowFunction = useCallback(\n (onUpdateRowFunction?: (newRow: any, oldRow: any) => void) => {\n dispatch({\n type: \"setOnUpdateRowFunction\",\n payload: { onUpdateRowFunction },\n });\n },\n []\n );\n\n const onPaste = useCallback((pasteData: string[][]) => {\n dispatch({ type: \"onPaste\", payload: { pasteData } });\n }, []);\n\n useEffect(() => {\n if (state.updateParameters.arguments.length > 0) {\n state.updateParameters.arguments.forEach(({ newRow, oldRow }) => {\n state.onUpdateRowFunction?.(newRow, oldRow);\n });\n }\n }, [state.updateParameters.timing, state.onUpdateRowFunction]);\n\n useEffect(() => {\n const paste = (e: ClipboardEvent) => {\n if (!range.isSelecting) {\n return;\n }\n\n if (e.clipboardData) {\n e.preventDefault();\n const pastedData = e.clipboardData.getData(\"Text\");\n\n onPaste(\n pastedData\n .replace(/\\t/g, \",\")\n .trim()\n .replace(/\\r\\n/g, \"\\n\")\n .split(\"\\n\")\n .map((row) => row.split(\",\"))\n );\n }\n };\n\n document.addEventListener(\"paste\", paste);\n\n return () => {\n document.removeEventListener(\"paste\", paste);\n };\n }, [range.isSelecting]);\n\n const actions: TPasteReducerReturn = useMemo(\n () => ({\n setRows,\n setCols,\n setColValidators,\n setOnUpdateRowFunction,\n onPaste,\n }),\n []\n );\n\n return actions;\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","colValidators","onUpdateRowFunction","isFocused","pasteData","start","end","setRange","res","paste","pasteArea","currentRows","currentCols","validators","tableArea","rowIndex","colIndex","length","isError","alert","message","pasteRange","updateParameters","arguments","updateArgument","timing","usePasteReducer","initial","useRangeActionContext","_a","useReducer","dispatch","useColumnValidatesContext","range","useRangeStateContext","useEffect","isSelecting","setRows","useCallback","setCols","setColValidators","setOnUpdateRowFunction","onPaste","forEach","newRow","oldRow","_b","call","e","clipboardData","preventDefault","pastedData","getData","replace","trim","split","map","row","document","addEvent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AAAgB,OAC/B,QAAzBC,EAAApD,EAAMQ,2BAAmB,IAAA4C,GAAAA,EAAAC,KAAArD,EAAGkD,EAAQC,EACtC,GAEJ,GAAG,CAACnD,EAAM4B,iBAAiBG,OAAQ/B,EAAMQ,sBAEzCiC,GAAU,WACR,IAAM1B,EAAQ,SAACuC,GACb,GAAKf,EAAMG,aAIPY,EAAEC,cAAe,CACnBD,EAAEE,iBACF,IAAMC,EAAaH,EAAEC,cAAcG,QAAQ,QAE3CV,EACES,EACGE,QAAQ,MAAO,KACfC,OACAD,QAAQ,QAAS,MACjBE,MAAM,MACNC,KAAI,SAACC,GAAQ,OAAAA,EAAIF,MAAM,IAAI,IAEjC,CACH,EAIA,OAFAG,SAASC,iBAAiB,QAASlD,GAE5B,WACLiD,SAASE,oBAAoB,QAASnD,EACxC,CACF,GAAG,CAACwB,EAAMG,cAE2ByB,GACnC,WAAM,MAAC,CACLxB,QAAOA,EACPE,QAAOA,EACPC,iBAAgBA,EAChBC,uBAAsBA,EACtBC,QAAOA,EALH,GAON,GAIJ"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__assign as r}from"../../../node_modules/tslib/tslib.es6.js";function e(e){var t,a=e.pasteData.length,s=Math.max.apply(Math,e.pasteData.map((function(r){return r.length})));if(0===a||0===s)return{isError:!0,type:"NoPasteData",message:"ペーストデータがありません。"};var n=e.pasteArea.end.rowIndex-e.pasteArea.start.rowIndex+1,o=e.pasteArea.end.colIndex-e.pasteArea.start.colIndex+1,l=n<a?a:n,p=o<s?s:o;if(l+e.pasteArea.start.rowIndex>e.currentRows.length)return{isError:!0,type:"OtherError",message:"貼り付け先の行数が足りません。"};if(p+e.pasteArea.start.colIndex>e.currentCols.length)return{isError:!0,type:"OtherError",message:"貼り付け先の列数が足りません。"};for(var d=0;d<p;d++){if(!(I=e.currentCols[e.pasteArea.start.colIndex+d]).editable)return{isError:!0,type:"OtherError",message:"編集できない列にデータを貼り付けることはできません。\n\n編集不可列: ".concat(null!==(t=I.label)&&void 0!==t?t:I.key)}}for(d=0;d<a;d++)for(var u=e.pasteData[d],c=0;c<p;c++){var i=c%u.length,x=u[i],I=e.currentCols[e.pasteArea.start.colIndex+c];if(!(0,e.validators[I.key])(x))return{isError:!0,type:"ValidationError",message:"バリデーションエラー: ".concat(x)}}var f=[];for(d=0;d<l;d++){u=e.pasteData[d%a];var A=r({},e.currentRows[e.pasteArea.start.rowIndex+d]),w=!1,g=function(r){var t=u[r%u.length],a=e.currentCols[e.pasteArea.start.colIndex+r],s="number"===a.type?Number(t):"select"===a.type?""===t?"":a.options.find((function(r){return r.label===t})).value:t;A[a.key]!==s&&(w=!0,A[a.key]=s)};for(c=0;c<p;c++)g(c);w&&f.push({newRow:A,oldRow:e.currentRows[e.pasteArea.start.rowIndex+d]})}return{isError:!1,updateArgument:f,pasteRange:{start:{rowIndex:e.pasteArea.start.rowIndex,colIndex:e.pasteArea.start.colIndex},end:{rowIndex:e.pasteArea.start.rowIndex+l-1,colIndex:e.pasteArea.start.colIndex+p-1}}}}export{e as paste};
|
|
2
|
+
//# sourceMappingURL=logic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logic.js","sources":["../../../../../src/table/paste/logic.ts"],"sourcesContent":["import { TTableColumn } from \"../table/type\";\n\ntype TPasteArgument = {\n pasteData: string[][];\n currentRows: any[];\n currentCols: TTableColumn<any>[];\n tableArea: {\n start: {\n rowIndex: number;\n colIndex: number;\n };\n end: {\n rowIndex: number;\n colIndex: number;\n };\n };\n pasteArea: {\n start: {\n rowIndex: number;\n colIndex: number;\n };\n end: {\n rowIndex: number;\n colIndex: number;\n };\n };\n validators: {\n [key: string]: (value: any) => boolean;\n };\n};\n\ntype TPasteResult =\n | {\n isError: true;\n type: \"ValidationError\" | \"NoPasteData\" | \"OtherError\";\n message: string;\n }\n | {\n isError: false;\n updateArgument: {\n newRow: any;\n oldRow: any;\n }[];\n pasteRange: {\n start: {\n rowIndex: number;\n colIndex: number;\n };\n end: {\n rowIndex: number;\n colIndex: number;\n };\n };\n };\n\nexport function paste(args: TPasteArgument): TPasteResult {\n // ペーストデータの行数と列数を取得\n const pasteDataRowLength = args.pasteData.length;\n const pasteDataColLength = Math.max(\n ...args.pasteData.map((row) => row.length)\n );\n\n // ペーストデータが空の場合は何もしない\n if (pasteDataRowLength === 0 || pasteDataColLength === 0) {\n return {\n isError: true,\n type: \"NoPasteData\",\n message: \"ペーストデータがありません。\",\n };\n }\n\n // Rangeの種類を取得\n const rangeRowLength =\n args.pasteArea.end.rowIndex - args.pasteArea.start.rowIndex + 1;\n const rangeColLength =\n args.pasteArea.end.colIndex - args.pasteArea.start.colIndex + 1;\n\n const pasteRowLength =\n rangeRowLength < pasteDataRowLength ? pasteDataRowLength : rangeRowLength;\n const pasteColLength =\n rangeColLength < pasteDataColLength ? pasteDataColLength : rangeColLength;\n\n // ペースト先の行数が足りない場合はエラー\n if (\n pasteRowLength + args.pasteArea.start.rowIndex >\n args.currentRows.length\n ) {\n return {\n isError: true,\n type: \"OtherError\",\n message: \"貼り付け先の行数が足りません。\",\n };\n }\n // ペースト先の列数が足りない場合はエラー\n if (\n pasteColLength + args.pasteArea.start.colIndex >\n args.currentCols.length\n ) {\n return {\n isError: true,\n type: \"OtherError\",\n message: \"貼り付け先の列数が足りません。\",\n };\n }\n\n // ペースト先の列に編集不可列が含まれている場合はエラー\n for (let i = 0; i < pasteColLength; i++) {\n const col = args.currentCols[args.pasteArea.start.colIndex + i];\n\n if (!col.editable) {\n return {\n isError: true,\n type: \"OtherError\",\n message: `編集できない列にデータを貼り付けることはできません。\\n\\n編集不可列: ${\n col.label ?? (col.key as string)\n }`,\n };\n }\n }\n\n // ペーストデータのバリデーション\n for (let i = 0; i < pasteDataRowLength; i++) {\n const pasteRow = args.pasteData[i];\n\n for (let j = 0; j < pasteColLength; j++) {\n const colIndexForData = j % pasteRow.length;\n const pasteValue = pasteRow[colIndexForData];\n const col = args.currentCols[args.pasteArea.start.colIndex + j];\n const validate = args.validators[col.key as string];\n\n if (!validate(pasteValue)) {\n return {\n isError: true,\n type: \"ValidationError\",\n message: `バリデーションエラー: ${pasteValue}`,\n };\n }\n }\n }\n\n const updateArguments: { newRow: any; oldRow: any }[] = [];\n\n // ペーストデータを反映\n for (let i = 0; i < pasteRowLength; i++) {\n const pasteRow = args.pasteData[i % pasteDataRowLength];\n const newRow = { ...args.currentRows[args.pasteArea.start.rowIndex + i] };\n let checkUpdatedRow = false;\n\n for (let j = 0; j < pasteColLength; j++) {\n const pasteValue = pasteRow[j % pasteRow.length];\n const col = args.currentCols[args.pasteArea.start.colIndex + j];\n const value =\n col.type === \"number\"\n ? Number(pasteValue)\n : col.type === \"select\"\n ? pasteValue === \"\"\n ? \"\"\n : col.options.find((option) => option.label === pasteValue)!.value\n : pasteValue;\n if (newRow[col.key] !== value) {\n checkUpdatedRow = true;\n newRow[col.key] = value;\n }\n }\n\n if (checkUpdatedRow) {\n updateArguments.push({\n newRow,\n oldRow: args.currentRows[args.pasteArea.start.rowIndex + i],\n });\n }\n }\n\n return {\n isError: false,\n updateArgument: updateArguments,\n pasteRange: {\n start: {\n rowIndex: args.pasteArea.start.rowIndex,\n colIndex: args.pasteArea.start.colIndex,\n },\n end: {\n rowIndex: args.pasteArea.start.rowIndex + pasteRowLength - 1,\n colIndex: args.pasteArea.start.colIndex + pasteColLength - 1,\n },\n },\n };\n}\n"],"names":["paste","args","pasteDataRowLength","pasteData","length","pasteDataColLength","Math","max","map","row","isError","type","message","rangeRowLength","pasteArea","end","rowIndex","start","rangeColLength","colIndex","pasteRowLength","pasteColLength","currentRows","currentCols","i","col","editable","concat","_a","label","key","pasteRow","j","colIndexForData","pasteValue","validate","validators","updateArguments","newRow","__assign","checkUpdatedRow","value","Number","options","find","option","push","oldRow","updateArgument","pasteRange"],"mappings":"oEAuDM,SAAUA,EAAMC,SAEdC,EAAqBD,EAAKE,UAAUC,OACpCC,EAAqBC,KAAKC,UAALD,KACtBL,EAAKE,UAAUK,KAAI,S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,GAGxD,IAASb,EAAI,EAAGA,EAAIJ,EAAgBI,IAAK,CACjCO,EAAW9B,EAAKE,UAAUqB,EAAItB,GAApC,IACMoC,EAAcC,EAAA,CAAA,EAAAtC,EAAKqB,YAAYrB,EAAKa,UAAUG,MAAMD,SAAWQ,IACjEgB,GAAkB,aAEbR,GACP,IAAME,EAAaH,EAASC,EAAID,EAAS3B,QACnCqB,EAAMxB,EAAKsB,YAAYtB,EAAKa,UAAUG,MAAME,SAAWa,GACvDS,EACS,WAAbhB,EAAId,KACA+B,OAAOR,GACM,WAAbT,EAAId,KACW,KAAfuB,EACE,GACAT,EAAIkB,QAAQC,MAAK,SAACC,GAAW,OAAAA,EAAOhB,QAAUK,CAAU,IAAGO,MAC7DP,EACFI,EAAOb,EAAIK,OAASW,IACtBD,GAAkB,EAClBF,EAAOb,EAAIK,KAAOW,IAbtB,IAAST,EAAI,EAAGA,EAAIX,EAAgBW,MAA3BA,GAiBLQ,GACFH,EAAgBS,KAAK,CACnBR,OAAMA,EACNS,OAAQ9C,EAAKqB,YAAYrB,EAAKa,UAAUG,MAAMD,SAAWQ,IAG9D,CAED,MAAO,CACLd,SAAS,EACTsC,eAAgBX,EAChBY,WAAY,CACVhC,MAAO,CACLD,SAAUf,EAAKa,UAAUG,MAAMD,SAC/BG,SAAUlB,EAAKa,UAAUG,MAAME,UAEjCJ,IAAK,CACHC,SAAUf,EAAKa,UAAUG,MAAMD,SAAWI,EAAiB,EAC3DD,SAAUlB,EAAKa,UAAUG,MAAME,SAAWE,EAAiB,IAInE"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as t,useMemo as n,useEffect as o}from"react";import{IdGenerator as i}from"../libs/id-generator.js";function r(e){return{maxColIndex:e.maxColIndex<-1?-1:e.maxColIndex,maxRowIndex:e.maxRowIndex<-1?-1:e.maxRowIndex}}function d(e){var t=e.rowIndex,n=e.colIndex;return t<0?t=0:e.constraint.maxRowIndex<t&&(t=e.constraint.maxRowIndex),n<0?n=0:e.constraint.maxColIndex<n&&(n=e.constraint.maxColIndex),{rowIndex:t,colIndex:n}}function a(e,t){return e.rowIndex===t.rowIndex&&e.colIndex===t.colIndex}var c={UP:{deltaRow:-1,deltaCol:0},DOWN:{deltaRow:1,deltaCol:0},LEFT:{deltaRow:0,deltaCol:-1},RIGHT:{deltaRow:0,deltaCol:1}};function s(e){var t=e.index,n=e.direction,o=e.constraint,i=c[n],r=i.deltaRow,a=i.deltaCol;return d({rowIndex:t.rowIndex+r,colIndex:t.colIndex+a,constraint:o})}var l=function(t,n){switch(n.type){case"setMax":return e(e({},t),{constraint:r(n.payload)});case"startSelectRange":var o=d({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return t.isSelecting&&a(t.start,o)&&a(t.end,o)&&t.inProgress?t:e(e({},t),{isSelecting:!0,inProgress:!0,start:o,end:o});case"moveSelectRange":if(!t.isSelecting||!t.inProgress)return t;var i=d({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return a(t.end,i)?t:e(e({},t),{end:i});case"endSelectRange":return t.isSelecting&&t.inProgress?e(e({},t),{inProgress:!1}):t;case"moveUp":return t.isSelecting?a(o=s({index:t.start,direction:"UP",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"moveDown":return t.isSelecting?a(o=s({index:t.start,direction:"DOWN",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"moveLeft":return t.isSelecting?a(o=s({index:t.start,direction:"LEFT",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"moveRight":return t.isSelecting?a(o=s({index:t.start,direction:"RIGHT",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"extendUp":return t.isSelecting?a(i=s({index:t.end,direction:"UP",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"extendDown":return t.isSelecting?a(i=s({index:t.end,direction:"DOWN",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"extendLeft":return t.isSelecting?a(i=s({index:t.end,direction:"LEFT",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"extendRight":return t.isSelecting?a(i=s({index:t.end,direction:"RIGHT",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"reset":return{constraint:t.constraint,isSelecting:!1}}};function x(){var d=t(l,{constraint:r({maxColIndex:0,maxRowIndex:0}),isSelecting:!1}),a=d[0],c=d[1],s=n((function(){return{setMax:function(e){c({type:"setMax",payload:e})},startSelectRange:function(e){c({type:"startSelectRange",payload:e})},moveSelectRange:function(e){c({type:"moveSelectRange",payload:e})},endSelectRange:function(){c({type:"endSelectRange"})},moveUp:function(){c({type:"moveUp"})},moveDown:function(){c({type:"moveDown"})},moveLeft:function(){c({type:"moveLeft"})},moveRight:function(){c({type:"moveRight"})},extendUp:function(){c({type:"extendUp"})},extendDown:function(){c({type:"extendDown"})},extendLeft:function(){c({type:"extendLeft"})},extendRight:function(){c({type:"extendRight"})},reset:function(){c({type:"reset"})}}}),[]);return o((function(){var e=function(e){var t=document.getElementById(i.getTableId()),n=e.target;n instanceof Node&&(null==t?void 0:t.contains(n))||c({type:"reset"})};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[]),{state:n((function(){if(!a.isSelecting)return a;var t=document.getElementById(i.getTableCellId(a.start.rowIndex,a.start.colIndex)),n=document.getElementById(i.getTableCellId(a.end.rowIndex,a.end.colIndex)),o=document.getElementById(i.getTableId());if(!t||!n||!o)return c({type:"reset"}),{isSelecting:!1};var r=t.getBoundingClientRect(),d=n.getBoundingClientRect(),s=o.getBoundingClientRect(),l=s.top-o.scrollTop-window.scrollY,x=s.left-o.scrollLeft-window.scrollX,g={top:r.top-l,left:r.left-x,width:r.width,height:r.height},u={top:d.top-l,left:d.left-x,width:d.width,height:d.height};return{isSelecting:!0,start:e(e({},a.start),{xStart:g.left,xEnd:g.left+g.width,yStart:g.top,yEnd:g.top+g.height}),end:e(e({},a.end),{xStart:u.left,xEnd:u.left+u.width,yStart:u.top,yEnd:u.top+u.height}),rangeBox:{top:Math.min(g.top,u.top),left:Math.min(g.left,u.left),width:Math.abs(g.left-u.left)+(g.left<=u.left?u.width:g.width),height:Math.abs(g.top-u.top)+(g.top<=u.top?u.height:g.height)}}}),[a]),actions:s}}export{l as rangeReducer,x as useRangeReducer};
|
|
1
|
+
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as t,useMemo as n,useEffect as o}from"react";import{IdGenerator as i}from"../libs/id-generator.js";function r(e){return{maxColIndex:e.maxColIndex<-1?-1:e.maxColIndex,maxRowIndex:e.maxRowIndex<-1?-1:e.maxRowIndex}}function d(e){var t=e.rowIndex,n=e.colIndex;return t<0?t=0:e.constraint.maxRowIndex<t&&(t=e.constraint.maxRowIndex),n<0?n=0:e.constraint.maxColIndex<n&&(n=e.constraint.maxColIndex),{rowIndex:t,colIndex:n}}function a(e,t){return e.rowIndex===t.rowIndex&&e.colIndex===t.colIndex}var c={UP:{deltaRow:-1,deltaCol:0},DOWN:{deltaRow:1,deltaCol:0},LEFT:{deltaRow:0,deltaCol:-1},RIGHT:{deltaRow:0,deltaCol:1}};function s(e){var t=e.index,n=e.direction,o=e.constraint,i=c[n],r=i.deltaRow,a=i.deltaCol;return d({rowIndex:t.rowIndex+r,colIndex:t.colIndex+a,constraint:o})}var l=function(t,n){switch(n.type){case"setMax":return e(e({},t),{constraint:r(n.payload)});case"startSelectRange":var o=d({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return t.isSelecting&&a(t.start,o)&&a(t.end,o)&&t.inProgress?t:e(e({},t),{isSelecting:!0,inProgress:!0,start:o,end:o});case"moveSelectRange":if(!t.isSelecting||!t.inProgress)return t;var i=d({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return a(t.end,i)?t:e(e({},t),{end:i});case"endSelectRange":return t.isSelecting&&t.inProgress?e(e({},t),{inProgress:!1}):t;case"moveUp":return t.isSelecting?a(o=s({index:t.start,direction:"UP",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"moveDown":return t.isSelecting?a(o=s({index:t.start,direction:"DOWN",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"moveLeft":return t.isSelecting?a(o=s({index:t.start,direction:"LEFT",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"moveRight":return t.isSelecting?a(o=s({index:t.start,direction:"RIGHT",constraint:t.constraint}),t.start)&&a(o,t.end)?t:e(e({},t),{start:o,end:o}):t;case"extendUp":return t.isSelecting?a(i=s({index:t.end,direction:"UP",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"extendDown":return t.isSelecting?a(i=s({index:t.end,direction:"DOWN",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"extendLeft":return t.isSelecting?a(i=s({index:t.end,direction:"LEFT",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"extendRight":return t.isSelecting?a(i=s({index:t.end,direction:"RIGHT",constraint:t.constraint}),t.end)?t:e(e({},t),{end:i}):t;case"reset":return{constraint:t.constraint,isSelecting:!1};case"setRange":return e(e({},t),{isSelecting:!0,inProgress:!1,start:n.payload.start,end:n.payload.end})}};function x(){var d=t(l,{constraint:r({maxColIndex:0,maxRowIndex:0}),isSelecting:!1}),a=d[0],c=d[1],s=n((function(){return{setMax:function(e){c({type:"setMax",payload:e})},startSelectRange:function(e){c({type:"startSelectRange",payload:e})},moveSelectRange:function(e){c({type:"moveSelectRange",payload:e})},endSelectRange:function(){c({type:"endSelectRange"})},moveUp:function(){c({type:"moveUp"})},moveDown:function(){c({type:"moveDown"})},moveLeft:function(){c({type:"moveLeft"})},moveRight:function(){c({type:"moveRight"})},extendUp:function(){c({type:"extendUp"})},extendDown:function(){c({type:"extendDown"})},extendLeft:function(){c({type:"extendLeft"})},extendRight:function(){c({type:"extendRight"})},reset:function(){c({type:"reset"})},setRange:function(e){c({type:"setRange",payload:e})}}}),[]);return o((function(){var e=function(e){var t=document.getElementById(i.getTableId()),n=e.target;n instanceof Node&&(null==t?void 0:t.contains(n))||c({type:"reset"})};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[]),{state:n((function(){if(!a.isSelecting)return a;var t=document.getElementById(i.getTableCellId(a.start.rowIndex,a.start.colIndex)),n=document.getElementById(i.getTableCellId(a.end.rowIndex,a.end.colIndex)),o=document.getElementById(i.getTableId());if(!t||!n||!o)return c({type:"reset"}),{isSelecting:!1};var r=t.getBoundingClientRect(),d=n.getBoundingClientRect(),s=o.getBoundingClientRect(),l=s.top-o.scrollTop-window.scrollY,x=s.left-o.scrollLeft-window.scrollX,g={top:r.top-l,left:r.left-x,width:r.width,height:r.height},u={top:d.top-l,left:d.left-x,width:d.width,height:d.height};return{isSelecting:!0,start:e(e({},a.start),{xStart:g.left,xEnd:g.left+g.width,yStart:g.top,yEnd:g.top+g.height}),end:e(e({},a.end),{xStart:u.left,xEnd:u.left+u.width,yStart:u.top,yEnd:u.top+u.height}),rangeBox:{top:Math.min(g.top,u.top),left:Math.min(g.left,u.left),width:Math.abs(g.left-u.left)+(g.left<=u.left?u.width:g.width),height:Math.abs(g.top-u.top)+(g.top<=u.top?u.height:g.height)}}}),[a]),actions:s}}export{l as rangeReducer,x as useRangeReducer};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/range/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useReducer } from \"react\";\nimport {\n IIndex,\n TRangeReducer,\n IRangeConstraint,\n TReturnRangeReducer,\n} from \"./type\";\nimport { IdGenerator } from \"../libs\";\n\nfunction newRangeConstraint(props: {\n maxColIndex: number;\n maxRowIndex: number;\n}): IRangeConstraint {\n return {\n maxColIndex: props.maxColIndex < -1 ? -1 : props.maxColIndex,\n maxRowIndex: props.maxRowIndex < -1 ? -1 : props.maxRowIndex,\n };\n}\n\nfunction newIndex(props: {\n rowIndex: number;\n colIndex: number;\n constraint: IRangeConstraint;\n}): IIndex {\n let rowIndex = props.rowIndex;\n let colIndex = props.colIndex;\n\n if (rowIndex < 0) {\n rowIndex = 0;\n } else if (props.constraint.maxRowIndex < rowIndex) {\n rowIndex = props.constraint.maxRowIndex;\n }\n\n if (colIndex < 0) {\n colIndex = 0;\n } else if (props.constraint.maxColIndex < colIndex) {\n colIndex = props.constraint.maxColIndex;\n }\n\n return { rowIndex, colIndex };\n}\n\nfunction equalIndex(a: IIndex, b: IIndex): boolean {\n return a.rowIndex === b.rowIndex && a.colIndex === b.colIndex;\n}\n\nconst MOVE_ACTION = {\n UP: { deltaRow: -1, deltaCol: 0 },\n DOWN: { deltaRow: 1, deltaCol: 0 },\n LEFT: { deltaRow: 0, deltaCol: -1 },\n RIGHT: { deltaRow: 0, deltaCol: 1 },\n} as const;\n\ntype TMoveAction = keyof typeof MOVE_ACTION;\n\nfunction moveIndex({\n index,\n direction,\n constraint,\n}: {\n index: IIndex;\n direction: TMoveAction;\n constraint: IRangeConstraint;\n}): IIndex {\n const { deltaRow, deltaCol } = MOVE_ACTION[direction];\n\n const newRow = index.rowIndex + deltaRow;\n const newCol = index.colIndex + deltaCol;\n\n return newIndex({\n rowIndex: newRow,\n colIndex: newCol,\n constraint,\n });\n}\n\nexport const rangeReducer: TRangeReducer = (state, action) => {\n switch (action.type) {\n /**\n * Actionが\"setMax\"の場合の説明:\n * - Actionのtypeが\"setMax\"の場合、選択範囲の最大値を設定します。\n * - payloadのmaxRowIndexとmaxColIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、constraintを新しい範囲制約に設定します。\n */\n case \"setMax\":\n return {\n ...state,\n constraint: newRangeConstraint(action.payload),\n };\n\n /**\n * Actionが\"start\"の場合の説明:\n * - Actionのtypeが\"start\"の場合、選択範囲の開始位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、isSelectingをtrueに設定し、startとendの位置をpayloadの位置に設定します。\n */\n case \"startSelectRange\": {\n const startIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (\n state.isSelecting &&\n equalIndex(state.start, startIndex) &&\n equalIndex(state.end, startIndex) &&\n state.inProgress\n ) {\n return state;\n }\n\n return {\n ...state,\n isSelecting: true,\n inProgress: true,\n start: startIndex,\n end: startIndex,\n };\n }\n\n case \"moveSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n const endIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (equalIndex(state.end, endIndex)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"end\"の場合の説明:\n * - Actionのtypeが\"end\"の場合、選択範囲の終了位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、endの位置をpayloadの位置に設定します。\n * - この場合、isSelectingはtrueのままです。\n */\n case \"endSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n return {\n ...state,\n inProgress: false,\n };\n }\n\n /**\n * Actionが\"moveUp\"の場合の説明:\n * - Actionのtypeが\"moveUp\"の場合、選択範囲を上に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に移動します。\n */\n case \"moveUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveDown\"の場合の説明:\n * - Actionのtypeが\"moveDown\"の場合、選択範囲を下に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に移動します。\n */\n case \"moveDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveLeft\"の場合の説明:\n * - Actionのtypeが\"moveLeft\"の場合、選択範囲を左に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に移動します。\n */\n case \"moveLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveRight\"の場合の説明:\n * - Actionのtypeが\"moveRight\"の場合、選択範囲を右に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に移動します。\n */\n case \"moveRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"extendUp\"の場合の説明:\n * - Actionのtypeが\"extendUp\"の場合、選択範囲を上に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に拡張します。\n */\n case \"extendUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendDown\"の場合の説明:\n * - Actionのtypeが\"extendDown\"の場合、選択範囲を下に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に拡張します。\n */\n case \"extendDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendLeft\"の場合の説明:\n * - Actionのtypeが\"extendLeft\"の場合、選択範囲を左に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に拡張します。\n */\n case \"extendLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendRight\"の場合の説明:\n * - Actionのtypeが\"extendRight\"の場合、選択範囲を右に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に拡張します。\n */\n case \"extendRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"reset\"の場合の説明:\n * - Actionのtypeが\"reset\"の場合、選択範囲をリセットします。\n * - isSelectingをfalseに設定します。\n */\n case \"reset\":\n return {\n constraint: state.constraint,\n isSelecting: false,\n };\n }\n};\n\nexport function useRangeReducer(): TReturnRangeReducer {\n const [state, dispatch] = useReducer(rangeReducer, {\n constraint: newRangeConstraint({ maxColIndex: 0, maxRowIndex: 0 }),\n isSelecting: false,\n });\n\n const actions = useMemo(\n () => ({\n setMax: (payload: { maxRowIndex: number; maxColIndex: number }) => {\n dispatch({ type: \"setMax\", payload });\n },\n startSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"startSelectRange\", payload });\n },\n moveSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"moveSelectRange\", payload });\n },\n endSelectRange: () => {\n dispatch({ type: \"endSelectRange\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n extendUp: () => {\n dispatch({ type: \"extendUp\" });\n },\n extendDown: () => {\n dispatch({ type: \"extendDown\" });\n },\n extendLeft: () => {\n dispatch({ type: \"extendLeft\" });\n },\n extendRight: () => {\n dispatch({ type: \"extendRight\" });\n },\n reset: () => {\n dispatch({ type: \"reset\" });\n },\n }),\n []\n );\n\n useEffect(() => {\n const onClickOutOfTable = (e: MouseEvent) => {\n const element = document.getElementById(IdGenerator.getTableId());\n const ele = e.target;\n if (ele instanceof Node && element?.contains(ele)) return;\n dispatch({ type: \"reset\" });\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfTable);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfTable);\n };\n }, []);\n\n const exState = useMemo<TReturnRangeReducer[\"state\"]>(() => {\n if (!state.isSelecting) {\n return state;\n }\n\n const startElement = document.getElementById(\n IdGenerator.getTableCellId(state.start.rowIndex, state.start.colIndex)\n );\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!startElement || !endElement || !tableElement) {\n dispatch({ type: \"reset\" });\n return { isSelecting: false };\n }\n\n const startRect = startElement.getBoundingClientRect();\n const endRect = endElement.getBoundingClientRect();\n const rectTable = tableElement.getBoundingClientRect();\n\n const adjustSize = {\n y: rectTable.top - tableElement.scrollTop - window.scrollY,\n x: rectTable.left - tableElement.scrollLeft - window.scrollX,\n };\n\n const startDivProps = {\n top: startRect.top - adjustSize.y,\n left: startRect.left - adjustSize.x,\n width: startRect.width,\n height: startRect.height,\n };\n\n const endDivProps = {\n top: endRect.top - adjustSize.y,\n left: endRect.left - adjustSize.x,\n width: endRect.width,\n height: endRect.height,\n };\n\n return {\n isSelecting: true,\n start: {\n ...state.start,\n xStart: startDivProps.left,\n xEnd: startDivProps.left + startDivProps.width,\n yStart: startDivProps.top,\n yEnd: startDivProps.top + startDivProps.height,\n },\n end: {\n ...state.end,\n xStart: endDivProps.left,\n xEnd: endDivProps.left + endDivProps.width,\n yStart: endDivProps.top,\n yEnd: endDivProps.top + endDivProps.height,\n },\n rangeBox: {\n top: Math.min(startDivProps.top, endDivProps.top),\n left: Math.min(startDivProps.left, endDivProps.left),\n width:\n Math.abs(startDivProps.left - endDivProps.left) +\n (startDivProps.left <= endDivProps.left\n ? endDivProps.width\n : startDivProps.width),\n height:\n Math.abs(startDivProps.top - endDivProps.top) +\n (startDivProps.top <= endDivProps.top\n ? endDivProps.height\n : startDivProps.height),\n },\n };\n }, [state]);\n\n return {\n state: exState,\n actions,\n };\n}\n"],"names":["newRangeConstraint","props","maxColIndex","maxRowIndex","newIndex","rowIndex","colIndex","constraint","equalIndex","a","b","MOVE_ACTION","UP","deltaRow","deltaCol","DOWN","LEFT","RIGHT","moveIndex","_a","index","direction","_b","rangeReducer","state","action","type","__assign","payload","startIndex","isSelecting","start","end","inProgress","endIndex","useRangeReducer","useReducer","dispatch","actions","useMemo","setMax","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","useEffect","onClickOutOfTable","e","element","document","getElementById","IdGenerator","getTableId","ele","target","Node","contains","addEventListener","removeEventListener","startElement","getTableCellId","endElement","tableElement","startRect","getBoundingClientRect","endRect","rectTable","adjustSize","top","scrollTop","window","scrollY","left","scrollLeft","scrollX","startDivProps","width","height","endDivProps","xStart","xEnd","yStart","yEnd","rangeBox","Math","min","abs"],"mappings":"yLASA,SAASA,EAAmBC,GAI1B,MAAO,CACLC,YAAaD,EAAMC,aAAe,GAAK,EAAID,EAAMC,YACjDC,YAAaF,EAAME,aAAe,GAAK,EAAIF,EAAME,YAErD,CAEA,SAASC,EAASH,GAKhB,IAAII,EAAWJ,EAAMI,SACjBC,EAAWL,EAAMK,SAcrB,OAZID,EAAW,EACbA,EAAW,EACFJ,EAAMM,WAAWJ,YAAcE,IACxCA,EAAWJ,EAAMM,WAAWJ,aAG1BG,EAAW,EACbA,EAAW,EACFL,EAAMM,WAAWL,YAAcI,IACxCA,EAAWL,EAAMM,WAAWL,aAGvB,CAAEG,SAAQA,EAAEC,SAAQA,EAC7B,CAEA,SAASE,EAAWC,EAAWC,GAC7B,OAAOD,EAAEJ,WAAaK,EAAEL,UAAYI,EAAEH,WAAaI,EAAEJ,QACvD,CAEA,IAAMK,EAAc,CAClB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AAQO,KAAOL,EACrBS,MAAOX,EAAQW,MACfC,OAAQZ,EAAQY,QAGlB,MAAO,CACLvD,aAAa,EACbC,aACKP,EAAMO,OAAK,CACdwD,OAAQJ,EAAcH,KACtBQ,KAAML,EAAcH,KAAOG,EAAcC,MACzCK,OAAQN,EAAcP,IACtBc,KAAMP,EAAcP,IAAMO,EAAcE,SAE1CrD,WACKR,EAAMQ,KAAG,CACZuD,OAAQD,EAAYN,KACpBQ,KAAMF,EAAYN,KAAOM,EAAYF,MACrCK,OAAQH,EAAYV,IACpBc,KAAMJ,EAAYV,IAAMU,EAAYD,SAEtCM,SAAU,CACRf,IAAKgB,KAAKC,IAAIV,EAAcP,IAAKU,EAAYV,KAC7CI,KAAMY,KAAKC,IAAIV,EAAcH,KAAMM,EAAYN,MAC/CI,MACEQ,KAAKE,IAAIX,EAAcH,KAAOM,EAAYN,OACzCG,EAAcH,MAAQM,EAAYN,KAC/BM,EAAYF,MACZD,EAAcC,OACpBC,OACEO,KAAKE,IAAIX,EAAcP,IAAMU,EAAYV,MACxCO,EAAcP,KAAOU,EAAYV,IAC9BU,EAAYD,OACZF,EAAcE,SAG1B,GAAG,CAAC7D,IAIFc,QAAOA,EAEX"}
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/range/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useReducer } from \"react\";\nimport {\n IIndex,\n TRangeReducer,\n IRangeConstraint,\n TReturnRangeReducer,\n} from \"./type\";\nimport { IdGenerator } from \"../libs\";\n\nfunction newRangeConstraint(props: {\n maxColIndex: number;\n maxRowIndex: number;\n}): IRangeConstraint {\n return {\n maxColIndex: props.maxColIndex < -1 ? -1 : props.maxColIndex,\n maxRowIndex: props.maxRowIndex < -1 ? -1 : props.maxRowIndex,\n };\n}\n\nfunction newIndex(props: {\n rowIndex: number;\n colIndex: number;\n constraint: IRangeConstraint;\n}): IIndex {\n let rowIndex = props.rowIndex;\n let colIndex = props.colIndex;\n\n if (rowIndex < 0) {\n rowIndex = 0;\n } else if (props.constraint.maxRowIndex < rowIndex) {\n rowIndex = props.constraint.maxRowIndex;\n }\n\n if (colIndex < 0) {\n colIndex = 0;\n } else if (props.constraint.maxColIndex < colIndex) {\n colIndex = props.constraint.maxColIndex;\n }\n\n return { rowIndex, colIndex };\n}\n\nfunction equalIndex(a: IIndex, b: IIndex): boolean {\n return a.rowIndex === b.rowIndex && a.colIndex === b.colIndex;\n}\n\nconst MOVE_ACTION = {\n UP: { deltaRow: -1, deltaCol: 0 },\n DOWN: { deltaRow: 1, deltaCol: 0 },\n LEFT: { deltaRow: 0, deltaCol: -1 },\n RIGHT: { deltaRow: 0, deltaCol: 1 },\n} as const;\n\ntype TMoveAction = keyof typeof MOVE_ACTION;\n\nfunction moveIndex({\n index,\n direction,\n constraint,\n}: {\n index: IIndex;\n direction: TMoveAction;\n constraint: IRangeConstraint;\n}): IIndex {\n const { deltaRow, deltaCol } = MOVE_ACTION[direction];\n\n const newRow = index.rowIndex + deltaRow;\n const newCol = index.colIndex + deltaCol;\n\n return newIndex({\n rowIndex: newRow,\n colIndex: newCol,\n constraint,\n });\n}\n\nexport const rangeReducer: TRangeReducer = (state, action) => {\n switch (action.type) {\n /**\n * Actionが\"setMax\"の場合の説明:\n * - Actionのtypeが\"setMax\"の場合、選択範囲の最大値を設定します。\n * - payloadのmaxRowIndexとmaxColIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、constraintを新しい範囲制約に設定します。\n */\n case \"setMax\":\n return {\n ...state,\n constraint: newRangeConstraint(action.payload),\n };\n\n /**\n * Actionが\"start\"の場合の説明:\n * - Actionのtypeが\"start\"の場合、選択範囲の開始位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、isSelectingをtrueに設定し、startとendの位置をpayloadの位置に設定します。\n */\n case \"startSelectRange\": {\n const startIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (\n state.isSelecting &&\n equalIndex(state.start, startIndex) &&\n equalIndex(state.end, startIndex) &&\n state.inProgress\n ) {\n return state;\n }\n\n return {\n ...state,\n isSelecting: true,\n inProgress: true,\n start: startIndex,\n end: startIndex,\n };\n }\n\n case \"moveSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n const endIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (equalIndex(state.end, endIndex)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"end\"の場合の説明:\n * - Actionのtypeが\"end\"の場合、選択範囲の終了位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、endの位置をpayloadの位置に設定します。\n * - この場合、isSelectingはtrueのままです。\n */\n case \"endSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n return {\n ...state,\n inProgress: false,\n };\n }\n\n /**\n * Actionが\"moveUp\"の場合の説明:\n * - Actionのtypeが\"moveUp\"の場合、選択範囲を上に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に移動します。\n */\n case \"moveUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveDown\"の場合の説明:\n * - Actionのtypeが\"moveDown\"の場合、選択範囲を下に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に移動します。\n */\n case \"moveDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveLeft\"の場合の説明:\n * - Actionのtypeが\"moveLeft\"の場合、選択範囲を左に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に移動します。\n */\n case \"moveLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveRight\"の場合の説明:\n * - Actionのtypeが\"moveRight\"の場合、選択範囲を右に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に移動します。\n */\n case \"moveRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"extendUp\"の場合の説明:\n * - Actionのtypeが\"extendUp\"の場合、選択範囲を上に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に拡張します。\n */\n case \"extendUp\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendDown\"の場合の説明:\n * - Actionのtypeが\"extendDown\"の場合、選択範囲を下に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に拡張します。\n */\n case \"extendDown\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendLeft\"の場合の説明:\n * - Actionのtypeが\"extendLeft\"の場合、選択範囲を左に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に拡張します。\n */\n case \"extendLeft\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendRight\"の場合の説明:\n * - Actionのtypeが\"extendRight\"の場合、選択範囲を右に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に拡張します。\n */\n case \"extendRight\": {\n if (!state.isSelecting) {\n return state;\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"reset\"の場合の説明:\n * - Actionのtypeが\"reset\"の場合、選択範囲をリセットします。\n * - isSelectingをfalseに設定します。\n */\n case \"reset\":\n return {\n constraint: state.constraint,\n isSelecting: false,\n };\n\n /**\n * Actionが\"setRange\"の場合の説明:\n * - Actionのtypeが\"setRange\"の場合、選択範囲を設定します。\n * - payloadのstartとendの位置を設定します。\n */\n case \"setRange\":\n return {\n ...state,\n isSelecting: true,\n inProgress: false,\n start: action.payload.start,\n end: action.payload.end,\n };\n }\n};\n\nexport function useRangeReducer(): TReturnRangeReducer {\n const [state, dispatch] = useReducer(rangeReducer, {\n constraint: newRangeConstraint({ maxColIndex: 0, maxRowIndex: 0 }),\n isSelecting: false,\n });\n\n const actions = useMemo(\n () => ({\n setMax: (payload: { maxRowIndex: number; maxColIndex: number }) => {\n dispatch({ type: \"setMax\", payload });\n },\n startSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"startSelectRange\", payload });\n },\n moveSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"moveSelectRange\", payload });\n },\n endSelectRange: () => {\n dispatch({ type: \"endSelectRange\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n extendUp: () => {\n dispatch({ type: \"extendUp\" });\n },\n extendDown: () => {\n dispatch({ type: \"extendDown\" });\n },\n extendLeft: () => {\n dispatch({ type: \"extendLeft\" });\n },\n extendRight: () => {\n dispatch({ type: \"extendRight\" });\n },\n reset: () => {\n dispatch({ type: \"reset\" });\n },\n setRange: (payload: { start: IIndex; end: IIndex }) => {\n dispatch({ type: \"setRange\", payload });\n },\n }),\n []\n );\n\n useEffect(() => {\n const onClickOutOfTable = (e: MouseEvent) => {\n const element = document.getElementById(IdGenerator.getTableId());\n const ele = e.target;\n if (ele instanceof Node && element?.contains(ele)) return;\n dispatch({ type: \"reset\" });\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfTable);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfTable);\n };\n }, []);\n\n const exState = useMemo<TReturnRangeReducer[\"state\"]>(() => {\n if (!state.isSelecting) {\n return state;\n }\n\n const startElement = document.getElementById(\n IdGenerator.getTableCellId(state.start.rowIndex, state.start.colIndex)\n );\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!startElement || !endElement || !tableElement) {\n dispatch({ type: \"reset\" });\n return { isSelecting: false };\n }\n\n const startRect = startElement.getBoundingClientRect();\n const endRect = endElement.getBoundingClientRect();\n const rectTable = tableElement.getBoundingClientRect();\n\n const adjustSize = {\n y: rectTable.top - tableElement.scrollTop - window.scrollY,\n x: rectTable.left - tableElement.scrollLeft - window.scrollX,\n };\n\n const startDivProps = {\n top: startRect.top - adjustSize.y,\n left: startRect.left - adjustSize.x,\n width: startRect.width,\n height: startRect.height,\n };\n\n const endDivProps = {\n top: endRect.top - adjustSize.y,\n left: endRect.left - adjustSize.x,\n width: endRect.width,\n height: endRect.height,\n };\n\n return {\n isSelecting: true,\n start: {\n ...state.start,\n xStart: startDivProps.left,\n xEnd: startDivProps.left + startDivProps.width,\n yStart: startDivProps.top,\n yEnd: startDivProps.top + startDivProps.height,\n },\n end: {\n ...state.end,\n xStart: endDivProps.left,\n xEnd: endDivProps.left + endDivProps.width,\n yStart: endDivProps.top,\n yEnd: endDivProps.top + endDivProps.height,\n },\n rangeBox: {\n top: Math.min(startDivProps.top, endDivProps.top),\n left: Math.min(startDivProps.left, endDivProps.left),\n width:\n Math.abs(startDivProps.left - endDivProps.left) +\n (startDivProps.left <= endDivProps.left\n ? endDivProps.width\n : startDivProps.width),\n height:\n Math.abs(startDivProps.top - endDivProps.top) +\n (startDivProps.top <= endDivProps.top\n ? endDivProps.height\n : startDivProps.height),\n },\n };\n }, [state]);\n\n return {\n state: exState,\n actions,\n };\n}\n"],"names":["newRangeConstraint","props","maxColIndex","maxRowIndex","newIndex","rowIndex","colIndex","constraint","equalIndex","a","b","MOVE_ACTION","UP","deltaRow","deltaCol","DOWN","LEFT","RIGHT","moveIndex","_a","index","direction","_b","rangeReducer","state","action","type","__assign","payload","startIndex","isSelecting","start","end","inProgress","endIndex","useRangeReducer","useReducer","dispatch","actions","useMemo","setMax","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","setRange","useEffect","onClickOutOfTable","e","element","document","getElementById","IdGenerator","getTableId","ele","target","Node","contains","addEventListener","removeEventListener","startElement","getTableCellId","endElement","tableElement","startRect","getBoundingClientRect","endRect","rectTable","adjustSize","top","scrollTop","window","scrollY","left","scrollLeft","scrollX","startDivProps","width","height","endDivProps","xStart","xEnd","yStart","yEnd","rangeBox","Math","min","abs"],"mappings":"yLASA,SAASA,EAAmBC,GAI1B,MAAO,CACLC,YAAaD,EAAMC,aAAe,GAAK,EAAID,EAAMC,YACjDC,YAAaF,EAAME,aAAe,GAAK,EAAIF,EAAME,YAErD,CAEA,SAASC,EAASH,GAKhB,IAAII,EAAWJ,EAAMI,SACjBC,EAAWL,EAAMK,SAcrB,OAZID,EAAW,EACbA,EAAW,EACFJ,EAAMM,WAAWJ,YAAcE,IACxCA,EAAWJ,EAAMM,WAAWJ,aAG1BG,EAAW,EACbA,EAAW,EACFL,EAAMM,WAAWL,YAAcI,IACxCA,EAAWL,EAAMM,WAAWL,aAGvB,CAAEG,SAAQA,EAAEC,SAAQA,EAC7B,CAEA,SAASE,EAAWC,EAAWC,GAC7B,OAAOD,EAAEJ,WAAaK,EAAEL,UAAYI,EAAEH,WAAaI,EAAEJ,QACvD,CAEA,IAAMK,EAAc,CAClBC,GAAI,CAAEC,UAAW,EA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GjDC,EAAgB,CACpBP,IAAKL,EAAUK,IAAMD,EACrBK,KAAMT,EAAUS,KAAOL,EACvBS,MAAOb,EAAUa,MACjBC,OAAQd,EAAUc,QAGdC,EAAc,CAClBV,IAAKH,EAAQG,IAAMD,EACnBK,KAAMP,EAAQO,KAAOL,EACrBS,MAAOX,EAAQW,MACfC,OAAQZ,EAAQY,QAGlB,MAAO,CACLxD,aAAa,EACbC,aACKP,EAAMO,OAAK,CACdyD,OAAQJ,EAAcH,KACtBQ,KAAML,EAAcH,KAAOG,EAAcC,MACzCK,OAAQN,EAAcP,IACtBc,KAAMP,EAAcP,IAAMO,EAAcE,SAE1CtD,WACKR,EAAMQ,KAAG,CACZwD,OAAQD,EAAYN,KACpBQ,KAAMF,EAAYN,KAAOM,EAAYF,MACrCK,OAAQH,EAAYV,IACpBc,KAAMJ,EAAYV,IAAMU,EAAYD,SAEtCM,SAAU,CACRf,IAAKgB,KAAKC,IAAIV,EAAcP,IAAKU,EAAYV,KAC7CI,KAAMY,KAAKC,IAAIV,EAAcH,KAAMM,EAAYN,MAC/CI,MACEQ,KAAKE,IAAIX,EAAcH,KAAOM,EAAYN,OACzCG,EAAcH,MAAQM,EAAYN,KAC/BM,EAAYF,MACZD,EAAcC,OACpBC,OACEO,KAAKE,IAAIX,EAAcP,IAAMU,EAAYV,MACxCO,EAAcP,KAAOU,EAAYV,IAC9BU,EAAYD,OACZF,EAAcE,SAG1B,GAAG,CAAC9D,IAIFc,QAAOA,EAEX"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as t,jsxs as n,Fragment as r}from"react/jsx-runtime";import{createContext as o,useContext as i,useEffect as d}from"react";import{NoImplementeFunction as
|
|
1
|
+
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as t,jsxs as n,Fragment as r}from"react/jsx-runtime";import{createContext as o,useContext as i,useEffect as d}from"react";import{NoImplementeFunction as a}from"../lib/errors.js";import{useRangeReducer as s}from"./hooks.js";import{useTablePropertyStateContext as l}from"../table-property/provider.js";import{IdGenerator as c}from"../libs/id-generator.js";var m=o({isSelecting:!1}),u=o({setMax:a,startSelectRange:a,moveSelectRange:a,endSelectRange:a,moveUp:a,moveDown:a,moveLeft:a,moveRight:a,extendUp:a,extendDown:a,extendLeft:a,extendRight:a,reset:a,setRange:a});function f(){return i(m)}function x(){return i(u)}function p(){return e(e({},f()),x())}function g(){var e=x().setMax,n=l(),o=n.maxDisplayRowCount,i=n.maxDisplayColCount;return d((function(){e({maxRowIndex:o-1,maxColIndex:i-1})}),[o,i]),t(r,{})}function v(e){var n=f();if(d((function(){if(n.isSelecting){var e=document.getElementById(c.getTableCellId(n.end.rowIndex,n.end.colIndex));e&&(e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),e.focus())}}),[n]),!n.isSelecting)return t(r,{});var o=n.rangeBox,i=n.start,a=n.end;return i.xEnd<a.xEnd?a.xEnd:i.xEnd,i.yEnd<a.yEnd?a.yEnd:i.yEnd,t(r,{children:t("div",{className:"absolute border border-gray-500 bg-gray-500 bg-opacity-10 ".concat(e.isCopied?"border-dashed":"border-solid"),style:{top:o.top,left:o.left,width:o.width,height:o.height,pointerEvents:"none"}})})}function h(e){var r=e.children,o=s(),i=o.state,d=o.actions;return t(m.Provider,{value:i,children:n(u.Provider,{value:d,children:[t(g,{}),r]})})}export{h as RangeProvider,v as TestRange,x as useRangeActionContext,p as useRangeContext,f as useRangeStateContext};
|
|
2
2
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/range/provider.tsx"],"sourcesContent":["import { createContext, useContext, useEffect } from \"react\";\nimport { TRangeActionContext, TRangeStateContext } from \"./type\";\nimport { NoImplementeFunction } from \"../lib/errors\";\nimport { useRangeReducer } from \"./hooks\";\nimport { useTablePropertyStateContext } from \"../table-property/provider\";\nimport { IdGenerator } from \"../libs\";\n\nconst RangeStateContext = createContext<TRangeStateContext>({\n isSelecting: false,\n});\n\nconst RangeActionContext = createContext<TRangeActionContext>({\n setMax: NoImplementeFunction,\n startSelectRange: NoImplementeFunction,\n moveSelectRange: NoImplementeFunction,\n endSelectRange: NoImplementeFunction,\n moveUp: NoImplementeFunction,\n moveDown: NoImplementeFunction,\n moveLeft: NoImplementeFunction,\n moveRight: NoImplementeFunction,\n extendUp: NoImplementeFunction,\n extendDown: NoImplementeFunction,\n extendLeft: NoImplementeFunction,\n extendRight: NoImplementeFunction,\n reset: NoImplementeFunction,\n});\n\nexport function useRangeStateContext() {\n return useContext(RangeStateContext);\n}\n\nexport function useRangeActionContext() {\n return useContext(RangeActionContext);\n}\n\nexport function useRangeContext() {\n return { ...useRangeStateContext(), ...useRangeActionContext() };\n}\n\nfunction EffectSetMax() {\n const { setMax } = useRangeActionContext();\n const { maxDisplayRowCount, maxDisplayColCount } =\n useTablePropertyStateContext();\n\n useEffect(() => {\n setMax({\n maxRowIndex: maxDisplayRowCount - 1,\n maxColIndex: maxDisplayColCount - 1,\n });\n }, [maxDisplayRowCount, maxDisplayColCount]);\n\n return <></>;\n}\n\nexport function TestRange(props: { isCopied?: boolean }) {\n const state = useRangeStateContext();\n\n useEffect(() => {\n if (state.isSelecting) {\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n\n if (endElement) {\n endElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n endElement.focus();\n }\n }\n }, [state]);\n\n if (!state.isSelecting) {\n return <></>;\n }\n\n const { rangeBox, start, end } = state;\n\n const clickboxPoint = {\n x: start.xEnd < end.xEnd ? end.xEnd : start.xEnd,\n y: start.yEnd < end.yEnd ? end.yEnd : start.yEnd,\n };\n\n return (\n <>\n <div\n className={`absolute border border-gray-500 ${\n props.isCopied ? \"border-dashed\" : \"border-solid\"\n }`}\n style={{\n top: rangeBox.top,\n left: rangeBox.left,\n width: rangeBox.width,\n height: rangeBox.height,\n pointerEvents: \"none\",\n }}\n ></div>\n <div\n className=\"absolute bg-gray-700\"\n style={{\n top: clickboxPoint.y - 5,\n left: clickboxPoint.x - 5,\n width: 10,\n height: 10,\n pointerEvents: \"none\",\n }}\n
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/range/provider.tsx"],"sourcesContent":["import { createContext, useContext, useEffect } from \"react\";\nimport { TRangeActionContext, TRangeStateContext } from \"./type\";\nimport { NoImplementeFunction } from \"../lib/errors\";\nimport { useRangeReducer } from \"./hooks\";\nimport { useTablePropertyStateContext } from \"../table-property/provider\";\nimport { IdGenerator } from \"../libs\";\n\nconst RangeStateContext = createContext<TRangeStateContext>({\n isSelecting: false,\n});\n\nconst RangeActionContext = createContext<TRangeActionContext>({\n setMax: NoImplementeFunction,\n startSelectRange: NoImplementeFunction,\n moveSelectRange: NoImplementeFunction,\n endSelectRange: NoImplementeFunction,\n moveUp: NoImplementeFunction,\n moveDown: NoImplementeFunction,\n moveLeft: NoImplementeFunction,\n moveRight: NoImplementeFunction,\n extendUp: NoImplementeFunction,\n extendDown: NoImplementeFunction,\n extendLeft: NoImplementeFunction,\n extendRight: NoImplementeFunction,\n reset: NoImplementeFunction,\n setRange: NoImplementeFunction,\n});\n\nexport function useRangeStateContext() {\n return useContext(RangeStateContext);\n}\n\nexport function useRangeActionContext() {\n return useContext(RangeActionContext);\n}\n\nexport function useRangeContext() {\n return { ...useRangeStateContext(), ...useRangeActionContext() };\n}\n\nfunction EffectSetMax() {\n const { setMax } = useRangeActionContext();\n const { maxDisplayRowCount, maxDisplayColCount } =\n useTablePropertyStateContext();\n\n useEffect(() => {\n setMax({\n maxRowIndex: maxDisplayRowCount - 1,\n maxColIndex: maxDisplayColCount - 1,\n });\n }, [maxDisplayRowCount, maxDisplayColCount]);\n\n return <></>;\n}\n\nexport function TestRange(props: { isCopied?: boolean }) {\n const state = useRangeStateContext();\n\n useEffect(() => {\n if (state.isSelecting) {\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n\n if (endElement) {\n endElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n endElement.focus();\n }\n }\n }, [state]);\n\n if (!state.isSelecting) {\n return <></>;\n }\n\n const { rangeBox, start, end } = state;\n\n const clickboxPoint = {\n x: start.xEnd < end.xEnd ? end.xEnd : start.xEnd,\n y: start.yEnd < end.yEnd ? end.yEnd : start.yEnd,\n };\n\n return (\n <>\n <div\n className={`absolute border border-gray-500 bg-gray-500 bg-opacity-10 ${\n props.isCopied ? \"border-dashed\" : \"border-solid\"\n }`}\n style={{\n top: rangeBox.top,\n left: rangeBox.left,\n width: rangeBox.width,\n height: rangeBox.height,\n pointerEvents: \"none\",\n }}\n ></div>\n {/* <div\n className=\"absolute bg-gray-700\"\n style={{\n top: clickboxPoint.y - 5,\n left: clickboxPoint.x - 5,\n width: 10,\n height: 10,\n pointerEvents: \"none\",\n }}\n /> */}\n </>\n );\n}\n\nexport function RangeProvider({\n children,\n}: {\n children: JSX.Element | JSX.Element[];\n}) {\n const { state, actions } = useRangeReducer();\n\n return (\n <RangeStateContext.Provider value={state}>\n <RangeActionContext.Provider value={actions}>\n <EffectSetMax />\n {children}\n </RangeActionContext.Provider>\n </RangeStateContext.Provider>\n );\n}\n"],"names":["RangeStateContext","createContext","isSelecting","RangeActionContext","setMax","NoImplementeFunction","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","setRange","useRangeStateContext","useContext","useRangeActionContext","useRangeContext","__assign","EffectSetMax","_a","useTablePropertyStateContext","maxDisplayRowCount","maxDisplayColCount","useEffect","maxRowIndex","maxColIndex","_jsx","TestRange","props","state","endElement","document","getElementById","IdGenerator","getTableCellId","end","rowIndex","colIndex","scrollIntoView","behavior","block","inline","focus","rangeBox","start","xEnd","yEnd","className","concat","isCopied","style","top","left","width","height","pointerEvents","RangeProvider","children","_b","useRangeReducer","actions","Provider","value","_jsxs"],"mappings":"ibAOA,IAAMA,EAAoBC,EAAkC,CAC1DC,aAAa,IAGTC,EAAqBF,EAAmC,CAC5DG,OAAQC,EACRC,iBAAkBD,EAClBE,gBAAiBF,EACjBG,eAAgBH,EAChBI,OAAQJ,EACRK,SAAUL,EACVM,SAAUN,EACVO,UAAWP,EACXQ,SAAUR,EACVS,WAAYT,EACZU,WAAYV,EACZW,YAAaX,EACbY,MAAOZ,EACPa,SAAUb,aAGIc,IACd,OAAOC,EAAWpB,EACpB,UAEgBqB,IACd,OAAOD,EAAWjB,EACpB,UAEgBmB,IACd,OAAAC,EAAAA,EAAA,CAAA,EAAYJ,KAA2BE,IACzC,CAEA,SAASG,IACC,IAAApB,EAAWiB,WACbI,EACJC,IADMC,EAAkBF,EAAAE,mBAAEC,EAAkBH,EAAAG,mBAU9C,OAPAC,GAAU,WACRzB,EAAO,CACL0B,YAAaH,EAAqB,EAClCI,YAAaH,EAAqB,GAEtC,GAAG,CAACD,EAAoBC,IAEjBI,OACT,CAEM,SAAUC,EAAUC,GACxB,IAAMC,EAAQhB,IAmBd,GAjBAU,GAAU,WACR,GAAIM,EAAMjC,YAAa,CACrB,IAAMkC,EAAaC,SAASC,eAC1BC,EAAYC,eAAeL,EAAMM,IAAIC,SAAUP,EAAMM,IAAIE,WAGvDP,IACFA,EAAWQ,eAAe,CACxBC,SAAU,SACVC,MAAO,UACPC,OAAQ,YAEVX,EAAWY,QAEd,CACH,GAAG,CAACb,KAECA,EAAMjC,YACT,OAAO8B,QAGD,IAAAiB,EAAyBd,EAAKc,SAApBC,EAAef,EAAKe,MAAbT,EAAQN,MAOjC,OAJKe,EAAMC,KAAOV,EAAIU,KAAOV,EAAIU,KAAOD,EAAMC,KACzCD,EAAME,KAAOX,EAAIW,KAAOX,EAAIW,KAAOF,EAAME,KAI5CpB,cACEA,EACE,MAAA,CAAAqB,UAAW,6DACTC,OAAApB,EAAMqB,SAAW,gBAAkB,gBAErCC,MAAO,CACLC,IAAKR,EAASQ,IACdC,KAAMT,EAASS,KACfC,MAAOV,EAASU,MAChBC,OAAQX,EAASW,OACjBC,cAAe,WAezB,CAEM,SAAUC,EAAcrC,GAC5B,IAAAsC,EAAQtC,EAAAsC,SAIFC,EAAqBC,IAAnB9B,EAAK6B,EAAA7B,MAAE+B,EAAOF,EAAAE,QAEtB,OACElC,EAAChC,EAAkBmE,SAAS,CAAAC,MAAOjC,EACjC4B,SAAAM,EAAClE,EAAmBgE,SAAQ,CAACC,MAAOF,EAAOH,SAAA,CACzC/B,EAACR,EAAe,CAAA,GACfuC,MAIT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as r,jsx as
|
|
1
|
+
import{jsxs as r,jsx as o}from"react/jsx-runtime";import{memo as t}from"react";import{Checkbox as e}from"../checkbox/components.js";import{TableCell as i}from"../cell/ui/cell.js";import{IdGenerator as a}from"../libs/id-generator.js";import{useRangeActionContext as n}from"../range/provider.js";var l=t((function(t){var l=n().reset,c=JSON.parse(t.dataString),s=t.conditionalFormattingString.split(",");return r("tr",{className:"relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ".concat(t.onClickRow?"hover:cursor-pointer":""," ").concat(t.applyRowFormatting?t.applyRowFormatting(c):""),onClick:function(r){r.preventDefault(),t.onClickRow&&(t.onClickRow(c),l())},"data-testid":c.id,children:[t.existCheckbox&&o("td",{onClick:function(r){r.stopPropagation()},children:o(e,{row:c})}),t.cols.map((function(r,e){var n;return o(i,{id:a.getTableCellId(t.rowIndex,e),row:c,isExistOnClickRow:!!t.onClickRow,cellFormatClassName:s[e],editable:null!==(n=r.editable)&&void 0!==n&&n},r.key)}))]})}));export{l as Row};
|
|
2
2
|
//# sourceMappingURL=components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../../../../src/table/sheet/components.tsx"],"sourcesContent":["import { memo } from \"react\";\nimport { DataRecord, TTableColumn } from \"../table/type\";\nimport { Checkbox } from \"../checkbox/components\";\nimport { TableCell } from \"../cell/ui/cell\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\ninterface TPropsRow<T extends DataRecord> {\n dataString: string;\n cols: TTableColumn<T>[];\n existCheckbox?: boolean;\n rowIndex: number;\n conditionalFormattingString: string;\n onClickRow?: (row: any) => void;\n applyRowFormatting?: (row: any) => string;\n}\n\nexport const Row = memo(function R<T extends DataRecord>(props: TPropsRow<T>) {\n const { reset } = useRangeActionContext();\n const row = JSON.parse(props.dataString);\n const conditionalFormatting = props.conditionalFormattingString.split(\",\");\n\n return (\n <tr\n className={`relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ${\n !!props.onClickRow ? \"hover:cursor-pointer\" : \"\"\n } ${props.applyRowFormatting ? props.applyRowFormatting(row) : \"\"}`}\n onClick={(e) => {\n e.preventDefault();\n\n if (!!props.onClickRow) {\n props.onClickRow(row);\n reset();\n }\n }}\n data-testid={row.id}\n >\n {props.existCheckbox && (\n <td>\n <Checkbox row={row} />\n </td>\n )}\n {props.cols.map((col, j) => {\n return (\n <TableCell\n key={col.key as string}\n id={IdGenerator.getTableCellId(props.rowIndex, j)}\n row={row}\n isExistOnClickRow={!!props.onClickRow}\n cellFormatClassName={conditionalFormatting[j]}\n editable={col.editable ?? false}\n />\n );\n })}\n </tr>\n );\n});\n"],"names":["Row","memo","props","reset","useRangeActionContext","row","JSON","parse","dataString","conditionalFormatting","conditionalFormattingString","split","_jsxs","className","concat","onClickRow","applyRowFormatting","onClick","e","preventDefault","id","
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../../../src/table/sheet/components.tsx"],"sourcesContent":["import { memo } from \"react\";\nimport { DataRecord, TTableColumn } from \"../table/type\";\nimport { Checkbox } from \"../checkbox/components\";\nimport { TableCell } from \"../cell/ui/cell\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\ninterface TPropsRow<T extends DataRecord> {\n dataString: string;\n cols: TTableColumn<T>[];\n existCheckbox?: boolean;\n rowIndex: number;\n conditionalFormattingString: string;\n onClickRow?: (row: any) => void;\n applyRowFormatting?: (row: any) => string;\n}\n\nexport const Row = memo(function R<T extends DataRecord>(props: TPropsRow<T>) {\n const { reset } = useRangeActionContext();\n const row = JSON.parse(props.dataString);\n const conditionalFormatting = props.conditionalFormattingString.split(\",\");\n\n return (\n <tr\n className={`relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ${\n !!props.onClickRow ? \"hover:cursor-pointer\" : \"\"\n } ${props.applyRowFormatting ? props.applyRowFormatting(row) : \"\"}`}\n onClick={(e) => {\n e.preventDefault();\n\n if (!!props.onClickRow) {\n props.onClickRow(row);\n reset();\n }\n }}\n data-testid={row.id}\n >\n {props.existCheckbox && (\n <td\n onClick={(e) => {\n e.stopPropagation();\n }}\n >\n <Checkbox row={row} />\n </td>\n )}\n {props.cols.map((col, j) => {\n return (\n <TableCell\n key={col.key as string}\n id={IdGenerator.getTableCellId(props.rowIndex, j)}\n row={row}\n isExistOnClickRow={!!props.onClickRow}\n cellFormatClassName={conditionalFormatting[j]}\n editable={col.editable ?? false}\n />\n );\n })}\n </tr>\n );\n});\n"],"names":["Row","memo","props","reset","useRangeActionContext","row","JSON","parse","dataString","conditionalFormatting","conditionalFormattingString","split","_jsxs","className","concat","onClickRow","applyRowFormatting","onClick","e","preventDefault","id","existCheckbox","_jsx","stopPropagation","children","Checkbox","cols","map","col","j","TableCell","IdGenerator","getTableCellId","rowIndex","isExistOnClickRow","cellFormatClassName","editable","_a","key"],"mappings":"0SAiBaA,EAAMC,GAAK,SAAiCC,GAC/C,IAAAC,EAAUC,UACZC,EAAMC,KAAKC,MAAML,EAAMM,YACvBC,EAAwBP,EAAMQ,4BAA4BC,MAAM,KAEtE,OACEC,EACE,KAAA,CAAAC,UAAW,0JACTC,OAAEZ,EAAMa,WAAa,uBAAyB,GAC5C,KAAAD,OAAAZ,EAAMc,mBAAqBd,EAAMc,mBAAmBX,GAAO,IAC/DY,QAAS,SAACC,GACRA,EAAEC,iBAEIjB,EAAMa,aACVb,EAAMa,WAAWV,GACjBF,IAEH,EACY,cAAAE,EAAIe,aAEhBlB,EAAMmB,eACLC,EAAA,KAAA,CACEL,QAAS,SAACC,GACRA,EAAEK,iBACH,EAAAC,SAEDF,EAACG,EAAQ,CAACpB,IAAKA,MAGlBH,EAAMwB,KAAKC,KAAI,SAACC,EAAKC,SACpB,OACEP,EAACQ,EAAS,CAERV,GAAIW,EAAYC,eAAe9B,EAAM+B,SAAUJ,GAC/CxB,IAAKA,EACL6B,oBAAqBhC,EAAMa,WAC3BoB,oBAAqB1B,EAAsBoB,GAC3CO,SAAsB,UAAZR,EAAIQ,gBAAQ,IAAAC,GAAAA,GALjBT,EAAIU,UAWrB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{__assign as o}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useTable as
|
|
2
|
+
import{__assign as o}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useTable as t}from"./hook.js";import{TableHeaderElement as i}from"../header/header.js";import{PagenationProvider as n}from"../pagenation/providers.js";import{DisplayRange as l,Pagenation as s}from"../pagenation/components.js";import{FilterProvider as d}from"../filter/provider.js";import{TableFilterRemoveButton as a,TableFilterForm as c}from"../filter/components.js";import"../sort/icon.js";import{SortProvider as m}from"../sort/provider.js";import{ColumnsProvider as p}from"../sheet/providers.js";import{CheckboxProvider as h,CheckboxStatusProvider as f}from"../checkbox/provider.js";import{AllCheckbox as g}from"../checkbox/components.js";import{IdGenerator as u}from"../libs/id-generator.js";import{EditProvider as v}from"../edit/provider.js";import{TablePropertyProvider as b}from"../table-property/provider.js";import{KeyboardSetting as w}from"../operation/components/keyboard-setting.js";import{Row as j}from"../sheet/components.js";import{PasteProvider as x}from"../paste/provider.js";import{generateFormattingString as y}from"../libs/conditional-formatting.js";import{Editor as k}from"../edit/ui/editor.js";import{useFilteringColumnStateContext as C}from"../filter/hooks/selectedFilteringColumn/provider.js";import{RangeProvider as N,useRangeActionContext as R,TestRange as F}from"../range/provider.js";import{CopyProvider as I}from"../copy/provider.js";import{CopiedMessage as P}from"../copy/components.js";function S(t){var i,l,s;return r(d,{children:r(m,{initialCondition:null===(i=t.initialCondition)||void 0===i?void 0:i.sort,children:r(n,{rowCount:t.rows.length,perPage:null===(s=null===(l=t.initialCondition)||void 0===l?void 0:l.pagenation)||void 0===s?void 0:s.rowCountPerPage,children:r(h,{checkbox:t.checkbox,children:r(f,{checkboxCount:t.rows.length,children:r(p,{cols:t.cols,errorHandler:t.errorHandler,children:r(v,{children:r(b,{children:r(N,{children:e(I,{rows:t.rows,cols:t.cols,children:[r(P,{}),e(x,{rows:t.rows,cols:t.cols,onUpdateRowFunction:t.onUpdateRow,children:[r(w,{}),r(T,o({},t))]})]})})})})})})})})})})}function T(o){var n=t(o),d=n.cols,m=n.rowMaps,p=n.pageRowIds,h=C(),f=R().reset;return e("div",{className:"w-full",children:[r("div",{className:"flex justify-end mb-1 mr-3",children:r(a,{children:r("p",{className:"text-xs underline text-gray-500 hover:text-gray-700",children:"全てのフィルタリング条件を解除する"})})}),e("div",{id:u.getTableId(),className:"relative h-full max-w-full max-h-[80vh] border border-gray-200 rounded-md overflow-auto",children:[r(F,{}),r(k,{rowMaps:m,pageRowIds:p}),e("table",{className:"table",children:[r("thead",{children:e("tr",{className:"sticky top-0 border-gray-200 z-20 bg-gray-200 text-gray-600 h-[32px]",onClick:function(o){o.stopPropagation(),f()},children:[o.checkbox&&r("th",{children:r(g,{rows:o.rows})}),d.map((function(o,e){return r(i,{id:u.getTableColId(e),col:o},o.key.toString())}))]})}),e("tbody",{children:[!!h&&r("tr",{onClick:function(o){o.stopPropagation(),f()},children:r("td",{colSpan:d.length,className:"sticky top-8 left-0 bg-gray-300 w-full shadow-lg rounded-b-2xl z-20 p-0 overflow-hidden",children:r(c,{})})}),0===p.length&&r("tr",{children:r("td",{colSpan:d.length,className:"py-5",children:r("p",{className:"text-center font-bold text-lg",children:"NO DATA"})})}),p.map((function(e,t){return r(j,{existCheckbox:!!o.checkbox,rowIndex:t,dataString:m[e].stringValue,cols:o.cols,onClickRow:o.onClickRow,applyRowFormatting:o.applyRowFormatting,conditionalFormattingString:y(m[e].data,d,o.conditionalFormattings)},e)}))]})]})]}),e("div",{className:"mt-1",children:[r(l,{}),r("div",{className:"mt-2",children:r(s,{})})]})]})}export{S as default};
|
|
3
3
|
//# sourceMappingURL=base.js.map
|