12 | {fields.map(field => {
13 | return (
14 |
{
18 | event.preventDefault()
19 | event.stopPropagation()
20 | editor.emitter.emitHaptic()
21 | editor.operate(operator => {
22 | Command.setNBDBBoardLabeledField(operator as NBOperator, {
23 | templateBlockID: template.templateBlockID,
24 | fieldID: field.fieldID,
25 | })
26 | })
27 | editor.popup(null)
28 | }}
29 | >
30 |
31 |
{field.name}
32 |
40 | {field.labelMap ? Object.keys(field.labelMap).length : 0}
41 |
42 |
43 | )
44 | })}
45 |
{
48 | event.preventDefault()
49 | event.stopPropagation()
50 |
51 | const fieldID = template.addNewLabeledField()
52 | if (!fieldID) return
53 |
54 | editor.popup({
55 | type: "nbdb-field",
56 | meta: {
57 | tableBlockID: template.tableBlockID,
58 | templateBlockID: template.templateBlockID,
59 | fieldID,
60 | disableTypeChanging: true,
61 | },
62 | }, event)
63 | }}
64 | >
65 |
Create New Field
66 |
67 |
68 | )
69 | }
70 |
--------------------------------------------------------------------------------
/src/adapter/dataManipulator/nbCRDTWithNBDB/range.ts:
--------------------------------------------------------------------------------
1 | import type {BlockID, NBRange, DBFieldID} from "@/domain"
2 |
3 | export type NBCellRange = {
4 | templateBlockID: BlockID;
5 | recordBlockID: BlockID;
6 | fieldID: DBFieldID;
7 | offset?: {start: number; end: number; isCollapsed: boolean};
8 | };
9 |
10 | export const subCellRange = (range: NBRange): NBCellRange | null => {
11 | if (range.start.subPath?.type !== "db") return null
12 | if (!range.start.subPath?.fieldID) return null
13 |
14 | const startSubPath = range.start.subPath
15 | if (startSubPath.fieldID !== range.end.subPath?.fieldID)
16 | return null
17 |
18 | if (
19 | range.start.blockID !== range.end.blockID ||
20 | startSubPath.recordBlockID !== range.end.subPath?.recordBlockID
21 | )
22 | return null
23 |
24 | return {
25 | templateBlockID: range.start.blockID,
26 | recordBlockID: startSubPath.recordBlockID,
27 | fieldID: startSubPath.fieldID!,
28 | offset:
29 | range.start.offset != null && range.end.offset != null
30 | ? {
31 | start: range.start.offset,
32 | end: range.end.offset,
33 | isCollapsed: range.isCollapsed,
34 | }
35 | : undefined,
36 | }
37 | }
38 |
--------------------------------------------------------------------------------
/src/adapter/dataManipulator/nbCRDTWithNBDB/state/drag/index.ts:
--------------------------------------------------------------------------------
1 | import type {Handler} from "@/domain/usecase/state/drag"
2 |
3 | import dbSpreadsheetColHandler from "./spreadsheet/col"
4 | import dbSpreadsheetDBRecordHandler from "./spreadsheet/record"
5 | import dbBoardColHandler from "./board/col"
6 | import dbBoardRecordHandler from "./board/record"
7 | import nbdbLabelsHandler from "./popup/labels"
8 | import nbdbFieldsHandler from "./popup/fields"
9 |
10 | export enum NBDBDragType {
11 | DBSpreadsheetRecord = "DB_SPREADSHEET_RECORD",
12 | DBSpreadsheetCol = "DB_SPREADSHEET_COL",
13 | DBBoardRecord = "DB_BOARD_RECORD",
14 | DBBoardCol = "DB_BOARD_COL",
15 | NBDBLabels = "NBDB_LABELS" ,
16 | NBDBFields = "NBDB_FIELDS",
17 | }
18 |
19 | export const customDragHandlers: {[type: string]: Handler} = {
20 | [NBDBDragType.DBSpreadsheetCol]: dbSpreadsheetColHandler,
21 | [NBDBDragType.DBSpreadsheetRecord]: dbSpreadsheetDBRecordHandler,
22 | [NBDBDragType.DBBoardCol]: dbBoardColHandler,
23 | [NBDBDragType.DBBoardRecord]: dbBoardRecordHandler,
24 | [NBDBDragType.NBDBLabels]: nbdbLabelsHandler,
25 | [NBDBDragType.NBDBFields]: nbdbFieldsHandler,
26 | }
--------------------------------------------------------------------------------
/src/adapter/dataManipulator/nbCRDTWithNBDB/state/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./template"
2 | export * from "./drag"
3 |
--------------------------------------------------------------------------------
/src/adapter/dataManipulator/nbCRDTWithNBDB/state/template/common/index.ts:
--------------------------------------------------------------------------------
1 | export * from "./state"
2 | export * from "./template"
--------------------------------------------------------------------------------
/src/adapter/dataManipulator/nbCRDTWithNBDB/state/template/common/state.ts:
--------------------------------------------------------------------------------
1 | import type {BlockID, Editor} from "@/domain"
2 | import type {NBDBTemplate} from "./template"
3 |
4 | import {BlockType} from "@/domain"
5 |
6 | export class Templates {
7 | editor: Editor
8 |
9 | private states: {[blockID: string]: NBDBTemplate} = {}
10 |
11 | constructor(editor: Editor) {
12 | this.editor = editor
13 | }
14 |
15 | get(blockID: BlockID): NBDBTemplate | undefined {
16 | return this.states[blockID]
17 | }
18 |
19 | add(blockID: BlockID, state: NBDBTemplate) {
20 | this.states[blockID] = state
21 | }
22 |
23 | update(blockIDs: Set