@zipify/wysiwyg 1.0.0-dev.9 → 1.0.0-dev.90
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/.editorconfig +1 -1
- package/.eslintrc.js +2 -2
- package/.github/dependabot.yaml +1 -0
- package/.lintstagedrc +2 -2
- package/.release-it.json +3 -1
- package/.stylelintrc +0 -4
- package/README.md +2 -2
- package/config/jest/setupTests.js +0 -3
- package/config/vite/example.config.js +25 -0
- package/config/vite/lib.config.js +30 -0
- package/config/{webpack → vite}/settings.js +0 -0
- package/dist/wysiwyg.css +404 -373
- package/dist/wysiwyg.mjs +26014 -0
- package/example/ExampleApp.vue +35 -4
- package/example/example.js +0 -3
- package/example/{example.html → index.html} +1 -0
- package/example/pageBlocks.js +31 -0
- package/example/presets.js +2 -2
- package/example/tooltip/Tooltip.js +1 -1
- package/jest.config.js +3 -1
- package/lib/Wysiwyg.vue +73 -14
- package/lib/__tests__/utils/index.js +0 -1
- package/lib/__tests__/utils/withComponentContext.js +1 -1
- package/lib/assets/icons/background-color.svg +3 -1
- package/lib/assets/icons/font-color.svg +1 -3
- package/lib/assets/icons/link.svg +3 -0
- package/lib/assets/icons/unlink.svg +3 -0
- package/lib/components/base/Button.vue +23 -2
- package/lib/components/base/Checkbox.vue +89 -0
- package/lib/components/base/FieldLabel.vue +2 -1
- package/lib/components/base/Icon.vue +3 -3
- package/lib/components/base/Modal.vue +1 -2
- package/lib/components/base/NumberField.vue +2 -2
- package/lib/components/base/Range.vue +1 -1
- package/lib/components/base/ScrollView.vue +1 -3
- package/lib/components/base/TextField.vue +108 -0
- package/lib/components/base/__tests__/Modal.test.js +7 -2
- package/lib/components/base/__tests__/TextField.test.js +57 -0
- package/lib/components/base/__tests__/__snapshots__/TextField.test.js.snap +9 -0
- package/lib/components/base/colorPicker/ColorPicker.vue +14 -12
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +6 -6
- package/lib/components/base/colorPicker/composables/usePickerApi.js +15 -8
- package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +3 -2
- package/lib/components/base/composables/__tests__/useActivatedListener.test.js +1 -1
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +1 -1
- package/lib/components/base/composables/__tests__/useElementRef.test.js +1 -1
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +1 -1
- package/lib/components/base/composables/__tests__/useNumberValue.test.js +1 -1
- package/lib/components/base/composables/__tests__/useScrollView.test.js +1 -1
- package/lib/components/base/composables/__tests__/useTempValue.test.js +1 -1
- package/lib/components/base/composables/__tests__/useValidator.test.js +44 -0
- package/lib/components/base/composables/index.js +1 -0
- package/lib/components/base/composables/useActivatedListener.js +1 -1
- package/lib/components/base/composables/useDeselectionLock.js +1 -1
- package/lib/components/base/composables/useElementRef.js +1 -1
- package/lib/components/base/composables/useModalToggler.js +6 -2
- package/lib/components/base/composables/useScrollView.js +1 -1
- package/lib/components/base/composables/useTempValue.js +1 -1
- package/lib/components/base/composables/useValidator.js +23 -0
- package/lib/components/base/dropdown/Dropdown.vue +16 -4
- package/lib/components/base/dropdown/DropdownActivator.vue +19 -3
- package/lib/components/base/dropdown/DropdownGroup.vue +1 -1
- package/lib/components/base/dropdown/DropdownMenu.vue +1 -1
- package/lib/components/base/dropdown/DropdownOption.vue +1 -1
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +1 -1
- package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +1 -1
- package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +1 -1
- package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +1 -1
- package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +1 -1
- package/lib/components/base/dropdown/composables/useActiveOptionManager.js +1 -1
- package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +1 -1
- package/lib/components/base/index.js +3 -1
- package/lib/components/toolbar/Toolbar.vue +51 -9
- package/lib/components/toolbar/ToolbarDivider.vue +1 -1
- package/lib/components/toolbar/ToolbarFull.vue +41 -10
- package/lib/components/toolbar/ToolbarRow.vue +1 -0
- package/lib/components/toolbar/__tests__/Toolbar.test.js +6 -0
- package/lib/components/toolbar/controls/AlignmentControl.vue +1 -1
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +1 -1
- package/lib/components/toolbar/controls/BackgroundColorControl.vue +1 -1
- package/lib/components/toolbar/controls/CaseStyleControl.vue +1 -1
- package/lib/components/toolbar/controls/FontColorControl.vue +1 -1
- package/lib/components/toolbar/controls/FontFamilyControl.vue +1 -1
- package/lib/components/toolbar/controls/FontSizeControl.vue +8 -1
- package/lib/components/toolbar/controls/FontWeightControl.vue +1 -1
- package/lib/components/toolbar/controls/ItalicControl.vue +1 -1
- package/lib/components/toolbar/controls/LineHeightControl.vue +1 -1
- package/lib/components/toolbar/controls/ListControl.vue +68 -34
- package/lib/components/toolbar/controls/RemoveFormatControl.vue +1 -1
- package/lib/components/toolbar/controls/StrikeThroughControl.vue +1 -1
- package/lib/components/toolbar/controls/StylePresetControl.vue +15 -2
- package/lib/components/toolbar/controls/SuperscriptControl.vue +1 -1
- package/lib/components/toolbar/controls/UnderlineControl.vue +2 -2
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +18 -3
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +17 -1
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +5 -1
- package/lib/components/toolbar/controls/composables/useRecentFonts.js +1 -1
- package/lib/components/toolbar/controls/index.js +1 -0
- package/lib/components/toolbar/controls/link/LinkControl.vue +160 -0
- package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +69 -0
- package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +79 -0
- package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +42 -0
- package/lib/components/toolbar/controls/link/composables/__tests__/__snapshots__/useLink.test.js.snap +15 -0
- package/lib/components/toolbar/controls/link/composables/__tests__/useLink.test.js +172 -0
- package/lib/components/toolbar/controls/link/composables/index.js +1 -0
- package/lib/components/toolbar/controls/link/composables/useLink.js +82 -0
- package/lib/components/toolbar/controls/link/destination/LinkControlDestination.vue +103 -0
- package/lib/components/toolbar/controls/link/destination/LinkControlPageBlock.vue +54 -0
- package/lib/components/toolbar/controls/link/destination/LinkControlUrl.vue +52 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlPageBlock.test.js +36 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/LinkControlUrl.test.js +46 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlPageBlock.test.js.snap +9 -0
- package/lib/components/toolbar/controls/link/destination/__tests__/__snapshots__/LinkControlUrl.test.js.snap +17 -0
- package/lib/components/toolbar/controls/link/destination/index.js +1 -0
- package/lib/components/toolbar/controls/link/index.js +1 -0
- package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +1 -0
- package/lib/composables/__tests__/useEditor.test.js +5 -4
- package/lib/composables/useEditor.js +12 -9
- package/lib/composables/useToolbar.js +26 -19
- package/lib/directives/__tests__/outClick.test.js +6 -0
- package/lib/directives/outClick.js +19 -6
- package/lib/enums/Alignments.js +10 -1
- package/lib/enums/LinkDestinations.js +4 -0
- package/lib/enums/LinkTargets.js +4 -0
- package/lib/enums/TextSettings.js +3 -1
- package/lib/enums/index.js +2 -0
- package/lib/extensions/Alignment.js +22 -8
- package/lib/extensions/BackgroundColor.js +15 -7
- package/lib/extensions/DeviceManager.js +2 -5
- package/lib/extensions/FontColor.js +15 -7
- package/lib/extensions/FontFamily.js +26 -9
- package/lib/extensions/FontSize.js +33 -13
- package/lib/extensions/FontStyle.js +24 -14
- package/lib/extensions/FontWeight.js +25 -15
- package/lib/extensions/LineHeight.js +33 -29
- package/lib/extensions/Link.js +90 -0
- package/lib/extensions/StylePreset.js +20 -19
- package/lib/extensions/Superscript.js +5 -1
- package/lib/extensions/TextDecoration.js +46 -13
- package/lib/extensions/__tests__/Alignment.test.js +14 -9
- package/lib/extensions/__tests__/BackgroundColor.test.js +13 -8
- package/lib/extensions/__tests__/CaseStyle.test.js +4 -7
- package/lib/extensions/__tests__/FontColor.test.js +13 -8
- package/lib/extensions/__tests__/FontFamily.test.js +34 -10
- package/lib/extensions/__tests__/FontSize.test.js +16 -10
- package/lib/extensions/__tests__/FontStyle.test.js +13 -8
- package/lib/extensions/__tests__/FontWeight.test.js +21 -8
- package/lib/extensions/__tests__/LineHeight.test.js +25 -14
- package/lib/extensions/__tests__/Link.test.js +101 -0
- package/lib/extensions/__tests__/StylePreset.test.js +72 -10
- package/lib/extensions/__tests__/TextDecoration.test.js +53 -8
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +26 -2
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +30 -1
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +18 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +88 -1
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +33 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +25 -4
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +47 -1
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +26 -2
- package/lib/extensions/__tests__/__snapshots__/Link.test.js.snap +225 -0
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +6 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +183 -3
- package/lib/extensions/core/CopyPasteProcessor.js +10 -0
- package/lib/extensions/core/NodeProcessor.js +1 -1
- package/lib/extensions/core/TextProcessor.js +11 -24
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -7
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +4 -7
- package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -14
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +26 -0
- package/lib/extensions/core/index.js +11 -2
- package/lib/extensions/core/plugins/PastePlugin.js +57 -0
- package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
- package/lib/extensions/core/plugins/index.js +1 -0
- package/lib/extensions/index.js +46 -34
- package/lib/extensions/list/List.js +5 -4
- package/lib/extensions/list/__tests__/List.test.js +6 -10
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +60 -20
- package/lib/index.js +3 -0
- package/lib/injectionTokens.js +3 -1
- package/lib/services/ContentNormalizer.js +144 -28
- package/lib/services/ContextWidnow.js +23 -0
- package/lib/{__tests__/utils → services}/NodeFactory.js +5 -1
- package/lib/services/__tests__/ContentNormalizer.test.js +124 -8
- package/lib/services/__tests__/FavoriteColors.test.js +1 -1
- package/lib/services/index.js +2 -0
- package/lib/styles/content.css +108 -13
- package/lib/styles/helpers/offsets.css +16 -0
- package/lib/styles/variables.css +6 -0
- package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +4 -4
- package/lib/utils/__tests__/convertAlignment.test.js +16 -0
- package/lib/utils/__tests__/convertFontSize.test.js +21 -0
- package/lib/utils/__tests__/convertLineHeight.test.js +21 -0
- package/lib/utils/convertAlignment.js +12 -0
- package/lib/utils/convertColor.js +1 -1
- package/lib/utils/convertFontSize.js +8 -0
- package/lib/utils/convertLineHeight.js +17 -0
- package/lib/utils/importIcon.js +7 -6
- package/lib/utils/index.js +4 -0
- package/lib/utils/isWysiwygContent.js +12 -0
- package/lib/utils/renderInlineSetting.js +1 -1
- package/package.json +26 -30
- package/config/webpack/example.config.js +0 -88
- package/config/webpack/lib.config.js +0 -44
- package/config/webpack/loaders/index.js +0 -6
- package/config/webpack/loaders/js-loader.js +0 -5
- package/config/webpack/loaders/style-loader.js +0 -9
- package/config/webpack/loaders/svg-loader.js +0 -4
- package/config/webpack/loaders/vue-loader.js +0 -4
- package/dist/wysiwyg.js +0 -2
- package/dist/wysiwyg.js.LICENSE.txt +0 -1
- package/lib/extensions/core/inputRules/closeDoubleQuote.js +0 -6
- package/lib/extensions/core/inputRules/closeSingleQuote.js +0 -6
- package/lib/extensions/core/inputRules/copyright.js +0 -6
- package/lib/extensions/core/inputRules/ellipsis.js +0 -6
- package/lib/extensions/core/inputRules/emDash.js +0 -6
- package/lib/extensions/core/inputRules/index.js +0 -9
- package/lib/extensions/core/inputRules/openDoubleQuote.js +0 -6
- package/lib/extensions/core/inputRules/openSingleQuote.js +0 -6
- package/lib/extensions/core/inputRules/registeredTrademark.js +0 -6
- package/lib/extensions/core/inputRules/trademark.js +0 -6
|
@@ -1,22 +1,21 @@
|
|
|
1
1
|
import { Extension } from '@tiptap/vue-2';
|
|
2
2
|
import { createCommand } from '../../utils';
|
|
3
|
-
import {
|
|
4
|
-
emDash,
|
|
5
|
-
registeredTrademark,
|
|
6
|
-
trademark,
|
|
7
|
-
ellipsis,
|
|
8
|
-
openDoubleQuote,
|
|
9
|
-
openSingleQuote,
|
|
10
|
-
closeDoubleQuote,
|
|
11
|
-
closeSingleQuote,
|
|
12
|
-
copyright
|
|
13
|
-
} from './inputRules';
|
|
14
3
|
|
|
15
4
|
export const TextProcessor = Extension.create({
|
|
16
5
|
name: 'text_processor',
|
|
17
6
|
|
|
18
7
|
addCommands() {
|
|
19
8
|
return {
|
|
9
|
+
getSelectedText: createCommand(({ state }) => {
|
|
10
|
+
const { from, to } = state.selection;
|
|
11
|
+
|
|
12
|
+
return state.doc.textBetween(from, to, ' ');
|
|
13
|
+
}),
|
|
14
|
+
|
|
15
|
+
unsetMarks: createCommand(({ commands }, marks) => {
|
|
16
|
+
marks.forEach((mark) => commands.unsetMark(mark));
|
|
17
|
+
}),
|
|
18
|
+
|
|
20
19
|
transformText: createCommand(({ state }, transform) => {
|
|
21
20
|
const { selection } = state.tr;
|
|
22
21
|
|
|
@@ -41,17 +40,5 @@ export const TextProcessor = Extension.create({
|
|
|
41
40
|
});
|
|
42
41
|
})
|
|
43
42
|
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
addInputRules: () => [
|
|
47
|
-
emDash,
|
|
48
|
-
registeredTrademark,
|
|
49
|
-
trademark,
|
|
50
|
-
ellipsis,
|
|
51
|
-
openDoubleQuote,
|
|
52
|
-
openSingleQuote,
|
|
53
|
-
closeDoubleQuote,
|
|
54
|
-
closeSingleQuote,
|
|
55
|
-
copyright
|
|
56
|
-
]
|
|
43
|
+
}
|
|
57
44
|
});
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { Editor, Extension } from '@tiptap/vue-2';
|
|
2
|
-
import { NodeFactory } from '../../../__tests__/utils';
|
|
3
|
-
import { CORE_EXTENSIONS } from '../index';
|
|
4
2
|
import { NodeTypes } from '../../../enums';
|
|
5
|
-
import { ContentNormalizer } from '../../../services';
|
|
3
|
+
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
4
|
+
import { buildCoreExtensions } from '../index';
|
|
6
5
|
|
|
7
6
|
const LineHeight = Extension.create({
|
|
8
7
|
name: 'line_height',
|
|
@@ -21,11 +20,9 @@ const LineHeight = Extension.create({
|
|
|
21
20
|
});
|
|
22
21
|
|
|
23
22
|
function createEditor({ content }) {
|
|
24
|
-
const normalizer = new ContentNormalizer();
|
|
25
|
-
|
|
26
23
|
return new Editor({
|
|
27
|
-
content:
|
|
28
|
-
extensions:
|
|
24
|
+
content: ContentNormalizer.normalize(content),
|
|
25
|
+
extensions: buildCoreExtensions().concat(LineHeight) // Included to core extensions
|
|
29
26
|
});
|
|
30
27
|
}
|
|
31
28
|
|
|
@@ -1,19 +1,16 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/vue-2';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { ContentNormalizer } from '../../../services';
|
|
2
|
+
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
3
|
+
import { buildCoreExtensions } from '../index';
|
|
5
4
|
|
|
6
5
|
function createEditor() {
|
|
7
|
-
const normalizer = new ContentNormalizer();
|
|
8
|
-
|
|
9
6
|
const content = NodeFactory.doc([
|
|
10
7
|
NodeFactory.paragraph('Lorem ipsum dolor sit amet'),
|
|
11
8
|
NodeFactory.paragraph('consectetur adipisicing elit')
|
|
12
9
|
]);
|
|
13
10
|
|
|
14
11
|
return new Editor({
|
|
15
|
-
content:
|
|
16
|
-
extensions:
|
|
12
|
+
content: ContentNormalizer.normalize(content),
|
|
13
|
+
extensions: buildCoreExtensions() // included to core
|
|
17
14
|
});
|
|
18
15
|
}
|
|
19
16
|
|
|
@@ -1,29 +1,119 @@
|
|
|
1
|
-
import { Editor, Mark } from '@tiptap/vue-2';
|
|
2
|
-
import { NodeFactory } from '../../../
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { Editor, Mark, Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
3
|
+
import { NodeTypes, TextSettings } from '../../../enums';
|
|
4
|
+
import { buildCoreExtensions } from '../index';
|
|
5
|
+
|
|
6
|
+
const MockFontSize = Mark.create({
|
|
7
|
+
name: TextSettings.FONT_SIZE,
|
|
8
|
+
|
|
9
|
+
addAttributes: () => ({
|
|
10
|
+
value: { default: null }
|
|
11
|
+
}),
|
|
12
|
+
|
|
13
|
+
renderHTML: () => ['span', {}, 0]
|
|
14
|
+
});
|
|
5
15
|
|
|
6
16
|
const MockFontWeight = Mark.create({
|
|
7
|
-
name:
|
|
17
|
+
name: TextSettings.FONT_WEIGHT,
|
|
8
18
|
|
|
9
19
|
addAttributes: () => ({
|
|
10
|
-
value: {
|
|
20
|
+
value: { default: null }
|
|
11
21
|
}),
|
|
12
22
|
|
|
13
|
-
renderHTML(
|
|
14
|
-
|
|
23
|
+
renderHTML: () => ['span', {}, 0]
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const MockAlignment = Extension.create({
|
|
27
|
+
name: TextSettings.ALIGNMENT,
|
|
15
28
|
|
|
16
|
-
|
|
17
|
-
|
|
29
|
+
addGlobalAttributes: () => [
|
|
30
|
+
{
|
|
31
|
+
types: [NodeTypes.PARAGRAPH, NodeTypes.HEADING],
|
|
32
|
+
attributes: {
|
|
33
|
+
[TextSettings.ALIGNMENT]: {
|
|
34
|
+
default: null,
|
|
35
|
+
renderHTML: () => ({})
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
]
|
|
18
40
|
});
|
|
19
41
|
|
|
20
|
-
|
|
21
|
-
|
|
42
|
+
const MockBackgroundColor = Mark.create({
|
|
43
|
+
name: TextSettings.BACKGROUND_COLOR,
|
|
44
|
+
|
|
45
|
+
addAttributes: () => ({
|
|
46
|
+
value: { default: null }
|
|
47
|
+
}),
|
|
48
|
+
|
|
49
|
+
renderHTML: () => ['span', {}, 0]
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
const MockFontColor = Mark.create({
|
|
53
|
+
name: TextSettings.FONT_COLOR,
|
|
54
|
+
|
|
55
|
+
addAttributes: () => ({
|
|
56
|
+
value: { default: null }
|
|
57
|
+
}),
|
|
58
|
+
|
|
59
|
+
renderHTML: () => ['span', {}, 0]
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
const MockFontFamily = Mark.create({
|
|
63
|
+
name: TextSettings.FONT_FAMILY,
|
|
64
|
+
|
|
65
|
+
addAttributes: () => ({
|
|
66
|
+
value: { default: null }
|
|
67
|
+
}),
|
|
68
|
+
|
|
69
|
+
renderHTML: () => ['span', {}, 0]
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
const MockFontStyle = Mark.create({
|
|
73
|
+
name: TextSettings.FONT_STYLE,
|
|
74
|
+
|
|
75
|
+
addAttributes: () => ({
|
|
76
|
+
value: { default: null }
|
|
77
|
+
}),
|
|
78
|
+
|
|
79
|
+
renderHTML: () => ['span', {}, 0]
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
const MockTextDecoration = Mark.create({
|
|
83
|
+
name: TextSettings.TEXT_DECORATION,
|
|
84
|
+
|
|
85
|
+
addAttributes: () => ({
|
|
86
|
+
value: { default: null }
|
|
87
|
+
}),
|
|
22
88
|
|
|
89
|
+
renderHTML: () => ['span', {}, 0]
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
const MockSuperscript = Mark.create({
|
|
93
|
+
name: TextSettings.SUPERSCRIPT,
|
|
94
|
+
|
|
95
|
+
addAttributes: () => ({
|
|
96
|
+
value: { default: null }
|
|
97
|
+
}),
|
|
98
|
+
|
|
99
|
+
renderHTML: () => ['span', {}, 0]
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
function createEditor({ content }) {
|
|
23
103
|
return new Editor({
|
|
24
|
-
content:
|
|
104
|
+
content: ContentNormalizer.normalize(content),
|
|
25
105
|
element: document.createElement('div'),
|
|
26
|
-
extensions:
|
|
106
|
+
extensions: buildCoreExtensions().concat(
|
|
107
|
+
MockFontSize,
|
|
108
|
+
MockFontWeight,
|
|
109
|
+
MockAlignment,
|
|
110
|
+
MockBackgroundColor,
|
|
111
|
+
MockFontColor,
|
|
112
|
+
MockFontFamily,
|
|
113
|
+
MockFontStyle,
|
|
114
|
+
MockTextDecoration,
|
|
115
|
+
MockSuperscript
|
|
116
|
+
)
|
|
27
117
|
});
|
|
28
118
|
}
|
|
29
119
|
|
|
@@ -62,3 +152,38 @@ describe('transform text', () => {
|
|
|
62
152
|
expect(editor.getJSON()).toMatchSnapshot();
|
|
63
153
|
});
|
|
64
154
|
});
|
|
155
|
+
|
|
156
|
+
describe('selected text', () => {
|
|
157
|
+
test('should return selected text', () => {
|
|
158
|
+
const editor = createEditor({
|
|
159
|
+
content: NodeFactory.doc([
|
|
160
|
+
NodeFactory.paragraph('hello world')
|
|
161
|
+
])
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
editor.commands.setTextSelection({ from: 5, to: 11 });
|
|
165
|
+
|
|
166
|
+
expect(editor.commands.getSelectedText()).toEqual('o worl');
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe('unset marks', () => {
|
|
171
|
+
test('should reset all marks', () => {
|
|
172
|
+
const editor = createEditor({
|
|
173
|
+
content: NodeFactory.doc([
|
|
174
|
+
NodeFactory.paragraph([
|
|
175
|
+
NodeFactory.text('hello world', [
|
|
176
|
+
NodeFactory.mark('font_weight', { value: '700' })
|
|
177
|
+
])
|
|
178
|
+
])
|
|
179
|
+
])
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
editor.chain()
|
|
183
|
+
.selectAll()
|
|
184
|
+
.unsetMarks(TextSettings.marks)
|
|
185
|
+
.run();
|
|
186
|
+
|
|
187
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -4,6 +4,9 @@ exports[`transform text should keep text marks 1`] = `
|
|
|
4
4
|
Object {
|
|
5
5
|
"content": Array [
|
|
6
6
|
Object {
|
|
7
|
+
"attrs": Object {
|
|
8
|
+
"alignment": null,
|
|
9
|
+
},
|
|
7
10
|
"content": Array [
|
|
8
11
|
Object {
|
|
9
12
|
"marks": Array [
|
|
@@ -29,6 +32,9 @@ exports[`transform text should transform selected text 1`] = `
|
|
|
29
32
|
Object {
|
|
30
33
|
"content": Array [
|
|
31
34
|
Object {
|
|
35
|
+
"attrs": Object {
|
|
36
|
+
"alignment": null,
|
|
37
|
+
},
|
|
32
38
|
"content": Array [
|
|
33
39
|
Object {
|
|
34
40
|
"text": "hELLO world",
|
|
@@ -41,3 +47,23 @@ Object {
|
|
|
41
47
|
"type": "doc",
|
|
42
48
|
}
|
|
43
49
|
`;
|
|
50
|
+
|
|
51
|
+
exports[`unset marks should reset all marks 1`] = `
|
|
52
|
+
Object {
|
|
53
|
+
"content": Array [
|
|
54
|
+
Object {
|
|
55
|
+
"attrs": Object {
|
|
56
|
+
"alignment": null,
|
|
57
|
+
},
|
|
58
|
+
"content": Array [
|
|
59
|
+
Object {
|
|
60
|
+
"text": "hello world",
|
|
61
|
+
"type": "text",
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
"type": "paragraph",
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
"type": "doc",
|
|
68
|
+
}
|
|
69
|
+
`;
|
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
import Document from '@tiptap/extension-document';
|
|
2
2
|
import Paragraph from '@tiptap/extension-paragraph';
|
|
3
3
|
import Text from '@tiptap/extension-text';
|
|
4
|
+
import Placeholder from '@tiptap/extension-placeholder';
|
|
5
|
+
import History from '@tiptap/extension-history';
|
|
4
6
|
import { NodeProcessor } from './NodeProcessor';
|
|
5
7
|
import { TextProcessor } from './TextProcessor';
|
|
6
8
|
import { SelectionProcessor } from './SelectionProcessor';
|
|
9
|
+
import { CopyPasteProcessor } from './CopyPasteProcessor';
|
|
7
10
|
|
|
8
|
-
export const
|
|
11
|
+
export const buildCoreExtensions = () => [
|
|
9
12
|
Document,
|
|
10
13
|
Paragraph.configure({
|
|
11
14
|
HTMLAttributes: { class: 'zw-style' }
|
|
12
15
|
}),
|
|
16
|
+
Placeholder.configure({
|
|
17
|
+
placeholder: 'Type your text here...',
|
|
18
|
+
emptyNodeClass: 'zw-wysiwyg__placeholder'
|
|
19
|
+
}),
|
|
13
20
|
Text,
|
|
21
|
+
History,
|
|
14
22
|
NodeProcessor,
|
|
15
23
|
TextProcessor,
|
|
16
|
-
SelectionProcessor
|
|
24
|
+
SelectionProcessor,
|
|
25
|
+
CopyPasteProcessor
|
|
17
26
|
];
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ContentNormalizer } from '../../../services';
|
|
2
|
+
import { NodeTypes } from '../../../enums';
|
|
3
|
+
import { ProseMirrorPlugin } from './ProseMirrorPlugin';
|
|
4
|
+
|
|
5
|
+
export class PastePlugin extends ProseMirrorPlugin {
|
|
6
|
+
buildProps() {
|
|
7
|
+
return {
|
|
8
|
+
transformPastedHTML: ContentNormalizer.normalize,
|
|
9
|
+
handlePaste: this._handlePaste.bind(this)
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
_handlePaste(view, _, slice) {
|
|
14
|
+
const transaction = this._insertPastedContent(view, slice)
|
|
15
|
+
.scrollIntoView()
|
|
16
|
+
.setMeta('paste', true)
|
|
17
|
+
.setMeta('uiEvent', 'paste');
|
|
18
|
+
|
|
19
|
+
view.dispatch(transaction);
|
|
20
|
+
|
|
21
|
+
return true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
_insertPastedContent({ state, input }, slice) {
|
|
25
|
+
if (!this._isFullBlockSelected(state)) {
|
|
26
|
+
return state.tr.replaceSelection(slice);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return state.tr.replaceSelectionWith(slice.content, input.shiftKey);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
_isFullBlockSelected(state) {
|
|
33
|
+
const blocksSelection = this._expandSelectionToBlocks(state);
|
|
34
|
+
const isFromMatch = this._isMatchPosition(blocksSelection.from, state.selection.from);
|
|
35
|
+
const isToMatch = this._isMatchPosition(blocksSelection.to, state.selection.to);
|
|
36
|
+
|
|
37
|
+
return isFromMatch && isToMatch;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
_expandSelectionToBlocks({ selection, doc }) {
|
|
41
|
+
let from = selection.from;
|
|
42
|
+
let to = selection.to;
|
|
43
|
+
|
|
44
|
+
doc.nodesBetween(from, to, (node, position, parent) => {
|
|
45
|
+
if (parent.type.name !== NodeTypes.DOCUMENT) return;
|
|
46
|
+
|
|
47
|
+
from = Math.min(from, position + 1);
|
|
48
|
+
to = Math.max(to, position + node.nodeSize - 1);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
return { from, to };
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
_isMatchPosition(position1, position2) {
|
|
55
|
+
return Math.abs(position1 - position2) < 5;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { Plugin, PluginKey } from 'prosemirror-state';
|
|
2
|
+
|
|
3
|
+
export class ProseMirrorPlugin {
|
|
4
|
+
static create(options) {
|
|
5
|
+
const plugin = new this(options || {});
|
|
6
|
+
|
|
7
|
+
return new Plugin({
|
|
8
|
+
key: new PluginKey(this.name),
|
|
9
|
+
props: plugin.buildProps()
|
|
10
|
+
});
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
constructor(options) {
|
|
14
|
+
this.options = options;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
buildProps() {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PastePlugin } from './PastePlugin';
|
package/lib/extensions/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import History from '@tiptap/extension-history';
|
|
2
|
-
import { CORE_EXTENSIONS } from './core';
|
|
3
1
|
import { FontFamily } from './FontFamily';
|
|
4
2
|
import { StylePreset } from './StylePreset';
|
|
5
3
|
import { FontWeight } from './FontWeight';
|
|
@@ -13,38 +11,52 @@ import { CaseStyle } from './CaseStyle';
|
|
|
13
11
|
import { Alignment } from './Alignment';
|
|
14
12
|
import { LineHeight } from './LineHeight';
|
|
15
13
|
import { List } from './list';
|
|
14
|
+
import { Link } from './Link';
|
|
16
15
|
import { Superscript } from './Superscript';
|
|
16
|
+
import { buildCoreExtensions } from './core';
|
|
17
17
|
|
|
18
|
-
export
|
|
18
|
+
export function buildExtensions(options) {
|
|
19
|
+
const getPresetById = (id) => options.presetsRef.value.find((preset) => preset.id === id);
|
|
20
|
+
const defaultPreset = getPresetById(options.defaultPresetId);
|
|
21
|
+
const linkPreset = getPresetById(options.linkPresetId);
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
23
|
+
return buildCoreExtensions(options).concat([
|
|
24
|
+
StylePreset.configure({
|
|
25
|
+
presets: options.presetsRef,
|
|
26
|
+
defaultId: options.defaultPresetId,
|
|
27
|
+
baseClass: options.basePresetClass,
|
|
28
|
+
makeVariable: options.makePresetVariable
|
|
29
|
+
}),
|
|
30
|
+
List.configure({
|
|
31
|
+
baseClass: options.baseListClass
|
|
32
|
+
}),
|
|
33
|
+
DeviceManager.configure({
|
|
34
|
+
device: options.deviceRef
|
|
35
|
+
}),
|
|
36
|
+
FontFamily.configure({
|
|
37
|
+
fonts: options.fonts,
|
|
38
|
+
defaultFont: defaultPreset.common.font_family
|
|
39
|
+
}),
|
|
40
|
+
FontWeight,
|
|
41
|
+
FontSize.configure({
|
|
42
|
+
minSize: options.minFontSize,
|
|
43
|
+
maxSize: options.maxFontSize,
|
|
44
|
+
wrapperRef: options.wrapperRef
|
|
45
|
+
}),
|
|
46
|
+
FontColor,
|
|
47
|
+
BackgroundColor,
|
|
48
|
+
FontStyle,
|
|
49
|
+
TextDecoration,
|
|
50
|
+
CaseStyle,
|
|
51
|
+
Superscript,
|
|
52
|
+
Alignment,
|
|
53
|
+
LineHeight.configure({
|
|
54
|
+
wrapperRef: options.wrapperRef
|
|
55
|
+
}),
|
|
56
|
+
Link.configure({
|
|
57
|
+
preset: linkPreset,
|
|
58
|
+
basePresetClass: options.basePresetClass,
|
|
59
|
+
pageBlocks: options.pageBlocksRef
|
|
60
|
+
})
|
|
61
|
+
]);
|
|
62
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Node, wrappingInputRule } from '@tiptap/vue-2';
|
|
2
|
-
import { computed } from '
|
|
2
|
+
import { computed } from 'vue';
|
|
3
3
|
import { createCommand } from '../../utils';
|
|
4
4
|
import { ListTypes, NodeTypes } from '../../enums';
|
|
5
5
|
import { ListItem } from './ListItem';
|
|
@@ -18,7 +18,9 @@ export const List = Node.create({
|
|
|
18
18
|
}),
|
|
19
19
|
|
|
20
20
|
addAttributes: () => ({
|
|
21
|
-
bullet: {
|
|
21
|
+
bullet: {
|
|
22
|
+
default: { type: ListTypes.DISC }
|
|
23
|
+
}
|
|
22
24
|
}),
|
|
23
25
|
|
|
24
26
|
parseHTML() {
|
|
@@ -80,12 +82,11 @@ export const List = Node.create({
|
|
|
80
82
|
return;
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
return chain().
|
|
85
|
+
return chain().applyDefaultPreset()._addList(type).run();
|
|
84
86
|
}),
|
|
85
87
|
|
|
86
88
|
_addList: createCommand(({ chain }, type) => {
|
|
87
89
|
return chain()
|
|
88
|
-
.removePreset()
|
|
89
90
|
.toggleList(NodeTypes.LIST, NodeTypes.LIST_ITEM)
|
|
90
91
|
.setBlockAttributes('bullet', { type })
|
|
91
92
|
.run();
|
|
@@ -1,24 +1,20 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/vue-2';
|
|
2
|
-
import { ref } from '@vue/composition-api';
|
|
3
|
-
import { NodeFactory } from '../../../__tests__/utils';
|
|
4
2
|
import { ListTypes } from '../../../enums';
|
|
5
|
-
import { CORE_EXTENSIONS } from '../../core';
|
|
6
3
|
import { StylePreset } from '../../StylePreset';
|
|
7
4
|
import { List } from '../List';
|
|
8
|
-
import { ContentNormalizer } from '../../../services';
|
|
5
|
+
import { ContentNormalizer, NodeFactory } from '../../../services';
|
|
6
|
+
import { buildCoreExtensions } from '../../core';
|
|
9
7
|
|
|
10
8
|
function createEditor({ content }) {
|
|
11
|
-
const normalizer = new ContentNormalizer();
|
|
12
|
-
|
|
13
9
|
return new Editor({
|
|
14
|
-
content:
|
|
10
|
+
content: ContentNormalizer.normalize(content),
|
|
15
11
|
element: document.createElement('div'),
|
|
16
|
-
extensions:
|
|
12
|
+
extensions: buildCoreExtensions().concat(
|
|
17
13
|
List.configure({
|
|
18
14
|
baseClass: 'zw-list--'
|
|
19
15
|
}),
|
|
20
16
|
StylePreset.configure({
|
|
21
|
-
|
|
17
|
+
presets: [
|
|
22
18
|
{
|
|
23
19
|
id: 'regular-1',
|
|
24
20
|
common: {},
|
|
@@ -26,7 +22,7 @@ function createEditor({ content }) {
|
|
|
26
22
|
tablet: {},
|
|
27
23
|
desktop: {}
|
|
28
24
|
}
|
|
29
|
-
]
|
|
25
|
+
],
|
|
30
26
|
defaultId: 'regular-1',
|
|
31
27
|
baseClass: 'zw ts-'
|
|
32
28
|
})
|