@atlaskit/editor-plugin-block-controls 1.1.0 → 1.3.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.
- package/CHANGELOG.md +23 -3
- package/dist/cjs/plugin.js +36 -2
- package/dist/cjs/pm-plugins/decorations.js +71 -0
- package/dist/cjs/pm-plugins/main.js +95 -4
- package/dist/cjs/ui/consts.js +8 -0
- package/dist/cjs/ui/drag-handle-menu.js +15 -0
- package/dist/cjs/ui/drag-handle.js +93 -0
- package/dist/cjs/ui/drag-preview.js +35 -0
- package/dist/cjs/ui/drop-target.js +72 -0
- package/dist/cjs/ui/global-styles.js +19 -0
- package/dist/es2019/plugin.js +35 -3
- package/dist/es2019/pm-plugins/decorations.js +64 -0
- package/dist/es2019/pm-plugins/main.js +97 -5
- package/dist/es2019/ui/consts.js +2 -0
- package/dist/es2019/ui/drag-handle-menu.js +10 -0
- package/dist/es2019/ui/drag-handle.js +86 -0
- package/dist/es2019/ui/drag-preview.js +27 -0
- package/dist/es2019/ui/drop-target.js +55 -0
- package/dist/es2019/ui/global-styles.js +12 -0
- package/dist/esm/plugin.js +36 -3
- package/dist/esm/pm-plugins/decorations.js +64 -0
- package/dist/esm/pm-plugins/main.js +95 -4
- package/dist/esm/ui/consts.js +2 -0
- package/dist/esm/ui/drag-handle-menu.js +8 -0
- package/dist/esm/ui/drag-handle.js +86 -0
- package/dist/esm/ui/drag-preview.js +29 -0
- package/dist/esm/ui/drop-target.js +62 -0
- package/dist/esm/ui/global-styles.js +12 -0
- package/dist/types/pm-plugins/decorations.d.ts +12 -0
- package/dist/types/pm-plugins/main.d.ts +2 -9
- package/dist/types/types.d.ts +25 -2
- package/dist/types/ui/consts.d.ts +2 -0
- package/dist/types/ui/drag-handle-menu.d.ts +6 -0
- package/dist/types/ui/drag-handle.d.ts +8 -0
- package/dist/types/ui/drag-preview.d.ts +1 -0
- package/dist/types/ui/drop-target.d.ts +7 -0
- package/dist/types/ui/global-styles.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -9
- package/dist/types-ts4.5/types.d.ts +25 -2
- package/dist/types-ts4.5/ui/consts.d.ts +2 -0
- package/dist/types-ts4.5/ui/drag-handle-menu.d.ts +6 -0
- package/dist/types-ts4.5/ui/drag-handle.d.ts +8 -0
- package/dist/types-ts4.5/ui/drag-preview.d.ts +1 -0
- package/dist/types-ts4.5/ui/drop-target.d.ts +7 -0
- package/dist/types-ts4.5/ui/global-styles.d.ts +3 -0
- package/package.json +7 -4
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
export var dragPreview = function dragPreview(container, domRef) {
|
|
2
|
+
var rect = domRef.current.getBoundingClientRect();
|
|
3
|
+
container.style.width = "".concat(rect.width, "px");
|
|
4
|
+
container.style.height = "".concat(rect.height, "px");
|
|
5
|
+
container.style.pointerEvents = 'none';
|
|
6
|
+
var parent = document.createElement('div');
|
|
7
|
+
// ProseMirror class is required to make sure the cloned dom is styled correctly
|
|
8
|
+
parent.classList.add('ProseMirror');
|
|
9
|
+
var clonedDom = domRef.current.cloneNode(true);
|
|
10
|
+
|
|
11
|
+
// Remove any margin from the cloned element to ensure is doesn't position incorrectly
|
|
12
|
+
clonedDom.style.marginLeft = '0';
|
|
13
|
+
clonedDom.style.marginTop = '0';
|
|
14
|
+
clonedDom.style.marginRight = '0';
|
|
15
|
+
clonedDom.style.marginBottom = '0';
|
|
16
|
+
parent.appendChild(clonedDom);
|
|
17
|
+
container.appendChild(parent);
|
|
18
|
+
var scrollParent = document.querySelector('.fabric-editor-popup-scroll-parent');
|
|
19
|
+
var scrollParentClassNames = scrollParent === null || scrollParent === void 0 ? void 0 : scrollParent.className;
|
|
20
|
+
|
|
21
|
+
// Add the scroll parent class to the container to ensure the cloned element is styled correctly
|
|
22
|
+
container.className = scrollParentClassNames || '';
|
|
23
|
+
container.classList.remove('fabric-editor-popup-scroll-parent');
|
|
24
|
+
// Prevents a scrollbar from showing
|
|
25
|
+
container.style.overflow = 'visible';
|
|
26
|
+
return function () {
|
|
27
|
+
return container;
|
|
28
|
+
};
|
|
29
|
+
};
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import React, { useEffect, useRef, useState } from 'react';
|
|
3
|
+
import { dropTargetForElements } from '@atlaskit/pragmatic-drag-and-drop/element/adapter';
|
|
4
|
+
export var DropTarget = function DropTarget(_ref) {
|
|
5
|
+
var api = _ref.api,
|
|
6
|
+
index = _ref.index;
|
|
7
|
+
var ref = useRef(null);
|
|
8
|
+
var _useState = useState(false),
|
|
9
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
10
|
+
isDraggedOver = _useState2[0],
|
|
11
|
+
setIsDraggedOver = _useState2[1];
|
|
12
|
+
useEffect(function () {
|
|
13
|
+
var element = ref.current;
|
|
14
|
+
if (!element) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
return dropTargetForElements({
|
|
18
|
+
element: element,
|
|
19
|
+
getIsSticky: function getIsSticky() {
|
|
20
|
+
return true;
|
|
21
|
+
},
|
|
22
|
+
onDragEnter: function onDragEnter() {
|
|
23
|
+
return setIsDraggedOver(true);
|
|
24
|
+
},
|
|
25
|
+
onDragLeave: function onDragLeave() {
|
|
26
|
+
return setIsDraggedOver(false);
|
|
27
|
+
},
|
|
28
|
+
onDrop: function onDrop() {
|
|
29
|
+
var _api$blockControls;
|
|
30
|
+
var _ref2 = (api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.currentState()) || {},
|
|
31
|
+
activeNode = _ref2.activeNode,
|
|
32
|
+
decorationState = _ref2.decorationState;
|
|
33
|
+
if (!activeNode || !decorationState) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
var _ref3 = decorationState.find(function (dec) {
|
|
37
|
+
return dec.index === index;
|
|
38
|
+
}) || {},
|
|
39
|
+
pos = _ref3.pos;
|
|
40
|
+
if (activeNode && pos !== undefined) {
|
|
41
|
+
var _api$core, _api$blockControls2;
|
|
42
|
+
var start = activeNode.pos;
|
|
43
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.moveNode(start, pos));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}, [index, api]);
|
|
48
|
+
return (
|
|
49
|
+
/*#__PURE__*/
|
|
50
|
+
// Note: Firefox has trouble with using a button element as the handle for drag and drop
|
|
51
|
+
React.createElement("div", {
|
|
52
|
+
style: {
|
|
53
|
+
height: '20px',
|
|
54
|
+
marginTop: '-22px',
|
|
55
|
+
top: '10px',
|
|
56
|
+
position: 'relative',
|
|
57
|
+
borderBottom: "solid ".concat(isDraggedOver ? 'blue' : 'transparent', " 2px")
|
|
58
|
+
},
|
|
59
|
+
ref: ref
|
|
60
|
+
})
|
|
61
|
+
);
|
|
62
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import { css, Global, jsx } from '@emotion/react';
|
|
3
|
+
var globalStyles = css({
|
|
4
|
+
'.ProseMirror-widget:first-child + *': {
|
|
5
|
+
'margin-top': '0 !important'
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
export var GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
9
|
+
return jsx(Global, {
|
|
10
|
+
styles: globalStyles
|
|
11
|
+
});
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { BlockControlsPlugin } from '../types';
|
|
5
|
+
export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
|
|
6
|
+
decs: Decoration[];
|
|
7
|
+
decorationState: {
|
|
8
|
+
index: number;
|
|
9
|
+
pos: number;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export declare const dragHandleDecoration: (oldState: EditorState, meta: any, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import {
|
|
5
|
-
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
import type { BlockControlsPlugin, PluginState } from '../types';
|
|
6
5
|
export declare const key: PluginKey<PluginState>;
|
|
7
|
-
export
|
|
8
|
-
decorations: DecorationSet;
|
|
9
|
-
isDragging: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<{
|
|
12
|
-
decorations: DecorationSet;
|
|
13
|
-
}>;
|
|
6
|
+
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<PluginState>;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -1,7 +1,30 @@
|
|
|
1
|
-
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export interface PluginState {
|
|
4
|
+
decorations: DecorationSet;
|
|
5
|
+
decorationState: DecorationState;
|
|
6
|
+
isDragging: boolean;
|
|
7
|
+
isMenuOpen?: boolean;
|
|
8
|
+
activeNode: {
|
|
9
|
+
pos: number;
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
2
12
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
3
13
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
4
14
|
dependencies: [];
|
|
5
|
-
sharedState:
|
|
15
|
+
sharedState: {
|
|
16
|
+
isMenuOpen: boolean;
|
|
17
|
+
activeNode: {
|
|
18
|
+
pos: number;
|
|
19
|
+
};
|
|
20
|
+
decorationState: DecorationState;
|
|
21
|
+
} | undefined;
|
|
6
22
|
actions: {};
|
|
23
|
+
commands: {
|
|
24
|
+
moveNode: (start: number, to: number) => EditorCommand;
|
|
25
|
+
};
|
|
7
26
|
}>;
|
|
27
|
+
export type DecorationState = {
|
|
28
|
+
index: number;
|
|
29
|
+
pos: number;
|
|
30
|
+
}[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
export declare const DragHandleMenu: ({ api, }: {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
|
+
}) => JSX.Element | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx } from '@emotion/react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
export declare const DragHandle: ({ dom, api, start, }: {
|
|
5
|
+
dom: HTMLElement;
|
|
6
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
7
|
+
start: number;
|
|
8
|
+
}) => jsx.JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dragPreview: (container: HTMLElement, domRef: React.MutableRefObject<HTMLElement>) => () => HTMLElement;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
export declare const DropTarget: ({ api, index, }: {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
|
+
index: number;
|
|
7
|
+
}) => JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorState } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { BlockControlsPlugin } from '../types';
|
|
5
|
+
export declare const dropTargetDecorations: (oldState: EditorState, newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => {
|
|
6
|
+
decs: Decoration[];
|
|
7
|
+
decorationState: {
|
|
8
|
+
index: number;
|
|
9
|
+
pos: number;
|
|
10
|
+
}[];
|
|
11
|
+
};
|
|
12
|
+
export declare const dragHandleDecoration: (oldState: EditorState, meta: any, api: ExtractInjectionAPI<BlockControlsPlugin>) => DecorationSet;
|
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import {
|
|
5
|
-
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
import type { BlockControlsPlugin, PluginState } from '../types';
|
|
6
5
|
export declare const key: PluginKey<PluginState>;
|
|
7
|
-
export
|
|
8
|
-
decorations: DecorationSet;
|
|
9
|
-
isDragging: boolean;
|
|
10
|
-
}
|
|
11
|
-
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<{
|
|
12
|
-
decorations: DecorationSet;
|
|
13
|
-
}>;
|
|
6
|
+
export declare const createPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined) => SafePlugin<PluginState>;
|
|
@@ -1,8 +1,31 @@
|
|
|
1
|
-
import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
1
|
+
import type { EditorCommand, NextEditorPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { type DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export interface PluginState {
|
|
4
|
+
decorations: DecorationSet;
|
|
5
|
+
decorationState: DecorationState;
|
|
6
|
+
isDragging: boolean;
|
|
7
|
+
isMenuOpen?: boolean;
|
|
8
|
+
activeNode: {
|
|
9
|
+
pos: number;
|
|
10
|
+
} | null;
|
|
11
|
+
}
|
|
2
12
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
3
13
|
export type BlockControlsPlugin = NextEditorPlugin<'blockControls', {
|
|
4
14
|
dependencies: [
|
|
5
15
|
];
|
|
6
|
-
sharedState:
|
|
16
|
+
sharedState: {
|
|
17
|
+
isMenuOpen: boolean;
|
|
18
|
+
activeNode: {
|
|
19
|
+
pos: number;
|
|
20
|
+
};
|
|
21
|
+
decorationState: DecorationState;
|
|
22
|
+
} | undefined;
|
|
7
23
|
actions: {};
|
|
24
|
+
commands: {
|
|
25
|
+
moveNode: (start: number, to: number) => EditorCommand;
|
|
26
|
+
};
|
|
8
27
|
}>;
|
|
28
|
+
export type DecorationState = {
|
|
29
|
+
index: number;
|
|
30
|
+
pos: number;
|
|
31
|
+
}[];
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
export declare const DragHandleMenu: ({ api, }: {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
|
+
}) => JSX.Element | null;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx } from '@emotion/react';
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
export declare const DragHandle: ({ dom, api, start, }: {
|
|
5
|
+
dom: HTMLElement;
|
|
6
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
7
|
+
start: number;
|
|
8
|
+
}) => jsx.JSX.Element;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const dragPreview: (container: HTMLElement, domRef: React.MutableRefObject<HTMLElement>) => () => HTMLElement;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
|
+
import type { BlockControlsPlugin } from '../types';
|
|
4
|
+
export declare const DropTarget: ({ api, index, }: {
|
|
5
|
+
api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
|
|
6
|
+
index: number;
|
|
7
|
+
}) => JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.0",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,12 +31,15 @@
|
|
|
31
31
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^78.
|
|
34
|
+
"@atlaskit/editor-common": "^78.37.0",
|
|
35
35
|
"@atlaskit/editor-prosemirror": "4.0.0",
|
|
36
|
-
"@
|
|
36
|
+
"@atlaskit/pragmatic-drag-and-drop": "^1.1.0",
|
|
37
|
+
"@babel/runtime": "^7.0.0",
|
|
38
|
+
"@emotion/react": "^11.7.1"
|
|
37
39
|
},
|
|
38
40
|
"peerDependencies": {
|
|
39
|
-
"react": "^16.8.0"
|
|
41
|
+
"react": "^16.8.0",
|
|
42
|
+
"react-dom": "^16.8.0"
|
|
40
43
|
},
|
|
41
44
|
"devDependencies": {
|
|
42
45
|
"@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0"
|