@teppen/react-ui 1.7.1 → 1.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (71) hide show
  1. package/dist/cjs/node_modules/react-icons/md/index.js +1 -1
  2. package/dist/cjs/node_modules/react-icons/md/index.js.map +1 -1
  3. package/dist/cjs/src/select-box/id/provider.js +2 -0
  4. package/dist/cjs/src/select-box/id/provider.js.map +1 -0
  5. package/dist/cjs/src/select-box/index.js +2 -0
  6. package/dist/cjs/src/select-box/index.js.map +1 -0
  7. package/dist/cjs/src/select-box/lib/id-generator.js +2 -0
  8. package/dist/cjs/src/select-box/lib/id-generator.js.map +1 -0
  9. package/dist/cjs/src/select-box/parts/frame.js +2 -0
  10. package/dist/cjs/src/select-box/parts/frame.js.map +1 -0
  11. package/dist/cjs/src/select-box/parts/input-area.js +3 -0
  12. package/dist/cjs/src/select-box/parts/input-area.js.map +1 -0
  13. package/dist/cjs/src/select-box/parts/options-area.js +2 -0
  14. package/dist/cjs/src/select-box/parts/options-area.js.map +1 -0
  15. package/dist/cjs/src/table/cell/hooks.js +1 -1
  16. package/dist/cjs/src/table/cell/hooks.js.map +1 -1
  17. package/dist/cjs/src/table/cell/ui/cell.js +1 -1
  18. package/dist/cjs/src/table/copy/components.js +2 -0
  19. package/dist/cjs/src/table/copy/components.js.map +1 -0
  20. package/dist/cjs/src/table/copy/hooks.js +1 -1
  21. package/dist/cjs/src/table/copy/hooks.js.map +1 -1
  22. package/dist/cjs/src/table/copy/provider.js +1 -1
  23. package/dist/cjs/src/table/copy/provider.js.map +1 -1
  24. package/dist/cjs/src/table/edit/ui/select-input.js +1 -1
  25. package/dist/cjs/src/table/paste/hooks.js +1 -1
  26. package/dist/cjs/src/table/paste/hooks.js.map +1 -1
  27. package/dist/cjs/src/table/paste/logic.js +2 -0
  28. package/dist/cjs/src/table/paste/logic.js.map +1 -0
  29. package/dist/cjs/src/table/range/hooks.js +1 -1
  30. package/dist/cjs/src/table/range/hooks.js.map +1 -1
  31. package/dist/cjs/src/table/range/provider.js +1 -1
  32. package/dist/cjs/src/table/range/provider.js.map +1 -1
  33. package/dist/cjs/src/table/sheet/components.js +1 -1
  34. package/dist/cjs/src/table/sheet/components.js.map +1 -1
  35. package/dist/cjs/src/table/table/base.js +1 -1
  36. package/dist/esm/node_modules/react-icons/md/index.js +1 -1
  37. package/dist/esm/node_modules/react-icons/md/index.js.map +1 -1
  38. package/dist/esm/src/select-box/id/provider.js +2 -0
  39. package/dist/esm/src/select-box/id/provider.js.map +1 -0
  40. package/dist/esm/src/select-box/index.js +2 -0
  41. package/dist/esm/src/select-box/index.js.map +1 -0
  42. package/dist/esm/src/select-box/lib/id-generator.js +2 -0
  43. package/dist/esm/src/select-box/lib/id-generator.js.map +1 -0
  44. package/dist/esm/src/select-box/parts/frame.js +2 -0
  45. package/dist/esm/src/select-box/parts/frame.js.map +1 -0
  46. package/dist/esm/src/select-box/parts/input-area.js +3 -0
  47. package/dist/esm/src/select-box/parts/input-area.js.map +1 -0
  48. package/dist/esm/src/select-box/parts/options-area.js +2 -0
  49. package/dist/esm/src/select-box/parts/options-area.js.map +1 -0
  50. package/dist/esm/src/table/cell/hooks.js +1 -1
  51. package/dist/esm/src/table/cell/hooks.js.map +1 -1
  52. package/dist/esm/src/table/cell/ui/cell.js +1 -1
  53. package/dist/esm/src/table/copy/components.js +2 -0
  54. package/dist/esm/src/table/copy/components.js.map +1 -0
  55. package/dist/esm/src/table/copy/hooks.js +1 -1
  56. package/dist/esm/src/table/copy/hooks.js.map +1 -1
  57. package/dist/esm/src/table/copy/provider.js +1 -1
  58. package/dist/esm/src/table/copy/provider.js.map +1 -1
  59. package/dist/esm/src/table/edit/ui/select-input.js +1 -1
  60. package/dist/esm/src/table/paste/hooks.js +1 -1
  61. package/dist/esm/src/table/paste/hooks.js.map +1 -1
  62. package/dist/esm/src/table/paste/logic.js +2 -0
  63. package/dist/esm/src/table/paste/logic.js.map +1 -0
  64. package/dist/esm/src/table/range/hooks.js +1 -1
  65. package/dist/esm/src/table/range/hooks.js.map +1 -1
  66. package/dist/esm/src/table/range/provider.js +1 -1
  67. package/dist/esm/src/table/range/provider.js.map +1 -1
  68. package/dist/esm/src/table/sheet/components.js +1 -1
  69. package/dist/esm/src/table/sheet/components.js.map +1 -1
  70. package/dist/esm/src/table/table/base.js +1 -1
  71. package/package.json +1 -1
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),r=require("react"),t=r.createContext("");exports.IdProvider=function(r){var n=r.id,i=r.children;return e.jsx(t.Provider,{value:n,children:i})},exports.useIdContext=function(){return r.useContext(t)};
2
+ //# sourceMappingURL=provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"provider.js","sources":["../../../../../src/select-box/id/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\n\nconst IdContext = createContext<string>(\"\");\n\nexport function IdProvider({\n id,\n children,\n}: {\n id: string;\n children: React.ReactNode;\n}) {\n return <IdContext.Provider value={id}>{children}</IdContext.Provider>;\n}\n\nexport function useIdContext() {\n return useContext(IdContext);\n}\n"],"names":["IdContext","createContext","_a","id","children","_jsx","jsx","Provider","value","useContext"],"mappings":"mEAEMA,EAAYC,EAAAA,cAAsB,uBAElC,SAAqBC,OACzBC,EAAED,EAAAC,GACFC,EAAQF,EAAAE,SAKR,OAAOC,EAAAC,IAACN,EAAUO,SAAQ,CAACC,MAAOL,EAAEC,SAAGA,GACzC,kCAGE,OAAOK,EAAAA,WAAWT,EACpB"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),n=require("react"),t=require("./parts/input-area.js"),r=require("./parts/options-area.js"),o=require("./parts/frame.js"),u=require("./id/provider.js"),i=require("./lib/id-generator.js");exports.SelectBox=function(a){var d,s,l,c,f=n.useState(null!==(d=a.value)&&void 0!==d?d:""),v=f[0],p=f[1],m=n.useState(null!==(s=a.defaultIsOpen)&&void 0!==s&&s),g=m[0],y=m[1],x=n.useState(""),w=x[0],I=x[1],S=n.useState(void 0),E=S[0],h=S[1],j=function(e){p(e),a.onSelect(e),I(""),y(!1)},k=null!==(c=null===(l=a.options.find((function(e){return e.value===v})))||void 0===l?void 0:l.label)&&void 0!==c?c:"",B=n.useMemo((function(){return a.options.filter((function(e){return e.label.toLowerCase().includes(w.toLowerCase())}))}),[a.options,w]);n.useEffect((function(){var e=function(e){var n=document.getElementById(i.IdGenerator.generateIdSelectBoxFrame(a.id)),t=document.getElementById(i.IdGenerator.generateIdSelectBoxOptionsArea(a.id)),r=e.target;r instanceof Node&&(null==n?void 0:n.contains(r))||r instanceof Node&&(null==t?void 0:t.contains(r))||(I(""),y(!1))};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[]),n.useEffect((function(){if(g){var e=function(e){"ArrowDown"===e.key?(e.preventDefault(),h((function(e){return"number"==typeof e?Math.min(e+1,B.length-1):0}))):"ArrowUp"===e.key?(e.preventDefault(),h((function(e){return"number"==typeof e?Math.max(e-1,0):0}))):"Enter"===e.key&&(e.preventDefault(),"number"==typeof E&&j(B[E].value))};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}h(void 0);var n=document.getElementById(i.IdGenerator.generateIdSelectBoxInputArea(a.id));if(n){var t=function(e){"ArrowDown"===e.key&&(e.preventDefault(),y(!0))};return n.addEventListener("keydown",t),function(){n.removeEventListener("keydown",t)}}}),[g,B,E,h]);var L=0===B.length?void 0:"number"==typeof E&&E<B.length?B[E].value:void 0;return e.jsx(u.IdProvider,{id:a.id,children:e.jsxs(o.SelectBoxFrame,{isOpen:g,onToggle:function(){return y((function(e){return!e}))},children:[e.jsx(t.InputArea,{inputRef:a.inputRef,isSelecting:g,selectedValue:k,searchText:w,onChangeSearchText:I}),g&&e.jsx(r.OptionsArea,{options:B,value:v,onSelect:j,selectingValue:L})]})})};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../../src/select-box/index.tsx"],"sourcesContent":["import { useEffect, useMemo, useState } from \"react\";\nimport { InputArea, OptionsArea, SelectBoxFrame } from \"./parts\";\nimport { Options } from \"./types\";\nimport { IdProvider } from \"./id/provider\";\nimport { IdGenerator } from \"./lib\";\n\ninterface IPropsSelectBox {\n id: string;\n inputRef?: React.RefObject<HTMLInputElement>;\n defaultIsOpen?: boolean;\n options: Options[];\n value?: string;\n onSelect: (value: string) => void;\n}\n\nexport function SelectBox(props: IPropsSelectBox) {\n const [value, setValue] = useState(props.value ?? \"\");\n const [isOpen, setIsOpen] = useState(props.defaultIsOpen ?? false);\n const [searchText, setSearchText] = useState(\"\");\n const [selectingIndex, setSelectingIndex] = useState<number | undefined>(\n undefined\n );\n\n const handleSelect = (value: string) => {\n setValue(value);\n props.onSelect(value);\n setSearchText(\"\");\n setIsOpen(false);\n };\n\n const label =\n props.options.find((option) => option.value === value)?.label ?? \"\";\n\n const searchedOptions = useMemo(\n () =>\n props.options.filter((option) =>\n option.label.toLowerCase().includes(searchText.toLowerCase())\n ),\n [props.options, searchText]\n );\n\n useEffect(() => {\n const onClickOutOfSelectBox = (e: MouseEvent) => {\n // SelectBox関連の要素を取得\n const frameElement = document.getElementById(\n IdGenerator.generateIdSelectBoxFrame(props.id)\n );\n const optionsElement = document.getElementById(\n IdGenerator.generateIdSelectBoxOptionsArea(props.id)\n );\n\n // クリックされた要素を取得\n const ele = e.target;\n\n if (ele instanceof Node && frameElement?.contains(ele)) return;\n if (ele instanceof Node && optionsElement?.contains(ele)) return;\n\n setSearchText(\"\");\n setIsOpen(false);\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfSelectBox);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfSelectBox);\n };\n }, []);\n\n useEffect(() => {\n if (!isOpen) {\n setSelectingIndex(undefined);\n\n const inputElement = document.getElementById(\n IdGenerator.generateIdSelectBoxInputArea(props.id)\n );\n\n if (inputElement) {\n // inputElementにフォーカスされている場合、ArrowDownを押すとOptionsAreaが開く\n const handleKeydown = (e: KeyboardEvent) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setIsOpen(true);\n }\n };\n inputElement.addEventListener(\"keydown\", handleKeydown);\n\n return () => {\n inputElement.removeEventListener(\"keydown\", handleKeydown);\n };\n }\n } else {\n const handleKeydown = (e: KeyboardEvent) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n setSelectingIndex((prev) =>\n typeof prev === \"number\"\n ? Math.min(prev + 1, searchedOptions.length - 1)\n : 0\n );\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n setSelectingIndex((prev) =>\n typeof prev === \"number\" ? Math.max(prev - 1, 0) : 0\n );\n } else if (e.key === \"Enter\") {\n e.preventDefault();\n if (typeof selectingIndex === \"number\") {\n handleSelect(searchedOptions[selectingIndex].value);\n }\n }\n };\n document.addEventListener(\"keydown\", handleKeydown);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeydown);\n };\n }\n }, [isOpen, searchedOptions, selectingIndex, setSelectingIndex]);\n\n const selectingValue =\n searchedOptions.length === 0\n ? undefined\n : typeof selectingIndex === \"number\" &&\n selectingIndex < searchedOptions.length\n ? searchedOptions[selectingIndex].value\n : undefined;\n\n return (\n <IdProvider id={props.id}>\n <SelectBoxFrame\n isOpen={isOpen}\n onToggle={() => setIsOpen((prev) => !prev)}\n >\n <InputArea\n inputRef={props.inputRef}\n isSelecting={isOpen}\n selectedValue={label}\n searchText={searchText}\n onChangeSearchText={setSearchText}\n />\n {isOpen && (\n <OptionsArea\n options={searchedOptions}\n value={value}\n onSelect={handleSelect}\n selectingValue={selectingValue}\n />\n )}\n </SelectBoxFrame>\n </IdProvider>\n );\n}\n"],"names":["props","_e","useState","_a","value","setValue","_f","_b","defaultIsOpen","isOpen","setIsOpen","_g","searchText","setSearchText","_h","undefined","selectingIndex","setSelectingIndex","handleSelect","onSelect","label","_d","_c","options","find","option","searchedOptions","useMemo","filter","toLowerCase","includes","useEffect","onClickOutOfSelectBox","e","frameElement","document","getElementById","IdGenerator","generateIdSelectBoxFrame","id","optionsElement","generateIdSelectBoxOptionsArea","ele","target","Node","contains","addEventListener","removeEventListener","handleKeydown_2","key","preventDefault","prev","Math","min","length","max","inputElement_1","generateIdSelectBoxInputArea","handleKeydown_1","selectingValue","_jsx","IdProvider","children","_jsxs","jsxs","SelectBoxFrame","onToggle","jsx","InputArea","inputRef","isSelecting","selectedValue","onChangeSearchText","OptionsArea"],"mappings":"4PAeM,SAAoBA,eAClBC,EAAoBC,EAAQA,SAAY,QAAXC,EAAAH,EAAMI,aAAK,IAAAD,EAAAA,EAAI,IAA3CC,EAAKH,EAAA,GAAEI,OACRC,EAAsBJ,EAAQA,SAAoB,QAAnBK,EAAAP,EAAMQ,qBAAa,IAAAD,GAAAA,GAAjDE,EAAMH,EAAA,GAAEI,OACTC,EAA8BT,EAAAA,SAAS,IAAtCU,EAAUD,EAAA,GAAEE,EAAaF,EAAA,GAC1BG,EAAsCZ,EAAAA,cAC1Ca,GADKC,EAAcF,EAAA,GAAEG,EAAiBH,EAAA,GAIlCI,EAAe,SAACd,GACpBC,EAASD,GACTJ,EAAMmB,SAASf,GACfS,EAAc,IACdH,GAAU,EACZ,EAEMU,EAC6D,QAAjEC,EAAwD,QAAxDC,EAAAtB,EAAMuB,QAAQC,MAAK,SAACC,GAAW,OAAAA,EAAOrB,QAAUA,YAAQ,IAAAkB,OAAA,EAAAA,EAAAF,aAAS,IAAAC,EAAAA,EAAA,GAE7DK,EAAkBC,EAAAA,SACtB,WACE,OAAA3B,EAAMuB,QAAQK,QAAO,SAACH,GACpB,OAAAA,EAAOL,MAAMS,cAAcC,SAASlB,EAAWiB,cAA/C,GACD,GACH,CAAC7B,EAAMuB,QAASX,IAGlBmB,EAAAA,WAAU,WACR,IAAMC,EAAwB,SAACC,GAE7B,IAAMC,EAAeC,SAASC,eAC5BC,EAAAA,YAAYC,yBAAyBtC,EAAMuC,KAEvCC,EAAiBL,SAASC,eAC9BC,EAAAA,YAAYI,+BAA+BzC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N,OACE6C,MAACC,EAAAA,YAAWtB,GAAIvC,EAAMuC,GACpBuB,SAAAC,EAAAC,KAACC,EAAcA,eACb,CAAAxD,OAAQA,EACRyD,SAAU,WAAM,OAAAxD,GAAU,SAACyC,GAAS,OAACA,IAAK,YAE1CS,EAACO,IAAAC,EAASA,WACRC,SAAUrE,EAAMqE,SAChBC,YAAa7D,EACb8D,cAAenD,EACfR,WAAYA,EACZ4D,mBAAoB3D,IAErBJ,GACCmD,EAACO,IAAAM,cACC,CAAAlD,QAASG,EACTtB,MAAOA,EACPe,SAAUD,EACVyC,eAAgBA,QAM5B"}
@@ -0,0 +1,2 @@
1
+ "use strict";var t="teppen:react-ui:select-box",n=function(){function n(){}return n.generateIdSelectBoxInputArea=function(n){return""===n?"".concat(t,":input-area"):"".concat(t,":").concat(n,":input-area")},n.generateIdSelectBoxOptionsArea=function(n){return""===n?"".concat(t,":options-area"):"".concat(t,":").concat(n,":options-area")},n.generateIdSelectBoxFrame=function(n){return""===n?"".concat(t,":frame"):"".concat(t,":").concat(n,":frame")},n.generateIdSelectBoxOption=function(n,e){return""===n?"".concat(t,":option:").concat(e):"".concat(t,":").concat(n,":option:").concat(e)},n}();exports.IdGenerator=n;
2
+ //# sourceMappingURL=id-generator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"id-generator.js","sources":["../../../../../src/select-box/lib/id-generator.ts"],"sourcesContent":["const ID_PREFIX = \"teppen:react-ui:select-box\";\n\nexport class IdGenerator {\n static generateIdSelectBoxInputArea(id: string): string {\n if (id === \"\") {\n return `${ID_PREFIX}:input-area`;\n } else {\n return `${ID_PREFIX}:${id}:input-area`;\n }\n }\n\n static generateIdSelectBoxOptionsArea(id: string): string {\n if (id === \"\") {\n return `${ID_PREFIX}:options-area`;\n } else {\n return `${ID_PREFIX}:${id}:options-area`;\n }\n }\n\n static generateIdSelectBoxFrame(id: string): string {\n if (id === \"\") {\n return `${ID_PREFIX}:frame`;\n } else {\n return `${ID_PREFIX}:${id}:frame`;\n }\n }\n\n static generateIdSelectBoxOption(id: string, value: string): string {\n if (id === \"\") {\n return `${ID_PREFIX}:option:${value}`;\n } else {\n return `${ID_PREFIX}:${id}:option:${value}`;\n }\n }\n}\n"],"names":["ID_PREFIX","IdGenerator","generateIdSelectBoxInputArea","id","concat","generateIdSelectBoxOptionsArea","generateIdSelectBoxFrame","generateIdSelectBoxOption","value"],"mappings":"aAAA,IAAMA,EAAY,6BAElBC,EAAA,WAAA,SAAAA,IAgCC,CAAD,OA/BSA,EAA4BC,6BAAnC,SAAoCC,GAClC,MAAW,KAAPA,EACK,GAAAC,OAAGJ,EAAS,eAEZ,GAAGI,OAAAJ,EAAa,KAAAI,OAAAD,kBAIpBF,EAA8BI,+BAArC,SAAsCF,GACpC,MAAW,KAAPA,EACK,GAAAC,OAAGJ,EAAS,iBAEZ,GAAGI,OAAAJ,EAAa,KAAAI,OAAAD,oBAIpBF,EAAwBK,yBAA/B,SAAgCH,GAC9B,MAAW,KAAPA,EACK,GAAAC,OAAGJ,EAAS,UAEZ,GAAGI,OAAAJ,EAAa,KAAAI,OAAAD,aAIpBF,EAAAM,0BAAP,SAAiCJ,EAAYK,GAC3C,MAAW,KAAPL,EACK,GAAGC,OAAAJ,EAAoB,YAAAI,OAAAI,GAEvB,UAAGR,EAAS,KAAAI,OAAID,EAAa,YAAAC,OAAAI,IAGzCP,CAAD"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),r=require("../id/provider.js"),i=require("../lib/id-generator.js"),t=require("../../../node_modules/react-icons/md/index.js");exports.SelectBoxFrame=function(n){var o=r.useIdContext();return e.jsxs("div",{id:i.IdGenerator.generateIdSelectBoxFrame(o),className:"relative w-full",children:[e.jsx("div",{onClick:function(e){n.isOpen||n.onToggle()},children:n.children}),e.jsx("div",{className:"absolute grid place-items-center h-full right-1 top-0",onClick:function(e){e.stopPropagation(),n.onToggle()},children:e.jsx(t.MdOutlineKeyboardArrowLeft,{className:"duration-300 ".concat(n.isOpen?"-rotate-90":"")})})]})};
2
+ //# sourceMappingURL=frame.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"frame.js","sources":["../../../../../src/select-box/parts/frame.tsx"],"sourcesContent":["import { useIdContext } from \"../id/provider\";\nimport { IdGenerator } from \"../lib\";\nimport { MdOutlineKeyboardArrowLeft } from \"react-icons/md\";\n\ninterface IPropsSelectBoxFrame {\n onToggle: () => void;\n isOpen: boolean;\n children: React.ReactNode;\n}\n\nexport function SelectBoxFrame(props: IPropsSelectBoxFrame) {\n const id = useIdContext();\n\n return (\n <div\n id={IdGenerator.generateIdSelectBoxFrame(id)}\n className=\"relative w-full\"\n >\n <div\n onClick={(e) => {\n if (!props.isOpen) {\n props.onToggle();\n }\n }}\n >\n {props.children}\n </div>\n <div\n className=\"absolute grid place-items-center h-full right-1 top-0\"\n onClick={(e) => {\n e.stopPropagation();\n props.onToggle();\n }}\n >\n <MdOutlineKeyboardArrowLeft\n className={`duration-300 ${props.isOpen ? \"-rotate-90\" : \"\"}`}\n />\n </div>\n </div>\n );\n}\n"],"names":["props","id","useIdContext","_jsxs","IdGenerator","generateIdSelectBoxFrame","className","children","_jsx","onClick","e","isOpen","onToggle","jsx","stopPropagation","MdOutlineKeyboardArrowLeft","concat"],"mappings":"qMAUM,SAAyBA,GAC7B,IAAMC,EAAKC,EAAAA,eAEX,OACEC,EAAAA,KACE,MAAA,CAAAF,GAAIG,EAAWA,YAACC,yBAAyBJ,GACzCK,UAAU,kBAAiBC,SAAA,CAE3BC,aACEC,QAAS,SAACC,GACHV,EAAMW,QACTX,EAAMY,UAET,EAEAL,SAAAP,EAAMO,WAETC,EAAAK,IAAA,MAAA,CACEP,UAAU,wDACVG,QAAS,SAACC,GACRA,EAAEI,kBACFd,EAAMY,YACPL,SAEDC,EAAAA,IAACO,EAAAA,2BAA0B,CACzBT,UAAW,gBAAAU,OAAgBhB,EAAMW,OAAS,aAAe,UAKnE"}
@@ -0,0 +1,3 @@
1
+ "use client";
2
+ "use strict";var e=require("react/jsx-runtime"),r=require("../id/provider.js"),t=require("../lib/id-generator.js");exports.InputArea=function(a){var n=r.useIdContext();return e.jsx("input",{id:t.IdGenerator.generateIdSelectBoxInputArea(n),ref:a.inputRef,className:"border border-gray-300 px-2 py-1 w-full",type:"text",placeholder:""===a.selectedValue?"選択してください":a.selectedValue,value:a.isSelecting?a.searchText:a.selectedValue,onChange:function(e){e.preventDefault(),a.onChangeSearchText(e.target.value)}})};
3
+ //# sourceMappingURL=input-area.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-area.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
@@ -0,0 +1,2 @@
1
+ "use strict";var e=require("react/jsx-runtime"),r=require("react"),t=require("../id/provider.js"),n=require("../lib/id-generator.js");exports.OptionsArea=function(a){var l=t.useIdContext();return r.useEffect((function(){var e,r=document.getElementById(n.IdGenerator.generateIdSelectBoxOption(l,null!==(e=a.selectingValue)&&void 0!==e?e:""));r&&r.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}),[a.selectingValue]),e.jsx("div",{id:n.IdGenerator.generateIdSelectBoxOptionsArea(l),className:"absolute top-full left-0 w-full max-h-[40vh] overflow-auto border border-gray-300",children:a.options.map((function(r){var t;return e.jsx("div",{id:n.IdGenerator.generateIdSelectBoxOption(l,null!==(t=r.value)&&void 0!==t?t:""),className:"hover:bg-gray-200 px-2 py-1 ".concat("string"==typeof a.selectingValue?a.selectingValue===r.value?"bg-gray-100":"bg-white":a.value===r.value?"bg-gray-100":"bg-white"),onClick:function(){return a.onSelect(r.value)},children:r.label},r.value)}))})};
2
+ //# sourceMappingURL=options-area.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options-area.js","sources":["../../../../../src/select-box/parts/options-area.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { Options } from \"../types\";\nimport { useIdContext } from \"../id/provider\";\nimport { IdGenerator } from \"../lib\";\n\ninterface IPropsSelectArea {\n options: Options[];\n value: string;\n onSelect: (value: string) => void;\n selectingValue?: string;\n}\n\nexport function OptionsArea(props: IPropsSelectArea) {\n const id = useIdContext();\n\n useEffect(() => {\n const optionElement = document.getElementById(\n IdGenerator.generateIdSelectBoxOption(id, props.selectingValue ?? \"\")\n );\n\n if (!optionElement) return;\n\n optionElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n }, [props.selectingValue]);\n\n return (\n <div\n id={IdGenerator.generateIdSelectBoxOptionsArea(id)}\n className=\"absolute top-full left-0 w-full max-h-[40vh] overflow-auto border border-gray-300\"\n >\n {props.options.map((option) => (\n <div\n id={IdGenerator.generateIdSelectBoxOption(id, option.value ?? \"\")}\n className={`hover:bg-gray-200 px-2 py-1 ${\n typeof props.selectingValue === \"string\"\n ? props.selectingValue === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n : props.value === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n }`}\n key={option.value}\n onClick={() => props.onSelect(option.value)}\n >\n {option.label}\n </div>\n ))}\n </div>\n );\n}\n"],"names":["props","id","useIdContext","useEffect","optionElement","document","getElementById","IdGenerator","generateIdSelectBoxOption","_a","selectingValue","scrollIntoView","behavior","block","inline","_jsx","generateIdSelectBoxOptionsArea","className","options","map","option","value","concat","onClick","onSelect","children","label"],"mappings":"0JAYM,SAAsBA,GAC1B,IAAMC,EAAKC,EAAAA,eAgBX,OAdAC,EAAAA,WAAU,iBACFC,EAAgBC,SAASC,eAC7BC,EAAWA,YAACC,0BAA0BP,UAAIQ,EAAAT,EAAMU,8BAAkB,KAG/DN,GAELA,EAAcO,eAAe,CAC3BC,SAAU,SACVC,MAAO,UACPC,OAAQ,WAEZ,GAAG,CAACd,EAAMU,iBAGRK,EAAAA,WACEd,GAAIM,EAAWA,YAACS,+BAA+Bf,GAC/CgB,UAAU,6FAETjB,EAAMkB,QAAQC,KAAI,SAACC,SAAW,OAC7BL,MACE,MAAA,CAAAd,GAAIM,EAAWA,YAACC,0BAA0BP,EAAoB,QAAhBQ,EAAAW,EAAOC,aAAS,IAAAZ,EAAAA,EAAA,IAC9DQ,UAAW,+BACTK,OAAgC,iBAAzBtB,EAAMU,eACTV,EAAMU,iBAAmBU,EAAOC,MAC9B,cACA,WACFrB,EAAMqB,QAAUD,EAAOC,MACvB,cACA,YAGNE,QAAS,WAAM,OAAAvB,EAAMwB,SAASJ,EAAOC,MAAM,EAE1CI,SAAAL,EAAOM,OAHHN,EAAOC,MAKf,KAGP"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("react"),t=require("../edit/provider.js"),n=require("../sheet/providers.js"),o=require("../libs/id-generator.js"),r=require("../range/provider.js");exports.useCell=function(i,u){var s,d,a=r.useRangeActionContext(),l=a.startSelectRange,c=a.moveSelectRange,p=a.endSelectRange,v=t.useEditActionContext().startEditing,f=o.IdGenerator.getCellIndex(i),g=f[0],m=f[1],x=n.useColumnsContext()[m],C=u[x.key],b="select"===x.type?null===(d=null===(s=x.options)||void 0===s?void 0:s.find((function(e){return e.value===C})))||void 0===d?void 0:d.label:C,I=e.useMemo((function(){return x.editable?b:x.render?x.render(C,u):b}),[x.editable,b,C,u]);return{type:!x.editable&&x.render?"component":x.type,component:I,onDoubleClick:function(e){e.preventDefault(),v()},onMouseDown:function(e){e.stopPropagation(),setTimeout((function(){l({rowIndex:g,colIndex:m});var e=function(t){t.preventDefault(),t.stopPropagation(),p(),document.removeEventListener("mouseup",e)};document.addEventListener("mouseup",e)}),0)},onMouseEnter:function(e){e.preventDefault(),e.stopPropagation(),c({rowIndex:g,colIndex:m})}}};
1
+ "use strict";var e=require("react"),n=require("../edit/provider.js"),t=require("../sheet/providers.js"),o=require("../libs/id-generator.js"),r=require("../range/provider.js");exports.useCell=function(i,u){var d,s,l=r.useRangeActionContext(),a=l.startSelectRange,c=l.moveSelectRange,p=l.endSelectRange,v=n.useEditActionContext().startEditing,f=o.IdGenerator.getCellIndex(i),m=f[0],g=f[1],x=t.useColumnsContext()[g],C=u[x.key],b="select"===x.type?null===(s=null===(d=x.options)||void 0===d?void 0:d.find((function(e){return e.value===C})))||void 0===s?void 0:s.label:C,I=e.useMemo((function(){return x.editable?b:x.render?x.render(C,u):b}),[x.editable,b,C,u]);return{type:!x.editable&&x.render?"component":x.type,component:I,onDoubleClick:function(e){e.preventDefault(),v()},onMouseDown:function(e){setTimeout((function(){a({rowIndex:m,colIndex:g});var e=function(n){n.preventDefault(),n.stopPropagation(),p(),document.removeEventListener("mouseup",e)};document.addEventListener("mouseup",e)}),0)},onMouseEnter:function(e){e.preventDefault(),e.stopPropagation(),c({rowIndex:m,colIndex:g})}}};
2
2
  //# sourceMappingURL=hooks.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.js","sources":["../../../../../src/table/cell/hooks.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useEditActionContext } from \"../edit/provider\";\nimport { useColumnsContext } from \"../sheet/providers\";\nimport { DataObject, DataRecord, TColumnType } from \"../table/type\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\nexport function useCell(id: string, row: DataObject<DataRecord>) {\n const { startSelectRange, moveSelectRange, endSelectRange } =\n useRangeActionContext();\n const { startEditing } = useEditActionContext();\n const [rowIndex, colIndex] = IdGenerator.getCellIndex(id);\n const col = useColumnsContext()[colIndex];\n const value = row[col.key as string];\n\n const label =\n col.type === \"select\"\n ? col.options?.find((op) => op.value === value)?.label\n : value;\n\n const component = useMemo(() => {\n if (col.editable) {\n return label;\n } else {\n return col.render ? col.render(value as never, row) : label;\n }\n }, [col.editable, label, value, row]);\n\n const type: TColumnType | \"component\" =\n !col.editable && col.render ? \"component\" : col.type;\n\n const onDoubleClick: React.MouseEventHandler<HTMLDivElement> = (e) => {\n e.preventDefault();\n startEditing();\n };\n\n /**\n * onBlurよりも先に発火するため、onBlurでendEditingを呼ぶと\n * すぐにstartEditingが呼ばれてしまうため、setTimeoutで遅延させる\n * これにより、endEditingが先に呼ばれるようになる\n */\n const onMouseDown: React.MouseEventHandler<HTMLDivElement> = (e) => {\n e.stopPropagation();\n\n setTimeout(() => {\n startSelectRange({ rowIndex, colIndex });\n\n const onMouseUp = (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n endSelectRange();\n document.removeEventListener(\"mouseup\", onMouseUp);\n };\n\n document.addEventListener(\"mouseup\", onMouseUp);\n }, 0);\n };\n\n const onMouseEnter: React.MouseEventHandler<HTMLDivElement> = (e) => {\n e.preventDefault();\n e.stopPropagation();\n moveSelectRange({ rowIndex, colIndex });\n };\n\n return {\n type,\n component,\n onDoubleClick,\n onMouseDown,\n onMouseEnter,\n };\n}\n"],"names":["id","row","_c","useRangeActionContext","startSelectRange","moveSelectRange","endSelectRange","startEditing","useEditActionContext","_d","IdGenerator","getCellIndex","rowIndex","colIndex","col","useColumnsContext","value","key","label","type","_a","options","find","op","_b","component","useMemo","editable","render","onDoubleClick","e","preventDefault","onMouseDown","stopPropagation","setTimeout","onMouseUp","document","removeEventListener","addEventListener","onMouseEnter"],"mappings":"+LAOgB,SAAQA,EAAYC,WAC5BC,EACJC,EAAAA,wBADMC,EAAgBF,EAAAE,iBAAEC,EAAeH,EAAAG,gBAAEC,EAAcJ,EAAAI,eAEjDC,EAAiBC,sCACnBC,EAAuBC,EAAAA,YAAYC,aAAaX,GAA/CY,EAAQH,EAAA,GAAEI,OACXC,EAAMC,EAAAA,oBAAoBF,GAC1BG,EAAQf,EAAIa,EAAIG,KAEhBC,EACS,WAAbJ,EAAIK,KAC6C,UAAlC,QAAXC,EAAAN,EAAIO,eAAO,IAAAD,OAAA,EAAAA,EAAEE,MAAK,SAACC,GAAO,OAAAA,EAAGP,QAAUA,CAAb,WAAmB,IAAAQ,OAAA,EAAAA,EAAEN,MAC/CF,EAEAS,EAAYC,EAAAA,SAAQ,WACxB,OAAIZ,EAAIa,SACCT,EAEAJ,EAAIc,OAASd,EAAIc,OAAOZ,EAAgBf,GAAOiB,CAE1D,GAAG,CAACJ,EAAIa,SAAUT,EAAOF,EAAOf,IAsChC,MAAO,CACLkB,MApCCL,EAAIa,UAAYb,EAAIc,OAAS,YAAcd,EAAIK,KAqChDM,UAASA,EACTI,cApC6D,SAACC,GAC9DA,EAAEC,iBACFxB,GACF,EAkCEyB,YA3B2D,SAACF,GAC5DA,EAAEG,kBAEFC,YAAW,WACT9B,EAAiB,CAAEQ,SAAQA,EAAEC,SAAQA,IAErC,IAAMsB,EAAY,SAACL,GACjBA,EAAEC,iBACFD,EAAEG,kBACF3B,IACA8B,SAASC,oBAAoB,UAAWF,EAC1C,EAEAC,SAASE,iBAAiB,UAAWH,EACtC,GAAE,EACL,EAaEI,aAX4D,SAACT,GAC7DA,EAAEC,iBACFD,EAAEG,kBACF5B,EAAgB,CAAEO,SAAQA,EAAEC,SAAQA,GACtC,EASF"}
