Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/polite-tables-dress.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@wangeditor-next/table-module": patch
---

Improve table and cell property modal controls.
96 changes: 74 additions & 22 deletions packages/table-module/__tests__/menu/property-menu.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ function setSelectionInsideFirstCell(editor) {
}

function createContextSelection(editor, rows: number[][][]): NodeEntryWithContext[][] {
return rows.map(row => row.map(path => [
[Node.get(editor, path as any) as any, path as any],
{
rtl: 0,
ltr: 1,
ttb: 1,
btt: 0,
},
]))
return rows.map(row =>
row.map(path => [
[Node.get(editor, path as any) as any, path as any],
{
rtl: 0,
ltr: 1,
ttb: 1,
btt: 0,
},
])
)
}

describe('table property menus', () => {
Expand All @@ -73,14 +75,20 @@ describe('table property menus', () => {
const borderColor = elem.querySelector('[name="borderColor"]') as HTMLInputElement
const borderWidth = elem.querySelector('[name="borderWidth"]') as HTMLInputElement
const backgroundColor = elem.querySelector('[name="backgroundColor"]') as HTMLInputElement
const textAlign = elem.querySelector('[name="textAlign"]') as HTMLSelectElement
const button = elem.querySelector('button') as HTMLButtonElement
const textAlign = elem.querySelector('[name="textAlign"]') as HTMLInputElement
const centerAlignButton = elem.querySelector(
'.w-e-table-property-align-button[data-value="center"]'
) as HTMLButtonElement
const button = elem.querySelector('.button-container button') as HTMLButtonElement

borderStyle.value = 'dashed'
borderColor.value = '#ff0000'
borderWidth.value = '2'
backgroundColor.value = '#00ff00'
textAlign.value = 'center'
centerAlignButton.click()

expect(textAlign.value).toBe('center')
expect(centerAlignButton.classList.contains('active')).toBe(true)

button.click()
vi.runAllTimers()
Expand All @@ -105,21 +113,33 @@ describe('table property menus', () => {
EDITOR_TO_SELECTION.set(
editor,
createContextSelection(editor, [
[[0, 0, 0], [0, 0, 1]],
[[0, 1, 0], [0, 1, 1]],
]),
[
[0, 0, 0],
[0, 0, 1],
],
[
[0, 1, 0],
[0, 1, 1],
],
])
)

const elem = menu.getModalContentElem(editor) as HTMLDivElement
const borderStyle = elem.querySelector('[name="borderStyle"]') as HTMLSelectElement
const textAlign = elem.querySelector('[name="textAlign"]') as HTMLSelectElement
const textAlign = elem.querySelector('[name="textAlign"]') as HTMLInputElement
const rightAlignButton = elem.querySelector(
'.w-e-table-property-align-button[data-value="right"]'
) as HTMLButtonElement
const backgroundColor = elem.querySelector('[name="backgroundColor"]') as HTMLInputElement
const button = elem.querySelector('button') as HTMLButtonElement
const button = elem.querySelector('.button-container button') as HTMLButtonElement

borderStyle.value = 'solid'
textAlign.value = 'right'
rightAlignButton.click()
backgroundColor.value = '#cccccc'

expect(textAlign.value).toBe('right')
expect(rightAlignButton.classList.contains('active')).toBe(true)

button.click()
vi.runAllTimers()

Expand All @@ -138,8 +158,12 @@ describe('table property menus', () => {

setSelectionInsideFirstCell(editor)
vi.spyOn(editor, 'getMenuConfig').mockImplementation((mark: string) => {
if (mark === 'color') { return { colors: ['#ff0000', '#00ff00'] } as any }
if (mark === 'bgColor') { return { colors: ['#cccccc'] } as any }
if (mark === 'color') {
return { colors: ['#ff0000', '#00ff00'] } as any
}
if (mark === 'bgColor') {
return { colors: ['#cccccc'] } as any
}
return {} as any
})

Expand All @@ -156,8 +180,9 @@ describe('table property menus', () => {
colorOption.click()

expect(borderColorInput.value).toBe('#00ff00')
expect((borderColorTrigger.querySelector('.color-group-block') as HTMLElement).style.backgroundColor)
.toContain('0, 255, 0')
expect(
(borderColorTrigger.querySelector('.color-group-block') as HTMLElement).style.backgroundColor
).toContain('0, 255, 0')

const clearPanel = menu.getPanelContentElem(editor, {
mark: 'bgColor',
Expand All @@ -168,4 +193,31 @@ describe('table property menus', () => {
expect(clearPanel.text()).toContain('清除')
expect(clearPanel.find('li.active').attr('data-value')).toBe('#cccccc')
})

test('TableProperty marks the current text alignment button as active', () => {
const editor = createEditor({
content: [
{
...createTableContent()[0],
textAlign: 'right',
},
],
})
const menu = new TableProperty()

setSelectionInsideFirstCell(editor)

const elem = menu.getModalContentElem(editor) as HTMLDivElement
const rightAlignButton = elem.querySelector(
'.w-e-table-property-align-button[data-value="right"]'
) as HTMLButtonElement
const leftAlignButton = elem.querySelector(
'.w-e-table-property-align-button[data-value="left"]'
) as HTMLButtonElement

expect(rightAlignButton.classList.contains('active')).toBe(true)
expect(rightAlignButton.getAttribute('aria-pressed')).toBe('true')
expect(leftAlignButton.classList.contains('active')).toBe(false)
expect(leftAlignButton.getAttribute('aria-pressed')).toBe('false')
})
})
124 changes: 100 additions & 24 deletions packages/table-module/src/assets/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -160,52 +160,128 @@
}

.w-e-modal {
.babel-container {
span.babel-container-border {
.w-e-table-property-modal {
.babel-container {
display: flex;
align-items: flex-start;
margin-bottom: 14px;

> span {
margin-bottom: 0;
}
}

.w-e-table-property-label {
flex: 0 0 72px;
min-height: 32px;
padding-top: 6px;
color: @toolbar-color;
line-height: 20px;
}

.w-e-table-property-controls {
flex: 1;
min-width: 0;
}

&> * {
height: 28px;
span.babel-container-border {
display: grid;
grid-template-columns: minmax(108px, 1fr) 32px 86px;
column-gap: 8px;

& > * {
min-height: 32px;
border: 1px solid var(--w-e-modal-button-border-color);
border-radius: 2px;
border-radius: 4px;
}

select {
width: 114px;
width: 100%;
height: 32px;
padding: 4px 8px;
color: @toolbar-color;
background-color: @toolbar-bg-color;
}
}

> :nth-child(n+2) {
margin-left: 8px;
}
.w-e-table-property-number {
position: relative;
display: block;

input:nth-child(3) {
width: 100px;
input[type='number'] {
width: 100%;
height: 30px;
padding-right: 28px;
border: 0;
}
}

span.babel-container-background input {
height: 28px;
border: 1px solid var(--w-e-modal-button-border-color);
border-radius: 2px;
width: 60px;
.w-e-table-property-unit {
position: absolute;
top: 50%;
right: 8px;
display: inline;
margin-bottom: 0;
color: @toolbar-disabled-color;
line-height: 1;
transform: translateY(-50%);
}

span.babel-container-algin select {
height: 28px;
span.babel-container-background {
display: flex;
min-height: 32px;
}

span.babel-container-align {
display: flex;
}

.w-e-table-property-align {
display: inline-flex;
overflow: hidden;
border: 1px solid var(--w-e-modal-button-border-color);
border-radius: 2px;
border-radius: 4px;
}

.w-e-table-property-align-button {
display: inline-flex;
align-items: center;
justify-content: center;
width: 36px;
height: 32px;
padding: 0;
border: 0;
border-right: 1px solid var(--w-e-modal-button-border-color);
border-radius: 0;
background-color: @toolbar-bg-color;

&:last-child {
border-right: 0;
}

&.active {
color: @toolbar-active-color;
background-color: @toolbar-active-bg-color;
}

svg {
width: 15px;
height: 15px;
fill: currentColor;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Fix currentColor keyword casing to satisfy Stylelint.

fill: currentColor; at Line 270 violates the configured keyword-case rule and can fail linting.

Proposed fix
-        fill: currentColor;
+        fill: currentcolor;

As per coding guidelines, style/lint violations should be fixed in changed segments.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
fill: currentColor;
fill: currentcolor;
🧰 Tools
🪛 Stylelint (17.12.0)

[error] 270-270: Expected "currentColor" to be "currentcolor" (value-keyword-case)

(value-keyword-case)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/table-module/src/assets/index.less` at line 270, The CSS keyword
casing violates Stylelint: locate the declaration "fill: currentColor;" (in
assets/index.less) and change the keyword to lowercase ("fill: currentcolor;")
so it satisfies the keyword-case rule; ensure you only modify the keyword casing
for the "fill" declaration.

Sources: Coding guidelines, Linters/SAST tools

}
}

.color-group {
position: relative;
width: 28px;
height: 28px;
width: 32px;
height: 32px;
margin-bottom: 0;
border: 1px solid var(--w-e-modal-button-border-color);
border-radius: 2px;
border-radius: 4px;
cursor: pointer;

.w-e-drop-panel {
margin-top: 28px;
margin-top: 32px;
}
}

Expand All @@ -218,7 +294,7 @@
svg {
width: 20px;
height: 20px;
margin: 1px 0px;
margin: 2px 1px;
}
}
}
Expand Down
1 change: 1 addition & 0 deletions packages/table-module/src/locale/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
tableModule: {
modal: {
border: 'Border',
borderColor: 'Border color',
borderWidth: 'Width',
bgColor: 'Back color',
align: 'Text Align',
Expand Down
1 change: 1 addition & 0 deletions packages/table-module/src/locale/zh-CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export default {
tableModule: {
modal: {
border: '边框',
borderColor: '边框颜色',
borderWidth: '宽度',
bgColor: '背景色',
align: '对齐方式',
Expand Down
2 changes: 1 addition & 1 deletion packages/table-module/src/module/menu/CellProperty.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class CellProperty extends TableProperty implements IButtonMenu {

readonly showModal = true

readonly modalWidth = 300
readonly modalWidth = 360

readonly menu = 'cell'

Expand Down
Loading