commit 41969f2b241cf0c29055b7472e44585ef00fc99e
parent 1148b0f5d6582131f8c11b060af5bd1f9df2d1df
Author: typable <contact@typable.dev>
Date: Sat, 1 Jul 2023 23:10:47 +0200
fix: Added support for all events
Diffstat:
M | lib.js | | | 97 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- |
1 file changed, 93 insertions(+), 4 deletions(-)
diff --git a/lib.js b/lib.js
@@ -17,6 +17,89 @@
* @typedef {ReactCreateFunction} DynFunction
*/
+const EVENTS = [
+ 'onCopy',
+ 'onCut',
+ 'onPaste',
+ 'onCompositionEnd',
+ 'onCompositionStart',
+ 'onCompositionUpdate',
+ 'onKeyDown',
+ 'onKeyPress',
+ 'onKeyUp',
+ 'onFocus',
+ 'onBlur',
+ 'onChange',
+ 'onInput',
+ 'onInvalid',
+ 'onReset',
+ 'onSubmit',
+ 'onError',
+ 'onLoad',
+ 'onClick',
+ 'onContextMenu',
+ 'onDoubleClick',
+ 'onDrag',
+ 'onDragEnd',
+ 'onDragEnter',
+ 'onDragExit',
+ 'onDragLeave',
+ 'onDragOver',
+ 'onDragStart',
+ 'onDrop',
+ 'onMouseDown',
+ 'onMouseEnter',
+ 'onMouseLeave',
+ 'onMouseMove',
+ 'onMouseOut',
+ 'onMouseOver',
+ 'onMouseUp',
+ 'onPointerDown',
+ 'onPointerMove',
+ 'onPointerUp',
+ 'onPointerCancel',
+ 'onGotPointerCapture',
+ 'onLostPointerCapture',
+ 'onPointerEnter',
+ 'onPointerLeave',
+ 'onPointerOver',
+ 'onPointerOut',
+ 'onSelect',
+ 'onTouchCancel',
+ 'onTouchEnd',
+ 'onTouchMove',
+ 'onTouchStart',
+ 'onScroll',
+ 'onWheel',
+ 'onAbort',
+ 'onCanPlay',
+ 'onCanPlayThrough',
+ 'onDurationChange',
+ 'onEmptied',
+ 'onEncrypted',
+ 'onEnded',
+ 'onLoadedData',
+ 'onLoadedMetadata',
+ 'onLoadStart',
+ 'onPause',
+ 'onPlay',
+ 'onPlaying',
+ 'onProgress',
+ 'onRateChange',
+ 'onSeeked',
+ 'onSeeking',
+ 'onStalled',
+ 'onSuspend',
+ 'onTimeUpdate',
+ 'onVolumeChange',
+ 'onWaiting',
+ 'onAnimationStart',
+ 'onAnimationEnd',
+ 'onAnimationIteration',
+ 'onTransitionEnd',
+ 'onToggle',
+];
+
/**
* Initializes the figure framework.
*
@@ -160,11 +243,17 @@ export default function figure(create) {
const values = feed(slice, refs);
const value = values.length == 1 ? values[0] : values;
let attr = key;
- const match = /^(\w+):(\w+)$/.exec(attr);
- if (match) {
+ const eventMatch = /^(\w+):(\w+)$/.exec(attr);
+ if (eventMatch) {
// camel case attribute name
- const [, pre, name] = match;
- attr = `${pre}${name.substring(0, 1).toUpperCase()}${name.substring(1)}`;
+ const [, pre, name] = eventMatch;
+ for (const event of EVENTS) {
+ // find matching event name
+ if (`${pre}${name}` === event.toLowerCase()) {
+ attr = event;
+ break;
+ }
+ }
}
props[attr] = value instanceof Array ? value.join('') : value;
}