UNPKG

@atlaskit/editor-common

Version:

A package that contains common classes and components for editor and renderer

159 lines (157 loc) • 12.9 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.tintDirtyTransaction = exports.telepointerStyle = exports.isDirtyTransaction = exports.TELEPOINTER_PULSE_DURING_TR_DURATION_MS = exports.TELEPOINTER_PULSE_DURING_TR_CLASS = exports.TELEPOINTER_PULSE_CLASS = exports.TELEPOINTER_DIM_CLASS = exports.TELEPOINTER_DATA_SESSION_ID_ATTR = exports.PROVIDER_ERROR_CODE = exports.DisconnectReason = void 0; var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral")); var _react = require("@emotion/react"); var _editorSharedStyles = require("@atlaskit/editor-shared-styles"); var _tokens = require("@atlaskit/tokens"); var _templateObject; /* eslint-disable @atlaskit/ui-styling-standard/use-compiled -- Pre-existing lint debt surfaced by this mechanical type-import-only PR. */ // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766 // Format of the payload returned by the callback function passed to the collab provider // that gets called when syncing with the back-end service fails. // Format of the document and its metadata returned from the collab provider // after editing and for draft sync // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any // Provider Errors // Emitted errors var PROVIDER_ERROR_CODE = exports.PROVIDER_ERROR_CODE = /*#__PURE__*/function (PROVIDER_ERROR_CODE) { PROVIDER_ERROR_CODE["NO_PERMISSION_ERROR"] = "NO_PERMISSION_ERROR"; PROVIDER_ERROR_CODE["INVALID_USER_TOKEN"] = "INVALID_USER_TOKEN"; PROVIDER_ERROR_CODE["DOCUMENT_NOT_FOUND"] = "DOCUMENT_NOT_FOUND"; PROVIDER_ERROR_CODE["LOCKED"] = "LOCKED"; PROVIDER_ERROR_CODE["FAIL_TO_SAVE"] = "FAIL_TO_SAVE"; PROVIDER_ERROR_CODE["DOCUMENT_RESTORE_ERROR"] = "DOCUMENT_RESTORE_ERROR"; PROVIDER_ERROR_CODE["INITIALISATION_ERROR"] = "INITIALISATION_ERROR"; PROVIDER_ERROR_CODE["NETWORK_ISSUE"] = "NETWORK_ISSUE"; PROVIDER_ERROR_CODE["INVALID_PROVIDER_CONFIGURATION"] = "INVALID_PROVIDER_CONFIGURATION"; PROVIDER_ERROR_CODE["INTERNAL_SERVICE_ERROR"] = "INTERNAL_SERVICE_ERROR"; PROVIDER_ERROR_CODE["DOCUMENT_UPDATE_ERROR"] = "DOCUMENT_UPDATE_ERROR"; return PROVIDER_ERROR_CODE; }({}); /** * This occurs when the provided user token is considered invalid for the given document ARI. * It happens during initialisation of the provider. * It could mean the document has been deleted (hence not found). * @message Message returned to editor, i.e User does not have permissions to access this document or document is not found * @recoverable It is recoverable, as we will try to refresh the token. */ /** * Similar to InsufficientEditingPermission, but the user token is invalid because it has expired or been revoked. * It may also be an invalid token format. * This error is given to the provider by NCS. * @message Message returned to editor, i.e. The user token was invalid * @recoverable It is recoverable, as we will try to refresh the token. */ /** * Document not found error, thrown when the provider is unable to find a document with the given ARI and user token. * It occurs during fetchCatchup, a function that fetches the latest document state during catchup. * We need to recieve a 404 from the document service to throw this error. * @message Message returned to editor, i.e. The requested document is not found * @recoverable It is recoverable, as the provider can try again later. */ /** * This error is thrown when the document is locked by another user. * The error is passed to us by NCS. * @message Message returned to editor, i.e. The document is currently not available, please try again later * @recoverable It is recoverable, as the provider can try again later. */ /** * This error is thrown when the provider is unable to save the document. * This can happen when the connection to dynamoDB is lost, or when we do not have sufficient permissions (DYNAMO ERROR). * This error is given to us by NCS. * @message Message returned to editor, i.e. Collab service is not able to save changes * @recoverable It is not recoverable, as we don't want the user to continue editing a document that is not being saved. */ /** * This error is thrown when the provider is unable to restore the document. * It occurs during onRestore, a function that restores the document to a previous version and reapplies unconfirmed steps. * onRestore is called when page recovery has emitted an 'init' event on a page client is currently connected to. * It could mean we failed to update the page metadata, or we failed to reapply unconfirmed steps. * @message Message returned to editor, i.e. Collab service unable to restore document * @recoverable It is not recoverable, as the provider has no further options after this. * The user will need to refresh the page to try again. */ /** * The initial document couldn't be loaded from the collab service. * This error is given to us by NCS. * It could indicate either a network issue, or an internal service error in NCS. * @message Message returned to editor, i.e. The initial document couldn't be loaded from the collab service * @recoverable It is not recoverable, as the provider cannot do anything to fix it. * The user will need to refresh the page to try again. */ /** * Couldn't reconnect to the collab service (NCS) due to network issues. * NCS could be down, or the user could be offline. It's also possible the url is incorrect, or the user is behind a proxy blocking the connection. * Fired upon a reconnection attempt error (from Socket.IO Manager) * @message Message returned to editor, i.e. Couldn't reconnect to the collab service due to network issues * @recoverable It is recoverable, as the provider will try to reconnect. */ /** * This error is thrown when the provider has an invalid configuration. * It could happen due to these errors from NCS: * NAMESPACE_INVALID INVALID_ACTIVATION_ID INVALID_DOCUMENT_ARI INVALID_CLOUD_ID * @message Message returned to editor, i.e. Invalid provider configuration * @recoverable It is not recoverable, as the provider cannot do anything to fix it. * The service using the provider will need to fix the configuration. */ /** * This error is thrown when the provider encounters an internal service error, not otherwise accounted for. * @message Message returned to editor, i.e. Collab Provider experienced an unrecoverable error * @recoverable It is not recoverable, as the provider cannot do anything to fix it. */ /** * A union of all possible provider errors that can be emitted back to the editor. */ // Collab Provider interface // Ignored via go/ees007 // eslint-disable-next-line @atlaskit/editor/enforce-todo-comment-format // TODO: Deprecate redundant payload types var DisconnectReason = exports.DisconnectReason = /*#__PURE__*/function (DisconnectReason) { DisconnectReason["CLIENT_DISCONNECT"] = "CLIENT_DISCONNECT"; DisconnectReason["SERVER_DISCONNECT"] = "SERVER_DISCONNECT"; DisconnectReason["SOCKET_CLOSED"] = "SOCKET_CLOSED"; DisconnectReason["SOCKET_ERROR"] = "SOCKET_ERROR"; DisconnectReason["SOCKET_TIMEOUT"] = "SOCKET_TIMEOUT"; DisconnectReason["UNKNOWN_DISCONNECT"] = "UNKNOWN_DISCONNECT"; return DisconnectReason; }({}); // Match with ProseMirror: https://prosemirror.net/docs/ref/#transform.ReplaceStep // Match with ProseMirror: https://prosemirror.net/docs/ref/#transform.ReplaceAroundStep // Match with ProseMirror: https://prosemirror.net/docs/ref/#transform.AttrStep //Intersection: NCS custom step type config in adf-schema //Unions var telepointerColorStyle = function telepointerColorStyle(backgroundColor, textColor, index) { var _getGlobalTheme = (0, _tokens.getGlobalTheme)(), colorMode = _getGlobalTheme.colorMode; var backgroundStyle = colorMode === 'dark' ? "linear-gradient(to bottom, ".concat(backgroundColor, " -800000%, transparent 200000%)") : "linear-gradient(to bottom, ".concat(backgroundColor, " -850000%, transparent 150000%)"); return "\n &.color-".concat(index, " {\n background: ").concat(backgroundStyle, ";\n &::after {\n background-color: ").concat(backgroundColor, ";\n color: ").concat(textColor, ";\n border-color: ").concat(backgroundColor, ";\n }\n }\n "); }; var TELEPOINTER_DIM_CLASS = exports.TELEPOINTER_DIM_CLASS = 'telepointer-dim'; var TELEPOINTER_PULSE_CLASS = exports.TELEPOINTER_PULSE_CLASS = 'telepointer-pulse-animate'; var TELEPOINTER_PULSE_DURING_TR_CLASS = exports.TELEPOINTER_PULSE_DURING_TR_CLASS = 'telepointer-pulse-during-tr'; var TELEPOINTER_PULSE_DURING_TR_DURATION_MS = exports.TELEPOINTER_PULSE_DURING_TR_DURATION_MS = 7500; // Keeping it longer so it'll be easier to spot during transactions var TELEPOINTER_DATA_SESSION_ID_ATTR = exports.TELEPOINTER_DATA_SESSION_ID_ATTR = 'data-telepointer-sessionid'; // ED-22557: Safely convert to object styling // Disable top: -14px since it is necessary to align to cursor // eslint-disable-next-line @atlaskit/design-system/ensure-design-token-usage/preview, @atlaskit/design-system/no-css-tagged-template-expression, @atlaskit/ui-styling-standard/no-exported-styles -- Ignored via go/DSP-18766 var telepointerStyle = exports.telepointerStyle = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n\t@keyframes pulseIn {\n\t\t0%,\n\t\t100% {\n\t\t\ttransform: scaleX(0);\n\t\t\topacity: 0;\n\t\t}\n\t\t10% {\n\t\t\ttransform: scaleX(1.4);\n\t\t\topacity: 1;\n\t\t}\n\t\t15%,\n\t\t85% {\n\t\t\ttransform: scaleX(1);\n\t\t\topacity: 1;\n\t\t}\n\t}\n\n\t@keyframes pulseOut {\n\t\t0%,\n\t\t90%,\n\t\t100% {\n\t\t\ttransform: scaleX(1);\n\t\t\topacity: 1;\n\t\t}\n\t\t10%,\n\t\t80% {\n\t\t\ttransform: scaleX(0);\n\t\t\topacity: 0;\n\t\t}\n\t}\n\n\t@keyframes pulseInDuringTr {\n\t\t0%,\n\t\t95% {\n\t\t\ttransform: scaleX(1);\n\t\t\topacity: 1;\n\t\t}\n\t\t100% {\n\t\t\ttransform: scaleX(0);\n\t\t\topacity: 0;\n\t\t}\n\t}\n\n\t@keyframes pulseOutDuringTr {\n\t\t100% {\n\t\t\ttransform: scaleX(1);\n\t\t\topacity: 1;\n\t\t}\n\t\t0%,\n\t\t90% {\n\t\t\ttransform: scaleX(0);\n\t\t\topacity: 0;\n\t\t}\n\t}\n\n\t.ProseMirror .telepointer {\n\t\tposition: relative;\n\t\ttransition: opacity 200ms;\n\n\t\t&.telepointer-selection:not(.inlineNodeView) {\n\t\t\tline-height: 1.2;\n\t\t\tpointer-events: none;\n\t\t\tuser-select: none;\n\t\t}\n\n\t\t&.telepointer-selection-badge {\n\t\t\t.telepointer-initial,\n\t\t\t.telepointer-fullname {\n\t\t\t\tposition: absolute;\n\t\t\t\tdisplay: block;\n\t\t\t\tuser-select: none;\n\t\t\t\twhite-space: pre;\n\t\t\t\ttop: -14px;\n\t\t\t\tleft: 0px;\n\t\t\t\tfont: ", ";\n\t\t\t\tpadding-left: ", ";\n\t\t\t\tpadding-right: ", ";\n\t\t\t\tborder-radius: 0 2px 2px 0;\n\t\t\t}\n\n\t\t\t.telepointer-initial {\n\t\t\t\topacity: 1;\n\t\t\t\ttransition: opacity 0.15s ease-out;\n\t\t\t}\n\n\t\t\t.telepointer-fullname {\n\t\t\t\topacity: 0;\n\t\t\t\ttransform: scaleX(0);\n\t\t\t\ttransform-origin: top left;\n\t\t\t\ttransition:\n\t\t\t\t\ttransform 0.15s ease-out,\n\t\t\t\t\topacity 0.15s ease-out;\n\t\t\t}\n\t\t}\n\n\t\t&.", " {\n\t\t\t.telepointer-initial {\n\t\t\t\tanimation: pulseOut 2.5s ease-in-out;\n\t\t\t}\n\n\t\t\t.telepointer-fullname {\n\t\t\t\tanimation: pulseIn 2.5s ease-in-out;\n\t\t\t}\n\t\t}\n\n\t\t&.", " {\n\t\t\t.telepointer-initial {\n\t\t\t\tanimation: pulseOutDuringTr ", "ms ease-in-out;\n\t\t\t}\n\n\t\t\t.telepointer-fullname {\n\t\t\t\tanimation: pulseInDuringTr ", "ms ease-in-out;\n\t\t\t}\n\t\t}\n\n\t\t&:hover {\n\t\t\t.telepointer-initial {\n\t\t\t\topacity: 0;\n\t\t\t\ttransition-delay: 150ms;\n\t\t\t}\n\n\t\t\t.telepointer-fullname {\n\t\t\t\ttransform: scaleX(1);\n\t\t\t\topacity: 1;\n\t\t\t\tz-index: 1;\n\t\t\t}\n\t\t}\n\n\t\t&.", " {\n\t\t\topacity: 0.2;\n\t\t}\n\n\t\t", ";\n\t}\n"])), "var(--ds-font-body-small, normal 400 12px/16px \"Atlassian Sans\", ui-sans-serif, -apple-system, BlinkMacSystemFont, \"Segoe UI\", Ubuntu, \"Helvetica Neue\", sans-serif)", "var(--ds-space-050, 4px)", "var(--ds-space-050, 4px)", TELEPOINTER_PULSE_CLASS, TELEPOINTER_PULSE_DURING_TR_CLASS, TELEPOINTER_PULSE_DURING_TR_DURATION_MS, TELEPOINTER_PULSE_DURING_TR_DURATION_MS, TELEPOINTER_DIM_CLASS, _editorSharedStyles.participantColors.map(function (participantColor, index) { return telepointerColorStyle(participantColor.backgroundColor, participantColor.textColor, index); })); var tintKey = 'collab:isDirtyTransaction'; var isDirtyTransaction = exports.isDirtyTransaction = function isDirtyTransaction(tr) { return Boolean(tr.getMeta(tintKey)); }; /* * This function is used to mark which commands that are dispatching * unnecessary changes on Editor. */ var tintDirtyTransaction = exports.tintDirtyTransaction = function tintDirtyTransaction(tr) { tr.setMeta(tintKey, true); };