@atlaskit/editor-plugin-breakout
Version:
Breakout plugin for @atlaskit/editor-core
132 lines (131 loc) • 4.54 kB
JavaScript
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.getGuidelines = exports.GUIDELINE_KEYS = void 0;
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
var _layout = require("@atlaskit/editor-common/styles/layout");
var _resizer = require("@atlaskit/editor-common/styles/resizer");
var _sharedStyles = require("@atlaskit/editor-common/ui-expand/sharedStyles");
var _constants = require("@atlaskit/editor-shared-styles/constants");
var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
var WIDTHS = {
MIN: _constants.akEditorDefaultLayoutWidth,
WIDE: _constants.akEditorCalculatedWideLayoutWidth,
FULL: _constants.akEditorFullWidthLayoutWidth,
MAX: _constants.akEditorMaxLayoutWidth
};
var GUIDELINE_KEYS = exports.GUIDELINE_KEYS = {
lineLengthLeft: 'grid_left',
lineLengthRight: 'grid_right',
wideLeft: 'wide_left',
wideRight: 'wide_right',
fullWidthLeft: 'full_width_left',
fullWidthRight: 'full_width_right',
maxWidthLeft: 'max_width_left',
maxWidthRight: 'max_width_right'
};
var SYNC_BLOCK_PADDING = 19;
var EXTENSION_WRAPPER_PADDING = 20;
var AK_NESTED_DND_GUTTER_OFFSET = 8;
var roundToNearest = function roundToNearest(value) {
var interval = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0.5;
return Math.round(value / interval) * interval;
};
var getGuidelines = exports.getGuidelines = (0, _memoizeOne.default)(function (isResizing, newWidth, getEditorWidth, nodeType) {
var guidelines = [];
if (!isResizing) {
return guidelines;
}
var innerPaddingOffset = 0;
if (nodeType) {
switch (nodeType.name) {
case 'expand':
innerPaddingOffset = _sharedStyles.EXPAND_CONTAINER_PADDING + _resizer.resizerHandleThumbWidth + AK_NESTED_DND_GUTTER_OFFSET;
break;
case 'layoutSection':
innerPaddingOffset = _layout.LAYOUT_COLUMN_PADDING + AK_NESTED_DND_GUTTER_OFFSET;
break;
case 'bodiedSyncBlock':
case 'syncBlock':
innerPaddingOffset = SYNC_BLOCK_PADDING;
break;
case 'extension':
case 'multiBodiedExtension':
case 'bodiedExtension':
innerPaddingOffset = EXTENSION_WRAPPER_PADDING;
break;
default:
break;
}
}
var _ref = getEditorWidth() || {},
width = _ref.width;
var padding = width && width <= _constants.akEditorFullPageNarrowBreakout && (0, _editorExperiment.editorExperiment)('platform_editor_preview_panel_responsiveness', true, {
exposure: true
}) ? _constants.akEditorGutterPaddingReduced : (0, _constants.akEditorGutterPaddingDynamic)();
var fullWidth = width ? Math.min(WIDTHS.FULL, width - 2 * padding - _constants.akEditorGutterPadding) : undefined;
var maxWidth = width ? Math.min(WIDTHS.MAX, width - 2 * padding - _constants.akEditorGutterPadding) : undefined;
guidelines.push({
key: GUIDELINE_KEYS.lineLengthLeft,
position: {
x: -roundToNearest(WIDTHS.MIN / 2 + innerPaddingOffset)
},
active: newWidth === WIDTHS.MIN
});
guidelines.push({
key: GUIDELINE_KEYS.lineLengthRight,
position: {
x: roundToNearest(WIDTHS.MIN / 2 + innerPaddingOffset)
},
active: newWidth === WIDTHS.MIN
});
guidelines.push({
key: GUIDELINE_KEYS.wideLeft,
position: {
x: -roundToNearest(WIDTHS.WIDE / 2 + innerPaddingOffset)
},
active: newWidth === WIDTHS.WIDE
});
guidelines.push({
key: GUIDELINE_KEYS.wideRight,
position: {
x: roundToNearest(WIDTHS.WIDE / 2 + innerPaddingOffset)
},
active: newWidth === WIDTHS.WIDE
});
if (fullWidth) {
guidelines.push({
key: GUIDELINE_KEYS.fullWidthLeft,
position: {
x: -roundToNearest(fullWidth / 2 + innerPaddingOffset)
},
active: newWidth === fullWidth
});
guidelines.push({
key: GUIDELINE_KEYS.fullWidthRight,
position: {
x: roundToNearest(fullWidth / 2 + innerPaddingOffset)
},
active: newWidth === fullWidth
});
}
if (maxWidth) {
guidelines.push({
key: GUIDELINE_KEYS.maxWidthLeft,
position: {
x: -roundToNearest(maxWidth / 2 + innerPaddingOffset)
},
active: newWidth === maxWidth
});
guidelines.push({
key: GUIDELINE_KEYS.maxWidthRight,
position: {
x: roundToNearest(maxWidth / 2 + innerPaddingOffset)
},
active: newWidth === maxWidth
});
}
return guidelines;
});