@atlaskit/editor-plugin-user-preferences 0.3.0 → 1.1.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 CHANGED
@@ -1,5 +1,57 @@
1
1
  # @atlaskit/editor-plugin-user-preferences
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#180076](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/180076)
8
+ [`f4353390abf4e`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f4353390abf4e) -
9
+ ED-27284 restore page active wather
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
15
+ ## 1.0.0
16
+
17
+ ### Major Changes
18
+
19
+ - [#181024](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/181024)
20
+ [`8e80c487ca307`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/8e80c487ca307) - ##
21
+ Make `@atlaskit/editor-common` a peer dependency
22
+
23
+ **WHAT:** `@atlaskit/editor-common` has been moved from `dependencies` to `peerDependencies` in
24
+ all editor plugin packages.
25
+
26
+ **WHY:** This change ensures that only a single version of `@atlaskit/editor-common` is used in
27
+ consuming applications, preventing issues caused by multiple versions of singleton libraries (such
28
+ as context mismatches or duplicated state). This is especially important for packages that rely on
29
+ shared context or singletons.
30
+
31
+ **HOW TO ADJUST:**
32
+
33
+ - Consumers must now explicitly install `@atlaskit/editor-common` in their own project if they use
34
+ any of these editor plugins.
35
+ - Ensure the version you install matches the version required by the plugins.
36
+ - You can use the
37
+ [`check-peer-dependencies`](https://www.npmjs.com/package/check-peer-dependencies) package to
38
+ verify that all required peer dependencies are installed and compatible.
39
+ - Example install command:
40
+ ```
41
+ npm install @atlaskit/editor-common
42
+ ```
43
+ or
44
+ ```
45
+ yarn add @atlaskit/editor-common
46
+ ```
47
+
48
+ **Note:** This is a breaking change. If `@atlaskit/editor-common` is not installed at the
49
+ application level, you may see errors or unexpected behavior.
50
+
51
+ ### Patch Changes
52
+
53
+ - Updated dependencies
54
+
3
55
  ## 0.3.0
4
56
 
5
57
  ### Minor Changes
@@ -17,9 +17,6 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
- {
21
- "path": "../../editor-common/afm-cc/tsconfig.json"
22
- },
23
20
  {
24
21
  "path": "../../editor-plugin-analytics/afm-cc/tsconfig.json"
25
22
  },
@@ -28,6 +25,9 @@
28
25
  },
29
26
  {
30
27
  "path": "../../tmp-editor-statsig/afm-cc/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-common/afm-cc/tsconfig.json"
31
31
  }
32
32
  ]
33
33
  }
@@ -17,9 +17,6 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
- {
21
- "path": "../../editor-common/afm-jira/tsconfig.json"
22
- },
23
20
  {
24
21
  "path": "../../editor-plugin-analytics/afm-jira/tsconfig.json"
25
22
  },
@@ -28,6 +25,9 @@
28
25
  },
29
26
  {
30
27
  "path": "../../tmp-editor-statsig/afm-jira/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-common/afm-jira/tsconfig.json"
31
31
  }
32
32
  ]
33
33
  }
@@ -17,9 +17,6 @@
17
17
  "../src/**/examples.*"
18
18
  ],
19
19
  "references": [
20
- {
21
- "path": "../../editor-common/afm-post-office/tsconfig.json"
22
- },
23
20
  {
24
21
  "path": "../../editor-plugin-analytics/afm-post-office/tsconfig.json"
25
22
  },
@@ -28,6 +25,9 @@
28
25
  },
29
26
  {
30
27
  "path": "../../tmp-editor-statsig/afm-post-office/tsconfig.json"
28
+ },
29
+ {
30
+ "path": "../../editor-common/afm-post-office/tsconfig.json"
31
31
  }
32
32
  ]
33
33
  }
@@ -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
+ };
@@ -7,6 +7,7 @@ exports.userPreferencesPlugin = void 0;
7
7
  var _userPreferences = require("@atlaskit/editor-common/user-preferences");
8
8
  var _commands = require("./pm-plugins/commands");
9
9
  var _main = require("./pm-plugins/main");
10
+ var _useDocumentVisibilityWatcher = require("./ui/useDocumentVisibilityWatcher");
10
11
  var _useUserPreferencesInitListener = require("./ui/useUserPreferencesInitListener");
11
12
  var _useUserPreferencesUpdateListener = require("./ui/useUserPreferencesUpdateListener");
12
13
  var userPreferencesPlugin = exports.userPreferencesPlugin = function userPreferencesPlugin(_ref) {
@@ -45,6 +46,7 @@ var userPreferencesPlugin = exports.userPreferencesPlugin = function userPrefere
45
46
  var _useResolvedUserPrefe = (0, _userPreferences.useResolvedUserPreferences)(userPreferencesProvider),
46
47
  resolvedUserPreferences = _useResolvedUserPrefe.resolvedUserPreferences;
47
48
  (0, _useUserPreferencesUpdateListener.useUserPreferencesUpdateListener)(editorView, resolvedUserPreferences);
49
+ (0, _useDocumentVisibilityWatcher.useDocumentVisibilityWatcher)(userPreferencesProvider);
48
50
  (0, _useUserPreferencesInitListener.useUserPreferencesInitListener)(Boolean(userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.isInitialized), resolvedUserPreferences, api);
49
51
  }
50
52
  };
