MCPcopy Create free account
hub / github.com/editablejs/editable / InsertActionDefault

Function InsertActionDefault

packages/plugins/table/src/components/action.tsx:43–126  ·  view source on GitHub ↗
({
  editor,
  table,
  left,
  top,
  height,
  width,
  index,
})

Source from the content-addressed store, hash-verified

41
42// insert action
43const InsertActionDefault: React.FC<TableActionProps> = ({
44 editor,
45 table,
46 left,
47 top,
48 height,
49 width,
50 index,
51}) => {
52 if (left !== undefined) {
53 left -= 1
54 }
55 if (top !== undefined) {
56 top -= 1
57 }
58
59 if (height !== undefined) {
60 height += 11
61 }
62 if (width !== undefined) {
63 width += 11
64 }
65
66 const type = left !== undefined ? TYPE_COL : TYPE_ROW
67
68 const { minColWidth = defaultTableMinColWidth, minRowHeight = defaultTableMinRowHeight } =
69 useTableOptions(editor)
70
71 const draggingTo = useTableDragTo()
72
73 const handleMouseDown = (event: React.MouseEvent) => {
74 event.preventDefault()
75 if (type === TYPE_COL) {
76 let colWidth = minColWidth
77 const { colsWidth } = table
78 if (colsWidth) {
79 if (index >= colsWidth.length) colWidth = colsWidth[colsWidth.length - 1]
80 else {
81 colWidth = colsWidth[index]
82 }
83 }
84 const path = Editable.findPath(editor, table)
85 Grid.insertCol(editor, path, index, { type: TABLE_CELL_KEY }, colWidth, minColWidth)
86 const newGrid = Grid.above(editor, path)
87 if (newGrid && newGrid[0].colsWidth) {
88 const newColsWidth = adaptiveExpandColumnWidthInContainer(editor, newGrid[0].colsWidth)
89 Transforms.setNodes<Grid>(editor, { colsWidth: newColsWidth }, { at: path })
90 }
91 } else if (type === TYPE_ROW) {
92 Grid.insertRow(
93 editor,
94 Editable.findPath(editor, table),
95 index,
96 { type: TABLE_ROW_KEY },
97 { type: TABLE_CELL_KEY },
98 minRowHeight,
99 )
100 }

Callers

nothing calls this directly

Calls 2

useTableOptionsFunction · 0.90
useTableDragToFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…