How to use the @ephox/sugar.Element.fromDom function in @ephox/sugar

To help you get started, we’ve selected a few @ephox/sugar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tinymce / tinymce / modules / tinymce / src / plugins / lists / main / ts / core / Delete.ts View on Github external
node = toElm.lastChild;
  if (node && NodeType.isBr(node) && fromElm.hasChildNodes()) {
    dom.remove(node);
  }

  if (NodeType.isEmpty(dom, toElm, true)) {
    dom.$(toElm).empty();
  }

  moveChildren(dom, fromElm, toElm);

  if (listNode) {
    toElm.appendChild(listNode);
  }

  const contains = Compare.contains(SugarElement.fromDom(toElm), SugarElement.fromDom(fromElm));

  const nestedLists = contains ? dom.getParents(fromElm, NodeType.isListNode, toElm) : [];

  dom.remove(fromElm);

  Arr.each(nestedLists, (list) => {
    if (NodeType.isEmpty(dom, list) && list !== dom.getRoot()) {
      dom.remove(list);
    }
  });
};
github tinymce / tinymce / modules / tinymce / src / themes / silver / main / ts / ui / menus / contextmenu / Coords.ts View on Github external
export const getNodeAnchor = (editor: Editor): NodeAnchorSpec => {
  return {
    anchor: 'node',
    node: Option.some(Element.fromDom(editor.selection.getNode())),
    root: Element.fromDom(editor.getBody())
  };
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / caret / CaretBr.ts View on Github external
const findBr = (forward: boolean, root: Element, pos: CaretPosition) => {
  const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
  const scope = Arr.head(parentBlocks).getOr(root);
  return CaretFinder.fromPosition(forward, scope.dom(), pos).filter(isBr);
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / selection / SelectionBookmark.ts View on Github external
const nativeRangeToSelectionRange = function (r) {
  return Selection.range(Element.fromDom(r.startContainer), r.startOffset, Element.fromDom(r.endContainer), r.endOffset);
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / keyboard / Nbsps.ts View on Github external
const getClosestBlock = (root: Element, pos: CaretPosition): Element => {
  const parentBlocks = Arr.filter(Parents.parentsAndSelf(Element.fromDom(pos.container()), root), ElementType.isBlock);
  return Arr.head(parentBlocks).getOr(root);
};
github tinymce / tinymce / modules / tinymce / src / themes / silver / main / ts / ui / dialog / WindowManager.ts View on Github external
          lazyContext: () => Option.some(Boxes.box(Element.fromDom(editor.getContentAreaContainer()))),
          fadeInClass: 'tox-dialog-dock-fadein',
github tinymce / tinymce / modules / tinymce / src / themes / silver / main / ts / backstage / Anchors.ts View on Github external
getSelection: () => {
      const rng = editor.selection.getRng();
      return Option.some(
        Selection.range(Element.fromDom(rng.startContainer), rng.startOffset, Element.fromDom(rng.endContainer), rng.endOffset)
      );
    }
  };
github tinymce / tinymce / modules / tinymce / src / plugins / visualchars / main / ts / core / VisualChars.ts View on Github external
const show = (editor: Editor, rootElm: Node) => {
  const nodeList = Nodes.filterDescendants(SugarElement.fromDom(rootElm), Nodes.isMatch);

  Arr.each(nodeList, (n) => {
    const parent = n.dom().parentNode;
    if (isWrappedNbsp(parent)) {
      Class.add(SugarElement.fromDom(parent), Data.nbspClass);
    } else {
      const withSpans = Nodes.replaceWithSpans(editor.dom.encode(SugarNode.value(n)));

      const div = editor.dom.create('div', null, withSpans);
      let node: any;
      while ((node = div.lastChild)) {
        editor.dom.insertAfter(node, n.dom());
      }

      editor.dom.remove(n.dom());
    }