-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee0ff0c
commit 4c49e22
Showing
14 changed files
with
352 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,8 @@ | |
"pdf-viewer", | ||
"preview", | ||
"search", | ||
"text-editor" | ||
"text-editor", | ||
"epub-reader" | ||
], | ||
"applications" : [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,8 @@ | |
"external", | ||
"admin-settings", | ||
"ocm", | ||
"webfinger" | ||
"webfinger", | ||
"epub-reader" | ||
], | ||
"external_apps": [ | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,7 +36,8 @@ | |
"external", | ||
"admin-settings", | ||
"ocm", | ||
"webfinger" | ||
"webfinger", | ||
"epub-reader" | ||
], | ||
"external_apps": [ | ||
{ | ||
|
6 changes: 6 additions & 0 deletions
6
packages/design-system/src/assets/icons/resource-type-epub-fill.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions
6
packages/design-system/src/assets/icons/resource-type-epub-line.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[main] | ||
host = https://www.transifex.com | ||
|
||
[o:owncloud-org:p:owncloud-web:r:epub-reader] | ||
file_filter = locale/<lang>/LC_MESSAGES/app.po | ||
minimum_perc = 0 | ||
source_file = template.pot | ||
source_lang = en | ||
type = PO |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "epub-reader", | ||
"version": "0.0.0", | ||
"private": true, | ||
"description": "ownCloud Web epub-reader", | ||
"license": "AGPL-3.0", | ||
"devDependencies": { | ||
"web-test-helpers": "workspace:*" | ||
}, | ||
"peerDependencies": { | ||
"@ownclouders/web-client": "workspace:*", | ||
"@ownclouders/web-pkg": "workspace:*", | ||
"vue3-gettext": "2.4.0", | ||
"epubjs": "^0.3.93" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<template> | ||
<div id="area" ref="bookContainer"></div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, PropType, ref, VNodeRef } from 'vue' | ||
import { Resource } from '@ownclouders/web-client/src/helpers/resource/types' | ||
import { AppConfigObject } from '@ownclouders/web-pkg' | ||
import { Book } from 'epubjs' | ||
export default defineComponent({ | ||
name: 'EpubReader', | ||
props: { | ||
applicationConfig: { type: Object as PropType<AppConfigObject>, required: true }, | ||
currentContent: { | ||
type: String, | ||
required: true | ||
}, | ||
isReadOnly: { type: Boolean, required: false }, | ||
resource: { type: Object as PropType<Resource>, required: true } | ||
}, | ||
setup(props) { | ||
const bookContainer = ref<VNodeRef>() | ||
const blob: any = new Blob([props.currentContent], { type: 'application/epub+zip' }) | ||
const instance = new Book(blob) | ||
instance.ready.then(() => { | ||
const options: RenditionOptions = { | ||
manager: 'continuous', | ||
flow: 'scrolled' | ||
} | ||
instance.renderTo('area', options) | ||
instance.rendition.display() | ||
}) | ||
return { | ||
bookContainer | ||
} | ||
} | ||
}) | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { useGettext } from 'vue3-gettext' | ||
import translations from '../l10n/translations.json' | ||
import EpubReader from './App.vue' | ||
import { | ||
AppWrapperRoute, | ||
ApplicationFileExtension, | ||
defineWebApplication | ||
} from '@ownclouders/web-pkg' | ||
|
||
export default defineWebApplication({ | ||
setup({ applicationConfig }) { | ||
const { $gettext } = useGettext() | ||
|
||
const appId = 'epub-reader' | ||
|
||
const fileExtensions = () => { | ||
const extensions: ApplicationFileExtension[] = [ | ||
{ | ||
extension: 'epub', | ||
label: $gettext('EPUB file') | ||
} | ||
] | ||
|
||
const config = applicationConfig || {} | ||
extensions.push(...(config.extraExtensions || []).map((ext: string) => ({ extension: ext }))) | ||
|
||
let primaryExtensions: string[] = config.primaryExtensions || ['epub'] | ||
|
||
if (typeof primaryExtensions === 'string') { | ||
primaryExtensions = [primaryExtensions] | ||
} | ||
|
||
return extensions.reduce<ApplicationFileExtension[]>((acc, extensionItem) => { | ||
const isPrimary = primaryExtensions.includes(extensionItem.extension) | ||
if (isPrimary) { | ||
extensionItem.newFileMenu = { | ||
menuTitle() { | ||
return $gettext(extensionItem.label) | ||
} | ||
} | ||
} | ||
acc.push(extensionItem) | ||
return acc | ||
}, []) | ||
} | ||
|
||
const routes = [ | ||
{ | ||
path: '/:driveAliasAndItem(.*)?', | ||
component: AppWrapperRoute(EpubReader, { | ||
applicationId: appId | ||
}), | ||
name: 'epub-reader', | ||
meta: { | ||
authContext: 'hybrid', | ||
title: $gettext('Epub Reader'), | ||
patchCleanPath: true | ||
} | ||
} | ||
] | ||
|
||
return { | ||
appInfo: { | ||
name: $gettext('Epub Reader'), | ||
id: appId, | ||
icon: 'file-text', | ||
color: '#0D856F', | ||
isFileEditor: true, | ||
defaultExtension: 'epub', | ||
extensions: fileExtensions().map((extensionItem) => { | ||
return { | ||
extension: extensionItem.extension, | ||
...(Object.hasOwn(extensionItem, 'newFileMenu') && { | ||
newFileMenu: extensionItem.newFileMenu | ||
}) | ||
} | ||
}) | ||
}, | ||
routes, | ||
translations | ||
} | ||
} | ||
}) |
3 changes: 3 additions & 0 deletions
3
packages/web-app-epub-reader/tests/unit/__snapshots__/app.spec.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html | ||
|
||
exports[`Epub reader app > shows the epub reader 1`] = `"<div id="area"></div>"`; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { Resource } from '@ownclouders/web-client/src' | ||
import { AppConfigObject } from '@ownclouders/web-pkg' | ||
import { mount } from 'web-test-helpers' | ||
import App from '../../src/App.vue' | ||
|
||
vi.mock('@ownclouders/web-pkg') | ||
|
||
describe('Epub reader app', () => { | ||
it('shows the epub reader', () => { | ||
const { wrapper } = getWrapper({ | ||
applicationConfig: {} | ||
}) | ||
expect(wrapper.html()).toMatchSnapshot() | ||
}) | ||
}) | ||
|
||
function getWrapper(props: { applicationConfig: AppConfigObject; resource?: Resource }) { | ||
return { | ||
wrapper: mount(App, { | ||
props | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.