@atlaskit/editor-plugin-type-ahead 3.0.0 → 3.0.2

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,21 @@
1
1
  # @atlaskit/editor-plugin-type-ahead
2
2
 
3
+ ## 3.0.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 3.0.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [#181781](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/181781)
14
+ [`e0060cc2c2eb7`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/e0060cc2c2eb7) -
15
+ ED-28417 Offline Editing: Update the type ahead error to clear on new requests, and make error
16
+ more generic.
17
+ - Updated dependencies
18
+
3
19
  ## 3.0.0
4
20
 
5
21
  ### Major Changes
@@ -12,6 +12,7 @@ var ACTIONS = exports.ACTIONS = /*#__PURE__*/function (ACTIONS) {
12
12
  ACTIONS["INSERT_RAW_QUERY"] = "INSERT_RAW_QUERY";
13
13
  ACTIONS["UPDATE_LIST_ITEMS"] = "UPDATE_LIST_ITEMS";
14
14
  ACTIONS["UPDATE_LIST_ERROR"] = "UPDATE_LIST_ERROR";
15
+ ACTIONS["CLEAR_LIST_ERROR"] = "CLEAR_LIST_ERROR";
15
16
  ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
16
17
  return ACTIONS;
17
18
  }({});
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clearListError = void 0;
7
+ var _actions = require("../actions");
8
+ var _key = require("../key");
9
+ var clearListError = exports.clearListError = function clearListError() {
10
+ return function (_ref) {
11
+ var tr = _ref.tr;
12
+ tr.setMeta(_key.pluginKey, {
13
+ action: _actions.ACTIONS.CLEAR_LIST_ERROR,
14
+ params: {
15
+ errorInfo: null
16
+ }
17
+ });
18
+ return tr;
19
+ };
20
+ };
@@ -114,6 +114,7 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
114
114
  var shouldUpdateListItems = action === _actions.ACTIONS.UPDATE_LIST_ITEMS;
115
115
  var shouldUpdateListError = action === _actions.ACTIONS.UPDATE_LIST_ERROR;
116
116
  var shouldUpdateSelectedIndex = action === _actions.ACTIONS.UPDATE_SELECTED_INDEX;
