Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

getSampleStateForTesting.js 2.5 KiB

3 лет назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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 BlockMapBuilder = require("./BlockMapBuilder");
  13. var CharacterMetadata = require("./CharacterMetadata");
  14. var ContentBlock = require("./ContentBlock");
  15. var ContentState = require("./ContentState");
  16. var EditorState = require("./EditorState");
  17. var SampleDraftInlineStyle = require("./SampleDraftInlineStyle");
  18. var SelectionState = require("./SelectionState");
  19. var Immutable = require("immutable");
  20. var BOLD = SampleDraftInlineStyle.BOLD,
  21. ITALIC = SampleDraftInlineStyle.ITALIC;
  22. var ENTITY_KEY = '1';
  23. var BLOCKS = [new ContentBlock({
  24. key: 'a',
  25. type: 'unstyled',
  26. text: 'Alpha',
  27. characterList: Immutable.List(Immutable.Repeat(CharacterMetadata.EMPTY, 5))
  28. }), new ContentBlock({
  29. key: 'b',
  30. type: 'unordered-list-item',
  31. text: 'Bravo',
  32. characterList: Immutable.List(Immutable.Repeat(CharacterMetadata.create({
  33. style: BOLD,
  34. entity: ENTITY_KEY
  35. }), 5))
  36. }), new ContentBlock({
  37. key: 'c',
  38. type: 'code-block',
  39. text: 'Test',
  40. characterList: Immutable.List(Immutable.Repeat(CharacterMetadata.EMPTY, 4))
  41. }), new ContentBlock({
  42. key: 'd',
  43. type: 'code-block',
  44. text: '',
  45. characterList: Immutable.List()
  46. }), new ContentBlock({
  47. key: 'e',
  48. type: 'code-block',
  49. text: '',
  50. characterList: Immutable.List()
  51. }), new ContentBlock({
  52. key: 'f',
  53. type: 'blockquote',
  54. text: 'Charlie',
  55. characterList: Immutable.List(Immutable.Repeat(CharacterMetadata.create({
  56. style: ITALIC,
  57. entity: null
  58. }), 7))
  59. })];
  60. var selectionState = new SelectionState({
  61. anchorKey: 'a',
  62. anchorOffset: 0,
  63. focusKey: 'a',
  64. focusOffset: 0,
  65. isBackward: false,
  66. hasFocus: true
  67. });
  68. var blockMap = BlockMapBuilder.createFromArray(BLOCKS);
  69. var contentState = new ContentState({
  70. blockMap: blockMap,
  71. entityMap: Immutable.OrderedMap(),
  72. selectionBefore: selectionState,
  73. selectionAfter: selectionState
  74. }).createEntity({
  75. type: 'IMAGE',
  76. mutability: 'IMMUTABLE',
  77. data: null
  78. });
  79. var editorState = EditorState.createWithContent(contentState);
  80. editorState = EditorState.forceSelection(editorState, selectionState);
  81. var getSampleStateForTesting = function getSampleStateForTesting() {
  82. return {
  83. editorState: editorState,
  84. contentState: contentState,
  85. selectionState: selectionState
  86. };
  87. };
  88. module.exports = getSampleStateForTesting;