@atlaskit/editor-core 189.0.9 → 189.0.10

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 CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/editor-core
2
2
 
3
+ ## 189.0.10
4
+
5
+ ### Patch Changes
6
+
7
+ - [#42139](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/42139) [`9474db7141c`](https://bitbucket.org/atlassian/atlassian-frontend/commits/9474db7141c) - [ED-20622] Fix task and decision placeholder been removed when the TypeAhead was open
8
+
3
9
  ## 189.0.9
4
10
 
5
11
  ### Patch Changes
@@ -9,8 +9,9 @@ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/hel
9
9
  var _react = require("@emotion/react");
10
10
  var _adfSchema = require("@atlaskit/adf-schema");
11
11
  var _analytics = require("@atlaskit/editor-common/analytics");
12
- var _messages = require("../insert-block/ui/ToolbarInsertBlock/messages");
12
+ var _messages = require("@atlaskit/editor-common/messages");
13
13
  var _quickInsert = require("@atlaskit/editor-common/quick-insert");
14
+ var _pluginKey = require("./pm-plugins/plugin-key");
14
15
  var _commands = require("./commands");
15
16
  var _inputRules = _interopRequireDefault(require("./pm-plugins/input-rules"));
16
17
  var _keymaps = _interopRequireDefault(require("./pm-plugins/keymaps"));
@@ -58,6 +59,15 @@ var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
58
59
  node: _adfSchema.taskItem
59
60
  }];
60
61
  },