@@ -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
+ };
@@ -1,6 +1,7 @@
1
1
  import { useResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
2
2
  import { updateUserPreference } from './pm-plugins/commands';
3
3
  import { createPlugin, userPreferencesPluginKey } from './pm-plugins/main';
4
+ import { useDocumentVisibilityWatcher } from './ui/useDocumentVisibilityWatcher';
4
5
  import { useUserPreferencesInitListener } from './ui/useUserPreferencesInitListener';
5
6
  import { useUserPreferencesUpdateListener } from './ui/useUserPreferencesUpdateListener';
6
7
  export const userPreferencesPlugin = ({
@@ -42,6 +43,7 @@ export const userPreferencesPlugin = ({
42
43
  resolvedUserPreferences
43
44
  } = useResolvedUserPreferences(userPreferencesProvider);
44
45
  useUserPreferencesUpdateListener(editorView, resolvedUserPreferences);
46
+ useDocumentVisibilityWatcher(userPreferencesProvider);
45
47
  useUserPreferencesInitListener(Boolean(userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.isInitialized), resolvedUserPreferences, api);
46
48
  }
47
49
  };
@@ -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
+ };
@@ -1,6 +1,7 @@
1
1
  import { useResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
2
2
  import { updateUserPreference as _updateUserPreference } from './pm-plugins/commands';
3
3
  import { createPlugin, userPreferencesPluginKey } from './pm-plugins/main';
4
+ import { useDocumentVisibilityWatcher } from './ui/useDocumentVisibilityWatcher';
4
5
  import { useUserPreferencesInitListener } from './ui/useUserPreferencesInitListener';
5
6
  import { useUserPreferencesUpdateListener } from './ui/useUserPreferencesUpdateListener';
6
7
  export var userPreferencesPlugin = function userPreferencesPlugin(_ref) {
@@ -39,6 +40,7 @@ export var userPreferencesPlugin = function userPreferencesPlugin(_ref) {
39
40
  var _useResolvedUserPrefe = useResolvedUserPreferences(userPreferencesProvider),
40
41
  resolvedUserPreferences = _useResolvedUserPrefe.resolvedUserPreferences;
41
42
  useUserPreferencesUpdateListener(editorView, resolvedUserPreferences);
43
+ useDocumentVisibilityWatcher(userPreferencesProvider);
42
44
  useUserPreferencesInitListener(Boolean(userPreferencesProvider === null || userPreferencesProvider === void 0 ? void 0 : userPreferencesProvider.isInitialized), resolvedUserPreferences, api);
43
45
  }
44
46
  };
@@ -1,9 +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, type UserPreferences, UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
3
+ import { type ResolvedUserPreferences, type UserPreferences, type UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
4
4
  export declare const updateUserPreference: ({ key, value, userPreferencesProvider, editorAnalyticsApi, }: {
5
5
  key: keyof UserPreferences;
6
- value: "top" | "none";
7
- userPreferencesProvider?: UserPreferencesProvider | undefined;
6
+ value: ResolvedUserPreferences[typeof key];
7
+ userPreferencesProvider?: UserPreferencesProvider;
8
8
  editorAnalyticsApi?: EditorAnalyticsAPI | undefined;
9
9
  }) => EditorCommand;
@@ -0,0 +1,2 @@
1
+ import { type UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
2
+ export declare const useDocumentVisibilityWatcher: (userPreferencesProvider?: UserPreferencesProvider) => void;
@@ -1,3 +1,3 @@
1
1
  import type { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
2
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import { type EditorView } from '@atlaskit/editor-prosemirror/view';
3
3
  export declare const useUserPreferencesUpdateListener: (editorView: EditorView, resolvedUserPreferences: ResolvedUserPreferences | null) => void;
@@ -1,9 +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, type UserPreferences, UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
3
+ import { type ResolvedUserPreferences, type UserPreferences, type UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
4
4
  export declare const updateUserPreference: ({ key, value, userPreferencesProvider, editorAnalyticsApi, }: {
5
5
  key: keyof UserPreferences;
6
- value: "top" | "none";
7
- userPreferencesProvider?: UserPreferencesProvider | undefined;
6
+ value: ResolvedUserPreferences[typeof key];
7
+ userPreferencesProvider?: UserPreferencesProvider;
8
8
  editorAnalyticsApi?: EditorAnalyticsAPI | undefined;
9
9
  }) => EditorCommand;
@@ -0,0 +1,2 @@
1
+ import { type UserPreferencesProvider } from '@atlaskit/editor-common/user-preferences';
2
+ export declare const useDocumentVisibilityWatcher: (userPreferencesProvider?: UserPreferencesProvider) => void;
@@ -1,3 +1,3 @@
1
1
  import type { ResolvedUserPreferences } from '@atlaskit/editor-common/user-preferences';
2
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ import { type EditorView } from '@atlaskit/editor-prosemirror/view';
3
3
  export declare const useUserPreferencesUpdateListener: (editorView: EditorView, resolvedUserPreferences: ResolvedUserPreferences | null) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-user-preferences",
3
- "version": "0.3.0",
3
+ "version": "1.1.0",
4
4
  "description": "UserPreferences plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,15 +31,15 @@
31
31
  ".": "./src/index.ts"
32
32
  },
33
33
  "dependencies": {
34
- "@atlaskit/editor-common": "^107.4.0",
35
- "@atlaskit/editor-plugin-analytics": "^2.3.0",
34
+ "@atlaskit/editor-plugin-analytics": "^3.0.0",
36
35
  "@atlaskit/editor-prosemirror": "7.0.0",
37
36
  "@atlaskit/platform-feature-flags": "^1.1.0",
38
- "@atlaskit/tmp-editor-statsig": "^8.5.0",
37
+ "@atlaskit/tmp-editor-statsig": "^8.8.0",
39
38
  "@babel/runtime": "^7.0.0",
40
39
  "bind-event-listener": "^3.0.0"
41
40
  },
42
41
  "peerDependencies": {
42
+ "@atlaskit/editor-common": "^107.7.0",
43
43
  "react": "^18.2.0"
44
44
  },
45
45
  "devDependencies": {