mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
rename NodeComponentProps
This commit is contained in:
parent
8553f91429
commit
65196bbbbb
15 changed files with 59 additions and 45 deletions
|
@ -1,43 +1,56 @@
|
|||
import { createElement, FC, useCallback, useMemo } from 'react';
|
||||
|
||||
import { INodeComponentProps, LAB_PREVIEW_LAYOUT, NODE_COMPONENTS, NODE_HEADS, NODE_INLINES } from '~/constants/node';
|
||||
import {
|
||||
NodeComponentProps,
|
||||
LAB_PREVIEW_LAYOUT,
|
||||
NODE_COMPONENTS,
|
||||
NODE_HEADS,
|
||||
NODE_INLINES,
|
||||
} from '~/constants/node';
|
||||
import { INode } from '~/types';
|
||||
import { isNil, prop } from '~/utils/ramda';
|
||||
|
||||
// useNodeBlocks returns head, block and inline blocks of node
|
||||
export const useNodeBlocks = (node: INode, isLoading: boolean) => {
|
||||
const createNodeBlock = useCallback(
|
||||
(block?: FC<INodeComponentProps>, key = 0) =>
|
||||
(block?: FC<NodeComponentProps>, key = 0) =>
|
||||
!isNil(block) &&
|
||||
createElement(block, {
|
||||
node,
|
||||
isLoading,
|
||||
key: `${node.id}-${key}`,
|
||||
}),
|
||||
[node, isLoading]
|
||||
[node, isLoading],
|
||||
);
|
||||
|
||||
const head = useMemo(
|
||||
() => createNodeBlock(node?.type ? prop(node?.type, NODE_HEADS) : undefined),
|
||||
[node, createNodeBlock]
|
||||
() =>
|
||||
createNodeBlock(node?.type ? prop(node?.type, NODE_HEADS) : undefined),
|
||||
[node, createNodeBlock],
|
||||
);
|
||||
|
||||
const block = useMemo(
|
||||
() => createNodeBlock(node?.type ? prop(node?.type, NODE_COMPONENTS) : undefined),
|
||||
[node, createNodeBlock]
|
||||
() =>
|
||||
createNodeBlock(
|
||||
node?.type ? prop(node?.type, NODE_COMPONENTS) : undefined,
|
||||
),
|
||||
[node, createNodeBlock],
|
||||
);
|
||||
|
||||
const inline = useMemo(
|
||||
() => createNodeBlock(node?.type ? prop(node?.type, NODE_INLINES) : undefined),
|
||||
[node, createNodeBlock]
|
||||
() =>
|
||||
createNodeBlock(node?.type ? prop(node?.type, NODE_INLINES) : undefined),
|
||||
[node, createNodeBlock],
|
||||
);
|
||||
|
||||
const lab = useMemo(
|
||||
() =>
|
||||
node?.type && prop(node.type, LAB_PREVIEW_LAYOUT)
|
||||
? prop(node.type, LAB_PREVIEW_LAYOUT).map((comp, i) => createNodeBlock(comp, i))
|
||||
? prop(node.type, LAB_PREVIEW_LAYOUT).map((comp, i) =>
|
||||
createNodeBlock(comp, i),
|
||||
)
|
||||
: undefined,
|
||||
[node, createNodeBlock]
|
||||
[node, createNodeBlock],
|
||||
);
|
||||
|
||||
return { head, block, inline, lab };
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue