@atlaskit/editor-plugin-table 0.0.1 → 0.0.2

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.
@@ -1,4 +1,5 @@
1
1
  import React from 'react';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
2
3
  import { browser } from '@atlaskit/editor-common/utils';
3
4
  import { tableEditing } from '@atlaskit/editor-tables/pm-plugins';
4
5
  import { createTable } from '@atlaskit/editor-tables/utils';
@@ -29,19 +30,31 @@ import LayoutButton from './ui/LayoutButton';
29
30
  import { isLayoutSupported } from './utils';
30
31
  import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
31
32
 
32
- var defaultGetEditorContainerWidth = function defaultGetEditorContainerWidth() {
33
- var _document, _document$body;
34
-
35
- return {
36
- width: ((_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.offsetWidth) || 500
37
- };
38
- };
39
-
40
33
  var defaultGetEditorFeatureFlags = function defaultGetEditorFeatureFlags() {
41
34
  return {};
42
35
  };
43
36
 
44
37
  var tablesPlugin = function tablesPlugin(options) {
38
+ var editorViewRef = {
39
+ current: null
40
+ };
41
+
42
+ var defaultGetEditorContainerWidth = function defaultGetEditorContainerWidth() {
43
+ if (!editorViewRef.current) {
44
+ var _document, _document$body;
45
+
46
+ return {
47
+ width: ((_document = document) === null || _document === void 0 ? void 0 : (_document$body = _document.body) === null || _document$body === void 0 ? void 0 : _document$body.offsetWidth) || 500
48
+ };
49
+ }
50
+
51
+ var state = editorViewRef.current.state; // TODO: ED-15663
52
+ // Please, do not copy or use this kind of code below
53
+ // @ts-ignore
54
+
55
+ return state['widthPlugin$'];
56
+ };
57
+
45
58
  return {
46
59
  name: 'table',
47
60
  nodes: function nodes() {
@@ -76,7 +89,7 @@ var tablesPlugin = function tablesPlugin(options) {
76
89
  editorAnalyticsAPI = _ref2.editorAnalyticsAPI,
77
90
  getEditorFeatureFlags = _ref2.getEditorFeatureFlags;
78
91
 
79
- return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), (options === null || options === void 0 ? void 0 : options.getEditorContainerWidth) || defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, breakoutEnabled, fullWidthEnabled, wasFullWidthEnabled, editorAnalyticsAPI);
92
+ return createPlugin(dispatchAnalyticsEvent, dispatch, portalProviderAPI, eventDispatcher, pluginConfig(tableOptions), defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, breakoutEnabled, fullWidthEnabled, wasFullWidthEnabled, editorAnalyticsAPI);
80
93
  }
81
94
  }, {
82
95
  name: 'tablePMColResizing',
@@ -87,7 +100,6 @@ var tablesPlugin = function tablesPlugin(options) {
87
100
  fullWidthEnabled = _ref4.fullWidthEnabled,
88
101
  tableOptions = _ref4.tableOptions,
89
102
  editorAnalyticsAPI = _ref4.editorAnalyticsAPI,
90
- getEditorContainerWidth = _ref4.getEditorContainerWidth,
91
103
  getEditorFeatureFlags = _ref4.getEditorFeatureFlags;
92
104
 
93
105
  var _pluginConfig = pluginConfig(tableOptions),
@@ -95,7 +107,7 @@ var tablesPlugin = function tablesPlugin(options) {
95
107
 
96
108
  return allowColumnResizing ? createFlexiResizingPlugin(dispatch, {
97
109
  lastColumnResizable: !fullWidthEnabled
98
- }, getEditorContainerWidth || defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI) : undefined;
110
+ }, defaultGetEditorContainerWidth, getEditorFeatureFlags || defaultGetEditorFeatureFlags, editorAnalyticsAPI) : undefined;
99
111
  }
100
112
  }, {
101
113
  name: 'tableEditing',
@@ -107,7 +119,7 @@ var tablesPlugin = function tablesPlugin(options) {
107
119
  {
108
120
  name: 'tableKeymap',
109
121
  plugin: function plugin() {
110
- return keymapPlugin((options === null || options === void 0 ? void 0 : options.getEditorContainerWidth) || defaultGetEditorContainerWidth, options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI);
122
+ return keymapPlugin(defaultGetEditorContainerWidth, options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI);
111
123
  }
112
124
  }, {
113
125
  name: 'tableSelectionKeymap',
@@ -134,6 +146,20 @@ var tablesPlugin = function tablesPlugin(options) {
134
146
  var dispatch = _ref6.dispatch;
135
147
  return createTableLocalIdPlugin(dispatch);
136
148
  }
149
+ }, {
150
+ name: 'tableGetEditorViewReferencePlugin',
151
+ plugin: function plugin() {
152
+ return new SafePlugin({
153
+ view: function view(editorView) {
154
+ editorViewRef.current = editorView;
155
+ return {
156
+ destroy: function destroy() {
157
+ editorViewRef.current = null;
158
+ }
159
+ };
160
+ }
161
+ });
162
+ }
137
163
  }]; // workaround for prosemirrors delayed dom selection syncing during pointer drag
138
164
  // causing issues with table selections in Safari
139
165
  // https://github.com/ProseMirror/prosemirror-view/commit/885258b80551ac87b81601d3ed25f552aeb22293
@@ -224,7 +250,7 @@ var tablesPlugin = function tablesPlugin(options) {
224
250
  hasStickyHeaders: stickyHeader && stickyHeader.sticky,
225
251
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
226
252
  editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI,
227
- getEditorContainerWidth: (options === null || options === void 0 ? void 0 : options.getEditorContainerWidth) || defaultGetEditorContainerWidth
253
+ getEditorContainerWidth: defaultGetEditorContainerWidth
228
254
  }), /*#__PURE__*/React.createElement(FloatingContextualMenu, {
229
255
  editorView: editorView,
230
256
  mountPoint: popupsMountPoint,
@@ -233,7 +259,7 @@ var tablesPlugin = function tablesPlugin(options) {
233
259
  isOpen: Boolean(isContextualMenuOpen),
234
260
  pluginConfig: pluginConfig,
235
261
  editorAnalyticsAPI: options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI,
236
- getEditorContainerWidth: (options === null || options === void 0 ? void 0 : options.getEditorContainerWidth) || defaultGetEditorContainerWidth
262
+ getEditorContainerWidth: defaultGetEditorContainerWidth
237
263
  }), allowControls && /*#__PURE__*/React.createElement(FloatingDeleteButton, {
238
264
  editorView: editorView,
239
265
  selection: editorView.state.selection,
@@ -304,7 +330,7 @@ var tablesPlugin = function tablesPlugin(options) {
304
330
  }
305
331
  }];
306
332
  },
