MCPcopy Create free account
hub / github.com/docusealco/docuseal / connectedCallback

Method connectedCallback

app/javascript/elements/markdown_editor.js:143–257  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

141 ]
142
143 async connectedCallback () {
144 if (!this.textarea || !this.editorElement) return
145
146 this.textarea.style.display = 'none'
147 this.adjustShortcutsForPlatform()
148
149 const { Editor, Extension, Bold, Italic, Paragraph, Text, HardBreak, UndoRedo, Document, Link, Underline, Markdown, Plugin, Decoration, DecorationSet } = await loadTiptap()
150
151 const buildDecorations = (doc) => {
152 const decorations = []
153 const regex = /\{\{?[a-zA-Z0-9_.-]+\}\}?/g
154
155 doc.descendants((node, pos) => {
156 if (!node.isText) return
157
158 let match
159
160 while ((match = regex.exec(node.text)) !== null) {
161 decorations.push(
162 Decoration.inline(pos + match.index, pos + match.index + match[0].length, {
163 class: 'bg-amber-100 py-0.5 px-1 rounded'
164 })
165 )
166 }
167 })
168
169 return DecorationSet.create(doc, decorations)
170 }
171
172 const VariableHighlight = Extension.create({
173 name: 'variableHighlight',
174 addProseMirrorPlugins () {
175 return [new Plugin({
176 state: {
177 init (_, { doc }) {
178 return buildDecorations(doc)
179 },
180 apply (tr, oldSet) {
181 return tr.docChanged ? buildDecorations(tr.doc) : oldSet
182 }
183 },
184 props: {
185 decorations (state) {
186 return this.getState(state)
187 }
188 }
189 })]
190 }
191 })
192
193 this.editor = new Editor({
194 element: this.editorElement,
195 extensions: [
196 Markdown,
197 Document,
198 Paragraph,
199 Text,
200 Bold,

Callers

nothing calls this directly

Calls 9

replaceMethod · 0.80
containsMethod · 0.80
hideMethod · 0.80
loadTiptapFunction · 0.70
createMethod · 0.45
toggleLinkMethod · 0.45
updateToolbarStateMethod · 0.45
handleLinkTooltipMethod · 0.45

Tested by

no test coverage detected