@atlaskit/editor-plugin-table 24.4.10 → 24.4.11
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 +10 -0
- package/dist/cjs/nodeviews/TableCell.js +12 -0
- package/dist/cjs/pm-plugins/active-cell-highlight/plugin.js +76 -23
- package/dist/cjs/tablePlugin.js +1 -1
- package/dist/es2019/nodeviews/TableCell.js +10 -0
- package/dist/es2019/pm-plugins/active-cell-highlight/plugin.js +68 -23
- package/dist/es2019/tablePlugin.js +1 -1
- package/dist/esm/nodeviews/TableCell.js +12 -0
- package/dist/esm/pm-plugins/active-cell-highlight/plugin.js +75 -23
- package/dist/esm/tablePlugin.js +1 -1
- package/dist/types/nodeviews/TableCell.d.ts +4 -0
- package/dist/types/pm-plugins/active-cell-highlight/plugin.d.ts +4 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-table
|
|
2
2
|
|
|
3
|
+
## 24.4.11
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`8bdbc5ba79617`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8bdbc5ba79617) -
|
|
8
|
+
[ux] Gate the table active cell decoration behind `platform_editor_table_q4_patch_3` so it is not
|
|
9
|
+
calculated or rendered until the editor has had its first interaction. Fix row control
|
|
10
|
+
mis-alignment issues.
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 24.4.10
|
|
4
14
|
|
|
5
15
|
### Patch Changes
|
|
@@ -110,6 +110,18 @@ var TableCell = exports.default = /*#__PURE__*/function (_TableNodeView) {
|
|
|
110
110
|
}
|
|
111
111
|
return didUpdate;
|
|
112
112
|
}
|
|
113
|
+
}, {
|
|
114
|
+
key: "ignoreMutation",
|
|
115
|
+
value: function ignoreMutation(mutation) {
|
|
116
|
+
var _mutation$attributeNa;
|
|
117
|
+
// `data-reaches-*` are presentation-only attrs written imperatively for the rounded-corner
|
|
118
|
+
// masks. Ignore them so ProseMirror doesn't rebuild the table (and drop the header row's
|
|
119
|
+
// sticky class) on every column insert.
|
|
120
|
+
if (mutation.type === 'attributes' && (_mutation$attributeNa = mutation.attributeName) !== null && _mutation$attributeNa !== void 0 && _mutation$attributeNa.startsWith('data-reaches-') && (0, _expValEquals.expValEquals)('platform_editor_table_q4_loveability', 'isEnabled', true) && (0, _expValEquals.expValEquals)('platform_editor_table_q4_patch_3', 'isEnabled', true)) {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
113
125
|
|
|
114
126
|
/**
|
|
115
127
|
* Detects whether this cell visually reaches the bottom or right edge of the table
|
|
@@ -1,15 +1,20 @@
|
|
|
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.createPlugin = exports.activeCellHighlightPluginKey = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
7
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
9
11
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
10
12
|
var _cellSelection = require("@atlaskit/editor-tables/cell-selection");
|
|
11
13
|
var _utils = require("@atlaskit/editor-tables/utils");
|
|
14
|
+
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
|
|
12
15
|
var _types = require("../../types");
|
|
16
|
+
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; }
|
|
17
|
+
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; }
|
|
13
18
|
var EMPTY_STATE = {
|
|
14
19
|
cellPos: -1,
|
|
15
20
|
decorationSet: _view.DecorationSet.empty
|
|
@@ -31,6 +36,8 @@ var getActiveCellPos = function getActiveCellPos(state) {
|
|
|
31
36
|
return -1;
|
|
32
37
|
}
|
|
33
38
|
};
|
|
39
|
+
|
|
40
|
+
/** Builds the decoration state highlighting the cell at `cellPos`. */
|
|
34
41
|
var buildState = function buildState(cellPos, state) {
|
|
35
42
|
if (cellPos === -1) {
|
|
36
43
|
return EMPTY_STATE;
|
|
@@ -51,31 +58,77 @@ var buildState = function buildState(cellPos, state) {
|
|
|
51
58
|
return EMPTY_STATE;
|
|
52
59
|
}
|
|
53
60
|
};
|
|
54
|
-
var
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
return buildState(nextCellPos, newState);
|
|
61
|
+
var hasHadInteraction = function hasHadInteraction(api) {
|
|
62
|
+
var _api$interaction$shar;
|
|
63
|
+
// The interaction plugin is optional - when absent, default to treating the editor as
|
|
64
|
+
// interacted.
|
|
65
|
+
if (!(api !== null && api !== void 0 && api.interaction)) {
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
return ((_api$interaction$shar = api.interaction.sharedState.currentState()) === null || _api$interaction$shar === void 0 ? void 0 : _api$interaction$shar.interactionState) !== 'hasNotHadInteraction';
|
|
69
|
+
};
|
|
70
|
+
var createLegacyStateField = function createLegacyStateField() {
|
|
71
|
+
return {
|
|
72
|
+
init: function init(_config, state) {
|
|
73
|
+
return buildState(getActiveCellPos(state), state);
|
|
74
|
+
},
|
|
75
|
+
apply: function apply(tr, prev, _oldState, newState) {
|
|
76
|
+
if (tr.docChanged) {
|
|
77
|
+
// Doc changed — always rebuild since positions may have shifted.
|
|
78
|
+
return buildState(getActiveCellPos(newState), newState);
|
|
79
|
+
}
|
|
80
|
+
if (!tr.selectionSet) {
|
|
81
|
+
// Neither doc nor selection changed — nothing to do.
|
|
82
|
+
return prev;
|
|
77
83
|
}
|
|
84
|
+
|
|
85
|
+
// Selection changed — only rebuild if the cursor moved to a different cell.
|
|
86
|
+
var nextCellPos = getActiveCellPos(newState);
|
|
87
|
+
return nextCellPos === prev.cellPos ? prev : buildState(nextCellPos, newState);
|
|
88
|
+
}
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Stays hidden until the first interaction
|
|
94
|
+
*/
|
|
95
|
+
var createGatedStateField = function createGatedStateField(api) {
|
|
96
|
+
return {
|
|
97
|
+
init: function init(_config, state) {
|
|
98
|
+
var interacted = hasHadInteraction(api);
|
|
99
|
+
return _objectSpread(_objectSpread({}, interacted ? buildState(getActiveCellPos(state), state) : EMPTY_STATE), {}, {
|
|
100
|
+
hasHadInteraction: interacted
|
|
101
|
+
});
|
|
78
102
|
},
|
|
103
|
+
apply: function apply(tr, prev, _oldState, newState) {
|
|
104
|
+
var interacted = hasHadInteraction(api);
|
|
105
|
+
|
|
106
|
+
// Keep the highlight hidden until the first interaction has happened.
|
|
107
|
+
if (!interacted) {
|
|
108
|
+
return prev;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// `true` only on the single transaction that crosses from "no interaction"
|
|
112
|
+
// to "interacted" — the meta-only transaction that reveals the highlight.
|
|
113
|
+
var isFirstInteraction = !prev.hasHadInteraction;
|
|
114
|
+
if (!tr.docChanged && !tr.selectionSet && !isFirstInteraction) {
|
|
115
|
+
// Doc, selection and interaction are all unchanged — nothing to do.
|
|
116
|
+
return prev;
|
|
117
|
+
}
|
|
118
|
+
var nextCellPos = getActiveCellPos(newState);
|
|
119
|
+
if (nextCellPos === prev.cellPos && !isFirstInteraction) {
|
|
120
|
+
return prev;
|
|
121
|
+
}
|
|
122
|
+
return _objectSpread(_objectSpread({}, buildState(nextCellPos, newState)), {}, {
|
|
123
|
+
hasHadInteraction: true
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
};
|
|
128
|
+
var createPlugin = exports.createPlugin = function createPlugin(api) {
|
|
129
|
+
return new _safePlugin.SafePlugin({
|
|
130
|
+
key: activeCellHighlightPluginKey,
|
|
131
|
+
state: (0, _expValEquals.expValEquals)('platform_editor_table_q4_patch_3', 'isEnabled', true) ? createGatedStateField(api) : createLegacyStateField(),
|
|
79
132
|
props: {
|
|
80
133
|
decorations: function decorations(state) {
|
|
81
134
|
var _activeCellHighlightP, _activeCellHighlightP2;
|
package/dist/cjs/tablePlugin.js
CHANGED
|
@@ -85,6 +85,16 @@ export default class TableCell extends TableNodeView {
|
|
|
85
85
|
}
|
|
86
86
|
return didUpdate;
|
|
87
87
|
}
|
|
88
|
+
ignoreMutation(mutation) {
|
|
89
|
+
var _mutation$attributeNa;
|
|
90
|
+
// `data-reaches-*` are presentation-only attrs written imperatively for the rounded-corner
|
|
91
|
+
// masks. Ignore them so ProseMirror doesn't rebuild the table (and drop the header row's
|
|
92
|
+
// sticky class) on every column insert.
|
|
93
|
+
if (mutation.type === 'attributes' && (_mutation$attributeNa = mutation.attributeName) !== null && _mutation$attributeNa !== void 0 && _mutation$attributeNa.startsWith('data-reaches-') && expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) && expValEquals('platform_editor_table_q4_patch_3', 'isEnabled', true)) {
|
|
94
|
+
return true;
|
|
95
|
+
}
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
88
98
|
|
|
89
99
|
/**
|
|
90
100
|
* Detects whether this cell visually reaches the bottom or right edge of the table
|
|
@@ -3,6 +3,7 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
3
3
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
4
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
5
5
|
import { findCellClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
6
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
7
|
import { TableCssClassName as ClassName } from '../../types';
|
|
7
8
|
const EMPTY_STATE = {
|
|
8
9
|
cellPos: -1,
|
|
@@ -25,6 +26,8 @@ const getActiveCellPos = state => {
|
|
|
25
26
|
return -1;
|
|
26
27
|
}
|
|
27
28
|
};
|
|
29
|
+
|
|
30
|
+
/** Builds the decoration state highlighting the cell at `cellPos`. */
|
|
28
31
|
const buildState = (cellPos, state) => {
|
|
29
32
|
if (cellPos === -1) {
|
|
30
33
|
return EMPTY_STATE;
|
|
@@ -45,31 +48,73 @@ const buildState = (cellPos, state) => {
|
|
|
45
48
|
return EMPTY_STATE;
|
|
46
49
|
}
|
|
47
50
|
};
|
|
48
|
-
|
|
51
|
+
const hasHadInteraction = api => {
|
|
52
|
+
var _api$interaction$shar;
|
|
53
|
+
// The interaction plugin is optional - when absent, default to treating the editor as
|
|
54
|
+
// interacted.
|
|
55
|
+
if (!(api !== null && api !== void 0 && api.interaction)) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
return ((_api$interaction$shar = api.interaction.sharedState.currentState()) === null || _api$interaction$shar === void 0 ? void 0 : _api$interaction$shar.interactionState) !== 'hasNotHadInteraction';
|
|
59
|
+
};
|
|
60
|
+
const createLegacyStateField = () => ({
|
|
61
|
+
init: (_config, state) => buildState(getActiveCellPos(state), state),
|
|
62
|
+
apply: (tr, prev, _oldState, newState) => {
|
|
63
|
+
if (tr.docChanged) {
|
|
64
|
+
// Doc changed — always rebuild since positions may have shifted.
|
|
65
|
+
return buildState(getActiveCellPos(newState), newState);
|
|
66
|
+
}
|
|
67
|
+
if (!tr.selectionSet) {
|
|
68
|
+
// Neither doc nor selection changed — nothing to do.
|
|
69
|
+
return prev;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
// Selection changed — only rebuild if the cursor moved to a different cell.
|
|
73
|
+
const nextCellPos = getActiveCellPos(newState);
|
|
74
|
+
return nextCellPos === prev.cellPos ? prev : buildState(nextCellPos, newState);
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Stays hidden until the first interaction
|
|
80
|
+
*/
|
|
81
|
+
const createGatedStateField = api => ({
|
|
82
|
+
init: (_config, state) => {
|
|
83
|
+
const interacted = hasHadInteraction(api);
|
|
84
|
+
return {
|
|
85
|
+
...(interacted ? buildState(getActiveCellPos(state), state) : EMPTY_STATE),
|
|
86
|
+
hasHadInteraction: interacted
|
|
87
|
+
};
|
|
88
|
+
},
|
|
89
|
+
apply: (tr, prev, _oldState, newState) => {
|
|
90
|
+
const interacted = hasHadInteraction(api);
|
|
91
|
+
|
|
92
|
+
// Keep the highlight hidden until the first interaction has happened.
|
|
93
|
+
if (!interacted) {
|
|
94
|
+
return prev;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// `true` only on the single transaction that crosses from "no interaction"
|
|
98
|
+
// to "interacted" — the meta-only transaction that reveals the highlight.
|
|
99
|
+
const isFirstInteraction = !prev.hasHadInteraction;
|
|
100
|
+
if (!tr.docChanged && !tr.selectionSet && !isFirstInteraction) {
|
|
101
|
+
// Doc, selection and interaction are all unchanged — nothing to do.
|
|
102
|
+
return prev;
|
|
103
|
+
}
|
|
104
|
+
const nextCellPos = getActiveCellPos(newState);
|
|
105
|
+
if (nextCellPos === prev.cellPos && !isFirstInteraction) {
|
|
106
|
+
return prev;
|
|
107
|
+
}
|
|
108
|
+
return {
|
|
109
|
+
...buildState(nextCellPos, newState),
|
|
110
|
+
hasHadInteraction: true
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
export const createPlugin = api => {
|
|
49
115
|
return new SafePlugin({
|
|
50
116
|
key: activeCellHighlightPluginKey,
|
|
51
|
-
state:
|
|
52
|
-
init: (_, state) => {
|
|
53
|
-
return buildState(getActiveCellPos(state), state);
|
|
54
|
-
},
|
|
55
|
-
apply: (tr, prev, _oldState, newState) => {
|
|
56
|
-
if (tr.docChanged) {
|
|
57
|
-
// Doc changed — always rebuild since positions may have shifted
|
|
58
|
-
return buildState(getActiveCellPos(newState), newState);
|
|
59
|
-
}
|
|
60
|
-
if (!tr.selectionSet) {
|
|
61
|
-
// Neither doc nor selection changed — nothing to do
|
|
62
|
-
return prev;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Selection changed — only rebuild if cursor moved to a different cell
|
|
66
|
-
const nextCellPos = getActiveCellPos(newState);
|
|
67
|
-
if (nextCellPos === prev.cellPos) {
|
|
68
|
-
return prev;
|
|
69
|
-
}
|
|
70
|
-
return buildState(nextCellPos, newState);
|
|
71
|
-
}
|
|
72
|
-
},
|
|
117
|
+
state: expValEquals('platform_editor_table_q4_patch_3', 'isEnabled', true) ? createGatedStateField(api) : createLegacyStateField(),
|
|
73
118
|
props: {
|
|
74
119
|
decorations: state => {
|
|
75
120
|
var _activeCellHighlightP, _activeCellHighlightP2;
|
|
@@ -496,7 +496,7 @@ const tablePlugin = ({
|
|
|
496
496
|
if (expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true)) {
|
|
497
497
|
plugins.push({
|
|
498
498
|
name: 'tableActiveCellHighlight',
|
|
499
|
-
plugin: () => createActiveCellHighlightPlugin()
|
|
499
|
+
plugin: () => createActiveCellHighlightPlugin(api)
|
|
500
500
|
});
|
|
501
501
|
}
|
|
502
502
|
const browser = getBrowserInfo();
|
|
@@ -103,6 +103,18 @@ var TableCell = /*#__PURE__*/function (_TableNodeView) {
|
|
|
103
103
|
}
|
|
104
104
|
return didUpdate;
|
|
105
105
|
}
|
|
106
|
+
}, {
|
|
107
|
+
key: "ignoreMutation",
|
|
108
|
+
value: function ignoreMutation(mutation) {
|
|
109
|
+
var _mutation$attributeNa;
|
|
110
|
+
// `data-reaches-*` are presentation-only attrs written imperatively for the rounded-corner
|
|
111
|
+
// masks. Ignore them so ProseMirror doesn't rebuild the table (and drop the header row's
|
|
112
|
+
// sticky class) on every column insert.
|
|
113
|
+
if (mutation.type === 'attributes' && (_mutation$attributeNa = mutation.attributeName) !== null && _mutation$attributeNa !== void 0 && _mutation$attributeNa.startsWith('data-reaches-') && expValEquals('platform_editor_table_q4_loveability', 'isEnabled', true) && expValEquals('platform_editor_table_q4_patch_3', 'isEnabled', true)) {
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
106
118
|
|
|
107
119
|
/**
|
|
108
120
|
* Detects whether this cell visually reaches the bottom or right edge of the table
|
|
@@ -1,8 +1,12 @@
|
|
|
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; }
|
|
1
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
6
|
import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
7
|
import { CellSelection } from '@atlaskit/editor-tables/cell-selection';
|
|
5
8
|
import { findCellClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
9
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
6
10
|
import { TableCssClassName as ClassName } from '../../types';
|
|
7
11
|
var EMPTY_STATE = {
|
|
8
12
|
cellPos: -1,
|
|
@@ -25,6 +29,8 @@ var getActiveCellPos = function getActiveCellPos(state) {
|
|
|
25
29
|
return -1;
|
|
26
30
|
}
|
|
27
31
|
};
|
|
32
|
+
|
|
33
|
+
/** Builds the decoration state highlighting the cell at `cellPos`. */
|
|
28
34
|
var buildState = function buildState(cellPos, state) {
|
|
29
35
|
if (cellPos === -1) {
|
|
30
36
|
return EMPTY_STATE;
|
|
@@ -45,31 +51,77 @@ var buildState = function buildState(cellPos, state) {
|
|
|
45
51
|
return EMPTY_STATE;
|
|
46
52
|
}
|
|
47
53
|
};
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return buildState(nextCellPos, newState);
|
|
54
|
+
var hasHadInteraction = function hasHadInteraction(api) {
|
|
55
|
+
var _api$interaction$shar;
|
|
56
|
+
// The interaction plugin is optional - when absent, default to treating the editor as
|
|
57
|
+
// interacted.
|
|
58
|
+
if (!(api !== null && api !== void 0 && api.interaction)) {
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
61
|
+
return ((_api$interaction$shar = api.interaction.sharedState.currentState()) === null || _api$interaction$shar === void 0 ? void 0 : _api$interaction$shar.interactionState) !== 'hasNotHadInteraction';
|
|
62
|
+
};
|
|
63
|
+
var createLegacyStateField = function createLegacyStateField() {
|
|
64
|
+
return {
|
|
65
|
+
init: function init(_config, state) {
|
|
66
|
+
return buildState(getActiveCellPos(state), state);
|
|
67
|
+
},
|
|
68
|
+
apply: function apply(tr, prev, _oldState, newState) {
|
|
69
|
+
if (tr.docChanged) {
|
|
70
|
+
// Doc changed — always rebuild since positions may have shifted.
|
|
71
|
+
return buildState(getActiveCellPos(newState), newState);
|
|
72
|
+
}
|
|
73
|
+
if (!tr.selectionSet) {
|
|
74
|
+
// Neither doc nor selection changed — nothing to do.
|
|
75
|
+
return prev;
|
|
71
76
|
}
|
|
77
|
+
|
|
78
|
+
// Selection changed — only rebuild if the cursor moved to a different cell.
|
|
79
|
+
var nextCellPos = getActiveCellPos(newState);
|
|
80
|
+
return nextCellPos === prev.cellPos ? prev : buildState(nextCellPos, newState);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Stays hidden until the first interaction
|
|
87
|
+
*/
|
|
88
|
+
var createGatedStateField = function createGatedStateField(api) {
|
|
89
|
+
return {
|
|
90
|
+
init: function init(_config, state) {
|
|
91
|
+
var interacted = hasHadInteraction(api);
|
|
92
|
+
return _objectSpread(_objectSpread({}, interacted ? buildState(getActiveCellPos(state), state) : EMPTY_STATE), {}, {
|
|
93
|
+
hasHadInteraction: interacted
|
|
94
|
+
});
|
|
72
95
|
},
|
|
96
|
+
apply: function apply(tr, prev, _oldState, newState) {
|
|
97
|
+
var interacted = hasHadInteraction(api);
|
|
98
|
+
|
|
99
|
+
// Keep the highlight hidden until the first interaction has happened.
|
|
100
|
+
if (!interacted) {
|
|
101
|
+
return prev;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// `true` only on the single transaction that crosses from "no interaction"
|
|
105
|
+
// to "interacted" — the meta-only transaction that reveals the highlight.
|
|
106
|
+
var isFirstInteraction = !prev.hasHadInteraction;
|
|
107
|
+
if (!tr.docChanged && !tr.selectionSet && !isFirstInteraction) {
|
|
108
|
+
// Doc, selection and interaction are all unchanged — nothing to do.
|
|
109
|
+
return prev;
|
|
110
|
+
}
|
|
111
|
+
var nextCellPos = getActiveCellPos(newState);
|
|
112
|
+
if (nextCellPos === prev.cellPos && !isFirstInteraction) {
|
|
113
|
+
return prev;
|
|
114
|
+
}
|
|
115
|
+
return _objectSpread(_objectSpread({}, buildState(nextCellPos, newState)), {}, {
|
|
116
|
+
hasHadInteraction: true
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
export var createPlugin = function createPlugin(api) {
|
|
122
|
+
return new SafePlugin({
|
|
123
|
+
key: activeCellHighlightPluginKey,
|
|
124
|
+
state: expValEquals('platform_editor_table_q4_patch_3', 'isEnabled', true) ? createGatedStateField(api) : createLegacyStateField(),
|
|
73
125
|
props: {
|
|
74
126
|
decorations: function decorations(state) {
|
|
75
127
|
var _activeCellHighlightP, _activeCellHighlightP2;
|
package/dist/esm/tablePlugin.js
CHANGED
|
@@ -8,6 +8,10 @@ export default class TableCell extends TableNodeView<HTMLElement> implements Nod
|
|
|
8
8
|
constructor(node: PMNode, view: EditorView, getPos: () => number | undefined, eventDispatcher: EventDispatcher, editorAnalyticsAPI: EditorAnalyticsAPI | undefined);
|
|
9
9
|
destroy: () => void;
|
|
10
10
|
update(node: PMNode): boolean;
|
|
11
|
+
ignoreMutation(mutation: MutationRecord | {
|
|
12
|
+
target: Node;
|
|
13
|
+
type: 'selection';
|
|
14
|
+
}): boolean;
|
|
11
15
|
/**
|
|
12
16
|
* Detects whether this cell visually reaches the bottom or right edge of the table
|
|
13
17
|
* (accounting for rowspan/colspan) and sets data attributes so CSS can apply
|
|
@@ -1,11 +1,14 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
4
|
+
import type { PluginInjectionAPI } from '../../types';
|
|
4
5
|
interface ActiveCellHighlightState {
|
|
5
6
|
/** Position of the currently highlighted cell, or -1 if none */
|
|
6
7
|
cellPos: number;
|
|
7
8
|
decorationSet: DecorationSet;
|
|
9
|
+
/** Whether the editor has had its first interaction. */
|
|
10
|
+
hasHadInteraction?: boolean;
|
|
8
11
|
}
|
|
9
12
|
export declare const activeCellHighlightPluginKey: PluginKey<ActiveCellHighlightState>;
|
|
10
|
-
export declare const createPlugin: () => SafePlugin<ActiveCellHighlightState>;
|
|
13
|
+
export declare const createPlugin: (api?: PluginInjectionAPI) => SafePlugin<ActiveCellHighlightState>;
|
|
11
14
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-table",
|
|
3
|
-
"version": "24.4.
|
|
3
|
+
"version": "24.4.11",
|
|
4
4
|
"description": "Table plugin for the @atlaskit/editor",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@atlaskit/pragmatic-drag-and-drop-auto-scroll": "^3.0.0",
|
|
53
53
|
"@atlaskit/pragmatic-drag-and-drop-hitbox": "^2.0.0",
|
|
54
54
|
"@atlaskit/primitives": "^22.0.0",
|
|
55
|
-
"@atlaskit/tmp-editor-statsig": "^126.
|
|
55
|
+
"@atlaskit/tmp-editor-statsig": "^126.4.0",
|
|
56
56
|
"@atlaskit/toggle": "^17.1.0",
|
|
57
57
|
"@atlaskit/tokens": "^16.0.0",
|
|
58
58
|
"@atlaskit/tooltip": "^23.1.0",
|