1
1
import { Model } from '../../../json-crdt/model' ;
2
2
import { Peritext } from '../Peritext' ;
3
- import type { Editor } from '../editor/Editor' ;
4
3
import { render } from './render' ;
4
+ import type { Editor } from '../editor/Editor' ;
5
5
6
6
const runInlineSlicesTests = (
7
7
desc : string ,
@@ -30,7 +30,7 @@ const runInlineSlicesTests = (
30
30
test ( 'can insert marker in the middle of text' , ( ) => {
31
31
const { view, editor} = setup ( ) ;
32
32
editor . cursor . setAt ( 10 ) ;
33
- editor . saved . insMarker ( [ 'p' ] , { foo : 'bar' } ) ;
33
+ editor . saved . insMarker ( [ [ 'p' , 0 , { foo : 'bar' } ] ] ) ;
34
34
expect ( view ( ) ) . toMatchInlineSnapshot ( `
35
35
"<>
36
36
<0>
@@ -44,7 +44,7 @@ const runInlineSlicesTests = (
44
44
test ( 'can insert at the beginning of text' , ( ) => {
45
45
const { view, editor} = setup ( ) ;
46
46
editor . cursor . setAt ( 0 ) ;
47
- editor . saved . insMarker ( [ 'p' ] , { foo : 'bar' } ) ;
47
+ editor . saved . insMarker ( [ [ 'p' , 0 , { foo : 'bar' } ] ] ) ;
48
48
expect ( view ( ) ) . toMatchInlineSnapshot ( `
49
49
"<>
50
50
<p> { foo = "bar" }
@@ -53,10 +53,61 @@ const runInlineSlicesTests = (
53
53
` ) ;
54
54
} ) ;
55
55
56
+ test ( 'nested block data' , ( ) => {
57
+ const { view, editor} = setup ( ) ;
58
+ editor . cursor . setAt ( 5 ) ;
59
+ editor . saved . insMarker ( [
60
+ [ 'ul' , 0 , { type : 'tasks' } ] ,
61
+ [ 'li' , 0 , { completed : false } ] ,
62
+ ] ) ;
63
+ editor . cursor . setAt ( 10 ) ;
64
+ editor . saved . insMarker ( [
65
+ [ 'ul' , 0 , { type : 'tasks' } ] ,
66
+ [ 'li' , 1 , { completed : true } ] ,
67
+ ] ) ;
68
+ expect ( view ( ) ) . toMatchInlineSnapshot ( `
69
+ "<>
70
+ <0>
71
+ "abcde" { }
72
+ <ul> { type = "tasks" }
73
+ <li> { completed = !f }
74
+ "fghi" { }
75
+ <li> { completed = !t }
76
+ "jklmnopqrstuvwxyz" { }
77
+ "
78
+ ` ) ;
79
+ } ) ;
80
+
81
+ test ( 'nested block data - 2' , ( ) => {
82
+ const { view, editor} = setup ( ) ;
83
+ editor . cursor . setAt ( 5 ) ;
84
+ editor . saved . insMarker ( [
85
+ [ 'ul' , 0 , { type : 'tasks' } ] ,
86
+ [ 'li' , 0 , { completed : false } ] ,
87
+ ] ) ;
88
+ editor . cursor . setAt ( 10 ) ;
89
+ editor . saved . insMarker ( [
90
+ [ 'ul' , 1 , { type : 'tasks' } ] ,
91
+ [ 'li' , 0 , { completed : true } ] ,
92
+ ] ) ;
93
+ expect ( view ( ) ) . toMatchInlineSnapshot ( `
94
+ "<>
95
+ <0>
96
+ "abcde" { }
97
+ <ul> { type = "tasks" }
98
+ <li> { completed = !f }
99
+ "fghi" { }
100
+ <ul> { type = "tasks" }
101
+ <li> { completed = !t }
102
+ "jklmnopqrstuvwxyz" { }
103
+ "
104
+ ` ) ;
105
+ } ) ;
106
+
56
107
test ( 'can insert at the end of text' , ( ) => {
57
108
const { view, editor} = setup ( ) ;
58
109
editor . cursor . setAt ( 26 ) ;
59
- editor . saved . insMarker ( [ 'unfurl' ] , { link : 'foobar' } ) ;
110
+ editor . saved . insMarker ( [ [ 'unfurl' , 0 , { link : 'foobar' } ] ] ) ;
60
111
expect ( view ( ) ) . toMatchInlineSnapshot ( `
61
112
"<>
62
113
<0>
@@ -71,14 +122,14 @@ const runInlineSlicesTests = (
71
122
editor . cursor . setAt ( 5 , 5 ) ;
72
123
editor . saved . insOne ( 'BOLD' ) ;
73
124
editor . cursor . setAt ( 15 ) ;
74
- editor . saved . insMarker ( [ 'paragraph' ] , [ ] ) ;
125
+ editor . saved . insMarker ( [ 'paragraph' ] ) ;
75
126
expect ( view ( ) ) . toMatchInlineSnapshot ( `
76
127
"<>
77
128
<0>
78
129
"abcde" { }
79
130
"fghij" { BOLD = [ !u ] }
80
131
"klmno" { }
81
- <paragraph> [ ]
132
+ <paragraph>
82
133
"pqrstuvwxyz" { }
83
134
"
84
135
` ) ;
@@ -89,14 +140,14 @@ const runInlineSlicesTests = (
89
140
editor . cursor . setAt ( 5 , 5 ) ;
90
141
editor . saved . insOne ( 'BOLD' ) ;
91
142
editor . cursor . setAt ( 10 ) ;
92
- editor . saved . insMarker ( [ 'paragraph' ] , [ ] ) ;
143
+ editor . saved . insMarker ( [ 'paragraph' ] ) ;
93
144
expect ( view ( ) ) . toMatchInlineSnapshot ( `
94
145
"<>
95
146
<0>
96
147
"abcde" { }
97
148
"fghij" { BOLD = [ !u ] }
98
149
"" { }
99
- <paragraph> [ ]
150
+ <paragraph>
100
151
"klmnopqrstuvwxyz" { }
101
152
"
102
153
` ) ;
@@ -107,12 +158,12 @@ const runInlineSlicesTests = (
107
158
editor . cursor . setAt ( 15 , 5 ) ;
108
159
editor . saved . insOne ( 'BOLD' ) ;
109
160
editor . cursor . setAt ( 10 ) ;
110
- editor . saved . insMarker ( [ 'paragraph' ] , [ ] ) ;
161
+ editor . saved . insMarker ( [ 'paragraph' ] ) ;
111
162
expect ( view ( ) ) . toMatchInlineSnapshot ( `
112
163
"<>
113
164
<0>
114
165
"abcdefghij" { }
115
- <paragraph> [ ]
166
+ <paragraph>
116
167
"klmno" { }
117
168
"pqrst" { BOLD = [ !u ] }
118
169
"uvwxyz" { }
@@ -125,12 +176,12 @@ const runInlineSlicesTests = (
125
176
editor . cursor . setAt ( 15 , 5 ) ;
126
177
editor . saved . insOne ( 'BOLD' ) ;
127
178
editor . cursor . setAt ( 15 ) ;
128
- editor . saved . insMarker ( [ 'paragraph' ] , [ ] ) ;
179
+ editor . saved . insMarker ( [ 'paragraph' ] ) ;
129
180
expect ( view ( ) ) . toMatchInlineSnapshot ( `
130
181
"<>
131
182
<0>
132
183
"abcdefghijklmno" { }
133
- <paragraph> [ ]
184
+ <paragraph>
134
185
"pqrst" { BOLD = [ !u ] }
135
186
"uvwxyz" { }
136
187
"
@@ -142,13 +193,13 @@ const runInlineSlicesTests = (
142
193
editor . cursor . setAt ( 5 , 10 ) ;
143
194
editor . saved . insOne ( 'BOLD' ) ;
144
195
editor . cursor . setAt ( 10 ) ;
145
- editor . saved . insMarker ( [ 'paragraph' ] , [ ] ) ;
196
+ editor . saved . insMarker ( [ 'paragraph' ] ) ;
146
197
expect ( view ( ) ) . toMatchInlineSnapshot ( `
147
198
"<>
148
199
<0>
149
200
"abcde" { }
150
201
"fghij" { BOLD = [ !u ] }
151
- <paragraph> [ ]
202
+ <paragraph>
152
203
"klmno" { BOLD = [ !u ] }
153
204
"pqrstuvwxyz" { }
154
205
"
@@ -158,19 +209,19 @@ const runInlineSlicesTests = (
158
209
test ( 'can annotate with slice over two block splits' , ( ) => {
159
210
const { view, editor} = setup ( ) ;
160
211
editor . cursor . setAt ( 10 ) ;
161
- editor . saved . insMarker ( [ 'p' ] , [ ] ) ;
212
+ editor . saved . insMarker ( [ 'p' ] ) ;
162
213
editor . cursor . setAt ( 15 ) ;
163
- editor . saved . insMarker ( [ 'p' ] , [ ] ) ;
214
+ editor . saved . insMarker ( [ 'p' ] ) ;
164
215
editor . cursor . setAt ( 8 , 15 ) ;
165
216
editor . saved . insOne ( 'BOLD' ) ;
166
217
expect ( view ( ) ) . toMatchInlineSnapshot ( `
167
218
"<>
168
219
<0>
169
220
"abcdefgh" { }
170
221
"ij" { BOLD = [ !u ] }
171
- <p> [ ]
222
+ <p>
172
223
"klmn" { BOLD = [ !u ] }
173
- <p> [ ]
224
+ <p>
174
225
"opqrstu" { BOLD = [ !u ] }
175
226
"vwxyz" { }
176
227
"
@@ -180,16 +231,16 @@ const runInlineSlicesTests = (
180
231
test ( 'can insert two blocks' , ( ) => {
181
232
const { view, editor} = setup ( ) ;
182
233
editor . cursor . setAt ( 10 ) ;
183
- editor . saved . insMarker ( 'p' , { } ) ;
234
+ editor . saved . insMarker ( 'p' ) ;
184
235
editor . cursor . setAt ( 10 + 10 + 1 ) ;
185
- editor . saved . insMarker ( 'p' , { } ) ;
236
+ editor . saved . insMarker ( 'p' ) ;
186
237
expect ( view ( ) ) . toMatchInlineSnapshot ( `
187
238
"<>
188
239
<0>
189
240
"abcdefghij" { }
190
- <p> { }
241
+ <p>
191
242
"klmnopqrst" { }
192
- <p> { }
243
+ <p>
193
244
"uvwxyz" { }
194
245
"
195
246
` ) ;
0 commit comments