Skip to content

Commit

Permalink
Revert "Merge pull request #42 from toeverything/feat/sub-page"
Browse files Browse the repository at this point in the history
This reverts commit cf6491f, reversing
changes made to e12deb3.
  • Loading branch information
darkskygit committed Aug 5, 2022
1 parent cf6491f commit ecc7080
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 164 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const AddCard = ({ group }: { group: KanbanGroup }) => {
const { addCard } = useKanban();
const handleClick = useCallback(async () => {
await addCard(group);
}, [addCard, group]);
}, [addCard]);
return <AddCardWrapper onClick={handleClick}>+</AddCardWrapper>;
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import type { KanbanCard } from '@toeverything/components/editor-core';
import {
RenderBlock,
useKanban,
useRefPage,
} from '@toeverything/components/editor-core';
import { RenderBlock, useKanban } from '@toeverything/components/editor-core';
import { styled } from '@toeverything/components/ui';
import { useFlag } from '@toeverything/datasource/feature-flags';

const CardContent = styled('div')({
margin: '20px',
Expand Down Expand Up @@ -63,24 +58,18 @@ export const CardItem = ({
block: KanbanCard['block'];
}) => {
const { addSubItem } = useKanban();
const { openSubPage } = useRefPage();
const showKanbanRefPageFlag = useFlag('ShowKanbanRefPage', false);
const onAddItem = async () => {
await addSubItem(block);
};

const onClickCard = async () => {
showKanbanRefPageFlag && openSubPage(id);
};

return (
<CardContainer onClick={onClickCard}>
<CardContainer>
<CardContent>
<RenderBlock blockId={id} />
</CardContent>
<CardActions onClick={onAddItem}>
<PlusIcon />
<span>Add a sub-block</span>
<span>Add item</span>
</CardActions>
</CardContainer>
);
Expand Down
6 changes: 3 additions & 3 deletions libs/components/editor-core/src/RenderRoot.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { BlockEditor } from './editor';
import { styled, usePatchNodes } from '@toeverything/components/ui';
import type { FC, PropsWithChildren } from 'react';
import React, { useEffect, useRef, useState, useCallback } from 'react';
import { EditorProvider } from './Contexts';
import { RootContext } from './contexts';
import { SelectionRect, SelectionRef } from './Selection';
import {
Protocol,
Expand Down Expand Up @@ -151,7 +151,7 @@ export const RenderRoot: FC<PropsWithChildren<RenderRootProps>> = ({
};

return (
<EditorProvider value={{ editor, editorElement }}>
<RootContext.Provider value={{ editor, editorElement }}>
<Container
isWhiteboard={editor.isWhiteboard}
ref={ref => {
Expand Down Expand Up @@ -183,7 +183,7 @@ export const RenderRoot: FC<PropsWithChildren<RenderRootProps>> = ({
{editor.isWhiteboard ? null : <ScrollBlank editor={editor} />}
{patchedNodes}
</Container>
</EditorProvider>
</RootContext.Provider>
);
};

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { createContext, useContext } from 'react';
import type { BlockEditor, AsyncBlock } from './editor';
import type { Column } from '@toeverything/datasource/db-service';
import { genErrorObj } from '@toeverything/utils';

const RootContext = createContext<{
export const RootContext = createContext<{
editor: BlockEditor;
// TODO: Temporary fix, dependencies in the new architecture are bottom-up, editors do not need to be passed down from the top
editorElement: () => JSX.Element;
Expand All @@ -13,8 +14,6 @@ const RootContext = createContext<{
) as any
);

export const EditorProvider = RootContext.Provider;

export const useEditor = () => {
return useContext(RootContext);
};
Expand All @@ -23,3 +22,16 @@ export const useEditor = () => {
* @deprecated
*/
export const BlockContext = createContext<AsyncBlock>(null as any);

/**
* Context of column information
*
* @deprecated
*/
export const ColumnsContext = createContext<{
fromId: string;
columns: Column[];
}>({
fromId: '',
columns: [],
});
20 changes: 10 additions & 10 deletions libs/components/editor-core/src/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { noop, Point } from '@toeverything/utils';
import { useCallback, useEffect, useRef, useState } from 'react';
import { useEditor } from './Contexts';
import {
AsyncBlock,
BlockEditor,
SelectEventTypes,
SelectionInfo,
SelectionSettingsMap,
} from './editor';
import { noop, Point } from '@toeverything/utils';
import { useCallback, useContext, useEffect, useRef, useState } from 'react';
import { RootContext } from './contexts';

function useRequestReRender() {
const [, setUpdateCounter] = useState(0);
Expand Down Expand Up @@ -56,7 +56,7 @@ function useRequestReRender() {
export const useBlock = (blockId: string) => {
const [block, setBlock] = useState<AsyncBlock>();
const requestReRender = useRequestReRender();
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
if (!blockId) {
return undefined;
Expand Down Expand Up @@ -95,7 +95,7 @@ export const useOnSelect = (
blockId: string,
cb: (isSelect: boolean) => void
) => {
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
editor.selectionManager.observe(blockId, SelectEventTypes.onSelect, cb);
return () => {
Expand All @@ -117,7 +117,7 @@ export const useOnSelectActive = (
blockId: string,
cb: (position: Point | undefined) => void
) => {
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
editor.selectionManager.observe(blockId, SelectEventTypes.active, cb);
return () => {
Expand All @@ -139,7 +139,7 @@ export const useOnSelectSetSelection = <T extends keyof SelectionSettingsMap>(
blockId: string,
cb: (args: SelectionSettingsMap[T]) => void
) => {
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
editor.selectionManager.observe(
blockId,
Expand All @@ -162,7 +162,7 @@ export const useOnSelectSetSelection = <T extends keyof SelectionSettingsMap>(
* @export
*/
export const useOnSelectChange = (cb: (info: SelectionInfo) => void) => {
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
editor.selectionManager.onSelectionChange(cb);
return () => {
Expand All @@ -177,7 +177,7 @@ export const useOnSelectChange = (cb: (info: SelectionInfo) => void) => {
* @export
*/
export const useOnSelectEnd = (cb: (info: SelectionInfo) => void) => {
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
editor.selectionManager.onSelectEnd(cb);
return () => {
Expand All @@ -195,7 +195,7 @@ export const useOnSelectStartWith = (
blockId: string,
cb: (args: MouseEvent) => void
) => {
const { editor } = useEditor();
const { editor } = useContext(RootContext);
useEffect(() => {
editor.mouseManager.onSelectStartWith(blockId, cb);
return () => {
Expand Down
3 changes: 1 addition & 2 deletions libs/components/editor-core/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { ColumnsContext, RootContext } from './contexts';
export { RenderRoot, MIN_PAGE_WIDTH } from './RenderRoot';
export * from './render-block';
export * from './hooks';
Expand All @@ -15,5 +16,3 @@ export * from './kanban/types';
export * from './utils';

export * from './editor';

export { RefPageProvider, useRefPage } from './ref-page';
2 changes: 1 addition & 1 deletion libs/components/editor-core/src/kanban/kanban.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Protocol } from '@toeverything/datasource/db-service';
import { useCallback, useContext, useEffect, useState } from 'react';
import { useEditor } from '../Contexts';
import { useEditor } from '../contexts';
import { AsyncBlock } from '../editor';
import { useRecastView } from '../recast-block';
import { useRecastBlock } from '../recast-block/Context';
Expand Down
5 changes: 2 additions & 3 deletions libs/components/editor-core/src/recast-block/Context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Protocol } from '@toeverything/datasource/db-service';
import { AsyncBlock } from '../editor';
import { ComponentType, createContext, ReactNode, useContext } from 'react';
import { RecastBlock } from './types';
import { RefPageProvider } from '../ref-page';

/**
* Determine whether the block supports RecastBlock
Expand Down Expand Up @@ -48,7 +47,7 @@ export const RecastBlockProvider = ({

return (
<RecastBlockContext.Provider value={block}>
<RefPageProvider>{children}</RefPageProvider>
{children}
</RecastBlockContext.Provider>
);
};
Expand All @@ -61,7 +60,7 @@ export const useRecastBlock = () => {
const recastBlock = useContext(RecastBlockContext);
if (!recastBlock) {
throw new Error(
'Failed to find recastBlock! Please use the hook under `RecastBlockProvider`.'
'Failed to find recastBlock! Please use the hook under `RecastTableProvider`.'
);
}
return recastBlock;
Expand Down
19 changes: 19 additions & 0 deletions libs/components/editor-core/src/recast-block/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,22 @@ const SomeBlock = () => {
return <div>...</div>;
};
```
## Scene
**Notice: The scene API will refactor at next version.**
```tsx
const SomeBlock = () => {
const { scene, setScene, setPage, setTable, setKanban } =
useRecastBlockScene();

return (
<>
<div>Scene: {scene}</div>
<button onClick={setPage}>list</button>
<button onClick={setKanban}>kanban</button>
</>
);
};
```
4 changes: 2 additions & 2 deletions libs/components/editor-core/src/recast-block/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const mergeGroup = async (...groups: AsyncBlock[]) => {
);
}

await mergeGroupProperties(...(groups as unknown as RecastBlock[]));
await mergeGroupProperties(...(groups as RecastBlock[]));

const [headGroup, ...restGroups] = groups;
// Add all children to the head group
Expand Down Expand Up @@ -174,7 +174,7 @@ export const splitGroup = async (
}

splitGroupProperties(
group as unknown as RecastBlock,
group as RecastBlock,
newGroupBlock as unknown as RecastBlock
);
await group.after(newGroupBlock);
Expand Down
90 changes: 0 additions & 90 deletions libs/components/editor-core/src/ref-page/ModalPage.tsx

This file was deleted.

1 change: 0 additions & 1 deletion libs/components/editor-core/src/ref-page/index.ts

This file was deleted.

8 changes: 4 additions & 4 deletions libs/components/editor-core/src/render-block/RenderBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { styled } from '@toeverything/components/ui';
import { FC, useLayoutEffect, useMemo, useRef } from 'react';
import { styled, Theme } from '@toeverything/components/ui';
import { FC, useContext, useLayoutEffect, useMemo, useRef } from 'react';

// import { RenderChildren } from './RenderChildren';
import { useEditor } from '../Contexts';
import { RootContext } from '../contexts';
import { useBlock } from '../hooks';

interface RenderBlockProps {
Expand All @@ -14,7 +14,7 @@ export const RenderBlock: FC<RenderBlockProps> = ({
blockId,
hasContainer = true,
}) => {
const { editor, editorElement } = useEditor();
const { editor, editorElement } = useContext(RootContext);
const { block } = useBlock(blockId);
const blockRef = useRef<HTMLDivElement>(null);

Expand Down
Loading

0 comments on commit ecc7080

Please sign in to comment.