@studysync/draft-js-modifiers 0.4.11 → 0.4.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/insertBlockAfter.js +3 -1
- package/es/insertBlockBefore.js +3 -1
- package/flow/stub/__dev__.js +3 -0
- package/insertBlockAfter.js +3 -1
- package/insertBlockBefore.js +3 -1
- package/package.json +6 -3
- package/script/add-module.js +48 -0
- package/src/addBlock.js +98 -0
- package/src/adjustBlockDepth.js +21 -0
- package/src/atEndOfBlock.js +10 -0
- package/src/atStartOfBlock.js +7 -0
- package/src/changeBlockType.js +19 -0
- package/src/getAllEntities.js +14 -0
- package/src/getEntitiesForBlock.js +29 -0
- package/src/getEntitiesForSelection.js +20 -0
- package/src/getSelectedText.js +11 -0
- package/src/getSimilarAdjacentBlocks.js +53 -0
- package/src/index.js +42 -0
- package/src/insertAtomicBlock.js +23 -0
- package/src/insertBlockAfter.js +42 -0
- package/src/insertBlockBefore.js +42 -0
- package/src/insertEmptyBlock.js +12 -0
- package/src/insertEntity.js +56 -0
- package/src/insertNewBlock.js +61 -0
- package/src/insertText.js +23 -0
- package/src/mergeBlockData.js +13 -0
- package/src/mergeBlockDataByKey.js +12 -0
- package/src/mergeEntityData.js +13 -0
- package/src/modifyBlock.js +20 -0
- package/src/modifyBlockByKey.js +19 -0
- package/src/moveCaretAfterBlock.js +26 -0
- package/src/moveCaretToEnd.js +20 -0
- package/src/removeBlock.js +43 -0
- package/src/removeBlockStyle.js +17 -0
- package/src/removeEntity.js +38 -0
- package/src/removeInlineStyles.js +29 -0
- package/src/resetBlock.js +29 -0
- package/src/selectAll.js +15 -0
- package/src/selectBlockByKey.js +20 -0
- package/src/setBlockData.js +14 -0
- package/src/toggleBlockStyle.js +33 -0
- package/src/toggleBlockType.js +12 -0
- package/src/toggleEntity.js +11 -0
- package/src/toggleInlineStyle.js +11 -0
- package/src/trimEditorState.js +41 -0
- package/src/utils/getCurrentBlock.js +10 -0
- package/src/utils/numbers.js +3 -0
- package/test/adjustBlockDepth.js +45 -0
- package/test/export.js +14 -0
- package/test/fixtures/createEditorState.js +12 -0
- package/test/fixtures/omitBlockKeysFromRawContent.js +9 -0
- package/test/insertAtomicBlock.js +89 -0
- package/test/insertEmptyBlock.js +65 -0
- package/test/insertNewBlock.js +68 -0
- package/test/insertText.js +58 -0
- package/test/mergeBlockData.js +40 -0
- package/test/mergeBlockDataByKey.js +103 -0
- package/test/mergeEntityData.js +49 -0
- package/test/modifyBlock.js +52 -0
- package/test/modifyBlockByKey.js +91 -0
- package/test/removeBlockStyle.js +52 -0
- package/test/removeInlineStyles.js +68 -0
- package/test/resetBlock.js +83 -0
- package/test/toggleBlockType.js +4 -0
- package/test/toggleEntity.js +4 -0
- package/test/toggleInlineStyle.js +4 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { convertToRaw } from 'draft-js'
|
|
3
|
+
import createEditorState from './fixtures/createEditorState'
|
|
4
|
+
|
|
5
|
+
import removeBlockStyle from '../src/removeBlockStyle'
|
|
6
|
+
|
|
7
|
+
test('removeBlockStyle', t => {
|
|
8
|
+
const beforeRawContentState = {
|
|
9
|
+
entityMap: {},
|
|
10
|
+
blocks: [{
|
|
11
|
+
key: 'item1',
|
|
12
|
+
text: '',
|
|
13
|
+
type: 'header-one',
|
|
14
|
+
depth: 0,
|
|
15
|
+
inlineStyleRanges: [],
|
|
16
|
+
entityRanges: [],
|
|
17
|
+
data: {},
|
|
18
|
+
}],
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const afterRawContentState = {
|
|
22
|
+
entityMap: {},
|
|
23
|
+
blocks: [{
|
|
24
|
+
key: 'item1',
|
|
25
|
+
text: '',
|
|
26
|
+
type: 'unstyled',
|
|
27
|
+
depth: 0,
|
|
28
|
+
inlineStyleRanges: [],
|
|
29
|
+
entityRanges: [],
|
|
30
|
+
data: {},
|
|
31
|
+
}],
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const editorState = createEditorState(
|
|
35
|
+
beforeRawContentState,
|
|
36
|
+
{
|
|
37
|
+
anchorKey: 'item1',
|
|
38
|
+
anchorOffset: 0,
|
|
39
|
+
focusKey: 'item1',
|
|
40
|
+
focusOffset: 0,
|
|
41
|
+
isBackward: false,
|
|
42
|
+
hasFocus: true,
|
|
43
|
+
}
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
const newEditorState = removeBlockStyle(editorState)
|
|
47
|
+
t.not(newEditorState, editorState)
|
|
48
|
+
t.deepEqual(
|
|
49
|
+
convertToRaw(newEditorState.getCurrentContent()),
|
|
50
|
+
afterRawContentState
|
|
51
|
+
)
|
|
52
|
+
})
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { convertToRaw } from 'draft-js'
|
|
3
|
+
import createEditorState from './fixtures/createEditorState'
|
|
4
|
+
|
|
5
|
+
import removeInlineStyles from '../src/removeInlineStyles'
|
|
6
|
+
|
|
7
|
+
test('removeInlineStyles', t => {
|
|
8
|
+
const beforeRawContentState = {
|
|
9
|
+
entityMap: {},
|
|
10
|
+
blocks: [{
|
|
11
|
+
key: 'item1',
|
|
12
|
+
text: 'asdfghjkl;',
|
|
13
|
+
type: 'unstyled',
|
|
14
|
+
depth: 0,
|
|
15
|
+
inlineStyleRanges: [
|
|
16
|
+
{
|
|
17
|
+
length: 2,
|
|
18
|
+
offset: 1,
|
|
19
|
+
style: 'BOLD',
|
|
20
|
+
},
|
|
21
|
+
{
|
|
22
|
+
length: 3,
|
|
23
|
+
offset: 3,
|
|
24
|
+
style: 'ITALIC',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
length: 5,
|
|
28
|
+
offset: 0,
|
|
29
|
+
style: 'UNDERLINE',
|
|
30
|
+
},
|
|
31
|
+
],
|
|
32
|
+
entityRanges: [],
|
|
33
|
+
data: {},
|
|
34
|
+
}],
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const afterRawContentState = {
|
|
38
|
+
entityMap: {},
|
|
39
|
+
blocks: [{
|
|
40
|
+
key: 'item1',
|
|
41
|
+
text: 'asdfghjkl;',
|
|
42
|
+
type: 'unstyled',
|
|
43
|
+
depth: 0,
|
|
44
|
+
inlineStyleRanges: [],
|
|
45
|
+
entityRanges: [],
|
|
46
|
+
data: {},
|
|
47
|
+
}],
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
const editorState = createEditorState(
|
|
51
|
+
beforeRawContentState,
|
|
52
|
+
{
|
|
53
|
+
anchorKey: 'item1',
|
|
54
|
+
anchorOffset: 0,
|
|
55
|
+
focusKey: 'item1',
|
|
56
|
+
focusOffset: 0,
|
|
57
|
+
isBackward: false,
|
|
58
|
+
hasFocus: true,
|
|
59
|
+
}
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
const newEditorState = removeInlineStyles(editorState, ['BOLD', 'ITALIC', 'UNDERLINE'])
|
|
63
|
+
t.not(newEditorState, editorState)
|
|
64
|
+
t.deepEqual(
|
|
65
|
+
convertToRaw(newEditorState.getCurrentContent()),
|
|
66
|
+
afterRawContentState
|
|
67
|
+
)
|
|
68
|
+
})
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import test from 'ava'
|
|
2
|
+
import { convertToRaw } from 'draft-js'
|
|
3
|
+
import createEditorState from './fixtures/createEditorState'
|
|
4
|
+
|
|
5
|
+
import resetBlock from '../src/resetBlock'
|
|
6
|
+
|
|
7
|
+
const blocks = () => [
|
|
8
|
+
{
|
|
9
|
+
key: 'item1',
|
|
10
|
+
text: 'asdf',
|
|
11
|
+
type: 'header-one',
|
|
12
|
+
depth: 0,
|
|
13
|
+
inlineStyleRanges: [],
|
|
14
|
+
entityRanges: [],
|
|
15
|
+
data: {},
|
|
16
|
+
},
|
|
17
|
+
{
|
|
18
|
+
key: 'item2',
|
|
19
|
+
text: 'fdsa',
|
|
20
|
+
type: 'header-two',
|
|
21
|
+
depth: 0,
|
|
22
|
+
inlineStyleRanges: [],
|
|
23
|
+
entityRanges: [],
|
|
24
|
+
// TODO: test Entity
|
|
25
|
+
// entityRanges: [{
|
|
26
|
+
// key: 0,
|
|
27
|
+
// length: 2,
|
|
28
|
+
// offset: 2
|
|
29
|
+
// }],
|
|
30
|
+
data: {},
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
key: 'item3',
|
|
34
|
+
text: 'jkl;',
|
|
35
|
+
type: 'ordered-list-item',
|
|
36
|
+
depth: 1,
|
|
37
|
+
inlineStyleRanges: [{
|
|
38
|
+
length: 4,
|
|
39
|
+
offset: 0,
|
|
40
|
+
style: 'ITALIC',
|
|
41
|
+
}],
|
|
42
|
+
entityRanges: [],
|
|
43
|
+
data: { foo: 1 },
|
|
44
|
+
},
|
|
45
|
+
]
|
|
46
|
+
|
|
47
|
+
const reset = block => Object.assign({}, block, {
|
|
48
|
+
text: '',
|
|
49
|
+
type: 'unstyled',
|
|
50
|
+
depth: 0,
|
|
51
|
+
inlineStyleRanges: [],
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
blocks().forEach(({ key }, i) => {
|
|
55
|
+
const beforeRawContentState = {
|
|
56
|
+
entityMap: {},
|
|
57
|
+
blocks: blocks(),
|
|
58
|
+
}
|
|
59
|
+
const afterRawContentState = {
|
|
60
|
+
entityMap: {},
|
|
61
|
+
blocks: blocks().map(block => block.key === key ? reset(block) : block),
|
|
62
|
+
}
|
|
63
|
+
const editorState = createEditorState(
|
|
64
|
+
beforeRawContentState,
|
|
65
|
+
{
|
|
66
|
+
anchorKey: 'item1',
|
|
67
|
+
anchorOffset: 0,
|
|
68
|
+
focusKey: 'item1',
|
|
69
|
+
focusOffset: 0,
|
|
70
|
+
isBackward: false,
|
|
71
|
+
hasFocus: true,
|
|
72
|
+
}
|
|
73
|
+
)
|
|
74
|
+
|
|
75
|
+
test(`resetBlock ${i}`, t => {
|
|
76
|
+
const newEditorState = resetBlock(editorState, editorState.getCurrentContent().getBlockForKey(key))
|
|
77
|
+
t.not(newEditorState, editorState)
|
|
78
|
+
t.deepEqual(
|
|
79
|
+
convertToRaw(newEditorState.getCurrentContent()),
|
|
80
|
+
afterRawContentState
|
|
81
|
+
)
|
|
82
|
+
})
|
|
83
|
+
})
|