Merge remote-tracking branch 'origin/develop' into fix/experience

This commit is contained in:
DarkSky
2022-08-24 19:17:53 +08:00
122 changed files with 2333 additions and 1537 deletions
+6 -4
View File
@@ -22,7 +22,6 @@ const AffineBoard = ({
editor,
}: AffineBoardProps & { editor: BlockEditor }) => {
const [app, set_app] = useState<TldrawApp>();
const [document] = useState(() => {
return {
...deepCopy(TldrawApp.default_document),
@@ -49,7 +48,7 @@ const AffineBoard = ({
};
});
const shapes = useShapes(workspace, rootBlockId);
const { shapes } = useShapes(workspace, rootBlockId);
useEffect(() => {
if (app) {
app.replacePageContent(shapes || {}, {}, {});
@@ -66,6 +65,9 @@ const AffineBoard = ({
onMount(app) {
set_app(app);
},
async onPaste(e, data) {
console.log('e,data: ', e, data);
},
async onCopy(e, groupIds) {
const clip =
await editor.clipboard.clipboardUtils.getClipDataOfBlocksById(
@@ -77,7 +79,7 @@ const AffineBoard = ({
clip.getData()
);
},
onChangePage(app, shapes, bindings, assets) {
async onChangePage(app, shapes, bindings, assets) {
Promise.all(
Object.entries(shapes).map(async ([id, shape]) => {
if (shape === undefined) {
@@ -106,7 +108,7 @@ const AffineBoard = ({
});
}
shape.affineId = block.id;
return services.api.editorBlock.update({
return await services.api.editorBlock.update({
workspace: shape.workspace,
id: block.id,
properties: {
@@ -9,28 +9,37 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
const { pageClientWidth } = usePageClientWidth();
// page padding left and right total 300px
const editorShapeInitSize = pageClientWidth - 300;
const [blocks, setBlocks] = useState<ReturnEditorBlock[]>();
const [blocks, setBlocks] = useState<{
shapes: [ReturnEditorBlock[]];
}>();
useEffect(() => {
services.api.editorBlock
.get({ workspace, ids: [rootBlockId] })
.then(async blockData => {
const shapes = await Promise.all(
(blockData?.[0]?.children || []).map(async childId => {
const childBlock = (
await services.api.editorBlock.get({
workspace,
ids: [childId],
})
)?.[0];
return childBlock;
})
);
setBlocks(shapes);
Promise.all([
services.api.editorBlock
.get({ workspace, ids: [rootBlockId] })
.then(async blockData => {
const shapes = await Promise.all(
(blockData?.[0]?.children || []).map(async childId => {
const childBlock = (
await services.api.editorBlock.get({
workspace,
ids: [childId],
})
)?.[0];
return childBlock;
})
);
return shapes;
}),
]).then(shapes => {
setBlocks({
shapes: shapes,
});
});
let unobserve: () => void;
services.api.editorBlock
.observe({ workspace, id: rootBlockId }, async blockData => {
const shapes = await Promise.all(
Promise.all(
(blockData?.children || []).map(async childId => {
const childBlock = (
await services.api.editorBlock.get({
@@ -40,8 +49,11 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
)?.[0];
return childBlock;
})
);
setBlocks(shapes);
).then(shapes => {
setBlocks({
shapes: [shapes],
});
});
})
.then(cb => {
unobserve = cb;
@@ -53,8 +65,7 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
}, [workspace, rootBlockId]);
let groupCount = 0;
return blocks?.reduce((acc, block) => {
let blocksShapes = blocks?.shapes[0]?.reduce((acc, block) => {
const shapeProps = block.properties.shapeProps?.value
? JSON.parse(block.properties.shapeProps.value)
: {};
@@ -75,4 +86,8 @@ export const useShapes = (workspace: string, rootBlockId: string) => {
return acc;
}, {} as Record<string, TDShape>);
return {
shapes: blocksShapes,
};
};