@ckeditor/ckeditor5-code-block 0.0.0-nightly-20241218.0 → 0.0.0-nightly-20241219.1
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/dist/index.js +86 -77
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -281,30 +281,33 @@ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, Me
|
|
|
281
281
|
* The code block command plugin.
|
|
282
282
|
*/ class CodeBlockCommand extends Command {
|
|
283
283
|
/**
|
|
284
|
-
|
|
285
|
-
|
|
284
|
+
* Contains the last used language.
|
|
285
|
+
*/ _lastLanguage;
|
|
286
|
+
/**
|
|
287
|
+
* @inheritDoc
|
|
288
|
+
*/ constructor(editor){
|
|
286
289
|
super(editor);
|
|
287
290
|
this._lastLanguage = null;
|
|
288
291
|
}
|
|
289
292
|
/**
|
|
290
|
-
|
|
291
|
-
|
|
293
|
+
* @inheritDoc
|
|
294
|
+
*/ refresh() {
|
|
292
295
|
this.value = this._getValue();
|
|
293
296
|
this.isEnabled = this._checkEnabled();
|
|
294
297
|
}
|
|
295
298
|
/**
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
299
|
+
* Executes the command. When the command {@link #value is on}, all topmost code blocks within
|
|
300
|
+
* the selection will be removed. If it is off, all selected blocks will be flattened and
|
|
301
|
+
* wrapped by a code block.
|
|
302
|
+
*
|
|
303
|
+
* @fires execute
|
|
304
|
+
* @param options Command options.
|
|
305
|
+
* @param options.language The code block language.
|
|
306
|
+
* @param options.forceValue If set, it will force the command behavior. If `true`, the command will apply a code block,
|
|
307
|
+
* otherwise the command will remove the code block. If not set, the command will act basing on its current value.
|
|
308
|
+
* @param options.usePreviousLanguageChoice If set on `true` and the `options.language` is not specified, the command
|
|
309
|
+
* will apply the previous language (if the command was already executed) when inserting the `codeBlock` element.
|
|
310
|
+
*/ execute(options = {}) {
|
|
308
311
|
const editor = this.editor;
|
|
309
312
|
const model = editor.model;
|
|
310
313
|
const selection = model.document.selection;
|
|
@@ -322,20 +325,20 @@ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, Me
|
|
|
322
325
|
});
|
|
323
326
|
}
|
|
324
327
|
/**
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
328
|
+
* Checks the command's {@link #value}.
|
|
329
|
+
*
|
|
330
|
+
* @returns The current value.
|
|
331
|
+
*/ _getValue() {
|
|
329
332
|
const selection = this.editor.model.document.selection;
|
|
330
333
|
const firstBlock = first(selection.getSelectedBlocks());
|
|
331
334
|
const isCodeBlock = !!(firstBlock && firstBlock.is('element', 'codeBlock'));
|
|
332
335
|
return isCodeBlock ? firstBlock.getAttribute('language') : false;
|
|
333
336
|
}
|
|
334
337
|
/**
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
338
|
+
* Checks whether the command can be enabled in the current context.
|
|
339
|
+
*
|
|
340
|
+
* @returns Whether the command should be enabled.
|
|
341
|
+
*/ _checkEnabled() {
|
|
339
342
|
if (this.value) {
|
|
340
343
|
return true;
|
|
341
344
|
}
|
|
@@ -404,21 +407,24 @@ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, Me
|
|
|
404
407
|
/**
|
|
405
408
|
* The code block indentation increase command plugin.
|
|
406
409
|
*/ class IndentCodeBlockCommand extends Command {
|
|
410
|
+
/**
|
|
411
|
+
* A sequence of characters added to the line when the command is executed.
|
|
412
|
+
*/ _indentSequence;
|
|
407
413
|
constructor(editor){
|
|
408
414
|
super(editor);
|
|
409
415
|
this._indentSequence = editor.config.get('codeBlock.indentSequence');
|
|
410
416
|
}
|
|
411
417
|
/**
|
|
412
|
-
|
|
413
|
-
|
|
418
|
+
* @inheritDoc
|
|
419
|
+
*/ refresh() {
|
|
414
420
|
this.isEnabled = this._checkEnabled();
|
|
415
421
|
}
|
|
416
422
|
/**
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
423
|
+
* Executes the command. When the command {@link #isEnabled is enabled}, the indentation of the
|
|
424
|
+
* code lines in the selection will be increased.
|
|
425
|
+
*
|
|
426
|
+
* @fires execute
|
|
427
|
+
*/ execute() {
|
|
422
428
|
const editor = this.editor;
|
|
423
429
|
const model = editor.model;
|
|
424
430
|
model.change((writer)=>{
|
|
@@ -456,8 +462,8 @@ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, Me
|
|
|
456
462
|
});
|
|
457
463
|
}
|
|
458
464
|
/**
|
|
459
|
-
|
|
460
|
-
|
|
465
|
+
* Checks whether the command can be enabled in the current context.
|
|
466
|
+
*/ _checkEnabled() {
|
|
461
467
|
if (!this._indentSequence) {
|
|
462
468
|
return false;
|
|
463
469
|
}
|
|
@@ -470,21 +476,24 @@ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, Me
|
|
|
470
476
|
/**
|
|
471
477
|
* The code block indentation decrease command plugin.
|
|
472
478
|
*/ class OutdentCodeBlockCommand extends Command {
|
|
479
|
+
/**
|
|
480
|
+
* A sequence of characters removed from the line when the command is executed.
|
|
481
|
+
*/ _indentSequence;
|
|
473
482
|
constructor(editor){
|
|
474
483
|
super(editor);
|
|
475
484
|
this._indentSequence = editor.config.get('codeBlock.indentSequence');
|
|
476
485
|
}
|
|
477
486
|
/**
|
|
478
|
-
|
|
479
|
-
|
|
487
|
+
* @inheritDoc
|
|
488
|
+
*/ refresh() {
|
|
480
489
|
this.isEnabled = this._checkEnabled();
|
|
481
490
|
}
|
|
482
491
|
/**
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
492
|
+
* Executes the command. When the command {@link #isEnabled is enabled}, the indentation of the
|
|
493
|
+
* code lines in the selection will be decreased.
|
|
494
|
+
*
|
|
495
|
+
* @fires execute
|
|
496
|
+
*/ execute() {
|
|
488
497
|
const editor = this.editor;
|
|
489
498
|
const model = editor.model;
|
|
490
499
|
model.change(()=>{
|
|
@@ -523,11 +532,11 @@ import { createDropdown, SplitButtonView, addListToDropdown, MenuBarMenuView, Me
|
|
|
523
532
|
});
|
|
524
533
|
}
|
|
525
534
|
/**
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
535
|
+
* Checks whether the command can be enabled in the current context.
|
|
536
|
+
*
|
|
537
|
+
* @private
|
|
538
|
+
* @returns {Boolean} Whether the command should be enabled.
|
|
539
|
+
*/ _checkEnabled() {
|
|
531
540
|
if (!this._indentSequence) {
|
|
532
541
|
return false;
|
|
533
542
|
}
|
|
@@ -876,25 +885,25 @@ const DEFAULT_ELEMENT = 'paragraph';
|
|
|
876
885
|
* Introduces the `'codeBlock'` command and the `'codeBlock'` model element.
|
|
877
886
|
*/ class CodeBlockEditing extends Plugin {
|
|
878
887
|
/**
|
|
879
|
-
|
|
880
|
-
|
|
888
|
+
* @inheritDoc
|
|
889
|
+
*/ static get pluginName() {
|
|
881
890
|
return 'CodeBlockEditing';
|
|
882
891
|
}
|
|
883
892
|
/**
|
|
884
|
-
|
|
885
|
-
|
|
893
|
+
* @inheritDoc
|
|
894
|
+
*/ static get isOfficialPlugin() {
|
|
886
895
|
return true;
|
|
887
896
|
}
|
|
888
897
|
/**
|
|
889
|
-
|
|
890
|
-
|
|
898
|
+
* @inheritDoc
|
|
899
|
+
*/ static get requires() {
|
|
891
900
|
return [
|
|
892
901
|
ShiftEnter
|
|
893
902
|
];
|
|
894
903
|
}
|
|
895
904
|
/**
|
|
896
|
-
|
|
897
|
-
|
|
905
|
+
* @inheritDoc
|
|
906
|
+
*/ constructor(editor){
|
|
898
907
|
super(editor);
|
|
899
908
|
editor.config.define('codeBlock', {
|
|
900
909
|
languages: [
|
|
@@ -960,8 +969,8 @@ const DEFAULT_ELEMENT = 'paragraph';
|
|
|
960
969
|
});
|
|
961
970
|
}
|
|
962
971
|
/**
|
|
963
|
-
|
|
964
|
-
|
|
972
|
+
* @inheritDoc
|
|
973
|
+
*/ init() {
|
|
965
974
|
const editor = this.editor;
|
|
966
975
|
const schema = editor.model.schema;
|
|
967
976
|
const model = editor.model;
|
|
@@ -1086,8 +1095,8 @@ const DEFAULT_ELEMENT = 'paragraph';
|
|
|
1086
1095
|
});
|
|
1087
1096
|
}
|
|
1088
1097
|
/**
|
|
1089
|
-
|
|
1090
|
-
|
|
1098
|
+
* @inheritDoc
|
|
1099
|
+
*/ afterInit() {
|
|
1091
1100
|
const editor = this.editor;
|
|
1092
1101
|
const commands = editor.commands;
|
|
1093
1102
|
const indent = commands.get('indent');
|
|
@@ -1124,11 +1133,11 @@ const DEFAULT_ELEMENT = 'paragraph';
|
|
|
1124
1133
|
this._initAriaAnnouncements();
|
|
1125
1134
|
}
|
|
1126
1135
|
/**
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1136
|
+
* Observe when user enters or leaves code block and set proper aria value in global live announcer.
|
|
1137
|
+
* This allows screen readers to indicate when the user has entered and left the specified code block.
|
|
1138
|
+
*
|
|
1139
|
+
* @internal
|
|
1140
|
+
*/ _initAriaAnnouncements() {
|
|
1132
1141
|
const { model, ui, t } = this.editor;
|
|
1133
1142
|
const languageDefs = getNormalizedAndLocalizedLanguageDefinitions(this.editor);
|
|
1134
1143
|
let lastFocusedCodeBlock = null;
|
|
@@ -1304,18 +1313,18 @@ function isSoftBreakNode(node) {
|
|
|
1304
1313
|
* Introduces the `'codeBlock'` dropdown.
|
|
1305
1314
|
*/ class CodeBlockUI extends Plugin {
|
|
1306
1315
|
/**
|
|
1307
|
-
|
|
1308
|
-
|
|
1316
|
+
* @inheritDoc
|
|
1317
|
+
*/ static get pluginName() {
|
|
1309
1318
|
return 'CodeBlockUI';
|
|
1310
1319
|
}
|
|
1311
1320
|
/**
|
|
1312
|
-
|
|
1313
|
-
|
|
1321
|
+
* @inheritDoc
|
|
1322
|
+
*/ static get isOfficialPlugin() {
|
|
1314
1323
|
return true;
|
|
1315
1324
|
}
|
|
1316
1325
|
/**
|
|
1317
|
-
|
|
1318
|
-
|
|
1326
|
+
* @inheritDoc
|
|
1327
|
+
*/ init() {
|
|
1319
1328
|
const editor = this.editor;
|
|
1320
1329
|
const t = editor.t;
|
|
1321
1330
|
const componentFactory = editor.ui.componentFactory;
|
|
@@ -1390,9 +1399,9 @@ function isSoftBreakNode(node) {
|
|
|
1390
1399
|
});
|
|
1391
1400
|
}
|
|
1392
1401
|
/**
|
|
1393
|
-
|
|
1394
|
-
|
|
1395
|
-
|
|
1402
|
+
* A helper returning a collection of the `codeBlock` dropdown items representing languages
|
|
1403
|
+
* available for the user to choose from.
|
|
1404
|
+
*/ _getLanguageListItemDefinitions(normalizedLanguageDefs) {
|
|
1396
1405
|
const editor = this.editor;
|
|
1397
1406
|
const command = editor.commands.get('codeBlock');
|
|
1398
1407
|
const itemDefinitions = new Collection();
|
|
@@ -1425,21 +1434,21 @@ function isSoftBreakNode(node) {
|
|
|
1425
1434
|
* and the {@link module:code-block/codeblockui~CodeBlockUI code block UI feature}.
|
|
1426
1435
|
*/ class CodeBlock extends Plugin {
|
|
1427
1436
|
/**
|
|
1428
|
-
|
|
1429
|
-
|
|
1437
|
+
* @inheritDoc
|
|
1438
|
+
*/ static get requires() {
|
|
1430
1439
|
return [
|
|
1431
1440
|
CodeBlockEditing,
|
|
1432
1441
|
CodeBlockUI
|
|
1433
1442
|
];
|
|
1434
1443
|
}
|
|
1435
1444
|
/**
|
|
1436
|
-
|
|
1437
|
-
|
|
1445
|
+
* @inheritDoc
|
|
1446
|
+
*/ static get pluginName() {
|
|
1438
1447
|
return 'CodeBlock';
|
|
1439
1448
|
}
|
|
1440
1449
|
/**
|
|
1441
|
-
|
|
1442
|
-
|
|
1450
|
+
* @inheritDoc
|
|
1451
|
+
*/ static get isOfficialPlugin() {
|
|
1443
1452
|
return true;
|
|
1444
1453
|
}
|
|
1445
1454
|
}
|