@ckeditor/ckeditor5-core 46.1.1 → 47.0.0-alpha.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 CHANGED
@@ -2,7 +2,7 @@
2
2
  * @license Copyright (c) 2003-2025, CKSource Holding sp. z o.o. All rights reserved.
3
3
  * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-licensing-options
4
4
  */
5
- import { ObservableMixin, insertToPriorityArray, CKEditorError, EmitterMixin, Config, Locale, Collection, KeystrokeHandler, env, global, uid, parseBase64EncodedObject, toArray, crc32, releaseDate, logError, setDataInElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
5
+ import { ObservableMixin, insertToPriorityArray, CKEditorError, EmitterMixin, Config, Locale, Collection, KeystrokeHandler, env, global, uid, decodeLicenseKey, toArray, crc32, releaseDate, logError, isFeatureBlockedByLicenseKey, setDataInElement } from '@ckeditor/ckeditor5-utils/dist/index.js';
6
6
  import { get, set, isFunction } from 'es-toolkit/compat';
7
7
  import { Model, StylesProcessor, DataController, EditingController, Conversion } from '@ckeditor/ckeditor5-engine/dist/index.js';
8
8
  import { EditorWatchdog, ContextWatchdog } from '@ckeditor/ckeditor5-watchdog/dist/index.js';
@@ -2063,16 +2063,9 @@ function getPageSessionID() {
2063
2063
  function verifyLicenseKey(editor) {
2064
2064
  const licenseKey = editor.config.get('licenseKey');
2065
2065
  const distributionChannel = window[Symbol.for('cke distribution')] || 'sh';
2066
- function blockEditor(reason) {
2066
+ function blockEditor(reason, name) {
2067
2067
  editor.enableReadOnlyMode(Symbol('invalidLicense'));
2068
- editor._showLicenseError(reason);
2069
- }
2070
- function getPayload(licenseKey) {
2071
- const parts = licenseKey.split('.');
2072
- if (parts.length != 3) {
2073
- return null;
2074
- }
2075
- return parts[1];
2068
+ editor._showLicenseError(reason, name);
2076
2069
  }
2077
2070
  function hasAllRequiredFields(licensePayload) {
2078
2071
  const requiredFields = [
@@ -2112,12 +2105,7 @@ function getPageSessionID() {
2112
2105
  }
2113
2106
  return;
2114
2107
  }
2115
- const encodedPayload = getPayload(licenseKey);
2116
- if (!encodedPayload) {
2117
- blockEditor('invalid');
2118
- return;
2119
- }
2120
- const licensePayload = parseBase64EncodedObject(encodedPayload);
2108
+ const licensePayload = decodeLicenseKey(licenseKey);
2121
2109
  if (!licensePayload) {
2122
2110
  blockEditor('invalid');
2123
2111
  return;
@@ -2406,7 +2394,35 @@ function getPageSessionID() {
2406
2394
  const removePlugins = config.get('removePlugins') || [];
2407
2395
  const extraPlugins = config.get('extraPlugins') || [];
2408
2396
  const substitutePlugins = config.get('substitutePlugins') || [];
2409
- return this.plugins.init(plugins.concat(extraPlugins), removePlugins, substitutePlugins);
2397
+ return this.plugins.init(plugins.concat(extraPlugins), removePlugins, substitutePlugins).then((plugins)=>{
2398
+ checkPluginsAllowedByLicenseKey(this);
2399
+ return plugins;
2400
+ });
2401
+ function checkPluginsAllowedByLicenseKey(editor) {
2402
+ const licenseKey = editor.config.get('licenseKey');
2403
+ if (licenseKey === 'GPL') {
2404
+ return;
2405
+ }
2406
+ const decodedPayload = decodeLicenseKey(licenseKey);
2407
+ if (!decodedPayload) {
2408
+ return;
2409
+ }
2410
+ const disallowedPlugin = [
2411
+ ...editor.plugins
2412
+ ].map(([pluginConstructor])=>pluginConstructor).find((pluginConstructor)=>{
2413
+ if (!pluginConstructor.pluginName) {
2414
+ return false;
2415
+ }
2416
+ if (!pluginConstructor.licenseFeatureCode) {
2417
+ return false;
2418
+ }
2419
+ return isFeatureBlockedByLicenseKey(decodedPayload, pluginConstructor.licenseFeatureCode);
2420
+ });
2421
+ if (disallowedPlugin) {
2422
+ editor.enableReadOnlyMode(Symbol('invalidLicense'));
2423
+ editor._showLicenseError('pluginNotAllowed', disallowedPlugin.pluginName);
2424
+ }
2425
+ }
2410
2426
  }
2411
2427
  /**
2412
2428
  * Destroys the editor instance, releasing all resources used by it.
@@ -2494,7 +2510,7 @@ function getPageSessionID() {
2494
2510
  *
2495
2511
  * Exposed as static editor field for easier access in editor builds.
2496
2512
  */ static ContextWatchdog = ContextWatchdog;
2497
- _showLicenseError(reason, pluginName) {
2513
+ _showLicenseError(reason, name) {
2498
2514
  setTimeout(()=>{
2499
2515
  if (reason == 'invalid') {
2500
2516
  /**
@@ -2530,7 +2546,7 @@ function getPageSessionID() {
2530
2546
  * @error license-key-domain-limit
2531
2547
  */ throw new CKEditorError('license-key-domain-limit');
2532
2548
  }
2533
- if (reason == 'featureNotAllowed') {
2549
+ if (reason == 'pluginNotAllowed') {
2534
2550
  /**
2535
2551
  * The plugin you are trying to use is not permitted under your current license.
2536
2552
  * Please check the available features on the
@@ -2540,7 +2556,20 @@ function getPageSessionID() {
2540
2556
  * @error license-key-plugin-not-allowed
2541
2557
  * @param {String} pluginName The plugin you tried to load.
2542
2558
  */ throw new CKEditorError('license-key-plugin-not-allowed', null, {
2543
- pluginName
2559
+ pluginName: name
2560
+ });
2561
+ }
2562
+ if (reason == 'featureNotAllowed') {
2563
+ /**
2564
+ * The feature you are trying to use is not permitted under your current license.
2565
+ * Please check the available features on the
2566
+ * [Customer Portal](https://portal.ckeditor.com) or
2567
+ * [contact support](https://ckeditor.com/contact/) for more information.
2568
+ *
2569
+ * @error license-key-feature-not-allowed
2570
+ * @param {String} featureName The feature you tried to use.
2571
+ */ throw new CKEditorError('license-key-feature-not-allowed', null, {
2572
+ featureName: name
2544
2573
  });
2545
2574
  }
2546
2575
  if (reason == 'evaluationLimit') {