@atlaskit/editor-plugin-undo-redo 6.1.0 → 6.1.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,20 @@
1
1
  # @atlaskit/editor-plugin-undo-redo
2
2
 
3
+ ## 6.1.2
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies
8
+
9
+ ## 6.1.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`c74a1bd9f8e48`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/c74a1bd9f8e48) -
14
+ EDITOR-1818: extend undo analytics to describe attribute changes. This is to help us investigate
15
+ undos that have no visible effects
16
+ - Updated dependencies
17
+
3
18
  ## 6.1.0
4
19
 
5
20
  ### Minor Changes
@@ -1,13 +1,21 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
7
  exports.attachInputMetaWithAnalytics = exports.attachInputMeta = void 0;
8
+ exports.getChanges = getChanges;
9
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
11
  var _analytics = require("@atlaskit/editor-common/analytics");
8
12
  var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
13
+ var _document = require("@atlaskit/editor-common/utils/document");
14
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
9
15
  var _enums = require("./enums");
10
16
  var _pluginKey = require("./plugin-key");
17
+ 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; }
18
+ 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; }
11
19
  var attachInputMeta = exports.attachInputMeta = function attachInputMeta(inputSource) {
12
20
  return function (command) {
13
21
  return function (state, dispatch) {
@@ -39,10 +47,66 @@ var inputSourceToInputMethod = function inputSourceToInputMethod(inputSource) {
39
47
  return _analytics.INPUT_METHOD.EXTERNAL;
40
48
  }
41
49
  };
50
+ function getNodesWithDifferingAttributes(_ref) {
51
+ var before = _ref.before,
52
+ after = _ref.after;
53
+ var allAttributeKeys = Object.keys(_objectSpread(_objectSpread({}, before.attrs), after.attrs));
54
+ var differingAttributes = allAttributeKeys.filter(function (key) {
55
+ return before.attrs[key] !== after.attrs[key];
56
+ });
57
+ var affectedNodes = differingAttributes.length ? [{
58
+ type: before.type.name,
59
+ attributes: differingAttributes
60
+ }] : [];
61
+ return before.children.reduce(function (acc, beforeChild, index) {
62
+ return [].concat((0, _toConsumableArray2.default)(acc), (0, _toConsumableArray2.default)(getNodesWithDifferingAttributes({
63
+ before: beforeChild,
64
+ after: after.child(index)
65
+ })));
66
+ }, affectedNodes);
67
+ }
68
+
69
+ /**
70
+ * Analyzes changes between two ProseMirror document nodes.
71
+ *
72
+ * @param params - Object containing before and after node states
73
+ * @param params.before - The document node before changes
74
+ * @param params.after - The document node after changes
75
+ * @returns Object containing change analysis results with hasChanged boolean and affectedNodes array
76
+ */
77
+ function getChanges(_ref2) {
78
+ var before = _ref2.before,
79
+ after = _ref2.after;
80
+ var hasChanged = !(0, _document.areNodesEqualIgnoreAttrs)(after, before);
81
+ var affectedNodes = hasChanged ? undefined : getNodesWithDifferingAttributes({
82
+ before: before,
83
+ after: after
84
+ })
85
+ // Limit to 25 nodes to avoid oversize payloads
86
+ .slice(0, 25);
87
+ return {
88
+ hasChanged: hasChanged,
89
+ affectedNodes: affectedNodes
90
+ };
91
+ }
42
92
  var attachInputMetaWithAnalytics = exports.attachInputMetaWithAnalytics = function attachInputMetaWithAnalytics(editorAnalyticsAPI) {
43
93
  return function (inputSource, action) {
44
94
  return function (command) {
45
- return attachInputMeta(inputSource)((0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, {
95
+ return attachInputMeta(inputSource)((0, _editorAnalytics.withAnalytics)(editorAnalyticsAPI, (0, _platformFeatureFlags.fg)('platform_editor_add_undo_meta_analytics') ? function (_ref3, _ref4) {
96
+ var before = _ref3.doc;
97
+ var after = _ref4.currentDoc;
98
+ return {
99
+ eventType: _analytics.EVENT_TYPE.TRACK,
100
+ action: action,
101
+ actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
102
+ attributes: _objectSpread({
103
+ inputMethod: inputSourceToInputMethod(inputSource)
104
+ }, getChanges({
105
+ before: before,
106
+ after: after
107
+ }))
108
+ };
109
+ } : {
46
110
  eventType: _analytics.EVENT_TYPE.TRACK,
47
111
  action: action,
48
112
  actionSubject: _analytics.ACTION_SUBJECT.EDITOR,
@@ -1,5 +1,7 @@
1
1
  import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
2
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
3
+ import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
4
+ import { fg } from '@atlaskit/platform-feature-flags';
3
5
  import { InputSource } from './enums';
4
6
  import { pluginKey as undoPluginKey } from './plugin-key';
5
7
  export const attachInputMeta = inputSource => command => (state, dispatch) => {
@@ -29,7 +31,65 @@ const inputSourceToInputMethod = inputSource => {
29
31
  return INPUT_METHOD.EXTERNAL;
30
32
  }
31
33
  };
32
- export const attachInputMetaWithAnalytics = editorAnalyticsAPI => (inputSource, action) => command => attachInputMeta(inputSource)(withAnalytics(editorAnalyticsAPI, {
34
+ function getNodesWithDifferingAttributes({
35
+ before,
36
+ after
37
+ }) {
38
+ const allAttributeKeys = Object.keys({
39
+ ...before.attrs,
40
+ ...after.attrs
41
+ });
42
+ const differingAttributes = allAttributeKeys.filter(key => before.attrs[key] !== after.attrs[key]);
43
+ const affectedNodes = differingAttributes.length ? [{
44
+ type: before.type.name,
45
+ attributes: differingAttributes
46
+ }] : [];
47
+ return before.children.reduce((acc, beforeChild, index) => [...acc, ...getNodesWithDifferingAttributes({
48
+ before: beforeChild,
49
+ after: after.child(index)
50
+ })], affectedNodes);
51
+ }
52
+
53
+ /**
54
+ * Analyzes changes between two ProseMirror document nodes.
55
+ *
56
+ * @param params - Object containing before and after node states
57
+ * @param params.before - The document node before changes
58
+ * @param params.after - The document node after changes
59
+ * @returns Object containing change analysis results with hasChanged boolean and affectedNodes array
60
+ */
61
+ export function getChanges({
62
+ before,
63
+ after
64
+ }) {
65
+ const hasChanged = !areNodesEqualIgnoreAttrs(after, before);
66
+ const affectedNodes = hasChanged ? undefined : getNodesWithDifferingAttributes({
67
+ before,
68
+ after
69
+ })
70
+ // Limit to 25 nodes to avoid oversize payloads
71
+ .slice(0, 25);
72
+ return {
73
+ hasChanged,
74
+ affectedNodes
75
+ };
76
+ }
77
+ export const attachInputMetaWithAnalytics = editorAnalyticsAPI => (inputSource, action) => command => attachInputMeta(inputSource)(withAnalytics(editorAnalyticsAPI, fg('platform_editor_add_undo_meta_analytics') ? ({
78
+ doc: before
79
+ }, {
80
+ currentDoc: after
81
+ }) => ({
82
+ eventType: EVENT_TYPE.TRACK,
83
+ action,
84
+ actionSubject: ACTION_SUBJECT.EDITOR,
85
+ attributes: {
86
+ inputMethod: inputSourceToInputMethod(inputSource),
87
+ ...getChanges({
88
+ before,
89
+ after
90
+ })
91
+ }
92
+ }) : {
33
93
  eventType: EVENT_TYPE.TRACK,
34
94
  action,
35
95
  actionSubject: ACTION_SUBJECT.EDITOR,
@@ -1,5 +1,11 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ 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; }
4
+ 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; }
1
5
  import { ACTION_SUBJECT, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
2
6
  import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
7
+ import { areNodesEqualIgnoreAttrs } from '@atlaskit/editor-common/utils/document';
8
+ import { fg } from '@atlaskit/platform-feature-flags';
3
9
  import { InputSource } from './enums';
4
10
  import { pluginKey as undoPluginKey } from './plugin-key';
5
11
  export var attachInputMeta = function attachInputMeta(inputSource) {
@@ -33,10 +39,66 @@ var inputSourceToInputMethod = function inputSourceToInputMethod(inputSource) {
33
39
  return INPUT_METHOD.EXTERNAL;
34
40
  }
35
41
  };
42
+ function getNodesWithDifferingAttributes(_ref) {
43
+ var before = _ref.before,
44
+ after = _ref.after;
45
+ var allAttributeKeys = Object.keys(_objectSpread(_objectSpread({}, before.attrs), after.attrs));
46
+ var differingAttributes = allAttributeKeys.filter(function (key) {
47
+ return before.attrs[key] !== after.attrs[key];
48
+ });
49
+ var affectedNodes = differingAttributes.length ? [{
50
+ type: before.type.name,
51
+ attributes: differingAttributes
52
+ }] : [];
53
+ return before.children.reduce(function (acc, beforeChild, index) {
54
+ return [].concat(_toConsumableArray(acc), _toConsumableArray(getNodesWithDifferingAttributes({
55
+ before: beforeChild,
56
+ after: after.child(index)
57
+ })));
58
+ }, affectedNodes);
59
+ }
60
+
61
+ /**
62
+ * Analyzes changes between two ProseMirror document nodes.
63
+ *
64
+ * @param params - Object containing before and after node states
65
+ * @param params.before - The document node before changes
66
+ * @param params.after - The document node after changes
67
+ * @returns Object containing change analysis results with hasChanged boolean and affectedNodes array
68
+ */
69
+ export function getChanges(_ref2) {
70
+ var before = _ref2.before,
71
+ after = _ref2.after;
72
+ var hasChanged = !areNodesEqualIgnoreAttrs(after, before);
73
+ var affectedNodes = hasChanged ? undefined : getNodesWithDifferingAttributes({
74
+ before: before,
75
+ after: after
76
+ })
77
+ // Limit to 25 nodes to avoid oversize payloads
78
+ .slice(0, 25);
79
+ return {
80
+ hasChanged: hasChanged,
81
+ affectedNodes: affectedNodes
82
+ };
83
+ }
36
84
  export var attachInputMetaWithAnalytics = function attachInputMetaWithAnalytics(editorAnalyticsAPI) {
37
85
  return function (inputSource, action) {
38
86
  return function (command) {
39
- return attachInputMeta(inputSource)(withAnalytics(editorAnalyticsAPI, {
87
+ return attachInputMeta(inputSource)(withAnalytics(editorAnalyticsAPI, fg('platform_editor_add_undo_meta_analytics') ? function (_ref3, _ref4) {
88
+ var before = _ref3.doc;
89
+ var after = _ref4.currentDoc;
90
+ return {
91
+ eventType: EVENT_TYPE.TRACK,
92
+ action: action,
93
+ actionSubject: ACTION_SUBJECT.EDITOR,
94
+ attributes: _objectSpread({
95
+ inputMethod: inputSourceToInputMethod(inputSource)
96
+ }, getChanges({
97
+ before: before,
98
+ after: after
99
+ }))
100
+ };
101
+ } : {
40
102
  eventType: EVENT_TYPE.TRACK,
41
103
  action: action,
42
104
  actionSubject: ACTION_SUBJECT.EDITOR,
@@ -1,8 +1,28 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import { type ACTION } from '@atlaskit/editor-common/analytics';
1
+ import type { EditorAnalyticsAPI, ACTION } from '@atlaskit/editor-common/analytics';
3
2
  import type { HigherOrderCommand, Command } from '@atlaskit/editor-common/types';
3
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
4
4
  import { InputSource } from './enums';
5
5
  type AttachInputMeta = (inputSource: InputSource) => HigherOrderCommand;
6
6
  export declare const attachInputMeta: AttachInputMeta;
7
+ type NodeHistory = {
8
+ after: Node;
9
+ before: Node;
10
+ };
11
+ type NodeWithDifferingAttributes = {
12
+ attributes: string[];
13
+ type: string;
14
+ };
15
+ /**
16
+ * Analyzes changes between two ProseMirror document nodes.
17
+ *
18
+ * @param params - Object containing before and after node states
19
+ * @param params.before - The document node before changes
20
+ * @param params.after - The document node after changes
21
+ * @returns Object containing change analysis results with hasChanged boolean and affectedNodes array
22
+ */
23
+ export declare function getChanges({ before, after }: NodeHistory): {
24
+ hasChanged: boolean;
25
+ affectedNodes: NodeWithDifferingAttributes[] | undefined;
26
+ };
7
27
  export declare const attachInputMetaWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputSource: InputSource, action: ACTION.UNDO_PERFORMED | ACTION.REDO_PERFORMED) => (command: Command) => Command;
8
28
  export {};
@@ -1,8 +1,28 @@
1
- import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
2
- import { type ACTION } from '@atlaskit/editor-common/analytics';
1
+ import type { EditorAnalyticsAPI, ACTION } from '@atlaskit/editor-common/analytics';
3
2
  import type { HigherOrderCommand, Command } from '@atlaskit/editor-common/types';
3
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
4
4
  import { InputSource } from './enums';
5
5
  type AttachInputMeta = (inputSource: InputSource) => HigherOrderCommand;
6
6
  export declare const attachInputMeta: AttachInputMeta;
7
+ type NodeHistory = {
8
+ after: Node;
9
+ before: Node;
10
+ };
11
+ type NodeWithDifferingAttributes = {
12
+ attributes: string[];
13
+ type: string;
14
+ };
15
+ /**
16
+ * Analyzes changes between two ProseMirror document nodes.
17
+ *
18
+ * @param params - Object containing before and after node states
19
+ * @param params.before - The document node before changes
20
+ * @param params.after - The document node after changes
21
+ * @returns Object containing change analysis results with hasChanged boolean and affectedNodes array
22
+ */
23
+ export declare function getChanges({ before, after }: NodeHistory): {
24
+ hasChanged: boolean;
25
+ affectedNodes: NodeWithDifferingAttributes[] | undefined;
26
+ };
7
27
  export declare const attachInputMetaWithAnalytics: (editorAnalyticsAPI: EditorAnalyticsAPI | undefined) => (inputSource: InputSource, action: ACTION.UNDO_PERFORMED | ACTION.REDO_PERFORMED) => (command: Command) => Command;
8
28
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-undo-redo",
3
- "version": "6.1.0",
3
+ "version": "6.1.2",
4
4
  "description": "Undo redo plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,15 +31,15 @@
31
31
  "dependencies": {
32
32
  "@atlaskit/editor-plugin-history": "^6.0.0",
33
33
  "@atlaskit/editor-plugin-primary-toolbar": "^7.0.0",
34
- "@atlaskit/editor-plugin-toolbar": "^3.1.0",
34
+ "@atlaskit/editor-plugin-toolbar": "^3.2.0",
35
35
  "@atlaskit/editor-plugin-type-ahead": "^6.4.0",
36
36
  "@atlaskit/editor-prosemirror": "7.0.0",
37
- "@atlaskit/editor-toolbar": "^0.14.0",
37
+ "@atlaskit/editor-toolbar": "^0.15.0",
38
38
  "@atlaskit/editor-toolbar-model": "^0.2.0",
39
39
  "@atlaskit/icon": "^28.5.0",
40
40
  "@atlaskit/platform-feature-flags": "^1.1.0",
41
41
  "@atlaskit/prosemirror-history": "^0.2.0",
42
- "@atlaskit/tmp-editor-statsig": "^13.6.0",
42
+ "@atlaskit/tmp-editor-statsig": "^13.8.0",
43
43
  "@babel/runtime": "^7.0.0",
44
44
  "@emotion/react": "^11.7.1"
45
45
  },
@@ -92,6 +92,9 @@
92
92
  "platform-feature-flags": {
93
93
  "platform_editor_cmd_y_mac_redo_shortcut": {
94
94
  "type": "boolean"
95
+ },
96
+ "platform_editor_add_undo_meta_analytics": {
97
+ "type": "boolean"
95
98
  }
96
99
  }
97
100
  }