@refraction-ui/react 0.2.1 → 0.3.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/dist/index.cjs +190 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +192 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React41 from 'react';
|
|
2
|
+
import { forwardRef, useRef, useState, useEffect } from 'react';
|
|
2
3
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
4
|
import * as ReactDOM from 'react-dom';
|
|
4
5
|
import { createPortal } from 'react-dom';
|
|
@@ -106,7 +107,6 @@ __export(index_exports, {
|
|
|
106
107
|
Command: () => Command,
|
|
107
108
|
CommandEmpty: () => CommandEmpty,
|
|
108
109
|
CommandGroup: () => CommandGroup,
|
|
109
|
-
CommandInput: () => CommandInput,
|
|
110
110
|
CommandItem: () => CommandItem,
|
|
111
111
|
CommandList: () => CommandList,
|
|
112
112
|
CommandSeparator: () => CommandSeparator,
|
|
@@ -12300,6 +12300,196 @@ var PaymentButton = React41.forwardRef(
|
|
|
12300
12300
|
);
|
|
12301
12301
|
PaymentButton.displayName = "PaymentButton";
|
|
12302
12302
|
|
|
12303
|
-
|
|
12303
|
+
// ../command-input/dist/index.js
|
|
12304
|
+
var CommandInput2 = class {
|
|
12305
|
+
state = {
|
|
12306
|
+
nodes: [],
|
|
12307
|
+
rawText: "",
|
|
12308
|
+
cursorPosition: 0,
|
|
12309
|
+
activeTrigger: null,
|
|
12310
|
+
activeCommandText: null
|
|
12311
|
+
};
|
|
12312
|
+
options;
|
|
12313
|
+
constructor(options) {
|
|
12314
|
+
this.options = { ...options };
|
|
12315
|
+
}
|
|
12316
|
+
handleInput(text, cursorPosition) {
|
|
12317
|
+
this.state.rawText = text;
|
|
12318
|
+
this.state.cursorPosition = cursorPosition;
|
|
12319
|
+
this.parseInput();
|
|
12320
|
+
this.notifyStateChange();
|
|
12321
|
+
}
|
|
12322
|
+
handleKeyDown(key, event) {
|
|
12323
|
+
if (this.state.activeTrigger) {
|
|
12324
|
+
if (key === "Escape") {
|
|
12325
|
+
if (event) event.preventDefault();
|
|
12326
|
+
this.state.activeTrigger = null;
|
|
12327
|
+
this.state.activeCommandText = null;
|
|
12328
|
+
if (this.options.onCommandCancel) {
|
|
12329
|
+
this.options.onCommandCancel();
|
|
12330
|
+
}
|
|
12331
|
+
this.notifyStateChange();
|
|
12332
|
+
} else if (key === "Enter") {
|
|
12333
|
+
if (event) event.preventDefault();
|
|
12334
|
+
const trigger = this.state.activeTrigger;
|
|
12335
|
+
const text = this.state.activeCommandText || "";
|
|
12336
|
+
this.state.activeTrigger = null;
|
|
12337
|
+
this.state.activeCommandText = null;
|
|
12338
|
+
if (this.options.onCommandCommit) {
|
|
12339
|
+
this.options.onCommandCommit(trigger, text);
|
|
12340
|
+
}
|
|
12341
|
+
this.notifyStateChange();
|
|
12342
|
+
}
|
|
12343
|
+
}
|
|
12344
|
+
}
|
|
12345
|
+
get value() {
|
|
12346
|
+
return this.state.nodes;
|
|
12347
|
+
}
|
|
12348
|
+
getState() {
|
|
12349
|
+
return { ...this.state };
|
|
12350
|
+
}
|
|
12351
|
+
parseInput() {
|
|
12352
|
+
const { rawText, cursorPosition } = this.state;
|
|
12353
|
+
this.state.activeTrigger = null;
|
|
12354
|
+
this.state.activeCommandText = null;
|
|
12355
|
+
for (let i = cursorPosition - 1; i >= 0; i--) {
|
|
12356
|
+
const char = rawText[i];
|
|
12357
|
+
const matchedTrigger = this.options.triggers.find((t) => t.char === char);
|
|
12358
|
+
if (matchedTrigger) {
|
|
12359
|
+
const isStartOfWord = i === 0 || /\\s/.test(rawText[i - 1]);
|
|
12360
|
+
if (isStartOfWord) {
|
|
12361
|
+
const commandText = rawText.slice(i + 1, cursorPosition);
|
|
12362
|
+
if (!/\\s/.test(commandText)) {
|
|
12363
|
+
let isValid = true;
|
|
12364
|
+
if (matchedTrigger.pattern) {
|
|
12365
|
+
isValid = matchedTrigger.pattern.test(commandText);
|
|
12366
|
+
}
|
|
12367
|
+
if (isValid) {
|
|
12368
|
+
this.state.activeTrigger = matchedTrigger;
|
|
12369
|
+
this.state.activeCommandText = commandText;
|
|
12370
|
+
if (this.options.onCommandTriggered) {
|
|
12371
|
+
this.options.onCommandTriggered(matchedTrigger, commandText);
|
|
12372
|
+
}
|
|
12373
|
+
}
|
|
12374
|
+
}
|
|
12375
|
+
}
|
|
12376
|
+
break;
|
|
12377
|
+
}
|
|
12378
|
+
if (/\\s/.test(char)) {
|
|
12379
|
+
break;
|
|
12380
|
+
}
|
|
12381
|
+
}
|
|
12382
|
+
const nodes = [];
|
|
12383
|
+
if (this.options.triggers.length === 0) {
|
|
12384
|
+
nodes.push({ type: "text", text: rawText });
|
|
12385
|
+
this.state.nodes = nodes;
|
|
12386
|
+
return;
|
|
12387
|
+
}
|
|
12388
|
+
const triggerChars = this.options.triggers.map((t) => t.char.replace(/[.*+?^\${}()|[\\]\\\\]/g, "\\\\$&"));
|
|
12389
|
+
const patternStr = `(^|\\\\s)(${triggerChars.join("|")})([^\\\\s]*)`;
|
|
12390
|
+
const regex = new RegExp(patternStr, "g");
|
|
12391
|
+
let currentIndex = 0;
|
|
12392
|
+
let match;
|
|
12393
|
+
while ((match = regex.exec(rawText)) !== null) {
|
|
12394
|
+
const precedingWhitespace = match[1];
|
|
12395
|
+
const triggerChar = match[2];
|
|
12396
|
+
const commandText = match[3];
|
|
12397
|
+
const matchStart = match.index;
|
|
12398
|
+
const triggerStart = matchStart + precedingWhitespace.length;
|
|
12399
|
+
const triggerConfig = this.options.triggers.find((t) => t.char === triggerChar);
|
|
12400
|
+
let isValid = true;
|
|
12401
|
+
if (triggerConfig?.pattern && commandText.length > 0) {
|
|
12402
|
+
isValid = triggerConfig.pattern.test(commandText);
|
|
12403
|
+
}
|
|
12404
|
+
if (isValid) {
|
|
12405
|
+
if (triggerStart > currentIndex) {
|
|
12406
|
+
nodes.push({ type: "text", text: rawText.slice(currentIndex, triggerStart) });
|
|
12407
|
+
}
|
|
12408
|
+
nodes.push({ type: "command", trigger: triggerChar, text: commandText });
|
|
12409
|
+
currentIndex = regex.lastIndex;
|
|
12410
|
+
}
|
|
12411
|
+
}
|
|
12412
|
+
if (currentIndex < rawText.length) {
|
|
12413
|
+
nodes.push({ type: "text", text: rawText.slice(currentIndex) });
|
|
12414
|
+
}
|
|
12415
|
+
this.state.nodes = nodes;
|
|
12416
|
+
}
|
|
12417
|
+
notifyStateChange() {
|
|
12418
|
+
if (this.options.onStateChange) {
|
|
12419
|
+
this.options.onStateChange({ ...this.state });
|
|
12420
|
+
}
|
|
12421
|
+
}
|
|
12422
|
+
};
|
|
12423
|
+
var CommandInput3 = forwardRef(
|
|
12424
|
+
({
|
|
12425
|
+
value = "",
|
|
12426
|
+
onChange,
|
|
12427
|
+
triggers = [],
|
|
12428
|
+
renderPopover,
|
|
12429
|
+
className,
|
|
12430
|
+
...props
|
|
12431
|
+
}, ref) => {
|
|
12432
|
+
const localRef = useRef(null);
|
|
12433
|
+
const containerRef = ref || localRef;
|
|
12434
|
+
const [popoverState, setPopoverState] = useState({
|
|
12435
|
+
isOpen: false,
|
|
12436
|
+
trigger: "",
|
|
12437
|
+
search: "",
|
|
12438
|
+
position: { top: 0, left: 0 }
|
|
12439
|
+
});
|
|
12440
|
+
const coreRef = useRef(null);
|
|
12441
|
+
useEffect(() => {
|
|
12442
|
+
if (containerRef.current && !coreRef.current) {
|
|
12443
|
+
coreRef.current = new CommandInput2({
|
|
12444
|
+
triggers,
|
|
12445
|
+
onCommandTriggered: (trigger, search) => {
|
|
12446
|
+
setPopoverState({
|
|
12447
|
+
isOpen: true,
|
|
12448
|
+
trigger: trigger.char,
|
|
12449
|
+
search,
|
|
12450
|
+
position: { top: 0, left: 0 }
|
|
12451
|
+
});
|
|
12452
|
+
},
|
|
12453
|
+
onCommandCancel: () => {
|
|
12454
|
+
setPopoverState((prev) => ({ ...prev, isOpen: false }));
|
|
12455
|
+
},
|
|
12456
|
+
onStateChange: (state) => {
|
|
12457
|
+
onChange?.(state.rawText);
|
|
12458
|
+
}
|
|
12459
|
+
});
|
|
12460
|
+
}
|
|
12461
|
+
}, [triggers, onChange]);
|
|
12462
|
+
useEffect(() => {
|
|
12463
|
+
if (containerRef.current && containerRef.current.innerHTML !== value && coreRef.current) {
|
|
12464
|
+
containerRef.current.innerHTML = value;
|
|
12465
|
+
}
|
|
12466
|
+
}, [value]);
|
|
12467
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("relative w-full", className), children: [
|
|
12468
|
+
/* @__PURE__ */ jsx(
|
|
12469
|
+
"div",
|
|
12470
|
+
{
|
|
12471
|
+
ref: containerRef,
|
|
12472
|
+
contentEditable: true,
|
|
12473
|
+
suppressContentEditableWarning: true,
|
|
12474
|
+
className: "w-full min-h-[40px] p-2 border border-gray-300 rounded focus:outline-none focus:ring-2 focus:ring-blue-500",
|
|
12475
|
+
onInput: (e) => {
|
|
12476
|
+
coreRef.current?.handleInput(e.currentTarget.textContent || "", 0);
|
|
12477
|
+
},
|
|
12478
|
+
onKeyDown: (e) => {
|
|
12479
|
+
coreRef.current?.handleKeyDown(e.key, e);
|
|
12480
|
+
},
|
|
12481
|
+
...props
|
|
12482
|
+
}
|
|
12483
|
+
),
|
|
12484
|
+
renderPopover && renderPopover({
|
|
12485
|
+
...popoverState,
|
|
12486
|
+
close: () => setPopoverState((prev) => ({ ...prev, isOpen: false }))
|
|
12487
|
+
})
|
|
12488
|
+
] });
|
|
12489
|
+
}
|
|
12490
|
+
);
|
|
12491
|
+
CommandInput3.displayName = "CommandInput";
|
|
12492
|
+
|
|
12493
|
+
export { Accordion, AccordionContent, AccordionItem, AccordionTrigger, AnimatedText, AppShell, AuthGuard, AuthProvider, Avatar, AvatarFallback, AvatarGroup, AvatarImage, Badge, BadgeDisplay, BottomNav, Breadcrumbs, Button, CATEGORY_LABELS, Calendar, CalendarHeader, Callout, Card2 as Card, CardContent, CardDescription, CardFooter, CardGrid, CardHeader, CardTitle, Carousel, CarouselContent, CarouselItem, CarouselTrigger, Checkbox, CodeBlock, CodeEditor, Collapsible, CollapsibleContent, CollapsibleTrigger, Command, CommandEmpty, CommandGroup, CommandItem, CommandList, CommandSeparator, ContentProtection, DataTable, DatePicker, DeviceFrame, Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogTitle, DialogTrigger, DiffViewer, DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSeparator, DropdownMenuTrigger, EMOJI_CATEGORIES, EMOJI_DATA, EmojiPicker, FeedbackButton, FeedbackDialog, FileUpload, Footer, InlineEditor, Input, InputGroup, InputGroupAddon, InputGroupButton, InputGroupText, InstallPrompt, KeyboardShortcut, LanguageSelector, LinkCard, MarkdownRenderer, MobileNav, MobileNavContent, MobileNavLink, MobileNavTrigger, Navbar, OtpInput, STATUS_COLORS as PRESENCE_STATUS_COLORS, STATUS_LABELS as PRESENCE_STATUS_LABELS, Pagination, Payment, Popover, PopoverClose, PopoverContent, PopoverTrigger, PresenceIndicator, ProgressBar, RadioGroup, RadioItem, ReactionBar, ResizableDivider, ResizableLayout, ResizablePane, STATUS_COLORS2 as STATUS_COLORS, STATUS_LABELS2 as STATUS_LABELS, SearchBar, SearchResultItem, SearchResults, Select, SelectContent, SelectItem, SelectTrigger, ShortcutBadge, Sidebar, Skeleton, SkeletonText, SkipToContent, SlideViewer, StatsGrid, StatusIndicator, Steps, Switch, TableOfContents, Tabs, TabsContent, TabsList, TabsTrigger, Textarea, ThemeProvider, ThemeScript, ThemeToggle, ThreadView, Toast, ToastProvider, Toaster, Tooltip, TooltipContent, TooltipTrigger, TypewriterText, VersionSelector, VideoPlayer, animatedTextVariants, avatarFallbackVariants, avatarImageVariants, avatarTokens, avatarVariants, badgeGridVariants, badgeItemVariants, badgeVariants, bottomNavTabVariants, bottomNavVariants, breadcrumbItemVariants, breadcrumbSeparatorStyles, breadcrumbsVariants, buttonTokens, buttonVariants, calendarVariants, canAccessAdmin, canAccessReviewer, cardContentVariants, cardDescriptionVariants, cardFooterVariants, cardHeaderVariants, cardTitleVariants, cardTokens, cardVariants, cellVariants, checkIconPath, checkboxTokens, checkboxVariants, codeEditorTokens, codeEditorVariants, collapsibleContentVariants, commandGroupVariants, commandInputVariants, commandItemVariants, commandVariants, contentProtectionVariants, controlsVariants, createDiffViewer, dayVariants, deviceFrameVariants, dialogContentVariants, diffViewerTokens, diffViewerVariants, editorVariants, emojiPickerContainerStyles, emojiPickerEmojiButtonStyles, emojiPickerGridStyles, feedbackDialogVariants, fileUploadDropZoneVariants, fileUploadFileItemStyles, fileUploadFileListStyles, footerVariants, formatFileSize, formatRelativeTime, formatShortcut, formatTimestamp, getAssignableRoles, getDefaultPortal, getInitials, hasAllRoles, hasAnyRole, hasRole, headerVariants, indeterminateIconPath, inputGroupAddonVariants, inputGroupButtonVariants, inputGroupTokens, inputGroupVariants, inputVariants, installPromptVariants, latestBadgeVariants, markdownRendererTokens, menuContentVariants, menuItemVariants, mobileNavContentVariants, mobileNavLinkVariants, mobileNavTokens, mobileNavTriggerVariants, mobileNavVariants, navLinkVariants, navbarVariants, optionVariants, otpInputContainerVariants, otpInputSlotVariants, otpInputTokens, overlayStyles, overlayVariants, playerVariants, popoverContentVariants, previewVariants, progressBarVariants, proseVariants, radioCircleVariants, radioGroupVariants, radioItemVariants, reactionAddButtonStyles, reactionBarStyles, reactionCountStyles, reactionEmojiStyles, reactionPillVariants, resizableDividerVariants, resizableLayoutTokens, resizableLayoutVariants, resizablePaneVariants, rowVariants, searchBarVariants, searchResultVariants, selectContentVariants, selectItemVariants, selectTokens, selectTriggerVariants, selectorVariants, shortcutBadgeStyles, shortcutKeyStyles, shortcutSeparatorStyles, skeletonVariants, slideTypeBadgeVariants, progressBarVariants2 as slideViewerProgressBarVariants, slideViewerTokens, slideViewerVariants, statCardVariants, statsGridVariants, statusBarVariants, statusContainerStyles, statusDotVariants, statusLabelStyles, statusPulseVariants, switchThumbVariants, switchTokens, switchVariants, tabBarVariants, tabVariants, tableVariants, tabsListVariants, tabsTriggerVariants, textareaVariants, threadAuthorStyles, threadAvatarStyles, threadBodyStyles, threadContainerStyles, threadContentStyles, threadMessageStyles, threadReactionsStyles, threadTimestampStyles, toastVariants, toolbarVariants, tooltipContentVariants, typewriterVariants, useAuth, useTheme, useToast, optionVariants2 as versionSelectorOptionVariants, versionSelectorVariants, watermarkVariants };
|
|
12304
12494
|
//# sourceMappingURL=index.js.map
|
|
12305
12495
|
//# sourceMappingURL=index.js.map
|