@bagelink/vue 1.20.31 → 1.20.36

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/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/vue",
3
3
  "type": "module",
4
- "version": "1.20.31",
4
+ "version": "1.20.36",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -63,7 +63,7 @@
63
63
  "@types/signature_pad": "^4.0.0",
64
64
  "vue": "^3.5.43",
65
65
  "vue-component-type-helpers": "^2.2.12",
66
- "@bagelink/sdk": "1.20.31"
66
+ "@bagelink/sdk": "1.20.36"
67
67
  },
68
68
  "peerDependencies": {
69
69
  "@bagelink/sdk": "*",
@@ -28,10 +28,13 @@ export const basicToolbarConfig: ToolbarConfig = [
28
28
  'blockquote',
29
29
  'orderedList',
30
30
  'unorderedList',
31
+ 'indent',
32
+ 'outdent',
31
33
  'separator',
32
34
  'bold',
33
35
  'italic',
34
36
  'underline',
37
+ 'superscript',
35
38
  'separator',
36
39
  'paragraphToolsMenu',
37
40
  'separator',
@@ -61,6 +64,7 @@ export const fullToolbarConfig: ToolbarConfig = [
61
64
  'bold',
62
65
  'italic',
63
66
  'underline',
67
+ 'superscript',
64
68
  'separator',
65
69
  'fontColor',
66
70
  'bgColor',
@@ -107,6 +111,7 @@ export const toolbarOptions: ToolbarOption[] = [
107
111
  { name: 'bold', label: 'Bold', icon: 'format_bold', shortcut: '⌘/Ctrl+B' },
108
112
  { name: 'italic', label: 'Italic', icon: 'format_italic', shortcut: '⌘/Ctrl+I' },
109
113
  { name: 'underline', label: 'Underline', icon: 'format_underlined', shortcut: '⌘/Ctrl+U' },
114
+ { name: 'superscript', label: 'Superscript', icon: 'superscript' },
110
115
  { name: 'orderedList', label: 'Ordered List', icon: 'format_list_numbered', shortcut: '⌘/Ctrl+Shift+.' },
111
116
  { name: 'unorderedList', label: 'Unordered List', icon: 'format_list_bulleted', shortcut: '⌘/Ctrl+Shift+/' },
112
117
  { name: 'link', label: 'Link', icon: 'add_link', shortcut: '⌘/Ctrl+K' },
@@ -40,6 +40,7 @@ export type FormattingCommand =
40
40
  | 'bold'
41
41
  | 'italic'
42
42
  | 'underline'
43
+ | 'superscript'
43
44
  | 'formatBlock'
44
45
  | 'orderedList'
45
46
  | 'unorderedList'
@@ -251,7 +251,7 @@ function applyFormattingToWordAtCursor(doc: Document, range: Range, tagSelector:
251
251
 
252
252
  function toggleInlineFormatting(
253
253
  state: EditorState,
254
- tagName: 'b' | 'i' | 'u',
254
+ tagName: 'b' | 'i' | 'u' | 'sup',
255
255
  matchSelector: string
256
256
  ) {
257
257
  const selectionInfo = getCurrentSelection(state)
@@ -663,6 +663,18 @@ function updateStateAfterCommand(state: EditorState, preCommandContent?: string)
663
663
  }
664
664
  }
665
665
 
666
+ function shiftBlockIndent(doc: Document, range: Range, delta: number) {
667
+ const listItems = getSelectedListItems(doc, range)
668
+ const blocks = listItems.length
669
+ ? listItems
670
+ : [findBlockElement(range.commonAncestorContainer)].filter(Boolean) as HTMLElement[]
671
+ blocks.forEach((block) => {
672
+ const current = Number.parseInt(block.style.paddingInlineStart || '0', 10) || 0
673
+ const next = Math.max(0, current + delta)
674
+ block.style.paddingInlineStart = next > 0 ? `${next}px` : ''
675
+ })
676
+ }
677
+
666
678
  function findBlockElement(node: Node): HTMLElement | null {
667
679
  let current = node.nodeType === Node.TEXT_NODE ? node.parentElement : node as HTMLElement | null
668
680
  while (current) {
@@ -1028,6 +1040,11 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
1028
1040
  s => toggleUnderline(s),
1029
1041
  s => Boolean(s.doc && isStyleActive('underline', s.doc))
1030
1042
  ),
1043
+ superscript: createCommand(
1044
+ 'Superscript',
1045
+ s => toggleInlineFormatting(s, 'sup', 'sup'),
1046
+ s => Boolean(s.doc && isStyleActive('superscript', s.doc))
1047
+ ),
1031
1048
  link: createCommand('Link', (s) => {
1032
1049
  const { openLinkModal } = s as any
1033
1050
  if (openLinkModal) {
@@ -1122,33 +1139,14 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
1122
1139
  const selectionInfo = getCurrentSelection(s)
1123
1140
  if (!selectionInfo || !s.doc) { return }
1124
1141
  if (indentSelectedListItems(s.doc, selectionInfo.selection, selectionInfo.range)) { return }
1125
- const listItems = getSelectedListItems(s.doc, selectionInfo.range)
1126
- const blocks = listItems.length
1127
- ? listItems
1128
- : [findBlockElement(selectionInfo.range.commonAncestorContainer)].filter(Boolean) as HTMLElement[]
1129
- blocks.forEach((block) => {
1130
- const isRTL = (block.dir || s.doc?.body.dir) === 'rtl'
1131
- const prop = isRTL ? 'marginRight' : 'marginLeft'
1132
- const current = Number.parseInt(block.style[prop] || '0', 10) || 0
1133
- block.style[prop] = `${current + 24}px`
1134
- })
1142
+ shiftBlockIndent(s.doc, selectionInfo.range, 24)
1135
1143
  }),
1136
1144
 
1137
1145
  outdent: createCommand('Outdent', (s) => {
1138
1146
  const selectionInfo = getCurrentSelection(s)
1139
1147
  if (!selectionInfo || !s.doc) { return }
1140
1148
  if (outdentSelectedListItems(s.doc, selectionInfo.selection, selectionInfo.range)) { return }
1141
- const listItems = getSelectedListItems(s.doc, selectionInfo.range)
1142
- const blocks = listItems.length
1143
- ? listItems
1144
- : [findBlockElement(selectionInfo.range.commonAncestorContainer)].filter(Boolean) as HTMLElement[]
1145
- blocks.forEach((block) => {
1146
- const isRTL = (block.dir || s.doc?.body.dir) === 'rtl'
1147
- const prop = isRTL ? 'marginRight' : 'marginLeft'
1148
- const current = Number.parseInt(block.style[prop] || '0', 10) || 0
1149
- const next = Math.max(0, current - 24)
1150
- block.style[prop] = next > 0 ? `${next}px` : ''
1151
- })
1149
+ shiftBlockIndent(s.doc, selectionInfo.range, -24)
1152
1150
  })
1153
1151
  }
1154
1152
 
@@ -5,6 +5,7 @@ export const ACTIVE_STYLE_KEYS = [
5
5
  'bold',
6
6
  'italic',
7
7
  'underline',
8
+ 'superscript',
8
9
  'link',
9
10
  'h1',
10
11
  'h2',
@@ -118,6 +119,7 @@ export function isStyleActive(style: string, doc: Document): boolean {
118
119
  },
119
120
  // `<u>` tags and CSS-driven underlines (e.g. the browser default on `<a>`)
120
121
  underline: el => isElementVisuallyUnderlined(el),
122
+ superscript: (el) => el.tagName?.toLowerCase() === 'sup',
121
123
  link: (el) => {
122
124
  return el.tagName?.toLowerCase() === 'a'
123
125
  },
@@ -43,6 +43,8 @@ export interface DialogConfirmOptions extends DialogBaseOptions {
43
43
  export interface DialogOpenOptions extends DialogBaseOptions {
44
44
  component: Component | string
45
45
  props?: Record<string, any>
46
+ /** Called when the dialog closes by any means (button, ESC, backdrop). */
47
+ onClose?: () => void
46
48
  }
47
49
 
48
50
  export interface DialogRef {
@@ -40,7 +40,7 @@ interface DialogStackItem {
40
40
  id: number
41
41
  type: 'form' | 'confirm' | 'open'
42
42
  options: any
43
- resolve: (value: any) => void
43
+ resolve: (value?: any) => void
44
44
  open: boolean
45
45
  }
46
46
 
@@ -82,30 +82,29 @@ export const DialogPlugin: Plugin = {
82
82
 
83
83
  open: (options: DialogOpenOptions): DialogRef => {
84
84
  const id = ++dialogId
85
+ const close = () => {
86
+ if (!item.open) return
87
+ item.open = false
88
+ options.onClose?.()
89
+ // Remove after animation
90
+ setTimeout(() => {
91
+ const removeIdx = dialogStack.findIndex(d => d.id === id)
92
+ if (removeIdx !== -1) {
93
+ dialogStack.splice(removeIdx, 1)
94
+ }
95
+ }, 200)
96
+ }
97
+
85
98
  const item: DialogStackItem = {
86
99
  id,
87
100
  type: 'open',
88
101
  options,
89
- resolve: () => {},
102
+ resolve: close,
90
103
  open: true
91
104
  }
92
105
  dialogStack.push(item)
93
106
 
94
- return {
95
- close: () => {
96
- const idx = dialogStack.findIndex(d => d.id === id)
97
- if (idx !== -1) {
98
- dialogStack[idx].open = false
99
- // Remove after animation
100
- setTimeout(() => {
101
- const removeIdx = dialogStack.findIndex(d => d.id === id)
102
- if (removeIdx !== -1) {
103
- dialogStack.splice(removeIdx, 1)
104
- }
105
- }, 200)
106
- }
107
- }
108
- }
107
+ return { close }
109
108
  }
110
109
  }
111
110
 
@@ -143,23 +142,10 @@ export const DialogPlugin: Plugin = {
143
142
  }, 200)
144
143
  }
145
144
 
146
- function handleOpenUpdate(item: DialogStackItem, open: boolean) {
147
- if (!open) {
148
- item.open = false
149
- setTimeout(() => {
150
- const idx = dialogStack.findIndex(d => d.id === item.id)
151
- if (idx !== -1) {
152
- dialogStack.splice(idx, 1)
153
- }
154
- }, 200)
155
- }
156
- }
157
-
158
145
  return {
159
146
  dialogStack,
160
147
  handleFormResolve,
161
- handleConfirmResolve,
162
- handleOpenUpdate
148
+ handleConfirmResolve
163
149
  }
164
150
  },
165
151
  render() {
@@ -206,7 +192,7 @@ export const DialogPlugin: Plugin = {
206
192
  'position': opts.position,
207
193
  'dismissable': opts.dismissable,
208
194
  'class': opts.class,
209
- 'onUpdate:open': (open: boolean) => { this.handleOpenUpdate(item, open) }
195
+ 'onUpdate:open': (open: boolean) => { if (!open) item.resolve() }
210
196
  }, {
211
197
  default: () => h(
212
198
  typeof opts.component === 'string' ? opts.component : opts.component,