feat(editor): unify block props api (#10888)

Closes: [BS-2707](https://linear.app/affine-design/issue/BS-2707/统一使用props获取和更新block-prop)
This commit is contained in:
Saul-Mirone
2025-03-16 05:48:34 +00:00
parent 8f9e5bf0aa
commit 26285f7dcb
193 changed files with 1019 additions and 891 deletions
@@ -27,12 +27,12 @@ export function forwardDelete(std: BlockStdScope): true | undefined {
const doc = std.store;
const model = doc.getBlock(text.from.blockId)?.model;
if (!model || !matchModels(model, [ListBlockModel])) return;
const isEnd = isCollapsed && text.from.index === model.text.length;
const isEnd = isCollapsed && text.from.index === model.props.text.length;
if (!isEnd) return;
// Has children in list
const firstChild = model.firstChild();
if (firstChild) {
model.text.join(firstChild.text as Text);
model.props.text.join(firstChild.text as Text);
const grandChildren = firstChild.children;
if (grandChildren) {
doc.moveBlocks(grandChildren, model);
@@ -49,7 +49,7 @@ export function forwardDelete(std: BlockStdScope): true | undefined {
const nextSibling = doc.getNext(model);
const nextText = nextSibling?.text;
if (nextSibling && nextText) {
model.text.join(nextText);
model.props.text.join(nextText);
if (nextSibling.children) {
if (!parent) return;
doc.moveBlocks(nextSibling.children, parent, model, false);
@@ -63,7 +63,7 @@ export function forwardDelete(std: BlockStdScope): true | undefined {
const nextBlock = getNextContentBlock(std.host, model);
const nextBlockText = nextBlock?.text;
if (nextBlock && nextBlockText) {
model.text.join(nextBlock.text as Text);
model.props.text.join(nextBlock.text as Text);
if (nextBlock.children) {
const nextBlockParent = doc.getParent(nextBlock);
if (!nextBlockParent) return;
@@ -36,7 +36,7 @@ export function getListIcon(
onClick: (e: MouseEvent) => void
) {
const deep = getListDeep(model);
switch (model.type) {
switch (model.props.type) {
case 'bulleted':
return html`<div
contenteditable="false"
@@ -51,7 +51,7 @@ export function getListIcon(
class="affine-list-block__prefix affine-list-block__numbered"
@click=${onClick}
>
${model.order ? getNumberPrefix(model.order, deep) : '1.'}
${model.props.order ? getNumberPrefix(model.props.order, deep) : '1.'}
</div>`;
case 'todo':
return html`<div
@@ -59,7 +59,7 @@ export function getListIcon(
class=${`affine-list-block__prefix affine-list-block__todo-prefix ${model.doc.readonly ? 'readonly' : ''}`}
@click=${onClick}
>
${model.checked
${model.props.checked
? CheckBoxCheckSolidIcon({ style: 'color: #1E96EB' })
: CheckBoxUnIcon()}
</div>`;
@@ -72,7 +72,7 @@ export function getListIcon(
${showChildren ? ToggleDownIcon() : ToggleRightIcon()}
</div>`;
default:
console.error('Unknown list type', model.type, model);
console.error('Unknown list type', model.props.type, model);
return null;
}
}