@atlaskit/editor-plugin-type-ahead 11.0.0 → 11.1.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.
Files changed (32) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/pm-plugins/actions.js +1 -0
  3. package/dist/cjs/pm-plugins/commands/update-section-title.js +38 -0
  4. package/dist/cjs/pm-plugins/main.js +1 -0
  5. package/dist/cjs/pm-plugins/reducer.js +51 -15
  6. package/dist/cjs/typeAheadPlugin.js +12 -1
  7. package/dist/cjs/ui/TypeAheadList.js +8 -4
  8. package/dist/es2019/pm-plugins/actions.js +1 -0
  9. package/dist/es2019/pm-plugins/commands/update-section-title.js +30 -0
  10. package/dist/es2019/pm-plugins/main.js +1 -0
  11. package/dist/es2019/pm-plugins/reducer.js +50 -1
  12. package/dist/es2019/typeAheadPlugin.js +12 -1
  13. package/dist/es2019/ui/TypeAheadList.js +7 -3
  14. package/dist/esm/pm-plugins/actions.js +1 -0
  15. package/dist/esm/pm-plugins/commands/update-section-title.js +31 -0
  16. package/dist/esm/pm-plugins/main.js +1 -0
  17. package/dist/esm/pm-plugins/reducer.js +51 -15
  18. package/dist/esm/typeAheadPlugin.js +12 -1
  19. package/dist/esm/ui/TypeAheadList.js +7 -3
  20. package/dist/types/pm-plugins/actions.d.ts +2 -1
  21. package/dist/types/pm-plugins/commands/update-section-title.d.ts +2 -0
  22. package/dist/types/typeAheadPluginType.d.ts +8 -1
  23. package/dist/types/types/index.d.ts +7 -0
  24. package/dist/types/ui/TypeAheadList.d.ts +12 -0
  25. package/dist/types/ui/hooks/build-sectioned-result.d.ts +1 -1
  26. package/dist/types-ts4.5/pm-plugins/actions.d.ts +2 -1
  27. package/dist/types-ts4.5/pm-plugins/commands/update-section-title.d.ts +2 -0
  28. package/dist/types-ts4.5/typeAheadPluginType.d.ts +8 -1
  29. package/dist/types-ts4.5/types/index.d.ts +7 -0
  30. package/dist/types-ts4.5/ui/TypeAheadList.d.ts +12 -0
  31. package/dist/types-ts4.5/ui/hooks/build-sectioned-result.d.ts +1 -1
  32. package/package.json +4 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-type-ahead
2
2
 
3
+ ## 11.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`3bb54917f1df6`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3bb54917f1df6) -
8
+ Add a gated API for updating mention typeahead section metadata.
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 11.0.1
15
+
16
+ ### Patch Changes
17
+
18
+ - Updated dependencies
19
+
3
20
  ## 11.0.0
4
21
 
5
22
  ### Patch Changes
