@atlaskit/editor-plugin-block-controls 2.13.12 → 2.13.13

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.
@@ -1,77 +0,0 @@
1
- /* eslint-disable @atlaskit/ui-styling-standard/no-exported-styles */
2
- /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
3
- /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
4
- /* eslint-disable @atlaskit/ui-styling-standard/no-important-styles */
5
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
6
- import { css } from '@emotion/react';
7
- import { fg } from '@atlaskit/platform-feature-flags';
8
- const emptyBlockExperimentWidget = '.ProseMirror-widget[data-empty-block-experiment="true"]';
9
- const quickInsertWidget = '.ProseMirror-widget[data-type-ahead="typeaheadDecoration"]';
10
- const formattingElement = 'div.fabric-editor-block-mark';
11
- const markFragment = 'div[data-mark-type="fragment"]';
12
- const breakoutMark = 'div.fabric-editor-breakout-mark';
13
- const breakoutMarkDom = 'div.fabric-editor-breakout-mark-dom';
14
- const elementWithEmptyBlockExperiment = `+ p > ${emptyBlockExperimentWidget}, + h1 > ${emptyBlockExperimentWidget}, + h2 > ${emptyBlockExperimentWidget}, + h3 > ${emptyBlockExperimentWidget}, + h4 > ${emptyBlockExperimentWidget}, + h5 > ${emptyBlockExperimentWidget}, + h6 > ${emptyBlockExperimentWidget}`;
15
- // Selectors for when contained withing a formatting container mark (eg. indent, centering, right-align)
16
- const elementWithEmptyBlockExperimentFormatted = `+ ${formattingElement} > p > ${emptyBlockExperimentWidget}, + ${formattingElement} > h1 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h2 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h3 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h4 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h5 > ${emptyBlockExperimentWidget}, + ${formattingElement} > h6 > ${emptyBlockExperimentWidget}`;
17
- const dragHandleContainer = '.ProseMirror-widget[data-blocks-drag-handle-container="true"]';
18
- const dragHandleSelector = 'button[data-testid="block-ctrl-drag-handle"]';
19
-
20
- // Hides the drag handle when the block contains the empty block experiment
21
- // Override is consistent with how the drag handle is hidden when the block contains a placeholder
22
- const dragHandleWithInlineNodeStyle = css({
23
- [`${dragHandleContainer}:has(${elementWithEmptyBlockExperiment}),
24
- ${dragHandleContainer}:has(${elementWithEmptyBlockExperimentFormatted}),` +
25
- // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
26
- // is nested in the previous div. These selectors are to handle those cases.
27
- // -------------------
28
- // Empty block in new paragraph after indent
29
- `${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child,
30
- ${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child,` +
31
- // Empty block in new paragraph after table
32
- `${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child,
33
- ${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child,` +
34
- // Empty block in new paragraph after breakout mark
35
- `${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child,
36
- ${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child`]: {
37
- display: 'none !important'
38
- }
39
- });
40
-
41
- // Alternate styling for hiding the drag handle when the block contains the empty block experiment
42
- // Override is consistent with a feature-gated bugfix that hides the drag handle when the block contains a placeholder
43
- /**
44
- * Please do not change change transform to display:none, or visibility:hidden
45
- * Otherwise it might break composition input for Chrome
46
- * https://product-fabric.atlassian.net/browse/ED-24136
47
- */
48
- const dragHandleWithInlineNodeStyleWithChromeFix = css({
49
- [`${dragHandleContainer}:has(${elementWithEmptyBlockExperiment}) ${dragHandleSelector},
50
- ${dragHandleContainer}:has(${elementWithEmptyBlockExperimentFormatted}) ${dragHandleSelector},` +
51
- // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
52
- // is nested in the previous div. These selectors are to handle those cases.
53
- // -------------------
54
- // Empty block in new paragraph after indent
55
- `${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child ${dragHandleSelector},
56
- ${formattingElement}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child ${dragHandleSelector},` +
57
- // Empty block in new paragraph after table
58
- `${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${dragHandleContainer}:last-child ${dragHandleSelector},
59
- ${markFragment}:has(> ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${dragHandleContainer}:last-child ${dragHandleSelector},` +
60
- // Empty block in new paragraph after breakout mark
61
- `${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperiment}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child ${dragHandleSelector},
62
- ${breakoutMark}:has(> ${breakoutMarkDom} > ${dragHandleContainer}:last-child):has(${elementWithEmptyBlockExperimentFormatted}) > ${breakoutMarkDom} > ${dragHandleContainer}:last-child ${dragHandleSelector}`]: {
63
- transform: 'scale(0)'
64
- }
65
- });
66
- const getDragHandleOverrides = () => {
67
- return fg('platform_editor_element_controls_chrome_input_fix') ? dragHandleWithInlineNodeStyleWithChromeFix : dragHandleWithInlineNodeStyle;
68
- };
69
-
70
- /**
71
- * Hide the experiment button when it has been activated. (contains quick-insert decoration widget)
72
- */
73
- export const emptyBlockExperimentGlobalStyles = css({
74
- [`${emptyBlockExperimentWidget}:has(+ ${quickInsertWidget}) button`]: {
75
- transform: 'scale(0)'
76
- }
77
- }, getDragHandleOverrides());
@@ -1,138 +0,0 @@
1
- /* eslint-disable @atlaskit/ui-styling-standard/use-compiled */
2
- import React, { createElement } from 'react';
3
- import { keyframes } from '@emotion/react';
4
- import ReactDOM from 'react-dom';
5
- import { injectIntl, RawIntlProvider } from 'react-intl-next';
6
- import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
7
- import { blockControlsMessages as messages } from '@atlaskit/editor-common/messages';
8
- import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
9
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
10
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
11
- import EditorAddIcon from '@atlaskit/icon/glyph/editor/add';
12
- import { fg } from '@atlaskit/platform-feature-flags';
13
- import { Box, Pressable, xcss } from '@atlaskit/primitives';
14
- import Tooltip from '@atlaskit/tooltip';
15
- const wrapperStyles = xcss({
16
- position: 'absolute',
17
- top: `calc('50%' - ${"var(--ds-space-150, 12px)"})`,
18
- left: `calc(${"var(--ds-space-negative-300, -24px)"} + ${"var(--ds-space-negative-100, -8px)"})`
19
- });
20
- const appear = keyframes({
21
- from: {
22
- visibility: 'hidden'
23
- },
24
- to: {
25
- visibility: 'visible'
26
- }
27
- });
28
- const delayedAppearance = xcss({
29
- visibility: 'hidden',
30
- animation: `${appear} 0.1s`,
31
- animationDelay: '2s',
32
- animationFillMode: 'forwards'
33
- });
34
- const buttonStyles = xcss({
35
- boxSizing: 'border-box',
36
- display: 'flex',
37
- flexDirection: 'column',
38
- justifyContent: 'center',
39
- alignItems: 'center',
40
- height: "var(--ds-space-300, 24px)",
41
- width: "var(--ds-space-300, 24px)",
42
- border: 'none',
43
- backgroundColor: 'color.background.neutral',
44
- borderRadius: '50%',
45
- color: 'color.text.accent.gray',
46
- zIndex: 'card',
47
- outline: 'none',
48
- ':hover': {
49
- backgroundColor: 'color.background.neutral.hovered'
50
- },
51
- ':active': {
52
- backgroundColor: 'color.background.neutral.pressed'
53
- },
54
- ':focus': {
55
- outline: `2px solid ${"var(--ds-border-focused, #388BFF)"}`
56
- }
57
- });
58
- export const TypeAheadControl = ({
59
- api,
60
- getPos,
61
- intl: {
62
- formatMessage
63
- }
64
- }) => {
65
- return /*#__PURE__*/React.createElement(Box, {
66
- xcss: [wrapperStyles],
67
- testId: "editor-empty-line-prompt-experiment"
68
- }, /*#__PURE__*/React.createElement(Tooltip, {
69
- content: /*#__PURE__*/React.createElement(ToolTipContent, {
70
- description: formatMessage(messages.insert),
71
- shortcutOverride: "/"
72
- })
73
- }, /*#__PURE__*/React.createElement(Pressable, {
74
- type: "button",
75
- "aria-label": formatMessage(messages.insert),
76
- xcss: [buttonStyles, ...(fg('platform_editor_empty_line_prompt_delay') ? [delayedAppearance] : [])],
77
- onClick: () => {
78
- var _api$core, _api$quickInsert;
79
- api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(({
80
- tr
81
- }) => {
82
- const start = getPos();
83
- if (!start) {
84
- return null;
85
- }
86
- return tr.setSelection(TextSelection.create(tr.doc, start));
87
- });
88
- api === null || api === void 0 ? void 0 : (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 ? void 0 : _api$quickInsert.actions.openTypeAhead('blockControl');
89
- }
90
- }, /*#__PURE__*/React.createElement(EditorAddIcon, {
91
- label: "add",
92
- size: "medium"
93
- }))));
94
- };
95
- const TypeAheadControlWithIntl = injectIntl(TypeAheadControl);
96
- const toDOM = (api, getPos, getIntl) => {
97
- const wrapper = document.createElement('span');
98
- wrapper.contentEditable = 'false';
99
- wrapper.setAttribute('data-empty-block-experiment', 'true');
100
- wrapper.setAttribute('class', 'empty-block-experiment');
101
- const element = document.createElement('span');
102
- element.contentEditable = 'false';
103
- element.setAttribute('style', 'position: absolute;');
104
- wrapper.appendChild(element);
105
- ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
106
- value: getIntl()
107
- }, /*#__PURE__*/createElement(TypeAheadControlWithIntl, {
108
- api,
109
- getPos
110
- })), element);
111
-
112
- // // This is a hack to ensure that the cursor in Chrome does not take on the height of the widget button.
113
- // // Cursor height cannot be controlled via CSS and is handled by the browser.
114
- // // see Prosemirror forum: https://discuss.prosemirror.net/t/chrome-caret-cursor-larger-than-the-text-with-inlined-items/5946
115
- const cursorHack = document.createTextNode(ZERO_WIDTH_SPACE);
116
- wrapper.appendChild(cursorHack);
117
- return wrapper;
118
- };
119
- export const createEmptyBlockWidgetDecoration = (selection, api, getIntl) => {
120
- if (selection instanceof TextSelection && selection.$cursor) {
121
- var _$cursor$parent, _$cursor$parent2;
122
- const {
123
- $cursor
124
- } = selection;
125
- const {
126
- depth
127
- } = $cursor;
128
- const cursorAtRoot = depth === 1;
129
- const nodeIsEmpty = ((_$cursor$parent = $cursor.parent) === null || _$cursor$parent === void 0 ? void 0 : _$cursor$parent.nodeSize) === 2;
130
- const supportedNodeTypes = ['paragraph', 'heading'];
131
- if (cursorAtRoot && nodeIsEmpty && supportedNodeTypes.includes((_$cursor$parent2 = $cursor.parent) === null || _$cursor$parent2 === void 0 ? void 0 : _$cursor$parent2.type.name)) {
132
- return Decoration.widget(selection.$cursor.posAtIndex($cursor.depth - 1), (_view, getPos) => toDOM(api, getPos, getIntl), {
133
- key: 'emptyBlockWidgetDecoration',
134
- side: -1
135
- });
136
- }
137
- }
138
- };
@@ -1,40 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
- import { createEmptyBlockWidgetDecoration } from '../ui/empty-block-experiment/widget';
5
- export var emptyBlockExperimentPluginKey = new PluginKey('emptyBlockExperiment');
6
- var getDecorations = function getDecorations(tr, api, getIntl) {
7
- var _api$editorDisabled;
8
- var isEditorDisabled = api === null || api === void 0 || (_api$editorDisabled = api.editorDisabled) === null || _api$editorDisabled === void 0 || (_api$editorDisabled = _api$editorDisabled.sharedState.currentState()) === null || _api$editorDisabled === void 0 ? void 0 : _api$editorDisabled.editorDisabled;
9
- if (isEditorDisabled) {
10
- return DecorationSet.empty;
11
- }
12
- var widget = createEmptyBlockWidgetDecoration(tr.selection, api, getIntl);
13
- if (widget) {
14
- return DecorationSet.create(tr.doc, [widget]);
15
- }
16
- return DecorationSet.empty;
17
- };
18
- export var createEmptyBlockExperimentPlugin = function createEmptyBlockExperimentPlugin(api, getIntl) {
19
- return new SafePlugin({
20
- key: emptyBlockExperimentPluginKey,
21
- state: {
22
- init: function init(_, _editorState) {
23
- return {
24
- decorations: DecorationSet.empty
25
- };
26
- },
27
- apply: function apply(tr, _currentState) {
28
- return {
29
- decorations: getDecorations(tr, api, getIntl)
30
- };
31
- }
32
- },
33
- props: {
34
- decorations: function decorations(state) {
35
- var _emptyBlockExperiment;
36
- return (_emptyBlockExperiment = emptyBlockExperimentPluginKey.getState(state)) === null || _emptyBlockExperiment === void 0 ? void 0 : _emptyBlockExperiment.decorations;
37
- }
38
- }
39
- });
40
- };
@@ -1,58 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /* eslint-disable @atlaskit/ui-styling-standard/no-exported-styles */
3
- /* eslint-disable @atlaskit/ui-styling-standard/no-unsafe-values */
4
- /* eslint-disable @atlaskit/ui-styling-standard/no-nested-selectors */
5
- /* eslint-disable @atlaskit/ui-styling-standard/no-important-styles */
6
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled
7
- import { css } from '@emotion/react';
8
- import { fg } from '@atlaskit/platform-feature-flags';
9
- var emptyBlockExperimentWidget = '.ProseMirror-widget[data-empty-block-experiment="true"]';
10
- var quickInsertWidget = '.ProseMirror-widget[data-type-ahead="typeaheadDecoration"]';
11
- var formattingElement = 'div.fabric-editor-block-mark';
12
- var markFragment = 'div[data-mark-type="fragment"]';
13
- var breakoutMark = 'div.fabric-editor-breakout-mark';
14
- var breakoutMarkDom = 'div.fabric-editor-breakout-mark-dom';
15
- var elementWithEmptyBlockExperiment = "+ p > ".concat(emptyBlockExperimentWidget, ", + h1 > ").concat(emptyBlockExperimentWidget, ", + h2 > ").concat(emptyBlockExperimentWidget, ", + h3 > ").concat(emptyBlockExperimentWidget, ", + h4 > ").concat(emptyBlockExperimentWidget, ", + h5 > ").concat(emptyBlockExperimentWidget, ", + h6 > ").concat(emptyBlockExperimentWidget);
16
- // Selectors for when contained withing a formatting container mark (eg. indent, centering, right-align)
17
- var elementWithEmptyBlockExperimentFormatted = "+ ".concat(formattingElement, " > p > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h1 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h2 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h3 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h4 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h5 > ").concat(emptyBlockExperimentWidget, ", + ").concat(formattingElement, " > h6 > ").concat(emptyBlockExperimentWidget);
18
- var dragHandleContainer = '.ProseMirror-widget[data-blocks-drag-handle-container="true"]';
19
- var dragHandleSelector = 'button[data-testid="block-ctrl-drag-handle"]';
20
-
21
- // Hides the drag handle when the block contains the empty block experiment
22
- // Override is consistent with how the drag handle is hidden when the block contains a placeholder
23
- var dragHandleWithInlineNodeStyle = css(_defineProperty({}, "".concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperiment, "),\n\t\t").concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperimentFormatted, "),") + // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
24
- // is nested in the previous div. These selectors are to handle those cases.
25
- // -------------------
26
- // Empty block in new paragraph after indent
27
- "".concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child,\n\t").concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child,") + // Empty block in new paragraph after table
28
- "".concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child,\n\t\t").concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child,") + // Empty block in new paragraph after breakout mark
29
- "".concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child,\n\t").concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child"), {
30
- display: 'none !important'
31
- }));
32
-
33
- // Alternate styling for hiding the drag handle when the block contains the empty block experiment
34
- // Override is consistent with a feature-gated bugfix that hides the drag handle when the block contains a placeholder
35
- /**
36
- * Please do not change change transform to display:none, or visibility:hidden
37
- * Otherwise it might break composition input for Chrome
38
- * https://product-fabric.atlassian.net/browse/ED-24136
39
- */
40
- var dragHandleWithInlineNodeStyleWithChromeFix = css(_defineProperty({}, "".concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperiment, ") ").concat(dragHandleSelector, ",\n\t\t").concat(dragHandleContainer, ":has(").concat(elementWithEmptyBlockExperimentFormatted, ") ").concat(dragHandleSelector, ",") + // In certain circumstances - eg. a paragraph after an indent, or after a table fragment, the dragHandleContainer
41
- // is nested in the previous div. These selectors are to handle those cases.
42
- // -------------------
43
- // Empty block in new paragraph after indent
44
- "".concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",\n\t").concat(formattingElement, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",") + // Empty block in new paragraph after table
45
- "".concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",\n\t\t").concat(markFragment, ":has(> ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",") + // Empty block in new paragraph after breakout mark
46
- "".concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperiment, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector, ",\n\t\t").concat(breakoutMark, ":has(> ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child):has(").concat(elementWithEmptyBlockExperimentFormatted, ") > ").concat(breakoutMarkDom, " > ").concat(dragHandleContainer, ":last-child ").concat(dragHandleSelector), {
47
- transform: 'scale(0)'
48
- }));
49
- var getDragHandleOverrides = function getDragHandleOverrides() {
50
- return fg('platform_editor_element_controls_chrome_input_fix') ? dragHandleWithInlineNodeStyleWithChromeFix : dragHandleWithInlineNodeStyle;
51
- };
52
-
53
- /**
54
- * Hide the experiment button when it has been activated. (contains quick-insert decoration widget)
55
- */
56
- export var emptyBlockExperimentGlobalStyles = css(_defineProperty({}, "".concat(emptyBlockExperimentWidget, ":has(+ ").concat(quickInsertWidget, ") button"), {
57
- transform: 'scale(0)'
58
- }), getDragHandleOverrides());
@@ -1,133 +0,0 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- /* eslint-disable @atlaskit/ui-styling-standard/use-compiled */
3
- import React, { createElement } from 'react';
4
- import { keyframes } from '@emotion/react';
5
- import ReactDOM from 'react-dom';
6
- import { injectIntl, RawIntlProvider } from 'react-intl-next';
7
- import { ToolTipContent } from '@atlaskit/editor-common/keymaps';
8
- import { blockControlsMessages as messages } from '@atlaskit/editor-common/messages';
9
- import { ZERO_WIDTH_SPACE } from '@atlaskit/editor-common/whitespace';
10
- import { TextSelection } from '@atlaskit/editor-prosemirror/state';
11
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
12
- import EditorAddIcon from '@atlaskit/icon/glyph/editor/add';
13
- import { fg } from '@atlaskit/platform-feature-flags';
14
- import { Box, Pressable, xcss } from '@atlaskit/primitives';
15
- import Tooltip from '@atlaskit/tooltip';
16
- var wrapperStyles = xcss({
17
- position: 'absolute',
18
- top: "calc('50%' - ".concat("var(--ds-space-150, 12px)", ")"),
19
- left: "calc(".concat("var(--ds-space-negative-300, -24px)", " + ", "var(--ds-space-negative-100, -8px)", ")")
20
- });
21
- var appear = keyframes({
22
- from: {
23
- visibility: 'hidden'
24
- },
25
- to: {
26
- visibility: 'visible'
27
- }
28
- });
29
- var delayedAppearance = xcss({
30
- visibility: 'hidden',
31
- animation: "".concat(appear, " 0.1s"),
32
- animationDelay: '2s',
33
- animationFillMode: 'forwards'
34
- });
35
- var buttonStyles = xcss({
36
- boxSizing: 'border-box',
37
- display: 'flex',
38
- flexDirection: 'column',
39
- justifyContent: 'center',
40
- alignItems: 'center',
41
- height: "var(--ds-space-300, 24px)",
42
- width: "var(--ds-space-300, 24px)",
43
- border: 'none',
44
- backgroundColor: 'color.background.neutral',
45
- borderRadius: '50%',
46
- color: 'color.text.accent.gray',
47
- zIndex: 'card',
48
- outline: 'none',
49
- ':hover': {
50
- backgroundColor: 'color.background.neutral.hovered'
51
- },
52
- ':active': {
53
- backgroundColor: 'color.background.neutral.pressed'
54
- },
55
- ':focus': {
56
- outline: "2px solid ".concat("var(--ds-border-focused, #388BFF)")
57
- }
58
- });
59
- export var TypeAheadControl = function TypeAheadControl(_ref) {
60
- var api = _ref.api,
61
- getPos = _ref.getPos,
62
- formatMessage = _ref.intl.formatMessage;
63
- return /*#__PURE__*/React.createElement(Box, {
64
- xcss: [wrapperStyles],
65
- testId: "editor-empty-line-prompt-experiment"
66
- }, /*#__PURE__*/React.createElement(Tooltip, {
67
- content: /*#__PURE__*/React.createElement(ToolTipContent, {
68
- description: formatMessage(messages.insert),
69
- shortcutOverride: "/"
70
- })
71
- }, /*#__PURE__*/React.createElement(Pressable, {
72
- type: "button",
73
- "aria-label": formatMessage(messages.insert),
74
- xcss: [buttonStyles].concat(_toConsumableArray(fg('platform_editor_empty_line_prompt_delay') ? [delayedAppearance] : [])),
75
- onClick: function onClick() {
76
- var _api$core, _api$quickInsert;
77
- api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function (_ref2) {
78
- var tr = _ref2.tr;
79
- var start = getPos();
80
- if (!start) {
81
- return null;
82
- }
83
- return tr.setSelection(TextSelection.create(tr.doc, start));
84
- });
85
- api === null || api === void 0 || (_api$quickInsert = api.quickInsert) === null || _api$quickInsert === void 0 || _api$quickInsert.actions.openTypeAhead('blockControl');
86
- }
87
- }, /*#__PURE__*/React.createElement(EditorAddIcon, {
88
- label: "add",
89
- size: "medium"
90
- }))));
91
- };
92
- var TypeAheadControlWithIntl = injectIntl(TypeAheadControl);
93
- var toDOM = function toDOM(api, getPos, getIntl) {
94
- var wrapper = document.createElement('span');
95
- wrapper.contentEditable = 'false';
96
- wrapper.setAttribute('data-empty-block-experiment', 'true');
97
- wrapper.setAttribute('class', 'empty-block-experiment');
98
- var element = document.createElement('span');
99
- element.contentEditable = 'false';
100
- element.setAttribute('style', 'position: absolute;');
101
- wrapper.appendChild(element);
102
- ReactDOM.render( /*#__PURE__*/createElement(RawIntlProvider, {
103
- value: getIntl()
104
- }, /*#__PURE__*/createElement(TypeAheadControlWithIntl, {
105
- api: api,
106
- getPos: getPos
107
- })), element);
108
-
109
- // // This is a hack to ensure that the cursor in Chrome does not take on the height of the widget button.
110
- // // Cursor height cannot be controlled via CSS and is handled by the browser.
111
- // // see Prosemirror forum: https://discuss.prosemirror.net/t/chrome-caret-cursor-larger-than-the-text-with-inlined-items/5946
112
- var cursorHack = document.createTextNode(ZERO_WIDTH_SPACE);
113
- wrapper.appendChild(cursorHack);
114
- return wrapper;
115
- };
116
- export var createEmptyBlockWidgetDecoration = function createEmptyBlockWidgetDecoration(selection, api, getIntl) {
117
- if (selection instanceof TextSelection && selection.$cursor) {
118
- var _$cursor$parent, _$cursor$parent2;
119
- var $cursor = selection.$cursor;
120
- var depth = $cursor.depth;
121
- var cursorAtRoot = depth === 1;
122
- var nodeIsEmpty = ((_$cursor$parent = $cursor.parent) === null || _$cursor$parent === void 0 ? void 0 : _$cursor$parent.nodeSize) === 2;
123
- var supportedNodeTypes = ['paragraph', 'heading'];
124
- if (cursorAtRoot && nodeIsEmpty && supportedNodeTypes.includes((_$cursor$parent2 = $cursor.parent) === null || _$cursor$parent2 === void 0 ? void 0 : _$cursor$parent2.type.name)) {
125
- return Decoration.widget(selection.$cursor.posAtIndex($cursor.depth - 1), function (_view, getPos) {
126
- return toDOM(api, getPos, getIntl);
127
- }, {
128
- key: 'emptyBlockWidgetDecoration',
129
- side: -1
130
- });
131
- }
132
- }
133
- };
@@ -1,13 +0,0 @@
1
- import { type IntlShape } from 'react-intl-next';
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
- import { type BlockControlsPlugin } from '../types';
7
- export declare const emptyBlockExperimentPluginKey: PluginKey<EmptyBlockExperimentState>;
8
- export type EmptyBlockExperimentState = {
9
- decorations: DecorationSet;
10
- };
11
- export declare const createEmptyBlockExperimentPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape) => SafePlugin<{
12
- decorations: DecorationSet;
13
- }>;
@@ -1,4 +0,0 @@
1
- /**
2
- * Hide the experiment button when it has been activated. (contains quick-insert decoration widget)
3
- */
4
- export declare const emptyBlockExperimentGlobalStyles: import("@emotion/react").SerializedStyles;
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { type IntlShape, type WrappedComponentProps } from 'react-intl-next';
3
- import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
- import { type Selection } from '@atlaskit/editor-prosemirror/state';
5
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
6
- import { type BlockControlsPlugin } from '../../types';
7
- type Props = {
8
- api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
9
- getPos: () => number | undefined;
10
- };
11
- export declare const TypeAheadControl: ({ api, getPos, intl: { formatMessage }, }: Props & WrappedComponentProps) => JSX.Element;
12
- export declare const createEmptyBlockWidgetDecoration: (selection: Selection, api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape) => Decoration | undefined;
13
- export {};
@@ -1,13 +0,0 @@
1
- import { type IntlShape } from 'react-intl-next';
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
- import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
6
- import { type BlockControlsPlugin } from '../types';
7
- export declare const emptyBlockExperimentPluginKey: PluginKey<EmptyBlockExperimentState>;
8
- export type EmptyBlockExperimentState = {
9
- decorations: DecorationSet;
10
- };
11
- export declare const createEmptyBlockExperimentPlugin: (api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape) => SafePlugin<{
12
- decorations: DecorationSet;
13
- }>;
@@ -1,4 +0,0 @@
1
- /**
2
- * Hide the experiment button when it has been activated. (contains quick-insert decoration widget)
3
- */
4
- export declare const emptyBlockExperimentGlobalStyles: import("@emotion/react").SerializedStyles;
@@ -1,13 +0,0 @@
1
- /// <reference types="react" />
2
- import { type IntlShape, type WrappedComponentProps } from 'react-intl-next';
3
- import { type ExtractInjectionAPI } from '@atlaskit/editor-common/types';
4
- import { type Selection } from '@atlaskit/editor-prosemirror/state';
5
- import { Decoration } from '@atlaskit/editor-prosemirror/view';
6
- import { type BlockControlsPlugin } from '../../types';
7
- type Props = {
8
- api: ExtractInjectionAPI<BlockControlsPlugin> | undefined;
9
- getPos: () => number | undefined;
10
- };
11
- export declare const TypeAheadControl: ({ api, getPos, intl: { formatMessage }, }: Props & WrappedComponentProps) => JSX.Element;
12
- export declare const createEmptyBlockWidgetDecoration: (selection: Selection, api: ExtractInjectionAPI<BlockControlsPlugin> | undefined, getIntl: () => IntlShape) => Decoration | undefined;
13
- export {};