@atlaskit/editor-plugin-show-diff
Version:
ShowDiff plugin for @atlaskit/editor-core
218 lines (208 loc) • 12.3 kB
JavaScript
/**
* Pre-refactor code preserved for the OFF cohort of
* `platform_editor_show_diff_color_scheme_refactor`.
*
* These resolvers hold, verbatim, the per-scheme string-constant style decisions that
* `wrapBlockNodeView.ts` made before the `colorSchemeRegistry` + `factory.ts` migration — same
* branches, same ternaries, same order, same shim constants, same module-level constants.
*
* Do not modify. Delete this file at experiment cleanup, together with `colorSchemes/standard.ts`,
* `colorSchemes/traditional.ts` (EDITOR-8281).
*/
import { convertToInlineCss } from '@atlaskit/editor-common/lazy-node-view';
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
import { isExtendedEnabled } from '../../isExtendedEnabled';
import { deletedBlockOutline, deletedBlockOutlineActive, deletedBlockOutlineRounded, deletedBlockOutlineRoundedActive, deletedContentStyle, deletedContentStyleActive, deletedContentStyleNew, deletedContentStyleUnbounded, deletedInlineContentStyleExtended, deletedStyleQuoteNodeWithLozenge, deletedStyleQuoteNodeWithLozengeActive, editingContentStyleInBlockExtended, editingContentStyleInBlockExtendedNoUnderline, editingStyleExtended, editingStyleExtendedNoUnderline, editingStyleActiveExtended, editingStyleActiveExtendedNoUnderline, editingStyleNode, addedCellOverlayStyle, addedCellOverlayRoundedStyle, deletedCellOverlayStyle, deletedCellOverlayRoundedStyle } from '../colorSchemes/standard';
import { deletedTraditionalBlockOutlineActive, deletedTraditionalBlockOutlineNew, deletedTraditionalBlockOutlineRoundedActive, deletedTraditionalBlockOutlineRoundedNew, deletedTraditionalContentStyleUnbounded, deletedTraditionalContentStyleUnboundedActive, getDeletedTraditionalInlineStyle, deletedTraditionalStyleQuoteNode, deletedTraditionalStyleQuoteNodeActive, traditionalInsertStyle, traditionalInsertStyleActive, traditionalStyleNodeActive, traditionalStyleNodeNew, traditionalAddedCellOverlayRoundedStyle, traditionalAddedCellOverlayStyleNew, deletedTraditionalCellOverlayStyle, deletedTraditionalCellOverlayRoundedStyle } from '../colorSchemes/traditional';
var lozengeStyle = convertToInlineCss({
display: 'inline-flex',
boxSizing: 'border-box',
position: 'static',
blockSize: 'min-content',
borderRadius: "var(--ds-radius-small, 4px)",
overflow: 'hidden',
paddingInlineStart: "var(--ds-space-050, 4px)",
paddingInlineEnd: "var(--ds-space-050, 4px)",
backgroundColor: "var(--ds-background-accent-gray-subtler, #DDDEE1)",
font: "var(--ds-font-body-small, normal 400 12px/16px \"Atlassian Sans\", ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)",
fontWeight: "var(--ds-font-weight-bold, 653)",
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
color: "var(--ds-text-warning-inverse, #292A2E)"
});
var lozengeStyleActiveStandard = convertToInlineCss({
display: 'inline-flex',
boxSizing: 'border-box',
position: 'static',
blockSize: 'min-content',
borderRadius: "var(--ds-radius-small, 4px)",
overflow: 'hidden',
paddingInlineStart: "var(--ds-space-050, 4px)",
paddingInlineEnd: "var(--ds-space-050, 4px)",
backgroundColor: "var(--ds-background-accent-red-subtler-pressed, #FD9891)",
font: "var(--ds-font-body-small, normal 400 12px/16px \"Atlassian Sans\", ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)",
fontWeight: "var(--ds-font-weight-bold, 653)",
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
color: "var(--ds-text-warning-inverse, #292A2E)"
});
var lozengeStyleActiveTraditional = convertToInlineCss({
display: 'inline-flex',
boxSizing: 'border-box',
position: 'static',
blockSize: 'min-content',
borderRadius: "var(--ds-radius-small, 4px)",
overflow: 'hidden',
paddingInlineStart: "var(--ds-space-050, 4px)",
paddingInlineEnd: "var(--ds-space-050, 4px)",
backgroundColor: "var(--ds-background-accent-red-subtler-pressed, #FD9891)",
font: "var(--ds-font-body-small, normal 400 12px/16px \"Atlassian Sans\", ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)",
fontWeight: "var(--ds-font-weight-bold, 653)",
textOverflow: 'ellipsis',
whiteSpace: 'nowrap',
color: "var(--ds-text-warning-inverse, #292A2E)"
});
/**
* Frozen copies of the two node-name predicates `getChangedNodeStyle` branched on pre-refactor.
* The live copies are exported from `./wrapBlockNodeViewStyles`; these exist so this module stays
* self-contained (and so the OFF cohort keeps the exact pre-refactor classification) and go away
* with the rest of the file at cleanup.
*/
var isMultiContainerBlockNode = function isMultiContainerBlockNode(nodeName) {
return ['decisionList', 'layoutSection'].includes(nodeName);
};
var isTextLikeBlockNode = function isTextLikeBlockNode(nodeName) {
return ['heading', 'bulletList', 'orderedList', 'listItem', 'taskList', 'blockquote'].includes(nodeName);
};
/** Pre-refactor inline content style for a changed (inserted or deleted) block node. */
export var getChangedContentStyleLegacy = function getChangedContentStyleLegacy(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;
if (isExtendedEnabled(diffType) && isInserted) {
if (colorScheme === 'traditional') {
return isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
}
return isActive ? hideAddedDiffsUnderline ? editingStyleActiveExtendedNoUnderline : editingStyleActiveExtended : hideAddedDiffsUnderline ? editingStyleExtendedNoUnderline : editingStyleExtended;
}
if (colorScheme === 'traditional') {
return getDeletedTraditionalInlineStyle(isActive);
}
if (isActive) {
return deletedContentStyleActive;
}
return expValEquals('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? deletedContentStyleNew : deletedContentStyle;
};
/** Pre-refactor node-specific style for a changed block node. */
export var getChangedNodeStyleLegacy = function getChangedNodeStyleLegacy(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 isTraditional = colorScheme === 'traditional';
if (isExtendedEnabled(diffType) && isInserted) {
if (isMultiContainerBlockNode(nodeName)) {
return hideAddedDiffsUnderline ? editingContentStyleInBlockExtendedNoUnderline : editingContentStyleInBlockExtended;
}
if (isTextLikeBlockNode(nodeName)) {
return undefined;
}
if (isTraditional) {
return isActive ? traditionalStyleNodeActive : traditionalStyleNodeNew;
}
return editingStyleNode;
}
switch (nodeName) {
case 'blockquote':
if (isTraditional) {
return isActive ? deletedTraditionalStyleQuoteNodeActive : deletedTraditionalStyleQuoteNode;
}
return isActive ? deletedStyleQuoteNodeWithLozengeActive : deletedStyleQuoteNodeWithLozenge;
case 'expand':
case 'decisionList':
if (isTraditional) {
return isActive ? deletedTraditionalBlockOutlineActive : deletedTraditionalBlockOutlineNew;
}
return isActive ? deletedBlockOutlineActive : deletedBlockOutline;
case 'panel':
case 'codeBlock':
if (isTraditional) {
return isActive ? deletedTraditionalBlockOutlineRoundedActive : deletedTraditionalBlockOutlineRoundedNew;
}
return isActive ? deletedBlockOutlineRoundedActive : deletedBlockOutlineRounded;
default:
return undefined;
}
};
/** Pre-refactor unbounded strikethrough line for deleted content. */
export var getDeletedContentStyleUnboundedLegacy = function getDeletedContentStyleUnboundedLegacy(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
if (colorScheme === 'traditional' && isActive) {
return deletedTraditionalContentStyleUnboundedActive;
}
return colorScheme === 'traditional' ? deletedTraditionalContentStyleUnbounded : deletedContentStyleUnbounded;
};
/** Pre-refactor inline style for inserted content. */
export var getInsertedContentStyleLegacy = function getInsertedContentStyleLegacy(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var hideAddedDiffsUnderline = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
if (colorScheme === 'traditional') {
return isActive ? traditionalInsertStyleActive : traditionalInsertStyle;
}
if (isActive) {
return hideAddedDiffsUnderline ? editingStyleActiveExtendedNoUnderline : editingStyleActiveExtended;
}
return hideAddedDiffsUnderline ? editingStyleExtendedNoUnderline : editingStyleExtended;
};
/** Pre-refactor inline style for deleted content. */
export var getDeletedContentStyleLegacy = function getDeletedContentStyleLegacy(colorScheme) {
var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
var diffType = arguments.length > 2 ? arguments[2] : undefined;
if (colorScheme === 'traditional') {
return getDeletedTraditionalInlineStyle(isActive);
}
if (isExtendedEnabled(diffType)) {
return (isActive ? deletedContentStyleActive : deletedContentStyleNew) + deletedInlineContentStyleExtended;
}
return isActive ? deletedContentStyleActive : deletedContentStyleNew;
};
/**
* Pre-refactor table-cell overlay style, as chosen inside the `querySelectorAll('td, th')` loop of
* `applyCellOverlayStyles`. The choice does not vary per cell, so hoisting it out of the loop is
* behaviour-preserving.
*
* NOTE: not interchangeable with the same-named resolver in
* `createChangedRowDecorationWidgets.styles.legacy.ts`. The two pre-refactor call sites disagreed
* for the traditional non-rounded added cell — the nodeview path (here) used
* `traditionalAddedCellOverlayStyleNew`, the row-widget path used `traditionalAddedCellOverlayStyle`.
* Preserved as-is.
*/
export var resolveCellOverlayStyleLegacy = function resolveCellOverlayStyleLegacy(_ref) {
var colorScheme = _ref.colorScheme,
isInserted = _ref.isInserted,
isRoundedTable = _ref.isRoundedTable;
var isTraditional = colorScheme === 'traditional';
var deletedCellStyle = isTraditional ? isRoundedTable ? deletedTraditionalCellOverlayRoundedStyle : deletedTraditionalCellOverlayStyle : isRoundedTable ? deletedCellOverlayRoundedStyle : deletedCellOverlayStyle;
var addedCellStyle = isTraditional ? isRoundedTable ? traditionalAddedCellOverlayRoundedStyle : traditionalAddedCellOverlayStyleNew : isRoundedTable ? addedCellOverlayRoundedStyle : addedCellOverlayStyle;
return isInserted ? addedCellStyle : deletedCellStyle;
};
/** Pre-refactor inner style for the "Removed" lozenge on a deleted block node. */
export var resolveRemovedLozengeStyleLegacy = function resolveRemovedLozengeStyleLegacy(colorScheme, isActive) {
return isActive && colorScheme === 'traditional' ? lozengeStyleActiveTraditional : isActive ? lozengeStyleActiveStandard : lozengeStyle;
};
/**
* Pre-refactor style for inserted content nested inside a multi-container or list node (the
* `decisionList` / `layoutSection` / `taskList` children). Always the standard scheme's node
* outline, in every colour scheme.
*/
export var resolveNestedInsertedNodeStyleLegacy = function resolveNestedInsertedNodeStyleLegacy() {
return editingStyleNode;
};
/**
* Pre-refactor scheme predicate behind `maybeAddDeletedOutlineNewClass`. The `!isActive` half of
* the original condition stays at the call site in `wrapBlockNodeView.ts`.
*/
export var hasRestingDeletedRingLegacy = function hasRestingDeletedRingLegacy(colorScheme) {
return colorScheme === 'traditional';
};