@atlaskit/editor-plugin-block-controls 17.1.4 → 17.1.5

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 (36) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/cjs/blockControlsPlugin.js +8 -3
  3. package/dist/cjs/pm-plugins/main.js +30 -4
  4. package/dist/cjs/pm-plugins/utils/surface-node-positions.js +71 -0
  5. package/dist/cjs/ui/block-controls-left-surface-targets.js +45 -0
  6. package/dist/cjs/ui/block-controls-left-surface.js +45 -0
  7. package/dist/cjs/ui/block-controls-left-surfaces.js +216 -0
  8. package/dist/cjs/ui/block-controls-surface-context.js +23 -17
  9. package/dist/es2019/blockControlsPlugin.js +8 -3
  10. package/dist/es2019/pm-plugins/main.js +31 -6
  11. package/dist/es2019/pm-plugins/utils/surface-node-positions.js +56 -0
  12. package/dist/es2019/ui/block-controls-left-surface-targets.js +25 -0
  13. package/dist/es2019/ui/block-controls-left-surface.js +39 -0
  14. package/dist/es2019/ui/block-controls-left-surfaces.js +181 -0
  15. package/dist/es2019/ui/block-controls-surface-context.js +21 -15
  16. package/dist/esm/blockControlsPlugin.js +8 -3
  17. package/dist/esm/pm-plugins/main.js +30 -4
  18. package/dist/esm/pm-plugins/utils/surface-node-positions.js +64 -0
  19. package/dist/esm/ui/block-controls-left-surface-targets.js +39 -0
  20. package/dist/esm/ui/block-controls-left-surface.js +38 -0
  21. package/dist/esm/ui/block-controls-left-surfaces.js +207 -0
  22. package/dist/esm/ui/block-controls-surface-context.js +22 -16
  23. package/dist/types/blockControlsPluginType.d.ts +2 -0
  24. package/dist/types/pm-plugins/main.d.ts +6 -2
  25. package/dist/types/pm-plugins/utils/surface-node-positions.d.ts +14 -0
  26. package/dist/types/ui/block-controls-left-surface-targets.d.ts +7 -0
  27. package/dist/types/ui/block-controls-left-surface.d.ts +23 -0
  28. package/dist/types/ui/{block-controls-surface.d.ts → block-controls-left-surfaces.d.ts} +1 -1
  29. package/dist/types/ui/block-controls-surface-context.d.ts +2 -0
  30. package/package.json +2 -2
  31. package/dist/cjs/ui/block-controls-surface.js +0 -185
  32. package/dist/es2019/ui/block-controls-surface.js +0 -170
  33. package/dist/esm/ui/block-controls-surface.js +0 -176
  34. /package/dist/cjs/ui/{block-controls-surface.compiled.css → block-controls-left-surface.compiled.css} +0 -0
  35. /package/dist/es2019/ui/{block-controls-surface.compiled.css → block-controls-left-surface.compiled.css} +0 -0
  36. /package/dist/esm/ui/{block-controls-surface.compiled.css → block-controls-left-surface.compiled.css} +0 -0
@@ -1,4 +1,6 @@
1
1
  import type { BlockControlUIContext } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
2
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
4
  import type { ActiveNode } from '../blockControlsPluginType';
5
+ export declare const createBlockControlsSurfaceContextForPosition: (state: EditorState, targetPos: number, activeNode?: ActiveNode) => BlockControlUIContext | undefined;
4
6
  export declare const createBlockControlsSurfaceContext: (view: EditorView, activeNode: ActiveNode | undefined, target?: 'active' | 'root') => BlockControlUIContext | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-block-controls",
3
- "version": "17.1.4",
3
+ "version": "17.1.5",
4
4
  "description": "Block controls plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -67,7 +67,7 @@
67
67
  "uuid": "^3.1.0"
68
68
  },
