@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,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 React, { useCallback } from 'react';
|
|
16
|
+
import MarkdownContent from './MarkdownContent.js';
|
|
17
|
+
import meta from './meta.js';
|
|
18
|
+
// GitHub-flavoured markdown drawn with React Native views in the iOS typography (MarkdownContent).
|
|
19
|
+
// Every pressed link, chips included, runs onLinkPress when the block has it. Without it a web
|
|
20
|
+
// link opens in the in-app browser and any other link (mail, phone) through the system; a chip is
|
|
21
|
+
// not pressable.
|
|
22
|
+
function Markdown({ components, events, methods, properties, styles = {} }) {
|
|
23
|
+
const hasOnLinkPress = Boolean(events.onLinkPress);
|
|
24
|
+
const triggerLinkPress = useCallback((href)=>methods.triggerEvent({
|
|
25
|
+
name: 'onLinkPress',
|
|
26
|
+
event: {
|
|
27
|
+
href
|
|
28
|
+
}
|
|
29
|
+
}), [
|
|
30
|
+
methods
|
|
31
|
+
]);
|
|
32
|
+
return /*#__PURE__*/ React.createElement(MarkdownContent, {
|
|
33
|
+
components: components,
|
|
34
|
+
content: properties.content,
|
|
35
|
+
linkChips: properties.linkChips,
|
|
36
|
+
onLinkPress: hasOnLinkPress ? triggerLinkPress : null,
|
|
37
|
+
skipHtml: properties.skipHtml === true,
|
|
38
|
+
style: styles.element
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
Markdown.meta = meta;
|
|
42
|
+
export default Markdown;
|
|
@@ -0,0 +1,67 @@
|
|
|
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 React from 'react';
|
|
16
|
+
import { ScrollView, Text, View } from 'react-native';
|
|
17
|
+
import getIosTextStyle from '../../typography/getIosTextStyle.js';
|
|
18
|
+
/**
|
|
19
|
+
* A fenced code block as a rounded card in the monospace font, its language (when the fence
|
|
20
|
+
* names one) above the code. Long lines scroll sideways rather than wrap, so code keeps its
|
|
21
|
+
* shape.
|
|
22
|
+
*
|
|
23
|
+
* @param {Object} props
|
|
24
|
+
* @param {string} [props.language]
|
|
25
|
+
* @param {Object} props.palette The Markdown's palette (getMarkdownStyles).
|
|
26
|
+
* @param {Object} [props.style] The card's style: its space below.
|
|
27
|
+
* @param {string} props.text
|
|
28
|
+
* @param {Object} props.textStyle The code's text style.
|
|
29
|
+
*/ function MarkdownCode({ language, palette, style, text, textStyle }) {
|
|
30
|
+
const hasLanguage = typeof language === 'string' && language.trim() !== '';
|
|
31
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
32
|
+
style: [
|
|
33
|
+
{
|
|
34
|
+
backgroundColor: palette.codeBackground,
|
|
35
|
+
borderRadius: 12,
|
|
36
|
+
overflow: 'hidden'
|
|
37
|
+
},
|
|
38
|
+
style
|
|
39
|
+
],
|
|
40
|
+
testID: "markdown-code"
|
|
41
|
+
}, hasLanguage ? /*#__PURE__*/ React.createElement(Text, {
|
|
42
|
+
style: [
|
|
43
|
+
getIosTextStyle({
|
|
44
|
+
color: palette.secondaryLabel,
|
|
45
|
+
textStyle: 'caption1',
|
|
46
|
+
tokens: palette.tokens
|
|
47
|
+
}),
|
|
48
|
+
{
|
|
49
|
+
fontWeight: '500',
|
|
50
|
+
paddingHorizontal: 14,
|
|
51
|
+
paddingTop: 10
|
|
52
|
+
}
|
|
53
|
+
]
|
|
54
|
+
}, language.trim()) : null, /*#__PURE__*/ React.createElement(ScrollView, {
|
|
55
|
+
contentContainerStyle: {
|
|
56
|
+
paddingBottom: 12,
|
|
57
|
+
paddingHorizontal: 14,
|
|
58
|
+
paddingTop: hasLanguage ? 6 : 12
|
|
59
|
+
},
|
|
60
|
+
horizontal: true,
|
|
61
|
+
showsHorizontalScrollIndicator: false
|
|
62
|
+
}, /*#__PURE__*/ React.createElement(View, null, /*#__PURE__*/ React.createElement(Text, {
|
|
63
|
+
selectable: true,
|
|
64
|
+
style: textStyle
|
|
65
|
+
}, text))));
|
|
66
|
+
}
|
|
67
|
+
export default MarkdownCode;
|
|
@@ -0,0 +1,101 @@
|
|
|
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 React, { useCallback, useMemo, useState } from 'react';
|
|
16
|
+
import { Dimensions, Linking, View } from 'react-native';
|
|
17
|
+
import * as WebBrowser from 'expo-web-browser';
|
|
18
|
+
import { useMarkdown } from 'react-native-marked';
|
|
19
|
+
import ChipWidthContext from './ChipWidthContext.js';
|
|
20
|
+
import getMarkdownStyles from './getMarkdownStyles.js';
|
|
21
|
+
import MarkdownRenderer from './MarkdownRenderer.js';
|
|
22
|
+
import MarkdownTokenizer from './MarkdownTokenizer.js';
|
|
23
|
+
import trimOuterSpace from './trimOuterSpace.js';
|
|
24
|
+
import useComponentTokens from '../../useComponentTokens.js';
|
|
25
|
+
const webPattern = /^https?:\/\//i;
|
|
26
|
+
/**
|
|
27
|
+
* GitHub-flavoured markdown drawn with React Native views in the iOS typography and the theme's
|
|
28
|
+
* semantic colours: the Markdown block's renderer, which AgentChat draws its replies with, so the
|
|
29
|
+
* two read the same. useMarkdown gives the elements rather than react-native-marked's FlatList,
|
|
30
|
+
* since the markdown sits in the page's scroll view; the space above the first element and below
|
|
31
|
+
* the last is trimmed (trimOuterSpace).
|
|
32
|
+
*
|
|
33
|
+
* Every pressed link, link chips included, runs `onLinkPress` when the host block gives one.
|
|
34
|
+
* Without it a web link opens in the in-app browser (expo-web-browser, its controls in the tint)
|
|
35
|
+
* and any other link (mail, phone) through the system, and a chip is not pressable.
|
|
36
|
+
*
|
|
37
|
+
* @param {Object} props
|
|
38
|
+
* @param {Object} props.components The host block's components (components.Icon for chip icons).
|
|
39
|
+
* @param {string} props.content
|
|
40
|
+
* @param {Object[]} [props.linkChips] Links drawn as inline chips, by scheme or pattern
|
|
41
|
+
* (schemas/linkChips).
|
|
42
|
+
* @param {((href: string) => void)|null} [props.onLinkPress]
|
|
43
|
+
* @param {boolean} [props.skipHtml] Leave raw html out rather than drawing its source.
|
|
44
|
+
* @param {Object} [props.style]
|
|
45
|
+
*/ function MarkdownContent({ components, content, linkChips, onLinkPress = null, skipHtml = false, style }) {
|
|
46
|
+
const { isDark, tokens } = useComponentTokens();
|
|
47
|
+
const [width, setWidth] = useState(()=>Dimensions.get('window').width - 32);
|
|
48
|
+
const { palette, styles: markdownStyles, theme } = useMemo(()=>getMarkdownStyles({
|
|
49
|
+
isDark,
|
|
50
|
+
tokens
|
|
51
|
+
}), [
|
|
52
|
+
isDark,
|
|
53
|
+
tokens
|
|
54
|
+
]);
|
|
55
|
+
const tokenizer = useMemo(()=>new MarkdownTokenizer(), []);
|
|
56
|
+
const openLink = useCallback((href)=>{
|
|
57
|
+
if (onLinkPress !== null) {
|
|
58
|
+
onLinkPress(href);
|
|
59
|
+
return;
|
|
60
|
+
}
|
|
61
|
+
if (webPattern.test(href)) {
|
|
62
|
+
WebBrowser.openBrowserAsync(href, {
|
|
63
|
+
controlsColor: tokens.colorTint
|
|
64
|
+
});
|
|
65
|
+
return;
|
|
66
|
+
}
|
|
67
|
+
Linking.openURL(href);
|
|
68
|
+
}, [
|
|
69
|
+
onLinkPress,
|
|
70
|
+
tokens.colorTint
|
|
71
|
+
]);
|
|
72
|
+
const renderer = useMemo(()=>new MarkdownRenderer({
|
|
73
|
+
Icon: components.Icon,
|
|
74
|
+
linkChips,
|
|
75
|
+
onChipPress: onLinkPress === null ? null : openLink,
|
|
76
|
+
onLinkPress: openLink,
|
|
77
|
+
palette,
|
|
78
|
+
skipHtml
|
|
79
|
+
}), [
|
|
80
|
+
components.Icon,
|
|
81
|
+
linkChips,
|
|
82
|
+
onLinkPress,
|
|
83
|
+
openLink,
|
|
84
|
+
palette,
|
|
85
|
+
skipHtml
|
|
86
|
+
]);
|
|
87
|
+
const elements = useMarkdown(content ?? '', {
|
|
88
|
+
colorScheme: isDark ? 'dark' : 'light',
|
|
89
|
+
renderer,
|
|
90
|
+
styles: markdownStyles,
|
|
91
|
+
theme,
|
|
92
|
+
tokenizer
|
|
93
|
+
});
|
|
94
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
95
|
+
onLayout: (event)=>setWidth(event.nativeEvent.layout.width),
|
|
96
|
+
style: style
|
|
97
|
+
}, /*#__PURE__*/ React.createElement(ChipWidthContext.Provider, {
|
|
98
|
+
value: width
|
|
99
|
+
}, trimOuterSpace(elements)));
|
|
100
|
+
}
|
|
101
|
+
export default MarkdownContent;
|
|
@@ -0,0 +1,97 @@
|
|
|
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 React, { useContext, useMemo, useState } from 'react';
|
|
16
|
+
import { Text, View } from 'react-native';
|
|
17
|
+
import ChipWidthView from './ChipWidthView.js';
|
|
18
|
+
import getListMarker from './getListMarker.js';
|
|
19
|
+
import { ListDepthContext, ListItemContext } from './MarkdownListContext.js';
|
|
20
|
+
import TaskBox from './TaskBox.js';
|
|
21
|
+
const ITEM_GAP = 6;
|
|
22
|
+
function ListItem({ children, first, marker, markerWidth, palette }) {
|
|
23
|
+
const [task, setTask] = useState(null);
|
|
24
|
+
const item = useMemo(()=>({
|
|
25
|
+
setTask
|
|
26
|
+
}), []);
|
|
27
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
28
|
+
style: {
|
|
29
|
+
flexDirection: 'row',
|
|
30
|
+
marginTop: first ? 0 : ITEM_GAP
|
|
31
|
+
}
|
|
32
|
+
}, /*#__PURE__*/ React.createElement(View, {
|
|
33
|
+
style: {
|
|
34
|
+
alignItems: task === null ? 'flex-end' : 'flex-start',
|
|
35
|
+
width: markerWidth
|
|
36
|
+
}
|
|
37
|
+
}, task === null ? /*#__PURE__*/ React.createElement(Text, {
|
|
38
|
+
style: {
|
|
39
|
+
...palette.text,
|
|
40
|
+
color: palette.secondaryLabel,
|
|
41
|
+
fontVariant: [
|
|
42
|
+
'tabular-nums'
|
|
43
|
+
],
|
|
44
|
+
paddingRight: 8
|
|
45
|
+
}
|
|
46
|
+
}, marker) : /*#__PURE__*/ React.createElement(TaskBox, {
|
|
47
|
+
checked: task.checked,
|
|
48
|
+
palette: palette
|
|
49
|
+
})), /*#__PURE__*/ React.createElement(ChipWidthView, {
|
|
50
|
+
style: {
|
|
51
|
+
flex: 1,
|
|
52
|
+
minWidth: 0
|
|
53
|
+
}
|
|
54
|
+
}, /*#__PURE__*/ React.createElement(ListItemContext.Provider, {
|
|
55
|
+
value: item
|
|
56
|
+
}, children)));
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* A markdown list drawn as iOS lays out text lists: each item's marker in a column of its own, so
|
|
60
|
+
* wrapped lines line up under the text, bullets and numbers by how deep the list sits
|
|
61
|
+
* (getListMarker), and a task item's box in its marker's place. A nested list sits close under
|
|
62
|
+
* its item; a top-level one keeps the block's space below it.
|
|
63
|
+
*
|
|
64
|
+
* @param {Object} props
|
|
65
|
+
* @param {React.ReactNode[]} props.items The items, as the renderer drew them.
|
|
66
|
+
* @param {boolean} props.ordered
|
|
67
|
+
* @param {Object} props.palette The Markdown's palette (getMarkdownStyles).
|
|
68
|
+
* @param {number} [props.start] The first item's number in an ordered list.
|
|
69
|
+
* @param {Object} [props.style] The list's style: its space below.
|
|
70
|
+
*/ function MarkdownList({ items, ordered, palette, start = 1, style }) {
|
|
71
|
+
const depth = useContext(ListDepthContext);
|
|
72
|
+
const markers = items.map((_, index)=>getListMarker({
|
|
73
|
+
depth,
|
|
74
|
+
number: start + index,
|
|
75
|
+
ordered
|
|
76
|
+
}));
|
|
77
|
+
const longest = Math.max(...markers.map((marker)=>marker.length));
|
|
78
|
+
const markerWidth = ordered ? Math.max(24, 9 * longest + 8) : 22;
|
|
79
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
80
|
+
style: depth === 0 ? style : [
|
|
81
|
+
style,
|
|
82
|
+
{
|
|
83
|
+
marginBottom: 0,
|
|
84
|
+
marginTop: ITEM_GAP
|
|
85
|
+
}
|
|
86
|
+
]
|
|
87
|
+
}, /*#__PURE__*/ React.createElement(ListDepthContext.Provider, {
|
|
88
|
+
value: depth + 1
|
|
89
|
+
}, items.map((item, index)=>/*#__PURE__*/ React.createElement(ListItem, {
|
|
90
|
+
first: index === 0,
|
|
91
|
+
key: index,
|
|
92
|
+
marker: markers[index],
|
|
93
|
+
markerWidth: markerWidth,
|
|
94
|
+
palette: palette
|
|
95
|
+
}, item))));
|
|
96
|
+
}
|
|
97
|
+
export default MarkdownList;
|
|
@@ -0,0 +1,22 @@
|
|
|
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 { createContext } from 'react';
|
|
16
|
+
// How deep the list being drawn sits: 0 at the top, 1 in a list item, and so on. A list reads it
|
|
17
|
+
// to pick its markers and gives its items one more.
|
|
18
|
+
const ListDepthContext = /*#__PURE__*/ createContext(0);
|
|
19
|
+
// The list item being drawn, which a task box in its text tells that it is a task, so the item
|
|
20
|
+
// draws the box where its marker goes. Null outside a list.
|
|
21
|
+
const ListItemContext = /*#__PURE__*/ createContext(null);
|
|
22
|
+
export { ListDepthContext, ListItemContext };
|
|
@@ -0,0 +1,223 @@
|
|
|
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 React from 'react';
|
|
16
|
+
import { Pressable, Text, View } from 'react-native';
|
|
17
|
+
import { Renderer } from 'react-native-marked';
|
|
18
|
+
import ChipWidthView from './ChipWidthView.js';
|
|
19
|
+
import getLinkChip from './getLinkChip.js';
|
|
20
|
+
import getNodeText from './getNodeText.js';
|
|
21
|
+
import layoutLinkChips from './layoutLinkChips.js';
|
|
22
|
+
import LinkChip from './LinkChip.js';
|
|
23
|
+
import MarkdownCode from './MarkdownCode.js';
|
|
24
|
+
import MarkdownList from './MarkdownList.js';
|
|
25
|
+
import MarkdownTable from './MarkdownTable.js';
|
|
26
|
+
import restyleText from './restyleText.js';
|
|
27
|
+
import { TASK_DONE, TASK_OPEN } from './MarkdownTokenizer.js';
|
|
28
|
+
import TaskMark from './TaskMark.js';
|
|
29
|
+
const THIN_SPACE = String.fromCharCode(0x2009);
|
|
30
|
+
const QUOTE_PADDING = 12;
|
|
31
|
+
// react-native-marked's renderer, drawn as iOS text: headings marked as headers, lists with a
|
|
32
|
+
// marker column and nesting (MarkdownList), task boxes in place of the marker, fenced code in a
|
|
33
|
+
// rounded card, quotes with a tint bar, tables in a rounded box and links in the tint. A link
|
|
34
|
+
// that matches one of `linkChips` (by scheme or pattern) is a chip (LinkChip), laid out with its
|
|
35
|
+
// line as a word of it (layoutLinkChips). Every link is pressed through onLinkPress; chips only
|
|
36
|
+
// when onChipPress is given. Raw html is drawn as its source text, as the web block escapes it,
|
|
37
|
+
// or dropped with skipHtml.
|
|
38
|
+
let MarkdownRenderer = class MarkdownRenderer extends Renderer {
|
|
39
|
+
heading(text, styles) {
|
|
40
|
+
return /*#__PURE__*/ React.createElement(Text, {
|
|
41
|
+
accessibilityRole: "header",
|
|
42
|
+
key: this.getKey(),
|
|
43
|
+
selectable: this.selectable,
|
|
44
|
+
style: styles
|
|
45
|
+
}, layoutLinkChips(text));
|
|
46
|
+
}
|
|
47
|
+
blockquote(children, styles) {
|
|
48
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
49
|
+
key: this.getKey(),
|
|
50
|
+
style: [
|
|
51
|
+
{
|
|
52
|
+
backgroundColor: this.palette.quoteBackground,
|
|
53
|
+
borderBottomRightRadius: 8,
|
|
54
|
+
borderTopRightRadius: 8,
|
|
55
|
+
flexDirection: 'row'
|
|
56
|
+
},
|
|
57
|
+
styles
|
|
58
|
+
],
|
|
59
|
+
testID: "markdown-quote"
|
|
60
|
+
}, /*#__PURE__*/ React.createElement(View, {
|
|
61
|
+
style: {
|
|
62
|
+
backgroundColor: this.palette.tint,
|
|
63
|
+
borderRadius: 1.5,
|
|
64
|
+
width: 3
|
|
65
|
+
}
|
|
66
|
+
}), /*#__PURE__*/ React.createElement(ChipWidthView, {
|
|
67
|
+
inset: 2 * QUOTE_PADDING,
|
|
68
|
+
style: {
|
|
69
|
+
flex: 1,
|
|
70
|
+
marginBottom: -this.palette.blockSpace,
|
|
71
|
+
minWidth: 0,
|
|
72
|
+
paddingBottom: 10,
|
|
73
|
+
paddingHorizontal: QUOTE_PADDING,
|
|
74
|
+
paddingTop: 10
|
|
75
|
+
}
|
|
76
|
+
}, children));
|
|
77
|
+
}
|
|
78
|
+
code(text, language, containerStyle, textStyle) {
|
|
79
|
+
return /*#__PURE__*/ React.createElement(MarkdownCode, {
|
|
80
|
+
key: this.getKey(),
|
|
81
|
+
language: language,
|
|
82
|
+
palette: this.palette,
|
|
83
|
+
style: containerStyle,
|
|
84
|
+
text: text,
|
|
85
|
+
textStyle: textStyle
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
codespan(text, styles) {
|
|
89
|
+
// Thin spaces either side keep the fill off the code's first and last letters.
|
|
90
|
+
return /*#__PURE__*/ React.createElement(Text, {
|
|
91
|
+
key: this.getKey(),
|
|
92
|
+
selectable: this.selectable,
|
|
93
|
+
style: styles
|
|
94
|
+
}, `${THIN_SPACE}${text}${THIN_SPACE}`);
|
|
95
|
+
}
|
|
96
|
+
hr(styles) {
|
|
97
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
98
|
+
key: this.getKey(),
|
|
99
|
+
style: styles
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
list(ordered, li, listStyle, textStyle, startIndex) {
|
|
103
|
+
return /*#__PURE__*/ React.createElement(MarkdownList, {
|
|
104
|
+
items: li,
|
|
105
|
+
key: this.getKey(),
|
|
106
|
+
ordered: ordered,
|
|
107
|
+
palette: this.palette,
|
|
108
|
+
start: startIndex,
|
|
109
|
+
style: listStyle
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
listItem(children) {
|
|
113
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
114
|
+
key: this.getKey()
|
|
115
|
+
}, children);
|
|
116
|
+
}
|
|
117
|
+
text(text, styles) {
|
|
118
|
+
if (Array.isArray(text)) {
|
|
119
|
+
return super.text(layoutLinkChips(text), styles);
|
|
120
|
+
}
|
|
121
|
+
if (typeof text !== 'string' || text[0] !== TASK_OPEN && text[0] !== TASK_DONE) {
|
|
122
|
+
return super.text(text, styles);
|
|
123
|
+
}
|
|
124
|
+
const mark = /*#__PURE__*/ React.createElement(TaskMark, {
|
|
125
|
+
checked: text[0] === TASK_DONE,
|
|
126
|
+
key: "task"
|
|
127
|
+
});
|
|
128
|
+
if (text.length === 1) {
|
|
129
|
+
return /*#__PURE__*/ React.createElement(React.Fragment, {
|
|
130
|
+
key: this.getKey()
|
|
131
|
+
}, mark);
|
|
132
|
+
}
|
|
133
|
+
return super.text([
|
|
134
|
+
mark,
|
|
135
|
+
text.slice(1)
|
|
136
|
+
], styles);
|
|
137
|
+
}
|
|
138
|
+
link(children, href, styles, title) {
|
|
139
|
+
const chip = getLinkChip({
|
|
140
|
+
href,
|
|
141
|
+
linkChips: this.linkChips,
|
|
142
|
+
text: getNodeText(children)
|
|
143
|
+
});
|
|
144
|
+
if (chip !== null) {
|
|
145
|
+
return /*#__PURE__*/ React.createElement(LinkChip, {
|
|
146
|
+
chip: chip.chip,
|
|
147
|
+
href: href,
|
|
148
|
+
Icon: this.Icon,
|
|
149
|
+
key: this.getKey(),
|
|
150
|
+
linkKey: chip.key,
|
|
151
|
+
onPress: this.onChipPress,
|
|
152
|
+
palette: this.palette,
|
|
153
|
+
title: chip.title
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
return /*#__PURE__*/ React.createElement(Text, {
|
|
157
|
+
accessibilityLabel: title,
|
|
158
|
+
accessibilityRole: "link",
|
|
159
|
+
key: this.getKey(),
|
|
160
|
+
onPress: ()=>this.onLinkPress(href),
|
|
161
|
+
selectable: this.selectable,
|
|
162
|
+
style: styles
|
|
163
|
+
}, children);
|
|
164
|
+
}
|
|
165
|
+
image(uri, alt, style, title) {
|
|
166
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
167
|
+
key: this.getKey(),
|
|
168
|
+
style: {
|
|
169
|
+
borderRadius: 10,
|
|
170
|
+
marginBottom: this.palette.blockSpace,
|
|
171
|
+
overflow: 'hidden'
|
|
172
|
+
}
|
|
173
|
+
}, super.image(uri, alt, style, title));
|
|
174
|
+
}
|
|
175
|
+
linkImage(href, imageUrl, alt, style, title) {
|
|
176
|
+
return /*#__PURE__*/ React.createElement(Pressable, {
|
|
177
|
+
accessibilityRole: "link",
|
|
178
|
+
key: this.getKey(),
|
|
179
|
+
onPress: ()=>this.onLinkPress(href)
|
|
180
|
+
}, this.image(imageUrl, alt, style, title));
|
|
181
|
+
}
|
|
182
|
+
// Each cell's parts flow as one line of text, in the subheadline size; header cells semibold.
|
|
183
|
+
table(header, rows, tableStyle) {
|
|
184
|
+
const cellText = {
|
|
185
|
+
fontSize: 15,
|
|
186
|
+
letterSpacing: -0.24,
|
|
187
|
+
lineHeight: 20
|
|
188
|
+
};
|
|
189
|
+
const toCell = (nodes, style)=>/*#__PURE__*/ React.createElement(Text, {
|
|
190
|
+
selectable: this.selectable,
|
|
191
|
+
style: [
|
|
192
|
+
this.palette.text,
|
|
193
|
+
style
|
|
194
|
+
]
|
|
195
|
+
}, layoutLinkChips(restyleText(nodes, style)));
|
|
196
|
+
return /*#__PURE__*/ React.createElement(MarkdownTable, {
|
|
197
|
+
header: header.map((cell)=>toCell(cell, {
|
|
198
|
+
...cellText,
|
|
199
|
+
fontWeight: '600'
|
|
200
|
+
})),
|
|
201
|
+
key: this.getKey(),
|
|
202
|
+
palette: this.palette,
|
|
203
|
+
rows: rows.map((row)=>row.map((cell)=>toCell(cell, cellText))),
|
|
204
|
+
style: tableStyle
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
html(text, styles) {
|
|
208
|
+
if (this.skipHtml) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return super.html(text, styles);
|
|
212
|
+
}
|
|
213
|
+
constructor({ Icon, linkChips = [], onChipPress, onLinkPress, palette, skipHtml }){
|
|
214
|
+
super();
|
|
215
|
+
this.Icon = Icon;
|
|
216
|
+
this.linkChips = linkChips;
|
|
217
|
+
this.onChipPress = onChipPress;
|
|
218
|
+
this.onLinkPress = onLinkPress;
|
|
219
|
+
this.palette = palette;
|
|
220
|
+
this.skipHtml = skipHtml;
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
export default MarkdownRenderer;
|
|
@@ -0,0 +1,96 @@
|
|
|
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 React, { useRef, useState } from 'react';
|
|
16
|
+
import { ScrollView, StyleSheet, View } from 'react-native';
|
|
17
|
+
const MIN_COLUMN = 64;
|
|
18
|
+
const MAX_COLUMN = 260;
|
|
19
|
+
const CELL_PADDING = {
|
|
20
|
+
paddingHorizontal: 12,
|
|
21
|
+
paddingVertical: 8
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* A GFM table in a rounded box with a tinted, semibold header row and hairlines between rows.
|
|
25
|
+
* Each column is as wide as its widest cell, between 64 and 260 points (a wider cell wraps), so
|
|
26
|
+
* the cells are measured once and the columns then set; a table wider than the screen scrolls
|
|
27
|
+
* sideways. The renderer keys each parse's elements afresh, so changed content mounts a new table
|
|
28
|
+
* and is measured again.
|
|
29
|
+
*
|
|
30
|
+
* @param {Object} props
|
|
31
|
+
* @param {React.ReactNode[][]} props.header The header cells, as the renderer drew them.
|
|
32
|
+
* @param {Object} props.palette The Markdown's palette (getMarkdownStyles).
|
|
33
|
+
* @param {React.ReactNode[][][]} props.rows The body rows' cells.
|
|
34
|
+
* @param {Object} [props.style] The table's style: its space below.
|
|
35
|
+
*/ function MarkdownTable({ header, palette, rows, style }) {
|
|
36
|
+
const columns = header.length;
|
|
37
|
+
const [widths, setWidths] = useState(null);
|
|
38
|
+
const measured = useRef(new Map());
|
|
39
|
+
const cellCount = columns * (rows.length + 1);
|
|
40
|
+
function onCellLayout(cell, column, width) {
|
|
41
|
+
if (widths !== null) return;
|
|
42
|
+
measured.current.set(cell, {
|
|
43
|
+
column,
|
|
44
|
+
width
|
|
45
|
+
});
|
|
46
|
+
if (measured.current.size < cellCount) return;
|
|
47
|
+
const next = Array(columns).fill(MIN_COLUMN);
|
|
48
|
+
measured.current.forEach((entry)=>{
|
|
49
|
+
next[entry.column] = Math.min(MAX_COLUMN, Math.max(next[entry.column], Math.ceil(entry.width)));
|
|
50
|
+
});
|
|
51
|
+
setWidths(next);
|
|
52
|
+
}
|
|
53
|
+
function renderRow(cells, rowIndex) {
|
|
54
|
+
const isHeader = rowIndex === 0;
|
|
55
|
+
return /*#__PURE__*/ React.createElement(View, {
|
|
56
|
+
key: rowIndex,
|
|
57
|
+
style: {
|
|
58
|
+
backgroundColor: isHeader ? palette.tableHeader : 'transparent',
|
|
59
|
+
borderTopColor: palette.separator,
|
|
60
|
+
borderTopWidth: isHeader ? 0 : StyleSheet.hairlineWidth,
|
|
61
|
+
flexDirection: 'row'
|
|
62
|
+
}
|
|
63
|
+
}, cells.map((cell, column)=>/*#__PURE__*/ React.createElement(View, {
|
|
64
|
+
key: column,
|
|
65
|
+
onLayout: (event)=>onCellLayout(`${rowIndex}:${column}`, column, event.nativeEvent.layout.width),
|
|
66
|
+
style: [
|
|
67
|
+
CELL_PADDING,
|
|
68
|
+
widths === null ? null : {
|
|
69
|
+
width: widths[column]
|
|
70
|
+
}
|
|
71
|
+
]
|
|
72
|
+
}, cell)));
|
|
73
|
+
}
|
|
74
|
+
return /*#__PURE__*/ React.createElement(ScrollView, {
|
|
75
|
+
horizontal: true,
|
|
76
|
+
showsHorizontalScrollIndicator: false,
|
|
77
|
+
style: [
|
|
78
|
+
{
|
|
79
|
+
flexGrow: 0
|
|
80
|
+
},
|
|
81
|
+
style
|
|
82
|
+
],
|
|
83
|
+
testID: "markdown-table"
|
|
84
|
+
}, /*#__PURE__*/ React.createElement(View, {
|
|
85
|
+
style: {
|
|
86
|
+
borderColor: palette.separator,
|
|
87
|
+
borderRadius: 10,
|
|
88
|
+
borderWidth: StyleSheet.hairlineWidth,
|
|
89
|
+
overflow: 'hidden'
|
|
90
|
+
}
|
|
91
|
+
}, [
|
|
92
|
+
header,
|
|
93
|
+
...rows
|
|
94
|
+
].map(renderRow)));
|
|
95
|
+
}
|
|
96
|
+
export default MarkdownTable;
|