repo_name
string
dataset
string
owner
string
lang
string
func_name
string
code
string
docstring
string
url
string
sha
string
libro
github_2023
weavefox
typescript
Application.start
async start(): Promise<void> { if (this.started) { return; } this.started = true; await this.initialize(); this.stateService.setState(ApplicationState.Initialized); await this.onStart(); this.stateService.setState(ApplicationState.Started); await this.viewStart(); this.mount(); this.stateService.setState(ApplicationState.ViewStarted); this.stateService.setState(ApplicationState.Ready); this.windowsService.onUnload(() => { this.stateService.setState(ApplicationState.Closing); this.onStop(); }); }
/** * Start the frontend application. * * Start up consists of the following steps: * - start frontend contributions * - create root view and render it * - restore or create other views and render them */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/application.ts#L112-L129
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Application.registerCompositionEventListeners
protected registerCompositionEventListeners(): Disposable { const compositionStart = () => { this.inComposition = true; }; const compositionEnd = () => { this.inComposition = false; }; document.addEventListener('compositionstart', compositionStart); document.addEventListener('compositionend', compositionEnd); return Disposable.create(() => { document.removeEventListener('compositionstart', compositionStart); document.removeEventListener('compositionend', compositionEnd); }); }
/** * Register composition related event listeners. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/application.ts#L136-L149
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Application.initialize
protected async initialize(): Promise<void> { for (const contribution of this.contributions.getContributions()) { if (contribution.initialize) { try { await this.measure(`${contribution.constructor.name}.initialize`, () => { if (contribution.initialize) { contribution.initialize(); } }); } catch (error) { console.error('contribution initialize', error); } } } }
/** * Initialize and start the frontend application contributions. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/application.ts#L173-L187
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Application.onStart
protected async onStart(): Promise<void> { for (const contribution of this.contributions.getContributions()) { if (contribution.onWillStart) { try { await this.measure(`${contribution.constructor.name}.onWillStart`, () => { if (contribution.onWillStart) { return contribution.onWillStart(this); } }); } catch (error) { console.error('contribution onWillStart', error); } } } for (const contribution of this.contributions.getContributions()) { if (contribution.onStart) { try { await this.measure(`${contribution.constructor.name}.onStart`, () => { if (contribution.onStart) { return contribution.onStart!(this); } }); } catch (error) { console.error('contribution onStart', error); } } } }
/** * Initialize and start the frontend application contributions. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/application.ts#L192-L220
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Application.onStop
protected onStop(): void { this.debugService('>>> Stopping contributions...'); for (const contribution of this.contributions.getContributions()) { if (contribution.onStop) { try { contribution.onStop(this); } catch (error) { console.error('contribution onStop', error); } } } this.debugService('<<< All contributions have been stopped.'); }
/** * Stop the frontend application contributions. This is called when the window is unloaded. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/application.ts#L262-L274
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DefaultWindowService.registerUnloadListeners
protected registerUnloadListeners(): void { window.addEventListener('beforeunload', (event) => { if (!this.canUnload()) { return this.preventUnload(event); } return undefined; }); // In a browser, `unload` is correctly fired when the page unloads, unlike Electron. // If `beforeunload` is cancelled, the user will be prompted to leave or stay. // If the user stays, the page won't be unloaded, so `unload` is not fired. // If the user leaves, the page will be unloaded, so `unload` is fired. window.addEventListener('unload', () => this.onUnloadEmitter.fire()); }
/** * Implement the mechanism to detect unloading of the page. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/default-window-service.ts#L38-L50
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DefaultWindowService.preventUnload
protected preventUnload(event: BeforeUnloadEvent): string | void { event.returnValue = ''; event.preventDefault(); return ''; }
/** * Notify the browser that we do not want to unload. * * Notes: * - Shows a confirmation popup in browsers. * - Prevents the window from closing without confirmation in electron. * * @param event The beforeunload event */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/application/default-window-service.ts#L61-L65
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.registerCommand
registerCommand(command: Command, handler?: CommandHandler): Disposable { if (this.commandMap[command.id]) { console.warn(`A command ${command.id} is already registered.`); return Disposable.NONE; } const toDispose = new DisposableCollection(this.doRegisterCommand(command)); if (handler) { toDispose.push(this.registerHandler(command.id, handler)); } this.toUnregisterCommands.set(command.id, toDispose); toDispose.push( Disposable.create(() => this.toUnregisterCommands.delete(command.id)), ); return toDispose; }
/** * Register the given command and handler if present. * * Throw if a command is already registered for the given command identifier. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L76-L90
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.registerCommandWithContext
registerCommandWithContext<T = any>( command: Command, ctx: T, handler?: CommandHandlerWithContext<T>, ): Disposable { const toDispose = new DisposableCollection(); if (this.commandMap[command.id] && !this.ctxMap[command.id]) { console.warn( `A command ${command.id} is already registered and has no registered context.`, ); return Disposable.NONE; } toDispose.push(this.registerCommand(command, handler)); toDispose.push(this.doRegisterCommandCtx(command, ctx)); return toDispose; }
/** * Register the given command with context, and handler if present. * * Throw if a command is already registered for the given command identifier. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L97-L112
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.registerHandler
registerHandler(commandId: string, handler: CommandHandler): Disposable { let handlers = this._handlers[commandId]; if (!handlers) { // eslint-disable-next-line no-multi-assign this._handlers[commandId] = handlers = []; } handlers.unshift(handler); return { dispose: () => { const idx = handlers.indexOf(handler); if (idx >= 0) { handlers.splice(idx, 1); } }, }; }
/** * Register the given handler for the given command identifier. * * If there is already a handler for the given command * then the given handler is registered as more specific, and * has higher priority during enablement, visibility and toggle state evaluations. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L160-L175
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.isEnabled
isEnabled(command: string, ...args: any[]): boolean { return typeof this.getEnableHandler(command, ...args) !== 'undefined'; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L181-L183
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.isVisible
isVisible(command: string, ...args: any[]): boolean { return typeof this.getVisibleHandler(command, ...args) !== 'undefined'; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L189-L191
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.isActive
isActive(command: string, ...args: any[]): boolean { return typeof this.getActiveHandler(command, ...args) !== 'undefined'; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L197-L199
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.isEnabledByHandler
isEnabledByHandler( handler: EnabledHandler, command: string, ...args: any[] ): boolean { const contextArgs = this.toContextArgs(command, ...args); if (handler.isEnabled) { return handler.isEnabled(...contextArgs); } return typeof this.getEnableHandler(command, ...args) !== 'undefined'; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L213-L223
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.isVisibleByHandler
isVisibleByHandler( handler: VisibleHandler, command: string, ...args: any[] ): boolean { const contextArgs = this.toContextArgs(command, ...args); if (handler.isVisible) { return handler.isVisible(...contextArgs); } return typeof this.getVisibleHandler(command, ...args) !== 'undefined'; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L229-L239
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.isActiveByHandler
isActiveByHandler(handler: ActiveHandler, command: string, ...args: any[]): boolean { const contextArgs = this.toContextArgs(command, ...args); if (handler.isActive) { return handler.isActive(...contextArgs); } return typeof this.getActiveHandler(command, ...args) !== 'undefined'; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L245-L251
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.executeCommandByHandler
executeCommandByHandler<T>( handler: ExecuteHandler, command: string, ...args: any[] ): Promise<T | undefined> { const contextArgs = this.toContextArgs(command, ...args); if (handler.execute) { return handler.execute(...contextArgs); } return this.executeCommand(command, ...args); }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L257-L267
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.executeCommand
async executeCommand<T>(commandId: string, ...args: any[]): Promise<T | undefined> { const handler = this.getEnableHandler(commandId, ...args); if (handler) { const contextArgs = this.toContextArgs(commandId, ...args); await this.fireWillExecuteCommand(commandId, contextArgs); const result = await handler.execute(...contextArgs); this.onDidExecuteCommandEmitter.fire({ commandId, args: contextArgs }); return result; } throw Object.assign( new Error( `The command '${commandId}' cannot be executed. There are no active handlers available for the command.`, ), { code: 'NO_ACTIVE_HANDLER' }, ); }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L275-L290
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.fireWillExecuteCommand
protected async fireWillExecuteCommand( commandId: string, args: any[] = [], ): Promise<void> { await WaitUntilEvent.fire( this.onWillExecuteCommandEmitter, { commandId, args }, 30000, ); }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L293-L302
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.getVisibleHandler
getVisibleHandler(commandId: string, ...args: any[]): CommandHandler | undefined { const contextArgs = this.toContextArgs(commandId, ...args); const handlers = this._handlers[commandId]; if (handlers) { for (const handler of handlers) { try { if (!handler.isVisible || handler.isVisible(...contextArgs)) { return handler; } } catch (error) { console.error(error); } } } return undefined; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L308-L323
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.getEnableHandler
getEnableHandler(commandId: string, ...args: any[]): CommandHandler | undefined { const contextArgs = this.toContextArgs(commandId, ...args); const handlers = this._handlers[commandId]; if (handlers) { for (const handler of handlers) { try { if (!handler.isEnabled || handler.isEnabled(...contextArgs)) { return handler; } } catch (error) { console.error(error); } } } return undefined; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L329-L344
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.getActiveHandler
getActiveHandler(commandId: string, ...args: any[]): CommandHandler | undefined { const contextArgs = this.toContextArgs(commandId, ...args); const handlers = this._handlers[commandId]; if (handlers) { for (const handler of handlers) { try { if (handler.isActive && handler.isActive(...contextArgs)) { return handler; } } catch (error) { console.error(error); } } } return undefined; }
// eslint-disable-next-line @typescript-eslint/no-explicit-any
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L350-L365
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.getAllHandlers
getAllHandlers(commandId: string): CommandHandler[] { const handlers = this._handlers[commandId]; return handlers ? handlers.slice() : []; }
/** * Returns with all handlers for the given command. If the command does not have any handlers, * or the command is not registered, returns an empty array. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L371-L374
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.commands
get commands(): Command[] { const commands: Command[] = []; for (const id of this.commandIds) { const cmd = this.getCommand(id); if (cmd) { commands.push(cmd); } } return commands; }
/** * Get all registered commands. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L379-L388
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.getCommand
getCommand(id: string): Command | undefined { return this.commandMap[id]; }
/** * Get a command for the given command identifier. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L393-L395
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.commandIds
get commandIds(): string[] { return Object.keys(this.commandMap); }
/** * Get all registered commands identifiers. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L400-L402
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.addRecentCommand
addRecentCommand(recent: Command | Command[]): void { if (Array.isArray(recent)) { recent.forEach((command: Command) => this.addRecentCommand(command)); } else { // Determine if the command currently exists in the recently used list. const index = this.recent.findIndex((command: Command) => Command.equals(recent, command), ); // If the command exists, remove it from the array so it can later be placed at the top. if (index >= 0) { this.recent.splice(index, 1); } // Add the recent command to the beginning of the array (most recent). this.recent.unshift(recent); } }
/** * Adds a command to recently used list. * Prioritizes commands that were recently executed to be most recent. * * @param recent a recent command, or array of recent commands. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L409-L424
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
CommandRegistry.clearCommandHistory
clearCommandHistory(): void { this.recent = []; }
/** * Clear the list of recently used commands. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/command/command-registry.ts#L429-L431
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
LocalStorageService.testLocalStorage
private testLocalStorage(): void { const keyTest = this.prefix('Test'); try { this.storage[keyTest] = JSON.stringify(new Array(60000)); } catch (error) { this.onDiskQuotaExceededEmitter.fire(); } finally { this.storage.removeItem?.(keyTest); } }
/** * Verify if there is still some spaces left to save another workspace configuration into the local storage of your browser. * If we are close to the limit, use a dialog to notify the user. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/common/storage-service.ts#L65-L74
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DefaultConfigurationProvider.canHandle
canHandle(storage: ConfigurationStorage): false | number { if (storage === DefaultConfigurationStorage) { return 100; } return 0; }
/** * 默认用内存的provider * @returns */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/configuration-provider.ts#L49-L54
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ConfigurationRegistry.registerConfiguration
registerConfiguration(configuration: ConfigurationNode<any>) { const config = this.findConfiguration(configuration.id); if (config && config.overridable === false) { console.warn(`cannot override configuration: ${config.id}`); return; } this.schemaValidator.addSchema(configuration); this.deregisterConfiguration(configuration); this.configurationNodes.push(configuration as ConfigurationNode<unknown>); const scope = this.getStorage(configuration); this.addStorage(scope); }
/** * Register a configuration to the registry. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/configuration-registry.ts#L99-L112
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ConfigurationRegistry.registerConfigurations
registerConfigurations(configurations: ConfigurationNode<any>[]) { configurations.forEach((config) => { this.registerConfiguration(config); }); }
/** * Register multiple configurations to the registry. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/configuration-registry.ts#L117-L121
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ConfigurationRegistry.deregisterConfigurations
deregisterConfigurations(configurations: ConfigurationNode<any>[]) { configurations.forEach((config) => { this.deregisterConfiguration(config); }); }
/** * Deregister multiple configurations from the registry. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/configuration-registry.ts#L126-L130
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ConfigurationRegistry.addStorage
addStorage(scope: ConfigurationStorage) { if ( this.scopes.get(scope.id) && this.scopes.get(scope.id)?.priority !== scope.priority ) { console.warn('添加scope时,scopeId相同,priority不一致'); return; } if (!this.scopes.has(scope.id)) { this.scopes.set(scope.id, scope); } }
/** * 添加scope,已包含错误处理 */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/configuration-registry.ts#L169-L180
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ConfigurationService.set
async set<T>( node: ConfigurationNode<T>, value: T, options?: { useCache?: boolean; validate?: boolean }, ) { if ( options?.validate !== false && !this.schemaValidator.validateNode(node, value) ) { return; } const useCache = options?.useCache ?? true; const setStorage = this.configurationRegistry.getStorage(node); this.configurationRegistry.addStorage(setStorage); const provider = this.getConfigurationProviderByStorage(setStorage); if (!provider) { return; } if (provider.enableCache && useCache) { this.configurationCache.set(provider, node, value); } await provider.set(node, value); this.onConfigurationValueChangeEmitter.fire({ key: node.id, value }); }
/** * * @param node 配置 * @param value 配置的值 * @param options * @returns */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/configuration-service.ts#L128-L151
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
SchemaValidator.addSchema
addSchema<T>(node: ConfigurationNode<T>) { getOrigin(this.ajvInstance).addSchema(node.schema, node.id); }
/** * https://ajv.js.org/guide/managing-schemas.html#using-ajv-instance-cache */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/configuration/validation.ts#L14-L16
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.onKeybindingsChanged
get onKeybindingsChanged(): Event<void> { return this.keybindingsChanged.event; }
/** * Event that is fired when the resolved keybindings change due to a different keyboard layout * or when a new keymap is being set */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L229-L231
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.registerContext
protected registerContext(...contexts: KeybindingContext[]): void { for (const context of contexts) { const { id } = context; if (this.contexts[id]) { this.logger(`A keybinding context with ID ${id} is already registered.`); } else { this.contexts[id] = context; } } }
/** * Registers the keybinding context arguments into the application. Fails when an already registered * context is being registered. * * @param contexts the keybinding contexts to register into the application. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L239-L248
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.registerKeybinding
registerKeybinding(binding: Keybinding): Disposable { return this.doRegisterKeybinding(binding); }
/** * Register a default keybinding to the registry. * * Keybindings registered later have higher priority during evaluation. * * @param binding the keybinding to be registered */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L257-L259
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.registerKeybindings
registerKeybindings(...bindings: Keybinding[]): Disposable { return this.doRegisterKeybindings(bindings, KeybindingScope.DEFAULT); }
/** * Register multiple default keybindings to the registry * * @param bindings An array of keybinding to be registered */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L266-L268
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.insertBindingIntoScope
protected insertBindingIntoScope( item: Keybinding & { scope: KeybindingScope }, scope: KeybindingScope, ): void { const scopedKeymap = this.keymaps[scope]; const getNumberOfKeystrokes = (binding: Keybinding): number => (binding.keybinding.trim().match(/\s/g)?.length ?? 0) + 1; const numberOfKeystrokesInBinding = getNumberOfKeystrokes(item); const indexOfFirstItemWithEqualStrokes = scopedKeymap.findIndex( (existingBinding) => getNumberOfKeystrokes(existingBinding) === numberOfKeystrokesInBinding, ); if (indexOfFirstItemWithEqualStrokes > -1) { scopedKeymap.splice(indexOfFirstItemWithEqualStrokes, 0, item); } else { scopedKeymap.push(item); } }
/** * Ensures that keybindings are inserted in order of increasing length of binding to ensure that if a * user triggers a short keybinding (e.g. ctrl+k), the UI won't wait for a longer one (e.g. ctrl+k enter) */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L339-L356
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.resolveKeybinding
resolveKeybinding(binding: ResolvedKeybinding): KeyCode[] { if (!binding.resolved) { const sequence = KeySequence.parse(binding.keybinding); binding.resolved = sequence.map((code) => this.keyboardLayoutService.resolveKeyCode(code), ); } return binding.resolved; }
/** * Ensure that the `resolved` property of the given binding is set by calling the KeyboardLayoutService. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L361-L369
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.clearResolvedKeybindings
protected clearResolvedKeybindings(): void { for (let i = KeybindingScope.DEFAULT; i < KeybindingScope.END; i++) { const bindings = this.keymaps[i]; for (let j = 0; j < bindings.length; j++) { const binding = bindings[j] as ResolvedKeybinding; binding.resolved = undefined; } } }
/** * Clear all `resolved` properties of registered keybindings so the KeyboardLayoutService is called * again to resolve them. This is necessary when the user's keyboard layout has changed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L375-L383
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.containsKeybindingInScope
containsKeybindingInScope( binding: Keybinding, scope = KeybindingScope.USER, ): boolean { const bindingKeySequence = this.resolveKeybinding(binding); const collisions = this.getKeySequenceCollisions( this.getUsableBindings(this.keymaps[scope]), bindingKeySequence, ).filter((b) => b.context === binding.context && !b.when && !binding.when); if (collisions.full.length > 0) { return true; } if (collisions.partial.length > 0) { return true; } if (collisions.shadow.length > 0) { return true; } return false; }
/** * Checks whether a colliding {@link common.Keybinding} exists in a specific scope. * @param binding the keybinding to check * @param scope the keybinding scope to check * @returns true if there is a colliding keybinding */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L391-L410
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.acceleratorFor
acceleratorFor(keybinding: Keybinding, separator = ' '): string[] { const bindingKeySequence = this.resolveKeybinding(keybinding); return this.acceleratorForSequence(bindingKeySequence, separator); }
/** * Get a user visible representation of a {@link common.Keybinding}. * @returns an array of strings representing all elements of the {@link KeySequence} defined by the {@link common.Keybinding} * @param keybinding the keybinding * @param separator the separator to be used to stringify {@link KeyCode}s that are part of the {@link KeySequence} */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L418-L421
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.acceleratorForSequence
acceleratorForSequence(keySequence: KeySequence, separator = ' '): string[] { return keySequence.map((keyCode) => this.acceleratorForKeyCode(keyCode, separator)); }
/** * Get a user visible representation of a {@link KeySequence}. * @returns an array of strings representing all elements of the {@link KeySequence} * @param keySequence the keysequence * @param separator the separator to be used to stringify {@link KeyCode}s that are part of the {@link KeySequence} */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L429-L431
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.acceleratorForKeyCode
acceleratorForKeyCode(keyCode: KeyCode, separator = ' '): string { const keyCodeResult = []; if (keyCode.meta && isOSX) { keyCodeResult.push('Cmd'); } if (keyCode.ctrl) { keyCodeResult.push('Ctrl'); } if (keyCode.alt) { keyCodeResult.push('Alt'); } if (keyCode.shift) { keyCodeResult.push('Shift'); } if (keyCode.key) { keyCodeResult.push(this.acceleratorForKey(keyCode.key)); } return keyCodeResult.join(separator); }
/** * Get a user visible representation of a key code (a key with modifiers). * @returns a string representing the {@link KeyCode} * @param keyCode the keycode * @param separator the separator used to separate keys (key and modifiers) in the returning string */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L439-L457
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.acceleratorForKey
acceleratorForKey(key: Key): string { if (isOSX) { if (key === Key.ARROW_LEFT) { return '←'; } if (key === Key.ARROW_RIGHT) { return '→'; } if (key === Key.ARROW_UP) { return '↑'; } if (key === Key.ARROW_DOWN) { return '↓'; } } const keyString = this.keyboardLayoutService.getKeyboardCharacter(key); if ( (key.keyCode >= Key.KEY_A.keyCode && key.keyCode <= Key.KEY_Z.keyCode) || (key.keyCode >= Key.F1.keyCode && key.keyCode <= Key.F24.keyCode) ) { return keyString.toUpperCase(); } if (keyString.length > 1) { return keyString.charAt(0).toUpperCase() + keyString.slice(1); } return keyString; }
/** * Return a user visible representation of a single key. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L462-L488
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.getKeySequenceCollisions
protected getKeySequenceCollisions( bindings: ScopedKeybinding[], candidate: KeySequence, ): KeybindingRegistry.KeybindingsResult { const result = new KeybindingRegistry.KeybindingsResult(); for (const binding of bindings) { try { const bindingKeySequence = this.resolveKeybinding(binding); const compareResult = KeySequence.compare(candidate, bindingKeySequence); switch (compareResult) { case KeySequence.CompareResult.FULL: { result.full.push(binding); break; } case KeySequence.CompareResult.PARTIAL: { result.partial.push(binding); break; } case KeySequence.CompareResult.SHADOW: { result.shadow.push(binding); break; } } } catch (error) { this.logger(error); } } return result; }
/** * Finds collisions for a key sequence inside a list of bindings (error-free) * * @param bindings the reference bindings * @param candidate the sequence to match */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L496-L524
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.getKeybindingsForCommand
getKeybindingsForCommand(commandId: string): ScopedKeybinding[] { const result: ScopedKeybinding[] = []; for ( let scope = KeybindingScope.END - 1; scope >= KeybindingScope.DEFAULT; scope-- ) { this.keymaps[scope].forEach((binding) => { const command = this.commandRegistry.getCommand(binding.command); if (command) { if (command.id === commandId) { result.push({ ...binding, scope }); } } }); if (result.length > 0) { return result; } } return result; }
/** * Get all keybindings associated to a commandId. * * @param commandId The ID of the command for which we are looking for keybindings. * @returns an array of {@link ScopedKeybinding} */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L532-L554
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.executeKeyBinding
protected executeKeyBinding(binding: Keybinding, event: KeyboardEvent): void { if (this.isPseudoCommand(binding.command)) { /* Don't do anything, let the event propagate. */ } else { const command = this.commandRegistry.getCommand(binding.command); if (command) { if (this.commandRegistry.isEnabled(binding.command, binding.args)) { this.commandRegistry .executeCommand(binding.command, binding.args) .catch((e) => console.error('Failed to execute command:', e)); } /* Note that if a keybinding is in context but the command is not active we still stop the processing here. */ const { preventDefault = this.preventDefault, stopPropagation = this.stopPropagation, } = binding; if (preventDefault) { event.preventDefault(); } if (stopPropagation) { event.stopPropagation(); } } } }
// eslint-disable-next-line @typescript-eslint/no-unused-vars
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L574-L600
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.isEnabled
protected isEnabled(binding: Keybinding, event: KeyboardEvent): boolean { const context = binding.context && this.contexts[binding.context]; if (context && !context.isEnabled(binding)) { return false; } if ( binding.when && !this.whenContextService.match(binding.when, <HTMLElement>event.target) ) { return false; } return true; }
/** * Only execute if it has no context (global context) or if we're in that context. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L605-L617
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.run
run(event: KeyboardEvent): void { if (event.defaultPrevented) { return; } const keyCode = KeyCode.createKeyCode(event, 'code'); /* Keycode is only a modifier, next keycode will be modifier + key. Ignore this one. */ if (keyCode.isModifierOnly()) { return; } this.keyboardLayoutService.validateKeyCode(keyCode); this.keySequence.push(keyCode); const match = this.matchKeybinding(this.keySequence, event); if (match && match.kind === 'partial') { /* Accumulate the keysequence */ // TODO: The effective scope of of prevent propagation. const { preventDefault = this.preventDefault, stopPropagation = this.stopPropagation, } = match.binding; if (preventDefault) { event.preventDefault(); } if (stopPropagation) { event.stopPropagation(); } this.emitter.fire(match); } else { if (match && match.kind === 'full') { this.executeKeyBinding(match.binding, event); } this.keySequence = []; this.emitter.fire(match); } }
/** * Run the command matching to the given keyboard event. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L659-L696
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.matchKeybinding
matchKeybinding( keySequence: KeySequence, event?: KeyboardEvent, ): KeybindingRegistry.Match { let disabled: Set<string> | undefined; const isEnabled = (binding: ScopedKeybinding) => { if (event && !this.isEnabled(binding, event)) { return false; } const { command, context, when, keybinding } = binding; if (!this.isUsable(binding)) { disabled = disabled || new Set<string>(); disabled.add( JSON.stringify({ command: command.substr(1), context, when, keybinding }), ); return false; } return !disabled?.has(JSON.stringify({ command, context, when, keybinding })); }; for (let scope = KeybindingScope.END; --scope >= KeybindingScope.DEFAULT; ) { for (const binding of this.keymaps[scope]) { const resolved = this.resolveKeybinding(binding); const compareResult = KeySequence.compare(keySequence, resolved); if (compareResult === KeySequence.CompareResult.FULL && isEnabled(binding)) { return { kind: 'full', binding }; } if (compareResult === KeySequence.CompareResult.PARTIAL && isEnabled(binding)) { return { kind: 'partial', binding }; } } } return undefined; }
/** * Match first binding in the current context. * Keybindings ordered by a scope and by a registration order within the scope. * * FIXME: * This method should run very fast since it happens on each keystroke. We should reconsider how keybindings are stored. * It should be possible to look up full and partial keybinding for given key sequence for constant time using some kind of tree. * Such tree should not contain disabled keybindings and be invalidated whenever the registry is changed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L711-L744
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.isUsable
protected isUsable(binding: Keybinding): boolean { return binding.command.charAt(0) !== '-'; }
/** * Returns true if the binding is usable * @param binding Binding to be checked */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L750-L752
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.getUsableBindings
protected getUsableBindings<T extends Keybinding>(bindings: T[]): T[] { return bindings.filter((binding) => this.isUsable(binding)); }
/** * Return a new filtered array containing only the usable bindings among the input bindings * @param bindings Bindings to filter */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L758-L760
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.isPseudoCommand
isPseudoCommand(commandId: string): boolean { return commandId === KeybindingRegistry.PASSTHROUGH_PSEUDO_COMMAND; }
/** * Return true of string a pseudo-command id, in other words a command id * that has a special meaning and that we won't find in the command * registry. * * @param commandId commandId to test */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L769-L771
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.setKeymap
setKeymap(scope: KeybindingScope, bindings: Keybinding[]): void { this.resetKeybindingsForScope(scope); this.toResetKeymap.set(scope, this.doRegisterKeybindings(bindings, scope)); this.keybindingsChanged.fire(undefined); }
/** * Sets a new keymap replacing all existing {@link common.Keybinding}s in the given scope. * @param scope the keybinding scope * @param bindings an array containing the new {@link common.Keybinding}s */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L778-L782
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.resetKeybindingsForScope
resetKeybindingsForScope(scope: KeybindingScope): void { const toReset = this.toResetKeymap.get(scope); if (toReset) { toReset.dispose(); } }
/** * Reset keybindings for a specific scope * @param scope scope to reset the keybindings for */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L790-L795
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.resetKeybindings
resetKeybindings(): void { for (let i = KeybindingScope.DEFAULT + 1; i < KeybindingScope.END; i++) { this.keymaps[i] = []; } }
/** * Reset keybindings for all scopes(only leaves the default keybindings mapped) */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L800-L804
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingRegistry.getKeybindingsByScope
getKeybindingsByScope(scope: KeybindingScope): ScopedKeybinding[] { return this.keymaps[scope]; }
/** * Get all {@link common.Keybinding}s for a {@link KeybindingScope}. * @returns an array of {@link common.ScopedKeybinding} * @param scope the keybinding scope to retrieve the {@link common.Keybinding}s for. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L811-L813
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingsResult.merge
merge(other: KeybindingsResult): KeybindingsResult { this.full.push(...other.full); this.partial.push(...other.partial); this.shadow.push(...other.shadow); return this; }
/** * Merge two results together inside `this` * * @param other the other KeybindingsResult to merge with * @return this */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L836-L841
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeybindingsResult.filter
filter(fn: (binding: Keybinding) => boolean): KeybindingsResult { const result = new KeybindingsResult(); result.full = this.full.filter(fn); result.partial = this.partial.filter(fn); result.shadow = this.shadow.filter(fn); return result; }
/** * Returns a new filtered KeybindingsResult * * @param fn callback filter on the results * @return filtered new result */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/keybinding.ts#L849-L855
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ConfigurationModel.setValue
public setValue(key: string, value: any) { this.addKey(key); addToValueTree(this.contents, key, value, (e) => { throw new Error(e); }); }
// Update methods
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/vs/configuration/configurationModels.ts#L268-L273
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ensurePropertyComplete
function ensurePropertyComplete(endOffset: number) { if (currentParent.type === 'property') { currentParent.length = endOffset - currentParent.offset; currentParent = currentParent.parent!; } }
// artificial root
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keybinding/vs/configuration/json.ts#L947-L952
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
BrowserKeyboardLayoutProvider.getLayoutData
protected getLayoutData( layoutId: string, raw: NativeKeyboardLayout, ): KeyboardLayoutData { const [language, name, hardware] = layoutId.split('-'); return { name: name.replace('_', ' '), hardware: hardware as 'pc' | 'mac', language, // Webpack knows what to do here and it should bundle all files under `../../../src/common/keyboard/layouts/` raw: raw, }; }
/** * Keyboard layout files are expected to have the following name scheme: * `language-name-hardware.json` * * - `language`: A language subtag according to IETF BCP 47 * - `name`: Display name of the keyboard layout (without dashes) * - `hardware`: `pc` or `mac` */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/browser-keyboard-layout-provider.ts#L65-L77
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
BrowserKeyboardLayoutProvider.setLayoutData
async setLayoutData( layout: KeyboardLayoutData | 'autodetect', ): Promise<KeyboardLayoutData> { if (layout === 'autodetect') { if (this.source === 'user-choice') { const [newLayout, source] = await this.autodetect(); this.setCurrent(newLayout, source); this.nativeLayoutChanged.fire(newLayout.raw); return newLayout; } return this.currentLayout; } else { if (this.source !== 'user-choice' || layout !== this.currentLayout) { this.setCurrent(layout, 'user-choice'); this.nativeLayoutChanged.fire(layout.raw); } return layout; } }
/** * Set user-chosen keyboard layout data. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/browser-keyboard-layout-provider.ts#L135-L153
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
BrowserKeyboardLayoutProvider.validateKey
validateKey(keyCode: KeyValidationInput): void { if (this.source !== 'pressed-keys') { return; } const accepted = this.tester.updateScores(keyCode); if (!accepted) { return; } const layout = this.selectLayout(); if (layout !== this.currentLayout && layout !== DEFAULT_LAYOUT_DATA) { this.setCurrent(layout, 'pressed-keys'); this.nativeLayoutChanged.fire(layout.raw); } }
/** * Test all known keyboard layouts with the given combination of pressed key and * produced character. Matching layouts have their score increased (see class * KeyboardTester). If this leads to a change of the top-scoring layout, a layout * change event is fired. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/browser-keyboard-layout-provider.ts#L161-L174
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
BrowserKeyboardLayoutProvider.testLayoutMap
protected testLayoutMap(layoutMap: KeyboardLayoutMap): void { this.tester.reset(); for (const [code, key] of layoutMap.entries()) { this.tester.updateScores({ code, character: key }); } }
/** * @param layoutMap a keyboard layout map according to https://wicg.github.io/keyboard-map/ */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/browser-keyboard-layout-provider.ts#L209-L214
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
BrowserKeyboardLayoutProvider.selectLayout
protected selectLayout(): KeyboardLayoutData { const candidates = this.tester.candidates; const scores = this.tester.scores; const topScore = this.tester.topScore; const language = navigator.language; let matchingOScount = 0; let topScoringCount = 0; for (let i = 0; i < candidates.length; i++) { if (scores[i] === topScore) { const candidate = candidates[i]; if (osMatches(candidate.hardware)) { if (language && language.startsWith(candidate.language)) { return candidate; } matchingOScount++; } topScoringCount++; } } if (matchingOScount >= 1) { return candidates.find( (c, i) => scores[i] === topScore && osMatches(c.hardware), )!; } if (topScoringCount >= 1) { return candidates.find((_, i) => scores[i] === topScore)!; } return DEFAULT_LAYOUT_DATA; }
/** * Select a layout based on the current tester state and the operating system * and language detected from the browser. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/browser-keyboard-layout-provider.ts#L220-L248
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyboardLayoutService.resolveKeyCode
resolveKeyCode(inCode: KeyCode): KeyCode { const layout = this.currentLayout; if (layout && inCode.key) { for (let shift = 0; shift <= 1; shift++) { const index = this.getCharacterIndex(inCode.key, !!shift); const mappedCode = layout.key2KeyCode[index]; if (mappedCode) { const transformed = this.transformKeyCode(inCode, mappedCode, !!shift); if (transformed) { return transformed; } } } } return inCode; }
/** * Resolve a KeyCode of a keybinding using the current keyboard layout. * If no keyboard layout has been detected or the layout does not contain the * key used in the KeyCode, the KeyCode is returned unchanged. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keyboard-layout-service.ts#L77-L92
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyboardLayoutService.getKeyboardCharacter
getKeyboardCharacter(key: Key): string { const layout = this.currentLayout; if (layout) { const value = layout.code2Character[key.code]; if (value && value.replace(/[\n\r\t]/g, '')) { return value; } } return key.easyString; }
/** * Return the character shown on the user's keyboard for the given key. * Use this to determine UI representations of keybindings. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keyboard-layout-service.ts#L98-L107
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyboardLayoutService.validateKeyCode
validateKeyCode(keyCode: KeyCode): void { if (this.keyValidator && keyCode.key && keyCode.character) { this.keyValidator.validateKey({ code: keyCode.key.code, character: keyCode.character, shiftKey: keyCode.shift, ctrlKey: keyCode.ctrl, altKey: keyCode.alt, }); } }
/** * Called when a KeyboardEvent is processed by the KeybindingRegistry. * The KeyValidator may trigger a keyboard layout change. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keyboard-layout-service.ts#L113-L123
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyCode.isModifierOnly
public isModifierOnly(): boolean { return this.key === undefined; }
/** * Return true if this KeyCode only contains modifiers. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keys.ts#L130-L132
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyCode.equals
equals(other: KeyCode): boolean { if ( (this.key && (!other.key || this.key.code !== other.key.code)) || (!this.key && other.key) ) { return false; } return ( this.ctrl === other.ctrl && this.alt === other.alt && this.shift === other.shift && this.meta === other.meta ); }
/** * Return true if the given KeyCode is equal to this one. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keys.ts#L137-L150
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyCode.toString
toString(): string { const result = []; if (this.meta) { result.push(SpecialCases.META); } if (this.shift) { result.push(Key.SHIFT_LEFT.easyString); } if (this.alt) { result.push(Key.ALT_LEFT.easyString); } if (this.ctrl) { result.push(Key.CONTROL_LEFT.easyString); } if (this.key) { result.push(this.key.easyString); } return result.join('+'); }
/* * Return a keybinding string compatible with the `Keybinding.keybinding` property. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keys.ts#L155-L173
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyCode.createKeyCode
public static createKeyCode( input: KeyboardEvent | Keystroke | KeyCodeSchema | string, eventDispatch: 'code' | 'keyCode' = 'code', ): KeyCode { if (typeof input === 'string') { const parts = input.split('+'); if (!KeyCode.isModifierString(parts[0])) { return KeyCode.createKeyCode({ first: Key.getKey(parts[0]), modifiers: parts.slice(1) as KeyModifier[], }); } return KeyCode.createKeyCode({ modifiers: parts as KeyModifier[] }); } if (KeyCode.isKeyboardEvent(input)) { const key = KeyCode.toKey(input, eventDispatch); return new KeyCode({ key: Key.isModifier(key.code) ? undefined : key, meta: isOSX && input.metaKey, shift: input.shiftKey, alt: input.altKey, ctrl: input.ctrlKey, character: KeyCode.toCharacter(input), }); } if ((input as Keystroke).first || (input as Keystroke).modifiers) { const keystroke = input as Keystroke; const schema: KeyCodeSchema = { key: keystroke.first, }; if (keystroke.modifiers) { if (isOSX) { schema.meta = keystroke.modifiers.some((mod) => mod === KeyModifier.CtrlCmd); schema.ctrl = keystroke.modifiers.some((mod) => mod === KeyModifier.MacCtrl); } else { schema.meta = false; schema.ctrl = keystroke.modifiers.some((mod) => mod === KeyModifier.CtrlCmd); } schema.shift = keystroke.modifiers.some((mod) => mod === KeyModifier.Shift); schema.alt = keystroke.modifiers.some((mod) => mod === KeyModifier.Alt); } return new KeyCode(schema); } return new KeyCode(input as KeyCodeSchema); }
/** * Create a KeyCode from one of several input types. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keys.ts#L178-L222
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyCode.resetKeyBindings
public static resetKeyBindings(): void { KeyCode.keybindings = {}; }
/* Reset the key hashmap, this is for testing purposes. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keys.ts#L227-L229
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
KeyCode.parse
public static parse(keybinding: string): KeyCode { if (KeyCode.keybindings[keybinding]) { return KeyCode.keybindings[keybinding]; } const schema: KeyCodeSchema = {}; const keys = []; let currentKey = ''; for (const character of keybinding.trim().toLowerCase()) { if (currentKey && (character === '-' || character === '+')) { keys.push(currentKey); currentKey = ''; } else if (character !== '+') { currentKey += character; } } if (currentKey) { keys.push(currentKey); } /* If duplicates i.e ctrl+ctrl+a or alt+alt+b or b+alt+b it is invalid */ if (keys.length !== new Set(keys).size) { throw new Error(`Can't parse keybinding ${keybinding} Duplicate modifiers`); } for (let keyString of keys) { if (SPECIAL_ALIASES[keyString] !== undefined) { keyString = SPECIAL_ALIASES[keyString]; } const key = EASY_TO_KEY[keyString]; /* meta only works on macOS */ if (keyString === SpecialCases.META) { if (isOSX) { schema.meta = true; } else { throw new Error(`Can't parse keybinding ${keybinding} meta is for OSX only`); } /* ctrlcmd for M1 keybindings that work on both macOS and other platforms */ } else if (keyString === SpecialCases.CTRLCMD) { if (isOSX) { schema.meta = true; } else { schema.ctrl = true; } } else if (Key.isKey(key)) { if (Key.isModifier(key.code)) { if ( key.code === Key.CONTROL_LEFT.code || key.code === Key.CONTROL_RIGHT.code ) { schema.ctrl = true; } else if ( key.code === Key.SHIFT_LEFT.code || key.code === Key.SHIFT_RIGHT.code ) { schema.shift = true; } else if ( key.code === Key.ALT_LEFT.code || key.code === Key.ALT_RIGHT.code ) { schema.alt = true; } } else { schema.key = key; } } else { throw new Error(`Unrecognized key '${keyString}' in '${keybinding}'`); } } KeyCode.keybindings[keybinding] = new KeyCode(schema); return KeyCode.keybindings[keybinding]; }
/** * Parses a string and returns a KeyCode object. * @param keybinding String representation of a keybinding */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/keyboard/keys.ts#L235-L307
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DefaultGeneralMenuItem.addNode
public addNode = (item: MenuItem): MenuItem => { this.children.push(item); const remove = () => { const idx = this.children.indexOf(getOrigin(item)); if (idx >= 0) { this.children.splice(idx, 1); } }; item.onDisposed(remove); return item; }
/** * Inserts the given node at the position indicated by `sortString`. * * @returns a disposable which, when called, will remove the given node again. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/default-menu-node.ts
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DefaultGeneralMenuItem.removeNode
public removeNode(id: string): void { const node = this.children.find((n) => n.id === id); if (node) { const idx = this.children.indexOf(node); if (idx >= 0) { this.children.splice(idx, 1); } } }
/** * Removes the first node with the given id. * * @param id node id. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/default-menu-node.ts#L189-L197
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
MenuRegistry.registerMenuAction
registerMenuAction(menuPath: MenuPath, item: ActionMenuNode): Disposable { const menuNode = this.actionItemFactory(item, menuPath); const parent = this.getOrCreateGroup(menuPath); return parent.addNode(menuNode); }
/** * Adds the given menu action to the menu denoted by the given path. * * @returns a disposable which, when called, will remove the menu action again. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/menu-registry.ts#L68-L72
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
MenuRegistry.registerMenuNode
registerMenuNode(menuPath: MenuPath, item: MenuNode): Disposable { const menuNode = this.generalItemFactory(item, menuPath); const parent = this.getOrCreateGroup(menuPath); return parent.addNode(menuNode); }
/** * Adds the given menu node to the menu denoted by the given path. * * @returns a disposable which, when called, will remove the menu node again. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/menu-registry.ts#L79-L83
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
MenuRegistry.registerSubmenu
registerSubmenu(menuPath: MenuPath, options: MenuOptions = {}): Disposable { if (menuPath.length === 0) { throw new Error('The sub menu path cannot be empty.'); } const index = menuPath.length - 1; const menuId = menuPath[index]; const groupPath = index === 0 ? [] : menuPath.slice(0, index); const parent = this.getOrCreateGroup(groupPath, options); let groupNode = this.getOrCreateSub(parent, menuId, options); if (!groupNode) { groupNode = this.generalItemFactory({ id: menuId, ...options }, parent.path); return parent.addNode(groupNode); } if (options.label) { groupNode.label = options.label; } if (options.icon) { groupNode.icon = options.icon; } if (options.order) { groupNode.order = options.order; } return Disposable.NONE; }
/** * Register a new menu at the given path with the given label. * (If the menu already exists without a label, iconClass or order this method can be used to set them.) * * @param menuPath the path for which a new submenu shall be registered. * @param label the label to be used for the new submenu. * @param options optionally allows to set an icon class and specify the order of the new menu. * * @returns if the menu was successfully created a disposable will be returned which, * when called, will remove the menu again. If the menu already existed a no-op disposable * will be returned. * * Note that if the menu already existed and was registered with a different label an error * will be thrown. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/menu-registry.ts#L125-L148
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
MenuRegistry.unregisterMenuNode
unregisterMenuNode(id: string): void { const recurse = (root: GeneralMenuItem) => { root.children.forEach((node) => { if (MenuItem.isGeneralMenuItem(node)) { node.removeNode(id); recurse(node); } }); }; recurse(this.root); }
/** * Recurse all menus, removing any menus matching the `id`. * * @param id technical identifier of the `MenuNode`. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/menu-registry.ts#L187-L197
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
MenuRegistry.getMenu
getMenu(menuPath: MenuPath = []): GeneralMenuItem { return this.getOrCreateGroup(menuPath); }
/** * Returns the menu at the given path. * * @param menuPath the path specifying the menu to return. If not given the empty path will be used. * * @returns the root menu when `menuPath` is empty. If `menuPath` is not empty the specified menu is * returned if it exists, otherwise an error is thrown. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/menu/menu-registry.ts#L235-L237
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
BaseVariableRegistry.getVariables
getVariables(): IterableIterator<string> { return this.getDefinitionIds(); }
/** * @deprecated using getDefinitionIds instead * */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/base-variable-registry.ts#L44-L46
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
HSLA.fromRGBA
static fromRGBA(rgba: RGBA): HSLA { const r = rgba.r / 255; const g = rgba.g / 255; const b = rgba.b / 255; const { a } = rgba; const max = Math.max(r, g, b); const min = Math.min(r, g, b); let h = 0; let s = 0; const l = (min + max) / 2; const chroma = max - min; if (chroma > 0) { s = Math.min(l <= 0.5 ? chroma / (2 * l) : chroma / (2 - 2 * l), 1); switch (max) { case r: h = (g - b) / chroma + (g < b ? 6 : 0); break; case g: h = (b - r) / chroma + 2; break; case b: h = (r - g) / chroma + 4; break; } h *= 60; h = Math.round(h); } return new HSLA(h, s, l, a); }
/** * Converts an RGB color value to HSL. Conversion formula * adapted from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes r, g, and b are contained in the set [0, 255] and * returns h in the set [0, 360], s, and l in the set [0, 1]. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L89-L121
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
HSLA.toRGBA
static toRGBA(hsla: HSLA): RGBA { const h = hsla.h / 360; const { s, l, a } = hsla; let r: number; let g: number; let b: number; if (s === 0) { r = g = b = l; // achromatic } else { const q = l < 0.5 ? l * (1 + s) : l + s - l * s; const p = 2 * l - q; r = HSLA._hue2rgb(p, q, h + 1 / 3); g = HSLA._hue2rgb(p, q, h); b = HSLA._hue2rgb(p, q, h - 1 / 3); } return new RGBA(Math.round(r * 255), Math.round(g * 255), Math.round(b * 255), a); }
/** * Converts an HSL color value to RGB. Conversion formula * adapted from http://en.wikipedia.org/wiki/HSL_color_space. * Assumes h in the set [0, 360] s, and l are contained in the set [0, 1] and * returns r, g, and b in the set [0, 255]. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L148-L166
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
HSVA.fromRGBA
static fromRGBA(rgba: RGBA): HSVA { const r = rgba.r / 255; const g = rgba.g / 255; const b = rgba.b / 255; const cmax = Math.max(r, g, b); const cmin = Math.min(r, g, b); const delta = cmax - cmin; const s = cmax === 0 ? 0 : delta / cmax; let m: number; if (delta === 0) { m = 0; } else if (cmax === r) { m = ((((g - b) / delta) % 6) + 6) % 6; } else if (cmax === g) { m = (b - r) / delta + 2; } else { m = (r - g) / delta + 4; } return new HSVA(Math.round(m * 60), s, cmax, rgba.a); }
// from http://www.rapidtables.com/convert/color/rgb-to-hsv.htm
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L204-L225
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
HSVA.toRGBA
static toRGBA(hsva: HSVA): RGBA { const { h, s, v, a } = hsva; const c = v * s; const x = c * (1 - Math.abs(((h / 60) % 2) - 1)); const m = v - c; let [r, g, b] = [0, 0, 0]; if (h < 60) { r = c; g = x; } else if (h < 120) { r = x; g = c; } else if (h < 180) { g = c; b = x; } else if (h < 240) { g = x; b = c; } else if (h < 300) { r = x; b = c; } else if (h <= 360) { r = c; b = x; } r = Math.round((r + m) * 255); g = Math.round((g + m) * 255); b = Math.round((b + m) * 255); return new RGBA(r, g, b, a); }
// from http://www.rapidtables.com/convert/color/hsv-to-rgb.htm
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L228-L260
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Color.getRelativeLuminance
getRelativeLuminance(): number { const R = Color._relativeLuminanceForComponent(this.rgba.r); const G = Color._relativeLuminanceForComponent(this.rgba.g); const B = Color._relativeLuminanceForComponent(this.rgba.b); const luminance = 0.2126 * R + 0.7152 * G + 0.0722 * B; return roundFloat(luminance, 4); }
/** * http://www.w3.org/TR/WCAG20/#relativeluminancedef * Returns the number in the set [0, 1]. O => Darkest Black. 1 => Lightest white. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L314-L321
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Color.getContrastRatio
getContrastRatio(another: Color): number { const lum1 = this.getRelativeLuminance(); const lum2 = another.getRelativeLuminance(); return lum1 > lum2 ? (lum1 + 0.05) / (lum2 + 0.05) : (lum2 + 0.05) / (lum1 + 0.05); }
/** * http://www.w3.org/TR/WCAG20/#contrast-ratiodef * Returns the contrast ration number in the set [1, 21]. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L332-L336
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Color.isDarker
isDarker(): boolean { const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000; return yiq < 128; }
/** * http://24ways.org/2010/calculating-color-contrast * Return 'true' if darker color otherwise 'false' */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L342-L345
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
Color.isLighter
isLighter(): boolean { const yiq = (this.rgba.r * 299 + this.rgba.g * 587 + this.rgba.b * 114) / 1000; return yiq >= 128; }
/** * http://24ways.org/2010/calculating-color-contrast * Return 'true' if lighter color otherwise 'false' */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/theme/color/color.ts#L351-L354
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
ToolbarRegistry.registerItem
registerItem(def: ToolbarNode): ToolbarItem { const { id } = def; if (this.items.has(id)) { throw new Error(`A toolbar item is already registered with the '${id}' ID.`); } const item = ToolbarItem.is(def) ? def : this.toolbarItemFactory(def); this.items.set(id, item); item.onDisposed(() => this.items.delete(id)); return item; }
/** * Registers the given item. Throws an error, if the corresponding command cannot be found or an item has been already registered for the desired command. * * @param item the item to register. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/toolbar/toolbar-registry.ts#L58-L67
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DisposableStore.dispose
public dispose(): void { if (this._isDisposed) { return; } markTracked(this); this._isDisposed = true; this.clear(); }
/** * Dispose of all registered disposables and mark this object as disposed. * * Any future disposables added to this object will be disposed of on `add`. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/utils/lifecycle.ts#L177-L185
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
DisposableStore.clear
public clear(): void { try { dispose(this._toDispose.values()); } finally { this._toDispose.clear(); } }
/** * Dispose of all registered disposables but do not mark this object as disposed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/utils/lifecycle.ts#L190-L196
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
FocusTracker.currentChanged
get currentChanged(): EmitterEvent<FocusTracker.IChangedArgs<T>> { return this.currentChangedEmitter.event; }
/** * A signal emitted when the current view has changed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/view/focus-tracker.ts#L28-L30
371f9fa4903254d60ed3142e335dbf3f6d8d03e4
libro
github_2023
weavefox
typescript
FocusTracker.activeChanged
get activeChanged(): EmitterEvent<FocusTracker.IChangedArgs<T>> { return this.activeChangedEmitter.event; }
/** * A signal emitted when the active view has changed. */
https://github.com/weavefox/libro/blob/371f9fa4903254d60ed3142e335dbf3f6d8d03e4/packages/libro-common/src/core/view/focus-tracker.ts#L35-L37
371f9fa4903254d60ed3142e335dbf3f6d8d03e4