当前位置: 首页>>代码示例>>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;未经允许,请勿转载。