uicore-ts 1.0.1

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.
Files changed (128) hide show
  1. package/.idea/misc.xml +6 -0
  2. package/.idea/modules.xml +8 -0
  3. package/.idea/uicore.iml +9 -0
  4. package/.idea/vcs.xml +6 -0
  5. package/LICENSE +21 -0
  6. package/README.md +5 -0
  7. package/compiledScripts/UIActionIndicator.d.ts +12 -0
  8. package/compiledScripts/UIActionIndicator.js +54 -0
  9. package/compiledScripts/UIActionIndicator.js.map +1 -0
  10. package/compiledScripts/UIBaseButton.d.ts +52 -0
  11. package/compiledScripts/UIBaseButton.js +268 -0
  12. package/compiledScripts/UIBaseButton.js.map +1 -0
  13. package/compiledScripts/UIButton.d.ts +54 -0
  14. package/compiledScripts/UIButton.js +247 -0
  15. package/compiledScripts/UIButton.js.map +1 -0
  16. package/compiledScripts/UIColor.d.ts +41 -0
  17. package/compiledScripts/UIColor.js +286 -0
  18. package/compiledScripts/UIColor.js.map +1 -0
  19. package/compiledScripts/UICore.d.ts +27 -0
  20. package/compiledScripts/UICore.js +105 -0
  21. package/compiledScripts/UICore.js.map +1 -0
  22. package/compiledScripts/UICoreExtensions.d.ts +60 -0
  23. package/compiledScripts/UICoreExtensions.js +527 -0
  24. package/compiledScripts/UICoreExtensions.js.map +1 -0
  25. package/compiledScripts/UIDateTimeInput.d.ts +40 -0
  26. package/compiledScripts/UIDateTimeInput.js +38 -0
  27. package/compiledScripts/UIDateTimeInput.js.map +1 -0
  28. package/compiledScripts/UIDialogView.d.ts +23 -0
  29. package/compiledScripts/UIDialogView.js +118 -0
  30. package/compiledScripts/UIDialogView.js.map +1 -0
  31. package/compiledScripts/UIImageView.d.ts +36 -0
  32. package/compiledScripts/UIImageView.js +170 -0
  33. package/compiledScripts/UIImageView.js.map +1 -0
  34. package/compiledScripts/UIKeyValueStringFilter.d.ts +21 -0
  35. package/compiledScripts/UIKeyValueStringFilter.js +98 -0
  36. package/compiledScripts/UIKeyValueStringFilter.js.map +1 -0
  37. package/compiledScripts/UIKeyValueStringSorter.d.ts +38 -0
  38. package/compiledScripts/UIKeyValueStringSorter.js +117 -0
  39. package/compiledScripts/UIKeyValueStringSorter.js.map +1 -0
  40. package/compiledScripts/UILayoutGrid.d.ts +8 -0
  41. package/compiledScripts/UILayoutGrid.js +22 -0
  42. package/compiledScripts/UILayoutGrid.js.map +1 -0
  43. package/compiledScripts/UILink.d.ts +25 -0
  44. package/compiledScripts/UILink.js +81 -0
  45. package/compiledScripts/UILink.js.map +1 -0
  46. package/compiledScripts/UILinkButton.d.ts +18 -0
  47. package/compiledScripts/UILinkButton.js +60 -0
  48. package/compiledScripts/UILinkButton.js.map +1 -0
  49. package/compiledScripts/UINativeScrollView.d.ts +20 -0
  50. package/compiledScripts/UINativeScrollView.js +121 -0
  51. package/compiledScripts/UINativeScrollView.js.map +1 -0
  52. package/compiledScripts/UIObject.d.ts +69 -0
  53. package/compiledScripts/UIObject.js +442 -0
  54. package/compiledScripts/UIObject.js.map +1 -0
  55. package/compiledScripts/UIPoint.d.ts +18 -0
  56. package/compiledScripts/UIPoint.js +68 -0
  57. package/compiledScripts/UIPoint.js.map +1 -0
  58. package/compiledScripts/UIRectangle.d.ts +61 -0
  59. package/compiledScripts/UIRectangle.js +421 -0
  60. package/compiledScripts/UIRectangle.js.map +1 -0
  61. package/compiledScripts/UIRoute.d.ts +39 -0
  62. package/compiledScripts/UIRoute.js +202 -0
  63. package/compiledScripts/UIRoute.js.map +1 -0
  64. package/compiledScripts/UIScrollView.d.ts +19 -0
  65. package/compiledScripts/UIScrollView.js +121 -0
  66. package/compiledScripts/UIScrollView.js.map +1 -0
  67. package/compiledScripts/UISlideScrollerView.d.ts +40 -0
  68. package/compiledScripts/UISlideScrollerView.js +242 -0
  69. package/compiledScripts/UISlideScrollerView.js.map +1 -0
  70. package/compiledScripts/UIStringFilter.d.ts +26 -0
  71. package/compiledScripts/UIStringFilter.js +107 -0
  72. package/compiledScripts/UIStringFilter.js.map +1 -0
  73. package/compiledScripts/UITableView.d.ts +61 -0
  74. package/compiledScripts/UITableView.js +383 -0
  75. package/compiledScripts/UITableView.js.map +1 -0
  76. package/compiledScripts/UITextArea.d.ts +7 -0
  77. package/compiledScripts/UITextArea.js +27 -0
  78. package/compiledScripts/UITextArea.js.map +1 -0
  79. package/compiledScripts/UITextField.d.ts +44 -0
  80. package/compiledScripts/UITextField.js +83 -0
  81. package/compiledScripts/UITextField.js.map +1 -0
  82. package/compiledScripts/UITextView.d.ts +89 -0
  83. package/compiledScripts/UITextView.js +237 -0
  84. package/compiledScripts/UITextView.js.map +1 -0
  85. package/compiledScripts/UITimer.d.ts +13 -0
  86. package/compiledScripts/UITimer.js +45 -0
  87. package/compiledScripts/UITimer.js.map +1 -0
  88. package/compiledScripts/UIView.d.ts +330 -0
  89. package/compiledScripts/UIView.js +1533 -0
  90. package/compiledScripts/UIView.js.map +1 -0
  91. package/compiledScripts/UIViewController.d.ts +38 -0
  92. package/compiledScripts/UIViewController.js +153 -0
  93. package/compiledScripts/UIViewController.js.map +1 -0
  94. package/compiledScripts/index.d.ts +29 -0
  95. package/compiledScripts/index.js +46 -0
  96. package/compiledScripts/index.js.map +1 -0
  97. package/package.json +36 -0
  98. package/scripts/UIActionIndicator.ts +139 -0
  99. package/scripts/UIBaseButton.ts +563 -0
  100. package/scripts/UIButton.ts +552 -0
  101. package/scripts/UIColor.ts +427 -0
  102. package/scripts/UICore.ts +223 -0
  103. package/scripts/UICoreExtensions.ts +949 -0
  104. package/scripts/UIDateTimeInput.ts +109 -0
  105. package/scripts/UIDialogView.ts +297 -0
  106. package/scripts/UIImageView.ts +366 -0
  107. package/scripts/UIKeyValueStringFilter.ts +260 -0
  108. package/scripts/UIKeyValueStringSorter.ts +337 -0
  109. package/scripts/UILayoutGrid.ts +83 -0
  110. package/scripts/UILink.ts +292 -0
  111. package/scripts/UILinkButton.ts +238 -0
  112. package/scripts/UINativeScrollView.ts +254 -0
  113. package/scripts/UIObject.ts +827 -0
  114. package/scripts/UIPoint.ts +123 -0
  115. package/scripts/UIRectangle.ts +730 -0
  116. package/scripts/UIRoute.ts +391 -0
  117. package/scripts/UIScrollView.ts +290 -0
  118. package/scripts/UISlideScrollerView.ts +530 -0
  119. package/scripts/UIStringFilter.ts +293 -0
  120. package/scripts/UITableView.ts +790 -0
  121. package/scripts/UITextArea.ts +91 -0
  122. package/scripts/UITextField.ts +218 -0
  123. package/scripts/UITextView.ts +561 -0
  124. package/scripts/UITimer.ts +107 -0
  125. package/scripts/UIView.ts +2789 -0
  126. package/scripts/UIViewController.ts +304 -0
  127. package/scripts/index.ts +36 -0
  128. package/tsconfig.json +59 -0
