@masterteam/components 0.0.264 → 0.0.266
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.
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as i0 from '@angular/core';
|
|
2
|
-
import { input, computed, ChangeDetectionStrategy, Component, signal, effect, untracked, inject,
|
|
2
|
+
import { input, computed, ChangeDetectionStrategy, Component, signal, effect, untracked, inject, ElementRef, DestroyRef, NgZone, output, Directive, model } from '@angular/core';
|
|
3
3
|
import { TruncateTooltip, Tooltip } from '@masterteam/components/tooltip';
|
|
4
4
|
import { Icon } from '@masterteam/icons';
|
|
5
5
|
import { MTDateFormatPipe, REQUEST_CONTEXT, readableTextOn } from '@masterteam/components';
|
|
@@ -1851,12 +1851,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
1851
1851
|
}], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: true }] }], attachmentShape: [{ type: i0.Input, args: [{ isSignal: true, alias: "attachmentShape", required: false }] }] } });
|
|
1852
1852
|
|
|
1853
1853
|
const EMPTY_KEY_SET = new Set();
|
|
1854
|
+
/**
|
|
1855
|
+
* Below this host width a field narrower than {@link MIN_NARROW_SPAN} cannot
|
|
1856
|
+
* hold its own value. Matches the container query in the stylesheet, which
|
|
1857
|
+
* handles the `stackOnNarrow` case the same way.
|
|
1858
|
+
*/
|
|
1859
|
+
const NARROW_HOST_WIDTH = 400;
|
|
1860
|
+
/**
|
|
1861
|
+
* The smallest share of the 24-column grid a field may take on a narrow host —
|
|
1862
|
+
* half the row.
|
|
1863
|
+
*
|
|
1864
|
+
* A card that opts out of the soft stack still laid its fields on 24 columns,
|
|
1865
|
+
* so a three-field row inside a ~350px card gave each field about 90px, and at
|
|
1866
|
+
* that width a budget rendered "10,000 S…" and a date "01/07/2…" — finding H-06
|
|
1867
|
+
* in its narrowest form, and the reviewer was explicit that a date must never
|
|
1868
|
+
* be truncated. Raising the floor to half the row is done here rather than in
|
|
1869
|
+
* CSS because the grid cannot be re-tracked safely: a field configured `span 24`
|
|
1870
|
+
* would spill into implicit columns and collapse the explicit ones to zero.
|
|
1871
|
+
*/
|
|
1872
|
+
const MIN_NARROW_SPAN = 12;
|
|
1854
1873
|
/** Classes every entity slot carries, before its per-slot modifiers. */
|
|
1855
1874
|
const SLOT_BASE_CLASS = 'min-w-0 overflow-hidden flex items-center rounded transition-colors';
|
|
1856
1875
|
/** Opt-in dashed frame (`configuration.showBorder`). */
|
|
1857
1876
|
const SLOT_BORDER_CLASS = 'border p-3 border-dashed border-gray-200 rounded-lg';
|
|
1858
1877
|
class EntitiesPreview {
|
|
1859
1878
|
transloco = inject(TranslocoService);
|
|
1879
|
+
elementRef = inject(ElementRef);
|
|
1880
|
+
destroyRef = inject(DestroyRef);
|
|
1881
|
+
zone = inject(NgZone);
|
|
1860
1882
|
/** Array of entity data to display */
|
|
1861
1883
|
entities = input.required(...(ngDevMode ? [{ debugName: "entities" }] : /* istanbul ignore next */ []));
|
|
1862
1884
|
attachmentShape = input('default', ...(ngDevMode ? [{ debugName: "attachmentShape" }] : /* istanbul ignore next */ []));
|
|
@@ -1922,6 +1944,7 @@ class EntitiesPreview {
|
|
|
1922
1944
|
const clickableTooltip = this.clickableTooltip();
|
|
1923
1945
|
const activeTooltip = this.activeTooltip();
|
|
1924
1946
|
const lang = this.activeLang();
|
|
1947
|
+
const narrow = this.isNarrowHost();
|
|
1925
1948
|
return this.sectionGroups().map((group, groupIndex) => ({
|
|
1926
1949
|
trackKey: group.section?.key ?? `__group__${groupIndex}`,
|
|
1927
1950
|
boxed: !!group.section,
|
|
@@ -1934,7 +1957,7 @@ class EntitiesPreview {
|
|
|
1934
1957
|
entity,
|
|
1935
1958
|
trackKey: entity.key ?? String(entity.order ?? entityIndex),
|
|
1936
1959
|
containerClass: buildSlotClass(entity, clickable, active),
|
|
1937
|
-
colSpan: `span ${(entity
|
|
1960
|
+
colSpan: `span ${resolveSpan(entity, narrow)}`,
|
|
1938
1961
|
clickable,
|
|
1939
1962
|
rowClickIgnore: clickable ? 'true' : null,
|
|
1940
1963
|
title: clickable ? (active ? activeTooltip : clickableTooltip) : null,
|
|
@@ -1942,6 +1965,34 @@ class EntitiesPreview {
|
|
|
1942
1965
|
}),
|
|
1943
1966
|
}));
|
|
1944
1967
|
}, ...(ngDevMode ? [{ debugName: "slotGroups" }] : /* istanbul ignore next */ []));
|
|
1968
|
+
/**
|
|
1969
|
+
* Whether the host is too narrow for the 24-column grid to stay legible.
|
|
1970
|
+
*
|
|
1971
|
+
* Measured rather than assumed: this component is narrow because of the
|
|
1972
|
+
* column layout it sits in, not because of the viewport, so a media query
|
|
1973
|
+
* would answer the wrong question — the same reason the stylesheet uses a
|
|
1974
|
+
* container query.
|
|
1975
|
+
*/
|
|
1976
|
+
hostWidth = signal(Number.POSITIVE_INFINITY, ...(ngDevMode ? [{ debugName: "hostWidth" }] : /* istanbul ignore next */ []));
|
|
1977
|
+
isNarrowHost = computed(() => this.hostWidth() <= NARROW_HOST_WIDTH, ...(ngDevMode ? [{ debugName: "isNarrowHost" }] : /* istanbul ignore next */ []));
|
|
1978
|
+
constructor() {
|
|
1979
|
+
if (typeof ResizeObserver === 'undefined') {
|
|
1980
|
+
return;
|
|
1981
|
+
}
|
|
1982
|
+
const element = this.elementRef.nativeElement;
|
|
1983
|
+
// `ResizeObserver` callbacks fire outside Angular's zone, so writing the
|
|
1984
|
+
// signal there marks this component dirty but schedules nothing to act on
|
|
1985
|
+
// it. Running the write inside the zone is what makes the re-render happen
|
|
1986
|
+
// (and is a no-op passthrough in a zoneless host).
|
|
1987
|
+
const observer = new ResizeObserver((entries) => {
|
|
1988
|
+
const width = entries[0]?.contentRect.width;
|
|
1989
|
+
if (typeof width === 'number' && width > 0) {
|
|
1990
|
+
this.zone.run(() => this.hostWidth.set(width));
|
|
1991
|
+
}
|
|
1992
|
+
});
|
|
1993
|
+
observer.observe(element);
|
|
1994
|
+
this.destroyRef.onDestroy(() => observer.disconnect());
|
|
1995
|
+
}
|
|
1945
1996
|
onSlotClick(source, slot) {
|
|
1946
1997
|
if (!slot.clickable)
|
|
1947
1998
|
return;
|
|
@@ -1961,7 +2012,15 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
|
|
|
1961
2012
|
class: 'block min-w-0 w-full',
|
|
1962
2013
|
'[class.mt-entities-stack-narrow]': 'stackOnNarrow()',
|
|
1963
2014
|
}, template: "<div class=\"flex flex-col gap-4\">\r\n @for (group of slotGroups(); track group.trackKey) {\r\n @if (group.boxed) {\r\n <!-- Titled section box (matches the client-form section view) -->\r\n <div\r\n class=\"flex flex-col gap-0 overflow-hidden rounded-md border border-surface-200 bg-surface-0\"\r\n >\r\n @if (group.title) {\r\n <h3\r\n class=\"m-0 border-b border-surface-200 bg-surface-50 px-4 py-3 text-lg font-semibold text-color\"\r\n dir=\"auto\"\r\n >\r\n {{ group.title }}\r\n </h3>\r\n }\r\n <div class=\"p-4\">\r\n <ng-container\r\n [ngTemplateOutlet]=\"entityGrid\"\r\n [ngTemplateOutletContext]=\"{ $implicit: group.slots }\"\r\n />\r\n </div>\r\n </div>\r\n } @else {\r\n <ng-container\r\n [ngTemplateOutlet]=\"entityGrid\"\r\n [ngTemplateOutletContext]=\"{ $implicit: group.slots }\"\r\n />\r\n }\r\n }\r\n</div>\r\n\r\n<!--\r\n Every binding here reads a value the component already resolved into the slot\r\n (see `EntitiesPreview.slotGroups`). Keep it that way: this template runs once\r\n per entity per change detection pass, and a card grid renders thousands of\r\n them, so a method call or a fresh object literal in this block is measurably\r\n expensive.\r\n-->\r\n<ng-template #entityGrid let-slots>\r\n <div class=\"mt-entities-grid grid grid-cols-24 gap-x-3 gap-y-5\">\r\n @for (slot of slots; track slot.trackKey) {\r\n <div\r\n [class]=\"slot.containerClass\"\r\n [attr.data-row-click-ignore]=\"slot.rowClickIgnore\"\r\n [attr.title]=\"slot.title\"\r\n [style.grid-column]=\"slot.colSpan\"\r\n (click)=\"onSlotClick($event, slot)\"\r\n >\r\n <mt-entity-preview\r\n [data]=\"slot.entity\"\r\n [attachmentShape]=\"attachmentShape()\"\r\n />\r\n </div>\r\n }\r\n </div>\r\n</ng-template>\r\n", styles: [":host{container-type:inline-size}@container (max-width: 400px){:host(.mt-entities-stack-narrow) .mt-entities-grid{grid-template-columns:1fr;column-gap:0}:host(.mt-entities-stack-narrow) .mt-entities-grid>*{grid-column:1 / -1!important}}@container (max-width: 280px){.mt-entities-grid{grid-template-columns:1fr;column-gap:0}.mt-entities-grid>*{grid-column:1 / -1!important}}.mt-entity-filterable{cursor:url(\"data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='none' stroke='%2314b8a6' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 3H2l8 9.46V19l4 2v-8.54L22 3z'/%3E%3C/svg%3E\") 7 3,zoom-in!important}.mt-entity-filter-active{cursor:url(\"data:image/svg+xml;utf8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='14' height='14' viewBox='0 0 24 24' fill='%2314b8a6' stroke='%2314b8a6' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M22 3H2l8 9.46V19l4 2v-8.54L22 3z'/%3E%3C/svg%3E\") 7 3,zoom-out!important}.mt-entity-filterable:hover{background-color:#ccfbf147;outline:1px dashed rgb(20 184 166 / .28);outline-offset:2px}.mt-entity-filter-active{background-color:#ccfbf14d;box-shadow:inset 0 0 0 1.5px #14b8a666,0 0 0 1px #ffffff80}\n"] }]
|
|
1964
|
-
}], propDecorators: { entities: [{ type: i0.Input, args: [{ isSignal: true, alias: "entities", required: true }] }], attachmentShape: [{ type: i0.Input, args: [{ isSignal: true, alias: "attachmentShape", required: false }] }], stackOnNarrow: [{ type: i0.Input, args: [{ isSignal: true, alias: "stackOnNarrow", required: false }] }], clickableKeys: [{ type: i0.Input, args: [{ isSignal: true, alias: "clickableKeys", required: false }] }], activeKeys: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeKeys", required: false }] }], clickableTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "clickableTooltip", required: false }] }], activeTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeTooltip", required: false }] }], entityClick: [{ type: i0.Output, args: ["entityClick"] }] } });
|
|
2015
|
+
}], ctorParameters: () => [], propDecorators: { entities: [{ type: i0.Input, args: [{ isSignal: true, alias: "entities", required: true }] }], attachmentShape: [{ type: i0.Input, args: [{ isSignal: true, alias: "attachmentShape", required: false }] }], stackOnNarrow: [{ type: i0.Input, args: [{ isSignal: true, alias: "stackOnNarrow", required: false }] }], clickableKeys: [{ type: i0.Input, args: [{ isSignal: true, alias: "clickableKeys", required: false }] }], activeKeys: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeKeys", required: false }] }], clickableTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "clickableTooltip", required: false }] }], activeTooltip: [{ type: i0.Input, args: [{ isSignal: true, alias: "activeTooltip", required: false }] }], entityClick: [{ type: i0.Output, args: ["entityClick"] }] } });
|
|
2016
|
+
/**
|
|
2017
|
+
* The column span a field renders at: its configured size, floored to half the
|
|
2018
|
+
* row once the host is too narrow for that size to hold the value.
|
|
2019
|
+
*/
|
|
2020
|
+
function resolveSpan(entity, narrow) {
|
|
2021
|
+
const size = (entity.configuration?.size ?? 8);
|
|
2022
|
+
return narrow && size < MIN_NARROW_SPAN ? MIN_NARROW_SPAN : size;
|
|
2023
|
+
}
|
|
1965
2024
|
/** Stable key resolution shared with the host — must agree on order. */
|
|
1966
2025
|
function resolveEntityKey(entity) {
|
|
1967
2026
|
return entity.key || entity.normalizedKey || entity.name || '';
|