@blocknote/core 0.1.2 → 0.2.1-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/README.md +12 -6
  2. package/dist/blocknote.js +1425 -5109
  3. package/dist/blocknote.js.map +1 -1
  4. package/dist/blocknote.umd.cjs +1 -53
  5. package/dist/blocknote.umd.cjs.map +1 -1
  6. package/dist/style.css +1 -1
  7. package/package.json +19 -32
  8. package/src/BlockNoteEditor.ts +54 -0
  9. package/src/BlockNoteExtensions.ts +52 -7
  10. package/src/assets/fonts-inter.css +92 -0
  11. package/src/editor.module.css +37 -0
  12. package/src/extensions/Blocks/BlockAttributes.ts +1 -3
  13. package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +71 -18
  14. package/src/extensions/Blocks/helpers/getBlockInfoFromPos.ts +66 -0
  15. package/src/extensions/Blocks/index.ts +7 -3
  16. package/src/extensions/Blocks/nodes/Block.module.css +116 -74
  17. package/src/extensions/Blocks/nodes/Block.ts +413 -292
  18. package/src/extensions/Blocks/nodes/BlockGroup.ts +6 -6
  19. package/src/extensions/Blocks/nodes/BlockTypes/HeadingBlock/HeadingContent.ts +84 -0
  20. package/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.ts +177 -0
  21. package/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.ts +77 -0
  22. package/src/extensions/Blocks/nodes/BlockTypes/TextBlock/TextContent.ts +34 -0
  23. package/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.ts +20 -0
  24. package/src/extensions/DraggableBlocks/DraggableBlocksExtension.ts +27 -9
  25. package/src/extensions/DraggableBlocks/{DraggableBlocksPlugin.tsx → DraggableBlocksPlugin.ts} +227 -147
  26. package/src/extensions/FormattingToolbar/FormattingToolbarExtension.ts +29 -0
  27. package/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.ts +35 -0
  28. package/src/extensions/FormattingToolbar/FormattingToolbarPlugin.ts +308 -0
  29. package/src/extensions/HyperlinkToolbar/HyperlinkMark.ts +28 -0
  30. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.ts +19 -0
  31. package/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.ts +251 -0
  32. package/src/extensions/Placeholder/PlaceholderExtension.ts +5 -2
  33. package/src/extensions/SlashMenu/SlashMenuExtension.ts +9 -1
  34. package/src/extensions/SlashMenu/SlashMenuItem.ts +1 -3
  35. package/src/extensions/SlashMenu/defaultCommands.tsx +33 -22
  36. package/src/extensions/TrailingNode/TrailingNodeExtension.ts +4 -4
  37. package/src/extensions/UniqueID/UniqueID.ts +14 -1
  38. package/src/index.ts +8 -4
  39. package/src/shared/EditorElement.ts +10 -0
  40. package/src/shared/plugins/suggestion/SuggestionItem.ts +1 -8
  41. package/src/shared/plugins/suggestion/SuggestionPlugin.ts +222 -101
  42. package/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.ts +21 -0
  43. package/src/{utils.ts → shared/utils.ts} +0 -0
  44. package/types/src/BlockNoteEditor.d.ts +13 -0
  45. package/types/src/BlockNoteExtensions.d.ts +12 -1
  46. package/types/src/EditorElement.d.ts +7 -0
  47. package/types/src/extensions/Blocks/PreviousBlockTypePlugin.d.ts +1 -1
  48. package/types/src/extensions/Blocks/helpers/getBlockInfoFromPos.d.ts +19 -0
  49. package/types/src/extensions/Blocks/nodes/Block.d.ts +11 -19
  50. package/types/src/extensions/Blocks/nodes/BlockTypes/HeadingBlock/HeadingContent.d.ts +8 -0
  51. package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/ListItemContent.d.ts +8 -0
  52. package/types/src/extensions/Blocks/nodes/BlockTypes/ListItemBlock/OrderedListItemIndexPlugin.d.ts +2 -0
  53. package/types/src/extensions/Blocks/nodes/BlockTypes/TextBlock/TextContent.d.ts +6 -0
  54. package/types/src/extensions/BubbleMenu/BubbleMenuExtension.d.ts +4 -1
  55. package/types/src/extensions/BubbleMenu/BubbleMenuFactoryTypes.d.ts +27 -0
  56. package/types/src/extensions/BubbleMenu/BubbleMenuPlugin.d.ts +10 -12
  57. package/types/src/extensions/DraggableBlocks/BlockMenuFactoryTypes.d.ts +12 -0
  58. package/types/src/extensions/DraggableBlocks/BlockSideMenuFactoryTypes.d.ts +14 -0
  59. package/types/src/extensions/DraggableBlocks/DragMenuFactoryTypes.d.ts +18 -0
  60. package/types/src/extensions/DraggableBlocks/DraggableBlocksExtension.d.ts +9 -3
  61. package/types/src/extensions/DraggableBlocks/DraggableBlocksPlugin.d.ts +23 -1
  62. package/types/src/extensions/FormattingToolbar/FormattingToolbarExtension.d.ts +8 -0
  63. package/types/src/extensions/FormattingToolbar/FormattingToolbarFactoryTypes.d.ts +23 -0
  64. package/types/src/extensions/FormattingToolbar/FormattingToolbarPlugin.d.ts +43 -0
  65. package/types/src/extensions/HyperlinkToolbar/HyperlinkMark.d.ts +8 -0
  66. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarFactoryTypes.d.ts +12 -0
  67. package/types/src/extensions/HyperlinkToolbar/HyperlinkToolbarPlugin.d.ts +11 -0
  68. package/types/src/extensions/Hyperlinks/HyperlinkMark.d.ts +2 -1
  69. package/types/src/extensions/Hyperlinks/HyperlinkMenuFactoryTypes.d.ts +11 -0
  70. package/types/src/extensions/Hyperlinks/HyperlinkMenuPlugin.d.ts +10 -1
  71. package/types/src/extensions/SlashMenu/SlashMenuExtension.d.ts +3 -1
  72. package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +2 -4
  73. package/types/src/index.d.ts +8 -3
  74. package/types/src/shared/EditorElement.d.ts +6 -0
  75. package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +1 -6
  76. package/types/src/shared/plugins/suggestion/SuggestionPlugin.d.ts +15 -10
  77. package/types/src/shared/plugins/suggestion/SuggestionsMenuFactoryTypes.d.ts +12 -0
  78. package/types/src/shared/utils.d.ts +2 -0
  79. package/types/src/utils.d.ts +2 -2
  80. package/src/BlockNoteTheme.ts +0 -150
  81. package/src/EditorContent.tsx +0 -2
  82. package/src/extensions/Blocks/OrderedListPlugin.ts +0 -46
  83. package/src/extensions/Blocks/commands/joinBackward.ts +0 -274
  84. package/src/extensions/Blocks/helpers/setBlockHeading.ts +0 -30
  85. package/src/extensions/Blocks/nodes/Content.ts +0 -63
  86. package/src/extensions/Blocks/rule.ts +0 -48
  87. package/src/extensions/BubbleMenu/BubbleMenuExtension.tsx +0 -36
  88. package/src/extensions/BubbleMenu/BubbleMenuPlugin.ts +0 -245
  89. package/src/extensions/BubbleMenu/component/BubbleMenu.tsx +0 -240
  90. package/src/extensions/BubbleMenu/component/LinkToolbarButton.tsx +0 -67
  91. package/src/extensions/DraggableBlocks/components/DragHandle.tsx +0 -102
  92. package/src/extensions/DraggableBlocks/components/DragHandleMenu.tsx +0 -19
  93. package/src/extensions/Hyperlinks/HyperlinkMark.tsx +0 -16
  94. package/src/extensions/Hyperlinks/HyperlinkMenuPlugin.tsx +0 -165
  95. package/src/extensions/Hyperlinks/menus/EditHyperlinkMenu.tsx +0 -44
  96. package/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItem.tsx +0 -34
  97. package/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemIcon.tsx +0 -31
  98. package/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemInput.tsx +0 -40
  99. package/src/extensions/Hyperlinks/menus/HoverHyperlinkMenu.tsx +0 -37
  100. package/src/extensions/Hyperlinks/menus/HyperlinkMenu.tsx +0 -63
  101. package/src/fonts-inter.css +0 -94
  102. package/src/globals.css +0 -28
  103. package/src/root.module.css +0 -19
  104. package/src/shared/components/toolbar/Toolbar.tsx +0 -10
  105. package/src/shared/components/toolbar/ToolbarButton.tsx +0 -57
  106. package/src/shared/components/toolbar/ToolbarDropdown.tsx +0 -35
  107. package/src/shared/components/toolbar/ToolbarDropdownItem.tsx +0 -35
  108. package/src/shared/components/toolbar/ToolbarDropdownTarget.tsx +0 -31
  109. package/src/shared/components/tooltip/TooltipContent.module.css +0 -15
  110. package/src/shared/components/tooltip/TooltipContent.tsx +0 -23
  111. package/src/shared/hooks/useEditorForceUpdate.tsx +0 -30
  112. package/src/shared/plugins/suggestion/SuggestionListReactRenderer.tsx +0 -236
  113. package/src/shared/plugins/suggestion/components/SuggestionGroup.tsx +0 -47
  114. package/src/shared/plugins/suggestion/components/SuggestionGroupItem.tsx +0 -82
  115. package/src/shared/plugins/suggestion/components/SuggestionList.tsx +0 -92
  116. package/src/useEditor.ts +0 -51
  117. package/types/src/BlockNoteTheme.d.ts +0 -2
  118. package/types/src/EditorContent.d.ts +0 -1
  119. package/types/src/commands/indentation.d.ts +0 -2
  120. package/types/src/extensions/Blocks/OrderedListPlugin.d.ts +0 -2
  121. package/types/src/extensions/Blocks/commands/joinBackward.d.ts +0 -14
  122. package/types/src/extensions/Blocks/helpers/setBlockHeading.d.ts +0 -5
  123. package/types/src/extensions/Blocks/nodes/Content.d.ts +0 -5
  124. package/types/src/extensions/Blocks/rule.d.ts +0 -16
  125. package/types/src/extensions/BubbleMenu/component/BubbleMenu.d.ts +0 -5
  126. package/types/src/extensions/BubbleMenu/component/DropdownBlockItem.d.ts +0 -10
  127. package/types/src/extensions/BubbleMenu/component/LinkToolbarButton.d.ts +0 -11
  128. package/types/src/extensions/DraggableBlocks/components/DragHandle.d.ts +0 -12
  129. package/types/src/extensions/DraggableBlocks/components/DragHandleMenu.d.ts +0 -6
  130. package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenu.d.ts +0 -11
  131. package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItem.d.ts +0 -13
  132. package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemIcon.d.ts +0 -8
  133. package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemInput.d.ts +0 -9
  134. package/types/src/extensions/Hyperlinks/menus/HoverHyperlinkMenu.d.ts +0 -12
  135. package/types/src/extensions/Hyperlinks/menus/HyperlinkBasicMenu.d.ts +0 -12
  136. package/types/src/extensions/Hyperlinks/menus/HyperlinkEditMenu.d.ts +0 -10
  137. package/types/src/extensions/Hyperlinks/menus/HyperlinkMenu.d.ts +0 -21
  138. package/types/src/extensions/Hyperlinks/menus/atlaskit/PanelTextInput.d.ts +0 -39
  139. package/types/src/extensions/Hyperlinks/menus/atlaskit/PanelTextInputStyles.d.ts +0 -1
  140. package/types/src/extensions/Hyperlinks/menus/atlaskit/ToolbarComponent.d.ts +0 -11
  141. package/types/src/extensions/Hyperlinks/menus/helpers/PanelTextInput.d.ts +0 -39
  142. package/types/src/extensions/Hyperlinks/menus/helpers/PanelTextInputStyles.d.ts +0 -3
  143. package/types/src/extensions/Hyperlinks/menus/helpers/ToolbarComponent.d.ts +0 -13
  144. package/types/src/extensions/helpers/formatKeyboardShortcut.d.ts +0 -1
  145. package/types/src/lib/atlaskit/browser.d.ts +0 -12
  146. package/types/src/nodes/ChildgroupNode.d.ts +0 -28
  147. package/types/src/nodes/patchNodes.d.ts +0 -1
  148. package/types/src/plugins/TreeViewPlugin/index.d.ts +0 -2
  149. package/types/src/plugins/animation.d.ts +0 -2
  150. package/types/src/react/BlockNoteComposer.d.ts +0 -17
  151. package/types/src/react/BlockNotePlugin.d.ts +0 -1
  152. package/types/src/react/index.d.ts +0 -3
  153. package/types/src/react/useBlockNoteSetup.d.ts +0 -2
  154. package/types/src/registerBlockNote.d.ts +0 -2
  155. package/types/src/shared/components/toolbar/SimpleToolbarButton.d.ts +0 -15
  156. package/types/src/shared/components/toolbar/SimpleToolbarDropdown.d.ts +0 -11
  157. package/types/src/shared/components/toolbar/SimpleToolbarDropdownItem.d.ts +0 -11
  158. package/types/src/shared/components/toolbar/Toolbar.d.ts +0 -4
  159. package/types/src/shared/components/toolbar/ToolbarButton.d.ts +0 -15
  160. package/types/src/shared/components/toolbar/ToolbarDropdown.d.ts +0 -17
  161. package/types/src/shared/components/toolbar/ToolbarDropdownItem.d.ts +0 -11
  162. package/types/src/shared/components/toolbar/ToolbarDropdownTarget.d.ts +0 -8
  163. package/types/src/shared/components/toolbar/ToolbarSeparator.d.ts +0 -2
  164. package/types/src/shared/components/tooltip/TooltipContent.d.ts +0 -15
  165. package/types/src/shared/hooks/useEditorForceUpdate.d.ts +0 -2
  166. package/types/src/shared/plugins/suggestion/SuggestionListReactRenderer.d.ts +0 -71
  167. package/types/src/shared/plugins/suggestion/components/SuggestionGroup.d.ts +0 -23
  168. package/types/src/shared/plugins/suggestion/components/SuggestionGroupItem.d.ts +0 -9
  169. package/types/src/shared/plugins/suggestion/components/SuggestionList.d.ts +0 -11
  170. package/types/src/themes/BlockNoteEditorTheme.d.ts +0 -11
  171. package/types/src/useEditor.d.ts +0 -11
