From ff48c77827ef205697d0114c46860996af335c65 Mon Sep 17 00:00:00 2001 From: samunohito <46447427+samunohito@users.noreply.github.com> Date: Fri, 2 Feb 2024 09:32:49 +0900 Subject: [PATCH] refactor grid --- .../src/components/grid/MkDataCell.vue | 6 +- .../src/components/grid/MkDataRow.vue | 3 +- .../frontend/src/components/grid/MkGrid.vue | 294 +++++++++++------- .../src/components/grid/MkHeaderCell.vue | 3 +- .../src/components/grid/MkHeaderRow.vue | 3 +- .../src/components/grid/MkNumberCell.vue | 3 +- .../src/components/grid/cell-validators.ts | 4 +- packages/frontend/src/components/grid/cell.ts | 35 ++- .../frontend/src/components/grid/column.ts | 31 ++ .../src/components/grid/grid-event.ts | 5 +- packages/frontend/src/components/grid/grid.ts | 35 +-- packages/frontend/src/components/grid/row.ts | 11 + .../pages/admin/custom-emojis-grid.list.vue | 2 +- .../admin/custom-emojis-grid.register.vue | 3 +- 14 files changed, 284 insertions(+), 154 deletions(-) create mode 100644 packages/frontend/src/components/grid/column.ts create mode 100644 packages/frontend/src/components/grid/row.ts diff --git a/packages/frontend/src/components/grid/MkDataCell.vue b/packages/frontend/src/components/grid/MkDataCell.vue index 8a2ca2b508..0a7ac4e314 100644 --- a/packages/frontend/src/components/grid/MkDataCell.vue +++ b/packages/frontend/src/components/grid/MkDataCell.vue @@ -56,10 +56,12 @@ import { useTooltip } from '@/scripts/use-tooltip.js'; import * as os from '@/os.js'; import { CellValue, GridCell } from '@/components/grid/cell.js'; import { equalCellAddress, getCellAddress } from '@/components/grid/utils.js'; +import { cellValidation, ValidateViolation } from '@/components/grid/cell-validators.js'; const emit = defineEmits<{ (ev: 'operation:beginEdit', sender: GridCell): void; (ev: 'operation:endEdit', sender: GridCell): void; + (ev: 'operation:validation', sender: GridCell, violation: ValidateViolation): void; (ev: 'change:value', sender: GridCell, newValue: CellValue): void; (ev: 'change:contentSize', sender: GridCell, newSize: Size): void; }>(); @@ -210,7 +212,9 @@ function endEditing(applyValue: boolean) { } function emitValueChange(newValue: CellValue) { - emit('change:value', cell.value, newValue); + const _cell = cell.value; + const violation = cellValidation(_cell, newValue); + emit('operation:validation', _cell, violation); } function emitContentSizeChanged() { diff --git a/packages/frontend/src/components/grid/MkDataRow.vue b/packages/frontend/src/components/grid/MkDataRow.vue index 8b1b1dfe60..a60cee8c62 100644 --- a/packages/frontend/src/components/grid/MkDataRow.vue +++ b/packages/frontend/src/components/grid/MkDataRow.vue @@ -20,10 +20,11 @@