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


TypeScript Chain.binder方法代碼示例

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


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

示例1: function

 const cHasState = function (predicate) {
   return Chain.control(
     Chain.binder(function (element) {
       return predicate(element) ? Result.value(element) : Result.error('Predicate didn\'t match.');
     }),
     Guard.addLogging('Assert element has state')
   );
 };
開發者ID:tinymce,項目名稱:tinymce,代碼行數:8,代碼來源:ImageOps.ts

示例2:

const sTriggerEventOnFocused = (label, component, eventName) => Logger.t(
  'DomSteps.sTriggerEventOnFocused(' + eventName + '): ' + label,
  Chain.asStep(Traverse.owner(component.element()), [
    FocusTools.cGetFocused,
    Chain.binder((focused) => component.getSystem().getByDom(focused)),
    Chain.op((input) => AlloyTriggers.emit(input, eventName))
  ])
);
開發者ID:tinymce,項目名稱:tinymce,代碼行數:8,代碼來源:DomSteps.ts

示例3: function

 const cFromDomSubSection = function (html, startPath, endPath) {
   return Chain.binder(function (_) {
     const tableElm = Element.fromHtml(html);
     const startElm = Hierarchy.follow(tableElm, startPath).getOrDie();
     const endElm = Hierarchy.follow(tableElm, endPath).getOrDie();
     return SimpleTableModel.subsection(SimpleTableModel.fromDom(tableElm), startElm, endElm).fold(
       Fun.constant(Result.error('Failed to get the subsection')),
       Result.value
     );
   });
 };
開發者ID:aha-app,項目名稱:tinymce-word-paste-filter,代碼行數:11,代碼來源:SimpleTableModelTest.ts

示例4:

    (editor: Editor, onSuccess, onFailure) => {
      const replacedElem = Element.fromDom(editor.getElement());

      Pipeline.async({ }, [
        Chain.asStep(Body.body(), [
          UiFinder.cFindIn(`#${Attr.get(replacedElem, 'id')}`),
          Chain.binder((elem) => Traverse.nextSibling(elem).fold(() => Result.error('Replaced element has no next sibling'), Result.value)),
          Chain.mapper((elem) => Class.has(elem, 'tox-tinymce')),
          Assertions.cAssertEq('Replaced element\'s next sibling has "tox-tinymce" class', true)
        ])
      ], onSuccess, onFailure);
    },
開發者ID:tinymce,項目名稱:tinymce,代碼行數:12,代碼來源:ToxWrappingTest.ts

示例5:

    (doc, body, gui, component, store) => {
      return [
        Assertions.sAssertStructure(
          'Checking initial structure',
          ApproxStructure.build((s, str, arr) => {
            return s.element('div', {
              children: [
                s.element('label', {
                  classes: [ arr.has('tox-label') ],
                  html: str.is('Dropzone Label')
                }),
                s.element('div', { })
              ]
            });
          }),
          component.element()
        ),

        Logger.t(
          'Trigger drop on zone',
          Chain.asStep(component.element(), [
            UiFinder.cFindIn('.tox-dropzone'),
            Chain.binder(component.getSystem().getByDom),
            Chain.op((zone) => {
              // TODO: Add 'drop' to NativeEvents
              AlloyTriggers.emitWith(zone, 'drop', {
                raw: {
                  dataTransfer: {
                    files: [
                      { name: 'image1.png' },
                      { name: 'image2.bmp' },
                      { name: 'image3.jpg' }
                    ]
                  }
                }
              });
            })
          ])
        ),

        Step.sync(() => {
          const zone = Composing.getCurrent(component).getOrDie(
            'Failed trying to get the zone from the container'
          );
          const filesValue = Representing.getValue(zone);
          Assertions.assertEq('Checking value of dropzone', [
            { name: 'image1.png' },
            { name: 'image3.jpg' }
          ], filesValue);
        })
      ];
    },
開發者ID:tinymce,項目名稱:tinymce,代碼行數:52,代碼來源:DropzoneTest.ts

示例6: TestExtras

