@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.
Files changed (26) hide show
  1. package/dist/components/form/inputs/RichText/components/EditorToolbar.vue.d.ts.map +1 -1
  2. package/dist/components/form/inputs/RichText/composables/useCommands.d.ts.map +1 -1
  3. package/dist/components/form/inputs/RichText/composables/useEditor.d.ts.map +1 -1
  4. package/dist/components/form/inputs/RichText/composables/useEditorKeyboard.d.ts.map +1 -1
  5. package/dist/components/form/inputs/RichText/config.d.ts.map +1 -1
  6. package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
  7. package/dist/components/form/inputs/RichText/richTextTypes.d.ts +1 -1
  8. package/dist/components/form/inputs/RichText/richTextTypes.d.ts.map +1 -1
  9. package/dist/components/form/inputs/RichText/utils/commands.d.ts.map +1 -1
  10. package/dist/components/form/inputs/RichText/utils/formatting.d.ts.map +1 -1
  11. package/dist/components/form/inputs/RichText/utils/selection.d.ts.map +1 -1
  12. package/dist/index.cjs +20 -20
  13. package/dist/index.mjs +19 -19
  14. package/dist/style.css +1 -1
  15. package/package.json +1 -1
  16. package/src/components/dataTable/DataTable.vue +1 -1
  17. package/src/components/form/inputs/RichText/components/EditorToolbar.vue +11 -0
  18. package/src/components/form/inputs/RichText/composables/useCommands.ts +42 -0
  19. package/src/components/form/inputs/RichText/composables/useEditor.ts +8 -5
  20. package/src/components/form/inputs/RichText/composables/useEditorKeyboard.ts +2 -128
  21. package/src/components/form/inputs/RichText/config.ts +15 -4
  22. package/src/components/form/inputs/RichText/index.vue +275 -73
  23. package/src/components/form/inputs/RichText/richTextTypes.ts +5 -0
  24. package/src/components/form/inputs/RichText/utils/commands.ts +614 -82
  25. package/src/components/form/inputs/RichText/utils/formatting.ts +17 -15
  26. 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
- const span = doc.createElement('span') as HTMLSpanElement
23
- if (command === 'underline') span.style.textDecoration = 'underline'
24
- else if (command === 'bold') span.style.fontWeight = 'bold'
25
- else if (command === 'italic') span.style.fontStyle = 'italic'
26
-
27
- if (isRTL) span.dir = 'rtl'
28
- range.surroundContents(span)
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
- const span = doc.createElement('span')
34
- if (command === 'bold') span.style.fontWeight = 'bold'
35
- else if (command === 'italic') span.style.fontStyle = 'italic'
36
- else if (command === 'underline') span.style.textDecoration = '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(span)
40
- } catch (e) {
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
- span.appendChild(fragment)
45
- range.insertNode(span)
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 or inline styles
28
+ // Text formatting - check for elements only, not CSS styles
29
29
  bold: (el) => {
30
30
  const tagName = el.tagName?.toLowerCase()
31
- if (tagName === 'strong' || tagName === 'b') return true
32
- const styles = window.getComputedStyle(el)
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
- if (tagName === 'em' || tagName === 'i') return true
39
- const styles = window.getComputedStyle(el)
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
- if (tagName === 'u') return true
46
- const styles = window.getComputedStyle(el)
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 (e) {
165
+ } catch {
145
166
  if (fallbackNode) {
146
167
  range.selectNodeContents(fallbackNode)
147
168
  }