@ckeditor/ckeditor5-engine 44.2.1 → 44.3.0-alpha.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 +1677 -1258
- package/dist/index.js.map +1 -1
- package/package.json +2 -4
- package/src/conversion/downcasthelpers.js +14 -42
- package/src/conversion/viewconsumable.d.ts +65 -97
- package/src/conversion/viewconsumable.js +217 -215
- package/src/view/attributeelement.d.ts +14 -0
- package/src/view/attributeelement.js +26 -0
- package/src/view/domconverter.js +72 -7
- package/src/view/downcastwriter.d.ts +32 -20
- package/src/view/downcastwriter.js +18 -142
- package/src/view/element.d.ts +309 -17
- package/src/view/element.js +432 -137
- package/src/view/matcher.d.ts +38 -16
- package/src/view/matcher.js +91 -166
- package/src/view/stylesmap.d.ts +68 -6
- package/src/view/stylesmap.js +144 -8
- package/src/view/tokenlist.d.ts +109 -0
- package/src/view/tokenlist.js +196 -0
package/src/view/element.d.ts
CHANGED
|
@@ -7,8 +7,8 @@
|
|
|
7
7
|
*/
|
|
8
8
|
import Node from './node.js';
|
|
9
9
|
import { type ArrayOrItem } from '@ckeditor/ckeditor5-utils';
|
|
10
|
-
import { type MatcherPattern } from './matcher.js';
|
|
11
|
-
import { type StyleValue } from './stylesmap.js';
|
|
10
|
+
import { type MatcherPattern, type NormalizedPropertyPattern } from './matcher.js';
|
|
11
|
+
import { type Styles, type StyleValue } from './stylesmap.js';
|
|
12
12
|
import type Document from './document.js';
|
|
13
13
|
import type Item from './item.js';
|
|
14
14
|
/**
|
|
@@ -60,18 +60,22 @@ export default class Element extends Node {
|
|
|
60
60
|
*/
|
|
61
61
|
private readonly _children;
|
|
62
62
|
/**
|
|
63
|
-
*
|
|
63
|
+
* Map of custom properties.
|
|
64
|
+
* Custom properties can be added to element instance, will be cloned but not rendered into DOM.
|
|
64
65
|
*/
|
|
65
|
-
private readonly
|
|
66
|
+
private readonly _customProperties;
|
|
66
67
|
/**
|
|
67
|
-
*
|
|
68
|
+
* Set of classes associated with element instance.
|
|
69
|
+
*
|
|
70
|
+
* Note that this is just an alias for `this._attrs.get( 'class' );`
|
|
68
71
|
*/
|
|
69
|
-
private
|
|
72
|
+
private get _classes();
|
|
70
73
|
/**
|
|
71
|
-
*
|
|
72
|
-
*
|
|
74
|
+
* Normalized styles.
|
|
75
|
+
*
|
|
76
|
+
* Note that this is just an alias for `this._attrs.get( 'style' );`
|
|
73
77
|
*/
|
|
74
|
-
private
|
|
78
|
+
private get _styles();
|
|
75
79
|
/**
|
|
76
80
|
* Creates a view element.
|
|
77
81
|
*
|
|
@@ -144,7 +148,7 @@ export default class Element extends Node {
|
|
|
144
148
|
* @param key Attribute key.
|
|
145
149
|
* @returns `true` if attribute with the specified key exists in the element, `false` otherwise.
|
|
146
150
|
*/
|
|
147
|
-
hasAttribute(key: string): boolean;
|
|
151
|
+
hasAttribute(key: string, token?: string): boolean;
|
|
148
152
|
/**
|
|
149
153
|
* Checks if this element is similar to other element.
|
|
150
154
|
* Both elements should have the same name and attributes to be considered as similar. Two similar elements
|
|
@@ -164,9 +168,9 @@ export default class Element extends Node {
|
|
|
164
168
|
/**
|
|
165
169
|
* Returns iterator that contains all class names.
|
|
166
170
|
*/
|
|
167
|
-
getClassNames():
|
|
171
|
+
getClassNames(): IterableIterator<string>;
|
|
168
172
|
/**
|
|
169
|
-
* Returns style value for the given property
|
|
173
|
+
* Returns style value for the given property name.
|
|
170
174
|
* If the style does not exist `undefined` is returned.
|
|
171
175
|
*
|
|
172
176
|
* **Note**: This method can work with normalized style names if
|
|
@@ -225,13 +229,13 @@ export default class Element extends Node {
|
|
|
225
229
|
*
|
|
226
230
|
* @param property Name of CSS property
|
|
227
231
|
*/
|
|
228
|
-
getNormalizedStyle(property: string): StyleValue;
|
|
232
|
+
getNormalizedStyle(property: string): StyleValue | undefined;
|
|
229
233
|
/**
|
|
230
|
-
* Returns
|
|
234
|
+
* Returns an array that contains all style names.
|
|
231
235
|
*
|
|
232
236
|
* @param expand Expand shorthand style properties and return all equivalent style representations.
|
|
233
237
|
*/
|
|
234
|
-
getStyleNames(expand?: boolean):
|
|
238
|
+
getStyleNames(expand?: boolean): Array<string>;
|
|
235
239
|
/**
|
|
236
240
|
* Returns true if style keys are present.
|
|
237
241
|
* If more then one style property is provided - returns true only when all properties are present.
|
|
@@ -345,19 +349,21 @@ export default class Element extends Node {
|
|
|
345
349
|
* @internal
|
|
346
350
|
* @param key Attribute key.
|
|
347
351
|
* @param value Attribute value.
|
|
352
|
+
* @param overwrite Whether tokenized attribute should override the attribute value or just add a token.
|
|
348
353
|
* @fires change
|
|
349
354
|
*/
|
|
350
|
-
_setAttribute(key: string, value: unknown): void;
|
|
355
|
+
_setAttribute(key: string, value: unknown, overwrite?: boolean): void;
|
|
351
356
|
/**
|
|
352
357
|
* Removes attribute from the element.
|
|
353
358
|
*
|
|
354
359
|
* @see module:engine/view/downcastwriter~DowncastWriter#removeAttribute
|
|
355
360
|
* @internal
|
|
356
361
|
* @param key Attribute key.
|
|
362
|
+
* @param tokens Attribute value tokens to remove. The whole attribute is removed if not specified.
|
|
357
363
|
* @returns Returns true if an attribute existed and has been removed.
|
|
358
364
|
* @fires change
|
|
359
365
|
*/
|
|
360
|
-
_removeAttribute(key: string): boolean;
|
|
366
|
+
_removeAttribute(key: string, tokens?: ArrayOrItem<string>): boolean;
|
|
361
367
|
/**
|
|
362
368
|
* Adds specified class.
|
|
363
369
|
*
|
|
@@ -441,6 +447,150 @@ export default class Element extends Node {
|
|
|
441
447
|
* @fires change
|
|
442
448
|
*/
|
|
443
449
|
_removeStyle(property: ArrayOrItem<string>): void;
|
|
450
|
+
/**
|
|
451
|
+
* Used by the {@link module:engine/view/matcher~Matcher Matcher} to collect matching attribute tuples
|
|
452
|
+
* (attribute name and optional token).
|
|
453
|
+
*
|
|
454
|
+
* Normalized patterns can be used in following ways:
|
|
455
|
+
* - to match any attribute name with any or no value:
|
|
456
|
+
*
|
|
457
|
+
* ```ts
|
|
458
|
+
* patterns: [
|
|
459
|
+
* [ true, true ]
|
|
460
|
+
* ]
|
|
461
|
+
* ```
|
|
462
|
+
*
|
|
463
|
+
* - to match a specific attribute with any value:
|
|
464
|
+
*
|
|
465
|
+
* ```ts
|
|
466
|
+
* patterns: [
|
|
467
|
+
* [ 'required', true ]
|
|
468
|
+
* ]
|
|
469
|
+
* ```
|
|
470
|
+
*
|
|
471
|
+
* - to match an attribute name with a RegExp with any value:
|
|
472
|
+
*
|
|
473
|
+
* ```ts
|
|
474
|
+
* patterns: [
|
|
475
|
+
* [ /h[1-6]/, true ]
|
|
476
|
+
* ]
|
|
477
|
+
* ```
|
|
478
|
+
*
|
|
479
|
+
* - to match a specific attribute with the exact value:
|
|
480
|
+
*
|
|
481
|
+
* ```ts
|
|
482
|
+
* patterns: [
|
|
483
|
+
* [ 'rel', 'nofollow' ]
|
|
484
|
+
* ]
|
|
485
|
+
* ```
|
|
486
|
+
*
|
|
487
|
+
* - to match a specific attribute with a value matching a RegExp:
|
|
488
|
+
*
|
|
489
|
+
* ```ts
|
|
490
|
+
* patterns: [
|
|
491
|
+
* [ 'src', /^https/ ]
|
|
492
|
+
* ]
|
|
493
|
+
* ```
|
|
494
|
+
*
|
|
495
|
+
* - to match an attribute name with a RegExp and the exact value:
|
|
496
|
+
*
|
|
497
|
+
* ```ts
|
|
498
|
+
* patterns: [
|
|
499
|
+
* [ /^data-property-/, 'foobar' ],
|
|
500
|
+
* ]
|
|
501
|
+
* ```
|
|
502
|
+
*
|
|
503
|
+
* - to match an attribute name with a RegExp and match a value with another RegExp:
|
|
504
|
+
*
|
|
505
|
+
* ```ts
|
|
506
|
+
* patterns: [
|
|
507
|
+
* [ /^data-property-/, /^foo/ ]
|
|
508
|
+
* ]
|
|
509
|
+
* ```
|
|
510
|
+
*
|
|
511
|
+
* - to match a specific style property with the value matching a RegExp:
|
|
512
|
+
*
|
|
513
|
+
* ```ts
|
|
514
|
+
* patterns: [
|
|
515
|
+
* [ 'style', 'font-size', /px$/ ]
|
|
516
|
+
* ]
|
|
517
|
+
* ```
|
|
518
|
+
*
|
|
519
|
+
* - to match a specific class (class attribute is tokenized so it matches tokens individually):
|
|
520
|
+
*
|
|
521
|
+
* ```ts
|
|
522
|
+
* patterns: [
|
|
523
|
+
* [ 'class', 'foo' ]
|
|
524
|
+
* ]
|
|
525
|
+
* ```
|
|
526
|
+
*
|
|
527
|
+
* @internal
|
|
528
|
+
* @param patterns An array of normalized patterns (tuples of 2 or 3 items depending on if tokenized attribute value match is needed).
|
|
529
|
+
* @param match An array to populate with matching tuples.
|
|
530
|
+
* @param exclude Array of attribute names to exclude from match.
|
|
531
|
+
* @returns `true` if element matches all patterns. The matching tuples are pushed to the `match` array.
|
|
532
|
+
*/
|
|
533
|
+
_collectAttributesMatch(patterns: Array<NormalizedPropertyPattern>, match: Array<[string, string?]>, exclude?: Array<string>): boolean;
|
|
534
|
+
/**
|
|
535
|
+
* Used by the {@link module:engine/conversion/viewconsumable~ViewConsumable} to collect the
|
|
536
|
+
* {@link module:engine/view/element~NormalizedConsumables} for the element.
|
|
537
|
+
*
|
|
538
|
+
* When `key` and `token` parameters are provided the output is filtered for the specified attribute and it's tokens and related tokens.
|
|
539
|
+
*
|
|
540
|
+
* @internal
|
|
541
|
+
* @param key Attribute name.
|
|
542
|
+
* @param token Reference token to collect all related tokens.
|
|
543
|
+
*/
|
|
544
|
+
_getConsumables(key?: string, token?: string): NormalizedConsumables;
|
|
545
|
+
/**
|
|
546
|
+
* Verify if the given element can be merged without conflicts into the element.
|
|
547
|
+
*
|
|
548
|
+
* Note that this method is extended by the {@link module:engine/view/attributeelement~AttributeElement} implementation.
|
|
549
|
+
*
|
|
550
|
+
* This method is used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
551
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
|
|
552
|
+
*
|
|
553
|
+
* @internal
|
|
554
|
+
* @returns Returns `true` if elements can be merged.
|
|
555
|
+
*/
|
|
556
|
+
_canMergeAttributesFrom(otherElement: Element): boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Merges attributes of a given element into the element.
|
|
559
|
+
* This includes also tokenized attributes like style and class.
|
|
560
|
+
*
|
|
561
|
+
* Note that you should make sure there are no conflicts before merging (see {@link #_canMergeAttributesFrom}).
|
|
562
|
+
*
|
|
563
|
+
* This method is used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
564
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
|
|
565
|
+
*
|
|
566
|
+
* @internal
|
|
567
|
+
*/
|
|
568
|
+
_mergeAttributesFrom(otherElement: Element): void;
|
|
569
|
+
/**
|
|
570
|
+
* Verify if the given element attributes can be fully subtracted from the element.
|
|
571
|
+
*
|
|
572
|
+
* Note that this method is extended by the {@link module:engine/view/attributeelement~AttributeElement} implementation.
|
|
573
|
+
*
|
|
574
|
+
* This method is used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
575
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to unwrap the AttributeElement.
|
|
576
|
+
*
|
|
577
|
+
* @internal
|
|
578
|
+
* @returns Returns `true` if elements attributes can be fully subtracted.
|
|
579
|
+
*/
|
|
580
|
+
_canSubtractAttributesOf(otherElement: Element): boolean;
|
|
581
|
+
/**
|
|
582
|
+
* Removes (subtracts) corresponding attributes of the given element from the element.
|
|
583
|
+
* This includes also tokenized attributes like style and class.
|
|
584
|
+
* All attributes, classes and styles from given element should be present inside the element being unwrapped.
|
|
585
|
+
*
|
|
586
|
+
* Note that you should make sure all attributes could be subtracted before subtracting them (see {@link #_canSubtractAttributesOf}).
|
|
587
|
+
*
|
|
588
|
+
* This method is used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
589
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to unwrap the AttributeElement.
|
|
590
|
+
*
|
|
591
|
+
* @internal
|
|
592
|
+
*/
|
|
593
|
+
_subtractAttributesOf(otherElement: Element): void;
|
|
444
594
|
/**
|
|
445
595
|
* Sets a custom property. Unlike attributes, custom properties are not rendered to the DOM,
|
|
446
596
|
* so they can be used to add special data to elements.
|
|
@@ -457,12 +607,154 @@ export default class Element extends Node {
|
|
|
457
607
|
* @returns Returns true if property was removed.
|
|
458
608
|
*/
|
|
459
609
|
_removeCustomProperty(key: string | symbol): boolean;
|
|
610
|
+
/**
|
|
611
|
+
* Parses attributes provided to the element constructor before they are applied to an element. If attributes are passed
|
|
612
|
+
* as an object (instead of `Iterable`), the object is transformed to the map. Attributes with `null` value are removed.
|
|
613
|
+
* Attributes with non-`String` value are converted to `String`.
|
|
614
|
+
*
|
|
615
|
+
* @param attrs Attributes to parse.
|
|
616
|
+
* @returns Parsed attributes.
|
|
617
|
+
*/
|
|
618
|
+
private _parseAttributes;
|
|
460
619
|
/**
|
|
461
620
|
* Returns block {@link module:engine/view/filler filler} offset or `null` if block filler is not needed.
|
|
462
621
|
*/
|
|
463
622
|
getFillerOffset?(): number | null;
|
|
464
623
|
}
|
|
624
|
+
/**
|
|
625
|
+
* Common interface for a {@link module:engine/view/tokenlist~TokenList} and {@link module:engine/view/stylesmap~StylesMap}.
|
|
626
|
+
*/
|
|
627
|
+
export interface ElementAttributeValue {
|
|
628
|
+
/**
|
|
629
|
+
* Returns `true` if attribute has no value set.
|
|
630
|
+
*/
|
|
631
|
+
get isEmpty(): boolean;
|
|
632
|
+
/**
|
|
633
|
+
* Number of tokens (styles, classes or other tokens) defined.
|
|
634
|
+
*/
|
|
635
|
+
get size(): number;
|
|
636
|
+
/**
|
|
637
|
+
* Checks if a given token (style, class, token) is set.
|
|
638
|
+
*/
|
|
639
|
+
has(name: string): boolean;
|
|
640
|
+
/**
|
|
641
|
+
* Returns all tokens (styles, classes, other tokens).
|
|
642
|
+
*/
|
|
643
|
+
keys(): Array<string>;
|
|
644
|
+
/**
|
|
645
|
+
* Resets the value to the given one.
|
|
646
|
+
*/
|
|
647
|
+
setTo(value: string): this;
|
|
648
|
+
/**
|
|
649
|
+
* Sets a given style property and value.
|
|
650
|
+
*/
|
|
651
|
+
set(name: string, value: StyleValue): void;
|
|
652
|
+
/**
|
|
653
|
+
* Sets a given token (for style also a record of properties).
|
|
654
|
+
*/
|
|
655
|
+
set(stylesOrTokens: Styles | ArrayOrItem<string>): void;
|
|
656
|
+
/**
|
|
657
|
+
* Removes given token (style, class, other token).
|
|
658
|
+
*/
|
|
659
|
+
remove(tokens: ArrayOrItem<string>): void;
|
|
660
|
+
/**
|
|
661
|
+
* Removes all tokens.
|
|
662
|
+
*/
|
|
663
|
+
clear(): void;
|
|
664
|
+
/**
|
|
665
|
+
* Returns a normalized tokens string (styles, classes, etc.).
|
|
666
|
+
*/
|
|
667
|
+
toString(): string;
|
|
668
|
+
/**
|
|
669
|
+
* Returns `true` if both attributes have the same content.
|
|
670
|
+
*/
|
|
671
|
+
isSimilar(other: this): boolean;
|
|
672
|
+
/**
|
|
673
|
+
* Clones the attribute value.
|
|
674
|
+
*/
|
|
675
|
+
_clone(): this;
|
|
676
|
+
/**
|
|
677
|
+
* Used by the {@link module:engine/view/matcher~Matcher Matcher} to collect matching attribute tokens.
|
|
678
|
+
*
|
|
679
|
+
* @param tokenPattern The matched token name pattern.
|
|
680
|
+
* @param valuePattern The matched token value pattern.
|
|
681
|
+
* @returns An array of matching tokens.
|
|
682
|
+
*/
|
|
683
|
+
_getTokensMatch(tokenPattern: true | string | RegExp, valuePattern?: true | string | RegExp): Array<string> | undefined;
|
|
684
|
+
/**
|
|
685
|
+
* Returns a list of consumables for the attribute. This includes related tokens
|
|
686
|
+
* (for example other forms of notation of the same style property).
|
|
687
|
+
*
|
|
688
|
+
* Could be filtered by the given token name (class name, style property, etc.).
|
|
689
|
+
*/
|
|
690
|
+
_getConsumables(name?: string): Array<string>;
|
|
691
|
+
/**
|
|
692
|
+
* Used by {@link ~Element#_canMergeAttributesFrom} to verify if the given attribute can be merged without conflicts into the attribute.
|
|
693
|
+
*
|
|
694
|
+
* This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
695
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
|
|
696
|
+
*/
|
|
697
|
+
_canMergeFrom(other: this): boolean;
|
|
698
|
+
/**
|
|
699
|
+
* Used by {@link ~Element#_mergeAttributesFrom} to merge a given attribute into the attribute.
|
|
700
|
+
*
|
|
701
|
+
* This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
702
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to merge it with other AttributeElement.
|
|
703
|
+
*/
|
|
704
|
+
_mergeFrom(other: this): void;
|
|
705
|
+
/**
|
|
706
|
+
* Used by {@link ~Element#_canSubtractAttributesOf} to verify if the given attribute can be fully subtracted from the attribute.
|
|
707
|
+
*
|
|
708
|
+
* This method is indirectly used by the {@link module:engine/view/downcastwriter~DowncastWriter} while down-casting
|
|
709
|
+
* an {@link module:engine/view/attributeelement~AttributeElement} to unwrap the AttributeElement.
|
|
710
|
+
*/
|
|
711
|
+
_isMatching(other: this): boolean;
|
|
712
|
+
}
|
|
465
713
|
/**
|
|
466
714
|
* Collection of attributes.
|
|
467
715
|
*/
|
|
468
716
|
export type ElementAttributes = Record<string, unknown> | Iterable<[string, unknown]> | null;
|
|
717
|
+
/**
|
|
718
|
+
* Object describing all features of a view element that could be consumed and converted individually.
|
|
719
|
+
* This is a normalized form of {@link module:engine/conversion/viewconsumable~Consumables} generated from the view Element.
|
|
720
|
+
*
|
|
721
|
+
* Example element:
|
|
722
|
+
*
|
|
723
|
+
* ```html
|
|
724
|
+
* <a class="foo bar" style="color: red; margin: 5px" href="https://ckeditor.com" rel="nofollow noreferrer" target="_blank">
|
|
725
|
+
* ```
|
|
726
|
+
*
|
|
727
|
+
* The `NormalizedConsumables` would include:
|
|
728
|
+
*
|
|
729
|
+
* ```json
|
|
730
|
+
* {
|
|
731
|
+
* name: true,
|
|
732
|
+
* attributes: [
|
|
733
|
+
* [ "class", "foo" ],
|
|
734
|
+
* [ "class", "bar" ],
|
|
735
|
+
* [ "style", "color" ],
|
|
736
|
+
* [ "style", "margin-top" ],
|
|
737
|
+
* [ "style", "margin-right" ],
|
|
738
|
+
* [ "style", "margin-bottom" ],
|
|
739
|
+
* [ "style", "margin-left" ],
|
|
740
|
+
[ "style", "margin" ],
|
|
741
|
+
* [ "href" ],
|
|
742
|
+
* [ "rel", "nofollow" ],
|
|
743
|
+
* [ "rel", "noreferrer" ],
|
|
744
|
+
* [ "target" ]
|
|
745
|
+
* ]
|
|
746
|
+
* }
|
|
747
|
+
* ```
|
|
748
|
+
*/
|
|
749
|
+
export interface NormalizedConsumables {
|
|
750
|
+
/**
|
|
751
|
+
* If set to `true` element's name will be included in a consumable.
|
|
752
|
+
* Depending on the usage context it would be added as consumable, tested for being available for consume or consumed.
|
|
753
|
+
*/
|
|
754
|
+
name: boolean;
|
|
755
|
+
/**
|
|
756
|
+
* Array of tuples - an attribute name, and optional token for tokenized attributes.
|
|
757
|
+
* Note that there could be multiple entries for the same attribute with different tokens (class names or style properties).
|
|
758
|
+
*/
|
|
759
|
+
attributes: Array<[string, string?]>;
|
|
760
|
+
}
|