From d641b41c9e03fd3b255c167ecd84db9ecee69dd9 Mon Sep 17 00:00:00 2001 From: Mark Michaelis Date: Thu, 9 Jan 2025 09:34:03 +0100 Subject: [PATCH] refactor(coremedia-richtext)! Redecide on `allowEmpty` default 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 `` and ``). 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`. --- .../ckeditor5-coremedia-richtext/src/rules/XLink.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/ckeditor5-coremedia-richtext/src/rules/XLink.ts b/packages/ckeditor5-coremedia-richtext/src/rules/XLink.ts index 4fa5efac41..e041d33d2f 100644 --- a/packages/ckeditor5-coremedia-richtext/src/rules/XLink.ts +++ b/packages/ckeditor5-coremedia-richtext/src/rules/XLink.ts @@ -72,7 +72,7 @@ export const extractXLinkDataSetEntries = (element: HTMLElement): XLinkAttribute * * ```typescript * setXLinkAttributes(element, { - * // empty: Ignored by default. + * // empty: Ignored, if allowEmpty=false * "title": "", * "href": "https://example.org/" * }); @@ -80,9 +80,9 @@ export const extractXLinkDataSetEntries = (element: HTMLElement): XLinkAttribute * * @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)) { @@ -110,7 +110,7 @@ export const setXLinkAttributes = (element: Element, attributes: XLinkAttributes * * ```typescript * setXLinkDataSetEntries(element, { - * // empty: Ignored by default. + * // empty: Ignored, if allowEmpty=false * "title": "", * "href": "https://example.org/" * }); @@ -118,9 +118,9 @@ export const setXLinkAttributes = (element: Element, attributes: XLinkAttributes * * @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)}`;