@atlaskit/editor-plugin-ufo 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/LICENSE.md +11 -0
- package/README.md +1 -0
- package/afm-cc/tsconfig.json +30 -0
- package/build/tsconfig.json +17 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/pm-plugins/disableTTVCOnFirstUserInteraction.js +75 -0
- package/dist/cjs/ufoPlugin.js +22 -0
- package/dist/cjs/ufoPluginType.js +5 -0
- package/dist/es2019/index.js +3 -0
- package/dist/es2019/pm-plugins/disableTTVCOnFirstUserInteraction.js +69 -0
- package/dist/es2019/ufoPlugin.js +14 -0
- package/dist/es2019/ufoPluginType.js +1 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/pm-plugins/disableTTVCOnFirstUserInteraction.js +68 -0
- package/dist/esm/ufoPlugin.js +16 -0
- package/dist/esm/ufoPluginType.js +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/pm-plugins/disableTTVCOnFirstUserInteraction.d.ts +2 -0
- package/dist/types/ufoPlugin.d.ts +2 -0
- package/dist/types/ufoPluginType.d.ts +2 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/disableTTVCOnFirstUserInteraction.d.ts +2 -0
- package/dist/types-ts4.5/ufoPlugin.d.ts +2 -0
- package/dist/types-ts4.5/ufoPluginType.d.ts +2 -0
- package/package.json +88 -0
- package/src/index.ts +4 -0
- package/src/pm-plugins/disableTTVCOnFirstUserInteraction.ts +110 -0
- package/src/ufoPlugin.tsx +21 -0
- package/src/ufoPluginType.ts +3 -0
- package/tsconfig.json +10 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# @atlaskit/editor-plugin-ufo
|
|
2
|
+
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- [#178022](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/178022)
|
|
8
|
+
[`34c30d3598c59`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/34c30d3598c59) -
|
|
9
|
+
[ED-25936] Editor Plugin to abort UFO TTVC on user interaction
|
package/LICENSE.md
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
Copyright 2019 Atlassian Pty Ltd
|
|
2
|
+
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
|
4
|
+
compliance with the License. You may obtain a copy of the License at
|
|
5
|
+
|
|
6
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
7
|
+
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
9
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
10
|
+
implied. See the License for the specific language governing permissions and limitations under the
|
|
11
|
+
License.
|
package/README.md
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Editor plugin ufo
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../../../../tsconfig.entry-points.confluence.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"composite": true,
|
|
6
|
+
"outDir": "../dist",
|
|
7
|
+
"rootDir": "../"
|
|
8
|
+
},
|
|
9
|
+
"include": [
|
|
10
|
+
"../src/**/*.ts",
|
|
11
|
+
"../src/**/*.tsx"
|
|
12
|
+
],
|
|
13
|
+
"exclude": [
|
|
14
|
+
"../src/**/__tests__/*",
|
|
15
|
+
"../src/**/*.test.*",
|
|
16
|
+
"../src/**/test.*",
|
|
17
|
+
"../src/**/examples.*"
|
|
18
|
+
],
|
|
19
|
+
"references": [
|
|
20
|
+
{
|
|
21
|
+
"path": "../../editor-common/afm-cc/tsconfig.json"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
"path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
"path": "../../../react-ufo/atlaskit/afm-cc/tsconfig.json"
|
|
28
|
+
}
|
|
29
|
+
]
|
|
30
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"extends": "../tsconfig",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"target": "es5",
|
|
5
|
+
"paths": {}
|
|
6
|
+
},
|
|
7
|
+
"include": [
|
|
8
|
+
"../src/**/*.ts",
|
|
9
|
+
"../src/**/*.tsx"
|
|
10
|
+
],
|
|
11
|
+
"exclude": [
|
|
12
|
+
"../src/**/__tests__/*",
|
|
13
|
+
"../src/**/*.test.*",
|
|
14
|
+
"../src/**/test.*",
|
|
15
|
+
"../src/**/examples.*"
|
|
16
|
+
]
|
|
17
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "ufoPlugin", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _ufoPlugin.ufoPlugin;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _ufoPlugin = require("./ufoPlugin");
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.disableTTVCOnFirstUserInteraction = void 0;
|
|
7
|
+
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
8
|
+
var _vc = require("@atlaskit/react-ufo/vc");
|
|
9
|
+
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners */
|
|
10
|
+
|
|
11
|
+
function bind(target, event, controller, listener) {
|
|
12
|
+
// Safe check for rare cases where window doesn't exist
|
|
13
|
+
if (!target || typeof target.addEventListener !== 'function') {
|
|
14
|
+
return function () {};
|
|
15
|
+
}
|
|
16
|
+
var options = {
|
|
17
|
+
capture: true,
|
|
18
|
+
passive: true,
|
|
19
|
+
once: true,
|
|
20
|
+
signal: controller.signal
|
|
21
|
+
};
|
|
22
|
+
target.addEventListener(event, listener, options);
|
|
23
|
+
return function unbind() {
|
|
24
|
+
target.removeEventListener(event, listener, options);
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
var AbortEvent = ['wheel', 'keydown', 'mousedown', 'pointerdown', 'pointerup', 'touchend', 'scroll', 'mouseover'];
|
|
28
|
+
var ttvcAbort = function ttvcAbort() {
|
|
29
|
+
var vc = (0, _vc.getVCObserver)();
|
|
30
|
+
if (!vc ||
|
|
31
|
+
// For reasons that goes beyond my understand,
|
|
32
|
+
// the type is not properly set.
|
|
33
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
34
|
+
// @ts-expect-error
|
|
35
|
+
typeof vc.abortCalculation !== 'function') {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// For reasons that goes beyond my understand,
|
|
40
|
+
// the type is not properly set.
|
|
41
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
42
|
+
// @ts-expect-error
|
|
43
|
+
vc.abortCalculation();
|
|
44
|
+
};
|
|
45
|
+
var disableTTVCOnFirstUserInteraction = exports.disableTTVCOnFirstUserInteraction = function disableTTVCOnFirstUserInteraction() {
|
|
46
|
+
var unbindCallbacks = new Set();
|
|
47
|
+
var controller = new AbortController();
|
|
48
|
+
var unbindFirstInteractionEvents = function unbindFirstInteractionEvents() {
|
|
49
|
+
controller.abort();
|
|
50
|
+
unbindCallbacks.forEach(function (cb) {
|
|
51
|
+
cb();
|
|
52
|
+
});
|
|
53
|
+
unbindCallbacks.clear();
|
|
54
|
+
};
|
|
55
|
+
return new _safePlugin.SafePlugin({
|
|
56
|
+
view: function view(_view) {
|
|
57
|
+
if (!_view || !_view.dom) {
|
|
58
|
+
return {};
|
|
59
|
+
}
|
|
60
|
+
var dom = _view.dom;
|
|
61
|
+
for (var _i = 0, _AbortEvent = AbortEvent; _i < _AbortEvent.length; _i++) {
|
|
62
|
+
var abortEventName = _AbortEvent[_i];
|
|
63
|
+
unbindCallbacks.add(bind(dom, abortEventName, controller, function () {
|
|
64
|
+
ttvcAbort();
|
|
65
|
+
unbindFirstInteractionEvents();
|
|
66
|
+
}));
|
|
67
|
+
}
|
|
68
|
+
return {
|
|
69
|
+
destroy: function destroy() {
|
|
70
|
+
unbindFirstInteractionEvents();
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ufoPlugin = void 0;
|
|
7
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
8
|
+
var _disableTTVCOnFirstUserInteraction = require("./pm-plugins/disableTTVCOnFirstUserInteraction");
|
|
9
|
+
var ufoPlugin = exports.ufoPlugin = function ufoPlugin() {
|
|
10
|
+
return {
|
|
11
|
+
name: 'ufo',
|
|
12
|
+
pmPlugins: function pmPlugins() {
|
|
13
|
+
if (!(0, _platformFeatureFlags.fg)('platform_editor_abort_ttvc_on_user_interaction')) {
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
return [{
|
|
17
|
+
name: 'disableTTVCOnFirstUserInteraction',
|
|
18
|
+
plugin: _disableTTVCOnFirstUserInteraction.disableTTVCOnFirstUserInteraction
|
|
19
|
+
}];
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners */
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { getVCObserver } from '@atlaskit/react-ufo/vc';
|
|
4
|
+
function bind(target, event, controller, listener) {
|
|
5
|
+
// Safe check for rare cases where window doesn't exist
|
|
6
|
+
if (!target || typeof target.addEventListener !== 'function') {
|
|
7
|
+
return () => {};
|
|
8
|
+
}
|
|
9
|
+
const options = {
|
|
10
|
+
capture: true,
|
|
11
|
+
passive: true,
|
|
12
|
+
once: true,
|
|
13
|
+
signal: controller.signal
|
|
14
|
+
};
|
|
15
|
+
target.addEventListener(event, listener, options);
|
|
16
|
+
return function unbind() {
|
|
17
|
+
target.removeEventListener(event, listener, options);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
const AbortEvent = ['wheel', 'keydown', 'mousedown', 'pointerdown', 'pointerup', 'touchend', 'scroll', 'mouseover'];
|
|
21
|
+
const ttvcAbort = () => {
|
|
22
|
+
const vc = getVCObserver();
|
|
23
|
+
if (!vc ||
|
|
24
|
+
// For reasons that goes beyond my understand,
|
|
25
|
+
// the type is not properly set.
|
|
26
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
typeof vc.abortCalculation !== 'function') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// For reasons that goes beyond my understand,
|
|
33
|
+
// the type is not properly set.
|
|
34
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
vc.abortCalculation();
|
|
37
|
+
};
|
|
38
|
+
export const disableTTVCOnFirstUserInteraction = () => {
|
|
39
|
+
const unbindCallbacks = new Set();
|
|
40
|
+
const controller = new AbortController();
|
|
41
|
+
const unbindFirstInteractionEvents = () => {
|
|
42
|
+
controller.abort();
|
|
43
|
+
unbindCallbacks.forEach(cb => {
|
|
44
|
+
cb();
|
|
45
|
+
});
|
|
46
|
+
unbindCallbacks.clear();
|
|
47
|
+
};
|
|
48
|
+
return new SafePlugin({
|
|
49
|
+
view(view) {
|
|
50
|
+
if (!view || !view.dom) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
const {
|
|
54
|
+
dom
|
|
55
|
+
} = view;
|
|
56
|
+
for (let abortEventName of AbortEvent) {
|
|
57
|
+
unbindCallbacks.add(bind(dom, abortEventName, controller, () => {
|
|
58
|
+
ttvcAbort();
|
|
59
|
+
unbindFirstInteractionEvents();
|
|
60
|
+
}));
|
|
61
|
+
}
|
|
62
|
+
return {
|
|
63
|
+
destroy: () => {
|
|
64
|
+
unbindFirstInteractionEvents();
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { disableTTVCOnFirstUserInteraction } from './pm-plugins/disableTTVCOnFirstUserInteraction';
|
|
3
|
+
export const ufoPlugin = () => ({
|
|
4
|
+
name: 'ufo',
|
|
5
|
+
pmPlugins() {
|
|
6
|
+
if (!fg('platform_editor_abort_ttvc_on_user_interaction')) {
|
|
7
|
+
return [];
|
|
8
|
+
}
|
|
9
|
+
return [{
|
|
10
|
+
name: 'disableTTVCOnFirstUserInteraction',
|
|
11
|
+
plugin: disableTTVCOnFirstUserInteraction
|
|
12
|
+
}];
|
|
13
|
+
}
|
|
14
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners */
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { getVCObserver } from '@atlaskit/react-ufo/vc';
|
|
4
|
+
function bind(target, event, controller, listener) {
|
|
5
|
+
// Safe check for rare cases where window doesn't exist
|
|
6
|
+
if (!target || typeof target.addEventListener !== 'function') {
|
|
7
|
+
return function () {};
|
|
8
|
+
}
|
|
9
|
+
var options = {
|
|
10
|
+
capture: true,
|
|
11
|
+
passive: true,
|
|
12
|
+
once: true,
|
|
13
|
+
signal: controller.signal
|
|
14
|
+
};
|
|
15
|
+
target.addEventListener(event, listener, options);
|
|
16
|
+
return function unbind() {
|
|
17
|
+
target.removeEventListener(event, listener, options);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
var AbortEvent = ['wheel', 'keydown', 'mousedown', 'pointerdown', 'pointerup', 'touchend', 'scroll', 'mouseover'];
|
|
21
|
+
var ttvcAbort = function ttvcAbort() {
|
|
22
|
+
var vc = getVCObserver();
|
|
23
|
+
if (!vc ||
|
|
24
|
+
// For reasons that goes beyond my understand,
|
|
25
|
+
// the type is not properly set.
|
|
26
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
27
|
+
// @ts-expect-error
|
|
28
|
+
typeof vc.abortCalculation !== 'function') {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// For reasons that goes beyond my understand,
|
|
33
|
+
// the type is not properly set.
|
|
34
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
vc.abortCalculation();
|
|
37
|
+
};
|
|
38
|
+
export var disableTTVCOnFirstUserInteraction = function disableTTVCOnFirstUserInteraction() {
|
|
39
|
+
var unbindCallbacks = new Set();
|
|
40
|
+
var controller = new AbortController();
|
|
41
|
+
var unbindFirstInteractionEvents = function unbindFirstInteractionEvents() {
|
|
42
|
+
controller.abort();
|
|
43
|
+
unbindCallbacks.forEach(function (cb) {
|
|
44
|
+
cb();
|
|
45
|
+
});
|
|
46
|
+
unbindCallbacks.clear();
|
|
47
|
+
};
|
|
48
|
+
return new SafePlugin({
|
|
49
|
+
view: function view(_view) {
|
|
50
|
+
if (!_view || !_view.dom) {
|
|
51
|
+
return {};
|
|
52
|
+
}
|
|
53
|
+
var dom = _view.dom;
|
|
54
|
+
for (var _i = 0, _AbortEvent = AbortEvent; _i < _AbortEvent.length; _i++) {
|
|
55
|
+
var abortEventName = _AbortEvent[_i];
|
|
56
|
+
unbindCallbacks.add(bind(dom, abortEventName, controller, function () {
|
|
57
|
+
ttvcAbort();
|
|
58
|
+
unbindFirstInteractionEvents();
|
|
59
|
+
}));
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
destroy: function destroy() {
|
|
63
|
+
unbindFirstInteractionEvents();
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
import { disableTTVCOnFirstUserInteraction } from './pm-plugins/disableTTVCOnFirstUserInteraction';
|
|
3
|
+
export var ufoPlugin = function ufoPlugin() {
|
|
4
|
+
return {
|
|
5
|
+
name: 'ufo',
|
|
6
|
+
pmPlugins: function pmPlugins() {
|
|
7
|
+
if (!fg('platform_editor_abort_ttvc_on_user_interaction')) {
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
return [{
|
|
11
|
+
name: 'disableTTVCOnFirstUserInteraction',
|
|
12
|
+
plugin: disableTTVCOnFirstUserInteraction
|
|
13
|
+
}];
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/editor-plugin-ufo",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Ufo plugin for @atlaskit/editor-core",
|
|
5
|
+
"author": "Atlassian Pty Ltd",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"publishConfig": {
|
|
8
|
+
"registry": "https://registry.npmjs.org/"
|
|
9
|
+
},
|
|
10
|
+
"atlassian": {
|
|
11
|
+
"team": "Editor: Lego",
|
|
12
|
+
"releaseModel": "continuous",
|
|
13
|
+
"singleton": true,
|
|
14
|
+
"runReact18": true
|
|
15
|
+
},
|
|
16
|
+
"repository": "https://bitbucket.org/atlassian/atlassian-frontend-mirror",
|
|
17
|
+
"main": "dist/cjs/index.js",
|
|
18
|
+
"module": "dist/esm/index.js",
|
|
19
|
+
"module:es2019": "dist/es2019/index.js",
|
|
20
|
+
"types": "dist/types/index.d.ts",
|
|
21
|
+
"typesVersions": {
|
|
22
|
+
">=4.5 <4.9": {
|
|
23
|
+
"*": [
|
|
24
|
+
"dist/types-ts4.5/*",
|
|
25
|
+
"dist/types-ts4.5/index.d.ts"
|
|
26
|
+
]
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"sideEffects": false,
|
|
30
|
+
"atlaskit:src": "src/index.ts",
|
|
31
|
+
"af:exports": {
|
|
32
|
+
".": "./src/index.ts"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@atlaskit/editor-common": "^96.5.0",
|
|
36
|
+
"@atlaskit/editor-prosemirror": "6.2.1",
|
|
37
|
+
"@atlaskit/platform-feature-flags": "^0.3.0",
|
|
38
|
+
"@atlaskit/react-ufo": "^2.5.0",
|
|
39
|
+
"@babel/runtime": "^7.0.0"
|
|
40
|
+
},
|
|
41
|
+
"peerDependencies": {
|
|
42
|
+
"react": "^16.8.0 || ^17.0.0 || ~18.2.0"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"typescript": "~5.4.2"
|
|
46
|
+
},
|
|
47
|
+
"techstack": {
|
|
48
|
+
"@atlassian/frontend": {
|
|
49
|
+
"code-structure": [
|
|
50
|
+
"editor-plugin"
|
|
51
|
+
],
|
|
52
|
+
"import-structure": [
|
|
53
|
+
"atlassian-conventions"
|
|
54
|
+
],
|
|
55
|
+
"circular-dependencies": [
|
|
56
|
+
"file-and-folder-level"
|
|
57
|
+
]
|
|
58
|
+
},
|
|
59
|
+
"@repo/internal": {
|
|
60
|
+
"dom-events": "use-bind-event-listener",
|
|
61
|
+
"analytics": [
|
|
62
|
+
"analytics-next"
|
|
63
|
+
],
|
|
64
|
+
"design-tokens": [
|
|
65
|
+
"color"
|
|
66
|
+
],
|
|
67
|
+
"theming": [
|
|
68
|
+
"react-context"
|
|
69
|
+
],
|
|
70
|
+
"ui-components": [
|
|
71
|
+
"lite-mode"
|
|
72
|
+
],
|
|
73
|
+
"deprecation": "no-deprecated-imports",
|
|
74
|
+
"styling": [
|
|
75
|
+
"emotion",
|
|
76
|
+
"emotion"
|
|
77
|
+
],
|
|
78
|
+
"imports": [
|
|
79
|
+
"import-no-extraneous-disable-for-examples-and-docs"
|
|
80
|
+
]
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
"platform-feature-flags": {
|
|
84
|
+
"platform_editor_abort_ttvc_on_user_interaction": {
|
|
85
|
+
"type": "boolean"
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
/* eslint-disable @repo/internal/dom-events/no-unsafe-event-listeners */
|
|
2
|
+
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
3
|
+
import { getVCObserver } from '@atlaskit/react-ufo/vc';
|
|
4
|
+
|
|
5
|
+
function bind(
|
|
6
|
+
target: HTMLElement,
|
|
7
|
+
event: FirstUserInteractionEvents,
|
|
8
|
+
controller: AbortController,
|
|
9
|
+
listener: () => void,
|
|
10
|
+
) {
|
|
11
|
+
// Safe check for rare cases where window doesn't exist
|
|
12
|
+
if (!target || typeof target.addEventListener !== 'function') {
|
|
13
|
+
return () => {};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const options = {
|
|
17
|
+
capture: true,
|
|
18
|
+
passive: true,
|
|
19
|
+
once: true,
|
|
20
|
+
signal: controller.signal,
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
target.addEventListener(event, listener, options);
|
|
24
|
+
|
|
25
|
+
return function unbind() {
|
|
26
|
+
target.removeEventListener(event, listener, options);
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
type FirstUserInteractionEvents =
|
|
31
|
+
| 'wheel'
|
|
32
|
+
| 'keydown'
|
|
33
|
+
| 'mousedown'
|
|
34
|
+
| 'pointerdown'
|
|
35
|
+
| 'pointerup'
|
|
36
|
+
| 'touchend'
|
|
37
|
+
| 'scroll'
|
|
38
|
+
| 'mouseover';
|
|
39
|
+
|
|
40
|
+
const AbortEvent: ReadonlyArray<FirstUserInteractionEvents> = [
|
|
41
|
+
'wheel',
|
|
42
|
+
'keydown',
|
|
43
|
+
'mousedown',
|
|
44
|
+
'pointerdown',
|
|
45
|
+
'pointerup',
|
|
46
|
+
'touchend',
|
|
47
|
+
'scroll',
|
|
48
|
+
'mouseover',
|
|
49
|
+
];
|
|
50
|
+
|
|
51
|
+
const ttvcAbort = () => {
|
|
52
|
+
const vc = getVCObserver();
|
|
53
|
+
|
|
54
|
+
if (
|
|
55
|
+
!vc ||
|
|
56
|
+
// For reasons that goes beyond my understand,
|
|
57
|
+
// the type is not properly set.
|
|
58
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
59
|
+
// @ts-expect-error
|
|
60
|
+
typeof vc.abortCalculation !== 'function'
|
|
61
|
+
) {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
// For reasons that goes beyond my understand,
|
|
66
|
+
// the type is not properly set.
|
|
67
|
+
// https://stash.atlassian.com/projects/ATLASSIAN/repos/atlassian-frontend-monorepo/pull-requests/169231
|
|
68
|
+
// @ts-expect-error
|
|
69
|
+
vc.abortCalculation();
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
export const disableTTVCOnFirstUserInteraction = () => {
|
|
73
|
+
const unbindCallbacks: Set<() => void> = new Set();
|
|
74
|
+
const controller = new AbortController();
|
|
75
|
+
const unbindFirstInteractionEvents = () => {
|
|
76
|
+
controller.abort();
|
|
77
|
+
|
|
78
|
+
unbindCallbacks.forEach((cb) => {
|
|
79
|
+
cb();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
unbindCallbacks.clear();
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return new SafePlugin({
|
|
86
|
+
view(view) {
|
|
87
|
+
if (!view || !view.dom) {
|
|
88
|
+
return {};
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const { dom } = view;
|
|
92
|
+
|
|
93
|
+
for (let abortEventName of AbortEvent) {
|
|
94
|
+
unbindCallbacks.add(
|
|
95
|
+
bind(dom, abortEventName, controller, () => {
|
|
96
|
+
ttvcAbort();
|
|
97
|
+
|
|
98
|
+
unbindFirstInteractionEvents();
|
|
99
|
+
}),
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return {
|
|
104
|
+
destroy: () => {
|
|
105
|
+
unbindFirstInteractionEvents();
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
});
|
|
110
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
2
|
+
|
|
3
|
+
import { disableTTVCOnFirstUserInteraction } from './pm-plugins/disableTTVCOnFirstUserInteraction';
|
|
4
|
+
import type { UfoPlugin } from './ufoPluginType';
|
|
5
|
+
|
|
6
|
+
export const ufoPlugin: UfoPlugin = () => ({
|
|
7
|
+
name: 'ufo',
|
|
8
|
+
|
|
9
|
+
pmPlugins() {
|
|
10
|
+
if (!fg('platform_editor_abort_ttvc_on_user_interaction')) {
|
|
11
|
+
return [];
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
return [
|
|
15
|
+
{
|
|
16
|
+
name: 'disableTTVCOnFirstUserInteraction',
|
|
17
|
+
plugin: disableTTVCOnFirstUserInteraction,
|
|
18
|
+
},
|
|
19
|
+
];
|
|
20
|
+
},
|
|
21
|
+
});
|