@masterteam/components 0.0.273 → 0.0.275

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, output, ElementRef, NgZone, Directive, model } from '@angular/core';
2
+ import { input, computed, ChangeDetectionStrategy, Component, inject, ElementRef, DestroyRef, afterNextRender, Directive, signal, effect, untracked, output, NgZone, 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';
@@ -57,6 +57,22 @@ function displayOrPlaceholder(value) {
57
57
  }
58
58
  return String(value);
59
59
  }
60
+ /**
61
+ * Text/LongText values are a plain string, except for translatable
62
+ * properties, where the backend sends `{ display, ar?, en? }` instead.
63
+ * Unwraps either shape to the string to render.
64
+ */
65
+ function extractDisplayText(value) {
66
+ if (typeof value === 'string') {
67
+ return value;
68
+ }
69
+ if (value &&
70
+ typeof value === 'object' &&
71
+ typeof value.display === 'string') {
72
+ return value.display;
73
+ }
74
+ return null;
75
+ }
60
76
  function isEntityLabelHidden(configuration) {
61
77
  const config = configuration;
62
78
  return config?.hideLabel ?? config?.hideName ?? false;
@@ -202,7 +218,7 @@ class EntityText {
202
218
  displayValue = computed(() => {
203
219
  const d = this.data();
204
220
  if (d) {
205
- return displayOrPlaceholder(typeof d.value === 'string' ? d.value : null);
221
+ return displayOrPlaceholder(extractDisplayText(d.value));
206
222
  }
207
223
  return displayOrPlaceholder(this.value());
208
224
  }, ...(ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []));
@@ -214,6 +230,109 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
214
230
  args: [{ selector: 'mt-entity-text', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [EntityField, TruncateTooltip], template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <!--\r\n Two lines before the ellipsis, not one. Portfolio and project names were\r\n being cut mid-word on the Explore board (\"Smart City Infrastructure Po\u2026\"),\r\n which makes similarly-titled records indistinguishable without opening each\r\n one (finding H-06). `line-clamp-2` still ellipsises what genuinely does not\r\n fit, and `mtTruncateTooltip` reads `scrollHeight > clientHeight`, so the\r\n tooltip keeps working for the clamped case exactly as it did for the\r\n single-line one.\r\n -->\r\n <div\r\n class=\"min-w-0 max-w-full line-clamp-2 break-words text-sm font-semibold\"\r\n mtTruncateTooltip\r\n tooltipPosition=\"top\"\r\n [innerHTML]=\"displayValue()\"\r\n ></div>\r\n</mt-entity-field>\r\n" }]
215
231
  }], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }] } });
216
232
 
