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


TypeScript Option.each方法代碼示例

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


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

示例1: createEntry

  return Traverse.firstChild(item).filter(isList).fold(() => {

    // Update selectionState (start)
    itemSelection.each((selection) => {
      if (Compare.eq(selection.start, item)) {
        selectionState.set(true);
      }
    });

    const currentItemEntry = createEntry(item, depth, selectionState.get());

    // Update selectionState (end)
    itemSelection.each((selection) => {
      if (Compare.eq(selection.end, item)) {
        selectionState.set(false);
      }
    });

    const childListEntries: Entry[] = Traverse.lastChild(item)
      .filter(isList)
      .map((list) => parseList(depth, itemSelection, selectionState, list))
      .getOr([]);

    return currentItemEntry.toArray().concat(childListEntries);
  }, (list) => parseList(depth, itemSelection, selectionState, list));
開發者ID:danielpunkass,項目名稱:tinymce,代碼行數:25,代碼來源:ParseLists.ts

示例2:

  const cSetSelectionFromBookmark = Chain.op(function (bookmark: Option<any>) {
    bookmark.each(function (b) {
      const root = Element.fromDom(viewBlock.get());
      const win = Traverse.defaultView(root);

      SelectionBookmark.validate(root, b)
        .each(function (rng) {
          WindowSelection.setExact(win.dom(), rng.start(), rng.soffset(), rng.finish(), rng.foffset());
        });
    });
  });
開發者ID:danielpunkass,項目名稱:tinymce,代碼行數:11,代碼來源:SelectionBookmarkTest.ts

示例3:

const updateLink = (editor: Editor, anchorElm: HTMLAnchorElement, text: Option<string>, linkAttrs: Record<string, string>) => {
  // If we have text, then update the anchor elements text content
  text.each((text) => {
    if (anchorElm.hasOwnProperty('innerText')) {
      anchorElm.innerText = text;
    } else {
      anchorElm.textContent = text;
    }
  });

  editor.dom.setAttribs(anchorElm, linkAttrs);
  editor.selection.select(anchorElm);
};
開發者ID:tinymce,項目名稱:tinymce,代碼行數:13,代碼來源:Utils.ts

示例4:

 const updateSelectionState = (itemRange: ItemRange) => itemSelection.each((selection) => {
   if (Compare.eq(itemRange === ItemRange.Start ? selection.start : selection.end, item)) {
     selectionState.set(itemRange === ItemRange.Start);
   }
 });
開發者ID:mdgbayly,項目名稱:tinymce,代碼行數:5,代碼來源:ParseLists.ts

示例5: success

const open = (editor: Editor, templateList: TemplateValues[]) => {
  const createTemplates = () => {
    if (!templateList || templateList.length === 0) {
      const message = editor.translate('No templates defined.');
      editor.notificationManager.open({ text: message, type: 'info' });
      return Option.none();
    }

    return Option.from(Tools.map(templateList, (template, index) => {
      return {
        selected: index === 0,
        text: template.title,
        value: {
          url: template.url,
          content: template.content,
          description: template.description
        }
      };
    }));
  };

  const createSelectBoxItems = (templates: TemplateData[]) => {
    return Arr.map(templates, (v) => {
      return {
        text: v.text,
        value: v.text
      };
    });
  };

  const findTemplate = (templates: TemplateData[], templateTitle: string) => {
    return Arr.find(templates, (t) => {
      return t.text === templateTitle;
    });
  };

  const getTemplateContent = (t: TemplateData) => {
    return new Promise<string>((resolve, reject) => {
      if (t.value.url) {
        XHR.send({
          url: t.value.url,
          success (html: string) {
            resolve(html);
          },
          error: (e) => {
            reject(e);
          }
        });
      } else {
        resolve(t.value.content);
      }
    });
  };

  const onChange = (templates: TemplateData[], updateDialog: UpdateDialogCallback) => (api: Types.Dialog.DialogInstanceApi<DialogData>, change: { name: string }) => {
    if (change.name === 'template') {
      const newTemplateTitle = api.getData().template;
      findTemplate(templates, newTemplateTitle).each((t) => {
        api.block('Loading...');
        getTemplateContent(t).then((previewHtml) => {
          updateDialog(api, t, previewHtml);
          api.unblock();
        });
      });
    }
  };

  const onSubmit = (templates: TemplateData[]) => (api: Types.Dialog.DialogInstanceApi<DialogData>) => {
    const data = api.getData();
    findTemplate(templates, data.template).each((t) => {
      getTemplateContent(t).then((previewHtml) => {
        Templates.insertTemplate(editor, false, previewHtml);
        api.close();
      });
    });
  };

  const openDialog = (templates: TemplateData[]) => {
    const selectBoxItems = createSelectBoxItems(templates);

    const buildDialogSpec = (bodyItems: Types.Dialog.BodyComponentApi[], initialData: DialogData): Types.Dialog.DialogApi<DialogData> => ({
      title: 'Insert Template',
      size: 'large',
      body: {
        type: 'panel',
        items: bodyItems
      },
      initialData,
      buttons: [
        {
          type: 'cancel',
          name: 'cancel',
          text: 'Cancel',
        },
        {
          type: 'submit',
          name: 'save',
          text: 'Save',
          primary: true
        }
//.........這裏部分代碼省略.........
開發者ID:tinymce,項目名稱:tinymce,代碼行數:101,代碼來源:Dialog.ts


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