feat(docs): per-side and inside table borders in ribbon (fixes #165) (#200)

* feat(docs): per-side and inside table borders in ribbon (fixes #165)

* style(docs): prettier-wrap border button props

* fix(docs): drop unused props from IconBorderDashedFrame

---------

Co-authored-by: Aniruddha Adak <aniruddhaadak80@users.noreply.github.com>
This commit is contained in:
ANIRUDDHA ADAK
2026-09-06 11:08:54 +08:00
committed by GitHub
co-authored by Aniruddha Adak
parent 360ce0625e
commit 567ad37013
22 changed files with 252 additions and 2 deletions
+81 -2
View File
@@ -80,9 +80,15 @@ import {
IconAlignRight,
IconAutoFit,
IconBorderAll,
IconBorderBottom,
IconBorderInner,
IconBorderInsideH,
IconBorderInsideV,
IconBorderLeft,
IconBorderNone,
IconBorderOuter,
IconBorderRight,
IconBorderTop,
IconBullets,
IconCaret,
IconCellAlignBottom,
@@ -1040,14 +1046,42 @@ function RibbonInner({
: 23.28
type BorderSide = { style: string; szEighths?: number; color?: string }
/** Apply borders to selected cells: all/outer/inner compute the four sides per cell from selection geometry; none clears explicitly */
const applyCellBorders = (mode: 'all' | 'outer' | 'inner' | 'none') => {
/** Apply borders to selected cells: all/outer/inner compute the four sides per cell from selection geometry; none clears explicitly.
* top/bottom/left/right apply only to that edge of the selection. insideH/insideV
* write the table-level tblBorders attr (per-cell insideH/insideV has no renderer):
* they apply to the whole table, as their tips state. */
const applyCellBorders = (
mode:
| 'all'
| 'outer'
| 'inner'
| 'none'
| 'top'
| 'bottom'
| 'left'
| 'right'
| 'insideH'
| 'insideV',
) => {
if (!canEdit || !isInTable(editor.state)) return
editor.view.focus()
const { state, view } = editor
const rect = selectedRect(state)
const solid: BorderSide = { style: 'single', szEighths: borderSz, color: borderColor }
const none: BorderSide = { style: 'none' }
if (mode === 'insideH' || mode === 'insideV') {
const tablePos = rect.tableStart - 1
const tableNode = state.doc.nodeAt(tablePos)
if (!tableNode || tableNode.type.name !== 'docTable') return
const prev = (tableNode.attrs.borders as Record<string, BorderSide> | null) ?? {}
view.dispatch(
state.tr.setNodeMarkup(tablePos, undefined, {
...tableNode.attrs,
borders: { ...prev, [mode]: solid },
}),
)
return
}
let tr = state.tr
const seen = new Set<number>()
for (let row = rect.top; row < rect.bottom; row++) {
@@ -1073,6 +1107,7 @@ function RibbonInner({
else if (mode === 'none') next[side] = none
else if (mode === 'outer' && edge[side]) next[side] = solid
else if (mode === 'inner' && !edge[side]) next[side] = solid
else if (mode === side && edge[side]) next[side] = solid
}
tr = tr.setNodeMarkup(pos, undefined, { ...node.attrs, borders: next })
}
@@ -2460,6 +2495,50 @@ function RibbonInner({
{t('ribbonNoBorders')}
</button>
</div>
<div className="table-tool-grid table-tool-grid-three">
<button
data-tip={t('ribbonOuterBordersTip')}
onClick={() => applyCellBorders('top')}
>
<IconBorderTop />
{t('ribbonBorderTop')}
</button>
<button
data-tip={t('ribbonOuterBordersTip')}
onClick={() => applyCellBorders('bottom')}
>
<IconBorderBottom />
{t('ribbonBorderBottom')}
</button>
<button
data-tip={t('ribbonOuterBordersTip')}
onClick={() => applyCellBorders('left')}
>
<IconBorderLeft />
{t('ribbonBorderLeft')}
</button>
<button
data-tip={t('ribbonOuterBordersTip')}
onClick={() => applyCellBorders('right')}
>
<IconBorderRight />
{t('ribbonBorderRight')}
</button>
<button
data-tip={t('ribbonTableInsideHBordersTip')}
onClick={() => applyCellBorders('insideH')}
>
<IconBorderInsideH />
{t('ribbonTableInsideHBorders')}
</button>
<button
data-tip={t('ribbonTableInsideVBordersTip')}
onClick={() => applyCellBorders('insideV')}
>
<IconBorderInsideV />
{t('ribbonTableInsideVBorders')}
</button>
</div>
<div className="table-tool-row table-border-opts">
<input
type="color"
@@ -773,6 +773,75 @@ export function IconBorderNone(props: IconProps) {
)
}
function IconBorderDashedFrame() {
return (
<rect
x="3.02"
y="3.02"
width="9.96"
height="9.96"
rx="0.42"
strokeWidth="1"
strokeDasharray="1.5 1.7"
opacity="0.55"
/>
)
}
export function IconBorderTop(props: IconProps) {
return (
<Svg {...props}>
<IconBorderDashedFrame />
<path d="M 3.02 3.02 h 9.96" />
</Svg>
)
}
export function IconBorderBottom(props: IconProps) {
return (
<Svg {...props}>
<IconBorderDashedFrame />
<path d="M 3.02 12.98 h 9.96" />
</Svg>
)
}
export function IconBorderLeft(props: IconProps) {
return (
<Svg {...props}>
<IconBorderDashedFrame />
<path d="M 3.02 3.02 v 9.96" />
</Svg>
)
}
export function IconBorderRight(props: IconProps) {
return (
<Svg {...props}>
<IconBorderDashedFrame />
<path d="M 12.98 3.02 v 9.96" />
</Svg>
)
}
export function IconBorderInsideH(props: IconProps) {
return (
<Svg {...props}>
<IconBorderDashedFrame />
<path d="M 3.02 8 h 9.96" />
</Svg>
)
}
export function IconBorderInsideV(props: IconProps) {
return (
<Svg {...props}>
<IconBorderDashedFrame />
<path d="M 8 3.02 v 9.96" />
</Svg>
)
}
/* ---------- Design ---------- */
export function IconTheme(props: IconProps) {
+4
View File
@@ -147,6 +147,10 @@ export const ar = {
ribbonOuterBordersTip: 'حدود على الحافة الخارجية للتحديد فقط',
ribbonInnerBorders: 'الحدود الداخلية',
ribbonInnerBordersTip: 'حدود داخل التحديد فقط',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'مسح حدود الخلايا المحددة',
ribbonBorderColor: 'لون الحدود',
ribbonBorderWidth: 'سُمك الحدود',
+4
View File
@@ -151,6 +151,10 @@ export const de = {
ribbonOuterBordersTip: 'Rahmenlinien nur am äußeren Rand der Auswahl',
ribbonInnerBorders: 'Rahmenlinien innen',
ribbonInnerBordersTip: 'Rahmenlinien nur innerhalb der Auswahl',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Rahmenlinien der ausgewählten Zellen entfernen',
ribbonBorderColor: 'Rahmenfarbe',
ribbonBorderWidth: 'Rahmenstärke',
+4
View File
@@ -148,6 +148,10 @@ export const en = {
ribbonOuterBordersTip: 'Borders on the outer edge of the selection only',
ribbonInnerBorders: 'Inside Borders',
ribbonInnerBordersTip: 'Borders inside the selection only',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Clear borders from the selected cells',
ribbonBorderColor: 'Border color',
ribbonBorderWidth: 'Border weight',
+4
View File
@@ -151,6 +151,10 @@ export const es = {
ribbonOuterBordersTip: 'Bordes solo en el contorno de la selección',
ribbonInnerBorders: 'Bordes internos',
ribbonInnerBordersTip: 'Bordes solo en el interior de la selección',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Borrar los bordes de las celdas seleccionadas',
ribbonBorderColor: 'Color del borde',
ribbonBorderWidth: 'Grosor del borde',
+4
View File
@@ -151,6 +151,10 @@ export const fr = {
ribbonOuterBordersTip: 'Bordures uniquement sur le pourtour de la sélection',
ribbonInnerBorders: 'Bordures intérieures',
ribbonInnerBordersTip: "Bordures uniquement à l'intérieur de la sélection",
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Effacer les bordures des cellules sélectionnées',
ribbonBorderColor: 'Couleur de bordure',
ribbonBorderWidth: 'Épaisseur de bordure',
+4
View File
@@ -147,6 +147,10 @@ export const he = {
ribbonOuterBordersTip: 'גבולות רק בהיקף החיצוני של הבחירה',
ribbonInnerBorders: 'גבולות פנימיים',
ribbonInnerBordersTip: 'גבולות רק בתוך הבחירה',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'נקה גבולות מהתאים הנבחרים',
ribbonBorderColor: 'צבע גבול',
ribbonBorderWidth: 'עובי גבול',
+4
View File
@@ -150,6 +150,10 @@ export const hi = {
ribbonOuterBordersTip: 'केवल चयन के बाहरी किनारे पर बॉर्डर',
ribbonInnerBorders: 'भीतरी बॉर्डर',
ribbonInnerBordersTip: 'केवल चयन के भीतर बॉर्डर',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'चयनित कक्षों से बॉर्डर साफ़ करें',
ribbonBorderColor: 'बॉर्डर रंग',
ribbonBorderWidth: 'बॉर्डर मोटाई',
+4
View File
@@ -149,6 +149,10 @@ export const id = {
ribbonOuterBordersTip: 'Batas hanya di tepi luar pilihan',
ribbonInnerBorders: 'Batas Dalam',
ribbonInnerBordersTip: 'Batas hanya di bagian dalam pilihan',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Hapus batas dari sel yang dipilih',
ribbonBorderColor: 'Warna batas',
ribbonBorderWidth: 'Ketebalan batas',
+4
View File
@@ -151,6 +151,10 @@ export const it = {
ribbonOuterBordersTip: 'Bordi solo sul contorno esterno della selezione',
ribbonInnerBorders: 'Bordi interni',
ribbonInnerBordersTip: "Bordi solo all'interno della selezione",
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Rimuovi i bordi dalle celle selezionate',
ribbonBorderColor: 'Colore bordo',
ribbonBorderWidth: 'Spessore bordo',
+4
View File
@@ -158,6 +158,10 @@ export const ja = {
ribbonOuterBordersTip: '選択範囲の外側のみに罫線を追加',
ribbonInnerBorders: '内側の罫線',
ribbonInnerBordersTip: '選択範囲の内側のみに罫線を追加',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: '選択したセルの罫線をクリア',
ribbonBorderColor: '罫線の色',
ribbonBorderWidth: '罫線の太さ',
+4
View File
@@ -156,6 +156,10 @@ export const ko = {
ribbonOuterBordersTip: '선택 영역의 바깥쪽에만 테두리 추가',
ribbonInnerBorders: '안쪽 테두리',
ribbonInnerBordersTip: '선택 영역의 안쪽에만 테두리 추가',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: '선택한 셀의 테두리 지우기',
ribbonBorderColor: '테두리 색',
ribbonBorderWidth: '테두리 두께',
+4
View File
@@ -150,6 +150,10 @@ export const ms = {
ribbonOuterBordersTip: 'Sempadan pada bahagian luar pilihan sahaja',
ribbonInnerBorders: 'Sempadan Dalam',
ribbonInnerBordersTip: 'Sempadan di bahagian dalam pilihan sahaja',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Kosongkan sempadan daripada sel yang dipilih',
ribbonBorderColor: 'Warna sempadan',
ribbonBorderWidth: 'Ketebalan sempadan',
+4
View File
@@ -152,6 +152,10 @@ export const nl = {
ribbonOuterBordersTip: 'Alleen randen aan de buitenkant van de selectie',
ribbonInnerBorders: 'Binnenranden',
ribbonInnerBordersTip: 'Alleen randen binnen de selectie',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Randen van de geselecteerde cellen wissen',
ribbonBorderColor: 'Randkleur',
ribbonBorderWidth: 'Randdikte',
+4
View File
@@ -150,6 +150,10 @@ export const pl = {
ribbonOuterBordersTip: 'Krawędzie tylko na zewnętrznym obrysie zaznaczenia',
ribbonInnerBorders: 'Krawędzie wewnętrzne',
ribbonInnerBordersTip: 'Krawędzie tylko wewnątrz zaznaczenia',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Usuń krawędzie z zaznaczonych komórek',
ribbonBorderColor: 'Kolor krawędzi',
ribbonBorderWidth: 'Grubość krawędzi',
+4
View File
@@ -150,6 +150,10 @@ export const pt = {
ribbonOuterBordersTip: 'Bordas apenas no contorno externo da seleção',
ribbonInnerBorders: 'Bordas Internas',
ribbonInnerBordersTip: 'Bordas apenas no interior da seleção',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Limpar as bordas das células selecionadas',
ribbonBorderColor: 'Cor da borda',
ribbonBorderWidth: 'Espessura da borda',
+4
View File
@@ -150,6 +150,10 @@ export const ru = {
ribbonOuterBordersTip: 'Границы только по внешнему краю выделения',
ribbonInnerBorders: 'Внутренние границы',
ribbonInnerBordersTip: 'Границы только внутри выделения',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'Убрать границы выделенных ячеек',
ribbonBorderColor: 'Цвет границы',
ribbonBorderWidth: 'Толщина границы',
+4
View File
@@ -148,6 +148,10 @@ export const th = {
ribbonOuterBordersTip: 'เส้นขอบเฉพาะรอบนอกของส่วนที่เลือกเท่านั้น',
ribbonInnerBorders: 'เส้นขอบด้านใน',
ribbonInnerBordersTip: 'เส้นขอบเฉพาะด้านในของส่วนที่เลือกเท่านั้น',
ribbonTableInsideHBorders: 'Inside Horizontal',
ribbonTableInsideHBordersTip: 'Inside horizontal borders for the whole table',
ribbonTableInsideVBorders: 'Inside Vertical',
ribbonTableInsideVBordersTip: 'Inside vertical borders for the whole table',
ribbonClearBordersTip: 'ล้างเส้นขอบของเซลล์ที่เลือก',
ribbonBorderColor: 'สีเส้นขอบ',
ribbonBorderWidth: 'ความหนาเส้นขอบ',
@@ -146,6 +146,10 @@ export const zhTW = {
ribbonOuterBordersTip: '僅選取範圍外側加上框線',
ribbonInnerBorders: '內框線',
ribbonInnerBordersTip: '僅選取範圍內部加上框線',
ribbonTableInsideHBorders: '內側橫框線',
ribbonTableInsideHBordersTip: '僅對整個表格添加內部橫向框線',
ribbonTableInsideVBorders: '內側縱框線',
ribbonTableInsideVBordersTip: '僅對整個表格添加內部縱向框線',
ribbonClearBordersTip: '清除選取儲存格的框線',
ribbonBorderColor: '框線色彩',
ribbonBorderWidth: '框線粗細',
+4
View File
@@ -155,6 +155,10 @@ export const zh = {
ribbonOuterBordersTip: '仅选区外侧加框线',
ribbonInnerBorders: '内侧框线',
ribbonInnerBordersTip: '仅选区内部加框线',
ribbonTableInsideHBorders: '内侧横框线',
ribbonTableInsideHBordersTip: '仅对整个表格添加内部横向框线',
ribbonTableInsideVBorders: '内侧纵框线',
ribbonTableInsideVBordersTip: '仅对整个表格添加内部纵向框线',
ribbonClearBordersTip: '清除选中单元格框线',
ribbonBorderColor: '框线颜色',
ribbonBorderWidth: '框线粗细',
+26
View File
@@ -0,0 +1,26 @@
import { describe, expect, it } from 'vitest'
import { tableBordersCss } from '../src/renderer/editor/extensions'
describe('tableBordersCss', () => {
it('emits edge variables for declared sides and none otherwise', () => {
const css = tableBordersCss({ top: { style: 'single', szEighths: 4, color: '000000' } })
expect(css).toContain('--doc-b-t:1px solid #000000')
expect(css).toContain('--doc-b-b:none')
expect(css).toContain('--doc-b-h:none')
expect(css).toContain('--doc-b-v:none')
})
it('emits insideH/insideV variables for table-level inner borders', () => {
const css = tableBordersCss({
insideH: { style: 'single', szEighths: 4, color: 'FF0000' },
insideV: { style: 'single', szEighths: 12, color: '0000FF' },
})
expect(css).toContain('--doc-b-h:1px solid #FF0000')
expect(css).toContain('--doc-b-v:2px solid #0000FF')
})
it('returns no declarations for a null attr', () => {
expect(tableBordersCss(null)).toEqual([])
})
})