69
69
  "peerDependencies": {
70
- "@atlaskit/editor-common": "^120.3.0",
70
+ "@atlaskit/editor-common": "^120.5.0",
71
71
  "react": "^18.2.0 || ^19.2.0",
72
72
  "react-dom": "^18.2.0 || ^19.2.0",
73
73
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"
@@ -1,185 +0,0 @@
1
- /* block-controls-surface.tsx generated by @compiled/babel-plugin v2.0.0 */
2
- "use strict";
3
-
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
5
- var _typeof = require("@babel/runtime/helpers/typeof");
6
- Object.defineProperty(exports, "__esModule", {
7
- value: true
8
- });
9
- exports.BlockControlsSurface = void 0;
10
- require("./block-controls-surface.compiled.css");
11
- var _runtime = require("@compiled/react/runtime");
12
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
13
- var _react = _interopRequireWildcard(require("react"));
14
- var _bindEventListener = require("bind-event-listener");
15
- var _browserApis = require("@atlaskit/browser-apis");
16
- var _blockControlUiContext = require("@atlaskit/editor-common/block-controls/block-control-ui-context");
17
- var _surfaceKeys = require("@atlaskit/editor-common/block-controls/surface-keys");
18
- var _hooks = require("@atlaskit/editor-common/hooks");
19
- var _surfaceRenderer = require("@atlaskit/editor-ui-control-model/surface-renderer");
20
- var _types = require("@atlaskit/editor-ui-control-model/types");
21
- var _decorationsCommon = require("../pm-plugins/decorations-common");
22
- var _blockControlsSurfaceContext = require("./block-controls-surface-context");
23
- var _getNodeContentElement = require("./utils/get-node-content-element");
24
- var _getSurfacePlacement = require("./utils/get-surface-placement");
25
- var _visibilityContainer = require("./visibility-container");
26
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
27
- var BLOCK_CONTROLS_SURFACE_Z_INDEX = 100;
28
- var surfaceStyles = null;
29
- var BlockControlsSurfaceAtTarget = function BlockControlsSurfaceAtTarget(_ref) {
30
- var _api$uiControlRegistr, _api$uiControlRegistr2, _activeNode$handleOpt;
31
- var activeNode = _ref.activeNode,
32
- api = _ref.api,
33
- editorView = _ref.editorView,
34
- target = _ref.target;
35
- var _useState = (0, _react.useState)(),
36
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
- position = _useState2[0],
38
- setPosition = _useState2[1];
39
- var animationFrameRef = (0, _react.useRef)(undefined);
40
- var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(_surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
41
- var blockControlsContext = (0, _react.useMemo)(function () {
42
- return (0, _blockControlsSurfaceContext.createBlockControlsSurfaceContext)(editorView, activeNode, target);
43
- }, [activeNode, editorView, target]);
44
- var surfaceContext = (0, _react.useMemo)(function () {
45
- return blockControlsContext ? (0, _types.createSurfaceContext)(_blockControlUiContext.BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
46
- }, [blockControlsContext]);
47
- (0, _react.useLayoutEffect)(function () {
48
- var _getDocument;
49
- if (!blockControlsContext) {
50
- setPosition(undefined);
51
- return;
52
- }
53
- var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
54
- var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
55
- if (!targetElementRoot) {
56
- setPosition(undefined);
57
- return;
58
- }
59
- var targetElement = (0, _getNodeContentElement.getNodeContentElement)(targetElementRoot, blockControlsContext.targetNode.type.name);
60
- var offsetParent = editorView.dom.offsetParent;
61
- var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = (0, _browserApis.getDocument)()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
62
- var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
63
- var updatePosition = function updatePosition() {
64
- var _targetElementRoot$ge, _scrollingOffsetParen, _scrollingOffsetParen2;
65
- animationFrameRef.current = undefined;
66
- if (!targetElementRoot.isConnected || !targetElement.isConnected) {
67
- setPosition(undefined);
68
- return;
69
- }
70
- var placement = (0, _getSurfacePlacement.getSurfacePlacement)({
71
- layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
72
- nodeRect: targetElement.getBoundingClientRect(),
73
- nodeType: blockControlsContext.targetNode.type.name,
74
- nodeTypeWithLevel: (0, _decorationsCommon.getNodeTypeWithLevel)(blockControlsContext.targetNode.node),
75
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
76
- });
77
- var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
78
- var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
79
- var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
80
- setPosition((0, _getSurfacePlacement.getAbsoluteSurfacePlacement)({
81
- offsetParentRect: offsetParentRect,
82
- offsetParentScrollLeft: offsetParentScrollLeft,
83
- offsetParentScrollTop: offsetParentScrollTop,
84
- placement: placement
85
- }));
86
- };
87
- var schedulePositionUpdate = function schedulePositionUpdate() {
88
- if (animationFrameRef.current === undefined) {
89
- animationFrameRef.current = requestAnimationFrame(updatePosition);
90
- }
91
- };
92
- updatePosition();
93
- var resizeObserver = new ResizeObserver(schedulePositionUpdate);
94
- resizeObserver.observe(editorView.dom);
95
- if (targetElement && targetElement !== editorView.dom) {
96
- resizeObserver.observe(targetElement);
97
- }
98
- if (offsetParent instanceof HTMLElement && offsetParent !== editorView.dom) {
99
- resizeObserver.observe(offsetParent);
100
- }
101
- var unbindWindowResize = (0, _bindEventListener.bind)(window, {
102
- type: 'resize',
103
- listener: schedulePositionUpdate
104
- });
105
- var unbindWindowScroll = (0, _bindEventListener.bind)(window, {
106
- type: 'scroll',
107
- listener: schedulePositionUpdate,
108
- options: {
109
- capture: true,
110
- passive: true
111
- }
112
- });
113
- var visualViewport = window.visualViewport;
114
- var unbindVisualViewportResize = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
115
- type: 'resize',
116
- listener: schedulePositionUpdate
117
- }) : undefined;
118
- var unbindVisualViewportScroll = visualViewport ? (0, _bindEventListener.bind)(visualViewport, {
119
- type: 'scroll',
120
- listener: schedulePositionUpdate
121
- }) : undefined;
122
- var unbindTransitionEnd = (0, _bindEventListener.bind)(targetElement, {
123
- type: 'transitionend',
124
- listener: schedulePositionUpdate
125
- });
126
- return function () {
127
- if (animationFrameRef.current !== undefined) {
128
- cancelAnimationFrame(animationFrameRef.current);
129
- animationFrameRef.current = undefined;
130
- }
131
- resizeObserver.disconnect();
132
- unbindWindowResize();
133
- unbindWindowScroll();
134
- unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
135
- unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
136
- unbindTransitionEnd();
137
- };
138
- }, [blockControlsContext, editorView]);
139
- if (components.length === 0 || !blockControlsContext || !surfaceContext || !position || !(0, _surfaceRenderer.willSurfaceRender)(components, _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
140
- return null;
141
- }
142
- return /*#__PURE__*/_react.default.createElement("div", {
143
- "data-editor-block-controls-surface": true
144
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the active node's runtime DOM geometry.
145
- ,
146
- style: position,
147
- "data-testid": target === 'root' ? 'block-controls-left-surface' : 'block-controls-left-surface-active',
148
- className: (0, _runtime.ax)(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
149
- }, /*#__PURE__*/_react.default.createElement(_visibilityContainer.VisibilityContainer, {
150
- api: api,
151
- controlSide: "left",
152
- forceVisibleOnMouseOut: Boolean((_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
153
- shouldUseDisplayContents: true
154
- }, /*#__PURE__*/_react.default.createElement(_surfaceRenderer.SurfaceRenderer, {
155
- components: components,
156
- surface: _surfaceKeys.BLOCK_CONTROLS_LEFT_SURFACE,
157
- surfaceContext: surfaceContext
158
- })));
159
- };
160
- var BlockControlsSurface = exports.BlockControlsSurface = function BlockControlsSurface(_ref2) {
161
- var _activeNode$rootPos;
162
- var api = _ref2.api,
163
- editorView = _ref2.editorView;
164
- var activeNode = (0, _hooks.useSharedPluginStateWithSelector)(api, ['blockControls'], function (states) {
165
- var _states$blockControls;
166
- return {
167
- activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode
168
- };
169
- }).activeNode;
170
- if (!activeNode) {
171
- return null;
172
- }
173
- var rootPos = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
174
- return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, /*#__PURE__*/_react.default.createElement(BlockControlsSurfaceAtTarget, {
175
- activeNode: activeNode,
176
- api: api,
177
- editorView: editorView,
178
- target: "root"
179
- }), rootPos !== activeNode.pos ? /*#__PURE__*/_react.default.createElement(BlockControlsSurfaceAtTarget, {
180
- activeNode: activeNode,
181
- api: api,
182
- editorView: editorView,
183
- target: "active"
184
- }) : null);
185
- };
@@ -1,170 +0,0 @@
1
- /* block-controls-surface.tsx generated by @compiled/babel-plugin v2.0.0 */
2
- import "./block-controls-surface.compiled.css";
3
- import { ax, ix } from "@compiled/react/runtime";
4
- import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
5
- import { bind } from 'bind-event-listener';
6
- import { getDocument } from '@atlaskit/browser-apis';
7
- import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
8
- import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
9
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
10
- import { SurfaceRenderer, willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
11
- import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/types';
12
- import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
13
- import { createBlockControlsSurfaceContext } from './block-controls-surface-context';
14
- import { getNodeContentElement } from './utils/get-node-content-element';
15
- import { getAbsoluteSurfacePlacement, getSurfacePlacement } from './utils/get-surface-placement';
16
- import { VisibilityContainer } from './visibility-container';
17
- const BLOCK_CONTROLS_SURFACE_Z_INDEX = 100;
18
- const surfaceStyles = null;
19
- const BlockControlsSurfaceAtTarget = ({
20
- activeNode,
21
- api,
22
- editorView,
23
- target
24
- }) => {
25
- var _api$uiControlRegistr, _api$uiControlRegistr2, _activeNode$handleOpt;
26
- const [position, setPosition] = useState();
27
- const animationFrameRef = useRef(undefined);
28
- const components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
29
- const blockControlsContext = useMemo(() => createBlockControlsSurfaceContext(editorView, activeNode, target), [activeNode, editorView, target]);
30
- const surfaceContext = useMemo(() => blockControlsContext ? createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined, [blockControlsContext]);
31
- useLayoutEffect(() => {
32
- var _getDocument;
33
- if (!blockControlsContext) {
34
- setPosition(undefined);
35
- return;
36
- }
37
- const targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
38
- const targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
39
- if (!targetElementRoot) {
40
- setPosition(undefined);
41
- return;
42
- }
43
- const targetElement = getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name);
44
- const offsetParent = editorView.dom.offsetParent;
45
- const isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
46
- const scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
47
- const updatePosition = () => {
48
- var _targetElementRoot$ge, _scrollingOffsetParen, _scrollingOffsetParen2;
49
- animationFrameRef.current = undefined;
50
- if (!targetElementRoot.isConnected || !targetElement.isConnected) {
51
- setPosition(undefined);
52
- return;
53
- }
54
- const placement = getSurfacePlacement({
55
- layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
56
- nodeRect: targetElement.getBoundingClientRect(),
57
- nodeType: blockControlsContext.targetNode.type.name,
58
- nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
59
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
60
- });
61
- const offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
62
- const offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
63
- const offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
64
- setPosition(getAbsoluteSurfacePlacement({
65
- offsetParentRect,
66
- offsetParentScrollLeft,
67
- offsetParentScrollTop,
68
- placement
69
- }));
70
- };
71
- const schedulePositionUpdate = () => {
72
- if (animationFrameRef.current === undefined) {
73
- animationFrameRef.current = requestAnimationFrame(updatePosition);
74
- }
75
- };
76
- updatePosition();
77
- const resizeObserver = new ResizeObserver(schedulePositionUpdate);
78
- resizeObserver.observe(editorView.dom);
79
- if (targetElement && targetElement !== editorView.dom) {
80
- resizeObserver.observe(targetElement);
81
- }
82
- if (offsetParent instanceof HTMLElement && offsetParent !== editorView.dom) {
83
- resizeObserver.observe(offsetParent);
84
- }
85
- const unbindWindowResize = bind(window, {
86
- type: 'resize',
87
- listener: schedulePositionUpdate
88
- });
89
- const unbindWindowScroll = bind(window, {
90
- type: 'scroll',
91
- listener: schedulePositionUpdate,
92
- options: {
93
- capture: true,
94
- passive: true
95
- }
96
- });
97
- const visualViewport = window.visualViewport;
98
- const unbindVisualViewportResize = visualViewport ? bind(visualViewport, {
99
- type: 'resize',
100
- listener: schedulePositionUpdate
101
- }) : undefined;
102
- const unbindVisualViewportScroll = visualViewport ? bind(visualViewport, {
103
- type: 'scroll',
104
- listener: schedulePositionUpdate
105
- }) : undefined;
106
- const unbindTransitionEnd = bind(targetElement, {
107
- type: 'transitionend',
108
- listener: schedulePositionUpdate
109
- });
110
- return () => {
111
- if (animationFrameRef.current !== undefined) {
112
- cancelAnimationFrame(animationFrameRef.current);
113
- animationFrameRef.current = undefined;
114
- }
115
- resizeObserver.disconnect();
116
- unbindWindowResize();
117
- unbindWindowScroll();
118
- unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 ? void 0 : unbindVisualViewportResize();
119
- unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 ? void 0 : unbindVisualViewportScroll();
120
- unbindTransitionEnd();
121
- };
122
- }, [blockControlsContext, editorView]);
123
- if (components.length === 0 || !blockControlsContext || !surfaceContext || !position || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
124
- return null;
125
- }
126
- return /*#__PURE__*/React.createElement("div", {
127
- "data-editor-block-controls-surface": true
128
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the active node's runtime DOM geometry.
129
- ,
130
- style: position,
131
- "data-testid": target === 'root' ? 'block-controls-left-surface' : 'block-controls-left-surface-active',
132
- className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
133
- }, /*#__PURE__*/React.createElement(VisibilityContainer, {
134
- api: api,
135
- controlSide: "left",
136
- forceVisibleOnMouseOut: Boolean((_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
137
- shouldUseDisplayContents: true
138
- }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
139
- components: components,
140
- surface: BLOCK_CONTROLS_LEFT_SURFACE,
141
- surfaceContext: surfaceContext
142
- })));
143
- };
144
- export const BlockControlsSurface = ({
145
- api,
146
- editorView
147
- }) => {
148
- var _activeNode$rootPos;
149
- const activeNode = useSharedPluginStateWithSelector(api, ['blockControls'], states => {
150
- var _states$blockControls;
151
- return {
152
- activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode
153
- };
154
- }).activeNode;
155
- if (!activeNode) {
156
- return null;
157
- }
158
- const rootPos = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
159
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BlockControlsSurfaceAtTarget, {
160
- activeNode: activeNode,
161
- api: api,
162
- editorView: editorView,
163
- target: "root"
164
- }), rootPos !== activeNode.pos ? /*#__PURE__*/React.createElement(BlockControlsSurfaceAtTarget, {
165
- activeNode: activeNode,
166
- api: api,
167
- editorView: editorView,
168
- target: "active"
169
- }) : null);
170
- };
@@ -1,176 +0,0 @@
1
- /* block-controls-surface.tsx generated by @compiled/babel-plugin v2.0.0 */
2
- import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import "./block-controls-surface.compiled.css";
4
- import { ax, ix } from "@compiled/react/runtime";
5
- import React, { useLayoutEffect, useMemo, useRef, useState } from 'react';
6
- import { bind } from 'bind-event-listener';
7
- import { getDocument } from '@atlaskit/browser-apis';
8
- import { BLOCK_CONTROL_UI_CONTEXT } from '@atlaskit/editor-common/block-controls/block-control-ui-context';
9
- import { BLOCK_CONTROLS_LEFT_SURFACE } from '@atlaskit/editor-common/block-controls/surface-keys';
10
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
11
- import { SurfaceRenderer, willSurfaceRender } from '@atlaskit/editor-ui-control-model/surface-renderer';
12
- import { createSurfaceContext } from '@atlaskit/editor-ui-control-model/types';
13
- import { getNodeTypeWithLevel } from '../pm-plugins/decorations-common';
14
- import { createBlockControlsSurfaceContext } from './block-controls-surface-context';
15
- import { getNodeContentElement } from './utils/get-node-content-element';
16
- import { getAbsoluteSurfacePlacement, getSurfacePlacement } from './utils/get-surface-placement';
17
- import { VisibilityContainer } from './visibility-container';
18
- var BLOCK_CONTROLS_SURFACE_Z_INDEX = 100;
19
- var surfaceStyles = null;
20
- var BlockControlsSurfaceAtTarget = function BlockControlsSurfaceAtTarget(_ref) {
21
- var _api$uiControlRegistr, _api$uiControlRegistr2, _activeNode$handleOpt;
22
- var activeNode = _ref.activeNode,
23
- api = _ref.api,
24
- editorView = _ref.editorView,
25
- target = _ref.target;
26
- var _useState = useState(),
27
- _useState2 = _slicedToArray(_useState, 2),
28
- position = _useState2[0],
29
- setPosition = _useState2[1];
30
- var animationFrameRef = useRef(undefined);
31
- var components = (_api$uiControlRegistr = (_api$uiControlRegistr2 = api.uiControlRegistry) === null || _api$uiControlRegistr2 === void 0 ? void 0 : _api$uiControlRegistr2.actions.getComponents(BLOCK_CONTROLS_LEFT_SURFACE)) !== null && _api$uiControlRegistr !== void 0 ? _api$uiControlRegistr : [];
32
- var blockControlsContext = useMemo(function () {
33
- return createBlockControlsSurfaceContext(editorView, activeNode, target);
34
- }, [activeNode, editorView, target]);
35
- var surfaceContext = useMemo(function () {
36
- return blockControlsContext ? createSurfaceContext(BLOCK_CONTROL_UI_CONTEXT, blockControlsContext) : undefined;
37
- }, [blockControlsContext]);
38
- useLayoutEffect(function () {
39
- var _getDocument;
40
- if (!blockControlsContext) {
41
- setPosition(undefined);
42
- return;
43
- }
44
- var targetNodeElement = editorView.nodeDOM(blockControlsContext.targetNode.pos);
45
- var targetElementRoot = targetNodeElement instanceof HTMLElement ? targetNodeElement : targetNodeElement === null || targetNodeElement === void 0 ? void 0 : targetNodeElement.parentElement;
46
- if (!targetElementRoot) {
47
- setPosition(undefined);
48
- return;
49
- }
50
- var targetElement = getNodeContentElement(targetElementRoot, blockControlsContext.targetNode.type.name);
51
- var offsetParent = editorView.dom.offsetParent;
52
- var isDocumentOffsetParent = !offsetParent || offsetParent === ((_getDocument = getDocument()) === null || _getDocument === void 0 ? void 0 : _getDocument.body);
53
- var scrollingOffsetParent = offsetParent instanceof HTMLElement && !isDocumentOffsetParent ? offsetParent : undefined;
54
- var updatePosition = function updatePosition() {
55
- var _targetElementRoot$ge, _scrollingOffsetParen, _scrollingOffsetParen2;
56
- animationFrameRef.current = undefined;
57
- if (!targetElementRoot.isConnected || !targetElement.isConnected) {
58
- setPosition(undefined);
59
- return;
60
- }
61
- var placement = getSurfacePlacement({
62
- layout: (_targetElementRoot$ge = targetElementRoot.getAttribute('layout')) !== null && _targetElementRoot$ge !== void 0 ? _targetElementRoot$ge : '',
63
- nodeRect: targetElement.getBoundingClientRect(),
64
- nodeType: blockControlsContext.targetNode.type.name,
65
- nodeTypeWithLevel: getNodeTypeWithLevel(blockControlsContext.targetNode.node),
66
- parentNodeType: blockControlsContext.targetNode.parentType === 'doc' ? undefined : blockControlsContext.targetNode.parentType
67
- });
68
- var offsetParentRect = offsetParent === null || offsetParent === void 0 ? void 0 : offsetParent.getBoundingClientRect();
69
- var offsetParentScrollTop = (_scrollingOffsetParen = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollTop) !== null && _scrollingOffsetParen !== void 0 ? _scrollingOffsetParen : window.scrollY;
70
- var offsetParentScrollLeft = (_scrollingOffsetParen2 = scrollingOffsetParent === null || scrollingOffsetParent === void 0 ? void 0 : scrollingOffsetParent.scrollLeft) !== null && _scrollingOffsetParen2 !== void 0 ? _scrollingOffsetParen2 : window.scrollX;
71
- setPosition(getAbsoluteSurfacePlacement({
72
- offsetParentRect: offsetParentRect,
73
- offsetParentScrollLeft: offsetParentScrollLeft,
74
- offsetParentScrollTop: offsetParentScrollTop,
75
- placement: placement
76
- }));
77
- };
78
- var schedulePositionUpdate = function schedulePositionUpdate() {
79
- if (animationFrameRef.current === undefined) {
80
- animationFrameRef.current = requestAnimationFrame(updatePosition);
81
- }
82
- };
83
- updatePosition();
84
- var resizeObserver = new ResizeObserver(schedulePositionUpdate);
85
- resizeObserver.observe(editorView.dom);
86
- if (targetElement && targetElement !== editorView.dom) {
87
- resizeObserver.observe(targetElement);
88
- }
89
- if (offsetParent instanceof HTMLElement && offsetParent !== editorView.dom) {
90
- resizeObserver.observe(offsetParent);
91
- }
92
- var unbindWindowResize = bind(window, {
93
- type: 'resize',
94
- listener: schedulePositionUpdate
95
- });
96
- var unbindWindowScroll = bind(window, {
97
- type: 'scroll',
98
- listener: schedulePositionUpdate,
99
- options: {
100
- capture: true,
101
- passive: true
102
- }
103
- });
104
- var visualViewport = window.visualViewport;
105
- var unbindVisualViewportResize = visualViewport ? bind(visualViewport, {
106
- type: 'resize',
107
- listener: schedulePositionUpdate
108
- }) : undefined;
109
- var unbindVisualViewportScroll = visualViewport ? bind(visualViewport, {
110
- type: 'scroll',
111
- listener: schedulePositionUpdate
112
- }) : undefined;
113
- var unbindTransitionEnd = bind(targetElement, {
114
- type: 'transitionend',
115
- listener: schedulePositionUpdate
116
- });
117
- return function () {
118
- if (animationFrameRef.current !== undefined) {
119
- cancelAnimationFrame(animationFrameRef.current);
120
- animationFrameRef.current = undefined;
121
- }
122
- resizeObserver.disconnect();
123
- unbindWindowResize();
124
- unbindWindowScroll();
125
- unbindVisualViewportResize === null || unbindVisualViewportResize === void 0 || unbindVisualViewportResize();
126
- unbindVisualViewportScroll === null || unbindVisualViewportScroll === void 0 || unbindVisualViewportScroll();
127
- unbindTransitionEnd();
128
- };
129
- }, [blockControlsContext, editorView]);
130
- if (components.length === 0 || !blockControlsContext || !surfaceContext || !position || !willSurfaceRender(components, BLOCK_CONTROLS_LEFT_SURFACE, surfaceContext)) {
131
- return null;
132
- }
133
- return /*#__PURE__*/React.createElement("div", {
134
- "data-editor-block-controls-surface": true
135
- // eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Placement is resolved from the active node's runtime DOM geometry.
136
- ,
137
- style: position,
138
- "data-testid": target === 'root' ? 'block-controls-left-surface' : 'block-controls-left-surface-active',
139
- className: ax(["_zulpv77o _4cvr1h6o _1e0c1txw _kqswstnw _1pbyb4wl"])
140
- }, /*#__PURE__*/React.createElement(VisibilityContainer, {
141
- api: api,
142
- controlSide: "left",
143
- forceVisibleOnMouseOut: Boolean((_activeNode$handleOpt = activeNode.handleOptions) === null || _activeNode$handleOpt === void 0 ? void 0 : _activeNode$handleOpt.isFocused),
144
- shouldUseDisplayContents: true
145
- }, /*#__PURE__*/React.createElement(SurfaceRenderer, {
146
- components: components,
147
- surface: BLOCK_CONTROLS_LEFT_SURFACE,
148
- surfaceContext: surfaceContext
149
- })));
150
- };
151
- export var BlockControlsSurface = function BlockControlsSurface(_ref2) {
152
- var _activeNode$rootPos;
153
- var api = _ref2.api,
154
- editorView = _ref2.editorView;
155
- var activeNode = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
156
- var _states$blockControls;
157
- return {
158
- activeNode: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.activeNode
159
- };
160
- }).activeNode;
161
- if (!activeNode) {
162
- return null;
163
- }
164
- var rootPos = (_activeNode$rootPos = activeNode.rootPos) !== null && _activeNode$rootPos !== void 0 ? _activeNode$rootPos : activeNode.pos;
165
- return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(BlockControlsSurfaceAtTarget, {
166
- activeNode: activeNode,
167
- api: api,
168
- editorView: editorView,
169
- target: "root"
170
- }), rootPos !== activeNode.pos ? /*#__PURE__*/React.createElement(BlockControlsSurfaceAtTarget, {
171
- activeNode: activeNode,
172
- api: api,
173
- editorView: editorView,
174
- target: "active"
175
- }) : null);
176
- };