retejs / context-menu-plugin

https://retejs.org
MIT License
11 stars 43 forks source link

Поиск компонентов не работает с символами + или * #43

Closed v1talii-dev closed 1 year ago

v1talii-dev commented 3 years ago

При попытке ввода символов + или * в поле поиска компонентов происходит ошибка:

SyntaxError: Invalid regular expression: /*/: Nothing to repeat
    at new RegExp (<anonymous>)
    at VueComponent.filtered

Можно протестировать на официальном примере.

v1talii-dev commented 3 years ago

@Ni55aN можете посмотреть проблему, пожалуйста?

v1talii-dev commented 3 years ago

Удалось решить следующим способом:

import ContextMenuPlugin, { Menu } from 'rete-context-menu-plugin';
// ...
editor.use(ContextMenuPlugin, {
 vueComponent: {
   extends: { ...Menu },
   computed: {
     ...Menu.computed,
     filtered: function() {
       try {
         if (!this.filter) {
           return this.items;
         }
         const search = this.filter.toLowerCase();
         return this.extractLeafs(this.items).filter(({ title }) => {
           const el = title.toLowerCase();
           return this.searchKeep(el) || el.includes(search);
         });
       } catch (e) {
         console.error(e);
       }
     }
   },
 }
});
Hatead1 commented 3 years ago
  const regex = new RegExp(this.filter.replace(/[*+]/, '\\$&'), 'gi');
rete-js[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 10 days.