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