@pumpkin-tech/pumpkin-tech-ng 0.2.9 → 0.2.11

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.
@@ -104,12 +104,14 @@ class PtechGridDirective {
104
104
  display = 'grid';
105
105
  columns = 'repeat(12, minmax(0, 1fr))';
106
106
  activeBp = null;
107
+ viewportBp = null;
107
108
  constructor(bp) {
108
109
  this.bp = bp;
109
110
  this.bp.observe(Object.values(MEDIA$1))
110
111
  .pipe(takeUntil(this.destroy$))
111
112
  .subscribe(state => {
112
- this.activeBp = this.pickActive(state.breakpoints);
113
+ this.viewportBp = this.pickActive(state.breakpoints);
114
+ this.activeBp = this.viewportBp;
113
115
  this.updateCols();
114
116
  });
115
117
  }
@@ -129,16 +131,22 @@ class PtechGridDirective {
129
131
  this.columns = `repeat(${cols}, minmax(0, 1fr))`;
130
132
  }
131
133
  resolveColsForBp() {
132
- const map = {
133
- xs: this.asNum(this.ptechColsXs),
134
- sm: this.asNum(this.ptechColsSm),
135
- md: this.asNum(this.ptechColsMd),
136
- lg: this.asNum(this.ptechColsLg),
137
- xl: this.asNum(this.ptechColsXl),
138
- };
134
+ const xs = this.asNum(this.ptechColsXs);
135
+ const sm = this.asNum(this.ptechColsSm);
136
+ const md = this.asNum(this.ptechColsMd);
137
+ const lg = this.asNum(this.ptechColsLg);
138
+ const xl = this.asNum(this.ptechColsXl);
139
139
  const bp = this.activeBp;
140
- const span = bp ? map[bp] : undefined;
141
- return span ?? this._cols ?? 12;
140
+ if (!bp)
141
+ return this._cols ?? 12;
142
+ switch (bp) {
143
+ case 'xl': return xl ?? lg ?? md ?? sm ?? xs ?? this._cols ?? 12;
144
+ case 'lg': return lg ?? md ?? sm ?? xs ?? this._cols ?? 12;
145
+ case 'md': return md ?? sm ?? xs ?? this._cols ?? 12;
146
+ case 'sm': return sm ?? xs ?? this._cols ?? 12;
147
+ case 'xs': return xs ?? this._cols ?? 12;
148
+ default: return this._cols ?? 12;
149
+ }
142
150
  }
143
151
  asNum(v, fallback) {
144
152
  if (v === null || v === undefined || v === '')
@@ -213,6 +221,8 @@ class PtechColDirective {
213
221
  ptechColLg;
214
222
  ptechColXl;
215
223
  activeBp = null;
224
+ viewportBp = null;
225
+ containerBp = null;
216
226
  activeSource = null;
217
227
  gridColumn = 'auto / span 12';
218
228
  minWidth = '0';
@@ -226,9 +236,14 @@ class PtechColDirective {
226
236
  .subscribe(s => {
227
237
  if (this.ptechColMode === 'container')
228
238
  return;
229
- if (this.ptechColMode === 'auto' && this.activeSource === 'container')
239
+ this.viewportBp = this.pickActive(s.breakpoints);
240
+ if (this.ptechColMode === 'auto') {
241
+ this.activeBp = this.pickAutoBp();
242
+ this.activeSource = this.containerBp ? 'container' : 'viewport';
243
+ this.updateSpan();
230
244
  return;
231
- this.activeBp = this.pickActive(s.breakpoints);
245
+ }
246
+ this.activeBp = this.viewportBp;
232
247
  this.activeSource = 'viewport';
233
248
  this.updateSpan();
234
249
  });
@@ -250,11 +265,23 @@ class PtechColDirective {
250
265
  : w >= 960 ? 'md'
251
266
  : w >= 600 ? 'sm'
252
267
  : 'xs';
253
- if (bp !== this.activeBp || this.activeSource !== 'container') {
254
- this.activeBp = bp;
255
- this.activeSource = 'container';
256
- this.ngZone.run(() => this.updateSpan());
257
- }
268
+ this.containerBp = bp;
269
+ this.ngZone.run(() => {
270
+ if (this.ptechColMode === 'auto') {
271
+ const nextBp = this.pickAutoBp();
272
+ if (nextBp !== this.activeBp || this.activeSource !== 'container') {
273
+ this.activeBp = nextBp;
274
+ this.activeSource = 'container';
275
+ this.updateSpan();
276
+ }
277
+ return;
278
+ }
279
+ if (this.ptechColMode === 'container' && (bp !== this.activeBp || this.activeSource !== 'container')) {
280
+ this.activeBp = bp;
281
+ this.activeSource = 'container';
282
+ this.updateSpan();
283
+ }
284
+ });
258
285
  });
259
286
  });
260
287
  this.ro.observe(gridParent);
@@ -283,6 +310,14 @@ class PtechColDirective {
283
310
  return key;
284
311
  return null;
285
312
  }
313
+ pickAutoBp() {
314
+ const rank = { xs: 0, sm: 1, md: 2, lg: 3, xl: 4 };
315
+ if (!this.viewportBp)
316
+ return this.containerBp;
317
+ if (!this.containerBp)
318
+ return this.viewportBp;
319
+ return rank[this.viewportBp] <= rank[this.containerBp] ? this.viewportBp : this.containerBp;
320
+ }
286
321
  updateSpan() {
287
322
  const span = this.resolveColForBp();
288
323
  if (span === this.lastSpan)
@@ -291,16 +326,28 @@ class PtechColDirective {
291
326
  this.gridColumn = `auto / span ${span}`;
292
327
  }
293
328
  resolveColForBp() {
294
- const map = {
295
- xs: this.asNum(this.ptechColXs),
296
- sm: this.asNum(this.ptechColSm),
297
- md: this.asNum(this.ptechColMd),
298
- lg: this.asNum(this.ptechColLg),
299
- xl: this.asNum(this.ptechColXl),
300
- };
329
+ const xs = this.asNum(this.ptechColXs);
330
+ const sm = this.asNum(this.ptechColSm);
331
+ const md = this.asNum(this.ptechColMd);
332
+ const lg = this.asNum(this.ptechColLg);
333
+ const xl = this.asNum(this.ptechColXl);
301
334
  const bp = this.activeBp;
302
- const span = bp ? map[bp] : undefined;
303
- return span ?? this._col ?? 12;
335
+ if (!bp)
336
+ return this._col ?? 12;
337
+ // Cascata mobile-first:
338
+ // xl -> lg -> md -> sm -> xs -> base
339
+ // lg -> md -> sm -> xs -> base
340
+ // md -> sm -> xs -> base
341
+ // sm -> xs -> base
342
+ // xs -> base
343
+ switch (bp) {
344
+ case 'xl': return xl ?? lg ?? md ?? sm ?? xs ?? this._col ?? 12;
345
+ case 'lg': return lg ?? md ?? sm ?? xs ?? this._col ?? 12;
346
+ case 'md': return md ?? sm ?? xs ?? this._col ?? 12;
347
+ case 'sm': return sm ?? xs ?? this._col ?? 12;
348
+ case 'xs': return xs ?? this._col ?? 12;
349
+ default: return this._col ?? 12;
350
+ }
304
351
  }
305
352
  asNum(v, fallback) {
306
353
  if (v === null || v === undefined || v === '')