|
"use strict";(self.webpackChunk_JUPYTERLAB_CORE_OUTPUT=self.webpackChunk_JUPYTERLAB_CORE_OUTPUT||[]).push([[113],{113:(t,e,s)=>{s.r(e),s.d(e,{default:()=>K});var i,n=s(23295),r=s(12030),o=s(35613),l=s(16934),a=s(20998),c=s(2549),h=s(18395);!function(t){t.editBinding="shortcuts:edit-keybinding",t.addBinding="shortcuts:add-keybinding",t.deleteBinding="shortcuts:delete-keybinding",t.toggleSelectors="shortcuts:toggle-selectors",t.resetAll="shortcuts:reset-all"}(i||(i={}));var d=s(78156),u=s.n(d),p=s(33625),m=s(80554);class g extends d.Component{constructor(t){super(t),this.handleSubmit=async()=>{this._isReplacingExistingKeybinding?this.state.selected?(this.props.toggleInput(),this.setState({value:"",userInput:""})):await this._updateShortcut():(await this._updateShortcut(),this.setState({value:"",keys:[],currentChain:""}),this.props.toggleInput()),this._updateConflictDisplay()},this._updateShortcut=async()=>{const t=[...this.state.keys,this.state.currentChain];this.setState({keys:t}),this.props.keybinding?await this.props.replaceKeybinding(this.props.shortcut,this.props.keybinding,t):await this.props.addKeybinding(this.props.shortcut,t)},this.handleOverwrite=async()=>{const t=[...this.state.keys,this.state.currentChain];for(const e of this.state.conflicts){const s=e.keybindings.filter((e=>a.JSONExt.deepEqual(e.keys,t)||t.some((t=>a.JSONExt.deepEqual(e.keys,[t])))))[0];s?await this.props.deleteKeybinding(e,s):console.error(`Conflicting binding could not be found for ${e} using keys ${t}`)}this.setState({conflicts:[]}),await this._updateShortcut(),this._updateConflictDisplay()},this.parseChaining=(t,e,s,i,n)=>{let r=m.EN_US.keyForKeydownEvent(t.nativeEvent);const o=["Shift","Control","Alt","Meta","Ctrl","Accel"];if("Backspace"===t.key)s="",i=[],n="",this.setState({value:"",userInput:s,keys:i,currentChain:n});else if("CapsLock"!==t.key){const e=s.substr(s.lastIndexOf(" ")+1,s.length).trim();-1===o.lastIndexOf(e)&&""!=e?(s+=",",i.push(n),n="",t.ctrlKey&&"Control"!=t.key&&(s=(s+" Ctrl").trim(),n=(n+" Ctrl").trim()),t.metaKey&&"Meta"!=t.key&&(s=(s+" Accel").trim(),n=(n+" Accel").trim()),t.altKey&&"Alt"!=t.key&&(s=(s+" Alt").trim(),n=(n+" Alt").trim()),t.shiftKey&&"Shift"!=t.key&&(s=(s+" Shift").trim(),n=(n+" Shift").trim()),-1===o.lastIndexOf(t.key)?(s=(s+" "+r).trim(),n=(n+" "+r).trim()):"Meta"===t.key?(s=(s+" Accel").trim(),n=(n+" Accel").trim()):"Control"===t.key?(s=(s+" Ctrl").trim(),n=(n+" Ctrl").trim()):"Shift"===t.key?(s=(s+" Shift").trim(),n=(n+" Shift").trim()):"Alt"===t.key?(s=(s+" Alt").trim(),n=(n+" Alt").trim()):(s=(s+" "+t.key).trim(),n=(n+" "+t.key).trim())):"Control"===t.key?(s=(s+" Ctrl").trim(),n=(n+" Ctrl").trim()):"Meta"===t.key?(s=(s+" Accel").trim(),n=(n+" Accel").trim()):"Shift"===t.key?(s=(s+" Shift").trim(),n=(n+" Shift").trim()):"Alt"===t.key?(s=(s+" Alt").trim(),n=(n+" Alt").trim()):(s=(s+" "+r).trim(),n=(n+" "+r).trim())}return this.setState({keys:i,currentChain:n}),[s,i,n]},this.checkNonFunctional=()=>{const t=["Ctrl","Alt","Accel","Shift"],e=this.state.currentChain.split(" "),s=e[e.length-1];return this.setState({isFunctional:!(-1!==t.indexOf(s))}),-1!==t.indexOf(s)},this.checkShortcutAvailability=(t,e,s)=>{const i=this.props.findConflictsFor([...e,s],this.props.shortcut.selector),n=""===t||0===i.length;return!n&&1===i.length&&i[0].id===this.props.shortcut.id&&this._isReplacingExistingKeybinding?(this.setState({isAvailable:!0}),[]):(this.setState({isAvailable:n}),i)},this.handleInput=t=>{t.preventDefault(),this.setState({selected:!1});const e=this.parseChaining(t,this.state.value,this.state.userInput,this.state.keys,this.state.currentChain),s=e[0],i=e[1],n=e[2],r=this.props.toSymbols(s);let o=this.checkShortcutAvailability(s,i,n);this.setState({value:r,userInput:s,conflicts:o,keys:i,currentChain:n},(()=>{this.checkNonFunctional(),this._updateConflictDisplay()}))},this.handleBlur=t=>{null!==t.relatedTarget&&"no-blur"===t.relatedTarget.id||(this.props.toggleInput(),this.setState({value:"",userInput:"",conflicts:[]},(()=>{this._updateConflictDisplay()})))},this.state={value:this.props.placeholder,userInput:"",isAvailable:!0,isFunctional:this._isReplacingExistingKeybinding,conflicts:[],keys:[],currentChain:"",selected:!0}}get _isReplacingExistingKeybinding(){return!!this.props.keybinding}_updateConflictDisplay(){this.props.displayConflicts({conflictsWith:this.state.conflicts,keys:this.state.keys,overwrite:this.handleOverwrite})}render(){const t=this.props.translator.load("jupyterlab");let e="jp-Shortcuts-Input";return this.state.isAvailable||(e+=" jp-mod-unavailable-Input"),d.createElement("div",{className:this.props.displayInput?this._isReplacingExistingKeybinding?"jp-Shortcuts-InputBox":"jp-Shortcuts-InputBox jp-Shortcuts-InputBoxNew":"jp-mod-hidden",onBlur:t=>this.handleBlur(t)},d.createElement("div",{tabIndex:0,id:"no-blur",className:e,onKeyDown:this.handleInput,ref:t=>t&&t.focus(),"data-lm-suppress-shortcuts":"true"},d.createElement("p",{className:this.state.selected&&this._isReplacingExistingKeybinding?"jp-Shortcuts-InputText jp-mod-selected-InputText":""===this.state.value?"jp-Shortcuts-InputText jp-mod-waiting-InputText":"jp-Shortcuts-InputText"},""===this.state.value?t.__("press keys"):this.state.value)),d.createElement("button",{className:this.state.isFunctional?this.state.isAvailable?"jp-Shortcuts-Submit":"jp-Shortcuts-Submit jp-mod-conflict-Submit":"jp-Shortcuts-Submit jp-mod-defunc-Submit",id:"no-blur",disabled:!this.state.isAvailable||!this.state.isFunctional,onClick:this.handleSubmit},this.state.isAvailable?d.createElement(o.checkIcon.react,null):d.createElement(o.errorIcon.react,null)))}}class y extends d.Component{constructor(t){super(t),this.toggleInputNew=()=>{this.setState({displayNewInput:!this.state.displayNewInput})},this.toSymbols=t=>t.split(" ").reduce(((t,e)=>"Ctrl"===e?(t+" ⌃").trim():"Alt"===e?(t+" ⌥").trim():"Shift"===e?(t+" ⇧").trim():"Accel"===e&&h.Platform.IS_MAC?(t+" ⌘").trim():"Accel"===e?(t+" ⌃").trim():(t+" "+e).trim()),""),this._trans=this.props.external.translator.load("jupyterlab"),this.state={displayNewInput:!1,displayReplaceInput:Object.freeze({}),conflicts:new Map}}componentDidMount(){this.props.external.actionRequested.connect(this._onActionRequested,this)}componentWillUnmount(){this.props.external.actionRequested.disconnect(this._onActionRequested,this)}async _onActionRequested(t,e){if(!("shortcutId"in e)||e.shortcutId===this.props.shortcut.id){if("add-keybinding"===e.request)return this.toggleInputNew();if("edit-keybinding"===e.request&&this.toggleInputReplaceMethod(e.keybinding),"delete-keybinding"===e.request){const t=this.props.shortcut,s=t.keybindings[e.keybinding];this.props.deleteKeybinding(t,s).catch(console.error)}}}getCategoryCell(){return d.createElement("div",{className:"jp-Shortcuts-Cell"},this.props.shortcut.category)}getLabelCell(){var t;return d.createElement("div",{className:"jp-Shortcuts-Cell"},d.createElement("div",{className:"jp-label"},null!==(t=this.props.shortcut.label)&&void 0!==t?t:this._trans.__("(Command label missing)")))}getResetShortCutLink(){return d.createElement("a",{className:"jp-Shortcuts-Reset",onClick:()=>this.props.resetKeybindings(this.props.shortcut)},this._trans.__("Reset"))}getSourceCell(){const t=this.props.shortcut.keybindings.every((t=>t.isDefault));return d.createElement("div",{className:"jp-Shortcuts-Cell"},d.createElement("div",{className:"jp-Shortcuts-SourceCell"},t?this._trans.__("Default"):this._trans.__("Custom")),t?"":this.getResetShortCutLink())}getOptionalSelectorCell(){return this.props.showSelectors?d.createElement("div",{className:"jp-Shortcuts-Cell"},d.createElement("div",{className:"jp-selector"},this.props.shortcut.selector)):null}getClassNameForShortCuts(t){const e=["jp-Shortcuts-ShortcutCell"];switch(t.length){case 1:e.push("jp-Shortcuts-SingleCell");break;case 0:e.push("jp-Shortcuts-EmptyCell")}return e.join(" ")}toggleInputReplaceMethod(t){const e=this.state.displayReplaceInput[t];this.setState({displayReplaceInput:{...this.state.displayReplaceInput,[t]:!e}})}getDisplayReplaceInput(t){return this.state.displayReplaceInput[t]}getOrDiplayIfNeeded(t){const e=["jp-Shortcuts-Or"];return(t||this.state.displayNewInput)&&e.push("jp-Shortcuts-Or-Forced"),d.createElement("div",{className:e.join(" ")},this._trans.__("or"))}getShortCutAsInput(t,e){return d.createElement(g,{addKeybinding:this.props.addKeybinding,replaceKeybinding:this.props.replaceKeybinding,deleteKeybinding:this.props.deleteKeybinding,findConflictsFor:this.props.findConflictsFor,toggleInput:()=>this.toggleInputReplaceMethod(e),shortcut:this.props.shortcut,keybinding:t,displayConflicts:e=>{const s=new Map(this.state.conflicts);s.set(t,e),this.setState({conflicts:s})},toSymbols:this.toSymbols,displayInput:this.getDisplayReplaceInput(e),placeholder:this.toSymbols(t.keys.join(", ")),translator:this.props.external.translator})}getShortCutForDisplayOnly(t){return t.keys.map(((e,s)=>d.createElement("div",{className:"jp-Shortcuts-ShortcutKeysContainer",key:s},d.createElement("div",{className:"jp-Shortcuts-ShortcutKeys"},this.toSymbols(e)),s+1<t.keys.length?d.createElement("div",{className:"jp-Shortcuts-Comma"},","):null)))}isLocationBeingEdited(t){return this.state.displayReplaceInput[t]}getDivForKey(t,e,s){return d.createElement("div",{className:"jp-Shortcuts-ShortcutContainer",key:this.props.shortcut.id+"_"+t,"data-keybinding":t,"data-shortcut":this.props.shortcut.id,onClick:()=>this.toggleInputReplaceMethod(t)},this.isLocationBeingEdited(t)?this.getShortCutAsInput(e,t):this.getShortCutForDisplayOnly(e),this.getOrDiplayIfNeeded(t<s.length-1))}getAddLink(){return d.createElement("a",{className:this.state.displayNewInput?"":"jp-Shortcuts-Plus",onClick:()=>{this.toggleInputNew()}},this._trans.__("Add"))}getInputBoxWhenToggled(){return this.state.displayNewInput?d.createElement(g,{addKeybinding:this.props.addKeybinding,replaceKeybinding:this.props.replaceKeybinding,deleteKeybinding:this.props.deleteKeybinding,findConflictsFor:this.props.findConflictsFor,toggleInput:this.toggleInputNew,shortcut:this.props.shortcut,displayConflicts:t=>{const e=new Map(this.state.conflicts);e.set(null,t),this.setState({conflicts:e})},toSymbols:this.toSymbols,displayInput:this.state.displayNewInput,placeholder:"",translator:this.props.external.translator}):d.createElement("div",null)}getShortCutsCell(t){return d.createElement("div",{className:"jp-Shortcuts-Cell"},d.createElement("div",{className:this.getClassNameForShortCuts(t)},t.map(((e,s)=>this.getDivForKey(s,e,t))),t.length>=1&&!this.state.displayNewInput&&!this.state.displayReplaceInput[0]&&this.getAddLink(),0===t.length&&!this.state.displayNewInput&&this.getAddLink(),this.getInputBoxWhenToggled()))}getConflicts(){const t=[...this.state.conflicts.values()].filter((t=>0!==t.conflictsWith.length));return 0===t.length?d.createElement(d.Fragment,null):d.createElement("div",{className:"jp-Shortcuts-Row"},d.createElement("div",{className:"jp-Shortcuts-ConflictContainer"},t.map((t=>{const e=t.keys.join(" ")+"_"+t.conflictsWith.map((t=>t.id)).join("");return d.createElement("div",{className:"jp-Shortcuts-Conflict",key:e},d.createElement("div",{className:"jp-Shortcuts-ErrorMessage"},this._trans.__("Shortcut already in use by %1. Overwrite it?",t.conflictsWith.map((t=>{var e;return null!==(e=t.label)&&void 0!==e?e:t.command})).join(", "))),d.createElement("div",{className:"jp-Shortcuts-ErrorButton"},d.createElement("button",null,this._trans.__("Cancel")),d.createElement("button",{id:"no-blur",onClick:()=>{t.overwrite()}},this._trans.__("Overwrite"))))}))))}get _nonEmptyBindings(){return this.props.shortcut.keybindings.filter((t=>0!==t.keys.filter((t=>""!=t)).length))}render(){return d.createElement(d.Fragment,null,d.createElement("div",{className:"jp-Shortcuts-Row","data-shortcut":this.props.shortcut.id},this.getCategoryCell(),this.getLabelCell(),this.getShortCutsCell(this._nonEmptyBindings),this.getSourceCell(),this.getOptionalSelectorCell()),this.getConflicts())}}class S extends d.Component{render(){return d.createElement("div",{className:"jp-Shortcuts-ShortcutListContainer",style:{height:this.props.height-115+"px"},id:"shortcutListContainer"},d.createElement("div",{className:"jp-Shortcuts-ShortcutList"},this.props.shortcuts.map((t=>d.createElement(y,{key:t.id,addKeybinding:this.props.addKeybinding,replaceKeybinding:this.props.replaceKeybinding,deleteKeybinding:this.props.deleteKeybinding,resetKeybindings:this.props.resetKeybindings,findConflictsFor:this.props.findConflictsFor,shortcut:t,showSelectors:this.props.showSelectors,external:this.props.external})))))}}class b extends d.Component{render(){return d.createElement("div",{className:this.props.title.toLowerCase()===this.props.active?"jp-Shortcuts-Header jp-Shortcuts-CurrentHeader":"jp-Shortcuts-Header",onClick:()=>this.props.updateSort(this.props.columnId)},this.props.title,d.createElement(o.caretDownEmptyThinIcon.react,{className:"jp-Shortcuts-SortButton jp-ShortcutTitleItem-sortButton"}))}}function f(t){return d.createElement("div",{className:"jp-Shortcuts-Symbols"},d.createElement("table",null,d.createElement("tbody",null,d.createElement("tr",null,d.createElement("td",null,d.createElement("kbd",null,"Cmd")),d.createElement("td",null,"⌘"),d.createElement("td",null,d.createElement("kbd",null,"Ctrl")),d.createElement("td",null,"⌃")),d.createElement("tr",null,d.createElement("td",null,d.createElement("kbd",null,"Alt")),d.createElement("td",null,"⌥"),d.createElement("td",null,d.createElement("kbd",null,"Shift")),d.createElement("td",null,"⇧")))))}function C(t){const e=t.translator.load("jupyterlab");return d.createElement("div",{className:"jp-Shortcuts-AdvancedOptions"},d.createElement("a",{className:"jp-Shortcuts-AdvancedOptionsLink",onClick:()=>t.toggleSelectors()},t.showSelectors?e.__("Hide Selectors"):e.__("Show Selectors")),d.createElement("a",{className:"jp-Shortcuts-AdvancedOptionsLink",onClick:()=>t.resetShortcuts()},e.__("Reset All")))}class k extends d.Component{constructor(t){super(t)}getShortCutTitleItem(t,e){return d.createElement("div",{className:"jp-Shortcuts-Cell"},d.createElement(b,{title:t,updateSort:this.props.updateSort,active:this.props.currentSort,columnId:e}))}render(){const t=this.props.translator.load("jupyterlab");return d.createElement("div",{className:"jp-Shortcuts-Top"},d.createElement("div",{className:"jp-Shortcuts-TopNav"},d.createElement(f,null),d.createElement(o.FilterBox,{"aria-label":t.__("Search shortcuts"),updateFilter:(t,e)=>this.props.updateSearchQuery(null!=e?e:""),placeholder:t.__("Search…"),useFuzzyFilter:!1}),d.createElement(C,{toggleSelectors:this.props.toggleSelectors,showSelectors:this.props.showSelectors,resetShortcuts:this.props.resetShortcuts,translator:this.props.translator})),d.createElement("div",{className:"jp-Shortcuts-HeaderRowContainer"},d.createElement("div",{className:"jp-Shortcuts-HeaderRow"},this.getShortCutTitleItem(t.__("Category"),"category"),this.getShortCutTitleItem(t.__("Command"),"command"),d.createElement("div",{className:"jp-Shortcuts-Cell"},d.createElement("div",{className:"title-div"},t.__("Shortcut"))),this.getShortCutTitleItem(t.__("Source"),"source"),this.props.showSelectors&&this.getShortCutTitleItem(t.__("Selectors"),"selector"))))}}class v extends Map{constructor(t){var e,s,i;super();const{settings:n,commandRegistry:r}=t,o=null!==(e=n.user.shortcuts)&&void 0!==e?e:[],l=new Set(o.map(this._computeKeybindingId.bind(this))),a=null!==(s=n.composite.shortcuts)&&void 0!==s?s:[];for(const t of a){const e=this._computeTargetId(t),s=this._computeKeybindingId(t),n={keys:t.keys,isDefault:!l.has(s)},o=this.get(e);if(o)o.keybindings.push(n);else{const s=t.command.split(":"),o=null!==(i=r.label(t.command,t.args))&&void 0!==i?i:s.length>1?s[1]:void 0,l=s[0];this.set(e,{id:e,selector:t.selector,command:t.command,category:l,label:o,args:t.args,keybindings:[n]})}}}findConflictsFor(t,e){const s=new _({registry:this});let i=s.findConflicts(t,e);if(0!==i.length)return i;for(const n of t)if(i=s.findConflicts([n],e),0!==i.length)return i;return[]}_computeTargetId(t){var e;return t.command+"_"+t.selector+"_"+JSON.stringify(null!==(e=t.args)&&void 0!==e?e:{})}_computeKeybindingId(t){var e;return[t.command,t.selector,JSON.stringify(null!==(e=t.args)&&void 0!==e?e:{}),t.keys.join(" ")].join("_")}}class _{constructor(t){var e;const s=new Map;for(const i of t.registry.values())for(const t of i.keybindings){const n=this._keybindingHash(t.keys,i.selector),r=null!==(e=s.get(n))&&void 0!==e?e:[];r.push(i),s.set(n,r)}this._keybindingsMap=s}findConflicts(t,e){var s;const i=this._keybindingHash(t,e);return null!==(s=this._keybindingsMap.get(i))&&void 0!==s?s:[]}_keybindingHash(t,e){return t.join(" ")+"_"+e}}function E(t,e){var s;const i=t.category.toLowerCase(),n=`${i} ${(null!==(s=t.label)&&void 0!==s?s:"").toLowerCase()}`;let r=1/0,o=null;const l=/\b\w/g;for(;;){const t=l.exec(n);if(!t)break;const s=p.StringExt.matchSumOfDeltas(n,e,t.index);if(!s)break;s&&s.score<=r&&(r=s.score,o=s.indices)}if(!o||r===1/0)return null;const a=i.length+1,c=p.ArrayExt.lowerBound(o,a,((t,e)=>t-e)),h=o.slice(0,c),d=o.slice(c);for(let t=0,e=d.length;t<e;++t)d[t]-=a;return 0===h.length?{matchType:0,categoryIndices:null,labelIndices:d,score:r,item:t}:0===d.length?{matchType:1,categoryIndices:h,labelIndices:null,score:r,item:t}:{matchType:2,categoryIndices:h,labelIndices:d,score:r,item:t}}class I extends d.Component{constructor(t){super(t),this.updateSearchQuery=t=>{this.setState({searchQuery:t},(()=>{const t=this.state.shortcutRegistry;this.setState({filteredShortcutList:this._searchFilterShortcuts(t)},(()=>{this.sortShortcuts()}))}))},this.resetShortcuts=async()=>{const t=await this.props.external.getSettings();await t.set("shortcuts",[]),await this._refreshShortcutList()},this.resetKeybindings=async t=>{for(const e of t.keybindings)await this._setKeybinding(t,e.isDefault?e.keys:[],e)},this.replaceKeybinding=async(t,e,s)=>this._setKeybinding(t,s,e),this.deleteKeybinding=async(t,e)=>{await this._setKeybinding(t,[],e)},this.addKeybinding=async(t,e)=>{await this._setKeybinding(t,e)},this.toggleSelectors=()=>{this.setState({showSelectors:!this.state.showSelectors})},this.updateSort=t=>{t!==this.state.currentSort&&this.setState({currentSort:t},this.sortShortcuts)},this.state={shortcutRegistry:null,filteredShortcutList:new Array,shortcutsFetched:!1,searchQuery:"",showSelectors:!1,currentSort:"category"}}componentDidMount(){this.props.external.actionRequested.connect(this._onActionRequested,this),this._refreshShortcutList()}componentWillUnmount(){this.props.external.actionRequested.disconnect(this._onActionRequested,this)}async _onActionRequested(t,e){if("toggle-selectors"===e.request)return this.toggleSelectors();"reset-all"===e.request&&await this.resetShortcuts()}async _refreshShortcutList(){const t=await this.props.external.getSettings(),e=new v({commandRegistry:this.props.external.commandRegistry,settings:t});this.setState({shortcutRegistry:e,filteredShortcutList:this._searchFilterShortcuts(e),shortcutsFetched:!0},(()=>{this.sortShortcuts()}))}_searchFilterShortcuts(t){return t?function(t,e){e=e.replace(/\s+/g,"").toLowerCase();let s=[];for(const i of t.values()){if(!e){s.push({matchType:3,categoryIndices:null,labelIndices:null,score:0,item:i});continue}let t=E(i,e);t&&s.push(t)}return s}(t,this.state.searchQuery).map((t=>t.item)):[]}async _setKeybinding(t,e,s){var i,n,r;1===e.length&&""==e[0]&&(e=[]);const o=await this.props.external.getSettings(),l=null!==(i=o.user.shortcuts)&&void 0!==i?i:[],c=[];let h=!1;for(let i of l)if(i.command===t.command&&i.selector===t.selector&&a.JSONExt.deepEqual(null!==(n=i.args)&&void 0!==n?n:{},null!==(r=t.args)&&void 0!==r?r:{})&&s&&a.JSONExt.deepEqual(s.keys,i.keys)){const t=s&&s.isDefault&&a.JSONExt.deepEqual(s.keys,e);0===e.length||t||c.push({command:i.command,selector:i.selector,keys:e}),h=!0}else c.push(i);if(!h){const i=!s||!a.JSONExt.deepEqual(s.keys,e);s&&s.isDefault&&i&&c.push({command:t.command,selector:t.selector,disabled:!0,keys:s.keys}),0!==e.length&&c.push({command:t.command,selector:t.selector,keys:e})}await o.set("shortcuts",c),await this._refreshShortcutList()}sortShortcuts(){const t=this.state.filteredShortcutList;let e=this.state.currentSort;"command"===e&&(e="label");const s=t=>{var s;return"source"===e?t.keybindings.every((t=>t.isDefault))?"default":"other":null!==(s=t[e])&&void 0!==s?s:""};t.sort(((t,e)=>{var i,n;const r=s(t),o=s(e),l=r.localeCompare(o);if(l)return l;{const s=null!==(i=t.label)&&void 0!==i?i:"",r=null!==(n=e.label)&&void 0!==n?n:"";return s.localeCompare(r)}})),this.setState({filteredShortcutList:t})}render(){return this.state.shortcutsFetched?d.createElement("div",{className:"jp-Shortcuts-ShortcutUI",id:"jp-shortcutui"},d.createElement(k,{updateSearchQuery:this.updateSearchQuery,resetShortcuts:this.resetShortcuts,toggleSelectors:this.toggleSelectors,showSelectors:this.state.showSelectors,updateSort:this.updateSort,currentSort:this.state.currentSort,width:this.props.width,translator:this.props.external.translator}),d.createElement(S,{shortcuts:this.state.filteredShortcutList,resetKeybindings:this.resetKeybindings,addKeybinding:this.addKeybinding,replaceKeybinding:this.replaceKeybinding,deleteKeybinding:this.deleteKeybinding,showSelectors:this.state.showSelectors,findConflictsFor:(t,e)=>this.state.shortcutRegistry?this.state.shortcutRegistry.findConflictsFor(t,e):(console.error("Cannot search for keybinding conflicts at this time: registry is not ready"),[]),height:this.props.height,external:this.props.external})):null}}var w=s(81997);const j="@jupyterlab/shortcuts-extension:shortcuts";function x(t,e,s,i){return{translator:s,getSettings:()=>t.load(j,!0),commandRegistry:e.commands,actionRequested:i}}const N={id:j,description:"Adds the keyboard shortcuts editor.",requires:[n.ISettingRegistry],optional:[r.ITranslator,o.IFormRendererRegistry],activate:async(t,e,s,o)=>{const c=null!=s?s:r.nullTranslator,d=c.load("jupyterlab"),{commands:p}=t;let m,g,y={};if(o){const s=new w.Signal({}),n=t=>void 0!==t.dataset.shortcut;t.commands.addCommand(i.editBinding,{label:d.__("Edit Keybinding"),caption:d.__("Edit existing keybinding"),execute:()=>{const e=t.contextMenuHitTest(n),i=null==e?void 0:e.dataset.keybinding,r=null==e?void 0:e.dataset.shortcut;if(!r||!i)return console.log("Missing shortcut id/keybinding information");s.emit({request:"edit-keybinding",keybinding:parseInt(i,10),shortcutId:r})}}),t.commands.addCommand(i.deleteBinding,{label:d.__("Delete Keybinding"),caption:d.__("Delete chosen keybinding"),execute:()=>{const e=t.contextMenuHitTest(n),i=null==e?void 0:e.dataset.keybinding,r=null==e?void 0:e.dataset.shortcut;if(!r||!i)return console.log("Missing shortcut id/keybinding information");s.emit({request:"delete-keybinding",keybinding:parseInt(i,10),shortcutId:r})}}),t.commands.addCommand(i.addBinding,{label:d.__("Add Keybinding"),caption:d.__("Add new keybinding for existing shortcut target"),execute:()=>{const e=t.contextMenuHitTest(n),i=null==e?void 0:e.dataset.shortcut;if(!i)return console.log("Missing shortcut id to add keybinding to");s.emit({request:"add-keybinding",shortcutId:i})}}),p.addCommand(i.toggleSelectors,{label:d.__("Toggle Selectors"),caption:d.__("Toggle command selectors"),execute:()=>{s.emit({request:"toggle-selectors"})}}),p.addCommand(i.resetAll,{label:d.__("Reset All"),caption:d.__("Reset all shortcuts"),execute:()=>{s.emit({request:"reset-all"})}});const r={fieldRenderer:i=>(t=>u().createElement(I,{external:t.external,height:1e3,width:1e3}))({external:x(e,t,c,s),...i})};o.addRenderer(`${N.id}.shortcuts`,r)}function S(s){const i=t.commands.listCommands().join("\n");g||(g=a.JSONExt.deepCopy(s.properties.shortcuts.default)),y={},s.properties.shortcuts.default=Object.keys(e.plugins).map((t=>{const s=e.plugins[t].schema["jupyter.lab.shortcuts"]||[];return y[t]=s,s})).concat([g]).reduce(((t,e)=>h.Platform.IS_MAC?t.concat(e):t.concat(e.filter((t=>!t.keys.some((t=>{const{cmd:e}=l.CommandRegistry.parseKeystroke(t);return e})))))),[]).sort(((t,e)=>t.command.localeCompare(e.command))),s.properties.shortcuts.description=d.__('Note: To disable a system default shortcut,\ncopy it to User Preferences and add the\n"disabled" key, for example:\n{\n "command": "application:activate-next-tab",\n "keys": [\n "Ctrl Shift ]"\n ],\n "selector": "body",\n "disabled": true\n}\n\nList of commands followed by keyboard shortcuts:\n%1\n\nList of keyboard shortcuts:',i)}e.pluginChanged.connect((async(t,s)=>{if(s!==N.id){const t=y[s],i=e.plugins[s].schema["jupyter.lab.shortcuts"]||[];void 0!==t&&a.JSONExt.deepEqual(t,i)||(m=null,e.plugins[N.id].schema.properties.shortcuts.default=g,await e.load(N.id,!0))}})),e.transform(N.id,{compose:t=>{var e,s,i,r;m||(m=a.JSONExt.deepCopy(t.schema),S(m));const o=null!==(i=null===(s=null===(e=m.properties)||void 0===e?void 0:e.shortcuts)||void 0===s?void 0:s.default)&&void 0!==i?i:[],l={shortcuts:null!==(r=t.data.user.shortcuts)&&void 0!==r?r:[]},c={shortcuts:n.SettingRegistry.reconcileShortcuts(o,l.shortcuts)};return t.data={composite:c,user:l},t},fetch:t=>(m||(m=a.JSONExt.deepCopy(t.schema),S(m)),{data:t.data,id:t.id,raw:t.raw,schema:m,version:t.version})});try{m=null;const t=await e.load(N.id);A.loadShortcuts(p,t.composite),t.changed.connect((()=>{A.loadShortcuts(p,t.composite)}))}catch(t){console.error(`Loading ${N.id} failed.`,t)}},autoStart:!0},K=N;var A;!function(t){let e;t.loadShortcuts=function(t,s){var i;const n=null!==(i=null==s?void 0:s.shortcuts)&&void 0!==i?i:[];e&&e.dispose(),e=n.reduce(((e,s)=>{const i=function(t){if(!t||"object"!=typeof t)return;const{isArray:e}=Array;return"command"in t&&"keys"in t&&"selector"in t&&e(t.keys)?t:void 0}(s);return i&&e.add(t.addKeyBinding(i)),e}),new c.DisposableSet)}}(A||(A={}))}}]); |