@@ -0,0 +1,561 @@
1
+ import { UIColor } from "./UIColor"
2
+ import { UILocalizedTextObject } from "./UICore"
3
+ import { FIRST, IS_LIKE_NULL, nil, NO, UIObject, YES } from "./UIObject"
4
+ import { UIRectangle } from "./UIRectangle"
5
+ import { UIView, UIViewBroadcastEvent } from "./UIView"
6
+
7
+
8
+
9
+
10
+
11
+ export class UITextView extends UIView {
12
+
13
+
14
+ _textColor: UIColor = UITextView.defaultTextColor
15
+ _textAlignment: string
16
+
17
+ _isSingleLine = YES
18
+
19
+ textPrefix = ""
20
+ textSuffix = ""
21
+
22
+ _notificationAmount = 0
23
+
24
+ _minFontSize: number = nil
25
+ _maxFontSize: number = nil
26
+
27
+ _automaticFontSizeSelection = NO
28
+
29
+ changesOften = NO
30
+
31
+ static defaultTextColor = UIColor.blackColor
32
+ static notificationTextColor = UIColor.redColor
33
+
34
+ static _intrinsicHeightCache: { [x: string]: { [x: string]: number; }; } & UIObject = new UIObject() as any
35
+ static _intrinsicWidthCache: { [x: string]: { [x: string]: number; }; } & UIObject = new UIObject() as any
36
+
37
+ _intrinsicHeightCache: { [x: string]: { [x: string]: number; }; } & UIObject = new UIObject() as any
38
+ _intrinsicWidthCache: { [x: string]: { [x: string]: number; }; } & UIObject = new UIObject() as any
39
+
40
+
41
+ static _ptToPx: number
42
+ static _pxToPt: number
43
+ _text: string
44
+
45
+
46
+ constructor(elementID?: string, textViewType = UITextView.type.paragraph, viewHTMLElement = null) {
47
+
48
+ super(elementID, viewHTMLElement, textViewType)
49
+
50
+ this._class = UITextView
51
+ this.superclass = UIView
52
+
53
+ this.text = ""
54
+
55
+ this.style.overflow = "hidden"
56
+ this.style.textOverflow = "ellipsis"
57
+ this.isSingleLine = YES
58
+
59
+ this.textColor = this.textColor
60
+
61
+ this.userInteractionEnabled = YES
62
+
63
+
64
+ if (textViewType == UITextView.type.textArea) {
65
+
66
+ this.pausesPointerEvents = YES
67
+
68
+ this.addTargetForControlEvent(UIView.controlEvent.PointerUpInside, function (sender, event) {
69
+
70
+ sender.focus()
71
+
72
+ })
73
+
74
+
75
+ }
76
+
77
+
78
+ }
79
+
80
+
81
+
82
+
83
+
84
+ static _determinePXAndPTRatios() {
85
+
86
+ const o = document.createElement("div")
87
+ o.style.width = "1000pt"
88
+ document.body.appendChild(o)
89
+ UITextView._ptToPx = o.clientWidth / 1000
90
+ document.body.removeChild(o)
91
+ UITextView._pxToPt = 1 / UITextView._ptToPx
92
+
93
+ }
94
+
95
+
96
+
97
+
98
+
99
+ static type = {
100
+
101
+ "paragraph": "p",
102
+ "header1": "h1",
103
+ "header2": "h2",
104
+ "header3": "h3",
105
+ "header4": "h4",
106
+ "header5": "h5",
107
+ "header6": "h6",
108
+ "textArea": "textarea",
109
+ "textField": "input",
110
+ "span": "span",
111
+ "label": "label"
112
+
113
+ }
114
+
115
+
116
+
117
+ static textAlignment = {
118
+
119
+ "left": "left",
120
+ "center": "center",
121
+ "right": "right",
122
+ "justify": "justify"
123
+
124
+ }
125
+
126
+ get textAlignment() {
127
+ const result = this.style.textAlign
128
+ return result
129
+ }
130
+
131
+ set textAlignment(textAlignment: string) {
132
+ this._textAlignment = textAlignment
133
+ this.style.textAlign = textAlignment
134
+ }
135
+
136
+
137
+
138
+ get textColor() {
139
+ const result = this._textColor
140
+ return result
141
+ }
142
+
143
+ set textColor(color: UIColor) {
144
+
145
+ this._textColor = color || UITextView.defaultTextColor
146
+ this.style.color = this._textColor.stringValue
147
+
148
+ }
149
+
150
+
151
+ get isSingleLine() {
152
+
153
+ return this._isSingleLine
154
+
155
+ }
156
+
157
+ set isSingleLine(isSingleLine: boolean) {
158
+
159
+ this._isSingleLine = isSingleLine
160
+
161
+ this._intrinsicHeightCache = new UIObject() as any
162
+ this._intrinsicWidthCache = new UIObject() as any
163
+
164
+ if (isSingleLine) {
165
+
166
+ this.style.whiteSpace = "pre"
167
+
168
+ return
169
+
170
+ }
171
+
172
+ this.style.whiteSpace = "pre-wrap"
173
+
174
+ }
175
+
176
+
177
+ get notificationAmount() {
178
+
179
+ return this._notificationAmount
180
+
181
+ }
182
+
183
+ set notificationAmount(notificationAmount: number) {
184
+
185
+ if (this._notificationAmount == notificationAmount) {
186
+
187
+ return
188
+
189
+ }
190
+
191
+ this._notificationAmount = notificationAmount
192
+
193
+ this.text = this.text
194
+
195
+ this.setNeedsLayoutUpToRootView()
196
+
197
+ this.notificationAmountDidChange(notificationAmount)
198
+
199
+ }
200
+
201
+ notificationAmountDidChange(notificationAmount: number) {
202
+
203
+
204
+
205
+
206
+
207
+ }
208
+
209
+
210
+
211
+
212
+
213
+ get text() {
214
+
215
+ return (this._text || this.viewHTMLElement.innerHTML)
216
+
217
+ }
218
+
219
+ set text(text) {
220
+
221
+ this._text = text
222
+
223
+ var notificationText = ""
224
+
225
+ if (this.notificationAmount) {
226
+
227
+ notificationText = "<span style=\"color: " + UITextView.notificationTextColor.stringValue + ";\">" +
228
+ (" (" + this.notificationAmount + ")").bold() + "</span>"
229
+
230
+ }
231
+
232
+ if (this.viewHTMLElement.innerHTML != this.textPrefix + text + this.textSuffix + notificationText) {
233
+
234
+ this.viewHTMLElement.innerHTML = this.textPrefix + FIRST(text, "") + this.textSuffix + notificationText
235
+
236
+ }
237
+
238
+ this._intrinsicHeightCache = new UIObject() as any
239
+ this._intrinsicWidthCache = new UIObject() as any
240
+
241
+ this.setNeedsLayout()
242
+
243
+ }
244
+
245
+ set innerHTML(innerHTML: string) {
246
+
247
+ this.text = innerHTML
248
+
249
+ }
250
+
251
+ get innerHTML() {
252
+
253
+ return this.viewHTMLElement.innerHTML
254
+
255
+ }
256
+
257
+
258
+
259
+ setText(key: string, defaultString: string, parameters?: { [x: string]: string | UILocalizedTextObject }) {
260
+
261
+ this.setInnerHTML(key, defaultString, parameters)
262
+
263
+ }
264
+
265
+
266
+ get fontSize() {
267
+
268
+ const style = window.getComputedStyle(this.viewHTMLElement, null).fontSize
269
+
270
+ const result = (parseFloat(style) * UITextView._pxToPt)
271
+
272
+ return result
273
+
274
+ }
275
+
276
+ set fontSize(fontSize: number) {
277
+
278
+
279
+ this.style.fontSize = "" + fontSize + "pt"
280
+
281
+ this._intrinsicHeightCache = new UIObject() as any
282
+ this._intrinsicWidthCache = new UIObject() as any // MEETOD LUUA!!!!
283
+
284
+
285
+ }
286
+
287
+
288
+
289
+
290
+
291
+ useAutomaticFontSize(minFontSize: number = nil, maxFontSize: number = nil) {
292
+
293
+
294
+ this._automaticFontSizeSelection = YES
295
+
296
+
297
+ this._minFontSize = minFontSize
298
+
299
+ this._maxFontSize = maxFontSize
300
+
301
+ this.setNeedsLayout()
302
+
303
+
304
+ }
305
+
306
+
307
+
308
+
309
+
310
+ static automaticallyCalculatedFontSize(
311
+ bounds: UIRectangle,
312
+ currentSize: UIRectangle,
313
+ currentFontSize: number,
314
+ minFontSize?: number,
315
+ maxFontSize?: number
316
+ ) {
317
+
318
+ minFontSize = FIRST(minFontSize, 1)
319
+
320
+ maxFontSize = FIRST(maxFontSize, 100000000000)
321
+
322
+
323
+ const heightMultiplier = bounds.height / (currentSize.height + 1)
324
+
325
+ const widthMultiplier = bounds.width / (currentSize.width + 1)
326
+
327
+
328
+
329
+
330
+ var multiplier = heightMultiplier
331
+
332
+ if (heightMultiplier > widthMultiplier) {
333
+
334
+ multiplier = widthMultiplier
335
+
336
+
337
+
338
+ }
339
+
340
+
341
+
342
+
343
+ const maxFittingFontSize = currentFontSize * multiplier
344
+
345
+
346
+ if (maxFittingFontSize > maxFontSize) {
347
+
348
+ return maxFontSize
349
+
350
+ }
351
+
352
+ if (minFontSize > maxFittingFontSize) {
353
+
354
+ return minFontSize
355
+
356
+ }
357
+
358
+
359
+ return maxFittingFontSize
360
+
361
+
362
+
363
+ }
364
+
365
+
366
+
367
+
368
+
369
+ didReceiveBroadcastEvent(event: UIViewBroadcastEvent) {
370
+
371
+ super.didReceiveBroadcastEvent(event)
372
+
373
+ }
374
+
375
+
376
+ willMoveToSuperview(superview: UIView) {
377
+
378
+ super.willMoveToSuperview(superview)
379
+
380
+ }
381
+
382
+
383
+
384
+
385
+
386
+ layoutSubviews() {
387
+
388
+ super.layoutSubviews()
389
+
390
+
391
+ if (this._automaticFontSizeSelection) {
392
+
393
+ this.fontSize = UITextView.automaticallyCalculatedFontSize(
394
+ new UIRectangle(0, 0, 1 *
395
+ this.viewHTMLElement.offsetHeight, 1 *
396
+ this.viewHTMLElement.offsetWidth),
397
+ this.intrinsicContentSize(),
398
+ this.fontSize,
399
+ this._minFontSize,
400
+ this._maxFontSize
401
+ )
402
+
403
+
404
+
405
+
406
+ }
407
+
408
+
409
+
410
+
411
+
412
+ }
413
+
414
+
415
+
416
+ intrinsicContentHeight(constrainingWidth = 0) {
417
+
418
+ const keyPath = (this.viewHTMLElement.innerHTML + "_csf_" + this.computedStyle.font).replace(new RegExp(
419
+ "\\.",
420
+ "g"
421
+ ), "_") + "." +
422
+ ("" + constrainingWidth).replace(new RegExp("\\.", "g"), "_")
423
+
424
+ let cacheObject = UITextView._intrinsicHeightCache
425
+
426
+ if (this.changesOften) {
427
+
428
+ cacheObject = this._intrinsicHeightCache
429
+
430
+
431
+ }
432
+
433
+
434
+ var result = cacheObject.valueForKeyPath(keyPath)
435
+
436
+
437
+ if (IS_LIKE_NULL(result)) {
438
+
439
+ result = super.intrinsicContentHeight(constrainingWidth)
440
+
441
+ cacheObject.setValueForKeyPath(keyPath, result)
442
+
443
+
444
+ }
445
+
446
+
447
+ return result
448
+
449
+ }
450
+
451
+ intrinsicContentWidth(constrainingHeight = 0) {
452
+
453
+ const keyPath = (this.viewHTMLElement.innerHTML + "_csf_" + this.computedStyle.font).replace(new RegExp(
454
+ "\\.",
455
+ "g"
456
+ ), "_") + "." +
457
+ ("" + constrainingHeight).replace(new RegExp("\\.", "g"), "_")
458
+
459
+ let cacheObject = UITextView._intrinsicWidthCache
460
+
461
+ if (this.changesOften) {
462
+
463
+ cacheObject = this._intrinsicWidthCache
464
+
465
+
466
+ }
467
+
468
+
469
+ var result = cacheObject.valueForKeyPath(keyPath)
470
+
471
+
472
+ if (IS_LIKE_NULL(result)) {
473
+
474
+ result = super.intrinsicContentWidth(constrainingHeight)
475
+
476
+ cacheObject.setValueForKeyPath(keyPath, result)
477
+
478
+
479
+ }
480
+
481
+
482
+ return result
483
+
484
+ }
485
+
486
+
487
+
488
+
489
+ intrinsicContentSize() {
490
+
491
+ // This works but is slow
492
+ const result = this.intrinsicContentSizeWithConstraints(nil, nil)
493
+
494
+ return result
495
+
496
+ }
497
+
498
+
499
+
500
+
501
+
502
+ }
503
+
504
+
505
+
506
+
507
+
508
+ UITextView._determinePXAndPTRatios()
509
+
510
+
511
+
512
+
513
+
514
+ // /**
515
+ // * Uses canvas.measureText to compute and return the width of the given text of given font in pixels.
516
+ // *
517
+ // * @param {String} text The text to be rendered.
518
+ // * @param {String} font The css font descriptor that text is to be rendered with (e.g. "bold 14px verdana").
519
+ // *
520
+ // * @see https://stackoverflow.com/questions/118241/calculate-text-width-with-javascript/21015393#21015393
521
+ // */
522
+ // function getTextMetrics(text, font) {
523
+ // // re-use canvas object for better performance
524
+ // var canvas = getTextMetrics.canvas || (getTextMetrics.canvas = document.createElement("canvas"));
525
+ // var context = canvas.getContext("2d");
526
+ // context.font = font;
527
+ // var metrics = context.measureText(text);
528
+ // return metrics;
529
+ // }
530
+
531
+
532
+
533
+
534
+
535
+
536
+
537
+
538
+
539
+
540
+
541
+
542
+
543
+
544
+
545
+
546
+
547
+
548
+
549
+
550
+
551
+
552
+
553
+
554
+
555
+
556
+
557
+
558
+
559
+
560
+
561
+
@@ -0,0 +1,107 @@
1
+ import { NO, UIObject, YES } from "./UIObject"
2
+
3
+
4
+ export class UITimer extends UIObject {
5
+
6
+
7
+
8
+
9
+
10
+ _intervalID: number
11
+
12
+ isValid: boolean = YES
13
+
14
+
15
+ constructor(public interval: number, public repeats: boolean, public target: Function) {
16
+
17
+ super()
18
+
19
+ this.superclass = UIObject
20
+
21
+
22
+ this.schedule()
23
+
24
+
25
+
26
+ }
27
+
28
+
29
+
30
+ schedule() {
31
+
32
+ const callback = function () {
33
+ if (this.repeats == NO) {
34
+ this.invalidate()
35
+ }
36
+ this.target()
37
+ }.bind(this)
38
+
39
+ this._intervalID = window.setInterval(callback, this.interval * 1000)
40
+
41
+ }
42
+
43
+
44
+ reschedule() {
45
+
46
+ this.invalidate()
47
+ this.schedule()
48
+
49
+ }
50
+
51
+
52
+
53
+ fire() {
54
+ if (this.repeats == NO) {
55
+ this.invalidate()
56
+ }
57
+ else {
58
+ this.reschedule()
59
+ }
60
+ this.target()
61
+ }
62
+
63
+ invalidate() {
64
+
65
+ if (this.isValid) {
66
+
67
+ clearInterval(this._intervalID)
68
+
69
+ this.isValid = NO
70
+
71
+ }
72
+
73
+
74
+
75
+ }
76
+
77
+
78
+
79
+
80
+
81
+ }
82
+
83
+
84
+
85
+
86
+
87
+
88
+
89
+
90
+
91
+
92
+
93
+
94
+
95
+
96
+
97
+
98
+
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+