307
- floatingToolbar: getToolbarConfig((options === null || options === void 0 ? void 0 : options.getEditorContainerWidth) || defaultGetEditorContainerWidth, options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI)(pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions))
333
+ floatingToolbar: getToolbarConfig(defaultGetEditorContainerWidth, options === null || options === void 0 ? void 0 : options.editorAnalyticsAPI)(pluginConfig(options === null || options === void 0 ? void 0 : options.tableOptions))
308
334
  }
309
335
  };
310
336
  };
@@ -1,4 +1,4 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.1"
3
+ "version": "0.0.2"
4
4
  }
@@ -2,7 +2,7 @@ import type { EditorPlugin } from '@atlaskit/editor-common/types';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
3
  import type { EditorSelectionAPI } from '@atlaskit/editor-common/selection';
4
4
  import { PluginConfig } from './types';
5
- import type { GetEditorContainerWidth, GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
5
+ import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
6
6
  interface TablePluginOptions {
7
7
  tableOptions: PluginConfig;
8
8
  breakoutEnabled?: boolean;
@@ -11,7 +11,6 @@ interface TablePluginOptions {
11
11
  wasFullWidthEnabled?: boolean;
12
12
  editorAnalyticsAPI?: EditorAnalyticsAPI;
13
13
  editorSelectionAPI?: EditorSelectionAPI;
14
- getEditorContainerWidth?: GetEditorContainerWidth;
15
14
  getEditorFeatureFlags?: GetEditorFeatureFlags;
16
15
  }
17
16
  declare const tablesPlugin: (options?: TablePluginOptions | undefined) => EditorPlugin;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-table",
3
- "version": "0.0.1",
3
+ "version": "0.0.2",
4
4
  "description": "Table plugin for the @atlaskit/editor",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
package/report.api.md CHANGED
@@ -1,6 +1,10 @@
1
- ## API Report File for "@atlaskit/editor-plugin-table".
1
+ ## API Report File for "@atlaskit/editor-plugin-table"
2
2
 
3
- > Do not edit this file. This report is auto-generated by [API Extractor](https://api-extractor.com/).
3
+ > Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
4
+
5
+ <!--
6
+ Generated API Report version: 2.0
7
+ -->
4
8
 
5
9
  [Learn more about API reports](https://hello.atlassian.net/wiki/spaces/UR/pages/1825484529/Package+API+Reports)
6
10
 
@@ -8,53 +12,86 @@
8
12
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
9
13
  import type { EditorPlugin } from '@atlaskit/editor-common/types';
10
14
  import type { EditorSelectionAPI } from '@atlaskit/editor-common/selection';
11
- import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
12
15
  import type { GetEditorFeatureFlags } from '@atlaskit/editor-common/types';
13
16
  import { TableLayout } from '@atlaskit/adf-schema';
14
17
 
15
- declare type PermittedLayoutsDescriptor = TableLayout[] | 'all';
18
+ // @public (undocumented)
19
+ type PermittedLayoutsDescriptor = TableLayout[] | 'all';
16
20
 
17
- declare interface PluginConfig {
21
+ // @public (undocumented)
22
+ interface PluginConfig {
23
+ // (undocumented)
18
24
  advanced?: boolean;
25
+ // (undocumented)
26
+ allowAddColumnWithCustomStep?: boolean;
27
+ // (undocumented)
19
28
  allowBackgroundColor?: boolean;
29
+ // (undocumented)
30
+ allowCellOptionsInFloatingToolbar?: boolean;
31
+ // (undocumented)
32
+ allowCollapse?: boolean;
33
+ // (undocumented)
20
34
  allowColumnResizing?: boolean;
35
+ // (undocumented)
36
+ allowColumnSorting?: boolean;
37
+ // (undocumented)
38
+ allowControls?: boolean;
39
+ // (undocumented)
40
+ allowDistributeColumns?: boolean;
41
+ // (undocumented)
21
42
  allowHeaderColumn?: boolean;
43
+ // (undocumented)
22
44
  allowHeaderRow?: boolean;
45
+ // (undocumented)
23
46
  allowMergeCells?: boolean;
47
+ // (undocumented)
24
48
  allowNumberColumn?: boolean;
25
- allowColumnSorting?: boolean;
26
- allowAddColumnWithCustomStep?: boolean;
27
- allowCollapse?: boolean;
49
+ // (undocumented)
50
+ initialRenderOptimization?: boolean;
51
+ // (undocumented)
28
52
  isHeaderRowRequired?: boolean;
29
- stickToolbarToBottom?: boolean;
53
+ // (undocumented)
54
+ mouseMoveOptimization?: boolean;
55
+ // (undocumented)
30
56
  permittedLayouts?: PermittedLayoutsDescriptor;
31
- allowControls?: boolean;
57
+ // (undocumented)
58
+ stickToolbarToBottom?: boolean;
59
+ // (undocumented)
32
60
  stickyHeaders?: boolean;
33
- allowCellOptionsInFloatingToolbar?: boolean;
34
- tableCellOptimization?: boolean;
35
- tableRenderOptimization?: boolean;
61
+ // (undocumented)
36
62
  stickyHeadersOptimization?: boolean;
37
- initialRenderOptimization?: boolean;
38
- mouseMoveOptimization?: boolean;
63
+ // (undocumented)
64
+ tableCellOptimization?: boolean;
65
+ // (undocumented)
39
66
  tableOverflowShadowsOptimization?: boolean;
40
- allowDistributeColumns?: boolean;
67
+ // (undocumented)
68
+ tableRenderOptimization?: boolean;
41
69
  }
42
70
 
43
- declare interface TablePluginOptions {
44
- tableOptions: PluginConfig;
45
- breakoutEnabled?: boolean;
71
+ // @public (undocumented)
72
+ interface TablePluginOptions {
73
+ // (undocumented)
46
74
  allowContextualMenu?: boolean;
47
- fullWidthEnabled?: boolean;
48
- wasFullWidthEnabled?: boolean;
75
+ // (undocumented)
76
+ breakoutEnabled?: boolean;
77
+ // (undocumented)
49
78
  editorAnalyticsAPI?: EditorAnalyticsAPI;
79
+ // (undocumented)
50
80
  editorSelectionAPI?: EditorSelectionAPI;
51
- getEditorContainerWidth?: GetEditorContainerWidth;
81
+ // (undocumented)
82
+ fullWidthEnabled?: boolean;
83
+ // (undocumented)
52
84
  getEditorFeatureFlags?: GetEditorFeatureFlags;
85
+ // (undocumented)
86
+ tableOptions: PluginConfig;
87
+ // (undocumented)
88
+ wasFullWidthEnabled?: boolean;
53
89
  }
54
90
 
55
- export declare const tablesPlugin: (
91
+ // @public (undocumented)
92
+ export const tablesPlugin: (
56
93
  options?: TablePluginOptions | undefined,
57
94
  ) => EditorPlugin;
58
95
 
59
- export {};
96
+ // (No @packageDocumentation comment for this package)
60
97
  ```
@@ -41,7 +41,6 @@ describe('table plugin: insert', () => {
41
41
  preset.add([
42
42
  tablePlugin,
43
43
  {
44
- getEditorContainerWidth: () => ({ width: mockBodyOffsetWidth }),
45
44
  tableOptions: {},
46
45
  },
47
46
  ]);
@@ -23,6 +23,7 @@ import tablePlugin from '../../../../../table';
23
23
  import { pluginKey } from '../../../../pm-plugins/plugin-key';
24
24
  import { TextSelection, NodeSelection } from 'prosemirror-state';
25
25
  import panelPlugin from '@atlaskit/editor-core/src/plugins/panel';
26
+ import widthPlugin from '@atlaskit/editor-core/src/plugins/width';
26
27
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
27
28
 
28
29
  describe('table-resizing/event-handlers', () => {
@@ -44,6 +45,7 @@ describe('table-resizing/event-handlers', () => {
44
45
  editorAnalyticsAPI: editorAnalyticsAPIFake,
45
46
  },
46
47
  ])
48
+ .add(widthPlugin)
47
49
  .add(panelPlugin),
48
50
  pluginKey,
49
51
  });