@bagelink/vue 1.4.62 → 1.4.69

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.
@@ -16,33 +16,57 @@ export function isStyleActive(style: string, doc: Document) {
16
16
 
17
17
  if (!parent) return false
18
18
 
19
- const checkParent = (element: Element | null, tags: string[]): boolean => {
20
- if (!element || !element.tagName) return false
21
- const tagName = element.tagName.toLowerCase()
22
- if (tags.includes(tagName)) return true
23
- return checkParent(element.parentElement, tags)
19
+ // Check if the current node or any parent has the style
20
+ const checkParent = (element: Element | null, checker: (el: Element) => boolean): boolean => {
21
+ if (!element) return false
22
+ if (checker(element)) return true
23
+ return checkParent(element.parentElement, checker)
24
24
  }
25
25
 
26
- // Define style mappings for different types of formatting
27
- const styleMappings: { [key: string]: string[] } = {
28
- // Inline styles
29
- bold: ['strong', 'b'],
30
- italic: ['em', 'i'],
31
- underline: ['u'],
32
-
33
- // Block styles
34
- h1: ['h1'],
35
- h2: ['h2'],
36
- h3: ['h3'],
37
- h4: ['h4'],
38
- h5: ['h5'],
39
- h6: ['h6'],
40
- p: ['p'],
41
- blockquote: ['blockquote'],
42
-
43
- // List styles
44
- orderedList: ['ol'],
45
- unorderedList: ['ul']
26
+ // Define style checkers for different formatting types
27
+ const styleCheckers: { [key: string]: (el: Element) => boolean } = {
28
+ // Text formatting - check for elements or inline styles
29
+ bold: (el) => {
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'
34
+ },
35
+
36
+ italic: (el) => {
37
+ const tagName = el.tagName?.toLowerCase()
38
+ if (tagName === 'em' || tagName === 'i') return true
39
+ const styles = window.getComputedStyle(el)
40
+ return styles.fontStyle === 'italic'
41
+ },
42
+
43
+ underline: (el) => {
44
+ const tagName = el.tagName?.toLowerCase()
45
+ if (tagName === 'u') return true
46
+ const styles = window.getComputedStyle(el)
47
+ return styles.textDecoration.includes('underline')
48
+ },
49
+
50
+ // Block elements
51
+ h1: el => el.tagName?.toLowerCase() === 'h1',
52
+ h2: el => el.tagName?.toLowerCase() === 'h2',
53
+ h3: el => el.tagName?.toLowerCase() === 'h3',
54
+ h4: el => el.tagName?.toLowerCase() === 'h4',
55
+ h5: el => el.tagName?.toLowerCase() === 'h5',
56
+ h6: el => el.tagName?.toLowerCase() === 'h6',
57
+ p: el => el.tagName?.toLowerCase() === 'p',
58
+ blockquote: el => el.tagName?.toLowerCase() === 'blockquote',
59
+
60
+ // List elements - check if we're inside a list
61
+ orderedList: (el) => {
62
+ // Check if we're inside an ordered list
63
+ return !!el.closest('ol')
64
+ },
65
+
66
+ unorderedList: (el) => {
67
+ // Check if we're inside an unordered list
68
+ return !!el.closest('ul')
69
+ }
46
70
  }
47
71
 
48
72
  // Special handling for view state commands
@@ -50,20 +74,14 @@ export function isStyleActive(style: string, doc: Document) {
50
74
  return false // These are handled by the editor state directly
51
75
  }
52
76
 
53
- // Special handling for list items
54
- if (style === 'orderedList' || style === 'unorderedList') {
55
- const listParent = parent.closest(style === 'orderedList' ? 'ol' : 'ul')
56
- return !!listParent
57
- }
58
-
59
- // Check for the style in the style mappings
60
- const tags = styleMappings[style]
61
- if (tags) {
62
- return checkParent(parent, tags)
77
+ // Use the appropriate checker
78
+ const checker = styleCheckers[style]
79
+ if (checker) {
80
+ return checkParent(parent, checker)
63
81
  }
64
82
 
65
- // Default to checking the style itself if no mapping exists
66
- return checkParent(parent, [style])
83
+ // Fallback: check if element matches the style tag name
84
+ return checkParent(parent, el => el.tagName?.toLowerCase() === style.toLowerCase())
67
85
  }
68
86
 
69
87
  export interface SelectionInfo {