@atlaskit/editor-plugin-tasks-and-decisions
Version:
Tasks and decisions plugin for @atlaskit/editor-core
362 lines (360 loc) • 19.4 kB
JavaScript
/* tasksAndDecisionsPlugin.tsx generated by @compiled/babel-plugin v0.39.1 */
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
var _typeof = require("@babel/runtime/helpers/typeof");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.tasksAndDecisionsPlugin = void 0;
require("./tasksAndDecisionsPlugin.compiled.css");
var React = _interopRequireWildcard(require("react"));
var _runtime = require("@compiled/react/runtime");
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
var _adfSchema = require("@atlaskit/adf-schema");
var _analytics = require("@atlaskit/editor-common/analytics");
var _blockMenu = require("@atlaskit/editor-common/block-menu");
var _indentation = require("@atlaskit/editor-common/indentation");
var _messages = require("@atlaskit/editor-common/messages");
var _quickInsert = require("@atlaskit/editor-common/quick-insert");
var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
var _utils = require("@atlaskit/editor-prosemirror/utils");
var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
var _taskItemNodeSpec = require("./nodeviews/taskItemNodeSpec");
var _decisionItem = require("./nodeviews/toDOM-fixes/decisionItem");
var _helpers = require("./pm-plugins/helpers");
var _inputRules = _interopRequireDefault(require("./pm-plugins/input-rules"));
var _insertCommands = require("./pm-plugins/insert-commands");
var _keymaps = _interopRequireWildcard(require("./pm-plugins/keymaps"));
var _main = require("./pm-plugins/main");
var _pluginKey = require("./pm-plugins/plugin-key");
var _toggleTasklistCommands = require("./pm-plugins/toggle-tasklist-commands");
var _DecisionListBlockMenuItem = require("./ui/DecisionListBlockMenuItem/DecisionListBlockMenuItem");
var _RequestToEditPopup = require("./ui/Task/RequestToEditPopup");
var _TaskListBlockMenuItem = require("./ui/TaskListBlockMenuItem/TaskListBlockMenuItem");
var _toolbarComponents = require("./ui/toolbar-components");
var _ToolbarDecision = _interopRequireDefault(require("./ui/ToolbarDecision"));
var _ToolbarTask = _interopRequireDefault(require("./ui/ToolbarTask"));
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
// Ignored via go/ees005
// eslint-disable-next-line import/no-named-as-default
var taskDecisionToolbarGroupStyles = null;
var TASK_LIST_NODE_NAME = 'taskList';
var DECISION_LIST_NODE_NAME = 'decisionList';
var addItem = function addItem(insert, listType, schema) {
return function (_ref) {
var listLocalId = _ref.listLocalId,
itemLocalId = _ref.itemLocalId;
var _getListTypes = (0, _insertCommands.getListTypes)(listType, schema),
list = _getListTypes.list,
item = _getListTypes.item;
return insert(list.createChecked({
localId: listLocalId
}, item.createChecked({
localId: itemLocalId
})));
};
};
function ContentComponent(_ref2) {
var editorView = _ref2.editorView,
popupsMountPoint = _ref2.popupsMountPoint,
popupsBoundariesElement = _ref2.popupsBoundariesElement,
popupsScrollableElement = _ref2.popupsScrollableElement,
dependencyApi = _ref2.dependencyApi;
var openRequestToEditPopupAt = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(dependencyApi, 'taskDecision.openRequestToEditPopupAt');
var hasEditPermission = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(dependencyApi, 'taskDecision.hasEditPermission');
if (!editorView || hasEditPermission || !openRequestToEditPopupAt) {
return null;
}
var domAtPos = editorView.domAtPos.bind(editorView);
// eslint-disable-next-line @atlaskit/editor/no-as-casting
var element = (0, _utils.findDomRefAtPos)(openRequestToEditPopupAt, domAtPos);
var handleOnClose = function handleOnClose() {
(0, _helpers.closeRequestEditPopupAt)(editorView);
editorView.focus();
};
return /*#__PURE__*/React.createElement(_RequestToEditPopup.RequestToEditPopup, {
key: openRequestToEditPopupAt,
api: dependencyApi,
editorView: editorView,
mountTo: popupsMountPoint,
boundariesElement: popupsBoundariesElement,
scrollableElement: popupsScrollableElement,
element: element,
onClose: handleOnClose
});
}
var tasksAndDecisionsPlugin = exports.tasksAndDecisionsPlugin = function tasksAndDecisionsPlugin(_ref3) {
var _api$analytics2, _api$analytics3, _api$analytics4;
var _ref3$config = _ref3.config,
_ref3$config2 = _ref3$config === void 0 ? {} : _ref3$config,
allowNestedTasks = _ref3$config2.allowNestedTasks,
consumeTabs = _ref3$config2.consumeTabs,
useLongPressSelection = _ref3$config2.useLongPressSelection,
_ref3$config2$hasEdit = _ref3$config2.hasEditPermission,
hasEditPermission = _ref3$config2$hasEdit === void 0 ? true : _ref3$config2$hasEdit,
hasRequestedEditPermission = _ref3$config2.hasRequestedEditPermission,
quickInsertActionDescription = _ref3$config2.quickInsertActionDescription,
requestToEditContent = _ref3$config2.requestToEditContent,
taskDecisionProvider = _ref3$config2.taskDecisionProvider,
taskPlaceholder = _ref3$config2.taskPlaceholder,
allowBlockTaskItem = _ref3$config2.allowBlockTaskItem,
api = _ref3.api;
var getIdentifierProvider = function getIdentifierProvider() {
var _api$contextIdentifie;
return api === null || api === void 0 || (_api$contextIdentifie = api.contextIdentifier) === null || _api$contextIdentifie === void 0 || (_api$contextIdentifie = _api$contextIdentifie.sharedState.currentState()) === null || _api$contextIdentifie === void 0 ? void 0 : _api$contextIdentifie.contextIdentifierProvider;
};
var previousTaskAndDecisionProvider;
var isToolbarAIFCEnabled = Boolean(api === null || api === void 0 ? void 0 : api.toolbar);
if (isToolbarAIFCEnabled) {
var _api$toolbar;
api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _toolbarComponents.getTasksAndDecisionsToolbarComponents)({
api: api
}));
}
if (taskDecisionProvider) {
taskDecisionProvider.then(function (provider) {
api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
var tr = _ref4.tr;
return (0, _insertCommands.setProvider)(provider)(tr);
});
});
}
if ((0, _experiments.editorExperiment)('platform_editor_block_menu', true)) {
var _api$blockMenu;
api === null || api === void 0 || (_api$blockMenu = api.blockMenu) === null || _api$blockMenu === void 0 || _api$blockMenu.actions.registerBlockMenuComponents([{
type: 'block-menu-item',
key: _blockMenu.TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key,
parent: {
type: 'block-menu-section',
key: _blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION.key,
rank: _blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION_RANK[_blockMenu.TRANSFORM_STRUCTURE_TASK_LIST_MENU_ITEM.key]
},
component: function component() {
return /*#__PURE__*/React.createElement(_TaskListBlockMenuItem.TaskListBlockMenuItem, {
api: api
});
},
isHidden: function isHidden() {
var _api$blockMenu2;
return Boolean(api === null || api === void 0 || (_api$blockMenu2 = api.blockMenu) === null || _api$blockMenu2 === void 0 ? void 0 : _api$blockMenu2.actions.isTransformOptionDisabled(TASK_LIST_NODE_NAME));
}
}, {
type: 'block-menu-item',
key: _blockMenu.TRANSFORM_STRUCTURE_DECISION_MENU_ITEM.key,
parent: {
type: 'block-menu-section',
key: _blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION.key,
rank: _blockMenu.TRANSFORM_STRUCTURE_MENU_SECTION_RANK[_blockMenu.TRANSFORM_STRUCTURE_DECISION_MENU_ITEM.key]
},
component: function component() {
return /*#__PURE__*/React.createElement(_DecisionListBlockMenuItem.DecisionListBlockMenuItem, {
api: api
});
},
isHidden: function isHidden() {
var _api$blockMenu3;
return Boolean(api === null || api === void 0 || (_api$blockMenu3 = api.blockMenu) === null || _api$blockMenu3 === void 0 ? void 0 : _api$blockMenu3.actions.isTransformOptionDisabled(DECISION_LIST_NODE_NAME));
}
}]);
}
return {
name: 'taskDecision',
nodes: function nodes() {
return [{
name: 'decisionList',
node: _adfSchema.decisionList
}, {
name: 'decisionItem',
node: (0, _decisionItem.decisionItemSpecWithFixedToDOM)()
}, {
name: 'taskList',
node: _adfSchema.taskList
}, {
name: 'taskItem',
node: (0, _taskItemNodeSpec.taskItemNodeSpec)()
}].concat((0, _toConsumableArray2.default)((0, _expValEquals.expValEquals)('platform_editor_blocktaskitem_node_tenantid', 'isEnabled', true) && allowBlockTaskItem ? [{
name: 'blockTaskItem',
node: (0, _taskItemNodeSpec.blockTaskItemNodeSpec)()
}] : []));
},
getSharedState: function getSharedState(editorState) {
if (!editorState) {
return undefined;
}
var pluginState = _pluginKey.stateKey.getState(editorState);
var indentLevel = (0, _helpers.getCurrentIndentLevel)(editorState.selection) || 0;
var itemIndex = (0, _helpers.getTaskItemIndex)(editorState);
return {
focusedTaskItemLocalId: (pluginState === null || pluginState === void 0 ? void 0 : pluginState.focusedTaskItemLocalId) || null,
isInsideTask: (0, _helpers.isInsideTask)(editorState),
indentDisabled: itemIndex === 0 || indentLevel >= _indentation.MAX_INDENTATION_LEVEL,
outdentDisabled: indentLevel <= 1,
// hasEditPermission is assumed to be true if pluginState.hasEditPermission is undefined
// this allows the default plugin state to initialise as true if the extra configuration is not provided
hasEditPermission: (pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasEditPermission) !== undefined ? pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasEditPermission : true,
requestToEditContent: pluginState === null || pluginState === void 0 ? void 0 : pluginState.requestToEditContent,
hasRequestedEditPermission: pluginState === null || pluginState === void 0 ? void 0 : pluginState.hasRequestedEditPermission,
taskDecisionProvider: pluginState === null || pluginState === void 0 ? void 0 : pluginState.taskDecisionProvider,
openRequestToEditPopupAt: pluginState === null || pluginState === void 0 ? void 0 : pluginState.openRequestToEditPopupAt
};
},
commands: {
toggleTaskList: function toggleTaskList(targetType) {
var _api$analytics;
return (0, _toggleTasklistCommands.toggleTaskList)(api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(targetType);
},
updateEditPermission: function updateEditPermission(hasEditPermission) {
return function (_ref5) {
var tr = _ref5.tr;
return tr.setMeta(_pluginKey.stateKey, {
hasEditPermission: hasEditPermission
});
};
},
updateHasRequestedEditPermission: function updateHasRequestedEditPermission(hasRequestedEditPermission) {
return function (_ref6) {
var tr = _ref6.tr;
return tr.setMeta(_pluginKey.stateKey, {
hasRequestedEditPermission: hasRequestedEditPermission
});
};
}
},
actions: {
insertTaskDecision: (0, _insertCommands.insertTaskDecisionCommand)(api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, getIdentifierProvider),
indentTaskList: (0, _keymaps.getIndentCommand)(api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions),
outdentTaskList: (0, _keymaps.getUnindentCommand)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions),
setProvider: function () {
var _setProvider2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(providerPromise) {
var _api$core$actions$exe;
var provider;
return _regenerator.default.wrap(function _callee$(_context) {
while (1) switch (_context.prev = _context.next) {
case 0:
_context.next = 2;
return providerPromise;
case 2:
provider = _context.sent;
if (!(previousTaskAndDecisionProvider === provider || taskDecisionProvider === providerPromise)) {
_context.next = 5;
break;
}
return _context.abrupt("return", false);
case 5:
previousTaskAndDecisionProvider = provider;
return _context.abrupt("return", (_api$core$actions$exe = api === null || api === void 0 ? void 0 : api.core.actions.execute(function (_ref7) {
var tr = _ref7.tr;
return (0, _insertCommands.setProvider)(provider)(tr);
})) !== null && _api$core$actions$exe !== void 0 ? _api$core$actions$exe : false);
case 7:
case "end":
return _context.stop();
}
}, _callee);
}));
function setProvider(_x) {
return _setProvider2.apply(this, arguments);
}
return setProvider;
}()
},
pmPlugins: function pmPlugins() {
return [{
name: 'tasksAndDecisions',
plugin: function plugin(_ref8) {
var portalProviderAPI = _ref8.portalProviderAPI,
eventDispatcher = _ref8.eventDispatcher,
dispatch = _ref8.dispatch,
getIntl = _ref8.getIntl;
return (0, _main.createPlugin)(portalProviderAPI, eventDispatcher, dispatch, api, getIntl, useLongPressSelection, hasEditPermission, hasRequestedEditPermission, requestToEditContent, taskPlaceholder);
}
}, {
name: 'tasksAndDecisionsInputRule',
plugin: function plugin(_ref9) {
var _api$analytics5;
var schema = _ref9.schema,
featureFlags = _ref9.featureFlags;
return (0, _inputRules.default)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions, getIdentifierProvider)(schema, featureFlags);
}
}, {
name: 'tasksAndDecisionsKeyMap',
plugin: function plugin(_ref0) {
var schema = _ref0.schema;
return (0, _keymaps.default)(schema, api, allowNestedTasks, consumeTabs);
}
} // Needs to be after "save-on-enter"
];
},
secondaryToolbarComponent: function secondaryToolbarComponent(_ref1) {
var editorView = _ref1.editorView,
disabled = _ref1.disabled;
return /*#__PURE__*/React.createElement("div", {
className: (0, _runtime.ax)(["_1e0c1txw"])
}, /*#__PURE__*/React.createElement(_ToolbarDecision.default, {
editorView: editorView,
isDisabled: disabled,
isReducedSpacing: true,
editorAPI: api
}), /*#__PURE__*/React.createElement(_ToolbarTask.default, {
editorView: editorView,
isDisabled: disabled,
isReducedSpacing: true,
editorAPI: api
}));
},
contentComponent: function contentComponent(_ref10) {
var editorView = _ref10.editorView,
dispatchAnalyticsEvent = _ref10.dispatchAnalyticsEvent,
popupsMountPoint = _ref10.popupsMountPoint,
popupsBoundariesElement = _ref10.popupsBoundariesElement,
popupsScrollableElement = _ref10.popupsScrollableElement;
if (!editorView) {
return null;
}
return /*#__PURE__*/React.createElement(ContentComponent, {
dependencyApi: api,
editorView: editorView,
dispatchAnalyticsEvent: dispatchAnalyticsEvent,
popupsMountPoint: popupsMountPoint,
popupsBoundariesElement: popupsBoundariesElement,
popupsScrollableElement: popupsScrollableElement
});
},
pluginsOptions: {
quickInsert: function quickInsert(_ref11) {
var formatMessage = _ref11.formatMessage;
return [{
id: 'action',
title: formatMessage(_messages.toolbarInsertBlockMessages.action),
description: quickInsertActionDescription !== null && quickInsertActionDescription !== void 0 ? quickInsertActionDescription : formatMessage(_messages.toolbarInsertBlockMessages.actionDescription),
priority: 100,
keywords: ['checkbox', 'task', 'todo'],
keyshortcut: '[]',
icon: function icon() {
return /*#__PURE__*/React.createElement(_quickInsert.IconAction, null);
},
action: function action(insert, state, source) {
var _api$analytics6;
return (0, _insertCommands.insertTaskDecisionAction)(api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : _api$analytics6.actions, getIdentifierProvider)(state, 'taskList', source !== null && source !== void 0 ? source : _analytics.INPUT_METHOD.QUICK_INSERT, addItem(insert, 'taskList', state.schema));
}
}, {
id: 'decision',
title: formatMessage(_messages.toolbarInsertBlockMessages.decision),
description: formatMessage(_messages.toolbarInsertBlockMessages.decisionDescription),
priority: 900,
keyshortcut: '<>',
icon: function icon() {
return /*#__PURE__*/React.createElement(_quickInsert.IconDecision, null);
},
action: function action(insert, state, source) {
var _api$analytics7;
return (0, _insertCommands.insertTaskDecisionAction)(api === null || api === void 0 || (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions, getIdentifierProvider)(state, 'decisionList', source !== null && source !== void 0 ? source : _analytics.INPUT_METHOD.QUICK_INSERT, addItem(insert, 'decisionList', state.schema));
}
}];
}
}
};
};