• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript darwin.InputHandlers类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了TypeScript中@ephox/darwin.InputHandlers的典型用法代码示例。如果您正苦于以下问题:TypeScript InputHandlers类的具体用法?TypeScript InputHandlers怎么用?TypeScript InputHandlers使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了InputHandlers类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的TypeScript代码示例。

示例1: function

  editor.on('init', function (e) {
    const win = editor.getWin();
    const body = Util.getBody(editor);
    const isRoot = Util.getIsRoot(editor);

    const syncSelection = function () {
      const sel = editor.selection;
      const start = Element.fromDom(sel.getStart());
      const end = Element.fromDom(sel.getEnd());
      const startTable = TableLookup.table(start);
      const endTable = TableLookup.table(end);
      const sameTable = startTable.bind(function (tableStart) {
        return endTable.bind(function (tableEnd) {
          return Compare.eq(tableStart, tableEnd) ? Option.some(true) : Option.none();
        });
      });
      sameTable.fold(function () {
        annotations.clear(body);
      }, Fun.noop);
    };

    const mouseHandlers = InputHandlers.mouse(win, body, isRoot, annotations);
    const keyHandlers = InputHandlers.keyboard(win, body, isRoot, annotations);
    const hasShiftKey = (event) => event.raw().shiftKey === true;

    const handleResponse = function (event, response) {
      // Only handle shift key non shiftkey cell navigation is handled by core
      if (!hasShiftKey(event)) {
        return;
      }

      if (response.kill()) {
        event.kill();
      }
      response.selection().each(function (ns) {
        const relative = Selection.relative(ns.start(), ns.finish());
        const rng = SelectionDirection.asLtrRange(win, relative);
        editor.selection.setRng(rng);
      });
    };

    const keyup = function (event) {
      const wrappedEvent = wrapEvent(event);
      // Note, this is an optimisation.
      if (wrappedEvent.raw().shiftKey && SelectionKeys.isNavigation(wrappedEvent.raw().which)) {
        const rng = editor.selection.getRng();
        const start = Element.fromDom(rng.startContainer);
        const end = Element.fromDom(rng.endContainer);
        keyHandlers.keyup(wrappedEvent, start, rng.startOffset, end, rng.endOffset).each(function (response) {
          handleResponse(wrappedEvent, response);
        });
      }
    };

    const checkLast = function (last) {
      return !Attr.has(last, 'data-mce-bogus') && Node.name(last) !== 'br' && !(Node.isText(last) && Text.get(last).length === 0);
    };

    const getLast = function () {
      const body = Element.fromDom(editor.getBody());

      const lastChild = Traverse.lastChild(body);

      const getPrevLast = function (last) {
        return Traverse.prevSibling(last).bind(function (prevLast) {
          return checkLast(prevLast) ? Option.some(prevLast) : getPrevLast(prevLast);
        });
      };

      return lastChild.bind(function (last) {
        return checkLast(last) ? Option.some(last) : getPrevLast(last);
      });
    };

    const keydown = function (event) {
      const wrappedEvent = wrapEvent(event);
      lazyResize().each(function (resize) {
        resize.hideBars();
      });

      if (event.which === 40) {
        getLast().each(function (last) {
          if (Node.name(last) === 'table') {
            if (getForcedRootBlock(editor)) {
              editor.dom.add(
                editor.getBody(),
                getForcedRootBlock(editor),
                getForcedRootBlockAttrs(editor),
                '<br/>'
              );
            } else {
              editor.dom.add(editor.getBody(), 'br');
            }
          }
        });
      }

      const rng = editor.selection.getRng();
      const startContainer = Element.fromDom(editor.selection.getStart());
      const start = Element.fromDom(rng.startContainer);
//.........这里部分代码省略.........
开发者ID:abstask,项目名称:tinymce,代码行数:101,代码来源:CellSelection.ts


示例2: function

  editor.on('init', function (e) {
    const win = editor.getWin();
    const body = Util.getBody(editor);
    const isRoot = Util.getIsRoot(editor);

    // When the selection changes through either the mouse or keyboard, and the selection is no longer within the table.
    // Remove the selection.
    const syncSelection = function () {
      const sel = editor.selection;
      const start = Element.fromDom(sel.getStart());
      const end = Element.fromDom(sel.getEnd());
      const shared = DomParent.sharedOne(TableLookup.table, [start, end]);
      shared.fold(function () {
        annotations.clear(body);
      }, Fun.noop);
    };

    const mouseHandlers = InputHandlers.mouse(win, body, isRoot, annotations);
    const keyHandlers = InputHandlers.keyboard(win, body, isRoot, annotations);
    const hasShiftKey = (event) => event.raw().shiftKey === true;

    const handleResponse = function (event, response) {
      // Only handle shift key non shiftkey cell navigation is handled by core
      if (!hasShiftKey(event)) {
        return;
      }

      if (response.kill()) {
        event.kill();
      }
      response.selection().each(function (ns) {
        const relative = Selection.relative(ns.start(), ns.finish());
        const rng = SelectionDirection.asLtrRange(win, relative);
        editor.selection.setRng(rng);
      });
    };

    const keyup = function (event) {
      const wrappedEvent = wrapEvent(event);
      // Note, this is an optimisation.
      if (wrappedEvent.raw().shiftKey && SelectionKeys.isNavigation(wrappedEvent.raw().which)) {
        const rng = editor.selection.getRng();
        const start = Element.fromDom(rng.startContainer);
        const end = Element.fromDom(rng.endContainer);
        keyHandlers.keyup(wrappedEvent, start, rng.startOffset, end, rng.endOffset).each(function (response) {
          handleResponse(wrappedEvent, response);
        });
      }
    };

    const keydown = function (event: KeyboardEvent) {
      const wrappedEvent = wrapEvent(event);
      lazyResize().each(function (resize) {
        resize.hideBars();
      });

      const rng = editor.selection.getRng();
      const startContainer = Element.fromDom(editor.selection.getStart());
      const start = Element.fromDom(rng.startContainer);
      const end = Element.fromDom(rng.endContainer);
      const direction = Direction.directionAt(startContainer).isRtl() ? SelectionKeys.rtl : SelectionKeys.ltr;
      keyHandlers.keydown(wrappedEvent, start, rng.startOffset, end, rng.endOffset, direction).each(function (response) {
        handleResponse(wrappedEvent, response);
      });
      lazyResize().each(function (resize) {
        resize.showBars();
      });
    };

    const isMouseEvent = (event: any): event is MouseEvent => event.hasOwnProperty('x') && event.hasOwnProperty('y');

    const wrapEvent = function (event: MouseEvent | KeyboardEvent) {
      // IE9 minimum
      const target = Element.fromDom(event.target as HTMLElement);

      const stop = function () {
        event.stopPropagation();
      };

      const prevent = function () {
        event.preventDefault();
      };

      const kill = Fun.compose(prevent, stop); // more of a sequence than a compose, but same effect

      // FIX: Don't just expose the raw event. Need to identify what needs standardisation.
      return {
        target:  Fun.constant(target),
        x:       Fun.constant(isMouseEvent(event) ? event.x : null),
        y:       Fun.constant(isMouseEvent(event) ? event.y : null),
        stop,
        prevent,
        kill,
        raw:     Fun.constant(event)
      };
    };

    const isLeftMouse = function (raw: MouseEvent) {
      return raw.button === 0;
    };
//.........这里部分代码省略.........
开发者ID:tinymce,项目名称:tinymce,代码行数:101,代码来源:CellSelection.ts



注:本文中的@ephox/darwin.InputHandlers类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript darwin.SelectionAnnotation类代码示例发布时间:2022-05-28
下一篇:
TypeScript bridge.Toolbar类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap