一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
53 行
2.2 KiB
TypeScript
53 行
2.2 KiB
TypeScript
import Logger from '@joplin/utils/Logger';
|
|
import time from '../../time';
|
|
import { formatMsToRelative } from '@joplin/utils/time';
|
|
import { TagEntity } from '../database/types';
|
|
import { ListRendererDependency, RenderNoteView } from '../plugins/api/noteListType';
|
|
|
|
const logger = Logger.create('renderViewProps');
|
|
|
|
export interface RenderViewPropsOptions {
|
|
// Note that we don't render the title here, because it requires the mark.js package which is
|
|
// only available on the `app-desktop` package. So the caller needs to pre-render the title and
|
|
// pass it as an option.
|
|
noteTitleHtml: string;
|
|
}
|
|
|
|
const renderViewProp = (name: ListRendererDependency, value: unknown, options: RenderViewPropsOptions): string => {
|
|
const renderers: Partial<Record<ListRendererDependency, ()=> string>> = {
|
|
'note.user_updated_time': () => formatMsToRelative(value as number),
|
|
'note.user_created_time': () => formatMsToRelative(value as number),
|
|
'note.updated_time': () => formatMsToRelative(value as number),
|
|
'note.created_time': () => formatMsToRelative(value as number),
|
|
'note.todo_completed': () => value ? time.formatMsToLocal(value as number) : '',
|
|
'note.todo_due': () => value ? time.formatMsToLocal(value as number) : '',
|
|
'note.tags': () => value ? (value as TagEntity[]).map(t => t.title).join(', ') : '',
|
|
'note.title': () => options.noteTitleHtml,
|
|
};
|
|
|
|
try {
|
|
const renderer = renderers[name];
|
|
if (renderer) return renderer();
|
|
} catch (error) {
|
|
// If the input value doesn't have the expected format, it may have been changed by the
|
|
// user. In that case we return the value without rendering it.
|
|
logger.warn('Could not render property:', name, 'With value:', value, 'Error:', error);
|
|
return value as string;
|
|
}
|
|
|
|
return value as string;
|
|
};
|
|
|
|
const renderViewProps = async (view: RenderNoteView, parentPath: string[], options: RenderViewPropsOptions) => {
|
|
for (const [name, value] of Object.entries(view)) {
|
|
const currentPath = parentPath.concat([name]);
|
|
if (value && typeof value === 'object' && !Array.isArray(value)) {
|
|
await renderViewProps(value, currentPath, options);
|
|
} else {
|
|
view[name] = renderViewProp(currentPath.join('.') as ListRendererDependency, value, options);
|
|
}
|
|
}
|
|
};
|
|
|
|
export default renderViewProps;
|