@blocknote/core 0.1.0 → 0.1.2
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.
- package/README.md +1 -1
- package/dist/blocknote.js +3454 -2426
- package/dist/blocknote.js.map +1 -1
- package/dist/blocknote.umd.cjs +35 -71
- package/dist/blocknote.umd.cjs.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +7 -6
- package/src/BlockNoteTheme.ts +150 -0
- package/src/extensions/Blocks/BlockAttributes.ts +12 -0
- package/src/extensions/Blocks/MultipleNodeSelection.ts +87 -0
- package/src/extensions/Blocks/PreviousBlockTypePlugin.ts +8 -2
- package/src/extensions/Blocks/nodes/Block.module.css +37 -37
- package/src/extensions/Blocks/nodes/Block.ts +79 -32
- package/src/extensions/Blocks/nodes/BlockGroup.ts +18 -1
- package/src/extensions/Blocks/nodes/Content.ts +14 -1
- package/src/extensions/BubbleMenu/BubbleMenuExtension.tsx +8 -1
- package/src/extensions/BubbleMenu/component/BubbleMenu.tsx +116 -88
- package/src/extensions/BubbleMenu/component/LinkToolbarButton.tsx +8 -8
- package/src/extensions/DraggableBlocks/DraggableBlocksPlugin.tsx +143 -33
- package/src/extensions/DraggableBlocks/components/DragHandle.tsx +14 -19
- package/src/extensions/DraggableBlocks/components/DragHandleMenu.tsx +8 -7
- package/src/extensions/Hyperlinks/HyperlinkMenuPlugin.tsx +31 -66
- package/src/extensions/Hyperlinks/menus/EditHyperlinkMenu.tsx +44 -0
- package/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItem.tsx +34 -0
- package/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemIcon.tsx +31 -0
- package/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemInput.tsx +40 -0
- package/src/extensions/Hyperlinks/menus/HoverHyperlinkMenu.tsx +37 -0
- package/src/extensions/Hyperlinks/menus/HyperlinkMenu.tsx +63 -0
- package/src/extensions/SlashMenu/SlashMenuItem.ts +3 -1
- package/src/extensions/SlashMenu/defaultCommands.tsx +4 -4
- package/src/extensions/UniqueID/UniqueID.ts +0 -11
- package/src/shared/components/toolbar/Toolbar.tsx +8 -3
- package/src/shared/components/toolbar/ToolbarButton.tsx +57 -0
- package/src/shared/components/toolbar/ToolbarDropdown.tsx +35 -0
- package/src/shared/components/toolbar/ToolbarDropdownItem.tsx +35 -0
- package/src/shared/components/toolbar/ToolbarDropdownTarget.tsx +31 -0
- package/src/shared/plugins/suggestion/SuggestionItem.ts +3 -1
- package/src/shared/plugins/suggestion/{SuggestionListReactRenderer.ts → SuggestionListReactRenderer.tsx} +13 -4
- package/src/shared/plugins/suggestion/components/SuggestionGroup.tsx +6 -93
- package/src/shared/plugins/suggestion/components/SuggestionGroupItem.tsx +82 -0
- package/src/shared/plugins/suggestion/components/SuggestionList.tsx +24 -23
- package/src/utils.ts +12 -0
- package/types/src/BlockNoteTheme.d.ts +2 -0
- package/types/src/commands/indentation.d.ts +2 -0
- package/types/src/extensions/Blocks/BlockAttributes.d.ts +2 -0
- package/types/src/extensions/Blocks/MultipleNodeSelection.d.ts +24 -0
- package/types/src/extensions/Blocks/nodes/Block.d.ts +1 -1
- package/types/src/extensions/BubbleMenu/component/LinkToolbarButton.d.ts +2 -2
- package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenu.d.ts +11 -0
- package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItem.d.ts +13 -0
- package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemIcon.d.ts +8 -0
- package/types/src/extensions/Hyperlinks/menus/EditHyperlinkMenuItemInput.d.ts +9 -0
- package/types/src/extensions/Hyperlinks/menus/HoverHyperlinkMenu.d.ts +12 -0
- package/types/src/extensions/Hyperlinks/menus/HyperlinkMenu.d.ts +21 -0
- package/types/src/extensions/Hyperlinks/menus/helpers/PanelTextInput.d.ts +39 -0
- package/types/src/extensions/Hyperlinks/menus/helpers/PanelTextInputStyles.d.ts +3 -0
- package/types/src/extensions/Hyperlinks/menus/helpers/ToolbarComponent.d.ts +13 -0
- package/types/src/extensions/SlashMenu/SlashMenuItem.d.ts +4 -7
- package/types/src/nodes/ChildgroupNode.d.ts +28 -0
- package/types/src/nodes/patchNodes.d.ts +1 -0
- package/types/src/plugins/TreeViewPlugin/index.d.ts +2 -0
- package/types/src/plugins/animation.d.ts +2 -0
- package/types/src/react/BlockNoteComposer.d.ts +17 -0
- package/types/src/react/BlockNotePlugin.d.ts +1 -0
- package/types/src/react/index.d.ts +3 -0
- package/types/src/react/useBlockNoteSetup.d.ts +2 -0
- package/types/src/registerBlockNote.d.ts +2 -0
- package/types/src/shared/components/toolbar/SimpleToolbarButton.d.ts +2 -3
- package/types/src/shared/components/toolbar/SimpleToolbarDropdown.d.ts +11 -0
- package/types/src/shared/components/toolbar/SimpleToolbarDropdownItem.d.ts +11 -0
- package/types/src/shared/components/toolbar/Toolbar.d.ts +2 -2
- package/types/src/shared/components/toolbar/ToolbarButton.d.ts +15 -0
- package/types/src/shared/components/toolbar/ToolbarDropdown.d.ts +17 -0
- package/types/src/shared/components/toolbar/ToolbarDropdownItem.d.ts +11 -0
- package/types/src/shared/components/toolbar/ToolbarDropdownTarget.d.ts +8 -0
- package/types/src/shared/plugins/suggestion/SuggestionItem.d.ts +2 -4
- package/types/src/shared/plugins/suggestion/components/SuggestionGroupItem.d.ts +9 -0
- package/types/src/shared/plugins/suggestion/components/SuggestionList.d.ts +0 -15
- package/types/src/themes/BlockNoteEditorTheme.d.ts +11 -0
- package/types/src/utils.d.ts +2 -0
- package/src/extensions/BubbleMenu/component/DropdownBlockItem.module.css +0 -13
- package/src/extensions/BubbleMenu/component/DropdownBlockItem.tsx +0 -25
- package/src/extensions/DraggableBlocks/components/DragHandle.module.css +0 -33
- package/src/extensions/DraggableBlocks/components/DragHandleMenu.module.css +0 -10
- package/src/extensions/Hyperlinks/menus/HyperlinkBasicMenu.tsx +0 -59
- package/src/extensions/Hyperlinks/menus/HyperlinkEditMenu.tsx +0 -72
- package/src/extensions/Hyperlinks/menus/atlaskit/PanelTextInput.tsx +0 -173
- package/src/extensions/Hyperlinks/menus/atlaskit/PanelTextInputStyles.ts +0 -36
- package/src/extensions/Hyperlinks/menus/atlaskit/README.md +0 -1
- package/src/extensions/Hyperlinks/menus/atlaskit/ToolbarComponent.tsx +0 -61
- package/src/extensions/helpers/formatKeyboardShortcut.ts +0 -9
- package/src/lib/atlaskit/browser.ts +0 -47
- package/src/shared/components/toolbar/SimpleToolbarButton.module.css +0 -13
- package/src/shared/components/toolbar/SimpleToolbarButton.tsx +0 -56
- package/src/shared/components/toolbar/Toolbar.module.css +0 -10
- package/src/shared/components/toolbar/ToolbarSeparator.module.css +0 -13
- package/src/shared/components/toolbar/ToolbarSeparator.tsx +0 -7
- package/src/shared/plugins/suggestion/components/SuggestionGroup.module.css +0 -45
- package/src/shared/plugins/suggestion/components/SuggestionList.module.css +0 -10
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { EditorState, EditorThemeClasses, Klass, LexicalEditor, LexicalNode } from "lexical";
|
|
3
|
+
export declare type InitialEditorStateType = null | string | EditorState | ((editor: LexicalEditor) => void);
|
|
4
|
+
declare type Props = {
|
|
5
|
+
children: JSX.Element | JSX.Element[];
|
|
6
|
+
initialConfig: Readonly<{
|
|
7
|
+
editor__DEPRECATED?: LexicalEditor | null;
|
|
8
|
+
namespace: string;
|
|
9
|
+
nodes?: ReadonlyArray<Klass<LexicalNode>>;
|
|
10
|
+
onError: (error: Error, editor: LexicalEditor) => void;
|
|
11
|
+
editable?: boolean;
|
|
12
|
+
theme?: EditorThemeClasses;
|
|
13
|
+
editorState?: InitialEditorStateType;
|
|
14
|
+
}>;
|
|
15
|
+
};
|
|
16
|
+
export declare function BlockNoteComposer({ initialConfig, children }: Props): JSX.Element;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function BlockNotePlugin(_props: {}): null;
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { IconType } from "react-icons";
|
|
2
3
|
export declare type SimpleToolbarButtonProps = {
|
|
3
4
|
onClick?: (e: React.MouseEvent) => void;
|
|
4
|
-
icon?:
|
|
5
|
-
className: string;
|
|
6
|
-
}>;
|
|
5
|
+
icon?: IconType;
|
|
7
6
|
mainTooltip: string;
|
|
8
7
|
secondaryTooltip?: string;
|
|
9
8
|
isSelected?: boolean;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { SimpleToolbarDropdownItemProps } from "./SimpleToolbarDropdownItem";
|
|
3
|
+
import { IconType } from "react-icons";
|
|
4
|
+
export declare type SimpleToolbarDropdownProps = {
|
|
5
|
+
text: string;
|
|
6
|
+
icon?: IconType;
|
|
7
|
+
items: Array<SimpleToolbarDropdownItemProps>;
|
|
8
|
+
children?: any;
|
|
9
|
+
isDisabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function SimpleToolbarDropdown(props: SimpleToolbarDropdownProps): JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconType } from "react-icons";
|
|
3
|
+
export declare type SimpleToolbarDropdownItemProps = {
|
|
4
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
5
|
+
text: string;
|
|
6
|
+
icon?: IconType;
|
|
7
|
+
isSelected?: boolean;
|
|
8
|
+
children?: any;
|
|
9
|
+
isDisabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function SimpleToolbarDropdownItem(props: SimpleToolbarDropdownItemProps): JSX.Element;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { IconType } from "react-icons";
|
|
3
|
+
export declare type ToolbarButtonProps = {
|
|
4
|
+
onClick?: (e: React.MouseEvent) => void;
|
|
5
|
+
icon?: IconType;
|
|
6
|
+
mainTooltip: string;
|
|
7
|
+
secondaryTooltip?: string;
|
|
8
|
+
isSelected?: boolean;
|
|
9
|
+
children?: any;
|
|
10
|
+
isDisabled?: boolean;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Helper for basic buttons that show in the inline bubble menu.
|
|
14
|
+
*/
|
|
15
|
+
export declare const ToolbarButton: React.ForwardRefExoticComponent<ToolbarButtonProps & React.RefAttributes<unknown>>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { IconType } from "react-icons";
|
|
2
|
+
import { MouseEvent } from "react";
|
|
3
|
+
export declare type ToolbarDropdownProps = {
|
|
4
|
+
text: string;
|
|
5
|
+
icon?: IconType;
|
|
6
|
+
items: Array<{
|
|
7
|
+
onClick?: (e: MouseEvent) => void;
|
|
8
|
+
text: string;
|
|
9
|
+
icon?: IconType;
|
|
10
|
+
isSelected?: boolean;
|
|
11
|
+
children?: any;
|
|
12
|
+
isDisabled?: boolean;
|
|
13
|
+
}>;
|
|
14
|
+
children?: any;
|
|
15
|
+
isDisabled?: boolean;
|
|
16
|
+
};
|
|
17
|
+
export declare function ToolbarDropdown(props: ToolbarDropdownProps): JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IconType } from "react-icons";
|
|
2
|
+
import { MouseEvent } from "react";
|
|
3
|
+
export declare type ToolbarDropdownItemProps = {
|
|
4
|
+
onClick?: (e: MouseEvent) => void;
|
|
5
|
+
text: string;
|
|
6
|
+
icon?: IconType;
|
|
7
|
+
isSelected?: boolean;
|
|
8
|
+
children?: any;
|
|
9
|
+
isDisabled?: boolean;
|
|
10
|
+
};
|
|
11
|
+
export declare function ToolbarDropdownItem(props: ToolbarDropdownItemProps): JSX.Element;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { IconType } from "react-icons";
|
|
3
|
+
export declare type ToolbarDropdownTargetProps = {
|
|
4
|
+
text: string;
|
|
5
|
+
icon?: IconType;
|
|
6
|
+
isDisabled?: boolean;
|
|
7
|
+
};
|
|
8
|
+
export declare const ToolbarDropdownTarget: import("react").ForwardRefExoticComponent<ToolbarDropdownTargetProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
1
|
+
import { IconType } from "react-icons";
|
|
2
2
|
/**
|
|
3
3
|
* A generic interface used in all suggestion menus (slash menu, mentions, etc)
|
|
4
4
|
*/
|
|
@@ -14,9 +14,7 @@ export default interface SuggestionItem {
|
|
|
14
14
|
/**
|
|
15
15
|
* The react icon
|
|
16
16
|
*/
|
|
17
|
-
icon?:
|
|
18
|
-
className: string;
|
|
19
|
-
}>;
|
|
17
|
+
icon?: IconType;
|
|
20
18
|
hint?: string;
|
|
21
19
|
shortcut?: string;
|
|
22
20
|
/**
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import SuggestionItem from "../SuggestionItem";
|
|
3
|
+
export declare type SuggestionGroupItemProps<T> = {
|
|
4
|
+
item: T;
|
|
5
|
+
index: number;
|
|
6
|
+
selectedIndex?: number;
|
|
7
|
+
clickItem: (item: T) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function SuggestionGroupItem<T extends SuggestionItem>(props: SuggestionGroupItemProps<T>): JSX.Element;
|
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
2
|
import SuggestionItem from "../SuggestionItem";
|
|
3
3
|
export declare type SuggestionListProps<T> = {
|
|
4
|
-
/**
|
|
5
|
-
* Object containing all suggestion items, grouped by their `groupName`.
|
|
6
|
-
*/
|
|
7
4
|
groups: {
|
|
8
5
|
[groupName: string]: T[];
|
|
9
6
|
};
|
|
10
|
-
/**
|
|
11
|
-
* The total number of suggestion-items
|
|
12
|
-
*/
|
|
13
7
|
count: number;
|
|
14
|
-
/**
|
|
15
|
-
* This callback gets executed whenever an item is clicked on
|
|
16
|
-
*/
|
|
17
8
|
onSelectItem: (item: T) => void;
|
|
18
|
-
/**
|
|
19
|
-
* The index of the item that is currently selected (but not yet clicked on)
|
|
20
|
-
*/
|
|
21
9
|
selectedIndex: number;
|
|
22
10
|
};
|
|
23
|
-
/**
|
|
24
|
-
* Stateless component that renders the suggestion list
|
|
25
|
-
*/
|
|
26
11
|
export declare function SuggestionList<T extends SuggestionItem>(props: SuggestionListProps<T>): JSX.Element;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
import type { EditorThemeClasses } from "lexical";
|
|
9
|
+
import "./BlockNoteEditorTheme.css";
|
|
10
|
+
declare const theme: EditorThemeClasses;
|
|
11
|
+
export { theme as defaultTheme };
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import { DropdownItem } from "@atlaskit/dropdown-menu";
|
|
2
|
-
import { IconType } from "react-icons/lib";
|
|
3
|
-
import { TiTick } from "react-icons/ti";
|
|
4
|
-
import styles from "./DropdownBlockItem.module.css";
|
|
5
|
-
|
|
6
|
-
interface DropdownBlockItemProps {
|
|
7
|
-
title: string;
|
|
8
|
-
icon: IconType;
|
|
9
|
-
isSelected?: boolean;
|
|
10
|
-
onClick?: () => void;
|
|
11
|
-
}
|
|
12
|
-
export default function DropdownBlockItem(props: DropdownBlockItemProps) {
|
|
13
|
-
const ItemIcon = props.icon;
|
|
14
|
-
return (
|
|
15
|
-
<DropdownItem onClick={props.onClick}>
|
|
16
|
-
<div className={`${styles.item_container}`}>
|
|
17
|
-
<div className={`${styles.logo_and_item_container}`}>
|
|
18
|
-
<ItemIcon />
|
|
19
|
-
{props.title}
|
|
20
|
-
</div>
|
|
21
|
-
{props.isSelected && <TiTick />}
|
|
22
|
-
</div>
|
|
23
|
-
</DropdownItem>
|
|
24
|
-
);
|
|
25
|
-
}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
.dragHandle {
|
|
2
|
-
/* position: absolute; */
|
|
3
|
-
transition: opacity 300ms;
|
|
4
|
-
width: 20px;
|
|
5
|
-
height: 24px;
|
|
6
|
-
|
|
7
|
-
background-image: url('data:image/svg+xml;charset=UTF-8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 -4 10 24"><path fill-opacity="0.2" d="M4 14c0 1.1-.9 2-2 2s-2-.9-2-2 .9-2 2-2 2 .9 2 2zM2 6C.9 6 0 6.9 0 8s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0-6C.9 0 0 .9 0 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm6 4c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" /></svg>');
|
|
8
|
-
background-repeat: no-repeat;
|
|
9
|
-
background-size: contain;
|
|
10
|
-
background-position: center;
|
|
11
|
-
cursor: grab;
|
|
12
|
-
border-radius: 3px;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/* .dragHandle:active {
|
|
16
|
-
cursor: !important;
|
|
17
|
-
} */
|
|
18
|
-
|
|
19
|
-
.dragHandleAdd:hover,
|
|
20
|
-
.dragHandle:hover {
|
|
21
|
-
background-color: #eee;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
.dragHandleAdd {
|
|
25
|
-
/* position: absolute; */
|
|
26
|
-
transition: opacity 300ms;
|
|
27
|
-
|
|
28
|
-
background-repeat: no-repeat;
|
|
29
|
-
background-size: contain;
|
|
30
|
-
background-position: center;
|
|
31
|
-
cursor: pointer;
|
|
32
|
-
border-radius: 3px;
|
|
33
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
2
|
-
import { RiExternalLinkFill, RiLinkUnlink } from "react-icons/ri";
|
|
3
|
-
import { SimpleToolbarButton } from "../../../shared/components/toolbar/SimpleToolbarButton";
|
|
4
|
-
import { Toolbar } from "../../../shared/components/toolbar/Toolbar";
|
|
5
|
-
import { ToolbarSeparator } from "../../../shared/components/toolbar/ToolbarSeparator";
|
|
6
|
-
import React from "react";
|
|
7
|
-
|
|
8
|
-
type HyperlinkMenuProps = {
|
|
9
|
-
href: string;
|
|
10
|
-
removeHandler: () => void;
|
|
11
|
-
editMenu: React.ReactElement;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* A hyperlink menu shown when an anchor is hovered over.
|
|
16
|
-
* It shows options to edit / remove / open the link
|
|
17
|
-
*/
|
|
18
|
-
export const HyperlinkBasicMenu = (props: HyperlinkMenuProps) => {
|
|
19
|
-
const [isEditing, setIsEditing] = useState(false);
|
|
20
|
-
if (isEditing) {
|
|
21
|
-
return props.editMenu;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function onEditClick(e: React.MouseEvent) {
|
|
25
|
-
setIsEditing(true);
|
|
26
|
-
e.stopPropagation();
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return (
|
|
30
|
-
<Toolbar>
|
|
31
|
-
<SimpleToolbarButton
|
|
32
|
-
mainTooltip="Edit"
|
|
33
|
-
isSelected={false}
|
|
34
|
-
onClick={onEditClick}>
|
|
35
|
-
Edit Link
|
|
36
|
-
</SimpleToolbarButton>
|
|
37
|
-
|
|
38
|
-
<ToolbarSeparator />
|
|
39
|
-
|
|
40
|
-
<SimpleToolbarButton
|
|
41
|
-
mainTooltip="Open in new tab"
|
|
42
|
-
isSelected={false}
|
|
43
|
-
onClick={() => {
|
|
44
|
-
window.open(props.href, "_blank");
|
|
45
|
-
}}
|
|
46
|
-
icon={RiExternalLinkFill}
|
|
47
|
-
/>
|
|
48
|
-
|
|
49
|
-
<ToolbarSeparator />
|
|
50
|
-
|
|
51
|
-
<SimpleToolbarButton
|
|
52
|
-
mainTooltip="Remove link"
|
|
53
|
-
isSelected={false}
|
|
54
|
-
onClick={props.removeHandler}
|
|
55
|
-
icon={RiLinkUnlink}
|
|
56
|
-
/>
|
|
57
|
-
</Toolbar>
|
|
58
|
-
);
|
|
59
|
-
};
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import Tippy from "@tippyjs/react";
|
|
2
|
-
import { useState } from "react";
|
|
3
|
-
import { RiLink, RiText } from "react-icons/ri";
|
|
4
|
-
import { TooltipContent } from "../../../shared/components/tooltip/TooltipContent";
|
|
5
|
-
import PanelTextInput from "./atlaskit/PanelTextInput";
|
|
6
|
-
import {
|
|
7
|
-
Container,
|
|
8
|
-
ContainerWrapper,
|
|
9
|
-
IconWrapper,
|
|
10
|
-
TextInputWrapper,
|
|
11
|
-
UrlInputWrapper,
|
|
12
|
-
} from "./atlaskit/ToolbarComponent";
|
|
13
|
-
|
|
14
|
-
export type HyperlinkEditorMenuProps = {
|
|
15
|
-
url: string;
|
|
16
|
-
text: string;
|
|
17
|
-
onSubmit: (url: string, text: string) => void;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* The sub menu for editing an anchor element
|
|
22
|
-
*/
|
|
23
|
-
export const HyperlinkEditMenu = (props: HyperlinkEditorMenuProps) => {
|
|
24
|
-
const [url, setUrl] = useState(props.url);
|
|
25
|
-
const [text, setText] = useState(props.text);
|
|
26
|
-
|
|
27
|
-
return (
|
|
28
|
-
<ContainerWrapper>
|
|
29
|
-
<Container provider={false}>
|
|
30
|
-
<UrlInputWrapper>
|
|
31
|
-
<IconWrapper>
|
|
32
|
-
<Tippy
|
|
33
|
-
content={<TooltipContent mainTooltip="Edit URL" />}
|
|
34
|
-
placement="left">
|
|
35
|
-
<span>
|
|
36
|
-
<RiLink size={20}></RiLink>
|
|
37
|
-
</span>
|
|
38
|
-
</Tippy>
|
|
39
|
-
</IconWrapper>
|
|
40
|
-
<PanelTextInput
|
|
41
|
-
defaultValue={url}
|
|
42
|
-
autoFocus={true}
|
|
43
|
-
onSubmit={(value) => {
|
|
44
|
-
props.onSubmit(value, text);
|
|
45
|
-
}}
|
|
46
|
-
onChange={(value) => {
|
|
47
|
-
setUrl(value);
|
|
48
|
-
}}></PanelTextInput>
|
|
49
|
-
</UrlInputWrapper>
|
|
50
|
-
<TextInputWrapper>
|
|
51
|
-
<IconWrapper>
|
|
52
|
-
<Tippy
|
|
53
|
-
content={<TooltipContent mainTooltip="Edit title" />}
|
|
54
|
-
placement="left">
|
|
55
|
-
<span>
|
|
56
|
-
<RiText size={20} />
|
|
57
|
-
</span>
|
|
58
|
-
</Tippy>
|
|
59
|
-
</IconWrapper>
|
|
60
|
-
<PanelTextInput
|
|
61
|
-
defaultValue={text!}
|
|
62
|
-
onSubmit={(value) => {
|
|
63
|
-
props.onSubmit(url, value);
|
|
64
|
-
}}
|
|
65
|
-
onChange={(value) => {
|
|
66
|
-
setText(value);
|
|
67
|
-
}}></PanelTextInput>
|
|
68
|
-
</TextInputWrapper>
|
|
69
|
-
</Container>
|
|
70
|
-
</ContainerWrapper>
|
|
71
|
-
);
|
|
72
|
-
};
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
import { KeyboardEvent, PureComponent } from "react";
|
|
2
|
-
import { Input } from "./PanelTextInputStyles";
|
|
3
|
-
import { FocusEvent } from "react";
|
|
4
|
-
import browser from "../../../../lib/atlaskit/browser";
|
|
5
|
-
|
|
6
|
-
// code adapted from https://bitbucket.org/atlassian/design-system-mirror/src/master/editor/editor-core/src/ui/PanelTextInput/index.tsx
|
|
7
|
-
|
|
8
|
-
export interface Props {
|
|
9
|
-
autoFocus?: boolean | FocusOptions;
|
|
10
|
-
defaultValue?: string;
|
|
11
|
-
onChange?: (value: string) => void;
|
|
12
|
-
onSubmit?: (value: string) => void;
|
|
13
|
-
onCancel?: (e: KeyboardEvent) => void;
|
|
14
|
-
placeholder?: string;
|
|
15
|
-
onMouseDown?: Function;
|
|
16
|
-
onKeyDown?: (e: KeyboardEvent<any>) => void;
|
|
17
|
-
// overrides default browser undo behaviour (cmd/ctrl + z) with that function
|
|
18
|
-
onUndo?: Function;
|
|
19
|
-
// overrides default browser redo behaviour (cm + shift + z / ctrl + y) with that function
|
|
20
|
-
onRedo?: Function;
|
|
21
|
-
onBlur?: Function;
|
|
22
|
-
width?: number;
|
|
23
|
-
maxLength?: number;
|
|
24
|
-
testId?: string;
|
|
25
|
-
ariaLabel?: string;
|
|
26
|
-
id?: string;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export interface State {
|
|
30
|
-
value?: string;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const KeyZCode = 90;
|
|
34
|
-
const KeyYCode = 89;
|
|
35
|
-
|
|
36
|
-
// returns an <Input> Component, used as an input field in HyperlinkEditMenu
|
|
37
|
-
export default class PanelTextInput extends PureComponent<Props, State> {
|
|
38
|
-
private input?: HTMLInputElement;
|
|
39
|
-
private focusTimeoutId: number | undefined;
|
|
40
|
-
|
|
41
|
-
constructor(props: Props) {
|
|
42
|
-
super(props);
|
|
43
|
-
|
|
44
|
-
this.state = {
|
|
45
|
-
value: props.defaultValue || "",
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
UNSAFE_componentWillReceiveProps(nextProps: Props) {
|
|
50
|
-
if (nextProps.defaultValue !== this.props.defaultValue) {
|
|
51
|
-
this.setState({
|
|
52
|
-
value: nextProps.defaultValue,
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
componentWillUnmount() {
|
|
58
|
-
window.clearTimeout(this.focusTimeoutId);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
onMouseDown = () => {
|
|
62
|
-
const { onMouseDown } = this.props;
|
|
63
|
-
if (onMouseDown) {
|
|
64
|
-
onMouseDown();
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
onBlur = (e: FocusEvent<any>) => {
|
|
69
|
-
const { onBlur } = this.props;
|
|
70
|
-
if (onBlur) {
|
|
71
|
-
onBlur(e);
|
|
72
|
-
}
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
render() {
|
|
76
|
-
const { placeholder, width, maxLength, testId, ariaLabel } = this.props;
|
|
77
|
-
const { value } = this.state;
|
|
78
|
-
return (
|
|
79
|
-
<Input
|
|
80
|
-
data-testid={testId || ""}
|
|
81
|
-
type="text"
|
|
82
|
-
placeholder={placeholder}
|
|
83
|
-
value={value}
|
|
84
|
-
onChange={this.handleChange}
|
|
85
|
-
onKeyDown={this.handleKeydown}
|
|
86
|
-
onMouseDown={this.onMouseDown}
|
|
87
|
-
onBlur={this.onBlur}
|
|
88
|
-
ref={this.handleRef}
|
|
89
|
-
width={width}
|
|
90
|
-
maxLength={maxLength}
|
|
91
|
-
aria-label={ariaLabel}
|
|
92
|
-
id={this.props.id}
|
|
93
|
-
style={{ fontSize: `0.8rem` }}
|
|
94
|
-
/>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
focus() {
|
|
99
|
-
const { input } = this;
|
|
100
|
-
if (input) {
|
|
101
|
-
const focusOpts =
|
|
102
|
-
typeof this.props.autoFocus === "object" ? this.props.autoFocus : {};
|
|
103
|
-
input.focus(focusOpts);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
private handleChange = () => {
|
|
108
|
-
const { onChange } = this.props;
|
|
109
|
-
if (this.input) {
|
|
110
|
-
this.setState({
|
|
111
|
-
value: this.input.value,
|
|
112
|
-
});
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (onChange && this.input) {
|
|
116
|
-
onChange(this.input.value);
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
private handleKeydown = (e: KeyboardEvent<any>) => {
|
|
121
|
-
const { onUndo, onRedo, onSubmit, onCancel } = this.props;
|
|
122
|
-
if (e.keyCode === 13 && onSubmit) {
|
|
123
|
-
e.preventDefault(); // Prevent from submitting if an editor is inside a form.
|
|
124
|
-
onSubmit(this.input!.value);
|
|
125
|
-
} else if (e.keyCode === 27 && onCancel) {
|
|
126
|
-
onCancel(e);
|
|
127
|
-
} else if (typeof onUndo === "function" && this.isUndoEvent(e)) {
|
|
128
|
-
e.preventDefault();
|
|
129
|
-
onUndo();
|
|
130
|
-
} else if (typeof onRedo === "function" && this.isRedoEvent(e)) {
|
|
131
|
-
e.preventDefault();
|
|
132
|
-
onRedo();
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (this.props.onKeyDown) {
|
|
136
|
-
this.props.onKeyDown(e);
|
|
137
|
-
}
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
private isUndoEvent(event: KeyboardEvent<any>) {
|
|
141
|
-
return (
|
|
142
|
-
event.keyCode === KeyZCode &&
|
|
143
|
-
// cmd + z for mac
|
|
144
|
-
((browser.mac && event.metaKey && !event.shiftKey) ||
|
|
145
|
-
// ctrl + z for non-mac
|
|
146
|
-
(!browser.mac && event.ctrlKey))
|
|
147
|
-
);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private isRedoEvent(event: KeyboardEvent<any>) {
|
|
151
|
-
return (
|
|
152
|
-
// ctrl + y for non-mac
|
|
153
|
-
(!browser.mac && event.ctrlKey && event.keyCode === KeyYCode) ||
|
|
154
|
-
(browser.mac &&
|
|
155
|
-
event.metaKey &&
|
|
156
|
-
event.shiftKey &&
|
|
157
|
-
event.keyCode === KeyZCode) ||
|
|
158
|
-
(event.ctrlKey && event.shiftKey && event.keyCode === KeyZCode)
|
|
159
|
-
);
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
private handleRef = (input: HTMLInputElement | null) => {
|
|
163
|
-
if (input instanceof HTMLInputElement) {
|
|
164
|
-
this.input = input;
|
|
165
|
-
if (this.props.autoFocus) {
|
|
166
|
-
// Need this to prevent jumping when we render TextInput inside Portal @see ED-2992
|
|
167
|
-
this.focusTimeoutId = window.setTimeout(() => this.focus());
|
|
168
|
-
}
|
|
169
|
-
} else {
|
|
170
|
-
this.input = undefined;
|
|
171
|
-
}
|
|
172
|
-
};
|
|
173
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { N400, N800 } from "@atlaskit/theme/colors";
|
|
2
|
-
import styled from "styled-components";
|
|
3
|
-
|
|
4
|
-
// code taken from https://bitbucket.org/atlassian/design-system-mirror/src/master/editor/editor-core/src/ui/PanelTextInput/styles.ts
|
|
5
|
-
|
|
6
|
-
// Normal .className gets overridden by input[type=text] hence this hack to produce input.className
|
|
7
|
-
export const Input = styled.input`
|
|
8
|
-
input& {
|
|
9
|
-
autofocus: true;
|
|
10
|
-
background: transparent;
|
|
11
|
-
border: 0;
|
|
12
|
-
border-radius: 0;
|
|
13
|
-
box-sizing: content-box;
|
|
14
|
-
color: ${N400};
|
|
15
|
-
flex-grow: 1;
|
|
16
|
-
font-size: 13px;
|
|
17
|
-
line-height: 20px;
|
|
18
|
-
padding: 0;
|
|
19
|
-
${(props) => (props.width ? `width: ${props.width}px` : "")};
|
|
20
|
-
min-width: 145px;
|
|
21
|
-
|
|
22
|
-
/* Hides IE10+ built-in [x] clear input button */
|
|
23
|
-
&::-ms-clear {
|
|
24
|
-
display: none;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
&:focus {
|
|
28
|
-
outline: none;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
&::placeholder {
|
|
32
|
-
color: ${N800};
|
|
33
|
-
opacity: 0.5;
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
`;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
Helper code copied from AtlasKit
|