fix: Incorrect empty check for collection description results in large empty space below title
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
|||||||
NavigationNode,
|
NavigationNode,
|
||||||
type ProsemirrorData,
|
type ProsemirrorData,
|
||||||
} from "@shared/types";
|
} from "@shared/types";
|
||||||
|
import { ProsemirrorHelper } from "@shared/utils/ProsemirrorHelper";
|
||||||
import { sortNavigationNodes } from "@shared/utils/collections";
|
import { sortNavigationNodes } from "@shared/utils/collections";
|
||||||
import type CollectionsStore from "~/stores/CollectionsStore";
|
import type CollectionsStore from "~/stores/CollectionsStore";
|
||||||
import Document from "~/models/Document";
|
import Document from "~/models/Document";
|
||||||
@@ -134,8 +135,14 @@ export default class Collection extends ParanoidModel {
|
|||||||
return !this.permission;
|
return !this.permission;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether this collection has a description.
|
||||||
|
*
|
||||||
|
* @returns boolean
|
||||||
|
*/
|
||||||
|
@computed
|
||||||
get hasDescription(): boolean {
|
get hasDescription(): boolean {
|
||||||
return !!this.data;
|
return this.data ? !ProsemirrorHelper.isEmptyData(this.data) : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
|
|||||||
@@ -52,6 +52,30 @@ export class ProsemirrorHelper {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if the data looks like an empty document.
|
||||||
|
*
|
||||||
|
* @param data The ProsemirrorData to check.
|
||||||
|
* @returns True if the document is empty.
|
||||||
|
*/
|
||||||
|
static isEmptyData(data: ProsemirrorData): boolean {
|
||||||
|
if (data.type !== "doc") {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (data.content.length === 1) {
|
||||||
|
const node = data.content[0];
|
||||||
|
return (
|
||||||
|
node.type === "paragraph" &&
|
||||||
|
(node.content === null ||
|
||||||
|
node.content === undefined ||
|
||||||
|
node.content.length === 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return data.content.length === 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the node as plain text.
|
* Returns the node as plain text.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user