@bagelink/vue 1.20.23 → 1.20.27
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/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/selection.d.ts +6 -0
- package/dist/components/form/inputs/RichText/utils/selection.d.ts.map +1 -1
- package/dist/core.css +1 -1
- package/dist/index.cjs +51 -51
- package/dist/index.css +1 -1
- package/dist/index.mjs +11737 -11611
- package/dist/style.css +1 -1
- package/package.json +2 -2
- package/src/components/form/inputs/RichText/components/EditorToolbar.vue +25 -0
- package/src/components/form/inputs/RichText/index.vue +50 -6
- package/src/components/form/inputs/RichText/richTextTypes.ts +1 -0
- package/src/components/form/inputs/RichText/utils/commands.ts +97 -2
- package/src/components/form/inputs/RichText/utils/selection.ts +28 -4
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bagelink/vue",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.20.
|
|
4
|
+
"version": "1.20.27",
|
|
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.
|
|
66
|
+
"@bagelink/sdk": "1.20.27"
|
|
67
67
|
},
|
|
68
68
|
"peerDependencies": {
|
|
69
69
|
"@bagelink/sdk": "*",
|
|
@@ -388,6 +388,31 @@ onBeforeUnmount(() => {
|
|
|
388
388
|
</template>
|
|
389
389
|
</Dropdown>
|
|
390
390
|
|
|
391
|
+
<!-- Link: add/edit action plus a remove action while inside a link -->
|
|
392
|
+
<template v-else-if="action.name === 'link' && !shouldHideAction('link')">
|
|
393
|
+
<Btn
|
|
394
|
+
:icon="action.icon || 'add_link'"
|
|
395
|
+
thin
|
|
396
|
+
flat
|
|
397
|
+
:class="[action.class, { active: selectedStyles.has('link') }]"
|
|
398
|
+
:aria-label="getActionLabel(action)"
|
|
399
|
+
:aria-pressed="selectedStyles.has('link')"
|
|
400
|
+
:title="getActionLabel(action)"
|
|
401
|
+
v-tooltip="getActionLabel(action)"
|
|
402
|
+
@click="runAction('link')"
|
|
403
|
+
/>
|
|
404
|
+
<Btn
|
|
405
|
+
v-if="selectedStyles.has('link')"
|
|
406
|
+
icon="link_off"
|
|
407
|
+
thin
|
|
408
|
+
flat
|
|
409
|
+
aria-label="Remove link"
|
|
410
|
+
title="Remove link"
|
|
411
|
+
v-tooltip="'Remove link'"
|
|
412
|
+
@click="runAction('unlink')"
|
|
413
|
+
/>
|
|
414
|
+
</template>
|
|
415
|
+
|
|
391
416
|
<!-- All other buttons -->
|
|
392
417
|
<Btn
|
|
393
418
|
v-else-if="action.name !== 'separator'
|
|
@@ -186,6 +186,16 @@ const editor = useEditor()
|
|
|
186
186
|
const isInitializing = ref(false)
|
|
187
187
|
const hasInitialized = ref(false)
|
|
188
188
|
const commands = useCommands(editor.state, editor.state.debug)
|
|
189
|
+
|
|
190
|
+
// Toolbar highlight state: selection styles plus the view toggles, which live in
|
|
191
|
+
// the editor state rather than the DOM and are never reported by computeActiveStyles.
|
|
192
|
+
const toolbarStyles = computed(() => {
|
|
193
|
+
const styles = new Set(editor.state.selectedStyles)
|
|
194
|
+
if (editor.state.isSplitView) { styles.add('splitView') }
|
|
195
|
+
if (editor.state.isCodeView) { styles.add('codeView') }
|
|
196
|
+
if (editor.state.isFullscreen) { styles.add('fullScreen') }
|
|
197
|
+
return styles
|
|
198
|
+
})
|
|
189
199
|
const documentMetrics = computed(() => {
|
|
190
200
|
void editor.state.content
|
|
191
201
|
return getRichTextMetrics(normalizedModelValue.value, editor.state.doc)
|
|
@@ -731,6 +741,10 @@ function showTooltipMessage(message: string, x?: number, y?: number) {
|
|
|
731
741
|
}
|
|
732
742
|
|
|
733
743
|
// Function to open link modal
|
|
744
|
+
function isEditingExistingLink(): boolean {
|
|
745
|
+
return Boolean(pendingLinkData?.existingLink)
|
|
746
|
+
}
|
|
747
|
+
|
|
734
748
|
function openLinkModal(selection: Selection, range: Range, existingLink: HTMLAnchorElement | null) {
|
|
735
749
|
pendingLinkData = { selection, range, existingLink }
|
|
736
750
|
linkForm.value = {
|
|
@@ -802,6 +816,27 @@ function submitLink() {
|
|
|
802
816
|
pendingLinkData = null
|
|
803
817
|
}
|
|
804
818
|
|
|
819
|
+
// Function to remove the link being edited, keeping its text and formatting
|
|
820
|
+
function removePendingLink() {
|
|
821
|
+
const existingLink = pendingLinkData?.existingLink
|
|
822
|
+
const { doc } = editor.state
|
|
823
|
+
if (!existingLink || !doc) { return }
|
|
824
|
+
|
|
825
|
+
const parent = existingLink.parentNode
|
|
826
|
+
if (parent) {
|
|
827
|
+
while (existingLink.firstChild) {
|
|
828
|
+
parent.insertBefore(existingLink.firstChild, existingLink)
|
|
829
|
+
}
|
|
830
|
+
existingLink.remove()
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
updateContentWithHistory(doc)
|
|
834
|
+
editor.updateState.styles()
|
|
835
|
+
updateCustomToolbarStyles()
|
|
836
|
+
showLinkModal.value = false
|
|
837
|
+
pendingLinkData = null
|
|
838
|
+
}
|
|
839
|
+
|
|
805
840
|
// Function to visit link
|
|
806
841
|
function visitLink() {
|
|
807
842
|
if (!linkForm.value.url || !isValidUrl(linkForm.value.url)) { return }
|
|
@@ -3762,7 +3797,7 @@ const imgTransform = computed({
|
|
|
3762
3797
|
>
|
|
3763
3798
|
<EditorToolbar
|
|
3764
3799
|
v-if="editor.state.hasInit && shouldShowToolbar" :config="effectiveToolbarConfig"
|
|
3765
|
-
:selectedStyles="
|
|
3800
|
+
:selectedStyles="toolbarStyles" :hide-images="hideImages" :hide-videos="hideVideos"
|
|
3766
3801
|
:hide-embeds="hideEmbed" :hide-tables="hideTables" :hide-alignment="hideAlignment"
|
|
3767
3802
|
:hide-directions="hideDirections" :hide-h5-h6="hideH5H6" :hide="effectiveHideArray"
|
|
3768
3803
|
:document-colors="documentColors"
|
|
@@ -3777,8 +3812,8 @@ const imgTransform = computed({
|
|
|
3777
3812
|
:icon="button.icon"
|
|
3778
3813
|
:value="button.value"
|
|
3779
3814
|
:aria-label="button.label"
|
|
3780
|
-
:class="[button.class, { active:
|
|
3781
|
-
:aria-pressed="
|
|
3815
|
+
:class="[button.class, { active: toolbarStyles.has(button.name) }]"
|
|
3816
|
+
:aria-pressed="toolbarStyles.has(button.name)"
|
|
3782
3817
|
thin
|
|
3783
3818
|
flat
|
|
3784
3819
|
tabindex="-1"
|
|
@@ -3857,11 +3892,16 @@ const imgTransform = computed({
|
|
|
3857
3892
|
/>
|
|
3858
3893
|
<Btn
|
|
3859
3894
|
thin flat icon="format_underlined"
|
|
3860
|
-
:class="{ active:
|
|
3895
|
+
:class="{ active: toolbarStyles.has('underline') }"
|
|
3861
3896
|
@click="runInlineAction('underline')"
|
|
3862
3897
|
/>
|
|
3863
3898
|
<Divider vertical size="1.25rem" class="mx-0125" />
|
|
3864
3899
|
<Btn thin flat icon="add_link" @click="runInlineAction('link')" />
|
|
3900
|
+
<Btn
|
|
3901
|
+
v-if="toolbarStyles.has('link')" thin flat icon="link_off" aria-label="Remove link"
|
|
3902
|
+
title="Remove link"
|
|
3903
|
+
@click="runInlineAction('unlink')"
|
|
3904
|
+
/>
|
|
3865
3905
|
</div>
|
|
3866
3906
|
</div>
|
|
3867
3907
|
<!-- Table Context Menu (built on shared ContextMenu / Dropdown) -->
|
|
@@ -3875,7 +3915,7 @@ const imgTransform = computed({
|
|
|
3875
3915
|
</div>
|
|
3876
3916
|
<!-- Link Modal -->
|
|
3877
3917
|
<Dialog
|
|
3878
|
-
:open="showLinkModal" :title="
|
|
3918
|
+
:open="showLinkModal" :title="isEditingExistingLink() ? 'Edit Link' : 'Add Link'"
|
|
3879
3919
|
width="s" @update:open="showLinkModal = $event"
|
|
3880
3920
|
>
|
|
3881
3921
|
<div class="flex gap-05 align-items-end">
|
|
@@ -3893,7 +3933,11 @@ const imgTransform = computed({
|
|
|
3893
3933
|
<template #footer>
|
|
3894
3934
|
<Btn value="Cancel" flat thin @click="showLinkModal = false" />
|
|
3895
3935
|
<Btn
|
|
3896
|
-
|
|
3936
|
+
v-if="isEditingExistingLink()" value="Remove Link" flat thin icon="link_off"
|
|
3937
|
+
color="red" @click="removePendingLink"
|
|
3938
|
+
/>
|
|
3939
|
+
<Btn
|
|
3940
|
+
:value="isEditingExistingLink() ? 'Update Link' : 'Add Link'"
|
|
3897
3941
|
:disabled="!isValidUrl(linkForm.url)" @click="submitLink"
|
|
3898
3942
|
/>
|
|
3899
3943
|
</template>
|
|
@@ -496,6 +496,96 @@ function toggleInlineFormatting(
|
|
|
496
496
|
}
|
|
497
497
|
}
|
|
498
498
|
|
|
499
|
+
function getAnchorForRange(range: Range): HTMLAnchorElement | null {
|
|
500
|
+
const container = range.commonAncestorContainer
|
|
501
|
+
const element = container.nodeType === Node.TEXT_NODE ? container.parentElement : container as Element | null
|
|
502
|
+
return element?.closest('a') as HTMLAnchorElement | null
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
function getAnchorsInRange(doc: Document, range: Range): HTMLAnchorElement[] {
|
|
506
|
+
if (range.collapsed) {
|
|
507
|
+
const anchor = getAnchorForRange(range)
|
|
508
|
+
return anchor ? [anchor] : []
|
|
509
|
+
}
|
|
510
|
+
return Array.from(doc.body.querySelectorAll<HTMLAnchorElement>('a'))
|
|
511
|
+
.filter(anchor => rangeOverlapsNodeContent(range, anchor))
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
function isAnchorUnderlined(anchor: HTMLElement): boolean {
|
|
515
|
+
// Inline declaration wins: it is the override this command toggles.
|
|
516
|
+
const inline = `${anchor.style.textDecorationLine} ${anchor.style.textDecoration}`.trim()
|
|
517
|
+
if (inline) { return /underline/.test(inline) }
|
|
518
|
+
|
|
519
|
+
const style = anchor.ownerDocument?.defaultView?.getComputedStyle(anchor)
|
|
520
|
+
const computed = `${style?.textDecorationLine ?? ''} ${style?.textDecoration ?? ''}`.trim()
|
|
521
|
+
if (computed) { return /underline/.test(computed) }
|
|
522
|
+
|
|
523
|
+
// Links are underlined by the browser stylesheet unless a rule says otherwise.
|
|
524
|
+
return true
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
/**
|
|
528
|
+
* Cancels the underline that a link inherits from the browser stylesheet.
|
|
529
|
+
* The declaration has to live on the `<a>` itself — `text-decoration` propagates
|
|
530
|
+
* from the anchor to its descendants and cannot be unset from a child element.
|
|
531
|
+
*/
|
|
532
|
+
function setAnchorUnderlined(anchor: HTMLAnchorElement, underlined: boolean) {
|
|
533
|
+
if (underlined) {
|
|
534
|
+
anchor.style.removeProperty('text-decoration')
|
|
535
|
+
if (!anchor.getAttribute('style')?.trim()) {
|
|
536
|
+
anchor.removeAttribute('style')
|
|
537
|
+
}
|
|
538
|
+
return
|
|
539
|
+
}
|
|
540
|
+
anchor.style.setProperty('text-decoration', 'none', 'important')
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
function unwrapElement(element: Element) {
|
|
544
|
+
const parent = element.parentNode
|
|
545
|
+
if (!parent) { return }
|
|
546
|
+
while (element.firstChild) {
|
|
547
|
+
parent.insertBefore(element.firstChild, element)
|
|
548
|
+
}
|
|
549
|
+
element.remove()
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
/**
|
|
553
|
+
* Underline toggle aware of CSS-driven underlines. Inside a link the underline
|
|
554
|
+
* comes from CSS, so it is toggled on the anchor instead of wrapping a `<u>`.
|
|
555
|
+
*/
|
|
556
|
+
function toggleUnderline(state: EditorState) {
|
|
557
|
+
const selectionInfo = getCurrentSelection(state)
|
|
558
|
+
if (!selectionInfo || !state.doc) { return }
|
|
559
|
+
|
|
560
|
+
const { doc } = state
|
|
561
|
+
const { range } = selectionInfo
|
|
562
|
+
|
|
563
|
+
const container = range.commonAncestorContainer
|
|
564
|
+
const element = container.nodeType === Node.TEXT_NODE ? container.parentElement : container as Element | null
|
|
565
|
+
|
|
566
|
+
// An explicit <u> wrapper always wins: clicking again unwraps it.
|
|
567
|
+
if (element?.closest('u')) {
|
|
568
|
+
toggleInlineFormatting(state, 'u', 'u')
|
|
569
|
+
return
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
const anchors = getAnchorsInRange(doc, range).filter(anchor => !anchor.closest('figure'))
|
|
573
|
+
if (anchors.length) {
|
|
574
|
+
anchors.forEach(anchor => setAnchorUnderlined(anchor, !isAnchorUnderlined(anchor)))
|
|
575
|
+
return
|
|
576
|
+
}
|
|
577
|
+
|
|
578
|
+
toggleInlineFormatting(state, 'u', 'u')
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
function removeLink(state: EditorState) {
|
|
582
|
+
const selectionInfo = getCurrentSelection(state)
|
|
583
|
+
if (!selectionInfo || !state.doc) { return }
|
|
584
|
+
|
|
585
|
+
const anchors = getAnchorsInRange(state.doc, selectionInfo.range)
|
|
586
|
+
anchors.forEach(unwrapElement)
|
|
587
|
+
}
|
|
588
|
+
|
|
499
589
|
function applyInlineStyle(state: EditorState, property: string, value: string) {
|
|
500
590
|
const selectionInfo = getCurrentSelection(state)
|
|
501
591
|
if (!selectionInfo || !state.doc || !value) { return }
|
|
@@ -935,7 +1025,7 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
935
1025
|
),
|
|
936
1026
|
underline: createCommand(
|
|
937
1027
|
'Underline',
|
|
938
|
-
s =>
|
|
1028
|
+
s => toggleUnderline(s),
|
|
939
1029
|
s => Boolean(s.doc && isStyleActive('underline', s.doc))
|
|
940
1030
|
),
|
|
941
1031
|
link: createCommand('Link', (s) => {
|
|
@@ -943,7 +1033,12 @@ export function createCommandRegistry(state: EditorState): CommandRegistry {
|
|
|
943
1033
|
if (openLinkModal) {
|
|
944
1034
|
insertLink(openLinkModal, s)
|
|
945
1035
|
}
|
|
946
|
-
}, s => Boolean(s.doc && isStyleActive('link', s.doc)), { skipHistory: true })
|
|
1036
|
+
}, s => Boolean(s.doc && isStyleActive('link', s.doc)), { skipHistory: true }),
|
|
1037
|
+
unlink: createCommand(
|
|
1038
|
+
'Remove Link',
|
|
1039
|
+
s => removeLink(s),
|
|
1040
|
+
s => Boolean(s.doc && isStyleActive('link', s.doc))
|
|
1041
|
+
)
|
|
947
1042
|
}
|
|
948
1043
|
|
|
949
1044
|
const headingCommands = ['h1', 'h2', 'h3', 'h4', 'h5', 'h6'].reduce<CommandRegistry>((acc, cmd) => ({
|
|
@@ -48,6 +48,32 @@ function getSelectedLeafBlocks(doc: Document, range: Range): HTMLElement[] {
|
|
|
48
48
|
.filter(block => rangeOverlapsNodeContent(range, block))
|
|
49
49
|
}
|
|
50
50
|
|
|
51
|
+
/**
|
|
52
|
+
* True when the element renders underlined text — either from an explicit
|
|
53
|
+
* `<u>` wrapper, an inline/class `text-decoration`, or the browser default
|
|
54
|
+
* underline on `<a>` (which never shows up as an inline declaration).
|
|
55
|
+
*/
|
|
56
|
+
export function isElementVisuallyUnderlined(element: Element): boolean {
|
|
57
|
+
const tagName = element.tagName?.toLowerCase()
|
|
58
|
+
if (tagName === 'u') { return true }
|
|
59
|
+
|
|
60
|
+
const inline = `${(element as HTMLElement).style?.textDecorationLine ?? ''} ${(element as HTMLElement).style?.textDecoration ?? ''}`.trim()
|
|
61
|
+
if (inline) { return /underline/.test(inline) }
|
|
62
|
+
|
|
63
|
+
try {
|
|
64
|
+
const view = element.ownerDocument?.defaultView
|
|
65
|
+
if (view) {
|
|
66
|
+
const style = view.getComputedStyle(element)
|
|
67
|
+
const decoration = `${style.textDecorationLine ?? ''} ${style.textDecoration ?? ''}`.trim()
|
|
68
|
+
if (decoration) { return /underline/.test(decoration) }
|
|
69
|
+
}
|
|
70
|
+
} catch {
|
|
71
|
+
// Ignore style resolution errors and fall through to the link default
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return tagName === 'a'
|
|
75
|
+
}
|
|
76
|
+
|
|
51
77
|
export function isStyleActive(style: string, doc: Document): boolean {
|
|
52
78
|
const selection = doc.getSelection()
|
|
53
79
|
if (!selection || !selection.rangeCount) { return false }
|
|
@@ -90,10 +116,8 @@ export function isStyleActive(style: string, doc: Document): boolean {
|
|
|
90
116
|
const tagName = el.tagName?.toLowerCase()
|
|
91
117
|
return tagName === 'em' || tagName === 'i'
|
|
92
118
|
},
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return tagName === 'u'
|
|
96
|
-
},
|
|
119
|
+
// `<u>` tags and CSS-driven underlines (e.g. the browser default on `<a>`)
|
|
120
|
+
underline: el => isElementVisuallyUnderlined(el),
|
|
97
121
|
link: (el) => {
|
|
98
122
|
return el.tagName?.toLowerCase() === 'a'
|
|
99
123
|
},
|