mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-06 11:59:51 +08:00
refactor(editor): align rich text util apis (#11039)
This commit is contained in:
+3
-3
@@ -29,7 +29,7 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = {
|
||||
model.doc.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
|
||||
action: ({ std, model }) => {
|
||||
const newDoc = createDefaultDoc(std.host.doc.workspace);
|
||||
insertContent(std.host, model, REFERENCE_NODE, {
|
||||
insertContent(std, model, REFERENCE_NODE, {
|
||||
reference: {
|
||||
type: 'LinkedPage',
|
||||
pageId: newDoc.id,
|
||||
@@ -70,9 +70,9 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = {
|
||||
// @ts-expect-error same as above
|
||||
const triggerKey = linkedDocWidget.config.triggerKeys[0];
|
||||
|
||||
insertContent(std.host, model, triggerKey);
|
||||
insertContent(std, model, triggerKey);
|
||||
|
||||
const inlineEditor = getInlineEditorByModel(std.host, model);
|
||||
const inlineEditor = getInlineEditorByModel(std, model);
|
||||
if (inlineEditor) {
|
||||
// Wait for range to be updated
|
||||
const subscription = inlineEditor.slots.inlineRangeSync.subscribe(
|
||||
|
||||
@@ -86,7 +86,7 @@ export const updateBlockType: Command<
|
||||
if (!id) return;
|
||||
const model = doc.getModelById(id);
|
||||
if (!model) return;
|
||||
asyncSetInlineRange(host, model, {
|
||||
asyncSetInlineRange(std, model, {
|
||||
index: model.text?.length ?? 0,
|
||||
length: 0,
|
||||
}).catch(console.error);
|
||||
@@ -132,7 +132,7 @@ export const updateBlockType: Command<
|
||||
const lastNewModel = updatedBlocks[updatedBlocks.length - 1];
|
||||
|
||||
const allTextUpdated = updatedBlocks.map(model =>
|
||||
onModelTextUpdated(host, model)
|
||||
onModelTextUpdated(std, model)
|
||||
);
|
||||
const selectionManager = host.selection;
|
||||
const textSelection = selectionManager.find(TextSelection);
|
||||
|
||||
@@ -119,7 +119,7 @@ class NoteKeymap {
|
||||
}
|
||||
|
||||
const [codeModel] = newModels;
|
||||
asyncGetBlockComponent(ctx.std.host, codeModel.id)
|
||||
asyncGetBlockComponent(ctx.std, codeModel.id)
|
||||
.then(codeElement => {
|
||||
if (!codeElement) {
|
||||
return;
|
||||
|
||||
@@ -15,7 +15,7 @@ export const splitParagraphCommand: Command<
|
||||
}
|
||||
> = (ctx, next) => {
|
||||
const { std } = ctx;
|
||||
const { store, host, selection } = std;
|
||||
const { store, selection } = std;
|
||||
let blockId = ctx.blockId;
|
||||
if (!blockId) {
|
||||
const text = selection.find(TextSelection);
|
||||
@@ -26,7 +26,7 @@ export const splitParagraphCommand: Command<
|
||||
const model = store.getBlock(blockId)?.model;
|
||||
if (!model || !matchModels(model, [ParagraphBlockModel])) return;
|
||||
|
||||
const inlineEditor = getInlineEditorByModel(host, model);
|
||||
const inlineEditor = getInlineEditorByModel(std, model);
|
||||
const range = inlineEditor?.getInlineRange();
|
||||
if (!range) return;
|
||||
|
||||
|
||||
@@ -83,10 +83,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
||||
matchModels(model.parent, [CalloutBlockModel])
|
||||
)
|
||||
return;
|
||||
const inlineEditor = getInlineEditorByModel(
|
||||
std.host,
|
||||
text.from.blockId
|
||||
);
|
||||
const inlineEditor = getInlineEditorByModel(std, text.from.blockId);
|
||||
const inlineRange = inlineEditor?.getInlineRange();
|
||||
if (!inlineRange || !inlineEditor) return;
|
||||
const raw = ctx.get('keyboardState').raw;
|
||||
@@ -115,10 +112,7 @@ export const ParagraphKeymapExtension = KeymapExtension(
|
||||
matchModels(model.parent, [CalloutBlockModel])
|
||||
)
|
||||
return;
|
||||
const inlineEditor = getInlineEditorByModel(
|
||||
std.host,
|
||||
text.from.blockId
|
||||
);
|
||||
const inlineEditor = getInlineEditorByModel(std, text.from.blockId);
|
||||
const inlineRange = inlineEditor?.getInlineRange();
|
||||
if (!inlineRange || !inlineEditor) return;
|
||||
|
||||
|
||||
@@ -77,7 +77,7 @@ export function mergeWithPrev(editorHost: EditorHost, model: BlockModel) {
|
||||
doc.deleteBlock(model, {
|
||||
bringChildrenTo: parent,
|
||||
});
|
||||
asyncSetInlineRange(editorHost, prevBlock, {
|
||||
asyncSetInlineRange(editorHost.std, prevBlock, {
|
||||
index: lengthBeforeJoin,
|
||||
length: 0,
|
||||
}).catch(console.error);
|
||||
|
||||
@@ -318,7 +318,7 @@ const pageToolGroup: KeyboardToolPanelGroup = {
|
||||
.pipe(({ selectedModels }) => {
|
||||
const newDoc = createDefaultDoc(std.store.workspace);
|
||||
if (!selectedModels?.length) return;
|
||||
insertContent(std.host, selectedModels[0], REFERENCE_NODE, {
|
||||
insertContent(std, selectedModels[0], REFERENCE_NODE, {
|
||||
reference: {
|
||||
type: 'LinkedPage',
|
||||
pageId: newDoc.id,
|
||||
@@ -360,9 +360,9 @@ const pageToolGroup: KeyboardToolPanelGroup = {
|
||||
if (!selectedModels?.length) return;
|
||||
|
||||
const currentModel = selectedModels[0];
|
||||
insertContent(std.host, currentModel, triggerKey);
|
||||
insertContent(std, currentModel, triggerKey);
|
||||
|
||||
const inlineEditor = getInlineEditorByModel(std.host, currentModel);
|
||||
const inlineEditor = getInlineEditorByModel(std, currentModel);
|
||||
// Wait for range to be updated
|
||||
if (inlineEditor) {
|
||||
const subscription = inlineEditor.slots.inlineRangeSync.subscribe(
|
||||
@@ -702,7 +702,7 @@ const dateToolGroup: KeyboardToolPanelGroup = {
|
||||
const model = selectedModels?.[0];
|
||||
if (!model) return;
|
||||
|
||||
insertContent(std.host, model, formatDate(new Date()));
|
||||
insertContent(std, model, formatDate(new Date()));
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -717,7 +717,7 @@ const dateToolGroup: KeyboardToolPanelGroup = {
|
||||
|
||||
const tomorrow = new Date();
|
||||
tomorrow.setDate(tomorrow.getDate() + 1);
|
||||
insertContent(std.host, model, formatDate(tomorrow));
|
||||
insertContent(std, model, formatDate(tomorrow));
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -732,7 +732,7 @@ const dateToolGroup: KeyboardToolPanelGroup = {
|
||||
|
||||
const yesterday = new Date();
|
||||
yesterday.setDate(yesterday.getDate() - 1);
|
||||
insertContent(std.host, model, formatDate(yesterday));
|
||||
insertContent(std, model, formatDate(yesterday));
|
||||
},
|
||||
},
|
||||
{
|
||||
@@ -745,7 +745,7 @@ const dateToolGroup: KeyboardToolPanelGroup = {
|
||||
const model = selectedModels?.[0];
|
||||
if (!model) return;
|
||||
|
||||
insertContent(std.host, model, formatTime(new Date()));
|
||||
insertContent(std, model, formatTime(new Date()));
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -38,7 +38,7 @@ export class LinkedDocPopover extends SignalWatcher(
|
||||
this.context.close();
|
||||
// clear input query
|
||||
cleanSpecifiedTail(
|
||||
this.context.std.host,
|
||||
this.context.std,
|
||||
this.context.inlineEditor,
|
||||
this.context.triggerKey + (this._query || '')
|
||||
);
|
||||
|
||||
+1
-1
@@ -134,7 +134,7 @@ export class AffineMobileLinkedDocMenu extends SignalWatcher(
|
||||
() => {
|
||||
this.context.close();
|
||||
cleanSpecifiedTail(
|
||||
this.context.std.host,
|
||||
this.context.std,
|
||||
this.context.inlineEditor,
|
||||
this.context.triggerKey + (this._query ?? '')
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user