1
+ {"version":3,"file":"hooks.js","sources":["../../../../../src/table/cell/hooks.ts"],"sourcesContent":["import { useMemo } from \"react\";\nimport { useEditActionContext } from \"../edit/provider\";\nimport { useColumnsContext } from \"../sheet/providers\";\nimport { DataObject, DataRecord, TColumnType } from \"../table/type\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\nexport function useCell(id: string, row: DataObject<DataRecord>) {\n const { startSelectRange, moveSelectRange, endSelectRange } =\n useRangeActionContext();\n const { startEditing } = useEditActionContext();\n const [rowIndex, colIndex] = IdGenerator.getCellIndex(id);\n const col = useColumnsContext()[colIndex];\n const value = row[col.key as string];\n\n const label =\n col.type === \"select\"\n ? col.options?.find((op) => op.value === value)?.label\n : value;\n\n const component = useMemo(() => {\n if (col.editable) {\n return label;\n } else {\n return col.render ? col.render(value as never, row) : label;\n }\n }, [col.editable, label, value, row]);\n\n const type: TColumnType | \"component\" =\n !col.editable && col.render ? \"component\" : col.type;\n\n const onDoubleClick: React.MouseEventHandler<HTMLDivElement> = (e) => {\n e.preventDefault();\n startEditing();\n };\n\n /**\n * onBlurよりも先に発火するため、onBlurでendEditingを呼ぶと\n * すぐにstartEditingが呼ばれてしまうため、setTimeoutで遅延させる\n * これにより、endEditingが先に呼ばれるようになる\n */\n const onMouseDown: React.MouseEventHandler<HTMLDivElement> = (e) => {\n setTimeout(() => {\n startSelectRange({ rowIndex, colIndex });\n\n const onMouseUp = (e: MouseEvent) => {\n e.preventDefault();\n e.stopPropagation();\n endSelectRange();\n document.removeEventListener(\"mouseup\", onMouseUp);\n };\n\n document.addEventListener(\"mouseup\", onMouseUp);\n }, 0);\n };\n\n const onMouseEnter: React.MouseEventHandler<HTMLDivElement> = (e) => {\n e.preventDefault();\n e.stopPropagation();\n moveSelectRange({ rowIndex, colIndex });\n };\n\n return {\n type,\n component,\n onDoubleClick,\n onMouseDown,\n onMouseEnter,\n };\n}\n"],"names":["id","row","_c","useRangeActionContext","startSelectRange","moveSelectRange","endSelectRange","startEditing","useEditActionContext","_d","IdGenerator","getCellIndex","rowIndex","colIndex","col","useColumnsContext","value","key","label","type","_a","options","find","op","_b","component","useMemo","editable","render","onDoubleClick","e","preventDefault","onMouseDown","setTimeout","onMouseUp","stopPropagation","document","removeEventListener","addEventListener","onMouseEnter"],"mappings":"+LAOgB,SAAQA,EAAYC,WAC5BC,EACJC,EAAAA,wBADMC,EAAgBF,EAAAE,iBAAEC,EAAeH,EAAAG,gBAAEC,EAAcJ,EAAAI,eAEjDC,EAAiBC,sCACnBC,EAAuBC,EAAAA,YAAYC,aAAaX,GAA/CY,EAAQH,EAAA,GAAEI,OACXC,EAAMC,EAAAA,oBAAoBF,GAC1BG,EAAQf,EAAIa,EAAIG,KAEhBC,EACS,WAAbJ,EAAIK,KAC6C,UAAlC,QAAXC,EAAAN,EAAIO,eAAO,IAAAD,OAAA,EAAAA,EAAEE,MAAK,SAACC,GAAO,OAAAA,EAAGP,QAAUA,CAAb,WAAmB,IAAAQ,OAAA,EAAAA,EAAEN,MAC/CF,EAEAS,EAAYC,EAAAA,SAAQ,WACxB,OAAIZ,EAAIa,SACCT,EAEAJ,EAAIc,OAASd,EAAIc,OAAOZ,EAAgBf,GAAOiB,CAE1D,GAAG,CAACJ,EAAIa,SAAUT,EAAOF,EAAOf,IAoChC,MAAO,CACLkB,MAlCCL,EAAIa,UAAYb,EAAIc,OAAS,YAAcd,EAAIK,KAmChDM,UAASA,EACTI,cAlC6D,SAACC,GAC9DA,EAAEC,iBACFxB,GACF,EAgCEyB,YAzB2D,SAACF,GAC5DG,YAAW,WACT7B,EAAiB,CAAEQ,SAAQA,EAAEC,SAAQA,IAErC,IAAMqB,EAAY,SAACJ,GACjBA,EAAEC,iBACFD,EAAEK,kBACF7B,IACA8B,SAASC,oBAAoB,UAAWH,EAC1C,EAEAE,SAASE,iBAAiB,UAAWJ,EACtC,GAAE,EACL,EAaEK,aAX4D,SAACT,GAC7DA,EAAEC,iBACFD,EAAEK,kBACF9B,EAAgB,CAAEO,SAAQA,EAAEC,SAAQA,GACtC,EASF"}
@@ -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"),s=require("react"),n=require("../range/provider.js"),r=function(s,n){switch(n.type){case"setRows":return e.__assign(e.__assign({},s),{rows:n.payload.rows});case"setCols":return e.__assign(e.__assign({},s),{cols:n.payload.cols});default:return s}};exports.useCopyReducer=function(t){var o=s.useReducer(r,e.__assign({},t)),u=o[0],a=o[1],i=n.useRangeStateContext(),c=s.useCallback((function(){if(i.isSelecting){var e=i.start.rowIndex,s=i.end.rowIndex,n=i.start.colIndex,r=i.end.colIndex,t=u.rows.slice(e,s+1).map((function(e){for(var s=[],t=function(n){var r=u.cols[n];if("number"==r.type||"string"==r.type)return s.push(e[r.key]),"continue";if("select"==r.type){var t=e[r.key];null==t||""===t?s.push(""):s.push(r.options.find((function(s){return s.value===e[r.key]})).label)}},o=n;o<=r;o++)t(o);return s})).map((function(e){return e.join("\t")})).join("\n");navigator.clipboard.writeText(t)}}),[i,u.rows,u.cols]),l=s.useCallback((function(e){a({type:"setRows",payload:{rows:e}})}),[]);return{actions:s.useMemo((function(){return{copy:c,setRows:l}}),[c,l])}};
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 = range.start.rowIndex;\n const endRowIndex = range.end.rowIndex;\n const startColIndex = range.start.colIndex;\n const endColIndex = 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 }, [range, state.rows, state.cols]);\n\n const setRows = useCallback((rows: any[]) => {\n dispatch({ type: \"setRows\", payload: { rows } });\n }, []);\n\n const actions = useMemo(\n () => ({\n copy,\n setRows,\n }),\n [copy, setRows]\n );\n\n return {\n actions,\n };\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","initial","_a","useReducer","dispatch","range","useRangeStateContext","copy","useCallback","isSelecting","startRowIndex","start","rowIndex","endRowIndex","end","startColIndex","colIndex","endColIndex","copiedDataString","slice","map","row","copiedRow","i","col","push","key","value","options","find","option","label","join","navigator","clipboard","writeText","setRows","actions","useMemo"],"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,QACE,OAAON,EAEb,yBAEM,SAAyBO,GAKvB,IAAAC,EAAoBC,EAAAA,WAAWV,EAChCI,EAAAA,SAAA,CAAA,EAAAI,IADEP,EAAKQ,EAAA,GAAEE,OAGRC,EAAQC,EAAAA,uBAERC,EAAOC,EAAAA,aAAY,WACvB,GAAKH,EAAMI,YAAX,CAIA,IAAMC,EAAgBL,EAAMM,MAAMC,SAC5BC,EAAcR,EAAMS,IAAIF,SACxBG,EAAgBV,EAAMM,MAAMK,SAC5BC,EAAcZ,EAAMS,IAAIE,SA4BxBE,EA1BaxB,EAAMI,KACtBqB,MAAMT,EAAeG,EAAc,GACnCO,KAAI,SAACC,GAEJ,IADA,IAAMC,EAAY,cACTC,GACP,IAAMC,EAAM9B,EAAMM,KAAKuB,GAEvB,GAAgB,UAAZC,EAAI5B,MAAgC,UAAZ4B,EAAI5B,YAC9B0B,EAAUG,KAAKJ,EAAIG,EAAIE,iBAElB,GAAgB,UAAZF,EAAI5B,KAAkB,CAC/B,IAAM+B,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,EAnC7B,CAoCH,GAAG,CAACb,EAAOX,EAAMI,KAAMJ,EAAMM,OAEvBoC,EAAU5B,eAAY,SAACV,GAC3BM,EAAS,CAAER,KAAM,UAAWG,QAAS,CAAED,KAAIA,IAC5C,GAAE,IAUH,MAAO,CACLuC,QATcC,WACd,WAAM,MAAC,CACL/B,KAAIA,EACJ6B,QAAOA,KAET,CAAC7B,EAAM6B,IAMX"}
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,IAA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,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"),r=require("react"),o=require("./hooks.js"),t=r.createContext({copy:function(){},setRows:function(){}});exports.CopyProvider=function(r){var n=r.children,s=r.rows,c=r.cols;return e.jsx(t.Provider,{value:o.useCopyReducer({rows:s,cols:c}).actions,children:n})},exports.useCopyActionContext=function(){return r.useContext(t)};
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 return (\n <CopyActionContext.Provider\n value={\n useCopyReducer({\n rows,\n cols,\n }).actions\n }\n >\n {children}\n </CopyActionContext.Provider>\n );\n}\n\nexport function useCopyActionContext() {\n return useContext(CopyActionContext);\n}\n"],"names":["CopyActionContext","createContext","copy","setRows","_a","children","rows","cols","_jsx","Provider","value","useCopyReducer","actions","useContext"],"mappings":"2FAIMA,EAAoBC,EAAAA,cAAkC,CAC1DC,KAAM,WAAQ,EACdC,QAAS,WAAQ,yBAGb,SAAuBC,GAC3B,IAAAC,aACAC,EAAIF,EAAAE,KACJC,EAAIH,EAAAG,KAMJ,OACEC,MAACR,EAAkBS,SACjB,CAAAC,MACEC,EAAAA,eAAe,CACbL,KAAIA,EACJC,KAAIA,IACHK,QAAOP,SAGXA,GAGP,0CAGE,OAAOQ,EAAAA,WAAWb,EACpB"}
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,3 +1,3 @@
1
1
  "use client";
2
- "use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../provider.js"),r=require("../../../icon/cancel-icon.js");exports.SelectCellInput=function(u){var l=u.col,o=n.useEditActionContext().endEditing,i=u.row[l.key],a=t.useState(i),c=a[0],s=a[1],f=t.useRef(null);return t.useEffect((function(){f.current&&f.current.focus()}),[f]),l.editable?e.jsxs("div",{className:"flex justify-between gap-1 w-full items-center",children:[e.jsxs("select",{ref:f,className:"w-full py-1 px-2 bg-white text-gray-900",value:c,onChange:function(e){e.preventDefault(),s(e.target.value)},onBlur:function(e){e.preventDefault(),c!==i?function(e){l.editable&&l.onCellBlur(l.key,e,u.row,o)}(c):o()},onKeyDown:function(e){"Enter"===e.key&&e.preventDefault()},onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(s(i),o())},children:[l.allowEmpty&&e.jsx("option",{value:"",children:""==i?"-- 未選択 --":"-- 選択解除 --"},"TEPPEN/ReactUI Empty Option"),l.options.map((function(t){return e.jsx("option",{value:t.value,children:t.label},t.value)}))]}),e.jsx("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){s(i),o()}),300)},children:e.jsx(r.CancelIcon,{size:16})})]}):e.jsx(e.Fragment,{})};
2
+ "use strict";var e=require("../../../../node_modules/tslib/tslib.es6.js"),t=require("react/jsx-runtime"),n=require("react"),o=require("../provider.js"),r=require("../../../icon/cancel-icon.js"),u=require("../../../select-box/index.js");exports.SelectCellInput=function(i){var s=i.col,c=o.useEditActionContext().endEditing,l=i.row[s.key],a=n.useState(l),f=a[0],d=a[1],p=n.useRef(null),v=n.useRef(null);n.useEffect((function(){v.current&&v.current.focus()}),[v]);var m=function(e){s.editable&&s.onCellBlur(s.key,e,i.row,c)};if(!s.editable)return t.jsx(t.Fragment,{});n.useEffect((function(){var e=function(e){var t=p.current,n=e.target;n instanceof Node&&(null==t?void 0:t.contains(n))||(f!==l?m(f):c())};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[f,m,c,l]);var x=n.useMemo((function(){return s.allowEmpty?e.__spreadArray([{value:"",label:""===l?"-- 未選択 --":"-- 選択解除 --"}],s.options,!0):s.options}),[s.options,s.allowEmpty,l]);return t.jsxs("div",{ref:p,className:"flex justify-between gap-1 w-full items-center",children:[t.jsx(u.SelectBox,{id:"TEPPEN/ReactUI SelectBox",inputRef:v,value:f,defaultIsOpen:!0,options:x,onSelect:function(e){d(e),m(e)}}),t.jsx("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){d(l),c()}),300)},children:t.jsx(r.CancelIcon,{size:16})})]})};
3
3
  //# sourceMappingURL=select-input.js.map
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react"),a=require("../sheet/providers.js"),n=require("../range/provider.js"),s=function(t,a){var n;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.rowIndex,l=t.colIndex;if(!t.onUpdateRowFunction)return t;var c={arguments:[],timing:t.updateParameters.timing+1},d=s.length,p=Math.max.apply(Math,s.map((function(e){return e.length})));if(0===d||0===p)return t;if(s.length+u>o.length)return alert("貼り付け先の行数が足りません。"),t;for(var f=0;f<p;f++){if(!(m=r[l+f]).editable)return alert("編集できない列にデータを貼り付けることはできません。\n\n編集不可列: ".concat(null!==(n=m.label)&&void 0!==n?n:m.key)),t}if(p+l>r.length)return alert("貼り付け先の列数が足りません。"),t;for(f=0;f<d;f++)for(var g=s[f],_=0;_<g.length;_++){var m,w=g[_];if(!(0,i[(m=r[l+_]).key])(w))return t}return s.forEach((function(t,a){var n=e.__assign({},o[u+a]),s=!1;t.forEach((function(e,t){var a=r[l+t],o="number"===a.type?Number(e):"select"===a.type?""===e?"":a.options.find((function(t){return t.label===e})).value:e;n[a.key]!==o&&(s=!0,n[a.key]=o)})),s&&c.arguments.push({newRow:n,oldRow:o[u+a]})})),c.arguments.length>0?e.__assign(e.__assign({},t),{updateParameters:c}):t;case"focus":return e.__assign(e.__assign({},t),{isFocused:!0,rowIndex:a.payload.rowIndex,colIndex:a.payload.colIndex});case"unfocus":return e.__assign(e.__assign({},t),{isFocused:!1})}};exports.usePasteReducer=function(o){var r=t.useReducer(s,e.__assign(e.__assign({},o),{colValidators:{},isFocused:!1,updateParameters:{arguments:[],timing:0}})),i=r[0],u=r[1],l=a.useColumnValidatesContext(),c=n.useRangeStateContext();t.useEffect((function(){c.isSelecting?u({type:"focus",payload:{rowIndex:c.start.rowIndex,colIndex:c.start.colIndex}}):u({type:"unfocus"})}),[c]);var d=t.useCallback((function(e){u({type:"setRows",payload:{rows:e}})}),[]),p=t.useCallback((function(e){u({type:"setCols",payload:{cols:e}})}),[]),f=t.useCallback((function(e){u({type:"setColValidators",payload:{colValidators:e}})}),[]);t.useEffect((function(){f(l)}),[l]);var g=t.useCallback((function(e){u({type:"setOnUpdateRowFunction",payload:{onUpdateRowFunction:e}})}),[]),_=t.useCallback((function(e){u({type:"onPaste",payload:{pasteData:e}})}),[]);return t.useEffect((function(){i.updateParameters.arguments.length>0&&i.updateParameters.arguments.forEach((function(e){var t,a=e.newRow,n=e.oldRow;null===(t=i.onUpdateRowFunction)||void 0===t||t.call(i,a,n)}))}),[i.updateParameters.timing,i.onUpdateRowFunction]),t.useEffect((function(){var e=function(e){if(c.isSelecting&&e.clipboardData){e.preventDefault();var t=e.clipboardData.getData("Text");_(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)}}),[c.isSelecting]),t.useMemo((function(){return{setRows:d,setCols:p,setColValidators:f,setOnUpdateRowFunction:g,onPaste:_}}),[])};
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,mBAC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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,C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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,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,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
- "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 r={UP:{deltaRow:-1,deltaCol:0},DOWN:{deltaRow:1,deltaCol:0},LEFT:{deltaRow:0,deltaCol:-1},RIGHT:{deltaRow:0,deltaCol:1}};function a(e){var t=e.index,n=e.direction,i=e.constraint,s=r[n],a=s.deltaRow,d=s.deltaCol;return o({rowIndex:t.rowIndex+a,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 r=o({rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex,constraint:t.constraint});return t.isSelecting&&s(t.start,r)&&s(t.end,r)&&t.inProgress?t:e.__assign(e.__assign({},t),{isSelecting:!0,inProgress:!0,start:r,end:r});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(r=a({index:t.start,direction:"UP",constraint:t.constraint}),t.start)&&s(r,t.end)?t:e.__assign(e.__assign({},t),{start:r,end:r}):t;case"moveDown":return t.isSelecting?s(r=a({index:t.start,direction:"DOWN",constraint:t.constraint}),t.start)&&s(r,t.end)?t:e.__assign(e.__assign({},t),{start:r,end:r}):t;case"moveLeft":return t.isSelecting?s(r=a({index:t.start,direction:"LEFT",constraint:t.constraint}),t.start)&&s(r,t.end)?t:e.__assign(e.__assign({},t),{start:r,end:r}):t;case"moveRight":return t.isSelecting?s(r=a({index:t.start,direction:"RIGHT",constraint:t.constraint}),t.start)&&s(r,t.end)?t:e.__assign(e.__assign({},t),{start:r,end:r}):t;case"extendUp":return t.isSelecting?s(d=a({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=a({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=a({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=a({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}}};exports.rangeReducer=d,exports.useRangeReducer=function(){var o=t.useReducer(d,{constraint:i({maxColIndex:0,maxRowIndex:0}),isSelecting:!1}),s=o[0],r=o[1],a=t.useMemo((function(){return{setMax:function(e){r({type:"setMax",payload:e})},startSelectRange:function(e){r({type:"startSelectRange",payload:e})},moveSelectRange:function(e){r({type:"moveSelectRange",payload:e})},endSelectRange:function(){r({type:"endSelectRange"})},moveUp:function(){r({type:"moveUp"})},moveDown:function(){r({type:"moveDown"})},moveLeft:function(){r({type:"moveLeft"})},moveRight:function(){r({type:"moveRight"})},extendUp:function(){r({type:"extendUp"})},extendDown:function(){r({type:"extendDown"})},extendLeft:function(){r({type:"extendLeft"})},extendRight:function(){r({type:"extendRight"})},reset:function(){r({type:"reset"})}}}),[]);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))||r({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 r({type:"reset"}),{isSelecting:!1};var a=t.getBoundingClientRect(),d=i.getBoundingClientRect(),c=o.getBoundingClientRect(),l=c.top-o.scrollTop-window.scrollY,g=c.left-o.scrollLeft-window.scrollX,x={top:a.top-l,left:a.left-g,width:a.width,height:a.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:a}};
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,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,EAAGC,SAAU,GAC9BC,KAAM,CAAEF,SAAU,EAAGC,SAAU,GAC/BE,KAAM,CAAEH,SAAU,EAAGC,UAAW,GAChCG,MAAO,CAAEJ,SAAU,EAAGC,SAAU,IAKlC,SAASI,EAAUC,GACjB,IAAAC,UACAC,EAASF,EAAAE,UACTd,EAAUY,EAAAZ,WAMJe,EAAyBX,EAAYU,GAAnCR,EAAQS,EAAAT,SAAEC,EAAQQ,EAAAR,SAK1B,OAAOV,EAAS,CACdC,SAJae,EAAMf,SAAWQ,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AcC,MACzCK,OAAQN,EAAcP,IACtBc,KAAMP,EAAcP,IAAMO,EAAcE,SAE1CpD,6BACKR,EAAMQ,KAAG,CACZsD,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,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","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,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,EAAGC,SAAU,GAC9BC,KAAM,CAAEF,SAAU,EAAGC,SAAU,GAC/BE,KAAM,CAAEH,SAAU,EAAGC,UAAW,GAChCG,MAAO,CAAEJ,SAAU,EAAGC,SAAU,IAKlC,SAASI,EAAUC,GACjB,IAAAC,UACAC,EAASF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EAAaW,WAAaH,OAAOI,QAGjDC,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,CACLvD,aAAa,EACbC,+BACKP,EAAMO,OAAK,CACdwD,OAAQJ,EAAcH,KACtBQ,KAAML,EAAcH,KAAOG,EAAcC,MACzCK,OAAQN,EAAcP,IACtBc,KAAMP,EAAcP,IAAMO,EAAcE,SAE1CrD,6BACKR,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,IAIFa,QAAOA,EAEX"}
@@ -1,2 +1,2 @@
1
- "use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react/jsx-runtime"),n=require("react"),o=require("../lib/errors.js"),r=require("./hooks.js"),i=require("../table-property/provider.js"),s=require("../libs/id-generator.js"),a=n.createContext({isSelecting:!1}),u=n.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});function l(){return n.useContext(a)}function c(){return n.useContext(u)}function d(){var e=c().setMax,o=i.useTablePropertyStateContext(),r=o.maxDisplayRowCount,s=o.maxDisplayColCount;return n.useEffect((function(){e({maxRowIndex:r-1,maxColIndex:s-1})}),[r,s]),t.jsx(t.Fragment,{})}exports.RangeProvider=function(e){var n=e.children,o=r.useRangeReducer(),i=o.state,s=o.actions;return t.jsx(a.Provider,{value:i,children:t.jsxs(u.Provider,{value:s,children:[t.jsx(d,{}),n]})})},exports.TestRange=function(e){var o=l();if(n.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 t.jsx(t.Fragment,{});var r=o.rangeBox,i=o.start,a=o.end,u=i.xEnd<a.xEnd?a.xEnd:i.xEnd,c=i.yEnd<a.yEnd?a.yEnd:i.yEnd;return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"absolute border border-gray-500 ".concat(e.isCopied?"border-dashed":"border-solid"),style:{top:r.top,left:r.left,width:r.width,height:r.height,pointerEvents:"none"}}),t.jsx("div",{className:"absolute bg-gray-700",style:{top:c-5,left:u-5,width:10,height:10,pointerEvents:"none"}})]})},exports.useRangeActionContext=c,exports.useRangeContext=function(){return e.__assign(e.__assign({},l()),c())},exports.useRangeStateContext=l;
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 />\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","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","clickboxPoint","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,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EAAIY,KAAOH,EAAMG,KAG9C,OACEnB,EAAAA,2BACET,EAAAA,IACE,MAAA,CAAA6B,UAAW,mCACTC,OAAApB,EAAMqB,SAAW,gBAAkB,gBAErCC,MAAO,CACLC,IAAKT,EAASS,IACdC,KAAMV,EAASU,KACfC,MAAOX,EAASW,MAChBC,OAAQZ,EAASY,OACjBC,cAAe,UAGnBrC,EAAAA,IACE,MAAA,CAAA6B,UAAU,uBACVG,MAAO,CACLC,IAAKP,EAAkB,EACvBQ,KAAMR,EAAkB,EACxBS,MAAO,GACPC,OAAQ,GACRC,cAAe,YAKzB,qEA3EE,OAAAC,EAAAA,SAAAA,EAAAA,SAAA,CAAA,EAAYjD,KAA2BE,IACzC"}
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,EAAoBA,qBAC/BQ,SAAUR,EAAoBA,qBAC9BS,WAAYT,EAAoBA,qBAChCU,WAAYV,EAAoBA,qBAChCW,YAAaX,EAAoBA,qBACjCY,MAAOZ,EAAoBA,qBAC3Ba,SAAUb,EAAoBA,gCAGhBc,IACd,OAAOC,EAAAA,WAAWpB,EACpB,UAEgBqB,IACd,OAAOD,EAAAA,WAAWjB,EACpB,CAMA,SAASmB,IACC,IAAAlB,EAAWiB,WACbE,EACJC,EAA4BA,+BADtBC,EAAkBF,EAAAE,mBAAEC,EAAkBH,EAAAG,mBAU9C,OAPAC,EAAAA,WAAU,WACRvB,EAAO,CACLwB,YAAaH,EAAqB,EAClCI,YAAaH,EAAqB,GAEtC,GAAG,CAACD,EAAoBC,IAEjBI,oBACT,uBA6DM,SAAwBP,GAC5B,IAAAQ,EAAQR,EAAAQ,SAIFC,EAAqBC,EAAeA,kBAAlCC,EAAKF,EAAAE,MAAEC,EAAOH,EAAAG,QAEtB,OACEL,EAACM,IAAApC,EAAkBqC,SAAS,CAAAC,MAAOJ,EACjCH,SAAAQ,OAACpC,EAAmBkC,SAAQ,CAACC,MAAOH,EAAOJ,SAAA,CACzCD,MAACR,EAAe,CAAA,GACfS,MAIT,oBA1EM,SAAoBS,GACxB,IAAMN,EAAQf,IAmBd,GAjBAQ,EAAAA,WAAU,WACR,GAAIO,EAAMhC,YAAa,CACrB,IAAMuC,EAAaC,SAASC,eAC1BC,EAAAA,YAAYC,eAAeX,EAAMY,IAAIC,SAAUb,EAAMY,IAAIE,WAGvDP,IACFA,EAAWQ,eAAe,CACxBC,SAAU,SACVC,MAAO,UACPC,OAAQ,YAEVX,EAAWY,QAEd,CACH,GAAG,CAACnB,KAECA,EAAMhC,YACT,OAAO4B,qBAGD,IAAAwB,EAAyBpB,EAAKoB,SAApBC,EAAerB,EAAKqB,MAAbT,EAAQZ,MAOjC,OAJKqB,EAAMC,KAAOV,EAAIU,KAAOV,EAAIU,KAAOD,EAAMC,KACzCD,EAAME,KAAOX,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"),a=require("../libs/id-generator.js"),i=require("../range/provider.js"),n=r.memo((function(r){var n=i.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",{children:e.jsx(t.Checkbox,{row:l})}),r.cols.map((function(t,i){var n;return e.jsx(o.TableCell,{id:a.IdGenerator.getTableCellId(r.rowIndex,i),row:l,isExistOnClickRow:!!r.onClickRow,cellFormatClassName:c[i],editable:null!==(n=t.editable)&&void 0!==n&&n},t.key)}))]})}));exports.Row=n;
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