Skip to content

Beautiful Open-Source Form Builder

ESC-685 - Update purify configuration to allow 'rel' attribute in links and enh… (#863)

Chirag Chhatrala8642795ccacf
diff --git a/client/components/forms/heavy/RichTextAreaInput.client.vue b/client/components/forms/heavy/RichTextAreaInput.client.vue
index 8d5498f10..f8dfd4aa5 100644
--- a/client/components/forms/heavy/RichTextAreaInput.client.vue
+++ b/client/components/forms/heavy/RichTextAreaInput.client.vue
@@ -198,12 +198,11 @@ watch(compVal, (val) => {
}
}, { immediate: true })
-// Initialize mention extension and fullscreen icon
+// Initialize mention extension - always register blot to prevent crashes
if (import.meta.client) {
- if (props.enableMentions) {
- // Register the mention extension with Quill
- mentionState.value = registerMentionExtension(Quill)
- }
+ // Always register mention blot globally for backward compatibility
+ // This ensures any content with mentions can be parsed without crashing
+ mentionState.value = registerMentionExtension(Quill)
}
// Handle editor ready event
@@ -226,10 +225,19 @@ const onEditorReady = (quillInstance) => {
}
}
-const quillOptions = computed(() => {
- const defaultOptions = {
+const buildQuillOptions = (includeFullscreen = false) => {
+ // Build formats array dynamically based on enabled features
+ const baseFormats = ['bold', 'color', 'italic', 'link', 'strike', 'underline', 'header', 'list']
+
+ // Add mention format when mentions are enabled
+ if (props.enableMentions) {
+ baseFormats.push('mention')
+ }
+
+ const baseOptions = {
placeholder: props.placeholder || '',
theme: 'snow',
+ formats: baseFormats,
modules: {
toolbar: [
[{ 'header': 1 }, { 'header': 2 }],
@@ -251,10 +259,17 @@ const quillOptions = computed(() => {
}
}
- const mergedOptions = { ...defaultOptions, ...props.editorOptions, modules: { ...defaultOptions.modules, ...props.editorOptions.modules } }
+ const mergedOptions = {
+ ...baseOptions,
+ ...props.editorOptions,
+ modules: {
+ ...baseOptions.modules,
+ ...props.editorOptions.modules
+ }
+ }
- // Add fullscreen button to toolbar if enabled
- if (props.allowFullscreen) {
+ // Add fullscreen button to toolbar if enabled and requested
+ if (includeFullscreen && props.allowFullscreen) {
mergedOptions.modules.toolbar.push(['fullscreen'])
// Set up toolbar with handlers
@@ -268,56 +283,24 @@ const quillOptions = computed(() => {
}
}
+ // Add mentions module and toolbar button if enabled
if (props.enableMentions) {
mergedOptions.modules.mention = true
- if (!mergedOptions.modules.toolbar.container) {
- mergedOptions.modules.toolbar.container = mergedOptions.modules.toolbar
+
+ // Handle toolbar container properly
+ const toolbar = mergedOptions.modules.toolbar
+ if (toolbar.container) {
+ toolbar.container.push(['mention'])
+ } else {
+ mergedOptions.modules.toolbar.push(['mention'])
}
- mergedOptions.modules.toolbar.container.push(['mention'])
}
return mergedOptions
-})
-
-const modalQuillOptions = computed(() => {
- const defaultOptions = {
- placeholder: props.placeholder || '',
- theme: 'snow',
- modules: {
- toolbar: [
- [{ 'header': 1 }, { 'header': 2 }],
- ['bold', 'italic', 'underline', 'strike'],
- ['link'],
- [{ list: 'ordered' }, { list: 'bullet' }],
- [{ color: [] }],
- ],
- keyboard: {
- bindings: {
- tab: {
- key: 9,
- handler (range) {
- this.quill.insertText(range.index, ' ', 'user')
- }
- }
- }
- }
- }
- }
+}
- const mergedOptions = { ...defaultOptions, ...props.editorOptions, modules: { ...defaultOptions.modules, ...props.editorOptions.modules } }
-
- // NOTE: No fullscreen button for modal editor
-
- if (props.enableMentions) {
- mergedOptions.modules.mention = true
- if (!mergedOptions.modules.toolbar) {
- mergedOptions.modules.toolbar = []
- }
- mergedOptions.modules.toolbar.push(['mention'])
- }
-
- return mergedOptions
-})
+const quillOptions = computed(() => buildQuillOptions(true))
+const modalQuillOptions = computed(() => buildQuillOptions(false))
const charCount = computed(() => {
return compVal.value ? compVal.value.replace(/<[^>]*>/g, '').trim().length : 0
diff --git a/client/components/forms/heavy/components/QuillyEditor.vue b/client/components/forms/heavy/components/QuillyEditor.vue
index 5da85185b..4dbf82462 100644
--- a/client/components/forms/heavy/components/QuillyEditor.vue
+++ b/client/components/forms/heavy/components/QuillyEditor.vue
@@ -48,7 +48,7 @@ const pasteHTML = (instance) => {
}
try {
- instance.clipboard.dangerouslyPasteHTML(props.modelValue, 'silent')
+ instance.clipboard.dangerouslyPasteHTML(0, props.modelValue, 'silent')
} catch (error) {
console.error('Error pasting HTML:', error)
// Fallback to setting empty content
@@ -60,7 +60,7 @@ const initializeQuill = () => {
if (container.value) {
// Merge default options with user options
const defaultOptions = {
- formats: ['bold', 'color', 'font', 'code', 'italic', 'link', 'size', 'strike', 'script', 'underline', 'header', 'list', 'mention']
+ formats: ['bold', 'color', 'italic', 'link', 'size', 'strike', 'underline', 'header', 'list']
}
const mergedOptions = {
@@ -71,7 +71,7 @@ const initializeQuill = () => {
...(props.options.modules || {})
}
}
-
+
// Initialize Quill with merged options
quillInstance = new Quill(container.value, mergedOptions)
@@ -145,7 +145,7 @@ onBeforeUnmount(() => {
quillInstance.off('selection-change')
quillInstance.off('text-change')
quillInstance.off('editor-change')
-
+
// Properly destroy the Quill instance
if (container.value && container.value.parentNode) {
// Find the toolbar - it's a sibling of the container
diff --git a/client/components/open/forms/fields/components/FieldOptions.vue b/client/components/open/forms/fields/components/FieldOptions.vue
index fcf1fad4e..ac055e89a 100644
--- a/client/components/open/forms/fields/components/FieldOptions.vue
+++ b/client/components/open/forms/fields/components/FieldOptions.vue
@@ -595,8 +595,16 @@
'italic',
'link',
'underline',
- 'list'
- ]
+ 'list',
+ 'strike'
+ ],
+ modules: {
+ toolbar: [
+ ['bold', 'italic', 'underline', 'strike'],
+ ['link'],
+ [{ list: 'ordered' }, { list: 'bullet' }]
+ ]
+ }
}"
help="Displayed below/above the field, like this text"
:help-position="field.help_position"
diff --git a/client/lib/quill/quillMentionExtension.js b/client/lib/quill/quillMentionExtension.js
index cf86928eb..3bf125136 100644
--- a/client/lib/quill/quillMentionExtension.js
+++ b/client/lib/quill/quillMentionExtension.js
@@ -24,12 +24,16 @@ export default function registerMentionExtension(QuillInstance) {
static tagName = 'SPAN'
static scope = Parchment.Scope.INLINE
- // Match any span with a 'mention' attribute
+ constructor(scroll, domNode) {
+ super(scroll, domNode)
+ }
+
+ // Match any span with a 'mention' attribute (regardless of value)
static matches(domNode) {
return (
domNode instanceof HTMLElement &&
domNode.tagName === this.tagName &&
- domNode.getAttribute('mention') === 'true'
+ domNode.hasAttribute('mention')
)
}
@@ -100,12 +104,26 @@ export default function registerMentionExtension(QuillInstance) {
addClipboardMatcher() {
if (this.quill.clipboard && typeof this.quill.clipboard.addMatcher === 'function') {
+ // First matcher: Convert mention spans to embed operations
+ this.quill.clipboard.addMatcher('span[mention]', (node) => {
+ const blotData = {
+ field: {
+ id: node.getAttribute('mention-field-id') || '',
+ name: cleanString(node.getAttribute('mention-field-name') || '')
+ },
+ fallback: cleanString(node.getAttribute('mention-fallback') || '')
+ }
+ // Return an embed operation for the mention
+ return new Delta().insert({ mention: blotData })
+ })
+
+ // Second matcher: Handle other spans and prevent false mentions
this.quill.clipboard.addMatcher('span', (node, delta) => {
- const isRealMention = node.getAttribute('mention') === 'true'
+ const isRealMention = node.hasAttribute('mention')
const isInterpretedAsMention = delta.ops.some(op => op.insert && typeof op.insert.mention === 'object')
if (isRealMention) {
- // This is a real mention. Quill's conversion is correct.
+ // Already handled by 'span[mention]' matcher above
return delta
}