UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

205 lines (189 loc) 13.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveRemovedLozengeStyle = exports.resolveNestedInsertedNodeStyle = exports.resolveCellOverlayStyle = exports.isTextLikeBlockNode = exports.isMultiContainerBlockNode = exports.hasRestingDeletedRing = exports.getInsertedContentStyle = exports.getDeletedContentStyleUnbounded = exports.getDeletedContentStyle = exports.getChangedNodeStyle = exports.getChangedContentStyle = void 0; var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _isExtendedEnabled = require("../../isExtendedEnabled"); var _factory = require("../colorSchemes/factory"); var _schemes = require("../colorSchemes/schemes"); var _wrapBlockNodeViewStyles = require("./wrapBlockNodeViewStyles.legacy"); /** * Style resolution for the `wrapBlockNodeView` nodeview decorations. * * Every exported resolver is a single gate: the `colorSchemeRegistry` + `factory.ts` * implementation when `platform_editor_show_diff_color_scheme_refactor` is on, and the verbatim * pre-refactor per-scheme constants from `./wrapBlockNodeViewStyles.legacy` when it is off. The two * paths are built to emit identical style strings for both shipped schemes, so this is a kill * switch for a refactor rather than a behaviour experiment. * * On cleanup (EDITOR-8281): drop the `isExperimentEnabled` dispatch and the `*Legacy` imports, * keeping the `*Next` bodies. */ var DEFAULT_COLOR_SCHEME = 'standard'; var getColorScheme = function getColorScheme(colorScheme) { return _schemes.colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : DEFAULT_COLOR_SCHEME]; }; /** * Inserted content inside a multi-container or list node always uses the standard scheme, so a * traditional diff shows purple here. Pre-existing: these call sites predate traditional. * Preserved as-is; see EDITOR-8281. */ var nestedContentScheme = _schemes.standardScheme; var lozengeStyle = (0, _factory.buildDeletedLozengeStyle)(); /** * 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 ['heading', 'bulletList', 'orderedList', 'listItem', 'taskList', 'blockquote'].includes(nodeName); }; var getChangedContentStyleNext = function getChangedContentStyleNext(colorScheme) { var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var isInserted = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var diffType = arguments.length > 3 ? arguments[3] : undefined; var hideAddedDiffsUnderline = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; var colors = getColorScheme(colorScheme); if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && isInserted) { return (0, _factory.buildInsertedInlineStyle)(colors, isActive, hideAddedDiffsUnderline); } if (isActive) { return (0, _factory.buildDeletedInlineContentStyle)(colors, 'active'); } return (0, _factory.buildDeletedInlineContentStyle)(colors, (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? 'new' : 'default'); }; var getChangedNodeStyleNext = function getChangedNodeStyleNext(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 diffType = arguments.length > 4 ? arguments[4] : undefined; var hideAddedDiffsUnderline = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; var colors = getColorScheme(colorScheme); if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && isInserted) { if (isMultiContainerBlockNode(nodeName)) { return hideAddedDiffsUnderline ? (0, _factory.buildInsertStyleInBlockExtendedNoUnderline)(nestedContentScheme) : (0, _factory.buildInsertStyleInBlockExtended)(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; } }; var getDeletedContentStyleUnboundedNext = function getDeletedContentStyleUnboundedNext(colorScheme) { var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; return (0, _factory.buildDeletedStrikethroughLine)(getColorScheme(colorScheme), isActive); }; var getInsertedContentStyleNext = function getInsertedContentStyleNext(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); }; var getDeletedContentStyleNext = function getDeletedContentStyleNext(colorScheme) { var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var diffType = arguments.length > 2 ? arguments[2] : undefined; 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' && (0, _isExtendedEnabled.isExtendedEnabled)(diffType); return needsExtendedHighlight ? base + (0, _factory.buildDeletedInlineContentStyleExtended)(colors) : base; }; var resolveCellOverlayStyleNext = function resolveCellOverlayStyleNext(_ref) { var colorScheme = _ref.colorScheme, isInserted = _ref.isInserted, isRoundedTable = _ref.isRoundedTable; var colors = getColorScheme(colorScheme); // Square added-cell overlays follow insertedNodeEmphasis: pressed background vs accent border. var addedCellStyle = isRoundedTable ? (0, _factory.buildAddedCellOverlayRoundedStyle)(colors) : colors.insertedNodeEmphasis === 'stateful' ? (0, _factory.buildAddedCellOverlayStyleNew)(colors) : (0, _factory.buildAddedCellOverlayStyle)(colors); var deletedCellStyle = isRoundedTable ? (0, _factory.buildDeletedCellOverlayRoundedStyle)(colors) : (0, _factory.buildDeletedCellOverlayStyle)(colors); return isInserted ? addedCellStyle : deletedCellStyle; }; var resolveRemovedLozengeStyleNext = function resolveRemovedLozengeStyleNext(colorScheme, isActive) { return isActive ? (0, _factory.buildDeletedLozengeActiveStyle)(getColorScheme(colorScheme)) : lozengeStyle; }; var resolveNestedInsertedNodeStyleNext = function resolveNestedInsertedNodeStyleNext() { return (0, _factory.buildInsertStyleNode)(nestedContentScheme); }; // Only 'stateful' schemes have a resting ring. var hasRestingDeletedRingNext = function hasRestingDeletedRingNext(colorScheme) { return getColorScheme(colorScheme).deletedNodeEmphasis === 'stateful'; }; /** 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 diffType = arguments.length > 3 ? arguments[3] : undefined; var hideAddedDiffsUnderline = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false; return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getChangedContentStyleNext(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getChangedContentStyleLegacy)(colorScheme, isActive, isInserted, diffType, hideAddedDiffsUnderline); }; /** 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 diffType = arguments.length > 4 ? arguments[4] : undefined; var hideAddedDiffsUnderline = arguments.length > 5 && arguments[5] !== undefined ? arguments[5] : false; return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getChangedNodeStyleNext(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getChangedNodeStyleLegacy)(nodeName, colorScheme, isInserted, isActive, diffType, hideAddedDiffsUnderline); }; /** 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, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleUnboundedNext(colorScheme, isActive) : (0, _wrapBlockNodeViewStyles.getDeletedContentStyleUnboundedLegacy)(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, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getInsertedContentStyleNext(colorScheme, isActive, hideAddedDiffsUnderline) : (0, _wrapBlockNodeViewStyles.getInsertedContentStyleLegacy)(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 diffType = arguments.length > 2 ? arguments[2] : undefined; return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleNext(colorScheme, isActive, diffType) : (0, _wrapBlockNodeViewStyles.getDeletedContentStyleLegacy)(colorScheme, isActive, diffType); }; /** * 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(args) { return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveCellOverlayStyleNext(args) : (0, _wrapBlockNodeViewStyles.resolveCellOverlayStyleLegacy)(args); }; /** Inner style for the "Removed" lozenge on a deleted block node. */ var resolveRemovedLozengeStyle = exports.resolveRemovedLozengeStyle = function resolveRemovedLozengeStyle(colorScheme, isActive) { return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveRemovedLozengeStyleNext(colorScheme, isActive) : (0, _wrapBlockNodeViewStyles.resolveRemovedLozengeStyleLegacy)(colorScheme, isActive); }; /** * Style for inserted content nested inside a multi-container or list node — the `decisionList` and * `taskList` `li`s and the `layoutSection` columns. Scheme-independent: see * `nestedContentScheme` above. */ var resolveNestedInsertedNodeStyle = exports.resolveNestedInsertedNodeStyle = function resolveNestedInsertedNodeStyle() { return (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? resolveNestedInsertedNodeStyleNext() : (0, _wrapBlockNodeViewStyles.resolveNestedInsertedNodeStyleLegacy)(); }; /** * 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 (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_show_diff_color_scheme_refactor') ? hasRestingDeletedRingNext(colorScheme) : (0, _wrapBlockNodeViewStyles.hasRestingDeletedRingLegacy)(colorScheme); };