@conduction/nextcloud-vue 2.162.0 → 2.163.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/esm/components/CnChipListManager/CnChipListManager.vue.js +9 -0
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue.js.map +1 -0
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue2.js +304 -0
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue2.js.map +1 -0
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue3.js +161 -0
- package/dist/esm/components/CnChipListManager/CnChipListManager.vue3.js.map +1 -0
- package/dist/esm/components/CnFilesBrowser/openRegisterSource.js +2 -1
- package/dist/esm/components/CnFilesBrowser/openRegisterSource.js.map +1 -1
- package/dist/esm/components/CnFilterRowsEditor/CnFilterRowsEditor.vue.js +1 -1
- package/dist/esm/components/CnFilterRowsEditor/CnFilterRowsEditor.vue2.js +4 -0
- package/dist/esm/components/CnFilterRowsEditor/CnFilterRowsEditor.vue2.js.map +1 -1
- package/dist/esm/components/CnFilterRowsEditor/CnFilterRowsEditor.vue3.js.map +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue.js +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue2.js +2 -2
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue2.js.map +1 -1
- package/dist/esm/components/CnFormDialog/CnFormDialog.vue3.js.map +1 -1
- package/dist/esm/components/CnIconPicker/CnIconPicker.vue.js +1 -1
- package/dist/esm/components/CnIconPicker/CnIconPicker.vue2.js +4 -3
- package/dist/esm/components/CnIconPicker/CnIconPicker.vue2.js.map +1 -1
- package/dist/esm/components/CnIconPicker/CnIconPicker.vue3.js.map +1 -1
- package/dist/esm/components/CnIconPicker/iconCatalogues.js +16 -3
- package/dist/esm/components/CnIconPicker/iconCatalogues.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js +76 -8
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue2.js.map +1 -1
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js +2 -2
- package/dist/esm/components/CnIndexPage/CnIndexPage.vue3.js.map +1 -1
- package/dist/esm/components/CnLinksWidgetForm/CnLinksWidgetForm.vue.js +1 -1
- package/dist/esm/components/CnLinksWidgetForm/CnLinksWidgetForm.vue2.js +2 -1
- package/dist/esm/components/CnLinksWidgetForm/CnLinksWidgetForm.vue2.js.map +1 -1
- package/dist/esm/components/CnLinksWidgetForm/CnLinksWidgetForm.vue3.js.map +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue.js +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue2.js +6 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue2.js.map +1 -1
- package/dist/esm/components/CnMarkdownEditor/CnMarkdownEditor.vue3.js.map +1 -1
- package/dist/esm/components/CnObjectListWidget/CnObjectListWidget.vue.js +1 -1
- package/dist/esm/components/CnObjectListWidget/CnObjectListWidget.vue2.js +1 -1
- package/dist/esm/components/CnObjectListWidget/CnObjectListWidget.vue2.js.map +1 -1
- package/dist/esm/components/CnObjectListWidget/CnObjectListWidget.vue3.js.map +1 -1
- package/dist/esm/components/CnObjectListWidgetForm/CnObjectListWidgetForm.vue.js +1 -1
- package/dist/esm/components/CnObjectListWidgetForm/CnObjectListWidgetForm.vue2.js +4 -0
- package/dist/esm/components/CnObjectListWidgetForm/CnObjectListWidgetForm.vue2.js.map +1 -1
- package/dist/esm/components/CnObjectListWidgetForm/CnObjectListWidgetForm.vue3.js.map +1 -1
- package/dist/esm/components/CnPageTreeNode/CnPageTreeRow.vue.js +1 -1
- package/dist/esm/components/CnPageTreeNode/CnPageTreeRow.vue2.js +10 -1
- package/dist/esm/components/CnPageTreeNode/CnPageTreeRow.vue2.js.map +1 -1
- package/dist/esm/components/CnPageTreeNode/CnPageTreeRow.vue3.js.map +1 -1
- package/dist/esm/components/CnSchemaFormDialog/CnSchemaPropertyActions.vue2.js +22 -0
- package/dist/esm/components/CnSchemaFormDialog/CnSchemaPropertyActions.vue2.js.map +1 -1
- package/dist/esm/components/CnSchemaFormDialog/CnSchemaPropertyActions.vue3.js.map +1 -1
- package/dist/esm/components/CnStagesWidgetForm/CnStagesWidgetForm.vue.js +1 -1
- package/dist/esm/components/CnStagesWidgetForm/CnStagesWidgetForm.vue2.js +4 -0
- package/dist/esm/components/CnStagesWidgetForm/CnStagesWidgetForm.vue2.js.map +1 -1
- package/dist/esm/components/CnStagesWidgetForm/CnStagesWidgetForm.vue3.js.map +1 -1
- package/dist/esm/components/CnWalkthrough/CnWalkthrough.vue.js +1 -1
- package/dist/esm/components/CnWalkthrough/CnWalkthrough.vue2.js +1 -1
- package/dist/esm/components/CnWalkthrough/CnWalkthrough.vue2.js.map +1 -1
- package/dist/esm/components/CnWalkthrough/CnWalkthrough.vue3.js.map +1 -1
- package/dist/esm/composables/indexSources.js +30 -2
- package/dist/esm/composables/indexSources.js.map +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsCard.vue.js +1 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsCard.vue2.js +2 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsCard.vue2.js.map +1 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsCard.vue3.js.map +1 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsTab.vue.js +1 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsTab.vue2.js +3 -2
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsTab.vue2.js.map +1 -1
- package/dist/esm/integrations/builtin/analytics/CnAnalyticsTab.vue3.js.map +1 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosCard.vue.js +1 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosCard.vue2.js +2 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosCard.vue2.js.map +1 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosCard.vue3.js.map +1 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosTab.vue.js +1 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosTab.vue2.js +2 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosTab.vue2.js.map +1 -1
- package/dist/esm/integrations/builtin/photos/CnPhotosTab.vue3.js.map +1 -1
- package/dist/esm/integrations/builtin/xwiki/CnXwikiCard.vue.js +1 -1
- package/dist/esm/integrations/builtin/xwiki/CnXwikiCard.vue2.js +2 -6
- package/dist/esm/integrations/builtin/xwiki/CnXwikiCard.vue2.js.map +1 -1
- package/dist/esm/integrations/builtin/xwiki/CnXwikiCard.vue3.js.map +1 -1
- package/dist/esm/integrations/builtin/xwiki/CnXwikiTab.vue.js +1 -1
- package/dist/esm/integrations/builtin/xwiki/CnXwikiTab.vue2.js +2 -6
- package/dist/esm/integrations/builtin/xwiki/CnXwikiTab.vue2.js.map +1 -1
- package/dist/esm/integrations/builtin/xwiki/CnXwikiTab.vue3.js.map +1 -1
- package/dist/esm/integrations/utils/marker.js +35 -6
- package/dist/esm/integrations/utils/marker.js.map +1 -1
- package/dist/esm/l10n/en.json.js +8 -0
- package/dist/esm/l10n/en.json.js.map +1 -1
- package/dist/esm/l10n/nl.json.js +8 -0
- package/dist/esm/l10n/nl.json.js.map +1 -1
- package/dist/esm/library-style.js +1 -1
- package/dist/esm/nextcloud-vue.css +478 -334
- package/dist/esm/utils/fillTemplate.js +3 -0
- package/dist/esm/utils/fillTemplate.js.map +1 -1
- package/dist/esm/utils/htmlToText.js +36 -0
- package/dist/esm/utils/htmlToText.js.map +1 -0
- package/dist/esm/utils/prototypeKeys.js +20 -0
- package/dist/esm/utils/prototypeKeys.js.map +1 -0
- package/dist/esm/utils/toastUiRawHtmlGuard.js +166 -0
- package/dist/esm/utils/toastUiRawHtmlGuard.js.map +1 -0
- package/dist/nextcloud-vue.cjs.js +11501 -10640
- package/dist/nextcloud-vue.cjs.js.map +2 -2
- package/dist/nextcloud-vue.css +478 -334
- package/l10n/en.json +8 -0
- package/l10n/nl.json +8 -0
- package/package.json +1 -1
- package/src/components/CnChipListManager/CnChipListManager.vue +504 -0
- package/src/components/CnChipListManager/index.js +4 -0
- package/src/components/CnFilesBrowser/openRegisterSource.js +2 -1
- package/src/components/CnFilterRowsEditor/CnFilterRowsEditor.vue +4 -0
- package/src/components/CnFormDialog/CnFormDialog.vue +2 -2
- package/src/components/CnIconPicker/CnIconPicker.vue +4 -3
- package/src/components/CnIconPicker/iconCatalogues.js +16 -3
- package/src/components/CnIndexPage/CnIndexPage.vue +78 -10
- package/src/components/CnLinksWidgetForm/CnLinksWidgetForm.vue +2 -1
- package/src/components/CnMarkdownEditor/CnMarkdownEditor.vue +6 -1
- package/src/components/CnObjectListWidget/CnObjectListWidget.vue +1 -1
- package/src/components/CnObjectListWidgetForm/CnObjectListWidgetForm.vue +4 -0
- package/src/components/CnPageTreeNode/CnPageTreeRow.vue +10 -1
- package/src/components/CnSchemaFormDialog/CnSchemaPropertyActions.vue +22 -0
- package/src/components/CnStagesWidgetForm/CnStagesWidgetForm.vue +4 -0
- package/src/components/CnWalkthrough/CnWalkthrough.vue +1 -1
- package/src/components/index.js +1 -0
- package/src/composables/indexSources.js +30 -2
- package/src/css/look-board-detail.css +6 -4
- package/src/css/look-board.css +46 -1
- package/src/index.js +1 -0
- package/src/integrations/builtin/analytics/CnAnalyticsCard.vue +2 -1
- package/src/integrations/builtin/analytics/CnAnalyticsTab.vue +3 -2
- package/src/integrations/builtin/photos/CnPhotosCard.vue +2 -1
- package/src/integrations/builtin/photos/CnPhotosTab.vue +2 -1
- package/src/integrations/builtin/xwiki/CnXwikiCard.vue +2 -6
- package/src/integrations/builtin/xwiki/CnXwikiTab.vue +2 -6
- package/src/integrations/utils/marker.js +35 -6
- package/src/utils/fillTemplate.js +3 -0
- package/src/utils/htmlToText.js +33 -0
- package/src/utils/prototypeKeys.js +17 -0
- package/src/utils/toastUiRawHtmlGuard.js +162 -0
|
@@ -25,15 +25,45 @@
|
|
|
25
25
|
* @module integrations/utils/marker
|
|
26
26
|
*/
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
// optionally surrounded by whitespace.
|
|
30
|
-
const BRACKETED = /\s*\[or:[^\]]+\]\s*/g
|
|
28
|
+
const OPEN = '[or:'
|
|
31
29
|
|
|
32
30
|
// Bare `or:{uuid}` marker without enclosing brackets. UUID-shaped
|
|
33
31
|
// payload only — we deliberately do NOT match arbitrary `or:foo` text
|
|
34
32
|
// to avoid eating legitimate values like "or:option-a" (a poll option).
|
|
35
33
|
// Pattern: `or:` followed by hex/hyphens (UUID alphabet) of length ≥ 8.
|
|
36
|
-
const BARE =
|
|
34
|
+
const BARE = /or:[0-9a-f-]{8,}/gi
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Replace every `[or:…]` marker (any non-empty, non-`]` content) with a
|
|
38
|
+
* space, in one pass over the text.
|
|
39
|
+
*
|
|
40
|
+
* @param {string} text The text to clean.
|
|
41
|
+
*
|
|
42
|
+
* @return {string}
|
|
43
|
+
*/
|
|
44
|
+
function dropBracketed(text) {
|
|
45
|
+
let out = ''
|
|
46
|
+
let from = 0
|
|
47
|
+
let search = 0
|
|
48
|
+
for (;;) {
|
|
49
|
+
const start = text.indexOf(OPEN, search)
|
|
50
|
+
if (start === -1) {
|
|
51
|
+
break
|
|
52
|
+
}
|
|
53
|
+
const end = text.indexOf(']', start + OPEN.length)
|
|
54
|
+
if (end === -1) {
|
|
55
|
+
break
|
|
56
|
+
}
|
|
57
|
+
if (end === start + OPEN.length) {
|
|
58
|
+
search = end
|
|
59
|
+
continue
|
|
60
|
+
}
|
|
61
|
+
out += text.slice(from, start) + ' '
|
|
62
|
+
from = end + 1
|
|
63
|
+
search = from
|
|
64
|
+
}
|
|
65
|
+
return out + text.slice(from)
|
|
66
|
+
}
|
|
37
67
|
|
|
38
68
|
/**
|
|
39
69
|
* Strip the `[or:{uuid}]` marker (and the rarer bare `or:{uuid}`
|
|
@@ -48,8 +78,7 @@ export function stripMarker(raw) {
|
|
|
48
78
|
if (raw === null || raw === undefined) {
|
|
49
79
|
return ''
|
|
50
80
|
}
|
|
51
|
-
return String(raw)
|
|
52
|
-
.replace(BRACKETED, ' ')
|
|
81
|
+
return dropBracketed(String(raw))
|
|
53
82
|
.replace(BARE, ' ')
|
|
54
83
|
.replace(/\s+/g, ' ')
|
|
55
84
|
.trim()
|
|
@@ -348,6 +348,9 @@ function splitFields(template) {
|
|
|
348
348
|
*/
|
|
349
349
|
export function joinTemplateParts(template, valueOf) {
|
|
350
350
|
const parts = splitFields(template)
|
|
351
|
+
if (parts.length === 1) {
|
|
352
|
+
return parts[0]
|
|
353
|
+
}
|
|
351
354
|
const lead = parts[0]
|
|
352
355
|
const tail = parts[parts.length - 1]
|
|
353
356
|
let body = ''
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* Rendered HTML to inert one-line text, read by the browser's HTML parser
|
|
6
|
+
* rather than by tag patterns, so a split or unclosed tag cannot slip through
|
|
7
|
+
* and a long hostile input stays linear.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const DROPPED = 'script, style, noscript, template'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Reduce HTML to its visible text: script, style, noscript and template
|
|
14
|
+
* content is dropped, comments are skipped, entities are decoded, and every
|
|
15
|
+
* element boundary reads as one space.
|
|
16
|
+
*
|
|
17
|
+
* @param {unknown} html Rendered HTML or plain text.
|
|
18
|
+
* @return {string} The text on one line, trimmed.
|
|
19
|
+
*/
|
|
20
|
+
export function htmlToText(html) {
|
|
21
|
+
const source = html === null || html === undefined ? '' : String(html)
|
|
22
|
+
if (source === '') {
|
|
23
|
+
return ''
|
|
24
|
+
}
|
|
25
|
+
const doc = new DOMParser().parseFromString(source, 'text/html')
|
|
26
|
+
doc.querySelectorAll(DROPPED).forEach((node) => node.remove())
|
|
27
|
+
const parts = []
|
|
28
|
+
const walker = doc.createTreeWalker(doc.documentElement, NodeFilter.SHOW_TEXT)
|
|
29
|
+
while (walker.nextNode()) {
|
|
30
|
+
parts.push(walker.currentNode.nodeValue)
|
|
31
|
+
}
|
|
32
|
+
return parts.join(' ').replace(/\s+/g, ' ').trim()
|
|
33
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
3
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
4
|
+
*
|
|
5
|
+
* Keys that reach an object's prototype when used as a property name.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Whether writing under this key would reach a prototype instead of an own
|
|
10
|
+
* property (`__proto__`, `constructor`, `prototype`).
|
|
11
|
+
*
|
|
12
|
+
* @param {unknown} key A property name, path segment or cell name.
|
|
13
|
+
* @return {boolean} True for a key an editor must not write under.
|
|
14
|
+
*/
|
|
15
|
+
export function isPrototypeKey(key) {
|
|
16
|
+
return key === '__proto__' || key === 'constructor' || key === 'prototype'
|
|
17
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SPDX-License-Identifier: EUPL-1.2
|
|
3
|
+
* SPDX-FileCopyrightText: 2026 Conduction B.V.
|
|
4
|
+
*
|
|
5
|
+
* Runs every raw HTML string that `@toast-ui/editor` turns into DOM through
|
|
6
|
+
* DOMPurify 3 (`toastUiSanitizer`) first.
|
|
7
|
+
*
|
|
8
|
+
* `customHTMLSanitizer` covers the preview and the HTML renderer only. When
|
|
9
|
+
* the WYSIWYG editor converts markdown (initial value, `setMarkdown`, a mode
|
|
10
|
+
* switch, `getHTML`), its raw HTML block and inline converters call the
|
|
11
|
+
* DOMPurify 2.3.3 copy inlined in the package and write the result into a
|
|
12
|
+
* `div` of the live document with `innerHTML`. The package is unmaintained,
|
|
13
|
+
* so no release fixes that, and patching the bundle would only hold where
|
|
14
|
+
* the patch is applied: each consuming app resolves and bundles
|
|
15
|
+
* `@toast-ui/editor` itself. This guard works on the editor instance, so it
|
|
16
|
+
* travels with CnMarkdownEditor into every app.
|
|
17
|
+
*
|
|
18
|
+
* What it changes, per instance:
|
|
19
|
+
* - the `htmlBlock` and `htmlInline` converters see the node's literal
|
|
20
|
+
* sanitised by DOMPurify 3 (restored afterwards, so the markdown source and
|
|
21
|
+
* its syntax tree stay untouched);
|
|
22
|
+
* - pasted HTML is sanitised after Toast UI's own clean-up and before
|
|
23
|
+
* ProseMirror parses it;
|
|
24
|
+
* - `setHTML` sanitises its argument.
|
|
25
|
+
* DOMPurify 2.3.3 still runs inside Toast UI, but only on output DOMPurify 3
|
|
26
|
+
* already produced.
|
|
27
|
+
*
|
|
28
|
+
* @module utils/toastUiRawHtmlGuard
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
import { toastUiSanitizer } from './toastUiSanitizer.js'
|
|
32
|
+
|
|
33
|
+
// Toast UI's own tag grammar (`reHTMLTag`): its converters read the tag name
|
|
34
|
+
// with it and throw when a literal does not start with a tag.
|
|
35
|
+
const TAG_NAME = '[A-Za-z][A-Za-z0-9-]*'
|
|
36
|
+
const ATTRIBUTE = '(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^"\'=<>`\\x00-\\x20]+|\'[^\']*\'|"[^"]*"))?)'
|
|
37
|
+
const OPEN_TAG = new RegExp(`^<(${TAG_NAME})${ATTRIBUTE}*\\s*/?>`, 'i')
|
|
38
|
+
const CLOSE_TAG = new RegExp(`^</(${TAG_NAME})\\s*>`, 'i')
|
|
39
|
+
// Toast UI renders a block holding a comment as plain text.
|
|
40
|
+
const HTML_COMMENT = /<! ---->|<!--(?:-?[^>-])(?:-?[^-])*-->/
|
|
41
|
+
|
|
42
|
+
// An opening tag no Toast UI converter or schema mark handles: converting it
|
|
43
|
+
// adds nothing, which is what the sanitiser asked for.
|
|
44
|
+
const INERT_OPEN_TAG = '<span>'
|
|
45
|
+
|
|
46
|
+
const GUARDED = Symbol('cnToastUiRawHtmlGuard')
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* The literal of a raw HTML block, sanitised.
|
|
50
|
+
*
|
|
51
|
+
* @param {string} literal The block's source HTML.
|
|
52
|
+
* @return {string} HTML that starts with a tag, as Toast UI requires.
|
|
53
|
+
*/
|
|
54
|
+
export function sanitizeHtmlBlockLiteral(literal) {
|
|
55
|
+
if (HTML_COMMENT.test(literal)) {
|
|
56
|
+
return literal
|
|
57
|
+
}
|
|
58
|
+
const clean = toastUiSanitizer(literal)
|
|
59
|
+
return OPEN_TAG.test(clean) ? clean : `<div>${clean}</div>`
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The literal of one raw inline HTML tag, sanitised.
|
|
64
|
+
*
|
|
65
|
+
* @param {string} literal The tag's source, e.g. `<img src=x>` or `</b>`.
|
|
66
|
+
* @return {string} The sanitised tag.
|
|
67
|
+
*/
|
|
68
|
+
export function sanitizeHtmlInlineLiteral(literal) {
|
|
69
|
+
const close = CLOSE_TAG.exec(literal)
|
|
70
|
+
if (close) {
|
|
71
|
+
return `</${close[1]}>`
|
|
72
|
+
}
|
|
73
|
+
if (!OPEN_TAG.test(literal)) {
|
|
74
|
+
return literal
|
|
75
|
+
}
|
|
76
|
+
const open = OPEN_TAG.exec(toastUiSanitizer(literal))
|
|
77
|
+
return open ? open[0] : INERT_OPEN_TAG
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Wrap one markdown-to-WYSIWYG converter so it reads a sanitised literal.
|
|
82
|
+
*
|
|
83
|
+
* @param {object} convertors The instance's `toWwConvertors` map.
|
|
84
|
+
* @param {string} type `htmlBlock` or `htmlInline`.
|
|
85
|
+
* @param {(literal: string) => string} sanitize Literal sanitiser for that type.
|
|
86
|
+
* @return {void}
|
|
87
|
+
*/
|
|
88
|
+
function wrapConvertor(convertors, type, sanitize) {
|
|
89
|
+
const original = convertors[type]
|
|
90
|
+
if (typeof original !== 'function') {
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
convertors[type] = function(state, node, context) {
|
|
94
|
+
const literal = node.literal
|
|
95
|
+
node.literal = sanitize(typeof literal === 'string' ? literal : '')
|
|
96
|
+
try {
|
|
97
|
+
return original.call(this, state, node, context)
|
|
98
|
+
} finally {
|
|
99
|
+
node.literal = literal
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Install the guard on a constructed Toast UI editor. Safe to call more than
|
|
106
|
+
* once; does nothing on an object without Toast UI's internals.
|
|
107
|
+
*
|
|
108
|
+
* @param {object} editor A `@toast-ui/editor` instance.
|
|
109
|
+
* @return {object} The same editor.
|
|
110
|
+
*/
|
|
111
|
+
export function guardToastUiEditor(editor) {
|
|
112
|
+
if (!editor || editor[GUARDED]) {
|
|
113
|
+
return editor
|
|
114
|
+
}
|
|
115
|
+
const convertors = editor.convertor && editor.convertor.toWwConvertors
|
|
116
|
+
const view = editor.wwEditor && editor.wwEditor.view
|
|
117
|
+
if (!convertors || !view || typeof view.setProps !== 'function') {
|
|
118
|
+
return editor
|
|
119
|
+
}
|
|
120
|
+
wrapConvertor(convertors, 'htmlBlock', sanitizeHtmlBlockLiteral)
|
|
121
|
+
wrapConvertor(convertors, 'htmlInline', sanitizeHtmlInlineLiteral)
|
|
122
|
+
|
|
123
|
+
const transformPastedHTML = view.props.transformPastedHTML
|
|
124
|
+
view.setProps({
|
|
125
|
+
transformPastedHTML(html, pmView) {
|
|
126
|
+
const cleaned = typeof transformPastedHTML === 'function' ? transformPastedHTML(html, pmView) : html
|
|
127
|
+
return toastUiSanitizer(cleaned)
|
|
128
|
+
},
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
editor[GUARDED] = true
|
|
132
|
+
return editor
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* A subclass of the Toast UI editor class with the guard installed.
|
|
137
|
+
*
|
|
138
|
+
* The constructor converts `initialValue` through `setMarkdown` before it
|
|
139
|
+
* returns, so the guard is installed from that override, ahead of the first
|
|
140
|
+
* conversion.
|
|
141
|
+
*
|
|
142
|
+
* @param {new (options?: object) => object} Editor The `@toast-ui/editor` default export.
|
|
143
|
+
* @return {new (options?: object) => object} The guarded editor class.
|
|
144
|
+
*/
|
|
145
|
+
export function guardedToastUiEditorClass(Editor) {
|
|
146
|
+
return class GuardedToastUiEditor extends Editor {
|
|
147
|
+
constructor(options) {
|
|
148
|
+
super(options)
|
|
149
|
+
guardToastUiEditor(this)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
setMarkdown(markdown, cursorToEnd) {
|
|
153
|
+
guardToastUiEditor(this)
|
|
154
|
+
return super.setMarkdown(markdown, cursorToEnd)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
setHTML(html, cursorToEnd) {
|
|
158
|
+
guardToastUiEditor(this)
|
|
159
|
+
return super.setHTML(toastUiSanitizer(html), cursorToEnd)
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|