@atlaskit/editor-common 128.2.0 → 128.3.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,28 @@
1
1
  # @atlaskit/editor-common
2
2
 
3
+ ## 128.3.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`faf42b91fb5b1`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/faf42b91fb5b1) -
8
+ Extend the `AnnotationManager` API ahead of media (block node) annotation support and the
9
+ Confluence comments migration. Types and manager plumbing only — the hooks behind these methods
10
+ land with the editor and renderer changes.
11
+ - `startDraft` takes an optional `localId`, so a draft can target a block node instead of the
12
+ current text selection. `StartDraftResult` gains an `invalid-localId` failure reason.
13
+ - New `clearSelectedAnnotation()` and `clearHoveredAnnotation()`: clear the selection or hover
14
+ without the caller having to track which annotation id is active. Both return the id they
15
+ cleared (`undefined` when nothing was active); `clearSelectedAnnotation` fails with
16
+ `draft-in-progress` while a draft is open.
17
+ - `AnnotationDraftStartedData` gains `targetNodeType`, and `AnnotationSelectedChangeData` gains
18
+ `targetNodeType` and `viewMethod`.
19
+ - `draftAnnotationCleared` is now subscribable via `onDraftAnnotationCleared` /
20
+ `offDraftAnnotationCleared`.
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies
25
+
3
26
  ## 128.2.0
4
27
 
5
28
  ### Minor Changes
@@ -74,6 +74,18 @@ var SharedAnnotationManager = exports.SharedAnnotationManager = /*#__PURE__*/fun
74
74
  this.emitter.off('annotationSelectionChanged', handler);
75
75
  return this;
76
76
  }
77
+ }, {
78
+ key: "onDraftAnnotationCleared",
79
+ value: function onDraftAnnotationCleared(handler) {
80
+ this.emitter.on('draftAnnotationCleared', handler);
81
+ return this;
82
+ }
83
+ }, {
84
+ key: "offDraftAnnotationCleared",
85
+ value: function offDraftAnnotationCleared(handler) {
86
+ this.emitter.off('draftAnnotationCleared', handler);
87
+ return this;
88
+ }
77
89
  }, {
78
90
  key: "emit",
79
91
  value: function emit(event) {
@@ -110,7 +122,7 @@ var SharedAnnotationManager = exports.SharedAnnotationManager = /*#__PURE__*/fun
110
122
  }
111
123
  }, {
112
124
  key: "startDraft",
113
- value: function startDraft() {
125
+ value: function startDraft(localId) {
114
126
  var fn = this.hooks.get('startDraft');
115
127
  if (!fn) {
116
128
  return {
@@ -119,7 +131,7 @@ var SharedAnnotationManager = exports.SharedAnnotationManager = /*#__PURE__*/fun
119
131
  };
120
132
  }
121
133
  try {
122
- return fn();
134
+ return fn(localId);
123
135
  } catch (_unused2) {
124
136
  return {
125
137
  success: false,
@@ -244,5 +256,43 @@ var SharedAnnotationManager = exports.SharedAnnotationManager = /*#__PURE__*/fun
244
256
  };
245
257
  }
246
258
  }
259
+ }, {
260
+ key: "clearSelectedAnnotation",
261
+ value: function clearSelectedAnnotation() {
262
+ var fn = this.hooks.get('clearSelectedAnnotation');
263
+ if (!fn) {
264
+ return {
265
+ success: false,
266
+ reason: 'manager-not-initialized'
267
+ };
268
+ }
269
+ try {
270
+ return fn();
271
+ } catch (_unused9) {
272
+ return {
273
+ success: false,
274
+ reason: 'hook-execution-error'
275
+ };
276
+ }
277
+ }
278
+ }, {
279
+ key: "clearHoveredAnnotation",
280
+ value: function clearHoveredAnnotation() {
281
+ var fn = this.hooks.get('clearHoveredAnnotation');
282
+ if (!fn) {
283
+ return {
284
+ success: false,
285
+ reason: 'manager-not-initialized'
286
+ };
287
+ }
288
+ try {
289
+ return fn();
290
+ } catch (_unused0) {
291
+ return {
292
+ success: false,
293
+ reason: 'hook-execution-error'
294
+ };
295
+ }
296
+ }
247
297
  }]);
248
298
  }();
