How to use the @ephox/sugar.Traverse.parent 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 / themes / silver / main / ts / autocomplete / AutocompleteTag.ts View on Github external
return detect(Element.fromDom(editor.selection.getNode())).getOrThunk(() => {
    // Create a wrapper
    const wrapper = Element.fromHtml('<span data-mce-bogus="1" data-mce-autocompleter="1"></span>', editor.getDoc());

    // Wrap the content
    Insert.append(wrapper, Element.fromDom(range.extractContents()));
    range.insertNode(wrapper.dom());
    Traverse.parent(wrapper).each((elm) =&gt; elm.dom().normalize());

    // Update the cursor position
    CursorPosition.last(wrapper).map((last) =&gt; {
      editor.selection.setCursorLocation(last.dom(), Awareness.getEnd(last));
    });

    return wrapper;
  });
};
github tinymce / tinymce / modules / tinymce / src / core / main / ts / annotate / AnnotationContext.ts View on Github external
const context = (editor: Editor, elem: any, wrapName: string, nodeName: string): ChildContext => {
  return Traverse.parent(elem).fold(
    () => ChildContext.Skipping,

    (parent) => {
      // We used to skip these, but given that they might be representing empty paragraphs, it probably
      // makes sense to treat them just like text nodes
      if (nodeName === 'br' || isZeroWidth(elem)) {
        return ChildContext.Valid;
      } else if (isAnnotation(elem)) {
        return ChildContext.Existing;
      } else if (isCaretNode(elem)) {
        return ChildContext.Caret;
      } else if (!FormatUtils.isValid(editor, wrapName, nodeName) || !FormatUtils.isValid(editor, Node.name(parent), wrapName)) {
        return ChildContext.InvalidChild;
      } else {
        return ChildContext.Valid;
      }
github tinymce / tinymce / modules / tinymce / src / themes / mobile / main / ts / util / FontSizes.ts View on Github external
const getRawOrComputed = function (isRoot, rawStart) {
  const optStart = Node.isElement(rawStart) ? Option.some(rawStart) : Traverse.parent(rawStart).filter(Node.isElement);
  return optStart.map(function (start) {
    const inline = PredicateFind.closest(start, (elem) => Css.getRaw(elem, 'font-size').isSome(), isRoot)
      .bind((elem) => Css.getRaw(elem, 'font-size'));

    return inline.getOrThunk(function () {
      return Css.get(start, 'font-size');
    });
  }).getOr('');
};
github tinymce / tinymce / modules / tinymce / src / themes / silver / main / ts / ui / dialog / UrlInput.ts View on Github external
          getRoot: (comp) => Traverse.parent(comp.element()),
          invalidClass: 'tox-control-wrap--status-invalid',
github tinymce / tinymce / src / themes / silver / main / ts / ui / dialog / TextField.ts View on Github external
getRoot(input) {
        return Traverse.parent(input.element());
      },
      invalidClass: 'tox-invalid',
github tinymce / tinymce / modules / tinymce / src / core / main / ts / commands / IndentOutdent.ts View on Github external
const parentIsListComponent = (el: Element) => {
  return Traverse.parent(el).map(isListComponent).getOr(false);
};
github tinymce / tinymce / modules / tinymce / src / plugins / lists / main / ts / listModel / Entry.ts View on Github external
const createEntry = (li: Element, depth: number, isSelected: boolean): Option =&gt; {
  return Traverse.parent(li).filter(Node.isElement).map((list) =&gt; {
    return {
      depth,
      isSelected,
      content: cloneItemContent(li),
      itemAttributes: Attr.clone(li),
      listAttributes: Attr.clone(list),
      listType: Node.name(list) as ListType
    };
  });
};
github tinymce / tinymce / modules / tinymce / src / plugins / lists / main / ts / core / DlIndentation.ts View on Github external
const outdentDlItem = (editor: Editor, item: Element): void => {
  if (Compare.is(item, 'dd')) {
    Replication.mutate(item, 'dt');
  } else if (Compare.is(item, 'dt')) {
    Traverse.parent(item).each((dl) => SplitList.splitList(editor, dl.dom(), item.dom()));
  }
};