@ckeditor/ckeditor5-engine 31.1.0 → 34.0.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/LICENSE.md +2 -2
- package/README.md +2 -1
- package/package.json +25 -25
- package/src/controller/datacontroller.js +65 -74
- package/src/controller/editingcontroller.js +83 -6
- package/src/conversion/conversion.js +15 -14
- package/src/conversion/conversionhelpers.js +1 -1
- package/src/conversion/downcastdispatcher.js +298 -367
- package/src/conversion/downcasthelpers.js +860 -81
- package/src/conversion/mapper.js +105 -60
- package/src/conversion/modelconsumable.js +85 -35
- package/src/conversion/upcastdispatcher.js +34 -7
- package/src/conversion/upcasthelpers.js +4 -2
- package/src/conversion/viewconsumable.js +1 -1
- package/src/dataprocessor/basichtmlwriter.js +1 -1
- package/src/dataprocessor/dataprocessor.jsdoc +1 -1
- package/src/dataprocessor/htmldataprocessor.js +9 -31
- package/src/dataprocessor/htmlwriter.js +1 -1
- package/src/dataprocessor/xmldataprocessor.js +1 -1
- package/src/dev-utils/model.js +16 -14
- package/src/dev-utils/operationreplayer.js +1 -1
- package/src/dev-utils/utils.js +1 -1
- package/src/dev-utils/view.js +1 -1
- package/src/index.js +8 -1
- package/src/model/batch.js +77 -10
- package/src/model/differ.js +115 -69
- package/src/model/document.js +13 -4
- package/src/model/documentfragment.js +1 -1
- package/src/model/documentselection.js +1 -1
- package/src/model/element.js +1 -1
- package/src/model/history.js +1 -1
- package/src/model/item.jsdoc +1 -1
- package/src/model/liveposition.js +1 -1
- package/src/model/liverange.js +1 -1
- package/src/model/markercollection.js +29 -5
- package/src/model/model.js +138 -12
- package/src/model/node.js +1 -1
- package/src/model/nodelist.js +1 -1
- package/src/model/operation/attributeoperation.js +1 -1
- package/src/model/operation/detachoperation.js +1 -1
- package/src/model/operation/insertoperation.js +1 -1
- package/src/model/operation/markeroperation.js +1 -1
- package/src/model/operation/mergeoperation.js +1 -1
- package/src/model/operation/moveoperation.js +1 -1
- package/src/model/operation/nooperation.js +1 -1
- package/src/model/operation/operation.js +1 -1
- package/src/model/operation/operationfactory.js +1 -1
- package/src/model/operation/renameoperation.js +1 -1
- package/src/model/operation/rootattributeoperation.js +1 -1
- package/src/model/operation/splitoperation.js +1 -1
- package/src/model/operation/transform.js +1 -1
- package/src/model/operation/utils.js +1 -1
- package/src/model/position.js +1 -1
- package/src/model/range.js +1 -1
- package/src/model/rootelement.js +1 -1
- package/src/model/schema.js +80 -11
- package/src/model/selection.js +1 -1
- package/src/model/text.js +1 -1
- package/src/model/textproxy.js +1 -1
- package/src/model/treewalker.js +3 -4
- package/src/model/utils/autoparagraphing.js +1 -1
- package/src/model/utils/deletecontent.js +16 -3
- package/src/model/utils/findoptimalinsertionrange.js +68 -0
- package/src/model/utils/getselectedcontent.js +1 -1
- package/src/model/utils/insertcontent.js +1 -1
- package/src/model/utils/insertobject.js +173 -0
- package/src/model/utils/modifyselection.js +15 -8
- package/src/model/utils/selection-post-fixer.js +1 -1
- package/src/model/writer.js +17 -27
- package/src/view/attributeelement.js +1 -11
- package/src/view/containerelement.js +1 -1
- package/src/view/document.js +3 -2
- package/src/view/documentfragment.js +1 -1
- package/src/view/documentselection.js +1 -1
- package/src/view/domconverter.js +55 -28
- package/src/view/downcastwriter.js +91 -50
- package/src/view/editableelement.js +1 -1
- package/src/view/element.js +1 -28
- package/src/view/elementdefinition.jsdoc +1 -1
- package/src/view/emptyelement.js +1 -4
- package/src/view/filler.js +1 -1
- package/src/view/item.jsdoc +1 -1
- package/src/view/matcher.js +3 -3
- package/src/view/node.js +1 -1
- package/src/view/observer/arrowkeysobserver.js +1 -1
- package/src/view/observer/bubblingemittermixin.js +1 -1
- package/src/view/observer/bubblingeventinfo.js +1 -1
- package/src/view/observer/clickobserver.js +1 -2
- package/src/view/observer/compositionobserver.js +1 -1
- package/src/view/observer/domeventdata.js +1 -1
- package/src/view/observer/domeventobserver.js +1 -1
- package/src/view/observer/fakeselectionobserver.js +1 -1
- package/src/view/observer/focusobserver.js +1 -1
- package/src/view/observer/inputobserver.js +2 -2
- package/src/view/observer/keyobserver.js +1 -1
- package/src/view/observer/mouseobserver.js +1 -1
- package/src/view/observer/mutationobserver.js +1 -1
- package/src/view/observer/observer.js +1 -1
- package/src/view/observer/selectionobserver.js +1 -1
- package/src/view/observer/tabobserver.js +68 -0
- package/src/view/placeholder.js +2 -2
- package/src/view/position.js +1 -1
- package/src/view/range.js +1 -1
- package/src/view/rawelement.js +1 -4
- package/src/view/renderer.js +3 -2
- package/src/view/rooteditableelement.js +1 -1
- package/src/view/selection.js +1 -1
- package/src/view/styles/background.js +1 -1
- package/src/view/styles/border.js +1 -1
- package/src/view/styles/margin.js +1 -1
- package/src/view/styles/padding.js +1 -1
- package/src/view/styles/utils.js +1 -1
- package/src/view/stylesmap.js +1 -1
- package/src/view/text.js +1 -1
- package/src/view/textproxy.js +1 -1
- package/src/view/treewalker.js +1 -1
- package/src/view/uielement.js +1 -4
- package/src/view/upcastwriter.js +1 -1
- package/src/view/view.js +5 -1
- package/theme/placeholder.css +10 -1
- package/theme/renderer.css +1 -1
package/src/view/domconverter.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -28,12 +28,14 @@ import { logWarning } from '@ckeditor/ckeditor5-utils/src/ckeditorerror';
|
|
|
28
28
|
import indexOf from '@ckeditor/ckeditor5-utils/src/dom/indexof';
|
|
29
29
|
import getAncestors from '@ckeditor/ckeditor5-utils/src/dom/getancestors';
|
|
30
30
|
import isText from '@ckeditor/ckeditor5-utils/src/dom/istext';
|
|
31
|
+
import isComment from '@ckeditor/ckeditor5-utils/src/dom/iscomment';
|
|
31
32
|
|
|
32
33
|
const BR_FILLER_REF = BR_FILLER( document ); // eslint-disable-line new-cap
|
|
33
34
|
const NBSP_FILLER_REF = NBSP_FILLER( document ); // eslint-disable-line new-cap
|
|
34
35
|
const MARKED_NBSP_FILLER_REF = MARKED_NBSP_FILLER( document ); // eslint-disable-line new-cap
|
|
35
36
|
const UNSAFE_ATTRIBUTE_NAME_PREFIX = 'data-ck-unsafe-attribute-';
|
|
36
37
|
const UNSAFE_ELEMENT_REPLACEMENT_ATTRIBUTE = 'data-ck-unsafe-element';
|
|
38
|
+
const UNSAFE_ELEMENTS = [ 'script', 'style' ];
|
|
37
39
|
|
|
38
40
|
/**
|
|
39
41
|
* `DomConverter` is a set of tools to do transformations between DOM nodes and view nodes. It also handles
|
|
@@ -322,7 +324,7 @@ export default class DomConverter {
|
|
|
322
324
|
|
|
323
325
|
// There are certain nodes, that should be renamed to <span> in editing pipeline.
|
|
324
326
|
if ( this._shouldRenameElement( elementName ) ) {
|
|
325
|
-
|
|
327
|
+
_logUnsafeElement( elementName );
|
|
326
328
|
|
|
327
329
|
currentNode.replaceWith( this._createReplacementDomElement( elementName, currentNode ) );
|
|
328
330
|
}
|
|
@@ -383,7 +385,7 @@ export default class DomConverter {
|
|
|
383
385
|
} else {
|
|
384
386
|
// Create DOM element.
|
|
385
387
|
if ( this._shouldRenameElement( viewNode.name ) ) {
|
|
386
|
-
|
|
388
|
+
_logUnsafeElement( viewNode.name );
|
|
387
389
|
|
|
388
390
|
domElement = this._createReplacementDomElement( viewNode.name );
|
|
389
391
|
} else if ( viewNode.hasAttribute( 'xmlns' ) ) {
|
|
@@ -424,10 +426,10 @@ export default class DomConverter {
|
|
|
424
426
|
* **Note**: To remove the attribute, use {@link #removeDomElementAttribute}.
|
|
425
427
|
*
|
|
426
428
|
* @param {HTMLElement} domElement The DOM element the attribute should be set on.
|
|
427
|
-
* @param {String} key The name of the attribute
|
|
428
|
-
* @param {String} value The value of the attribute
|
|
429
|
+
* @param {String} key The name of the attribute.
|
|
430
|
+
* @param {String} value The value of the attribute.
|
|
429
431
|
* @param {module:engine/view/element~Element} [relatedViewElement] The view element related to the `domElement` (if there is any).
|
|
430
|
-
* It helps decide whether the attribute set is unsafe. For instance, view elements created via
|
|
432
|
+
* It helps decide whether the attribute set is unsafe. For instance, view elements created via the
|
|
431
433
|
* {@link module:engine/view/downcastwriter~DowncastWriter} methods can allow certain attributes that would normally be filtered out.
|
|
432
434
|
*/
|
|
433
435
|
setDomElementAttribute( domElement, key, value, relatedViewElement = null ) {
|
|
@@ -491,7 +493,22 @@ export default class DomConverter {
|
|
|
491
493
|
yield this._getBlockFiller( domDocument );
|
|
492
494
|
}
|
|
493
495
|
|
|
494
|
-
|
|
496
|
+
const transparentRendering = childView.is( 'element' ) && childView.getCustomProperty( 'dataPipeline:transparentRendering' );
|
|
497
|
+
|
|
498
|
+
if ( transparentRendering && this.renderingMode == 'data' ) {
|
|
499
|
+
yield* this.viewChildrenToDom( childView, domDocument, options );
|
|
500
|
+
} else {
|
|
501
|
+
if ( transparentRendering ) {
|
|
502
|
+
/**
|
|
503
|
+
* The `dataPipeline:transparentRendering` flag is supported only in the data pipeline.
|
|
504
|
+
*
|
|
505
|
+
* @error domconverter-transparent-rendering-unsupported-in-editing-pipeline
|
|
506
|
+
*/
|
|
507
|
+
logWarning( 'domconverter-transparent-rendering-unsupported-in-editing-pipeline', { viewElement: childView } );
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
yield this.viewToDom( childView, domDocument, options );
|
|
511
|
+
}
|
|
495
512
|
|
|
496
513
|
offset++;
|
|
497
514
|
}
|
|
@@ -617,7 +634,7 @@ export default class DomConverter {
|
|
|
617
634
|
return hostElement;
|
|
618
635
|
}
|
|
619
636
|
|
|
620
|
-
if (
|
|
637
|
+
if ( isComment( domNode ) && options.skipComments ) {
|
|
621
638
|
return null;
|
|
622
639
|
}
|
|
623
640
|
|
|
@@ -662,8 +679,8 @@ export default class DomConverter {
|
|
|
662
679
|
|
|
663
680
|
// Treat this element's content as a raw data if it was registered as such.
|
|
664
681
|
// Comment node is also treated as an element with raw data.
|
|
665
|
-
if ( this._isViewElementWithRawContent( viewElement, options ) ||
|
|
666
|
-
const rawContent =
|
|
682
|
+
if ( this._isViewElementWithRawContent( viewElement, options ) || isComment( domNode ) ) {
|
|
683
|
+
const rawContent = isComment( domNode ) ? domNode.data : domNode.innerHTML;
|
|
667
684
|
|
|
668
685
|
viewElement._setCustomProperty( '$rawContent', rawContent );
|
|
669
686
|
|
|
@@ -1032,16 +1049,6 @@ export default class DomConverter {
|
|
|
1032
1049
|
return node && node.nodeType == Node.DOCUMENT_FRAGMENT_NODE;
|
|
1033
1050
|
}
|
|
1034
1051
|
|
|
1035
|
-
/**
|
|
1036
|
-
* Returns `true` when `node.nodeType` equals `Node.COMMENT_NODE`.
|
|
1037
|
-
*
|
|
1038
|
-
* @param {Node} node Node to check.
|
|
1039
|
-
* @returns {Boolean}
|
|
1040
|
-
*/
|
|
1041
|
-
isComment( node ) {
|
|
1042
|
-
return node && node.nodeType == Node.COMMENT_NODE;
|
|
1043
|
-
}
|
|
1044
|
-
|
|
1045
1052
|
/**
|
|
1046
1053
|
* Checks if the node is an instance of the block filler for this DOM converter.
|
|
1047
1054
|
*
|
|
@@ -1526,7 +1533,7 @@ export default class DomConverter {
|
|
|
1526
1533
|
* @returns {Element}
|
|
1527
1534
|
*/
|
|
1528
1535
|
_createViewElement( node, options ) {
|
|
1529
|
-
if (
|
|
1536
|
+
if ( isComment( node ) ) {
|
|
1530
1537
|
return new ViewUIElement( this.document, '$comment' );
|
|
1531
1538
|
}
|
|
1532
1539
|
|
|
@@ -1555,7 +1562,9 @@ export default class DomConverter {
|
|
|
1555
1562
|
* @returns {Boolean}
|
|
1556
1563
|
*/
|
|
1557
1564
|
_shouldRenameElement( elementName ) {
|
|
1558
|
-
|
|
1565
|
+
const name = elementName.toLowerCase();
|
|
1566
|
+
|
|
1567
|
+
return this.renderingMode === 'editing' && UNSAFE_ELEMENTS.includes( name );
|
|
1559
1568
|
}
|
|
1560
1569
|
|
|
1561
1570
|
/**
|
|
@@ -1635,6 +1644,20 @@ function hasBlockParent( domNode, blockElements ) {
|
|
|
1635
1644
|
return parent && parent.tagName && blockElements.includes( parent.tagName.toLowerCase() );
|
|
1636
1645
|
}
|
|
1637
1646
|
|
|
1647
|
+
// Log to console the information about element that was replaced.
|
|
1648
|
+
// Check UNSAFE_ELEMENTS for all recognized unsafe elements.
|
|
1649
|
+
//
|
|
1650
|
+
// @param {String} elementName The name of the view element
|
|
1651
|
+
function _logUnsafeElement( elementName ) {
|
|
1652
|
+
if ( elementName === 'script' ) {
|
|
1653
|
+
logWarning( 'domconverter-unsafe-script-element-detected' );
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
if ( elementName === 'style' ) {
|
|
1657
|
+
logWarning( 'domconverter-unsafe-style-element-detected' );
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1638
1661
|
/**
|
|
1639
1662
|
* Enum representing the type of the block filler.
|
|
1640
1663
|
*
|
|
@@ -1649,13 +1672,17 @@ function hasBlockParent( domNode, blockElements ) {
|
|
|
1649
1672
|
*/
|
|
1650
1673
|
|
|
1651
1674
|
/**
|
|
1652
|
-
*
|
|
1653
|
-
*
|
|
1654
|
-
*
|
|
1675
|
+
* While rendering the editor content, the {@link module:engine/view/domconverter~DomConverter} detected a `<script>` element that may
|
|
1676
|
+
* disrupt the editing experience. To avoid this, the `<script>` element was replaced with `<span data-ck-unsafe-element="script"></span>`.
|
|
1677
|
+
*
|
|
1678
|
+
* @error domconverter-unsafe-script-element-detected
|
|
1679
|
+
*/
|
|
1680
|
+
|
|
1681
|
+
/**
|
|
1682
|
+
* While rendering the editor content, the {@link module:engine/view/domconverter~DomConverter} detected a `<style>` element that may affect
|
|
1683
|
+
* the editing experience. To avoid this, the `<style>` element was replaced with `<span data-ck-unsafe-element="style"></span>`.
|
|
1655
1684
|
*
|
|
1656
|
-
* @error domconverter-unsafe-element-detected
|
|
1657
|
-
* @param {module:engine/model/element~Element|HTMLElement} unsafeElement The editing view or DOM element
|
|
1658
|
-
* that was renamed.
|
|
1685
|
+
* @error domconverter-unsafe-style-element-detected
|
|
1659
1686
|
*/
|
|
1660
1687
|
|
|
1661
1688
|
/**
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -58,6 +58,14 @@ export default class DowncastWriter {
|
|
|
58
58
|
* @type {Map.<String,Set>}
|
|
59
59
|
*/
|
|
60
60
|
this._cloneGroups = new Map();
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* The slot factory used by the `elementToStructure` downcast helper.
|
|
64
|
+
*
|
|
65
|
+
* @private
|
|
66
|
+
* @type {Function|null}
|
|
67
|
+
*/
|
|
68
|
+
this._slotFactory = null;
|
|
61
69
|
}
|
|
62
70
|
|
|
63
71
|
/**
|
|
@@ -177,10 +185,6 @@ export default class DowncastWriter {
|
|
|
177
185
|
* // Set `id` of a marker element so it is not joined or merged with "normal" elements.
|
|
178
186
|
* writer.createAttributeElement( 'span', { class: 'my-marker' }, { id: 'marker:my' } );
|
|
179
187
|
*
|
|
180
|
-
* **Note:** By default an `AttributeElement` is split by a
|
|
181
|
-
* {@link module:engine/view/containerelement~ContainerElement `ContainerElement`} but this behavior can be modified
|
|
182
|
-
* with `isAllowedInsideAttributeElement` option set while {@link #createContainerElement creating the element}.
|
|
183
|
-
*
|
|
184
188
|
* @param {String} name Name of the element.
|
|
185
189
|
* @param {Object} [attributes] Element's attributes.
|
|
186
190
|
* @param {Object} [options] Element's options.
|
|
@@ -222,23 +226,36 @@ export default class DowncastWriter {
|
|
|
222
226
|
* // Create element with custom classes.
|
|
223
227
|
* writer.createContainerElement( 'p', { class: 'foo bar baz' } );
|
|
224
228
|
*
|
|
229
|
+
* // Create element with children.
|
|
230
|
+
* writer.createContainerElement( 'figure', { class: 'image' }, [
|
|
231
|
+
* writer.createEmptyElement( 'img' ),
|
|
232
|
+
* writer.createContainerElement( 'figcaption' )
|
|
233
|
+
* ] );
|
|
234
|
+
*
|
|
235
|
+
* // Create element with specific options.
|
|
236
|
+
* writer.createContainerElement( 'span', { class: 'placeholder' }, { renderUnsafeAttributes: [ 'foo' ] } );
|
|
237
|
+
*
|
|
225
238
|
* @param {String} name Name of the element.
|
|
226
239
|
* @param {Object} [attributes] Elements attributes.
|
|
240
|
+
* @param {module:engine/view/node~Node|Iterable.<module:engine/view/node~Node>|Object} [childrenOrOptions]
|
|
241
|
+
* A node or a list of nodes to be inserted into the created element. If no children were specified, element's `options`
|
|
242
|
+
* can be passed in this argument.
|
|
227
243
|
* @param {Object} [options] Element's options.
|
|
228
|
-
* @param {Boolean} [options.isAllowedInsideAttributeElement=false] Whether an element is
|
|
229
|
-
* {@link module:engine/view/element~Element#isAllowedInsideAttributeElement allowed inside an AttributeElement} and can be wrapped
|
|
230
|
-
* with {@link module:engine/view/attributeelement~AttributeElement} by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
231
244
|
* @param {Array.<String>} [options.renderUnsafeAttributes] A list of attribute names that should be rendered in the editing
|
|
232
245
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
233
246
|
* @returns {module:engine/view/containerelement~ContainerElement} Created element.
|
|
234
247
|
*/
|
|
235
|
-
createContainerElement( name, attributes, options = {} ) {
|
|
236
|
-
|
|
248
|
+
createContainerElement( name, attributes, childrenOrOptions = {}, options = {} ) {
|
|
249
|
+
let children = null;
|
|
237
250
|
|
|
238
|
-
if (
|
|
239
|
-
|
|
251
|
+
if ( isPlainObject( childrenOrOptions ) ) {
|
|
252
|
+
options = childrenOrOptions;
|
|
253
|
+
} else {
|
|
254
|
+
children = childrenOrOptions;
|
|
240
255
|
}
|
|
241
256
|
|
|
257
|
+
const containerElement = new ContainerElement( this.document, name, attributes, children );
|
|
258
|
+
|
|
242
259
|
if ( options.renderUnsafeAttributes ) {
|
|
243
260
|
containerElement._unsafeAttributesToRender.push( ...options.renderUnsafeAttributes );
|
|
244
261
|
}
|
|
@@ -282,9 +299,6 @@ export default class DowncastWriter {
|
|
|
282
299
|
* @param {String} name Name of the element.
|
|
283
300
|
* @param {Object} [attributes] Elements attributes.
|
|
284
301
|
* @param {Object} [options] Element's options.
|
|
285
|
-
* @param {Boolean} [options.isAllowedInsideAttributeElement=true] Whether an element is
|
|
286
|
-
* {@link module:engine/view/element~Element#isAllowedInsideAttributeElement allowed inside an AttributeElement} and can be wrapped
|
|
287
|
-
* with {@link module:engine/view/attributeelement~AttributeElement} by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
288
302
|
* @param {Array.<String>} [options.renderUnsafeAttributes] A list of attribute names that should be rendered in the editing
|
|
289
303
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
290
304
|
* @returns {module:engine/view/emptyelement~EmptyElement} Created element.
|
|
@@ -292,10 +306,6 @@ export default class DowncastWriter {
|
|
|
292
306
|
createEmptyElement( name, attributes, options = {} ) {
|
|
293
307
|
const emptyElement = new EmptyElement( this.document, name, attributes );
|
|
294
308
|
|
|
295
|
-
if ( options.isAllowedInsideAttributeElement !== undefined ) {
|
|
296
|
-
emptyElement._isAllowedInsideAttributeElement = options.isAllowedInsideAttributeElement;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
309
|
if ( options.renderUnsafeAttributes ) {
|
|
300
310
|
emptyElement._unsafeAttributesToRender.push( ...options.renderUnsafeAttributes );
|
|
301
311
|
}
|
|
@@ -326,23 +336,15 @@ export default class DowncastWriter {
|
|
|
326
336
|
* @param {String} name The name of the element.
|
|
327
337
|
* @param {Object} [attributes] Element attributes.
|
|
328
338
|
* @param {Function} [renderFunction] A custom render function.
|
|
329
|
-
* @param {Object} [options] Element's options.
|
|
330
|
-
* @param {Boolean} [options.isAllowedInsideAttributeElement=true] Whether an element is
|
|
331
|
-
* {@link module:engine/view/element~Element#isAllowedInsideAttributeElement allowed inside an AttributeElement} and can be wrapped
|
|
332
|
-
* with {@link module:engine/view/attributeelement~AttributeElement} by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
333
339
|
* @returns {module:engine/view/uielement~UIElement} The created element.
|
|
334
340
|
*/
|
|
335
|
-
createUIElement( name, attributes, renderFunction
|
|
341
|
+
createUIElement( name, attributes, renderFunction ) {
|
|
336
342
|
const uiElement = new UIElement( this.document, name, attributes );
|
|
337
343
|
|
|
338
344
|
if ( renderFunction ) {
|
|
339
345
|
uiElement.render = renderFunction;
|
|
340
346
|
}
|
|
341
347
|
|
|
342
|
-
if ( options.isAllowedInsideAttributeElement !== undefined ) {
|
|
343
|
-
uiElement._isAllowedInsideAttributeElement = options.isAllowedInsideAttributeElement;
|
|
344
|
-
}
|
|
345
|
-
|
|
346
348
|
return uiElement;
|
|
347
349
|
}
|
|
348
350
|
|
|
@@ -369,9 +371,6 @@ export default class DowncastWriter {
|
|
|
369
371
|
* @param {Object} [attributes] Element attributes.
|
|
370
372
|
* @param {Function} [renderFunction] A custom render function.
|
|
371
373
|
* @param {Object} [options] Element's options.
|
|
372
|
-
* @param {Boolean} [options.isAllowedInsideAttributeElement=true] Whether an element is
|
|
373
|
-
* {@link module:engine/view/element~Element#isAllowedInsideAttributeElement allowed inside an AttributeElement} and can be wrapped
|
|
374
|
-
* with {@link module:engine/view/attributeelement~AttributeElement} by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
375
374
|
* @param {Array.<String>} [options.renderUnsafeAttributes] A list of attribute names that should be rendered in the editing
|
|
376
375
|
* pipeline even though they would normally be filtered out by unsafe attribute detection mechanisms.
|
|
377
376
|
* @returns {module:engine/view/rawelement~RawElement} The created element.
|
|
@@ -381,10 +380,6 @@ export default class DowncastWriter {
|
|
|
381
380
|
|
|
382
381
|
rawElement.render = renderFunction || ( () => {} );
|
|
383
382
|
|
|
384
|
-
if ( options.isAllowedInsideAttributeElement !== undefined ) {
|
|
385
|
-
rawElement._isAllowedInsideAttributeElement = options.isAllowedInsideAttributeElement;
|
|
386
|
-
}
|
|
387
|
-
|
|
388
383
|
if ( options.renderUnsafeAttributes ) {
|
|
389
384
|
rawElement._unsafeAttributesToRender.push( ...options.renderUnsafeAttributes );
|
|
390
385
|
}
|
|
@@ -762,7 +757,7 @@ export default class DowncastWriter {
|
|
|
762
757
|
|
|
763
758
|
// Break attributes on nodes that do exist in the model tree so they can have attributes, other elements
|
|
764
759
|
// can't have an attribute in model and won't get wrapped with an AttributeElement while down-casted.
|
|
765
|
-
const breakAttributes = !
|
|
760
|
+
const breakAttributes = !node.is( 'uiElement' );
|
|
766
761
|
|
|
767
762
|
if ( !lastGroup || lastGroup.breakAttributes != breakAttributes ) {
|
|
768
763
|
groups.push( {
|
|
@@ -951,16 +946,6 @@ export default class DowncastWriter {
|
|
|
951
946
|
* Throws {@link module:utils/ckeditorerror~CKEditorError} `view-writer-wrap-nonselection-collapsed-range` when passed range
|
|
952
947
|
* is collapsed and different than view selection.
|
|
953
948
|
*
|
|
954
|
-
* **Note:** Attribute elements by default can wrap {@link module:engine/view/text~Text},
|
|
955
|
-
* {@link module:engine/view/emptyelement~EmptyElement}, {@link module:engine/view/uielement~UIElement},
|
|
956
|
-
* {@link module:engine/view/rawelement~RawElement} and other attribute elements with higher priority. Other elements while placed
|
|
957
|
-
* inside an attribute element will split it (or nest it in case of an `AttributeElement`). This behavior can be modified by changing
|
|
958
|
-
* the `isAllowedInsideAttributeElement` option while using
|
|
959
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createContainerElement},
|
|
960
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createEmptyElement},
|
|
961
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createUIElement} or
|
|
962
|
-
* {@link module:engine/view/downcastwriter~DowncastWriter#createRawElement}.
|
|
963
|
-
*
|
|
964
949
|
* @param {module:engine/view/range~Range} range Range to wrap.
|
|
965
950
|
* @param {module:engine/view/attributeelement~AttributeElement} attribute Attribute element to use as wrapper.
|
|
966
951
|
* @returns {module:engine/view/range~Range} range Range after wrapping, spanning over wrapping attribute element.
|
|
@@ -1167,7 +1152,7 @@ export default class DowncastWriter {
|
|
|
1167
1152
|
}
|
|
1168
1153
|
|
|
1169
1154
|
/**
|
|
1170
|
-
Creates new {@link module:engine/view/selection~Selection} instance.
|
|
1155
|
+
* Creates new {@link module:engine/view/selection~Selection} instance.
|
|
1171
1156
|
*
|
|
1172
1157
|
* // Creates empty selection without ranges.
|
|
1173
1158
|
* const selection = writer.createSelection();
|
|
@@ -1230,6 +1215,63 @@ export default class DowncastWriter {
|
|
|
1230
1215
|
return new Selection( selectable, placeOrOffset, options );
|
|
1231
1216
|
}
|
|
1232
1217
|
|
|
1218
|
+
/**
|
|
1219
|
+
* Creates placeholders for child elements of the {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure
|
|
1220
|
+
* `elementToStructure()`} conversion helper.
|
|
1221
|
+
*
|
|
1222
|
+
* const viewSlot = conversionApi.writer.createSlot();
|
|
1223
|
+
* const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
|
|
1224
|
+
*
|
|
1225
|
+
* conversionApi.writer.insert( viewPosition, viewSlot );
|
|
1226
|
+
*
|
|
1227
|
+
* It could be filtered down to a specific subset of children (only `<foo>` model elements in this case):
|
|
1228
|
+
*
|
|
1229
|
+
* const viewSlot = conversionApi.writer.createSlot( node => node.is( 'element', 'foo' ) );
|
|
1230
|
+
* const viewPosition = conversionApi.writer.createPositionAt( viewElement, 0 );
|
|
1231
|
+
*
|
|
1232
|
+
* conversionApi.writer.insert( viewPosition, viewSlot );
|
|
1233
|
+
*
|
|
1234
|
+
* While providing a filtered slot, make sure to provide slots for all child nodes. A single node can not be downcasted into
|
|
1235
|
+
* multiple slots.
|
|
1236
|
+
*
|
|
1237
|
+
* **Note**: You should not change the order of nodes. View elements should be in the same order as model nodes.
|
|
1238
|
+
*
|
|
1239
|
+
* @param {'children'|module:engine/conversion/downcasthelpers~SlotFilter} [modeOrFilter='children'] The filter for child nodes.
|
|
1240
|
+
* @returns {module:engine/view/element~Element} The slot element to be placed in to the view structure while processing
|
|
1241
|
+
* {@link module:engine/conversion/downcasthelpers~DowncastHelpers#elementToStructure `elementToStructure()`}.
|
|
1242
|
+
*/
|
|
1243
|
+
createSlot( modeOrFilter ) {
|
|
1244
|
+
if ( !this._slotFactory ) {
|
|
1245
|
+
/**
|
|
1246
|
+
* The `createSlot()` method is only allowed inside the `elementToStructure` downcast helper callback.
|
|
1247
|
+
*
|
|
1248
|
+
* @error view-writer-invalid-create-slot-context
|
|
1249
|
+
*/
|
|
1250
|
+
throw new CKEditorError( 'view-writer-invalid-create-slot-context', this.document );
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
return this._slotFactory( this, modeOrFilter );
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
/**
|
|
1257
|
+
* Registers a slot factory.
|
|
1258
|
+
*
|
|
1259
|
+
* @protected
|
|
1260
|
+
* @param {Function} slotFactory The slot factory.
|
|
1261
|
+
*/
|
|
1262
|
+
_registerSlotFactory( slotFactory ) {
|
|
1263
|
+
this._slotFactory = slotFactory;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
/**
|
|
1267
|
+
* Clears the registered slot factory.
|
|
1268
|
+
*
|
|
1269
|
+
* @protected
|
|
1270
|
+
*/
|
|
1271
|
+
_clearSlotFactory() {
|
|
1272
|
+
this._slotFactory = null;
|
|
1273
|
+
}
|
|
1274
|
+
|
|
1233
1275
|
/**
|
|
1234
1276
|
* Inserts a node or nodes at the specified position. Takes care of breaking attributes before insertion
|
|
1235
1277
|
* and merging them afterwards if requested by the breakAttributes param.
|
|
@@ -1314,7 +1356,6 @@ export default class DowncastWriter {
|
|
|
1314
1356
|
const child = parent.getChild( i );
|
|
1315
1357
|
const isText = child.is( '$text' );
|
|
1316
1358
|
const isAttribute = child.is( 'attributeElement' );
|
|
1317
|
-
const isAllowedInsideAttributeElement = child.isAllowedInsideAttributeElement;
|
|
1318
1359
|
|
|
1319
1360
|
//
|
|
1320
1361
|
// (In all examples, assume that `wrapElement` is `<span class="foo">` element.)
|
|
@@ -1333,7 +1374,7 @@ export default class DowncastWriter {
|
|
|
1333
1374
|
//
|
|
1334
1375
|
// <p>abc</p> --> <p><span class="foo">abc</span></p>
|
|
1335
1376
|
// <p><strong>abc</strong></p> --> <p><span class="foo"><strong>abc</strong></span></p>
|
|
1336
|
-
else if ( isText ||
|
|
1377
|
+
else if ( isText || !isAttribute || shouldABeOutsideB( wrapElement, child ) ) {
|
|
1337
1378
|
// Clone attribute.
|
|
1338
1379
|
const newAttribute = wrapElement._clone();
|
|
1339
1380
|
|
|
@@ -1351,7 +1392,7 @@ export default class DowncastWriter {
|
|
|
1351
1392
|
//
|
|
1352
1393
|
// <p><a href="foo.html">abc</a></p> --> <p><a href="foo.html"><span class="foo">abc</span></a></p>
|
|
1353
1394
|
//
|
|
1354
|
-
else if ( isAttribute ) {
|
|
1395
|
+
else /* if ( isAttribute ) */ {
|
|
1355
1396
|
this._wrapChildren( child, 0, child.childCount, wrapElement );
|
|
1356
1397
|
}
|
|
1357
1398
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
package/src/view/element.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -130,15 +130,6 @@ export default class Element extends Node {
|
|
|
130
130
|
*/
|
|
131
131
|
this._customProperties = new Map();
|
|
132
132
|
|
|
133
|
-
/**
|
|
134
|
-
* Whether an element is allowed inside an AttributeElement and can be wrapped with
|
|
135
|
-
* {@link module:engine/view/attributeelement~AttributeElement} by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
136
|
-
*
|
|
137
|
-
* @protected
|
|
138
|
-
* @member {Boolean}
|
|
139
|
-
*/
|
|
140
|
-
this._isAllowedInsideAttributeElement = false;
|
|
141
|
-
|
|
142
133
|
/**
|
|
143
134
|
* A list of attribute names that should be rendered in the editing pipeline even though filtering mechanisms
|
|
144
135
|
* implemented in the {@link module:engine/view/domconverter~DomConverter} (for instance,
|
|
@@ -175,17 +166,6 @@ export default class Element extends Node {
|
|
|
175
166
|
return this._children.length === 0;
|
|
176
167
|
}
|
|
177
168
|
|
|
178
|
-
/**
|
|
179
|
-
* Whether the element is allowed inside an AttributeElement and can be wrapped with
|
|
180
|
-
* {@link module:engine/view/attributeelement~AttributeElement} by {@link module:engine/view/downcastwriter~DowncastWriter}.
|
|
181
|
-
*
|
|
182
|
-
* @readonly
|
|
183
|
-
* @type {Boolean}
|
|
184
|
-
*/
|
|
185
|
-
get isAllowedInsideAttributeElement() {
|
|
186
|
-
return this._isAllowedInsideAttributeElement;
|
|
187
|
-
}
|
|
188
|
-
|
|
189
169
|
/**
|
|
190
170
|
* Checks whether this object is of the given.
|
|
191
171
|
*
|
|
@@ -350,11 +330,6 @@ export default class Element extends Node {
|
|
|
350
330
|
return false;
|
|
351
331
|
}
|
|
352
332
|
|
|
353
|
-
// Check isAllowedInsideAttributeElement property.
|
|
354
|
-
if ( this.isAllowedInsideAttributeElement != otherElement.isAllowedInsideAttributeElement ) {
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
333
|
// Check number of attributes, classes and styles.
|
|
359
334
|
if ( this._attrs.size !== otherElement._attrs.size || this._classes.size !== otherElement._classes.size ||
|
|
360
335
|
this._styles.size !== otherElement._styles.size ) {
|
|
@@ -633,8 +608,6 @@ export default class Element extends Node {
|
|
|
633
608
|
// is changed by e.g. toWidget() function from ckeditor5-widget. Perhaps this should be one of custom props.
|
|
634
609
|
cloned.getFillerOffset = this.getFillerOffset;
|
|
635
610
|
|
|
636
|
-
cloned._isAllowedInsideAttributeElement = this.isAllowedInsideAttributeElement;
|
|
637
|
-
|
|
638
611
|
return cloned;
|
|
639
612
|
}
|
|
640
613
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
package/src/view/emptyelement.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -37,9 +37,6 @@ export default class EmptyElement extends Element {
|
|
|
37
37
|
constructor( document, name, attrs, children ) {
|
|
38
38
|
super( document, name, attrs, children );
|
|
39
39
|
|
|
40
|
-
// Override the default of the base class.
|
|
41
|
-
this._isAllowedInsideAttributeElement = true;
|
|
42
|
-
|
|
43
40
|
/**
|
|
44
41
|
* Returns `null` because filler is not needed for EmptyElements.
|
|
45
42
|
*
|
package/src/view/filler.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
package/src/view/item.jsdoc
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
package/src/view/matcher.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -739,7 +739,7 @@ function matchStyles( patterns, element ) {
|
|
|
739
739
|
* styles: /^border.*$/
|
|
740
740
|
* }
|
|
741
741
|
*
|
|
742
|
-
* Refer to the {@glink
|
|
742
|
+
* Refer to the {@glink updating/migration-to-29##migration-to-ckeditor-5-v2910 Migration to v29.1.0} guide
|
|
743
743
|
* and {@link module:engine/view/matcher~MatcherPattern} documentation.
|
|
744
744
|
*
|
|
745
745
|
* @param {Object} pattern Pattern with missing properties.
|
|
@@ -769,7 +769,7 @@ function matchStyles( patterns, element ) {
|
|
|
769
769
|
* classes: 'foobar'
|
|
770
770
|
* }
|
|
771
771
|
*
|
|
772
|
-
* Refer to the {@glink
|
|
772
|
+
* Refer to the {@glink updating/migration-to-29##migration-to-ckeditor-5-v2910 Migration to v29.1.0} guide
|
|
773
773
|
* and the {@link module:engine/view/matcher~MatcherPattern} documentation.
|
|
774
774
|
*
|
|
775
775
|
* @param {Object} pattern Pattern with missing properties.
|
package/src/view/node.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
|
|
2
1
|
/**
|
|
3
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
4
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
5
4
|
*/
|
|
6
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @license Copyright (c) 2003-
|
|
2
|
+
* @license Copyright (c) 2003-2022, CKSource Holding sp. z o.o. All rights reserved.
|
|
3
3
|
* For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
|
|
4
4
|
*/
|
|
5
5
|
|