@zipify/wysiwyg 1.0.0-dev.1
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 +18 -0
- package/.eslintrc.js +253 -0
- package/.github/actions/deploy-example/action.yaml +61 -0
- package/.github/actions/lint-css/action.yaml +15 -0
- package/.github/actions/lint-js/action.yaml +22 -0
- package/.github/actions/setup/action.yaml +19 -0
- package/.github/actions/unit-tests/action.yaml +13 -0
- package/.github/actions/unit-tests/jest.config.js +8 -0
- package/.github/dependabot.yaml +17 -0
- package/.github/pull_request_template.md +17 -0
- package/.github/workflows/frontend-ci.yaml +120 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +12 -0
- package/.release-it.json +6 -0
- package/.stylelintrc +110 -0
- package/README.md +61 -0
- package/babel.config.js +15 -0
- package/ci/example/deploy.sh +25 -0
- package/config/jest/TestEnvironment.js +27 -0
- package/config/jest/matchers/index.js +6 -0
- package/config/jest/matchers/toElementHasStyle.js +27 -0
- package/config/jest/matchers/toVueContainComponent.js +20 -0
- package/config/jest/matchers/toVueContainElement.js +34 -0
- package/config/jest/matchers/toVueContainLazyComponent.js +19 -0
- package/config/jest/matchers/toVueEmpty.js +16 -0
- package/config/jest/matchers/toVuexActionHasBeenDispatched.js +19 -0
- package/config/jest/setupMatchers.js +4 -0
- package/config/jest/setupTests.js +32 -0
- package/config/jest/typing.d.ts +14 -0
- package/config/svgo.js +22 -0
- package/config/webpack/example.config.js +86 -0
- package/config/webpack/loaders/index.js +6 -0
- package/config/webpack/loaders/js-loader.js +5 -0
- package/config/webpack/loaders/style-loader.js +7 -0
- package/config/webpack/loaders/svg-loader.js +4 -0
- package/config/webpack/loaders/vue-loader.js +4 -0
- package/config/webpack/settings.js +9 -0
- package/example/ExampleApp.vue +136 -0
- package/example/example.html +17 -0
- package/example/example.js +19 -0
- package/example/fonts.js +474 -0
- package/example/presets.js +245 -0
- package/example/tooltip/Tooltip.js +241 -0
- package/example/tooltip/TooltipManager.js +132 -0
- package/example/tooltip/index.js +3 -0
- package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +73 -0
- package/example/tooltip/modifiers/index.js +1 -0
- package/example/tooltip/tooltip.css +95 -0
- package/jest.config.js +17 -0
- package/lib/Wysiwyg.vue +156 -0
- package/lib/__mocks__/svgMock.js +1 -0
- package/lib/__tests__/utils/NodeFactory.js +67 -0
- package/lib/__tests__/utils/index.js +4 -0
- package/lib/__tests__/utils/setReadonlyProperty.js +9 -0
- package/lib/__tests__/utils/waitAsyncOperation.js +6 -0
- package/lib/__tests__/utils/withComponentContext.js +14 -0
- package/lib/assets/icons.svg +69 -0
- package/lib/components/base/Button.vue +117 -0
- package/lib/components/base/ButtonToggle.vue +40 -0
- package/lib/components/base/FieldLabel.vue +28 -0
- package/lib/components/base/Icon.vue +67 -0
- package/lib/components/base/Modal.vue +116 -0
- package/lib/components/base/NumberField.vue +242 -0
- package/lib/components/base/Range.vue +196 -0
- package/lib/components/base/ScrollView.vue +60 -0
- package/lib/components/base/__tests__/Button.test.js +50 -0
- package/lib/components/base/__tests__/Icon.test.js +56 -0
- package/lib/components/base/__tests__/Modal.test.js +69 -0
- package/lib/components/base/__tests__/Range.test.js +39 -0
- package/lib/components/base/colorPicker/ColorPicker.vue +93 -0
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +81 -0
- package/lib/components/base/colorPicker/composables/index.js +2 -0
- package/lib/components/base/colorPicker/composables/usePickerApi.js +35 -0
- package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +25 -0
- package/lib/components/base/colorPicker/index.js +1 -0
- package/lib/components/base/composables/__tests__/useActivatedListener.test.js +89 -0
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +80 -0
- package/lib/components/base/composables/__tests__/useElementRef.test.js +29 -0
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +55 -0
- package/lib/components/base/composables/__tests__/useNumberValue.test.js +153 -0
- package/lib/components/base/composables/__tests__/useScrollView.test.js +43 -0
- package/lib/components/base/composables/__tests__/useTempValue.test.js +38 -0
- package/lib/components/base/composables/index.js +7 -0
- package/lib/components/base/composables/useActivatedListener.js +23 -0
- package/lib/components/base/composables/useDeselectionLock.js +35 -0
- package/lib/components/base/composables/useElementRef.js +5 -0
- package/lib/components/base/composables/useModalToggler.js +58 -0
- package/lib/components/base/composables/useNumberValue.js +53 -0
- package/lib/components/base/composables/useScrollView.js +22 -0
- package/lib/components/base/composables/useTempValue.js +11 -0
- package/lib/components/base/dropdown/Dropdown.vue +88 -0
- package/lib/components/base/dropdown/DropdownActivator.vue +81 -0
- package/lib/components/base/dropdown/DropdownDivider.vue +21 -0
- package/lib/components/base/dropdown/DropdownGroup.vue +55 -0
- package/lib/components/base/dropdown/DropdownMenu.vue +62 -0
- package/lib/components/base/dropdown/DropdownOption.vue +91 -0
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +54 -0
- package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +67 -0
- package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +81 -0
- package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +41 -0
- package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +24 -0
- package/lib/components/base/dropdown/composables/index.js +2 -0
- package/lib/components/base/dropdown/composables/useActiveOptionManager.js +25 -0
- package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +5 -0
- package/lib/components/base/dropdown/index.js +2 -0
- package/lib/components/base/dropdown/injectionTokens.js +5 -0
- package/lib/components/base/index.js +11 -0
- package/lib/components/index.js +1 -0
- package/lib/components/toolbar/Toolbar.vue +56 -0
- package/lib/components/toolbar/ToolbarDevice.vue +35 -0
- package/lib/components/toolbar/ToolbarDivider.vue +50 -0
- package/lib/components/toolbar/ToolbarFull.vue +94 -0
- package/lib/components/toolbar/ToolbarGroup.vue +18 -0
- package/lib/components/toolbar/ToolbarRow.vue +19 -0
- package/lib/components/toolbar/__tests__/Toolbar.test.js +33 -0
- package/lib/components/toolbar/__tests__/ToolbarDivider.test.js +26 -0
- package/lib/components/toolbar/controls/AlignmentControl.vue +72 -0
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +67 -0
- package/lib/components/toolbar/controls/BackgroundColorControl.vue +48 -0
- package/lib/components/toolbar/controls/CaseStyleControl.vue +54 -0
- package/lib/components/toolbar/controls/FontColorControl.vue +48 -0
- package/lib/components/toolbar/controls/FontFamilyControl.vue +96 -0
- package/lib/components/toolbar/controls/FontSizeControl.vue +45 -0
- package/lib/components/toolbar/controls/FontWeightControl.vue +43 -0
- package/lib/components/toolbar/controls/ItalicControl.vue +47 -0
- package/lib/components/toolbar/controls/LineHeightControl.vue +102 -0
- package/lib/components/toolbar/controls/ListControl.vue +86 -0
- package/lib/components/toolbar/controls/RemoveFormatControl.vue +37 -0
- package/lib/components/toolbar/controls/StrikeThroughControl.vue +44 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +95 -0
- package/lib/components/toolbar/controls/SuperscriptControl.vue +44 -0
- package/lib/components/toolbar/controls/UnderlineControl.vue +44 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +51 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +77 -0
- package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +59 -0
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +43 -0
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +59 -0
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +57 -0
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +47 -0
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +45 -0
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +63 -0
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +120 -0
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +82 -0
- package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +34 -0
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +44 -0
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +129 -0
- package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +44 -0
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +44 -0
- package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +69 -0
- package/lib/components/toolbar/controls/composables/index.js +1 -0
- package/lib/components/toolbar/controls/composables/useRecentFonts.js +18 -0
- package/lib/components/toolbar/controls/index.js +16 -0
- package/lib/components/toolbar/index.js +1 -0
- package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +24 -0
- package/lib/composables/__tests__/useEditor.test.js +67 -0
- package/lib/composables/__tests__/useToolbar.test.js +56 -0
- package/lib/composables/index.js +2 -0
- package/lib/composables/useEditor.js +21 -0
- package/lib/composables/useToolbar.js +44 -0
- package/lib/directives/__tests__/outClick.test.js +86 -0
- package/lib/directives/__tests__/tooltip.test.js +39 -0
- package/lib/directives/index.js +2 -0
- package/lib/directives/outClick.js +37 -0
- package/lib/directives/tooltip.js +7 -0
- package/lib/enums/Alignments.js +6 -0
- package/lib/enums/CaseStyles.js +5 -0
- package/lib/enums/Devices.js +15 -0
- package/lib/enums/ListTypes.js +23 -0
- package/lib/enums/NodeTypes.js +12 -0
- package/lib/enums/TextSettings.js +30 -0
- package/lib/enums/index.js +6 -0
- package/lib/extensions/Alignment.js +67 -0
- package/lib/extensions/BackgroundColor.js +28 -0
- package/lib/extensions/CaseStyle.js +36 -0
- package/lib/extensions/DeviceManager.js +16 -0
- package/lib/extensions/FontColor.js +36 -0
- package/lib/extensions/FontFamily.js +62 -0
- package/lib/extensions/FontSize.js +74 -0
- package/lib/extensions/FontStyle.js +62 -0
- package/lib/extensions/FontWeight.js +56 -0
- package/lib/extensions/LineHeight.js +60 -0
- package/lib/extensions/StylePreset.js +168 -0
- package/lib/extensions/Superscript.js +5 -0
- package/lib/extensions/TextDecoration.js +97 -0
- package/lib/extensions/__tests__/Alignment.test.js +107 -0
- package/lib/extensions/__tests__/BackgroundColor.test.js +75 -0
- package/lib/extensions/__tests__/CaseStyle.test.js +58 -0
- package/lib/extensions/__tests__/FontColor.test.js +85 -0
- package/lib/extensions/__tests__/FontFamily.test.js +171 -0
- package/lib/extensions/__tests__/FontSize.test.js +183 -0
- package/lib/extensions/__tests__/FontStyle.test.js +136 -0
- package/lib/extensions/__tests__/FontWeight.test.js +151 -0
- package/lib/extensions/__tests__/LineHeight.test.js +106 -0
- package/lib/extensions/__tests__/StylePreset.test.js +400 -0
- package/lib/extensions/__tests__/TextDecoration.test.js +258 -0
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +29 -0
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +28 -0
- package/lib/extensions/__tests__/__snapshots__/CaseStyle.test.js.snap +69 -0
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +28 -0
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +158 -0
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +140 -0
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +87 -0
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +140 -0
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +29 -0
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +310 -0
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +206 -0
- package/lib/extensions/core/NodeProcessor.js +32 -0
- package/lib/extensions/core/SelectionProcessor.js +37 -0
- package/lib/extensions/core/TextProcessor.js +57 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +120 -0
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +78 -0
- package/lib/extensions/core/__tests__/TextProcessor.test.js +61 -0
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +93 -0
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +43 -0
- package/lib/extensions/core/index.js +17 -0
- package/lib/extensions/core/inputRules/closeDoubleQuote.js +6 -0
- package/lib/extensions/core/inputRules/closeSingleQuote.js +6 -0
- package/lib/extensions/core/inputRules/copyright.js +6 -0
- package/lib/extensions/core/inputRules/ellipsis.js +6 -0
- package/lib/extensions/core/inputRules/emDash.js +6 -0
- package/lib/extensions/core/inputRules/index.js +9 -0
- package/lib/extensions/core/inputRules/openDoubleQuote.js +6 -0
- package/lib/extensions/core/inputRules/openSingleQuote.js +6 -0
- package/lib/extensions/core/inputRules/registeredTrademark.js +6 -0
- package/lib/extensions/core/inputRules/trademark.js +6 -0
- package/lib/extensions/index.js +49 -0
- package/lib/extensions/list/List.js +81 -0
- package/lib/extensions/list/ListItem.js +12 -0
- package/lib/extensions/list/__tests__/List.test.js +130 -0
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +212 -0
- package/lib/extensions/list/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib/injectionTokens.js +7 -0
- package/lib/models/Font.js +37 -0
- package/lib/models/__tests__/Font.test.js +58 -0
- package/lib/models/index.js +1 -0
- package/lib/services/FavoriteColors.js +6 -0
- package/lib/services/JsonSerializer.js +15 -0
- package/lib/services/Storage.js +49 -0
- package/lib/services/index.js +3 -0
- package/lib/styles/content.css +39 -0
- package/lib/styles/helpers/common.css +3 -0
- package/lib/styles/helpers/offsets.css +3 -0
- package/lib/styles/helpers/text.css +6 -0
- package/lib/styles/main.css +5 -0
- package/lib/styles/variables.css +57 -0
- package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +40 -0
- package/lib/utils/__tests__/capitalize.test.js +11 -0
- package/lib/utils/__tests__/renderInlineSetting.test.js +39 -0
- package/lib/utils/capitalize.js +3 -0
- package/lib/utils/createCommand.js +3 -0
- package/lib/utils/createKeyboardShortcut.js +6 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/renderInlineSetting.js +17 -0
- package/package.json +75 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`apply decoration should apply decoration 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"content": Array [
|
|
6
|
+
Object {
|
|
7
|
+
"content": Array [
|
|
8
|
+
Object {
|
|
9
|
+
"marks": Array [
|
|
10
|
+
Object {
|
|
11
|
+
"attrs": Object {
|
|
12
|
+
"strike_through": false,
|
|
13
|
+
"underline": true,
|
|
14
|
+
},
|
|
15
|
+
"type": "text_decoration",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
"text": "hello world",
|
|
19
|
+
"type": "text",
|
|
20
|
+
},
|
|
21
|
+
],
|
|
22
|
+
"type": "paragraph",
|
|
23
|
+
},
|
|
24
|
+
],
|
|
25
|
+
"type": "doc",
|
|
26
|
+
}
|
|
27
|
+
`;
|
|
28
|
+
|
|
29
|
+
exports[`apply decoration should remove decoration 1`] = `
|
|
30
|
+
Object {
|
|
31
|
+
"content": Array [
|
|
32
|
+
Object {
|
|
33
|
+
"content": Array [
|
|
34
|
+
Object {
|
|
35
|
+
"marks": Array [
|
|
36
|
+
Object {
|
|
37
|
+
"attrs": Object {
|
|
38
|
+
"strike_through": false,
|
|
39
|
+
"underline": true,
|
|
40
|
+
},
|
|
41
|
+
"type": "text_decoration",
|
|
42
|
+
},
|
|
43
|
+
],
|
|
44
|
+
"text": "hello world",
|
|
45
|
+
"type": "text",
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
"type": "paragraph",
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
"type": "doc",
|
|
52
|
+
}
|
|
53
|
+
`;
|
|
54
|
+
|
|
55
|
+
exports[`apply decoration should remove mark if no decoration 1`] = `
|
|
56
|
+
Object {
|
|
57
|
+
"content": Array [
|
|
58
|
+
Object {
|
|
59
|
+
"content": Array [
|
|
60
|
+
Object {
|
|
61
|
+
"text": "hello world",
|
|
62
|
+
"type": "text",
|
|
63
|
+
},
|
|
64
|
+
],
|
|
65
|
+
"type": "paragraph",
|
|
66
|
+
},
|
|
67
|
+
],
|
|
68
|
+
"type": "doc",
|
|
69
|
+
}
|
|
70
|
+
`;
|
|
71
|
+
|
|
72
|
+
exports[`apply decoration should second decoration 1`] = `
|
|
73
|
+
Object {
|
|
74
|
+
"content": Array [
|
|
75
|
+
Object {
|
|
76
|
+
"content": Array [
|
|
77
|
+
Object {
|
|
78
|
+
"marks": Array [
|
|
79
|
+
Object {
|
|
80
|
+
"attrs": Object {
|
|
81
|
+
"strike_through": true,
|
|
82
|
+
"underline": true,
|
|
83
|
+
},
|
|
84
|
+
"type": "text_decoration",
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
"text": "hello world",
|
|
88
|
+
"type": "text",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
"type": "paragraph",
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
"type": "doc",
|
|
95
|
+
}
|
|
96
|
+
`;
|
|
97
|
+
|
|
98
|
+
exports[`apply decoration strike through should toggle to removed 1`] = `
|
|
99
|
+
Object {
|
|
100
|
+
"content": Array [
|
|
101
|
+
Object {
|
|
102
|
+
"content": Array [
|
|
103
|
+
Object {
|
|
104
|
+
"marks": Array [
|
|
105
|
+
Object {
|
|
106
|
+
"attrs": Object {
|
|
107
|
+
"strike_through": false,
|
|
108
|
+
"underline": true,
|
|
109
|
+
},
|
|
110
|
+
"type": "text_decoration",
|
|
111
|
+
},
|
|
112
|
+
],
|
|
113
|
+
"text": "hello world",
|
|
114
|
+
"type": "text",
|
|
115
|
+
},
|
|
116
|
+
],
|
|
117
|
+
"type": "paragraph",
|
|
118
|
+
},
|
|
119
|
+
],
|
|
120
|
+
"type": "doc",
|
|
121
|
+
}
|
|
122
|
+
`;
|
|
123
|
+
|
|
124
|
+
exports[`apply decoration strike through should toggle to used 1`] = `
|
|
125
|
+
Object {
|
|
126
|
+
"content": Array [
|
|
127
|
+
Object {
|
|
128
|
+
"content": Array [
|
|
129
|
+
Object {
|
|
130
|
+
"marks": Array [
|
|
131
|
+
Object {
|
|
132
|
+
"attrs": Object {
|
|
133
|
+
"strike_through": true,
|
|
134
|
+
"underline": false,
|
|
135
|
+
},
|
|
136
|
+
"type": "text_decoration",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
"text": "hello world",
|
|
140
|
+
"type": "text",
|
|
141
|
+
},
|
|
142
|
+
],
|
|
143
|
+
"type": "paragraph",
|
|
144
|
+
},
|
|
145
|
+
],
|
|
146
|
+
"type": "doc",
|
|
147
|
+
}
|
|
148
|
+
`;
|
|
149
|
+
|
|
150
|
+
exports[`apply decoration underline should toggle to removed 1`] = `
|
|
151
|
+
Object {
|
|
152
|
+
"content": Array [
|
|
153
|
+
Object {
|
|
154
|
+
"content": Array [
|
|
155
|
+
Object {
|
|
156
|
+
"marks": Array [
|
|
157
|
+
Object {
|
|
158
|
+
"attrs": Object {
|
|
159
|
+
"strike_through": true,
|
|
160
|
+
"underline": false,
|
|
161
|
+
},
|
|
162
|
+
"type": "text_decoration",
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
"text": "hello world",
|
|
166
|
+
"type": "text",
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
"type": "paragraph",
|
|
170
|
+
},
|
|
171
|
+
],
|
|
172
|
+
"type": "doc",
|
|
173
|
+
}
|
|
174
|
+
`;
|
|
175
|
+
|
|
176
|
+
exports[`apply decoration underline should toggle to used 1`] = `
|
|
177
|
+
Object {
|
|
178
|
+
"content": Array [
|
|
179
|
+
Object {
|
|
180
|
+
"content": Array [
|
|
181
|
+
Object {
|
|
182
|
+
"marks": Array [
|
|
183
|
+
Object {
|
|
184
|
+
"attrs": Object {
|
|
185
|
+
"strike_through": false,
|
|
186
|
+
"underline": true,
|
|
187
|
+
},
|
|
188
|
+
"type": "text_decoration",
|
|
189
|
+
},
|
|
190
|
+
],
|
|
191
|
+
"text": "hello world",
|
|
192
|
+
"type": "text",
|
|
193
|
+
},
|
|
194
|
+
],
|
|
195
|
+
"type": "paragraph",
|
|
196
|
+
},
|
|
197
|
+
],
|
|
198
|
+
"type": "doc",
|
|
199
|
+
}
|
|
200
|
+
`;
|
|
201
|
+
|
|
202
|
+
exports[`rendering should render both 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: underline line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
|
|
203
|
+
|
|
204
|
+
exports[`rendering should render strike through only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: line-through;\\" class=\\"zw-style\\">hello world</span></p>"`;
|
|
205
|
+
|
|
206
|
+
exports[`rendering should render underline only 1`] = `"<p class=\\"zw-style\\"><span style=\\"--zw-text-decoration: underline;\\" class=\\"zw-style\\">hello world</span></p>"`;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { computed } from '@vue/composition-api';
|
|
3
|
+
import { createCommand } from '../../utils';
|
|
4
|
+
import { NodeTypes } from '../../enums';
|
|
5
|
+
|
|
6
|
+
export const NodeProcessor = Extension.create({
|
|
7
|
+
name: 'node_processor',
|
|
8
|
+
|
|
9
|
+
addCommands() {
|
|
10
|
+
return {
|
|
11
|
+
setBlockAttributes: createCommand(({ commands }, name, attrs, defaults = {}) => {
|
|
12
|
+
const current = commands.getBlockAttributes(name).value ?? {};
|
|
13
|
+
|
|
14
|
+
for (const type of NodeTypes.blocks) {
|
|
15
|
+
commands.updateAttributes(type, {
|
|
16
|
+
[name]: { ...defaults, ...current, ...attrs }
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}),
|
|
20
|
+
|
|
21
|
+
getBlockAttributes: createCommand(({ editor }, name, defaults) => computed(() => {
|
|
22
|
+
let attrs = Object.assign({}, defaults || {});
|
|
23
|
+
|
|
24
|
+
for (const type of NodeTypes.blocks) {
|
|
25
|
+
Object.assign(attrs, editor.getAttributes(type)?.[name] || {});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return Object.keys(attrs).length ? attrs : null;
|
|
29
|
+
}))
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { createCommand } from '../../utils';
|
|
3
|
+
import { NodeTypes } from '../../enums';
|
|
4
|
+
|
|
5
|
+
export const SelectionProcessor = Extension.create({
|
|
6
|
+
name: 'selection_processor',
|
|
7
|
+
|
|
8
|
+
addStorage: () => ({
|
|
9
|
+
selection: null
|
|
10
|
+
}),
|
|
11
|
+
|
|
12
|
+
addCommands() {
|
|
13
|
+
return {
|
|
14
|
+
storeSelection: createCommand(({ state }) => {
|
|
15
|
+
this.storage.selection = state.selection;
|
|
16
|
+
}),
|
|
17
|
+
|
|
18
|
+
restoreSelection: createCommand(({ commands }) => {
|
|
19
|
+
commands.setTextSelection(this.storage.selection);
|
|
20
|
+
}),
|
|
21
|
+
|
|
22
|
+
expandSelectionToBlock: createCommand(({ state, commands }) => {
|
|
23
|
+
let from = state.selection.from;
|
|
24
|
+
let to = state.selection.to;
|
|
25
|
+
|
|
26
|
+
state.doc.nodesBetween(from, to, (node, position, parent) => {
|
|
27
|
+
if (parent.type.name !== NodeTypes.DOCUMENT) return;
|
|
28
|
+
|
|
29
|
+
from = Math.min(from, position + 1);
|
|
30
|
+
to = Math.max(to, position + node.nodeSize - 1);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
commands.setTextSelection({ from, to });
|
|
34
|
+
})
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
});
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { Extension } from '@tiptap/vue-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
|
+
|
|
15
|
+
export const TextProcessor = Extension.create({
|
|
16
|
+
name: 'text_processor',
|
|
17
|
+
|
|
18
|
+
addCommands() {
|
|
19
|
+
return {
|
|
20
|
+
transformText: createCommand(({ state }, transform) => {
|
|
21
|
+
const { selection } = state.tr;
|
|
22
|
+
|
|
23
|
+
if (selection.from === selection.to) return;
|
|
24
|
+
|
|
25
|
+
state.doc.nodesBetween(selection.from, selection.to, (node, position) => {
|
|
26
|
+
if (!node.isText) return;
|
|
27
|
+
|
|
28
|
+
const startPosition = Math.max(position, selection.from);
|
|
29
|
+
const endPosition = Math.min(position + node.nodeSize, selection.to);
|
|
30
|
+
|
|
31
|
+
const substringFrom = Math.max(0, selection.from - position);
|
|
32
|
+
const substringTo = Math.max(0, selection.to - position);
|
|
33
|
+
|
|
34
|
+
const updatedText = transform({
|
|
35
|
+
text: node.textContent.substring(substringFrom, substringTo),
|
|
36
|
+
position: { start: startPosition, end: endPosition }
|
|
37
|
+
});
|
|
38
|
+
const updatedNode = state.schema.text(updatedText, node.marks);
|
|
39
|
+
|
|
40
|
+
state.tr.replaceWith(startPosition, endPosition, updatedNode);
|
|
41
|
+
});
|
|
42
|
+
})
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
|
|
46
|
+
addInputRules: () => [
|
|
47
|
+
emDash,
|
|
48
|
+
registeredTrademark,
|
|
49
|
+
trademark,
|
|
50
|
+
ellipsis,
|
|
51
|
+
openDoubleQuote,
|
|
52
|
+
openSingleQuote,
|
|
53
|
+
closeDoubleQuote,
|
|
54
|
+
closeSingleQuote,
|
|
55
|
+
copyright
|
|
56
|
+
]
|
|
57
|
+
});
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { Editor, Extension } from '@tiptap/vue-2';
|
|
2
|
+
import { NodeFactory } from '../../../__tests__/utils';
|
|
3
|
+
import { CORE_EXTENSIONS } from '../index';
|
|
4
|
+
import { NodeTypes } from '../../../enums';
|
|
5
|
+
|
|
6
|
+
const LineHeight = Extension.create({
|
|
7
|
+
name: 'line_height',
|
|
8
|
+
|
|
9
|
+
addGlobalAttributes: () => [
|
|
10
|
+
{
|
|
11
|
+
types: [NodeTypes.PARAGRAPH],
|
|
12
|
+
attributes: {
|
|
13
|
+
line_height: {
|
|
14
|
+
isRequired: false,
|
|
15
|
+
renderHTML: (attrs) => ({ style: `line-height: ${attrs.line_height}` })
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
function createEditor({ content }) {
|
|
23
|
+
return new Editor({
|
|
24
|
+
content,
|
|
25
|
+
extensions: CORE_EXTENSIONS.concat(LineHeight) // Included to core extensions
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe('block attributes', () => {
|
|
30
|
+
const createContent = (attrs) => NodeFactory.doc([
|
|
31
|
+
NodeFactory.paragraph(attrs, [
|
|
32
|
+
NodeFactory.text('hello world')
|
|
33
|
+
])
|
|
34
|
+
]);
|
|
35
|
+
|
|
36
|
+
const DEFAULTS = {
|
|
37
|
+
mobile: null,
|
|
38
|
+
tablet: null,
|
|
39
|
+
desktop: null
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
test('should get attributes', () => {
|
|
43
|
+
const editor = createEditor({
|
|
44
|
+
content: createContent({
|
|
45
|
+
line_height: { mobile: '1.2' }
|
|
46
|
+
})
|
|
47
|
+
});
|
|
48
|
+
const attrs = editor.commands.getBlockAttributes('line_height');
|
|
49
|
+
|
|
50
|
+
expect(attrs.value).toEqual({ mobile: '1.2' });
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
test('should get attributes with defaults', () => {
|
|
54
|
+
const editor = createEditor({
|
|
55
|
+
content: createContent({
|
|
56
|
+
line_height: { mobile: '1.2' }
|
|
57
|
+
})
|
|
58
|
+
});
|
|
59
|
+
const attrs = editor.commands.getBlockAttributes('line_height', DEFAULTS);
|
|
60
|
+
|
|
61
|
+
expect(attrs.value).toEqual({
|
|
62
|
+
mobile: '1.2',
|
|
63
|
+
tablet: null,
|
|
64
|
+
desktop: null
|
|
65
|
+
});
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('should get null if no attributes set', () => {
|
|
69
|
+
const editor = createEditor({
|
|
70
|
+
content: createContent({ line_height: null })
|
|
71
|
+
});
|
|
72
|
+
const attrs = editor.commands.getBlockAttributes('line_height');
|
|
73
|
+
|
|
74
|
+
expect(attrs.value).toEqual(null);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
test('should set attributes', () => {
|
|
78
|
+
const editor = createEditor({
|
|
79
|
+
content: createContent({ line_height: null })
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
editor.chain().selectAll().setBlockAttributes('line_height', { mobile: '1.3' }).run();
|
|
83
|
+
|
|
84
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
85
|
+
});
|
|
86
|
+
|
|
87
|
+
test('should set attributes with defaults', () => {
|
|
88
|
+
const editor = createEditor({
|
|
89
|
+
content: createContent({ line_height: null })
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
editor.chain().selectAll().setBlockAttributes('line_height', { mobile: '1.3' }, DEFAULTS).run();
|
|
93
|
+
|
|
94
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
test('should update attributes', () => {
|
|
98
|
+
const editor = createEditor({
|
|
99
|
+
content: createContent({
|
|
100
|
+
line_height: { mobile: '1.1' }
|
|
101
|
+
})
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
editor.chain().selectAll().setBlockAttributes('line_height', { mobile: '1.3' }).run();
|
|
105
|
+
|
|
106
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
test('should update attributes with defaults', () => {
|
|
110
|
+
const editor = createEditor({
|
|
111
|
+
content: createContent({
|
|
112
|
+
line_height: { mobile: '1.1' }
|
|
113
|
+
})
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
editor.chain().selectAll().setBlockAttributes('line_height', { mobile: '1.3' }, DEFAULTS).run();
|
|
117
|
+
|
|
118
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { Editor } from '@tiptap/vue-2';
|
|
2
|
+
import { CORE_EXTENSIONS } from '../index';
|
|
3
|
+
import { NodeFactory } from '../../../__tests__/utils';
|
|
4
|
+
|
|
5
|
+
function createEditor() {
|
|
6
|
+
return new Editor({
|
|
7
|
+
content: NodeFactory.doc([
|
|
8
|
+
NodeFactory.paragraph('Lorem ipsum dolor sit amet'),
|
|
9
|
+
NodeFactory.paragraph('consectetur adipisicing elit')
|
|
10
|
+
]),
|
|
11
|
+
extensions: CORE_EXTENSIONS // included to core
|
|
12
|
+
});
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
describe('store/restore selection', () => {
|
|
16
|
+
const getStoredSelection = (editor) => editor.storage.selection_processor.selection;
|
|
17
|
+
|
|
18
|
+
test('should store selection', () => {
|
|
19
|
+
const editor = createEditor();
|
|
20
|
+
|
|
21
|
+
editor
|
|
22
|
+
.chain()
|
|
23
|
+
.setTextSelection({ from: 10, to: 20 })
|
|
24
|
+
.storeSelection()
|
|
25
|
+
.selectAll()
|
|
26
|
+
.run();
|
|
27
|
+
|
|
28
|
+
expect(getStoredSelection(editor)).toEqual(
|
|
29
|
+
expect.objectContaining({ from: 10, to: 20 })
|
|
30
|
+
);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
test('should restore selection', () => {
|
|
34
|
+
const editor = createEditor();
|
|
35
|
+
|
|
36
|
+
editor
|
|
37
|
+
.chain()
|
|
38
|
+
.setTextSelection({ from: 10, to: 20 })
|
|
39
|
+
.storeSelection()
|
|
40
|
+
.selectAll()
|
|
41
|
+
.restoreSelection()
|
|
42
|
+
.run();
|
|
43
|
+
|
|
44
|
+
expect(editor.state.selection).toEqual(
|
|
45
|
+
expect.objectContaining({ from: 10, to: 20 })
|
|
46
|
+
);
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
describe('expand selection to block', () => {
|
|
51
|
+
test('should exand selection to one block', () => {
|
|
52
|
+
const editor = createEditor();
|
|
53
|
+
|
|
54
|
+
editor
|
|
55
|
+
.chain()
|
|
56
|
+
.setTextSelection({ from: 10, to: 20 })
|
|
57
|
+
.expandSelectionToBlock()
|
|
58
|
+
.run();
|
|
59
|
+
|
|
60
|
+
expect(editor.state.selection).toEqual(
|
|
61
|
+
expect.objectContaining({ from: 1, to: 27 })
|
|
62
|
+
);
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('should exand selection to multiple blocks', () => {
|
|
66
|
+
const editor = createEditor();
|
|
67
|
+
|
|
68
|
+
editor
|
|
69
|
+
.chain()
|
|
70
|
+
.setTextSelection({ from: 10, to: 30 })
|
|
71
|
+
.expandSelectionToBlock()
|
|
72
|
+
.run();
|
|
73
|
+
|
|
74
|
+
expect(editor.state.selection).toEqual(
|
|
75
|
+
expect.objectContaining({ from: 1, to: 57 })
|
|
76
|
+
);
|
|
77
|
+
});
|
|
78
|
+
});
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { Editor, Mark } from '@tiptap/vue-2';
|
|
2
|
+
import { NodeFactory } from '../../../__tests__/utils';
|
|
3
|
+
import { CORE_EXTENSIONS } from '../index';
|
|
4
|
+
|
|
5
|
+
const MockFontWeight = Mark.create({
|
|
6
|
+
name: 'font_weight',
|
|
7
|
+
|
|
8
|
+
addAttributes: () => ({
|
|
9
|
+
value: { required: true }
|
|
10
|
+
}),
|
|
11
|
+
|
|
12
|
+
renderHTML(context) {
|
|
13
|
+
const { value } = context.HTMLAttributes;
|
|
14
|
+
|
|
15
|
+
return ['span', { style: `font-weight: ${value}` }, 0];
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
function createEditor({ content }) {
|
|
20
|
+
return new Editor({
|
|
21
|
+
content,
|
|
22
|
+
element: document.createElement('div'),
|
|
23
|
+
extensions: CORE_EXTENSIONS.concat(MockFontWeight)
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
describe('transform text', () => {
|
|
28
|
+
test('should transform selected text', () => {
|
|
29
|
+
const editor = createEditor({
|
|
30
|
+
content: NodeFactory.doc([
|
|
31
|
+
NodeFactory.paragraph('hello world')
|
|
32
|
+
])
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
editor.chain()
|
|
36
|
+
.setTextSelection({ from: 2, to: 6 })
|
|
37
|
+
.transformText(({ text }) => text.toUpperCase())
|
|
38
|
+
.run();
|
|
39
|
+
|
|
40
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
test('should keep text marks', () => {
|
|
44
|
+
const editor = createEditor({
|
|
45
|
+
content: NodeFactory.doc([
|
|
46
|
+
NodeFactory.paragraph([
|
|
47
|
+
NodeFactory.text('hello world', [
|
|
48
|
+
NodeFactory.mark('font_weight', { value: '700' })
|
|
49
|
+
])
|
|
50
|
+
])
|
|
51
|
+
])
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
editor.chain()
|
|
55
|
+
.setTextSelection({ from: 2, to: 6 })
|
|
56
|
+
.transformText(({ text }) => text.toUpperCase())
|
|
57
|
+
.run();
|
|
58
|
+
|
|
59
|
+
expect(editor.getJSON()).toMatchSnapshot();
|
|
60
|
+
});
|
|
61
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
|
2
|
+
|
|
3
|
+
exports[`block attributes should set attributes 1`] = `
|
|
4
|
+
Object {
|
|
5
|
+
"content": Array [
|
|
6
|
+
Object {
|
|
7
|
+
"attrs": Object {
|
|
8
|
+
"line_height": Object {
|
|
9
|
+
"mobile": "1.3",
|
|
10
|
+
},
|
|
11
|
+
},
|
|
12
|
+
"content": Array [
|
|
13
|
+
Object {
|
|
14
|
+
"text": "hello world",
|
|
15
|
+
"type": "text",
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
"type": "paragraph",
|
|
19
|
+
},
|
|
20
|
+
],
|
|
21
|
+
"type": "doc",
|
|
22
|
+
}
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
exports[`block attributes should set attributes with defaults 1`] = `
|
|
26
|
+
Object {
|
|
27
|
+
"content": Array [
|
|
28
|
+
Object {
|
|
29
|
+
"attrs": Object {
|
|
30
|
+
"line_height": Object {
|
|
31
|
+
"desktop": null,
|
|
32
|
+
"mobile": "1.3",
|
|
33
|
+
"tablet": null,
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
"content": Array [
|
|
37
|
+
Object {
|
|
38
|
+
"text": "hello world",
|
|
39
|
+
"type": "text",
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
"type": "paragraph",
|
|
43
|
+
},
|
|
44
|
+
],
|
|
45
|
+
"type": "doc",
|
|
46
|
+
}
|
|
47
|
+
`;
|
|
48
|
+
|
|
49
|
+
exports[`block attributes should update attributes 1`] = `
|
|
50
|
+
Object {
|
|
51
|
+
"content": Array [
|
|
52
|
+
Object {
|
|
53
|
+
"attrs": Object {
|
|
54
|
+
"line_height": Object {
|
|
55
|
+
"mobile": "1.3",
|
|
56
|
+
},
|
|
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
|
+
`;
|
|
70
|
+
|
|
71
|
+
exports[`block attributes should update attributes with defaults 1`] = `
|
|
72
|
+
Object {
|
|
73
|
+
"content": Array [
|
|
74
|
+
Object {
|
|
75
|
+
"attrs": Object {
|
|
76
|
+
"line_height": Object {
|
|
77
|
+
"desktop": null,
|
|
78
|
+
"mobile": "1.3",
|
|
79
|
+
"tablet": null,
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
"content": Array [
|
|
83
|
+
Object {
|
|
84
|
+
"text": "hello world",
|
|
85
|
+
"type": "text",
|
|
86
|
+
},
|
|
87
|
+
],
|
|
88
|
+
"type": "paragraph",
|
|
89
|
+
},
|
|
90
|
+
],
|
|
91
|
+
"type": "doc",
|
|
92
|
+
}
|
|
93
|
+
`;
|