Last active
August 18, 2022 12:39
-
-
Save diegohaz/c48c82775c0ac36fda45987e73e9787c to your computer and use it in GitHub Desktop.
Revisions
-
diegohaz revised this gist
May 29, 2021 . 1 changed file with 3 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -44,14 +44,15 @@ const Link = createBlock<LinkProps>((props) => { }); const ListItem = createBlock((props) => { const { value, insertBlock, removeBlock } = useEditorState(props); useEnter((defaultAction) => { if (value.length) { insertBlock("ListItem"); } else { removeBlock(props.id); defaultAction(); } }, [value, insertBlock, removeBlock, props.id]); return <Text as="li" {...props} />; }); -
diegohaz revised this gist
May 29, 2021 . 1 changed file with 1 addition and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,8 +11,7 @@ const Link = createBlock<LinkProps>((props) => { useEffect(() => { return onSelectionChange((selection) => { if (selection.startContainerIds.includes(props.id) && selection.endContainerIds.includes(props.id)) { popover.show(); } }); -
diegohaz revised this gist
May 29, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -11,6 +11,7 @@ const Link = createBlock<LinkProps>((props) => { useEffect(() => { return onSelectionChange((selection) => { // Check parents if (selection.startContainerId === props.id || selection.endContainerId === props.id) { popover.show(); } -
diegohaz revised this gist
May 29, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -28,7 +28,7 @@ const Link = createBlock<LinkProps>((props) => { props.onClick?.(event); if (event.defaultPrevented) return; event.preventDefault(); selectBlockConents(props.id); }} > {(disclosureProps) => ( -
diegohaz revised this gist
May 29, 2021 . 1 changed file with 25 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,19 +1,41 @@ type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement>; const Link = createBlock<LinkProps>((props) => { const { onSelectionChange, selectBlockContents } = useEditorState(props); const popover = usePopoverState({ portal: true }); const [href, setHref] = useState(props.href); useEffect(() => { setHref(props.href); }, [props.href]); useEffect(() => { return onSelectionChange((selection) => { if (selection.startContainerId === props.id || selection.endContainerId === props.id) { popover.show(); } }); }, [onSelect, props.id, popover.show]); return ( <> <PopoverDisclosure as="a" state={popover} {...props} href={href} onClick={(event) => { props.onClick?.(event); if (event.defaultPrevented) return; event.preventDefault(); popover.selectBlockConents(); }} > {(disclosureProps) => ( <Text as="a" {...disclosureProps} /> )} </PopoverDisclosure> <Popover autoFocusOnShow={false} state={popover}> <a href={href} /> <button>Edit</button> </Popover> -
diegohaz revised this gist
May 29, 2021 . 1 changed file with 35 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,38 @@ type LinkProps = AnchorHTMLAttributes<HTMLAnchorElement>; const Link = createBlock<LinkProps>((props) => { const popover = usePopoverState(); const [href, setHref] = useState(props.href); useEffect(() => { setHref(props.href); }, [props.href]); return ( <> <PopoverDisclosure as="a" state={state} {...props} href={href}> {(disclosureProps) => ( <Text as="a" {...disclosureProps} /> )} </PopoverDisclosure> <Popover state={state}> <a href={href} /> <button>Edit</button> </Popover> </> ); }); const ListItem = createBlock((props) => { const { value, insertBlock } = useEditorState(props); useEnter((defaultAction) => { if (value.length) { insertBlock("ListItem"); } else { defaultAction(); } }, [value, insertBlock]); return <Text as="li" {...props} />; }); const ListItem = createEditorComponent((props) => { const editor = useEditorState(props); useEditorEnter(() => { -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 8 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -13,7 +13,13 @@ type ListProps = { }; const List = createEditorComponent<ListProps>((props) => { const editor = useEditorState({ ...props, defaultValue: [{ type: "ListItem", id: `${props.id}-1`, }], }); const type = useEditorInput( ToggleGroup, { @@ -27,6 +33,7 @@ const List = createEditorComponent<ListProps>((props) => { ); const component = type === "ordered" ? "ol" : "ul"; // if defaultValue doesn't work useLayoutEffect(() => { if (!editor.value.length) { const selection = { -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,4 +1,8 @@ const ListItem = createEditorComponent((props) => { const editor = useEditorState(props); useEditorEnter(() => { editor.insertElement("ListItem"); }, [editor.insertElement]); return <Text as="li" {...props} />; }); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 43 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,43 @@ const ListItem = createEditorComponent((props) => { return <Text as="li" {...props} />; }); type ListProps = { inputs: { type: "ordered" | "unordered"; }; }; const List = createEditorComponent<ListProps>((props) => { const editor = useEditorState(props); const type = useEditorInput( ToggleGroup, { ...props, name: "type", options: [ { value: "ordered", label: "Ordered", icon: "Ordered" }, { value: "unordered", label: "Unordered", icon: "Unordered" }, ], } ); const component = type === "ordered" ? "ol" : "ul"; useLayoutEffect(() => { if (!editor.value.length) { const selection = { startContainerId: props.id, startOffset: 0, endContainerId: props.id, endOffset: 0, }; editor.insertElement("ListItem", null, selection); } }, [editor.insertElement, editor.value, props.id]); return <EditorComponent as={component} {...props} />; }); type HeadingProps = TextProps & { inputs: { level?: number; @@ -8,7 +48,9 @@ const Heading = createEditorComponent<HeadingProps>((props) => { const level = useEditorInput(HeadingLevel, { ...props, name: "level", label: "Heading level" }); const component = `h${level}`; useEditorReplace("Paragraph"); return <Text as={component} {...props} />; }); Heading.defaultProps = { -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,7 +39,7 @@ const defaultComponents = { function App() { const editor = useEditorState({ defaultComponents }); editor.getSelection(); // { startContainerId: "id", startOffset: 0, endContainerId: "id", endOffset: 3, collapsed: false } editor.insertElement("Paragraph", null, editor.getSelection()); editor.insertElement(Heading, { inputs: { level: 2 } }); editor.replaceElement(Paragraph); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 1 addition and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,6 +39,7 @@ const defaultComponents = { function App() { const editor = useEditorState({ defaultComponents }); editor.getSelection(); // { containerId: "id", offset: 0, startContainerId: "id", startOffset: 0, endContainerId: "id", endOffset: 3 } editor.insertElement("Paragraph", null, editor.getSelection()); editor.insertElement(Heading, { inputs: { level: 2 } }); editor.replaceElement(Paragraph); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -39,5 +39,8 @@ const defaultComponents = { function App() { const editor = useEditorState({ defaultComponents }); editor.insertElement("Paragraph", null, editor.getSelection()); editor.insertElement(Heading, { inputs: { level: 2 } }); editor.replaceElement(Paragraph); return <Editor state={editor} />; } -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -26,7 +26,7 @@ Heading.triggers = { }; const HeadingLevel = createEditorInput<HeadingProps>((props) => { useEditorInputValue(props, "value"); return <div />; }); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 0 additions and 11 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,14 +1,3 @@ type HeadingProps = TextProps & { inputs: { level?: number; -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 14 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -37,6 +37,18 @@ Heading.triggers = { }; const HeadingLevel = createEditorInput<HeadingProps>((props) => { const [value, setValue] = useEditorInputState(props); return <div />; }); const defaultComponents = { Paragraph, Bold, Heading, ... }; function App() { const editor = useEditorState({ defaultComponents }); return <Editor state={editor} />; } -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -16,7 +16,7 @@ type HeadingProps = TextProps & { }; const Heading = createEditorComponent<HeadingProps>((props) => { const level = useEditorInput(HeadingLevel, { ...props, name: "level", label: "Heading level" }); const component = `h${level}`; return <Text {...props} as={component} />; -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 4 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,8 +22,10 @@ const Heading = createEditorComponent<HeadingProps>((props) => { return <Text {...props} as={component} />; }); Heading.defaultProps = { inputs: { level: 1, }, }; Heading.triggers = { -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 4 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -22,6 +22,10 @@ const Heading = createEditorComponent<HeadingProps>((props) => { return <Text {...props} as={component} />; }); Heading.defaultInputs = { level: 1, }; Heading.triggers = { "#{1,6}": (text) => ({ inputs: { -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 2 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,6 +2,7 @@ import { createEditorComponent, createEditorInput, useEditorInput, useEditorInputValue, } from "editor"; import { Text, @@ -30,5 +31,6 @@ Heading.triggers = { }; const HeadingLevel = createEditorInput<HeadingProps>((props) => { useEditorInputValue(props, ""); ... }); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 4 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ import { createEditorComponent, createEditorInput, useEditorInput, } from "editor"; import { Text, @@ -14,7 +15,7 @@ type HeadingProps = TextProps & { }; const Heading = createEditorComponent<HeadingProps>((props) => { const level = useEditorInput("HeadingLevel", { ...props, name: "level", label: "Heading level" }); const component = `h${level}`; return <Text {...props} as={component} />; @@ -28,6 +29,6 @@ Heading.triggers = { }); }; const HeadingLevel = createEditorInput<HeadingProps>((props) => { ... }); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 7 additions and 6 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,7 +1,6 @@ import { createEditorComponent, createEditorInput, } from "editor"; import { Text, @@ -18,14 +17,16 @@ const Heading = createEditorComponent<HeadingProps>((props) => { const level = useHeadingLevelInput({ ...props, name: "level", label: "Heading level" }); const component = `h${level}`; return <Text {...props} as={component} />; }); Heading.triggers = { "#{1,6}": (text) => ({ inputs: { level: text.length, }, }); }; const useHeadingLevelInput = createEditorInput<HeadingProps>((props) => { useInputRender(() => <input />, []); -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 3 additions and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -2,9 +2,11 @@ import { createEditorComponent, createEditorInput, useTrigger, } from "editor"; import { Text, TextProps, } from "editor/components"; type HeadingProps = TextProps & { inputs: { -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 8 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,7 @@ import { createEditorComponent, createEditorInput, useTrigger, Text, TextProps, } from "editor"; @@ -14,6 +15,13 @@ type HeadingProps = TextProps & { const Heading = createEditorComponent<HeadingProps>((props) => { const level = useHeadingLevelInput({ ...props, name: "level", label: "Heading level" }); const component = `h${level}`; useTrigger("#{1,6}", (text) => ({ inputs: { level: text.length, }, })); return <Text {...props} as={component} />; }); -
diegohaz renamed this gist
May 28, 2021 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
diegohaz revised this gist
May 28, 2021 . 1 changed file with 21 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,22 @@ import { createEditorComponent, createEditorInput, Text, TextProps, } from "editor"; type HeadingProps = TextProps & { inputs: { level?: number; }; }; const Heading = createEditorComponent<HeadingProps>((props) => { const level = useHeadingLevelInput({ ...props, name: "level", label: "Heading level" }); const component = `h${level}`; return <Text {...props} as={component} />; }); const useHeadingLevelInput = createEditorInput<HeadingProps>((props) => { useInputRender(() => <input />, []); }); -
diegohaz created this gist
May 28, 2021 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,3 @@ import { createEditorComponent } from "editor";