@ng-native/components 0.26.1 → 0.28.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/ContextMenuPopup.kt +61 -19
- package/android/src/main/java/dev/ngnative/components/MenusModule.kt +22 -0
- package/android/src/main/java/dev/ngnative/components/Shortcut.kt +13 -4
- package/dist/context-menu.d.ts +14 -6
- package/dist/context-menu.js +30 -28
- package/dist/context-menu.js.map +1 -1
- package/dist/drag-and-drop.d.ts +4 -4
- package/dist/drag-and-drop.js +6 -6
- package/dist/drag-and-drop.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/menu.d.ts +7 -4
- package/dist/menu.js +10 -4
- package/dist/menu.js.map +1 -1
- package/dist/modal.d.ts +12 -8
- package/dist/modal.js +8 -8
- package/dist/modal.js.map +1 -1
- package/dist/native-button.d.ts +13 -3
- package/dist/native-button.js +12 -5
- package/dist/native-button.js.map +1 -1
- package/dist/press-menu.d.ts +39 -0
- package/dist/press-menu.js +76 -0
- package/dist/press-menu.js.map +1 -0
- package/dist/pressable.d.ts +3 -0
- package/dist/pressable.js +6 -1
- package/dist/pressable.js.map +1 -1
- package/dist/reanimated.js +27 -3
- package/dist/reanimated.js.map +1 -1
- package/dist/safe-area-provider.js +9 -7
- package/dist/safe-area-provider.js.map +1 -1
- package/dist/settled-updates.d.ts +55 -0
- package/dist/settled-updates.js +77 -0
- package/dist/settled-updates.js.map +1 -0
- package/dist/sidebar-item.d.ts +19 -4
- package/dist/sidebar-item.js +33 -6
- package/dist/sidebar-item.js.map +1 -1
- package/dist/sidebar-section.js +3 -2
- package/dist/sidebar-section.js.map +1 -1
- package/dist/stand-ins/reanimated.d.ts +5 -0
- package/dist/stand-ins/reanimated.js +7 -0
- package/dist/stand-ins/reanimated.js.map +1 -1
- package/dist/sticky-rows.d.ts +120 -25
- package/dist/sticky-rows.js +265 -65
- package/dist/sticky-rows.js.map +1 -1
- package/dist/svg-icon.d.ts +9 -0
- package/dist/svg-icon.js +37 -0
- package/dist/svg-icon.js.map +1 -0
- package/dist/virtual-list-sticky-level.d.ts +39 -0
- package/dist/virtual-list-sticky-level.js +82 -0
- package/dist/virtual-list-sticky-level.js.map +1 -0
- package/dist/virtual-list-sticky.d.ts +19 -0
- package/dist/virtual-list-sticky.js +13 -0
- package/dist/virtual-list-sticky.js.map +1 -0
- package/dist/virtual-list.d.ts +6 -2
- package/dist/virtual-list.js +60 -43
- package/dist/virtual-list.js.map +1 -1
- package/dist/worklet-style.d.ts +11 -0
- package/dist/worklet-style.js +15 -1
- package/dist/worklet-style.js.map +1 -1
- package/dist/worklets.d.ts +5 -1
- package/dist/worklets.js.map +1 -1
- package/dist/written-props.js +1 -0
- package/dist/written-props.js.map +1 -1
- package/package.json +3 -3
package/dist/menu.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { Component, DestroyRef, ElementRef, booleanAttribute, computed, inject, input, model, output, signal, } from '@angular/core';
|
|
8
8
|
import { MENU_MODEL, Menus, menuModelInTreeOrder, } from '@ng-native/device';
|
|
9
|
+
import { ControlledModel } from "./controlled-model.js";
|
|
9
10
|
import * as i0 from "@angular/core";
|
|
10
11
|
export { menuModelInTreeOrder, treeOrder } from '@ng-native/device';
|
|
11
12
|
/** Register `entry` with the menu the element is written in, and take it out as it goes. */
|
|
@@ -44,8 +45,9 @@ function listened(emitter) {
|
|
|
44
45
|
return computed(() => listeners() > 0);
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
* One item of a menu. `(select)` fires when it is chosen, and a `[(checked)]` item toggles.
|
|
48
|
-
*
|
|
48
|
+
* One item of a menu. `(select)` fires when it is chosen, and a `[(checked)]` item toggles. A
|
|
49
|
+
* one-way `[checked]` stays as the app binds it, so a menu of choices checks the one the app keeps.
|
|
50
|
+
* An item with a `menuRole` and no `(select)` does what the OS does for that role.
|
|
49
51
|
*/
|
|
50
52
|
export class MenuItem {
|
|
51
53
|
label = input('', /* @ts-ignore */
|
|
@@ -60,6 +62,7 @@ export class MenuItem {
|
|
|
60
62
|
/** A check mark. Bound two-way, it toggles as the item is chosen. */
|
|
61
63
|
checked = model(undefined, /* @ts-ignore */
|
|
62
64
|
...(ngDevMode ? [{ debugName: "checked" }] : /* istanbul ignore next */ []));
|
|
65
|
+
checkedModel = new ControlledModel(this.checked, 'checked');
|
|
63
66
|
destructive = input(false, { ...(ngDevMode ? { debugName: "destructive" } : /* istanbul ignore next */ {}), transform: booleanAttribute });
|
|
64
67
|
subtitle = input(/* @ts-ignore */
|
|
65
68
|
...(ngDevMode ? [undefined, { debugName: "subtitle" }] : /* istanbul ignore next */ []));
|
|
@@ -91,17 +94,20 @@ export class MenuItem {
|
|
|
91
94
|
};
|
|
92
95
|
}), 'menu-item');
|
|
93
96
|
}
|
|
97
|
+
ngOnChanges(changes) {
|
|
98
|
+
this.checkedModel.noteChanges(changes);
|
|
99
|
+
}
|
|
94
100
|
/** One handler for the item's life: the id a host reports a choice by. See `menuActionId`. */
|
|
95
101
|
choose = () => {
|
|
96
102
|
if (this.disabled())
|
|
97
103
|
return;
|
|
98
104
|
const checked = this.checked();
|
|
99
105
|
if (checked !== undefined)
|
|
100
|
-
this.
|
|
106
|
+
this.checkedModel.propose(!checked);
|
|
101
107
|
this.select.emit();
|
|
102
108
|
};
|
|
103
109
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: MenuItem, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
104
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.0", type: MenuItem, isStandalone: true, selector: "menu-item", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, menuRole: { classPropertyName: "menuRole", publicName: "menuRole", isSignal: true, isRequired: false, transformFunction: null }, shortcut: { classPropertyName: "shortcut", publicName: "shortcut", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, destructive: { classPropertyName: "destructive", publicName: "destructive", isSignal: true, isRequired: false, transformFunction: null }, subtitle: { classPropertyName: "subtitle", publicName: "subtitle", isSignal: true, isRequired: false, transformFunction: null }, sfSymbol: { classPropertyName: "sfSymbol", publicName: "sfSymbol", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", select: "select" }, host: { properties: { "style.display": "\"none\"" } }, ngImport: i0, template: '', isInline: true });
|
|
110
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.0", type: MenuItem, isStandalone: true, selector: "menu-item", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, menuRole: { classPropertyName: "menuRole", publicName: "menuRole", isSignal: true, isRequired: false, transformFunction: null }, shortcut: { classPropertyName: "shortcut", publicName: "shortcut", isSignal: true, isRequired: false, transformFunction: null }, disabled: { classPropertyName: "disabled", publicName: "disabled", isSignal: true, isRequired: false, transformFunction: null }, checked: { classPropertyName: "checked", publicName: "checked", isSignal: true, isRequired: false, transformFunction: null }, destructive: { classPropertyName: "destructive", publicName: "destructive", isSignal: true, isRequired: false, transformFunction: null }, subtitle: { classPropertyName: "subtitle", publicName: "subtitle", isSignal: true, isRequired: false, transformFunction: null }, sfSymbol: { classPropertyName: "sfSymbol", publicName: "sfSymbol", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { checked: "checkedChange", select: "select" }, host: { properties: { "style.display": "\"none\"" } }, usesOnChanges: true, ngImport: i0, template: '', isInline: true });
|
|
105
111
|
}
|
|
106
112
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: MenuItem, decorators: [{
|
|
107
113
|
type: Component,
|
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,GAGP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,UAAU,EACV,KAAK,EACL,oBAAoB,GAIrB,MAAM,mBAAmB,CAAC;;AAG3B,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,SAAS,QAAQ,CAAC,OAA+B;IAC/C,MAAM,SAAS,GAAG,MAAM,CAAC,CAAC;kFAAC,CAAC;IAC5B,MAAM,SAAS,GAAG,OAAO,CAAC,SAAS,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IAClD,OAAO,CAAC,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,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 OutputEmitterRef,\n type Signal,\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';\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. An\n * 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 {\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 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 /** 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.checked.set(!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,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,SAAS,QAAQ,CAAC,OAA+B;IAC/C,MAAM,SAAS,GAAG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T,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"]}
|
package/dist/modal.d.ts
CHANGED
|
@@ -3,8 +3,12 @@ import { type EngineNode } from '@ng-native/fabric';
|
|
|
3
3
|
import { ViewBase } from './view-base.ts';
|
|
4
4
|
import * as i0 from "@angular/core";
|
|
5
5
|
export type ModalPresentationStyle = 'fullScreen' | 'pageSheet' | 'formSheet' | 'overFullScreen';
|
|
6
|
-
/**
|
|
7
|
-
|
|
6
|
+
/**
|
|
7
|
+
* What `anchor` takes: an element, its `ElementRef`, or a component such as a `<pressable>`. A
|
|
8
|
+
* template reference types as `HTMLElement` for an element and as its class for a component, so
|
|
9
|
+
* both are named; at run time an element is its engine node, and a component's is its `node`.
|
|
10
|
+
*/
|
|
11
|
+
export type ModalAnchor = ElementRef | EngineNode | HTMLElement | ViewBase | {
|
|
8
12
|
readonly node: unknown;
|
|
9
13
|
} | null | undefined;
|
|
10
14
|
export type ModalOrientation = 'portrait' | 'portrait-upside-down' | 'landscape' | 'landscape-left' | 'landscape-right';
|
|
@@ -55,13 +59,13 @@ export declare class Modal extends ViewBase {
|
|
|
55
59
|
/** Android: give the modal's window a hardware-accelerated surface. */
|
|
56
60
|
readonly hardwareAccelerated: import("@angular/core").InputSignalWithTransform<boolean | undefined, unknown>;
|
|
57
61
|
/**
|
|
58
|
-
* The element the modal points at. With one, it shows as a popover at the element on macOS
|
|
59
|
-
* every other OS, iPadOS included, it shows as it would without one. Committed as the
|
|
60
|
-
* of the element's view.
|
|
62
|
+
* The element the modal points at. With one, it shows as a popover at the element on macOS and
|
|
63
|
+
* Linux; on every other OS, iPadOS included, it shows as it would without one. Committed as the
|
|
64
|
+
* react tag of the element's view.
|
|
61
65
|
*/
|
|
62
66
|
readonly anchor: import("@angular/core").InputSignal<ModalAnchor>;
|
|
63
67
|
private readonly direction;
|
|
64
|
-
/** Only
|
|
68
|
+
/** Only the desktop host reads the anchor, so only there does the modal wait for it. */
|
|
65
69
|
private readonly readsAnchor;
|
|
66
70
|
/** For the anchor view tag, which only the engine itself hands out. */
|
|
67
71
|
private readonly views;
|
|
@@ -69,8 +73,8 @@ export declare class Modal extends ViewBase {
|
|
|
69
73
|
/** The anchor's view tag, committed as `anchor`, or undefined with none. */
|
|
70
74
|
protected readonly anchorTag: import("@angular/core").WritableSignal<number | undefined>;
|
|
71
75
|
/**
|
|
72
|
-
* Whether the anchor's view has still to commit, which gives it its tag. On
|
|
73
|
-
* the host reads the anchor as it presents, and one presented without it stays a sheet.
|
|
76
|
+
* Whether the anchor's view has still to commit, which gives it its tag. On a desktop OS the modal
|
|
77
|
+
* waits: the host reads the anchor as it presents, and one presented without it stays a sheet.
|
|
74
78
|
*/
|
|
75
79
|
protected readonly awaitingAnchor: import("@angular/core").WritableSignal<boolean>;
|
|
76
80
|
protected readonly resolvedPresentationStyle: import("@angular/core").Signal<ModalPresentationStyle | undefined>;
|
package/dist/modal.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component, DestroyRef, ElementRef, Injector, afterNextRender, booleanAttribute, computed, effect, inject, input, signal, } from '@angular/core';
|
|
2
|
-
import {
|
|
2
|
+
import { DESKTOP, Direction } from '@ng-native/device';
|
|
3
3
|
import { Engine, HostEngine } from '@ng-native/fabric';
|
|
4
4
|
import { optionalBoolean } from "./transforms.js";
|
|
5
5
|
import { View } from "./view.js";
|
|
@@ -66,15 +66,15 @@ export class Modal extends ViewBase {
|
|
|
66
66
|
/** Android: give the modal's window a hardware-accelerated surface. */
|
|
67
67
|
hardwareAccelerated = input(undefined, { ...(ngDevMode ? { debugName: "hardwareAccelerated" } : /* istanbul ignore next */ {}), transform: optionalBoolean });
|
|
68
68
|
/**
|
|
69
|
-
* The element the modal points at. With one, it shows as a popover at the element on macOS
|
|
70
|
-
* every other OS, iPadOS included, it shows as it would without one. Committed as the
|
|
71
|
-
* of the element's view.
|
|
69
|
+
* The element the modal points at. With one, it shows as a popover at the element on macOS and
|
|
70
|
+
* Linux; on every other OS, iPadOS included, it shows as it would without one. Committed as the
|
|
71
|
+
* react tag of the element's view.
|
|
72
72
|
*/
|
|
73
73
|
anchor = input(/* @ts-ignore */
|
|
74
74
|
...(ngDevMode ? [undefined, { debugName: "anchor" }] : /* istanbul ignore next */ []));
|
|
75
75
|
direction = inject(Direction);
|
|
76
|
-
/** Only
|
|
77
|
-
readsAnchor = inject(
|
|
76
|
+
/** Only the desktop host reads the anchor, so only there does the modal wait for it. */
|
|
77
|
+
readsAnchor = inject(DESKTOP);
|
|
78
78
|
/** For the anchor view tag, which only the engine itself hands out. */
|
|
79
79
|
views = inject(Engine, { optional: true });
|
|
80
80
|
injector = inject(Injector);
|
|
@@ -82,8 +82,8 @@ export class Modal extends ViewBase {
|
|
|
82
82
|
anchorTag = signal(undefined, /* @ts-ignore */
|
|
83
83
|
...(ngDevMode ? [{ debugName: "anchorTag" }] : /* istanbul ignore next */ []));
|
|
84
84
|
/**
|
|
85
|
-
* Whether the anchor's view has still to commit, which gives it its tag. On
|
|
86
|
-
* the host reads the anchor as it presents, and one presented without it stays a sheet.
|
|
85
|
+
* Whether the anchor's view has still to commit, which gives it its tag. On a desktop OS the modal
|
|
86
|
+
* waits: the host reads the anchor as it presents, and one presented without it stays a sheet.
|
|
87
87
|
*/
|
|
88
88
|
awaitingAnchor = signal(false, /* @ts-ignore */
|
|
89
89
|
...(ngDevMode ? [{ debugName: "awaitingAnchor" }] : /* istanbul ignore next */ []));
|
package/dist/modal.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modal.js","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAmB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;;AAM1C,4CAA4C;AAC5C,SAAS,UAAU,CAAC,MAAmB;IACrC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,MAAM,YAAY,UAAU;QAAE,OAAO,MAAM,CAAC,aAA2B,CAAC;IAC5E,IAAI,UAAU,IAAI,MAAM;QAAE,OAAO,MAAoB,CAAC;IACtD,OAAS,MAA6B,CAAC,IAA+B,IAAI,IAAI,CAAC;AACjF,CAAC;AAKD;;;;;;;;;;;;;GAaG;AAkBH,MAAM,OAAO,KAAM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gC;wBAC7C,eAAe,EAAE,eAAe;wBAChC,iBAAiB,EAAE,iBAAiB;wBACpC,qBAAqB,EAAE,6BAA6B;wBACpD,yBAAyB,EAAE,yBAAyB;wBACpD,uBAAuB,EAAE,uBAAuB;wBAChD,wBAAwB,EAAE,wBAAwB;wBAClD,4BAA4B,EAAE,4BAA4B;wBAC1D,uBAAuB,EAAE,uBAAuB;wBAChD,UAAU,EAAE,aAAa;qBAC1B;iBACF","sourcesContent":["import {\n Component,\n DestroyRef,\n ElementRef,\n Injector,\n afterNextRender,\n booleanAttribute,\n computed,\n effect,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport { Direction, OS } from '@ng-native/device';\nimport { Engine, HostEngine, type EngineNode } from '@ng-native/fabric';\nimport { optionalBoolean } from './transforms.ts';\nimport { View } from './view.ts';\nimport { ViewBase } from './view-base.ts';\n\nexport type ModalPresentationStyle = 'fullScreen' | 'pageSheet' | 'formSheet' | 'overFullScreen';\n/** What `anchor` takes: an element, its `ElementRef`, or a component or directive with a `node`. */\nexport type ModalAnchor = ElementRef | EngineNode | { readonly node: unknown } | null | undefined;\n\n/** The engine node an anchor stands for. */\nfunction anchorNode(anchor: ModalAnchor): EngineNode | null {\n if (!anchor) return null;\n if (anchor instanceof ElementRef) return anchor.nativeElement as EngineNode;\n if ('nodeKind' in anchor) return anchor as EngineNode;\n return ((anchor as { node?: unknown }).node as EngineNode | undefined) ?? null;\n}\n\nexport type ModalOrientation =\n 'portrait' | 'portrait-upside-down' | 'landscape' | 'landscape-left' | 'landscape-right';\n\n/**\n * Content presented over everything else. Commits as `ModalHostView`.\n *\n * RN's `Modal.js` gives the native host `{position: 'absolute'}` (the engine's default for it)\n * and puts the children inside a full-bleed view carrying the backdrop colour. Without the\n * container the content has no backdrop and no layout box, so a modal renders as nothing.\n *\n * Events are element events: `(requestClose)` for the Android back button and an iOS swipe,\n * `(show)`, `(dismiss)`, and `(orientationChange)`.\n *\n * The container is pinned to the leading edge with `[side]: 0`, the same as RN's own Modal.js -\n * `left` in a left-to-right layout, `right` in a right-to-left one - so the backdrop starts from\n * the edge content actually begins at rather than always the physical left.\n */\n@Component({\n selector: 'modal',\n imports: [View],\n template: `<view [style]=\"containerStyle()\" collapsable=\"false\"><ng-content /></view>`,\n host: {\n '[visible]': 'visible() && !awaitingAnchor()',\n '[transparent]': 'transparent()',\n '[animationType]': 'animationType()',\n '[presentationStyle]': 'resolvedPresentationStyle()',\n '[supportedOrientations]': 'supportedOrientations()',\n '[allowSwipeDismissal]': 'allowSwipeDismissal()',\n '[statusBarTranslucent]': 'statusBarTranslucent()',\n '[navigationBarTranslucent]': 'navigationBarTranslucent()',\n '[hardwareAccelerated]': 'hardwareAccelerated()',\n '[anchor]': 'anchorTag()',\n },\n})\nexport class Modal extends ViewBase {\n /**\n * Whether the modal is showing. Defaults to true, as in RN. While false the engine leaves the\n * native host out of the commit, as RN's Modal returns null when hidden, because the host\n * covers the screen and takes every touch whether or not it presents; on iOS a modal that was\n * showing stays until native reports its dismissal.\n */\n readonly visible = input(true, { transform: booleanAttribute });\n /** See through to the screen behind; the container gets no backdrop. */\n readonly transparent = input(false, { transform: booleanAttribute });\n /** The container's background when not transparent. Defaults to white. */\n readonly backdropColor = input<string>();\n /** How the modal appears and leaves. Defaults to `none`. */\n readonly animationType = input<'none' | 'slide' | 'fade'>();\n /** iOS: full screen, a sheet, or over the current content. `overFullScreen` if transparent. */\n readonly presentationStyle = input<ModalPresentationStyle>();\n /** iOS: which orientations the modal may rotate to. Defaults to portrait. */\n readonly supportedOrientations = input<readonly ModalOrientation[]>();\n /** iOS: let a downward swipe dismiss the modal, reported through `(requestClose)`. */\n readonly allowSwipeDismissal = input(undefined, { transform: optionalBoolean });\n /**\n * Android: draw under the status bar. Always on under Android edge-to-edge (Expo SDK 57), where\n * React Native ignores `false`.\n */\n readonly statusBarTranslucent = input(undefined, { transform: optionalBoolean });\n /**\n * Android: draw under the navigation bar. Always on under Android edge-to-edge (Expo SDK 57),\n * where React Native ignores `false`. In an app that opts out, it needs `statusBarTranslucent`.\n */\n readonly navigationBarTranslucent = input(undefined, { transform: optionalBoolean });\n /** Android: give the modal's window a hardware-accelerated surface. */\n readonly hardwareAccelerated = input(undefined, { transform: optionalBoolean });\n\n /**\n * The element the modal points at. With one, it shows as a popover at the element on macOS; on\n * every other OS, iPadOS included, it shows as it would without one. Committed as the react tag\n * of the element's view.\n */\n readonly anchor = input<ModalAnchor>();\n\n private readonly direction = inject(Direction);\n /** Only macOS reads the anchor, so only there does the modal wait for it. */\n private readonly readsAnchor = inject(OS) === 'macos';\n /** For the anchor view tag, which only the engine itself hands out. */\n private readonly views = inject(Engine, { optional: true });\n private readonly injector = inject(Injector);\n\n /** The anchor's view tag, committed as `anchor`, or undefined with none. */\n protected readonly anchorTag = signal<number | undefined>(undefined);\n /**\n * Whether the anchor's view has still to commit, which gives it its tag. On macOS the modal waits:\n * the host reads the anchor as it presents, and one presented without it stays a sheet.\n */\n protected readonly awaitingAnchor = signal(false);\n\n protected readonly resolvedPresentationStyle = computed(\n () => this.presentationStyle() ?? (this.transparent() ? 'overFullScreen' : undefined),\n );\n\n protected readonly containerStyle = computed(() => ({\n [this.direction.rtl() ? 'right' : 'left']: 0,\n top: 0,\n flex: 1,\n backgroundColor: this.transparent() ? 'transparent' : (this.backdropColor() ?? 'white'),\n }));\n\n constructor() {\n super();\n // RN's host claims any touch that reaches it, so nothing inside the modal can hand a\n // gesture to the screen underneath.\n const stop = inject(HostEngine).setResponder(this.node, {\n onStartShouldSetResponder: () => true,\n });\n inject(DestroyRef).onDestroy(stop);\n\n effect(() => this.followAnchor(anchorNode(this.anchor())));\n\n effect(() => {\n const style = this.presentationStyle();\n if (this.transparent() && style && style !== 'overFullScreen') {\n console.warn(\n `[angular-native] <modal> is transparent, which needs presentationStyle=\"overFullScreen\" on iOS; '${style}' will not be see-through.`,\n );\n }\n });\n }\n\n /**\n * Commit the anchor's tag. A view not yet committed has none, so it is read again once the\n * commit that makes it has happened.\n */\n private followAnchor(node: EngineNode | null): void {\n if (!node) {\n // The engine commits a prop that goes as null, which takes it off the native view.\n this.anchorTag.set(undefined);\n this.awaitingAnchor.set(false);\n return;\n }\n const tag = this.views?.tagOf(node);\n if (tag != null) {\n this.anchorTag.set(tag);\n this.awaitingAnchor.set(false);\n return;\n }\n // Elsewhere nothing reads the anchor, and a modal hidden to wait for it would be dismissed.\n if (this.readsAnchor) this.awaitingAnchor.set(true);\n afterNextRender(\n () => {\n if (anchorNode(this.anchor()) !== node) return;\n this.anchorTag.set(this.views?.tagOf(node) ?? undefined);\n // Once: an anchor that has still not committed is left out, and the modal shows anyway.\n this.awaitingAnchor.set(false);\n },\n { injector: this.injector },\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"modal.js","sourceRoot":"","sources":["../src/modal.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,UAAU,EACV,QAAQ,EACR,eAAe,EACf,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,MAAM,EAAE,UAAU,EAAmB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;;AAW1C,4CAA4C;AAC5C,SAAS,UAAU,CAAC,MAAmB;IACrC,IAAI,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,MAAM,YAAY,UAAU;QAAE,OAAO,MAAM,CAAC,aAA2B,CAAC;IAC5E,IAAI,UAAU,IAAI,MAAM;QAAE,OAAO,MAAoB,CAAC;IACtD,OAAS,MAA6B,CAAC,IAA+B,IAAI,IAAI,CAAC;AACjF,CAAC;AAK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AAI,EAAE;wBACJ,WAAW,EAAE,gCAAgC;wBAC7C,eAAe,EAAE,eAAe;wBAChC,iBAAiB,EAAE,iBAAiB;wBACpC,qBAAqB,EAAE,6BAA6B;wBACpD,yBAAyB,EAAE,yBAAyB;wBACpD,uBAAuB,EAAE,uBAAuB;wBAChD,wBAAwB,EAAE,wBAAwB;wBAClD,4BAA4B,EAAE,4BAA4B;wBAC1D,uBAAuB,EAAE,uBAAuB;wBAChD,UAAU,EAAE,aAAa;qBAC1B;iBACF","sourcesContent":["import {\n Component,\n DestroyRef,\n ElementRef,\n Injector,\n afterNextRender,\n booleanAttribute,\n computed,\n effect,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport { DESKTOP, Direction } from '@ng-native/device';\nimport { Engine, HostEngine, type EngineNode } from '@ng-native/fabric';\nimport { optionalBoolean } from './transforms.ts';\nimport { View } from './view.ts';\nimport { ViewBase } from './view-base.ts';\n\nexport type ModalPresentationStyle = 'fullScreen' | 'pageSheet' | 'formSheet' | 'overFullScreen';\n/**\n * What `anchor` takes: an element, its `ElementRef`, or a component such as a `<pressable>`. A\n * template reference types as `HTMLElement` for an element and as its class for a component, so\n * both are named; at run time an element is its engine node, and a component's is its `node`.\n */\nexport type ModalAnchor =\n ElementRef | EngineNode | HTMLElement | ViewBase | { readonly node: unknown } | null | undefined;\n\n/** The engine node an anchor stands for. */\nfunction anchorNode(anchor: ModalAnchor): EngineNode | null {\n if (!anchor) return null;\n if (anchor instanceof ElementRef) return anchor.nativeElement as EngineNode;\n if ('nodeKind' in anchor) return anchor as EngineNode;\n return ((anchor as { node?: unknown }).node as EngineNode | undefined) ?? null;\n}\n\nexport type ModalOrientation =\n 'portrait' | 'portrait-upside-down' | 'landscape' | 'landscape-left' | 'landscape-right';\n\n/**\n * Content presented over everything else. Commits as `ModalHostView`.\n *\n * RN's `Modal.js` gives the native host `{position: 'absolute'}` (the engine's default for it)\n * and puts the children inside a full-bleed view carrying the backdrop colour. Without the\n * container the content has no backdrop and no layout box, so a modal renders as nothing.\n *\n * Events are element events: `(requestClose)` for the Android back button and an iOS swipe,\n * `(show)`, `(dismiss)`, and `(orientationChange)`.\n *\n * The container is pinned to the leading edge with `[side]: 0`, the same as RN's own Modal.js -\n * `left` in a left-to-right layout, `right` in a right-to-left one - so the backdrop starts from\n * the edge content actually begins at rather than always the physical left.\n */\n@Component({\n selector: 'modal',\n imports: [View],\n template: `<view [style]=\"containerStyle()\" collapsable=\"false\"><ng-content /></view>`,\n host: {\n '[visible]': 'visible() && !awaitingAnchor()',\n '[transparent]': 'transparent()',\n '[animationType]': 'animationType()',\n '[presentationStyle]': 'resolvedPresentationStyle()',\n '[supportedOrientations]': 'supportedOrientations()',\n '[allowSwipeDismissal]': 'allowSwipeDismissal()',\n '[statusBarTranslucent]': 'statusBarTranslucent()',\n '[navigationBarTranslucent]': 'navigationBarTranslucent()',\n '[hardwareAccelerated]': 'hardwareAccelerated()',\n '[anchor]': 'anchorTag()',\n },\n})\nexport class Modal extends ViewBase {\n /**\n * Whether the modal is showing. Defaults to true, as in RN. While false the engine leaves the\n * native host out of the commit, as RN's Modal returns null when hidden, because the host\n * covers the screen and takes every touch whether or not it presents; on iOS a modal that was\n * showing stays until native reports its dismissal.\n */\n readonly visible = input(true, { transform: booleanAttribute });\n /** See through to the screen behind; the container gets no backdrop. */\n readonly transparent = input(false, { transform: booleanAttribute });\n /** The container's background when not transparent. Defaults to white. */\n readonly backdropColor = input<string>();\n /** How the modal appears and leaves. Defaults to `none`. */\n readonly animationType = input<'none' | 'slide' | 'fade'>();\n /** iOS: full screen, a sheet, or over the current content. `overFullScreen` if transparent. */\n readonly presentationStyle = input<ModalPresentationStyle>();\n /** iOS: which orientations the modal may rotate to. Defaults to portrait. */\n readonly supportedOrientations = input<readonly ModalOrientation[]>();\n /** iOS: let a downward swipe dismiss the modal, reported through `(requestClose)`. */\n readonly allowSwipeDismissal = input(undefined, { transform: optionalBoolean });\n /**\n * Android: draw under the status bar. Always on under Android edge-to-edge (Expo SDK 57), where\n * React Native ignores `false`.\n */\n readonly statusBarTranslucent = input(undefined, { transform: optionalBoolean });\n /**\n * Android: draw under the navigation bar. Always on under Android edge-to-edge (Expo SDK 57),\n * where React Native ignores `false`. In an app that opts out, it needs `statusBarTranslucent`.\n */\n readonly navigationBarTranslucent = input(undefined, { transform: optionalBoolean });\n /** Android: give the modal's window a hardware-accelerated surface. */\n readonly hardwareAccelerated = input(undefined, { transform: optionalBoolean });\n\n /**\n * The element the modal points at. With one, it shows as a popover at the element on macOS and\n * Linux; on every other OS, iPadOS included, it shows as it would without one. Committed as the\n * react tag of the element's view.\n */\n readonly anchor = input<ModalAnchor>();\n\n private readonly direction = inject(Direction);\n /** Only the desktop host reads the anchor, so only there does the modal wait for it. */\n private readonly readsAnchor = inject(DESKTOP);\n /** For the anchor view tag, which only the engine itself hands out. */\n private readonly views = inject(Engine, { optional: true });\n private readonly injector = inject(Injector);\n\n /** The anchor's view tag, committed as `anchor`, or undefined with none. */\n protected readonly anchorTag = signal<number | undefined>(undefined);\n /**\n * Whether the anchor's view has still to commit, which gives it its tag. On a desktop OS the modal\n * waits: the host reads the anchor as it presents, and one presented without it stays a sheet.\n */\n protected readonly awaitingAnchor = signal(false);\n\n protected readonly resolvedPresentationStyle = computed(\n () => this.presentationStyle() ?? (this.transparent() ? 'overFullScreen' : undefined),\n );\n\n protected readonly containerStyle = computed(() => ({\n [this.direction.rtl() ? 'right' : 'left']: 0,\n top: 0,\n flex: 1,\n backgroundColor: this.transparent() ? 'transparent' : (this.backdropColor() ?? 'white'),\n }));\n\n constructor() {\n super();\n // RN's host claims any touch that reaches it, so nothing inside the modal can hand a\n // gesture to the screen underneath.\n const stop = inject(HostEngine).setResponder(this.node, {\n onStartShouldSetResponder: () => true,\n });\n inject(DestroyRef).onDestroy(stop);\n\n effect(() => this.followAnchor(anchorNode(this.anchor())));\n\n effect(() => {\n const style = this.presentationStyle();\n if (this.transparent() && style && style !== 'overFullScreen') {\n console.warn(\n `[angular-native] <modal> is transparent, which needs presentationStyle=\"overFullScreen\" on iOS; '${style}' will not be see-through.`,\n );\n }\n });\n }\n\n /**\n * Commit the anchor's tag. A view not yet committed has none, so it is read again once the\n * commit that makes it has happened.\n */\n private followAnchor(node: EngineNode | null): void {\n if (!node) {\n // The engine commits a prop that goes as null, which takes it off the native view.\n this.anchorTag.set(undefined);\n this.awaitingAnchor.set(false);\n return;\n }\n const tag = this.views?.tagOf(node);\n if (tag != null) {\n this.anchorTag.set(tag);\n this.awaitingAnchor.set(false);\n return;\n }\n // Elsewhere nothing reads the anchor, and a modal hidden to wait for it would be dismissed.\n if (this.readsAnchor) this.awaitingAnchor.set(true);\n afterNextRender(\n () => {\n if (anchorNode(this.anchor()) !== node) return;\n this.anchorTag.set(this.views?.tagOf(node) ?? undefined);\n // Once: an anchor that has still not committed is left out, and the modal shows anyway.\n this.awaitingAnchor.set(false);\n },\n { injector: this.injector },\n );\n }\n}\n"]}
|
package/dist/native-button.d.ts
CHANGED
|
@@ -6,18 +6,24 @@ import * as i0 from "@angular/core";
|
|
|
6
6
|
* On iOS they are styles only.
|
|
7
7
|
*/
|
|
8
8
|
export type ButtonKind = 'default' | 'cancel' | 'destructive' | 'plain';
|
|
9
|
-
/**
|
|
9
|
+
/**
|
|
10
|
+
* 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, on macOS and Linux. The host draws the markup
|
|
12
|
+
* in the button's text colour, as it does a symbol, and an SF Symbol given too wins on macOS.
|
|
13
|
+
*/
|
|
10
14
|
export type ButtonIcon = {
|
|
11
15
|
readonly sfSymbol: string;
|
|
12
16
|
} | {
|
|
13
17
|
readonly drawable: string;
|
|
18
|
+
} | {
|
|
19
|
+
readonly svg: string;
|
|
14
20
|
};
|
|
15
21
|
/**
|
|
16
22
|
* A platform button, its label the text inside it:
|
|
17
23
|
*
|
|
18
24
|
* <native-button kind="default" (press)="save()">Save</native-button>
|
|
19
25
|
*
|
|
20
|
-
* On macOS it is an NSButton and on iOS a UIButton, drawn by the host, which sends
|
|
26
|
+
* On macOS it is an NSButton, on Linux a GtkButton and on iOS a UIButton, drawn by the host, which sends
|
|
21
27
|
* `topButtonPress` when it is clicked, tapped, or pressed by Space, and on macOS by Return (a
|
|
22
28
|
* `default` button) or Escape (a `cancel` one). On Android it is a view pressed through the responder, as a
|
|
23
29
|
* `<pressable>` is, and takes `android_ripple` as one does. The web host draws an HTML `button`.
|
|
@@ -39,7 +45,11 @@ export declare class NativeButton extends ControlBase {
|
|
|
39
45
|
readonly icon: import("@angular/core").InputSignal<ButtonIcon | undefined>;
|
|
40
46
|
protected readonly symbol: import("@angular/core").Signal<string | undefined>;
|
|
41
47
|
protected readonly drawableResource: import("@angular/core").Signal<string | undefined>;
|
|
42
|
-
|
|
48
|
+
protected readonly svgIcon: import("@angular/core").Signal<string | undefined>;
|
|
49
|
+
/**
|
|
50
|
+
* Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press
|
|
51
|
+
* it twice.
|
|
52
|
+
*/
|
|
43
53
|
private readonly drawnByHost;
|
|
44
54
|
private stopPress;
|
|
45
55
|
protected roleByDefault(): 'button';
|
package/dist/native-button.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Component, computed, forwardRef, input } from '@angular/core';
|
|
2
|
-
import { isApplePlatform, registerViewName } from '@ng-native/fabric';
|
|
2
|
+
import { isApplePlatform, nativePlatform, registerViewName, } from '@ng-native/fabric';
|
|
3
3
|
import { ControlBase, TouchableBase } from "./pressable.js";
|
|
4
|
+
import { svgIconMarkup } from "./svg-icon.js";
|
|
4
5
|
import * as i0 from "@angular/core";
|
|
5
6
|
/**
|
|
6
7
|
* The button on Apple's OSes is the host's: NSButton on macOS and UIButton on iOS. Android has no
|
|
@@ -12,7 +13,7 @@ registerViewName('native-button', { ios: 'NgNativeButton', android: 'View', maco
|
|
|
12
13
|
*
|
|
13
14
|
* <native-button kind="default" (press)="save()">Save</native-button>
|
|
14
15
|
*
|
|
15
|
-
* On macOS it is an NSButton and on iOS a UIButton, drawn by the host, which sends
|
|
16
|
+
* On macOS it is an NSButton, on Linux a GtkButton and on iOS a UIButton, drawn by the host, which sends
|
|
16
17
|
* `topButtonPress` when it is clicked, tapped, or pressed by Space, and on macOS by Return (a
|
|
17
18
|
* `default` button) or Escape (a `cancel` one). On Android it is a view pressed through the responder, as a
|
|
18
19
|
* `<pressable>` is, and takes `android_ripple` as one does. The web host draws an HTML `button`.
|
|
@@ -46,8 +47,13 @@ export class NativeButton extends ControlBase {
|
|
|
46
47
|
return this.drawableName() ?? (icon && 'drawable' in icon ? icon.drawable : undefined);
|
|
47
48
|
}, /* @ts-ignore */
|
|
48
49
|
...(ngDevMode ? [{ debugName: "drawableResource" }] : /* istanbul ignore next */ []));
|
|
49
|
-
|
|
50
|
-
|
|
50
|
+
svgIcon = computed(() => svgIconMarkup(this.icon(), 'native-button', true), /* @ts-ignore */
|
|
51
|
+
...(ngDevMode ? [{ debugName: "svgIcon" }] : /* istanbul ignore next */ []));
|
|
52
|
+
/**
|
|
53
|
+
* Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press
|
|
54
|
+
* it twice.
|
|
55
|
+
*/
|
|
56
|
+
drawnByHost = isApplePlatform() || nativePlatform() === 'linux';
|
|
51
57
|
stopPress = null;
|
|
52
58
|
roleByDefault() {
|
|
53
59
|
return 'button';
|
|
@@ -79,7 +85,7 @@ export class NativeButton extends ControlBase {
|
|
|
79
85
|
this.stopPress?.();
|
|
80
86
|
}
|
|
81
87
|
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, deps: null, target: i0.ɵɵFactoryTarget.Component });
|
|
82
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.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": "drawableResource()", "enabled": "!pressDisabled()" } }, providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }], usesInheritance: true, ngImport: i0, template: '<ng-content />', isInline: true });
|
|
88
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.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": "drawableResource()", "svgIcon": "svgIcon()", "enabled": "!pressDisabled()" } }, providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }], usesInheritance: true, ngImport: i0, template: '<ng-content />', isInline: true });
|
|
83
89
|
}
|
|
84
90
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, decorators: [{
|
|
85
91
|
type: Component,
|
|
@@ -92,6 +98,7 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
92
98
|
'[controlSize]': 'controlSize()',
|
|
93
99
|
'[sfSymbol]': 'symbol()',
|
|
94
100
|
'[drawable]': 'drawableResource()',
|
|
101
|
+
'[svgIcon]': 'svgIcon()',
|
|
95
102
|
'[enabled]': '!pressDisabled()',
|
|
96
103
|
},
|
|
97
104
|
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"native-button.js","sourceRoot":"","sources":["../src/native-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,
|
|
1
|
+
{"version":3,"file":"native-button.js","sourceRoot":"","sources":["../src/native-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,GAEjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;;AAgB9C;;;GAGG;AACH,gBAAgB,CACd,eAAe,EACf,EAAE,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,EACnE,SAAS,EACT,EAAE,WAAW,EAAE,OAAO,EAAE,CACzB,CAAC;AAEF;;;;;;;;;;GAUG;AAcH,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC3C;;;OAGG;IACM,IAAI,GAAG,KAAK;wFAAc,CAAC;IACpC,yFAAyF;IAChF,WAAW,GAAG,KAAK;+FAAe,CAAC;IAC5C,uDAAuD;IAC9C,QAAQ,GAAG,KAAK;4FAAU,CAAC;IACpC,qDAAqD;IAC5C,YAAY,GAAG,KAAK,CAAS,SAAS,oFAAI,KAAK,EAAE,UAAU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C;QACjB,IAAI,CAAC,IAAI,CAAC,WAAW,IAAI,IAAI,CAAC,SAAS;YAAE,OAAO;QAChD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAC3C,IAAI,CAAC,IAAgB,EACrB,gBAAgB,EAChB,CAAC,KAAK,EAAE,EAAE;YACR,IAAI,IAAI,CAAC,aAAa,EAAE;gBAAE,OAAO;YACjC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,EAAE,OAAO,EAAE,KAAc,EAAE,OAAO,CAAC,CAAC;QAClE,CAAC,CACF,CAAC;IACJ,CAAC;IAEQ,WAAW;QAClB,KAAK,CAAC,WAAW,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;IACrB,CAAC;uGAtEU,YAAY;2FAAZ,YAAY,m4BAVZ,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,iDAD1E,gBAAgB;;2FAWf,YAAY;kBAbxB,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;oBACzB,QAAQ,EAAE,gBAAgB;oBAC1B,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;oBACpF,IAAI,EAAE;wBACJ,QAAQ,EAAE,QAAQ;wBAClB,eAAe,EAAE,eAAe;wBAChC,YAAY,EAAE,UAAU;wBACxB,YAAY,EAAE,oBAAoB;wBAClC,WAAW,EAAE,WAAW;wBACxB,WAAW,EAAE,kBAAkB;qBAChC;iBACF","sourcesContent":["import { Component, computed, forwardRef, input } from '@angular/core';\nimport {\n isApplePlatform,\n nativePlatform,\n registerViewName,\n type HostNode,\n} from '@ng-native/fabric';\nimport type { ControlSize } from '@ng-native/device';\nimport { ControlBase, TouchableBase } from './pressable.ts';\nimport { svgIconMarkup } from './svg-icon.ts';\n\n/**\n * What a button does in its window: on macOS, Return presses `default` and Escape presses `cancel`.\n * On iOS they are styles only.\n */\nexport type ButtonKind = 'default' | 'cancel' | 'destructive' | 'plain';\n\n/**\n * A button's picture, as on `<native-tab>`: an SF Symbol on Apple's OSes, a drawable on Android, or\n * an icon's SVG markup, such as an `@ng-icons` set's, on macOS and Linux. The host draws the markup\n * in the button's text colour, as it does a symbol, and an SF Symbol given too wins on macOS.\n */\nexport type ButtonIcon =\n { readonly sfSymbol: string } | { readonly drawable: string } | { readonly svg: string };\n\n/**\n * The button on Apple's OSes is the host's: NSButton on macOS and UIButton on iOS. Android has no\n * platform button React Native draws, so there it is a view this component makes pressable.\n */\nregisterViewName(\n 'native-button',\n { ios: 'NgNativeButton', android: 'View', macos: 'NgNativeButton' },\n undefined,\n { textContent: 'title' },\n);\n\n/**\n * A platform button, its label the text inside it:\n *\n * <native-button kind=\"default\" (press)=\"save()\">Save</native-button>\n *\n * On macOS it is an NSButton, on Linux a GtkButton and on iOS a UIButton, drawn by the host, which sends\n * `topButtonPress` when it is clicked, tapped, or pressed by Space, and on macOS by Return (a\n * `default` button) or Escape (a `cancel` one). On Android it is a view pressed through the responder, as a\n * `<pressable>` is, and takes `android_ripple` as one does. The web host draws an HTML `button`.\n * It is a button to assistive technology everywhere, and takes focus.\n */\n@Component({\n selector: 'native-button',\n template: '<ng-content />',\n providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }],\n host: {\n '[kind]': 'kind()',\n '[controlSize]': 'controlSize()',\n '[sfSymbol]': 'symbol()',\n '[drawable]': 'drawableResource()',\n '[svgIcon]': 'svgIcon()',\n '[enabled]': '!pressDisabled()',\n },\n})\nexport class NativeButton extends ControlBase {\n /**\n * What the button does in its window. In a desktop window `default` takes Return and `cancel`\n * takes Escape; elsewhere the kind is a style alone. Unset, it is a plain push button.\n */\n readonly kind = input<ButtonKind>();\n /** AppKit's control size on macOS, and UIKit's button size on iOS. Ignored elsewhere. */\n readonly controlSize = input<ControlSize>();\n /** An SF Symbol beside the label, on iOS and macOS. */\n readonly sfSymbol = input<string>();\n /** Android: a drawable resource beside the label. */\n readonly drawableName = input<string>(undefined, { alias: 'drawable' });\n /** The picture for each OS at once, as on `<native-tab>`. */\n readonly icon = input<ButtonIcon>();\n\n protected readonly symbol = computed(() => {\n const icon = this.icon();\n return this.sfSymbol() ?? (icon && 'sfSymbol' in icon ? icon.sfSymbol : undefined);\n });\n\n protected readonly drawableResource = computed(() => {\n const icon = this.icon();\n return this.drawableName() ?? (icon && 'drawable' in icon ? icon.drawable : undefined);\n });\n\n protected readonly svgIcon = computed(() => svgIconMarkup(this.icon(), 'native-button', true));\n\n /**\n * Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press\n * it twice.\n */\n private readonly drawnByHost = isApplePlatform() || nativePlatform() === 'linux';\n private stopPress: (() => void) | null = null;\n\n protected override roleByDefault(): 'button' {\n return 'button';\n }\n\n protected override accessibleByDefault(): boolean {\n return true;\n }\n\n protected override focusableByDefault(): boolean {\n return true;\n }\n\n protected override disabledForAccessibility(): boolean | undefined {\n return this.disabled();\n }\n\n protected override claims(): boolean {\n return !this.drawnByHost && super.claims();\n }\n\n override ngOnInit(): void {\n super.ngOnInit();\n if (!this.drawnByHost || this.stopPress) return;\n this.stopPress = this.engine.setEventListener(\n this.node as HostNode,\n 'topButtonPress',\n (event) => {\n if (this.pressDisabled()) return;\n this.emitReported(this.press, 'click', event as never, 'click');\n },\n );\n }\n\n override ngOnDestroy(): void {\n super.ngOnDestroy();\n this.stopPress?.();\n }\n}\n"]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { InjectionToken, type TemplateRef } from '@angular/core';
|
|
2
|
+
import * as i0 from "@angular/core";
|
|
3
|
+
/** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */
|
|
4
|
+
export declare const PRESS_MENU: InjectionToken<{
|
|
5
|
+
open(): boolean;
|
|
6
|
+
}>;
|
|
7
|
+
/**
|
|
8
|
+
* A menu a press opens: `<pressable [menu]="menu">`, with `<ng-template #menu>` holding
|
|
9
|
+
* `<menu-item>`s, as a `[contextMenu]` is written. A click, a screen reader's press or, on macOS,
|
|
10
|
+
* Space on the focused element opens it under the element, and `(press)` does not fire. A pop-up
|
|
11
|
+
* select is a menu of `[checked]` items. `open()` opens it from code: `#sort="pressMenu"` names it in
|
|
12
|
+
* the template.
|
|
13
|
+
*
|
|
14
|
+
* macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, and Android
|
|
15
|
+
* as a PopupMenu below it, which takes the `NgNativeMenus` module that Expo Go lacks. Other hosts
|
|
16
|
+
* (iOS, Expo Go, the web) draw none yet: there a press fires `(press)`, with one warning in
|
|
17
|
+
* development.
|
|
18
|
+
*
|
|
19
|
+
* The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as
|
|
20
|
+
* `serializeMenu` makes it. The host sends the item chosen as the view's `topContextMenuSelect`,
|
|
21
|
+
* as a context menu's.
|
|
22
|
+
*/
|
|
23
|
+
export declare class PressMenu {
|
|
24
|
+
readonly menu: import("@angular/core").InputSignal<TemplateRef<unknown> | null | undefined>;
|
|
25
|
+
private readonly node;
|
|
26
|
+
private readonly engine;
|
|
27
|
+
private readonly menus;
|
|
28
|
+
private readonly built;
|
|
29
|
+
constructor();
|
|
30
|
+
/**
|
|
31
|
+
* Ask the host to open the menu under the element now. True once the request is sent, which
|
|
32
|
+
* does not mean the menu showed: the host draws none for a view it is not showing (no window on
|
|
33
|
+
* macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu
|
|
34
|
+
* shows no item, the element has no view yet, or the host draws no press menu.
|
|
35
|
+
*/
|
|
36
|
+
open(): boolean;
|
|
37
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<PressMenu, never>;
|
|
38
|
+
static ɵdir: i0.ɵɵDirectiveDeclaration<PressMenu, "pressable[menu]", ["pressMenu"], { "menu": { "alias": "menu"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
|
|
39
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { DestroyRef, Directive, ElementRef, InjectionToken, Injector, forwardRef, inject, input, untracked, } from '@angular/core';
|
|
2
|
+
import { Menus, OS } from '@ng-native/device';
|
|
3
|
+
import { HostEngine } from '@ng-native/fabric';
|
|
4
|
+
import { templateMenu } from "./context-menu.js";
|
|
5
|
+
import * as i0 from "@angular/core";
|
|
6
|
+
/** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */
|
|
7
|
+
export const PRESS_MENU = new InjectionToken('angular-native.pressMenu');
|
|
8
|
+
/** Whether the warning for a host that draws no press menu has been given, which it is once. */
|
|
9
|
+
let warned = false;
|
|
10
|
+
/**
|
|
11
|
+
* A menu a press opens: `<pressable [menu]="menu">`, with `<ng-template #menu>` holding
|
|
12
|
+
* `<menu-item>`s, as a `[contextMenu]` is written. A click, a screen reader's press or, on macOS,
|
|
13
|
+
* Space on the focused element opens it under the element, and `(press)` does not fire. A pop-up
|
|
14
|
+
* select is a menu of `[checked]` items. `open()` opens it from code: `#sort="pressMenu"` names it in
|
|
15
|
+
* the template.
|
|
16
|
+
*
|
|
17
|
+
* macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, and Android
|
|
18
|
+
* as a PopupMenu below it, which takes the `NgNativeMenus` module that Expo Go lacks. Other hosts
|
|
19
|
+
* (iOS, Expo Go, the web) draw none yet: there a press fires `(press)`, with one warning in
|
|
20
|
+
* development.
|
|
21
|
+
*
|
|
22
|
+
* The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as
|
|
23
|
+
* `serializeMenu` makes it. The host sends the item chosen as the view's `topContextMenuSelect`,
|
|
24
|
+
* as a context menu's.
|
|
25
|
+
*/
|
|
26
|
+
export class PressMenu {
|
|
27
|
+
menu = input(/* @ts-ignore */
|
|
28
|
+
...(ngDevMode ? [undefined, { debugName: "menu" }] : /* istanbul ignore next */ []));
|
|
29
|
+
node = inject(ElementRef).nativeElement;
|
|
30
|
+
engine = inject(HostEngine);
|
|
31
|
+
menus = inject(Menus);
|
|
32
|
+
built = templateMenu(() => this.menu() ?? null, inject(Injector), inject(OS));
|
|
33
|
+
constructor() {
|
|
34
|
+
const stop = this.engine.setEventListener(this.node, 'topContextMenuSelect', (event) => {
|
|
35
|
+
const id = event.nativeEvent?.id;
|
|
36
|
+
if (id !== undefined)
|
|
37
|
+
this.built.choose(id);
|
|
38
|
+
});
|
|
39
|
+
inject(DestroyRef).onDestroy(stop);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Ask the host to open the menu under the element now. True once the request is sent, which
|
|
43
|
+
* does not mean the menu showed: the host draws none for a view it is not showing (no window on
|
|
44
|
+
* macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu
|
|
45
|
+
* shows no item, the element has no view yet, or the host draws no press menu.
|
|
46
|
+
*/
|
|
47
|
+
open() {
|
|
48
|
+
const entries = untracked(this.built.sent);
|
|
49
|
+
if (!entries)
|
|
50
|
+
return false;
|
|
51
|
+
if (!this.menus.popsUpMenus) {
|
|
52
|
+
if (typeof ngDevMode !== 'undefined' && ngDevMode && !warned) {
|
|
53
|
+
warned = true;
|
|
54
|
+
console.warn('[menu] on a <pressable>: this host draws no menu on a press yet (macOS, Linux and ' +
|
|
55
|
+
'Android do), so the press fires (press) instead.');
|
|
56
|
+
}
|
|
57
|
+
return false;
|
|
58
|
+
}
|
|
59
|
+
const view = this.engine.tagOf?.(this.node) ?? null;
|
|
60
|
+
if (view === null)
|
|
61
|
+
return false;
|
|
62
|
+
this.menus.popUpMenu(view, entries);
|
|
63
|
+
return true;
|
|
64
|
+
}
|
|
65
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PressMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive });
|
|
66
|
+
static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: PressMenu, isStandalone: true, selector: "pressable[menu]", inputs: { menu: { classPropertyName: "menu", publicName: "menu", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }], exportAs: ["pressMenu"], ngImport: i0 });
|
|
67
|
+
}
|
|
68
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PressMenu, decorators: [{
|
|
69
|
+
type: Directive,
|
|
70
|
+
args: [{
|
|
71
|
+
selector: 'pressable[menu]',
|
|
72
|
+
exportAs: 'pressMenu',
|
|
73
|
+
providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }],
|
|
74
|
+
}]
|
|
75
|
+
}], ctorParameters: () => [], propDecorators: { menu: [{ type: i0.Input, args: [{ isSignal: true, alias: "menu", required: false }] }] } });
|
|
76
|
+
//# sourceMappingURL=press-menu.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"press-menu.js","sourceRoot":"","sources":["../src/press-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;;AAEjD,wFAAwF;AACxF,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,cAAc,CAAsB,0BAA0B,CAAC,CAAC;AAI9F,gGAAgG;AAChG,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB;;;;;;;;;;;;;;;GAeG;AAMH,MAAM,OAAO,SAAS;IACX,IAAI,GAAG,KAAK;wFAA+B,CAAC;IAEpC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,aAAyB,CAAC;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,CAAC;QAChC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;QACpC,OAAO,IAAI,CAAC;IACd,CAAC;uGAvCU,SAAS;2FAAT,SAAS,+LAFT,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,EAAE,CAAC;;2FAEnE,SAAS;kBALrB,SAAS;mBAAC;oBACT,QAAQ,EAAE,iBAAiB;oBAC3B,QAAQ,EAAE,WAAW;oBACrB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC;iBAC/E","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n InjectionToken,\n Injector,\n forwardRef,\n inject,\n input,\n untracked,\n type TemplateRef,\n} from '@angular/core';\nimport { Menus, OS } from '@ng-native/device';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\nimport { templateMenu } from './context-menu.ts';\n\n/** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */\nexport const PRESS_MENU = new InjectionToken<{ open(): boolean }>('angular-native.pressMenu');\n\ndeclare const ngDevMode: unknown;\n\n/** Whether the warning for a host that draws no press menu has been given, which it is once. */\nlet warned = false;\n\n/**\n * A menu a press opens: `<pressable [menu]=\"menu\">`, with `<ng-template #menu>` holding\n * `<menu-item>`s, as a `[contextMenu]` is written. A click, a screen reader's press or, on macOS,\n * Space on the focused element opens it under the element, and `(press)` does not fire. A pop-up\n * select is a menu of `[checked]` items. `open()` opens it from code: `#sort=\"pressMenu\"` names it in\n * the template.\n *\n * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, and Android\n * as a PopupMenu below it, which takes the `NgNativeMenus` module that Expo Go lacks. Other hosts\n * (iOS, Expo Go, the web) draw none yet: there a press fires `(press)`, with one warning in\n * development.\n *\n * The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as\n * `serializeMenu` makes it. The host sends the item chosen as the view's `topContextMenuSelect`,\n * as a context menu's.\n */\n@Directive({\n selector: 'pressable[menu]',\n exportAs: 'pressMenu',\n providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }],\n})\nexport class PressMenu {\n readonly menu = input<TemplateRef<unknown> | null>();\n\n private readonly node = inject(ElementRef).nativeElement as HostNode;\n private readonly engine = inject(HostEngine);\n private readonly menus = inject(Menus);\n private readonly built = templateMenu(() => this.menu() ?? null, inject(Injector), inject(OS));\n\n constructor() {\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.built.choose(id);\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /**\n * Ask the host to open the menu under the element now. True once the request is sent, which\n * does not mean the menu showed: the host draws none for a view it is not showing (no window on\n * macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu\n * shows no item, the element has no view yet, or the host draws no press menu.\n */\n open(): boolean {\n const entries = untracked(this.built.sent);\n if (!entries) return false;\n if (!this.menus.popsUpMenus) {\n if (typeof ngDevMode !== 'undefined' && ngDevMode && !warned) {\n warned = true;\n console.warn(\n '[menu] on a <pressable>: this host draws no menu on a press yet (macOS, Linux and ' +\n 'Android do), so the press fires (press) instead.',\n );\n }\n return false;\n }\n const view = this.engine.tagOf?.(this.node) ?? null;\n if (view === null) return false;\n this.menus.popUpMenu(view, entries);\n return true;\n }\n}\n"]}
|
package/dist/pressable.d.ts
CHANGED
|
@@ -103,6 +103,8 @@ export declare abstract class TouchableBase extends ViewBase {
|
|
|
103
103
|
private longPressListeners;
|
|
104
104
|
/** A `[contextMenu]` on the same element, whose menu a long press may open instead. */
|
|
105
105
|
private readonly contextMenu;
|
|
106
|
+
/** A `[menu]` on the same element, which a press opens instead of firing `(press)`. */
|
|
107
|
+
private readonly pressMenu;
|
|
106
108
|
/**
|
|
107
109
|
* For `Menus`, read only where there is a `(longPress)` (see `takeLongPressFromMenus`), and for
|
|
108
110
|
* the interaction observers, read only once something is pressed.
|
|
@@ -234,6 +236,7 @@ export declare abstract class TouchableBase extends ViewBase {
|
|
|
234
236
|
* Observers are looked up here rather than injected, because a press is rare and a lookup for
|
|
235
237
|
* every `<text>` on screen is not. A press is reported whether or not anything listens to it: a
|
|
236
238
|
* control that does nothing when tapped is what an observer looking for dead taps wants to hear.
|
|
239
|
+
* A press on an element whose `[menu]` opens is reported, and `(press)` does not fire.
|
|
237
240
|
*/
|
|
238
241
|
protected emitReported(output: {
|
|
239
242
|
emit(event: PressEvent): void;
|
package/dist/pressable.js
CHANGED
|
@@ -9,6 +9,7 @@ import { Directive, Injector, computed, forwardRef, inject, input, output, runIn
|
|
|
9
9
|
import { Menus } from '@ng-native/device';
|
|
10
10
|
import { isTouchPointer, nativePlatform, } from '@ng-native/fabric';
|
|
11
11
|
import { CONTEXT_MENU } from "./context-menu.js";
|
|
12
|
+
import { PRESS_MENU } from "./press-menu.js";
|
|
12
13
|
import { describeElement, interactionObservers, notifyInteraction, textWithin, } from "./interaction-observer.js";
|
|
13
14
|
import { byNativeId } from "./native-id.js";
|
|
14
15
|
import { booleanOr, numberOr, optionalBoolean } from "./transforms.js";
|
|
@@ -169,6 +170,8 @@ export class TouchableBase extends ViewBase {
|
|
|
169
170
|
longPressListeners = 0;
|
|
170
171
|
/** A `[contextMenu]` on the same element, whose menu a long press may open instead. */
|
|
171
172
|
contextMenu = inject(CONTEXT_MENU, { self: true, optional: true });
|
|
173
|
+
/** A `[menu]` on the same element, which a press opens instead of firing `(press)`. */
|
|
174
|
+
pressMenu = inject(PRESS_MENU, { self: true, optional: true });
|
|
172
175
|
/**
|
|
173
176
|
* For `Menus`, read only where there is a `(longPress)` (see `takeLongPressFromMenus`), and for
|
|
174
177
|
* the interaction observers, read only once something is pressed.
|
|
@@ -483,11 +486,13 @@ export class TouchableBase extends ViewBase {
|
|
|
483
486
|
* Observers are looked up here rather than injected, because a press is rare and a lookup for
|
|
484
487
|
* every `<text>` on screen is not. A press is reported whether or not anything listens to it: a
|
|
485
488
|
* control that does nothing when tapped is what an observer looking for dead taps wants to hear.
|
|
489
|
+
* A press on an element whose `[menu]` opens is reported, and `(press)` does not fire.
|
|
486
490
|
*/
|
|
487
491
|
emitReported(output, type, event, source) {
|
|
488
492
|
const observers = interactionObservers(this.injector);
|
|
489
493
|
const interaction = observers && this.describeInteraction(type, event, source);
|
|
490
|
-
output.
|
|
494
|
+
if (output !== this.press || !this.pressMenu?.open())
|
|
495
|
+
output.emit(event);
|
|
491
496
|
if (observers && interaction)
|
|
492
497
|
notifyInteraction(observers, interaction);
|
|
493
498
|
}
|