@zipify/wysiwyg 2.6.0 → 2.7.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/dist/cli.js +3 -3
- package/dist/wysiwyg.mjs +12697 -12637
- package/lib/cli/commands/ToJsonCommand.js +10 -2
- package/lib/cli/index.js +0 -1
- package/lib/entry-lib.js +1 -1
- package/lib/{cli → services}/ContentSerializer.js +16 -17
- package/lib/services/HtmlToJsonParser.js +17 -0
- package/lib/services/index.js +2 -0
- package/package.json +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { resolve } from 'path';
|
|
2
|
-
import { ContentSerializer } from '
|
|
2
|
+
import { ContentSerializer, ContextWindow } from '../../services';
|
|
3
|
+
import { NodeDomParser } from '../NodeDomParser';
|
|
3
4
|
import { Command } from './Command';
|
|
4
5
|
|
|
5
6
|
export class ToJsonCommand extends Command {
|
|
@@ -23,7 +24,14 @@ export class ToJsonCommand extends Command {
|
|
|
23
24
|
|
|
24
25
|
doCommand(html, { config, format }) {
|
|
25
26
|
const configPath = resolve(process.cwd(), config);
|
|
26
|
-
|
|
27
|
+
|
|
28
|
+
ContextWindow.use(NodeDomParser.createWindow());
|
|
29
|
+
|
|
30
|
+
const serializer = ContentSerializer.build({
|
|
31
|
+
config: require(configPath).editor,
|
|
32
|
+
nodeDomParser: new NodeDomParser()
|
|
33
|
+
});
|
|
34
|
+
|
|
27
35
|
const content = serializer.toJSON(this.#formatInputHtml(html));
|
|
28
36
|
const json = this.#stringifyContent(content);
|
|
29
37
|
|
package/lib/cli/index.js
CHANGED
package/lib/entry-lib.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export { default as Wysiwyg } from './Wysiwyg';
|
|
2
|
-
export { NodeFactory } from './services';
|
|
2
|
+
export { NodeFactory, HtmlToJsonParser } from './services';
|
|
3
3
|
export { NodeTypes, TextSettings, Alignments } from './enums';
|
|
4
4
|
export { isWysiwygContent, unmarkWysiwygContent, markWysiwygContent } from './utils';
|
|
@@ -3,23 +3,21 @@ import { getSchema } from '@tiptap/core';
|
|
|
3
3
|
import { DOMParser } from 'prosemirror-model';
|
|
4
4
|
import { buildExtensions } from '../extensions';
|
|
5
5
|
import { Devices } from '../enums';
|
|
6
|
-
import { ContentNormalizer
|
|
7
|
-
import {
|
|
6
|
+
import { ContentNormalizer } from './normalizer';
|
|
7
|
+
import { ContextWindow } from './ContextWidnow';
|
|
8
8
|
|
|
9
9
|
export class ContentSerializer {
|
|
10
|
-
static build(
|
|
11
|
-
ContextWindow.use(NodeDomParser.createWindow());
|
|
12
|
-
|
|
10
|
+
static build({ config, nodeDomParser }) {
|
|
13
11
|
const extensions = buildExtensions({
|
|
14
|
-
fonts:
|
|
12
|
+
fonts: config.fonts,
|
|
15
13
|
minFontSize: 0,
|
|
16
14
|
maxFontSize: 0,
|
|
17
|
-
presetsRef: ref(
|
|
18
|
-
defaultPresetId:
|
|
19
|
-
linkPresetId:
|
|
15
|
+
presetsRef: ref(config.presets),
|
|
16
|
+
defaultPresetId: config.defaultPresetId,
|
|
17
|
+
linkPresetId: config.linkPresetId,
|
|
20
18
|
makePresetVariable: () => '',
|
|
21
|
-
basePresetClass:
|
|
22
|
-
baseListClass:
|
|
19
|
+
basePresetClass: config.basePresetClass,
|
|
20
|
+
baseListClass: config.baseListClass,
|
|
23
21
|
deviceRef: ref(Devices.DESKTOP),
|
|
24
22
|
pageBlocksRef: ref([]),
|
|
25
23
|
wrapperRef: ContextWindow.document.createElement('p')
|
|
@@ -28,25 +26,26 @@ export class ContentSerializer {
|
|
|
28
26
|
|
|
29
27
|
return new ContentSerializer({
|
|
30
28
|
schema: schema,
|
|
31
|
-
domParser: DOMParser.fromSchema(schema)
|
|
29
|
+
domParser: DOMParser.fromSchema(schema),
|
|
30
|
+
nodeDomParser
|
|
32
31
|
});
|
|
33
32
|
}
|
|
34
33
|
|
|
35
34
|
#schema;
|
|
36
35
|
#domParser;
|
|
36
|
+
#nodeDomParser;
|
|
37
37
|
|
|
38
|
-
constructor({ schema, domParser }) {
|
|
38
|
+
constructor({ schema, domParser, nodeDomParser }) {
|
|
39
39
|
this.#schema = schema;
|
|
40
40
|
this.#domParser = domParser;
|
|
41
|
+
this.#nodeDomParser = nodeDomParser;
|
|
41
42
|
}
|
|
42
43
|
|
|
43
44
|
toJSON(html) {
|
|
44
|
-
const normalizer = ContentNormalizer.build(html, {
|
|
45
|
-
parser: new NodeDomParser()
|
|
46
|
-
});
|
|
45
|
+
const normalizer = ContentNormalizer.build(html, { parser: this.#nodeDomParser });
|
|
47
46
|
|
|
48
47
|
normalizer.normalizeHTML();
|
|
49
48
|
|
|
50
|
-
return this.#domParser.parse(normalizer.dom.body);
|
|
49
|
+
return this.#domParser.parse(normalizer.dom.body).toJSON();
|
|
51
50
|
}
|
|
52
51
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ContentSerializer } from './ContentSerializer';
|
|
2
|
+
|
|
3
|
+
export class HtmlToJsonParser {
|
|
4
|
+
static create(config) {
|
|
5
|
+
return new HtmlToJsonParser(ContentSerializer.build({ config }));
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
#contentSerializer;
|
|
9
|
+
|
|
10
|
+
constructor(contentSerializer) {
|
|
11
|
+
this.#contentSerializer = contentSerializer;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
toJSON(html) {
|
|
15
|
+
return this.#contentSerializer.toJSON(html);
|
|
16
|
+
}
|
|
17
|
+
}
|
package/lib/services/index.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export { JsonSerializer } from './JsonSerializer';
|
|
2
|
+
export { ContentSerializer } from './ContentSerializer';
|
|
2
3
|
export { Storage } from './Storage';
|
|
3
4
|
export { FavoriteColors } from './FavoriteColors';
|
|
4
5
|
export { ContentNormalizer } from './normalizer';
|
|
5
6
|
export { ContextWindow } from './ContextWidnow';
|
|
6
7
|
export { NodeFactory } from './NodeFactory';
|
|
8
|
+
export { HtmlToJsonParser } from './HtmlToJsonParser';
|