@zipify/wysiwyg 4.11.0 → 4.11.2
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/.release-it.json +2 -1
- package/dist/cli.js +28 -28
- package/dist/node.js +26 -26
- package/dist/types/Wysiwyg.vue.d.ts +7 -8
- package/dist/types/components/base/Button.vue.d.ts +5 -10
- package/dist/types/components/base/ButtonToggle.vue.d.ts +9 -14
- package/dist/types/components/base/Checkbox.vue.d.ts +1 -1
- package/dist/types/components/base/FieldLabel.vue.d.ts +5 -10
- package/dist/types/components/base/Icon.vue.d.ts +1 -1
- package/dist/types/components/base/Modal.vue.d.ts +5 -14
- package/dist/types/components/base/ModalFloating.vue.d.ts +5 -14
- package/dist/types/components/base/NumberField.vue.d.ts +1 -1
- package/dist/types/components/base/Range.vue.d.ts +1 -1
- package/dist/types/components/base/ScrollView.vue.d.ts +5 -14
- package/dist/types/components/base/TextField.vue.d.ts +1 -1
- package/dist/types/components/base/colorPicker/ColorPicker.vue.d.ts +10 -517
- package/dist/types/components/base/dropdown/Dropdown.vue.d.ts +6 -15
- package/dist/types/components/base/dropdown/DropdownActivator.vue.d.ts +7 -12
- package/dist/types/components/base/dropdown/DropdownDivider.vue.d.ts +1 -1
- package/dist/types/components/base/dropdown/DropdownGroup.vue.d.ts +7 -12
- package/dist/types/components/base/dropdown/DropdownMenu.vue.d.ts +6 -12
- package/dist/types/components/base/dropdown/DropdownOption.vue.d.ts +5 -14
- package/dist/types/components/toolbar/ToolbarFloating.vue.d.ts +5 -14
- package/dist/types/components/toolbar/controls/AlignmentControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/CaseStyleControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/FontFamilyControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/FontSizeControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/FontWeightControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/ItalicControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/LineHeightControl.vue.d.ts +1 -3
- package/dist/types/components/toolbar/controls/ListControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/RemoveFormatControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/StrikeThroughControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/SuperscriptControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/UnderlineControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/link/LinkControl.vue.d.ts +1 -3
- package/dist/types/components/toolbar/controls/link/LinkControlHeader.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/link/composables/useLink.d.ts +11 -9
- package/dist/types/components/toolbar/controls/link/destination/LinkControlDestination.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/link/destination/LinkControlPageBlock.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/link/destination/LinkControlUrl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/stylePreset/StylePresetControl.vue.d.ts +1 -1
- package/dist/types/components/toolbar/controls/stylePreset/StylePresetOption.vue.d.ts +2 -4
- package/dist/types/enums/Alignment.d.ts +7 -0
- package/dist/types/enums/CaseStyle.d.ts +5 -0
- package/dist/types/enums/Device.d.ts +7 -0
- package/dist/types/enums/LinkDestination.d.ts +4 -0
- package/dist/types/enums/LinkTarget.d.ts +4 -0
- package/dist/types/enums/ListType.d.ts +10 -0
- package/dist/types/enums/MarkGroup.d.ts +4 -0
- package/dist/types/enums/NodeType.d.ts +9 -0
- package/dist/types/enums/TextSetting.d.ts +19 -0
- package/dist/types/enums/index.d.ts +9 -9
- package/dist/types/extensions/Alignment.d.ts +2 -1
- package/dist/types/extensions/CaseStyle.d.ts +2 -1
- package/dist/types/models/Font.d.ts +1 -0
- package/dist/wysiwyg.css +27 -27
- package/dist/wysiwyg.mjs +135 -165
- package/example/fonts.js +111 -111
- package/lib/Wysiwyg.vue +3 -3
- package/lib/__tests__/utils/buildTestExtensions.js +6 -6
- package/lib/components/toolbar/Toolbar.vue +2 -2
- package/lib/components/toolbar/__tests__/Toolbar.test.js +5 -5
- package/lib/components/toolbar/controls/AlignmentControl.vue +7 -7
- package/lib/components/toolbar/controls/CaseStyleControl.vue +5 -5
- package/lib/components/toolbar/controls/FontColorControl.vue +2 -2
- package/lib/components/toolbar/controls/FontFamilyControl.vue +2 -2
- package/lib/components/toolbar/controls/FontSizeControl.vue +2 -2
- package/lib/components/toolbar/controls/FontWeightControl.vue +2 -2
- package/lib/components/toolbar/controls/ItalicControl.vue +2 -2
- package/lib/components/toolbar/controls/LineHeightControl.vue +2 -2
- package/lib/components/toolbar/controls/ListControl.vue +5 -5
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +13 -13
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +4 -4
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +10 -10
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +6 -6
- package/lib/components/toolbar/controls/link/LinkControl.vue +5 -5
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +20 -20
- package/lib/components/toolbar/controls/link/composables/useLink.js +10 -10
- package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +10 -7
- package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +1 -1
- package/lib/enums/{Alignments.ts → Alignment.ts} +0 -8
- package/lib/enums/{CaseStyles.ts → CaseStyle.ts} +0 -6
- package/lib/enums/{Devices.ts → Device.ts} +0 -8
- package/lib/enums/LinkDestination.ts +4 -0
- package/lib/enums/LinkTarget.ts +4 -0
- package/lib/enums/{ListTypes.ts → ListType.ts} +0 -9
- package/lib/enums/MarkGroup.ts +4 -0
- package/lib/enums/{NodeTypes.ts → NodeType.ts} +0 -8
- package/lib/enums/{TextSettings.ts → TextSetting.ts} +0 -11
- package/lib/enums/index.ts +9 -9
- package/lib/extensions/Alignment.js +13 -11
- package/lib/extensions/BackgroundColor.js +2 -2
- package/lib/extensions/CaseStyle.js +8 -6
- package/lib/extensions/FontColor.js +4 -4
- package/lib/extensions/FontFamily.js +8 -6
- package/lib/extensions/FontSize.js +3 -3
- package/lib/extensions/FontStyle.js +3 -3
- package/lib/extensions/FontWeight.js +3 -3
- package/lib/extensions/LineHeight.js +4 -4
- package/lib/extensions/Link.js +11 -11
- package/lib/extensions/Margin.js +4 -4
- package/lib/extensions/StylePreset.js +18 -12
- package/lib/extensions/Superscript.js +2 -2
- package/lib/extensions/TextDecoration.js +2 -2
- package/lib/extensions/__tests__/Alignment.test.js +21 -21
- package/lib/extensions/__tests__/BackgroundColor.test.js +4 -4
- package/lib/extensions/__tests__/CaseStyle.test.js +6 -6
- package/lib/extensions/__tests__/FontColor.test.js +4 -4
- package/lib/extensions/__tests__/FontFamily.test.js +10 -10
- package/lib/extensions/__tests__/FontSize.test.js +9 -9
- package/lib/extensions/__tests__/FontStyle.test.js +6 -6
- package/lib/extensions/__tests__/FontWeight.test.js +11 -11
- package/lib/extensions/__tests__/LineHeight.test.js +2 -2
- package/lib/extensions/__tests__/Link.test.js +13 -13
- package/lib/extensions/__tests__/StylePreset.test.js +29 -29
- package/lib/extensions/__tests__/Superscript.test.js +5 -5
- package/lib/extensions/__tests__/TextDecoration.test.js +14 -14
- package/lib/extensions/core/Document.js +3 -3
- package/lib/extensions/core/Heading.js +2 -2
- package/lib/extensions/core/NodeProcessor.js +8 -8
- package/lib/extensions/core/Paragraph.js +2 -2
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +68 -68
- package/lib/extensions/core/__tests__/TextProcessor.test.js +13 -13
- package/lib/extensions/list/ListItem.js +5 -5
- package/lib/extensions/list/__tests__/List.test.js +11 -11
- package/lib/extensions/proseMirror/PasteLinkPlugin.js +4 -4
- package/lib/extensions/proseMirror/PastePlugin.js +2 -2
- package/lib/models/Font.ts +4 -0
- package/lib/services/ContentSerializer.js +3 -3
- package/lib/services/StylePresetRenderer.js +4 -4
- package/lib/services/__tests__/NodeFactory.test.js +11 -11
- package/lib/services/__tests__/NodeSelector.test.js +18 -18
- package/lib/services/normalizer/JsonNormalizer.js +5 -5
- package/lib/services/normalizer/__tests__/JsonNormalizer.test.js +15 -15
- package/lib/utils/__tests__/convertAlignment.test.js +3 -3
- package/lib/utils/convertAlignment.js +4 -4
- package/package.json +17 -17
- package/lib/enums/LinkDestinations.ts +0 -9
- package/lib/enums/LinkTargets.ts +0 -9
- package/lib/enums/MarkGroups.ts +0 -9
|
@@ -8,11 +8,3 @@ export enum NodeType {
|
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export const NodeBlockTypeList = [NodeType.PARAGRAPH, NodeType.LIST, NodeType.HEADING];
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @deprecated Use `NodeType` instead.
|
|
14
|
-
*/
|
|
15
|
-
export const NodeTypes = Object.freeze({
|
|
16
|
-
...NodeType,
|
|
17
|
-
blocks: NodeBlockTypeList
|
|
18
|
-
});
|
|
@@ -41,14 +41,3 @@ export const TextBlockMarkList = [
|
|
|
41
41
|
TextSetting.TEXT_DECORATION,
|
|
42
42
|
TextSetting.SUPERSCRIPT
|
|
43
43
|
];
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* @deprecated Use `TextSetting` instead.
|
|
47
|
-
*/
|
|
48
|
-
export const TextSettings = {
|
|
49
|
-
...TextSetting,
|
|
50
|
-
attributes: TextAttributeSettingList,
|
|
51
|
-
presetAttributes: TextPresetAttributeSettingList,
|
|
52
|
-
inlineMarks: TextInlineMarkList,
|
|
53
|
-
marks: TextBlockMarkList
|
|
54
|
-
};
|
package/lib/enums/index.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
export * from './
|
|
2
|
-
export * from './
|
|
3
|
-
export * from './
|
|
4
|
-
export * from './
|
|
5
|
-
export * from './
|
|
6
|
-
export * from './
|
|
7
|
-
export * from './
|
|
8
|
-
export * from './
|
|
9
|
-
export * from './
|
|
1
|
+
export * from './Device';
|
|
2
|
+
export * from './CaseStyle';
|
|
3
|
+
export * from './Alignment';
|
|
4
|
+
export * from './NodeType';
|
|
5
|
+
export * from './ListType';
|
|
6
|
+
export * from './TextSetting';
|
|
7
|
+
export * from './MarkGroup';
|
|
8
|
+
export * from './LinkTarget';
|
|
9
|
+
export * from './LinkDestination';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
|
-
import { convertAlignment, createCommand, createKeyboardShortcut, renderInlineSetting } from '
|
|
4
|
-
import {
|
|
3
|
+
import { convertAlignment, createCommand, createKeyboardShortcut, renderInlineSetting } from '@/utils';
|
|
4
|
+
import { Alignment, NodeType, TextSetting } from '@/enums';
|
|
5
5
|
|
|
6
6
|
const DEFAULTS = {
|
|
7
7
|
mobile: null,
|
|
@@ -9,14 +9,14 @@ const DEFAULTS = {
|
|
|
9
9
|
desktop: null
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
export const
|
|
13
|
-
name:
|
|
12
|
+
export const AlignmentExtension = Extension.create({
|
|
13
|
+
name: TextSetting.ALIGNMENT,
|
|
14
14
|
|
|
15
15
|
addGlobalAttributes: () => [
|
|
16
16
|
{
|
|
17
|
-
types: [
|
|
17
|
+
types: [NodeType.PARAGRAPH, NodeType.HEADING],
|
|
18
18
|
attributes: {
|
|
19
|
-
[
|
|
19
|
+
[TextSetting.ALIGNMENT]: {
|
|
20
20
|
isRequired: false,
|
|
21
21
|
|
|
22
22
|
parseHTML({ style }) {
|
|
@@ -71,15 +71,17 @@ export const Alignment = Extension.create({
|
|
|
71
71
|
const device = commands.getDevice();
|
|
72
72
|
const preset = commands.getPreset();
|
|
73
73
|
|
|
74
|
-
return computed(() => unref(preset)[unref(device)].alignment ??
|
|
74
|
+
return computed(() => unref(preset)[unref(device)].alignment ?? Alignment.LEFT);
|
|
75
75
|
})
|
|
76
76
|
};
|
|
77
77
|
},
|
|
78
78
|
|
|
79
79
|
addKeyboardShortcuts: () => ({
|
|
80
|
-
'Mod-Shift-l': createKeyboardShortcut('applyAlignment',
|
|
81
|
-
'Mod-Shift-e': createKeyboardShortcut('applyAlignment',
|
|
82
|
-
'Mod-Shift-r': createKeyboardShortcut('applyAlignment',
|
|
83
|
-
'Mod-Shift-j': createKeyboardShortcut('applyAlignment',
|
|
80
|
+
'Mod-Shift-l': createKeyboardShortcut('applyAlignment', Alignment.LEFT),
|
|
81
|
+
'Mod-Shift-e': createKeyboardShortcut('applyAlignment', Alignment.CENTER),
|
|
82
|
+
'Mod-Shift-r': createKeyboardShortcut('applyAlignment', Alignment.RIGHT),
|
|
83
|
+
'Mod-Shift-j': createKeyboardShortcut('applyAlignment', Alignment.JUSTIFY)
|
|
84
84
|
})
|
|
85
85
|
});
|
|
86
|
+
|
|
87
|
+
export { AlignmentExtension as Alignment };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { convertColor, createCommand, renderMark } from '../utils';
|
|
3
|
-
import {
|
|
3
|
+
import { TextSetting } from '../enums';
|
|
4
4
|
|
|
5
5
|
export const BackgroundColor = Mark.create({
|
|
6
|
-
name:
|
|
6
|
+
name: TextSetting.BACKGROUND_COLOR,
|
|
7
7
|
|
|
8
8
|
addAttributes: () => ({
|
|
9
9
|
value: { required: true }
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-3';
|
|
2
|
-
import { capitalize, createCommand } from '
|
|
3
|
-
import {
|
|
2
|
+
import { capitalize, createCommand } from '@/utils';
|
|
3
|
+
import { CaseStyle } from '@/enums';
|
|
4
4
|
|
|
5
|
-
export const
|
|
5
|
+
export const CaseStyleExtension = Extension.create({
|
|
6
6
|
name: 'case_style',
|
|
7
7
|
|
|
8
8
|
addCommands() {
|
|
9
9
|
return {
|
|
10
10
|
applyCaseStyle: createCommand(({ commands }, value) => {
|
|
11
11
|
switch (value) {
|
|
12
|
-
case
|
|
12
|
+
case CaseStyle.CAPITALIZE:
|
|
13
13
|
return commands.applyCapitalize();
|
|
14
14
|
|
|
15
|
-
case
|
|
15
|
+
case CaseStyle.LOWERCASE:
|
|
16
16
|
return commands.applyLowerCase();
|
|
17
17
|
|
|
18
|
-
case
|
|
18
|
+
case CaseStyle.UPPERCASE:
|
|
19
19
|
return commands.applyUpperCase();
|
|
20
20
|
}
|
|
21
21
|
}),
|
|
@@ -34,3 +34,5 @@ export const CaseStyle = Extension.create({
|
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
36
|
});
|
|
37
|
+
|
|
38
|
+
export { CaseStyleExtension as CaseStyle };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
|
-
import { convertColor, createCommand, renderMark } from '
|
|
4
|
-
import {
|
|
3
|
+
import { convertColor, createCommand, renderMark } from '@/utils';
|
|
4
|
+
import { MarkGroup, TextSetting } from '@/enums';
|
|
5
5
|
|
|
6
6
|
export const FontColor = Mark.create({
|
|
7
|
-
name:
|
|
8
|
-
group:
|
|
7
|
+
name: TextSetting.FONT_COLOR,
|
|
8
|
+
group: MarkGroup.SETTINGS,
|
|
9
9
|
|
|
10
10
|
addAttributes: () => ({
|
|
11
11
|
value: { required: true }
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
|
-
import { createCommand, renderMark } from '
|
|
4
|
-
import {
|
|
3
|
+
import { createCommand, renderMark } from '@/utils';
|
|
4
|
+
import { MarkGroup, TextSetting } from '@/enums';
|
|
5
5
|
|
|
6
6
|
export const FontFamily = Mark.create({
|
|
7
|
-
name:
|
|
8
|
-
group:
|
|
7
|
+
name: TextSetting.FONT_FAMILY,
|
|
8
|
+
group: MarkGroup.SETTINGS,
|
|
9
9
|
|
|
10
10
|
addOptions: () => ({
|
|
11
11
|
fonts: []
|
|
@@ -28,9 +28,11 @@ export const FontFamily = Mark.create({
|
|
|
28
28
|
commands.applyFontWeight(fontWeight);
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
const isItalicCustomized = commands.isSettingCustomized(
|
|
31
|
+
const isItalicCustomized = commands.isSettingCustomized(TextSetting.FONT_STYLE).value;
|
|
32
32
|
|
|
33
|
-
if (
|
|
33
|
+
if (font.isItalicOnly) {
|
|
34
|
+
commands.applyItalic();
|
|
35
|
+
} else if (!font.isItalicSupported(fontWeight) && isItalicCustomized) {
|
|
34
36
|
commands.removeItalic();
|
|
35
37
|
}
|
|
36
38
|
}),
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { convertFontSize, createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { MarkGroup, TextSetting } from '../enums';
|
|
5
5
|
|
|
6
6
|
export const FontSize = Mark.create({
|
|
7
|
-
name:
|
|
8
|
-
group:
|
|
7
|
+
name: TextSetting.FONT_SIZE,
|
|
8
|
+
group: MarkGroup.SETTINGS,
|
|
9
9
|
|
|
10
10
|
addOptions: () => ({
|
|
11
11
|
minSize: 1,
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderMark } from '@/utils';
|
|
4
|
-
import {
|
|
4
|
+
import { MarkGroup, TextSetting } from '@/enums';
|
|
5
5
|
|
|
6
6
|
export const FontStyle = Mark.create({
|
|
7
|
-
name:
|
|
8
|
-
group:
|
|
7
|
+
name: TextSetting.FONT_STYLE,
|
|
8
|
+
group: MarkGroup.SETTINGS,
|
|
9
9
|
|
|
10
10
|
addAttributes: () => ({
|
|
11
11
|
italic: { required: true }
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { MarkGroup, TextSetting } from '../enums';
|
|
5
5
|
|
|
6
6
|
export const FontWeight = Mark.create({
|
|
7
|
-
name:
|
|
8
|
-
group:
|
|
7
|
+
name: TextSetting.FONT_WEIGHT,
|
|
8
|
+
group: MarkGroup.SETTINGS,
|
|
9
9
|
|
|
10
10
|
addAttributes: () => ({
|
|
11
11
|
value: { required: true }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { createCommand, renderInlineSetting, convertLineHeight } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { NodeType, TextSetting } from '../enums';
|
|
5
5
|
|
|
6
6
|
const DEFAULTS = {
|
|
7
7
|
mobile: null,
|
|
@@ -10,14 +10,14 @@ const DEFAULTS = {
|
|
|
10
10
|
};
|
|
11
11
|
|
|
12
12
|
export const LineHeight = Extension.create({
|
|
13
|
-
name:
|
|
13
|
+
name: TextSetting.LINE_HEIGHT,
|
|
14
14
|
|
|
15
15
|
addGlobalAttributes() {
|
|
16
16
|
return [
|
|
17
17
|
{
|
|
18
|
-
types: [
|
|
18
|
+
types: [NodeType.PARAGRAPH, NodeType.HEADING],
|
|
19
19
|
attributes: {
|
|
20
|
-
[
|
|
20
|
+
[TextSetting.LINE_HEIGHT]: {
|
|
21
21
|
isRequired: false,
|
|
22
22
|
|
|
23
23
|
parseHTML: (element) => {
|
package/lib/extensions/Link.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import Base from '@tiptap/extension-link';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
|
-
import { createCommand } from '
|
|
4
|
-
import {
|
|
5
|
-
import { NodeFactory } from '
|
|
3
|
+
import { createCommand } from '@/utils';
|
|
4
|
+
import { LinkDestination, LinkTarget, TextSetting } from '@/enums';
|
|
5
|
+
import { NodeFactory } from '@/services';
|
|
6
6
|
import { PasteLinkPlugin } from './proseMirror';
|
|
7
7
|
|
|
8
8
|
export const Link = Base.extend({
|
|
9
|
-
name:
|
|
9
|
+
name: TextSetting.LINK,
|
|
10
10
|
|
|
11
11
|
addOptions() {
|
|
12
12
|
return {
|
|
@@ -30,23 +30,23 @@ export const Link = Base.extend({
|
|
|
30
30
|
},
|
|
31
31
|
|
|
32
32
|
target: {
|
|
33
|
-
default:
|
|
34
|
-
parseHTML: (element) => element.getAttribute('target') ||
|
|
33
|
+
default: LinkTarget.SELF,
|
|
34
|
+
parseHTML: (element) => element.getAttribute('target') || LinkTarget.SELF
|
|
35
35
|
},
|
|
36
36
|
|
|
37
37
|
destination: {
|
|
38
|
-
default:
|
|
38
|
+
default: LinkDestination.URL,
|
|
39
39
|
|
|
40
40
|
parseHTML: (element) => {
|
|
41
41
|
const href = element.getAttribute('href');
|
|
42
42
|
|
|
43
|
-
if (!href.startsWith('#')) return
|
|
43
|
+
if (!href.startsWith('#')) return LinkDestination.URL;
|
|
44
44
|
|
|
45
45
|
const id = href.replace('#', '');
|
|
46
46
|
const blocks = unref(this.options.pageBlocks);
|
|
47
47
|
const block = blocks.find((block) => block.id === parseInt(id));
|
|
48
48
|
|
|
49
|
-
return block ?
|
|
49
|
+
return block ? LinkDestination.BLOCK : LinkDestination.URL;
|
|
50
50
|
}
|
|
51
51
|
}
|
|
52
52
|
};
|
|
@@ -63,7 +63,7 @@ export const Link = Base.extend({
|
|
|
63
63
|
|
|
64
64
|
if (!commands.getSelectedText()) {
|
|
65
65
|
return commands.insertContent(NodeFactory.text(attributes.text, [
|
|
66
|
-
NodeFactory.mark(
|
|
66
|
+
NodeFactory.mark(TextSetting.LINK, attributes)
|
|
67
67
|
]));
|
|
68
68
|
}
|
|
69
69
|
|
|
@@ -96,7 +96,7 @@ export const Link = Base.extend({
|
|
|
96
96
|
},
|
|
97
97
|
|
|
98
98
|
renderHTML({ HTMLAttributes: attrs }) {
|
|
99
|
-
const href = attrs.destination ===
|
|
99
|
+
const href = attrs.destination === LinkDestination.BLOCK ? `#${attrs.href}` : attrs.href;
|
|
100
100
|
const presetClass = unref(this.options.basePresetClass) + unref(this.options.preset).id;
|
|
101
101
|
const linkAttrs = { href, target: attrs.target, class: `${presetClass} zw-style` };
|
|
102
102
|
|
package/lib/extensions/Margin.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-3';
|
|
2
|
-
import {
|
|
2
|
+
import { NodeType, TextSetting } from '../enums';
|
|
3
3
|
import { renderInlineSetting } from '../utils';
|
|
4
4
|
|
|
5
5
|
// Fallback margins in old wysiwyg content
|
|
6
6
|
export const Margin = Extension.create({
|
|
7
|
-
name:
|
|
7
|
+
name: TextSetting.MARGIN,
|
|
8
8
|
|
|
9
9
|
addGlobalAttributes: () => [
|
|
10
10
|
{
|
|
11
|
-
types: [
|
|
11
|
+
types: [NodeType.PARAGRAPH, NodeType.HEADING],
|
|
12
12
|
|
|
13
13
|
attributes: {
|
|
14
|
-
[
|
|
14
|
+
[TextSetting.MARGIN]: {
|
|
15
15
|
isRequired: false,
|
|
16
16
|
|
|
17
17
|
parseHTML(el) {
|
|
@@ -1,16 +1,22 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, toRef, unref } from 'vue';
|
|
3
3
|
import { createCommand } from '@/utils';
|
|
4
|
-
import {
|
|
4
|
+
import {
|
|
5
|
+
NodeType,
|
|
6
|
+
TextAttributeSettingList,
|
|
7
|
+
TextBlockMarkList,
|
|
8
|
+
TextPresetAttributeSettingList,
|
|
9
|
+
TextSetting
|
|
10
|
+
} from '@/enums';
|
|
5
11
|
import { ContextWindow } from '@/services';
|
|
6
12
|
|
|
7
13
|
export const StylePreset = Extension.create({
|
|
8
|
-
name:
|
|
14
|
+
name: TextSetting.STYLE_PRESET,
|
|
9
15
|
|
|
10
16
|
addGlobalAttributes() {
|
|
11
17
|
return [
|
|
12
18
|
{
|
|
13
|
-
types: [
|
|
19
|
+
types: [NodeType.PARAGRAPH, NodeType.HEADING],
|
|
14
20
|
attributes: {
|
|
15
21
|
preset: {
|
|
16
22
|
isRequired: false,
|
|
@@ -97,7 +103,7 @@ export const StylePreset = Extension.create({
|
|
|
97
103
|
applyPreset: createCommand(({ commands, chain }, presetId) => {
|
|
98
104
|
const presets = unref(commands.getPresetList());
|
|
99
105
|
const preset = findPresetById(presets, presetId);
|
|
100
|
-
const nodeType = preset.node?.type ??
|
|
106
|
+
const nodeType = preset.node?.type ?? NodeType.PARAGRAPH;
|
|
101
107
|
|
|
102
108
|
const attrs = {
|
|
103
109
|
preset: { id: presetId }
|
|
@@ -107,7 +113,7 @@ export const StylePreset = Extension.create({
|
|
|
107
113
|
attrs.level = preset.node.level;
|
|
108
114
|
}
|
|
109
115
|
|
|
110
|
-
for (const textAttribute of
|
|
116
|
+
for (const textAttribute of TextAttributeSettingList) {
|
|
111
117
|
attrs[textAttribute] = unref(commands.getBlockAttributes(textAttribute));
|
|
112
118
|
}
|
|
113
119
|
|
|
@@ -119,7 +125,7 @@ export const StylePreset = Extension.create({
|
|
|
119
125
|
}),
|
|
120
126
|
|
|
121
127
|
removePreset: createCommand(({ commands }) => {
|
|
122
|
-
commands.setNode(
|
|
128
|
+
commands.setNode(NodeType.PARAGRAPH, { preset: null });
|
|
123
129
|
}),
|
|
124
130
|
|
|
125
131
|
getPresetCustomization: createCommand(({ editor, commands }) => {
|
|
@@ -135,7 +141,7 @@ export const StylePreset = Extension.create({
|
|
|
135
141
|
|
|
136
142
|
isSettingCustomized: createCommand(({ commands }, name) => {
|
|
137
143
|
const customization = commands.getPresetCustomization();
|
|
138
|
-
const group =
|
|
144
|
+
const group = TextPresetAttributeSettingList.includes(name) ? 'attributes' : 'marks';
|
|
139
145
|
|
|
140
146
|
return computed(() => unref(customization)[group]?.includes(name) ?? false);
|
|
141
147
|
}),
|
|
@@ -156,13 +162,13 @@ export const StylePreset = Extension.create({
|
|
|
156
162
|
|
|
157
163
|
doc.nodesBetween(from, to, (node) => {
|
|
158
164
|
for (const [name, value] of Object.entries(node.attrs)) {
|
|
159
|
-
const isSetting =
|
|
165
|
+
const isSetting = TextPresetAttributeSettingList.includes(name);
|
|
160
166
|
|
|
161
167
|
if (isSetting && value) attributes.add(name);
|
|
162
168
|
}
|
|
163
169
|
|
|
164
170
|
for (const { type } of node.marks) {
|
|
165
|
-
if (
|
|
171
|
+
if (TextBlockMarkList.includes(type.name)) {
|
|
166
172
|
marks.add(type.name);
|
|
167
173
|
}
|
|
168
174
|
}
|
|
@@ -178,9 +184,9 @@ export const StylePreset = Extension.create({
|
|
|
178
184
|
chain()
|
|
179
185
|
.storeSelection()
|
|
180
186
|
.expandSelectionToBlock()
|
|
181
|
-
.removeMarks(
|
|
182
|
-
.resetAttributes(
|
|
183
|
-
.resetAttributes(
|
|
187
|
+
.removeMarks(TextBlockMarkList)
|
|
188
|
+
.resetAttributes(NodeType.PARAGRAPH, TextPresetAttributeSettingList)
|
|
189
|
+
.resetAttributes(NodeType.HEADING, TextPresetAttributeSettingList)
|
|
184
190
|
.restoreSelection()
|
|
185
191
|
.run();
|
|
186
192
|
}),
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { createCommand } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { TextSetting } from '../enums';
|
|
5
5
|
|
|
6
6
|
export const Superscript = Mark.create({
|
|
7
|
-
name:
|
|
7
|
+
name: TextSetting.SUPERSCRIPT,
|
|
8
8
|
|
|
9
9
|
addCommands() {
|
|
10
10
|
return {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Mark } from '@tiptap/vue-3';
|
|
2
2
|
import { computed, unref } from 'vue';
|
|
3
3
|
import { createCommand, createKeyboardShortcut, renderMark } from '../utils';
|
|
4
|
-
import {
|
|
4
|
+
import { TextSetting } from '../enums';
|
|
5
5
|
|
|
6
6
|
export const TextDecoration = Mark.create({
|
|
7
|
-
name:
|
|
7
|
+
name: TextSetting.TEXT_DECORATION,
|
|
8
8
|
priority: 1000,
|
|
9
9
|
|
|
10
10
|
addAttributes: () => ({
|
|
@@ -1,21 +1,21 @@
|
|
|
1
1
|
import { Editor, Extension } from '@tiptap/vue-3';
|
|
2
2
|
import { ref } from 'vue';
|
|
3
|
-
import { buildTestExtensions } from '
|
|
4
|
-
import { createCommand } from '
|
|
5
|
-
import { Alignment } from '
|
|
3
|
+
import { buildTestExtensions } from '@/__tests__/utils';
|
|
4
|
+
import { createCommand } from '@/utils';
|
|
5
|
+
import { Alignment, TextSetting } from '@/enums';
|
|
6
|
+
import { ContentNormalizer, NodeFactory } from '@/services';
|
|
7
|
+
import { AlignmentExtension } from '../Alignment';
|
|
6
8
|
import { DeviceManager } from '../DeviceManager';
|
|
7
|
-
import { Alignments, TextSettings } from '../../enums';
|
|
8
|
-
import { ContentNormalizer, NodeFactory } from '../../services';
|
|
9
9
|
|
|
10
10
|
const MockStylePreset = Extension.create({
|
|
11
|
-
name:
|
|
11
|
+
name: TextSetting.STYLE_PRESET,
|
|
12
12
|
|
|
13
13
|
addCommands() {
|
|
14
14
|
return {
|
|
15
15
|
getPreset: createCommand(() => ref({
|
|
16
|
-
mobile: { alignment:
|
|
17
|
-
tablet: { alignment:
|
|
18
|
-
desktop: { alignment:
|
|
16
|
+
mobile: { alignment: Alignment.JUSTIFY },
|
|
17
|
+
tablet: { alignment: Alignment.JUSTIFY },
|
|
18
|
+
desktop: { alignment: Alignment.JUSTIFY }
|
|
19
19
|
}))
|
|
20
20
|
};
|
|
21
21
|
}
|
|
@@ -28,7 +28,7 @@ function createEditor({ content }) {
|
|
|
28
28
|
include: [
|
|
29
29
|
MockStylePreset,
|
|
30
30
|
DeviceManager.configure({ device: ref('desktop') }),
|
|
31
|
-
|
|
31
|
+
AlignmentExtension
|
|
32
32
|
]
|
|
33
33
|
})
|
|
34
34
|
});
|
|
@@ -44,13 +44,13 @@ describe('get value', () => {
|
|
|
44
44
|
test('should get from selection', () => {
|
|
45
45
|
const editor = createEditor({
|
|
46
46
|
content: createContent({
|
|
47
|
-
alignment: { desktop:
|
|
47
|
+
alignment: { desktop: Alignment.CENTER }
|
|
48
48
|
})
|
|
49
49
|
});
|
|
50
50
|
|
|
51
51
|
editor.commands.selectAll();
|
|
52
52
|
|
|
53
|
-
expect(editor.commands.getAlignment().value).toEqual(
|
|
53
|
+
expect(editor.commands.getAlignment().value).toEqual(Alignment.CENTER);
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
test('should get default value', () => {
|
|
@@ -58,7 +58,7 @@ describe('get value', () => {
|
|
|
58
58
|
content: createContent({ alignment: null })
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
expect(editor.commands.getDefaultAlignment().value).toEqual(
|
|
61
|
+
expect(editor.commands.getDefaultAlignment().value).toEqual(Alignment.JUSTIFY);
|
|
62
62
|
});
|
|
63
63
|
|
|
64
64
|
test('should get from preset', () => {
|
|
@@ -66,7 +66,7 @@ describe('get value', () => {
|
|
|
66
66
|
content: createContent({ alignment: null })
|
|
67
67
|
});
|
|
68
68
|
|
|
69
|
-
expect(editor.commands.getAlignment().value).toEqual(
|
|
69
|
+
expect(editor.commands.getAlignment().value).toEqual(Alignment.JUSTIFY);
|
|
70
70
|
});
|
|
71
71
|
});
|
|
72
72
|
|
|
@@ -77,7 +77,7 @@ describe('change value', () => {
|
|
|
77
77
|
});
|
|
78
78
|
|
|
79
79
|
editor.commands.selectAll();
|
|
80
|
-
editor.commands.applyAlignment(
|
|
80
|
+
editor.commands.applyAlignment(Alignment.RIGHT);
|
|
81
81
|
|
|
82
82
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
83
83
|
});
|
|
@@ -85,12 +85,12 @@ describe('change value', () => {
|
|
|
85
85
|
test('should remove value', () => {
|
|
86
86
|
const editor = createEditor({
|
|
87
87
|
content: createContent({
|
|
88
|
-
alignment: { desktop:
|
|
88
|
+
alignment: { desktop: Alignment.CENTER }
|
|
89
89
|
})
|
|
90
90
|
});
|
|
91
91
|
|
|
92
92
|
editor.commands.selectAll();
|
|
93
|
-
editor.commands.removeAlignment(
|
|
93
|
+
editor.commands.removeAlignment(TextSetting.ALIGNMENT);
|
|
94
94
|
|
|
95
95
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
96
96
|
});
|
|
@@ -100,7 +100,7 @@ describe('rendering', () => {
|
|
|
100
100
|
test('should render only desktop', () => {
|
|
101
101
|
const editor = createEditor({
|
|
102
102
|
content: createContent({
|
|
103
|
-
alignment: { desktop:
|
|
103
|
+
alignment: { desktop: Alignment.CENTER }
|
|
104
104
|
})
|
|
105
105
|
});
|
|
106
106
|
|
|
@@ -111,9 +111,9 @@ describe('rendering', () => {
|
|
|
111
111
|
const editor = createEditor({
|
|
112
112
|
content: createContent({
|
|
113
113
|
alignment: {
|
|
114
|
-
desktop:
|
|
115
|
-
tablet:
|
|
116
|
-
mobile:
|
|
114
|
+
desktop: Alignment.CENTER,
|
|
115
|
+
tablet: Alignment.RIGHT,
|
|
116
|
+
mobile: Alignment.LEFT
|
|
117
117
|
}
|
|
118
118
|
})
|
|
119
119
|
});
|
|
@@ -4,10 +4,10 @@ import { buildTestExtensions } from '../../__tests__/utils';
|
|
|
4
4
|
import { createCommand } from '../../utils';
|
|
5
5
|
import { BackgroundColor } from '../BackgroundColor';
|
|
6
6
|
import { ContentNormalizer, NodeFactory } from '../../services';
|
|
7
|
-
import {
|
|
7
|
+
import { TextSetting } from '../../enums';
|
|
8
8
|
|
|
9
9
|
const MockStylePreset = Extension.create({
|
|
10
|
-
name:
|
|
10
|
+
name: TextSetting.STYLE_PRESET,
|
|
11
11
|
|
|
12
12
|
addCommands() {
|
|
13
13
|
return {
|
|
@@ -35,7 +35,7 @@ describe('get background color', () => {
|
|
|
35
35
|
test('should get from selection', () => {
|
|
36
36
|
const editor = createEditor({
|
|
37
37
|
content: createContent(NodeFactory.text('hello world', [
|
|
38
|
-
NodeFactory.mark(
|
|
38
|
+
NodeFactory.mark(TextSetting.BACKGROUND_COLOR, { value: 'green' })
|
|
39
39
|
]))
|
|
40
40
|
});
|
|
41
41
|
|
|
@@ -70,7 +70,7 @@ describe('rendering', () => {
|
|
|
70
70
|
test('should render html', () => {
|
|
71
71
|
const editor = createEditor({
|
|
72
72
|
content: createContent(NodeFactory.text('hello world', [
|
|
73
|
-
NodeFactory.mark(
|
|
73
|
+
NodeFactory.mark(TextSetting.BACKGROUND_COLOR, { value: 'green' })
|
|
74
74
|
]))
|
|
75
75
|
});
|
|
76
76
|
|