@atlaskit/editor-plugin-table 2.12.3 → 2.12.5

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,17 @@
1
1
  # @atlaskit/editor-plugin-table
2
2
 
3
+ ## 2.12.5
4
+
5
+ ### Patch Changes
6
+
7
+ - [`1da71810c5d`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1da71810c5d) - [Regression] Fix Invalid getPos issue happening for Table nodeviews
8
+
9
+ ## 2.12.4
10
+
11
+ ### Patch Changes
12
+
13
+ - [`74cf8d56408`](https://bitbucket.org/atlassian/atlassian-frontend/commits/74cf8d56408) - ED-19748: dispatch analytics when a table is selected.
14
+
3
15
  ## 2.12.3
4
16
 
5
17
  ### Patch Changes
@@ -182,8 +182,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
182
182
  name: 'tableWidth',
183
183
  plugin: function plugin(_ref9) {
184
184
  var _options$fullWidthEna;
185
- var dispatch = _ref9.dispatch;
186
- return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
185
+ var dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent,
186
+ dispatch = _ref9.dispatch;
187
+ return options !== null && options !== void 0 && options.tableResizingEnabled ? (0, _tableWidth.createPlugin)(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
187
188
  }
188
189
  }, {
189
190
  name: 'tableGetEditorViewReferencePlugin',
@@ -153,7 +153,19 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
153
153
  var containerWidth = props.getEditorContainerWidth();
154
154
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
155
155
  var isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
156
- var tableActive = props.getPos() === pluginState.tablePos && !isTableResizing;
156
+
157
+ /**
158
+ * ED-19810
159
+ * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
160
+ * before CR6 lands in production
161
+ */
162
+ var tablePos;
163
+ try {
164
+ tablePos = typeof props.getPos === 'function' ? props.getPos() : undefined;
165
+ } catch (e) {
166
+ tablePos = undefined;
167
+ }
168
+ var tableActive = tablePos === pluginState.tablePos && !isTableResizing;
157
169
  return /*#__PURE__*/_react.default.createElement(_TableComponent.default, {
158
170
  view: props.view,
159
171
  allowColumnResizing: props.allowColumnResizing,
@@ -8,10 +8,12 @@ exports.pluginKey = exports.createPlugin = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
10
10
  var _steps = require("@atlaskit/adf-schema/steps");
11
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
12
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
12
13
  var _state = require("@atlaskit/editor-prosemirror/state");
13
14
  var _transform = require("@atlaskit/editor-prosemirror/transform");
14
15
  var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
16
+ var _utils = require("@atlaskit/editor-tables/utils");
15
17
  var _excluded = ["width"];
16
18
  /**
17
19
  * A plugin for handle table custom widths
@@ -22,7 +24,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
22
24
  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; }
23
25
  var pluginKey = new _state.PluginKey('tableWidthPlugin');
24
26
  exports.pluginKey = pluginKey;
25
- var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
27
+ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled) {
26
28
  return new _safePlugin.SafePlugin({
27
29
  key: pluginKey,
28
30
  state: {
@@ -43,7 +45,27 @@ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
43
45
  return pluginState;
44
46
  }
45
47
  },
46
- appendTransaction: function appendTransaction(transactions, _oldState, newState) {
48
+ appendTransaction: function appendTransaction(transactions, oldState, newState) {
49
+ // do not fire select table analytics events when a table is being created or deleted
50
+ var selectedTableOldState = (0, _utils.findTable)(oldState.selection);
51
+ var selectedTableNewState = (0, _utils.findTable)(newState.selection);
52
+
53
+ /**
54
+ * Select table event
55
+ * condition: 1
56
+ * When users selection changes to table
57
+ */
58
+ if (!selectedTableOldState && selectedTableNewState) {
59
+ dispatchAnalyticsEvent({
60
+ action: _analytics.ACTION.SELECTED,
61
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
62
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
63
+ eventType: _analytics.EVENT_TYPE.TRACK,
64
+ attributes: {
65
+ localId: selectedTableNewState.node.attrs.localId || ''
66
+ }
67
+ });
68
+ }
47
69
  // When document first load in Confluence, initially it is an empty document
48
70
  // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
49
71
  // what we need to do is to add width attr to all tables in the real document
@@ -57,7 +79,7 @@ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
57
79
  return false;
58
80
  }
59
81
  var isStepReplacingFromDocStart = step.from === 0;
60
- var isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
82
+ var isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
61
83
  if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
62
84
  return false;
63
85
  }
@@ -70,6 +92,23 @@ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
70
92
  }
71
93
  var tr = newState.tr;
72
94
  var table = newState.schema.nodes.table;
95
+
96
+ /**
97
+ * Select table event
98
+ * condition: 2
99
+ * Users selection defaults to table, if first node
100
+ */
101
+ if (selectedTableOldState) {
102
+ dispatchAnalyticsEvent({
103
+ action: _analytics.ACTION.SELECTED,
104
+ actionSubject: _analytics.ACTION_SUBJECT.DOCUMENT,
105
+ actionSubjectId: _analytics.ACTION_SUBJECT_ID.TABLE,
106
+ eventType: _analytics.EVENT_TYPE.TRACK,
107
+ attributes: {
108
+ localId: selectedTableOldState.node.attrs.localId || ''
109
+ }
110
+ });
111
+ }
73
112
  newState.doc.forEach(function (node, offset) {
74
113
  if (node.type === table) {
75
114
  var width = node.attrs.width;
@@ -165,10 +165,11 @@ const tablesPlugin = ({
165
165
  }, {
166
166
  name: 'tableWidth',
167
167
  plugin: ({
168
+ dispatchAnalyticsEvent,
168
169
  dispatch
169
170
  }) => {
170
171
  var _options$fullWidthEna;
171
- return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
172
+ return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
172
173
  }
173
174
  }, {
174
175
  name: 'tableGetEditorViewReferencePlugin',
@@ -125,7 +125,19 @@ export default class TableView extends ReactNodeView {
125
125
  const containerWidth = props.getEditorContainerWidth();
126
126
  const isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
127
127
  const isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
128
- const tableActive = props.getPos() === pluginState.tablePos && !isTableResizing;
128
+
129
+ /**
130
+ * ED-19810
131
+ * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
132
+ * before CR6 lands in production
133
+ */
134
+ let tablePos;
135
+ try {
136
+ tablePos = typeof props.getPos === 'function' ? props.getPos() : undefined;
137
+ } catch (e) {
138
+ tablePos = undefined;
139
+ }
140
+ const tableActive = tablePos === pluginState.tablePos && !isTableResizing;
129
141
  return /*#__PURE__*/React.createElement(TableComponent, {
130
142
  view: props.view,
131
143
  allowColumnResizing: props.allowColumnResizing,
@@ -5,12 +5,14 @@
5
5
  */
6
6
 
7
7
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
8
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
8
9
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
9
10
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
10
11
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
11
12
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
13
+ import { findTable } from '@atlaskit/editor-tables/utils';
12
14
  export const pluginKey = new PluginKey('tableWidthPlugin');
13
- const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
15
+ const createPlugin = (dispatch, dispatchAnalyticsEvent, fullWidthEnabled) => new SafePlugin({
14
16
  key: pluginKey,
15
17
  state: {
16
18
  init() {
@@ -30,7 +32,27 @@ const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
30
32
  return pluginState;
31
33
  }
32
34
  },
33
- appendTransaction: (transactions, _oldState, newState) => {
35
+ appendTransaction: (transactions, oldState, newState) => {
36
+ // do not fire select table analytics events when a table is being created or deleted
37
+ const selectedTableOldState = findTable(oldState.selection);
38
+ const selectedTableNewState = findTable(newState.selection);
39
+
40
+ /**
41
+ * Select table event
42
+ * condition: 1
43
+ * When users selection changes to table
44
+ */
45
+ if (!selectedTableOldState && selectedTableNewState) {
46
+ dispatchAnalyticsEvent({
47
+ action: ACTION.SELECTED,
48
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
49
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
50
+ eventType: EVENT_TYPE.TRACK,
51
+ attributes: {
52
+ localId: selectedTableNewState.node.attrs.localId || ''
53
+ }
54
+ });
55
+ }
34
56
  // When document first load in Confluence, initially it is an empty document
35
57
  // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
36
58
  // what we need to do is to add width attr to all tables in the real document
@@ -44,7 +66,7 @@ const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
44
66
  return false;
45
67
  }
46
68
  const isStepReplacingFromDocStart = step.from === 0;
47
- const isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
69
+ const isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
48
70
  if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
49
71
  return false;
50
72
  }
@@ -59,6 +81,23 @@ const createPlugin = (dispatch, fullWidthEnabled) => new SafePlugin({
59
81
  const {
60
82
  table
61
83
  } = newState.schema.nodes;
84
+
85
+ /**
86
+ * Select table event
87
+ * condition: 2
88
+ * Users selection defaults to table, if first node
89
+ */
90
+ if (selectedTableOldState) {
91
+ dispatchAnalyticsEvent({
92
+ action: ACTION.SELECTED,
93
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
94
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
95
+ eventType: EVENT_TYPE.TRACK,
96
+ attributes: {
97
+ localId: selectedTableOldState.node.attrs.localId || ''
98
+ }
99
+ });
100
+ }
62
101
  newState.doc.forEach((node, offset) => {
63
102
  if (node.type === table) {
64
103
  const width = node.attrs.width;
@@ -175,8 +175,9 @@ var tablesPlugin = function tablesPlugin(_ref) {
175
175
  name: 'tableWidth',
176
176
  plugin: function plugin(_ref9) {
177
177
  var _options$fullWidthEna;
178
- var dispatch = _ref9.dispatch;
179
- return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
178
+ var dispatchAnalyticsEvent = _ref9.dispatchAnalyticsEvent,
179
+ dispatch = _ref9.dispatch;
180
+ return options !== null && options !== void 0 && options.tableResizingEnabled ? createTableWidthPlugin(dispatch, dispatchAnalyticsEvent, (_options$fullWidthEna = options === null || options === void 0 ? void 0 : options.fullWidthEnabled) !== null && _options$fullWidthEna !== void 0 ? _options$fullWidthEna : false) : undefined;
180
181
  }
181
182
  }, {
182
183
  name: 'tableGetEditorViewReferencePlugin',
@@ -146,7 +146,19 @@ var TableView = /*#__PURE__*/function (_ReactNodeView) {
146
146
  var containerWidth = props.getEditorContainerWidth();
147
147
  var isTableResizing = tableWidthPluginState === null || tableWidthPluginState === void 0 ? void 0 : tableWidthPluginState.resizing;
148
148
  var isResizing = Boolean((tableResizingPluginState === null || tableResizingPluginState === void 0 ? void 0 : tableResizingPluginState.dragging) || isTableResizing);
149
- var tableActive = props.getPos() === pluginState.tablePos && !isTableResizing;
149
+
150
+ /**
151
+ * ED-19810
152
+ * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
153
+ * before CR6 lands in production
154
+ */
155
+ var tablePos;
156
+ try {
157
+ tablePos = typeof props.getPos === 'function' ? props.getPos() : undefined;
158
+ } catch (e) {
159
+ tablePos = undefined;
160
+ }
161
+ var tableActive = tablePos === pluginState.tablePos && !isTableResizing;
150
162
  return /*#__PURE__*/React.createElement(TableComponent, {
151
163
  view: props.view,
152
164
  allowColumnResizing: props.allowColumnResizing,
@@ -10,12 +10,14 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
10
10
  */
11
11
 
12
12
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
13
+ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
13
14
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
14
15
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
15
16
  import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
16
17
  import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
18
+ import { findTable } from '@atlaskit/editor-tables/utils';
17
19
  export var pluginKey = new PluginKey('tableWidthPlugin');
18
- var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
20
+ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled) {
19
21
  return new SafePlugin({
20
22
  key: pluginKey,
21
23
  state: {
@@ -36,7 +38,27 @@ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
36
38
  return pluginState;
37
39
  }
38
40
  },
39
- appendTransaction: function appendTransaction(transactions, _oldState, newState) {
41
+ appendTransaction: function appendTransaction(transactions, oldState, newState) {
42
+ // do not fire select table analytics events when a table is being created or deleted
43
+ var selectedTableOldState = findTable(oldState.selection);
44
+ var selectedTableNewState = findTable(newState.selection);
45
+
46
+ /**
47
+ * Select table event
48
+ * condition: 1
49
+ * When users selection changes to table
50
+ */
51
+ if (!selectedTableOldState && selectedTableNewState) {
52
+ dispatchAnalyticsEvent({
53
+ action: ACTION.SELECTED,
54
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
55
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
56
+ eventType: EVENT_TYPE.TRACK,
57
+ attributes: {
58
+ localId: selectedTableNewState.node.attrs.localId || ''
59
+ }
60
+ });
61
+ }
40
62
  // When document first load in Confluence, initially it is an empty document
41
63
  // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
42
64
  // what we need to do is to add width attr to all tables in the real document
@@ -50,7 +72,7 @@ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
50
72
  return false;
51
73
  }
52
74
  var isStepReplacingFromDocStart = step.from === 0;
53
- var isStepReplacingUntilTheEndOfDocument = step.to === _oldState.doc.content.size;
75
+ var isStepReplacingUntilTheEndOfDocument = step.to === oldState.doc.content.size;
54
76
  if (!isStepReplacingFromDocStart || !isStepReplacingUntilTheEndOfDocument) {
55
77
  return false;
56
78
  }
@@ -63,6 +85,23 @@ var createPlugin = function createPlugin(dispatch, fullWidthEnabled) {
63
85
  }
64
86
  var tr = newState.tr;
65
87
  var table = newState.schema.nodes.table;
88
+
89
+ /**
90
+ * Select table event
91
+ * condition: 2
92
+ * Users selection defaults to table, if first node
93
+ */
94
+ if (selectedTableOldState) {
95
+ dispatchAnalyticsEvent({
96
+ action: ACTION.SELECTED,
97
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
98
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
99
+ eventType: EVENT_TYPE.TRACK,
100
+ attributes: {
101
+ localId: selectedTableOldState.node.attrs.localId || ''
102
+ }
103
+ });
104
+ }
66
105
  newState.doc.forEach(function (node, offset) {
67
106
  if (node.type === table) {
68
107
  var width = node.attrs.width;
@@ -3,6 +3,7 @@
3
3
  * Has login to scan the document, add width value to table's width attribute when necessary
4
4
  * Also holds resizing state to hide / show table controls
5
5
  */
6
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
6
7
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
7
8
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
9
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
@@ -10,7 +11,7 @@ type TableWidthPluginState = {
10
11
  resizing: boolean;
11
12
  };
12
13
  export declare const pluginKey: PluginKey<TableWidthPluginState>;
13
- declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<{
14
+ declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean) => SafePlugin<{
14
15
  resizing: boolean;
15
16
  }>;
16
17
  export { createPlugin };
@@ -3,6 +3,7 @@
3
3
  * Has login to scan the document, add width value to table's width attribute when necessary
4
4
  * Also holds resizing state to hide / show table controls
5
5
  */
6
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
6
7
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
7
8
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
9
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
@@ -10,7 +11,7 @@ type TableWidthPluginState = {
10
11
  resizing: boolean;
11
12
  };
12
13
  export declare const pluginKey: PluginKey<TableWidthPluginState>;
13
- declare const createPlugin: (dispatch: Dispatch, fullWidthEnabled: boolean) => SafePlugin<{
14
+ declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean) => SafePlugin<{
14
15
  resizing: boolean;
15
16
  }>;
16
17
  export { createPlugin };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "2.12.3",
3
+ "version": "2.12.5",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -37,7 +37,7 @@
37
37
  "@atlaskit/editor-tables": "^2.3.0",
38
38
  "@atlaskit/icon": "^21.12.0",
39
39
  "@atlaskit/platform-feature-flags": "^0.2.1",
40
- "@atlaskit/theme": "^12.5.0",
40
+ "@atlaskit/theme": "^12.6.0",
41
41
  "@atlaskit/tokens": "^1.18.0",
42
42
  "@atlaskit/tooltip": "^17.8.0",
43
43
  "@babel/runtime": "^7.0.0",
@@ -268,10 +268,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
268
268
  },
269
269
  {
270
270
  name: 'tableWidth',
271
- plugin: ({ dispatch }) =>
271
+ plugin: ({ dispatchAnalyticsEvent, dispatch }) =>
272
272
  options?.tableResizingEnabled
273
273
  ? createTableWidthPlugin(
274
274
  dispatch,
275
+ dispatchAnalyticsEvent,
275
276
  options?.fullWidthEnabled ?? false,
276
277
  )
277
278
  : undefined,
@@ -221,8 +221,22 @@ export default class TableView extends ReactNodeView<Props> {
221
221
  const isResizing = Boolean(
222
222
  tableResizingPluginState?.dragging || isTableResizing,
223
223
  );
224
+
225
+ /**
226
+ * ED-19810
227
+ * There is a getPos issue coming from this code. We need to apply this workaround for now and apply a patch
228
+ * before CR6 lands in production
229
+ */
230
+ let tablePos: number | undefined;
231
+ try {
232
+ tablePos =
233
+ typeof props.getPos === 'function' ? props.getPos() : undefined;
234
+ } catch (e) {
235
+ tablePos = undefined;
236
+ }
237
+
224
238
  const tableActive =
225
- props.getPos() === pluginState!.tablePos && !isTableResizing;
239
+ tablePos === pluginState!.tablePos && !isTableResizing;
226
240
 
227
241
  return (
228
242
  <TableComponent
@@ -5,6 +5,13 @@
5
5
  */
6
6
 
7
7
  import { SetAttrsStep } from '@atlaskit/adf-schema/steps';
8
+ import {
9
+ ACTION,
10
+ ACTION_SUBJECT,
11
+ ACTION_SUBJECT_ID,
12
+ EVENT_TYPE,
13
+ } from '@atlaskit/editor-common/analytics';
14
+ import type { DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
8
15
  import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
9
16
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
10
17
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
@@ -14,6 +21,7 @@ import {
14
21
  akEditorFullWidthLayoutWidth,
15
22
  akEditorWideLayoutWidth,
16
23
  } from '@atlaskit/editor-shared-styles';
24
+ import { findTable } from '@atlaskit/editor-tables/utils';
17
25
 
18
26
  type __ReplaceStep = ReplaceStep & {
19
27
  // Properties `to` and `from` are private attributes of ReplaceStep.
@@ -29,7 +37,11 @@ export const pluginKey = new PluginKey<TableWidthPluginState>(
29
37
  'tableWidthPlugin',
30
38
  );
31
39
 
32
- const createPlugin = (dispatch: Dispatch, fullWidthEnabled: boolean) =>
40
+ const createPlugin = (
41
+ dispatch: Dispatch,
42
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent,
43
+ fullWidthEnabled: boolean,
44
+ ) =>
33
45
  new SafePlugin({
34
46
  key: pluginKey,
35
47
  state: {
@@ -50,7 +62,27 @@ const createPlugin = (dispatch: Dispatch, fullWidthEnabled: boolean) =>
50
62
  return pluginState;
51
63
  },
52
64
  },
53
- appendTransaction: (transactions, _oldState, newState) => {
65
+ appendTransaction: (transactions, oldState, newState) => {
66
+ // do not fire select table analytics events when a table is being created or deleted
67
+ const selectedTableOldState = findTable(oldState.selection);
68
+ const selectedTableNewState = findTable(newState.selection);
69
+
70
+ /**
71
+ * Select table event
72
+ * condition: 1
73
+ * When users selection changes to table
74
+ */
75
+ if (!selectedTableOldState && selectedTableNewState) {
76
+ dispatchAnalyticsEvent({
77
+ action: ACTION.SELECTED,
78
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
79
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
80
+ eventType: EVENT_TYPE.TRACK,
81
+ attributes: {
82
+ localId: selectedTableNewState.node.attrs.localId || '',
83
+ },
84
+ });
85
+ }
54
86
  // When document first load in Confluence, initially it is an empty document
55
87
  // and Collab service triggers a transaction to replace the empty document with the real document that should be rendered.
56
88
  // what we need to do is to add width attr to all tables in the real document
@@ -68,7 +100,7 @@ const createPlugin = (dispatch: Dispatch, fullWidthEnabled: boolean) =>
68
100
  const isStepReplacingFromDocStart =
69
101
  (step as __ReplaceStep).from === 0;
70
102
  const isStepReplacingUntilTheEndOfDocument =
71
- (step as __ReplaceStep).to === _oldState.doc.content.size;
103
+ (step as __ReplaceStep).to === oldState.doc.content.size;
72
104
 
73
105
  if (
74
106
  !isStepReplacingFromDocStart ||
@@ -89,6 +121,23 @@ const createPlugin = (dispatch: Dispatch, fullWidthEnabled: boolean) =>
89
121
  const tr = newState.tr;
90
122
  const { table } = newState.schema.nodes;
91
123
 
124
+ /**
125
+ * Select table event
126
+ * condition: 2
127
+ * Users selection defaults to table, if first node
128
+ */
129
+ if (selectedTableOldState) {
130
+ dispatchAnalyticsEvent({
131
+ action: ACTION.SELECTED,
132
+ actionSubject: ACTION_SUBJECT.DOCUMENT,
133
+ actionSubjectId: ACTION_SUBJECT_ID.TABLE,
134
+ eventType: EVENT_TYPE.TRACK,
135
+ attributes: {
136
+ localId: selectedTableOldState.node.attrs.localId || '',
137
+ },
138
+ });
139
+ }
140
+
92
141
  newState.doc.forEach((node, offset) => {
93
142
  if (node.type === table) {
94
143
  const width = node.attrs.width;
@@ -1,173 +0,0 @@
1
- // Jest Snapshot v1, https://goo.gl/fbAQLP
2
-
3
- exports[`change-date-inside-table.ts: Change date inside table 1`] = `
4
- Object {
5
- "content": Array [
6
- Object {
7
- "attrs": Object {
8
- "__autoSize": false,
9
- "isNumberColumnEnabled": false,
10
- "layout": "default",
11
- "localId": "abc-123",
12
- },
13
- "content": Array [
14
- Object {
15
- "content": Array [
16
- Object {
17
- "attrs": Object {
18
- "background": null,
19
- "colspan": 1,
20
- "colwidth": null,
21
- "rowspan": 1,
22
- },
23
- "content": Array [
24
- Object {
25
- "content": Array [
26
- Object {
27
- "attrs": Object {
28
- "timestamp": "1502841600000",
29
- },
30
- "type": "date",
31
- },
32
- Object {
33
- "text": " ",
34
- "type": "text",
35
- },
36
- ],
37
- "type": "paragraph",
38
- },
39
- ],
40
- "type": "tableHeader",
41
- },
42
- Object {
43
- "attrs": Object {
44
- "background": null,
45
- "colspan": 1,
46
- "colwidth": null,
47
- "rowspan": 1,
48
- },
49
- "content": Array [
50
- Object {
51
- "type": "paragraph",
52
- },
53
- ],
54
- "type": "tableHeader",
55
- },
56
- Object {
57
- "attrs": Object {
58
- "background": null,
59
- "colspan": 1,
60
- "colwidth": null,
61
- "rowspan": 1,
62
- },
63
- "content": Array [
64
- Object {
65
- "type": "paragraph",
66
- },
67
- ],
68
- "type": "tableHeader",
69
- },
70
- ],
71
- "type": "tableRow",
72
- },
73
- Object {
74
- "content": Array [
75
- Object {
76
- "attrs": Object {
77
- "background": null,
78
- "colspan": 1,
79
- "colwidth": null,
80
- "rowspan": 1,
81
- },
82
- "content": Array [
83
- Object {
84
- "type": "paragraph",
85
- },
86
- ],
87
- "type": "tableCell",
88
- },
89
- Object {
90
- "attrs": Object {
91
- "background": null,
92
- "colspan": 1,
93
- "colwidth": null,
94
- "rowspan": 1,
95
- },
96
- "content": Array [
97
- Object {
98
- "type": "paragraph",
99
- },
100
- ],
101
- "type": "tableCell",
102
- },
103
- Object {
104
- "attrs": Object {
105
- "background": null,
106
- "colspan": 1,
107
- "colwidth": null,
108
- "rowspan": 1,
109
- },
110
- "content": Array [
111
- Object {
112
- "type": "paragraph",
113
- },
114
- ],
115
- "type": "tableCell",
116
- },
117
- ],
118
- "type": "tableRow",
119
- },
120
- Object {
121
- "content": Array [
122
- Object {
123
- "attrs": Object {
124
- "background": null,
125
- "colspan": 1,
126
- "colwidth": null,
127
- "rowspan": 1,
128
- },
129
- "content": Array [
130
- Object {
131
- "type": "paragraph",
132
- },
133
- ],
134
- "type": "tableCell",
135
- },
136
- Object {
137
- "attrs": Object {
138
- "background": null,
139
- "colspan": 1,
140
- "colwidth": null,
141
- "rowspan": 1,
142
- },
143
- "content": Array [
144
- Object {
145
- "type": "paragraph",
146
- },
147
- ],
148
- "type": "tableCell",
149
- },
150
- Object {
151
- "attrs": Object {
152
- "background": null,
153
- "colspan": 1,
154
- "colwidth": null,
155
- "rowspan": 1,
156
- },
157
- "content": Array [
158
- Object {
159
- "type": "paragraph",
160
- },
161
- ],
162
- "type": "tableCell",
163
- },
164
- ],
165
- "type": "tableRow",
166
- },
167
- ],
168
- "type": "table",
169
- },
170
- ],
171
- "type": "doc",
172
- }
173
- `;
@@ -1,46 +0,0 @@
1
- import {
2
- editable,
3
- fullpage,
4
- getDocFromElement,
5
- insertBlockMenuItem,
6
- quickInsert,
7
- } from '@atlaskit/editor-test-helpers/integration/helpers';
8
- import {
9
- goToEditorTestingWDExample,
10
- mountEditor,
11
- } from '@atlaskit/editor-test-helpers/testing-example-page';
12
- import { BrowserTestCase } from '@atlaskit/webdriver-runner/runner';
13
-
14
- const calendar = '[aria-label="calendar"]';
15
- const nextDate = 'button[aria-selected=true] + button';
16
-
17
- BrowserTestCase(
18
- 'change-date-inside-table.ts: Change date inside table',
19
- {},
20
- async (client: any, testName: string) => {
21
- const page = await goToEditorTestingWDExample(
22
- client,
23
- 'editor-plugin-table',
24
- );
25
- await mountEditor(page, {
26
- appearance: fullpage.appearance,
27
- allowDate: true,
28
- allowTables: {
29
- advanced: true,
30
- },
31
- });
32
-
33
- await page.click(editable);
34
-
35
- // Insert table
36
- await quickInsert(page, 'Table');
37
- // Insert Date
38
- await insertBlockMenuItem(page, 'Date');
39
- expect(await page.isExisting(calendar)).toBe(true);
40
-
41
- await page.click(nextDate);
42
-
43
- const doc = await page.$eval(editable, getDocFromElement);
44
- expect(doc).toMatchCustomDocSnapshot(testName);
45
- },
46
- );