const getItemSelection = (editor: Editor): Option<ItemSelection> => {
  const selectedListItems = Arr.map(Selection.getSelectedListItems(editor), Element.fromDom);

  return Options.liftN([
    Arr.find(selectedListItems, Fun.not(hasFirstChildList)),
    Arr.find(Arr.reverse(selectedListItems), Fun.not(hasFirstChildList))
  ], (start, end) => ({ start, end }));
};
Example #2
0
const lookup = (compInSystem: AlloyComponent, footerButtons: DialogMemButton[], buttonName: string) => {
  return Arr.find(footerButtons, (button) => {
    return button.name === buttonName;
  }).bind((memButton) => {
    return memButton.memento.getOpt(compInSystem);
  });
};
Example #3
0
 Chain.async(function (container, next, die) {
   return Arr.find(editor.windowManager.getWindows(), function (win) {
     return container.dom().id === win._id;
   }).fold(() => die('Could not find popup window'), function (win) {
     next(win);
   });
 })
Example #4
0
 Chain.on(function (container, next, die) {
   return Arr.find(editor.windowManager.getWindows(), function (win) {
     return container.dom().id === win._id;
   }).fold(die, function (win) {
     next(Chain.wrap(win));
   });
 })
Example #5
0
 const scanAndSet = (dialogApi: Types.Dialog.DialogInstanceApi<typeof initialData>, pattern: string) => {
   Arr.find(charMap, (group) => group.name === currentTab.get()).each((f) => {
     const items = Scan.scan(f, pattern);
     dialogApi.setData({
       results: items
     });
   });
 };
Example #6
0
 AlloyEvents.run<SystemEvents.AlloySlotVisibilityEvent>(SystemEvents.slotVisibility(), (sidepanel, se) => {
   const data = se.event();
   const optSidePanelSpec = Arr.find(specs, (config) => config.name === data.name());
   optSidePanelSpec.each((sidePanelSpec) => {
     const handler = data.visible() ? sidePanelSpec.onShow : sidePanelSpec.onHide;
     handler(sidePanelSpec.getApi(sidepanel));
   });
 })
Example #7
0
const maybeUrlize = function (editor, key) {
  return Arr.find(PluginUrls.urls, function (x) {
    return x.key === key;
  }).fold(function () {
    const getMetadata = editor.plugins[key].getMetadata;
    return typeof getMetadata === 'function' ? makeLink(getMetadata()) : key;
  }, function (x) {
    return makeLink({ name: x.name, url: 'https://www.tinymce.com/docs/plugins/' + x.key });
  });
};
const getServiceErrorMsg = function (type) {
  return Arr.find(friendlyServiceErrors, function (error) {
    return error.type === type;
  }).fold(
    Fun.constant('Unknown service error'),
    function (error) {
      return error.message;
    }
  );
};
const getHttpErrorMsg = function (status) {
  const message = Arr.find(friendlyHttpErrors, function (error) {
    return status === error.code;
  }).fold(
    Fun.constant('Unknown ImageProxy error'),
    function (error) {
      return error.message;
    }
  );

  return 'ImageProxy HTTP error: ' + message;
};
Example #10
0
    return Step.sync(function () {
      state.set([]);

      const matches = MatchKeys.match(patterns, event);
      Assertions.assertEq('Should have some matches', true, matches.length > 0);

      Arr.find(matches, function (pattern) {
        return pattern.action();
      });

      Assertions.assertEq('Should have the expected state', expectedData, state.get());
    });
Example #11
0
const getFullySelectedListWrappers = function (parents, rng) {
  return Arr.find(parents, function (elm) {
    return Node.name(elm) === 'li' && SelectionUtils.hasAllContentsSelected(elm, rng);
  }).fold(
    Fun.constant([]),
    function (li) {
      return findParentListContainer(parents).map(function (listCont) {
        return [
          Element.fromTag('li'),
          Element.fromTag(Node.name(listCont))
        ];
      }).getOr([]);
    }
  );
};
Example #12
0
const getSize = function (editor) {
  // This was taken from the tinymce approach (FontInfo is unlikely to be global)
  const node = editor.selection.getStart();
  const elem = Element.fromDom(node);
  const root = Element.fromDom(editor.getBody());

  const isRoot = function (e) {
    return Compare.eq(root, e);
  };

  const elemSize = getRawOrComputed(isRoot, elem);
  return Arr.find(candidates, function (size) {
    return elemSize === size;
  }).getOr(defaultSize);
};
Example #13
0
  const getMatchingValue = () => {
    let matchOpt = Option.none();
    const items = dataset.data;

    const px = editor.queryCommandValue('FontSize');
    if (px) {
      // checking for three digits after decimal point, should be precise enough
      for (let precision = 3; matchOpt.isNone() && precision >= 0; precision--) {
        const pt = toPt(px, precision);
        matchOpt = Arr.find(items, (item) => item.format === px || item.format === pt);
      }
    }

    return { matchOpt, px };
  };
