@teppen/react-ui 1.3.2 → 1.4.1
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/README.md +20 -1
- package/dist/cjs/src/table/base.js +1 -1
- package/dist/cjs/src/table/cell/provider.js +2 -0
- package/dist/cjs/src/table/cell/provider.js.map +1 -0
- package/dist/cjs/src/table/cell/ui/base-input.js +2 -0
- package/dist/cjs/src/table/cell/ui/base-input.js.map +1 -0
- package/dist/cjs/src/table/cell/ui/cell.js +3 -0
- package/dist/cjs/src/table/cell/ui/edit-button.js +3 -0
- package/dist/cjs/src/table/cell/ui/edit-button.js.map +1 -0
- package/dist/cjs/src/table/cell/ui/number-input.js +3 -0
- package/dist/cjs/src/table/cell/ui/number-input.js.map +1 -0
- package/dist/cjs/src/table/cell/ui/select-input.js +3 -0
- package/dist/cjs/src/table/cell/ui/select-input.js.map +1 -0
- package/dist/cjs/src/table/cell/ui/string-input.js +3 -0
- package/dist/cjs/src/table/cell/ui/string-input.js.map +1 -0
- package/dist/cjs/src/table/edit/hooks.js +1 -1
- package/dist/cjs/src/table/edit/hooks.js.map +1 -1
- package/dist/cjs/src/table/edit/provider.js +1 -1
- package/dist/cjs/src/table/focus/hooks.js +2 -0
- package/dist/cjs/src/table/focus/hooks.js.map +1 -0
- package/dist/cjs/src/table/focus/provider.js +2 -0
- package/dist/cjs/src/table/focus/provider.js.map +1 -0
- package/dist/cjs/src/table/header/header.js +2 -1
- package/dist/cjs/src/table/header/header.js.map +1 -1
- 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 +2 -0
- package/dist/cjs/src/table/libs/generate-validate-function.js.map +1 -0
- package/dist/cjs/src/table/libs/id-generator.js +2 -0
- package/dist/cjs/src/table/libs/id-generator.js.map +1 -0
- package/dist/cjs/src/table/operation/components/keyboard-setting.js +2 -0
- package/dist/cjs/src/table/operation/components/keyboard-setting.js.map +1 -0
- package/dist/cjs/src/table/pagenation/components.js +1 -1
- package/dist/cjs/src/table/pagenation/constants.js +1 -1
- package/dist/cjs/src/table/pagenation/constants.js.map +1 -1
- package/dist/cjs/src/table/pagenation/hooks.js +1 -1
- package/dist/cjs/src/table/pagenation/hooks.js.map +1 -1
- package/dist/cjs/src/table/pagenation/providers.js +1 -1
- package/dist/cjs/src/table/sheet/providers.js +1 -1
- package/dist/cjs/src/table/table/components/auto-switch-edit-mode.js +2 -0
- package/dist/cjs/src/table/table/components/auto-switch-edit-mode.js.map +1 -0
- package/dist/cjs/src/table/table-property/components/auto-update-table-property.js +2 -0
- package/dist/cjs/src/table/table-property/components/auto-update-table-property.js.map +1 -0
- package/dist/cjs/src/table/table-property/hook.js +2 -0
- package/dist/cjs/src/table/table-property/hook.js.map +1 -0
- package/dist/cjs/src/table/table-property/provider.js +2 -0
- package/dist/cjs/src/table/table-property/provider.js.map +1 -0
- package/dist/esm/src/table/base.js +1 -1
- package/dist/esm/src/table/cell/provider.js +2 -0
- package/dist/esm/src/table/cell/provider.js.map +1 -0
- package/dist/esm/src/table/cell/ui/base-input.js +2 -0
- package/dist/esm/src/table/cell/ui/base-input.js.map +1 -0
- package/dist/esm/src/table/cell/ui/cell.js +3 -0
- package/dist/esm/src/table/cell/ui/edit-button.js +3 -0
- package/dist/esm/src/table/cell/ui/edit-button.js.map +1 -0
- package/dist/esm/src/table/cell/ui/number-input.js +3 -0
- package/dist/esm/src/table/cell/ui/number-input.js.map +1 -0
- package/dist/esm/src/table/cell/ui/select-input.js +3 -0
- package/dist/esm/src/table/cell/ui/select-input.js.map +1 -0
- package/dist/esm/src/table/cell/ui/string-input.js +3 -0
- package/dist/esm/src/table/cell/ui/string-input.js.map +1 -0
- package/dist/esm/src/table/edit/hooks.js +1 -1
- package/dist/esm/src/table/edit/hooks.js.map +1 -1
- package/dist/esm/src/table/edit/provider.js +1 -1
- package/dist/esm/src/table/focus/hooks.js +2 -0
- package/dist/esm/src/table/focus/hooks.js.map +1 -0
- package/dist/esm/src/table/focus/provider.js +2 -0
- package/dist/esm/src/table/focus/provider.js.map +1 -0
- package/dist/esm/src/table/header/header.js +2 -1
- package/dist/esm/src/table/header/header.js.map +1 -1
- 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 +2 -0
- package/dist/esm/src/table/libs/generate-validate-function.js.map +1 -0
- package/dist/esm/src/table/libs/id-generator.js +2 -0
- package/dist/esm/src/table/libs/id-generator.js.map +1 -0
- package/dist/esm/src/table/operation/components/keyboard-setting.js +2 -0
- package/dist/esm/src/table/operation/components/keyboard-setting.js.map +1 -0
- package/dist/esm/src/table/pagenation/components.js +1 -1
- package/dist/esm/src/table/pagenation/constants.js +1 -1
- package/dist/esm/src/table/pagenation/constants.js.map +1 -1
- package/dist/esm/src/table/pagenation/hooks.js +1 -1
- package/dist/esm/src/table/pagenation/hooks.js.map +1 -1
- package/dist/esm/src/table/pagenation/providers.js +1 -1
- package/dist/esm/src/table/sheet/providers.js +1 -1
- package/dist/esm/src/table/table/components/auto-switch-edit-mode.js +2 -0
- package/dist/esm/src/table/table/components/auto-switch-edit-mode.js.map +1 -0
- package/dist/esm/src/table/table-property/components/auto-update-table-property.js +2 -0
- package/dist/esm/src/table/table-property/components/auto-update-table-property.js.map +1 -0
- package/dist/esm/src/table/table-property/hook.js +2 -0
- package/dist/esm/src/table/table-property/hook.js.map +1 -0
- package/dist/esm/src/table/table-property/provider.js +2 -0
- package/dist/esm/src/table/table-property/provider.js.map +1 -0
- package/dist/index.d.ts +16 -9
- package/package.json +1 -1
- package/dist/cjs/node_modules/react-intersection-observer/index.js +0 -3
- package/dist/cjs/node_modules/react-intersection-observer/index.js.map +0 -1
- package/dist/cjs/src/table/cell.js +0 -3
- package/dist/esm/node_modules/react-intersection-observer/index.js +0 -3
- package/dist/esm/node_modules/react-intersection-observer/index.js.map +0 -1
- package/dist/esm/src/table/cell.js +0 -3
- /package/dist/cjs/src/table/{cell.js.map → cell/ui/cell.js.map} +0 -0
- /package/dist/esm/src/table/{cell.js.map → cell/ui/cell.js.map} +0 -0
package/README.md
CHANGED
|
@@ -144,10 +144,16 @@ const App = () => {
|
|
|
144
144
|
key: "id",
|
|
145
145
|
asc: true,
|
|
146
146
|
},
|
|
147
|
+
pagenation: {
|
|
148
|
+
rowCountPerPage: 50,
|
|
149
|
+
},
|
|
147
150
|
}}
|
|
148
151
|
onClickRow={(row) => {
|
|
149
152
|
alert(`Clicked row: (id: ${row.id})`);
|
|
150
153
|
}}
|
|
154
|
+
onUpdateRow={(newRow, oldRow) => {
|
|
155
|
+
alert({ newRow, oldRow });
|
|
156
|
+
}}
|
|
151
157
|
applyRowFormatting={(row) => {
|
|
152
158
|
if (row.role === "1") {
|
|
153
159
|
return "bg-red-600 text-white";
|
|
@@ -177,10 +183,11 @@ A component that displays a table based on the row and column information passed
|
|
|
177
183
|
- Filtering function (only when `label` is set in the column information)
|
|
178
184
|
- Editing function (only when `editable` is true and `onCellBlur` is set in the column information)
|
|
179
185
|
- Checkbox function
|
|
186
|
+
- Paste function
|
|
180
187
|
|
|
181
188
|
#### Arguments
|
|
182
189
|
|
|
183
|
-
The table component only accepts the arguments `rows`, `cols`, `initialCondition`
|
|
190
|
+
The table component only accepts the arguments `rows`, `cols`, `initialCondition`, `onClickRow`, `onUpdateRow`, `applyRowFormatting`. Details for each argument are described below.
|
|
184
191
|
|
|
185
192
|
##### rows
|
|
186
193
|
|
|
@@ -240,6 +247,9 @@ In `initialCondition`, you can set initial values for each function. This is opt
|
|
|
240
247
|
```ts
|
|
241
248
|
type TInitialCondition = {
|
|
242
249
|
sort?: { key: string; asc?: boolean };
|
|
250
|
+
pagenation?: {
|
|
251
|
+
rowCountPerPage?: 20 | 50 | 100 | "all";
|
|
252
|
+
};
|
|
243
253
|
};
|
|
244
254
|
```
|
|
245
255
|
|
|
@@ -251,6 +261,15 @@ In `onClickRow`, you may define the behavior when a row is clicked. This is opti
|
|
|
251
261
|
type TOnClickRow = (row: DataObject) => void;
|
|
252
262
|
```
|
|
253
263
|
|
|
264
|
+
##### onUpdateRow
|
|
265
|
+
|
|
266
|
+
In `onUpdateRow`, You can define the behavior when you paste data from Excel or spreadsheets into a table. This is optional.
|
|
267
|
+
For multi-line data, this function is executed one line at a time.
|
|
268
|
+
|
|
269
|
+
```ts
|
|
270
|
+
type TOnUpdateRow = (newRow: DataObject, oldRow: DataObject) => void;
|
|
271
|
+
```
|
|
272
|
+
|
|
254
273
|
##### applyRowFormatting
|
|
255
274
|
|
|
256
275
|
In `applyRowFormatting`, depending on the status of each row, you can define the format of the row using TailwindCSS classes. In principle, TailwindCSS classes other than background and text color are not guaranteed to work, but any class can be specified.
|
|
@@ -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"),
|
|
2
|
+
"use strict";var e=require("../../node_modules/tslib/tslib.es6.js"),r=require("react/jsx-runtime"),o=require("./hook.js"),t=require("./cell/ui/cell.js"),i=require("./header/header.js"),s=require("./pagenation/providers.js"),l=require("./pagenation/components.js"),n=require("./filter/provider.js"),a=require("./filter/components.js");require("./sort/icon.js");var d=require("./sort/provider.js"),c=require("./sheet/providers.js"),u=require("./focus/provider.js"),x=require("./checkbox/provider.js"),h=require("./checkbox/components.js"),j=require("./libs/id-generator.js"),p=require("./edit/provider.js"),v=require("./table-property/provider.js"),b=require("./table-property/components/auto-update-table-property.js"),m=require("./operation/components/keyboard-setting.js"),g=require("./table/components/auto-switch-edit-mode.js");function f(e){var s=o.useTable(e),d=s.cols,x=s.rows,p=n.useFilterContext().selectedFilterKey,v=u.useFocusActionContext().unfocus;return r.jsxs("div",{className:"w-full",children:[r.jsx("div",{className:"flex justify-end mb-1 mr-3",children:r.jsx(a.TableFilterRemoveButton,{children:r.jsx("p",{className:"text-xs underline text-gray-500 hover:text-gray-700",children:"全てのフィルタリング条件を解除する"})})}),r.jsx("div",{id:"table-frame",className:"relative h-full max-w-full max-h-[80vh] border border-gray-200 rounded-md overflow-auto",children:r.jsxs("table",{className:"table",children:[r.jsx("thead",{children:r.jsxs("tr",{className:"sticky top-0 border-gray-200 z-20 bg-gray-200 text-gray-600 h-[32px]",children:[e.checkbox&&r.jsx("th",{children:r.jsx(h.AllCheckbox,{rows:e.rows})}),d.map((function(e,o){return r.jsx(i.TableHeaderElement,{id:j.IdGenerator.getTableColId(o),columnKey:e.key},e.key)}))]})}),r.jsxs("tbody",{children:[!!p&&r.jsx("tr",{children:r.jsx("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.jsx(a.TableFilterForm,{})})}),0===x.length&&r.jsx("tr",{children:r.jsx("td",{colSpan:d.length,className:"py-5",children:r.jsx("p",{className:"text-center font-bold text-lg",children:"NO DATA"})})}),x.map((function(o,i){return r.jsx(c.RowProvider,{row:o,children:r.jsxs("tr",{className:"relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ".concat(e.onClickRow?"hover:cursor-pointer":""," ").concat(e.applyRowFormatting?e.applyRowFormatting(o):""),onClick:function(r){r.preventDefault(),e.onClickRow&&(e.onClickRow(o),v())},"data-testid":o.id,children:[e.checkbox&&r.jsx("td",{children:r.jsx(h.Checkbox,{})}),d.map((function(o,s){return r.jsx(t.TableCell,{rowIndex:i,colIndex:s,columnKey:o.key,isExistOnClickRow:!!e.onClickRow,onUpdateRow:e.onUpdateRow},o.key)}))]})},o.id)}))]})]})}),r.jsxs("div",{className:"mt-1",children:[r.jsx(l.DisplayRange,{}),r.jsx("div",{className:"mt-2",children:r.jsx(l.Pagenation,{})})]})]})}module.exports=function(o){var t,i,l;return r.jsx(n.FilterProvider,{children:r.jsx(d.SortProvider,{initialCondition:null===(t=o.initialCondition)||void 0===t?void 0:t.sort,children:r.jsx(s.PagenationProvider,{rowCount:o.rows.length,perPage:null===(l=null===(i=o.initialCondition)||void 0===i?void 0:i.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(c.ProcessedDataProvider,{props:o,children:r.jsx(c.ColumnsProvider,{cols:o.cols,children:r.jsx(u.FocusProvider,{children:r.jsx(p.EditProvider,{children:r.jsxs(v.TablePropertyProvider,{children:[r.jsx(b.AutoUpdateTableProperty,{}),r.jsx(g.AutoSwitchEditMode,{}),r.jsx(m.KeyboardSetting,{}),r.jsx(f,e.__assign({},o))]})})})})})})})})})})};
|
|
3
3
|
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../sheet/providers.js"),r=require("../edit/provider.js"),u=t.createContext({columnKey:"",value:"",label:"",type:"string",updateCellValue:function(){}});exports.CellProvider=function(l){var o,i,d=l.children,a=l.columnKey,c=n.useColumnContext(a),s=n.useRowContext(),p=s[a],v=r.useEditActionContext().endEditing,C="select"===c.type?null===(i=null===(o=c.options)||void 0===o?void 0:o.find((function(e){return e.value===p})))||void 0===i?void 0:i.label:p,m=t.useMemo((function(){return c.editable?C:c.render?c.render(p,s):C}),[c.editable,C,p,s]),b=t.useCallback((function(e){c.editable&&("number"===c.type?c.onCellBlur(a,Number(e),s,v):c.onCellBlur(a,e,s,v))}),[c,a,s]),x=!c.editable&&c.render?"component":c.type,f=t.useMemo((function(){return{columnKey:a,value:p,label:C,component:m,type:x,updateCellValue:b}}),[a,p,C,m,c,b]);return e.jsx(u.Provider,{value:f,children:d})},exports.useCellContext=function(){return t.useContext(u)};
|
|
2
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/cell/provider.tsx"],"sourcesContent":["import { createContext, useCallback, useContext, useMemo } from \"react\";\nimport { TColumnType } from \"../type\";\nimport { useColumnContext, useRowContext } from \"../sheet\";\nimport { useEditActionContext } from \"../edit/provider\";\n\nconst CellContext = createContext<{\n columnKey: string;\n value: any;\n label: any;\n type: TColumnType | \"component\";\n component?: React.ReactNode;\n updateCellValue: (value: string) => void;\n}>({\n columnKey: \"\",\n value: \"\",\n label: \"\",\n type: \"string\",\n updateCellValue: () => {},\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 const { endEditing } = useEditActionContext();\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 updateCellValue = useCallback(\n (value: string) => {\n if (col.editable) {\n if (col.type === \"number\") {\n col.onCellBlur(columnKey, Number(value), row, endEditing);\n } else {\n col.onCellBlur(columnKey, value, row, endEditing);\n }\n }\n },\n [col, columnKey, row]\n );\n\n const type: TColumnType | \"component\" =\n !col.editable && col.render ? \"component\" : col.type;\n\n const cellStatus = useMemo(\n () => ({\n columnKey,\n value,\n label,\n component,\n type,\n updateCellValue,\n }),\n [columnKey, value, label, component, col, updateCellValue]\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","columnKey","value","label","type","updateCellValue","_a","children","col","useColumnContext","row","useRowContext","endEditing","useEditActionContext","_b","options","find","op","_c","component","useMemo","editable","render","useCallback","onCellBlur","Number","cellStatus","_jsx","jsx","Provider","useContext"],"mappings":"uIAKMA,EAAcC,EAAAA,cAOjB,CACDC,UAAW,GACXC,MAAO,GACPC,MAAO,GACPC,KAAM,SACNC,gBAAiB,WAAQ,yBAGrB,SAAuBC,WAC3BC,EAAQD,EAAAC,SACRN,EAASK,EAAAL,UAKHO,EAAMC,mBAAiBR,GACvBS,EAAMC,EAAAA,gBACNT,EAAQQ,EAAIT,GACVW,EAAeC,oCAEjBV,EACS,WAAbK,EAAIJ,KAC6C,UAAlC,QAAXU,EAAAN,EAAIO,eAAO,IAAAD,OAAA,EAAAA,EAAEE,MAAK,SAACC,GAAO,OAAAA,EAAGf,QAAUA,CAAb,WAAmB,IAAAgB,OAAA,EAAAA,EAAEf,MAC/CD,EAEAiB,EAAYC,EAAAA,SAAQ,WACxB,OAAIZ,EAAIa,SACClB,EAEAK,EAAIc,OAASd,EAAIc,OAAOpB,EAAgBQ,GAAOP,CAE1D,GAAG,CAACK,EAAIa,SAAUlB,EAAOD,EAAOQ,IAE1BL,EAAkBkB,eACtB,SAACrB,GACKM,EAAIa,WACW,WAAbb,EAAIJ,KACNI,EAAIgB,WAAWvB,EAAWwB,OAAOvB,GAAQQ,EAAKE,GAE9CJ,EAAIgB,WAAWvB,EAAWC,EAAOQ,EAAKE,GAG3C,GACD,CAACJ,EAAKP,EAAWS,IAGbN,GACHI,EAAIa,UAAYb,EAAIc,OAAS,YAAcd,EAAIJ,KAE5CsB,EAAaN,WACjB,WAAM,MAAC,CACLnB,UAASA,EACTC,MAAKA,EACLC,MAAKA,EACLgB,UAASA,EACTf,KAAIA,EACJC,gBAAeA,EACf,GACF,CAACJ,EAAWC,EAAOC,EAAOgB,EAAWX,EAAKH,IAG5C,OACEsB,EAAAC,IAAC7B,EAAY8B,SAAQ,CAAC3B,MAAOwB,EAAUnB,SAAGA,GAE9C,oCAGE,OAAOuB,EAAAA,WAAW/B,EACpB"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("../../cancel-icon.js");exports.CellInput=function(n){return e.jsxs("div",{className:"flex justify-between gap-1 w-full items-center",onClick:function(e){e.preventDefault(),e.stopPropagation()},children:[e.jsx("input",{id:"table-cell-form",className:"w-full py-1 px-2 bg-white text-gray-900",type:"text",value:n.value,onChange:n.onChange,onBlur:n.onBlur,onKeyUp:function(e){e.preventDefault(),"Enter"===e.key?e.target.blur():"Escape"===e.key&&(n.reset(),n.endEditing())}}),e.jsx("button",{onMouseDown:function(e){e.preventDefault(),e.stopPropagation(),setTimeout((function(){n.reset(),n.endEditing()}),300)},children:e.jsx(t.CancelIcon,{size:16})})]})};
|
|
2
|
+
//# sourceMappingURL=base-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base-input.js","sources":["../../../../../../src/table/cell/ui/base-input.tsx"],"sourcesContent":["import { CancelIcon } from \"../../cancel-icon\";\n\nexport function CellInput(props: {\n value: string | number;\n onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;\n onBlur: (e: React.FocusEvent<HTMLInputElement>) => void;\n reset: () => void;\n endEditing: () => void;\n}) {\n return (\n <div\n className={`flex justify-between gap-1 w-full items-center`}\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n }}\n >\n <input\n id=\"table-cell-form\"\n className=\"w-full py-1 px-2 bg-white text-gray-900\"\n type=\"text\"\n value={props.value}\n onChange={props.onChange}\n onBlur={props.onBlur}\n onKeyUp={(e: React.KeyboardEvent<HTMLInputElement>) => {\n e.preventDefault();\n if (e.key === \"Enter\") {\n (e.target as HTMLInputElement).blur();\n } else if (e.key === \"Escape\") {\n props.reset();\n props.endEditing();\n }\n }}\n />\n <button\n onMouseDown={(e) => {\n e.preventDefault();\n e.stopPropagation();\n setTimeout(() => {\n props.reset();\n props.endEditing();\n }, 300);\n }}\n >\n <CancelIcon size={16} />\n </button>\n </div>\n );\n}\n"],"names":["props","_jsxs","className","onClick","e","preventDefault","stopPropagation","children","_jsx","jsx","id","type","value","onChange","onBlur","onKeyUp","key","target","blur","reset","endEditing","onMouseDown","setTimeout","CancelIcon","size"],"mappings":"oGAEM,SAAoBA,GAOxB,OACEC,EAAAA,YACEC,UAAW,iDACXC,QAAS,SAACC,GACRA,EAAEC,iBACFD,EAAEE,iBACJ,EAEAC,SAAA,CAAAC,EAAAC,IAAA,QAAA,CACEC,GAAG,kBACHR,UAAU,0CACVS,KAAK,OACLC,MAAOZ,EAAMY,MACbC,SAAUb,EAAMa,SAChBC,OAAQd,EAAMc,OACdC,QAAS,SAACX,GACRA,EAAEC,iBACY,UAAVD,EAAEY,IACHZ,EAAEa,OAA4BC,OACZ,WAAVd,EAAEY,MACXhB,EAAMmB,QACNnB,EAAMoB,aAEV,IAEFZ,EAAAA,IAAA,SAAA,CACEa,YAAa,SAACjB,GACZA,EAAEC,iBACFD,EAAEE,kBACFgB,YAAW,WACTtB,EAAMmB,QACNnB,EAAMoB,YACP,GAAE,MACJb,SAEDC,MAACe,EAAAA,WAAW,CAAAC,KAAM,SAI1B"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("../../hook.js"),l=require("./edit-button.js"),i=require("./string-input.js"),n=require("./number-input.js"),o=require("./select-input.js"),r=require("react"),s=require("../../libs/id-generator.js"),a=require("../provider.js"),c=require("../../sheet/providers.js"),u=r.memo((function(t){return e.jsx(e.Fragment,{children:"component"===t.type?t.component:e.jsx("div",{onDoubleClick:t.onDoubleClick,children:e.jsx("p",{className:"cell-data text-left whitespace-nowrap",children:t.component})})})})),d=r.memo((function(t){var r=a.useCellContext();return e.jsx("td",{id:t.id,onPaste:function(e){e.preventDefault(),t.isExistOnUpdateRow?t.pasteData(e.clipboardData.getData("text")):alert("ペースト機能が有効化されていません。")},children:e.jsxs("div",{className:"relative",onClick:t.isExistOnClickRow?void 0:function(e){e.preventDefault(),t.focusAtCell()},onDoubleClick:t.isExistOnClickRow?void 0:t.onDoubleClickCellToEdit,children:[e.jsx("div",{id:"".concat(t.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(),t.focusAtCell()},children:[e.jsx(u,{type:r.type,component:r.component,onDoubleClick:t.onDoubleClickCellToEdit}),t.editable&&e.jsx(l.EditButton,{})]})}),t.editable&&e.jsxs("div",{id:"".concat(t.id,"-editor"),className:"absolute top-0 left-0 w-full h-full grid place-items-center z-10 pr-2",onClick:t.preventPropagation,style:{opacity:0,pointerEvents:"none"},children:["string"===r.type&&e.jsx(i.StringCellInput,{}),"number"===r.type&&e.jsx(n.NumberCellInput,{}),"select"===r.type&&e.jsx(o.SelectCellInput,{})]})]})})}));exports.TableCell=function(l){var i,n=t.useCell(l.rowIndex,l.colIndex,l.onUpdateRow),o=n.focusAtCell,r=n.onDoubleClickCellToEdit,u=n.preventPropagation,p=n.pasteData,C=c.useColumnContext(l.columnKey);return e.jsx(a.CellProvider,{columnKey:l.columnKey,children:e.jsx(d,{id:s.IdGenerator.getTableCellId(l.rowIndex,l.colIndex),editable:null!==(i=C.editable)&&void 0!==i&&i,focusAtCell:o,onDoubleClickCellToEdit:r,preventPropagation:u,pasteData:p,isExistOnClickRow:l.isExistOnClickRow,isExistOnUpdateRow:!!l.onUpdateRow})})};
|
|
3
|
+
//# sourceMappingURL=cell.js.map
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var t=require("react/jsx-runtime"),e=require("react"),r=require("../../edit/provider.js"),i=require("../../edit-icon.js"),n=e.memo((function(){var e=r.useEditActionContext().startEditing;return t.jsx("button",{className:"w-fit h-fit p-1 rounded-full text-gray-500 hover:bg-gray-200",onClick:function(t){t.preventDefault(),e()},children:t.jsx(i.EditIcon,{size:12})})}));exports.EditButton=n;
|
|
3
|
+
//# sourceMappingURL=edit-button.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"edit-button.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -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("./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],d=v[1];if(!l.editable||"number"!==l.type)throw new Error("Invalid condition");return 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]+\.$/)?d(e.target.value):isNaN(Number(e.target.value))||d(Number(e.target.value).toString()):d("-0"):d("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 d(i.value.toString())},endEditing:s})};
|
|
3
|
+
//# sourceMappingURL=number-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"number-input.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),n=require("../../edit/provider.js"),r=require("../../sheet/providers.js"),u=require("../../cancel-icon.js"),l=require("../provider.js");exports.SelectCellInput=function(){var i=l.useCellContext(),o=r.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 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(u.CancelIcon,{size:16})})]})};
|
|
3
|
+
//# sourceMappingURL=select-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"select-input.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../edit/provider.js"),n=require("../../sheet/providers.js"),u=require("./base-input.js"),i=require("../provider.js"),o=t.memo((function(){var o=i.useCellContext(),l=n.useColumnContext(o.columnKey),a=n.useColumnValidateContext(o.columnKey),s=r.useEditActionContext().endEditing,d=t.useState(o.value),c=d[0],v=d[1];if(!l.editable||"string"!==l.type)throw new Error("Invalid condition");return e.jsx(u.CellInput,{value:c,onChange:function(e){e.preventDefault(),v(e.target.value)},onBlur:function(e){e.preventDefault(),c!==o.value?a(c)?o.updateCellValue(c):setTimeout((function(){e.target.focus()}),100):s()},reset:function(){return v(o.value.toString())},endEditing:s})}));exports.StringCellInput=o;
|
|
3
|
+
//# sourceMappingURL=string-input.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"string-input.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var i=require("react"),t=function(i,t){switch(t.type){case"startEditing":return i.isEditing?i:{isEditing:!0};case"endEditing":return i.isEditing?{isEditing:!1}:i}};exports.useEditReducer=function(){var n=i.useReducer(t,{isEditing:!1}),e=n[0],s=n[1],d=i.useCallback((function(){s({type:"startEditing"})}),[]),r=i.useCallback((function(){s({type:"endEditing"})}),[]);return{isEditing:e.isEditing,startEditing:d,endEditing:r}};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/edit/hooks.ts"],"sourcesContent":["import { useCallback, useReducer } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/edit/hooks.ts"],"sourcesContent":["import { useCallback, useReducer } from \"react\";\nimport { TEditReducer, TReturnEditReducer } from \"./types\";\n\nconst reducer: TEditReducer = (state, action) => {\n switch (action.type) {\n case \"startEditing\":\n if (state.isEditing) return state;\n\n return {\n isEditing: true,\n };\n\n case \"endEditing\":\n if (!state.isEditing) return state;\n\n return {\n isEditing: false,\n };\n }\n};\n\nexport function useEditReducer(): TReturnEditReducer {\n const [state, dispatch] = useReducer(reducer, {\n isEditing: false,\n });\n\n const startEditing = useCallback(() => {\n dispatch({ type: \"startEditing\" });\n }, []);\n\n const endEditing = useCallback(() => {\n dispatch({ type: \"endEditing\" });\n }, []);\n\n return {\n isEditing: state.isEditing,\n startEditing,\n endEditing,\n };\n}\n"],"names":["reducer","state","action","type","isEditing","_a","useReducer","dispatch","startEditing","useCallback","endEditing"],"mappings":"oCAGMA,EAAwB,SAACC,EAAOC,GACpC,OAAQA,EAAOC,MACb,IAAK,eACH,OAAIF,EAAMG,UAAkBH,EAErB,CACLG,WAAW,GAGf,IAAK,aACH,OAAKH,EAAMG,UAEJ,CACLA,WAAW,GAHgBH,EAMnC,oCAGQ,IAAAI,EAAoBC,EAAUA,WAACN,EAAS,CAC5CI,WAAW,IADNH,EAAKI,EAAA,GAAEE,OAIRC,EAAeC,EAAAA,aAAY,WAC/BF,EAAS,CAAEJ,KAAM,gBAClB,GAAE,IAEGO,EAAaD,EAAAA,aAAY,WAC7BF,EAAS,CAAEJ,KAAM,cAClB,GAAE,IAEH,MAAO,CACLC,UAAWH,EAAMG,UACjBI,aAAYA,EACZE,WAAUA,EAEd"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var t=require("../../../node_modules/tslib/tslib.es6.js"),e=require("react/jsx-runtime"),i=require("react"),n=require("./hooks.js"),r=i.createContext({isEditing:!1}),s=i.createContext({startEditing:function(){},endEditing:function(){}});function u(){return i.useContext(r)}function o(){return i.useContext(s)}exports.EditProvider=function(t){var u=n.useEditReducer(),o=i.useMemo((function(){return{isEditing:u.isEditing}}),[u.isEditing]),d=i.useMemo((function(){return{startEditing:u.startEditing,endEditing:u.endEditing}}),[]);return e.jsx(r.Provider,{value:o,children:e.jsx(s.Provider,{value:d,children:t.children})})},exports.useEditActionContext=o,exports.useEditContext=function(){return t.__assign(t.__assign({},u()),o())},exports.useEditStateContext=u;
|
|
3
3
|
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),o=require("react"),n=require("../libs/id-generator.js"),s=function(o,n){switch(n.type){case"focus":return o.isFocus?o:{isFocus:!0,rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex};case"unfocus":return o.isFocus?{isFocus:!1}:o;case"move":return o.isFocus?{isFocus:!0,rowIndex:n.payload.rowIndex,colIndex:n.payload.colIndex}:o;case"moveLeft":return o.isFocus?e.__assign(e.__assign({},o),{colIndex:o.colIndex-1}):o;case"moveRight":return o.isFocus?e.__assign(e.__assign({},o),{colIndex:o.colIndex+1}):o;case"moveUp":return o.isFocus?e.__assign(e.__assign({},o),{rowIndex:o.rowIndex-1}):o;case"moveDown":return o.isFocus?e.__assign(e.__assign({},o),{rowIndex:o.rowIndex+1}):o}};exports.useFocusReducer=function(){var e=o.useReducer(s,{isFocus:!1}),t=e[0],c=e[1],u=o.useCallback((function(e,o){c({type:"focus",payload:{rowIndex:e,colIndex:o}})}),[]),l=o.useCallback((function(){c({type:"unfocus"})}),[]),r=o.useCallback((function(e,o){c({type:"move",payload:{rowIndex:e,colIndex:o}})}),[]),i=o.useCallback((function(){c({type:"moveLeft"})}),[]),a=o.useCallback((function(){c({type:"moveRight"})}),[]),d=o.useCallback((function(){c({type:"moveUp"})}),[]),f=o.useCallback((function(){c({type:"moveDown"})}),[]);return o.useEffect((function(){var e=function(e){var o=document.getElementById("table-frame"),n=e.target;n instanceof Node&&(null==o?void 0:o.contains(n))||l()};return document.addEventListener("click",e),function(){document.removeEventListener("click",e)}}),[]),o.useEffect((function(){if(t.isFocus){var e=document.getElementById(n.IdGenerator.getTableCellId(t.rowIndex,t.colIndex));null==e||e.style.setProperty("outline-style","solid"),null==e||e.style.setProperty("outline-width","1px"),null==e||e.style.setProperty("outline-offset","-1px"),null==e||e.style.setProperty("outline-color","#9ca3af"),null==e||e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),null==e||e.focus()}return function(){if(t.isFocus){var e=document.getElementById(n.IdGenerator.getTableCellId(t.rowIndex,t.colIndex));null==e||e.style.setProperty("outline-style","none")}}}),[t]),t.isFocus?{isFocus:!0,rowIndex:t.rowIndex,colIndex:t.colIndex,focus:u,unfocus:l,move:r,moveLeft:i,moveRight:a,moveUp:d,moveDown:f}:{isFocus:!1,focus:u,unfocus:l,move:r,moveLeft:i,moveRight:a,moveUp:d,moveDown:f}};
|
|
2
|
+
//# sourceMappingURL=hooks.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/focus/hooks.ts"],"sourcesContent":["import { useCallback, useEffect, useReducer } from \"react\";\nimport { TFocusReducer, TReturnFocusReducer } from \"./types\";\nimport { IdGenerator } from \"../libs\";\n\nconst reducer: TFocusReducer = (state, action) => {\n switch (action.type) {\n case \"focus\":\n if (state.isFocus) {\n return state;\n }\n\n return {\n isFocus: true,\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n };\n case \"unfocus\":\n if (!state.isFocus) {\n return state;\n }\n\n return {\n isFocus: false,\n };\n case \"move\":\n if (!state.isFocus) {\n return state;\n }\n\n return {\n isFocus: true,\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n };\n case \"moveLeft\":\n if (!state.isFocus) {\n return state;\n }\n\n return {\n ...state,\n colIndex: state.colIndex - 1,\n };\n case \"moveRight\":\n if (!state.isFocus) {\n return state;\n }\n\n return {\n ...state,\n colIndex: state.colIndex + 1,\n };\n case \"moveUp\":\n if (!state.isFocus) {\n return state;\n }\n\n return {\n ...state,\n rowIndex: state.rowIndex - 1,\n };\n case \"moveDown\":\n if (!state.isFocus) {\n return state;\n }\n\n return {\n ...state,\n rowIndex: state.rowIndex + 1,\n };\n }\n};\n\nexport function useFocusReducer(): TReturnFocusReducer {\n const [state, dispatch] = useReducer(reducer, {\n isFocus: false,\n });\n\n const focus = useCallback((rowIndex: number, colIndex: number) => {\n dispatch({ type: \"focus\", payload: { rowIndex, colIndex } });\n }, []);\n\n const unfocus = useCallback(() => {\n dispatch({ type: \"unfocus\" });\n }, []);\n\n const move = useCallback((rowIndex: number, colIndex: number) => {\n dispatch({ type: \"move\", payload: { rowIndex, colIndex } });\n }, []);\n\n const moveLeft = useCallback(() => {\n dispatch({ type: \"moveLeft\" });\n }, []);\n\n const moveRight = useCallback(() => {\n dispatch({ type: \"moveRight\" });\n }, []);\n\n const moveUp = useCallback(() => {\n dispatch({ type: \"moveUp\" });\n }, []);\n\n const moveDown = useCallback(() => {\n dispatch({ type: \"moveDown\" });\n }, []);\n\n useEffect(() => {\n const onClickOutOfTable = (e: MouseEvent) => {\n const element = document.getElementById(\"table-frame\");\n const ele = e.target;\n if (ele instanceof Node && element?.contains(ele)) return;\n unfocus();\n };\n\n document.addEventListener(\"click\", onClickOutOfTable);\n\n return () => {\n document.removeEventListener(\"click\", onClickOutOfTable);\n };\n }, []);\n\n useEffect(() => {\n if (state.isFocus) {\n const element = document.getElementById(\n IdGenerator.getTableCellId(state.rowIndex, state.colIndex)\n );\n element?.style.setProperty(\"outline-style\", \"solid\");\n element?.style.setProperty(\"outline-width\", \"1px\");\n element?.style.setProperty(\"outline-offset\", \"-1px\");\n element?.style.setProperty(\"outline-color\", \"#9ca3af\");\n\n element?.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n element?.focus();\n }\n\n return () => {\n if (state.isFocus) {\n const element = document.getElementById(\n IdGenerator.getTableCellId(state.rowIndex, state.colIndex)\n );\n element?.style.setProperty(\"outline-style\", \"none\");\n }\n };\n }, [state]);\n\n if (state.isFocus) {\n return {\n isFocus: true,\n rowIndex: state.rowIndex,\n colIndex: state.colIndex,\n focus,\n unfocus,\n move,\n moveLeft,\n moveRight,\n moveUp,\n moveDown,\n };\n } else {\n return {\n isFocus: false,\n focus,\n unfocus,\n move,\n moveLeft,\n moveRight,\n moveUp,\n moveDown,\n };\n }\n}\n"],"names":["reducer","state","action","type","isFocus","rowIndex","payload","colIndex","__assign","_a","useReducer","dispatch","focus","useCallback","unfocus","move","moveLeft","moveRight","moveUp","moveDown","useEffect","onClickOutOfTable","e","element","document","getElementById","ele","target","Node","contains","addEventListener","removeEventListener","IdGenerator","getTableCellId","style","setProperty","scrollIntoView","behavior","block","inline"],"mappings":"+HAIMA,EAAyB,SAACC,EAAOC,GACrC,OAAQA,EAAOC,MACb,IAAK,QACH,OAAIF,EAAMG,QACDH,EAGF,CACLG,SAAS,EACTC,SAAUH,EAAOI,QAAQD,SACzBE,SAAUL,EAAOI,QAAQC,UAE7B,IAAK,UACH,OAAKN,EAAMG,QAIJ,CACLA,SAAS,GAJFH,EAMX,IAAK,OACH,OAAKA,EAAMG,QAIJ,CACLA,SAAS,EACTC,SAAUH,EAAOI,QAAQD,SACzBE,SAAUL,EAAOI,QAAQC,UANlBN,EAQX,IAAK,WACH,OAAKA,EAAMG,QAKNI,WAAAA,EAAAA,SAAA,CAAA,EAAAP,IACHM,SAAUN,EAAMM,SAAW,IALpBN,EAOX,IAAK,YACH,OAAKA,EAAMG,QAKNI,WAAAA,EAAAA,SAAA,CAAA,EAAAP,IACHM,SAAUN,EAAMM,SAAW,IALpBN,EAOX,IAAK,SACH,OAAKA,EAAMG,QAKNI,WAAAA,EAAAA,SAAA,CAAA,EAAAP,IACHI,SAAUJ,EAAMI,SAAW,IALpBJ,EAOX,IAAK,WACH,OAAKA,EAAMG,QAKNI,WAAAA,EAAAA,SAAA,CAAA,EAAAP,IACHI,SAAUJ,EAAMI,SAAW,IALpBJ,EAQf,qCAGQ,IAAAQ,EAAoBC,EAAUA,WAACV,EAAS,CAC5CI,SAAS,IADJH,EAAKQ,EAAA,GAAEE,OAIRC,EAAQC,EAAAA,aAAY,SAACR,EAAkBE,GAC3CI,EAAS,CAAER,KAAM,QAASG,QAAS,CAAED,WAAUE,aAChD,GAAE,IAEGO,EAAUD,EAAAA,aAAY,WAC1BF,EAAS,CAAER,KAAM,WAClB,GAAE,IAEGY,EAAOF,EAAAA,aAAY,SAACR,EAAkBE,GAC1CI,EAAS,CAAER,KAAM,OAAQG,QAAS,CAAED,WAAUE,aAC/C,GAAE,IAEGS,EAAWH,EAAAA,aAAY,WAC3BF,EAAS,CAAER,KAAM,YAClB,GAAE,IAEGc,EAAYJ,EAAAA,aAAY,WAC5BF,EAAS,CAAER,KAAM,aAClB,GAAE,IAEGe,EAASL,EAAAA,aAAY,WACzBF,EAAS,CAAER,KAAM,UAClB,GAAE,IAEGgB,EAAWN,EAAAA,aAAY,WAC3BF,EAAS,CAAER,KAAM,YAClB,GAAE,IA6CH,OA3CAiB,EAAAA,WAAU,WACR,IAAMC,EAAoB,SAACC,GACzB,IAAMC,EAAUC,SAASC,eAAe,eAClCC,EAAMJ,EAAEK,OACVD,aAAeE,OAAQL,aAAA,EAAAA,EAASM,SAASH,KAC7CZ,GACF,EAIA,OAFAU,SAASM,iBAAiB,QAAST,GAE5B,WACLG,SAASO,oBAAoB,QAASV,EACxC,CACD,GAAE,IAEHD,EAAAA,WAAU,WACR,GAAInB,EAAMG,QAAS,CACjB,IAAMmB,EAAUC,SAASC,eACvBO,cAAYC,eAAehC,EAAMI,SAAUJ,EAAMM,WAEnDgB,SAAAA,EAASW,MAAMC,YAAY,gBAAiB,SAC5CZ,SAAAA,EAASW,MAAMC,YAAY,gBAAiB,OAC5CZ,SAAAA,EAASW,MAAMC,YAAY,iBAAkB,QAC7CZ,SAAAA,EAASW,MAAMC,YAAY,gBAAiB,WAE5CZ,SAAAA,EAASa,eAAe,CACtBC,SAAU,SACVC,MAAO,UACPC,OAAQ,YAEVhB,SAAAA,EAASX,OACV,CAED,OAAO,WACL,GAAIX,EAAMG,QAAS,CACjB,IAAMmB,EAAUC,SAASC,eACvBO,cAAYC,eAAehC,EAAMI,SAAUJ,EAAMM,WAEnDgB,SAAAA,EAASW,MAAMC,YAAY,gBAAiB,OAC7C,CACH,CACF,GAAG,CAAClC,IAEAA,EAAMG,QACD,CACLA,SAAS,EACTC,SAAUJ,EAAMI,SAChBE,SAAUN,EAAMM,SAChBK,MAAKA,EACLE,QAAOA,EACPC,KAAIA,EACJC,SAAQA,EACRC,UAASA,EACTC,OAAMA,EACNC,SAAQA,GAGH,CACLf,SAAS,EACTQ,MAAKA,EACLE,QAAOA,EACPC,KAAIA,EACJC,SAAQA,EACRC,UAASA,EACTC,OAAMA,EACNC,SAAQA,EAGd"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),o=require("react/jsx-runtime"),n=require("react"),t=require("./hooks.js"),u=n.createContext({isFocus:!1}),s=n.createContext({focus:function(){},unfocus:function(){},move:function(){},moveLeft:function(){},moveRight:function(){},moveUp:function(){},moveDown:function(){}});function r(){return n.useContext(u)}function c(){return n.useContext(s)}exports.FocusProvider=function(e){var r=t.useFocusReducer(),c=r.isFocus?{isFocus:!0,rowIndex:r.rowIndex,colIndex:r.colIndex}:{isFocus:!1},i=n.useMemo((function(){return{focus:r.focus,unfocus:r.unfocus,move:r.move,moveLeft:r.moveLeft,moveRight:r.moveRight,moveUp:r.moveUp,moveDown:r.moveDown}}),[]);return o.jsx(u.Provider,{value:c,children:o.jsx(s.Provider,{value:i,children:e.children})})},exports.useFocusActionContext=c,exports.useFocusContext=function(){return e.__assign(e.__assign({},r()),c())},exports.useFocusStateContext=r;
|
|
2
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/focus/provider.tsx"],"sourcesContent":["import { createContext, useContext, useMemo } from \"react\";\nimport { TFocusState, TReturnFocusReducer } from \"./types\";\nimport { useFocusReducer } from \"./hooks\";\n\nconst FocusStateContext = createContext<TFocusState>({\n isFocus: false,\n});\n\nconst FocusActionContext = createContext<\n Omit<TReturnFocusReducer, \"isFocus\" | \"rowIndex\" | \"colIndex\">\n>({\n focus: () => {},\n unfocus: () => {},\n move: () => {},\n moveLeft: () => {},\n moveRight: () => {},\n moveUp: () => {},\n moveDown: () => {},\n});\n\nexport function FocusProvider(props: { children: React.ReactNode }) {\n const focus = useFocusReducer();\n\n const state: TFocusState = focus.isFocus\n ? {\n isFocus: true,\n rowIndex: focus.rowIndex,\n colIndex: focus.colIndex,\n }\n : {\n isFocus: false,\n };\n\n const action: Omit<TReturnFocusReducer, \"isFocus\" | \"rowIndex\" | \"colIndex\"> =\n useMemo(() => {\n return {\n focus: focus.focus,\n unfocus: focus.unfocus,\n move: focus.move,\n moveLeft: focus.moveLeft,\n moveRight: focus.moveRight,\n moveUp: focus.moveUp,\n moveDown: focus.moveDown,\n };\n }, []);\n\n return (\n <FocusStateContext.Provider value={state}>\n <FocusActionContext.Provider value={action}>\n {props.children}\n </FocusActionContext.Provider>\n </FocusStateContext.Provider>\n );\n}\n\nexport function useFocusStateContext() {\n return useContext(FocusStateContext);\n}\n\nexport function useFocusActionContext() {\n return useContext(FocusActionContext);\n}\n\nexport function useFocusContext() {\n return { ...useFocusStateContext(), ...useFocusActionContext() };\n}\n"],"names":["FocusStateContext","createContext","isFocus","FocusActionContext","focus","unfocus","move","moveLeft","moveRight","moveUp","moveDown","useFocusStateContext","useContext","useFocusActionContext","props","useFocusReducer","state","rowIndex","colIndex","action","useMemo","_jsx","Provider","value","children","__assign"],"mappings":"iJAIMA,EAAoBC,EAAAA,cAA2B,CACnDC,SAAS,IAGLC,EAAqBF,EAAAA,cAEzB,CACAG,MAAO,WAAQ,EACfC,QAAS,WAAQ,EACjBC,KAAM,WAAQ,EACdC,SAAU,WAAQ,EAClBC,UAAW,WAAQ,EACnBC,OAAQ,WAAQ,EAChBC,SAAU,WAAQ,aAsCJC,IACd,OAAOC,EAAAA,WAAWZ,EACpB,UAEgBa,IACd,OAAOD,EAAAA,WAAWT,EACpB,uBAzCM,SAAwBW,GAC5B,IAAMV,EAAQW,EAAAA,kBAERC,EAAqBZ,EAAMF,QAC7B,CACEA,SAAS,EACTe,SAAUb,EAAMa,SAChBC,SAAUd,EAAMc,UAElB,CACEhB,SAAS,GAGTiB,EACJC,EAAAA,SAAQ,WACN,MAAO,CACLhB,MAAOA,EAAMA,MACbC,QAASD,EAAMC,QACfC,KAAMF,EAAME,KACZC,SAAUH,EAAMG,SAChBC,UAAWJ,EAAMI,UACjBC,OAAQL,EAAMK,OACdC,SAAUN,EAAMM,SAEnB,GAAE,IAEL,OACEW,EAAAA,IAACrB,EAAkBsB,UAASC,MAAOP,EAAKQ,SACtCH,MAAClB,EAAmBmB,SAAQ,CAACC,MAAOJ,EAAMK,SACvCV,EAAMU,YAIf,qEAWE,OAAAC,EAAAA,SAAAA,EAAAA,SAAA,CAAA,EAAYd,KAA2BE,IACzC"}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
"use
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime");require("../filter/provider.js");var i=require("../filter/components.js"),s=require("../sheet/providers.js"),t=require("../sort/components.js");require("../sort/provider.js");var r=require("./resize-col-width-hook.js");exports.TableHeaderElement=function(l){var o=s.useColumnContext(l.columnKey),n=r.useResizeColWidthHook({initialWidth:o.initialWidth,minWidth:o.minWidth}),a=n.colWidth,d=n.onMouseDownResizeWidth;return e.jsxs("th",{id:l.id,className:"relative",style:{minWidth:a},children:[e.jsxs("div",{className:"flex justify-between items-center bg-gray-200 text-gray-600 h-[32px] min-w-fit",children:[e.jsx("div",{className:"px-2",children:o.label&&e.jsx("p",{className:"text-left font-bold text-nowrap overflow-hidden text-ellipsis w-[70%] min-w-20",children:o.label})}),e.jsxs("div",{className:"flex items-center gap-1 px-1",children:[!o.disableSort&&e.jsx(t.SortButton,{columnKey:l.columnKey}),!o.disableFilter&&e.jsx(i.TableFilter,{columnKey:l.columnKey})]})]}),e.jsx("div",{className:"absolute top-0 right-0 grid place-items-end py-1 w-[4px] h-full cursor-col-resize",onMouseDown:d,children:e.jsx("div",{className:"w-[1px] h-full bg-white"})})]})};
|
|
2
3
|
//# sourceMappingURL=header.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"header.js","sources":[
|
|
1
|
+
{"version":3,"file":"header.js","sources":[],"sourcesContent":[],"names":[],"mappings":";"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("../../node_modules/tslib/tslib.es6.js"),t=require("react"),r=require("./pagenation/providers.js");require("react/jsx-runtime");var o=require("./filter/provider.js");require("./filter/constants.js");var n=require("./sheet/providers.js");require("./sort/icon.js");var u=require("./sort/provider.js"),s=require("./focus/provider.js"),i=require("./checkbox/provider.js"),a=require("./edit/provider.js");exports.useCell=function(r,o,u){var i=s.useFocusActionContext(),l=a.useEditActionContext(),c=n.useProcessedDataContext().rows,f=n.useColumnsContext(),v=n.useColumnValidatesContext(),d=t.useCallback((function(){i.move(r,o),i.focus(r,o)}),[i,r,o]),p=t.useCallback((function(t){var n,s,i=0,a=t.trim().replace(/\r\n/g,"\n").split("\n").map((function(e){var t=e.split("\t");return i=Math.max(i,t.length),t}));if(0!==a.length&&0!==i){for(var l=0;l<i;l++){if(!(p=f[o+l]).editable)return void alert("編集できない列にデータを貼り付けることはできません。\n\n編集不可列: ".concat(null!==(n=p.label)&&void 0!==n?n:p.key))}if(a.length+r>c.length)alert("貼り付け先の行数が足りません。");else{for(l=0;l<a.length;l++)for(var d=0;d<a[l].length;d++){var p=f[o+d];if(!(0,v[p.key])(a[l][d]))return void alert("[".concat(null!==(s=p.label)&&void 0!==s?s:p.key,"]列に次の不正なデータが含まれています。\n").concat(a[l][d]))}var C=function(t){for(var n=!1,s=e.__assign({},c[r+t]),i=function(e){var r=f[o+e],u="number"===r.type?Number(a[t][e]):"select"===r.type?""===a[t][e]?"":r.options.find((function(r){return r.label===a[t][e]})).value:a[t][e];s[r.key]!==u&&(n=!0,s[r.key]=u)},l=0;l<a[t].length;l++)i(l);n&&u&&u(s,c[r+t])};for(l=0;l<a.length;l++)C(l)}}}),[r,o]);return{focusAtCell:d,onDoubleClickCellToEdit:t.useCallback((function(e){e.preventDefault(),i.move(r,o),i.focus(r,o),l.startEditing()}),[i,l]),preventPropagation:t.useCallback((function(e){e.preventDefault(),e.stopPropagation()}),[]),pasteData:p}},exports.useTable=function(e){var n=o.useFilterContext().filter,s=u.useSortContext().sort,a=r.usePageContext(),l=a.setRowCount,c=a.pageFilter,f=i.useCheckboxStatusContext().dispatchCheckboxStatus,v=t.useMemo((function(){return n(e.rows)}),[n,e.rows]);t.useEffect((function(){l(v.length)}),[v.length]);var d=t.useMemo((function(){return e.checkbox?e.rows.filter((function(t){var r;return null===(r=e.checkbox)||void 0===r?void 0:r.checked(t)})):[]}),[e.checkbox,e.rows]);t.useEffect((function(){f({type:"SET",payload:{checkedRecords:d}})}),[d]);var p=t.useMemo((function(){return s(v)}),[v,s]),C=t.useMemo((function(){return c(p)}),[c,p]);return{cols:e.cols,rows:C}};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../src/table/hook.ts"],"sourcesContent":["import { useCallback, useEffect, useMemo
|
|
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 { useSortContext } from \"./sort\";\nimport { useFocusActionContext } from \"./focus/provider\";\nimport { useCheckboxStatusContext } from \"./checkbox/provider\";\nimport { useEditActionContext } from \"./edit/provider\";\nimport {\n useColumnsContext,\n useColumnValidatesContext,\n useProcessedDataContext,\n} from \"./sheet/providers\";\n\nexport function useTable<T extends DataRecord>(props: TPropsTable<T>) {\n const { filter } = useFilterContext();\n const { sort } = useSortContext();\n const { setRowCount, pageFilter } = usePageContext();\n const { dispatchCheckboxStatus } = useCheckboxStatusContext();\n\n const filteredRows = useMemo(() => filter(props.rows), [filter, props.rows]);\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(() => sort(filteredRows), [filteredRows, sort]);\n\n const pageRows = useMemo(\n () => pageFilter(sortedRows),\n [pageFilter, sortedRows]\n );\n\n return {\n cols: props.cols,\n rows: pageRows,\n };\n}\n\nexport function useCell<T extends DataRecord>(\n rowIndex: number,\n colIndex: number,\n onUpdateRow?: (newRow: DataObject<T>, oldRow: DataObject<T>) => void\n) {\n const focus = useFocusActionContext();\n const editAction = useEditActionContext();\n const rows = useProcessedDataContext().rows;\n const cols = useColumnsContext();\n const colValidator = useColumnValidatesContext();\n\n const focusAtCell = useCallback(() => {\n focus.move(rowIndex, colIndex);\n focus.focus(rowIndex, colIndex);\n }, [focus, rowIndex, colIndex]);\n\n const pasteData = useCallback(\n (text: string) => {\n let colLength = 0;\n\n const tableData = text\n .trim()\n .replace(/\\r\\n/g, \"\\n\")\n .split(\"\\n\")\n .map((row) => {\n const colsData = row.split(\"\\t\");\n colLength = Math.max(colLength, colsData.length);\n return colsData;\n });\n\n if (tableData.length === 0 || colLength === 0) {\n return;\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\n }`\n );\n return;\n }\n }\n\n if (tableData.length + rowIndex > rows.length) {\n alert(\"貼り付け先の行数が足りません。\");\n return;\n }\n\n for (let i = 0; i < tableData.length; i++) {\n for (let j = 0; j < tableData[i].length; j++) {\n const col = cols[colIndex + j];\n const validate = colValidator[col.key];\n\n if (!validate(tableData[i][j])) {\n alert(\n `[${\n col.label ?? col.key\n }]列に次の不正なデータが含まれています。\\n${tableData[i][j]}`\n );\n return;\n }\n }\n }\n\n for (let i = 0; i < tableData.length; i++) {\n let checkUpdatedRow = false;\n const row = { ...rows[rowIndex + i] };\n\n for (let j = 0; j < tableData[i].length; j++) {\n const col = cols[colIndex + j];\n const value =\n col.type === \"number\"\n ? Number(tableData[i][j])\n : col.type === \"select\"\n ? tableData[i][j] === \"\"\n ? \"\"\n : col.options.find(\n (option) => option.label === tableData[i][j]\n )!.value\n : tableData[i][j];\n\n if (row[col.key] !== value) {\n checkUpdatedRow = true;\n\n row[col.key] = value;\n }\n }\n if (checkUpdatedRow && onUpdateRow)\n onUpdateRow!(\n row as DataObject<T>,\n rows[rowIndex + i] as DataObject<T>\n );\n }\n },\n [rowIndex, colIndex]\n );\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]\n );\n\n const preventPropagation: React.MouseEventHandler<HTMLDivElement> =\n useCallback((e) => {\n e.preventDefault();\n e.stopPropagation();\n }, []);\n\n return {\n focusAtCell,\n onDoubleClickCellToEdit,\n preventPropagation,\n pasteData,\n };\n}\n"],"names":["rowIndex","colIndex","onUpdateRow","focus","useFocusActionContext","editAction","useEditActionContext","rows","useProcessedDataContext","cols","useColumnsContext","colValidator","useColumnValidatesContext","focusAtCell","useCallback","move","pasteData","text","colLength","tableData","trim","replace","split","map","row","colsData","Math","max","length","i","col","editable","alert","concat","_a","label","key","j","validate","_b","checkUpdatedRow","value","type","Number","options","find","option","onDoubleClickCellToEdit","e","preventDefault","startEditing","preventPropagation","stopPropagation","props","filter","useFilterContext","sort","useSortContext","usePageContext","setRowCount","pageFilter","dispatchCheckboxStatus","useCheckboxStatusContext","filteredRows","useMemo","useEffect","checkBoxes","checkbox","checked","payload","checkedRecords","sortedRows","pageRows"],"mappings":"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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";exports.generateValidateFunction=function(t){if("string"===t.type)return a=t.constraints,function(t){return(null==a?void 0:a.maxLength)&&t.length>a.maxLength?(alert("最大文字数(".concat(a.maxLength,")を超過しています。(現在").concat(t.length,"文字)")),!1):(null==a?void 0:a.minLength)&&t.length<a.minLength?(alert("最小文字数(".concat(a.minLength,")を下回っています。(現在").concat(t.length,"文字)")),!1):!((null==a?void 0:a.pattern)&&!new RegExp(a.pattern).test(t)&&(alert("パターンに一致しません。(パターン".concat(a.pattern,")")),1))};if("number"===t.type)return function(t){return function(n){if("string"==typeof n){if(!/^-?[0-9]+(\.[0-9]+)?$/.test(n))return alert("数値ではない値が入力されています。"),!1;n=Number(n)}return"number"==typeof(null==t?void 0:t.max)&&n>t.max?(alert("最大値(".concat(t.max,")を超過しています。(入力値:").concat(n,")")),!1):!("number"==typeof(null==t?void 0:t.min)&&n<t.min&&(alert("最小値(".concat(t.min,")を下回っています。(入力値:").concat(n,")")),1))}}(t.constraints);if("select"===t.type)return n=t.options,e=t.allowEmpty,r=new Set(n.map((function(t){return t.label}))),function(t){return!(!e||""!==t)||!!r.has(t)||(alert("選択肢に含まれていない値です。(選択肢:".concat(t,")")),!1)};throw new Error("Invalid type");var n,e,r,a};
|
|
2
|
+
//# sourceMappingURL=generate-validate-function.js.map
|
|
@@ -0,0 +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":["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":"8CAgHM,SACJA,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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-generator.js","sources":["../../../../../src/table/libs/id-generator.ts"],"sourcesContent":["export const IdGenerator = {\n getTableCellId: (rowIndex: number, columnIndex: number) =>\n `table-cell-${rowIndex}-${columnIndex}`,\n getTableColId: (columnIndex: number) => `table-col-${columnIndex}`,\n};\n"],"names":["getTableCellId","rowIndex","columnIndex","concat","getTableColId"],"mappings":"iCAA2B,CACzBA,eAAgB,SAACC,EAAkBC,GACjC,MAAA,cAAcC,OAAAF,EAAY,KAAAE,OAAAD,EAAa,EACzCE,cAAe,SAACF,GAAwB,MAAA,aAAaC,OAAAD,EAAa"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../table-property/provider.js"),n=require("../../focus/provider.js"),i=require("../../edit/provider.js"),o=require("../../sheet/providers.js");exports.KeyboardSetting=function(){var s=n.useFocusContext(),u=i.useEditContext(),f=r.useTablePropertyStateContext(),d=f.maxDisplayColCount,a=f.maxDisplayRowCount,c=o.useColumnsContext()[s.isFocus?s.colIndex:0],l=s.isFocus?s.rowIndex:-1,v=s.isFocus?s.colIndex:-1;return t.useEffect((function(){var e=function(e){if(u.isEditing)"Escape"===e.key&&(e.preventDefault(),u.endEditing());else if(s.isFocus)if("Enter"===e.key)e.preventDefault(),s.moveDown();else if("Escape"===e.key)e.preventDefault(),s.unfocus();else if("ArrowRight"===e.key){if(e.preventDefault(),s.colIndex===d-1)return;s.moveRight()}else if("ArrowLeft"===e.key){if(e.preventDefault(),0===s.colIndex)return;s.moveLeft()}else if("ArrowUp"===e.key){if(e.preventDefault(),0===s.rowIndex)return;s.moveUp()}else if("ArrowDown"===e.key){if(e.preventDefault(),s.rowIndex===a-1)return;s.moveDown()}else"F2"===e.key&&(e.preventDefault(),u.startEditing())};return document.addEventListener("keydown",e),function(){document.removeEventListener("keydown",e)}}),[u.isEditing,s.isFocus,l,v]),t.useEffect((function(){u.isEditing&&!c.editable&&u.endEditing()}),[u,c]),e.jsx(e.Fragment,{})};
|
|
2
|
+
//# sourceMappingURL=keyboard-setting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keyboard-setting.js","sources":["../../../../../../src/table/operation/components/keyboard-setting.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useTablePropertyStateContext } from \"../../table-property/provider\";\nimport { useFocusContext } from \"../../focus/provider\";\nimport { useEditContext } from \"../../edit/provider\";\nimport { useColumnsContext } from \"../../sheet/providers\";\n\nexport function KeyboardSetting() {\n const focus = useFocusContext();\n const edit = useEditContext();\n const { maxDisplayColCount, maxDisplayRowCount } =\n useTablePropertyStateContext();\n const col = useColumnsContext()[focus.isFocus ? focus.colIndex : 0];\n\n const rowIndex = focus.isFocus ? focus.rowIndex : -1;\n const colIndex = focus.isFocus ? focus.colIndex : -1;\n\n useEffect(() => {\n const listener = (e: KeyboardEvent) => {\n if (edit.isEditing) {\n if (e.key === \"Escape\") {\n e.preventDefault();\n edit.endEditing();\n }\n } else if (focus.isFocus) {\n if (e.key === \"Enter\") {\n e.preventDefault();\n focus.moveDown();\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n focus.unfocus();\n } else if (e.key === \"ArrowRight\") {\n e.preventDefault();\n\n if (focus.colIndex === maxDisplayColCount - 1) return;\n\n focus.moveRight();\n } else if (e.key === \"ArrowLeft\") {\n e.preventDefault();\n\n if (focus.colIndex === 0) return;\n\n focus.moveLeft();\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n\n if (focus.rowIndex === 0) return;\n\n focus.moveUp();\n } else if (e.key === \"ArrowDown\") {\n e.preventDefault();\n\n if (focus.rowIndex === maxDisplayRowCount - 1) return;\n\n focus.moveDown();\n } else if (e.key === \"F2\") {\n e.preventDefault();\n edit.startEditing();\n }\n }\n };\n\n document.addEventListener(\"keydown\", listener);\n\n return () => {\n document.removeEventListener(\"keydown\", listener);\n };\n }, [edit.isEditing, focus.isFocus, rowIndex, colIndex]);\n\n useEffect(() => {\n if (edit.isEditing && !col.editable) {\n edit.endEditing();\n }\n }, [edit, col]);\n\n return <></>;\n}\n"],"names":["focus","useFocusContext","edit","useEditContext","_a","useTablePropertyStateContext","maxDisplayColCount","maxDisplayRowCount","col","useColumnsContext","isFocus","colIndex","rowIndex","useEffect","listener","e","isEditing","key","preventDefault","endEditing","moveDown","unfocus","moveRight","moveLeft","moveUp","startEditing","document","addEventListener","removeEventListener","editable","_jsx"],"mappings":"mQAOE,IAAMA,EAAQC,EAAAA,kBACRC,EAAOC,EAAAA,iBACPC,EACJC,EAA4BA,+BADtBC,EAAkBF,EAAAE,mBAAEC,EAAkBH,EAAAG,mBAExCC,EAAMC,EAAiBA,oBAAGT,EAAMU,QAAUV,EAAMW,SAAW,GAE3DC,EAAWZ,EAAMU,QAAUV,EAAMY,UAAY,EAC7CD,EAAWX,EAAMU,QAAUV,EAAMW,UAAY,EA4DnD,OA1DAE,EAAAA,WAAU,WACR,IAAMC,EAAW,SAACC,GAChB,GAAIb,EAAKc,UACO,WAAVD,EAAEE,MACJF,EAAEG,iBACFhB,EAAKiB,mBAEF,GAAInB,EAAMU,QACf,GAAc,UAAVK,EAAEE,IACJF,EAAEG,iBACFlB,EAAMoB,gBACD,GAAc,WAAVL,EAAEE,IACXF,EAAEG,iBACFlB,EAAMqB,eACD,GAAc,eAAVN,EAAEE,IAAsB,CAGjC,GAFAF,EAAEG,iBAEElB,EAAMW,WAAaL,EAAqB,EAAG,OAE/CN,EAAMsB,WACP,MAAM,GAAc,cAAVP,EAAEE,IAAqB,CAGhC,GAFAF,EAAEG,iBAEqB,IAAnBlB,EAAMW,SAAgB,OAE1BX,EAAMuB,UACP,MAAM,GAAc,YAAVR,EAAEE,IAAmB,CAG9B,GAFAF,EAAEG,iBAEqB,IAAnBlB,EAAMY,SAAgB,OAE1BZ,EAAMwB,QACP,MAAM,GAAc,cAAVT,EAAEE,IAAqB,CAGhC,GAFAF,EAAEG,iBAEElB,EAAMY,WAAaL,EAAqB,EAAG,OAE/CP,EAAMoB,UACP,KAAoB,OAAVL,EAAEE,MACXF,EAAEG,iBACFhB,EAAKuB,eAGX,EAIA,OAFAC,SAASC,iBAAiB,UAAWb,GAE9B,WACLY,SAASE,oBAAoB,UAAWd,EAC1C,CACF,GAAG,CAACZ,EAAKc,UAAWhB,EAAMU,QAASE,EAAUD,IAE7CE,EAAAA,WAAU,WACJX,EAAKc,YAAcR,EAAIqB,UACzB3B,EAAKiB,YAET,GAAG,CAACjB,EAAMM,IAEHsB,oBACT"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("./providers.js");exports.DisplayRange=function(){var n=t.usePageContext(),r=n.enable,s=n.from,a=n.to,u=n.rowCount;return r?e.jsxs("p",{className:"text-center text-sm text-gray-600",children:[s+1," - ",a<u?a:u," of ",u]}):e.jsx(e.Fragment,{})},exports.Pagenation=function(){var n=t.usePageContext(),r=n.enable,s=n.current,a=n.pageCount,u=n.jump,c=n.prev,i=n.next;return r?e.jsxs("div",{className:"flex justify-center gap-2",children:[e.jsx("button",{className:"text-sm",onClick:function(){return u(1)},disabled:1===s,children:"≪"}),e.jsx("button",{className:"text-sm",onClick:function(){return c()},disabled:1===s,children:"<"}),Array.from({length:a},(function(e,t){return t+1})).filter((function(e){return s-2<=e&&e<=s+2})).map((function(t){return e.jsx("button",{className:"text-sm ".concat(s===t?"text-blue-600":""),onClick:function(){return u(t)},children:t},t)})),e.jsx("button",{className:"text-sm",onClick:function(){return i()},disabled:s===a,children:">"}),e.jsx("button",{className:"text-sm",onClick:function(){return u(a)},disabled:s===a,children:"≫"})]}):e.jsx(e.Fragment,{})};
|
|
3
3
|
//# sourceMappingURL=components.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";exports.INITIAL_PAGE_STATE={perPage:50,currentPage:1,rowCount:0};
|
|
1
|
+
"use strict";exports.INITIAL_PAGE_STATE={enable:!0,perPage:50,currentPage:1,rowCount:0};
|
|
2
2
|
//# sourceMappingURL=constants.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","sources":["../../../../../src/table/pagenation/constants.ts"],"sourcesContent":["import { TPageState } from \"./types\";\n\nexport const INITIAL_PAGE_STATE: TPageState = {\n perPage: 50,\n currentPage: 1,\n rowCount: 0,\n};\n"],"names":["perPage","currentPage","rowCount"],"mappings":"wCAE8C,CAC5CA,QAAS,GACTC,YAAa,EACbC,SAAU"}
|
|
1
|
+
{"version":3,"file":"constants.js","sources":["../../../../../src/table/pagenation/constants.ts"],"sourcesContent":["import { TPageState } from \"./types\";\n\nexport const INITIAL_PAGE_STATE: TPageState = {\n enable: true,\n perPage: 50,\n currentPage: 1,\n rowCount: 0,\n};\n"],"names":["enable","perPage","currentPage","rowCount"],"mappings":"wCAE8C,CAC5CA,QAAQ,EACRC,QAAS,GACTC,YAAa,EACbC,SAAU"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),r=require("react"),a=require("./constants.js");function
|
|
1
|
+
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),r=require("react"),a=require("./constants.js");function n(r,a){switch(a.type){case"setRowCount":return r.enable?e.__assign(e.__assign({},r),{currentPage:1,rowCount:a.payload.rowCount}):e.__assign(e.__assign({},r),{rowCount:a.payload.rowCount});case"setPerPage":return"all"===a.payload.perPage?{rowCount:r.rowCount,enable:!1}:r.enable?e.__assign(e.__assign({},r),{currentPage:1,perPage:a.payload.perPage}):{rowCount:r.rowCount,enable:!0,currentPage:1,perPage:a.payload.perPage};case"next":return r.enable?r.currentPage===Math.ceil(r.rowCount/r.perPage)?r:e.__assign(e.__assign({},r),{currentPage:r.currentPage+1}):r;case"prev":return r.enable?1===r.currentPage?r:e.__assign(e.__assign({},r),{currentPage:r.currentPage-1}):r;case"jump":return r.enable?a.payload.pageNumber<1||a.payload.pageNumber>Math.ceil(r.rowCount/r.perPage)||r.currentPage===a.payload.pageNumber?r:e.__assign(e.__assign({},r),{currentPage:a.payload.pageNumber}):r;default:return r}}exports.usePageReducer=function(e){var t=r.useReducer(n,null!=e?e:a.INITIAL_PAGE_STATE),u=t[0],o=t[1],s=r.useCallback((function(){return o({type:"next"})}),[o]),l=r.useCallback((function(){return o({type:"prev"})}),[o]),g=r.useCallback((function(e){return o({type:"jump",payload:{pageNumber:e}})}),[o]),c=r.useCallback((function(e){return o({type:"setRowCount",payload:{rowCount:e}})}),[o]),p=r.useMemo((function(){return u.enable?(u.currentPage-1)*u.perPage:0}),[u]),i=r.useMemo((function(){return u.enable?u.currentPage*u.perPage:u.rowCount}),[u]),P=r.useCallback((function(e){return e.slice(p,i)}),[p,i]);return{enable:u.enable,perPage:u.enable?u.perPage:u.rowCount,current:u.enable?u.currentPage:1,rowCount:u.rowCount,pageCount:u.enable?Math.ceil(u.rowCount/u.perPage):1,from:p,to:i,next:s,prev:l,jump:g,setRowCount:c,pageFilter:P}};
|
|
2
2
|
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/pagenation/hooks.ts"],"sourcesContent":["import { useCallback, useMemo, useReducer } from \"react\";\nimport { TPageAction, TPageState } from \"./types\";\nimport { INITIAL_PAGE_STATE } from \"./constants\";\nimport { DataObject, DataRecord } from \"../type\";\n\nfunction pagenationReducer(state: TPageState, action: TPageAction): TPageState {\n switch (action.type) {\n case \"setRowCount\":\n return {\n ...state,\n currentPage: 1,\n rowCount: action.payload.rowCount,\n };\n case \"setPerPage\":\n return {\n ...state,\n perPage: action.payload.perPage,\n };\n case \"next\":\n if (state.currentPage === Math.ceil(state.rowCount / state.perPage)) {\n return state;\n }\n\n return {\n ...state,\n currentPage: state.currentPage + 1,\n };\n case \"prev\":\n if (state.currentPage === 1) {\n return state;\n }\n\n return {\n ...state,\n currentPage: state.currentPage - 1,\n };\n case \"jump\":\n if (\n action.payload.pageNumber < 1 ||\n action.payload.pageNumber > Math.ceil(state.rowCount / state.perPage) ||\n state.currentPage === action.payload.pageNumber\n ) {\n return state;\n }\n\n return {\n ...state,\n currentPage: action.payload.pageNumber,\n };\n default:\n return state;\n }\n}\n\nexport function usePageReducer(initialState?: TPageState) {\n const [state, dispatch] = useReducer(\n pagenationReducer,\n initialState ?? INITIAL_PAGE_STATE\n );\n\n const next = useCallback(() => dispatch({ type: \"next\" }), [dispatch]);\n const prev = useCallback(() => dispatch({ type: \"prev\" }), [dispatch]);\n const jump = useCallback(\n (pageNumber: number) => dispatch({ type: \"jump\", payload: { pageNumber } }),\n [dispatch]\n );\n\n const setRowCount = useCallback(\n (rowCount: number) =>\n dispatch({ type: \"setRowCount\", payload: { rowCount } }),\n [dispatch]\n );\n\n const from = useMemo(() => (state.currentPage - 1) * state.perPage, [state]);\n const to = useMemo(() => state.currentPage * state.perPage, [state]);\n\n const pageFilter = useCallback(\n <U extends DataRecord>(data: DataObject<U>[]): DataObject<U>[] => {\n return data.slice(from, to);\n },\n [from, to]\n );\n\n return {\n perPage: state.perPage,\n current: state.currentPage,\n rowCount: state.rowCount,\n pageCount: Math.ceil(state.rowCount / state.perPage),\n from,\n to,\n next,\n prev,\n jump,\n setRowCount,\n pageFilter,\n };\n}\n"],"names":["pagenationReducer","state","action","type","__assign","currentPage","rowCount","payload","perPage","Math","ceil","pageNumber","initialState","_a","useReducer","INITIAL_PAGE_STATE","dispatch","next","useCallback","prev","jump","setRowCount","from","useMemo","to","pageFilter","data","slice","current","pageCount"],"mappings":"sHAKA,SAASA,EAAkBC,EAAmBC,GAC5C,OAAQA,EAAOC,MACb,IAAK,cACH,
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/pagenation/hooks.ts"],"sourcesContent":["import { useCallback, useMemo, useReducer } from \"react\";\nimport { TPageAction, TPageState } from \"./types\";\nimport { INITIAL_PAGE_STATE } from \"./constants\";\nimport { DataObject, DataRecord } from \"../type\";\n\nfunction pagenationReducer(state: TPageState, action: TPageAction): TPageState {\n switch (action.type) {\n case \"setRowCount\":\n if (!state.enable) {\n return {\n ...state,\n rowCount: action.payload.rowCount,\n };\n }\n return {\n ...state,\n currentPage: 1,\n rowCount: action.payload.rowCount,\n };\n case \"setPerPage\":\n if (action.payload.perPage === \"all\") {\n return {\n rowCount: state.rowCount,\n enable: false,\n };\n }\n\n if (!state.enable) {\n return {\n rowCount: state.rowCount,\n enable: true,\n currentPage: 1,\n perPage: action.payload.perPage,\n };\n }\n\n return {\n ...state,\n currentPage: 1,\n perPage: action.payload.perPage,\n };\n case \"next\":\n if (!state.enable) {\n return state;\n }\n\n if (state.currentPage === Math.ceil(state.rowCount / state.perPage)) {\n return state;\n }\n\n return {\n ...state,\n currentPage: state.currentPage + 1,\n };\n case \"prev\":\n if (!state.enable) {\n return state;\n }\n\n if (state.currentPage === 1) {\n return state;\n }\n\n return {\n ...state,\n currentPage: state.currentPage - 1,\n };\n case \"jump\":\n if (!state.enable) {\n return state;\n }\n\n if (\n action.payload.pageNumber < 1 ||\n action.payload.pageNumber > Math.ceil(state.rowCount / state.perPage) ||\n state.currentPage === action.payload.pageNumber\n ) {\n return state;\n }\n\n return {\n ...state,\n currentPage: action.payload.pageNumber,\n };\n default:\n return state;\n }\n}\n\nexport function usePageReducer(initialState?: TPageState) {\n const [state, dispatch] = useReducer(\n pagenationReducer,\n initialState ?? INITIAL_PAGE_STATE\n );\n\n const next = useCallback(() => dispatch({ type: \"next\" }), [dispatch]);\n const prev = useCallback(() => dispatch({ type: \"prev\" }), [dispatch]);\n const jump = useCallback(\n (pageNumber: number) => dispatch({ type: \"jump\", payload: { pageNumber } }),\n [dispatch]\n );\n\n const setRowCount = useCallback(\n (rowCount: number) =>\n dispatch({ type: \"setRowCount\", payload: { rowCount } }),\n [dispatch]\n );\n\n const from = useMemo(() => {\n if (!state.enable) {\n return 0;\n }\n return (state.currentPage - 1) * state.perPage;\n }, [state]);\n\n const to = useMemo(() => {\n if (!state.enable) {\n return state.rowCount;\n }\n return state.currentPage * state.perPage;\n }, [state]);\n\n const pageFilter = useCallback(\n <U extends DataRecord>(data: DataObject<U>[]): DataObject<U>[] => {\n return data.slice(from, to);\n },\n [from, to]\n );\n\n return {\n enable: state.enable,\n perPage: state.enable ? state.perPage : state.rowCount,\n current: state.enable ? state.currentPage : 1,\n rowCount: state.rowCount,\n pageCount: state.enable ? Math.ceil(state.rowCount / state.perPage) : 1,\n from,\n to,\n next,\n prev,\n jump,\n setRowCount,\n pageFilter,\n };\n}\n"],"names":["pagenationReducer","state","action","type","enable","__assign","currentPage","rowCount","payload","perPage","Math","ceil","pageNumber","initialState","_a","useReducer","INITIAL_PAGE_STATE","dispatch","next","useCallback","prev","jump","setRowCount","from","useMemo","to","pageFilter","data","slice","current","pageCount"],"mappings":"sHAKA,SAASA,EAAkBC,EAAmBC,GAC5C,OAAQA,EAAOC,MACb,IAAK,cACH,OAAKF,EAAMG,OAMXC,EAAAA,SAAAA,EAAAA,SAAA,GACKJ,GAAK,CACRK,YAAa,EACbC,SAAUL,EAAOM,QAAQD,WAPpBF,WAAAA,EAAAA,SAAA,CAAA,EAAAJ,IACHM,SAAUL,EAAOM,QAAQD,WAQ/B,IAAK,aACH,MAA+B,QAA3BL,EAAOM,QAAQC,QACV,CACLF,SAAUN,EAAMM,SAChBH,QAAQ,GAIPH,EAAMG,OASXC,EAAAA,SAAAA,EAAAA,SAAA,GACKJ,GAAK,CACRK,YAAa,EACbG,QAASP,EAAOM,QAAQC,UAXjB,CACLF,SAAUN,EAAMM,SAChBH,QAAQ,EACRE,YAAa,EACbG,QAASP,EAAOM,QAAQC,SAS9B,IAAK,OACH,OAAKR,EAAMG,OAIPH,EAAMK,cAAgBI,KAAKC,KAAKV,EAAMM,SAAWN,EAAMQ,SAClDR,EAIJI,WAAAA,EAAAA,SAAA,CAAA,EAAAJ,IACHK,YAAaL,EAAMK,YAAc,IAT1BL,EAWX,IAAK,OACH,OAAKA,EAAMG,OAIe,IAAtBH,EAAMK,YACDL,EAIJI,WAAAA,EAAAA,SAAA,CAAA,EAAAJ,IACHK,YAAaL,EAAMK,YAAc,IAT1BL,EAWX,IAAK,OACH,OAAKA,EAAMG,OAKTF,EAAOM,QAAQI,WAAa,GAC5BV,EAAOM,QAAQI,WAAaF,KAAKC,KAAKV,EAAMM,SAAWN,EAAMQ,UAC7DR,EAAMK,cAAgBJ,EAAOM,QAAQI,WAE9BX,EAIJI,WAAAA,EAAAA,SAAA,CAAA,EAAAJ,IACHK,YAAaJ,EAAOM,QAAQI,aAbrBX,EAeX,QACE,OAAOA,EAEb,wBAEM,SAAyBY,GACvB,IAAAC,EAAoBC,EAAAA,WACxBf,EACAa,QAAAA,EAAgBG,EAAAA,oBAFXf,OAAOgB,OAKRC,EAAOC,EAAAA,aAAY,WAAM,OAAAF,EAAS,CAAEd,KAAM,QAAjB,GAA4B,CAACc,IACtDG,EAAOD,EAAAA,aAAY,WAAM,OAAAF,EAAS,CAAEd,KAAM,QAAjB,GAA4B,CAACc,IACtDI,EAAOF,EAAAA,aACX,SAACP,GAAuB,OAAAK,EAAS,CAAEd,KAAM,OAAQK,QAAS,CAAEI,WAAUA,OACtE,CAACK,IAGGK,EAAcH,eAClB,SAACZ,GACC,OAAAU,EAAS,CAAEd,KAAM,cAAeK,QAAS,CAAED,SAAQA,IAAnD,GACF,CAACU,IAGGM,EAAOC,EAAAA,SAAQ,WACnB,OAAKvB,EAAMG,QAGHH,EAAMK,YAAc,GAAKL,EAAMQ,QAF9B,CAGX,GAAG,CAACR,IAEEwB,EAAKD,EAAAA,SAAQ,WACjB,OAAKvB,EAAMG,OAGJH,EAAMK,YAAcL,EAAMQ,QAFxBR,EAAMM,QAGjB,GAAG,CAACN,IAEEyB,EAAaP,eACjB,SAAuBQ,GACrB,OAAOA,EAAKC,MAAML,EAAME,EAC1B,GACA,CAACF,EAAME,IAGT,MAAO,CACLrB,OAAQH,EAAMG,OACdK,QAASR,EAAMG,OAASH,EAAMQ,QAAUR,EAAMM,SAC9CsB,QAAS5B,EAAMG,OAASH,EAAMK,YAAc,EAC5CC,SAAUN,EAAMM,SAChBuB,UAAW7B,EAAMG,OAASM,KAAKC,KAAKV,EAAMM,SAAWN,EAAMQ,SAAW,EACtEc,KAAIA,EACJE,GAAEA,EACFP,KAAIA,EACJE,KAAIA,EACJC,KAAIA,EACJC,YAAWA,EACXI,WAAUA,EAEd"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
"use strict";var e=require("react/jsx-runtime"),r=require("react"),n=require("./hooks.js"),t=r.createContext({perPage:0,current:0,pageCount:0,from:0,to:0,rowCount:0,next:function(){throw new Error("Function not implemented.")},prev:function(){throw new Error("Function not implemented.")},jump:function(){throw new Error("Function not implemented.")},setRowCount:function(){throw new Error("Function not implemented.")},pageFilter:function(){return[]}});exports.PagenationProvider=function(r){var o,u
|
|
2
|
+
"use strict";var e=require("react/jsx-runtime"),r=require("react"),n=require("./hooks.js"),t=r.createContext({enable:!0,perPage:0,current:0,pageCount:0,from:0,to:0,rowCount:0,next:function(){throw new Error("Function not implemented.")},prev:function(){throw new Error("Function not implemented.")},jump:function(){throw new Error("Function not implemented.")},setRowCount:function(){throw new Error("Function not implemented.")},pageFilter:function(){return[]}});exports.PagenationProvider=function(r){var o,u,i="all"===r.perPage?{enable:!1,rowCount:r.rowCount}:{enable:!0,rowCount:r.rowCount,perPage:null!==(o=r.perPage)&&void 0!==o?o:50,currentPage:null!==(u=r.currentPage)&&void 0!==u?u:1};return e.jsx(t.Provider,{value:n.usePageReducer(i),children:r.children})},exports.usePageContext=function(){return r.useContext(t)};
|
|
3
3
|
//# sourceMappingURL=providers.js.map
|
|
@@ -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"),t=require("react"),r=require("../hook.js"),n=require("../libs/generate-validate-function.js"),o=t.createContext({cols:[],rows:[]});var u=t.createContext({id:""});var s=t.createContext({cols:[],colMaps:{},validates:{}});exports.ColumnsProvider=function(r){var o=r.children,u=r.cols,i=t.useMemo((function(){return u.reduce((function(e,t){return e[t.key]=t,e}),{})}),[u]),c=t.useMemo((function(){return u.reduce((function(e,t){return e[t.key]=n.generateValidateFunction(t),e}),{})}),[u]),a=t.useMemo((function(){return{cols:u,colMaps:i,validates:c}}),[u]);return e.jsx(s.Provider,{value:a,children:o})},exports.ProcessedDataProvider=function(t){var n=t.children,u=t.props,s=r.useTable(u),i=s.cols,c=s.rows;return e.jsx(o.Provider,{value:{cols:i,rows:c},children:n})},exports.RowProvider=function(r){var n=r.children,o=r.row,s=t.useMemo((function(){return o}),[o]);return e.jsx(u.Provider,{value:s,children:n})},exports.useColumnContext=function(e){return t.useContext(s).colMaps[e]},exports.useColumnValidateContext=function(e){return t.useContext(s).validates[e]},exports.useColumnValidatesContext=function(){return t.useContext(s).validates},exports.useColumnsContext=function(){return t.useContext(s).cols},exports.useProcessedDataContext=function(){return t.useContext(o)},exports.useRowContext=function(){return t.useContext(u)};
|
|
3
3
|
//# sourceMappingURL=providers.js.map
|
|
@@ -0,0 +1,2 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),t=require("react"),r=require("../../sheet/providers.js"),s=require("../provider.js");exports.AutoUpdateTableProperty=function(){var o=s.useTablePropertyActionContext(),n=o.setMaxDisplayColCount,u=o.setMaxDisplayRowCount,a=r.useProcessedDataContext(),i=a.cols,c=a.rows;return t.useEffect((function(){n(i.length)}),[i.length]),t.useEffect((function(){u(c.length)}),[c.length]),e.jsx(e.Fragment,{})};
|
|
2
|
+
//# sourceMappingURL=auto-update-table-property.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auto-update-table-property.js","sources":["../../../../../../src/table/table-property/components/auto-update-table-property.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { useProcessedDataContext } from \"../../sheet/providers\";\nimport { useTablePropertyActionContext } from \"../provider\";\n\nexport function AutoUpdateTableProperty() {\n const { setMaxDisplayColCount, setMaxDisplayRowCount } =\n useTablePropertyActionContext();\n const { cols, rows } = useProcessedDataContext();\n\n useEffect(() => {\n setMaxDisplayColCount(cols.length);\n }, [cols.length]);\n\n useEffect(() => {\n setMaxDisplayRowCount(rows.length);\n }, [rows.length]);\n\n return <></>;\n}\n"],"names":["_a","useTablePropertyActionContext","setMaxDisplayColCount","setMaxDisplayRowCount","_b","useProcessedDataContext","cols","rows","useEffect","length","_jsx"],"mappings":"gLAKQ,IAAAA,EACJC,EAA6BA,gCADvBC,EAAqBF,EAAAE,sBAAEC,EAAqBH,EAAAG,sBAE9CC,EAAiBC,EAAuBA,0BAAtCC,EAAIF,EAAAE,KAAEC,EAAIH,EAAAG,KAUlB,OARAC,EAAAA,WAAU,WACRN,EAAsBI,EAAKG,OAC7B,GAAG,CAACH,EAAKG,SAETD,EAAAA,WAAU,WACRL,EAAsBI,EAAKE,OAC7B,GAAG,CAACF,EAAKE,SAEFC,oBACT"}
|