62
+ getSharedState: function getSharedState(editorState) {
63
+ if (!editorState) {
64
+ return undefined;
65
+ }
66
+ var pluginState = _pluginKey.stateKey.getState(editorState);
67
+ return {
68
+ focusedTaskItemLocalId: (pluginState === null || pluginState === void 0 ? void 0 : pluginState.focusedTaskItemLocalId) || null
69
+ };
70
+ },
61
71
  pmPlugins: function pmPlugins() {
62
72
  return [{
63
73
  name: 'tasksAndDecisions',
@@ -107,8 +117,8 @@ var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
107
117
  var formatMessage = _ref7.formatMessage;
108
118
  return [{
109
119
  id: 'action',
110
- title: formatMessage(_messages.messages.action),
111
- description: formatMessage(_messages.messages.actionDescription),
120
+ title: formatMessage(_messages.toolbarInsertBlockMessages.action),
121
+ description: formatMessage(_messages.toolbarInsertBlockMessages.actionDescription),
112
122
  priority: 100,
113
123
  keywords: ['checkbox', 'task', 'todo'],
114
124
  keyshortcut: '[]',
@@ -121,8 +131,8 @@ var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
121
131
  }
122
132
  }, {
123
133
  id: 'decision',
124
- title: formatMessage(_messages.messages.decision),
125
- description: formatMessage(_messages.messages.decisionDescription),
134
+ title: formatMessage(_messages.toolbarInsertBlockMessages.decision),
135
+ description: formatMessage(_messages.toolbarInsertBlockMessages.decisionDescription),
126
136
  priority: 900,
127
137
  keyshortcut: '<>',
128
138
  icon: function icon() {
@@ -13,19 +13,25 @@ var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime
13
13
  var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
14
  var _react = _interopRequireDefault(require("react"));
15
15
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
16
- var _hooks = require("@atlaskit/editor-common/hooks");
16
+ var _useShowPlaceholder = require("./hooks/use-show-placeholder");
17
17
  var _Decision = _interopRequireDefault(require("../ui/Decision"));
18
18
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
19
19
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
20
20
  var DecisionItemWrapper = function DecisionItemWrapper(_ref) {
21
21
  var api = _ref.api,
22
+ editorView = _ref.editorView,
22
23
  forwardRef = _ref.forwardRef,
23
- isContentNodeEmpty = _ref.isContentNodeEmpty;
24
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['typeAhead']),
25
- typeAheadState = _useSharedPluginState.typeAheadState;
24
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
25
+ getPos = _ref.getPos;
26
+ var showPlaceholder = (0, _useShowPlaceholder.useShowPlaceholder)({
27
+ editorView: editorView,
28
+ isContentNodeEmpty: isContentNodeEmpty,
29
+ getPos: getPos,
30
+ api: api
31
+ });
26
32
  return /*#__PURE__*/_react.default.createElement(_Decision.default, {
27
33
  contentRef: forwardRef,
28
- showPlaceholder: isContentNodeEmpty && !(typeAheadState !== null && typeAheadState !== void 0 && typeAheadState.isOpen)
34
+ showPlaceholder: showPlaceholder
29
35
  });
30
36
  };
31
37
  var Decision = /*#__PURE__*/function (_ReactNodeView) {
@@ -73,6 +79,11 @@ var Decision = /*#__PURE__*/function (_ReactNodeView) {
73
79
  forwardRef: forwardRef,
74
80
  isContentNodeEmpty: isContentNodeEmpty,
75
81
  api: this.api
82
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
83
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
84
+ ,
85
+ getPos: this.getPos,
86
+ editorView: this.view
76
87
  });
77
88
  }
78
89
  }, {
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useShowPlaceholder = void 0;
7
+ var _react = require("react");
8
+ var _state = require("@atlaskit/editor-prosemirror/state");
9
+ var _hooks = require("@atlaskit/editor-common/hooks");
10
+ var useShowPlaceholder = exports.useShowPlaceholder = function useShowPlaceholder(_ref) {
11
+ var editorView = _ref.editorView,
12
+ api = _ref.api,
13
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
14
+ getPos = _ref.getPos;
15
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['typeAhead']),
16
+ typeAheadState = _useSharedPluginState.typeAheadState;
17
+ var isTypeAheadOpen = Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen);
18
+ var isTypeAheadOpenedInsideItem = (0, _react.useMemo)(function () {
19
+ var _selection$$cursor;
20
+ if (!isTypeAheadOpen) {
21
+ return false;
22
+ }
23
+ var itemPosition = getPos();
24
+ if (typeof itemPosition !== 'number') {
25
+ return false;
26
+ }
27
+ var selection = editorView.state.selection;
28
+ if (!(selection instanceof _state.TextSelection)) {
29
+ return false;
30
+ }
31
+ var maybeItemNode = editorView.state.doc.nodeAt(itemPosition);
32
+ var maybeParentItemNode = (_selection$$cursor = selection.$cursor) === null || _selection$$cursor === void 0 ? void 0 : _selection$$cursor.node();
33
+ if (maybeItemNode && maybeParentItemNode && maybeItemNode.eq(maybeParentItemNode)) {
34
+ return true;
35
+ }
36
+ return false;
37
+ }, [isTypeAheadOpen, getPos, editorView]);
38
+ var showPlaceholder = Boolean(!isTypeAheadOpenedInsideItem && isContentNodeEmpty);
39
+ return showPlaceholder;
40
+ };
@@ -16,35 +16,40 @@ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/de
16
16
  var _react = _interopRequireDefault(require("react"));
17
17
  var _analyticsNext = require("@atlaskit/analytics-next");
18
18
  var _steps = require("@atlaskit/adf-schema/steps");
19
- var _hooks = require("@atlaskit/editor-common/hooks");
20
19
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
21
- var _withPluginState = require("@atlaskit/editor-common/with-plugin-state");
22
- var _pluginKey = require("../pm-plugins/plugin-key");
20
+ var _hooks = require("@atlaskit/editor-common/hooks");
21
+ var _useShowPlaceholder = require("./hooks/use-show-placeholder");
23
22
  var _Task = _interopRequireDefault(require("../ui/Task"));
24
23
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
25
24
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
26
25
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
27
26
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
28
- //import { isTypeAheadOpen } from '../../type-ahead/utils';
29
-
30
27
  var TaskItemWrapper = function TaskItemWrapper(_ref) {
31
28
  var localId = _ref.localId,
32
29
  forwardRef = _ref.forwardRef,
33
30
  isDone = _ref.isDone,
34
31
  onChange = _ref.onChange,
35
- isFocused = _ref.isFocused,
36
- isContentNodeEmpty = _ref.isContentNodeEmpty,
37
32
  providerFactory = _ref.providerFactory,
38
- api = _ref.api;
39
- var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['typeAhead']),
40
- typeAheadState = _useSharedPluginState.typeAheadState;
33
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
34
+ api = _ref.api,
35
+ getPos = _ref.getPos,
36
+ editorView = _ref.editorView;
37
+ var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['taskDecision']),
38
+ taskDecisionState = _useSharedPluginState.taskDecisionState;
39
+ var isFocused = Boolean((taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.focusedTaskItemLocalId) === localId);
40
+ var showPlaceholder = (0, _useShowPlaceholder.useShowPlaceholder)({
41
+ editorView: editorView,
42
+ isContentNodeEmpty: isContentNodeEmpty,
43
+ getPos: getPos,
44
+ api: api
45
+ });
41
46
  return /*#__PURE__*/_react.default.createElement(_Task.default, {
42
47
  taskId: localId,
43
48
  contentRef: forwardRef,
44
49
  isDone: isDone,
45
50
  onChange: onChange,
46
51
  isFocused: isFocused,
47
- showPlaceholder: isContentNodeEmpty && !(typeAheadState !== null && typeAheadState !== void 0 && typeAheadState.isOpen),
52
+ showPlaceholder: showPlaceholder,
48
53
  providers: providerFactory
49
54
  });
