UNPKG

@atlaskit/editor-plugin-show-diff

Version:

ShowDiff plugin for @atlaskit/editor-core

225 lines (213 loc) 12.5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.resolveRemovedLozengeStyleLegacy = exports.resolveNestedInsertedNodeStyleLegacy = exports.resolveCellOverlayStyleLegacy = exports.hasRestingDeletedRingLegacy = exports.getInsertedContentStyleLegacy = exports.getDeletedContentStyleUnboundedLegacy = exports.getDeletedContentStyleLegacy = exports.getChangedNodeStyleLegacy = exports.getChangedContentStyleLegacy = void 0; var _lazyNodeView = require("@atlaskit/editor-common/lazy-node-view"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _isExtendedEnabled = require("../../isExtendedEnabled"); var _standard = require("../colorSchemes/standard"); var _traditional = require("../colorSchemes/traditional"); /** * 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). */ var lozengeStyle = (0, _lazyNodeView.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 = (0, _lazyNodeView.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 = (0, _lazyNodeView.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. */ var getChangedContentStyleLegacy = exports.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 ((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && isInserted) { if (colorScheme === 'traditional') { return isActive ? _traditional.traditionalInsertStyleActive : _traditional.traditionalInsertStyle; } return isActive ? hideAddedDiffsUnderline ? _standard.editingStyleActiveExtendedNoUnderline : _standard.editingStyleActiveExtended : hideAddedDiffsUnderline ? _standard.editingStyleExtendedNoUnderline : _standard.editingStyleExtended; } if (colorScheme === 'traditional') { return (0, _traditional.getDeletedTraditionalInlineStyle)(isActive); } if (isActive) { return _standard.deletedContentStyleActive; } return (0, _expValEquals.expValEquals)('platform_editor_enghealth_a11y_jan_fixes', 'isEnabled', true) ? _standard.deletedContentStyleNew : _standard.deletedContentStyle; }; /** Pre-refactor node-specific style for a changed block node. */ var getChangedNodeStyleLegacy = exports.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 ((0, _isExtendedEnabled.isExtendedEnabled)(diffType) && isInserted) { if (isMultiContainerBlockNode(nodeName)) { return hideAddedDiffsUnderline ? _standard.editingContentStyleInBlockExtendedNoUnderline : _standard.editingContentStyleInBlockExtended; } if (isTextLikeBlockNode(nodeName)) { return undefined; } if (isTraditional) { return isActive ? _traditional.traditionalStyleNodeActive : _traditional.traditionalStyleNodeNew; } return _standard.editingStyleNode; } switch (nodeName) { case 'blockquote': if (isTraditional) { return isActive ? _traditional.deletedTraditionalStyleQuoteNodeActive : _traditional.deletedTraditionalStyleQuoteNode; } return isActive ? _standard.deletedStyleQuoteNodeWithLozengeActive : _standard.deletedStyleQuoteNodeWithLozenge; case 'expand': case 'decisionList': if (isTraditional) { return isActive ? _traditional.deletedTraditionalBlockOutlineActive : _traditional.deletedTraditionalBlockOutlineNew; } return isActive ? _standard.deletedBlockOutlineActive : _standard.deletedBlockOutline; case 'panel': case 'codeBlock': if (isTraditional) { return isActive ? _traditional.deletedTraditionalBlockOutlineRoundedActive : _traditional.deletedTraditionalBlockOutlineRoundedNew; } return isActive ? _standard.deletedBlockOutlineRoundedActive : _standard.deletedBlockOutlineRounded; default: return undefined; } }; /** Pre-refactor unbounded strikethrough line for deleted content. */ var getDeletedContentStyleUnboundedLegacy = exports.getDeletedContentStyleUnboundedLegacy = function getDeletedContentStyleUnboundedLegacy(colorScheme) { var isActive = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; if (colorScheme === 'traditional' && isActive) { return _traditional.deletedTraditionalContentStyleUnboundedActive; } return colorScheme === 'traditional' ? _traditional.deletedTraditionalContentStyleUnbounded : _standard.deletedContentStyleUnbounded; }; /** Pre-refactor inline style for inserted content. */ var getInsertedContentStyleLegacy = exports.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 ? _traditional.traditionalInsertStyleActive : _traditional.traditionalInsertStyle; } if (isActive) { return hideAddedDiffsUnderline ? _standard.editingStyleActiveExtendedNoUnderline : _standard.editingStyleActiveExtended; } return hideAddedDiffsUnderline ? _standard.editingStyleExtendedNoUnderline : _standard.editingStyleExtended; }; /** Pre-refactor inline style for deleted content. */ var getDeletedContentStyleLegacy = exports.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 (0, _traditional.getDeletedTraditionalInlineStyle)(isActive); } if ((0, _isExtendedEnabled.isExtendedEnabled)(diffType)) { return (isActive ? _standard.deletedContentStyleActive : _standard.deletedContentStyleNew) + _standard.deletedInlineContentStyleExtended; } return isActive ? _standard.deletedContentStyleActive : _standard.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. */ var resolveCellOverlayStyleLegacy = exports.resolveCellOverlayStyleLegacy = function resolveCellOverlayStyleLegacy(_ref) { var colorScheme = _ref.colorScheme, isInserted = _ref.isInserted, isRoundedTable = _ref.isRoundedTable; var isTraditional = colorScheme === 'traditional'; var deletedCellStyle = isTraditional ? isRoundedTable ? _traditional.deletedTraditionalCellOverlayRoundedStyle : _traditional.deletedTraditionalCellOverlayStyle : isRoundedTable ? _standard.deletedCellOverlayRoundedStyle : _standard.deletedCellOverlayStyle; var addedCellStyle = isTraditional ? isRoundedTable ? _traditional.traditionalAddedCellOverlayRoundedStyle : _traditional.traditionalAddedCellOverlayStyleNew : isRoundedTable ? _standard.addedCellOverlayRoundedStyle : _standard.addedCellOverlayStyle; return isInserted ? addedCellStyle : deletedCellStyle; }; /** Pre-refactor inner style for the "Removed" lozenge on a deleted block node. */ var resolveRemovedLozengeStyleLegacy = exports.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. */ var resolveNestedInsertedNodeStyleLegacy = exports.resolveNestedInsertedNodeStyleLegacy = function resolveNestedInsertedNodeStyleLegacy() { return _standard.editingStyleNode; }; /** * Pre-refactor scheme predicate behind `maybeAddDeletedOutlineNewClass`. The `!isActive` half of * the original condition stays at the call site in `wrapBlockNodeView.ts`. */ var hasRestingDeletedRingLegacy = exports.hasRestingDeletedRingLegacy = function hasRestingDeletedRingLegacy(colorScheme) { return colorScheme === 'traditional'; };