Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

110 linhas
3.5 KiB

  1. /**
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. *
  7. * @format
  8. *
  9. * @emails oncall+draft_js
  10. *
  11. * This is unstable and not part of the public API and should not be used by
  12. * production systems. This file may be update/removed without notice.
  13. */
  14. 'use strict';
  15. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  16. var DraftEditorDecoratedLeaves = require("./DraftEditorDecoratedLeaves.react");
  17. var DraftEditorLeaf = require("./DraftEditorLeaf.react");
  18. var DraftOffsetKey = require("./DraftOffsetKey");
  19. var Immutable = require("immutable");
  20. var React = require("react");
  21. var cx = require("fbjs/lib/cx");
  22. var List = Immutable.List;
  23. var DraftEditorNode =
  24. /*#__PURE__*/
  25. function (_React$Component) {
  26. _inheritsLoose(DraftEditorNode, _React$Component);
  27. function DraftEditorNode() {
  28. return _React$Component.apply(this, arguments) || this;
  29. }
  30. var _proto = DraftEditorNode.prototype;
  31. _proto.render = function render() {
  32. var _this$props = this.props,
  33. block = _this$props.block,
  34. contentState = _this$props.contentState,
  35. customStyleFn = _this$props.customStyleFn,
  36. customStyleMap = _this$props.customStyleMap,
  37. decorator = _this$props.decorator,
  38. direction = _this$props.direction,
  39. forceSelection = _this$props.forceSelection,
  40. hasSelection = _this$props.hasSelection,
  41. selection = _this$props.selection,
  42. tree = _this$props.tree;
  43. var blockKey = block.getKey();
  44. var text = block.getText();
  45. var lastLeafSet = tree.size - 1;
  46. var children = this.props.children || tree.map(function (leafSet, ii) {
  47. var decoratorKey = leafSet.get('decoratorKey');
  48. var leavesForLeafSet = leafSet.get('leaves');
  49. var lastLeaf = leavesForLeafSet.size - 1;
  50. var Leaves = leavesForLeafSet.map(function (leaf, jj) {
  51. var offsetKey = DraftOffsetKey.encode(blockKey, ii, jj);
  52. var start = leaf.get('start');
  53. var end = leaf.get('end');
  54. return React.createElement(DraftEditorLeaf, {
  55. key: offsetKey,
  56. offsetKey: offsetKey,
  57. block: block,
  58. start: start,
  59. selection: hasSelection ? selection : null,
  60. forceSelection: forceSelection,
  61. text: text.slice(start, end),
  62. styleSet: block.getInlineStyleAt(start),
  63. customStyleMap: customStyleMap,
  64. customStyleFn: customStyleFn,
  65. isLast: decoratorKey === lastLeafSet && jj === lastLeaf
  66. });
  67. }).toArray();
  68. if (!decoratorKey || !decorator) {
  69. return Leaves;
  70. }
  71. return React.createElement(DraftEditorDecoratedLeaves, {
  72. block: block,
  73. children: Leaves,
  74. contentState: contentState,
  75. decorator: decorator,
  76. decoratorKey: decoratorKey,
  77. direction: direction,
  78. leafSet: leafSet,
  79. text: text,
  80. key: ii
  81. });
  82. }).toArray();
  83. return React.createElement("div", {
  84. "data-offset-key": DraftOffsetKey.encode(blockKey, 0, 0),
  85. className: cx({
  86. 'public/DraftStyleDefault/block': true,
  87. 'public/DraftStyleDefault/ltr': direction === 'LTR',
  88. 'public/DraftStyleDefault/rtl': direction === 'RTL'
  89. })
  90. }, children);
  91. };
  92. return DraftEditorNode;
  93. }(React.Component);
  94. module.exports = DraftEditorNode;