@bagelink/vue 1.4.139 → 1.4.141
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.
- package/dist/components/form/inputs/RichText/components/EditorToolbar.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/composables/useCommands.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/composables/useEditor.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/composables/useEditorKeyboard.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/config.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/richTextTypes.d.ts +1 -1
- package/dist/components/form/inputs/RichText/richTextTypes.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/commands.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/formatting.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/utils/selection.d.ts.map +1 -1
- package/dist/index.cjs +20 -20
- package/dist/index.mjs +19 -19
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/dataTable/DataTable.vue +1 -1
- package/src/components/form/inputs/RichText/components/EditorToolbar.vue +11 -0
- package/src/components/form/inputs/RichText/composables/useCommands.ts +42 -0
- package/src/components/form/inputs/RichText/composables/useEditor.ts +8 -5
- package/src/components/form/inputs/RichText/composables/useEditorKeyboard.ts +2 -128
- package/src/components/form/inputs/RichText/config.ts +15 -4
- package/src/components/form/inputs/RichText/index.vue +275 -73
- package/src/components/form/inputs/RichText/richTextTypes.ts +5 -0
- package/src/components/form/inputs/RichText/utils/commands.ts +614 -82
- package/src/components/form/inputs/RichText/utils/formatting.ts +17 -15
- package/src/components/form/inputs/RichText/utils/selection.ts +32 -11
|
@@ -19,30 +19,32 @@ export function formatting(state: EditorState) {
|
|
|
19
19
|
// Don't apply inline styles directly to block elements
|
|
20
20
|
if (parentBlock?.tagName.match(/^H[1-6]|P|BLOCKQUOTE|LI$/)) {
|
|
21
21
|
if (!range.collapsed && range.toString().trim()) {
|
|
22
|
-
|
|
23
|
-
if (command === 'underline')
|
|
24
|
-
else if (command === 'bold')
|
|
25
|
-
else if (command === 'italic')
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
22
|
+
let element: HTMLElement
|
|
23
|
+
if (command === 'underline') element = doc.createElement('u')
|
|
24
|
+
else if (command === 'bold') element = doc.createElement('b')
|
|
25
|
+
else if (command === 'italic') element = doc.createElement('i')
|
|
26
|
+
else return
|
|
27
|
+
|
|
28
|
+
if (isRTL) element.dir = 'rtl'
|
|
29
|
+
range.surroundContents(element)
|
|
29
30
|
}
|
|
30
31
|
} else {
|
|
31
32
|
if (range.collapsed) return // No selection, nothing to format
|
|
32
33
|
|
|
33
|
-
|
|
34
|
-
if (command === 'bold')
|
|
35
|
-
else if (command === 'italic')
|
|
36
|
-
else if (command === 'underline')
|
|
34
|
+
let element: HTMLElement
|
|
35
|
+
if (command === 'bold') element = doc.createElement('b')
|
|
36
|
+
else if (command === 'italic') element = doc.createElement('i')
|
|
37
|
+
else if (command === 'underline') element = doc.createElement('u')
|
|
38
|
+
else return
|
|
37
39
|
|
|
38
40
|
try {
|
|
39
|
-
range.surroundContents(
|
|
40
|
-
} catch
|
|
41
|
+
range.surroundContents(element)
|
|
42
|
+
} catch {
|
|
41
43
|
// If surroundContents fails (e.g., for selections across multiple nodes)
|
|
42
44
|
// Extract the fragment, wrap it, and insert it back
|
|
43
45
|
const fragment = range.extractContents()
|
|
44
|
-
|
|
45
|
-
range.insertNode(
|
|
46
|
+
element.appendChild(fragment)
|
|
47
|
+
range.insertNode(element)
|
|
46
48
|
}
|
|
47
49
|
}
|
|
48
50
|
}
|
|
@@ -25,26 +25,23 @@ export function isStyleActive(style: string, doc: Document) {
|
|
|
25
25
|
|
|
26
26
|
// Define style checkers for different formatting types
|
|
27
27
|
const styleCheckers: { [key: string]: (el: Element) => boolean } = {
|
|
28
|
-
// Text formatting - check for elements
|
|
28
|
+
// Text formatting - check for elements only, not CSS styles
|
|
29
29
|
bold: (el) => {
|
|
30
30
|
const tagName = el.tagName?.toLowerCase()
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
return styles.fontWeight === 'bold' || styles.fontWeight === '700'
|
|
31
|
+
// Only consider <b> and <strong> tags, not CSS bold styling
|
|
32
|
+
return tagName === 'strong' || tagName === 'b'
|
|
34
33
|
},
|
|
35
34
|
|
|
36
35
|
italic: (el) => {
|
|
37
36
|
const tagName = el.tagName?.toLowerCase()
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return styles.fontStyle === 'italic'
|
|
37
|
+
// Only consider <i> and <em> tags, not CSS italic styling
|
|
38
|
+
return tagName === 'em' || tagName === 'i'
|
|
41
39
|
},
|
|
42
40
|
|
|
43
41
|
underline: (el) => {
|
|
44
42
|
const tagName = el.tagName?.toLowerCase()
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
return styles.textDecoration.includes('underline')
|
|
43
|
+
// Only consider <u> tag, not CSS underline styling
|
|
44
|
+
return tagName === 'u'
|
|
48
45
|
},
|
|
49
46
|
|
|
50
47
|
// Block elements
|
|
@@ -66,6 +63,30 @@ export function isStyleActive(style: string, doc: Document) {
|
|
|
66
63
|
unorderedList: (el) => {
|
|
67
64
|
// Check if we're inside an unordered list
|
|
68
65
|
return !!el.closest('ul')
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
// Text alignment
|
|
69
|
+
alignLeft: (el) => {
|
|
70
|
+
const paragraph = el.closest('p, h1, h2, h3, h4, h5, h6')
|
|
71
|
+
return (paragraph as HTMLElement)?.style.textAlign === 'left'
|
|
72
|
+
},
|
|
73
|
+
alignCenter: (el) => {
|
|
74
|
+
const paragraph = el.closest('p, h1, h2, h3, h4, h5, h6')
|
|
75
|
+
return (paragraph as HTMLElement)?.style.textAlign === 'center'
|
|
76
|
+
},
|
|
77
|
+
alignRight: (el) => {
|
|
78
|
+
const paragraph = el.closest('p, h1, h2, h3, h4, h5, h6')
|
|
79
|
+
return (paragraph as HTMLElement)?.style.textAlign === 'right'
|
|
80
|
+
},
|
|
81
|
+
alignJustify: (el) => {
|
|
82
|
+
const paragraph = el.closest('p, h1, h2, h3, h4, h5, h6')
|
|
83
|
+
return (paragraph as HTMLElement)?.style.textAlign === 'justify'
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
// Text direction
|
|
87
|
+
textDirection: (el) => {
|
|
88
|
+
const paragraph = el.closest('p, h1, h2, h3, h4, h5, h6')
|
|
89
|
+
return (paragraph as HTMLElement)?.dir === 'rtl'
|
|
69
90
|
}
|
|
70
91
|
}
|
|
71
92
|
|
|
@@ -141,7 +162,7 @@ export function restoreSelection(
|
|
|
141
162
|
try {
|
|
142
163
|
range.setStart(info.originalStart, info.originalStartOffset)
|
|
143
164
|
range.setEnd(info.originalEnd, info.originalEndOffset)
|
|
144
|
-
} catch
|
|
165
|
+
} catch {
|
|
145
166
|
if (fallbackNode) {
|
|
146
167
|
range.selectNodeContents(fallbackNode)
|
|
147
168
|
}
|