@scx-js/scx-ui 0.0.1 → 0.0.2

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/index.js CHANGED
@@ -1,44 +1,44 @@
1
- export * from "./scx-context-menu/index.js";
2
- export * from "./scx-drag/index.js";
3
-
4
- import ScxGroup from "./scx-group/index.vue";
5
- import ScxIcon from "./scx-icon/index.vue";
6
- import ScxInput from "./scx-input/index.vue";
7
- import ScxPanel from "./scx-panel/index.vue";
8
- import ScxPanelItem from "./scx-panel/scx-panel-item.vue";
9
- import ScxProgress from "./scx-progress/index.vue";
10
- import ScxSwitch from "./scx-switch/index.vue";
11
- import ScxUpload from "./scx-upload/index.vue";
12
- import ScxUploadList from "./scx-upload-list/index.vue";
13
- import {ScxContextMenuDirective} from "./scx-context-menu/index.js";
14
- import {ScxDragDirective} from "./scx-drag/index.js";
15
-
16
- //以下为组件
17
- const components = [ScxGroup, ScxIcon, ScxInput, ScxPanel, ScxPanelItem, ScxProgress, ScxSwitch, ScxUpload, ScxUploadList];
18
-
19
- //以下为指令
20
- const directives = [ScxContextMenuDirective, ScxDragDirective];
21
-
22
- const ScxComponent = {
23
- install: (app) => {
24
- //安装组件
25
- components.forEach(c => app.component(c.name, c));
26
- //安装指令
27
- directives.forEach(d => app.directive(d.name, d));
28
- },
29
- };
30
-
31
- export {
32
- ScxGroup,
33
- ScxIcon,
34
- ScxInput,
35
- ScxPanel,
36
- ScxPanelItem,
37
- ScxProgress,
38
- ScxSwitch,
39
- ScxUpload,
40
- ScxUploadList,
41
- ScxContextMenuDirective,
42
- ScxDragDirective,
43
- ScxComponent,
44
- };
1
+ export * from "./scx-context-menu/index.js";
2
+ export * from "./scx-drag/index.js";
3
+
4
+ import ScxGroup from "./scx-group/index.vue";
5
+ import ScxIcon from "./scx-icon/index.vue";
6
+ import ScxInput from "./scx-input/index.vue";
7
+ import ScxPanel from "./scx-panel/index.vue";
8
+ import ScxPanelItem from "./scx-panel/scx-panel-item.vue";
9
+ import ScxProgress from "./scx-progress/index.vue";
10
+ import ScxSwitch from "./scx-switch/index.vue";
11
+ import ScxUpload from "./scx-upload/index.vue";
12
+ import ScxUploadList from "./scx-upload-list/index.vue";
13
+ import {ScxContextMenuDirective} from "./scx-context-menu/index.js";
14
+ import {ScxDragDirective} from "./scx-drag/index.js";
15
+
16
+ //以下为组件
17
+ const components = [ScxGroup, ScxIcon, ScxInput, ScxPanel, ScxPanelItem, ScxProgress, ScxSwitch, ScxUpload, ScxUploadList];
18
+
19
+ //以下为指令
20
+ const directives = [ScxContextMenuDirective, ScxDragDirective];
21
+
22
+ const ScxComponent = {
23
+ install: (app) => {
24
+ //安装组件
25
+ components.forEach(c => app.component(c.name, c));
26
+ //安装指令
27
+ directives.forEach(d => app.directive(d.name, d));
28
+ },
29
+ };
30
+
31
+ export {
32
+ ScxGroup,
33
+ ScxIcon,
34
+ ScxInput,
35
+ ScxPanel,
36
+ ScxPanelItem,
37
+ ScxProgress,
38
+ ScxSwitch,
39
+ ScxUpload,
40
+ ScxUploadList,
41
+ ScxContextMenuDirective,
42
+ ScxDragDirective,
43
+ ScxComponent,
44
+ };
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "@scx-js/scx-ui",
3
- "version": "0.0.1",
4
- "description": "SCX UI",
5
- "license": "MIT",
6
- "author": "scx567888",
7
- "main": "index.js",
8
- "type": "module",
9
- "scripts": {
10
- "dev:test": "vite _test --host",
11
- "build:test": "vite build _test",
12
- "preview:test": "vite preview _test --host"
13
- },
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/scx567888/scx-js.git"
17
- },
18
- "dependencies": {
19
- "@scx-js/scx-common": "0.0.1",
20
- "@scx-js/scx-app-x": "0.0.1",
21
- "@scx-js/scx-dom": "0.0.1"
22
- },
23
- "devDependencies": {
24
- "@vitejs/plugin-vue": "^5.0.0",
25
- "clipboard": "^2.0.0",
26
- "vite": "^6.0.0",
27
- "vue-router": "^4.0.0"
28
- }
29
- }
1
+ {
2
+ "name": "@scx-js/scx-ui",
3
+ "version": "0.0.2",
4
+ "description": "SCX UI",
5
+ "license": "MIT",
6
+ "author": "scx567888",
7
+ "main": "index.js",
8
+ "type": "module",
9
+ "scripts": {
10
+ "dev:test": "vite _test --host",
11
+ "build:test": "vite build _test",
12
+ "preview:test": "vite preview _test --host"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/scx567888/scx-js.git"
17
+ },
18
+ "dependencies": {
19
+ "@scx-js/scx-common": "0.0.2",
20
+ "@scx-js/scx-app-x": "0.0.2",
21
+ "@scx-js/scx-dom": "0.0.2"
22
+ },
23
+ "devDependencies": {
24
+ "@vitejs/plugin-vue": "^5.0.0",
25
+ "clipboard": "^2.0.0",
26
+ "vite": "^6.0.0",
27
+ "vue-router": "^4.0.0"
28
+ }
29
+ }
@@ -1,51 +1,51 @@
1
- /*全局右键菜单*/
2
- .scx-context-menu {
3
- margin: 0;
4
- background: var(--scx-glass-bg);
5
- z-index: 3000;
6
- position: absolute;
7
- list-style-type: none;
8
- padding: 3px;
9
- border-radius: 2px;
10
- font-size: 12px;
11
- font-weight: 400;
12
- box-shadow: var(--scx-box-shadow);
13
- max-height: 500px;
14
- overflow: auto;
15
- backdrop-filter: var(--scx-glass-bg-filter);
16
- box-sizing: border-box;
17
- width: max-content;
18
- }
19
-
20
- @keyframes from-top {
21
- 0% {
22
- opacity: 0;
23
- transform: translateY(-10px);
24
- }
25
- }
26
-
27
- @keyframes from-bottom {
28
- 0% {
29
- opacity: 0;
30
- transform: translateY(10px);
31
- }
32
- }
33
-
34
- .scx-context-menu.top {
35
- animation: from-top 200ms cubic-bezier(.23, 1, .32, 1);
36
- }
37
-
38
- .scx-context-menu.bottom {
39
- animation: from-bottom 200ms cubic-bezier(.23, 1, .32, 1);
40
- }
41
-
42
- .scx-context-menu-item {
43
- margin: 0;
44
- padding: 7px 16px;
45
- cursor: pointer;
46
- }
47
-
48
- .scx-context-menu-item:hover {
49
- background: var(--scx-theme);
50
- color: var(--scx-bg);
1
+ /*全局右键菜单*/
2
+ .scx-context-menu {
3
+ margin: 0;
4
+ background: var(--scx-glass-bg);
5
+ z-index: 3000;
6
+ position: absolute;
7
+ list-style-type: none;
8
+ padding: 3px;
9
+ border-radius: 2px;
10
+ font-size: 12px;
11
+ font-weight: 400;
12
+ box-shadow: var(--scx-box-shadow);
13
+ max-height: 500px;
14
+ overflow: auto;
15
+ backdrop-filter: var(--scx-glass-bg-filter);
16
+ box-sizing: border-box;
17
+ width: max-content;
18
+ }
19
+
20
+ @keyframes from-top {
21
+ 0% {
22
+ opacity: 0;
23
+ transform: translateY(-10px);
24
+ }
25
+ }
26
+
27
+ @keyframes from-bottom {
28
+ 0% {
29
+ opacity: 0;
30
+ transform: translateY(10px);
31
+ }
32
+ }
33
+
34
+ .scx-context-menu.top {
35
+ animation: from-top 200ms cubic-bezier(.23, 1, .32, 1);
36
+ }
37
+
38
+ .scx-context-menu.bottom {
39
+ animation: from-bottom 200ms cubic-bezier(.23, 1, .32, 1);
40
+ }
41
+
42
+ .scx-context-menu-item {
43
+ margin: 0;
44
+ padding: 7px 16px;
45
+ cursor: pointer;
46
+ }
47
+
48
+ .scx-context-menu-item:hover {
49
+ background: var(--scx-theme);
50
+ color: var(--scx-bg);
51
51
  }
@@ -1,65 +1,65 @@
1
- import ScxContextMenu from "./index.vue";
2
- import {h, render} from "vue";
3
-
4
- // 这里因为 vite 每次导入时都使用不同的 上下文导致 contextMenuInstance 为空 这里直接绑定到 window 上
5
- // let contextMenuInstance;
6
-
7
- function getInstance() {
8
- return window["__SCX_CONTEXT_MENU_INSTANCE__"];
9
- }
10
-
11
- function setInstance(instance) {
12
- return window["__SCX_CONTEXT_MENU_INSTANCE__"] = instance;
13
- }
14
-
15
- function bodyClick(e) {
16
- let isOnContextmenu = e.target.closest(".scx-context-menu");
17
-
18
- if (!isOnContextmenu && getInstance()) {
19
- closeContextMenu();
20
- }
21
- }
22
-
23
- function showContextMenu(e, value) {
24
- //默认阻止事件冒泡
25
- e.stopPropagation();
26
- const instance = getInstance();
27
- if (instance) {
28
- document.body.removeChild(instance);
29
- }
30
- const container = document.createElement("div");
31
- let vm = h(ScxContextMenu, {
32
- mouseEvent: e,
33
- contextMenuItems: value,
34
- });
35
- render(vm, container);
36
- setInstance(container);
37
- document.body.appendChild(container);
38
- document.body.addEventListener("click", bodyClick);
39
- }
40
-
41
- function closeContextMenu() {
42
- document.body.removeChild(getInstance());
43
- setInstance(null);
44
- document.body.removeEventListener("click", bodyClick);
45
- }
46
-
47
- const ScxContextMenuDirective = {
48
- name: "contextmenu",
49
- //待处理
50
- mounted(el, {value}) {
51
- el.oncontextmenu = (e) => {
52
- showContextMenu(e, value);
53
- return false;
54
- };
55
- },
56
- updated(el, {value}) {
57
-
58
- },
59
- };
60
-
61
- export {
62
- ScxContextMenuDirective,
63
- showContextMenu,
64
- closeContextMenu,
65
- };
1
+ import ScxContextMenu from "./index.vue";
2
+ import {h, render} from "vue";
3
+
4
+ // 这里因为 vite 每次导入时都使用不同的 上下文导致 contextMenuInstance 为空 这里直接绑定到 window 上
5
+ // let contextMenuInstance;
6
+
7
+ function getInstance() {
8
+ return window["__SCX_CONTEXT_MENU_INSTANCE__"];
9
+ }
10
+
11
+ function setInstance(instance) {
12
+ return window["__SCX_CONTEXT_MENU_INSTANCE__"] = instance;
13
+ }
14
+
15
+ function bodyClick(e) {
16
+ let isOnContextmenu = e.target.closest(".scx-context-menu");
17
+
18
+ if (!isOnContextmenu && getInstance()) {
19
+ closeContextMenu();
20
+ }
21
+ }
22
+
23
+ function showContextMenu(e, value) {
24
+ //默认阻止事件冒泡
25
+ e.stopPropagation();
26
+ const instance = getInstance();
27
+ if (instance) {
28
+ document.body.removeChild(instance);
29
+ }
30
+ const container = document.createElement("div");
31
+ let vm = h(ScxContextMenu, {
32
+ mouseEvent: e,
33
+ contextMenuItems: value,
34
+ });
35
+ render(vm, container);
36
+ setInstance(container);
37
+ document.body.appendChild(container);
38
+ document.body.addEventListener("click", bodyClick);
39
+ }
40
+
41
+ function closeContextMenu() {
42
+ document.body.removeChild(getInstance());
43
+ setInstance(null);
44
+ document.body.removeEventListener("click", bodyClick);
45
+ }
46
+
47
+ const ScxContextMenuDirective = {
48
+ name: "contextmenu",
49
+ //待处理
50
+ mounted(el, {value}) {
51
+ el.oncontextmenu = (e) => {
52
+ showContextMenu(e, value);
53
+ return false;
54
+ };
55
+ },
56
+ updated(el, {value}) {
57
+
58
+ },
59
+ };
60
+
61
+ export {
62
+ ScxContextMenuDirective,
63
+ showContextMenu,
64
+ closeContextMenu,
65
+ };
@@ -1,86 +1,86 @@
1
- <template>
2
- <div ref="scxContextMenuRef" class="scx-context-menu" @contextmenu.prevent="">
3
- <div v-for="item in contextMenuItems" class="scx-context-menu-item" @click="callItemCallBack(item)">
4
- <component :is="renderLabel(item)"></component>
5
- </div>
6
- </div>
7
- </template>
8
-
9
- <script>
10
- //todo 多级菜单 ?
11
- import "./index.css";
12
- import {nextTick, onMounted, ref} from "vue";
13
- import {closeContextMenu} from "./index.js";
14
- import {isFunction} from "../../scx-common/index.js";
15
-
16
- export default {
17
- name: "scx-context-menu",
18
- props: {
19
- mouseEvent: MouseEvent,
20
- contextMenuItems: Array
21
- },
22
- setup(props, context) {
23
- const scxContextMenuRef = ref(null);
24
-
25
- //设置初始状态 保证元素可以正确的获取的内容大小以便后续计算
26
- function initStatus() {
27
- scxContextMenuRef.value.style.top = 0;
28
- scxContextMenuRef.value.style.left = 0;
29
- scxContextMenuRef.value.style.visibility = "hidden";
30
- }
31
-
32
- function setStatus(top, left, type) {
33
- scxContextMenuRef.value.classList.add(type);
34
- scxContextMenuRef.value.style.top = top + "px";
35
- scxContextMenuRef.value.style.left = left + "px";
36
- scxContextMenuRef.value.style.visibility = "unset";
37
- }
38
-
39
- function show(mouseEvent) {
40
- initStatus();
41
- //todo 或者用 clientX ?
42
- let x = mouseEvent.pageX;
43
- let y = mouseEvent.pageY;
44
- const clientWidth = window.innerWidth;
45
- const clientHeight = window.innerHeight;
46
- nextTick(() => {
47
- const {
48
- width,
49
- height
50
- } = scxContextMenuRef.value.getBoundingClientRect();
51
- //todo 这里还可以做优化 以保证 菜单展示不下的时候出现滚动条 通过设置 height 和 width 实现
52
- const top = clientHeight > height + y ? y : y - height;
53
- const type = clientHeight > height + y ? "top" : "bottom";
54
- const left = clientWidth > width + x ? x : x - width;
55
- setStatus(top, left, type);
56
- });
57
- }
58
-
59
- function callItemCallBack(item) {
60
- if (item.callback) {
61
- item.callback(closeContextMenu);
62
- } else {
63
- closeContextMenu();
64
- }
65
- }
66
-
67
- function renderLabel(c) {
68
- const {label} = c;
69
- if (isFunction(label)) {
70
- return label;
71
- } else {
72
- return () => label;
73
- }
74
- }
75
-
76
- onMounted(() => show(props.mouseEvent));
77
-
78
- return {
79
- scxContextMenuRef,
80
- callItemCallBack,
81
- renderLabel
82
- };
83
- }
84
-
85
- };
86
- </script>
1
+ <template>
2
+ <div ref="scxContextMenuRef" class="scx-context-menu" @contextmenu.prevent="">
3
+ <div v-for="item in contextMenuItems" class="scx-context-menu-item" @click="callItemCallBack(item)">
4
+ <component :is="renderLabel(item)"></component>
5
+ </div>
6
+ </div>
7
+ </template>
8
+
9
+ <script>
10
+ //todo 多级菜单 ?
11
+ import "./index.css";
12
+ import {nextTick, onMounted, ref} from "vue";
13
+ import {closeContextMenu} from "./index.js";
14
+ import {isFunction} from "../../scx-common/index.js";
15
+
16
+ export default {
17
+ name: "scx-context-menu",
18
+ props: {
19
+ mouseEvent: MouseEvent,
20
+ contextMenuItems: Array
21
+ },
22
+ setup(props, context) {
23
+ const scxContextMenuRef = ref(null);
24
+
25
+ //设置初始状态 保证元素可以正确的获取的内容大小以便后续计算
26
+ function initStatus() {
27
+ scxContextMenuRef.value.style.top = 0;
28
+ scxContextMenuRef.value.style.left = 0;
29
+ scxContextMenuRef.value.style.visibility = "hidden";
30
+ }
31
+
32
+ function setStatus(top, left, type) {
33
+ scxContextMenuRef.value.classList.add(type);
34
+ scxContextMenuRef.value.style.top = top + "px";
35
+ scxContextMenuRef.value.style.left = left + "px";
36
+ scxContextMenuRef.value.style.visibility = "unset";
37
+ }
38
+
39
+ function show(mouseEvent) {
40
+ initStatus();
41
+ //todo 或者用 clientX ?
42
+ let x = mouseEvent.pageX;
43
+ let y = mouseEvent.pageY;
44
+ const clientWidth = window.innerWidth;
45
+ const clientHeight = window.innerHeight;
46
+ nextTick(() => {
47
+ const {
48
+ width,
49
+ height
50
+ } = scxContextMenuRef.value.getBoundingClientRect();
51
+ //todo 这里还可以做优化 以保证 菜单展示不下的时候出现滚动条 通过设置 height 和 width 实现
52
+ const top = clientHeight > height + y ? y : y - height;
53
+ const type = clientHeight > height + y ? "top" : "bottom";
54
+ const left = clientWidth > width + x ? x : x - width;
55
+ setStatus(top, left, type);
56
+ });
57
+ }
58
+
59
+ function callItemCallBack(item) {
60
+ if (item.callback) {
61
+ item.callback(closeContextMenu);
62
+ } else {
63
+ closeContextMenu();
64
+ }
65
+ }
66
+
67
+ function renderLabel(c) {
68
+ const {label} = c;
69
+ if (isFunction(label)) {
70
+ return label;
71
+ } else {
72
+ return () => label;
73
+ }
74
+ }
75
+
76
+ onMounted(() => show(props.mouseEvent));
77
+
78
+ return {
79
+ scxContextMenuRef,
80
+ callItemCallBack,
81
+ renderLabel
82
+ };
83
+ }
84
+
85
+ };
86
+ </script>
package/scx-drag/index.js CHANGED
@@ -1,30 +1,30 @@
1
- import {onBeforeUnmount} from "vue";
2
- import {ScxDrag} from "@scx-js/scx-dom";
3
-
4
- /**
5
- *
6
- * @param targetElement
7
- * @param options {{dragElement, callback, bounds}}}
8
- * @return {ScxDrag}
9
- */
10
- function useScxDrag(targetElement, options = {}) {
11
- const scxDrag = new ScxDrag(targetElement, options);
12
- scxDrag.enable();
13
- onBeforeUnmount(() => scxDrag.disable());
14
- return scxDrag;
15
- }
16
-
17
- const ScxDragDirective = {
18
- name: "drag",
19
- mounted(el, {value}) {
20
- useScxDrag(el, value);
21
- },
22
- updated(el, {value}) {
23
-
24
- },
25
- };
26
-
27
- export {
28
- useScxDrag,
29
- ScxDragDirective,
30
- };
1
+ import {onBeforeUnmount} from "vue";
2
+ import {ScxDrag} from "@scx-js/scx-dom";
3
+
4
+ /**
5
+ *
6
+ * @param targetElement
7
+ * @param options {{dragElement, callback, bounds}}}
8
+ * @return {ScxDrag}
9
+ */
10
+ function useScxDrag(targetElement, options = {}) {
11
+ const scxDrag = new ScxDrag(targetElement, options);
12
+ scxDrag.enable();
13
+ onBeforeUnmount(() => scxDrag.disable());
14
+ return scxDrag;
15
+ }
16
+
17
+ const ScxDragDirective = {
18
+ name: "drag",
19
+ mounted(el, {value}) {
20
+ useScxDrag(el, value);
21
+ },
22
+ updated(el, {value}) {
23
+
24
+ },
25
+ };
26
+
27
+ export {
28
+ useScxDrag,
29
+ ScxDragDirective,
30
+ };