@contrail/documents 2.4.0-alpha.ce67280 → 2.4.0-alpha.e27d364

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
@@ -64,6 +64,12 @@ Also shipped on the 1.x line as 1.21.0.
64
64
  `n/a`. `calculateSize` no longer throws on an element that reaches it without a `size`, which on
65
65
  the server failed the read for the whole document.
66
66
 
67
+ - `min` and `max` over a date property rendered nothing at all. `Number` of a date string is `NaN`,
68
+ so every member was dropped; they now order by the instant each date names.
69
+ - `uniqueArray` sorted the rendered text rather than the value, so `11/20/2026` came after
70
+ `01/15/2027` and `100` before `9`. It now orders by value, falling back to text order for values
71
+ that are neither a date nor a number.
72
+
67
73
  ### Changed
68
74
 
69
75
  - `anchorFor` and the index measure through the same factory call, so a caller holding an element
@@ -52,6 +52,7 @@ export declare const HARD_CODED_TEXT: {
52
52
  };
53
53
  export declare function isContainerBinding(bindingProperty: string | null | undefined): boolean;
54
54
  export declare class DynamicTextUtil {
55
+ static componentsBoundTo(componentElements: DocumentElement[], entityType: string): DocumentElement[];
55
56
  static isDynamicText(documentElement: DocumentElement): boolean;
56
57
  static takesValueFromContainer(bindingProperty: string | null | undefined): boolean;
57
58
  static getDynamicTextValue(dynamicTextElement: DocumentElement, property: TypeProperty, propertyLevel: PropertyLevel, container: DynamicTextContainer | null, componentModels: any[], ownerReferenceModel?: any): string;
@@ -59,6 +60,7 @@ export declare class DynamicTextUtil {
59
60
  width: number;
60
61
  height: number;
61
62
  };
63
+ private static rankValue;
62
64
  static getTextFromFrameMemberValues(displayFunction: string, property: any, memberValues: any[]): string;
63
65
  private static getItemCount;
64
66
  }
@@ -63,6 +63,12 @@ function isContainerBinding(bindingProperty) {
63
63
  return DynamicTextUtil.takesValueFromContainer(bindingProperty);
64
64
  }
65
65
  class DynamicTextUtil {
66
+ static componentsBoundTo(componentElements, entityType) {
67
+ if (CONTAINER_SOURCES.includes(entityType)) {
68
+ return componentElements;
69
+ }
70
+ return (componentElements !== null && componentElements !== void 0 ? componentElements : []).filter((element) => { var _a; return Object.keys((_a = element === null || element === void 0 ? void 0 : element.modelBindings) !== null && _a !== void 0 ? _a : {}).includes(entityType); });
71
+ }
66
72
  static isDynamicText(documentElement) {
67
73
  var _a;
68
74
  return ((documentElement === null || documentElement === void 0 ? void 0 : documentElement.type) === 'text' &&
@@ -204,6 +210,9 @@ class DynamicTextUtil {
204
210
  catch (e) { }
205
211
  return size;
206
212
  }
213
+ static rankValue(value, property) {
214
+ return (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date ? Date.parse(value) : Number(value);
215
+ }
207
216
  static getTextFromFrameMemberValues(displayFunction, property, memberValues) {
208
217
  let text = '';
209
218
  if (memberValues.length === 0) {
@@ -219,11 +228,16 @@ class DynamicTextUtil {
219
228
  text = formatter.formatValueForProperty(memberValues.reduce((a, b) => a + b, 0), property);
220
229
  }
221
230
  else if (displayFunction === DynamicTextDisplayFunction.UNIQUE_ARRAY) {
222
- text = Array.from(new Set(memberValues
223
- .filter((e) => e !== null && e !== undefined && e !== '')
224
- .flat()
225
- .map((e) => formatter.formatValueForProperty(e, property))))
226
- .sort()
231
+ const byValue = new Map();
232
+ for (const value of memberValues.filter((e) => e !== null && e !== undefined && e !== '').flat()) {
233
+ const formatted = formatter.formatValueForProperty(value, property);
234
+ if (!byValue.has(formatted)) {
235
+ byValue.set(formatted, DynamicTextUtil.rankValue(value, property));
236
+ }
237
+ }
238
+ text = Array.from(byValue)
239
+ .sort(([leftText, leftRank], [rightText, rightRank]) => Number.isNaN(leftRank) || Number.isNaN(rightRank) ? leftText.localeCompare(rightText) : leftRank - rightRank)
240
+ .map(([formatted]) => formatted)
227
241
  .join(', ');
228
242
  }
229
243
  else if (!displayFunction ||
@@ -235,15 +249,17 @@ class DynamicTextUtil {
235
249
  }
236
250
  else if (displayFunction === DynamicTextDisplayFunction.MIN ||
237
251
  displayFunction === DynamicTextDisplayFunction.MAX) {
238
- const present = memberValues
252
+ const isDate = (property === null || property === void 0 ? void 0 : property.propertyType) === types_1.PropertyType.Date;
253
+ const ranked = memberValues
239
254
  .filter((e) => e !== null && e !== undefined && e !== '')
240
- .map(Number)
241
- .filter((e) => !Number.isNaN(e));
242
- if (!present.length) {
255
+ .map((value) => ({ value, rank: DynamicTextUtil.rankValue(value, property) }))
256
+ .filter(({ rank }) => !Number.isNaN(rank));
257
+ if (!ranked.length) {
243
258
  return '';
244
259
  }
245
- const extreme = displayFunction === DynamicTextDisplayFunction.MIN ? Math.min(...present) : Math.max(...present);
246
- text = formatter.formatValueForProperty(extreme, property);
260
+ const wantsLower = displayFunction === DynamicTextDisplayFunction.MIN;
261
+ const extreme = ranked.reduce((best, candidate) => (wantsLower ? candidate.rank < best.rank : candidate.rank > best.rank) ? candidate : best);
262
+ text = formatter.formatValueForProperty(isDate ? extreme.value : extreme.rank, property);
247
263
  }
248
264
  return text;
249
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contrail/documents",
3
- "version": "2.4.0-alpha.ce67280",
3
+ "version": "2.4.0-alpha.e27d364",
4
4
  "description": "Documents library for contrail platform",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",