@@ -10,7 +10,7 @@ import Text from '../../../src/model/text';
10
10
import TextProxy from '../../../src/model/textproxy' ;
11
11
import Position from '../../../src/model/position' ;
12
12
import Range from '../../../src/model/range' ;
13
- import utils from '../../../src/model/operation/utils' ;
13
+ import * as utils from '../../../src/model/operation/utils' ;
14
14
import { getData } from '../../../src/dev-utils/model' ;
15
15
16
16
import CKEditorError from '@ckeditor/ckeditor5-utils/src/ckeditorerror' ;
@@ -38,19 +38,19 @@ describe( 'writer utils', () => {
38
38
39
39
describe ( 'insert' , ( ) => {
40
40
it ( 'should insert nodes between nodes' , ( ) => {
41
- utils . insert ( Position . createAt ( root , 3 ) , [ 'xxx' , new Element ( 'p' ) ] ) ;
41
+ utils . _insert ( Position . createAt ( root , 3 ) , [ 'xxx' , new Element ( 'p' ) ] ) ;
42
42
43
43
expectData ( 'fooxxx<p></p><$text bold="true">bar</$text><image src="img.jpg"></image>xyz' ) ;
44
44
} ) ;
45
45
46
46
it ( 'should split text node if nodes at inserted at offset inside text node' , ( ) => {
47
- utils . insert ( Position . createAt ( root , 5 ) , new Element ( 'p' ) ) ;
47
+ utils . _insert ( Position . createAt ( root , 5 ) , new Element ( 'p' ) ) ;
48
48
49
49
expectData ( 'foo<$text bold="true">ba</$text><p></p><$text bold="true">r</$text><image src="img.jpg"></image>xyz' ) ;
50
50
} ) ;
51
51
52
52
it ( 'should merge text nodes if possible' , ( ) => {
53
- utils . insert ( Position . createAt ( root , 3 ) , new Text ( 'xxx' , { bold : true } ) ) ;
53
+ utils . _insert ( Position . createAt ( root , 3 ) , new Text ( 'xxx' , { bold : true } ) ) ;
54
54
55
55
expectData ( 'foo<$text bold="true">xxxbar</$text><image src="img.jpg"></image>xyz' ) ;
56
56
} ) ;
@@ -59,73 +59,73 @@ describe( 'writer utils', () => {
59
59
describe ( 'remove' , ( ) => {
60
60
it ( 'should remove nodes in given range' , ( ) => {
61
61
const range = Range . createFromParentsAndOffsets ( root , 3 , root , 6 ) ;
62
- utils . remove ( range ) ;
62
+ utils . _remove ( range ) ;
63
63
64
64
expectData ( 'foo<image src="img.jpg"></image>xyz' ) ;
65
65
} ) ;
66
66
67
67
it ( 'should split text node if range starts or ends inside text node' , ( ) => {
68
68
const range = Range . createFromParentsAndOffsets ( root , 1 , root , 5 ) ;
69
- utils . remove ( range ) ;
69
+ utils . _remove ( range ) ;
70
70
71
71
expectData ( 'f<$text bold="true">r</$text><image src="img.jpg"></image>xyz' ) ;
72
72
} ) ;
73
73
74
74
it ( 'should merge text nodes if possible' , ( ) => {
75
75
const range = Range . createFromParentsAndOffsets ( root , 3 , root , 7 ) ;
76
- utils . remove ( range ) ;
76
+ utils . _remove ( range ) ;
77
77
78
78
expectData ( 'fooxyz' ) ;
79
79
expect ( root . childCount ) . to . equal ( 1 ) ;
80
80
} ) ;
81
81
82
82
it ( 'should throw if given range is not flat' , ( ) => {
83
83
expect ( ( ) => {
84
- utils . remove ( new Range ( new Position ( root , [ 0 ] ) , new Position ( root , [ 1 , 2 ] ) ) ) ;
84
+ utils . _remove ( new Range ( new Position ( root , [ 0 ] ) , new Position ( root , [ 1 , 2 ] ) ) ) ;
85
85
} ) . to . throw ( CKEditorError , / o p e r a t i o n - u t i l s - r e m o v e - r a n g e - n o t - f l a t / ) ;
86
86
} ) ;
87
87
} ) ;
88
88
89
89
describe ( 'move' , ( ) => {
90
90
it ( 'should move a range of nodes' , ( ) => {
91
91
const range = Range . createFromParentsAndOffsets ( root , 3 , root , 6 ) ;
92
- utils . move ( range , Position . createAt ( root , 0 ) ) ;
92
+ utils . _move ( range , Position . createAt ( root , 0 ) ) ;
93
93
94
94
expectData ( '<$text bold="true">bar</$text>foo<image src="img.jpg"></image>xyz' ) ;
95
95
} ) ;
96
96
97
97
it ( 'should correctly move if target position is in same element as moved range, but after range' , ( ) => {
98
98
const range = Range . createFromParentsAndOffsets ( root , 3 , root , 6 ) ;
99
- utils . move ( range , Position . createAt ( root , 10 ) ) ;
99
+ utils . _move ( range , Position . createAt ( root , 10 ) ) ;
100
100
101
101
expectData ( 'foo<image src="img.jpg"></image>xyz<$text bold="true">bar</$text>' ) ;
102
102
} ) ;
103
103
104
104
it ( 'should throw if given range is not flat' , ( ) => {
105
105
expect ( ( ) => {
106
- utils . move ( new Range ( new Position ( root , [ 0 ] ) , new Position ( root , [ 1 , 2 ] ) ) , null ) ;
106
+ utils . _move ( new Range ( new Position ( root , [ 0 ] ) , new Position ( root , [ 1 , 2 ] ) ) , null ) ;
107
107
} ) . to . throw ( CKEditorError , / o p e r a t i o n - u t i l s - m o v e - r a n g e - n o t - f l a t / ) ;
108
108
} ) ;
109
109
} ) ;
110
110
111
111
describe ( 'setAttribute' , ( ) => {
112
112
it ( 'should set attribute on given range of nodes' , ( ) => {
113
113
const range = Range . createFromParentsAndOffsets ( root , 6 , root , 8 ) ;
114
- utils . setAttribute ( range , 'newAttr' , true ) ;
114
+ utils . _setAttribute ( range , 'newAttr' , true ) ;
115
115
116
116
expectData ( 'foo<$text bold="true">bar</$text><image newAttr="true" src="img.jpg"></image><$text newAttr="true">x</$text>yz' ) ;
117
117
} ) ;
118
118
119
119
it ( 'should remove attribute if null was passed as a value' , ( ) => {
120
120
const range = Range . createFromParentsAndOffsets ( root , 6 , root , 7 ) ;
121
- utils . setAttribute ( range , 'src' , null ) ;
121
+ utils . _setAttribute ( range , 'src' , null ) ;
122
122
123
123
expectData ( 'foo<$text bold="true">bar</$text><image></image>xyz' ) ;
124
124
} ) ;
125
125
126
126
it ( 'should merge nodes if possible' , ( ) => {
127
127
const range = Range . createFromParentsAndOffsets ( root , 0 , root , 3 ) ;
128
- utils . setAttribute ( range , 'bold' , true ) ;
128
+ utils . _setAttribute ( range , 'bold' , true ) ;
129
129
130
130
expectData ( '<$text bold="true">foobar</$text><image src="img.jpg"></image>xyz' ) ;
131
131
} ) ;
@@ -136,11 +136,11 @@ describe( 'normalizeNodes', () => {
136
136
it ( 'should change single object into an array' , ( ) => {
137
137
const p = new Element ( 'p' ) ;
138
138
139
- expect ( utils . normalizeNodes ( p ) ) . to . deep . equal ( [ p ] ) ;
139
+ expect ( utils . _normalizeNodes ( p ) ) . to . deep . equal ( [ p ] ) ;
140
140
} ) ;
141
141
142
142
it ( 'should change strings to text nodes' , ( ) => {
143
- const text = utils . normalizeNodes ( 'abc' ) [ 0 ] ;
143
+ const text = utils . _normalizeNodes ( 'abc' ) [ 0 ] ;
144
144
145
145
expect ( text ) . to . be . instanceof ( Text ) ;
146
146
expect ( text . data ) . to . equal ( 'abc' ) ;
@@ -150,7 +150,7 @@ describe( 'normalizeNodes', () => {
150
150
const textNode = new Text ( 'abc' ) ;
151
151
const textProxy = new TextProxy ( textNode , 1 , 1 ) ;
152
152
153
- const text = utils . normalizeNodes ( textProxy ) [ 0 ] ;
153
+ const text = utils . _normalizeNodes ( textProxy ) [ 0 ] ;
154
154
155
155
expect ( text ) . to . be . instanceof ( Text ) ;
156
156
expect ( text . data ) . to . equal ( 'b' ) ;
@@ -159,19 +159,19 @@ describe( 'normalizeNodes', () => {
159
159
it ( 'should not change elements' , ( ) => {
160
160
const p = new Element ( 'p' ) ;
161
161
162
- expect ( utils . normalizeNodes ( p ) [ 0 ] ) . to . equal ( p ) ;
162
+ expect ( utils . _normalizeNodes ( p ) [ 0 ] ) . to . equal ( p ) ;
163
163
} ) ;
164
164
165
165
it ( 'should omit unrecognized objects' , ( ) => {
166
- expect ( utils . normalizeNodes ( 1 ) ) . to . deep . equal ( [ ] ) ;
166
+ expect ( utils . _normalizeNodes ( 1 ) ) . to . deep . equal ( [ ] ) ;
167
167
} ) ;
168
168
169
169
it ( 'should accept arrays' , ( ) => {
170
170
const text = new Text ( 'foo' , { bold : true } ) ;
171
171
const image = new Element ( 'image' ) ;
172
172
const nodes = [ 'abc' , text , image , 1 , 'xyz' ] ;
173
173
174
- const normalized = utils . normalizeNodes ( nodes ) ;
174
+ const normalized = utils . _normalizeNodes ( nodes ) ;
175
175
176
176
expect ( normalized [ 0 ] ) . to . be . instanceof ( Text ) ;
177
177
expect ( normalized [ 1 ] ) . to . equal ( text ) ;
@@ -180,7 +180,7 @@ describe( 'normalizeNodes', () => {
180
180
} ) ;
181
181
182
182
it ( 'should merge text nodes if mergeTextNodes flag is set to true' , ( ) => {
183
- const normalized = utils . normalizeNodes ( [ 'foo' , 'bar' ] , true ) ;
183
+ const normalized = utils . _normalizeNodes ( [ 'foo' , 'bar' ] , true ) ;
184
184
185
185
expect ( normalized . length ) . to . equal ( 1 ) ;
186
186
expect ( normalized [ 0 ] . data ) . to . equal ( 'foobar' ) ;
@@ -193,7 +193,7 @@ describe( 'normalizeNodes', () => {
193
193
'xyz'
194
194
] ;
195
195
196
- const normalized = utils . normalizeNodes ( nodes , true ) ;
196
+ const normalized = utils . _normalizeNodes ( nodes , true ) ;
197
197
198
198
expect ( normalized [ 0 ] ) . to . be . instanceof ( Text ) ;
199
199
expect ( normalized [ 0 ] . getAttribute ( 'bold' ) ) . to . be . true ;
0 commit comments