233
+ /** Smallest size the text may shrink to before ellipsis takes over, in px. */
234
+ const MIN_FONT_PX = 11;
235
+ /** Each pass down the ramp. Small enough to look deliberate, not stepped. */
236
+ const STEP_PX = 0.5;
237
+ /**
238
+ * Shrinks an atomic value a little rather than letting it truncate.
239
+ *
240
+ * A date and an amount are single indivisible facts: `2026/08/16` cut to
241
+ * `2026/08…` has lost the day, and `100,000 SAR` cut to `100,000 …` has lost
242
+ * the currency — which is the one part a reader cannot infer. Prose survives an
243
+ * ellipsis; these do not, so they get one lever before it.
244
+ *
245
+ * Why measure instead of thresholding. The first pass at this capped currency
246
+ * by magnitude — compact anything above 100,000 — with the threshold read off
247
+ * one measured card slot. But slot width is a property of the card layout, not
248
+ * of the number: the three-across boxes on an Explore card are far narrower
249
+ * than the slot that was measured, so `100,000 SAR` and `50,000 SAR` sat under
250
+ * the threshold and truncated anyway. No constant can know the width it has.
251
+ * This asks the element.
252
+ *
253
+ * The element keeps its `truncate`, so anything still too long at the floor
254
+ * ellipsizes exactly as before — with the tooltip callers already attach
255
+ * carrying the full value. Shrinking is a nudge, never the whole answer.
256
+ */
257
+ class FitText {
258
+ /** Set false to leave a particular instance alone. */
259
+ mtFitText = input(true, { ...(ngDevMode ? { debugName: "mtFitText" } : /* istanbul ignore next */ {}), transform: (value) => value !== false && value !== 'false' });
260
+ host = inject(ElementRef);
261
+ destroyRef = inject(DestroyRef);
262
+ basePx = 0;
263
+ frame = 0;
264
+ resizeObserver;
265
+ mutationObserver;
266
+ constructor() {
267
+ afterNextRender(() => {
268
+ const el = this.host.nativeElement;
269
+ this.basePx = parseFloat(getComputedStyle(el).fontSize) || 0;
270
+ if (!this.basePx) {
271
+ return;
272
+ }
273
+ if (typeof ResizeObserver !== 'undefined') {
274
+ this.resizeObserver = new ResizeObserver(() => this.schedule());
275
+ this.resizeObserver.observe(el);
276
+ }
277
+ // The value itself changes without the box changing size — a re-fetch,
278
+ // a locale switch, an edit committed in place.
279
+ this.mutationObserver = new MutationObserver(() => this.schedule());
280
+ this.mutationObserver.observe(el, {
281
+ characterData: true,
282
+ childList: true,
283
+ subtree: true,
284
+ });
285
+ this.schedule();
286
+ });
287
+ this.destroyRef.onDestroy(() => {
288
+ this.resizeObserver?.disconnect();
289
+ this.mutationObserver?.disconnect();
290
+ if (this.frame) {
291
+ cancelAnimationFrame(this.frame);
292
+ }
293
+ });
294
+ }
295
+ schedule() {
296
+ if (this.frame) {
297
+ cancelAnimationFrame(this.frame);
298
+ }
299
+ this.frame = requestAnimationFrame(() => {
300
+ this.frame = 0;
301
+ this.fit();
302
+ });
303
+ }
304
+ fit() {
305
+ const el = this.host.nativeElement;
306
+ if (!this.mtFitText() || !this.basePx) {
307
+ el.style.removeProperty('font-size');
308
+ return;
309
+ }
310
+ // Always measure from the base size: the box may have grown back, and a
311
+ // value that once needed shrinking should return to full size when it fits.
312
+ el.style.fontSize = `${this.basePx}px`;
313
+ if (el.clientWidth === 0) {
314
+ return;
315
+ }
316
+ let size = this.basePx;
317
+ while (el.scrollWidth > el.clientWidth && size > MIN_FONT_PX) {
318
+ size = Math.max(MIN_FONT_PX, size - STEP_PX);
319
+ el.style.fontSize = `${size}px`;
320
+ }
321
+ if (size === this.basePx) {
322
+ el.style.removeProperty('font-size');
323
+ }
324
+ }
325
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: FitText, deps: [], target: i0.ɵɵFactoryTarget.Directive });
326
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "21.2.8", type: FitText, isStandalone: true, selector: "[mtFitText]", inputs: { mtFitText: { classPropertyName: "mtFitText", publicName: "mtFitText", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
327
+ }
328
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: FitText, decorators: [{
329
+ type: Directive,
330
+ args: [{
331
+ selector: '[mtFitText]',
332
+ standalone: true,
333
+ }]
334
+ }], ctorParameters: () => [], propDecorators: { mtFitText: [{ type: i0.Input, args: [{ isSignal: true, alias: "mtFitText", required: false }] }] } });
335
+
217
336
  class EntityDate {
218
337
  /** Full entity data object */
219
338
  data = input(...(ngDevMode ? [undefined, { debugName: "data" }] : /* istanbul ignore next */ []));
@@ -239,11 +358,11 @@ class EntityDate {
239
358
  }, ...(ngDevMode ? [{ debugName: "resolvedViewType" }] : /* istanbul ignore next */ []));
240
359
  displayValue = computed(() => this.data()?.rawValue ?? this.data()?.value ?? this.value(), ...(ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []));
