@paroicms/quill-editor-plugin 1.34.0 → 1.36.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.
@@ -1,19 +1,20 @@
1
- import { boolValOrUndef, objVal, strVal, strValOrUndef } from "@paroi/data-formatters-lib";
2
1
  import { isResizeRule } from "@paroicms/public-anywhere-lib";
3
- export function formatMediaBlotValues(val) {
4
- const obj = objVal(val);
5
- const resizeRule = strVal(obj.resizeRule);
6
- if (!isResizeRule(resizeRule))
7
- throw new Error(`Invalid resizeRule: ${resizeRule}`);
8
- const align = strValOrUndef(obj.align);
9
- if (align && !["center", "left", "right"].includes(align)) {
10
- throw new Error(`Invalid align value: ${align}`);
11
- }
2
+ import { type } from "arktype";
3
+ export const MediaBlotInputAT = type({
4
+ mediaId: "string",
5
+ resizeRule: "string",
6
+ "align?": '"center"|"left"|"right"|undefined|null',
7
+ "href?": "string|undefined|null",
8
+ "zoomable?": "boolean|undefined|null",
9
+ "+": "reject",
10
+ }).pipe((data) => {
11
+ if (!isResizeRule(data.resizeRule))
12
+ throw new Error(`Invalid resizeRule: ${data.resizeRule}`);
12
13
  return {
13
- mediaId: strVal(obj.mediaId),
14
- resizeRule,
15
- align: align,
16
- href: strValOrUndef(obj.href),
17
- zoomable: boolValOrUndef(obj.zoomable),
14
+ mediaId: data.mediaId,
15
+ resizeRule: data.resizeRule,
16
+ align: data.align ?? undefined,
17
+ href: data.href ?? undefined,
18
+ zoomable: data.zoomable ?? undefined,
18
19
  };
19
- }
20
+ });
@@ -1,18 +1,22 @@
1
- import { isObj, strVal, strValOrUndef } from "@paroi/data-formatters-lib";
2
- import { isJsonFieldValue } from "@paroicms/public-anywhere-lib";
1
+ import { isJsonFieldValue, isObj } from "@paroicms/public-anywhere-lib";
3
2
  import { escapeHtml, makeStylesheetLinkAsyncTag, resolveModuleDirectory, } from "@paroicms/public-server-lib";
3
+ import { type } from "arktype";
4
4
  import { readFileSync } from "node:fs";
5
5
  import { dirname, join } from "node:path";
6
6
  import { convertQuillDeltaToHtml, convertQuillDeltaToPlainText } from "./quill-delta.js";
7
+ const MediaIdQueryAT = type({
8
+ "mediaId?": "string|undefined",
9
+ "+": "reject",
10
+ });
7
11
  const projectDir = resolveModuleDirectory(import.meta.url, { parent: true });
8
12
  const packageDir = dirname(projectDir);