UnitTest.asynctest('WindowManager:inline-dialog Test', (success, failure) => {
  const helpers = TestExtras();
  const windowManager = WindowManager.setup(helpers.extras);

  const cGetDialogLabelId = Chain.binder((dialogE: Element) => {
    if (Attr.has(dialogE, 'aria-labelledby')) {
      const labelId = Attr.get(dialogE, 'aria-labelledby');
      return labelId.length > 0 ? Result.value(labelId) : Result.error('Dialog has zero length aria-labelledby attribute');
    } else {
      return Result.error('Dialog has no aria-labelledby attribute');
    }
  });

  const sAssertDialogLabelledBy =
    Chain.asStep(Body.body(), [NamedChain.asChain([
      NamedChain.direct(NamedChain.inputName(), UiFinder.cFindIn('[role="dialog"]'), 'dialog'),
      NamedChain.direct('dialog', cGetDialogLabelId, 'labelId'),
      NamedChain.bundle((obj) => UiFinder.findIn(obj.dialog, `#${obj.labelId}`)),
    ])]);

  const sTestDialogLabelled = (params) =>
    Logger.t(
      `Dialog should have "aria-labelledby" for config "${JSON.stringify(params)}"`,
      GeneralSteps.sequence([
        Step.sync(() => {
            const dialogSpec: Types.Dialog.DialogApi<{}> = {
              title: 'Silver Test Inline (Toolbar) Dialog',
              body: {
                type: 'panel',
                items: []
              },
              buttons: [],
              initialData: {}
            };
            windowManager.open(dialogSpec, params, Fun.noop );
        }),
        sAssertDialogLabelledBy,
      ])
    );

  Pipeline.async({}, [
    TestHelpers.GuiSetup.mAddStyles(Element.fromDom(document), [
      '.tox-dialog { background: white; border: 2px solid black; padding: 1em; margin: 1em; }'
    ]),
    sTestDialogLabelled({ inline: 'toolbar' }),
    sTestDialogLabelled({ inline: 'not-inline!!' }),
    TestHelpers.GuiSetup.mRemoveStyles
  ], () => {
    helpers.destroy();
    success();
  }, failure);
});
開發者ID:tinymce,項目名稱:tinymce,代碼行數:52,代碼來源:SilverDialogAriaLabelTest.ts

示例7:

 const sAssertVisibleFocusInside = (cGetFocused, selector: string) => Chain.asStep(doc, [
   cGetFocused,
   Chain.mapper((elem) => {
     return elem.dom().getBoundingClientRect();
   }),
   Chain.binder((rect: ClientRect) => {
     const middle = { x: rect.left + rect.width / 2, y: rect.top + rect.height / 2 };
     const range = document.caretRangeFromPoint(middle.x, middle.y);
     if (! range) {
       return Result.error('Could not find a range at coordinate: (' + middle.x + ', ' + middle.y + ')');
     } else {
       return SelectorExists.closest(Element.fromDom(range.startContainer), selector) ? Result.value(rect) : Result.error('Range was not within: "' + selector + '". Are you sure that it is on top of the dialog?');
     }
   })
 ]);
開發者ID:tinymce,項目名稱:tinymce,代碼行數:15,代碼來源:SilverDialogPopupsTest.ts

示例8: function

