@zipify/wysiwyg 1.1.0 → 1.1.1-0
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/cli.js +2 -2
- package/dist/wysiwyg.css +11 -11
- package/dist/wysiwyg.mjs +36 -36
- package/lib/components/toolbar/controls/link/LinkControl.vue +5 -4
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +2 -2
- package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +1 -1
- package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +1 -1
- package/lib/components/toolbar/controls/link/composables/useLink.js +7 -5
- package/lib/enums/TextSettings.js +2 -0
- package/lib/extensions/FontStyle.js +2 -2
- package/lib/extensions/Link.js +13 -15
- package/lib/extensions/TextDecoration.js +12 -13
- package/lib/extensions/__tests__/FontFamily.test.js +7 -6
- package/lib/extensions/__tests__/FontWeight.test.js +11 -10
- package/lib/extensions/__tests__/TextDecoration.test.js +73 -42
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +18 -0
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +16 -0
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +0 -43
- package/package.json +1 -1
package/dist/wysiwyg.css
CHANGED
|
@@ -591,34 +591,34 @@
|
|
|
591
591
|
display: flex;
|
|
592
592
|
}
|
|
593
593
|
|
|
594
|
-
.zw-link-modal-header[data-v-
|
|
594
|
+
.zw-link-modal-header[data-v-aa42e2ce] {
|
|
595
595
|
display: flex;
|
|
596
596
|
align-items: center;
|
|
597
597
|
justify-content: space-between;
|
|
598
598
|
padding: var(--zw-offset-sm);
|
|
599
599
|
border-bottom: 2px solid rgb(var(--zw-color-n5));
|
|
600
600
|
}
|
|
601
|
-
.zw-link-modal-header__title[data-v-
|
|
601
|
+
.zw-link-modal-header__title[data-v-aa42e2ce] {
|
|
602
602
|
text-transform: uppercase;
|
|
603
603
|
font-weight: var(--zw-font-weight-semibold);
|
|
604
604
|
font-size: var(--zw-font-size-xxs);
|
|
605
605
|
color: rgb(var(--zw-color-white));
|
|
606
606
|
}
|
|
607
|
-
.zw-link-modal-header__unlink-icon[data-v-
|
|
607
|
+
.zw-link-modal-header__unlink-icon[data-v-aa42e2ce] {
|
|
608
608
|
margin-right: var(--zw-offset-xxs);
|
|
609
609
|
}
|
|
610
|
-
.zw-link-modal-header__unlink-button[data-v-
|
|
610
|
+
.zw-link-modal-header__unlink-button[data-v-aa42e2ce] {
|
|
611
611
|
color: rgb(var(--zw-color-n80));
|
|
612
612
|
font-size: var(--zw-font-size-xxs);
|
|
613
613
|
transition: 0.1s opacity ease-out, 0.1s color ease-out;
|
|
614
614
|
will-change: opacity, color;
|
|
615
615
|
}
|
|
616
|
-
.zw-link-modal-header__unlink-button[data-v-
|
|
616
|
+
.zw-link-modal-header__unlink-button[data-v-aa42e2ce]:disabled {
|
|
617
617
|
opacity: 0.35;
|
|
618
618
|
}
|
|
619
|
-
.zw-link-modal-header__unlink-button[data-v-
|
|
620
|
-
.zw-link-modal-header__unlink-button[data-v-
|
|
621
|
-
.zw-link-modal-header__unlink-button[data-v-
|
|
619
|
+
.zw-link-modal-header__unlink-button[data-v-aa42e2ce]:focus,
|
|
620
|
+
.zw-link-modal-header__unlink-button[data-v-aa42e2ce]:focus-within,
|
|
621
|
+
.zw-link-modal-header__unlink-button[data-v-aa42e2ce]:hover {
|
|
622
622
|
color: rgb(var(--zw-color-white));
|
|
623
623
|
}
|
|
624
624
|
|
|
@@ -627,13 +627,13 @@
|
|
|
627
627
|
justify-content: flex-end;
|
|
628
628
|
}
|
|
629
629
|
|
|
630
|
-
.zw-link-modal[data-v-
|
|
630
|
+
.zw-link-modal[data-v-74b3b43a] {
|
|
631
631
|
width: 266px;
|
|
632
632
|
}
|
|
633
|
-
.zw-link-modal__body[data-v-
|
|
633
|
+
.zw-link-modal__body[data-v-74b3b43a] {
|
|
634
634
|
padding: var(--zw-offset-sm);
|
|
635
635
|
}
|
|
636
|
-
[data-v-
|
|
636
|
+
[data-v-74b3b43a] .zw-link-modal-dropdown__option {
|
|
637
637
|
width: 234px;
|
|
638
638
|
}
|
|
639
639
|
|
package/dist/wysiwyg.mjs
CHANGED
|
@@ -13986,6 +13986,8 @@ const TextSettings = Object.freeze({
|
|
|
13986
13986
|
TEXT_DECORATION: "text_decoration",
|
|
13987
13987
|
SUPERSCRIPT: "superscript",
|
|
13988
13988
|
MARGIN: "margin",
|
|
13989
|
+
LINK: "link",
|
|
13990
|
+
STYLE_PRESET: "style_preset",
|
|
13989
13991
|
get attributes() {
|
|
13990
13992
|
return [
|
|
13991
13993
|
this.ALIGNMENT,
|
|
@@ -22088,7 +22090,7 @@ const __vue2_script$9 = {
|
|
|
22088
22090
|
components: { Icon, Button },
|
|
22089
22091
|
setup(_, { emit }) {
|
|
22090
22092
|
const editor = inject(InjectionTokens$1.EDITOR);
|
|
22091
|
-
const isLink =
|
|
22093
|
+
const isLink = editor.commands.isLink();
|
|
22092
22094
|
const removeLink = () => emit("remove-link");
|
|
22093
22095
|
return { isLink, removeLink };
|
|
22094
22096
|
}
|
|
@@ -22100,7 +22102,7 @@ var __component__$9 = /* @__PURE__ */ normalizeComponent(
|
|
|
22100
22102
|
staticRenderFns$9,
|
|
22101
22103
|
false,
|
|
22102
22104
|
__vue2_injectStyles$9,
|
|
22103
|
-
"
|
|
22105
|
+
"aa42e2ce",
|
|
22104
22106
|
null,
|
|
22105
22107
|
null
|
|
22106
22108
|
);
|
|
@@ -22175,11 +22177,12 @@ function useLink() {
|
|
|
22175
22177
|
linkData.value.target = isChecked ? LinkTargets.BLANK : LinkTargets.SELF;
|
|
22176
22178
|
}
|
|
22177
22179
|
function prepareInitialFields() {
|
|
22180
|
+
const link = editor.getAttributes(TextSettings.LINK);
|
|
22178
22181
|
linkData.value.text = editor.commands.getSelectedText();
|
|
22179
|
-
currentDestination.value.id =
|
|
22180
|
-
linkData.value.target =
|
|
22181
|
-
if (
|
|
22182
|
-
destinationHrefs.value[currentDestination.value.id] =
|
|
22182
|
+
currentDestination.value.id = link.destination || LinkDestinations.URL;
|
|
22183
|
+
linkData.value.target = link.target || LinkTargets.SELF;
|
|
22184
|
+
if (link.href) {
|
|
22185
|
+
destinationHrefs.value[currentDestination.value.id] = link.href;
|
|
22183
22186
|
}
|
|
22184
22187
|
}
|
|
22185
22188
|
function resetDestinations() {
|
|
@@ -22590,7 +22593,7 @@ const __vue2_script$4 = {
|
|
|
22590
22593
|
urlValidator.reset();
|
|
22591
22594
|
};
|
|
22592
22595
|
const onBeforeOpened = () => {
|
|
22593
|
-
editor.commands.extendMarkRange(
|
|
22596
|
+
editor.commands.extendMarkRange(TextSettings.LINK);
|
|
22594
22597
|
resetErrors();
|
|
22595
22598
|
link.prepareInitialFields();
|
|
22596
22599
|
};
|
|
@@ -22599,7 +22602,8 @@ const __vue2_script$4 = {
|
|
|
22599
22602
|
wrapperRef,
|
|
22600
22603
|
modalRef
|
|
22601
22604
|
});
|
|
22602
|
-
const
|
|
22605
|
+
const isLink = editor.commands.isLink();
|
|
22606
|
+
const isActive2 = computed(() => toggler.isOpened.value || unref(isLink));
|
|
22603
22607
|
const updateLinkText = (value) => {
|
|
22604
22608
|
resetErrors();
|
|
22605
22609
|
link.updateText(value);
|
|
@@ -22639,7 +22643,7 @@ var __component__$4 = /* @__PURE__ */ normalizeComponent(
|
|
|
22639
22643
|
staticRenderFns$4,
|
|
22640
22644
|
false,
|
|
22641
22645
|
__vue2_injectStyles$4,
|
|
22642
|
-
"
|
|
22646
|
+
"74b3b43a",
|
|
22643
22647
|
null,
|
|
22644
22648
|
null
|
|
22645
22649
|
);
|
|
@@ -23463,7 +23467,7 @@ const FontStyle = Mark.create({
|
|
|
23463
23467
|
commands2.setMark(this.name, { italic: true });
|
|
23464
23468
|
}),
|
|
23465
23469
|
removeItalic: createCommand(({ commands: commands2 }) => {
|
|
23466
|
-
commands2.
|
|
23470
|
+
commands2.setMark(this.name, { italic: false });
|
|
23467
23471
|
})
|
|
23468
23472
|
};
|
|
23469
23473
|
},
|
|
@@ -23489,21 +23493,22 @@ const FontStyle = Mark.create({
|
|
|
23489
23493
|
];
|
|
23490
23494
|
},
|
|
23491
23495
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
23492
|
-
const font_style = attrs.italic ? "italic" :
|
|
23496
|
+
const font_style = attrs.italic ? "italic" : "normal";
|
|
23493
23497
|
return renderMark({ font_style });
|
|
23494
23498
|
}
|
|
23495
23499
|
});
|
|
23496
23500
|
const TextDecoration = Mark.create({
|
|
23497
23501
|
name: TextSettings.TEXT_DECORATION,
|
|
23502
|
+
priority: 1e3,
|
|
23498
23503
|
addAttributes: () => ({
|
|
23499
23504
|
underline: { default: false },
|
|
23500
23505
|
strike_through: { default: false }
|
|
23501
23506
|
}),
|
|
23502
23507
|
addCommands() {
|
|
23503
23508
|
return {
|
|
23504
|
-
isUnderline: createCommand(({ commands: commands2
|
|
23509
|
+
isUnderline: createCommand(({ commands: commands2 }) => {
|
|
23505
23510
|
const decoration = commands2.getTextDecoration();
|
|
23506
|
-
return computed(() =>
|
|
23511
|
+
return computed(() => unref(decoration).underline);
|
|
23507
23512
|
}),
|
|
23508
23513
|
isStrikeThrough: createCommand(({ commands: commands2 }) => {
|
|
23509
23514
|
const decoration = commands2.getTextDecoration();
|
|
@@ -23522,17 +23527,20 @@ const TextDecoration = Mark.create({
|
|
|
23522
23527
|
}),
|
|
23523
23528
|
getDefaultTextDecoration: createCommand(({ commands: commands2 }) => {
|
|
23524
23529
|
const preset = commands2.getPreset();
|
|
23530
|
+
const isLink = commands2.isLink();
|
|
23531
|
+
const linkPreset = commands2.getLinkPreset();
|
|
23525
23532
|
return computed(() => {
|
|
23526
|
-
const decoration =
|
|
23533
|
+
const decoration = [
|
|
23534
|
+
unref(preset).common.text_decoration,
|
|
23535
|
+
unref(isLink) ? unref(linkPreset).common.text_decoration : ""
|
|
23536
|
+
].join(" ");
|
|
23527
23537
|
return {
|
|
23528
23538
|
underline: decoration.includes("underline"),
|
|
23529
23539
|
strike_through: decoration.includes("line-through")
|
|
23530
23540
|
};
|
|
23531
23541
|
});
|
|
23532
23542
|
}),
|
|
23533
|
-
toggleUnderline: createCommand(({ commands: commands2
|
|
23534
|
-
if (editor.isActive("link"))
|
|
23535
|
-
return;
|
|
23543
|
+
toggleUnderline: createCommand(({ commands: commands2 }) => {
|
|
23536
23544
|
commands2.toggleTextDecoration("underline");
|
|
23537
23545
|
}),
|
|
23538
23546
|
toggleStrikeThrough: createCommand(({ commands: commands2 }) => {
|
|
@@ -23546,12 +23554,7 @@ const TextDecoration = Mark.create({
|
|
|
23546
23554
|
commands2.setMark(this.name, { [name]: true });
|
|
23547
23555
|
}),
|
|
23548
23556
|
removeTextDecoration: createCommand(({ commands: commands2 }, name) => {
|
|
23549
|
-
|
|
23550
|
-
...unref(commands2.getTextDecoration()),
|
|
23551
|
-
[name]: false
|
|
23552
|
-
};
|
|
23553
|
-
const isRemoveMark = !mark.underline && !mark.strike_through;
|
|
23554
|
-
isRemoveMark ? commands2.unsetMark(this.name) : commands2.setMark(this.name, mark);
|
|
23557
|
+
commands2.setMark(this.name, { ...unref(commands2.getTextDecoration()), [name]: false });
|
|
23555
23558
|
})
|
|
23556
23559
|
};
|
|
23557
23560
|
},
|
|
@@ -23603,6 +23606,8 @@ const TextDecoration = Mark.create({
|
|
|
23603
23606
|
decorations.push("underline");
|
|
23604
23607
|
if (attrs.strike_through)
|
|
23605
23608
|
decorations.push("line-through");
|
|
23609
|
+
if (!decorations.length)
|
|
23610
|
+
decorations.push("none");
|
|
23606
23611
|
return renderMark({ text_decoration: decorations.join(" ") });
|
|
23607
23612
|
}
|
|
23608
23613
|
});
|
|
@@ -24866,7 +24871,7 @@ const Link$1 = Mark.create({
|
|
|
24866
24871
|
}
|
|
24867
24872
|
});
|
|
24868
24873
|
const Link = Link$1.extend({
|
|
24869
|
-
name:
|
|
24874
|
+
name: TextSettings.LINK,
|
|
24870
24875
|
addOptions() {
|
|
24871
24876
|
var _a;
|
|
24872
24877
|
return {
|
|
@@ -24909,19 +24914,14 @@ const Link = Link$1.extend({
|
|
|
24909
24914
|
...(_a = this.parent) == null ? void 0 : _a.call(this),
|
|
24910
24915
|
applyLink: createCommand(({ commands: commands2, chain }, attributes) => {
|
|
24911
24916
|
if (!commands2.getSelectedText()) {
|
|
24912
|
-
return commands2.insertContent(
|
|
24913
|
-
|
|
24914
|
-
|
|
24915
|
-
{
|
|
24916
|
-
type: "link",
|
|
24917
|
-
attrs: { ...attributes }
|
|
24918
|
-
}
|
|
24919
|
-
],
|
|
24920
|
-
text: attributes.text
|
|
24921
|
-
});
|
|
24917
|
+
return commands2.insertContent(NodeFactory.text(attributes.text, [
|
|
24918
|
+
NodeFactory.mark(TextSettings.LINK, attributes)
|
|
24919
|
+
]));
|
|
24922
24920
|
}
|
|
24923
|
-
return chain().setMark(this.name, attributes).transformText(() => attributes.text).extendMarkRange(
|
|
24924
|
-
})
|
|
24921
|
+
return chain().setMark(this.name, attributes).transformText(() => attributes.text).extendMarkRange(TextSettings.LINK).run();
|
|
24922
|
+
}),
|
|
24923
|
+
isLink: createCommand(({ editor }) => computed(() => editor.isActive(TextSettings.LINK))),
|
|
24924
|
+
getLinkPreset: createCommand(() => computed(() => this.options.preset))
|
|
24925
24925
|
};
|
|
24926
24926
|
},
|
|
24927
24927
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
@@ -31,8 +31,8 @@
|
|
|
31
31
|
</template>
|
|
32
32
|
|
|
33
33
|
<script>
|
|
34
|
-
import { computed, ref, inject } from 'vue';
|
|
35
|
-
import { LinkDestinations } from '../../../../enums';
|
|
34
|
+
import { computed, ref, inject, unref } from 'vue';
|
|
35
|
+
import { LinkDestinations, TextSettings } from '../../../../enums';
|
|
36
36
|
import { InjectionTokens } from '../../../../injectionTokens';
|
|
37
37
|
import { tooltip } from '../../../../directives';
|
|
38
38
|
import { useValidator } from '../../../base/composables';
|
|
@@ -94,7 +94,7 @@ export default {
|
|
|
94
94
|
};
|
|
95
95
|
|
|
96
96
|
const onBeforeOpened = () => {
|
|
97
|
-
editor.commands.extendMarkRange(
|
|
97
|
+
editor.commands.extendMarkRange(TextSettings.LINK);
|
|
98
98
|
resetErrors();
|
|
99
99
|
link.prepareInitialFields();
|
|
100
100
|
};
|
|
@@ -105,7 +105,8 @@ export default {
|
|
|
105
105
|
modalRef
|
|
106
106
|
});
|
|
107
107
|
|
|
108
|
-
const
|
|
108
|
+
const isLink = editor.commands.isLink();
|
|
109
|
+
const isActive = computed(() => toggler.isOpened.value || unref(isLink));
|
|
109
110
|
|
|
110
111
|
const updateLinkText = (value) => {
|
|
111
112
|
resetErrors();
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
</template>
|
|
11
11
|
|
|
12
12
|
<script>
|
|
13
|
-
import {
|
|
13
|
+
import { inject } from 'vue';
|
|
14
14
|
import { Icon, Button } from '../../../base';
|
|
15
15
|
import { InjectionTokens } from '../../../../injectionTokens';
|
|
16
16
|
|
|
@@ -21,7 +21,7 @@ export default {
|
|
|
21
21
|
|
|
22
22
|
setup(_, { emit }) {
|
|
23
23
|
const editor = inject(InjectionTokens.EDITOR);
|
|
24
|
-
const isLink =
|
|
24
|
+
const isLink = editor.commands.isLink();
|
|
25
25
|
|
|
26
26
|
const removeLink = () => emit('remove-link');
|
|
27
27
|
|
|
@@ -7,7 +7,7 @@ import LinkControlApply from '../LinkControlApply';
|
|
|
7
7
|
import { LinkControlDestination } from '../destination';
|
|
8
8
|
|
|
9
9
|
const createEditor = (isActive) => ({
|
|
10
|
-
|
|
10
|
+
commands: { isLink: () => isActive ?? false }
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
function createComponent({ editor }) {
|
|
@@ -4,7 +4,7 @@ import { Button } from '../../../../base';
|
|
|
4
4
|
import LinkControlHeader from '../LinkControlHeader';
|
|
5
5
|
|
|
6
6
|
const createEditor = (isActive) => ({
|
|
7
|
-
|
|
7
|
+
commands: { isLink: () => isActive ?? false }
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
function createComponent({ editor }) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref, inject } from 'vue';
|
|
2
|
-
import { LinkTargets, LinkDestinations } from '../../../../../enums';
|
|
2
|
+
import { LinkTargets, LinkDestinations, TextSettings } from '../../../../../enums';
|
|
3
3
|
import { InjectionTokens } from '../../../../../injectionTokens';
|
|
4
4
|
|
|
5
5
|
export function useLink() {
|
|
@@ -15,12 +15,14 @@ export function useLink() {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
function prepareInitialFields() {
|
|
18
|
+
const link = editor.getAttributes(TextSettings.LINK);
|
|
19
|
+
|
|
18
20
|
linkData.value.text = editor.commands.getSelectedText();
|
|
19
|
-
currentDestination.value.id =
|
|
20
|
-
linkData.value.target =
|
|
21
|
+
currentDestination.value.id = link.destination || LinkDestinations.URL;
|
|
22
|
+
linkData.value.target = link.target || LinkTargets.SELF;
|
|
21
23
|
|
|
22
|
-
if (
|
|
23
|
-
destinationHrefs.value[currentDestination.value.id] =
|
|
24
|
+
if (link.href) {
|
|
25
|
+
destinationHrefs.value[currentDestination.value.id] = link.href;
|
|
24
26
|
}
|
|
25
27
|
}
|
|
26
28
|
|
|
@@ -46,7 +46,7 @@ export const FontStyle = Mark.create({
|
|
|
46
46
|
}),
|
|
47
47
|
|
|
48
48
|
removeItalic: createCommand(({ commands }) => {
|
|
49
|
-
commands.
|
|
49
|
+
commands.setMark(this.name, { italic: false });
|
|
50
50
|
})
|
|
51
51
|
};
|
|
52
52
|
},
|
|
@@ -76,7 +76,7 @@ export const FontStyle = Mark.create({
|
|
|
76
76
|
},
|
|
77
77
|
|
|
78
78
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
79
|
-
const font_style = attrs.italic ? 'italic' :
|
|
79
|
+
const font_style = attrs.italic ? 'italic' : 'normal';
|
|
80
80
|
|
|
81
81
|
return renderMark({ font_style });
|
|
82
82
|
}
|
package/lib/extensions/Link.js
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import Base from '@tiptap/extension-link';
|
|
2
|
-
import { unref } from 'vue';
|
|
2
|
+
import { computed, unref } from 'vue';
|
|
3
3
|
import { createCommand } from '../utils';
|
|
4
|
-
import { LinkDestinations, LinkTargets } from '../enums';
|
|
4
|
+
import { LinkDestinations, LinkTargets, TextSettings } from '../enums';
|
|
5
|
+
import { NodeFactory } from '../services';
|
|
5
6
|
|
|
6
7
|
export const Link = Base.extend({
|
|
7
|
-
name:
|
|
8
|
+
name: TextSettings.LINK,
|
|
8
9
|
|
|
9
10
|
addOptions() {
|
|
10
11
|
return {
|
|
@@ -52,26 +53,23 @@ export const Link = Base.extend({
|
|
|
52
53
|
addCommands() {
|
|
53
54
|
return {
|
|
54
55
|
...this.parent?.(),
|
|
56
|
+
|
|
55
57
|
applyLink: createCommand(({ commands, chain }, attributes) => {
|
|
56
58
|
if (!commands.getSelectedText()) {
|
|
57
|
-
return commands.insertContent(
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
{
|
|
61
|
-
type: 'link',
|
|
62
|
-
attrs: { ...attributes }
|
|
63
|
-
}
|
|
64
|
-
],
|
|
65
|
-
text: attributes.text
|
|
66
|
-
});
|
|
59
|
+
return commands.insertContent(NodeFactory.text(attributes.text, [
|
|
60
|
+
NodeFactory.mark(TextSettings.LINK, attributes)
|
|
61
|
+
]));
|
|
67
62
|
}
|
|
68
63
|
|
|
69
64
|
return chain()
|
|
70
65
|
.setMark(this.name, attributes)
|
|
71
66
|
.transformText(() => attributes.text)
|
|
72
|
-
.extendMarkRange(
|
|
67
|
+
.extendMarkRange(TextSettings.LINK)
|
|
73
68
|
.run();
|
|
74
|
-
})
|
|
69
|
+
}),
|
|
70
|
+
|
|
71
|
+
isLink: createCommand(({ editor }) => computed(() => editor.isActive(TextSettings.LINK))),
|
|
72
|
+
getLinkPreset: createCommand(() => computed(() => this.options.preset))
|
|
75
73
|
};
|
|
76
74
|
},
|
|
77
75
|
|
|
@@ -5,6 +5,7 @@ import { TextSettings } from '../enums';
|
|
|
5
5
|
|
|
6
6
|
export const TextDecoration = Mark.create({
|
|
7
7
|
name: TextSettings.TEXT_DECORATION,
|
|
8
|
+
priority: 1000,
|
|
8
9
|
|
|
9
10
|
addAttributes: () => ({
|
|
10
11
|
underline: { default: false },
|
|
@@ -13,10 +14,10 @@ export const TextDecoration = Mark.create({
|
|
|
13
14
|
|
|
14
15
|
addCommands() {
|
|
15
16
|
return {
|
|
16
|
-
isUnderline: createCommand(({ commands
|
|
17
|
+
isUnderline: createCommand(({ commands }) => {
|
|
17
18
|
const decoration = commands.getTextDecoration();
|
|
18
19
|
|
|
19
|
-
return computed(() =>
|
|
20
|
+
return computed(() => unref(decoration).underline);
|
|
20
21
|
}),
|
|
21
22
|
|
|
22
23
|
isStrikeThrough: createCommand(({ commands }) => {
|
|
@@ -40,9 +41,14 @@ export const TextDecoration = Mark.create({
|
|
|
40
41
|
|
|
41
42
|
getDefaultTextDecoration: createCommand(({ commands }) => {
|
|
42
43
|
const preset = commands.getPreset();
|
|
44
|
+
const isLink = commands.isLink();
|
|
45
|
+
const linkPreset = commands.getLinkPreset();
|
|
43
46
|
|
|
44
47
|
return computed(() => {
|
|
45
|
-
const decoration =
|
|
48
|
+
const decoration = [
|
|
49
|
+
unref(preset).common.text_decoration,
|
|
50
|
+
unref(isLink) ? unref(linkPreset).common.text_decoration : ''
|
|
51
|
+
].join(' ');
|
|
46
52
|
|
|
47
53
|
return {
|
|
48
54
|
underline: decoration.includes('underline'),
|
|
@@ -51,9 +57,7 @@ export const TextDecoration = Mark.create({
|
|
|
51
57
|
});
|
|
52
58
|
}),
|
|
53
59
|
|
|
54
|
-
toggleUnderline: createCommand(({ commands
|
|
55
|
-
if (editor.isActive('link')) return;
|
|
56
|
-
|
|
60
|
+
toggleUnderline: createCommand(({ commands }) => {
|
|
57
61
|
commands.toggleTextDecoration('underline');
|
|
58
62
|
}),
|
|
59
63
|
|
|
@@ -72,13 +76,7 @@ export const TextDecoration = Mark.create({
|
|
|
72
76
|
}),
|
|
73
77
|
|
|
74
78
|
removeTextDecoration: createCommand(({ commands }, name) => {
|
|
75
|
-
|
|
76
|
-
...unref(commands.getTextDecoration()),
|
|
77
|
-
[name]: false
|
|
78
|
-
};
|
|
79
|
-
const isRemoveMark = !mark.underline && !mark.strike_through;
|
|
80
|
-
|
|
81
|
-
isRemoveMark ? commands.unsetMark(this.name) : commands.setMark(this.name, mark);
|
|
79
|
+
commands.setMark(this.name, { ...unref(commands.getTextDecoration()), [name]: false });
|
|
82
80
|
})
|
|
83
81
|
};
|
|
84
82
|
},
|
|
@@ -135,6 +133,7 @@ export const TextDecoration = Mark.create({
|
|
|
135
133
|
|
|
136
134
|
if (attrs.underline) decorations.push('underline');
|
|
137
135
|
if (attrs.strike_through) decorations.push('line-through');
|
|
136
|
+
if (!decorations.length) decorations.push('none');
|
|
138
137
|
|
|
139
138
|
return renderMark({ text_decoration: decorations.join(' ') });
|
|
140
139
|
}
|
|
@@ -6,10 +6,11 @@ import { FontFamily } from '../FontFamily';
|
|
|
6
6
|
import { FontWeight } from '../FontWeight';
|
|
7
7
|
import { FontStyle } from '../FontStyle';
|
|
8
8
|
import { ContentNormalizer, NodeFactory } from '../../services';
|
|
9
|
+
import { TextSettings } from '../../enums';
|
|
9
10
|
import { buildCoreExtensions } from '../core';
|
|
10
11
|
|
|
11
12
|
const MockStylePreset = Extension.create({
|
|
12
|
-
name:
|
|
13
|
+
name: TextSettings.STYLE_PRESET,
|
|
13
14
|
|
|
14
15
|
addCommands() {
|
|
15
16
|
return {
|
|
@@ -30,10 +31,10 @@ function createEditor({ content }) {
|
|
|
30
31
|
MockStylePreset,
|
|
31
32
|
FontFamily.configure({
|
|
32
33
|
fonts: [
|
|
33
|
-
new Font({ name: 'Lato', styles: ['400', '700', '700i'] }),
|
|
34
|
+
new Font({ name: 'Lato', styles: ['400', '400i', '700', '700i'] }),
|
|
34
35
|
new Font({ name: 'Bungee', styles: ['400'] }),
|
|
35
|
-
new Font({ name: 'Roboto', styles: ['400'] }),
|
|
36
|
-
new Font({ name: 'Josefin Slab', styles: ['400'] })
|
|
36
|
+
new Font({ name: 'Roboto', styles: ['400', '400i'] }),
|
|
37
|
+
new Font({ name: 'Josefin Slab', styles: ['400', '400i'] })
|
|
37
38
|
],
|
|
38
39
|
defaultFont: 'Lato'
|
|
39
40
|
}),
|
|
@@ -51,7 +52,7 @@ describe('get font family', () => {
|
|
|
51
52
|
test('should get from selection', () => {
|
|
52
53
|
const editor = createEditor({
|
|
53
54
|
content: createContent(NodeFactory.text('hello world', [
|
|
54
|
-
NodeFactory.mark(
|
|
55
|
+
NodeFactory.mark(TextSettings.FONT_FAMILY, { value: 'Bungee' })
|
|
55
56
|
]))
|
|
56
57
|
});
|
|
57
58
|
|
|
@@ -165,7 +166,7 @@ describe('rendering', () => {
|
|
|
165
166
|
test('should render html', () => {
|
|
166
167
|
const editor = createEditor({
|
|
167
168
|
content: createContent(NodeFactory.text('hello world', [
|
|
168
|
-
NodeFactory.mark(
|
|
169
|
+
NodeFactory.mark(TextSettings.FONT_FAMILY, { value: 'Bungee' })
|
|
169
170
|
]))
|
|
170
171
|
});
|
|
171
172
|
|
|
@@ -6,10 +6,11 @@ import { FontWeight } from '../FontWeight';
|
|
|
6
6
|
import { FontFamily } from '../FontFamily';
|
|
7
7
|
import { FontStyle } from '../FontStyle';
|
|
8
8
|
import { ContentNormalizer, NodeFactory } from '../../services';
|
|
9
|
+
import { TextSettings } from '../../enums';
|
|
9
10
|
import { buildCoreExtensions } from '../core';
|
|
10
11
|
|
|
11
12
|
const MockStylePreset = Extension.create({
|
|
12
|
-
name:
|
|
13
|
+
name: TextSettings.STYLE_PRESET,
|
|
13
14
|
|
|
14
15
|
addCommands() {
|
|
15
16
|
return {
|
|
@@ -30,8 +31,8 @@ function createEditor({ content }) {
|
|
|
30
31
|
MockStylePreset,
|
|
31
32
|
FontFamily.configure({
|
|
32
33
|
fonts: [
|
|
33
|
-
new Font({ name: 'Lato', styles: ['400', '700'] }),
|
|
34
|
-
new Font({ name: 'Bungee', styles: ['300', '800'] })
|
|
34
|
+
new Font({ name: 'Lato', styles: ['400', '400i', '700', '700i'] }),
|
|
35
|
+
new Font({ name: 'Bungee', styles: ['300', '300i', '800', '800i'] })
|
|
35
36
|
]
|
|
36
37
|
}),
|
|
37
38
|
FontWeight,
|
|
@@ -48,7 +49,7 @@ describe('get font weight', () => {
|
|
|
48
49
|
test('should get from selection', () => {
|
|
49
50
|
const editor = createEditor({
|
|
50
51
|
content: createContent(NodeFactory.text('hello world', [
|
|
51
|
-
NodeFactory.mark(
|
|
52
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
52
53
|
]))
|
|
53
54
|
});
|
|
54
55
|
|
|
@@ -78,7 +79,7 @@ describe('get font weight', () => {
|
|
|
78
79
|
test('should get closest available font weight', () => {
|
|
79
80
|
const editor = createEditor({
|
|
80
81
|
content: createContent(NodeFactory.text('hello world', [
|
|
81
|
-
NodeFactory.mark(
|
|
82
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '800' })
|
|
82
83
|
]))
|
|
83
84
|
});
|
|
84
85
|
|
|
@@ -102,7 +103,7 @@ describe('apply font weight', () => {
|
|
|
102
103
|
test('should toggle weight to bold', () => {
|
|
103
104
|
const editor = createEditor({
|
|
104
105
|
content: createContent(NodeFactory.text('hello world', [
|
|
105
|
-
NodeFactory.mark(
|
|
106
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
106
107
|
]))
|
|
107
108
|
});
|
|
108
109
|
|
|
@@ -115,7 +116,7 @@ describe('apply font weight', () => {
|
|
|
115
116
|
const editor = createEditor({
|
|
116
117
|
content: createContent(NodeFactory.text('hello world', [
|
|
117
118
|
NodeFactory.mark('font_family', { value: 'Bungee' }),
|
|
118
|
-
NodeFactory.mark(
|
|
119
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '400' })
|
|
119
120
|
]))
|
|
120
121
|
});
|
|
121
122
|
|
|
@@ -127,7 +128,7 @@ describe('apply font weight', () => {
|
|
|
127
128
|
test('should toggle weight to medium', () => {
|
|
128
129
|
const editor = createEditor({
|
|
129
130
|
content: createContent(NodeFactory.text('hello world', [
|
|
130
|
-
NodeFactory.mark(
|
|
131
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
131
132
|
]))
|
|
132
133
|
});
|
|
133
134
|
|
|
@@ -140,7 +141,7 @@ describe('apply font weight', () => {
|
|
|
140
141
|
const editor = createEditor({
|
|
141
142
|
content: createContent(NodeFactory.text('hello world', [
|
|
142
143
|
NodeFactory.mark('font_family', { value: 'Bungee' }),
|
|
143
|
-
NodeFactory.mark(
|
|
144
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '800' })
|
|
144
145
|
]))
|
|
145
146
|
});
|
|
146
147
|
|
|
@@ -154,7 +155,7 @@ describe('rendering', () => {
|
|
|
154
155
|
test('should render html', () => {
|
|
155
156
|
const editor = createEditor({
|
|
156
157
|
content: createContent(NodeFactory.text('hello world', [
|
|
157
|
-
NodeFactory.mark(
|
|
158
|
+
NodeFactory.mark(TextSettings.FONT_WEIGHT, { value: '700' })
|
|
158
159
|
]))
|
|
159
160
|
});
|
|
160
161
|
|