50
55
  };
@@ -150,7 +155,6 @@ var Task = /*#__PURE__*/function (_ReactNodeView) {
150
155
  }, {
151
156
  key: "render",
152
157
  value: function render(props, forwardRef) {
153
- var _this2 = this;
154
158
  var _this$node$attrs = this.node.attrs,
155
159
  localId = _this$node$attrs.localId,
156
160
  state = _this$node$attrs.state;
@@ -158,23 +162,19 @@ var Task = /*#__PURE__*/function (_ReactNodeView) {
158
162
  return /*#__PURE__*/_react.default.createElement(_analyticsNext.AnalyticsListener, {
159
163
  channel: "fabric-elements",
160
164
  onEvent: this.addListAnalyticsData
161
- }, /*#__PURE__*/_react.default.createElement(_withPluginState.WithPluginState, {
162
- plugins: {
163
- taskDecisionPlugin: _pluginKey.stateKey
164
- },
165
- render: function render(_ref2) {
166
- var taskDecisionPlugin = _ref2.taskDecisionPlugin;
167
- return /*#__PURE__*/_react.default.createElement(TaskItemWrapper, {
168
- localId: localId,
169
- forwardRef: forwardRef,
170
- isDone: state === 'DONE',
171
- onChange: _this2.handleOnChange,
172
- isFocused: Boolean((taskDecisionPlugin === null || taskDecisionPlugin === void 0 ? void 0 : taskDecisionPlugin.focusedTaskItemLocalId) === localId),
173
- isContentNodeEmpty: isContentNodeEmpty,
174
- providerFactory: props.providerFactory,
175
- api: _this2.api
176
- });
177
- }
165
+ }, /*#__PURE__*/_react.default.createElement(TaskItemWrapper, {
166
+ localId: localId,
167
+ forwardRef: forwardRef,
168
+ isDone: state === 'DONE',
169
+ onChange: this.handleOnChange,
170
+ isContentNodeEmpty: isContentNodeEmpty,
171
+ providerFactory: props.providerFactory
172
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
173
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
174
+ ,
175
+ getPos: this.getPos,
176
+ editorView: this.view,
177
+ api: this.api
178
178
  }));
179
179
  }
180
180
  }, {
@@ -190,11 +190,11 @@ var Task = /*#__PURE__*/function (_ReactNodeView) {
190
190
  }, {
191
191
  key: "update",
192
192
  value: function update(node, decorations) {
193
- var _this3 = this;
193
+ var _this2 = this;
194
194
  return (0, _get2.default)((0, _getPrototypeOf2.default)(Task.prototype), "update", this).call(this, node, decorations, undefined, function (currentNode, newNode) {
195
195
  return (
196
196
  // Toggle the placeholder based on whether user input exists
197
- !_this3.isContentEmpty(newNode) && !!(currentNode.attrs.state === newNode.attrs.state)
197
+ !_this2.isContentEmpty(newNode) && !!(currentNode.attrs.state === newNode.attrs.state)
198
198
  );
199
199
  });
200
200
  }
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.version = exports.nextMajorVersion = exports.name = void 0;
7
7
  var name = exports.name = "@atlaskit/editor-core";
8
- var version = exports.version = "189.0.9";
8
+ var version = exports.version = "189.0.10";
9
9
  var nextMajorVersion = exports.nextMajorVersion = function nextMajorVersion() {
10
10
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
11
11
  };
@@ -2,8 +2,9 @@
2
2
  import { css, jsx } from '@emotion/react';
3
3
  import { decisionItem, decisionList, taskItem, taskList } from '@atlaskit/adf-schema';
4
4
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
5
- import { messages as insertBlockMessages } from '../insert-block/ui/ToolbarInsertBlock/messages';
5
+ import { toolbarInsertBlockMessages as insertBlockMessages } from '@atlaskit/editor-common/messages';
6
6
  import { IconAction, IconDecision } from '@atlaskit/editor-common/quick-insert';
7
+ import { stateKey as taskPluginKey } from './pm-plugins/plugin-key';
7
8
  import { insertTaskDecisionAction, getListTypes } from './commands';
8
9
  import inputRulePlugin from './pm-plugins/input-rules';
9
10
  import keymap from './pm-plugins/keymaps';
@@ -51,6 +52,15 @@ const tasksAndDecisionsPlugin = ({
51
52
  node: taskItem
52
53
  }];
53
54
  },
55
+ getSharedState(editorState) {
56
+ if (!editorState) {
57
+ return undefined;
58
+ }
59
+ const pluginState = taskPluginKey.getState(editorState);
60
+ return {
61
+ focusedTaskItemLocalId: (pluginState === null || pluginState === void 0 ? void 0 : pluginState.focusedTaskItemLocalId) || null
62
+ };
63
+ },
54
64
  pmPlugins() {
55
65
  return [{
56
66
  name: 'tasksAndDecisions',
@@ -1,18 +1,23 @@
1
1
  import React from 'react';
2
2
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
3
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { useShowPlaceholder } from './hooks/use-show-placeholder';
4
4
  import DecisionItem from '../ui/Decision';
5
5
  const DecisionItemWrapper = ({
6
6
  api,
7
+ editorView,
7
8
  forwardRef,
8
- isContentNodeEmpty
9
+ isContentNodeEmpty,
10
+ getPos
9
11
  }) => {
10
- const {
11
- typeAheadState
12
- } = useSharedPluginState(api, ['typeAhead']);
12
+ const showPlaceholder = useShowPlaceholder({
13
+ editorView,
14
+ isContentNodeEmpty,
15
+ getPos,
16
+ api
17
+ });
13
18
  return /*#__PURE__*/React.createElement(DecisionItem, {
14
19
  contentRef: forwardRef,
15
- showPlaceholder: isContentNodeEmpty && !(typeAheadState !== null && typeAheadState !== void 0 && typeAheadState.isOpen)
20
+ showPlaceholder: showPlaceholder
16
21
  });
17
22
  };
18
23
  class Decision extends ReactNodeView {
@@ -44,6 +49,11 @@ class Decision extends ReactNodeView {
44
49
  forwardRef: forwardRef,
45
50
  isContentNodeEmpty: isContentNodeEmpty,
46
51
  api: this.api
52
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
53
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
54
+ ,
55
+ getPos: this.getPos,
56
+ editorView: this.view
47
57
  });
48
58
  }
49
59
  viewShouldUpdate(nextNode) {
@@ -0,0 +1,36 @@
1
+ import { useMemo } from 'react';
2
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
+ export const useShowPlaceholder = ({
5
+ editorView,
6
+ api,
7
+ isContentNodeEmpty,
8
+ getPos
9
+ }) => {
10
+ const {
11
+ typeAheadState
12
+ } = useSharedPluginState(api, ['typeAhead']);
13
+ const isTypeAheadOpen = Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen);
14
+ const isTypeAheadOpenedInsideItem = useMemo(() => {
15
+ var _selection$$cursor;
16
+ if (!isTypeAheadOpen) {
17
+ return false;
18
+ }
19
+ const itemPosition = getPos();
20
+ if (typeof itemPosition !== 'number') {
21
+ return false;
22
+ }
23
+ const selection = editorView.state.selection;
24
+ if (!(selection instanceof TextSelection)) {
25
+ return false;
26
+ }
27
+ const maybeItemNode = editorView.state.doc.nodeAt(itemPosition);
28
+ const maybeParentItemNode = (_selection$$cursor = selection.$cursor) === null || _selection$$cursor === void 0 ? void 0 : _selection$$cursor.node();
29
+ if (maybeItemNode && maybeParentItemNode && maybeItemNode.eq(maybeParentItemNode)) {
30
+ return true;
31
+ }
32
+ return false;
33
+ }, [isTypeAheadOpen, getPos, editorView]);
34
+ const showPlaceholder = Boolean(!isTypeAheadOpenedInsideItem && isContentNodeEmpty);
35
+ return showPlaceholder;
36
+ };
@@ -2,34 +2,38 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import React from 'react';
3
3
  import { AnalyticsListener } from '@atlaskit/analytics-next';
4
4
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
5
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
6
5
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
7
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
8
- import { stateKey as taskPluginKey } from '../pm-plugins/plugin-key';
6
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
7
+ import { useShowPlaceholder } from './hooks/use-show-placeholder';
9
8
  import TaskItem from '../ui/Task';
10
-
11
- //import { isTypeAheadOpen } from '../../type-ahead/utils';
12
-
13
9
  const TaskItemWrapper = ({
14
10
  localId,
15
11
  forwardRef,
16
12
  isDone,
17
13
  onChange,
18
- isFocused,
19
- isContentNodeEmpty,
20
14
  providerFactory,
21
- api
15
+ isContentNodeEmpty,
16
+ api,
17
+ getPos,
18
+ editorView
22
19
  }) => {
23
20
  const {
24
- typeAheadState
25
- } = useSharedPluginState(api, ['typeAhead']);
21
+ taskDecisionState
22
+ } = useSharedPluginState(api, ['taskDecision']);
23
+ const isFocused = Boolean((taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.focusedTaskItemLocalId) === localId);
24
+ const showPlaceholder = useShowPlaceholder({
25
+ editorView,
26
+ isContentNodeEmpty,
27
+ getPos,
28
+ api
29
+ });
26
30
  return /*#__PURE__*/React.createElement(TaskItem, {
27
31
  taskId: localId,
28
32
  contentRef: forwardRef,
29
33
  isDone: isDone,
30
34
  onChange: onChange,
31
35
  isFocused: isFocused,
32
- showPlaceholder: isContentNodeEmpty && !(typeAheadState !== null && typeAheadState !== void 0 && typeAheadState.isOpen),
36
+ showPlaceholder: showPlaceholder,
33
37
  providers: providerFactory
34
38
  });
35
39
  };
@@ -130,24 +134,19 @@ class Task extends ReactNodeView {
130
134
  return /*#__PURE__*/React.createElement(AnalyticsListener, {
131
135
  channel: "fabric-elements",
132
136
  onEvent: this.addListAnalyticsData
133
- }, /*#__PURE__*/React.createElement(WithPluginState, {
134
- plugins: {
135
- taskDecisionPlugin: taskPluginKey
136
- },
137
- render: ({
138
- taskDecisionPlugin
139
- }) => {
140
- return /*#__PURE__*/React.createElement(TaskItemWrapper, {
141
- localId: localId,
142
- forwardRef: forwardRef,
143
- isDone: state === 'DONE',
144
- onChange: this.handleOnChange,
145
- isFocused: Boolean((taskDecisionPlugin === null || taskDecisionPlugin === void 0 ? void 0 : taskDecisionPlugin.focusedTaskItemLocalId) === localId),
146
- isContentNodeEmpty: isContentNodeEmpty,
147
- providerFactory: props.providerFactory,
148
- api: this.api
149
- });
150
- }
137
+ }, /*#__PURE__*/React.createElement(TaskItemWrapper, {
138
+ localId: localId,
139
+ forwardRef: forwardRef,
140
+ isDone: state === 'DONE',
141
+ onChange: this.handleOnChange,
142
+ isContentNodeEmpty: isContentNodeEmpty,
143
+ providerFactory: props.providerFactory
144
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
145
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
146
+ ,
147
+ getPos: this.getPos,
148
+ editorView: this.view,
149
+ api: this.api
151
150
  }));
152
151
  }
153
152
  viewShouldUpdate(nextNode) {
@@ -1,5 +1,5 @@
1
1
  export const name = "@atlaskit/editor-core";
2
- export const version = "189.0.9";
2
+ export const version = "189.0.10";
3
3
  export const nextMajorVersion = () => {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -4,8 +4,9 @@ var _templateObject;
4
4
  import { css, jsx } from '@emotion/react';
5
5
  import { decisionItem, decisionList, taskItem, taskList } from '@atlaskit/adf-schema';
6
6
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
7
- import { messages as insertBlockMessages } from '../insert-block/ui/ToolbarInsertBlock/messages';
7
+ import { toolbarInsertBlockMessages as insertBlockMessages } from '@atlaskit/editor-common/messages';
8
8
  import { IconAction, IconDecision } from '@atlaskit/editor-common/quick-insert';
9
+ import { stateKey as taskPluginKey } from './pm-plugins/plugin-key';
9
10
  import { insertTaskDecisionAction, getListTypes } from './commands';
10
11
  import inputRulePlugin from './pm-plugins/input-rules';
11
12
  import keymap from './pm-plugins/keymaps';
@@ -51,6 +52,15 @@ var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
51
52
  node: taskItem
52
53
  }];
53
54
  },
55
+ getSharedState: function getSharedState(editorState) {
56
+ if (!editorState) {
57
+ return undefined;
58
+ }
59
+ var pluginState = taskPluginKey.getState(editorState);
60
+ return {
61
+ focusedTaskItemLocalId: (pluginState === null || pluginState === void 0 ? void 0 : pluginState.focusedTaskItemLocalId) || null
62
+ };
63
+ },
54
64
  pmPlugins: function pmPlugins() {
55
65
  return [{
56
66
  name: 'tasksAndDecisions',
@@ -8,17 +8,23 @@ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflec
8
8
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
9
9
  import React from 'react';
10
10
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
11
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
11
+ import { useShowPlaceholder } from './hooks/use-show-placeholder';
12
12
  import DecisionItem from '../ui/Decision';
13
13
  var DecisionItemWrapper = function DecisionItemWrapper(_ref) {
14
14
  var api = _ref.api,
15
+ editorView = _ref.editorView,
15
16
  forwardRef = _ref.forwardRef,
16
- isContentNodeEmpty = _ref.isContentNodeEmpty;
17
- var _useSharedPluginState = useSharedPluginState(api, ['typeAhead']),
18
- typeAheadState = _useSharedPluginState.typeAheadState;
17
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
18
+ getPos = _ref.getPos;
19
+ var showPlaceholder = useShowPlaceholder({
20
+ editorView: editorView,
21
+ isContentNodeEmpty: isContentNodeEmpty,
22
+ getPos: getPos,
23
+ api: api
24
+ });
19
25
  return /*#__PURE__*/React.createElement(DecisionItem, {
20
26
  contentRef: forwardRef,
21
- showPlaceholder: isContentNodeEmpty && !(typeAheadState !== null && typeAheadState !== void 0 && typeAheadState.isOpen)
27
+ showPlaceholder: showPlaceholder
22
28
  });
23
29
  };
24
30
  var Decision = /*#__PURE__*/function (_ReactNodeView) {
@@ -66,6 +72,11 @@ var Decision = /*#__PURE__*/function (_ReactNodeView) {
66
72
  forwardRef: forwardRef,
67
73
  isContentNodeEmpty: isContentNodeEmpty,
68
74
  api: this.api
75
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
76
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
77
+ ,
78
+ getPos: this.getPos,
79
+ editorView: this.view
69
80
  });
70
81
  }
71
82
  }, {
@@ -0,0 +1,34 @@
1
+ import { useMemo } from 'react';
2
+ import { TextSelection } from '@atlaskit/editor-prosemirror/state';
3
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
4
+ export var useShowPlaceholder = function useShowPlaceholder(_ref) {
5
+ var editorView = _ref.editorView,
6
+ api = _ref.api,
7
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
8
+ getPos = _ref.getPos;
9
+ var _useSharedPluginState = useSharedPluginState(api, ['typeAhead']),
10
+ typeAheadState = _useSharedPluginState.typeAheadState;
11
+ var isTypeAheadOpen = Boolean(typeAheadState === null || typeAheadState === void 0 ? void 0 : typeAheadState.isOpen);
12
+ var isTypeAheadOpenedInsideItem = useMemo(function () {
13
+ var _selection$$cursor;
14
+ if (!isTypeAheadOpen) {
15
+ return false;
16
+ }
17
+ var itemPosition = getPos();
18
+ if (typeof itemPosition !== 'number') {
19
+ return false;
20
+ }
21
+ var selection = editorView.state.selection;
22
+ if (!(selection instanceof TextSelection)) {
23
+ return false;
24
+ }
25
+ var maybeItemNode = editorView.state.doc.nodeAt(itemPosition);
26
+ var maybeParentItemNode = (_selection$$cursor = selection.$cursor) === null || _selection$$cursor === void 0 ? void 0 : _selection$$cursor.node();
27
+ if (maybeItemNode && maybeParentItemNode && maybeItemNode.eq(maybeParentItemNode)) {
28
+ return true;
29
+ }
30
+ return false;
31
+ }, [isTypeAheadOpen, getPos, editorView]);
32
+ var showPlaceholder = Boolean(!isTypeAheadOpenedInsideItem && isContentNodeEmpty);
33
+ return showPlaceholder;
34
+ };
@@ -13,32 +13,36 @@ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Re
13
13
  import React from 'react';
14
14
  import { AnalyticsListener } from '@atlaskit/analytics-next';
15
15
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
16
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
17
16
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
18
- import { WithPluginState } from '@atlaskit/editor-common/with-plugin-state';
19
- import { stateKey as taskPluginKey } from '../pm-plugins/plugin-key';
17
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
18
+ import { useShowPlaceholder } from './hooks/use-show-placeholder';
20
19
  import TaskItem from '../ui/Task';
21
-
22
- //import { isTypeAheadOpen } from '../../type-ahead/utils';
23
-
24
20
  var TaskItemWrapper = function TaskItemWrapper(_ref) {
25
21
  var localId = _ref.localId,
26
22
  forwardRef = _ref.forwardRef,
27
23
  isDone = _ref.isDone,
28
24
  onChange = _ref.onChange,
29
- isFocused = _ref.isFocused,
30
- isContentNodeEmpty = _ref.isContentNodeEmpty,
31
25
  providerFactory = _ref.providerFactory,
32
- api = _ref.api;
33
- var _useSharedPluginState = useSharedPluginState(api, ['typeAhead']),
34
- typeAheadState = _useSharedPluginState.typeAheadState;
26
+ isContentNodeEmpty = _ref.isContentNodeEmpty,
27
+ api = _ref.api,
28
+ getPos = _ref.getPos,
29
+ editorView = _ref.editorView;
30
+ var _useSharedPluginState = useSharedPluginState(api, ['taskDecision']),
31
+ taskDecisionState = _useSharedPluginState.taskDecisionState;
32
+ var isFocused = Boolean((taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.focusedTaskItemLocalId) === localId);
33
+ var showPlaceholder = useShowPlaceholder({
34
+ editorView: editorView,
35
+ isContentNodeEmpty: isContentNodeEmpty,
36
+ getPos: getPos,
37
+ api: api
38
+ });
35
39
  return /*#__PURE__*/React.createElement(TaskItem, {
36
40
  taskId: localId,
37
41
  contentRef: forwardRef,
38
42
  isDone: isDone,
39
43
  onChange: onChange,
40
44
  isFocused: isFocused,
41
- showPlaceholder: isContentNodeEmpty && !(typeAheadState !== null && typeAheadState !== void 0 && typeAheadState.isOpen),
45
+ showPlaceholder: showPlaceholder,
42
46
  providers: providerFactory
43
47
  });
44
48
  };
@@ -144,7 +148,6 @@ var Task = /*#__PURE__*/function (_ReactNodeView) {
144
148
  }, {
145
149
  key: "render",
146
150
  value: function render(props, forwardRef) {
147
- var _this2 = this;
148
151
  var _this$node$attrs = this.node.attrs,
149
152
  localId = _this$node$attrs.localId,
150
153
  state = _this$node$attrs.state;
@@ -152,23 +155,19 @@ var Task = /*#__PURE__*/function (_ReactNodeView) {
152
155
  return /*#__PURE__*/React.createElement(AnalyticsListener, {
153
156
  channel: "fabric-elements",
154
157
  onEvent: this.addListAnalyticsData
155
- }, /*#__PURE__*/React.createElement(WithPluginState, {
156
- plugins: {
157
- taskDecisionPlugin: taskPluginKey
158
- },
159
- render: function render(_ref2) {
160
- var taskDecisionPlugin = _ref2.taskDecisionPlugin;
161
- return /*#__PURE__*/React.createElement(TaskItemWrapper, {
162
- localId: localId,
163
- forwardRef: forwardRef,
164
- isDone: state === 'DONE',
165
- onChange: _this2.handleOnChange,
166
- isFocused: Boolean((taskDecisionPlugin === null || taskDecisionPlugin === void 0 ? void 0 : taskDecisionPlugin.focusedTaskItemLocalId) === localId),
167
- isContentNodeEmpty: isContentNodeEmpty,
168
- providerFactory: props.providerFactory,
169
- api: _this2.api
170
- });
171
- }
158
+ }, /*#__PURE__*/React.createElement(TaskItemWrapper, {
159
+ localId: localId,
160
+ forwardRef: forwardRef,
161
+ isDone: state === 'DONE',
162
+ onChange: this.handleOnChange,
163
+ isContentNodeEmpty: isContentNodeEmpty,
164
+ providerFactory: props.providerFactory
165
+ // The getPosHandler type is wrong, there is no `boolean` in the real implementation
166
+ // @ts-expect-error 2322: Type 'getPosHandler' is not assignable to type '() => number | undefined'.
167
+ ,
168
+ getPos: this.getPos,
169
+ editorView: this.view,
170
+ api: this.api
172
171
  }));
173
172
  }
174
173
  }, {
@@ -184,11 +183,11 @@ var Task = /*#__PURE__*/function (_ReactNodeView) {
184
183
  }, {
185
184
  key: "update",
186
185
  value: function update(node, decorations) {
187
- var _this3 = this;
186
+ var _this2 = this;
188
187
  return _get(_getPrototypeOf(Task.prototype), "update", this).call(this, node, decorations, undefined, function (currentNode, newNode) {
189
188
  return (
190
189
  // Toggle the placeholder based on whether user input exists
191
- !_this3.isContentEmpty(newNode) && !!(currentNode.attrs.state === newNode.attrs.state)
190
+ !_this2.isContentEmpty(newNode) && !!(currentNode.attrs.state === newNode.attrs.state)
192
191
  );
193
192
  });
194
193
  }
@@ -1,5 +1,5 @@
1
1
  export var name = "@atlaskit/editor-core";
2
- export var version = "189.0.9";
2
+ export var version = "189.0.10";
3
3
  export var nextMajorVersion = function nextMajorVersion() {
4
4
  return [Number(version.split('.')[0]) + 1, 0, 0].join('.');
5
5
  };
@@ -0,0 +1,11 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { TaskAndDecisionsPlugin } from '../../types';
4
+ type Props2 = {
5
+ editorView: EditorView;
6
+ api: ExtractInjectionAPI<TaskAndDecisionsPlugin> | undefined;
7
+ getPos: () => number | undefined;
8
+ isContentNodeEmpty: boolean;
9
+ };
10
+ export declare const useShowPlaceholder: ({ editorView, api, isContentNodeEmpty, getPos, }: Props2) => boolean;
11
+ export {};
@@ -26,8 +26,12 @@ export interface TaskDecisionPluginOptions extends LongPressSelectionPluginOptio
26
26
  allowNestedTasks?: boolean;
27
27
  consumeTabs?: boolean;
28
28
  }
29
+ export type TaskAndDecisionsSharedState = {
30
+ focusedTaskItemLocalId: string | null;
31
+ };
29
32
  export type TaskAndDecisionsPlugin = NextEditorPlugin<'taskDecision', {
30
33
  pluginConfiguration: TaskDecisionPluginOptions | undefined;
34
+ sharedState: TaskAndDecisionsSharedState | undefined;
31
35
  dependencies: [
32
36
  OptionalPlugin<TypeAheadPlugin>,
33
37
  OptionalPlugin<AnalyticsPlugin>
@@ -0,0 +1,11 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { TaskAndDecisionsPlugin } from '../../types';
4
+ type Props2 = {
5
+ editorView: EditorView;
6
+ api: ExtractInjectionAPI<TaskAndDecisionsPlugin> | undefined;
7
+ getPos: () => number | undefined;
8
+ isContentNodeEmpty: boolean;
9
+ };
10
+ export declare const useShowPlaceholder: ({ editorView, api, isContentNodeEmpty, getPos, }: Props2) => boolean;
11
+ export {};
@@ -26,8 +26,12 @@ export interface TaskDecisionPluginOptions extends LongPressSelectionPluginOptio
26
26
  allowNestedTasks?: boolean;
27
27
  consumeTabs?: boolean;
28
28
  }
29
+ export type TaskAndDecisionsSharedState = {
30
+ focusedTaskItemLocalId: string | null;
31
+ };
29
32
  export type TaskAndDecisionsPlugin = NextEditorPlugin<'taskDecision', {
30
33
  pluginConfiguration: TaskDecisionPluginOptions | undefined;
34
+ sharedState: TaskAndDecisionsSharedState | undefined;
31
35
  dependencies: [
32
36
  OptionalPlugin<TypeAheadPlugin>,
33
37
  OptionalPlugin<AnalyticsPlugin>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-core",
3
- "version": "189.0.9",
3
+ "version": "189.0.10",
4
4
  "description": "A package contains Atlassian editor core functionality",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"