當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript EditorAPI.toDataNode方法代碼示例

本文整理匯總了TypeScript中wed.EditorAPI.toDataNode方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript EditorAPI.toDataNode方法的具體用法?TypeScript EditorAPI.toDataNode怎麽用?TypeScript EditorAPI.toDataNode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在wed.EditorAPI的用法示例。


在下文中一共展示了EditorAPI.toDataNode方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: executeDeleteAttribute

function executeDeleteAttribute(editor: EditorAPI,
                                data: TransformationData): void {
  const node = data.node;

  if (node == null || !isAttr(node)) {
    throw new Error("node must be an attribute");
  }

  const element = node.ownerElement!;
  const caretManager = editor.caretManager;
  const guiOwnerLoc = caretManager.mustFromDataLocation(element, 0);
  // If the node we start with is an Element, then the node in guiOwnerLoc
  // is necessarily an Element too.
  const guiOwner = guiOwnerLoc.node as Element;
  if (!guiOwner.classList.contains("_readonly")) {
    const encoded = node.name;
    const startLabel = childByClass(guiOwner, "__start_label")!;

    // An earlier version of this code relied on the order of attributes in the
    // data tree. However, this order is not consistent from platform to
    // platform. Using the order of attributes in the GUI is
    // consistent. Therefore we go to the GUI to find the next attribute.

    const values = startLabel.getElementsByClassName("_attribute_value");

    // We have to get the parent node because fromDataLocation brings us to the
    // text node that contains the value.
    const guiNode = caretManager.mustFromDataLocation(node, 0).node.parentNode;
    const index = indexOf(values, guiNode!);
    const nextGUIValue = values[index + 1];
    const nextAttr = nextGUIValue != null ?
      editor.toDataNode(nextGUIValue) : null;

    editor.dataUpdater.setAttribute(element, encoded, null);

    // We set the caret inside the next attribute, or if it does not exist,
    // inside the label.
    if (nextAttr !== null) {
      editor.caretManager.setCaret(nextAttr, 0);
    }
    else {
      editor.caretManager.setCaret(
        guiOwner.getElementsByClassName("_element_name")[0], 0);
    }
  }
}
開發者ID:lddubeau,項目名稱:wed,代碼行數:46,代碼來源:generic-tr.ts

示例2: replaceSemanticFields

export function replaceSemanticFields(editor: EditorAPI,
                                      data: SemanticFieldTransformationData):
void {
  const dataCaret = editor.caretManager.getDataCaret(true)!;
  const guiCaret = editor.caretManager.fromDataLocation(dataCaret)!;
  const guiSfsContainer = domutil.closestByClass(guiCaret.node,
                                                 "btw:semantic-fields",
                                                 editor.guiRoot);
  if (guiSfsContainer === null) {
    throw new Error("unable to acquire btw:semantic-fields");
  }

  const sfsContainer = editor.toDataNode(guiSfsContainer)!;
  const sfsParent = sfsContainer.parentNode!;
  const sfsIndex = _indexOf.call(sfsParent.childNodes, sfsContainer);
  // Remove the container from the tree.
  editor.dataUpdater.removeNode(sfsContainer);

  // and manipulate it off-line.
  while (sfsContainer.firstChild !== null) {
    sfsContainer.removeChild(sfsContainer.firstChild);
  }

  const doc = sfsContainer.ownerDocument;
  const newPaths = data.newPaths;
  const mode = editor.modeTree.getMode(sfsContainer);
  const ename = mode.getAbsoluteResolver().resolveName("btw:sf")!;

  for (const path of newPaths) {
    const sf = makeElement(doc, ename.ns, "btw:sf");
    sf.textContent = path;
    sfsContainer.appendChild(sf);
  }

  // Finally, reintroduce it to the data tree.
  editor.dataUpdater.insertNodeAt(sfsParent, sfsIndex, sfsContainer);
  editor.caretManager.setCaret(sfsContainer, 0);
}
開發者ID:mangalam-research,項目名稱:btw,代碼行數:38,代碼來源:btw-tr.ts


注:本文中的wed.EditorAPI.toDataNode方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。