@lowdefy/blocks-native 0.0.0-stage → 7.2.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/LICENSE +201 -0
- package/README.md +9 -2
- package/dist/actions/AddCalendarEvent/AddCalendarEvent.js +31 -0
- package/dist/actions/AddCalendarEvent/schema.js +55 -0
- package/dist/actions/AddContact/AddContact.js +24 -0
- package/dist/actions/AddContact/schema.js +49 -0
- package/dist/actions/CancelNotification/CancelNotification.js +23 -0
- package/dist/actions/CancelNotification/schema.js +31 -0
- package/dist/actions/DiscardQueuedRequest/DiscardQueuedRequest.js +23 -0
- package/dist/actions/DiscardQueuedRequest/schema.js +31 -0
- package/dist/actions/GetCalendarEvents/GetCalendarEvents.js +32 -0
- package/dist/actions/GetCalendarEvents/schema.js +35 -0
- package/dist/actions/GetRequestQueue/GetRequestQueue.js +24 -0
- package/dist/actions/GetRequestQueue/schema.js +22 -0
- package/dist/actions/Haptic/Haptic.js +38 -0
- package/dist/actions/Haptic/schema.js +37 -0
- package/dist/actions/KeepAwake/KeepAwake.js +23 -0
- package/dist/actions/KeepAwake/schema.js +28 -0
- package/dist/actions/PickContact/PickContact.js +24 -0
- package/dist/actions/PickContact/schema.js +22 -0
- package/dist/actions/PickFile/PickFile.js +32 -0
- package/dist/actions/PickFile/schema.js +58 -0
- package/dist/actions/PickImage/PickImage.js +32 -0
- package/dist/actions/PickImage/schema.js +76 -0
- package/dist/actions/ReadNfc/ReadNfc.js +24 -0
- package/dist/actions/ReadNfc/schema.js +27 -0
- package/dist/actions/RefreshWidgets/RefreshWidgets.js +24 -0
- package/dist/actions/RefreshWidgets/schema.js +22 -0
- package/dist/actions/RequestNotificationPermission/RequestNotificationPermission.js +24 -0
- package/dist/actions/RequestNotificationPermission/schema.js +22 -0
- package/dist/actions/RetryRequestQueue/RetryRequestQueue.js +24 -0
- package/dist/actions/RetryRequestQueue/schema.js +27 -0
- package/dist/actions/ScanCode/ScanCode.js +24 -0
- package/dist/actions/ScanCode/schema.js +54 -0
- package/dist/actions/ScanDocument/ScanDocument.js +32 -0
- package/dist/actions/ScanDocument/schema.js +57 -0
- package/dist/actions/ScheduleNotification/ScheduleNotification.js +27 -0
- package/dist/actions/ScheduleNotification/schema.js +67 -0
- package/dist/actions/SetBadgeCount/SetBadgeCount.js +27 -0
- package/dist/actions/SetBadgeCount/schema.js +31 -0
- package/dist/actions/SetBrightness/SetBrightness.js +24 -0
- package/dist/actions/SetBrightness/schema.js +33 -0
- package/dist/actions/Share/Share.js +50 -0
- package/dist/actions/Share/schema.js +51 -0
- package/dist/actions/Speak/Speak.js +27 -0
- package/dist/actions/Speak/schema.js +44 -0
- package/dist/actions/StartGeofencing/StartGeofencing.js +29 -0
- package/dist/actions/StartGeofencing/schema.js +63 -0
- package/dist/actions/StartLocationTracking/StartLocationTracking.js +29 -0
- package/dist/actions/StartLocationTracking/schema.js +59 -0
- package/dist/actions/StartRecording/StartRecording.js +23 -0
- package/dist/actions/StartRecording/schema.js +32 -0
- package/dist/actions/StopGeofencing/StopGeofencing.js +23 -0
- package/dist/actions/StopGeofencing/schema.js +22 -0
- package/dist/actions/StopLocationTracking/StopLocationTracking.js +23 -0
- package/dist/actions/StopLocationTracking/schema.js +22 -0
- package/dist/actions/StopRecording/StopRecording.js +37 -0
- package/dist/actions/StopRecording/schema.js +46 -0
- package/dist/actions/StopSpeaking/StopSpeaking.js +23 -0
- package/dist/actions/StopSpeaking/schema.js +22 -0
- package/dist/actions/TakePhoto/TakePhoto.js +31 -0
- package/dist/actions/TakePhoto/schema.js +67 -0
- package/dist/actions/WriteNfc/WriteNfc.js +28 -0
- package/dist/actions/WriteNfc/schema.js +61 -0
- package/dist/actions/uploadFiles.js +51 -0
- package/dist/actions.js +47 -0
- package/dist/blocks/ActivityTimeline/ActivityTimeline.js +507 -0
- package/dist/blocks/ActivityTimeline/CommentBody.js +176 -0
- package/dist/blocks/ActivityTimeline/CommentItem.js +302 -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 +160 -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 +320 -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 +51 -0
- package/dist/blocks/Avatar/AvatarCircle.js +114 -0
- package/dist/blocks/Avatar/AvatarPhoto.js +68 -0
- package/dist/blocks/Avatar/AvatarStack.js +89 -0
- package/dist/blocks/Avatar/getAvatarColor.js +84 -0
- package/dist/blocks/Avatar/getAvatarImage.js +97 -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 +313 -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 +511 -0
- package/dist/blocks/Composer/MentionTextInput.js +91 -0
- package/dist/blocks/Composer/SuggestionList.js +165 -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/FileInput/FileInput.js +253 -0
- package/dist/blocks/FileInput/formatFileSize.js +28 -0
- package/dist/blocks/FileInput/getFileSources.js +48 -0
- package/dist/blocks/FileInput/meta.js +123 -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 +440 -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/Map/Map.js +78 -0
- package/dist/blocks/Map/meta.js +153 -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 +70 -0
- package/dist/blocks/Markdown/MarkdownCode.js +67 -0
- package/dist/blocks/Markdown/MarkdownContent.js +119 -0
- package/dist/blocks/Markdown/MarkdownImage.js +77 -0
- package/dist/blocks/Markdown/MarkdownList.js +97 -0
- package/dist/blocks/Markdown/MarkdownListContext.js +22 -0
- package/dist/blocks/Markdown/MarkdownRenderer.js +231 -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 +56 -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 +290 -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/QRScanner/QRScanner.js +94 -0
- package/dist/blocks/QRScanner/createScanFilter.js +44 -0
- package/dist/blocks/QRScanner/meta.js +80 -0
- package/dist/blocks/Screen/meta.js +197 -0
- package/dist/blocks/SegmentedControl/SegmentedControl.js +77 -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 +122 -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 +54 -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/SignaturePad/SignaturePad.js +182 -0
- package/dist/blocks/SignaturePad/meta.js +74 -0
- package/dist/blocks/SignaturePad/toSignatureValue.js +52 -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 +85 -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 +52 -0
- package/dist/device/getDeviceFeature.js +81 -0
- package/dist/device/playFeedback.js +32 -0
- package/dist/device.js +18 -0
- package/dist/dictation.js +17 -0
- package/dist/htmlToText.js +32 -0
- package/dist/metas.js +53 -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/schemas.js +47 -0
- package/dist/shared/ClearButton.js +53 -0
- package/dist/shared/CountText.js +38 -0
- package/dist/shared/MissingFeature.js +43 -0
- package/dist/shared/NativeMenu.js +69 -0
- package/dist/shared/OptionGlyph.js +59 -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 +294 -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 +23 -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 -3
|
@@ -0,0 +1,36 @@
|
|
|
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_LENGTH = 60;
|
|
17
|
+
function quote(value) {
|
|
18
|
+
const text = String(value).replace(/\s+/g, ' ').trim();
|
|
19
|
+
return text.length > MAX_LENGTH ? `“${text.slice(0, MAX_LENGTH)}…”` : `“${text}”`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The one line under a running tool call: the values it was called with, such as
|
|
23
|
+
* `“payroll” · ACME` for a search. Only the input's top-level strings and numbers are read; a call
|
|
24
|
+
* with none says it is running.
|
|
25
|
+
*
|
|
26
|
+
* @param {Object} params
|
|
27
|
+
* @param {*} params.input The tool's input, which may still be streaming in.
|
|
28
|
+
* @param {Function} params.translate
|
|
29
|
+
* @returns {string}
|
|
30
|
+
*/ function summarizeToolInput({ input, translate }) {
|
|
31
|
+
if (!type.isObject(input)) return translate('agent.toolResult.running');
|
|
32
|
+
const values = Object.values(input).filter((value)=>type.isString(value) && value.trim() !== '' || type.isNumber(value));
|
|
33
|
+
if (values.length === 0) return translate('agent.toolResult.running');
|
|
34
|
+
return values.slice(0, 2).map(quote).join(' · ');
|
|
35
|
+
}
|
|
36
|
+
export default summarizeToolInput;
|
|
@@ -0,0 +1,49 @@
|
|
|
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_LENGTH = 80;
|
|
17
|
+
/**
|
|
18
|
+
* The one line under a finished tool call, as the web block's summary: how many results, which
|
|
19
|
+
* fields, or the start of a text answer.
|
|
20
|
+
*
|
|
21
|
+
* @param {Object} params
|
|
22
|
+
* @param {*} params.output The tool's output.
|
|
23
|
+
* @param {Function} params.translate
|
|
24
|
+
* @returns {string}
|
|
25
|
+
*/ function summarizeToolOutput({ output, translate }) {
|
|
26
|
+
if (type.isNone(output)) return translate('agent.toolResult.completedNoData');
|
|
27
|
+
if (type.isArray(output)) {
|
|
28
|
+
return translate('agent.toolResult.returnedCount', {
|
|
29
|
+
count: output.length
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (type.isObject(output)) {
|
|
33
|
+
const keys = Object.keys(output);
|
|
34
|
+
if (keys.length <= 3) {
|
|
35
|
+
return translate('agent.toolResult.returnedKeys', {
|
|
36
|
+
keys: keys.join(', ')
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
return translate('agent.toolResult.returnedFields', {
|
|
40
|
+
count: keys.length
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
if (type.isString(output)) {
|
|
44
|
+
const line = output.replace(/\s+/g, ' ').trim();
|
|
45
|
+
return line.length > MAX_LENGTH ? `${line.slice(0, MAX_LENGTH)}…` : line;
|
|
46
|
+
}
|
|
47
|
+
return String(output);
|
|
48
|
+
}
|
|
49
|
+
export default summarizeToolOutput;
|
|
@@ -0,0 +1,218 @@
|
|
|
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
|
+
*/ // The web AgentChat's (blocks-antd-x), copied rather than imported, so a shell never installs a
|
|
16
|
+
// web block package.
|
|
17
|
+
import { useRef, useEffect } from 'react';
|
|
18
|
+
// Collect the event-dedup ids present in a set of messages. Used to seed the
|
|
19
|
+
// suppression sets when messages are loaded externally (restored history):
|
|
20
|
+
// restored messages must not replay onToolCall / onToolResult / onUserMessage /
|
|
21
|
+
// onTitleGenerated side effects.
|
|
22
|
+
function collectExternalEventIds(msgs) {
|
|
23
|
+
const ids = {
|
|
24
|
+
toolCallIds: new Set(),
|
|
25
|
+
toolResultIds: new Set(),
|
|
26
|
+
userMessageIds: new Set(),
|
|
27
|
+
titleKeys: new Set()
|
|
28
|
+
};
|
|
29
|
+
for (const message of msgs ?? []){
|
|
30
|
+
if (message.role === 'user') {
|
|
31
|
+
if (message.id) ids.userMessageIds.add(message.id);
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
if (message.role !== 'assistant') continue;
|
|
35
|
+
for (const part of message.parts ?? []){
|
|
36
|
+
if ((part.type?.startsWith?.('tool-') || part.type === 'dynamic-tool') && part.toolCallId) {
|
|
37
|
+
ids.toolCallIds.add(part.toolCallId);
|
|
38
|
+
if (part.state === 'output-available' || part.state === 'output-error') {
|
|
39
|
+
ids.toolResultIds.add(part.toolCallId);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (part.type === 'data-chat-title' && part.data?.title) {
|
|
43
|
+
ids.titleKeys.add(`${message.id}-${part.data.title}`);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return ids;
|
|
48
|
+
}
|
|
49
|
+
function useAgentEvents({ messages, status, methods, finishMetaRef, conversationId, externalIdsRef }) {
|
|
50
|
+
const prevStatusRef = useRef(status);
|
|
51
|
+
const firedToolCallIds = useRef(new Set());
|
|
52
|
+
const firedToolResultIds = useRef(new Set());
|
|
53
|
+
const firedUserMessageIds = useRef(new Set());
|
|
54
|
+
const firedTitleIds = useRef(new Set());
|
|
55
|
+
const firedConversationStartRef = useRef(false);
|
|
56
|
+
const lastMessageCountRef = useRef(0);
|
|
57
|
+
// Fire onMessageComplete when streaming finishes
|
|
58
|
+
useEffect(()=>{
|
|
59
|
+
if (prevStatusRef.current === 'streaming' && (status === 'ready' || status === 'idle')) {
|
|
60
|
+
const lastAssistantMessage = [
|
|
61
|
+
...messages
|
|
62
|
+
].reverse().find((m)=>m.role === 'assistant');
|
|
63
|
+
if (lastAssistantMessage) {
|
|
64
|
+
const textContent = lastAssistantMessage.parts?.filter((p)=>p.type === 'text').map((p)=>p.text).join('');
|
|
65
|
+
const finishMeta = finishMetaRef?.current ?? {};
|
|
66
|
+
methods.triggerEvent({
|
|
67
|
+
name: 'onMessageComplete',
|
|
68
|
+
event: {
|
|
69
|
+
role: lastAssistantMessage.role,
|
|
70
|
+
content: textContent,
|
|
71
|
+
messageId: lastAssistantMessage.id,
|
|
72
|
+
parts: lastAssistantMessage.parts,
|
|
73
|
+
finishReason: finishMeta.finishReason,
|
|
74
|
+
isAbort: finishMeta.isAbort ?? false,
|
|
75
|
+
isDisconnect: finishMeta.isDisconnect ?? false,
|
|
76
|
+
messages: messages.map((m)=>({
|
|
77
|
+
id: m.id,
|
|
78
|
+
role: m.role,
|
|
79
|
+
parts: m.parts
|
|
80
|
+
}))
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
finishMetaRef.current = null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
prevStatusRef.current = status;
|
|
87
|
+
}, [
|
|
88
|
+
status,
|
|
89
|
+
messages,
|
|
90
|
+
methods
|
|
91
|
+
]);
|
|
92
|
+
// Fire onUserMessage when a new user message appears
|
|
93
|
+
useEffect(()=>{
|
|
94
|
+
const lastMessage = messages[messages.length - 1];
|
|
95
|
+
if (lastMessage && lastMessage.role === 'user' && !firedUserMessageIds.current.has(lastMessage.id)) {
|
|
96
|
+
firedUserMessageIds.current.add(lastMessage.id);
|
|
97
|
+
// Externally loaded (restored) messages are history, not new input.
|
|
98
|
+
if (externalIdsRef?.current?.userMessageIds?.has(lastMessage.id)) return;
|
|
99
|
+
// Announce the conversation once, on its first user message, with the
|
|
100
|
+
// effective (possibly auto-minted) conversationId so apps can persist or
|
|
101
|
+
// track with a guaranteed id.
|
|
102
|
+
if (!firedConversationStartRef.current) {
|
|
103
|
+
firedConversationStartRef.current = true;
|
|
104
|
+
methods.triggerEvent({
|
|
105
|
+
name: 'onConversationStart',
|
|
106
|
+
event: {
|
|
107
|
+
conversationId
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
const textContent = lastMessage.parts?.filter((p)=>p.type === 'text').map((p)=>p.text).join('');
|
|
112
|
+
methods.triggerEvent({
|
|
113
|
+
name: 'onUserMessage',
|
|
114
|
+
event: {
|
|
115
|
+
role: 'user',
|
|
116
|
+
messageId: lastMessage.id,
|
|
117
|
+
content: textContent,
|
|
118
|
+
parts: lastMessage.parts,
|
|
119
|
+
messages: messages.map((m)=>({
|
|
120
|
+
id: m.id,
|
|
121
|
+
role: m.role,
|
|
122
|
+
parts: m.parts
|
|
123
|
+
}))
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}, [
|
|
128
|
+
messages,
|
|
129
|
+
methods,
|
|
130
|
+
conversationId
|
|
131
|
+
]);
|
|
132
|
+
// Scan for new tool calls and results
|
|
133
|
+
useEffect(()=>{
|
|
134
|
+
for (const message of messages){
|
|
135
|
+
if (message.role !== 'assistant') continue;
|
|
136
|
+
for (const part of message.parts ?? []){
|
|
137
|
+
if (part.type?.startsWith?.('tool-') || part.type === 'dynamic-tool') {
|
|
138
|
+
const toolCallId = part.toolCallId;
|
|
139
|
+
if (!toolCallId) continue;
|
|
140
|
+
// The input JSON streams incrementally — fire onToolCall only once
|
|
141
|
+
// the input is complete, or the event carries a truncated input.
|
|
142
|
+
if (part.state === 'input-streaming') continue;
|
|
143
|
+
const toolName = part.toolName ?? part.type?.replace('tool-', '');
|
|
144
|
+
if (!firedToolCallIds.current.has(toolCallId)) {
|
|
145
|
+
firedToolCallIds.current.add(toolCallId);
|
|
146
|
+
if (!externalIdsRef?.current?.toolCallIds?.has(toolCallId)) {
|
|
147
|
+
methods.triggerEvent({
|
|
148
|
+
name: 'onToolCall',
|
|
149
|
+
event: {
|
|
150
|
+
toolName,
|
|
151
|
+
toolCallId,
|
|
152
|
+
input: part.input
|
|
153
|
+
}
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if ((part.state === 'output-available' || part.state === 'output-error') && !firedToolResultIds.current.has(toolCallId)) {
|
|
158
|
+
firedToolResultIds.current.add(toolCallId);
|
|
159
|
+
if (!externalIdsRef?.current?.toolResultIds?.has(toolCallId)) {
|
|
160
|
+
methods.triggerEvent({
|
|
161
|
+
name: 'onToolResult',
|
|
162
|
+
event: {
|
|
163
|
+
toolName,
|
|
164
|
+
toolCallId,
|
|
165
|
+
output: part.output,
|
|
166
|
+
error: part.state === 'output-error'
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}, [
|
|
175
|
+
messages,
|
|
176
|
+
methods
|
|
177
|
+
]);
|
|
178
|
+
// Fire onTitleGenerated when a data-chat-title part appears
|
|
179
|
+
useEffect(()=>{
|
|
180
|
+
for (const message of messages){
|
|
181
|
+
if (message.role !== 'assistant') continue;
|
|
182
|
+
for (const part of message.parts ?? []){
|
|
183
|
+
if (part.type === 'data-chat-title' && part.data?.title) {
|
|
184
|
+
const titleKey = `${message.id}-${part.data.title}`;
|
|
185
|
+
if (!firedTitleIds.current.has(titleKey)) {
|
|
186
|
+
firedTitleIds.current.add(titleKey);
|
|
187
|
+
if (!externalIdsRef?.current?.titleKeys?.has(titleKey)) {
|
|
188
|
+
methods.triggerEvent({
|
|
189
|
+
name: 'onTitleGenerated',
|
|
190
|
+
event: {
|
|
191
|
+
title: part.data.title
|
|
192
|
+
}
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
}, [
|
|
200
|
+
messages,
|
|
201
|
+
methods
|
|
202
|
+
]);
|
|
203
|
+
// Reset tracking when messages are cleared (conversation switch)
|
|
204
|
+
useEffect(()=>{
|
|
205
|
+
if (messages.length < lastMessageCountRef.current) {
|
|
206
|
+
firedToolCallIds.current.clear();
|
|
207
|
+
firedToolResultIds.current.clear();
|
|
208
|
+
firedUserMessageIds.current.clear();
|
|
209
|
+
firedTitleIds.current.clear();
|
|
210
|
+
firedConversationStartRef.current = false;
|
|
211
|
+
}
|
|
212
|
+
lastMessageCountRef.current = messages.length;
|
|
213
|
+
}, [
|
|
214
|
+
messages.length
|
|
215
|
+
]);
|
|
216
|
+
}
|
|
217
|
+
export { collectExternalEventIds };
|
|
218
|
+
export default useAgentEvents;
|
|
@@ -0,0 +1,151 @@
|
|
|
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 { useEffect, useRef, useState } from 'react';
|
|
16
|
+
import insertAtSelection from '../../shared/dictation/insertAtSelection.js';
|
|
17
|
+
import useDictation from '../../shared/dictation/useDictation.js';
|
|
18
|
+
/**
|
|
19
|
+
* Dictation into the chat composer's plain text (useDictation, with no hints). The selection when
|
|
20
|
+
* a session starts is its anchor: words still being heard show there (the host renders
|
|
21
|
+
* PartialSpans with `anchor`) and are not part of the text, and each final result goes in there
|
|
22
|
+
* with insertAtSelection's spacing, moving the anchor after it. Text stays as said: there is no
|
|
23
|
+
* spoken-mention conversion here.
|
|
24
|
+
*
|
|
25
|
+
* `discard` drops everything the session put in and puts the text and cursor back as they were;
|
|
26
|
+
* a prompt chip, `setInput` and New chat call it. `endWithText` ends the session and keeps the
|
|
27
|
+
* text as it is now, for typing and for a send that has its final words.
|
|
28
|
+
*
|
|
29
|
+
* @param {Object} params
|
|
30
|
+
* @param {boolean} params.disabled Hide the mic.
|
|
31
|
+
* @param {(text: string) => void} params.setText The composer's text setter.
|
|
32
|
+
* @param {string} params.text The composer's text.
|
|
33
|
+
*/ function useChatDictation({ disabled, setText, text }) {
|
|
34
|
+
const textRef = useRef(text);
|
|
35
|
+
textRef.current = text;
|
|
36
|
+
// The input's selection, as onSelectionChange last reported it; null until it reports one,
|
|
37
|
+
// which puts the words at the end.
|
|
38
|
+
const selectionRef = useRef(null);
|
|
39
|
+
// The session's anchor, and the text and selection it started with, for discard.
|
|
40
|
+
const sessionRef = useRef(null);
|
|
41
|
+
const [anchor, setAnchor] = useState(null);
|
|
42
|
+
// A selection set after the text changes under the cursor: passed to the input for one frame.
|
|
43
|
+
const [forced, setForced] = useState(undefined);
|
|
44
|
+
useEffect(()=>{
|
|
45
|
+
if (forced === undefined) return undefined;
|
|
46
|
+
const frame = requestAnimationFrame(()=>setForced(undefined));
|
|
47
|
+
return ()=>cancelAnimationFrame(frame);
|
|
48
|
+
}, [
|
|
49
|
+
forced
|
|
50
|
+
]);
|
|
51
|
+
const placeCursor = (selection)=>{
|
|
52
|
+
selectionRef.current = selection;
|
|
53
|
+
setForced(selection);
|
|
54
|
+
};
|
|
55
|
+
const dictation = useDictation({
|
|
56
|
+
disabled,
|
|
57
|
+
onFinal: (words)=>{
|
|
58
|
+
const session = sessionRef.current;
|
|
59
|
+
const placed = insertAtSelection({
|
|
60
|
+
text: textRef.current,
|
|
61
|
+
selection: session?.anchor ?? selectionRef.current,
|
|
62
|
+
insert: words
|
|
63
|
+
});
|
|
64
|
+
const cursor = {
|
|
65
|
+
start: placed.cursor,
|
|
66
|
+
end: placed.cursor
|
|
67
|
+
};
|
|
68
|
+
// Two final results can arrive before the first one renders.
|
|
69
|
+
textRef.current = placed.text;
|
|
70
|
+
setText(placed.text);
|
|
71
|
+
placeCursor(cursor);
|
|
72
|
+
if (session !== null) {
|
|
73
|
+
session.anchor = cursor;
|
|
74
|
+
setAnchor(cursor);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
const listening = dictation.status !== 'idle';
|
|
79
|
+
const forget = ()=>{
|
|
80
|
+
sessionRef.current = null;
|
|
81
|
+
setAnchor(null);
|
|
82
|
+
};
|
|
83
|
+
useEffect(()=>{
|
|
84
|
+
if (listening) return;
|
|
85
|
+
sessionRef.current = null;
|
|
86
|
+
setAnchor(null);
|
|
87
|
+
}, [
|
|
88
|
+
listening
|
|
89
|
+
]);
|
|
90
|
+
const clearWarning = dictation.clearWarning;
|
|
91
|
+
useEffect(()=>{
|
|
92
|
+
if (text === '') clearWarning();
|
|
93
|
+
}, [
|
|
94
|
+
text,
|
|
95
|
+
clearWarning
|
|
96
|
+
]);
|
|
97
|
+
const toggle = ()=>{
|
|
98
|
+
if (listening) {
|
|
99
|
+
dictation.stop();
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
const end = textRef.current.length;
|
|
103
|
+
const selection = selectionRef.current ?? {
|
|
104
|
+
start: end,
|
|
105
|
+
end
|
|
106
|
+
};
|
|
107
|
+
sessionRef.current = {
|
|
108
|
+
anchor: selection,
|
|
109
|
+
startSelection: selection,
|
|
110
|
+
startText: text
|
|
111
|
+
};
|
|
112
|
+
setAnchor(selection);
|
|
113
|
+
dictation.start();
|
|
114
|
+
};
|
|
115
|
+
const discard = ()=>{
|
|
116
|
+
const session = sessionRef.current;
|
|
117
|
+
dictation.cancel();
|
|
118
|
+
if (!listening || session === null) return;
|
|
119
|
+
forget();
|
|
120
|
+
textRef.current = session.startText;
|
|
121
|
+
setText(session.startText);
|
|
122
|
+
placeCursor(session.startSelection);
|
|
123
|
+
};
|
|
124
|
+
const endWithText = ()=>{
|
|
125
|
+
if (!listening) return;
|
|
126
|
+
forget();
|
|
127
|
+
dictation.cancel();
|
|
128
|
+
};
|
|
129
|
+
const onSelectionChange = ({ nativeEvent })=>{
|
|
130
|
+
selectionRef.current = nativeEvent.selection;
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
anchor,
|
|
134
|
+
available: dictation.available,
|
|
135
|
+
clearWarning,
|
|
136
|
+
// The text as of the last final result, which may not have rendered yet.
|
|
137
|
+
currentText: ()=>textRef.current,
|
|
138
|
+
discard,
|
|
139
|
+
endWithText,
|
|
140
|
+
finish: dictation.finish,
|
|
141
|
+
level: dictation.level,
|
|
142
|
+
listening,
|
|
143
|
+
onSelectionChange,
|
|
144
|
+
partial: dictation.partial,
|
|
145
|
+
selection: forced,
|
|
146
|
+
status: dictation.status,
|
|
147
|
+
toggle,
|
|
148
|
+
warning: dictation.warning
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
export default useChatDictation;
|