UNPKG

@atlaskit/editor-plugin-list

Version:

List plugin for @atlaskit/editor-core

162 lines (159 loc) 7.63 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.listPlugin = void 0; var _react = _interopRequireDefault(require("react")); var _adfSchema = require("@atlaskit/adf-schema"); var _analytics = require("@atlaskit/editor-common/analytics"); var _keymaps = require("@atlaskit/editor-common/keymaps"); var _messages = require("@atlaskit/editor-common/messages"); var _quickInsert = require("@atlaskit/editor-common/quick-insert"); var _platformFeatureFlags = require("@atlaskit/platform-feature-flags"); var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals"); var _experiments = require("@atlaskit/tmp-editor-statsig/experiments"); var _commands = require("./pm-plugins/commands"); var _indentList = require("./pm-plugins/commands/indent-list"); var _outdentList2 = require("./pm-plugins/commands/outdent-list"); var _inputRules = _interopRequireDefault(require("./pm-plugins/input-rules")); var _keymap = _interopRequireDefault(require("./pm-plugins/keymap")); var _main = require("./pm-plugins/main"); var _find = require("./pm-plugins/utils/find"); var _selection = require("./pm-plugins/utils/selection"); var _ui = require("./ui"); // Ignored via go/ees005 // eslint-disable-next-line import/no-named-as-default /* Toolbar buttons to bullet and ordered list can be found in packages/editor/editor-core/src/plugins/toolbar-lists-indentation/ui/Toolbar.tsx */ /** * List plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor` * from `@atlaskit/editor-core`. */ var listPlugin = exports.listPlugin = function listPlugin(_ref) { var _api$featureFlags, _api$analytics; var api = _ref.api; var featureFlags = (api === null || api === void 0 || (_api$featureFlags = api.featureFlags) === null || _api$featureFlags === void 0 ? void 0 : _api$featureFlags.sharedState.currentState()) || {}; var editorAnalyticsAPI = api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions; 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((0, _ui.getListComponents)(api)); } return { name: 'list', actions: { isInsideListItem: _selection.isInsideListItem, findRootParentListNode: _find.findRootParentListNode }, commands: { indentList: (0, _indentList.indentList)(editorAnalyticsAPI), outdentList: function outdentList(inputMethod) { return (0, _outdentList2.outdentList)(editorAnalyticsAPI)(inputMethod); }, toggleOrderedList: (0, _commands.toggleOrderedList)(editorAnalyticsAPI), toggleBulletList: (0, _commands.toggleBulletList)(editorAnalyticsAPI) }, getSharedState: function getSharedState(editorState) { if (!editorState) { return undefined; } return _main.pluginKey.getState(editorState); }, nodes: function nodes() { var getListItemNode = function getListItemNode() { if ((0, _expValEquals.expValEquals)('platform_editor_flexible_list_schema', 'isEnabled', true)) { return _adfSchema.listItemWithFlexibleFirstChildStage0; } else if ((0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid')) { return _adfSchema.listItemWithLocalId; } return _adfSchema.listItem; }; return [{ name: 'bulletList', node: (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ? _adfSchema.bulletListWithLocalId : _adfSchema.bulletList }, { name: 'orderedList', node: (0, _platformFeatureFlags.fg)('platform_editor_adf_with_localid') ? _adfSchema.orderedListWithOrderAndLocalId : _adfSchema.orderedListWithOrder }, { name: 'listItem', node: getListItemNode() }]; }, pmPlugins: function pmPlugins() { return [{ name: 'list', plugin: function plugin(_ref2) { var dispatch = _ref2.dispatch; return (0, _main.createPlugin)(dispatch, featureFlags, api); } }, { name: 'listInputRule', plugin: function plugin(_ref3) { var _api$analytics2; var schema = _ref3.schema; return (0, _inputRules.default)(schema, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions); } }, { name: 'listKeymap', plugin: function plugin() { var _api$analytics3; return (0, _keymap.default)(featureFlags, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions); } }]; }, pluginsOptions: { quickInsert: function quickInsert(_ref4) { var formatMessage = _ref4.formatMessage; return [{ id: 'unorderedList', title: formatMessage(_messages.listMessages.unorderedList), description: formatMessage(_messages.listMessages.unorderedListDescription), keywords: ['ul', 'unordered'], priority: 1100, keyshortcut: (0, _keymaps.tooltip)(_keymaps.toggleBulletList), icon: function icon() { return /*#__PURE__*/_react.default.createElement(_quickInsert.IconList, null); }, action: function action(insert, state) { var tr = insert(state.schema.nodes.bulletList.createChecked({}, state.schema.nodes.listItem.createChecked({}, state.schema.nodes.paragraph.createChecked()))); editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({ action: _analytics.ACTION.INSERTED, actionSubject: _analytics.ACTION_SUBJECT.LIST, actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_BULLET, eventType: _analytics.EVENT_TYPE.TRACK, attributes: { inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT } })(tr); return tr; } }, { id: 'orderedList', title: formatMessage(_messages.listMessages.orderedList), description: formatMessage(_messages.listMessages.orderedListDescription), keywords: ['ol', 'ordered'], priority: 1200, keyshortcut: (0, _keymaps.tooltip)(_keymaps.toggleOrderedList), icon: function icon() { return /*#__PURE__*/_react.default.createElement(_quickInsert.IconListNumber, null); }, action: function action(insert, state) { var tr = insert(state.schema.nodes.orderedList.createChecked({}, state.schema.nodes.listItem.createChecked({}, state.schema.nodes.paragraph.createChecked()))); editorAnalyticsAPI === null || editorAnalyticsAPI === void 0 || editorAnalyticsAPI.attachAnalyticsEvent({ action: _analytics.ACTION.INSERTED, actionSubject: _analytics.ACTION_SUBJECT.LIST, actionSubjectId: _analytics.ACTION_SUBJECT_ID.FORMAT_LIST_NUMBER, eventType: _analytics.EVENT_TYPE.TRACK, attributes: { inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT } })(tr); return tr; } }]; } } }; };