UNPKG

@atlaskit/editor-common

Version:

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

154 lines (152 loc) • 10.5 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); var _typeof = require("@babel/runtime/helpers/typeof"); Object.defineProperty(exports, "__esModule", { value: true }); exports.tintDirtyTransaction = exports.telepointerStyle = exports.isDirtyTransaction = exports.colors = exports.TELEPOINTER_DIM_CLASS = exports.PROVIDER_ERROR_CODE = exports.DisconnectReason = void 0; var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral")); var _react = require("@emotion/react"); var _adfSchema = require("@atlaskit/adf-schema"); var _editorSharedStyles = require("@atlaskit/editor-shared-styles"); var themeColors = _interopRequireWildcard(require("@atlaskit/theme/colors")); var _templateObject; function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); } function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; } // 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 // 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 // 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; }({}); // TODO: https://product-fabric.atlassian.net/browse/DSP-7269 /* eslint-disable @atlaskit/design-system/ensure-design-token-usage */ var colors = exports.colors = [themeColors.R100, themeColors.R300, themeColors.R500, themeColors.Y100, themeColors.Y300, themeColors.Y500, themeColors.G100, themeColors.G300, themeColors.G500, themeColors.T100, themeColors.T300, themeColors.T500, themeColors.B100, themeColors.B300, themeColors.B500, themeColors.P100, themeColors.P300, themeColors.P500, themeColors.N70, themeColors.N200, themeColors.N800].map(function (solid) { return { solid: solid, selection: (0, _adfSchema.hexToRgba)(solid, 0.2) }; }); var telepointerColorStyle = function telepointerColorStyle(color, index) { return "\n &.color-".concat(index, " {\n background-color: ").concat(color.selection, ";\n &::after {\n background-color: ").concat(color.solid, ";\n color: ", "var(--ds-text-inverse, #fff)", ";\n border-color: ").concat(color.solid, ";\n }\n }\n"); }; var TELEPOINTER_DIM_CLASS = exports.TELEPOINTER_DIM_CLASS = 'telepointer-dim'; // 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 var telepointerStyle = exports.telepointerStyle = (0, _react.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n .ProseMirror .telepointer {\n position: relative;\n transition: opacity 200ms;\n\n &.telepointer-selection {\n line-height: 1.2;\n pointer-events: none;\n user-select: none;\n }\n\n &.telepointer-selection-badge::after {\n content: attr(data-initial);\n position: absolute;\n display: block;\n top: -14px;\n font-size: ", ";\n padding: ", ";\n color: ", ";\n left: 0px;\n border-radius: 2px 2px 2px 0;\n line-height: initial;\n }\n\n &.", " {\n opacity: 0.2;\n }\n\n ", ";\n }\n"])), (0, _editorSharedStyles.relativeFontSizeToBase16)(9), "var(--ds-space-025, 2px)", "var(--ds-text-inverse, white)", TELEPOINTER_DIM_CLASS, colors.map(function (color, index) { return telepointerColorStyle(color, 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); };