uicore-ts 1.1.261 → 1.1.263
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,58 @@
|
|
|
1
|
-
import { UIView, UIViewBroadcastEvent } from "./UIView";
|
|
1
|
+
import { UIView, UIViewAddControlEventTargetObject, UIViewBroadcastEvent } from "./UIView";
|
|
2
2
|
export declare class UIBaseButton extends UIView {
|
|
3
|
+
static controlEvent: {
|
|
4
|
+
readonly PointerDown: "PointerDown";
|
|
5
|
+
readonly PointerMove: "PointerMove";
|
|
6
|
+
readonly PointerDrag: "PointerDrag";
|
|
7
|
+
readonly PointerLeave: "PointerLeave";
|
|
8
|
+
readonly PointerEnter: "PointerEnter";
|
|
9
|
+
readonly PointerUpInside: "PointerUpInside";
|
|
10
|
+
readonly PointerTap: "PointerTap";
|
|
11
|
+
readonly PointerUp: "PointerUp";
|
|
12
|
+
readonly MultipleTouches: "PointerZoom";
|
|
13
|
+
readonly PointerCancel: "PointerCancel";
|
|
14
|
+
readonly PointerHover: "PointerHover";
|
|
15
|
+
readonly EnterDown: "EnterDown";
|
|
16
|
+
readonly EnterUp: "EnterUp";
|
|
17
|
+
readonly SpaceDown: "SpaceDown";
|
|
18
|
+
readonly EscDown: "EscDown";
|
|
19
|
+
readonly TabDown: "TabDown";
|
|
20
|
+
readonly LeftArrowDown: "LeftArrowDown";
|
|
21
|
+
readonly RightArrowDown: "RightArrowDown";
|
|
22
|
+
readonly DownArrowDown: "DownArrowDown";
|
|
23
|
+
readonly UpArrowDown: "UpArrowDown";
|
|
24
|
+
readonly Focus: "Focus";
|
|
25
|
+
readonly Blur: "Blur";
|
|
26
|
+
} & {
|
|
27
|
+
readonly PrimaryActionTriggered: "PrimaryActionTriggered";
|
|
28
|
+
};
|
|
29
|
+
controlEvent: {
|
|
30
|
+
readonly PointerDown: "PointerDown";
|
|
31
|
+
readonly PointerMove: "PointerMove";
|
|
32
|
+
readonly PointerDrag: "PointerDrag";
|
|
33
|
+
readonly PointerLeave: "PointerLeave";
|
|
34
|
+
readonly PointerEnter: "PointerEnter";
|
|
35
|
+
readonly PointerUpInside: "PointerUpInside";
|
|
36
|
+
readonly PointerTap: "PointerTap";
|
|
37
|
+
readonly PointerUp: "PointerUp";
|
|
38
|
+
readonly MultipleTouches: "PointerZoom";
|
|
39
|
+
readonly PointerCancel: "PointerCancel";
|
|
40
|
+
readonly PointerHover: "PointerHover";
|
|
41
|
+
readonly EnterDown: "EnterDown";
|
|
42
|
+
readonly EnterUp: "EnterUp";
|
|
43
|
+
readonly SpaceDown: "SpaceDown";
|
|
44
|
+
readonly EscDown: "EscDown";
|
|
45
|
+
readonly TabDown: "TabDown";
|
|
46
|
+
readonly LeftArrowDown: "LeftArrowDown";
|
|
47
|
+
readonly RightArrowDown: "RightArrowDown";
|
|
48
|
+
readonly DownArrowDown: "DownArrowDown";
|
|
49
|
+
readonly UpArrowDown: "UpArrowDown";
|
|
50
|
+
readonly Focus: "Focus";
|
|
51
|
+
readonly Blur: "Blur";
|
|
52
|
+
} & {
|
|
53
|
+
readonly PrimaryActionTriggered: "PrimaryActionTriggered";
|
|
54
|
+
};
|
|
55
|
+
get controlEventTargetAccumulator(): UIViewAddControlEventTargetObject<typeof UIBaseButton>;
|
|
3
56
|
_selected: boolean;
|
|
4
57
|
_highlighted: boolean;
|
|
5
58
|
_isPointerInside: boolean;
|
|
@@ -24,9 +24,10 @@ module.exports = __toCommonJS(UIBaseButton_exports);
|
|
|
24
24
|
var import_UIColor = require("./UIColor");
|
|
25
25
|
var import_UIObject = require("./UIObject");
|
|
26
26
|
var import_UIView = require("./UIView");
|
|
27
|
-
class
|
|
27
|
+
const _UIBaseButton = class extends import_UIView.UIView {
|
|
28
28
|
constructor(elementID, elementType) {
|
|
29
29
|
super(elementID, void 0, elementType);
|
|
30
|
+
this.controlEvent = _UIBaseButton.controlEvent;
|
|
30
31
|
this._selected = import_UIObject.NO;
|
|
31
32
|
this._highlighted = import_UIObject.NO;
|
|
32
33
|
this._isToggleable = import_UIObject.NO;
|
|
@@ -73,6 +74,13 @@ class UIBaseButton extends import_UIView.UIView {
|
|
|
73
74
|
this.addTargetForControlEvent(import_UIView.UIView.controlEvent.EnterDown, () => {
|
|
74
75
|
setHighlighted();
|
|
75
76
|
setNotHighlightedWithMinimumDuration();
|
|
77
|
+
this.sendControlEventForKey(import_UIView.UIView.controlEvent.PointerUpInside, import_UIObject.nil);
|
|
78
|
+
});
|
|
79
|
+
this.addTargetForControlEvent(import_UIView.UIView.controlEvent.SpaceDown, (sender, event) => {
|
|
80
|
+
event.preventDefault();
|
|
81
|
+
setHighlighted();
|
|
82
|
+
setNotHighlightedWithMinimumDuration();
|
|
83
|
+
this.sendControlEventForKey(import_UIView.UIView.controlEvent.PointerUpInside, import_UIObject.nil);
|
|
76
84
|
});
|
|
77
85
|
this.addTargetForControlEvent(
|
|
78
86
|
import_UIView.UIView.controlEvent.Focus,
|
|
@@ -91,7 +99,7 @@ class UIBaseButton extends import_UIView.UIView {
|
|
|
91
99
|
this.style.cursor = "pointer";
|
|
92
100
|
this.nativeSelectionEnabled = import_UIObject.NO;
|
|
93
101
|
this.addTargetForControlEvents([
|
|
94
|
-
|
|
102
|
+
_UIBaseButton.controlEvent.PrimaryActionTriggered,
|
|
95
103
|
import_UIView.UIView.controlEvent.PointerUpInside
|
|
96
104
|
], () => {
|
|
97
105
|
if (this.isToggleable) {
|
|
@@ -99,6 +107,9 @@ class UIBaseButton extends import_UIView.UIView {
|
|
|
99
107
|
}
|
|
100
108
|
});
|
|
101
109
|
}
|
|
110
|
+
get controlEventTargetAccumulator() {
|
|
111
|
+
return super.controlEventTargetAccumulator;
|
|
112
|
+
}
|
|
102
113
|
set hovered(hovered) {
|
|
103
114
|
this._hovered = hovered;
|
|
104
115
|
this.updateContentForCurrentState();
|
|
@@ -219,6 +230,9 @@ class UIBaseButton extends import_UIView.UIView {
|
|
|
219
230
|
const asd = 1;
|
|
220
231
|
} else {
|
|
221
232
|
super.sendControlEventForKey(eventKey, nativeEvent);
|
|
233
|
+
if (eventKey == import_UIView.UIView.controlEvent.PointerUpInside) {
|
|
234
|
+
super.sendControlEventForKey(_UIBaseButton.controlEvent.PrimaryActionTriggered, nativeEvent);
|
|
235
|
+
}
|
|
222
236
|
}
|
|
223
237
|
}
|
|
224
238
|
static getEventCoordinatesInDocument(touchOrMouseEvent) {
|
|
@@ -268,7 +282,11 @@ class UIBaseButton extends import_UIView.UIView {
|
|
|
268
282
|
);
|
|
269
283
|
return coordinatesInElement;
|
|
270
284
|
}
|
|
271
|
-
}
|
|
285
|
+
};
|
|
286
|
+
let UIBaseButton = _UIBaseButton;
|
|
287
|
+
UIBaseButton.controlEvent = Object.assign({}, import_UIView.UIView.controlEvent, {
|
|
288
|
+
"PrimaryActionTriggered": "PrimaryActionTriggered"
|
|
289
|
+
});
|
|
272
290
|
// Annotate the CommonJS export names for ESM import in node:
|
|
273
291
|
0 && (module.exports = {
|
|
274
292
|
UIBaseButton
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../scripts/UIBaseButton.ts"],
|
|
4
|
-
"sourcesContent": ["import { UIColor } from \"./UIColor\"\nimport { IS, nil, NO, YES } from \"./UIObject\"\nimport { UIView, UIViewBroadcastEvent } from \"./UIView\"\n\n\nexport class UIBaseButton extends UIView {\n \n _selected: boolean = NO\n _highlighted: boolean = NO\n \n override _isPointerInside: boolean\n \n \n _isToggleable: boolean = NO\n _hovered?: boolean\n _focused?: boolean\n \n \n constructor(elementID?: string, elementType?: string) {\n \n super(elementID, undefined, elementType)\n \n // Instance variables\n \n \n this._isPointerInside = NO\n \n \n const setHovered = () => {\n this.hovered = YES\n }\n this.addTargetForControlEvent(UIView.controlEvent.PointerHover, setHovered)\n \n const setNotHovered = () => {\n \n this.hovered = NO\n \n }\n \n this.addTargetForControlEvents([\n UIView.controlEvent.PointerLeave, UIView.controlEvent.PointerCancel, UIView.controlEvent.MultipleTouches\n ], setNotHovered)\n \n \n let highlightingTime: number\n const setHighlighted = () => {\n this.highlighted = YES\n highlightingTime = Date.now()\n }\n this.addTargetForControlEvent(UIView.controlEvent.PointerDown, setHighlighted)\n this.addTargetForControlEvent(UIView.controlEvent.PointerEnter, setHighlighted)\n \n const setNotHighlighted = () => {\n this.highlighted = NO\n }\n const setNotHighlightedWithMinimumDuration = () => {\n const minimumDurationInMilliseconds = 50\n const elapsedTime = Date.now() - highlightingTime\n if (minimumDurationInMilliseconds < elapsedTime) {\n this.highlighted = NO\n }\n else {\n setTimeout(() => {\n this.highlighted = NO\n }, minimumDurationInMilliseconds - elapsedTime)\n }\n }\n this.addTargetForControlEvents([\n UIView.controlEvent.PointerLeave, UIView.controlEvent.PointerCancel, UIView.controlEvent.MultipleTouches\n ], setNotHighlighted)\n this.addTargetForControlEvent(UIView.controlEvent.PointerUp, setNotHighlightedWithMinimumDuration)\n \n // Handle enter key press\n this.addTargetForControlEvent(UIView.controlEvent.EnterDown, () => {\n \n setHighlighted()\n setNotHighlightedWithMinimumDuration()\n \n })\n \n \n this.addTargetForControlEvent(\n UIView.controlEvent.Focus,\n (sender: UIView, event: Event) => {\n \n this.focused = YES\n \n }\n )\n \n this.addTargetForControlEvent(\n UIView.controlEvent.Blur,\n (sender: UIView, event: Event) => {\n \n this.focused = NO\n \n }\n )\n \n \n this.pausesPointerEvents = YES\n this.tabIndex = 1\n \n this.style.cursor = \"pointer\"\n \n //this.style.outline = \"none\";\n \n \n this.nativeSelectionEnabled = NO\n \n \n this.addTargetForControlEvents([\n UIView.controlEvent.EnterDown, UIView.controlEvent.PointerUpInside\n ], () => {\n \n if (this.isToggleable) {\n \n this.toggleSelectedState()\n \n }\n \n })\n \n }\n \n public set hovered(hovered: boolean) {\n this._hovered = hovered\n this.updateContentForCurrentState()\n }\n \n public get hovered(): boolean {\n return this._hovered ?? NO\n }\n \n public set highlighted(highlighted: boolean) {\n this._highlighted = highlighted\n this.updateContentForCurrentState()\n }\n \n public get highlighted(): boolean {\n return this._highlighted\n }\n \n public set focused(focused: boolean) {\n this._focused = focused\n if (focused) {\n this.focus()\n }\n else {\n this.blur()\n }\n this.updateContentForCurrentState()\n }\n \n public get focused(): boolean {\n return this._focused ?? NO\n }\n \n public set selected(selected: boolean) {\n this._selected = selected\n this.updateContentForCurrentState()\n }\n \n public get selected(): boolean {\n return this._selected\n }\n \n \n updateContentForCurrentState() {\n \n let updateFunction: Function = this.updateContentForNormalState\n if (this.selected && this.highlighted) {\n updateFunction = this.updateContentForSelectedAndHighlightedState\n }\n else if (this.selected) {\n updateFunction = this.updateContentForSelectedState\n }\n else if (this.focused) {\n updateFunction = this.updateContentForFocusedState\n }\n else if (this.highlighted) {\n updateFunction = this.updateContentForHighlightedState\n }\n else if (this.hovered) {\n updateFunction = this.updateContentForHoveredState\n }\n \n if (!IS(updateFunction)) {\n this.backgroundColor = UIColor.nilColor\n }\n else {\n updateFunction.call(this)\n }\n \n }\n \n updateContentForNormalState() {\n \n \n }\n \n updateContentForHoveredState() {\n \n this.updateContentForNormalState()\n \n }\n \n updateContentForFocusedState() {\n \n this.updateContentForHoveredState()\n \n }\n \n updateContentForHighlightedState() {\n \n \n }\n \n updateContentForSelectedState() {\n \n \n }\n \n updateContentForSelectedAndHighlightedState() {\n \n this.updateContentForSelectedState()\n \n }\n \n \n override set enabled(enabled: boolean) {\n super.enabled = enabled\n this.updateContentForCurrentEnabledState()\n }\n \n override get enabled() {\n return super.enabled\n }\n \n override updateContentForCurrentEnabledState() {\n \n if (this.enabled) {\n this.alpha = 1\n }\n else {\n this.alpha = 0.5\n }\n \n this.userInteractionEnabled = this.enabled\n \n }\n \n \n override addStyleClass(styleClassName: string) {\n \n super.addStyleClass(styleClassName)\n \n if (this.styleClassName != styleClassName) {\n \n this.updateContentForCurrentState.call(this)\n \n }\n \n }\n \n \n override didReceiveBroadcastEvent(event: UIViewBroadcastEvent) {\n \n super.didReceiveBroadcastEvent(event)\n \n if (event.name == UIView.broadcastEventName.PageDidScroll || event.name ==\n UIView.broadcastEventName.AddedToViewTree) {\n \n const wasHovered = this._hovered\n const wasHighlighted = this._highlighted\n \n this._hovered = NO\n this._highlighted = NO\n \n if (wasHovered || wasHighlighted) {\n this.updateContentForCurrentState()\n }\n \n }\n \n \n }\n \n \n toggleSelectedState() {\n \n \n this.selected = !this.selected\n \n \n }\n \n set isToggleable(isToggleable: boolean) {\n \n this._isToggleable = isToggleable\n \n }\n \n get isToggleable() {\n \n return this._isToggleable\n \n }\n \n \n override layoutSubviews() {\n \n super.layoutSubviews()\n \n const bounds = this.bounds\n \n \n }\n \n \n override sendControlEventForKey(eventKey: string, nativeEvent: Event) {\n \n if (eventKey == UIView.controlEvent.PointerUpInside && !this.highlighted) {\n \n // Do not send the event in this case\n //super.sendControlEventForKey(eventKey, nativeEvent);\n \n const asd = 1\n \n }\n else {\n \n super.sendControlEventForKey(eventKey, nativeEvent)\n \n }\n \n }\n \n \n static getEventCoordinatesInDocument(touchOrMouseEvent: any) {\n // http://www.quirksmode.org/js/events_properties.html\n var posx = 0\n var posy = 0\n var e = touchOrMouseEvent\n if (!e) {\n e = window.event\n }\n if (e.pageX || e.pageY) {\n posx = e.pageX\n posy = e.pageY\n }\n else if (e.clientX || e.clientY) {\n posx = e.clientX + document.body.scrollLeft\n + document.documentElement.scrollLeft\n posy = e.clientY + document.body.scrollTop\n + document.documentElement.scrollTop\n }\n // posx and posy contain the mouse position relative to the document\n \n const coordinates = { \"x\": posx, \"y\": posy }\n \n return coordinates\n \n }\n \n \n static getElementPositionInDocument(el: { tagName: string; offsetLeft: number; scrollLeft: number; clientLeft: number; offsetTop: number; scrollTop: number; clientTop: number; offsetParent: any }) {\n //https://www.kirupa.com/html5/getting_mouse_click_position.htm\n var xPosition = 0\n var yPosition = 0\n \n while (el) {\n if (el.tagName == \"BODY\") {\n \n // Coordinates in document are coordinates in body, therefore subtracting the scroll position of the body is not needed\n \n // // deal with browser quirks with body/window/document and page scroll\n // var xScrollPos = el.scrollLeft || document.documentElement.scrollLeft;\n // var yScrollPos = el.scrollTop || document.documentElement.scrollTop;\n //\n // xPosition += (el.offsetLeft - xScrollPos + el.clientLeft);\n // yPosition += (el.offsetTop - yScrollPos + el.clientTop);\n }\n else {\n xPosition += (el.offsetLeft - el.scrollLeft + el.clientLeft)\n yPosition += (el.offsetTop - el.scrollTop + el.clientTop)\n }\n \n el = el.offsetParent\n }\n return {\n x: xPosition,\n y: yPosition\n }\n }\n \n static convertCoordinatesFromDocumentToElement(x: number, y: number, element: any) {\n const elementPositionInDocument = this.getElementPositionInDocument(element)\n const coordinatesInElement = { \"x\": x - elementPositionInDocument.x, \"y\": y - elementPositionInDocument.y }\n return coordinatesInElement\n }\n \n static getEventCoordinatesInElement(touchOrMouseEvent: any, element: any) {\n const coordinatesInDocument = this.getEventCoordinatesInDocument(touchOrMouseEvent)\n const coordinatesInElement = this.convertCoordinatesFromDocumentToElement(\n coordinatesInDocument.x,\n coordinatesInDocument.y,\n element\n )\n return coordinatesInElement\n }\n \n \n}\n"],
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,qBAAwB;AACxB,sBAAiC;AACjC,
|
|
4
|
+
"sourcesContent": ["import { UIColor } from \"./UIColor\"\nimport { IS, nil, NO, YES } from \"./UIObject\"\nimport { UIView, UIViewAddControlEventTargetObject, UIViewBroadcastEvent } from \"./UIView\"\n\n\nexport class UIBaseButton extends UIView {\n \n static override controlEvent = Object.assign({}, UIView.controlEvent, {\n \"PrimaryActionTriggered\": \"PrimaryActionTriggered\"\n } as const)\n \n override controlEvent = UIBaseButton.controlEvent\n \n override get controlEventTargetAccumulator(): UIViewAddControlEventTargetObject<typeof UIBaseButton> {\n return super.controlEventTargetAccumulator as any\n }\n \n \n _selected: boolean = NO\n _highlighted: boolean = NO\n \n override _isPointerInside: boolean\n \n \n _isToggleable: boolean = NO\n _hovered?: boolean\n _focused?: boolean\n \n \n constructor(elementID?: string, elementType?: string) {\n \n super(elementID, undefined, elementType)\n \n // Instance variables\n \n \n this._isPointerInside = NO\n \n \n const setHovered = () => {\n this.hovered = YES\n }\n this.addTargetForControlEvent(UIView.controlEvent.PointerHover, setHovered)\n \n const setNotHovered = () => {\n \n this.hovered = NO\n \n }\n \n this.addTargetForControlEvents([\n UIView.controlEvent.PointerLeave, UIView.controlEvent.PointerCancel, UIView.controlEvent.MultipleTouches\n ], setNotHovered)\n \n \n let highlightingTime: number\n const setHighlighted = () => {\n this.highlighted = YES\n highlightingTime = Date.now()\n }\n this.addTargetForControlEvent(UIView.controlEvent.PointerDown, setHighlighted)\n this.addTargetForControlEvent(UIView.controlEvent.PointerEnter, setHighlighted)\n \n const setNotHighlighted = () => {\n this.highlighted = NO\n }\n const setNotHighlightedWithMinimumDuration = () => {\n const minimumDurationInMilliseconds = 50\n const elapsedTime = Date.now() - highlightingTime\n if (minimumDurationInMilliseconds < elapsedTime) {\n this.highlighted = NO\n }\n else {\n setTimeout(() => {\n this.highlighted = NO\n }, minimumDurationInMilliseconds - elapsedTime)\n }\n }\n this.addTargetForControlEvents([\n UIView.controlEvent.PointerLeave, UIView.controlEvent.PointerCancel, UIView.controlEvent.MultipleTouches\n ], setNotHighlighted)\n this.addTargetForControlEvent(UIView.controlEvent.PointerUp, setNotHighlightedWithMinimumDuration)\n \n // Enter and Space both activate the button.\n // Fire PointerUpInside (which cascades to PrimaryActionTriggered via sendControlEventForKey).\n this.addTargetForControlEvent(UIView.controlEvent.EnterDown, () => {\n \n setHighlighted()\n setNotHighlightedWithMinimumDuration()\n this.sendControlEventForKey(UIView.controlEvent.PointerUpInside, nil)\n \n })\n \n this.addTargetForControlEvent(UIView.controlEvent.SpaceDown, (sender, event) => {\n \n event.preventDefault()\n setHighlighted()\n setNotHighlightedWithMinimumDuration()\n this.sendControlEventForKey(UIView.controlEvent.PointerUpInside, nil)\n \n })\n \n \n this.addTargetForControlEvent(\n UIView.controlEvent.Focus,\n (sender: UIView, event: Event) => {\n \n this.focused = YES\n \n }\n )\n \n this.addTargetForControlEvent(\n UIView.controlEvent.Blur,\n (sender: UIView, event: Event) => {\n \n this.focused = NO\n \n }\n )\n \n \n this.pausesPointerEvents = YES\n this.tabIndex = 1\n \n this.style.cursor = \"pointer\"\n \n //this.style.outline = \"none\";\n \n \n this.nativeSelectionEnabled = NO\n \n \n this.addTargetForControlEvents([\n UIBaseButton.controlEvent.PrimaryActionTriggered, UIView.controlEvent.PointerUpInside\n ], () => {\n \n if (this.isToggleable) {\n \n this.toggleSelectedState()\n \n }\n \n })\n \n }\n \n public set hovered(hovered: boolean) {\n this._hovered = hovered\n this.updateContentForCurrentState()\n }\n \n public get hovered(): boolean {\n return this._hovered ?? NO\n }\n \n public set highlighted(highlighted: boolean) {\n this._highlighted = highlighted\n this.updateContentForCurrentState()\n }\n \n public get highlighted(): boolean {\n return this._highlighted\n }\n \n public set focused(focused: boolean) {\n this._focused = focused\n if (focused) {\n this.focus()\n }\n else {\n this.blur()\n }\n this.updateContentForCurrentState()\n }\n \n public get focused(): boolean {\n return this._focused ?? NO\n }\n \n public set selected(selected: boolean) {\n this._selected = selected\n this.updateContentForCurrentState()\n }\n \n public get selected(): boolean {\n return this._selected\n }\n \n \n updateContentForCurrentState() {\n \n let updateFunction: Function = this.updateContentForNormalState\n if (this.selected && this.highlighted) {\n updateFunction = this.updateContentForSelectedAndHighlightedState\n }\n else if (this.selected) {\n updateFunction = this.updateContentForSelectedState\n }\n else if (this.focused) {\n updateFunction = this.updateContentForFocusedState\n }\n else if (this.highlighted) {\n updateFunction = this.updateContentForHighlightedState\n }\n else if (this.hovered) {\n updateFunction = this.updateContentForHoveredState\n }\n \n if (!IS(updateFunction)) {\n this.backgroundColor = UIColor.nilColor\n }\n else {\n updateFunction.call(this)\n }\n \n }\n \n updateContentForNormalState() {\n \n \n }\n \n updateContentForHoveredState() {\n \n this.updateContentForNormalState()\n \n }\n \n updateContentForFocusedState() {\n \n this.updateContentForHoveredState()\n \n }\n \n updateContentForHighlightedState() {\n \n \n }\n \n updateContentForSelectedState() {\n \n \n }\n \n updateContentForSelectedAndHighlightedState() {\n \n this.updateContentForSelectedState()\n \n }\n \n \n override set enabled(enabled: boolean) {\n super.enabled = enabled\n this.updateContentForCurrentEnabledState()\n }\n \n override get enabled() {\n return super.enabled\n }\n \n override updateContentForCurrentEnabledState() {\n \n if (this.enabled) {\n this.alpha = 1\n }\n else {\n this.alpha = 0.5\n }\n \n this.userInteractionEnabled = this.enabled\n \n }\n \n \n override addStyleClass(styleClassName: string) {\n \n super.addStyleClass(styleClassName)\n \n if (this.styleClassName != styleClassName) {\n \n this.updateContentForCurrentState.call(this)\n \n }\n \n }\n \n \n override didReceiveBroadcastEvent(event: UIViewBroadcastEvent) {\n \n super.didReceiveBroadcastEvent(event)\n \n if (event.name == UIView.broadcastEventName.PageDidScroll || event.name ==\n UIView.broadcastEventName.AddedToViewTree) {\n \n const wasHovered = this._hovered\n const wasHighlighted = this._highlighted\n \n this._hovered = NO\n this._highlighted = NO\n \n if (wasHovered || wasHighlighted) {\n this.updateContentForCurrentState()\n }\n \n }\n \n \n }\n \n \n toggleSelectedState() {\n \n \n this.selected = !this.selected\n \n \n }\n \n set isToggleable(isToggleable: boolean) {\n \n this._isToggleable = isToggleable\n \n }\n \n get isToggleable() {\n \n return this._isToggleable\n \n }\n \n \n override layoutSubviews() {\n \n super.layoutSubviews()\n \n const bounds = this.bounds\n \n \n }\n \n \n override sendControlEventForKey(eventKey: string, nativeEvent: Event) {\n \n if (eventKey == UIView.controlEvent.PointerUpInside && !this.highlighted) {\n \n // Do not send the event in this case\n //super.sendControlEventForKey(eventKey, nativeEvent);\n \n const asd = 1\n \n }\n else {\n \n super.sendControlEventForKey(eventKey, nativeEvent)\n \n if (eventKey == UIView.controlEvent.PointerUpInside) {\n super.sendControlEventForKey(UIBaseButton.controlEvent.PrimaryActionTriggered, nativeEvent)\n }\n \n }\n \n }\n \n \n static getEventCoordinatesInDocument(touchOrMouseEvent: any) {\n // http://www.quirksmode.org/js/events_properties.html\n var posx = 0\n var posy = 0\n var e = touchOrMouseEvent\n if (!e) {\n e = window.event\n }\n if (e.pageX || e.pageY) {\n posx = e.pageX\n posy = e.pageY\n }\n else if (e.clientX || e.clientY) {\n posx = e.clientX + document.body.scrollLeft\n + document.documentElement.scrollLeft\n posy = e.clientY + document.body.scrollTop\n + document.documentElement.scrollTop\n }\n // posx and posy contain the mouse position relative to the document\n \n const coordinates = { \"x\": posx, \"y\": posy }\n \n return coordinates\n \n }\n \n \n static getElementPositionInDocument(el: { tagName: string; offsetLeft: number; scrollLeft: number; clientLeft: number; offsetTop: number; scrollTop: number; clientTop: number; offsetParent: any }) {\n //https://www.kirupa.com/html5/getting_mouse_click_position.htm\n var xPosition = 0\n var yPosition = 0\n \n while (el) {\n if (el.tagName == \"BODY\") {\n \n // Coordinates in document are coordinates in body, therefore subtracting the scroll position of the body is not needed\n \n // // deal with browser quirks with body/window/document and page scroll\n // var xScrollPos = el.scrollLeft || document.documentElement.scrollLeft;\n // var yScrollPos = el.scrollTop || document.documentElement.scrollTop;\n //\n // xPosition += (el.offsetLeft - xScrollPos + el.clientLeft);\n // yPosition += (el.offsetTop - yScrollPos + el.clientTop);\n }\n else {\n xPosition += (el.offsetLeft - el.scrollLeft + el.clientLeft)\n yPosition += (el.offsetTop - el.scrollTop + el.clientTop)\n }\n \n el = el.offsetParent\n }\n return {\n x: xPosition,\n y: yPosition\n }\n }\n \n static convertCoordinatesFromDocumentToElement(x: number, y: number, element: any) {\n const elementPositionInDocument = this.getElementPositionInDocument(element)\n const coordinatesInElement = { \"x\": x - elementPositionInDocument.x, \"y\": y - elementPositionInDocument.y }\n return coordinatesInElement\n }\n \n static getEventCoordinatesInElement(touchOrMouseEvent: any, element: any) {\n const coordinatesInDocument = this.getEventCoordinatesInDocument(touchOrMouseEvent)\n const coordinatesInElement = this.convertCoordinatesFromDocumentToElement(\n coordinatesInDocument.x,\n coordinatesInDocument.y,\n element\n )\n return coordinates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7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "uicore-ts",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.263",
|
|
4
4
|
"description": "UICore is a library to build native-like user interfaces using pure Typescript. No HTML is needed at all. Components are described as TS classes and all user interactions are handled explicitly. This library is strongly inspired by the UIKit framework that is used in IOS. In addition, UICore has tools to handle URL based routing, array sorting and filtering and adds a number of other utilities for convenience.",
|
|
5
5
|
"main": "compiledScripts/index.js",
|
|
6
6
|
"types": "compiledScripts/index.d.ts",
|
package/scripts/UIBaseButton.ts
CHANGED
|
@@ -1,10 +1,21 @@
|
|
|
1
1
|
import { UIColor } from "./UIColor"
|
|
2
2
|
import { IS, nil, NO, YES } from "./UIObject"
|
|
3
|
-
import { UIView, UIViewBroadcastEvent } from "./UIView"
|
|
3
|
+
import { UIView, UIViewAddControlEventTargetObject, UIViewBroadcastEvent } from "./UIView"
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
export class UIBaseButton extends UIView {
|
|
7
7
|
|
|
8
|
+
static override controlEvent = Object.assign({}, UIView.controlEvent, {
|
|
9
|
+
"PrimaryActionTriggered": "PrimaryActionTriggered"
|
|
10
|
+
} as const)
|
|
11
|
+
|
|
12
|
+
override controlEvent = UIBaseButton.controlEvent
|
|
13
|
+
|
|
14
|
+
override get controlEventTargetAccumulator(): UIViewAddControlEventTargetObject<typeof UIBaseButton> {
|
|
15
|
+
return super.controlEventTargetAccumulator as any
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
|
|
8
19
|
_selected: boolean = NO
|
|
9
20
|
_highlighted: boolean = NO
|
|
10
21
|
|
|
@@ -70,11 +81,22 @@ export class UIBaseButton extends UIView {
|
|
|
70
81
|
], setNotHighlighted)
|
|
71
82
|
this.addTargetForControlEvent(UIView.controlEvent.PointerUp, setNotHighlightedWithMinimumDuration)
|
|
72
83
|
|
|
73
|
-
//
|
|
84
|
+
// Enter and Space both activate the button.
|
|
85
|
+
// Fire PointerUpInside (which cascades to PrimaryActionTriggered via sendControlEventForKey).
|
|
74
86
|
this.addTargetForControlEvent(UIView.controlEvent.EnterDown, () => {
|
|
75
87
|
|
|
76
88
|
setHighlighted()
|
|
77
89
|
setNotHighlightedWithMinimumDuration()
|
|
90
|
+
this.sendControlEventForKey(UIView.controlEvent.PointerUpInside, nil)
|
|
91
|
+
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
this.addTargetForControlEvent(UIView.controlEvent.SpaceDown, (sender, event) => {
|
|
95
|
+
|
|
96
|
+
event.preventDefault()
|
|
97
|
+
setHighlighted()
|
|
98
|
+
setNotHighlightedWithMinimumDuration()
|
|
99
|
+
this.sendControlEventForKey(UIView.controlEvent.PointerUpInside, nil)
|
|
78
100
|
|
|
79
101
|
})
|
|
80
102
|
|
|
@@ -110,7 +132,7 @@ export class UIBaseButton extends UIView {
|
|
|
110
132
|
|
|
111
133
|
|
|
112
134
|
this.addTargetForControlEvents([
|
|
113
|
-
|
|
135
|
+
UIBaseButton.controlEvent.PrimaryActionTriggered, UIView.controlEvent.PointerUpInside
|
|
114
136
|
], () => {
|
|
115
137
|
|
|
116
138
|
if (this.isToggleable) {
|
|
@@ -332,6 +354,10 @@ export class UIBaseButton extends UIView {
|
|
|
332
354
|
|
|
333
355
|
super.sendControlEventForKey(eventKey, nativeEvent)
|
|
334
356
|
|
|
357
|
+
if (eventKey == UIView.controlEvent.PointerUpInside) {
|
|
358
|
+
super.sendControlEventForKey(UIBaseButton.controlEvent.PrimaryActionTriggered, nativeEvent)
|
|
359
|
+
}
|
|
360
|
+
|
|
335
361
|
}
|
|
336
362
|
|
|
337
363
|
}
|