-
-
Notifications
You must be signed in to change notification settings - Fork 57
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
API Design #135
API Design #135
Conversation
I like where this is headed. I'd be in favor of proposal 3 for a couple reasons.
There are some things that feel intuitive to me about these changes though.
Ok. That's all I've got! |
@mattmcmanus Thanks for the excellent feedback:
I looked into mousetrap and keymaster to see how they handled key vs code and whether we could/should use them. In both cases, I found that they rely on now-deprecated keyboard event properties (
Good point, or maybe
If we do this, we lose the ability to attach additional shortcuts to one action by adding key combo strings as additional arguments. I think that flexibility is worth it, but absent that I agree the order would read better flipped.
I think
It triggers a click on the element it is attached to. I'll update the doc to clarify this.
I can see what it would be confusing. The difference between the two is that the component listens and is triggerable whenever it is rendered while the modifier only triggers when the element is focused. I think we need both, though they don't necessarily need to be named the same thing.
It's not in this API document currently, but ember-keyboard has a bunch of existing support for managing priority and propagation that I think we would want to preserve as-is. |
@lukemelia Have you publically shared this on Discord and Twitter? Maybe others can chime in :) |
@Alonski Yes, I have. If you can help amplify, that would be great: https://twitter.com/lukemelia/status/1256439569181900800 |
Just to chime in, I'm also a fan of proposal 3. I wonder though if
+1 to I’m a big fan of aligning with native terminology whenever possible, but in this case something like
I didn't find
I also think flipped order would be ideal... Not only does it feel more natural, it’s also a pattern users are familiar with because the
It’s a bummer that there’s no other solid JS keyboard libraries out there that could be leveraged. Mousetrap has always been my favorite but it’s definitely outdated and neglected. Hotkeys (a continuation of Keymaster) seems to be the only one actively maintained, but it still uses |
@seanCodes That's some excellent feedback!
I really like this idea. I just checked the list of I am going to update the document to take this approach.
OK, I find your and @mattmcmanus' feedback persuasive on this. I'll update.
This is a good point. I will update to align to the style of the
Seriously. I think it's probably due to IE 11 not supporting these APIs, but still -- it's surprising.
Please do implement. ;-) |
I've incorporated feedback from @mattmcmanus and @seanCodes into Proposal 4, which is my new favorite. It has one not-yet-discussed idea in it as well, which is to use the same |
@lukemelia @seanCodes Love it! Proposal 4 feels so much more ergonomic and intuitive. Now my questions are:
|
I very much like proposal 4, but have one suggestion that I think is relatively minor in terms of the work/implementation, but would make it quite a bit more flexible. I think that the core key-mapping engine that takes DOM events and recognizes key patterns should be exposed independently of the DOM event handling, since I think that's the core value that this would be providing. So in a template, it would allow something like {{!-- attach your own event handler using the {{on}} modifier --}}
<div {{on "keypress" (dispatch-key "alt+c" this.doThing)}}></div>
{{! use ember-on-helper }}
{{on-document "keydown" (dispatch-key "alt+x" this.doThing)}}
{{! use some third-party component API }}
<SomeComponent @onKey={{dispatch-key "alt+x" this.doThing}}/> and in Javascript maybe function onEvent(e) {
if (keyEventMatches(e, 'alt+x')) {
this.handleAltX();
}
} Absolutely still provide the higher-level API you've specified as the primary API for the addon, but also expose these lower-level primitives so if you don't anticipate some particular pattern for capturing DOM events, it's not a blocker and user can still leverage the harder-to-duplicate DOM-event parsing logic. |
@mattmcmanus wrote:
Registered key handlers would be available via the the keyboard service, but I think it is likely that an interface like you've described would be maintained independently. Things like order, layout and a description of each key combos function would be impossible to standardize in a one-size-fits-most way. @mattmcmanus wrote:
True. This could be a cool future enhancement. @mattmcmanus wrote:
I don't think so. The issue that prompted this rethink was that we were conceptually mixing @bendemboski wrote:
I like this idea a lot. It would also help us ensure this part of the codebase is well-isolated and can be covered by a thorough test suite. This low-level API would by necessity not participate in other ember-keyboard features like priority and propagation options but that doesn't obviate its utility. I think I would find |
Sure, makes sense. I called it |
Chiming in here super late, sorry everyone. Had gotten pulled away from my upgrade which included this PR. I'm a big fan of the evolution to Proposal 4. However I think I prefer the I think it comes down to documentation at this point. "alt+c" and "alt+KeyC" aren't immediately obvious. Given just these you really don't know for sure what the difference between "alt+c" and "alt+KeyC" is. Users will need to go read the docs and discover what it means. However, It's really down to "how much magic" do we want here |
@optikalefx wrote:
My thinking is that |
I think it's definitely good to consider this question, but I'm still finding myself in favor of not having the mode argument. Let's think about how users are going to first encounter this. If they read the documentation first because they are trying to start using the addon, then no problem - the documentation can be made clear. If they encounter a usage of it in the wild, there are two possible cases:
In case 1, having an extra In case 2 having I think case 1 is going to be the much more common case, so given that the advantages |
@bendemboski Great breakdown and scenario gaming. 👍 |
Last call for comments. I think we arrived at a great plan and I intend to start implementing it soon and see what happens when the plan collides with reality! |
Implementation has begun. I've added a checklist to the description of this PR. If anyone wants to contribute, or to pair on any of this, let me know! |
51491a9
to
5bbba43
Compare
- In the future, once we have good alternatives, I expect all of this addon's mixins to be deprecated and removed, but for now this will let it execute without triggering deprecation warnings.
- can be used any place a function that received a KeyboardEvent would be used - does not participate in the wider ember-keyboard functionality (responders, priority, etc), but can be useful if you just want to leverage the key combo matching code of this addon
'_all' matches any keystroke. 'ctrl+_all' matches any keystroke with ctrl held down, etc.
- Translates to `meta` on Mac and `ctrl` on other platforms.
…API-DESIGN.md suitable for future use in an upgrade guide.
…lint,eslint-*, markdown-code-highlighting, qunit-dom
- Moved deprecations to their own page - Removed mixins documentation - Added deprecations warnings to each mixin and added documentation entries on how to migrate away from each one - Updated API Design doc to reflect changes in decorator API - Added support for mouse and touch events to new API to match capabilties of previous API
- also switch to `auto` location
OK, I think we are good to go for a new beta. I'll leave this for a day or two before I merge in case anyone wants to do some more code review. |
Just upgraded emberclear to v6. Nice work everyone! :D |
@NullVoxPopuli Great to hear! 👍 |
Rendered
We're implementing in this PR as well. Here's the check list:
on-keyboard
modifierkeyboard-shortcut
modifierkeyboard-press
componenthas
/trigger
via Evented mixin) that leveragesisKey
functionisKey
function d50035cstopPropagation
/stopImmediatePropagation
fromon-key
helperstopPropagation
/stopImmediatePropagation
fromon-key
modifierif-key
helper_all
support inisKey
functionkey
mapping support inisKey
functionon-key
helper being a function