一些检查失败了
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
54 行
1.6 KiB
TypeScript
54 行
1.6 KiB
TypeScript
import { Command } from 'prosemirror-state';
|
|
import { getEditorApi } from '../joplinEditorApiPlugin';
|
|
import createEditorDialog from './utils/createEditorDialog';
|
|
import postProcessRenderedHtml from './utils/postProcessRenderedHtml';
|
|
import schema from '../../schema';
|
|
import { JoplinEditableAttributes } from './joplinEditablePlugin';
|
|
|
|
interface EditablePromptOptions {
|
|
source: string;
|
|
inline: boolean;
|
|
cursor: number;
|
|
}
|
|
|
|
const showCreateEditablePrompt = ({ source, inline, cursor }: EditablePromptOptions): Command => (_state, dispatch, view) => {
|
|
if (!dispatch) return true;
|
|
if (!view) throw new Error('Missing required argument: view');
|
|
|
|
createEditorDialog({
|
|
editorApi: getEditorApi(view.state),
|
|
source,
|
|
cursor,
|
|
onSave: async (newSource) => {
|
|
source = newSource;
|
|
},
|
|
onDismiss: async () => {
|
|
const rendered = await getEditorApi(view.state).renderer.renderMarkupToHtml(
|
|
source,
|
|
{ forceMarkdown: true, isFullPageRender: false },
|
|
);
|
|
|
|
const html = postProcessRenderedHtml(rendered.html, inline);
|
|
const state = view.state;
|
|
const node = inline ? schema.nodes.joplinEditableInline : schema.nodes.joplinEditableBlock;
|
|
const tr = state.tr.replaceSelectionWith(
|
|
node.create({
|
|
contentHtml: html,
|
|
source,
|
|
closeCharacters: '',
|
|
openCharacters: '',
|
|
language: '',
|
|
readOnly: false,
|
|
} satisfies JoplinEditableAttributes),
|
|
);
|
|
view.dispatch(tr);
|
|
|
|
// Required by certain renderer plugins:
|
|
document.dispatchEvent(new Event('joplin-noteDidUpdate'));
|
|
},
|
|
});
|
|
return true;
|
|
};
|
|
|
|
export default showCreateEditablePrompt;
|