241
360
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityDate, deps: [], target: i0.ɵɵFactoryTarget.Component });
242
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityDate, isStandalone: true, selector: "mt-entity-date", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, viewType: { classPropertyName: "viewType", publicName: "viewType", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n mtTruncateTooltip\r\n tooltipPosition=\"top\"\r\n >\r\n @if (displayValue()) {\r\n {{ displayValue() | mtDateFormat: resolvedViewType() }}\r\n } @else {\r\n -\r\n }\r\n </span>\r\n</mt-entity-field>\r\n", dependencies: [{ kind: "component", type: EntityField, selector: "mt-entity-field", inputs: ["label", "labelIconName", "configuration", "gap"] }, { kind: "directive", type: TruncateTooltip, selector: "[mtTruncateTooltip]" }, { kind: "pipe", type: MTDateFormatPipe, name: "mtDateFormat" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
361
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.2.8", type: EntityDate, isStandalone: true, selector: "mt-entity-date", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null }, viewType: { classPropertyName: "viewType", publicName: "viewType", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n mtFitText\r\n mtTruncateTooltip\r\n tooltipPosition=\"top\"\r\n >\r\n @if (displayValue()) {\r\n {{ displayValue() | mtDateFormat: resolvedViewType() }}\r\n } @else {\r\n -\r\n }\r\n </span>\r\n</mt-entity-field>\r\n", dependencies: [{ kind: "component", type: EntityField, selector: "mt-entity-field", inputs: ["label", "labelIconName", "configuration", "gap"] }, { kind: "directive", type: TruncateTooltip, selector: "[mtTruncateTooltip]" }, { kind: "directive", type: FitText, selector: "[mtFitText]", inputs: ["mtFitText"] }, { kind: "pipe", type: MTDateFormatPipe, name: "mtDateFormat" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
243
362
  }
244
363
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityDate, decorators: [{
245
364
  type: Component,
246
- args: [{ selector: 'mt-entity-date', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [EntityField, TruncateTooltip, MTDateFormatPipe], template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n mtTruncateTooltip\r\n tooltipPosition=\"top\"\r\n >\r\n @if (displayValue()) {\r\n {{ displayValue() | mtDateFormat: resolvedViewType() }}\r\n } @else {\r\n -\r\n }\r\n </span>\r\n</mt-entity-field>\r\n" }]
365
+ args: [{ selector: 'mt-entity-date', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [EntityField, TruncateTooltip, MTDateFormatPipe, FitText], template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n mtFitText\r\n mtTruncateTooltip\r\n tooltipPosition=\"top\"\r\n >\r\n @if (displayValue()) {\r\n {{ displayValue() | mtDateFormat: resolvedViewType() }}\r\n } @else {\r\n -\r\n }\r\n </span>\r\n</mt-entity-field>\r\n" }]
247
366
  }], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }], viewType: [{ type: i0.Input, args: [{ isSignal: true, alias: "viewType", required: false }] }] } });
248
367
 
249
368
  class EntityStatus {
@@ -657,11 +776,11 @@ class EntityCurrency {
657
776
  */
658
777
  displayValue = computed(() => compactCurrencyDisplay(this.fullValue(), this.data()?.rawValue, this.locale()), ...(ngDevMode ? [{ debugName: "displayValue" }] : /* istanbul ignore next */ []));
659
778
  static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityCurrency, deps: [], target: i0.ɵɵFactoryTarget.Component });
660
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.8", type: EntityCurrency, isStandalone: true, selector: "mt-entity-currency", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n [mtTooltip]=\"fullValue()\"\r\n tooltipPosition=\"top\"\r\n >\r\n {{ displayValue() }}\r\n </span>\r\n</mt-entity-field>\r\n", dependencies: [{ kind: "component", type: EntityField, selector: "mt-entity-field", inputs: ["label", "labelIconName", "configuration", "gap"] }, { kind: "directive", type: Tooltip, selector: "[mtTooltip]" }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
779
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "21.2.8", type: EntityCurrency, isStandalone: true, selector: "mt-entity-currency", inputs: { data: { classPropertyName: "data", publicName: "data", isSignal: true, isRequired: false, transformFunction: null }, name: { classPropertyName: "name", publicName: "name", isSignal: true, isRequired: false, transformFunction: null }, value: { classPropertyName: "value", publicName: "value", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0, template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n mtFitText\r\n [mtTooltip]=\"fullValue()\"\r\n tooltipPosition=\"top\"\r\n >\r\n {{ displayValue() }}\r\n </span>\r\n</mt-entity-field>\r\n", dependencies: [{ kind: "component", type: EntityField, selector: "mt-entity-field", inputs: ["label", "labelIconName", "configuration", "gap"] }, { kind: "directive", type: Tooltip, selector: "[mtTooltip]" }, { kind: "directive", type: FitText, selector: "[mtFitText]", inputs: ["mtFitText"] }], changeDetection: i0.ChangeDetectionStrategy.OnPush });
661
780
  }
662
781
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImport: i0, type: EntityCurrency, decorators: [{
663
782
  type: Component,
664
- args: [{ selector: 'mt-entity-currency', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [EntityField, Tooltip], template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n [mtTooltip]=\"fullValue()\"\r\n tooltipPosition=\"top\"\r\n >\r\n {{ displayValue() }}\r\n </span>\r\n</mt-entity-field>\r\n" }]
783
+ args: [{ selector: 'mt-entity-currency', changeDetection: ChangeDetectionStrategy.OnPush, standalone: true, imports: [EntityField, Tooltip, FitText], template: "<mt-entity-field\r\n [label]=\"displayName()\"\r\n [configuration]=\"data()?.configuration\"\r\n>\r\n <span\r\n class=\"block min-w-0 truncate text-sm font-semibold tabular-nums whitespace-nowrap\"\r\n mtFitText\r\n [mtTooltip]=\"fullValue()\"\r\n tooltipPosition=\"top\"\r\n >\r\n {{ displayValue() }}\r\n </span>\r\n</mt-entity-field>\r\n" }]
665
784
  }], propDecorators: { data: [{ type: i0.Input, args: [{ isSignal: true, alias: "data", required: false }] }], name: [{ type: i0.Input, args: [{ isSignal: true, alias: "name", required: false }] }], value: [{ type: i0.Input, args: [{ isSignal: true, alias: "value", required: false }] }] } });
