@94ai/nf-resizable-panels 3.1.37 → 3.1.38

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.
@@ -0,0 +1,2 @@
1
+ export const presudos = ['', 'webkit', 'moz'];
2
+ export const CHILD_DATA_ATTR_NAME = 'resiable-panel-child';
@@ -0,0 +1,8 @@
1
+ import NfResizablePanels from './nf-resizable-panels.vue'
2
+ import { Vue2, PluginObject } from 'vue-demi'
3
+
4
+ NfResizablePanels.install = (app: typeof Vue2) => {
5
+ app!.component('nf-resizable-panels', NfResizablePanels)
6
+ }
7
+
8
+ export default NfResizablePanels as typeof NfResizablePanels & PluginObject<undefined>
@@ -0,0 +1,177 @@
1
+ <script lang="tsx">
2
+ import {
3
+ computed,
4
+ defineComponent,
5
+ PropType,
6
+ ref,
7
+ VNode
8
+ } from 'vue-demi'
9
+ import {
10
+ _getComputedStyle,
11
+ getFlexDirection,
12
+ } from './utils'
13
+ import { CHILD_DATA_ATTR_NAME } from './const'
14
+ import { generateID } from '../../../utils'
15
+
16
+ export default defineComponent({
17
+ name: 'nf-resizable-panels',
18
+ props: {
19
+ /**
20
+ * 指定容器类型
21
+ */
22
+ resizablePanelsContainerTag: {
23
+ type: String,
24
+ default: 'div',
25
+ },
26
+ /**
27
+ * 分割符号宽度
28
+ */
29
+ seperatorSize: {
30
+ type: Number,
31
+ default: 0,
32
+ },
33
+ /**
34
+ * 填充分割符
35
+ */
36
+ fillSeperator: {
37
+ type: Boolean,
38
+ default: false
39
+ },
40
+ /**
41
+ * 拖拽方向
42
+ */
43
+ dragDirection: {
44
+ type: String as PropType<'row' | 'column'>,
45
+ default: 'row',
46
+ },
47
+ /**
48
+ * 允许resize的最小值
49
+ */
50
+ resizeMinWidth: {
51
+ type: Number,
52
+ default: 0,
53
+ },
54
+ /**
55
+ * 分隔符模式 - 边框或符号
56
+ */
57
+ symbolMode: {
58
+ type: String as PropType<'symbol' | 'border'>,
59
+ default: 'symbol'
60
+ },
61
+ /**
62
+ * 分割线位置
63
+ */
64
+ seperatorPosition: {
65
+ type: String as PropType<'start' | 'end' | 'center'>,
66
+ default: 'start'
67
+ },
68
+ },
69
+ setup(_, { emit }) {
70
+ const dataId = `${generateID()}`;
71
+ const seperator = ref()
72
+ function handleDragSeperator(parentEl: HTMLElement, e: MouseEvent, idx: number) {
73
+ const { vertical } = getFlexDirection(parentEl);
74
+ const wOrH = vertical ? 'height' : 'width';
75
+
76
+ const children = parentEl.querySelectorAll(`[data-${CHILD_DATA_ATTR_NAME}]`) as ArrayLike<HTMLElement>;
77
+ const element = children[idx]!;
78
+ const prevElement = children[idx - 1]!;
79
+
80
+ element.dataset.dragLastSize = _getComputedStyle(element, wOrH)!;
81
+ prevElement.dataset.dragLastSize = _getComputedStyle(prevElement, wOrH)!;
82
+
83
+ const totalStarSize = parseFloat(element.dataset.dragLastSize) + parseFloat(prevElement.dataset.dragLastSize);
84
+ let prevEvt = e;
85
+ const moveHandle = async (_e: MouseEvent) => {
86
+ const screen = vertical ? 'screenY' : 'screenX';
87
+ const delta = _e[screen] - prevEvt[screen];
88
+ prevEvt = _e;
89
+ if (!delta) return;
90
+ const deltaElement = delta > 0 ? element : prevElement;
91
+ const otherElement = element === deltaElement ? prevElement : element;
92
+
93
+ const deltaElementSize = parseFloat(deltaElement.dataset.dragLastSize!) - Math.abs(delta);
94
+ if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || totalStarSize - deltaElementSize < _.resizeMinWidth)) {
95
+ return
96
+ }
97
+ deltaElement.style[wOrH] = `${deltaElementSize}px`;
98
+ otherElement.style[wOrH] = `${totalStarSize - deltaElementSize}px`;
99
+
100
+ deltaElement.dataset.dragLastSize = _getComputedStyle(deltaElement, wOrH)!;
101
+ otherElement.dataset.dragLastSize = _getComputedStyle(otherElement, wOrH)!;
102
+ };
103
+ const mouseupHandle = () => {
104
+ document.removeEventListener('mousemove', moveHandle, false);
105
+ document.removeEventListener('mouseup', mouseupHandle, false);
106
+ emit('resize');
107
+ };
108
+
109
+ document.addEventListener('mousemove', moveHandle, false);
110
+ document.addEventListener('mouseup', mouseupHandle, false);
111
+ }
112
+ const size = computed(() => {
113
+ if (_.seperatorSize) {
114
+ if (_.dragDirection === 'row') {
115
+ return {
116
+ width: _.seperatorSize + 'px'
117
+ }
118
+ }
119
+ return {
120
+ height: _.seperatorSize + 'px'
121
+ }
122
+ }
123
+ return {}
124
+ })
125
+ return { handleDragSeperator, dataId, size, seperator };
126
+ },
127
+ render() {
128
+ const Tag = this.resizablePanelsContainerTag;
129
+ const defaultSlots = this.$scopedSlots.default ? this.$scopedSlots.default({}) : [];
130
+ const seperatorSymbol = this.$scopedSlots['seperator-symbol'] ? this.$scopedSlots['seperator-symbol']({})?.[0] : null
131
+ const { handleDragSeperator, dataId, symbolMode, seperatorPosition, size, fillSeperator, dragDirection } = this;
132
+ return (
133
+ <Tag class={'nf-resizable-panels nf-resizable-panels-' + dragDirection}>
134
+ {!defaultSlots ? null : ([] as VNode[]).concat(...defaultSlots.filter(item => !!(item.tag || item.text?.trim())).map((vNode, idx) => {
135
+ const isVShowFalse = vNode.data?.directives?.find(a => (a as any).rawName === 'v-show')?.value === false;
136
+ const isComment = vNode?.isComment;
137
+ if (vNode.data) {
138
+ vNode.data.attrs = vNode.data.attrs ?? {};
139
+ vNode.data.attrs[`data-${CHILD_DATA_ATTR_NAME}`] = dataId;
140
+ }
141
+ if (idx === 0) {
142
+ return vNode;
143
+ }
144
+ return [
145
+ seperatorSymbol ? <span style={{ cursor: `${dragDirection === 'column' ? 'row' : 'col'}-resize`,
146
+ display: (isVShowFalse || isComment) ? 'none' : undefined,
147
+ }}
148
+ onMousedown={
149
+ (evt: MouseEvent) => {
150
+ handleDragSeperator(this.$el as HTMLElement, evt, idx)
151
+ }
152
+ }
153
+ >
154
+ {seperatorSymbol}
155
+ </span> : (<div
156
+ style={{ display: (isVShowFalse || isComment) ? 'none' : undefined, ...size }}
157
+ class={{
158
+ 'nf-resizable-panels-seperator': true,
159
+ "nf-seperator-border": symbolMode === 'border',
160
+ [`nf-flex-${seperatorPosition}`]: true,
161
+ 'nf-resizable-panels-seperator-fill': fillSeperator
162
+ }}
163
+ onMousedown={
164
+ (evt: MouseEvent) => {
165
+ handleDragSeperator(this.$el as HTMLElement, evt, idx)
166
+ }
167
+ }
168
+ />),
169
+ vNode,
170
+ ];
171
+ }))}
172
+ </Tag>
173
+ );
174
+ },
175
+ });
176
+ </script>
177
+
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/css/nf-resizable-panels.css'
@@ -0,0 +1 @@
1
+ import '@94ai/nf-theme-chalk/lib/nf-resizable-panels.scss'
@@ -0,0 +1,92 @@
1
+ import { presudos } from '../const'
2
+ import { merge, pick, omit } from 'lodash';
3
+ import mergeProps from '@vue/babel-helper-vue-jsx-merge-props';
4
+
5
+ /**
6
+ * 转驼峰
7
+ * @param { string } word
8
+ */
9
+ export function upperCamelCase(word: string): string {
10
+ const cleanedString = word.replace(/\W/g, '');
11
+ const words = cleanedString.toLowerCase().split(/\B(?=[A-Z])/);
12
+ const upperCamelCase = words.map(word => word.charAt(0).toUpperCase() + word.slice(1)).join('');
13
+ return upperCamelCase;
14
+ }
15
+
16
+ /**
17
+ * flex: none => flex: 0 0 auto
18
+ * flex: 0 => flex: 0 1 0%
19
+ * flex: 1 => flex: 1 1 0%
20
+ * 没有flex => flex: 0 1 auto
21
+ * @param { HTMLElement } el
22
+ */
23
+ export function isAutoFlexBasis(el: HTMLElement): boolean {
24
+ const flexBasis = _getComputedStyle(el, 'flexBasis') as string;
25
+ return flexBasis === 'auto';
26
+ }
27
+
28
+ /**
29
+ * 兼容各浏览器getComputedStyle
30
+ * @param { HTMLElement } el
31
+ * @param { string } k
32
+ */
33
+ export function _getComputedStyle(el: HTMLElement, k: string): string | undefined {
34
+ const computedStyle = getComputedStyle(el);
35
+ for (let i = 0; i <= presudos.length; i++) {
36
+ const key = presudos[i] ? `${presudos[i]}${upperCamelCase(k)}` : k;
37
+ if (computedStyle[key]) {
38
+ return computedStyle[key as keyof CSSStyleDeclaration] as string;
39
+ }
40
+ }
41
+ return undefined;
42
+ }
43
+
44
+ /**
45
+ * 获取元素flex方向
46
+ * @param { HTMLElement } el
47
+ */
48
+ export function getFlexDirection(el: HTMLElement): {
49
+ /**
50
+ * 是否竖向
51
+ */
52
+ vertical: boolean,
53
+ reverse: boolean,
54
+ } {
55
+ const flexDirection = _getComputedStyle(el, 'flexDirection') as string;
56
+ const [direction, reverse] = flexDirection.split('-');
57
+ return {
58
+ vertical: direction === 'column',
59
+ reverse: !!reverse,
60
+ };
61
+ }
62
+
63
+
64
+ export function mergeVNodeProps(vnode, ...args) {
65
+ if (vnode.componentOptions) {
66
+ const { propsData, listeners, Ctor } = vnode.componentOptions;
67
+ // 为了便于合并, 我们只取on和attrs两个参数,分别合并事件和属性
68
+ const { on, attrs } = mergeProps([{ on: listeners, attrs: propsData }, ...args]);
69
+ // 获取组件中定义的props
70
+ const keys = Object.keys(Ctor.options.props || {});
71
+ // 分离出组件需要的propsData和attrs
72
+ const [$props, $attrs] = [pick(attrs, keys), omit(attrs, keys)];
73
+
74
+ // 这里偷懒使用lodash.merge函数进行递归合并
75
+ merge(vnode, {
76
+ data: { attrs: $attrs },
77
+ componentOptions: {
78
+ listeners: on,
79
+ propsData: $props,
80
+ },
81
+ });
82
+ } else {
83
+ // 非组件VNode,直接合并data。但需要注意事件使用的是on而非nativeOn
84
+ // 属性根据情况可以使用attrs或domProps,这二者的区别见后文
85
+ vnode.data = mergeProps([vnode.data, ...args]);
86
+ }
87
+
88
+ return vnode;
89
+ }
90
+
91
+
92
+
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@94ai/nf-resizable-panels",
3
- "version": "3.1.37",
3
+ "version": "3.1.38",
4
4
  "description": "> TODO: description",
5
5
  "keywords": [],
6
6
  "author": "zoujiahe <zoujiahe@94ai.com>",
@@ -14,7 +14,7 @@
14
14
  "url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
15
15
  },
16
16
  "dependencies": {
17
- "@94ai/nf-theme-chalk": "^3.1.37",
17
+ "@94ai/nf-theme-chalk": "^3.1.38",
18
18
  "vue-demi": "^0.14.5"
19
19
  },
20
20
  "peerDependenciesMeta": {
@@ -30,5 +30,5 @@
30
30
  "types": "lib/index.d.ts",
31
31
  "main": "lib/nf-resizable-panels.cjs.js",
32
32
  "module": "lib/nf-resizable-panels.esm-bundler.js",
33
- "gitHead": "14dfc729b9988003d4686b414e1e9c0aaa7c4dcd"
33
+ "gitHead": "2b60696b405feafbbaeed385e5bcf666ceefbf2c"
34
34
  }