UnitTest.asynctest('browser.tinymce.core.delete.TableDeleteActionTest', function () {
  const success = arguments[arguments.length - 2];
  const failure = arguments[arguments.length - 1];

  const cFromHtml = function (html, startPath, startOffset, endPath, endOffset) {
    return Chain.mapper(function () {
      const elm = Element.fromHtml(html);
      const sc = Hierarchy.follow(elm, startPath).getOrDie();
      const ec = Hierarchy.follow(elm, endPath).getOrDie();
      const rng = document.createRange();

      rng.setStart(sc.dom(), startOffset);
      rng.setEnd(ec.dom(), endOffset);

      return TableDeleteAction.getActionFromRange(elm, rng);
    });
  };

  const fail = function (message) {
    return Fun.constant(Result.error(message));
  };

  const cAssertNone = Chain.op(function (x) {
    Assertions.assertEq('Is none', true, x.isNone());
  });

  const cExtractActionCells = Chain.binder(function (actionOpt) {
    return actionOpt
        .fold(
          fail('unexpected nothing'),
          function (action) {
            return action.fold(
              fail('unexpected action'),
              function (xs) {
                const cellString = Arr.map(xs, Html.getOuter).join('');

                return Result.value(cellString);
              }
            );
          }
        );
  });

  const cExtractTableFromDeleteAction = Chain.binder(function (actionOpt) {
    return actionOpt
      .fold(
        fail('unexpected nothing'),
        function (action) {
          return action.fold(
            function (table) {
              return Result.value(Html.getOuter(table));
            },
            fail('unexpected action')
          );
        }
      );
  });

  Pipeline.async({}, [
    Logger.t('collapsed range should return none', Chain.asStep({}, [
      cFromHtml('<table><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbody></table>', [0, 0, 0, 0], 0, [0, 0, 0, 0], 0),
      cAssertNone
    ])),

    Logger.t('select two out of three cells returns the emptycells action', Chain.asStep({}, [
      cFromHtml('<table><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbody></table>', [0, 0, 0, 0], 0, [0, 0, 1, 0], 1),
      cExtractActionCells,
      Assertions.cAssertEq('Should be cells', '<td>a</td><td>b</td>')
    ])),

    Logger.t('select two out of three cells returns the emptycells action', Chain.asStep({}, [
      cFromHtml('<table><tbody><tr><th>a</th><th>b</th><th>c</th></tr></tbody></table>', [0, 0, 0, 0], 0, [0, 0, 1, 0], 1),
      cExtractActionCells,
      Assertions.cAssertEq('Should be cells', '<th>a</th><th>b</th>')
    ])),

    Logger.t('select three out of three cells returns the removeTable action', Chain.asStep({}, [
      cFromHtml('<table><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbody></table>', [0, 0, 0, 0], 0, [0, 0, 2, 0], 1),
      cExtractTableFromDeleteAction,
      Assertions.cAssertEq('should be table', '<table><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbody></table>')
    ])),

    Logger.t('select between rows, not all cells', Chain.asStep({}, [
      cFromHtml(
        '<table><tbody><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>d</td><td>e</td><td>f</td></tr></tbody></table>',
        [0, 0, 1, 0], 0, [0, 1, 0, 0], 1
      ),
      cExtractActionCells,
      Assertions.cAssertEq('should be cells', '<th>b</th><th>c</th><td>d</td>')
    ])),

    Logger.t('select between rows, all cells', Chain.asStep({}, [
      cFromHtml(
        '<table><tbody><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>d</td><td>e</td><td>f</td></tr></tbody></table>',
        [0, 0, 0, 0], 0, [0, 1, 2, 0], 1
      ),
      cExtractTableFromDeleteAction,
      Assertions.cAssertEq('should be table', '<table><tbody><tr><th>a</th><th>b</th><th>c</th></tr><tr><td>d</td><td>e</td><td>f</td></tr></tbody></table>')
    ]))
  ], function () {
//.........這裏部分代碼省略.........
開發者ID:aha-app,項目名稱:tinymce-word-paste-filter,代碼行數:101,代碼來源:TableDeleteActionTest.ts

示例9:

const cExtractOnlyOne = (selector) => Chain.fromChains([
  UiFinder.cFindAllIn(selector),
  Chain.binder((ts) => ts.length === 1 ? Result.value(ts[0]) : Result.error('Did not find exactly 1 of ' +
    selector + '. Found: ' + ts.length))
]);
開發者ID:tinymce,項目名稱:tinymce,代碼行數:5,代碼來源:UiChainUtils.ts

示例10: function

 const cHasState = function (predicate) {
   return Chain.binder(function (element) {
     return predicate(element) ? Result.value(element) : Result.error('Predicate didn\'t match.');
   });
 };
開發者ID:abstask,項目名稱:tinymce,代碼行數:5,代碼來源:ImageOps.ts


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