@veltra/desktop 1.0.13 → 1.0.15
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/components/action/action-group.js +110 -3
- package/dist/components/action/action-group.js.map +1 -1
- package/dist/components/action/action-group.vue.d.ts +16 -3
- package/dist/components/action/action.js +26 -13
- package/dist/components/action/action.js.map +1 -1
- package/dist/components/action/style.js +2 -1
- package/dist/components/action/style2.css +35 -7
- package/dist/components/batch-edit/batch-edit-form.js +106 -42
- package/dist/components/batch-edit/batch-edit-form.js.map +1 -1
- package/dist/components/batch-edit/batch-edit-list.js +84 -47
- package/dist/components/batch-edit/batch-edit-list.js.map +1 -1
- package/dist/components/batch-edit/batch-edit.js +42 -10
- package/dist/components/batch-edit/batch-edit.js.map +1 -1
- package/dist/components/batch-edit/style.js +2 -4
- package/dist/components/batch-edit/style2.css +202 -30
- package/dist/components/batch-edit/use-edit.js +45 -9
- package/dist/components/batch-edit/use-edit.js.map +1 -1
- package/dist/components/cascade/cascade.js +3 -1
- package/dist/components/cascade/cascade.js.map +1 -1
- package/dist/components/code-editor/code-editor.js +145 -49
- package/dist/components/code-editor/code-editor.js.map +1 -1
- package/dist/components/code-editor/code-editor.vue.d.ts +2 -0
- package/dist/components/code-editor/style2.css +87 -19
- package/dist/components/dialog/dialog.js +6 -2
- package/dist/components/dialog/dialog.js.map +1 -1
- package/dist/components/dialog/style2.css +2 -3
- package/dist/components/expression-editor/components/path-preview.js +27 -0
- package/dist/components/expression-editor/components/path-preview.js.map +1 -0
- package/dist/components/expression-editor/components/variable-picker.js +200 -153
- package/dist/components/expression-editor/components/variable-picker.js.map +1 -1
- package/dist/components/expression-editor/core/chip.js +54 -0
- package/dist/components/expression-editor/core/chip.js.map +1 -0
- package/dist/components/expression-editor/core/editor.js +425 -0
- package/dist/components/expression-editor/core/editor.js.map +1 -0
- package/dist/components/expression-editor/core/mention.js +91 -0
- package/dist/components/expression-editor/core/mention.js.map +1 -0
- package/dist/components/expression-editor/core/model.js +64 -0
- package/dist/components/expression-editor/core/model.js.map +1 -0
- package/dist/components/expression-editor/di.js +4 -10
- package/dist/components/expression-editor/di.js.map +1 -1
- package/dist/components/expression-editor/expression-editor.js +168 -114
- package/dist/components/expression-editor/expression-editor.js.map +1 -1
- package/dist/components/expression-editor/expression-editor.vue.d.ts +2 -1
- package/dist/components/expression-editor/style.js +0 -2
- package/dist/components/expression-editor/style2.css +145 -218
- package/dist/components/index.js +54 -54
- package/dist/components/layout/layout.js +12 -11
- package/dist/components/layout/layout.js.map +1 -1
- package/dist/components/multi-select/multi-select.vue.d.ts +1 -1
- package/dist/components/multi-tree-select/multi-tree-select.vue.d.ts +1 -1
- package/dist/components/number-input/number-input.js +4 -4
- package/dist/components/number-input/number-input.js.map +1 -1
- package/dist/components/pop-confirm/pop-confirm.vue.d.ts +1 -1
- package/dist/components/rich-text-editor/rich-text-editor.js +1 -1
- package/dist/components/rich-text-editor/toolbar.js +2 -2
- package/dist/components/steps/steps.vue.d.ts +1 -1
- package/dist/components/table/use-table.js +16 -0
- package/dist/components/table/use-table.js.map +1 -1
- package/dist/components/tabs/tabs-horizontal.vue.d.ts +3 -3
- package/dist/components/tabs/tabs-vertical.vue.d.ts +2 -2
- package/dist/components/tabs/tabs.vue.d.ts +3 -3
- package/dist/components/tip/tip.js +4 -5
- package/dist/components/tip/tip.js.map +1 -1
- package/dist/components/tip/tip.vue.d.ts +1 -1
- package/dist/components/tree/style2.css +18 -12
- package/dist/components/tree/tree-node.js +7 -4
- package/dist/components/tree/tree-node.js.map +1 -1
- package/dist/components/tree-select/tree-select.vue.d.ts +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +83 -83
- package/dist/style.js +3 -3
- package/dist/types/action.d.ts +38 -4
- package/dist/types/cascade.d.ts +2 -3
- package/dist/types/code-editor.d.ts +9 -2
- package/dist/types/expression-editor.d.ts +9 -1
- package/dist/types/index.d.ts +2 -2
- package/package.json +11 -12
- package/src/components/action/action-group.vue +126 -56
- package/src/components/action/action.vue +35 -12
- package/src/components/action/style.scss +46 -10
- package/src/components/action/style.ts +2 -1
- package/src/components/batch-edit/batch-edit-form.vue +121 -45
- package/src/components/batch-edit/batch-edit-list.vue +56 -39
- package/src/components/batch-edit/batch-edit.vue +57 -6
- package/src/components/batch-edit/style.scss +251 -37
- package/src/components/batch-edit/style.ts +5 -8
- package/src/components/batch-edit/use-edit.ts +58 -11
- package/src/components/cascade/cascade.vue +3 -1
- package/src/components/code-editor/code-editor.vue +198 -63
- package/src/components/code-editor/style.scss +110 -12
- package/src/components/dialog/dialog.vue +6 -2
- package/src/components/dialog/style.scss +4 -4
- package/src/components/expression-editor/__test__/chip.test.ts +86 -0
- package/src/components/expression-editor/__test__/editor.test.ts +47 -0
- package/src/components/expression-editor/__test__/mention.test.ts +122 -0
- package/src/components/expression-editor/__test__/model.test.ts +127 -0
- package/src/components/expression-editor/components/path-preview.vue +32 -0
- package/src/components/expression-editor/components/variable-picker.vue +225 -219
- package/src/components/expression-editor/core/chip.ts +101 -0
- package/src/components/expression-editor/core/editor.ts +514 -0
- package/src/components/expression-editor/core/mention.ts +121 -0
- package/src/components/expression-editor/core/model.ts +109 -0
- package/src/components/expression-editor/di.ts +4 -32
- package/src/components/expression-editor/expression-editor.vue +184 -151
- package/src/components/expression-editor/style.scss +148 -219
- package/src/components/expression-editor/style.ts +0 -2
- package/src/components/layout/layout.vue +17 -19
- package/src/components/number-input/number-input.vue +4 -4
- package/src/components/table/use-table.ts +16 -0
- package/src/components/tip/tip.vue +4 -3
- package/src/components/tree/style.scss +30 -33
- package/src/components/tree/tree-node.vue +4 -2
- package/src/types/action.ts +42 -4
- package/src/types/cascade.ts +4 -3
- package/src/types/code-editor.ts +9 -2
- package/src/types/expression-editor.ts +9 -0
- package/dist/components/action/action-group.vue_vue_type_script_setup_true_lang.js +0 -65
- package/dist/components/action/action-group.vue_vue_type_script_setup_true_lang.js.map +0 -1
- package/dist/components/expression-editor/constants.js +0 -9
- package/dist/components/expression-editor/constants.js.map +0 -1
- package/dist/components/expression-editor/internal/editor-runtime/create-runtime.js +0 -47
- package/dist/components/expression-editor/internal/editor-runtime/create-runtime.js.map +0 -1
- package/dist/components/expression-editor/internal/editor-runtime/model-sync.js +0 -49
- package/dist/components/expression-editor/internal/editor-runtime/model-sync.js.map +0 -1
- package/dist/components/expression-editor/internal/features/commands/register-command-packs.js +0 -215
- package/dist/components/expression-editor/internal/features/commands/register-command-packs.js.map +0 -1
- package/dist/components/expression-editor/internal/features/drag-drop/drag-drop-service.js +0 -33
- package/dist/components/expression-editor/internal/features/drag-drop/drag-drop-service.js.map +0 -1
- package/dist/components/expression-editor/internal/features/insertion/insertion-service.js +0 -33
- package/dist/components/expression-editor/internal/features/insertion/insertion-service.js.map +0 -1
- package/dist/components/expression-editor/nodes/variable-node.js +0 -94
- package/dist/components/expression-editor/nodes/variable-node.js.map +0 -1
- package/dist/components/expression-editor/parser.js +0 -32
- package/dist/components/expression-editor/parser.js.map +0 -1
- package/dist/components/expression-editor/plain-text.js +0 -19
- package/dist/components/expression-editor/plain-text.js.map +0 -1
- package/dist/components/expression-editor/use-context.js +0 -69
- package/dist/components/expression-editor/use-context.js.map +0 -1
- package/dist/components/expression-editor/use-decorators.js +0 -27
- package/dist/components/expression-editor/use-decorators.js.map +0 -1
- package/dist/components/expression-editor/use-expression-drag-drop.js +0 -275
- package/dist/components/expression-editor/use-expression-drag-drop.js.map +0 -1
- package/src/components/batch-edit/batch-edit-new.vue +0 -168
- package/src/components/batch-edit/style-new.scss +0 -35
- package/src/components/batch-edit/use-edit-new.ts +0 -68
- package/src/components/batch-edit/use-tip.ts +0 -47
- package/src/components/expression-editor/__test__/architecture-boundaries.test.ts +0 -103
- package/src/components/expression-editor/__test__/architecture-compatibility.test.ts +0 -52
- package/src/components/expression-editor/__test__/drag-drop.test.ts +0 -171
- package/src/components/expression-editor/__test__/parser.test.ts +0 -62
- package/src/components/expression-editor/constants.ts +0 -6
- package/src/components/expression-editor/internal/contracts/editor-runtime.ts +0 -11
- package/src/components/expression-editor/internal/editor-runtime/create-runtime.ts +0 -64
- package/src/components/expression-editor/internal/editor-runtime/index.ts +0 -1
- package/src/components/expression-editor/internal/editor-runtime/model-sync.ts +0 -68
- package/src/components/expression-editor/internal/features/commands/register-command-packs.ts +0 -517
- package/src/components/expression-editor/internal/features/drag-drop/drag-drop-service.ts +0 -51
- package/src/components/expression-editor/internal/features/insertion/insertion-service.ts +0 -56
- package/src/components/expression-editor/nodes/variable-node.tsx +0 -118
- package/src/components/expression-editor/parser.ts +0 -46
- package/src/components/expression-editor/plain-text.ts +0 -25
- package/src/components/expression-editor/plan.md +0 -22
- package/src/components/expression-editor/use-context.ts +0 -134
- package/src/components/expression-editor/use-decorators.tsx +0 -29
- package/src/components/expression-editor/use-editor.ts +0 -12
- package/src/components/expression-editor/use-expression-drag-drop.ts +0 -396
|
@@ -1,118 +0,0 @@
|
|
|
1
|
-
import { DecoratorNode, type LexicalNode, type SerializedLexicalNode, type NodeKey } from 'lexical'
|
|
2
|
-
import type { VNode } from 'vue'
|
|
3
|
-
|
|
4
|
-
import { UTag } from '../../tag'
|
|
5
|
-
import {
|
|
6
|
-
EXPRESSION_VARIABLE_DRAG_KEY_ATTR,
|
|
7
|
-
EXPRESSION_VARIABLE_DRAG_MARKER_ATTR
|
|
8
|
-
} from '../constants'
|
|
9
|
-
|
|
10
|
-
interface SerializedVariableNode extends SerializedLexicalNode {
|
|
11
|
-
type: 'variable'
|
|
12
|
-
variable: string
|
|
13
|
-
label?: string
|
|
14
|
-
variableType?: string
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export class VariableNode extends DecoratorNode<VNode> {
|
|
18
|
-
__variable: string
|
|
19
|
-
__label: string
|
|
20
|
-
__variableType: string
|
|
21
|
-
__text: string
|
|
22
|
-
__domNode: HTMLElement | null = null
|
|
23
|
-
|
|
24
|
-
static override getType(): string {
|
|
25
|
-
return 'variable'
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static override clone(node: VariableNode): VariableNode {
|
|
29
|
-
return new VariableNode(node.__variable, node.__label, node.__variableType, node.__key)
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
static override importJSON(serializedNode: SerializedLexicalNode): VariableNode {
|
|
33
|
-
const variableNode = serializedNode as SerializedVariableNode
|
|
34
|
-
return new VariableNode(
|
|
35
|
-
variableNode.variable,
|
|
36
|
-
variableNode.label || variableNode.variable,
|
|
37
|
-
variableNode.variableType
|
|
38
|
-
)
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
constructor(variable: string, label?: string, type?: string, key?: NodeKey) {
|
|
42
|
-
super(key)
|
|
43
|
-
|
|
44
|
-
this.__variable = variable
|
|
45
|
-
this.__label = label || variable
|
|
46
|
-
this.__variableType = type || ''
|
|
47
|
-
this.__text = `{${variable}}`
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
override createDOM(): HTMLElement {
|
|
51
|
-
const span = document.createElement('span')
|
|
52
|
-
span.style.display = 'inline-block'
|
|
53
|
-
span.classList.add('ultra-expression-variable-source')
|
|
54
|
-
span.setAttribute(EXPRESSION_VARIABLE_DRAG_MARKER_ATTR, 'true')
|
|
55
|
-
span.setAttribute(EXPRESSION_VARIABLE_DRAG_KEY_ATTR, this.getKey())
|
|
56
|
-
span.draggable = true
|
|
57
|
-
return span
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
override getTextContent(): string {
|
|
61
|
-
return this.__text
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
override updateDOM(): false {
|
|
65
|
-
return false
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
override decorate(): VNode {
|
|
69
|
-
const displayText = this.__variableType
|
|
70
|
-
? `${this.__label} (${this.__variableType})`
|
|
71
|
-
: this.__label
|
|
72
|
-
return (
|
|
73
|
-
<UTag size='small' style='margin: 0 2px' type='primary' round title={this.__label}>
|
|
74
|
-
{displayText}
|
|
75
|
-
</UTag>
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
updateVariable(newVariable: string, newLabel?: string, newType?: string): void {
|
|
80
|
-
const writable = this.getWritable()
|
|
81
|
-
writable.__variable = newVariable
|
|
82
|
-
writable.__label = newLabel || newVariable
|
|
83
|
-
writable.__variableType = newType ?? writable.__variableType
|
|
84
|
-
writable.__text = `{${newVariable}}`
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
getVariable(): string {
|
|
88
|
-
return this.__variable
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
getLabel(): string {
|
|
92
|
-
return this.__label
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
getVariableType(): string {
|
|
96
|
-
return this.__variableType
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
override exportJSON(): SerializedVariableNode {
|
|
100
|
-
return {
|
|
101
|
-
...super.exportJSON(),
|
|
102
|
-
type: 'variable',
|
|
103
|
-
variable: this.__variable,
|
|
104
|
-
label: this.__label,
|
|
105
|
-
variableType: this.__variableType
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
/** 判断是否为变量节点 */
|
|
111
|
-
export function $isVariableNode(node: LexicalNode | null | undefined): boolean {
|
|
112
|
-
return node instanceof VariableNode
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/** 创建变量节点 */
|
|
116
|
-
export function $createVariableNode(variable: string, label?: string, type?: string): VariableNode {
|
|
117
|
-
return new VariableNode(variable, label, type)
|
|
118
|
-
}
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { $createTextNode, type LexicalNode } from 'lexical'
|
|
2
|
-
|
|
3
|
-
import type { VariableItem } from '../../types'
|
|
4
|
-
import { $createVariableNode } from './nodes/variable-node'
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 解析表达式内容
|
|
8
|
-
* @param content 表达式内容
|
|
9
|
-
* @param variableMap 变量映射表(可选,用于查找 label)
|
|
10
|
-
* @returns 节点列表
|
|
11
|
-
*/
|
|
12
|
-
export function parseContent(
|
|
13
|
-
content: string,
|
|
14
|
-
variableMap?: Map<string, VariableItem>
|
|
15
|
-
): LexicalNode[] {
|
|
16
|
-
const nodes: LexicalNode[] = []
|
|
17
|
-
|
|
18
|
-
let prevItem: null | RegExpExecArray = null
|
|
19
|
-
for (const item of content.matchAll(/\{([^}]+)\}/g)) {
|
|
20
|
-
const variable = item[1]!
|
|
21
|
-
|
|
22
|
-
const startIndex = prevItem ? prevItem.index! + prevItem[0].length : 0
|
|
23
|
-
const endIndex = item.index
|
|
24
|
-
|
|
25
|
-
const text = content.slice(startIndex, endIndex)
|
|
26
|
-
|
|
27
|
-
if (text) {
|
|
28
|
-
nodes.push($createTextNode(text))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
prevItem = item
|
|
32
|
-
|
|
33
|
-
// 从映射表中查找对应的 label
|
|
34
|
-
const label = variableMap?.get(variable)?.label
|
|
35
|
-
nodes.push($createVariableNode(variable, label))
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (prevItem) {
|
|
39
|
-
const tail = content.slice(prevItem.index! + prevItem[0].length)
|
|
40
|
-
if (tail) nodes.push($createTextNode(tail))
|
|
41
|
-
} else if (content) {
|
|
42
|
-
nodes.push($createTextNode(content))
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return nodes
|
|
46
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { LexicalEditor } from 'lexical'
|
|
2
|
-
import { onBeforeUnmount } from 'vue'
|
|
3
|
-
|
|
4
|
-
import { registerCommandPacks } from './internal/features/commands/register-command-packs'
|
|
5
|
-
import { clearDragVisualState } from './use-expression-drag-drop'
|
|
6
|
-
|
|
7
|
-
export interface RegisterPlainTextOptions {
|
|
8
|
-
/** Optional context-key commands registration (e.g. from use-context). Merged when provided. */
|
|
9
|
-
getContextCommands?: () => () => void
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Registers plain-text editing commands for the expression editor.
|
|
14
|
-
* Delegates to capability command packs (text-editing, clipboard, drag-drop, optional context-keys).
|
|
15
|
-
*/
|
|
16
|
-
export function registerPlainText(editor: LexicalEditor, options?: RegisterPlainTextOptions): void {
|
|
17
|
-
const removeListener = registerCommandPacks(editor, {
|
|
18
|
-
getContextCommands: options?.getContextCommands
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
onBeforeUnmount(() => {
|
|
22
|
-
clearDragVisualState(editor)
|
|
23
|
-
removeListener()
|
|
24
|
-
})
|
|
25
|
-
}
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import { mergeRegister } from '@lexical/utils'
|
|
2
|
-
import {
|
|
3
|
-
$getSelection,
|
|
4
|
-
$isRangeSelection,
|
|
5
|
-
COMMAND_PRIORITY_LOW,
|
|
6
|
-
COMMAND_PRIORITY_EDITOR,
|
|
7
|
-
KEY_ARROW_DOWN_COMMAND,
|
|
8
|
-
KEY_ARROW_UP_COMMAND,
|
|
9
|
-
type LexicalEditor,
|
|
10
|
-
SELECTION_CHANGE_COMMAND,
|
|
11
|
-
KEY_ENTER_COMMAND,
|
|
12
|
-
KEY_ESCAPE_COMMAND,
|
|
13
|
-
TextNode
|
|
14
|
-
} from 'lexical'
|
|
15
|
-
import { shallowRef, type ShallowRef } from 'vue'
|
|
16
|
-
|
|
17
|
-
import { CONTEXT_TRIGGER_CHAR } from './constants'
|
|
18
|
-
|
|
19
|
-
export function useContext(editor: LexicalEditor): {
|
|
20
|
-
contextVisible: ShallowRef<boolean>
|
|
21
|
-
contextTriggerDom: ShallowRef<HTMLElement | undefined>
|
|
22
|
-
textNode: ShallowRef<TextNode | undefined>
|
|
23
|
-
charPosition: ShallowRef<number>
|
|
24
|
-
registerPickerKeyHandler: (handler: ((e: KeyboardEvent) => void) | null) => void
|
|
25
|
-
/** Returns cleanup for context-key commands. Injected into registerCommandPacks. */
|
|
26
|
-
registerContextCommands: () => () => void
|
|
27
|
-
} {
|
|
28
|
-
const contextVisible = shallowRef(false)
|
|
29
|
-
const contextTriggerDom = shallowRef<HTMLElement>()
|
|
30
|
-
const textNode = shallowRef<TextNode>()
|
|
31
|
-
const charPosition = shallowRef(0)
|
|
32
|
-
const pickerKeyHandlerRef = shallowRef<((e: KeyboardEvent) => void) | null>(null)
|
|
33
|
-
|
|
34
|
-
function registerPickerKeyHandler(handler: ((e: KeyboardEvent) => void) | null) {
|
|
35
|
-
pickerKeyHandlerRef.value = handler
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function openContextMenu(triggerElement: HTMLElement) {
|
|
39
|
-
contextVisible.value = true
|
|
40
|
-
|
|
41
|
-
contextTriggerDom.value = triggerElement
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function closeContextMenu() {
|
|
45
|
-
contextVisible.value = false
|
|
46
|
-
contextTriggerDom.value = undefined
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
function PreventDefaultListener(event: KeyboardEvent) {
|
|
50
|
-
if (event.isComposing) return false
|
|
51
|
-
if (contextVisible.value) {
|
|
52
|
-
event.preventDefault()
|
|
53
|
-
pickerKeyHandlerRef.value?.(event)
|
|
54
|
-
return true
|
|
55
|
-
}
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function registerContextCommands(): () => void {
|
|
60
|
-
return mergeRegister(
|
|
61
|
-
// 选取变更命令,实现呼出上下文菜单的核心
|
|
62
|
-
editor.registerCommand(
|
|
63
|
-
SELECTION_CHANGE_COMMAND,
|
|
64
|
-
() => {
|
|
65
|
-
const selection = $getSelection()
|
|
66
|
-
|
|
67
|
-
// 如果菜单已经打开,不要因为失焦而关闭(用户可能在输入搜索框)
|
|
68
|
-
if (contextVisible.value) {
|
|
69
|
-
return true
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
// 选区类型必须为rangeSelection且选取的anchor和focus的offset值必须一致
|
|
73
|
-
// 否则关闭上下文菜单
|
|
74
|
-
if (!$isRangeSelection(selection) || selection.anchor.offset !== selection.focus.offset) {
|
|
75
|
-
closeContextMenu()
|
|
76
|
-
|
|
77
|
-
return false
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const cursorPosition = selection.focus.offset
|
|
81
|
-
const node = selection.focus.getNode()
|
|
82
|
-
const textContent = node.getTextContent()
|
|
83
|
-
|
|
84
|
-
// 检测光标是否在 '@' 左右
|
|
85
|
-
const isAtTriggerLeft = textContent[cursorPosition - 1] === CONTEXT_TRIGGER_CHAR
|
|
86
|
-
const isAtTriggerRight = textContent[cursorPosition] === CONTEXT_TRIGGER_CHAR
|
|
87
|
-
|
|
88
|
-
// 光标左右的字符都不是'@'时,关闭上下文菜单
|
|
89
|
-
if (!isAtTriggerLeft && !isAtTriggerRight) {
|
|
90
|
-
closeContextMenu()
|
|
91
|
-
return false
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
// 更新文本节点和光标位置
|
|
95
|
-
// charPosition: index of first char after '@' (for slice in handleVariableSelect)
|
|
96
|
-
// isAtTriggerLeft: '@' is left of cursor (cursor already after '@') → charPosition = cursorPosition
|
|
97
|
-
// isAtTriggerRight: '@' is right of cursor (cursor before '@') → charPosition = cursorPosition + 1
|
|
98
|
-
textNode.value = node as TextNode
|
|
99
|
-
charPosition.value = isAtTriggerLeft ? cursorPosition : cursorPosition + 1
|
|
100
|
-
|
|
101
|
-
const triggerDom = editor.getElementByKey(node.getKey())
|
|
102
|
-
|
|
103
|
-
// 如果弹框已经打开,更新位置;否则打开弹框
|
|
104
|
-
if (contextVisible.value) {
|
|
105
|
-
// 更新触发元素位置(如果变化了)
|
|
106
|
-
if (triggerDom && triggerDom !== contextTriggerDom.value) {
|
|
107
|
-
contextTriggerDom.value = triggerDom
|
|
108
|
-
}
|
|
109
|
-
} else {
|
|
110
|
-
triggerDom && openContextMenu(triggerDom)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return true
|
|
114
|
-
},
|
|
115
|
-
COMMAND_PRIORITY_EDITOR
|
|
116
|
-
),
|
|
117
|
-
|
|
118
|
-
// 当上下文菜单显示时,阻止下面的命令的默认行为
|
|
119
|
-
editor.registerCommand(KEY_ENTER_COMMAND, PreventDefaultListener, COMMAND_PRIORITY_LOW),
|
|
120
|
-
editor.registerCommand(KEY_ESCAPE_COMMAND, PreventDefaultListener, COMMAND_PRIORITY_LOW),
|
|
121
|
-
editor.registerCommand(KEY_ARROW_UP_COMMAND, PreventDefaultListener, COMMAND_PRIORITY_LOW),
|
|
122
|
-
editor.registerCommand(KEY_ARROW_DOWN_COMMAND, PreventDefaultListener, COMMAND_PRIORITY_LOW)
|
|
123
|
-
)
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
return {
|
|
127
|
-
contextVisible,
|
|
128
|
-
contextTriggerDom,
|
|
129
|
-
textNode,
|
|
130
|
-
charPosition,
|
|
131
|
-
registerPickerKeyHandler,
|
|
132
|
-
registerContextCommands
|
|
133
|
-
}
|
|
134
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import type { LexicalEditor } from 'lexical'
|
|
2
|
-
import type { DefineComponent, VNode } from 'vue'
|
|
3
|
-
import { Teleport, computed, onBeforeUnmount, shallowRef, type ComputedRef } from 'vue'
|
|
4
|
-
|
|
5
|
-
export function useDecorators(editor: LexicalEditor): ComputedRef<VNode[]> {
|
|
6
|
-
const decorators = shallowRef(editor.getDecorators<DefineComponent>())
|
|
7
|
-
|
|
8
|
-
const removeListener = editor.registerDecoratorListener<DefineComponent>((nextDecorators) => {
|
|
9
|
-
decorators.value = nextDecorators
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
onBeforeUnmount(() => {
|
|
13
|
-
removeListener()
|
|
14
|
-
})
|
|
15
|
-
|
|
16
|
-
return computed(() => {
|
|
17
|
-
const decoratedTeleports: VNode[] = []
|
|
18
|
-
const decoratorKeys = Object.keys(decorators.value)
|
|
19
|
-
decoratorKeys.forEach((nodeKey) => {
|
|
20
|
-
const node = decorators.value[nodeKey]!
|
|
21
|
-
const element = editor.getElementByKey(nodeKey)
|
|
22
|
-
if (element !== null) {
|
|
23
|
-
decoratedTeleports.push(<Teleport to={element}>{node}</Teleport>)
|
|
24
|
-
}
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
return decoratedTeleports
|
|
28
|
-
})
|
|
29
|
-
}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { LexicalEditor } from 'lexical'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
createExpressionEditorRuntime,
|
|
5
|
-
type CreateExpressionEditorRuntimeOptions
|
|
6
|
-
} from './internal/editor-runtime/create-runtime'
|
|
7
|
-
|
|
8
|
-
export type EditorOptions = CreateExpressionEditorRuntimeOptions
|
|
9
|
-
|
|
10
|
-
export function useEditor(options: EditorOptions): LexicalEditor {
|
|
11
|
-
return createExpressionEditorRuntime(options).editor
|
|
12
|
-
}
|