@zipify/wysiwyg 1.0.0-dev.4 → 1.0.0-dev.42
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/.eslintignore +1 -0
- package/.eslintrc.js +2 -2
- package/.github/dependabot.yaml +1 -0
- package/.lintstagedrc +2 -2
- package/.release-it.json +3 -2
- package/.stylelintignore +1 -0
- package/.stylelintrc +0 -4
- package/README.md +5 -3
- package/config/jest/setupTests.js +7 -4
- package/config/vite/lib.config.js +31 -0
- package/config/vite/settings.js +9 -0
- package/config/webpack/example.config.js +2 -0
- package/config/webpack/lib.config.js +43 -0
- package/config/webpack/loaders/style-loader.js +3 -1
- package/config/webpack/loaders/svg-loader.js +1 -1
- package/dist/wysiwyg.css +1 -0
- package/dist/wysiwyg.mjs +18198 -0
- package/example/ExampleApp.vue +52 -33
- package/example/example.js +25 -2
- package/example/pageBlocks.js +31 -0
- package/example/presets.js +4 -2
- package/lib/Wysiwyg.vue +42 -22
- package/lib/__tests__/utils/withComponentContext.js +1 -1
- package/lib/assets/icons/alignment-center.svg +3 -0
- package/lib/assets/icons/alignment-justify.svg +3 -0
- package/lib/assets/icons/alignment-left.svg +3 -0
- package/lib/assets/icons/alignment-right.svg +3 -0
- package/lib/assets/icons/arrow.svg +3 -0
- package/lib/assets/icons/background-color.svg +3 -0
- package/lib/assets/icons/case-style.svg +3 -0
- package/lib/assets/icons/font-color.svg +5 -0
- package/lib/assets/icons/italic.svg +3 -0
- package/lib/assets/icons/line-height.svg +3 -0
- package/lib/assets/icons/link.svg +3 -0
- package/lib/assets/icons/list-circle.svg +3 -0
- package/lib/assets/icons/list-decimal.svg +3 -0
- package/lib/assets/icons/list-disc.svg +3 -0
- package/lib/assets/icons/list-latin.svg +3 -0
- package/lib/assets/icons/list-roman.svg +3 -0
- package/lib/assets/icons/list-square.svg +3 -0
- package/lib/assets/icons/remove-format.svg +3 -0
- package/lib/assets/icons/reset-styles.svg +3 -0
- package/lib/assets/icons/strike-through.svg +3 -0
- package/lib/assets/icons/superscript.svg +3 -0
- package/lib/assets/icons/underline.svg +3 -0
- package/lib/assets/icons/unlink.svg +3 -0
- package/lib/components/base/Button.vue +22 -2
- package/lib/components/base/Checkbox.vue +89 -0
- package/lib/components/base/FieldLabel.vue +2 -1
- package/lib/components/base/Icon.vue +19 -11
- 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 +2 -2
- package/lib/components/base/TextField.vue +106 -0
- package/lib/components/base/__tests__/Icon.test.js +6 -13
- package/lib/components/base/__tests__/Modal.test.js +8 -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 +1 -1
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +1 -1
- package/lib/components/base/colorPicker/composables/usePickerApi.js +1 -1
- 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/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 +1 -1
- 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 +19 -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 +49 -9
- package/lib/components/toolbar/ToolbarDivider.vue +1 -1
- package/lib/components/toolbar/ToolbarFull.vue +10 -2
- package/lib/components/toolbar/__tests__/Toolbar.test.js +8 -1
- 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 +2 -6
- 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 +1 -1
- 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 +1 -1
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +1 -1
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +1 -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 +152 -0
- package/lib/components/toolbar/controls/link/LinkControlApply.vue +35 -0
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +67 -0
- package/lib/components/toolbar/controls/link/composables/index.js +1 -0
- package/lib/components/toolbar/controls/link/composables/useLink.js +61 -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/index.js +1 -0
- package/lib/components/toolbar/controls/link/index.js +1 -0
- package/lib/composables/__tests__/useEditor.test.js +15 -6
- package/lib/composables/useEditor.js +13 -8
- package/lib/composables/useToolbar.js +14 -29
- package/lib/directives/outClick.js +20 -4
- 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 -4
- package/lib/extensions/BackgroundColor.js +17 -2
- package/lib/extensions/DeviceManager.js +2 -5
- package/lib/extensions/FontColor.js +17 -2
- package/lib/extensions/FontFamily.js +27 -3
- package/lib/extensions/FontSize.js +29 -4
- package/lib/extensions/FontStyle.js +24 -3
- package/lib/extensions/FontWeight.js +34 -2
- package/lib/extensions/LineHeight.js +30 -4
- package/lib/extensions/Link.js +101 -0
- package/lib/extensions/StylePreset.js +38 -15
- package/lib/extensions/TextDecoration.js +30 -4
- package/lib/extensions/__tests__/Alignment.test.js +32 -5
- package/lib/extensions/__tests__/BackgroundColor.test.js +39 -4
- package/lib/extensions/__tests__/CaseStyle.test.js +4 -3
- package/lib/extensions/__tests__/FontColor.test.js +39 -4
- package/lib/extensions/__tests__/FontFamily.test.js +60 -6
- package/lib/extensions/__tests__/FontSize.test.js +40 -5
- package/lib/extensions/__tests__/FontStyle.test.js +47 -4
- package/lib/extensions/__tests__/FontWeight.test.js +67 -4
- package/lib/extensions/__tests__/LineHeight.test.js +51 -5
- package/lib/extensions/__tests__/StylePreset.test.js +144 -6
- package/lib/extensions/__tests__/TextDecoration.test.js +88 -4
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +70 -2
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +121 -1
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +109 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +179 -1
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +132 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +142 -1
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +179 -1
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +118 -2
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +171 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +300 -3
- package/lib/extensions/core/CopyPasteProcessor.js +10 -0
- package/lib/extensions/core/NodeProcessor.js +1 -1
- package/lib/extensions/core/TextProcessor.js +10 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +4 -3
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +9 -6
- package/lib/extensions/core/__tests__/TextProcessor.test.js +139 -10
- 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 +48 -0
- package/lib/extensions/core/plugins/ProseMirrorPlugin.js +20 -0
- package/lib/extensions/core/plugins/index.js +1 -0
- package/lib/extensions/index.js +41 -33
- package/lib/extensions/list/List.js +35 -1
- package/lib/extensions/list/__tests__/List.test.js +117 -8
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +481 -0
- package/lib/injectionTokens.js +2 -1
- package/lib/services/ContentNormalizer.js +157 -0
- package/lib/services/ContextWidnow.js +23 -0
- package/lib/services/Storage.js +1 -13
- package/lib/services/__tests__/ContentNormalizer.test.js +74 -0
- package/lib/services/__tests__/FavoriteColors.test.js +20 -0
- package/lib/services/__tests__/JsonSerializer.test.js +23 -0
- package/lib/services/__tests__/Storage.test.js +79 -0
- package/lib/services/index.js +2 -0
- package/lib/styles/content.css +96 -9
- 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__/convertColor.test.js +19 -0
- package/lib/utils/__tests__/createKeyboardShortcut.test.js +25 -0
- package/lib/utils/__tests__/renderInlineSetting.test.js +26 -0
- package/lib/utils/convertColor.js +7 -0
- package/lib/utils/importIcon.js +13 -0
- package/lib/utils/index.js +2 -0
- package/lib/utils/renderInlineSetting.js +2 -2
- package/package.json +21 -16
- package/lib/assets/icons.svg +0 -69
- package/lib/composables/__tests__/useToolbar.test.js +0 -56
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { ContentNormalizer } from '../ContentNormalizer';
|
|
2
|
+
import { NodeFactory } from '../../__tests__/utils';
|
|
3
|
+
|
|
4
|
+
describe('normalize text content', () => {
|
|
5
|
+
test('should ignore json content', () => {
|
|
6
|
+
const content = NodeFactory.doc([NodeFactory.paragraph('Test')]);
|
|
7
|
+
|
|
8
|
+
expect(ContentNormalizer.normalize(content)).toBe(content);
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
test('should flat structure', () => {
|
|
12
|
+
const input = '<p style="text-align: center; color: rgb(255, 255, 255);"><span style="background-color: rgb(255, 0, 0);">lore<span style="color: rgb(0, 0, 0);">m ip</span>sum</span></p>';
|
|
13
|
+
const output = '<p style="text-align: center;">' +
|
|
14
|
+
'<span style="background-color: rgb(255, 0, 0); color: rgb(255, 255, 255);">lore</span>' +
|
|
15
|
+
'<span style="color: rgb(0, 0, 0); background-color: rgb(255, 0, 0);">m ip</span>' +
|
|
16
|
+
'<span style="background-color: rgb(255, 0, 0); color: rgb(255, 255, 255);">sum</span>' +
|
|
17
|
+
'</p>';
|
|
18
|
+
|
|
19
|
+
expect(ContentNormalizer.normalize(input)).toBe(output);
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
test('should move styles from paragraph to text', () => {
|
|
23
|
+
const input = '<p style="background-color: red;">lorem ipsum</p>';
|
|
24
|
+
const output = '<p><span style="background-color: red;">lorem ipsum</span></p>';
|
|
25
|
+
|
|
26
|
+
expect(ContentNormalizer.normalize(input)).toBe(output);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should move styles from paragraph to unstyled text', () => {
|
|
30
|
+
const input = '<p style="background-color: red;"><span style="background-color: #000;">lorem</span> ipsum <span style="color: white;">one</span></p>';
|
|
31
|
+
const output = '<p>' +
|
|
32
|
+
'<span style="background-color: #000;">lorem</span>' +
|
|
33
|
+
'<span style="background-color: red;"> ipsum </span>' +
|
|
34
|
+
'<span style="color: white; background-color: red;">one</span' +
|
|
35
|
+
'></p>';
|
|
36
|
+
|
|
37
|
+
expect(ContentNormalizer.normalize(input)).toBe(output);
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
test('should wrap list content in paragraph', () => {
|
|
41
|
+
const input = '<ul><li style="line-height: 2;">lorem impsum</li></ul>';
|
|
42
|
+
const output = '<ul><li><p style="line-height: 2;"><span>lorem impsum</span></p></li></ul>';
|
|
43
|
+
|
|
44
|
+
expect(ContentNormalizer.normalize(input)).toBe(output);
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
test('should keep order in list nodes', () => {
|
|
48
|
+
const input = '<ul><li style="line-height: 2;"><span style="font-weight: 700">lorem</span> impsum</li></ul>';
|
|
49
|
+
const output = '<ul>' +
|
|
50
|
+
'<li>' +
|
|
51
|
+
'<p style="line-height: 2;"><span style="font-weight: 700">lorem</span><span> impsum</span></p>' +
|
|
52
|
+
'</li>' +
|
|
53
|
+
'</ul>';
|
|
54
|
+
|
|
55
|
+
expect(ContentNormalizer.normalize(input)).toBe(output);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
test('should wrap non paragraph list content', () => {
|
|
59
|
+
const input = '<ul>' +
|
|
60
|
+
'<li style="line-height: 2;">' +
|
|
61
|
+
'<span style="font-weight: 700">lorem</span> impsum' +
|
|
62
|
+
'<p>paragraph text</p>' +
|
|
63
|
+
'</li>' +
|
|
64
|
+
'</ul>';
|
|
65
|
+
const output = '<ul>' +
|
|
66
|
+
'<li>' +
|
|
67
|
+
'<p style="line-height: 2;"><span style="font-weight: 700">lorem</span><span> impsum</span></p>' +
|
|
68
|
+
'<p style="line-height: 2;"><span>paragraph text</span></p>' +
|
|
69
|
+
'</li>' +
|
|
70
|
+
'</ul>';
|
|
71
|
+
|
|
72
|
+
expect(ContentNormalizer.normalize(input)).toBe(output);
|
|
73
|
+
});
|
|
74
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { ref } from 'vue';
|
|
2
|
+
import { FavoriteColors } from '../FavoriteColors';
|
|
3
|
+
|
|
4
|
+
function createService({ colors, onUpdate }) {
|
|
5
|
+
return new FavoriteColors({
|
|
6
|
+
listRef: ref(colors ?? []),
|
|
7
|
+
triggerUpdate: onUpdate
|
|
8
|
+
});
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
describe('trigger update', () => {
|
|
12
|
+
test('should trigger colors update', () => {
|
|
13
|
+
const onUpdate = jest.fn();
|
|
14
|
+
const service = createService({ onUpdate });
|
|
15
|
+
|
|
16
|
+
service.triggerUpdate(['red']);
|
|
17
|
+
|
|
18
|
+
expect(onUpdate).toHaveBeenCalledWith(['red']);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { JsonSerializer } from '../JsonSerializer';
|
|
2
|
+
|
|
3
|
+
describe('decode', () => {
|
|
4
|
+
test('should decode json', () => {
|
|
5
|
+
const json = JsonSerializer.decode('{ "test": 1 }');
|
|
6
|
+
|
|
7
|
+
expect(json).toEqual({ test: 1 });
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
test('should return null on error', () => {
|
|
11
|
+
const json = JsonSerializer.decode('{ "tes');
|
|
12
|
+
|
|
13
|
+
expect(json).toBe(null);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
describe('encode', () => {
|
|
18
|
+
test('should encode object to json', () => {
|
|
19
|
+
const json = JsonSerializer.encode({ test: 1 });
|
|
20
|
+
|
|
21
|
+
expect(json).toBe('{"test":1}');
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { Storage } from '../Storage';
|
|
2
|
+
|
|
3
|
+
const createNativeStorage = (data) => ({
|
|
4
|
+
data: data ?? {},
|
|
5
|
+
setItem: jest.fn(function (key, data) {
|
|
6
|
+
this.data[key] = data;
|
|
7
|
+
}),
|
|
8
|
+
getItem: jest.fn(function (key) {
|
|
9
|
+
return this.data[key] || null;
|
|
10
|
+
})
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
function createStorage({ storage }) {
|
|
14
|
+
return new Storage(storage ?? createNativeStorage());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
describe('get item', () => {
|
|
18
|
+
test('should return null if no data', () => {
|
|
19
|
+
const storage = createStorage({
|
|
20
|
+
storage: createNativeStorage({})
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
expect(storage.getItem('test')).toBe(null);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
test('should parse json', () => {
|
|
27
|
+
const storage = createStorage({
|
|
28
|
+
storage: createNativeStorage({
|
|
29
|
+
'zp.test': '{ "test": 1 }'
|
|
30
|
+
})
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
expect(storage.getItem('test')).toEqual({ test: 1 });
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('should handle error in private mode', () => {
|
|
37
|
+
const nativeStorage = createNativeStorage({});
|
|
38
|
+
const storage = createStorage({ storage: nativeStorage });
|
|
39
|
+
const error = new Error('private mode');
|
|
40
|
+
|
|
41
|
+
nativeStorage.getItem.mockImplementation(() => { throw error; });
|
|
42
|
+
storage.getItem('test');
|
|
43
|
+
|
|
44
|
+
// eslint-disable-next-line no-console
|
|
45
|
+
expect(console.error).toHaveBeenCalledWith(error);
|
|
46
|
+
});
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
describe('set item', () => {
|
|
50
|
+
test('should set item to storage', () => {
|
|
51
|
+
const nativeStorage = createNativeStorage({});
|
|
52
|
+
const storage = createStorage({ storage: nativeStorage });
|
|
53
|
+
|
|
54
|
+
storage.setItem('test', 'hello');
|
|
55
|
+
|
|
56
|
+
expect(nativeStorage.data).toEqual({ 'zp.test': '"hello"' });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
test('should stringify json', () => {
|
|
60
|
+
const nativeStorage = createNativeStorage({});
|
|
61
|
+
const storage = createStorage({ storage: nativeStorage });
|
|
62
|
+
|
|
63
|
+
storage.setItem('test', { test: 1 });
|
|
64
|
+
|
|
65
|
+
expect(nativeStorage.data).toEqual({ 'zp.test': '{"test":1}' });
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
test('should handle error in private mode', () => {
|
|
69
|
+
const nativeStorage = createNativeStorage({});
|
|
70
|
+
const storage = createStorage({ storage: nativeStorage });
|
|
71
|
+
const error = new Error('private mode');
|
|
72
|
+
|
|
73
|
+
nativeStorage.getItem.mockImplementation(() => { throw error; });
|
|
74
|
+
storage.setItem('test', 'test');
|
|
75
|
+
|
|
76
|
+
// eslint-disable-next-line no-console
|
|
77
|
+
expect(console.error).toHaveBeenCalledWith(error);
|
|
78
|
+
});
|
|
79
|
+
});
|
package/lib/services/index.js
CHANGED
package/lib/styles/content.css
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
outline: none;
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
+
.zw-wysiwyg__placeholder:first-child:last-child::before {
|
|
6
|
+
content: attr(data-placeholder);
|
|
7
|
+
color: rgb(var(--zw-color-n70));
|
|
8
|
+
float: left;
|
|
9
|
+
height: 0;
|
|
10
|
+
pointer-events: none;
|
|
11
|
+
}
|
|
12
|
+
|
|
5
13
|
.zw-style {
|
|
6
14
|
font-weight: var(--zw-font-weight, var(--zw-preset-font-weight));
|
|
7
15
|
font-family: var(--zw-font-family, var(--zw-preset-font-family));
|
|
@@ -14,26 +22,105 @@
|
|
|
14
22
|
@media (min-width: 1200px) {
|
|
15
23
|
|
|
16
24
|
.zw-style {
|
|
17
|
-
font-size: var(--zw-
|
|
18
|
-
text-align: var(--zw-
|
|
19
|
-
line-height: var(--zw-
|
|
25
|
+
font-size: var(--zw-font-size-desktop, var(--zw-preset-desktop-font-size));
|
|
26
|
+
text-align: var(--zw-text-align-desktop, var(--zw-preset-desktop-text-align));
|
|
27
|
+
line-height: var(--zw-line-height-desktop, var(--zw-preset-desktop-line-height));
|
|
20
28
|
}
|
|
21
29
|
}
|
|
22
30
|
|
|
23
31
|
@media (min-width: 769px) and (max-width: 1199.98px) {
|
|
24
32
|
|
|
25
33
|
.zw-style {
|
|
26
|
-
font-size: var(--zw-
|
|
27
|
-
text-align: var(--zw-
|
|
28
|
-
line-height: var(--zw-
|
|
34
|
+
font-size: var(--zw-font-size-tablet, var(--zw-preset-tablet-font-size));
|
|
35
|
+
text-align: var(--zw-text-align-tablet, var(--zw-preset-tablet-text-align));
|
|
36
|
+
line-height: var(--zw-line-height-tablet, var(--zw-preset-tablet-line-height));
|
|
29
37
|
}
|
|
30
38
|
}
|
|
31
39
|
|
|
32
40
|
@media (max-width: 768.98px) {
|
|
33
41
|
|
|
34
42
|
.zw-style {
|
|
35
|
-
font-size: var(--zw-
|
|
36
|
-
text-align: var(--zw-
|
|
37
|
-
line-height: var(--zw-
|
|
43
|
+
font-size: var(--zw-font-size-mobile, var(--zw-preset-mobile-font-size));
|
|
44
|
+
text-align: var(--zw-text-align-mobile, var(--zw-preset-mobile-text-align));
|
|
45
|
+
line-height: var(--zw-line-height-mobile, var(--zw-preset-mobile-line-height));
|
|
38
46
|
}
|
|
39
47
|
}
|
|
48
|
+
|
|
49
|
+
/* ProseMirror styles */
|
|
50
|
+
|
|
51
|
+
.ProseMirror {
|
|
52
|
+
position: relative;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
.ProseMirror {
|
|
56
|
+
word-wrap: break-word;
|
|
57
|
+
white-space: pre-wrap;
|
|
58
|
+
white-space: break-spaces;
|
|
59
|
+
-webkit-font-variant-ligatures: none;
|
|
60
|
+
font-variant-ligatures: none;
|
|
61
|
+
font-feature-settings: "liga" 0; /* the above doesn't seem to work in Edge */
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
.ProseMirror [contenteditable="false"] {
|
|
65
|
+
white-space: normal;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
.ProseMirror [contenteditable="false"] [contenteditable="true"] {
|
|
69
|
+
white-space: pre-wrap;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.ProseMirror pre {
|
|
73
|
+
white-space: pre-wrap;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
img.ProseMirror-separator {
|
|
77
|
+
display: inline !important;
|
|
78
|
+
border: none !important;
|
|
79
|
+
margin: 0 !important;
|
|
80
|
+
width: 1px !important;
|
|
81
|
+
height: 1px !important;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
.ProseMirror-gapcursor {
|
|
85
|
+
display: none;
|
|
86
|
+
pointer-events: none;
|
|
87
|
+
position: absolute;
|
|
88
|
+
margin: 0;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.ProseMirror-gapcursor::after {
|
|
92
|
+
content: "";
|
|
93
|
+
display: block;
|
|
94
|
+
position: absolute;
|
|
95
|
+
top: -2px;
|
|
96
|
+
width: 20px;
|
|
97
|
+
border-top: 1px solid #000;
|
|
98
|
+
animation: ProseMirror-cursor-blink 1.1s steps(2, start) infinite;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@keyframes ProseMirror-cursor-blink {
|
|
102
|
+
|
|
103
|
+
to {
|
|
104
|
+
visibility: hidden;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
.ProseMirror-hideselection *::selection {
|
|
109
|
+
background: transparent;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
.ProseMirror-hideselection *::-moz-selection {
|
|
113
|
+
background: transparent;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.ProseMirror-hideselection * {
|
|
117
|
+
caret-color: transparent;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
.ProseMirror-focused .ProseMirror-gapcursor {
|
|
121
|
+
display: block;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
.tippy-box[data-animation=fade][data-state=hidden] {
|
|
125
|
+
opacity: 0
|
|
126
|
+
}
|
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
.zw-margin-bottom--xxs {
|
|
2
|
+
margin-bottom: var(--zw-offset-xxs);
|
|
3
|
+
}
|
|
4
|
+
|
|
1
5
|
.zw-margin-bottom--xs {
|
|
2
6
|
margin-bottom: var(--zw-offset-xs);
|
|
3
7
|
}
|
|
8
|
+
|
|
9
|
+
.zw-margin-bottom--sm {
|
|
10
|
+
margin-bottom: var(--zw-offset-sm);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.zw-margin-bottom--md {
|
|
14
|
+
margin-bottom: var(--zw-offset-md);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
.zw-margin-right--xs {
|
|
18
|
+
margin-right: var(--zw-offset-xs);
|
|
19
|
+
}
|
package/lib/styles/variables.css
CHANGED
|
@@ -8,13 +8,17 @@
|
|
|
8
8
|
--zw-color-n80: 196, 196, 196; /* #C4C4C4 */
|
|
9
9
|
--zw-color-n85: 217, 217, 217; /* #D9D9D9 */
|
|
10
10
|
--zw-color-n90: 230, 230, 230; /* #E6E6E6 */
|
|
11
|
+
--zw-color-n200: 194, 200, 209; /* #C2C8D1 */
|
|
11
12
|
--zw-color-black: 0, 0, 0;
|
|
12
13
|
--zw-color-white: 255, 255, 255;
|
|
14
|
+
--zw-color-green: 59, 180, 74; /* #3BB44A */
|
|
15
|
+
--zw-color-red: 234, 58, 58; /* #EA3A3A */
|
|
13
16
|
|
|
14
17
|
--zw-offset-xxs: 4px;
|
|
15
18
|
--zw-offset-xs: 8px;
|
|
16
19
|
--zw-offset-xsm: 12px;
|
|
17
20
|
--zw-offset-sm: 16px;
|
|
21
|
+
--zw-offset-md: 24px;
|
|
18
22
|
|
|
19
23
|
--zw-font-weight-thin: 400;
|
|
20
24
|
--zw-font-weight-semibold: 500;
|
|
@@ -42,6 +46,8 @@ $builder-N90: #E6E6E6;
|
|
|
42
46
|
$builder-N94: #F0F0F0;
|
|
43
47
|
$builder-N96: #F5F5F5;
|
|
44
48
|
$builder-N98: #FAFAFA;
|
|
49
|
+
$builder-N200: #C2C8D1;
|
|
50
|
+
$builder-R50: #EA3A3A;
|
|
45
51
|
|
|
46
52
|
$font-size-xxs: 12px;
|
|
47
53
|
$font-size-xs: 14px;
|
|
@@ -5,7 +5,7 @@ Array [
|
|
|
5
5
|
"span",
|
|
6
6
|
Object {
|
|
7
7
|
"class": "zw-style",
|
|
8
|
-
"style": "--zw-mobile-font-size:
|
|
8
|
+
"style": "--zw-mobile-font-size:12px;--zw-tablet-font-size:14px;--zw-desktop-font-size:16px;",
|
|
9
9
|
},
|
|
10
10
|
0,
|
|
11
11
|
]
|
|
@@ -16,7 +16,7 @@ Array [
|
|
|
16
16
|
"span",
|
|
17
17
|
Object {
|
|
18
18
|
"class": "zw-style",
|
|
19
|
-
"style": "--zw-desktop-font-size:
|
|
19
|
+
"style": "--zw-desktop-font-size:16px;",
|
|
20
20
|
},
|
|
21
21
|
0,
|
|
22
22
|
]
|
|
@@ -27,7 +27,7 @@ Array [
|
|
|
27
27
|
"span",
|
|
28
28
|
Object {
|
|
29
29
|
"class": "zw-style",
|
|
30
|
-
"style": "--zw-font-size:
|
|
30
|
+
"style": "--zw-font-size:12px;",
|
|
31
31
|
},
|
|
32
32
|
0,
|
|
33
33
|
]
|
|
@@ -35,6 +35,6 @@ Array [
|
|
|
35
35
|
|
|
36
36
|
exports[`render settings should render unwrapped styles 1`] = `
|
|
37
37
|
Object {
|
|
38
|
-
"style": "--zw-desktop-font-size:
|
|
38
|
+
"style": "--zw-desktop-font-size:16px;",
|
|
39
39
|
}
|
|
40
40
|
`;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { convertColor } from '../convertColor';
|
|
2
|
+
|
|
3
|
+
describe('convert color', () => {
|
|
4
|
+
test('should convert alias to color', () => {
|
|
5
|
+
expect(convertColor('red')).toBe('#FF0000');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
test('should convert short hex to full', () => {
|
|
9
|
+
expect(convertColor('#F00')).toBe('#FF0000');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('should convert short hex with alpha to rgba', () => {
|
|
13
|
+
expect(convertColor('#F003')).toBe('rgba(255, 0, 0, 20%)');
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('should convert rgba from float to percent', () => {
|
|
17
|
+
expect(convertColor('rgba(255, 0, 0, 0.2)')).toBe('rgba(255, 0, 0, 20%)');
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createKeyboardShortcut } from '../createKeyboardShortcut';
|
|
2
|
+
|
|
3
|
+
describe('create shortcut', () => {
|
|
4
|
+
test('should bind command', () => {
|
|
5
|
+
const editor = {
|
|
6
|
+
commands: { toggleBold: jest.fn() }
|
|
7
|
+
};
|
|
8
|
+
const shortcut = createKeyboardShortcut('toggleBold');
|
|
9
|
+
|
|
10
|
+
shortcut({ editor });
|
|
11
|
+
|
|
12
|
+
expect(editor.commands.toggleBold).toHaveBeenCalled();
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should bind command with arguments', () => {
|
|
16
|
+
const editor = {
|
|
17
|
+
commands: { applyAlignment: jest.fn() }
|
|
18
|
+
};
|
|
19
|
+
const shortcut = createKeyboardShortcut('applyAlignment', 'left');
|
|
20
|
+
|
|
21
|
+
shortcut({ editor });
|
|
22
|
+
|
|
23
|
+
expect(editor.commands.applyAlignment).toHaveBeenCalledWith('left');
|
|
24
|
+
});
|
|
25
|
+
});
|
|
@@ -27,6 +27,16 @@ describe('render settings', () => {
|
|
|
27
27
|
expect(result).toMatchSnapshot();
|
|
28
28
|
});
|
|
29
29
|
|
|
30
|
+
test('should render no attributes if all styles empty', () => {
|
|
31
|
+
const result = renderMark({
|
|
32
|
+
mobile_font_size: null,
|
|
33
|
+
tablet_font_size: null,
|
|
34
|
+
desktop_font_size: null
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
expect(result[1]).toEqual({});
|
|
38
|
+
});
|
|
39
|
+
|
|
30
40
|
test('should render unwrapped styles', () => {
|
|
31
41
|
const result = renderInlineSetting({
|
|
32
42
|
mobile_font_size: '',
|
|
@@ -36,4 +46,20 @@ describe('render settings', () => {
|
|
|
36
46
|
|
|
37
47
|
expect(result).toMatchSnapshot();
|
|
38
48
|
});
|
|
49
|
+
|
|
50
|
+
test('should return null if no styles', () => {
|
|
51
|
+
const result = renderInlineSetting({});
|
|
52
|
+
|
|
53
|
+
expect(result).toBe(null);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
test('should return null if all styles empty', () => {
|
|
57
|
+
const result = renderInlineSetting({
|
|
58
|
+
mobile_font_size: null,
|
|
59
|
+
tablet_font_size: null,
|
|
60
|
+
desktop_font_size: null
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
expect(result).toBe(null);
|
|
64
|
+
});
|
|
39
65
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
const modules = import.meta.glob('../assets/icons/*.svg', { as: 'raw', eager: true });
|
|
2
|
+
|
|
3
|
+
export function importIcon(name) {
|
|
4
|
+
const icon = modules[`../assets/icons/${name}.svg`];
|
|
5
|
+
|
|
6
|
+
if (!icon) {
|
|
7
|
+
// eslint-disable-next-line no-console
|
|
8
|
+
console.warn(`[WSWG] Cannot resolve ${name} icon`);
|
|
9
|
+
return '';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
return icon;
|
|
13
|
+
}
|
package/lib/utils/index.js
CHANGED
|
@@ -2,3 +2,5 @@ export { createCommand } from './createCommand';
|
|
|
2
2
|
export { renderInlineSetting, renderMark } from './renderInlineSetting';
|
|
3
3
|
export { capitalize } from './capitalize';
|
|
4
4
|
export { createKeyboardShortcut } from './createKeyboardShortcut';
|
|
5
|
+
export { convertColor } from './convertColor';
|
|
6
|
+
export { importIcon } from './importIcon';
|
|
@@ -4,7 +4,7 @@ export function renderInlineSetting(setting) {
|
|
|
4
4
|
|
|
5
5
|
const property = name.replace(/_/g, '-');
|
|
6
6
|
|
|
7
|
-
return `${css}
|
|
7
|
+
return `${css}--zw-${property}:${value};`;
|
|
8
8
|
}, '');
|
|
9
9
|
|
|
10
10
|
return style ? { style } : null;
|
|
@@ -13,5 +13,5 @@ export function renderInlineSetting(setting) {
|
|
|
13
13
|
export function renderMark(setting) {
|
|
14
14
|
const attrs = renderInlineSetting(setting);
|
|
15
15
|
|
|
16
|
-
return ['span', attrs ? { ...attrs, class: 'zw-style' } :
|
|
16
|
+
return ['span', attrs ? { ...attrs, class: 'zw-style' } : {}, 0];
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zipify/wysiwyg",
|
|
3
|
-
"version": "1.0.0-dev.
|
|
3
|
+
"version": "1.0.0-dev.42",
|
|
4
4
|
"description": "Zipify modification of TipTap text editor",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "dist/wysiwyg.mjs",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/ZipifyApps/ZipifyWysiwyg.git"
|
|
@@ -14,13 +14,14 @@
|
|
|
14
14
|
"url": "https://github.com/ZipifyApps/ZipifyWysiwyg/issues"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
+
"lib:build": "vite build --config ./config/vite/lib.config.js",
|
|
17
18
|
"example:start": "NODE_ENV=development webpack serve --config ./config/webpack/example.config.js",
|
|
18
19
|
"example:build": "NODE_ENV=production webpack --config ./config/webpack/example.config.js",
|
|
19
20
|
"test:unit": "jest .",
|
|
20
21
|
"optimize-svg": "svgo --config ./config/svgo.js",
|
|
21
22
|
"gzip": "gzipper compress",
|
|
22
23
|
"prepare": "husky install",
|
|
23
|
-
"release": "export $(cat ./.env | xargs) && release-it"
|
|
24
|
+
"release": "export $(cat ./.env | xargs) && npm run lib:build && release-it"
|
|
24
25
|
},
|
|
25
26
|
"dependencies": {
|
|
26
27
|
"@popperjs/core": "^2.11.5",
|
|
@@ -28,47 +29,51 @@
|
|
|
28
29
|
"@tiptap/extension-document": "^2.0.0-beta.17",
|
|
29
30
|
"@tiptap/extension-heading": "^2.0.0-beta.29",
|
|
30
31
|
"@tiptap/extension-history": "^2.0.0-beta.26",
|
|
32
|
+
"@tiptap/extension-link": "^2.0.0-beta.43",
|
|
31
33
|
"@tiptap/extension-list-item": "^2.0.0-beta.23",
|
|
32
34
|
"@tiptap/extension-paragraph": "^2.0.0-beta.26",
|
|
35
|
+
"@tiptap/extension-placeholder": "^2.0.0-beta.53",
|
|
33
36
|
"@tiptap/extension-superscript": "^2.0.0-beta.13",
|
|
34
37
|
"@tiptap/extension-text": "^2.0.0-beta.17",
|
|
35
38
|
"@tiptap/vue-2": "^2.0.0-beta.84",
|
|
36
39
|
"simplebar": "^5.3.8"
|
|
37
40
|
},
|
|
38
41
|
"peerDependencies": {
|
|
39
|
-
"
|
|
42
|
+
"vue": "2.7.*",
|
|
40
43
|
"zipify-colorpicker": "*"
|
|
41
44
|
},
|
|
42
45
|
"devDependencies": {
|
|
43
|
-
"@babel/core": "^7.18.
|
|
44
|
-
"@babel/eslint-parser": "^7.18.
|
|
45
|
-
"@babel/plugin-transform-runtime": "^7.18.
|
|
46
|
-
"@babel/preset-env": "^7.18.
|
|
47
|
-
"@babel/runtime": "^7.18.
|
|
48
|
-
"@vue/composition-api": "^1.7.0",
|
|
46
|
+
"@babel/core": "^7.18.9",
|
|
47
|
+
"@babel/eslint-parser": "^7.18.9",
|
|
48
|
+
"@babel/plugin-transform-runtime": "^7.18.9",
|
|
49
|
+
"@babel/preset-env": "^7.18.9",
|
|
50
|
+
"@babel/runtime": "^7.18.9",
|
|
49
51
|
"@vue/test-utils": "^1.3.0",
|
|
50
52
|
"@vue/vue2-jest": "^28.0.1",
|
|
51
|
-
"babel-jest": "^28.1.
|
|
53
|
+
"babel-jest": "^28.1.3",
|
|
52
54
|
"babel-loader": "^8.2.5",
|
|
53
55
|
"css-loader": "^6.7.1",
|
|
54
56
|
"eslint": "^8.20.0",
|
|
55
57
|
"eslint-plugin-import": "^2.26.0",
|
|
56
|
-
"eslint-plugin-vue": "^9.
|
|
58
|
+
"eslint-plugin-vue": "^9.3.0",
|
|
57
59
|
"gzipper": "^7.1.0",
|
|
58
60
|
"html-webpack-plugin": "^5.5.0",
|
|
59
61
|
"husky": "^8.0.1",
|
|
60
62
|
"jest": "^28.1.3",
|
|
61
63
|
"jest-environment-jsdom": "^28.1.3",
|
|
62
64
|
"lint-staged": "^13.0.3",
|
|
65
|
+
"mini-css-extract-plugin": "^2.6.1",
|
|
63
66
|
"postcss-html": "^1.5.0",
|
|
64
67
|
"release-it": "^15.1.2",
|
|
65
68
|
"style-loader": "^3.3.1",
|
|
66
69
|
"stylelint": "^14.9.1",
|
|
67
70
|
"svgo": "^2.8.0",
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"vue
|
|
71
|
-
"
|
|
71
|
+
"vite": "^3.0.4",
|
|
72
|
+
"vite-plugin-vue2": "^2.0.2",
|
|
73
|
+
"vue": "^2.7.8",
|
|
74
|
+
"vue-loader": "^15.10.0",
|
|
75
|
+
"vue-template-compiler": "^2.7.8",
|
|
76
|
+
"webpack": "^5.74.0",
|
|
72
77
|
"webpack-bundle-analyzer": "^4.5.0",
|
|
73
78
|
"webpack-cli": "^4.10.0",
|
|
74
79
|
"webpack-dev-server": "^4.9.3",
|