@bigbinary/neeto-editor 1.47.48 → 1.47.50

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 CHANGED
@@ -10,12 +10,12 @@ import { D as DIRECT_UPLOAD_ENDPOINT, E as EDITOR_OPTIONS, C as COMBINED_REGEX,
10
10
  import { isNotPresent, findBy, isNotEmpty, isPresent, noop as noop$1, slugify } from '@bigbinary/neeto-cist';
11
11
  import { useOnClickOutside, useFuncDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
12
12
  import Label from '@bigbinary/neetoui/Label';
13
- import { is, intersection, difference, union, isEmpty as isEmpty$1, isNil, mergeRight, assoc, equals } from 'ramda';
13
+ import { is, intersection, difference, union, isEmpty as isEmpty$1, isNil, mergeRight, prop, pluck, assoc, equals } from 'ramda';
14
14
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
15
15
  import { n } from './chunk-DmrvuTKK.js';
16
16
  import { P as Plugin, o as PluginKey, b as Slice, F as Fragment$1, T as TextSelection, S as Selection, d as dropPoint, N as NodeSelection, q as Mapping$1, M as Mark$1, e as MarkType, R as ReplaceError, s as SelectionRange, u as buildLevelsFromOptions, v as validateAndFormatUrl, w as getEditorStyles, x as clipboardTextParser, y as transformPastedHTML, z as setInitialPosition } from './chunk-TvTt0Gg2.js';
17
17
  import ReactDOM from 'react-dom/server';
18
- import { l as lowlight, M as MARGIN_HEIGHT, r as removeEmptyTags } from './chunk-BCoBS5ED.js';
18
+ import { l as lowlight, M as MARGIN_HEIGHT, F as FUZZY_SEARCH_DEFAULT_LIMIT, D as DEFAULT_SEARCH_KEYS, r as removeEmptyTags } from './chunk-CeRlskgG.js';
19
19
  import { L as LINK_VALIDATION_SCHEMA, D as DEFAULT_EDITOR_OPTIONS } from './chunk-BZmNiqsu.js';
20
20
  import * as Y from 'yjs';
21
21
  import { UndoManager, Item as Item$1, ContentType, Text as Text$2, XmlElement } from 'yjs';
@@ -14086,6 +14086,91 @@ var SelectionDecoration = Document.extend({
14086
14086
  }
14087
14087
  });
14088
14088
 
14089
+ var calculateScore = function calculateScore(input, target) {
14090
+ var inputLower = input.toLowerCase();
14091
+ var targetLower = target.toLowerCase();
14092
+ var substringIndex = targetLower.indexOf(inputLower);
14093
+ if (substringIndex !== -1) {
14094
+ return 1.0 - substringIndex / targetLower.length * 0.1;
14095
+ }
14096
+ var inputIndex = 0;
14097
+ var targetIndex = 0;
14098
+ var firstMatchIndex = -1;
14099
+ var consecutiveMatches = 0;
14100
+ var maxConsecutive = 0;
14101
+ while (inputIndex < inputLower.length && targetIndex < targetLower.length) {
14102
+ if (inputLower[inputIndex] === targetLower[targetIndex]) {
14103
+ if (firstMatchIndex === -1) {
14104
+ firstMatchIndex = targetIndex;
14105
+ }
14106
+ consecutiveMatches++;
14107
+ inputIndex++;
14108
+ } else {
14109
+ maxConsecutive = Math.max(maxConsecutive, consecutiveMatches);
14110
+ consecutiveMatches = 0;
14111
+ }
14112
+ targetIndex++;
14113
+ }
14114
+ maxConsecutive = Math.max(maxConsecutive, consecutiveMatches);
14115
+ if (inputIndex < inputLower.length) {
14116
+ return 0;
14117
+ }
14118
+ var positionScore = 1.0 - firstMatchIndex / targetLower.length;
14119
+ var consecutiveBonus = maxConsecutive / inputLower.length;
14120
+ var lengthRatio = inputLower.length / targetLower.length;
14121
+ var score = positionScore * 0.6 + consecutiveBonus * 0.2 + lengthRatio * 0.2;
14122
+ return Math.min(score, 0.89);
14123
+ };
14124
+ var fuzzySearch = function fuzzySearch(items, query) {
14125
+ var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {
14126
+ limit: FUZZY_SEARCH_DEFAULT_LIMIT
14127
+ };
14128
+ var _options$limit = options.limit,
14129
+ limit = _options$limit === void 0 ? FUZZY_SEARCH_DEFAULT_LIMIT : _options$limit,
14130
+ _options$keys = options.keys,
14131
+ keys = _options$keys === void 0 ? DEFAULT_SEARCH_KEYS : _options$keys;
14132
+ if (!query || typeof query !== "string" || !items || isEmpty$1(items)) {
14133
+ return items ? items.slice(0, limit) : [];
14134
+ }
14135
+ var trimmedQuery = query.trim();
14136
+ if (!trimmedQuery) {
14137
+ return items ? items.slice(0, limit) : [];
14138
+ }
14139
+ var fieldAccessors = keys.map(function (key) {
14140
+ return {
14141
+ getValue: typeof key === "string" ? prop(key) : prop(key.name),
14142
+ weight: typeof key === "string" ? 1 : key.weight || 1
14143
+ };
14144
+ });
14145
+ var results = items.reduce(function (acc, item) {
14146
+ var bestScore = fieldAccessors.reduce(function (maxScore, accessor) {
14147
+ var fieldValue = accessor.getValue(item);
14148
+ if (isNil(fieldValue)) return maxScore;
14149
+ var fieldString = String(fieldValue);
14150
+ var score = calculateScore(trimmedQuery, fieldString);
14151
+ if (score <= 0) return maxScore;
14152
+ var weightedScore = score * accessor.weight;
14153
+ return weightedScore > maxScore ? weightedScore : maxScore;
14154
+ }, 0);
14155
+ if (bestScore > 0) {
14156
+ acc.push({
14157
+ item: item,
14158
+ score: bestScore
14159
+ });
14160
+ }
14161
+ return acc;
14162
+ }, []);
14163
+ results.sort(function (a, b) {
14164
+ if (Math.abs(a.score - b.score) < 0.001) {
14165
+ var aTitle = a.item.title || a.item.name || "";
14166
+ var bTitle = b.item.title || b.item.name || "";
14167
+ return aTitle.localeCompare(bTitle);
14168
+ }
14169
+ return b.score - a.score;
14170
+ });
14171
+ return pluck("item", results.slice(0, limit));
14172
+ };
14173
+
14089
14174
  function ownKeys$a(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; }
14090
14175
  function _objectSpread$a(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys$a(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys$a(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
14091
14176
  function _callSuper$1(t, o, e) { return o = _getPrototypeOf(o), _possibleConstructorReturn(t, _isNativeReflectConstruct$1() ? Reflect.construct(o, e || [], _getPrototypeOf(t).constructor) : o.apply(t, e)); }
@@ -14717,10 +14802,10 @@ var SlashCommands = {
14717
14802
  },
14718
14803
  items: function items(_ref3) {
14719
14804
  var query = _ref3.query;
14720
- var filteredItems = commandItems.filter(function (_ref4) {
14721
- var title = _ref4.title;
14722
- return title.toLowerCase().includes(query.toLowerCase());
14723
- });
14805
+ if (!query) {
14806
+ return commandItems.slice(0, 10);
14807
+ }
14808
+ var filteredItems = fuzzySearch(commandItems, query);
14724
14809
  return isEmpty$1(filteredItems) ? [NO_RESULT_MENU_ITEM] : filteredItems;
14725
14810
  },
14726
14811
  render: function render() {
@@ -19852,26 +19937,6 @@ var TodoItemExtension = TaskItem.extend({
19852
19937
  },
19853
19938
  "Shift-Tab": function ShiftTab() {
19854
19939
  return _this2.editor.commands.liftListItem(_this2.name);
19855
- },
19856
- Backspace: function Backspace() {
19857
- var _this2$editor = _this2.editor,
19858
- state = _this2$editor.state,
19859
- commands = _this2$editor.commands;
19860
- var _state$selection = state.selection,
19861
- $from = _state$selection.$from,
19862
- empty = _state$selection.empty;
19863
- if (!empty) return false;
19864
- if ($from.parentOffset === 0) {
19865
- var currentNode = $from.parent;
19866
- if (currentNode.content.size === 0) {
19867
- return commands.lift(_this2.name);
19868
- }
19869
- var todoListNode = $from.node($from.depth - 1);
19870
- if ((todoListNode === null || todoListNode === void 0 ? void 0 : todoListNode.type.name) === "todoList") {
19871
- return commands.liftListItem(_this2.name);
19872
- }
19873
- }
19874
- return false;
19875
19940
  }
19876
19941
  };
19877
19942
  }