Example #14
0
  const open = function (args) {
    // Never open notification if editor has been removed.
    if (editor.removed || !EditorView.isEditorAttachedToDom(editor)) {
      return;
    }

    return Arr.find(notifications, function (notification) {
      return isEqual(getImplementation().getArgs(notification), args);
    }).getOrThunk(function () {
      editor.editorManager.setActive(editor);

      const notification = getImplementation().open(args, function () {
        closeNotification(notification);
        reposition();
      });

      addNotification(notification);
      reposition();
      return notification;
    });
  };
Example #15
0
  return function (e) {
    if (isLeftMouseButtonPressed(e)) {
      const ceElm = Arr.find(editor.dom.getParents(e.target), Predicate.or(isContentEditableFalse, isContentEditableTrue)).getOr(null);

      if (isDraggable(editor.getBody(), ceElm)) {
        const elmPos = editor.dom.getPos(ceElm);
        const bodyElm = editor.getBody();
        const docElm = editor.getDoc().documentElement;

        state.element = ceElm;
        state.screenX = e.screenX;
        state.screenY = e.screenY;
        state.maxX = (editor.inline ? bodyElm.scrollWidth : docElm.offsetWidth) - 2;
        state.maxY = (editor.inline ? bodyElm.scrollHeight : docElm.offsetHeight) - 2;
        state.relX = e.pageX - elmPos.x;
        state.relY = e.pageY - elmPos.y;
        state.width = ceElm.offsetWidth;
        state.height = ceElm.offsetHeight;
        state.ghost = createGhost(editor, ceElm, state.width, state.height);
      }
    }
  };
Example #16
0
  const getMatchingValue = (): Option<{ title: string, format: string }> => {
    const getFirstFont = (fontFamily) => {
      return fontFamily ? fontFamily.split(',')[0] : '';
    };

    const fontFamily = editor.queryCommandValue('FontName');
    const items = dataset.data;
    const font = fontFamily ? fontFamily.toLowerCase() : '';

    return Arr.find(items, (item) => {
      const format = item.format;
      return (format.toLowerCase() === font) || (getFirstFont(format).toLowerCase() === getFirstFont(font).toLowerCase());
    }).orThunk(() => {
      if (isSystemFontStack(font)) {
        return Option.from({
          title: 'System Font',
          format: font
        });
      } else {
        return Option.none();
      }
    });
  };
Example #17
0
 return optSlotContainer.bind((slotContainer) =>
   Arr.find(SlotContainer.getSlotNames(slotContainer), (name) =>
     SlotContainer.isShowing(slotContainer, name)
   )
Example #18
0
 return Options.liftN([getStartNode(rng), getEndNode(rng)], function (startNode, endNode) {
   const start = Arr.find(getFirstChildren(elm), Fun.curry(Compare.eq, startNode));
   const end = Arr.find(getLastChildren(elm), Fun.curry(Compare.eq, endNode));
   return start.isSome() && end.isSome();
 }).getOr(false);
const execute = function (patterns, evt) {
  return Arr.find(match(patterns, evt), function (pattern) {
    return pattern.action();
  });
};
const getParentCaption = function (rootElm, elm) {
  return Arr.find(Parents.parentsAndSelf(elm, rootElm), function (elm) {
    return Node.name(elm) === 'caption';
  });
};
const getParentCell = function (rootElm, elm) {
  return Arr.find(Parents.parentsAndSelf(elm, rootElm), ElementType.isTableCell);
};
const firstElement = function (nodes) {
  return Arr.find(nodes, Node.isElement);
};
Example #23
0
const execute = function (patterns: KeyPattern[], evt: KeyboardEvent) {
  return Arr.find(match(patterns, evt), (pattern) => {
    return pattern.action();
  });
};
Example #24
0
 const findTemplate = (templates: TemplateData[], templateTitle: string) => {
   return Arr.find(templates, (t) => {
     return t.text === templateTitle;
   });
 };
Example #25
0
const removeEmptyRoot = function (rootNode, block) {
  const parents = Parents.parentsAndSelf(block, rootNode);
  return Arr.find(parents.reverse(), Empty.isEmpty).each(Remove.remove);
};
Example #26
0
 const getMatchingValue = (): Option<Partial<FormatItem>> => {
   return  Arr.find(alignMenuItems, (item) => editor.formatter.match(item.format));
 };
Example #27
0
const getParentCell = (rootElm, elm) => Arr.find(Parents.parentsAndSelf(elm, rootElm), ElementType.isTableCell);
Example #28
0
const findParentListContainer = function (parents) {
  return Arr.find(parents, function (elm) {
    return Node.name(elm) === 'ul' || Node.name(elm) === 'ol';
  });
};
Example #29
0
 return Options.findMap(parents, (parent) => {
   return Arr.find(styles, (fmt) => {
     return editor.formatter.matchNode(parent, fmt.format);
   });
 }).orThunk(() => {
 const getDialogByElement = function (element) {
   return Arr.find(editor.windowManager.getWindows(), function (win) {
     return element.dom().id === win._id;
   });
 };