@paroicms/quill-editor-plugin 1.24.0 → 1.25.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/backend/dist/plugin.js +16 -17
- package/backend/dist/quill-delta.js +31 -35
- package/package.json +5 -4
package/backend/dist/plugin.js
CHANGED
|
@@ -1,27 +1,26 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
const version = (0, data_formatters_lib_1.strVal)(require((0, node_path_1.join)(packageDir, "package.json")).version);
|
|
1
|
+
import { isObj, strVal } from "@paroi/data-formatters-lib";
|
|
2
|
+
import { escapeHtml, resolveModuleDirectory, } from "@paroicms/public-server-lib";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import { dirname, join } from "node:path";
|
|
5
|
+
import { convertQuillDeltaToHtml, convertQuillDeltaToPlainText } from "./quill-delta.js";
|
|
6
|
+
const projectDir = resolveModuleDirectory(import.meta.url, { parent: true });
|
|
7
|
+
const packageDir = dirname(projectDir);
|
|
8
|
+
const version = strVal(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8")).version);
|
|
10
9
|
const plugin = {
|
|
11
10
|
version,
|
|
12
11
|
siteInit(service) {
|
|
13
|
-
service.setPublicAssetsDirectory(
|
|
14
|
-
service.setBoAssetsDirectory(
|
|
15
|
-
service.registerSiteSchemaLibrary(
|
|
12
|
+
service.setPublicAssetsDirectory(join(packageDir, "public-front", "dist"));
|
|
13
|
+
service.setBoAssetsDirectory(join(packageDir, "bo-front", "dist"));
|
|
14
|
+
service.registerSiteSchemaLibrary(join(packageDir, "site-schema-lib"));
|
|
16
15
|
service.registerFieldPreprocessor("quillDelta", (service, value, options) => {
|
|
17
|
-
if (!
|
|
16
|
+
if (!isObj(value) || !isObj(value.delta))
|
|
18
17
|
return;
|
|
19
18
|
const delta = value.delta;
|
|
20
19
|
if (options.outputType === "plainText")
|
|
21
|
-
return
|
|
22
|
-
return
|
|
20
|
+
return convertQuillDeltaToPlainText(service, delta);
|
|
21
|
+
return convertQuillDeltaToHtml(service, delta, options);
|
|
23
22
|
});
|
|
24
|
-
service.addHeadTag(`<link rel="stylesheet" href="${
|
|
23
|
+
service.addHeadTag(`<link rel="stylesheet" href="${escapeHtml(`${service.pluginAssetsUrl}/public-front-plugin.css`)}">`, `<script type="module" src="${escapeHtml(`${service.pluginAssetsUrl}/public-front-plugin.mjs`)}"></script>`);
|
|
25
24
|
if (service.pluginConf.backOffice?.code) {
|
|
26
25
|
service.addHeadTag(`<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.10.0/build/styles/default.min.css">`, `<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.10.0/build/highlight.min.js"></script>`, `<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.10.0/build/languages/typescript.min.js"></script>`, `<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.10.0/build/languages/javascript.min.js"></script>`, `<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.10.0/build/languages/xml.min.js"></script>`, `<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.10.0/build/languages/json.min.js"></script>`, `<script>
|
|
27
26
|
hljs.highlightAll();
|
|
@@ -36,4 +35,4 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
|
36
35
|
}
|
|
37
36
|
},
|
|
38
37
|
};
|
|
39
|
-
|
|
38
|
+
export default plugin;
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const data_formatters_lib_1 = require("@paroi/data-formatters-lib");
|
|
6
|
-
const quill_delta_to_html_1 = require("@paroi/quill-delta-to-html");
|
|
7
|
-
const public_server_lib_1 = require("@paroicms/public-server-lib");
|
|
8
|
-
async function convertQuillDeltaToHtml(service, delta, options) {
|
|
1
|
+
import { nbValOrUndef, strVal, strValOrUndef } from "@paroi/data-formatters-lib";
|
|
2
|
+
import { QuillDeltaToHtmlAsyncConverter, QuillDeltaToHtmlConverter, } from "@paroi/quill-delta-to-html";
|
|
3
|
+
import { applyRatioToImageSize, escapeHtml, generateObfuscatedHtml, isImageSize, obfuscateAsHtmlLink, stripHtmlTags, toAbsoluteUrl, } from "@paroicms/public-server-lib";
|
|
4
|
+
export async function convertQuillDeltaToHtml(service, delta, options) {
|
|
9
5
|
const ops = delta.ops;
|
|
10
6
|
preprocessDelta(ops);
|
|
11
|
-
const converter = new
|
|
7
|
+
const converter = new QuillDeltaToHtmlAsyncConverter(ops, {
|
|
12
8
|
multiLineParagraph: false,
|
|
13
9
|
linkTarget: (href) => {
|
|
14
10
|
if (href.startsWith("/"))
|
|
@@ -41,8 +37,8 @@ async function convertQuillDeltaToHtml(service, delta, options) {
|
|
|
41
37
|
});
|
|
42
38
|
return await converter.convert();
|
|
43
39
|
}
|
|
44
|
-
function convertQuillDeltaToPlainText(service, delta) {
|
|
45
|
-
const converter = new
|
|
40
|
+
export function convertQuillDeltaToPlainText(service, delta) {
|
|
41
|
+
const converter = new QuillDeltaToHtmlConverter(delta.ops);
|
|
46
42
|
converter.renderCustomWith((customOp) => {
|
|
47
43
|
const { type, value } = customOp.insert;
|
|
48
44
|
if (type === "html-snippet")
|
|
@@ -57,38 +53,38 @@ function convertQuillDeltaToPlainText(service, delta) {
|
|
|
57
53
|
return "";
|
|
58
54
|
});
|
|
59
55
|
const html = converter.convert();
|
|
60
|
-
return
|
|
56
|
+
return stripHtmlTags(html, { blockSeparator: " – " });
|
|
61
57
|
}
|
|
62
58
|
async function imgBlotProcessing(service, value, options) {
|
|
63
59
|
const { themeConf, useImage, logger } = service;
|
|
64
|
-
const uid =
|
|
65
|
-
const variant =
|
|
66
|
-
const align =
|
|
67
|
-
const zoom =
|
|
60
|
+
const uid = strValOrUndef(value.uid, { varName: "uid" });
|
|
61
|
+
const variant = strValOrUndef(value.variant, { varName: "variant" });
|
|
62
|
+
const align = strValOrUndef(value.align);
|
|
63
|
+
const zoom = strValOrUndef(value.zoom);
|
|
68
64
|
const hasZoom = zoom !== "none";
|
|
69
|
-
const href =
|
|
65
|
+
const href = strValOrUndef(value.href, { varName: "href" });
|
|
70
66
|
let imgAttributes;
|
|
71
|
-
if (uid && variant &&
|
|
72
|
-
const realSize =
|
|
67
|
+
if (uid && variant && isImageSize(variant)) {
|
|
68
|
+
const realSize = applyRatioToImageSize(variant, themeConf.pixelRatio);
|
|
73
69
|
const image = await useImage({ size: realSize, imageUid: uid });
|
|
74
70
|
let dataZoomSrc;
|
|
75
71
|
if (hasZoom) {
|
|
76
72
|
const zoomImage = await useImage({
|
|
77
73
|
imageUid: uid,
|
|
78
|
-
size:
|
|
74
|
+
size: applyRatioToImageSize("x1900x", themeConf.pixelRatio),
|
|
79
75
|
});
|
|
80
|
-
dataZoomSrc = options?.absoluteUrls ?
|
|
76
|
+
dataZoomSrc = options?.absoluteUrls ? toAbsoluteUrl(service, zoomImage.url) : zoomImage.url;
|
|
81
77
|
}
|
|
82
78
|
imgAttributes = {
|
|
83
79
|
dataZoomSrc,
|
|
84
|
-
src: options?.absoluteUrls ?
|
|
80
|
+
src: options?.absoluteUrls ? toAbsoluteUrl(service, image.url) : image.url,
|
|
85
81
|
width: Math.round(image.width / themeConf.pixelRatio),
|
|
86
82
|
height: Math.round(image.height / themeConf.pixelRatio),
|
|
87
83
|
href,
|
|
88
84
|
};
|
|
89
85
|
}
|
|
90
86
|
else {
|
|
91
|
-
const src =
|
|
87
|
+
const src = strValOrUndef(value.src, { varName: "src" });
|
|
92
88
|
if (!src) {
|
|
93
89
|
logger.warn("missing 'uid' and 'src' in 'img' blot");
|
|
94
90
|
return "";
|
|
@@ -96,17 +92,17 @@ async function imgBlotProcessing(service, value, options) {
|
|
|
96
92
|
imgAttributes = {
|
|
97
93
|
dataZoomSrc: hasZoom ? src : undefined,
|
|
98
94
|
src,
|
|
99
|
-
width:
|
|
100
|
-
height:
|
|
95
|
+
width: nbValOrUndef(value.width),
|
|
96
|
+
height: nbValOrUndef(value.height),
|
|
101
97
|
href,
|
|
102
98
|
};
|
|
103
99
|
}
|
|
104
100
|
const attributes = [];
|
|
105
101
|
if (imgAttributes.dataZoomSrc) {
|
|
106
|
-
attributes.push(`data-zoom-src="${
|
|
102
|
+
attributes.push(`data-zoom-src="${escapeHtml(imgAttributes.dataZoomSrc)}"`);
|
|
107
103
|
}
|
|
108
|
-
attributes.push(`src="${
|
|
109
|
-
attributes.push(`class="Img${align ? ` ${
|
|
104
|
+
attributes.push(`src="${escapeHtml(imgAttributes.src)}"`);
|
|
105
|
+
attributes.push(`class="Img${align ? ` ${escapeHtml(align)}` : ""}"`);
|
|
110
106
|
attributes.push(`loading="lazy"`);
|
|
111
107
|
attributes.push(`width="${imgAttributes.width}"`);
|
|
112
108
|
attributes.push(`height="${imgAttributes.height}"`);
|
|
@@ -132,16 +128,16 @@ function preprocessDelta(ops) {
|
|
|
132
128
|
}
|
|
133
129
|
}
|
|
134
130
|
function obfuscateBlotProcessing(value, inlineAttributes) {
|
|
135
|
-
const textVal =
|
|
131
|
+
const textVal = strValOrUndef(value);
|
|
136
132
|
if (!textVal)
|
|
137
133
|
return "";
|
|
138
|
-
const asALink = formatObfuscateAsALink(
|
|
134
|
+
const asALink = formatObfuscateAsALink(strVal(inlineAttributes.obfuscate));
|
|
139
135
|
let obfuscatedVal;
|
|
140
136
|
if (asALink === "mailto" || asALink === "tel") {
|
|
141
|
-
obfuscatedVal =
|
|
137
|
+
obfuscatedVal = obfuscateAsHtmlLink(textVal);
|
|
142
138
|
}
|
|
143
139
|
else {
|
|
144
|
-
obfuscatedVal =
|
|
140
|
+
obfuscatedVal = generateObfuscatedHtml(textVal);
|
|
145
141
|
}
|
|
146
142
|
let result = obfuscatedVal;
|
|
147
143
|
if (inlineAttributes.strike) {
|
|
@@ -165,7 +161,7 @@ function formatObfuscateAsALink(val) {
|
|
|
165
161
|
throw new Error(`invalid link-type '${val}'`);
|
|
166
162
|
}
|
|
167
163
|
function videoPluginBlotProcessing(_service, value, _options) {
|
|
168
|
-
const videoId =
|
|
164
|
+
const videoId = strValOrUndef(value);
|
|
169
165
|
if (!videoId)
|
|
170
166
|
return "";
|
|
171
167
|
return `
|
|
@@ -177,12 +173,12 @@ function videoPluginBlotProcessing(_service, value, _options) {
|
|
|
177
173
|
`;
|
|
178
174
|
}
|
|
179
175
|
async function internalLinkPluginBlotProcessing(service, value, options) {
|
|
180
|
-
const documentId =
|
|
176
|
+
const documentId = strValOrUndef(value);
|
|
181
177
|
if (!documentId)
|
|
182
178
|
return "";
|
|
183
179
|
const doc = await service.getDocument(documentId);
|
|
184
180
|
if (!doc)
|
|
185
181
|
return "";
|
|
186
182
|
const url = await doc.getUrl({ absoluteUrl: !!options?.absoluteUrls });
|
|
187
|
-
return `<a class="InternalLink" href="${url}">${
|
|
183
|
+
return `<a class="InternalLink" href="${url}">${strValOrUndef(doc.title)}</a>`;
|
|
188
184
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@paroicms/quill-editor-plugin",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.25.0",
|
|
4
4
|
"description": "Quill Editor plugin for ParoiCMS",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"paroicms",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"@paroicms/public-server-lib": "0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
|
-
"@paroicms/public-anywhere-lib": "0.
|
|
41
|
-
"@paroicms/public-bo-lib": "0.19.
|
|
42
|
-
"@paroicms/public-server-lib": "0.
|
|
40
|
+
"@paroicms/public-anywhere-lib": "0.15.0",
|
|
41
|
+
"@paroicms/public-bo-lib": "0.19.1",
|
|
42
|
+
"@paroicms/public-server-lib": "0.23.0",
|
|
43
43
|
"@solid-primitives/i18n": "~2.1.1",
|
|
44
44
|
"@types/node": "~22.10.7",
|
|
45
45
|
"highlight.js": "~11.10.0",
|
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"vite-plugin-solid": "~2.11.0",
|
|
55
55
|
"terser": "~5.37.0"
|
|
56
56
|
},
|
|
57
|
+
"type": "module",
|
|
57
58
|
"main": "backend/dist/plugin.js",
|
|
58
59
|
"types": "types/html-editor-public-types.d.ts",
|
|
59
60
|
"files": [
|