@teppen/react-ui 1.5.3 → 1.5.5
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/table/base.js +1 -1
- package/dist/cjs/src/table/cell/provider.js +1 -1
- package/dist/cjs/src/table/cell/provider.js.map +1 -1
- package/dist/cjs/src/table/cell/ui/base-input.js +2 -1
- package/dist/cjs/src/table/cell/ui/base-input.js.map +1 -1
- package/dist/cjs/src/table/cell/ui/cell.js +1 -1
- package/dist/cjs/src/table/edit/ui/editor.js +2 -0
- package/dist/cjs/src/table/edit/ui/editor.js.map +1 -0
- package/dist/cjs/src/table/edit/ui/number-input.js +3 -0
- package/dist/cjs/src/table/edit/ui/select-input.js +3 -0
- package/dist/cjs/src/table/edit/ui/string-input.js +3 -0
- package/dist/cjs/src/table/hook.js +1 -1
- package/dist/cjs/src/table/hook.js.map +1 -1
- package/dist/cjs/src/table/libs/generate-validate-function.js +1 -1
- package/dist/cjs/src/table/libs/generate-validate-function.js.map +1 -1
- package/dist/cjs/src/table/paste/hooks.js +1 -1
- package/dist/cjs/src/table/paste/hooks.js.map +1 -1
- package/dist/cjs/src/table/sheet/providers.js +1 -1
- package/dist/esm/src/table/base.js +1 -1
- package/dist/esm/src/table/cell/provider.js +1 -1
- package/dist/esm/src/table/cell/provider.js.map +1 -1
- package/dist/esm/src/table/cell/ui/base-input.js +2 -1
- package/dist/esm/src/table/cell/ui/base-input.js.map +1 -1
- package/dist/esm/src/table/cell/ui/cell.js +1 -1
- package/dist/esm/src/table/edit/ui/editor.js +2 -0
- package/dist/esm/src/table/edit/ui/editor.js.map +1 -0
- package/dist/esm/src/table/edit/ui/number-input.js +3 -0
- package/dist/esm/src/table/edit/ui/select-input.js +3 -0
- package/dist/esm/src/table/edit/ui/string-input.js +3 -0
- package/dist/esm/src/table/hook.js +1 -1
- package/dist/esm/src/table/hook.js.map +1 -1
- package/dist/esm/src/table/libs/generate-validate-function.js +1 -1
- package/dist/esm/src/table/libs/generate-validate-function.js.map +1 -1
- package/dist/esm/src/table/paste/hooks.js +1 -1
- package/dist/esm/src/table/paste/hooks.js.map +1 -1
- package/dist/esm/src/table/sheet/providers.js +1 -1
- package/dist/index.d.ts +30 -2
- package/package.json +1 -1
- package/dist/cjs/src/table/cell/ui/number-input.js +0 -3
- package/dist/cjs/src/table/cell/ui/select-input.js +0 -3
- package/dist/cjs/src/table/cell/ui/string-input.js +0 -3
- package/dist/cjs/src/table/table/components/auto-switch-edit-mode.js +0 -2
- package/dist/cjs/src/table/table/components/auto-switch-edit-mode.js.map +0 -1
- package/dist/esm/src/table/cell/ui/number-input.js +0 -3
- package/dist/esm/src/table/cell/ui/select-input.js +0 -3
- package/dist/esm/src/table/cell/ui/string-input.js +0 -3
- package/dist/esm/src/table/table/components/auto-switch-edit-mode.js +0 -2
- package/dist/esm/src/table/table/components/auto-switch-edit-mode.js.map +0 -1
- /package/dist/cjs/src/table/{cell → edit}/ui/number-input.js.map +0 -0
- /package/dist/cjs/src/table/{cell → edit}/ui/select-input.js.map +0 -0
- /package/dist/cjs/src/table/{cell → edit}/ui/string-input.js.map +0 -0
- /package/dist/esm/src/table/{cell → edit}/ui/number-input.js.map +0 -0
- /package/dist/esm/src/table/{cell → edit}/ui/select-input.js.map +0 -0
- /package/dist/esm/src/table/{cell → edit}/ui/string-input.js.map +0 -0
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var e=require("../../node_modules/tslib/tslib.es6.js"),r=require("react/jsx-runtime"),o=require("./hook.js"),i=require("./header/header.js"),t=require("./pagenation/providers.js"),s=require("./pagenation/components.js"),n=require("./filter/provider.js"),l=require("./filter/components.js");require("./sort/icon.js");var a=require("./sort/provider.js"),d=require("./sheet/providers.js"),c=require("./focus/provider.js"),x=require("./checkbox/provider.js"),u=require("./checkbox/components.js"),
|
|
2
|
+
"use strict";var e=require("../../node_modules/tslib/tslib.es6.js"),r=require("react/jsx-runtime"),o=require("./hook.js"),i=require("./header/header.js"),t=require("./pagenation/providers.js"),s=require("./pagenation/components.js"),n=require("./filter/provider.js"),l=require("./filter/components.js");require("./sort/icon.js");var a=require("./sort/provider.js"),d=require("./sheet/providers.js"),c=require("./focus/provider.js"),x=require("./checkbox/provider.js"),u=require("./checkbox/components.js"),j=require("./libs/id-generator.js"),h=require("./edit/provider.js"),p=require("./table-property/provider.js"),g=require("./operation/components/keyboard-setting.js"),m=require("./sheet/components.js"),v=require("./paste/provider.js"),b=require("./libs/conditional-formatting.js"),w=require("./edit/ui/editor.js");function y(e){var t=o.useTable(e),a=t.cols,d=t.rowMaps,c=t.pageRowIds,x=n.useFilterContext().selectedFilterKey,h=v.usePasteActionContext().onPaste;return r.jsxs("div",{className:"w-full",children:[r.jsx("div",{className:"flex justify-end mb-1 mr-3",children:r.jsx(l.TableFilterRemoveButton,{children:r.jsx("p",{className:"text-xs underline text-gray-500 hover:text-gray-700",children:"全てのフィルタリング条件を解除する"})})}),r.jsxs("div",{id:"table-frame",className:"relative h-full max-w-full max-h-[80vh] border border-gray-200 rounded-md overflow-auto",children:[r.jsx(w.Editor,{rowMaps:d,pageRowIds:c}),r.jsxs("table",{className:"table",onPaste:function(e){e.preventDefault();var r=e.clipboardData.getData("Text");h(r.replace(/\t/g,",").trim().replace(/\r\n/g,"\n").split("\n").map((function(e){return e.split(",")})))},children:[r.jsx("thead",{children:r.jsxs("tr",{className:"sticky top-0 border-gray-200 z-20 bg-gray-200 text-gray-600 h-[32px]",children:[e.checkbox&&r.jsx("th",{children:r.jsx(u.AllCheckbox,{rows:e.rows})}),a.map((function(e,o){return r.jsx(i.TableHeaderElement,{id:j.IdGenerator.getTableColId(o),columnKey:e.key},e.key)}))]})}),r.jsxs("tbody",{children:[!!x&&r.jsx("tr",{children:r.jsx("td",{colSpan:a.length,className:"sticky top-8 left-0 bg-gray-300 w-full shadow-lg rounded-b-2xl z-20 p-0 overflow-hidden",children:r.jsx(l.TableFilterForm,{})})}),0===c.length&&r.jsx("tr",{children:r.jsx("td",{colSpan:a.length,className:"py-5",children:r.jsx("p",{className:"text-center font-bold text-lg",children:"NO DATA"})})}),c.map((function(o,i){return r.jsx(m.Row,{existCheckbox:!!e.checkbox,rowIndex:i,dataString:d[o].stringValue,cols:e.cols,onClickRow:e.onClickRow,applyRowFormatting:e.applyRowFormatting,conditionalFormattingString:b.generateFormattingString(d[o].data,a,e.conditionalFormattings),onUpdateRow:e.onUpdateRow},o)}))]})]})]}),r.jsxs("div",{className:"mt-1",children:[r.jsx(s.DisplayRange,{}),r.jsx("div",{className:"mt-2",children:r.jsx(s.Pagenation,{})})]})]})}module.exports=function(o){var i,s,l;return r.jsx(n.FilterProvider,{children:r.jsx(a.SortProvider,{initialCondition:null===(i=o.initialCondition)||void 0===i?void 0:i.sort,children:r.jsx(t.PagenationProvider,{rowCount:o.rows.length,perPage:null===(l=null===(s=o.initialCondition)||void 0===s?void 0:s.pagenation)||void 0===l?void 0:l.rowCountPerPage,children:r.jsx(x.CheckboxProvider,{checkbox:o.checkbox,children:r.jsx(x.CheckboxStatusProvider,{checkboxCount:o.rows.length,children:r.jsx(d.ColumnsProvider,{cols:o.cols,errorHandler:o.errorHandler,children:r.jsx(c.FocusProvider,{children:r.jsx(h.EditProvider,{children:r.jsx(p.TablePropertyProvider,{children:r.jsxs(v.PasteProvider,{rows:o.rows,cols:o.cols,colValidators:{},onUpdateRowFunction:o.onUpdateRow,children:[r.jsx(g.KeyboardSetting,{}),r.jsx(y,e.__assign({},o))]})})})})})})})})})})};
|
|
3
3
|
//# sourceMappingURL=base.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../sheet/providers.js"),n=t.createContext({type:"string"});exports.CellProvider=function(o){var u,i,l=o.children,s=o.columnKey,d=r.useColumnContext(s),c=r.useRowContext(),a=c[s],v="select"===d.type?null===(i=null===(u=d.options)||void 0===u?void 0:u.find((function(e){return e.value===a})))||void 0===i?void 0:i.label:a,p=t.useMemo((function(){return d.editable?v:d.render?d.render(a,c):v}),[d.editable,v,a,c]),x=!d.editable&&d.render?"component":d.type,C=t.useMemo((function(){return{component:p,type:x}}),[x,p]);return e.jsx(n.Provider,{value:C,children:l})},exports.useCellContext=function(){return t.useContext(n)};
|
|
2
2
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/cell/provider.tsx"],"sourcesContent":["import { createContext,
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/cell/provider.tsx"],"sourcesContent":["import { createContext, useContext, useMemo } from \"react\";\nimport { TColumnType } from \"../type\";\nimport { useColumnContext, useRowContext } from \"../sheet\";\n\nconst CellContext = createContext<{\n type: TColumnType | \"component\";\n component?: React.ReactNode;\n}>({\n type: \"string\",\n});\n\nexport function CellProvider({\n children,\n columnKey,\n}: {\n children: React.ReactNode;\n columnKey: string;\n}) {\n const col = useColumnContext(columnKey);\n const row = useRowContext();\n const value = row[columnKey];\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 cellStatus = useMemo(\n () => ({\n component,\n type,\n }),\n [type, component]\n );\n\n return (\n <CellContext.Provider value={cellStatus}>{children}</CellContext.Provider>\n );\n}\n\nexport function useCellContext() {\n return useContext(CellContext);\n}\n"],"names":["CellContext","createContext","type","_a","children","columnKey","col","useColumnContext","row","useRowContext","value","label","_b","options","find","op","_c","component","useMemo","editable","render","cellStatus","_jsx","jsx","Provider","useContext"],"mappings":"sGAIMA,EAAcC,EAAAA,cAGjB,CACDC,KAAM,gCAGF,SAAuBC,WAC3BC,EAAQD,EAAAC,SACRC,EAASF,EAAAE,UAKHC,EAAMC,mBAAiBF,GACvBG,EAAMC,EAAAA,gBACNC,EAAQF,EAAIH,GAEZM,EACS,WAAbL,EAAIJ,KAC6C,UAAlC,QAAXU,EAAAN,EAAIO,eAAO,IAAAD,OAAA,EAAAA,EAAEE,MAAK,SAACC,GAAO,OAAAA,EAAGL,QAAUA,CAAb,WAAmB,IAAAM,OAAA,EAAAA,EAAEL,MAC/CD,EAEAO,EAAYC,EAAAA,SAAQ,WACxB,OAAIZ,EAAIa,SACCR,EAEAL,EAAIc,OAASd,EAAIc,OAAOV,EAAgBF,GAAOG,CAE1D,GAAG,CAACL,EAAIa,SAAUR,EAAOD,EAAOF,IAE1BN,GACHI,EAAIa,UAAYb,EAAIc,OAAS,YAAcd,EAAIJ,KAE5CmB,EAAaH,WACjB,WAAM,MAAC,CACLD,UAASA,EACTf,KAAIA,KAEN,CAACA,EAAMe,IAGT,OACEK,EAAAC,IAACvB,EAAYwB,SAAQ,CAACd,MAAOW,EAAUjB,SAAGA,GAE9C,oCAGE,OAAOqB,EAAAA,WAAWzB,EACpB"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../../cancel-icon.js");exports.CellInput=function(r){var u=t.useRef(null);return t.useEffect((function(){u.current&&u.current.focus()}),[u]),e.jsxs("div",{className:"flex justify-between gap-1 w-full items-center",onClick:function(e){e.preventDefault(),e.stopPropagation()},children:[e.jsx("input",{ref:u,className:"w-full py-1 px-2 bg-white text-gray-900",type:"text",value:r.value,onChange:r.onChange,onBlur:r.onBlur,onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(r.reset(),r.endEditing())}}),e.jsx("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){r.reset(),r.endEditing()}),300)},children:e.jsx(n.CancelIcon,{size:16})})]})};
|
|
2
3
|
//# sourceMappingURL=base-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-input.js","sources":[
|
|
1
|
+
{"version":3,"file":"base-input.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var e=require("react/jsx-runtime"),
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),l=require("../../hook.js"),o=require("./edit-button.js"),i=require("react"),t=require("../../libs/id-generator.js"),n=require("../provider.js"),r=require("../../sheet/providers.js"),s=i.memo((function(l){return e.jsx(e.Fragment,{children:"component"===l.type?l.component:e.jsx("div",{onDoubleClick:l.onDoubleClick,children:e.jsx("p",{className:"cell-data text-left whitespace-nowrap",children:l.component})})})})),c=i.memo((function(l){var i=n.useCellContext();return e.jsx("td",{id:l.id,className:"".concat(l.cellFormatClassName),children:e.jsx("div",{className:"relative",onClick:l.isExistOnClickRow?void 0:function(e){e.preventDefault(),l.focusAtCell()},onDoubleClick:l.isExistOnClickRow?void 0:l.onDoubleClickCellToEdit,children:e.jsx("div",{id:"".concat(l.id,"-display"),children:e.jsxs("div",{className:"flex items-center gap-3 w-fit p-2 cursor-default",onClick:function(e){e.preventDefault(),e.stopPropagation(),l.focusAtCell()},children:[e.jsx(s,{type:i.type,component:i.component,onDoubleClick:l.onDoubleClickCellToEdit}),l.editable&&e.jsx(o.EditButton,{})]})})})})}));exports.TableCell=function(o){var i,s=l.useCell(o.rowIndex,o.colIndex),a=s.focusAtCell,d=s.onDoubleClickCellToEdit,u=r.useColumnContext(o.columnKey);return e.jsx(n.CellProvider,{columnKey:o.columnKey,children:e.jsx(c,{id:t.IdGenerator.getTableCellId(o.rowIndex,o.colIndex),editable:null!==(i=u.editable)&&void 0!==i&&i,cellFormatClassName:o.cellFormatClassName,focusAtCell:a,onDoubleClickCellToEdit:d,isExistOnClickRow:o.isExistOnClickRow,isExistOnUpdateRow:!!o.onUpdateRow})})};
|
|
3
3
|
//# sourceMappingURL=cell.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../focus/provider.js"),i=require("../../sheet/providers.js"),n=require("../provider.js"),o=require("./number-input.js"),s=require("./select-input.js"),l=require("./string-input.js"),u=require("../../libs/id-generator.js");exports.Editor=function(d){var c=r.useFocusStateContext(),a=n.useEditStateContext(),p=n.useEditActionContext(),g=i.useColumnsContext();if(t.useEffect((function(){c.isFocus&&!g[c.colIndex].editable&&p.endEditing()}),[a,c]),!a.isEditing)return e.jsx(e.Fragment,{});if(!c.isFocus)return e.jsx(e.Fragment,{});var f=g[c.colIndex],x=d.rowMaps[d.pageRowIds[c.rowIndex]].data;if(!f.editable)return e.jsx(e.Fragment,{});var j=u.IdGenerator.getTableCellId(c.rowIndex,c.colIndex),m=document.getElementById(j),w=null==m?void 0:m.getBoundingClientRect(),h=w?{width:w.width,height:w.height,top:w.top,left:w.left}:void 0;if(!h)return e.jsx(e.Fragment,{});var v=document.getElementById("table-frame");if(!v)return e.jsx(e.Fragment,{});var I=v.getBoundingClientRect();return h.top-=I.top-v.scrollTop-window.scrollY,h.left-=I.left-v.scrollLeft-window.scrollX,e.jsxs("div",{className:"absolute top-0 left-0 grid place-items-center z-10 pr-2",onClick:function(e){e.preventDefault(),e.stopPropagation()},style:{width:h.width,height:h.height,top:h.top-1,left:h.left},children:["string"===f.type&&e.jsx(l.StringCellInput,{col:f,row:x}),"number"===f.type&&e.jsx(o.NumberCellInput,{col:f,row:x}),"select"===f.type&&e.jsx(s.SelectCellInput,{col:f,row:x})]})};
|
|
2
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sources":["../../../../../../src/table/edit/ui/editor.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useFocusStateContext } from \"../../focus/provider\";\nimport { useColumnsContext } from \"../../sheet/providers\";\nimport { useEditActionContext, useEditStateContext } from \"../provider\";\nimport { NumberCellInput } from \"./number-input\";\nimport { SelectCellInput } from \"./select-input\";\nimport { StringCellInput } from \"./string-input\";\nimport { IdGenerator } from \"../../libs\";\nimport { DataObject, DataRecord } from \"../../type\";\n\ntype TPropsEditor = {\n pageRowIds: (string | number)[];\n rowMaps: {\n [id: string]: {\n data: DataObject<DataRecord>;\n stringValue: string;\n };\n [id: number]: {\n data: DataObject<DataRecord>;\n stringValue: string;\n };\n };\n};\n\nexport function Editor(props: TPropsEditor) {\n const focus = useFocusStateContext();\n const edit = useEditStateContext();\n const editActions = useEditActionContext();\n const cols = useColumnsContext();\n\n useEffect(() => {\n if (focus.isFocus && !cols[focus.colIndex].editable) {\n editActions.endEditing();\n }\n }, [edit, focus]);\n\n if (!edit.isEditing) return <></>;\n if (!focus.isFocus) return <></>;\n\n const col = cols[focus.colIndex];\n const row = props.rowMaps[props.pageRowIds[focus.rowIndex]].data;\n\n if (!col.editable) return <></>;\n\n const id = IdGenerator.getTableCellId(focus.rowIndex, focus.colIndex);\n const cellElement = document.getElementById(id);\n const rect = cellElement?.getBoundingClientRect();\n\n const size = rect\n ? {\n width: rect.width,\n height: rect.height,\n top: rect.top,\n left: rect.left,\n }\n : undefined;\n\n if (!size) return <></>;\n\n const tableElement = document.getElementById(\"table-frame\");\n if (!tableElement) return <></>;\n const rectTable = tableElement.getBoundingClientRect();\n\n size.top -= rectTable.top - tableElement.scrollTop - window.scrollY;\n size.left -= rectTable.left - tableElement.scrollLeft - window.scrollX;\n\n return (\n <div\n className=\"absolute top-0 left-0 grid place-items-center z-10 pr-2\"\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n style={{\n width: size.width,\n height: size.height,\n top: size.top - 1,\n left: size.left,\n }}\n >\n {col.type === \"string\" && <StringCellInput col={col} row={row} />}\n {col.type === \"number\" && <NumberCellInput col={col} row={row} />}\n {col.type === \"select\" && <SelectCellInput col={col} row={row} />}\n </div>\n );\n}\n"],"names":["props","focus","useFocusStateContext","edit","useEditStateContext","editActions","useEditActionContext","cols","useColumnsContext","useEffect","isFocus","colIndex","editable","endEditing","isEditing","_jsx","col","row","rowMaps","pageRowIds","rowIndex","data","id","IdGenerator","getTableCellId","cellElement","document","getElementById","rect","getBoundingClientRect","size","width","height","top","left","undefined","tableElement","rectTable","scrollTop","window","scrollY","scrollLeft","scrollX","_jsxs","className","onClick","e","preventDefault","stopPropagation","style","children","type","StringCellInput","NumberCellInput","SelectCellInput"],"mappings":"8TAwBM,SAAiBA,GACrB,IAAMC,EAAQC,EAAAA,uBACRC,EAAOC,EAAAA,sBACPC,EAAcC,EAAAA,uBACdC,EAAOC,EAAAA,oBAQb,GANAC,EAAAA,WAAU,WACJR,EAAMS,UAAYH,EAAKN,EAAMU,UAAUC,UACzCP,EAAYQ,YAEhB,GAAG,CAACV,EAAMF,KAELE,EAAKW,UAAW,OAAOC,qBAC5B,IAAKd,EAAMS,QAAS,OAAOK,qBAE3B,IAAMC,EAAMT,EAAKN,EAAMU,UACjBM,EAAMjB,EAAMkB,QAAQlB,EAAMmB,WAAWlB,EAAMmB,WAAWC,KAE5D,IAAKL,EAAIJ,SAAU,OAAOG,qBAE1B,IAAMO,EAAKC,EAAAA,YAAYC,eAAevB,EAAMmB,SAAUnB,EAAMU,UACtDc,EAAcC,SAASC,eAAeL,GACtCM,EAAOH,eAAAA,EAAaI,wBAEpBC,EAAOF,EACT,CACEG,MAAOH,EAAKG,MACZC,OAAQJ,EAAKI,OACbC,IAAKL,EAAKK,IACVC,KAAMN,EAAKM,WAEbC,EAEJ,IAAKL,EAAM,OAAOf,qBAElB,IAAMqB,EAAeV,SAASC,eAAe,eAC7C,IAAKS,EAAc,OAAOrB,qBAC1B,IAAMsB,EAAYD,EAAaP,wBAK/B,OAHAC,EAAKG,KAAOI,EAAUJ,IAAMG,EAAaE,UAAYC,OAAOC,QAC5DV,EAAKI,MAAQG,EAAUH,KAAOE,EAAaK,WAAaF,OAAOG,QAG7DC,EAAAA,YACEC,UAAU,0DACVC,QAAS,SAACC,GACRA,EAAEC,iBACFD,EAAEE,iBACH,EACDC,MAAO,CACLlB,MAAOD,EAAKC,MACZC,OAAQF,EAAKE,OACbC,IAAKH,EAAKG,IAAM,EAChBC,KAAMJ,EAAKI,MAGZgB,SAAA,CAAa,WAAblC,EAAImC,MAAqBpC,EAAAA,IAACqC,EAAAA,gBAAgB,CAAApC,IAAKA,EAAKC,IAAKA,IAC5C,WAAbD,EAAImC,MAAqBpC,MAACsC,EAAAA,gBAAe,CAACrC,IAAKA,EAAKC,IAAKA,IAC5C,WAAbD,EAAImC,MAAqBpC,MAACuC,EAAeA,gBAAA,CAACtC,IAAKA,EAAKC,IAAKA,MAGhE"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../sheet/providers.js"),u=require("../../cell/ui/base-input.js"),n=require("../provider.js");exports.NumberCellInput=function(a){var i=a.col,l=r.useColumnValidateContext(i.key),o=n.useEditActionContext().endEditing,s=a.row[i.key],c=t.useState(s.toString()),g=c[0],v=c[1];return e.jsx(u.CellInput,{value:g,onChange:function(e){e.preventDefault(),""!==e.target.value?"-"!==e.target.value&&"0-"!==e.target.value?e.target.value.match(/^-?[0-9]+\.$/)?v(e.target.value):isNaN(Number(e.target.value))||v(Number(e.target.value).toString()):v("-0"):v("0")},onBlur:function(e){e.preventDefault(),Number(g)!==s?l(g)?function(e){i.editable&&i.onCellBlur(i.key,Number(e),a.row,o)}(g):setTimeout((function(){e.target.focus()}),100):o()},reset:function(){return v(s.toString())},endEditing:o})};
|
|
3
|
+
//# sourceMappingURL=number-input.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../provider.js"),r=require("../../cancel-icon.js");exports.SelectCellInput=function(l){var o=l.col,u=n.useEditActionContext().endEditing,i=l.row[o.key],a=t.useState(i),c=a[0],s=a[1];return o.editable?e.jsxs("div",{className:"flex justify-between gap-1 w-full items-center",children:[e.jsxs("select",{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){o.editable&&o.onCellBlur(o.key,e,l.row,u)}(c):u()},onKeyDown:function(e){"Enter"===e.key&&e.preventDefault()},onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(s(i),u())},children:[o.allowEmpty&&e.jsx("option",{value:"",children:""==i?"-- 未選択 --":"-- 選択解除 --"},"TEPPEN/ReactUI Empty Option"),o.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),u()}),300)},children:e.jsx(r.CancelIcon,{size:16})})]}):e.jsx(e.Fragment,{})};
|
|
3
|
+
//# sourceMappingURL=select-input.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../provider.js"),n=require("../../sheet/providers.js"),u=require("../../cell/ui/base-input.js");exports.StringCellInput=function(i){var o=i.col,l=n.useColumnValidateContext(o.key),s=r.useEditActionContext().endEditing,a=i.row[o.key],c=t.useState(a),d=c[0],f=c[1];return e.jsx(u.CellInput,{value:d,onChange:function(e){e.preventDefault(),f(e.target.value)},onBlur:function(e){e.preventDefault(),d!==a?l(d)?function(e){o.editable&&o.onCellBlur(o.key,e,i.row,s)}(d):setTimeout((function(){e.target.focus()}),100):s()},reset:function(){return f(a.toString())},endEditing:s})};
|
|
3
|
+
//# sourceMappingURL=string-input.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react"),t=require("./pagenation/providers.js");require("react/jsx-runtime");var r=require("./filter/provider.js");require("./filter/constants.js"),require("./sheet/providers.js");var
|
|
1
|
+
"use strict";var e=require("react"),t=require("./pagenation/providers.js");require("react/jsx-runtime");var r=require("./filter/provider.js");require("./filter/constants.js"),require("./sheet/providers.js");var o=require("./focus/provider.js"),n=require("./checkbox/provider.js"),u=require("./edit/provider.js"),s=require("./sort/provider.js"),i=require("./table-property/provider.js"),c=require("./paste/provider.js");exports.useCell=function(t,r){var n=o.useFocusActionContext(),s=u.useEditActionContext();return{focusAtCell:e.useCallback((function(){n.move(t,r),n.focus(t,r)}),[n,t,r]),onDoubleClickCellToEdit:e.useCallback((function(e){e.preventDefault(),n.move(t,r),n.focus(t,r),s.startEditing()}),[n,s,t,r])}},exports.useTable=function(o){var u=r.useFilterContext().filter,a=s.useSortActionContext(),f=a.sort,l=a.updatedData,d=s.useSortTimingContext(),p=t.usePageContext(),v=p.setRowCount,C=p.pageFilter,x=n.useCheckboxStatusContext().dispatchCheckboxStatus,h=c.usePasteActionContext().setRows,g=i.useTablePropertyActionContext(),b=g.setMaxDisplayColCount,m=g.setMaxDisplayRowCount,w=e.useMemo((function(){return u(o.rows)}),[u,d,o.rows.length]);e.useEffect((function(){v(w.length)}),[w.length]);var j=e.useMemo((function(){return o.checkbox?o.rows.filter((function(e){var t;return null===(t=o.checkbox)||void 0===t?void 0:t.checked(e)})):[]}),[o.checkbox,o.rows]);e.useEffect((function(){x({type:"SET",payload:{checkedRecords:j}})}),[j]);var k=e.useMemo((function(){return f(w)}),[w,d]);e.useEffect((function(){l()}),[o.rows]);var q=e.useMemo((function(){return C(k)}),[C,k]),E=e.useMemo((function(){return q.map((function(e){return e.id}))}),[q]),M=e.useMemo((function(){return new Set(E)}),[E]),y=e.useMemo((function(){return o.rows.filter((function(e){return M.has(e.id)})).reduce((function(e,t){var r=Object.keys(t).sort().reduce((function(e,r){return e[r]=t[r],e}),{});return e[t.id]={data:r,stringValue:JSON.stringify(r)},e}),{})}),[o.rows,M]);return e.useEffect((function(){b(o.cols.length)}),[o.cols.length]),e.useEffect((function(){m(E.length)}),[E.length]),e.useEffect((function(){h(E.map((function(e){return y[e].data})))}),[y]),{cols:o.cols,rowMaps:y,pageRowIds:E}};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../src/table/hook.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo } from \"react\";\nimport { DataObject, DataRecord, TPropsTable } from \"./type\";\nimport { usePageContext } from \"./pagenation/providers\";\nimport { useFilterContext } from \"./filter\";\nimport { useFocusActionContext } from \"./focus/provider\";\nimport { useCheckboxStatusContext } from \"./checkbox/provider\";\nimport { useEditActionContext } from \"./edit/provider\";\nimport { useSortActionContext, useSortTimingContext } from \"./sort/provider\";\nimport { useTablePropertyActionContext } from \"./table-property/provider\";\nimport { usePasteActionContext } from \"./paste/provider\";\n\nexport function useTable<T extends DataRecord>(props: TPropsTable<T>) {\n const { filter } = useFilterContext();\n const { sort, updatedData } = useSortActionContext();\n const sortTiming = useSortTimingContext();\n const { setRowCount, pageFilter } = usePageContext();\n const { dispatchCheckboxStatus } = useCheckboxStatusContext();\n const { setRows } = usePasteActionContext();\n const { setMaxDisplayColCount, setMaxDisplayRowCount } =\n useTablePropertyActionContext();\n\n const filteredRows = useMemo(\n () => filter(props.rows),\n [filter, sortTiming, props.rows.length]\n );\n\n useEffect(() => {\n setRowCount(filteredRows.length);\n }, [filteredRows.length]);\n\n const checkBoxes = useMemo(() => {\n if (!props.checkbox) {\n return [];\n }\n\n return props.rows.filter((row) => props.checkbox?.checked(row));\n }, [props.checkbox, props.rows]);\n\n useEffect(() => {\n dispatchCheckboxStatus({\n type: \"SET\",\n payload: { checkedRecords: checkBoxes },\n });\n }, [checkBoxes]);\n\n const sortedRows = useMemo(\n () => sort(filteredRows),\n [filteredRows, sortTiming]\n );\n\n useEffect(() => {\n updatedData();\n }, [props.rows]);\n\n const pageRows = useMemo(\n () => pageFilter(sortedRows),\n [pageFilter, sortedRows]\n );\n\n const pageRowIds = useMemo(() => pageRows.map((row) => row.id), [pageRows]);\n const pageRowIdSets = useMemo(() => new Set(pageRowIds), [pageRowIds]);\n\n const rowMaps = useMemo(\n () =>\n props.rows\n .filter((row) => pageRowIdSets.has(row.id))\n .reduce((acc, row) => {\n const rowSortedByKey = Object.keys(row)\n .sort()\n .reduce((acc, key) => {\n acc[key] = row[key];\n return acc;\n }, {} as { [key: string]: string | number });\n\n acc[row.id] = {\n data: rowSortedByKey,\n stringValue: JSON.stringify(rowSortedByKey),\n };\n return acc;\n }, {} as { [id: string | number]: { data: DataObject<any>; stringValue: string } }),\n [props.rows, pageRowIdSets]\n );\n\n useEffect(() => {\n setMaxDisplayColCount(props.cols.length);\n }, [props.cols.length]);\n\n useEffect(() => {\n setMaxDisplayRowCount(pageRowIds.length);\n }, [pageRowIds.length]);\n\n useEffect(() => {\n setRows(pageRowIds.map((id) => rowMaps[id].data));\n }, [rowMaps]);\n\n return {\n cols: props.cols,\n rowMaps,\n pageRowIds,\n };\n}\n\nexport function useCell(rowIndex: number, colIndex: number) {\n const focus = useFocusActionContext();\n const editAction = useEditActionContext();\n
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../src/table/hook.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo } from \"react\";\nimport { DataObject, DataRecord, TPropsTable } from \"./type\";\nimport { usePageContext } from \"./pagenation/providers\";\nimport { useFilterContext } from \"./filter\";\nimport { useFocusActionContext } from \"./focus/provider\";\nimport { useCheckboxStatusContext } from \"./checkbox/provider\";\nimport { useEditActionContext } from \"./edit/provider\";\nimport { useSortActionContext, useSortTimingContext } from \"./sort/provider\";\nimport { useTablePropertyActionContext } from \"./table-property/provider\";\nimport { usePasteActionContext } from \"./paste/provider\";\n\nexport function useTable<T extends DataRecord>(props: TPropsTable<T>) {\n const { filter } = useFilterContext();\n const { sort, updatedData } = useSortActionContext();\n const sortTiming = useSortTimingContext();\n const { setRowCount, pageFilter } = usePageContext();\n const { dispatchCheckboxStatus } = useCheckboxStatusContext();\n const { setRows } = usePasteActionContext();\n const { setMaxDisplayColCount, setMaxDisplayRowCount } =\n useTablePropertyActionContext();\n\n const filteredRows = useMemo(\n () => filter(props.rows),\n [filter, sortTiming, props.rows.length]\n );\n\n useEffect(() => {\n setRowCount(filteredRows.length);\n }, [filteredRows.length]);\n\n const checkBoxes = useMemo(() => {\n if (!props.checkbox) {\n return [];\n }\n\n return props.rows.filter((row) => props.checkbox?.checked(row));\n }, [props.checkbox, props.rows]);\n\n useEffect(() => {\n dispatchCheckboxStatus({\n type: \"SET\",\n payload: { checkedRecords: checkBoxes },\n });\n }, [checkBoxes]);\n\n const sortedRows = useMemo(\n () => sort(filteredRows),\n [filteredRows, sortTiming]\n );\n\n useEffect(() => {\n updatedData();\n }, [props.rows]);\n\n const pageRows = useMemo(\n () => pageFilter(sortedRows),\n [pageFilter, sortedRows]\n );\n\n const pageRowIds = useMemo(() => pageRows.map((row) => row.id), [pageRows]);\n const pageRowIdSets = useMemo(() => new Set(pageRowIds), [pageRowIds]);\n\n const rowMaps = useMemo(\n () =>\n props.rows\n .filter((row) => pageRowIdSets.has(row.id))\n .reduce((acc, row) => {\n const rowSortedByKey = Object.keys(row)\n .sort()\n .reduce((acc, key) => {\n acc[key] = row[key];\n return acc;\n }, {} as { [key: string]: string | number });\n\n acc[row.id] = {\n data: rowSortedByKey,\n stringValue: JSON.stringify(rowSortedByKey),\n };\n return acc;\n }, {} as { [id: string | number]: { data: DataObject<any>; stringValue: string } }),\n [props.rows, pageRowIdSets]\n );\n\n useEffect(() => {\n setMaxDisplayColCount(props.cols.length);\n }, [props.cols.length]);\n\n useEffect(() => {\n setMaxDisplayRowCount(pageRowIds.length);\n }, [pageRowIds.length]);\n\n useEffect(() => {\n setRows(pageRowIds.map((id) => rowMaps[id].data));\n }, [rowMaps]);\n\n return {\n cols: props.cols,\n rowMaps,\n pageRowIds,\n };\n}\n\nexport function useCell(rowIndex: number, colIndex: number) {\n const focus = useFocusActionContext();\n const editAction = useEditActionContext();\n\n const focusAtCell = useCallback(() => {\n focus.move(rowIndex, colIndex);\n focus.focus(rowIndex, colIndex);\n }, [focus, rowIndex, colIndex]);\n\n const onDoubleClickCellToEdit: React.MouseEventHandler<HTMLDivElement> =\n useCallback(\n (e) => {\n e.preventDefault();\n focus.move(rowIndex, colIndex);\n focus.focus(rowIndex, colIndex);\n editAction.startEditing();\n },\n [focus, editAction, rowIndex, colIndex]\n );\n\n return {\n focusAtCell,\n onDoubleClickCellToEdit,\n };\n}\n"],"names":["rowIndex","colIndex","focus","useFocusActionContext","editAction","useEditActionContext","focusAtCell","useCallback","move","onDoubleClickCellToEdit","e","preventDefault","startEditing","props","filter","useFilterContext","_a","useSortActionContext","sort","updatedData","sortTiming","useSortTimingContext","_b","usePageContext","setRowCount","pageFilter","dispatchCheckboxStatus","useCheckboxStatusContext","setRows","usePasteActionContext","_c","useTablePropertyActionContext","setMaxDisplayColCount","setMaxDisplayRowCount","filteredRows","useMemo","rows","length","useEffect","checkBoxes","checkbox","row","checked","type","payload","checkedRecords","sortedRows","pageRows","pageRowIds","map","id","pageRowIdSets","Set","rowMaps","has","reduce","acc","rowSortedByKey","Object","keys","key","data","stringValue","JSON","stringify","cols"],"mappings":"mbAsGgB,SAAQA,EAAkBC,GACxC,IAAMC,EAAQC,EAAAA,wBACRC,EAAaC,EAAAA,uBAkBnB,MAAO,CACLC,YAjBkBC,EAAAA,aAAY,WAC9BL,EAAMM,KAAKR,EAAUC,GACrBC,EAAMA,MAAMF,EAAUC,EACvB,GAAE,CAACC,EAAOF,EAAUC,IAenBQ,wBAZAF,eACE,SAACG,GACCA,EAAEC,iBACFT,EAAMM,KAAKR,EAAUC,GACrBC,EAAMA,MAAMF,EAAUC,GACtBG,EAAWQ,cACZ,GACD,CAACV,EAAOE,EAAYJ,EAAUC,IAOpC,mBAnHM,SAAyCY,GACrC,IAAAC,EAAWC,4BACbC,EAAwBC,EAAoBA,uBAA1CC,EAAIF,EAAAE,KAAEC,EAAWH,EAAAG,YACnB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AOC,KAAKlB,GAChCvB,OACAqC,QAAO,SAACC,EAAKI,GAEZ,OADAJ,EAAII,GAAOnB,EAAImB,GACRJ,CACR,GAAE,CAAwC,GAM7C,OAJAA,EAAIf,EAAIS,IAAM,CACZW,KAAMJ,EACNK,YAAaC,KAAKC,UAAUP,IAEvBD,CACR,GAAE,CAA+E,EAAC,GACvF,CAAC3C,EAAMuB,KAAMe,IAef,OAZAb,EAAAA,WAAU,WACRN,EAAsBnB,EAAMoD,KAAK5B,OAClC,GAAE,CAACxB,EAAMoD,KAAK5B,SAEfC,EAAAA,WAAU,WACRL,EAAsBe,EAAWX,OACnC,GAAG,CAACW,EAAWX,SAEfC,EAAAA,WAAU,WACRV,EAAQoB,EAAWC,KAAI,SAACC,GAAO,OAAAG,EAAQH,GAAIW,QAC7C,GAAG,CAACR,IAEG,CACLY,KAAMpD,EAAMoD,KACZZ,QAAOA,EACPL,WAAUA,EAEd"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";exports.generateValidateFunction=function(t){if("string"===
|
|
1
|
+
"use strict";function n(n){var e="入力値が不正のため、エラーを確認し修正してください。\n\n";e+="[対象の列名]: ".concat(n[0].label,"\n"),e+="[入力値] : ".concat(n[0].value,"\n\n"),e+="[エラー内容]:",e+=n.reduce((function(n,e){switch(e.type){case"STRING_IS_TOO_LONG":return n+"\n・文字数が最大の長さ".concat(e.maxLength,"文字を超えています。(現在").concat(e.currentLength,"文字)");case"STRING_IS_TOO_SHORT":return n+"\n・文字数が最小の長さ".concat(e.minLength,"文字に満たないです。(現在").concat(e.currentLength,"文字)");case"STRING_PATTERN_NOT_MATCH":return n+"\n・パターンに一致しません。(パターン".concat(e.pattern,")");case"NUMBER_IS_TOO_LARGE":return n+"\n・最大値".concat(e.max,"を超えています。(入力値").concat(e.value,")");case"NUMBER_IS_TOO_SMALL":return n+"\n・最小値".concat(e.min,"を下回っています。(入力値").concat(e.value,")");case"NOT_NUMBER":return n+"\n・数値ではない値が入力されています。";case"NOT_IN_OPTIONS":return n+"\n・選択肢に含まれていない値です。"}}),""),alert(e)}exports.generateValidateFunction=function(e,t){if("string"===e.type)return function(e,t,r,a){return function(e){var u=[];return(null==r?void 0:r.maxLength)&&e.length>r.maxLength&&u.push({type:"STRING_IS_TOO_LONG",label:t,maxLength:r.maxLength,currentLength:e.length,value:e}),(null==r?void 0:r.minLength)&&e.length<r.minLength&&u.push({type:"STRING_IS_TOO_SHORT",label:t,minLength:r.minLength,currentLength:e.length,value:e}),(null==r?void 0:r.pattern)&&(new RegExp(r.pattern).test(e)||u.push({type:"STRING_PATTERN_NOT_MATCH",label:t,pattern:r.pattern,value:e})),!(u.length>0&&(a?a(u):n(u),1))}}(e.key,e.label,e.constraints,t);if("number"===e.type)return function(e,t,r,a){return function(e){var u=[];return"string"!=typeof e||/^-?[0-9]+(\.[0-9]+)?$/.test(e)?(e=Number(e),"number"==typeof(null==r?void 0:r.max)&&e>r.max&&u.push({type:"NUMBER_IS_TOO_LARGE",label:t,max:r.max,value:e}),"number"==typeof(null==r?void 0:r.min)&&e<r.min&&u.push({type:"NUMBER_IS_TOO_SMALL",label:t,min:r.min,value:e}),!(u.length>0&&(a?a(u):n(u),1))):(u.push({type:"NOT_NUMBER",label:t,value:e}),a?a(u):n(u),!1)}}(e.key,e.label,e.constraints,t);if("select"===e.type)return function(e,t,r,a,u){var l=new Set(r.map((function(n){return n.label})));return function(e){if(a&&""===e)return!0;var r=[];return l.has(e)||r.push({type:"NOT_IN_OPTIONS",label:t,value:e,options:Array.from(l)}),!(r.length>0&&(u?u(r):n(r),1))}}(e.key,e.label,e.options,e.allowEmpty,t);throw new Error("Invalid type")};
|
|
2
2
|
//# sourceMappingURL=generate-validate-function.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-validate-function.js","sources":["../../../../../src/table/libs/generate-validate-function.ts"],"sourcesContent":["export type TStringValidateOption = {\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n};\n\nexport type TNumberValidateOption = {\n max?: number;\n min?: number;\n};\n\ntype TPropsGenerateValidateFunction
|
|
1
|
+
{"version":3,"file":"generate-validate-function.js","sources":["../../../../../src/table/libs/generate-validate-function.ts"],"sourcesContent":["export type TStringValidateOption = {\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n};\n\nexport type TNumberValidateOption = {\n max?: number;\n min?: number;\n};\n\ntype TPropsGenerateValidateFunction = {\n key: string;\n label: string;\n} & (\n | {\n type: \"string\";\n constraints?: TStringValidateOption;\n }\n | {\n type: \"number\";\n constraints?: TNumberValidateOption;\n }\n | {\n type: \"select\";\n options: { value: string; label: string }[];\n allowEmpty?: boolean;\n }\n);\n\ntype TStringValidateFunction = (value: string) => boolean;\n\nexport type TErrorValidation = {\n label: string;\n value: string | number;\n} & (\n | {\n type: \"STRING_IS_TOO_LONG\";\n maxLength: number;\n currentLength: number;\n }\n | {\n type: \"STRING_IS_TOO_SHORT\";\n minLength: number;\n currentLength: number;\n }\n | {\n type: \"STRING_PATTERN_NOT_MATCH\";\n pattern: string;\n }\n | {\n type: \"NUMBER_IS_TOO_LARGE\";\n max: number;\n }\n | {\n type: \"NUMBER_IS_TOO_SMALL\";\n min: number;\n }\n | {\n type: \"NOT_NUMBER\";\n }\n | {\n type: \"NOT_IN_OPTIONS\";\n options: string[];\n }\n);\n\nfunction defaultErrorHandler(errors: TErrorValidation[]) {\n let message = `入力値が不正のため、エラーを確認し修正してください。\\n\\n`;\n message += `[対象の列名]: ${errors[0].label}\\n`;\n message += `[入力値] : ${errors[0].value}\\n\\n`;\n message += `[エラー内容]:`;\n\n message += errors.reduce((acc, error) => {\n switch (error.type) {\n case \"STRING_IS_TOO_LONG\":\n return (\n acc +\n `\\n・文字数が最大の長さ${error.maxLength}文字を超えています。(現在${error.currentLength}文字)`\n );\n case \"STRING_IS_TOO_SHORT\":\n return (\n acc +\n `\\n・文字数が最小の長さ${error.minLength}文字に満たないです。(現在${error.currentLength}文字)`\n );\n case \"STRING_PATTERN_NOT_MATCH\":\n return acc + `\\n・パターンに一致しません。(パターン${error.pattern})`;\n case \"NUMBER_IS_TOO_LARGE\":\n return (\n acc + `\\n・最大値${error.max}を超えています。(入力値${error.value})`\n );\n case \"NUMBER_IS_TOO_SMALL\":\n return (\n acc + `\\n・最小値${error.min}を下回っています。(入力値${error.value})`\n );\n case \"NOT_NUMBER\":\n return acc + `\\n・数値ではない値が入力されています。`;\n case \"NOT_IN_OPTIONS\":\n return acc + `\\n・選択肢に含まれていない値です。`;\n }\n }, \"\");\n\n alert(message);\n}\n\nfunction generateStringValidateFunction(\n key: string,\n label: string,\n constraints?: TStringValidateOption,\n errorHandler?: (errors: TErrorValidation[]) => void\n): TStringValidateFunction {\n return (value: string) => {\n const errors: TErrorValidation[] = [];\n\n if (constraints?.maxLength) {\n if (value.length > constraints.maxLength) {\n errors.push({\n type: \"STRING_IS_TOO_LONG\",\n label,\n maxLength: constraints.maxLength,\n currentLength: value.length,\n value,\n });\n }\n }\n\n if (constraints?.minLength) {\n if (value.length < constraints.minLength) {\n errors.push({\n type: \"STRING_IS_TOO_SHORT\",\n label,\n minLength: constraints.minLength,\n currentLength: value.length,\n value,\n });\n }\n }\n\n if (constraints?.pattern) {\n if (!new RegExp(constraints.pattern).test(value)) {\n errors.push({\n type: \"STRING_PATTERN_NOT_MATCH\",\n label,\n pattern: constraints.pattern,\n value,\n });\n }\n }\n\n if (errors.length > 0) {\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n\n return true;\n };\n}\n\ntype TNumberValidateFunction = (value: number) => boolean;\n\nfunction generateNumberValidateFunction(\n key: string,\n label: string,\n constraints?: TNumberValidateOption,\n errorHandler?: (errors: TErrorValidation[]) => void\n): TNumberValidateFunction {\n return (value: number | string) => {\n const errors: TErrorValidation[] = [];\n\n if (typeof value === \"string\") {\n // 小数も含めて数値に変換可能な値かを検査\n if (!/^-?[0-9]+(\\.[0-9]+)?$/.test(value)) {\n errors.push({\n type: \"NOT_NUMBER\",\n label,\n value,\n });\n\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n }\n\n value = Number(value);\n\n if (typeof constraints?.max === \"number\") {\n if (value > constraints.max) {\n errors.push({\n type: \"NUMBER_IS_TOO_LARGE\",\n label,\n max: constraints.max,\n value,\n });\n }\n }\n\n if (typeof constraints?.min === \"number\") {\n if (value < constraints.min) {\n errors.push({\n type: \"NUMBER_IS_TOO_SMALL\",\n label,\n min: constraints.min,\n value,\n });\n }\n }\n\n if (errors.length > 0) {\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n\n return true;\n };\n}\n\ntype TSelectValidateFunction = (label: string) => boolean;\n\nfunction generatSelectValidateFunction(\n key: string,\n columnLabel: string,\n options: { value: string; label: string }[],\n allowEmpty?: boolean,\n errorHandler?: (errors: TErrorValidation[]) => void\n): TSelectValidateFunction {\n const labelSets = new Set(options.map((option) => option.label));\n return (label: string) => {\n if (allowEmpty && label === \"\") {\n return true;\n }\n\n const errors: TErrorValidation[] = [];\n\n if (!labelSets.has(label)) {\n errors.push({\n type: \"NOT_IN_OPTIONS\",\n label: columnLabel,\n value: label,\n options: Array.from(labelSets),\n });\n }\n\n if (errors.length > 0) {\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n\n return true;\n };\n}\n\nexport function generateValidateFunction(\n props: TPropsGenerateValidateFunction,\n errorHandler?: (errors: TErrorValidation[]) => void\n) {\n if (props.type === \"string\") {\n return generateStringValidateFunction(\n props.key,\n props.label,\n props.constraints,\n errorHandler\n );\n } else if (props.type === \"number\") {\n return generateNumberValidateFunction(\n props.key,\n props.label,\n props.constraints,\n errorHandler\n );\n } else if (props.type === \"select\") {\n return generatSelectValidateFunction(\n props.key,\n props.label,\n props.options,\n props.allowEmpty,\n errorHandler\n );\n } else {\n throw new Error(\"Invalid type\");\n }\n}\n"],"names":["defaultErrorHandler","errors","message","label","value","reduce","acc","error","type","concat","maxLength","currentLength","minLength","pattern","max","min","alert","props","errorHandler","key","constraints","length","push","RegExp","test","generateStringValidateFunction","Number","generateNumberValidateFunction","columnLabel","options","allowEmpty","labelSets","Set","map","option","has","Array","from","generatSelectValidateFunction","Error"],"mappings":"aAmEA,SAASA,EAAoBC,GAC3B,IAAIC,EAAU,iCACdA,GAAW,mBAAYD,EAAO,GAAGE,MAAK,MACtCD,GAAW,mBAAYD,EAAO,GAAGG,MAAK,QACtCF,GAAW,WAEXA,GAAWD,EAAOI,QAAO,SAACC,EAAKC,GAC7B,OAAQA,EAAMC,MACZ,IAAK,qBACH,OACEF,EACA,eAAeG,OAAAF,EAAMG,UAAS,iBAAAD,OAAgBF,EAAMI,cAAkB,OAE1E,IAAK,sBACH,OACEL,EACA,eAAeG,OAAAF,EAAMK,UAAS,iBAAAH,OAAgBF,EAAMI,cAAkB,OAE1E,IAAK,2BACH,OAAOL,EAAM,uBAAAG,OAAuBF,EAAMM,aAC5C,IAAK,sBACH,OACEP,EAAM,SAAAG,OAASF,EAAMO,IAAG,gBAAAL,OAAeF,EAAMH,MAAK,KAEtD,IAAK,sBACH,OACEE,EAAM,SAAAG,OAASF,EAAMQ,IAAG,iBAAAN,OAAgBF,EAAMH,MAAK,KAEvD,IAAK,aACH,OAAOE,EAAM,uBACf,IAAK,iBACH,OAAOA,EAAM,qBAElB,GAAE,IAEHU,MAAMd,EACR,kCAoKgB,SACde,EACAC,GAEA,GAAmB,WAAfD,EAAMT,KACR,OAvKJ,SACEW,EACAhB,EACAiB,EACAF,GAEA,OAAO,SAACd,GACN,IAAMH,EAA6B,GAqCnC,OAnCImB,aAAW,EAAXA,EAAaV,YACXN,EAAMiB,OAASD,EAAYV,WAC7BT,EAAOqB,KAAK,CACVd,KAAM,qBACNL,MAAKA,EACLO,UAAWU,EAAYV,UACvBC,cAAeP,EAAMiB,OACrBjB,MAAKA,KAKPgB,aAAW,EAAXA,EAAaR,YACXR,EAAMi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W,OAAAA,EAAO/B,UACzD,OAAO,SAACA,GACN,GAAI2B,GAAwB,KAAV3B,EAChB,OAAO,EAGT,IAAMF,EAA6B,GAWnC,OATK8B,EAAUI,IAAIhC,IACjBF,EAAOqB,KAAK,CACVd,KAAM,iBACNL,MAAOyB,EACPxB,MAAOD,EACP0B,QAASO,MAAMC,KAAKN,OAIpB9B,EAAOoB,OAAS,IACdH,EACFA,EAAajB,GAEbD,EAAoBC,GAEf,GAIX,CACF,CAqBWqC,CACLrB,EAAME,IACNF,EAAMd,MACNc,EAAMY,QACNZ,EAAMa,WACNZ,GAGF,MAAM,IAAIqB,MAAM,eAEpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),a=require("react"),t=require("../sheet/providers.js"),n=function(a,t){var n
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),a=require("react"),t=require("../sheet/providers.js"),n=require("../focus/provider.js"),s=function(a,t){var n;switch(t.type){case"setRows":return e.__assign(e.__assign({},a),{rows:t.payload.rows});case"setCols":return e.__assign(e.__assign({},a),{cols:t.payload.cols});case"setColValidators":return e.__assign(e.__assign({},a),{colValidators:t.payload.colValidators});case"setOnUpdateRowFunction":return e.__assign(e.__assign({},a),{onUpdateRowFunction:t.payload.onUpdateRowFunction});case"onPaste":if(!a.isFocused)return a;var s=t.payload.pasteData,o=a.rows,r=a.cols,u=a.colValidators,i=a.rowIndex,l=a.colIndex;if(!a.onUpdateRowFunction)return a;var c={arguments:[],timing:a.updateParameters.timing+1},d=s.length,p=Math.max.apply(Math,s.map((function(e){return e.length})));if(0===d||0===p)return a;if(s.length+i>o.length)return alert("貼り付け先の行数が足りません。"),a;for(var f=0;f<p;f++){if(!(w=r[l+f]).editable)return alert("編集できない列にデータを貼り付けることはできません。\n\n編集不可列: ".concat(null!==(n=w.label)&&void 0!==n?n:w.key)),a}if(p+l>r.length)return alert("貼り付け先の列数が足りません。"),a;for(f=0;f<d;f++)for(var g=s[f],_=0;_<g.length;_++){var w,y=g[_];if(!(0,u[(w=r[l+_]).key])(y))return a}return s.forEach((function(a,t){var n=e.__assign({},o[i+t]),s=!1;a.forEach((function(e,a){var t=r[l+a],o="number"===t.type?Number(e):"select"===t.type?""===e?"":t.options.find((function(a){return a.label===e})).value:e;n[t.key]!==o&&(s=!0,n[t.key]=o)})),s&&c.arguments.push({newRow:n,oldRow:o[i+t]})})),c.arguments.length>0?e.__assign(e.__assign({},a),{updateParameters:c}):a;case"focus":return e.__assign(e.__assign({},a),{isFocused:!0,rowIndex:t.payload.rowIndex,colIndex:t.payload.colIndex});case"unfocus":return e.__assign(e.__assign({},a),{isFocused:!1})}};exports.usePasteReducer=function(o){var r=a.useReducer(s,e.__assign(e.__assign({},o),{isFocused:!1,updateParameters:{arguments:[],timing:0}})),u=r[0],i=r[1],l=t.useColumnValidatesContext(),c=n.useFocusStateContext();a.useEffect((function(){c.isFocus?i({type:"focus",payload:{rowIndex:c.rowIndex,colIndex:c.colIndex}}):i({type:"unfocus"})}),[c]);var d=a.useCallback((function(e){i({type:"setRows",payload:{rows:e}})}),[]),p=a.useCallback((function(e){i({type:"setCols",payload:{cols:e}})}),[]),f=a.useCallback((function(e){i({type:"setColValidators",payload:{colValidators:e}})}),[]);a.useEffect((function(){f(l)}),[l]);var g=a.useCallback((function(e){i({type:"setOnUpdateRowFunction",payload:{onUpdateRowFunction:e}})}),[]),_=a.useCallback((function(e){i({type:"onPaste",payload:{pasteData:e}})}),[]);return a.useEffect((function(){u.updateParameters.arguments.length>0&&u.updateParameters.arguments.forEach((function(e){var a,t=e.newRow,n=e.oldRow;null===(a=u.onUpdateRowFunction)||void 0===a||a.call(u,t,n)}))}),[u.updateParameters.timing,u.onUpdateRowFunction]),a.useMemo((function(){return{setRows:d,setCols:p,setColValidators:f,setOnUpdateRowFunction:g,onPaste:_}}),[])};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/paste/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useReducer } from \"react\";\nimport { TPasteReducer, TPasteReducerReturn } from \"./types\";\nimport { useColumnValidatesContext } from \"../sheet/providers\";\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
|
|
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 { useFocusStateContext } from \"../focus/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 colValidators: { [key: string]: (value: any) => boolean };\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TPasteReducerReturn {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n isFocused: false,\n updateParameters: { arguments: [], timing: 0 },\n });\n const validators = useColumnValidatesContext();\n const focus = useFocusStateContext();\n\n useEffect(() => {\n if (focus.isFocus) {\n dispatch({\n type: \"focus\",\n payload: { rowIndex: focus.rowIndex, colIndex: focus.colIndex },\n });\n } else {\n dispatch({ type: \"unfocus\" });\n }\n }, [focus]);\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 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","focus","useFocusStateContext","useEffect","isFocus","setRows","useCallback","setCols","setColValidators","setOnUpdateRowFunction","onPaste","_b","call","useMemo"],"mappings":"+JAKMA,EAAyB,SAACC,EAAOC,SACrC,OAA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x-runtime"),t=require("react"),
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../libs/generate-validate-function.js"),n=t.createContext({id:""});var o=t.createContext({cols:[],colMaps:{},validates:{}});exports.ColumnsProvider=function(n){var u=n.children,s=n.cols,i=n.errorHandler,a=t.useMemo((function(){return s.reduce((function(e,t){return e[t.key]=t,e}),{})}),[s]),c=t.useMemo((function(){return s.reduce((function(e,t){return e[t.key]=r.generateValidateFunction(t,i),e}),{})}),[s]),l=t.useMemo((function(){return{cols:s,colMaps:a,validates:c}}),[s]);return e.jsx(o.Provider,{value:l,children:u})},exports.RowProvider=function(t){var r=t.children,o=t.row;return e.jsx(n.Provider,{value:o,children:r})},exports.useColumnContext=function(e){return t.useContext(o).colMaps[e]},exports.useColumnValidateContext=function(e){return t.useContext(o).validates[e]},exports.useColumnValidatesContext=function(){return t.useContext(o).validates},exports.useColumnsContext=function(){return t.useContext(o).cols},exports.useRowContext=function(){return t.useContext(n)};
|
|
3
3
|
//# sourceMappingURL=providers.js.map
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{__assign as o}from"../../node_modules/tslib/tslib.es6.js";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useTable as t}from"./hook.js";import{TableHeaderElement as i}from"./header/header.js";import{PagenationProvider as n}from"./pagenation/providers.js";import{DisplayRange as l,Pagenation as
|
|
2
|
+
import{__assign as o}from"../../node_modules/tslib/tslib.es6.js";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useTable as t}from"./hook.js";import{TableHeaderElement as i}from"./header/header.js";import{PagenationProvider as n}from"./pagenation/providers.js";import{DisplayRange as l,Pagenation as a}from"./pagenation/components.js";import{FilterProvider as d,useFilterContext as s}from"./filter/provider.js";import{TableFilterRemoveButton as c,TableFilterForm as m}from"./filter/components.js";import"./sort/icon.js";import{SortProvider as p}from"./sort/provider.js";import{ColumnsProvider as h}from"./sheet/providers.js";import{FocusProvider as f}from"./focus/provider.js";import{CheckboxProvider as g,CheckboxStatusProvider as u}from"./checkbox/provider.js";import{AllCheckbox as v}from"./checkbox/components.js";import{IdGenerator as b}from"./libs/id-generator.js";import{EditProvider as w}from"./edit/provider.js";import{TablePropertyProvider as x}from"./table-property/provider.js";import{KeyboardSetting as j}from"./operation/components/keyboard-setting.js";import{Row as y}from"./sheet/components.js";import{PasteProvider as k,usePasteActionContext as N}from"./paste/provider.js";import{generateFormattingString as C}from"./libs/conditional-formatting.js";import{Editor as R}from"./edit/ui/editor.js";function F(t){var i,l,a;return r(d,{children:r(p,{initialCondition:null===(i=t.initialCondition)||void 0===i?void 0:i.sort,children:r(n,{rowCount:t.rows.length,perPage:null===(a=null===(l=t.initialCondition)||void 0===l?void 0:l.pagenation)||void 0===a?void 0:a.rowCountPerPage,children:r(g,{checkbox:t.checkbox,children:r(u,{checkboxCount:t.rows.length,children:r(h,{cols:t.cols,errorHandler:t.errorHandler,children:r(f,{children:r(w,{children:r(x,{children:e(k,{rows:t.rows,cols:t.cols,colValidators:{},onUpdateRowFunction:t.onUpdateRow,children:[r(j,{}),r(P,o({},t))]})})})})})})})})})})}function P(o){var n=t(o),d=n.cols,p=n.rowMaps,h=n.pageRowIds,f=s().selectedFilterKey,g=N().onPaste;return e("div",{className:"w-full",children:[r("div",{className:"flex justify-end mb-1 mr-3",children:r(c,{children:r("p",{className:"text-xs underline text-gray-500 hover:text-gray-700",children:"全てのフィルタリング条件を解除する"})})}),e("div",{id:"table-frame",className:"relative h-full max-w-full max-h-[80vh] border border-gray-200 rounded-md overflow-auto",children:[r(R,{rowMaps:p,pageRowIds:h}),e("table",{className:"table",onPaste:function(o){o.preventDefault();var r=o.clipboardData.getData("Text");g(r.replace(/\t/g,",").trim().replace(/\r\n/g,"\n").split("\n").map((function(o){return o.split(",")})))},children:[r("thead",{children:e("tr",{className:"sticky top-0 border-gray-200 z-20 bg-gray-200 text-gray-600 h-[32px]",children:[o.checkbox&&r("th",{children:r(v,{rows:o.rows})}),d.map((function(o,e){return r(i,{id:b.getTableColId(e),columnKey:o.key},o.key)}))]})}),e("tbody",{children:[!!f&&r("tr",{children:r("td",{colSpan:d.length,className:"sticky top-8 left-0 bg-gray-300 w-full shadow-lg rounded-b-2xl z-20 p-0 overflow-hidden",children:r(m,{})})}),0===h.length&&r("tr",{children:r("td",{colSpan:d.length,className:"py-5",children:r("p",{className:"text-center font-bold text-lg",children:"NO DATA"})})}),h.map((function(e,t){return r(y,{existCheckbox:!!o.checkbox,rowIndex:t,dataString:p[e].stringValue,cols:o.cols,onClickRow:o.onClickRow,applyRowFormatting:o.applyRowFormatting,conditionalFormattingString:C(p[e].data,d,o.conditionalFormattings),onUpdateRow:o.onUpdateRow},e)}))]})]})]}),e("div",{className:"mt-1",children:[r(l,{}),r("div",{className:"mt-2",children:r(a,{})})]})]})}export{F as default};
|
|
3
3
|
//# sourceMappingURL=base.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsx as e}from"react/jsx-runtime";import{createContext as r,useContext as n,useMemo as t
|
|
1
|
+
import{jsx as e}from"react/jsx-runtime";import{createContext as r,useContext as n,useMemo as t}from"react";import{useColumnContext as o,useRowContext as i}from"../sheet/providers.js";var u=r({type:"string"});function d(r){var n,d,l=r.children,c=r.columnKey,p=o(c),a=i(),m=a[c],v="select"===p.type?null===(d=null===(n=p.options)||void 0===n?void 0:n.find((function(e){return e.value===m})))||void 0===d?void 0:d.label:m,f=t((function(){return p.editable?v:p.render?p.render(m,a):v}),[p.editable,v,m,a]),s=!p.editable&&p.render?"component":p.type,y=t((function(){return{component:f,type:s}}),[s,f]);return e(u.Provider,{value:y,children:l})}function l(){return n(u)}export{d as CellProvider,l as useCellContext};
|
|
2
2
|
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/cell/provider.tsx"],"sourcesContent":["import { createContext,
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/cell/provider.tsx"],"sourcesContent":["import { createContext, useContext, useMemo } from \"react\";\nimport { TColumnType } from \"../type\";\nimport { useColumnContext, useRowContext } from \"../sheet\";\n\nconst CellContext = createContext<{\n type: TColumnType | \"component\";\n component?: React.ReactNode;\n}>({\n type: \"string\",\n});\n\nexport function CellProvider({\n children,\n columnKey,\n}: {\n children: React.ReactNode;\n columnKey: string;\n}) {\n const col = useColumnContext(columnKey);\n const row = useRowContext();\n const value = row[columnKey];\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 cellStatus = useMemo(\n () => ({\n component,\n type,\n }),\n [type, component]\n );\n\n return (\n <CellContext.Provider value={cellStatus}>{children}</CellContext.Provider>\n );\n}\n\nexport function useCellContext() {\n return useContext(CellContext);\n}\n"],"names":["CellContext","createContext","type","CellProvider","_a","children","columnKey","col","useColumnContext","row","useRowContext","value","label","_b","options","find","op","_c","component","useMemo","editable","render","cellStatus","_jsx","Provider","useCellContext","useContext"],"mappings":"uLAIA,IAAMA,EAAcC,EAGjB,CACDC,KAAM,WAGF,SAAUC,EAAaC,WAC3BC,EAAQD,EAAAC,SACRC,EAASF,EAAAE,UAKHC,EAAMC,EAAiBF,GACvBG,EAAMC,IACNC,EAAQF,EAAIH,GAEZM,EACS,WAAbL,EAAIL,KAC6C,UAAlC,QAAXW,EAAAN,EAAIO,eAAO,IAAAD,OAAA,EAAAA,EAAEE,MAAK,SAACC,GAAO,OAAAA,EAAGL,QAAUA,CAAb,WAAmB,IAAAM,OAAA,EAAAA,EAAEL,MAC/CD,EAEAO,EAAYC,GAAQ,WACxB,OAAIZ,EAAIa,SACCR,EAEAL,EAAIc,OAASd,EAAIc,OAAOV,EAAgBF,GAAOG,CAE1D,GAAG,CAACL,EAAIa,SAAUR,EAAOD,EAAOF,IAE1BP,GACHK,EAAIa,UAAYb,EAAIc,OAAS,YAAcd,EAAIL,KAE5CoB,EAAaH,GACjB,WAAM,MAAC,CACLD,UAASA,EACThB,KAAIA,KAEN,CAACA,EAAMgB,IAGT,OACEK,EAACvB,EAAYwB,SAAQ,CAACb,MAAOW,EAAUjB,SAAGA,GAE9C,UAEgBoB,IACd,OAAOC,EAAW1B,EACpB"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useRef as n,useEffect as r}from"react";import{CancelIcon as o}from"../../cancel-icon.js";function i(i){var u=n(null);return r((function(){u.current&&u.current.focus()}),[u]),e("div",{className:"flex justify-between gap-1 w-full items-center",onClick:function(e){e.preventDefault(),e.stopPropagation()},children:[t("input",{ref:u,className:"w-full py-1 px-2 bg-white text-gray-900",type:"text",value:i.value,onChange:i.onChange,onBlur:i.onBlur,onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(i.reset(),i.endEditing())}}),t("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){i.reset(),i.endEditing()}),300)},children:t(o,{size:16})})]})}export{i as CellInput};
|
|
2
3
|
//# sourceMappingURL=base-input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base-input.js","sources":[
|
|
1
|
+
{"version":3,"file":"base-input.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as e,Fragment as
|
|
2
|
+
import{jsx as e,Fragment as o,jsxs as l}from"react/jsx-runtime";import{useCell as i}from"../../hook.js";import{EditButton as t}from"./edit-button.js";import{memo as n}from"react";import{IdGenerator as c}from"../../libs/id-generator.js";import{useCellContext as r,CellProvider as a}from"../provider.js";import{useColumnContext as d}from"../../sheet/providers.js";var s=n((function(l){return e(o,{children:"component"===l.type?l.component:e("div",{onDoubleClick:l.onDoubleClick,children:e("p",{className:"cell-data text-left whitespace-nowrap",children:l.component})})})})),m=n((function(o){var i=r();return e("td",{id:o.id,className:"".concat(o.cellFormatClassName),children:e("div",{className:"relative",onClick:o.isExistOnClickRow?void 0:function(e){e.preventDefault(),o.focusAtCell()},onDoubleClick:o.isExistOnClickRow?void 0:o.onDoubleClickCellToEdit,children:e("div",{id:"".concat(o.id,"-display"),children:l("div",{className:"flex items-center gap-3 w-fit p-2 cursor-default",onClick:function(e){e.preventDefault(),e.stopPropagation(),o.focusAtCell()},children:[e(s,{type:i.type,component:i.component,onDoubleClick:o.onDoubleClickCellToEdit}),o.editable&&e(t,{})]})})})})}));function p(o){var l,t=i(o.rowIndex,o.colIndex),n=t.focusAtCell,r=t.onDoubleClickCellToEdit,s=d(o.columnKey);return e(a,{columnKey:o.columnKey,children:e(m,{id:c.getTableCellId(o.rowIndex,o.colIndex),editable:null!==(l=s.editable)&&void 0!==l&&l,cellFormatClassName:o.cellFormatClassName,focusAtCell:n,onDoubleClickCellToEdit:r,isExistOnClickRow:o.isExistOnClickRow,isExistOnUpdateRow:!!o.onUpdateRow})})}export{p as TableCell};
|
|
3
3
|
//# sourceMappingURL=cell.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{jsx as t,Fragment as e,jsxs as r}from"react/jsx-runtime";import{useEffect as o}from"react";import{useFocusStateContext as i}from"../../focus/provider.js";import{useColumnsContext as n}from"../../sheet/providers.js";import{useEditStateContext as l,useEditActionContext as d}from"../provider.js";import{NumberCellInput as p}from"./number-input.js";import{SelectCellInput as s}from"./select-input.js";import{StringCellInput as c}from"./string-input.js";import{IdGenerator as f}from"../../libs/id-generator.js";function m(m){var u=i(),a=l(),g=d(),w=n();if(o((function(){u.isFocus&&!w[u.colIndex].editable&&g.endEditing()}),[a,u]),!a.isEditing)return t(e,{});if(!u.isFocus)return t(e,{});var h=w[u.colIndex],v=m.rowMaps[m.pageRowIds[u.rowIndex]].data;if(!h.editable)return t(e,{});var I=f.getTableCellId(u.rowIndex,u.colIndex),b=document.getElementById(I),j=null==b?void 0:b.getBoundingClientRect(),x=j?{width:j.width,height:j.height,top:j.top,left:j.left}:void 0;if(!x)return t(e,{});var y=document.getElementById("table-frame");if(!y)return t(e,{});var B=y.getBoundingClientRect();return x.top-=B.top-y.scrollTop-window.scrollY,x.left-=B.left-y.scrollLeft-window.scrollX,r("div",{className:"absolute top-0 left-0 grid place-items-center z-10 pr-2",onClick:function(t){t.preventDefault(),t.stopPropagation()},style:{width:x.width,height:x.height,top:x.top-1,left:x.left},children:["string"===h.type&&t(c,{col:h,row:v}),"number"===h.type&&t(p,{col:h,row:v}),"select"===h.type&&t(s,{col:h,row:v})]})}export{m as Editor};
|
|
2
|
+
//# sourceMappingURL=editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editor.js","sources":["../../../../../../src/table/edit/ui/editor.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useFocusStateContext } from \"../../focus/provider\";\nimport { useColumnsContext } from \"../../sheet/providers\";\nimport { useEditActionContext, useEditStateContext } from \"../provider\";\nimport { NumberCellInput } from \"./number-input\";\nimport { SelectCellInput } from \"./select-input\";\nimport { StringCellInput } from \"./string-input\";\nimport { IdGenerator } from \"../../libs\";\nimport { DataObject, DataRecord } from \"../../type\";\n\ntype TPropsEditor = {\n pageRowIds: (string | number)[];\n rowMaps: {\n [id: string]: {\n data: DataObject<DataRecord>;\n stringValue: string;\n };\n [id: number]: {\n data: DataObject<DataRecord>;\n stringValue: string;\n };\n };\n};\n\nexport function Editor(props: TPropsEditor) {\n const focus = useFocusStateContext();\n const edit = useEditStateContext();\n const editActions = useEditActionContext();\n const cols = useColumnsContext();\n\n useEffect(() => {\n if (focus.isFocus && !cols[focus.colIndex].editable) {\n editActions.endEditing();\n }\n }, [edit, focus]);\n\n if (!edit.isEditing) return <></>;\n if (!focus.isFocus) return <></>;\n\n const col = cols[focus.colIndex];\n const row = props.rowMaps[props.pageRowIds[focus.rowIndex]].data;\n\n if (!col.editable) return <></>;\n\n const id = IdGenerator.getTableCellId(focus.rowIndex, focus.colIndex);\n const cellElement = document.getElementById(id);\n const rect = cellElement?.getBoundingClientRect();\n\n const size = rect\n ? {\n width: rect.width,\n height: rect.height,\n top: rect.top,\n left: rect.left,\n }\n : undefined;\n\n if (!size) return <></>;\n\n const tableElement = document.getElementById(\"table-frame\");\n if (!tableElement) return <></>;\n const rectTable = tableElement.getBoundingClientRect();\n\n size.top -= rectTable.top - tableElement.scrollTop - window.scrollY;\n size.left -= rectTable.left - tableElement.scrollLeft - window.scrollX;\n\n return (\n <div\n className=\"absolute top-0 left-0 grid place-items-center z-10 pr-2\"\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n style={{\n width: size.width,\n height: size.height,\n top: size.top - 1,\n left: size.left,\n }}\n >\n {col.type === \"string\" && <StringCellInput col={col} row={row} />}\n {col.type === \"number\" && <NumberCellInput col={col} row={row} />}\n {col.type === \"select\" && <SelectCellInput col={col} row={row} />}\n </div>\n );\n}\n"],"names":["Editor","props","focus","useFocusStateContext","edit","useEditStateContext","editActions","useEditActionContext","cols","useColumnsContext","useEffect","isFocus","colIndex","editable","endEditing","isEditing","_jsx","col","row","rowMaps","pageRowIds","rowIndex","data","id","IdGenerator","getTableCellId","cellElement","document","getElementById","rect","getBoundingClientRect","size","width","height","top","left","undefined","tableElement","rectTable","scrollTop","window","scrollY","scrollLeft","scrollX","_jsxs","className","onClick","e","preventDefault","stopPropagation","style","children","type","StringCellInput","NumberCellInput","SelectCellInput"],"mappings":"kgBAwBM,SAAUA,EAAOC,GACrB,IAAMC,EAAQC,IACRC,EAAOC,IACPC,EAAcC,IACdC,EAAOC,IAQb,GANAC,GAAU,WACJR,EAAMS,UAAYH,EAAKN,EAAMU,UAAUC,UACzCP,EAAYQ,YAEhB,GAAG,CAACV,EAAMF,KAELE,EAAKW,UAAW,OAAOC,QAC5B,IAAKd,EAAMS,QAAS,OAAOK,QAE3B,IAAMC,EAAMT,EAAKN,EAAMU,UACjBM,EAAMjB,EAAMkB,QAAQlB,EAAMmB,WAAWlB,EAAMmB,WAAWC,KAE5D,IAAKL,EAAIJ,SAAU,OAAOG,QAE1B,IAAMO,EAAKC,EAAYC,eAAevB,EAAMmB,SAAUnB,EAAMU,UACtDc,EAAcC,SAASC,eAAeL,GACtCM,EAAOH,eAAAA,EAAaI,wBAEpBC,EAAOF,EACT,CACEG,MAAOH,EAAKG,MACZC,OAAQJ,EAAKI,OACbC,IAAKL,EAAKK,IACVC,KAAMN,EAAKM,WAEbC,EAEJ,IAAKL,EAAM,OAAOf,QAElB,IAAMqB,EAAeV,SAASC,eAAe,eAC7C,IAAKS,EAAc,OAAOrB,QAC1B,IAAMsB,EAAYD,EAAaP,wBAK/B,OAHAC,EAAKG,KAAOI,EAAUJ,IAAMG,EAAaE,UAAYC,OAAOC,QAC5DV,EAAKI,MAAQG,EAAUH,KAAOE,EAAaK,WAAaF,OAAOG,QAG7DC,SACEC,UAAU,0DACVC,QAAS,SAACC,GACRA,EAAEC,iBACFD,EAAEE,iBACH,EACDC,MAAO,CACLlB,MAAOD,EAAKC,MACZC,OAAQF,EAAKE,OACbC,IAAKH,EAAKG,IAAM,EAChBC,KAAMJ,EAAKI,MAGZgB,SAAA,CAAa,WAAblC,EAAImC,MAAqBpC,EAACqC,EAAgB,CAAApC,IAAKA,EAAKC,IAAKA,IAC5C,WAAbD,EAAImC,MAAqBpC,EAACsC,EAAe,CAACrC,IAAKA,EAAKC,IAAKA,IAC5C,WAAbD,EAAImC,MAAqBpC,EAACuC,EAAe,CAACtC,IAAKA,EAAKC,IAAKA,MAGhE"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as t}from"react/jsx-runtime";import{useState as e}from"react";import{useColumnValidateContext as r}from"../../sheet/providers.js";import{CellInput as o}from"../../cell/ui/base-input.js";import{useEditActionContext as n}from"../provider.js";function u(u){var a=u.col,i=r(a.key),l=n().endEditing,m=u.row[a.key],f=e(m.toString()),g=f[0],v=f[1];return t(o,{value:g,onChange:function(t){t.preventDefault(),""!==t.target.value?"-"!==t.target.value&&"0-"!==t.target.value?t.target.value.match(/^-?[0-9]+\.$/)?v(t.target.value):isNaN(Number(t.target.value))||v(Number(t.target.value).toString()):v("-0"):v("0")},onBlur:function(t){t.preventDefault(),Number(g)!==m?i(g)?function(t){a.editable&&a.onCellBlur(a.key,Number(t),u.row,l)}(g):setTimeout((function(){t.target.focus()}),100):l()},reset:function(){return v(m.toString())},endEditing:l})}export{u as NumberCellInput};
|
|
3
|
+
//# sourceMappingURL=number-input.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as e,Fragment as t,jsxs as n}from"react/jsx-runtime";import{useState as o}from"react";import{useEditActionContext as r}from"../provider.js";import{CancelIcon as l}from"../../cancel-icon.js";function i(i){var a=i.col,u=r().endEditing,c=i.row[a.key],p=o(c),f=p[0],m=p[1];return a.editable?n("div",{className:"flex justify-between gap-1 w-full items-center",children:[n("select",{className:"w-full py-1 px-2 bg-white text-gray-900",value:f,onChange:function(e){e.preventDefault(),m(e.target.value)},onBlur:function(e){e.preventDefault(),f!==c?function(e){a.editable&&a.onCellBlur(a.key,e,i.row,u)}(f):u()},onKeyDown:function(e){"Enter"===e.key&&e.preventDefault()},onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(m(c),u())},children:[a.allowEmpty&&e("option",{value:"",children:""==c?"-- 未選択 --":"-- 選択解除 --"},"TEPPEN/ReactUI Empty Option"),a.options.map((function(t){return e("option",{value:t.value,children:t.label},t.value)}))]}),e("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){m(c),u()}),300)},children:e(l,{size:16})})]}):e(t,{})}export{i as SelectCellInput};
|
|
3
|
+
//# sourceMappingURL=select-input.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import{jsx as e}from"react/jsx-runtime";import{useState as t}from"react";import{useEditActionContext as r}from"../provider.js";import{useColumnValidateContext as o}from"../../sheet/providers.js";import{CellInput as n}from"../../cell/ui/base-input.js";function i(i){var u=i.col,f=o(u.key),a=r().endEditing,l=i.row[u.key],m=t(l),c=m[0],p=m[1];return e(n,{value:c,onChange:function(e){e.preventDefault(),p(e.target.value)},onBlur:function(e){e.preventDefault(),c!==l?f(c)?function(e){u.editable&&u.onCellBlur(u.key,e,i.row,a)}(c):setTimeout((function(){e.target.focus()}),100):a()},reset:function(){return p(l.toString())},endEditing:a})}export{i as StringCellInput};
|
|
3
|
+
//# sourceMappingURL=string-input.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useMemo as
|
|
1
|
+
import{useMemo as r,useEffect as t,useCallback as o}from"react";import{usePageContext as e}from"./pagenation/providers.js";import"react/jsx-runtime";import{useFilterContext as n}from"./filter/provider.js";import"./filter/constants.js";import"./sheet/providers.js";import{useFocusActionContext as i}from"./focus/provider.js";import{useCheckboxStatusContext as u}from"./checkbox/provider.js";import{useEditActionContext as c}from"./edit/provider.js";import{useSortActionContext as s,useSortTimingContext as f}from"./sort/provider.js";import{useTablePropertyActionContext as a}from"./table-property/provider.js";import{usePasteActionContext as p}from"./paste/provider.js";function l(o){var i=n().filter,c=s(),l=c.sort,d=c.updatedData,m=f(),v=e(),h=v.setRowCount,g=v.pageFilter,w=u().dispatchCheckboxStatus,j=p().setRows,k=a(),x=k.setMaxDisplayColCount,b=k.setMaxDisplayRowCount,C=r((function(){return i(o.rows)}),[i,m,o.rows.length]);t((function(){h(C.length)}),[C.length]);var y=r((function(){return o.checkbox?o.rows.filter((function(r){var t;return null===(t=o.checkbox)||void 0===t?void 0:t.checked(r)})):[]}),[o.checkbox,o.rows]);t((function(){w({type:"SET",payload:{checkedRecords:y}})}),[y]);var D=r((function(){return l(C)}),[C,m]);t((function(){d()}),[o.rows]);var R=r((function(){return g(D)}),[g,D]),S=r((function(){return R.map((function(r){return r.id}))}),[R]),E=r((function(){return new Set(S)}),[S]),M=r((function(){return o.rows.filter((function(r){return E.has(r.id)})).reduce((function(r,t){var o=Object.keys(t).sort().reduce((function(r,o){return r[o]=t[o],r}),{});return r[t.id]={data:o,stringValue:JSON.stringify(o)},r}),{})}),[o.rows,E]);return t((function(){x(o.cols.length)}),[o.cols.length]),t((function(){b(S.length)}),[S.length]),t((function(){j(S.map((function(r){return M[r].data})))}),[M]),{cols:o.cols,rowMaps:M,pageRowIds:S}}function d(r,t){var e=i(),n=c();return{focusAtCell:o((function(){e.move(r,t),e.focus(r,t)}),[e,r,t]),onDoubleClickCellToEdit:o((function(o){o.preventDefault(),e.move(r,t),e.focus(r,t),n.startEditing()}),[e,n,r,t])}}export{d as useCell,l as useTable};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../src/table/hook.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo } from \"react\";\nimport { DataObject, DataRecord, TPropsTable } from \"./type\";\nimport { usePageContext } from \"./pagenation/providers\";\nimport { useFilterContext } from \"./filter\";\nimport { useFocusActionContext } from \"./focus/provider\";\nimport { useCheckboxStatusContext } from \"./checkbox/provider\";\nimport { useEditActionContext } from \"./edit/provider\";\nimport { useSortActionContext, useSortTimingContext } from \"./sort/provider\";\nimport { useTablePropertyActionContext } from \"./table-property/provider\";\nimport { usePasteActionContext } from \"./paste/provider\";\n\nexport function useTable<T extends DataRecord>(props: TPropsTable<T>) {\n const { filter } = useFilterContext();\n const { sort, updatedData } = useSortActionContext();\n const sortTiming = useSortTimingContext();\n const { setRowCount, pageFilter } = usePageContext();\n const { dispatchCheckboxStatus } = useCheckboxStatusContext();\n const { setRows } = usePasteActionContext();\n const { setMaxDisplayColCount, setMaxDisplayRowCount } =\n useTablePropertyActionContext();\n\n const filteredRows = useMemo(\n () => filter(props.rows),\n [filter, sortTiming, props.rows.length]\n );\n\n useEffect(() => {\n setRowCount(filteredRows.length);\n }, [filteredRows.length]);\n\n const checkBoxes = useMemo(() => {\n if (!props.checkbox) {\n return [];\n }\n\n return props.rows.filter((row) => props.checkbox?.checked(row));\n }, [props.checkbox, props.rows]);\n\n useEffect(() => {\n dispatchCheckboxStatus({\n type: \"SET\",\n payload: { checkedRecords: checkBoxes },\n });\n }, [checkBoxes]);\n\n const sortedRows = useMemo(\n () => sort(filteredRows),\n [filteredRows, sortTiming]\n );\n\n useEffect(() => {\n updatedData();\n }, [props.rows]);\n\n const pageRows = useMemo(\n () => pageFilter(sortedRows),\n [pageFilter, sortedRows]\n );\n\n const pageRowIds = useMemo(() => pageRows.map((row) => row.id), [pageRows]);\n const pageRowIdSets = useMemo(() => new Set(pageRowIds), [pageRowIds]);\n\n const rowMaps = useMemo(\n () =>\n props.rows\n .filter((row) => pageRowIdSets.has(row.id))\n .reduce((acc, row) => {\n const rowSortedByKey = Object.keys(row)\n .sort()\n .reduce((acc, key) => {\n acc[key] = row[key];\n return acc;\n }, {} as { [key: string]: string | number });\n\n acc[row.id] = {\n data: rowSortedByKey,\n stringValue: JSON.stringify(rowSortedByKey),\n };\n return acc;\n }, {} as { [id: string | number]: { data: DataObject<any>; stringValue: string } }),\n [props.rows, pageRowIdSets]\n );\n\n useEffect(() => {\n setMaxDisplayColCount(props.cols.length);\n }, [props.cols.length]);\n\n useEffect(() => {\n setMaxDisplayRowCount(pageRowIds.length);\n }, [pageRowIds.length]);\n\n useEffect(() => {\n setRows(pageRowIds.map((id) => rowMaps[id].data));\n }, [rowMaps]);\n\n return {\n cols: props.cols,\n rowMaps,\n pageRowIds,\n };\n}\n\nexport function useCell(rowIndex: number, colIndex: number) {\n const focus = useFocusActionContext();\n const editAction = useEditActionContext();\n
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../src/table/hook.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo } from \"react\";\nimport { DataObject, DataRecord, TPropsTable } from \"./type\";\nimport { usePageContext } from \"./pagenation/providers\";\nimport { useFilterContext } from \"./filter\";\nimport { useFocusActionContext } from \"./focus/provider\";\nimport { useCheckboxStatusContext } from \"./checkbox/provider\";\nimport { useEditActionContext } from \"./edit/provider\";\nimport { useSortActionContext, useSortTimingContext } from \"./sort/provider\";\nimport { useTablePropertyActionContext } from \"./table-property/provider\";\nimport { usePasteActionContext } from \"./paste/provider\";\n\nexport function useTable<T extends DataRecord>(props: TPropsTable<T>) {\n const { filter } = useFilterContext();\n const { sort, updatedData } = useSortActionContext();\n const sortTiming = useSortTimingContext();\n const { setRowCount, pageFilter } = usePageContext();\n const { dispatchCheckboxStatus } = useCheckboxStatusContext();\n const { setRows } = usePasteActionContext();\n const { setMaxDisplayColCount, setMaxDisplayRowCount } =\n useTablePropertyActionContext();\n\n const filteredRows = useMemo(\n () => filter(props.rows),\n [filter, sortTiming, props.rows.length]\n );\n\n useEffect(() => {\n setRowCount(filteredRows.length);\n }, [filteredRows.length]);\n\n const checkBoxes = useMemo(() => {\n if (!props.checkbox) {\n return [];\n }\n\n return props.rows.filter((row) => props.checkbox?.checked(row));\n }, [props.checkbox, props.rows]);\n\n useEffect(() => {\n dispatchCheckboxStatus({\n type: \"SET\",\n payload: { checkedRecords: checkBoxes },\n });\n }, [checkBoxes]);\n\n const sortedRows = useMemo(\n () => sort(filteredRows),\n [filteredRows, sortTiming]\n );\n\n useEffect(() => {\n updatedData();\n }, [props.rows]);\n\n const pageRows = useMemo(\n () => pageFilter(sortedRows),\n [pageFilter, sortedRows]\n );\n\n const pageRowIds = useMemo(() => pageRows.map((row) => row.id), [pageRows]);\n const pageRowIdSets = useMemo(() => new Set(pageRowIds), [pageRowIds]);\n\n const rowMaps = useMemo(\n () =>\n props.rows\n .filter((row) => pageRowIdSets.has(row.id))\n .reduce((acc, row) => {\n const rowSortedByKey = Object.keys(row)\n .sort()\n .reduce((acc, key) => {\n acc[key] = row[key];\n return acc;\n }, {} as { [key: string]: string | number });\n\n acc[row.id] = {\n data: rowSortedByKey,\n stringValue: JSON.stringify(rowSortedByKey),\n };\n return acc;\n }, {} as { [id: string | number]: { data: DataObject<any>; stringValue: string } }),\n [props.rows, pageRowIdSets]\n );\n\n useEffect(() => {\n setMaxDisplayColCount(props.cols.length);\n }, [props.cols.length]);\n\n useEffect(() => {\n setMaxDisplayRowCount(pageRowIds.length);\n }, [pageRowIds.length]);\n\n useEffect(() => {\n setRows(pageRowIds.map((id) => rowMaps[id].data));\n }, [rowMaps]);\n\n return {\n cols: props.cols,\n rowMaps,\n pageRowIds,\n };\n}\n\nexport function useCell(rowIndex: number, colIndex: number) {\n const focus = useFocusActionContext();\n const editAction = useEditActionContext();\n\n const focusAtCell = useCallback(() => {\n focus.move(rowIndex, colIndex);\n focus.focus(rowIndex, colIndex);\n }, [focus, rowIndex, colIndex]);\n\n const onDoubleClickCellToEdit: React.MouseEventHandler<HTMLDivElement> =\n useCallback(\n (e) => {\n e.preventDefault();\n focus.move(rowIndex, colIndex);\n focus.focus(rowIndex, colIndex);\n editAction.startEditing();\n },\n [focus, editAction, rowIndex, colIndex]\n );\n\n return {\n focusAtCell,\n onDoubleClickCellToEdit,\n };\n}\n"],"names":["useTable","props","filter","useFilterContext","_a","useSortActionContext","sort","updatedData","sortTiming","useSortTimingContext","_b","usePageContext","setRowCount","pageFilter","dispatchCheckboxStatus","useCheckboxStatusContext","setRows","usePasteActionContext","_c","useTablePropertyActionContext","setMaxDisplayColCount","setMaxDisplayRowCount","filteredRows","useMemo","rows","length","useEffect","checkBoxes","checkbox","row","checked","type","payload","checkedRecords","sortedRows","pageRows","pageRowIds","map","id","pageRowIdSets","Set","rowMaps","has","reduce","acc","rowSortedByKey","Object","keys","key","data","stringValue","JSON","stringify","cols","useCell","rowIndex","colIndex","focus","useFocusActionContext","editAction","useEditActionContext","focusAtCell","useCallback","move","onDoubleClickCellToEdit","e","preventDefault","startEditing"],"mappings":"6pBAW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AAOC,KAAKlB,GAChCvB,OACAqC,QAAO,SAACC,EAAKI,GAEZ,OADAJ,EAAII,GAAOnB,EAAImB,GACRJ,CACR,GAAE,CAAwC,GAM7C,OAJAA,EAAIf,EAAIS,IAAM,CACZW,KAAMJ,EACNK,YAAaC,KAAKC,UAAUP,IAEvBD,CACR,GAAE,CAA+E,EAAC,GACvF,CAAC3C,EAAMuB,KAAMe,IAef,OAZAb,GAAU,WACRN,EAAsBnB,EAAMoD,KAAK5B,OAClC,GAAE,CAACxB,EAAMoD,KAAK5B,SAEfC,GAAU,WACRL,EAAsBe,EAAWX,OACnC,GAAG,CAACW,EAAWX,SAEfC,GAAU,WACRV,EAAQoB,EAAWC,KAAI,SAACC,GAAO,OAAAG,EAAQH,GAAIW,QAC7C,GAAG,CAACR,IAEG,CACLY,KAAMpD,EAAMoD,KACZZ,QAAOA,EACPL,WAAUA,EAEd,CAEgB,SAAAkB,EAAQC,EAAkBC,GACxC,IAAMC,EAAQC,IACRC,EAAaC,IAkBnB,MAAO,CACLC,YAjBkBC,GAAY,WAC9BL,EAAMM,KAAKR,EAAUC,GACrBC,EAAMA,MAAMF,EAAUC,EACvB,GAAE,CAACC,EAAOF,EAAUC,IAenBQ,wBAZAF,GACE,SAACG,GACCA,EAAEC,iBACFT,EAAMM,KAAKR,EAAUC,GACrBC,EAAMA,MAAMF,EAAUC,GACtBG,EAAWQ,cACZ,GACD,CAACV,EAAOE,EAAYJ,EAAUC,IAOpC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function
|
|
1
|
+
function n(n){var e="入力値が不正のため、エラーを確認し修正してください。\n\n";e+="[対象の列名]: ".concat(n[0].label,"\n"),e+="[入力値] : ".concat(n[0].value,"\n\n"),e+="[エラー内容]:",e+=n.reduce((function(n,e){switch(e.type){case"STRING_IS_TOO_LONG":return n+"\n・文字数が最大の長さ".concat(e.maxLength,"文字を超えています。(現在").concat(e.currentLength,"文字)");case"STRING_IS_TOO_SHORT":return n+"\n・文字数が最小の長さ".concat(e.minLength,"文字に満たないです。(現在").concat(e.currentLength,"文字)");case"STRING_PATTERN_NOT_MATCH":return n+"\n・パターンに一致しません。(パターン".concat(e.pattern,")");case"NUMBER_IS_TOO_LARGE":return n+"\n・最大値".concat(e.max,"を超えています。(入力値").concat(e.value,")");case"NUMBER_IS_TOO_SMALL":return n+"\n・最小値".concat(e.min,"を下回っています。(入力値").concat(e.value,")");case"NOT_NUMBER":return n+"\n・数値ではない値が入力されています。";case"NOT_IN_OPTIONS":return n+"\n・選択肢に含まれていない値です。"}}),""),alert(e)}function e(e,t){if("string"===e.type)return function(e,t,r,a){return function(e){var u=[];return(null==r?void 0:r.maxLength)&&e.length>r.maxLength&&u.push({type:"STRING_IS_TOO_LONG",label:t,maxLength:r.maxLength,currentLength:e.length,value:e}),(null==r?void 0:r.minLength)&&e.length<r.minLength&&u.push({type:"STRING_IS_TOO_SHORT",label:t,minLength:r.minLength,currentLength:e.length,value:e}),(null==r?void 0:r.pattern)&&(new RegExp(r.pattern).test(e)||u.push({type:"STRING_PATTERN_NOT_MATCH",label:t,pattern:r.pattern,value:e})),!(u.length>0&&(a?a(u):n(u),1))}}(e.key,e.label,e.constraints,t);if("number"===e.type)return function(e,t,r,a){return function(e){var u=[];return"string"!=typeof e||/^-?[0-9]+(\.[0-9]+)?$/.test(e)?(e=Number(e),"number"==typeof(null==r?void 0:r.max)&&e>r.max&&u.push({type:"NUMBER_IS_TOO_LARGE",label:t,max:r.max,value:e}),"number"==typeof(null==r?void 0:r.min)&&e<r.min&&u.push({type:"NUMBER_IS_TOO_SMALL",label:t,min:r.min,value:e}),!(u.length>0&&(a?a(u):n(u),1))):(u.push({type:"NOT_NUMBER",label:t,value:e}),a?a(u):n(u),!1)}}(e.key,e.label,e.constraints,t);if("select"===e.type)return function(e,t,r,a,u){var l=new Set(r.map((function(n){return n.label})));return function(e){if(a&&""===e)return!0;var r=[];return l.has(e)||r.push({type:"NOT_IN_OPTIONS",label:t,value:e,options:Array.from(l)}),!(r.length>0&&(u?u(r):n(r),1))}}(e.key,e.label,e.options,e.allowEmpty,t);throw new Error("Invalid type")}export{e as generateValidateFunction};
|
|
2
2
|
//# sourceMappingURL=generate-validate-function.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"generate-validate-function.js","sources":["../../../../../src/table/libs/generate-validate-function.ts"],"sourcesContent":["export type TStringValidateOption = {\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n};\n\nexport type TNumberValidateOption = {\n max?: number;\n min?: number;\n};\n\ntype TPropsGenerateValidateFunction =\n | {\n type: \"string\";\n constraints?: TStringValidateOption;\n }\n | {\n type: \"number\";\n constraints?: TNumberValidateOption;\n }\n | {\n type: \"select\";\n options: { value: string; label: string }[];\n allowEmpty?: boolean;\n };\n\ntype TStringValidateFunction = (value: string) => boolean;\n\nfunction generateStringValidateFunction(\n constraints?: TStringValidateOption\n): TStringValidateFunction {\n return (value: string) => {\n if (constraints?.maxLength) {\n if (value.length > constraints.maxLength) {\n alert(\n `最大文字数(${constraints.maxLength})を超過しています。(現在${value.length}文字)`\n );\n return false;\n }\n }\n if (constraints?.minLength) {\n if (value.length < constraints.minLength) {\n alert(\n `最小文字数(${constraints.minLength})を下回っています。(現在${value.length}文字)`\n );\n return false;\n }\n }\n if (constraints?.pattern) {\n if (!new RegExp(constraints.pattern).test(value)) {\n alert(`パターンに一致しません。(パターン${constraints.pattern})`);\n return false;\n }\n }\n return true;\n };\n}\n\ntype TNumberValidateFunction = (value: number) => boolean;\n\nfunction generateNumberValidateFunction(\n constraints?: TNumberValidateOption\n): TNumberValidateFunction {\n return (value: number | string) => {\n if (typeof value === \"string\") {\n // 小数も含めて数値に変換可能な値かを検査\n if (!/^-?[0-9]+(\\.[0-9]+)?$/.test(value)) {\n alert(\"数値ではない値が入力されています。\");\n return false;\n }\n value = Number(value);\n }\n\n if (typeof constraints?.max === \"number\") {\n if (value > constraints.max) {\n alert(`最大値(${constraints.max})を超過しています。(入力値:${value})`);\n return false;\n }\n }\n\n if (typeof constraints?.min === \"number\") {\n if (value < constraints.min) {\n alert(`最小値(${constraints.min})を下回っています。(入力値:${value})`);\n return false;\n }\n }\n\n return true;\n };\n}\n\ntype TSelectValidateFunction = (label: string) => boolean;\n\nfunction generatSelectValidateFunction(\n options: { value: string; label: string }[],\n allowEmpty?: boolean\n): TSelectValidateFunction {\n const labelSets = new Set(options.map((option) => option.label));\n return (label: string) => {\n if (allowEmpty && label === \"\") {\n return true;\n }\n\n if (!labelSets.has(label)) {\n alert(`選択肢に含まれていない値です。(選択肢:${label})`);\n return false;\n }\n\n return true;\n };\n}\n\nexport function generateValidateFunction(\n props: TPropsGenerateValidateFunction\n) {\n if (props.type === \"string\") {\n return generateStringValidateFunction(props.constraints);\n } else if (props.type === \"number\") {\n return generateNumberValidateFunction(props.constraints);\n } else if (props.type === \"select\") {\n return generatSelectValidateFunction(props.options, props.allowEmpty);\n } else {\n throw new Error(\"Invalid type\");\n }\n}\n"],"names":["generateValidateFunction","props","type","constraints","value","maxLength","length","alert","concat","minLength","pattern","RegExp","test","Number","max","min","generateNumberValidateFunction","options","allowEmpty","labelSets","Set","map","option","label","has","Error"],"mappings":"AAgHM,SAAUA,EACdC,GAEA,GAAmB,WAAfA,EAAMC,KACR,OAvFFC,EAuFwCF,EAAME,YArFvC,SAACC,GACN,OAAID,aAAW,EAAXA,EAAaE,YACXD,EAAME,OAASH,EAAYE,WAC7BE,MACE,SAASC,OAAAL,EAAYE,UAAyB,iBAAAG,OAAAJ,EAAME,OAAW,SAE1D,IAGPH,aAAW,EAAXA,EAAaM,YACXL,EAAME,OAASH,EAAYM,WAC7BF,MACE,SAASC,OAAAL,EAAYM,UAAyB,iBAAAD,OAAAJ,EAAME,OAAW,SAE1D,MAGPH,aAAW,EAAXA,EAAaO,WACV,IAAIC,OAAOR,EAAYO,SAASE,KAAKR,KACxCG,MAAM,oBAAoBC,OAAAL,EAAYO,QAAO,MACtC,GAIb,EA8DO,GAAmB,WAAfT,EAAMC,KACf,OA1DJ,SACEC,GAEA,OAAO,SAACC,GACN,GAAqB,iBAAVA,EAAoB,CAE7B,IAAK,wBAAwBQ,KAAKR,GAEhC,OADAG,MAAM,sBACC,EAETH,EAAQS,OAAOT,EAChB,CAED,MAAgC,iBAArBD,aAAW,EAAXA,EAAaW,MAClBV,EAAQD,EAAYW,KACtBP,MAAM,cAAOJ,EAAYW,IAAqB,mBAAAN,OAAAJ,EAAQ,OAC/C,KAIqB,iBAArBD,aAAW,EAAXA,EAAaY,MAClBX,EAAQD,EAAYY,MACtBR,MAAM,cAAOJ,EAAYY,IAAqB,mBAAAP,OAAAJ,EAAQ,MAC/C,GAKb,CACF,CA6BWY,CAA+Bf,EAAME,aACvC,GAAmB,WAAfF,EAAMC,KACf,OA1BFe,EA0BuChB,EAAMgB,QAzB7CC,EAyBsDjB,EAAMiB,WAvBtDC,EAAY,IAAIC,IAAIH,EAAQI,KAAI,SAACC,GAAW,OAAAA,EAAOC,UAClD,SAACA,GACN,SAAIL,GAAwB,KAAVK,MAIbJ,EAAUK,IAAID,KACjBhB,MAAM,uBAAAC,OAAuBe,EAAK,OAC3B,EAIX,EAaE,MAAM,IAAIE,MAAM,gBA7BpB,IACER,EACAC,EAEMC,EApENhB,CA+FF"}
|
|
1
|
+
{"version":3,"file":"generate-validate-function.js","sources":["../../../../../src/table/libs/generate-validate-function.ts"],"sourcesContent":["export type TStringValidateOption = {\n maxLength?: number;\n minLength?: number;\n pattern?: string;\n};\n\nexport type TNumberValidateOption = {\n max?: number;\n min?: number;\n};\n\ntype TPropsGenerateValidateFunction = {\n key: string;\n label: string;\n} & (\n | {\n type: \"string\";\n constraints?: TStringValidateOption;\n }\n | {\n type: \"number\";\n constraints?: TNumberValidateOption;\n }\n | {\n type: \"select\";\n options: { value: string; label: string }[];\n allowEmpty?: boolean;\n }\n);\n\ntype TStringValidateFunction = (value: string) => boolean;\n\nexport type TErrorValidation = {\n label: string;\n value: string | number;\n} & (\n | {\n type: \"STRING_IS_TOO_LONG\";\n maxLength: number;\n currentLength: number;\n }\n | {\n type: \"STRING_IS_TOO_SHORT\";\n minLength: number;\n currentLength: number;\n }\n | {\n type: \"STRING_PATTERN_NOT_MATCH\";\n pattern: string;\n }\n | {\n type: \"NUMBER_IS_TOO_LARGE\";\n max: number;\n }\n | {\n type: \"NUMBER_IS_TOO_SMALL\";\n min: number;\n }\n | {\n type: \"NOT_NUMBER\";\n }\n | {\n type: \"NOT_IN_OPTIONS\";\n options: string[];\n }\n);\n\nfunction defaultErrorHandler(errors: TErrorValidation[]) {\n let message = `入力値が不正のため、エラーを確認し修正してください。\\n\\n`;\n message += `[対象の列名]: ${errors[0].label}\\n`;\n message += `[入力値] : ${errors[0].value}\\n\\n`;\n message += `[エラー内容]:`;\n\n message += errors.reduce((acc, error) => {\n switch (error.type) {\n case \"STRING_IS_TOO_LONG\":\n return (\n acc +\n `\\n・文字数が最大の長さ${error.maxLength}文字を超えています。(現在${error.currentLength}文字)`\n );\n case \"STRING_IS_TOO_SHORT\":\n return (\n acc +\n `\\n・文字数が最小の長さ${error.minLength}文字に満たないです。(現在${error.currentLength}文字)`\n );\n case \"STRING_PATTERN_NOT_MATCH\":\n return acc + `\\n・パターンに一致しません。(パターン${error.pattern})`;\n case \"NUMBER_IS_TOO_LARGE\":\n return (\n acc + `\\n・最大値${error.max}を超えています。(入力値${error.value})`\n );\n case \"NUMBER_IS_TOO_SMALL\":\n return (\n acc + `\\n・最小値${error.min}を下回っています。(入力値${error.value})`\n );\n case \"NOT_NUMBER\":\n return acc + `\\n・数値ではない値が入力されています。`;\n case \"NOT_IN_OPTIONS\":\n return acc + `\\n・選択肢に含まれていない値です。`;\n }\n }, \"\");\n\n alert(message);\n}\n\nfunction generateStringValidateFunction(\n key: string,\n label: string,\n constraints?: TStringValidateOption,\n errorHandler?: (errors: TErrorValidation[]) => void\n): TStringValidateFunction {\n return (value: string) => {\n const errors: TErrorValidation[] = [];\n\n if (constraints?.maxLength) {\n if (value.length > constraints.maxLength) {\n errors.push({\n type: \"STRING_IS_TOO_LONG\",\n label,\n maxLength: constraints.maxLength,\n currentLength: value.length,\n value,\n });\n }\n }\n\n if (constraints?.minLength) {\n if (value.length < constraints.minLength) {\n errors.push({\n type: \"STRING_IS_TOO_SHORT\",\n label,\n minLength: constraints.minLength,\n currentLength: value.length,\n value,\n });\n }\n }\n\n if (constraints?.pattern) {\n if (!new RegExp(constraints.pattern).test(value)) {\n errors.push({\n type: \"STRING_PATTERN_NOT_MATCH\",\n label,\n pattern: constraints.pattern,\n value,\n });\n }\n }\n\n if (errors.length > 0) {\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n\n return true;\n };\n}\n\ntype TNumberValidateFunction = (value: number) => boolean;\n\nfunction generateNumberValidateFunction(\n key: string,\n label: string,\n constraints?: TNumberValidateOption,\n errorHandler?: (errors: TErrorValidation[]) => void\n): TNumberValidateFunction {\n return (value: number | string) => {\n const errors: TErrorValidation[] = [];\n\n if (typeof value === \"string\") {\n // 小数も含めて数値に変換可能な値かを検査\n if (!/^-?[0-9]+(\\.[0-9]+)?$/.test(value)) {\n errors.push({\n type: \"NOT_NUMBER\",\n label,\n value,\n });\n\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n }\n\n value = Number(value);\n\n if (typeof constraints?.max === \"number\") {\n if (value > constraints.max) {\n errors.push({\n type: \"NUMBER_IS_TOO_LARGE\",\n label,\n max: constraints.max,\n value,\n });\n }\n }\n\n if (typeof constraints?.min === \"number\") {\n if (value < constraints.min) {\n errors.push({\n type: \"NUMBER_IS_TOO_SMALL\",\n label,\n min: constraints.min,\n value,\n });\n }\n }\n\n if (errors.length > 0) {\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n\n return true;\n };\n}\n\ntype TSelectValidateFunction = (label: string) => boolean;\n\nfunction generatSelectValidateFunction(\n key: string,\n columnLabel: string,\n options: { value: string; label: string }[],\n allowEmpty?: boolean,\n errorHandler?: (errors: TErrorValidation[]) => void\n): TSelectValidateFunction {\n const labelSets = new Set(options.map((option) => option.label));\n return (label: string) => {\n if (allowEmpty && label === \"\") {\n return true;\n }\n\n const errors: TErrorValidation[] = [];\n\n if (!labelSets.has(label)) {\n errors.push({\n type: \"NOT_IN_OPTIONS\",\n label: columnLabel,\n value: label,\n options: Array.from(labelSets),\n });\n }\n\n if (errors.length > 0) {\n if (errorHandler) {\n errorHandler(errors);\n } else {\n defaultErrorHandler(errors);\n }\n return false;\n }\n\n return true;\n };\n}\n\nexport function generateValidateFunction(\n props: TPropsGenerateValidateFunction,\n errorHandler?: (errors: TErrorValidation[]) => void\n) {\n if (props.type === \"string\") {\n return generateStringValidateFunction(\n props.key,\n props.label,\n props.constraints,\n errorHandler\n );\n } else if (props.type === \"number\") {\n return generateNumberValidateFunction(\n props.key,\n props.label,\n props.constraints,\n errorHandler\n );\n } else if (props.type === \"select\") {\n return generatSelectValidateFunction(\n props.key,\n props.label,\n props.options,\n props.allowEmpty,\n errorHandler\n );\n } else {\n throw new Error(\"Invalid type\");\n }\n}\n"],"names":["defaultErrorHandler","errors","message","label","value","reduce","acc","error","type","concat","maxLength","currentLength","minLength","pattern","max","min","alert","generateValidateFunction","props","errorHandler","key","constraints","length","push","RegExp","test","generateStringValidateFunction","Number","generateNumberValidateFunction","columnLabel","options","allowEmpty","labelSets","Set","map","option","has","Array","from","generatSelectValidateFunction","Error"],"mappings":"AAmEA,SAASA,EAAoBC,GAC3B,IAAIC,EAAU,iCACdA,GAAW,mBAAYD,EAAO,GAAGE,MAAK,MACtCD,GAAW,mBAAYD,EAAO,GAAGG,MAAK,QACtCF,GAAW,WAEXA,GAAWD,EAAOI,QAAO,SAACC,EAAKC,GAC7B,OAAQA,EAAMC,MACZ,IAAK,qBACH,OACEF,EACA,eAAeG,OAAAF,EAAMG,UAAS,iBAAAD,OAAgBF,EAAMI,cAAkB,OAE1E,IAAK,sBACH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ACf,GACN,IAAMH,EAA6B,GAEnC,MAAqB,iBAAVG,GAEJ,wBAAwBqB,KAAKrB,IAgBpCA,EAAQuB,OAAOvB,GAEiB,iBAArBiB,aAAW,EAAXA,EAAaP,MAClBV,EAAQiB,EAAYP,KACtBb,EAAOsB,KAAK,CACVf,KAAM,sBACNL,MAAKA,EACLW,IAAKO,EAAYP,IACjBV,MAAKA,IAKqB,iBAArBiB,aAAW,EAAXA,EAAaN,MAClBX,EAAQiB,EAAYN,KACtBd,EAAOsB,KAAK,CACVf,KAAM,sBACNL,MAAKA,EACLY,IAAKM,EAAYN,IACjBX,MAAKA,MAKPH,EAAOqB,OAAS,IACdH,EACFA,EAAalB,GAEbD,EAAoBC,GAEf,MA7CLA,EAAOsB,KAAK,CACVf,KAAM,aACNL,MAAKA,EACLC,MAAKA,IAGHe,EACFA,EAAalB,GAEbD,EAAoBC,IAEf,EAsCb,CACF,CAqDW2B,CACLV,EAAME,IACNF,EAAMf,MACNe,EAAMG,YACNF,GAEG,GAAmB,WAAfD,EAAMV,KACf,OAxDJ,SACEY,EACAS,EACAC,EACAC,EACAZ,GAEA,IAAMa,EAAY,IAAIC,IAAIH,EAAQI,KAAI,SAACC,GAAW,OAAAA,EAAOhC,UACzD,OAAO,SAACA,GACN,GAAI4B,GAAwB,KAAV5B,EAChB,OAAO,EAGT,IAAMF,EAA6B,GAWnC,OATK+B,EAAUI,IAAIjC,IACjBF,EAAOsB,KAAK,CACVf,KAAM,iBACNL,MAAO0B,EACPzB,MAAOD,EACP2B,QAASO,MAAMC,KAAKN,OAIpB/B,EAAOqB,OAAS,IACdH,EACFA,EAAalB,GAEbD,EAAoBC,GAEf,GAIX,CACF,CAqBWsC,CACLrB,EAAME,IACNF,EAAMf,MACNe,EAAMY,QACNZ,EAAMa,WACNZ,GAGF,MAAM,IAAIqB,MAAM,eAEpB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as e,useCallback as
|
|
1
|
+
import{__assign as t}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as e,useEffect as o,useCallback as n,useMemo as a}from"react";import{useColumnValidatesContext as r}from"../sheet/providers.js";import{useFocusStateContext as s}from"../focus/provider.js";var u=function(e,o){var n;switch(o.type){case"setRows":return t(t({},e),{rows:o.payload.rows});case"setCols":return t(t({},e),{cols:o.payload.cols});case"setColValidators":return t(t({},e),{colValidators:o.payload.colValidators});case"setOnUpdateRowFunction":return t(t({},e),{onUpdateRowFunction:o.payload.onUpdateRowFunction});case"onPaste":if(!e.isFocused)return e;var a=o.payload.pasteData,r=e.rows,s=e.cols,u=e.colValidators,l=e.rowIndex,i=e.colIndex;if(!e.onUpdateRowFunction)return e;var c={arguments:[],timing:e.updateParameters.timing+1},d=a.length,p=Math.max.apply(Math,a.map((function(t){return t.length})));if(0===d||0===p)return e;if(a.length+l>r.length)return alert("貼り付け先の行数が足りません。"),e;for(var f=0;f<p;f++){if(!(y=s[i+f]).editable)return alert("編集できない列にデータを貼り付けることはできません。\n\n編集不可列: ".concat(null!==(n=y.label)&&void 0!==n?n:y.key)),e}if(p+i>s.length)return alert("貼り付け先の列数が足りません。"),e;for(f=0;f<d;f++)for(var m=a[f],w=0;w<m.length;w++){var y,g=m[w];if(!(0,u[(y=s[i+w]).key])(g))return e}return a.forEach((function(e,o){var n=t({},r[l+o]),a=!1;e.forEach((function(t,e){var o=s[i+e],r="number"===o.type?Number(t):"select"===o.type?""===t?"":o.options.find((function(e){return e.label===t})).value:t;n[o.key]!==r&&(a=!0,n[o.key]=r)})),a&&c.arguments.push({newRow:n,oldRow:r[l+o]})})),c.arguments.length>0?t(t({},e),{updateParameters:c}):e;case"focus":return t(t({},e),{isFocused:!0,rowIndex:o.payload.rowIndex,colIndex:o.payload.colIndex});case"unfocus":return t(t({},e),{isFocused:!1})}};function l(l){var i=e(u,t(t({},l),{isFocused:!1,updateParameters:{arguments:[],timing:0}})),c=i[0],d=i[1],p=r(),f=s();o((function(){f.isFocus?d({type:"focus",payload:{rowIndex:f.rowIndex,colIndex:f.colIndex}}):d({type:"unfocus"})}),[f]);var m=n((function(t){d({type:"setRows",payload:{rows:t}})}),[]),w=n((function(t){d({type:"setCols",payload:{cols:t}})}),[]),y=n((function(t){d({type:"setColValidators",payload:{colValidators:t}})}),[]);o((function(){y(p)}),[p]);var g=n((function(t){d({type:"setOnUpdateRowFunction",payload:{onUpdateRowFunction:t}})}),[]),v=n((function(t){d({type:"onPaste",payload:{pasteData:t}})}),[]);return o((function(){c.updateParameters.arguments.length>0&&c.updateParameters.arguments.forEach((function(t){var e,o=t.newRow,n=t.oldRow;null===(e=c.onUpdateRowFunction)||void 0===e||e.call(c,o,n)}))}),[c.updateParameters.timing,c.onUpdateRowFunction]),a((function(){return{setRows:m,setCols:w,setColValidators:y,setOnUpdateRowFunction:g,onPaste:v}}),[])}export{l as usePasteReducer};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/paste/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useReducer } from \"react\";\nimport { TPasteReducer, TPasteReducerReturn } from \"./types\";\nimport { useColumnValidatesContext } from \"../sheet/providers\";\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
|
|
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 { useFocusStateContext } from \"../focus/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 colValidators: { [key: string]: (value: any) => boolean };\n onUpdateRowFunction?: (newRow: any, oldRow: any) => void;\n}): TPasteReducerReturn {\n const [state, dispatch] = useReducer(reducer, {\n ...initial,\n isFocused: false,\n updateParameters: { arguments: [], timing: 0 },\n });\n const validators = useColumnValidatesContext();\n const focus = useFocusStateContext();\n\n useEffect(() => {\n if (focus.isFocus) {\n dispatch({\n type: \"focus\",\n payload: { rowIndex: focus.rowIndex, colIndex: focus.colIndex },\n });\n } else {\n dispatch({ type: \"unfocus\" });\n }\n }, [focus]);\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 const actions: TPasteReducerReturn = useMemo(\n () => ({\n setRows,\n setCols,\n setColValidators,\n setOnUpdateRowFunction,\n onPaste,\n }),\n []\n );\n\n return actions;\n}\n"],"names":["reducer","state","action","type","__assign","rows","payload","cols","colValidators","onUpdateRowFunction","isFocused","pasteData","rows_1","cols_1","rowIndex_1","rowIndex","colIndex_1","colIndex","updateParameters_1","arguments","timing","updateParameters","rowLength","length","colLength","Math","max","apply","map","row","alert","i","col","editable","concat","_a","label","key","pasteRow","j","pasteValue","validate","forEach","checkUpdatedRow","value","Number","options","find","option","push","newRow","oldRow","usePasteReducer","initial","useReducer","dispatch","validators","useColumnValidatesContext","focus","useFocusStateContext","useEffect","isFocus","setRows","useCallback","setCols","setColValidators","setOnUpdateRowFunction","onPaste","_b","call","useMemo"],"mappings":"kRAKA,IAAMA,EAAyB,SAACC,EAAOC,SACrC,OAAQA,EAAOC,MACb,IAAK,UACH,OAAYC,EAAAA,EAAA,CAAA,EAAAH,IAAOI,KAAMH,EAAOI,QAAQD,OAC1C,IAAK,UACH,OAAYD,EAAAA,EAAA,CAAA,EAAAH,IAAOM,KAAML,EAAOI,QAAQC,OAC1C,IAAK,mBACH,OAAYH,EAAAA,EAAA,CAAA,EAAAH,IAAOO,cAAeN,EAAOI,QAAQE,gBACnD,IAAK,yBACH,OACKJ,EAAAA,EAAA,CAAA,EAAAH,IACHQ,oBAAqBP,EAAOI,QAAQG,sBAExC,IAAK,UACH,IAAKR,EAAMS,UACT,OAAOT,EAGD,IAAAU,EAAcT,EAAOI,kBAE3BM,EAMEX,EAAKI,KALPQ,EAKEZ,EALEM,KACJC,EAIEP,EAAKO,cAHPM,EAGEb,EAHMc,SACRC,EAEEf,EAAKgB,SAET,IAFIhB,sBAGF,OAAOA,EAGT,IAAMiB,EAAmB,CACvBC,UAAW,GACXC,OAAQnB,EAAM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AAE,IAqBH,OAnBAiD,GAAU,WACJ3D,EAAMoB,iBAAiBF,UAAUI,OAAS,GAC5CtB,EAAMoB,iBAAiBF,UAAUuB,SAAQ,SAACP,SAAEe,EAAMf,EAAAe,OAAEC,EAAMhB,EAAAgB,OAC/B,QAAzBiB,EAAAnE,EAAMQ,2BAAmB,IAAA2D,GAAAA,EAAAC,KAAApE,EAAGiD,EAAQC,EACtC,GAEJ,GAAG,CAAClD,EAAMoB,iBAAiBD,OAAQnB,EAAMQ,sBAEJ6D,GACnC,WAAM,MAAC,CACLR,QAAOA,EACPE,QAAOA,EACPC,iBAAgBA,EAChBC,uBAAsBA,EACtBC,QAAOA,EALH,GAON,GAIJ"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{jsx as r}from"react/jsx-runtime";import{createContext as n,useContext as e,useMemo as t}from"react";import{generateValidateFunction as
|
|
2
|
+
import{jsx as r}from"react/jsx-runtime";import{createContext as n,useContext as e,useMemo as t}from"react";import{generateValidateFunction as o}from"../libs/generate-validate-function.js";var i=n({id:""});function u(n){var e=n.children,t=n.row;return r(i.Provider,{value:t,children:e})}function c(){return e(i)}var a=n({cols:[],colMaps:{},validates:{}});function l(n){var e=n.children,i=n.cols,u=n.errorHandler,c=t((function(){return i.reduce((function(r,n){return r[n.key]=n,r}),{})}),[i]),l=t((function(){return i.reduce((function(r,n){return r[n.key]=o(n,u),r}),{})}),[i]),f=t((function(){return{cols:i,colMaps:c,validates:l}}),[i]);return r(a.Provider,{value:f,children:e})}function f(r){return e(a).colMaps[r]}function d(){return e(a).cols}function s(r){return e(a).validates[r]}function v(){return e(a).validates}export{l as ColumnsProvider,u as RowProvider,f as useColumnContext,s as useColumnValidateContext,v as useColumnValidatesContext,d as useColumnsContext,c as useRowContext};
|
|
3
3
|
//# sourceMappingURL=providers.js.map
|
package/dist/index.d.ts
CHANGED
|
@@ -9,6 +9,32 @@ type TNumberValidateOption = {
|
|
|
9
9
|
max?: number;
|
|
10
10
|
min?: number;
|
|
11
11
|
};
|
|
12
|
+
type TErrorValidation = {
|
|
13
|
+
label: string;
|
|
14
|
+
value: string | number;
|
|
15
|
+
} & ({
|
|
16
|
+
type: "STRING_IS_TOO_LONG";
|
|
17
|
+
maxLength: number;
|
|
18
|
+
currentLength: number;
|
|
19
|
+
} | {
|
|
20
|
+
type: "STRING_IS_TOO_SHORT";
|
|
21
|
+
minLength: number;
|
|
22
|
+
currentLength: number;
|
|
23
|
+
} | {
|
|
24
|
+
type: "STRING_PATTERN_NOT_MATCH";
|
|
25
|
+
pattern: string;
|
|
26
|
+
} | {
|
|
27
|
+
type: "NUMBER_IS_TOO_LARGE";
|
|
28
|
+
max: number;
|
|
29
|
+
} | {
|
|
30
|
+
type: "NUMBER_IS_TOO_SMALL";
|
|
31
|
+
min: number;
|
|
32
|
+
} | {
|
|
33
|
+
type: "NOT_NUMBER";
|
|
34
|
+
} | {
|
|
35
|
+
type: "NOT_IN_OPTIONS";
|
|
36
|
+
options: string[];
|
|
37
|
+
});
|
|
12
38
|
|
|
13
39
|
type DataRecord = Record<string, string | number>;
|
|
14
40
|
type DataObject<T extends DataRecord> = T & {
|
|
@@ -49,14 +75,15 @@ type TSelectCellEditingCondition<T extends DataRecord> = ({
|
|
|
49
75
|
onCellBlur: (key: keyof T, value: string, current: DataObject<T>, completeEditing: () => void) => void;
|
|
50
76
|
}));
|
|
51
77
|
type TCellEditingCondition<T extends DataRecord> = TStringCellEditingCondition<T> | TNumberCellEditingCondition<T> | TSelectCellEditingCondition<T>;
|
|
52
|
-
type
|
|
78
|
+
type TColumnProperty<T extends DataRecord> = {
|
|
53
79
|
key: keyof T;
|
|
54
80
|
label?: string;
|
|
55
81
|
disableSort?: boolean;
|
|
56
82
|
disableFilter?: boolean;
|
|
57
83
|
initialWidth?: number;
|
|
58
84
|
minWidth?: number;
|
|
59
|
-
}
|
|
85
|
+
};
|
|
86
|
+
type TTableColumn<T extends DataRecord> = TColumnProperty<T> & TCellEditingCondition<T>;
|
|
60
87
|
type TCheckboxProperty<T extends DataRecord> = {
|
|
61
88
|
checkbox?: {
|
|
62
89
|
checked: (row: DataObject<T>) => boolean;
|
|
@@ -86,6 +113,7 @@ type TPropsTable<T extends DataRecord> = {
|
|
|
86
113
|
};
|
|
87
114
|
applyRowFormatting?: (row: DataObject<T>) => TailwindCssStyle;
|
|
88
115
|
conditionalFormattings?: TConditionalFormatting<T>[];
|
|
116
|
+
errorHandler?: (errors: TErrorValidation[]) => void;
|
|
89
117
|
} & TCheckboxProperty<T>;
|
|
90
118
|
|
|
91
119
|
declare function Table<T extends DataRecord>(props: TPropsTable<T>): react_jsx_runtime.JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../sheet/providers.js"),u=require("./base-input.js"),n=require("../provider.js"),a=require("../../edit/provider.js");exports.NumberCellInput=function(){var i=n.useCellContext(),l=r.useColumnContext(i.columnKey),o=r.useColumnValidateContext(i.columnKey),s=a.useEditActionContext().endEditing,v=t.useState(i.value.toString()),c=v[0],g=v[1];if(!l.editable||"number"!==l.type)throw new Error("Invalid condition");return t.useEffect((function(){g(i.value.toString())}),[i.value]),e.jsx(u.CellInput,{value:c,onChange:function(e){e.preventDefault(),""!==e.target.value?"-"!==e.target.value&&"0-"!==e.target.value?e.target.value.match(/^-?[0-9]+\.$/)?g(e.target.value):isNaN(Number(e.target.value))||g(Number(e.target.value).toString()):g("-0"):g("0")},onBlur:function(e){e.preventDefault(),Number(c)!==i.value?o(c)?i.updateCellValue(c):setTimeout((function(){e.target.focus()}),100):s()},reset:function(){return g(i.value.toString())},endEditing:s})};
|
|
3
|
-
//# sourceMappingURL=number-input.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../../edit/provider.js"),u=require("../../sheet/providers.js"),l=require("../../cancel-icon.js"),r=require("../provider.js");exports.SelectCellInput=function(){var i=r.useCellContext(),o=u.useColumnContext(i.columnKey),a=n.useEditActionContext().endEditing,s=t.useState(i.value),c=s[0],p=s[1];if(!o.editable||"select"!==o.type)throw new Error("Invalid condition");return t.useEffect((function(){p(i.value)}),[i.value]),e.jsxs("div",{className:"flex justify-between gap-1 w-full items-center",children:[e.jsxs("select",{className:"w-full py-1 px-2 bg-white text-gray-900",value:c,onChange:function(e){e.preventDefault(),p(e.target.value)},onBlur:function(e){e.preventDefault(),c!==i.value?i.updateCellValue(c):a()},onKeyDown:function(e){"Enter"===e.key&&e.preventDefault()},onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(p(i.value),a())},children:[o.allowEmpty&&e.jsx("option",{value:"",children:""==i.value?"-- 未選択 --":"-- 選択解除 --"},"TEPPEN/ReactUI Empty Option"),o.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(){p(i.value),a()}),300)},children:e.jsx(l.CancelIcon,{size:16})})]})};
|
|
3
|
-
//# sourceMappingURL=select-input.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../../edit/provider.js"),u=require("../../sheet/providers.js"),r=require("./base-input.js"),i=require("../provider.js"),o=t.memo((function(){var o=i.useCellContext(),l=u.useColumnContext(o.columnKey),a=u.useColumnValidateContext(o.columnKey),s=n.useEditActionContext().endEditing,c=t.useState(o.value),v=c[0],d=c[1];if(!l.editable||"string"!==l.type)throw new Error("Invalid condition");return t.useEffect((function(){d(o.value)}),[o.value]),e.jsx(r.CellInput,{value:v,onChange:function(e){e.preventDefault(),d(e.target.value)},onBlur:function(e){e.preventDefault(),v!==o.value?a(v)?o.updateCellValue(v):setTimeout((function(){e.target.focus()}),100):s()},reset:function(){return d(o.value.toString())},endEditing:s})}));exports.StringCellInput=o;
|
|
3
|
-
//# sourceMappingURL=string-input.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../focus/provider.js"),o=require("../../edit/provider.js"),n=require("../../libs/id-generator.js");exports.AutoSwitchEditMode=function(){var i=r.useFocusContext(),l=o.useEditContext();return t.useEffect((function(){var e,t;if(i.isFocus&&l.isEditing){var r=n.IdGenerator.getTableCellId(i.rowIndex,i.colIndex),o=document.getElementById("".concat(r,"-display")),s=document.getElementById("".concat(r,"-editor"));null==o||o.style.setProperty("opacity","0"),null==s||s.style.setProperty("opacity","1"),null==s||s.style.setProperty("pointer-events","auto"),null===(e=null==s?void 0:s.querySelector("input"))||void 0===e||e.focus(),null===(t=null==s?void 0:s.querySelector("select"))||void 0===t||t.focus()}return function(){if(i.isFocus&&l.isEditing){var e=n.IdGenerator.getTableCellId(i.rowIndex,i.colIndex),t=document.getElementById("".concat(e,"-display")),r=document.getElementById("".concat(e,"-editor"));null==t||t.style.setProperty("opacity","1"),null==r||r.style.setProperty("opacity","0"),null==r||r.style.setProperty("pointer-events","none")}}}),[l.isEditing]),e.jsx(e.Fragment,{})};
|
|
2
|
-
//# sourceMappingURL=auto-switch-edit-mode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-switch-edit-mode.js","sources":["../../../../../../src/table/table/components/auto-switch-edit-mode.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useFocusContext } from \"../../focus/provider\";\nimport { useEditContext } from \"../../edit/provider\";\nimport { IdGenerator } from \"../../libs\";\n\nexport function AutoSwitchEditMode() {\n const focus = useFocusContext();\n const edit = useEditContext();\n\n useEffect(() => {\n if (focus.isFocus && edit.isEditing) {\n const id = IdGenerator.getTableCellId(focus.rowIndex, focus.colIndex);\n\n const cellDisplayElement = document.getElementById(`${id}-display`);\n const cellEditorElement = document.getElementById(`${id}-editor`);\n cellDisplayElement?.style.setProperty(\"opacity\", \"0\");\n cellEditorElement?.style.setProperty(\"opacity\", \"1\");\n cellEditorElement?.style.setProperty(\"pointer-events\", \"auto\");\n cellEditorElement?.querySelector(\"input\")?.focus();\n cellEditorElement?.querySelector(\"select\")?.focus();\n }\n\n return () => {\n if (focus.isFocus && edit.isEditing) {\n const id = IdGenerator.getTableCellId(focus.rowIndex, focus.colIndex);\n\n const cellDisplayElement = document.getElementById(`${id}-display`);\n const cellEditorElement = document.getElementById(`${id}-editor`);\n cellDisplayElement?.style.setProperty(\"opacity\", \"1\");\n cellEditorElement?.style.setProperty(\"opacity\", \"0\");\n cellEditorElement?.style.setProperty(\"pointer-events\", \"none\");\n }\n };\n }, [edit.isEditing]);\n\n return <></>;\n}\n"],"names":["focus","useFocusContext","edit","useEditContext","useEffect","isFocus","isEditing","id","IdGenerator","getTableCellId","rowIndex","colIndex","cellDisplayElement","document","getElementById","concat","cellEditorElement","style","setProperty","_a","querySelector","_b","_jsx"],"mappings":"0NAME,IAAMA,EAAQC,EAAAA,kBACRC,EAAOC,EAAAA,iBA4Bb,OA1BAC,EAAAA,WAAU,mBACR,GAAIJ,EAAMK,SAAWH,EAAKI,UAAW,CACnC,IAAMC,EAAKC,EAAAA,YAAYC,eAAeT,EAAMU,SAAUV,EAAMW,UAEtDC,EAAqBC,SAASC,eAAe,GAAGC,OAAAR,EAAY,aAC5DS,EAAoBH,SAASC,eAAe,GAAGC,OAAAR,EAAW,YAChEK,SAAAA,EAAoBK,MAAMC,YAAY,UAAW,KACjDF,SAAAA,EAAmBC,MAAMC,YAAY,UAAW,KAChDF,SAAAA,EAAmBC,MAAMC,YAAY,iBAAkB,QACZ,QAA3CC,EAAAH,aAAiB,EAAjBA,EAAmBI,cAAc,gBAAU,IAAAD,GAAAA,EAAAnB,QACC,QAA5CqB,EAAAL,aAAiB,EAAjBA,EAAmBI,cAAc,iBAAW,IAAAC,GAAAA,EAAArB,OAC7C,CAED,OAAO,WACL,GAAIA,EAAMK,SAAWH,EAAKI,UAAW,CACnC,IAAMC,EAAKC,EAAAA,YAAYC,eAAeT,EAAMU,SAAUV,EAAMW,UAEtDC,EAAqBC,SAASC,eAAe,GAAGC,OAAAR,EAAY,aAC5DS,EAAoBH,SAASC,eAAe,GAAGC,OAAAR,EAAW,YAChEK,SAAAA,EAAoBK,MAAMC,YAAY,UAAW,KACjDF,SAAAA,EAAmBC,MAAMC,YAAY,UAAW,KAChDF,SAAAA,EAAmBC,MAAMC,YAAY,iBAAkB,OACxD,CACH,CACF,GAAG,CAAChB,EAAKI,YAEFgB,oBACT"}
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{jsx as e}from"react/jsx-runtime";import{useState as t,useEffect as r}from"react";import{useColumnContext as n,useColumnValidateContext as o}from"../../sheet/providers.js";import{CellInput as u}from"./base-input.js";import{useCellContext as a}from"../provider.js";import{useEditActionContext as i}from"../../edit/provider.js";function l(){var l=a(),m=n(l.columnKey),v=o(l.columnKey),f=i().endEditing,g=t(l.value.toString()),p=g[0],c=g[1];if(!m.editable||"number"!==m.type)throw new Error("Invalid condition");return r((function(){c(l.value.toString())}),[l.value]),e(u,{value:p,onChange:function(e){e.preventDefault(),""!==e.target.value?"-"!==e.target.value&&"0-"!==e.target.value?e.target.value.match(/^-?[0-9]+\.$/)?c(e.target.value):isNaN(Number(e.target.value))||c(Number(e.target.value).toString()):c("-0"):c("0")},onBlur:function(e){e.preventDefault(),Number(p)!==l.value?v(p)?l.updateCellValue(p):setTimeout((function(){e.target.focus()}),100):f()},reset:function(){return c(l.value.toString())},endEditing:f})}export{l as NumberCellInput};
|
|
3
|
-
//# sourceMappingURL=number-input.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{jsxs as e,jsx as t}from"react/jsx-runtime";import{useState as n,useEffect as o}from"react";import{useEditActionContext as r}from"../../edit/provider.js";import{useColumnContext as l}from"../../sheet/providers.js";import{CancelIcon as i}from"../../cancel-icon.js";import{useCellContext as a}from"../provider.js";function u(){var u=a(),p=l(u.columnKey),c=r().endEditing,f=n(u.value),v=f[0],m=f[1];if(!p.editable||"select"!==p.type)throw new Error("Invalid condition");return o((function(){m(u.value)}),[u.value]),e("div",{className:"flex justify-between gap-1 w-full items-center",children:[e("select",{className:"w-full py-1 px-2 bg-white text-gray-900",value:v,onChange:function(e){e.preventDefault(),m(e.target.value)},onBlur:function(e){e.preventDefault(),v!==u.value?u.updateCellValue(v):c()},onKeyDown:function(e){"Enter"===e.key&&e.preventDefault()},onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(m(u.value),c())},children:[p.allowEmpty&&t("option",{value:"",children:""==u.value?"-- 未選択 --":"-- 選択解除 --"},"TEPPEN/ReactUI Empty Option"),p.options.map((function(e){return t("option",{value:e.value,children:e.label},e.value)}))]}),t("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){m(u.value),c()}),300)},children:t(i,{size:16})})]})}export{u as SelectCellInput};
|
|
3
|
-
//# sourceMappingURL=select-input.js.map
|
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import{jsx as e}from"react/jsx-runtime";import{memo as t,useState as r,useEffect as n}from"react";import{useEditActionContext as o}from"../../edit/provider.js";import{useColumnContext as i,useColumnValidateContext as u}from"../../sheet/providers.js";import{CellInput as a}from"./base-input.js";import{useCellContext as l}from"../provider.js";var f=t((function(){var t=l(),f=i(t.columnKey),m=u(t.columnKey),p=o().endEditing,v=r(t.value),c=v[0],d=v[1];if(!f.editable||"string"!==f.type)throw new Error("Invalid condition");return n((function(){d(t.value)}),[t.value]),e(a,{value:c,onChange:function(e){e.preventDefault(),d(e.target.value)},onBlur:function(e){e.preventDefault(),c!==t.value?m(c)?t.updateCellValue(c):setTimeout((function(){e.target.focus()}),100):p()},reset:function(){return d(t.value.toString())},endEditing:p})}));export{f as StringCellInput};
|
|
3
|
-
//# sourceMappingURL=string-input.js.map
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{jsx as e,Fragment as t}from"react/jsx-runtime";import{useEffect as o}from"react";import{useFocusContext as r}from"../../focus/provider.js";import{useEditContext as n}from"../../edit/provider.js";import{IdGenerator as l}from"../../libs/id-generator.js";function i(){var i=r(),s=n();return o((function(){var e,t;if(i.isFocus&&s.isEditing){var o=l.getTableCellId(i.rowIndex,i.colIndex),r=document.getElementById("".concat(o,"-display")),n=document.getElementById("".concat(o,"-editor"));null==r||r.style.setProperty("opacity","0"),null==n||n.style.setProperty("opacity","1"),null==n||n.style.setProperty("pointer-events","auto"),null===(e=null==n?void 0:n.querySelector("input"))||void 0===e||e.focus(),null===(t=null==n?void 0:n.querySelector("select"))||void 0===t||t.focus()}return function(){if(i.isFocus&&s.isEditing){var e=l.getTableCellId(i.rowIndex,i.colIndex),t=document.getElementById("".concat(e,"-display")),o=document.getElementById("".concat(e,"-editor"));null==t||t.style.setProperty("opacity","1"),null==o||o.style.setProperty("opacity","0"),null==o||o.style.setProperty("pointer-events","none")}}}),[s.isEditing]),e(t,{})}export{i as AutoSwitchEditMode};
|
|
2
|
-
//# sourceMappingURL=auto-switch-edit-mode.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"auto-switch-edit-mode.js","sources":["../../../../../../src/table/table/components/auto-switch-edit-mode.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useFocusContext } from \"../../focus/provider\";\nimport { useEditContext } from \"../../edit/provider\";\nimport { IdGenerator } from \"../../libs\";\n\nexport function AutoSwitchEditMode() {\n const focus = useFocusContext();\n const edit = useEditContext();\n\n useEffect(() => {\n if (focus.isFocus && edit.isEditing) {\n const id = IdGenerator.getTableCellId(focus.rowIndex, focus.colIndex);\n\n const cellDisplayElement = document.getElementById(`${id}-display`);\n const cellEditorElement = document.getElementById(`${id}-editor`);\n cellDisplayElement?.style.setProperty(\"opacity\", \"0\");\n cellEditorElement?.style.setProperty(\"opacity\", \"1\");\n cellEditorElement?.style.setProperty(\"pointer-events\", \"auto\");\n cellEditorElement?.querySelector(\"input\")?.focus();\n cellEditorElement?.querySelector(\"select\")?.focus();\n }\n\n return () => {\n if (focus.isFocus && edit.isEditing) {\n const id = IdGenerator.getTableCellId(focus.rowIndex, focus.colIndex);\n\n const cellDisplayElement = document.getElementById(`${id}-display`);\n const cellEditorElement = document.getElementById(`${id}-editor`);\n cellDisplayElement?.style.setProperty(\"opacity\", \"1\");\n cellEditorElement?.style.setProperty(\"opacity\", \"0\");\n cellEditorElement?.style.setProperty(\"pointer-events\", \"none\");\n }\n };\n }, [edit.isEditing]);\n\n return <></>;\n}\n"],"names":["AutoSwitchEditMode","focus","useFocusContext","edit","useEditContext","useEffect","isFocus","isEditing","id","IdGenerator","getTableCellId","rowIndex","colIndex","cellDisplayElement","document","getElementById","concat","cellEditorElement","style","setProperty","_a","querySelector","_b","_jsx"],"mappings":"4QAKgBA,IACd,IAAMC,EAAQC,IACRC,EAAOC,IA4Bb,OA1BAC,GAAU,mBACR,GAAIJ,EAAMK,SAAWH,EAAKI,UAAW,CACnC,IAAMC,EAAKC,EAAYC,eAAeT,EAAMU,SAAUV,EAAMW,UAEtDC,EAAqBC,SAASC,eAAe,GAAGC,OAAAR,EAAY,aAC5DS,EAAoBH,SAASC,eAAe,GAAGC,OAAAR,EAAW,YAChEK,SAAAA,EAAoBK,MAAMC,YAAY,UAAW,KACjDF,SAAAA,EAAmBC,MAAMC,YAAY,UAAW,KAChDF,SAAAA,EAAmBC,MAAMC,YAAY,iBAAkB,QACZ,QAA3CC,EAAAH,aAAiB,EAAjBA,EAAmBI,cAAc,gBAAU,IAAAD,GAAAA,EAAAnB,QACC,QAA5CqB,EAAAL,aAAiB,EAAjBA,EAAmBI,cAAc,iBAAW,IAAAC,GAAAA,EAAArB,OAC7C,CAED,OAAO,WACL,GAAIA,EAAMK,SAAWH,EAAKI,UAAW,CACnC,IAAMC,EAAKC,EAAYC,eAAeT,EAAMU,SAAUV,EAAMW,UAEtDC,EAAqBC,SAASC,eAAe,GAAGC,OAAAR,EAAY,aAC5DS,EAAoBH,SAASC,eAAe,GAAGC,OAAAR,EAAW,YAChEK,SAAAA,EAAoBK,MAAMC,YAAY,UAAW,KACjDF,SAAAA,EAAmBC,MAAMC,YAAY,UAAW,KAChDF,SAAAA,EAAmBC,MAAMC,YAAY,iBAAkB,OACxD,CACH,CACF,GAAG,CAAChB,EAAKI,YAEFgB,OACT"}
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|