Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The link rel attribute should be handled as a token list to allow mixing manual link decorators for the same attribute #17461

Open
wants to merge 61 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
cdf9b8d
Refactoring of view styles and classes to more generic solution.
niegowski Nov 4, 2024
5e6a334
Fixed unwrapping.
niegowski Nov 5, 2024
5310c3f
Updated tests.
niegowski Nov 5, 2024
8cd520d
Added fast-access private properties.
niegowski Nov 5, 2024
60c7c58
Fixed tests.
niegowski Nov 5, 2024
3daf3b3
Merge branch 'refs/heads/master' into ck/13985
niegowski Nov 6, 2024
1b142c1
Using getter for easier usage and marginal performance difference.
niegowski Nov 6, 2024
6437f0e
Bring back original method signature.
niegowski Nov 6, 2024
9685665
Merge branch 'refs/heads/master' into ck/13985
niegowski Nov 6, 2024
a7ac306
Unified setAttribute for both tokenized, styles map and plain string …
niegowski Nov 8, 2024
cc84584
Reduced usage of addClass, removeClass, addStyle, removeStyle in Down…
niegowski Nov 8, 2024
f2b5543
Wrap/unwrap AttributeElement delegated to the view Elements.
niegowski Nov 13, 2024
4665f8f
Added tests.
niegowski Nov 13, 2024
7d04816
Added hasAttribute with expected value handling.
niegowski Nov 14, 2024
ece3d94
Fixed mention upcast conversion (all attributes must be consumed).
niegowski Nov 14, 2024
72c6449
Removed not used property from type declaration.
niegowski Nov 14, 2024
6ffcbb7
Part of the Matcher internal logic split into the view Element.
niegowski Nov 14, 2024
dd0b292
Code simplification.
niegowski Nov 15, 2024
47af99d
WiP.
niegowski Nov 15, 2024
ad48a11
Adjusting matcher logic.
niegowski Nov 18, 2024
6cae667
Fixed failing tests.
niegowski Nov 19, 2024
a2e01fe
Unified pattern match check.
niegowski Nov 19, 2024
419cc23
Added test for attribute name match without a value match.
niegowski Nov 19, 2024
467d497
Split matching back to helpers.
niegowski Nov 20, 2024
8afae7f
Added tests for backward compatibility and fixed pattern normalizatio…
niegowski Nov 20, 2024
b56d2ae
Removed de-dup.
niegowski Nov 20, 2024
a3a9f33
Merge branch 'master' into ck/13985
niegowski Nov 22, 2024
e111c07
Merge branch 'master' into ck/13985
niegowski Nov 26, 2024
9f6eea0
Merge branch 'master' into ck/13985
niegowski Dec 5, 2024
3c92676
The ViewConsumable should not be aware how to handle different kinds …
niegowski Dec 6, 2024
a09ee9e
Updated GHS to the new matcher output format.
niegowski Dec 6, 2024
cca2cd6
Normalized output of MatcherFunctionPattern match.
niegowski Dec 6, 2024
e80aa7f
Updated MatcherFunctionPattern handling so it accepts boolean return …
niegowski Dec 6, 2024
8aa73c1
Delegated consuming of related styles.
niegowski Dec 9, 2024
3dde209
Update test.
niegowski Dec 9, 2024
fb4c515
Reorder methods.
niegowski Dec 9, 2024
9feeacb
Simplified collecting of matching attributes.
niegowski Dec 9, 2024
36c3a98
Avoid double normalization.
niegowski Dec 9, 2024
3119882
Code cleaning.
niegowski Dec 9, 2024
ff24ea0
Code cleaning.
niegowski Dec 10, 2024
1e719ef
Empty style and class attribute should be possible.
niegowski Dec 10, 2024
0d3328e
Updating docs.
niegowski Dec 10, 2024
775c7b7
Updating docs.
niegowski Dec 10, 2024
40b2075
Added iterator to getClassNames() for backward compatibility.
niegowski Dec 11, 2024
4d7d7a2
Updating docs.
niegowski Dec 11, 2024
261c526
Merge branch 'master' into ck/13985
niegowski Dec 12, 2024
d2d5aac
Added tests.
niegowski Dec 13, 2024
be6969a
Added tests.
niegowski Dec 16, 2024
d210c85
Added tests.
niegowski Dec 16, 2024
dd9f070
Added tests.
niegowski Dec 16, 2024
17c67ab
Added tests.
niegowski Dec 16, 2024
d671264
Merge branch 'master' into ck/13985
niegowski Dec 16, 2024
08e7d87
Fix doclet.
niegowski Dec 17, 2024
0c4253d
Apply suggestions from code review.
niegowski Jan 9, 2025
9873c87
Review fixes.
niegowski Jan 23, 2025
690516b
Merge branch 'master' into ck/13985
niegowski Jan 23, 2025
239aeae
Review fixes.
niegowski Jan 23, 2025
cbda4b6
Review fixes.
niegowski Jan 23, 2025
1662805
Updated API docs.
niegowski Jan 24, 2025
ac149a9
Updated API docs.
niegowski Jan 24, 2025
5a170c4
Updated API docs.
niegowski Jan 24, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Split matching back to helpers.
niegowski committed Nov 20, 2024
commit 467d497fd5a357657fa875f962fda788baf2942c
84 changes: 60 additions & 24 deletions packages/ckeditor5-engine/src/view/matcher.ts
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
import type Element from './element.js';

