Skip to content

Commit 66716da

Browse files
authored
feat: format-painter allow ignore formats (#318)
* feat: format-painter allow ignore formats * chore: upgrate table-up * chore: lint code * pref: optimize variable set
1 parent 67f0d23 commit 66716da

9 files changed

Lines changed: 69 additions & 99 deletions

File tree

packages/docs/fluent-editor/demos/table-up-menu.vue

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ onMounted(() => {
3434
'toolbar': TOOLBAR_CONFIG,
3535
'table-up': {
3636
customSelect: defaultCustomSelect,
37-
selection: TableSelection,
38-
selectionOptions: {
39-
tableMenu: TableMenuSelect,
40-
},
37+
modules: [
38+
{ module: TableSelection },
39+
{ module: TableMenuSelect },
40+
],
4141
},
4242
},
4343
})
@@ -49,10 +49,10 @@ onMounted(() => {
4949
'toolbar': TOOLBAR_CONFIG,
5050
'table-up': {
5151
customSelect: defaultCustomSelect,
52-
selection: TableSelection,
53-
selectionOptions: {
54-
tableMenu: TableMenuContextmenu,
55-
},
52+
modules: [
53+
{ module: TableSelection },
54+
{ module: TableMenuContextmenu },
55+
],
5656
},
5757
},
5858
})

packages/docs/fluent-editor/demos/table-up-resize.vue

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ onMounted(() => {
3636
'toolbar': TOOLBAR_CONFIG,
3737
'table-up': {
3838
customSelect: defaultCustomSelect,
39-
resize: TableResizeBox,
39+
modules: [
40+
{ module: TableResizeBox },
41+
],
4042
},
4143
},
4244
})
@@ -48,7 +50,9 @@ onMounted(() => {
4850
'toolbar': TOOLBAR_CONFIG,
4951
'table-up': {
5052
customSelect: defaultCustomSelect,
51-
resize: TableResizeLine,
53+
modules: [
54+
{ module: TableResizeLine },
55+
],
5256
},
5357
},
5458
})
@@ -60,7 +64,9 @@ onMounted(() => {
6064
'toolbar': TOOLBAR_CONFIG,
6165
'table-up': {
6266
customSelect: defaultCustomSelect,
63-
resizeScale: TableResizeScale,
67+
modules: [
68+
{ module: TableResizeScale },
69+
],
6470
},
6571
},
6672
})

packages/docs/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"mathlive": "^0.101.0",
2525
"quill-header-list": "0.0.2",
2626
"quill-markdown-shortcuts": "^0.0.10",
27-
"quill-table-up": "^2.1.7",
27+
"quill-table-up": "^3.0.1",
2828
"quill-toolbar-tip": "^0.0.13",
2929
"vue": "^3.5.13",
3030
"vue-toastification": "2.0.0-rc.5"

packages/fluent-editor/src/config/types/editor-config.interface.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,14 @@ import type { ScreenShotOptions } from '../../tools/screenshot'
33
import type { IEditorModules } from './editor-modules.interface'
44

55
export interface IEditorConfig extends QuillOptions {
6-
modules?: IEditorModules
7-
screenshotOnStaticPage?: boolean
8-
scrollingContainer?: HTMLElement | string | null
6+
'modules'?: IEditorModules
7+
'screenshotOnStaticPage'?: boolean
8+
'scrollingContainer'?: HTMLElement | string | null
99
// Auto protocol for link
10-
autoProtocol?: boolean | string
11-
editorPaste?: any
12-
screenshot?: Partial<ScreenShotOptions>
10+
'autoProtocol'?: boolean | string
11+
'editorPaste'?: any
12+
'screenshot'?: Partial<ScreenShotOptions>
13+
'format-painter'?: {
14+
ignoreFormat?: string[]
15+
}
1316
}

packages/fluent-editor/src/modules/table-up/index.ts

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,30 @@
1-
import type { Parchment } from 'quill'
21
import type Toolbar from 'quill/modules/toolbar'
32
import type BaseTheme from 'quill/themes/base'
43
import type Picker from 'quill/ui/picker'
54
import type { Constructor } from '../../config/types'
65
import type FluentEditor from '../../core/fluent-editor'
76
import { CHANGE_LANGUAGE_EVENT } from '../../config'
7+
import { isFunction } from '../../utils/is'
88

