@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,396 +0,0 @@
|
|
|
1
|
-
import { $getNodeByKey, $getRoot, type LexicalEditor, type LexicalNode } from 'lexical'
|
|
2
|
-
|
|
3
|
-
import {
|
|
4
|
-
EXPRESSION_DROP_SCOPE_ATTR,
|
|
5
|
-
EXPRESSION_VARIABLE_DRAG_KEY_ATTR,
|
|
6
|
-
EXPRESSION_VARIABLE_DRAG_MARKER_ATTR,
|
|
7
|
-
EXPRESSION_VARIABLE_DRAG_TYPE
|
|
8
|
-
} from './constants'
|
|
9
|
-
import { VariableNode } from './nodes/variable-node'
|
|
10
|
-
|
|
11
|
-
type Direction = -1 | 1
|
|
12
|
-
|
|
13
|
-
interface DragVisualState {
|
|
14
|
-
indicatorEl: HTMLDivElement | null
|
|
15
|
-
sourceEl: HTMLElement | null
|
|
16
|
-
cleanupDragEnd: (() => void) | null
|
|
17
|
-
activePayload: InternalDragPayload | null
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
interface DropAnchor {
|
|
21
|
-
x: number
|
|
22
|
-
y: number
|
|
23
|
-
height: number
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface VariableNodeDescriptor {
|
|
27
|
-
key: string
|
|
28
|
-
variable: string
|
|
29
|
-
label: string
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export interface InternalDragPayload {
|
|
33
|
-
sourceKey: string
|
|
34
|
-
scopeId: string
|
|
35
|
-
action: 'move-variable'
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export interface ApplyDropReorderOptions {
|
|
39
|
-
payloadText: string | null
|
|
40
|
-
scopeId: string
|
|
41
|
-
targetSlot: number
|
|
42
|
-
focusMovedNode?: boolean
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const DROP_INDICATOR_CLASS = 'expression-editor__drop-indicator'
|
|
46
|
-
const DRAG_SOURCE_CLASS = 'is-dragging'
|
|
47
|
-
|
|
48
|
-
const dragVisualStateMap = new WeakMap<LexicalEditor, DragVisualState>()
|
|
49
|
-
|
|
50
|
-
function getDragVisualState(editor: LexicalEditor): DragVisualState {
|
|
51
|
-
const existing = dragVisualStateMap.get(editor)
|
|
52
|
-
if (existing) return existing
|
|
53
|
-
|
|
54
|
-
const created: DragVisualState = {
|
|
55
|
-
indicatorEl: null,
|
|
56
|
-
sourceEl: null,
|
|
57
|
-
cleanupDragEnd: null,
|
|
58
|
-
activePayload: null
|
|
59
|
-
}
|
|
60
|
-
dragVisualStateMap.set(editor, created)
|
|
61
|
-
return created
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function isHTMLElement(target: EventTarget | null): target is HTMLElement {
|
|
65
|
-
return target instanceof HTMLElement
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function hasChildren(
|
|
69
|
-
node: LexicalNode
|
|
70
|
-
): node is LexicalNode & { getChildren: () => LexicalNode[] } {
|
|
71
|
-
return typeof (node as { getChildren?: unknown }).getChildren === 'function'
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
function traverseVariableNodes(node: LexicalNode, collector: VariableNodeDescriptor[]): void {
|
|
75
|
-
if (node instanceof VariableNode) {
|
|
76
|
-
collector.push({ key: node.getKey(), variable: node.getVariable(), label: node.getLabel() })
|
|
77
|
-
return
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
if (!hasChildren(node)) return
|
|
81
|
-
node.getChildren().forEach((child) => traverseVariableNodes(child, collector))
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
function $collectVariableNodeDescriptors(): VariableNodeDescriptor[] {
|
|
85
|
-
const collector: VariableNodeDescriptor[] = []
|
|
86
|
-
const root = $getRoot()
|
|
87
|
-
traverseVariableNodes(root, collector)
|
|
88
|
-
return collector
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
function getDropIndicator(rootElement: HTMLElement): HTMLDivElement {
|
|
92
|
-
const existing = rootElement.querySelector<HTMLDivElement>(`.${DROP_INDICATOR_CLASS}`)
|
|
93
|
-
if (existing) return existing
|
|
94
|
-
|
|
95
|
-
const indicator = document.createElement('div')
|
|
96
|
-
indicator.className = DROP_INDICATOR_CLASS
|
|
97
|
-
indicator.style.opacity = '0'
|
|
98
|
-
rootElement.appendChild(indicator)
|
|
99
|
-
return indicator
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function getDropAnchors(editor: LexicalEditor): DropAnchor[] {
|
|
103
|
-
const descriptors = collectVariableNodeDescriptors(editor)
|
|
104
|
-
if (descriptors.length === 0) return []
|
|
105
|
-
|
|
106
|
-
const rects = descriptors
|
|
107
|
-
.map((descriptor) => editor.getElementByKey(descriptor.key))
|
|
108
|
-
.filter((element): element is HTMLElement => element instanceof HTMLElement)
|
|
109
|
-
.map((element) => element.getBoundingClientRect())
|
|
110
|
-
|
|
111
|
-
if (rects.length === 0) return []
|
|
112
|
-
|
|
113
|
-
const anchors: DropAnchor[] = []
|
|
114
|
-
const first = rects[0]!
|
|
115
|
-
anchors.push({ x: first.left, y: first.top, height: first.height })
|
|
116
|
-
|
|
117
|
-
for (let index = 0; index < rects.length - 1; index++) {
|
|
118
|
-
const currentRect = rects[index]!
|
|
119
|
-
const nextRect = rects[index + 1]!
|
|
120
|
-
anchors.push({
|
|
121
|
-
x: (currentRect.right + nextRect.left) / 2,
|
|
122
|
-
y: (currentRect.top + nextRect.top) / 2,
|
|
123
|
-
height: Math.max(currentRect.height, nextRect.height)
|
|
124
|
-
})
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const last = rects[rects.length - 1]!
|
|
128
|
-
anchors.push({ x: last.right, y: last.top, height: last.height })
|
|
129
|
-
|
|
130
|
-
return anchors
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
function getDistance(pointerX: number, pointerY: number, anchor: DropAnchor): number {
|
|
134
|
-
const dx = pointerX - anchor.x
|
|
135
|
-
const dy = pointerY - (anchor.y + anchor.height / 2)
|
|
136
|
-
return dx * dx + dy * dy
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
export function supportsNativeDnD(): boolean {
|
|
140
|
-
if (typeof window === 'undefined') return false
|
|
141
|
-
|
|
142
|
-
const probe = document.createElement('span')
|
|
143
|
-
const hasDragApi = 'draggable' in probe && typeof DataTransfer !== 'undefined'
|
|
144
|
-
const coarsePointer = window.matchMedia?.('(pointer: coarse)').matches ?? false
|
|
145
|
-
|
|
146
|
-
return hasDragApi && !coarsePointer
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
export function collectVariableNodeDescriptors(editor: LexicalEditor): VariableNodeDescriptor[] {
|
|
150
|
-
let descriptors: VariableNodeDescriptor[] = []
|
|
151
|
-
editor.getEditorState().read(() => {
|
|
152
|
-
descriptors = $collectVariableNodeDescriptors()
|
|
153
|
-
})
|
|
154
|
-
return descriptors
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export function ensureDropScopeId(editor: LexicalEditor): string {
|
|
158
|
-
const rootElement = editor.getRootElement()
|
|
159
|
-
if (!rootElement) return ''
|
|
160
|
-
|
|
161
|
-
const existing = rootElement.getAttribute(EXPRESSION_DROP_SCOPE_ATTR)
|
|
162
|
-
if (existing) return existing
|
|
163
|
-
|
|
164
|
-
const generated = `scope-${Math.random().toString(36).slice(2)}`
|
|
165
|
-
rootElement.setAttribute(EXPRESSION_DROP_SCOPE_ATTR, generated)
|
|
166
|
-
return generated
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
export function findVariableDragSource(target: EventTarget | null): HTMLElement | null {
|
|
170
|
-
if (!isHTMLElement(target)) return null
|
|
171
|
-
|
|
172
|
-
return target.closest<HTMLElement>(`[${EXPRESSION_VARIABLE_DRAG_MARKER_ATTR}="true"]`)
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
export function readDragSourceKey(target: EventTarget | null): string | null {
|
|
176
|
-
const source = findVariableDragSource(target)
|
|
177
|
-
if (!source) return null
|
|
178
|
-
|
|
179
|
-
return source.getAttribute(EXPRESSION_VARIABLE_DRAG_KEY_ATTR)
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
export function createInternalDragPayload(payload: InternalDragPayload): string {
|
|
183
|
-
return JSON.stringify(payload)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
export function writeInternalDragPayload(
|
|
187
|
-
dataTransfer: DataTransfer | null,
|
|
188
|
-
payload: InternalDragPayload
|
|
189
|
-
): void {
|
|
190
|
-
if (!dataTransfer) return
|
|
191
|
-
dataTransfer.setData(EXPRESSION_VARIABLE_DRAG_TYPE, createInternalDragPayload(payload))
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
export function parseInternalDragPayload(payloadText: string | null): InternalDragPayload | null {
|
|
195
|
-
if (!payloadText) return null
|
|
196
|
-
|
|
197
|
-
try {
|
|
198
|
-
const parsed = JSON.parse(payloadText) as Partial<InternalDragPayload>
|
|
199
|
-
if (
|
|
200
|
-
parsed.action !== 'move-variable' ||
|
|
201
|
-
typeof parsed.scopeId !== 'string' ||
|
|
202
|
-
parsed.scopeId.length === 0 ||
|
|
203
|
-
typeof parsed.sourceKey !== 'string' ||
|
|
204
|
-
parsed.sourceKey.length === 0
|
|
205
|
-
) {
|
|
206
|
-
return null
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return { action: parsed.action, scopeId: parsed.scopeId, sourceKey: parsed.sourceKey }
|
|
210
|
-
} catch {
|
|
211
|
-
return null
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
export function readInternalDragPayload(
|
|
216
|
-
dataTransfer: DataTransfer | null
|
|
217
|
-
): InternalDragPayload | null {
|
|
218
|
-
if (!dataTransfer) return null
|
|
219
|
-
return parseInternalDragPayload(dataTransfer.getData(EXPRESSION_VARIABLE_DRAG_TYPE))
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
export function beginDragVisualState(
|
|
223
|
-
editor: LexicalEditor,
|
|
224
|
-
sourceEl: HTMLElement | null,
|
|
225
|
-
payload?: InternalDragPayload
|
|
226
|
-
): void {
|
|
227
|
-
const state = getDragVisualState(editor)
|
|
228
|
-
clearDragVisualState(editor)
|
|
229
|
-
state.activePayload = payload ?? null
|
|
230
|
-
|
|
231
|
-
if (!sourceEl) return
|
|
232
|
-
sourceEl.classList.add(DRAG_SOURCE_CLASS)
|
|
233
|
-
state.sourceEl = sourceEl
|
|
234
|
-
|
|
235
|
-
const onDragEnd = () => {
|
|
236
|
-
clearDragVisualState(editor)
|
|
237
|
-
}
|
|
238
|
-
window.addEventListener('dragend', onDragEnd, true)
|
|
239
|
-
state.cleanupDragEnd = () => {
|
|
240
|
-
window.removeEventListener('dragend', onDragEnd, true)
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
export function getActiveInternalDragPayload(editor: LexicalEditor): InternalDragPayload | null {
|
|
245
|
-
return getDragVisualState(editor).activePayload
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
export function showDropIndicator(editor: LexicalEditor, slot: number): void {
|
|
249
|
-
const rootElement = editor.getRootElement()
|
|
250
|
-
if (!rootElement) return
|
|
251
|
-
|
|
252
|
-
const anchors = getDropAnchors(editor)
|
|
253
|
-
if (slot < 0 || slot >= anchors.length) {
|
|
254
|
-
clearDropIndicator(editor)
|
|
255
|
-
return
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
const anchor = anchors[slot]!
|
|
259
|
-
const indicator = getDropIndicator(rootElement)
|
|
260
|
-
const rootRect = rootElement.getBoundingClientRect()
|
|
261
|
-
|
|
262
|
-
indicator.style.left = `${anchor.x - rootRect.left}px`
|
|
263
|
-
indicator.style.top = `${anchor.y - rootRect.top}px`
|
|
264
|
-
indicator.style.height = `${anchor.height}px`
|
|
265
|
-
indicator.style.opacity = '1'
|
|
266
|
-
|
|
267
|
-
const state = getDragVisualState(editor)
|
|
268
|
-
state.indicatorEl = indicator
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
export function clearDropIndicator(editor: LexicalEditor): void {
|
|
272
|
-
const state = getDragVisualState(editor)
|
|
273
|
-
if (!state.indicatorEl) return
|
|
274
|
-
state.indicatorEl.style.opacity = '0'
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
export function clearDragVisualState(editor: LexicalEditor): void {
|
|
278
|
-
const state = getDragVisualState(editor)
|
|
279
|
-
|
|
280
|
-
if (state.sourceEl) {
|
|
281
|
-
state.sourceEl.classList.remove(DRAG_SOURCE_CLASS)
|
|
282
|
-
state.sourceEl = null
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
if (state.indicatorEl) {
|
|
286
|
-
state.indicatorEl.style.opacity = '0'
|
|
287
|
-
state.indicatorEl = null
|
|
288
|
-
}
|
|
289
|
-
|
|
290
|
-
if (state.cleanupDragEnd) {
|
|
291
|
-
state.cleanupDragEnd()
|
|
292
|
-
state.cleanupDragEnd = null
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
state.activePayload = null
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
export function autoScrollWhenNearEdge(container: HTMLElement, pointerY: number): void {
|
|
299
|
-
const rect = container.getBoundingClientRect()
|
|
300
|
-
const threshold = 24
|
|
301
|
-
const step = 10
|
|
302
|
-
|
|
303
|
-
if (pointerY < rect.top + threshold) {
|
|
304
|
-
container.scrollBy({ top: -step, behavior: 'auto' })
|
|
305
|
-
return
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
if (pointerY > rect.bottom - threshold) {
|
|
309
|
-
container.scrollBy({ top: step, behavior: 'auto' })
|
|
310
|
-
}
|
|
311
|
-
}
|
|
312
|
-
|
|
313
|
-
export function resolveDropSlot(editor: LexicalEditor, event: DragEvent): number | null {
|
|
314
|
-
const rootElement = editor.getRootElement()
|
|
315
|
-
if (!rootElement || !isHTMLElement(event.target)) return null
|
|
316
|
-
if (!rootElement.contains(event.target)) return null
|
|
317
|
-
|
|
318
|
-
const anchors = getDropAnchors(editor)
|
|
319
|
-
if (anchors.length === 0) return null
|
|
320
|
-
|
|
321
|
-
let nearestSlot = 0
|
|
322
|
-
let nearestDistance = Number.POSITIVE_INFINITY
|
|
323
|
-
for (let slot = 0; slot < anchors.length; slot++) {
|
|
324
|
-
const anchor = anchors[slot]!
|
|
325
|
-
const distance = getDistance(event.clientX, event.clientY, anchor)
|
|
326
|
-
if (distance < nearestDistance) {
|
|
327
|
-
nearestDistance = distance
|
|
328
|
-
nearestSlot = slot
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
return nearestSlot
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
export function reorderVariableNode(
|
|
336
|
-
sourceKey: string,
|
|
337
|
-
targetSlot: number,
|
|
338
|
-
focusMovedNode = true
|
|
339
|
-
): boolean {
|
|
340
|
-
const nodes = $collectVariableNodeDescriptors()
|
|
341
|
-
if (nodes.length <= 1) return false
|
|
342
|
-
|
|
343
|
-
const sourceIndex = nodes.findIndex((item) => item.key === sourceKey)
|
|
344
|
-
if (sourceIndex < 0) return false
|
|
345
|
-
if (targetSlot < 0 || targetSlot > nodes.length) return false
|
|
346
|
-
if (targetSlot === sourceIndex || targetSlot === sourceIndex + 1) return false
|
|
347
|
-
|
|
348
|
-
const sourceNode = $getNodeByKey(sourceKey)
|
|
349
|
-
if (!(sourceNode instanceof VariableNode)) return false
|
|
350
|
-
|
|
351
|
-
const remaining = nodes.filter((item) => item.key !== sourceKey)
|
|
352
|
-
const insertionIndex = targetSlot > sourceIndex ? targetSlot - 1 : targetSlot
|
|
353
|
-
const reference = remaining[insertionIndex]
|
|
354
|
-
|
|
355
|
-
if (reference) {
|
|
356
|
-
const referenceNode = $getNodeByKey(reference.key)
|
|
357
|
-
if (!(referenceNode instanceof VariableNode)) return false
|
|
358
|
-
referenceNode.insertBefore(sourceNode)
|
|
359
|
-
} else {
|
|
360
|
-
const last = remaining[remaining.length - 1]
|
|
361
|
-
if (!last) return false
|
|
362
|
-
const lastNode = $getNodeByKey(last.key)
|
|
363
|
-
if (!(lastNode instanceof VariableNode)) return false
|
|
364
|
-
lastNode.insertAfter(sourceNode)
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
if (focusMovedNode) {
|
|
368
|
-
sourceNode.selectEnd()
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
return true
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
export function moveVariableByDirection(
|
|
375
|
-
sourceKey: string,
|
|
376
|
-
direction: Direction,
|
|
377
|
-
focusMovedNode = true
|
|
378
|
-
): boolean {
|
|
379
|
-
const nodes = $collectVariableNodeDescriptors()
|
|
380
|
-
const sourceIndex = nodes.findIndex((item) => item.key === sourceKey)
|
|
381
|
-
if (sourceIndex < 0) return false
|
|
382
|
-
|
|
383
|
-
const targetIndex = sourceIndex + direction
|
|
384
|
-
if (targetIndex < 0 || targetIndex >= nodes.length) return false
|
|
385
|
-
|
|
386
|
-
const targetSlot = direction === -1 ? targetIndex : targetIndex + 1
|
|
387
|
-
return reorderVariableNode(sourceKey, targetSlot, focusMovedNode)
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
export function applyDropReorder(options: ApplyDropReorderOptions): boolean {
|
|
391
|
-
const payload = parseInternalDragPayload(options.payloadText)
|
|
392
|
-
if (!payload) return false
|
|
393
|
-
if (payload.scopeId !== options.scopeId) return false
|
|
394
|
-
|
|
395
|
-
return reorderVariableNode(payload.sourceKey, options.targetSlot, options.focusMovedNode ?? true)
|
|
396
|
-
}
|