Skip to content

Commit

Permalink
refactor(coremedia-richtext)! Redecide on allowEmpty default
Browse files Browse the repository at this point in the history
In many use-cases it makes more sense not to ignore empty
values for XLink entries. Such as for attributes that are required
(`xlink:href` for `<a>` and `<img>`).

This reverts the previous decision to "break" the API of
`setXLinkDataSetEntries`. Instead, the breaking change now
applies to `setXLinkAttributes`.

Still, the goal is, to keep both aligned.

`allowEmpty = true` as default is also considered "more harmless"
as the result is less surprising, if you invoke this API. If empty
values are ignored, you may be surprised, if you did not read the
TSdoc (or code) before.

BREAKING CHANGE: `setXLinkAttributes` may need to set `allowEmpty = true` explicitly. Reverting previous breaking change for `setXLinkDataSetEntries`.
  • Loading branch information
mmichaelis authored Jan 9, 2025
1 parent 754c369 commit d641b41
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions packages/ckeditor5-coremedia-richtext/src/rules/XLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,17 +72,17 @@ export const extractXLinkDataSetEntries = (element: HTMLElement): XLinkAttribute
*
* ```typescript
* setXLinkAttributes(element, {
* // empty: Ignored by default.
* // empty: Ignored, if allowEmpty=false
* "title": "",
* "href": "https://example.org/"
* });
* ```
*
* @param element - the elemant to set the attributes at
* @param attributes - the key-value pairs of attributes to set
* @param allowEmpty - if to ignore entries with empty values or not
* @param allowEmpty - if to ignore entries with empty values or not; default: `true`
*/
export const setXLinkAttributes = (element: Element, attributes: XLinkAttributes, allowEmpty = false): void => {
export const setXLinkAttributes = (element: Element, attributes: XLinkAttributes, allowEmpty = true): void => {
const { ownerDocument } = element;
Object.entries(attributes).forEach(([key, value]: [XLinkAttributeKey, string | undefined]) => {
if (typeof value === "string" && (value || allowEmpty)) {
Expand Down Expand Up @@ -110,17 +110,17 @@ export const setXLinkAttributes = (element: Element, attributes: XLinkAttributes
*
* ```typescript
* setXLinkDataSetEntries(element, {
* // empty: Ignored by default.
* // empty: Ignored, if allowEmpty=false
* "title": "",
* "href": "https://example.org/"
* });
* ```
*
* @param element - the elemant to set the attributes at
* @param attributes - the key-value pairs of attributes to set
* @param allowEmpty - if to ignore entries with empty values or not
* @param allowEmpty - if to ignore entries with empty values or not; default: `true`
*/
export const setXLinkDataSetEntries = (element: HTMLElement, attributes: XLinkAttributes, allowEmpty = false): void => {
export const setXLinkDataSetEntries = (element: HTMLElement, attributes: XLinkAttributes, allowEmpty = true): void => {
Object.entries(attributes).forEach(([localName, value]: [XLinkAttributeKey, string | undefined]) => {
if (typeof value === "string" && (value || allowEmpty)) {
const key: XLinkAttributeDataSetKey = `${xLinkPrefix}${capitalize(localName)}`;
Expand Down

0 comments on commit d641b41

Please sign in to comment.