@teppen/react-ui 1.5.17 → 1.6.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/dist/cjs/node_modules/tslib/tslib.es6.js +1 -1
- package/dist/cjs/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/cjs/src/lib/errors.js +2 -0
- package/dist/cjs/src/lib/errors.js.map +1 -0
- package/dist/cjs/src/table/cell/hooks.js +1 -1
- package/dist/cjs/src/table/cell/hooks.js.map +1 -1
- package/dist/cjs/src/table/cell/ui/cell.js +1 -1
- package/dist/cjs/src/table/copy/hooks.js +2 -0
- package/dist/cjs/src/table/copy/hooks.js.map +1 -0
- package/dist/cjs/src/table/copy/provider.js +2 -0
- package/dist/cjs/src/table/copy/provider.js.map +1 -0
- package/dist/cjs/src/table/edit/ui/editor.js +1 -1
- package/dist/cjs/src/table/edit/ui/editor.js.map +1 -1
- package/dist/cjs/src/table/lib/errors.js +2 -0
- package/dist/cjs/src/table/lib/errors.js.map +1 -0
- package/dist/cjs/src/table/libs/id-generator.js +1 -1
- package/dist/cjs/src/table/libs/id-generator.js.map +1 -1
- package/dist/cjs/src/table/operation/components/keyboard-setting.js +2 -1
- package/dist/cjs/src/table/operation/components/keyboard-setting.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/range/errors.js +2 -0
- package/dist/cjs/src/table/range/errors.js.map +1 -0
- package/dist/cjs/src/table/range/hooks.js +2 -0
- package/dist/cjs/src/table/range/hooks.js.map +1 -0
- package/dist/cjs/src/table/range/provider.js +2 -0
- package/dist/cjs/src/table/range/provider.js.map +1 -0
- package/dist/cjs/src/table/sheet/components.js +1 -1
- package/dist/cjs/src/table/sheet/components.js.map +1 -1
- package/dist/cjs/src/table/table/base.js +1 -1
- package/dist/cjs/src/table/table/hook.js +1 -1
- package/dist/cjs/src/table/table/hook.js.map +1 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js +1 -1
- package/dist/esm/node_modules/tslib/tslib.es6.js.map +1 -1
- package/dist/esm/src/lib/errors.js +2 -0
- package/dist/esm/src/lib/errors.js.map +1 -0
- package/dist/esm/src/table/cell/hooks.js +1 -1
- package/dist/esm/src/table/cell/hooks.js.map +1 -1
- package/dist/esm/src/table/cell/ui/cell.js +1 -1
- package/dist/esm/src/table/copy/hooks.js +2 -0
- package/dist/esm/src/table/copy/hooks.js.map +1 -0
- package/dist/esm/src/table/copy/provider.js +2 -0
- package/dist/esm/src/table/copy/provider.js.map +1 -0
- package/dist/esm/src/table/edit/ui/editor.js +1 -1
- package/dist/esm/src/table/edit/ui/editor.js.map +1 -1
- package/dist/esm/src/table/lib/errors.js +2 -0
- package/dist/esm/src/table/lib/errors.js.map +1 -0
- package/dist/esm/src/table/libs/id-generator.js +1 -1
- package/dist/esm/src/table/libs/id-generator.js.map +1 -1
- package/dist/esm/src/table/operation/components/keyboard-setting.js +2 -1
- package/dist/esm/src/table/operation/components/keyboard-setting.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/range/errors.js +2 -0
- package/dist/esm/src/table/range/errors.js.map +1 -0
- package/dist/esm/src/table/range/hooks.js +2 -0
- package/dist/esm/src/table/range/hooks.js.map +1 -0
- package/dist/esm/src/table/range/provider.js +2 -0
- package/dist/esm/src/table/range/provider.js.map +1 -0
- package/dist/esm/src/table/sheet/components.js +1 -1
- package/dist/esm/src/table/sheet/components.js.map +1 -1
- package/dist/esm/src/table/table/base.js +1 -1
- package/dist/esm/src/table/table/hook.js +1 -1
- package/dist/esm/src/table/table/hook.js.map +1 -1
- package/package.json +1 -1
- package/dist/cjs/src/table/focus/hooks.js +0 -2
- package/dist/cjs/src/table/focus/hooks.js.map +0 -1
- package/dist/cjs/src/table/focus/provider.js +0 -2
- package/dist/cjs/src/table/focus/provider.js.map +0 -1
- package/dist/esm/src/table/focus/hooks.js +0 -2
- package/dist/esm/src/table/focus/hooks.js.map +0 -1
- package/dist/esm/src/table/focus/provider.js +0 -2
- package/dist/esm/src/table/focus/provider.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/range/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, useReducer } from \"react\";\nimport { InvalidOperationError, OutOfRangeError } from \"./errors\";\nimport {\n IIndex,\n TRangeReducer,\n IRangeConstraint,\n TReturnRangeReducer,\n} from \"./type\";\nimport { IdGenerator } from \"../libs\";\n\nfunction newRangeConstraint({\n maxColIndex,\n maxRowIndex,\n}: {\n maxColIndex: number;\n maxRowIndex: number;\n}): IRangeConstraint {\n if (maxColIndex < -1) {\n throw new OutOfRangeError(\n \"001\",\n \"maxColIndex must be 0 or greater\",\n `The provided maxColIndex (${maxColIndex}) is out of range. It must be 0 or greater.`\n );\n }\n\n if (maxRowIndex < -1) {\n throw new OutOfRangeError(\n \"002\",\n \"maxRowIndex must be 0 or greater\",\n `The provided maxRowIndex (${maxRowIndex}) is out of range. It must be 0 or greater.`\n );\n }\n\n return {\n maxColIndex,\n maxRowIndex,\n };\n}\n\nfunction newIndex({\n rowIndex,\n colIndex,\n constraint: { maxRowIndex, maxColIndex },\n}: {\n rowIndex: number;\n colIndex: number;\n constraint: IRangeConstraint;\n}): IIndex {\n if (rowIndex < 0) {\n throw new OutOfRangeError(\n \"003\",\n \"rowIndex must be 0 or greater\",\n `The provided rowIndex (${rowIndex}) is out of range. It must be 0 or greater.`\n );\n }\n\n if (maxRowIndex < rowIndex) {\n throw new OutOfRangeError(\n \"004\",\n \"rowIndex must be less than maxRowIndex\",\n `The provided rowIndex (${rowIndex}) is out of range. It must be less than ${maxRowIndex}.`\n );\n }\n\n if (colIndex < 0) {\n throw new OutOfRangeError(\n \"005\",\n \"colIndex must be 0 or greater\",\n `The provided colIndex (${colIndex}) is out of range. It must be 0 or greater.`\n );\n }\n\n if (maxColIndex < colIndex) {\n throw new OutOfRangeError(\n \"006\",\n \"colIndex must be less than maxColIndex\",\n `The provided colIndex (${colIndex}) is out of range. It must be less than ${maxColIndex}.`\n );\n }\n\n return { rowIndex, colIndex };\n}\n\nfunction equalIndex(a: IIndex, b: IIndex): boolean {\n return a.rowIndex === b.rowIndex && a.colIndex === b.colIndex;\n}\n\nconst MOVE_ACTION = {\n UP: { deltaRow: -1, deltaCol: 0 },\n DOWN: { deltaRow: 1, deltaCol: 0 },\n LEFT: { deltaRow: 0, deltaCol: -1 },\n RIGHT: { deltaRow: 0, deltaCol: 1 },\n} as const;\n\ntype TMoveAction = keyof typeof MOVE_ACTION;\n\nfunction moveIndex({\n index,\n direction,\n constraint,\n}: {\n index: IIndex;\n direction: TMoveAction;\n constraint: IRangeConstraint;\n}): IIndex {\n const { deltaRow, deltaCol } = MOVE_ACTION[direction];\n\n const newRow = index.rowIndex + deltaRow;\n const newCol = index.colIndex + deltaCol;\n\n try {\n return newIndex({\n rowIndex: newRow,\n colIndex: newCol,\n constraint,\n });\n } catch (e) {\n if (e instanceof OutOfRangeError) {\n return index;\n }\n\n throw e;\n }\n}\n\nexport const rangeReducer: TRangeReducer = (state, action) => {\n switch (action.type) {\n /**\n * Actionが\"setMax\"の場合の説明:\n * - Actionのtypeが\"setMax\"の場合、選択範囲の最大値を設定します。\n * - payloadのmaxRowIndexとmaxColIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、constraintを新しい範囲制約に設定します。\n */\n case \"setMax\":\n return {\n ...state,\n constraint: newRangeConstraint(action.payload),\n };\n\n /**\n * Actionが\"start\"の場合の説明:\n * - Actionのtypeが\"start\"の場合、選択範囲の開始位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、isSelectingをtrueに設定し、startとendの位置をpayloadの位置に設定します。\n */\n case \"startSelectRange\": {\n const startIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (\n state.isSelecting &&\n equalIndex(state.start, startIndex) &&\n equalIndex(state.end, startIndex) &&\n state.inProgress\n ) {\n return state;\n }\n\n return {\n ...state,\n isSelecting: true,\n inProgress: true,\n start: startIndex,\n end: startIndex,\n };\n }\n\n case \"moveSelectRange\": {\n if (!state.isSelecting || !state.inProgress) {\n return state;\n }\n\n const endIndex = newIndex({\n rowIndex: action.payload.rowIndex,\n colIndex: action.payload.colIndex,\n constraint: state.constraint,\n });\n\n if (equalIndex(state.end, endIndex)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"end\"の場合の説明:\n * - Actionのtypeが\"end\"の場合、選択範囲の終了位置を設定します。\n * - payloadのrowIndexとcolIndexが範囲外の場合、OutOfRangeErrorをスローします。\n * - 範囲内の場合、endの位置をpayloadの位置に設定します。\n * - この場合、isSelectingはtrueのままです。\n */\n case \"endSelectRange\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"001\",\n \"Cannot set end without starting\",\n \"Cannot set end without starting\"\n );\n }\n\n if (!state.inProgress) {\n return state;\n }\n\n return {\n ...state,\n inProgress: false,\n };\n }\n\n /**\n * Actionが\"moveUp\"の場合の説明:\n * - Actionのtypeが\"moveUp\"の場合、選択範囲を上に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に移動します。\n */\n case \"moveUp\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"002\",\n \"Cannot move without starting\",\n \"Cannot move without starting\"\n );\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveDown\"の場合の説明:\n * - Actionのtypeが\"moveDown\"の場合、選択範囲を下に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に移動します。\n */\n case \"moveDown\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"003\",\n \"Cannot move without starting\",\n \"Cannot move without starting\"\n );\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveLeft\"の場合の説明:\n * - Actionのtypeが\"moveLeft\"の場合、選択範囲を左に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に移動します。\n */\n case \"moveLeft\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"004\",\n \"Cannot move without starting\",\n \"Cannot move without starting\"\n );\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"moveRight\"の場合の説明:\n * - Actionのtypeが\"moveRight\"の場合、選択範囲を右に移動します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に移動します。\n */\n case \"moveRight\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"005\",\n \"Cannot move without starting\",\n \"Cannot move without starting\"\n );\n }\n\n const startIndex = moveIndex({\n index: state.start,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (\n equalIndex(startIndex, state.start) &&\n equalIndex(startIndex, state.end)\n ) {\n return state;\n }\n\n return {\n ...state,\n start: startIndex,\n end: startIndex,\n };\n }\n\n /**\n * Actionが\"extendUp\"の場合の説明:\n * - Actionのtypeが\"extendUp\"の場合、選択範囲を上に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ上に拡張します。\n */\n case \"extendUp\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"006\",\n \"Cannot extend without starting\",\n \"Cannot extend without starting\"\n );\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"UP\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendDown\"の場合の説明:\n * - Actionのtypeが\"extendDown\"の場合、選択範囲を下に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ下に拡張します。\n */\n case \"extendDown\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"007\",\n \"Cannot extend without starting\",\n \"Cannot extend without starting\"\n );\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"DOWN\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendLeft\"の場合の説明:\n * - Actionのtypeが\"extendLeft\"の場合、選択範囲を左に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ左に拡張します。\n */\n case \"extendLeft\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"008\",\n \"Cannot extend without starting\",\n \"Cannot extend without starting\"\n );\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"LEFT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"extendRight\"の場合の説明:\n * - Actionのtypeが\"extendRight\"の場合、選択範囲を右に拡張します。\n * - isSelectingがfalseの場合、InvalidOperationErrorをスローします。\n * - 移動後の位置がstartとendが同じ場合、stateをそのまま返します。\n * - それ以外の場合、endの位置を1つ右に拡張します。\n */\n case \"extendRight\": {\n if (!state.isSelecting) {\n throw new InvalidOperationError(\n \"009\",\n \"Cannot extend without starting\",\n \"Cannot extend without starting\"\n );\n }\n\n const endIndex = moveIndex({\n index: state.end,\n direction: \"RIGHT\",\n constraint: state.constraint,\n });\n\n if (equalIndex(endIndex, state.end)) {\n return state;\n }\n\n return {\n ...state,\n end: endIndex,\n };\n }\n\n /**\n * Actionが\"reset\"の場合の説明:\n * - Actionのtypeが\"reset\"の場合、選択範囲をリセットします。\n * - isSelectingをfalseに設定します。\n */\n case \"reset\":\n return {\n constraint: state.constraint,\n isSelecting: false,\n };\n }\n};\n\nexport function useRangeReducer(): TReturnRangeReducer {\n const [state, dispatch] = useReducer(rangeReducer, {\n constraint: newRangeConstraint({ maxColIndex: 0, maxRowIndex: 0 }),\n isSelecting: false,\n });\n\n const actions = useMemo(\n () => ({\n setMax: (payload: { maxRowIndex: number; maxColIndex: number }) => {\n dispatch({ type: \"setMax\", payload });\n },\n startSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"startSelectRange\", payload });\n },\n moveSelectRange: (payload: { rowIndex: number; colIndex: number }) => {\n dispatch({ type: \"moveSelectRange\", payload });\n },\n endSelectRange: () => {\n dispatch({ type: \"endSelectRange\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n extendUp: () => {\n dispatch({ type: \"extendUp\" });\n },\n extendDown: () => {\n dispatch({ type: \"extendDown\" });\n },\n extendLeft: () => {\n dispatch({ type: \"extendLeft\" });\n },\n extendRight: () => {\n dispatch({ type: \"extendRight\" });\n },\n reset: () => {\n dispatch({ type: \"reset\" });\n },\n }),\n []\n );\n\n useEffect(() => {\n const onClickOutOfTable = (e: MouseEvent) => {\n const element = document.getElementById(IdGenerator.getTableId());\n const ele = e.target;\n if (ele instanceof Node && element?.contains(ele)) return;\n dispatch({ type: \"reset\" });\n };\n\n document.addEventListener(\"mousedown\", onClickOutOfTable);\n\n return () => {\n document.removeEventListener(\"mousedown\", onClickOutOfTable);\n };\n }, []);\n\n const exState = useMemo<TReturnRangeReducer[\"state\"]>(() => {\n if (!state.isSelecting) {\n return state;\n }\n\n const startElement = document.getElementById(\n IdGenerator.getTableCellId(state.start.rowIndex, state.start.colIndex)\n );\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n const tableElement = document.getElementById(IdGenerator.getTableId());\n\n if (!startElement || !endElement || !tableElement) {\n dispatch({ type: \"reset\" });\n return { isSelecting: false };\n }\n\n const startRect = startElement.getBoundingClientRect();\n const endRect = endElement.getBoundingClientRect();\n const rectTable = tableElement.getBoundingClientRect();\n\n const adjustSize = {\n y: rectTable.top - tableElement.scrollTop - window.scrollY,\n x: rectTable.left - tableElement.scrollLeft - window.scrollX,\n };\n\n const startDivProps = {\n top: startRect.top - adjustSize.y,\n left: startRect.left - adjustSize.x,\n width: startRect.width,\n height: startRect.height,\n };\n\n const endDivProps = {\n top: endRect.top - adjustSize.y,\n left: endRect.left - adjustSize.x,\n width: endRect.width,\n height: endRect.height,\n };\n\n return {\n isSelecting: true,\n start: {\n ...state.start,\n xStart: startDivProps.left,\n xEnd: startDivProps.left + startDivProps.width,\n yStart: startDivProps.top,\n yEnd: startDivProps.top + startDivProps.height,\n },\n end: {\n ...state.end,\n xStart: endDivProps.left,\n xEnd: endDivProps.left + endDivProps.width,\n yStart: endDivProps.top,\n yEnd: endDivProps.top + endDivProps.height,\n },\n rangeBox: {\n top: Math.min(startDivProps.top, endDivProps.top),\n left: Math.min(startDivProps.left, endDivProps.left),\n width:\n Math.abs(startDivProps.left - endDivProps.left) +\n (startDivProps.left <= endDivProps.left\n ? endDivProps.width\n : startDivProps.width),\n height:\n Math.abs(startDivProps.top - endDivProps.top) +\n (startDivProps.top <= endDivProps.top\n ? endDivProps.height\n : startDivProps.height),\n },\n };\n }, [state]);\n\n return {\n state: exState,\n actions,\n };\n}\n"],"names":["newRangeConstraint","_a","maxColIndex","maxRowIndex","OutOfRangeError","concat","newIndex","rowIndex","colIndex","_b","constraint","equalIndex","a","b","MOVE_ACTION","UP","deltaRow","deltaCol","DOWN","LEFT","RIGHT","moveIndex","index","direction","newRow","newCol","e","rangeReducer","state","action","type","__assign","payload","startIndex","isSelecting","start","end","inProgress","endIndex","InvalidOperationError","useRangeReducer","useReducer","dispatch","actions","useMemo","setMax","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","useEffect","onClickOutOfTable","element","document","getElementById","IdGenerator","getTableId","ele","target","Node","contains","addEventListener","removeEventListener","startElement","getTableCellId","endElement","tableElement","startRect","getBoundingClientRect","endRect","rectTable","adjustSize","top","scrollTop","window","scrollY","left","scrollLeft","scrollX","startDivProps","width","height","endDivProps","xStart","xEnd","yStart","yEnd","rangeBox","Math","min","abs"],"mappings":"kQAUA,SAASA,EAAmBC,OAC1BC,EAAWD,EAAAC,YACXC,EAAWF,EAAAE,YAKX,GAAID,GAAe,EACjB,MAAM,IAAIE,EACR,MACA,mCACA,6BAA6BC,OAAAH,EAAwD,gDAIzF,GAAIC,GAAe,EACjB,MAAM,IAAIC,EACR,MACA,mCACA,6BAA6BC,OAAAF,EAAwD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Aa,EACbC,aACKP,EAAMO,OAAK,CACdwD,OAAQJ,EAAcH,KACtBQ,KAAML,EAAcH,KAAOG,EAAcC,MACzCK,OAAQN,EAAcP,IACtBc,KAAMP,EAAcP,IAAMO,EAAcE,SAE1CrD,WACKR,EAAMQ,KAAG,CACZuD,OAAQD,EAAYN,KACpBQ,KAAMF,EAAYN,KAAOM,EAAYF,MACrCK,OAAQH,EAAYV,IACpBc,KAAMJ,EAAYV,IAAMU,EAAYD,SAEtCM,SAAU,CACRf,IAAKgB,KAAKC,IAAIV,EAAcP,IAAKU,EAAYV,KAC7CI,KAAMY,KAAKC,IAAIV,EAAcH,KAAMM,EAAYN,MAC/CI,MACEQ,KAAKE,IAAIX,EAAcH,KAAOM,EAAYN,OACzCG,EAAcH,MAAQM,EAAYN,KAC/BM,EAAYF,MACZD,EAAcC,OACpBC,OACEO,KAAKE,IAAIX,EAAcP,IAAMU,EAAYV,MACxCO,EAAcP,KAAOU,EAAYV,IAC9BU,EAAYD,OACZF,EAAcE,SAG1B,GAAG,CAAC7D,IAIFe,QAAOA,EAEX"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as t,jsxs as n,Fragment as r}from"react/jsx-runtime";import{createContext as o,useContext as i,useEffect as d}from"react";import{NoImplementeFunction as s}from"../lib/errors.js";import{useRangeReducer as a}from"./hooks.js";import{useTablePropertyStateContext as l}from"../table-property/provider.js";import{IdGenerator as c}from"../libs/id-generator.js";var m=o({isSelecting:!1}),u=o({setMax:s,startSelectRange:s,moveSelectRange:s,endSelectRange:s,moveUp:s,moveDown:s,moveLeft:s,moveRight:s,extendUp:s,extendDown:s,extendLeft:s,extendRight:s,reset:s});function f(){return i(m)}function p(){return i(u)}function v(){return e(e({},f()),p())}function x(){var e=p().setMax,n=l(),o=n.maxDisplayRowCount,i=n.maxDisplayColCount;return d((function(){e({maxRowIndex:o-1,maxColIndex:i-1})}),[o,i]),t(r,{})}function h(e){var o=f();if(d((function(){if(o.isSelecting){var e=document.getElementById(c.getTableCellId(o.end.rowIndex,o.end.colIndex));e&&(e.scrollIntoView({behavior:"smooth",block:"nearest",inline:"nearest"}),e.focus())}}),[o]),!o.isSelecting)return t(r,{});var i=o.rangeBox,s=o.start,a=o.end,l=s.xEnd<a.xEnd?a.xEnd:s.xEnd,m=s.yEnd<a.yEnd?a.yEnd:s.yEnd;return n(r,{children:[t("div",{className:"absolute border border-gray-500 ".concat(e.isCopied?"border-dashed":"border-solid"),style:{top:i.top,left:i.left,width:i.width,height:i.height,pointerEvents:"none"}}),t("div",{className:"absolute bg-gray-700",style:{top:m-5,left:l-5,width:10,height:10,pointerEvents:"none"}})]})}function g(e){var r=e.children,o=a(),i=o.state,d=o.actions;return t(m.Provider,{value:i,children:n(u.Provider,{value:d,children:[t(x,{}),r]})})}export{g as RangeProvider,h as TestRange,p as useRangeActionContext,v as useRangeContext,f as useRangeStateContext};
|
|
2
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sources":["../../../../../src/table/range/provider.tsx"],"sourcesContent":["import { createContext, useContext, useEffect } from \"react\";\nimport { TRangeActionContext, TRangeStateContext } from \"./type\";\nimport { NoImplementeFunction } from \"../lib/errors\";\nimport { useRangeReducer } from \"./hooks\";\nimport { useTablePropertyStateContext } from \"../table-property/provider\";\nimport { IdGenerator } from \"../libs\";\n\nconst RangeStateContext = createContext<TRangeStateContext>({\n isSelecting: false,\n});\n\nconst RangeActionContext = createContext<TRangeActionContext>({\n setMax: NoImplementeFunction,\n startSelectRange: NoImplementeFunction,\n moveSelectRange: NoImplementeFunction,\n endSelectRange: NoImplementeFunction,\n moveUp: NoImplementeFunction,\n moveDown: NoImplementeFunction,\n moveLeft: NoImplementeFunction,\n moveRight: NoImplementeFunction,\n extendUp: NoImplementeFunction,\n extendDown: NoImplementeFunction,\n extendLeft: NoImplementeFunction,\n extendRight: NoImplementeFunction,\n reset: NoImplementeFunction,\n});\n\nexport function useRangeStateContext() {\n return useContext(RangeStateContext);\n}\n\nexport function useRangeActionContext() {\n return useContext(RangeActionContext);\n}\n\nexport function useRangeContext() {\n return { ...useRangeStateContext(), ...useRangeActionContext() };\n}\n\nfunction EffectSetMax() {\n const { setMax } = useRangeActionContext();\n const { maxDisplayRowCount, maxDisplayColCount } =\n useTablePropertyStateContext();\n\n useEffect(() => {\n setMax({\n maxRowIndex: maxDisplayRowCount - 1,\n maxColIndex: maxDisplayColCount - 1,\n });\n }, [maxDisplayRowCount, maxDisplayColCount]);\n\n return <></>;\n}\n\nexport function TestRange(props: { isCopied?: boolean }) {\n const state = useRangeStateContext();\n\n useEffect(() => {\n if (state.isSelecting) {\n const endElement = document.getElementById(\n IdGenerator.getTableCellId(state.end.rowIndex, state.end.colIndex)\n );\n\n if (endElement) {\n endElement.scrollIntoView({\n behavior: \"smooth\",\n block: \"nearest\",\n inline: \"nearest\",\n });\n endElement.focus();\n }\n }\n }, [state]);\n\n if (!state.isSelecting) {\n return <></>;\n }\n\n const { rangeBox, start, end } = state;\n\n const clickboxPoint = {\n x: start.xEnd < end.xEnd ? end.xEnd : start.xEnd,\n y: start.yEnd < end.yEnd ? end.yEnd : start.yEnd,\n };\n\n return (\n <>\n <div\n className={`absolute border border-gray-500 ${\n props.isCopied ? \"border-dashed\" : \"border-solid\"\n }`}\n style={{\n top: rangeBox.top,\n left: rangeBox.left,\n width: rangeBox.width,\n height: rangeBox.height,\n pointerEvents: \"none\",\n }}\n ></div>\n <div\n className=\"absolute bg-gray-700\"\n style={{\n top: clickboxPoint.y - 5,\n left: clickboxPoint.x - 5,\n width: 10,\n height: 10,\n pointerEvents: \"none\",\n }}\n />\n </>\n );\n}\n\nexport function RangeProvider({\n children,\n}: {\n children: JSX.Element | JSX.Element[];\n}) {\n const { state, actions } = useRangeReducer();\n\n return (\n <RangeStateContext.Provider value={state}>\n <RangeActionContext.Provider value={actions}>\n <EffectSetMax />\n {children}\n </RangeActionContext.Provider>\n </RangeStateContext.Provider>\n );\n}\n"],"names":["RangeStateContext","createContext","isSelecting","RangeActionContext","setMax","NoImplementeFunction","startSelectRange","moveSelectRange","endSelectRange","moveUp","moveDown","moveLeft","moveRight","extendUp","extendDown","extendLeft","extendRight","reset","useRangeStateContext","useContext","useRangeActionContext","useRangeContext","__assign","EffectSetMax","_a","useTablePropertyStateContext","maxDisplayRowCount","maxDisplayColCount","useEffect","maxRowIndex","maxColIndex","_jsx","TestRange","props","state","endElement","document","getElementById","IdGenerator","getTableCellId","end","rowIndex","colIndex","scrollIntoView","behavior","block","inline","focus","rangeBox","start","clickboxPoint","xEnd","yEnd","_jsxs","className","concat","isCopied","style","top","left","width","height","pointerEvents","RangeProvider","children","_b","useRangeReducer","actions","Provider","value"],"mappings":"ibAOA,IAAMA,EAAoBC,EAAkC,CAC1DC,aAAa,IAGTC,EAAqBF,EAAmC,CAC5DG,OAAQC,EACRC,iBAAkBD,EAClBE,gBAAiBF,EACjBG,eAAgBH,EAChBI,OAAQJ,EACRK,SAAUL,EACVM,SAAUN,EACVO,UAAWP,EACXQ,SAAUR,EACVS,WAAYT,EACZU,WAAYV,EACZW,YAAaX,EACbY,MAAOZ,aAGOa,IACd,OAAOC,EAAWnB,EACpB,UAEgBoB,IACd,OAAOD,EAAWhB,EACpB,UAEgBkB,IACd,OAAAC,EAAAA,EAAA,CAAA,EAAYJ,KAA2BE,IACzC,CAEA,SAASG,IACC,IAAAnB,EAAWgB,WACbI,EACJC,IADMC,EAAkBF,EAAAE,mBAAEC,EAAkBH,EAAAG,mBAU9C,OAPAC,GAAU,WACRxB,EAAO,CACLyB,YAAaH,EAAqB,EAClCI,YAAaH,EAAqB,GAEtC,GAAG,CAACD,EAAoBC,IAEjBI,OACT,CAEM,SAAUC,EAAUC,GACxB,IAAMC,EAAQhB,IAmBd,GAjBAU,GAAU,WACR,GAAIM,EAAMhC,YAAa,CACrB,IAAMiC,EAAaC,SAASC,eAC1BC,EAAYC,eAAeL,EAAMM,IAAIC,SAAUP,EAAMM,IAAIE,WAGvDP,IACFA,EAAWQ,eAAe,CACxBC,SAAU,SACVC,MAAO,UACPC,OAAQ,YAEVX,EAAWY,QAEd,CACH,GAAG,CAACb,KAECA,EAAMhC,YACT,OAAO6B,QAGD,IAAAiB,EAAyBd,EAAKc,SAApBC,EAAef,EAAKe,MAAbT,EAAQN,MAE3BgB,EACDD,EAAME,KAAOX,EAAIW,KAAOX,EAAIW,KAAOF,EAAME,KADxCD,EAEDD,EAAMG,KAAOZ,EAAIY,KAAOZ,EAAIY,KAAOH,EAAMG,KAG9C,OACEC,eACEtB,EACE,MAAA,CAAAuB,UAAW,mCACTC,OAAAtB,EAAMuB,SAAW,gBAAkB,gBAErCC,MAAO,CACLC,IAAKV,EAASU,IACdC,KAAMX,EAASW,KACfC,MAAOZ,EAASY,MAChBC,OAAQb,EAASa,OACjBC,cAAe,UAGnB/B,EACE,MAAA,CAAAuB,UAAU,uBACVG,MAAO,CACLC,IAAKR,EAAkB,EACvBS,KAAMT,EAAkB,EACxBU,MAAO,GACPC,OAAQ,GACRC,cAAe,YAKzB,CAEM,SAAUC,EAAcvC,GAC5B,IAAAwC,EAAQxC,EAAAwC,SAIFC,EAAqBC,IAAnBhC,EAAK+B,EAAA/B,MAAEiC,EAAOF,EAAAE,QAEtB,OACEpC,EAAC/B,EAAkBoE,SAAS,CAAAC,MAAOnC,EACjC8B,SAAAX,EAAClD,EAAmBiE,SAAQ,CAACC,MAAOF,EAAOH,SAAA,CACzCjC,EAACR,EAAe,CAAA,GACfyC,MAIT"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as r,jsx as
|
|
1
|
+
import{jsxs as r,jsx as t}from"react/jsx-runtime";import{memo as e}from"react";import{Checkbox as o}from"../checkbox/components.js";import{TableCell as i}from"../cell/ui/cell.js";import{IdGenerator as a}from"../libs/id-generator.js";import{useRangeActionContext as n}from"../range/provider.js";var l=e((function(e){var l=n().reset,c=JSON.parse(e.dataString),s=e.conditionalFormattingString.split(",");return r("tr",{className:"relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ".concat(e.onClickRow?"hover:cursor-pointer":""," ").concat(e.applyRowFormatting?e.applyRowFormatting(c):""),onClick:function(r){r.preventDefault(),e.onClickRow&&(e.onClickRow(c),l())},"data-testid":c.id,children:[e.existCheckbox&&t("td",{children:t(o,{row:c})}),e.cols.map((function(r,o){var n;return t(i,{id:a.getTableCellId(e.rowIndex,o),row:c,isExistOnClickRow:!!e.onClickRow,cellFormatClassName:s[o],editable:null!==(n=r.editable)&&void 0!==n&&n},r.key)}))]})}));export{l as Row};
|
|
2
2
|
//# sourceMappingURL=components.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"components.js","sources":["../../../../../src/table/sheet/components.tsx"],"sourcesContent":["import { memo } from \"react\";\nimport {
|
|
1
|
+
{"version":3,"file":"components.js","sources":["../../../../../src/table/sheet/components.tsx"],"sourcesContent":["import { memo } from \"react\";\nimport { DataRecord, TTableColumn } from \"../table/type\";\nimport { Checkbox } from \"../checkbox/components\";\nimport { TableCell } from \"../cell/ui/cell\";\nimport { IdGenerator } from \"../libs\";\nimport { useRangeActionContext } from \"../range/provider\";\n\ninterface TPropsRow<T extends DataRecord> {\n dataString: string;\n cols: TTableColumn<T>[];\n existCheckbox?: boolean;\n rowIndex: number;\n conditionalFormattingString: string;\n onClickRow?: (row: any) => void;\n applyRowFormatting?: (row: any) => string;\n}\n\nexport const Row = memo(function R<T extends DataRecord>(props: TPropsRow<T>) {\n const { reset } = useRangeActionContext();\n const row = JSON.parse(props.dataString);\n const conditionalFormatting = props.conditionalFormattingString.split(\",\");\n\n return (\n <tr\n className={`relative border border-gray-200 after:absolute after:w-full after:h-full after:top-0 after:left-0 after:pointer-events-none after:hover:bg-gray-500/10 ${\n !!props.onClickRow ? \"hover:cursor-pointer\" : \"\"\n } ${props.applyRowFormatting ? props.applyRowFormatting(row) : \"\"}`}\n onClick={(e) => {\n e.preventDefault();\n\n if (!!props.onClickRow) {\n props.onClickRow(row);\n reset();\n }\n }}\n data-testid={row.id}\n >\n {props.existCheckbox && (\n <td>\n <Checkbox row={row} />\n </td>\n )}\n {props.cols.map((col, j) => {\n return (\n <TableCell\n key={col.key as string}\n id={IdGenerator.getTableCellId(props.rowIndex, j)}\n row={row}\n isExistOnClickRow={!!props.onClickRow}\n cellFormatClassName={conditionalFormatting[j]}\n editable={col.editable ?? false}\n />\n );\n })}\n </tr>\n );\n});\n"],"names":["Row","memo","props","reset","useRangeActionContext","row","JSON","parse","dataString","conditionalFormatting","conditionalFormattingString","split","_jsxs","className","concat","onClickRow","applyRowFormatting","onClick","e","preventDefault","id","children","existCheckbox","_jsx","Checkbox","cols","map","col","j","TableCell","IdGenerator","getTableCellId","rowIndex","isExistOnClickRow","cellFormatClassName","editable","_a","key"],"mappings":"0SAiBaA,EAAMC,GAAK,SAAiCC,GAC/C,IAAAC,EAAUC,UACZC,EAAMC,KAAKC,MAAML,EAAMM,YACvBC,EAAwBP,EAAMQ,4BAA4BC,MAAM,KAEtE,OACEC,EACE,KAAA,CAAAC,UAAW,0JACTC,OAAEZ,EAAMa,WAAa,uBAAyB,GAC5C,KAAAD,OAAAZ,EAAMc,mBAAqBd,EAAMc,mBAAmBX,GAAO,IAC/DY,QAAS,SAACC,GACRA,EAAEC,iBAEIjB,EAAMa,aACVb,EAAMa,WAAWV,GACjBF,IAEH,EACY,cAAAE,EAAIe,GAEhBC,SAAA,CAAAnB,EAAMoB,eACLC,EACE,KAAA,CAAAF,SAAAE,EAACC,EAAS,CAAAnB,IAAKA,MAGlBH,EAAMuB,KAAKC,KAAI,SAACC,EAAKC,SACpB,OACEL,EAACM,EAAS,CAERT,GAAIU,EAAYC,eAAe7B,EAAM8B,SAAUJ,GAC/CvB,IAAKA,EACL4B,oBAAqB/B,EAAMa,WAC3BmB,oBAAqBzB,EAAsBmB,GAC3CO,SAAsB,UAAZR,EAAIQ,gBAAQ,IAAAC,GAAAA,GALjBT,EAAIU,UAWrB"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import{__assign as o}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useTable as
|
|
2
|
+
import{__assign as o}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as r,jsxs as e}from"react/jsx-runtime";import{useTable as i}from"./hook.js";import{TableHeaderElement as t}from"../header/header.js";import{PagenationProvider as n}from"../pagenation/providers.js";import{DisplayRange as l,Pagenation as s}from"../pagenation/components.js";import{FilterProvider as d}from"../filter/provider.js";import{TableFilterRemoveButton as a,TableFilterForm as c}from"../filter/components.js";import"../sort/icon.js";import{SortProvider as m}from"../sort/provider.js";import{ColumnsProvider as p}from"../sheet/providers.js";import{CheckboxProvider as h,CheckboxStatusProvider as f}from"../checkbox/provider.js";import{AllCheckbox as g}from"../checkbox/components.js";import{IdGenerator as u}from"../libs/id-generator.js";import{EditProvider as v}from"../edit/provider.js";import{TablePropertyProvider as b}from"../table-property/provider.js";import{KeyboardSetting as w}from"../operation/components/keyboard-setting.js";import{Row as j}from"../sheet/components.js";import{PasteProvider as x}from"../paste/provider.js";import{generateFormattingString as k}from"../libs/conditional-formatting.js";import{Editor as y}from"../edit/ui/editor.js";import{useFilteringColumnStateContext as C}from"../filter/hooks/selectedFilteringColumn/provider.js";import{RangeProvider as N,useRangeActionContext as R,TestRange as F}from"../range/provider.js";import{CopyProvider as I}from"../copy/provider.js";function P(i){var t,l,s;return r(d,{children:r(m,{initialCondition:null===(t=i.initialCondition)||void 0===t?void 0:t.sort,children:r(n,{rowCount:i.rows.length,perPage:null===(s=null===(l=i.initialCondition)||void 0===l?void 0:l.pagenation)||void 0===s?void 0:s.rowCountPerPage,children:r(h,{checkbox:i.checkbox,children:r(f,{checkboxCount:i.rows.length,children:r(p,{cols:i.cols,errorHandler:i.errorHandler,children:r(v,{children:r(b,{children:r(N,{children:r(I,{rows:i.rows,cols:i.cols,children:e(x,{rows:i.rows,cols:i.cols,onUpdateRowFunction:i.onUpdateRow,children:[r(w,{}),r(S,o({},i))]})})})})})})})})})})})}function S(o){var n=i(o),d=n.cols,m=n.rowMaps,p=n.pageRowIds,h=C(),f=R().reset;return e("div",{className:"w-full",children:[r("div",{className:"flex justify-end mb-1 mr-3",children:r(a,{children:r("p",{className:"text-xs underline text-gray-500 hover:text-gray-700",children:"全てのフィルタリング条件を解除する"})})}),e("div",{id:u.getTableId(),className:"relative h-full max-w-full max-h-[80vh] border border-gray-200 rounded-md overflow-auto",children:[r(F,{}),r(y,{rowMaps:m,pageRowIds:p}),e("table",{className:"table",children:[r("thead",{children:e("tr",{className:"sticky top-0 border-gray-200 z-20 bg-gray-200 text-gray-600 h-[32px]",onClick:function(o){o.stopPropagation(),f()},children:[o.checkbox&&r("th",{children:r(g,{rows:o.rows})}),d.map((function(o,e){return r(t,{id:u.getTableColId(e),col:o},o.key.toString())}))]})}),e("tbody",{children:[!!h&&r("tr",{onClick:function(o){o.stopPropagation(),f()},children:r("td",{colSpan:d.length,className:"sticky top-8 left-0 bg-gray-300 w-full shadow-lg rounded-b-2xl z-20 p-0 overflow-hidden",children:r(c,{})})}),0===p.length&&r("tr",{children:r("td",{colSpan:d.length,className:"py-5",children:r("p",{className:"text-center font-bold text-lg",children:"NO DATA"})})}),p.map((function(e,i){return r(j,{existCheckbox:!!o.checkbox,rowIndex:i,dataString:m[e].stringValue,cols:o.cols,onClickRow:o.onClickRow,applyRowFormatting:o.applyRowFormatting,conditionalFormattingString:k(m[e].data,d,o.conditionalFormattings)},e)}))]})]})]}),e("div",{className:"mt-1",children:[r(l,{}),r("div",{className:"mt-2",children:r(s,{})})]})]})}export{P as default};
|
|
3
3
|
//# sourceMappingURL=base.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{useMemo as r,useEffect as t}from"react";import{usePageContext as o}from"../pagenation/providers.js";import"react/jsx-runtime";import{useFilterContext as e}from"../filter/provider.js";import"../filter/constants.js";import"../sheet/providers.js";import"../filter/hooks/selectedFilteringColumn/provider.js";import{useCheckboxStatusContext as n}from"../checkbox/provider.js";import{useSortActionContext as i,useSortTimingContext as s}from"../sort/provider.js";import{useTablePropertyActionContext as c}from"../table-property/provider.js";import{usePasteActionContext as u}from"../paste/provider.js";function a(a){var
|
|
1
|
+
import{useMemo as r,useEffect as t}from"react";import{usePageContext as o}from"../pagenation/providers.js";import"react/jsx-runtime";import{useFilterContext as e}from"../filter/provider.js";import"../filter/constants.js";import"../sheet/providers.js";import"../filter/hooks/selectedFilteringColumn/provider.js";import{useCheckboxStatusContext as n}from"../checkbox/provider.js";import{useSortActionContext as i,useSortTimingContext as s}from"../sort/provider.js";import{useTablePropertyActionContext as c}from"../table-property/provider.js";import{usePasteActionContext as u}from"../paste/provider.js";import{useCopyActionContext as p}from"../copy/provider.js";function a(a){var f=e().filter,l=i(),d=l.sort,m=l.updatedData,h=s(),v=o(),w=v.setRowCount,g=v.pageFilter,j=n().dispatchCheckboxStatus,k=u().setRows,x=p().setRows,y=c(),b=y.setMaxDisplayColCount,C=y.setMaxDisplayRowCount,R=r((function(){return f(a.rows)}),[f,h,a.rows.length]);t((function(){w(R.length)}),[R.length]);var S=r((function(){return a.checkbox?a.rows.filter((function(r){var t;return null===(t=a.checkbox)||void 0===t?void 0:t.checked(r)})):[]}),[a.checkbox,a.rows]);t((function(){j({type:"SET",payload:{checkedRecords:S}})}),[S]);var D=r((function(){return d(R)}),[R,h]);t((function(){m()}),[a.rows]);var M=r((function(){return g(D)}),[g,D]),F=r((function(){return M.map((function(r){return r.id}))}),[M]),O=r((function(){return new Set(F)}),[F]),E=r((function(){return a.rows.filter((function(r){return O.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}),{})}),[a.rows,O]);return t((function(){b(a.cols.length)}),[a.cols.length]),t((function(){C(F.length)}),[F.length]),t((function(){var r=F.map((function(r){return E[r].data}));x(r),k(r)}),[E]),{cols:a.cols,rowMaps:E,pageRowIds:F}}export{a as useTable};
|
|
2
2
|
//# sourceMappingURL=hook.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","sources":["../../../../../src/table/table/hook.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { DataObject, DataRecord, TPropsTable } from \"./type\";\nimport { usePageContext } from \"../pagenation/providers\";\nimport { useFilterContext } from \"../filter\";\nimport { useCheckboxStatusContext } from \"../checkbox/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
|
|
1
|
+
{"version":3,"file":"hook.js","sources":["../../../../../src/table/table/hook.ts"],"sourcesContent":["import { useEffect, useMemo } from \"react\";\nimport { DataObject, DataRecord, TPropsTable } from \"./type\";\nimport { usePageContext } from \"../pagenation/providers\";\nimport { useFilterContext } from \"../filter\";\nimport { useCheckboxStatusContext } from \"../checkbox/provider\";\nimport { useSortActionContext, useSortTimingContext } from \"../sort/provider\";\nimport { useTablePropertyActionContext } from \"../table-property/provider\";\nimport { usePasteActionContext } from \"../paste/provider\";\nimport { useCopyActionContext } from \"../copy/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: setRowsForPaste } = usePasteActionContext();\n const { setRows: setRowsForCopy } = useCopyActionContext();\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 const rows = pageRowIds.map((id) => rowMaps[id].data);\n setRowsForCopy(rows);\n setRowsForPaste(rows);\n }, [rowMaps]);\n\n return {\n cols: props.cols,\n rowMaps,\n pageRowIds,\n };\n}\n"],"names":["useTable","props","filter","useFilterContext","_a","useSortActionContext","sort","updatedData","sortTiming","useSortTimingContext","_b","usePageContext","setRowCount","pageFilter","dispatchCheckboxStatus","useCheckboxStatusContext","setRowsForPaste","usePasteActionContext","setRowsForCopy","useCopyActionContext","_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":"qpBAUM,SAAUA,EAA+BC,GACrC,IAAAC,EAAWC,WACbC,EAAwBC,IAAtBC,EAAIF,EAAAE,KAAEC,EAAWH,EAAAG,YACnBC,EAAaC,IACbC,EAA8BC,IAA5BC,EAAWF,EAAAE,YAAEC,EAAUH,EAAAG,WACvBC,EAA2BC,2BAClBC,EAAoBC,YACpBC,EAAmBC,YAC9BC,EACJC,IADMC,EAAqBF,EAAAE,sBAAEC,EAAqBH,EAAAG,sBAG9CC,EAAeC,GACnB,WAAM,OAAAvB,EAAOD,EAAMyB,KAAK,GACxB,CAACxB,EAAQM,EAAYP,EAAMyB,KAAKC,SAGlCC,GAAU,WACRhB,EAAYY,EAAaG,OAC3B,GAAG,CAACH,EAAaG,SAEjB,IAAME,EAAaJ,GAAQ,WACzB,OAAKxB,EAAM6B,SAIJ7B,EAAMyB,KAAKxB,QAAO,SAAC6B,GAAG,IAAA3B,EAAK,eAAAA,EAAAH,EAAM6B,+BAAUE,QAAQD,EAAI,IAHrD,EAIV,GAAE,CAAC9B,EAAM6B,SAAU7B,EAAMyB,OAE1BE,GAAU,WACRd,EAAuB,CACrBmB,KAAM,MACNC,QAAS,CAAEC,eAAgBN,IAE/B,GAAG,CAACA,IAEJ,IAAMO,EAAaX,GACjB,WAAM,OAAAnB,EAAKkB,KACX,CAACA,EAAchB,IAGjBoB,GAAU,WACRrB,GACF,GAAG,CAACN,EAAMyB,OAEV,IAAMW,EAAWZ,GACf,WAAM,OAAAZ,EAAWuB,KACjB,CAACvB,EAAYuB,IAGTE,EAAab,GAAQ,WAAM,OAAAY,EAASE,KAAI,SAACR,GAAQ,OAAAA,EAAIS,EAAE,GAAC,GAAE,CAACH,IAC3DI,EAAgBhB,GAAQ,WAAM,OAAA,IAAIiB,IAAIJ,EAAW,GAAE,CAACA,IAEpDK,EAAUlB,GACd,WACE,OAAAxB,EAAMyB,KACHxB,QAAO,SAAC6B,GAAQ,OAAAU,EAAcG,IAAIb,EAAIS,OACtCK,QAAO,SAACC,EAAKf,GACZ,IAAMgB,EAAiBC,OAAOC,KAAKlB,GAChCzB,OACAuC,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,CAAC7C,EAAMyB,KAAMe,IAiBf,OAdAb,GAAU,WACRN,EAAsBrB,EAAMsD,KAAK5B,OAClC,GAAE,CAAC1B,EAAMsD,KAAK5B,SAEfC,GAAU,WACRL,EAAsBe,EAAWX,OACnC,GAAG,CAACW,EAAWX,SAEfC,GAAU,WACR,IAAMF,EAAOY,EAAWC,KAAI,SAACC,GAAO,OAAAG,EAAQH,GAAIW,IAAI,IACpDjC,EAAeQ,GACfV,EAAgBU,EAClB,GAAG,CAACiB,IAEG,CACLY,KAAMtD,EAAMsD,KACZZ,QAAOA,EACPL,WAAUA,EAEd"}
|
package/package.json
CHANGED
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),o=require("react"),n=require("../libs/id-generator.js"),t=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(t,{isFocus:!1}),s=e[0],u=e[1],c=o.useMemo((function(){return{focus:function(e,o){u({type:"focus",payload:{rowIndex:e,colIndex:o}})},unfocus:function(){u({type:"unfocus"})},move:function(e,o){u({type:"move",payload:{rowIndex:e,colIndex:o}})},moveLeft:function(){u({type:"moveLeft"})},moveRight:function(){u({type:"moveRight"})},moveUp:function(){u({type:"moveUp"})},moveDown:function(){u({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))||c.unfocus()};return document.addEventListener("click",e),function(){document.removeEventListener("click",e)}}),[]),o.useEffect((function(){if(s.isFocus){var e=document.getElementById(n.IdGenerator.getTableCellId(s.rowIndex,s.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(s.isFocus){var e=document.getElementById(n.IdGenerator.getTableCellId(s.rowIndex,s.colIndex));null==e||e.style.setProperty("outline-style","none")}}}),[s]),{state:s,actions:c}};
|
|
2
|
-
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/focus/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, 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 actions = useMemo(\n () => ({\n focus: (rowIndex: number, colIndex: number) => {\n dispatch({ type: \"focus\", payload: { rowIndex, colIndex } });\n },\n unfocus: () => {\n dispatch({ type: \"unfocus\" });\n },\n move: (rowIndex: number, colIndex: number) => {\n dispatch({ type: \"move\", payload: { rowIndex, colIndex } });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n }),\n []\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 actions.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 return {\n state,\n actions,\n };\n}\n"],"names":["reducer","state","action","type","isFocus","rowIndex","payload","colIndex","__assign","_a","useReducer","dispatch","actions","useMemo","focus","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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e,CACtBC,SAAU,SACVC,MAAO,UACPC,OAAQ,YAEVhB,SAAAA,EAASV,OACV,CAED,OAAO,WACL,GAAIb,EAAMG,QAAS,CACjB,IAAMoB,EAAUC,SAASC,eACvBO,cAAYC,eAAejC,EAAMI,SAAUJ,EAAMM,WAEnDiB,SAAAA,EAASW,MAAMC,YAAY,gBAAiB,OAC7C,CACH,CACF,GAAG,CAACnC,IAEG,CACLA,MAAKA,EACLW,QAAOA,EAEX"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
"use strict";var e=require("../../../node_modules/tslib/tslib.es6.js"),t=require("react/jsx-runtime"),o=require("react"),n=require("./hooks.js"),u=o.createContext({isFocus:!1}),r=o.createContext({focus:function(){},unfocus:function(){},move:function(){},moveLeft:function(){},moveRight:function(){},moveUp:function(){},moveDown:function(){}});function s(){return o.useContext(u)}function i(){return o.useContext(r)}exports.FocusProvider=function(e){var o=n.useFocusReducer(),s=o.state,i=o.actions;return t.jsx(u.Provider,{value:s,children:t.jsx(r.Provider,{value:i,children:e.children})})},exports.useFocusActionContext=i,exports.useFocusContext=function(){return e.__assign(e.__assign({},s()),i())},exports.useFocusStateContext=s;
|
|
2
|
-
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/focus/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { TFocusActionContext, TFocusStateContext } from \"./types\";\nimport { useFocusReducer } from \"./hooks\";\n\nconst FocusStateContext = createContext<TFocusStateContext>({\n isFocus: false,\n});\n\nconst FocusActionContext = createContext<TFocusActionContext>({\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 { state, actions } = useFocusReducer();\n\n return (\n <FocusStateContext.Provider value={state}>\n <FocusActionContext.Provider value={actions}>\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","_a","useFocusReducer","state","actions","_jsx","Provider","value","children","__assign"],"mappings":"iJAIMA,EAAoBC,EAAAA,cAAkC,CAC1DC,SAAS,IAGLC,EAAqBF,EAAAA,cAAmC,CAC5DG,MAAO,WAAQ,EACfC,QAAS,WAAQ,EACjBC,KAAM,WAAQ,EACdC,SAAU,WAAQ,EAClBC,UAAW,WAAQ,EACnBC,OAAQ,WAAQ,EAChBC,SAAU,WAAQ,aAeJC,IACd,OAAOC,EAAAA,WAAWZ,EACpB,UAEgBa,IACd,OAAOD,EAAAA,WAAWT,EACpB,uBAlBM,SAAwBW,GACtB,IAAAC,EAAqBC,EAAeA,kBAAlCC,EAAKF,EAAAE,MAAEC,EAAOH,EAAAG,QAEtB,OACEC,EAAAA,IAACnB,EAAkBoB,UAASC,MAAOJ,EAAKK,SACtCH,MAAChB,EAAmBiB,SAAQ,CAACC,MAAOH,EAAOI,SACxCR,EAAMQ,YAIf,qEAWE,OAAAC,EAAAA,SAAAA,EAAAA,SAAA,CAAA,EAAYZ,KAA2BE,IACzC"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{__assign as e}from"../../../node_modules/tslib/tslib.es6.js";import{useReducer as o,useMemo as n,useEffect as t}from"react";import{IdGenerator as c}from"../libs/id-generator.js";var 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(e({},o),{colIndex:o.colIndex-1}):o;case"moveRight":return o.isFocus?e(e({},o),{colIndex:o.colIndex+1}):o;case"moveUp":return o.isFocus?e(e({},o),{rowIndex:o.rowIndex-1}):o;case"moveDown":return o.isFocus?e(e({},o),{rowIndex:o.rowIndex+1}):o}};function r(){var e=o(s,{isFocus:!1}),r=e[0],u=e[1],l=n((function(){return{focus:function(e,o){u({type:"focus",payload:{rowIndex:e,colIndex:o}})},unfocus:function(){u({type:"unfocus"})},move:function(e,o){u({type:"move",payload:{rowIndex:e,colIndex:o}})},moveLeft:function(){u({type:"moveLeft"})},moveRight:function(){u({type:"moveRight"})},moveUp:function(){u({type:"moveUp"})},moveDown:function(){u({type:"moveDown"})}}}),[]);return t((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.unfocus()};return document.addEventListener("click",e),function(){document.removeEventListener("click",e)}}),[]),t((function(){if(r.isFocus){var e=document.getElementById(c.getTableCellId(r.rowIndex,r.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(r.isFocus){var e=document.getElementById(c.getTableCellId(r.rowIndex,r.colIndex));null==e||e.style.setProperty("outline-style","none")}}}),[r]),{state:r,actions:l}}export{r as useFocusReducer};
|
|
2
|
-
//# sourceMappingURL=hooks.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.js","sources":["../../../../../src/table/focus/hooks.ts"],"sourcesContent":["import { useEffect, useMemo, 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 actions = useMemo(\n () => ({\n focus: (rowIndex: number, colIndex: number) => {\n dispatch({ type: \"focus\", payload: { rowIndex, colIndex } });\n },\n unfocus: () => {\n dispatch({ type: \"unfocus\" });\n },\n move: (rowIndex: number, colIndex: number) => {\n dispatch({ type: \"move\", payload: { rowIndex, colIndex } });\n },\n moveLeft: () => {\n dispatch({ type: \"moveLeft\" });\n },\n moveRight: () => {\n dispatch({ type: \"moveRight\" });\n },\n moveUp: () => {\n dispatch({ type: \"moveUp\" });\n },\n moveDown: () => {\n dispatch({ type: \"moveDown\" });\n },\n }),\n []\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 actions.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 return {\n state,\n actions,\n };\n}\n"],"names":["reducer","state","action","type","isFocus","rowIndex","payload","colIndex","__assign","useFocusReducer","_a","useReducer","dispatch","actions","useMemo","focus","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":"yLAIA,IAAMA,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,EAAAA,EAAA,CAAA,EAAAP,IACHM,SAAUN,EAAMM,SAAW,IALpBN,EAOX,IAAK,YACH,OAAKA,EAAMG,QAKNI,EAAAA,EAAA,CAAA,EAAAP,IACHM,SAAUN,EAAMM,SAAW,IALpBN,EAOX,IAAK,SACH,OAA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,YAAY,gBAAiB,WAE5CZ,SAAAA,EAASa,eAAe,CACtBC,SAAU,SACVC,MAAO,UACPC,OAAQ,YAEVhB,SAAAA,EAASV,OACV,CAED,OAAO,WACL,GAAId,EAAMG,QAAS,CACjB,IAAMqB,EAAUC,SAASC,eACvBO,EAAYC,eAAelC,EAAMI,SAAUJ,EAAMM,WAEnDkB,SAAAA,EAASW,MAAMC,YAAY,gBAAiB,OAC7C,CACH,CACF,GAAG,CAACpC,IAEG,CACLA,MAAKA,EACLY,QAAOA,EAEX"}
|
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{__assign as o}from"../../../node_modules/tslib/tslib.es6.js";import{jsx as n}from"react/jsx-runtime";import{createContext as t,useContext as r}from"react";import{useFocusReducer as i}from"./hooks.js";var e=t({isFocus:!1}),u=t({focus:function(){},unfocus:function(){},move:function(){},moveLeft:function(){},moveRight:function(){},moveUp:function(){},moveDown:function(){}});function c(o){var t=i(),r=t.state,c=t.actions;return n(e.Provider,{value:r,children:n(u.Provider,{value:c,children:o.children})})}function f(){return r(e)}function m(){return r(u)}function s(){return o(o({},f()),m())}export{c as FocusProvider,m as useFocusActionContext,s as useFocusContext,f as useFocusStateContext};
|
|
2
|
-
//# sourceMappingURL=provider.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../../../../../src/table/focus/provider.tsx"],"sourcesContent":["import { createContext, useContext } from \"react\";\nimport { TFocusActionContext, TFocusStateContext } from \"./types\";\nimport { useFocusReducer } from \"./hooks\";\n\nconst FocusStateContext = createContext<TFocusStateContext>({\n isFocus: false,\n});\n\nconst FocusActionContext = createContext<TFocusActionContext>({\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 { state, actions } = useFocusReducer();\n\n return (\n <FocusStateContext.Provider value={state}>\n <FocusActionContext.Provider value={actions}>\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","FocusProvider","props","_a","useFocusReducer","state","actions","_jsx","Provider","value","children","useFocusStateContext","useContext","useFocusActionContext","useFocusContext","__assign"],"mappings":"+MAIA,IAAMA,EAAoBC,EAAkC,CAC1DC,SAAS,IAGLC,EAAqBF,EAAmC,CAC5DG,MAAO,WAAQ,EACfC,QAAS,WAAQ,EACjBC,KAAM,WAAQ,EACdC,SAAU,WAAQ,EAClBC,UAAW,WAAQ,EACnBC,OAAQ,WAAQ,EAChBC,SAAU,WAAQ,IAGd,SAAUC,EAAcC,GACtB,IAAAC,EAAqBC,IAAnBC,EAAKF,EAAAE,MAAEC,EAAOH,EAAAG,QAEtB,OACEC,EAACjB,EAAkBkB,UAASC,MAAOJ,EAAKK,SACtCH,EAACd,EAAmBe,SAAQ,CAACC,MAAOH,EAAOI,SACxCR,EAAMQ,YAIf,UAEgBC,IACd,OAAOC,EAAWtB,EACpB,UAEgBuB,IACd,OAAOD,EAAWnB,EACpB,UAEgBqB,IACd,OAAAC,EAAAA,EAAA,CAAA,EAAYJ,KAA2BE,IACzC"}
|