@lemonadejs/modal 2.4.10 → 2.5.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/dist/index.d.ts CHANGED
@@ -23,7 +23,7 @@ declare namespace Modal {
23
23
  /** Modal can be moved from its original position. Default: false */
24
24
  draggable?: boolean;
25
25
  /** Modal is automatic align during initialization */
26
- position?: 'center' | 'left' | 'right' | undefined;
26
+ position?: 'center' | 'left' | 'right' | 'bottom' | undefined;
27
27
  /** Title of the modal */
28
28
  title?: string;
29
29
  /** Width of the modal */
@@ -52,6 +52,8 @@ declare namespace Modal {
52
52
  onopen?: (self: object) => void;
53
53
  /** onclose event */
54
54
  onclose?: (self: object) => void;
55
+ /** onload event */
56
+ onload?: (self: object) => void;
55
57
  }
56
58
 
57
59
  interface Instance {
package/dist/index.js CHANGED
@@ -81,18 +81,19 @@ if (!lemonade && typeof (require) === 'function') {
81
81
  if (typeof(controls.action) === 'function') {
82
82
  controls.action();
83
83
  }
84
- // Remove cursor
85
- if (controls.e) {
86
- controls.e.style.cursor = '';
87
- controls.e.classList.remove('moving');
88
- }
89
- // Reset controls
90
- controls = {};
91
- // Reset state controls
92
- state = {
93
- x: null,
94
- y: null,
95
- }
84
+ setTimeout(function() {
85
+ // Remove cursor
86
+ if (controls.e) {
87
+ controls.e.style.cursor = '';
88
+ }
89
+ // Reset controls
90
+ controls = {};
91
+ // Reset state controls
92
+ state = {
93
+ x: null,
94
+ y: null,
95
+ }
96
+ }, 0)
96
97
  }
97
98
 
98
99
  const mouseMove = function(e) {
@@ -166,16 +167,18 @@ if (!lemonade && typeof (require) === 'function') {
166
167
  const refreshMinimized = function() {
167
168
  let items = minimizedModals;
168
169
  let numOfItems = items.length;
169
- let width = 0;
170
- let height = 5;
170
+ let width = 10;
171
+ let height = 10;
172
+ let offsetWidth = document.body.offsetWidth;
173
+ let offsetHeight = document.body.offsetHeight;
171
174
  for (let i = 0; i < numOfItems; i++) {
172
175
  let item = items[i];
173
- item.el.style.marginLeft = width;
174
- item.el.style.marginBottom = height;
176
+ item.el.style.left = width + 'px';
177
+ item.el.style.top = offsetHeight - 30 - height + 'px';
175
178
  width += 205;
176
179
 
177
- if (document.body.offsetWidth - width < 205) {
178
- width = 0;
180
+ if (offsetWidth - width < 205) {
181
+ width = 10;
179
182
  height += 50;
180
183
  }
181
184
  }
@@ -185,26 +188,25 @@ if (!lemonade && typeof (require) === 'function') {
185
188
  // Minimize modals
186
189
  minimizedModals.push(self);
187
190
  // Refresh positions
188
- refreshMinimized.call(self);
191
+ refreshMinimized();
189
192
  }
190
193
 
191
194
  const removeMini = function(self) {
192
195
  minimizedModals.splice(minimizedModals.indexOf(self), 1);
193
- self.el.style.marginLeft = '';
194
- self.el.style.marginBottom = '';
196
+ self.el.style.top = self.top + 'px';
197
+ self.el.style.left = self.left + 'px';
195
198
  // Refresh positions
196
- refreshMinimized.call(self);
199
+ refreshMinimized();
197
200
  }
198
201
 
199
202
  const adjustVertical = function() {
200
203
  let self = this;
201
- self.el.style.marginTop = '';
202
204
  let rect = self.el.getBoundingClientRect();
203
205
  let limit = document.documentElement.clientHeight + window.scrollY - (rect.top + rect.height);
204
206
  if (limit < 0) {
205
- self.el.style.marginTop = limit - 10 + 'px';
207
+ return rect.top + (limit - 10);
206
208
  } else if (rect.top < 0) {
207
- self.el.style.marginTop = -1 * rect.top + 10 + 'px';
209
+ return 10;
208
210
  }
209
211
  }
210
212
 
@@ -214,9 +216,9 @@ if (!lemonade && typeof (require) === 'function') {
214
216
  // Make sure component will be visible on page
215
217
  let limit = document.documentElement.clientWidth - (rect.left + rect.width);
216
218
  if (limit < 0) {
217
- self.el.style.marginLeft = limit - 10 + 'px';
219
+ return rect.left + (limit - 10);
218
220
  } else if (rect.left < 0) {
219
- self.el.style.marginLeft = -1 * rect.left + 10 + 'px';
221
+ return 10;
220
222
  }
221
223
  }
222
224
 
@@ -240,6 +242,10 @@ if (!lemonade && typeof (require) === 'function') {
240
242
  sendToFront(self.el);
241
243
  }
242
244
 
245
+ // Onload method
246
+ let onload = self.onload;
247
+
248
+ // Native lemonade
243
249
  self.onload = function() {
244
250
  if (self.url) {
245
251
  fetch(self.url)
@@ -256,23 +262,20 @@ if (!lemonade && typeof (require) === 'function') {
256
262
  // Dimensions
257
263
  if (self.width) {
258
264
  self.el.style.width = self.width + 'px';
259
- } else if (self.el.offsetWidth) {
260
- self.width = self.el.offsetWidth;
261
265
  }
262
266
  if (self.height) {
263
267
  self.el.style.height = self.height + 'px';
264
- } else if (self.el.offsetHeight) {
265
- self.height = self.el.offsetHeight;
266
- }
267
- if (self.top) {
268
- self.el.style.top = self.top + 'px';
269
- }
270
- if (self.left) {
271
- self.el.style.left = self.left + 'px';
272
268
  }
273
269
 
274
270
  // Initial centralize
275
- if (self.position === 'center') {
271
+ if (! self.position) {
272
+ if (! self.width && self.el.offsetWidth) {
273
+ self.width = self.el.offsetWidth;
274
+ }
275
+ if (! self.height && self.el.offsetHeight) {
276
+ self.height = self.el.offsetHeight;
277
+ }
278
+ } else if (self.position === 'center') {
276
279
  self.top = (window.innerHeight - self.height) / 2;
277
280
  self.left = (window.innerWidth - self.width) / 2;
278
281
  }
@@ -298,8 +301,14 @@ if (!lemonade && typeof (require) === 'function') {
298
301
 
299
302
  // Adjust position
300
303
  if (isTrue(self['auto-adjust'])) {
301
- adjustVertical.call(self);
302
- adjustHorizontal.call(self);
304
+ let v = adjustVertical.call(self);
305
+ if (v) {
306
+ self.top = v;
307
+ }
308
+ v = adjustHorizontal.call(self);
309
+ if (v) {
310
+ self.left = v;
311
+ }
303
312
  }
304
313
 
305
314
  // Bring to front on focus
@@ -310,7 +319,7 @@ if (!lemonade && typeof (require) === 'function') {
310
319
  // Focus out of the component
311
320
  self.el.addEventListener('focusout', function(e) {
312
321
  if (isTrue(self['auto-close'])) {
313
- if (!self.el.contains(e.relatedTarget)) {
322
+ if (! self.el.contains(e.relatedTarget)) {
314
323
  self.closed = true;
315
324
  }
316
325
  }
@@ -324,9 +333,19 @@ if (!lemonade && typeof (require) === 'function') {
324
333
  e.stopImmediatePropagation();
325
334
  }
326
335
  });
336
+
337
+ if (typeof(onload) === 'function') {
338
+ Dispatch.call(self, 'onload', self);
339
+ }
327
340
  }
328
341
 
342
+ let ignoreEvents = false;
343
+
329
344
  self.onchange = function(property) {
345
+ if (ignoreEvents) {
346
+ return false;
347
+ }
348
+
330
349
  if (property === 'closed') {
331
350
  if (self.closed === false) {
332
351
  // Focus on the modal
@@ -337,31 +356,30 @@ if (!lemonade && typeof (require) === 'function') {
337
356
  if (backdrop) {
338
357
  self.el.parentNode.insertBefore(backdrop, self.el);
339
358
  }
340
- // Animation
341
- if (self.animation) {
342
- self.el.classList.add('lm-modal-animation');
343
- }
344
359
  } else {
345
360
  // Hide backdrop
346
361
  if (backdrop) {
347
362
  backdrop.remove();
348
363
  }
349
- if (self.animation) {
350
- self.el.classList.remove('lm-modal-animation');
351
- }
352
364
  }
353
365
 
354
366
  // Call the vents
355
- self.closed ? Dispatch.call(self,'onclose') : Dispatch.call(self,'onopen');
367
+ self.closed ? Dispatch.call(self,'onclose',self) : Dispatch.call(self,'onopen',self);
356
368
  } else if (property === 'top' || property === 'left' || property === 'width' || property === 'height') {
357
- self.el.style[property] = self[property] + 'px';
358
- }
359
-
360
- // Adjust position
361
- if (self.closed === false) {
362
- if (isTrue(self['auto-adjust'])) {
363
- adjustVertical.call(self);
364
- adjustHorizontal.call(self);
369
+ if (self[property] !== '') {
370
+ self.el.style[property] = self[property] + 'px';
371
+ } else {
372
+ self.el.style[property] = '';
373
+ }
374
+ } else if (property === 'position') {
375
+ if (self.position) {
376
+ if (self.position === 'center') {
377
+ self.top = (window.innerHeight - self.el.offsetHeight) / 2;
378
+ self.left = (window.innerWidth - self.el.offsetWidth) / 2;
379
+ } else {
380
+ self.top = '';
381
+ self.left = '';
382
+ }
365
383
  }
366
384
  }
367
385
  }
@@ -420,49 +438,71 @@ if (!lemonade && typeof (require) === 'function') {
420
438
  controls.w = rect.width;
421
439
  controls.h = rect.height;
422
440
 
423
- let corner = rect.width - (x - rect.left) < 40 && (y - rect.top) < 40;
441
+ let corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 34;
424
442
 
425
- if (isTrue(self.minimizable) && corner === true) {
426
- self.minimized = ! self.minimized;
427
- // Handles minimized modal positioning
428
- if (self.minimized) {
429
- setMini(self);
430
- } else {
431
- removeMini(self);
443
+ // Check if the click in on close
444
+ if (isTrue(self.closable)) {
445
+ if (corner) {
446
+ self.closed = true;
447
+ if (isTrue(self.minimizable)) {
448
+ removeMini(self);
449
+ }
450
+ return;
432
451
  }
433
- } else if (isTrue(self.closable) && corner === true) {
434
- self.closed = true;
435
- } else if (! self.minimized) {
452
+
453
+ corner = (y - rect.top) < 40 && rect.width - (x - rect.left) < 65;
454
+ }
455
+
456
+ // Check if the click in on minimize
457
+ if (isTrue(self.minimizable)) {
458
+ if (corner) {
459
+ // Minimize
460
+ self.minimized = ! self.minimized;
461
+ // Handles minimized modal positioning
462
+ if (self.minimized) {
463
+ if (! self.top) {
464
+ self.top = self.el.offsetTop;
465
+ }
466
+ if (! self.left) {
467
+ self.left = self.el.offsetLeft;
468
+ }
469
+
470
+ setMini(self);
471
+ } else {
472
+ removeMini(self);
473
+ }
474
+
475
+ return;
476
+ }
477
+ }
478
+
479
+ if (! self.minimized) {
436
480
  // If is not minimized
437
481
  if (controls.type === 'resize') {
438
- // This will be the callback when finalize the resize
439
- controls.action = function () {
440
- self.width = parseInt(item.style.width);
441
- self.height = parseInt(item.style.height);
442
- }
443
482
  // Make sure the width and height is defined for the modal
444
- if (!item.style.width) {
483
+ if (! item.style.width) {
445
484
  item.style.width = controls.w + 'px';
446
485
  }
447
- if (!item.style.height) {
486
+ if (! item.style.height) {
448
487
  item.style.height = controls.h + 'px';
449
488
  }
450
-
451
- e.preventDefault();
489
+ // This will be the callback when finalize the resize
490
+ controls.action = function () {
491
+ self.width = parseInt(item.style.width);
492
+ self.height = parseInt(item.style.height);
493
+ controls.e.classList.remove('resizing');
494
+ }
495
+ controls.e.classList.add('resizing');
452
496
  } else if (isTrue(self.draggable) && self.title && y - rect.top < 40) {
453
- let rect = self.el.getBoundingClientRect();
454
- let top = rect.top;
455
- let left = rect.left;
456
- self.el.style.marginLeft = 0;
457
- self.el.style.marginTop = 0;
458
- self.el.style.top = top + 'px';
459
- self.el.style.left = left + 'px';
460
497
  // Action
461
498
  controls.type = 'move';
462
499
  // Callback
463
500
  controls.action = function () {
464
- self.top = parseInt(item.style.top);
465
- self.left = parseInt(item.style.left);
501
+ let v = adjustVertical.call(self) || item.style.top;
502
+ let h = adjustHorizontal.call(self) || item.style.left;
503
+ self.top = parseInt(v);
504
+ self.left = parseInt(h);
505
+ controls.e.classList.remove('moving');
466
506
  }
467
507
  controls.e.classList.add('moving');
468
508
  }
package/dist/style.css CHANGED
@@ -8,13 +8,13 @@
8
8
  box-sizing: border-box;
9
9
  box-shadow: 0 0 12px rgb(0 0 0 / 22%);
10
10
  opacity: 1;
11
- transition: opacity 0.5s ease;
12
11
  will-change: transform;
13
12
  border: 1px solid #bbb;
14
13
  outline: none;
15
14
  margin: 0;
16
15
  display: flex;
17
16
  flex-direction: column;
17
+ transition: opacity 0.4s ease, top 0.4s ease, left 0.4s ease, width 0.4s ease, height 0.4s ease;
18
18
  }
19
19
 
20
20
  .lm-modal-title {
@@ -75,25 +75,8 @@
75
75
  display: none !important;
76
76
  }
77
77
 
78
- .lm-modal[minimized="true"] {
79
- bottom: 0;
80
- top: initial !important;
81
- left: initial !important;
82
- width: 200px !important;
83
- height: 45px !important;
84
- min-width: initial;
85
- min-height: initial;
86
- overflow: hidden;
87
- transition: margin 0.2s ease-in-out;
88
- }
89
-
90
- .lm-modal[minimized="true"]::after {
91
- content: 'open_in_full';
92
- }
93
-
94
- @keyframes slide-bottom-in {
95
- 0% { transform: translateY(100%); }
96
- 100% { transform: translateY(0%); }
78
+ .lm-modal[minimized="true"]:before {
79
+ content: '\e5d7';
97
80
  }
98
81
 
99
82
  .lm-modal.hide {
@@ -104,11 +87,6 @@
104
87
  z-index: 999;
105
88
  }
106
89
 
107
- .lm-modal-animation {
108
- transform: none;
109
- animation: slide-bottom-in 0.4s forwards;
110
- }
111
-
112
90
  .lm-modal[data-responsive].fullscreen {
113
91
  top: 0;
114
92
  height: 100% !important;
@@ -116,6 +94,11 @@
116
94
 
117
95
  .lm-modal.moving {
118
96
  cursor: move !important;
97
+ transition: initial;
98
+ }
99
+
100
+ .lm-modal.resizing {
101
+ transition: initial;
119
102
  }
120
103
 
121
104
  .lm-modal-backdrop {
@@ -156,17 +139,35 @@
156
139
  top: 0;
157
140
  left: 0;
158
141
  width: 280px;
159
- height: 100vh;
142
+ height: 100vh !important;
160
143
  border-width: 0;
161
144
  border-radius: initial;
162
145
  }
163
146
 
164
147
  .lm-modal[position="right"] {
165
148
  top: 0;
166
- left: initial;
149
+ left: auto;
167
150
  right: 0;
168
151
  width: 280px;
169
- height: 100vh;
152
+ height: 100vh !important;
153
+ border-width: 0;
154
+ border-radius: initial;
155
+ }
156
+
157
+ .lm-modal[position="bottom"] {
158
+ top: auto;
159
+ left: 0;
160
+ bottom: 0;
161
+ width: 100vw !important;
162
+ height: 280px;
170
163
  border-width: 0;
171
164
  border-radius: initial;
165
+ }
166
+
167
+ .lm-modal[minimized="true"] {
168
+ width: 200px !important;
169
+ height: 45px !important;
170
+ min-width: initial;
171
+ min-height: initial;
172
+ overflow: hidden;
172
173
  }
package/package.json CHANGED
@@ -17,5 +17,5 @@
17
17
  },
18
18
  "main": "dist/index.js",
19
19
  "types": "dist/index.d.ts",
20
- "version": "2.4.10"
20
+ "version": "2.5.0"
21
21
  }