uiik 1.1.0 → 1.3.0-alpha

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/splittable.js DELETED
@@ -1,340 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var _Splittable_instances, _Splittable_checkDirection, _Splittable_bindHandle;
7
- /* eslint-disable max-len */
8
- /**
9
- * splitter
10
- * @author holyhigh
11
- */
12
- import { isArray, isEmpty } from 'myfx/is';
13
- import { each, includes, map, reject } from 'myfx/collection';
14
- import { assign } from 'myfx/object';
15
- import { Uii } from './types';
16
- import { lockPage, restoreCursor, saveCursor, setCursor, unlockPage } from './utils';
17
- const THRESHOLD = 1;
18
- const CLASS_SPLITTABLE = "uii-splittable";
19
- const CLASS_SPLITTABLE_HANDLE = "uii-splittable-handle";
20
- const CLASS_SPLITTABLE_HANDLE_GHOST = "uii-splittable-handle-ghost";
21
- const CLASS_SPLITTABLE_HANDLE_ACTIVE = "uii-splittable-handle-active";
22
- const CLASS_SPLITTABLE_V = "uii-splittable-v";
23
- const CLASS_SPLITTABLE_H = "uii-splittable-h";
24
- function getRootEl(el, root) {
25
- let rs = el.parentNode;
26
- while (rs && rs.parentNode !== root) {
27
- rs = rs.parentNode;
28
- }
29
- return rs;
30
- }
31
- /**
32
- * 用于表示一个或多个分割器的定义
33
- * > 可用CSS接口
34
- * - .uii-splittable
35
- * - .uii-splittable-handle
36
- * - .uii-splittable-handle-ghost
37
- * - .uii-splittable-handle-active
38
- * - .uii-splittable-v
39
- * - .uii-splittable-h
40
- * @public
41
- */
42
- export class Splittable extends Uii {
43
- constructor(container, opts) {
44
- super(container, assign({
45
- handleSize: 10,
46
- minSize: 0,
47
- sticky: false,
48
- inside: false,
49
- ghost: false
50
- }, opts));
51
- _Splittable_instances.add(this);
52
- each(this.ele, con => {
53
- //detect container position
54
- const pos = window.getComputedStyle(con).position;
55
- if (pos === "static") {
56
- con.style.position = "relative";
57
- }
58
- con.classList.toggle(CLASS_SPLITTABLE, true);
59
- const handleDoms = con.querySelectorAll(this.opts.handle);
60
- const children = reject(con.children, c => {
61
- if (includes(handleDoms, c))
62
- return true;
63
- return false;
64
- });
65
- const dir = __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_checkDirection).call(this, con);
66
- con.classList.toggle(dir === 'v' ? CLASS_SPLITTABLE_V : CLASS_SPLITTABLE_H, true);
67
- const minSizeAry = map(children, (c, i) => {
68
- if (isArray(this.opts.minSize)) {
69
- return this.opts.minSize[i] || 0;
70
- }
71
- else {
72
- return this.opts.minSize;
73
- }
74
- });
75
- const stickyAry = map(children, (c, i) => {
76
- if (isArray(this.opts.sticky)) {
77
- return this.opts.sticky[i] || false;
78
- }
79
- else {
80
- return this.opts.sticky;
81
- }
82
- });
83
- if (isEmpty(handleDoms)) {
84
- const len = children.length - 1;
85
- for (let i = 0; i < len; i++) {
86
- __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, children[i], children[i + 1]);
87
- }
88
- }
89
- else {
90
- each(handleDoms, (h, i) => {
91
- const isRoot = h.parentNode.classList.contains(CLASS_SPLITTABLE);
92
- let dom1, dom2;
93
- if (isRoot) {
94
- dom1 = h.previousElementSibling;
95
- dom2 = h.nextElementSibling;
96
- }
97
- else {
98
- dom2 = getRootEl(h, con);
99
- dom1 = dom2.previousElementSibling;
100
- }
101
- __classPrivateFieldGet(this, _Splittable_instances, "m", _Splittable_bindHandle).call(this, minSizeAry.slice(i, i + 2), stickyAry.slice(i, i + 2), this.opts, dir, dom1, dom2, h);
102
- });
103
- }
104
- });
105
- }
106
- }
107
- _Splittable_instances = new WeakSet(), _Splittable_checkDirection = function _Splittable_checkDirection(container) {
108
- let dir = 'h';
109
- const child = container.children[0];
110
- let lastY = child.offsetTop;
111
- each(container.children, c => {
112
- if (c.offsetTop != lastY) {
113
- dir = 'v';
114
- return false;
115
- }
116
- });
117
- return dir;
118
- }, _Splittable_bindHandle = function _Splittable_bindHandle(minSizeAry, stickyAry, opts, dir, dom1, dom2, handle) {
119
- var _a;
120
- const handleSize = opts.handleSize;
121
- if (!handle) {
122
- handle = document.createElement('div');
123
- let initPos = 0;
124
- if (!opts.inside) {
125
- initPos = (dir === 'v' ? dom2.offsetTop : dom2.offsetLeft);
126
- }
127
- const sensorHCss = `width:${handleSize}px;height:100%;top:0;left:${initPos - handleSize / 2}px;z-index:9;`;
128
- const sensorVCss = `height:${handleSize}px;width:100%;left:0;top:${initPos - handleSize / 2}px;z-index:9;`;
129
- handle.style.cssText =
130
- 'position: absolute;' + (dir === 'v' ? sensorVCss : sensorHCss);
131
- if (opts.inside) {
132
- dom2.appendChild(handle);
133
- }
134
- (_a = dom2.parentNode) === null || _a === void 0 ? void 0 : _a.insertBefore(handle, dom2);
135
- }
136
- handle.style.cursor = dir === 'v' ? 's-resize' : 'e-resize';
137
- handle.dataset.cursor = handle.style.cursor;
138
- handle.classList.add(CLASS_SPLITTABLE_HANDLE);
139
- const minSize1 = minSizeAry[0];
140
- const minSize2 = minSizeAry[1];
141
- let sticky1 = stickyAry[0];
142
- let sticky2 = stickyAry[1];
143
- const onStart = opts.onStart;
144
- const onSplit = opts.onSplit;
145
- const onEnd = opts.onEnd;
146
- const onSticky = opts.onSticky;
147
- const onClone = opts.onClone;
148
- const oneSideMode = opts.oneSideMode;
149
- const updateStart = !oneSideMode || oneSideMode === 'start';
150
- const updateEnd = !oneSideMode || oneSideMode === 'end';
151
- handle.onmousedown = function (e) {
152
- // 1. 获取原始高度/宽度;设置宽度/高度
153
- let originSize = 0;
154
- let originSize1 = 0;
155
- const originPosX = e.clientX;
156
- const originPosY = e.clientY;
157
- let splitterSize = 1;
158
- let blockSize = 0; // 分割区size
159
- switch (dir) {
160
- case 'v':
161
- originSize = dom1.offsetHeight;
162
- originSize1 = dom2.offsetHeight;
163
- splitterSize = handle.offsetHeight;
164
- break;
165
- case 'h':
166
- originSize = dom1.offsetWidth;
167
- originSize1 = dom2.offsetWidth;
168
- splitterSize = handle.offsetWidth;
169
- break;
170
- }
171
- blockSize = splitterSize + originSize + originSize1;
172
- const dom1Style = dom1.style;
173
- const dom2Style = dom2.style;
174
- //ghost
175
- const ghost = opts.ghost;
176
- const ghostClass = opts.ghostClass;
177
- let ghostNode = null;
178
- // 初始化sticked位置
179
- let sticked = 'none';
180
- if (originSize < minSize1 / 2) {
181
- sticked = 'start';
182
- }
183
- else if (blockSize - originSize - splitterSize < minSize2 / 2) {
184
- sticked = 'end';
185
- }
186
- let dragging = false;
187
- saveCursor();
188
- let startPos = dir === 'v' ? dom1.offsetTop : dom1.offsetLeft;
189
- let ds1, anotherSize;
190
- const dragListener = (ev) => {
191
- var _a;
192
- const offsetx = ev.clientX - originPosX;
193
- const offsety = ev.clientY - originPosY;
194
- if (!dragging) {
195
- if (Math.abs(offsetx) > THRESHOLD || Math.abs(offsety) > THRESHOLD) {
196
- dragging = true;
197
- handle === null || handle === void 0 ? void 0 : handle.classList.add(CLASS_SPLITTABLE_HANDLE_ACTIVE);
198
- if (ghost) {
199
- ghostNode = handle.cloneNode(true);
200
- ghostNode.style.opacity = '0.3';
201
- ghostNode.style.pointerEvents = 'none';
202
- ghostNode.classList.add(CLASS_SPLITTABLE_HANDLE_GHOST);
203
- if (ghostNode) {
204
- if (ghostClass) {
205
- ghostNode.className =
206
- ghostNode.className.replace(ghostClass, '') + ' ' + ghostClass;
207
- }
208
- (_a = handle === null || handle === void 0 ? void 0 : handle.parentNode) === null || _a === void 0 ? void 0 : _a.appendChild(ghostNode);
209
- onClone && onClone({ clone: ghostNode }, e);
210
- }
211
- }
212
- lockPage();
213
- setCursor((handle === null || handle === void 0 ? void 0 : handle.dataset.cursor) || '');
214
- onStart && onStart({ size1: originSize, size2: originSize1 }, ev);
215
- }
216
- else {
217
- ev.preventDefault();
218
- return false;
219
- }
220
- }
221
- let doSticky = false;
222
- ds1 = dir === 'v' ? originSize + offsety : originSize + offsetx;
223
- if (ds1 < minSize1 / 2 && sticky1 && minSize1 > 0) {
224
- if (sticked == 'none') {
225
- doSticky = true;
226
- sticked = 'start';
227
- }
228
- ds1 = 0;
229
- }
230
- else if (ds1 < minSize1) {
231
- ds1 = minSize1;
232
- if (sticked == 'start' && sticky1) {
233
- // 重置状态
234
- doSticky = true;
235
- sticked = 'none';
236
- }
237
- }
238
- else if (blockSize - ds1 - splitterSize < minSize2 / 2 &&
239
- sticky2) {
240
- if (sticked == 'none') {
241
- doSticky = true;
242
- sticked = 'end';
243
- }
244
- ds1 = blockSize - splitterSize;
245
- }
246
- else if (blockSize - ds1 - splitterSize < minSize2) {
247
- ds1 = blockSize - minSize2 - splitterSize;
248
- if (sticked == 'end' && sticky2) {
249
- // 重置状态
250
- doSticky = true;
251
- sticked = 'none';
252
- }
253
- }
254
- anotherSize = blockSize - ds1 - splitterSize;
255
- if (ghostNode) {
256
- if (dir === 'v') {
257
- ghostNode.style.top = startPos + ds1 - handleSize / 2 + 'px';
258
- }
259
- else {
260
- ghostNode.style.left = startPos + ds1 - handleSize / 2 + 'px';
261
- }
262
- }
263
- else {
264
- const updateProp = dir === 'v' ? 'height' : 'width';
265
- if (updateStart) {
266
- dom1Style.setProperty(updateProp, ds1 + 'px', 'important');
267
- }
268
- if (updateEnd) {
269
- dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
270
- }
271
- if (doSticky) {
272
- onSticky && onSticky({ size1: ds1, size2: anotherSize, position: sticked }, ev);
273
- }
274
- //update handle
275
- if (dir === 'v') {
276
- handle.style.top = dom2.offsetTop - handleSize / 2 + 'px';
277
- }
278
- else {
279
- handle.style.left = dom2.offsetLeft - handleSize / 2 + 'px';
280
- }
281
- }
282
- onSplit && onSplit({ size1: ds1, size2: anotherSize }, ev);
283
- ev.preventDefault();
284
- return false;
285
- };
286
- const dragEndListener = (ev) => {
287
- var _a, _b;
288
- document.removeEventListener('mousemove', dragListener, false);
289
- document.removeEventListener('mouseup', dragEndListener, false);
290
- window.removeEventListener('blur', dragEndListener, false);
291
- if (dragging) {
292
- switch (dir) {
293
- case 'v':
294
- originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetHeight) || -1;
295
- originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetHeight) || -1;
296
- break;
297
- case 'h':
298
- originSize = (dom1 === null || dom1 === void 0 ? void 0 : dom1.offsetWidth) || -1;
299
- originSize1 = (dom2 === null || dom2 === void 0 ? void 0 : dom2.offsetWidth) || -1;
300
- break;
301
- }
302
- handle === null || handle === void 0 ? void 0 : handle.classList.remove(CLASS_SPLITTABLE_HANDLE_ACTIVE);
303
- if (ghostNode) {
304
- const updateProp = dir === 'v' ? 'height' : 'width';
305
- if (updateStart) {
306
- dom1Style.setProperty(updateProp, ds1 + 'px', 'important');
307
- }
308
- if (updateEnd) {
309
- dom2Style.setProperty(updateProp, anotherSize + 'px', 'important');
310
- }
311
- //update handle
312
- if (dir === 'v') {
313
- handle.style.top = startPos + ds1 - handleSize / 2 + 'px';
314
- }
315
- else {
316
- handle.style.left = startPos + ds1 - handleSize / 2 + 'px';
317
- }
318
- ((_a = ghostNode.parentNode) === null || _a === void 0 ? void 0 : _a.contains(ghostNode)) && ((_b = ghostNode.parentNode) === null || _b === void 0 ? void 0 : _b.removeChild(ghostNode));
319
- }
320
- unlockPage();
321
- restoreCursor();
322
- onEnd && onEnd({ size1: originSize, size2: originSize1 }, ev);
323
- }
324
- };
325
- document.addEventListener('mousemove', dragListener, false);
326
- document.addEventListener('mouseup', dragEndListener, false);
327
- window.addEventListener('blur', dragEndListener, false);
328
- e.preventDefault();
329
- return false;
330
- };
331
- };
332
- /**
333
- * Add one or more splittors into the container
334
- * @param container css selector or html element
335
- * @param opts SplittableOptions
336
- * @returns
337
- */
338
- export function newSplittable(container, opts) {
339
- return new Splittable(container, opts);
340
- }
package/types.js DELETED
@@ -1,116 +0,0 @@
1
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
2
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
3
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
4
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
- };
6
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
7
- if (kind === "m") throw new TypeError("Private method is not writable");
8
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
9
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
10
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
11
- };
12
- var _Uii_listeners;
13
- import { isElement, isString, isArrayLike } from 'myfx/is';
14
- import { each, map, toArray } from 'myfx/collection';
15
- import { assign } from 'myfx/object';
16
- /**
17
- * A Base class for all Uii classes
18
- */
19
- export class Uii {
20
- constructor(ele, opts) {
21
- this.enabled = true;
22
- _Uii_listeners.set(this, []);
23
- this.opts = opts || {};
24
- if (isArrayLike(ele) && !isString(ele)) {
25
- this.ele = map(ele, (el) => {
26
- let e = isString(el) ? document.querySelector(el) : el;
27
- if (!isElement(e)) {
28
- console.error('Invalid element "' + el + '"');
29
- return false;
30
- }
31
- return e;
32
- });
33
- }
34
- else {
35
- const el = isString(ele) ? document.querySelectorAll(ele) : ele;
36
- if (!isElement(el) && !isArrayLike(el)) {
37
- console.error('Invalid element "' + ele + '"');
38
- return;
39
- }
40
- this.ele = isArrayLike(el) ? toArray(el) : [el];
41
- }
42
- }
43
- /**
44
- * 销毁uii对象,包括卸载事件、清空元素等
45
- */
46
- destroy() {
47
- each(__classPrivateFieldGet(this, _Uii_listeners, "f"), (ev) => {
48
- ev[0].removeEventListener(ev[1], ev[2], ev[3]);
49
- });
50
- __classPrivateFieldSet(this, _Uii_listeners, [], "f");
51
- }
52
- /**
53
- * 注册事件,以便在{@link destroy}方法中卸载
54
- * @param el dom元素
55
- * @param event 事件名
56
- * @param hook 回调函数
57
- * @param useCapture 默认false
58
- */
59
- registerEvent(el, event, hook, useCapture = false) {
60
- const wrapper = ((ev) => {
61
- if (!this.enabled)
62
- return;
63
- hook(ev);
64
- }).bind(this);
65
- el.addEventListener(event, wrapper, useCapture);
66
- __classPrivateFieldGet(this, _Uii_listeners, "f").push([el, event, wrapper, useCapture]);
67
- }
68
- /**
69
- * 禁用uii实例,禁用后的dom不会响应事件
70
- */
71
- disable() {
72
- this.enabled = false;
73
- }
74
- /**
75
- * 启用uii实例
76
- */
77
- enable() {
78
- this.enabled = true;
79
- }
80
- /**
81
- * 获取uii实例选项对象
82
- */
83
- getOptions() {
84
- return this.opts;
85
- }
86
- /**
87
- * 获取指定名称的选项值
88
- * @param name
89
- * @returns
90
- */
91
- getOption(name) {
92
- return this.opts[name];
93
- }
94
- /**
95
- * 设置多个选项值。触发`onOptionChanged`
96
- * @param options
97
- */
98
- setOptions(options) {
99
- assign(this.opts, options);
100
- this.onOptionChanged(this.opts);
101
- }
102
- /**
103
- * 设置指定name的选项值。触发`onOptionChanged`
104
- * @param name
105
- * @param value
106
- */
107
- setOption(name, value) {
108
- this.opts[name] = value;
109
- this.onOptionChanged(this.opts);
110
- }
111
- /**
112
- * @internal
113
- */
114
- onOptionChanged(opts) { }
115
- }
116
- _Uii_listeners = new WeakMap();
package/utils.js DELETED
@@ -1,58 +0,0 @@
1
- /* eslint-disable max-len */
2
- /**
3
- * 工具包
4
- * @author holyhigh2
5
- */
6
- import { find } from "myfx/collection";
7
- /**
8
- * 获取child相对于parent的offset信息。含border宽度
9
- * @returns
10
- */
11
- export function getOffset(child, parent) {
12
- const rs = { x: 0, y: 0 };
13
- let op = child.offsetParent;
14
- while (op && parent && op !== parent) {
15
- const style = window.getComputedStyle(op);
16
- rs.x += op.offsetLeft + parseFloat(style.borderLeftWidth);
17
- rs.y += op.offsetTop + parseFloat(style.borderTopWidth);
18
- op = op.offsetParent;
19
- }
20
- rs.x += child.offsetLeft;
21
- rs.y += child.offsetTop;
22
- return rs;
23
- }
24
- /**
25
- * 边缘检测最小内部边距
26
- */
27
- export const EDGE_THRESHOLD = 5;
28
- export const DRAGGING_RULE = "body * { pointer-events: none; }";
29
- let lockSheet;
30
- export function lockPage() {
31
- lockSheet = getFirstSS();
32
- lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.insertRule(DRAGGING_RULE, 0);
33
- }
34
- export function unlockPage() {
35
- lockSheet === null || lockSheet === void 0 ? void 0 : lockSheet.deleteRule(0);
36
- }
37
- function getFirstSS() {
38
- if (document.styleSheets.length < 1) {
39
- document.head.appendChild(document.createElement('style'));
40
- }
41
- const sheet = find(document.styleSheets, ss => !ss.href);
42
- if (!sheet) {
43
- document.head.appendChild(document.createElement('style'));
44
- }
45
- return sheet || find(document.styleSheets, ss => !ss.href);
46
- }
47
- let cursor = { html: '', body: '' };
48
- export function saveCursor() {
49
- cursor.body = document.body.style.cursor;
50
- cursor.html = document.documentElement.style.cursor;
51
- }
52
- export function setCursor(cursor) {
53
- document.body.style.cursor = document.documentElement.style.cursor = cursor;
54
- }
55
- export function restoreCursor() {
56
- document.body.style.cursor = cursor.body;
57
- document.documentElement.style.cursor = cursor.html;
58
- }