@zipify/wysiwyg 4.2.2 → 4.4.0-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.release-it.json +1 -0
- package/config/build/cli.config.js +9 -6
- package/config/build/node.config.js +50 -0
- package/dist/cli.js +61 -24
- package/dist/node.js +40 -0
- package/dist/types/Wysiwyg.vue.d.ts +2 -2
- package/dist/types/composables/useEditor.d.ts +3 -4
- package/dist/types/entryLib.d.ts +1 -1
- package/dist/types/entryNode.d.ts +2 -0
- package/dist/types/node/NodeDomParser.d.ts +5 -0
- package/dist/types/node/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -2
- package/dist/types/utils/isWysiwygContent.d.ts +0 -5
- package/dist/wysiwyg.mjs +209 -367
- package/lib/cli/commands/ToJsonCommand.js +2 -2
- package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +0 -1
- package/lib/composables/useEditor.ts +7 -14
- package/lib/entryLib.ts +1 -1
- package/lib/entryNode.ts +2 -0
- package/lib/node/NodeDomParser.ts +16 -0
- package/lib/node/index.ts +1 -0
- package/lib/utils/index.ts +1 -2
- package/lib/utils/isWysiwygContent.ts +1 -14
- package/package.json +20 -12
- package/lib/cli/NodeDomParser.js +0 -16
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
-
import { ContentSerializer, ContextWindow } from '
|
|
3
|
-
import { NodeDomParser } from '
|
|
2
|
+
import { ContentSerializer, ContextWindow } from '@/services';
|
|
3
|
+
import { NodeDomParser } from '@/node';
|
|
4
4
|
import { Command } from './Command';
|
|
5
5
|
|
|
6
6
|
export class ToJsonCommand extends Command {
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
import { type AnyExtension, Editor } from '@tiptap/vue-3';
|
|
2
|
-
import type { Content } from '@tiptap/core';
|
|
2
|
+
import type { Content, JSONContent } from '@tiptap/core';
|
|
3
3
|
import { onUnmounted, watch, reactive, unref } from 'vue';
|
|
4
4
|
import type { Ref, UnwrapNestedRefs } from 'vue';
|
|
5
5
|
import { ContentNormalizer } from '@/services';
|
|
6
|
-
import { markWysiwygContent } from '@/utils';
|
|
7
|
-
import type { WysiwygContent } from '@/utils';
|
|
8
6
|
|
|
9
7
|
export interface IUseEditorProps {
|
|
10
8
|
content: Ref<Content>;
|
|
11
|
-
onChange: (content:
|
|
9
|
+
onChange: (content: JSONContent) => void;
|
|
12
10
|
extensions: AnyExtension[];
|
|
13
11
|
isReadonlyRef: Ref<boolean>;
|
|
14
12
|
|
|
@@ -16,18 +14,13 @@ export interface IUseEditorProps {
|
|
|
16
14
|
|
|
17
15
|
export interface IUseEditorReturn {
|
|
18
16
|
editor: Editor;
|
|
19
|
-
getContent():
|
|
17
|
+
getContent(): JSONContent;
|
|
20
18
|
}
|
|
21
19
|
|
|
22
20
|
export function useEditor({ content, onChange, extensions, isReadonlyRef }: IUseEditorProps): IUseEditorReturn {
|
|
23
|
-
|
|
24
|
-
let editor: UnwrapNestedRefs<Editor>;
|
|
25
|
-
|
|
26
|
-
const getContent = (): WysiwygContent => markWysiwygContent(editor.getJSON());
|
|
27
|
-
|
|
28
|
-
editor = reactive(new Editor({
|
|
21
|
+
const editor: UnwrapNestedRefs<Editor> = reactive(new Editor({
|
|
29
22
|
content: ContentNormalizer.normalize(content.value),
|
|
30
|
-
onUpdate: () => onChange(
|
|
23
|
+
onUpdate: () => onChange(editor.getJSON()),
|
|
31
24
|
extensions,
|
|
32
25
|
injectCSS: false,
|
|
33
26
|
editable: !unref(isReadonlyRef),
|
|
@@ -41,7 +34,7 @@ export function useEditor({ content, onChange, extensions, isReadonlyRef }: IUse
|
|
|
41
34
|
onUnmounted(() => editor.destroy());
|
|
42
35
|
|
|
43
36
|
watch(content, (value) => {
|
|
44
|
-
if (JSON.stringify(
|
|
37
|
+
if (JSON.stringify(editor.getJSON()) !== JSON.stringify(value)) {
|
|
45
38
|
const content = ContentNormalizer.normalize(value);
|
|
46
39
|
|
|
47
40
|
editor.commands.setContent(content, false);
|
|
@@ -50,5 +43,5 @@ export function useEditor({ content, onChange, extensions, isReadonlyRef }: IUse
|
|
|
50
43
|
|
|
51
44
|
watch(isReadonlyRef, (isReadonly) => editor.setEditable(!isReadonly, false));
|
|
52
45
|
|
|
53
|
-
return { editor: editor as Editor, getContent };
|
|
46
|
+
return { editor: editor as Editor, getContent: () => editor.getJSON() };
|
|
54
47
|
}
|
package/lib/entryLib.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export { default as Wysiwyg } from './Wysiwyg.vue';
|
|
2
2
|
export { NodeFactory, HtmlToJsonParser } from './services';
|
|
3
3
|
export { NodeTypes, TextSettings, Alignments } from './enums';
|
|
4
|
-
export { isWysiwygContent
|
|
4
|
+
export { isWysiwygContent } from './utils';
|
|
5
5
|
export * from './components/base';
|
|
6
6
|
export { InjectionTokens } from './injectionTokens';
|
package/lib/entryNode.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { JSDOM } from 'jsdom';
|
|
2
|
+
|
|
3
|
+
export class NodeDomParser {
|
|
4
|
+
static createWindow(): Window {
|
|
5
|
+
return new JSDOM().window as unknown as Window;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
types!: Window;
|
|
9
|
+
|
|
10
|
+
parse(html: string): Document {
|
|
11
|
+
const { window } = new JSDOM(html);
|
|
12
|
+
|
|
13
|
+
this.types = window as unknown as Window;
|
|
14
|
+
return window.document;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './NodeDomParser';
|
package/lib/utils/index.ts
CHANGED
|
@@ -7,8 +7,7 @@ export { convertLineHeight } from './convertLineHeight';
|
|
|
7
7
|
export { convertFontSize } from './convertFontSize';
|
|
8
8
|
export { convertAlignment } from './convertAlignment';
|
|
9
9
|
export { importIcon } from './importIcon';
|
|
10
|
-
export { isWysiwygContent
|
|
11
|
-
export type { WysiwygContent } from './isWysiwygContent';
|
|
10
|
+
export { isWysiwygContent } from './isWysiwygContent';
|
|
12
11
|
export { resolveTextPosition } from './resolveTextPosition';
|
|
13
12
|
export { resolvePositionOffset } from './resolvePositionOffset';
|
|
14
13
|
export { isNodeFullySelected } from './isNodeFullySelected';
|
|
@@ -1,18 +1,5 @@
|
|
|
1
1
|
import type { JSONContent } from '@tiptap/core';
|
|
2
2
|
|
|
3
|
-
export interface WysiwygContent extends JSONContent{
|
|
4
|
-
__wswg__: true;
|
|
5
|
-
}
|
|
6
|
-
|
|
7
3
|
export function isWysiwygContent(content: string | object): content is JSONContent {
|
|
8
|
-
return typeof content === 'object' && (content as
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
12
|
-
export function unmarkWysiwygContent({ __wswg__, ...content }: WysiwygContent): JSONContent {
|
|
13
|
-
return content;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function markWysiwygContent(content: JSONContent): WysiwygContent {
|
|
17
|
-
return { ...content, __wswg__: true };
|
|
4
|
+
return typeof content === 'object' && (content as JSONContent).type === 'doc';
|
|
18
5
|
}
|
package/package.json
CHANGED
|
@@ -1,9 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zipify/wysiwyg",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0-0",
|
|
4
4
|
"description": "Zipify modification of TipTap text editor",
|
|
5
|
-
"
|
|
6
|
-
|
|
5
|
+
"exports": {
|
|
6
|
+
".": {
|
|
7
|
+
"import": "./dist/wysiwyg.mjs",
|
|
8
|
+
"types": "./dist/wysiwyg.d.ts"
|
|
9
|
+
},
|
|
10
|
+
"./node": {
|
|
11
|
+
"require": "./dist/node.cjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
7
14
|
"bin": {
|
|
8
15
|
"zipify-wysiwyg": "bin/cli"
|
|
9
16
|
},
|
|
@@ -21,6 +28,7 @@
|
|
|
21
28
|
"lib:build": "npm run lib:build-types && vite build --config config/build/lib.config.ts",
|
|
22
29
|
"lib:build-types": "vue-tsc -P ./tsconfig.types.json",
|
|
23
30
|
"lib:release": "[ -f .env ] && export $(cat .env | xargs) && release-it",
|
|
31
|
+
"node:build": "NODE_ENV=production rollup --config config/build/node.config.js --bundleConfigAsCjs",
|
|
24
32
|
"cli:build": "NODE_ENV=production rollup --config config/build/cli.config.js --bundleConfigAsCjs",
|
|
25
33
|
"cli:dev": "NODE_ENV=development rollup --config config/build/cli.config.js --bundleConfigAsCjs --watch",
|
|
26
34
|
"example:start": "NODE_ENV=development vite serve --config config/build/example.config.ts",
|
|
@@ -49,8 +57,8 @@
|
|
|
49
57
|
},
|
|
50
58
|
"peerDependencies": {
|
|
51
59
|
"@zipify/colorpicker": "^3.2",
|
|
52
|
-
"
|
|
53
|
-
"
|
|
60
|
+
"simplebar": "^6.2",
|
|
61
|
+
"vue": "^3.4"
|
|
54
62
|
},
|
|
55
63
|
"peerDependenciesMeta": {
|
|
56
64
|
"@zipify/colorpicker": {
|
|
@@ -69,19 +77,18 @@
|
|
|
69
77
|
"@babel/plugin-transform-runtime": "^7.24.0",
|
|
70
78
|
"@babel/preset-env": "^7.24.0",
|
|
71
79
|
"@babel/runtime": "^7.24.0",
|
|
72
|
-
"@optimize-lodash/rollup-plugin": "^
|
|
80
|
+
"@optimize-lodash/rollup-plugin": "^5.0.0",
|
|
73
81
|
"@rollup/plugin-alias": "^5.1.0",
|
|
74
|
-
"@rollup/plugin-commonjs": "^
|
|
82
|
+
"@rollup/plugin-commonjs": "^26.0.1",
|
|
75
83
|
"@rollup/plugin-json": "^6.1.0",
|
|
76
84
|
"@rollup/plugin-node-resolve": "^15.2.3",
|
|
77
|
-
"@rollup/plugin-replace": "^5.0.
|
|
78
|
-
"@rollup/plugin-terser": "^0.4.4",
|
|
85
|
+
"@rollup/plugin-replace": "^5.0.7",
|
|
79
86
|
"@rushstack/eslint-patch": "^1.7.2",
|
|
80
87
|
"@types/jest": "^29.5.12",
|
|
81
88
|
"@types/node": "^20.10.0",
|
|
82
89
|
"@typescript-eslint/eslint-plugin": "^7.2.0",
|
|
83
90
|
"@typescript-eslint/parser": "^7.2.0",
|
|
84
|
-
"@vitejs/plugin-vue": "^5.
|
|
91
|
+
"@vitejs/plugin-vue": "^5.1.2",
|
|
85
92
|
"@vue/eslint-config-typescript": "^13.0.0",
|
|
86
93
|
"@vue/test-utils": "^2.4.5",
|
|
87
94
|
"@vue/tsconfig": "^0.5.1",
|
|
@@ -101,13 +108,14 @@
|
|
|
101
108
|
"lint-staged": "^15.2.2",
|
|
102
109
|
"postcss-html": "^1.6.0",
|
|
103
110
|
"release-it": "^17.1.1",
|
|
104
|
-
"rollup": "^4.
|
|
111
|
+
"rollup": "^4.21.1",
|
|
105
112
|
"rollup-plugin-esbuild": "^6.1.1",
|
|
113
|
+
"rollup-plugin-esbuild-minify": "^1.1.2",
|
|
106
114
|
"simplebar": "^6.2.5",
|
|
107
115
|
"stylelint": "^14.16.1",
|
|
108
116
|
"svgo": "^3.2.0",
|
|
109
117
|
"typescript": "^5.4.2",
|
|
110
|
-
"vite": "^5.
|
|
118
|
+
"vite": "^5.4.2",
|
|
111
119
|
"vue": "3.4.21",
|
|
112
120
|
"vue-tsc": "^2.0.6"
|
|
113
121
|
},
|
package/lib/cli/NodeDomParser.js
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { JSDOM } from 'jsdom';
|
|
2
|
-
|
|
3
|
-
export class NodeDomParser {
|
|
4
|
-
static createWindow() {
|
|
5
|
-
return new JSDOM().window;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
types;
|
|
9
|
-
|
|
10
|
-
parse(html) {
|
|
11
|
-
const { window } = new JSDOM(html);
|
|
12
|
-
|
|
13
|
-
this.types = window;
|
|
14
|
-
return window.document;
|
|
15
|
-
}
|
|
16
|
-
}
|