WICG / scroll-to-text-fragment

Proposal to allow specifying a text snippet in a URL fragment
Other
589 stars 42 forks source link

Explainer for FragmentDirective API #175

Closed bokand closed 2 years ago

bokand commented 2 years ago

Also +@tomayac - would value your thoughts if you have some time to look this over.

bokand commented 2 years ago

Thanks Thomas!

I believe the IDL needs to state where it's exposed (document).

You're right, though it's [Exposed=Window] since Exposed works on a global object. FragmentDirective is already spec'ed in our draft spec as being a member of Document - I added the existing IDL here for clarity. Maybe it'd make sense to also expose TextDirective and related on Worker as well? getMatchingRange couldn't work but the attributes might be useful? Thoughts?

There's some redundancy of repeating the directive name text= when the type is known (new TextDirective("text=foo") vs. a hypothetical simpler new TextDirective("foo")), but I think that's fine.

Good catch, I have a mix of both styles here - I agree the latter is more ergonomic so I changed the examples to that.

It might be useful to have a Directive.parse(DOMString) that just returns a list of Directive objects of the right type (e.g. so you could do Directive.parse("text=foo&note(href=example.com)&selector(...)") and get back 3 Directive objects) but I'm weary of adding too many bells and whistles before we know how it'll be used.

bokand commented 2 years ago

@flackr please also take a look

bokand commented 2 years ago

@flackr Since I'll be out for the next 6 weeks I'm going to merge the latest changes so I have something to point to in the intent to prototype but feel free to make changes while I'm gone if you have any.