@atlaskit/editor-plugin-user-preferences 0.1.2 → 0.2.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 +12 -0
- package/afm-cc/tsconfig.json +4 -1
- package/dist/cjs/pm-plugins/commands.js +6 -3
- package/dist/cjs/pm-plugins/main.js +12 -2
- package/dist/cjs/ui/useDocumentVisibilityWatcher.js +53 -0
- package/dist/cjs/ui/useUserPreferencesInitListener.js +26 -0
- package/dist/cjs/ui/useUserPreferencesUpdateListener.js +17 -0
- package/dist/cjs/userPreferencesPlugin.js +7 -72
- package/dist/es2019/pm-plugins/commands.js +5 -2
- package/dist/es2019/pm-plugins/main.js +12 -2
- package/dist/es2019/ui/useDocumentVisibilityWatcher.js +24 -0
- package/dist/es2019/ui/useUserPreferencesInitListener.js +20 -0
- package/dist/es2019/ui/useUserPreferencesUpdateListener.js +11 -0
- package/dist/es2019/userPreferencesPlugin.js +9 -53
- package/dist/esm/pm-plugins/commands.js +5 -2
- package/dist/esm/pm-plugins/main.js +12 -2
- package/dist/esm/ui/useDocumentVisibilityWatcher.js +46 -0
- package/dist/esm/ui/useUserPreferencesInitListener.js +20 -0
- package/dist/esm/ui/useUserPreferencesUpdateListener.js +11 -0
- package/dist/esm/userPreferencesPlugin.js +8 -72
- package/dist/types/index.d.ts +1 -1
- package/dist/types/pm-plugins/commands.d.ts +5 -6
- package/dist/types/pm-plugins/main.d.ts +2 -2
- package/dist/types/ui/useDocumentVisibilityWatcher.d.ts +2 -0
- package/dist/types/ui/useUserPreferencesInitListener.d.ts +4 -0
- package/dist/types/ui/useUserPreferencesUpdateListener.d.ts +3 -0
- package/dist/types/userPreferencesPluginType.d.ts +13 -5
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/commands.d.ts +5 -6
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -2
- package/dist/types-ts4.5/ui/useDocumentVisibilityWatcher.d.ts +2 -0
- package/dist/types-ts4.5/ui/useUserPreferencesInitListener.d.ts +4 -0
- package/dist/types-ts4.5/ui/useUserPreferencesUpdateListener.d.ts +3 -0
- package/dist/types-ts4.5/userPreferencesPluginType.d.ts +13 -5
- package/package.json +3 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-user-preferences
|
|
2
2
|
|
|
3
|
+
## 0.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#158546](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/158546)
|
|
8
|
+
[`b7fe4e6f226f3`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b7fe4e6f226f3) -
|
|
9
|
+
ED-27284 use user preferences plugin in editor preset.
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 0.1.2
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
package/afm-cc/tsconfig.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"compilerOptions": {
|
|
4
4
|
"target": "es5",
|
|
5
5
|
"composite": true,
|
|
6
|
-
"outDir": "
|
|
6
|
+
"outDir": "../../../../../confluence/tsDist/@atlaskit__editor-plugin-user-preferences",
|
|
7
7
|
"rootDir": "../"
|
|
8
8
|
},
|
|
9
9
|
"include": [
|
|
@@ -25,6 +25,9 @@
|
|
|
25
25
|
},
|
|
26
26
|
{
|
|
27
27
|
"path": "../../../platform/feature-flags/afm-cc/tsconfig.json"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"path": "../../tmp-editor-statsig/afm-cc/tsconfig.json"
|
|
28
31
|
}
|
|
29
32
|
]
|
|
30
33
|
}
|
|
@@ -4,12 +4,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.updateUserPreference = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
10
|
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
11
11
|
var _main = require("./main");
|
|
12
|
-
var
|
|
12
|
+
var updateUserPreference = exports.updateUserPreference = function updateUserPreference(_ref) {
|
|
13
13
|
var key = _ref.key,
|
|
14
14
|
value = _ref.value,
|
|
15
15
|
userPreferencesProvider = _ref.userPreferencesProvider,
|
|
@@ -17,12 +17,15 @@ var updateToolbarDockingPosition = exports.updateToolbarDockingPosition = functi
|
|
|
17
17
|
return function (_ref2) {
|
|
18
18
|
var tr = _ref2.tr;
|
|
19
19
|
try {
|
|
20
|
-
userPreferencesProvider.updatePreference(key, value);
|
|
20
|
+
userPreferencesProvider === null || userPreferencesProvider === void 0 || userPreferencesProvider.updatePreference(key, value);
|
|
21
21
|
} catch (error) {
|
|
22
22
|
(0, _monitoring.logException)(error, {
|
|
23
23
|
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
24
24
|
});
|
|
25
25
|
}
|
|
26
|
+
|
|
27
|
+
// If the userPreferencesProvider is not available,
|
|
28
|
+
// the plugin's state will be updated to operate in 'in memory' mode.
|
|
26
29
|
tr.setMeta(_main.userPreferencesPluginKey, {
|
|
27
30
|
preferences: (0, _defineProperty2.default)({}, key, value)
|
|
28
31
|
});
|
|
@@ -8,17 +8,27 @@ exports.userPreferencesPluginKey = exports.createPlugin = void 0;
|
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
10
10
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
11
|
+
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
|
|
11
12
|
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; }
|
|
12
13
|
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
14
|
var userPreferencesPluginKey = exports.userPreferencesPluginKey = new _state.PluginKey('userPreferencesPlugin');
|
|
14
15
|
var createPlugin = exports.createPlugin = function createPlugin(pluginOptions, _api) {
|
|
15
|
-
var userPreferencesProvider = pluginOptions.userPreferencesProvider
|
|
16
|
+
var userPreferencesProvider = pluginOptions.userPreferencesProvider,
|
|
17
|
+
initialUserPreferences = pluginOptions.initialUserPreferences;
|
|
18
|
+
var getInitialUserPreferences = function getInitialUserPreferences() {
|
|
19
|
+
if (initialUserPreferences && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1')) {
|
|
20
|
+
return initialUserPreferences;
|
|
21
|
+
}
|
|
22
|
+
return {
|
|
23
|
+
toolbarDockingPosition: 'top'
|
|
24
|
+
};
|
|
25
|
+
};
|
|
16
26
|
return new _safePlugin.SafePlugin({
|
|
17
27
|
key: userPreferencesPluginKey,
|
|
18
28
|
state: {
|
|
19
29
|
init: function init() {
|
|
20
30
|
return {
|
|
21
|
-
preferences: userPreferencesProvider.getPreferences()
|
|
31
|
+
preferences: (userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.getPreferences()) || getInitialUserPreferences()
|
|
22
32
|
};
|
|
23
33
|
},
|
|
24
34
|
apply: function apply(tr, currentPluginState) {
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useDocumentVisibilityWatcher = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _react = require("react");
|
|
11
|
+
var _bindEventListener = require("bind-event-listener");
|
|
12
|
+
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
13
|
+
var useDocumentVisibilityWatcher = exports.useDocumentVisibilityWatcher = function useDocumentVisibilityWatcher(userPreferencesProvider) {
|
|
14
|
+
(0, _react.useEffect)(function () {
|
|
15
|
+
if (userPreferencesProvider) {
|
|
16
|
+
var refreshPreferences = /*#__PURE__*/function () {
|
|
17
|
+
var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
18
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
19
|
+
while (1) switch (_context.prev = _context.next) {
|
|
20
|
+
case 0:
|
|
21
|
+
if (!(document.visibilityState === 'visible')) {
|
|
22
|
+
_context.next = 9;
|
|
23
|
+
break;
|
|
24
|
+
}
|
|
25
|
+
_context.prev = 1;
|
|
26
|
+
_context.next = 4;
|
|
27
|
+
return userPreferencesProvider.loadPreferences();
|
|
28
|
+
case 4:
|
|
29
|
+
_context.next = 9;
|
|
30
|
+
break;
|
|
31
|
+
case 6:
|
|
32
|
+
_context.prev = 6;
|
|
33
|
+
_context.t0 = _context["catch"](1);
|
|
34
|
+
(0, _monitoring.logException)(_context.t0, {
|
|
35
|
+
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
36
|
+
});
|
|
37
|
+
case 9:
|
|
38
|
+
case "end":
|
|
39
|
+
return _context.stop();
|
|
40
|
+
}
|
|
41
|
+
}, _callee, null, [[1, 6]]);
|
|
42
|
+
}));
|
|
43
|
+
return function refreshPreferences() {
|
|
44
|
+
return _ref.apply(this, arguments);
|
|
45
|
+
};
|
|
46
|
+
}();
|
|
47
|
+
return (0, _bindEventListener.bind)(document, {
|
|
48
|
+
type: 'visibilitychange',
|
|
49
|
+
listener: refreshPreferences
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}, [userPreferencesProvider]);
|
|
53
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useUserPreferencesInitListener = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
9
|
+
var useUserPreferencesInitListener = exports.useUserPreferencesInitListener = function useUserPreferencesInitListener(isInitialized, resolvedUserPreferences, api) {
|
|
10
|
+
var isInitializedRef = (0, _react.useRef)(false);
|
|
11
|
+
(0, _react.useEffect)(function () {
|
|
12
|
+
if (isInitialized && resolvedUserPreferences && !isInitializedRef.current) {
|
|
13
|
+
var _api$analytics;
|
|
14
|
+
isInitializedRef.current = true;
|
|
15
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
16
|
+
action: _analytics.ACTION.INITIALISED,
|
|
17
|
+
actionSubject: _analytics.ACTION_SUBJECT.USER_PREFERENCES,
|
|
18
|
+
actionSubjectId: _analytics.ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES,
|
|
19
|
+
attributes: {
|
|
20
|
+
toolbarDocking: resolvedUserPreferences.toolbarDockingPosition
|
|
21
|
+
},
|
|
22
|
+
eventType: _analytics.EVENT_TYPE.OPERATIONAL
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
}, [api, isInitialized, resolvedUserPreferences]);
|
|
26
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.useUserPreferencesUpdateListener = void 0;
|
|
7
|
+
var _react = require("react");
|
|
8
|
+
var _main = require("../pm-plugins/main");
|
|
9
|
+
var useUserPreferencesUpdateListener = exports.useUserPreferencesUpdateListener = function useUserPreferencesUpdateListener(editorView, resolvedUserPreferences) {
|
|
10
|
+
(0, _react.useEffect)(function () {
|
|
11
|
+
if (resolvedUserPreferences) {
|
|
12
|
+
editorView.dispatch(editorView.state.tr.setMeta(_main.userPreferencesPluginKey, {
|
|
13
|
+
preferences: resolvedUserPreferences
|
|
14
|
+
}));
|
|
15
|
+
}
|
|
16
|
+
}, [resolvedUserPreferences, editorView]);
|
|
17
|
+
};
|
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.userPreferencesPlugin = void 0;
|
|
8
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
-
var _react = require("react");
|
|
11
|
-
var _bindEventListener = require("bind-event-listener");
|
|
12
|
-
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
13
|
-
var _monitoring = require("@atlaskit/editor-common/monitoring");
|
|
14
7
|
var _userPreferences = require("@atlaskit/editor-common/user-preferences");
|
|
15
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
16
8
|
var _commands = require("./pm-plugins/commands");
|
|
17
9
|
var _main = require("./pm-plugins/main");
|
|
10
|
+
var _useDocumentVisibilityWatcher = require("./ui/useDocumentVisibilityWatcher");
|
|
11
|
+
var _useUserPreferencesInitListener = require("./ui/useUserPreferencesInitListener");
|
|
12
|
+
var _useUserPreferencesUpdateListener = require("./ui/useUserPreferencesUpdateListener");
|
|
18
13
|
var userPreferencesPlugin = exports.userPreferencesPlugin = function userPreferencesPlugin(_ref) {
|
|
19
14
|
var config = _ref.config,
|
|
20
15
|
api = _ref.api;
|
|
@@ -32,15 +27,12 @@ var userPreferencesPlugin = exports.userPreferencesPlugin = function userPrefere
|
|
|
32
27
|
actions: {
|
|
33
28
|
updateUserPreference: function updateUserPreference(key, value) {
|
|
34
29
|
var _api$analytics;
|
|
35
|
-
return (0, _commands.
|
|
30
|
+
return (0, _commands.updateUserPreference)({
|
|
36
31
|
key: key,
|
|
37
32
|
value: value,
|
|
38
33
|
userPreferencesProvider: userPreferencesProvider,
|
|
39
34
|
editorAnalyticsApi: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
40
35
|
});
|
|
41
|
-
},
|
|
42
|
-
setDefaultPreferences: function setDefaultPreferences(preferences) {
|
|
43
|
-
userPreferencesProvider.setDefaultPreferences(preferences);
|
|
44
36
|
}
|
|
45
37
|
},
|
|
46
38
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -53,66 +45,9 @@ var userPreferencesPlugin = exports.userPreferencesPlugin = function userPrefere
|
|
|
53
45
|
var editorView = _ref2.editorView;
|
|
54
46
|
var _useResolvedUserPrefe = (0, _userPreferences.useResolvedUserPreferences)(userPreferencesProvider),
|
|
55
47
|
resolvedUserPreferences = _useResolvedUserPrefe.resolvedUserPreferences;
|
|
56
|
-
|
|
57
|
-
(0,
|
|
58
|
-
|
|
59
|
-
if (userPreferencesProvider.isInitialized && !isInitialized.current) {
|
|
60
|
-
var _api$analytics2;
|
|
61
|
-
isInitialized.current = true;
|
|
62
|
-
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.fireAnalyticsEvent({
|
|
63
|
-
action: _analytics.ACTION.INITIALISED,
|
|
64
|
-
actionSubject: _analytics.ACTION_SUBJECT.USER_PREFERENCES,
|
|
65
|
-
actionSubjectId: _analytics.ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES,
|
|
66
|
-
attributes: {
|
|
67
|
-
toolbarDocking: resolvedUserPreferences.toolbarDockingPosition
|
|
68
|
-
},
|
|
69
|
-
eventType: _analytics.EVENT_TYPE.OPERATIONAL
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
editorView.dispatch(editorView.state.tr.setMeta(_main.userPreferencesPluginKey, {
|
|
73
|
-
preferences: resolvedUserPreferences
|
|
74
|
-
}));
|
|
75
|
-
}
|
|
76
|
-
}, [resolvedUserPreferences, editorView]);
|
|
77
|
-
(0, _react.useEffect)(function () {
|
|
78
|
-
if ((0, _platformFeatureFlags.fg)('platform_editor_use_preferences_plugin')) {
|
|
79
|
-
var refreshPrefrerence = /*#__PURE__*/function () {
|
|
80
|
-
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
81
|
-
return _regenerator.default.wrap(function _callee$(_context) {
|
|
82
|
-
while (1) switch (_context.prev = _context.next) {
|
|
83
|
-
case 0:
|
|
84
|
-
if (!(document.visibilityState === 'visible')) {
|
|
85
|
-
_context.next = 9;
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
_context.prev = 1;
|
|
89
|
-
_context.next = 4;
|
|
90
|
-
return userPreferencesProvider.loadPreferences();
|
|
91
|
-
case 4:
|
|
92
|
-
_context.next = 9;
|
|
93
|
-
break;
|
|
94
|
-
case 6:
|
|
95
|
-
_context.prev = 6;
|
|
96
|
-
_context.t0 = _context["catch"](1);
|
|
97
|
-
(0, _monitoring.logException)(_context.t0, {
|
|
98
|
-
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
99
|
-
});
|
|
100
|
-
case 9:
|
|
101
|
-
case "end":
|
|
102
|
-
return _context.stop();
|
|
103
|
-
}
|
|
104
|
-
}, _callee, null, [[1, 6]]);
|
|
105
|
-
}));
|
|
106
|
-
return function refreshPrefrerence() {
|
|
107
|
-
return _ref3.apply(this, arguments);
|
|
108
|
-
};
|
|
109
|
-
}();
|
|
110
|
-
return (0, _bindEventListener.bind)(document, {
|
|
111
|
-
type: 'visibilitychange',
|
|
112
|
-
listener: refreshPrefrerence
|
|
113
|
-
});
|
|
114
|
-
}
|
|
115
|
-
}, []);
|
|
48
|
+
(0, _useUserPreferencesUpdateListener.useUserPreferencesUpdateListener)(editorView, resolvedUserPreferences);
|
|
49
|
+
(0, _useDocumentVisibilityWatcher.useDocumentVisibilityWatcher)(userPreferencesProvider);
|
|
50
|
+
(0, _useUserPreferencesInitListener.useUserPreferencesInitListener)(Boolean(userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.isInitialized), resolvedUserPreferences, api);
|
|
116
51
|
}
|
|
117
52
|
};
|
|
118
53
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
3
3
|
import { userPreferencesPluginKey } from './main';
|
|
4
|
-
export const
|
|
4
|
+
export const updateUserPreference = ({
|
|
5
5
|
key,
|
|
6
6
|
value,
|
|
7
7
|
userPreferencesProvider,
|
|
@@ -10,12 +10,15 @@ export const updateToolbarDockingPosition = ({
|
|
|
10
10
|
tr
|
|
11
11
|
}) => {
|
|
12
12
|
try {
|
|
13
|
-
userPreferencesProvider.updatePreference(key, value);
|
|
13
|
+
userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.updatePreference(key, value);
|
|
14
14
|
} catch (error) {
|
|
15
15
|
logException(error, {
|
|
16
16
|
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
// If the userPreferencesProvider is not available,
|
|
21
|
+
// the plugin's state will be updated to operate in 'in memory' mode.
|
|
19
22
|
tr.setMeta(userPreferencesPluginKey, {
|
|
20
23
|
preferences: {
|
|
21
24
|
[key]: value
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
3
4
|
export const userPreferencesPluginKey = new PluginKey('userPreferencesPlugin');
|
|
4
5
|
export const createPlugin = (pluginOptions, _api) => {
|
|
5
6
|
const {
|
|
6
|
-
userPreferencesProvider
|
|
7
|
+
userPreferencesProvider,
|
|
8
|
+
initialUserPreferences
|
|
7
9
|
} = pluginOptions;
|
|
10
|
+
const getInitialUserPreferences = () => {
|
|
11
|
+
if (initialUserPreferences && editorExperiment('platform_editor_controls', 'variant1')) {
|
|
12
|
+
return initialUserPreferences;
|
|
13
|
+
}
|
|
14
|
+
return {
|
|
15
|
+
toolbarDockingPosition: 'top'
|
|
16
|
+
};
|
|
17
|
+
};
|
|
8
18
|
return new SafePlugin({
|
|
9
19
|
key: userPreferencesPluginKey,
|
|
10
20
|
state: {
|
|
11
21
|
init() {
|
|
12
22
|
return {
|
|
13
|
-
preferences: userPreferencesProvider.getPreferences()
|
|
23
|
+
preferences: (userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.getPreferences()) || getInitialUserPreferences()
|
|
14
24
|
};
|
|
15
25
|
},
|
|
16
26
|
apply: (tr, currentPluginState) => {
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { bind } from 'bind-event-listener';
|
|
3
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
4
|
+
export const useDocumentVisibilityWatcher = userPreferencesProvider => {
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (userPreferencesProvider) {
|
|
7
|
+
const refreshPreferences = async () => {
|
|
8
|
+
if (document.visibilityState === 'visible') {
|
|
9
|
+
try {
|
|
10
|
+
await userPreferencesProvider.loadPreferences();
|
|
11
|
+
} catch (error) {
|
|
12
|
+
logException(error, {
|
|
13
|
+
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
};
|
|
18
|
+
return bind(document, {
|
|
19
|
+
type: 'visibilitychange',
|
|
20
|
+
listener: refreshPreferences
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}, [userPreferencesProvider]);
|
|
24
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
export const useUserPreferencesInitListener = (isInitialized, resolvedUserPreferences, api) => {
|
|
4
|
+
const isInitializedRef = useRef(false);
|
|
5
|
+
useEffect(() => {
|
|
6
|
+
if (isInitialized && resolvedUserPreferences && !isInitializedRef.current) {
|
|
7
|
+
var _api$analytics;
|
|
8
|
+
isInitializedRef.current = true;
|
|
9
|
+
api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
|
|
10
|
+
action: ACTION.INITIALISED,
|
|
11
|
+
actionSubject: ACTION_SUBJECT.USER_PREFERENCES,
|
|
12
|
+
actionSubjectId: ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES,
|
|
13
|
+
attributes: {
|
|
14
|
+
toolbarDocking: resolvedUserPreferences.toolbarDockingPosition
|
|
15
|
+
},
|
|
16
|
+
eventType: EVENT_TYPE.OPERATIONAL
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}, [api, isInitialized, resolvedUserPreferences]);
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { userPreferencesPluginKey } from '../pm-plugins/main';
|
|
3
|
+
export const useUserPreferencesUpdateListener = (editorView, resolvedUserPreferences) => {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
if (resolvedUserPreferences) {
|
|
6
|
+
editorView.dispatch(editorView.state.tr.setMeta(userPreferencesPluginKey, {
|
|
7
|
+
preferences: resolvedUserPreferences
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
}, [resolvedUserPreferences, editorView]);
|
|
11
|
+
};
|
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { useEffect, useRef } from 'react';
|
|
2
|
-
import { bind } from 'bind-event-listener';
|
|
3
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
4
|
-
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
5
1
|
import { useResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
6
|
-
import {
|
|
7
|
-
import { updateToolbarDockingPosition } from './pm-plugins/commands';
|
|
2
|
+
import { updateUserPreference } from './pm-plugins/commands';
|
|
8
3
|
import { createPlugin, userPreferencesPluginKey } from './pm-plugins/main';
|
|
4
|
+
import { useDocumentVisibilityWatcher } from './ui/useDocumentVisibilityWatcher';
|
|
5
|
+
import { useUserPreferencesInitListener } from './ui/useUserPreferencesInitListener';
|
|
6
|
+
import { useUserPreferencesUpdateListener } from './ui/useUserPreferencesUpdateListener';
|
|
9
7
|
export const userPreferencesPlugin = ({
|
|
10
8
|
config,
|
|
11
9
|
api
|
|
12
10
|
}) => {
|
|
13
|
-
const
|
|
14
|
-
userPreferencesProvider
|
|
15
|
-
} = config;
|
|
11
|
+
const userPreferencesProvider = config.userPreferencesProvider;
|
|
16
12
|
return {
|
|
17
13
|
name: 'userPreferences',
|
|
18
14
|
pmPlugins() {
|
|
@@ -26,15 +22,12 @@ export const userPreferencesPlugin = ({
|
|
|
26
22
|
actions: {
|
|
27
23
|
updateUserPreference: (key, value) => {
|
|
28
24
|
var _api$analytics;
|
|
29
|
-
return
|
|
25
|
+
return updateUserPreference({
|
|
30
26
|
key,
|
|
31
27
|
value,
|
|
32
28
|
userPreferencesProvider,
|
|
33
29
|
editorAnalyticsApi: api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
34
30
|
});
|
|
35
|
-
},
|
|
36
|
-
setDefaultPreferences: preferences => {
|
|
37
|
-
userPreferencesProvider.setDefaultPreferences(preferences);
|
|
38
31
|
}
|
|
39
32
|
},
|
|
40
33
|
getSharedState(editorState) {
|
|
@@ -49,46 +42,9 @@ export const userPreferencesPlugin = ({
|
|
|
49
42
|
const {
|
|
50
43
|
resolvedUserPreferences
|
|
51
44
|
} = useResolvedUserPreferences(userPreferencesProvider);
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
if (userPreferencesProvider.isInitialized && !isInitialized.current) {
|
|
56
|
-
var _api$analytics2;
|
|
57
|
-
isInitialized.current = true;
|
|
58
|
-
api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent({
|
|
59
|
-
action: ACTION.INITIALISED,
|
|
60
|
-
actionSubject: ACTION_SUBJECT.USER_PREFERENCES,
|
|
61
|
-
actionSubjectId: ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES,
|
|
62
|
-
attributes: {
|
|
63
|
-
toolbarDocking: resolvedUserPreferences.toolbarDockingPosition
|
|
64
|
-
},
|
|
65
|
-
eventType: EVENT_TYPE.OPERATIONAL
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
editorView.dispatch(editorView.state.tr.setMeta(userPreferencesPluginKey, {
|
|
69
|
-
preferences: resolvedUserPreferences
|
|
70
|
-
}));
|
|
71
|
-
}
|
|
72
|
-
}, [resolvedUserPreferences, editorView]);
|
|
73
|
-
useEffect(() => {
|
|
74
|
-
if (fg('platform_editor_use_preferences_plugin')) {
|
|
75
|
-
const refreshPrefrerence = async () => {
|
|
76
|
-
if (document.visibilityState === 'visible') {
|
|
77
|
-
try {
|
|
78
|
-
await userPreferencesProvider.loadPreferences();
|
|
79
|
-
} catch (error) {
|
|
80
|
-
logException(error, {
|
|
81
|
-
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
return bind(document, {
|
|
87
|
-
type: 'visibilitychange',
|
|
88
|
-
listener: refreshPrefrerence
|
|
89
|
-
});
|
|
90
|
-
}
|
|
91
|
-
}, []);
|
|
45
|
+
useUserPreferencesUpdateListener(editorView, resolvedUserPreferences);
|
|
46
|
+
useDocumentVisibilityWatcher(userPreferencesProvider);
|
|
47
|
+
useUserPreferencesInitListener(Boolean(userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.isInitialized), resolvedUserPreferences, api);
|
|
92
48
|
}
|
|
93
49
|
};
|
|
94
50
|
};
|
|
@@ -2,7 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
|
2
2
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
3
|
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
4
4
|
import { userPreferencesPluginKey } from './main';
|
|
5
|
-
export var
|
|
5
|
+
export var updateUserPreference = function updateUserPreference(_ref) {
|
|
6
6
|
var key = _ref.key,
|
|
7
7
|
value = _ref.value,
|
|
8
8
|
userPreferencesProvider = _ref.userPreferencesProvider,
|
|
@@ -10,12 +10,15 @@ export var updateToolbarDockingPosition = function updateToolbarDockingPosition(
|
|
|
10
10
|
return function (_ref2) {
|
|
11
11
|
var tr = _ref2.tr;
|
|
12
12
|
try {
|
|
13
|
-
userPreferencesProvider.updatePreference(key, value);
|
|
13
|
+
userPreferencesProvider === null || userPreferencesProvider === void 0 || userPreferencesProvider.updatePreference(key, value);
|
|
14
14
|
} catch (error) {
|
|
15
15
|
logException(error, {
|
|
16
16
|
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
17
17
|
});
|
|
18
18
|
}
|
|
19
|
+
|
|
20
|
+
// If the userPreferencesProvider is not available,
|
|
21
|
+
// the plugin's state will be updated to operate in 'in memory' mode.
|
|
19
22
|
tr.setMeta(userPreferencesPluginKey, {
|
|
20
23
|
preferences: _defineProperty({}, key, value)
|
|
21
24
|
});
|
|
@@ -3,15 +3,25 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
3
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; }
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
7
|
export var userPreferencesPluginKey = new PluginKey('userPreferencesPlugin');
|
|
7
8
|
export var createPlugin = function createPlugin(pluginOptions, _api) {
|
|
8
|
-
var userPreferencesProvider = pluginOptions.userPreferencesProvider
|
|
9
|
+
var userPreferencesProvider = pluginOptions.userPreferencesProvider,
|
|
10
|
+
initialUserPreferences = pluginOptions.initialUserPreferences;
|
|
11
|
+
var getInitialUserPreferences = function getInitialUserPreferences() {
|
|
12
|
+
if (initialUserPreferences && editorExperiment('platform_editor_controls', 'variant1')) {
|
|
13
|
+
return initialUserPreferences;
|
|
14
|
+
}
|
|
15
|
+
return {
|
|
16
|
+
toolbarDockingPosition: 'top'
|
|
17
|
+
};
|
|
18
|
+
};
|
|
9
19
|
return new SafePlugin({
|
|
10
20
|
key: userPreferencesPluginKey,
|
|
11
21
|
state: {
|
|
12
22
|
init: function init() {
|
|
13
23
|
return {
|
|
14
|
-
preferences: userPreferencesProvider.getPreferences()
|
|
24
|
+
preferences: (userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.getPreferences()) || getInitialUserPreferences()
|
|
15
25
|
};
|
|
16
26
|
},
|
|
17
27
|
apply: function apply(tr, currentPluginState) {
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { bind } from 'bind-event-listener';
|
|
5
|
+
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
6
|
+
export var useDocumentVisibilityWatcher = function useDocumentVisibilityWatcher(userPreferencesProvider) {
|
|
7
|
+
useEffect(function () {
|
|
8
|
+
if (userPreferencesProvider) {
|
|
9
|
+
var refreshPreferences = /*#__PURE__*/function () {
|
|
10
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
11
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
12
|
+
while (1) switch (_context.prev = _context.next) {
|
|
13
|
+
case 0:
|
|
14
|
+
if (!(document.visibilityState === 'visible')) {
|
|
15
|
+
_context.next = 9;
|
|
16
|
+
break;
|
|
17
|
+
}
|
|
18
|
+
_context.prev = 1;
|
|
19
|
+
_context.next = 4;
|
|
20
|
+
return userPreferencesProvider.loadPreferences();
|
|
21
|
+
case 4:
|
|
22
|
+
_context.next = 9;
|
|
23
|
+
break;
|
|
24
|
+
case 6:
|
|
25
|
+
_context.prev = 6;
|
|
26
|
+
_context.t0 = _context["catch"](1);
|
|
27
|
+
logException(_context.t0, {
|
|
28
|
+
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
29
|
+
});
|
|
30
|
+
case 9:
|
|
31
|
+
case "end":
|
|
32
|
+
return _context.stop();
|
|
33
|
+
}
|
|
34
|
+
}, _callee, null, [[1, 6]]);
|
|
35
|
+
}));
|
|
36
|
+
return function refreshPreferences() {
|
|
37
|
+
return _ref.apply(this, arguments);
|
|
38
|
+
};
|
|
39
|
+
}();
|
|
40
|
+
return bind(document, {
|
|
41
|
+
type: 'visibilitychange',
|
|
42
|
+
listener: refreshPreferences
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}, [userPreferencesProvider]);
|
|
46
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEffect, useRef } from 'react';
|
|
2
|
+
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
3
|
+
export var useUserPreferencesInitListener = function useUserPreferencesInitListener(isInitialized, resolvedUserPreferences, api) {
|
|
4
|
+
var isInitializedRef = useRef(false);
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
if (isInitialized && resolvedUserPreferences && !isInitializedRef.current) {
|
|
7
|
+
var _api$analytics;
|
|
8
|
+
isInitializedRef.current = true;
|
|
9
|
+
api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
|
|
10
|
+
action: ACTION.INITIALISED,
|
|
11
|
+
actionSubject: ACTION_SUBJECT.USER_PREFERENCES,
|
|
12
|
+
actionSubjectId: ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES,
|
|
13
|
+
attributes: {
|
|
14
|
+
toolbarDocking: resolvedUserPreferences.toolbarDockingPosition
|
|
15
|
+
},
|
|
16
|
+
eventType: EVENT_TYPE.OPERATIONAL
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
}, [api, isInitialized, resolvedUserPreferences]);
|
|
20
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { userPreferencesPluginKey } from '../pm-plugins/main';
|
|
3
|
+
export var useUserPreferencesUpdateListener = function useUserPreferencesUpdateListener(editorView, resolvedUserPreferences) {
|
|
4
|
+
useEffect(function () {
|
|
5
|
+
if (resolvedUserPreferences) {
|
|
6
|
+
editorView.dispatch(editorView.state.tr.setMeta(userPreferencesPluginKey, {
|
|
7
|
+
preferences: resolvedUserPreferences
|
|
8
|
+
}));
|
|
9
|
+
}
|
|
10
|
+
}, [resolvedUserPreferences, editorView]);
|
|
11
|
+
};
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
-
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
-
import { useEffect, useRef } from 'react';
|
|
4
|
-
import { bind } from 'bind-event-listener';
|
|
5
|
-
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
6
|
-
import { logException } from '@atlaskit/editor-common/monitoring';
|
|
7
1
|
import { useResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
8
|
-
import {
|
|
9
|
-
import { updateToolbarDockingPosition } from './pm-plugins/commands';
|
|
2
|
+
import { updateUserPreference as _updateUserPreference } from './pm-plugins/commands';
|
|
10
3
|
import { createPlugin, userPreferencesPluginKey } from './pm-plugins/main';
|
|
4
|
+
import { useDocumentVisibilityWatcher } from './ui/useDocumentVisibilityWatcher';
|
|
5
|
+
import { useUserPreferencesInitListener } from './ui/useUserPreferencesInitListener';
|
|
6
|
+
import { useUserPreferencesUpdateListener } from './ui/useUserPreferencesUpdateListener';
|
|
11
7
|
export var userPreferencesPlugin = function userPreferencesPlugin(_ref) {
|
|
12
8
|
var config = _ref.config,
|
|
13
9
|
api = _ref.api;
|
|
@@ -25,15 +21,12 @@ export var userPreferencesPlugin = function userPreferencesPlugin(_ref) {
|
|
|
25
21
|
actions: {
|
|
26
22
|
updateUserPreference: function updateUserPreference(key, value) {
|
|
27
23
|
var _api$analytics;
|
|
28
|
-
return
|
|
24
|
+
return _updateUserPreference({
|
|
29
25
|
key: key,
|
|
30
26
|
value: value,
|
|
31
27
|
userPreferencesProvider: userPreferencesProvider,
|
|
32
28
|
editorAnalyticsApi: api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions
|
|
33
29
|
});
|
|
34
|
-
},
|
|
35
|
-
setDefaultPreferences: function setDefaultPreferences(preferences) {
|
|
36
|
-
userPreferencesProvider.setDefaultPreferences(preferences);
|
|
37
30
|
}
|
|
38
31
|
},
|
|
39
32
|
getSharedState: function getSharedState(editorState) {
|
|
@@ -46,66 +39,9 @@ export var userPreferencesPlugin = function userPreferencesPlugin(_ref) {
|
|
|
46
39
|
var editorView = _ref2.editorView;
|
|
47
40
|
var _useResolvedUserPrefe = useResolvedUserPreferences(userPreferencesProvider),
|
|
48
41
|
resolvedUserPreferences = _useResolvedUserPrefe.resolvedUserPreferences;
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (userPreferencesProvider.isInitialized && !isInitialized.current) {
|
|
53
|
-
var _api$analytics2;
|
|
54
|
-
isInitialized.current = true;
|
|
55
|
-
api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.fireAnalyticsEvent({
|
|
56
|
-
action: ACTION.INITIALISED,
|
|
57
|
-
actionSubject: ACTION_SUBJECT.USER_PREFERENCES,
|
|
58
|
-
actionSubjectId: ACTION_SUBJECT_ID.SELECTION_TOOLBAR_PREFERENCES,
|
|
59
|
-
attributes: {
|
|
60
|
-
toolbarDocking: resolvedUserPreferences.toolbarDockingPosition
|
|
61
|
-
},
|
|
62
|
-
eventType: EVENT_TYPE.OPERATIONAL
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
editorView.dispatch(editorView.state.tr.setMeta(userPreferencesPluginKey, {
|
|
66
|
-
preferences: resolvedUserPreferences
|
|
67
|
-
}));
|
|
68
|
-
}
|
|
69
|
-
}, [resolvedUserPreferences, editorView]);
|
|
70
|
-
useEffect(function () {
|
|
71
|
-
if (fg('platform_editor_use_preferences_plugin')) {
|
|
72
|
-
var refreshPrefrerence = /*#__PURE__*/function () {
|
|
73
|
-
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
|
|
74
|
-
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
75
|
-
while (1) switch (_context.prev = _context.next) {
|
|
76
|
-
case 0:
|
|
77
|
-
if (!(document.visibilityState === 'visible')) {
|
|
78
|
-
_context.next = 9;
|
|
79
|
-
break;
|
|
80
|
-
}
|
|
81
|
-
_context.prev = 1;
|
|
82
|
-
_context.next = 4;
|
|
83
|
-
return userPreferencesProvider.loadPreferences();
|
|
84
|
-
case 4:
|
|
85
|
-
_context.next = 9;
|
|
86
|
-
break;
|
|
87
|
-
case 6:
|
|
88
|
-
_context.prev = 6;
|
|
89
|
-
_context.t0 = _context["catch"](1);
|
|
90
|
-
logException(_context.t0, {
|
|
91
|
-
location: 'editor-plugin-user-preferences/userPreferencesPlugin'
|
|
92
|
-
});
|
|
93
|
-
case 9:
|
|
94
|
-
case "end":
|
|
95
|
-
return _context.stop();
|
|
96
|
-
}
|
|
97
|
-
}, _callee, null, [[1, 6]]);
|
|
98
|
-
}));
|
|
99
|
-
return function refreshPrefrerence() {
|
|
100
|
-
return _ref3.apply(this, arguments);
|
|
101
|
-
};
|
|
102
|
-
}();
|
|
103
|
-
return bind(document, {
|
|
104
|
-
type: 'visibilitychange',
|
|
105
|
-
listener: refreshPrefrerence
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
}, []);
|
|
42
|
+
useUserPreferencesUpdateListener(editorView, resolvedUserPreferences);
|
|
43
|
+
useDocumentVisibilityWatcher(userPreferencesProvider);
|
|
44
|
+
useUserPreferencesInitListener(Boolean(userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.isInitialized), resolvedUserPreferences, api);
|
|
109
45
|
}
|
|
110
46
|
};
|
|
111
47
|
};
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { userPreferencesPlugin } from './userPreferencesPlugin';
|
|
2
|
-
export type { UserPreferencesPlugin } from './userPreferencesPluginType';
|
|
2
|
+
export type { UserPreferencesPlugin, UserPreferencesPluginOptions, } from './userPreferencesPluginType';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
-
import { type ResolvedUserPreferences, UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
userPreferencesProvider: UserPreferencesProvider;
|
|
3
|
+
import { type ResolvedUserPreferences, type UserPreferences, UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
|
|
4
|
+
export declare const updateUserPreference: ({ key, value, userPreferencesProvider, editorAnalyticsApi, }: {
|
|
5
|
+
key: keyof UserPreferences;
|
|
6
|
+
value: "top" | "none";
|
|
7
|
+
userPreferencesProvider?: UserPreferencesProvider | undefined;
|
|
9
8
|
editorAnalyticsApi?: EditorAnalyticsAPI | undefined;
|
|
10
9
|
}) => EditorCommand;
|
|
@@ -2,10 +2,10 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
4
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import type {
|
|
5
|
+
import type { UserPreferencesPluginOptions, UserPreferencesPlugin } from '../userPreferencesPluginType';
|
|
6
6
|
export declare const userPreferencesPluginKey: PluginKey<any>;
|
|
7
7
|
type UserPreferencesPluginState = {
|
|
8
8
|
preferences: ResolvedUserPreferences;
|
|
9
9
|
};
|
|
10
|
-
export declare const createPlugin: (pluginOptions:
|
|
10
|
+
export declare const createPlugin: (pluginOptions: UserPreferencesPluginOptions, _api: ExtractInjectionAPI<UserPreferencesPlugin> | undefined) => SafePlugin<UserPreferencesPluginState>;
|
|
11
11
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
3
|
+
import { UserPreferencesPlugin } from '../userPreferencesPluginType';
|
|
4
|
+
export declare const useUserPreferencesInitListener: (isInitialized: boolean, resolvedUserPreferences: ResolvedUserPreferences | null, api?: ExtractInjectionAPI<UserPreferencesPlugin>) => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
2
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export declare const useUserPreferencesUpdateListener: (editorView: EditorView, resolvedUserPreferences: ResolvedUserPreferences | null) => void;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { type ResolvedUserPreferences, type
|
|
2
|
+
import { type ResolvedUserPreferences, type UserPreferencesProvider, type UserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
-
export type
|
|
5
|
-
|
|
4
|
+
export type UserPreferencesPluginOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The user preferences provider to be used to get and set user preferences.
|
|
7
|
+
* When not provided, user preferences will not be persisted.
|
|
8
|
+
*/
|
|
9
|
+
userPreferencesProvider?: UserPreferencesProvider;
|
|
10
|
+
/**
|
|
11
|
+
* The initial user preferences to be used when the userPreferencesProvider is not available.
|
|
12
|
+
* Otherwise, will default to the userPreferencesProvider's initial preferences.
|
|
13
|
+
*/
|
|
14
|
+
initialUserPreferences?: ResolvedUserPreferences;
|
|
6
15
|
};
|
|
7
16
|
export type PrefKey = keyof UserPreferences;
|
|
8
17
|
export type ResolvedPrefKey = keyof ResolvedUserPreferences;
|
|
@@ -10,10 +19,9 @@ export type UserPreferencesSharedState = {
|
|
|
10
19
|
preferences: ResolvedUserPreferences;
|
|
11
20
|
};
|
|
12
21
|
export type UserPreferencesPlugin = NextEditorPlugin<'userPreferences', {
|
|
13
|
-
pluginConfiguration:
|
|
22
|
+
pluginConfiguration: UserPreferencesPluginOptions;
|
|
14
23
|
actions: {
|
|
15
24
|
updateUserPreference: (key: PrefKey, value: ResolvedUserPreferences[PrefKey]) => EditorCommand;
|
|
16
|
-
setDefaultPreferences: (preferences: ResolvedUserPreferences) => void;
|
|
17
25
|
};
|
|
18
26
|
sharedState: UserPreferencesSharedState;
|
|
19
27
|
dependencies: [OptionalPlugin<AnalyticsPlugin>];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { userPreferencesPlugin } from './userPreferencesPlugin';
|
|
2
|
-
export type { UserPreferencesPlugin } from './userPreferencesPluginType';
|
|
2
|
+
export type { UserPreferencesPlugin, UserPreferencesPluginOptions, } from './userPreferencesPluginType';
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { type EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
2
2
|
import type { EditorCommand } from '@atlaskit/editor-common/types';
|
|
3
|
-
import { type ResolvedUserPreferences, UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
userPreferencesProvider: UserPreferencesProvider;
|
|
3
|
+
import { type ResolvedUserPreferences, type UserPreferences, UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
|
|
4
|
+
export declare const updateUserPreference: ({ key, value, userPreferencesProvider, editorAnalyticsApi, }: {
|
|
5
|
+
key: keyof UserPreferences;
|
|
6
|
+
value: "top" | "none";
|
|
7
|
+
userPreferencesProvider?: UserPreferencesProvider | undefined;
|
|
9
8
|
editorAnalyticsApi?: EditorAnalyticsAPI | undefined;
|
|
10
9
|
}) => EditorCommand;
|
|
@@ -2,10 +2,10 @@ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
|
2
2
|
import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
4
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
|
-
import type {
|
|
5
|
+
import type { UserPreferencesPluginOptions, UserPreferencesPlugin } from '../userPreferencesPluginType';
|
|
6
6
|
export declare const userPreferencesPluginKey: PluginKey<any>;
|
|
7
7
|
type UserPreferencesPluginState = {
|
|
8
8
|
preferences: ResolvedUserPreferences;
|
|
9
9
|
};
|
|
10
|
-
export declare const createPlugin: (pluginOptions:
|
|
10
|
+
export declare const createPlugin: (pluginOptions: UserPreferencesPluginOptions, _api: ExtractInjectionAPI<UserPreferencesPlugin> | undefined) => SafePlugin<UserPreferencesPluginState>;
|
|
11
11
|
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
2
|
+
import { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
3
|
+
import { UserPreferencesPlugin } from '../userPreferencesPluginType';
|
|
4
|
+
export declare const useUserPreferencesInitListener: (isInitialized: boolean, resolvedUserPreferences: ResolvedUserPreferences | null, api?: ExtractInjectionAPI<UserPreferencesPlugin>) => void;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
2
|
+
import { EditorView } from '@atlaskit/editor-prosemirror/view';
|
|
3
|
+
export declare const useUserPreferencesUpdateListener: (editorView: EditorView, resolvedUserPreferences: ResolvedUserPreferences | null) => void;
|
|
@@ -1,8 +1,17 @@
|
|
|
1
1
|
import type { EditorCommand, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
-
import { type ResolvedUserPreferences, type
|
|
2
|
+
import { type ResolvedUserPreferences, type UserPreferencesProvider, type UserPreferences } from '@atlaskit/editor-common/user-preferences';
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
|
-
export type
|
|
5
|
-
|
|
4
|
+
export type UserPreferencesPluginOptions = {
|
|
5
|
+
/**
|
|
6
|
+
* The user preferences provider to be used to get and set user preferences.
|
|
7
|
+
* When not provided, user preferences will not be persisted.
|
|
8
|
+
*/
|
|
9
|
+
userPreferencesProvider?: UserPreferencesProvider;
|
|
10
|
+
/**
|
|
11
|
+
* The initial user preferences to be used when the userPreferencesProvider is not available.
|
|
12
|
+
* Otherwise, will default to the userPreferencesProvider's initial preferences.
|
|
13
|
+
*/
|
|
14
|
+
initialUserPreferences?: ResolvedUserPreferences;
|
|
6
15
|
};
|
|
7
16
|
export type PrefKey = keyof UserPreferences;
|
|
8
17
|
export type ResolvedPrefKey = keyof ResolvedUserPreferences;
|
|
@@ -10,10 +19,9 @@ export type UserPreferencesSharedState = {
|
|
|
10
19
|
preferences: ResolvedUserPreferences;
|
|
11
20
|
};
|
|
12
21
|
export type UserPreferencesPlugin = NextEditorPlugin<'userPreferences', {
|
|
13
|
-
pluginConfiguration:
|
|
22
|
+
pluginConfiguration: UserPreferencesPluginOptions;
|
|
14
23
|
actions: {
|
|
15
24
|
updateUserPreference: (key: PrefKey, value: ResolvedUserPreferences[PrefKey]) => EditorCommand;
|
|
16
|
-
setDefaultPreferences: (preferences: ResolvedUserPreferences) => void;
|
|
17
25
|
};
|
|
18
26
|
sharedState: UserPreferencesSharedState;
|
|
19
27
|
dependencies: [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-user-preferences",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "UserPreferences plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,10 +32,11 @@
|
|
|
32
32
|
".": "./src/index.ts"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@atlaskit/editor-common": "^106.
|
|
35
|
+
"@atlaskit/editor-common": "^106.7.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^2.3.0",
|
|
37
37
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
38
38
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
39
|
+
"@atlaskit/tmp-editor-statsig": "^7.0.0",
|
|
39
40
|
"@babel/runtime": "^7.0.0",
|
|
40
41
|
"bind-event-listener": "^3.0.0"
|
|
41
42
|
},
|