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

feat(coremedia-richtext): TSdoc and allowEmpty (XLink) #201

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

mmichaelis
Copy link
Member

@mmichaelis mmichaelis commented Jan 9, 2025

Adds TSdoc and a new feature to setXLinkAttributes in XLink tooling.

allowEmpty is required to be true if, for example, you need to explicitly set a value for a required attribute and it must not be skipped (such as an <a> which aways requires xlink:href to comply with CoreMedia Rich Text DTD 1.0.

To not break existing usages, allowEmpty must default to false.

Decide on breaking change:

As additional part of this PR, also decided to align the behavior of setXLinkDataSetEntries
with setXLinkAttributes, thus, to (by default) drop attributes with empty values. While this
is aligned with the DevNote that existed before, this has to be considered a breaking change.

Usages that rely on "empty values" to be accepted, need to explicitly add allowEmpty = true to the call.

The defensive option would be to set the default to true for this method, but this again makes it harder to "learn the API by heart" due to the difference of setXLinkAttributes.

As an alternative to this, perhaps even the better one, is to make allowEmpty default to true for both. For a newly developed API, this would be my recommendation as "stripping given (empty) values" is more of a convenience behavior that spares some extra lines to filter the attributes before handing them over to the API.

This again, would of course also be breaking, but this time for setXLinkAttributes.

Adds TSdoc and a new feature to `setXLinkAttributes` in `XLink`
tooling.

`allowEmpty` is required to be `true` if, for example, you need
to explicitly set a value for a required attribute and it must not
be skipped (such as an `<a>` which aways requires `xlink:href`
to comply with CoreMedia Rich Text DTD 1.0.

To not break existing usages, `allowEmpty` must default to
`false`.
…inkAttributes`

As `setXLinkAttributes` and `setXLinkDataSetEntries` are kind of
meant to "work as a pair", both should provide a comparable
experience.

* Added `allowEmpty` as just done for `setXLinkAttributes`.
* Added TSdoc for the method

Note, that this is a breaking change, as, different from which the
line-comment suggested, this method did not ignore empty
values. Now it does (by default).

All usages should be reviewed and possibly adapted.

BREAKING CHANGE: `setXLinkDataSetEntries` now by default ignores entries with empty values.
The system test _Should correctly render broken image with empty src_ fails.

This is (most likely) due to the breaking API change of
`setXLinkDataSetEntries`. To grant the old behavior, adding
`allowEmpty = true` to the call.
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`.
Now that `allowEmpty` defaults to `true`, there is no need anymore
to adapt `ImageElements.ts`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant