UNPKG

@atlaskit/editor-plugin-unsupported-content

Version:

Unsupported Content plugin for @atlaskit/editor-core

51 lines (50 loc) • 2.08 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getUnsupportedContent = getUnsupportedContent; /** * Resolves the label shown on an unsupported content node. * * Duplicated from `@atlaskit/editor-common` (`src/ui/unsupported-content-helper.ts`) to avoid a * dependency issue. A separate PR will remove the duplication. * * @see https://hello.jira.atlassian.cloud/jira/browse/EDITOR-8637 */ function getUnsupportedContent( // Ignored via go/ees005 // eslint-disable-next-line @typescript-eslint/no-explicit-any message, prefix, node, intl // eslint-disable-next-line @typescript-eslint/no-explicit-any ) { var defaultLocale = 'en'; var canTranslateToLocale = true; var locale = intl ? intl.locale : defaultLocale; var finalMessage = message.defaultMessage; if (node && locale.startsWith(defaultLocale)) { // `confluenceUnsupportedBlock` and `confluenceUnsupportedInline` are declared with a // `cxhtml` attribute and no `originalValue`, so this must not assume it exists. // // NOTE: intentional deviation from the `@atlaskit/editor-common` original, which throws a // TypeError for those node types. In the React node views that throw is swallowed by // `ReactNodeView`'s ErrorBoundary; a vanilla node view has no such boundary, so it would // propagate out of the ProseMirror node view constructor. Keep this guard when the // duplication is resolved. // // @see https://hello.jira.atlassian.cloud/jira/browse/EDITOR-8637 var originalValue = node.attrs.originalValue; if (originalValue) { if (originalValue.text || originalValue.attrs && originalValue.attrs.text) { finalMessage = originalValue.text ? originalValue.text : originalValue.attrs.text; canTranslateToLocale = false; } else if (originalValue.type) { finalMessage = "".concat(prefix, " ").concat(originalValue.type); canTranslateToLocale = false; } } } if (intl && canTranslateToLocale) { return intl.formatMessage(message); } return finalMessage; }