feat: restore Wolai workspace navigation and assets
This commit is contained in:
@@ -92,6 +92,7 @@ export const createSidebarAttachmentOpenRuntime = (dependencies = {}) => {
|
||||
function localMarkdownAttachmentPathFromHref(href, documentId) {
|
||||
var raw = String(href || '').trim();
|
||||
if (!raw || raw.indexOf('#') === 0 || /^[a-z][a-z0-9+.-]*:/i.test(raw)) return '';
|
||||
if (raw.indexOf('/documents/') === 0 || raw.indexOf('/api/') === 0) return '';
|
||||
var documentPath = localMarkdownPathFromDocumentId(documentId);
|
||||
if (!documentPath) return '';
|
||||
var slashIndex = documentPath.lastIndexOf('/');
|
||||
@@ -271,6 +272,7 @@ export const createSidebarAttachmentOpenRuntime = (dependencies = {}) => {
|
||||
|
||||
async function refreshLocalAttachmentExistence(link) {
|
||||
if (!(link instanceof HTMLAnchorElement)) return;
|
||||
if (link.classList.contains('mnote-page-block-link')) return;
|
||||
var href = link.getAttribute('href') || link.href || '';
|
||||
var paneContext = editorAttachmentPaneContext(link);
|
||||
var attachmentRef = attachmentRefForHref(href, paneContext, link ? link.textContent : '');
|
||||
@@ -317,6 +319,7 @@ export const createSidebarAttachmentOpenRuntime = (dependencies = {}) => {
|
||||
|
||||
function refreshEditorLocalAttachmentExistence() {
|
||||
document.querySelectorAll(editorAttachmentEnhanceSelector + ', .editor-surface .ProseMirror a[href*="/api/local-folder/files/open"]').forEach(function(link) {
|
||||
if (link instanceof HTMLAnchorElement && link.classList.contains('mnote-page-block-link')) return;
|
||||
if (link instanceof HTMLAnchorElement) void refreshLocalAttachmentExistence(link);
|
||||
});
|
||||
}
|
||||
@@ -418,16 +421,33 @@ export const createSidebarAttachmentOpenRuntime = (dependencies = {}) => {
|
||||
try {
|
||||
absoluteHref = new URL(href, window.location.href).href;
|
||||
} catch (_) {}
|
||||
var localPath = normalizeLocalRelativePath(
|
||||
localFileOpenPathFromHref(href) || localMarkdownAttachmentPathFromHref(href, paneContext && paneContext.documentId)
|
||||
);
|
||||
return refs.find(function(ref) {
|
||||
if (!ref || typeof ref !== 'object') return false;
|
||||
var refRelativePath = normalizeLocalRelativePath(ref.relativePath || '');
|
||||
var refNormalizedHref = normalizeLocalRelativePath(ref.normalizedHref || ref.rawHref || '').replace(/^\.\//, '');
|
||||
return String(ref.rawHref || '') === href
|
||||
|| String(ref.normalizedHref || '') === href
|
||||
|| String(ref.resolvedUri || '') === href
|
||||
|| (absoluteHref && String(ref.resolvedUri || '') === absoluteHref)
|
||||
|| (localPath && refRelativePath && refRelativePath === localPath)
|
||||
|| (localPath && refNormalizedHref && localPath.endsWith('/' + refNormalizedHref))
|
||||
|| (!href && textLabel && String(ref.label || '').trim() === textLabel);
|
||||
}) || null;
|
||||
}
|
||||
|
||||
function attachmentFileSizeLabel(attachmentRef) {
|
||||
if (!attachmentRef || typeof attachmentRef !== 'object') return '';
|
||||
if (typeof uploadedFileSize === 'function') return uploadedFileSize(attachmentRef);
|
||||
var size = Number(attachmentRef.file_size || attachmentRef.fileSize || 0);
|
||||
if (!Number.isFinite(size) || size <= 0) return '';
|
||||
if (size >= 1024 * 1024) return (size / 1024 / 1024).toFixed(size >= 10 * 1024 * 1024 ? 1 : 2) + ' MB';
|
||||
if (size >= 1024) return (size / 1024).toFixed(size >= 100 * 1024 ? 0 : 2) + ' KB';
|
||||
return String(Math.round(size)) + ' B';
|
||||
}
|
||||
|
||||
function detailFromEditorAttachmentLink(link) {
|
||||
var rawHref = link instanceof HTMLAnchorElement ? (link.getAttribute('href') || '') : '';
|
||||
var params = attachmentQueryParams(rawHref);
|
||||
@@ -483,6 +503,7 @@ export const createSidebarAttachmentOpenRuntime = (dependencies = {}) => {
|
||||
function enhanceEditorAttachmentLink(link) {
|
||||
if (!(link instanceof HTMLAnchorElement)) return;
|
||||
var href = link.getAttribute('href') || '';
|
||||
if (link.classList.contains('mnote-page-block-link')) return;
|
||||
var params = attachmentQueryParams(href);
|
||||
var paneContext = editorAttachmentPaneContext(link);
|
||||
var attachmentRef = attachmentRefForHref(href, paneContext, link ? link.textContent : '');
|
||||
@@ -509,6 +530,8 @@ export const createSidebarAttachmentOpenRuntime = (dependencies = {}) => {
|
||||
if (typeof attachmentRef.authorized === 'boolean') {
|
||||
setEditorAttachmentUnauthorizedState(link, attachmentRef.authorized === false);
|
||||
}
|
||||
var fileSizeLabel = attachmentFileSizeLabel(attachmentRef);
|
||||
if (fileSizeLabel) setAttributeIfChanged(link, 'data-file-size', fileSizeLabel);
|
||||
}
|
||||
setAttributeIfChanged(link, 'target', '_blank');
|
||||
setAttributeIfChanged(link, 'rel', 'noopener noreferrer nofollow');
|
||||
|
||||
Reference in New Issue
Block a user