@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
161 lines (145 loc) • 8.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.resolveRemovedLozengeStyle = exports.resolveNestedInsertedNodeStyle = exports.resolveDeletedNodeCSSVariables = exports.resolveCellOverlayStyle = exports.isTextLikeBlockNode = exports.isMultiContainerBlockNode = exports.hasRestingDeletedRing = exports.getInsertedContentStyle = exports.getDeletedContentStyleUnbounded = exports.getDeletedContentStyle = exports.getChangedNodeStyle = exports.getChangedContentStyle = void 0;
var _cssHelper = require("@atlaskit/editor-common/css-helper");
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
var _factory = require("../colorSchemes/factory");
var _schemes = require("../colorSchemes/schemes");
/**
* Style resolution for the `wrapBlockNodeView` nodeview decorations.
*
* Every exported resolver is driven by the `colorSchemeRegistry` + `factory.ts` implementation.
*/
var getColorScheme = function getColorScheme(colorScheme) {
return _schemes.colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : 'standard'];
};
/**
* Scheme for the outline of an inserted multi-container block (layouts, decision lists, etc.).
*/
var nestedContentScheme = _schemes.standardScheme;
/**
* Node-name classification shared by the style resolvers below and by the routing in
* `wrapBlockNodeView.ts`.
*/
var isMultiContainerBlockNode = exports.isMultiContainerBlockNode = function isMultiContainerBlockNode(nodeName) {
return ['decisionList', 'layoutSection'].includes(nodeName);
};
var isTextLikeBlockNode = exports.isTextLikeBlockNode = function isTextLikeBlockNode(nodeName) {
return ['paragraph', 'heading', 'bulletList', 'orderedList', 'listItem', 'taskList', 'blockquote'].includes(nodeName);
};
/** Inline content style for a changed (inserted or deleted) block node. */
var getChangedContentStyle = exports.getChangedContentStyle = function getChangedContentStyle(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var hideAddedDiffsUnderline = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var colors = getColorScheme(colorScheme);
if (isInserted) {
return (0, _factory.buildInsertedInlineStyle)(colors, isActive, hideAddedDiffsUnderline);
}
var base = (0, _factory.buildDeletedInlineContentStyle)(colors, isActive ? 'active' : 'new');
// Text-like blocks (heading, lists, blockquote) render their deleted content through this
// getter rather than `getDeletedContentStyle`, so without this they never receive the
// glyphTint background + underline that plain deleted text already gets.
if ((0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_attributed_version_history') && colors.deletedInlineTreatment === 'glyphTint') {
return base + (0, _factory.buildDeletedInlineContentStyleExtended)(colors, isActive);
}
return base;
};
/** Node-specific style for a changed block node, or `undefined` when the node type has none. */
var getChangedNodeStyle = exports.getChangedNodeStyle = function getChangedNodeStyle(nodeName, colorScheme) {
var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
var isActive = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
var hideAddedDiffsUnderline = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
var colors = getColorScheme(colorScheme);
if (isInserted) {
if (isMultiContainerBlockNode(nodeName)) {
return (0, _factory.buildInsertStyleInBlockExtendedNoUnderline)(nestedContentScheme);
}
if (isTextLikeBlockNode(nodeName)) {
return undefined;
}
return (0, _factory.buildInsertedBlockNodeStyle)(colors, 'node', isActive);
}
switch (nodeName) {
case 'blockquote':
return (0, _factory.buildDeletedQuoteNodeWithLozengeStyle)(colors, isActive);
case 'expand':
case 'decisionList':
return (0, _factory.buildDeletedWrappedBlockOutline)(colors, {
isActive: isActive,
isRounded: false
});
case 'panel':
case 'codeBlock':
return (0, _factory.buildDeletedWrappedBlockOutline)(colors, {
isActive: isActive,
isRounded: true
});
default:
return undefined;
}
};
/** The positioned line drawn across deleted content spanning an unbounded range. */
var getDeletedContentStyleUnbounded = exports.getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return (0, _factory.buildDeletedStrikethroughLine)(getColorScheme(colorScheme), isActive);
};
/** Inline style for inserted content. */
var getInsertedContentStyle = exports.getInsertedContentStyle = function getInsertedContentStyle(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var hideAddedDiffsUnderline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return (0, _factory.buildInsertedInlineStyle)(getColorScheme(colorScheme), isActive, hideAddedDiffsUnderline);
};
/** Inline style for deleted content. */
var getDeletedContentStyle = exports.getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var colors = getColorScheme(colorScheme);
var base = (0, _factory.buildDeletedInlineContentStyle)(colors, isActive ? 'active' : 'new');
// glyphTint adds a background highlight and border-bottom over the tint; strikethrough does not.
var needsExtendedHighlight = colors.deletedInlineTreatment === 'glyphTint';
return needsExtendedHighlight ? base + (0, _factory.buildDeletedInlineContentStyleExtended)(colors, isActive) : base;
};
var inheritedCellBorderStyle = (0, _cssHelper.convertToInlineCss)({
border: 'inherit'
});
/**
* Overlay style for one added or deleted table cell. Invariant across the cells of a table, so the
* `querySelectorAll('td, th')` loop in `wrapBlockNodeView.ts` resolves it once.
*/
var resolveCellOverlayStyle = exports.resolveCellOverlayStyle = function resolveCellOverlayStyle(_ref) {
var colorScheme = _ref.colorScheme,
isInserted = _ref.isInserted;
var colors = getColorScheme(colorScheme);
var overlayStyle = isInserted ? (0, _factory.buildAddedCellOverlayRoundedStyle)(colors) : (0, _factory.buildDeletedCellOverlayRoundedStyle)(colors);
if ((!isInserted || colors.roundedAddedCellOverlayInheritsBorder) && !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_table_diff_overlay_border_fix')) {
return "".concat(overlayStyle, " ").concat(inheritedCellBorderStyle);
}
return overlayStyle;
};
/** Inner style for the "Removed" lozenge on a deleted block node. */
var resolveRemovedLozengeStyle = exports.resolveRemovedLozengeStyle = function resolveRemovedLozengeStyle(colorScheme, isActive) {
var colors = getColorScheme(colorScheme);
return isActive ? (0, _factory.buildDeletedLozengeActiveStyle)(colors) : (0, _factory.buildDeletedLozengeStyle)(colors);
};
/**
* Style for inserted content nested inside a multi-container or list node — the `decisionList` and
* `taskList` `li`s and the `layoutSection` columns.
*/
var resolveNestedInsertedNodeStyle = exports.resolveNestedInsertedNodeStyle = function resolveNestedInsertedNodeStyle(colorScheme) {
return (0, _factory.buildInsertStyleNode)(getColorScheme(colorScheme));
};
/**
* Whether the colour scheme draws a resting (non-active) ring on a deleted media/embed node, which
* is what the `show-diff-deleted-outline-new` class styles in editor-core's smartCardStyles.
*/
var hasRestingDeletedRing = exports.hasRestingDeletedRing = function hasRestingDeletedRing(colorScheme) {
return getColorScheme(colorScheme).deletedNodeEmphasis === 'stateful';
};
/**
* Custom properties consumed by the `show-diff-deleted-node-vars` selectors in editor-core.
*/
var resolveDeletedNodeCSSVariables = exports.resolveDeletedNodeCSSVariables = function resolveDeletedNodeCSSVariables(colorScheme) {
return (0, _factory.buildDeletedNodeCSSVariables)(getColorScheme(colorScheme));
};