@paroicms/quill-editor-plugin 1.15.0 → 1.16.1

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.
@@ -11,16 +11,19 @@ async function convertQuillDeltaToHtml(service, delta, options) {
11
11
  const converter = new quill_delta_to_html_1.QuillDeltaToHtmlAsyncConverter(ops, {
12
12
  multiLineParagraph: false,
13
13
  });
14
- converter.renderCustomWith((customOp) => {
14
+ converter.renderCustomWith(async (customOp) => {
15
15
  const { type, value } = customOp.insert;
16
16
  if (type === "html-snippet")
17
17
  return value.html;
18
18
  if (type === "obfuscate")
19
19
  return obfuscateBlotProcessing(value, customOp.attributes);
20
20
  if (type === "img")
21
- return imgBlotProcessing(service, value, options);
21
+ return await imgBlotProcessing(service, value, options);
22
22
  if (type === "video-plugin")
23
23
  return videoPluginBlotProcessing(service, value, options);
24
+ if (type === "internal-link-plugin") {
25
+ return await internalLinkPluginBlotProcessing(service, value, options);
26
+ }
24
27
  service.logger.warn(`Invalid blot '${type}'`);
25
28
  return "";
26
29
  });
@@ -36,6 +39,8 @@ function convertQuillDeltaToPlainText(service, delta) {
36
39
  return "";
37
40
  if (type === "video-plugin")
38
41
  return "";
42
+ if (type === "internal-link-plugin")
43
+ return "";
39
44
  service.logger.warn(`Invalid blot '${type}'`);
40
45
  return "";
41
46
  });
@@ -96,11 +101,18 @@ async function imgBlotProcessing(service, value, options) {
96
101
  }
97
102
  function preprocessDelta(ops) {
98
103
  for (const op of ops) {
99
- if (!op.insert || !op.attributes?.obfuscate)
104
+ if (!op.insert || !op.attributes)
100
105
  continue;
101
- op.insert = {
102
- obfuscate: op.insert,
103
- };
106
+ if (op.attributes?.obfuscate) {
107
+ op.insert = {
108
+ obfuscate: op.insert,
109
+ };
110
+ }
111
+ else if (op.attributes?.["internal-link-plugin"]) {
112
+ op.insert = {
113
+ "internal-link-plugin": op.attributes?.["internal-link-plugin"],
114
+ };
115
+ }
104
116
  }
105
117
  }
106
118
  function obfuscateBlotProcessing(value, inlineAttributes) {
@@ -136,15 +148,25 @@ function formatObfuscateAsALink(val) {
136
148
  return "tel";
137
149
  throw new Error(`invalid link-type '${val}'`);
138
150
  }
139
- function videoPluginBlotProcessing(service, value, options) {
151
+ function videoPluginBlotProcessing(_service, value, _options) {
140
152
  const videoId = (0, data_formatters_lib_1.strValOrUndef)(value);
141
153
  if (!videoId)
142
154
  return "";
143
155
  return `
144
- <iframe
145
- width="420"
146
- height="315"
147
- src="https://www.youtube.com/embed/${encodeURIComponent(videoId)}"
148
- ></iframe>
156
+ <iframe
157
+ width="420"
158
+ height="315"
159
+ src="https://www.youtube.com/embed/${encodeURIComponent(videoId)}"
160
+ ></iframe>
149
161
  `;
150
162
  }
163
+ async function internalLinkPluginBlotProcessing(service, value, options) {
164
+ const documentId = (0, data_formatters_lib_1.strValOrUndef)(value);
165
+ if (!documentId)
166
+ return "";
167
+ const doc = await service.getDocument(documentId);
168
+ if (!doc)
169
+ return "";
170
+ const url = await doc.getUrl({ absoluteUrl: !!options?.absoluteUrls });
171
+ return `<a class="InternalLink" href="${url}">${(0, data_formatters_lib_1.strValOrUndef)(doc.title)}</a>`;
172
+ }