@bigbinary/neeto-editor 1.45.27 → 1.45.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -5,7 +5,7 @@ var _toConsumableArray = require('@babel/runtime/helpers/toConsumableArray');
5
5
  var _slicedToArray = require('@babel/runtime/helpers/slicedToArray');
6
6
  var _objectWithoutProperties = require('@babel/runtime/helpers/objectWithoutProperties');
7
7
  var React = require('react');
8
- var Menu$3 = require('./chunk-DZ7EK7nf.cjs.js');
8
+ var Menu$3 = require('./chunk-C-KwpuWA.cjs.js');
9
9
  var classnames = require('classnames');
10
10
  var constants = require('./chunk-B9Evf49b.cjs.js');
11
11
  var neetoCist = require('@bigbinary/neeto-cist');
@@ -3028,6 +3028,268 @@ const Highlight = Menu$3.Mark.create({
3028
3028
  },
3029
3029
  });
3030
3030
 
3031
+ const findListItemPos = (typeOrName, state) => {
3032
+ const { $from } = state.selection;
3033
+ const nodeType = Menu$3.getNodeType(typeOrName, state.schema);
3034
+ let currentNode = null;
3035
+ let currentDepth = $from.depth;
3036
+ let currentPos = $from.pos;
3037
+ let targetDepth = null;
3038
+ while (currentDepth > 0 && targetDepth === null) {
3039
+ currentNode = $from.node(currentDepth);
3040
+ if (currentNode.type === nodeType) {
3041
+ targetDepth = currentDepth;
3042
+ }
3043
+ else {
3044
+ currentDepth -= 1;
3045
+ currentPos -= 1;
3046
+ }
3047
+ }
3048
+ if (targetDepth === null) {
3049
+ return null;
3050
+ }
3051
+ return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
3052
+ };
3053
+
3054
+ const getNextListDepth = (typeOrName, state) => {
3055
+ const listItemPos = findListItemPos(typeOrName, state);
3056
+ if (!listItemPos) {
3057
+ return false;
3058
+ }
3059
+ const [, depth] = Menu$3.getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
3060
+ return depth;
3061
+ };
3062
+
3063
+ const hasListBefore = (editorState, name, parentListTypes) => {
3064
+ const { $anchor } = editorState.selection;
3065
+ const previousNodePos = Math.max(0, $anchor.pos - 2);
3066
+ const previousNode = editorState.doc.resolve(previousNodePos).node();
3067
+ if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
3068
+ return false;
3069
+ }
3070
+ return true;
3071
+ };
3072
+
3073
+ const hasListItemBefore = (typeOrName, state) => {
3074
+ var _a;
3075
+ const { $anchor } = state.selection;
3076
+ const $targetPos = state.doc.resolve($anchor.pos - 2);
3077
+ if ($targetPos.index() === 0) {
3078
+ return false;
3079
+ }
3080
+ if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
3081
+ return false;
3082
+ }
3083
+ return true;
3084
+ };
3085
+
3086
+ const listItemHasSubList = (typeOrName, state, node) => {
3087
+ if (!node) {
3088
+ return false;
3089
+ }
3090
+ const nodeType = Menu$3.getNodeType(typeOrName, state.schema);
3091
+ let hasSubList = false;
3092
+ node.descendants(child => {
3093
+ if (child.type === nodeType) {
3094
+ hasSubList = true;
3095
+ }
3096
+ });
3097
+ return hasSubList;
3098
+ };
3099
+
3100
+ const handleBackspace = (editor, name, parentListTypes) => {
3101
+ // this is required to still handle the undo handling
3102
+ if (editor.commands.undoInputRule()) {
3103
+ return true;
3104
+ }
3105
+ // if the selection is not collapsed
3106
+ // we can rely on the default backspace behavior
3107
+ if (editor.state.selection.from !== editor.state.selection.to) {
3108
+ return false;
3109
+ }
3110
+ // if the current item is NOT inside a list item &
3111
+ // the previous item is a list (orderedList or bulletList)
3112
+ // move the cursor into the list and delete the current item
3113
+ if (!Menu$3.isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
3114
+ const { $anchor } = editor.state.selection;
3115
+ const $listPos = editor.state.doc.resolve($anchor.before() - 1);
3116
+ const listDescendants = [];
3117
+ $listPos.node().descendants((node, pos) => {
3118
+ if (node.type.name === name) {
3119
+ listDescendants.push({ node, pos });
3120
+ }
3121
+ });
3122
+ const lastItem = listDescendants.at(-1);
3123
+ if (!lastItem) {
3124
+ return false;
3125
+ }
3126
+ const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
3127
+ return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
3128
+ }
3129
+ // if the cursor is not inside the current node type
3130
+ // do nothing and proceed
3131
+ if (!Menu$3.isNodeActive(editor.state, name)) {
3132
+ return false;
3133
+ }
3134
+ // if the cursor is not at the start of a node
3135
+ // do nothing and proceed
3136
+ if (!Menu$3.isAtStartOfNode(editor.state)) {
3137
+ return false;
3138
+ }
3139
+ const listItemPos = findListItemPos(name, editor.state);
3140
+ if (!listItemPos) {
3141
+ return false;
3142
+ }
3143
+ const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
3144
+ const prevNode = $prev.node(listItemPos.depth);
3145
+ const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
3146
+ // if the previous item is a list item and doesn't have a sublist, join the list items
3147
+ if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
3148
+ return editor.commands.joinItemBackward();
3149
+ }
3150
+ // otherwise in the end, a backspace should
3151
+ // always just lift the list item if
3152
+ // joining / merging is not possible
3153
+ return editor.chain().liftListItem(name).run();
3154
+ };
3155
+
3156
+ const nextListIsDeeper = (typeOrName, state) => {
3157
+ const listDepth = getNextListDepth(typeOrName, state);
3158
+ const listItemPos = findListItemPos(typeOrName, state);
3159
+ if (!listItemPos || !listDepth) {
3160
+ return false;
3161
+ }
3162
+ if (listDepth > listItemPos.depth) {
3163
+ return true;
3164
+ }
3165
+ return false;
3166
+ };
3167
+
3168
+ const nextListIsHigher = (typeOrName, state) => {
3169
+ const listDepth = getNextListDepth(typeOrName, state);
3170
+ const listItemPos = findListItemPos(typeOrName, state);
3171
+ if (!listItemPos || !listDepth) {
3172
+ return false;
3173
+ }
3174
+ if (listDepth < listItemPos.depth) {
3175
+ return true;
3176
+ }
3177
+ return false;
3178
+ };
3179
+
3180
+ const handleDelete = (editor, name) => {
3181
+ // if the cursor is not inside the current node type
3182
+ // do nothing and proceed
3183
+ if (!Menu$3.isNodeActive(editor.state, name)) {
3184
+ return false;
3185
+ }
3186
+ // if the cursor is not at the end of a node
3187
+ // do nothing and proceed
3188
+ if (!Menu$3.isAtEndOfNode(editor.state, name)) {
3189
+ return false;
3190
+ }
3191
+ // if the selection is not collapsed, or not within a single node
3192
+ // do nothing and proceed
3193
+ const { selection } = editor.state;
3194
+ const { $from, $to } = selection;
3195
+ if (!selection.empty && $from.sameParent($to)) {
3196
+ return false;
3197
+ }
3198
+ // check if the next node is a list with a deeper depth
3199
+ if (nextListIsDeeper(name, editor.state)) {
3200
+ return editor
3201
+ .chain()
3202
+ .focus(editor.state.selection.from + 4)
3203
+ .lift(name)
3204
+ .joinBackward()
3205
+ .run();
3206
+ }
3207
+ if (nextListIsHigher(name, editor.state)) {
3208
+ return editor.chain()
3209
+ .joinForward()
3210
+ .joinBackward()
3211
+ .run();
3212
+ }
3213
+ return editor.commands.joinItemForward();
3214
+ };
3215
+
3216
+ /**
3217
+ * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.
3218
+ * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into
3219
+ * the adjacent or previous list item. This extension will prevent this behaviour and instead will
3220
+ * try to join paragraphs from two list items into a single list item.
3221
+ * @see https://www.tiptap.dev/api/extensions/list-keymap
3222
+ */
3223
+ const ListKeymap = Menu$3.Extension.create({
3224
+ name: 'listKeymap',
3225
+ addOptions() {
3226
+ return {
3227
+ listTypes: [
3228
+ {
3229
+ itemName: 'listItem',
3230
+ wrapperNames: ['bulletList', 'orderedList'],
3231
+ },
3232
+ {
3233
+ itemName: 'taskItem',
3234
+ wrapperNames: ['taskList'],
3235
+ },
3236
+ ],
3237
+ };
3238
+ },
3239
+ addKeyboardShortcuts() {
3240
+ return {
3241
+ Delete: ({ editor }) => {
3242
+ let handled = false;
3243
+ this.options.listTypes.forEach(({ itemName }) => {
3244
+ if (editor.state.schema.nodes[itemName] === undefined) {
3245
+ return;
3246
+ }
3247
+ if (handleDelete(editor, itemName)) {
3248
+ handled = true;
3249
+ }
3250
+ });
3251
+ return handled;
3252
+ },
3253
+ 'Mod-Delete': ({ editor }) => {
3254
+ let handled = false;
3255
+ this.options.listTypes.forEach(({ itemName }) => {
3256
+ if (editor.state.schema.nodes[itemName] === undefined) {
3257
+ return;
3258
+ }
3259
+ if (handleDelete(editor, itemName)) {
3260
+ handled = true;
3261
+ }
3262
+ });
3263
+ return handled;
3264
+ },
3265
+ Backspace: ({ editor }) => {
3266
+ let handled = false;
3267
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
3268
+ if (editor.state.schema.nodes[itemName] === undefined) {
3269
+ return;
3270
+ }
3271
+ if (handleBackspace(editor, itemName, wrapperNames)) {
3272
+ handled = true;
3273
+ }
3274
+ });
3275
+ return handled;
3276
+ },
3277
+ 'Mod-Backspace': ({ editor }) => {
3278
+ let handled = false;
3279
+ this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
3280
+ if (editor.state.schema.nodes[itemName] === undefined) {
3281
+ return;
3282
+ }
3283
+ if (handleBackspace(editor, itemName, wrapperNames)) {
3284
+ handled = true;
3285
+ }
3286
+ });
3287
+ return handled;
3288
+ },
3289
+ };
3290
+ },
3291
+ });
3292
+
3031
3293
  /**
3032
3294
  * This extension allows you to create table cells.
3033
3295
  * @see https://www.tiptap.dev/api/nodes/table-cell
@@ -5007,7 +5269,7 @@ const underscorePasteRegex = /(?:^|\s)(_(?!\s+_)((?:[^_]+))_(?!\s+_))/g;
5007
5269
  * This extension allows you to create italic text.
5008
5270
  * @see https://www.tiptap.dev/api/marks/italic
5009
5271
  */
