@ckeditor/ckeditor5-code-block 0.0.0-nightly-20241215.0 → 0.0.0-nightly-20241217.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 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
- * Contains the last used language.
285
- */ _lastLanguage;
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
- * @inheritDoc
294
- */ refresh() {
290
+ * @inheritDoc
291
+ */ refresh() {
295
292
  this.value = this._getValue();
296
293
  this.isEnabled = this._checkEnabled();
297
294
  }
298
295
  /**
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 = {}) {
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
- * Checks the command's {@link #value}.
329
- *
330
- * @returns The current value.
331
- */ _getValue() {
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
- * Checks whether the command can be enabled in the current context.
339
- *
340
- * @returns Whether the command should be enabled.
341
- */ _checkEnabled() {
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
- * @inheritDoc
419
- */ refresh() {
412
+ * @inheritDoc
413
+ */ refresh() {
420
414
  this.isEnabled = this._checkEnabled();
421
415
  }
422
416
  /**
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() {
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
- * Checks whether the command can be enabled in the current context.
466
- */ _checkEnabled() {
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
- * @inheritDoc
488
- */ refresh() {
478
+ * @inheritDoc
479
+ */ refresh() {
489
480
  this.isEnabled = this._checkEnabled();
490
481
  }
491
482
  /**
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() {
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
- * 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() {
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
- * @inheritDoc
889
- */ static get pluginName() {
879
+ * @inheritDoc
880
+ */ static get pluginName() {
890
881
  return 'CodeBlockEditing';
891
882
  }
892
883
  /**
893
- * @inheritDoc
894
- */ static get isOfficialPlugin() {
884
+ * @inheritDoc
885
+ */ static get isOfficialPlugin() {
895
886
  return true;
896
887
  }
897
888
  /**
898
- * @inheritDoc
899
- */ static get requires() {
889
+ * @inheritDoc
890
+ */ static get requires() {
900
891
  return [
901
892
  ShiftEnter
902
893
  ];
903
894
  }
904
895
  /**
905
- * @inheritDoc
906
- */ constructor(editor){
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
- * @inheritDoc
973
- */ init() {
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
- * @inheritDoc
1099
- */ afterInit() {
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
- * 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() {
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
- * @inheritDoc
1317
- */ static get pluginName() {
1307
+ * @inheritDoc
1308
+ */ static get pluginName() {
1318
1309
  return 'CodeBlockUI';
1319
1310
  }
1320
1311
  /**
1321
- * @inheritDoc
1322
- */ static get isOfficialPlugin() {
1312
+ * @inheritDoc
1313
+ */ static get isOfficialPlugin() {
1323
1314
  return true;
1324
1315
  }
1325
1316
  /**
1326
- * @inheritDoc
1327
- */ init() {
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
- * A helper returning a collection of the `codeBlock` dropdown items representing languages
1403
- * available for the user to choose from.
1404
- */ _getLanguageListItemDefinitions(normalizedLanguageDefs) {
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
- * @inheritDoc
1438
- */ static get requires() {
1428
+ * @inheritDoc
1429
+ */ static get requires() {
1439
1430
  return [
1440
1431
  CodeBlockEditing,
1441
1432
  CodeBlockUI
1442
1433
  ];
1443
1434
  }
1444
1435
  /**
1445
- * @inheritDoc
1446
- */ static get pluginName() {
1436
+ * @inheritDoc
1437
+ */ static get pluginName() {
1447
1438
  return 'CodeBlock';
1448
1439
  }
1449
1440
  /**
1450
- * @inheritDoc
1451
- */ static get isOfficialPlugin() {
1441
+ * @inheritDoc
1442
+ */ static get isOfficialPlugin() {
1452
1443
  return true;
1453
1444
  }
1454
1445
  }