@bagelink/vue 1.5.17 → 1.5.20
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/bin/experimentalGenTypedRoutes.ts +15 -15
- package/bin/generateFormSchema.ts +12 -12
- package/bin/utils.ts +4 -4
- package/dist/components/Dropdown.vue.d.ts.map +1 -1
- package/dist/components/calendar/CalendarPopover.vue.d.ts.map +1 -1
- package/dist/components/form/BagelForm.vue.d.ts.map +1 -1
- package/dist/components/form/FieldArray.vue.d.ts +5 -4
- package/dist/components/form/FieldArray.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/CheckInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/RichText/index.vue.d.ts +1 -0
- package/dist/components/form/inputs/RichText/index.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/SelectInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/ToggleInput.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/Upload/UploadInput.vue.d.ts.map +1 -1
- package/dist/composables/useFormField.d.ts.map +1 -1
- package/dist/composables/useSchemaField.d.ts.map +1 -1
- package/dist/index.cjs +17 -14
- package/dist/index.mjs +511 -422
- package/dist/style.css +1 -1
- package/package.json +1 -1
- package/src/components/AccordionItem.vue +2 -2
- package/src/components/AddToCalendar.vue +1 -1
- package/src/components/BglVideo.vue +8 -8
- package/src/components/Btn.vue +9 -9
- package/src/components/Card.vue +4 -4
- package/src/components/Carousel.vue +44 -44
- package/src/components/DataPreview.vue +1 -1
- package/src/components/DragOver.vue +6 -6
- package/src/components/Dropdown.vue +14 -14
- package/src/components/Flag.vue +3 -3
- package/src/components/Icon/Icon.vue +13 -13
- package/src/components/Image.vue +4 -4
- package/src/components/ImportData.vue +79 -79
- package/src/components/ListItem.vue +7 -7
- package/src/components/MapEmbed/Index.vue +6 -6
- package/src/components/Modal.vue +10 -10
- package/src/components/ModalForm.vue +4 -4
- package/src/components/NavBar.vue +2 -2
- package/src/components/Pagination.vue +9 -9
- package/src/components/Pill.vue +1 -1
- package/src/components/Rating.vue +2 -2
- package/src/components/Slider.vue +77 -77
- package/src/components/Spreadsheet/Index.vue +34 -34
- package/src/components/Spreadsheet/SpreadsheetTable.vue +3 -3
- package/src/components/Zoomer.vue +28 -28
- package/src/components/analytics/BarChart.vue +6 -6
- package/src/components/analytics/KpiCard.vue +2 -2
- package/src/components/analytics/LineChart.vue +14 -14
- package/src/components/analytics/PieChart.vue +11 -11
- package/src/components/calendar/CalendarPopover.vue +1 -1
- package/src/components/calendar/Index.vue +1 -1
- package/src/components/calendar/views/AgendaView.vue +2 -2
- package/src/components/calendar/views/DayView.vue +6 -6
- package/src/components/calendar/views/MonthView.vue +2 -2
- package/src/components/calendar/views/WeekView.vue +18 -18
- package/src/components/dataTable/DataTable.vue +3 -3
- package/src/components/dataTable/useSorting.ts +1 -1
- package/src/components/dataTable/useTableData.ts +15 -15
- package/src/components/dataTable/useTableSelection.ts +8 -8
- package/src/components/dataTable/useTableVirtualization.ts +1 -1
- package/src/components/draggable/useDraggable.ts +42 -42
- package/src/components/form/BagelForm.vue +66 -23
- package/src/components/form/BglMultiStepForm.vue +18 -18
- package/src/components/form/FieldArray.vue +177 -67
- package/src/components/form/inputs/CheckInput.vue +2 -1
- package/src/components/form/inputs/CodeEditor/Index.vue +1 -1
- package/src/components/form/inputs/CodeEditor/format.ts +7 -7
- package/src/components/form/inputs/CodeEditor/useHighlight.ts +6 -6
- package/src/components/form/inputs/DateInput.vue +6 -6
- package/src/components/form/inputs/DatePicker.vue +19 -19
- package/src/components/form/inputs/EmailInput.vue +14 -14
- package/src/components/form/inputs/NumberInput.vue +6 -6
- package/src/components/form/inputs/OTP.vue +3 -3
- package/src/components/form/inputs/RadioGroup.vue +1 -1
- package/src/components/form/inputs/RadioPillsInput.vue +8 -8
- package/src/components/form/inputs/RichText/components/EditorToolbar.vue +10 -10
- package/src/components/form/inputs/RichText/components/TableGridSelector.vue +1 -1
- package/src/components/form/inputs/RichText/composables/useCommands.ts +1 -1
- package/src/components/form/inputs/RichText/composables/useEditor.ts +12 -12
- package/src/components/form/inputs/RichText/composables/useEditorKeyboard.ts +1 -1
- package/src/components/form/inputs/RichText/index.vue +143 -134
- package/src/components/form/inputs/RichText/utils/commands.ts +69 -69
- package/src/components/form/inputs/RichText/utils/debug.ts +1 -1
- package/src/components/form/inputs/RichText/utils/formatting.ts +39 -39
- package/src/components/form/inputs/RichText/utils/media.ts +6 -6
- package/src/components/form/inputs/RichText/utils/selection.ts +28 -28
- package/src/components/form/inputs/RichText/utils/table.ts +19 -19
- package/src/components/form/inputs/SelectBtn.vue +1 -1
- package/src/components/form/inputs/SelectInput.vue +50 -26
- package/src/components/form/inputs/SignaturePad.vue +15 -15
- package/src/components/form/inputs/TableField.vue +1 -1
- package/src/components/form/inputs/TelInput.vue +6 -6
- package/src/components/form/inputs/TextInput.vue +5 -5
- package/src/components/form/inputs/ToggleInput.vue +2 -1
- package/src/components/form/inputs/Upload/UploadInput.vue +155 -102
- package/src/components/form/inputs/Upload/upload.ts +1 -1
- package/src/components/form/inputs/Upload/useFileUpload.ts +6 -6
- package/src/components/form/useBagelFormState.ts +5 -5
- package/src/components/layout/AppContent.vue +1 -1
- package/src/components/layout/AppLayout.vue +1 -1
- package/src/components/layout/Layout.vue +4 -4
- package/src/components/layout/TabbedLayout.vue +1 -1
- package/src/components/layout/Tabs.vue +2 -2
- package/src/components/layout/TabsNav.vue +7 -7
- package/src/components/lightbox/Lightbox.vue +8 -8
- package/src/components/lightbox/index.ts +8 -8
- package/src/composables/index.ts +2 -2
- package/src/composables/useAddToCalendar.ts +13 -13
- package/src/composables/useDevice.ts +2 -2
- package/src/composables/useExcel.ts +6 -6
- package/src/composables/useFormField.ts +5 -9
- package/src/composables/usePolling.ts +8 -8
- package/src/composables/useSchemaField.ts +53 -38
- package/src/composables/useTheme.ts +9 -9
- package/src/composables/useValidateFieldValue.ts +2 -2
- package/src/directives/pattern.ts +25 -25
- package/src/directives/ripple.ts +4 -4
- package/src/directives/vResize.ts +6 -6
- package/src/plugins/bagel.ts +4 -4
- package/src/plugins/useModal.ts +3 -3
- package/src/styles/layout.css +7 -1
- package/src/utils/BagelFormUtils.ts +7 -7
- package/src/utils/calendar/Helpers.ts +8 -8
- package/src/utils/calendar/dateUtils.ts +22 -22
- package/src/utils/calendar/time.ts +25 -25
- package/src/utils/calendar/week.ts +25 -25
- package/src/utils/elementUtils.ts +27 -27
- package/src/utils/index.ts +22 -22
- package/src/utils/sizeParsing.ts +2 -2
- package/src/utils/strings.ts +5 -5
- package/src/utils/tapDetector.ts +11 -11
- package/src/utils/useSearch.ts +29 -29
- package/vite.config.ts +1 -1
|
@@ -21,10 +21,10 @@ export interface CommandExecutor {
|
|
|
21
21
|
|
|
22
22
|
// Helper functions
|
|
23
23
|
function getCurrentSelection(state: EditorState): { selection: Selection, range: Range } | null {
|
|
24
|
-
if (!state.doc) return null
|
|
24
|
+
if (!state.doc) {return null}
|
|
25
25
|
|
|
26
26
|
const selection = state.doc.getSelection()
|
|
27
|
-
if (!selection || !selection.rangeCount) return null
|
|
27
|
+
if (!selection || !selection.rangeCount) {return null}
|
|
28
28
|
|
|
29
29
|
const range = selection.getRangeAt(0)
|
|
30
30
|
return { selection, range }
|
|
@@ -32,7 +32,7 @@ function getCurrentSelection(state: EditorState): { selection: Selection, range:
|
|
|
32
32
|
|
|
33
33
|
// Alternative helper function to apply formatting to word at cursor
|
|
34
34
|
function applyFormattingToWordAtCursor(doc: Document, range: Range, tagName: string): boolean {
|
|
35
|
-
if (!range.collapsed) return false
|
|
35
|
+
if (!range.collapsed) {return false}
|
|
36
36
|
|
|
37
37
|
let textNode = range.startContainer
|
|
38
38
|
let offset = range.startOffset
|
|
@@ -40,7 +40,7 @@ function applyFormattingToWordAtCursor(doc: Document, range: Range, tagName: str
|
|
|
40
40
|
// If we're in an element node, try to find a text node
|
|
41
41
|
if (textNode.nodeType !== Node.TEXT_NODE) {
|
|
42
42
|
const element = textNode as Element
|
|
43
|
-
if (element.childNodes.length
|
|
43
|
+
if (0 < element.childNodes.length && offset < element.childNodes.length) {
|
|
44
44
|
const childNode = element.childNodes[offset]
|
|
45
45
|
if (childNode.nodeType === Node.TEXT_NODE) {
|
|
46
46
|
textNode = childNode
|
|
@@ -88,7 +88,7 @@ function applyFormattingToWordAtCursor(doc: Document, range: Range, tagName: str
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
const text = textNode.textContent || ''
|
|
91
|
-
if (!text) return false
|
|
91
|
+
if (!text) {return false}
|
|
92
92
|
|
|
93
93
|
// Find word boundaries - support Hebrew, English, and numbers
|
|
94
94
|
let start = offset
|
|
@@ -99,14 +99,14 @@ function applyFormattingToWordAtCursor(doc: Document, range: Range, tagName: str
|
|
|
99
99
|
|
|
100
100
|
// If we're at the end of a word (cursor right after the last character)
|
|
101
101
|
// move back one position to include that word
|
|
102
|
-
if (
|
|
102
|
+
if (0 < offset && wordChar.test(text[offset - 1]) &&
|
|
103
103
|
(offset >= text.length || !wordChar.test(text[offset]))) {
|
|
104
104
|
start = offset - 1
|
|
105
105
|
end = offset - 1
|
|
106
106
|
}
|
|
107
107
|
|
|
108
108
|
// Move start backwards to find word beginning
|
|
109
|
-
while (
|
|
109
|
+
while (0 < start && wordChar.test(text[start - 1])) {
|
|
110
110
|
start--
|
|
111
111
|
}
|
|
112
112
|
|
|
@@ -167,14 +167,14 @@ function applyFormattingToWordAtCursor(doc: Document, range: Range, tagName: str
|
|
|
167
167
|
}
|
|
168
168
|
|
|
169
169
|
function updateStateAfterCommand(state: EditorState) {
|
|
170
|
-
if (!state.doc) return
|
|
170
|
+
if (!state.doc) {return}
|
|
171
171
|
|
|
172
172
|
// Update content
|
|
173
173
|
state.content = state.doc.body.innerHTML
|
|
174
174
|
|
|
175
175
|
// Update selection state
|
|
176
176
|
const selection = state.doc.getSelection()
|
|
177
|
-
if (selection && selection.rangeCount
|
|
177
|
+
if (selection && 0 < selection.rangeCount) {
|
|
178
178
|
state.selection = selection
|
|
179
179
|
state.range = selection.getRangeAt(0).cloneRange()
|
|
180
180
|
state.rangeCount = selection.rangeCount
|
|
@@ -197,7 +197,7 @@ function createCommand(name: string, execute: Command['execute'], isActive?: Com
|
|
|
197
197
|
return {
|
|
198
198
|
name,
|
|
199
199
|
execute: (state: EditorState, value?: string) => {
|
|
200
|
-
if (!state.doc) return
|
|
200
|
+
if (!state.doc) {return}
|
|
201
201
|
execute(state, value)
|
|
202
202
|
updateStateAfterCommand(state)
|
|
203
203
|
},
|
|
@@ -209,7 +209,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
209
209
|
// History commands
|
|
210
210
|
const historyCommands = {
|
|
211
211
|
undo: createCommand('Undo', () => {
|
|
212
|
-
if (state.undoStack.length
|
|
212
|
+
if (0 < state.undoStack.length && state.doc) {
|
|
213
213
|
const lastContent = state.undoStack.pop()
|
|
214
214
|
if (lastContent !== undefined) {
|
|
215
215
|
state.redoStack.push(state.content)
|
|
@@ -219,7 +219,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
219
219
|
}
|
|
220
220
|
}),
|
|
221
221
|
redo: createCommand('Redo', () => {
|
|
222
|
-
if (state.redoStack.length
|
|
222
|
+
if (0 < state.redoStack.length && state.doc) {
|
|
223
223
|
const nextContent = state.redoStack.pop()
|
|
224
224
|
if (nextContent !== undefined) {
|
|
225
225
|
state.undoStack.push(state.content)
|
|
@@ -234,15 +234,15 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
234
234
|
const textCommands = {
|
|
235
235
|
bold: createCommand('Bold', (state) => {
|
|
236
236
|
const selectionInfo = getCurrentSelection(state)
|
|
237
|
-
if (!selectionInfo) return
|
|
237
|
+
if (!selectionInfo) {return}
|
|
238
238
|
|
|
239
239
|
let { range, selection } = selectionInfo
|
|
240
240
|
|
|
241
241
|
// If no text is selected, try to apply formatting to word at cursor
|
|
242
242
|
if (range.collapsed) {
|
|
243
243
|
const success = applyFormattingToWordAtCursor(state.doc!, range, 'b')
|
|
244
|
-
if (success) return
|
|
245
|
-
|
|
244
|
+
if (success) {return}
|
|
245
|
+
return
|
|
246
246
|
}
|
|
247
247
|
|
|
248
248
|
// Check if the selection is already bold
|
|
@@ -291,7 +291,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
291
291
|
}, (state) => {
|
|
292
292
|
// isActive function for bold
|
|
293
293
|
const selectionInfo = getCurrentSelection(state)
|
|
294
|
-
if (!selectionInfo) return false
|
|
294
|
+
if (!selectionInfo) {return false}
|
|
295
295
|
|
|
296
296
|
const commonAncestor = selectionInfo.range.commonAncestorContainer
|
|
297
297
|
const parentElement = commonAncestor.nodeType === Node.TEXT_NODE
|
|
@@ -303,15 +303,15 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
303
303
|
|
|
304
304
|
italic: createCommand('Italic', (state) => {
|
|
305
305
|
const selectionInfo = getCurrentSelection(state)
|
|
306
|
-
if (!selectionInfo) return
|
|
306
|
+
if (!selectionInfo) {return}
|
|
307
307
|
|
|
308
308
|
let { range, selection } = selectionInfo
|
|
309
309
|
|
|
310
310
|
// If no text is selected, try to apply formatting to word at cursor
|
|
311
311
|
if (range.collapsed) {
|
|
312
312
|
const success = applyFormattingToWordAtCursor(state.doc!, range, 'i')
|
|
313
|
-
if (success) return
|
|
314
|
-
|
|
313
|
+
if (success) {return}
|
|
314
|
+
return
|
|
315
315
|
}
|
|
316
316
|
|
|
317
317
|
// Check if the selection is already italic
|
|
@@ -360,7 +360,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
360
360
|
}, (state) => {
|
|
361
361
|
// isActive function for italic
|
|
362
362
|
const selectionInfo = getCurrentSelection(state)
|
|
363
|
-
if (!selectionInfo) return false
|
|
363
|
+
if (!selectionInfo) {return false}
|
|
364
364
|
|
|
365
365
|
const commonAncestor = selectionInfo.range.commonAncestorContainer
|
|
366
366
|
const parentElement = commonAncestor.nodeType === Node.TEXT_NODE
|
|
@@ -372,15 +372,15 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
372
372
|
|
|
373
373
|
underline: createCommand('Underline', (state) => {
|
|
374
374
|
const selectionInfo = getCurrentSelection(state)
|
|
375
|
-
if (!selectionInfo) return
|
|
375
|
+
if (!selectionInfo) {return}
|
|
376
376
|
|
|
377
377
|
let { range, selection } = selectionInfo
|
|
378
378
|
|
|
379
379
|
// If no text is selected, try to apply formatting to word at cursor
|
|
380
380
|
if (range.collapsed) {
|
|
381
381
|
const success = applyFormattingToWordAtCursor(state.doc!, range, 'u')
|
|
382
|
-
if (success) return
|
|
383
|
-
|
|
382
|
+
if (success) {return}
|
|
383
|
+
return
|
|
384
384
|
}
|
|
385
385
|
|
|
386
386
|
// Check if the selection is already underlined
|
|
@@ -429,7 +429,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
429
429
|
}, (state) => {
|
|
430
430
|
// isActive function for underline
|
|
431
431
|
const selectionInfo = getCurrentSelection(state)
|
|
432
|
-
if (!selectionInfo) return false
|
|
432
|
+
if (!selectionInfo) {return false}
|
|
433
433
|
|
|
434
434
|
const commonAncestor = selectionInfo.range.commonAncestorContainer
|
|
435
435
|
const parentElement = commonAncestor.nodeType === Node.TEXT_NODE
|
|
@@ -447,7 +447,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
447
447
|
}, (state) => {
|
|
448
448
|
// isActive function for link
|
|
449
449
|
const selectionInfo = getCurrentSelection(state)
|
|
450
|
-
if (!selectionInfo) return false
|
|
450
|
+
if (!selectionInfo) {return false}
|
|
451
451
|
|
|
452
452
|
const commonAncestor = selectionInfo.range.commonAncestorContainer
|
|
453
453
|
const parentElement = commonAncestor.nodeType === Node.TEXT_NODE
|
|
@@ -463,11 +463,11 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
463
463
|
...acc,
|
|
464
464
|
[cmd]: createCommand(`Heading ${cmd}`, (state) => {
|
|
465
465
|
const selectionInfo = getCurrentSelection(state)
|
|
466
|
-
if (!selectionInfo) return
|
|
466
|
+
if (!selectionInfo) {return}
|
|
467
467
|
|
|
468
468
|
const { range, selection } = selectionInfo
|
|
469
469
|
const currentBlock = findBlockElement(range.commonAncestorContainer)
|
|
470
|
-
if (!currentBlock) return
|
|
470
|
+
if (!currentBlock) {return}
|
|
471
471
|
|
|
472
472
|
// Store the original selection information before modification
|
|
473
473
|
const startContainer = range.startContainer
|
|
@@ -497,7 +497,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
497
497
|
|
|
498
498
|
// Find corresponding nodes in the new block
|
|
499
499
|
const findCorrespondingNode = (originalNode: Node, originalBlock: Element, newBlock: Element): Node | null => {
|
|
500
|
-
if (originalNode === originalBlock) return newBlock
|
|
500
|
+
if (originalNode === originalBlock) {return newBlock}
|
|
501
501
|
|
|
502
502
|
// If it's a text node, find it by traversing the tree
|
|
503
503
|
if (originalNode.nodeType === Node.TEXT_NODE) {
|
|
@@ -600,14 +600,14 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
600
600
|
const blockCommands = {
|
|
601
601
|
p: createCommand('Paragraph', (state) => {
|
|
602
602
|
const selectionInfo = getCurrentSelection(state)
|
|
603
|
-
if (!selectionInfo) return
|
|
603
|
+
if (!selectionInfo) {return}
|
|
604
604
|
|
|
605
605
|
const { range } = selectionInfo
|
|
606
606
|
const currentBlock = findBlockElement(range.commonAncestorContainer)
|
|
607
|
-
if (!currentBlock) return
|
|
607
|
+
if (!currentBlock) {return}
|
|
608
608
|
|
|
609
609
|
// Check if already a paragraph - if so, nothing to do
|
|
610
|
-
if (currentBlock.tagName.toLowerCase()
|
|
610
|
+
if ('p' === currentBlock.tagName.toLowerCase()) {
|
|
611
611
|
return
|
|
612
612
|
}
|
|
613
613
|
|
|
@@ -634,14 +634,14 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
634
634
|
|
|
635
635
|
blockquote: createCommand('Blockquote', (state) => {
|
|
636
636
|
const selectionInfo = getCurrentSelection(state)
|
|
637
|
-
if (!selectionInfo) return
|
|
637
|
+
if (!selectionInfo) {return}
|
|
638
638
|
|
|
639
639
|
const { range } = selectionInfo
|
|
640
640
|
const currentBlock = findBlockElement(range.commonAncestorContainer)
|
|
641
|
-
if (!currentBlock) return
|
|
641
|
+
if (!currentBlock) {return}
|
|
642
642
|
|
|
643
643
|
// Check if already a blockquote - if so, toggle to paragraph
|
|
644
|
-
const isToggleOff = currentBlock.tagName.toLowerCase()
|
|
644
|
+
const isToggleOff = 'blockquote' === currentBlock.tagName.toLowerCase()
|
|
645
645
|
const newTag = isToggleOff ? 'p' : 'blockquote'
|
|
646
646
|
|
|
647
647
|
try {
|
|
@@ -670,20 +670,20 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
670
670
|
const listCommands = {
|
|
671
671
|
orderedList: createCommand('Ordered List', (state) => {
|
|
672
672
|
const selectionInfo = getCurrentSelection(state)
|
|
673
|
-
if (!selectionInfo) return
|
|
673
|
+
if (!selectionInfo) {return}
|
|
674
674
|
|
|
675
675
|
const { range } = selectionInfo
|
|
676
676
|
const currentBlock = findBlockElement(range.commonAncestorContainer)
|
|
677
|
-
if (!currentBlock) return
|
|
677
|
+
if (!currentBlock) {return}
|
|
678
678
|
|
|
679
679
|
// Check if we're inside a list item
|
|
680
680
|
const listItem = currentBlock.closest('li')
|
|
681
681
|
if (listItem) {
|
|
682
682
|
const listParent = listItem.parentElement as HTMLElement
|
|
683
|
-
if (!listParent) return
|
|
683
|
+
if (!listParent) {return}
|
|
684
684
|
|
|
685
685
|
// If it's already an ordered list, toggle off to paragraph
|
|
686
|
-
if (listParent.tagName.toLowerCase()
|
|
686
|
+
if ('ol' === listParent.tagName.toLowerCase()) {
|
|
687
687
|
const p = state.doc!.createElement('p')
|
|
688
688
|
while (listItem.firstChild) {
|
|
689
689
|
p.appendChild(listItem.firstChild)
|
|
@@ -703,7 +703,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
703
703
|
}
|
|
704
704
|
|
|
705
705
|
// Convert unordered list to ordered list
|
|
706
|
-
if (listParent.tagName.toLowerCase()
|
|
706
|
+
if ('ul' === listParent.tagName.toLowerCase()) {
|
|
707
707
|
const ol = state.doc!.createElement('ol')
|
|
708
708
|
|
|
709
709
|
// Store current cursor position before conversion
|
|
@@ -762,20 +762,20 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
762
762
|
|
|
763
763
|
unorderedList: createCommand('Unordered List', (state) => {
|
|
764
764
|
const selectionInfo = getCurrentSelection(state)
|
|
765
|
-
if (!selectionInfo) return
|
|
765
|
+
if (!selectionInfo) {return}
|
|
766
766
|
|
|
767
767
|
const { range } = selectionInfo
|
|
768
768
|
const currentBlock = findBlockElement(range.commonAncestorContainer)
|
|
769
|
-
if (!currentBlock) return
|
|
769
|
+
if (!currentBlock) {return}
|
|
770
770
|
|
|
771
771
|
// Check if we're inside a list item
|
|
772
772
|
const listItem = currentBlock.closest('li')
|
|
773
773
|
if (listItem) {
|
|
774
774
|
const listParent = listItem.parentElement as HTMLElement
|
|
775
|
-
if (!listParent) return
|
|
775
|
+
if (!listParent) {return}
|
|
776
776
|
|
|
777
777
|
// If it's already an unordered list, toggle off to paragraph
|
|
778
|
-
if (listParent.tagName.toLowerCase()
|
|
778
|
+
if ('ul' === listParent.tagName.toLowerCase()) {
|
|
779
779
|
const p = state.doc!.createElement('p')
|
|
780
780
|
while (listItem.firstChild) {
|
|
781
781
|
p.appendChild(listItem.firstChild)
|
|
@@ -795,7 +795,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
795
795
|
}
|
|
796
796
|
|
|
797
797
|
// Convert ordered list to unordered list
|
|
798
|
-
if (listParent.tagName.toLowerCase()
|
|
798
|
+
if ('ol' === listParent.tagName.toLowerCase()) {
|
|
799
799
|
const ul = state.doc!.createElement('ul')
|
|
800
800
|
|
|
801
801
|
// Store current cursor position before conversion
|
|
@@ -858,7 +858,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
858
858
|
const formatCommands = {
|
|
859
859
|
clear: createCommand('Clear Formatting', (state) => {
|
|
860
860
|
const selectionInfo = getCurrentSelection(state)
|
|
861
|
-
if (!selectionInfo) return
|
|
861
|
+
if (!selectionInfo) {return}
|
|
862
862
|
|
|
863
863
|
const { range, selection } = selectionInfo
|
|
864
864
|
|
|
@@ -895,7 +895,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
895
895
|
// For formatting elements, just return the cleaned text content
|
|
896
896
|
const cleanedText = cleanText(element.textContent || '')
|
|
897
897
|
return state.doc!.createTextNode(cleanedText)
|
|
898
|
-
}
|
|
898
|
+
}if (structuralTags.includes(tagName)) {
|
|
899
899
|
// For structural elements, keep the element but remove all styling attributes
|
|
900
900
|
const cleanElement = state.doc!.createElement(tagName)
|
|
901
901
|
|
|
@@ -1080,7 +1080,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1080
1080
|
...acc,
|
|
1081
1081
|
[`tableAlign${align}`]: createCommand(`Table Align ${align}`, state => {
|
|
1082
1082
|
if (state.range) {
|
|
1083
|
-
const alignment =
|
|
1083
|
+
const alignment = 'Left' === align ? 'start' : 'Right' === align ? 'end' : align.toLowerCase() as 'center' | 'justify'
|
|
1084
1084
|
return alignColumn(state.range, alignment)
|
|
1085
1085
|
}
|
|
1086
1086
|
})
|
|
@@ -1090,7 +1090,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1090
1090
|
const textAlignmentCommands = {
|
|
1091
1091
|
alignLeft: createCommand('Align Left', (state) => {
|
|
1092
1092
|
const selectionInfo = getCurrentSelection(state)
|
|
1093
|
-
if (!selectionInfo) return
|
|
1093
|
+
if (!selectionInfo) {return}
|
|
1094
1094
|
|
|
1095
1095
|
const { range } = selectionInfo
|
|
1096
1096
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1102,19 +1102,19 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1102
1102
|
}
|
|
1103
1103
|
}, (state) => {
|
|
1104
1104
|
const selectionInfo = getCurrentSelection(state)
|
|
1105
|
-
if (!selectionInfo) return false
|
|
1105
|
+
if (!selectionInfo) {return false}
|
|
1106
1106
|
|
|
1107
1107
|
const { range } = selectionInfo
|
|
1108
1108
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1109
1109
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1110
1110
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1111
1111
|
|
|
1112
|
-
return (paragraph as HTMLElement)?.style.textAlign
|
|
1112
|
+
return 'left' === (paragraph as HTMLElement)?.style.textAlign
|
|
1113
1113
|
}),
|
|
1114
1114
|
|
|
1115
1115
|
alignCenter: createCommand('Align Center', (state) => {
|
|
1116
1116
|
const selectionInfo = getCurrentSelection(state)
|
|
1117
|
-
if (!selectionInfo) return
|
|
1117
|
+
if (!selectionInfo) {return}
|
|
1118
1118
|
|
|
1119
1119
|
const { range } = selectionInfo
|
|
1120
1120
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1126,19 +1126,19 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1126
1126
|
}
|
|
1127
1127
|
}, (state) => {
|
|
1128
1128
|
const selectionInfo = getCurrentSelection(state)
|
|
1129
|
-
if (!selectionInfo) return false
|
|
1129
|
+
if (!selectionInfo) {return false}
|
|
1130
1130
|
|
|
1131
1131
|
const { range } = selectionInfo
|
|
1132
1132
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1133
1133
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1134
1134
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1135
1135
|
|
|
1136
|
-
return (paragraph as HTMLElement)?.style.textAlign
|
|
1136
|
+
return 'center' === (paragraph as HTMLElement)?.style.textAlign
|
|
1137
1137
|
}),
|
|
1138
1138
|
|
|
1139
1139
|
alignRight: createCommand('Align Right', (state) => {
|
|
1140
1140
|
const selectionInfo = getCurrentSelection(state)
|
|
1141
|
-
if (!selectionInfo) return
|
|
1141
|
+
if (!selectionInfo) {return}
|
|
1142
1142
|
|
|
1143
1143
|
const { range } = selectionInfo
|
|
1144
1144
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1150,19 +1150,19 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1150
1150
|
}
|
|
1151
1151
|
}, (state) => {
|
|
1152
1152
|
const selectionInfo = getCurrentSelection(state)
|
|
1153
|
-
if (!selectionInfo) return false
|
|
1153
|
+
if (!selectionInfo) {return false}
|
|
1154
1154
|
|
|
1155
1155
|
const { range } = selectionInfo
|
|
1156
1156
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1157
1157
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1158
1158
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1159
1159
|
|
|
1160
|
-
return (paragraph as HTMLElement)?.style.textAlign
|
|
1160
|
+
return 'right' === (paragraph as HTMLElement)?.style.textAlign
|
|
1161
1161
|
}),
|
|
1162
1162
|
|
|
1163
1163
|
alignJustify: createCommand('Align Justify', (state) => {
|
|
1164
1164
|
const selectionInfo = getCurrentSelection(state)
|
|
1165
|
-
if (!selectionInfo) return
|
|
1165
|
+
if (!selectionInfo) {return}
|
|
1166
1166
|
|
|
1167
1167
|
const { range } = selectionInfo
|
|
1168
1168
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1174,19 +1174,19 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1174
1174
|
}
|
|
1175
1175
|
}, (state) => {
|
|
1176
1176
|
const selectionInfo = getCurrentSelection(state)
|
|
1177
|
-
if (!selectionInfo) return false
|
|
1177
|
+
if (!selectionInfo) {return false}
|
|
1178
1178
|
|
|
1179
1179
|
const { range } = selectionInfo
|
|
1180
1180
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1181
1181
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1182
1182
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1183
1183
|
|
|
1184
|
-
return (paragraph as HTMLElement)?.style.textAlign
|
|
1184
|
+
return 'justify' === (paragraph as HTMLElement)?.style.textAlign
|
|
1185
1185
|
}),
|
|
1186
1186
|
|
|
1187
1187
|
textDirection: createCommand('Toggle Text Direction', (state) => {
|
|
1188
1188
|
const selectionInfo = getCurrentSelection(state)
|
|
1189
|
-
if (!selectionInfo) return
|
|
1189
|
+
if (!selectionInfo) {return}
|
|
1190
1190
|
|
|
1191
1191
|
const { range } = selectionInfo
|
|
1192
1192
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1195,23 +1195,23 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1195
1195
|
|
|
1196
1196
|
if (paragraph) {
|
|
1197
1197
|
const currentDir = (paragraph as HTMLElement).dir || 'ltr'
|
|
1198
|
-
; (paragraph as HTMLElement).dir =
|
|
1198
|
+
; (paragraph as HTMLElement).dir = 'ltr' === currentDir ? 'rtl' : 'ltr'
|
|
1199
1199
|
}
|
|
1200
1200
|
}, (state) => {
|
|
1201
1201
|
const selectionInfo = getCurrentSelection(state)
|
|
1202
|
-
if (!selectionInfo) return false
|
|
1202
|
+
if (!selectionInfo) {return false}
|
|
1203
1203
|
|
|
1204
1204
|
const { range } = selectionInfo
|
|
1205
1205
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1206
1206
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1207
1207
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1208
1208
|
|
|
1209
|
-
return (paragraph as HTMLElement)?.dir
|
|
1209
|
+
return 'rtl' === (paragraph as HTMLElement)?.dir
|
|
1210
1210
|
}),
|
|
1211
1211
|
|
|
1212
1212
|
ltrDirection: createCommand('Set Left to Right Direction', (state) => {
|
|
1213
1213
|
const selectionInfo = getCurrentSelection(state)
|
|
1214
|
-
if (!selectionInfo) return
|
|
1214
|
+
if (!selectionInfo) {return}
|
|
1215
1215
|
|
|
1216
1216
|
const { range } = selectionInfo
|
|
1217
1217
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1223,19 +1223,19 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1223
1223
|
}
|
|
1224
1224
|
}, (state) => {
|
|
1225
1225
|
const selectionInfo = getCurrentSelection(state)
|
|
1226
|
-
if (!selectionInfo) return false
|
|
1226
|
+
if (!selectionInfo) {return false}
|
|
1227
1227
|
|
|
1228
1228
|
const { range } = selectionInfo
|
|
1229
1229
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1230
1230
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1231
1231
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1232
1232
|
|
|
1233
|
-
return (paragraph as HTMLElement)?.dir
|
|
1233
|
+
return 'ltr' === (paragraph as HTMLElement)?.dir
|
|
1234
1234
|
}),
|
|
1235
1235
|
|
|
1236
1236
|
rtlDirection: createCommand('Set Right to Left Direction', (state) => {
|
|
1237
1237
|
const selectionInfo = getCurrentSelection(state)
|
|
1238
|
-
if (!selectionInfo) return
|
|
1238
|
+
if (!selectionInfo) {return}
|
|
1239
1239
|
|
|
1240
1240
|
const { range } = selectionInfo
|
|
1241
1241
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
@@ -1247,14 +1247,14 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
1247
1247
|
}
|
|
1248
1248
|
}, (state) => {
|
|
1249
1249
|
const selectionInfo = getCurrentSelection(state)
|
|
1250
|
-
if (!selectionInfo) return false
|
|
1250
|
+
if (!selectionInfo) {return false}
|
|
1251
1251
|
|
|
1252
1252
|
const { range } = selectionInfo
|
|
1253
1253
|
const paragraph = range.startContainer.nodeType === Node.TEXT_NODE
|
|
1254
1254
|
? range.startContainer.parentElement?.closest('p, h1, h2, h3, h4, h5, h6')
|
|
1255
1255
|
: (range.startContainer as Element).closest('p, h1, h2, h3, h4, h5, h6')
|
|
1256
1256
|
|
|
1257
|
-
return (paragraph as HTMLElement)?.dir
|
|
1257
|
+
return 'rtl' === (paragraph as HTMLElement)?.dir
|
|
1258
1258
|
})
|
|
1259
1259
|
}
|
|
1260
1260
|
|
|
@@ -50,7 +50,7 @@ export class EditorDebugger {
|
|
|
50
50
|
|
|
51
51
|
private getNodeDescription(node: Node): string {
|
|
52
52
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
53
|
-
return `Text("${node.textContent?.slice(0, 20)}${node.textContent && node.textContent.length
|
|
53
|
+
return `Text("${node.textContent?.slice(0, 20)}${node.textContent && 20 < node.textContent.length ? '...' : ''}")`
|
|
54
54
|
}
|
|
55
55
|
const element = node as Element
|
|
56
56
|
return `${element.tagName.toLowerCase()}${element.id ? `#${element.id}` : ''}`
|