Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/default-packages/unigraph.core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,14 @@
{
"id": "command_handler",
"src": "schemas/command_handler.json"
},
{
"id": "hotkey",
"src": "schemas/hotkey.json"
},
{
"id": "hotkey_binding",
"src": "schemas/hotkey_binding.json"
}
],
"executables": [
Expand Down
7 changes: 7 additions & 0 deletions packages/default-packages/unigraph.core/schemas/hotkey.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"dgraph.type": "Type",
"_name": "Hotkey",
"_definition": {
"type": { "unigraph.id": "$/primitive/string" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"dgraph.type": "Type",
"_name": "Hotkey Binding",
"_icon": "%3Csvg xmlns='http://www.w3.org/2000/svg' style='width:24px;height:24px' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M9 11.24V7.5C9 6.12 10.12 5 11.5 5S14 6.12 14 7.5v3.74c1.21-.81 2-2.18 2-3.74C16 5.01 13.99 3 11.5 3S7 5.01 7 7.5c0 1.56.79 2.93 2 3.74zm9.84 4.63-4.54-2.26c-.17-.07-.35-.11-.54-.11H13v-6c0-.83-.67-1.5-1.5-1.5S10 6.67 10 7.5v10.74c-3.6-.76-3.54-.75-3.67-.75-.31 0-.59.13-.79.33l-.79.8 4.94 4.94c.27.27.65.44 1.06.44h6.79c.75 0 1.33-.55 1.44-1.28l.75-5.27c.01-.07.02-.14.02-.2 0-.62-.38-1.16-.91-1.38z' /%3E%3C/svg%3E",
"_definition": {
"type": { "unigraph.id": "$/composer/Object" },
"_parameters": {
"_indexedBy": { "unigraph.id": "$/primitive/string" }
},
"_properties": [
{
"_key": "hotkey",
"_definition": {
"type": { "unigraph.id": "$/primitive/string" }
},
"_indexAs": "hotkey"
},
{
"_key": "command",
"_definition": {
"type": { "unigraph.id": "$/schema/command" }
}
}
]
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type": { "unigraph.id": "$/schema/hotkey_binding" },
"hotkey": "ctrl+e",
"command": { "unigraph.id": "$./entity/open_omnibar_command" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"type": { "unigraph.id": "$/schema/command" },
"name": "Open Omnibar (Command)"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": { "unigraph.id": "$/schema/command_handler" },
"command": { "unigraph.id": "$./entity/open_omnibar_command" },
"action": { "unigraph.id": "$./executable/open-omnibar-action" },
"condition": { "unigraph.id": "$./executable/open-omnibar-condition" }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"type": { "unigraph.id": "$/schema/settings_page" },
"title": "Hotkey settings",
"subtitle": "Customize Unigraph hotkeys by package",
"page": {
"name": "Hotkey settings",
"env": "react-explorer",
"view": { "unigraph.id": "$./executable/settings-view-hotkeys" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
unigraph.getState('global/omnibarSummoner').setValue({
show: true,
tooltip: '',
defaultValue: '',
});
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
true;
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
const [hotkeyBindings, setHotkeyBindings] = React.useState([]);

const tabContext = React.useContext(TabContext);

React.useEffect(() => {
const id = getRandomInt();
tabContext.subscribeToType(
`$/schema/hotkey_binding`,
(res) => {
console.log('hotkeySettings 1', { res, hotkeyBindings });
setHotkeyBindings(res);
},
id,
);
return function cleanup() {
tabContext.unsubscribe(id);
};
}, []);

const hotkeyBindingView = React.useCallback((binding) => (
<div style={{ display: 'flex', justifyContent: 'space-between', flexDirection: 'row' }}>
<span>{binding.get('command').get('name').as('primitive')}</span>
<span>{binding.get('hotkey').as('primitive')}</span>
</div>
));

return (
<div>
{/* <Typography variant="h4">Hotkey settings</Typography> */}
<h1>Hotkey settings</h1>
{hotkeyBindings && hotkeyBindings.length > 0 ? (
<div style={{ display: 'flex', flexDirection: 'column' }}>
<div
style={{
display: 'flex',
justifyContent: 'space-between',
flexDirection: 'row',
fontWeight: 'bold',
}}
>
<span>Command</span>
<span>Binding</span>
</div>
{hotkeyBindings.map(hotkeyBindingView)}
</div>
) : (
<div>No hotkey bindings</div>
)}
</div>
);
65 changes: 65 additions & 0 deletions packages/default-packages/unigraph.hotkeys/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"displayName": "Unigraph Hotkeys",
"version": "0.2.5",
"description": "Hotkeys and bindings.",
"name": "unigraph.hotkeys",
"unigraph": {
"entities": [
{
"id": "open_omnibar_command",
"src": "entities/open_omnibar_command.json"
},
{
"id": "open_omnibar_command_handler",
"src": "entities/open_omnibar_command_handler.json"
},
{
"id": "open_omnibar_binding",
"src": "entities/open_omnibar_binding.json"
},
{
"id": "settings_page_hotkeys",
"src": "entities/settings_page_hotkeys.json"
}
],
"executables": [
{
"id": "open-omnibar-action",
"env": "client/js",
"src": "executables/openOmnibarAction.js",
"editable": true,
"name": "Open Omnibar (Action)",
"concurrency": 1
},
{
"id": "open-omnibar-condition",
"env": "lambda/js",
"src": "executables/openOmnibarCondition.js",
"editable": true,
"name": "Open Omnibar (Condition)",
"concurrency": 1
},
{
"id": "settings-view-hotkeys",
"env": "component/react-jsx",
"src": "executables/settingsViewHotkeys.jsx",
"editable": true,
"imports": [
{
"env": "npm",
"package": "@mui/material",
"import": "Typography",
"as": "Typography"
},
{
"env": "npm",
"package": "@mui/material",
"import": "Button",
"as": "Button"
}
],
"name": "Hotkey settings view"
}
]
}
}
70 changes: 35 additions & 35 deletions packages/default-packages/unigraph.ui_commands/package.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
{
"displayName": "Unigraph UI Commands",
"version": "0.2.5",
"description": "User-triggered commands and command handlers.",
"name": "unigraph.ui_commands",
"unigraph": {
"entities": [
{
"id": "close_tab_command",
"src": "entities/close_tab_command.json"
},
{
"id": "close_tab_command_handler",
"src": "entities/close_tab_command_handler.json"
}
],
"executables": [
{
"id": "close-tab-action",
"env": "client/js",
"src": "executables/closeTabAction.js",
"editable": true,
"name": "Close tab (Action)",
"concurrency": 1
},
{
"id": "close-tab-condition",
"env": "lambda/js",
"src": "executables/closeTabCondition.js",
"editable": true,
"name": "Close tab (Condition)",
"concurrency": 1
}
]
}
}
"displayName": "Unigraph UI Commands",
"version": "0.2.5",
"description": "User-triggered commands and command handlers.",
"name": "unigraph.ui_commands",
"unigraph": {
"entities": [
{
"id": "close_tab_command",
"src": "entities/close_tab_command.json"
},
{
"id": "close_tab_command_handler",
"src": "entities/close_tab_command_handler.json"
}
],
"executables": [
{
"id": "close-tab-action",
"env": "client/js",
"src": "executables/closeTabAction.js",
"editable": true,
"name": "Close tab (Action)",
"concurrency": 1
},
{
"id": "close-tab-condition",
"env": "lambda/js",
"src": "executables/closeTabCondition.js",
"editable": true,
"name": "Close tab (Condition)",
"concurrency": 1
}
]
}
}
2 changes: 2 additions & 0 deletions packages/unigraph-dev-backend/src/templates/defaultDb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { pkg as nlp } from 'unigraph-dev-common/lib/data/unigraph.nlp.pkg';
import { pkg as openai } from 'unigraph-dev-common/lib/data/unigraph.openai.pkg';
import { pkg as kanban } from 'unigraph-dev-common/lib/data/unigraph.kanban.pkg';
import { pkg as uiCommands } from 'unigraph-dev-common/lib/data/unigraph.ui_commands.pkg';
import { pkg as hotkeys } from 'unigraph-dev-common/lib/data/unigraph.hotkeys.pkg';

export const defaultTypes = `<_value>: uid @reverse .
<_value.#i>: int .
Expand Down Expand Up @@ -364,4 +365,5 @@ export const defaultPackages = [
openai,
kanban,
uiCommands,
hotkeys,
];
16 changes: 16 additions & 0 deletions packages/unigraph-dev-explorer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import _ from 'lodash/fp';
import { init } from './init';
import { initDefaultComponents } from './pages';
import * as serviceWorker from './serviceWorker';
Expand Down Expand Up @@ -135,6 +136,21 @@ window.unigraph.onReady!(() => {
{ all: true },
);

window.unigraph.subscribeToType(
'$/schema/hotkey_binding',
_.pipe(
_.keyBy((binding: any) => binding.get('hotkey').as('primitive')),
window.unigraph.getState('global/hotkeyBindings').setValue,
),
// (data: any[]) => {
// const bindings = window.unigraph.getState('global/hotkeyBindings');

// bindings.setValue(data);
// },
undefined,
{ all: true },
);

initDynamicObjectViews();
window.reloadCommands();

Expand Down
7 changes: 4 additions & 3 deletions packages/unigraph-dev-explorer/src/init.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,9 @@ export function init(hostname?: string) {
});
window.unigraph.addState('global/focused/actions', {});
/* Example: {'shift+Tab': {'319908': () => {return true;}}} */
window.unigraph.addState('global/keyboardShortcuts', {});
window.unigraph.addState('global/keyboardShortcuts', {}); // old hotkeys
window.unigraph.addState('global/activeTab', '');
window.unigraph.addState('global/hotkeyBindings', {}); // new hotkeys

if (window.localStorage.getItem('enableAnalytics') === 'true') initAnalyticsIfOptedIn();

Expand Down Expand Up @@ -240,11 +241,11 @@ function initRegistry() {
window.unigraph.addState('registry/components', {});
window.unigraph.addState('registry/contextMenu', {});
window.unigraph.addState('registry/commands', {}); // old commands
window.unigraph.addState('registry/uiCommands', {}); // new ui commands
window.unigraph.addState('registry/uiCommandHandlers', {}); // new ui command handlers
window.unigraph.addState('registry/backlinks', {});
window.unigraph.addState('registry/backlinksCallbacks', {});
window.unigraph.addState('registry/runningExecutables', []); // a parallel with serverState.runningExecutables
window.unigraph.addState('registry/uiCommands', {}); // new ui commands
window.unigraph.addState('registry/uiCommandHandlers', {}); // new ui command handlers
}

function initBacklinkManager() {
Expand Down
Loading