@atlaskit/editor-plugin-expand
Version:
Expand plugin for @atlaskit/editor-core
71 lines (70 loc) • 5.34 kB
JavaScript
;
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.toDOM = exports.getExpandBodyAriaLabel = exports.buildExpandClassName = void 0;
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
var _expand = require("@atlaskit/editor-common/expand");
var _styles = require("@atlaskit/editor-common/styles");
var _ui = require("@atlaskit/editor-common/ui");
var _isExperimentEnabled = require("@atlaskit/platform-feature-experiments/is-experiment-enabled");
var _fg = require("@atlaskit/platform-feature-flags/fg");
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
var buildExpandClassName = exports.buildExpandClassName = function buildExpandClassName(type, expanded) {
return "".concat(_styles.expandClassNames.prefix, " ").concat(_styles.expandClassNames.type(type), " ").concat(expanded ? _styles.expandClassNames.expanded : '');
};
var getExpandBodyAriaLabel = exports.getExpandBodyAriaLabel = function getExpandBodyAriaLabel(title, intl) {
var safeTitle = title.trim() || (intl === null || intl === void 0 ? void 0 : intl.formatMessage(_ui.expandMessages.expandBodyAriaLabelUntitled)) || _ui.expandMessages.expandBodyAriaLabelUntitled.defaultMessage;
return (intl === null || intl === void 0 ? void 0 : intl.formatMessage(_ui.expandMessages.expandBodyAriaLabel, {
title: safeTitle
})) || _ui.expandMessages.expandBodyAriaLabel.defaultMessage.replace('{title}', safeTitle);
};
var toDOM = exports.toDOM = function toDOM(node, __livePage, intl, titleReadOnly, contentEditable) {
var _expandedState$get, _node$attrs$title, _intl$formatMessage;
return ['div', _objectSpread({
// prettier-ignore
'class': buildExpandClassName(node.type.name, (_expandedState$get = _expand.expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false),
'data-node-type': node.type.name,
'data-title': node.attrs.title
}, (0, _fg.fg)('platform_editor_adf_with_localid') && {
'data-local-id': node.attrs.localId
}), ['div', {
// prettier-ignore
'class': _styles.expandClassNames.titleContainer,
contenteditable: 'false',
// Element gains access to focus events.
// This is needed to prevent PM gaining access
// on interacting with our controls.
tabindex: '-1'
},
// prettier-ignore
['div', {
'class': _styles.expandClassNames.icon,
style: "display: flex; width: ".concat("var(--ds-space-300, 24px)", "; height: ", "var(--ds-space-300, 24px)")
}], ['div', {
// prettier-ignore
'class': _styles.expandClassNames.inputContainer
}, ['input', {
// prettier-ignore
'class': _styles.expandClassNames.titleInput,
'aria-label': intl && intl.formatMessage(_ui.expandMessages.expandArialabel) || _ui.expandMessages.expandArialabel.defaultMessage,
value: node.attrs.title,
placeholder: intl && typeof intl.formatMessage === 'function' && intl.formatMessage(_ui.expandMessages.expandPlaceholderText) || _ui.expandMessages.expandPlaceholderText.defaultMessage,
type: 'text',
readonly: titleReadOnly ? 'true' : undefined
}]]], [(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_expand_content_a11y_2') ? 'section' : 'div', _objectSpread(_objectSpread({
// prettier-ignore
class: "".concat(_styles.expandClassNames.content, " ").concat(_expand.expandedState.get(node) ? '' : _styles.expandClassNames.contentCollapsed),
contenteditable: contentEditable !== undefined ? contentEditable ? 'true' : 'false' : undefined
}, !(0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_expand_content_a11y_2') && {
role: 'textbox',
'aria-multiline': 'true',
'aria-label': intl && intl.formatMessage(_ui.expandMessages.expandBodyAriaLabelOriginal) || _ui.expandMessages.expandBodyAriaLabelOriginal.defaultMessage
}), (0, _isExperimentEnabled.isExperimentEnabled)('platform_editor_expand_content_a11y_2') && {
'aria-label': getExpandBodyAriaLabel((_node$attrs$title = node.attrs.title) !== null && _node$attrs$title !== void 0 ? _node$attrs$title : '', intl),
'aria-description': (intl === null || intl === void 0 ? void 0 : intl.formatMessage(_ui.expandMessages.expandBodyAriaDescription)) || _ui.expandMessages.expandBodyAriaDescription.defaultMessage,
'aria-roledescription': (_intl$formatMessage = intl === null || intl === void 0 ? void 0 : intl.formatMessage(_ui.expandMessages.expandBodyRoleDescription)) !== null && _intl$formatMessage !== void 0 ? _intl$formatMessage : _ui.expandMessages.expandBodyRoleDescription.defaultMessage
}), 0]];
};