mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 05:09:38 +02:00
* Add Lucide gem (#364) * feat: add cursor pointer in the log-in and create account pages, also make full with (it's cutted right now) the fileds in the settings edit page * feat: skip system test with an explanation instead of comment them * fix typo in the skip * feat: add lucide gem * Add reusable modal (#362) * Remove unused form * Add reusable modal * Prelim styling * Add instructions --------- Co-authored-by: Josh Pigford <josh@joshpigford.com> * Add keyboard navigation to new account selector (#375) * New account menu (#372) * New account menu * Styling tweaks --------- Signed-off-by: Josh Pigford <josh@joshpigford.com> * Entry method links (#376) * Initial add account form (#378) * Initial add account form * Unused --------- Signed-off-by: Josh Pigford <josh@joshpigford.com> Co-authored-by: Pedro López Mareque <Pedro.lopez.mareque@gmail.com> Co-authored-by: Rob Zolkos <rob@zolkos.com> Co-authored-by: Josh Brown <josh@joossh.com>
2 lines
5.5 KiB
JavaScript
2 lines
5.5 KiB
JavaScript
class Leaf{constructor(e){this.children=[];this.parent=e}delete(e){const t=this.children.indexOf(e);if(t===-1)return false;this.children=this.children.slice(0,t).concat(this.children.slice(t+1));this.children.length===0&&this.parent.delete(this);return true}add(e){this.children.push(e);return this}}class RadixTrie{constructor(e){this.parent=null;this.children={};this.parent=e||null}get(e){return this.children[e]}insert(e){let t=this;for(let n=0;n<e.length;n+=1){const i=e[n];let r=t.get(i);if(n===e.length-1){if(r instanceof RadixTrie){t.delete(r);r=null}if(!r){r=new Leaf(t);t.children[i]=r}return r}r instanceof Leaf&&(r=null);if(!r){r=new RadixTrie(t);t.children[i]=r}t=r}return t}delete(e){for(const t in this.children){const n=this.children[t];if(n===e){const e=delete this.children[t];Object.keys(this.children).length===0&&this.parent&&this.parent.delete(this);return e}}return false}}const e={"¡":"1","™":"2","£":"3","¢":"4","∞":"5","§":"6","¶":"7","•":"8","ª":"9","º":"0","–":"-","≠":"=","⁄":"!","€":"@","‹":"#","›":"$","fi":"%","fl":"^","‡":"&","°":"*","·":"(","‚":")","—":"_","±":"+","œ":"q","∑":"w","®":"r","†":"t","¥":"y","ø":"o","π":"p","“":"[","‘":"]","«":"\\","Œ":"Q","„":"W","´":"E","‰":"R","ˇ":"T","Á":"Y","¨":"U","ˆ":"I","Ø":"O","∏":"P","”":"{","’":"}","»":"|","å":"a","ß":"s","∂":"d","ƒ":"f","©":"g","˙":"h","∆":"j","˚":"k","¬":"l","…":";","æ":"'","Å":"A","Í":"S","Î":"D","Ï":"F","˝":"G","Ó":"H","Ô":"J","":"K","Ò":"L","Ú":":","Æ":'"',"Ω":"z","≈":"x","ç":"c","√":"v","∫":"b","µ":"m","≤":",","≥":".","÷":"/","¸":"Z","˛":"X","Ç":"C","◊":"V","ı":"B","˜":"N","Â":"M","¯":"<","˘":">","¿":"?"};const t={"`":"~",1:"!",2:"@",3:"#",4:"$",5:"%",6:"^",7:"&",8:"*",9:"(",0:")","-":"_","=":"+","[":"{","]":"}","\\":"|",";":":","'":'"',",":"<",".":">","/":"?",q:"Q",w:"W",e:"E",r:"R",t:"T",y:"Y",u:"U",i:"I",o:"O",p:"P",a:"A",s:"S",d:"D",f:"F",g:"G",h:"H",j:"J",k:"K",l:"L",z:"Z",x:"X",c:"C",v:"V",b:"B",n:"N",m:"M"};const n={" ":"Space","+":"Plus"};function eventToHotkeyString(s,o=navigator.platform){var l,c,a;const{ctrlKey:h,altKey:d,metaKey:u,shiftKey:f,key:p}=s;const m=[];const k=[h,d,u,f];for(const[e,t]of k.entries())t&&m.push(i[e]);if(!i.includes(p)){const i=m.includes("Alt")&&r.test(o)&&(l=e[p])!==null&&l!==void 0?l:p;const s=m.includes("Shift")&&r.test(o)&&(c=t[i])!==null&&c!==void 0?c:i;const h=(a=n[s])!==null&&a!==void 0?a:s;m.push(h)}return m.join("+")}const i=["Control","Alt","Meta","Shift"];function normalizeHotkey(e,t){let n;n=localizeMod(e,t);n=sortModifiers(n);return n}const r=/Mac|iPod|iPhone|iPad/i;function localizeMod(e,t=navigator.platform){const n=r.test(t)?"Meta":"Control";return e.replace("Mod",n)}function sortModifiers(e){const t=e.split("+").pop();const n=[];for(const t of["Control","Alt","Meta","Shift"])e.includes(t)&&n.push(t);t&&n.push(t);return n.join("+")}const s=" ";class SequenceTracker{constructor({onReset:e}={}){this._path=[];this.timer=null;this.onReset=e}get path(){return this._path}get sequence(){return this._path.join(s)}registerKeypress(e){this._path=[...this._path,eventToHotkeyString(e)];this.startTimer()}reset(){var e;this.killTimer();this._path=[];(e=this.onReset)===null||e===void 0?void 0:e.call(this)}killTimer(){this.timer!=null&&window.clearTimeout(this.timer);this.timer=null}startTimer(){this.killTimer();this.timer=window.setTimeout((()=>this.reset()),SequenceTracker.CHORD_TIMEOUT)}}SequenceTracker.CHORD_TIMEOUT=1500;function normalizeSequence(e){return e.split(s).map((e=>normalizeHotkey(e))).join(s)}function isFormField(e){if(!(e instanceof HTMLElement))return false;const t=e.nodeName.toLowerCase();const n=(e.getAttribute("type")||"").toLowerCase();return t==="select"||t==="textarea"||t==="input"&&n!=="submit"&&n!=="reset"&&n!=="checkbox"&&n!=="radio"&&n!=="file"||e.isContentEditable}function fireDeterminedAction(e,t){const n=new CustomEvent("hotkey-fire",{cancelable:true,detail:{path:t}});const i=!e.dispatchEvent(n);i||(isFormField(e)?e.focus():e.click())}function expandHotkeyToEdges(e){const t=[];let n=[""];let i=false;for(let r=0;r<e.length;r++)if(i&&e[r]===","){t.push(n);n=[""];i=false}else if(e[r]!==s){i=e[r]!=="+";n[n.length-1]+=e[r]}else{n.push("");i=false}t.push(n);return t.map((e=>e.map((e=>normalizeHotkey(e))).filter((e=>e!=="")))).filter((e=>e.length>0))}const o=new RadixTrie;const l=new WeakMap;let c=o;const a=new SequenceTracker({onReset(){c=o}});function keyDownHandler(e){if(e.defaultPrevented)return;if(!(e.target instanceof Node))return;if(isFormField(e.target)){const t=e.target;if(!t.id)return;if(!t.ownerDocument.querySelector(`[data-hotkey-scope="${t.id}"]`))return}const t=c.get(eventToHotkeyString(e));if(t){a.registerKeypress(e);c=t;if(t instanceof Leaf){const n=e.target;let i=false;let r;const s=isFormField(n);for(let e=t.children.length-1;e>=0;e-=1){r=t.children[e];const o=r.getAttribute("data-hotkey-scope");if(!s&&!o||s&&n.id===o){i=true;break}}if(r&&i){fireDeterminedAction(r,a.path);e.preventDefault()}a.reset()}}else a.reset()}function install(e,t){Object.keys(o.children).length===0&&document.addEventListener("keydown",keyDownHandler);const n=expandHotkeyToEdges(t||e.getAttribute("data-hotkey")||"");const i=n.map((t=>o.insert(t).add(e)));l.set(e,i)}function uninstall(e){const t=l.get(e);if(t&&t.length)for(const n of t)n&&n.delete(e);Object.keys(o.children).length===0&&document.removeEventListener("keydown",keyDownHandler)}export{Leaf,RadixTrie,SequenceTracker,eventToHotkeyString,install,normalizeHotkey,normalizeSequence,uninstall};
|
||
|