@mlightcad/ui-components 0.0.8 → 0.0.10

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.
Files changed (35) hide show
  1. package/README.md +21 -3
  2. package/dist/ui-components.es.js +416 -318
  3. package/dist/ui-components.umd.js +2 -2
  4. package/lib/index.d.ts +2 -1
  5. package/lib/index.js +3 -1
  6. package/package.json +1 -1
  7. package/src/components/MlCollapse.vue +11 -5
  8. package/src/components/MlStatusBar.vue +43 -0
  9. package/src/components/MlToolPalette.vue +41 -30
  10. package/src/{composable → composables}/types.ts +10 -0
  11. package/src/composables/useAutoOpen.ts +77 -0
  12. package/src/composables/useBoundingRect.ts +161 -0
  13. package/src/composables/useDrag.ts +176 -0
  14. package/src/{composable → composables}/useDragEx.ts +16 -6
  15. package/src/{composable → composables}/useInitialRect.ts +13 -13
  16. package/src/composables/useLastPosAndSize.ts +43 -0
  17. package/src/composables/useLeftPosAndWidth.ts +47 -0
  18. package/src/{composable → composables}/useResize.ts +36 -28
  19. package/src/{composable → composables}/useTransition.ts +31 -24
  20. package/src/index.ts +10 -1
  21. package/lib/MlDropdown.vue.d.ts +0 -59
  22. package/lib/MlDropdown.vue.js +0 -106
  23. package/lib/MlLanguage.vue.d.ts +0 -29
  24. package/lib/MlLanguage.vue.js +0 -67
  25. package/lib/MlToolPalette.vue.d.ts +0 -2
  26. package/lib/MlToolPalette.vue.js +0 -149
  27. package/lib/MlToolbar.vue.d.ts +0 -74
  28. package/lib/MlToolbar.vue.js +0 -129
  29. package/src/composable/useBoundingRect.ts +0 -87
  30. package/src/composable/useDrag.ts +0 -157
  31. package/src/composable/useRect.ts +0 -23
  32. /package/src/{composable → composables}/useWindowSize.ts +0 -0
  33. /package/src/{svg → svgs}/arrow-left.svg +0 -0
  34. /package/src/{svg → svgs}/arrow-right.svg +0 -0
  35. /package/src/{svg → svgs}/svg.d.ts +0 -0