@@ -27,7 +27,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
27
27
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
28
28
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
29
29
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
30
- var packageVersion = "128.1.0";
30
+ var packageVersion = "128.2.0";
31
31
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
32
32
  // Remove URL as it has UGC
33
33
  // Ignored via go/ees007
@@ -24,7 +24,7 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
24
24
  * @jsx jsx
25
25
  */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
26
26
  var packageName = "@atlaskit/editor-common";
27
- var packageVersion = "128.1.0";
27
+ var packageVersion = "128.2.0";
28
28
  var halfFocusRing = 1;
29
29
  var dropOffset = '0, 8';
30
30
  var fadeIn = (0, _react2.keyframes)({
@@ -49,6 +49,14 @@ export class SharedAnnotationManager {
49
49
  this.emitter.off('annotationSelectionChanged', handler);
50
50
  return this;
51
51
  }
52
+ onDraftAnnotationCleared(handler) {
53
+ this.emitter.on('draftAnnotationCleared', handler);
54
+ return this;
55
+ }
56
+ offDraftAnnotationCleared(handler) {
57
+ this.emitter.off('draftAnnotationCleared', handler);
58
+ return this;
59
+ }
52
60
  emit(event) {
53
61
  this.emitter.emit(event.name, 'data' in event ? event.data : undefined);
54
62
  return this;
@@ -75,7 +83,7 @@ export class SharedAnnotationManager {
75
83
  return false;
76
84
  }
77
85
  }
78
- startDraft() {
86
+ startDraft(localId) {
79
87
  const fn = this.hooks.get('startDraft');
80
88
  if (!fn) {
81
89
  return {
@@ -84,7 +92,7 @@ export class SharedAnnotationManager {
84
92
  };
85
93
  }
86
94
  try {
87
- return fn();
95
+ return fn(localId);
88
96
  } catch {
89
97
  return {
90
98
  success: false,
@@ -197,4 +205,38 @@ export class SharedAnnotationManager {
197
205
  };
198
206
  }
199
207
  }
208
+ clearSelectedAnnotation() {
209
+ const fn = this.hooks.get('clearSelectedAnnotation');
210
+ if (!fn) {
211
+ return {
212
+ success: false,
213
+ reason: 'manager-not-initialized'
214
+ };
215
+ }
216
+ try {
217
+ return fn();
218
+ } catch {
219
+ return {
220
+ success: false,
221
+ reason: 'hook-execution-error'
222
+ };
223
+ }
224
+ }
225
+ clearHoveredAnnotation() {
226
+ const fn = this.hooks.get('clearHoveredAnnotation');
227
+ if (!fn) {
228
+ return {
229
+ success: false,
230
+ reason: 'manager-not-initialized'
231
+ };
232
+ }
233
+ try {
234
+ return fn();
235
+ } catch {
236
+ return {
237
+ success: false,
238
+ reason: 'hook-execution-error'
239
+ };
240
+ }
241
+ }
200
242
  }
@@ -13,7 +13,7 @@ const NETWORK_FAILURE_REGEX = /^network failure/i;
13
13
  const RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
14
14
  const SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
15
15
  const packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
16
- const packageVersion = "128.1.0";
16
+ const packageVersion = "128.2.0";
17
17
  const sanitiseSentryEvents = (data, _hint) => {
18
18
  // Remove URL as it has UGC
19
19
  // Ignored via go/ees007
@@ -14,7 +14,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
14
14
  import { fg } from '@atlaskit/platform-feature-flags/fg';
15
15
  import Layer from '../Layer';
16
16
  const packageName = "@atlaskit/editor-common";
17
- const packageVersion = "128.1.0";
17
+ const packageVersion = "128.2.0";
18
18
  const halfFocusRing = 1;
19
19
  const dropOffset = '0, 8';
20
20
  const fadeIn = keyframes({
@@ -67,6 +67,18 @@ export var SharedAnnotationManager = /*#__PURE__*/function () {
67
67
  this.emitter.off('annotationSelectionChanged', handler);
68
68
  return this;
69
69
  }
70
+ }, {
71
+ key: "onDraftAnnotationCleared",
72
+ value: function onDraftAnnotationCleared(handler) {
73
+ this.emitter.on('draftAnnotationCleared', handler);
74
+ return this;
75
+ }
76
+ }, {
77
+ key: "offDraftAnnotationCleared",
78
+ value: function offDraftAnnotationCleared(handler) {
79
+ this.emitter.off('draftAnnotationCleared', handler);
80
+ return this;
81
+ }
70
82
  }, {
71
83
  key: "emit",
72
84
  value: function emit(event) {
@@ -103,7 +115,7 @@ export var SharedAnnotationManager = /*#__PURE__*/function () {
103
115
  }
104
116
  }, {
105
117
  key: "startDraft",
106
- value: function startDraft() {
118
+ value: function startDraft(localId) {
107
119
  var fn = this.hooks.get('startDraft');
108
120
  if (!fn) {
109
121
  return {
@@ -112,7 +124,7 @@ export var SharedAnnotationManager = /*#__PURE__*/function () {
112
124
  };
113
125
  }
114
126
  try {
115
- return fn();
127
+ return fn(localId);
116
128
  } catch (_unused2) {
117
129
  return {
118
130
  success: false,
@@ -237,5 +249,43 @@ export var SharedAnnotationManager = /*#__PURE__*/function () {
237
249
  };
238
250
  }
239
251
  }
252
+ }, {
253
+ key: "clearSelectedAnnotation",
254
+ value: function clearSelectedAnnotation() {
255
+ var fn = this.hooks.get('clearSelectedAnnotation');
256
+ if (!fn) {
257
+ return {
258
+ success: false,
259
+ reason: 'manager-not-initialized'
260
+ };
261
+ }
262
+ try {
263
+ return fn();
264
+ } catch (_unused9) {
265
+ return {
266
+ success: false,
267
+ reason: 'hook-execution-error'
268
+ };
269
+ }
270
+ }
271
+ }, {
272
+ key: "clearHoveredAnnotation",
273
+ value: function clearHoveredAnnotation() {
274
+ var fn = this.hooks.get('clearHoveredAnnotation');
275
+ if (!fn) {
276
+ return {
277
+ success: false,
278
+ reason: 'manager-not-initialized'
279
+ };
280
+ }
281
+ try {
282
+ return fn();
283
+ } catch (_unused0) {
284
+ return {
285
+ success: false,
286
+ reason: 'hook-execution-error'
287
+ };
288
+ }
289
+ }
240
290
  }]);
241
291
  }();
@@ -19,7 +19,7 @@ var NETWORK_FAILURE_REGEX = /^network failure/i;
19
19
  var RESIZE_OBSERVER_LOOP_REGEX = /ResizeObserver loop completed with undelivered notifications/;
20
20
  var SENTRY_DSN = 'https://0b10c8e02fb44d8796c047b102c9bee8@o55978.ingest.sentry.io/4505129224110080';
21
21
  var packageName = 'editor-common'; // Sentry doesn't accept '/' in its releases https://docs.sentry.io/platforms/javascript/configuration/releases/
22
- var packageVersion = "128.1.0";
22
+ var packageVersion = "128.2.0";
23
23
  var sanitiseSentryEvents = function sanitiseSentryEvents(data, _hint) {
24
24
  // Remove URL as it has UGC
25
25
  // Ignored via go/ees007
@@ -21,7 +21,7 @@ import withAnalyticsEvents from '@atlaskit/analytics-next/withAnalyticsEvents';
21
21
  import { fg } from '@atlaskit/platform-feature-flags/fg';
22
22
  import Layer from '../Layer';
23
23
  var packageName = "@atlaskit/editor-common";
24
- var packageVersion = "128.1.0";
24
+ var packageVersion = "128.2.0";
25
25
  var halfFocusRing = 1;
26
26
  var dropOffset = '0, 8';
27
27
  var fadeIn = keyframes({
@@ -41,11 +41,17 @@ export type AnnotationDraftStartedData = {
41
41
  */
42
42
  inlineNodeTypes: string[];
43
43
  targetElement: HTMLElement | undefined;
44
+ /** The type of the node the draft targets, e.g. `'media'`. Undefined for an inline text draft. */
45
+ targetNodeType?: string;
44
46
  };
45
47
  export type AnnotationSelectedChangeData = {
46
48
  annotationId: AnnotationId;
47
49
  inlineNodeTypes: string[];
48
50
  isSelected: boolean;
51
+ /** The type of the node the annotation is on, e.g. `'media'`. Undefined for inline text. */
52
+ targetNodeType?: string;
53
+ /** How the annotation came to be selected, for analytics parity with the surface events. */
54
+ viewMethod?: string;
49
55
  };
50
56
  export type AnnotationManagerEvents = {
51
57
  data: AnnotationDraftStartedData;
@@ -58,7 +64,7 @@ export type AnnotationManagerEvents = {
58
64
  };
59
65
  export type ManagerFailureReasons = 'manager-not-initialized' | 'hook-execution-error';
60
66
  export type StartDraftResult = {
61
- reason: ManagerFailureReasons | 'invalid-range' | 'draft-in-progress';
67
+ reason: ManagerFailureReasons | 'invalid-range' | 'draft-in-progress' | 'invalid-localId';
62
68
  success: false;
63
69
  } | ({
64
70
  success: true;
@@ -108,6 +114,20 @@ export type HoverAnnotationResult = {
108
114
  isHovered: boolean;
109
115
  success: true;
110
116
  };
117
+ export type ClearSelectedAnnotationResult = {
118
+ reason: ManagerFailureReasons | 'draft-in-progress';
119
+ success: false;
120
+ } | {
121
+ annotationId: AnnotationId | undefined;
122
+ success: true;
123
+ };
124
+ export type ClearHoveredAnnotationResult = {
125
+ reason: ManagerFailureReasons;
126
+ success: false;
127
+ } | {
128
+ annotationId: AnnotationId | undefined;
129
+ success: true;
130
+ };
111
131
  /**
112
132
  * This is the list of methods which exist on the Manager interface. These are the methods that can be hooked into.
113
133
  */
@@ -126,6 +146,17 @@ export type AnnotationManagerMethods = {
126
146
  applyDraft: (id: AnnotationId) => ApplyDraftResult;
127
147
  clearAnnotation: (id: AnnotationId) => ClearAnnotationResult;
128
148
  clearDraft: () => ClearDraftResult;
149
+ /**
150
+ * Clears the hover state without needing to know which annotation is hovered.
151
+ * @returns The annotation that was hovered, or undefined when nothing was.
152
+ */
153
+ clearHoveredAnnotation: () => ClearHoveredAnnotationResult;
154
+ /**
155
+ * Deselects the selected annotation without needing to know which one it is, for surfaces
156
+ * outside the document (the comments panel, the comment button) that only want to clear it.
157
+ * @returns The annotation that was selected, or undefined when nothing was.
158
+ */
159
+ clearSelectedAnnotation: () => ClearSelectedAnnotationResult;
129
160
  /**
130
161
  * This can be used to inspect the current active draft.
131
162
  * @returns The current draft data. If the draft is not started, it will return an error.
@@ -133,7 +164,14 @@ export type AnnotationManagerMethods = {
133
164
  getDraft: () => GetDraftResult;
134
165
  setIsAnnotationHovered: (id: AnnotationId, isHovered: boolean) => HoverAnnotationResult;
135
166
  setIsAnnotationSelected: (id: AnnotationId, isSelected: boolean) => SelectAnnotationResult;
136
- startDraft: () => StartDraftResult;
167
+ /**
168
+ * Starts a draft annotation.
169
+ *
170
+ * @param localId Targets the block node with this `localId`, resolving to its closest
171
+ * annotatable ancestor when the node itself does not accept annotations. Without it the draft
172
+ * targets the current text selection.
173
+ */
174
+ startDraft: (localId?: string) => StartDraftResult;
137
175
  };
138
176
  export type AnnotationManager = AnnotationManagerMethods & {
139
177
  /**
@@ -163,8 +201,11 @@ export type AnnotationManager = AnnotationManagerMethods & {
163
201
  */
164
202
  hook: <H extends keyof AnnotationManagerMethods>(method: H, handler: AnnotationManagerMethods[H]) => AnnotationManager;
165
203
  offAnnotationSelectionChange: (handler: (data: AnnotationSelectedChangeData) => void) => AnnotationManager;
204
+ offDraftAnnotationCleared: (handler: () => void) => AnnotationManager;
166
205
  offDraftAnnotationStarted: (handler: (data: AnnotationDraftStartedData) => void) => AnnotationManager;
167
206
  onAnnotationSelectionChange: (handler: (data: AnnotationSelectedChangeData) => void) => AnnotationManager;
207
+ /** Subscribe to `draftAnnotationCleared`, fired when an in-progress draft is discarded. */
208
+ onDraftAnnotationCleared: (handler: () => void) => AnnotationManager;
168
209
  onDraftAnnotationStarted: (handler: (data: AnnotationDraftStartedData) => void) => AnnotationManager;
169
210
  /**
170
211
  * This method is used to set a preemptive gate. A preemptive gate is a function that will be called
@@ -1,5 +1,5 @@
1
1
  import type { AnnotationId } from '@atlaskit/adf-schema/annotation';
2
- import type { AnnotationDraftStartedData, AnnotationManager, AnnotationManagerEvents, AnnotationManagerMethods, AnnotationSelectedChangeData, ApplyDraftResult, ClearAnnotationResult, ClearDraftResult, GetDraftResult, HoverAnnotationResult, SelectAnnotationResult, StartDraftResult } from './index';
2
+ import type { AnnotationDraftStartedData, AnnotationManager, AnnotationManagerEvents, AnnotationManagerMethods, AnnotationSelectedChangeData, ApplyDraftResult, ClearAnnotationResult, ClearDraftResult, ClearHoveredAnnotationResult, ClearSelectedAnnotationResult, GetDraftResult, HoverAnnotationResult, SelectAnnotationResult, StartDraftResult } from './index';
3
3
  export declare class SharedAnnotationManager implements AnnotationManager {
4
4
  /**
5
5
  * This is the event emitter that is used to emit events from the manager. It is used to communicate with
@@ -19,15 +19,19 @@ export declare class SharedAnnotationManager implements AnnotationManager {
19
19
  offDraftAnnotationStarted(handler: (data: AnnotationDraftStartedData) => void): AnnotationManager;
20
20
  onAnnotationSelectionChange(handler: (data: AnnotationSelectedChangeData) => void): AnnotationManager;
21
21
  offAnnotationSelectionChange(handler: (data: AnnotationSelectedChangeData) => void): AnnotationManager;
22
+ onDraftAnnotationCleared(handler: () => void): AnnotationManager;
23
+ offDraftAnnotationCleared(handler: () => void): AnnotationManager;
22
24
  emit(event: AnnotationManagerEvents): AnnotationManager;
23
25
  hook<H extends keyof AnnotationManagerMethods>(method: H, handler: AnnotationManagerMethods[H]): AnnotationManager;
24
26
  unhook<H extends keyof AnnotationManagerMethods>(method: H, handler: AnnotationManagerMethods[H]): AnnotationManager;
25
27
  allowAnnotation(): boolean;
26
- startDraft(): StartDraftResult;
28
+ startDraft(localId?: string): StartDraftResult;
27
29
  clearDraft(): ClearDraftResult;
28
30
  applyDraft(id: AnnotationId): ApplyDraftResult;
29
31
  getDraft(): GetDraftResult;
30
32
  setIsAnnotationSelected(id: string, isSelected: boolean): SelectAnnotationResult;
31
33
  setIsAnnotationHovered(id: string, isHovered: boolean): HoverAnnotationResult;
32
34
  clearAnnotation(id: AnnotationId): ClearAnnotationResult;
35
+ clearSelectedAnnotation(): ClearSelectedAnnotationResult;
36
+ clearHoveredAnnotation(): ClearHoveredAnnotationResult;
33
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-common",
3
- "version": "128.2.0",
3
+ "version": "128.3.0",
4
4
  "description": "A package that contains common classes and components for editor and renderer",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -85,8 +85,8 @@
85
85
  "@atlaskit/task-decision": "^21.12.0",
86
86
  "@atlaskit/teams-app-config": "^3.1.0",
87
87
  "@atlaskit/textfield": "^10.2.0",
88
- "@atlaskit/tmp-editor-statsig": "^221.0.0",
89
- "@atlaskit/tokens": "^20.2.0",
88
+ "@atlaskit/tmp-editor-statsig": "^222.0.0",
89
+ "@atlaskit/tokens": "^20.3.0",
90
90
  "@atlaskit/tooltip": "^24.4.0",
91
91
  "@atlaskit/width-detector": "^7.2.0",
92
92
  "@babel/runtime": "^7.0.0",