@teppen/react-ui 1.8.1 → 1.8.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/src/select-box/options-window/component.js +1 -1
- package/dist/cjs/src/select-box/options-window/component.js.map +1 -1
- package/dist/cjs/src/table/filter-v2/hook.js +1 -1
- package/dist/cjs/src/table/filter-v2/hook.js.map +1 -1
- package/dist/esm/src/select-box/options-window/component.js +1 -1
- package/dist/esm/src/select-box/options-window/component.js.map +1 -1
- package/dist/esm/src/table/filter-v2/hook.js +1 -1
- package/dist/esm/src/table/filter-v2/hook.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("./context.js"),o=require("../id/provider.js"),i=require("../lib/id-generator.js");exports.OptionsArea=function(){var r=o.useIdContext(),s=n.useOptionsWindow(),l=s.state,u=s.actions,a=t.useState(""),c=a[0],d=a[1],f=t.useState(void 0),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("./context.js"),o=require("../id/provider.js"),i=require("../lib/id-generator.js");exports.OptionsArea=function(){var r=o.useIdContext(),s=n.useOptionsWindow(),l=s.state,u=s.actions,a=t.useState(""),c=a[0],d=a[1],f=t.useState(void 0),v=f[0],p=f[1],m=t.useState({top:0,left:0}),g=m[0],y=m[1],h=l.isOpen?0===l.options.length?void 0:"number"==typeof v&&v<l.options.length&&v>=0?l.options[v].value:void 0:void 0;return t.useEffect((function(){if(l.isOpen){var e=document.getElementById(i.IdGenerator.generateIdSelectBoxOption(r,null!=h?h:""));if(!e)return;if(0===g.top&&0===g.left)return;e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}else p(void 0)}),[l,g,h]),t.useEffect((function(){if(l.isOpen){var e=function(e){if("ArrowDown"===e.key)e.preventDefault(),p((function(e){return"number"==typeof e?Math.min(e+1,l.options.length-1):0}));else if("ArrowUp"===e.key)e.preventDefault(),p((function(e){return"number"==typeof e?Math.max(e-1,0):0}));else if("Enter"===e.key&&(e.preventDefault(),"number"==typeof v)){if(0===l.options.length||l.options.length<=v)return;var t=l.options[v].value;if(!t)return;d(t),l.onSelect(t),u.closeOptionsWindow()}};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}}),[l,v,p]),t.useEffect((function(){var e=setTimeout((function(){var e;if(l.isOpen){for(var t=null===(e=document.getElementById("ReactUI:SelectBox:OptionsArea"))||void 0===e?void 0:e.parentElement,n=["relative","fixed","absolute","sticky"];t;){var o=n.some((function(e){return t.className.includes(e)})),i=n.some((function(e){return t.style.position.includes(e)}));if(o||i){console.log(t);break}t=t.parentElement}var r=document.getElementById(l.selectBoxId);if(r){var s=r.getBoundingClientRect(),u=s.top+s.height,a=s.left;if(t){var c=t.getBoundingClientRect();y({top:u-c.top,left:a-c.left})}else y({top:u+window.scrollY,left:a+window.scrollX})}}}),0);return function(){clearTimeout(e)}}),[l.isOpen]),t.useEffect((function(){var e=function(e){if(l.isOpen){var t=document.getElementById(l.selectBoxId),n=document.getElementById("ReactUI:SelectBox:OptionsArea"),o=e.target;o instanceof Node&&(null==t?void 0:t.contains(o))||o instanceof Node&&(null==n?void 0:n.contains(o))||(u.setSearchText(""),u.closeOptionsWindow())}};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[l.isOpen]),l.isOpen?e.jsx("div",{id:"ReactUI:SelectBox:OptionsArea",className:"absolute min-w-fit max-h-[40vh] overflow-auto border border-gray-300 z-10",style:g,children:l.options.map((function(t){var n,o;return e.jsx("div",{id:i.IdGenerator.generateIdSelectBoxOption(r,null!==(n=t.value)&&void 0!==n?n:""),className:"hover:bg-gray-200 px-2 py-1 ".concat("string"==typeof h?h===t.value?"bg-gray-100":"bg-white":c===t.value?"bg-gray-100":"bg-white"),onClick:function(){l.onSelect(t.value),u.closeOptionsWindow()},children:null!==(o=t.searchLabel)&&void 0!==o?o:t.label},t.value)}))}):e.jsx(e.Fragment,{})};
|
|
2
2
|
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../../../src/select-box/options-window/component.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { useOptionsWindow } from \"../options-window\";\nimport { useIdContext } from \"../id/provider\";\nimport { IdGenerator } from \"../lib\";\n\nexport function OptionsArea() {\n const id = useIdContext();\n const { state, actions } = useOptionsWindow();\n const [value, setValue] = useState(\"\");\n const [selectingIndex, setSelectingIndex] = useState<number | undefined>(\n undefined\n );\n const [position, setPosition] = useState({ top: 0, left: 0 });\n\n const selectingValue = state.isOpen\n ? state.options.length === 0\n ? undefined\n : typeof selectingIndex === \"number\" &&\n selectingIndex < state.options.length &&\n selectingIndex >= 0\n ? state.options[selectingIndex].value\n : undefined\n : undefined;\n\n useEffect(() => {\n if (state.isOpen) {\n const optionElement = document.getElementById(\n IdGenerator.generateIdSelectBoxOption(id, selectingValue ?? \"\")\n );\n\n if (!optionElement) return;\n if (position.top === 0 && position.left === 0) return;\n\n optionElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n } else {\n setSelectingIndex(undefined);\n }\n }, [state, position, selectingValue]);\n\n useEffect(() => {\n if (state.isOpen) {\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, state.options.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 if (\n state.options.length === 0 ||\n state.options.length <= selectingIndex\n )\n return;\n\n const value = state.options[selectingIndex].value;\n\n if (!value) return;\n\n setValue(value);\n state.onSelect(value);\n actions.closeOptionsWindow();\n }\n }\n };\n\n document.addEventListener(\"keydown\", handleKeydown);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeydown);\n };\n }\n }, [state, selectingIndex, setSelectingIndex]);\n\n useEffect(() => {\n const searchParentElement = () => {\n if (state.isOpen) {\n let parentElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n );\n\n while (parentElement) {\n if (parentElement.className.includes(\"relative\")) {\n break;\n }\n\n parentElement = parentElement.parentElement;\n }\n\n const selectBoxElement = document.getElementById(state.selectBoxId);\n\n if (selectBoxElement) {\n const rect = selectBoxElement.getBoundingClientRect();\n let top = rect.top + rect.height;\n let left = rect.left;\n\n if (parentElement) {\n const parentRect = parentElement.getBoundingClientRect();\n setPosition({\n top: top - parentRect.top,\n left: left - parentRect.left,\n });\n } else {\n setPosition({\n top: top + window.scrollY,\n left: left + window.scrollX,\n });\n }\n }\n }\n };\n\n const timer = setTimeout(searchParentElement, 0);\n\n return () => {\n clearTimeout(timer);\n };\n }, [state.isOpen]);\n\n useEffect(() => {\n const onClickOutOfSelectBox = (e: MouseEvent) => {\n if (!state.isOpen) return;\n\n // SelectBox関連の要素を取得\n const frameElement = document.getElementById(state.selectBoxId);\n const optionsElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n );\n\n // クリックされた要素を取得\n const ele = e.target;\n\n if (ele instanceof Node && frameElement?.contains(ele)) return;\n\n if (ele instanceof Node && optionsElement?.contains(ele)) return;\n\n actions.setSearchText(\"\");\n actions.closeOptionsWindow();\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfSelectBox);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfSelectBox);\n };\n }, [state.isOpen]);\n\n if (!state.isOpen) return <></>;\n\n return (\n <div\n id={\"ReactUI:SelectBox:OptionsArea\"}\n className=\"absolute min-w-fit max-h-[40vh] overflow-auto border border-gray-300 z-10\"\n style={position}\n >\n {state.options.map((option) => (\n <div\n id={IdGenerator.generateIdSelectBoxOption(id, option.value ?? \"\")}\n className={`hover:bg-gray-200 px-2 py-1 ${\n typeof selectingValue === \"string\"\n ? selectingValue === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n : value === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n }`}\n key={option.value}\n onClick={() => {\n state.onSelect(option.value);\n actions.closeOptionsWindow();\n }}\n >\n {option.searchLabel ?? option.label}\n </div>\n ))}\n </div>\n );\n}\n"],"names":["id","useIdContext","_a","useOptionsWindow","state","actions","_b","useState","value","setValue","_c","undefined","selectingIndex","setSelectingIndex","_d","top","left","position","setPosition","selectingValue","isOpen","options","length","useEffect","optionElement","document","getElementById","IdGenerator","generateIdSelectBoxOption","scrollIntoView","behavior","block","inline","handleKeydown_1","e","key","preventDefault","prev","Math","min","max","value_1","onSelect","closeOptionsWindow","addEventListener","removeEventListener","timer","setTimeout","parentElement","className","includes","selectBoxElement","selectBoxId","rect","getBoundingClientRect","top_1","height","parentRect","window","scrollY","scrollX","clearTimeout","onClickOutOfSelectBox","frameElement","optionsElement","ele","target","Node","contains","setSearchText","_jsx","style","map","option","jsx","concat","onClick","children","searchLabel","label"],"mappings":"+LAME,IAAMA,EAAKC,EAAAA,eACLC,EAAqBC,EAAgBA,mBAAnCC,EAAKF,EAAAE,MAAEC,EAAOH,EAAAG,QAChBC,EAAoBC,EAAAA,SAAS,IAA5BC,EAAKF,EAAA,GAAEG,EAAQH,EAAA,GAChBI,EAAsCH,EAAAA,cAC1CI,GADKC,EAAcF,EAAA,GAAEG,EAAiBH,EAAA,GAGlCI,EAA0BP,EAAAA,SAAS,CAAEQ,IAAK,EAAGC,KAAM,IAAlDC,OAAUC,OAEXC,EAAiBf,EAAMgB,OACA,IAAzBhB,EAAMiB,QAAQC,YACZX,EAC0B,iBAAnBC,GACPA,EAAiBR,EAAMiB,QAAQC,QAC/BV,GAAkB,EAClBR,EAAMiB,QAAQT,GAAgBJ,WAC9BG,OACFA,EAyIJ,OAvIAY,EAAAA,WAAU,WACR,GAAInB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,EAAOjE,MACjB,cACA,YAGNoE,QAAS,WACPxE,EAAMsC,SAAS+B,EAAOjE,OACtBH,EAAQsC,oBACV,EAECkC,SAAsB,QAAtBvE,EAAAmE,EAAOK,mBAAe,IAAAxE,EAAAA,EAAAmE,EAAOM,OANzBN,EAAOjE,MAQf,MA5BqB8D,oBA+B5B"}
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../../../src/select-box/options-window/component.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { useOptionsWindow } from \"../options-window\";\nimport { useIdContext } from \"../id/provider\";\nimport { IdGenerator } from \"../lib\";\n\nexport function OptionsArea() {\n const id = useIdContext();\n const { state, actions } = useOptionsWindow();\n const [value, setValue] = useState(\"\");\n const [selectingIndex, setSelectingIndex] = useState<number | undefined>(\n undefined\n );\n const [position, setPosition] = useState({ top: 0, left: 0 });\n\n const selectingValue = state.isOpen\n ? state.options.length === 0\n ? undefined\n : typeof selectingIndex === \"number\" &&\n selectingIndex < state.options.length &&\n selectingIndex >= 0\n ? state.options[selectingIndex].value\n : undefined\n : undefined;\n\n useEffect(() => {\n if (state.isOpen) {\n const optionElement = document.getElementById(\n IdGenerator.generateIdSelectBoxOption(id, selectingValue ?? \"\")\n );\n\n if (!optionElement) return;\n if (position.top === 0 && position.left === 0) return;\n\n optionElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n } else {\n setSelectingIndex(undefined);\n }\n }, [state, position, selectingValue]);\n\n useEffect(() => {\n if (state.isOpen) {\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, state.options.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 if (\n state.options.length === 0 ||\n state.options.length <= selectingIndex\n )\n return;\n\n const value = state.options[selectingIndex].value;\n\n if (!value) return;\n\n setValue(value);\n state.onSelect(value);\n actions.closeOptionsWindow();\n }\n }\n };\n\n document.addEventListener(\"keydown\", handleKeydown);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeydown);\n };\n }\n }, [state, selectingIndex, setSelectingIndex]);\n\n useEffect(() => {\n const searchParentElement = () => {\n if (state.isOpen) {\n let parentElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n )?.parentElement;\n\n const positionClasses = [\"relative\", \"fixed\", \"absolute\", \"sticky\"];\n\n while (parentElement) {\n const hasPositionClass = positionClasses.some((className) =>\n parentElement!.className.includes(className)\n );\n\n const hasPositionStyle = positionClasses.some((style) =>\n parentElement!.style.position.includes(style)\n );\n\n if (hasPositionClass || hasPositionStyle) {\n console.log(parentElement);\n break;\n }\n\n parentElement = parentElement.parentElement;\n }\n\n const selectBoxElement = document.getElementById(state.selectBoxId);\n\n if (selectBoxElement) {\n const rect = selectBoxElement.getBoundingClientRect();\n let top = rect.top + rect.height;\n let left = rect.left;\n\n if (parentElement) {\n const parentRect = parentElement.getBoundingClientRect();\n setPosition({\n top: top - parentRect.top,\n left: left - parentRect.left,\n });\n } else {\n setPosition({\n top: top + window.scrollY,\n left: left + window.scrollX,\n });\n }\n }\n }\n };\n\n const timer = setTimeout(searchParentElement, 0);\n\n return () => {\n clearTimeout(timer);\n };\n }, [state.isOpen]);\n\n useEffect(() => {\n const onClickOutOfSelectBox = (e: MouseEvent) => {\n if (!state.isOpen) return;\n\n // SelectBox関連の要素を取得\n const frameElement = document.getElementById(state.selectBoxId);\n const optionsElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n );\n\n // クリックされた要素を取得\n const ele = e.target;\n\n if (ele instanceof Node && frameElement?.contains(ele)) return;\n\n if (ele instanceof Node && optionsElement?.contains(ele)) return;\n\n actions.setSearchText(\"\");\n actions.closeOptionsWindow();\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfSelectBox);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfSelectBox);\n };\n }, [state.isOpen]);\n\n if (!state.isOpen) return <></>;\n\n return (\n <div\n id={\"ReactUI:SelectBox:OptionsArea\"}\n className=\"absolute min-w-fit max-h-[40vh] overflow-auto border border-gray-300 z-10\"\n style={position}\n >\n {state.options.map((option) => (\n <div\n id={IdGenerator.generateIdSelectBoxOption(id, option.value ?? \"\")}\n className={`hover:bg-gray-200 px-2 py-1 ${\n typeof selectingValue === \"string\"\n ? selectingValue === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n : value === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n }`}\n key={option.value}\n onClick={() => {\n state.onSelect(option.value);\n actions.closeOptionsWindow();\n }}\n >\n {option.searchLabel ?? option.label}\n </div>\n ))}\n </div>\n );\n}\n"],"names":["id","useIdContext","_a","useOptionsWindow","state","actions","_b","useState","value","setValue","_c","undefined","selectingIndex","setSelectingIndex","_d","top","left","position","setPosition","selectingValue","isOpen","options","length","useEffect","optionElement","document","getElementById","IdGenerator","generateIdSelectBoxOption","scrollIntoView","behavior","block","inline","handleKeydown_1","e","key","preventDefault","prev","Math","min","max","value_1","onSelect","closeOptionsWindow","addEventListener","removeEventListener","timer","setTimeout","parentElement_1","parentElement","positionClasses","hasPositionClass","some","className","includes","hasPositionStyle","style","console","log","selectBoxElement","selectBoxId","rect","getBoundingClientRect","top_1","height","parentRect","window","scrollY","scrollX","clearTimeout","onClickOutOfSelectBox","frameElement","optionsElement","ele","target","Node","contains","setSearchText","_jsx","map","option","jsx","concat","onClick","children","searchLabel","label"],"mappings":"+LAME,IAAMA,EAAKC,EAAAA,eACLC,EAAqBC,EAAgBA,mBAAnCC,EAAKF,EAAAE,MAAEC,EAAOH,EAAAG,QAChBC,EAAoBC,EAAAA,SAAS,IAA5BC,EAAKF,EAAA,GAAEG,EAAQH,EAAA,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,aAC7CY,EAAiB/C,SAASC,eAC9B,iCAII+C,EAAMvC,EAAEwC,OAEVD,aAAeE,OAAQJ,aAAA,EAAAA,EAAcK,SAASH,KAE9CA,aAAeE,OAAQH,aAAA,EAAAA,EAAgBI,SAASH,MAEpDpE,EAAQwE,cAAc,IACtBxE,EAAQsC,qBAhBkB,CAiB5B,EAIA,OAFAlB,SAASmB,iBAAiB,YAAa0B,GAEhC,WACL7C,SAASoB,oBAAoB,YAAayB,EAC5C,CACF,GAAG,CAAClE,EAAMgB,SAELhB,EAAMgB,OAGT0D,EAAAA,WACE9E,GAAI,gCACJqD,UAAU,4EACVG,MAAOvC,WAENb,EAAMiB,QAAQ0D,KAAI,SAACC,WAAW,OAC7BF,EACEG,IAAA,MAAA,CAAAjF,GAAI2B,EAAAA,YAAYC,0BAA0B5B,EAAgB,QAAZE,EAAA8E,EAAOxE,aAAK,IAAAN,EAAAA,EAAI,IAC9DmD,UAAW,+BACT6B,OAA0B,iBAAnB/D,EACHA,IAAmB6D,EAAOxE,MACxB,cACA,WACFA,IAAUwE,EAAOxE,MACjB,cACA,YAGN2E,QAAS,WACP/E,EAAMsC,SAASsC,EAAOxE,OACtBH,EAAQsC,oBACV,EAECyC,SAAsB,QAAtB9E,EAAA0E,EAAOK,mBAAe,IAAA/E,EAAAA,EAAA0E,EAAOM,OANzBN,EAAOxE,MAQf,MA5BqBsE,oBA+B5B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=require("./reducer.js");exports.useFilterHook=function(r){var n=e.useReducer(t.filterReducer,{conditions:r}),i=n[0],o=n[1],u=e.useMemo((function(){return{addFilter:function(e){o({type:"add",payload:{condition:e}})},removeFilter:function(e){o({type:"remove",payload:{index:e}})},clearFilter:function(){o({type:"clear"})}}}),[i.conditions]),s=e.useMemo((function(){return{filter:function(e){return e.filter((function(e){return i.conditions.every((function(t){return function(e,t,r){switch(e.operator.type){case"number":if("single number"===e.operator.inputType){if(r.type!==e.operator.inputType)throw new Error("input type is not match");var n=r.payload.value;switch(e.operator.key){case"number:eq":return t===n;case"number:gt":return t>n;case"number:gte":return t>=n;case"number:lt":return t<n;case"number:lte":return t<=n;case"number:neq":return t!==n}}case"string":switch(e.operator.inputType){case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"string:is_not_null":return null!=t&&""!==t;case"string:is_null":return null==t||""===t}case"single string":if(r.type!==e.operator.inputType)throw new Error("input type is not match");var i=r.payload.value;switch(e.operator.key){case"string:eq":return t===i;case"string:like":return t.includes(i);case"string:neq":return t!==i;case"string:not_like":return!t.includes(i)}}case"select":switch(e.operator.inputType){case"select":if(r.type!==e.operator.inputType)throw new Error("input type is not match");i=r.payload.value;switch(e.operator.key){case"select:eq":return t===i;case"select:neq":return t!==i}case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"select:is_null":return null==t||""===t;case"select:is_not_null":return null!=t
|
|
1
|
+
"use strict";var e=require("react"),t=require("./reducer.js");exports.useFilterHook=function(r){var n=e.useReducer(t.filterReducer,{conditions:r}),i=n[0],o=n[1],u=e.useMemo((function(){return{addFilter:function(e){o({type:"add",payload:{condition:e}})},removeFilter:function(e){o({type:"remove",payload:{index:e}})},clearFilter:function(){o({type:"clear"})}}}),[i.conditions]),s=e.useMemo((function(){return{filter:function(e){return e.filter((function(e){return i.conditions.every((function(t){return function(e,t,r){switch(e.operator.type){case"number":if("single number"===e.operator.inputType){if(r.type!==e.operator.inputType)throw new Error("input type is not match");var n=r.payload.value;switch(e.operator.key){case"number:eq":return t===n;case"number:gt":return t>n;case"number:gte":return t>=n;case"number:lt":return t<n;case"number:lte":return t<=n;case"number:neq":return t!==n}}case"string":switch(e.operator.inputType){case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"string:is_not_null":return null!=t&&""!==t;case"string:is_null":return null==t||""===t}case"single string":if(r.type!==e.operator.inputType)throw new Error("input type is not match");var i=r.payload.value;switch(e.operator.key){case"string:eq":return t===i;case"string:like":return t.includes(i);case"string:neq":return t!==i;case"string:not_like":return!t.includes(i)}}case"select":switch(e.operator.inputType){case"select":if(r.type!==e.operator.inputType)throw new Error("input type is not match");i=r.payload.value;switch(e.operator.key){case"select:eq":return t===i;case"select:neq":return t!==i}case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"select:is_null":return null==t||""===t;case"select:is_not_null":return null!=t&&""!==t}}}}(t,e[t.target.key],t.input)}))}))}}}),[i.conditions]);return{state:i,actions:u,functions:s}};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../../src/table/filter-v2/hook.ts"],"sourcesContent":["import { useMemo, useReducer } from \"react\";\nimport { TFilterHook } from \"./type\";\nimport { filterReducer } from \"./reducer\";\nimport { Condition } from \"../../search-bar\";\nimport { DataObject, DataRecord } from \"../table/type\";\nimport { SearchInput } from \"../../search-bar/condition-search-bar/condition-input-management/type\";\n\nexport const useFilterHook: TFilterHook = (initialConditions) => {\n const [state, dispatch] = useReducer(filterReducer, {\n conditions: initialConditions,\n });\n\n const actions = useMemo(\n () => ({\n addFilter: (condition: Condition) => {\n dispatch({ type: \"add\", payload: { condition } });\n },\n removeFilter: (index: number) => {\n dispatch({ type: \"remove\", payload: { index } });\n },\n clearFilter: () => {\n dispatch({ type: \"clear\" });\n },\n }),\n [state.conditions]\n );\n\n const functions = useMemo(\n () => ({\n filter: <T extends DataRecord>(rows: DataObject<T>[]) => {\n return rows.filter((row) => {\n return state.conditions.every((condition) => {\n const value = row[condition.target.key];\n return isMatchCondition(condition, value, condition.input);\n });\n });\n },\n }),\n [state.conditions]\n );\n\n return {\n state,\n actions,\n functions,\n };\n};\n\nfunction isMatchCondition(\n condition: Condition,\n targetValue: any,\n input: SearchInput\n): boolean {\n switch (condition.operator.type) {\n // case \"date\":\n // switch (condition.operator.key) {\n // case \"date:eq\":\n // return false;\n // case \"date:gt\":\n // return false;\n // case \"date:gte\":\n // return false;\n // case \"date:lt\":\n // return false;\n // case \"date:lte\":\n // return false;\n // case \"date:neq\":\n // return false;\n // case \"date:is_not_null\":\n // return false;\n // case \"date:is_null\":\n // return false;\n // }\n case \"number\":\n switch (condition.operator.inputType) {\n case \"single number\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const numValue = input.payload.value;\n\n switch (condition.operator.key) {\n case \"number:eq\":\n return targetValue === numValue;\n case \"number:gt\":\n return targetValue > numValue;\n case \"number:gte\":\n return targetValue >= numValue;\n case \"number:lt\":\n return targetValue < numValue;\n case \"number:lte\":\n return targetValue <= numValue;\n case \"number:neq\":\n return targetValue !== numValue;\n }\n }\n\n case \"string\":\n switch (condition.operator.inputType) {\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"string:is_not_null\":\n return (\n targetValue !== null &&\n targetValue !== undefined &&\n targetValue !== \"\"\n );\n case \"string:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n }\n case \"single string\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"string:eq\":\n return targetValue === value;\n case \"string:like\":\n return targetValue.includes(value);\n case \"string:neq\":\n return targetValue !== value;\n case \"string:not_like\":\n return !targetValue.includes(value);\n }\n }\n\n case \"select\":\n switch (condition.operator.inputType) {\n case \"select\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"select:eq\":\n return targetValue === value;\n case \"select:neq\":\n return targetValue !== value;\n }\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"select:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n case \"select:is_not_null\":\n return (\n
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../../src/table/filter-v2/hook.ts"],"sourcesContent":["import { useMemo, useReducer } from \"react\";\nimport { TFilterHook } from \"./type\";\nimport { filterReducer } from \"./reducer\";\nimport { Condition } from \"../../search-bar\";\nimport { DataObject, DataRecord } from \"../table/type\";\nimport { SearchInput } from \"../../search-bar/condition-search-bar/condition-input-management/type\";\n\nexport const useFilterHook: TFilterHook = (initialConditions) => {\n const [state, dispatch] = useReducer(filterReducer, {\n conditions: initialConditions,\n });\n\n const actions = useMemo(\n () => ({\n addFilter: (condition: Condition) => {\n dispatch({ type: \"add\", payload: { condition } });\n },\n removeFilter: (index: number) => {\n dispatch({ type: \"remove\", payload: { index } });\n },\n clearFilter: () => {\n dispatch({ type: \"clear\" });\n },\n }),\n [state.conditions]\n );\n\n const functions = useMemo(\n () => ({\n filter: <T extends DataRecord>(rows: DataObject<T>[]) => {\n return rows.filter((row) => {\n return state.conditions.every((condition) => {\n const value = row[condition.target.key];\n return isMatchCondition(condition, value, condition.input);\n });\n });\n },\n }),\n [state.conditions]\n );\n\n return {\n state,\n actions,\n functions,\n };\n};\n\nfunction isMatchCondition(\n condition: Condition,\n targetValue: any,\n input: SearchInput\n): boolean {\n switch (condition.operator.type) {\n // case \"date\":\n // switch (condition.operator.key) {\n // case \"date:eq\":\n // return false;\n // case \"date:gt\":\n // return false;\n // case \"date:gte\":\n // return false;\n // case \"date:lt\":\n // return false;\n // case \"date:lte\":\n // return false;\n // case \"date:neq\":\n // return false;\n // case \"date:is_not_null\":\n // return false;\n // case \"date:is_null\":\n // return false;\n // }\n case \"number\":\n switch (condition.operator.inputType) {\n case \"single number\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const numValue = input.payload.value;\n\n switch (condition.operator.key) {\n case \"number:eq\":\n return targetValue === numValue;\n case \"number:gt\":\n return targetValue > numValue;\n case \"number:gte\":\n return targetValue >= numValue;\n case \"number:lt\":\n return targetValue < numValue;\n case \"number:lte\":\n return targetValue <= numValue;\n case \"number:neq\":\n return targetValue !== numValue;\n }\n }\n\n case \"string\":\n switch (condition.operator.inputType) {\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"string:is_not_null\":\n return (\n targetValue !== null &&\n targetValue !== undefined &&\n targetValue !== \"\"\n );\n case \"string:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n }\n case \"single string\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"string:eq\":\n return targetValue === value;\n case \"string:like\":\n return targetValue.includes(value);\n case \"string:neq\":\n return targetValue !== value;\n case \"string:not_like\":\n return !targetValue.includes(value);\n }\n }\n\n case \"select\":\n switch (condition.operator.inputType) {\n case \"select\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"select:eq\":\n return targetValue === value;\n case \"select:neq\":\n return targetValue !== value;\n }\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"select:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n case \"select:is_not_null\":\n return (\n targetValue !== null &&\n targetValue !== undefined &&\n targetValue !== \"\"\n );\n }\n }\n }\n}\n"],"names":["initialConditions","_a","useReducer","filterReducer","conditions","state","dispatch","actions","useMemo","addFilter","condition","type","payload","removeFilter","index","clearFilter","functions","filter","rows","row","every","targetValue","input","operator","inputType","Error","numValue","value","key","includes","isMatchCondition","target"],"mappings":"oFAO0C,SAACA,GACnC,IAAAC,EAAoBC,EAAUA,WAACC,gBAAe,CAClDC,WAAYJ,IADPK,EAAKJ,EAAA,GAAEK,OAIRC,EAAUC,WACd,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ASF,GAC9B,IAAK,aACH,OAAON,IAAgBM,EACzB,IAAK,kBACH,OAAQN,EAAYQ,SAASF,IAIvC,IAAK,SACH,OAAQjB,EAAUa,SAASC,WACzB,IAAK,SACH,GAAIF,EAAMX,OAASD,EAAUa,SAASC,UACpC,MAAM,IAAIC,MAAM,2BAGZE,EAAQL,EAAMV,QAAQe,MAE5B,OAAQjB,EAAUa,SAASK,KACzB,IAAK,YACH,OAAOP,IAAgBM,EACzB,IAAK,aACH,OAAON,IAAgBM,EAE7B,IAAK,OACH,GAAIL,EAAMX,OAASD,EAAUa,SAASC,UACpC,MAAM,IAAIC,MAAM,2BAGlB,OAAQf,EAAUa,SAASK,KACzB,IAAK,iBACH,OACEP,SAEgB,KAAhBA,EAEJ,IAAK,qBACH,OACEA,SAEgB,KAAhBA,IAKhB,CA7ImBS,CAAiBpB,EADVS,EAAIT,EAAUqB,OAAOH,KACOlB,EAAUY,MACtD,GACF,GACD,KAEH,CAACjB,EAAMD,aAGT,MAAO,CACLC,MAAKA,EACLE,QAAOA,EACPS,UAASA,EAEb"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useState as n,useEffect as o}from"react";import{useOptionsWindow as i}from"./context.js";import{useIdContext as r}from"../id/provider.js";import{IdGenerator as l}from"../lib/id-generator.js";function a(){var a=r(),s=i(),
|
|
1
|
+
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useState as n,useEffect as o}from"react";import{useOptionsWindow as i}from"./context.js";import{useIdContext as r}from"../id/provider.js";import{IdGenerator as l}from"../lib/id-generator.js";function a(){var a=r(),s=i(),u=s.state,c=s.actions,d=n(""),f=d[0],p=d[1],v=n(void 0),m=v[0],g=v[1],y=n({top:0,left:0}),h=y[0],b=y[1],w=u.isOpen?0===u.options.length?void 0:"number"==typeof m&&m<u.options.length&&m>=0?u.options[m].value:void 0:void 0;return o((function(){if(u.isOpen){var e=document.getElementById(l.generateIdSelectBoxOption(a,null!=w?w:""));if(!e)return;if(0===h.top&&0===h.left)return;e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"})}else g(void 0)}),[u,h,w]),o((function(){if(u.isOpen){var e=function(e){if("ArrowDown"===e.key)e.preventDefault(),g((function(e){return"number"==typeof e?Math.min(e+1,u.options.length-1):0}));else if("ArrowUp"===e.key)e.preventDefault(),g((function(e){return"number"==typeof e?Math.max(e-1,0):0}));else if("Enter"===e.key&&(e.preventDefault(),"number"==typeof m)){if(0===u.options.length||u.options.length<=m)return;var t=u.options[m].value;if(!t)return;p(t),u.onSelect(t),c.closeOptionsWindow()}};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}}),[u,m,g]),o((function(){var e=setTimeout((function(){var e;if(u.isOpen){for(var t=null===(e=document.getElementById("ReactUI:SelectBox:OptionsArea"))||void 0===e?void 0:e.parentElement,n=["relative","fixed","absolute","sticky"];t;){var o=n.some((function(e){return t.className.includes(e)})),i=n.some((function(e){return t.style.position.includes(e)}));if(o||i){console.log(t);break}t=t.parentElement}var r=document.getElementById(u.selectBoxId);if(r){var l=r.getBoundingClientRect(),a=l.top+l.height,s=l.left;if(t){var c=t.getBoundingClientRect();b({top:a-c.top,left:s-c.left})}else b({top:a+window.scrollY,left:s+window.scrollX})}}}),0);return function(){clearTimeout(e)}}),[u.isOpen]),o((function(){var e=function(e){if(u.isOpen){var t=document.getElementById(u.selectBoxId),n=document.getElementById("ReactUI:SelectBox:OptionsArea"),o=e.target;o instanceof Node&&(null==t?void 0:t.contains(o))||o instanceof Node&&(null==n?void 0:n.contains(o))||(c.setSearchText(""),c.closeOptionsWindow())}};return document.addEventListener("mousedown",e),function(){document.removeEventListener("mousedown",e)}}),[u.isOpen]),u.isOpen?e("div",{id:"ReactUI:SelectBox:OptionsArea",className:"absolute min-w-fit max-h-[40vh] overflow-auto border border-gray-300 z-10",style:h,children:u.options.map((function(t){var n,o;return e("div",{id:l.generateIdSelectBoxOption(a,null!==(n=t.value)&&void 0!==n?n:""),className:"hover:bg-gray-200 px-2 py-1 ".concat("string"==typeof w?w===t.value?"bg-gray-100":"bg-white":f===t.value?"bg-gray-100":"bg-white"),onClick:function(){u.onSelect(t.value),c.closeOptionsWindow()},children:null!==(o=t.searchLabel)&&void 0!==o?o:t.label},t.value)}))}):e(t,{})}export{a as OptionsArea};
|
|
2
2
|
//# sourceMappingURL=component.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../../../../src/select-box/options-window/component.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { useOptionsWindow } from \"../options-window\";\nimport { useIdContext } from \"../id/provider\";\nimport { IdGenerator } from \"../lib\";\n\nexport function OptionsArea() {\n const id = useIdContext();\n const { state, actions } = useOptionsWindow();\n const [value, setValue] = useState(\"\");\n const [selectingIndex, setSelectingIndex] = useState<number | undefined>(\n undefined\n );\n const [position, setPosition] = useState({ top: 0, left: 0 });\n\n const selectingValue = state.isOpen\n ? state.options.length === 0\n ? undefined\n : typeof selectingIndex === \"number\" &&\n selectingIndex < state.options.length &&\n selectingIndex >= 0\n ? state.options[selectingIndex].value\n : undefined\n : undefined;\n\n useEffect(() => {\n if (state.isOpen) {\n const optionElement = document.getElementById(\n IdGenerator.generateIdSelectBoxOption(id, selectingValue ?? \"\")\n );\n\n if (!optionElement) return;\n if (position.top === 0 && position.left === 0) return;\n\n optionElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n } else {\n setSelectingIndex(undefined);\n }\n }, [state, position, selectingValue]);\n\n useEffect(() => {\n if (state.isOpen) {\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, state.options.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 if (\n state.options.length === 0 ||\n state.options.length <= selectingIndex\n )\n return;\n\n const value = state.options[selectingIndex].value;\n\n if (!value) return;\n\n setValue(value);\n state.onSelect(value);\n actions.closeOptionsWindow();\n }\n }\n };\n\n document.addEventListener(\"keydown\", handleKeydown);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeydown);\n };\n }\n }, [state, selectingIndex, setSelectingIndex]);\n\n useEffect(() => {\n const searchParentElement = () => {\n if (state.isOpen) {\n let parentElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n );\n\n while (parentElement) {\n if (parentElement.className.includes(\"relative\")) {\n break;\n }\n\n parentElement = parentElement.parentElement;\n }\n\n const selectBoxElement = document.getElementById(state.selectBoxId);\n\n if (selectBoxElement) {\n const rect = selectBoxElement.getBoundingClientRect();\n let top = rect.top + rect.height;\n let left = rect.left;\n\n if (parentElement) {\n const parentRect = parentElement.getBoundingClientRect();\n setPosition({\n top: top - parentRect.top,\n left: left - parentRect.left,\n });\n } else {\n setPosition({\n top: top + window.scrollY,\n left: left + window.scrollX,\n });\n }\n }\n }\n };\n\n const timer = setTimeout(searchParentElement, 0);\n\n return () => {\n clearTimeout(timer);\n };\n }, [state.isOpen]);\n\n useEffect(() => {\n const onClickOutOfSelectBox = (e: MouseEvent) => {\n if (!state.isOpen) return;\n\n // SelectBox関連の要素を取得\n const frameElement = document.getElementById(state.selectBoxId);\n const optionsElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n );\n\n // クリックされた要素を取得\n const ele = e.target;\n\n if (ele instanceof Node && frameElement?.contains(ele)) return;\n\n if (ele instanceof Node && optionsElement?.contains(ele)) return;\n\n actions.setSearchText(\"\");\n actions.closeOptionsWindow();\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfSelectBox);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfSelectBox);\n };\n }, [state.isOpen]);\n\n if (!state.isOpen) return <></>;\n\n return (\n <div\n id={\"ReactUI:SelectBox:OptionsArea\"}\n className=\"absolute min-w-fit max-h-[40vh] overflow-auto border border-gray-300 z-10\"\n style={position}\n >\n {state.options.map((option) => (\n <div\n id={IdGenerator.generateIdSelectBoxOption(id, option.value ?? \"\")}\n className={`hover:bg-gray-200 px-2 py-1 ${\n typeof selectingValue === \"string\"\n ? selectingValue === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n : value === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n }`}\n key={option.value}\n onClick={() => {\n state.onSelect(option.value);\n actions.closeOptionsWindow();\n }}\n >\n {option.searchLabel ?? option.label}\n </div>\n ))}\n </div>\n );\n}\n"],"names":["OptionsArea","id","useIdContext","_a","useOptionsWindow","state","actions","_b","useState","value","setValue","_c","undefined","selectingIndex","setSelectingIndex","_d","top","left","position","setPosition","selectingValue","isOpen","options","length","useEffect","optionElement","document","getElementById","IdGenerator","generateIdSelectBoxOption","scrollIntoView","behavior","block","inline","handleKeydown_1","e","key","preventDefault","prev","Math","min","max","value_1","onSelect","closeOptionsWindow","addEventListener","removeEventListener","timer","setTimeout","parentElement","className","includes","selectBoxElement","selectBoxId","rect","getBoundingClientRect","top_1","height","parentRect","window","scrollY","scrollX","clearTimeout","onClickOutOfSelectBox","frameElement","optionsElement","ele","target","Node","contains","setSearchText","_jsx","style","map","option","concat","onClick","children","searchLabel","label"],"mappings":"qQAKgBA,IACd,IAAMC,EAAKC,IACLC,EAAqBC,IAAnBC,EAAKF,EAAAE,MAAEC,EAAOH,EAAAG,QAChBC,EAAoBC,EAAS,IAA5BC,EAAKF,EAAA,GAAEG,EAAQH,EAAA,GAChBI,EAAsCH,OAC1CI,GADKC,EAAcF,EAAA,GAAEG,EAAiBH,EAAA,GAGlCI,EAA0BP,EAAS,CAAEQ,IAAK,EAAGC,KAAM,IAAlDC,OAAUC,OAEXC,EAAiBf,EAAMgB,OACA,IAAzBhB,EAAMiB,QAAQ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AAAA,EAAI,IAC9D+C,UAAW,+BACTyB,OAA0B,iBAAnBvD,EACHA,IAAmBsD,EAAOjE,MACxB,cACA,WACFA,IAAUiE,EAAOjE,MACjB,cACA,YAGNmE,QAAS,WACPvE,EAAMsC,SAAS+B,EAAOjE,OACtBH,EAAQsC,oBACV,EAECiC,SAAsB,QAAtBtE,EAAAmE,EAAOI,mBAAe,IAAAvE,EAAAA,EAAAmE,EAAOK,OANzBL,EAAOjE,MAQf,MA5BqB8D,OA+B5B"}
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../../../../src/select-box/options-window/component.tsx"],"sourcesContent":["import { useEffect, useRef, useState } from \"react\";\nimport { useOptionsWindow } from \"../options-window\";\nimport { useIdContext } from \"../id/provider\";\nimport { IdGenerator } from \"../lib\";\n\nexport function OptionsArea() {\n const id = useIdContext();\n const { state, actions } = useOptionsWindow();\n const [value, setValue] = useState(\"\");\n const [selectingIndex, setSelectingIndex] = useState<number | undefined>(\n undefined\n );\n const [position, setPosition] = useState({ top: 0, left: 0 });\n\n const selectingValue = state.isOpen\n ? state.options.length === 0\n ? undefined\n : typeof selectingIndex === \"number\" &&\n selectingIndex < state.options.length &&\n selectingIndex >= 0\n ? state.options[selectingIndex].value\n : undefined\n : undefined;\n\n useEffect(() => {\n if (state.isOpen) {\n const optionElement = document.getElementById(\n IdGenerator.generateIdSelectBoxOption(id, selectingValue ?? \"\")\n );\n\n if (!optionElement) return;\n if (position.top === 0 && position.left === 0) return;\n\n optionElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n } else {\n setSelectingIndex(undefined);\n }\n }, [state, position, selectingValue]);\n\n useEffect(() => {\n if (state.isOpen) {\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, state.options.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 if (\n state.options.length === 0 ||\n state.options.length <= selectingIndex\n )\n return;\n\n const value = state.options[selectingIndex].value;\n\n if (!value) return;\n\n setValue(value);\n state.onSelect(value);\n actions.closeOptionsWindow();\n }\n }\n };\n\n document.addEventListener(\"keydown\", handleKeydown);\n\n return () => {\n document.removeEventListener(\"keydown\", handleKeydown);\n };\n }\n }, [state, selectingIndex, setSelectingIndex]);\n\n useEffect(() => {\n const searchParentElement = () => {\n if (state.isOpen) {\n let parentElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n )?.parentElement;\n\n const positionClasses = [\"relative\", \"fixed\", \"absolute\", \"sticky\"];\n\n while (parentElement) {\n const hasPositionClass = positionClasses.some((className) =>\n parentElement!.className.includes(className)\n );\n\n const hasPositionStyle = positionClasses.some((style) =>\n parentElement!.style.position.includes(style)\n );\n\n if (hasPositionClass || hasPositionStyle) {\n console.log(parentElement);\n break;\n }\n\n parentElement = parentElement.parentElement;\n }\n\n const selectBoxElement = document.getElementById(state.selectBoxId);\n\n if (selectBoxElement) {\n const rect = selectBoxElement.getBoundingClientRect();\n let top = rect.top + rect.height;\n let left = rect.left;\n\n if (parentElement) {\n const parentRect = parentElement.getBoundingClientRect();\n setPosition({\n top: top - parentRect.top,\n left: left - parentRect.left,\n });\n } else {\n setPosition({\n top: top + window.scrollY,\n left: left + window.scrollX,\n });\n }\n }\n }\n };\n\n const timer = setTimeout(searchParentElement, 0);\n\n return () => {\n clearTimeout(timer);\n };\n }, [state.isOpen]);\n\n useEffect(() => {\n const onClickOutOfSelectBox = (e: MouseEvent) => {\n if (!state.isOpen) return;\n\n // SelectBox関連の要素を取得\n const frameElement = document.getElementById(state.selectBoxId);\n const optionsElement = document.getElementById(\n \"ReactUI:SelectBox:OptionsArea\"\n );\n\n // クリックされた要素を取得\n const ele = e.target;\n\n if (ele instanceof Node && frameElement?.contains(ele)) return;\n\n if (ele instanceof Node && optionsElement?.contains(ele)) return;\n\n actions.setSearchText(\"\");\n actions.closeOptionsWindow();\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfSelectBox);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfSelectBox);\n };\n }, [state.isOpen]);\n\n if (!state.isOpen) return <></>;\n\n return (\n <div\n id={\"ReactUI:SelectBox:OptionsArea\"}\n className=\"absolute min-w-fit max-h-[40vh] overflow-auto border border-gray-300 z-10\"\n style={position}\n >\n {state.options.map((option) => (\n <div\n id={IdGenerator.generateIdSelectBoxOption(id, option.value ?? \"\")}\n className={`hover:bg-gray-200 px-2 py-1 ${\n typeof selectingValue === \"string\"\n ? selectingValue === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n : value === option.value\n ? \"bg-gray-100\"\n : \"bg-white\"\n }`}\n key={option.value}\n onClick={() => {\n state.onSelect(option.value);\n actions.closeOptionsWindow();\n }}\n >\n {option.searchLabel ?? option.label}\n </div>\n ))}\n </div>\n );\n}\n"],"names":["OptionsArea","id","useIdContext","_a","useOptionsWindow","state","actions","_b","useState","value","setValue","_c","undefined","selectingIndex","setSelectingIndex","_d","top","left","position","setPosition","selectingValue","isOpen","options","length","useEffect","optionElement","document","getElementById","IdGenerator","generateIdSelectBoxOption","scrollIntoView","behavior","block","inline","handleKeydown_1","e","key","preventDefault","prev","Math","min","max","value_1","onSelect","closeOptionsWindow","addEventListener","removeEventListener","timer","setTimeout","parentElement_1","parentElement","positionClasses","hasPositionClass","some","className","includes","hasPositionStyle","style","console","log","selectBoxElement","selectBoxId","rect","getBoundingClientRect","top_1","height","parentRect","window","scrollY","scrollX","clearTimeout","onClickOutOfSelectBox","frameElement","optionsElement","ele","target","Node","contains","setSearchText","_jsx","map","option","concat","onClick","children","searchLabel","label"],"mappings":"qQAKgBA,IACd,IAAMC,EAAKC,IACLC,EAAqBC,IAAnBC,EAAKF,EAA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A,IAAMmD,EAAe9C,SAASC,eAAetB,EAAMwD,aAC7CY,EAAiB/C,SAASC,eAC9B,iCAII+C,EAAMvC,EAAEwC,OAEVD,aAAeE,OAAQJ,aAAA,EAAAA,EAAcK,SAASH,KAE9CA,aAAeE,OAAQH,aAAA,EAAAA,EAAgBI,SAASH,MAEpDpE,EAAQwE,cAAc,IACtBxE,EAAQsC,qBAhBkB,CAiB5B,EAIA,OAFAlB,SAASmB,iBAAiB,YAAa0B,GAEhC,WACL7C,SAASoB,oBAAoB,YAAayB,EAC5C,CACF,GAAG,CAAClE,EAAMgB,SAELhB,EAAMgB,OAGT0D,SACE9E,GAAI,gCACJqD,UAAU,4EACVG,MAAOvC,WAENb,EAAMiB,QAAQ0D,KAAI,SAACC,WAAW,OAC7BF,EACE,MAAA,CAAA9E,GAAI2B,EAAYC,0BAA0B5B,EAAgB,QAAZE,EAAA8E,EAAOxE,aAAK,IAAAN,EAAAA,EAAI,IAC9DmD,UAAW,+BACT4B,OAA0B,iBAAnB9D,EACHA,IAAmB6D,EAAOxE,MACxB,cACA,WACFA,IAAUwE,EAAOxE,MACjB,cACA,YAGN0E,QAAS,WACP9E,EAAMsC,SAASsC,EAAOxE,OACtBH,EAAQsC,oBACV,EAECwC,SAAsB,QAAtB7E,EAAA0E,EAAOI,mBAAe,IAAA9E,EAAAA,EAAA0E,EAAOK,OANzBL,EAAOxE,MAQf,MA5BqBsE,OA+B5B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useReducer as e,useMemo as t}from"react";import{filterReducer as r}from"./reducer.js";var n=function(n){var o=e(r,{conditions:n}),i=o[0],u=o[1],a=t((function(){return{addFilter:function(e){u({type:"add",payload:{condition:e}})},removeFilter:function(e){u({type:"remove",payload:{index:e}})},clearFilter:function(){u({type:"clear"})}}}),[i.conditions]),s=t((function(){return{filter:function(e){return e.filter((function(e){return i.conditions.every((function(t){return function(e,t,r){switch(e.operator.type){case"number":if("single number"===e.operator.inputType){if(r.type!==e.operator.inputType)throw new Error("input type is not match");var n=r.payload.value;switch(e.operator.key){case"number:eq":return t===n;case"number:gt":return t>n;case"number:gte":return t>=n;case"number:lt":return t<n;case"number:lte":return t<=n;case"number:neq":return t!==n}}case"string":switch(e.operator.inputType){case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"string:is_not_null":return null!=t&&""!==t;case"string:is_null":return null==t||""===t}case"single string":if(r.type!==e.operator.inputType)throw new Error("input type is not match");var o=r.payload.value;switch(e.operator.key){case"string:eq":return t===o;case"string:like":return t.includes(o);case"string:neq":return t!==o;case"string:not_like":return!t.includes(o)}}case"select":switch(e.operator.inputType){case"select":if(r.type!==e.operator.inputType)throw new Error("input type is not match");o=r.payload.value;switch(e.operator.key){case"select:eq":return t===o;case"select:neq":return t!==o}case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"select:is_null":return null==t||""===t;case"select:is_not_null":return null!=t
|
|
1
|
+
import{useReducer as e,useMemo as t}from"react";import{filterReducer as r}from"./reducer.js";var n=function(n){var o=e(r,{conditions:n}),i=o[0],u=o[1],a=t((function(){return{addFilter:function(e){u({type:"add",payload:{condition:e}})},removeFilter:function(e){u({type:"remove",payload:{index:e}})},clearFilter:function(){u({type:"clear"})}}}),[i.conditions]),s=t((function(){return{filter:function(e){return e.filter((function(e){return i.conditions.every((function(t){return function(e,t,r){switch(e.operator.type){case"number":if("single number"===e.operator.inputType){if(r.type!==e.operator.inputType)throw new Error("input type is not match");var n=r.payload.value;switch(e.operator.key){case"number:eq":return t===n;case"number:gt":return t>n;case"number:gte":return t>=n;case"number:lt":return t<n;case"number:lte":return t<=n;case"number:neq":return t!==n}}case"string":switch(e.operator.inputType){case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"string:is_not_null":return null!=t&&""!==t;case"string:is_null":return null==t||""===t}case"single string":if(r.type!==e.operator.inputType)throw new Error("input type is not match");var o=r.payload.value;switch(e.operator.key){case"string:eq":return t===o;case"string:like":return t.includes(o);case"string:neq":return t!==o;case"string:not_like":return!t.includes(o)}}case"select":switch(e.operator.inputType){case"select":if(r.type!==e.operator.inputType)throw new Error("input type is not match");o=r.payload.value;switch(e.operator.key){case"select:eq":return t===o;case"select:neq":return t!==o}case"none":if(r.type!==e.operator.inputType)throw new Error("input type is not match");switch(e.operator.key){case"select:is_null":return null==t||""===t;case"select:is_not_null":return null!=t&&""!==t}}}}(t,e[t.target.key],t.input)}))}))}}}),[i.conditions]);return{state:i,actions:a,functions:s}};export{n as useFilterHook};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../../src/table/filter-v2/hook.ts"],"sourcesContent":["import { useMemo, useReducer } from \"react\";\nimport { TFilterHook } from \"./type\";\nimport { filterReducer } from \"./reducer\";\nimport { Condition } from \"../../search-bar\";\nimport { DataObject, DataRecord } from \"../table/type\";\nimport { SearchInput } from \"../../search-bar/condition-search-bar/condition-input-management/type\";\n\nexport const useFilterHook: TFilterHook = (initialConditions) => {\n const [state, dispatch] = useReducer(filterReducer, {\n conditions: initialConditions,\n });\n\n const actions = useMemo(\n () => ({\n addFilter: (condition: Condition) => {\n dispatch({ type: \"add\", payload: { condition } });\n },\n removeFilter: (index: number) => {\n dispatch({ type: \"remove\", payload: { index } });\n },\n clearFilter: () => {\n dispatch({ type: \"clear\" });\n },\n }),\n [state.conditions]\n );\n\n const functions = useMemo(\n () => ({\n filter: <T extends DataRecord>(rows: DataObject<T>[]) => {\n return rows.filter((row) => {\n return state.conditions.every((condition) => {\n const value = row[condition.target.key];\n return isMatchCondition(condition, value, condition.input);\n });\n });\n },\n }),\n [state.conditions]\n );\n\n return {\n state,\n actions,\n functions,\n };\n};\n\nfunction isMatchCondition(\n condition: Condition,\n targetValue: any,\n input: SearchInput\n): boolean {\n switch (condition.operator.type) {\n // case \"date\":\n // switch (condition.operator.key) {\n // case \"date:eq\":\n // return false;\n // case \"date:gt\":\n // return false;\n // case \"date:gte\":\n // return false;\n // case \"date:lt\":\n // return false;\n // case \"date:lte\":\n // return false;\n // case \"date:neq\":\n // return false;\n // case \"date:is_not_null\":\n // return false;\n // case \"date:is_null\":\n // return false;\n // }\n case \"number\":\n switch (condition.operator.inputType) {\n case \"single number\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const numValue = input.payload.value;\n\n switch (condition.operator.key) {\n case \"number:eq\":\n return targetValue === numValue;\n case \"number:gt\":\n return targetValue > numValue;\n case \"number:gte\":\n return targetValue >= numValue;\n case \"number:lt\":\n return targetValue < numValue;\n case \"number:lte\":\n return targetValue <= numValue;\n case \"number:neq\":\n return targetValue !== numValue;\n }\n }\n\n case \"string\":\n switch (condition.operator.inputType) {\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"string:is_not_null\":\n return (\n targetValue !== null &&\n targetValue !== undefined &&\n targetValue !== \"\"\n );\n case \"string:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n }\n case \"single string\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"string:eq\":\n return targetValue === value;\n case \"string:like\":\n return targetValue.includes(value);\n case \"string:neq\":\n return targetValue !== value;\n case \"string:not_like\":\n return !targetValue.includes(value);\n }\n }\n\n case \"select\":\n switch (condition.operator.inputType) {\n case \"select\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"select:eq\":\n return targetValue === value;\n case \"select:neq\":\n return targetValue !== value;\n }\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"select:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n case \"select:is_not_null\":\n return (\n
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../../src/table/filter-v2/hook.ts"],"sourcesContent":["import { useMemo, useReducer } from \"react\";\nimport { TFilterHook } from \"./type\";\nimport { filterReducer } from \"./reducer\";\nimport { Condition } from \"../../search-bar\";\nimport { DataObject, DataRecord } from \"../table/type\";\nimport { SearchInput } from \"../../search-bar/condition-search-bar/condition-input-management/type\";\n\nexport const useFilterHook: TFilterHook = (initialConditions) => {\n const [state, dispatch] = useReducer(filterReducer, {\n conditions: initialConditions,\n });\n\n const actions = useMemo(\n () => ({\n addFilter: (condition: Condition) => {\n dispatch({ type: \"add\", payload: { condition } });\n },\n removeFilter: (index: number) => {\n dispatch({ type: \"remove\", payload: { index } });\n },\n clearFilter: () => {\n dispatch({ type: \"clear\" });\n },\n }),\n [state.conditions]\n );\n\n const functions = useMemo(\n () => ({\n filter: <T extends DataRecord>(rows: DataObject<T>[]) => {\n return rows.filter((row) => {\n return state.conditions.every((condition) => {\n const value = row[condition.target.key];\n return isMatchCondition(condition, value, condition.input);\n });\n });\n },\n }),\n [state.conditions]\n );\n\n return {\n state,\n actions,\n functions,\n };\n};\n\nfunction isMatchCondition(\n condition: Condition,\n targetValue: any,\n input: SearchInput\n): boolean {\n switch (condition.operator.type) {\n // case \"date\":\n // switch (condition.operator.key) {\n // case \"date:eq\":\n // return false;\n // case \"date:gt\":\n // return false;\n // case \"date:gte\":\n // return false;\n // case \"date:lt\":\n // return false;\n // case \"date:lte\":\n // return false;\n // case \"date:neq\":\n // return false;\n // case \"date:is_not_null\":\n // return false;\n // case \"date:is_null\":\n // return false;\n // }\n case \"number\":\n switch (condition.operator.inputType) {\n case \"single number\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const numValue = input.payload.value;\n\n switch (condition.operator.key) {\n case \"number:eq\":\n return targetValue === numValue;\n case \"number:gt\":\n return targetValue > numValue;\n case \"number:gte\":\n return targetValue >= numValue;\n case \"number:lt\":\n return targetValue < numValue;\n case \"number:lte\":\n return targetValue <= numValue;\n case \"number:neq\":\n return targetValue !== numValue;\n }\n }\n\n case \"string\":\n switch (condition.operator.inputType) {\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"string:is_not_null\":\n return (\n targetValue !== null &&\n targetValue !== undefined &&\n targetValue !== \"\"\n );\n case \"string:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n }\n case \"single string\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"string:eq\":\n return targetValue === value;\n case \"string:like\":\n return targetValue.includes(value);\n case \"string:neq\":\n return targetValue !== value;\n case \"string:not_like\":\n return !targetValue.includes(value);\n }\n }\n\n case \"select\":\n switch (condition.operator.inputType) {\n case \"select\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n const value = input.payload.value;\n\n switch (condition.operator.key) {\n case \"select:eq\":\n return targetValue === value;\n case \"select:neq\":\n return targetValue !== value;\n }\n case \"none\":\n if (input.type !== condition.operator.inputType) {\n throw new Error(\"input type is not match\");\n }\n\n switch (condition.operator.key) {\n case \"select:is_null\":\n return (\n targetValue === null ||\n targetValue === undefined ||\n targetValue === \"\"\n );\n case \"select:is_not_null\":\n return (\n targetValue !== null &&\n targetValue !== undefined &&\n targetValue !== \"\"\n );\n }\n }\n }\n}\n"],"names":["useFilterHook","initialConditions","_a","useReducer","filterReducer","conditions","state","dispatch","actions","useMemo","addFilter","condition","type","payload","removeFilter","index","clearFilter","functions","filter","rows","row","every","targetValue","input","operator","inputType","Error","numValue","value","key","includes","isMatchCondition","target"],"mappings":"6FAOO,IAAMA,EAA6B,SAACC,GACnC,IAAAC,EAAoBC,EAAWC,EAAe,CAClDC,WAAYJ,IADPK,EAAKJ,EAAA,GAAEK,OAIRC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