mirror of
https://github.com/chinchang/web-maker.git
synced 2025-05-05 18:15:58 +02:00
Add some more commands to commands palette.
Some refactoring also. Move palette events to commands.js.
This commit is contained in:
parent
021f1390ab
commit
f4de6572c2
@ -1,18 +1,9 @@
|
||||
import { deferred } from './deferred';
|
||||
import { log } from 'util';
|
||||
|
||||
export const SWITCH_FILE_EVENT = 'switchFileEvent';
|
||||
export const OPEN_SAVED_CREATIONS_EVENT = 'openSavedCreationsEvent';
|
||||
export const SAVE_EVENT = 'saveEvent';
|
||||
|
||||
export const commandPaletteService = {
|
||||
subscriptions: {},
|
||||
subscribe(eventName, callback) {
|
||||
console.log('subscribed for ', eventName);
|
||||
this.subscriptions[eventName] = this.subscriptions[eventName] || [];
|
||||
this.subscriptions[eventName].push(callback);
|
||||
return () => {
|
||||
console.log('Unsubscribing ', eventName);
|
||||
this.subscriptions[eventName].splice(
|
||||
this.subscriptions[eventName].indexOf(callback),
|
||||
1
|
||||
@ -20,7 +11,6 @@ export const commandPaletteService = {
|
||||
};
|
||||
},
|
||||
publish(eventName, ...args) {
|
||||
console.log('published ', eventName, args);
|
||||
const callbacks = this.subscriptions[eventName] || [];
|
||||
callbacks.forEach(callback => {
|
||||
callback.apply(null, args);
|
||||
|
@ -1,9 +1,15 @@
|
||||
import {
|
||||
OPEN_SAVED_CREATIONS_EVENT,
|
||||
SAVE_EVENT
|
||||
} from './commandPaletteService';
|
||||
export const SWITCH_FILE_EVENT = 'switchFileEvent';
|
||||
export const NEW_CREATION_EVENT = 'newCreationEvent';
|
||||
export const OPEN_SAVED_CREATIONS_EVENT = 'openSavedCreationsEvent';
|
||||
export const SAVE_EVENT = 'saveEvent';
|
||||
export const OPEN_SETTINGS_EVENT = 'openSettingsEvent';
|
||||
|
||||
export const commands = [
|
||||
{
|
||||
name: 'Start New Creation',
|
||||
event: NEW_CREATION_EVENT,
|
||||
keyboardShortcut: ''
|
||||
},
|
||||
{
|
||||
name: 'Open Creation',
|
||||
event: OPEN_SAVED_CREATIONS_EVENT,
|
||||
@ -15,8 +21,8 @@ export const commands = [
|
||||
keyboardShortcut: 'Cmd+S'
|
||||
},
|
||||
{
|
||||
name: 'Add Library',
|
||||
run: '',
|
||||
keyboardShortcut: 'Cmd+F'
|
||||
name: 'Open Settings',
|
||||
event: OPEN_SETTINGS_EVENT,
|
||||
keyboardShortcut: ''
|
||||
}
|
||||
];
|
||||
|
@ -1,11 +1,9 @@
|
||||
import { h, Component } from 'preact';
|
||||
import Modal from './Modal';
|
||||
import { AutoFocusInput } from './common';
|
||||
import { commands } from '../commands';
|
||||
import {
|
||||
commandPaletteService,
|
||||
SWITCH_FILE_EVENT
|
||||
} from '../commandPaletteService';
|
||||
import { commands, SWITCH_FILE_EVENT } from '../commands';
|
||||
|
||||
import { commandPaletteService } from '../commandPaletteService';
|
||||
import { FileIcon } from './FileIcon';
|
||||
import { UP_KEY, DOWN_KEY, ENTER_KEY } from '../keyboardKeys';
|
||||
|
||||
|
@ -17,10 +17,8 @@ import 'codemirror/mode/meta';
|
||||
import { deferred } from '../deferred';
|
||||
import { SidePane } from './SidePane';
|
||||
import { Console } from './Console';
|
||||
import {
|
||||
commandPaletteService,
|
||||
SWITCH_FILE_EVENT
|
||||
} from '../commandPaletteService';
|
||||
import { SWITCH_FILE_EVENT } from '../commands';
|
||||
import { commandPaletteService } from '../commandPaletteService';
|
||||
|
||||
const minCodeWrapSize = 33;
|
||||
|
||||
|
@ -32,7 +32,12 @@ export default class Modal extends Component {
|
||||
if (this.props.show) {
|
||||
// HACK: refs will evaluate on next tick due to portals
|
||||
setTimeout(() => {
|
||||
this.overlayEl.querySelector('.js-modal__close-btn').focus();
|
||||
const closeButton = this.overlayEl.querySelector(
|
||||
'.js-modal__close-btn'
|
||||
);
|
||||
if (closeButton) {
|
||||
closeButton.focus();
|
||||
}
|
||||
}, 0);
|
||||
|
||||
/* We insert a dummy hidden input which will take focus as soon as focus
|
||||
|
@ -57,9 +57,12 @@ import { Icons } from './Icons';
|
||||
import JSZip from 'jszip';
|
||||
import { CommandPalette } from './CommandPalette';
|
||||
import {
|
||||
commandPaletteService,
|
||||
OPEN_SAVED_CREATIONS_EVENT
|
||||
} from '../commandPaletteService';
|
||||
OPEN_SAVED_CREATIONS_EVENT,
|
||||
SAVE_EVENT,
|
||||
OPEN_SETTINGS_EVENT,
|
||||
NEW_CREATION_EVENT
|
||||
} from '../commands';
|
||||
import { commandPaletteService } from '../commandPaletteService';
|
||||
|
||||
if (module.hot) {
|
||||
require('preact/debug');
|
||||
@ -497,6 +500,10 @@ export default class App extends Component {
|
||||
this.editorWithFocus.focus();
|
||||
}
|
||||
}
|
||||
openSettings() {
|
||||
this.setState({ isSettingsModalOpen: true });
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
document.body.style.height = `${window.innerHeight}px`;
|
||||
|
||||
@ -560,10 +567,26 @@ export default class App extends Component {
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
commandPaletteService.subscribe(OPEN_SAVED_CREATIONS_EVENT, () => {
|
||||
this.openSavedItemsPane();
|
||||
});
|
||||
const commandPalleteHooks = {
|
||||
[NEW_CREATION_EVENT]: () => {
|
||||
this.openNewCreationModal();
|
||||
},
|
||||
[OPEN_SAVED_CREATIONS_EVENT]: () => {
|
||||
this.openSavedItemsPane();
|
||||
},
|
||||
[SAVE_EVENT]: () => {
|
||||
this.saveItem();
|
||||
},
|
||||
[OPEN_SETTINGS_EVENT]: () => {
|
||||
this.openSettings();
|
||||
}
|
||||
};
|
||||
for (let eventName in commandPalleteHooks) {
|
||||
commandPaletteService.subscribe(
|
||||
eventName,
|
||||
commandPalleteHooks[eventName]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
closeAllOverlays() {
|
||||
@ -931,8 +954,7 @@ export default class App extends Component {
|
||||
this.forkItem(item);
|
||||
}, 350);
|
||||
}
|
||||
newBtnClickHandler() {
|
||||
trackEvent('ui', 'newBtnClick');
|
||||
openNewCreationModal() {
|
||||
if (this.state.unsavedEditCount) {
|
||||
var shouldDiscard = confirm(
|
||||
'You have unsaved changes. Do you still want to create something new?'
|
||||
@ -948,6 +970,10 @@ export default class App extends Component {
|
||||
});
|
||||
}
|
||||
}
|
||||
newBtnClickHandler() {
|
||||
trackEvent('ui', 'newBtnClick');
|
||||
this.openNewCreationModal();
|
||||
}
|
||||
openBtnClickHandler() {
|
||||
trackEvent('ui', 'openBtnClick');
|
||||
this.openSavedItemsPane();
|
||||
@ -1412,9 +1438,7 @@ export default class App extends Component {
|
||||
prefs={this.state.prefs}
|
||||
layoutBtnClickHandler={this.layoutBtnClickHandler.bind(this)}
|
||||
helpBtnClickHandler={() => this.setState({ isHelpModalOpen: true })}
|
||||
settingsBtnClickHandler={() =>
|
||||
this.setState({ isSettingsModalOpen: true })
|
||||
}
|
||||
settingsBtnClickHandler={this.openSettings.bind(this)}
|
||||
notificationsBtnClickHandler={this.notificationsBtnClickHandler.bind(
|
||||
this
|
||||
)}
|
||||
|
Loading…
x
Reference in New Issue
Block a user