<commit_before>/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */

import Settings from '../api/Settings';
import Editor from 'tinymce/core/api/Editor';

const addToEditor = (editor: Editor) => {
  const isEditable = (node) => {
    const editable = editor.dom.getContentEditableParent(node);
    return editable !== 'false';
  }
  const isImage = (node) => node.nodeName === 'IMG' || node.nodeName === 'FIGURE' && /image/i.test(node.className);
  const imageToolbarItems = Settings.getImageToolbarItems(editor);
  if (imageToolbarItems.trim().length > 0) {
    editor.ui.registry.addContextToolbar('imageselection', {
      predicate: isImage,
      items: imageToolbarItems,
      position: 'node'
    });
  }

  const textToolbarItems = Settings.getTextSelectionToolbarItems(editor);
  if (textToolbarItems.trim().length > 0) {<commit_msg>TINY-4359: Add types to code<commit_after>/**
 * Copyright (c) Tiny Technologies, Inc. All rights reserved.
 * Licensed under the LGPL or a commercial license.
 * For LGPL see License.txt in the project root for license information.
 * For commercial licenses see https://www.tiny.cloud/
 */

import { Element } from '@ephox/dom-globals';
import Settings from '../api/Settings';
import Editor from 'tinymce/core/api/Editor';

const addToEditor = (editor: Editor) => {
  const isEditable = (node: Element) => editor.dom.getContentEditableParent(node) !== 'false';
  const isImage = (node: Element) => node.nodeName === 'IMG' || node.nodeName === 'FIGURE' && /image/i.test(node.className);

  const imageToolbarItems = Settings.getImageToolbarItems(editor);
  if (imageToolbarItems.trim().length > 0) {
    editor.ui.registry.addContextToolbar('imageselection', {
      predicate: isImage,
      items: imageToolbarItems,
      position: 'node'
    });
  }

  const textToolbarItems = Settings.getTextSelectionToolbarItems(editor);
  if (textToolbarItems.trim().length > 0) {
{'fraction_non_alphanumeric': 0.13434247871333965, 'fraction_numerical': 0.003784295175023652, 'mean_word_length': 4.20935960591133, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1792936', 'n_tokens_mistral': 626, 'n_tokens_neox': 627, 'n_words': 168}