Skip to content

Commit 91ba559

Browse files
author
knight.chen
committed
optimize: 移除对 @alilc/lowcode-utils 的依赖
1 parent 26303d8 commit 91ba559

File tree

11 files changed

+111
-76
lines changed

11 files changed

+111
-76
lines changed

packages/utils/src/check.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,7 @@ export function isESModule(obj: unknown): obj is ESModule {
2222
export function isCSSUrl(url: string): boolean {
2323
return /\.css$/.test(url);
2424
}
25+
26+
export function isElement(node: unknown): node is Element {
27+
return isObject(node) && node.nodeType === Node.ELEMENT_NODE;
28+
}

packages/utils/src/setup-environment.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,14 @@ import type { Project } from '@alilc/lowcode-shell';
22
import { AssetType } from '@alilc/lowcode-types';
33
import { assetItem } from './asset';
44

5-
export function setupHostEnvironment(project: Project): void {
5+
export function setupHostEnvironment(project: Project, vueRuntimeUrl: string): void {
66
project.onSimulatorHostReady((host) => {
77
host.set('environment', [
88
assetItem(
99
AssetType.JSText,
10-
'window.Vue=window.parent.Vue;window.__is_simulator_env__=true;',
11-
undefined,
12-
'vue'
13-
),
14-
assetItem(
15-
AssetType.JSText,
16-
'window.__VUE_DEVTOOLS_GLOBAL_HOOK__=window.parent.__VUE_DEVTOOLS_GLOBAL_HOOK__;window.__VUE_HMR_RUNTIME__=window.parent.__VUE_HMR_RUNTIME__;'
10+
'window.__is_simulator_env__=true;window.__VUE_DEVTOOLS_GLOBAL_HOOK__=window.parent.__VUE_DEVTOOLS_GLOBAL_HOOK__;'
1711
),
12+
assetItem(AssetType.JSUrl, vueRuntimeUrl, undefined, 'vue'),
1813
]);
1914
});
2015
}

packages/vue-simulator-renderer/package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
"homepage": "https://unpkg.com/@knxcloud/[email protected]/build/index.html",
2020
"dependencies": {
2121
"@alilc/lowcode-types": "^1.0.11",
22-
"@alilc/lowcode-utils": "^1.0.11",
2322
"@knxcloud/lowcode-utils": "^1.4.3",
2423
"@knxcloud/lowcode-vue-renderer": "^1.4.3",
2524
"vue-router": "^4.0.16"

packages/vue-simulator-renderer/src/index.less

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,26 @@ html.engine-cursor-ew-resize * {
2525
cursor: ew-resize !important;
2626
}
2727

28+
html.lc-cursor-dragging,
29+
html.lc-cursor-dragging * {
30+
cursor: move !important;
31+
}
32+
33+
html.lc-cursor-x-resizing,
34+
html.lc-cursor-x-resizing * {
35+
cursor: col-resize;
36+
}
37+
38+
html.lc-cursor-y-resizing,
39+
html.lc-cursor-y-resizing * {
40+
cursor: row-resize;
41+
}
42+
43+
html.lc-cursor-copy,
44+
html.lc-cursor-copy * {
45+
cursor: copy !important;
46+
}
47+
2848
::-webkit-scrollbar {
2949
width: 5px;
3050
height: 5px;

packages/vue-simulator-renderer/src/index.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ win.addEventListener('beforeunload', () => {
1616
export default simulator;
1717
export * from '@knxcloud/lowcode-vue-renderer';
1818
export {
19-
useLeaf,
20-
useRenderer,
21-
useRootScope,
2219
config as vueRendererConfig,
2320
default as VueRenderer,
2421
} from '@knxcloud/lowcode-vue-renderer';

packages/vue-simulator-renderer/src/simulator.ts

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,5 @@
11
import { DocumentModel } from '@alilc/lowcode-designer';
22
import { TransformStage } from '@alilc/lowcode-types';
3-
import {
4-
AssetLoader,
5-
cursor,
6-
getSubComponent,
7-
setNativeSelection,
8-
} from '@alilc/lowcode-utils';
93
import {
104
Ref,
115
Component,
@@ -18,7 +12,7 @@ import {
1812
onUnmounted,
1913
} from 'vue';
2014
import { config } from '@knxcloud/lowcode-vue-renderer';
21-
import { buildComponents } from '@knxcloud/lowcode-utils';
15+
import { AssetLoader, buildComponents, getSubComponent } from '@knxcloud/lowcode-utils';
2216
import {
2317
ComponentInstance,
2418
DocumentInstance,
@@ -30,6 +24,7 @@ import { Renderer, SimulatorRendererView } from './simulator-view';
3024
import { Slot, Leaf, Page } from './buildin-components';
3125
import { host } from './host';
3226
import {
27+
cursor,
3328
findDOMNodes,
3429
getClientRects,
3530
getCompRootData,
@@ -38,6 +33,7 @@ import {
3833
ComponentRecord,
3934
isComponentRecord,
4035
getClosestNodeInstanceByComponent,
36+
setNativeSelection,
4137
} from './utils';
4238
import { createMemoryHistory, createRouter } from 'vue-router';
4339

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
class Cursor {
2+
private states = new Set<string>();
3+
4+
setDragging(flag: boolean) {
5+
if (flag) {
6+
this.addState('dragging');
7+
} else {
8+
this.removeState('dragging');
9+
}
10+
}
11+
12+
setXResizing(flag: boolean) {
13+
if (flag) {
14+
this.addState('x-resizing');
15+
} else {
16+
this.removeState('x-resizing');
17+
}
18+
}
19+
20+
setYResizing(flag: boolean) {
21+
if (flag) {
22+
this.addState('y-resizing');
23+
} else {
24+
this.removeState('y-resizing');
25+
}
26+
}
27+
28+
setCopy(flag: boolean) {
29+
if (flag) {
30+
this.addState('copy');
31+
} else {
32+
this.removeState('copy');
33+
}
34+
}
35+
36+
isCopy() {
37+
return this.states.has('copy');
38+
}
39+
40+
release() {
41+
for (const state of this.states) {
42+
this.removeState(state);
43+
}
44+
}
45+
46+
addState(state: string) {
47+
if (!this.states.has(state)) {
48+
this.states.add(state);
49+
document.documentElement.classList.add(`lc-cursor-${state}`);
50+
}
51+
}
52+
53+
private removeState(state: string) {
54+
if (this.states.has(state)) {
55+
this.states.delete(state);
56+
document.documentElement.classList.remove(`lc-cursor-${state}`);
57+
}
58+
}
59+
}
60+
61+
export const cursor = new Cursor();

packages/vue-simulator-renderer/src/utils/get-client-rects.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isElement } from '@alilc/lowcode-utils';
1+
import { isElement } from '@knxcloud/lowcode-utils';
22

33
// a range for test TextNode clientRect
44
const cycleRange = document.createRange();

packages/vue-simulator-renderer/src/utils/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,5 @@ export * from './check';
55
export * from './closest-node';
66
export * from './find-dom-nodes';
77
export * from './logger';
8+
export * from './cursor';
9+
export * from './navtive-selection';
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
let nativeSelectionEnabled = true;
2+
const preventSelection = (e: Event) => {
3+
if (nativeSelectionEnabled) {
4+
return null;
5+
}
6+
e.preventDefault();
7+
e.stopPropagation();
8+
return false;
9+
};
10+
document.addEventListener('selectstart', preventSelection, true);
11+
document.addEventListener('dragstart', preventSelection, true);
12+
13+
export function setNativeSelection(enableFlag: boolean) {
14+
nativeSelectionEnabled = enableFlag;
15+
}

0 commit comments

Comments
 (0)