uicore-ts 1.1.141 → 1.1.145
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/compiledScripts/UIObject.d.ts +1 -1
- package/compiledScripts/UIObject.js.map +1 -1
- package/compiledScripts/UITableView.d.ts +1 -0
- package/compiledScripts/UITableView.js +28 -6
- package/compiledScripts/UITableView.js.map +2 -2
- package/compiledScripts/UITextField.js +10 -10
- package/compiledScripts/UITextField.js.map +2 -2
- package/compiledScripts/UITextView.d.ts +25 -5
- package/compiledScripts/UITextView.js +157 -57
- package/compiledScripts/UITextView.js.map +2 -2
- package/compiledScripts/UIView.d.ts +4 -4
- package/compiledScripts/UIView.js +2 -1
- package/compiledScripts/UIView.js.map +2 -2
- package/package.json +1 -1
- package/scripts/UIObject.ts +1 -1
- package/scripts/UITableView.ts +31 -6
- package/scripts/UITextField.ts +16 -72
- package/scripts/UITextView.ts +253 -81
- package/scripts/UIView.ts +9 -6
package/scripts/UITextView.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { UIColor } from "./UIColor"
|
|
2
2
|
import { UILocalizedTextObject } from "./UIInterfaces"
|
|
3
|
-
import { FIRST, IS_LIKE_NULL, nil, NO, UIObject, ValueOf, YES } from "./UIObject"
|
|
3
|
+
import { EXTEND, FIRST, IS_LIKE_NULL, nil, NO, UIObject, ValueOf, YES } from "./UIObject"
|
|
4
4
|
import { UIRectangle } from "./UIRectangle"
|
|
5
5
|
import { TextMeasurementStyle, UITextMeasurement } from "./UITextMeasurement"
|
|
6
6
|
import { UIView, UIViewBroadcastEvent } from "./UIView"
|
|
@@ -35,51 +35,71 @@ export class UITextView extends UIView {
|
|
|
35
35
|
} as const
|
|
36
36
|
|
|
37
37
|
static textAlignment = {
|
|
38
|
-
"left": "
|
|
38
|
+
"left": "left",
|
|
39
39
|
"center": "center",
|
|
40
|
-
"right": "
|
|
41
|
-
"justify": "
|
|
40
|
+
"right": "right",
|
|
41
|
+
"justify": "justify"
|
|
42
42
|
} as const
|
|
43
43
|
|
|
44
44
|
//#endregion
|
|
45
45
|
|
|
46
46
|
//#region Constructor
|
|
47
47
|
|
|
48
|
+
|
|
48
49
|
constructor(
|
|
49
50
|
elementID?: string,
|
|
50
51
|
textViewType: string | ValueOf<typeof UITextView.type> = UITextView.type.paragraph,
|
|
51
52
|
viewHTMLElement = null
|
|
52
53
|
) {
|
|
53
54
|
|
|
54
|
-
|
|
55
|
+
// Create inner text element as a UIView
|
|
56
|
+
const innerElementID = elementID ? `${elementID}_textElement` : undefined
|
|
57
|
+
const _textElementView = new UIView(innerElementID, null, textViewType)
|
|
55
58
|
|
|
56
|
-
this
|
|
59
|
+
// Create outer container (wrapper) - this is the main viewHTMLElement
|
|
60
|
+
super(elementID, viewHTMLElement, "span", { _textElementView })
|
|
57
61
|
|
|
58
|
-
|
|
59
|
-
this.style.textOverflow = "ellipsis"
|
|
60
|
-
this.isSingleLine = YES
|
|
62
|
+
// Configure outer container for vertical centering using direct property access
|
|
61
63
|
|
|
62
|
-
this.
|
|
64
|
+
this.configureWithObject({
|
|
65
|
+
// @ts-ignore
|
|
66
|
+
viewHTMLElement: {
|
|
67
|
+
style: {
|
|
68
|
+
display: "flex",
|
|
69
|
+
alignItems: "center", // Vertical centering
|
|
70
|
+
overflow: "hidden"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
this.text = ""
|
|
63
76
|
|
|
64
|
-
this.
|
|
77
|
+
this._textElementView = _textElementView
|
|
65
78
|
|
|
66
|
-
|
|
79
|
+
// Configure inner text element for ellipsis and positioning
|
|
80
|
+
this._textElementView.configureWithObject({
|
|
67
81
|
style: {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
whiteSpace: "normal",
|
|
78
|
-
wordWrap: "break-word",
|
|
79
|
-
overflowWrap: "break-word"
|
|
80
|
-
}
|
|
82
|
+
position: "relative",
|
|
83
|
+
overflow: "hidden",
|
|
84
|
+
textOverflow: "ellipsis",
|
|
85
|
+
width: "100%",
|
|
86
|
+
margin: "0",
|
|
87
|
+
padding: "0"
|
|
88
|
+
},
|
|
89
|
+
// Forward control events from text element to the container
|
|
90
|
+
sendControlEventForKey: EXTEND(this.sendControlEventForKey.bind(this))
|
|
81
91
|
})
|
|
82
92
|
|
|
93
|
+
// Add text element as a subview
|
|
94
|
+
this.addSubview(this._textElementView)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
this.isSingleLine = YES
|
|
98
|
+
|
|
99
|
+
this.textColor = this.textColor
|
|
100
|
+
|
|
101
|
+
this.userInteractionEnabled = YES
|
|
102
|
+
|
|
83
103
|
if (textViewType == UITextView.type.textArea) {
|
|
84
104
|
this.pausesPointerEvents = YES
|
|
85
105
|
this.addTargetForControlEvent(
|
|
@@ -91,6 +111,51 @@ export class UITextView extends UIView {
|
|
|
91
111
|
|
|
92
112
|
//#endregion
|
|
93
113
|
|
|
114
|
+
//#region Text Element View Property
|
|
115
|
+
|
|
116
|
+
private _textElementView: UIView
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* The inner text element that holds the actual text content
|
|
120
|
+
*/
|
|
121
|
+
get textElementView(): UIView {
|
|
122
|
+
return this._textElementView
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/**
|
|
126
|
+
* Override style to apply to the text element instead of the container
|
|
127
|
+
*/
|
|
128
|
+
// override get style() {
|
|
129
|
+
// return this._textElementView.style
|
|
130
|
+
// }
|
|
131
|
+
//
|
|
132
|
+
// /**
|
|
133
|
+
// * Override computedStyle to get computed styles from the text element
|
|
134
|
+
// */
|
|
135
|
+
// override get computedStyle() {
|
|
136
|
+
// return this._textElementView.computedStyle
|
|
137
|
+
// }
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Access the outer container's style (for positioning, layout, etc.)
|
|
141
|
+
*/
|
|
142
|
+
get containerStyle() {
|
|
143
|
+
return this.viewHTMLElement.style
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Override styleClasses to apply to the text element
|
|
148
|
+
*/
|
|
149
|
+
override get styleClasses() {
|
|
150
|
+
return this._textElementView.styleClasses
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
override set styleClasses(styleClasses: string[]) {
|
|
154
|
+
this._textElementView.styleClasses = styleClasses
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
//#endregion
|
|
158
|
+
|
|
94
159
|
//#region Lifecycle Methods
|
|
95
160
|
|
|
96
161
|
override didReceiveBroadcastEvent(event: UIViewBroadcastEvent) {
|
|
@@ -106,9 +171,12 @@ export class UITextView extends UIView {
|
|
|
106
171
|
|
|
107
172
|
if (this._automaticFontSizeSelection) {
|
|
108
173
|
this.fontSize = UITextView.automaticallyCalculatedFontSize(
|
|
109
|
-
new UIRectangle(
|
|
110
|
-
|
|
111
|
-
|
|
174
|
+
new UIRectangle(
|
|
175
|
+
0,
|
|
176
|
+
0,
|
|
177
|
+
this.textElementView.viewHTMLElement.offsetHeight,
|
|
178
|
+
this.textElementView.viewHTMLElement.offsetWidth
|
|
179
|
+
),
|
|
112
180
|
this.intrinsicContentSize(),
|
|
113
181
|
this.fontSize,
|
|
114
182
|
this._minFontSize,
|
|
@@ -123,7 +191,7 @@ export class UITextView extends UIView {
|
|
|
123
191
|
|
|
124
192
|
private _invalidateMeasurementStyles(): void {
|
|
125
193
|
this._cachedMeasurementStyles = undefined
|
|
126
|
-
UITextMeasurement.invalidateElement(this.viewHTMLElement)
|
|
194
|
+
UITextMeasurement.invalidateElement(this.textElementView.viewHTMLElement)
|
|
127
195
|
this._intrinsicSizesCache = {}
|
|
128
196
|
}
|
|
129
197
|
|
|
@@ -133,15 +201,15 @@ export class UITextView extends UIView {
|
|
|
133
201
|
}
|
|
134
202
|
|
|
135
203
|
// Ensure element is in document
|
|
136
|
-
if (!this.viewHTMLElement.isConnected) {
|
|
204
|
+
if (!this.textElementView.viewHTMLElement.isConnected) {
|
|
137
205
|
return null
|
|
138
206
|
}
|
|
139
207
|
|
|
140
208
|
// Force a layout flush ONCE to ensure computed styles are available
|
|
141
209
|
// This is only paid once per style change, then we use cached values
|
|
142
|
-
this.viewHTMLElement.offsetHeight
|
|
210
|
+
this.textElementView.viewHTMLElement.offsetHeight
|
|
143
211
|
|
|
144
|
-
const computed = window.getComputedStyle(this.viewHTMLElement)
|
|
212
|
+
const computed = window.getComputedStyle(this.textElementView.viewHTMLElement)
|
|
145
213
|
const fontSizeStr = computed.fontSize
|
|
146
214
|
const fontSize = parseFloat(fontSizeStr)
|
|
147
215
|
|
|
@@ -156,18 +224,18 @@ export class UITextView extends UIView {
|
|
|
156
224
|
}
|
|
157
225
|
|
|
158
226
|
const font = [
|
|
159
|
-
computed.fontStyle ||
|
|
160
|
-
computed.fontVariant ||
|
|
161
|
-
computed.fontWeight ||
|
|
162
|
-
fontSize +
|
|
163
|
-
computed.fontFamily ||
|
|
227
|
+
computed.fontStyle || "normal",
|
|
228
|
+
computed.fontVariant || "normal",
|
|
229
|
+
computed.fontWeight || "normal",
|
|
230
|
+
fontSize + "px",
|
|
231
|
+
computed.fontFamily || "sans-serif"
|
|
164
232
|
].join(" ")
|
|
165
233
|
|
|
166
234
|
this._cachedMeasurementStyles = {
|
|
167
235
|
font: font,
|
|
168
236
|
fontSize: fontSize,
|
|
169
237
|
lineHeight: lineHeight,
|
|
170
|
-
whiteSpace: computed.whiteSpace ||
|
|
238
|
+
whiteSpace: computed.whiteSpace || "normal",
|
|
171
239
|
paddingLeft: parseFloat(computed.paddingLeft) || 0,
|
|
172
240
|
paddingRight: parseFloat(computed.paddingRight) || 0,
|
|
173
241
|
paddingTop: parseFloat(computed.paddingTop) || 0,
|
|
@@ -192,7 +260,7 @@ export class UITextView extends UIView {
|
|
|
192
260
|
}
|
|
193
261
|
|
|
194
262
|
private _shouldUseFastMeasurement(): boolean {
|
|
195
|
-
const content = this.text || this.innerHTML
|
|
263
|
+
const content = this.text || this.textElementView.innerHTML
|
|
196
264
|
|
|
197
265
|
if (this._innerHTMLKey || this._localizedTextObject) {
|
|
198
266
|
return false
|
|
@@ -226,12 +294,12 @@ export class UITextView extends UIView {
|
|
|
226
294
|
//#region Getters & Setters - Text Alignment
|
|
227
295
|
|
|
228
296
|
get textAlignment() {
|
|
229
|
-
|
|
230
|
-
return this.style.alignItems
|
|
297
|
+
return this._textElementView.style.textAlign as ValueOf<typeof UITextView.textAlignment>
|
|
231
298
|
}
|
|
232
299
|
|
|
233
300
|
set textAlignment(textAlignment: ValueOf<typeof UITextView.textAlignment>) {
|
|
234
|
-
this.
|
|
301
|
+
this._textAlignment = textAlignment
|
|
302
|
+
this._textElementView.style.textAlign = textAlignment
|
|
235
303
|
}
|
|
236
304
|
|
|
237
305
|
//#endregion
|
|
@@ -244,7 +312,7 @@ export class UITextView extends UIView {
|
|
|
244
312
|
|
|
245
313
|
set textColor(color: UIColor) {
|
|
246
314
|
this._textColor = color || UITextView.defaultTextColor
|
|
247
|
-
this.style.color = this._textColor.stringValue
|
|
315
|
+
this._textElementView.style.color = this._textColor.stringValue
|
|
248
316
|
}
|
|
249
317
|
|
|
250
318
|
//#endregion
|
|
@@ -262,11 +330,23 @@ export class UITextView extends UIView {
|
|
|
262
330
|
this._intrinsicWidthCache = new UIObject() as any
|
|
263
331
|
|
|
264
332
|
if (isSingleLine) {
|
|
265
|
-
|
|
333
|
+
// Single line: use nowrap with ellipsis
|
|
334
|
+
this._textElementView.style.whiteSpace = "nowrap"
|
|
335
|
+
this._textElementView.style.textOverflow = "ellipsis"
|
|
336
|
+
this._textElementView.style.display = ""
|
|
337
|
+
this._textElementView.style.webkitLineClamp = ""
|
|
338
|
+
this._textElementView.style.webkitBoxOrient = ""
|
|
266
339
|
return
|
|
267
340
|
}
|
|
268
341
|
|
|
269
|
-
|
|
342
|
+
// Multiline: allow wrapping, but still show ellipsis if content overflows the container
|
|
343
|
+
// This uses the -webkit-line-clamp approach which works for multiline ellipsis
|
|
344
|
+
this._textElementView.style.whiteSpace = "normal"
|
|
345
|
+
this._textElementView.style.textOverflow = "ellipsis"
|
|
346
|
+
this._textElementView.style.display = "-webkit-box"
|
|
347
|
+
this._textElementView.style.webkitBoxOrient = "vertical"
|
|
348
|
+
// Don't set line-clamp to a specific number - let it fill available space
|
|
349
|
+
// The overflow: hidden from the constructor will clip content that exceeds the height
|
|
270
350
|
this.invalidateMeasurementStrategy()
|
|
271
351
|
}
|
|
272
352
|
|
|
@@ -297,7 +377,7 @@ export class UITextView extends UIView {
|
|
|
297
377
|
//#region Getters & Setters - Text Content
|
|
298
378
|
|
|
299
379
|
get text() {
|
|
300
|
-
return (this._text || this.viewHTMLElement.innerHTML)
|
|
380
|
+
return (this._text || this.textElementView.viewHTMLElement.innerHTML)
|
|
301
381
|
}
|
|
302
382
|
|
|
303
383
|
set text(text) {
|
|
@@ -308,8 +388,9 @@ export class UITextView extends UIView {
|
|
|
308
388
|
(" (" + this.notificationAmount + ")").bold() + "</span>"
|
|
309
389
|
}
|
|
310
390
|
|
|
311
|
-
if (this.viewHTMLElement.innerHTML != this.textPrefix + text + this.textSuffix + notificationText) {
|
|
312
|
-
this.viewHTMLElement.innerHTML = this.textPrefix + FIRST(
|
|
391
|
+
if (this.textElementView.viewHTMLElement.innerHTML != this.textPrefix + text + this.textSuffix + notificationText) {
|
|
392
|
+
this.textElementView.viewHTMLElement.innerHTML = this.textPrefix + FIRST(
|
|
393
|
+
text, "") + this.textSuffix + notificationText
|
|
313
394
|
}
|
|
314
395
|
|
|
315
396
|
if (this.changesOften) {
|
|
@@ -336,7 +417,7 @@ export class UITextView extends UIView {
|
|
|
336
417
|
}
|
|
337
418
|
|
|
338
419
|
setText(key: string, defaultString: string, parameters?: { [x: string]: string | UILocalizedTextObject }) {
|
|
339
|
-
this.setInnerHTML(key, defaultString, parameters)
|
|
420
|
+
this.textElementView.setInnerHTML(key, defaultString, parameters)
|
|
340
421
|
this.invalidateMeasurementStrategy()
|
|
341
422
|
}
|
|
342
423
|
|
|
@@ -345,14 +426,14 @@ export class UITextView extends UIView {
|
|
|
345
426
|
//#region Getters & Setters - Font Size
|
|
346
427
|
|
|
347
428
|
get fontSize() {
|
|
348
|
-
const style = this.style.fontSize || window.getComputedStyle(this.viewHTMLElement, null).fontSize
|
|
429
|
+
const style = this._textElementView.style.fontSize || window.getComputedStyle(this._textElementView.viewHTMLElement, null).fontSize
|
|
349
430
|
const result = (parseFloat(style) * UITextView._pxToPt)
|
|
350
431
|
return result
|
|
351
432
|
}
|
|
352
433
|
|
|
353
434
|
set fontSize(fontSize: number) {
|
|
354
435
|
if (fontSize != this.fontSize) {
|
|
355
|
-
this.style.fontSize = "" + fontSize + "pt"
|
|
436
|
+
this._textElementView.style.fontSize = "" + fontSize + "pt"
|
|
356
437
|
|
|
357
438
|
this._intrinsicHeightCache = new UIObject() as any
|
|
358
439
|
this._intrinsicWidthCache = new UIObject() as any
|
|
@@ -381,10 +462,10 @@ export class UITextView extends UIView {
|
|
|
381
462
|
private _getFontCacheKey(): string {
|
|
382
463
|
// Check if font-related properties have changed
|
|
383
464
|
const currentTriggers = {
|
|
384
|
-
fontSize: this.style.fontSize || "",
|
|
385
|
-
fontFamily: this.style.fontFamily || "",
|
|
386
|
-
fontWeight: this.style.fontWeight || "",
|
|
387
|
-
fontStyle: this.style.fontStyle || "",
|
|
465
|
+
fontSize: this._textElementView.style.fontSize || "",
|
|
466
|
+
fontFamily: this._textElementView.style.fontFamily || "",
|
|
467
|
+
fontWeight: this._textElementView.style.fontWeight || "",
|
|
468
|
+
fontStyle: this._textElementView.style.fontStyle || "",
|
|
388
469
|
styleClasses: this.styleClasses.join(",")
|
|
389
470
|
}
|
|
390
471
|
|
|
@@ -397,7 +478,7 @@ export class UITextView extends UIView {
|
|
|
397
478
|
|
|
398
479
|
if (!this._cachedFontKey || hasChanged) {
|
|
399
480
|
// Only access computedStyle when we know something changed
|
|
400
|
-
const computed = this.computedStyle
|
|
481
|
+
const computed = this._textElementView.computedStyle
|
|
401
482
|
this._cachedFontKey = [
|
|
402
483
|
computed.fontStyle,
|
|
403
484
|
computed.fontVariant,
|
|
@@ -495,11 +576,11 @@ export class UITextView extends UIView {
|
|
|
495
576
|
// Cache for the computed font string
|
|
496
577
|
private _cachedFontKey?: string
|
|
497
578
|
private _fontInvalidationTriggers = {
|
|
498
|
-
fontSize:
|
|
499
|
-
fontFamily:
|
|
500
|
-
fontWeight:
|
|
501
|
-
fontStyle:
|
|
502
|
-
styleClasses:
|
|
579
|
+
fontSize: "",
|
|
580
|
+
fontFamily: "",
|
|
581
|
+
fontWeight: "",
|
|
582
|
+
fontStyle: "",
|
|
583
|
+
styleClasses: ""
|
|
503
584
|
}
|
|
504
585
|
|
|
505
586
|
//#endregion
|
|
@@ -519,11 +600,31 @@ export class UITextView extends UIView {
|
|
|
519
600
|
|
|
520
601
|
//#endregion
|
|
521
602
|
|
|
603
|
+
// Override addStyleClass to invalidate font cache
|
|
604
|
+
override addStyleClass(styleClass: string) {
|
|
605
|
+
super.addStyleClass(styleClass)
|
|
606
|
+
this._invalidateFontCache()
|
|
607
|
+
}
|
|
522
608
|
|
|
609
|
+
// Override removeStyleClass to invalidate font cache
|
|
610
|
+
override removeStyleClass(styleClass: string) {
|
|
611
|
+
super.removeStyleClass(styleClass)
|
|
612
|
+
this._invalidateFontCache()
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// Override focus to focus the text element
|
|
616
|
+
override focus() {
|
|
617
|
+
this._textElementView.focus()
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
// Override blur to blur the text element
|
|
621
|
+
override blur() {
|
|
622
|
+
this._textElementView.blur()
|
|
623
|
+
}
|
|
523
624
|
|
|
524
625
|
override intrinsicContentHeight(constrainingWidth = 0) {
|
|
525
626
|
|
|
526
|
-
const keyPath = ((this.viewHTMLElement.innerHTML || this.text) + "_csf_" + this._getFontCacheKey()) + "." +
|
|
627
|
+
const keyPath = ((this.textElementView.viewHTMLElement.innerHTML || this.text) + "_csf_" + this._getFontCacheKey()) + "." +
|
|
527
628
|
("" + constrainingWidth).replace(new RegExp("\\.", "g"), "_")
|
|
528
629
|
|
|
529
630
|
let cacheObject = UITextView._intrinsicHeightCache
|
|
@@ -545,18 +646,20 @@ export class UITextView extends UIView {
|
|
|
545
646
|
// If styles are invalid (element not properly initialized), fall back to DOM
|
|
546
647
|
if (styles) {
|
|
547
648
|
const size = UITextMeasurement.calculateTextSize(
|
|
548
|
-
this.viewHTMLElement,
|
|
549
|
-
this.text || this.innerHTML,
|
|
649
|
+
this.textElementView.viewHTMLElement,
|
|
650
|
+
this.text || this.textElementView.innerHTML,
|
|
550
651
|
constrainingWidth || undefined,
|
|
551
652
|
undefined,
|
|
552
653
|
styles
|
|
553
654
|
)
|
|
554
655
|
result = size.height
|
|
555
|
-
}
|
|
656
|
+
}
|
|
657
|
+
else {
|
|
556
658
|
// Styles not ready, use DOM measurement
|
|
557
659
|
result = super.intrinsicContentHeight(constrainingWidth)
|
|
558
660
|
}
|
|
559
|
-
}
|
|
661
|
+
}
|
|
662
|
+
else {
|
|
560
663
|
// Fallback: DOM-based measurement for complex content
|
|
561
664
|
result = super.intrinsicContentHeight(constrainingWidth)
|
|
562
665
|
}
|
|
@@ -574,7 +677,7 @@ export class UITextView extends UIView {
|
|
|
574
677
|
|
|
575
678
|
override intrinsicContentWidth(constrainingHeight = 0) {
|
|
576
679
|
|
|
577
|
-
const keyPath = ((this.viewHTMLElement.innerHTML || this.text) + "_csf_" + this._getFontCacheKey()) + "." +
|
|
680
|
+
const keyPath = ((this.textElementView.viewHTMLElement.innerHTML || this.text) + "_csf_" + this._getFontCacheKey()) + "." +
|
|
578
681
|
("" + constrainingHeight).replace(new RegExp("\\.", "g"), "_")
|
|
579
682
|
|
|
580
683
|
let cacheObject = UITextView._intrinsicWidthCache
|
|
@@ -596,18 +699,20 @@ export class UITextView extends UIView {
|
|
|
596
699
|
// If styles are invalid (element not properly initialized), fall back to DOM
|
|
597
700
|
if (styles) {
|
|
598
701
|
const size = UITextMeasurement.calculateTextSize(
|
|
599
|
-
this.viewHTMLElement,
|
|
600
|
-
this.text || this.innerHTML,
|
|
702
|
+
this.textElementView.viewHTMLElement,
|
|
703
|
+
this.text || this.textElementView.innerHTML,
|
|
601
704
|
undefined,
|
|
602
705
|
constrainingHeight || undefined,
|
|
603
706
|
styles
|
|
604
707
|
)
|
|
605
708
|
result = size.width
|
|
606
|
-
}
|
|
709
|
+
}
|
|
710
|
+
else {
|
|
607
711
|
// Styles not ready, use DOM measurement
|
|
608
712
|
result = super.intrinsicContentWidth(constrainingHeight)
|
|
609
713
|
}
|
|
610
|
-
}
|
|
714
|
+
}
|
|
715
|
+
else {
|
|
611
716
|
// Fallback: DOM-based measurement for complex content
|
|
612
717
|
result = super.intrinsicContentWidth(constrainingHeight)
|
|
613
718
|
}
|
|
@@ -619,16 +724,83 @@ export class UITextView extends UIView {
|
|
|
619
724
|
}
|
|
620
725
|
|
|
621
726
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
this.
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
727
|
+
override intrinsicContentSizeWithConstraints(constrainingHeight: number = 0, constrainingWidth: number = 0) {
|
|
728
|
+
|
|
729
|
+
const cacheKey = this._getIntrinsicSizeCacheKey(constrainingHeight, constrainingWidth)
|
|
730
|
+
const cachedResult = this._getCachedIntrinsicSize(cacheKey)
|
|
731
|
+
if (cachedResult) {
|
|
732
|
+
return cachedResult
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
// UITextView needs to measure the text element, not the outer container
|
|
736
|
+
const result = new UIRectangle(0, 0, 0, 0)
|
|
737
|
+
if (this.rootView.forceIntrinsicSizeZero) {
|
|
738
|
+
return result
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
let temporarilyInViewTree = NO
|
|
742
|
+
let nodeAboveThisView: Node | null = null
|
|
743
|
+
if (!this.isMemberOfViewTree) {
|
|
744
|
+
document.body.appendChild(this.viewHTMLElement)
|
|
745
|
+
temporarilyInViewTree = YES
|
|
746
|
+
nodeAboveThisView = this.viewHTMLElement.nextSibling
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
// Save and clear styles on the TEXT ELEMENT (not the container)
|
|
750
|
+
const height = this._textElementView.style.height
|
|
751
|
+
const width = this._textElementView.style.width
|
|
752
|
+
|
|
753
|
+
this._textElementView.style.height = "" + constrainingHeight
|
|
754
|
+
this._textElementView.style.width = "" + constrainingWidth
|
|
755
|
+
|
|
756
|
+
const left = this._textElementView.style.left
|
|
757
|
+
const right = this._textElementView.style.right
|
|
758
|
+
const bottom = this._textElementView.style.bottom
|
|
759
|
+
const top = this._textElementView.style.top
|
|
760
|
+
|
|
761
|
+
this._textElementView.style.left = ""
|
|
762
|
+
this._textElementView.style.right = ""
|
|
763
|
+
this._textElementView.style.bottom = ""
|
|
764
|
+
this._textElementView.style.top = ""
|
|
765
|
+
|
|
766
|
+
// Measure height with the text element
|
|
767
|
+
const resultHeight = this._textElementView.viewHTMLElement.scrollHeight
|
|
768
|
+
|
|
769
|
+
// Measure width by temporarily setting nowrap
|
|
770
|
+
const whiteSpace = this._textElementView.style.whiteSpace
|
|
771
|
+
this._textElementView.style.whiteSpace = "nowrap"
|
|
772
|
+
|
|
773
|
+
const resultWidth = this._textElementView.viewHTMLElement.scrollWidth
|
|
774
|
+
|
|
775
|
+
this._textElementView.style.whiteSpace = whiteSpace
|
|
776
|
+
|
|
777
|
+
// Restore styles on the TEXT ELEMENT
|
|
778
|
+
this._textElementView.style.height = height
|
|
779
|
+
this._textElementView.style.width = width
|
|
780
|
+
|
|
781
|
+
this._textElementView.style.left = left
|
|
782
|
+
this._textElementView.style.right = right
|
|
783
|
+
this._textElementView.style.bottom = bottom
|
|
784
|
+
this._textElementView.style.top = top
|
|
785
|
+
|
|
786
|
+
if (temporarilyInViewTree) {
|
|
787
|
+
document.body.removeChild(this.viewHTMLElement)
|
|
788
|
+
if (this.superview) {
|
|
789
|
+
if (nodeAboveThisView) {
|
|
790
|
+
this.superview.viewHTMLElement.insertBefore(this.viewHTMLElement, nodeAboveThisView)
|
|
791
|
+
}
|
|
792
|
+
else {
|
|
793
|
+
this.superview.viewHTMLElement.appendChild(this.viewHTMLElement)
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
}
|
|
797
|
+
|
|
798
|
+
result.height = resultHeight
|
|
799
|
+
result.width = resultWidth
|
|
800
|
+
|
|
801
|
+
this._setCachedIntrinsicSize(cacheKey, result)
|
|
802
|
+
|
|
803
|
+
return result
|
|
632
804
|
}
|
|
633
805
|
|
|
634
806
|
|
package/scripts/UIView.ts
CHANGED
|
@@ -16,7 +16,7 @@ import {
|
|
|
16
16
|
IS_NOT_LIKE_NULL,
|
|
17
17
|
nil,
|
|
18
18
|
NO,
|
|
19
|
-
RETURNER,
|
|
19
|
+
RETURNER, UIInitializerObject,
|
|
20
20
|
UIObject,
|
|
21
21
|
YES
|
|
22
22
|
} from "./UIObject"
|
|
@@ -330,11 +330,13 @@ export class UIView extends UIObject {
|
|
|
330
330
|
elementID: string = ("UIView" + UIView.nextIndex),
|
|
331
331
|
viewHTMLElement: HTMLElement & LooseObject | null = null,
|
|
332
332
|
elementType: string | null = null,
|
|
333
|
-
|
|
333
|
+
preInitConfiguratorObject?: any
|
|
334
334
|
) {
|
|
335
335
|
|
|
336
336
|
super()
|
|
337
337
|
|
|
338
|
+
this.configureWithObject(preInitConfiguratorObject)
|
|
339
|
+
|
|
338
340
|
// Instance variables
|
|
339
341
|
|
|
340
342
|
UIView._UIViewIndex = UIView.nextIndex
|
|
@@ -522,7 +524,8 @@ export class UIView extends UIObject {
|
|
|
522
524
|
_initViewHTMLElement(
|
|
523
525
|
elementID: string,
|
|
524
526
|
viewHTMLElement: (HTMLElement & LooseObject) | null,
|
|
525
|
-
elementType?: string | null
|
|
527
|
+
elementType?: string | null,
|
|
528
|
+
|
|
526
529
|
) {
|
|
527
530
|
|
|
528
531
|
if (!IS(elementType)) {
|
|
@@ -3670,15 +3673,15 @@ export class UIView extends UIObject {
|
|
|
3670
3673
|
)
|
|
3671
3674
|
}
|
|
3672
3675
|
|
|
3673
|
-
|
|
3676
|
+
protected _getIntrinsicSizeCacheKey(constrainingHeight: number, constrainingWidth: number): string {
|
|
3674
3677
|
return `h_${constrainingHeight}__w_${constrainingWidth}`
|
|
3675
3678
|
}
|
|
3676
3679
|
|
|
3677
|
-
|
|
3680
|
+
protected _getCachedIntrinsicSize(cacheKey: string): UIRectangle | undefined {
|
|
3678
3681
|
return this._intrinsicSizesCache[cacheKey]
|
|
3679
3682
|
}
|
|
3680
3683
|
|
|
3681
|
-
|
|
3684
|
+
protected _setCachedIntrinsicSize(cacheKey: string, size: UIRectangle): void {
|
|
3682
3685
|
this._intrinsicSizesCache[cacheKey] = size.copy()
|
|
3683
3686
|
}
|
|
3684
3687
|
|