@ckeditor/ckeditor5-widget 44.3.0 → 45.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/LICENSE.md CHANGED
@@ -18,7 +18,7 @@ Where not otherwise indicated, all CKEditor content is authored by CKSource engi
18
18
 
19
19
  The following libraries are included in CKEditor under the [MIT license](https://opensource.org/licenses/MIT):
20
20
 
21
- * Lodash - Copyright (c) JS Foundation and other contributors https://js.foundation/. Based on Underscore.js, copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors http://underscorejs.org/.
21
+ * es-toolkit - Copyright (c) 2024 Viva Republica, Inc.
22
22
 
23
23
  Trademarks
24
24
  ----------
package/dist/index.js CHANGED
@@ -6,9 +6,10 @@ import { Plugin } from '@ckeditor/ckeditor5-core/dist/index.js';
6
6
  import { MouseObserver, TreeWalker } from '@ckeditor/ckeditor5-engine/dist/index.js';
7
7
  import { Delete } from '@ckeditor/ckeditor5-typing/dist/index.js';
8
8
  import { EmitterMixin, Rect, CKEditorError, toArray, isForwardArrowKeyCode, env, keyCodes, getLocalizedArrowKeyCodeDirection, getRangeFromMouseEvent, logWarning, ObservableMixin, compareArrays, global, DomEmitterMixin } from '@ckeditor/ckeditor5-utils/dist/index.js';
9
+ import { IconDragHandle, IconReturnArrow } from '@ckeditor/ckeditor5-icons/dist/index.js';
9
10
  import { IconView, Template, ContextualBalloon, ToolbarView, BalloonPanelView, View } from '@ckeditor/ckeditor5-ui/dist/index.js';
10
11
  import { Enter } from '@ckeditor/ckeditor5-enter/dist/index.js';
11
- import { throttle } from 'lodash-es';
12
+ import { throttle } from 'es-toolkit/compat';
12
13
 
13
14
  /**
14
15
  * Class used to handle the correct order of highlights on elements.
@@ -120,8 +121,6 @@ import { throttle } from 'lodash-es';
120
121
  return Array.isArray(classes) ? classes.sort().join(',') : classes;
121
122
  }
122
123
 
123
- var dragHandleIcon = "<svg viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M4 0v1H1v3H0V.5A.5.5 0 0 1 .5 0H4zm8 0h3.5a.5.5 0 0 1 .5.5V4h-1V1h-3V0zM4 16H.5a.5.5 0 0 1-.5-.5V12h1v3h3v1zm8 0v-1h3v-3h1v3.5a.5.5 0 0 1-.5.5H12z\"/><path fill-opacity=\".256\" d=\"M1 1h14v14H1z\"/><g class=\"ck-icon__selected-indicator\"><path d=\"M7 0h2v1H7V0zM0 7h1v2H0V7zm15 0h1v2h-1V7zm-8 8h2v1H7v-1z\"/><path fill-opacity=\".254\" d=\"M1 1h14v14H1z\"/></g></svg>";
124
-
125
124
  /**
126
125
  * CSS class added to each widget element.
127
126
  */ const WIDGET_CLASS_NAME = 'ck-widget';
@@ -279,6 +278,7 @@ var dragHandleIcon = "<svg viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/
279
278
  * * adds the `ck-editor__editable` and `ck-editor__nested-editable` CSS classes,
280
279
  * * adds the `ck-editor__nested-editable_focused` CSS class when the editable is focused and removes it when it is blurred.
281
280
  * * implements the {@link ~setHighlightHandling view highlight on widget's editable}.
281
+ * * sets the `role` attribute to `textbox` for accessibility purposes.
282
282
  *
283
283
  * Similarly to {@link ~toWidget `toWidget()`} this function should be used in `editingDowncast` only and it is usually
284
284
  * used together with {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToElement `elementToElement()`}.
@@ -311,13 +311,17 @@ var dragHandleIcon = "<svg viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/
311
311
  *
312
312
  * @param options Additional options.
313
313
  * @param options.label Editable's label used by assistive technologies (e.g. screen readers).
314
+ * @param options.withAriaRole Whether to add the role="textbox" attribute on the editable. Defaults to `true`.
314
315
  * @returns Returns the same element that was provided in the `editable` parameter
315
316
  */ function toWidgetEditable(editable, writer, options = {}) {
316
317
  writer.addClass([
317
318
  'ck-editor__editable',
318
319
  'ck-editor__nested-editable'
319
320
  ], editable);
320
- writer.setAttribute('role', 'textbox', editable);
321
+ // Set role="textbox" only if explicitly requested (defaults to true for backward compatibility).
322
+ if (options.withAriaRole !== false) {
323
+ writer.setAttribute('role', 'textbox', editable);
324
+ }
321
325
  writer.setAttribute('tabindex', '-1', editable);
322
326
  if (options.label) {
323
327
  writer.setAttribute('aria-label', options.label, editable);
@@ -438,7 +442,7 @@ var dragHandleIcon = "<svg viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/
438
442
  const domElement = this.toDomElement(domDocument);
439
443
  // Use the IconView from the ui library.
440
444
  const icon = new IconView();
441
- icon.set('content', dragHandleIcon);
445
+ icon.set('content', IconDragHandle);
442
446
  // Render the icon view right away to append its #element to the selectionHandle DOM element.
443
447
  icon.render();
444
448
  domElement.appendChild(icon.element);
@@ -536,14 +540,12 @@ var dragHandleIcon = "<svg viewBox=\"0 0 16 16\" xmlns=\"http://www.w3.org/2000/
536
540
  return selection.getAttribute(TYPE_AROUND_SELECTION_ATTRIBUTE);
537
541
  }
538
542
 
539
- var returnIcon = "<svg viewBox=\"0 0 10 8\" xmlns=\"http://www.w3.org/2000/svg\"><path d=\"M9.055.263v3.972h-6.77M1 4.216l2-2.038m-2 2 2 2.038\"/></svg>";
540
-
541
543
  const POSSIBLE_INSERTION_POSITIONS = [
542
544
  'before',
543
545
  'after'
544
546
  ];
545
547
  // Do the SVG parsing once and then clone the result <svg> DOM element for each new button.
546
- const RETURN_ARROW_ICON_ELEMENT = new DOMParser().parseFromString(returnIcon, 'image/svg+xml').firstChild;
548
+ const RETURN_ARROW_ICON_ELEMENT = new DOMParser().parseFromString(IconReturnArrow, 'image/svg+xml').firstChild;
547
549
  const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
548
550
  /**
549
551
  * A plugin that allows users to type around widgets where normally it is impossible to place the caret due
@@ -673,9 +675,9 @@ const PLUGIN_DISABLED_EDITING_ROOT_CLASS = 'ck-widget__type-around_disabled';
673
675
  return false;
674
676
  }
675
677
  // @if CK_DEBUG_TYPING // if ( ( window as any ).logCKETyping ) {
676
- // @if CK_DEBUG_TYPING // console.info( '%c[WidgetTypeAround]%c Fake caret -> insert paragraph',
677
- // @if CK_DEBUG_TYPING // 'font-weight: bold; color: green', ''
678
- // @if CK_DEBUG_TYPING // );
678
+ // @if CK_DEBUG_TYPING // console.info( ..._buildLogMessage( this, 'WidgetTypeAround',
679
+ // @if CK_DEBUG_TYPING // 'Fake caret -> insert paragraph',
680
+ // @if CK_DEBUG_TYPING // ) );
679
681
  // @if CK_DEBUG_TYPING // }
680
682
  const selectedModelElement = modelSelection.getSelectedElement();
681
683
  this._insertParagraph(selectedModelElement, typeAroundFakeCaretPosition);
@@ -2160,7 +2162,7 @@ function selectionWillShrink(selection, isForward) {
2160
2162
  * @param options.items Array of toolbar items.
2161
2163
  * @param options.getRelatedElement Callback which returns an element the toolbar should be attached to.
2162
2164
  * @param options.balloonClassName CSS class for the widget balloon.
2163
- */ register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container' }) {
2165
+ */ register(toolbarId, { ariaLabel, items, getRelatedElement, balloonClassName = 'ck-toolbar-container', positions }) {
2164
2166
  // Trying to register a toolbar without any item.
2165
2167
  if (!items.length) {
2166
2168
  /**
@@ -2200,6 +2202,7 @@ function selectionWillShrink(selection, isForward) {
2200
2202
  getRelatedElement,
2201
2203
  balloonClassName,
2202
2204
  itemsConfig: items,
2205
+ positions,
2203
2206
  initialized: false
2204
2207
  };
2205
2208
  // Register the toolbar so it becomes available for Alt+F10 and Esc navigation.
@@ -2264,7 +2267,7 @@ function selectionWillShrink(selection, isForward) {
2264
2267
  * should be still visible after the {@link module:ui/editorui/editorui~EditorUI#event:update}.
2265
2268
  */ _showToolbar(toolbarDefinition, relatedElement) {
2266
2269
  if (this._isToolbarVisible(toolbarDefinition)) {
2267
- repositionContextualBalloon(this.editor, relatedElement);
2270
+ repositionContextualBalloon(this.editor, relatedElement, toolbarDefinition.positions);
2268
2271
  } else if (!this._isToolbarInBalloon(toolbarDefinition)) {
2269
2272
  if (!toolbarDefinition.initialized) {
2270
2273
  toolbarDefinition.initialized = true;
@@ -2272,7 +2275,7 @@ function selectionWillShrink(selection, isForward) {
2272
2275
  }
2273
2276
  this._balloon.add({
2274
2277
  view: toolbarDefinition.view,
2275
- position: getBalloonPositionData(this.editor, relatedElement),
2278
+ position: getBalloonPositionData(this.editor, relatedElement, toolbarDefinition.positions),
2276
2279
  balloonClassName: toolbarDefinition.balloonClassName
2277
2280
  });
2278
2281
  // Update toolbar position each time stack with toolbar view is switched to visible.
@@ -2283,7 +2286,7 @@ function selectionWillShrink(selection, isForward) {
2283
2286
  for (const definition of this._toolbarDefinitions.values()){
2284
2287
  if (this._isToolbarVisible(definition)) {
2285
2288
  const relatedElement = definition.getRelatedElement(this.editor.editing.view.document.selection);
2286
- repositionContextualBalloon(this.editor, relatedElement);
2289
+ repositionContextualBalloon(this.editor, relatedElement, toolbarDefinition.positions);
2287
2290
  }
2288
2291
  }
2289
2292
  });
@@ -2296,17 +2299,17 @@ function selectionWillShrink(selection, isForward) {
2296
2299
  return this._balloon.hasView(toolbar.view);
2297
2300
  }
2298
2301
  }
2299
- function repositionContextualBalloon(editor, relatedElement) {
2302
+ function repositionContextualBalloon(editor, relatedElement, positions) {
2300
2303
  const balloon = editor.plugins.get('ContextualBalloon');
2301
- const position = getBalloonPositionData(editor, relatedElement);
2304
+ const position = getBalloonPositionData(editor, relatedElement, positions);
2302
2305
  balloon.updatePosition(position);
2303
2306
  }
2304
- function getBalloonPositionData(editor, relatedElement) {
2307
+ function getBalloonPositionData(editor, relatedElement, positions) {
2305
2308
  const editingView = editor.editing.view;
2306
2309
  const defaultPositions = BalloonPanelView.defaultPositions;
2307
2310
  return {
2308
2311
  target: editingView.domConverter.mapViewToDom(relatedElement),
2309
- positions: [
2312
+ positions: positions || [
2310
2313
  defaultPositions.northArrowSouth,
2311
2314
  defaultPositions.northArrowSouthWest,
2312
2315
  defaultPositions.northArrowSouthEast,