domma-cms 1.6.51 → 1.6.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/admin/js/lib/hotkeys.js +1 -1
- package/package.json +1 -1
package/admin/js/lib/hotkeys.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const CORE_HOTKEYS=Object.freeze({"#/":"d","#/pages":"p","#/media":"m","#/collections":"l","#/forms":"f","#/views":"v","#/users":"u","#/analytics":"a","#/notes":"n","#/todo":"t","#/contacts":"c","#/settings":","}),LEADER="g",SEQUENCE_MS=1500,FREQUENT_KEYS=9;export function normaliseHotkey(e){if(typeof e!="string")return null;const r=e.trim().toLowerCase();return r.length!==1||r===LEADER?null:/^[a-z,]$/.test(r)?r:null}export function hotkeyLabel(e){return`G then ${String(e).toUpperCase()}`}export function paletteKeyLabel(e=!1){return e?"\u2318K or \u2318D":"Ctrl+K or Ctrl+D"}export function sidebarTools(e){const r=[],o=new Set,n=(c,s)=>{for(const t of c||[]){if(!t||typeof t!="object"||t.hidden||t.frequent||t.type==="separator"||t.type==="spacer"||t.type==="theme-switcher")continue;const i=String(t.text||"").replace(/\s*\(\d+\)\s*$/,"").trim(),l=typeof t.url=="string"?t.url:"";if(l.startsWith("#/")&&i&&!o.has(l)){o.add(l);const
|
|
1
|
+
export const CORE_HOTKEYS=Object.freeze({"#/":"d","#/pages":"p","#/media":"m","#/collections":"l","#/forms":"f","#/views":"v","#/users":"u","#/analytics":"a","#/notes":"n","#/todo":"t","#/contacts":"c","#/settings":","}),LEADER="g",SEQUENCE_MS=1500,FREQUENT_KEYS=9;export function normaliseHotkey(e){if(typeof e!="string")return null;const r=e.trim().toLowerCase();return r.length!==1||r===LEADER?null:/^[a-z,]$/.test(r)?r:null}export function hotkeyLabel(e){return`G then ${String(e).toUpperCase()}`}export function paletteKeyLabel(e=!1){return e?"\u2318K or \u2318D":"Ctrl+K or Ctrl+D"}export function sidebarTools(e){const r=[],o=new Set,n=(c,s)=>{for(const t of c||[]){if(!t||typeof t!="object"||t.hidden||t.frequent||t.type==="separator"||t.type==="spacer"||t.type==="theme-switcher")continue;const i=String(t.text||"").replace(/\s*\(\d+\)\s*$/,"").trim(),l=typeof t.url=="string"?t.url:"";if(l.startsWith("#/")&&i&&!o.has(l)){o.add(l);const u=normaliseHotkey(t.hotkey),f=CORE_HOTKEYS[l]||null;r.push({url:l,text:i,icon:t.icon||null,path:s,wants:f||u,core:!!f})}Array.isArray(t.items)&&t.items.length&&n(t.items,i?[...s,i]:s)}};return n(e,[]),r}export function assignHotkeys(e){const r=sidebarTools(e),o=new Map,n=new Map,c=[],s=t=>{if(!t.wants)return;const i=o.get(t.wants);if(i){c.push({url:t.url,text:t.text,key:t.wants,takenBy:i.text});return}o.set(t.wants,t),n.set(t.url,t.wants)};return r.filter(t=>t.core).forEach(s),r.filter(t=>!t.core).forEach(s),{tools:r.map(t=>({...t,key:n.get(t.url)||null})),byKey:o,byUrl:n,conflicts:c}}export function frequentKeys(e){return((e||[]).find(o=>o&&o.frequent)?.items||[]).filter(o=>o&&typeof o.url=="string"&&o.url.startsWith("#/")).slice(0,FREQUENT_KEYS).map((o,n)=>({n:n+1,url:o.url,text:String(o.text||"")}))}export const CHIP_DELAY_MS=300;export function chipEntries(e,{max:r=14}={}){const o=(e?.frequent||[]).slice(0,r).map(s=>({n:s.n,text:s.text})),n=[...(e?.byKey||new Map).entries()].map(([s,t])=>({key:s,text:t.text})).sort((s,t)=>(s.key===","?1:0)-(t.key===","?1:0)||s.key.localeCompare(t.key)),c=Math.max(r-o.length,0);return{frequent:o,letters:n.slice(0,c),more:Math.max(n.length-c,0)}}export function createSequence(e){let r=null;const o=n=>r!==null&&n-r<=SEQUENCE_MS;return{pending:o,reset(){r=null},press(n,c){const s=typeof n=="string"&&n.length===1?n.toLowerCase():null;if(o(c)){if(r=null,!s)return{type:"miss"};const{byKey:t,frequent:i}=e();if(/^[1-9]$/.test(s)){const u=(i||[]).find(f=>f.n===Number(s));return u?{type:"go",url:u.url}:{type:"miss"}}const l=t?.get(s);return l?{type:"go",url:l.url}:{type:"miss"}}return r=null,s===LEADER?(r=c,{type:"start"}):null}}}export function matchTools(e,r,o=50){const n=String(r||"").trim().toLowerCase(),c=(t,i)=>(i.t.key?1:0)-(t.t.key?1:0)||t.t.path.length-i.t.path.length||t.at-i.at;if(!n)return e.map((t,i)=>({t,at:i})).sort(c).slice(0,o).map(t=>t.t);const s=[];return e.forEach((t,i)=>{const l=t.text.toLowerCase(),u=l.split(/[\s\-_/&]+/).filter(Boolean),f=u.map(p=>p[0]).join(""),y=t.path.join(" ").toLowerCase();let a=0;n.length===1&&t.key===n?a=120:l===n?a=110:l.startsWith(n)?a=100:u.some(p=>p.startsWith(n))?a=80:n.length>1&&f.startsWith(n)?a=70:l.includes(n)?a=50:y.includes(n)&&(a=20),a&&s.push({t,score:a,at:i})}),s.sort((t,i)=>i.score-t.score||c(t,i)),s.slice(0,o).map(t=>t.t)}export function isTypingTarget(e){if(!e||typeof e!="object")return!1;const r=String(e.tagName||"").toUpperCase();if(r==="TEXTAREA"||r==="SELECT")return!0;if(r==="INPUT"){const o=String(e.type||"text").toLowerCase();return!["button","submit","reset","checkbox","radio","range","color","file","image"].includes(o)}return e.isContentEditable?!0:!!(e.closest&&e.closest('[contenteditable=""], [contenteditable="true"], .cm-editor, .CodeMirror, .monaco-editor, .ProseMirror, [data-own-keys]'))}export function isPaletteKey(e){if(!e||e.altKey||e.shiftKey||!(e.ctrlKey||e.metaKey)||e.ctrlKey&&e.metaKey)return!1;const r=String(e.key||"").toLowerCase();return r==="d"?!isTypingTarget(e.target):r==="k"?!m(e.target):!1}function m(e){return!e||typeof e!="object"?!1:e.isContentEditable?!0:!!(e.closest&&e.closest('[contenteditable=""], [contenteditable="true"], .cm-editor, .CodeMirror, .monaco-editor, .ProseMirror'))}
|