Skip to content

Commit

Permalink
feat(notes): allow attaching notes everywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
thesophiaxu committed Jan 3, 2022
1 parent 1d320a6 commit 6a05099
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": { "unigraph.id": "$/schema/context_menu_item" },
"name": "Attach note to object",
"item_type": {"unigraph.id": "$/schema/any"},
"on_click": {"unigraph.id": "$/package/unigraph.notes/0.0.1/executable/attach-note"},
"icon": "%3Csvg xmlns='http://www.w3.org/2000/svg' style='width:24px;height:24px' viewBox='0 0 24 24'%3E%3Cpath fill='currentColor' d='M5 19V5H12V12H19V13C19.7 13 20.37 13.13 21 13.35V9L15 3H5C3.89 3 3 3.89 3 5V19C3 20.1 3.89 21 5 21H13.35C13.13 20.37 13 19.7 13 19H5M14 4.5L19.5 10H14V4.5M23 18V20H20V23H18V20H15V18H18V15H20V18H23Z' /%3E%3C/svg%3E"
}
10 changes: 10 additions & 0 deletions packages/default-packages/unigraph.notes/executables/attachNote.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const { uid } = context.params;

const newNote = (await unigraph.addObject({
text: {
_value: '',
type: { 'unigraph.id': '$/schema/markdown' },
},
}, '$/schema/note_block'))[0];
unigraph.runExecutable('$/executable/add-item-to-list', { where: uid, item: newNote });
window?.wsnavigator?.(`/library/object?uid=${newNote}&viewer=${'dynamic-view-detailed'}&type=$/schema/note_block`);
10 changes: 9 additions & 1 deletion packages/default-packages/unigraph.notes/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
],
"package_name": "unigraph.notes",
"entities": [
{"id": "section_daily_notes", "src": "entities/daily_notes.json"}
{"id": "section_daily_notes", "src": "entities/daily_notes.json"},
{"id": "add_note_context_menu", "src": "entities/add_note_context_menu.json"}
],
"executables": [
{
Expand All @@ -24,6 +25,13 @@
{"env": "npm", "package": "@material-ui/core", "import": "Button", "as": "Button"}
],
"editable": true
},
{
"id": "attach-note",
"env": "client/js",
"src": "executables/attachNote.js",
"editable": true,
"name": "Attach note to an item"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,21 @@ export const onUnigraphContextMenu = (
contextUid?: string,
) {
return (
<MenuItem onClick={() => {
<MenuItem
style={{ paddingTop: '2px', paddingBottom: '2px' }}
onClick={() => {
onfire();
onDynamicContextMenu(el, uid, object, callbacks, contextUid);
}}
>
{(new UnigraphObject(el)).get('name').as('primitive') || ''}
{(new UnigraphObject(el)).get('icon')?.as('primitive') ? (
<ListItemIcon style={{
minWidth: '19px', minHeight: '19px', marginRight: '12px', backgroundImage: `url("data:image/svg+xml,${(new UnigraphObject(el)).get('icon')?.as('primitive')}")`, opacity: 0.54,
}}
/>
)
: []}
<ListItemText>{(new UnigraphObject(el)).get('name').as('primitive') || ''}</ListItemText>
</MenuItem>
);
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ export function CalendarEvent({ data, callbacks }: any) {
<Typography variant="body2" style={{ color: 'gray' }}>{data.get('location').as('primitive')}</Typography>
</div>
<AutoDynamicView object={new UnigraphObject(data.get('time_frame')._value)} callbacks={callbacks} noDrag noDrop inline />
<div style={{ display: data?._value?.children?.['_value[']?.map ? '' : 'none', marginTop: '4px' }}>
{data?._value?.children?.['_value[']?.map
? data._value.children['_value['].map((it: any) => <AutoDynamicView object={new UnigraphObject(it._value)} callbacks={callbacks} inline style={{ verticalAlign: 'middle' }} />)
: []}
</div>
</div>
</div>
);
Expand Down

0 comments on commit 6a05099

Please sign in to comment.