@ng-native/components 0.28.0 → 0.30.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/README.md +2 -2
- package/android/src/main/java/dev/ngnative/components/ColorSchemeModule.kt +116 -11
- package/dist/activity-indicator.js +3 -3
- package/dist/animated-style.js +3 -3
- package/dist/animations-web.js +3 -3
- package/dist/animations.js +3 -3
- package/dist/content-container.js +3 -3
- package/dist/context-menu.js +3 -3
- package/dist/drag-and-drop.js +6 -6
- package/dist/gestures-web.js +6 -6
- package/dist/gestures.js +6 -6
- package/dist/gradient-text.d.ts +1 -1
- package/dist/gradient-text.js +4 -4
- package/dist/gradient-text.js.map +1 -1
- package/dist/image-background.js +3 -3
- package/dist/image.js +3 -3
- package/dist/index.d.ts +3 -2
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/input-accessory-view.js +3 -3
- package/dist/keyboard-avoiding-view.js +3 -3
- package/dist/keyboard-dock.js +15 -15
- package/dist/markdown-blocks.d.ts +2 -1
- package/dist/markdown-blocks.js +22 -18
- package/dist/markdown-blocks.js.map +1 -1
- package/dist/markdown-columns.js +3 -3
- package/dist/markdown-stream.js +8 -5
- package/dist/markdown-stream.js.map +1 -1
- package/dist/markdown.js +5 -5
- package/dist/markdown.js.map +1 -1
- package/dist/menu.d.ts +11 -5
- package/dist/menu.js +24 -44
- package/dist/menu.js.map +1 -1
- package/dist/modal.js +8 -3
- package/dist/modal.js.map +1 -1
- package/dist/native-button.d.ts +25 -3
- package/dist/native-button.js +102 -8
- package/dist/native-button.js.map +1 -1
- package/dist/native-gesture.js +3 -3
- package/dist/native-ref.js +3 -3
- package/dist/press-menu.d.ts +38 -8
- package/dist/press-menu.js +80 -19
- package/dist/press-menu.js.map +1 -1
- package/dist/pressable.js +14 -13
- package/dist/pressable.js.map +1 -1
- package/dist/reanimated-web.js +6 -6
- package/dist/reanimated.js +6 -6
- package/dist/refresh-control.js +3 -3
- package/dist/safe-area-provider.js +3 -3
- package/dist/safe-area-view.js +3 -3
- package/dist/scroll-view-props.js +3 -3
- package/dist/scroll-view.d.ts +3 -1
- package/dist/scroll-view.js +10 -5
- package/dist/scroll-view.js.map +1 -1
- package/dist/section-list.d.ts +4 -4
- package/dist/section-list.js +37 -34
- package/dist/section-list.js.map +1 -1
- package/dist/shortcut.js +3 -3
- package/dist/sidebar-item.js +3 -3
- package/dist/sidebar-section.d.ts +12 -5
- package/dist/sidebar-section.js +32 -12
- package/dist/sidebar-section.js.map +1 -1
- package/dist/sidebar.d.ts +11 -3
- package/dist/sidebar.js +18 -8
- package/dist/sidebar.js.map +1 -1
- package/dist/split-view.d.ts +23 -2
- package/dist/split-view.js +36 -9
- package/dist/split-view.js.map +1 -1
- package/dist/stand-ins/animations.js +3 -3
- 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/switch.js +3 -3
- package/dist/template-slot.js +3 -3
- package/dist/text-input.js +3 -3
- package/dist/text.js +3 -3
- package/dist/touchable-opacity.js +3 -3
- package/dist/tray-icon.d.ts +7 -1
- package/dist/tray-icon.js +17 -5
- package/dist/tray-icon.js.map +1 -1
- package/dist/view-base.d.ts +18 -2
- package/dist/view-base.js +42 -10
- package/dist/view-base.js.map +1 -1
- package/dist/view.js +3 -3
- package/dist/virtual-list-layout.d.ts +5 -0
- package/dist/virtual-list-layout.js.map +1 -1
- package/dist/virtual-list-num-columns.d.ts +8 -4
- package/dist/virtual-list-num-columns.js +13 -5
- package/dist/virtual-list-num-columns.js.map +1 -1
- package/dist/virtual-list-sticky-level.d.ts +0 -6
- package/dist/virtual-list-sticky-level.js +5 -29
- package/dist/virtual-list-sticky-level.js.map +1 -1
- package/dist/virtual-list.d.ts +72 -11
- package/dist/virtual-list.js +285 -74
- package/dist/virtual-list.js.map +1 -1
- package/dist/visual-effect.d.ts +37 -0
- package/dist/visual-effect.js +60 -0
- package/dist/visual-effect.js.map +1 -0
- package/dist/worklet-scroll.js +3 -3
- package/dist/worklet-style.js +3 -3
- package/dist/written-props.js +9 -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/NgNativeComponents.podspec +2 -2
- package/ios/NgNativeKeyboardFocus.h +21 -0
- package/ios/NgNativeKeyboardFocus.mm +28 -0
- package/ios/NgNativeKeyboardFocusModule.mm +203 -0
- package/ios/NgNativeMenus.mm +62 -2
- package/ios/NgNativePressMenu.h +36 -0
- package/ios/NgNativePressMenu.mm +79 -0
- package/ios/NgNativeViewBinder.h +5 -0
- package/ios/NgNativeViewBinder.mm +31 -4
- package/package.json +6 -6
package/dist/markdown.js
CHANGED
|
@@ -270,8 +270,8 @@ export class Markdown {
|
|
|
270
270
|
if (!prevented && opensOnPress(link.href))
|
|
271
271
|
this.injector.get(DeepLinks).open(link.href);
|
|
272
272
|
}
|
|
273
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
274
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.
|
|
273
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Markdown, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
274
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: Markdown, isStandalone: true, selector: "markdown", inputs: { source: { classPropertyName: "source", publicName: "source", isSignal: true, isRequired: false, transformFunction: null }, tokens: { classPropertyName: "tokens", publicName: "tokens", isSignal: true, isRequired: false, transformFunction: null }, streaming: { classPropertyName: "streaming", publicName: "streaming", isSignal: true, isRequired: false, transformFunction: null }, linkSchemes: { classPropertyName: "linkSchemes", publicName: "linkSchemes", isSignal: true, isRequired: false, transformFunction: null }, classes: { classPropertyName: "classes", publicName: "classes", isSignal: true, isRequired: false, transformFunction: null } }, outputs: { linkPress: "linkPress" }, host: { properties: { "class.md-ios": "apple", "class.md-android": "platform === 'android'" } }, ngImport: i0, template: `
|
|
275
275
|
<ng-template #blockTemplate let-list>
|
|
276
276
|
@for (block of list; track blockKey(block)) {
|
|
277
277
|
@switch (block.kind) {
|
|
@@ -392,9 +392,9 @@ export class Markdown {
|
|
|
392
392
|
</ng-template>
|
|
393
393
|
|
|
394
394
|
<ng-container *templateSlot="blockTemplate; context: { $implicit: blocks() }" />
|
|
395
|
-
`, isInline: true, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-
|
|
395
|
+
`, isInline: true, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n /* The document's size, here so a class on the element replaces it: paragraphs, list markers and\n table cells set none of their own and inherit this. */\n font-size: 16px;\n line-height: 23px;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-strong {\n font-weight: 700;\n}\n\n.md-em {\n font-style: italic;\n}\n\n.md-del {\n text-decoration-line: line-through;\n}\n\n.md-a {\n color: #0a66d8;\n text-decoration-line: underline;\n}\n\n.md-code {\n background-color: rgba(120, 120, 128, 0.16);\n}\n\n.md-code,\n.md-pre {\n font-family: Courier New;\n}\n\n:host(.md-ios) .md-code,\n:host(.md-ios) .md-pre {\n font-family: Menlo;\n}\n\n:host(.md-android) .md-code,\n:host(.md-android) .md-pre {\n font-family: monospace;\n}\n\n.md-blockquote {\n gap: 8px;\n padding-left: 12px;\n border-left-width: 3px;\n border-left-color: #d1d1d6;\n color: #6c6c70;\n}\n\n.md-ul,\n.md-ol {\n gap: 4px;\n}\n\n.md-li {\n flex-direction: row;\n gap: 8px;\n}\n\n.md-marker {\n min-width: 16px;\n}\n\n.md-li-body {\n flex: 1;\n gap: 4px;\n}\n\n.md-pre {\n flex-grow: 0;\n border-radius: 8px;\n background-color: #f2f2f7;\n}\n\n.md-pre-text {\n padding: 12px;\n font-size: 14px;\n line-height: 20px;\n}\n\n.md-hr {\n height: 1px;\n background-color: #d1d1d6;\n}\n\n.md-img {\n width: var(--md-img-width, 100%);\n max-width: 100%;\n height: 200px;\n border-radius: 8px;\n}\n\n.md-table {\n border-width: 1px;\n border-color: #d1d1d6;\n border-radius: 8px;\n overflow: hidden;\n}\n\n.md-tr {\n flex-direction: row;\n}\n\n/* The text hugs its content inside the column's least width, so it can report a narrower one. */\n.md-cell {\n align-items: flex-start;\n}\n\n.md-th,\n.md-td {\n max-width: 280px;\n padding: 6px 8px;\n}\n\n.md-cell-body {\n border-top-width: 1px;\n border-top-color: #d1d1d6;\n}\n\n.md-th {\n font-weight: 600;\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n color: #f2f2f7;\n }\n\n .md-h6,\n .md-blockquote {\n color: #98989f;\n }\n\n .md-a {\n color: #4c9bff;\n }\n\n .md-code {\n background-color: rgba(120, 120, 128, 0.32);\n }\n\n .md-pre {\n background-color: #1c1c1e;\n }\n\n .md-blockquote,\n .md-table,\n .md-cell-body {\n border-color: #38383a;\n }\n\n .md-hr {\n background-color: #38383a;\n }\n}\n"], dependencies: [{ kind: "directive", type: Image, selector: "image", inputs: ["source", "src", "srcSet", "defaultSource", "loadingIndicatorSource", "resizeMode", "resizeMethod", "resizeMultiplier", "blurRadius", "capInsets", "tintColor", "fadeDuration", "progressiveRenderingEnabled", "alt", "crossOrigin", "referrerPolicy"] }, { kind: "directive", type: MarkdownColumns, selector: "[markdownColumns]", inputs: ["markdownColumns"], exportAs: ["markdownColumns"] }, { kind: "component", type: ScrollView, selector: "scroll-view", inputs: ["contentContainerStyle", "contentContainerClass", "horizontal", "contentOffset", "maintainVisibleContentPosition", "keyboardShouldPersistTaps", "nestedScrollEnabled", "stickyHeaderIndices"], outputs: ["contentSizeChange"], exportAs: ["scrollView"] }, { kind: "directive", type: TemplateSlot, selector: "[templateSlot]", inputs: ["templateSlot", "templateSlotContext"] }, { kind: "directive", type: Text, selector: "text", inputs: ["numberOfLines", "ellipsizeMode", "selectable", "selectionColor", "allowFontScaling", "maxFontSizeMultiplier", "dynamicTypeRamp", "adjustsFontSizeToFit", "minimumFontScale", "lineBreakStrategyIOS", "textBreakStrategy", "dataDetectorType", "android_hyphenationFrequency", "pressable", "suppressHighlighting"], exportAs: ["text"] }, { kind: "directive", type: View, selector: "view" }] });
|
|
396
396
|
}
|
|
397
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
397
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Markdown, decorators: [{
|
|
398
398
|
type: Component,
|
|
399
399
|
args: [{ selector: 'markdown', imports: [Image, MarkdownColumns, ScrollView, TemplateSlot, Text, View], template: `
|
|
400
400
|
<ng-template #blockTemplate let-list>
|
|
@@ -520,6 +520,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImpor
|
|
|
520
520
|
`, host: {
|
|
521
521
|
'[class.md-ios]': 'apple',
|
|
522
522
|
'[class.md-android]': "platform === 'android'",
|
|
523
|
-
}, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-
|
|
523
|
+
}, styles: ["/* What a document looks like with no `classes` of the app's, in light and in dark. */\n\n:host {\n gap: 12px;\n color: #1c1c1e;\n /* The document's size, here so a class on the element replaces it: paragraphs, list markers and\n table cells set none of their own and inherit this. */\n font-size: 16px;\n line-height: 23px;\n}\n\n.md-h1,\n.md-h2,\n.md-h3,\n.md-h4,\n.md-h5,\n.md-h6 {\n font-weight: 700;\n}\n\n.md-h1 {\n font-size: 28px;\n line-height: 34px;\n}\n\n.md-h2 {\n font-size: 22px;\n line-height: 28px;\n}\n\n.md-h3 {\n font-size: 20px;\n line-height: 25px;\n}\n\n.md-h4 {\n font-size: 17px;\n line-height: 22px;\n}\n\n.md-h5 {\n font-size: 15px;\n line-height: 20px;\n}\n\n.md-h6 {\n font-size: 13px;\n line-height: 18px;\n color: #6c6c70;\n}\n\n.md-strong {\n font-weight: 700;\n}\n\n.md-em {\n font-style: italic;\n}\n\n.md-del {\n text-decoration-line: line-through;\n}\n\n.md-a {\n color: #0a66d8;\n text-decoration-line: underline;\n}\n\n.md-code {\n background-color: rgba(120, 120, 128, 0.16);\n}\n\n.md-code,\n.md-pre {\n font-family: Courier New;\n}\n\n:host(.md-ios) .md-code,\n:host(.md-ios) .md-pre {\n font-family: Menlo;\n}\n\n:host(.md-android) .md-code,\n:host(.md-android) .md-pre {\n font-family: monospace;\n}\n\n.md-blockquote {\n gap: 8px;\n padding-left: 12px;\n border-left-width: 3px;\n border-left-color: #d1d1d6;\n color: #6c6c70;\n}\n\n.md-ul,\n.md-ol {\n gap: 4px;\n}\n\n.md-li {\n flex-direction: row;\n gap: 8px;\n}\n\n.md-marker {\n min-width: 16px;\n}\n\n.md-li-body {\n flex: 1;\n gap: 4px;\n}\n\n.md-pre {\n flex-grow: 0;\n border-radius: 8px;\n background-color: #f2f2f7;\n}\n\n.md-pre-text {\n padding: 12px;\n font-size: 14px;\n line-height: 20px;\n}\n\n.md-hr {\n height: 1px;\n background-color: #d1d1d6;\n}\n\n.md-img {\n width: var(--md-img-width, 100%);\n max-width: 100%;\n height: 200px;\n border-radius: 8px;\n}\n\n.md-table {\n border-width: 1px;\n border-color: #d1d1d6;\n border-radius: 8px;\n overflow: hidden;\n}\n\n.md-tr {\n flex-direction: row;\n}\n\n/* The text hugs its content inside the column's least width, so it can report a narrower one. */\n.md-cell {\n align-items: flex-start;\n}\n\n.md-th,\n.md-td {\n max-width: 280px;\n padding: 6px 8px;\n}\n\n.md-cell-body {\n border-top-width: 1px;\n border-top-color: #d1d1d6;\n}\n\n.md-th {\n font-weight: 600;\n}\n\n@media (prefers-color-scheme: dark) {\n :host {\n color: #f2f2f7;\n }\n\n .md-h6,\n .md-blockquote {\n color: #98989f;\n }\n\n .md-a {\n color: #4c9bff;\n }\n\n .md-code {\n background-color: rgba(120, 120, 128, 0.32);\n }\n\n .md-pre {\n background-color: #1c1c1e;\n }\n\n .md-blockquote,\n .md-table,\n .md-cell-body {\n border-color: #38383a;\n }\n\n .md-hr {\n background-color: #38383a;\n }\n}\n"] }]
|
|
524
524
|
}], propDecorators: { source: [{ type: i0.Input, args: [{ isSignal: true, alias: "source", required: false }] }], tokens: [{ type: i0.Input, args: [{ isSignal: true, alias: "tokens", required: false }] }], streaming: [{ type: i0.Input, args: [{ isSignal: true, alias: "streaming", required: false }] }], linkSchemes: [{ type: i0.Input, args: [{ isSignal: true, alias: "linkSchemes", required: false }] }], classes: [{ type: i0.Input, args: [{ isSignal: true, alias: "classes", required: false }] }], linkPress: [{ type: i0.Output, args: ["linkPress"] }] } });
|
|
525
525
|
//# sourceMappingURL=markdown.js.map
|
package/dist/markdown.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,SAAS,EACT,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,GAKZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO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views and text.\n *\n * Its own entry point because it parses with `marked`, an optional peer dependency an app installs\n * only when it renders Markdown: the barrel never imports it, so an app that does not is not asked\n * for it.\n *\n * ```ts\n * import { Markdown } from '@ng-native/components/markdown';\n * ```\n */\nimport {\n Component,\n Injector,\n InjectionToken,\n booleanAttribute,\n computed,\n inject,\n input,\n linkedSignal,\n output,\n type Provider,\n} from '@angular/core';\nimport { DeepLinks } from '@ng-native/device';\nimport { isApplePlatform, nativePlatform } from '@ng-native/fabric';\nimport { lexer, type Token } from 'marked';\nimport type { ImageLoadEvent, LayoutEvent } from './events.ts';\nimport { Image } from './image.ts';\nimport {\n blockKey,\n linkSchemeSet,\n markdownBlocks,\n opensOnPress,\n shareBlocks,\n type AppLinkSchemes,\n type MarkdownBlock,\n type MarkdownElement,\n type MarkdownInline,\n} from './markdown-blocks.ts';\nimport { MarkdownColumns } from './markdown-columns.ts';\nimport { MarkdownStream } from './markdown-stream.ts';\nimport { ScrollView } from './scroll-view.ts';\nimport { TemplateSlot } from './template-slot.ts';\nimport { Text } from './text.ts';\nimport { View } from './view.ts';\n\nexport type { MarkdownElement } from './markdown-blocks.ts';\n\n/** Classes for the elements a document is drawn with, each one in place of the default. */\nexport type MarkdownClasses = Partial<Readonly<Record<MarkdownElement, string>>>;\n\n/** `(linkPress)`: a link was pressed. */\nexport interface MarkdownLinkPress {\n /** The target as written, after its entities are decoded and its scheme was allowed. */\n readonly href: string;\n readonly title: string | null;\n /** Keep the link from being opened, to handle it in the app instead. */\n preventDefault(): void;\n}\n\n/**\n * The schemes, beyond `http`, `https`, `mailto` and `tel`, that every `<markdown>` draws links in\n * unless its own `linkSchemes` is set. See `provideMarkdownLinkSchemes`.\n */\nexport const MARKDOWN_LINK_SCHEMES = new InjectionToken<readonly string[]>(\n 'MARKDOWN_LINK_SCHEMES',\n { providedIn: 'root', factory: () => [] },\n);\n\n/**\n * Make links in the app's own schemes links in every `<markdown>`, such as `myapp:item/42`:\n * drawn as links and reported through `(linkPress)`, and never opened by default. A\n * `[linkSchemes]` input on one `<markdown>` replaces this list for that one.\n *\n * ```ts\n * providers: [provideMarkdownLinkSchemes('myapp')]\n * ```\n */\nexport function provideMarkdownLinkSchemes(...schemes: readonly string[]): Provider {\n return { provide: MARKDOWN_LINK_SCHEMES, useValue: schemes };\n}\n\nconst ELEMENTS: readonly MarkdownElement[] = [\n ...['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'ul', 'ol', 'li', 'marker'],\n ...['pre', 'code', 'strong', 'em', 'del', 'a', 'hr', 'img', 'table', 'tr', 'th', 'td'],\n] as MarkdownElement[];\n\nconst DEFAULT_CLASSES = Object.fromEntries(\n ELEMENTS.map((element) => [element, `md-${element}`]),\n) as Readonly<Record<MarkdownElement, string>>;\n\ntype MarkdownLink = Extract<MarkdownInline, { kind: 'link' }>;\n\n/** A loaded image's own width in points, and its width over its height. */\ninterface ImageSize {\n readonly width: number;\n readonly ratio: number;\n}\n\ntype ImageBlock = Extract<MarkdownBlock, { kind: 'image' }>;\n\n/** Every image in `blocks`, however deep in quotes and lists. */\nfunction imageBlocks(\n blocks: readonly MarkdownBlock[],\n into = new Set<ImageBlock>(),\n): Set<ImageBlock> {\n for (const block of blocks) {\n if (block.kind === 'image') into.add(block);\n else if (block.kind === 'blockquote') imageBlocks(block.children, into);\n else if (block.kind === 'list') {\n for (const item of block.items) imageBlocks(item.children, into);\n }\n }\n return into;\n}\n\n/**\n * A Markdown document as `<text>`, `<view>`, `<image>` and `<scroll-view>`: headings, paragraphs,\n * emphasis, inline code, links, quotes, ordered, unordered and task lists, code blocks, rules,\n * tables and images.\n *\n * `source` is parsed with `marked.lexer`; `tokens` takes tokens lexed already, and wins when both\n * are set. A paragraph is one `<text>` with a nested `<text>` for each emphasis, code span and\n * link, so it wraps as one run; an image is lifted out to a block of its own.\n *\n * Nothing in the document is interpreted. Raw HTML is drawn as the text it is written as, a link\n * is followed only to `http`, `https`, `mailto`, `tel` or a relative target, and an image is\n * loaded only over `http` or `https`; anything else is drawn as its text.\n *\n * Each element carries a default class, `md-h1`, `md-p`, `md-a` and so on, styled in light and\n * dark. `classes` replaces one by its element's name, so a global stylesheet or Tailwind styles it\n * instead: `{ h1: 'text-3xl font-bold' }`. Put the default back beside your own to keep both.\n *\n * For a source that grows as it streams in, an answer arriving a few words at a time, set\n * `streaming` until it is complete. The blocks before the last one are then kept as they are and\n * only the last is lexed and converted again, unless a chunk defines or changes a link reference,\n * which can change a block already kept, and the whole source is lexed again. Syntax still open at its end, a code span, an emphasis, a link,\n * an image or a table row, is held back until it closes. Of a code fence only an unfinished\n * opening line is held back, and its code then streams as it arrives. Clearing `streaming` draws\n * the whole source as written, and `tokens` are always drawn as given. A block that did not\n * change keeps its views, streaming or not.\n *\n * A pressed link is `(linkPress)`. An absolute target is then opened with `DeepLinks.open` unless\n * a handler calls `preventDefault()`; a relative one is only reported, for the app to route.\n *\n * A link in the app's own scheme, `myapp:item/42`, is drawn as plain text unless the scheme is\n * listed in `linkSchemes`, or app-wide with `provideMarkdownLinkSchemes`. A listed scheme is drawn\n * as a link and reported through `(linkPress)`, and is never opened: the app routes it. The input\n * replaces the provider's list when it is set, even to an empty one. Schemes are matched without\n * regard to case, and the list is read as a value: give a new array to change it.\n */\n@Component({\n selector: 'markdown',\n imports: [Image, MarkdownColumns, ScrollView, TemplateSlot, Text, View],\n template: `\n <ng-template #blockTemplate let-list>\n @for (block of list; track blockKey(block)) {\n @switch (block.kind) {\n @case ('heading') {\n <text [class]=\"classFor(block.element)\" accessibilityRole=\"header\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('paragraph') {\n <text [class]=\"classFor('p')\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('image') {\n <image\n [src]=\"block.src\"\n [alt]=\"block.alt || undefined\"\n resizeMode=\"contain\"\n [class]=\"classFor('img')\"\n [style.--md-img-width]=\"imageWidth(block.src)\"\n [style.aspectRatio]=\"sizes().get(block.src)?.ratio ?? null\"\n [style.height]=\"imageHeight(block)\"\n (load)=\"sizeImage(block.src, $any($event))\"\n (layout)=\"layOutImage(block, $any($event))\"\n />\n }\n @case ('blockquote') {\n <view [class]=\"classFor('blockquote')\">\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: block.children }\" />\n </view>\n }\n @case ('list') {\n <view [class]=\"classFor(block.element)\">\n @for (item of block.items; track $index) {\n <view [class]=\"classFor('li')\">\n <text [class]=\"classFor('marker')\">{{ item.marker }}</text>\n <view class=\"md-li-body\">\n <ng-container\n *templateSlot=\"blockTemplate; context: { $implicit: item.children }\"\n />\n </view>\n </view>\n }\n </view>\n }\n @case ('code') {\n <scroll-view horizontal [class]=\"classFor('pre')\">\n <text selectable class=\"md-pre-text\">{{ block.text }}</text>\n </scroll-view>\n }\n @case ('hr') {\n <view [class]=\"classFor('hr')\"></view>\n }\n @case ('table') {\n <scroll-view horizontal>\n <view\n [class]=\"classFor('table')\"\n [markdownColumns]=\"block\"\n #columns=\"markdownColumns\"\n >\n <view [class]=\"classFor('tr')\">\n @for (cell of block.header; track $index; let column = $index) {\n <view class=\"md-cell\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('th')\"\n (layout)=\"columns.measure(0, column, $any($event))\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n @for (row of block.rows; track $index; let r = $index) {\n <view [class]=\"classFor('tr')\">\n @for (cell of row; track $index; let column = $index) {\n <view class=\"md-cell md-cell-body\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('td')\"\n (layout)=\"columns.measure(r + 1, column, $any($event))\"\n ><ng-container\n *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n }\n </view>\n </scroll-view>\n }\n }\n }\n </ng-template>\n\n <ng-template #inlineTemplate let-runs>\n @for (run of runs; track $index) {\n @switch (run.kind) {\n @case ('text') {\n <ng-container>{{ run.text }}</ng-container>\n }\n @case ('code') {\n <text [class]=\"classFor('code')\">{{ run.text }}</text>\n }\n @case ('link') {\n <text\n [class]=\"classFor('a')\"\n pressable\n [accessibilityHint]=\"run.title ?? undefined\"\n (press)=\"followLink(run)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n @default {\n <text [class]=\"classFor(run.kind)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n }\n }\n </ng-template>\n\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: blocks() }\" />\n `,\n styleUrl: './markdown.css',\n host: {\n '[class.md-ios]': 'apple',\n '[class.md-android]': \"platform === 'android'\",\n },\n})\nexport class Markdown {\n private readonly injector = inject(Injector);\n /** Which monospace font code is drawn in, as the platform names it. */\n protected readonly platform = nativePlatform();\n /** Menlo, which iOS and macOS both have. */\n protected readonly apple = isApplePlatform();\n\n /** The Markdown to draw. */\n readonly source = input<string>();\n /** Tokens `marked.lexer` made already, drawn in place of `source`. */\n readonly tokens = input<readonly Token[]>();\n /**\n * Whether `source` is still arriving, a chunk at a time. While it is, only its last block is\n * lexed again, unless a link reference changes, and syntax still open at its end is held back.\n * See the class note.\n */\n readonly streaming = input(false, { transform: booleanAttribute });\n /**\n * Schemes besides `http`, `https`, `mailto` and `tel` whose links are drawn as links and\n * reported through `(linkPress)`, never opened. Replaces `provideMarkdownLinkSchemes` when set.\n * See the class note.\n */\n readonly linkSchemes = input<readonly string[]>();\n /** A class for an element, in place of its default. See the class note. */\n readonly classes = input<MarkdownClasses>({});\n /** A link was pressed. See the class note. */\n readonly linkPress = output<MarkdownLinkPress>();\n\n private readonly stream = new MarkdownStream();\n protected readonly blockKey = blockKey;\n\n /**\n * The blocks each token the stream kept was drawn as. A kept token is the same object from one\n * chunk to the next, so its blocks are not converted or compared again; a source lexed whole\n * makes new tokens, and so new blocks.\n */\n private streamed = new WeakMap<Token, readonly MarkdownBlock[]>();\n /** The schemes `streamed` was converted with; its blocks are stale once they change. */\n private streamedFor: AppLinkSchemes | undefined;\n\n private readonly providedSchemes = inject(MARKDOWN_LINK_SCHEMES);\n\n /** The schemes links are drawn in, the same set while the list reads the same. */\n private readonly appSchemes = computed(\n () => linkSchemeSet(this.linkSchemes() ?? this.providedSchemes),\n { equal: (a, b) => a.size === b.size && [...a].every((scheme) => b.has(scheme)) },\n );\n\n private readonly lexed = computed(() => {\n const tokens = this.tokens();\n if (tokens) return { tokens, streamed: false };\n const streamed = this.streaming();\n return { tokens: this.lex(this.source() ?? '', streamed), streamed };\n });\n\n /** The document's blocks, with each one that did not change kept, so it is not drawn again. */\n protected readonly blocks = linkedSignal({\n source: () => ({ ...this.lexed(), schemes: this.appSchemes() }),\n computation: ({ tokens, streamed, schemes }, previous?: { value: readonly MarkdownBlock[] }) =>\n streamed\n ? this.streamedBlocks(tokens, previous?.value, schemes)\n : shareBlocks(previous?.value, markdownBlocks(tokens, schemes)),\n });\n\n private readonly classOf = computed(() => ({ ...DEFAULT_CLASSES, ...this.classes() }));\n\n /**\n * Each image's own width and its width over its height, once it has loaded, so it is drawn at its\n * own size and shape, as a browser draws it, and no wider than the document. The width reaches\n * the image as `--md-img-width`, which `.md-img` reads, so a class of the app's own still sets\n * the width. An image the document no longer has is forgotten when the document changes.\n */\n protected readonly sizes = linkedSignal<readonly MarkdownBlock[], ReadonlyMap<string, ImageSize>>(\n {\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<string, ImageSize>();\n if (!previous) return kept;\n const present = new Set([...imageBlocks(blocks)].map((block) => block.src));\n for (const [src, size] of previous.value) if (present.has(src)) kept.set(src, size);\n return kept;\n },\n },\n );\n\n /**\n * The width each image is laid out at where that is less than its own, narrowed by\n * `max-width`. Yoga takes an image's height from its width before `max-width` narrows it, where\n * CSS takes it after, so a narrowed image is given the height its ratio makes of the width it\n * has. An image no longer in the document is forgotten when the document changes.\n */\n protected readonly narrowed = linkedSignal<\n readonly MarkdownBlock[],\n ReadonlyMap<ImageBlock, number>\n >({\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<ImageBlock, number>();\n if (!previous) return kept;\n const present = imageBlocks(blocks);\n for (const [block, width] of previous.value) if (present.has(block)) kept.set(block, width);\n return kept;\n },\n });\n\n private lex(source: string, streaming: boolean): readonly Token[] {\n return streaming ? this.stream.lex(source) : lexer(source);\n }\n\n /** `tokens`' blocks, converting and sharing only those of tokens the stream had not kept. */\n private streamedBlocks(\n tokens: readonly Token[],\n previous: readonly MarkdownBlock[] | undefined,\n schemes: AppLinkSchemes,\n ): readonly MarkdownBlock[] {\n if (this.streamedFor !== schemes) {\n this.streamed = new WeakMap();\n this.streamedFor = schemes;\n }\n const kept: MarkdownBlock[] = [];\n let at = 0;\n for (; at < tokens.length; at++) {\n const blocks = this.streamed.get(tokens[at]!);\n if (!blocks) break;\n kept.push(...blocks);\n }\n const rest = tokens.slice(at);\n const converted = rest.map((token) => markdownBlocks([token], schemes));\n // The blocks drawn after the kept ones, when those are still the ones drawn first.\n const drawn = !kept.length || previous?.[kept.length - 1] === kept.at(-1);\n const was = drawn ? previous?.slice(kept.length) : undefined;\n const shared = shareBlocks(was, converted.flat());\n let from = 0;\n rest.forEach((token, i) => {\n const count = converted[i]!.length;\n this.streamed.set(token, shared.slice(from, (from += count)));\n });\n return [...kept, ...shared];\n }\n\n protected classFor(element: MarkdownElement): string {\n return this.classOf()[element];\n }\n\n protected imageWidth(src: string): string | null {\n const size = this.sizes().get(src);\n return size ? `${size.width}px` : null;\n }\n\n /** The class's height until the image loads, then its ratio's, or a narrowed image's own. */\n protected imageHeight(block: ImageBlock): number | 'auto' | null {\n const size = this.sizes().get(block.src);\n if (!size) return null;\n const width = this.narrowed().get(block);\n return width === undefined ? 'auto' : width / size.ratio;\n }\n\n protected layOutImage(block: ImageBlock, event: Partial<LayoutEvent>): void {\n const width = event.nativeEvent?.layout?.width;\n const size = this.sizes().get(block.src);\n if (width === undefined || !size) return;\n const narrowed = width < size.width ? width : undefined;\n if (this.narrowed().get(block) === narrowed) return;\n this.narrowed.update((all) => {\n const next = new Map(all);\n if (narrowed === undefined) next.delete(block);\n else next.set(block, narrowed);\n return next;\n });\n }\n\n protected sizeImage(src: string, event: Partial<ImageLoadEvent>): void {\n const source = event.nativeEvent?.source;\n if (!source) return;\n const { width, height } = source;\n if (!(width > 0 && height > 0)) return;\n // A url's or a data url's scale is 1, so the load event's pixels are the points a browser's\n // CSS pixels are.\n this.sizes.update((sizes) => new Map(sizes).set(src, { width, ratio: width / height }));\n }\n\n protected followLink(link: MarkdownLink): void {\n let prevented = false;\n this.linkPress.emit({\n href: link.href,\n title: link.title,\n preventDefault: () => {\n prevented = true;\n },\n });\n if (!prevented && opensOnPress(link.href)) this.injector.get(DeepLinks).open(link.href);\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"markdown.js","sourceRoot":"","sources":["../src/markdown.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,SAAS,EACT,QAAQ,EACR,cAAc,EACd,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,KAAK,EACL,YAAY,EACZ,MAAM,GAEP,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACpE,OAAO,EAAE,KAAK,EAAc,MAAM,QAAQ,CAAC;AAE3C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EACL,QAAQ,EACR,aAAa,EACb,cAAc,EACd,YAAY,EACZ,WAAW,GAKZ,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,E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AAE,KAAK,EAAE,KAAK,GAAG,MAAM,EAAE,CAAC,CAAC,CAAC;IAC1F,CAAC;IAES,UAAU,CAAC,IAAkB;QACrC,IAAI,SAAS,GAAG,KAAK,CAAC;QACtB,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;YAClB,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,KAAK,EAAE,IAAI,CAAC,KAAK;YACjB,cAAc,EAAE,GAAG,EAAE;gBACnB,SAAS,GAAG,IAAI,CAAC;YACnB,CAAC;SACF,CAAC,CAAC;QACH,IAAI,CAAC,SAAS,IAAI,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC1F,CAAC;uGA/LU,QAAQ;2FAAR,QAAQ,w1BAhIT;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyHT,i2FA1HS,KAAK,mTAAE,eAAe,0HAAE,UAAU,0TAAE,YAAY,4GAAE,IAAI,mYAAE,IAAI;;2FAiI3D,QAAQ;kBAnIpB,SAAS;+BACE,UAAU,WACX,CAAC,KAAK,EAAE,eAAe,EAAE,UAAU,EAAE,YAAY,EAAE,IAAI,EAAE,IAAI,CAAC,YAC7D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAyHT,QAEK;wBACJ,gBAAgB,EAAE,OAAO;wBACzB,oBAAoB,EAAE,wBAAwB;qBAC/C","sourcesContent":["/**\n * Markdown, drawn as native views and text.\n *\n * Its own entry point because it parses with `marked`, an optional peer dependency an app installs\n * only when it renders Markdown: the barrel never imports it, so an app that does not is not asked\n * for it.\n *\n * ```ts\n * import { Markdown } from '@ng-native/components/markdown';\n * ```\n */\nimport {\n Component,\n Injector,\n InjectionToken,\n booleanAttribute,\n computed,\n inject,\n input,\n linkedSignal,\n output,\n type Provider,\n} from '@angular/core';\nimport { DeepLinks } from '@ng-native/device';\nimport { isApplePlatform, nativePlatform } from '@ng-native/fabric';\nimport { lexer, type Token } from 'marked';\nimport type { ImageLoadEvent, LayoutEvent } from './events.ts';\nimport { Image } from './image.ts';\nimport {\n blockKey,\n linkSchemeSet,\n markdownBlocks,\n opensOnPress,\n shareBlocks,\n type AppLinkSchemes,\n type MarkdownBlock,\n type MarkdownElement,\n type MarkdownInline,\n} from './markdown-blocks.ts';\nimport { MarkdownColumns } from './markdown-columns.ts';\nimport { MarkdownStream } from './markdown-stream.ts';\nimport { ScrollView } from './scroll-view.ts';\nimport { TemplateSlot } from './template-slot.ts';\nimport { Text } from './text.ts';\nimport { View } from './view.ts';\n\nexport type { MarkdownElement } from './markdown-blocks.ts';\n\n/** Classes for the elements a document is drawn with, each one in place of the default. */\nexport type MarkdownClasses = Partial<Readonly<Record<MarkdownElement, string>>>;\n\n/** `(linkPress)`: a link was pressed. */\nexport interface MarkdownLinkPress {\n /** The target as written, after its entities are decoded and its scheme was allowed. */\n readonly href: string;\n readonly title: string | null;\n /** Keep the link from being opened, to handle it in the app instead. */\n preventDefault(): void;\n}\n\n/**\n * The schemes, beyond `http`, `https`, `mailto` and `tel`, that every `<markdown>` draws links in\n * unless its own `linkSchemes` is set. See `provideMarkdownLinkSchemes`.\n */\nexport const MARKDOWN_LINK_SCHEMES = new InjectionToken<readonly string[]>(\n 'MARKDOWN_LINK_SCHEMES',\n { providedIn: 'root', factory: () => [] },\n);\n\n/**\n * Make links in the app's own schemes links in every `<markdown>`, such as `myapp:item/42`:\n * drawn as links and reported through `(linkPress)`, and never opened by default. A\n * `[linkSchemes]` input on one `<markdown>` replaces this list for that one.\n *\n * ```ts\n * providers: [provideMarkdownLinkSchemes('myapp')]\n * ```\n */\nexport function provideMarkdownLinkSchemes(...schemes: readonly string[]): Provider {\n return { provide: MARKDOWN_LINK_SCHEMES, useValue: schemes };\n}\n\nconst ELEMENTS: readonly MarkdownElement[] = [\n ...['h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'blockquote', 'ul', 'ol', 'li', 'marker'],\n ...['pre', 'code', 'strong', 'em', 'del', 'a', 'hr', 'img', 'table', 'tr', 'th', 'td'],\n] as MarkdownElement[];\n\nconst DEFAULT_CLASSES = Object.fromEntries(\n ELEMENTS.map((element) => [element, `md-${element}`]),\n) as Readonly<Record<MarkdownElement, string>>;\n\ntype MarkdownLink = Extract<MarkdownInline, { kind: 'link' }>;\n\n/** A loaded image's own width in points, and its width over its height. */\ninterface ImageSize {\n readonly width: number;\n readonly ratio: number;\n}\n\ntype ImageBlock = Extract<MarkdownBlock, { kind: 'image' }>;\n\n/** Every image in `blocks`, however deep in quotes and lists. */\nfunction imageBlocks(\n blocks: readonly MarkdownBlock[],\n into = new Set<ImageBlock>(),\n): Set<ImageBlock> {\n for (const block of blocks) {\n if (block.kind === 'image') into.add(block);\n else if (block.kind === 'blockquote') imageBlocks(block.children, into);\n else if (block.kind === 'list') {\n for (const item of block.items) imageBlocks(item.children, into);\n }\n }\n return into;\n}\n\n/**\n * A Markdown document as `<text>`, `<view>`, `<image>` and `<scroll-view>`: headings, paragraphs,\n * emphasis, inline code, links, quotes, ordered, unordered and task lists, code blocks, rules,\n * tables and images.\n *\n * `source` is parsed with `marked.lexer`; `tokens` takes tokens lexed already, and wins when both\n * are set. A paragraph is one `<text>` with a nested `<text>` for each emphasis, code span and\n * link, so it wraps as one run; an image is lifted out to a block of its own.\n *\n * Nothing in the document is interpreted. Raw HTML is drawn as the text it is written as, a link\n * is followed only to `http`, `https`, `mailto`, `tel` or a relative target, and an image is\n * loaded only over `http` or `https`; anything else is drawn as its text.\n *\n * Each element carries a default class, `md-h1`, `md-p`, `md-a` and so on, styled in light and\n * dark. `classes` replaces one by its element's name, so a global stylesheet or Tailwind styles it\n * instead: `{ h1: 'text-3xl font-bold' }`. Put the default back beside your own to keep both.\n *\n * For a source that grows as it streams in, an answer arriving a few words at a time, set\n * `streaming` until it is complete. The blocks before the last one are then kept as they are and\n * only the last is lexed and converted again, unless a chunk defines or changes a link reference,\n * which can change a block already kept, and the whole source is lexed again. Syntax still open at its end, a code span, an emphasis, a link,\n * an image or a table row, is held back until it closes. Of a code fence only an unfinished\n * opening line is held back, and its code then streams as it arrives. Clearing `streaming` draws\n * the whole source as written, and `tokens` are always drawn as given. A block that did not\n * change keeps its views, streaming or not.\n *\n * A pressed link is `(linkPress)`. An absolute target is then opened with `DeepLinks.open` unless\n * a handler calls `preventDefault()`; a relative one is only reported, for the app to route.\n *\n * A link in the app's own scheme, `myapp:item/42`, is drawn as plain text unless the scheme is\n * listed in `linkSchemes`, or app-wide with `provideMarkdownLinkSchemes`. A listed scheme is drawn\n * as a link and reported through `(linkPress)`, and is never opened: the app routes it. The input\n * replaces the provider's list when it is set, even to an empty one. Schemes are matched without\n * regard to case, and the list is read as a value: give a new array to change it.\n */\n@Component({\n selector: 'markdown',\n imports: [Image, MarkdownColumns, ScrollView, TemplateSlot, Text, View],\n template: `\n <ng-template #blockTemplate let-list>\n @for (block of list; track blockKey(block)) {\n @switch (block.kind) {\n @case ('heading') {\n <text [class]=\"classFor(block.element)\" accessibilityRole=\"header\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('paragraph') {\n <text [class]=\"classFor('p')\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: block.children }\"\n /></text>\n }\n @case ('image') {\n <image\n [src]=\"block.src\"\n [alt]=\"block.alt || undefined\"\n resizeMode=\"contain\"\n [class]=\"classFor('img')\"\n [style.--md-img-width]=\"imageWidth(block.src)\"\n [style.aspectRatio]=\"sizes().get(block.src)?.ratio ?? null\"\n [style.height]=\"imageHeight(block)\"\n (load)=\"sizeImage(block.src, $any($event))\"\n (layout)=\"layOutImage(block, $any($event))\"\n />\n }\n @case ('blockquote') {\n <view [class]=\"classFor('blockquote')\">\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: block.children }\" />\n </view>\n }\n @case ('list') {\n <view [class]=\"classFor(block.element)\">\n @for (item of block.items; track $index) {\n <view [class]=\"classFor('li')\">\n <text [class]=\"classFor('marker')\">{{ item.marker }}</text>\n <view class=\"md-li-body\">\n <ng-container\n *templateSlot=\"blockTemplate; context: { $implicit: item.children }\"\n />\n </view>\n </view>\n }\n </view>\n }\n @case ('code') {\n <scroll-view horizontal [class]=\"classFor('pre')\">\n <text selectable class=\"md-pre-text\">{{ block.text }}</text>\n </scroll-view>\n }\n @case ('hr') {\n <view [class]=\"classFor('hr')\"></view>\n }\n @case ('table') {\n <scroll-view horizontal>\n <view\n [class]=\"classFor('table')\"\n [markdownColumns]=\"block\"\n #columns=\"markdownColumns\"\n >\n <view [class]=\"classFor('tr')\">\n @for (cell of block.header; track $index; let column = $index) {\n <view class=\"md-cell\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('th')\"\n (layout)=\"columns.measure(0, column, $any($event))\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n @for (row of block.rows; track $index; let r = $index) {\n <view [class]=\"classFor('tr')\">\n @for (cell of row; track $index; let column = $index) {\n <view class=\"md-cell md-cell-body\" [style.minWidth]=\"columns.width(column)\">\n <text\n [class]=\"classFor('td')\"\n (layout)=\"columns.measure(r + 1, column, $any($event))\"\n ><ng-container\n *templateSlot=\"inlineTemplate; context: { $implicit: cell }\"\n /></text>\n </view>\n }\n </view>\n }\n </view>\n </scroll-view>\n }\n }\n }\n </ng-template>\n\n <ng-template #inlineTemplate let-runs>\n @for (run of runs; track $index) {\n @switch (run.kind) {\n @case ('text') {\n <ng-container>{{ run.text }}</ng-container>\n }\n @case ('code') {\n <text [class]=\"classFor('code')\">{{ run.text }}</text>\n }\n @case ('link') {\n <text\n [class]=\"classFor('a')\"\n pressable\n [accessibilityHint]=\"run.title ?? undefined\"\n (press)=\"followLink(run)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n @default {\n <text [class]=\"classFor(run.kind)\"\n ><ng-container *templateSlot=\"inlineTemplate; context: { $implicit: run.children }\"\n /></text>\n }\n }\n }\n </ng-template>\n\n <ng-container *templateSlot=\"blockTemplate; context: { $implicit: blocks() }\" />\n `,\n styleUrl: './markdown.css',\n host: {\n '[class.md-ios]': 'apple',\n '[class.md-android]': \"platform === 'android'\",\n },\n})\nexport class Markdown {\n private readonly injector = inject(Injector);\n /** Which monospace font code is drawn in, as the platform names it. */\n protected readonly platform = nativePlatform();\n /** Menlo, which iOS and macOS both have. */\n protected readonly apple = isApplePlatform();\n\n /** The Markdown to draw. */\n readonly source = input<string>();\n /** Tokens `marked.lexer` made already, drawn in place of `source`. */\n readonly tokens = input<readonly Token[]>();\n /**\n * Whether `source` is still arriving, a chunk at a time. While it is, only its last block is\n * lexed again, unless a link reference changes, and syntax still open at its end is held back.\n * See the class note.\n */\n readonly streaming = input(false, { transform: booleanAttribute });\n /**\n * Schemes besides `http`, `https`, `mailto` and `tel` whose links are drawn as links and\n * reported through `(linkPress)`, never opened. Replaces `provideMarkdownLinkSchemes` when set.\n * See the class note.\n */\n readonly linkSchemes = input<readonly string[]>();\n /** A class for an element, in place of its default. See the class note. */\n readonly classes = input<MarkdownClasses>({});\n /** A link was pressed. See the class note. */\n readonly linkPress = output<MarkdownLinkPress>();\n\n private readonly stream = new MarkdownStream();\n protected readonly blockKey = blockKey;\n\n /**\n * The blocks each token the stream kept was drawn as. A kept token is the same object from one\n * chunk to the next, so its blocks are not converted or compared again; a source lexed whole\n * makes new tokens, and so new blocks.\n */\n private streamed = new WeakMap<Token, readonly MarkdownBlock[]>();\n /** The schemes `streamed` was converted with; its blocks are stale once they change. */\n private streamedFor: AppLinkSchemes | undefined;\n\n private readonly providedSchemes = inject(MARKDOWN_LINK_SCHEMES);\n\n /** The schemes links are drawn in, the same set while the list reads the same. */\n private readonly appSchemes = computed(\n () => linkSchemeSet(this.linkSchemes() ?? this.providedSchemes),\n { equal: (a, b) => a.size === b.size && [...a].every((scheme) => b.has(scheme)) },\n );\n\n private readonly lexed = computed(() => {\n const tokens = this.tokens();\n if (tokens) return { tokens, streamed: false };\n const streamed = this.streaming();\n return { tokens: this.lex(this.source() ?? '', streamed), streamed };\n });\n\n /** The document's blocks, with each one that did not change kept, so it is not drawn again. */\n protected readonly blocks = linkedSignal({\n source: () => ({ ...this.lexed(), schemes: this.appSchemes() }),\n computation: ({ tokens, streamed, schemes }, previous?: { value: readonly MarkdownBlock[] }) =>\n streamed\n ? this.streamedBlocks(tokens, previous?.value, schemes)\n : shareBlocks(previous?.value, markdownBlocks(tokens, schemes)),\n });\n\n private readonly classOf = computed(() => ({ ...DEFAULT_CLASSES, ...this.classes() }));\n\n /**\n * Each image's own width and its width over its height, once it has loaded, so it is drawn at its\n * own size and shape, as a browser draws it, and no wider than the document. The width reaches\n * the image as `--md-img-width`, which `.md-img` reads, so a class of the app's own still sets\n * the width. An image the document no longer has is forgotten when the document changes.\n */\n protected readonly sizes = linkedSignal<readonly MarkdownBlock[], ReadonlyMap<string, ImageSize>>(\n {\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<string, ImageSize>();\n if (!previous) return kept;\n const present = new Set([...imageBlocks(blocks)].map((block) => block.src));\n for (const [src, size] of previous.value) if (present.has(src)) kept.set(src, size);\n return kept;\n },\n },\n );\n\n /**\n * The width each image is laid out at where that is less than its own, narrowed by\n * `max-width`. Yoga takes an image's height from its width before `max-width` narrows it, where\n * CSS takes it after, so a narrowed image is given the height its ratio makes of the width it\n * has. An image no longer in the document is forgotten when the document changes.\n */\n protected readonly narrowed = linkedSignal<\n readonly MarkdownBlock[],\n ReadonlyMap<ImageBlock, number>\n >({\n source: this.blocks,\n computation: (blocks, previous) => {\n const kept = new Map<ImageBlock, number>();\n if (!previous) return kept;\n const present = imageBlocks(blocks);\n for (const [block, width] of previous.value) if (present.has(block)) kept.set(block, width);\n return kept;\n },\n });\n\n private lex(source: string, streaming: boolean): readonly Token[] {\n return streaming ? this.stream.lex(source) : lexer(source);\n }\n\n /** `tokens`' blocks, converting and sharing only those of tokens the stream had not kept. */\n private streamedBlocks(\n tokens: readonly Token[],\n previous: readonly MarkdownBlock[] | undefined,\n schemes: AppLinkSchemes,\n ): readonly MarkdownBlock[] {\n if (this.streamedFor !== schemes) {\n this.streamed = new WeakMap();\n this.streamedFor = schemes;\n }\n const kept: MarkdownBlock[] = [];\n let at = 0;\n for (; at < tokens.length; at++) {\n const blocks = this.streamed.get(tokens[at]!);\n if (!blocks) break;\n kept.push(...blocks);\n }\n const rest = tokens.slice(at);\n const converted = rest.map((token) => markdownBlocks([token], schemes));\n // The blocks drawn after the kept ones, when those are still the ones drawn first.\n const drawn = !kept.length || previous?.[kept.length - 1] === kept.at(-1);\n const was = drawn ? previous?.slice(kept.length) : undefined;\n const shared = shareBlocks(was, converted.flat());\n let from = 0;\n rest.forEach((token, i) => {\n const count = converted[i]!.length;\n this.streamed.set(token, shared.slice(from, (from += count)));\n });\n return [...kept, ...shared];\n }\n\n protected classFor(element: MarkdownElement): string {\n return this.classOf()[element];\n }\n\n protected imageWidth(src: string): string | null {\n const size = this.sizes().get(src);\n return size ? `${size.width}px` : null;\n }\n\n /** The class's height until the image loads, then its ratio's, or a narrowed image's own. */\n protected imageHeight(block: ImageBlock): number | 'auto' | null {\n const size = this.sizes().get(block.src);\n if (!size) return null;\n const width = this.narrowed().get(block);\n return width === undefined ? 'auto' : width / size.ratio;\n }\n\n protected layOutImage(block: ImageBlock, event: Partial<LayoutEvent>): void {\n const width = event.nativeEvent?.layout?.width;\n const size = this.sizes().get(block.src);\n if (width === undefined || !size) return;\n const narrowed = width < size.width ? width : undefined;\n if (this.narrowed().get(block) === narrowed) return;\n this.narrowed.update((all) => {\n const next = new Map(all);\n if (narrowed === undefined) next.delete(block);\n else next.set(block, narrowed);\n return next;\n });\n }\n\n protected sizeImage(src: string, event: Partial<ImageLoadEvent>): void {\n const source = event.nativeEvent?.source;\n if (!source) return;\n const { width, height } = source;\n if (!(width > 0 && height > 0)) return;\n // A url's or a data url's scale is 1, so the load event's pixels are the points a browser's\n // CSS pixels are.\n this.sizes.update((sizes) => new Map(sizes).set(src, { width, ratio: width / height }));\n }\n\n protected followLink(link: MarkdownLink): void {\n let prevented = false;\n this.linkPress.emit({\n href: link.href,\n title: link.title,\n preventDefault: () => {\n prevented = true;\n },\n });\n if (!prevented && opensOnPress(link.href)) this.injector.get(DeepLinks).open(link.href);\n }\n}\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');
|
|
@@ -106,10 +86,10 @@ export class MenuItem {
|
|
|
106
86
|
this.checkedModel.propose(!checked);
|
|
107
87
|
this.select.emit();
|
|
108
88
|
};
|
|
109
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
110
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.
|
|
89
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuItem, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
90
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.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 });
|
|
111
91
|
}
|
|
112
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
92
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuItem, decorators: [{
|
|
113
93
|
type: Component,
|
|
114
94
|
args: [{
|
|
115
95
|
selector: 'menu-item',
|
|
@@ -122,10 +102,10 @@ export class MenuSeparator {
|
|
|
122
102
|
constructor() {
|
|
123
103
|
registerIn(computed(() => ({ separator: true })), 'menu-separator');
|
|
124
104
|
}
|
|
125
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
126
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.
|
|
105
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuSeparator, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
106
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.3.0", type: MenuSeparator, isStandalone: true, selector: "menu-separator", host: { properties: { "style.display": "\"none\"" } }, ngImport: i0, template: '', isInline: true });
|
|
127
107
|
}
|
|
128
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
108
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuSeparator, decorators: [{
|
|
129
109
|
type: Component,
|
|
130
110
|
args: [{
|
|
131
111
|
selector: 'menu-separator',
|
|
@@ -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,15 +137,14 @@ 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
|
}
|
|
164
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
165
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.
|
|
144
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuGroup, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
145
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.0", type: MenuGroup, isStandalone: true, selector: "menu-group", inputs: { label: { classPropertyName: "label", publicName: "label", isSignal: true, isRequired: false, transformFunction: null }, menuRole: { classPropertyName: "menuRole", publicName: "menuRole", isSignal: true, isRequired: false, transformFunction: null }, inline: { classPropertyName: "inline", publicName: "inline", 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 }, destructive: { classPropertyName: "destructive", publicName: "destructive", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "style.display": "\"none\"" } }, providers: [{ provide: MENU_MODEL, useFactory: menuModelInTreeOrder }], ngImport: i0, template: '<ng-content />', isInline: true });
|
|
166
146
|
}
|
|
167
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
147
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuGroup, decorators: [{
|
|
168
148
|
type: Component,
|
|
169
149
|
args: [{
|
|
170
150
|
selector: 'menu-group',
|
|
@@ -184,10 +164,10 @@ export class MenuBar {
|
|
|
184
164
|
const own = inject(MENU_MODEL, { self: true });
|
|
185
165
|
inject(DestroyRef).onDestroy(inject(Menus).addMenuBar(own.entries));
|
|
186
166
|
}
|
|
187
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
188
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.
|
|
167
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuBar, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
168
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "14.0.0", version: "22.3.0", type: MenuBar, isStandalone: true, selector: "menu-bar", host: { properties: { "style.display": "\"none\"" } }, providers: [{ provide: MENU_MODEL, useFactory: menuModelInTreeOrder }], ngImport: i0, template: '<ng-content />', isInline: true });
|
|
189
169
|
}
|
|
190
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
170
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: MenuBar, decorators: [{
|
|
191
171
|
type: Component,
|
|
192
172
|
args: [{
|
|
193
173
|
selector: 'menu-bar',
|
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,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AAW,EAAE,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC;SACjD,CAAC,CAAC,EACH,YAAY,CACb,CAAC;IACJ,CAAC;uGAvBU,SAAS;2FAAT,SAAS,g3BAFT,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,oBAAoB,EAAE,CAAC,0BAF5D,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;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O,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 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/modal.js
CHANGED
|
@@ -98,6 +98,11 @@ export class Modal extends ViewBase {
|
|
|
98
98
|
...(ngDevMode ? [{ debugName: "containerStyle" }] : /* istanbul ignore next */ []));
|
|
99
99
|
constructor() {
|
|
100
100
|
super();
|
|
101
|
+
// A modal made outside a change detection (with a routed page, by `createComponent`) is in the
|
|
102
|
+
// tree before its `visible` binding has run, and a commit in between would read it as showing:
|
|
103
|
+
// the host presents it, empty, for that one commit. It starts hidden, and the binding's first
|
|
104
|
+
// value says whether it shows.
|
|
105
|
+
this.engine.setProp(this.node, 'visible', false);
|
|
101
106
|
// RN's host claims any touch that reaches it, so nothing inside the modal can hand a
|
|
102
107
|
// gesture to the screen underneath.
|
|
103
108
|
const stop = inject(HostEngine).setResponder(this.node, {
|
|
@@ -140,10 +145,10 @@ export class Modal extends ViewBase {
|
|
|
140
145
|
this.awaitingAnchor.set(false);
|
|
141
146
|
}, { injector: this.injector });
|
|
142
147
|
}
|
|
143
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.
|
|
144
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.
|
|
148
|
+
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Modal, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
149
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.3.0", type: Modal, isStandalone: true, selector: "modal", inputs: { visible: { classPropertyName: "visible", publicName: "visible", isSignal: true, isRequired: false, transformFunction: null }, transparent: { classPropertyName: "transparent", publicName: "transparent", isSignal: true, isRequired: false, transformFunction: null }, backdropColor: { classPropertyName: "backdropColor", publicName: "backdropColor", isSignal: true, isRequired: false, transformFunction: null }, animationType: { classPropertyName: "animationType", publicName: "animationType", isSignal: true, isRequired: false, transformFunction: null }, presentationStyle: { classPropertyName: "presentationStyle", publicName: "presentationStyle", isSignal: true, isRequired: false, transformFunction: null }, supportedOrientations: { classPropertyName: "supportedOrientations", publicName: "supportedOrientations", isSignal: true, isRequired: false, transformFunction: null }, allowSwipeDismissal: { classPropertyName: "allowSwipeDismissal", publicName: "allowSwipeDismissal", isSignal: true, isRequired: false, transformFunction: null }, statusBarTranslucent: { classPropertyName: "statusBarTranslucent", publicName: "statusBarTranslucent", isSignal: true, isRequired: false, transformFunction: null }, navigationBarTranslucent: { classPropertyName: "navigationBarTranslucent", publicName: "navigationBarTranslucent", isSignal: true, isRequired: false, transformFunction: null }, hardwareAccelerated: { classPropertyName: "hardwareAccelerated", publicName: "hardwareAccelerated", isSignal: true, isRequired: false, transformFunction: null }, anchor: { classPropertyName: "anchor", publicName: "anchor", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "visible": "visible() && !awaitingAnchor()", "transparent": "transparent()", "animationType": "animationType()", "presentationStyle": "resolvedPresentationStyle()", "supportedOrientations": "supportedOrientations()", "allowSwipeDismissal": "allowSwipeDismissal()", "statusBarTranslucent": "statusBarTranslucent()", "navigationBarTranslucent": "navigationBarTranslucent()", "hardwareAccelerated": "hardwareAccelerated()", "anchor": "anchorTag()" } }, usesInheritance: true, ngImport: i0, template: `<view [style]="containerStyle()" collapsable="false"><ng-content /></view>`, isInline: true, dependencies: [{ kind: "directive", type: View, selector: "view" }] });
|
|
145
150
|
}
|
|
146
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.
|
|
151
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: Modal, decorators: [{
|
|
147
152
|
type: Component,
|
|
148
153
|
args: [{
|
|
149
154
|
selector: 'modal',
|
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,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;AAKD;;;;;;;;;;;;;GAaG;AAkBH,MAAM,OAAO,KAAM,SAAQ,QAAQ;IACjC;;;;;OAKG;IACM,OAAO,GAAG,KAAK,CAAC,IAAI,+EAAI,SAAS,EAAE,gBAAgB,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AAE,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"]}
|
|
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;AA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,4EAA4E,4DAD5E,IAAI;;2FAeH,KAAK;kBAjBjB,SAAS;mBAAC;oBACT,QAAQ,EAAE,OAAO;oBACjB,OAAO,EAAE,CAAC,IAAI,CAAC;oBACf,QAAQ,EAAE,4EAA4E;oBACtF,IAAI,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 // A modal made outside a change detection (with a routed page, by `createComponent`) is in the\n // tree before its `visible` binding has run, and a commit in between would read it as showing:\n // the host presents it, empty, for that one commit. It starts hidden, and the binding's first\n // value says whether it shows.\n this.engine.setProp(this.node, 'visible', false);\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"]}
|