@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
154 lines (140 loc) • 7.69 kB
JavaScript
/**
* Style resolution for the `wrapBlockNodeView` nodeview decorations.
*
* Every exported resolver is driven by the `colorSchemeRegistry` + `factory.ts` implementation.
*/
import { convertToInlineCss } from '@atlaskit/editor-common/css-helper';
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
import { buildAddedCellOverlayRoundedStyle, buildDeletedCellOverlayRoundedStyle, buildDeletedInlineContentStyle, buildDeletedInlineContentStyleExtended, buildDeletedLozengeActiveStyle, buildDeletedLozengeStyle, buildDeletedNodeCSSVariables, buildDeletedQuoteNodeWithLozengeStyle, buildDeletedStrikethroughLine, buildDeletedWrappedBlockOutline, buildInsertedBlockNodeStyle, buildInsertedInlineStyle, buildInsertStyleInBlockExtendedNoUnderline, buildInsertStyleNode } from '../colorSchemes/factory';
import { colorSchemeRegistry, standardScheme } from '../colorSchemes/schemes';
var getColorScheme = function getColorScheme(colorScheme) {
return colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : 'standard'];
};
/**
* Scheme for the outline of an inserted multi-container block (layouts, decision lists, etc.).
*/
var nestedContentScheme = standardScheme;
/**
* Node-name classification shared by the style resolvers below and by the routing in
* `wrapBlockNodeView.ts`.
*/
export var isMultiContainerBlockNode = function isMultiContainerBlockNode(nodeName) {
return ['decisionList', 'layoutSection'].includes(nodeName);
};
export var 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. */
export var 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 buildInsertedInlineStyle(colors, isActive, hideAddedDiffsUnderline);
}
var base = 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 (isExperimentEnabled('platform_editor_attributed_version_history') && colors.deletedInlineTreatment === 'glyphTint') {
return base + buildDeletedInlineContentStyleExtended(colors, isActive);
}
return base;
};
/** Node-specific style for a changed block node, or `undefined` when the node type has none. */
export var 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 buildInsertStyleInBlockExtendedNoUnderline(nestedContentScheme);
}
if (isTextLikeBlockNode(nodeName)) {
return undefined;
}
return buildInsertedBlockNodeStyle(colors, 'node', isActive);
}
switch (nodeName) {
case 'blockquote':
return buildDeletedQuoteNodeWithLozengeStyle(colors, isActive);
case 'expand':
case 'decisionList':
return buildDeletedWrappedBlockOutline(colors, {
isActive: isActive,
isRounded: false
});
case 'panel':
case 'codeBlock':
return buildDeletedWrappedBlockOutline(colors, {
isActive: isActive,
isRounded: true
});
default:
return undefined;
}
};
/** The positioned line drawn across deleted content spanning an unbounded range. */
export var getDeletedContentStyleUnbounded = function getDeletedContentStyleUnbounded(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return buildDeletedStrikethroughLine(getColorScheme(colorScheme), isActive);
};
/** Inline style for inserted content. */
export var 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 buildInsertedInlineStyle(getColorScheme(colorScheme), isActive, hideAddedDiffsUnderline);
};
/** Inline style for deleted content. */
export var getDeletedContentStyle = function getDeletedContentStyle(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var colors = getColorScheme(colorScheme);
var base = 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 + buildDeletedInlineContentStyleExtended(colors, isActive) : base;
};
var inheritedCellBorderStyle = 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.
*/
export var resolveCellOverlayStyle = function resolveCellOverlayStyle(_ref) {
var colorScheme = _ref.colorScheme,
isInserted = _ref.isInserted;
var colors = getColorScheme(colorScheme);
var overlayStyle = isInserted ? buildAddedCellOverlayRoundedStyle(colors) : buildDeletedCellOverlayRoundedStyle(colors);
if ((!isInserted || colors.roundedAddedCellOverlayInheritsBorder) && !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. */
export var resolveRemovedLozengeStyle = function resolveRemovedLozengeStyle(colorScheme, isActive) {
var colors = getColorScheme(colorScheme);
return isActive ? buildDeletedLozengeActiveStyle(colors) : buildDeletedLozengeStyle(colors);
};
/**
* Style for inserted content nested inside a multi-container or list node — the `decisionList` and
* `taskList` `li`s and the `layoutSection` columns.
*/
export var resolveNestedInsertedNodeStyle = function resolveNestedInsertedNodeStyle(colorScheme) {
return 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.
*/
export var hasRestingDeletedRing = function hasRestingDeletedRing(colorScheme) {
return getColorScheme(colorScheme).deletedNodeEmphasis === 'stateful';
};
/**
* Custom properties consumed by the `show-diff-deleted-node-vars` selectors in editor-core.
*/
export var resolveDeletedNodeCSSVariables = function resolveDeletedNodeCSSVariables(colorScheme) {
return buildDeletedNodeCSSVariables(getColorScheme(colorScheme));
};