Repository navigation
Feat/humanreadable2 #828
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/humanreadable2 #828
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
14706bb
slideshow option when 1 image
SharonStrats c9515c2
move human readable and make iframe component
SharonStrats 00f11df
link in tab, open in solidos
SharonStrats 663b898
pdf new design and web component
SharonStrats 4dbc824
improve plaintext
SharonStrats a722436
use markdown it instead of marked and improve code
SharonStrats cca8a32
Add JSON separately and format nicely
SharonStrats 4cfdf56
fix(pdf): emit worker as separate asset
SharonStrats 2f7acd3
small improvements
SharonStrats 0d10829
nicely handle errors
SharonStrats 5e334da
update video and styles
SharonStrats c4e6dea
human readable axe testing
SharonStrats 357af64
pad creation test
SharonStrats 3c3f749
some cleanup
SharonStrats 0e8ed4b
Address PR feedback
SharonStrats ca9f735
fix mobile
SharonStrats 5fe59c6
mobile styling
SharonStrats 282c74e
chore: update solidos dependencies (dev: [email protected] solid-ui…
github-actions[bot] edcc721
chore: update solidos dependencies (dev: [email protected] solid-ui…
github-actions[bot] 669cb4e
chore: update solidos dependencies (dev: [email protected] solid-ui…
github-actions[bot] fa8a5c1
restore standalone image and video pane lifecycle
SharonStrats 1eed59f
remove office document integration from human readable
SharonStrats f2a46eb
update media accessibility tests for standalone panes
SharonStrats 7a8a348
chore: update solidos dependencies (dev: [email protected] solid-ui…
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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 hidden or 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 @@ | ||
| :host { | ||
| display: flex; | ||
| flex: 1 1 0%; | ||
| min-height: 0; | ||
| min-width: 0; | ||
| } | ||
|
|
||
| .editor-card, | ||
| .human-readable-pane__container--iframe { | ||
| display: flex; | ||
| flex: 1 1 0%; | ||
| flex-direction: column; | ||
| min-height: 0; | ||
| min-width: 0; | ||
| } | ||
|
|
||
| .human-readable-pane__frame--iframe { | ||
| flex: 1 1 0%; | ||
| width: 100%; | ||
| min-height: 0; | ||
| box-sizing: border-box; | ||
| border: 1px solid var(--solid-ui-color-slate-200, #E2E8F0); | ||
| } |
This file contains hidden or 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,169 @@ | ||
| import { html, nothing } from 'lit' | ||
| import { property, state } from 'lit/decorators.js' | ||
| import { customElement, WebComponent } from 'solid-ui' | ||
| import type { LiveStore, NamedNode } from 'rdflib' | ||
| import { | ||
| documentTitle, | ||
| HTML_PREVIEW_SANDBOX, | ||
| IFRAME_PREVIEW_FRAME_NAME, | ||
| resourceFilename, | ||
| addResponsivePreviewStyles | ||
| } from '../../humanReadable/previewHelpers' | ||
| import styles from './IframePreview.styles.css' | ||
| import 'solid-ui/components/error-state' | ||
|
|
||
| @customElement('solid-panes-iframe-preview') | ||
| export default class IframePreview extends WebComponent { | ||
| static styles = styles | ||
|
|
||
| @property({ attribute: false }) | ||
| accessor store: LiveStore | undefined = undefined | ||
|
|
||
| @property({ attribute: false }) | ||
| accessor subject: NamedNode | undefined = undefined | ||
|
|
||
| @state() | ||
| private accessor contentType: string | null = null | ||
|
|
||
| @state() | ||
| private accessor content: string | undefined = undefined | ||
|
|
||
| @state() | ||
| private accessor errorMessage = '' | ||
|
|
||
| @state() | ||
| private accessor dokieliHtml = false | ||
|
|
||
| @state() | ||
| private accessor fetchedTitle = '' | ||
|
|
||
| @property({ attribute: false }) | ||
| accessor rememberHtmlType: ((uri: string, isDokieli: boolean) => void) | undefined | ||
|
|
||
| @property({ attribute: false }) | ||
| accessor withBaseHref: ((html: string, uri: string) => string) | undefined | ||
|
|
||
| @property({ attribute: false }) | ||
| accessor isDokieliHtml: ((html: string) => boolean) | undefined | ||
|
|
||
| @property({ attribute: false }) | ||
| accessor mountDokieliBridge: | ||
| ((frame: HTMLIFrameElement, uri: string, html: string) => () => void) | undefined | ||
|
|
||
| private objectUrl: string | undefined | ||
| private removeDokieliBridge = () => {} | ||
| private rawHtml: string | undefined | ||
| private fetchGeneration = 0 | ||
|
|
||
| private get previewTitle (): string { | ||
| return this.fetchedTitle || (this.subject?.uri ? resourceFilename(this.subject.uri) : 'preview') | ||
| } | ||
|
|
||
| private dismissError = (): void => { | ||
| this.errorMessage = '' | ||
| } | ||
|
|
||
| private clearPreview (): void { | ||
| this.removeDokieliBridge() | ||
| this.removeDokieliBridge = () => {} | ||
| this.renderRoot.querySelector('iframe')?.removeAttribute('srcdoc') | ||
| if (this.objectUrl) { | ||
| URL.revokeObjectURL(this.objectUrl) | ||
| this.objectUrl = undefined | ||
| } | ||
| this.content = undefined | ||
| this.contentType = null | ||
| this.rawHtml = undefined | ||
| this.fetchedTitle = '' | ||
| this.dokieliHtml = false | ||
| this.errorMessage = '' | ||
| } | ||
|
|
||
| private async fetchDocument (): Promise<void> { | ||
| const generation = ++this.fetchGeneration | ||
| const { subject, store } = this | ||
| this.clearPreview() | ||
| if (!subject || !store) return | ||
|
|
||
| const isCurrent = () => this.isConnected && | ||
| generation === this.fetchGeneration && this.subject === subject && this.store === store | ||
|
|
||
| try { | ||
| const response = await store.fetcher._fetch(subject.uri) | ||
| if (!response.ok) throw new Error(`HTTP ${response.status}`) | ||
| const contentType = response.headers.get('content-type')?.split(';', 1)[0].trim().toLowerCase() ?? null | ||
| const isHtml = contentType === 'text/html' || contentType === 'application/xhtml+xml' | ||
|
|
||
| if (isHtml) { | ||
| const htmlContent = await response.text() | ||
| if (!isCurrent()) return | ||
| this.dokieliHtml = this.isDokieliHtml?.(htmlContent) ?? false | ||
| this.rememberHtmlType?.(subject.uri, this.dokieliHtml) | ||
| this.rawHtml = htmlContent | ||
| this.fetchedTitle = documentTitle(htmlContent, subject.uri) | ||
| this.contentType = contentType | ||
| const documentHtml = this.withBaseHref?.(htmlContent, subject.uri) ?? htmlContent | ||
| this.content = addResponsivePreviewStyles(documentHtml) | ||
| } else { | ||
| const blob = await response.blob() | ||
| if (!isCurrent()) return | ||
| this.objectUrl = URL.createObjectURL(blob) | ||
| this.contentType = contentType | ||
| this.content = this.objectUrl | ||
| } | ||
| } catch (error) { | ||
| if (isCurrent()) { | ||
| this.errorMessage = error instanceof Error ? error.message : String(error) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| connectedCallback (): void { | ||
| super.connectedCallback() | ||
| if (this.hasUpdated) this.fetchDocument() | ||
| } | ||
|
|
||
| protected updated (changed: Map<PropertyKey, unknown>): void { | ||
| super.updated(changed) | ||
| if (changed.has('subject') || changed.has('store')) { | ||
| this.fetchDocument() | ||
| } else if (changed.has('content') && this.dokieliHtml && this.rawHtml && this.subject) { | ||
| const frame = this.renderRoot.querySelector<HTMLIFrameElement>('iframe') | ||
| if (frame && this.mountDokieliBridge) { | ||
| this.removeDokieliBridge() | ||
| this.removeDokieliBridge = this.mountDokieliBridge(frame, this.subject.uri, this.rawHtml) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| disconnectedCallback (): void { | ||
| ++this.fetchGeneration | ||
| this.clearPreview() | ||
| super.disconnectedCallback() | ||
| } | ||
|
|
||
| render () { | ||
| const isHtml = this.contentType === 'text/html' || this.contentType === 'application/xhtml+xml' | ||
| return html` | ||
| <section class="editor-card" aria-label=${`Preview of ${this.previewTitle}`}> | ||
| <div class="human-readable-pane__container--iframe"> | ||
| <iframe | ||
| class="human-readable-pane__frame--iframe" | ||
| name=${IFRAME_PREVIEW_FRAME_NAME} | ||
| title=${this.previewTitle} | ||
| sandbox=${this.contentType === 'application/pdf' ? nothing : HTML_PREVIEW_SANDBOX} | ||
| src=${isHtml ? nothing : this.content ?? nothing} | ||
| srcdoc=${isHtml && !this.dokieliHtml ? this.content ?? nothing : nothing} | ||
| ></iframe> | ||
| </div> | ||
| ${this.errorMessage | ||
| ? html`<solid-ui-error-state | ||
| title="Unable to load preview" | ||
| .message=${this.errorMessage} | ||
| @close=${this.dismissError} | ||
| ></solid-ui-error-state>` | ||
| : nothing} | ||
| </section> | ||
| ` | ||
| } | ||
| } | ||
This file contains hidden or 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,4 @@ | ||
| import IframePreview from './IframePreview' | ||
|
|
||
| export { IframePreview } | ||
| export default IframePreview |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.