tinymce / tinymce-vue

Official TinyMCE Vue component
MIT License
2.01k stars 202 forks source link

Cannot enter input in URL dialog #379

Open HikaruShiho opened 1 year ago

HikaruShiho commented 1 year ago

Also posted in Stack Overflow https://stackoverflow.com/questions/76223386/tinymce-5-cannot-enter-input-in-url-dialog

Current Status

Current Code

<script setup lang="ts">
import Editor from "@tinymce/tinymce-vue";

const init = {
  selector: "textarea",
  height: 500,
  skin: "oxide-dark",
  placeholder: "コンテンツを入力",
  plugins: "link lists",
  toolbar:
    "link custom-image h1 h2 h3 | bold italic underline forecolor backcolor | numlist bullist indent | alignleft aligncenter alignright | blockquote",
  menubar: "insert | format",
  link_default_target: '_blank', // リンクを別タブで開く
  language: "ja", // 言語を日本語に設定
  branding: false, // 右下のロゴを非表示
  content_style: "img { max-width: 100%; height: auto; }", // imgタグのサイズを調整
  setup: function (editor: any) {
    editor.ui.registry.addButton("custom-image", {
      icon: "image",
      tooltip: "custom-image",
      onAction: function () {
        // <input type="file">のダイアログを開く
        // 画像アップロードでカーソル位置にimgタグを挿入
        const input = document.createElement("input");
        input.setAttribute("type", "file");
        input.setAttribute("accept", "image/*");
        input.click();
        input.onchange = function () {
          if (input.files && input.files[0]) {
            const file = input.files[0];
            const reader = new FileReader();
            reader.readAsDataURL(file);
            reader.onload = function () {
              const img = document.createElement("img");
              img.src = reader.result as string;
              editor.insertContent(img.outerHTML);
            };
          }
        };
      },
    });
  },
};
</script>

<template>
  <Editor api-key="xxxxxx" :init="init" />
</template>

Expected behavior

development environment


Is this a bug? Or am I describing it wrong? I need your help.