Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

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