@94ai/nf-resizable-panels 5.0.32 → 5.0.36
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/index.d.ts +26 -0
- package/lib/nf-resizable-panels.cjs.js +168 -9
- package/lib/nf-resizable-panels.esm-bundler.js +170 -11
- package/lib/nf-resizable-panels.vue.d.ts +9 -0
- package/lib/util.d.ts +15 -0
- package/package/nf-resizable-panels.vue +100 -16
- package/package/util.ts +113 -0
- package/package.json +4 -4
package/lib/index.d.ts
CHANGED
|
@@ -36,6 +36,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
36
36
|
type: import("vue-demi").PropType<"flex" | "calc">;
|
|
37
37
|
default: string;
|
|
38
38
|
};
|
|
39
|
+
cached: {
|
|
40
|
+
type: BooleanConstructor;
|
|
41
|
+
default: boolean;
|
|
42
|
+
};
|
|
39
43
|
}>>, Readonly<import("vue-demi").ExtractPropTypes<{
|
|
40
44
|
resizablePanelsContainerTag: {
|
|
41
45
|
type: StringConstructor;
|
|
@@ -73,6 +77,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
73
77
|
type: import("vue-demi").PropType<"flex" | "calc">;
|
|
74
78
|
default: string;
|
|
75
79
|
};
|
|
80
|
+
cached: {
|
|
81
|
+
type: BooleanConstructor;
|
|
82
|
+
default: boolean;
|
|
83
|
+
};
|
|
76
84
|
}>>, {}, {
|
|
77
85
|
resizablePanelsContainerTag: string;
|
|
78
86
|
seperatorSize: number;
|
|
@@ -83,6 +91,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
83
91
|
seperatorPosition: "start" | "end" | "center";
|
|
84
92
|
unique: string;
|
|
85
93
|
divideType: "flex" | "calc";
|
|
94
|
+
cached: boolean;
|
|
86
95
|
}, true, import("vue/types/v3-component-options").ComponentOptionsBase<any, any, any, any, any, any, any, any, any, any>> & Readonly<Readonly<import("vue-demi").ExtractPropTypes<{
|
|
87
96
|
resizablePanelsContainerTag: {
|
|
88
97
|
type: StringConstructor;
|
|
@@ -120,6 +129,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
120
129
|
type: import("vue-demi").PropType<"flex" | "calc">;
|
|
121
130
|
default: string;
|
|
122
131
|
};
|
|
132
|
+
cached: {
|
|
133
|
+
type: BooleanConstructor;
|
|
134
|
+
default: boolean;
|
|
135
|
+
};
|
|
123
136
|
}>>> & import("vue-demi").ShallowUnwrapRef<{
|
|
124
137
|
handleDragSeperator: (parentEl: HTMLElement, e: MouseEvent, idx: number) => void;
|
|
125
138
|
dataId: string;
|
|
@@ -171,6 +184,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
171
184
|
type: import("vue-demi").PropType<"flex" | "calc">;
|
|
172
185
|
default: string;
|
|
173
186
|
};
|
|
187
|
+
cached: {
|
|
188
|
+
type: BooleanConstructor;
|
|
189
|
+
default: boolean;
|
|
190
|
+
};
|
|
174
191
|
}>>, any, any, any, import("vue-demi").ComponentComputedOptions, import("vue-demi").ComponentMethodOptions> & import("vue/types/v3-component-options").ComponentOptionsBase<Readonly<import("vue-demi").ExtractPropTypes<{
|
|
175
192
|
resizablePanelsContainerTag: {
|
|
176
193
|
type: StringConstructor;
|
|
@@ -208,6 +225,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
208
225
|
type: import("vue-demi").PropType<"flex" | "calc">;
|
|
209
226
|
default: string;
|
|
210
227
|
};
|
|
228
|
+
cached: {
|
|
229
|
+
type: BooleanConstructor;
|
|
230
|
+
default: boolean;
|
|
231
|
+
};
|
|
211
232
|
}>>, {
|
|
212
233
|
handleDragSeperator: (parentEl: HTMLElement, e: MouseEvent, idx: number) => void;
|
|
213
234
|
dataId: string;
|
|
@@ -232,6 +253,7 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
232
253
|
seperatorPosition: "start" | "end" | "center";
|
|
233
254
|
unique: string;
|
|
234
255
|
divideType: "flex" | "calc";
|
|
256
|
+
cached: boolean;
|
|
235
257
|
}> & {
|
|
236
258
|
props: {
|
|
237
259
|
resizablePanelsContainerTag: {
|
|
@@ -270,6 +292,10 @@ declare const _default: import("vue/types/v3-component-public-instance").Compone
|
|
|
270
292
|
type: import("vue-demi").PropType<"flex" | "calc">;
|
|
271
293
|
default: string;
|
|
272
294
|
};
|
|
295
|
+
cached: {
|
|
296
|
+
type: BooleanConstructor;
|
|
297
|
+
default: boolean;
|
|
298
|
+
};
|
|
273
299
|
};
|
|
274
300
|
} & PluginObject<undefined>;
|
|
275
301
|
export default _default;
|
|
@@ -4,6 +4,83 @@ const vueDemi = require("vue-demi");
|
|
|
4
4
|
const commonUtils = require("@94ai/common-utils");
|
|
5
5
|
const vue2RuntimeHelpers = require("@94ai/vue2-runtime-helpers");
|
|
6
6
|
const CHILD_DATA_ATTR_NAME = "resiable-panel-child";
|
|
7
|
+
function isInteger(obj) {
|
|
8
|
+
return Math.floor(obj) === obj;
|
|
9
|
+
}
|
|
10
|
+
function toInteger(floatNum) {
|
|
11
|
+
const ret = { times: 1, num: 0 };
|
|
12
|
+
if (isInteger(floatNum)) {
|
|
13
|
+
ret.num = floatNum;
|
|
14
|
+
return ret;
|
|
15
|
+
}
|
|
16
|
+
const strfi = floatNum + "";
|
|
17
|
+
const dotPos = strfi.indexOf(".");
|
|
18
|
+
const len = strfi.substr(dotPos + 1).length;
|
|
19
|
+
const times = Math.pow(10, len);
|
|
20
|
+
const intNum = Number(floatNum.toString().replace(".", ""));
|
|
21
|
+
ret.times = times;
|
|
22
|
+
ret.num = intNum;
|
|
23
|
+
return ret;
|
|
24
|
+
}
|
|
25
|
+
function operation(a, b, digits, op) {
|
|
26
|
+
const o1 = toInteger(a);
|
|
27
|
+
const o2 = toInteger(b);
|
|
28
|
+
const n1 = o1.num;
|
|
29
|
+
const n2 = o2.num;
|
|
30
|
+
const t1 = o1.times;
|
|
31
|
+
const t2 = o2.times;
|
|
32
|
+
const max = t1 > t2 ? t1 : t2;
|
|
33
|
+
let result = null;
|
|
34
|
+
switch (op) {
|
|
35
|
+
case "add":
|
|
36
|
+
if (t1 === t2) {
|
|
37
|
+
result = n1 + n2;
|
|
38
|
+
} else if (t1 > t2) {
|
|
39
|
+
result = n1 + n2 * (t1 / t2);
|
|
40
|
+
} else {
|
|
41
|
+
result = n1 * (t2 / t1) + n2;
|
|
42
|
+
}
|
|
43
|
+
return result / max;
|
|
44
|
+
case "subtract":
|
|
45
|
+
if (t1 === t2) {
|
|
46
|
+
result = n1 - n2;
|
|
47
|
+
} else if (t1 > t2) {
|
|
48
|
+
result = n1 - n2 * (t1 / t2);
|
|
49
|
+
} else {
|
|
50
|
+
result = n1 * (t2 / t1) - n2;
|
|
51
|
+
}
|
|
52
|
+
return result / max;
|
|
53
|
+
case "multiply":
|
|
54
|
+
result = n1 * n2 / (t1 * t2);
|
|
55
|
+
return result;
|
|
56
|
+
case "divide":
|
|
57
|
+
result = n1 / n2 * (t2 / t1);
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function add(a, b, digits) {
|
|
62
|
+
return operation(a, b, digits, "add");
|
|
63
|
+
}
|
|
64
|
+
function subtract(a, b, digits) {
|
|
65
|
+
return operation(a, b, digits, "subtract");
|
|
66
|
+
}
|
|
67
|
+
const _LocalStorageUtil = class _LocalStorageUtil2 {
|
|
68
|
+
static getNfResizablePanelsCached(key) {
|
|
69
|
+
const cached = localStorage.getItem(`${_LocalStorageUtil2.cachedKey}-${key}`);
|
|
70
|
+
if (cached) {
|
|
71
|
+
try {
|
|
72
|
+
return JSON.parse(cached);
|
|
73
|
+
} catch (e) {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return [];
|
|
77
|
+
}
|
|
78
|
+
static setNfResizablePanelsCached(key, value) {
|
|
79
|
+
localStorage.setItem(`${_LocalStorageUtil2.cachedKey}-${key}`, JSON.stringify(value));
|
|
80
|
+
}
|
|
81
|
+
};
|
|
82
|
+
_LocalStorageUtil.cachedKey = "nf-resizable-panels";
|
|
83
|
+
let LocalStorageUtil = _LocalStorageUtil;
|
|
7
84
|
const _sfc_main = vueDemi.defineComponent({
|
|
8
85
|
name: "nf-resizable-panels",
|
|
9
86
|
props: {
|
|
@@ -60,16 +137,28 @@ const _sfc_main = vueDemi.defineComponent({
|
|
|
60
137
|
type: String,
|
|
61
138
|
default: CHILD_DATA_ATTR_NAME
|
|
62
139
|
},
|
|
140
|
+
/**
|
|
141
|
+
* 布局类型
|
|
142
|
+
*/
|
|
63
143
|
divideType: {
|
|
64
144
|
type: String,
|
|
65
145
|
default: "calc"
|
|
146
|
+
},
|
|
147
|
+
/**
|
|
148
|
+
* 是否开启缓存
|
|
149
|
+
*/
|
|
150
|
+
cached: {
|
|
151
|
+
type: Boolean,
|
|
152
|
+
default: false
|
|
66
153
|
}
|
|
67
154
|
},
|
|
68
155
|
setup(_, {
|
|
69
156
|
emit
|
|
70
157
|
}) {
|
|
158
|
+
var _a;
|
|
71
159
|
const dataId = `${commonUtils.generateID()}`;
|
|
72
160
|
const seperator = vueDemi.ref();
|
|
161
|
+
const instance = (_a = vueDemi.getCurrentInstance()) == null ? void 0 : _a.proxy;
|
|
73
162
|
function handleDragSeperator(parentEl, e, idx) {
|
|
74
163
|
const {
|
|
75
164
|
vertical
|
|
@@ -81,28 +170,59 @@ const _sfc_main = vueDemi.defineComponent({
|
|
|
81
170
|
const prevElement = children[idx - 1];
|
|
82
171
|
const elementSize = element.dataset.dragLastSize = commonUtils._getComputedStyle(element, wOrH);
|
|
83
172
|
const prevElementSize = prevElement.dataset.dragLastSize = commonUtils._getComputedStyle(prevElement, wOrH);
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
173
|
+
const elementMinSize = commonUtils._getComputedStyle(element, `min-${wOrH}`);
|
|
174
|
+
const prevElementMinSize = commonUtils._getComputedStyle(prevElement, `min-${wOrH}`);
|
|
175
|
+
const totalStarSize = add(parseFloat(elementSize), parseFloat(prevElementSize), 4);
|
|
176
|
+
if (_.cached) {
|
|
177
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
178
|
+
cached[idx] = element.dataset.dragLastSize;
|
|
179
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize;
|
|
180
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached);
|
|
181
|
+
}
|
|
182
|
+
element.style[wOrH] = element.style[wOrHSet] = elementSize;
|
|
183
|
+
prevElement.style[wOrH] = prevElement.style[wOrHSet] = prevElementSize;
|
|
87
184
|
let prevEvt = e;
|
|
185
|
+
const recordCached = commonUtils.debounce(() => {
|
|
186
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
187
|
+
cached[idx] = element.dataset.dragLastSize;
|
|
188
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize;
|
|
189
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached);
|
|
190
|
+
}, 100, false);
|
|
88
191
|
const moveHandle = async (_e) => {
|
|
89
192
|
const screen = vertical ? "screenY" : "screenX";
|
|
90
193
|
const delta = _e[screen] - prevEvt[screen];
|
|
91
194
|
prevEvt = _e;
|
|
92
195
|
if (!delta)
|
|
93
196
|
return;
|
|
94
|
-
const deltaElementSize = parseFloat(prevElement.dataset.dragLastSize)
|
|
95
|
-
if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || totalStarSize
|
|
197
|
+
const deltaElementSize = add(parseFloat(prevElement.dataset.dragLastSize), delta, 4);
|
|
198
|
+
if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || subtract(totalStarSize, deltaElementSize, 4) < _.resizeMinWidth)) {
|
|
96
199
|
return;
|
|
97
200
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
201
|
+
if (elementMinSize.indexOf("px") > -1) {
|
|
202
|
+
if (subtract(totalStarSize, deltaElementSize, 4) <= parseFloat(elementMinSize)) {
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
if (prevElementMinSize.indexOf("px") > -1) {
|
|
207
|
+
if (deltaElementSize <= parseFloat(prevElementMinSize)) {
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
prevElement.style[wOrH] = prevElement.style[wOrHSet] = `${deltaElementSize}px`;
|
|
212
|
+
element.style[wOrH] = element.style[wOrHSet] = `${subtract(totalStarSize, deltaElementSize, 4)}px`;
|
|
102
213
|
prevElement.dataset.dragLastSize = prevElement.style[wOrHSet];
|
|
103
214
|
element.dataset.dragLastSize = element.style[wOrHSet];
|
|
215
|
+
if (_.cached) {
|
|
216
|
+
recordCached();
|
|
217
|
+
}
|
|
104
218
|
};
|
|
105
219
|
const mouseupHandle = () => {
|
|
220
|
+
if (_.cached) {
|
|
221
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
222
|
+
cached[idx] = element.dataset.dragLastSize;
|
|
223
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize;
|
|
224
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached);
|
|
225
|
+
}
|
|
106
226
|
document.removeEventListener("mousemove", moveHandle, false);
|
|
107
227
|
document.removeEventListener("mouseup", mouseupHandle, false);
|
|
108
228
|
emit("resize");
|
|
@@ -123,6 +243,45 @@ const _sfc_main = vueDemi.defineComponent({
|
|
|
123
243
|
}
|
|
124
244
|
return {};
|
|
125
245
|
});
|
|
246
|
+
vueDemi.onMounted(async () => {
|
|
247
|
+
const {
|
|
248
|
+
vertical
|
|
249
|
+
} = commonUtils.getFlexDirection(instance.$el);
|
|
250
|
+
const wOrH = vertical ? "height" : "width";
|
|
251
|
+
const wOrHSet = _.divideType === "flex" ? "flex-basis" : vertical ? "height" : "width";
|
|
252
|
+
const children = instance.$el.querySelectorAll(`[data-${_.unique}]`);
|
|
253
|
+
const arr = [];
|
|
254
|
+
let realSum = 0;
|
|
255
|
+
Array.from(children).forEach((_2, index) => {
|
|
256
|
+
const elementSize = children[index].dataset.dragLastSize = commonUtils._getComputedStyle(children[index], wOrH);
|
|
257
|
+
arr.push(elementSize);
|
|
258
|
+
realSum = add(realSum, parseFloat(elementSize), 4);
|
|
259
|
+
});
|
|
260
|
+
if (_.cached) {
|
|
261
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
262
|
+
if (cached.length) {
|
|
263
|
+
if (cached.length === children.length) {
|
|
264
|
+
let sum = 0;
|
|
265
|
+
cached.forEach((cachedItem) => {
|
|
266
|
+
sum = add(sum, parseFloat(cachedItem), 4);
|
|
267
|
+
});
|
|
268
|
+
if (Math.abs(sum - realSum) <= 4) {
|
|
269
|
+
cached.forEach((cachedItem, index) => {
|
|
270
|
+
const dom = children[index];
|
|
271
|
+
dom.dataset.dragLastSize = cachedItem;
|
|
272
|
+
dom.style[wOrH] = dom.style[wOrHSet] = cachedItem;
|
|
273
|
+
});
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, arr);
|
|
279
|
+
}
|
|
280
|
+
arr.forEach((item, index) => {
|
|
281
|
+
const dom = children[index];
|
|
282
|
+
dom.style[wOrH] = dom.style[wOrHSet] = item;
|
|
283
|
+
});
|
|
284
|
+
});
|
|
126
285
|
return {
|
|
127
286
|
handleDragSeperator,
|
|
128
287
|
dataId,
|
|
@@ -1,7 +1,84 @@
|
|
|
1
|
-
import { defineComponent, ref, computed, h } from "vue-demi";
|
|
2
|
-
import { generateID, getFlexDirection, _getComputedStyle } from "@94ai/common-utils";
|
|
1
|
+
import { defineComponent, ref, getCurrentInstance, computed, onMounted, h } from "vue-demi";
|
|
2
|
+
import { generateID, getFlexDirection, _getComputedStyle, debounce } from "@94ai/common-utils";
|
|
3
3
|
import { normalizeComponent } from "@94ai/vue2-runtime-helpers";
|
|
4
4
|
const CHILD_DATA_ATTR_NAME = "resiable-panel-child";
|
|
5
|
+
function isInteger(obj) {
|
|
6
|
+
return Math.floor(obj) === obj;
|
|
7
|
+
}
|
|
8
|
+
function toInteger(floatNum) {
|
|
9
|
+
const ret = { times: 1, num: 0 };
|
|
10
|
+
if (isInteger(floatNum)) {
|
|
11
|
+
ret.num = floatNum;
|
|
12
|
+
return ret;
|
|
13
|
+
}
|
|
14
|
+
const strfi = floatNum + "";
|
|
15
|
+
const dotPos = strfi.indexOf(".");
|
|
16
|
+
const len = strfi.substr(dotPos + 1).length;
|
|
17
|
+
const times = Math.pow(10, len);
|
|
18
|
+
const intNum = Number(floatNum.toString().replace(".", ""));
|
|
19
|
+
ret.times = times;
|
|
20
|
+
ret.num = intNum;
|
|
21
|
+
return ret;
|
|
22
|
+
}
|
|
23
|
+
function operation(a, b, digits, op) {
|
|
24
|
+
const o1 = toInteger(a);
|
|
25
|
+
const o2 = toInteger(b);
|
|
26
|
+
const n1 = o1.num;
|
|
27
|
+
const n2 = o2.num;
|
|
28
|
+
const t1 = o1.times;
|
|
29
|
+
const t2 = o2.times;
|
|
30
|
+
const max = t1 > t2 ? t1 : t2;
|
|
31
|
+
let result = null;
|
|
32
|
+
switch (op) {
|
|
33
|
+
case "add":
|
|
34
|
+
if (t1 === t2) {
|
|
35
|
+
result = n1 + n2;
|
|
36
|
+
} else if (t1 > t2) {
|
|
37
|
+
result = n1 + n2 * (t1 / t2);
|
|
38
|
+
} else {
|
|
39
|
+
result = n1 * (t2 / t1) + n2;
|
|
40
|
+
}
|
|
41
|
+
return result / max;
|
|
42
|
+
case "subtract":
|
|
43
|
+
if (t1 === t2) {
|
|
44
|
+
result = n1 - n2;
|
|
45
|
+
} else if (t1 > t2) {
|
|
46
|
+
result = n1 - n2 * (t1 / t2);
|
|
47
|
+
} else {
|
|
48
|
+
result = n1 * (t2 / t1) - n2;
|
|
49
|
+
}
|
|
50
|
+
return result / max;
|
|
51
|
+
case "multiply":
|
|
52
|
+
result = n1 * n2 / (t1 * t2);
|
|
53
|
+
return result;
|
|
54
|
+
case "divide":
|
|
55
|
+
result = n1 / n2 * (t2 / t1);
|
|
56
|
+
return result;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function add(a, b, digits) {
|
|
60
|
+
return operation(a, b, digits, "add");
|
|
61
|
+
}
|
|
62
|
+
function subtract(a, b, digits) {
|
|
63
|
+
return operation(a, b, digits, "subtract");
|
|
64
|
+
}
|
|
65
|
+
const _LocalStorageUtil = class _LocalStorageUtil2 {
|
|
66
|
+
static getNfResizablePanelsCached(key) {
|
|
67
|
+
const cached = localStorage.getItem(`${_LocalStorageUtil2.cachedKey}-${key}`);
|
|
68
|
+
if (cached) {
|
|
69
|
+
try {
|
|
70
|
+
return JSON.parse(cached);
|
|
71
|
+
} catch (e) {
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return [];
|
|
75
|
+
}
|
|
76
|
+
static setNfResizablePanelsCached(key, value) {
|
|
77
|
+
localStorage.setItem(`${_LocalStorageUtil2.cachedKey}-${key}`, JSON.stringify(value));
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
_LocalStorageUtil.cachedKey = "nf-resizable-panels";
|
|
81
|
+
let LocalStorageUtil = _LocalStorageUtil;
|
|
5
82
|
const _sfc_main = defineComponent({
|
|
6
83
|
name: "nf-resizable-panels",
|
|
7
84
|
props: {
|
|
@@ -58,16 +135,28 @@ const _sfc_main = defineComponent({
|
|
|
58
135
|
type: String,
|
|
59
136
|
default: CHILD_DATA_ATTR_NAME
|
|
60
137
|
},
|
|
138
|
+
/**
|
|
139
|
+
* 布局类型
|
|
140
|
+
*/
|
|
61
141
|
divideType: {
|
|
62
142
|
type: String,
|
|
63
143
|
default: "calc"
|
|
144
|
+
},
|
|
145
|
+
/**
|
|
146
|
+
* 是否开启缓存
|
|
147
|
+
*/
|
|
148
|
+
cached: {
|
|
149
|
+
type: Boolean,
|
|
150
|
+
default: false
|
|
64
151
|
}
|
|
65
152
|
},
|
|
66
153
|
setup(_, {
|
|
67
154
|
emit
|
|
68
155
|
}) {
|
|
156
|
+
var _a;
|
|
69
157
|
const dataId = `${generateID()}`;
|
|
70
158
|
const seperator = ref();
|
|
159
|
+
const instance = (_a = getCurrentInstance()) == null ? void 0 : _a.proxy;
|
|
71
160
|
function handleDragSeperator(parentEl, e, idx) {
|
|
72
161
|
const {
|
|
73
162
|
vertical
|
|
@@ -79,28 +168,59 @@ const _sfc_main = defineComponent({
|
|
|
79
168
|
const prevElement = children[idx - 1];
|
|
80
169
|
const elementSize = element.dataset.dragLastSize = _getComputedStyle(element, wOrH);
|
|
81
170
|
const prevElementSize = prevElement.dataset.dragLastSize = _getComputedStyle(prevElement, wOrH);
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
171
|
+
const elementMinSize = _getComputedStyle(element, `min-${wOrH}`);
|
|
172
|
+
const prevElementMinSize = _getComputedStyle(prevElement, `min-${wOrH}`);
|
|
173
|
+
const totalStarSize = add(parseFloat(elementSize), parseFloat(prevElementSize), 4);
|
|
174
|
+
if (_.cached) {
|
|
175
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
176
|
+
cached[idx] = element.dataset.dragLastSize;
|
|
177
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize;
|
|
178
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached);
|
|
179
|
+
}
|
|
180
|
+
element.style[wOrH] = element.style[wOrHSet] = elementSize;
|
|
181
|
+
prevElement.style[wOrH] = prevElement.style[wOrHSet] = prevElementSize;
|
|
85
182
|
let prevEvt = e;
|
|
183
|
+
const recordCached = debounce(() => {
|
|
184
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
185
|
+
cached[idx] = element.dataset.dragLastSize;
|
|
186
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize;
|
|
187
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached);
|
|
188
|
+
}, 100, false);
|
|
86
189
|
const moveHandle = async (_e) => {
|
|
87
190
|
const screen = vertical ? "screenY" : "screenX";
|
|
88
191
|
const delta = _e[screen] - prevEvt[screen];
|
|
89
192
|
prevEvt = _e;
|
|
90
193
|
if (!delta)
|
|
91
194
|
return;
|
|
92
|
-
const deltaElementSize = parseFloat(prevElement.dataset.dragLastSize)
|
|
93
|
-
if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || totalStarSize
|
|
195
|
+
const deltaElementSize = add(parseFloat(prevElement.dataset.dragLastSize), delta, 4);
|
|
196
|
+
if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || subtract(totalStarSize, deltaElementSize, 4) < _.resizeMinWidth)) {
|
|
94
197
|
return;
|
|
95
198
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
199
|
+
if (elementMinSize.indexOf("px") > -1) {
|
|
200
|
+
if (subtract(totalStarSize, deltaElementSize, 4) <= parseFloat(elementMinSize)) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (prevElementMinSize.indexOf("px") > -1) {
|
|
205
|
+
if (deltaElementSize <= parseFloat(prevElementMinSize)) {
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
prevElement.style[wOrH] = prevElement.style[wOrHSet] = `${deltaElementSize}px`;
|
|
210
|
+
element.style[wOrH] = element.style[wOrHSet] = `${subtract(totalStarSize, deltaElementSize, 4)}px`;
|
|
100
211
|
prevElement.dataset.dragLastSize = prevElement.style[wOrHSet];
|
|
101
212
|
element.dataset.dragLastSize = element.style[wOrHSet];
|
|
213
|
+
if (_.cached) {
|
|
214
|
+
recordCached();
|
|
215
|
+
}
|
|
102
216
|
};
|
|
103
217
|
const mouseupHandle = () => {
|
|
218
|
+
if (_.cached) {
|
|
219
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
220
|
+
cached[idx] = element.dataset.dragLastSize;
|
|
221
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize;
|
|
222
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached);
|
|
223
|
+
}
|
|
104
224
|
document.removeEventListener("mousemove", moveHandle, false);
|
|
105
225
|
document.removeEventListener("mouseup", mouseupHandle, false);
|
|
106
226
|
emit("resize");
|
|
@@ -121,6 +241,45 @@ const _sfc_main = defineComponent({
|
|
|
121
241
|
}
|
|
122
242
|
return {};
|
|
123
243
|
});
|
|
244
|
+
onMounted(async () => {
|
|
245
|
+
const {
|
|
246
|
+
vertical
|
|
247
|
+
} = getFlexDirection(instance.$el);
|
|
248
|
+
const wOrH = vertical ? "height" : "width";
|
|
249
|
+
const wOrHSet = _.divideType === "flex" ? "flex-basis" : vertical ? "height" : "width";
|
|
250
|
+
const children = instance.$el.querySelectorAll(`[data-${_.unique}]`);
|
|
251
|
+
const arr = [];
|
|
252
|
+
let realSum = 0;
|
|
253
|
+
Array.from(children).forEach((_2, index) => {
|
|
254
|
+
const elementSize = children[index].dataset.dragLastSize = _getComputedStyle(children[index], wOrH);
|
|
255
|
+
arr.push(elementSize);
|
|
256
|
+
realSum = add(realSum, parseFloat(elementSize), 4);
|
|
257
|
+
});
|
|
258
|
+
if (_.cached) {
|
|
259
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique);
|
|
260
|
+
if (cached.length) {
|
|
261
|
+
if (cached.length === children.length) {
|
|
262
|
+
let sum = 0;
|
|
263
|
+
cached.forEach((cachedItem) => {
|
|
264
|
+
sum = add(sum, parseFloat(cachedItem), 4);
|
|
265
|
+
});
|
|
266
|
+
if (Math.abs(sum - realSum) <= 4) {
|
|
267
|
+
cached.forEach((cachedItem, index) => {
|
|
268
|
+
const dom = children[index];
|
|
269
|
+
dom.dataset.dragLastSize = cachedItem;
|
|
270
|
+
dom.style[wOrH] = dom.style[wOrHSet] = cachedItem;
|
|
271
|
+
});
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, arr);
|
|
277
|
+
}
|
|
278
|
+
arr.forEach((item, index) => {
|
|
279
|
+
const dom = children[index];
|
|
280
|
+
dom.style[wOrH] = dom.style[wOrHSet] = item;
|
|
281
|
+
});
|
|
282
|
+
});
|
|
124
283
|
return {
|
|
125
284
|
handleDragSeperator,
|
|
126
285
|
dataId,
|
|
@@ -36,6 +36,10 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
36
36
|
type: PropType<"flex" | "calc">;
|
|
37
37
|
default: string;
|
|
38
38
|
};
|
|
39
|
+
cached: {
|
|
40
|
+
type: BooleanConstructor;
|
|
41
|
+
default: boolean;
|
|
42
|
+
};
|
|
39
43
|
}, {
|
|
40
44
|
handleDragSeperator: (parentEl: HTMLElement, e: MouseEvent, idx: number) => void;
|
|
41
45
|
dataId: string;
|
|
@@ -87,6 +91,10 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
87
91
|
type: PropType<"flex" | "calc">;
|
|
88
92
|
default: string;
|
|
89
93
|
};
|
|
94
|
+
cached: {
|
|
95
|
+
type: BooleanConstructor;
|
|
96
|
+
default: boolean;
|
|
97
|
+
};
|
|
90
98
|
}>>, {
|
|
91
99
|
resizablePanelsContainerTag: string;
|
|
92
100
|
seperatorSize: number;
|
|
@@ -97,5 +105,6 @@ declare const _default: import("vue-demi").DefineComponent<{
|
|
|
97
105
|
seperatorPosition: "start" | "end" | "center";
|
|
98
106
|
unique: string;
|
|
99
107
|
divideType: "flex" | "calc";
|
|
108
|
+
cached: boolean;
|
|
100
109
|
}>;
|
|
101
110
|
export default _default;
|
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export declare function isInteger(obj: any): boolean;
|
|
2
|
+
export declare function toInteger(floatNum: any): {
|
|
3
|
+
times: number;
|
|
4
|
+
num: number;
|
|
5
|
+
};
|
|
6
|
+
export declare function operation(a: any, b: any, digits: any, op: any): number | null | undefined;
|
|
7
|
+
export declare function add(a: any, b: any, digits: any): number | null | undefined;
|
|
8
|
+
export declare function subtract(a: any, b: any, digits: any): number | null | undefined;
|
|
9
|
+
export declare function multiply(a: any, b: any, digits: any): number | null | undefined;
|
|
10
|
+
export declare function divide(a: any, b: any, digits: any): number | null | undefined;
|
|
11
|
+
export declare class LocalStorageUtil {
|
|
12
|
+
static cachedKey: string;
|
|
13
|
+
static getNfResizablePanelsCached(key: any): any;
|
|
14
|
+
static setNfResizablePanelsCached(key: any, value: any): void;
|
|
15
|
+
}
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
import {
|
|
3
3
|
computed,
|
|
4
4
|
defineComponent,
|
|
5
|
+
getCurrentInstance,
|
|
6
|
+
onMounted,
|
|
5
7
|
PropType,
|
|
6
8
|
ref,
|
|
7
9
|
VNode
|
|
@@ -9,9 +11,15 @@ import {
|
|
|
9
11
|
import {
|
|
10
12
|
_getComputedStyle,
|
|
11
13
|
getFlexDirection,
|
|
12
|
-
generateID
|
|
14
|
+
generateID,
|
|
15
|
+
debounce
|
|
13
16
|
} from '@94ai/common-utils'
|
|
14
17
|
import { CHILD_DATA_ATTR_NAME } from './const'
|
|
18
|
+
import {
|
|
19
|
+
add,
|
|
20
|
+
LocalStorageUtil,
|
|
21
|
+
subtract
|
|
22
|
+
} from './util'
|
|
15
23
|
|
|
16
24
|
export default defineComponent({
|
|
17
25
|
name: 'nf-resizable-panels',
|
|
@@ -69,14 +77,25 @@ export default defineComponent({
|
|
|
69
77
|
type: String,
|
|
70
78
|
default: CHILD_DATA_ATTR_NAME,
|
|
71
79
|
},
|
|
80
|
+
/**
|
|
81
|
+
* 布局类型
|
|
82
|
+
*/
|
|
72
83
|
divideType: {
|
|
73
84
|
type: String as PropType<'flex' | 'calc'>,
|
|
74
85
|
default: 'calc'
|
|
86
|
+
},
|
|
87
|
+
/**
|
|
88
|
+
* 是否开启缓存
|
|
89
|
+
*/
|
|
90
|
+
cached: {
|
|
91
|
+
type: Boolean,
|
|
92
|
+
default: false
|
|
75
93
|
}
|
|
76
94
|
},
|
|
77
95
|
setup(_, { emit }) {
|
|
78
96
|
const dataId = `${generateID()}`;
|
|
79
97
|
const seperator = ref()
|
|
98
|
+
const instance = getCurrentInstance()?.proxy!
|
|
80
99
|
function handleDragSeperator(parentEl: HTMLElement, e: MouseEvent, idx: number) {
|
|
81
100
|
const { vertical } = getFlexDirection(parentEl);
|
|
82
101
|
const wOrH = vertical ? 'height' : 'width';
|
|
@@ -85,41 +104,67 @@ export default defineComponent({
|
|
|
85
104
|
const children = parentEl.querySelectorAll(`[data-${_.unique}]`) as ArrayLike<HTMLElement>;
|
|
86
105
|
const element = children[idx]!;
|
|
87
106
|
const prevElement = children[idx - 1]!;
|
|
88
|
-
|
|
89
107
|
const elementSize = element.dataset.dragLastSize = _getComputedStyle(element, wOrH);
|
|
90
108
|
const prevElementSize = prevElement.dataset.dragLastSize = _getComputedStyle(prevElement, wOrH);
|
|
109
|
+
const elementMinSize = _getComputedStyle(element, `min-${wOrH}`)!;
|
|
110
|
+
const prevElementMinSize = _getComputedStyle(prevElement, `min-${wOrH}`)!;
|
|
91
111
|
|
|
92
|
-
const totalStarSize = parseFloat(elementSize!)
|
|
112
|
+
const totalStarSize = add(parseFloat(elementSize!), parseFloat(prevElementSize!), 4)!;
|
|
113
|
+
if (_.cached) {
|
|
114
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique)
|
|
115
|
+
cached[idx] = element.dataset.dragLastSize
|
|
116
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize
|
|
117
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached)
|
|
118
|
+
}
|
|
119
|
+
element.style[wOrH] = element.style[wOrHSet] = elementSize!;
|
|
120
|
+
prevElement.style[wOrH] = prevElement.style[wOrHSet] = prevElementSize!;
|
|
121
|
+
let prevEvt = e;
|
|
93
122
|
|
|
94
|
-
|
|
95
|
-
|
|
123
|
+
const recordCached = debounce(() => {
|
|
124
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique)
|
|
125
|
+
cached[idx] = element.dataset.dragLastSize
|
|
126
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize
|
|
127
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached)
|
|
128
|
+
}, 100, false)
|
|
96
129
|
|
|
97
|
-
let prevEvt = e;
|
|
98
130
|
const moveHandle = async (_e: MouseEvent) => {
|
|
99
131
|
const screen = vertical ? 'screenY' : 'screenX';
|
|
100
132
|
const delta = _e[screen] - prevEvt[screen];
|
|
101
133
|
prevEvt = _e;
|
|
102
134
|
if (!delta) return;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || totalStarSize - deltaElementSize < _.resizeMinWidth)) {
|
|
135
|
+
const deltaElementSize = add(parseFloat(prevElement.dataset.dragLastSize!), delta, 4)!;
|
|
136
|
+
if (_.resizeMinWidth && (deltaElementSize < _.resizeMinWidth || subtract(totalStarSize, deltaElementSize, 4)! < _.resizeMinWidth)) {
|
|
106
137
|
return
|
|
107
138
|
}
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
139
|
+
if (elementMinSize.indexOf('px') > -1) {
|
|
140
|
+
if (subtract(totalStarSize, deltaElementSize, 4)! <= parseFloat(elementMinSize)) {
|
|
141
|
+
return
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
if (prevElementMinSize.indexOf('px') > -1) {
|
|
145
|
+
if (deltaElementSize <= parseFloat(prevElementMinSize)) {
|
|
146
|
+
return
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
prevElement.style[wOrH] = prevElement.style[wOrHSet] = `${deltaElementSize}px`;
|
|
150
|
+
element.style[wOrH] = element.style[wOrHSet] = `${subtract(totalStarSize, deltaElementSize, 4)}px`;
|
|
114
151
|
prevElement.dataset.dragLastSize = prevElement.style[wOrHSet];
|
|
115
152
|
element.dataset.dragLastSize = element.style[wOrHSet];
|
|
153
|
+
if (_.cached) {
|
|
154
|
+
recordCached()
|
|
155
|
+
}
|
|
116
156
|
};
|
|
117
157
|
const mouseupHandle = () => {
|
|
158
|
+
if (_.cached) {
|
|
159
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique)
|
|
160
|
+
cached[idx] = element.dataset.dragLastSize
|
|
161
|
+
cached[idx - 1] = prevElement.dataset.dragLastSize
|
|
162
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, cached)
|
|
163
|
+
}
|
|
118
164
|
document.removeEventListener('mousemove', moveHandle, false);
|
|
119
165
|
document.removeEventListener('mouseup', mouseupHandle, false);
|
|
120
166
|
emit('resize');
|
|
121
167
|
};
|
|
122
|
-
|
|
123
168
|
document.addEventListener('mousemove', moveHandle, false);
|
|
124
169
|
document.addEventListener('mouseup', mouseupHandle, false);
|
|
125
170
|
}
|
|
@@ -136,6 +181,45 @@ export default defineComponent({
|
|
|
136
181
|
}
|
|
137
182
|
return {}
|
|
138
183
|
})
|
|
184
|
+
onMounted(async () => {
|
|
185
|
+
const {
|
|
186
|
+
vertical
|
|
187
|
+
} = getFlexDirection(instance.$el! as HTMLElement);
|
|
188
|
+
const wOrH = vertical ? "height" : "width";
|
|
189
|
+
const wOrHSet = _.divideType === "flex" ? "flex-basis" : vertical ? "height" : "width";
|
|
190
|
+
const children = instance.$el.querySelectorAll(`[data-${_.unique}]`);
|
|
191
|
+
const arr: string[] = []
|
|
192
|
+
let realSum: number = 0
|
|
193
|
+
Array.from(children).forEach((_, index) => {
|
|
194
|
+
const elementSize = (children[index] as HTMLElement).dataset.dragLastSize = _getComputedStyle(children[index] as HTMLElement, wOrH)!;
|
|
195
|
+
arr.push(elementSize)
|
|
196
|
+
realSum = add(realSum, parseFloat(elementSize), 4)!
|
|
197
|
+
})
|
|
198
|
+
if (_.cached) {
|
|
199
|
+
const cached = LocalStorageUtil.getNfResizablePanelsCached(_.unique)
|
|
200
|
+
if (cached.length) {
|
|
201
|
+
if (cached.length === children.length) {
|
|
202
|
+
let sum: number = 0
|
|
203
|
+
cached.forEach(cachedItem => {
|
|
204
|
+
sum = add(sum, parseFloat(cachedItem), 4)!
|
|
205
|
+
})
|
|
206
|
+
if (Math.abs(sum - realSum) <= 4) {
|
|
207
|
+
cached.forEach((cachedItem, index) => {
|
|
208
|
+
const dom = children[index] as HTMLElement
|
|
209
|
+
dom.dataset.dragLastSize = cachedItem;
|
|
210
|
+
dom.style[wOrH] = dom.style[wOrHSet] = cachedItem;
|
|
211
|
+
})
|
|
212
|
+
return
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
LocalStorageUtil.setNfResizablePanelsCached(_.unique, arr)
|
|
217
|
+
}
|
|
218
|
+
arr.forEach((item, index) => {
|
|
219
|
+
const dom = children[index] as HTMLElement
|
|
220
|
+
dom.style[wOrH] = dom.style[wOrHSet] = item;
|
|
221
|
+
})
|
|
222
|
+
})
|
|
139
223
|
return { handleDragSeperator, dataId, size, seperator };
|
|
140
224
|
},
|
|
141
225
|
render() {
|
package/package/util.ts
ADDED
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/*
|
|
3
|
+
* 判断obj是否为一个整数
|
|
4
|
+
*/
|
|
5
|
+
export function isInteger(obj) {
|
|
6
|
+
return Math.floor(obj) === obj
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/*
|
|
10
|
+
* 将一个浮点数转成整数,返回整数和倍数。如 3.14 >> 314,倍数是 100
|
|
11
|
+
* @param floatNum {number} 小数
|
|
12
|
+
* @return {object}
|
|
13
|
+
* {times:100, num: 314}
|
|
14
|
+
*/
|
|
15
|
+
export function toInteger(floatNum) {
|
|
16
|
+
const ret = { times: 1, num: 0 }
|
|
17
|
+
if (isInteger(floatNum)) {
|
|
18
|
+
ret.num = floatNum
|
|
19
|
+
return ret
|
|
20
|
+
}
|
|
21
|
+
const strfi = floatNum + ''
|
|
22
|
+
const dotPos = strfi.indexOf('.')
|
|
23
|
+
const len = strfi.substr(dotPos + 1).length
|
|
24
|
+
const times = Math.pow(10, len)
|
|
25
|
+
const intNum = Number(floatNum.toString().replace('.', ''))
|
|
26
|
+
ret.times = times
|
|
27
|
+
ret.num = intNum
|
|
28
|
+
return ret
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/*
|
|
32
|
+
* 核心方法,实现加减乘除运算,确保不丢失精度
|
|
33
|
+
* 思路:把小数放大为整数(乘),进行算术运算,再缩小为小数(除)
|
|
34
|
+
*
|
|
35
|
+
* @param a {number} 运算数1
|
|
36
|
+
* @param b {number} 运算数2
|
|
37
|
+
* @param digits {number} 精度,保留的小数点数,比如 2, 即保留为两位小数
|
|
38
|
+
* @param op {string} 运算类型,有加减乘除(add/subtract/multiply/divide)
|
|
39
|
+
*
|
|
40
|
+
*/
|
|
41
|
+
export function operation(a, b, digits, op) {
|
|
42
|
+
const o1 = toInteger(a)
|
|
43
|
+
const o2 = toInteger(b)
|
|
44
|
+
const n1 = o1.num
|
|
45
|
+
const n2 = o2.num
|
|
46
|
+
const t1 = o1.times
|
|
47
|
+
const t2 = o2.times
|
|
48
|
+
const max = t1 > t2 ? t1 : t2
|
|
49
|
+
let result = null
|
|
50
|
+
switch (op) {
|
|
51
|
+
case 'add':
|
|
52
|
+
if (t1 === t2) { // 两个小数位数相同
|
|
53
|
+
result = n1 + n2
|
|
54
|
+
} else if (t1 > t2) { // o1 小数位 大于 o2
|
|
55
|
+
result = n1 + n2 * (t1 / t2)
|
|
56
|
+
} else { // o1 小数位 小于 o2
|
|
57
|
+
result = n1 * (t2 / t1) + n2
|
|
58
|
+
}
|
|
59
|
+
return result / max
|
|
60
|
+
case 'subtract':
|
|
61
|
+
if (t1 === t2) {
|
|
62
|
+
result = n1 - n2
|
|
63
|
+
} else if (t1 > t2) {
|
|
64
|
+
result = n1 - n2 * (t1 / t2)
|
|
65
|
+
} else {
|
|
66
|
+
result = n1 * (t2 / t1) - n2
|
|
67
|
+
}
|
|
68
|
+
return result / max
|
|
69
|
+
case 'multiply':
|
|
70
|
+
result = (n1 * n2) / (t1 * t2)
|
|
71
|
+
return result
|
|
72
|
+
case 'divide':
|
|
73
|
+
result = (n1 / n2) * (t2 / t1)
|
|
74
|
+
return result
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// 加减乘除的四个接口
|
|
79
|
+
export function add(a, b, digits) {
|
|
80
|
+
return operation(a, b, digits, 'add')
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export function subtract(a, b, digits) {
|
|
84
|
+
return operation(a, b, digits, 'subtract')
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function multiply(a, b, digits) {
|
|
88
|
+
return operation(a, b, digits, 'multiply')
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export function divide(a, b, digits) {
|
|
92
|
+
return operation(a, b, digits, 'divide')
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export class LocalStorageUtil {
|
|
96
|
+
static cachedKey = 'nf-resizable-panels'
|
|
97
|
+
|
|
98
|
+
static getNfResizablePanelsCached (key) {
|
|
99
|
+
const cached = localStorage.getItem(`${LocalStorageUtil.cachedKey}-${key}`)
|
|
100
|
+
if (cached) {
|
|
101
|
+
try {
|
|
102
|
+
return JSON.parse(cached)
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// console.log(e)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
return []
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
static setNfResizablePanelsCached (key, value) {
|
|
111
|
+
localStorage.setItem(`${LocalStorageUtil.cachedKey}-${key}`, JSON.stringify(value))
|
|
112
|
+
}
|
|
113
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@94ai/nf-resizable-panels",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.36",
|
|
4
4
|
"description": "> TODO: description",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "zoujiahe <zoujiahe@94ai.com>",
|
|
@@ -14,8 +14,8 @@
|
|
|
14
14
|
"url": "http://94ai.gitlab.com/zoujiahe/common-ui.git"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
|
-
"@94ai/common-utils": "^5.0.
|
|
18
|
-
"@94ai/nf-theme-chalk": "^5.0.
|
|
17
|
+
"@94ai/common-utils": "^5.0.36",
|
|
18
|
+
"@94ai/nf-theme-chalk": "^5.0.36",
|
|
19
19
|
"lodash-es": "^4.17.21",
|
|
20
20
|
"vue-demi": "^0.14.5"
|
|
21
21
|
},
|
|
@@ -32,5 +32,5 @@
|
|
|
32
32
|
"types": "lib/index.d.ts",
|
|
33
33
|
"main": "lib/nf-resizable-panels.cjs.js",
|
|
34
34
|
"module": "lib/nf-resizable-panels.esm-bundler.js",
|
|
35
|
-
"gitHead": "
|
|
35
|
+
"gitHead": "61f9750e0bbdfe0bd9191e47d4672b7bfa6be506"
|
|
36
36
|
}
|