@farris/cli 2.0.3 → 2.1.0
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/lib/commands/build.js +6 -7
- package/lib/commands/build.js.map +1 -1
- package/lib/commands/generate/api.js +188 -0
- package/lib/commands/generate/api.js.map +1 -0
- package/lib/commands/generate/common.js +101 -0
- package/lib/commands/generate/common.js.map +1 -0
- package/lib/commands/generate/component.js +163 -0
- package/lib/commands/generate/component.js.map +1 -0
- package/lib/commands/generate/view.js +195 -0
- package/lib/commands/generate/view.js.map +1 -0
- package/lib/commands/workspace/add-app.js +170 -0
- package/lib/commands/workspace/add-app.js.map +1 -0
- package/lib/commands/workspace/create.js +310 -0
- package/lib/commands/workspace/create.js.map +1 -0
- package/lib/commands/workspace/inspect.js +31 -0
- package/lib/commands/workspace/inspect.js.map +1 -0
- package/lib/commands/workspace/verify.js +39 -0
- package/lib/commands/workspace/verify.js.map +1 -0
- package/lib/common/constant.js +42 -1
- package/lib/common/constant.js.map +1 -1
- package/lib/common/get-vite-config.js +66 -9
- package/lib/common/get-vite-config.js.map +1 -1
- package/lib/common/output.js +93 -0
- package/lib/common/output.js.map +1 -0
- package/lib/common/safety.js +172 -0
- package/lib/common/safety.js.map +1 -0
- package/lib/common/template-renderer.js +113 -0
- package/lib/common/template-renderer.js.map +1 -0
- package/lib/common/transaction.js +84 -0
- package/lib/common/transaction.js.map +1 -0
- package/lib/common/verifier.js +147 -0
- package/lib/common/verifier.js.map +1 -0
- package/lib/config/vite-common.js +1 -1
- package/lib/config/vite-common.js.map +1 -1
- package/lib/index.js +124 -30
- package/lib/index.js.map +1 -1
- package/package.json +14 -10
- package/templates/workspace/app/farris.config.mjs +13 -0
- package/templates/{lib → workspace/app}/index.html +12 -12
- package/templates/workspace/app/package.json +22 -0
- package/templates/workspace/app/src/App.tsx +11 -0
- package/templates/workspace/app/src/main.ts +11 -0
- package/templates/workspace/app/src/router/index.ts +16 -0
- package/templates/workspace/app/src/styles/index.css +0 -0
- package/templates/workspace/app/src/styles/index.scss +0 -0
- package/templates/workspace/app/src/views/home/composables/use-home.ts +7 -0
- package/templates/workspace/app/src/views/home/home.component.tsx +15 -0
- package/templates/workspace/app/src/views/home/index.ts +4 -0
- package/templates/workspace/app/tsconfig.json +21 -0
- package/templates/workspace/root/README.md +28 -0
- package/templates/workspace/root/package.json +13 -0
- package/templates/workspace/root/pnpm-workspace.yaml +12 -0
- package/templates/lib/.eslintrc.cjs +0 -15
- package/templates/lib/.prettierrc.json +0 -8
- package/templates/lib/components/button/index.ts +0 -7
- package/templates/lib/components/button/src/button.component.tsx +0 -84
- package/templates/lib/components/button/src/button.props.ts +0 -55
- package/templates/lib/components/button/src/button.scss +0 -179
- package/templates/lib/components/common/index.ts +0 -6
- package/templates/lib/components/common/src/common.scss +0 -4
- package/templates/lib/components/common/src/compositions/index.ts +0 -19
- package/templates/lib/components/common/src/compositions/types.ts +0 -6
- package/templates/lib/components/common/src/compositions/use-bem/index.ts +0 -46
- package/templates/lib/components/common/src/compositions/use-click-away/index.ts +0 -40
- package/templates/lib/components/common/src/compositions/use-context/use-children-contexts.ts +0 -40
- package/templates/lib/components/common/src/compositions/use-context/use-parent-context.ts +0 -24
- package/templates/lib/components/common/src/compositions/use-event-listener/index.ts +0 -45
- package/templates/lib/components/common/src/compositions/use-expose/index.ts +0 -9
- package/templates/lib/components/common/src/compositions/use-lay-render/index.ts +0 -17
- package/templates/lib/components/common/src/compositions/use-link/index.ts +0 -14
- package/templates/lib/components/common/src/compositions/use-lock-scroll/index.ts +0 -25
- package/templates/lib/components/common/src/compositions/use-long-press/index.ts +0 -141
- package/templates/lib/components/common/src/compositions/use-momentum/index.ts +0 -82
- package/templates/lib/components/common/src/compositions/use-mount-component/index.ts +0 -48
- package/templates/lib/components/common/src/compositions/use-rect/index.ts +0 -31
- package/templates/lib/components/common/src/compositions/use-refs/index.ts +0 -21
- package/templates/lib/components/common/src/compositions/use-resize-observer/index.ts +0 -85
- package/templates/lib/components/common/src/compositions/use-resize-observer/utils.ts +0 -37
- package/templates/lib/components/common/src/compositions/use-scroll-parent/index.ts +0 -42
- package/templates/lib/components/common/src/compositions/use-touch/index.ts +0 -82
- package/templates/lib/components/common/src/compositions/use-touch-move/index.ts +0 -120
- package/templates/lib/components/common/src/entity/base-property.ts +0 -129
- package/templates/lib/components/common/src/entity/entity-schema.ts +0 -274
- package/templates/lib/components/common/src/entity/input-base-property.ts +0 -285
- package/templates/lib/components/common/src/style/animation/index.scss +0 -150
- package/templates/lib/components/common/src/style/base.scss +0 -63
- package/templates/lib/components/common/src/style/fonts/farris-mobile-icon.ttf +0 -0
- package/templates/lib/components/common/src/style/icon.scss +0 -6
- package/templates/lib/components/common/src/style/index.scss +0 -4
- package/templates/lib/components/common/src/style/mixins/bem.scss +0 -204
- package/templates/lib/components/common/src/style/mixins/border-radius.scss +0 -13
- package/templates/lib/components/common/src/style/mixins/ellipsis.scss +0 -15
- package/templates/lib/components/common/src/style/mixins/hairline.scss +0 -113
- package/templates/lib/components/common/src/style/mixins/index.scss +0 -6
- package/templates/lib/components/common/src/style/mixins/margin.scss +0 -10
- package/templates/lib/components/common/src/style/mixins/safe-area.scss +0 -9
- package/templates/lib/components/common/src/style/variables.scss +0 -113
- package/templates/lib/components/common/src/utils/index.ts +0 -15
- package/templates/lib/components/common/src/utils/src/common.ts +0 -83
- package/templates/lib/components/common/src/utils/src/date.ts +0 -134
- package/templates/lib/components/common/src/utils/src/dom/event.ts +0 -37
- package/templates/lib/components/common/src/utils/src/hook.ts +0 -18
- package/templates/lib/components/common/src/utils/src/number.ts +0 -26
- package/templates/lib/components/common/src/utils/src/query-filter.ts +0 -40
- package/templates/lib/components/common/src/utils/src/resove-asset.ts +0 -33
- package/templates/lib/components/common/src/utils/src/string.ts +0 -18
- package/templates/lib/components/common/src/utils/src/throttle.ts +0 -41
- package/templates/lib/components/common/src/utils/src/transition.ts +0 -14
- package/templates/lib/components/common/src/utils/src/type.ts +0 -105
- package/templates/lib/components/common/src/utils/src/use-appearance.ts +0 -33
- package/templates/lib/components/common/src/utils/src/with-install.ts +0 -16
- package/templates/lib/components/common/src/utils/src/with-register-designer.ts +0 -16
- package/templates/lib/components/common/src/utils/src/with-register.ts +0 -16
- package/templates/lib/components/common/types.ts +0 -131
- package/templates/lib/components/index.scss +0 -2
- package/templates/lib/components/index.ts +0 -21
- package/templates/lib/farris.config.mjs +0 -56
- package/templates/lib/package.json +0 -32
- package/templates/lib/src/App.vue +0 -80
- package/templates/lib/src/components/TheButton.vue +0 -3
- package/templates/lib/src/main.ts +0 -10
- package/templates/lib/src/router/index.ts +0 -23
- package/templates/lib/src/views/AboutView.vue +0 -15
- package/templates/lib/src/views/HomeView.vue +0 -9
- package/templates/lib/tsconfig.json +0 -20
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
type MonmentumOption = {
|
|
2
|
-
maxOverflowY?: number,
|
|
3
|
-
TimeThreshold?: number,
|
|
4
|
-
YThreshold?: number
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
export const useMonmentum = (options: MonmentumOption) => {
|
|
8
|
-
const { maxOverflowY = 0, TimeThreshold = 200, YThreshold = 88 } = options;
|
|
9
|
-
let startTime = 0;
|
|
10
|
-
let momentumStartY = 0;
|
|
11
|
-
let deltaY = 0;
|
|
12
|
-
const start = (y: number) => {
|
|
13
|
-
startTime = new Date().getTime();
|
|
14
|
-
momentumStartY = y;
|
|
15
|
-
};
|
|
16
|
-
const move = (y: number) => {
|
|
17
|
-
deltaY = y;
|
|
18
|
-
const now = new Date().getTime();
|
|
19
|
-
const duration = now - startTime;
|
|
20
|
-
if (duration > TimeThreshold) {
|
|
21
|
-
momentumStartY = deltaY;
|
|
22
|
-
startTime = now;
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
const end = () => {
|
|
26
|
-
const now = new Date().getTime();
|
|
27
|
-
const duration = now - startTime;
|
|
28
|
-
const absDeltaY = Math.abs(deltaY - momentumStartY);
|
|
29
|
-
if (duration < TimeThreshold && absDeltaY > YThreshold) {
|
|
30
|
-
return true;
|
|
31
|
-
}
|
|
32
|
-
return false;
|
|
33
|
-
};
|
|
34
|
-
const get = (current: number, minY: number, maxY: number) => {
|
|
35
|
-
const durationMap = {
|
|
36
|
-
noBounce: 2500,
|
|
37
|
-
weekBounce: 800,
|
|
38
|
-
strongBounce: 400
|
|
39
|
-
};
|
|
40
|
-
const bezierMap = {
|
|
41
|
-
noBounce: 'cubic-bezier(.17, .89, .45, 1)',
|
|
42
|
-
weekBounce: 'cubic-bezier(.25, .46, .45, .94)',
|
|
43
|
-
strongBounce: 'cubic-bezier(.25, .46, .45, .94)'
|
|
44
|
-
};
|
|
45
|
-
let type = 'noBounce';
|
|
46
|
-
// 惯性滑动加速度
|
|
47
|
-
const deceleration = 0.003;
|
|
48
|
-
// 回弹阻力
|
|
49
|
-
const bounceRate = 10;
|
|
50
|
-
// 强弱回弹的分割值
|
|
51
|
-
const bounceThreshold = 300;
|
|
52
|
-
|
|
53
|
-
let overflowY = 0;
|
|
54
|
-
const now = new Date().getTime();
|
|
55
|
-
const duration = now - startTime;
|
|
56
|
-
|
|
57
|
-
const distance = current - momentumStartY;
|
|
58
|
-
const speed = (2 * Math.abs(distance)) / duration;
|
|
59
|
-
let destination = current + (speed / deceleration) * (distance < 0 ? -1 : 1);
|
|
60
|
-
if (destination < minY) {
|
|
61
|
-
overflowY = minY - destination;
|
|
62
|
-
type = overflowY > bounceThreshold ? 'strongBounce' : 'weekBounce';
|
|
63
|
-
destination = Math.max(minY - maxOverflowY, minY - overflowY / bounceRate);
|
|
64
|
-
} else if (destination > maxY) {
|
|
65
|
-
overflowY = destination - maxY;
|
|
66
|
-
type = overflowY > bounceThreshold ? 'strongBounce' : 'weekBounce';
|
|
67
|
-
destination = Math.min(maxY + maxOverflowY, maxY + overflowY / bounceRate);
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
return {
|
|
71
|
-
destination,
|
|
72
|
-
duration: durationMap[type],
|
|
73
|
-
bezier: bezierMap[type]
|
|
74
|
-
};
|
|
75
|
-
};
|
|
76
|
-
return {
|
|
77
|
-
start,
|
|
78
|
-
move,
|
|
79
|
-
end,
|
|
80
|
-
get
|
|
81
|
-
};
|
|
82
|
-
};
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useExpose } from "../use-expose";
|
|
2
|
-
import { Component, createApp, nextTick, reactive } from "vue";
|
|
3
|
-
|
|
4
|
-
export function usePopupState() {
|
|
5
|
-
const state = reactive({
|
|
6
|
-
show: false,
|
|
7
|
-
});
|
|
8
|
-
|
|
9
|
-
const toggle = (show: boolean) => {
|
|
10
|
-
state.show = show;
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
const open = (props: Record<string, any>) => {
|
|
14
|
-
Object.assign(state, props);
|
|
15
|
-
|
|
16
|
-
nextTick(() => {
|
|
17
|
-
toggle(true);
|
|
18
|
-
});
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
const close = () => {
|
|
22
|
-
toggle(false);
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
useExpose({ open, close, toggle });
|
|
26
|
-
|
|
27
|
-
return {
|
|
28
|
-
open,
|
|
29
|
-
close,
|
|
30
|
-
state,
|
|
31
|
-
toggle,
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function mountComponent(RootComponent: Component) {
|
|
36
|
-
const app = createApp(RootComponent);
|
|
37
|
-
const root = document.createElement('div');
|
|
38
|
-
|
|
39
|
-
document.body.appendChild(root);
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
instance: app.mount(root),
|
|
43
|
-
unmount() {
|
|
44
|
-
app.unmount();
|
|
45
|
-
document.body.removeChild(root);
|
|
46
|
-
},
|
|
47
|
-
};
|
|
48
|
-
}
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { Ref, unref } from 'vue';
|
|
2
|
-
|
|
3
|
-
const isWindow = (val: unknown): val is Window => val === window;
|
|
4
|
-
|
|
5
|
-
const makeDOMRect = (width: number, height: number) =>
|
|
6
|
-
({
|
|
7
|
-
top: 0,
|
|
8
|
-
left: 0,
|
|
9
|
-
right: width,
|
|
10
|
-
bottom: height,
|
|
11
|
-
width,
|
|
12
|
-
height,
|
|
13
|
-
}) as DOMRect;
|
|
14
|
-
|
|
15
|
-
export const useRect = (
|
|
16
|
-
elementOrRef: Element | Window | Ref<Element | Window | undefined>,
|
|
17
|
-
) => {
|
|
18
|
-
const element = unref(elementOrRef);
|
|
19
|
-
|
|
20
|
-
if (isWindow(element)) {
|
|
21
|
-
const width = element.innerWidth;
|
|
22
|
-
const height = element.innerHeight;
|
|
23
|
-
return makeDOMRect(width, height);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (element?.getBoundingClientRect) {
|
|
27
|
-
return element.getBoundingClientRect();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
return makeDOMRect(0, 0);
|
|
31
|
-
};
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ref, Ref, onBeforeUpdate } from 'vue';
|
|
2
|
-
|
|
3
|
-
export function useRefs<T = Element>() {
|
|
4
|
-
const refs = ref([]) as Ref<T[]>;
|
|
5
|
-
const cache: Array<(el: unknown) => void> = [];
|
|
6
|
-
|
|
7
|
-
onBeforeUpdate(() => {
|
|
8
|
-
refs.value = [];
|
|
9
|
-
});
|
|
10
|
-
|
|
11
|
-
const setRefs = (index: number) => {
|
|
12
|
-
if (!cache[index]) {
|
|
13
|
-
cache[index] = (el: unknown) => {
|
|
14
|
-
refs.value[index] = el as T;
|
|
15
|
-
};
|
|
16
|
-
}
|
|
17
|
-
return cache[index];
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
return [refs, setRefs] as const;
|
|
21
|
-
}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
import { computed, watch } from 'vue';
|
|
3
|
-
import { MaybeComputedElementRef, unrefElement, tryOnScopeDispose, defaultWindow } from './utils';
|
|
4
|
-
|
|
5
|
-
export interface ResizeObserverSize {
|
|
6
|
-
readonly inlineSize: number;
|
|
7
|
-
readonly blockSize: number;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export interface ResizeObserverEntry {
|
|
11
|
-
readonly target: Element;
|
|
12
|
-
readonly contentRect: DOMRectReadOnly;
|
|
13
|
-
readonly borderBoxSize?: ReadonlyArray<ResizeObserverSize>;
|
|
14
|
-
readonly contentBoxSize?: ReadonlyArray<ResizeObserverSize>;
|
|
15
|
-
readonly devicePixelContentBoxSize?: ReadonlyArray<ResizeObserverSize>;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export type ResizeObserverCallback = (entries: ReadonlyArray<ResizeObserverEntry>, observer: ResizeObserver) => void;
|
|
19
|
-
|
|
20
|
-
export interface UseResizeObserverOptions {
|
|
21
|
-
|
|
22
|
-
/** 监听的盒模型,默认为`content-box` */
|
|
23
|
-
box?: ResizeObserverBoxOptions;
|
|
24
|
-
|
|
25
|
-
/** 允许指定一个的`window` */
|
|
26
|
-
window?: Window;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
declare class ResizeObserver {
|
|
30
|
-
|
|
31
|
-
constructor(callback: ResizeObserverCallback);
|
|
32
|
-
|
|
33
|
-
disconnect(): void;
|
|
34
|
-
|
|
35
|
-
observe(target: Element, options?: UseResizeObserverOptions): void;
|
|
36
|
-
|
|
37
|
-
unobserve(target: Element): void;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* 监听元素的大小变化
|
|
42
|
-
*/
|
|
43
|
-
export function useResizeObserver(
|
|
44
|
-
target: MaybeComputedElementRef | MaybeComputedElementRef[],
|
|
45
|
-
callback: ResizeObserverCallback,
|
|
46
|
-
options: UseResizeObserverOptions = {},
|
|
47
|
-
) {
|
|
48
|
-
const { window = defaultWindow, ...observerOptions } = options;
|
|
49
|
-
let observer: ResizeObserver | undefined;
|
|
50
|
-
|
|
51
|
-
const cleanup = () => {
|
|
52
|
-
if (observer) {
|
|
53
|
-
observer.disconnect();
|
|
54
|
-
observer = undefined;
|
|
55
|
-
}
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
const targets = computed(() =>
|
|
59
|
-
Array.isArray(target)
|
|
60
|
-
? target.map(el => unrefElement(el))
|
|
61
|
-
: [unrefElement(target)]);
|
|
62
|
-
|
|
63
|
-
const stopWatch = watch(
|
|
64
|
-
targets,
|
|
65
|
-
(elements) => {
|
|
66
|
-
cleanup();
|
|
67
|
-
if (window && 'ResizeObserver' in window) {
|
|
68
|
-
observer = new ResizeObserver(callback);
|
|
69
|
-
elements.forEach((element) => {
|
|
70
|
-
element && observer!.observe(element, observerOptions);
|
|
71
|
-
});
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
{ immediate: true, flush: 'post' },
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const stop = () => {
|
|
78
|
-
cleanup();
|
|
79
|
-
stopWatch();
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
tryOnScopeDispose(stop);
|
|
83
|
-
|
|
84
|
-
return { stop };
|
|
85
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
import { ComponentPublicInstance, Ref, unref, getCurrentScope, onScopeDispose } from 'vue';
|
|
3
|
-
import { inBrowser } from '../../utils';
|
|
4
|
-
|
|
5
|
-
export const defaultWindow = inBrowser ? window : undefined;
|
|
6
|
-
|
|
7
|
-
export type MaybeRef<T> = T | Ref<T>;
|
|
8
|
-
export type MaybeRefOrGetter<T> = MaybeRef<T> | (() => T);
|
|
9
|
-
|
|
10
|
-
export type VueInstance = ComponentPublicInstance;
|
|
11
|
-
export type MaybeElementRef<T extends MaybeElement = MaybeElement> = MaybeRef<T>;
|
|
12
|
-
export type MaybeComputedElementRef<T extends MaybeElement = MaybeElement> = MaybeRefOrGetter<T>;
|
|
13
|
-
export type MaybeElement = HTMLElement | SVGElement | VueInstance | undefined | null;
|
|
14
|
-
|
|
15
|
-
export type UnRefElementReturn<T extends MaybeElement = MaybeElement> =
|
|
16
|
-
T extends VueInstance ? Exclude<MaybeElement, VueInstance> : T | undefined;
|
|
17
|
-
|
|
18
|
-
export type AnyFn = (...args: any[]) => any;
|
|
19
|
-
|
|
20
|
-
export function toValue<T>(r: MaybeRefOrGetter<T>): T {
|
|
21
|
-
return typeof r === 'function'
|
|
22
|
-
? (r as AnyFn)()
|
|
23
|
-
: unref(r);
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export function unrefElement<T extends MaybeElement>(elRef: MaybeComputedElementRef<T>): UnRefElementReturn<T> {
|
|
27
|
-
const plain = toValue(elRef);
|
|
28
|
-
return (plain as VueInstance)?.$el ?? plain;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
export function tryOnScopeDispose(fn: (() => void)) {
|
|
32
|
-
if (getCurrentScope()) {
|
|
33
|
-
onScopeDispose(fn);
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
36
|
-
return false;
|
|
37
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import { ref, Ref, onMounted } from 'vue';
|
|
2
|
-
import { inBrowser } from '../../utils';
|
|
3
|
-
|
|
4
|
-
type ScrollElement = HTMLElement | Window;
|
|
5
|
-
|
|
6
|
-
const overflowScrollReg = /scroll|auto|overlay/i;
|
|
7
|
-
const defaultRoot = inBrowser ? window : undefined;
|
|
8
|
-
|
|
9
|
-
function isElement(node: Element) {
|
|
10
|
-
const ELEMENT_NODE_TYPE = 1;
|
|
11
|
-
return (
|
|
12
|
-
node.tagName !== 'HTML' &&
|
|
13
|
-
node.tagName !== 'BODY' &&
|
|
14
|
-
node.nodeType === ELEMENT_NODE_TYPE
|
|
15
|
-
);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export function getScrollParent(el: Element, root: ScrollElement | undefined = defaultRoot) {
|
|
19
|
-
let node = el;
|
|
20
|
-
|
|
21
|
-
while (node && node !== root && isElement(node)) {
|
|
22
|
-
const { overflowY } = window.getComputedStyle(node);
|
|
23
|
-
if (overflowScrollReg.test(overflowY)) {
|
|
24
|
-
return node;
|
|
25
|
-
}
|
|
26
|
-
node = node.parentNode as Element;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return root;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export function useScrollParent(el: Ref<Element | undefined>, root: ScrollElement | undefined = defaultRoot) {
|
|
33
|
-
const scrollParent = ref<Element | Window>();
|
|
34
|
-
|
|
35
|
-
onMounted(() => {
|
|
36
|
-
if (el.value) {
|
|
37
|
-
scrollParent.value = getScrollParent(el.value, root);
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return scrollParent;
|
|
42
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import { ref } from 'vue';
|
|
2
|
-
|
|
3
|
-
export const TAP_OFFSET = 5;
|
|
4
|
-
|
|
5
|
-
type Direction = '' | 'vertical' | 'horizontal';
|
|
6
|
-
|
|
7
|
-
function getDirection(x: number, y: number) {
|
|
8
|
-
if (x > y) {
|
|
9
|
-
return 'horizontal';
|
|
10
|
-
}
|
|
11
|
-
if (y > x) {
|
|
12
|
-
return 'vertical';
|
|
13
|
-
}
|
|
14
|
-
return '';
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
export function useTouch() {
|
|
18
|
-
const startX = ref(0);
|
|
19
|
-
const startY = ref(0);
|
|
20
|
-
const deltaX = ref(0);
|
|
21
|
-
const deltaY = ref(0);
|
|
22
|
-
const offsetX = ref(0);
|
|
23
|
-
const offsetY = ref(0);
|
|
24
|
-
const direction = ref<Direction>('');
|
|
25
|
-
const isTap = ref(true);
|
|
26
|
-
|
|
27
|
-
const isVertical = () => direction.value === 'vertical';
|
|
28
|
-
const isHorizontal = () => direction.value === 'horizontal';
|
|
29
|
-
|
|
30
|
-
const reset = () => {
|
|
31
|
-
deltaX.value = 0;
|
|
32
|
-
deltaY.value = 0;
|
|
33
|
-
offsetX.value = 0;
|
|
34
|
-
offsetY.value = 0;
|
|
35
|
-
direction.value = '';
|
|
36
|
-
isTap.value = true;
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
const start = ((event: TouchEvent) => {
|
|
40
|
-
reset();
|
|
41
|
-
startX.value = event.touches[0].clientX;
|
|
42
|
-
startY.value = event.touches[0].clientY;
|
|
43
|
-
}) as EventListener;
|
|
44
|
-
|
|
45
|
-
const move = ((event: TouchEvent) => {
|
|
46
|
-
const touch = event.touches[0];
|
|
47
|
-
// safari back will set clientX to negative number
|
|
48
|
-
deltaX.value = (touch.clientX < 0 ? 0 : touch.clientX) - startX.value;
|
|
49
|
-
deltaY.value = touch.clientY - startY.value;
|
|
50
|
-
offsetX.value = Math.abs(deltaX.value);
|
|
51
|
-
offsetY.value = Math.abs(deltaY.value);
|
|
52
|
-
|
|
53
|
-
// lock direction when distance is greater than a certain value
|
|
54
|
-
const LOCK_DIRECTION_DISTANCE = 10;
|
|
55
|
-
if (
|
|
56
|
-
!direction.value ||
|
|
57
|
-
(offsetX.value < LOCK_DIRECTION_DISTANCE && offsetY.value < LOCK_DIRECTION_DISTANCE)
|
|
58
|
-
) {
|
|
59
|
-
direction.value = getDirection(offsetX.value, offsetY.value);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if (isTap.value && (offsetX.value > TAP_OFFSET || offsetY.value > TAP_OFFSET)) {
|
|
63
|
-
isTap.value = false;
|
|
64
|
-
}
|
|
65
|
-
}) as EventListener;
|
|
66
|
-
|
|
67
|
-
return {
|
|
68
|
-
move,
|
|
69
|
-
start,
|
|
70
|
-
reset,
|
|
71
|
-
startX,
|
|
72
|
-
startY,
|
|
73
|
-
deltaX,
|
|
74
|
-
deltaY,
|
|
75
|
-
offsetX,
|
|
76
|
-
offsetY,
|
|
77
|
-
direction,
|
|
78
|
-
isVertical,
|
|
79
|
-
isHorizontal,
|
|
80
|
-
isTap
|
|
81
|
-
};
|
|
82
|
-
}
|
|
@@ -1,120 +0,0 @@
|
|
|
1
|
-
import { reactive, ref, Ref } from 'vue';
|
|
2
|
-
import { throttle } from '../../utils';
|
|
3
|
-
import { useEventListener } from '../use-event-listener';
|
|
4
|
-
|
|
5
|
-
const MIN_DISTANCE = 10;
|
|
6
|
-
|
|
7
|
-
type TouchDirection = 'horizontal' | 'vertical' | '';
|
|
8
|
-
|
|
9
|
-
export type TouchOffset = {
|
|
10
|
-
startX: number;
|
|
11
|
-
startY: number;
|
|
12
|
-
endX: number;
|
|
13
|
-
endY: number;
|
|
14
|
-
offsetX: number;
|
|
15
|
-
offsetY: number;
|
|
16
|
-
direction: TouchDirection;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
type TouchListener = {
|
|
20
|
-
onTouchStart?: (event: Event) => void;
|
|
21
|
-
onTouchMove?: (event: Event) => void;
|
|
22
|
-
onTouchEnd?: (event: Event) => void;
|
|
23
|
-
onTouchCancel?: (event: Event) => void;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
function getDirection(x: number, y: number): TouchDirection {
|
|
27
|
-
if (x > y && x > MIN_DISTANCE) {
|
|
28
|
-
return 'horizontal';
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (y > x && y > MIN_DISTANCE) {
|
|
32
|
-
return 'vertical';
|
|
33
|
-
}
|
|
34
|
-
return '';
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
const defaultTouchOffset: () => TouchOffset = () => {
|
|
38
|
-
return {
|
|
39
|
-
startX: 0,
|
|
40
|
-
startY: 0,
|
|
41
|
-
endX: 0,
|
|
42
|
-
endY: 0,
|
|
43
|
-
offsetX: 0,
|
|
44
|
-
offsetY: 0,
|
|
45
|
-
direction: ''
|
|
46
|
-
};
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
export enum DragStatus {
|
|
50
|
-
NotStarted,
|
|
51
|
-
Started,
|
|
52
|
-
Dragging,
|
|
53
|
-
End
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export function useTouchMove(
|
|
57
|
-
target: Ref<EventTarget | undefined>,
|
|
58
|
-
listener?: TouchListener,
|
|
59
|
-
wait = 0
|
|
60
|
-
) {
|
|
61
|
-
let beginOffset = { offsetX: 0, offsetY: 0 };
|
|
62
|
-
const offset: TouchOffset = reactive(defaultTouchOffset());
|
|
63
|
-
const dragStatus = ref(DragStatus.NotStarted);
|
|
64
|
-
|
|
65
|
-
const touchStart = (event: any) => {
|
|
66
|
-
if (!event.touches || !event.touches[0]) {
|
|
67
|
-
return;
|
|
68
|
-
}
|
|
69
|
-
offset.startX = event.touches[0].clientX;
|
|
70
|
-
offset.startY = event.touches[0].clientY;
|
|
71
|
-
listener?.onTouchStart && listener.onTouchStart(event);
|
|
72
|
-
dragStatus.value = DragStatus.Started;
|
|
73
|
-
};
|
|
74
|
-
|
|
75
|
-
const touchMove = (event: any) => {
|
|
76
|
-
if (!event.touches || !event.touches[0]) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const touch = event.touches[0];
|
|
80
|
-
offset.offsetX = touch.clientX - offset.startX + beginOffset.offsetX;
|
|
81
|
-
offset.offsetY = touch.clientY - offset.startY + beginOffset.offsetY;
|
|
82
|
-
offset.endX = event.touches[0].clientX;
|
|
83
|
-
offset.endY = event.touches[0].clientY;
|
|
84
|
-
offset.direction = getDirection(offset.offsetX, offset.offsetY);
|
|
85
|
-
listener?.onTouchMove && listener.onTouchMove(event);
|
|
86
|
-
dragStatus.value = DragStatus.Dragging;
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const touchEnd = (event: Event) => {
|
|
90
|
-
beginOffset = { offsetX: offset.offsetX, offsetY: offset.offsetY };
|
|
91
|
-
listener?.onTouchEnd && listener.onTouchEnd(event);
|
|
92
|
-
listener?.onTouchCancel && listener.onTouchCancel(event);
|
|
93
|
-
dragStatus.value = DragStatus.End;
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
const resetTouchStatus = () => {
|
|
97
|
-
offset.endX = 0;
|
|
98
|
-
offset.endY = 0;
|
|
99
|
-
offset.offsetX = 0;
|
|
100
|
-
offset.offsetY = 0;
|
|
101
|
-
offset.direction = '';
|
|
102
|
-
beginOffset = { offsetX: 0, offsetY: 0 };
|
|
103
|
-
dragStatus.value = DragStatus.NotStarted;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
if (target) {
|
|
107
|
-
useEventListener('touchstart', touchStart, { target });
|
|
108
|
-
useEventListener('touchmove', wait > 0 ? throttle(touchMove, wait) : touchMove, {
|
|
109
|
-
target,
|
|
110
|
-
passive: false
|
|
111
|
-
});
|
|
112
|
-
useEventListener('touchend', touchEnd, { target });
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return {
|
|
116
|
-
offset,
|
|
117
|
-
dragStatus,
|
|
118
|
-
resetTouchStatus
|
|
119
|
-
};
|
|
120
|
-
}
|
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
import { DesignerComponentInstance, DgControl } from "@/components/designer-canvas";
|
|
2
|
-
import { cloneDeep } from "lodash-es";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 控件属性基类
|
|
6
|
-
*/
|
|
7
|
-
export class BaseControlProperty {
|
|
8
|
-
public componentId: string;
|
|
9
|
-
|
|
10
|
-
public viewModelId: string;
|
|
11
|
-
|
|
12
|
-
public eventsEditorUtils: any;
|
|
13
|
-
|
|
14
|
-
public formSchemaUtils: any;
|
|
15
|
-
public formMetadataConverter: any;
|
|
16
|
-
public designViewModelUtils: any;
|
|
17
|
-
public designViewModelField: any;
|
|
18
|
-
public controlCreatorUtils: any;
|
|
19
|
-
public designerHostService: any;
|
|
20
|
-
|
|
21
|
-
schemaService: any = null;
|
|
22
|
-
|
|
23
|
-
metadataService: any = null;
|
|
24
|
-
|
|
25
|
-
protected propertyConfig = {
|
|
26
|
-
type: 'object',
|
|
27
|
-
categories: {}
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
constructor(componentId: string, designerHostService: any) {
|
|
31
|
-
this.componentId = componentId;
|
|
32
|
-
this.designerHostService = designerHostService;
|
|
33
|
-
this.eventsEditorUtils = designerHostService['eventsEditorUtils'];
|
|
34
|
-
this.formSchemaUtils = designerHostService['formSchemaUtils'];
|
|
35
|
-
this.formMetadataConverter = designerHostService['formMetadataConverter'];
|
|
36
|
-
this.viewModelId = this.formSchemaUtils?.getViewModelIdByComponentId(componentId) || '';
|
|
37
|
-
this.designViewModelUtils = designerHostService['designViewModelUtils'];
|
|
38
|
-
this.controlCreatorUtils = designerHostService['controlCreatorUtils'];
|
|
39
|
-
this.metadataService = designerHostService['metadataService'];
|
|
40
|
-
this.schemaService = designerHostService['schemaService'];
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
getTableInfo() {
|
|
44
|
-
return this.schemaService?.getTableInfoByViewModelId(this.viewModelId);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
setDesignViewModelField(propertyData: any) {
|
|
48
|
-
const bindingFieldId = propertyData.binding && propertyData.binding.type === 'Form' && propertyData.binding.field;
|
|
49
|
-
// 视图模型中[字段更新时机]属性现在要在控件上维护,所以在控件上复制一份属性值
|
|
50
|
-
if (bindingFieldId) {
|
|
51
|
-
if (!this.designViewModelField) {
|
|
52
|
-
const dgViewModel = this.designViewModelUtils.getDgViewModel(this.viewModelId);
|
|
53
|
-
this.designViewModelField = dgViewModel.fields.find(f => f.id === bindingFieldId);
|
|
54
|
-
}
|
|
55
|
-
propertyData.updateOn = this.designViewModelField?.updateOn;
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
getBasicPropConfig(propertyData: any): any {
|
|
60
|
-
return {
|
|
61
|
-
description: 'Basic Information',
|
|
62
|
-
title: '基本信息',
|
|
63
|
-
properties: {
|
|
64
|
-
id: {
|
|
65
|
-
description: '组件标识',
|
|
66
|
-
title: '标识',
|
|
67
|
-
type: 'string',
|
|
68
|
-
readonly: true
|
|
69
|
-
},
|
|
70
|
-
type: {
|
|
71
|
-
description: '组件类型',
|
|
72
|
-
title: '控件类型',
|
|
73
|
-
type: 'select',
|
|
74
|
-
editor: {
|
|
75
|
-
type: 'combo-list',
|
|
76
|
-
textField: 'name',
|
|
77
|
-
valueField: 'value',
|
|
78
|
-
editable: false,
|
|
79
|
-
data: [{ value: propertyData.type, name: DgControl[propertyData.type] && DgControl[propertyData.type].name }]
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
protected getAppearanceConfig(propertyData = null): any {
|
|
89
|
-
return {
|
|
90
|
-
title: "外观",
|
|
91
|
-
description: "Appearance",
|
|
92
|
-
properties: {
|
|
93
|
-
class: {
|
|
94
|
-
title: "class样式",
|
|
95
|
-
type: "string",
|
|
96
|
-
description: "组件的CSS样式",
|
|
97
|
-
$converter: "/converter/appearance.converter"
|
|
98
|
-
},
|
|
99
|
-
style: {
|
|
100
|
-
title: "style样式",
|
|
101
|
-
type: "string",
|
|
102
|
-
description: "组件的样式",
|
|
103
|
-
$converter: "/converter/appearance.converter"
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
/**
|
|
110
|
-
*
|
|
111
|
-
* @param propertyId
|
|
112
|
-
* @param componentInstance
|
|
113
|
-
* @returns
|
|
114
|
-
*/
|
|
115
|
-
public updateElementByParentContainer(propertyId: string, componentInstance: DesignerComponentInstance) {
|
|
116
|
-
// 1、定位控件父容器
|
|
117
|
-
const parentContainer = componentInstance && componentInstance.parent && componentInstance.parent['schema'];
|
|
118
|
-
if (!parentContainer) {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
const index = parentContainer.contents.findIndex(c => c.id === propertyId);
|
|
122
|
-
// 通过cloneDeep方式的触发更新
|
|
123
|
-
const controlSchema = cloneDeep(parentContainer.contents[index]);
|
|
124
|
-
// 5、替换控件
|
|
125
|
-
parentContainer.contents.splice(index, 1);
|
|
126
|
-
parentContainer.contents.splice(index, 0, controlSchema);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
}
|