@bigbinary/neeto-editor 1.45.27 → 1.45.28
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.
- package/dist/Editor.js +268 -41
- package/dist/Editor.js.map +1 -1
- package/dist/FormikEditor.js +1 -1
- package/dist/Menu.js +1 -1
- package/dist/{chunk-B_ypvaUL.js → chunk-C0xZGEez.js} +53 -2
- package/dist/{chunk-B_ypvaUL.js.map → chunk-C0xZGEez.js.map} +1 -1
- package/dist/cjs/Editor.cjs.js +268 -41
- package/dist/cjs/Editor.cjs.js.map +1 -1
- package/dist/cjs/FormikEditor.cjs.js +1 -1
- package/dist/cjs/Menu.cjs.js +1 -1
- package/dist/cjs/{chunk-DZ7EK7nf.cjs.js → chunk-C-KwpuWA.cjs.js} +57 -2
- package/dist/cjs/{chunk-DZ7EK7nf.cjs.js.map → chunk-C-KwpuWA.cjs.js.map} +1 -1
- package/dist/cjs/index.cjs.js +1 -1
- package/dist/editor-stats.html +19 -1
- package/dist/index.js +1 -1
- package/package.json +2 -1
package/dist/cjs/Editor.cjs.js
CHANGED
|
@@ -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-
|
|
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
|
|
@@ -10771,51 +11033,16 @@ var KeyboardShortcuts = function KeyboardShortcuts(_ref) {
|
|
|
10771
11033
|
return true;
|
|
10772
11034
|
}
|
|
10773
11035
|
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
11036
|
}
|
|
10810
11037
|
}, shortcuts);
|
|
10811
11038
|
}
|
|
10812
11039
|
});
|
|
10813
11040
|
};
|
|
10814
11041
|
var KeyboardShortcuts$1 = {
|
|
10815
|
-
configure: function configure(
|
|
10816
|
-
var onSubmit =
|
|
10817
|
-
shortcuts =
|
|
10818
|
-
isBlockQuoteActive =
|
|
11042
|
+
configure: function configure(_ref2) {
|
|
11043
|
+
var onSubmit = _ref2.onSubmit,
|
|
11044
|
+
shortcuts = _ref2.shortcuts,
|
|
11045
|
+
isBlockQuoteActive = _ref2.isBlockQuoteActive;
|
|
10819
11046
|
return KeyboardShortcuts({
|
|
10820
11047
|
onSubmit: onSubmit,
|
|
10821
11048
|
shortcuts: shortcuts,
|
|
@@ -19204,7 +19431,7 @@ var useCustomExtensions = function useCustomExtensions(_ref) {
|
|
|
19204
19431
|
onSubmit: onSubmit,
|
|
19205
19432
|
shortcuts: keyboardShortcuts,
|
|
19206
19433
|
isBlockQuoteActive: options.includes(constants.EDITOR_OPTIONS.BLOCKQUOTE)
|
|
19207
|
-
})];
|
|
19434
|
+
}), ListKeymap];
|
|
19208
19435
|
if (isVideoEmbedActive) {
|
|
19209
19436
|
customExtensions.push(Embeds);
|
|
19210
19437
|
}
|