Skip to content

Commit

Permalink
feat: Super notes can now be exported as PDF (#2776)
Browse files Browse the repository at this point in the history
  • Loading branch information
amanharwara authored Jan 24, 2024
1 parent 813304c commit 418d1a7
Show file tree
Hide file tree
Showing 55 changed files with 1,062 additions and 70 deletions.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
2 changes: 1 addition & 1 deletion packages/desktop/app/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
content="
default-src 'self' blob:;
script-src 'self' 'unsafe-eval';
worker-src blob:;
worker-src 'self' blob:;
connect-src * data: blob:;
style-src 'unsafe-inline' 'self' http://localhost:* http://127.0.0.1:45653;
frame-src * blob:;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
export interface SuperConverterServiceInterface {
isValidSuperString(superString: string): boolean
convertSuperStringToOtherFormat: (superString: string, toFormat: 'txt' | 'md' | 'html' | 'json') => Promise<string>
convertSuperStringToOtherFormat: (
superString: string,
toFormat: 'txt' | 'md' | 'html' | 'json' | 'pdf',
) => Promise<string>
convertOtherFormatToSuperString: (
otherFormatString: string,
fromFormat: 'txt' | 'md' | 'html' | 'json',
Expand Down
2 changes: 1 addition & 1 deletion packages/models/src/Domain/Syncable/UserPrefs/PrefKey.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ export type PrefValue = {
[PrefKey.MomentsDefaultTagUuid]: string | undefined
[PrefKey.ClipperDefaultTagUuid]: string | undefined
[PrefKey.SystemViewPreferences]: Partial<Record<SystemViewId, TagPreferences>>
[PrefKey.SuperNoteExportFormat]: 'json' | 'md' | 'html'
[PrefKey.SuperNoteExportFormat]: 'json' | 'md' | 'html' | 'pdf'
[PrefKey.SuperNoteExportEmbedBehavior]: 'reference' | 'inline' | 'separate'
[PrefKey.SuperNoteExportUseMDFrontmatter]: boolean
[PrefKey.AuthenticatorNames]: string
Expand Down
4 changes: 2 additions & 2 deletions packages/toast/src/Toast.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ export const Toast = forwardRef(({ toast, index }: Props, ref: ForwardedRef<HTML
}}
ref={ref}
>
<div className="grid gap-x-2.5 gap-y-1 overflow-hidden grid-cols-[1fr,auto] pl-3 pr-3.5 py-2.5">
{icon ? <div className="sn-icon flex flex-shrink-0 items-center justify-center">{icon}</div> : null}
<div className="grid gap-x-2.5 gap-y-1 overflow-hidden grid-cols-[min-content,auto] pl-3 pr-3.5 py-2.5">
{icon ? <div className="sn-icon flex items-center justify-center">{icon}</div> : null}
{toast.title && <div className="text-text text-sm font-semibold col-start-2">{toast.title}</div>}
<div className="text-text text-sm [word-wrap:anywhere] col-start-2">{toast.message}</div>
{hasActions && (
Expand Down
2 changes: 2 additions & 0 deletions packages/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@
"@ariakit/react": "^0.3.9",
"@lexical/headless": "0.12.6",
"@radix-ui/react-slot": "^1.0.1",
"@react-pdf/renderer": "^3.3.2",
"comlink": "^4.4.1",
"fast-diff": "^1.3.0"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,22 @@ const NotesOptions = ({ notes, closeMenu }: NotesOptionsProps) => {
downloadSelectedItems().catch(console.error)
}, [downloadSelectedItems, notes])

const shareSelectedItems = useCallback(() => {
createNoteExport(application, notes)
.then((result) => {
if (!result) {
return
}

const { blob, fileName } = result

shareBlobOnMobile(application.mobileDevice, application.isNativeMobileWeb(), blob, fileName).catch(
console.error,
)
})
.catch(console.error)
}, [application, notes])

const closeMenuAndToggleNotesList = useCallback(() => {
const isMobileScreen = matchMedia(MutuallyExclusiveMediaQueryBreakpoints.sm).matches
if (isMobileScreen) {
Expand Down Expand Up @@ -347,34 +363,14 @@ const NotesOptions = ({ notes, closeMenu }: NotesOptionsProps) => {
{pinShortcut && <KeyboardShortcutIndicator className="ml-auto" shortcut={pinShortcut} />}
</MenuItem>
)}
<MenuItem
onClick={() => {
if (application.isNativeMobileWeb()) {
createNoteExport(application, notes)
.then((result) => {
if (!result) {
return
}

const { blob, fileName } = result

shareBlobOnMobile(application.mobileDevice, application.isNativeMobileWeb(), blob, fileName).catch(
console.error,
)
})
.catch(console.error)
} else {
exportSelectedItems()
}
}}
>
<Icon type={application.platform === Platform.Android ? 'share' : 'download'} className={iconClass} />
{application.platform === Platform.Android ? 'Share' : 'Export'}
<MenuItem onClick={exportSelectedItems}>
<Icon type="download" className={iconClass} />
Export
</MenuItem>
{application.platform === Platform.Android && (
<MenuItem onClick={exportSelectedItems}>
<Icon type="download" className={iconClass} />
Export
<MenuItem onClick={shareSelectedItems}>
<Icon type="share" className={iconClass} />
Share
</MenuItem>
)}
<MenuItem onClick={duplicateSelectedItems} disabled={areSomeNotesInReadonlySharedVault}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ type Props = {

const SuperExportModal = ({ notes, exportNotes, close }: Props) => {
const application = useApplication()

const superNoteExportFormat = usePreference(PrefKey.SuperNoteExportFormat)
const superNoteExportEmbedBehavior = usePreference(PrefKey.SuperNoteExportEmbedBehavior)
const superNoteExportUseMDFrontmatter = usePreference(PrefKey.SuperNoteExportUseMDFrontmatter)
Expand All @@ -26,10 +27,15 @@ const SuperExportModal = ({ notes, exportNotes, close }: Props) => {
if (superNoteExportFormat === 'md' && superNoteExportEmbedBehavior === 'reference') {
void application.setPreference(PrefKey.SuperNoteExportEmbedBehavior, 'separate')
}
if (superNoteExportFormat === 'pdf' && superNoteExportEmbedBehavior !== 'inline') {
void application.setPreference(PrefKey.SuperNoteExportEmbedBehavior, 'inline')
}
}, [application, superNoteExportEmbedBehavior, superNoteExportFormat])

const someNotesHaveEmbeddedFiles = notes.some(noteHasEmbeddedFiles)

const canShowEmbeddedFileOptions = !['json', 'pdf'].includes(superNoteExportFormat)

return (
<Modal
title="Export notes"
Expand Down Expand Up @@ -61,6 +67,7 @@ const SuperExportModal = ({ notes, exportNotes, close }: Props) => {
{ label: 'Super (.json)', value: 'json' },
{ label: 'Markdown (.md)', value: 'md' },
{ label: 'HTML', value: 'html' },
{ label: 'PDF', value: 'pdf' },
]}
value={superNoteExportFormat}
onChange={(value) => {
Expand Down Expand Up @@ -93,7 +100,7 @@ const SuperExportModal = ({ notes, exportNotes, close }: Props) => {
</Switch>
</div>
)}
{superNoteExportFormat !== 'json' && someNotesHaveEmbeddedFiles && (
{canShowEmbeddedFileOptions && someNotesHaveEmbeddedFiles && (
<div className="mb-2 mt-4">
<div className="mb-1">How do you want embedded files to be handled?</div>
<RadioButtonGroup
Expand Down
Loading

0 comments on commit 418d1a7

Please sign in to comment.