@paroicms/quill-editor-plugin 1.37.0 → 1.39.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.
@@ -0,0 +1,15 @@
1
+ export async function formatTextsInQuillDelta(service, delta, language) {
2
+ const processedOps = await Promise.all(delta.ops.map(async (op) => {
3
+ if (typeof op.insert !== "string")
4
+ return op;
5
+ const formattedText = await service.executeHook("textFormatting", {
6
+ value: op.insert,
7
+ options: { language },
8
+ });
9
+ return {
10
+ ...op,
11
+ insert: formattedText ?? op.insert,
12
+ };
13
+ }));
14
+ return { ops: processedOps };
15
+ }
@@ -1,8 +1,9 @@
1
- import { readFileSync } from "node:fs";
2
- import { dirname, join } from "node:path";
3
1
  import { isJsonFieldValue, isObj } from "@paroicms/public-anywhere-lib";
4
2
  import { escapeHtml, makeStylesheetLinkAsyncTag, resolveModuleDirectory, } from "@paroicms/public-server-lib";
5
3
  import { type } from "arktype";
4
+ import { readFileSync } from "node:fs";
5
+ import { dirname, join } from "node:path";
6
+ import { formatTextsInQuillDelta } from "./format-texts-in-delta.js";
6
7
  import { convertQuillDeltaToHtml, convertQuillDeltaToPlainText } from "./quill-delta.js";
7
8
  const MediaIdQueryAT = type({
8
9
  "mediaId?": "string|undefined",
@@ -10,7 +11,11 @@ const MediaIdQueryAT = type({
10
11
  });
11
12
  const projectDir = resolveModuleDirectory(import.meta.url, { parent: true });
12
13
  const packageDir = dirname(projectDir);
13
- const version = type({ version: "string", "+": "ignore" }).assert(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8"))).version;
14
+ const { name: pluginName, version } = type({
15
+ name: "string",
16
+ version: "string",
17
+ "+": "ignore",
18
+ }).assert(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8")));
14
19
  const plugin = {
15
20
  version,
16
21
  slug: "quill-editor",
@@ -18,9 +23,12 @@ const plugin = {
18
23
  service.setPublicAssetsDirectory(join(packageDir, "frontend", "dist"));
19
24
  service.setAdminUiAssetsDirectory(join(packageDir, "admin-ui-plugin", "dist"));
20
25
  service.registerSiteSchemaLibrary(join(packageDir, "site-schema-lib"));
21
- service.registerFieldPreprocessor((service, value, options) => {
26
+ service.registerRenderingHook("fieldPreprocessor", ({ service, value, options }) => {
27
+ const { fieldType } = options;
28
+ if (fieldType.pluginName !== pluginName)
29
+ return value;
22
30
  if (!isJsonFieldValue(value))
23
- return;
31
+ return value;
24
32
  if (!isObj(value.j) || !("ops" in value.j))
25
33
  throw new Error("Invalid QuillDeltaValue");
26
34
  const delta = value.j;
@@ -29,6 +37,17 @@ const plugin = {
29
37
  service.setRenderState("paQuillEditor:html", true);
30
38
  return convertQuillDeltaToHtml(service, delta, options);
31
39
  });
40
+ service.registerHook("beforeSaveValue", async ({ service, value, options }) => {
41
+ const { fieldType, language } = options;
42
+ if (fieldType.pluginName !== pluginName)
43
+ return value;
44
+ if (!isJsonFieldValue(value) || !isObj(value.j) || !Array.isArray(value.j.ops))
45
+ return value;
46
+ const newDelta = await formatTextsInQuillDelta(service, value.j, language);
47
+ return {
48
+ j: newDelta,
49
+ };
50
+ });
32
51
  service.registerHeadTags(({ state }) => {
33
52
  if (!state.get("paQuillEditor:html"))
34
53
  return;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/quill-editor-plugin",
3
- "version": "1.37.0",
3
+ "version": "1.39.0",
4
4
  "description": "Quill Editor plugin for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -38,9 +38,9 @@
38
38
  "@paroicms/public-server-lib": "0"
39
39
  },
40
40
  "devDependencies": {
41
- "@paroicms/public-admin-ui-lib": "0.26.8",
42
- "@paroicms/public-anywhere-lib": "0.29.0",
43
- "@paroicms/public-server-lib": "0.38.3",
41
+ "@paroicms/public-admin-ui-lib": "0.27.2",
42
+ "@paroicms/public-anywhere-lib": "0.32.0",
43
+ "@paroicms/public-server-lib": "0.41.0",
44
44
  "@solid-primitives/i18n": "~2.2.1",
45
45
  "@types/node": "~24.0.1",
46
46
  "highlight.js": "~11.11.1",
@@ -19,7 +19,7 @@ export interface HtmlEditorVideoPlugin {
19
19
  }
20
20
 
21
21
  export interface HtmlEditorInternalLinkPlugin {
22
- getDocumentTitle(nodelId: string): Promise<string | undefined>;
22
+ getDocumentTitle(lNodeId: string): Promise<string | undefined>;
23
23
  openDialog(
24
24
  documentId: string | undefined,
25
25
  options: {