@bigbinary/neeto-editor 1.47.32 → 1.47.33

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-D44ZMvgb.cjs.js');
8
+ var Menu$3 = require('./chunk-BCoa9xCZ.cjs.js');
9
9
  var classnames = require('classnames');
10
10
  var constants = require('./chunk-BlNpxkqF.cjs.js');
11
11
  var neetoCist = require('@bigbinary/neeto-cist');
@@ -3038,268 +3038,6 @@ const Highlight = Menu$3.Mark.create({
3038
3038
  },
3039
3039
  });
3040
3040
 
3041
- const findListItemPos = (typeOrName, state) => {
3042
- const { $from } = state.selection;
3043
- const nodeType = Menu$3.getNodeType(typeOrName, state.schema);
3044
- let currentNode = null;
3045
- let currentDepth = $from.depth;
3046
- let currentPos = $from.pos;
3047
- let targetDepth = null;
3048
- while (currentDepth > 0 && targetDepth === null) {
3049
- currentNode = $from.node(currentDepth);
3050
- if (currentNode.type === nodeType) {
3051
- targetDepth = currentDepth;
3052
- }
3053
- else {
3054
- currentDepth -= 1;
3055
- currentPos -= 1;
3056
- }
3057
- }
3058
- if (targetDepth === null) {
3059
- return null;
3060
- }
3061
- return { $pos: state.doc.resolve(currentPos), depth: targetDepth };
3062
- };
3063
-
3064
- const getNextListDepth = (typeOrName, state) => {
3065
- const listItemPos = findListItemPos(typeOrName, state);
3066
- if (!listItemPos) {
3067
- return false;
3068
- }
3069
- const [, depth] = Menu$3.getNodeAtPosition(state, typeOrName, listItemPos.$pos.pos + 4);
3070
- return depth;
3071
- };
3072
-
3073
- const hasListBefore = (editorState, name, parentListTypes) => {
3074
- const { $anchor } = editorState.selection;
3075
- const previousNodePos = Math.max(0, $anchor.pos - 2);
3076
- const previousNode = editorState.doc.resolve(previousNodePos).node();
3077
- if (!previousNode || !parentListTypes.includes(previousNode.type.name)) {
3078
- return false;
3079
- }
3080
- return true;
3081
- };
3082
-
3083
- const hasListItemBefore = (typeOrName, state) => {
3084
- var _a;
3085
- const { $anchor } = state.selection;
3086
- const $targetPos = state.doc.resolve($anchor.pos - 2);
3087
- if ($targetPos.index() === 0) {
3088
- return false;
3089
- }
3090
- if (((_a = $targetPos.nodeBefore) === null || _a === void 0 ? void 0 : _a.type.name) !== typeOrName) {
3091
- return false;
3092
- }
3093
- return true;
3094
- };
3095
-
3096
- const listItemHasSubList = (typeOrName, state, node) => {
3097
- if (!node) {
3098
- return false;
3099
- }
3100
- const nodeType = Menu$3.getNodeType(typeOrName, state.schema);
3101
- let hasSubList = false;
3102
- node.descendants(child => {
3103
- if (child.type === nodeType) {
3104
- hasSubList = true;
3105
- }
3106
- });
3107
- return hasSubList;
3108
- };
3109
-
3110
- const handleBackspace = (editor, name, parentListTypes) => {
3111
- // this is required to still handle the undo handling
3112
- if (editor.commands.undoInputRule()) {
3113
- return true;
3114
- }
3115
- // if the selection is not collapsed
3116
- // we can rely on the default backspace behavior
3117
- if (editor.state.selection.from !== editor.state.selection.to) {
3118
- return false;
3119
- }
3120
- // if the current item is NOT inside a list item &
3121
- // the previous item is a list (orderedList or bulletList)
3122
- // move the cursor into the list and delete the current item
3123
- if (!Menu$3.isNodeActive(editor.state, name) && hasListBefore(editor.state, name, parentListTypes)) {
3124
- const { $anchor } = editor.state.selection;
3125
- const $listPos = editor.state.doc.resolve($anchor.before() - 1);
3126
- const listDescendants = [];
3127
- $listPos.node().descendants((node, pos) => {
3128
- if (node.type.name === name) {
3129
- listDescendants.push({ node, pos });
3130
- }
3131
- });
3132
- const lastItem = listDescendants.at(-1);
3133
- if (!lastItem) {
3134
- return false;
3135
- }
3136
- const $lastItemPos = editor.state.doc.resolve($listPos.start() + lastItem.pos + 1);
3137
- return editor.chain().cut({ from: $anchor.start() - 1, to: $anchor.end() + 1 }, $lastItemPos.end()).joinForward().run();
3138
- }
3139
- // if the cursor is not inside the current node type
3140
- // do nothing and proceed
3141
- if (!Menu$3.isNodeActive(editor.state, name)) {
3142
- return false;
3143
- }
3144
- // if the cursor is not at the start of a node
3145
- // do nothing and proceed
3146
- if (!Menu$3.isAtStartOfNode(editor.state)) {
3147
- return false;
3148
- }
3149
- const listItemPos = findListItemPos(name, editor.state);
3150
- if (!listItemPos) {
3151
- return false;
3152
- }
3153
- const $prev = editor.state.doc.resolve(listItemPos.$pos.pos - 2);
3154
- const prevNode = $prev.node(listItemPos.depth);
3155
- const previousListItemHasSubList = listItemHasSubList(name, editor.state, prevNode);
3156
- // if the previous item is a list item and doesn't have a sublist, join the list items
3157
- if (hasListItemBefore(name, editor.state) && !previousListItemHasSubList) {
3158
- return editor.commands.joinItemBackward();
3159
- }
3160
- // otherwise in the end, a backspace should
3161
- // always just lift the list item if
3162
- // joining / merging is not possible
3163
- return editor.chain().liftListItem(name).run();
3164
- };
3165
-
3166
- const nextListIsDeeper = (typeOrName, state) => {
3167
- const listDepth = getNextListDepth(typeOrName, state);
3168
- const listItemPos = findListItemPos(typeOrName, state);
3169
- if (!listItemPos || !listDepth) {
3170
- return false;
3171
- }
3172
- if (listDepth > listItemPos.depth) {
3173
- return true;
3174
- }
3175
- return false;
3176
- };
3177
-
3178
- const nextListIsHigher = (typeOrName, state) => {
3179
- const listDepth = getNextListDepth(typeOrName, state);
3180
- const listItemPos = findListItemPos(typeOrName, state);
3181
- if (!listItemPos || !listDepth) {
3182
- return false;
3183
- }
3184
- if (listDepth < listItemPos.depth) {
3185
- return true;
3186
- }
3187
- return false;
3188
- };
3189
-
3190
- const handleDelete = (editor, name) => {
3191
- // if the cursor is not inside the current node type
3192
- // do nothing and proceed
3193
- if (!Menu$3.isNodeActive(editor.state, name)) {
3194
- return false;
3195
- }
3196
- // if the cursor is not at the end of a node
3197
- // do nothing and proceed
3198
- if (!Menu$3.isAtEndOfNode(editor.state, name)) {
3199
- return false;
3200
- }
3201
- // if the selection is not collapsed, or not within a single node
3202
- // do nothing and proceed
3203
- const { selection } = editor.state;
3204
- const { $from, $to } = selection;
3205
- if (!selection.empty && $from.sameParent($to)) {
3206
- return false;
3207
- }
3208
- // check if the next node is a list with a deeper depth
3209
- if (nextListIsDeeper(name, editor.state)) {
3210
- return editor
3211
- .chain()
3212
- .focus(editor.state.selection.from + 4)
3213
- .lift(name)
3214
- .joinBackward()
3215
- .run();
3216
- }
3217
- if (nextListIsHigher(name, editor.state)) {
3218
- return editor.chain()
3219
- .joinForward()
3220
- .joinBackward()
3221
- .run();
3222
- }
3223
- return editor.commands.joinItemForward();
3224
- };
3225
-
3226
- /**
3227
- * This extension registers custom keymaps to change the behaviour of the backspace and delete keys.
3228
- * By default Prosemirror keyhandling will always lift or sink items so paragraphs are joined into
3229
- * the adjacent or previous list item. This extension will prevent this behaviour and instead will
3230
- * try to join paragraphs from two list items into a single list item.
3231
- * @see https://www.tiptap.dev/api/extensions/list-keymap
3232
- */
3233
- const ListKeymap = Menu$3.Extension.create({
3234
- name: 'listKeymap',
3235
- addOptions() {
3236
- return {
3237
- listTypes: [
3238
- {
3239
- itemName: 'listItem',
3240
- wrapperNames: ['bulletList', 'orderedList'],
3241
- },
3242
- {
3243
- itemName: 'taskItem',
3244
- wrapperNames: ['taskList'],
3245
- },
3246
- ],
3247
- };
3248
- },
3249
- addKeyboardShortcuts() {
3250
- return {
3251
- Delete: ({ editor }) => {
3252
- let handled = false;
3253
- this.options.listTypes.forEach(({ itemName }) => {
3254
- if (editor.state.schema.nodes[itemName] === undefined) {
3255
- return;
3256
- }
3257
- if (handleDelete(editor, itemName)) {
3258
- handled = true;
3259
- }
3260
- });
3261
- return handled;
3262
- },
3263
- 'Mod-Delete': ({ editor }) => {
3264
- let handled = false;
3265
- this.options.listTypes.forEach(({ itemName }) => {
3266
- if (editor.state.schema.nodes[itemName] === undefined) {
3267
- return;
3268
- }
3269
- if (handleDelete(editor, itemName)) {
3270
- handled = true;
3271
- }
3272
- });
3273
- return handled;
3274
- },
3275
- Backspace: ({ editor }) => {
3276
- let handled = false;
3277
- this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
3278
- if (editor.state.schema.nodes[itemName] === undefined) {
3279
- return;
3280
- }
3281
- if (handleBackspace(editor, itemName, wrapperNames)) {
3282
- handled = true;
3283
- }
3284
- });
3285
- return handled;
3286
- },
3287
- 'Mod-Backspace': ({ editor }) => {
3288
- let handled = false;
3289
- this.options.listTypes.forEach(({ itemName, wrapperNames }) => {
3290
- if (editor.state.schema.nodes[itemName] === undefined) {
3291
- return;
3292
- }
3293
- if (handleBackspace(editor, itemName, wrapperNames)) {
3294
- handled = true;
3295
- }
3296
- });
3297
- return handled;
3298
- },
3299
- };
3300
- },
3301
- });
3302
-
3303
3041
  /**
3304
3042
  * This extension allows you to create table cells.
3305
3043
  * @see https://www.tiptap.dev/api/nodes/table-cell
@@ -19990,7 +19728,7 @@ var useCustomExtensions = function useCustomExtensions(_ref) {
19990
19728
  onSubmit: onSubmit,
19991
19729
  shortcuts: keyboardShortcuts,
19992
19730
  isBlockQuoteActive: options.includes(constants.EDITOR_OPTIONS.BLOCKQUOTE)
19993
- }), ListKeymap, EmojiSuggestion$1, EmojiPicker];
19731
+ }), EmojiSuggestion$1, EmojiPicker];
19994
19732
  if (options.includes(constants.EDITOR_OPTIONS.VIDEO_UPLOAD)) {
19995
19733
  customExtensions.push(UnifiedVideoExtension);
19996
19734
  }