a tool for shared writing and social publishing
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix block command button grouping

+18 -60
+15 -57
components/Blocks/TextBlock/index.tsx
··· 52 52 import { TooltipButton } from "components/Buttons"; 53 53 import { v7 } from "uuid"; 54 54 import { focusPage } from "components/Pages"; 55 + import { blockCommands } from "../BlockCommands"; 55 56 56 57 export function TextBlock( 57 58 props: BlockProps & { className?: string; preview?: boolean }, ··· 406 407 <TooltipButton 407 408 className={props.className} 408 409 onMouseDown={async () => { 409 - let entity; 410 - if (!props.entityID) { 411 - entity = v7(); 412 - await rep.rep?.mutate.addBlock({ 413 - parent: props.parent, 414 - factID: v7(), 415 - permission_set: entity_set.set, 416 - type: "image", 417 - position: generateKeyBetween( 418 - props.position, 419 - props.nextPosition, 420 - ), 421 - newEntityID: entity, 422 - }); 423 - } else { 424 - entity = props.entityID; 425 - await rep.rep?.mutate.assertFact({ 426 - entity, 427 - attribute: "block/type", 428 - data: { type: "block-type-union", value: "image" }, 429 - }); 430 - } 431 - return entity; 410 + let command = blockCommands.find((f) => f.name === "Image"); 411 + if (!rep.rep) return; 412 + await command?.onSelect( 413 + rep.rep, 414 + { ...props, entity_set: entity_set.set }, 415 + rep.undoManager, 416 + ); 432 417 }} 433 418 side="bottom" 434 419 tooltipContent={ ··· 441 426 <TooltipButton 442 427 className={props.className} 443 428 onMouseDown={async () => { 444 - let entity; 445 - if (!props.entityID) { 446 - entity = v7(); 447 - await rep.rep?.mutate.addBlock({ 448 - parent: props.parent, 449 - factID: v7(), 450 - permission_set: entity_set.set, 451 - type: "card", 452 - position: generateKeyBetween( 453 - props.position, 454 - props.nextPosition, 455 - ), 456 - newEntityID: entity, 457 - }); 458 - } else { 459 - entity = props.entityID; 460 - await rep.rep?.mutate.assertFact({ 461 - entity, 462 - attribute: "block/type", 463 - data: { type: "block-type-union", value: "card" }, 464 - }); 465 - } 466 - 467 - let newPage = v7(); 468 - await rep.rep?.mutate.addPageLinkBlock({ 469 - blockEntity: entity, 470 - firstBlockFactID: v7(), 471 - firstBlockEntity: v7(), 472 - pageEntity: newPage, 473 - type: "doc", 474 - permission_set: entity_set.set, 475 - }); 476 - useUIState.getState().openPage(props.parent, newPage); 477 - rep.rep && focusPage(newPage, rep.rep, "focusFirstBlock"); 429 + let command = blockCommands.find((f) => f.name === "New Page"); 430 + if (!rep.rep) return; 431 + await command?.onSelect( 432 + rep.rep, 433 + { ...props, entity_set: entity_set.set }, 434 + rep.undoManager, 435 + ); 478 436 }} 479 437 side="bottom" 480 438 tooltipContent={
+3 -3
components/Buttons.tsx
··· 145 145 }; 146 146 147 147 export const TooltipButton = (props: { 148 - onMouseDown?: (e: React.MouseEvent) => void; 148 + onMouseDown?: (e: React.MouseEvent) => void | Promise<void>; 149 149 disabled?: boolean; 150 150 className?: string; 151 151 children: React.ReactNode; ··· 165 165 <RadixTooltip.Trigger 166 166 disabled={props.disabled} 167 167 className={props.className} 168 - onMouseDown={(e) => { 168 + onMouseDown={async (e) => { 169 169 e.preventDefault(); 170 170 undoManager.startGroup(); 171 - props.onMouseDown && props.onMouseDown(e); 171 + props.onMouseDown && (await props.onMouseDown(e)); 172 172 undoManager.endGroup(); 173 173 }} 174 174 >