99
interface QuillTheme extends BaseTheme {
1010
pickers: QuillThemePicker[]
1111
}
1212
type QuillThemePicker = (Picker & { options: HTMLElement })
13-
interface InternalModule {
14-
show: () => void
15-
hide: () => void
16-
update: () => void
17-
destroy: () => void
18-
}
19-
export interface InternalTableSelectionModule extends InternalModule {
20-
dragging: boolean
21-
boundary: {
22-
x: number
23-
y: number
24-
x1: number
25-
y1: number
26-
width: number
27-
height: number
28-
} | null
29-
selectedTds: Parchment.Blot[]
30-
cellSelect: HTMLElement
31-
tableMenu?: InternalModule
32-
computeSelectedTds: (
33-
startPoint: {
34-
x: number
35-
y: number
36-
},
37-
endPoint: {
38-
x: number
39-
y: number
40-
}
41-
) => Parchment.Blot[]
42-
updateWithSelectedTds: () => void
43-
}
13+
4414
export function generateTableUp(QuillTableUp: Constructor) {
4515
return class extends QuillTableUp {
46-
tableSelection?: InternalTableSelectionModule
4716
constructor(public quill: FluentEditor, options: Partial<any>) {
4817
super(quill, options)
4918

19+
if (!this.quill.options['format-painter']) this.quill.options['format-painter'] = {}
20+
const currentIgnoreFormat = this.quill.options['format-painter'].ignoreFormat || []
21+
this.quill.options['format-painter'].ignoreFormat = Array.from(
22+
new Set([
23+
...currentIgnoreFormat,
24+
'table-up-cell-inner',
25+
]),
26+
)
27+
5028
this.quill.emitter.on(CHANGE_LANGUAGE_EVENT, () => {
5129
this.options.texts = this.resolveTexts(options.texts)
5230
const toolbar = this.quill.getModule('toolbar') as Toolbar
@@ -59,13 +37,14 @@ export function generateTableUp(QuillTableUp: Constructor) {
5937
}
6038
}
6139
}
62-
if (this.tableSelection) {
63-
this.tableSelection.destroy()
64-
}
65-
if (this.options.selection) {
66-
// eslint-disable-next-line new-cap
67-
this.tableSelection = new this.options.selection(this, this.quill, this.options.selectionOptions)
68-
}
40+
41+
Object.keys(this.modules).forEach((key) => {
42+
if (isFunction(this.modules[key].destroy)) {
43+
this.modules[key].destroy()
44+
}
45+
})
46+
this.modules = {}
47+
this.initModules()
6948
})
7049
}
7150

packages/fluent-editor/src/tools/format-painter.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import type { Range } from 'quill'
22
import type Toolbar from 'quill/modules/toolbar'
33
import Quill from 'quill'
44

5-
interface FormatData {
5+
export interface FormatData {
66
formatPainter: {
77
rangeFormat: Record<string, any>
88
isFormatterLock: boolean
@@ -22,8 +22,14 @@ export function FormatPainter(this: Toolbar & FormatData) {
2222
const [, formatterBtn] = this.controls.find(([name]) => name === FormatPainter.toolName)
2323
const formatRange = (range: Range | null) => {
2424
if (!range) return
25-
this.quill.removeFormat(range.index, range.length)
25+
const currentFormats = this.quill.getFormat(range)
26+
for (const format in currentFormats) {
27+
if (this.quill.options['format-painter']?.ignoreFormat?.includes(format)) continue
28+
this.quill.format(format, null, Quill.sources.USER)
29+
}
30+
2631
for (const format in this.formatPainter.rangeFormat) {
32+
if (this.quill.options['format-painter']?.ignoreFormat?.includes(format)) continue
2733
this.quill.format(format, this.formatPainter.rangeFormat[format], Quill.sources.USER)
2834
}
2935
if (!this.formatPainter.isFormatterLock) {
@@ -54,7 +60,7 @@ export function FormatPainter(this: Toolbar & FormatData) {
5460
}
5561
const unbindFormatSelect = () => {
5662
this.quill.off(Quill.events.SELECTION_CHANGE, formatRange)
57-
this.formatPainter.rangeFormat = undefined
63+
this.formatPainter.rangeFormat = {}
5864
btnRemoveActive()
5965
this.formatPainter.isFormating = false
6066
this.formatPainter.isFormatterLock = false

packages/projects/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"@opentiny/fluent-editor": "workspace:^",
1313
"@tailwindcss/vite": "^4.0.0",
1414
"quill-header-list": "0.0.2",
15-
"quill-table-up": "^2.1.7",
15+
"quill-table-up": "^3.0.1",
1616
"sass": "^1.90.0",
1717
"tailwindcss": "^4.0.0",
1818
"vue": "^3.5.13",

packages/projects/src/views/yuque/YuQue.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,12 @@ onMounted(() => {
5757
},
5858
'table-up': {
5959
customSelect: defaultCustomSelect,
60-
selection: TableSelection,
61-
selectionOptions: {
62-
tableMenu: TableMenuContextmenu,
63-
},
64-
resize: TableResizeLine,
65-
resizeScale: TableResizeScale,
60+
modules: [
61+
{ module: TableResizeLine },
62+
{ module: TableResizeScale },
63+
{ module: TableSelection },
64+
{ module: TableMenuContextmenu },
65+
],
6666
},
6767
'shortcut-key': {
6868
menuItems: [tableUpConfig],

0 commit comments

Comments
 (0)