5010
- const Italic = Menu$3.Mark.create({
5272
+ const Italic$1 = Menu$3.Mark.create({
5011
5273
  name: 'italic',
5012
5274
  addOptions() {
5013
5275
  return {
@@ -5448,7 +5710,7 @@ const StarterKit = Menu$3.Extension.create({
5448
5710
  extensions.push(HorizontalRule.configure((_m = this.options) === null || _m === void 0 ? void 0 : _m.horizontalRule));
5449
5711
  }
5450
5712
  if (this.options.italic !== false) {
5451
- extensions.push(Italic.configure((_o = this.options) === null || _o === void 0 ? void 0 : _o.italic));
5713
+ extensions.push(Italic$1.configure((_o = this.options) === null || _o === void 0 ? void 0 : _o.italic));
5452
5714
  }
5453
5715
  if (this.options.listItem !== false) {
5454
5716
  extensions.push(ListItem$1.configure((_p = this.options) === null || _p === void 0 ? void 0 : _p.listItem));
@@ -10750,6 +11012,12 @@ var FigCaption = Menu$3.Node.create({
10750
11012
  }
10751
11013
  });
10752
11014
 
11015
+ var Italic = Italic$1.extend({
11016
+ addInputRules: function addInputRules() {
11017
+ return [];
11018
+ }
11019
+ });
11020
+
10753
11021
  function ownKeys$9(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; }
10754
11022
  function _objectSpread$9(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$9(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$9(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
10755
11023
  var KeyboardShortcuts = function KeyboardShortcuts(_ref) {
@@ -10771,51 +11039,16 @@ var KeyboardShortcuts = function KeyboardShortcuts(_ref) {
10771
11039
  return true;
10772
11040
  }
10773
11041
  return false;
10774
- },
10775
- // To fix the issue with backspace on the empty list item moving the focus to the block on top.
10776
- // https://github.com/ueberdosis/tiptap/issues/2829#issuecomment-1511064298
10777
- Backspace: function Backspace() {
10778
- return _this.editor.commands.command(function (_ref2) {
10779
- var tr = _ref2.tr;
10780
- var selection = tr.selection,
10781
- doc = tr.doc;
10782
- var $cursor = selection.$cursor;
10783
- var depth = $cursor === null || $cursor === void 0 ? void 0 : $cursor.depth;
10784
- if ($cursor && depth >= 3 &&
10785
- // At least the structure is doc -> orderedList/bulletList -> listItem -> paragraph
10786
- $cursor.parent.type.name === "paragraph" &&
10787
- // The cursor is inside a paragraph.
10788
- $cursor.parentOffset === 0 &&
10789
- // The cursor is at the beginning of the paragraph.
10790
- $cursor.node(depth - 1).type.name === "listItem" &&
10791
- // The paragraph is inside a listItem.
10792
- $cursor.index(depth - 1) === 0 &&
10793
- // The paragraph is at the beginning of the listItem.
10794
- $cursor.index(depth - 2) === 0 // The listItem is at the beginning of the list.
10795
- ) {
10796
- var listItemNode = $cursor.node(depth - 1);
10797
- var listItemPos = $cursor.before(depth - 1);
10798
- var $contentBegin = doc.resolve(listItemPos + 1);
10799
- var $contentEnd = doc.resolve(listItemPos + listItemNode.nodeSize - 1);
10800
- var range = $contentBegin.blockRange($contentEnd);
10801
- var target = Menu$3.liftTarget(range);
10802
- if (target !== null) {
10803
- tr.lift(range, target);
10804
- return true;
10805
- }
10806
- }
10807
- return false;
10808
- });
10809
11042
  }
10810
11043
  }, shortcuts);
10811
11044
  }
10812
11045
  });
10813
11046
  };
10814
11047
  var KeyboardShortcuts$1 = {
10815
- configure: function configure(_ref3) {
10816
- var onSubmit = _ref3.onSubmit,
10817
- shortcuts = _ref3.shortcuts,
10818
- isBlockQuoteActive = _ref3.isBlockQuoteActive;
11048
+ configure: function configure(_ref2) {
11049
+ var onSubmit = _ref2.onSubmit,
11050
+ shortcuts = _ref2.shortcuts,
11051
+ isBlockQuoteActive = _ref2.isBlockQuoteActive;
10819
11052
  return KeyboardShortcuts({
10820
11053
  onSubmit: onSubmit,
10821
11054
  shortcuts: shortcuts,
@@ -19196,15 +19429,16 @@ var useCustomExtensions = function useCustomExtensions(_ref) {
19196
19429
  bulletList: false,
19197
19430
  blockquote: options.includes(constants.EDITOR_OPTIONS.BLOCKQUOTE),
19198
19431
  orderedList: options.includes(constants.EDITOR_OPTIONS.LIST_ORDERED),
19432
+ italic: false,
19199
19433
  history: !collaborationProvider,
19200
19434
  heading: {
19201
19435
  levels: utils.buildLevelsFromOptions(options)
19202
19436
  }
19203
- }), TextStyle$2, Underline, KeyboardShortcuts$1.configure({
19437
+ }), TextStyle$2, Underline, Italic, KeyboardShortcuts$1.configure({
19204
19438
  onSubmit: onSubmit,
19205
19439
  shortcuts: keyboardShortcuts,
19206
19440
  isBlockQuoteActive: options.includes(constants.EDITOR_OPTIONS.BLOCKQUOTE)
19207
- })];
19441
+ }), ListKeymap];
19208
19442
  if (isVideoEmbedActive) {
19209
19443
  customExtensions.push(Embeds);
19210
19444
  }