-
Notifications
You must be signed in to change notification settings - Fork 155
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 9dd61a7
Showing
17 changed files
with
487 additions
and
37 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 @@ | ||
{} |
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,159 @@ | ||
<template> | ||
<div class="epub-reader oc-flex oc-p-s"> | ||
<oc-list class="epub-reader-chapters-list oc-width-1-4"> | ||
<li | ||
v-for="chapter in chapters" | ||
:key="chapter.id" | ||
class="epub-reader-chapters-list-item" | ||
:class="{ active: currentChapter.id === chapter.id }" | ||
> | ||
<oc-button appearance="raw" @click="showChapter(chapter)"> | ||
<span v-text="chapter.label" /> | ||
</oc-button> | ||
</li> | ||
</oc-list> | ||
<div class="oc-flex oc-flex-middle oc-mx-l"> | ||
<oc-button :disabled="navigateLeftDisabled" appearance="raw" @click="navigateLeft"> | ||
<oc-icon name="arrow-left-s" fill-type="line" size="xlarge" /> | ||
</oc-button> | ||
</div> | ||
<div id="reader" ref="bookContainer" class="oc-flex oc-flex-center" /> | ||
<div class="oc-flex oc-flex-middle oc-mx-l"> | ||
<oc-button :disabled="navigateRightDisabled" appearance="raw" @click="navigateRight"> | ||
<oc-icon name="arrow-right-s" fill-type="line" size="xlarge" /> | ||
</oc-button> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script lang="ts"> | ||
import { defineComponent, nextTick, PropType, ref, unref, watch } from 'vue' | ||
import { Resource } from '@ownclouders/web-client/src/helpers/resource/types' | ||
import { AppConfigObject, Key, useKeyboardActions } from '@ownclouders/web-pkg' | ||
import ePub, { Book, NavItem, Rendition } 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 } | ||
}, | ||
emits: ['close'], | ||
setup(props) { | ||
const keyboardActions = useKeyboardActions() | ||
const bookContainer = ref<Element>() | ||
const chapters = ref<NavItem[]>([]) | ||
const currentChapter = ref<NavItem>() | ||
const navigateLeftDisabled = ref(true) | ||
const navigateRightDisabled = ref(false) | ||
let book: Book | ||
let rendition: Rendition | ||
const navigateLeft = () => { | ||
rendition.prev() | ||
} | ||
const navigateRight = () => { | ||
rendition.next() | ||
} | ||
const showChapter = (chapter: NavItem) => { | ||
rendition.display(chapter.href) | ||
} | ||
keyboardActions.bindKeyAction({ primary: Key.ArrowLeft }, () => navigateLeft()) | ||
keyboardActions.bindKeyAction({ primary: Key.ArrowRight }, () => navigateRight()) | ||
watch( | ||
() => props.currentContent, | ||
async () => { | ||
await nextTick() | ||
if (book) { | ||
book.destroy() | ||
} | ||
book = ePub(props.currentContent) | ||
book.loaded.navigation.then(({ toc }) => { | ||
chapters.value = toc | ||
currentChapter.value = toc[0] | ||
}) | ||
rendition = book.renderTo(unref(bookContainer), { | ||
flow: 'paginated', | ||
width: 700, | ||
height: '100%' | ||
}) | ||
rendition.display() | ||
rendition.on('keydown', (event: KeyboardEvent) => { | ||
if (event.key === Key.ArrowLeft) { | ||
navigateLeft() | ||
} | ||
if (event.key === Key.ArrowRight) { | ||
navigateRight() | ||
} | ||
}) | ||
rendition.on('relocated', () => { | ||
const currentLocation = rendition.currentLocation() as any | ||
const locationCfi = currentLocation.start.cfi | ||
const spineItem = book.spine.get(locationCfi) | ||
const navItem = book.navigation.get(spineItem.href) | ||
// Might be sub nav item and therefore undefined | ||
if (navItem) { | ||
currentChapter.value = navItem | ||
} | ||
navigateLeftDisabled.value = currentLocation.atStart === true | ||
navigateRightDisabled.value = currentLocation.atEnd === true | ||
}) | ||
}, | ||
{ | ||
immediate: true | ||
} | ||
) | ||
return { | ||
bookContainer, | ||
navigateLeft, | ||
navigateLeftDisabled, | ||
navigateRight, | ||
navigateRightDisabled, | ||
currentChapter, | ||
chapters, | ||
showChapter | ||
} | ||
} | ||
}) | ||
</script> | ||
<style lang="scss"> | ||
.epub-reader { | ||
.epub-container { | ||
background: white; | ||
} | ||
&-chapters-list { | ||
overflow-y: auto; | ||
&-item { | ||
padding-top: var(--oc-space-small); | ||
} | ||
&-item.active { | ||
.oc-button { | ||
color: var(--oc-color-swatch-primary-default); | ||
} | ||
} | ||
&-item:not(:last-child) { | ||
border-bottom: 1px solid var(--oc-color-border); | ||
padding-bottom: var(--oc-space-small); | ||
} | ||
} | ||
} | ||
</style> |
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,86 @@ | ||
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, | ||
fileContentOptions: { | ||
responseType: 'blob' | ||
} | ||
}), | ||
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 | ||
} | ||
} | ||
}) |
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.skip('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.