@@ -14,5 +14,6 @@ var ACTIONS = exports.ACTIONS = /*#__PURE__*/function (ACTIONS) {
14
14
  ACTIONS["UPDATE_LIST_ERROR"] = "UPDATE_LIST_ERROR";
15
15
  ACTIONS["CLEAR_LIST_ERROR"] = "CLEAR_LIST_ERROR";
16
16
  ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
17
+ ACTIONS["UPDATE_SECTION_TITLE"] = "UPDATE_SECTION_TITLE";
17
18
  return ACTIONS;
18
19
  }({});
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.updateSectionTitle = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
+ var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
10
+ var _actions = require("../actions");
11
+ var _key = require("../key");
12
+ 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; }
13
+ 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; }
14
+ var updateSectionTitle = exports.updateSectionTitle = function updateSectionTitle(_ref) {
15
+ var id = _ref.id,
16
+ title = _ref.title,
17
+ showTitleWhenOnlySection = _ref.showTitleWhenOnlySection;
18
+ return function (state, dispatch) {
19
+ if (!(0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false) || !dispatch) {
20
+ return false;
21
+ }
22
+ var tr = state.tr;
23
+ var update = _objectSpread({
24
+ title: title
25
+ }, showTitleWhenOnlySection !== undefined ? {
26
+ showTitleWhenOnlySection: showTitleWhenOnlySection
27
+ } : {});
28
+ tr.setMeta(_key.pluginKey, {
29
+ action: _actions.ACTIONS.UPDATE_SECTION_TITLE,
30
+ params: {
31
+ id: id,
32
+ update: update
33
+ }
34
+ });
35
+ dispatch(tr);
36
+ return true;
37
+ };
38
+ };
@@ -67,6 +67,7 @@ function createPlugin(_ref) {
67
67
  decorationSet: _view.DecorationSet.empty,
68
68
  decorationElement: null,
69
69
  items: [],
70
+ sectionTitleUpdates: {},
70
71
  sections: [],
71
72
  errorInfo: null,
72
73
  selectedIndex: -1,
@@ -11,6 +11,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
11
11
  var _view = require("@atlaskit/editor-prosemirror/view");
12
12
  var _insm = require("@atlaskit/insm");
13
13
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
14
+ var _expVal = require("@atlaskit/tmp-editor-statsig/expVal");
14
15
  var _actions = require("./actions");
15
16
  var _key = require("./key");
16
17
  var _utils = require("./utils");
@@ -32,6 +33,21 @@ var shouldForceClose = function shouldForceClose(step) {
32
33
  var isUndoingDeletionRawQuery = step.isUndoingStep() && step.stage === _steps.InsertTypeAheadStages.DELETING_RAW_QUERY;
33
34
  return isInsertingItem || isUndoingDeletionRawQuery;
34
35
  };
36
+ var applySectionTitleUpdates = function applySectionTitleUpdates(_ref) {
37
+ var sections = _ref.sections,
38
+ sectionTitleUpdates = _ref.sectionTitleUpdates;
39
+ if (!(0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false)) {
40
+ return sections;
41
+ }
42
+ var updatedSections = sections.map(function (section) {
43
+ var update = sectionTitleUpdates[section.id];
44
+ if (!update) {
45
+ return section;
46
+ }
47
+ return _objectSpread(_objectSpread({}, section), update);
48
+ });
49
+ return updatedSections;
50
+ };
35
51
  var createFindHandler = function createFindHandler(typeAheadHandlers) {
36
52
  return function (step) {
37
53
  if (!(step instanceof _steps.InsertTypeAheadStep)) {
@@ -43,18 +59,18 @@ var createFindHandler = function createFindHandler(typeAheadHandlers) {
43
59
  return handler || null;
44
60
  };
45
61
  };
46
- var createReducer = exports.createReducer = function createReducer(_ref) {
47
- var typeAheadHandlers = _ref.typeAheadHandlers,
48
- removeDecorations = _ref.removeDecorations,
49
- createDecorations = _ref.createDecorations;
62
+ var createReducer = exports.createReducer = function createReducer(_ref2) {
63
+ var typeAheadHandlers = _ref2.typeAheadHandlers,
64
+ removeDecorations = _ref2.removeDecorations,
65
+ createDecorations = _ref2.createDecorations;
50
66
  var findHandler = createFindHandler(typeAheadHandlers);
51
- var openMenu = function openMenu(currentPluginState, _ref2) {
52
- var tr = _ref2.tr,
53
- triggerHandler = _ref2.triggerHandler,
54
- inputMethod = _ref2.inputMethod,
55
- reopenQuery = _ref2.reopenQuery,
56
- selectedIndex = _ref2.selectedIndex,
57
- removePrefixTriggerOnCancel = _ref2.removePrefixTriggerOnCancel;
67
+ var openMenu = function openMenu(currentPluginState, _ref3) {
68
+ var tr = _ref3.tr,
69
+ triggerHandler = _ref3.triggerHandler,
70
+ inputMethod = _ref3.inputMethod,
71
+ reopenQuery = _ref3.reopenQuery,
72
+ selectedIndex = _ref3.selectedIndex,
73
+ removePrefixTriggerOnCancel = _ref3.removePrefixTriggerOnCancel;
58
74
  removeDecorations(currentPluginState.decorationSet);
59
75
  var _createDecorations = createDecorations(tr, {
60
76
  triggerHandler: triggerHandler,
@@ -76,6 +92,7 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
76
92
  inputMethod: inputMethod,
77
93
  selectedIndex: typeof selectedIndex === 'number' ? selectedIndex : -1,
78
94
  items: [],
95
+ sectionTitleUpdates: {},
79
96
  sections: [],
80
97
  query: reopenQuery || '',
81
98
  removePrefixTriggerOnCancel: removePrefixTriggerOnCancel
@@ -96,6 +113,7 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
96
113
  triggerHandler: undefined,
97
114
  items: [],
98
115
  sections: [],
116
+ sectionTitleUpdates: {},
99
117
  removePrefixTriggerOnCancel: undefined
100
118
  });
101
119
  };
@@ -116,9 +134,9 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
116
134
  } else if (shouldForceClose(typeAheadStepOverride)) {
117
135
  return closeMenu(currentPluginState);
118
136
  }
119
- var _ref3 = meta || {},
120
- action = _ref3.action,
121
- params = _ref3.params;
137
+ var _ref4 = meta || {},
138
+ action = _ref4.action,
139
+ params = _ref4.params;
122
140
  var shouldOpenMenu = action === _actions.ACTIONS.OPEN_TYPEAHEAD_AT_CURSOR && (0, _utils.isTypeAheadHandler)(params === null || params === void 0 ? void 0 : params.triggerHandler);
123
141
  var selectionChanged = tr.selectionSet && (tr.isGeneric || Boolean(tr.getMeta('pointer')));
124
142
  var shouldCloseMenu = [_actions.ACTIONS.CLOSE_TYPE_AHEAD, _actions.ACTIONS.INSERT_ITEM].includes(action) || selectionChanged;
@@ -126,6 +144,7 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
126
144
  var shouldUpdateListItems = action === _actions.ACTIONS.UPDATE_LIST_ITEMS;
127
145
  var shouldUpdateListError = action === _actions.ACTIONS.UPDATE_LIST_ERROR;
128
146
  var shouldUpdateSelectedIndex = action === _actions.ACTIONS.UPDATE_SELECTED_INDEX;
147
+ var shouldUpdateSectionTitleState = action === _actions.ACTIONS.UPDATE_SECTION_TITLE;
129
148
  var shouldClearListError = action === _actions.ACTIONS.CLEAR_LIST_ERROR;
130
149
  if (shouldOpenMenu) {
131
150
  return openMenu(currentPluginState, {
@@ -156,9 +175,26 @@ var createReducer = exports.createReducer = function createReducer(_ref) {
156
175
  var selectedIndex = currentPluginState.selectedIndex;
157
176
  return _objectSpread(_objectSpread({}, currentPluginState), {}, {
158
177
  items: items,
159
- sections: sections,
178
+ sections: applySectionTitleUpdates({
179
+ sections: sections,
180
+ sectionTitleUpdates: currentPluginState.sectionTitleUpdates
181
+ }),
160
182
  selectedIndex: Math.max(selectedIndex >= items.length ? items.length - 1 : selectedIndex, -1)
161
183
  });
184
+ } else if (shouldUpdateSectionTitleState) {
185
+ if (!(0, _expVal.expVal)('platform_editor_agent_mentions', 'isEnabled', false)) {
186
+ return currentPluginState;
187
+ }
188
+ var id = params.id,
189
+ update = params.update;
190
+ var sectionTitleUpdates = _objectSpread(_objectSpread({}, currentPluginState.sectionTitleUpdates), {}, (0, _defineProperty2.default)({}, id, _objectSpread(_objectSpread({}, currentPluginState.sectionTitleUpdates[id]), update)));
191
+ return _objectSpread(_objectSpread({}, currentPluginState), {}, {
192
+ sectionTitleUpdates: sectionTitleUpdates,
193
+ sections: applySectionTitleUpdates({
194
+ sections: currentPluginState.sections,
195
+ sectionTitleUpdates: sectionTitleUpdates
196
+ })
197
+ });
162
198
  } else if (shouldUpdateSelectedIndex) {
163
199
  return _objectSpread(_objectSpread({}, currentPluginState), {}, {
164
200
  selectedIndex: params.selectedIndex
@@ -15,6 +15,7 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
15
15
  var _closeTypeAhead = require("./pm-plugins/commands/close-type-ahead");
16
16
  var _insertTypeAheadItem = require("./pm-plugins/commands/insert-type-ahead-item");
17
17
  var _openTypeaheadAtCursor = require("./pm-plugins/commands/open-typeahead-at-cursor");
18
+ var _updateSectionTitle = require("./pm-plugins/commands/update-section-title");
18
19
  var _inputRules = require("./pm-plugins/input-rules");
19
20
  var _insertItemPlugin = require("./pm-plugins/insert-item-plugin");
20
21
  var _key = require("./pm-plugins/key");
@@ -111,6 +112,15 @@ var createFindHandlerByTrigger = function createFindHandlerByTrigger(editorViewR
111
112
  return (0, _utils.findHandler)(trigger, view.state);
112
113
  };
113
114
  };
115
+ var createUpdateSectionTitle = function createUpdateSectionTitle(editorViewRef) {
116
+ return function (props) {
117
+ if (!editorViewRef.current) {
118
+ return false;
119
+ }
120
+ var view = editorViewRef.current;
121
+ return (0, _updateSectionTitle.updateSectionTitle)(props)(view.state, view.dispatch);
122
+ };
123
+ };
114
124
  var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
115
125
  return function (options) {
116
126
  if (!editorViewRef.current) {
@@ -253,7 +263,8 @@ var typeAheadPlugin = exports.typeAheadPlugin = function typeAheadPlugin(_ref) {
253
263
  openAtTransaction: createOpenAtTransaction(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
254
264
  findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
255
265
  insert: createInsertTypeAheadItem(editorViewRef),
256
- close: createCloseTypeAhead(editorViewRef)
266
+ close: createCloseTypeAhead(editorViewRef),
267
+ updateSectionTitle: createUpdateSectionTitle(editorViewRef)
257
268
  },
258
269
  contentComponent: function contentComponent(_ref4) {
259
270
  var editorView = _ref4.editorView,
@@ -5,7 +5,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
- exports.TypeAheadList = void 0;
8
+ exports.buildTypeAheadRows = exports.TypeAheadList = void 0;
9
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
  var _react = _interopRequireWildcard(require("react"));
@@ -44,7 +44,7 @@ var list = (0, _react2.css)({
44
44
  padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)")
45
45
  }
46
46
  });
47
- var buildTypeAheadRows = function buildTypeAheadRows(_ref) {
47
+ var buildTypeAheadRows = exports.buildTypeAheadRows = function buildTypeAheadRows(_ref) {
48
48
  var itemsLength = _ref.itemsLength,
49
49
  sections = _ref.sections;
50
50
  if (sections.length === 0) {
@@ -149,12 +149,12 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref3) {
149
149
  });
150
150
  return rowIndexByItemIndex;
151
151
  }, [listRows]);
152
+ var selectedItemRowIndex = selectedIndex >= 0 ? (_itemRowIndexByItemIn = itemRowIndexByItemIndex.get(selectedIndex)) !== null && _itemRowIndexByItemIn !== void 0 ? _itemRowIndexByItemIn : -1 : -1;
152
153
  var populatedSectionCount = (0, _react.useMemo)(function () {
153
154
  return listRows.filter(function (row) {
154
155
  return row.type === 'section';
155
156
  }).length;
156
157
  }, [listRows]);
157
- var selectedItemRowIndex = selectedIndex >= 0 ? (_itemRowIndexByItemIn = itemRowIndexByItemIndex.get(selectedIndex)) !== null && _itemRowIndexByItemIn !== void 0 ? _itemRowIndexByItemIn : -1 : -1;
158
158
  var onItemsRendered = (0, _react.useCallback)(function (props) {
159
159
  lastVisibleIndexes.current = props;
160
160
  }, []);
@@ -370,6 +370,7 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref3) {
370
370
  if (!currentRow) {
371
371
  return null;
372
372
  }
373
+ var shouldHideSingleSectionTitle = currentRow.type === 'section' && populatedSectionCount === 1 && !currentRow.section.showTitleWhenOnlySection;
373
374
  return (0, _react2.jsx)(_CellMeasurer.CellMeasurer, {
374
375
  key: key,
375
376
  cache: cache,
@@ -391,7 +392,10 @@ var TypeAheadListComponent = /*#__PURE__*/_react.default.memo(function (_ref3) {
391
392
  onMouseMove: function onMouseMove(e) {
392
393
  return _onMouseMove(e, currentRow);
393
394
  }
394
- }, currentRow.type === 'section' ? populatedSectionCount === 1 ? null : (0, _react2.jsx)(_compiled.Box, {
395
+ }, currentRow.type === 'section' ?
396
+ // Preserve the existing collapsed-title behaviour for single-section results unless
397
+ // the gated section title API explicitly asks for the title to remain visible.
398
+ shouldHideSingleSectionTitle ? null : (0, _react2.jsx)(_compiled.Box, {
395
399
  paddingInline: "space.150",
396
400
  paddingBlock: "space.050"
397
401
  }, (0, _react2.jsx)(_compiled.Text, {
@@ -8,5 +8,6 @@ export let ACTIONS = /*#__PURE__*/function (ACTIONS) {
8
8
  ACTIONS["UPDATE_LIST_ERROR"] = "UPDATE_LIST_ERROR";
9
9
  ACTIONS["CLEAR_LIST_ERROR"] = "CLEAR_LIST_ERROR";
10
10
  ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
11
+ ACTIONS["UPDATE_SECTION_TITLE"] = "UPDATE_SECTION_TITLE";
11
12
  return ACTIONS;
12
13
  }({});
@@ -0,0 +1,30 @@
1
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
2
+ import { ACTIONS } from '../actions';
3
+ import { pluginKey as typeAheadPluginKey } from '../key';
4
+ export const updateSectionTitle = ({
5
+ id,
6
+ title,
7
+ showTitleWhenOnlySection
8
+ }) => {
9
+ return (state, dispatch) => {
10
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false) || !dispatch) {
11
+ return false;
12
+ }
13
+ const tr = state.tr;
14
+ const update = {
15
+ title,
16
+ ...(showTitleWhenOnlySection !== undefined ? {
17
+ showTitleWhenOnlySection
18
+ } : {})
19
+ };
20
+ tr.setMeta(typeAheadPluginKey, {
21
+ action: ACTIONS.UPDATE_SECTION_TITLE,
22
+ params: {
23
+ id,
24
+ update
25
+ }
26
+ });
27
+ dispatch(tr);
28
+ return true;
29
+ };
30
+ };
@@ -61,6 +61,7 @@ export function createPlugin({
61
61
  decorationSet: DecorationSet.empty,
62
62
  decorationElement: null,
63
63
  items: [],
64
+ sectionTitleUpdates: {},
64
65
  sections: [],
65
66
  errorInfo: null,
66
67
  selectedIndex: -1,
@@ -3,6 +3,7 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
3
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
4
4
  import { insm } from '@atlaskit/insm';
5
5
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
6
7
  import { ACTIONS } from './actions';
7
8
  import { pluginKey } from './key';
8
9
  import { isTypeAheadHandler } from './utils';
@@ -22,6 +23,25 @@ const shouldForceClose = step => {
22
23
  const isUndoingDeletionRawQuery = step.isUndoingStep() && step.stage === InsertTypeAheadStages.DELETING_RAW_QUERY;
23
24
  return isInsertingItem || isUndoingDeletionRawQuery;
24
25
  };
26
+ const applySectionTitleUpdates = ({
27
+ sections,
28
+ sectionTitleUpdates
29
+ }) => {
30
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
31
+ return sections;
32
+ }
33
+ const updatedSections = sections.map(section => {
34
+ const update = sectionTitleUpdates[section.id];
35
+ if (!update) {
36
+ return section;
37
+ }
38
+ return {
39
+ ...section,
40
+ ...update
41
+ };
42
+ });
43
+ return updatedSections;
44
+ };
25
45
  const createFindHandler = typeAheadHandlers => step => {
26
46
  if (!(step instanceof InsertTypeAheadStep)) {
27
47
  return null;
@@ -66,6 +86,7 @@ export const createReducer = ({
66
86
  inputMethod,
67
87
  selectedIndex: typeof selectedIndex === 'number' ? selectedIndex : -1,
68
88
  items: [],
89
+ sectionTitleUpdates: {},
69
90
  sections: [],
70
91
  query: reopenQuery || '',
71
92
  removePrefixTriggerOnCancel
@@ -87,6 +108,7 @@ export const createReducer = ({
87
108
  triggerHandler: undefined,
88
109
  items: [],
89
110
  sections: [],
111
+ sectionTitleUpdates: {},
90
112
  removePrefixTriggerOnCancel: undefined
91
113
  };
92
114
  };
@@ -118,6 +140,7 @@ export const createReducer = ({
118
140
  const shouldUpdateListItems = action === ACTIONS.UPDATE_LIST_ITEMS;
119
141
  const shouldUpdateListError = action === ACTIONS.UPDATE_LIST_ERROR;
120
142
  const shouldUpdateSelectedIndex = action === ACTIONS.UPDATE_SELECTED_INDEX;
143
+ const shouldUpdateSectionTitleState = action === ACTIONS.UPDATE_SECTION_TITLE;
121
144
  const shouldClearListError = action === ACTIONS.CLEAR_LIST_ERROR;
122
145
  if (shouldOpenMenu) {
123
146
  return openMenu(currentPluginState, {
@@ -156,9 +179,35 @@ export const createReducer = ({
156
179
  return {
157
180
  ...currentPluginState,
158
181
  items,
159
- sections,
182
+ sections: applySectionTitleUpdates({
183
+ sections,
184
+ sectionTitleUpdates: currentPluginState.sectionTitleUpdates
185
+ }),
160
186
  selectedIndex: Math.max(selectedIndex >= items.length ? items.length - 1 : selectedIndex, -1)
161
187
  };
188
+ } else if (shouldUpdateSectionTitleState) {
189
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
190
+ return currentPluginState;
191
+ }
192
+ const {
193
+ id,
194
+ update
195
+ } = params;
196
+ const sectionTitleUpdates = {
197
+ ...currentPluginState.sectionTitleUpdates,
198
+ [id]: {
199
+ ...currentPluginState.sectionTitleUpdates[id],
200
+ ...update
201
+ }
202
+ };
203
+ return {
204
+ ...currentPluginState,
205
+ sectionTitleUpdates,
206
+ sections: applySectionTitleUpdates({
207
+ sections: currentPluginState.sections,
208
+ sectionTitleUpdates
209
+ })
210
+ };
162
211
  } else if (shouldUpdateSelectedIndex) {
163
212
  return {
164
213
  ...currentPluginState,
@@ -16,6 +16,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
16
16
  import { closeTypeAhead } from './pm-plugins/commands/close-type-ahead';
17
17
  import { insertTypeAheadItem } from './pm-plugins/commands/insert-type-ahead-item';
18
18
  import { openTypeAheadAtCursor } from './pm-plugins/commands/open-typeahead-at-cursor';
19
+ import { updateSectionTitle } from './pm-plugins/commands/update-section-title';
19
20
  import { inputRulePlugin } from './pm-plugins/input-rules';
20
21
  import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
21
22
  import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
@@ -105,6 +106,15 @@ const createFindHandlerByTrigger = editorViewRef => trigger => {
105
106
  } = editorViewRef;
106
107
  return findHandler(trigger, view.state);
107
108
  };
109
+ const createUpdateSectionTitle = editorViewRef => props => {
110
+ if (!editorViewRef.current) {
111
+ return false;
112
+ }
113
+ const {
114
+ current: view
115
+ } = editorViewRef;
116
+ return updateSectionTitle(props)(view.state, view.dispatch);
117
+ };
108
118
  const createCloseTypeAhead = editorViewRef => options => {
109
119
  if (!editorViewRef.current) {
110
120
  return false;
@@ -247,7 +257,8 @@ export const typeAheadPlugin = ({
247
257
  openAtTransaction: createOpenAtTransaction(api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
248
258
  findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
249
259
  insert: createInsertTypeAheadItem(editorViewRef),
250
- close: createCloseTypeAhead(editorViewRef)
260
+ close: createCloseTypeAhead(editorViewRef),
261
+ updateSectionTitle: createUpdateSectionTitle(editorViewRef)
251
262
  },
252
263
  contentComponent({
253
264
  editorView,
@@ -33,7 +33,7 @@ const list = css({
33
33
  padding: `${"var(--ds-space-100, 8px)"} ${"var(--ds-space-150, 12px)"}`
34
34
  }
35
35
  });
36
- const buildTypeAheadRows = ({
36
+ export const buildTypeAheadRows = ({
37
37
  itemsLength,
38
38
  sections
39
39
  }) => {
@@ -127,8 +127,8 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
127
127
  });
128
128
  return rowIndexByItemIndex;
129
129
  }, [listRows]);
130
- const populatedSectionCount = useMemo(() => listRows.filter(row => row.type === 'section').length, [listRows]);
131
130
  const selectedItemRowIndex = selectedIndex >= 0 ? (_itemRowIndexByItemIn = itemRowIndexByItemIndex.get(selectedIndex)) !== null && _itemRowIndexByItemIn !== void 0 ? _itemRowIndexByItemIn : -1 : -1;
131
+ const populatedSectionCount = useMemo(() => listRows.filter(row => row.type === 'section').length, [listRows]);
132
132
  const onItemsRendered = useCallback(props => {
133
133
  lastVisibleIndexes.current = props;
134
134
  }, []);
@@ -341,6 +341,7 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
341
341
  if (!currentRow) {
342
342
  return null;
343
343
  }
344
+ const shouldHideSingleSectionTitle = currentRow.type === 'section' && populatedSectionCount === 1 && !currentRow.section.showTitleWhenOnlySection;
344
345
  return jsx(CellMeasurer, {
345
346
  key: key,
346
347
  cache: cache,
@@ -360,7 +361,10 @@ const TypeAheadListComponent = /*#__PURE__*/React.memo(({
360
361
  // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
361
362
  ,
362
363
  onMouseMove: e => onMouseMove(e, currentRow)
363
- }, currentRow.type === 'section' ? populatedSectionCount === 1 ? null : jsx(Box, {
364
+ }, currentRow.type === 'section' ?
365
+ // Preserve the existing collapsed-title behaviour for single-section results unless
366
+ // the gated section title API explicitly asks for the title to remain visible.
367
+ shouldHideSingleSectionTitle ? null : jsx(Box, {
364
368
  paddingInline: "space.150",
365
369
  paddingBlock: "space.050"
366
370
  }, jsx(Text, {
@@ -8,5 +8,6 @@ export var ACTIONS = /*#__PURE__*/function (ACTIONS) {
8
8
  ACTIONS["UPDATE_LIST_ERROR"] = "UPDATE_LIST_ERROR";
9
9
  ACTIONS["CLEAR_LIST_ERROR"] = "CLEAR_LIST_ERROR";
10
10
  ACTIONS["UPDATE_SELECTED_INDEX"] = "UPDATE_SELECTED_INDEX";
11
+ ACTIONS["UPDATE_SECTION_TITLE"] = "UPDATE_SECTION_TITLE";
11
12
  return ACTIONS;
12
13
  }({});
@@ -0,0 +1,31 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
4
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
5
+ import { ACTIONS } from '../actions';
6
+ import { pluginKey as typeAheadPluginKey } from '../key';
7
+ export var updateSectionTitle = function updateSectionTitle(_ref) {
8
+ var id = _ref.id,
9
+ title = _ref.title,
10
+ showTitleWhenOnlySection = _ref.showTitleWhenOnlySection;
11
+ return function (state, dispatch) {
12
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false) || !dispatch) {
13
+ return false;
14
+ }
15
+ var tr = state.tr;
16
+ var update = _objectSpread({
17
+ title: title
18
+ }, showTitleWhenOnlySection !== undefined ? {
19
+ showTitleWhenOnlySection: showTitleWhenOnlySection
20
+ } : {});
21
+ tr.setMeta(typeAheadPluginKey, {
22
+ action: ACTIONS.UPDATE_SECTION_TITLE,
23
+ params: {
24
+ id: id,
25
+ update: update
26
+ }
27
+ });
28
+ dispatch(tr);
29
+ return true;
30
+ };
31
+ };
@@ -61,6 +61,7 @@ export function createPlugin(_ref) {
61
61
  decorationSet: DecorationSet.empty,
62
62
  decorationElement: null,
63
63
  items: [],
64
+ sectionTitleUpdates: {},
64
65
  sections: [],
65
66
  errorInfo: null,
66
67
  selectedIndex: -1,
@@ -6,6 +6,7 @@ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
6
  import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
7
7
  import { insm } from '@atlaskit/insm';
8
8
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
9
+ import { expVal } from '@atlaskit/tmp-editor-statsig/expVal';
9
10
  import { ACTIONS } from './actions';
10
11
  import { pluginKey } from './key';
11
12
  import { isTypeAheadHandler } from './utils';
@@ -25,6 +26,21 @@ var shouldForceClose = function shouldForceClose(step) {
25
26
  var isUndoingDeletionRawQuery = step.isUndoingStep() && step.stage === InsertTypeAheadStages.DELETING_RAW_QUERY;
26
27
  return isInsertingItem || isUndoingDeletionRawQuery;
27
28
  };
29
+ var applySectionTitleUpdates = function applySectionTitleUpdates(_ref) {
30
+ var sections = _ref.sections,
31
+ sectionTitleUpdates = _ref.sectionTitleUpdates;
32
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
33
+ return sections;
34
+ }
35
+ var updatedSections = sections.map(function (section) {
36
+ var update = sectionTitleUpdates[section.id];
37
+ if (!update) {
38
+ return section;
39
+ }
40
+ return _objectSpread(_objectSpread({}, section), update);
41
+ });
42
+ return updatedSections;
43
+ };
28
44
  var createFindHandler = function createFindHandler(typeAheadHandlers) {
29
45
  return function (step) {
30
46
  if (!(step instanceof InsertTypeAheadStep)) {
@@ -36,18 +52,18 @@ var createFindHandler = function createFindHandler(typeAheadHandlers) {
36
52
  return handler || null;
37
53
  };
38
54
  };
39
- export var createReducer = function createReducer(_ref) {
40
- var typeAheadHandlers = _ref.typeAheadHandlers,
41
- removeDecorations = _ref.removeDecorations,
42
- createDecorations = _ref.createDecorations;
55
+ export var createReducer = function createReducer(_ref2) {
56
+ var typeAheadHandlers = _ref2.typeAheadHandlers,
57
+ removeDecorations = _ref2.removeDecorations,
58
+ createDecorations = _ref2.createDecorations;
43
59
  var findHandler = createFindHandler(typeAheadHandlers);
44
- var openMenu = function openMenu(currentPluginState, _ref2) {
45
- var tr = _ref2.tr,
46
- triggerHandler = _ref2.triggerHandler,
47
- inputMethod = _ref2.inputMethod,
48
- reopenQuery = _ref2.reopenQuery,
49
- selectedIndex = _ref2.selectedIndex,
50
- removePrefixTriggerOnCancel = _ref2.removePrefixTriggerOnCancel;
60
+ var openMenu = function openMenu(currentPluginState, _ref3) {
61
+ var tr = _ref3.tr,
62
+ triggerHandler = _ref3.triggerHandler,
63
+ inputMethod = _ref3.inputMethod,
64
+ reopenQuery = _ref3.reopenQuery,
65
+ selectedIndex = _ref3.selectedIndex,
66
+ removePrefixTriggerOnCancel = _ref3.removePrefixTriggerOnCancel;
51
67
  removeDecorations(currentPluginState.decorationSet);
52
68
  var _createDecorations = createDecorations(tr, {
53
69
  triggerHandler: triggerHandler,
@@ -69,6 +85,7 @@ export var createReducer = function createReducer(_ref) {
69
85
  inputMethod: inputMethod,
70
86
  selectedIndex: typeof selectedIndex === 'number' ? selectedIndex : -1,
71
87
  items: [],
88
+ sectionTitleUpdates: {},
72
89
  sections: [],
73
90
  query: reopenQuery || '',
74
91
  removePrefixTriggerOnCancel: removePrefixTriggerOnCancel
@@ -89,6 +106,7 @@ export var createReducer = function createReducer(_ref) {
89
106
  triggerHandler: undefined,
90
107
  items: [],
91
108
  sections: [],
109
+ sectionTitleUpdates: {},
92
110
  removePrefixTriggerOnCancel: undefined
93
111
  });
94
112
  };
@@ -109,9 +127,9 @@ export var createReducer = function createReducer(_ref) {
109
127
  } else if (shouldForceClose(typeAheadStepOverride)) {
110
128
  return closeMenu(currentPluginState);
111
129
  }
112
- var _ref3 = meta || {},
113
- action = _ref3.action,
114
- params = _ref3.params;
130
+ var _ref4 = meta || {},
131
+ action = _ref4.action,
132
+ params = _ref4.params;
115
133
  var shouldOpenMenu = action === ACTIONS.OPEN_TYPEAHEAD_AT_CURSOR && isTypeAheadHandler(params === null || params === void 0 ? void 0 : params.triggerHandler);
116
134
  var selectionChanged = tr.selectionSet && (tr.isGeneric || Boolean(tr.getMeta('pointer')));
117
135
  var shouldCloseMenu = [ACTIONS.CLOSE_TYPE_AHEAD, ACTIONS.INSERT_ITEM].includes(action) || selectionChanged;
@@ -119,6 +137,7 @@ export var createReducer = function createReducer(_ref) {
119
137
  var shouldUpdateListItems = action === ACTIONS.UPDATE_LIST_ITEMS;
120
138
  var shouldUpdateListError = action === ACTIONS.UPDATE_LIST_ERROR;
121
139
  var shouldUpdateSelectedIndex = action === ACTIONS.UPDATE_SELECTED_INDEX;
140
+ var shouldUpdateSectionTitleState = action === ACTIONS.UPDATE_SECTION_TITLE;
122
141
  var shouldClearListError = action === ACTIONS.CLEAR_LIST_ERROR;
123
142
  if (shouldOpenMenu) {
124
143
  return openMenu(currentPluginState, {
@@ -149,9 +168,26 @@ export var createReducer = function createReducer(_ref) {
149
168
  var selectedIndex = currentPluginState.selectedIndex;
150
169
  return _objectSpread(_objectSpread({}, currentPluginState), {}, {
151
170
  items: items,
152
- sections: sections,
171
+ sections: applySectionTitleUpdates({
172
+ sections: sections,
173
+ sectionTitleUpdates: currentPluginState.sectionTitleUpdates
174
+ }),
153
175
  selectedIndex: Math.max(selectedIndex >= items.length ? items.length - 1 : selectedIndex, -1)
154
176
  });
177
+ } else if (shouldUpdateSectionTitleState) {
178
+ if (!expVal('platform_editor_agent_mentions', 'isEnabled', false)) {
179
+ return currentPluginState;
180
+ }
181
+ var id = params.id,
182
+ update = params.update;
183
+ var sectionTitleUpdates = _objectSpread(_objectSpread({}, currentPluginState.sectionTitleUpdates), {}, _defineProperty({}, id, _objectSpread(_objectSpread({}, currentPluginState.sectionTitleUpdates[id]), update)));
184
+ return _objectSpread(_objectSpread({}, currentPluginState), {}, {
185
+ sectionTitleUpdates: sectionTitleUpdates,
186
+ sections: applySectionTitleUpdates({
187
+ sections: currentPluginState.sections,
188
+ sectionTitleUpdates: sectionTitleUpdates
189
+ })
190
+ });
155
191
  } else if (shouldUpdateSelectedIndex) {
156
192
  return _objectSpread(_objectSpread({}, currentPluginState), {}, {
157
193
  selectedIndex: params.selectedIndex
@@ -16,6 +16,7 @@ import { fg } from '@atlaskit/platform-feature-flags';
16
16
  import { closeTypeAhead } from './pm-plugins/commands/close-type-ahead';
17
17
  import { insertTypeAheadItem } from './pm-plugins/commands/insert-type-ahead-item';
18
18
  import { openTypeAheadAtCursor } from './pm-plugins/commands/open-typeahead-at-cursor';
19
+ import { updateSectionTitle } from './pm-plugins/commands/update-section-title';
19
20
  import { inputRulePlugin } from './pm-plugins/input-rules';
20
21
  import { createPlugin as createInsertItemPlugin } from './pm-plugins/insert-item-plugin';
21
22
  import { pluginKey as typeAheadPluginKey } from './pm-plugins/key';
@@ -103,6 +104,15 @@ var createFindHandlerByTrigger = function createFindHandlerByTrigger(editorViewR
103
104
  return findHandler(trigger, view.state);
104
105
  };
105
106
  };
107
+ var createUpdateSectionTitle = function createUpdateSectionTitle(editorViewRef) {
108
+ return function (props) {
109
+ if (!editorViewRef.current) {
110
+ return false;
111
+ }
112
+ var view = editorViewRef.current;
113
+ return updateSectionTitle(props)(view.state, view.dispatch);
114
+ };
115
+ };
106
116
  var createCloseTypeAhead = function createCloseTypeAhead(editorViewRef) {
107
117
  return function (options) {
108
118
  if (!editorViewRef.current) {
@@ -245,7 +255,8 @@ export var typeAheadPlugin = function typeAheadPlugin(_ref) {
245
255
  openAtTransaction: createOpenAtTransaction(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions),
246
256
  findHandlerByTrigger: createFindHandlerByTrigger(editorViewRef),
247
257
  insert: createInsertTypeAheadItem(editorViewRef),
248
- close: createCloseTypeAhead(editorViewRef)
258
+ close: createCloseTypeAhead(editorViewRef),
259
+ updateSectionTitle: createUpdateSectionTitle(editorViewRef)
249
260
  },
250
261
  contentComponent: function contentComponent(_ref4) {
251
262
  var editorView = _ref4.editorView,
@@ -35,7 +35,7 @@ var list = css({
35
35
  padding: "var(--ds-space-100, 8px)".concat(" ", "var(--ds-space-150, 12px)")
36
36
  }
37
37
  });
38
- var buildTypeAheadRows = function buildTypeAheadRows(_ref) {
38
+ export var buildTypeAheadRows = function buildTypeAheadRows(_ref) {
39
39
  var itemsLength = _ref.itemsLength,
40
40
  sections = _ref.sections;
41
41
  if (sections.length === 0) {
@@ -140,12 +140,12 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref3) {
140
140
  });
141
141
  return rowIndexByItemIndex;
142
142
  }, [listRows]);
143
+ var selectedItemRowIndex = selectedIndex >= 0 ? (_itemRowIndexByItemIn = itemRowIndexByItemIndex.get(selectedIndex)) !== null && _itemRowIndexByItemIn !== void 0 ? _itemRowIndexByItemIn : -1 : -1;
143
144
  var populatedSectionCount = useMemo(function () {
144
145
  return listRows.filter(function (row) {
145
146
  return row.type === 'section';
146
147
  }).length;
147
148
  }, [listRows]);
148
- var selectedItemRowIndex = selectedIndex >= 0 ? (_itemRowIndexByItemIn = itemRowIndexByItemIndex.get(selectedIndex)) !== null && _itemRowIndexByItemIn !== void 0 ? _itemRowIndexByItemIn : -1 : -1;
149
149
  var onItemsRendered = useCallback(function (props) {
150
150
  lastVisibleIndexes.current = props;
151
151
  }, []);
@@ -361,6 +361,7 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref3) {
361
361
  if (!currentRow) {
362
362
  return null;
363
363
  }
364
+ var shouldHideSingleSectionTitle = currentRow.type === 'section' && populatedSectionCount === 1 && !currentRow.section.showTitleWhenOnlySection;
364
365
  return jsx(CellMeasurer, {
365
366
  key: key,
366
367
  cache: cache,
@@ -382,7 +383,10 @@ var TypeAheadListComponent = /*#__PURE__*/React.memo(function (_ref3) {
382
383
  onMouseMove: function onMouseMove(e) {
383
384
  return _onMouseMove(e, currentRow);
384
385
  }
385
- }, currentRow.type === 'section' ? populatedSectionCount === 1 ? null : jsx(Box, {
386
+ }, currentRow.type === 'section' ?
387
+ // Preserve the existing collapsed-title behaviour for single-section results unless
388
+ // the gated section title API explicitly asks for the title to remain visible.
389
+ shouldHideSingleSectionTitle ? null : jsx(Box, {
386
390
  paddingInline: "space.150",
387
391
  paddingBlock: "space.050"
388
392
  }, jsx(Text, {
@@ -7,5 +7,6 @@ export declare enum ACTIONS {
7
7
  UPDATE_LIST_ITEMS = "UPDATE_LIST_ITEMS",
8
8
  UPDATE_LIST_ERROR = "UPDATE_LIST_ERROR",
9
9
  CLEAR_LIST_ERROR = "CLEAR_LIST_ERROR",
10
- UPDATE_SELECTED_INDEX = "UPDATE_SELECTED_INDEX"
10
+ UPDATE_SELECTED_INDEX = "UPDATE_SELECTED_INDEX",
11
+ UPDATE_SECTION_TITLE = "UPDATE_SECTION_TITLE"
11
12
  }
@@ -0,0 +1,2 @@
1
+ import type { Command, TypeAheadSectionTitleUpdate } from '@atlaskit/editor-common/types';
2
+ export declare const updateSectionTitle: ({ id, title, showTitleWhenOnlySection }: TypeAheadSectionTitleUpdate) => Command;
@@ -1,5 +1,5 @@
1
1
  import type { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
2
- import type { Command, NextEditorPlugin, OptionalPlugin, TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
2
+ import type { Command, NextEditorPlugin, OptionalPlugin, TypeAheadHandler, TypeAheadItem, TypeAheadSectionTitleUpdate } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
5
5
  import type { ContextPanelPlugin } from '@atlaskit/editor-plugin-context-panel';
@@ -31,6 +31,13 @@ export type TypeAheadPlugin = NextEditorPlugin<'typeAhead', {
31
31
  isOpen: (editorState: EditorState) => boolean;
32
32
  open: (props: OpenTypeAheadProps) => boolean;
33
33
  openAtTransaction: (props: OpenTypeAheadProps) => (tr: Transaction) => boolean;
34
+ /**
35
+ * Updates the display title for an existing typeahead section in the current typeahead session.
36
+ *
37
+ * The optional `showTitleWhenOnlySection` flag keeps the title visible when this section is
38
+ * the only populated section. It does not render titles for empty sections.
39
+ */
40
+ updateSectionTitle?: (props: TypeAheadSectionTitleUpdate) => boolean;
34
41
  };
35
42
  dependencies: [
36
43
  OptionalPlugin<AnalyticsPlugin>,
@@ -24,6 +24,7 @@ export interface TypeAheadStatsMobileModifier extends TypeAheadStatsSerializable
24
24
  closeTime: () => void;
25
25
  resetTime: () => void;
26
26
  }
27
+ export type TypeAheadSectionTitleUpdateState = Pick<TypeAheadResolvedSection, 'showTitleWhenOnlySection' | 'title'>;
27
28
  export type TypeAheadPluginState = {
28
29
  decorationElement: HTMLElement | null;
29
30
  decorationSet: DecorationSet;
@@ -36,6 +37,7 @@ export type TypeAheadPluginState = {
36
37
  */
37
38
  removePrefixTriggerOnCancel?: boolean;
38
39
  sections: Array<TypeAheadResolvedSection>;
40
+ sectionTitleUpdates: Record<string, TypeAheadSectionTitleUpdateState>;
39
41
  selectedIndex: number;
40
42
  stats: TypeAheadStatsSerializable | null;
41
43
  triggerHandler?: TypeAheadHandler;
@@ -44,6 +46,11 @@ export type TypeAheadPluginState = {
44
46
  export type TypeAheadResolvedSection = {
45
47
  endIndex: number;
46
48
  id: string;
49
+ /**
50
+ * Keeps this section's title visible when it is the only section with matching items.
51
+ * Does not render the title for an empty section.
52
+ */
53
+ showTitleWhenOnlySection?: boolean;
47
54
  startIndex: number;
48
55
  title: string;
49
56
  };
@@ -10,6 +10,17 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
10
  import type { InputMethodType } from '../pm-plugins/analytics';
11
11
  import type { TypeAheadPlugin } from '../typeAheadPluginType';
12
12
  import type { TypeAheadHandler, TypeAheadResolvedSection } from '../types';
13
+ type TypeAheadRowEntry = {
14
+ section: TypeAheadResolvedSection;
15
+ type: 'section';
16
+ } | {
17
+ itemIndex: number;
18
+ type: 'item';
19
+ };
20
+ export declare const buildTypeAheadRows: ({ itemsLength, sections, }: {
21
+ itemsLength: number;
22
+ sections: Array<TypeAheadResolvedSection>;
23
+ }) => Array<TypeAheadRowEntry>;
13
24
  export declare const TypeAheadList: React.FC<WithIntlProps<{
14
25
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
15
26
  decorationElement: HTMLElement;
@@ -41,3 +52,4 @@ export declare const TypeAheadList: React.FC<WithIntlProps<{
41
52
  triggerHandler?: TypeAheadHandler;
42
53
  } & WrappedComponentProps>;
43
54
  };
55
+ export {};
@@ -2,9 +2,9 @@ import type { IntlShape } from 'react-intl';
2
2
  import type { TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
3
3
  import type { TypeAheadResolvedSection } from '../../types';
4
4
  export declare const buildSectionedResult: ({ items, triggerHandler, intl, }: {
5
+ intl: IntlShape | null;
5
6
  items: Array<TypeAheadItem>;
6
7
  triggerHandler: TypeAheadHandler;
7
- intl: IntlShape | null;
8
8
  }) => {
9
9
  items: Array<TypeAheadItem>;
10
10
  sections: Array<TypeAheadResolvedSection>;
@@ -7,5 +7,6 @@ export declare enum ACTIONS {
7
7
  UPDATE_LIST_ITEMS = "UPDATE_LIST_ITEMS",
8
8
  UPDATE_LIST_ERROR = "UPDATE_LIST_ERROR",
9
9
  CLEAR_LIST_ERROR = "CLEAR_LIST_ERROR",
10
- UPDATE_SELECTED_INDEX = "UPDATE_SELECTED_INDEX"
10
+ UPDATE_SELECTED_INDEX = "UPDATE_SELECTED_INDEX",
11
+ UPDATE_SECTION_TITLE = "UPDATE_SECTION_TITLE"
11
12
  }
@@ -0,0 +1,2 @@
1
+ import type { Command, TypeAheadSectionTitleUpdate } from '@atlaskit/editor-common/types';
2
+ export declare const updateSectionTitle: ({ id, title, showTitleWhenOnlySection }: TypeAheadSectionTitleUpdate) => Command;
@@ -1,5 +1,5 @@
1
1
  import type { SelectItemMode } from '@atlaskit/editor-common/type-ahead';
2
- import type { Command, NextEditorPlugin, OptionalPlugin, TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
2
+ import type { Command, NextEditorPlugin, OptionalPlugin, TypeAheadHandler, TypeAheadItem, TypeAheadSectionTitleUpdate } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
4
  import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
5
5
  import type { ContextPanelPlugin } from '@atlaskit/editor-plugin-context-panel';
@@ -31,6 +31,13 @@ export type TypeAheadPlugin = NextEditorPlugin<'typeAhead', {
31
31
  isOpen: (editorState: EditorState) => boolean;
32
32
  open: (props: OpenTypeAheadProps) => boolean;
33
33
  openAtTransaction: (props: OpenTypeAheadProps) => (tr: Transaction) => boolean;
34
+ /**
35
+ * Updates the display title for an existing typeahead section in the current typeahead session.
36
+ *
37
+ * The optional `showTitleWhenOnlySection` flag keeps the title visible when this section is
38
+ * the only populated section. It does not render titles for empty sections.
39
+ */
40
+ updateSectionTitle?: (props: TypeAheadSectionTitleUpdate) => boolean;
34
41
  };
35
42
  dependencies: [
36
43
  OptionalPlugin<AnalyticsPlugin>,
@@ -24,6 +24,7 @@ export interface TypeAheadStatsMobileModifier extends TypeAheadStatsSerializable
24
24
  closeTime: () => void;
25
25
  resetTime: () => void;
26
26
  }
27
+ export type TypeAheadSectionTitleUpdateState = Pick<TypeAheadResolvedSection, 'showTitleWhenOnlySection' | 'title'>;
27
28
  export type TypeAheadPluginState = {
28
29
  decorationElement: HTMLElement | null;
29
30
  decorationSet: DecorationSet;
@@ -36,6 +37,7 @@ export type TypeAheadPluginState = {
36
37
  */
37
38
  removePrefixTriggerOnCancel?: boolean;
38
39
  sections: Array<TypeAheadResolvedSection>;
40
+ sectionTitleUpdates: Record<string, TypeAheadSectionTitleUpdateState>;
39
41
  selectedIndex: number;
40
42
  stats: TypeAheadStatsSerializable | null;
41
43
  triggerHandler?: TypeAheadHandler;
@@ -44,6 +46,11 @@ export type TypeAheadPluginState = {
44
46
  export type TypeAheadResolvedSection = {
45
47
  endIndex: number;
46
48
  id: string;
49
+ /**
50
+ * Keeps this section's title visible when it is the only section with matching items.
51
+ * Does not render the title for an empty section.
52
+ */
53
+ showTitleWhenOnlySection?: boolean;
47
54
  startIndex: number;
48
55
  title: string;
49
56
  };
@@ -10,6 +10,17 @@ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
10
10
  import type { InputMethodType } from '../pm-plugins/analytics';
11
11
  import type { TypeAheadPlugin } from '../typeAheadPluginType';
12
12
  import type { TypeAheadHandler, TypeAheadResolvedSection } from '../types';
13
+ type TypeAheadRowEntry = {
14
+ section: TypeAheadResolvedSection;
15
+ type: 'section';
16
+ } | {
17
+ itemIndex: number;
18
+ type: 'item';
19
+ };
20
+ export declare const buildTypeAheadRows: ({ itemsLength, sections, }: {
21
+ itemsLength: number;
22
+ sections: Array<TypeAheadResolvedSection>;
23
+ }) => Array<TypeAheadRowEntry>;
13
24
  export declare const TypeAheadList: React.FC<WithIntlProps<{
14
25
  api: ExtractInjectionAPI<TypeAheadPlugin> | undefined;
15
26
  decorationElement: HTMLElement;
@@ -41,3 +52,4 @@ export declare const TypeAheadList: React.FC<WithIntlProps<{
41
52
  triggerHandler?: TypeAheadHandler;
42
53
  } & WrappedComponentProps>;
43
54
  };
55
+ export {};
@@ -2,9 +2,9 @@ import type { IntlShape } from 'react-intl';
2
2
  import type { TypeAheadHandler, TypeAheadItem } from '@atlaskit/editor-common/types';
3
3
  import type { TypeAheadResolvedSection } from '../../types';
4
4
  export declare const buildSectionedResult: ({ items, triggerHandler, intl, }: {
5
+ intl: IntlShape | null;
5
6
  items: Array<TypeAheadItem>;
6
7
  triggerHandler: TypeAheadHandler;
7
- intl: IntlShape | null;
8
8
  }) => {
9
9
  items: Array<TypeAheadItem>;
10
10
  sections: Array<TypeAheadResolvedSection>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-type-ahead",
3
- "version": "11.0.0",
3
+ "version": "11.1.0",
4
4
  "description": "Type-ahead plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "atlaskit:src": "src/index.ts",
31
31
  "dependencies": {
32
- "@atlaskit/adf-schema": "^52.15.0",
32
+ "@atlaskit/adf-schema": "^52.16.0",
33
33
  "@atlaskit/editor-plugin-analytics": "^11.0.0",
34
34
  "@atlaskit/editor-plugin-connectivity": "^11.0.0",
35
35
  "@atlaskit/editor-plugin-context-panel": "^13.0.0",
@@ -44,7 +44,7 @@
44
44
  "@atlaskit/primitives": "^19.0.0",
45
45
  "@atlaskit/prosemirror-history": "^0.2.0",
46
46
  "@atlaskit/prosemirror-input-rules": "^3.7.0",
47
- "@atlaskit/tmp-editor-statsig": "^88.0.0",
47
+ "@atlaskit/tmp-editor-statsig": "^89.0.0",
48
48
  "@atlaskit/tokens": "^13.1.0",
49
49
  "@atlaskit/visually-hidden": "^3.1.0",
50
50
  "@babel/runtime": "^7.0.0",
@@ -56,7 +56,7 @@
56
56
  "w3c-keyname": "^2.1.8"
57
57
  },
58
58
  "peerDependencies": {
59
- "@atlaskit/editor-common": "^115.0.0",
59
+ "@atlaskit/editor-common": "^115.3.0",
60
60
  "react": "^18.2.0",
61
61
  "react-dom": "^18.2.0",
62
62
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"