@@ -1,165 +0,0 @@
1
- import { MantineProvider } from "@mantine/core";
2
- import Tippy from "@tippyjs/react";
3
- import { getMarkRange } from "@tiptap/core";
4
- import { Mark, ResolvedPos } from "prosemirror-model";
5
- import { Plugin, PluginKey } from "prosemirror-state";
6
- import ReactDOM from "react-dom";
7
- import { BlockNoteTheme } from "../../BlockNoteTheme";
8
- import { HyperlinkMenu } from "./menus/HyperlinkMenu";
9
- const PLUGIN_KEY = new PluginKey("HyperlinkMenuPlugin");
10
-
11
- export const createHyperlinkMenuPlugin = () => {
12
- // as we always use Tippy appendTo(document.body), we can just create an element
13
- // that we use for ReactDOM, but it isn't used anywhere (except by React internally)
14
- const fakeRenderTarget = document.createElement("div");
15
-
16
- let hoveredLink: HTMLAnchorElement | undefined;
17
- let menuState: "cursor-based" | "mouse-based" | "hidden" = "hidden";
18
- let nextTippyKey = 0;
19
-
20
- return new Plugin({
21
- key: PLUGIN_KEY,
22
- view() {
23
- return {
24
- update: async (view, _prevState) => {
25
- const selection = view.state.selection;
26
- if (selection.from !== selection.to) {
27
- // don't show menu when we have an active selection
28
- if (menuState !== "hidden") {
29
- menuState = "hidden";
30
- ReactDOM.render(<></>, fakeRenderTarget);
31
- }
32
- return;
33
- }
34
-
35
- let pos: number | undefined;
36
- let resPos: ResolvedPos | undefined;
37
- let linkMark: Mark | undefined;
38
- let basedOnCursorPos = false;
39
- if (hoveredLink) {
40
- pos = view.posAtDOM(hoveredLink.firstChild!, 0);
41
- resPos = view.state.doc.resolve(pos);
42
- // based on https://github.com/ueberdosis/tiptap/blob/main/packages/core/src/helpers/getMarkRange.ts
43
- const start = resPos.parent.childAfter(resPos.parentOffset).node;
44
- linkMark = start?.marks.find((m) => m.type.name.startsWith("link"));
45
- }
46
-
47
- if (
48
- !linkMark &&
49
- (view.hasFocus() || menuState === "cursor-based") // prevents re-opening menu after submission. Only open cursor-based menu if editor has focus
50
- ) {
51
- // no hovered link mark, try get from cursor position
52
- pos = selection.from;
53
- resPos = view.state.doc.resolve(pos);
54
- const start = resPos.parent.childAfter(resPos.parentOffset).node;
55
- linkMark = start?.marks.find((m) => m.type.name.startsWith("link"));
56
- basedOnCursorPos = true;
57
- }
58
-
59
- if (!linkMark || !pos || !resPos) {
60
- // The mouse-based popup takes care of hiding itself (tippy)
61
- // Because the cursor-based popup is has "showOnCreate", we want to hide it manually
62
- // if the cursor moves way
63
- if (menuState === "cursor-based") {
64
- menuState = "hidden";
65
- ReactDOM.render(<></>, fakeRenderTarget);
66
- }
67
- return;
68
- }
69
-
70
- const range = getMarkRange(resPos, linkMark.type, linkMark.attrs);
71
- if (!range) {
72
- return;
73
- }
74
- const text = view.state.doc.textBetween(range.from, range.to);
75
- const url = linkMark.attrs.href;
76
-
77
- const anchorPos = {
78
- // use the 'median' position of the range
79
- ...view.coordsAtPos(Math.round((range.from + range.to) / 2)),
80
- height: 0, // needed to satisfy types
81
- width: 0,
82
- };
83
-
84
- const foundLinkMark = linkMark; // typescript workaround for event handlers
85
-
86
- // A URL has to begin with http(s):// to be interpreted as an absolute path
87
- const editHandler = (href: string, text: string) => {
88
- menuState = "hidden";
89
- ReactDOM.render(<></>, fakeRenderTarget);
90
-
91
- // update the mark with new href
92
- (foundLinkMark as any).attrs = { ...foundLinkMark.attrs, href }; // TODO: invalid assign to attrs
93
- // insertText actually replaces the range with text
94
- const tr = view.state.tr.insertText(text, range.from, range.to);
95
- // the former range.to is no longer in use
96
- tr.addMark(range.from, range.from + text.length, foundLinkMark);
97
- view.dispatch(tr);
98
- };
99
-
100
- const removeHandler = () => {
101
- view.dispatch(
102
- view.state.tr
103
- .removeMark(range.from, range.to, foundLinkMark.type)
104
- .setMeta("preventAutolink", true)
105
- );
106
- };
107
-
108
- const hyperlinkMenu = (
109
- <MantineProvider theme={BlockNoteTheme}>
110
- <Tippy
111
- key={nextTippyKey + ""} // it could be tippy has "hidden" itself after mouseout. We use a key to get a new instance with a clean state.
112
- getReferenceClientRect={() => anchorPos as any}
113
- content={
114
- <HyperlinkMenu
115
- update={editHandler}
116
- pos={anchorPos}
117
- remove={removeHandler}
118
- text={text}
119
- url={url}
120
- />
121
- }
122
- onHide={() => {
123
- nextTippyKey++;
124
- menuState = "hidden";
125
- }}
126
- aria={{ expanded: false }}
127
- interactive={true}
128
- interactiveBorder={30}
129
- triggerTarget={hoveredLink}
130
- showOnCreate={basedOnCursorPos}
131
- appendTo={document.body}>
132
- <div></div>
133
- </Tippy>
134
- </MantineProvider>
135
- );
136
- ReactDOM.render(hyperlinkMenu, fakeRenderTarget);
137
- menuState = basedOnCursorPos ? "cursor-based" : "mouse-based";
138
- },
139
- };
140
- },
141
-
142
- props: {
143
- handleDOMEvents: {
144
- // update view when an <a> is hovered over
145
- mouseover(view, event: any) {
146
- const newHoveredLink =
147
- event.target instanceof HTMLAnchorElement &&
148
- event.target.nodeName === "A"
149
- ? event.target
150
- : undefined;
151
-
152
- if (newHoveredLink !== hoveredLink) {
153
- // dispatch a meta transaction to make sure the view gets updated
154
- hoveredLink = newHoveredLink;
155
-
156
- view.dispatch(
157
- view.state.tr.setMeta(PLUGIN_KEY, { hoveredLinkChanged: true })
158
- );
159
- }
160
- return false;
161
- },
162
- },
163
- },
164
- });
165
- };
@@ -1,44 +0,0 @@
1
- import { createStyles, Stack } from "@mantine/core";
2
- import { useState } from "react";
3
- import { RiLink, RiText } from "react-icons/ri";
4
- import { EditHyperlinkMenuItem } from "./EditHyperlinkMenuItem";
5
-
6
- export type EditHyperlinkMenuProps = {
7
- url: string;
8
- text: string;
9
- update: (url: string, text: string) => void;
10
- };
11
-
12
- /**
13
- * Menu which opens when editing an existing hyperlink or creating a new one.
14
- * Provides input fields for setting the hyperlink URL and title.
15
- */
16
- export const EditHyperlinkMenu = (props: EditHyperlinkMenuProps) => {
17
- const [url, setUrl] = useState(props.url);
18
- const [title, setTitle] = useState(props.text);
19
- const { classes } = createStyles({ root: {} })(undefined, {
20
- name: "EditHyperlinkMenu",
21
- });
22
-
23
- return (
24
- <Stack className={classes.root}>
25
- <EditHyperlinkMenuItem
26
- icon={RiLink}
27
- mainIconTooltip={"Edit URL"}
28
- autofocus={true}
29
- placeholder={"Edit URL"}
30
- value={url}
31
- onChange={(value) => setUrl(value)}
32
- onSubmit={() => props.update(url, title)}
33
- />
34
- <EditHyperlinkMenuItem
35
- icon={RiText}
36
- mainIconTooltip={"Edit Title"}
37
- placeholder={"Edit Title"}
38
- value={title}
39
- onChange={(value) => setTitle(value)}
40
- onSubmit={() => props.update(url, title)}
41
- />
42
- </Stack>
43
- );
44
- };
@@ -1,34 +0,0 @@
1
- import { IconType } from "react-icons";
2
- import { EditHyperlinkMenuItemIcon } from "./EditHyperlinkMenuItemIcon";
3
- import { EditHyperlinkMenuItemInput } from "./EditHyperlinkMenuItemInput";
4
- import { Group } from "@mantine/core";
5
-
6
- export type EditHyperlinkMenuItemProps = {
7
- icon: IconType;
8
- mainIconTooltip: string;
9
- secondaryIconTooltip?: string;
10
- autofocus?: boolean;
11
- placeholder?: string;
12
- value?: string;
13
- onChange: (value: string) => void;
14
- onSubmit: () => void;
15
- };
16
-
17
- export function EditHyperlinkMenuItem(props: EditHyperlinkMenuItemProps) {
18
- return (
19
- <Group>
20
- <EditHyperlinkMenuItemIcon
21
- icon={props.icon}
22
- mainTooltip={props.mainIconTooltip}
23
- secondaryTooltip={props.secondaryIconTooltip}
24
- />
25
- <EditHyperlinkMenuItemInput
26
- autofocus={props.autofocus}
27
- placeholder={props.placeholder}
28
- value={props.value}
29
- onChange={props.onChange}
30
- onSubmit={props.onSubmit}
31
- />
32
- </Group>
33
- );
34
- }
@@ -1,31 +0,0 @@
1
- import { IconType } from "react-icons";
2
- import Tippy from "@tippyjs/react";
3
- import { TooltipContent } from "../../../shared/components/tooltip/TooltipContent";
4
- import { Container } from "@mantine/core";
5
-
6
- export type EditHyperlinkMenuItemIconProps = {
7
- icon: IconType;
8
- mainTooltip: string;
9
- secondaryTooltip?: string;
10
- };
11
-
12
- export function EditHyperlinkMenuItemIcon(
13
- props: EditHyperlinkMenuItemIconProps
14
- ) {
15
- const Icon = props.icon;
16
-
17
- return (
18
- <Tippy
19
- content={
20
- <TooltipContent
21
- mainTooltip={props.mainTooltip}
22
- secondaryTooltip={props.secondaryTooltip}
23
- />
24
- }
25
- placement="left">
26
- <Container>
27
- <Icon size={16}></Icon>
28
- </Container>
29
- </Tippy>
30
- );
31
- }
@@ -1,40 +0,0 @@
1
- import { KeyboardEvent, useEffect, useRef } from "react";
2
- import { TextInput } from "@mantine/core";
3
-
4
- export type EditHyperlinkMenuItemInputProps = {
5
- autofocus?: boolean;
6
- placeholder?: string;
7
- value?: string;
8
- onChange: (value: string) => void;
9
- onSubmit: () => void;
10
- };
11
-
12
- export function EditHyperlinkMenuItemInput(
13
- props: EditHyperlinkMenuItemInputProps
14
- ) {
15
- const inputRef = useRef<HTMLInputElement>(null);
16
-
17
- useEffect(() => {
18
- setTimeout(() => {
19
- props.autofocus && inputRef.current?.focus();
20
- });
21
- }, [props.autofocus]);
22
-
23
- function handleEnter(event: KeyboardEvent) {
24
- if (event.key === "Enter") {
25
- event.preventDefault();
26
- props.onSubmit();
27
- }
28
- }
29
-
30
- return (
31
- <TextInput
32
- size={"xs"}
33
- value={props.value}
34
- onChange={(event) => props.onChange(event.currentTarget.value)}
35
- onKeyDown={handleEnter}
36
- placeholder={props.placeholder}
37
- ref={inputRef}
38
- />
39
- );
40
- }
@@ -1,37 +0,0 @@
1
- import { RiExternalLinkFill, RiLinkUnlink } from "react-icons/ri";
2
- import { Toolbar } from "../../../shared/components/toolbar/Toolbar";
3
- import { ToolbarButton } from "../../../shared/components/toolbar/ToolbarButton";
4
-
5
- type HoverHyperlinkMenuProps = {
6
- url: string;
7
- edit: () => void;
8
- remove: () => void;
9
- };
10
-
11
- /**
12
- * Menu which opens when hovering an existing hyperlink.
13
- * Provides buttons for editing, opening, and removing the hyperlink.
14
- */
15
- export const HoverHyperlinkMenu = (props: HoverHyperlinkMenuProps) => {
16
- return (
17
- <Toolbar>
18
- <ToolbarButton mainTooltip="Edit" isSelected={false} onClick={props.edit}>
19
- Edit Link
20
- </ToolbarButton>
21
- <ToolbarButton
22
- mainTooltip="Open in new tab"
23
- isSelected={false}
24
- onClick={() => {
25
- window.open(props.url, "_blank");
26
- }}
27
- icon={RiExternalLinkFill}
28
- />
29
- <ToolbarButton
30
- mainTooltip="Remove link"
31
- isSelected={false}
32
- onClick={props.remove}
33
- icon={RiLinkUnlink}
34
- />
35
- </Toolbar>
36
- );
37
- };
@@ -1,63 +0,0 @@
1
- import { useState } from "react";
2
- import Tippy from "@tippyjs/react";
3
- import { EditHyperlinkMenu } from "./EditHyperlinkMenu";
4
- import { HoverHyperlinkMenu } from "./HoverHyperlinkMenu";
5
- import rootStyles from "../../../root.module.css";
6
-
7
- type HyperlinkMenuProps = {
8
- url: string;
9
- text: string;
10
- pos: {
11
- height: number;
12
- width: number;
13
- left: number;
14
- right: number;
15
- top: number;
16
- bottom: number;
17
- };
18
- update: (url: string, text: string) => void;
19
- remove: () => void;
20
- };
21
-
22
- /**
23
- * Main menu component for the hyperlink extension.
24
- * Either renders a menu to create/edit a hyperlink, or a menu to interact with it on mouse hover.
25
- */
26
- export const HyperlinkMenu = (props: HyperlinkMenuProps) => {
27
- const [isEditing, setIsEditing] = useState(false);
28
-
29
- const editHyperlinkMenu = (
30
- <Tippy
31
- getReferenceClientRect={() => props.pos as any}
32
- content={
33
- <EditHyperlinkMenu
34
- url={props.url}
35
- text={props.text}
36
- update={props.update}
37
- />
38
- }
39
- interactive={true}
40
- interactiveBorder={30}
41
- showOnCreate={true}
42
- trigger={"click"} // so that we don't hide on mouse out
43
- hideOnClick
44
- className={rootStyles.bnRoot}
45
- appendTo={document.body}>
46
- <div></div>
47
- </Tippy>
48
- );
49
-
50
- const hoverHyperlinkMenu = (
51
- <HoverHyperlinkMenu
52
- url={props.url}
53
- edit={() => setIsEditing(true)}
54
- remove={props.remove}
55
- />
56
- );
57
-
58
- if (isEditing) {
59
- return editHyperlinkMenu;
60
- } else {
61
- return hoverHyperlinkMenu;
62
- }
63
- };
@@ -1,94 +0,0 @@
1
- /* Generated using https://google-webfonts-helper.herokuapp.com/fonts/inter?subsets=latin */
2
-
3
- /* inter-100 - latin */
4
- @font-face {
5
- font-family: "Inter";
6
- font-style: normal;
7
- font-weight: 100;
8
- src: local(""),
9
- url("./assets/inter-v12-latin/inter-v12-latin-100.woff2") format("woff2"),
10
- /* Chrome 26+, Opera 23+, Firefox 39+ */
11
- url("./assets/inter-v12-latin/inter-v12-latin-100.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
12
- }
13
- /* inter-200 - latin */
14
- @font-face {
15
- font-family: "Inter";
16
- font-style: normal;
17
- font-weight: 200;
18
- src: local(""),
19
- url("./assets/inter-v12-latin/inter-v12-latin-200.woff2") format("woff2"),
20
- /* Chrome 26+, Opera 23+, Firefox 39+ */
21
- url("./assets/inter-v12-latin/inter-v12-latin-200.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
22
- }
23
- /* inter-300 - latin */
24
- @font-face {
25
- font-family: "Inter";
26
- font-style: normal;
27
- font-weight: 300;
28
- src: local(""),
29
- url("./assets/inter-v12-latin/inter-v12-latin-300.woff2") format("woff2"),
30
- /* Chrome 26+, Opera 23+, Firefox 39+ */
31
- url("./assets/inter-v12-latin/inter-v12-latin-300.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
32
- }
33
- /* inter-regular - latin */
34
- @font-face {
35
- font-family: "Inter";
36
- font-style: normal;
37
- font-weight: 400;
38
- src: local(""),
39
- url("./assets/inter-v12-latin/inter-v12-latin-regular.woff2")
40
- format("woff2"),
41
- /* Chrome 26+, Opera 23+, Firefox 39+ */
42
- url("./assets/inter-v12-latin/inter-v12-latin-regular.woff")
43
- format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
44
- }
45
- /* inter-500 - latin */
46
- @font-face {
47
- font-family: "Inter";
48
- font-style: normal;
49
- font-weight: 500;
50
- src: local(""),
51
- url("./assets/inter-v12-latin/inter-v12-latin-500.woff2") format("woff2"),
52
- /* Chrome 26+, Opera 23+, Firefox 39+ */
53
- url("./assets/inter-v12-latin/inter-v12-latin-500.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
54
- }
55
- /* inter-600 - latin */
56
- @font-face {
57
- font-family: "Inter";
58
- font-style: normal;
59
- font-weight: 600;
60
- src: local(""),
61
- url("./assets/inter-v12-latin/inter-v12-latin-600.woff2") format("woff2"),
62
- /* Chrome 26+, Opera 23+, Firefox 39+ */
63
- url("./assets/inter-v12-latin/inter-v12-latin-600.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
64
- }
65
- /* inter-700 - latin */
66
- @font-face {
67
- font-family: "Inter";
68
- font-style: normal;
69
- font-weight: 700;
70
- src: local(""),
71
- url("./assets/inter-v12-latin/inter-v12-latin-700.woff2") format("woff2"),
72
- /* Chrome 26+, Opera 23+, Firefox 39+ */
73
- url("./assets/inter-v12-latin/inter-v12-latin-700.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
74
- }
75
- /* inter-800 - latin */
76
- @font-face {
77
- font-family: "Inter";
78
- font-style: normal;
79
- font-weight: 800;
80
- src: local(""),
81
- url("./assets/inter-v12-latin/inter-v12-latin-800.woff2") format("woff2"),
82
- /* Chrome 26+, Opera 23+, Firefox 39+ */
83
- url("./assets/inter-v12-latin/inter-v12-latin-800.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
84
- }
85
- /* inter-900 - latin */
86
- @font-face {
87
- font-family: "Inter";
88
- font-style: normal;
89
- font-weight: 900;
90
- src: local(""),
91
- url("./assets/inter-v12-latin/inter-v12-latin-900.woff2") format("woff2"),
92
- /* Chrome 26+, Opera 23+, Firefox 39+ */
93
- url("./assets/inter-v12-latin/inter-v12-latin-900.woff") format("woff"); /* Chrome 6+, Firefox 3.6+, IE 9+, Safari 5.1+ */
94
- }
package/src/globals.css DELETED
@@ -1,28 +0,0 @@
1
- @import url("fonts-inter.css");
2
-
3
- /* TODO: should not be on root as this changes entire consuming application */
4
-
5
- :root {
6
- /* Define a set of colors to be used throughout the app for consistency
7
- see https://atlassian.design/foundations/color for more info */
8
- --N800: #172b4d; /* Dark neutral used for tooltips and text on light background */
9
- --N40: #dfe1e6; /* Light neutral used for subtle borders and text on dark background */
10
-
11
- font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont,
12
- "Open Sans", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
13
- "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
14
- -webkit-font-smoothing: antialiased;
15
- -moz-osx-font-smoothing: grayscale;
16
-
17
- color: rgb(60, 65, 73);
18
- }
19
-
20
- button {
21
- font-family: "Inter", "SF Pro Display", -apple-system, BlinkMacSystemFont,
22
- "Open Sans", "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell",
23
- "Fira Sans", "Droid Sans", "Helvetica Neue", sans-serif;
24
- -webkit-font-smoothing: antialiased;
25
- -moz-osx-font-smoothing: grayscale;
26
-
27
- color: rgb(60, 65, 73);
28
- }
@@ -1,19 +0,0 @@
1
- /*
2
- bnRoot should be applied to all top-level elements
3
-
4
- This includes the Prosemirror editor, but also <div> element such as
5
- Tippy popups that are appended to document.body directly
6
- */
7
- .bnRoot {
8
- -webkit-box-sizing: border-box;
9
- -moz-box-sizing: border-box;
10
- box-sizing: border-box;
11
- }
12
-
13
- .bnRoot *,
14
- .bnRoot *::before,
15
- .bnRoot *::after {
16
- -webkit-box-sizing: inherit;
17
- -moz-box-sizing: inherit;
18
- box-sizing: inherit;
19
- }
@@ -1,10 +0,0 @@
1
- import { createStyles, Group } from "@mantine/core";
2
- import { ReactNode } from "react";
3
-
4
- export const Toolbar = (props: { children: ReactNode }) => {
5
- const { classes } = createStyles({ root: {} })(undefined, {
6
- name: "Toolbar",
7
- });
8
-
9
- return <Group className={classes.root}>{props.children}</Group>;
10
- };
@@ -1,57 +0,0 @@
1
- import { ActionIcon, Button } from "@mantine/core";
2
- import Tippy from "@tippyjs/react";
3
- import { forwardRef } from "react";
4
- import { TooltipContent } from "../tooltip/TooltipContent";
5
- import React from "react";
6
- import { IconType } from "react-icons";
7
-
8
- export type ToolbarButtonProps = {
9
- onClick?: (e: React.MouseEvent) => void;
10
- icon?: IconType;
11
- mainTooltip: string;
12
- secondaryTooltip?: string;
13
- isSelected?: boolean;
14
- children?: any;
15
- isDisabled?: boolean;
16
- };
17
-
18
- /**
19
- * Helper for basic buttons that show in the inline bubble menu.
20
- */
21
- export const ToolbarButton = forwardRef((props: ToolbarButtonProps, ref) => {
22
- const ButtonIcon = props.icon;
23
- return (
24
- <Tippy
25
- content={
26
- <TooltipContent
27
- mainTooltip={props.mainTooltip}
28
- secondaryTooltip={props.secondaryTooltip}
29
- />
30
- }
31
- trigger={"mouseenter"}>
32
- {/*Creates an ActionIcon instead of a Button if only an icon is provided as content.*/}
33
- {props.children ? (
34
- <Button
35
- onClick={props.onClick}
36
- color={"brandFinal"}
37
- size={"xs"}
38
- variant={props.isSelected ? "filled" : "subtle"}
39
- disabled={props.isDisabled || false}
40
- ref={ref as any}>
41
- {ButtonIcon && <ButtonIcon />}
42
- {props.children}
43
- </Button>
44
- ) : (
45
- <ActionIcon
46
- onClick={props.onClick}
47
- color={"brandFinal"}
48
- size={30}
49
- variant={props.isSelected ? "filled" : "subtle"}
50
- disabled={props.isDisabled || false}
51
- ref={ref as any}>
52
- {ButtonIcon && <ButtonIcon />}
53
- </ActionIcon>
54
- )}
55
- </Tippy>
56
- );
57
- });
@@ -1,35 +0,0 @@
1
- import { Menu } from "@mantine/core";
2
- import { IconType } from "react-icons";
3
- import { ToolbarDropdownTarget } from "./ToolbarDropdownTarget";
4
- import { MouseEvent } from "react";
5
- import { ToolbarDropdownItem } from "./ToolbarDropdownItem";
6
-
7
- export type ToolbarDropdownProps = {
8
- text: string;
9
- icon?: IconType;
10
- items: Array<{
11
- onClick?: (e: MouseEvent) => void;
12
- text: string;
13
- icon?: IconType;
14
- isSelected?: boolean;
15
- children?: any;
16
- isDisabled?: boolean;
17
- }>;
18
- children?: any;
19
- isDisabled?: boolean;
20
- };
21
-
22
- export function ToolbarDropdown(props: ToolbarDropdownProps) {
23
- return (
24
- <Menu exitTransitionDuration={0}>
25
- <Menu.Target>
26
- <ToolbarDropdownTarget {...props} />
27
- </Menu.Target>
28
- <Menu.Dropdown>
29
- {props.items.map((item) => (
30
- <ToolbarDropdownItem key={item.text} {...item} />
31
- ))}
32
- </Menu.Dropdown>
33
- </Menu>
34
- );
35
- }