@ng-native/components 0.22.1 → 0.23.0
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/android/build.gradle +22 -0
- package/android/src/main/java/dev/ngnative/components/ContextMenuAccessibility.kt +71 -0
- package/android/src/main/java/dev/ngnative/components/ContextMenuGesture.kt +161 -0
- package/android/src/main/java/dev/ngnative/components/ContextMenuPopup.kt +197 -0
- package/android/src/main/java/dev/ngnative/components/MenuHost.kt +45 -0
- package/android/src/main/java/dev/ngnative/components/MenuWindowCallback.kt +76 -0
- package/android/src/main/java/dev/ngnative/components/MenusModule.kt +85 -0
- package/android/src/main/java/dev/ngnative/components/Shortcut.kt +144 -0
- package/android/src/main/java/dev/ngnative/components/WindowWrapper.kt +22 -0
- package/dist/activity-indicator.d.ts +4 -1
- package/dist/activity-indicator.js +6 -2
- package/dist/activity-indicator.js.map +1 -1
- package/dist/context-menu.d.ts +52 -0
- package/dist/context-menu.js +101 -0
- package/dist/context-menu.js.map +1 -0
- package/dist/drag-and-drop.d.ts +52 -0
- package/dist/drag-and-drop.js +112 -0
- package/dist/drag-and-drop.js.map +1 -0
- package/dist/gesture-backend.d.ts +32 -2
- package/dist/gesture-backend.js.map +1 -1
- package/dist/gesture-dispatch.d.ts +8 -1
- package/dist/gesture-dispatch.js +60 -16
- package/dist/gesture-dispatch.js.map +1 -1
- package/dist/gesture-interaction.d.ts +13 -0
- package/dist/gesture-interaction.js +97 -0
- package/dist/gesture-interaction.js.map +1 -0
- package/dist/gesture-tracking.d.ts +18 -0
- package/dist/gesture-tracking.js +28 -0
- package/dist/gesture-tracking.js.map +1 -0
- package/dist/gestures-web.d.ts +3 -1
- package/dist/gestures-web.js +5 -2
- package/dist/gestures-web.js.map +1 -1
- package/dist/gestures.d.ts +1 -0
- package/dist/gestures.js +45 -3
- package/dist/gestures.js.map +1 -1
- package/dist/image.d.ts +1 -1
- package/dist/index.d.ts +12 -1
- package/dist/index.js +12 -1
- package/dist/index.js.map +1 -1
- package/dist/interaction-observer.d.ts +11 -0
- package/dist/interaction-observer.js +12 -0
- package/dist/interaction-observer.js.map +1 -0
- package/dist/keyboard-avoiding-view.js +3 -3
- package/dist/keyboard-avoiding-view.js.map +1 -1
- package/dist/markdown-stream.d.ts +3 -1
- package/dist/markdown-stream.js +14 -2
- package/dist/markdown-stream.js.map +1 -1
- package/dist/markdown.d.ts +2 -0
- package/dist/markdown.js +5 -3
- package/dist/markdown.js.map +1 -1
- package/dist/menu.d.ts +71 -0
- package/dist/menu.js +193 -0
- package/dist/menu.js.map +1 -0
- package/dist/modal.d.ts +30 -1
- package/dist/modal.js +67 -6
- package/dist/modal.js.map +1 -1
- package/dist/native-button.d.ts +54 -0
- package/dist/native-button.js +100 -0
- package/dist/native-button.js.map +1 -0
- package/dist/native-gesture.d.ts +9 -1
- package/dist/native-gesture.js +32 -3
- package/dist/native-gesture.js.map +1 -1
- package/dist/native-id.d.ts +10 -0
- package/dist/native-id.js +70 -0
- package/dist/native-id.js.map +1 -0
- package/dist/pressable.d.ts +31 -0
- package/dist/pressable.js +102 -9
- package/dist/pressable.js.map +1 -1
- package/dist/safe-area-provider.js +15 -8
- package/dist/safe-area-provider.js.map +1 -1
- package/dist/scroll-view-props.d.ts +7 -1
- package/dist/scroll-view-props.js +54 -3
- package/dist/scroll-view-props.js.map +1 -1
- package/dist/section-list.js +2 -2
- package/dist/section-list.js.map +1 -1
- package/dist/shortcut.d.ts +21 -0
- package/dist/shortcut.js +34 -0
- package/dist/shortcut.js.map +1 -0
- package/dist/sidebar-item.d.ts +53 -0
- package/dist/sidebar-item.js +152 -0
- package/dist/sidebar-item.js.map +1 -0
- package/dist/sidebar-section.d.ts +21 -0
- package/dist/sidebar-section.js +74 -0
- package/dist/sidebar-section.js.map +1 -0
- package/dist/sidebar.d.ts +47 -0
- package/dist/sidebar.js +110 -0
- package/dist/sidebar.js.map +1 -0
- package/dist/split-view.d.ts +63 -0
- package/dist/split-view.js +121 -0
- package/dist/split-view.js.map +1 -0
- package/dist/switch.d.ts +9 -1
- package/dist/switch.js +23 -2
- package/dist/switch.js.map +1 -1
- package/dist/text-input.d.ts +8 -3
- package/dist/text-input.js +10 -4
- package/dist/text-input.js.map +1 -1
- package/dist/transforms.d.ts +7 -0
- package/dist/transforms.js +12 -3
- package/dist/transforms.js.map +1 -1
- package/dist/tray-icon.d.ts +18 -0
- package/dist/tray-icon.js +46 -0
- package/dist/tray-icon.js.map +1 -0
- package/dist/view-base.d.ts +42 -1
- package/dist/view-base.js +67 -39
- package/dist/view-base.js.map +1 -1
- package/dist/virtual-list.js +12 -1
- package/dist/virtual-list.js.map +1 -1
- package/dist/written-props.js +25 -0
- package/dist/written-props.js.map +1 -1
- package/expo-module.config.json +6 -0
- package/ios/NgNativeButtonComponentView.mm +132 -0
- package/ios/NgNativeButtonMetrics.h +28 -0
- package/ios/NgNativeButtonMetrics.mm +68 -0
- package/ios/NgNativeButtonShadowNode.h +65 -0
- package/ios/NgNativeButtonShadowNode.mm +40 -0
- package/ios/NgNativeComponents.podspec +28 -0
- package/ios/NgNativeDragAndDrop.mm +342 -0
- package/ios/NgNativeDropItems.h +29 -0
- package/ios/NgNativeDropItems.mm +55 -0
- package/ios/NgNativeMenuBuilding.h +40 -0
- package/ios/NgNativeMenuBuilding.mm +217 -0
- package/ios/NgNativeMenus.mm +320 -0
- package/ios/NgNativeResponderHooks.h +53 -0
- package/ios/NgNativeResponderHooks.mm +215 -0
- package/ios/NgNativeSceneKeys.h +36 -0
- package/ios/NgNativeSceneKeys.mm +56 -0
- package/ios/NgNativeSplitView.mm +433 -0
- package/ios/NgNativeSplitViewDelegate.h +29 -0
- package/ios/NgNativeSplitViewDelegate.mm +122 -0
- package/ios/NgNativeSplitViewShadowNodes.h +115 -0
- package/ios/NgNativeSplitViewShadowNodes.mm +31 -0
- package/ios/NgNativeUndo.mm +107 -0
- package/ios/NgNativeUndoSteps.h +17 -0
- package/ios/NgNativeUndoSteps.mm +22 -0
- package/ios/NgNativeViewBinder.h +54 -0
- package/ios/NgNativeViewBinder.mm +225 -0
- package/ios/NgNativeWindows.mm +1126 -0
- package/package.json +13 -5
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
package dev.ngnative.components
|
|
2
|
+
|
|
3
|
+
import android.view.KeyEvent
|
|
4
|
+
import android.view.KeyboardShortcutGroup
|
|
5
|
+
import android.view.KeyboardShortcutInfo
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A shortcut as `Menus` sends it: its `id`, its chord read for Android (`mod` is Ctrl), and the
|
|
9
|
+
* `label` and `group` the Keyboard Shortcuts helper lists it under.
|
|
10
|
+
*/
|
|
11
|
+
internal class Shortcut(
|
|
12
|
+
val id: String,
|
|
13
|
+
/** The key as `KeyboardEvent.key` names it: `k` lower case, `,`, `ArrowLeft`, `Enter`. */
|
|
14
|
+
val key: String,
|
|
15
|
+
val ctrl: Boolean,
|
|
16
|
+
val meta: Boolean,
|
|
17
|
+
val alt: Boolean,
|
|
18
|
+
val shift: Boolean,
|
|
19
|
+
val label: String,
|
|
20
|
+
val group: String,
|
|
21
|
+
) {
|
|
22
|
+
/** Whether `event` is this chord: the same key, and exactly these modifiers. */
|
|
23
|
+
fun matches(event: KeyEvent): Boolean =
|
|
24
|
+
matches(
|
|
25
|
+
keyName(event),
|
|
26
|
+
shiftedName(event),
|
|
27
|
+
event.isCtrlPressed,
|
|
28
|
+
event.isMetaPressed,
|
|
29
|
+
event.isAltPressed,
|
|
30
|
+
event.isShiftPressed,
|
|
31
|
+
)
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether a key `pressed` (as `keyName` names it) is this chord with these modifiers held.
|
|
35
|
+
* `shifted` is the character the key types with Shift, while Shift is held.
|
|
36
|
+
*/
|
|
37
|
+
fun matches(
|
|
38
|
+
pressed: String?,
|
|
39
|
+
shifted: String?,
|
|
40
|
+
ctrl: Boolean,
|
|
41
|
+
meta: Boolean,
|
|
42
|
+
alt: Boolean,
|
|
43
|
+
shift: Boolean,
|
|
44
|
+
): Boolean {
|
|
45
|
+
if (pressed == null || ctrl != this.ctrl || meta != this.meta || alt != this.alt) return false
|
|
46
|
+
if (pressed.equals(normalKey, ignoreCase = key.length > 1)) return shift == this.shift
|
|
47
|
+
// `KeyboardEvent.key` names the shifted character, so `mod+?` is Ctrl-Shift-/, and so is
|
|
48
|
+
// `mod+shift+?`, which names the Shift too.
|
|
49
|
+
return shift && shifted == normalKey
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** `Space` and `Spacebar` are the space key, as `KeyboardEvent.key` has it. */
|
|
53
|
+
private val normalKey: String =
|
|
54
|
+
if (key.equals("space", true) || key.equals("spacebar", true)) " " else key
|
|
55
|
+
|
|
56
|
+
/** The row in the Keyboard Shortcuts helper, or null for a key it has no way to show. */
|
|
57
|
+
fun info(): KeyboardShortcutInfo? {
|
|
58
|
+
val modifiers = (if (ctrl) KeyEvent.META_CTRL_ON else 0) or
|
|
59
|
+
(if (meta) KeyEvent.META_META_ON else 0) or
|
|
60
|
+
(if (alt) KeyEvent.META_ALT_ON else 0) or
|
|
61
|
+
(if (shift) KeyEvent.META_SHIFT_ON else 0)
|
|
62
|
+
val code = keyCode()
|
|
63
|
+
if (code != null) return KeyboardShortcutInfo(label, code, modifiers)
|
|
64
|
+
return KeyboardShortcutInfo(label, helperChar() ?: return null, modifiers)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The key code of a key `KeyboardEvent.key` names with a word, or null. */
|
|
68
|
+
fun keyCode(): Int? = NAMED.entries.firstOrNull { it.value.equals(normalKey, true) }?.key
|
|
69
|
+
|
|
70
|
+
/** The character the helper shows for a key with no key code, or null for a word it lacks. */
|
|
71
|
+
fun helperChar(): Char? = normalKey.singleOrNull()?.uppercaseChar()
|
|
72
|
+
|
|
73
|
+
companion object {
|
|
74
|
+
/** A shortcut from what `setShortcuts` was given, or null for one with no key. */
|
|
75
|
+
fun from(sent: Map<String, Any?>): Shortcut? {
|
|
76
|
+
val chord = sent["chord"] as? Map<*, *> ?: return null
|
|
77
|
+
val key = chord["key"] as? String ?: return null
|
|
78
|
+
if (key.isEmpty()) return null
|
|
79
|
+
return Shortcut(
|
|
80
|
+
id = sent["id"] as? String ?: return null,
|
|
81
|
+
key = key,
|
|
82
|
+
ctrl = chord["ctrl"] == true,
|
|
83
|
+
meta = chord["meta"] == true,
|
|
84
|
+
alt = chord["alt"] == true,
|
|
85
|
+
shift = chord["shift"] == true,
|
|
86
|
+
label = sent["label"] as? String ?: "",
|
|
87
|
+
group = sent["group"] as? String ?: "",
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* The keys `KeyboardEvent.key` names with a word, by their key code. Android has no key past
|
|
93
|
+
* F12, so a shortcut on F13 and up never fires here and the helper does not list it.
|
|
94
|
+
*/
|
|
95
|
+
private val NAMED: Map<Int, String> = buildMap {
|
|
96
|
+
put(KeyEvent.KEYCODE_DPAD_LEFT, "ArrowLeft")
|
|
97
|
+
put(KeyEvent.KEYCODE_DPAD_RIGHT, "ArrowRight")
|
|
98
|
+
put(KeyEvent.KEYCODE_DPAD_UP, "ArrowUp")
|
|
99
|
+
put(KeyEvent.KEYCODE_DPAD_DOWN, "ArrowDown")
|
|
100
|
+
put(KeyEvent.KEYCODE_ENTER, "Enter")
|
|
101
|
+
put(KeyEvent.KEYCODE_NUMPAD_ENTER, "Enter")
|
|
102
|
+
put(KeyEvent.KEYCODE_ESCAPE, "Escape")
|
|
103
|
+
put(KeyEvent.KEYCODE_DEL, "Backspace")
|
|
104
|
+
put(KeyEvent.KEYCODE_FORWARD_DEL, "Delete")
|
|
105
|
+
put(KeyEvent.KEYCODE_TAB, "Tab")
|
|
106
|
+
put(KeyEvent.KEYCODE_SPACE, " ")
|
|
107
|
+
put(KeyEvent.KEYCODE_MOVE_HOME, "Home")
|
|
108
|
+
put(KeyEvent.KEYCODE_MOVE_END, "End")
|
|
109
|
+
put(KeyEvent.KEYCODE_PAGE_UP, "PageUp")
|
|
110
|
+
put(KeyEvent.KEYCODE_PAGE_DOWN, "PageDown")
|
|
111
|
+
put(KeyEvent.KEYCODE_INSERT, "Insert")
|
|
112
|
+
put(KeyEvent.KEYCODE_BREAK, "Pause")
|
|
113
|
+
put(KeyEvent.KEYCODE_SCROLL_LOCK, "ScrollLock")
|
|
114
|
+
put(KeyEvent.KEYCODE_MENU, "ContextMenu")
|
|
115
|
+
for (n in 1..12) put(KeyEvent.KEYCODE_F1 + n - 1, "F$n")
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/** The key `event` is, as `KeyboardEvent.key` names it, ignoring Shift: `k`, `,`, `Enter`. */
|
|
119
|
+
fun keyName(event: KeyEvent): String? {
|
|
120
|
+
nameOf(event.keyCode)?.let { return it }
|
|
121
|
+
val char = event.getUnicodeChar(0)
|
|
122
|
+
if (char <= 0) return null
|
|
123
|
+
return char.toChar().lowercase()
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The word `KeyboardEvent.key` names the key with `keyCode` by, or null for a character. */
|
|
127
|
+
fun nameOf(keyCode: Int): String? = NAMED[keyCode]
|
|
128
|
+
|
|
129
|
+
/** The character `event`'s key types with Shift, while Shift is held, or null. */
|
|
130
|
+
private fun shiftedName(event: KeyEvent): String? {
|
|
131
|
+
if (!event.isShiftPressed) return null
|
|
132
|
+
val char = event.getUnicodeChar(event.metaState and KeyEvent.META_SHIFT_MASK)
|
|
133
|
+
return if (char > 0) char.toChar().toString() else null
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** The helper's groups: each group's shortcuts under its name, in the order sent. */
|
|
137
|
+
fun groups(shortcuts: List<Shortcut>): List<KeyboardShortcutGroup> =
|
|
138
|
+
shortcuts
|
|
139
|
+
.groupBy { it.group }
|
|
140
|
+
.mapNotNull { (group, list) ->
|
|
141
|
+
list.mapNotNull(Shortcut::info).takeIf { it.isNotEmpty() }?.let { KeyboardShortcutGroup(group, it) }
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
package dev.ngnative.components
|
|
2
|
+
|
|
3
|
+
import java.util.Collections
|
|
4
|
+
import java.util.WeakHashMap
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Puts a wrapper on each window's callback once. On the main thread only.
|
|
8
|
+
*
|
|
9
|
+
* Whether a window has the wrapper is kept by window, not read from the top of its callback chain:
|
|
10
|
+
* a library that wraps the callback on resume and unwraps it on pause only while it is on top
|
|
11
|
+
* (some crash and analytics SDKs do this) leaves ours under its own, and a check of the top would
|
|
12
|
+
* wrap the window again on every resume.
|
|
13
|
+
*/
|
|
14
|
+
internal class WindowWrapper<W : Any> {
|
|
15
|
+
private val wrapped: MutableSet<W> = Collections.newSetFromMap(WeakHashMap())
|
|
16
|
+
|
|
17
|
+
/** Wrap `window`'s `callback` with `wrap` and `set` the result, the first time only. */
|
|
18
|
+
fun <C : Any> wrapOnce(window: W, callback: C?, wrap: (C) -> C, set: (C) -> Unit) {
|
|
19
|
+
if (callback == null || !wrapped.add(window)) return
|
|
20
|
+
set(wrap(callback))
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ControlSize } from '@ng-native/device';
|
|
1
2
|
import { ViewBase } from './view-base.ts';
|
|
2
3
|
import * as i0 from "@angular/core";
|
|
3
4
|
/**
|
|
@@ -11,6 +12,8 @@ import * as i0 from "@angular/core";
|
|
|
11
12
|
export declare class ActivityIndicator extends ViewBase {
|
|
12
13
|
/** `small` and `large` match RN's 20 and 36 points; a number sets both dimensions. */
|
|
13
14
|
readonly size: import("@angular/core").InputSignal<number | "small" | "large">;
|
|
15
|
+
/** AppKit's control size on macOS, and UIKit's on iOS 26 and later. Ignored elsewhere. */
|
|
16
|
+
readonly controlSize: import("@angular/core").InputSignal<ControlSize | undefined>;
|
|
14
17
|
/** Whether the spinner turns. Defaults to true. */
|
|
15
18
|
readonly animating: import("@angular/core").InputSignalWithTransform<boolean | undefined, unknown>;
|
|
16
19
|
/** The spinner's colour. */
|
|
@@ -37,5 +40,5 @@ export declare class ActivityIndicator extends ViewBase {
|
|
|
37
40
|
height: number;
|
|
38
41
|
}>;
|
|
39
42
|
static ɵfac: i0.ɵɵFactoryDeclaration<ActivityIndicator, never>;
|
|
40
|
-
static ɵdir: i0.ɵɵDirectiveDeclaration<ActivityIndicator, "activity-indicator", never, { "size": { "alias": "size"; "required": false; "isSignal": true; }; "animating": { "alias": "animating"; "required": false; "isSignal": true; }; "color": { "alias": "color"; "required": false; "isSignal": true; }; "hidesWhenStopped": { "alias": "hidesWhenStopped"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
43
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<ActivityIndicator, "activity-indicator", never, { "size": { "alias": "size"; "required": false; "isSignal": true; }; "controlSize": { "alias": "controlSize"; "required": false; "isSignal": true; }; "animating": { "alias": "animating"; "required": false; "isSignal": true; }; "color": { "alias": "color"; "required": false; "isSignal": true; }; "hidesWhenStopped": { "alias": "hidesWhenStopped"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
41
44
|
}
|
|
@@ -15,6 +15,9 @@ export class ActivityIndicator extends ViewBase {
|
|
|
15
15
|
/** `small` and `large` match RN's 20 and 36 points; a number sets both dimensions. */
|
|
16
16
|
size = input('small', /* @ts-ignore */
|
|
17
17
|
...(ngDevMode ? [{ debugName: "size" }] : /* istanbul ignore next */ []));
|
|
18
|
+
/** AppKit's control size on macOS, and UIKit's on iOS 26 and later. Ignored elsewhere. */
|
|
19
|
+
controlSize = input(/* @ts-ignore */
|
|
20
|
+
...(ngDevMode ? [undefined, { debugName: "controlSize" }] : /* istanbul ignore next */ []));
|
|
18
21
|
/** Whether the spinner turns. Defaults to true. */
|
|
19
22
|
animating = input(undefined, { ...(ngDevMode ? { debugName: "animating" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
|
|
20
23
|
/** The spinner's colour. */
|
|
@@ -46,7 +49,7 @@ export class ActivityIndicator extends ViewBase {
|
|
|
46
49
|
}, /* @ts-ignore */
|
|
47
50
|
...(ngDevMode ? [{ debugName: "sizeStyle" }] : /* istanbul ignore next */ []));
|
|
48
51
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityIndicator, deps: null, target: i0.ɵɵFactoryTarget.Directive });
|
|
49
|
-
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: ActivityIndicator, isStandalone: true, selector: "activity-indicator", inputs: { size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, animating: { classPropertyName: "animating", publicName: "animating", isSignal: true, isRequired: false, transformFunction: null }, color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: false, transformFunction: null }, hidesWhenStopped: { classPropertyName: "hidesWhenStopped", publicName: "hidesWhenStopped", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style": "sizeStyle()", "size": "nativeSize()", "animating": "animating()", "color": "color()", "hidesWhenStopped": "hidesWhenStopped()", "styleAttr": "styleAttr", "indeterminate": "indeterminate" } }, usesInheritance: true, ngImport: i0 });
|
|
52
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: ActivityIndicator, isStandalone: true, selector: "activity-indicator", inputs: { size: { classPropertyName: "size", publicName: "size", isSignal: true, isRequired: false, transformFunction: null }, controlSize: { classPropertyName: "controlSize", publicName: "controlSize", isSignal: true, isRequired: false, transformFunction: null }, animating: { classPropertyName: "animating", publicName: "animating", isSignal: true, isRequired: false, transformFunction: null }, color: { classPropertyName: "color", publicName: "color", isSignal: true, isRequired: false, transformFunction: null }, hidesWhenStopped: { classPropertyName: "hidesWhenStopped", publicName: "hidesWhenStopped", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style": "sizeStyle()", "size": "nativeSize()", "controlSize": "controlSize()", "animating": "animating()", "color": "color()", "hidesWhenStopped": "hidesWhenStopped()", "styleAttr": "styleAttr", "indeterminate": "indeterminate" } }, usesInheritance: true, ngImport: i0 });
|
|
50
53
|
}
|
|
51
54
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ActivityIndicator, decorators: [{
|
|
52
55
|
type: Directive,
|
|
@@ -55,6 +58,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
55
58
|
host: {
|
|
56
59
|
'[style]': 'sizeStyle()',
|
|
57
60
|
'[size]': 'nativeSize()',
|
|
61
|
+
'[controlSize]': 'controlSize()',
|
|
58
62
|
'[animating]': 'animating()',
|
|
59
63
|
'[color]': 'color()',
|
|
60
64
|
'[hidesWhenStopped]': 'hidesWhenStopped()',
|
|
@@ -62,5 +66,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
62
66
|
'[indeterminate]': 'indeterminate',
|
|
63
67
|
},
|
|
64
68
|
}]
|
|
65
|
-
}], propDecorators: { size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], animating: [{ type: i0.Input, args: [{ isSignal: true, alias: "animating", required: false }] }], color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: false }] }], hidesWhenStopped: [{ type: i0.Input, args: [{ isSignal: true, alias: "hidesWhenStopped", required: false }] }] } });
|
|
69
|
+
}], propDecorators: { size: [{ type: i0.Input, args: [{ isSignal: true, alias: "size", required: false }] }], controlSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlSize", required: false }] }], animating: [{ type: i0.Input, args: [{ isSignal: true, alias: "animating", required: false }] }], color: [{ type: i0.Input, args: [{ isSignal: true, alias: "color", required: false }] }], hidesWhenStopped: [{ type: i0.Input, args: [{ isSignal: true, alias: "hidesWhenStopped", required: false }] }] } });
|
|
66
70
|
//# sourceMappingURL=activity-indicator.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"activity-indicator.js","sourceRoot":"","sources":["../src/activity-indicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"activity-indicator.js","sourceRoot":"","sources":["../src/activity-indicator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;;AAE1C;;;;;;;GAOG;AAcH,MAAM,OAAO,iBAAkB,SAAQ,QAAQ;IAC7C,sFAAsF;IAC7E,IAAI,GAAG,KAAK,CAA6B,OAAO;6EAAC,CAAC;IAC3D,0FAA0F;IACjF,WAAW,GAAG,KAAK;+FAAe,CAAC;IAC5C,mDAAmD;IAC1C,SAAS,GAAG,KAAK,CAAC,SAAS,iFAAI,SAAS,EAAE,eAAe,GAAG,CAAC;IACtE,4BAA4B;IACnB,KAAK,GAAG,KAAK;yFAAU,CAAC;IACjC,oFAAoF;IAC3E,gBAAgB,GAAG,KAAK,CAAC,SAAS,wFAAI,SAAS,EAAE,eAAe,GAAG,CAAC;IAE1D,UAAU,GAAG,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC;mFAAC,CAAC;IAE9F;;;;;;;;;;;OAWG;IACgB,SAAS,GAAG,cAAc,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC;IAClE,aAAa,GAAG,cAAc,EAAE,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IAElE,SAAS,GAAG,QAAQ,CAAC,GAAG,EAAE;QAC3C,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,IAAI,OAAO,IAAI,KAAK,QAAQ;YAAE,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC;QACnE,OAAO,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC;IAClF,CAAC;kFAAC,CAAC;uGAjCQ,iBAAiB;2FAAjB,iBAAiB;;2FAAjB,iBAAiB;kBAb7B,SAAS;mBAAC;oBACT,QAAQ,EAAE,oBAAoB;oBAC9B,IAAI,EAAE;wBACJ,SAAS,EAAE,aAAa;wBACxB,QAAQ,EAAE,cAAc;wBACxB,eAAe,EAAE,eAAe;wBAChC,aAAa,EAAE,aAAa;wBAC5B,SAAS,EAAE,SAAS;wBACpB,oBAAoB,EAAE,oBAAoB;wBAC1C,aAAa,EAAE,WAAW;wBAC1B,iBAAiB,EAAE,eAAe;qBACnC;iBACF","sourcesContent":["import { Directive, computed, input } from '@angular/core';\nimport { nativePlatform } from '@ng-native/fabric';\nimport type { ControlSize } from '@ng-native/device';\nimport { optionalBoolean } from './transforms.ts';\nimport { ViewBase } from './view-base.ts';\n\n/**\n * A spinner. Commits as `ActivityIndicatorView` on iOS and `AndroidProgressBar` on Android.\n *\n * RN's wrapper gives the native view an explicit size: the native component has no intrinsic\n * dimensions, so without one it stretches to fill whatever space its parent offers. That\n * failure is invisible, since the spinner still draws at its natural size in the middle of the\n * stretched box, but the box swallows gestures across its whole width.\n */\n@Directive({\n selector: 'activity-indicator',\n host: {\n '[style]': 'sizeStyle()',\n '[size]': 'nativeSize()',\n '[controlSize]': 'controlSize()',\n '[animating]': 'animating()',\n '[color]': 'color()',\n '[hidesWhenStopped]': 'hidesWhenStopped()',\n '[styleAttr]': 'styleAttr',\n '[indeterminate]': 'indeterminate',\n },\n})\nexport class ActivityIndicator extends ViewBase {\n /** `small` and `large` match RN's 20 and 36 points; a number sets both dimensions. */\n readonly size = input<'small' | 'large' | number>('small');\n /** AppKit's control size on macOS, and UIKit's on iOS 26 and later. Ignored elsewhere. */\n readonly controlSize = input<ControlSize>();\n /** Whether the spinner turns. Defaults to true. */\n readonly animating = input(undefined, { transform: optionalBoolean });\n /** The spinner's colour. */\n readonly color = input<string>();\n /** iOS: hide the spinner when `animating` is false rather than showing it still. */\n readonly hidesWhenStopped = input(undefined, { transform: optionalBoolean });\n\n protected readonly nativeSize = computed(() => (this.size() === 'large' ? 'large' : 'small'));\n\n /**\n * Android only, and not optional there.\n *\n * `AndroidProgressBar` picks its drawable from `styleAttr`, and has no default: the native view\n * throws `setStyle() not called` out of its own update pass if the first commit arrives without\n * one, which takes the whole screen down. RN's wrapper sends `Normal` for every size and lets\n * the box above do the sizing, so this sends the same rather than mapping `large` onto\n * `progressBarStyleLarge` and diverging. `indeterminate` is required by the same spec.\n *\n * Both stay `undefined` on iOS, where `ActivityIndicatorView` has neither prop and an undefined\n * input never reaches native.\n */\n protected readonly styleAttr = nativePlatform() === 'android' ? 'Normal' : undefined;\n protected readonly indeterminate = nativePlatform() === 'android' ? true : undefined;\n\n protected readonly sizeStyle = computed(() => {\n const size = this.size();\n if (typeof size === 'number') return { width: size, height: size };\n return size === 'large' ? { width: 36, height: 36 } : { width: 20, height: 20 };\n });\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { InjectionToken, type TemplateRef } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/**
|
|
4
|
+
* The `[contextMenu]` on an element, for `<pressable>`: where a long press opens the menu,
|
|
5
|
+
* `(longPress)` does not also fire.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CONTEXT_MENU: InjectionToken<{
|
|
8
|
+
takesLongPress(): boolean;
|
|
9
|
+
}>;
|
|
10
|
+
/**
|
|
11
|
+
* A context menu on an element: `[contextMenu]="menu"`, with `<ng-template #menu>` holding
|
|
12
|
+
* `<menu-item>`s. A right-click opens it on macOS. On Android a long press or a right-click opens
|
|
13
|
+
* it as a PopupMenu at the press point, and on iOS and iPadOS a long press, or a secondary click
|
|
14
|
+
* from an iPad pointer, opens it through UIContextMenuInteraction. On Android and iOS that takes
|
|
15
|
+
* the `NgNativeMenus` module, which Expo Go lacks, and where it is there `(longPress)` does not
|
|
16
|
+
* also fire. On Android a `(longPress)` on a view inside the element keeps its long press, which
|
|
17
|
+
* then opens no menu: the innermost handler wins.
|
|
18
|
+
*
|
|
19
|
+
* The host contract: the view takes a `contextMenu` prop, the menu as `serializeMenu` makes it
|
|
20
|
+
* (null to take it away), and sends `topContextMenuSelect` with the chosen item's `id`. React
|
|
21
|
+
* Native's Android and iOS views drop a prop they do not know, so there the menu goes through
|
|
22
|
+
* `Menus.setContextMenu` by the view's `nativeID`, and an element without one is given one. iOS's
|
|
23
|
+
* module sends the choice, which reaches the element as `topContextMenuSelect`.
|
|
24
|
+
*/
|
|
25
|
+
export declare class ContextMenu {
|
|
26
|
+
readonly contextMenu: import("@angular/core").InputSignal<TemplateRef<unknown> | null | undefined>;
|
|
27
|
+
private readonly node;
|
|
28
|
+
private readonly engine;
|
|
29
|
+
private readonly injector;
|
|
30
|
+
private readonly os;
|
|
31
|
+
private readonly menus;
|
|
32
|
+
/** Android's and iOS's hosts, which take the menu by `nativeID` and draw it on a long press. */
|
|
33
|
+
private readonly byNativeId;
|
|
34
|
+
private readonly sender;
|
|
35
|
+
private readonly built;
|
|
36
|
+
private readonly menu;
|
|
37
|
+
/** The entries to send, or null where they show no item: only separators and empty sections. */
|
|
38
|
+
private readonly sent;
|
|
39
|
+
constructor();
|
|
40
|
+
/** Whether a long press opens this menu now, so `(longPress)` does not also fire. */
|
|
41
|
+
takesLongPress(): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Send the menu to the host under the view's `nativeID`. On iOS the choice comes back by that
|
|
44
|
+
* name, and runs as the view's own `topContextMenuSelect` would.
|
|
45
|
+
*/
|
|
46
|
+
private sendByNativeId;
|
|
47
|
+
private choose;
|
|
48
|
+
/** Make the template's items, which register with the menu this element sends. */
|
|
49
|
+
private build;
|
|
50
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<ContextMenu, never>;
|
|
51
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<ContextMenu, "[contextMenu]", never, { "contextMenu": { "alias": "contextMenu"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { DestroyRef, Directive, ElementRef, InjectionToken, Injector, computed, effect, forwardRef, inject, input, signal, untracked, } from '@angular/core';
|
|
2
|
+
import { Menus, OS, buildMenuTemplate, serializeMenu, } from '@ng-native/device';
|
|
3
|
+
import { HostEngine } from '@ng-native/fabric';
|
|
4
|
+
import { byNativeId } from "./native-id.js";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/**
|
|
7
|
+
* The `[contextMenu]` on an element, for `<pressable>`: where a long press opens the menu,
|
|
8
|
+
* `(longPress)` does not also fire.
|
|
9
|
+
*/
|
|
10
|
+
export const CONTEXT_MENU = new InjectionToken('angular-native.contextMenu');
|
|
11
|
+
/**
|
|
12
|
+
* A context menu on an element: `[contextMenu]="menu"`, with `<ng-template #menu>` holding
|
|
13
|
+
* `<menu-item>`s. A right-click opens it on macOS. On Android a long press or a right-click opens
|
|
14
|
+
* it as a PopupMenu at the press point, and on iOS and iPadOS a long press, or a secondary click
|
|
15
|
+
* from an iPad pointer, opens it through UIContextMenuInteraction. On Android and iOS that takes
|
|
16
|
+
* the `NgNativeMenus` module, which Expo Go lacks, and where it is there `(longPress)` does not
|
|
17
|
+
* also fire. On Android a `(longPress)` on a view inside the element keeps its long press, which
|
|
18
|
+
* then opens no menu: the innermost handler wins.
|
|
19
|
+
*
|
|
20
|
+
* The host contract: the view takes a `contextMenu` prop, the menu as `serializeMenu` makes it
|
|
21
|
+
* (null to take it away), and sends `topContextMenuSelect` with the chosen item's `id`. React
|
|
22
|
+
* Native's Android and iOS views drop a prop they do not know, so there the menu goes through
|
|
23
|
+
* `Menus.setContextMenu` by the view's `nativeID`, and an element without one is given one. iOS's
|
|
24
|
+
* module sends the choice, which reaches the element as `topContextMenuSelect`.
|
|
25
|
+
*/
|
|
26
|
+
export class ContextMenu {
|
|
27
|
+
contextMenu = input(/* @ts-ignore */
|
|
28
|
+
...(ngDevMode ? [undefined, { debugName: "contextMenu" }] : /* istanbul ignore next */ []));
|
|
29
|
+
node = inject(ElementRef).nativeElement;
|
|
30
|
+
engine = inject(HostEngine);
|
|
31
|
+
injector = inject(Injector);
|
|
32
|
+
os = inject(OS);
|
|
33
|
+
menus = inject(Menus);
|
|
34
|
+
/** Android's and iOS's hosts, which take the menu by `nativeID` and draw it on a long press. */
|
|
35
|
+
byNativeId = (this.os === 'android' || this.os === 'ios') && this.menus.contextMenuByNativeId;
|
|
36
|
+
sender = this.byNativeId
|
|
37
|
+
? byNativeId(this.engine, this.node, (nativeID) => this.sendByNativeId(nativeID), (nativeID) => this.menus.setContextMenu(nativeID, null))
|
|
38
|
+
: null;
|
|
39
|
+
built = signal(null, /* @ts-ignore */
|
|
40
|
+
...(ngDevMode ? [{ debugName: "built" }] : /* istanbul ignore next */ []));
|
|
41
|
+
menu = computed(() => serializeMenu(this.built()?.model.entries() ?? [], this.os), /* @ts-ignore */
|
|
42
|
+
...(ngDevMode ? [{ debugName: "menu" }] : /* istanbul ignore next */ []));
|
|
43
|
+
/** The entries to send, or null where they show no item: only separators and empty sections. */
|
|
44
|
+
sent = computed(() => {
|
|
45
|
+
const { entries } = this.menu();
|
|
46
|
+
return showsAnItem(entries) ? entries : null;
|
|
47
|
+
}, /* @ts-ignore */
|
|
48
|
+
...(ngDevMode ? [{ debugName: "sent" }] : /* istanbul ignore next */ []));
|
|
49
|
+
constructor() {
|
|
50
|
+
effect(() => this.build(this.contextMenu() ?? null));
|
|
51
|
+
effect(() => {
|
|
52
|
+
this.engine.setProp(this.node, 'contextMenu', this.sent());
|
|
53
|
+
this.sender?.();
|
|
54
|
+
});
|
|
55
|
+
const stop = this.engine.setEventListener(this.node, 'topContextMenuSelect', (event) => {
|
|
56
|
+
const id = event.nativeEvent?.id;
|
|
57
|
+
if (id !== undefined)
|
|
58
|
+
this.choose(id);
|
|
59
|
+
});
|
|
60
|
+
inject(DestroyRef).onDestroy(() => {
|
|
61
|
+
stop();
|
|
62
|
+
this.build(null);
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/** Whether a long press opens this menu now, so `(longPress)` does not also fire. */
|
|
66
|
+
takesLongPress() {
|
|
67
|
+
return this.byNativeId && this.sent() !== null;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Send the menu to the host under the view's `nativeID`. On iOS the choice comes back by that
|
|
71
|
+
* name, and runs as the view's own `topContextMenuSelect` would.
|
|
72
|
+
*/
|
|
73
|
+
sendByNativeId(nativeID) {
|
|
74
|
+
this.menus.setContextMenu(nativeID, untracked(this.sent), (id) => this.choose(id));
|
|
75
|
+
}
|
|
76
|
+
choose(id) {
|
|
77
|
+
this.menu().actions.get(id)?.();
|
|
78
|
+
}
|
|
79
|
+
/** Make the template's items, which register with the menu this element sends. */
|
|
80
|
+
build(template) {
|
|
81
|
+
// Read and written outside the effect that calls this, which would otherwise run again.
|
|
82
|
+
untracked(() => {
|
|
83
|
+
this.built()?.destroy();
|
|
84
|
+
this.built.set(template ? buildMenuTemplate(template, this.injector) : null);
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ContextMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
88
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: ContextMenu, isStandalone: true, selector: "[contextMenu]", inputs: { contextMenu: { classPropertyName: "contextMenu", publicName: "contextMenu", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: CONTEXT_MENU, useExisting: forwardRef(() => ContextMenu) }], ngImport: i0 });
|
|
89
|
+
}
|
|
90
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: ContextMenu, decorators: [{
|
|
91
|
+
type: Directive,
|
|
92
|
+
args: [{
|
|
93
|
+
selector: '[contextMenu]',
|
|
94
|
+
providers: [{ provide: CONTEXT_MENU, useExisting: forwardRef(() => ContextMenu) }],
|
|
95
|
+
}]
|
|
96
|
+
}], ctorParameters: () => [], propDecorators: { contextMenu: [{ type: i0.Input, args: [{ isSignal: true, alias: "contextMenu", required: false }] }] } });
|
|
97
|
+
/** Whether `entries` show an item: one that is not a separator, nor a section with none. */
|
|
98
|
+
function showsAnItem(entries) {
|
|
99
|
+
return entries.some((entry) => !('separator' in entry) && (!entry.inline || showsAnItem(entry.items ?? [])));
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=context-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-menu.js","sourceRoot":"","sources":["../src/context-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,KAAK,EACL,EAAE,EACF,iBAAiB,EACjB,aAAa,GAGd,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,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E,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IACrF,CAAC;IAEO,MAAM,CAAC,EAAU;QACvB,IAAI,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;IAClC,CAAC;IAED,kFAAkF;IAC1E,KAAK,CAAC,QAAqC;QACjD,wFAAwF;QACxF,SAAS,CAAC,GAAG,EAAE;YACb,IAAI,CAAC,KAAK,EAAE,EAAE,OAAO,EAAE,CAAC;YACxB,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,iBAAiB,CAAC,QAAQ,EAAE,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/E,CAAC,CAAC,CAAC;IACL,CAAC;uGArEU,WAAW;2FAAX,WAAW,kNAFX,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,CAAC;;2FAEvE,WAAW;kBAJvB,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;oBACzB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,YAAY,CAAC,EAAE,CAAC;iBACnF;;AAyED,4FAA4F;AAC5F,SAAS,WAAW,CAAC,OAAmC;IACtD,OAAO,OAAO,CAAC,IAAI,CACjB,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,KAAK,CAAC,MAAM,IAAI,WAAW,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,CACxF,CAAC;AACJ,CAAC","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n InjectionToken,\n Injector,\n computed,\n effect,\n forwardRef,\n inject,\n input,\n signal,\n untracked,\n type TemplateRef,\n} from '@angular/core';\nimport {\n Menus,\n OS,\n buildMenuTemplate,\n serializeMenu,\n type MenuTemplate,\n type NativeMenuEntry,\n} from '@ng-native/device';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\nimport { byNativeId } from './native-id.ts';\n\n/**\n * The `[contextMenu]` on an element, for `<pressable>`: where a long press opens the menu,\n * `(longPress)` does not also fire.\n */\nexport const CONTEXT_MENU = new InjectionToken<{ takesLongPress(): boolean }>(\n 'angular-native.contextMenu',\n);\n\n/**\n * A context menu on an element: `[contextMenu]=\"menu\"`, with `<ng-template #menu>` holding\n * `<menu-item>`s. A right-click opens it on macOS. On Android a long press or a right-click opens\n * it as a PopupMenu at the press point, and on iOS and iPadOS a long press, or a secondary click\n * from an iPad pointer, opens it through UIContextMenuInteraction. On Android and iOS that takes\n * the `NgNativeMenus` module, which Expo Go lacks, and where it is there `(longPress)` does not\n * also fire. On Android a `(longPress)` on a view inside the element keeps its long press, which\n * then opens no menu: the innermost handler wins.\n *\n * The host contract: the view takes a `contextMenu` prop, the menu as `serializeMenu` makes it\n * (null to take it away), and sends `topContextMenuSelect` with the chosen item's `id`. React\n * Native's Android and iOS views drop a prop they do not know, so there the menu goes through\n * `Menus.setContextMenu` by the view's `nativeID`, and an element without one is given one. iOS's\n * module sends the choice, which reaches the element as `topContextMenuSelect`.\n */\n@Directive({\n selector: '[contextMenu]',\n providers: [{ provide: CONTEXT_MENU, useExisting: forwardRef(() => ContextMenu) }],\n})\nexport class ContextMenu {\n readonly contextMenu = input<TemplateRef<unknown> | null>();\n\n private readonly node = inject(ElementRef).nativeElement as HostNode;\n private readonly engine = inject(HostEngine);\n private readonly injector = inject(Injector);\n private readonly os = inject(OS);\n private readonly menus = inject(Menus);\n /** Android's and iOS's hosts, which take the menu by `nativeID` and draw it on a long press. */\n private readonly byNativeId =\n (this.os === 'android' || this.os === 'ios') && this.menus.contextMenuByNativeId;\n private readonly sender = this.byNativeId\n ? byNativeId(\n this.engine,\n this.node,\n (nativeID) => this.sendByNativeId(nativeID),\n (nativeID) => this.menus.setContextMenu(nativeID, null),\n )\n : null;\n private readonly built = signal<MenuTemplate | null>(null);\n private readonly menu = computed(() =>\n serializeMenu(this.built()?.model.entries() ?? [], this.os),\n );\n /** The entries to send, or null where they show no item: only separators and empty sections. */\n private readonly sent = computed(() => {\n const { entries } = this.menu();\n return showsAnItem(entries) ? entries : null;\n });\n\n constructor() {\n effect(() => this.build(this.contextMenu() ?? null));\n effect(() => {\n this.engine.setProp(this.node, 'contextMenu', this.sent());\n this.sender?.();\n });\n const stop = this.engine.setEventListener(this.node, 'topContextMenuSelect', (event) => {\n const id = (event as { nativeEvent?: { id?: string } }).nativeEvent?.id;\n if (id !== undefined) this.choose(id);\n });\n inject(DestroyRef).onDestroy(() => {\n stop();\n this.build(null);\n });\n }\n\n /** Whether a long press opens this menu now, so `(longPress)` does not also fire. */\n takesLongPress(): boolean {\n return this.byNativeId && this.sent() !== null;\n }\n\n /**\n * Send the menu to the host under the view's `nativeID`. On iOS the choice comes back by that\n * name, and runs as the view's own `topContextMenuSelect` would.\n */\n private sendByNativeId(nativeID: string): void {\n this.menus.setContextMenu(nativeID, untracked(this.sent), (id) => this.choose(id));\n }\n\n private choose(id: string): void {\n this.menu().actions.get(id)?.();\n }\n\n /** Make the template's items, which register with the menu this element sends. */\n private build(template: TemplateRef<unknown> | null): void {\n // Read and written outside the effect that calls this, which would otherwise run again.\n untracked(() => {\n this.built()?.destroy();\n this.built.set(template ? buildMenuTemplate(template, this.injector) : null);\n });\n }\n}\n\n/** Whether `entries` show an item: one that is not a separator, nor a section with none. */\nfunction showsAnItem(entries: readonly NativeMenuEntry[]): boolean {\n return entries.some(\n (entry) => !('separator' in entry) && (!entry.inline || showsAnItem(entry.items ?? [])),\n );\n}\n"]}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
/** A file dragged onto a view: its `file://` url and its name. */
|
|
3
|
+
export interface DroppedFile {
|
|
4
|
+
readonly uri: string;
|
|
5
|
+
readonly name: string;
|
|
6
|
+
}
|
|
7
|
+
/** What is dragged onto a view: files, plain text, and urls that are not files. */
|
|
8
|
+
export interface FileDropEvent {
|
|
9
|
+
readonly files: readonly DroppedFile[];
|
|
10
|
+
readonly text: string | null;
|
|
11
|
+
readonly urls: readonly string[];
|
|
12
|
+
}
|
|
13
|
+
/** What a `[dragItem]` view offers when it is dragged out. Files are paths or `file://` urls. */
|
|
14
|
+
export interface DragItemValue {
|
|
15
|
+
readonly files?: readonly string[];
|
|
16
|
+
readonly text?: string;
|
|
17
|
+
readonly url?: string;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Files, text and urls dragged onto a view, on macOS and iPadOS: `(fileDragEnter)` as a drag
|
|
21
|
+
* comes over it, `(fileDragLeave)` as it goes off without dropping, and `(fileDrop)` when it is
|
|
22
|
+
* dropped. Each carries a `FileDropEvent`. On iPhone, Android and the web host nothing fires.
|
|
23
|
+
*
|
|
24
|
+
* The host contract: the view takes a `fileDrop` prop of `true`, and sends `topDropEnter`,
|
|
25
|
+
* `topDropLeave` and `topDropPerform` with `{ files, text, urls }`. Those names differ from the
|
|
26
|
+
* outputs', which a binding also listens for, so each output fires once. On iOS, where React
|
|
27
|
+
* Native's view reads no such prop, the view goes to `DragAndDrop` by its `nativeID` instead, and
|
|
28
|
+
* the same events come back from its module (iPadOS; a development build, not Expo Go).
|
|
29
|
+
*/
|
|
30
|
+
export declare class FileDrop {
|
|
31
|
+
readonly fileDragEnter: import("@angular/core").OutputEmitterRef<FileDropEvent>;
|
|
32
|
+
readonly fileDragLeave: import("@angular/core").OutputEmitterRef<void>;
|
|
33
|
+
readonly fileDrop: import("@angular/core").OutputEmitterRef<FileDropEvent>;
|
|
34
|
+
constructor();
|
|
35
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<FileDrop, never>;
|
|
36
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<FileDrop, "[fileDrop],[fileDragEnter],[fileDragLeave]", never, {}, { "fileDragEnter": "fileDragEnter"; "fileDragLeave": "fileDragLeave"; "fileDrop": "fileDrop"; }, never, never, true, never>;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* A view that can be dragged out, on macOS and iPadOS: to Finder, another app, or a `(fileDrop)`
|
|
40
|
+
* view. `[dragItem]="{ files: [path] }"`, `{ text }` or `{ url }`, or several of them; null for
|
|
41
|
+
* none. A mouse drag starts it on macOS and a long press on iPadOS.
|
|
42
|
+
*
|
|
43
|
+
* The host contract: the view takes a `dragItem` prop of `{ files, text, url }`, with each file
|
|
44
|
+
* as a `file://` url and the others a string or null, or null to take it away. On iOS the item
|
|
45
|
+
* goes to `DragAndDrop` by the view's `nativeID` too.
|
|
46
|
+
*/
|
|
47
|
+
export declare class DragItem {
|
|
48
|
+
readonly dragItem: import("@angular/core").InputSignal<DragItemValue | null | undefined>;
|
|
49
|
+
constructor();
|
|
50
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<DragItem, never>;
|
|
51
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<DragItem, "[dragItem]", never, { "dragItem": { "alias": "dragItem"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
52
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { DestroyRef, Directive, ElementRef, effect, inject, input, output, untracked, } from '@angular/core';
|
|
2
|
+
import { DragAndDrop, OS } from '@ng-native/device';
|
|
3
|
+
import { HostEngine } from '@ng-native/fabric';
|
|
4
|
+
import { byNativeId } from "./native-id.js";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/** Drag and drop exists on macOS and iPadOS; iPhone's host ignores both props. */
|
|
7
|
+
const takesDrags = (os) => os === 'macos' || os === 'ios';
|
|
8
|
+
/** iOS's host module, which takes both by the view's `nativeID`, where the app has it. */
|
|
9
|
+
function moduleOnIos(os) {
|
|
10
|
+
const module = inject(DragAndDrop);
|
|
11
|
+
return os === 'ios' && module.available() ? module : null;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Files, text and urls dragged onto a view, on macOS and iPadOS: `(fileDragEnter)` as a drag
|
|
15
|
+
* comes over it, `(fileDragLeave)` as it goes off without dropping, and `(fileDrop)` when it is
|
|
16
|
+
* dropped. Each carries a `FileDropEvent`. On iPhone, Android and the web host nothing fires.
|
|
17
|
+
*
|
|
18
|
+
* The host contract: the view takes a `fileDrop` prop of `true`, and sends `topDropEnter`,
|
|
19
|
+
* `topDropLeave` and `topDropPerform` with `{ files, text, urls }`. Those names differ from the
|
|
20
|
+
* outputs', which a binding also listens for, so each output fires once. On iOS, where React
|
|
21
|
+
* Native's view reads no such prop, the view goes to `DragAndDrop` by its `nativeID` instead, and
|
|
22
|
+
* the same events come back from its module (iPadOS; a development build, not Expo Go).
|
|
23
|
+
*/
|
|
24
|
+
export class FileDrop {
|
|
25
|
+
fileDragEnter = output();
|
|
26
|
+
fileDragLeave = output();
|
|
27
|
+
fileDrop = output();
|
|
28
|
+
constructor() {
|
|
29
|
+
const os = inject(OS);
|
|
30
|
+
if (!takesDrags(os))
|
|
31
|
+
return;
|
|
32
|
+
const node = inject(ElementRef).nativeElement;
|
|
33
|
+
const engine = inject(HostEngine);
|
|
34
|
+
engine.setProp(node, 'fileDrop', true);
|
|
35
|
+
const hear = (type, native) => {
|
|
36
|
+
if (type === 'topDropEnter' || type === 'dropEnter')
|
|
37
|
+
this.fileDragEnter.emit(dropOf(native));
|
|
38
|
+
else if (type === 'topDropLeave' || type === 'dropLeave')
|
|
39
|
+
this.fileDragLeave.emit();
|
|
40
|
+
else
|
|
41
|
+
this.fileDrop.emit(dropOf(native));
|
|
42
|
+
};
|
|
43
|
+
const stops = ['topDropEnter', 'topDropLeave', 'topDropPerform'].map((type) => engine.setEventListener(node, type, (event) => hear(type, event.nativeEvent)));
|
|
44
|
+
inject(DestroyRef).onDestroy(() => stops.forEach((stop) => stop()));
|
|
45
|
+
const module = moduleOnIos(os);
|
|
46
|
+
if (module) {
|
|
47
|
+
byNativeId(engine, node, (nativeID) => module.setFileDrop(nativeID, (event) => hear(event.type, event)), (nativeID) => module.setFileDrop(nativeID, null))();
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: FileDrop, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
51
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: FileDrop, isStandalone: true, selector: "[fileDrop],[fileDragEnter],[fileDragLeave]", outputs: { fileDragEnter: "fileDragEnter", fileDragLeave: "fileDragLeave", fileDrop: "fileDrop" }, ngImport: i0 });
|
|
52
|
+
}
|
|
53
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: FileDrop, decorators: [{
|
|
54
|
+
type: Directive,
|
|
55
|
+
args: [{ selector: '[fileDrop],[fileDragEnter],[fileDragLeave]' }]
|
|
56
|
+
}], ctorParameters: () => [], propDecorators: { fileDragEnter: [{ type: i0.Output, args: ["fileDragEnter"] }], fileDragLeave: [{ type: i0.Output, args: ["fileDragLeave"] }], fileDrop: [{ type: i0.Output, args: ["fileDrop"] }] } });
|
|
57
|
+
/**
|
|
58
|
+
* A view that can be dragged out, on macOS and iPadOS: to Finder, another app, or a `(fileDrop)`
|
|
59
|
+
* view. `[dragItem]="{ files: [path] }"`, `{ text }` or `{ url }`, or several of them; null for
|
|
60
|
+
* none. A mouse drag starts it on macOS and a long press on iPadOS.
|
|
61
|
+
*
|
|
62
|
+
* The host contract: the view takes a `dragItem` prop of `{ files, text, url }`, with each file
|
|
63
|
+
* as a `file://` url and the others a string or null, or null to take it away. On iOS the item
|
|
64
|
+
* goes to `DragAndDrop` by the view's `nativeID` too.
|
|
65
|
+
*/
|
|
66
|
+
export class DragItem {
|
|
67
|
+
dragItem = input(/* @ts-ignore */
|
|
68
|
+
...(ngDevMode ? [undefined, { debugName: "dragItem" }] : /* istanbul ignore next */ []));
|
|
69
|
+
constructor() {
|
|
70
|
+
const os = inject(OS);
|
|
71
|
+
if (!takesDrags(os))
|
|
72
|
+
return;
|
|
73
|
+
const node = inject(ElementRef).nativeElement;
|
|
74
|
+
const engine = inject(HostEngine);
|
|
75
|
+
const module = moduleOnIos(os);
|
|
76
|
+
const offered = () => {
|
|
77
|
+
const item = untracked(this.dragItem);
|
|
78
|
+
return item ? committedItem(item) : null;
|
|
79
|
+
};
|
|
80
|
+
const send = module &&
|
|
81
|
+
byNativeId(engine, node, (nativeID) => module.setDragItem(nativeID, offered()), (nativeID) => module.setDragItem(nativeID, null));
|
|
82
|
+
effect(() => {
|
|
83
|
+
this.dragItem();
|
|
84
|
+
engine.setProp(node, 'dragItem', offered());
|
|
85
|
+
send?.();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DragItem, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
89
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: DragItem, isStandalone: true, selector: "[dragItem]", inputs: { dragItem: { classPropertyName: "dragItem", publicName: "dragItem", isSignal: true, isRequired: false, transformFunction: null } }, ngImport: i0 });
|
|
90
|
+
}
|
|
91
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: DragItem, decorators: [{
|
|
92
|
+
type: Directive,
|
|
93
|
+
args: [{ selector: '[dragItem]' }]
|
|
94
|
+
}], ctorParameters: () => [], propDecorators: { dragItem: [{ type: i0.Input, args: [{ isSignal: true, alias: "dragItem", required: false }] }] } });
|
|
95
|
+
function committedItem(item) {
|
|
96
|
+
return {
|
|
97
|
+
files: (item.files ?? []).map(fileUrl),
|
|
98
|
+
text: item.text ?? null,
|
|
99
|
+
url: item.url ?? null,
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** A path as a `file://` url, and a url as it is. */
|
|
103
|
+
function fileUrl(file) {
|
|
104
|
+
if (/^[a-z][a-z0-9+.-]*:/i.test(file))
|
|
105
|
+
return file;
|
|
106
|
+
return `file://${file.split('/').map(encodeURIComponent).join('/')}`;
|
|
107
|
+
}
|
|
108
|
+
function dropOf(payload) {
|
|
109
|
+
const native = (payload ?? {});
|
|
110
|
+
return { files: native.files ?? [], text: native.text ?? null, urls: native.urls ?? [] };
|
|
111
|
+
}
|
|
112
|
+
//# sourceMappingURL=drag-and-drop.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drag-and-drop.js","sourceRoot":"","sources":["../src/drag-and-drop.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,GACV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,EAAE,EAAuB,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;;AAsB5C,kFAAkF;AAClF,MAAM,UAAU,GAAG,CAAC,EAAU,EAAW,EAAE,CAAC,EAAE,KAAK,OAAO,IAAI,EAAE,KAAK,KAAK,CAAC;AAE3E,0FAA0F;AAC1F,SAAS,WAAW,CAAC,EAAU;IAC7B,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,CAAC,CAAC;IACnC,OAAO,EAAE,KAAK,KAAK,IAAI,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC;AAED;;;;;;;;;;GAUG;AAEH,MAAM,OAAO,QAAQ;IACV,aAAa,GAAG,MAAM,EAAiB,CAAC;IACxC,aAAa,GAAG,MAAM,EAAQ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@angular/core';\nimport { DragAndDrop, OS, type NativeDragItem } from '@ng-native/device';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\nimport { byNativeId } from './native-id.ts';\n\n/** A file dragged onto a view: its `file://` url and its name. */\nexport interface DroppedFile {\n readonly uri: string;\n readonly name: string;\n}\n\n/** What is dragged onto a view: files, plain text, and urls that are not files. */\nexport interface FileDropEvent {\n readonly files: readonly DroppedFile[];\n readonly text: string | null;\n readonly urls: readonly string[];\n}\n\n/** What a `[dragItem]` view offers when it is dragged out. Files are paths or `file://` urls. */\nexport interface DragItemValue {\n readonly files?: readonly string[];\n readonly text?: string;\n readonly url?: string;\n}\n\n/** Drag and drop exists on macOS and iPadOS; iPhone's host ignores both props. */\nconst takesDrags = (os: string): boolean => os === 'macos' || os === 'ios';\n\n/** iOS's host module, which takes both by the view's `nativeID`, where the app has it. */\nfunction moduleOnIos(os: string): DragAndDrop | null {\n const module = inject(DragAndDrop);\n return os === 'ios' && module.available() ? module : null;\n}\n\n/**\n * Files, text and urls dragged onto a view, on macOS and iPadOS: `(fileDragEnter)` as a drag\n * comes over it, `(fileDragLeave)` as it goes off without dropping, and `(fileDrop)` when it is\n * dropped. Each carries a `FileDropEvent`. On iPhone, Android and the web host nothing fires.\n *\n * The host contract: the view takes a `fileDrop` prop of `true`, and sends `topDropEnter`,\n * `topDropLeave` and `topDropPerform` with `{ files, text, urls }`. Those names differ from the\n * outputs', which a binding also listens for, so each output fires once. On iOS, where React\n * Native's view reads no such prop, the view goes to `DragAndDrop` by its `nativeID` instead, and\n * the same events come back from its module (iPadOS; a development build, not Expo Go).\n */\n@Directive({ selector: '[fileDrop],[fileDragEnter],[fileDragLeave]' })\nexport class FileDrop {\n readonly fileDragEnter = output<FileDropEvent>();\n readonly fileDragLeave = output<void>();\n readonly fileDrop = output<FileDropEvent>();\n\n constructor() {\n const os = inject(OS);\n if (!takesDrags(os)) return;\n const node = inject(ElementRef).nativeElement as HostNode;\n const engine = inject(HostEngine);\n engine.setProp(node, 'fileDrop', true);\n const hear = (type: string, native: unknown) => {\n if (type === 'topDropEnter' || type === 'dropEnter') this.fileDragEnter.emit(dropOf(native));\n else if (type === 'topDropLeave' || type === 'dropLeave') this.fileDragLeave.emit();\n else this.fileDrop.emit(dropOf(native));\n };\n const stops = ['topDropEnter', 'topDropLeave', 'topDropPerform'].map((type) =>\n engine.setEventListener(node, type, (event) =>\n hear(type, (event as { nativeEvent?: unknown }).nativeEvent),\n ),\n );\n inject(DestroyRef).onDestroy(() => stops.forEach((stop) => stop()));\n const module = moduleOnIos(os);\n if (module) {\n byNativeId(\n engine,\n node,\n (nativeID) => module.setFileDrop(nativeID, (event) => hear(event.type, event)),\n (nativeID) => module.setFileDrop(nativeID, null),\n )();\n }\n }\n}\n\n/**\n * A view that can be dragged out, on macOS and iPadOS: to Finder, another app, or a `(fileDrop)`\n * view. `[dragItem]=\"{ files: [path] }\"`, `{ text }` or `{ url }`, or several of them; null for\n * none. A mouse drag starts it on macOS and a long press on iPadOS.\n *\n * The host contract: the view takes a `dragItem` prop of `{ files, text, url }`, with each file\n * as a `file://` url and the others a string or null, or null to take it away. On iOS the item\n * goes to `DragAndDrop` by the view's `nativeID` too.\n */\n@Directive({ selector: '[dragItem]' })\nexport class DragItem {\n readonly dragItem = input<DragItemValue | null>();\n\n constructor() {\n const os = inject(OS);\n if (!takesDrags(os)) return;\n const node = inject(ElementRef).nativeElement as HostNode;\n const engine = inject(HostEngine);\n const module = moduleOnIos(os);\n const offered = () => {\n const item = untracked(this.dragItem);\n return item ? committedItem(item) : null;\n };\n const send =\n module &&\n byNativeId(\n engine,\n node,\n (nativeID) => module.setDragItem(nativeID, offered()),\n (nativeID) => module.setDragItem(nativeID, null),\n );\n effect(() => {\n this.dragItem();\n engine.setProp(node, 'dragItem', offered());\n send?.();\n });\n }\n}\n\nfunction committedItem(item: DragItemValue): NativeDragItem {\n return {\n files: (item.files ?? []).map(fileUrl),\n text: item.text ?? null,\n url: item.url ?? null,\n };\n}\n\n/** A path as a `file://` url, and a url as it is. */\nfunction fileUrl(file: string): string {\n if (/^[a-z][a-z0-9+.-]*:/i.test(file)) return file;\n return `file://${file.split('/').map(encodeURIComponent).join('/')}`;\n}\n\nfunction dropOf(payload: unknown): FileDropEvent {\n const native = (payload ?? {}) as Partial<FileDropEvent>;\n return { files: native.files ?? [], text: native.text ?? null, urls: native.urls ?? [] };\n}\n"]}
|