|
1 | 1 | import {builders} from 'prosemirror-test-builder'; |
| 2 | +import dd from 'ts-dedent'; |
| 3 | + |
| 4 | +import {ExtensionsManager} from '#core'; |
| 5 | +import {BaseNode, BaseSchemaSpecs} from 'src/extensions/base/specs'; |
| 6 | +import {BoldSpecs, BreakNodeName, BreaksSpecs, boldMarkName} from 'src/extensions/markdown/specs'; |
2 | 7 |
|
3 | 8 | import {parseDOM} from '../../../../tests/parse-dom'; |
4 | 9 | import {createMarkupChecker} from '../../../../tests/sameMarkup'; |
5 | | -import {ExtensionsManager} from '../../../core'; |
6 | | -import {BaseNode, BaseSchemaSpecs} from '../../base/specs'; |
7 | | -import {BoldSpecs, boldMarkName} from '../../markdown/specs'; |
8 | 10 |
|
9 | 11 | import {CheckboxAttr, CheckboxNode, CheckboxSpecs} from './CheckboxSpecs'; |
10 | 12 | import {fixPastePlugin} from './plugins/fix-paste'; |
@@ -192,4 +194,99 @@ describe('Checkbox extension', () => { |
192 | 194 | [fixPastePlugin()], |
193 | 195 | ); |
194 | 196 | }); |
| 197 | + |
| 198 | + describe('allow multiline', () => { |
| 199 | + const { |
| 200 | + schema, |
| 201 | + markupParser: parser, |
| 202 | + serializer, |
| 203 | + } = new ExtensionsManager({ |
| 204 | + extensions: (builder) => |
| 205 | + builder.use(BaseSchemaSpecs, {}).use(BreaksSpecs, {}).use(CheckboxSpecs, { |
| 206 | + multiline: true, |
| 207 | + checkboxLabelPlaceholder: 'checklist', |
| 208 | + }), |
| 209 | + }).buildDeps(); |
| 210 | + |
| 211 | + const {doc, p, soft, chBox, chInput, chLabel} = builders< |
| 212 | + 'doc' | 'p' | 'soft' | 'chBox' | 'chInput' | 'chLabel' |
| 213 | + >(schema, { |
| 214 | + doc: {nodeType: BaseNode.Doc}, |
| 215 | + p: {nodeType: BaseNode.Paragraph}, |
| 216 | + soft: {nodeType: BreakNodeName.SoftBreak}, |
| 217 | + chBox: {nodeType: CheckboxNode.Checkbox}, |
| 218 | + chInput: {nodeType: CheckboxNode.Input}, |
| 219 | + chLabel: {nodeType: CheckboxNode.Label}, |
| 220 | + }); |
| 221 | + |
| 222 | + const checker = createMarkupChecker({parser, serializer}); |
| 223 | + |
| 224 | + it('should parse multiline checkbox', () => { |
| 225 | + checker.same( |
| 226 | + dd` |
| 227 | + [ ] long |
| 228 | + long |
| 229 | + checkbox |
| 230 | + `, |
| 231 | + doc( |
| 232 | + chBox( |
| 233 | + chInput({[CheckboxAttr.Id]: 'yfm-editor-checkbox0'}), |
| 234 | + chLabel( |
| 235 | + {[CheckboxAttr.For]: 'yfm-editor-checkbox0'}, |
| 236 | + 'long', |
| 237 | + soft(), |
| 238 | + 'long', |
| 239 | + soft(), |
| 240 | + 'checkbox', |
| 241 | + ), |
| 242 | + ), |
| 243 | + ), |
| 244 | + ); |
| 245 | + }); |
| 246 | + |
| 247 | + it('should remember tight checkboxes', () => { |
| 248 | + checker.same( |
| 249 | + dd` |
| 250 | + [ ] one |
| 251 | + [ ] two |
| 252 | +
|
| 253 | + [X] three |
| 254 | + 3 |
| 255 | + [X] four |
| 256 | + 4 |
| 257 | +
|
| 258 | + five |
| 259 | + `, |
| 260 | + doc( |
| 261 | + chBox( |
| 262 | + {[CheckboxAttr.Tight]: true}, |
| 263 | + chInput({[CheckboxAttr.Id]: 'yfm-editor-checkbox1'}), |
| 264 | + chLabel({[CheckboxAttr.For]: 'yfm-editor-checkbox1'}, 'one'), |
| 265 | + ), |
| 266 | + chBox( |
| 267 | + {[CheckboxAttr.Tight]: false}, |
| 268 | + chInput({[CheckboxAttr.Id]: 'yfm-editor-checkbox2'}), |
| 269 | + chLabel({[CheckboxAttr.For]: 'yfm-editor-checkbox2'}, 'two'), |
| 270 | + ), |
| 271 | + chBox( |
| 272 | + {[CheckboxAttr.Tight]: true}, |
| 273 | + chInput({ |
| 274 | + [CheckboxAttr.Checked]: 'true', |
| 275 | + [CheckboxAttr.Id]: 'yfm-editor-checkbox3', |
| 276 | + }), |
| 277 | + chLabel({[CheckboxAttr.For]: 'yfm-editor-checkbox3'}, 'three', soft(), '3'), |
| 278 | + ), |
| 279 | + chBox( |
| 280 | + {[CheckboxAttr.Tight]: null}, |
| 281 | + chInput({ |
| 282 | + [CheckboxAttr.Checked]: 'true', |
| 283 | + [CheckboxAttr.Id]: 'yfm-editor-checkbox4', |
| 284 | + }), |
| 285 | + chLabel({[CheckboxAttr.For]: 'yfm-editor-checkbox4'}, 'four', soft(), '4'), |
| 286 | + ), |
| 287 | + p('five'), |
| 288 | + ), |
| 289 | + ); |
| 290 | + }); |
| 291 | + }); |
195 | 292 | }); |
0 commit comments