117
+ var shouldClearListError = action === _actions.ACTIONS.CLEAR_LIST_ERROR;
117
118
  if (shouldOpenMenu) {
118
119
  return openMenu(currentPluginState, {
119
120
  tr: tr,
@@ -146,6 +147,10 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
146
147
  return _objectSpread(_objectSpread({}, currentPluginState), {}, {
147
148
  selectedIndex: params.selectedIndex
148
149
  });
150
+ } else if (shouldClearListError) {
151
+ return _objectSpread(_objectSpread({}, currentPluginState), {}, {
152
+ errorInfo: null
153
+ });
149
154
  }
150
155
  if (tr.docChanged) {
151
156
  var decorationSet = currentPluginState.decorationSet;
@@ -23,10 +23,10 @@ var minHeightComponentStyles = (0, _react.css)({
23
23
  });
24
24
  var TypeAheadErrorFallback = exports.TypeAheadErrorFallback = function TypeAheadErrorFallback() {
25
25
  var intl = (0, _reactIntlNext.useIntl)();
26
- var header = intl.formatMessage(_typeAhead.typeAheadListMessages.offlineErrorFallbackHeading);
27
- var description = intl.formatMessage(_typeAhead.typeAheadListMessages.offlineErrorFallbackDesc);
26
+ var header = intl.formatMessage(_typeAhead.typeAheadListMessages.typeAheadErrorFallbackHeading);
27
+ var description = intl.formatMessage(_typeAhead.typeAheadListMessages.typeAheadErrorFallbackDesc);
28
28
  return (0, _react.jsx)("div", {
29
- "data-testid": "mentions-typeahead-error-boundary-ui",
29
+ "data-testid": "typeahead-error-boundary-ui",
30
30
  css: minHeightComponentStyles
31
31
  }, (0, _react.jsx)(_EmptyState.EmptyState, {
32
32
  header: header,
@@ -50,7 +50,7 @@ var WrapperTypeAhead = exports.WrapperTypeAhead = /*#__PURE__*/_react.default.me
50
50
  setQuery = _useState4[1];
51
51
  var queryRef = (0, _react.useRef)(query);
52
52
  var editorViewRef = (0, _react.useRef)(editorView);
53
- var items = (0, _useLoadItems.useLoadItems)(triggerHandler, editorView, query, showMoreOptionsButton);
53
+ var items = (0, _useLoadItems.useLoadItems)(triggerHandler, editorView, query, showMoreOptionsButton, api);
54
54
  (0, _react.useEffect)(function () {
55
55
  if (!closed && (0, _platformFeatureFlags.fg)('platform_editor_ease_of_use_metrics')) {
56
56
  var _api$metrics;
@@ -8,10 +8,11 @@ exports.useLoadItems = void 0;
8
8
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
9
9
  var _react = require("react");
10
10
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
11
+ var _clearListError = require("../../pm-plugins/commands/clear-list-error");
11
12
  var _updateListError = require("../../pm-plugins/commands/update-list-error");
12
13
  var _updateListItems = require("../../pm-plugins/commands/update-list-items");
13
14
  var EMPTY_LIST_ITEM = [];
14
- var useLoadItems = exports.useLoadItems = function useLoadItems(triggerHandler, editorView, query, showViewMore) {
15
+ var useLoadItems = exports.useLoadItems = function useLoadItems(triggerHandler, editorView, query, showViewMore, api) {
15
16
  var _useState = (0, _react.useState)(EMPTY_LIST_ITEM),
16
17
  _useState2 = (0, _slicedToArray2.default)(_useState, 2),
17
18
  items = _useState2[0],
@@ -29,6 +30,12 @@ var useLoadItems = exports.useLoadItems = function useLoadItems(triggerHandler,
29
30
  editorState: editorView.state
30
31
  };
31
32
  var view = editorViewRef.current;
33
+ if ((0, _experiments.editorExperiment)('platform_editor_offline_editing_web', true)) {
34
+ // Clear any existing error state before making a new request
35
+ queueMicrotask(function () {
36
+ api === null || api === void 0 || api.core.actions.execute((0, _clearListError.clearListError)());
37
+ });
38
+ }
32
39
  getItems(options).then(function (result) {
33
40
  var list = result.length > 0 ? result : EMPTY_LIST_ITEM;
34
41
  if (componentIsMounted.current) {
@@ -6,6 +6,7 @@ export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
6
6
  ACTIONS["INSERT_RAW_QUERY"] = "INSERT_RAW_QUERY";
7
7
  ACTIONS["UPDATE_LIST_ITEMS"] = "UPDATE_LIST_ITEMS";
8
8
  ACTIONS["UPDATE_LIST_ERROR"] = "UPDATE_LIST_ERROR";
9
+ ACTIONS["CLEAR_LIST_ERROR"] = "CLEAR_LIST_ERROR";
9
10
  ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
10
11
  return ACTIONS;
11
12
  }({});
@@ -0,0 +1,15 @@
1
+ import { ACTIONS } from '../actions';
2
+ import { pluginKey as typeAheadPluginKey } from '../key';
3
+ export const clearListError = () => {
4
+ return ({
5
+ tr
6
+ }) => {
7
+ tr.setMeta(typeAheadPluginKey, {
8
+ action: ACTIONS.CLEAR_LIST_ERROR,
9
+ params: {
10
+ errorInfo: null
11
+ }
12
+ });
13
+ return tr;
14
+ };
15
+ };
@@ -106,6 +106,7 @@ export const createReducer = ({
106
106
  const shouldUpdateListItems = action === ACTIONS.UPDATE_LIST_ITEMS;
107
107
  const shouldUpdateListError = action === ACTIONS.UPDATE_LIST_ERROR;
108
108
  const shouldUpdateSelectedIndex = action === ACTIONS.UPDATE_SELECTED_INDEX;
109
+ const shouldClearListError = action === ACTIONS.CLEAR_LIST_ERROR;
109
110
  if (shouldOpenMenu) {
110
111
  return openMenu(currentPluginState, {
111
112
  tr,
@@ -148,6 +149,11 @@ export const createReducer = ({
148
149
  ...currentPluginState,
149
150
  selectedIndex: params.selectedIndex
150
151
  };
152
+ } else if (shouldClearListError) {
153
+ return {
154
+ ...currentPluginState,
155
+ errorInfo: null
156
+ };
151
157
  }
152
158
  if (tr.docChanged) {
153
159
  const {
@@ -16,10 +16,10 @@ const minHeightComponentStyles = css({
16
16
  });
17
17
  export const TypeAheadErrorFallback = () => {
18
18
  const intl = useIntl();
19
- const header = intl.formatMessage(messages.offlineErrorFallbackHeading);
20
- const description = intl.formatMessage(messages.offlineErrorFallbackDesc);
19
+ const header = intl.formatMessage(messages.typeAheadErrorFallbackHeading);
20
+ const description = intl.formatMessage(messages.typeAheadErrorFallbackDesc);
21
21
  return jsx("div", {
22
- "data-testid": "mentions-typeahead-error-boundary-ui",
22
+ "data-testid": "typeahead-error-boundary-ui",
23
23
  css: minHeightComponentStyles
24
24
  }, jsx(EmptyState, {
25
25
  header: header,
@@ -35,7 +35,7 @@ export const WrapperTypeAhead = /*#__PURE__*/React.memo(({
35
35
  const [query, setQuery] = useState(reopenQuery || '');
36
36
  const queryRef = useRef(query);
37
37
  const editorViewRef = useRef(editorView);
38
- const items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton);
38
+ const items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton, api);
39
39
  useEffect(() => {
40
40
  if (!closed && fg('platform_editor_ease_of_use_metrics')) {
41
41
  var _api$metrics;
@@ -1,9 +1,10 @@
1
1
  import { useEffect, useRef, useState } from 'react';
2
2
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
3
+ import { clearListError } from '../../pm-plugins/commands/clear-list-error';
3
4
  import { updateListError } from '../../pm-plugins/commands/update-list-error';
4
5
  import { updateListItem } from '../../pm-plugins/commands/update-list-items';
5
6
  const EMPTY_LIST_ITEM = [];
6
- export const useLoadItems = (triggerHandler, editorView, query, showViewMore) => {
7
+ export const useLoadItems = (triggerHandler, editorView, query, showViewMore, api) => {
7
8
  const [items, setItems] = useState(EMPTY_LIST_ITEM);
8
9
  const componentIsMounted = useRef(true);
9
10
  const editorViewRef = useRef(editorView);
@@ -20,6 +21,12 @@ export const useLoadItems = (triggerHandler, editorView, query, showViewMore) =>
20
21
  const {
21
22
  current: view
22
23
  } = editorViewRef;
24
+ if (editorExperiment('platform_editor_offline_editing_web', true)) {
25
+ // Clear any existing error state before making a new request
26
+ queueMicrotask(() => {
27
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(clearListError());
28
+ });
29
+ }
23
30
  getItems(options).then(result => {
24
31
  const list = result.length > 0 ? result : EMPTY_LIST_ITEM;
25
32
  if (componentIsMounted.current) {
@@ -6,6 +6,7 @@ export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
6
6
  ACTIONS["INSERT_RAW_QUERY"] = "INSERT_RAW_QUERY";
7
7
  ACTIONS["UPDATE_LIST_ITEMS"] = "UPDATE_LIST_ITEMS";
8
8
  ACTIONS["UPDATE_LIST_ERROR"] = "UPDATE_LIST_ERROR";
9
+ ACTIONS["CLEAR_LIST_ERROR"] = "CLEAR_LIST_ERROR";
9
10
  ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
10
11
  return ACTIONS;
11
12
  }({});
@@ -0,0 +1,14 @@
1
+ import { ACTIONS } from '../actions';
2
+ import { pluginKey as typeAheadPluginKey } from '../key';
3
+ export var clearListError = function clearListError() {
4
+ return function (_ref) {
5
+ var tr = _ref.tr;
6
+ tr.setMeta(typeAheadPluginKey, {
7
+ action: ACTIONS.CLEAR_LIST_ERROR,
8
+ params: {
9
+ errorInfo: null
10
+ }
11
+ });
12
+ return tr;
13
+ };
14
+ };
@@ -107,6 +107,7 @@ export var createReducer = function createReducer(_ref) {
107
107
  var shouldUpdateListItems = action === ACTIONS.UPDATE_LIST_ITEMS;
108
108
  var shouldUpdateListError = action === ACTIONS.UPDATE_LIST_ERROR;
109
109
  var shouldUpdateSelectedIndex = action === ACTIONS.UPDATE_SELECTED_INDEX;
110
+ var shouldClearListError = action === ACTIONS.CLEAR_LIST_ERROR;
110
111
  if (shouldOpenMenu) {
111
112
  return openMenu(currentPluginState, {
112
113
  tr: tr,
@@ -139,6 +140,10 @@ export var createReducer = function createReducer(_ref) {
139
140
  return _objectSpread(_objectSpread({}, currentPluginState), {}, {
140
141
  selectedIndex: params.selectedIndex
141
142
  });
143
+ } else if (shouldClearListError) {
144
+ return _objectSpread(_objectSpread({}, currentPluginState), {}, {
145
+ errorInfo: null
146
+ });
142
147
  }
143
148
  if (tr.docChanged) {
144
149
  var decorationSet = currentPluginState.decorationSet;
@@ -16,10 +16,10 @@ var minHeightComponentStyles = css({
16
16
  });
17
17
  export var TypeAheadErrorFallback = function TypeAheadErrorFallback() {
18
18
  var intl = useIntl();
19
- var header = intl.formatMessage(messages.offlineErrorFallbackHeading);
20
- var description = intl.formatMessage(messages.offlineErrorFallbackDesc);
19
+ var header = intl.formatMessage(messages.typeAheadErrorFallbackHeading);
20
+ var description = intl.formatMessage(messages.typeAheadErrorFallbackDesc);
21
21
  return jsx("div", {
22
- "data-testid": "mentions-typeahead-error-boundary-ui",
22
+ "data-testid": "typeahead-error-boundary-ui",
23
23
  css: minHeightComponentStyles
24
24
  }, jsx(EmptyState, {
25
25
  header: header,
@@ -41,7 +41,7 @@ export var WrapperTypeAhead = /*#__PURE__*/React.memo(function (_ref) {
41
41
  setQuery = _useState4[1];
42
42
  var queryRef = useRef(query);
43
43
  var editorViewRef = useRef(editorView);
44
- var items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton);
44
+ var items = useLoadItems(triggerHandler, editorView, query, showMoreOptionsButton, api);
45
45
  useEffect(function () {
46
46
  if (!closed && fg('platform_editor_ease_of_use_metrics')) {
47
47
  var _api$metrics;
@@ -1,10 +1,11 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import { useEffect, useRef, useState } from 'react';
3
3
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
4
+ import { clearListError } from '../../pm-plugins/commands/clear-list-error';
4
5
  import { updateListError } from '../../pm-plugins/commands/update-list-error';
5
6
  import { updateListItem } from '../../pm-plugins/commands/update-list-items';
6
7
  var EMPTY_LIST_ITEM = [];
7
- export var useLoadItems = function useLoadItems(triggerHandler, editorView, query, showViewMore) {
8
+ export var useLoadItems = function useLoadItems(triggerHandler, editorView, query, showViewMore, api) {
8
9
  var _useState = useState(EMPTY_LIST_ITEM),
9
10
  _useState2 = _slicedToArray(_useState, 2),
10
11
  items = _useState2[0],
@@ -22,6 +23,12 @@ export var useLoadItems = function useLoadItems(triggerHandler, editorView, quer
22
23
  editorState: editorView.state
23
24
  };
24
25
  var view = editorViewRef.current;
26
+ if (editorExperiment('platform_editor_offline_editing_web', true)) {
27
+ // Clear any existing error state before making a new request
28
+ queueMicrotask(function () {
29
+ api === null || api === void 0 || api.core.actions.execute(clearListError());
30
+ });
31
+ }
25
32
  getItems(options).then(function (result) {
26
33
  var list = result.length > 0 ? result : EMPTY_LIST_ITEM;
27
34
  if (componentIsMounted.current) {
@@ -6,5 +6,6 @@ export declare enum ACTIONS {
6
6
  INSERT_RAW_QUERY = "INSERT_RAW_QUERY",
7
7
  UPDATE_LIST_ITEMS = "UPDATE_LIST_ITEMS",
8
8
  UPDATE_LIST_ERROR = "UPDATE_LIST_ERROR",
9
+ CLEAR_LIST_ERROR = "CLEAR_LIST_ERROR",
9
10
  UPDATE_SELECTED_INDEX = "UPDATE_SELECTED_INDEX"
10
11
  }
@@ -0,0 +1,2 @@
1
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ export declare const clearListError: () => EditorCommand;
@@ -1,3 +1,4 @@
1
- import type { TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
1
+ import type { ExtractInjectionAPI, TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
2
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
- export declare const useLoadItems: (triggerHandler: TypeAheadHandler, editorView: EditorView, query: string, showViewMore?: boolean) => Array<TypeAheadItem>;
3
+ import type { TypeAheadPlugin } from '../../typeAheadPluginType';
4
+ export declare const useLoadItems: (triggerHandler: TypeAheadHandler, editorView: EditorView, query: string, showViewMore?: boolean, api?: ExtractInjectionAPI<TypeAheadPlugin> | undefined) => Array<TypeAheadItem>;
@@ -6,5 +6,6 @@ export declare enum ACTIONS {
6
6
  INSERT_RAW_QUERY = "INSERT_RAW_QUERY",
7
7
  UPDATE_LIST_ITEMS = "UPDATE_LIST_ITEMS",
8
8
  UPDATE_LIST_ERROR = "UPDATE_LIST_ERROR",
9
+ CLEAR_LIST_ERROR = "CLEAR_LIST_ERROR",
9
10
  UPDATE_SELECTED_INDEX = "UPDATE_SELECTED_INDEX"
10
11
  }
@@ -0,0 +1,2 @@
1
+ import type { EditorCommand } from '@atlaskit/editor-common/types';
2
+ export declare const clearListError: () => EditorCommand;
@@ -1,3 +1,4 @@
1
- import type { TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
1
+ import type { ExtractInjectionAPI, TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
2
2
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
- export declare const useLoadItems: (triggerHandler: TypeAheadHandler, editorView: EditorView, query: string, showViewMore?: boolean) => Array<TypeAheadItem>;
3
+ import type { TypeAheadPlugin } from '../../typeAheadPluginType';
4
+ export declare const useLoadItems: (triggerHandler: TypeAheadHandler, editorView: EditorView, query: string, showViewMore?: boolean, api?: ExtractInjectionAPI<TypeAheadPlugin> | undefined) => Array<TypeAheadItem>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-type-ahead",
3
- "version": "3.0.0",
3
+ "version": "3.0.2",
4
4
  "description": "Type-ahead plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -41,13 +41,13 @@
41
41
  "@atlaskit/editor-prosemirror": "7.0.0",
42
42
  "@atlaskit/editor-shared-styles": "^3.4.0",
43
43
  "@atlaskit/heading": "^5.2.0",
44
- "@atlaskit/icon": "^27.2.0",
44
+ "@atlaskit/icon": "^27.3.0",
45
45
  "@atlaskit/menu": "^8.0.0",
46
46
  "@atlaskit/platform-feature-flags": "^1.1.0",
47
47
  "@atlaskit/primitives": "^14.10.0",
48
48
  "@atlaskit/prosemirror-input-rules": "^3.3.0",
49
49
  "@atlaskit/theme": "^18.0.0",
50
- "@atlaskit/tmp-editor-statsig": "^8.7.0",
50
+ "@atlaskit/tmp-editor-statsig": "^9.0.0",
51
51
  "@atlaskit/tokens": "^5.4.0",
52
52
  "@babel/runtime": "^7.0.0",
53
53
  "@emotion/react": "^11.7.1",
@@ -58,7 +58,7 @@
58
58
  "w3c-keyname": "^2.1.8"
59
59
  },
60
60
  "peerDependencies": {
61
- "@atlaskit/editor-common": "^107.6.0",
61
+ "@atlaskit/editor-common": "^107.7.0",
62
62
  "react": "^18.2.0",
63
63
  "react-dom": "^18.2.0",
64
64
  "react-intl-next": "npm:react-intl@^5.18.1"