@bagelink/vue 1.2.13 → 1.2.15

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.
@@ -5,17 +5,52 @@ export function insertTable(rows: number, cols: number, state: EditorState) {
5
5
  const table = state.doc.createElement('table')
6
6
  table.style.width = '100%'
7
7
  table.style.borderCollapse = 'collapse'
8
+ table.style.marginBottom = '1rem'
9
+
10
+ // Add a header row
11
+ const thead = state.doc.createElement('thead')
12
+ const headerRow = thead.insertRow()
13
+ for (let j = 0; j < cols; j++) {
14
+ const th = state.doc.createElement('th')
15
+ th.innerHTML = `Header ${j + 1}`
16
+ th.style.padding = '8px'
17
+ th.style.border = '1px solid var(--border-color, #ddd)'
18
+ th.style.backgroundColor = 'var(--bgl-gray-light, #f4f4f4)'
19
+ headerRow.appendChild(th)
20
+ }
21
+ table.appendChild(thead)
8
22
 
23
+ // Add body rows
24
+ const tbody = state.doc.createElement('tbody')
9
25
  for (let i = 0; i < rows; i++) {
10
- const row = table.insertRow()
26
+ const row = tbody.insertRow()
11
27
  for (let j = 0; j < cols; j++) {
12
28
  const cell = row.insertCell()
13
29
  cell.innerHTML = '&nbsp;'
30
+ cell.style.padding = '8px'
31
+ cell.style.border = '1px solid var(--border-color, #ddd)'
14
32
  }
15
33
  }
34
+ table.appendChild(tbody)
35
+
36
+ // Insert the table at the current selection
16
37
  const { range } = state
17
38
  if (range) {
18
39
  range.insertNode(table)
40
+
41
+ // Move cursor inside first cell for convenience
42
+ if (state.doc.getSelection()) {
43
+ const firstCell = table.querySelector('td')
44
+ if (firstCell) {
45
+ range.selectNodeContents(firstCell)
46
+ range.collapse(true)
47
+ const selection = state.doc.getSelection()
48
+ if (selection) {
49
+ selection.removeAllRanges()
50
+ selection.addRange(range)
51
+ }
52
+ }
53
+ }
19
54
  } else {
20
55
  state.doc.body.appendChild(table)
21
56
  }