@atlaskit/editor-plugin-table 7.16.3 → 7.16.5
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 +16 -0
- package/dist/cjs/commands/insert.js +15 -6
- package/dist/cjs/plugin.js +16 -6
- package/dist/cjs/pm-plugins/keymap.js +5 -4
- package/dist/cjs/pm-plugins/table-width.js +13 -6
- package/dist/cjs/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
- package/dist/cjs/utils/alignment.js +5 -2
- package/dist/cjs/utils/create.js +12 -7
- package/dist/es2019/commands/insert.js +15 -6
- package/dist/es2019/plugin.js +15 -6
- package/dist/es2019/pm-plugins/keymap.js +2 -2
- package/dist/es2019/pm-plugins/table-width.js +13 -6
- package/dist/es2019/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
- package/dist/es2019/utils/alignment.js +4 -1
- package/dist/es2019/utils/create.js +13 -7
- package/dist/esm/commands/insert.js +15 -6
- package/dist/esm/plugin.js +16 -6
- package/dist/esm/pm-plugins/keymap.js +5 -4
- package/dist/esm/pm-plugins/table-width.js +13 -6
- package/dist/esm/ui/TableFloatingColumnControls/ColumnControls/index.js +6 -2
- package/dist/esm/utils/alignment.js +4 -1
- package/dist/esm/utils/create.js +12 -7
- package/dist/types/commands/insert.d.ts +2 -2
- package/dist/types/pm-plugins/keymap.d.ts +1 -1
- package/dist/types/pm-plugins/table-width.d.ts +1 -1
- package/dist/types/utils/alignment.d.ts +2 -0
- package/dist/types/utils/create.d.ts +8 -3
- package/dist/types-ts4.5/commands/insert.d.ts +2 -2
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/table-width.d.ts +1 -1
- package/dist/types-ts4.5/utils/alignment.d.ts +2 -0
- package/dist/types-ts4.5/utils/create.d.ts +8 -3
- package/package.json +1 -1
- package/src/commands/insert.ts +28 -22
- package/src/plugin.tsx +14 -8
- package/src/pm-plugins/keymap.ts +2 -0
- package/src/pm-plugins/table-width.ts +19 -5
- package/src/ui/TableFloatingColumnControls/ColumnControls/index.tsx +18 -7
- package/src/utils/alignment.ts +4 -1
- package/src/utils/create.ts +24 -10
|
@@ -11,14 +11,15 @@ import { moveSourceWithAnalyticsViaShortcut } from '../pm-plugins/drag-and-drop/
|
|
|
11
11
|
export function keymapPlugin(getEditorContainerWidth, editorAnalyticsAPI, dragAndDropEnabled) {
|
|
12
12
|
var _pluginInjectionApi$a;
|
|
13
13
|
var isTableScalingEnabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
14
|
-
var
|
|
15
|
-
var
|
|
16
|
-
var
|
|
14
|
+
var isTableAlignmentEnabled = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
|
|
15
|
+
var isFullWidthEnabled = arguments.length > 5 ? arguments[5] : undefined;
|
|
16
|
+
var pluginInjectionApi = arguments.length > 6 ? arguments[6] : undefined;
|
|
17
|
+
var getIntl = arguments.length > 7 ? arguments[7] : undefined;
|
|
17
18
|
var list = {};
|
|
18
19
|
var ariaNotifyPlugin = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.accessibilityUtils) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.ariaNotify;
|
|
19
20
|
bindKeymapWithCommand(nextCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(1), list);
|
|
20
21
|
bindKeymapWithCommand(previousCell.common, goToNextCell(editorAnalyticsAPI, ariaNotifyPlugin, getIntl)(-1), list);
|
|
21
|
-
bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
22
|
+
bindKeymapWithCommand(toggleTable.common, createTable(isTableScalingEnabled, isTableAlignmentEnabled, !!isFullWidthEnabled, editorAnalyticsAPI), list);
|
|
22
23
|
bindKeymapWithCommand(backspace.common, chainCommands(deleteTableIfSelectedWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD), emptyMultipleCellsWithAnalytics(editorAnalyticsAPI)(INPUT_METHOD.KEYBOARD)), list);
|
|
23
24
|
bindKeymapWithCommand(backspace.common, moveCursorBackward, list);
|
|
24
25
|
|
|
@@ -16,9 +16,10 @@ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
|
16
16
|
import { ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
17
17
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
18
18
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
19
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
19
20
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
20
21
|
export var pluginKey = new PluginKey('tableWidthPlugin');
|
|
21
|
-
var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled) {
|
|
22
|
+
var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullWidthEnabled, isTableScalingEnabled, isTableAlignmentEnabled) {
|
|
22
23
|
return new SafePlugin({
|
|
23
24
|
key: pluginKey,
|
|
24
25
|
state: {
|
|
@@ -91,8 +92,9 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
91
92
|
var referentialityTr = transactions.find(function (tr) {
|
|
92
93
|
return tr.getMeta('referentialityTableInserted');
|
|
93
94
|
});
|
|
94
|
-
var
|
|
95
|
-
|
|
95
|
+
var shouldPatchTableWidth = fullWidthEnabled && isTableScalingEnabled;
|
|
96
|
+
var shouldPatchTableAlignment = fullWidthEnabled && isTableAlignmentEnabled;
|
|
97
|
+
if (!isReplaceDocumentOperation && (!shouldPatchTableWidth && !shouldPatchTableAlignment || !referentialityTr)) {
|
|
96
98
|
return null;
|
|
97
99
|
}
|
|
98
100
|
var table = newState.schema.nodes.table;
|
|
@@ -152,10 +154,15 @@ var createPlugin = function createPlugin(dispatch, dispatchAnalyticsEvent, fullW
|
|
|
152
154
|
}
|
|
153
155
|
if (referentialityTr) {
|
|
154
156
|
referentialityTr.steps.forEach(function (step) {
|
|
155
|
-
step.getMap().forEach(function (
|
|
157
|
+
step.getMap().forEach(function (_, __, newStart, newEnd) {
|
|
156
158
|
newState.doc.nodesBetween(newStart, newEnd, function (node, pos) {
|
|
157
|
-
if (node.type === table
|
|
158
|
-
|
|
159
|
+
if (node.type === table) {
|
|
160
|
+
if (shouldPatchTableWidth && node.attrs.width !== TABLE_MAX_WIDTH) {
|
|
161
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
162
|
+
}
|
|
163
|
+
if (shouldPatchTableAlignment) {
|
|
164
|
+
tr.setNodeAttribute(pos, 'layout', ALIGN_START);
|
|
165
|
+
}
|
|
159
166
|
}
|
|
160
167
|
});
|
|
161
168
|
});
|
|
@@ -117,6 +117,7 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
117
117
|
var generateHandleByType = function generateHandleByType(type, appearance, gridColumn, indexes) {
|
|
118
118
|
var _rowHeights$reduce, _colWidths$reduce;
|
|
119
119
|
var isHover = type === 'hover';
|
|
120
|
+
var isPlaceholder = appearance === 'placeholder';
|
|
120
121
|
var previewHeight = (_rowHeights$reduce = rowHeights === null || rowHeights === void 0 ? void 0 : rowHeights.reduce(function (sum, cur) {
|
|
121
122
|
return sum + cur;
|
|
122
123
|
}, 0)) !== null && _rowHeights$reduce !== void 0 ? _rowHeights$reduce : 0;
|
|
@@ -138,7 +139,7 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
138
139
|
width: '100%',
|
|
139
140
|
position: 'relative'
|
|
140
141
|
},
|
|
141
|
-
"data-testid": "table-floating-column-".concat(isHover ? colIndex : selectedColIndexes[0], "-drag-handle")
|
|
142
|
+
"data-testid": "table-floating-column-".concat(isHover ? colIndex : isPlaceholder ? appearance : selectedColIndexes[0], "-drag-handle")
|
|
142
143
|
}, /*#__PURE__*/React.createElement(DragHandle, {
|
|
143
144
|
isDragMenuTarget: !isHover,
|
|
144
145
|
direction: "column",
|
|
@@ -163,10 +164,13 @@ export var ColumnControls = function ColumnControls(_ref) {
|
|
|
163
164
|
if (!tableActive) {
|
|
164
165
|
return null;
|
|
165
166
|
}
|
|
167
|
+
var selectedAppearance = isColumnSelected && isEntireTableSelected ? isInDanger ? 'danger' : 'selected' : 'placeholder';
|
|
166
168
|
|
|
167
169
|
// placeholder / selected need to always render at least one handle
|
|
168
170
|
// so it can be focused via keyboard shortcuts
|
|
169
|
-
handles.push(generateHandleByType('selected',
|
|
171
|
+
handles.push(generateHandleByType('selected', selectedAppearance,
|
|
172
|
+
// always position placeholder in first column to avoid overflow issues
|
|
173
|
+
selectedAppearance === 'placeholder' ? '1 / span 1' : "".concat(selectedColIndexes[0] + 1, " / span ").concat(selectedColIndexes.length), selectedColIndexes));
|
|
170
174
|
if (hoveredCell && isTableHovered && colIndex !== undefined && !selectedColIndexes.includes(colIndex)) {
|
|
171
175
|
handles.push(generateHandleByType('hover', 'default', "".concat(colIndex + 1, " / span 1"), colIndexes));
|
|
172
176
|
}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
+
export var ALIGN_START = 'align-start';
|
|
2
|
+
export var ALIGN_CENTER = 'center';
|
|
3
|
+
|
|
1
4
|
/**
|
|
2
5
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
3
6
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
4
7
|
*/
|
|
5
8
|
export var normaliseAlignment = function normaliseAlignment(layout) {
|
|
6
|
-
return layout ===
|
|
9
|
+
return layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
|
7
10
|
};
|
package/dist/esm/utils/create.js
CHANGED
|
@@ -3,16 +3,21 @@ 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 { createTable } from '@atlaskit/editor-tables/utils';
|
|
5
5
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
6
|
-
export var createTableWithWidth = function createTableWithWidth(
|
|
6
|
+
export var createTableWithWidth = function createTableWithWidth(_ref) {
|
|
7
|
+
var isTableScalingEnabled = _ref.isTableScalingEnabled,
|
|
8
|
+
isTableAlignmentEnabled = _ref.isTableAlignmentEnabled,
|
|
9
|
+
isFullWidthModeEnabled = _ref.isFullWidthModeEnabled,
|
|
10
|
+
createTableProps = _ref.createTableProps;
|
|
7
11
|
return function (schema) {
|
|
12
|
+
var attrsOverrides = {};
|
|
8
13
|
if (isTableScalingEnabled && isFullWidthModeEnabled) {
|
|
9
|
-
|
|
10
|
-
schema: schema,
|
|
11
|
-
tableWidth: TABLE_MAX_WIDTH
|
|
12
|
-
}, createTableProps));
|
|
14
|
+
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
13
15
|
}
|
|
14
|
-
|
|
16
|
+
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
17
|
+
attrsOverrides.layout = 'align-start';
|
|
18
|
+
}
|
|
19
|
+
return createTable(_objectSpread(_objectSpread({
|
|
15
20
|
schema: schema
|
|
16
|
-
}, createTableProps));
|
|
21
|
+
}, createTableProps), attrsOverrides));
|
|
17
22
|
};
|
|
18
23
|
};
|
|
@@ -8,5 +8,5 @@ export declare const addColumnBefore: (isTableScalingEnabled?: boolean) => Comma
|
|
|
8
8
|
export declare const addColumnAfter: (isTableScalingEnabled?: boolean) => Command;
|
|
9
9
|
export declare const insertColumn: (isTableScalingEnabled?: boolean, isCellBackgroundDuplicated?: boolean) => (column: number) => Command;
|
|
10
10
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean, isCellBackgroundDuplicated?: boolean) => Command;
|
|
11
|
-
export declare const createTable: (isTableScalingEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
-
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
11
|
+
export declare const createTable: (isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
+
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
@@ -3,5 +3,5 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { PluginInjectionAPIWithA11y } from '../types';
|
|
6
|
-
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
6
|
+
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
7
7
|
export default keymapPlugin;
|
|
@@ -13,7 +13,7 @@ type TableWidthPluginState = {
|
|
|
13
13
|
tableRef: HTMLTableElement | null;
|
|
14
14
|
};
|
|
15
15
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
16
|
-
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
|
|
16
|
+
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean) => SafePlugin<{
|
|
17
17
|
resizing: boolean;
|
|
18
18
|
tableLocalId: string;
|
|
19
19
|
tableRef: null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { AlignmentOptions } from '../types';
|
|
3
|
+
export declare const ALIGN_START = "align-start";
|
|
4
|
+
export declare const ALIGN_CENTER = "center";
|
|
3
5
|
/**
|
|
4
6
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
5
7
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export declare const createTableWithWidth: (isTableScalingEnabled
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const createTableWithWidth: ({ isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, createTableProps, }: {
|
|
3
|
+
isTableScalingEnabled?: boolean | undefined;
|
|
4
|
+
isTableAlignmentEnabled?: boolean | undefined;
|
|
5
|
+
isFullWidthModeEnabled?: boolean | undefined;
|
|
6
|
+
createTableProps?: {
|
|
7
|
+
rowsCount?: number | undefined;
|
|
8
|
+
colsCount?: number | undefined;
|
|
9
|
+
} | undefined;
|
|
5
10
|
}) => (schema: Schema) => import("prosemirror-model").Node;
|
|
@@ -8,5 +8,5 @@ export declare const addColumnBefore: (isTableScalingEnabled?: boolean) => Comma
|
|
|
8
8
|
export declare const addColumnAfter: (isTableScalingEnabled?: boolean) => Command;
|
|
9
9
|
export declare const insertColumn: (isTableScalingEnabled?: boolean, isCellBackgroundDuplicated?: boolean) => (column: number) => Command;
|
|
10
10
|
export declare const insertRow: (row: number, moveCursorToTheNewRow: boolean, isCellBackgroundDuplicated?: boolean) => Command;
|
|
11
|
-
export declare const createTable: (isTableScalingEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
-
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
11
|
+
export declare const createTable: (isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthModeEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null) => Command;
|
|
12
|
+
export declare const insertTableWithSize: (isFullWidthModeEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, editorAnalyticsAPI?: EditorAnalyticsAPI) => (rowsCount: number, colsCount: number, inputMethod?: INPUT_METHOD.PICKER) => EditorCommand;
|
|
@@ -3,5 +3,5 @@ import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
|
|
|
3
3
|
import type { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
4
4
|
import type { GetEditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
5
5
|
import type { PluginInjectionAPIWithA11y } from '../types';
|
|
6
|
-
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
6
|
+
export declare function keymapPlugin(getEditorContainerWidth: GetEditorContainerWidth, editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null, dragAndDropEnabled?: boolean, isTableScalingEnabled?: boolean, isTableAlignmentEnabled?: boolean, isFullWidthEnabled?: boolean, pluginInjectionApi?: PluginInjectionAPIWithA11y, getIntl?: () => IntlShape): SafePlugin;
|
|
7
7
|
export default keymapPlugin;
|
|
@@ -13,7 +13,7 @@ type TableWidthPluginState = {
|
|
|
13
13
|
tableRef: HTMLTableElement | null;
|
|
14
14
|
};
|
|
15
15
|
export declare const pluginKey: PluginKey<TableWidthPluginState>;
|
|
16
|
-
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean) => SafePlugin<{
|
|
16
|
+
declare const createPlugin: (dispatch: Dispatch, dispatchAnalyticsEvent: DispatchAnalyticsEvent, fullWidthEnabled: boolean, isTableScalingEnabled: boolean, isTableAlignmentEnabled: boolean) => SafePlugin<{
|
|
17
17
|
resizing: boolean;
|
|
18
18
|
tableLocalId: string;
|
|
19
19
|
tableRef: null;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { TableLayout } from '@atlaskit/adf-schema';
|
|
2
2
|
import type { AlignmentOptions } from '../types';
|
|
3
|
+
export declare const ALIGN_START = "align-start";
|
|
4
|
+
export declare const ALIGN_CENTER = "center";
|
|
3
5
|
/**
|
|
4
6
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
5
7
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
|
-
export declare const createTableWithWidth: (isTableScalingEnabled
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
export declare const createTableWithWidth: ({ isTableScalingEnabled, isTableAlignmentEnabled, isFullWidthModeEnabled, createTableProps, }: {
|
|
3
|
+
isTableScalingEnabled?: boolean | undefined;
|
|
4
|
+
isTableAlignmentEnabled?: boolean | undefined;
|
|
5
|
+
isFullWidthModeEnabled?: boolean | undefined;
|
|
6
|
+
createTableProps?: {
|
|
7
|
+
rowsCount?: number | undefined;
|
|
8
|
+
colsCount?: number | undefined;
|
|
9
|
+
} | undefined;
|
|
5
10
|
}) => (schema: Schema) => import("prosemirror-model").Node;
|
package/package.json
CHANGED
package/src/commands/insert.ts
CHANGED
|
@@ -201,37 +201,42 @@ export const insertRow =
|
|
|
201
201
|
return true;
|
|
202
202
|
};
|
|
203
203
|
|
|
204
|
-
export const createTable =
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
204
|
+
export const createTable =
|
|
205
|
+
(
|
|
206
|
+
isTableScalingEnabled?: boolean,
|
|
207
|
+
isTableAlignmentEnabled?: boolean,
|
|
208
|
+
isFullWidthModeEnabled?: boolean,
|
|
209
|
+
editorAnalyticsAPI?: EditorAnalyticsAPI | undefined | null,
|
|
210
|
+
): Command =>
|
|
211
|
+
(state, dispatch) => {
|
|
212
|
+
const table = createTableWithWidth({
|
|
213
|
+
isTableScalingEnabled,
|
|
214
|
+
isTableAlignmentEnabled,
|
|
215
|
+
isFullWidthModeEnabled,
|
|
216
|
+
})(state.schema);
|
|
213
217
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
if (dispatch) {
|
|
219
|
+
const tr = safeInsert(table)(state.tr).scrollIntoView();
|
|
220
|
+
if (editorAnalyticsAPI) {
|
|
221
|
+
editorAnalyticsAPI?.attachAnalyticsEvent({
|
|
218
222
|
action: ACTION.INSERTED,
|
|
219
223
|
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
220
224
|
actionSubjectId: ACTION_SUBJECT_ID.TABLE,
|
|
221
225
|
attributes: { inputMethod: INPUT_METHOD.SHORTCUT },
|
|
222
226
|
eventType: EVENT_TYPE.TRACK,
|
|
223
|
-
|
|
227
|
+
})(tr);
|
|
228
|
+
}
|
|
229
|
+
dispatch(tr);
|
|
224
230
|
}
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
return true;
|
|
229
|
-
}
|
|
231
|
+
|
|
232
|
+
return true;
|
|
233
|
+
};
|
|
230
234
|
|
|
231
235
|
export const insertTableWithSize =
|
|
232
236
|
(
|
|
233
237
|
isFullWidthModeEnabled?: boolean,
|
|
234
238
|
isTableScalingEnabled?: boolean,
|
|
239
|
+
isTableAlignmentEnabled?: boolean,
|
|
235
240
|
editorAnalyticsAPI?: EditorAnalyticsAPI,
|
|
236
241
|
) =>
|
|
237
242
|
(
|
|
@@ -240,14 +245,15 @@ export const insertTableWithSize =
|
|
|
240
245
|
inputMethod?: INPUT_METHOD.PICKER,
|
|
241
246
|
): EditorCommand => {
|
|
242
247
|
return ({ tr }) => {
|
|
243
|
-
const tableNode = createTableWithWidth(
|
|
248
|
+
const tableNode = createTableWithWidth({
|
|
244
249
|
isTableScalingEnabled,
|
|
245
250
|
isFullWidthModeEnabled,
|
|
246
|
-
|
|
251
|
+
isTableAlignmentEnabled,
|
|
252
|
+
createTableProps: {
|
|
247
253
|
rowsCount: rowsCount,
|
|
248
254
|
colsCount: colsCount,
|
|
249
255
|
},
|
|
250
|
-
)(tr.doc.type.schema);
|
|
256
|
+
})(tr.doc.type.schema);
|
|
251
257
|
|
|
252
258
|
const newTr = safeInsert(tableNode)(tr).scrollIntoView();
|
|
253
259
|
if (inputMethod) {
|
package/src/plugin.tsx
CHANGED
|
@@ -199,10 +199,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
199
199
|
insertTable:
|
|
200
200
|
(analyticsPayload): Command =>
|
|
201
201
|
(state, dispatch) => {
|
|
202
|
-
const node = createTableWithWidth(
|
|
203
|
-
options?.isTableScalingEnabled,
|
|
204
|
-
options?.
|
|
205
|
-
|
|
202
|
+
const node = createTableWithWidth({
|
|
203
|
+
isTableScalingEnabled: options?.isTableScalingEnabled,
|
|
204
|
+
isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
|
|
205
|
+
isFullWidthModeEnabled: options?.fullWidthEnabled,
|
|
206
|
+
})(state.schema);
|
|
206
207
|
|
|
207
208
|
return (
|
|
208
209
|
api?.contentInsertion?.actions?.insert({
|
|
@@ -229,6 +230,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
229
230
|
insertTableWithSize: insertTableWithSize(
|
|
230
231
|
options?.fullWidthEnabled,
|
|
231
232
|
options?.isTableScalingEnabled,
|
|
233
|
+
options?.isTableAlignmentEnabled,
|
|
232
234
|
api?.analytics?.actions,
|
|
233
235
|
),
|
|
234
236
|
},
|
|
@@ -318,6 +320,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
318
320
|
const {
|
|
319
321
|
dragAndDropEnabled,
|
|
320
322
|
isTableScalingEnabled = false,
|
|
323
|
+
isTableAlignmentEnabled = false,
|
|
321
324
|
fullWidthEnabled = false,
|
|
322
325
|
} = options || ({} as TablePluginOptions);
|
|
323
326
|
return keymapPlugin(
|
|
@@ -325,6 +328,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
325
328
|
editorAnalyticsAPI,
|
|
326
329
|
dragAndDropEnabled,
|
|
327
330
|
isTableScalingEnabled,
|
|
331
|
+
isTableAlignmentEnabled,
|
|
328
332
|
fullWidthEnabled,
|
|
329
333
|
api,
|
|
330
334
|
getIntl,
|
|
@@ -401,6 +405,7 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
401
405
|
dispatchAnalyticsEvent,
|
|
402
406
|
options?.fullWidthEnabled ?? false,
|
|
403
407
|
options?.isTableScalingEnabled ?? false,
|
|
408
|
+
options?.isTableAlignmentEnabled ?? false,
|
|
404
409
|
)
|
|
405
410
|
: undefined,
|
|
406
411
|
},
|
|
@@ -644,10 +649,11 @@ const tablesPlugin: TablePlugin = ({ config: options, api }) => {
|
|
|
644
649
|
// see comment on tablesPlugin.getSharedState on usage
|
|
645
650
|
const tableState = api?.table?.sharedState.currentState();
|
|
646
651
|
|
|
647
|
-
const tableNode = createTableWithWidth(
|
|
648
|
-
options?.isTableScalingEnabled,
|
|
649
|
-
|
|
650
|
-
|
|
652
|
+
const tableNode = createTableWithWidth({
|
|
653
|
+
isTableScalingEnabled: options?.isTableScalingEnabled,
|
|
654
|
+
isTableAlignmentEnabled: options?.isTableAlignmentEnabled,
|
|
655
|
+
isFullWidthModeEnabled: tableState?.isFullWidthModeEnabled,
|
|
656
|
+
})(state.schema);
|
|
651
657
|
|
|
652
658
|
const tr = insert(tableNode);
|
|
653
659
|
|
package/src/pm-plugins/keymap.ts
CHANGED
|
@@ -57,6 +57,7 @@ export function keymapPlugin(
|
|
|
57
57
|
editorAnalyticsAPI: EditorAnalyticsAPI | undefined | null,
|
|
58
58
|
dragAndDropEnabled?: boolean,
|
|
59
59
|
isTableScalingEnabled = false,
|
|
60
|
+
isTableAlignmentEnabled = false,
|
|
60
61
|
isFullWidthEnabled?: boolean,
|
|
61
62
|
pluginInjectionApi?: PluginInjectionAPIWithA11y,
|
|
62
63
|
getIntl?: () => IntlShape,
|
|
@@ -80,6 +81,7 @@ export function keymapPlugin(
|
|
|
80
81
|
toggleTable.common!,
|
|
81
82
|
createTable(
|
|
82
83
|
isTableScalingEnabled,
|
|
84
|
+
isTableAlignmentEnabled,
|
|
83
85
|
!!isFullWidthEnabled,
|
|
84
86
|
editorAnalyticsAPI,
|
|
85
87
|
),
|
|
@@ -23,6 +23,8 @@ import {
|
|
|
23
23
|
} from '@atlaskit/editor-shared-styles';
|
|
24
24
|
import { findTable } from '@atlaskit/editor-tables/utils';
|
|
25
25
|
|
|
26
|
+
import { ALIGN_START } from '../utils/alignment';
|
|
27
|
+
|
|
26
28
|
import { TABLE_MAX_WIDTH } from './table-resizing/utils';
|
|
27
29
|
|
|
28
30
|
type __ReplaceStep = ReplaceStep & {
|
|
@@ -46,6 +48,7 @@ const createPlugin = (
|
|
|
46
48
|
dispatchAnalyticsEvent: DispatchAnalyticsEvent,
|
|
47
49
|
fullWidthEnabled: boolean,
|
|
48
50
|
isTableScalingEnabled: boolean,
|
|
51
|
+
isTableAlignmentEnabled: boolean,
|
|
49
52
|
) => {
|
|
50
53
|
return new SafePlugin({
|
|
51
54
|
key: pluginKey,
|
|
@@ -133,11 +136,14 @@ const createPlugin = (
|
|
|
133
136
|
tr.getMeta('referentialityTableInserted'),
|
|
134
137
|
);
|
|
135
138
|
|
|
136
|
-
const
|
|
139
|
+
const shouldPatchTableWidth = fullWidthEnabled && isTableScalingEnabled;
|
|
140
|
+
const shouldPatchTableAlignment =
|
|
141
|
+
fullWidthEnabled && isTableAlignmentEnabled;
|
|
137
142
|
|
|
138
143
|
if (
|
|
139
144
|
!isReplaceDocumentOperation &&
|
|
140
|
-
(!
|
|
145
|
+
((!shouldPatchTableWidth && !shouldPatchTableAlignment) ||
|
|
146
|
+
!referentialityTr)
|
|
141
147
|
) {
|
|
142
148
|
return null;
|
|
143
149
|
}
|
|
@@ -206,10 +212,18 @@ const createPlugin = (
|
|
|
206
212
|
|
|
207
213
|
if (referentialityTr) {
|
|
208
214
|
referentialityTr.steps.forEach((step) => {
|
|
209
|
-
step.getMap().forEach((
|
|
215
|
+
step.getMap().forEach((_, __, newStart, newEnd) => {
|
|
210
216
|
newState.doc.nodesBetween(newStart, newEnd, (node, pos) => {
|
|
211
|
-
if (node.type === table
|
|
212
|
-
|
|
217
|
+
if (node.type === table) {
|
|
218
|
+
if (
|
|
219
|
+
shouldPatchTableWidth &&
|
|
220
|
+
node.attrs.width !== TABLE_MAX_WIDTH
|
|
221
|
+
) {
|
|
222
|
+
tr.setNodeAttribute(pos, 'width', TABLE_MAX_WIDTH);
|
|
223
|
+
}
|
|
224
|
+
if (shouldPatchTableAlignment) {
|
|
225
|
+
tr.setNodeAttribute(pos, 'layout', ALIGN_START);
|
|
226
|
+
}
|
|
213
227
|
}
|
|
214
228
|
});
|
|
215
229
|
});
|
|
@@ -195,6 +195,7 @@ export const ColumnControls = ({
|
|
|
195
195
|
indexes: number[],
|
|
196
196
|
) => {
|
|
197
197
|
const isHover = type === 'hover';
|
|
198
|
+
const isPlaceholder = appearance === 'placeholder';
|
|
198
199
|
const previewHeight = rowHeights?.reduce((sum, cur) => sum + cur, 0) ?? 0;
|
|
199
200
|
|
|
200
201
|
const previewWidth =
|
|
@@ -221,7 +222,11 @@ export const ColumnControls = ({
|
|
|
221
222
|
position: 'relative',
|
|
222
223
|
}}
|
|
223
224
|
data-testid={`table-floating-column-${
|
|
224
|
-
isHover
|
|
225
|
+
isHover
|
|
226
|
+
? colIndex
|
|
227
|
+
: isPlaceholder
|
|
228
|
+
? appearance
|
|
229
|
+
: selectedColIndexes[0]
|
|
225
230
|
}-drag-handle`}
|
|
226
231
|
>
|
|
227
232
|
<DragHandle
|
|
@@ -254,17 +259,23 @@ export const ColumnControls = ({
|
|
|
254
259
|
return null;
|
|
255
260
|
}
|
|
256
261
|
|
|
262
|
+
const selectedAppearance =
|
|
263
|
+
isColumnSelected && isEntireTableSelected
|
|
264
|
+
? isInDanger
|
|
265
|
+
? 'danger'
|
|
266
|
+
: 'selected'
|
|
267
|
+
: 'placeholder';
|
|
268
|
+
|
|
257
269
|
// placeholder / selected need to always render at least one handle
|
|
258
270
|
// so it can be focused via keyboard shortcuts
|
|
259
271
|
handles.push(
|
|
260
272
|
generateHandleByType(
|
|
261
273
|
'selected',
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
:
|
|
267
|
-
`${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`,
|
|
274
|
+
selectedAppearance,
|
|
275
|
+
// always position placeholder in first column to avoid overflow issues
|
|
276
|
+
selectedAppearance === 'placeholder'
|
|
277
|
+
? '1 / span 1'
|
|
278
|
+
: `${selectedColIndexes[0] + 1} / span ${selectedColIndexes.length}`,
|
|
268
279
|
selectedColIndexes,
|
|
269
280
|
),
|
|
270
281
|
);
|
package/src/utils/alignment.ts
CHANGED
|
@@ -2,9 +2,12 @@ import type { TableLayout } from '@atlaskit/adf-schema';
|
|
|
2
2
|
|
|
3
3
|
import type { AlignmentOptions } from '../types';
|
|
4
4
|
|
|
5
|
+
export const ALIGN_START = 'align-start';
|
|
6
|
+
export const ALIGN_CENTER = 'center';
|
|
7
|
+
|
|
5
8
|
/**
|
|
6
9
|
* Normalise table layout attribute an alignment value ('center' or 'align-start'), returns
|
|
7
10
|
* center if layout equals a breakout value (e.g. 'default', 'wide', 'full-width')
|
|
8
11
|
*/
|
|
9
12
|
export const normaliseAlignment = (layout: TableLayout): AlignmentOptions =>
|
|
10
|
-
layout ===
|
|
13
|
+
layout === ALIGN_CENTER || layout === ALIGN_START ? layout : ALIGN_CENTER;
|
package/src/utils/create.ts
CHANGED
|
@@ -1,27 +1,41 @@
|
|
|
1
|
+
import type { TableAttributes } from '@atlaskit/adf-schema';
|
|
1
2
|
import type { Schema } from '@atlaskit/editor-prosemirror/model';
|
|
2
3
|
import { createTable } from '@atlaskit/editor-tables/utils';
|
|
3
4
|
|
|
4
5
|
import { TABLE_MAX_WIDTH } from '../pm-plugins/table-resizing/utils';
|
|
5
6
|
|
|
7
|
+
type CreateTableOverrides = {
|
|
8
|
+
tableWidth?: TableAttributes['width'];
|
|
9
|
+
layout?: TableAttributes['layout'];
|
|
10
|
+
};
|
|
11
|
+
|
|
6
12
|
export const createTableWithWidth =
|
|
7
|
-
(
|
|
8
|
-
isTableScalingEnabled
|
|
9
|
-
|
|
13
|
+
({
|
|
14
|
+
isTableScalingEnabled,
|
|
15
|
+
isTableAlignmentEnabled,
|
|
16
|
+
isFullWidthModeEnabled,
|
|
17
|
+
createTableProps,
|
|
18
|
+
}: {
|
|
19
|
+
isTableScalingEnabled?: boolean;
|
|
20
|
+
isTableAlignmentEnabled?: boolean;
|
|
21
|
+
isFullWidthModeEnabled?: boolean;
|
|
10
22
|
createTableProps?: {
|
|
11
23
|
rowsCount?: number;
|
|
12
24
|
colsCount?: number;
|
|
13
|
-
}
|
|
14
|
-
) =>
|
|
25
|
+
};
|
|
26
|
+
}) =>
|
|
15
27
|
(schema: Schema) => {
|
|
28
|
+
const attrsOverrides: CreateTableOverrides = {};
|
|
16
29
|
if (isTableScalingEnabled && isFullWidthModeEnabled) {
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
});
|
|
30
|
+
attrsOverrides.tableWidth = TABLE_MAX_WIDTH;
|
|
31
|
+
}
|
|
32
|
+
if (isTableAlignmentEnabled && isFullWidthModeEnabled) {
|
|
33
|
+
attrsOverrides.layout = 'align-start';
|
|
22
34
|
}
|
|
35
|
+
|
|
23
36
|
return createTable({
|
|
24
37
|
schema,
|
|
25
38
|
...createTableProps,
|
|
39
|
+
...attrsOverrides,
|
|
26
40
|
});
|
|
27
41
|
};
|