@nstudio/nativescript-effect-ui 0.1.1 → 0.1.2
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 +79 -0
- package/README.md +28 -0
- package/dist/linux/LinuxHost.js +9 -1
- package/dist/linux/LinuxHost.js.map +1 -1
- package/dist/macos/MacosHost.d.ts +13 -0
- package/dist/macos/MacosHost.d.ts.map +1 -1
- package/dist/macos/MacosHost.js +373 -12
- package/dist/macos/MacosHost.js.map +1 -1
- package/dist/macos/styles.d.ts.map +1 -1
- package/dist/macos/styles.js +4 -1
- package/dist/macos/styles.js.map +1 -1
- package/dist/mason/MasonHost.d.ts +35 -1
- package/dist/mason/MasonHost.d.ts.map +1 -1
- package/dist/mason/MasonHost.js +330 -18
- package/dist/mason/MasonHost.js.map +1 -1
- package/dist/mason/dialog.d.ts +24 -1
- package/dist/mason/dialog.d.ts.map +1 -1
- package/dist/mason/dialog.js +162 -2
- package/dist/mason/dialog.js.map +1 -1
- package/dist/mason/elements.d.ts.map +1 -1
- package/dist/mason/elements.js +33 -6
- package/dist/mason/elements.js.map +1 -1
- package/dist/mason/events.d.ts +4 -0
- package/dist/mason/events.d.ts.map +1 -1
- package/dist/mason/events.js +110 -2
- package/dist/mason/events.js.map +1 -1
- package/dist/mason/index.d.ts +2 -1
- package/dist/mason/index.d.ts.map +1 -1
- package/dist/mason/index.js +2 -1
- package/dist/mason/index.js.map +1 -1
- package/dist/mason/input-native.d.ts +32 -0
- package/dist/mason/input-native.d.ts.map +1 -0
- package/dist/mason/input-native.js +280 -0
- package/dist/mason/input-native.js.map +1 -0
- package/dist/mason/media.d.ts +18 -0
- package/dist/mason/media.d.ts.map +1 -0
- package/dist/mason/media.js +255 -0
- package/dist/mason/media.js.map +1 -0
- package/dist/mason/select.d.ts +25 -0
- package/dist/mason/select.d.ts.map +1 -0
- package/dist/mason/select.js +75 -0
- package/dist/mason/select.js.map +1 -0
- package/dist/mason/services.d.ts +2 -1
- package/dist/mason/services.d.ts.map +1 -1
- package/dist/mason/services.js +61 -75
- package/dist/mason/services.js.map +1 -1
- package/dist/mason/styles.d.ts +16 -0
- package/dist/mason/styles.d.ts.map +1 -1
- package/dist/mason/styles.js +138 -19
- package/dist/mason/styles.js.map +1 -1
- package/dist/mason/svg.d.ts +86 -0
- package/dist/mason/svg.d.ts.map +1 -0
- package/dist/mason/svg.js +932 -0
- package/dist/mason/svg.js.map +1 -0
- package/dist/mason/video.d.ts +40 -0
- package/dist/mason/video.d.ts.map +1 -0
- package/dist/mason/video.js +641 -0
- package/dist/mason/video.js.map +1 -0
- package/dist/motion/index.d.ts +8 -8
- package/dist/platform/intl-mapping.d.ts +124 -0
- package/dist/platform/intl-mapping.d.ts.map +1 -0
- package/dist/platform/intl-mapping.js +540 -0
- package/dist/platform/intl-mapping.js.map +1 -0
- package/dist/platform/intl-polyfill.d.ts +60 -0
- package/dist/platform/intl-polyfill.d.ts.map +1 -0
- package/dist/platform/intl-polyfill.js +389 -0
- package/dist/platform/intl-polyfill.js.map +1 -0
- package/dist/platform/intl.d.ts +9 -0
- package/dist/platform/intl.d.ts.map +1 -0
- package/dist/platform/intl.js +219 -0
- package/dist/platform/intl.js.map +1 -0
- package/dist/postcss/color.d.ts +18 -0
- package/dist/postcss/color.d.ts.map +1 -0
- package/dist/postcss/color.js +620 -0
- package/dist/postcss/color.js.map +1 -0
- package/dist/postcss/index.d.ts +39 -0
- package/dist/postcss/index.d.ts.map +1 -0
- package/dist/postcss/index.js +249 -0
- package/dist/postcss/index.js.map +1 -0
- package/dist/postcss/values.d.ts +49 -0
- package/dist/postcss/values.d.ts.map +1 -0
- package/dist/postcss/values.js +259 -0
- package/dist/postcss/values.js.map +1 -0
- package/dist/testing/MockMasonHost.d.ts +2 -2
- package/dist/testing/MockMasonHost.d.ts.map +1 -1
- package/dist/testing/MockMasonHost.js +1 -1
- package/dist/testing/MockMasonHost.js.map +1 -1
- package/dist/windows/WindowsHost.js +9 -1
- package/dist/windows/WindowsHost.js.map +1 -1
- package/package.json +31 -3
package/dist/macos/MacosHost.js
CHANGED
|
@@ -32,18 +32,79 @@ function ensureAppKitClasses() {
|
|
|
32
32
|
FlippedNSViewCtor = FlippedNSView;
|
|
33
33
|
class ClickableNSView extends NSViewCls {
|
|
34
34
|
_onClick;
|
|
35
|
+
_onFocusChange;
|
|
36
|
+
_isFocused = false;
|
|
37
|
+
_baseBorderWidth = 0;
|
|
38
|
+
_baseBorderColor = null;
|
|
35
39
|
get isFlipped() {
|
|
36
40
|
return true;
|
|
37
41
|
}
|
|
42
|
+
get acceptsFirstResponder() {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
get canBecomeKeyView() {
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
becomeFirstResponder() {
|
|
49
|
+
this._isFocused = true;
|
|
50
|
+
this._applyFocusVisuals(true);
|
|
51
|
+
this._onFocusChange?.(true);
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
resignFirstResponder() {
|
|
55
|
+
this._isFocused = false;
|
|
56
|
+
this._applyFocusVisuals(false);
|
|
57
|
+
this._onFocusChange?.(false);
|
|
58
|
+
return true;
|
|
59
|
+
}
|
|
60
|
+
_applyFocusVisuals(focused) {
|
|
61
|
+
try {
|
|
62
|
+
const layer = this.layer;
|
|
63
|
+
if (!layer)
|
|
64
|
+
return;
|
|
65
|
+
if (focused) {
|
|
66
|
+
const accent = g('NSColor').controlAccentColor;
|
|
67
|
+
layer.borderWidth = 3;
|
|
68
|
+
layer.borderColor = accent.CGColor;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
layer.borderWidth = this._baseBorderWidth;
|
|
72
|
+
layer.borderColor = this._baseBorderColor;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
// Ignore
|
|
77
|
+
}
|
|
78
|
+
}
|
|
38
79
|
mouseDown(_event) {
|
|
39
80
|
if (this.layer)
|
|
40
81
|
this.layer.opacity = 0.72;
|
|
82
|
+
try {
|
|
83
|
+
this.window?.makeFirstResponder(this);
|
|
84
|
+
}
|
|
85
|
+
catch {
|
|
86
|
+
// Ignore
|
|
87
|
+
}
|
|
41
88
|
}
|
|
42
89
|
mouseUp(_event) {
|
|
43
90
|
if (this.layer)
|
|
44
91
|
this.layer.opacity = 1.0;
|
|
45
92
|
this._onClick?.();
|
|
46
93
|
}
|
|
94
|
+
keyDown(event) {
|
|
95
|
+
const code = Number(event?.keyCode ?? -1);
|
|
96
|
+
if (code === 49 || code === 36 || code === 76) {
|
|
97
|
+
if (this.layer)
|
|
98
|
+
this.layer.opacity = 0.72;
|
|
99
|
+
setTimeout(() => {
|
|
100
|
+
if (this.layer)
|
|
101
|
+
this.layer.opacity = 1.0;
|
|
102
|
+
}, 90);
|
|
103
|
+
this._onClick?.();
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
super.keyDown(event);
|
|
107
|
+
}
|
|
47
108
|
resetCursorRects() {
|
|
48
109
|
try {
|
|
49
110
|
const NSCursorCls = g('NSCursor');
|
|
@@ -58,7 +119,14 @@ function ensureAppKitClasses() {
|
|
|
58
119
|
ClickableNSViewCtor = ClickableNSView;
|
|
59
120
|
class InputDelegate extends NSObjectCls {
|
|
60
121
|
_onChange;
|
|
122
|
+
_onFocusChange;
|
|
61
123
|
static ObjCProtocols = [g('NSTextFieldDelegate')];
|
|
124
|
+
controlTextDidBeginEditing(_notification) {
|
|
125
|
+
this._onFocusChange?.(true);
|
|
126
|
+
}
|
|
127
|
+
controlTextDidEndEditing(_notification) {
|
|
128
|
+
this._onFocusChange?.(false);
|
|
129
|
+
}
|
|
62
130
|
controlTextDidChange(notification) {
|
|
63
131
|
try {
|
|
64
132
|
const field = notification?.object;
|
|
@@ -135,8 +203,8 @@ function makeAttributedText(text, style) {
|
|
|
135
203
|
}
|
|
136
204
|
if (style.textAlign !== 'left') {
|
|
137
205
|
const para = g('NSMutableParagraphStyle').new();
|
|
138
|
-
// NSTextAlignment: Left=0,
|
|
139
|
-
para.alignment = style.textAlign === 'center' ?
|
|
206
|
+
// macOS 64-bit NSTextAlignment: Left=0, Center=1, Right=2
|
|
207
|
+
para.alignment = style.textAlign === 'center' ? 1 : 2;
|
|
140
208
|
attrs['NSParagraphStyle'] = para;
|
|
141
209
|
}
|
|
142
210
|
return g('NSAttributedString').alloc().initWithStringAttributes(text, attrs);
|
|
@@ -253,9 +321,12 @@ function makeNativeHtmlServices() {
|
|
|
253
321
|
focus: (el) => {
|
|
254
322
|
try {
|
|
255
323
|
const node = el;
|
|
256
|
-
const
|
|
257
|
-
|
|
258
|
-
|
|
324
|
+
const target = node?.nsInput ?? node?.nsView;
|
|
325
|
+
const win = target?.window ?? node?.nsView?.window;
|
|
326
|
+
if (win && target) {
|
|
327
|
+
win.makeFirstResponder(target);
|
|
328
|
+
target.scrollRectToVisible?.(target.bounds);
|
|
329
|
+
}
|
|
259
330
|
}
|
|
260
331
|
catch {
|
|
261
332
|
// Ignore
|
|
@@ -328,7 +399,28 @@ export function makeMacosHost(options) {
|
|
|
328
399
|
ensureAppKitClasses();
|
|
329
400
|
const rootContainer = createMacosElementNode('div');
|
|
330
401
|
const activeDialogs = new Set();
|
|
402
|
+
const focusOrderByWindow = new Map();
|
|
403
|
+
const focusedNodeByWindow = new Map();
|
|
331
404
|
let lastTitle;
|
|
405
|
+
const setInputContainerFocus = (view, focused) => {
|
|
406
|
+
try {
|
|
407
|
+
view._isFocused = focused;
|
|
408
|
+
const layer = view.layer;
|
|
409
|
+
if (!layer)
|
|
410
|
+
return;
|
|
411
|
+
if (focused) {
|
|
412
|
+
layer.borderWidth = 3;
|
|
413
|
+
layer.borderColor = g('NSColor').controlAccentColor.CGColor;
|
|
414
|
+
}
|
|
415
|
+
else {
|
|
416
|
+
layer.borderWidth = view._baseBorderWidth ?? 0;
|
|
417
|
+
layer.borderColor = view._baseBorderColor ?? null;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
catch {
|
|
421
|
+
// Ignore
|
|
422
|
+
}
|
|
423
|
+
};
|
|
332
424
|
const ensureNSView = (node, isClickable) => {
|
|
333
425
|
if (node.nsView)
|
|
334
426
|
return node.nsView;
|
|
@@ -345,6 +437,11 @@ export function makeMacosHost(options) {
|
|
|
345
437
|
}
|
|
346
438
|
fireBubble(node, 'click', {});
|
|
347
439
|
};
|
|
440
|
+
view._onFocusChange = (focused) => {
|
|
441
|
+
if (focused && view.window)
|
|
442
|
+
focusedNodeByWindow.set(view.window, node);
|
|
443
|
+
fireBubble(node, focused ? 'focus' : 'blur', {});
|
|
444
|
+
};
|
|
348
445
|
}
|
|
349
446
|
node.nsView = view;
|
|
350
447
|
return view;
|
|
@@ -359,8 +456,24 @@ export function makeMacosHost(options) {
|
|
|
359
456
|
const layer = view.layer;
|
|
360
457
|
if (layer) {
|
|
361
458
|
layer.backgroundColor = style.backgroundColor ? toNSColor(style.backgroundColor).CGColor : null;
|
|
362
|
-
|
|
363
|
-
|
|
459
|
+
const baseBorderColor = style.borderColor ? toNSColor(style.borderColor).CGColor : null;
|
|
460
|
+
view._baseBorderWidth = style.borderWidth;
|
|
461
|
+
view._baseBorderColor = baseBorderColor;
|
|
462
|
+
const isTrackedFocused = (() => {
|
|
463
|
+
for (const tracked of focusedNodeByWindow.values()) {
|
|
464
|
+
if (tracked === node)
|
|
465
|
+
return true;
|
|
466
|
+
}
|
|
467
|
+
return false;
|
|
468
|
+
})();
|
|
469
|
+
if (view._isFocused || isTrackedFocused) {
|
|
470
|
+
layer.borderWidth = 3;
|
|
471
|
+
layer.borderColor = g('NSColor').controlAccentColor.CGColor;
|
|
472
|
+
}
|
|
473
|
+
else {
|
|
474
|
+
layer.borderWidth = style.borderWidth;
|
|
475
|
+
layer.borderColor = baseBorderColor;
|
|
476
|
+
}
|
|
364
477
|
const maxR = Math.min(rect.width, rect.height) / 2;
|
|
365
478
|
layer.cornerRadius = style.borderRadius >= 999 ? maxR : Math.min(style.borderRadius, maxR);
|
|
366
479
|
layer.masksToBounds = style.borderRadius > 0;
|
|
@@ -376,12 +489,18 @@ export function makeMacosHost(options) {
|
|
|
376
489
|
tf.isSelectable = true;
|
|
377
490
|
tf.isBordered = false;
|
|
378
491
|
tf.drawsBackground = false;
|
|
379
|
-
tf.focusRingType = 1; // NSFocusRingTypeNone
|
|
492
|
+
tf.focusRingType = 1; // NSFocusRingTypeNone (drawn cleanly on outer rounded border)
|
|
380
493
|
const del = InputDelegateCtor.new();
|
|
381
494
|
del._onChange = (val) => {
|
|
382
495
|
node.props['value'] = val;
|
|
383
496
|
fireBubble(node, 'input', { value: val });
|
|
384
497
|
};
|
|
498
|
+
del._onFocusChange = (focused) => {
|
|
499
|
+
setInputContainerFocus(view, focused);
|
|
500
|
+
if (focused && view.window)
|
|
501
|
+
focusedNodeByWindow.set(view.window, node);
|
|
502
|
+
fireBubble(node, focused ? 'focus' : 'blur', {});
|
|
503
|
+
};
|
|
385
504
|
tf.delegate = del;
|
|
386
505
|
node._inputDelegate = del;
|
|
387
506
|
node.nsInput = tf;
|
|
@@ -420,10 +539,16 @@ export function makeMacosHost(options) {
|
|
|
420
539
|
const innerW = Math.max(0, rect.width - style.padLeft - style.padRight);
|
|
421
540
|
const innerH = Math.max(0, rect.height - style.padTop - style.padBottom);
|
|
422
541
|
const measured = measureAppKitText(text, style, innerW);
|
|
542
|
+
const isCentered = style.textAlign === 'center';
|
|
543
|
+
const isSingleLine = isCentered && measured.height <= style.fontSize * 1.75;
|
|
544
|
+
lbl.usesSingleLineMode = isSingleLine;
|
|
423
545
|
const textY = style.padTop + Math.max(0, (innerH - measured.height) / 2);
|
|
424
546
|
lbl.frame = {
|
|
425
|
-
origin: { x: style.padLeft, y: textY },
|
|
426
|
-
size: {
|
|
547
|
+
origin: { x: isCentered ? 0 : style.padLeft, y: textY },
|
|
548
|
+
size: {
|
|
549
|
+
width: isCentered ? rect.width : innerW,
|
|
550
|
+
height: Math.max(innerH, measured.height),
|
|
551
|
+
},
|
|
427
552
|
};
|
|
428
553
|
lbl.attributedStringValue = makeAttributedText(text, style);
|
|
429
554
|
}
|
|
@@ -486,6 +611,206 @@ export function makeMacosHost(options) {
|
|
|
486
611
|
// Ignore
|
|
487
612
|
}
|
|
488
613
|
};
|
|
614
|
+
const collectFocusable = (node, out, allowDialog = false) => {
|
|
615
|
+
const ln = node.layoutNode;
|
|
616
|
+
if (!ln || ln.style.display === 'none' || (node.tag === 'dialog' && !allowDialog))
|
|
617
|
+
return;
|
|
618
|
+
const disabled = node.attrs['disabled'] !== undefined || node.props['disabled'] === true;
|
|
619
|
+
const tabIndex = node.attrs['tabindex'];
|
|
620
|
+
if (!disabled && tabIndex !== '-1') {
|
|
621
|
+
if (node.tag === 'input' && node.nsInput) {
|
|
622
|
+
out.push({ node, view: node.nsInput });
|
|
623
|
+
}
|
|
624
|
+
else if ((node.tag === 'button' || Boolean(node.handlers['click'])) && node.nsView) {
|
|
625
|
+
out.push({ node, view: node.nsView });
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
const childElements = ln.text === undefined ? collectElementChildren(node) : [];
|
|
629
|
+
for (const ch of childElements) {
|
|
630
|
+
collectFocusable(ch, out, false);
|
|
631
|
+
}
|
|
632
|
+
};
|
|
633
|
+
const wireKeyViewLoop = (root, win, allowDialog = false) => {
|
|
634
|
+
if (!win)
|
|
635
|
+
return;
|
|
636
|
+
const list = [];
|
|
637
|
+
collectFocusable(root, list, allowDialog);
|
|
638
|
+
focusOrderByWindow.set(win, list);
|
|
639
|
+
try {
|
|
640
|
+
win.autorecalculatesKeyViewLoop = false;
|
|
641
|
+
for (let i = 0; i < list.length; i++) {
|
|
642
|
+
const cur = list[i].view;
|
|
643
|
+
const next = list[(i + 1) % list.length].view;
|
|
644
|
+
cur.nextKeyView = next;
|
|
645
|
+
}
|
|
646
|
+
if (list.length > 0) {
|
|
647
|
+
const preferred = allowDialog
|
|
648
|
+
? list.find((item) => Boolean(item.node.nsInput)) ?? list[0]
|
|
649
|
+
: list[0];
|
|
650
|
+
win.initialFirstResponder = preferred.view;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
catch {
|
|
654
|
+
// Ignore
|
|
655
|
+
}
|
|
656
|
+
};
|
|
657
|
+
const isSameObjC = (a, b) => {
|
|
658
|
+
if (!a || !b)
|
|
659
|
+
return false;
|
|
660
|
+
if (a === b)
|
|
661
|
+
return true;
|
|
662
|
+
try {
|
|
663
|
+
return Boolean(a.isEqual?.(b));
|
|
664
|
+
}
|
|
665
|
+
catch {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
};
|
|
669
|
+
const getFocusListForWindow = (win) => {
|
|
670
|
+
if (!win)
|
|
671
|
+
return [];
|
|
672
|
+
const direct = focusOrderByWindow.get(win);
|
|
673
|
+
if (direct)
|
|
674
|
+
return direct;
|
|
675
|
+
for (const [k, v] of focusOrderByWindow) {
|
|
676
|
+
if (isSameObjC(k, win))
|
|
677
|
+
return v;
|
|
678
|
+
}
|
|
679
|
+
return [];
|
|
680
|
+
};
|
|
681
|
+
const findFocusedIndex = (list, win) => {
|
|
682
|
+
try {
|
|
683
|
+
const fr = win?.firstResponder;
|
|
684
|
+
if (fr) {
|
|
685
|
+
for (let i = 0; i < list.length; i++) {
|
|
686
|
+
const item = list[i];
|
|
687
|
+
if (isSameObjC(item.view, fr))
|
|
688
|
+
return i;
|
|
689
|
+
// AppKit field editor (NSTextView) has delegate or superview === NSTextField
|
|
690
|
+
if (item.node.nsInput &&
|
|
691
|
+
(isSameObjC(fr, item.node.nsInput) ||
|
|
692
|
+
isSameObjC(fr.delegate, item.node.nsInput) ||
|
|
693
|
+
isSameObjC(fr.superview, item.node.nsInput) ||
|
|
694
|
+
isSameObjC(fr.superview?.superview, item.node.nsInput))) {
|
|
695
|
+
return i;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
// Check tracked focused node for this window (covers transient field-editor states)
|
|
700
|
+
for (const [k, tracked] of focusedNodeByWindow) {
|
|
701
|
+
if (isSameObjC(k, win)) {
|
|
702
|
+
const idx = list.findIndex((item) => item.node === tracked);
|
|
703
|
+
if (idx >= 0)
|
|
704
|
+
return idx;
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
// Fallback: check our tracked _isFocused flag on outer NSView
|
|
708
|
+
for (let i = 0; i < list.length; i++) {
|
|
709
|
+
if (list[i].node.nsView?._isFocused)
|
|
710
|
+
return i;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
catch {
|
|
714
|
+
// Ignore
|
|
715
|
+
}
|
|
716
|
+
return -1;
|
|
717
|
+
};
|
|
718
|
+
const focusEntry = (win, list, nextIdx) => {
|
|
719
|
+
if (nextIdx < 0 || nextIdx >= list.length)
|
|
720
|
+
return;
|
|
721
|
+
// Clear any stale _isFocused border across the window first
|
|
722
|
+
for (const item of list) {
|
|
723
|
+
if (item.node.nsInput && item.node.nsView?._isFocused) {
|
|
724
|
+
setInputContainerFocus(item.node.nsView, false);
|
|
725
|
+
}
|
|
726
|
+
else if (item.node.nsView?._isFocused && item.node.nsView?._applyFocusVisuals) {
|
|
727
|
+
item.node.nsView._isFocused = false;
|
|
728
|
+
item.node.nsView._applyFocusVisuals(false);
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
const target = list[nextIdx];
|
|
732
|
+
focusedNodeByWindow.set(win, target.node);
|
|
733
|
+
win.makeFirstResponder(target.view);
|
|
734
|
+
if (target.node.nsInput && target.node.nsView) {
|
|
735
|
+
setInputContainerFocus(target.node.nsView, true);
|
|
736
|
+
}
|
|
737
|
+
else if (target.node.nsView?._applyFocusVisuals) {
|
|
738
|
+
target.node.nsView._isFocused = true;
|
|
739
|
+
target.node.nsView._applyFocusVisuals(true);
|
|
740
|
+
}
|
|
741
|
+
const scrollViewTarget = target.node.nsView ?? target.view;
|
|
742
|
+
scrollViewTarget?.scrollRectToVisible?.(scrollViewTarget.bounds);
|
|
743
|
+
};
|
|
744
|
+
const handleKeyEvent = (event, activeWindow) => {
|
|
745
|
+
try {
|
|
746
|
+
// NSEventTypeKeyDown = 10
|
|
747
|
+
if (Number(event?.type ?? -1) !== 10)
|
|
748
|
+
return false;
|
|
749
|
+
const code = Number(event?.keyCode ?? -1);
|
|
750
|
+
const flags = Number(event?.modifierFlags ?? 0);
|
|
751
|
+
const shift = (flags & (1 << 17)) !== 0;
|
|
752
|
+
// Prefer an open modal sheet if one is active
|
|
753
|
+
let targetWin = activeWindow;
|
|
754
|
+
let activeDlg;
|
|
755
|
+
for (const dlg of activeDialogs) {
|
|
756
|
+
if (dlg.dialogWindow) {
|
|
757
|
+
activeDlg = dlg;
|
|
758
|
+
targetWin = dlg.dialogWindow;
|
|
759
|
+
}
|
|
760
|
+
}
|
|
761
|
+
if (!targetWin)
|
|
762
|
+
targetWin = options.getHostWindow();
|
|
763
|
+
const list = getFocusListForWindow(targetWin);
|
|
764
|
+
// Escape dismisses active modal sheet
|
|
765
|
+
if (code === 53 && activeDlg) {
|
|
766
|
+
fireBubble(activeDlg, 'cancel', { cancelable: true });
|
|
767
|
+
return true;
|
|
768
|
+
}
|
|
769
|
+
// Tab / Shift+Tab advances native AppKit firstResponder along the key view loop
|
|
770
|
+
if (code === 48 && list.length > 0) {
|
|
771
|
+
const curIdx = findFocusedIndex(list, targetWin);
|
|
772
|
+
const nextIdx = curIdx < 0
|
|
773
|
+
? shift
|
|
774
|
+
? list.length - 1
|
|
775
|
+
: 0
|
|
776
|
+
: (curIdx + (shift ? -1 : 1) + list.length) % list.length;
|
|
777
|
+
focusEntry(targetWin, list, nextIdx);
|
|
778
|
+
return true;
|
|
779
|
+
}
|
|
780
|
+
// Space or Return on a focused ClickableNSView activates it
|
|
781
|
+
if (code === 49 || code === 36 || code === 76) {
|
|
782
|
+
const curIdx = findFocusedIndex(list, targetWin);
|
|
783
|
+
if (curIdx >= 0) {
|
|
784
|
+
const focused = list[curIdx];
|
|
785
|
+
if (focused.node.nsInput) {
|
|
786
|
+
// Return inside an input submits its enclosing <form>
|
|
787
|
+
if (code === 36 || code === 76) {
|
|
788
|
+
const form = findAncestorTag(focused.node, 'form');
|
|
789
|
+
if (form) {
|
|
790
|
+
fireBubble(form, 'submit', { values: collectFormValues(form) });
|
|
791
|
+
return true;
|
|
792
|
+
}
|
|
793
|
+
}
|
|
794
|
+
return false;
|
|
795
|
+
}
|
|
796
|
+
if (focused.view?._onClick) {
|
|
797
|
+
if (focused.view.layer)
|
|
798
|
+
focused.view.layer.opacity = 0.72;
|
|
799
|
+
setTimeout(() => {
|
|
800
|
+
if (focused.view.layer)
|
|
801
|
+
focused.view.layer.opacity = 1.0;
|
|
802
|
+
}, 90);
|
|
803
|
+
focused.view._onClick();
|
|
804
|
+
return true;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
catch {
|
|
810
|
+
// Ignore
|
|
811
|
+
}
|
|
812
|
+
return false;
|
|
813
|
+
};
|
|
489
814
|
const syncDialogs = (root, dark) => {
|
|
490
815
|
const foundDialogs = [];
|
|
491
816
|
const walk = (n) => {
|
|
@@ -530,6 +855,7 @@ export function makeMacosHost(options) {
|
|
|
530
855
|
panel._winDel = del;
|
|
531
856
|
syncNSViewTree(dlg, contentRoot, true);
|
|
532
857
|
dlg.dialogWindow = panel;
|
|
858
|
+
wireKeyViewLoop(dlg, panel, true);
|
|
533
859
|
const hostWin = options.getHostWindow();
|
|
534
860
|
if (hostWin) {
|
|
535
861
|
hostWin.beginSheetCompletionHandler(panel, null);
|
|
@@ -538,6 +864,12 @@ export function makeMacosHost(options) {
|
|
|
538
864
|
panel.center();
|
|
539
865
|
panel.makeKeyAndOrderFront(null);
|
|
540
866
|
}
|
|
867
|
+
// Automatically focus the first text input (or first control) inside the modal sheet
|
|
868
|
+
const dlgList = getFocusListForWindow(panel);
|
|
869
|
+
if (dlgList.length > 0) {
|
|
870
|
+
const inputIdx = dlgList.findIndex((item) => Boolean(item.node.nsInput));
|
|
871
|
+
focusEntry(panel, dlgList, inputIdx >= 0 ? inputIdx : 0);
|
|
872
|
+
}
|
|
541
873
|
}
|
|
542
874
|
else if (wantOpen && isOpen && dlg.dialogWindow) {
|
|
543
875
|
const pal = dark ? darkPalette : lightPalette;
|
|
@@ -547,16 +879,21 @@ export function makeMacosHost(options) {
|
|
|
547
879
|
const dlgH = Math.max(240, m.height + 16);
|
|
548
880
|
layoutTree(ln, 0, 0, dlgW, dlgH, measureAppKitText);
|
|
549
881
|
syncNSViewTree(dlg, dlg.dialogWindow.contentView, true);
|
|
882
|
+
wireKeyViewLoop(dlg, dlg.dialogWindow, true);
|
|
550
883
|
}
|
|
551
884
|
else if (!wantOpen && isOpen) {
|
|
552
885
|
activeDialogs.delete(dlg);
|
|
553
886
|
const panel = dlg.dialogWindow;
|
|
554
887
|
dlg.dialogWindow = undefined;
|
|
555
888
|
if (panel) {
|
|
889
|
+
focusOrderByWindow.delete(panel);
|
|
890
|
+
focusedNodeByWindow.delete(panel);
|
|
556
891
|
const hostWin = options.getHostWindow();
|
|
557
892
|
try {
|
|
558
|
-
if (hostWin)
|
|
893
|
+
if (hostWin) {
|
|
559
894
|
hostWin.endSheet(panel);
|
|
895
|
+
hostWin.makeKeyAndOrderFront(null);
|
|
896
|
+
}
|
|
560
897
|
panel.orderOut(null);
|
|
561
898
|
}
|
|
562
899
|
catch {
|
|
@@ -582,6 +919,7 @@ export function makeMacosHost(options) {
|
|
|
582
919
|
if (primary.nsView) {
|
|
583
920
|
options.attachRootView(primary.nsView, totalH);
|
|
584
921
|
}
|
|
922
|
+
wireKeyViewLoop(primary, options.getHostWindow(), false);
|
|
585
923
|
syncDialogs(rootContainer, dark);
|
|
586
924
|
};
|
|
587
925
|
const detach = (node) => {
|
|
@@ -702,6 +1040,9 @@ export function makeMacosHost(options) {
|
|
|
702
1040
|
host,
|
|
703
1041
|
rootContainer,
|
|
704
1042
|
relayout,
|
|
1043
|
+
handleKeyEvent,
|
|
1044
|
+
getFocusRingOrder: (win) => focusOrderByWindow.get(win ?? options.getHostWindow()) ?? [],
|
|
1045
|
+
getActiveDialogs: () => activeDialogs,
|
|
705
1046
|
dispose: () => {
|
|
706
1047
|
for (const dlg of activeDialogs) {
|
|
707
1048
|
try {
|
|
@@ -712,6 +1053,7 @@ export function makeMacosHost(options) {
|
|
|
712
1053
|
}
|
|
713
1054
|
}
|
|
714
1055
|
activeDialogs.clear();
|
|
1056
|
+
focusOrderByWindow.clear();
|
|
715
1057
|
},
|
|
716
1058
|
};
|
|
717
1059
|
}
|
|
@@ -844,6 +1186,23 @@ export async function run(component, props, options) {
|
|
|
844
1186
|
// Start AppKit cooperative event pump alongside Node/Bun + Effect event loop!
|
|
845
1187
|
NSApp.finishLaunching();
|
|
846
1188
|
NSApp.activateIgnoringOtherApps(true);
|
|
1189
|
+
if (options?.onReady) {
|
|
1190
|
+
options.onReady({
|
|
1191
|
+
window,
|
|
1192
|
+
macos,
|
|
1193
|
+
capture: (outputPath, targetWindow) => {
|
|
1194
|
+
macos.relayout();
|
|
1195
|
+
const target = targetWindow ?? window;
|
|
1196
|
+
target.displayIfNeeded();
|
|
1197
|
+
captureWindowToPng(target, outputPath);
|
|
1198
|
+
},
|
|
1199
|
+
exit: () => {
|
|
1200
|
+
appDelegate.running = false;
|
|
1201
|
+
macos.dispose();
|
|
1202
|
+
process.exit(0);
|
|
1203
|
+
},
|
|
1204
|
+
});
|
|
1205
|
+
}
|
|
847
1206
|
if (options?.capturePath) {
|
|
848
1207
|
const delay = options.captureDelayMs ?? 900;
|
|
849
1208
|
setTimeout(() => {
|
|
@@ -863,7 +1222,9 @@ export async function run(component, props, options) {
|
|
|
863
1222
|
null, 'kCFRunLoopDefaultMode', true);
|
|
864
1223
|
if (!ev)
|
|
865
1224
|
break;
|
|
866
|
-
|
|
1225
|
+
if (!macos.handleKeyEvent(ev, NSApp.keyWindow ?? window)) {
|
|
1226
|
+
NSApp.sendEvent(ev);
|
|
1227
|
+
}
|
|
867
1228
|
drained += 1;
|
|
868
1229
|
}
|
|
869
1230
|
NSApp.updateWindows();
|