@cocreate/resize 1.1.76 → 1.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,29 @@
1
+ ## [1.2.2](https://github.com/CoCreate-app/CoCreate-resize/compare/v1.2.1...v1.2.2) (2022-08-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * renamed order-by and order-type to filter-order-name and filter-order-type ([0f6c9e6](https://github.com/CoCreate-app/CoCreate-resize/commit/0f6c9e645cbdc750b5af1b1ea13dd9a934662889))
7
+
8
+ ## [1.2.1](https://github.com/CoCreate-app/CoCreate-resize/compare/v1.2.0...v1.2.1) (2022-07-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * removed console.logs ([884c02e](https://github.com/CoCreate-app/CoCreate-resize/commit/884c02e8aeef5805d9269dbc0de518ff41789d11))
14
+
15
+ # [1.2.0](https://github.com/CoCreate-app/CoCreate-resize/compare/v1.1.76...v1.2.0) (2022-06-29)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * bug when resizing from corners ([293a478](https://github.com/CoCreate-app/CoCreate-resize/commit/293a47828b662c96cfb4b34bd5f1f7b7e608fa5f))
21
+
22
+
23
+ ### Features
24
+
25
+ * if closest element is contentEditable use crdt text functiontions to insert styles resulting from resize ([4e8668e](https://github.com/CoCreate-app/CoCreate-resize/commit/4e8668e23d7fe9502258d676eebc170eb9771995))
26
+
1
27
  ## [1.1.76](https://github.com/CoCreate-app/CoCreate-resize/compare/v1.1.75...v1.1.76) (2022-06-18)
2
28
 
3
29
 
@@ -116,8 +116,8 @@
116
116
  <!-- Fetch and Render-->
117
117
  <ul class="overflow:auto display:flex flex-direction:column width:100% height:calc(100vh_-_160px) bottom:10px margin-right:5px">
118
118
  <div fetch-collection="modules"
119
- order-by="main-menu-position"
120
- order-type="asc"
119
+ filter-order-name="main-menu-position"
120
+ filter-order-type="asc"
121
121
  filter-name="main-menu-position"
122
122
  filter-value="0"
123
123
  filter-value-type="number"
@@ -188,7 +188,7 @@
188
188
  <main class="padding:10px" content_id="content">
189
189
  <!--<div class="domEditor main-height" name='cards1' collection="test" pass_id="me1234">-->
190
190
 
191
- <div class="display:grid grid-auto-rows:50px gap:10px grid-template-columns:repeat(auto-fill,minmax(50px,1fr))" dnd-group-name="dashboard" fetch-collection="files" template_id="card" droppable="true">
191
+ <div class="display:grid grid-auto-rows:50px gap:10px grid-template-columns:repeat(auto-fill,minmax(50px,1fr))" dnd-group-name="dashboard" fetch-collection="files" fetch-count="20" template_id="card" droppable="true">
192
192
 
193
193
  <div template_id="card" class="card position:relative template display:flex padding:20px align-items:center grid-column-end:span_6 grid-row-end:span_2" eid="id1" draggable="tru" resizable>
194
194
  <!-- dashboard template-->
@@ -206,8 +206,10 @@
206
206
  <div class="width:120px">
207
207
  <div class="progressbar-circle text-align:center width:100%" progressbar-color="#22CCE2" percent-value="85" percent-note="New Visits"></div>
208
208
  </div>
209
- <div resize="right"></div>
210
- <div resize="bottom"></div>
209
+ <div resize="top" dnd-exclude></div>
210
+ <div resize="bottom" dnd-exclude></div>
211
+ <div resize="left" dnd-exclude></div>
212
+ <div resize="right" dnd-exclude></div>
211
213
  </div>
212
214
  </div>
213
215
 
@@ -224,8 +226,8 @@
224
226
  </main>
225
227
 
226
228
 
227
- <!--<script src="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>-->
228
- <script src="../../../CoCreateJS/dist/CoCreate.js"></script>
229
+ <script src="https://cdn.cocreate.app/latest/CoCreate.min.js"></script>
230
+ <!-- <script src="../../../CoCreateJS/dist/CoCreate.js"></script> -->
229
231
 
230
232
  </body>
231
233
 
package/demo/index.html CHANGED
@@ -25,16 +25,6 @@
25
25
  background: #dddddd;
26
26
  }
27
27
 
28
- .resize2 {
29
- top: 150px;
30
- left: 150px;
31
- width: 50px;
32
- height: 50px;
33
- padding: 0.5em;
34
- position: absolute;
35
- background: #dddddd;
36
- }
37
-
38
28
  .resize3 {
39
29
  top: 250px;
40
30
  left: 250px;
@@ -44,29 +34,20 @@
44
34
  position: absolute;
45
35
  background: #dddddd;
46
36
  }
47
- .resize4 {
48
- top: 350px;
49
- left: 350px;
50
- width: 50px;
51
- height: 50px;
52
- padding: 0.5em;
53
- position: absolute;
54
- background: #dddddd;
55
- }
56
37
  </style>
57
38
  </head>
58
39
 
59
40
  <body>
60
41
 
61
42
  <!--<div class="">-->
62
- <div class="position:fixed height:100vh width:300px right:0px background:whitesmoke" resizable>
43
+ <!-- <div class="position:fixed height:100vh width:300px right:0px background:whitesmoke" resizable>
63
44
  <div resize="left"></div>
64
45
  <div resize="right"></div>
65
46
  <div resize="top"></div>
66
47
  <div resize="bottom"></div>
67
- </div>
48
+ </div> -->
68
49
 
69
- <div class="resize resize3" resizable>
50
+ <div class="resize resize1" resizable>
70
51
  <div resize="left"></div>
71
52
  <div resize="right"></div>
72
53
  <div resize="top"></div>
@@ -75,8 +56,8 @@
75
56
  <!--</div>-->
76
57
 
77
58
 
78
- <!--<script src="../dist/CoCreate-resize.js"></script>-->
79
- <script src="../../../CoCreateJS/dist/CoCreate.js" ></script>
59
+ <script src="../dist/CoCreate-resize.js"></script>
60
+ <!-- <script src="../../../CoCreateJS/dist/CoCreate.js" ></script> -->
80
61
  </body>
81
62
 
82
63
  </html>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocreate/resize",
3
- "version": "1.1.76",
3
+ "version": "1.2.2",
4
4
  "description": "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.",
5
5
  "keywords": [
6
6
  "resize",
package/src/index.js CHANGED
@@ -52,8 +52,6 @@ CoCreateResize.prototype = {
52
52
  this.isGrid = this.detectGrid();
53
53
  this.gridWidth = 0;
54
54
  this.gridHeight = 0;
55
- // this.missingWidth = 0;
56
- // this.missingHeight = 0;
57
55
  this.limitSpan = 0;
58
56
  this.widthSpan = 0;
59
57
  this.heightSpan = 0;
@@ -75,11 +73,9 @@ CoCreateResize.prototype = {
75
73
  getGridProperty: function() {
76
74
  if(!this.resizeWidget.parentNode) return;
77
75
  let compStyles = window.getComputedStyle(this.resizeWidget.parentNode);
78
- // let currentCompStyles = window.getComputedStyle(this.resizeWidget);
79
76
  let gridColumns = compStyles.gridTemplateColumns;
80
77
  let height = compStyles.gridAutoRows;
81
78
 
82
- // console.log(compStyles)
83
79
  if(gridColumns !== 'none') {
84
80
  let width = gridColumns.split(' ');
85
81
  this.limitSpan = width.length;
@@ -87,12 +83,6 @@ CoCreateResize.prototype = {
87
83
  this.gridRowGap = Number.parseInt(compStyles.gridRowGap);
88
84
  this.gridWidth = Number.parseFloat(width[0]);
89
85
  this.gridHeight = Number.parseInt(height);
90
- // this.missingWidth = Number.parseInt(currentCompStyles.paddingRight) + Number.parseInt(currentCompStyles.paddingLeft)
91
- // + Number.parseInt(currentCompStyles.marginRight) + Number.parseInt(currentCompStyles.marginLeft)
92
- // + Number.parseInt(currentCompStyles.borderRight) + Number.parseInt(currentCompStyles.borderLeft);
93
- // this.missingHeight = Number.parseInt(currentCompStyles.paddingTop) + Number.parseInt(currentCompStyles.paddingBottom)
94
- // + Number.parseInt(currentCompStyles.marginTop) + Number.parseInt(currentCompStyles.marginBottom)
95
- // + Number.parseInt(currentCompStyles.borderTop) + Number.parseInt(currentCompStyles.borderBottom);
96
86
  }
97
87
  },
98
88
 
@@ -126,15 +116,27 @@ CoCreateResize.prototype = {
126
116
  },
127
117
 
128
118
  initResize: function() {
129
- DIRECTIONS.map(d => { if (this.Drags[d]) this.addListenerMulti(this.Drags[d], EVENTS[0], this.checkCorners[d]); });
119
+ DIRECTIONS.map(d => {
120
+ if (this.Drags[d])
121
+ this.addListenerMulti(this.Drags[d], EVENTS[0], this.checkCorners[d]);
122
+ });
130
123
  },
131
124
 
132
125
  checkDragImplementation: function(e, from, to, offset, fcur, scur) {
133
126
  if (e.touches)
134
127
  e = e.touches[0];
135
-
128
+ let other;
129
+ if (to == 'top')
130
+ other = 'bottom'
131
+ else if (to == 'bottom')
132
+ other = 'top'
133
+ else if (to == 'left')
134
+ other = 'right'
135
+ else if (to == 'right')
136
+ other = 'left'
136
137
  this.removeListenerMulti(this.Drags[from], EVENTS[1], this.initDrags[from]);
137
138
  this.removeListenerMulti(this.Drags[from], EVENTS[1], this.initDrags[to]);
139
+ this.removeListenerMulti(this.Drags[from], EVENTS[1], this.initDrags[other]);
138
140
  this.addListenerMulti(this.Drags[from], EVENTS[1], this.initDrags[from]);
139
141
 
140
142
  if (offset < this.cornerSize && this.Drags[to]) {
@@ -147,6 +149,12 @@ CoCreateResize.prototype = {
147
149
  },
148
150
 
149
151
  initDrag: function(e, idx) {
152
+ e.preventDefault();
153
+
154
+ if (!this.resizeWidget.hasAttribute('resizing')){
155
+ this.resizeWidget.setAttribute('resizing', '')
156
+ }
157
+
150
158
  let selector = document.defaultView.getComputedStyle(this.resizeWidget);
151
159
  this.processIframe();
152
160
 
@@ -181,6 +189,7 @@ CoCreateResize.prototype = {
181
189
  },
182
190
  initLeftDrag: function(e) {
183
191
  this.initDrag(e, 'left');
192
+
184
193
  },
185
194
  initRightDrag: function(e) {
186
195
  this.initDrag(e, 'right');
@@ -190,8 +199,8 @@ CoCreateResize.prototype = {
190
199
  setRowEnd: function(height) {
191
200
  if(this.gridHeight) {
192
201
  this.heightSpan = Math.ceil((height - (this.heightSpan - 1) * this.gridRowGap) / this.gridHeight );
193
- // this.heightSpan = Math.ceil((height + this.missingHeight) / this.gridHeight);
194
202
  this.resizeWidget.style['grid-row-end'] = 'span ' + this.heightSpan;
203
+ this.collaborate({rowEnd: this.heightSpan})
195
204
  }
196
205
  },
197
206
 
@@ -203,20 +212,19 @@ CoCreateResize.prototype = {
203
212
  top = this.startTop + e.clientY - this.startY;
204
213
  height = this.startHeight - e.clientY + this.startY;
205
214
 
206
- if (top < 10 || height < 10)
215
+ if (height < 10)
207
216
  return;
208
- // this.resizeWidget.style.top = top + 'px';
209
- let compStyles = window.getComputedStyle(this.resizeWidget);
210
- this.resizeWidget.style.bottom = compStyles.bottom;
211
- this.resizeWidget.style.top = null;
217
+ if (!this.isGrid) {
218
+ this.resizeWidget.style.top = top + 'px';
219
+ this.collaborate({top, height})
220
+ }
212
221
  this.resizeWidget.style.height = height + 'px';
213
-
214
222
  this.setRowEnd(height);
215
223
  },
216
224
 
217
225
 
218
226
  doBottomDrag: function(e) {
219
- let height = 0;
227
+ let height;
220
228
 
221
229
  if (e.touches)
222
230
  e = e.touches[0];
@@ -225,10 +233,9 @@ CoCreateResize.prototype = {
225
233
 
226
234
  if (height < 10)
227
235
  return;
228
- // this.resizeWidget.style.height = height + 'px';
229
- let compStyles = window.getComputedStyle(this.resizeWidget);
230
- this.resizeWidget.style.top = compStyles.top;
231
- this.resizeWidget.style.bottom = null;
236
+ if (!this.isGrid)
237
+ this.collaborate({height})
238
+
232
239
  this.resizeWidget.style.height = height + 'px';
233
240
  this.setRowEnd(height);
234
241
  },
@@ -239,6 +246,7 @@ CoCreateResize.prototype = {
239
246
  let spans = Math.ceil((width - (this.widthSpan - 1) * this.gridColumnGap) / this.gridWidth);
240
247
  this.widthSpan = (spans > this.limitSpan) ? this.limitSpan : spans;
241
248
  this.resizeWidget.style['grid-column-end'] = 'span ' + this.widthSpan;
249
+ this.collaborate({columnEnd: this.widthSpan})
242
250
  }
243
251
  },
244
252
 
@@ -247,35 +255,32 @@ CoCreateResize.prototype = {
247
255
  if (e.touches)
248
256
  e = e.touches[0];
249
257
  left = this.startLeft + e.clientX - this.startX;
250
- console.log('left', left)
251
258
  width = this.startWidth - e.clientX + this.startX;
252
259
 
253
260
  if (width < 10)
254
261
  return;
255
- if (!this.isGrid)
262
+ if (!this.isGrid) {
256
263
  this.resizeWidget.style.left = left + 'px';
257
- // let compStyles = window.getComputedStyle(this.resizeWidget);
258
- // this.resizeWidget.style.right = compStyles.right;
259
- // this.resizeWidget.style.left = null;
260
- this.resizeWidget.style.width = width + 'px';
264
+ this.collaborate({left, width})
265
+ }
261
266
 
267
+ this.resizeWidget.style.width = width + 'px';
262
268
  this.setColumnEnd(width);
263
269
  },
264
270
 
265
271
 
266
272
  doRightDrag: function(e) {
267
- let width = 0;
273
+ let width;
268
274
  if (e.touches)
269
275
  e = e.touches[0];
270
276
  width = this.startWidth + e.clientX - this.startX;
271
277
  if (width < 10)
272
278
  return;
273
-
274
- let compStyles = window.getComputedStyle(this.resizeWidget);
275
- this.resizeWidget.style.left = compStyles.left;
276
- this.resizeWidget.style.right = null;
277
- this.resizeWidget.style.width = width + 'px';
278
279
 
280
+ if (!this.isGrid)
281
+ this.collaborate({width})
282
+
283
+ this.resizeWidget.style.width = width + 'px';
279
284
  this.setColumnEnd(width);
280
285
  },
281
286
 
@@ -293,6 +298,9 @@ CoCreateResize.prototype = {
293
298
  document.querySelectorAll('iframe').forEach(function(item) {
294
299
  item.style.pointerEvents = null;
295
300
  });
301
+ if (this.resizeWidget.hasAttribute('resizing')){
302
+ this.resizeWidget.removeAttribute('resizing', '')
303
+ }
296
304
 
297
305
  //this is just for grid system
298
306
  if(this.detectGrid()) {
@@ -308,21 +316,41 @@ CoCreateResize.prototype = {
308
316
  DIRECTIONS.map(d => { this.removeListenerMulti(document.documentElement, EVENTS[0], this.doDrags[d]) });
309
317
  this.removeListenerMulti(document.documentElement, EVENTS[2], this.stopDrag);
310
318
  },
311
- checkLeftDragTopCorner: function(e) {
312
- const offset = e.clientY - this.getDistance(this.Drags['left'], true) + document.documentElement.scrollTop;
313
- this.checkDragImplementation(e, 'left', 'top', offset, 'se-resize', 'e-resize');
319
+ checkLeftCorners: function(e) {
320
+ let offset = e.clientY - this.getDistance(this.Drags['left'], true) + document.documentElement.scrollTop;
321
+ if (offset > 10) {
322
+ offset = this.getDistance(this.Drags['left'], true) + this.Drags['left'].clientHeight - e.clientY - document.documentElement.scrollTop;
323
+ this.checkDragImplementation(e, 'left', 'bottom', offset, 'ne-resize', 'e-resize');
324
+ } else {
325
+ this.checkDragImplementation(e, 'left', 'top', offset, 'se-resize', 'e-resize');
326
+ }
314
327
  },
315
- checkTopDragRightCorner: function(e) {
316
- const offset = this.getDistance(this.Drags['right'], false) - e.clientX - document.documentElement.scrollLeft;
317
- this.checkDragImplementation(e, 'top', 'right', offset, 'ne-resize', 's-resize');
328
+ checkTopCorners: function(e) {
329
+ let offset = e.clientX - this.getDistance(this.Drags['top'], false) + document.documentElement.scrollTop;
330
+ if (offset > 10) {
331
+ offset = this.getDistance(this.Drags['top'], false) + this.Drags['top'].clientWidth - e.clientX - document.documentElement.scrollLeft;
332
+ this.checkDragImplementation(e, 'top', 'right', offset, 'ne-resize', 's-resize');
333
+ } else {
334
+ this.checkDragImplementation(e, 'top', 'left', offset, 'se-resize', 's-resize');
335
+ }
318
336
  },
319
- checkBottomDragLeftCorner: function(e) {
320
- const offset = e.clientX - this.getDistance(this.Drags['bottom'], false) + document.documentElement.scrollLeft;
321
- this.checkDragImplementation(e, 'bottom', 'left', offset, 'ne-resize', 's-resize');
337
+ checkBottomCorners: function(e) {
338
+ let offset = e.clientX - this.getDistance(this.Drags['bottom'], false) + document.documentElement.scrollTop;
339
+ if (offset > 10) {
340
+ offset = this.getDistance(this.Drags['bottom'], false) + this.Drags['bottom'].clientWidth - e.clientX - document.documentElement.scrollLeft;
341
+ this.checkDragImplementation(e, 'bottom', 'right', offset, 'se-resize', 's-resize');
342
+ } else {
343
+ this.checkDragImplementation(e, 'bottom', 'left', offset, 'ne-resize', 's-resize');
344
+ }
322
345
  },
323
- checkRightDragBottomCorner: function(e) {
324
- const offset = this.getDistance(this.Drags['bottom'], true) - e.clientY - document.documentElement.scrollTop;
325
- this.checkDragImplementation(e, 'right', 'bottom', offset, 'se-resize', 'e-resize');
346
+ checkRightCorners: function(e) {
347
+ let offset = e.clientY - this.getDistance(this.Drags['right'], true) + document.documentElement.scrollTop;
348
+ if (offset > 10) {
349
+ offset = this.getDistance(this.Drags['right'], true) + this.Drags['right'].clientHeight - e.clientY - document.documentElement.scrollTop;
350
+ this.checkDragImplementation(e, 'right', 'bottom', offset, 'se-resize', 'e-resize');
351
+ } else {
352
+ this.checkDragImplementation(e, 'right', 'top', offset, 'ne-resize', 'e-resize');
353
+ }
326
354
  },
327
355
 
328
356
  bindListeners: function() {
@@ -333,10 +361,10 @@ CoCreateResize.prototype = {
333
361
 
334
362
  this.stopDrag = this.stopDrag.bind(this);
335
363
 
336
- this.checkCorners['left'] = this.checkLeftDragTopCorner.bind(this);
337
- this.checkCorners['top'] = this.checkTopDragRightCorner.bind(this);
338
- this.checkCorners['bottom'] = this.checkBottomDragLeftCorner.bind(this);
339
- this.checkCorners['right'] = this.checkRightDragBottomCorner.bind(this);
364
+ this.checkCorners['left'] = this.checkLeftCorners.bind(this);
365
+ this.checkCorners['top'] = this.checkTopCorners.bind(this);
366
+ this.checkCorners['bottom'] = this.checkBottomCorners.bind(this);
367
+ this.checkCorners['right'] = this.checkRightCorners.bind(this);
340
368
 
341
369
  this.initDrags['top'] = this.initTopDrag.bind(this);
342
370
  this.initDrags['left'] = this.initLeftDrag.bind(this);
@@ -377,6 +405,38 @@ CoCreateResize.prototype = {
377
405
  document.querySelectorAll('iframe').forEach(function(item) {
378
406
  item.style.pointerEvents = null;
379
407
  });
408
+ },
409
+
410
+ collaborate: function({left, top, width, height, rowEnd, columnEnd}) {
411
+ if (window.CoCreate && window.CoCreate.text) {
412
+ let domTextEditor = this.resizeWidget.closest('[contenteditable]');
413
+ if (domTextEditor){
414
+ if (left)
415
+ CoCreate.text.setStyle({
416
+ domTextEditor, target: this.resizeWidget, property: 'left', value: left + 'px'
417
+ })
418
+ if (top)
419
+ CoCreate.text.setStyle({
420
+ domTextEditor, target: this.resizeWidget, property: 'top', value: top + 'px'
421
+ })
422
+ if (width)
423
+ CoCreate.text.setStyle({
424
+ domTextEditor, target: this.resizeWidget, property: 'width', value: width + 'px'
425
+ })
426
+ if (height)
427
+ CoCreate.text.setStyle({
428
+ domTextEditor, target: this.resizeWidget, property: 'height', value: height + 'px'
429
+ })
430
+ if (rowEnd)
431
+ CoCreate.text.setStyle({
432
+ domTextEditor, target: this.resizeWidget, property: 'grid-row-end', value: 'span ' + rowEnd
433
+ })
434
+ if (columnEnd)
435
+ CoCreate.text.setStyle({
436
+ domTextEditor, target: this.resizeWidget, property: 'grid-column-end', value: 'span ' + columnEnd
437
+ })
438
+ }
439
+ }
380
440
  }
381
441
  };
382
442