@cocreate/resize 1.18.0 → 2.0.0
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/.github/FUNDING.yml +1 -1
- package/.github/workflows/automated.yml +18 -7
- package/CHANGELOG.md +531 -498
- package/CONTRIBUTING.md +6 -6
- package/README.md +17 -17
- package/demo/dashboard.html +2 -2
- package/demo/index.html +2 -2
- package/docs/index.html +7 -7
- package/package.json +7 -7
- package/src/index.css +102 -39
- package/src/index.js +757 -667
- package/webpack.config.js +1 -1
package/src/index.js
CHANGED
|
@@ -3,9 +3,9 @@ import observer from "@cocreate/observer";
|
|
|
3
3
|
import "./index.css";
|
|
4
4
|
|
|
5
5
|
const EVENTS = [
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
"mousemove touchmove",
|
|
7
|
+
"mousedown touchstart",
|
|
8
|
+
"mouseup touchend"
|
|
9
9
|
];
|
|
10
10
|
const DIRECTIONS = ["left", "right", "top", "bottom"];
|
|
11
11
|
|
|
@@ -15,702 +15,792 @@ document.head.appendChild(styleEl);
|
|
|
15
15
|
const styleSheet = styleEl.sheet;
|
|
16
16
|
|
|
17
17
|
const coCreateResize = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
18
|
+
/**
|
|
19
|
+
* CSS selector used by init() to find resizable elements.
|
|
20
|
+
* @public
|
|
21
|
+
* @environment client
|
|
22
|
+
* @type {string}
|
|
23
|
+
*/
|
|
24
|
+
selector: "", //'.resize',
|
|
25
|
+
/**
|
|
26
|
+
* Elements matched by the current selector.
|
|
27
|
+
* @public
|
|
28
|
+
* @environment client
|
|
29
|
+
* @type {NodeList<Element>}
|
|
30
|
+
*/
|
|
31
|
+
resizers: [],
|
|
32
|
+
/**
|
|
33
|
+
* Resize controller instances created for matching elements.
|
|
34
|
+
* @public
|
|
35
|
+
* @environment client
|
|
36
|
+
* @type {CoCreateResize[]}
|
|
37
|
+
*/
|
|
38
|
+
resizeWidgets: [],
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Initializes resize controllers for elements matching handleObj.selector.
|
|
42
|
+
*
|
|
43
|
+
* @public
|
|
44
|
+
* @environment client
|
|
45
|
+
* @param {Object} handleObj - Selector and resize-handle selectors.
|
|
46
|
+
*/
|
|
47
|
+
init: function (handleObj) {
|
|
48
|
+
for (var handleKey in handleObj)
|
|
49
|
+
if (handleObj.hasOwnProperty(handleKey) && handleKey == "selector")
|
|
50
|
+
this.selector = handleObj[handleKey];
|
|
51
|
+
|
|
52
|
+
this.resizers = document.querySelectorAll(this.selector);
|
|
53
|
+
var _this = this;
|
|
54
|
+
this.resizers.forEach(function (resize, idx) {
|
|
55
|
+
let resizeWidget = new CoCreateResize(resize, handleObj);
|
|
56
|
+
_this.resizeWidgets[idx] = resizeWidget;
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Initializes a resize controller for one element using the default handle selectors.
|
|
62
|
+
*
|
|
63
|
+
* @public
|
|
64
|
+
* @environment client
|
|
65
|
+
* @param {Element} target - Element to make resizable.
|
|
66
|
+
*/
|
|
67
|
+
initElement: function (target) {
|
|
68
|
+
let resizeWidget = new CoCreateResize(target, {
|
|
69
|
+
dragLeft: "[resize='left']",
|
|
70
|
+
dragRight: "[resize='right']",
|
|
71
|
+
dragTop: "[resize='top']",
|
|
72
|
+
dragBottom: "[resize='bottom']"
|
|
73
|
+
});
|
|
74
|
+
this.resizeWidgets[0] = resizeWidget;
|
|
75
|
+
}
|
|
44
76
|
};
|
|
45
77
|
|
|
46
78
|
function CoCreateResize(resizer, options) {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
79
|
+
this.resizeWidget = resizer;
|
|
80
|
+
this.cornerSize = 10;
|
|
81
|
+
this.init(options);
|
|
50
82
|
}
|
|
51
83
|
|
|
52
84
|
CoCreateResize.prototype = {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
if (height)
|
|
575
|
-
CoCreate.text.setStyle({
|
|
576
|
-
domTextEditor,
|
|
577
|
-
target: this.resizeWidget,
|
|
578
|
-
property: "height",
|
|
579
|
-
value: height + "px"
|
|
580
|
-
});
|
|
581
|
-
if (rowEnd)
|
|
582
|
-
CoCreate.text.setStyle({
|
|
583
|
-
domTextEditor,
|
|
584
|
-
target: this.resizeWidget,
|
|
585
|
-
property: "grid-row-end",
|
|
586
|
-
value: "span " + rowEnd
|
|
587
|
-
});
|
|
588
|
-
if (columnEnd)
|
|
589
|
-
CoCreate.text.setStyle({
|
|
590
|
-
domTextEditor,
|
|
591
|
-
target: this.resizeWidget,
|
|
592
|
-
property: "grid-column-end",
|
|
593
|
-
value: "span " + columnEnd
|
|
594
|
-
});
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
}
|
|
85
|
+
init: function (handleObj) {
|
|
86
|
+
if (this.resizeWidget) {
|
|
87
|
+
this.initDrags = [];
|
|
88
|
+
this.checkCorners = [];
|
|
89
|
+
this.doDrags = [];
|
|
90
|
+
this.Drags = [];
|
|
91
|
+
|
|
92
|
+
//this is for grid
|
|
93
|
+
this.isGrid = this.detectGrid();
|
|
94
|
+
this.gridWidth = 0;
|
|
95
|
+
this.gridHeight = 0;
|
|
96
|
+
this.limitSpan = 0;
|
|
97
|
+
this.widthSpan = 0;
|
|
98
|
+
this.heightSpan = 0;
|
|
99
|
+
this.originClassAttribute = this.resizeWidget.getAttribute("class");
|
|
100
|
+
|
|
101
|
+
DIRECTIONS.map((d) => {
|
|
102
|
+
this.Drags[d] = this.resizeWidget.querySelector(
|
|
103
|
+
handleObj["drag" + d.charAt(0).toUpperCase() + d.slice(1)]
|
|
104
|
+
);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
this.bindListeners();
|
|
108
|
+
this.initResize();
|
|
109
|
+
|
|
110
|
+
//this is just for grid system
|
|
111
|
+
this.getGridProperty();
|
|
112
|
+
window.addEventListener("resize", this.checkGridColumns.bind(this));
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
|
|
116
|
+
getGridProperty: function () {
|
|
117
|
+
if (!this.resizeWidget.parentNode) return;
|
|
118
|
+
let compStyles = window.getComputedStyle(this.resizeWidget.parentNode);
|
|
119
|
+
let gridColumns = compStyles.gridTemplateColumns;
|
|
120
|
+
let height = compStyles.gridAutoRows;
|
|
121
|
+
|
|
122
|
+
if (gridColumns !== "none") {
|
|
123
|
+
let width = gridColumns.split(" ");
|
|
124
|
+
this.limitSpan = width.length;
|
|
125
|
+
this.gridColumnGap = Number.parseInt(compStyles.gridColumnGap);
|
|
126
|
+
this.gridRowGap = Number.parseInt(compStyles.gridRowGap);
|
|
127
|
+
this.gridWidth = Number.parseFloat(width[0]);
|
|
128
|
+
this.gridHeight = Number.parseInt(height);
|
|
129
|
+
}
|
|
130
|
+
},
|
|
131
|
+
|
|
132
|
+
checkGridColumns: function () {
|
|
133
|
+
if (
|
|
134
|
+
typeof this.resizeWidget !== "undefined" &&
|
|
135
|
+
this.resizeWidget.parentNode
|
|
136
|
+
) {
|
|
137
|
+
let compStylesOfParent = window.getComputedStyle(
|
|
138
|
+
this.resizeWidget.parentNode
|
|
139
|
+
);
|
|
140
|
+
let spans = 0;
|
|
141
|
+
let gridColumns = compStylesOfParent.gridTemplateColumns.split(" ");
|
|
142
|
+
let temp = gridColumns[0];
|
|
143
|
+
gridColumns.map((v) => {
|
|
144
|
+
if (v == temp) spans++;
|
|
145
|
+
});
|
|
146
|
+
this.limitSpan = spans;
|
|
147
|
+
if (this.resizeWidget.style["grid-column-end"]) {
|
|
148
|
+
let curClassAttributes = this.resizeWidget
|
|
149
|
+
.getAttribute("class")
|
|
150
|
+
.split(" ");
|
|
151
|
+
let prevColumnState =
|
|
152
|
+
curClassAttributes[curClassAttributes.length - 1].split(
|
|
153
|
+
"_"
|
|
154
|
+
);
|
|
155
|
+
let prevSpan = Number.parseInt(prevColumnState[1]);
|
|
156
|
+
let curColumnState =
|
|
157
|
+
this.resizeWidget.style["grid-column-end"].split(" ");
|
|
158
|
+
let curSpan = Number.parseInt(curColumnState[1]);
|
|
159
|
+
|
|
160
|
+
let span = 0;
|
|
161
|
+
if (this.limitSpan >= prevSpan) span = prevSpan;
|
|
162
|
+
else if (prevSpan > this.limitSpan) span = this.limitSpan;
|
|
163
|
+
else span = Math.min(curSpan, this.limitSpan);
|
|
164
|
+
|
|
165
|
+
this.resizeWidget.style["grid-column-end"] = "span " + span;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
|
|
170
|
+
initResize: function () {
|
|
171
|
+
DIRECTIONS.map((d) => {
|
|
172
|
+
if (this.Drags[d])
|
|
173
|
+
this.addListenerMulti(
|
|
174
|
+
this.Drags[d],
|
|
175
|
+
EVENTS[0],
|
|
176
|
+
this.checkCorners[d]
|
|
177
|
+
);
|
|
178
|
+
});
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
checkDragImplementation: function (e, from, to, offset, fcur, scur) {
|
|
182
|
+
if (e.touches) e = e.touches[0];
|
|
183
|
+
let other;
|
|
184
|
+
if (to == "top") other = "bottom";
|
|
185
|
+
else if (to == "bottom") other = "top";
|
|
186
|
+
else if (to == "left") other = "right";
|
|
187
|
+
else if (to == "right") other = "left";
|
|
188
|
+
this.removeListenerMulti(
|
|
189
|
+
this.Drags[from],
|
|
190
|
+
EVENTS[1],
|
|
191
|
+
this.initDrags[from]
|
|
192
|
+
);
|
|
193
|
+
this.removeListenerMulti(
|
|
194
|
+
this.Drags[from],
|
|
195
|
+
EVENTS[1],
|
|
196
|
+
this.initDrags[to]
|
|
197
|
+
);
|
|
198
|
+
this.removeListenerMulti(
|
|
199
|
+
this.Drags[from],
|
|
200
|
+
EVENTS[1],
|
|
201
|
+
this.initDrags[other]
|
|
202
|
+
);
|
|
203
|
+
this.addListenerMulti(
|
|
204
|
+
this.Drags[from],
|
|
205
|
+
EVENTS[1],
|
|
206
|
+
this.initDrags[from]
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
if (offset < this.cornerSize && this.Drags[to]) {
|
|
210
|
+
this.Drags[from].style.cursor = fcur;
|
|
211
|
+
this.addListenerMulti(
|
|
212
|
+
this.Drags[from],
|
|
213
|
+
EVENTS[1],
|
|
214
|
+
this.initDrags[to]
|
|
215
|
+
);
|
|
216
|
+
} else {
|
|
217
|
+
this.Drags[from].style.cursor = scur;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
|
|
221
|
+
initDrag: function (e, idx) {
|
|
222
|
+
e.preventDefault();
|
|
223
|
+
|
|
224
|
+
if (!this.resizeWidget.hasAttribute("resizing")) {
|
|
225
|
+
this.resizeWidget.setAttribute("resizing", "");
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
let selector = document.defaultView.getComputedStyle(this.resizeWidget);
|
|
229
|
+
styleSheet.insertRule("iframe {pointer-events: none}", 0);
|
|
230
|
+
|
|
231
|
+
if (idx == "top" || idx == "bottom") {
|
|
232
|
+
this.startTop = parseInt(selector.top, 10);
|
|
233
|
+
this.startHeight = parseInt(selector.height, 10);
|
|
234
|
+
|
|
235
|
+
if (e.touches) this.startY = e.touches[0].clientY;
|
|
236
|
+
else this.startY = e.clientY;
|
|
237
|
+
} else {
|
|
238
|
+
this.startLeft = parseInt(selector.left, 10);
|
|
239
|
+
this.startRight = parseInt(selector.right, 10);
|
|
240
|
+
this.startWidth = parseInt(selector.width, 10);
|
|
241
|
+
|
|
242
|
+
if (e.touches) this.startX = e.touches[0].clientX;
|
|
243
|
+
else this.startX = e.clientX;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
this.addListenerMulti(
|
|
247
|
+
document.documentElement,
|
|
248
|
+
EVENTS[0],
|
|
249
|
+
this.doDrags[idx]
|
|
250
|
+
);
|
|
251
|
+
this.addListenerMulti(
|
|
252
|
+
document.documentElement,
|
|
253
|
+
EVENTS[2],
|
|
254
|
+
this.stopDrag
|
|
255
|
+
);
|
|
256
|
+
},
|
|
257
|
+
|
|
258
|
+
initTopDrag: function (e) {
|
|
259
|
+
this.initDrag(e, "top");
|
|
260
|
+
},
|
|
261
|
+
initBottomDrag: function (e) {
|
|
262
|
+
this.initDrag(e, "bottom");
|
|
263
|
+
},
|
|
264
|
+
initLeftDrag: function (e) {
|
|
265
|
+
this.initDrag(e, "left");
|
|
266
|
+
},
|
|
267
|
+
initRightDrag: function (e) {
|
|
268
|
+
this.initDrag(e, "right");
|
|
269
|
+
},
|
|
270
|
+
|
|
271
|
+
//this is just for grid system
|
|
272
|
+
setRowEnd: function (height) {
|
|
273
|
+
if (this.gridHeight) {
|
|
274
|
+
this.heightSpan = Math.ceil(
|
|
275
|
+
(height - (this.heightSpan - 1) * this.gridRowGap) /
|
|
276
|
+
this.gridHeight
|
|
277
|
+
);
|
|
278
|
+
this.resizeWidget.style["grid-row-end"] = "span " + this.heightSpan;
|
|
279
|
+
this.collaborate({ rowEnd: this.heightSpan });
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
|
|
283
|
+
doTopDrag: function (e) {
|
|
284
|
+
let top, height;
|
|
285
|
+
|
|
286
|
+
if (e.touches) e = e.touches[0];
|
|
287
|
+
top = this.startTop + e.clientY - this.startY;
|
|
288
|
+
height = this.startHeight - e.clientY + this.startY;
|
|
289
|
+
|
|
290
|
+
if (height < 10) return;
|
|
291
|
+
if (!this.isGrid) {
|
|
292
|
+
this.resizeWidget.style.top = top + "px";
|
|
293
|
+
this.collaborate({ top, height });
|
|
294
|
+
}
|
|
295
|
+
this.resizeWidget.style.height = height + "px";
|
|
296
|
+
this.setRowEnd(height);
|
|
297
|
+
},
|
|
298
|
+
|
|
299
|
+
doBottomDrag: function (e) {
|
|
300
|
+
let height;
|
|
301
|
+
|
|
302
|
+
if (e.touches) e = e.touches[0];
|
|
303
|
+
|
|
304
|
+
height = this.startHeight + e.clientY - this.startY;
|
|
305
|
+
|
|
306
|
+
if (height < 10) return;
|
|
307
|
+
if (!this.isGrid) this.collaborate({ height });
|
|
308
|
+
|
|
309
|
+
this.resizeWidget.style.height = height + "px";
|
|
310
|
+
this.setRowEnd(height);
|
|
311
|
+
},
|
|
312
|
+
|
|
313
|
+
//this is just for grid system
|
|
314
|
+
setColumnEnd: function (width) {
|
|
315
|
+
if (this.gridWidth) {
|
|
316
|
+
let spans = Math.ceil(
|
|
317
|
+
(width - (this.widthSpan - 1) * this.gridColumnGap) /
|
|
318
|
+
this.gridWidth
|
|
319
|
+
);
|
|
320
|
+
this.widthSpan = spans > this.limitSpan ? this.limitSpan : spans;
|
|
321
|
+
this.resizeWidget.style["grid-column-end"] =
|
|
322
|
+
"span " + this.widthSpan;
|
|
323
|
+
this.collaborate({ columnEnd: this.widthSpan });
|
|
324
|
+
}
|
|
325
|
+
},
|
|
326
|
+
|
|
327
|
+
doLeftDrag: function (e) {
|
|
328
|
+
let left, right, width;
|
|
329
|
+
if (e.touches) e = e.touches[0];
|
|
330
|
+
left = this.startLeft + e.clientX - this.startX;
|
|
331
|
+
right = this.startRight;
|
|
332
|
+
width = this.startWidth - e.clientX + this.startX;
|
|
333
|
+
|
|
334
|
+
if (width < 10) return;
|
|
335
|
+
if (!this.isGrid) {
|
|
336
|
+
this.resizeWidget.style.left = "";
|
|
337
|
+
this.resizeWidget.style.right = right + "px";
|
|
338
|
+
this.collaborate({ left, width });
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
this.resizeWidget.style.width = width + "px";
|
|
342
|
+
this.setColumnEnd(width);
|
|
343
|
+
},
|
|
344
|
+
|
|
345
|
+
doRightDrag: function (e) {
|
|
346
|
+
let width;
|
|
347
|
+
if (e.touches) e = e.touches[0];
|
|
348
|
+
width = this.startWidth + e.clientX - this.startX;
|
|
349
|
+
if (width < 10) return;
|
|
350
|
+
|
|
351
|
+
if (!this.isGrid) this.collaborate({ width });
|
|
352
|
+
|
|
353
|
+
this.resizeWidget.style.width = width + "px";
|
|
354
|
+
this.setColumnEnd(width);
|
|
355
|
+
},
|
|
356
|
+
|
|
357
|
+
detectGrid: function () {
|
|
358
|
+
let isGrid = false;
|
|
359
|
+
if (this.resizeWidget.parentNode) {
|
|
360
|
+
let compStyles = window.getComputedStyle(
|
|
361
|
+
this.resizeWidget.parentNode
|
|
362
|
+
);
|
|
363
|
+
isGrid = compStyles.display === "grid";
|
|
364
|
+
}
|
|
365
|
+
this.isGrid = isGrid;
|
|
366
|
+
return isGrid;
|
|
367
|
+
},
|
|
368
|
+
|
|
369
|
+
stopDrag: function (e) {
|
|
370
|
+
styleSheet.deleteRule(0);
|
|
371
|
+
if (this.resizeWidget.hasAttribute("resizing")) {
|
|
372
|
+
this.resizeWidget.removeAttribute("resizing", "");
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
//this is just for grid system
|
|
376
|
+
if (this.detectGrid()) {
|
|
377
|
+
this.resizeWidget.style.width = null;
|
|
378
|
+
this.resizeWidget.style.height = null;
|
|
379
|
+
this.resizeWidget.style.left = null;
|
|
380
|
+
this.resizeWidget.style.top = null;
|
|
381
|
+
|
|
382
|
+
if (this.widthSpan)
|
|
383
|
+
this.resizeWidget.setAttribute(
|
|
384
|
+
"class",
|
|
385
|
+
this.originClassAttribute +
|
|
386
|
+
" grid-column-end:span_" +
|
|
387
|
+
this.widthSpan
|
|
388
|
+
);
|
|
389
|
+
if (this.heightSpan)
|
|
390
|
+
this.resizeWidget.setAttribute(
|
|
391
|
+
"class",
|
|
392
|
+
this.originClassAttribute +
|
|
393
|
+
" grid-row-end:span_" +
|
|
394
|
+
this.heightSpan
|
|
395
|
+
);
|
|
396
|
+
|
|
397
|
+
this.collaborate({});
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
DIRECTIONS.map((d) => {
|
|
401
|
+
this.removeListenerMulti(
|
|
402
|
+
document.documentElement,
|
|
403
|
+
EVENTS[0],
|
|
404
|
+
this.doDrags[d]
|
|
405
|
+
);
|
|
406
|
+
});
|
|
407
|
+
this.removeListenerMulti(
|
|
408
|
+
document.documentElement,
|
|
409
|
+
EVENTS[2],
|
|
410
|
+
this.stopDrag
|
|
411
|
+
);
|
|
412
|
+
},
|
|
413
|
+
checkLeftCorners: function (e) {
|
|
414
|
+
let offset =
|
|
415
|
+
e.clientY -
|
|
416
|
+
this.getDistance(this.Drags["left"], true) +
|
|
417
|
+
document.documentElement.scrollTop;
|
|
418
|
+
if (offset > 10) {
|
|
419
|
+
offset =
|
|
420
|
+
this.getDistance(this.Drags["left"], true) +
|
|
421
|
+
this.Drags["left"].clientHeight -
|
|
422
|
+
e.clientY -
|
|
423
|
+
document.documentElement.scrollTop;
|
|
424
|
+
this.checkDragImplementation(
|
|
425
|
+
e,
|
|
426
|
+
"left",
|
|
427
|
+
"bottom",
|
|
428
|
+
offset,
|
|
429
|
+
"ne-resize",
|
|
430
|
+
"e-resize"
|
|
431
|
+
);
|
|
432
|
+
} else {
|
|
433
|
+
this.checkDragImplementation(
|
|
434
|
+
e,
|
|
435
|
+
"left",
|
|
436
|
+
"top",
|
|
437
|
+
offset,
|
|
438
|
+
"se-resize",
|
|
439
|
+
"e-resize"
|
|
440
|
+
);
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
checkTopCorners: function (e) {
|
|
444
|
+
let offset =
|
|
445
|
+
e.clientX -
|
|
446
|
+
this.getDistance(this.Drags["top"], false) +
|
|
447
|
+
document.documentElement.scrollTop;
|
|
448
|
+
if (offset > 10) {
|
|
449
|
+
offset =
|
|
450
|
+
this.getDistance(this.Drags["top"], false) +
|
|
451
|
+
this.Drags["top"].clientWidth -
|
|
452
|
+
e.clientX -
|
|
453
|
+
document.documentElement.scrollLeft;
|
|
454
|
+
this.checkDragImplementation(
|
|
455
|
+
e,
|
|
456
|
+
"top",
|
|
457
|
+
"right",
|
|
458
|
+
offset,
|
|
459
|
+
"ne-resize",
|
|
460
|
+
"s-resize"
|
|
461
|
+
);
|
|
462
|
+
} else {
|
|
463
|
+
this.checkDragImplementation(
|
|
464
|
+
e,
|
|
465
|
+
"top",
|
|
466
|
+
"left",
|
|
467
|
+
offset,
|
|
468
|
+
"se-resize",
|
|
469
|
+
"s-resize"
|
|
470
|
+
);
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
checkBottomCorners: function (e) {
|
|
474
|
+
let offset =
|
|
475
|
+
e.clientX -
|
|
476
|
+
this.getDistance(this.Drags["bottom"], false) +
|
|
477
|
+
document.documentElement.scrollTop;
|
|
478
|
+
if (offset > 10) {
|
|
479
|
+
offset =
|
|
480
|
+
this.getDistance(this.Drags["bottom"], false) +
|
|
481
|
+
this.Drags["bottom"].clientWidth -
|
|
482
|
+
e.clientX -
|
|
483
|
+
document.documentElement.scrollLeft;
|
|
484
|
+
this.checkDragImplementation(
|
|
485
|
+
e,
|
|
486
|
+
"bottom",
|
|
487
|
+
"right",
|
|
488
|
+
offset,
|
|
489
|
+
"se-resize",
|
|
490
|
+
"s-resize"
|
|
491
|
+
);
|
|
492
|
+
} else {
|
|
493
|
+
this.checkDragImplementation(
|
|
494
|
+
e,
|
|
495
|
+
"bottom",
|
|
496
|
+
"left",
|
|
497
|
+
offset,
|
|
498
|
+
"ne-resize",
|
|
499
|
+
"s-resize"
|
|
500
|
+
);
|
|
501
|
+
}
|
|
502
|
+
},
|
|
503
|
+
checkRightCorners: function (e) {
|
|
504
|
+
let offset =
|
|
505
|
+
e.clientY -
|
|
506
|
+
this.getDistance(this.Drags["right"], true) +
|
|
507
|
+
document.documentElement.scrollTop;
|
|
508
|
+
if (offset > 10) {
|
|
509
|
+
offset =
|
|
510
|
+
this.getDistance(this.Drags["right"], true) +
|
|
511
|
+
this.Drags["right"].clientHeight -
|
|
512
|
+
e.clientY -
|
|
513
|
+
document.documentElement.scrollTop;
|
|
514
|
+
this.checkDragImplementation(
|
|
515
|
+
e,
|
|
516
|
+
"right",
|
|
517
|
+
"bottom",
|
|
518
|
+
offset,
|
|
519
|
+
"se-resize",
|
|
520
|
+
"e-resize"
|
|
521
|
+
);
|
|
522
|
+
} else {
|
|
523
|
+
this.checkDragImplementation(
|
|
524
|
+
e,
|
|
525
|
+
"right",
|
|
526
|
+
"top",
|
|
527
|
+
offset,
|
|
528
|
+
"ne-resize",
|
|
529
|
+
"e-resize"
|
|
530
|
+
);
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
|
|
534
|
+
bindListeners: function () {
|
|
535
|
+
this.doDrags["left"] = this.doLeftDrag.bind(this);
|
|
536
|
+
this.doDrags["top"] = this.doTopDrag.bind(this);
|
|
537
|
+
this.doDrags["right"] = this.doRightDrag.bind(this);
|
|
538
|
+
this.doDrags["bottom"] = this.doBottomDrag.bind(this);
|
|
539
|
+
|
|
540
|
+
this.stopDrag = this.stopDrag.bind(this);
|
|
541
|
+
|
|
542
|
+
this.checkCorners["left"] = this.checkLeftCorners.bind(this);
|
|
543
|
+
this.checkCorners["top"] = this.checkTopCorners.bind(this);
|
|
544
|
+
this.checkCorners["bottom"] = this.checkBottomCorners.bind(this);
|
|
545
|
+
this.checkCorners["right"] = this.checkRightCorners.bind(this);
|
|
546
|
+
|
|
547
|
+
this.initDrags["top"] = this.initTopDrag.bind(this);
|
|
548
|
+
this.initDrags["left"] = this.initLeftDrag.bind(this);
|
|
549
|
+
this.initDrags["bottom"] = this.initBottomDrag.bind(this);
|
|
550
|
+
this.initDrags["right"] = this.initRightDrag.bind(this);
|
|
551
|
+
},
|
|
552
|
+
|
|
553
|
+
getDistance: function (elem, flag) {
|
|
554
|
+
var location = 0;
|
|
555
|
+
if (!elem) return;
|
|
556
|
+
if (elem.offsetParent) {
|
|
557
|
+
do {
|
|
558
|
+
location += flag ? elem.offsetTop : elem.offsetLeft;
|
|
559
|
+
elem = elem.offsetParent;
|
|
560
|
+
} while (elem);
|
|
561
|
+
}
|
|
562
|
+
return location >= 0 ? location : 0;
|
|
563
|
+
},
|
|
564
|
+
|
|
565
|
+
// Bind multiiple events to a listener
|
|
566
|
+
addListenerMulti: function (element, eventNames, listener) {
|
|
567
|
+
var events = eventNames.split(" ");
|
|
568
|
+
for (var i = 0, iLen = events.length; i < iLen; i++) {
|
|
569
|
+
element.addEventListener(events[i], listener, { passive: false });
|
|
570
|
+
}
|
|
571
|
+
},
|
|
572
|
+
|
|
573
|
+
// Remove multiiple events from a listener
|
|
574
|
+
removeListenerMulti: function (element, eventNames, listener) {
|
|
575
|
+
var events = eventNames.split(" ");
|
|
576
|
+
for (var i = 0, iLen = events.length; i < iLen; i++) {
|
|
577
|
+
element.removeEventListener(events[i], listener, {
|
|
578
|
+
passive: false
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
},
|
|
582
|
+
|
|
583
|
+
collaborate: function ({ left, top, width, height, rowEnd, columnEnd }) {
|
|
584
|
+
const details = typeof this.resizeWidget.editor?.getStart === "function"
|
|
585
|
+
? this.resizeWidget.editor : this.resizeWidget.editorDetails;
|
|
586
|
+
const editorElement = details?.element || details?.editorElement;
|
|
587
|
+
if (typeof details?.setAttribute !== "function" && !editorElement?.editor?.setAttribute) return;
|
|
588
|
+
|
|
589
|
+
const style = this.resizeWidget.ownerDocument.createElement("span").style;
|
|
590
|
+
style.cssText = this.resizeWidget.getAttribute("style") || "";
|
|
591
|
+
if (left !== undefined) style.left = left + "px";
|
|
592
|
+
if (top !== undefined) style.top = top + "px";
|
|
593
|
+
if (width !== undefined) style.width = width + "px";
|
|
594
|
+
if (height !== undefined) style.height = height + "px";
|
|
595
|
+
if (rowEnd !== undefined) style.setProperty("grid-row-end", "span " + rowEnd);
|
|
596
|
+
if (columnEnd !== undefined) style.setProperty("grid-column-end", "span " + columnEnd);
|
|
597
|
+
|
|
598
|
+
const result = typeof details.setAttribute === "function"
|
|
599
|
+
? details.setAttribute("style", style.cssText)
|
|
600
|
+
: editorElement.editor.setAttribute({ target: this.resizeWidget, name: "style", value: style.cssText });
|
|
601
|
+
result?.catch(error => this.resizeWidget.dispatchEvent(new CustomEvent("editor-error", {
|
|
602
|
+
bubbles: true,
|
|
603
|
+
detail: { error }
|
|
604
|
+
})));
|
|
605
|
+
}
|
|
598
606
|
};
|
|
599
607
|
|
|
600
608
|
// Function to auto-resize the element based on its content
|
|
601
609
|
function autoResizeElement(element) {
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
} else if (element.tagName === "SELECT" && element.multiple) {
|
|
618
|
-
element.size = Math.max(element.options.length, 1); // Ensure at least 1 visible option
|
|
619
|
-
}
|
|
610
|
+
if (!element) return;
|
|
611
|
+
|
|
612
|
+
if (element.tagName === "TEXTAREA") {
|
|
613
|
+
element.style.height = "auto";
|
|
614
|
+
|
|
615
|
+
const style = getComputedStyle(element);
|
|
616
|
+
const padding = parseFloat(style.paddingTop) + parseFloat(style.paddingBottom);
|
|
617
|
+
const border = parseFloat(style.borderTopWidth) + parseFloat(style.borderBottomWidth);
|
|
618
|
+
// scrollHeight includes padding, but not borders.
|
|
619
|
+
const height = element.scrollHeight +
|
|
620
|
+
(style.boxSizing === "border-box" ? border : -padding);
|
|
621
|
+
element.style.height = Math.max(0, height) + "px";
|
|
622
|
+
} else if (element.tagName === "SELECT" && element.multiple) {
|
|
623
|
+
element.size = Math.max(element.options.length, 1); // Ensure at least 1 visible option
|
|
624
|
+
}
|
|
620
625
|
}
|
|
621
626
|
|
|
622
627
|
// Observe the resize of the element
|
|
623
628
|
function observeElementResize(element) {
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
629
|
+
const resizeObserver = new ResizeObserver(() => {
|
|
630
|
+
autoResizeElement(element);
|
|
631
|
+
});
|
|
627
632
|
|
|
628
|
-
|
|
633
|
+
resizeObserver.observe(element);
|
|
629
634
|
}
|
|
630
635
|
|
|
631
636
|
// Listen for input events on the entire document
|
|
632
637
|
function initAutoHeight(element) {
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
// // Handle iframe document changes (e.g., if src or srcdoc is modified)
|
|
664
|
-
// element.addEventListener("load", () => {
|
|
665
|
-
// observer.disconnect(); // Disconnect the previous observer
|
|
666
|
-
// observeIframeContent(); // Reinitialize the observer on new document
|
|
667
|
-
// });
|
|
668
|
-
// }
|
|
669
|
-
}
|
|
670
|
-
|
|
671
|
-
for (let i = 0; i < element.length; i++) {
|
|
672
|
-
if (element[i].tagName === "TEXTAREA") {
|
|
673
|
-
element[i].rows = 1;
|
|
674
|
-
}
|
|
675
|
-
autoResizeElement(element[i]);
|
|
676
|
-
observeElementResize(element[i]); // Observe resize changes.
|
|
677
|
-
}
|
|
638
|
+
if (
|
|
639
|
+
element &&
|
|
640
|
+
!(element instanceof HTMLCollection) &&
|
|
641
|
+
!(element instanceof NodeList) &&
|
|
642
|
+
!Array.isArray(element)
|
|
643
|
+
) {
|
|
644
|
+
element = [element];
|
|
645
|
+
} else if (!element) {
|
|
646
|
+
element = document.querySelectorAll('[height="auto"]');
|
|
647
|
+
|
|
648
|
+
// Add event listener for iframes on load
|
|
649
|
+
document.addEventListener(
|
|
650
|
+
"input",
|
|
651
|
+
function (event) {
|
|
652
|
+
// Check if the target element has height="auto"
|
|
653
|
+
if (event.target.getAttribute("height") === "auto") {
|
|
654
|
+
autoResizeElement(event.target);
|
|
655
|
+
}
|
|
656
|
+
},
|
|
657
|
+
false
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
for (let i = 0; i < element.length; i++) {
|
|
662
|
+
if (element[i].tagName === "TEXTAREA") {
|
|
663
|
+
element[i].rows = 1;
|
|
664
|
+
}
|
|
665
|
+
autoResizeElement(element[i]);
|
|
666
|
+
observeElementResize(element[i]); // Observe resize changes.
|
|
667
|
+
}
|
|
678
668
|
}
|
|
679
669
|
|
|
680
670
|
initAutoHeight();
|
|
681
671
|
|
|
682
672
|
observer.init({
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
673
|
+
name: "CoCreateResize",
|
|
674
|
+
types: ["addedNodes"],
|
|
675
|
+
selector: "[resizable]:not([resizable='false'])",
|
|
676
|
+
callback: function (mutation) {
|
|
677
|
+
coCreateResize.initElement(mutation.target);
|
|
678
|
+
}
|
|
689
679
|
});
|
|
690
680
|
|
|
691
681
|
observer.init({
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
682
|
+
name: "CoCreateAutoResize",
|
|
683
|
+
types: ["addedNodes"],
|
|
684
|
+
selector: "[height='auto']",
|
|
685
|
+
callback: function (mutation) {
|
|
686
|
+
initAutoHeight(mutation.target);
|
|
687
|
+
}
|
|
698
688
|
});
|
|
699
689
|
|
|
700
690
|
observer.init({
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
691
|
+
name: "CoCreateAutoResizeOptions",
|
|
692
|
+
types: ["addedNodes"],
|
|
693
|
+
selector: "[height='auto'] option",
|
|
694
|
+
callback: function (mutation) {
|
|
695
|
+
autoResizeElement(mutation.target.parentElement);
|
|
696
|
+
}
|
|
707
697
|
});
|
|
708
698
|
|
|
709
699
|
coCreateResize.init({
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
700
|
+
selector: "[resizable]:not([resizable='false'])",
|
|
701
|
+
dragLeft: "[resize='left']",
|
|
702
|
+
dragRight: "[resize='right']",
|
|
703
|
+
dragTop: "[resize='top']",
|
|
704
|
+
dragBottom: "[resize='bottom']"
|
|
715
705
|
});
|
|
716
706
|
export default coCreateResize;
|
|
707
|
+
|
|
708
|
+
/**
|
|
709
|
+
* Preserves the element's original class value while resize updates grid sizing.
|
|
710
|
+
* @name class
|
|
711
|
+
* @kind member
|
|
712
|
+
* @attribute
|
|
713
|
+
* @environment client
|
|
714
|
+
* @type {string}
|
|
715
|
+
*/
|
|
716
|
+
|
|
717
|
+
/**
|
|
718
|
+
* Internal marker applied to this module's injected style element.
|
|
719
|
+
* @name component
|
|
720
|
+
* @kind member
|
|
721
|
+
* @attribute
|
|
722
|
+
* @environment client
|
|
723
|
+
* @type {string}
|
|
724
|
+
* @private
|
|
725
|
+
*/
|
|
726
|
+
|
|
727
|
+
/**
|
|
728
|
+
* Enables automatic content-based resizing when set to "auto". This applies to textareas and multiple selects.
|
|
729
|
+
* @name height
|
|
730
|
+
* @kind member
|
|
731
|
+
* @attribute
|
|
732
|
+
* @environment client
|
|
733
|
+
* @type {string}
|
|
734
|
+
* @acceptedValues auto
|
|
735
|
+
* @example
|
|
736
|
+
* <textarea height="auto"></textarea>
|
|
737
|
+
*/
|
|
738
|
+
|
|
739
|
+
/**
|
|
740
|
+
* Runtime state marker added while a resize gesture is active.
|
|
741
|
+
* @name resizing
|
|
742
|
+
* @kind member
|
|
743
|
+
* @attribute
|
|
744
|
+
* @environment client
|
|
745
|
+
* @type {boolean}
|
|
746
|
+
*/
|
|
747
|
+
|
|
748
|
+
/**
|
|
749
|
+
* Inline styles updated with the element's resized dimensions and grid span.
|
|
750
|
+
* @name style
|
|
751
|
+
* @kind member
|
|
752
|
+
* @attribute
|
|
753
|
+
* @environment client
|
|
754
|
+
* @type {string}
|
|
755
|
+
*/
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Enables interactive resizing unless explicitly set to "false".
|
|
759
|
+
*
|
|
760
|
+
* @name resizable
|
|
761
|
+
* @kind member
|
|
762
|
+
* @attribute
|
|
763
|
+
* @environment client
|
|
764
|
+
* @type {boolean}
|
|
765
|
+
* @acceptedValues false
|
|
766
|
+
* @example
|
|
767
|
+
* <div resizable><span resize="right"></span></div>
|
|
768
|
+
*/
|
|
769
|
+
|
|
770
|
+
/**
|
|
771
|
+
* Marks a child element as a resize handle and selects its drag direction.
|
|
772
|
+
*
|
|
773
|
+
* @name resize
|
|
774
|
+
* @kind member
|
|
775
|
+
* @attribute
|
|
776
|
+
* @environment client
|
|
777
|
+
* @type {string}
|
|
778
|
+
* @acceptedValues left, right, top, bottom
|
|
779
|
+
* @example
|
|
780
|
+
* <span resize="right"></span>
|
|
781
|
+
*/
|
|
782
|
+
|
|
783
|
+
/**
|
|
784
|
+
* A light weight resize handler make any element resizable by adding data attributes or usinng init object. Great for Customized text box or text area.
|
|
785
|
+
*
|
|
786
|
+
* @module resize
|
|
787
|
+
* @environment client
|
|
788
|
+
*/
|
|
789
|
+
|
|
790
|
+
/**
|
|
791
|
+
* Declarative selectors recognized by this module.
|
|
792
|
+
*
|
|
793
|
+
* @name declarative-selectors
|
|
794
|
+
* @kind member
|
|
795
|
+
* @selectors
|
|
796
|
+
* @environment client
|
|
797
|
+
* @example
|
|
798
|
+
* ```json
|
|
799
|
+
* [
|
|
800
|
+
* "",
|
|
801
|
+
* "[resizable]:not([resizable='false'])",
|
|
802
|
+
* "[height='auto']",
|
|
803
|
+
* "[height='auto'] option"
|
|
804
|
+
* ]
|
|
805
|
+
* ```
|
|
806
|
+
*/
|