@@ -1,157 +0,0 @@
1
- import {
2
- computed,
3
- nextTick,
4
- onMounted,
5
- onUnmounted,
6
- Ref,
7
- ref,
8
- watch
9
- } from 'vue'
10
-
11
- import { Position } from './types'
12
-
13
- /**
14
- * Options to use `useDrag`
15
- */
16
- export interface DragOptions {
17
- /**
18
- * The minimum distance from the left border of the element to the left border of the window
19
- */
20
- leftGap: number
21
- /**
22
- * The minimum distance from the right border of the element to the right border of the window
23
- */
24
- rightGap: number
25
- /**
26
- * The container HTML element. Its left and top attributes will be modified when mouse is moving.
27
- */
28
- container: HTMLElement | null
29
- }
30
-
31
- /**
32
- * Drag `targetRef` element to move it
33
- * @param targetRef Input element to drag
34
- * @param options Input dragging options to customize dragging behaviors
35
- * @returns Return thefollowing data
36
- * - isDragging: flag to indicate whether the element is in dragging state
37
- * - movement: movement based on the original position of the element
38
- * - position: new left and top position of the element after dragged
39
- */
40
- export function useDrag(
41
- targetRef: Ref<HTMLElement | null>,
42
- options?: Ref<DragOptions>
43
- ) {
44
- const isDragging = ref(false)
45
- const position = ref<Position>({ x: 0, y: 0 })
46
- const initialPosition = ref<Position>({ x: 0, y: 0 }) // Initial CSS position
47
- const movement = computed(() => {
48
- return {
49
- x: position.value.x - initialPosition.value.x,
50
- y: position.value.y - initialPosition.value.y
51
- }
52
- })
53
-
54
- const setInitialPosition = () => {
55
- if (targetRef.value) {
56
- const rect = targetRef.value.getBoundingClientRect()
57
- initialPosition.value.x = rect.left
58
- initialPosition.value.y = rect.top
59
- position.value.x = rect.left
60
- position.value.y = rect.top
61
- }
62
- }
63
-
64
- const addEventListeners = () => {
65
- if (targetRef.value) {
66
- targetRef.value.addEventListener('mousedown', onMouseDown)
67
- }
68
- }
69
-
70
- const removeEventListeners = () => {
71
- if (targetRef.value) {
72
- targetRef.value.removeEventListener('mousedown', onMouseDown)
73
- }
74
- }
75
-
76
- const onMouseDown = () => {
77
- isDragging.value = true
78
- document.addEventListener('mousemove', onMouseMove)
79
- document.addEventListener('mouseup', onMouseUp)
80
- }
81
-
82
- const onMouseMove = (e: MouseEvent) => {
83
- if (isDragging.value) {
84
- const viewportWidth = window.innerWidth
85
- const viewportHeight = window.innerHeight
86
- const element = targetRef.value as HTMLElement
87
- const elementWidth = element.offsetWidth
88
- const elementHeight = element.offsetHeight
89
-
90
- const newX = position.value.x + e.movementX
91
- const newY = position.value.y + e.movementY
92
-
93
- position.value.x = Math.max(
94
- options ? options.value.leftGap : 0,
95
- Math.min(newX, viewportWidth - elementWidth)
96
- )
97
- const containerWidth = options && options.value.container ? options.value.container.clientWidth : 0
98
- const distanceToRightBorder = viewportWidth - containerWidth - elementWidth
99
- position.value.x = Math.min(
100
- options ? (distanceToRightBorder - options.value.rightGap) : distanceToRightBorder,
101
- position.value.x
102
- )
103
- position.value.y = Math.max(
104
- 0,
105
- Math.min(newY, viewportHeight - elementHeight)
106
- )
107
-
108
- // Update values of left and top attributes of container element
109
- if (options?.value.container) {
110
- const container = options?.value.container
111
- // const rect = container.getBoundingClientRect()
112
- container.style.left = position.value.x + 'px'
113
- container.style.top = position.value.y + 'px'
114
- }
115
- }
116
- }
117
-
118
- const onMouseUp = () => {
119
- isDragging.value = false
120
- document.removeEventListener('mousemove', onMouseMove)
121
- document.removeEventListener('mouseup', onMouseUp)
122
- }
123
-
124
- onMounted(() => {
125
- if (targetRef.value) {
126
- nextTick(() => {
127
- setInitialPosition() // Set initial position from CSS
128
- addEventListeners()
129
- })
130
- }
131
- })
132
-
133
- onUnmounted(() => {
134
- if (targetRef.value) {
135
- setInitialPosition() // Re-calculate the position when the component becomes visible
136
- targetRef.value.removeEventListener('mousedown', onMouseDown)
137
- }
138
- })
139
-
140
- // Watch for changes in the targetRef, to handle cases where v-if makes the element appear/disappear
141
- watch(targetRef, newVal => {
142
- if (newVal) {
143
- nextTick(() => {
144
- setInitialPosition() // Set initial position from CSS
145
- addEventListeners()
146
- })
147
- } else {
148
- removeEventListeners()
149
- }
150
- })
151
-
152
- return {
153
- isDragging,
154
- movement,
155
- position
156
- }
157
- }
@@ -1,23 +0,0 @@
1
- import { computed, Ref, ref } from 'vue'
2
-
3
- import { Rect } from './types'
4
- import { useInitialRect } from './useInitialRect'
5
-
6
- /**
7
- * Get the bounding rect of the specified element.
8
- * - If it is the first time to show this element, return the initial size and position from CSS
9
- * - Otherwise, return the last size and postion when the element is closed
10
- * @param targetRef Input element to get its bounding rect
11
- * @returns Return the bounding rect of the element
12
- */
13
- export function useRect(targetRef: Ref<HTMLElement | null>) {
14
- const { initialRect } = useInitialRect(targetRef)
15
- // The last size and postion when the `targetRef` disappears
16
- const lastRect = ref<Rect | null>(null)
17
-
18
- const rect = computed(() => {
19
- return lastRect.value ? lastRect.value : initialRect.value
20
- })
21
-
22
- return { rect }
23
- }
File without changes
File without changes
File without changes