{"version":3,"file":"text_controller-YwbubYoc.js","sources":["../../../app/javascript/controllers/capture/text_controller.js"],"sourcesContent":["import ComposeController from '../compose/base_controller'\nimport { useURLValidations } from \"../mixins/useURLValidations\"\nimport {KeyboardKey} from \"@/controllers/compose/models\";\n\nexport default class extends ComposeController {\n static targets = [\n 'toolbar',\n 'italicButton',\n 'boldButton',\n 'linkButton',\n 'linkInput',\n 'addLinkButton',\n 'editLinkContainer',\n 'newLinkContainer',\n ]\n\n onTrixFocus() {\n this.element.classList.add('border-solid', 'border-tiger')\n this.show(this.toolbarTarget)\n this.focused = true\n }\n\n\n blur() {\n this.trixTarget.blur()\n this.element.classList.remove('border-solid', 'border-tiger')\n this.hide(this.toolbarTarget)\n this.focused = false\n }\n\n onClickOutside(event) {\n if(this.element.contains(event.target) || !this.focused) return\n this.blur()\n }\n\n onTrixSelectionChange() {\n super.onTrixSelectionChange()\n\n if(this.editor.attributeIsActive('italic')) {\n this.italicButtonTarget.classList.add('text-tiger')\n } else {\n this.italicButtonTarget.classList.remove('text-tiger')\n }\n\n if(this.editor.attributeIsActive('bold')) {\n this.boldButtonTarget.classList.add('text-tiger')\n } else {\n this.boldButtonTarget.classList.remove('text-tiger')\n }\n\n this.linkButtonTarget.disabled = this.cursor.stringAtRange().trim().length === 0 && !this.editor.attributeIsActive('href')\n\n if(this.editor.attributeIsActive('href')) {\n this.linkButtonTarget.classList.add('text-tiger')\n } else {\n this.linkButtonTarget.classList.remove('text-tiger')\n }\n }\n\n toggleBold() {\n if(this.editor.attributeIsActive('bold')) {\n this.editor.deactivateAttribute('bold')\n } else {\n this.editor.activateAttribute('bold')\n }\n }\n\n onTrixKeydown(event) {\n const key = KeyboardKey.fromKeyboardEvent(event)\n\n if(key.activateLink) {\n event.preventDefault()\n\n if(this.cursor.stringAtRange(this.currentRange).length > 0 || this.editor.attributeIsActive('href')) {\n this.toggleLinkContainer()\n }\n }\n }\n\n\n toggleLinkContainer() {\n const pieceAtCaret = this.cursor.pieceAtCaret()\n\n if(pieceAtCaret.isAnchor) {\n this.linkInputTarget.value = pieceAtCaret.piece.attributes.get('href')\n\n this.editLinkContainerTarget.classList.remove(\"hidden\")\n this.addLinkButtonTarget.classList.add(\"hidden\")\n\n const pieceIndex = this.trixDocument.getPieces().indexOf(pieceAtCaret.piece)\n const contentLengthBeforePiece = this.contentLengthBeforePiece(pieceIndex)\n this.linkRange = [contentLengthBeforePiece, contentLengthBeforePiece + pieceAtCaret.piece.string.length]\n } else {\n this.editLinkContainerTarget.classList.add(\"hidden\")\n this.addLinkButtonTarget.classList.remove(\"hidden\")\n this.linkRange = this.trixPosition\n }\n\n this.newLinkContainerTarget.classList.toggle(\"hidden\")\n this.editor.activateAttribute('frozen')\n\n this.focus(this.linkInputTarget, { moveCursorToEnd: true })\n }\n\n saveLink() {\n const url = this.linkInputTarget.value\n\n this.editor.activateAttribute('href', url)\n this.editor.deactivateAttribute('frozen')\n\n this.newLinkContainerTarget.classList.add(\"hidden\")\n this.linkInputTarget.value = 'https://www.'\n\n this.editor.setSelectedRange([this.trixPosition[1], this.trixPosition[1]])\n this.trixTarget.focus()\n }\n\n abortLinkEdit() {\n this.editor.deactivateAttribute('frozen')\n\n this.newLinkContainerTarget.classList.add(\"hidden\")\n this.linkInputTarget.value = 'https://www.'\n\n if (this.trixPosition) {\n this.editor.setSelectedRange([this.trixPosition[1], this.trixPosition[1]])\n }\n\n this.trixTarget.focus()\n }\n\n unlink() {\n this.editor.setSelectedRange(this.linkRange)\n\n this.editor.deactivateAttribute('href')\n this.editor.deactivateAttribute('frozen')\n\n this.abortLinkEdit()\n }\n}\n"],"names":["text_controller","ComposeController","event","KeyboardKey","pieceAtCaret","pieceIndex","contentLengthBeforePiece","url","__publicField"],"mappings":"kQAIe,MAAKA,UAASC,CAAkB,CAY7C,aAAc,CACZ,KAAK,QAAQ,UAAU,IAAI,eAAgB,cAAc,EACzD,KAAK,KAAK,KAAK,aAAa,EAC5B,KAAK,QAAU,EACnB,CAGE,MAAO,CACL,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