@atlaskit/editor-plugin-tasks-and-decisions 2.7.7 → 2.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # @atlaskit/editor-plugin-tasks-and-decisions
2
2
 
3
+ ## 2.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#148391](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/148391)
8
+ [`3588af87c8dc3`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3588af87c8dc3) -
9
+ [ux] ED-24964 Sync up request to edit between plugin and confluence
10
+
3
11
  ## 2.7.7
4
12
 
5
13
  ### Patch Changes
@@ -36,6 +36,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
36
36
  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; }
37
37
  function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = (0, _getPrototypeOf2.default)(t); if (r) { var s = (0, _getPrototypeOf2.default)(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return (0, _possibleConstructorReturn2.default)(this, e); }; }
38
38
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
39
+ var TRYING_REQUEST_TIMEOUT = 3000;
39
40
  var wrapperStyles = (0, _primitives.xcss)({
40
41
  display: 'flex',
41
42
  flexDirection: 'column',
@@ -116,12 +117,31 @@ var TaskItemWrapper = function TaskItemWrapper(_ref2) {
116
117
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
117
118
  isOpen = _useState2[0],
118
119
  setIsOpen = _useState2[1];
119
- var _useState3 = (0, _react.useState)(false),
120
+ var _useState3 = (0, _react.useState)(taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission),
120
121
  _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
121
122
  requested = _useState4[0],
122
123
  setRequested = _useState4[1];
124
+ var _useState5 = (0, _react.useState)(false),
125
+ _useState6 = (0, _slicedToArray2.default)(_useState5, 2),
126
+ tryingRequest = _useState6[0],
127
+ setTryingRequest = _useState6[1];
123
128
  var _useIntl3 = (0, _reactIntlNext.useIntl)(),
124
129
  formatMessage = _useIntl3.formatMessage;
130
+ (0, _react.useEffect)(function () {
131
+ if ((0, _platformFeatureFlags.fg)('editor_request_to_edit_task')) {
132
+ setRequested(taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission);
133
+ }
134
+ }, [taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission]);
135
+ (0, _react.useEffect)(function () {
136
+ if (!tryingRequest && (0, _platformFeatureFlags.fg)('editor_request_to_edit_task')) {
137
+ var timout = setTimeout(function () {
138
+ setTryingRequest(false);
139
+ }, TRYING_REQUEST_TIMEOUT);
140
+ return function () {
141
+ return clearTimeout(timout);
142
+ };
143
+ }
144
+ }, [tryingRequest]);
125
145
  var showPlaceholder = (0, _useShowPlaceholder.useShowPlaceholder)({
126
146
  editorView: editorView,
127
147
  isContentNodeEmpty: isContentNodeEmpty,
@@ -131,7 +151,7 @@ var TaskItemWrapper = function TaskItemWrapper(_ref2) {
131
151
  var onHandleEdit = function onHandleEdit(editorAnalyticsAPI) {
132
152
  if ((0, _platformFeatureFlags.fg)('editor_request_to_edit_task')) {
133
153
  var _api$taskDecision;
134
- setRequested(true);
154
+ setTryingRequest(true);
135
155
  var tr = editorView.state.tr;
136
156
  var nodePos = getPos();
137
157
  if (typeof nodePos !== 'number') {
@@ -185,7 +205,7 @@ var TaskItemWrapper = function TaskItemWrapper(_ref2) {
185
205
  size: "xsmall"
186
206
  }, formatMessage(_messages.tasksAndDecisionsMessages.editAccessTitle)), /*#__PURE__*/_react.default.createElement("div", null, formatMessage(_messages.tasksAndDecisionsMessages.requestToEditDescription)), /*#__PURE__*/_react.default.createElement(_primitives.Box, {
187
207
  xcss: wrapperBoxStyles
188
- }, requested ? /*#__PURE__*/_react.default.createElement(RequestedMessage, null) : /*#__PURE__*/_react.default.createElement(RequestToEditButton, {
208
+ }, tryingRequest || requested ? /*#__PURE__*/_react.default.createElement(RequestedMessage, null) : /*#__PURE__*/_react.default.createElement(RequestToEditButton, {
189
209
  onClick: (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'view' ? function () {
190
210
  var _api$analytics2;
191
211
  return onHandleEdit(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
@@ -121,6 +121,7 @@ var tasksAndDecisionsPlugin = exports.tasksAndDecisionsPlugin = function tasksAn
121
121
  consumeTabs = _ref2$config2.consumeTabs,
122
122
  useLongPressSelection = _ref2$config2.useLongPressSelection,
123
123
  hasEditPermission = _ref2$config2.hasEditPermission,
124
+ hasRequestedEditPermission = _ref2$config2.hasRequestedEditPermission,
124
125
  requestToEditContent = _ref2$config2.requestToEditContent,
125
126
  api = _ref2.api;
126
127
  var getIdentifierProvider = function getIdentifierProvider() {
@@ -157,7 +158,8 @@ var tasksAndDecisionsPlugin = exports.tasksAndDecisionsPlugin = function tasksAn
157
158
  indentDisabled: itemIndex === 0 || indentLevel >= _indentation.MAX_INDENTATION_LEVEL,
158
159
  outdentDisabled: indentLevel <= 1,
159
160
  hasEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasEditPermission,
160
- requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent
161
+ requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent,
162
+ hasRequestedEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasRequestedEditPermission
161
163
  };
162
164
  },
163
165
  commands: {
@@ -168,6 +170,14 @@ var tasksAndDecisionsPlugin = exports.tasksAndDecisionsPlugin = function tasksAn
168
170
  hasEditPermission: hasEditPermission
169
171
  });
170
172
  };
173
+ },
174
+ updateHasRequestedEditPermission: function updateHasRequestedEditPermission(hasRequestedEditPermission) {
175
+ return function (_ref4) {
176
+ var tr = _ref4.tr;
177
+ return tr.setMeta(_pluginKey.stateKey, {
178
+ hasRequestedEditPermission: hasRequestedEditPermission
179
+ });
180
+ };
171
181
  }
172
182
  },
173
183
  actions: {
@@ -178,33 +188,33 @@ var tasksAndDecisionsPlugin = exports.tasksAndDecisionsPlugin = function tasksAn
178
188
  pmPlugins: function pmPlugins() {
179
189
  return [{
180
190
  name: 'tasksAndDecisions',
181
- plugin: function plugin(_ref4) {
182
- var portalProviderAPI = _ref4.portalProviderAPI,
183
- providerFactory = _ref4.providerFactory,
184
- eventDispatcher = _ref4.eventDispatcher,
185
- dispatch = _ref4.dispatch;
186
- return (0, _main.createPlugin)(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection, hasEditPermission, requestToEditContent);
191
+ plugin: function plugin(_ref5) {
192
+ var portalProviderAPI = _ref5.portalProviderAPI,
193
+ providerFactory = _ref5.providerFactory,
194
+ eventDispatcher = _ref5.eventDispatcher,
195
+ dispatch = _ref5.dispatch;
196
+ return (0, _main.createPlugin)(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection, hasEditPermission, hasRequestedEditPermission, requestToEditContent);
187
197
  }
188
198
  }, {
189
199
  name: 'tasksAndDecisionsInputRule',
190
- plugin: function plugin(_ref5) {
200
+ plugin: function plugin(_ref6) {
191
201
  var _api$analytics4;
192
- var schema = _ref5.schema,
193
- featureFlags = _ref5.featureFlags;
202
+ var schema = _ref6.schema,
203
+ featureFlags = _ref6.featureFlags;
194
204
  return (0, _inputRules.default)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, getIdentifierProvider)(schema, featureFlags);
195
205
  }
196
206
  }, {
197
207
  name: 'tasksAndDecisionsKeyMap',
198
- plugin: function plugin(_ref6) {
199
- var schema = _ref6.schema;
208
+ plugin: function plugin(_ref7) {
209
+ var schema = _ref7.schema;
200
210
  return (0, _keymaps.default)(schema, api, allowNestedTasks, consumeTabs);
201
211
  }
202
212
  } // Needs to be after "save-on-enter"
203
213
  ];
204
214
  },
205
- secondaryToolbarComponent: function secondaryToolbarComponent(_ref7) {
206
- var editorView = _ref7.editorView,
207
- disabled = _ref7.disabled;
215
+ secondaryToolbarComponent: function secondaryToolbarComponent(_ref8) {
216
+ var editorView = _ref8.editorView,
217
+ disabled = _ref8.disabled;
208
218
  return (0, _react.jsx)("div", {
209
219
  css: taskDecisionToolbarGroupStyles
210
220
  }, (0, _react.jsx)(_ToolbarDecision.default, {
@@ -220,8 +230,8 @@ var tasksAndDecisionsPlugin = exports.tasksAndDecisionsPlugin = function tasksAn
220
230
  }));
221
231
  },
222
232
  pluginsOptions: {
223
- quickInsert: function quickInsert(_ref8) {
224
- var formatMessage = _ref8.formatMessage;
233
+ quickInsert: function quickInsert(_ref9) {
234
+ var formatMessage = _ref9.formatMessage;
225
235
  return [{
226
236
  id: 'action',
227
237
  title: formatMessage(_messages.toolbarInsertBlockMessages.action),
@@ -32,7 +32,8 @@ function nodesBetweenChanged(tr, f, startPos) {
32
32
  function createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api) {
33
33
  var useLongPressSelection = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
34
34
  var hasEditPermission = arguments.length > 6 ? arguments[6] : undefined;
35
- var requestToEditContent = arguments.length > 7 ? arguments[7] : undefined;
35
+ var hasRequestedEditPermission = arguments.length > 7 ? arguments[7] : undefined;
36
+ var requestToEditContent = arguments.length > 8 ? arguments[8] : undefined;
36
37
  return new _safePlugin.SafePlugin({
37
38
  props: {
38
39
  nodeViews: {
@@ -169,6 +170,7 @@ function createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispa
169
170
  return {
170
171
  insideTaskDecisionItem: false,
171
172
  hasEditPermission: hasEditPermission,
173
+ hasRequestedEditPermission: hasRequestedEditPermission,
172
174
  requestToEditContent: requestToEditContent
173
175
  };
174
176
  },
@@ -197,6 +199,11 @@ function createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispa
197
199
  hasEditPermission: metaData.hasEditPermission
198
200
  });
199
201
  }
202
+ if (metaData && 'hasRequestedEditPermission' in metaData && (0, _platformFeatureFlags.fg)('editor_request_to_edit_task')) {
203
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
204
+ hasRequestedEditPermission: metaData.hasRequestedEditPermission
205
+ });
206
+ }
200
207
 
201
208
  // Dispatch
202
209
  dispatch(_pluginKey.stateKey, newPluginState);
@@ -1,5 +1,5 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { useState } from 'react';
2
+ import React, { useEffect, useState } from 'react';
3
3
  import { useIntl } from 'react-intl-next';
4
4
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
5
5
  import { AnalyticsListener } from '@atlaskit/analytics-next';
@@ -14,6 +14,7 @@ import Popup from '@atlaskit/popup';
14
14
  import { Box, Pressable, Stack, xcss } from '@atlaskit/primitives';
15
15
  import TaskItem from '../ui/Task';
16
16
  import { useShowPlaceholder } from './hooks/use-show-placeholder';
17
+ const TRYING_REQUEST_TIMEOUT = 3000;
17
18
  const wrapperStyles = xcss({
18
19
  display: 'flex',
19
20
  flexDirection: 'column',
@@ -96,10 +97,24 @@ const TaskItemWrapper = ({
96
97
  } = useSharedPluginState(api, ['taskDecision']);
97
98
  const isFocused = Boolean((taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.focusedTaskItemLocalId) === localId);
98
99
  const [isOpen, setIsOpen] = useState(false);
99
- const [requested, setRequested] = useState(false);
100
+ const [requested, setRequested] = useState(taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission);
101
+ const [tryingRequest, setTryingRequest] = useState(false);
100
102
  const {
101
103
  formatMessage
102
104
  } = useIntl();
105
+ useEffect(() => {
106
+ if (fg('editor_request_to_edit_task')) {
107
+ setRequested(taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission);
108
+ }
109
+ }, [taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission]);
110
+ useEffect(() => {
111
+ if (!tryingRequest && fg('editor_request_to_edit_task')) {
112
+ const timout = setTimeout(() => {
113
+ setTryingRequest(false);
114
+ }, TRYING_REQUEST_TIMEOUT);
115
+ return () => clearTimeout(timout);
116
+ }
117
+ }, [tryingRequest]);
103
118
  const showPlaceholder = useShowPlaceholder({
104
119
  editorView,
105
120
  isContentNodeEmpty,
@@ -109,7 +124,7 @@ const TaskItemWrapper = ({
109
124
  const onHandleEdit = editorAnalyticsAPI => {
110
125
  if (fg('editor_request_to_edit_task')) {
111
126
  var _api$taskDecision, _api$taskDecision$sha;
112
- setRequested(true);
127
+ setTryingRequest(true);
113
128
  const {
114
129
  tr
115
130
  } = editorView.state;
@@ -165,7 +180,7 @@ const TaskItemWrapper = ({
165
180
  size: "xsmall"
166
181
  }, formatMessage(tasksAndDecisionsMessages.editAccessTitle)), /*#__PURE__*/React.createElement("div", null, formatMessage(tasksAndDecisionsMessages.requestToEditDescription)), /*#__PURE__*/React.createElement(Box, {
167
182
  xcss: wrapperBoxStyles
168
- }, requested ? /*#__PURE__*/React.createElement(RequestedMessage, null) : /*#__PURE__*/React.createElement(RequestToEditButton, {
183
+ }, tryingRequest || requested ? /*#__PURE__*/React.createElement(RequestedMessage, null) : /*#__PURE__*/React.createElement(RequestToEditButton, {
169
184
  onClick: (api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : (_api$editorViewMode$s = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode$s === void 0 ? void 0 : _api$editorViewMode$s.mode) === 'view' ? () => {
170
185
  var _api$analytics2;
171
186
  return onHandleEdit(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
@@ -110,6 +110,7 @@ export const tasksAndDecisionsPlugin = ({
110
110
  consumeTabs,
111
111
  useLongPressSelection,
112
112
  hasEditPermission,
113
+ hasRequestedEditPermission,
113
114
  requestToEditContent
114
115
  } = {},
115
116
  api
@@ -149,7 +150,8 @@ export const tasksAndDecisionsPlugin = ({
149
150
  indentDisabled: itemIndex === 0 || indentLevel >= MAX_INDENTATION_LEVEL,
150
151
  outdentDisabled: indentLevel <= 1,
151
152
  hasEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasEditPermission,
152
- requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent
153
+ requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent,
154
+ hasRequestedEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasRequestedEditPermission
153
155
  };
154
156
  },
155
157
  commands: {
@@ -157,6 +159,11 @@ export const tasksAndDecisionsPlugin = ({
157
159
  tr
158
160
  }) => tr.setMeta(taskPluginKey, {
159
161
  hasEditPermission
162
+ }),
163
+ updateHasRequestedEditPermission: hasRequestedEditPermission => ({
164
+ tr
165
+ }) => tr.setMeta(taskPluginKey, {
166
+ hasRequestedEditPermission
160
167
  })
161
168
  },
162
169
  actions: {
@@ -173,7 +180,7 @@ export const tasksAndDecisionsPlugin = ({
173
180
  eventDispatcher,
174
181
  dispatch
175
182
  }) => {
176
- return createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection, hasEditPermission, requestToEditContent);
183
+ return createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection, hasEditPermission, hasRequestedEditPermission, requestToEditContent);
177
184
  }
178
185
  }, {
179
186
  name: 'tasksAndDecisionsInputRule',
@@ -17,7 +17,7 @@ function nodesBetweenChanged(tr, f, startPos) {
17
17
  }
18
18
  tr.doc.nodesBetween(stepRange.from, stepRange.to, f, startPos);
19
19
  }
20
- export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection = false, hasEditPermission, requestToEditContent) {
20
+ export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection = false, hasEditPermission, hasRequestedEditPermission, requestToEditContent) {
21
21
  return new SafePlugin({
22
22
  props: {
23
23
  nodeViews: {
@@ -162,6 +162,7 @@ export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory
162
162
  return {
163
163
  insideTaskDecisionItem: false,
164
164
  hasEditPermission,
165
+ hasRequestedEditPermission,
165
166
  requestToEditContent
166
167
  };
167
168
  },
@@ -193,6 +194,12 @@ export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory
193
194
  hasEditPermission: metaData.hasEditPermission
194
195
  };
195
196
  }
197
+ if (metaData && 'hasRequestedEditPermission' in metaData && fg('editor_request_to_edit_task')) {
198
+ newPluginState = {
199
+ ...newPluginState,
200
+ hasRequestedEditPermission: metaData.hasRequestedEditPermission
201
+ };
202
+ }
196
203
 
197
204
  // Dispatch
198
205
  dispatch(stateKey, newPluginState);
@@ -11,7 +11,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
11
11
  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) { _defineProperty(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; }
12
12
  function _createSuper(t) { var r = _isNativeReflectConstruct(); return function () { var e, o = _getPrototypeOf(t); if (r) { var s = _getPrototypeOf(this).constructor; e = Reflect.construct(o, arguments, s); } else e = o.apply(this, arguments); return _possibleConstructorReturn(this, e); }; }
13
13
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
14
- import React, { useState } from 'react';
14
+ import React, { useEffect, useState } from 'react';
15
15
  import { useIntl } from 'react-intl-next';
16
16
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
17
17
  import { AnalyticsListener } from '@atlaskit/analytics-next';
@@ -26,6 +26,7 @@ import Popup from '@atlaskit/popup';
26
26
  import { Box, Pressable, Stack, xcss } from '@atlaskit/primitives';
27
27
  import TaskItem from '../ui/Task';
28
28
  import { useShowPlaceholder } from './hooks/use-show-placeholder';
29
+ var TRYING_REQUEST_TIMEOUT = 3000;
29
30
  var wrapperStyles = xcss({
30
31
  display: 'flex',
31
32
  flexDirection: 'column',
@@ -106,12 +107,31 @@ var TaskItemWrapper = function TaskItemWrapper(_ref2) {
106
107
  _useState2 = _slicedToArray(_useState, 2),
107
108
  isOpen = _useState2[0],
108
109
  setIsOpen = _useState2[1];
109
- var _useState3 = useState(false),
110
+ var _useState3 = useState(taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission),
110
111
  _useState4 = _slicedToArray(_useState3, 2),
111
112
  requested = _useState4[0],
112
113
  setRequested = _useState4[1];
114
+ var _useState5 = useState(false),
115
+ _useState6 = _slicedToArray(_useState5, 2),
116
+ tryingRequest = _useState6[0],
117
+ setTryingRequest = _useState6[1];
113
118
  var _useIntl3 = useIntl(),
114
119
  formatMessage = _useIntl3.formatMessage;
120
+ useEffect(function () {
121
+ if (fg('editor_request_to_edit_task')) {
122
+ setRequested(taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission);
123
+ }
124
+ }, [taskDecisionState === null || taskDecisionState === void 0 ? void 0 : taskDecisionState.hasRequestedEditPermission]);
125
+ useEffect(function () {
126
+ if (!tryingRequest && fg('editor_request_to_edit_task')) {
127
+ var timout = setTimeout(function () {
128
+ setTryingRequest(false);
129
+ }, TRYING_REQUEST_TIMEOUT);
130
+ return function () {
131
+ return clearTimeout(timout);
132
+ };
133
+ }
134
+ }, [tryingRequest]);
115
135
  var showPlaceholder = useShowPlaceholder({
116
136
  editorView: editorView,
117
137
  isContentNodeEmpty: isContentNodeEmpty,
@@ -121,7 +141,7 @@ var TaskItemWrapper = function TaskItemWrapper(_ref2) {
121
141
  var onHandleEdit = function onHandleEdit(editorAnalyticsAPI) {
122
142
  if (fg('editor_request_to_edit_task')) {
123
143
  var _api$taskDecision;
124
- setRequested(true);
144
+ setTryingRequest(true);
125
145
  var tr = editorView.state.tr;
126
146
  var nodePos = getPos();
127
147
  if (typeof nodePos !== 'number') {
@@ -175,7 +195,7 @@ var TaskItemWrapper = function TaskItemWrapper(_ref2) {
175
195
  size: "xsmall"
176
196
  }, formatMessage(tasksAndDecisionsMessages.editAccessTitle)), /*#__PURE__*/React.createElement("div", null, formatMessage(tasksAndDecisionsMessages.requestToEditDescription)), /*#__PURE__*/React.createElement(Box, {
177
197
  xcss: wrapperBoxStyles
178
- }, requested ? /*#__PURE__*/React.createElement(RequestedMessage, null) : /*#__PURE__*/React.createElement(RequestToEditButton, {
198
+ }, tryingRequest || requested ? /*#__PURE__*/React.createElement(RequestedMessage, null) : /*#__PURE__*/React.createElement(RequestToEditButton, {
179
199
  onClick: (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'view' ? function () {
180
200
  var _api$analytics2;
181
201
  return onHandleEdit(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
@@ -113,6 +113,7 @@ export var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
113
113
  consumeTabs = _ref2$config2.consumeTabs,
114
114
  useLongPressSelection = _ref2$config2.useLongPressSelection,
115
115
  hasEditPermission = _ref2$config2.hasEditPermission,
116
+ hasRequestedEditPermission = _ref2$config2.hasRequestedEditPermission,
116
117
  requestToEditContent = _ref2$config2.requestToEditContent,
117
118
  api = _ref2.api;
118
119
  var getIdentifierProvider = function getIdentifierProvider() {
@@ -149,7 +150,8 @@ export var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
149
150
  indentDisabled: itemIndex === 0 || indentLevel >= MAX_INDENTATION_LEVEL,
150
151
  outdentDisabled: indentLevel <= 1,
151
152
  hasEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasEditPermission,
152
- requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent
153
+ requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent,
154
+ hasRequestedEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasRequestedEditPermission
153
155
  };
154
156
  },
155
157
  commands: {
@@ -160,6 +162,14 @@ export var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
160
162
  hasEditPermission: hasEditPermission
161
163
  });
162
164
  };
165
+ },
166
+ updateHasRequestedEditPermission: function updateHasRequestedEditPermission(hasRequestedEditPermission) {
167
+ return function (_ref4) {
168
+ var tr = _ref4.tr;
169
+ return tr.setMeta(taskPluginKey, {
170
+ hasRequestedEditPermission: hasRequestedEditPermission
171
+ });
172
+ };
163
173
  }
164
174
  },
165
175
  actions: {
@@ -170,33 +180,33 @@ export var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
170
180
  pmPlugins: function pmPlugins() {
171
181
  return [{
172
182
  name: 'tasksAndDecisions',
173
- plugin: function plugin(_ref4) {
174
- var portalProviderAPI = _ref4.portalProviderAPI,
175
- providerFactory = _ref4.providerFactory,
176
- eventDispatcher = _ref4.eventDispatcher,
177
- dispatch = _ref4.dispatch;
178
- return createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection, hasEditPermission, requestToEditContent);
183
+ plugin: function plugin(_ref5) {
184
+ var portalProviderAPI = _ref5.portalProviderAPI,
185
+ providerFactory = _ref5.providerFactory,
186
+ eventDispatcher = _ref5.eventDispatcher,
187
+ dispatch = _ref5.dispatch;
188
+ return createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api, useLongPressSelection, hasEditPermission, hasRequestedEditPermission, requestToEditContent);
179
189
  }
180
190
  }, {
181
191
  name: 'tasksAndDecisionsInputRule',
182
- plugin: function plugin(_ref5) {
192
+ plugin: function plugin(_ref6) {
183
193
  var _api$analytics4;
184
- var schema = _ref5.schema,
185
- featureFlags = _ref5.featureFlags;
194
+ var schema = _ref6.schema,
195
+ featureFlags = _ref6.featureFlags;
186
196
  return inputRulePlugin(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, getIdentifierProvider)(schema, featureFlags);
187
197
  }
188
198
  }, {
189
199
  name: 'tasksAndDecisionsKeyMap',
190
- plugin: function plugin(_ref6) {
191
- var schema = _ref6.schema;
200
+ plugin: function plugin(_ref7) {
201
+ var schema = _ref7.schema;
192
202
  return keymap(schema, api, allowNestedTasks, consumeTabs);
193
203
  }
194
204
  } // Needs to be after "save-on-enter"
195
205
  ];
196
206
  },
197
- secondaryToolbarComponent: function secondaryToolbarComponent(_ref7) {
198
- var editorView = _ref7.editorView,
199
- disabled = _ref7.disabled;
207
+ secondaryToolbarComponent: function secondaryToolbarComponent(_ref8) {
208
+ var editorView = _ref8.editorView,
209
+ disabled = _ref8.disabled;
200
210
  return jsx("div", {
201
211
  css: taskDecisionToolbarGroupStyles
202
212
  }, jsx(ToolbarDecision, {
@@ -212,8 +222,8 @@ export var tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref2) {
212
222
  }));
213
223
  },
214
224
  pluginsOptions: {
215
- quickInsert: function quickInsert(_ref8) {
216
- var formatMessage = _ref8.formatMessage;
225
+ quickInsert: function quickInsert(_ref9) {
226
+ var formatMessage = _ref9.formatMessage;
217
227
  return [{
218
228
  id: 'action',
219
229
  title: formatMessage(insertBlockMessages.action),
@@ -25,7 +25,8 @@ function nodesBetweenChanged(tr, f, startPos) {
25
25
  export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory, dispatch, api) {
26
26
  var useLongPressSelection = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false;
27
27
  var hasEditPermission = arguments.length > 6 ? arguments[6] : undefined;
28
- var requestToEditContent = arguments.length > 7 ? arguments[7] : undefined;
28
+ var hasRequestedEditPermission = arguments.length > 7 ? arguments[7] : undefined;
29
+ var requestToEditContent = arguments.length > 8 ? arguments[8] : undefined;
29
30
  return new SafePlugin({
30
31
  props: {
31
32
  nodeViews: {
@@ -162,6 +163,7 @@ export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory
162
163
  return {
163
164
  insideTaskDecisionItem: false,
164
165
  hasEditPermission: hasEditPermission,
166
+ hasRequestedEditPermission: hasRequestedEditPermission,
165
167
  requestToEditContent: requestToEditContent
166
168
  };
167
169
  },
@@ -190,6 +192,11 @@ export function createPlugin(portalProviderAPI, eventDispatcher, providerFactory
190
192
  hasEditPermission: metaData.hasEditPermission
191
193
  });
192
194
  }
195
+ if (metaData && 'hasRequestedEditPermission' in metaData && fg('editor_request_to_edit_task')) {
196
+ newPluginState = _objectSpread(_objectSpread({}, newPluginState), {}, {
197
+ hasRequestedEditPermission: metaData.hasRequestedEditPermission
198
+ });
199
+ }
193
200
 
194
201
  // Dispatch
195
202
  dispatch(stateKey, newPluginState);
@@ -4,4 +4,4 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { type PortalProviderAPI } from '@atlaskit/editor-common/src/portal';
5
5
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
6
  import type { TasksAndDecisionsPlugin } from '../types';
7
- export declare function createPlugin(portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, providerFactory: ProviderFactory, dispatch: Dispatch, api: ExtractInjectionAPI<TasksAndDecisionsPlugin> | undefined, useLongPressSelection?: boolean, hasEditPermission?: boolean, requestToEditContent?: () => void): SafePlugin<any>;
7
+ export declare function createPlugin(portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, providerFactory: ProviderFactory, dispatch: Dispatch, api: ExtractInjectionAPI<TasksAndDecisionsPlugin> | undefined, useLongPressSelection?: boolean, hasEditPermission?: boolean, hasRequestedEditPermission?: boolean, requestToEditContent?: () => void): SafePlugin<any>;
@@ -47,6 +47,11 @@ export interface TaskDecisionPluginOptions extends LongPressSelectionPluginOptio
47
47
  * @default false
48
48
  */
49
49
  hasEditPermission?: boolean;
50
+ /**
51
+ * Indicates whether the user has requested permission to edit.
52
+ * @default false
53
+ */
54
+ hasRequestedEditPermission?: boolean;
50
55
  /**
51
56
  * Function to request edit permission.
52
57
  */
@@ -58,6 +63,7 @@ export type TaskAndDecisionsSharedState = {
58
63
  outdentDisabled: boolean;
59
64
  isInsideTask: boolean;
60
65
  hasEditPermission?: boolean;
66
+ hasRequestedEditPermission?: boolean;
61
67
  requestToEditContent?: () => void;
62
68
  };
63
69
  export type TasksAndDecisionsPlugin = NextEditorPlugin<'taskDecision', {
@@ -76,6 +82,7 @@ export type TasksAndDecisionsPlugin = NextEditorPlugin<'taskDecision', {
76
82
  };
77
83
  commands: {
78
84
  updateEditPermission: (hasEditPermission: boolean | undefined) => EditorCommand;
85
+ updateHasRequestedEditPermission: (hasRequestedEditPermission: boolean) => EditorCommand;
79
86
  };
80
87
  }>;
81
88
  export type GetContextIdentifier = () => ContextIdentifierProvider | undefined;
@@ -4,4 +4,4 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { type PortalProviderAPI } from '@atlaskit/editor-common/src/portal';
5
5
  import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
6
6
  import type { TasksAndDecisionsPlugin } from '../types';
7
- export declare function createPlugin(portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, providerFactory: ProviderFactory, dispatch: Dispatch, api: ExtractInjectionAPI<TasksAndDecisionsPlugin> | undefined, useLongPressSelection?: boolean, hasEditPermission?: boolean, requestToEditContent?: () => void): SafePlugin<any>;
7
+ export declare function createPlugin(portalProviderAPI: PortalProviderAPI, eventDispatcher: EventDispatcher, providerFactory: ProviderFactory, dispatch: Dispatch, api: ExtractInjectionAPI<TasksAndDecisionsPlugin> | undefined, useLongPressSelection?: boolean, hasEditPermission?: boolean, hasRequestedEditPermission?: boolean, requestToEditContent?: () => void): SafePlugin<any>;
@@ -47,6 +47,11 @@ export interface TaskDecisionPluginOptions extends LongPressSelectionPluginOptio
47
47
  * @default false
48
48
  */
49
49
  hasEditPermission?: boolean;
50
+ /**
51
+ * Indicates whether the user has requested permission to edit.
52
+ * @default false
53
+ */
54
+ hasRequestedEditPermission?: boolean;
50
55
  /**
51
56
  * Function to request edit permission.
52
57
  */
@@ -58,6 +63,7 @@ export type TaskAndDecisionsSharedState = {
58
63
  outdentDisabled: boolean;
59
64
  isInsideTask: boolean;
60
65
  hasEditPermission?: boolean;
66
+ hasRequestedEditPermission?: boolean;
61
67
  requestToEditContent?: () => void;
62
68
  };
63
69
  export type TasksAndDecisionsPlugin = NextEditorPlugin<'taskDecision', {
@@ -76,6 +82,7 @@ export type TasksAndDecisionsPlugin = NextEditorPlugin<'taskDecision', {
76
82
  };
77
83
  commands: {
78
84
  updateEditPermission: (hasEditPermission: boolean | undefined) => EditorCommand;
85
+ updateHasRequestedEditPermission: (hasRequestedEditPermission: boolean) => EditorCommand;
79
86
  };
80
87
  }>;
81
88
  export type GetContextIdentifier = () => ContextIdentifierProvider | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-tasks-and-decisions",
3
- "version": "2.7.7",
3
+ "version": "2.8.0",
4
4
  "description": "Tasks and decisions plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",