No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 
 

107 líneas
3.6 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. 'use strict';
  12. var CharacterMetadata = require("./CharacterMetadata");
  13. var ContentBlock = require("./ContentBlock");
  14. var ContentState = require("./ContentState");
  15. var EditorState = require("./EditorState");
  16. var _require = require("./SampleDraftInlineStyle"),
  17. BOLD = _require.BOLD;
  18. var Immutable = require("immutable");
  19. var EMPTY = CharacterMetadata.EMPTY;
  20. var getSampleSelectionMocksForTesting = function getSampleSelectionMocksForTesting() {
  21. var root = document.createElement('div');
  22. var contents = document.createElement('div');
  23. contents.setAttribute('data-contents', 'true');
  24. root.appendChild(contents);
  25. var text = ['Washington', 'Jefferson', 'Lincoln', 'Roosevelt', 'Kennedy', 'Obama'];
  26. var textA = text[0] + text[1];
  27. var textB = text[2] + text[3];
  28. var textC = text[4] + text[5];
  29. var boldChar = CharacterMetadata.create({
  30. style: BOLD
  31. });
  32. var aChars = Immutable.List(Immutable.Repeat(EMPTY, text[0].length).concat(Immutable.Repeat(boldChar, text[1].length)));
  33. var bChars = Immutable.List(Immutable.Repeat(EMPTY, text[2].length).concat(Immutable.Repeat(boldChar, text[3].length)));
  34. var cChars = Immutable.List(Immutable.Repeat(EMPTY, text[4].length).concat(Immutable.Repeat(boldChar, text[5].length)));
  35. var contentBlocks = [new ContentBlock({
  36. key: 'a',
  37. type: 'unstyled',
  38. text: textA,
  39. characterList: aChars
  40. }), new ContentBlock({
  41. key: 'b',
  42. type: 'unstyled',
  43. text: textB,
  44. characterList: bChars
  45. }), new ContentBlock({
  46. key: 'c',
  47. type: 'unstyled',
  48. text: textC,
  49. characterList: cChars
  50. })];
  51. var contentState = ContentState.createFromBlockArray(contentBlocks);
  52. var editorState = EditorState.createWithContent(contentState);
  53. var textNodes = text.map(function (text) {
  54. return document.createTextNode(text);
  55. });
  56. var leafChildren = textNodes.map(function (textNode) {
  57. var span = document.createElement('span');
  58. span.appendChild(textNode);
  59. return span;
  60. });
  61. var leafs = ['a-0-0', 'a-0-1', 'b-0-0', 'b-0-1', 'c-0-0', 'c-0-1'].map(function (blockKey, index) {
  62. var span = document.createElement('span');
  63. span.setAttribute('data-offset-key', '' + blockKey);
  64. span.appendChild(leafChildren[index]);
  65. return span;
  66. });
  67. var decorators = ['a-0-0', 'b-0-0', 'c-0-0'].map(function (decoratorKey, index) {
  68. var span = document.createElement('span');
  69. span.setAttribute('data-offset-key', '' + decoratorKey);
  70. span.appendChild(leafs[index * 2]);
  71. span.appendChild(leafs[index * 2 + 1]);
  72. return span;
  73. });
  74. var blocks = ['a-0-0', 'b-0-0', 'c-0-0'].map(function (blockKey, index) {
  75. var outerBlockElement = document.createElement('div');
  76. var innerBlockElement = document.createElement('div');
  77. innerBlockElement.setAttribute('data-offset-key', '' + blockKey);
  78. innerBlockElement.appendChild(decorators[index]);
  79. outerBlockElement.setAttribute('data-offset-key', '' + blockKey);
  80. outerBlockElement.setAttribute('data-block', 'true');
  81. outerBlockElement.appendChild(innerBlockElement);
  82. return outerBlockElement;
  83. });
  84. blocks.forEach(function (blockElem) {
  85. contents.appendChild(blockElem);
  86. });
  87. return {
  88. editorState: editorState,
  89. root: root,
  90. contents: contents,
  91. blocks: blocks,
  92. decorators: decorators,
  93. leafs: leafs,
  94. leafChildren: leafChildren,
  95. textNodes: textNodes
  96. };
  97. };
  98. module.exports = getSampleSelectionMocksForTesting;