mirror of
https://github.com/streetwriters/notesnook.git
synced 2025-12-18 12:47:50 +01:00
editor: fix crash on adding a task list
This commit is contained in:
committed by
Abdullah Atta
parent
271aa11f74
commit
1859799ca3
@@ -159,6 +159,7 @@ export class ReactNodeView<P extends ReactNodeViewProps> implements NodeView {
|
|||||||
<EmotionThemeProvider scope="editor" injectCssVars={false}>
|
<EmotionThemeProvider scope="editor" injectCssVars={false}>
|
||||||
<this.options.component
|
<this.options.component
|
||||||
{...props}
|
{...props}
|
||||||
|
pos={this.getPos()}
|
||||||
editor={this.editor}
|
editor={this.editor}
|
||||||
getPos={this.getPos}
|
getPos={this.getPos}
|
||||||
node={this.node}
|
node={this.node}
|
||||||
|
|||||||
@@ -51,7 +51,8 @@ export class PortalProviderAPI extends EventDispatcher {
|
|||||||
|
|
||||||
render(
|
render(
|
||||||
children: () => React.ReactChild | JSX.Element | null,
|
children: () => React.ReactChild | JSX.Element | null,
|
||||||
container: HTMLElement
|
container: HTMLElement,
|
||||||
|
callback?: () => void
|
||||||
) {
|
) {
|
||||||
if (!this.context) return;
|
if (!this.context) return;
|
||||||
|
|
||||||
@@ -63,7 +64,8 @@ export class PortalProviderAPI extends EventDispatcher {
|
|||||||
unstable_renderSubtreeIntoContainer(
|
unstable_renderSubtreeIntoContainer(
|
||||||
this.context,
|
this.context,
|
||||||
wrappedChildren,
|
wrappedChildren,
|
||||||
container
|
container,
|
||||||
|
callback
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ export type ContentDOM =
|
|||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
export type ReactNodeViewProps<TAttributes = Attrs> = {
|
export type ReactNodeViewProps<TAttributes = Attrs> = {
|
||||||
|
pos: number | undefined;
|
||||||
getPos: GetPosNode;
|
getPos: GetPosNode;
|
||||||
node: NodeWithAttrs<TAttributes>;
|
node: NodeWithAttrs<TAttributes>;
|
||||||
editor: Editor;
|
editor: Editor;
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ export function TaskItemComponent(
|
|||||||
opacity: [1, 1, 0],
|
opacity: [1, 1, 0],
|
||||||
alignSelf: "start",
|
alignSelf: "start",
|
||||||
bg: "transparent",
|
bg: "transparent",
|
||||||
mt: "0.36ch",
|
mt: isMobile ? "0.20ch" : "0.36ch",
|
||||||
cursor: "grab",
|
cursor: "grab",
|
||||||
mx: 1,
|
mx: 1,
|
||||||
fontFamily: "inherit"
|
fontFamily: "inherit"
|
||||||
@@ -104,7 +104,7 @@ export function TaskItemComponent(
|
|||||||
borderRadius: "default",
|
borderRadius: "default",
|
||||||
alignSelf: "start",
|
alignSelf: "start",
|
||||||
p: "1px",
|
p: "1px",
|
||||||
mt: "0.40ch",
|
mt: isMobile ? "0.20ch" : "0.36ch",
|
||||||
marginInlineEnd: 1,
|
marginInlineEnd: 1,
|
||||||
cursor: editor.isEditable ? "pointer" : "unset",
|
cursor: editor.isEditable ? "pointer" : "unset",
|
||||||
":hover": isMobile
|
":hover": isMobile
|
||||||
@@ -137,13 +137,6 @@ export function TaskItemComponent(
|
|||||||
textDecorationLine: checked ? "line-through" : "none",
|
textDecorationLine: checked ? "line-through" : "none",
|
||||||
opacity: checked ? 0.8 : 1
|
opacity: checked ? 0.8 : 1
|
||||||
},
|
},
|
||||||
// FIXME: this is quite fragile and will break if the structure
|
|
||||||
// changes. We should probably find a better & more robust
|
|
||||||
// solution for this.
|
|
||||||
"> .taskitem-content-wrapper > p:hover ~ div > div.task-list-tools .toggleSublist":
|
|
||||||
{
|
|
||||||
opacity: 1
|
|
||||||
},
|
|
||||||
flex: 1,
|
flex: 1,
|
||||||
mt: ["3px", "3px", 0],
|
mt: ["3px", "3px", 0],
|
||||||
ml: ["2px", "2px", 0]
|
ml: ["2px", "2px", 0]
|
||||||
|
|||||||
@@ -32,15 +32,18 @@ export function TaskListComponent(
|
|||||||
props: ReactNodeViewProps<TaskListAttributes>
|
props: ReactNodeViewProps<TaskListAttributes>
|
||||||
) {
|
) {
|
||||||
// const isMobile = useIsMobile();
|
// const isMobile = useIsMobile();
|
||||||
const { editor, getPos, node, updateAttributes, forwardRef } = props;
|
const { editor, getPos, node, updateAttributes, forwardRef, pos } = props;
|
||||||
const taskItemType = getNodeType(TaskItemNode.name, editor.schema);
|
const taskItemType = getNodeType(TaskItemNode.name, editor.schema);
|
||||||
const { title, textDirection } = node.attrs;
|
const { title, textDirection } = node.attrs;
|
||||||
const [stats, setStats] = useState({ checked: 0, total: 0, percentage: 0 });
|
const [stats, setStats] = useState({ checked: 0, total: 0, percentage: 0 });
|
||||||
|
|
||||||
const getParent = useCallback(() => {
|
const getParent = useCallback(() => {
|
||||||
const pos = editor.state.doc.resolve(getPos());
|
if (pos === undefined) return;
|
||||||
return findParentNodeOfTypeClosestToPos(pos, taskItemType);
|
return findParentNodeOfTypeClosestToPos(
|
||||||
}, [editor.state.doc, getPos, taskItemType]);
|
editor.state.doc.resolve(pos),
|
||||||
|
taskItemType
|
||||||
|
);
|
||||||
|
}, [editor.state.doc, pos, taskItemType]);
|
||||||
|
|
||||||
const isNested = useMemo(() => {
|
const isNested = useMemo(() => {
|
||||||
return !!getParent();
|
return !!getParent();
|
||||||
|
|||||||
Reference in New Issue
Block a user