@atlaskit/editor-plugin-table 2.12.3 → 2.12.4
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 +6 -0
- package/dist/cjs/plugins/table/index.js +3 -2
- package/dist/cjs/plugins/table/pm-plugins/table-width.js +42 -3
- package/dist/es2019/plugins/table/index.js +2 -1
- package/dist/es2019/plugins/table/pm-plugins/table-width.js +42 -3
- package/dist/esm/plugins/table/index.js +3 -2
- package/dist/esm/plugins/table/pm-plugins/table-width.js +42 -3
- package/dist/types/plugins/table/pm-plugins/table-width.d.ts +2 -1
- package/dist/types-ts4.5/plugins/table/pm-plugins/table-width.d.ts +2 -1
- package/package.json +1 -1
- package/src/plugins/table/index.tsx +2 -1
- package/src/plugins/table/pm-plugins/table-width.ts +52 -3
package/CHANGELOG.md
CHANGED
|
@@ -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
|
|
186
|
-
|
|
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',
|
|
@@ -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,
|
|
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 ===
|
|
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',
|
|
@@ -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,
|
|
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 ===
|
|
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
|
|
179
|
-
|
|
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',
|
|
@@ -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,
|
|
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 ===
|
|
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
|
@@ -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,
|
|
@@ -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 = (
|
|
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,
|
|
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 ===
|
|
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;
|