import { logWarning } from '@ckeditor/ckeditor5-utils';
import { isPlainObject } from 'lodash-es';

/**
* View matcher class.
@@ -182,24 +181,7 @@ export default class Matcher {

// Check element's attributes.
if ( pattern.attributes ) {
let excludeAttributes;

// The `style` and `class` attribute keys are deprecated. Only allow them in object pattern
// for backward compatibility.
if ( isPlainObject( pattern.attributes ) ) {
if ( ( pattern.attributes as any ).style !== undefined ) {
// Documented at the end of matcher.js.
logWarning( 'matcher-pattern-deprecated-attributes-style-key', pattern.attributes as any );
}
if ( ( pattern.attributes as any ).class !== undefined ) {
// Documented at the end of matcher.js.
logWarning( 'matcher-pattern-deprecated-attributes-class-key', pattern.attributes as any );
}
} else {
excludeAttributes = [ 'class', 'style' ];
}

const attributesMatch = element._getAttributesMatch( normalizePatterns( pattern.attributes ), excludeAttributes );
const attributesMatch = matchAttributes( pattern.attributes, element );

if ( attributesMatch ) {
// TODO temporary
@@ -211,8 +193,7 @@ export default class Matcher {

// Check element's classes.
if ( pattern.classes ) {
const normalizedPatterns = normalizePatterns( pattern.classes, 'class' );
const classesMatch = element._getAttributesMatch( normalizedPatterns ) as Array<[ string, string ]> | undefined;
const classesMatch = matchClasses( pattern.classes, element );

if ( classesMatch ) {
// TODO temporary
@@ -224,8 +205,7 @@ export default class Matcher {

// Check element's styles.
if ( pattern.styles ) {
const normalizedPatterns = normalizePatterns( pattern.styles, 'style' );
const stylesMatch = element._getAttributesMatch( normalizedPatterns ) as Array<[ string, string ]> | undefined;
const stylesMatch = matchStyles( pattern.styles, element );

if ( stylesMatch ) {
// TODO temporary
@@ -337,7 +317,7 @@ function matchName( pattern: string | RegExp, name: string ): boolean {
function normalizePatterns( patterns: PropertyPatterns, prefix?: string ): Array<NormalizedPropertyPattern> {
if ( Array.isArray( patterns ) ) {
return patterns.map( pattern => {
if ( typeof pattern !== 'object' || pattern instanceof RegExp ) {
if ( typeof pattern === 'string' || pattern instanceof RegExp ) {
return prefix ?
[ prefix, pattern, true ] :
[ pattern, true ];
@@ -366,6 +346,7 @@ function normalizePatterns( patterns: PropertyPatterns, prefix?: string ): Array
const normalizedPatterns: Array<NormalizedPropertyPattern> = [];

for ( const key in patterns ) {
// Replace with Object.hasOwn() when we upgrade to es2022.
if ( Object.prototype.hasOwnProperty.call( patterns, key ) ) {
normalizedPatterns.push(
prefix ?
@@ -378,6 +359,61 @@ function normalizePatterns( patterns: PropertyPatterns, prefix?: string ): Array
return normalizedPatterns;
}

/**
* Checks if attributes of provided element can be matched against provided patterns.
*
* @param patterns Object with information about attributes to match. Each key of the object will be
* used as attribute name. Value of each key can be a string or regular expression to match against attribute value.
* @param element Element which attributes will be tested.
* @returns Returns array with matched attribute names or `null` if no attributes were matched.
*/
function matchAttributes(
patterns: AttributePatterns,
element: Element
): Array<[ string, string? ]> | undefined {
let excludeAttributes;

// `style` and `class` attribute keys are deprecated. Only allow them in object pattern
// for backward compatibility.
if ( typeof patterns === 'object' && !( patterns instanceof RegExp ) && !Array.isArray( patterns ) ) {
if ( patterns.style !== undefined ) {
// Documented at the end of matcher.js.
logWarning( 'matcher-pattern-deprecated-attributes-style-key', patterns );
}
if ( patterns.class !== undefined ) {
// Documented at the end of matcher.js.
logWarning( 'matcher-pattern-deprecated-attributes-class-key', patterns );
}
} else {
excludeAttributes = [ 'class', 'style' ];
}

return element._getAttributesMatch( normalizePatterns( patterns ), excludeAttributes );
}

/**
* Checks if classes of provided element can be matched against provided patterns.
*
* @param patterns Array of strings or regular expressions to match against element's classes.
* @param element Element which classes will be tested.
* @returns Returns array with matched class names or `null` if no classes were matched.
*/
function matchClasses( patterns: ClassPatterns, element: Element ): Array<[ string, string ]> | undefined {
return element._getAttributesMatch( normalizePatterns( patterns, 'class' ) ) as Array<[ string, string ]> | undefined;
}

/**
* Checks if styles of provided element can be matched against provided patterns.
*
* @param patterns Object with information about styles to match. Each key of the object will be
* used as style name. Value of each key can be a string or regular expression to match against style value.
* @param element Element which styles will be tested.
* @returns Returns array with matched style names or `null` if no styles were matched.
*/
function matchStyles( patterns: StylePatterns, element: Element ): Array<[ string, string ]> | undefined {
return element._getAttributesMatch( normalizePatterns( patterns, 'style' ) ) as Array<[ string, string ]> | undefined;
}

/**
* An entity that is a valid pattern recognized by a matcher. `MatcherPattern` is used by {@link ~Matcher} to recognize
* if a view element fits in a group of view elements described by the pattern.