import { TIPTAP_FIGURE_TYPE, TIPTAP_VIDEO_TYPE } from "./../../ricos-content/index.js";
import { findParentNodeClosestToPos } from "./../../tiptap/index.js";
import { createRicosNodeExtension } from "./../../plugin-commons/index.js";
import { Video } from "./component.js";
const tiptapExtensions = [
  createRicosNodeExtension({
    groups: [
      "spoilerable",
      "overlay",
      "not-overtypable",
      {
        group: "resizable",
        options: { lockAspectRatio: true, expandToFullWidthOnOverdrag: true }
      },
      "custom-styles",
      "draggable"
    ],
    type: "react-node",
    name: TIPTAP_VIDEO_TYPE,
    reconfigure: (config, _extensions, _props, settings, services) => ({
      ...config,
      addOptions: () => ({
        services,
        ...settings
      })
    }),
    Component: Video,
    createExtensionConfig() {
      return {
        name: this.name,
        /*
         * Priority should be higher than ricos-common-plugin list-item extension in order
         * to shortcuts to work
         */
        priority: 102,
        group: "block figureFirstChildContent",
        selectable: true,
        draggable: true,
        addAttributes: () => ({
          containerData: null,
          video: null,
          thumbnail: null,
          disableDownload: null,
          disableExpand: null,
          title: null,
          options: null,
          loading: {
            default: false
          },
          error: null,
          loadingPercentage: null,
          tempData: null,
          uploadToken: null
        }),
        addKeyboardShortcuts() {
          const newLine = ({ editor }) => {
            const videoFigure = getVideoFigure(editor);
            if (!videoFigure) {
              return false;
            }
            editor.chain().setTextSelection(videoFigure.start + videoFigure.node.nodeSize - 1).createParagraphNear().focus().run();
            return true;
          };
          const tiptapKeyboardShortcuts = {
            Enter: newLine
          };
          const newLineShortcuts = [];
          this.options.services.shortcuts.shortcuts.forEach((shortcut) => {
            if (shortcut.shortcut.name === "NewLine") {
              newLineShortcuts.push(shortcut);
            }
          });
          newLineShortcuts.forEach((newLineShortcut) => {
            const modifier = newLineShortcut.keys.macOs.modifiers[0];
            const key = newLineShortcut.keys.macOs.key;
            const shortcutKey = modifier ? `${modifier}-${key}` : key;
            tiptapKeyboardShortcuts[shortcutKey] = newLine;
          });
          return tiptapKeyboardShortcuts;
        },
        addCommands() {
          return {};
        }
      };
    }
  })
];
const getVideoFigure = (editor) => findParentNodeClosestToPos(
  editor.state.selection.$from,
  (node) => node.type.name === TIPTAP_FIGURE_TYPE
);
export {
  tiptapExtensions
};
//# sourceMappingURL=tiptap.js.map
