@lowdefy/blocks-native 0.0.0-experimental-20261019052246
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/LICENSE +201 -0
- package/README.md +10 -0
- package/dist/blocks/ActivityTimeline/ActivityTimeline.js +477 -0
- package/dist/blocks/ActivityTimeline/CommentBody.js +174 -0
- package/dist/blocks/ActivityTimeline/CommentItem.js +300 -0
- package/dist/blocks/ActivityTimeline/EditBox.js +143 -0
- package/dist/blocks/ActivityTimeline/LineText.js +71 -0
- package/dist/blocks/ActivityTimeline/RailIcon.js +41 -0
- package/dist/blocks/ActivityTimeline/RailRow.js +74 -0
- package/dist/blocks/ActivityTimeline/ReactionPicker.js +68 -0
- package/dist/blocks/ActivityTimeline/ReactionPills.js +112 -0
- package/dist/blocks/ActivityTimeline/ThreadCard.js +159 -0
- package/dist/blocks/ActivityTimeline/TimelineMarkdownRenderer.js +48 -0
- package/dist/blocks/ActivityTimeline/buildTimelineRows.js +194 -0
- package/dist/blocks/ActivityTimeline/describeEvent.js +61 -0
- package/dist/blocks/ActivityTimeline/describeGap.js +71 -0
- package/dist/blocks/ActivityTimeline/fillTemplate.js +84 -0
- package/dist/blocks/ActivityTimeline/fillText.js +38 -0
- package/dist/blocks/ActivityTimeline/formatRelativeTime.js +68 -0
- package/dist/blocks/ActivityTimeline/getActor.js +41 -0
- package/dist/blocks/ActivityTimeline/getCommentMenuActions.js +85 -0
- package/dist/blocks/ActivityTimeline/getCommentView.js +72 -0
- package/dist/blocks/ActivityTimeline/getTimelineColors.js +71 -0
- package/dist/blocks/ActivityTimeline/getToneColor.js +49 -0
- package/dist/blocks/ActivityTimeline/getVisibleReplies.js +36 -0
- package/dist/blocks/ActivityTimeline/isThreadShown.js +28 -0
- package/dist/blocks/ActivityTimeline/joinList.js +21 -0
- package/dist/blocks/ActivityTimeline/meta.js +314 -0
- package/dist/blocks/ActivityTimeline/parseTimelineHref.js +43 -0
- package/dist/blocks/ActivityTimeline/selectEventRule.js +69 -0
- package/dist/blocks/ActivityTimeline/summariseEvents.js +51 -0
- package/dist/blocks/ActivityTimeline/toPlainText.js +32 -0
- package/dist/blocks/ActivityTimeline/toTime.js +36 -0
- package/dist/blocks/ActivityTimeline/toTimelineMarkdown.js +57 -0
- package/dist/blocks/ActivityTimeline/toggleReaction.js +74 -0
- package/dist/blocks/ActivityTimeline/useNow.js +24 -0
- package/dist/blocks/AgentChat/AgentChat.js +726 -0
- package/dist/blocks/AgentChat/AssistantMessage.js +243 -0
- package/dist/blocks/AgentChat/ChatComposer.js +401 -0
- package/dist/blocks/AgentChat/ChatError.js +129 -0
- package/dist/blocks/AgentChat/ChatSkeleton.js +97 -0
- package/dist/blocks/AgentChat/ReasoningDisclosure.js +125 -0
- package/dist/blocks/AgentChat/ThinkingIndicator.js +103 -0
- package/dist/blocks/AgentChat/ThreadsSheet.js +347 -0
- package/dist/blocks/AgentChat/ToolApprovalCard.js +190 -0
- package/dist/blocks/AgentChat/ToolCallRow.js +187 -0
- package/dist/blocks/AgentChat/ToolDetail.js +137 -0
- package/dist/blocks/AgentChat/UserMessage.js +84 -0
- package/dist/blocks/AgentChat/WelcomeView.js +100 -0
- package/dist/blocks/AgentChat/createAgentTransport.js +74 -0
- package/dist/blocks/AgentChat/describeToolPart.js +133 -0
- package/dist/blocks/AgentChat/getChatSeed.js +44 -0
- package/dist/blocks/AgentChat/getFirstExchange.js +43 -0
- package/dist/blocks/AgentChat/getMessageSegments.js +73 -0
- package/dist/blocks/AgentChat/getMessageText.js +25 -0
- package/dist/blocks/AgentChat/getPageStateUpdates.js +47 -0
- package/dist/blocks/AgentChat/getProvisionalTitle.js +32 -0
- package/dist/blocks/AgentChat/getReadableRows.js +157 -0
- package/dist/blocks/AgentChat/getThreadEndpoints.js +54 -0
- package/dist/blocks/AgentChat/getToolIcon.js +110 -0
- package/dist/blocks/AgentChat/humanizeToolName.js +30 -0
- package/dist/blocks/AgentChat/messageParts.js +86 -0
- package/dist/blocks/AgentChat/meta.js +530 -0
- package/dist/blocks/AgentChat/mintConversationId.js +29 -0
- package/dist/blocks/AgentChat/replayableMessages.js +62 -0
- package/dist/blocks/AgentChat/showMessageMenu.js +49 -0
- package/dist/blocks/AgentChat/summarizeToolInput.js +36 -0
- package/dist/blocks/AgentChat/summarizeToolOutput.js +49 -0
- package/dist/blocks/AgentChat/useAgentEvents.js +218 -0
- package/dist/blocks/AgentChat/useChatDictation.js +151 -0
- package/dist/blocks/AgentChat/useChatThreads.js +450 -0
- package/dist/blocks/AgentChat/useFollowScroll.js +80 -0
- package/dist/blocks/AgentChat/useThinkingMessage.js +77 -0
- package/dist/blocks/Alert/Alert.js +167 -0
- package/dist/blocks/Alert/meta.js +200 -0
- package/dist/blocks/Avatar/Avatar.js +49 -0
- package/dist/blocks/Avatar/AvatarCircle.js +111 -0
- package/dist/blocks/Avatar/AvatarPhoto.js +70 -0
- package/dist/blocks/Avatar/AvatarStack.js +87 -0
- package/dist/blocks/Avatar/getAvatarColor.js +84 -0
- package/dist/blocks/Avatar/getAvatarImage.js +95 -0
- package/dist/blocks/Avatar/getInitials.js +51 -0
- package/dist/blocks/Avatar/meta.js +57 -0
- package/dist/blocks/Box/Box.js +118 -0
- package/dist/blocks/Box/getRubberBand.js +29 -0
- package/dist/blocks/Box/getSwipeDirection.js +45 -0
- package/dist/blocks/Box/isSwipeGesture.js +41 -0
- package/dist/blocks/Box/meta.js +46 -0
- package/dist/blocks/Box/useSwipeGesture.js +113 -0
- package/dist/blocks/Button/Button.js +136 -0
- package/dist/blocks/Button/getButtonColors.js +216 -0
- package/dist/blocks/Button/meta.js +137 -0
- package/dist/blocks/Card/Card.js +185 -0
- package/dist/blocks/Card/meta.js +203 -0
- package/dist/blocks/ChipSelector/Chip.js +178 -0
- package/dist/blocks/ChipSelector/ChipSelector.js +311 -0
- package/dist/blocks/ChipSelector/EdgeFade.js +68 -0
- package/dist/blocks/ChipSelector/getChipColors.js +88 -0
- package/dist/blocks/ChipSelector/getFadeRanges.js +55 -0
- package/dist/blocks/ChipSelector/getOverscrollSwipe.js +44 -0
- package/dist/blocks/ChipSelector/getScrollTarget.js +41 -0
- package/dist/blocks/ChipSelector/meta.js +156 -0
- package/dist/blocks/Composer/Composer.js +501 -0
- package/dist/blocks/Composer/MentionTextInput.js +91 -0
- package/dist/blocks/Composer/SuggestionList.js +163 -0
- package/dist/blocks/Composer/applyDisplayEdit.js +81 -0
- package/dist/blocks/Composer/convertSpokenMentions.js +234 -0
- package/dist/blocks/Composer/createMentionPattern.js +40 -0
- package/dist/blocks/Composer/findTrigger.js +51 -0
- package/dist/blocks/Composer/getSendState.js +38 -0
- package/dist/blocks/Composer/getSpokenMentionWords.js +35 -0
- package/dist/blocks/Composer/indexSpokenNames.js +50 -0
- package/dist/blocks/Composer/insertLink.js +36 -0
- package/dist/blocks/Composer/insertMention.js +43 -0
- package/dist/blocks/Composer/matchSpokenName.js +88 -0
- package/dist/blocks/Composer/meta.js +212 -0
- package/dist/blocks/Composer/parseMentionValue.js +55 -0
- package/dist/blocks/Composer/placeDictation.js +51 -0
- package/dist/blocks/Composer/rankMentions.js +51 -0
- package/dist/blocks/Composer/replaceRange.js +48 -0
- package/dist/blocks/Composer/segmentText.js +78 -0
- package/dist/blocks/Composer/shiftOffset.js +37 -0
- package/dist/blocks/Composer/snapSelection.js +37 -0
- package/dist/blocks/Composer/useMentionEditor.js +381 -0
- package/dist/blocks/Composer/withPartial.js +50 -0
- package/dist/blocks/DateSelector/DateSelector.js +250 -0
- package/dist/blocks/DateSelector/formatDateValue.js +34 -0
- package/dist/blocks/DateSelector/getDateMenuActions.js +96 -0
- package/dist/blocks/DateSelector/meta.js +109 -0
- package/dist/blocks/DateSelector/toBoundDate.js +40 -0
- package/dist/blocks/DateSelector/toPickerDate.js +31 -0
- package/dist/blocks/DateSelector/toUtcDay.js +25 -0
- package/dist/blocks/Divider/Divider.js +159 -0
- package/dist/blocks/Divider/meta.js +108 -0
- package/dist/blocks/Empty/Empty.js +107 -0
- package/dist/blocks/Empty/meta.js +61 -0
- package/dist/blocks/Icon/Icon.js +41 -0
- package/dist/blocks/Icon/meta.js +80 -0
- package/dist/blocks/Illustration/Illustration.js +154 -0
- package/dist/blocks/Illustration/IllustrationLayer.js +105 -0
- package/dist/blocks/Illustration/colorNodes.js +72 -0
- package/dist/blocks/Illustration/createIllustrationMotion.js +172 -0
- package/dist/blocks/Illustration/getIllustrationBox.js +54 -0
- package/dist/blocks/Illustration/getIllustrationColors.js +48 -0
- package/dist/blocks/Illustration/getKeyframeRange.js +99 -0
- package/dist/blocks/Illustration/getLayerBounds.js +74 -0
- package/dist/blocks/Illustration/getLayers.js +113 -0
- package/dist/blocks/Illustration/getNodePoints.js +210 -0
- package/dist/blocks/Illustration/meta.js +196 -0
- package/dist/blocks/Illustration/parseIllustration.js +84 -0
- package/dist/blocks/Illustration/toBoundingBoxGradients.js +188 -0
- package/dist/blocks/Illustration/useIllustrationMotion.js +75 -0
- package/dist/blocks/Label/Label.js +111 -0
- package/dist/blocks/Label/getLabelProperties.js +38 -0
- package/dist/blocks/Label/getLabelState.js +59 -0
- package/dist/blocks/List/List.js +159 -0
- package/dist/blocks/List/ListRow.js +74 -0
- package/dist/blocks/List/ListRowContext.js +20 -0
- package/dist/blocks/List/SectionHeader.js +119 -0
- package/dist/blocks/List/getSections.js +161 -0
- package/dist/blocks/List/meta.js +190 -0
- package/dist/blocks/ListItem/ListItem.js +418 -0
- package/dist/blocks/ListItem/ListItemContextMenu.js +58 -0
- package/dist/blocks/ListItem/getListItemParts.js +101 -0
- package/dist/blocks/ListItem/getSfSymbol.js +33 -0
- package/dist/blocks/ListItem/meta.js +284 -0
- package/dist/blocks/ListItem/showContextMenuAlert.js +36 -0
- package/dist/blocks/Markdown/ChipWidthContext.js +20 -0
- package/dist/blocks/Markdown/ChipWidthView.js +40 -0
- package/dist/blocks/Markdown/LinkChip.js +151 -0
- package/dist/blocks/Markdown/Markdown.js +42 -0
- package/dist/blocks/Markdown/MarkdownCode.js +67 -0
- package/dist/blocks/Markdown/MarkdownContent.js +101 -0
- package/dist/blocks/Markdown/MarkdownList.js +97 -0
- package/dist/blocks/Markdown/MarkdownListContext.js +22 -0
- package/dist/blocks/Markdown/MarkdownRenderer.js +223 -0
- package/dist/blocks/Markdown/MarkdownTable.js +96 -0
- package/dist/blocks/Markdown/MarkdownTokenizer.js +43 -0
- package/dist/blocks/Markdown/TaskBox.js +58 -0
- package/dist/blocks/Markdown/TaskMark.js +37 -0
- package/dist/blocks/Markdown/getChipMaxWidth.js +33 -0
- package/dist/blocks/Markdown/getLinkChip.js +95 -0
- package/dist/blocks/Markdown/getLinkChipColors.js +51 -0
- package/dist/blocks/Markdown/getListMarker.js +116 -0
- package/dist/blocks/Markdown/getMarkdownStyles.js +206 -0
- package/dist/blocks/Markdown/getNodeText.js +37 -0
- package/dist/blocks/Markdown/layoutLinkChips.js +209 -0
- package/dist/blocks/Markdown/matchLinkChip.js +82 -0
- package/dist/blocks/Markdown/meta.js +50 -0
- package/dist/blocks/Markdown/restyleText.js +40 -0
- package/dist/blocks/Markdown/trimOuterSpace.js +42 -0
- package/dist/blocks/Menu/Menu.js +96 -0
- package/dist/blocks/Menu/getMenuActions.js +66 -0
- package/dist/blocks/Menu/meta.js +159 -0
- package/dist/blocks/MultipleSelector/MultipleSelector.js +288 -0
- package/dist/blocks/MultipleSelector/MultipleSelectorRow.js +71 -0
- package/dist/blocks/MultipleSelector/ValueSummary.js +130 -0
- package/dist/blocks/MultipleSelector/getOptionIndices.js +30 -0
- package/dist/blocks/MultipleSelector/getSessionOptions.js +38 -0
- package/dist/blocks/MultipleSelector/getSummaryCount.js +35 -0
- package/dist/blocks/MultipleSelector/meta.js +284 -0
- package/dist/blocks/MultipleSelector/toggleValue.js +50 -0
- package/dist/blocks/NumberInput/NumberInput.js +251 -0
- package/dist/blocks/NumberInput/StepButton.js +46 -0
- package/dist/blocks/NumberInput/formatNumber.js +35 -0
- package/dist/blocks/NumberInput/getNumberKeyboardType.js +32 -0
- package/dist/blocks/NumberInput/meta.js +123 -0
- package/dist/blocks/NumberInput/normalizeNumber.js +38 -0
- package/dist/blocks/NumberInput/parseNumberText.js +46 -0
- package/dist/blocks/PageDots/PageDots.js +131 -0
- package/dist/blocks/PageDots/meta.js +48 -0
- package/dist/blocks/Paragraph/Paragraph.js +52 -0
- package/dist/blocks/Paragraph/meta.js +295 -0
- package/dist/blocks/Screen/meta.js +197 -0
- package/dist/blocks/SegmentedControl/SegmentedControl.js +75 -0
- package/dist/blocks/SegmentedControl/meta.js +78 -0
- package/dist/blocks/Selector/NoValueAvatar.js +42 -0
- package/dist/blocks/Selector/PickerOptionRow.js +130 -0
- package/dist/blocks/Selector/PickerRowLeading.js +57 -0
- package/dist/blocks/Selector/PickerSearchField.js +85 -0
- package/dist/blocks/Selector/PickerSheet.js +239 -0
- package/dist/blocks/Selector/Selector.js +120 -0
- package/dist/blocks/Selector/SelectorMenu.js +97 -0
- package/dist/blocks/Selector/SelectorRow.js +86 -0
- package/dist/blocks/Selector/SelectorSheet.js +131 -0
- package/dist/blocks/Selector/getOptionIndex.js +39 -0
- package/dist/blocks/Selector/getOptionLabel.js +32 -0
- package/dist/blocks/Selector/getOptionValue.js +20 -0
- package/dist/blocks/Selector/getPickerSheetDetents.js +45 -0
- package/dist/blocks/Selector/getPickerSheetRows.js +174 -0
- package/dist/blocks/Selector/getPickerSheetScrollIndex.js +35 -0
- package/dist/blocks/Selector/getSelectorMenuActions.js +61 -0
- package/dist/blocks/Selector/meta.js +195 -0
- package/dist/blocks/Selector/normalizeSearchText.js +27 -0
- package/dist/blocks/Selector/setSelectorValue.js +52 -0
- package/dist/blocks/Sheet/Sheet.js +174 -0
- package/dist/blocks/Sheet/getSheetDetents.js +56 -0
- package/dist/blocks/Sheet/meta.js +72 -0
- package/dist/blocks/Skeleton/Skeleton.js +131 -0
- package/dist/blocks/Skeleton/SkeletonCard.js +42 -0
- package/dist/blocks/Skeleton/SkeletonHero.js +72 -0
- package/dist/blocks/Skeleton/SkeletonInsetGroup.js +82 -0
- package/dist/blocks/Skeleton/SkeletonListRow.js +90 -0
- package/dist/blocks/Skeleton/SkeletonParagraph.js +36 -0
- package/dist/blocks/Skeleton/SkeletonRows.js +58 -0
- package/dist/blocks/Skeleton/SkeletonTimeline.js +88 -0
- package/dist/blocks/Skeleton/getBarWidth.js +45 -0
- package/dist/blocks/Skeleton/getParagraphWidths.js +56 -0
- package/dist/blocks/Skeleton/getSectionCounts.js +33 -0
- package/dist/blocks/Skeleton/getSkeletonVariant.js +27 -0
- package/dist/blocks/Skeleton/meta.js +98 -0
- package/dist/blocks/Spinner/Spinner.js +68 -0
- package/dist/blocks/Spinner/meta.js +35 -0
- package/dist/blocks/StatusIcon/StatusGlyph.js +247 -0
- package/dist/blocks/StatusIcon/StatusIcon.js +34 -0
- package/dist/blocks/StatusIcon/StatusMark.js +87 -0
- package/dist/blocks/StatusIcon/getPiePath.js +41 -0
- package/dist/blocks/StatusIcon/getStatusColor.js +61 -0
- package/dist/blocks/StatusIcon/meta.js +38 -0
- package/dist/blocks/StatusIcon/statusLabels.js +33 -0
- package/dist/blocks/Switch/Switch.js +83 -0
- package/dist/blocks/Switch/meta.js +78 -0
- package/dist/blocks/Tabs/Tabs.js +269 -0
- package/dist/blocks/Tabs/meta.js +305 -0
- package/dist/blocks/Tag/TONE_PALETTES.js +34 -0
- package/dist/blocks/Tag/Tag.js +173 -0
- package/dist/blocks/Tag/getTagColors.js +120 -0
- package/dist/blocks/Tag/getTagDotColor.js +32 -0
- package/dist/blocks/Tag/meta.js +131 -0
- package/dist/blocks/TextArea/ComposerSendButton.js +69 -0
- package/dist/blocks/TextArea/TextArea.js +167 -0
- package/dist/blocks/TextArea/meta.js +96 -0
- package/dist/blocks/TextInput/TextInput.js +253 -0
- package/dist/blocks/TextInput/applyReplaceInput.js +30 -0
- package/dist/blocks/TextInput/getKeyboardProps.js +64 -0
- package/dist/blocks/TextInput/getSearchBoxStyle.js +39 -0
- package/dist/blocks/TextInput/meta.js +113 -0
- package/dist/blocks/Title/Title.js +62 -0
- package/dist/blocks/Title/meta.js +355 -0
- package/dist/blocks.js +48 -0
- package/dist/dictation.js +17 -0
- package/dist/htmlToText.js +32 -0
- package/dist/metas.js +49 -0
- package/dist/schemas/avatar.js +40 -0
- package/dist/schemas/icon.js +65 -0
- package/dist/schemas/inputLabel.js +96 -0
- package/dist/schemas/inputProperties.js +92 -0
- package/dist/schemas/linkChips.js +85 -0
- package/dist/schemas/status.js +75 -0
- package/dist/schemas/textStyle.js +33 -0
- package/dist/schemas/tone.js +28 -0
- package/dist/shared/ClearButton.js +53 -0
- package/dist/shared/CountText.js +38 -0
- package/dist/shared/NativeMenu.js +66 -0
- package/dist/shared/OptionGlyph.js +58 -0
- package/dist/shared/PropertyRow.js +89 -0
- package/dist/shared/SheetCloseButton.js +51 -0
- package/dist/shared/SheetDoneButton.js +44 -0
- package/dist/shared/SwipeContext.js +20 -0
- package/dist/shared/SwipeableRow.js +292 -0
- package/dist/shared/SystemIcon.js +72 -0
- package/dist/shared/dictation/DictationButton.js +77 -0
- package/dist/shared/dictation/DictationWarning.js +89 -0
- package/dist/shared/dictation/LevelMeter.js +57 -0
- package/dist/shared/dictation/ListeningRow.js +100 -0
- package/dist/shared/dictation/PartialSpans.js +50 -0
- package/dist/shared/dictation/checkDictationAvailable.js +65 -0
- package/dist/shared/dictation/claimMic.js +68 -0
- package/dist/shared/dictation/createQueuedRecognizer.js +213 -0
- package/dist/shared/dictation/getDictationLevel.js +30 -0
- package/dist/shared/dictation/getDictationWarning.js +40 -0
- package/dist/shared/dictation/getLevelBars.js +38 -0
- package/dist/shared/dictation/getRecognizer.js +46 -0
- package/dist/shared/dictation/getStartOptions.js +42 -0
- package/dist/shared/dictation/insertAtSelection.js +48 -0
- package/dist/shared/dictation/pickRecognitionLocale.js +37 -0
- package/dist/shared/dictation/useDictation.js +299 -0
- package/dist/shared/getControlSize.js +50 -0
- package/dist/shared/getInputBoxStyle.js +93 -0
- package/dist/shared/getPropertyRowTextStyles.js +40 -0
- package/dist/shared/getSemanticColors.js +96 -0
- package/dist/shared/getToneColor.js +51 -0
- package/dist/shared/iosTextStyles.js +49 -0
- package/dist/shared/useBlockTokens.js +41 -0
- package/dist/skeleton/SkeletonFrameContext.js +21 -0
- package/dist/skeleton/SkeletonLine.js +46 -0
- package/dist/skeleton/SkeletonShape.js +140 -0
- package/dist/skeleton/createShimmerClock.js +57 -0
- package/dist/skeleton/shimmerClock.js +20 -0
- package/dist/skeleton/skeletonText.js +44 -0
- package/dist/skeleton/useShimmer.js +34 -0
- package/dist/types.js +17 -0
- package/dist/typography/TITLE_LEVEL_STYLES.js +24 -0
- package/dist/typography/TypographyText.js +78 -0
- package/dist/typography/getIosTextStyle.js +33 -0
- package/dist/typography/getTextStyle.js +94 -0
- package/dist/useComponentTokens.js +38 -0
- package/package.json +94 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Errors that end a session without anything going wrong for the person: they cancelled
|
|
16
|
+
// ("aborted", which iOS sends on abort()), or they said nothing ("no-speech", and Android's
|
|
17
|
+
// "speech-timeout" for the same case).
|
|
18
|
+
const QUIET = new Set([
|
|
19
|
+
'aborted',
|
|
20
|
+
'no-speech',
|
|
21
|
+
'speech-timeout'
|
|
22
|
+
]);
|
|
23
|
+
/**
|
|
24
|
+
* The warning a speech recognition error shows: `denied` when the microphone or speech permission
|
|
25
|
+
* is refused, nothing for a session the person ended or left silent, and `failed` for anything
|
|
26
|
+
* else.
|
|
27
|
+
*
|
|
28
|
+
* @param {Object} params
|
|
29
|
+
* @param {string} params.error The error code of expo-speech-recognition's error event.
|
|
30
|
+
* @returns {'denied'|'failed'|null}
|
|
31
|
+
*/ function getDictationWarning({ error }) {
|
|
32
|
+
if (error === 'not-allowed') {
|
|
33
|
+
return 'denied';
|
|
34
|
+
}
|
|
35
|
+
if (QUIET.has(error)) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
return 'failed';
|
|
39
|
+
}
|
|
40
|
+
export default getDictationWarning;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // One level drives all eight bars. Each bar has its own share of it, so the meter reads as a
|
|
16
|
+
// waveform rather than a block that grows.
|
|
17
|
+
const SHAPE = [
|
|
18
|
+
0.3,
|
|
19
|
+
0.6,
|
|
20
|
+
1,
|
|
21
|
+
0.55,
|
|
22
|
+
0.8,
|
|
23
|
+
0.4,
|
|
24
|
+
0.7,
|
|
25
|
+
0.25
|
|
26
|
+
];
|
|
27
|
+
const MIN_HEIGHT = 4;
|
|
28
|
+
const MAX_HEIGHT = 22;
|
|
29
|
+
/**
|
|
30
|
+
* The heights, in points, of the level meter's eight bars for an input level.
|
|
31
|
+
*
|
|
32
|
+
* @param {Object} params
|
|
33
|
+
* @param {number} params.level The input level, from 0 to 1.
|
|
34
|
+
* @returns {number[]}
|
|
35
|
+
*/ function getLevelBars({ level }) {
|
|
36
|
+
return SHAPE.map((share)=>Math.round(MIN_HEIGHT + (MAX_HEIGHT - MIN_HEIGHT) * share * level));
|
|
37
|
+
}
|
|
38
|
+
export default getLevelBars;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { ExpoSpeechRecognitionModule } from 'expo-speech-recognition';
|
|
16
|
+
import createQueuedRecognizer from './createQueuedRecognizer.js';
|
|
17
|
+
// The stand-in Lowdefy Dev installs, so agents and journeys can dictate. A release shell never
|
|
18
|
+
// installs one, and dictation uses the phone's recogniser.
|
|
19
|
+
let installed = null;
|
|
20
|
+
/**
|
|
21
|
+
* The recogniser dictation uses: the one Lowdefy Dev installed, or expo-speech-recognition's.
|
|
22
|
+
*/ function getRecognizer() {
|
|
23
|
+
return installed ?? ExpoSpeechRecognitionModule;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Makes dictation play injected transcripts, and use the microphone when none is injected
|
|
27
|
+
* (createQueuedRecognizer). blocks-native cannot import the shell, so the shell's dev build passes
|
|
28
|
+
* in its `injected`.
|
|
29
|
+
*
|
|
30
|
+
* @param {(name: string) => any} read Reads an injection: `transcript` and
|
|
31
|
+
* `permission:microphone`.
|
|
32
|
+
* @returns {() => void} Removes it.
|
|
33
|
+
*/ function installDictationSource(read) {
|
|
34
|
+
const recognizer = createQueuedRecognizer({
|
|
35
|
+
device: ExpoSpeechRecognitionModule,
|
|
36
|
+
read
|
|
37
|
+
});
|
|
38
|
+
installed = recognizer;
|
|
39
|
+
return ()=>{
|
|
40
|
+
if (installed === recognizer) {
|
|
41
|
+
installed = null;
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
export { installDictationSource };
|
|
46
|
+
export default getRecognizer;
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { type } from '@lowdefy/helpers';
|
|
16
|
+
const MAX_HINTS = 100;
|
|
17
|
+
/**
|
|
18
|
+
* The options a dictation session starts expo-speech-recognition with: words as they are heard,
|
|
19
|
+
* until stopped, recognised on the phone only (never on Apple's or Google's servers), punctuated,
|
|
20
|
+
* as text entry, in the phone's language, with the host's hints (such as the names that can be
|
|
21
|
+
* mentioned) and the input level.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} params
|
|
24
|
+
* @param {string[]} [params.hints] Words the recogniser should expect; the first 100 are used.
|
|
25
|
+
* @param {string} params.lang The recognition locale.
|
|
26
|
+
* @returns {Object}
|
|
27
|
+
*/ function getStartOptions({ hints, lang }) {
|
|
28
|
+
const contextualStrings = (hints ?? []).filter((hint)=>type.isString(hint) && hint !== '').slice(0, MAX_HINTS);
|
|
29
|
+
return {
|
|
30
|
+
lang,
|
|
31
|
+
interimResults: true,
|
|
32
|
+
continuous: true,
|
|
33
|
+
requiresOnDeviceRecognition: true,
|
|
34
|
+
addsPunctuation: true,
|
|
35
|
+
iosTaskHint: 'dictation',
|
|
36
|
+
contextualStrings,
|
|
37
|
+
volumeChangeEventOptions: {
|
|
38
|
+
enabled: true
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
export default getStartOptions;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // Words that start with closing punctuation join the word before them: "gate" + ", then" reads
|
|
16
|
+
// "gate, then", not "gate , then".
|
|
17
|
+
const STARTS_WITH_PUNCTUATION = /^[.,!?;:…)\]}]/;
|
|
18
|
+
const ENDS_WITH_SPACE = /\s$/;
|
|
19
|
+
/**
|
|
20
|
+
* Puts dictated words into a text at the selection: replaces the selected text, or inserts at the
|
|
21
|
+
* cursor. A space goes before the words unless the text before them is empty, already ends in
|
|
22
|
+
* whitespace, or the words start with punctuation.
|
|
23
|
+
*
|
|
24
|
+
* @param {Object} params
|
|
25
|
+
* @param {{ start: number, end: number }} [params.selection] The selection, or the cursor when
|
|
26
|
+
* start equals end. Without one, the words go at the end of the text.
|
|
27
|
+
* @param {string} params.insert The words to put in.
|
|
28
|
+
* @param {string} params.text
|
|
29
|
+
* @returns {{ text: string, cursor: number }} The new text, and the cursor just after the words.
|
|
30
|
+
*/ function insertAtSelection({ text, selection, insert }) {
|
|
31
|
+
const start = selection?.start ?? text.length;
|
|
32
|
+
const end = selection?.end ?? start;
|
|
33
|
+
if (insert === '') {
|
|
34
|
+
return {
|
|
35
|
+
text,
|
|
36
|
+
cursor: end
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
const before = text.slice(0, start);
|
|
40
|
+
const after = text.slice(end);
|
|
41
|
+
const needsSpace = before !== '' && !ENDS_WITH_SPACE.test(before) && !STARTS_WITH_PUNCTUATION.test(insert);
|
|
42
|
+
const words = needsSpace ? ` ${insert}` : insert;
|
|
43
|
+
return {
|
|
44
|
+
text: `${before}${words}${after}`,
|
|
45
|
+
cursor: start + words.length
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
export default insertAtSelection;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ function normalise(locale) {
|
|
16
|
+
return locale.replace(/_/g, '-').toLowerCase();
|
|
17
|
+
}
|
|
18
|
+
function languageOf(locale) {
|
|
19
|
+
return normalise(locale).split('-')[0];
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The installed recognition locale to dictate in for the phone's language: the phone's own
|
|
23
|
+
* locale when it is installed, else another installed locale of the same language (en-US for a
|
|
24
|
+
* phone set to en-ZA), else null. Locales compare without case, and with "_" read as "-".
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} params
|
|
27
|
+
* @param {string} params.lang The phone's locale, such as "en-ZA".
|
|
28
|
+
* @param {string[]} params.locales The locales the recogniser has installed.
|
|
29
|
+
* @returns {string|null}
|
|
30
|
+
*/ function pickRecognitionLocale({ lang, locales }) {
|
|
31
|
+
const exact = locales.find((locale)=>normalise(locale) === normalise(lang));
|
|
32
|
+
if (exact !== undefined) {
|
|
33
|
+
return exact;
|
|
34
|
+
}
|
|
35
|
+
return locales.find((locale)=>languageOf(locale) === languageOf(lang)) ?? null;
|
|
36
|
+
}
|
|
37
|
+
export default pickRecognitionLocale;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ import { useCallback, useEffect, useRef, useState } from 'react';
|
|
16
|
+
import { AppState } from 'react-native';
|
|
17
|
+
import checkDictationAvailable from './checkDictationAvailable.js';
|
|
18
|
+
import claimMic from './claimMic.js';
|
|
19
|
+
import getDictationLevel from './getDictationLevel.js';
|
|
20
|
+
import getDictationWarning from './getDictationWarning.js';
|
|
21
|
+
import getRecognizer from './getRecognizer.js';
|
|
22
|
+
import getStartOptions from './getStartOptions.js';
|
|
23
|
+
const FINISH_MS = 1500;
|
|
24
|
+
const SILENCE_MS = 20000;
|
|
25
|
+
function settle(session) {
|
|
26
|
+
const waiters = session.waiters;
|
|
27
|
+
session.waiters = [];
|
|
28
|
+
waiters.forEach((resolve)=>resolve());
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Dictation into a native input, on the phone only. The hook owns the recogniser (getRecognizer:
|
|
32
|
+
* the phone's, or the one playing Lowdefy Dev's injected transcripts): whether it can run, the
|
|
33
|
+
* permission prompts, the start options, the input level, the silence timer, ending on
|
|
34
|
+
* background and unmount, the error warning and the one session the app can run at a time. It
|
|
35
|
+
* holds none of the host's text: it reports words still being heard as `partial` and hands each
|
|
36
|
+
* final result to `onFinal`, and the host puts both where they belong.
|
|
37
|
+
*
|
|
38
|
+
* A session ends on its own after 20 s without words, when the app goes to the background and when
|
|
39
|
+
* another input starts the mic. Those keep the words heard so far, as `stop()` does. `cancel()`
|
|
40
|
+
* drops them, and so does unmounting the host, since nothing is left to take them.
|
|
41
|
+
*
|
|
42
|
+
* @param {Object} params
|
|
43
|
+
* @param {boolean} [params.disabled] While true, `available` is false and `start` does nothing.
|
|
44
|
+
* @param {string[]} [params.hints] Words to expect, such as the names that can be mentioned.
|
|
45
|
+
* @param {(text: string) => void} params.onFinal Called once for each final result, without
|
|
46
|
+
* surrounding spaces: for each segment as it is heard on Android and on iOS 18 and later, and
|
|
47
|
+
* once at stop on earlier iOS.
|
|
48
|
+
* @returns {{
|
|
49
|
+
* available: boolean,
|
|
50
|
+
* status: 'idle'|'listening'|'stopping',
|
|
51
|
+
* level: number,
|
|
52
|
+
* partial: string,
|
|
53
|
+
* warning: 'denied'|'failed'|null,
|
|
54
|
+
* start: () => Promise<void>,
|
|
55
|
+
* stop: () => void,
|
|
56
|
+
* cancel: () => void,
|
|
57
|
+
* finish: () => Promise<void>,
|
|
58
|
+
* clearWarning: () => void,
|
|
59
|
+
* }} `level` runs from 0 to 1. `finish` stops and resolves once the final result is committed, or
|
|
60
|
+
* after 1.5 s.
|
|
61
|
+
*/ function useDictation({ disabled = false, hints, onFinal }) {
|
|
62
|
+
const [supported, setSupported] = useState(false);
|
|
63
|
+
const [status, setStatus] = useState('idle');
|
|
64
|
+
const [level, setLevel] = useState(0);
|
|
65
|
+
const [partial, setPartial] = useState('');
|
|
66
|
+
const [warning, setWarning] = useState(null);
|
|
67
|
+
const sessionRef = useRef(null);
|
|
68
|
+
const langRef = useRef(null);
|
|
69
|
+
const latest = useRef({
|
|
70
|
+
hints,
|
|
71
|
+
onFinal
|
|
72
|
+
});
|
|
73
|
+
latest.current = {
|
|
74
|
+
hints,
|
|
75
|
+
onFinal
|
|
76
|
+
};
|
|
77
|
+
const available = supported && !disabled;
|
|
78
|
+
useEffect(()=>{
|
|
79
|
+
let mounted = true;
|
|
80
|
+
checkDictationAvailable().then((result)=>{
|
|
81
|
+
if (!mounted) return;
|
|
82
|
+
langRef.current = result.lang;
|
|
83
|
+
setSupported(result.available);
|
|
84
|
+
});
|
|
85
|
+
return ()=>{
|
|
86
|
+
mounted = false;
|
|
87
|
+
};
|
|
88
|
+
}, []);
|
|
89
|
+
const endSession = useCallback((session)=>{
|
|
90
|
+
clearTimeout(session.silence);
|
|
91
|
+
if (!session.cancelled && session.partial !== '') {
|
|
92
|
+
latest.current.onFinal(session.partial);
|
|
93
|
+
}
|
|
94
|
+
sessionRef.current = null;
|
|
95
|
+
session.mic?.release();
|
|
96
|
+
settle(session);
|
|
97
|
+
setStatus('idle');
|
|
98
|
+
setLevel(0);
|
|
99
|
+
setPartial('');
|
|
100
|
+
}, []);
|
|
101
|
+
const stop = useCallback(()=>{
|
|
102
|
+
const session = sessionRef.current;
|
|
103
|
+
if (session === null || session.stopping) return;
|
|
104
|
+
if (session.mic === null) {
|
|
105
|
+
// Still waiting on the permission prompt or the mic: nothing has been heard yet.
|
|
106
|
+
session.cancelled = true;
|
|
107
|
+
endSession(session);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
session.stopping = true;
|
|
111
|
+
clearTimeout(session.silence);
|
|
112
|
+
setStatus('stopping');
|
|
113
|
+
getRecognizer().stop();
|
|
114
|
+
}, [
|
|
115
|
+
endSession
|
|
116
|
+
]);
|
|
117
|
+
const stopRef = useRef(stop);
|
|
118
|
+
stopRef.current = stop;
|
|
119
|
+
const resetSilence = useCallback((session)=>{
|
|
120
|
+
clearTimeout(session.silence);
|
|
121
|
+
if (session.stopping) return;
|
|
122
|
+
session.silence = setTimeout(()=>stopRef.current(), SILENCE_MS);
|
|
123
|
+
}, []);
|
|
124
|
+
const cancel = useCallback(()=>{
|
|
125
|
+
const session = sessionRef.current;
|
|
126
|
+
if (session === null) return;
|
|
127
|
+
session.cancelled = true;
|
|
128
|
+
session.partial = '';
|
|
129
|
+
setPartial('');
|
|
130
|
+
if (session.mic === null) {
|
|
131
|
+
endSession(session);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
getRecognizer().abort();
|
|
135
|
+
}, [
|
|
136
|
+
endSession
|
|
137
|
+
]);
|
|
138
|
+
const finish = useCallback(()=>{
|
|
139
|
+
const session = sessionRef.current;
|
|
140
|
+
if (session === null) {
|
|
141
|
+
return Promise.resolve();
|
|
142
|
+
}
|
|
143
|
+
return new Promise((resolve)=>{
|
|
144
|
+
const timer = setTimeout(done, FINISH_MS);
|
|
145
|
+
function done() {
|
|
146
|
+
clearTimeout(timer);
|
|
147
|
+
resolve();
|
|
148
|
+
}
|
|
149
|
+
session.waiters.push(done);
|
|
150
|
+
stop();
|
|
151
|
+
});
|
|
152
|
+
}, [
|
|
153
|
+
stop
|
|
154
|
+
]);
|
|
155
|
+
const start = useCallback(async ()=>{
|
|
156
|
+
if (!available || sessionRef.current !== null) return;
|
|
157
|
+
const session = {
|
|
158
|
+
cancelled: false,
|
|
159
|
+
mic: null,
|
|
160
|
+
partial: '',
|
|
161
|
+
silence: null,
|
|
162
|
+
stopping: false,
|
|
163
|
+
waiters: []
|
|
164
|
+
};
|
|
165
|
+
sessionRef.current = session;
|
|
166
|
+
setWarning(null);
|
|
167
|
+
const permission = await getRecognizer().requestPermissionsAsync();
|
|
168
|
+
if (sessionRef.current !== session) return;
|
|
169
|
+
if (permission.granted !== true) {
|
|
170
|
+
session.cancelled = true;
|
|
171
|
+
endSession(session);
|
|
172
|
+
setWarning('denied');
|
|
173
|
+
return;
|
|
174
|
+
}
|
|
175
|
+
const mic = await claimMic({
|
|
176
|
+
end: ()=>stopRef.current()
|
|
177
|
+
});
|
|
178
|
+
if (mic === null) {
|
|
179
|
+
if (sessionRef.current === session) endSession(session);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
if (sessionRef.current !== session) {
|
|
183
|
+
mic.release();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
session.mic = mic;
|
|
187
|
+
setPartial('');
|
|
188
|
+
setLevel(0);
|
|
189
|
+
setStatus('listening');
|
|
190
|
+
resetSilence(session);
|
|
191
|
+
getRecognizer().start(getStartOptions({
|
|
192
|
+
hints: latest.current.hints,
|
|
193
|
+
lang: langRef.current
|
|
194
|
+
}));
|
|
195
|
+
}, [
|
|
196
|
+
available,
|
|
197
|
+
endSession,
|
|
198
|
+
resetSilence
|
|
199
|
+
]);
|
|
200
|
+
const clearWarning = useCallback(()=>setWarning(null), []);
|
|
201
|
+
useEffect(()=>{
|
|
202
|
+
function ownSession() {
|
|
203
|
+
const session = sessionRef.current;
|
|
204
|
+
if (session === null || session.mic === null || !session.mic.owns()) return null;
|
|
205
|
+
return session;
|
|
206
|
+
}
|
|
207
|
+
const recognizer = getRecognizer();
|
|
208
|
+
const subscriptions = [
|
|
209
|
+
recognizer.addListener('result', (event)=>{
|
|
210
|
+
const session = ownSession();
|
|
211
|
+
if (session === null) return;
|
|
212
|
+
resetSilence(session);
|
|
213
|
+
// iOS 18 and later end a segment at each pause, as Android does, and start every later
|
|
214
|
+
// transcript with a space. The host spaces the words itself (insertAtSelection).
|
|
215
|
+
const text = (event.results[0]?.transcript ?? '').trim();
|
|
216
|
+
if (!event.isFinal) {
|
|
217
|
+
if (session.cancelled) return;
|
|
218
|
+
session.partial = text;
|
|
219
|
+
setPartial(text);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
session.partial = '';
|
|
223
|
+
setPartial('');
|
|
224
|
+
if (!session.cancelled && text !== '') {
|
|
225
|
+
latest.current.onFinal(text);
|
|
226
|
+
}
|
|
227
|
+
if (session.stopping) {
|
|
228
|
+
settle(session);
|
|
229
|
+
}
|
|
230
|
+
}),
|
|
231
|
+
recognizer.addListener('speechstart', ()=>{
|
|
232
|
+
const session = ownSession();
|
|
233
|
+
if (session !== null) resetSilence(session);
|
|
234
|
+
}),
|
|
235
|
+
recognizer.addListener('volumechange', (event)=>{
|
|
236
|
+
if (ownSession() !== null) setLevel(getDictationLevel({
|
|
237
|
+
value: event.value
|
|
238
|
+
}));
|
|
239
|
+
}),
|
|
240
|
+
recognizer.addListener('error', (event)=>{
|
|
241
|
+
if (ownSession() === null) return;
|
|
242
|
+
const next = getDictationWarning({
|
|
243
|
+
error: event.error
|
|
244
|
+
});
|
|
245
|
+
if (next !== null) setWarning(next);
|
|
246
|
+
}),
|
|
247
|
+
recognizer.addListener('end', ()=>{
|
|
248
|
+
const session = ownSession();
|
|
249
|
+
if (session !== null) endSession(session);
|
|
250
|
+
})
|
|
251
|
+
];
|
|
252
|
+
return ()=>{
|
|
253
|
+
subscriptions.forEach((subscription)=>subscription.remove());
|
|
254
|
+
};
|
|
255
|
+
}, [
|
|
256
|
+
endSession,
|
|
257
|
+
resetSilence
|
|
258
|
+
]);
|
|
259
|
+
useEffect(()=>{
|
|
260
|
+
const subscription = AppState.addEventListener('change', (state)=>{
|
|
261
|
+
// Android's permission prompt sends the app to the background too, so a session still
|
|
262
|
+
// waiting on the prompt or the mic carries on: only one that listens ends.
|
|
263
|
+
if (state === 'background' && sessionRef.current?.mic) stopRef.current();
|
|
264
|
+
});
|
|
265
|
+
return ()=>subscription.remove();
|
|
266
|
+
}, []);
|
|
267
|
+
useEffect(()=>{
|
|
268
|
+
return ()=>{
|
|
269
|
+
const session = sessionRef.current;
|
|
270
|
+
if (session === null) return;
|
|
271
|
+
sessionRef.current = null;
|
|
272
|
+
clearTimeout(session.silence);
|
|
273
|
+
settle(session);
|
|
274
|
+
if (session.mic === null) return;
|
|
275
|
+
// The host is gone, so nothing can take the words: drop them. The mic is free once the
|
|
276
|
+
// aborted session's own end event arrives, so its late events reach no other input.
|
|
277
|
+
const mic = session.mic;
|
|
278
|
+
const recognizer = getRecognizer();
|
|
279
|
+
const ended = recognizer.addListener('end', ()=>{
|
|
280
|
+
ended.remove();
|
|
281
|
+
mic.release();
|
|
282
|
+
});
|
|
283
|
+
recognizer.abort();
|
|
284
|
+
};
|
|
285
|
+
}, []);
|
|
286
|
+
return {
|
|
287
|
+
available,
|
|
288
|
+
status,
|
|
289
|
+
level,
|
|
290
|
+
partial,
|
|
291
|
+
warning,
|
|
292
|
+
start,
|
|
293
|
+
stop,
|
|
294
|
+
cancel,
|
|
295
|
+
finish,
|
|
296
|
+
clearWarning
|
|
297
|
+
};
|
|
298
|
+
}
|
|
299
|
+
export default useDictation;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Copyright 2020-2026 Lowdefy, Inc
|
|
3
|
+
|
|
4
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
you may not use this file except in compliance with the License.
|
|
6
|
+
You may obtain a copy of the License at
|
|
7
|
+
|
|
8
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
|
|
10
|
+
Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
See the License for the specific language governing permissions and
|
|
14
|
+
limitations under the License.
|
|
15
|
+
*/ // iOS control metrics: 44 points is the smallest comfortable touch target, so the default size
|
|
16
|
+
// is 44 tall in the body text size; small is a compact 34 in subheadline, large 50.
|
|
17
|
+
const SIZES = {
|
|
18
|
+
small: {
|
|
19
|
+
borderRadius: 8,
|
|
20
|
+
fontSize: 15,
|
|
21
|
+
height: 34,
|
|
22
|
+
paddingHorizontal: 10
|
|
23
|
+
},
|
|
24
|
+
default: {
|
|
25
|
+
borderRadius: 10,
|
|
26
|
+
fontSize: 17,
|
|
27
|
+
height: 44,
|
|
28
|
+
paddingHorizontal: 12
|
|
29
|
+
},
|
|
30
|
+
large: {
|
|
31
|
+
borderRadius: 12,
|
|
32
|
+
fontSize: 17,
|
|
33
|
+
height: 50,
|
|
34
|
+
paddingHorizontal: 16
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* The height, font size, corner radius and horizontal padding of an input or button for its
|
|
39
|
+
* `size`, at iOS control metrics.
|
|
40
|
+
*
|
|
41
|
+
* @param {Object} params
|
|
42
|
+
* @param {string} [params.size] 'small', 'default' or 'middle' (the same), or 'large'.
|
|
43
|
+
* @returns {{ borderRadius: number, fontSize: number, height: number, paddingHorizontal: number }}
|
|
44
|
+
*/ function getControlSize({ size }) {
|
|
45
|
+
if (size === 'small' || size === 'large') {
|
|
46
|
+
return SIZES[size];
|
|
47
|
+
}
|
|
48
|
+
return SIZES.default;
|
|
49
|
+
}
|
|
50
|
+
export default getControlSize;
|