owl-tiptap 1.2.1 → 1.2.2

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.
@@ -35,6 +35,7 @@ export class SuggestionList extends Component {
35
35
  * 获取处理后的项目列表
36
36
  */
37
37
  get processedItems() {
38
+ console.log(this.props.items);
38
39
  // 检查是否有分组项结构
39
40
  const hasGroupItems = this.props.items.some((item) => this.isGroupItem(item));
40
41
  // 如果有分组项,则直接返回
@@ -99,7 +100,7 @@ export class SuggestionList extends Component {
99
100
  if (!selectableItems.length) {
100
101
  return;
101
102
  }
102
- const selectedIndex = selectableItems.indexOf(selectedItem);
103
+ const selectedIndex = selectableItems.findIndex((item) => item.value === selectedItem?.value);
103
104
  const newIndex = (selectedIndex - 1 + selectableItems.length) % selectableItems.length;
104
105
  this.state.selectedItem = selectableItems[newIndex];
105
106
  }
@@ -120,7 +121,7 @@ export class SuggestionList extends Component {
120
121
  if (!selectableItems.length) {
121
122
  return;
122
123
  }
123
- const selectedIndex = selectableItems.indexOf(selectedItem);
124
+ const selectedIndex = selectableItems.findIndex((item) => item.value === selectedItem?.value);
124
125
  const newIndex = (selectedIndex + 1) % selectableItems.length;
125
126
  this.state.selectedItem = selectableItems[newIndex];
126
127
  }
@@ -2,8 +2,8 @@ import { Component } from '@odoo/owl';
2
2
  import { Editor } from '@tiptap/core';
3
3
  import { SuggestionList } from './SuggestionList';
4
4
  import type { SuggestionItem, ListItem } from './SuggestionList';
5
- export type { SuggestionItem, ListItem, GroupItem } from './SuggestionList';
6
5
  import './TagInput.css';
6
+ export type { SuggestionItem, ListItem, GroupItem } from './SuggestionList';
7
7
  export interface TagAttributes {
8
8
  value: string;
9
9
  label?: string;
@@ -47,6 +47,7 @@ interface TagInputProps {
47
47
  readonly?: boolean;
48
48
  onTagClick?: (index: number, attrs: TagAttributes) => void;
49
49
  char?: string;
50
+ tagOnly?: boolean;
50
51
  }
51
52
  export declare class TagInput extends Component<TagInputProps> {
52
53
  static components: {
@@ -97,12 +98,17 @@ export declare class TagInput extends Component<TagInputProps> {
97
98
  type: StringConstructor;
98
99
  optional: boolean;
99
100
  };
101
+ tagOnly: {
102
+ type: BooleanConstructor;
103
+ optional: boolean;
104
+ };
100
105
  };
101
106
  static template: string;
102
107
  static defaultProps: {
103
108
  items: () => any[];
104
109
  readonly: boolean;
105
110
  char: string;
111
+ tagOnly: boolean;
106
112
  };
107
113
  editorRef: {
108
114
  el: HTMLElement;
@@ -8,7 +8,7 @@ import History from '@tiptap/extension-history';
8
8
  import Placeholder from '@tiptap/extension-placeholder';
9
9
  import { SuggestionList } from './SuggestionList';
10
10
  import { TagNode } from './TagNode';
11
- import { SuggestionPlugin } from './suggestion';
11
+ import { SuggestionPlugin, exitSuggestionPlugin } from './suggestion';
12
12
  import './TagInput.css';
13
13
  export class TagInput extends Component {
14
14
  constructor() {
@@ -188,9 +188,14 @@ export class TagInput extends Component {
188
188
  }),
189
189
  ],
190
190
  content: null,
191
+ onFocus: ({ editor }) => {
192
+ if (this.props.tagOnly) {
193
+ this.state.suggestion.visible = true;
194
+ }
195
+ },
191
196
  onBlur: ({ editor }) => {
192
- // this.state.suggestion.visible = false;
193
- // exitSuggestionPlugin(editor.view);
197
+ this.state.suggestion.visible = false;
198
+ exitSuggestionPlugin(editor.view);
194
199
  },
195
200
  onUpdate: ({ editor, transaction }) => {
196
201
  if (transaction.docChanged) {
@@ -235,6 +240,7 @@ TagInput.props = {
235
240
  readonly: { type: Boolean, optional: true },
236
241
  onTagClick: { type: Function, optional: true },
237
242
  char: { type: String, optional: true },
243
+ tagOnly: { type: Boolean, optional: true },
238
244
  };
239
245
  TagInput.template = xml `
240
246
  <div t-att-class="className">
@@ -253,4 +259,5 @@ TagInput.defaultProps = {
253
259
  items: () => [],
254
260
  readonly: false,
255
261
  char: '@',
262
+ tagOnly: false,
256
263
  };
@@ -2,6 +2,7 @@ import { Extension } from '@tiptap/core';
2
2
  import { Suggestion } from '@tiptap/suggestion';
3
3
  import { PluginKey } from 'prosemirror-state'; // optional, if you need to create a custom key
4
4
  import { exitSuggestion } from '@tiptap/suggestion';
5
+ import { isChangeOrigin } from '@tiptap/extension-collaboration';
5
6
  export const MySuggestionPluginKey = new PluginKey('my-suggestions'); // or use the default 'suggestion'
6
7
  export const exitSuggestionPlugin = (view) => {
7
8
  exitSuggestion(view, MySuggestionPluginKey);
@@ -20,6 +21,9 @@ export const SuggestionPlugin = Extension.create({
20
21
  pluginKey: MySuggestionPluginKey,
21
22
  editor: this.editor,
22
23
  ...this.options,
24
+ shouldShow: ({ transaction }) => {
25
+ return isChangeOrigin(transaction);
26
+ },
23
27
  }),
24
28
  ];
25
29
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "owl-tiptap",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "description": "tiptap used in odoo owl2",
5
5
  "main": "es/index.js",
6
6
  "scripts": {
@@ -24,6 +24,7 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@tiptap/core": "^3.2.0",
27
+ "@tiptap/extension-collaboration": "^3.15.3",
27
28
  "@tiptap/extension-document": "^3.13.0",
28
29
  "@tiptap/extension-history": "^3.13.0",
29
30
  "@tiptap/extension-mention": "^3.2.0",
@@ -31,7 +32,8 @@
31
32
  "@tiptap/extension-placeholder": "^3.2.0",
32
33
  "@tiptap/extension-text": "^3.13.0",
33
34
  "@tiptap/suggestion": "^3.13.0",
34
- "classnames": "^2.3.2"
35
+ "classnames": "^2.3.2",
36
+ "prosemirror-state": "1.4.4"
35
37
  },
36
38
  "peerDependencies": {
37
39
  "@odoo/owl": "~2.4.1"