666
785
 
667
786
  class EntityCheckbox {
@@ -715,11 +834,7 @@ class EntityLongText {
715
834
  displayName = computed(() => this.data()?.name ?? this.name() ?? '', ...(ngDevMode ? [{ debugName: "displayName" }] : /* istanbul ignore next */ []));
716
835
  displayValue = computed(() => {
717
836
  const d = this.data();
718
- const raw = d
719
- ? typeof d.value === 'string'
720
- ? d.value
721
- : null
722
- : this.value();
837
+ const raw = d ? extractDisplayText(d.value) : this.value();
723
838
  if (isValueMissing(raw)) {
724
839
  return ENTITY_EMPTY_VALUE_PLACEHOLDER;
725
840
  }
@@ -2367,5 +2482,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.2.8", ngImpor
2367
2482
  * Generated bundle index. Do not edit.
2368
2483
  */
2369
2484
 
2370
- export { CONNECTION_KEY_SEPARATOR, CURRENCY_COMPACT_THRESHOLD, ComparisonEntityList, ComparisonValue, DEFAULT_PHASE_GATE_COLOR, ENTITY_EMPTY_VALUE_PLACEHOLDER, EntitiesManage, EntitiesPreview, EntitiesResizeBase, EntityAttachment, EntityCheckbox, EntityConnection, EntityCurrency, EntityDate, EntityField, EntityLeafDetails, EntityLocation, EntityLongText, EntityLookup, EntityLookupModuleCheckList, EntityPercentage, EntityPhaseGate, EntityPreview, EntityPreviewBody, EntityScheduleItem, EntityStatus, EntityText, EntityUser, LEAF_DETAILS_KEY_SEPARATOR, SECTION_KEY_PREFIX, buildConnectionKey, buildDisplayEntities, buildSectionKey, compactCurrencyDisplay, currencyUnitOf, displayOrPlaceholder, expandConnectionEntity, expandLeafDetailsEntity, getEntitySectionTitle, groupEntitiesIntoSections, isConnectionSyntheticKey, isEntityAlignEnd, isEntityLabelHidden, isEntitySection, isLeafDetailsCatalogConfiguration, isLeafDetailsCollectionValue, isLeafDetailsRuntimeValue, isLeafDetailsSyntheticKey, isLeafDetailsValue, isSectionKey, isValueMissing, matchesPercentageColorRule, normalizeConnectionSourceLevels, normalizeNumerals, parseCurrencyAmount, resolveConnectionLevelName, resolveEntityLabelPosition, resolveLocalizedLabel, resolvePercentageColor, serializeEntityRawValue, splitConnectionKey };
2485
+ export { CONNECTION_KEY_SEPARATOR, CURRENCY_COMPACT_THRESHOLD, ComparisonEntityList, ComparisonValue, DEFAULT_PHASE_GATE_COLOR, ENTITY_EMPTY_VALUE_PLACEHOLDER, EntitiesManage, EntitiesPreview, EntitiesResizeBase, EntityAttachment, EntityCheckbox, EntityConnection, EntityCurrency, EntityDate, EntityField, EntityLeafDetails, EntityLocation, EntityLongText, EntityLookup, EntityLookupModuleCheckList, EntityPercentage, EntityPhaseGate, EntityPreview, EntityPreviewBody, EntityScheduleItem, EntityStatus, EntityText, EntityUser, FitText, LEAF_DETAILS_KEY_SEPARATOR, SECTION_KEY_PREFIX, buildConnectionKey, buildDisplayEntities, buildSectionKey, compactCurrencyDisplay, currencyUnitOf, displayOrPlaceholder, expandConnectionEntity, expandLeafDetailsEntity, extractDisplayText, getEntitySectionTitle, groupEntitiesIntoSections, isConnectionSyntheticKey, isEntityAlignEnd, isEntityLabelHidden, isEntitySection, isLeafDetailsCatalogConfiguration, isLeafDetailsCollectionValue, isLeafDetailsRuntimeValue, isLeafDetailsSyntheticKey, isLeafDetailsValue, isSectionKey, isValueMissing, matchesPercentageColorRule, normalizeConnectionSourceLevels, normalizeNumerals, parseCurrencyAmount, resolveConnectionLevelName, resolveEntityLabelPosition, resolveLocalizedLabel, resolvePercentageColor, serializeEntityRawValue, splitConnectionKey };
2371
2486
  //# sourceMappingURL=masterteam-components-entities.mjs.map