9
- const version = strVal(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8")).version);
13
+ const version = type({ version: "string", "+": "ignore" }).assert(JSON.parse(readFileSync(join(packageDir, "package.json"), "utf-8"))).version;
10
14
  const plugin = {
11
15
  version,
12
16
  slug: "quill-editor",
13
17
  siteInit(service) {
14
- service.setPublicAssetsDirectory(join(packageDir, "public-front", "dist"));
15
- service.setBoAssetsDirectory(join(packageDir, "bo-front", "dist"));
18
+ service.setPublicAssetsDirectory(join(packageDir, "frontend", "dist"));
19
+ service.setAdminUiAssetsDirectory(join(packageDir, "admin-ui-plugin", "dist"));
16
20
  service.registerSiteSchemaLibrary(join(packageDir, "site-schema-lib"));
17
21
  service.registerFieldPreprocessor((service, value, options) => {
18
22
  if (!isJsonFieldValue(value))
@@ -29,14 +33,14 @@ const plugin = {
29
33
  if (!state.get("paQuillEditor:html"))
30
34
  return;
31
35
  const tags = [
32
- makeStylesheetLinkAsyncTag(`${service.pluginAssetsUrl}/public-front-plugin.css`),
36
+ makeStylesheetLinkAsyncTag(`${service.pluginAssetsUrl}/quill-editor-plugin.css`),
33
37
  ];
34
38
  if (state.get("paQuillEditor:zoomable")) {
35
- tags.push(`<script type="module" src="${escapeHtml(`${service.pluginAssetsUrl}/public-front-plugin.mjs`)}" async></script>`);
39
+ tags.push(`<script type="module" src="${escapeHtml(`${service.pluginAssetsUrl}/quill-editor-plugin.mjs`)}" async></script>`);
36
40
  }
37
41
  return tags;
38
42
  });
39
- if (service.configuration.backOffice?.code) {
43
+ if (service.configuration.adminUi?.code) {
40
44
  service.registerHeadTags(({ state }) => {
41
45
  if (!state.get("paQuillEditor:html"))
42
46
  return;
@@ -80,7 +84,7 @@ document.addEventListener("DOMContentLoaded", () => {
80
84
  service.setPublicApiHandler(async (service, httpContext, relativePath) => {
81
85
  const { req, res } = httpContext;
82
86
  if (relativePath === "/zoom-image") {
83
- const mediaId = strValOrUndef(req.query.mediaId);
87
+ const { mediaId } = MediaIdQueryAT.assert(req.query);
84
88
  if (!mediaId) {
85
89
  res.append("Content-Type", "application/json; charset=utf-8");
86
90
  res.status(400).send({ error: "mediaId parameter is required" });
@@ -1,8 +1,13 @@
1
- import { strVal, strValOrUndef } from "@paroi/data-formatters-lib";
2
1
  import { QuillDeltaToHtmlAsyncConverter, QuillDeltaToHtmlConverter, } from "@paroi/quill-delta-to-html";
3
2
  import { escapeHtml, generateObfuscatedHtml, obfuscateAsHtmlLink, stripHtmlTags, } from "@paroicms/public-server-lib";
4
- import { formatMediaBlotValues } from "./formatters.js";
3
+ import { type } from "arktype";
4
+ import { MediaBlotInputAT } from "./formatters.js";
5
5
  import { shouldOpenInBlankTab } from "./url-blank-tab.js";
6
+ const ObfuscateAttributesAT = type({
7
+ obfuscate: "string",
8
+ "+": "reject",
9
+ });
10
+ const StringOrUndefinedAT = type("string|undefined|null").pipe((data) => data ?? undefined);
6
11
  export async function convertQuillDeltaToHtml(service, delta, options) {
7
12
  const { pluginService } = service;
8
13
  const ops = delta.ops;
@@ -51,7 +56,7 @@ export function convertQuillDeltaToPlainText(service, delta) {
51
56
  }
52
57
  async function mediaBlotProcessing(service, obj, options) {
53
58
  const { useImage, pluginService } = service;
54
- const value = formatMediaBlotValues(obj);
59
+ const value = MediaBlotInputAT.assert(obj);
55
60
  const media = await pluginService.getMedia({ mediaId: value.mediaId }, { withAttachedData: { language: service.language } });
56
61
  if (media?.kind !== "image") {
57
62
  pluginService.logger.warn(`media '${value.mediaId}' is not an image`);
@@ -102,16 +107,17 @@ export function preprocessDelta(ops) {
102
107
  }
103
108
  }
104
109
  function obfuscateBlotProcessing(value, inlineAttributes) {
105
- const textVal = strValOrUndef(value);
106
- if (!textVal)
110
+ const textValue = StringOrUndefinedAT.assert(value);
111
+ if (!textValue)
107
112
  return "";
108
- const asALink = formatObfuscateAsALink(strVal(inlineAttributes.obfuscate));
113
+ const { obfuscate } = ObfuscateAttributesAT.assert(inlineAttributes);
114
+ const asALink = formatObfuscateAsALink(obfuscate);
109
115
  let obfuscatedVal;
110
116
  if (asALink === "mailto" || asALink === "tel") {
111
- obfuscatedVal = obfuscateAsHtmlLink(textVal);
117
+ obfuscatedVal = obfuscateAsHtmlLink(textValue);
112
118
  }
113
119
  else {
114
- obfuscatedVal = generateObfuscatedHtml(textVal);
120
+ obfuscatedVal = generateObfuscatedHtml(textValue);
115
121
  }
116
122
  let result = obfuscatedVal;
117
123
  if (inlineAttributes.strike) {
@@ -135,7 +141,7 @@ function formatObfuscateAsALink(val) {
135
141
  throw new Error(`invalid link-type '${val}'`);
136
142
  }
137
143
  function videoPluginBlotProcessing(_service, value, _options) {
138
- const videoId = strValOrUndef(value);
144
+ const videoId = StringOrUndefinedAT.assert(value);
139
145
  if (!videoId)
140
146
  return "";
141
147
  return `
@@ -147,12 +153,12 @@ function videoPluginBlotProcessing(_service, value, _options) {
147
153
  `;
148
154
  }
149
155
  async function internalLinkPluginBlotProcessing(service, value, options) {
150
- const documentId = strValOrUndef(value);
156
+ const documentId = StringOrUndefinedAT.assert(value);
151
157
  if (!documentId)
152
158
  return "";
153
159
  const doc = await service.getDocument(documentId);
154
160
  if (!doc)
155
161
  return "";
156
162
  const url = await doc.getUrl({ absoluteUrl: !!options?.absoluteUrls });
157
- return `<a class="InternalLink" href="${url}">${strValOrUndef(doc.title)}</a>`;
163
+ return `<a class="InternalLink" href="${url}">${StringOrUndefinedAT.assert(doc.title) ?? ""}</a>`;
158
164
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@paroicms/quill-editor-plugin",
3
- "version": "1.34.0",
3
+ "version": "1.36.0",
4
4
  "description": "Quill Editor plugin for ParoiCMS",
5
5
  "keywords": [
6
6
  "paroicms",
@@ -16,31 +16,31 @@
16
16
  "author": "Paroi Team",
17
17
  "license": "MIT",
18
18
  "scripts": {
19
- "dev:bo": "(cd bo-front && vite)",
20
- "build": "npm run build:backend && npm run build:bo && npm run build:public",
19
+ "dev:admin-ui": "(cd admin-ui-plugin && vite)",
20
+ "build": "npm run build:backend && npm run build:admin-ui && npm run build:public",
21
21
  "build:backend": "(cd backend && tsc)",
22
22
  "build:backend:watch": "(cd backend && tsc --watch --preserveWatchOutput)",
23
- "build:bo": "(cd bo-front && tsc && vite build && npm run minify:bo)",
24
- "minify:bo": "terser bo-front/dist/bo-plugin.mjs --output bo-front/dist/bo-plugin.mjs",
25
- "build:public": "(cd public-front && tsc && vite build && npm run minify:public)",
26
- "minify:public": "terser public-front/dist/public-front-plugin.mjs --output public-front/dist/public-front-plugin.mjs",
27
- "build:public:watch": "(cd public-front && tsc && vite build --watch)",
28
- "build:bo:watch": "(cd bo-front && vite build --watch)",
29
- "bo:tsc": "(cd bo-front && tsc)",
30
- "clear": "rimraf backend/dist/* bo-front/dist/*"
23
+ "build:admin-ui": "(cd admin-ui-plugin && tsc && vite build && npm run minify:admin-ui)",
24
+ "minify:admin-ui": "terser admin-ui-plugin/dist/admin-ui-plugin.mjs --output admin-ui-plugin/dist/admin-ui-plugin.mjs",
25
+ "build:public": "(cd frontend && tsc && vite build && npm run minify:public)",
26
+ "minify:public": "terser frontend/dist/quill-editor-plugin.mjs --output frontend/dist/quill-editor-plugin.mjs",
27
+ "build:public:watch": "(cd frontend && tsc && vite build --watch)",
28
+ "build:admin-ui:watch": "(cd admin-ui-plugin && vite build --watch)",
29
+ "bo:tsc": "(cd admin-ui-plugin && tsc)",
30
+ "clear": "rimraf backend/dist/* frontend/dist/* admin-ui-plugin/dist/*"
31
31
  },
32
32
  "dependencies": {
33
33
  "@paroi/quill-delta-to-html": "~0.12.3",
34
- "@paroi/data-formatters-lib": "~0.4.0"
34
+ "arktype": "~2.1.20"
35
35
  },
36
36
  "peerDependencies": {
37
37
  "@paroicms/public-anywhere-lib": "0",
38
38
  "@paroicms/public-server-lib": "0"
39
39
  },
40
40
  "devDependencies": {
41
- "@paroicms/public-anywhere-lib": "0.23.1",
42
- "@paroicms/public-bo-lib": "0.24.1",
43
- "@paroicms/public-server-lib": "0.35.0",
41
+ "@paroicms/public-admin-ui-lib": "0.26.0",
42
+ "@paroicms/public-anywhere-lib": "0.25.0",
43
+ "@paroicms/public-server-lib": "0.37.0",
44
44
  "@solid-primitives/i18n": "~2.2.1",
45
45
  "@types/node": "~24.0.1",
46
46
  "highlight.js": "~11.11.1",
@@ -50,18 +50,18 @@
50
50
  "sass": "~1.89.2",
51
51
  "solid-devtools": "~0.34.0",
52
52
  "solid-js": "1.9.7",
53
+ "terser": "~5.42.0",
53
54
  "typescript": "~5.8.3",
54
55
  "vite": "~6.3.5",
55
- "vite-plugin-solid": "~2.11.6",
56
- "terser": "~5.42.0"
56
+ "vite-plugin-solid": "~2.11.6"
57
57
  },
58
58
  "type": "module",
59
59
  "main": "backend/dist/plugin.js",
60
60
  "types": "types/html-editor-public-types.d.ts",
61
61
  "files": [
62
62
  "backend/dist",
63
- "public-front/dist",
64
- "bo-front/dist",
63
+ "frontend/dist",
64
+ "admin-ui-plugin/dist",
65
65
  "site-schema-lib",
66
66
  "types"
67
67
  ]
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "8",
2
+ "ParoiCMSSiteSchemaFormatVersion": "9",
3
3
  "languages": ["en", "fr"],
4
4
  "fieldTypes": [
5
5
  {
@@ -9,7 +9,7 @@
9
9
  "dataType": "json",
10
10
  "renderAs": "html",
11
11
  "useAsExcerpt": 1,
12
- "backOffice": {
12
+ "adminUi": {
13
13
  "editorRows": 4
14
14
  },
15
15
  "plugin": "@paroicms/quill-editor-plugin"
@@ -32,7 +32,7 @@
32
32
  "dataType": "json",
33
33
  "renderAs": "html",
34
34
  "useAsExcerpt": 1,
35
- "backOffice": {
35
+ "adminUi": {
36
36
  "editorRows": 8
37
37
  },
38
38
  "plugin": "@paroicms/quill-editor-plugin"
@@ -43,7 +43,7 @@
43
43
  "storedAs": "text",
44
44
  "dataType": "json",
45
45
  "renderAs": "html",
46
- "backOffice": {
46
+ "adminUi": {
47
47
  "editorRows": 4
48
48
  },
49
49
  "plugin": "@paroicms/quill-editor-plugin"
File without changes