@markprompt/react
Advanced tools
Comparing version 0.10.2 to 0.10.3
@@ -5,4 +5,3 @@ export { useMarkprompt, type UseMarkpromptOptions, type UseMarkpromptResult, } from './useMarkprompt.js'; | ||
export { useMarkpromptContext } from './context.js'; | ||
export { getHref } from './utils.js'; | ||
export * from './types.js'; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -5,4 +5,3 @@ export { useMarkprompt, } from './useMarkprompt.js'; | ||
export { useMarkpromptContext } from './context.js'; | ||
export { getHref } from './utils.js'; | ||
export * from './types.js'; | ||
//# sourceMappingURL=index.js.map |
@@ -6,2 +6,3 @@ import * as AccessibleIcon from '@radix-ui/react-accessible-icon'; | ||
import { Answer } from './Answer.js'; | ||
import { DEFAULT_MARKPROMPT_OPTIONS } from './constants.js'; | ||
import { useMarkpromptContext } from './context.js'; | ||
@@ -35,3 +36,3 @@ import { ChatIcon, ChevronLeftIcon, ChevronUpIcon, CommandIcon, CornerDownLeftIcon, SearchIcon, SparklesIcon, } from './icons.js'; | ||
!trigger?.customElement && (React.createElement(React.Fragment, null, trigger?.floating !== false ? (React.createElement(BaseMarkprompt.DialogTrigger, { className: "MarkpromptFloatingTrigger" }, | ||
React.createElement(AccessibleIcon.Root, { label: trigger?.label ?? 'Open Markprompt' }, | ||
React.createElement(AccessibleIcon.Root, { label: trigger?.label ?? DEFAULT_MARKPROMPT_OPTIONS.trigger.label }, | ||
React.createElement(ChatIcon, { className: "MarkpromptChatIcon", width: "24", height: "24" })))) : (React.createElement(SearchBoxTrigger, { trigger: trigger, setOpen: setOpen, open: open })))), | ||
@@ -41,3 +42,3 @@ React.createElement(BaseMarkprompt.Portal, null, | ||
React.createElement(BaseMarkprompt.Content, { className: "MarkpromptContent", showBranding: showBranding }, | ||
React.createElement(BaseMarkprompt.Title, { hide: title?.hide ?? true }, title?.text ?? 'Ask me anything'), | ||
React.createElement(BaseMarkprompt.Title, { hide: title?.hide ?? true }, title?.text ?? DEFAULT_MARKPROMPT_OPTIONS.prompt.label), | ||
description?.text && (React.createElement(BaseMarkprompt.Description, { hide: description?.hide ?? true }, description?.text)), | ||
@@ -48,6 +49,6 @@ React.createElement(BaseMarkprompt.Form, { className: "MarkpromptForm" }, | ||
? 'Search or ask a question…' | ||
: 'Ask me anything…'), labelClassName: "MarkpromptPromptLabel", label: React.createElement(AccessibleIcon.Root, { label: prompt?.label ?? 'Ask me anything…' }, | ||
: DEFAULT_MARKPROMPT_OPTIONS.prompt.label), labelClassName: "MarkpromptPromptLabel", label: React.createElement(AccessibleIcon.Root, { label: prompt?.label ?? DEFAULT_MARKPROMPT_OPTIONS.prompt.label }, | ||
React.createElement(SearchIcon, { className: "MarkpromptSearchIcon" })) }), | ||
React.createElement(BaseMarkprompt.Close, { className: "MarkpromptClose" }, | ||
React.createElement(AccessibleIcon.Root, { label: close?.label ?? 'Close Markprompt' }, | ||
React.createElement(AccessibleIcon.Root, { label: close?.label ?? DEFAULT_MARKPROMPT_OPTIONS.close.label }, | ||
React.createElement("kbd", null, "Esc")))), | ||
@@ -113,3 +114,3 @@ React.createElement(AnswerOrSearchResults, { search: search, references: references, showSearch: showSearch, promptCTA: prompt?.cta, toggleSearchAnswer: toggle }))))); | ||
return (React.createElement(BaseMarkprompt.DialogTrigger, { className: "MarkpromptSearchBoxTrigger" }, | ||
React.createElement(AccessibleIcon.Root, { label: trigger?.label ?? 'Open Markprompt' }, | ||
React.createElement(AccessibleIcon.Root, { label: trigger?.label ?? DEFAULT_MARKPROMPT_OPTIONS.trigger.label }, | ||
React.createElement("span", { className: "MarkpromptSearchBoxTriggerContent" }, | ||
@@ -183,3 +184,3 @@ React.createElement("span", { className: "MarkpromptSearchBoxTriggerText" }, | ||
React.createElement(SparklesIcon, { focusable: false, className: "MarkpromptSearchIcon" })), | ||
React.createElement("span", null, promptCTA || 'Ask Docs AI…'), | ||
React.createElement("span", null, promptCTA || DEFAULT_MARKPROMPT_OPTIONS.prompt.cta), | ||
React.createElement("kbd", null, | ||
@@ -186,0 +187,0 @@ navigator.platform.indexOf('Mac') === 0 || |
@@ -9,5 +9,5 @@ import * as Dialog from '@radix-ui/react-dialog'; | ||
import { ConditionalVisuallyHidden } from '../ConditionalWrap.js'; | ||
import { DEFAULT_MARKPROMPT_OPTIONS } from '../constants.js'; | ||
import { MarkpromptContext, useMarkpromptContext } from '../context.js'; | ||
import { useMarkprompt } from '../useMarkprompt.js'; | ||
import { getHref as getDefaultHref } from '../utils.js'; | ||
/** | ||
@@ -135,3 +135,3 @@ * The Markprompt context provider and dialog root. | ||
const Prompt = forwardRef(function Prompt(props, ref) { | ||
const { autoCapitalize = 'none', autoComplete = 'off', autoCorrect = 'off', autoFocus = true, label, labelClassName, onChange, placeholder = 'Ask me anything…', spellCheck = false, type = 'search', ...rest } = props; | ||
const { autoCapitalize = 'none', autoComplete = 'off', autoCorrect = 'off', autoFocus = true, label, labelClassName, onChange, placeholder = DEFAULT_MARKPROMPT_OPTIONS.prompt.placeholder, spellCheck = false, type = 'search', ...rest } = props; | ||
const { activeSearchResult, isSearchActive, prompt, searchResults, submitSearchQuery, updateActiveSearchResult, updatePrompt, } = useMarkpromptContext(); | ||
@@ -276,3 +276,5 @@ const debouncedSubmitSearchQuery = useMemo(() => debounce(submitSearchQuery, 220), [submitSearchQuery]); | ||
const SearchResult = forwardRef((props, ref) => { | ||
const { title, path, score, sectionHeading, source, getHref = (path, sectionHeading) => getDefaultHref(path, sectionHeading), ...rest } = props; | ||
const { title, path, score, sectionHeading, source, getHref = (path, sectionHeading) => { | ||
return (DEFAULT_MARKPROMPT_OPTIONS.search.getResultHref?.(path, sectionHeading) || path); | ||
}, ...rest } = props; | ||
return (React.createElement("li", { ref: ref, ...rest }, | ||
@@ -279,0 +281,0 @@ React.createElement("a", { href: getHref(path, sectionHeading, source), "data-markprompt-score": score }, title))); |
import { animated, useSpring } from '@react-spring/web'; | ||
import React, { useCallback, useMemo } from 'react'; | ||
import { DEFAULT_MARKPROMPT_OPTIONS } from './constants.js'; | ||
import { useMarkpromptContext } from './index.js'; | ||
import * as Markprompt from './index.js'; | ||
import { useElementSize } from './useElementSize.js'; | ||
const capitalize = (text) => { | ||
return text.charAt(0).toUpperCase() + text.slice(1); | ||
}; | ||
const removeFileExtension = (fileName) => { | ||
const lastDotIndex = fileName.lastIndexOf('.'); | ||
if (lastDotIndex === -1) { | ||
return fileName; | ||
} | ||
return fileName.substring(0, lastDotIndex); | ||
}; | ||
const defaultTransformReferenceId = (referenceId) => ({ | ||
href: removeFileExtension(referenceId), | ||
text: capitalize(removeFileExtension(referenceId.split('/').slice(-1)[0])), | ||
}); | ||
const Reference = (props) => { | ||
const { transformReferenceId = defaultTransformReferenceId, index, referenceId, } = props; | ||
const { transformReferenceId = DEFAULT_MARKPROMPT_OPTIONS.references | ||
.transformReferenceId, index, referenceId, } = props; | ||
const reference = useMemo(() => transformReferenceId(referenceId), [referenceId, transformReferenceId]); | ||
@@ -29,3 +17,3 @@ return (React.createElement("li", { key: referenceId, className: "MarkpromptReference", style: { | ||
const References = (props) => { | ||
const { loadingText = 'Fetching relevant pages…', referencesText = 'Answer generated from the following sources:', transformReferenceId, } = props; | ||
const { loadingText = DEFAULT_MARKPROMPT_OPTIONS.references.loadingText, referencesText = DEFAULT_MARKPROMPT_OPTIONS.references.referencesText, transformReferenceId, } = props; | ||
const { state, references } = useMarkpromptContext(); | ||
@@ -32,0 +20,0 @@ const [ref, { height }] = useElementSize(); |
import { clsx } from 'clsx'; | ||
import React, { Fragment, forwardRef, memo } from 'react'; | ||
import { DEFAULT_MARKPROMPT_OPTIONS } from './constants.js'; | ||
import { FileTextIcon, HashIcon } from './icons.js'; | ||
import { useMarkpromptContext, getHref as getDefaultHref, } from './index.js'; | ||
import { useMarkpromptContext } from './index.js'; | ||
// Source: https://github.com/shuding/nextra/blob/main/packages/nextra-theme-docs/src/components/highlight-matches.tsx | ||
@@ -35,3 +36,4 @@ const HighlightMatches = memo(function HighlightMatches({ value, match, }) { | ||
React.createElement("a", { href: getHref?.(path, sectionHeading, source) || | ||
getDefaultHref(path, sectionHeading), className: "MarkpromptSearchResultLink", onMouseOver: onMouseOver }, | ||
DEFAULT_MARKPROMPT_OPTIONS.search.getResultHref?.(path, sectionHeading, source) || | ||
'', className: "MarkpromptSearchResultLink", onMouseOver: onMouseOver }, | ||
React.createElement("div", { className: "MarkpromptSearchResultContainer" }, | ||
@@ -38,0 +40,0 @@ React.createElement("div", { className: "MarkpromptSearchResultIconWrapper MarkpromptSearchResultIconWrapperBordered" }, !isParent ? (React.createElement(HashIcon, { className: "MarkpromptSearchResultIcon" })) : (React.createElement(FileTextIcon, { className: "MarkpromptSearchResultIcon" }))), |
@@ -89,3 +89,3 @@ import { type Source, type SubmitPromptOptions, type SubmitSearchQueryOptions } from '@markprompt/core'; | ||
/** Callback to transform a search result into an href */ | ||
getResultHref?: (path: string, sectionHeading: SectionHeading | undefined, source: Source) => string; | ||
getResultHref?: (path: string, sectionHeading: SectionHeading | undefined, source?: Source | undefined) => string; | ||
}; | ||
@@ -92,0 +92,0 @@ trigger?: { |
{ | ||
"name": "@markprompt/react", | ||
"version": "0.10.2", | ||
"version": "0.10.3", | ||
"description": "A headless React component for adding GPT-4 powered search using the Markprompt API.", | ||
@@ -24,3 +24,3 @@ "repository": { | ||
"dependencies": { | ||
"@markprompt/core": "^0.6.0", | ||
"@markprompt/core": "^0.6.1", | ||
"@radix-ui/react-accessible-icon": "^1.0.3", | ||
@@ -27,0 +27,0 @@ "@radix-ui/react-dialog": "^1.0.4", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
184477
1656
Updated@markprompt/core@^0.6.1