refactor(editor): rename doc to store on block components (#12173)
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Unified internal data access by replacing all references from `doc` to `store` across all components, blocks, widgets, and utilities. This affects how readonly state, block operations, and service retrieval are handled throughout the application. - **Tests** - Updated all test utilities and test cases to use `store` instead of `doc` for document-related operations. - **Chores** - Updated context providers and property names to reflect the change from `doc` to `store` for improved consistency and maintainability. No user-facing features or behaviors have changed. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
@@ -79,7 +79,7 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
};
|
};
|
||||||
|
|
||||||
copy = () => {
|
copy = () => {
|
||||||
const slice = Slice.fromModels(this.doc, [this.model]);
|
const slice = Slice.fromModels(this.store, [this.model]);
|
||||||
this.std.clipboard.copySlice(slice).catch(console.error);
|
this.std.clipboard.copySlice(slice).catch(console.error);
|
||||||
toast(this.host, 'Copied to clipboard');
|
toast(this.host, 'Copied to clipboard');
|
||||||
};
|
};
|
||||||
@@ -133,9 +133,9 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
|
|
||||||
this.refreshData();
|
this.refreshData();
|
||||||
|
|
||||||
if (!this.model.props.style && !this.doc.readonly) {
|
if (!this.model.props.style && !this.store.readonly) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
style: AttachmentBlockStyles[1],
|
style: AttachmentBlockStyles[1],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -127,7 +127,10 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
handleClick = (event: MouseEvent) => {
|
handleClick = (event: MouseEvent) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
|
|
||||||
if (this.model.parent?.flavour !== 'affine:surface' && !this.doc.readonly) {
|
if (
|
||||||
|
this.model.parent?.flavour !== 'affine:surface' &&
|
||||||
|
!this.store.readonly
|
||||||
|
) {
|
||||||
this.selectBlock();
|
this.selectBlock();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -184,7 +187,7 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
) {
|
) {
|
||||||
// When the doc is readonly, and the preview data not provided
|
// When the doc is readonly, and the preview data not provided
|
||||||
// We should fetch the preview data and update the local link preview data
|
// We should fetch the preview data and update the local link preview data
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
this._updateLocalLinkPreview();
|
this._updateLocalLinkPreview();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ export class BookmarkCard extends SignalWatcher(
|
|||||||
|
|
||||||
const theme = this.bookmark.std.get(ThemeProvider).theme;
|
const theme = this.bookmark.std.get(ThemeProvider).theme;
|
||||||
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
||||||
const imageProxyService = this.bookmark.doc.get(ImageProxyService);
|
const imageProxyService = this.bookmark.store.get(ImageProxyService);
|
||||||
|
|
||||||
const titleIcon = this.loading
|
const titleIcon = this.loading
|
||||||
? LoadingIcon
|
? LoadingIcon
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ const bookmarkSlashMenuConfig: SlashMenuConfig = {
|
|||||||
model.store.schema.flavourSchemaMap.has('affine:bookmark'),
|
model.store.schema.flavourSchemaMap.has('affine:bookmark'),
|
||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
const { host } = std;
|
const { host } = std;
|
||||||
const parentModel = host.doc.getParent(model);
|
const parentModel = host.store.getParent(model);
|
||||||
if (!parentModel) {
|
if (!parentModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export async function refreshBookmarkUrlData(
|
|||||||
try {
|
try {
|
||||||
bookmarkElement.loading = true;
|
bookmarkElement.loading = true;
|
||||||
|
|
||||||
const linkPreviewer = bookmarkElement.doc.get(LinkPreviewerService);
|
const linkPreviewer = bookmarkElement.store.get(LinkPreviewerService);
|
||||||
const bookmarkUrlData = await linkPreviewer.query(
|
const bookmarkUrlData = await linkPreviewer.query(
|
||||||
bookmarkElement.model.props.url,
|
bookmarkElement.model.props.url,
|
||||||
signal
|
signal
|
||||||
@@ -32,7 +32,7 @@ export async function refreshBookmarkUrlData(
|
|||||||
|
|
||||||
if (signal?.aborted) return;
|
if (signal?.aborted) return;
|
||||||
|
|
||||||
bookmarkElement.doc.updateBlock(bookmarkElement.model, {
|
bookmarkElement.store.updateBlock(bookmarkElement.model, {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
icon,
|
icon,
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
get readonly() {
|
get readonly() {
|
||||||
return this.doc.readonly;
|
return this.store.readonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
get langs() {
|
get langs() {
|
||||||
@@ -226,7 +226,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
|||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
Tab: ctx => {
|
Tab: ctx => {
|
||||||
if (this.doc.readonly) return;
|
if (this.store.readonly) return;
|
||||||
const state = ctx.get('keyboardState');
|
const state = ctx.get('keyboardState');
|
||||||
const event = state.raw;
|
const event = state.raw;
|
||||||
const inlineEditor = this.inlineEditor;
|
const inlineEditor = this.inlineEditor;
|
||||||
@@ -337,7 +337,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
|||||||
return;
|
return;
|
||||||
},
|
},
|
||||||
Enter: () => {
|
Enter: () => {
|
||||||
this.doc.captureSync();
|
this.store.captureSync();
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
'Mod-Enter': () => {
|
'Mod-Enter': () => {
|
||||||
@@ -348,11 +348,16 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
|||||||
if (!inlineRange || !inlineEditor) return;
|
if (!inlineRange || !inlineEditor) return;
|
||||||
const isEnd = model.props.text.length === inlineRange.index;
|
const isEnd = model.props.text.length === inlineRange.index;
|
||||||
if (!isEnd) return;
|
if (!isEnd) return;
|
||||||
const parent = this.doc.getParent(model);
|
const parent = this.store.getParent(model);
|
||||||
if (!parent) return;
|
if (!parent) return;
|
||||||
const index = parent.children.indexOf(model);
|
const index = parent.children.indexOf(model);
|
||||||
if (index === -1) return;
|
if (index === -1) return;
|
||||||
const id = this.doc.addBlock('affine:paragraph', {}, parent, index + 1);
|
const id = this.store.addBlock(
|
||||||
|
'affine:paragraph',
|
||||||
|
{},
|
||||||
|
parent,
|
||||||
|
index + 1
|
||||||
|
);
|
||||||
focusTextModel(std, id);
|
focusTextModel(std, id);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
@@ -406,10 +411,10 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
|||||||
})}
|
})}
|
||||||
.yText=${this.model.props.text.yText}
|
.yText=${this.model.props.text.yText}
|
||||||
.inlineEventSource=${this.topContenteditableElement ?? nothing}
|
.inlineEventSource=${this.topContenteditableElement ?? nothing}
|
||||||
.undoManager=${this.doc.history}
|
.undoManager=${this.store.history}
|
||||||
.attributesSchema=${this.inlineManager.getSchema()}
|
.attributesSchema=${this.inlineManager.getSchema()}
|
||||||
.attributeRenderer=${this.inlineManager.getRenderer()}
|
.attributeRenderer=${this.inlineManager.getRenderer()}
|
||||||
.readonly=${this.doc.readonly}
|
.readonly=${this.store.readonly}
|
||||||
.inlineRangeProvider=${this._inlineRangeProvider}
|
.inlineRangeProvider=${this._inlineRangeProvider}
|
||||||
.enableClipboard=${false}
|
.enableClipboard=${false}
|
||||||
.enableUndoRedo=${false}
|
.enableUndoRedo=${false}
|
||||||
@@ -442,7 +447,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
|
|||||||
}
|
}
|
||||||
|
|
||||||
setWrap(wrap: boolean) {
|
setWrap(wrap: boolean) {
|
||||||
this.doc.updateBlock(this.model, { wrap });
|
this.store.updateBlock(this.model, { wrap });
|
||||||
}
|
}
|
||||||
|
|
||||||
@query('rich-text')
|
@query('rich-text')
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ export class LanguageListButton extends WithDisposable(
|
|||||||
private _abortController?: AbortController;
|
private _abortController?: AbortController;
|
||||||
|
|
||||||
private readonly _clickLangBtn = () => {
|
private readonly _clickLangBtn = () => {
|
||||||
if (this.blockComponent.doc.readonly) return;
|
if (this.blockComponent.store.readonly) return;
|
||||||
if (this._abortController) {
|
if (this._abortController) {
|
||||||
// Close the language list if it's already opened.
|
// Close the language list if it's already opened.
|
||||||
this._abortController.abort();
|
this._abortController.abort();
|
||||||
@@ -71,7 +71,7 @@ export class LanguageListButton extends WithDisposable(
|
|||||||
sortedBundledLanguages.splice(index, 1);
|
sortedBundledLanguages.splice(index, 1);
|
||||||
sortedBundledLanguages.unshift(item);
|
sortedBundledLanguages.unshift(item);
|
||||||
}
|
}
|
||||||
this.blockComponent.doc.transact(() => {
|
this.blockComponent.store.transact(() => {
|
||||||
this.blockComponent.model.props.language$.value = item.name;
|
this.blockComponent.model.props.language$.value = item.name;
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
@@ -134,10 +134,10 @@ export class LanguageListButton extends WithDisposable(
|
|||||||
</div>`}
|
</div>`}
|
||||||
height="24px"
|
height="24px"
|
||||||
@click=${this._clickLangBtn}
|
@click=${this._clickLangBtn}
|
||||||
?disabled=${this.blockComponent.doc.readonly}
|
?disabled=${this.blockComponent.store.readonly}
|
||||||
>
|
>
|
||||||
<span class="lang-button-icon" slot="suffix">
|
<span class="lang-button-icon" slot="suffix">
|
||||||
${!this.blockComponent.doc.readonly ? ArrowDownIcon : nothing}
|
${!this.blockComponent.store.readonly ? ArrowDownIcon : nothing}
|
||||||
</span>
|
</span>
|
||||||
</icon-button> `;
|
</icon-button> `;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,9 +50,9 @@ export class PreviewButton extends WithDisposable(SignalWatcher(LitElement)) {
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
private readonly _toggle = (value: boolean) => {
|
private readonly _toggle = (value: boolean) => {
|
||||||
if (this.blockComponent.doc.readonly) return;
|
if (this.blockComponent.store.readonly) return;
|
||||||
|
|
||||||
this.blockComponent.doc.updateBlock(this.blockComponent.model, {
|
this.blockComponent.store.updateBlock(this.blockComponent.model, {
|
||||||
preview: value,
|
preview: value,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export class CodeBlockToolbarContext extends MenuContext {
|
|||||||
};
|
};
|
||||||
|
|
||||||
get doc() {
|
get doc() {
|
||||||
return this.blockComponent.doc;
|
return this.blockComponent.store;
|
||||||
}
|
}
|
||||||
|
|
||||||
get host() {
|
get host() {
|
||||||
|
|||||||
@@ -26,16 +26,16 @@ export const dataViewSlashMenuConfig: SlashMenuConfig = {
|
|||||||
|
|
||||||
action: ({ model, std }) => {
|
action: ({ model, std }) => {
|
||||||
const { host } = std;
|
const { host } = std;
|
||||||
const parent = host.doc.getParent(model);
|
const parent = host.store.getParent(model);
|
||||||
if (!parent) return;
|
if (!parent) return;
|
||||||
const index = parent.children.indexOf(model);
|
const index = parent.children.indexOf(model);
|
||||||
const id = host.doc.addBlock(
|
const id = host.store.addBlock(
|
||||||
'affine:data-view',
|
'affine:data-view',
|
||||||
{},
|
{},
|
||||||
host.doc.getParent(model),
|
host.store.getParent(model),
|
||||||
index + 1
|
index + 1
|
||||||
);
|
);
|
||||||
const dataViewModel = host.doc.getBlock(id)!;
|
const dataViewModel = host.store.getBlock(id)!;
|
||||||
|
|
||||||
const dataView = std.view.getBlock(
|
const dataView = std.view.getBlock(
|
||||||
dataViewModel.id
|
dataViewModel.id
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ export class BlockQueryDataSource extends DataSourceBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get workspace() {
|
get workspace() {
|
||||||
return this.host.doc.workspace;
|
return this.host.store.workspace;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
|||||||
prefix: CopyIcon,
|
prefix: CopyIcon,
|
||||||
name: 'Copy',
|
name: 'Copy',
|
||||||
select: () => {
|
select: () => {
|
||||||
const slice = Slice.fromModels(this.doc, [this.model]);
|
const slice = Slice.fromModels(this.store, [this.model]);
|
||||||
this.std.clipboard.copySlice(slice).catch(console.error);
|
this.std.clipboard.copySlice(slice).catch(console.error);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
@@ -119,9 +119,9 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
|||||||
name: 'Delete Database',
|
name: 'Delete Database',
|
||||||
select: () => {
|
select: () => {
|
||||||
this.model.children.slice().forEach(block => {
|
this.model.children.slice().forEach(block => {
|
||||||
this.doc.deleteBlock(block);
|
this.store.deleteBlock(block);
|
||||||
});
|
});
|
||||||
this.doc.deleteBlock(this.model);
|
this.store.deleteBlock(this.model);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@@ -237,7 +237,7 @@ export class DataViewBlockComponent extends CaptionedBlockComponent<DataViewBloc
|
|||||||
}
|
}
|
||||||
|
|
||||||
private renderDatabaseOps() {
|
private renderDatabaseOps() {
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
return html` <div class="database-ops" @click="${this._clickDatabaseOps}">
|
return html` <div class="database-ops" @click="${this._clickDatabaseOps}">
|
||||||
|
|||||||
@@ -568,20 +568,20 @@ export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
|||||||
const firstModel = selectedModels?.[0];
|
const firstModel = selectedModels?.[0];
|
||||||
if (!firstModel) return;
|
if (!firstModel) return;
|
||||||
|
|
||||||
host.doc.captureSync();
|
host.store.captureSync();
|
||||||
|
|
||||||
const parentModel = host.doc.getParent(firstModel);
|
const parentModel = host.store.getParent(firstModel);
|
||||||
if (!parentModel) {
|
if (!parentModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const id = host.doc.addBlock(
|
const id = host.store.addBlock(
|
||||||
'affine:database',
|
'affine:database',
|
||||||
{},
|
{},
|
||||||
parentModel,
|
parentModel,
|
||||||
parentModel.children.indexOf(firstModel)
|
parentModel.children.indexOf(firstModel)
|
||||||
);
|
);
|
||||||
const databaseModel = host.doc.getBlock(id)?.model as
|
const databaseModel = host.store.getBlock(id)?.model as
|
||||||
| DatabaseBlockModel
|
| DatabaseBlockModel
|
||||||
| undefined;
|
| undefined;
|
||||||
if (!databaseModel) {
|
if (!databaseModel) {
|
||||||
@@ -589,7 +589,7 @@ export const convertToDatabase = (host: EditorHost, viewType: string) => {
|
|||||||
}
|
}
|
||||||
const datasource = new DatabaseBlockDataSource(databaseModel);
|
const datasource = new DatabaseBlockDataSource(databaseModel);
|
||||||
datasource.viewManager.viewAdd(viewType);
|
datasource.viewManager.viewAdd(viewType);
|
||||||
host.doc.moveBlocks(selectedModels, databaseModel);
|
host.store.moveBlocks(selectedModels, databaseModel);
|
||||||
|
|
||||||
const selectionManager = host.selection;
|
const selectionManager = host.selection;
|
||||||
selectionManager.clear();
|
selectionManager.clear();
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBloc
|
|||||||
prefix: CopyIcon(),
|
prefix: CopyIcon(),
|
||||||
name: 'Copy',
|
name: 'Copy',
|
||||||
select: () => {
|
select: () => {
|
||||||
const slice = Slice.fromModels(this.doc, [this.model]);
|
const slice = Slice.fromModels(this.store, [this.model]);
|
||||||
this.std.clipboard
|
this.std.clipboard
|
||||||
.copySlice(slice)
|
.copySlice(slice)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
@@ -139,9 +139,9 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBloc
|
|||||||
name: 'Delete Database',
|
name: 'Delete Database',
|
||||||
select: () => {
|
select: () => {
|
||||||
this.model.children.slice().forEach(block => {
|
this.model.children.slice().forEach(block => {
|
||||||
this.doc.deleteBlock(block);
|
this.store.deleteBlock(block);
|
||||||
});
|
});
|
||||||
this.doc.deleteBlock(this.model);
|
this.store.deleteBlock(this.model);
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
],
|
],
|
||||||
@@ -258,18 +258,18 @@ export class DatabaseBlockComponent extends CaptionedBlockComponent<DatabaseBloc
|
|||||||
);
|
);
|
||||||
return () => {
|
return () => {
|
||||||
this.indicator.remove();
|
this.indicator.remove();
|
||||||
const model = this.doc.getBlock(id)?.model;
|
const model = this.store.getBlock(id)?.model;
|
||||||
const target = result.modelState.model;
|
const target = result.modelState.model;
|
||||||
let parent = this.doc.getParent(target.id);
|
let parent = this.store.getParent(target.id);
|
||||||
const shouldInsertIn = result.placement === 'in';
|
const shouldInsertIn = result.placement === 'in';
|
||||||
if (shouldInsertIn) {
|
if (shouldInsertIn) {
|
||||||
parent = target;
|
parent = target;
|
||||||
}
|
}
|
||||||
if (model && target && parent) {
|
if (model && target && parent) {
|
||||||
if (shouldInsertIn) {
|
if (shouldInsertIn) {
|
||||||
this.doc.moveBlocks([model], parent);
|
this.store.moveBlocks([model], parent);
|
||||||
} else {
|
} else {
|
||||||
this.doc.moveBlocks(
|
this.store.moveBlocks(
|
||||||
[model],
|
[model],
|
||||||
parent,
|
parent,
|
||||||
target,
|
target,
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export class BlockRenderer
|
|||||||
}
|
}
|
||||||
|
|
||||||
get model() {
|
get model() {
|
||||||
return this.host?.doc.getBlock(this.rowId)?.model;
|
return this.host?.store.getBlock(this.rowId)?.model;
|
||||||
}
|
}
|
||||||
|
|
||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
`;
|
`;
|
||||||
|
|
||||||
private readonly _resizeObserver = new ResizeObserver(() => {
|
private readonly _resizeObserver = new ResizeObserver(() => {
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
const rect = this._textContainer.getBoundingClientRect();
|
const rect = this._textContainer.getBoundingClientRect();
|
||||||
bound.h = rect.height / this.gfx.viewport.zoom;
|
bound.h = rect.height / this.gfx.viewport.zoom;
|
||||||
|
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
xywh: bound.serialize(),
|
xywh: bound.serialize(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
EDGELESS_TEXT_BLOCK_MIN_WIDTH * this.gfx.viewport.zoom
|
EDGELESS_TEXT_BLOCK_MIN_WIDTH * this.gfx.viewport.zoom
|
||||||
);
|
);
|
||||||
|
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
xywh: bound.serialize(),
|
xywh: bound.serialize(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
!firstChild ||
|
!firstChild ||
|
||||||
!matchModels(firstChild, [ListBlockModel, ParagraphBlockModel])
|
!matchModels(firstChild, [ListBlockModel, ParagraphBlockModel])
|
||||||
) {
|
) {
|
||||||
newParagraphId = this.doc.addBlock(
|
newParagraphId = this.store.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{},
|
{},
|
||||||
this.model.id,
|
this.model.id,
|
||||||
@@ -182,7 +182,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
!lastChild ||
|
!lastChild ||
|
||||||
!matchModels(lastChild, [ListBlockModel, ParagraphBlockModel])
|
!matchModels(lastChild, [ListBlockModel, ParagraphBlockModel])
|
||||||
) {
|
) {
|
||||||
newParagraphId = this.doc.addBlock(
|
newParagraphId = this.store.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{},
|
{},
|
||||||
this.model.id
|
this.model.id
|
||||||
@@ -284,7 +284,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.model.children.length === 0) {
|
if (this.model.children.length === 0) {
|
||||||
const blockId = this.doc.addBlock(
|
const blockId = this.store.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{ type: 'text' },
|
{ type: 'text' },
|
||||||
this.model.id
|
this.model.id
|
||||||
@@ -339,7 +339,7 @@ export class EdgelessTextBlockComponent extends GfxBlockComponent<EdgelessTextBl
|
|||||||
minWidth: !hasMaxWidth ? '220px' : undefined,
|
minWidth: !hasMaxWidth ? '220px' : undefined,
|
||||||
};
|
};
|
||||||
|
|
||||||
this.contentEditable = String(editing && !this.doc.readonly$.value);
|
this.contentEditable = String(editing && !this.store.readonly$.value);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div
|
<div
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ const linkedDocSlashMenuConfig: SlashMenuConfig = {
|
|||||||
when: ({ model }) =>
|
when: ({ model }) =>
|
||||||
model.store.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
|
model.store.schema.flavourSchemaMap.has('affine:embed-linked-doc'),
|
||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
const newDoc = createDefaultDoc(std.host.doc.workspace);
|
const newDoc = createDefaultDoc(std.host.store.workspace);
|
||||||
insertContent(std, model, REFERENCE_NODE, {
|
insertContent(std, model, REFERENCE_NODE, {
|
||||||
reference: {
|
reference: {
|
||||||
type: 'LinkedPage',
|
type: 'LinkedPage',
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ import { styles } from './styles.js';
|
|||||||
import { getEmbedLinkedDocIcons } from './utils.js';
|
import { getEmbedLinkedDocIcons } from './utils.js';
|
||||||
|
|
||||||
@Peekable({
|
@Peekable({
|
||||||
enableOn: ({ doc }: EmbedLinkedDocBlockComponent) => !doc.readonly,
|
enableOn: ({ store }: EmbedLinkedDocBlockComponent) => !store.readonly,
|
||||||
})
|
})
|
||||||
export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinkedDocModel> {
|
export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinkedDocModel> {
|
||||||
static override styles = styles;
|
static override styles = styles;
|
||||||
@@ -124,7 +124,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
|||||||
};
|
};
|
||||||
|
|
||||||
private readonly _setDocUpdatedAt = () => {
|
private readonly _setDocUpdatedAt = () => {
|
||||||
const meta = this.doc.workspace.meta.getDocMeta(this.model.props.pageId);
|
const meta = this.store.workspace.meta.getDocMeta(this.model.props.pageId);
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const date = meta.updatedDate || meta.createDate;
|
const date = meta.updatedDate || meta.createDate;
|
||||||
this._docUpdatedAt = new Date(date);
|
this._docUpdatedAt = new Date(date);
|
||||||
@@ -249,7 +249,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
|||||||
}
|
}
|
||||||
|
|
||||||
get readonly() {
|
get readonly() {
|
||||||
return this.doc.readonly;
|
return this.store.readonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isCitation() {
|
get isCitation() {
|
||||||
@@ -504,7 +504,7 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
|||||||
|
|
||||||
this._setDocUpdatedAt();
|
this._setDocUpdatedAt();
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this.doc.workspace.slots.docListUpdated.subscribe(() => {
|
this.store.workspace.slots.docListUpdated.subscribe(() => {
|
||||||
this._setDocUpdatedAt();
|
this._setDocUpdatedAt();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -563,8 +563,8 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
|||||||
if (linkedDoc && style === 'horizontalThin') {
|
if (linkedDoc && style === 'horizontalThin') {
|
||||||
bound.w = EMBED_CARD_WIDTH.horizontal;
|
bound.w = EMBED_CARD_WIDTH.horizontal;
|
||||||
bound.h = EMBED_CARD_HEIGHT.horizontal;
|
bound.h = EMBED_CARD_HEIGHT.horizontal;
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
xywh: bound.serialize(),
|
xywh: bound.serialize(),
|
||||||
style: 'horizontal',
|
style: 'horizontal',
|
||||||
});
|
});
|
||||||
@@ -572,8 +572,8 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
|
|||||||
} else if (!linkedDoc && style === 'horizontal') {
|
} else if (!linkedDoc && style === 'horizontal') {
|
||||||
bound.w = EMBED_CARD_WIDTH.horizontalThin;
|
bound.w = EMBED_CARD_WIDTH.horizontalThin;
|
||||||
bound.h = EMBED_CARD_HEIGHT.horizontalThin;
|
bound.h = EMBED_CARD_HEIGHT.horizontalThin;
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
xywh: bound.serialize(),
|
xywh: bound.serialize(),
|
||||||
style: 'horizontalThin',
|
style: 'horizontalThin',
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -48,7 +48,7 @@ import type { EmbedSyncedDocCard } from './components/embed-synced-doc-card.js';
|
|||||||
import { blockStyles } from './styles.js';
|
import { blockStyles } from './styles.js';
|
||||||
|
|
||||||
@Peekable({
|
@Peekable({
|
||||||
enableOn: ({ doc }: EmbedSyncedDocBlockComponent) => !doc.readonly,
|
enableOn: ({ store }: EmbedSyncedDocBlockComponent) => !store.readonly,
|
||||||
})
|
})
|
||||||
export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSyncedDocModel> {
|
export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSyncedDocModel> {
|
||||||
static override styles = blockStyles;
|
static override styles = blockStyles;
|
||||||
@@ -348,7 +348,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
|||||||
|
|
||||||
open = (event?: Partial<DocLinkClickedEvent>) => {
|
open = (event?: Partial<DocLinkClickedEvent>) => {
|
||||||
const pageId = this.model.props.pageId;
|
const pageId = this.model.props.pageId;
|
||||||
if (pageId === this.doc.id) return;
|
if (pageId === this.store.id) return;
|
||||||
|
|
||||||
this.std
|
this.std
|
||||||
.getOptional(RefNodeSlotsProvider)
|
.getOptional(RefNodeSlotsProvider)
|
||||||
@@ -413,7 +413,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
|||||||
let editorHost: EditorHost | null = this.host;
|
let editorHost: EditorHost | null = this.host;
|
||||||
while (editorHost && !this._cycle) {
|
while (editorHost && !this._cycle) {
|
||||||
this._cycle =
|
this._cycle =
|
||||||
!!editorHost && editorHost.doc.id === this.model.props.pageId;
|
!!editorHost && editorHost.store.id === this.model.props.pageId;
|
||||||
editorHost = editorHost.parentElement?.closest('editor-host') ?? null;
|
editorHost = editorHost.parentElement?.closest('editor-host') ?? null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -482,7 +482,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _setDocUpdatedAt() {
|
private _setDocUpdatedAt() {
|
||||||
const meta = this.doc.workspace.meta.getDocMeta(this.model.props.pageId);
|
const meta = this.store.workspace.meta.getDocMeta(this.model.props.pageId);
|
||||||
if (meta) {
|
if (meta) {
|
||||||
const date = meta.updatedDate || meta.createDate;
|
const date = meta.updatedDate || meta.createDate;
|
||||||
this._docUpdatedAt = new Date(date);
|
this._docUpdatedAt = new Date(date);
|
||||||
@@ -518,7 +518,7 @@ export class EmbedSyncedDocBlockComponent extends EmbedBlockComponent<EmbedSynce
|
|||||||
|
|
||||||
this._setDocUpdatedAt();
|
this._setDocUpdatedAt();
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this.doc.workspace.slots.docListUpdated.subscribe(() => {
|
this.store.workspace.slots.docListUpdated.subscribe(() => {
|
||||||
this._setDocUpdatedAt();
|
this._setDocUpdatedAt();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -46,10 +46,10 @@ export function insertEmbedCard(
|
|||||||
if (blockId) {
|
if (blockId) {
|
||||||
const block = host.view.getBlock(blockId);
|
const block = host.view.getBlock(blockId);
|
||||||
if (!block) return;
|
if (!block) return;
|
||||||
const parent = host.doc.getParent(block.model);
|
const parent = host.store.getParent(block.model);
|
||||||
if (!parent) return;
|
if (!parent) return;
|
||||||
const index = parent.children.indexOf(block.model);
|
const index = parent.children.indexOf(block.model);
|
||||||
const cardId = host.doc.addBlock(
|
const cardId = host.store.addBlock(
|
||||||
flavour as never,
|
flavour as never,
|
||||||
props,
|
props,
|
||||||
parent,
|
parent,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const embedFigmaSlashMenuConfig: SlashMenuConfig = {
|
|||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { host } = std;
|
const { host } = std;
|
||||||
const parentModel = host.doc.getParent(model);
|
const parentModel = host.store.getParent(model);
|
||||||
if (!parentModel) {
|
if (!parentModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,8 @@ export class EmbedFigmaBlockComponent extends EmbedBlockComponent<EmbedFigmaMode
|
|||||||
this._cardStyle = this.model.props.style;
|
this._cardStyle = this.model.props.style;
|
||||||
|
|
||||||
if (!this.model.props.title) {
|
if (!this.model.props.title) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
title: 'Figma',
|
title: 'Figma',
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const embedGithubSlashMenuConfig: SlashMenuConfig = {
|
|||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { host } = std;
|
const { host } = std;
|
||||||
const parentModel = host.doc.getParent(model);
|
const parentModel = host.store.getParent(model);
|
||||||
if (!parentModel) {
|
if (!parentModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,12 +83,12 @@ export class EmbedGithubBlockComponent extends EmbedBlockComponent<
|
|||||||
!this.model.props.repo ||
|
!this.model.props.repo ||
|
||||||
!this.model.props.githubId
|
!this.model.props.githubId
|
||||||
) {
|
) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
const url = this.model.props.url;
|
const url = this.model.props.url;
|
||||||
const urlMatch = url.match(githubUrlRegex);
|
const urlMatch = url.match(githubUrlRegex);
|
||||||
if (urlMatch) {
|
if (urlMatch) {
|
||||||
const [, owner, repo, githubType, githubId] = urlMatch;
|
const [, owner, repo, githubType, githubId] = urlMatch;
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
owner,
|
owner,
|
||||||
repo,
|
repo,
|
||||||
githubType: githubType === 'issue' ? 'issue' : 'pr',
|
githubType: githubType === 'issue' ? 'issue' : 'pr',
|
||||||
@@ -98,7 +98,7 @@ export class EmbedGithubBlockComponent extends EmbedBlockComponent<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
if (!this.model.props.description && !this.model.props.title) {
|
if (!this.model.props.description && !this.model.props.title) {
|
||||||
this.refreshData();
|
this.refreshData();
|
||||||
} else {
|
} else {
|
||||||
@@ -132,7 +132,7 @@ export class EmbedGithubBlockComponent extends EmbedBlockComponent<
|
|||||||
|
|
||||||
const loading = this.loading;
|
const loading = this.loading;
|
||||||
const theme = this.std.get(ThemeProvider).theme;
|
const theme = this.std.get(ThemeProvider).theme;
|
||||||
const imageProxyService = this.doc.get(ImageProxyService);
|
const imageProxyService = this.store.get(ImageProxyService);
|
||||||
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
||||||
const titleIcon = loading ? LoadingIcon : GithubIcon;
|
const titleIcon = loading ? LoadingIcon : GithubIcon;
|
||||||
const statusIcon = status
|
const statusIcon = status
|
||||||
|
|||||||
@@ -110,7 +110,7 @@ export async function refreshEmbedGithubUrlData(
|
|||||||
|
|
||||||
if (signal?.aborted) return;
|
if (signal?.aborted) return;
|
||||||
|
|
||||||
embedGithubElement.doc.updateBlock(embedGithubElement.model, {
|
embedGithubElement.store.updateBlock(embedGithubElement.model, {
|
||||||
image,
|
image,
|
||||||
status,
|
status,
|
||||||
statusReason,
|
statusReason,
|
||||||
@@ -144,7 +144,7 @@ export async function refreshEmbedGithubStatus(
|
|||||||
|
|
||||||
if (!githubApiData.status || signal?.aborted) return;
|
if (!githubApiData.status || signal?.aborted) return;
|
||||||
|
|
||||||
embedGithubElement.doc.updateBlock(embedGithubElement.model, {
|
embedGithubElement.store.updateBlock(embedGithubElement.model, {
|
||||||
status: githubApiData.status,
|
status: githubApiData.status,
|
||||||
statusReason: githubApiData.statusReason,
|
statusReason: githubApiData.statusReason,
|
||||||
createdAt: githubApiData.createdAt,
|
createdAt: githubApiData.createdAt,
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ export const insertEmbedIframeWithUrlCommand: Command<
|
|||||||
if (selectedBlockId) {
|
if (selectedBlockId) {
|
||||||
const block = host.view.getBlock(selectedBlockId);
|
const block = host.view.getBlock(selectedBlockId);
|
||||||
if (!block) return;
|
if (!block) return;
|
||||||
const parent = host.doc.getParent(block.model);
|
const parent = host.store.getParent(block.model);
|
||||||
if (!parent) return;
|
if (!parent) return;
|
||||||
const index = parent.children.indexOf(block.model);
|
const index = parent.children.indexOf(block.model);
|
||||||
newBlockId = host.doc.addBlock(flavour, props, parent, index + 1);
|
newBlockId = host.store.addBlock(flavour, props, parent, index + 1);
|
||||||
} else {
|
} else {
|
||||||
// When there is no selected block and in edgeless mode
|
// When there is no selected block and in edgeless mode
|
||||||
// We should insert the embed iframe block to surface
|
// We should insert the embed iframe block to surface
|
||||||
|
|||||||
@@ -177,7 +177,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
|
|||||||
|
|
||||||
// update model
|
// update model
|
||||||
const iframeUrl = this._getIframeUrl(embedData) ?? currentIframeUrl;
|
const iframeUrl = this._getIframeUrl(embedData) ?? currentIframeUrl;
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
iframeUrl,
|
iframeUrl,
|
||||||
title: embedData?.title || previewData?.title,
|
title: embedData?.title || previewData?.title,
|
||||||
description: embedData?.description || previewData?.description,
|
description: embedData?.description || previewData?.description,
|
||||||
@@ -373,7 +373,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
|
|||||||
|
|
||||||
// if the iframe url is not set, refresh the data to get the iframe url
|
// if the iframe url is not set, refresh the data to get the iframe url
|
||||||
if (!this.model.props.iframeUrl) {
|
if (!this.model.props.iframeUrl) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.refreshData().catch(console.error);
|
this.refreshData().catch(console.error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
@@ -452,7 +452,7 @@ export class EmbedIframeBlockComponent extends CaptionedBlockComponent<EmbedIfra
|
|||||||
};
|
};
|
||||||
|
|
||||||
get readonly() {
|
get readonly() {
|
||||||
return this.doc.readonly;
|
return this.store.readonly;
|
||||||
}
|
}
|
||||||
|
|
||||||
get selectionManager() {
|
get selectionManager() {
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const embedLoomSlashMenuConfig: SlashMenuConfig = {
|
|||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { host } = std;
|
const { host } = std;
|
||||||
const parentModel = host.doc.getParent(model);
|
const parentModel = host.store.getParent(model);
|
||||||
if (!parentModel) {
|
if (!parentModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,12 +60,12 @@ export class EmbedLoomBlockComponent extends EmbedBlockComponent<
|
|||||||
this._cardStyle = this.model.props.style;
|
this._cardStyle = this.model.props.style;
|
||||||
|
|
||||||
if (!this.model.props.videoId) {
|
if (!this.model.props.videoId) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
const url = this.model.props.url;
|
const url = this.model.props.url;
|
||||||
const urlMatch = url.match(loomUrlRegex);
|
const urlMatch = url.match(loomUrlRegex);
|
||||||
if (urlMatch) {
|
if (urlMatch) {
|
||||||
const [, videoId] = urlMatch;
|
const [, videoId] = urlMatch;
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
videoId,
|
videoId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -73,7 +73,7 @@ export class EmbedLoomBlockComponent extends EmbedBlockComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.model.props.description && !this.model.props.title) {
|
if (!this.model.props.description && !this.model.props.title) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.refreshData();
|
this.refreshData();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -93,7 +93,7 @@ export class EmbedLoomBlockComponent extends EmbedBlockComponent<
|
|||||||
|
|
||||||
const loading = this.loading;
|
const loading = this.loading;
|
||||||
const theme = this.std.get(ThemeProvider).theme;
|
const theme = this.std.get(ThemeProvider).theme;
|
||||||
const imageProxyService = this.doc.get(ImageProxyService);
|
const imageProxyService = this.store.get(ImageProxyService);
|
||||||
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
||||||
const titleIcon = loading ? LoadingIcon : LoomIcon;
|
const titleIcon = loading ? LoadingIcon : LoomIcon;
|
||||||
const titleText = loading ? 'Loading...' : title;
|
const titleText = loading ? 'Loading...' : title;
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export async function refreshEmbedLoomUrlData(
|
|||||||
|
|
||||||
if (signal?.aborted) return;
|
if (signal?.aborted) return;
|
||||||
|
|
||||||
embedLoomElement.doc.updateBlock(embedLoomElement.model, {
|
embedLoomElement.store.updateBlock(embedLoomElement.model, {
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
image,
|
image,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export const embedYoutubeSlashMenuConfig: SlashMenuConfig = {
|
|||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const { host } = std;
|
const { host } = std;
|
||||||
const parentModel = host.doc.getParent(model);
|
const parentModel = host.store.getParent(model);
|
||||||
if (!parentModel) {
|
if (!parentModel) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockComponent<
|
|||||||
this._cardStyle = this.model.props.style;
|
this._cardStyle = this.model.props.style;
|
||||||
|
|
||||||
if (!this.model.props.videoId) {
|
if (!this.model.props.videoId) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
const url = this.model.props.url;
|
const url = this.model.props.url;
|
||||||
const urlMatch = url.match(youtubeUrlRegex);
|
const urlMatch = url.match(youtubeUrlRegex);
|
||||||
if (urlMatch) {
|
if (urlMatch) {
|
||||||
const [, videoId] = urlMatch;
|
const [, videoId] = urlMatch;
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
videoId,
|
videoId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -76,7 +76,7 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!this.model.props.description && !this.model.props.title) {
|
if (!this.model.props.description && !this.model.props.title) {
|
||||||
this.doc.withoutTransact(() => {
|
this.store.withoutTransact(() => {
|
||||||
this.refreshData();
|
this.refreshData();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ export class EmbedYoutubeBlockComponent extends EmbedBlockComponent<
|
|||||||
|
|
||||||
const loading = this.loading;
|
const loading = this.loading;
|
||||||
const theme = this.std.get(ThemeProvider).theme;
|
const theme = this.std.get(ThemeProvider).theme;
|
||||||
const imageProxyService = this.doc.get(ImageProxyService);
|
const imageProxyService = this.store.get(ImageProxyService);
|
||||||
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
const { LoadingIcon, EmbedCardBannerIcon } = getEmbedCardIcons(theme);
|
||||||
const titleIcon = loading ? LoadingIcon : YoutubeIcon;
|
const titleIcon = loading ? LoadingIcon : YoutubeIcon;
|
||||||
const titleText = loading ? 'Loading...' : title;
|
const titleText = loading ? 'Loading...' : title;
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ export async function refreshEmbedYoutubeUrlData(
|
|||||||
|
|
||||||
if (signal?.aborted) return;
|
if (signal?.aborted) return;
|
||||||
|
|
||||||
embedYoutubeElement.doc.updateBlock(embedYoutubeElement.model, {
|
embedYoutubeElement.store.updateBlock(embedYoutubeElement.model, {
|
||||||
image,
|
image,
|
||||||
title,
|
title,
|
||||||
description,
|
description,
|
||||||
|
|||||||
@@ -176,7 +176,7 @@ export class PresentationToolbar extends EdgelessToolbarToolMixin(
|
|||||||
private _exitPresentation() {
|
private _exitPresentation() {
|
||||||
// When exit presentation mode, we need to set the tool to default or pan
|
// When exit presentation mode, we need to set the tool to default or pan
|
||||||
// And exit fullscreen
|
// And exit fullscreen
|
||||||
if (this.edgeless.doc.readonly) {
|
if (this.edgeless.store.readonly) {
|
||||||
this.setEdgelessTool(PanTool, { panning: false });
|
this.setEdgelessTool(PanTool, { panning: false });
|
||||||
} else {
|
} else {
|
||||||
this.setEdgelessTool(DefaultTool);
|
this.setEdgelessTool(DefaultTool);
|
||||||
@@ -316,7 +316,7 @@ export class PresentationToolbar extends EdgelessToolbarToolMixin(
|
|||||||
this.edgelessTool.toolType === PresentTool &&
|
this.edgelessTool.toolType === PresentTool &&
|
||||||
this._fullScreenMode
|
this._fullScreenMode
|
||||||
) {
|
) {
|
||||||
if (this.edgeless.doc.readonly) {
|
if (this.edgeless.store.readonly) {
|
||||||
this.setEdgelessTool(PanTool, { panning: false });
|
this.setEdgelessTool(PanTool, { panning: false });
|
||||||
} else {
|
} else {
|
||||||
this.setEdgelessTool(DefaultTool);
|
this.setEdgelessTool(DefaultTool);
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const frameQuickTool = QuickToolExtension('frame', ({ block, gfx }) => {
|
|||||||
.edgeless=${block}
|
.edgeless=${block}
|
||||||
></edgeless-frame-tool-button>`,
|
></edgeless-frame-tool-button>`,
|
||||||
menu: buildFrameDenseMenu(block, gfx),
|
menu: buildFrameDenseMenu(block, gfx),
|
||||||
enable: !block.doc.readonly,
|
enable: !block.store.readonly,
|
||||||
priority: 90,
|
priority: 90,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
|
|||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
this.doc.slots.blockUpdated.subscribe(({ type, id }) => {
|
this.store.slots.blockUpdated.subscribe(({ type, id }) => {
|
||||||
if (id === this.model.id && type === 'update') {
|
if (id === this.model.id && type === 'update') {
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ export class EdgelessFrameOrderButton extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override render() {
|
protected override render() {
|
||||||
const { readonly } = this.edgeless.doc;
|
const { readonly } = this.edgeless.store;
|
||||||
return html`
|
return html`
|
||||||
<style>
|
<style>
|
||||||
.edgeless-frame-order-button svg {
|
.edgeless-frame-order-button svg {
|
||||||
|
|||||||
@@ -193,7 +193,7 @@ export class EdgelessFrameOrderMenu extends SignalWatcher(
|
|||||||
this.crud.updateElement(frame.id, {
|
this.crud.updateElement(frame.id, {
|
||||||
presentationIndex: generateKeyBetweenV2(before, after),
|
presentationIndex: generateKeyBetweenV2(before, after),
|
||||||
});
|
});
|
||||||
this.edgeless.doc.captureSync();
|
this.edgeless.store.captureSync();
|
||||||
|
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,7 @@ export class ImageBlockPageComponent extends WithDisposable(ShadowlessElement) {
|
|||||||
private _isDragging = false;
|
private _isDragging = false;
|
||||||
|
|
||||||
private get _doc() {
|
private get _doc() {
|
||||||
return this.block.doc;
|
return this.block.store;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _host() {
|
private get _host() {
|
||||||
@@ -128,21 +128,21 @@ export class ImageBlockPageComponent extends WithDisposable(ShadowlessElement) {
|
|||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Delete: ctx => {
|
Delete: ctx => {
|
||||||
if (this._host.doc.readonly || !this._isSelected) return;
|
if (this._host.store.readonly || !this._isSelected) return;
|
||||||
|
|
||||||
addParagraph(ctx);
|
addParagraph(ctx);
|
||||||
this._doc.deleteBlock(this._model);
|
this._doc.deleteBlock(this._model);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Backspace: ctx => {
|
Backspace: ctx => {
|
||||||
if (this._host.doc.readonly || !this._isSelected) return;
|
if (this._host.store.readonly || !this._isSelected) return;
|
||||||
|
|
||||||
addParagraph(ctx);
|
addParagraph(ctx);
|
||||||
this._doc.deleteBlock(this._model);
|
this._doc.deleteBlock(this._model);
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
Enter: ctx => {
|
Enter: ctx => {
|
||||||
if (this._host.doc.readonly || !this._isSelected) return;
|
if (this._host.store.readonly || !this._isSelected) return;
|
||||||
|
|
||||||
addParagraph(ctx);
|
addParagraph(ctx);
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@@ -108,7 +108,7 @@ export async function resetImageSize(
|
|||||||
const xywh = bound.serialize();
|
const xywh = bound.serialize();
|
||||||
const props: Partial<ImageBlockProps> = { ...imageSize, xywh };
|
const props: Partial<ImageBlockProps> = { ...imageSize, xywh };
|
||||||
|
|
||||||
block.doc.updateBlock(model, props);
|
block.store.updateBlock(model, props);
|
||||||
}
|
}
|
||||||
|
|
||||||
function convertToPng(blob: Blob): Promise<Blob | null> {
|
function convertToPng(blob: Blob): Promise<Blob | null> {
|
||||||
@@ -193,7 +193,7 @@ export async function copyImageBlob(
|
|||||||
export async function turnImageIntoCardView(
|
export async function turnImageIntoCardView(
|
||||||
block: ImageBlockComponent | ImageEdgelessBlockComponent
|
block: ImageBlockComponent | ImageEdgelessBlockComponent
|
||||||
) {
|
) {
|
||||||
const doc = block.doc;
|
const doc = block.store;
|
||||||
if (!doc.schema.flavourSchemaMap.has('affine:attachment')) {
|
if (!doc.schema.flavourSchemaMap.has('affine:attachment')) {
|
||||||
console.error('The attachment flavour is not supported!');
|
console.error('The attachment flavour is not supported!');
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ export class LatexBlockComponent extends CaptionedBlockComponent<LatexBlockModel
|
|||||||
|
|
||||||
this.disposables.addFromEvent(this, 'click', () => {
|
this.disposables.addFromEvent(this, 'click', () => {
|
||||||
// should not open editor or select block in readonly mode
|
// should not open editor or select block in readonly mode
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -13,12 +13,12 @@ export const convertToNumberedListCommand: Command<
|
|||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std, id, order, stopCapturing = true } = ctx;
|
const { std, id, order, stopCapturing = true } = ctx;
|
||||||
const host = std.host as EditorHost;
|
const host = std.host as EditorHost;
|
||||||
const doc = host.doc;
|
const doc = host.store;
|
||||||
|
|
||||||
const model = doc.getBlock(id)?.model;
|
const model = doc.getBlock(id)?.model;
|
||||||
if (!model || !model.text) return;
|
if (!model || !model.text) return;
|
||||||
|
|
||||||
if (stopCapturing) host.doc.captureSync();
|
if (stopCapturing) host.store.captureSync();
|
||||||
|
|
||||||
const listConvertedId = toNumberedList(std, model, order);
|
const listConvertedId = toNumberedList(std, model, order);
|
||||||
|
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ export const splitListCommand: Command<{
|
|||||||
}> = (ctx, next) => {
|
}> = (ctx, next) => {
|
||||||
const { blockId, inlineIndex, std } = ctx;
|
const { blockId, inlineIndex, std } = ctx;
|
||||||
const host = std.host as EditorHost;
|
const host = std.host as EditorHost;
|
||||||
const doc = host.doc;
|
const doc = host.store;
|
||||||
|
|
||||||
const model = doc.getBlock(blockId)?.model;
|
const model = doc.getBlock(blockId)?.model;
|
||||||
if (!model || !matchModels(model, [ListBlockModel])) {
|
if (!model || !matchModels(model, [ListBlockModel])) {
|
||||||
|
|||||||
@@ -39,22 +39,22 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
|
|||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
if (this.model.props.type === 'toggle') {
|
if (this.model.props.type === 'toggle') {
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
this._readonlyCollapsed = !this._readonlyCollapsed;
|
this._readonlyCollapsed = !this._readonlyCollapsed;
|
||||||
} else {
|
} else {
|
||||||
this.doc.captureSync();
|
this.store.captureSync();
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
collapsed: !this.model.props.collapsed,
|
collapsed: !this.model.props.collapsed,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else if (this.model.props.type === 'todo') {
|
} else if (this.model.props.type === 'todo') {
|
||||||
if (this.doc.readonly) return;
|
if (this.store.readonly) return;
|
||||||
|
|
||||||
this.doc.captureSync();
|
this.store.captureSync();
|
||||||
const checkedPropObj = { checked: !this.model.props.checked };
|
const checkedPropObj = { checked: !this.model.props.checked };
|
||||||
this.doc.updateBlock(this.model, checkedPropObj);
|
this.store.updateBlock(this.model, checkedPropObj);
|
||||||
if (this.model.props.checked) {
|
if (this.model.props.checked) {
|
||||||
const checkEl = this.querySelector('.affine-list-block__todo-prefix');
|
const checkEl = this.querySelector('.affine-list-block__todo-prefix');
|
||||||
if (checkEl) {
|
if (checkEl) {
|
||||||
@@ -120,7 +120,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
|
|||||||
const order = this.model.props.order$.value;
|
const order = this.model.props.order$.value;
|
||||||
// old numbered list has no order
|
// old numbered list has no order
|
||||||
if (type === 'numbered' && !Number.isInteger(order)) {
|
if (type === 'numbered' && !Number.isInteger(order)) {
|
||||||
correctNumberedListsOrderToPrev(this.doc, this.model, false);
|
correctNumberedListsOrderToPrev(this.store, this.model, false);
|
||||||
}
|
}
|
||||||
// if list is not numbered, order should be null
|
// if list is not numbered, order should be null
|
||||||
if (type !== 'numbered' && order !== null) {
|
if (type !== 'numbered' && order !== null) {
|
||||||
@@ -138,7 +138,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
|
|||||||
|
|
||||||
override renderBlock(): TemplateResult<1> {
|
override renderBlock(): TemplateResult<1> {
|
||||||
const { model, _onClickIcon } = this;
|
const { model, _onClickIcon } = this;
|
||||||
const collapsed = this.doc.readonly
|
const collapsed = this.store.readonly
|
||||||
? this._readonlyCollapsed
|
? this._readonlyCollapsed
|
||||||
: model.props.collapsed;
|
: model.props.collapsed;
|
||||||
|
|
||||||
@@ -169,11 +169,11 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
|
|||||||
<blocksuite-toggle-button
|
<blocksuite-toggle-button
|
||||||
.collapsed=${collapsed}
|
.collapsed=${collapsed}
|
||||||
.updateCollapsed=${(value: boolean) => {
|
.updateCollapsed=${(value: boolean) => {
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
this._readonlyCollapsed = value;
|
this._readonlyCollapsed = value;
|
||||||
} else {
|
} else {
|
||||||
this.doc.captureSync();
|
this.store.captureSync();
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
collapsed: value,
|
collapsed: value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -185,12 +185,12 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
|
|||||||
<rich-text
|
<rich-text
|
||||||
.yText=${this.model.props.text.yText}
|
.yText=${this.model.props.text.yText}
|
||||||
.inlineEventSource=${this.topContenteditableElement ?? nothing}
|
.inlineEventSource=${this.topContenteditableElement ?? nothing}
|
||||||
.undoManager=${this.doc.history}
|
.undoManager=${this.store.history}
|
||||||
.attributeRenderer=${this.attributeRenderer}
|
.attributeRenderer=${this.attributeRenderer}
|
||||||
.attributesSchema=${this.attributesSchema}
|
.attributesSchema=${this.attributesSchema}
|
||||||
.markdownMatches=${this.inlineManager?.markdownMatches}
|
.markdownMatches=${this.inlineManager?.markdownMatches}
|
||||||
.embedChecker=${this.embedChecker}
|
.embedChecker=${this.embedChecker}
|
||||||
.readonly=${this.doc.readonly}
|
.readonly=${this.store.readonly}
|
||||||
.inlineRangeProvider=${this._inlineRangeProvider}
|
.inlineRangeProvider=${this._inlineRangeProvider}
|
||||||
.enableClipboard=${false}
|
.enableClipboard=${false}
|
||||||
.enableUndoRedo=${false}
|
.enableUndoRedo=${false}
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ export const updateBlockType: Command<
|
|||||||
|
|
||||||
const blockModels = selectedBlocks.map(ele => ele.model);
|
const blockModels = selectedBlocks.map(ele => ele.model);
|
||||||
|
|
||||||
const hasSameDoc = selectedBlocks.every(block => block.doc === doc);
|
const hasSameDoc = selectedBlocks.every(block => block.store === doc);
|
||||||
if (!hasSameDoc) {
|
if (!hasSameDoc) {
|
||||||
// doc check
|
// doc check
|
||||||
console.error(
|
console.error(
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ export class EdgelessNoteBackground extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
get doc() {
|
get doc() {
|
||||||
return this.std.host.doc;
|
return this.std.host.store;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _tryAddParagraph(x: number, y: number) {
|
private _tryAddParagraph(x: number, y: number) {
|
||||||
@@ -137,7 +137,7 @@ export class EdgelessNoteBackground extends SignalWatcher(
|
|||||||
const y = clamp(e.y, rect.top + offsetY, rect.bottom - offsetY);
|
const y = clamp(e.y, rect.top + offsetY, rect.bottom - offsetY);
|
||||||
handleNativeRangeAtPoint(x, y);
|
handleNativeRangeAtPoint(x, y);
|
||||||
|
|
||||||
if (this.std.host.doc.readonly) return;
|
if (this.std.host.store.readonly) return;
|
||||||
|
|
||||||
this._tryAddParagraph(x, y);
|
this._tryAddParagraph(x, y);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -298,7 +298,7 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
|
|||||||
.note=${this.model}
|
.note=${this.model}
|
||||||
></edgeless-page-block-title>
|
></edgeless-page-block-title>
|
||||||
<div
|
<div
|
||||||
contenteditable=${String(!this.doc.readonly$.value)}
|
contenteditable=${String(!this.store.readonly$.value)}
|
||||||
class="edgeless-note-page-content"
|
class="edgeless-note-page-content"
|
||||||
>
|
>
|
||||||
${this.renderPageContent()}
|
${this.renderPageContent()}
|
||||||
@@ -362,7 +362,7 @@ export class EdgelessNoteBlockComponent extends toGfxBlockComponent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (this.model.children.length === 0) {
|
if (this.model.children.length === 0) {
|
||||||
const blockId = this.doc.addBlock(
|
const blockId = this.store.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{ type: 'text' },
|
{ type: 'text' },
|
||||||
this.model.id
|
this.model.id
|
||||||
|
|||||||
@@ -125,7 +125,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
|
|||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
effect(() => {
|
effect(() => {
|
||||||
const composing = this._composing.value;
|
const composing = this._composing.value;
|
||||||
if (composing || this.doc.readonly) {
|
if (composing || this.store.readonly) {
|
||||||
this._displayPlaceholder.value = false;
|
this._displayPlaceholder.value = false;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -197,7 +197,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
|
|||||||
nearestHeading &&
|
nearestHeading &&
|
||||||
nearestHeading.props.type.startsWith('h') &&
|
nearestHeading.props.type.startsWith('h') &&
|
||||||
nearestHeading.props.collapsed &&
|
nearestHeading.props.collapsed &&
|
||||||
!this.doc.readonly
|
!this.store.readonly
|
||||||
) {
|
) {
|
||||||
nearestHeading.props.collapsed = false;
|
nearestHeading.props.collapsed = false;
|
||||||
}
|
}
|
||||||
@@ -215,7 +215,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
|
|||||||
|
|
||||||
override renderBlock(): TemplateResult<1> {
|
override renderBlock(): TemplateResult<1> {
|
||||||
const { type$ } = this.model.props;
|
const { type$ } = this.model.props;
|
||||||
const collapsed = this.doc.readonly
|
const collapsed = this.store.readonly
|
||||||
? this._readonlyCollapsed
|
? this._readonlyCollapsed
|
||||||
: this.model.props.collapsed;
|
: this.model.props.collapsed;
|
||||||
const collapsedSiblings = this.collapsedSiblings;
|
const collapsedSiblings = this.collapsedSiblings;
|
||||||
@@ -278,11 +278,11 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
|
|||||||
<blocksuite-toggle-button
|
<blocksuite-toggle-button
|
||||||
.collapsed=${collapsed}
|
.collapsed=${collapsed}
|
||||||
.updateCollapsed=${(value: boolean) => {
|
.updateCollapsed=${(value: boolean) => {
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
this._readonlyCollapsed = value;
|
this._readonlyCollapsed = value;
|
||||||
} else {
|
} else {
|
||||||
this.doc.captureSync();
|
this.store.captureSync();
|
||||||
this.doc.updateBlock(this.model, {
|
this.store.updateBlock(this.model, {
|
||||||
collapsed: value,
|
collapsed: value,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -293,12 +293,12 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
|
|||||||
<rich-text
|
<rich-text
|
||||||
.yText=${this.model.props.text.yText}
|
.yText=${this.model.props.text.yText}
|
||||||
.inlineEventSource=${this.topContenteditableElement ?? nothing}
|
.inlineEventSource=${this.topContenteditableElement ?? nothing}
|
||||||
.undoManager=${this.doc.history}
|
.undoManager=${this.store.history}
|
||||||
.attributesSchema=${this.attributesSchema}
|
.attributesSchema=${this.attributesSchema}
|
||||||
.attributeRenderer=${this.attributeRenderer}
|
.attributeRenderer=${this.attributeRenderer}
|
||||||
.markdownMatches=${this.inlineManager?.markdownMatches}
|
.markdownMatches=${this.inlineManager?.markdownMatches}
|
||||||
.embedChecker=${this.embedChecker}
|
.embedChecker=${this.embedChecker}
|
||||||
.readonly=${this.doc.readonly}
|
.readonly=${this.store.readonly}
|
||||||
.inlineRangeProvider=${this._inlineRangeProvider}
|
.inlineRangeProvider=${this._inlineRangeProvider}
|
||||||
.enableClipboard=${false}
|
.enableClipboard=${false}
|
||||||
.enableUndoRedo=${false}
|
.enableUndoRedo=${false}
|
||||||
|
|||||||
@@ -174,7 +174,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
presentationIndex: frameMgr.generatePresentationIndex(),
|
presentationIndex: frameMgr.generatePresentationIndex(),
|
||||||
});
|
});
|
||||||
const id = this.crud.addBlock('affine:frame', props, surfaceBlockModel);
|
const id = this.crud.addBlock('affine:frame', props, surfaceBlockModel);
|
||||||
edgeless.doc.captureSync();
|
edgeless.store.captureSync();
|
||||||
const frame = this.crud.getElementById(id);
|
const frame = this.crud.getElementById(id);
|
||||||
if (!frame) return;
|
if (!frame) return;
|
||||||
|
|
||||||
@@ -190,7 +190,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _addNote() {
|
private _addNote() {
|
||||||
const { doc } = this.edgeless;
|
const { store } = this.edgeless;
|
||||||
const target = this._getTargetXYWH(
|
const target = this._getTargetXYWH(
|
||||||
DEFAULT_NOTE_WIDTH,
|
DEFAULT_NOTE_WIDTH,
|
||||||
DEFAULT_NOTE_OVERLAY_HEIGHT
|
DEFAULT_NOTE_OVERLAY_HEIGHT
|
||||||
@@ -203,13 +203,13 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
{
|
{
|
||||||
xywh: serializeXYWH(...xywh),
|
xywh: serializeXYWH(...xywh),
|
||||||
},
|
},
|
||||||
doc.root?.id
|
store.root?.id
|
||||||
);
|
);
|
||||||
const note = doc.getBlock(id)?.model;
|
const note = store.getBlock(id)?.model;
|
||||||
if (!matchModels(note, [NoteBlockModel])) {
|
if (!matchModels(note, [NoteBlockModel])) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
doc.addBlock('affine:paragraph', { type: 'text' }, id);
|
store.addBlock('affine:paragraph', { type: 'text' }, id);
|
||||||
const group = this.currentSource.group;
|
const group = this.currentSource.group;
|
||||||
|
|
||||||
if (group instanceof GroupElementModel) {
|
if (group instanceof GroupElementModel) {
|
||||||
@@ -251,7 +251,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
elements: [id],
|
elements: [id],
|
||||||
editing: true,
|
editing: true,
|
||||||
});
|
});
|
||||||
edgeless.doc.captureSync();
|
edgeless.store.captureSync();
|
||||||
}
|
}
|
||||||
|
|
||||||
private _addText() {
|
private _addText() {
|
||||||
@@ -260,7 +260,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
const { xywh, position } = target;
|
const { xywh, position } = target;
|
||||||
const bound = Bound.fromXYWH(xywh);
|
const bound = Bound.fromXYWH(xywh);
|
||||||
|
|
||||||
const textFlag = this.edgeless.doc
|
const textFlag = this.edgeless.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_edgeless_text');
|
.getFlag('enable_edgeless_text');
|
||||||
if (textFlag) {
|
if (textFlag) {
|
||||||
@@ -287,7 +287,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
elements: [textId],
|
elements: [textId],
|
||||||
editing: false,
|
editing: false,
|
||||||
});
|
});
|
||||||
this.edgeless.doc.captureSync();
|
this.edgeless.store.captureSync();
|
||||||
} else {
|
} else {
|
||||||
const textId = this.crud.addElement(CanvasElementType.TEXT, {
|
const textId = this.crud.addElement(CanvasElementType.TEXT, {
|
||||||
xywh: bound.serialize(),
|
xywh: bound.serialize(),
|
||||||
@@ -316,7 +316,7 @@ export class EdgelessAutoCompletePanel extends WithDisposable(LitElement) {
|
|||||||
elements: [textId],
|
elements: [textId],
|
||||||
editing: false,
|
editing: false,
|
||||||
});
|
});
|
||||||
this.edgeless.doc.captureSync();
|
this.edgeless.store.captureSync();
|
||||||
|
|
||||||
mountTextElementEditor(textElement, this.edgeless);
|
mountTextElementEditor(textElement, this.edgeless);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -371,7 +371,7 @@ export class EdgelessAutoComplete extends WithDisposable(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _generateElementOnClick(type: Direction) {
|
private _generateElementOnClick(type: Direction) {
|
||||||
const { doc } = this.edgeless;
|
const { store } = this.edgeless;
|
||||||
const bound = this._computeNextBound(type);
|
const bound = this._computeNextBound(type);
|
||||||
const id = createEdgelessElement(this.edgeless, this.current, bound);
|
const id = createEdgelessElement(this.edgeless, this.current, bound);
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
@@ -393,7 +393,7 @@ export class EdgelessAutoComplete extends WithDisposable(LitElement) {
|
|||||||
this.edgeless
|
this.edgeless
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
const model = doc.getModelById(id);
|
const model = store.getModelById(id);
|
||||||
if (!model) {
|
if (!model) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -288,8 +288,8 @@ export function createEdgelessElement(
|
|||||||
if (!id) return null;
|
if (!id) return null;
|
||||||
element = crud.getElementById(id);
|
element = crud.getElementById(id);
|
||||||
} else {
|
} else {
|
||||||
const { doc } = edgeless;
|
const { store } = edgeless;
|
||||||
id = doc.addBlock(
|
id = store.addBlock(
|
||||||
'affine:note',
|
'affine:note',
|
||||||
{
|
{
|
||||||
background: current.props.background,
|
background: current.props.background,
|
||||||
@@ -299,7 +299,7 @@ export function createEdgelessElement(
|
|||||||
},
|
},
|
||||||
edgeless.model.id
|
edgeless.model.id
|
||||||
);
|
);
|
||||||
const note = doc.getBlock(id)?.model;
|
const note = store.getBlock(id)?.model;
|
||||||
if (!note) {
|
if (!note) {
|
||||||
throw new BlockSuiteError(
|
throw new BlockSuiteError(
|
||||||
ErrorCode.GfxBlockElementError,
|
ErrorCode.GfxBlockElementError,
|
||||||
@@ -307,10 +307,10 @@ export function createEdgelessElement(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
assertType<NoteBlockModel>(note);
|
assertType<NoteBlockModel>(note);
|
||||||
doc.updateBlock(note, () => {
|
store.updateBlock(note, () => {
|
||||||
note.props.edgeless.collapse = true;
|
note.props.edgeless.collapse = true;
|
||||||
});
|
});
|
||||||
doc.addBlock('affine:paragraph', {}, note.id);
|
store.addBlock('affine:paragraph', {}, note.id);
|
||||||
|
|
||||||
element = note;
|
element = note;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,7 +152,7 @@ export class NoteSlicer extends WidgetComponent<RootBlockModel> {
|
|||||||
|
|
||||||
private _sliceNote() {
|
private _sliceNote() {
|
||||||
if (!this._anchorNote || !this._noteBlockIds.length) return;
|
if (!this._anchorNote || !this._noteBlockIds.length) return;
|
||||||
const doc = this.doc;
|
const doc = this.store;
|
||||||
|
|
||||||
const {
|
const {
|
||||||
index: originalIndex,
|
index: originalIndex,
|
||||||
@@ -177,7 +177,7 @@ export class NoteSlicer extends WidgetComponent<RootBlockModel> {
|
|||||||
const sliceVerticalPos =
|
const sliceVerticalPos =
|
||||||
this._divingLinePositions[this._activeSlicerIndex].y;
|
this._divingLinePositions[this._activeSlicerIndex].y;
|
||||||
const newY = this.gfx.viewport.toModelCoord(x, sliceVerticalPos)[1];
|
const newY = this.gfx.viewport.toModelCoord(x, sliceVerticalPos)[1];
|
||||||
const newNoteId = this.doc.addBlock(
|
const newNoteId = this.store.addBlock(
|
||||||
'affine:note',
|
'affine:note',
|
||||||
{
|
{
|
||||||
background,
|
background,
|
||||||
@@ -364,7 +364,7 @@ export class NoteSlicer extends WidgetComponent<RootBlockModel> {
|
|||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
if (
|
if (
|
||||||
this.doc.readonly ||
|
this.store.readonly ||
|
||||||
this._hidden ||
|
this._hidden ||
|
||||||
this._isResizing ||
|
this._isResizing ||
|
||||||
!this._anchorNote ||
|
!this._anchorNote ||
|
||||||
|
|||||||
@@ -477,7 +477,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
private readonly _onDragEnd = () => {
|
private readonly _onDragEnd = () => {
|
||||||
this.slots.dragEnd.next();
|
this.slots.dragEnd.next();
|
||||||
|
|
||||||
this.doc.transact(() => {
|
this.store.transact(() => {
|
||||||
this._dragEndCallback.forEach(cb => cb());
|
this._dragEndCallback.forEach(cb => cb());
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -1210,7 +1210,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
this._isHeightLimit = bound.h === NOTE_MIN_HEIGHT * scale;
|
this._isHeightLimit = bound.h === NOTE_MIN_HEIGHT * scale;
|
||||||
|
|
||||||
if (bound.h > NOTE_MIN_HEIGHT * scale) {
|
if (bound.h > NOTE_MIN_HEIGHT * scale) {
|
||||||
this.doc.updateBlock(element, () => {
|
this.store.updateBlock(element, () => {
|
||||||
element.props.edgeless.collapse = true;
|
element.props.edgeless.collapse = true;
|
||||||
element.props.edgeless.collapsedHeight = bound.h / scale;
|
element.props.edgeless.collapsedHeight = bound.h / scale;
|
||||||
});
|
});
|
||||||
@@ -1393,7 +1393,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
this.doc.slots.blockUpdated.subscribe(this._updateOnElementChange)
|
this.store.slots.blockUpdated.subscribe(this._updateOnElementChange)
|
||||||
);
|
);
|
||||||
|
|
||||||
_disposables.add(
|
_disposables.add(
|
||||||
@@ -1464,14 +1464,14 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
const {
|
const {
|
||||||
block,
|
block,
|
||||||
gfx,
|
gfx,
|
||||||
doc,
|
store,
|
||||||
resizeMode,
|
resizeMode,
|
||||||
_resizeManager,
|
_resizeManager,
|
||||||
_selectedRect,
|
_selectedRect,
|
||||||
_updateCursor,
|
_updateCursor,
|
||||||
} = this;
|
} = this;
|
||||||
|
|
||||||
const hasResizeHandles = !selection.editing && !doc.readonly;
|
const hasResizeHandles = !selection.editing && !store.readonly;
|
||||||
const inoperable = selection.inoperable;
|
const inoperable = selection.inoperable;
|
||||||
const hasElementLocked = elements.some(element => element.isLocked());
|
const hasElementLocked = elements.some(element => element.isLocked());
|
||||||
const handlers = [];
|
const handlers = [];
|
||||||
@@ -1578,7 +1578,7 @@ export class EdgelessSelectedRectWidget extends WidgetComponent<
|
|||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
${!doc.readonly && !inoperable && this._canAutoComplete()
|
${!store.readonly && !inoperable && this._canAutoComplete()
|
||||||
? html`<edgeless-auto-complete
|
? html`<edgeless-auto-complete
|
||||||
.current=${this.selection.selectedElements[0]}
|
.current=${this.selection.selectedElements[0]}
|
||||||
.edgeless=${block}
|
.edgeless=${block}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ export function createLinkedDocFromEdgelessElements(
|
|||||||
elements: GfxModel[],
|
elements: GfxModel[],
|
||||||
docTitle?: string
|
docTitle?: string
|
||||||
) {
|
) {
|
||||||
const _doc = host.doc.workspace.createDoc();
|
const _doc = host.store.workspace.createDoc();
|
||||||
const transformer = host.doc.getTransformer();
|
const transformer = host.store.getTransformer();
|
||||||
const linkedDoc = _doc.getStore();
|
const linkedDoc = _doc.getStore();
|
||||||
linkedDoc.load(() => {
|
linkedDoc.load(() => {
|
||||||
const rootId = linkedDoc.addBlock('affine:page', {
|
const rootId = linkedDoc.addBlock('affine:page', {
|
||||||
|
|||||||
@@ -465,7 +465,7 @@ export class EdgelessPageKeyboardManager extends PageKeyboardManager {
|
|||||||
!event.metaKey
|
!event.metaKey
|
||||||
) {
|
) {
|
||||||
const elements = selection.selectedElements;
|
const elements = selection.selectedElements;
|
||||||
const doc = this.rootComponent.doc;
|
const doc = this.rootComponent.store;
|
||||||
|
|
||||||
if (isSingleMindMapNode(elements)) {
|
if (isSingleMindMapNode(elements)) {
|
||||||
const target = gfx.getElementById(
|
const target = gfx.getElementById(
|
||||||
|
|||||||
@@ -407,7 +407,7 @@ export class EdgelessRootBlockComponent extends BlockComponent<
|
|||||||
elements[0].id
|
elements[0].id
|
||||||
) as ShapeElementModel;
|
) as ShapeElementModel;
|
||||||
if (target.text) {
|
if (target.text) {
|
||||||
this.doc.transact(() => {
|
this.store.transact(() => {
|
||||||
target.text!.delete(0, target.text!.length);
|
target.text!.delete(0, target.text!.length);
|
||||||
target.text!.insert(0, key);
|
target.text!.insert(0, key);
|
||||||
});
|
});
|
||||||
@@ -467,7 +467,7 @@ export class EdgelessRootBlockComponent extends BlockComponent<
|
|||||||
this._initPanEvent();
|
this._initPanEvent();
|
||||||
this._initPinchEvent();
|
this._initPinchEvent();
|
||||||
|
|
||||||
if (this.doc.readonly) {
|
if (this.store.readonly) {
|
||||||
this.gfx.tool.setTool(PanTool, { panning: true });
|
this.gfx.tool.setTool(PanTool, { panning: true });
|
||||||
} else {
|
} else {
|
||||||
this.gfx.tool.setTool(DefaultTool);
|
this.gfx.tool.setTool(DefaultTool);
|
||||||
|
|||||||
@@ -25,10 +25,10 @@ export function deleteElements(
|
|||||||
|
|
||||||
set.forEach(element => {
|
set.forEach(element => {
|
||||||
if (isNoteBlock(element)) {
|
if (isNoteBlock(element)) {
|
||||||
const children = edgeless.doc.root?.children ?? [];
|
const children = edgeless.store.root?.children ?? [];
|
||||||
// FIXME: should always keep at least 1 note
|
// FIXME: should always keep at least 1 note
|
||||||
if (children.length > 1) {
|
if (children.length > 1) {
|
||||||
edgeless.doc.deleteBlock(element);
|
edgeless.store.deleteBlock(element);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
service.removeElement(element.id);
|
service.removeElement(element.id);
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ export class PageKeyboardManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get _doc() {
|
private get _doc() {
|
||||||
return this.rootComponent.doc;
|
return this.rootComponent.store;
|
||||||
}
|
}
|
||||||
|
|
||||||
private get _selection() {
|
private get _selection() {
|
||||||
@@ -143,7 +143,7 @@ export class PageKeyboardManager {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const doc = rootComponent.host.doc;
|
const doc = rootComponent.host.store;
|
||||||
const autofill = getTitleFromSelectedModels(
|
const autofill = getTitleFromSelectedModels(
|
||||||
selectedModels.map(toDraftModel)
|
selectedModels.map(toDraftModel)
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
|||||||
focusTextModel(this.std, firstText.id);
|
focusTextModel(this.std, firstText.id);
|
||||||
return { id: firstText.id, created: false };
|
return { id: firstText.id, created: false };
|
||||||
} else {
|
} else {
|
||||||
const newFirstParagraphId = this.doc.addBlock(
|
const newFirstParagraphId = this.store.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{},
|
{},
|
||||||
defaultNote,
|
defaultNote,
|
||||||
@@ -131,7 +131,7 @@ export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
|||||||
keyboardManager: PageKeyboardManager | null = null;
|
keyboardManager: PageKeyboardManager | null = null;
|
||||||
|
|
||||||
prependParagraphWithText = (text: Text) => {
|
prependParagraphWithText = (text: Text) => {
|
||||||
const newFirstParagraphId = this.doc.addBlock(
|
const newFirstParagraphId = this.store.addBlock(
|
||||||
'affine:paragraph',
|
'affine:paragraph',
|
||||||
{ text },
|
{ text },
|
||||||
this._getDefaultNoteBlock(),
|
this._getDefaultNoteBlock(),
|
||||||
@@ -157,16 +157,17 @@ export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _createDefaultNoteBlock() {
|
private _createDefaultNoteBlock() {
|
||||||
const { doc } = this;
|
const { store } = this;
|
||||||
|
|
||||||
const noteId = doc.addBlock('affine:note', {}, doc.root?.id);
|
const noteId = store.addBlock('affine:note', {}, store.root?.id);
|
||||||
return doc.getModelById(noteId) as NoteBlockModel;
|
return store.getModelById(noteId) as NoteBlockModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getDefaultNoteBlock() {
|
private _getDefaultNoteBlock() {
|
||||||
return (
|
return (
|
||||||
this.doc.root?.children.find(child => child.flavour === 'affine:note') ??
|
this.store.root?.children.find(
|
||||||
this._createDefaultNoteBlock()
|
child => child.flavour === 'affine:note'
|
||||||
|
) ?? this._createDefaultNoteBlock()
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -230,16 +231,16 @@ export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
|||||||
);
|
);
|
||||||
if (!sel) return;
|
if (!sel) return;
|
||||||
let model: BlockModel | null = null;
|
let model: BlockModel | null = null;
|
||||||
let current = this.doc.getModelById(sel.blockId);
|
let current = this.store.getModelById(sel.blockId);
|
||||||
while (current && !model) {
|
while (current && !model) {
|
||||||
if (current.flavour === 'affine:note') {
|
if (current.flavour === 'affine:note') {
|
||||||
model = current;
|
model = current;
|
||||||
} else {
|
} else {
|
||||||
current = this.doc.getParent(current);
|
current = this.store.getParent(current);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!model) return;
|
if (!model) return;
|
||||||
const prevNote = this.doc.getPrev(model);
|
const prevNote = this.store.getPrev(model);
|
||||||
if (!prevNote || prevNote.flavour !== 'affine:note') {
|
if (!prevNote || prevNote.flavour !== 'affine:note') {
|
||||||
const isFirstText = sel.is(TextSelection) && sel.start.index === 0;
|
const isFirstText = sel.is(TextSelection) && sel.start.index === 0;
|
||||||
const isBlock = sel.is(BlockSelection);
|
const isBlock = sel.is(BlockSelection);
|
||||||
@@ -248,7 +249,7 @@ export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
|||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const notes = this.doc.getModelsByFlavour('affine:note');
|
const notes = this.store.getModelsByFlavour('affine:note');
|
||||||
const index = notes.indexOf(prevNote);
|
const index = notes.indexOf(prevNote);
|
||||||
if (index !== 0) return;
|
if (index !== 0) return;
|
||||||
|
|
||||||
@@ -409,7 +410,7 @@ export class PageRootBlockComponent extends BlockComponent<RootBlockModel> {
|
|||||||
return !(isNote && displayOnEdgeless);
|
return !(isNote && displayOnEdgeless);
|
||||||
});
|
});
|
||||||
|
|
||||||
this.contentEditable = String(!this.doc.readonly$.value);
|
this.contentEditable = String(!this.store.readonly$.value);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<div class="affine-page-root-block-container">${children} ${widgets}</div>
|
<div class="affine-page-root-block-container">${children} ${widgets}</div>
|
||||||
|
|||||||
@@ -146,14 +146,14 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
private _initHotkey() {
|
private _initHotkey() {
|
||||||
const selection = this.host.selection;
|
const selection = this.host.selection;
|
||||||
const addParagraph = () => {
|
const addParagraph = () => {
|
||||||
if (!this.doc.getParent(this.model)) return;
|
if (!this.store.getParent(this.model)) return;
|
||||||
|
|
||||||
const [paragraphId] = this.doc.addSiblingBlocks(this.model, [
|
const [paragraphId] = this.store.addSiblingBlocks(this.model, [
|
||||||
{
|
{
|
||||||
flavour: 'affine:paragraph',
|
flavour: 'affine:paragraph',
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
const model = this.doc.getModelById(paragraphId);
|
const model = this.store.getModelById(paragraphId);
|
||||||
if (!model) return;
|
if (!model) return;
|
||||||
|
|
||||||
requestConnectedFrame(() => {
|
requestConnectedFrame(() => {
|
||||||
@@ -185,7 +185,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
|
|
||||||
private _initReferencedModel() {
|
private _initReferencedModel() {
|
||||||
const findReferencedModel = (): [GfxModel | null, string] => {
|
const findReferencedModel = (): [GfxModel | null, string] => {
|
||||||
if (!this.model.props.reference) return [null, this.doc.id];
|
if (!this.model.props.reference) return [null, this.store.id];
|
||||||
const referenceId = this.model.props.reference;
|
const referenceId = this.model.props.reference;
|
||||||
|
|
||||||
const find = (doc: Store): [GfxModel | null, string] => {
|
const find = (doc: Store): [GfxModel | null, string] => {
|
||||||
@@ -203,7 +203,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
};
|
};
|
||||||
|
|
||||||
// find current doc first
|
// find current doc first
|
||||||
let result = find(this.doc);
|
let result = find(this.store);
|
||||||
if (result[0]) return result;
|
if (result[0]) return result;
|
||||||
|
|
||||||
for (const doc of this.std.workspace.docs.values()) {
|
for (const doc of this.std.workspace.docs.values()) {
|
||||||
@@ -211,7 +211,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
if (result[0]) return result;
|
if (result[0]) return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
return [null, this.doc.id];
|
return [null, this.store.id];
|
||||||
};
|
};
|
||||||
|
|
||||||
const init = () => {
|
const init = () => {
|
||||||
@@ -220,7 +220,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
this._referencedModel =
|
this._referencedModel =
|
||||||
referencedModel && referencedModel.xywh ? referencedModel : null;
|
referencedModel && referencedModel.xywh ? referencedModel : null;
|
||||||
// TODO(@L-Sun): clear query cache
|
// TODO(@L-Sun): clear query cache
|
||||||
const doc = this.doc.workspace.getDoc(docId);
|
const doc = this.store.workspace.getDoc(docId);
|
||||||
this._previewDoc = doc?.getStore({ readonly: true }) ?? null;
|
this._previewDoc = doc?.getStore({ readonly: true }) ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -249,7 +249,7 @@ export class SurfaceRefBlockComponent extends BlockComponent<SurfaceRefBlockMode
|
|||||||
|
|
||||||
if (this._referencedModel instanceof GfxBlockElementModel) {
|
if (this._referencedModel instanceof GfxBlockElementModel) {
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
this.doc.slots.blockUpdated.subscribe(({ type, id }) => {
|
this.store.slots.blockUpdated.subscribe(({ type, id }) => {
|
||||||
if (type === 'delete' && id === this.model.props.reference) {
|
if (type === 'delete' && id === this.model.props.reference) {
|
||||||
init();
|
init();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -542,7 +542,7 @@ type RootBlockComponent = BlockComponent & {
|
|||||||
function getRootByEditorHost(
|
function getRootByEditorHost(
|
||||||
editorHost: EditorHost
|
editorHost: EditorHost
|
||||||
): RootBlockComponent | null {
|
): RootBlockComponent | null {
|
||||||
const model = editorHost.doc.root;
|
const model = editorHost.store.root;
|
||||||
if (!model) return null;
|
if (!model) return null;
|
||||||
const root = editorHost.view.getBlock(model.id);
|
const root = editorHost.view.getBlock(model.id);
|
||||||
return root as RootBlockComponent | null;
|
return root as RootBlockComponent | null;
|
||||||
|
|||||||
@@ -17,12 +17,13 @@ export class BlockZeroWidth extends LitElement {
|
|||||||
|
|
||||||
_handleClick = (e: MouseEvent) => {
|
_handleClick = (e: MouseEvent) => {
|
||||||
stopPropagation(e);
|
stopPropagation(e);
|
||||||
if (this.block.doc.readonly) return;
|
if (this.block.store.readonly) return;
|
||||||
const nextBlock = this.block.doc.getNext(this.block.model);
|
const nextBlock = this.block.store.getNext(this.block.model);
|
||||||
if (nextBlock?.flavour !== 'affine:paragraph') {
|
if (nextBlock?.flavour !== 'affine:paragraph') {
|
||||||
const [paragraphId] = this.block.doc.addSiblingBlocks(this.block.model, [
|
const [paragraphId] = this.block.store.addSiblingBlocks(
|
||||||
{ flavour: 'affine:paragraph' },
|
this.block.model,
|
||||||
]);
|
[{ flavour: 'affine:paragraph' }]
|
||||||
|
);
|
||||||
const std = this.block.std;
|
const std = this.block.std;
|
||||||
std.selection.setGroup('note', [
|
std.selection.setGroup('note', [
|
||||||
std.selection.create(TextSelection, {
|
std.selection.create(TextSelection, {
|
||||||
|
|||||||
@@ -3,10 +3,10 @@ import { stopPropagation } from '@blocksuite/affine-shared/utils';
|
|||||||
import { WithDisposable } from '@blocksuite/global/lit';
|
import { WithDisposable } from '@blocksuite/global/lit';
|
||||||
import type { BlockStdScope } from '@blocksuite/std';
|
import type { BlockStdScope } from '@blocksuite/std';
|
||||||
import {
|
import {
|
||||||
docContext,
|
|
||||||
modelContext,
|
modelContext,
|
||||||
ShadowlessElement,
|
ShadowlessElement,
|
||||||
stdContext,
|
stdContext,
|
||||||
|
storeContext,
|
||||||
TextSelection,
|
TextSelection,
|
||||||
} from '@blocksuite/std';
|
} from '@blocksuite/std';
|
||||||
import { RANGE_SYNC_EXCLUDE_ATTR } from '@blocksuite/std/inline';
|
import { RANGE_SYNC_EXCLUDE_ATTR } from '@blocksuite/std/inline';
|
||||||
@@ -168,7 +168,7 @@ export class BlockCaptionEditor<
|
|||||||
@state()
|
@state()
|
||||||
accessor display = false;
|
accessor display = false;
|
||||||
|
|
||||||
@consume({ context: docContext })
|
@consume({ context: storeContext })
|
||||||
accessor doc!: Store;
|
accessor doc!: Store;
|
||||||
|
|
||||||
@query('.block-caption-editor')
|
@query('.block-caption-editor')
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ export class CaptionedBlockComponent<
|
|||||||
.selected=${this.selected$.value}
|
.selected=${this.selected$.value}
|
||||||
></affine-block-selection>`
|
></affine-block-selection>`
|
||||||
: null}
|
: null}
|
||||||
${this.useZeroWidth && !this.doc.readonly
|
${this.useZeroWidth && !this.store.readonly
|
||||||
? html`<block-zero-width .block=${this}></block-zero-width>`
|
? html`<block-zero-width .block=${this}></block-zero-width>`
|
||||||
: nothing}
|
: nothing}
|
||||||
</div>`;
|
</div>`;
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ export class EmbedCardCreateModal extends SignalWatcher(
|
|||||||
flavour = embedOptions.flavour;
|
flavour = embedOptions.flavour;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.host.doc.addBlock(
|
this.host.store.addBlock(
|
||||||
flavour as never,
|
flavour as never,
|
||||||
{
|
{
|
||||||
url,
|
url,
|
||||||
|
|||||||
@@ -18,11 +18,11 @@ export const createToastContainer = (editorHost: EditorHost) => {
|
|||||||
`;
|
`;
|
||||||
const template = html`<div class="toast-container" style="${styles}"></div>`;
|
const template = html`<div class="toast-container" style="${styles}"></div>`;
|
||||||
const element = htmlToElement<HTMLDivElement>(template);
|
const element = htmlToElement<HTMLDivElement>(template);
|
||||||
const { std, doc } = editorHost;
|
const { std, store } = editorHost;
|
||||||
|
|
||||||
let container = document.body;
|
let container = document.body;
|
||||||
if (doc.root) {
|
if (store.root) {
|
||||||
const rootComponent = std.view.getBlock(doc.root.id) as BlockComponent & {
|
const rootComponent = std.view.getBlock(store.root.id) as BlockComponent & {
|
||||||
viewportElement: HTMLElement;
|
viewportElement: HTMLElement;
|
||||||
};
|
};
|
||||||
if (rootComponent) {
|
if (rootComponent) {
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export class FramePanelBody extends SignalWatcher(
|
|||||||
};
|
};
|
||||||
|
|
||||||
get frames() {
|
get frames() {
|
||||||
const frames = this.editorHost.doc
|
const frames = this.editorHost.store
|
||||||
.getBlocksByFlavour('affine:frame')
|
.getBlocksByFlavour('affine:frame')
|
||||||
.map(block => block.model as FrameBlockModel);
|
.map(block => block.model as FrameBlockModel);
|
||||||
return frames.sort(compare);
|
return frames.sort(compare);
|
||||||
@@ -318,7 +318,7 @@ export class FramePanelBody extends SignalWatcher(
|
|||||||
before = newIndex;
|
before = newIndex;
|
||||||
});
|
});
|
||||||
|
|
||||||
this.editorHost.doc.captureSync();
|
this.editorHost.store.captureSync();
|
||||||
this._updateFrames();
|
this._updateFrames();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -392,9 +392,9 @@ export class FramePanelBody extends SignalWatcher(
|
|||||||
|
|
||||||
override updated(_changedProperties: PropertyValues) {
|
override updated(_changedProperties: PropertyValues) {
|
||||||
if (_changedProperties.has('editorHost') && this.editorHost) {
|
if (_changedProperties.has('editorHost') && this.editorHost) {
|
||||||
this._setDocDisposables(this.editorHost.doc);
|
this._setDocDisposables(this.editorHost.store);
|
||||||
// after switch to edgeless mode, should update the selection
|
// after switch to edgeless mode, should update the selection
|
||||||
if (this.editorHost.doc.id === this._lastEdgelessRootId) {
|
if (this.editorHost.store.id === this._lastEdgelessRootId) {
|
||||||
this._gfx.selection.set({
|
this._gfx.selection.set({
|
||||||
elements: this._selected,
|
elements: this._selected,
|
||||||
editing: false,
|
editing: false,
|
||||||
@@ -402,7 +402,7 @@ export class FramePanelBody extends SignalWatcher(
|
|||||||
} else {
|
} else {
|
||||||
this._selected = this._selected.length ? [] : this._selected;
|
this._selected = this._selected.length ? [] : this._selected;
|
||||||
}
|
}
|
||||||
this._lastEdgelessRootId = this.editorHost.doc.id;
|
this._lastEdgelessRootId = this.editorHost.store.id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export class OutlineNotice extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
const shouldShowNotice =
|
const shouldShowNotice =
|
||||||
getNotesFromDoc(this._context.editor$.value.doc, [
|
getNotesFromDoc(this._context.editor$.value.store, [
|
||||||
NoteDisplayMode.DocOnly,
|
NoteDisplayMode.DocOnly,
|
||||||
]).length > 0;
|
]).length > 0;
|
||||||
|
|
||||||
|
|||||||
@@ -92,7 +92,7 @@ export class OutlinePanelBody extends SignalWatcher(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private get doc() {
|
private get doc() {
|
||||||
return this.editor.doc;
|
return this.editor.store;
|
||||||
}
|
}
|
||||||
|
|
||||||
get viewportPadding(): [number, number, number, number] {
|
get viewportPadding(): [number, number, number, number] {
|
||||||
@@ -262,14 +262,14 @@ export class OutlinePanelBody extends SignalWatcher(
|
|||||||
|
|
||||||
private _watchSelectedNotes() {
|
private _watchSelectedNotes() {
|
||||||
return effect(() => {
|
return effect(() => {
|
||||||
const { std, doc } = this.editor;
|
const { std, store } = this.editor;
|
||||||
const docModeService = this.editor.std.get(DocModeProvider);
|
const docModeService = this.editor.std.get(DocModeProvider);
|
||||||
const mode = docModeService.getEditorMode();
|
const mode = docModeService.getEditorMode();
|
||||||
if (mode !== 'edgeless') return;
|
if (mode !== 'edgeless') return;
|
||||||
|
|
||||||
const currSelectedNotes = std.selection
|
const currSelectedNotes = std.selection
|
||||||
.filter(SurfaceSelection)
|
.filter(SurfaceSelection)
|
||||||
.map(({ blockId }) => doc.getBlock(blockId)?.model)
|
.map(({ blockId }) => store.getBlock(blockId)?.model)
|
||||||
.filter(model => {
|
.filter(model => {
|
||||||
return !!model && matchModels(model, [NoteBlockModel]);
|
return !!model && matchModels(model, [NoteBlockModel]);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -168,10 +168,10 @@ export class MobileOutlineMenu extends SignalWatcher(
|
|||||||
override render() {
|
override render() {
|
||||||
const docModeService = this.editor.std.get(DocModeProvider);
|
const docModeService = this.editor.std.get(DocModeProvider);
|
||||||
const mode = docModeService.getEditorMode();
|
const mode = docModeService.getEditorMode();
|
||||||
if (this.editor.doc.root === null || mode === 'edgeless') return nothing;
|
if (this.editor.store.root === null || mode === 'edgeless') return nothing;
|
||||||
|
|
||||||
const headingBlocks = getHeadingBlocksFromDoc(
|
const headingBlocks = getHeadingBlocksFromDoc(
|
||||||
this.editor.doc,
|
this.editor.store,
|
||||||
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@@ -179,7 +179,7 @@ export class MobileOutlineMenu extends SignalWatcher(
|
|||||||
if (headingBlocks.length === 0) return nothing;
|
if (headingBlocks.length === 0) return nothing;
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
...(this.editor.doc.meta?.title !== '' ? [this.editor.doc.root] : []),
|
...(this.editor.store.meta?.title !== '' ? [this.editor.store.root] : []),
|
||||||
...headingBlocks,
|
...headingBlocks,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ export class OutlineViewer extends SignalWatcher(
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this.editor.doc.workspace.meta.docMetaUpdated.subscribe(() => {
|
this.editor.store.workspace.meta.docMetaUpdated.subscribe(() => {
|
||||||
this.requestUpdate();
|
this.requestUpdate();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
@@ -223,10 +223,10 @@ export class OutlineViewer extends SignalWatcher(
|
|||||||
override render() {
|
override render() {
|
||||||
const docModeService = this.editor.std.get(DocModeProvider);
|
const docModeService = this.editor.std.get(DocModeProvider);
|
||||||
const mode = docModeService.getEditorMode();
|
const mode = docModeService.getEditorMode();
|
||||||
if (this.editor.doc.root === null || mode === 'edgeless') return nothing;
|
if (this.editor.store.root === null || mode === 'edgeless') return nothing;
|
||||||
|
|
||||||
const headingBlocks = getHeadingBlocksFromDoc(
|
const headingBlocks = getHeadingBlocksFromDoc(
|
||||||
this.editor.doc,
|
this.editor.store,
|
||||||
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
@@ -234,7 +234,7 @@ export class OutlineViewer extends SignalWatcher(
|
|||||||
if (headingBlocks.length === 0) return nothing;
|
if (headingBlocks.length === 0) return nothing;
|
||||||
|
|
||||||
const items = [
|
const items = [
|
||||||
...(this.editor.doc.meta?.title !== '' ? [this.editor.doc.root] : []),
|
...(this.editor.store.meta?.title !== '' ? [this.editor.store.root] : []),
|
||||||
...headingBlocks,
|
...headingBlocks,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export function scrollToBlock(host: EditorHost, blockId: string) {
|
|||||||
const mode = docModeService.getEditorMode();
|
const mode = docModeService.getEditorMode();
|
||||||
if (mode === 'edgeless') return;
|
if (mode === 'edgeless') return;
|
||||||
|
|
||||||
if (host.doc.root?.id === blockId) {
|
if (host.store.root?.id === blockId) {
|
||||||
const docTitle = getDocTitleByEditorHost(host);
|
const docTitle = getDocTitleByEditorHost(host);
|
||||||
if (!docTitle) return;
|
if (!docTitle) return;
|
||||||
|
|
||||||
@@ -60,12 +60,12 @@ export const observeActiveHeadingDuringScroll = (
|
|||||||
const host = getEditor();
|
const host = getEditor();
|
||||||
|
|
||||||
const headings = getHeadingBlocksFromDoc(
|
const headings = getHeadingBlocksFromDoc(
|
||||||
host.doc,
|
host.store,
|
||||||
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
[NoteDisplayMode.DocAndEdgeless, NoteDisplayMode.DocOnly],
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
|
||||||
let activeHeadingId = host.doc.root?.id ?? null;
|
let activeHeadingId = host.store.root?.id ?? null;
|
||||||
headings.forEach(heading => {
|
headings.forEach(heading => {
|
||||||
if (isBlockBeforeViewportCenter(heading.id, host)) {
|
if (isBlockBeforeViewportCenter(heading.id, host)) {
|
||||||
activeHeadingId = heading.id;
|
activeHeadingId = heading.id;
|
||||||
@@ -87,7 +87,7 @@ let highlightTimeoutId: ReturnType<typeof setTimeout> | null = null;
|
|||||||
function highlightBlock(host: EditorHost, blockId: string) {
|
function highlightBlock(host: EditorHost, blockId: string) {
|
||||||
const emptyClear = () => {};
|
const emptyClear = () => {};
|
||||||
|
|
||||||
if (host.doc.root?.id === blockId) return emptyClear;
|
if (host.store.root?.id === blockId) return emptyClear;
|
||||||
|
|
||||||
const rootComponent = host.querySelector<
|
const rootComponent = host.querySelector<
|
||||||
HTMLElement & { viewport: Viewport }
|
HTMLElement & { viewport: Viewport }
|
||||||
|
|||||||
@@ -163,7 +163,7 @@ export class EdgelessPenMenu extends EdgelessToolbarToolMixin(
|
|||||||
.theme=${theme}
|
.theme=${theme}
|
||||||
.palettes=${DefaultTheme.StrokeColorShortPalettes}
|
.palettes=${DefaultTheme.StrokeColorShortPalettes}
|
||||||
.shouldKeepColor=${true}
|
.shouldKeepColor=${true}
|
||||||
.hasTransparent=${!this.edgeless.doc
|
.hasTransparent=${!this.edgeless.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_color_picker')}
|
.getFlag('enable_color_picker')}
|
||||||
></edgeless-color-panel>
|
></edgeless-color-panel>
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ import { WithDisposable } from '@blocksuite/global/lit';
|
|||||||
import {
|
import {
|
||||||
type BlockComponent,
|
type BlockComponent,
|
||||||
type BlockStdScope,
|
type BlockStdScope,
|
||||||
docContext,
|
|
||||||
stdContext,
|
stdContext,
|
||||||
|
storeContext,
|
||||||
} from '@blocksuite/std';
|
} from '@blocksuite/std';
|
||||||
import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
|
||||||
import type { Store } from '@blocksuite/store';
|
import type { Store } from '@blocksuite/store';
|
||||||
@@ -154,7 +154,7 @@ export class EdgelessConnectorHandle extends WithDisposable(LitElement) {
|
|||||||
accessor connector!: ConnectorElementModel;
|
accessor connector!: ConnectorElementModel;
|
||||||
|
|
||||||
@consume({
|
@consume({
|
||||||
context: docContext,
|
context: storeContext,
|
||||||
})
|
})
|
||||||
accessor doc!: Store;
|
accessor doc!: Store;
|
||||||
|
|
||||||
|
|||||||
@@ -137,7 +137,7 @@ export class EdgelessConnectorMenu extends EdgelessToolbarToolMixin(
|
|||||||
.value=${stroke}
|
.value=${stroke}
|
||||||
.theme=${this._theme$.value}
|
.theme=${this._theme$.value}
|
||||||
.palettes=${DefaultTheme.StrokeColorShortPalettes}
|
.palettes=${DefaultTheme.StrokeColorShortPalettes}
|
||||||
.hasTransparent=${!this.edgeless.doc
|
.hasTransparent=${!this.edgeless.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_color_picker')}
|
.getFlag('enable_color_picker')}
|
||||||
@select=${(e: ColorEvent) =>
|
@select=${(e: ColorEvent) =>
|
||||||
|
|||||||
@@ -115,7 +115,7 @@ export const textRender: DraggableTool['render'] = async (bound, edgeless) => {
|
|||||||
const w = 100;
|
const w = 100;
|
||||||
const h = 32;
|
const h = 32;
|
||||||
|
|
||||||
const flag = edgeless.doc
|
const flag = edgeless.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_edgeless_text');
|
.getFlag('enable_edgeless_text');
|
||||||
let id: string;
|
let id: string;
|
||||||
@@ -135,7 +135,7 @@ export const textRender: DraggableTool['render'] = async (bound, edgeless) => {
|
|||||||
text: new Y.Text(),
|
text: new Y.Text(),
|
||||||
}) as string;
|
}) as string;
|
||||||
|
|
||||||
edgeless.doc.captureSync();
|
edgeless.store.captureSync();
|
||||||
const textElement = crud.getElementById(id);
|
const textElement = crud.getElementById(id);
|
||||||
if (!(textElement instanceof TextElementModel)) {
|
if (!(textElement instanceof TextElementModel)) {
|
||||||
console.error('Cannot mount text editor on a non-text element');
|
console.error('Cannot mount text editor on a non-text element');
|
||||||
|
|||||||
@@ -194,7 +194,7 @@ export class EdgelessShapeMenu extends SignalWatcher(
|
|||||||
.value=${fillColor}
|
.value=${fillColor}
|
||||||
.theme=${this._theme$.value}
|
.theme=${this._theme$.value}
|
||||||
.palettes=${DefaultTheme.FillColorShortPalettes}
|
.palettes=${DefaultTheme.FillColorShortPalettes}
|
||||||
.hasTransparent=${!this.edgeless.doc
|
.hasTransparent=${!this.edgeless.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_color_picker')}
|
.getFlag('enable_color_picker')}
|
||||||
@select=${(e: ColorEvent) => this._setFillColor(e.detail)}
|
@select=${(e: ColorEvent) => this._setFillColor(e.detail)}
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export const insertEdgelessTextCommand: Command<
|
|||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const { std, x, y } = ctx;
|
const { std, x, y } = ctx;
|
||||||
const host = std.host;
|
const host = std.host;
|
||||||
const doc = host.doc;
|
const doc = host.store;
|
||||||
const surface = getSurfaceBlock(doc);
|
const surface = getSurfaceBlock(doc);
|
||||||
if (!surface) {
|
if (!surface) {
|
||||||
next();
|
next();
|
||||||
|
|||||||
@@ -83,7 +83,7 @@ export function addText(edgeless: BlockComponent, event: PointerEventState) {
|
|||||||
});
|
});
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|
||||||
edgeless.doc.captureSync();
|
edgeless.store.captureSync();
|
||||||
const textElement = crud.getElementById(id);
|
const textElement = crud.getElementById(id);
|
||||||
if (!textElement) return;
|
if (!textElement) return;
|
||||||
if (textElement instanceof TextElementModel) {
|
if (textElement instanceof TextElementModel) {
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export const LatexExtension = InlineMarkdownExtension<AffineTextAttributes>({
|
|||||||
inlineEditor.rootElement.closest<BlockComponent>('[data-block-id]');
|
inlineEditor.rootElement.closest<BlockComponent>('[data-block-id]');
|
||||||
if (!blockComponent) return;
|
if (!blockComponent) return;
|
||||||
|
|
||||||
const doc = blockComponent.doc;
|
const doc = blockComponent.store;
|
||||||
const parentComponent = blockComponent.parentComponent;
|
const parentComponent = blockComponent.parentComponent;
|
||||||
if (!parentComponent) return;
|
if (!parentComponent) return;
|
||||||
|
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
flavour: 'affine:list',
|
flavour: 'affine:list',
|
||||||
@@ -93,7 +93,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
flavour: ['affine:list', 'affine:code'],
|
flavour: ['affine:list', 'affine:code'],
|
||||||
@@ -114,7 +114,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
role: 'content',
|
role: 'content',
|
||||||
flavour: 'affine:list',
|
flavour: 'affine:list',
|
||||||
@@ -153,7 +153,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
role: 'hub',
|
role: 'hub',
|
||||||
@@ -173,7 +173,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
role: 'hub',
|
role: 'hub',
|
||||||
@@ -193,7 +193,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
flavour: 'affine:list',
|
flavour: 'affine:list',
|
||||||
@@ -217,7 +217,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-2')?.model;
|
const note = host.store.getBlock('note-2')?.model;
|
||||||
|
|
||||||
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
const [_, { firstBlock }] = host.command.exec(getFirstBlockCommand, {
|
||||||
role: 'content',
|
role: 'content',
|
||||||
|
|||||||
@@ -73,7 +73,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
flavour: 'affine:list',
|
flavour: 'affine:list',
|
||||||
@@ -93,7 +93,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
flavour: ['affine:list', 'affine:code'],
|
flavour: ['affine:list', 'affine:code'],
|
||||||
@@ -114,7 +114,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
role: 'content',
|
role: 'content',
|
||||||
flavour: 'affine:list',
|
flavour: 'affine:list',
|
||||||
@@ -153,7 +153,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
role: 'hub',
|
role: 'hub',
|
||||||
@@ -173,7 +173,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
role: 'hub',
|
role: 'hub',
|
||||||
@@ -193,7 +193,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-1')?.model;
|
const note = host.store.getBlock('note-1')?.model;
|
||||||
|
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
flavour: 'affine:list',
|
flavour: 'affine:list',
|
||||||
@@ -217,7 +217,7 @@ describe('commands/block-crud', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const note = host.doc.getBlock('note-2')?.model;
|
const note = host.store.getBlock('note-2')?.model;
|
||||||
|
|
||||||
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
const [_, { lastBlock }] = host.command.exec(getLastBlockCommand, {
|
||||||
role: 'content',
|
role: 'content',
|
||||||
|
|||||||
@@ -12,17 +12,17 @@ describe('helpers/affine-template', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
expect(host.doc).toBeDefined();
|
expect(host.store).toBeDefined();
|
||||||
|
|
||||||
const pageBlock = host.doc.getBlock('page');
|
const pageBlock = host.store.getBlock('page');
|
||||||
expect(pageBlock).toBeDefined();
|
expect(pageBlock).toBeDefined();
|
||||||
expect(pageBlock?.flavour).toBe('affine:page');
|
expect(pageBlock?.flavour).toBe('affine:page');
|
||||||
|
|
||||||
const noteBlock = host.doc.getBlock('note');
|
const noteBlock = host.store.getBlock('note');
|
||||||
expect(noteBlock).toBeDefined();
|
expect(noteBlock).toBeDefined();
|
||||||
expect(noteBlock?.flavour).toBe('affine:note');
|
expect(noteBlock?.flavour).toBe('affine:note');
|
||||||
|
|
||||||
const paragraphBlock = host.doc.getBlock('paragraph-1');
|
const paragraphBlock = host.store.getBlock('paragraph-1');
|
||||||
expect(paragraphBlock).toBeDefined();
|
expect(paragraphBlock).toBeDefined();
|
||||||
expect(paragraphBlock?.flavour).toBe('affine:paragraph');
|
expect(paragraphBlock?.flavour).toBe('affine:paragraph');
|
||||||
});
|
});
|
||||||
@@ -38,16 +38,17 @@ describe('helpers/affine-template', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const noteBlocks = host.doc.getBlocksByFlavour('affine:note');
|
const noteBlocks = host.store.getBlocksByFlavour('affine:note');
|
||||||
const paragraphBlocks = host.doc.getBlocksByFlavour('affine:paragraph');
|
const paragraphBlocks = host.store.getBlocksByFlavour('affine:paragraph');
|
||||||
const listBlocks = host.doc.getBlocksByFlavour('affine:list');
|
const listBlocks = host.store.getBlocksByFlavour('affine:list');
|
||||||
|
|
||||||
expect(noteBlocks.length).toBe(1);
|
expect(noteBlocks.length).toBe(1);
|
||||||
expect(paragraphBlocks.length).toBe(2);
|
expect(paragraphBlocks.length).toBe(2);
|
||||||
expect(listBlocks.length).toBe(1);
|
expect(listBlocks.length).toBe(1);
|
||||||
|
|
||||||
const noteBlock = noteBlocks[0];
|
const noteBlock = noteBlocks[0];
|
||||||
const noteChildren = host.doc.getBlock(noteBlock.id)?.model.children || [];
|
const noteChildren =
|
||||||
|
host.store.getBlock(noteBlock.id)?.model.children || [];
|
||||||
expect(noteChildren.length).toBe(3);
|
expect(noteChildren.length).toBe(3);
|
||||||
|
|
||||||
expect(noteChildren[0].flavour).toBe('affine:paragraph');
|
expect(noteChildren[0].flavour).toBe('affine:paragraph');
|
||||||
@@ -64,10 +65,10 @@ describe('helpers/affine-template', () => {
|
|||||||
</affine-page>
|
</affine-page>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
const paragraphBlocks = host.doc.getBlocksByFlavour('affine:paragraph');
|
const paragraphBlocks = host.store.getBlocksByFlavour('affine:paragraph');
|
||||||
expect(paragraphBlocks.length).toBe(1);
|
expect(paragraphBlocks.length).toBe(1);
|
||||||
|
|
||||||
const paragraphBlock = host.doc.getBlock(paragraphBlocks[0].id);
|
const paragraphBlock = host.store.getBlock(paragraphBlocks[0].id);
|
||||||
const paragraphText = paragraphBlock?.model.text?.toString() || '';
|
const paragraphText = paragraphBlock?.model.text?.toString() || '';
|
||||||
expect(paragraphText).toBe('');
|
expect(paragraphText).toBe('');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -229,10 +229,10 @@ export function createTestHost(doc: Store): EditorHost {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const host = {
|
const host = {
|
||||||
doc: doc,
|
store: doc,
|
||||||
std: std as any,
|
std: std as any,
|
||||||
};
|
};
|
||||||
host.doc = doc;
|
host.store = doc;
|
||||||
host.std = std as any;
|
host.std = std as any;
|
||||||
|
|
||||||
std.host = host;
|
std.host = host;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const getFirstBlockCommand: Command<
|
|||||||
firstBlock: BlockModel | null;
|
firstBlock: BlockModel | null;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const root = ctx.root || ctx.std.host.doc.root;
|
const root = ctx.root || ctx.std.host.store.root;
|
||||||
if (!root) {
|
if (!root) {
|
||||||
next({
|
next({
|
||||||
firstBlock: null,
|
firstBlock: null,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ export const getLastBlockCommand: Command<
|
|||||||
lastBlock: BlockModel | null;
|
lastBlock: BlockModel | null;
|
||||||
}
|
}
|
||||||
> = (ctx, next) => {
|
> = (ctx, next) => {
|
||||||
const root = ctx.root || ctx.std.host.doc.root;
|
const root = ctx.root || ctx.std.host.store.root;
|
||||||
if (!root) {
|
if (!root) {
|
||||||
next({
|
next({
|
||||||
lastBlock: null,
|
lastBlock: null,
|
||||||
|
|||||||
@@ -35,13 +35,13 @@ export class PreviewHelper {
|
|||||||
if (!selectedIds.includes(parent)) {
|
if (!selectedIds.includes(parent)) {
|
||||||
ids.push({ viewType: 'bypass', id: parent });
|
ids.push({ viewType: 'bypass', id: parent });
|
||||||
}
|
}
|
||||||
parent = this.widget.doc.getParent(parent)?.id ?? null;
|
parent = this.widget.store.getParent(parent)?.id ?? null;
|
||||||
} while (parent && !ids.map(({ id }) => id).includes(parent));
|
} while (parent && !ids.map(({ id }) => id).includes(parent));
|
||||||
});
|
});
|
||||||
|
|
||||||
// The children of the selected blocks should be rendered as Display
|
// The children of the selected blocks should be rendered as Display
|
||||||
const addChildren = (id: string) => {
|
const addChildren = (id: string) => {
|
||||||
const model = this.widget.doc.getBlock(id)?.model;
|
const model = this.widget.store.getBlock(id)?.model;
|
||||||
if (!model) {
|
if (!model) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -68,7 +68,7 @@ export class PreviewHelper {
|
|||||||
const docModeService = std.get(DocModeProvider);
|
const docModeService = std.get(DocModeProvider);
|
||||||
const editorSetting = std.get(EditorSettingProvider);
|
const editorSetting = std.get(EditorSettingProvider);
|
||||||
const query = this._calculateQuery(blockIds as string[]);
|
const query = this._calculateQuery(blockIds as string[]);
|
||||||
const store = widget.doc.doc.getStore({ query });
|
const store = widget.store.doc.getStore({ query });
|
||||||
let previewSpec = widget.std
|
let previewSpec = widget.std
|
||||||
.get(ViewExtensionManagerIdentifier)
|
.get(ViewExtensionManagerIdentifier)
|
||||||
.get('preview-page');
|
.get('preview-page');
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ export const containChildBlock = (
|
|||||||
if (currentBlock.id === block.model.id) {
|
if (currentBlock.id === block.model.id) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
currentBlock = block.doc.getParent(currentBlock.id);
|
currentBlock = block.store.getParent(currentBlock.id);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -501,7 +501,7 @@ export class DragEventWatcher {
|
|||||||
// can't drop edgeless content on the same doc
|
// can't drop edgeless content on the same doc
|
||||||
if (
|
if (
|
||||||
dragPayload.bsEntity?.fromMode === 'gfx' &&
|
dragPayload.bsEntity?.fromMode === 'gfx' &&
|
||||||
dragPayload.from?.docId === this.widget.doc.id
|
dragPayload.from?.docId === this.widget.store.id
|
||||||
) {
|
) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -550,7 +550,7 @@ export class DragEventWatcher {
|
|||||||
|
|
||||||
// drop on the same place, do nothing
|
// drop on the same place, do nothing
|
||||||
if (
|
if (
|
||||||
(dragPayload.from?.docId === this.widget.doc.id &&
|
(dragPayload.from?.docId === this.widget.store.id &&
|
||||||
result.placement === 'after' &&
|
result.placement === 'after' &&
|
||||||
parent.children[index]?.id === snapshot.content[0].id) ||
|
parent.children[index]?.id === snapshot.content[0].id) ||
|
||||||
(result.placement === 'before' &&
|
(result.placement === 'before' &&
|
||||||
@@ -566,7 +566,7 @@ export class DragEventWatcher {
|
|||||||
) {
|
) {
|
||||||
snapshot.content = snapshot.content.filter(
|
snapshot.content = snapshot.content.filter(
|
||||||
block =>
|
block =>
|
||||||
dragPayload.from?.docId !== this.widget.doc.id ||
|
dragPayload.from?.docId !== this.widget.store.id ||
|
||||||
block.id !== parent.id
|
block.id !== parent.id
|
||||||
);
|
);
|
||||||
if (snapshot.content.length) {
|
if (snapshot.content.length) {
|
||||||
@@ -590,7 +590,7 @@ export class DragEventWatcher {
|
|||||||
matchModels(parent, [NoteBlockModel])
|
matchModels(parent, [NoteBlockModel])
|
||||||
) {
|
) {
|
||||||
// if the snapshot comes from the same doc, just create a surface-ref block
|
// if the snapshot comes from the same doc, just create a surface-ref block
|
||||||
if (dragPayload.from?.docId === this.widget.doc.id) {
|
if (dragPayload.from?.docId === this.widget.store.id) {
|
||||||
let largestElem!: {
|
let largestElem!: {
|
||||||
size: number;
|
size: number;
|
||||||
id: string;
|
id: string;
|
||||||
@@ -1194,7 +1194,7 @@ export class DragEventWatcher {
|
|||||||
};
|
};
|
||||||
|
|
||||||
this._rewriteSnapshotXYWH(pageSnapshot, point, true);
|
this._rewriteSnapshotXYWH(pageSnapshot, point, true);
|
||||||
this._dropToModel(pageSnapshot, this.widget.doc.root!.id)
|
this._dropToModel(pageSnapshot, this.widget.store.root!.id)
|
||||||
.then(slices => {
|
.then(slices => {
|
||||||
slices?.content.forEach((block, idx) => {
|
slices?.content.forEach((block, idx) => {
|
||||||
if (block.flavour === 'affine:embed-iframe') {
|
if (block.flavour === 'affine:embed-iframe') {
|
||||||
@@ -1259,7 +1259,7 @@ export class DragEventWatcher {
|
|||||||
DEFAULT_NOTE_HEIGHT
|
DEFAULT_NOTE_HEIGHT
|
||||||
).serialize(),
|
).serialize(),
|
||||||
},
|
},
|
||||||
this.widget.doc.root!
|
this.widget.store.root!
|
||||||
);
|
);
|
||||||
|
|
||||||
this._dropToModel(
|
this._dropToModel(
|
||||||
@@ -1508,7 +1508,7 @@ export class DragEventWatcher {
|
|||||||
*/
|
*/
|
||||||
if (source.data.bsEntity?.type === 'blocks') {
|
if (source.data.bsEntity?.type === 'blocks') {
|
||||||
return (
|
return (
|
||||||
source.data.from?.docId !== widget.doc.id ||
|
source.data.from?.docId !== widget.store.id ||
|
||||||
source.data.bsEntity.modelIds.every(id => id !== view.model.id)
|
source.data.bsEntity.modelIds.every(id => id !== view.model.id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export class EdgelessWatcher {
|
|||||||
|
|
||||||
updateAnchorElement = () => {
|
updateAnchorElement = () => {
|
||||||
if (!this.widget.isConnected) return;
|
if (!this.widget.isConnected) return;
|
||||||
if (this.widget.doc.readonly || this.widget.mode === 'page') {
|
if (this.widget.store.readonly || this.widget.mode === 'page') {
|
||||||
this.widget.hide();
|
this.widget.hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -100,7 +100,11 @@ export class EdgelessWatcher {
|
|||||||
const editing = selection.editing;
|
const editing = selection.editing;
|
||||||
const selectedElements = selection.selectedElements;
|
const selectedElements = selection.selectedElements;
|
||||||
|
|
||||||
if (editing || selectedElements.length !== 1 || this.widget.doc.readonly) {
|
if (
|
||||||
|
editing ||
|
||||||
|
selectedElements.length !== 1 ||
|
||||||
|
this.widget.store.readonly
|
||||||
|
) {
|
||||||
this.widget.hide();
|
this.widget.hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ export class PageWatcher {
|
|||||||
const { disposables } = this.widget;
|
const { disposables } = this.widget;
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
this.widget.doc.slots.blockUpdated.subscribe(() => this.widget.hide())
|
this.widget.store.slots.blockUpdated.subscribe(() => this.widget.hide())
|
||||||
);
|
);
|
||||||
|
|
||||||
disposables.add(
|
disposables.add(
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ export class PointerEventWatcher {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private readonly _canEditing = (noteBlock: BlockComponent) => {
|
private readonly _canEditing = (noteBlock: BlockComponent) => {
|
||||||
if (noteBlock.doc.id !== this.widget.doc.id) return false;
|
if (noteBlock.store.id !== this.widget.store.id) return false;
|
||||||
|
|
||||||
if (this.widget.mode === 'page') return true;
|
if (this.widget.mode === 'page') return true;
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ export class PointerEventWatcher {
|
|||||||
|
|
||||||
this.widget.anchorBlockId.value = blockId;
|
this.widget.anchorBlockId.value = blockId;
|
||||||
|
|
||||||
if (insideDatabaseTable(closestBlock) || this.widget.doc.readonly) {
|
if (insideDatabaseTable(closestBlock) || this.widget.store.readonly) {
|
||||||
this.widget.hide();
|
this.widget.hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -226,7 +226,7 @@ export class PointerEventWatcher {
|
|||||||
ctx => {
|
ctx => {
|
||||||
if (this._isPointerDown) return;
|
if (this._isPointerDown) return;
|
||||||
if (
|
if (
|
||||||
this.widget.doc.readonly ||
|
this.widget.store.readonly ||
|
||||||
this.widget.dragging ||
|
this.widget.dragging ||
|
||||||
!this.widget.isConnected
|
!this.widget.isConnected
|
||||||
) {
|
) {
|
||||||
|
|||||||
@@ -317,7 +317,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
})
|
})
|
||||||
);
|
);
|
||||||
this._disposables.add(
|
this._disposables.add(
|
||||||
this.doc.slots.blockUpdated.subscribe(payload => {
|
this.store.slots.blockUpdated.subscribe(payload => {
|
||||||
if (payload.flavour === 'affine:surface-ref') {
|
if (payload.flavour === 'affine:surface-ref') {
|
||||||
switch (payload.type) {
|
switch (payload.type) {
|
||||||
case 'add':
|
case 'add':
|
||||||
@@ -585,7 +585,7 @@ export class EdgelessAutoConnectWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
const advancedVisibilityEnabled = this.doc
|
const advancedVisibilityEnabled = this.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_advanced_block_visibility');
|
.getFlag('enable_advanced_block_visibility');
|
||||||
|
|
||||||
|
|||||||
@@ -660,7 +660,7 @@ export class EdgelessToolbarWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
const type = this.edgelessTool;
|
const type = this.edgelessTool;
|
||||||
if (this.doc.readonly && type !== 'frameNavigator') {
|
if (this.store.readonly && type !== 'frameNavigator') {
|
||||||
return nothing;
|
return nothing;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ export const AFFINE_FRAME_TITLE_WIDGET = 'affine-frame-title-widget';
|
|||||||
|
|
||||||
export class AffineFrameTitleWidget extends WidgetComponent<RootBlockModel> {
|
export class AffineFrameTitleWidget extends WidgetComponent<RootBlockModel> {
|
||||||
private get _frames() {
|
private get _frames() {
|
||||||
return Object.values(this.doc.blocks.value)
|
return Object.values(this.store.blocks.value)
|
||||||
.map(({ model }) => model)
|
.map(({ model }) => model)
|
||||||
.filter(model => model instanceof FrameBlockModel);
|
.filter(model => model instanceof FrameBlockModel);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ export class EdgelessFrameTitleEditor extends WithDisposable(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
const rootBlockId = this.editorHost.doc.root?.id;
|
const rootBlockId = this.editorHost.store.root?.id;
|
||||||
if (!rootBlockId) return nothing;
|
if (!rootBlockId) return nothing;
|
||||||
|
|
||||||
const viewport = this.gfx.viewport;
|
const viewport = this.gfx.viewport;
|
||||||
|
|||||||
@@ -110,9 +110,9 @@ export class AffineKeyboardToolbarWidget extends WidgetComponent<RootBlockModel>
|
|||||||
|
|
||||||
override render() {
|
override render() {
|
||||||
if (
|
if (
|
||||||
this.doc.readonly ||
|
this.store.readonly ||
|
||||||
!IS_MOBILE ||
|
!IS_MOBILE ||
|
||||||
!this.doc
|
!this.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_mobile_keyboard_toolbar')
|
.getFlag('enable_mobile_keyboard_toolbar')
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -78,7 +78,7 @@ export function createLinkedDocMenuGroup(
|
|||||||
editorHost: EditorHost,
|
editorHost: EditorHost,
|
||||||
inlineEditor: AffineInlineEditor
|
inlineEditor: AffineInlineEditor
|
||||||
) {
|
) {
|
||||||
const doc = editorHost.doc;
|
const doc = editorHost.store;
|
||||||
const { docMetas } = doc.workspace.meta;
|
const { docMetas } = doc.workspace.meta;
|
||||||
const filteredDocList = docMetas
|
const filteredDocList = docMetas
|
||||||
.filter(({ id }) => id !== doc.id)
|
.filter(({ id }) => id !== doc.id)
|
||||||
@@ -122,7 +122,7 @@ export function createNewDocMenuGroup(
|
|||||||
editorHost: EditorHost,
|
editorHost: EditorHost,
|
||||||
inlineEditor: AffineInlineEditor
|
inlineEditor: AffineInlineEditor
|
||||||
): LinkedMenuGroup {
|
): LinkedMenuGroup {
|
||||||
const doc = editorHost.doc;
|
const doc = editorHost.store;
|
||||||
const docName = query || DEFAULT_DOC_NAME;
|
const docName = query || DEFAULT_DOC_NAME;
|
||||||
const displayDocName =
|
const displayDocName =
|
||||||
docName.slice(0, DISPLAY_NAME_LENGTH) +
|
docName.slice(0, DISPLAY_NAME_LENGTH) +
|
||||||
|
|||||||
@@ -307,7 +307,7 @@ export class AffineLinkedDocWidget extends WidgetComponent<RootBlockModel> {
|
|||||||
|
|
||||||
this._updateInputRects();
|
this._updateInputRects();
|
||||||
|
|
||||||
const enableMobile = this.doc
|
const enableMobile = this.store
|
||||||
.get(FeatureFlagService)
|
.get(FeatureFlagService)
|
||||||
.getFlag('enable_mobile_linked_doc_menu');
|
.getFlag('enable_mobile_linked_doc_menu');
|
||||||
this._mode$.value = enableMobile ? mode : 'desktop';
|
this._mode$.value = enableMobile ? mode : 'desktop';
|
||||||
|
|||||||
@@ -118,7 +118,7 @@ export function getSelectingBlockPaths(
|
|||||||
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
// eslint-disable-next-line @typescript-eslint/prefer-for-of
|
||||||
for (let i = 0; i < blocks.length; i++) {
|
for (let i = 0; i < blocks.length; i++) {
|
||||||
const block = blocks[i];
|
const block = blocks[i];
|
||||||
const parent = blocks[i].element.doc.getParent(block.element.model);
|
const parent = blocks[i].element.store.getParent(block.element.model);
|
||||||
const parentId = parent?.id;
|
const parentId = parent?.id;
|
||||||
if (parentId) {
|
if (parentId) {
|
||||||
const isParentInBlocks = blocks.some(
|
const isParentInBlocks = blocks.some(
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user