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

Move to Svelte 4 style custom element API, support prop type coercion #13

Open
8 tasks
patricknelson opened this issue Jun 22, 2023 · 2 comments
Open
8 tasks
Labels
enhancement New feature or request
Milestone

Comments

@patricknelson
Copy link
Owner

patricknelson commented Jun 22, 2023

Svelte 4.0.0 has been released: https://svelte.dev/blog/svelte-4.

Work can now be done to align svelte-retag's API to the new format in Svelte 4's <svelte:options customElement={…} /> (documented here). For example (copied from sveltejs/svelte#8681 (comment)):

// String syntax:
svelteRetag(component, 'example-element');

// Object syntax:
svelteRetag(component, {
	tag: 'example-element',
	shadow: 'none',
	props: {
		greetPerson: { reflect: true, attribute: 'greet-person' },
	},
});

Propose passing in the component as the first required parameter and then allow for an easy direct copy/paste of the Svelte 4 style customElement options as a second parameter (with the same baseline requirements). This will be supported features only.

Important: Rolling into v2 milestone., since this syntax should replace the old component definition syntax. Doing so should make the API of svelte-retag overall easier to comprehend for others (a huge plus for a library). Plus it’s likely easier to implement/maintain.

Supported features

Due to the complexity of the API (at time of writing) it may be worthwhile to outline exactly what we want as “must have” vs. “nice to have” if possible in this ticket. Otherwise, implement the “must haves” and delegate the “nice to have” features to a separate issue for now.

Must have

  • tag for tag name
  • shadow for use of shadow DOM or not (must default to true, methinks)
  • props where each key defines the property (e.g. greetName) with support for
    • attribute defines alternative attribute name
    • type to coerce to a particular type (instead of always being type String (per HTML attribute spec)

Nice to have

@patricknelson patricknelson added the enhancement New feature or request label Jul 12, 2023
@patricknelson
Copy link
Owner Author

Added explicit set of desired features in order of priority (must have vs. nice to have) to help explicitly call out desire to perform type coercion (as requested in #26 which is a dupe of this).

@patricknelson patricknelson added this to the v2 milestone Nov 28, 2023
@patricknelson patricknelson changed the title Support Svelte 4 custom element API Move to Svelte 4 style custom element API Dec 3, 2023
@patricknelson
Copy link
Owner Author

Quick note: Clarified that this will be for supported features only, i.e. either features that already exist or ones being added specifically in this ticket (e.g. custom attribute names and attribute type coercion).

This is worth calling out so that the expectation isn't set that we'll always 100% support all features of <svelte:options customElement={…} /> per se, but rather have an API that is very similar in order to support migration. This is not intended to be a drop-in but instead an alternative with the ability to enhance with additional features, where feasible. 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant