@atlaskit/editor-core 190.1.5 → 190.1.7

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.
Files changed (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/plugins/index.js +0 -21
  3. package/dist/cjs/presets/universal.js +0 -15
  4. package/dist/cjs/ui/AppearanceComponents/Mobile.js +3 -0
  5. package/dist/cjs/version-wrapper.js +1 -1
  6. package/dist/es2019/plugins/index.js +0 -3
  7. package/dist/es2019/presets/universal.js +1 -16
  8. package/dist/es2019/ui/AppearanceComponents/Mobile.js +4 -0
  9. package/dist/es2019/version-wrapper.js +1 -1
  10. package/dist/esm/plugins/index.js +0 -3
  11. package/dist/esm/presets/universal.js +1 -16
  12. package/dist/esm/ui/AppearanceComponents/Mobile.js +4 -0
  13. package/dist/esm/version-wrapper.js +1 -1
  14. package/dist/types/plugins/index.d.ts +0 -3
  15. package/dist/types-ts4.5/plugins/index.d.ts +0 -3
  16. package/package.json +3 -3
  17. package/dist/cjs/plugins/mobile-dimensions/actions.js +0 -12
  18. package/dist/cjs/plugins/mobile-dimensions/commands.js +0 -26
  19. package/dist/cjs/plugins/mobile-dimensions/index.js +0 -99
  20. package/dist/cjs/plugins/mobile-dimensions/plugin-factory.js +0 -15
  21. package/dist/cjs/plugins/mobile-dimensions/reducer.js +0 -28
  22. package/dist/cjs/plugins/mobile-dimensions/types.js +0 -5
  23. package/dist/cjs/plugins/mobile-selection/content-in-selection.js +0 -24
  24. package/dist/cjs/plugins/mobile-selection/index.js +0 -18
  25. package/dist/cjs/plugins/mobile-selection/mobile-selection-plugin.js +0 -59
  26. package/dist/cjs/plugins/mobile-selection/types.js +0 -5
  27. package/dist/cjs/plugins/view-update-subscription/index.js +0 -90
  28. package/dist/cjs/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +0 -109
  29. package/dist/es2019/plugins/mobile-dimensions/actions.js +0 -6
  30. package/dist/es2019/plugins/mobile-dimensions/commands.js +0 -14
  31. package/dist/es2019/plugins/mobile-dimensions/index.js +0 -88
  32. package/dist/es2019/plugins/mobile-dimensions/plugin-factory.js +0 -9
  33. package/dist/es2019/plugins/mobile-dimensions/reducer.js +0 -21
  34. package/dist/es2019/plugins/mobile-dimensions/types.js +0 -1
  35. package/dist/es2019/plugins/mobile-selection/content-in-selection.js +0 -17
  36. package/dist/es2019/plugins/mobile-selection/index.js +0 -1
  37. package/dist/es2019/plugins/mobile-selection/mobile-selection-plugin.js +0 -53
  38. package/dist/es2019/plugins/mobile-selection/types.js +0 -1
  39. package/dist/es2019/plugins/view-update-subscription/index.js +0 -73
  40. package/dist/es2019/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +0 -106
  41. package/dist/esm/plugins/mobile-dimensions/actions.js +0 -6
  42. package/dist/esm/plugins/mobile-dimensions/commands.js +0 -20
  43. package/dist/esm/plugins/mobile-dimensions/index.js +0 -93
  44. package/dist/esm/plugins/mobile-dimensions/plugin-factory.js +0 -9
  45. package/dist/esm/plugins/mobile-dimensions/reducer.js +0 -21
  46. package/dist/esm/plugins/mobile-dimensions/types.js +0 -1
  47. package/dist/esm/plugins/mobile-selection/content-in-selection.js +0 -18
  48. package/dist/esm/plugins/mobile-selection/index.js +0 -1
  49. package/dist/esm/plugins/mobile-selection/mobile-selection-plugin.js +0 -53
  50. package/dist/esm/plugins/mobile-selection/types.js +0 -1
  51. package/dist/esm/plugins/view-update-subscription/index.js +0 -83
  52. package/dist/esm/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.js +0 -103
  53. package/dist/types/plugins/mobile-dimensions/actions.d.ts +0 -18
  54. package/dist/types/plugins/mobile-dimensions/commands.d.ts +0 -3
  55. package/dist/types/plugins/mobile-dimensions/index.d.ts +0 -7
  56. package/dist/types/plugins/mobile-dimensions/plugin-factory.d.ts +0 -5
  57. package/dist/types/plugins/mobile-dimensions/reducer.d.ts +0 -3
  58. package/dist/types/plugins/mobile-dimensions/types.d.ts +0 -8
  59. package/dist/types/plugins/mobile-selection/content-in-selection.d.ts +0 -5
  60. package/dist/types/plugins/mobile-selection/index.d.ts +0 -2
  61. package/dist/types/plugins/mobile-selection/mobile-selection-plugin.d.ts +0 -7
  62. package/dist/types/plugins/mobile-selection/types.d.ts +0 -32
  63. package/dist/types/plugins/view-update-subscription/index.d.ts +0 -19
  64. package/dist/types/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.d.ts +0 -12
  65. package/dist/types-ts4.5/plugins/mobile-dimensions/actions.d.ts +0 -18
  66. package/dist/types-ts4.5/plugins/mobile-dimensions/commands.d.ts +0 -3
  67. package/dist/types-ts4.5/plugins/mobile-dimensions/index.d.ts +0 -7
  68. package/dist/types-ts4.5/plugins/mobile-dimensions/plugin-factory.d.ts +0 -5
  69. package/dist/types-ts4.5/plugins/mobile-dimensions/reducer.d.ts +0 -3
  70. package/dist/types-ts4.5/plugins/mobile-dimensions/types.d.ts +0 -8
  71. package/dist/types-ts4.5/plugins/mobile-selection/content-in-selection.d.ts +0 -5
  72. package/dist/types-ts4.5/plugins/mobile-selection/index.d.ts +0 -2
  73. package/dist/types-ts4.5/plugins/mobile-selection/mobile-selection-plugin.d.ts +0 -7
  74. package/dist/types-ts4.5/plugins/mobile-selection/types.d.ts +0 -32
  75. package/dist/types-ts4.5/plugins/view-update-subscription/index.d.ts +0 -19
  76. package/dist/types-ts4.5/plugins/view-update-subscription/subscribe/toolbarAndPickerUpdates.d.ts +0 -12
@@ -1,90 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.trackerStore = exports.default = void 0;
8
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
11
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
12
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
- var _state = require("@atlaskit/editor-prosemirror/state");
14
- var trackerStore = exports.trackerStore = new WeakMap();
15
- var Tracker = /*#__PURE__*/(0, _createClass2.default)(function Tracker() {
16
- var _this = this;
17
- (0, _classCallCheck2.default)(this, Tracker);
18
- (0, _defineProperty2.default)(this, "update", function (props) {
19
- _this.subscriptions.forEach(function (cb) {
20
- return cb(props);
21
- });
22
- });
23
- (0, _defineProperty2.default)(this, "add", function (subscription) {
24
- _this.subscriptions.push(subscription);
25
- });
26
- (0, _defineProperty2.default)(this, "remove", function (subscription) {
27
- _this.subscriptions = _this.subscriptions.filter(function (s) {
28
- return s !== subscription;
29
- });
30
- });
31
- this.subscriptions = [];
32
- });
33
- var pluginKey = new _state.PluginKey('viewUpdateSubscriptionKey');
34
- var createViewUpdateSubscriptionPlugin = function createViewUpdateSubscriptionPlugin() {
35
- var tracker;
36
- var lastUpdateRef = {
37
- current: null,
38
- initial: null,
39
- transactions: [],
40
- queued: false
41
- };
42
- return {
43
- name: 'viewUpdateSubscription',
44
- pmPlugins: function pmPlugins() {
45
- var createPlugin = function createPlugin() {
46
- return new _safePlugin.SafePlugin({
47
- key: pluginKey,
48
- view: function view(editorView) {
49
- tracker = trackerStore.get(editorView);
50
- if (!tracker) {
51
- tracker = new Tracker();
52
- trackerStore.set(editorView, tracker);
53
- }
54
- return {};
55
- }
56
- });
57
- };
58
- return [{
59
- name: 'viewUpdateSubscription',
60
- plugin: createPlugin
61
- }];
62
- },
63
- onEditorViewStateUpdated: function onEditorViewStateUpdated(props) {
64
- var _lastUpdateRef$transa;
65
- lastUpdateRef.current = props;
66
- (_lastUpdateRef$transa = lastUpdateRef.transactions).push.apply(_lastUpdateRef$transa, (0, _toConsumableArray2.default)(props.transactions));
67
- if (!lastUpdateRef.queued) {
68
- lastUpdateRef.initial = props;
69
- lastUpdateRef.queued = true;
70
- queueMicrotask(function () {
71
- if (!lastUpdateRef.current || !lastUpdateRef.initial) {
72
- return;
73
- }
74
- if (tracker) {
75
- var _lastUpdateRef$initia;
76
- tracker.update({
77
- newEditorState: lastUpdateRef.current.newEditorState,
78
- oldEditorState: (_lastUpdateRef$initia = lastUpdateRef.initial) === null || _lastUpdateRef$initia === void 0 ? void 0 : _lastUpdateRef$initia.oldEditorState,
79
- transactions: lastUpdateRef.transactions
80
- });
81
- }
82
- lastUpdateRef.queued = false;
83
- lastUpdateRef.current = null;
84
- lastUpdateRef.transactions = [];
85
- });
86
- }
87
- }
88
- };
89
- };
90
- var _default = exports.default = createViewUpdateSubscriptionPlugin;
@@ -1,109 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.subscribeToToolbarAndPickerUpdates = void 0;
7
- var _floatingToolbar = require("@atlaskit/editor-common/floating-toolbar");
8
- var _ = require("..");
9
- var areToolbarsSame = function areToolbarsSame(left, right) {
10
- if (!left && !right) {
11
- return true;
12
- }
13
- if (left && !right || !left && right) {
14
- return false;
15
- }
16
- var leftConfig = left.config;
17
- var rightConfig = right.config;
18
- if (!leftConfig && !rightConfig) {
19
- return true;
20
- }
21
- if (!leftConfig && rightConfig || leftConfig && !rightConfig) {
22
- return false;
23
- }
24
- var leftItems = Array.isArray(leftConfig.items) ? leftConfig.items : leftConfig.items(left.node);
25
- var rightItems = Array.isArray(rightConfig.items) ? rightConfig.items : rightConfig.items(right.node);
26
- return (0, _floatingToolbar.areSameItems)(leftItems, rightItems);
27
- };
28
- var subscribeToToolbarAndPickerUpdates = exports.subscribeToToolbarAndPickerUpdates = function subscribeToToolbarAndPickerUpdates(editorView, cb) {
29
- var lastUpdatedState = null;
30
- var subscription = function subscription(_ref) {
31
- var newEditorState = _ref.newEditorState;
32
- // Creating fake plugin keys for these plugins for the mean time until all these plugins are extracted.
33
- var typeAheadPluginKey = {
34
- key: 'typeAheadPlugin$',
35
- getState: function getState(state) {
36
- return state['typeAheadPlugin$'];
37
- }
38
- };
39
- var datePluginKey = {
40
- key: 'datePlugin$',
41
- getState: function getState(state) {
42
- return state['datePlugin$'];
43
- }
44
- };
45
- var statusPluginKey = {
46
- key: 'statusPlugin$',
47
- getState: function getState(state) {
48
- return state['statusPlugin$'];
49
- }
50
- };
51
- var floatingToolbarPluginKey = {
52
- key: 'floatingToolbarPluginKey$',
53
- getState: function getState(state) {
54
- return state['floatingToolbarPluginKey$'];
55
- }
56
- };
57
- var isTypeAheadOpen = function isTypeAheadOpen(editorState) {
58
- var _typeAheadState$decor;
59
- var typeAheadState = typeAheadPluginKey.getState(newEditorState);
60
- return !!((_typeAheadState$decor = typeAheadState.decorationSet) !== null && _typeAheadState$decor !== void 0 && _typeAheadState$decor.find().length);
61
- };
62
- // TypeAhead has priority in the mobile-bridge
63
- // In case it is open we don't need to send
64
- // any toolbar updates don't need to be send
65
- if (isTypeAheadOpen(newEditorState)) {
66
- return;
67
- }
68
- var dateState = datePluginKey.getState(newEditorState);
69
- var statusState = statusPluginKey.getState(newEditorState);
70
- var _ref2 = floatingToolbarPluginKey.getState(newEditorState),
71
- getConfigWithNodeInfo = _ref2.getConfigWithNodeInfo;
72
- var toolbarConfig = getConfigWithNodeInfo(newEditorState);
73
- var shouldCallback = false;
74
- if (lastUpdatedState) {
75
- var oldDateState = datePluginKey.getState(lastUpdatedState);
76
- var oldStatusState = statusPluginKey.getState(lastUpdatedState);
77
- var _ref3 = floatingToolbarPluginKey.getState(lastUpdatedState),
78
- getOldConfigWithNodeInfo = _ref3.getConfigWithNodeInfo;
79
- var oldToolbarConfig = getOldConfigWithNodeInfo(lastUpdatedState);
80
- var isToolbarEqual = areToolbarsSame(toolbarConfig, oldToolbarConfig);
81
- if (dateState !== oldDateState || statusState !== oldStatusState ||
82
- // Sometimes the toolbar changes while a picker is open, we dont care about this
83
- // EG A nested status or date node in a table
84
- !isToolbarEqual && !(statusState !== null && statusState !== void 0 && statusState.showStatusPickerAt) && !(dateState !== null && dateState !== void 0 && dateState.showDatePickerAt)) {
85
- shouldCallback = true;
86
- }
87
- } else {
88
- shouldCallback = true;
89
- }
90
- if (shouldCallback) {
91
- cb({
92
- dateState: dateState,
93
- statusState: statusState,
94
- toolbarConfig: toolbarConfig
95
- });
96
- }
97
- lastUpdatedState = newEditorState;
98
- };
99
- var tracker = _.trackerStore.get(editorView);
100
- if (tracker) {
101
- tracker.add(subscription);
102
- }
103
- return function () {
104
- var tracker = _.trackerStore.get(editorView);
105
- if (tracker) {
106
- tracker.remove(subscription);
107
- }
108
- };
109
- };
@@ -1,6 +0,0 @@
1
- export let MobileDimensionsActionTypes = /*#__PURE__*/function (MobileDimensionsActionTypes) {
2
- MobileDimensionsActionTypes["SET_WINDOW_HEIGHT"] = "SET_WINDOW_HEIGHT";
3
- MobileDimensionsActionTypes["SET_MOBILE_PADDING_TOP"] = "SET_MOBILE_PADDING_TOP";
4
- MobileDimensionsActionTypes["SET_IS_EXPANDED"] = "SET_IS_EXPANDED";
5
- return MobileDimensionsActionTypes;
6
- }({});
@@ -1,14 +0,0 @@
1
- import { MobileDimensionsActionTypes } from './actions';
2
- import { createCommand } from './plugin-factory';
3
- export const setWindowHeight = windowHeight => createCommand({
4
- type: MobileDimensionsActionTypes.SET_WINDOW_HEIGHT,
5
- windowHeight
6
- });
7
- export const setMobilePaddingTop = paddingTop => createCommand({
8
- type: MobileDimensionsActionTypes.SET_MOBILE_PADDING_TOP,
9
- paddingTop
10
- });
11
- export const setIsExpanded = isExpanded => createCommand({
12
- type: MobileDimensionsActionTypes.SET_IS_EXPANDED,
13
- isExpanded
14
- });
@@ -1,88 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { setWindowHeight } from './commands';
3
- import { createPluginState, mobileDimensionsPluginKey } from './plugin-factory';
4
- const getInitialState = () => ({
5
- mobilePaddingTop: 0,
6
- windowHeight: window.innerHeight,
7
- isExpanded: false
8
- });
9
-
10
- /**
11
- * Plugin to store the dimensions of the mobile such as keyboard height and window size
12
- */
13
-
14
- const createPlugin = dispatch => {
15
- let rafId;
16
- return new SafePlugin({
17
- state: createPluginState(dispatch, getInitialState),
18
- key: mobileDimensionsPluginKey,
19
- props: {
20
- scrollThreshold: {
21
- top: 12,
22
- left: 0,
23
- right: 0,
24
- bottom: 12
25
- },
26
- scrollMargin: {
27
- top: 12,
28
- bottom: 12,
29
- left: 0,
30
- right: 0
31
- }
32
- },
33
- view(editorView) {
34
- const handleResize = () => {
35
- if (rafId) {
36
- window.cancelAnimationFrame(rafId);
37
- }
38
- let windowInnerHeight = window.innerHeight;
39
- let count = 0;
40
- const checkWindowHeight = () => {
41
- // wait for height to stabilise before we commit to set it
42
- // this helps handle menu transitions in Android which we don't want to scroll for
43
- if (window.innerHeight === windowInnerHeight) {
44
- count++;
45
- if (count >= 5) {
46
- rafId = undefined;
47
- setWindowHeight(window.innerHeight)(editorView.state, editorView.dispatch);
48
- } else {
49
- rafId = requestAnimationFrame(checkWindowHeight);
50
- }
51
- } else {
52
- rafId = requestAnimationFrame(checkWindowHeight);
53
- }
54
- windowInnerHeight = window.innerHeight;
55
- };
56
- rafId = requestAnimationFrame(checkWindowHeight);
57
- };
58
- // the window will resize on Android when the keyboard shows/hides
59
- window.addEventListener('resize', handleResize);
60
- return {
61
- destroy() {
62
- window.removeEventListener('resize', handleResize);
63
- if (rafId) {
64
- window.cancelAnimationFrame(rafId);
65
- }
66
- }
67
- };
68
- }
69
- });
70
- };
71
- const mobileDimensionsPlugin = () => ({
72
- name: 'mobileDimensions',
73
- getSharedState(editorState) {
74
- if (!editorState) {
75
- return undefined;
76
- }
77
- return mobileDimensionsPluginKey.getState(editorState);
78
- },
79
- pmPlugins() {
80
- return [{
81
- name: 'mobileDimensions',
82
- plugin: ({
83
- dispatch
84
- }) => createPlugin(dispatch)
85
- }];
86
- }
87
- });
88
- export default mobileDimensionsPlugin;
@@ -1,9 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- import { pluginFactory } from '../../utils/plugin-state-factory';
3
- import reducer from './reducer';
4
- export const mobileDimensionsPluginKey = new PluginKey('mobileDimensions');
5
- export const {
6
- createPluginState,
7
- getPluginState,
8
- createCommand
9
- } = pluginFactory(mobileDimensionsPluginKey, reducer);
@@ -1,21 +0,0 @@
1
- import { MobileDimensionsActionTypes } from './actions';
2
- export default function (state, action) {
3
- switch (action.type) {
4
- case MobileDimensionsActionTypes.SET_WINDOW_HEIGHT:
5
- return {
6
- ...state,
7
- windowHeight: action.windowHeight
8
- };
9
- case MobileDimensionsActionTypes.SET_MOBILE_PADDING_TOP:
10
- return {
11
- ...state,
12
- mobilePaddingTop: action.paddingTop
13
- };
14
- case MobileDimensionsActionTypes.SET_IS_EXPANDED:
15
- return {
16
- ...state,
17
- isExpanded: action.isExpanded
18
- };
19
- }
20
- return state;
21
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,17 +0,0 @@
1
- // Gets a plain text representation of the nodes in the current selection
2
- export const contentInSelection = ({
3
- selection,
4
- doc
5
- }) => {
6
- const nodes = new Array();
7
- const marks = new Array();
8
- doc.nodesBetween(selection.from, selection.to, node => {
9
- nodes.push(node.type.name);
10
- node.marks.forEach(mark => marks.push(mark.type.name));
11
- return true;
12
- });
13
- return {
14
- nodeTypes: Array.from(nodes),
15
- markTypes: Array.from(marks)
16
- };
17
- };
@@ -1 +0,0 @@
1
- export { mobileSelectionPlugin as default, selectionPluginKey } from './mobile-selection-plugin';
@@ -1,53 +0,0 @@
1
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
3
- import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
4
- import { contentInSelection } from './content-in-selection';
5
- export const selectionPluginKey = new PluginKey('mobile-selection');
6
- export const createProseMirrorPlugin = dispatch => {
7
- return new SafePlugin({
8
- view: editorView => {
9
- const domAtPos = editorView.domAtPos.bind(editorView);
10
- return {
11
- update: (view, previousState) => {
12
- const {
13
- state,
14
- state: {
15
- selection,
16
- doc
17
- }
18
- } = view;
19
- if (previousState.doc.eq(doc) && previousState.selection.eq(selection)) {
20
- return;
21
- }
22
- const ref = findDomRefAtPos(selection.$anchor.pos, domAtPos);
23
- const {
24
- top,
25
- left
26
- } = ref.getBoundingClientRect();
27
- const {
28
- nodeTypes,
29
- markTypes
30
- } = contentInSelection(state);
31
- dispatch(selectionPluginKey, {
32
- rect: {
33
- top: Math.round(top),
34
- left: Math.round(left)
35
- },
36
- selection: state.selection.toJSON(),
37
- nodeTypes,
38
- markTypes
39
- });
40
- }
41
- };
42
- }
43
- });
44
- };
45
- export const mobileSelectionPlugin = () => ({
46
- name: 'mobileSelection',
47
- pmPlugins: () => [{
48
- name: 'mobileSelection',
49
- plugin: ({
50
- dispatch
51
- }) => createProseMirrorPlugin(dispatch)
52
- }]
53
- });
@@ -1 +0,0 @@
1
- export {};
@@ -1,73 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
4
- export const trackerStore = new WeakMap();
5
- class Tracker {
6
- constructor() {
7
- _defineProperty(this, "update", props => {
8
- this.subscriptions.forEach(cb => cb(props));
9
- });
10
- _defineProperty(this, "add", subscription => {
11
- this.subscriptions.push(subscription);
12
- });
13
- _defineProperty(this, "remove", subscription => {
14
- this.subscriptions = this.subscriptions.filter(s => s !== subscription);
15
- });
16
- this.subscriptions = [];
17
- }
18
- }
19
- const pluginKey = new PluginKey('viewUpdateSubscriptionKey');
20
- const createViewUpdateSubscriptionPlugin = () => {
21
- let tracker;
22
- const lastUpdateRef = {
23
- current: null,
24
- initial: null,
25
- transactions: [],
26
- queued: false
27
- };
28
- return {
29
- name: 'viewUpdateSubscription',
30
- pmPlugins: () => {
31
- const createPlugin = () => new SafePlugin({
32
- key: pluginKey,
33
- view(editorView) {
34
- tracker = trackerStore.get(editorView);
35
- if (!tracker) {
36
- tracker = new Tracker();
37
- trackerStore.set(editorView, tracker);
38
- }
39
- return {};
40
- }
41
- });
42
- return [{
43
- name: 'viewUpdateSubscription',
44
- plugin: createPlugin
45
- }];
46
- },
47
- onEditorViewStateUpdated(props) {
48
- lastUpdateRef.current = props;
49
- lastUpdateRef.transactions.push(...props.transactions);
50
- if (!lastUpdateRef.queued) {
51
- lastUpdateRef.initial = props;
52
- lastUpdateRef.queued = true;
53
- queueMicrotask(() => {
54
- if (!lastUpdateRef.current || !lastUpdateRef.initial) {
55
- return;
56
- }
57
- if (tracker) {
58
- var _lastUpdateRef$initia;
59
- tracker.update({
60
- newEditorState: lastUpdateRef.current.newEditorState,
61
- oldEditorState: (_lastUpdateRef$initia = lastUpdateRef.initial) === null || _lastUpdateRef$initia === void 0 ? void 0 : _lastUpdateRef$initia.oldEditorState,
62
- transactions: lastUpdateRef.transactions
63
- });
64
- }
65
- lastUpdateRef.queued = false;
66
- lastUpdateRef.current = null;
67
- lastUpdateRef.transactions = [];
68
- });
69
- }
70
- }
71
- };
72
- };
73
- export default createViewUpdateSubscriptionPlugin;
@@ -1,106 +0,0 @@
1
- import { areSameItems } from '@atlaskit/editor-common/floating-toolbar';
2
- import { trackerStore } from '..';
3
- const areToolbarsSame = (left, right) => {
4
- if (!left && !right) {
5
- return true;
6
- }
7
- if (left && !right || !left && right) {
8
- return false;
9
- }
10
- const leftConfig = left.config;
11
- const rightConfig = right.config;
12
- if (!leftConfig && !rightConfig) {
13
- return true;
14
- }
15
- if (!leftConfig && rightConfig || leftConfig && !rightConfig) {
16
- return false;
17
- }
18
- const leftItems = Array.isArray(leftConfig.items) ? leftConfig.items : leftConfig.items(left.node);
19
- const rightItems = Array.isArray(rightConfig.items) ? rightConfig.items : rightConfig.items(right.node);
20
- return areSameItems(leftItems, rightItems);
21
- };
22
- export const subscribeToToolbarAndPickerUpdates = (editorView, cb) => {
23
- let lastUpdatedState = null;
24
- const subscription = ({
25
- newEditorState
26
- }) => {
27
- // Creating fake plugin keys for these plugins for the mean time until all these plugins are extracted.
28
- const typeAheadPluginKey = {
29
- key: 'typeAheadPlugin$',
30
- getState: state => {
31
- return state['typeAheadPlugin$'];
32
- }
33
- };
34
- const datePluginKey = {
35
- key: 'datePlugin$',
36
- getState: state => {
37
- return state['datePlugin$'];
38
- }
39
- };
40
- const statusPluginKey = {
41
- key: 'statusPlugin$',
42
- getState: state => {
43
- return state['statusPlugin$'];
44
- }
45
- };
46
- const floatingToolbarPluginKey = {
47
- key: 'floatingToolbarPluginKey$',
48
- getState: state => {
49
- return state['floatingToolbarPluginKey$'];
50
- }
51
- };
52
- const isTypeAheadOpen = editorState => {
53
- var _typeAheadState$decor;
54
- const typeAheadState = typeAheadPluginKey.getState(newEditorState);
55
- return !!((_typeAheadState$decor = typeAheadState.decorationSet) !== null && _typeAheadState$decor !== void 0 && _typeAheadState$decor.find().length);
56
- };
57
- // TypeAhead has priority in the mobile-bridge
58
- // In case it is open we don't need to send
59
- // any toolbar updates don't need to be send
60
- if (isTypeAheadOpen(newEditorState)) {
61
- return;
62
- }
63
- const dateState = datePluginKey.getState(newEditorState);
64
- const statusState = statusPluginKey.getState(newEditorState);
65
- const {
66
- getConfigWithNodeInfo
67
- } = floatingToolbarPluginKey.getState(newEditorState);
68
- const toolbarConfig = getConfigWithNodeInfo(newEditorState);
69
- let shouldCallback = false;
70
- if (lastUpdatedState) {
71
- const oldDateState = datePluginKey.getState(lastUpdatedState);
72
- const oldStatusState = statusPluginKey.getState(lastUpdatedState);
73
- const {
74
- getConfigWithNodeInfo: getOldConfigWithNodeInfo
75
- } = floatingToolbarPluginKey.getState(lastUpdatedState);
76
- const oldToolbarConfig = getOldConfigWithNodeInfo(lastUpdatedState);
77
- const isToolbarEqual = areToolbarsSame(toolbarConfig, oldToolbarConfig);
78
- if (dateState !== oldDateState || statusState !== oldStatusState ||
79
- // Sometimes the toolbar changes while a picker is open, we dont care about this
80
- // EG A nested status or date node in a table
81
- !isToolbarEqual && !(statusState !== null && statusState !== void 0 && statusState.showStatusPickerAt) && !(dateState !== null && dateState !== void 0 && dateState.showDatePickerAt)) {
82
- shouldCallback = true;
83
- }
84
- } else {
85
- shouldCallback = true;
86
- }
87
- if (shouldCallback) {
88
- cb({
89
- dateState,
90
- statusState,
91
- toolbarConfig
92
- });
93
- }
94
- lastUpdatedState = newEditorState;
95
- };
96
- const tracker = trackerStore.get(editorView);
97
- if (tracker) {
98
- tracker.add(subscription);
99
- }
100
- return () => {
101
- const tracker = trackerStore.get(editorView);
102
- if (tracker) {
103
- tracker.remove(subscription);
104
- }
105
- };
106
- };
@@ -1,6 +0,0 @@
1
- export var MobileDimensionsActionTypes = /*#__PURE__*/function (MobileDimensionsActionTypes) {
2
- MobileDimensionsActionTypes["SET_WINDOW_HEIGHT"] = "SET_WINDOW_HEIGHT";
3
- MobileDimensionsActionTypes["SET_MOBILE_PADDING_TOP"] = "SET_MOBILE_PADDING_TOP";
4
- MobileDimensionsActionTypes["SET_IS_EXPANDED"] = "SET_IS_EXPANDED";
5
- return MobileDimensionsActionTypes;
6
- }({});
@@ -1,20 +0,0 @@
1
- import { MobileDimensionsActionTypes } from './actions';
2
- import { createCommand } from './plugin-factory';
3
- export var setWindowHeight = function setWindowHeight(windowHeight) {
4
- return createCommand({
5
- type: MobileDimensionsActionTypes.SET_WINDOW_HEIGHT,
6
- windowHeight: windowHeight
7
- });
8
- };
9
- export var setMobilePaddingTop = function setMobilePaddingTop(paddingTop) {
10
- return createCommand({
11
- type: MobileDimensionsActionTypes.SET_MOBILE_PADDING_TOP,
12
- paddingTop: paddingTop
13
- });
14
- };
15
- export var setIsExpanded = function setIsExpanded(isExpanded) {
16
- return createCommand({
17
- type: MobileDimensionsActionTypes.SET_IS_EXPANDED,
18
- isExpanded: isExpanded
19
- });
20
- };