Skip to content

Commit f40cad3

Browse files
committed
fix(table): improve property modal defaults
1 parent c06bde0 commit f40cad3

5 files changed

Lines changed: 381 additions & 162 deletions

File tree

packages/table-module/__tests__/menu/property-menu.test.ts

Lines changed: 58 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ function changeInputValue(input: HTMLInputElement | HTMLSelectElement, value: st
4747
input.dispatchEvent(new Event('change', { bubbles: true }))
4848
}
4949

50+
function selectBorderStyle(elem: HTMLElement, value: string) {
51+
const trigger = elem.querySelector('.w-e-table-property-select-trigger') as HTMLButtonElement
52+
const option = elem.querySelector(
53+
`.w-e-table-property-select-option[data-value="${value}"]`
54+
) as HTMLButtonElement
55+
56+
trigger.click()
57+
option.click()
58+
}
59+
5060
function createContextSelection(editor, rows: number[][][]): NodeEntryWithContext[][] {
5161
return rows.map(row =>
5262
row.map(path => [
@@ -76,15 +86,12 @@ describe('table property menus', () => {
7686
setSelectionInsideFirstCell(editor)
7787

7888
const elem = menu.getModalContentElem(editor) as HTMLDivElement
79-
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLSelectElement
89+
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLInputElement
8090
const borderWidth = elem.querySelector('[name="borderWidth"]') as HTMLInputElement
8191
const borderColorTrigger = elem.querySelector('[data-mark="color"]') as HTMLElement
8292
const backgroundColorTrigger = elem.querySelector('[data-mark="bgColor"]') as HTMLElement
83-
const width = elem.querySelector('[name="width"]') as HTMLInputElement
84-
const fullWidthButton = elem.querySelector(
85-
'.w-e-table-property-segment-button[data-value="100%"]'
86-
) as HTMLButtonElement
8793
const textAlign = elem.querySelector('[name="textAlign"]') as HTMLInputElement | null
94+
const width = elem.querySelector('[name="width"]') as HTMLInputElement | null
8895
const button = elem.querySelector('.button-container button') as HTMLButtonElement
8996

9097
vi.spyOn(editor, 'getMenuConfig').mockImplementation((mark: string) => {
@@ -97,24 +104,23 @@ describe('table property menus', () => {
97104
return {} as any
98105
})
99106

100-
fullWidthButton.click()
101-
changeInputValue(borderStyle, 'dashed')
107+
selectBorderStyle(elem, 'dashed')
102108
changeInputValue(borderWidth, '2')
103109
borderColorTrigger.click()
104110
;(borderColorTrigger.querySelector('li[data-value="#ff0000"]') as HTMLElement).click()
105111
backgroundColorTrigger.click()
106112
;(backgroundColorTrigger.querySelector('li[data-value="#00ff00"]') as HTMLElement).click()
107113

108114
expect(textAlign).toBeNull()
109-
expect(width.value).toBe('100%')
110-
expect(fullWidthButton.classList.contains('active')).toBe(true)
115+
expect(width).toBeNull()
116+
expect(borderStyle.value).toBe('dashed')
111117

112118
button.click()
113119
vi.runAllTimers()
114120

115121
const table = editor.children[0] as TableElement & Record<string, string>
116122

117-
expect(table.width).toBe('100%')
123+
expect(table.width).toBe('auto')
118124
expect(table.borderStyle).toBe('dashed')
119125
expect(table.borderColor).toBe('#ff0000')
120126
expect(table.borderWidth).toBe('2')
@@ -123,6 +129,44 @@ describe('table property menus', () => {
123129
expect(focusSpy).toHaveBeenCalled()
124130
})
125131

132+
test('TableProperty shows default border style and makes selected border color visible', () => {
133+
vi.useFakeTimers()
134+
const editor = createEditor({ content: createTableContent() })
135+
const menu = new TableProperty()
136+
137+
setSelectionInsideFirstCell(editor)
138+
vi.spyOn(editor, 'getMenuConfig').mockImplementation((mark: string) => {
139+
if (mark === 'color') {
140+
return { colors: ['#ff0000'] } as any
141+
}
142+
return {} as any
143+
})
144+
145+
const elem = menu.getModalContentElem(editor) as HTMLDivElement
146+
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLInputElement
147+
const borderWidth = elem.querySelector('[name="borderWidth"]') as HTMLInputElement
148+
const borderColorTrigger = elem.querySelector('[data-mark="color"]') as HTMLElement
149+
const button = elem.querySelector('.button-container button') as HTMLButtonElement
150+
151+
expect(borderStyle.value).toBe('none')
152+
expect(borderWidth.placeholder).toBe('默认 1')
153+
154+
borderColorTrigger.click()
155+
;(borderColorTrigger.querySelector('li[data-value="#ff0000"]') as HTMLElement).click()
156+
157+
expect(borderStyle.value).toBe('solid')
158+
expect(borderWidth.value).toBe('1')
159+
160+
button.click()
161+
vi.runAllTimers()
162+
163+
const table = editor.children[0] as TableElement & Record<string, string>
164+
165+
expect(table.borderColor).toBe('#ff0000')
166+
expect(table.borderStyle).toBe('solid')
167+
expect(table.borderWidth).toBe('1')
168+
})
169+
126170
test('CellProperty applies properties to every selected cell in the batch selection', () => {
127171
vi.useFakeTimers()
128172
const editor = createEditor({ content: createTableContent() })
@@ -145,7 +189,6 @@ describe('table property menus', () => {
145189
)
146190

147191
const elem = menu.getModalContentElem(editor) as HTMLDivElement
148-
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLSelectElement
149192
const textAlign = elem.querySelector('[name="textAlign"]') as HTMLInputElement
150193
const rightAlignButton = elem.querySelector(
151194
'.w-e-table-property-align-button[data-value="right"]'
@@ -164,7 +207,7 @@ describe('table property menus', () => {
164207
return {} as any
165208
})
166209

167-
changeInputValue(borderStyle, 'solid')
210+
selectBorderStyle(elem, 'solid')
168211
rightAlignButton.click()
169212
middleVerticalAlignButton.click()
170213
backgroundColorTrigger.click()
@@ -235,7 +278,7 @@ describe('table property menus', () => {
235278

236279
const elem = menu.getModalContentElem(editor) as HTMLDivElement
237280
const backgroundColor = elem.querySelector('[name="backgroundColor"]') as HTMLInputElement
238-
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLSelectElement
281+
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLInputElement
239282
const rightAlignButton = elem.querySelector(
240283
'.w-e-table-property-align-button[data-value="right"]'
241284
) as HTMLButtonElement
@@ -287,6 +330,8 @@ describe('table property menus', () => {
287330
colorOption.click()
288331

289332
expect(borderColorInput.value).toBe('#00ff00')
333+
expect((elem.querySelector('[name="borderStyle"]') as HTMLInputElement).value).toBe('solid')
334+
expect((elem.querySelector('[name="borderWidth"]') as HTMLInputElement).value).toBe('1')
290335
expect(
291336
(borderColorTrigger.querySelector('.color-group-block') as HTMLElement).style.backgroundColor
292337
).toContain('0, 255, 0')

packages/table-module/src/assets/index.less

Lines changed: 60 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,80 @@
186186
min-width: 0;
187187
}
188188

189-
span.babel-container-width,
190189
span.babel-container-select,
191190
span.babel-container-number {
192191
display: block;
193192
}
194193

195-
span.babel-container-width {
194+
.w-e-table-property-select {
195+
position: relative;
196+
display: block;
196197
width: 100%;
197198
}
198199

199-
span.babel-container-select select {
200+
.w-e-table-property-select-trigger {
201+
position: relative;
200202
width: 100%;
201203
height: 32px;
202-
padding: 4px 8px;
204+
padding: 4px 24px 4px 8px;
203205
color: @toolbar-color;
204206
background-color: @toolbar-bg-color;
207+
text-align: left;
205208
border: 1px solid @modal-button-border-color;
206209
border-radius: 4px;
210+
211+
&::after {
212+
position: absolute;
213+
top: 50%;
214+
right: 8px;
215+
width: 0;
216+
height: 0;
217+
border-top: 4px solid @toolbar-disabled-color;
218+
border-right: 4px solid transparent;
219+
border-left: 4px solid transparent;
220+
content: '';
221+
transform: translateY(-50%);
222+
}
223+
}
224+
225+
.w-e-table-property-select-value {
226+
display: block;
227+
overflow: hidden;
228+
line-height: 20px;
229+
text-overflow: ellipsis;
230+
white-space: nowrap;
231+
}
232+
233+
.w-e-table-property-select-panel {
234+
position: absolute;
235+
z-index: 1;
236+
top: 34px;
237+
left: 0;
238+
display: none;
239+
width: 100%;
240+
max-height: 184px;
241+
overflow-y: auto;
242+
padding: 4px;
243+
border: 1px solid @modal-button-border-color;
244+
border-radius: 4px;
245+
background-color: @toolbar-bg-color;
246+
box-shadow: 0 2px 8px #0000001f;
247+
}
248+
249+
.w-e-table-property-select-option {
250+
display: block;
251+
width: 100%;
252+
height: 28px;
253+
padding: 4px 8px;
254+
text-align: left;
255+
border: 0;
256+
border-radius: 3px;
257+
background-color: transparent;
258+
259+
&:hover,
260+
&.active {
261+
background-color: @toolbar-active-bg-color;
262+
}
207263
}
208264

209265
.w-e-table-property-number {
@@ -243,10 +299,6 @@
243299
display: flex;
244300
}
245301

246-
span.babel-container-vertical-align {
247-
display: flex;
248-
}
249-
250302
.w-e-table-property-align,
251303
.w-e-table-property-segment {
252304
display: inline-flex;

packages/table-module/src/locale/en.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
borderColor: 'Border color',
1111
borderStyle: 'Border style',
1212
borderWidth: 'Border width',
13+
borderWidthDefault: 'Default 1',
1314
bgColor: 'Back color',
1415
align: 'Text Align',
1516
verticalAlign: 'Vertical Align',

packages/table-module/src/locale/zh-CN.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export default {
1010
borderColor: '边框颜色',
1111
borderStyle: '边框样式',
1212
borderWidth: '边框粗细',
13+
borderWidthDefault: '默认 1',
1314
bgColor: '背景色',
1415
align: '对齐方式',
1516
verticalAlign: '垂直对齐',

0 commit comments

Comments
 (0)