@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
213 lines (197 loc) • 14.2 kB
JavaScript
import _defineProperty from "@babel/runtime/helpers/defineProperty";
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
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; }
/**
* 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.
*/
import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
import { fg } from '@atlaskit/platform-feature-flags/fg';
import { buildAddedCellOverlayRoundedStyle, buildAddedCellOverlayStyle, buildAddedCellOverlayStyleNew, buildDeletedCellOverlayRoundedStyle, buildDeletedCellOverlayStyle, buildDeletedInlineContentStyle, buildDeletedInlineContentStyleExtended, buildDeletedLozengeActiveStyle, buildDeletedLozengeStyle, buildDeletedNodeCSSVariables, buildDeletedQuoteNodeWithLozengeStyle, buildDeletedStrikethroughLine, buildDeletedWrappedBlockOutline, buildInsertedBlockNodeStyle, buildInsertedInlineStyle, buildInsertStyleInBlockExtended, buildInsertStyleInBlockExtendedNoUnderline, buildInsertStyleNode } from '../colorSchemes/factory';
import { colorSchemeRegistry, getLegacyColorScheme, standardScheme } from '../colorSchemes/schemes';
import { getChangedContentStyleLegacy, getChangedNodeStyleLegacy, getDeletedContentStyleLegacy, getDeletedContentStyleUnboundedLegacy, getInsertedContentStyleLegacy, hasRestingDeletedRingLegacy, resolveCellOverlayStyleLegacy, resolveNestedInsertedNodeStyleLegacy, resolveRemovedLozengeStyleLegacy } from './wrapBlockNodeViewStyles.legacy';
var getColorScheme = function getColorScheme(colorScheme) {
return colorSchemeRegistry[colorScheme !== null && colorScheme !== void 0 ? colorScheme : 'standard'];
};
/**
* Preserve the historical purple nested outlines when the layout/decision diff patch is off.
*/
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) {
// When cleaning up platform_editor_ai_show_diff_patch_2 just put paragraph into the list
if (nodeName === 'paragraph') {
return fg('platform_editor_ai_show_diff_patch_2');
}
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 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 (fg('confluence_ncs_step_diffing_version_history') && colors.deletedInlineTreatment === 'glyphTint') {
return base + buildDeletedInlineContentStyleExtended(colors, isActive);
}
return base;
};
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 hideAddedDiffsUnderline = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : false;
var colors = getColorScheme(colorScheme);
if (isInserted) {
if (isMultiContainerBlockNode(nodeName)) {
return hideAddedDiffsUnderline || fg('platform_editor_ai_show_diff_patch_1') ? buildInsertStyleInBlockExtendedNoUnderline(nestedContentScheme) : buildInsertStyleInBlockExtended(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;
}
};
var getDeletedContentStyleUnboundedNext = function getDeletedContentStyleUnboundedNext(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
return 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 buildInsertedInlineStyle(getColorScheme(colorScheme), isActive, hideAddedDiffsUnderline);
};
var getDeletedContentStyleNext = function getDeletedContentStyleNext(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var omitHighlight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 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' && !omitHighlight;
return needsExtendedHighlight ? base + buildDeletedInlineContentStyleExtended(colors, isActive) : 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 ? buildAddedCellOverlayRoundedStyle(colors) : colors.insertedNodeEmphasis === 'stateful' ? buildAddedCellOverlayStyleNew(colors) : buildAddedCellOverlayStyle(colors);
var deletedCellStyle = isRoundedTable ? buildDeletedCellOverlayRoundedStyle(colors) : buildDeletedCellOverlayStyle(colors);
return isInserted ? addedCellStyle : deletedCellStyle;
};
var resolveRemovedLozengeStyleNext = function resolveRemovedLozengeStyleNext(colorScheme, isActive) {
var colors = getColorScheme(colorScheme);
return isActive ? buildDeletedLozengeActiveStyle(colors) : buildDeletedLozengeStyle(colors);
};
var resolveNestedInsertedNodeStyleNext = function resolveNestedInsertedNodeStyleNext(colorScheme) {
return buildInsertStyleNode(fg('platform_editor_ai_show_diff_patch_1') ? getColorScheme(colorScheme) : 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. */
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;
return isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getChangedContentStyleNext(colorScheme, isActive, isInserted, hideAddedDiffsUnderline) : getChangedContentStyleLegacy(getLegacyColorScheme(colorScheme), isActive, isInserted, hideAddedDiffsUnderline);
};
/** 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;
return isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getChangedNodeStyleNext(nodeName, colorScheme, isInserted, isActive, hideAddedDiffsUnderline) : getChangedNodeStyleLegacy(nodeName, getLegacyColorScheme(colorScheme), isInserted, isActive, hideAddedDiffsUnderline);
};
/** 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 isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleUnboundedNext(colorScheme, isActive) : getDeletedContentStyleUnboundedLegacy(getLegacyColorScheme(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 isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getInsertedContentStyleNext(colorScheme, isActive, hideAddedDiffsUnderline) : getInsertedContentStyleLegacy(getLegacyColorScheme(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 omitHighlight = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
return isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? getDeletedContentStyleNext(colorScheme, isActive, omitHighlight) : getDeletedContentStyleLegacy(getLegacyColorScheme(colorScheme), isActive, omitHighlight);
};
/**
* 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(args) {
return isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveCellOverlayStyleNext(args) : resolveCellOverlayStyleLegacy(_objectSpread(_objectSpread({}, args), {}, {
colorScheme: getLegacyColorScheme(args.colorScheme)
}));
};
/** Inner style for the "Removed" lozenge on a deleted block node. */
export var resolveRemovedLozengeStyle = function resolveRemovedLozengeStyle(colorScheme, isActive) {
return isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveRemovedLozengeStyleNext(colorScheme, isActive) : resolveRemovedLozengeStyleLegacy(getLegacyColorScheme(colorScheme), isActive);
};
/**
* 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 isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? resolveNestedInsertedNodeStyleNext(colorScheme) : 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.
*/
export var hasRestingDeletedRing = function hasRestingDeletedRing(colorScheme) {
return isExperimentEnabled('platform_editor_show_diff_color_scheme_refactor') ? hasRestingDeletedRingNext(colorScheme) : hasRestingDeletedRingLegacy(getLegacyColorScheme(colorScheme));
};
/**
* Custom properties consumed by the `show-diff-deleted-node-vars` selectors in editor-core.
*
* No `*Legacy` counterpart: the OFF cohort emits no properties at all and takes its colours from the
* per-scheme selectors instead, so the gate lives at the single caller in `wrapBlockNodeView`.
*/
export var resolveDeletedNodeCSSVariables = function resolveDeletedNodeCSSVariables(colorScheme) {
return buildDeletedNodeCSSVariables(getColorScheme(colorScheme));
};