-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Add support for 3D/CAD file formats preview #34794
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
Open
kerwin612
wants to merge
14
commits into
go-gitea:main
Choose a base branch
from
kerwin612:feat/support-preview-3d-file
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+216
−57
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
448effb
feat: add plugin-based file rendering system with 3D file preview sup…
kerwin612 2e80917
fix tests error
kerwin612 1296d61
Merge branch 'main' into feat/support-preview-3d-file
wxiaoguang 5ef2279
Merge branch 'main' into feat/support-preview-3d-file
kerwin612 c84be59
fix
kerwin612 f32eaac
Merge remote-tracking branch 'kerwin612/feat/support-preview-3d-file'…
kerwin612 3a6dd02
refactor the PdfViewer
kerwin612 505b644
fix test error
kerwin612 00eb205
fix
kerwin612 3fe3bc6
Merge branch 'main' into feat/support-preview-3d-file
kerwin612 2e7fe6e
clean code
kerwin612 f54fecf
temp
wxiaoguang 2f45268
fix
wxiaoguang 24d7bab
fix
wxiaoguang 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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
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,5 @@ | ||
<div class="file-view-render-container" data-global-init="initFileViewRender" data-raw-file-link="{{$.RawFileLink}}"> | ||
<div class="file-view-raw-prompt tw-p-4"> | ||
<a href="{{$.RawFileLink}}" rel="nofollow">{{ctx.Locale.Tr "repo.file_view_raw"}}</a> | ||
</div> | ||
</div> |
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,3 @@ | ||
.file-view-render-container :last-child { | ||
border-radius: 0 0 var(--border-radius) var(--border-radius); /* to match the "ui segment" bottom radius */ | ||
} |
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 |
---|---|---|
|
@@ -85,4 +85,6 @@ | |
|
||
@import "./helpers.css"; | ||
|
||
@import "./file-view.css"; | ||
|
||
@tailwind utilities; |
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
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,52 @@ | ||
import {findFileRenderPlugin} from '../modules/file-render-plugin.ts'; | ||
import {registerGlobalInitFunc} from '../modules/observer.ts'; | ||
import {createElementFromHTML} from '../utils/dom.ts'; | ||
import {register3DViewerPlugin} from '../render/plugins/3d-viewer.ts'; | ||
import {registerPdfViewerPlugin} from '../render/plugins/pdf-viewer.ts'; | ||
import {htmlEscape} from 'escape-goat'; | ||
import {basename} from '../utils.ts'; | ||
|
||
export function initFileViewRender(): void { | ||
let pluginRegistered = false; | ||
|
||
registerGlobalInitFunc('initFileViewRender', async (container: HTMLElement) => { | ||
if (!pluginRegistered) { | ||
pluginRegistered = true; | ||
register3DViewerPlugin(); | ||
registerPdfViewerPlugin(); | ||
} | ||
|
||
const rawFileLink = container.getAttribute('data-raw-file-link'); | ||
const mimeType = container.getAttribute('data-mime-type') || ''; // not used yet | ||
const elViewRawPrompt = container.querySelector('.file-view-raw-prompt'); | ||
if (!rawFileLink || !elViewRawPrompt) throw new Error('unexpected file view container'); | ||
|
||
let rendered = false, errorMsg = ''; | ||
try { | ||
const plugin = findFileRenderPlugin(basename(rawFileLink), mimeType); | ||
if (plugin) { | ||
container.classList.add('is-loading'); | ||
container.setAttribute('data-render-name', plugin.name); // not used yet | ||
await plugin.render(container, rawFileLink); | ||
rendered = true; | ||
} | ||
} catch (e) { | ||
errorMsg = `${e}`; | ||
} finally { | ||
container.classList.remove('is-loading'); | ||
} | ||
|
||
if (rendered) { | ||
elViewRawPrompt.remove(); | ||
return; | ||
} | ||
|
||
// remove all children from the container, and only show the raw file link | ||
container.replaceChildren(elViewRawPrompt); | ||
|
||
if (errorMsg) { | ||
const elErrorMessage = createElementFromHTML(htmlEscape`<div class="ui error message">${errorMsg}</div>`); | ||
elViewRawPrompt.insertAdjacentElement('afterbegin', elErrorMessage); | ||
} | ||
}); | ||
} |
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,26 @@ | ||
/** | ||
* File Render Plugin System | ||
* | ||
* This module provides a plugin architecture for rendering different file types | ||
* in the browser without requiring backend support for identifying file types. | ||
*/ | ||
export type FileRenderPlugin = { | ||
// unique plugin name | ||
name: string; | ||
|
||
// test if plugin can handle a specified file | ||
canHandle: (filename: string, mimeType: string) => boolean; | ||
|
||
// render file content | ||
render: (container: HTMLElement, fileUrl: string, options?: any) => Promise<void>; | ||
} | ||
|
||
const plugins: FileRenderPlugin[] = []; | ||
|
||
export function registerFileRenderPlugin(plugin: FileRenderPlugin): void { | ||
plugins.push(plugin); | ||
} | ||
|
||
export function findFileRenderPlugin(filename: string, mimeType: string): FileRenderPlugin | null { | ||
return plugins.find((plugin) => plugin.canHandle(filename, mimeType)) || null; | ||
} |
This file was deleted.
Oops, something went wrong.
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.