@ng-native/components 0.28.0 → 0.29.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/src/main/java/dev/ngnative/components/ColorSchemeModule.kt +116 -11
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/menu.d.ts +11 -5
- package/dist/menu.js +12 -32
- package/dist/menu.js.map +1 -1
- package/dist/native-button.d.ts +25 -3
- package/dist/native-button.js +101 -7
- package/dist/native-button.js.map +1 -1
- package/dist/press-menu.d.ts +29 -8
- package/dist/press-menu.js +56 -16
- package/dist/press-menu.js.map +1 -1
- package/dist/pressable.js +2 -1
- package/dist/pressable.js.map +1 -1
- package/dist/scroll-view.d.ts +3 -1
- package/dist/scroll-view.js +7 -2
- package/dist/scroll-view.js.map +1 -1
- package/dist/sidebar.js +4 -3
- package/dist/sidebar.js.map +1 -1
- package/dist/split-view.d.ts +23 -2
- package/dist/split-view.js +32 -5
- package/dist/split-view.js.map +1 -1
- package/dist/sticky-headers.d.ts +19 -0
- package/dist/sticky-headers.js +67 -10
- package/dist/sticky-headers.js.map +1 -1
- package/dist/sticky-rows.d.ts +13 -11
- package/dist/sticky-rows.js +35 -21
- package/dist/sticky-rows.js.map +1 -1
- package/dist/svg-icon.d.ts +16 -2
- package/dist/svg-icon.js +19 -3
- package/dist/svg-icon.js.map +1 -1
- package/dist/tray-icon.d.ts +7 -1
- package/dist/tray-icon.js +15 -3
- package/dist/tray-icon.js.map +1 -1
- package/dist/virtual-list-sticky-level.d.ts +0 -6
- package/dist/virtual-list-sticky-level.js +2 -26
- package/dist/virtual-list-sticky-level.js.map +1 -1
- package/dist/virtual-list.d.ts +24 -6
- package/dist/virtual-list.js +79 -28
- package/dist/virtual-list.js.map +1 -1
- package/dist/written-props.js +2 -0
- package/dist/written-props.js.map +1 -1
- package/ios/NgNativeButtonComponentView.mm +8 -4
- package/ios/NgNativeButtonMetrics.h +9 -2
- package/ios/NgNativeButtonMetrics.mm +33 -4
- package/ios/NgNativeButtonShadowNode.h +2 -0
- package/ios/NgNativeButtonShadowNode.mm +5 -1
- package/ios/NgNativeMenus.mm +42 -2
- package/ios/NgNativePressMenu.h +28 -0
- package/ios/NgNativePressMenu.mm +45 -0
- package/package.json +3 -3
|
@@ -4,11 +4,18 @@ import android.app.UiModeManager
|
|
|
4
4
|
import android.content.Context
|
|
5
5
|
import android.content.res.ColorStateList
|
|
6
6
|
import android.content.res.Configuration
|
|
7
|
+
import android.graphics.drawable.BitmapDrawable
|
|
8
|
+
import android.graphics.drawable.Drawable
|
|
9
|
+
import android.graphics.drawable.DrawableContainer
|
|
10
|
+
import android.graphics.drawable.LayerDrawable
|
|
11
|
+
import android.graphics.drawable.NinePatchDrawable
|
|
12
|
+
import android.graphics.drawable.RippleDrawable
|
|
7
13
|
import android.os.Build
|
|
8
14
|
import android.os.Handler
|
|
9
15
|
import android.os.Looper
|
|
10
16
|
import android.view.View
|
|
11
17
|
import android.view.ViewGroup
|
|
18
|
+
import android.widget.EditText
|
|
12
19
|
import androidx.activity.ComponentActivity
|
|
13
20
|
import androidx.appcompat.R
|
|
14
21
|
import androidx.appcompat.content.res.AppCompatResources
|
|
@@ -28,14 +35,20 @@ import java.lang.ref.WeakReference
|
|
|
28
35
|
* (Android 12 and later) is part of the configuration the system applies, so it holds, and the
|
|
29
36
|
* system keeps it across launches. Earlier Android has no such setting and this does nothing there.
|
|
30
37
|
*
|
|
31
|
-
* It also retints the activity's switches after each configuration change the
|
|
32
|
-
* place, whatever made it, as React Native's
|
|
38
|
+
* It also retints the activity's switches and text inputs after each configuration change the
|
|
39
|
+
* activity takes in place, whatever made it, as React Native's keep the colours they were created
|
|
40
|
+
* with.
|
|
33
41
|
*/
|
|
34
42
|
class ColorSchemeModule : Module() {
|
|
35
43
|
private val main = Handler(Looper.getMainLooper())
|
|
36
44
|
private var watched: WeakReference<ComponentActivity>? = null
|
|
45
|
+
/** The theme's selection colour before the change, which a field showing it took by default. */
|
|
46
|
+
private var highlight = 0
|
|
37
47
|
private val onConfigurationChanged = Consumer<Configuration> {
|
|
38
|
-
watched?.get()
|
|
48
|
+
val activity = watched?.get() ?: return@Consumer
|
|
49
|
+
val was = highlight
|
|
50
|
+
highlight = themeHighlight(activity)
|
|
51
|
+
activity.window?.decorView?.let { refreshControls(it, was, highlight) }
|
|
39
52
|
}
|
|
40
53
|
|
|
41
54
|
override fun definition() = ModuleDefinition {
|
|
@@ -63,6 +76,7 @@ class ColorSchemeModule : Module() {
|
|
|
63
76
|
unwatch()
|
|
64
77
|
activity.addOnConfigurationChangedListener(onConfigurationChanged)
|
|
65
78
|
watched = WeakReference(activity)
|
|
79
|
+
highlight = themeHighlight(activity)
|
|
66
80
|
}
|
|
67
81
|
}
|
|
68
82
|
|
|
@@ -73,20 +87,81 @@ class ColorSchemeModule : Module() {
|
|
|
73
87
|
}
|
|
74
88
|
|
|
75
89
|
/**
|
|
76
|
-
* Retint every switch under [view] from its theme as it is now. `SwitchCompat`,
|
|
77
|
-
* Native's `AndroidSwitch` is, takes its thumb and track tints
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
90
|
+
* Retint every switch and text input under [view] from its theme as it is now. `SwitchCompat`,
|
|
91
|
+
* which React Native's `AndroidSwitch` is, takes its thumb and track tints and its press ripple
|
|
92
|
+
* from the theme once, when it is created, and an `EditText` its selection colour, cursor and
|
|
93
|
+
* selection handles, so after a scheme change that an activity handling `uiMode` takes in place,
|
|
94
|
+
* by the system or by `setColorScheme`, those on screen keep the old scheme's. Colours React
|
|
95
|
+
* Native set from JavaScript stay: its `trackColor`, `thumbColor`, `cursorColor` and
|
|
96
|
+
* `selectionHandleColor` are colour filters, which draw in place of a tint and are left alone, and
|
|
97
|
+
* a `selectionColor` is kept unless it is the old theme's own, [was]. A modal's controls are
|
|
98
|
+
* reached too: its host hands out its dialog's views as its children.
|
|
82
99
|
*/
|
|
83
|
-
internal fun
|
|
100
|
+
internal fun refreshControls(view: View, was: Int, highlight: Int) {
|
|
84
101
|
if (view is SwitchCompat) refreshSwitch(view)
|
|
85
|
-
if (view is
|
|
102
|
+
if (view is EditText) refreshField(view, was, highlight)
|
|
103
|
+
if (view is ViewGroup) {
|
|
104
|
+
for (i in 0 until view.childCount) refreshControls(view.getChildAt(i), was, highlight)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** The theme's `textColorHighlight`, which React Native gives a field with no `selectionColor`. */
|
|
109
|
+
private fun themeHighlight(context: Context): Int {
|
|
110
|
+
val styled = context.obtainStyledAttributes(intArrayOf(android.R.attr.textColorHighlight))
|
|
111
|
+
try {
|
|
112
|
+
return styled.getColorStateList(0)?.defaultColor ?: 0
|
|
113
|
+
} finally {
|
|
114
|
+
styled.recycle()
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* A field's selection colour after a change from [was] to [now]: the new theme's when it showed
|
|
120
|
+
* the old theme's, and its own otherwise.
|
|
121
|
+
*
|
|
122
|
+
* ponytail: a `selectionColor` set to exactly the old theme's colour follows the theme too.
|
|
123
|
+
*/
|
|
124
|
+
internal fun followedHighlight(current: Int, was: Int, now: Int): Int =
|
|
125
|
+
if (current == was) now else current
|
|
126
|
+
|
|
127
|
+
private fun refreshField(field: EditText, was: Int, highlight: Int) {
|
|
128
|
+
field.highlightColor = followedHighlight(field.highlightColor, was, highlight)
|
|
129
|
+
// Android 10 added the getters and setters; earlier, React Native reaches these by reflection.
|
|
130
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) return
|
|
131
|
+
// The platform's cursor and handles are tinted `colorControlActivated`. Loading them again does
|
|
132
|
+
// not do: the drawable cache keeps the old scheme's tint, as a theme attribute is not a `uiMode`
|
|
133
|
+
// dependency it knows of. So they are tinted again in place.
|
|
134
|
+
val styled = field.context.obtainStyledAttributes(intArrayOf(android.R.attr.colorControlActivated))
|
|
135
|
+
val tint =
|
|
136
|
+
try {
|
|
137
|
+
styled.getColorStateList(0)
|
|
138
|
+
} finally {
|
|
139
|
+
styled.recycle()
|
|
140
|
+
} ?: return
|
|
141
|
+
field.textCursorDrawable?.takeIf { it.colorFilter == null }?.let {
|
|
142
|
+
it.mutate().setTintList(tint)
|
|
143
|
+
field.textCursorDrawable = it
|
|
144
|
+
}
|
|
145
|
+
// React Native filters all three handles or none.
|
|
146
|
+
if (field.textSelectHandle?.colorFilter != null) return
|
|
147
|
+
field.textSelectHandle?.let { field.setTextSelectHandle(it.mutate().apply { setTintList(tint) }) }
|
|
148
|
+
field.textSelectHandleLeft?.let {
|
|
149
|
+
field.setTextSelectHandleLeft(it.mutate().apply { setTintList(tint) })
|
|
150
|
+
}
|
|
151
|
+
field.textSelectHandleRight?.let {
|
|
152
|
+
field.setTextSelectHandleRight(it.mutate().apply { setTintList(tint) })
|
|
153
|
+
}
|
|
86
154
|
}
|
|
87
155
|
|
|
88
156
|
/** The tints AppCompat gives its own switch drawables, read again; others it leaves alone. */
|
|
89
157
|
private fun refreshSwitch(switch: SwitchCompat) {
|
|
158
|
+
// React Native's `thumbColor` filters the thumb (a state list, whose nine-patch states keep the
|
|
159
|
+
// filter on their paint and report none) and colours the ripple too, which a wrapper for an
|
|
160
|
+
// outline or a border added later keeps.
|
|
161
|
+
// ponytail: a ripple has no colour to read back, so with the thumb filtered it is taken as the
|
|
162
|
+
// app's. One wrapped before `thumbColor` came, which React Native left the theme's, then keeps
|
|
163
|
+
// the old scheme's ripple; an app's own colour is never painted over.
|
|
164
|
+
val ownRipple = switch.thumbDrawable?.let(::hasFilter) == true
|
|
90
165
|
val context = switch.context
|
|
91
166
|
val styled =
|
|
92
167
|
context.obtainStyledAttributes(null, R.styleable.SwitchCompat, R.attr.switchStyle, 0)
|
|
@@ -100,8 +175,38 @@ private fun refreshSwitch(switch: SwitchCompat) {
|
|
|
100
175
|
switch.trackTintList =
|
|
101
176
|
AppCompatResources.getColorStateList(context, R.color.abc_tint_switch_track)
|
|
102
177
|
}
|
|
178
|
+
if (ownRipple) return
|
|
179
|
+
val ripple = themeRipple(switch.background) ?: return
|
|
180
|
+
val highlight = context.obtainStyledAttributes(intArrayOf(R.attr.colorControlHighlight))
|
|
181
|
+
try {
|
|
182
|
+
highlight.getColorStateList(0)?.let(ripple::setColor)
|
|
183
|
+
} finally {
|
|
184
|
+
highlight.recycle()
|
|
185
|
+
}
|
|
103
186
|
}
|
|
104
187
|
|
|
188
|
+
/** Whether a colour filter is on [drawable], or on the state a state list shows. */
|
|
189
|
+
private fun hasFilter(drawable: Drawable): Boolean {
|
|
190
|
+
val shown = if (drawable is DrawableContainer) drawable.current ?: drawable else drawable
|
|
191
|
+
return drawable.colorFilter != null ||
|
|
192
|
+
shown.colorFilter != null ||
|
|
193
|
+
(shown as? NinePatchDrawable)?.paint?.colorFilter != null ||
|
|
194
|
+
(shown as? BitmapDrawable)?.paint?.colorFilter != null
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* The theme's borderless item background, whose colour is `colorControlHighlight`: a ripple with
|
|
199
|
+
* no layers, where React Native's `backgroundColor` makes one around a colour. Found inside the
|
|
200
|
+
* layers React Native wraps it in for an outline, a border or a shadow.
|
|
201
|
+
*/
|
|
202
|
+
private fun themeRipple(drawable: Drawable?): RippleDrawable? =
|
|
203
|
+
when (drawable) {
|
|
204
|
+
is RippleDrawable -> drawable.takeIf { it.numberOfLayers == 0 }
|
|
205
|
+
is LayerDrawable ->
|
|
206
|
+
(0 until drawable.numberOfLayers).firstNotNullOfOrNull { themeRipple(drawable.getDrawable(it)) }
|
|
207
|
+
else -> null
|
|
208
|
+
}
|
|
209
|
+
|
|
105
210
|
/**
|
|
106
211
|
* AppCompat's thumb tint, which it builds in code: `colorSwitchThumbNormal`, and
|
|
107
212
|
* `colorControlActivated` when checked.
|
package/dist/index.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export { PRESS_MENU, PressMenu } from './press-menu.ts';
|
|
|
23
23
|
export { Shortcut } from './shortcut.ts';
|
|
24
24
|
export { DragItem, FileDrop, type DragItemValue, type DroppedFile, type FileDropEvent, } from './drag-and-drop.ts';
|
|
25
25
|
export { TrayIcon } from './tray-icon.ts';
|
|
26
|
-
export { SplitView, SplitViewContent, type SplitViewShowing } from './split-view.ts';
|
|
26
|
+
export { SplitView, SplitViewContent, type SplitViewContentStyle, type SplitViewShowing, } from './split-view.ts';
|
|
27
27
|
export { Sidebar, type SidebarRow } from './sidebar.ts';
|
|
28
28
|
export { SidebarSection } from './sidebar-section.ts';
|
|
29
29
|
export { SidebarItem, type SidebarItemIcon } from './sidebar-item.ts';
|
package/dist/index.js
CHANGED
|
@@ -23,7 +23,7 @@ export { PRESS_MENU, PressMenu } from "./press-menu.js";
|
|
|
23
23
|
export { Shortcut } from "./shortcut.js";
|
|
24
24
|
export { DragItem, FileDrop, } from "./drag-and-drop.js";
|
|
25
25
|
export { TrayIcon } from "./tray-icon.js";
|
|
26
|
-
export { SplitView, SplitViewContent } from "./split-view.js";
|
|
26
|
+
export { SplitView, SplitViewContent, } from "./split-view.js";
|
|
27
27
|
export { Sidebar } from "./sidebar.js";
|
|
28
28
|
export { SidebarSection } from "./sidebar-section.js";
|
|
29
29
|
export { SidebarItem } from "./sidebar-item.js";
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAC5D,OAAO,EAAmD,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAwCN,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,KAAK,EAA+D,MAAM,YAAY,CAAC;AAChG,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AAC/D,OAAO,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CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,IAAI,EAA4C,MAAM,WAAW,CAAC;AAC3E,OAAO,EACL,SAAS,GAIV,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EACL,QAAQ,EACR,YAAY,EACZ,uBAAuB,GAWxB,MAAM,gBAAgB,CAAC;AACxB,OAAO,EACL,WAAW,EACX,cAAc,EACd,oBAAoB,GAMrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,mBAAmB,EAA0B,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,qBAAqB,EAAE,MAAM,+BAA+B,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAA0B,MAAM,0BAA0B,CAAC;AACvF,OAAO,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAC;AACxE,OAAO,EAA6D,MAAM,sBAAsB,CAAC;AACjG,OAAO,EACL,aAAa,EACb,YAAY,GAMb,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC","sourcesContent":["/**\n * The host primitives, and the platform-capability tokens they inject.\n *\n * Every element a template renders natively is a component here and must be imported by the\n * component whose template uses it, as any Angular component must. A template that uses one\n * without importing it compiles, renders a plain view, and is reported in dev builds.\n *\n * Importing this barrel evaluates decorators, so anything a Node test needs at runtime has to\n * be reached as a source file instead - see the note in `packages/integration-tests/compile.ts`.\n */\nexport { ActivityIndicator } from './activity-indicator.ts';\nexport { type AnimatedPropsHandle, type AnimationBackend } from './animation.ts';\nexport {\n type AccessibilityActionEvent,\n type AccessibilityActionPayload,\n type ContentSizeChangeEvent,\n type ImageErrorEvent,\n type ImageErrorPayload,\n type ImageLoadEvent,\n type ImageLoadPayload,\n type ImageProgressEvent,\n type ImageProgressPayload,\n type Insets,\n type KeyPressEvent,\n type KeyPressPayload,\n type LayoutEvent,\n type LayoutPayload,\n type OrientationChangeEvent,\n type OrientationChangePayload,\n type Point,\n type Rect,\n type ScrollEvent,\n type ScrollPayload,\n type SelectionChangeEvent,\n type SelectionChangePayload,\n type Size,\n type SwitchChangeEvent,\n type SwitchChangePayload,\n type TextInputChangeEvent,\n type TextInputChangePayload,\n type TextInputContentSizeEvent,\n type TextInputContentSizePayload,\n type TextInputEditingEvent,\n type TextInputFocusEvent,\n type TextInputFocusPayload,\n type TextInputScrollEvent,\n type TextInputScrollPayload,\n type TextLayoutEvent,\n type TextLayoutLine,\n type TextLayoutPayload,\n type TouchEvent,\n type TouchEventPayload,\n} from './events.ts';\nexport { Image, type ImageResizeMode, type ImageSource, type ImageURISource } from './image.ts';\nexport { ImageBackground } from './image-background.ts';\nexport { InputAccessoryView } from './input-accessory-view.ts';\nexport {\n KEYBOARD_CONTROLLER,\n KeyboardDock,\n KeyboardLift,\n provideKeyboardController,\n} from './keyboard-dock.ts';\nexport { KeyboardAvoidingView, type KeyboardAvoidingBehavior } from './keyboard-avoiding-view.ts';\nexport {\n Modal,\n type ModalAnchor,\n type ModalOrientation,\n type ModalPresentationStyle,\n} from './modal.ts';\nexport { MenuBar, MenuGroup, MenuItem, MenuSeparator, treeOrder } from './menu.ts';\nexport { CONTEXT_MENU, ContextMenu } from './context-menu.ts';\nexport { PRESS_MENU, PressMenu } from './press-menu.ts';\nexport { Shortcut } from './shortcut.ts';\nexport {\n DragItem,\n FileDrop,\n type DragItemValue,\n type DroppedFile,\n type FileDropEvent,\n} from './drag-and-drop.ts';\nexport { TrayIcon } from './tray-icon.ts';\nexport {\n SplitView,\n SplitViewContent,\n type SplitViewContentStyle,\n type SplitViewShowing,\n} from './split-view.ts';\nexport { Sidebar, type SidebarRow } from './sidebar.ts';\nexport { SidebarSection } from './sidebar-section.ts';\nexport { SidebarItem, type SidebarItemIcon } from './sidebar-item.ts';\nexport { NativeButton, type ButtonIcon, type ButtonKind } from './native-button.ts';\nexport { NativeRef } from './native-ref.ts';\nexport {\n ControlBase,\n PressBehavior,\n Pressable,\n TouchableBase,\n type AndroidRipple,\n type PressEvent,\n} from './pressable.ts';\nexport {\n INTERACTION_OBSERVERS,\n SWIPE_VELOCITY,\n provideInteractionObserver,\n type InteractionDirection,\n type InteractionEvent,\n type InteractionGesture,\n type InteractionObserver,\n type InteractionType,\n} from './interaction-observer.ts';\nexport { RefreshControl } from './refresh-control.ts';\nexport { GradientText } from './gradient-text.ts';\nexport { type SafeAreaEdge, type SafeAreaEdges } from './safe-area.ts';\nexport { SafeAreaProvider } from './safe-area-provider.ts';\nexport { SafeAreaView, type SafeAreaEdgeMode } from './safe-area-view.ts';\nexport { type KeyboardShouldPersistTaps } from './keyboard-taps.ts';\nexport { ScrollView } from './scroll-view.ts';\nexport {\n SectionEdgeSeparator,\n SectionFooter,\n SectionHeader,\n SectionItem,\n SectionList,\n SectionSeparator,\n type SectionContext,\n type SectionEdgeSeparatorContext,\n type SectionItemContext,\n type SectionListSection,\n type SectionRow,\n type SectionSeparatorContext,\n} from './section-list.ts';\nexport { Switch } from './switch.ts';\nexport { Text, type DynamicTypeRamp, type EllipsizeMode } from './text.ts';\nexport {\n TextInput,\n type KeyboardType,\n type ReturnKeyType,\n type SubmitBehavior,\n} from './text-input.ts';\nexport { TouchableOpacity } from './touchable-opacity.ts';\nexport { optionalBoolean, optionalNumber } from './transforms.ts';\nexport { View } from './view.ts';\nexport {\n ViewBase,\n ViewBehavior,\n contributeAccessibility,\n type AccessibilityAction,\n type AccessibilityContribution,\n type AccessibilityLiveRegion,\n type AccessibilityRole,\n type Role,\n type AccessibilityState,\n type AccessibilityValue,\n type AndroidDrawable,\n type ImportantForAccessibility,\n type PointerEvents,\n} from './view-base.ts';\nexport {\n VirtualList,\n VirtualListRow,\n VirtualListSeparator,\n type VirtualItemHeight,\n type VirtualListSeparatorContext,\n type VirtualListPadding,\n type VirtualListVisiblePosition,\n type VirtualRow,\n} from './virtual-list.ts';\nexport { VIRTUAL_LIST_LAYOUT, type VirtualListLayout } from './virtual-list-layout.ts';\nexport { VirtualListNumColumns } from './virtual-list-num-columns.ts';\nexport { VIRTUAL_LIST_STICKY, type VirtualListSticky } from './virtual-list-sticky.ts';\nexport { VirtualListStickyLevel } from './virtual-list-sticky-level.ts';\nexport { type GestureBackend, type GestureSpec, type GestureTarget } from './gesture-backend.ts';\nexport {\n workletScroll,\n workletStyle,\n type SharedValue,\n type WorkletBackend,\n type WorkletScrollSpec,\n type WorkletStyleSpec,\n type WorkletTarget,\n} from './worklets.ts';\nexport { releaseOnDestroy } from './release-on-destroy.ts';\n"]}
|
package/dist/menu.d.ts
CHANGED
|
@@ -4,8 +4,9 @@
|
|
|
4
4
|
* `MENU_MODEL`, and the menu's owner draws it: `Menus` sends a `<menu-bar>` to the host, and a
|
|
5
5
|
* `[contextMenu]` or a `<native-header-item [menu]>` reads a template of items.
|
|
6
6
|
*/
|
|
7
|
-
import { type OnChanges, type
|
|
7
|
+
import { type OnChanges, type SimpleChanges } from '@angular/core';
|
|
8
8
|
import { type MenuGroupRole, type MenuRole } from '@ng-native/device';
|
|
9
|
+
import type { ButtonIcon } from './native-button.ts';
|
|
9
10
|
import * as i0 from "@angular/core";
|
|
10
11
|
export { menuModelInTreeOrder, treeOrder } from '@ng-native/device';
|
|
11
12
|
/**
|
|
@@ -27,9 +28,13 @@ export declare class MenuItem implements OnChanges {
|
|
|
27
28
|
readonly subtitle: import("@angular/core").InputSignal<string | undefined>;
|
|
28
29
|
/** An SF Symbol, on Apple's OSes. */
|
|
29
30
|
readonly sfSymbol: import("@angular/core").InputSignal<string | undefined>;
|
|
30
|
-
/**
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
/**
|
|
32
|
+
* The picture: a drawable resource's name, on Android, or a `ButtonIcon` as `<native-button>`
|
|
33
|
+
* takes, `{ sfSymbol }`, `{ drawable }`, or an icon's SVG markup, `{ svg }`, in a macOS menu and
|
|
34
|
+
* in a Linux tray icon's menu.
|
|
35
|
+
*/
|
|
36
|
+
readonly icon: import("@angular/core").InputSignal<string | ButtonIcon | undefined>;
|
|
37
|
+
readonly select: import("@angular/core").OutputEmitterRef<void>;
|
|
33
38
|
private readonly handled;
|
|
34
39
|
constructor();
|
|
35
40
|
ngOnChanges(changes: SimpleChanges): void;
|
|
@@ -54,7 +59,8 @@ export declare class MenuGroup {
|
|
|
54
59
|
readonly menuRole: import("@angular/core").InputSignal<MenuGroupRole | undefined>;
|
|
55
60
|
readonly inline: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
56
61
|
readonly sfSymbol: import("@angular/core").InputSignal<string | undefined>;
|
|
57
|
-
|
|
62
|
+
/** A drawable's name, or a `ButtonIcon`, as on `<menu-item>`. */
|
|
63
|
+
readonly icon: import("@angular/core").InputSignal<string | ButtonIcon | undefined>;
|
|
58
64
|
readonly destructive: import("@angular/core").InputSignalWithTransform<boolean, unknown>;
|
|
59
65
|
private readonly own;
|
|
60
66
|
constructor();
|
package/dist/menu.js
CHANGED
|
@@ -4,9 +4,10 @@
|
|
|
4
4
|
* `MENU_MODEL`, and the menu's owner draws it: `Menus` sends a `<menu-bar>` to the host, and a
|
|
5
5
|
* `[contextMenu]` or a `<native-header-item [menu]>` reads a template of items.
|
|
6
6
|
*/
|
|
7
|
-
import { Component, DestroyRef, ElementRef, booleanAttribute, computed, inject, input, model, output,
|
|
8
|
-
import { MENU_MODEL, Menus, menuModelInTreeOrder, } from '@ng-native/device';
|
|
7
|
+
import { Component, DestroyRef, ElementRef, booleanAttribute, computed, inject, input, model, output, } from '@angular/core';
|
|
8
|
+
import { MENU_MODEL, Menus, menuModelInTreeOrder, outputListened, } from '@ng-native/device';
|
|
9
9
|
import { ControlledModel } from "./controlled-model.js";
|
|
10
|
+
import { iconFields } from "./svg-icon.js";
|
|
10
11
|
import * as i0 from "@angular/core";
|
|
11
12
|
export { menuModelInTreeOrder, treeOrder } from '@ng-native/device';
|
|
12
13
|
/** Register `entry` with the menu the element is written in, and take it out as it goes. */
|
|
@@ -20,30 +21,6 @@ function registerIn(entry, element) {
|
|
|
20
21
|
const node = inject(ElementRef).nativeElement;
|
|
21
22
|
inject(DestroyRef).onDestroy(menu.register(entry, node));
|
|
22
23
|
}
|
|
23
|
-
/**
|
|
24
|
-
* Count an output's listeners, so an item knows whether the app handles it: as a signal, so the
|
|
25
|
-
* menu follows a listener added or removed after it was first sent.
|
|
26
|
-
*/
|
|
27
|
-
function listened(emitter) {
|
|
28
|
-
const listeners = signal(0, /* @ts-ignore */
|
|
29
|
-
...(ngDevMode ? [{ debugName: "listeners" }] : /* istanbul ignore next */ []));
|
|
30
|
-
const subscribe = emitter.subscribe.bind(emitter);
|
|
31
|
-
emitter.subscribe = (callback) => {
|
|
32
|
-
listeners.update((count) => count + 1);
|
|
33
|
-
const subscription = subscribe(callback);
|
|
34
|
-
let stopped = false;
|
|
35
|
-
return {
|
|
36
|
-
unsubscribe: () => {
|
|
37
|
-
if (stopped)
|
|
38
|
-
return;
|
|
39
|
-
stopped = true;
|
|
40
|
-
listeners.update((count) => count - 1);
|
|
41
|
-
subscription.unsubscribe();
|
|
42
|
-
},
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
return computed(() => listeners() > 0);
|
|
46
|
-
}
|
|
47
24
|
/**
|
|
48
25
|
* One item of a menu. `(select)` fires when it is chosen, and a `[(checked)]` item toggles. A
|
|
49
26
|
* one-way `[checked]` stays as the app binds it, so a menu of choices checks the one the app keeps.
|
|
@@ -69,11 +46,15 @@ export class MenuItem {
|
|
|
69
46
|
/** An SF Symbol, on Apple's OSes. */
|
|
70
47
|
sfSymbol = input(/* @ts-ignore */
|
|
71
48
|
...(ngDevMode ? [undefined, { debugName: "sfSymbol" }] : /* istanbul ignore next */ []));
|
|
72
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* The picture: a drawable resource's name, on Android, or a `ButtonIcon` as `<native-button>`
|
|
51
|
+
* takes, `{ sfSymbol }`, `{ drawable }`, or an icon's SVG markup, `{ svg }`, in a macOS menu and
|
|
52
|
+
* in a Linux tray icon's menu.
|
|
53
|
+
*/
|
|
73
54
|
icon = input(/* @ts-ignore */
|
|
74
55
|
...(ngDevMode ? [undefined, { debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
75
56
|
select = output();
|
|
76
|
-
handled =
|
|
57
|
+
handled = outputListened(this.select);
|
|
77
58
|
constructor() {
|
|
78
59
|
registerIn(computed(() => {
|
|
79
60
|
const checked = this.checked();
|
|
@@ -88,8 +69,7 @@ export class MenuItem {
|
|
|
88
69
|
...(checked !== undefined && { checked }),
|
|
89
70
|
...(this.destructive() && { destructive: true }),
|
|
90
71
|
...(this.subtitle() && { subtitle: this.subtitle() }),
|
|
91
|
-
...(this.sfSymbol()
|
|
92
|
-
...(this.icon() && { icon: this.icon() }),
|
|
72
|
+
...iconFields(this.sfSymbol(), this.icon(), 'menu-item', true),
|
|
93
73
|
...(own && { select: this.choose }),
|
|
94
74
|
};
|
|
95
75
|
}), 'menu-item');
|
|
@@ -146,6 +126,7 @@ export class MenuGroup {
|
|
|
146
126
|
inline = input(false, { ...(ngDevMode ? { debugName: "inline" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
147
127
|
sfSymbol = input(/* @ts-ignore */
|
|
148
128
|
...(ngDevMode ? [undefined, { debugName: "sfSymbol" }] : /* istanbul ignore next */ []));
|
|
129
|
+
/** A drawable's name, or a `ButtonIcon`, as on `<menu-item>`. */
|
|
149
130
|
icon = input(/* @ts-ignore */
|
|
150
131
|
...(ngDevMode ? [undefined, { debugName: "icon" }] : /* istanbul ignore next */ []));
|
|
151
132
|
destructive = input(false, { ...(ngDevMode ? { debugName: "destructive" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
@@ -156,8 +137,7 @@ export class MenuGroup {
|
|
|
156
137
|
items: this.own.entries(),
|
|
157
138
|
...(this.menuRole() && { group: this.menuRole() }),
|
|
158
139
|
...(this.inline() && { inline: true }),
|
|
159
|
-
...(this.sfSymbol()
|
|
160
|
-
...(this.icon() && { icon: this.icon() }),
|
|
140
|
+
...iconFields(this.sfSymbol(), this.icon(), 'menu-group', true),
|
|
161
141
|
...(this.destructive() && { destructive: true }),
|
|
162
142
|
})), 'menu-group');
|
|
163
143
|
}
|
package/dist/menu.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,KAAK,EACL,KAAK,EACL,MAAM,EACN,MAAM,GAKP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,KAAK,EACL,oBAAoB,GAIrB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;;AAExD,OAAO,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAEpE,4FAA4F;AAC5F,SAAS,UAAU,CAAC,KAAwB,EAAE,OAAe;IAC3D,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACpE,IAAI,CAAC,IAAI,EAAE,CAAC;QACV,OAAO,CAAC,IAAI,CACV,qBAAqB,OAAO,mDAAmD;YAC7E,oFAAoF,CACvF,CAAC;QACF,OAAO;IACT,CAAC;IACD,MAAM,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,aAA2B,CAAC;IAC5D,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;AAC3D,CAAC;AAED;;;GAGG;AACH,SAA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gBAAgB;;2FAIf,SAAS;kBANrB,SAAS;mBAAC;oBACT,QAAQ,EAAE,YAAY;oBACtB,QAAQ,EAAE,gBAAgB;oBAC1B,IAAI,EAAE,EAAE,iBAAiB,EAAE,QAAQ,EAAE;oBACrC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC;iBACvE;;AA2BD;;;;;GAKG;AAOH,MAAM,OAAO,OAAO;IAClB;QACE,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAC/C,MAAM,CAAC,UAAU,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,CAAC;uGAJU,OAAO;2FAAP,OAAO,8GAFP,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,0BAF5D,gBAAgB;;2FAIf,OAAO;kBANnB,SAAS;mBAAC;oBACT,QAAQ,EAAE,UAAU;oBACpB,QAAQ,EAAE,gBAAgB;oBAC1B,IAAI,EAAE,EAAE,iBAAiB,EAAE,QAAQ,EAAE;oBACrC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC;iBACvE","sourcesContent":["/**\n * Menus written as elements: `<menu-bar>`, `<menu-group>`, `<menu-item>` and `<menu-separator>`.\n * They draw nothing themselves. Each item registers itself with the menu it is written in, through\n * `MENU_MODEL`, and the menu's owner draws it: `Menus` sends a `<menu-bar>` to the host, and a\n * `[contextMenu]` or a `<native-header-item [menu]>` reads a template of items.\n */\nimport {\n Component,\n DestroyRef,\n ElementRef,\n booleanAttribute,\n computed,\n inject,\n input,\n model,\n output,\n signal,\n type OnChanges,\n type OutputEmitterRef,\n type Signal,\n type SimpleChanges,\n} from '@angular/core';\nimport {\n MENU_MODEL,\n Menus,\n menuModelInTreeOrder,\n type MenuEntry,\n type MenuGroupRole,\n type MenuRole,\n} from '@ng-native/device';\nimport type { EngineNode } from '@ng-native/fabric';\nimport { ControlledModel } from './controlled-model.ts';\n\nexport { menuModelInTreeOrder, treeOrder } from '@ng-native/device';\n\n/** Register `entry` with the menu the element is written in, and take it out as it goes. */\nfunction registerIn(entry: Signal<MenuEntry>, element: string): void {\n const menu = inject(MENU_MODEL, { optional: true, skipSelf: true });\n if (!menu) {\n console.warn(\n `[angular-native] <${element}> is outside a menu: write it in a <menu-bar>, a ` +\n '<menu-group>, or a template given to [contextMenu] or <native-header-item [menu]>.',\n );\n return;\n }\n const node = inject(ElementRef).nativeElement as EngineNode;\n inject(DestroyRef).onDestroy(menu.register(entry, node));\n}\n\n/**\n * Count an output's listeners, so an item knows whether the app handles it: as a signal, so the\n * menu follows a listener added or removed after it was first sent.\n */\nfunction listened(emitter: OutputEmitterRef<void>): Signal<boolean> {\n const listeners = signal(0);\n const subscribe = emitter.subscribe.bind(emitter);\n emitter.subscribe = (callback) => {\n listeners.update((count) => count + 1);\n const subscription = subscribe(callback);\n let stopped = false;\n return {\n unsubscribe: () => {\n if (stopped) return;\n stopped = true;\n listeners.update((count) => count - 1);\n subscription.unsubscribe();\n },\n };\n };\n return computed(() => listeners() > 0);\n}\n\n/**\n * One item of a menu. `(select)` fires when it is chosen, and a `[(checked)]` item toggles. A\n * one-way `[checked]` stays as the app binds it, so a menu of choices checks the one the app keeps.\n * An item with a `menuRole` and no `(select)` does what the OS does for that role.\n */\n@Component({\n selector: 'menu-item',\n template: '',\n host: { '[style.display]': '\"none\"' },\n})\nexport class MenuItem implements OnChanges {\n readonly label = input('');\n /** What the item is for, where the OS has a standard one: it replaces that default. */\n readonly menuRole = input<MenuRole>();\n /** `mod+s`: Cmd on Apple's OSes, Ctrl on Android. */\n readonly shortcut = input<string>();\n readonly disabled = input(false, { transform: booleanAttribute });\n /** A check mark. Bound two-way, it toggles as the item is chosen. */\n readonly checked = model<boolean | undefined>(undefined);\n private readonly checkedModel = new ControlledModel(this.checked, 'checked');\n readonly destructive = input(false, { transform: booleanAttribute });\n readonly subtitle = input<string>();\n /** An SF Symbol, on Apple's OSes. */\n readonly sfSymbol = input<string>();\n /** A drawable resource's name, on Android. */\n readonly icon = input<string>();\n readonly select = output<void>();\n\n private readonly handled = listened(this.select);\n\n constructor() {\n registerIn(\n computed(() => {\n const checked = this.checked();\n const role = this.menuRole();\n // An item with a role and no handler is the OS's: no `select`, so the host does it.\n const own = !role || this.handled() || checked !== undefined;\n return {\n label: this.label(),\n ...(role && { menuRole: role }),\n ...(this.shortcut() && { shortcut: this.shortcut() }),\n ...(this.disabled() && { disabled: true }),\n ...(checked !== undefined && { checked }),\n ...(this.destructive() && { destructive: true }),\n ...(this.subtitle() && { subtitle: this.subtitle() }),\n ...(this.sfSymbol() && { sfSymbol: this.sfSymbol() }),\n ...(this.icon() && { icon: this.icon() }),\n ...(own && { select: this.choose }),\n };\n }),\n 'menu-item',\n );\n }\n\n ngOnChanges(changes: SimpleChanges): void {\n this.checkedModel.noteChanges(changes);\n }\n\n /** One handler for the item's life: the id a host reports a choice by. See `menuActionId`. */\n private readonly choose = (): void => {\n if (this.disabled()) return;\n const checked = this.checked();\n if (checked !== undefined) this.checkedModel.propose(!checked);\n this.select.emit();\n };\n}\n\n/** A line between items. */\n@Component({\n selector: 'menu-separator',\n template: '',\n host: { '[style.display]': '\"none\"' },\n})\nexport class MenuSeparator {\n constructor() {\n registerIn(\n computed(() => ({ separator: true }) as const),\n 'menu-separator',\n );\n }\n}\n\n/**\n * A submenu, a section of the menu it is in (`inline`), or in a `<menu-bar>` a menu of the bar. In\n * a bar, a `menuRole` of `app`, `file`, `edit`, `view`, `window` or `help` adds its items to that\n * standard menu.\n */\n@Component({\n selector: 'menu-group',\n template: '<ng-content />',\n host: { '[style.display]': '\"none\"' },\n providers: [{ provide: MENU_MODEL, useFactory: menuModelInTreeOrder }],\n})\nexport class MenuGroup {\n readonly label = input('');\n readonly menuRole = input<MenuGroupRole>();\n readonly inline = input(false, { transform: booleanAttribute });\n readonly sfSymbol = input<string>();\n readonly icon = input<string>();\n readonly destructive = input(false, { transform: booleanAttribute });\n\n private readonly own = inject(MENU_MODEL, { self: true });\n\n constructor() {\n registerIn(\n computed(() => ({\n label: this.label(),\n items: this.own.entries(),\n ...(this.menuRole() && { group: this.menuRole() }),\n ...(this.inline() && { inline: true }),\n ...(this.sfSymbol() && { sfSymbol: this.sfSymbol() }),\n ...(this.icon() && { icon: this.icon() }),\n ...(this.destructive() && { destructive: true }),\n })),\n 'menu-group',\n );\n }\n}\n\n/**\n * The app's menus in the menu bar, merged with the menus every desktop app has: App, Edit, View,\n * Window and Help. On macOS and iPadOS it is the menu bar. On iPhone and Android nothing is drawn,\n * and the items' shortcuts work from a hardware keyboard. It can be anywhere in the app, and\n * follows what its items say for as long as it is there.\n */\n@Component({\n selector: 'menu-bar',\n template: '<ng-content />',\n host: { '[style.display]': '\"none\"' },\n providers: [{ provide: MENU_MODEL, useFactory: menuModelInTreeOrder }],\n})\nexport class MenuBar {\n constructor() {\n const own = inject(MENU_MODEL, { self: true });\n inject(DestroyRef).onDestroy(inject(Menus).addMenuBar(own.entries));\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"menu.js","sourceRoot":"","sources":["../src/menu.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,KAAK,EACL,KAAK,EACL,MAAM,GAIP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,KAAK,EACL,oBAAoB,EAIpB,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;;AAE3C,OAAO,EAAE,oBAAoB,EAA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UAAU,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;IACtE,CAAC;uGAJU,OAAO;2FAAP,OAAO,8GAFP,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,0BAF5D,gBAAgB;;2FAIf,OAAO;kBANnB,SAAS;mBAAC;oBACT,QAAQ,EAAE,UAAU;oBACpB,QAAQ,EAAE,gBAAgB;oBAC1B,IAAI,EAAE,EAAE,iBAAiB,EAAE,QAAQ,EAAE;oBACrC,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC;iBACvE","sourcesContent":["/**\n * Menus written as elements: `<menu-bar>`, `<menu-group>`, `<menu-item>` and `<menu-separator>`.\n * They draw nothing themselves. Each item registers itself with the menu it is written in, through\n * `MENU_MODEL`, and the menu's owner draws it: `Menus` sends a `<menu-bar>` to the host, and a\n * `[contextMenu]` or a `<native-header-item [menu]>` reads a template of items.\n */\nimport {\n Component,\n DestroyRef,\n ElementRef,\n booleanAttribute,\n computed,\n inject,\n input,\n model,\n output,\n type OnChanges,\n type Signal,\n type SimpleChanges,\n} from '@angular/core';\nimport {\n MENU_MODEL,\n Menus,\n menuModelInTreeOrder,\n type MenuEntry,\n type MenuGroupRole,\n type MenuRole,\n outputListened,\n} from '@ng-native/device';\nimport type { EngineNode } from '@ng-native/fabric';\nimport { ControlledModel } from './controlled-model.ts';\nimport type { ButtonIcon } from './native-button.ts';\nimport { iconFields } from './svg-icon.ts';\n\nexport { menuModelInTreeOrder, treeOrder } from '@ng-native/device';\n\n/** Register `entry` with the menu the element is written in, and take it out as it goes. */\nfunction registerIn(entry: Signal<MenuEntry>, element: string): void {\n const menu = inject(MENU_MODEL, { optional: true, skipSelf: true });\n if (!menu) {\n console.warn(\n `[angular-native] <${element}> is outside a menu: write it in a <menu-bar>, a ` +\n '<menu-group>, or a template given to [contextMenu] or <native-header-item [menu]>.',\n );\n return;\n }\n const node = inject(ElementRef).nativeElement as EngineNode;\n inject(DestroyRef).onDestroy(menu.register(entry, node));\n}\n\n/**\n * One item of a menu. `(select)` fires when it is chosen, and a `[(checked)]` item toggles. A\n * one-way `[checked]` stays as the app binds it, so a menu of choices checks the one the app keeps.\n * An item with a `menuRole` and no `(select)` does what the OS does for that role.\n */\n@Component({\n selector: 'menu-item',\n template: '',\n host: { '[style.display]': '\"none\"' },\n})\nexport class MenuItem implements OnChanges {\n readonly label = input('');\n /** What the item is for, where the OS has a standard one: it replaces that default. */\n readonly menuRole = input<MenuRole>();\n /** `mod+s`: Cmd on Apple's OSes, Ctrl on Android. */\n readonly shortcut = input<string>();\n readonly disabled = input(false, { transform: booleanAttribute });\n /** A check mark. Bound two-way, it toggles as the item is chosen. */\n readonly checked = model<boolean | undefined>(undefined);\n private readonly checkedModel = new ControlledModel(this.checked, 'checked');\n readonly destructive = input(false, { transform: booleanAttribute });\n readonly subtitle = input<string>();\n /** An SF Symbol, on Apple's OSes. */\n readonly sfSymbol = input<string>();\n /**\n * The picture: a drawable resource's name, on Android, or a `ButtonIcon` as `<native-button>`\n * takes, `{ sfSymbol }`, `{ drawable }`, or an icon's SVG markup, `{ svg }`, in a macOS menu and\n * in a Linux tray icon's menu.\n */\n readonly icon = input<string | ButtonIcon>();\n readonly select = output<void>();\n\n private readonly handled = outputListened(this.select);\n\n constructor() {\n registerIn(\n computed(() => {\n const checked = this.checked();\n const role = this.menuRole();\n // An item with a role and no handler is the OS's: no `select`, so the host does it.\n const own = !role || this.handled() || checked !== undefined;\n return {\n label: this.label(),\n ...(role && { menuRole: role }),\n ...(this.shortcut() && { shortcut: this.shortcut() }),\n ...(this.disabled() && { disabled: true }),\n ...(checked !== undefined && { checked }),\n ...(this.destructive() && { destructive: true }),\n ...(this.subtitle() && { subtitle: this.subtitle() }),\n ...iconFields(this.sfSymbol(), this.icon(), 'menu-item', true),\n ...(own && { select: this.choose }),\n };\n }),\n 'menu-item',\n );\n }\n\n ngOnChanges(changes: SimpleChanges): void {\n this.checkedModel.noteChanges(changes);\n }\n\n /** One handler for the item's life: the id a host reports a choice by. See `menuActionId`. */\n private readonly choose = (): void => {\n if (this.disabled()) return;\n const checked = this.checked();\n if (checked !== undefined) this.checkedModel.propose(!checked);\n this.select.emit();\n };\n}\n\n/** A line between items. */\n@Component({\n selector: 'menu-separator',\n template: '',\n host: { '[style.display]': '\"none\"' },\n})\nexport class MenuSeparator {\n constructor() {\n registerIn(\n computed(() => ({ separator: true }) as const),\n 'menu-separator',\n );\n }\n}\n\n/**\n * A submenu, a section of the menu it is in (`inline`), or in a `<menu-bar>` a menu of the bar. In\n * a bar, a `menuRole` of `app`, `file`, `edit`, `view`, `window` or `help` adds its items to that\n * standard menu.\n */\n@Component({\n selector: 'menu-group',\n template: '<ng-content />',\n host: { '[style.display]': '\"none\"' },\n providers: [{ provide: MENU_MODEL, useFactory: menuModelInTreeOrder }],\n})\nexport class MenuGroup {\n readonly label = input('');\n readonly menuRole = input<MenuGroupRole>();\n readonly inline = input(false, { transform: booleanAttribute });\n readonly sfSymbol = input<string>();\n /** A drawable's name, or a `ButtonIcon`, as on `<menu-item>`. */\n readonly icon = input<string | ButtonIcon>();\n readonly destructive = input(false, { transform: booleanAttribute });\n\n private readonly own = inject(MENU_MODEL, { self: true });\n\n constructor() {\n registerIn(\n computed(() => ({\n label: this.label(),\n items: this.own.entries(),\n ...(this.menuRole() && { group: this.menuRole() }),\n ...(this.inline() && { inline: true }),\n ...iconFields(this.sfSymbol(), this.icon(), 'menu-group', true),\n ...(this.destructive() && { destructive: true }),\n })),\n 'menu-group',\n );\n }\n}\n\n/**\n * The app's menus in the menu bar, merged with the menus every desktop app has: App, Edit, View,\n * Window and Help. On macOS and iPadOS it is the menu bar. On iPhone and Android nothing is drawn,\n * and the items' shortcuts work from a hardware keyboard. It can be anywhere in the app, and\n * follows what its items say for as long as it is there.\n */\n@Component({\n selector: 'menu-bar',\n template: '<ng-content />',\n host: { '[style.display]': '\"none\"' },\n providers: [{ provide: MENU_MODEL, useFactory: menuModelInTreeOrder }],\n})\nexport class MenuBar {\n constructor() {\n const own = inject(MENU_MODEL, { self: true });\n inject(DestroyRef).onDestroy(inject(Menus).addMenuBar(own.entries));\n }\n}\n"]}
|
package/dist/native-button.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type ControlSize } from '@ng-native/device';
|
|
2
|
+
import { type ImageURISource } from './image.ts';
|
|
2
3
|
import { ControlBase } from './pressable.ts';
|
|
3
4
|
import * as i0 from "@angular/core";
|
|
4
5
|
/**
|
|
@@ -8,8 +9,9 @@ import * as i0 from "@angular/core";
|
|
|
8
9
|
export type ButtonKind = 'default' | 'cancel' | 'destructive' | 'plain';
|
|
9
10
|
/**
|
|
10
11
|
* A button's picture, as on `<native-tab>`: an SF Symbol on Apple's OSes, a drawable on Android, or
|
|
11
|
-
* an icon's SVG markup, such as an `@ng-icons` set's
|
|
12
|
-
*
|
|
12
|
+
* an icon's SVG markup, such as an `@ng-icons` set's. macOS and Linux draw the markup themselves,
|
|
13
|
+
* and iOS and Android draw it through the renderer `SVG_ICON_RENDERER` provides. It is drawn in the
|
|
14
|
+
* button's text colour, as a symbol is, and an SF Symbol given too wins on macOS.
|
|
13
15
|
*/
|
|
14
16
|
export type ButtonIcon = {
|
|
15
17
|
readonly sfSymbol: string;
|
|
@@ -45,7 +47,27 @@ export declare class NativeButton extends ControlBase {
|
|
|
45
47
|
readonly icon: import("@angular/core").InputSignal<ButtonIcon | undefined>;
|
|
46
48
|
protected readonly symbol: import("@angular/core").Signal<string | undefined>;
|
|
47
49
|
protected readonly drawableResource: import("@angular/core").Signal<string | undefined>;
|
|
50
|
+
private readonly svgRenderer;
|
|
51
|
+
private readonly svgHost;
|
|
52
|
+
private readonly errors;
|
|
53
|
+
protected readonly android: boolean;
|
|
54
|
+
/** Where the markup is drawn here, by the app's renderer, as an image. */
|
|
55
|
+
private readonly drawsSvg;
|
|
48
56
|
protected readonly svgIcon: import("@angular/core").Signal<string | undefined>;
|
|
57
|
+
/** The markup drawn as an image, on iOS and Android, once the renderer has answered. */
|
|
58
|
+
private readonly drawnSvg;
|
|
59
|
+
/** The image iOS draws before the title, tinted as a symbol is. */
|
|
60
|
+
protected readonly iosPicture: import("@angular/core").Signal<ImageURISource | undefined>;
|
|
61
|
+
/** Android: the image before the label, a drawable's or the drawn markup. */
|
|
62
|
+
protected readonly androidPicture: import("@angular/core").Signal<ImageURISource | undefined>;
|
|
63
|
+
/** The label's colour, which an Android icon is tinted in: black, as text is, where none is set. */
|
|
64
|
+
protected readonly tint: import("@angular/core").WritableSignal<string | undefined>;
|
|
65
|
+
constructor();
|
|
66
|
+
/**
|
|
67
|
+
* The markup drawn once by the app's renderer, where the platform draws no SVG itself. An answer
|
|
68
|
+
* for an icon the button no longer has is dropped.
|
|
69
|
+
*/
|
|
70
|
+
private drawSvg;
|
|
49
71
|
/**
|
|
50
72
|
* Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press
|
|
51
73
|
* it twice.
|
package/dist/native-button.js
CHANGED
|
@@ -1,8 +1,19 @@
|
|
|
1
|
-
import { Component, computed, forwardRef, input } from '@angular/core';
|
|
1
|
+
import { Component, ErrorHandler, ViewContainerRef, computed, effect, forwardRef, inject, input, signal, } from '@angular/core';
|
|
2
2
|
import { isApplePlatform, nativePlatform, registerViewName, } from '@ng-native/fabric';
|
|
3
|
+
import { SVG_ICON_RENDERER } from '@ng-native/device';
|
|
4
|
+
import { Image } from "./image.js";
|
|
3
5
|
import { ControlBase, TouchableBase } from "./pressable.js";
|
|
4
6
|
import { svgIconMarkup } from "./svg-icon.js";
|
|
5
7
|
import * as i0 from "@angular/core";
|
|
8
|
+
/** Platforms already told that a button's SVG icon has nothing to draw it. */
|
|
9
|
+
const warnedNoRenderer = new Set();
|
|
10
|
+
/**
|
|
11
|
+
* The side of an SVG icon drawn for iOS, in points. The button sizes it to its title's font, so
|
|
12
|
+
* it is drawn large enough for the largest text size to scale it down rather than up.
|
|
13
|
+
*/
|
|
14
|
+
const IOS_SVG_SIZE = 40;
|
|
15
|
+
/** The side of an Android button's icon, in points: Material's for an icon in a button. */
|
|
16
|
+
const ANDROID_ICON_SIZE = 18;
|
|
6
17
|
/**
|
|
7
18
|
* The button on Apple's OSes is the host's: NSButton on macOS and UIButton on iOS. Android has no
|
|
8
19
|
* platform button React Native draws, so there it is a view this component makes pressable.
|
|
@@ -47,8 +58,66 @@ export class NativeButton extends ControlBase {
|
|
|
47
58
|
return this.drawableName() ?? (icon && 'drawable' in icon ? icon.drawable : undefined);
|
|
48
59
|
}, /* @ts-ignore */
|
|
49
60
|
...(ngDevMode ? [{ debugName: "drawableResource" }] : /* istanbul ignore next */ []));
|
|
50
|
-
|
|
61
|
+
svgRenderer = inject(SVG_ICON_RENDERER);
|
|
62
|
+
svgHost = inject(ViewContainerRef);
|
|
63
|
+
errors = inject(ErrorHandler);
|
|
64
|
+
android = nativePlatform() === 'android';
|
|
65
|
+
/** Where the markup is drawn here, by the app's renderer, as an image. */
|
|
66
|
+
drawsSvg = this.android || nativePlatform() === 'ios';
|
|
67
|
+
svgIcon = computed(() => svgIconMarkup(this.icon(), 'native-button', !this.drawsSvg, 'macOS, Linux, iOS and Android'), /* @ts-ignore */
|
|
51
68
|
...(ngDevMode ? [{ debugName: "svgIcon" }] : /* istanbul ignore next */ []));
|
|
69
|
+
/** The markup drawn as an image, on iOS and Android, once the renderer has answered. */
|
|
70
|
+
drawnSvg = this.drawSvg();
|
|
71
|
+
/** The image iOS draws before the title, tinted as a symbol is. */
|
|
72
|
+
iosPicture = computed(() => this.android ? undefined : this.drawnSvg(), /* @ts-ignore */
|
|
73
|
+
...(ngDevMode ? [{ debugName: "iosPicture" }] : /* istanbul ignore next */ []));
|
|
74
|
+
/** Android: the image before the label, a drawable's or the drawn markup. */
|
|
75
|
+
androidPicture = computed(() => {
|
|
76
|
+
if (!this.android)
|
|
77
|
+
return undefined;
|
|
78
|
+
const drawable = this.drawableResource();
|
|
79
|
+
if (drawable)
|
|
80
|
+
return { uri: drawable };
|
|
81
|
+
return this.drawnSvg();
|
|
82
|
+
}, /* @ts-ignore */
|
|
83
|
+
...(ngDevMode ? [{ debugName: "androidPicture" }] : /* istanbul ignore next */ []));
|
|
84
|
+
/** The label's colour, which an Android icon is tinted in: black, as text is, where none is set. */
|
|
85
|
+
tint = signal(undefined, /* @ts-ignore */
|
|
86
|
+
...(ngDevMode ? [{ debugName: "tint" }] : /* istanbul ignore next */ []));
|
|
87
|
+
constructor() {
|
|
88
|
+
super();
|
|
89
|
+
// Only a button with an icon follows its colour: a watch is a look at every commit.
|
|
90
|
+
effect((onCleanup) => {
|
|
91
|
+
if (!this.androidPicture())
|
|
92
|
+
return;
|
|
93
|
+
const follow = (colour) => this.tint.set(colour ?? 'black');
|
|
94
|
+
follow(this.engine.colour(this.node));
|
|
95
|
+
onCleanup(this.engine.watchColour(this.node, follow));
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The markup drawn once by the app's renderer, where the platform draws no SVG itself. An answer
|
|
100
|
+
* for an icon the button no longer has is dropped.
|
|
101
|
+
*/
|
|
102
|
+
drawSvg() {
|
|
103
|
+
const drawn = signal(undefined, /* @ts-ignore */
|
|
104
|
+
...(ngDevMode ? [{ debugName: "drawn" }] : /* istanbul ignore next */ []));
|
|
105
|
+
if (!this.drawsSvg)
|
|
106
|
+
return drawn;
|
|
107
|
+
effect((onCleanup) => {
|
|
108
|
+
const markup = this.svgIcon();
|
|
109
|
+
drawn.set(undefined);
|
|
110
|
+
if (!markup)
|
|
111
|
+
return;
|
|
112
|
+
if (!this.svgRenderer)
|
|
113
|
+
return warnNoRenderer();
|
|
114
|
+
let current = true;
|
|
115
|
+
onCleanup(() => (current = false));
|
|
116
|
+
const size = this.android ? ANDROID_ICON_SIZE : IOS_SVG_SIZE;
|
|
117
|
+
this.svgRenderer.render(markup, size, this.svgHost).then((source) => current && drawn.set(source ?? undefined), (error) => this.errors.handleError(error));
|
|
118
|
+
});
|
|
119
|
+
return drawn;
|
|
120
|
+
}
|
|
52
121
|
/**
|
|
53
122
|
* Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press
|
|
54
123
|
* it twice.
|
|
@@ -84,23 +153,48 @@ export class NativeButton extends ControlBase {
|
|
|
84
153
|
super.ngOnDestroy();
|
|
85
154
|
this.stopPress?.();
|
|
86
155
|
}
|
|
87
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, deps:
|
|
88
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.
|
|
156
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
157
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.2.0", type: NativeButton, isStandalone: true, selector: "native-button", inputs: { kind: { classPropertyName: "kind", publicName: "kind", isSignal: true, isRequired: false, transformFunction: null }, controlSize: { classPropertyName: "controlSize", publicName: "controlSize", isSignal: true, isRequired: false, transformFunction: null }, sfSymbol: { classPropertyName: "sfSymbol", publicName: "sfSymbol", isSignal: true, isRequired: false, transformFunction: null }, drawableName: { classPropertyName: "drawableName", publicName: "drawable", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "kind": "kind()", "controlSize": "controlSize()", "sfSymbol": "symbol()", "drawable": "android ? undefined : drawableResource()", "svgIcon": "svgIcon()", "iconImage": "iosPicture()?.uri", "style.flexDirection": "androidPicture() ? \"row\" : undefined", "style.alignItems": "androidPicture() ? \"center\" : undefined", "style.gap": "androidPicture() ? \"8px\" : undefined", "enabled": "!pressDisabled()" } }, providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }], usesInheritance: true, ngImport: i0, template: `
|
|
158
|
+
@if (androidPicture(); as source) {
|
|
159
|
+
<image [source]="source" [tintColor]="tint()" style="width: 18px; height: 18px" />
|
|
160
|
+
}
|
|
161
|
+
<ng-content />
|
|
162
|
+
`, isInline: true, dependencies: [{ kind: "directive", type: Image, selector: "image", inputs: ["source", "src", "srcSet", "defaultSource", "loadingIndicatorSource", "resizeMode", "resizeMethod", "resizeMultiplier", "blurRadius", "capInsets", "tintColor", "fadeDuration", "progressiveRenderingEnabled", "alt", "crossOrigin", "referrerPolicy"] }] });
|
|
89
163
|
}
|
|
90
164
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, decorators: [{
|
|
91
165
|
type: Component,
|
|
92
166
|
args: [{
|
|
93
167
|
selector: 'native-button',
|
|
94
|
-
|
|
168
|
+
imports: [Image],
|
|
169
|
+
template: `
|
|
170
|
+
@if (androidPicture(); as source) {
|
|
171
|
+
<image [source]="source" [tintColor]="tint()" style="width: 18px; height: 18px" />
|
|
172
|
+
}
|
|
173
|
+
<ng-content />
|
|
174
|
+
`,
|
|
95
175
|
providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }],
|
|
96
176
|
host: {
|
|
97
177
|
'[kind]': 'kind()',
|
|
98
178
|
'[controlSize]': 'controlSize()',
|
|
99
179
|
'[sfSymbol]': 'symbol()',
|
|
100
|
-
'[drawable]': 'drawableResource()',
|
|
180
|
+
'[drawable]': 'android ? undefined : drawableResource()',
|
|
101
181
|
'[svgIcon]': 'svgIcon()',
|
|
182
|
+
'[iconImage]': 'iosPicture()?.uri',
|
|
183
|
+
'[style.flexDirection]': 'androidPicture() ? "row" : undefined',
|
|
184
|
+
'[style.alignItems]': 'androidPicture() ? "center" : undefined',
|
|
185
|
+
'[style.gap]': 'androidPicture() ? "8px" : undefined',
|
|
102
186
|
'[enabled]': '!pressDisabled()',
|
|
103
187
|
},
|
|
104
188
|
}]
|
|
105
|
-
}], propDecorators: { kind: [{ type: i0.Input, args: [{ isSignal: true, alias: "kind", required: false }] }], controlSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlSize", required: false }] }], sfSymbol: [{ type: i0.Input, args: [{ isSignal: true, alias: "sfSymbol", required: false }] }], drawableName: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawable", required: false }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }] } });
|
|
189
|
+
}], ctorParameters: () => [], propDecorators: { kind: [{ type: i0.Input, args: [{ isSignal: true, alias: "kind", required: false }] }], controlSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlSize", required: false }] }], sfSymbol: [{ type: i0.Input, args: [{ isSignal: true, alias: "sfSymbol", required: false }] }], drawableName: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawable", required: false }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }] } });
|
|
190
|
+
/** Says once, in development, that a button's SVG icon has nothing to draw it, so it shows none. */
|
|
191
|
+
function warnNoRenderer() {
|
|
192
|
+
const os = nativePlatform();
|
|
193
|
+
if ((typeof ngDevMode !== 'undefined' && !ngDevMode) || warnedNoRenderer.has(os))
|
|
194
|
+
return;
|
|
195
|
+
warnedNoRenderer.add(os);
|
|
196
|
+
console.warn(`[angular-native] <native-button> has an SVG icon and nothing to draw it on ${os}, so it ` +
|
|
197
|
+
`shows none. Add withSvgIcons(SvgImages) to provideNativeRouter (withSvgIcons from ` +
|
|
198
|
+
`@ng-native/router, SvgImages from @ng-native/icons), or provide SVG_ICON_RENDERER.`);
|
|
199
|
+
}
|
|
106
200
|
//# sourceMappingURL=native-button.js.map
|