UNPKG

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