@algenium/blocks 1.14.1 → 1.15.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 CHANGED
@@ -17,6 +17,7 @@ var ScrollAreaPrimitive = require('@radix-ui/react-scroll-area');
17
17
  var TooltipPrimitive = require('@radix-ui/react-tooltip');
18
18
  var dateFns = require('date-fns');
19
19
  var reactDayPicker = require('react-day-picker');
20
+ var cmdk = require('cmdk');
20
21
  var valid = require('card-validator');
21
22
 
22
23
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -3902,7 +3903,7 @@ function LanguageSwitcher({
3902
3903
  const onLanguageChange = propOnLanguageChange ?? context?.setLanguage;
3903
3904
  const sizes = sizeClasses2[size];
3904
3905
  const shapeClass = shapeClasses2[shape];
3905
- const defaultLabels5 = {
3906
+ const defaultLabels6 = {
3906
3907
  language: labels.language ?? "Language"
3907
3908
  };
3908
3909
  if (variant === "mini") {
@@ -3912,7 +3913,7 @@ function LanguageSwitcher({
3912
3913
  {
3913
3914
  variant: "ghost",
3914
3915
  size: "icon",
3915
- "aria-label": defaultLabels5.language,
3916
+ "aria-label": defaultLabels6.language,
3916
3917
  className: cn(sizes.buttonMini, shapeClass, className),
3917
3918
  children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Languages, { className: sizes.iconMini })
3918
3919
  }
@@ -9192,6 +9193,342 @@ function useDebouncedValueStrict(value, delayMs) {
9192
9193
  }, [value, delayMs]);
9193
9194
  return debounced;
9194
9195
  }
9196
+ function Command({
9197
+ className,
9198
+ ...props
9199
+ }) {
9200
+ return /* @__PURE__ */ jsxRuntime.jsx(
9201
+ cmdk.Command,
9202
+ {
9203
+ "data-slot": "command",
9204
+ className: cn(
9205
+ "flex h-full w-full flex-col overflow-hidden rounded-md bg-popover text-popover-foreground",
9206
+ className
9207
+ ),
9208
+ ...props
9209
+ }
9210
+ );
9211
+ }
9212
+ function CommandDialog({
9213
+ title = "Command Palette",
9214
+ description = "Search for a command to run...",
9215
+ children,
9216
+ className,
9217
+ showCloseButton = true,
9218
+ commandProps,
9219
+ ...props
9220
+ }) {
9221
+ return /* @__PURE__ */ jsxRuntime.jsxs(Dialog, { ...props, children: [
9222
+ /* @__PURE__ */ jsxRuntime.jsxs(DialogHeader, { className: "sr-only", children: [
9223
+ /* @__PURE__ */ jsxRuntime.jsx(DialogTitle, { children: title }),
9224
+ /* @__PURE__ */ jsxRuntime.jsx(DialogDescription, { children: description })
9225
+ ] }),
9226
+ /* @__PURE__ */ jsxRuntime.jsx(
9227
+ DialogContent,
9228
+ {
9229
+ className: cn("overflow-hidden p-0", className),
9230
+ showCloseButton,
9231
+ children: /* @__PURE__ */ jsxRuntime.jsx(
9232
+ Command,
9233
+ {
9234
+ className: "**:data-[slot=command-input-wrapper]:h-12 [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground [&_[cmdk-group]]:px-2 [&_[cmdk-group]:not([hidden])_~[cmdk-group]]:pt-0 [&_[cmdk-input-wrapper]_svg]:h-5 [&_[cmdk-input-wrapper]_svg]:w-5 [&_[cmdk-input]]:h-12 [&_[cmdk-item]]:px-2 [&_[cmdk-item]]:py-3 [&_[cmdk-item]_svg]:h-5 [&_[cmdk-item]_svg]:w-5",
9235
+ ...commandProps,
9236
+ children
9237
+ }
9238
+ )
9239
+ }
9240
+ )
9241
+ ] });
9242
+ }
9243
+ function CommandInput({
9244
+ className,
9245
+ ...props
9246
+ }) {
9247
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9248
+ "div",
9249
+ {
9250
+ "data-slot": "command-input-wrapper",
9251
+ className: "flex h-9 items-center gap-2 border-b px-3",
9252
+ children: [
9253
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.SearchIcon, { className: "size-4 shrink-0 opacity-50" }),
9254
+ /* @__PURE__ */ jsxRuntime.jsx(
9255
+ cmdk.Command.Input,
9256
+ {
9257
+ "data-slot": "command-input",
9258
+ className: cn(
9259
+ "flex h-10 w-full rounded-md bg-transparent py-3 text-sm outline-hidden placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50",
9260
+ className
9261
+ ),
9262
+ ...props
9263
+ }
9264
+ )
9265
+ ]
9266
+ }
9267
+ );
9268
+ }
9269
+ function CommandList({
9270
+ className,
9271
+ ...props
9272
+ }) {
9273
+ return /* @__PURE__ */ jsxRuntime.jsx(
9274
+ cmdk.Command.List,
9275
+ {
9276
+ "data-slot": "command-list",
9277
+ className: cn(
9278
+ "max-h-[300px] scroll-py-1 overflow-x-hidden overflow-y-auto",
9279
+ className
9280
+ ),
9281
+ ...props
9282
+ }
9283
+ );
9284
+ }
9285
+ function CommandEmpty({
9286
+ ...props
9287
+ }) {
9288
+ return /* @__PURE__ */ jsxRuntime.jsx(
9289
+ cmdk.Command.Empty,
9290
+ {
9291
+ "data-slot": "command-empty",
9292
+ className: "py-6 text-center text-sm",
9293
+ ...props
9294
+ }
9295
+ );
9296
+ }
9297
+ function CommandGroup({
9298
+ className,
9299
+ ...props
9300
+ }) {
9301
+ return /* @__PURE__ */ jsxRuntime.jsx(
9302
+ cmdk.Command.Group,
9303
+ {
9304
+ "data-slot": "command-group",
9305
+ className: cn(
9306
+ "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
9307
+ className
9308
+ ),
9309
+ ...props
9310
+ }
9311
+ );
9312
+ }
9313
+ function CommandSeparator({
9314
+ className,
9315
+ ...props
9316
+ }) {
9317
+ return /* @__PURE__ */ jsxRuntime.jsx(
9318
+ cmdk.Command.Separator,
9319
+ {
9320
+ "data-slot": "command-separator",
9321
+ className: cn("-mx-1 h-px bg-border", className),
9322
+ ...props
9323
+ }
9324
+ );
9325
+ }
9326
+ function CommandItem({
9327
+ className,
9328
+ ...props
9329
+ }) {
9330
+ return /* @__PURE__ */ jsxRuntime.jsx(
9331
+ cmdk.Command.Item,
9332
+ {
9333
+ "data-slot": "command-item",
9334
+ className: cn(
9335
+ "relative flex cursor-default items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden select-none data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50 data-[selected=true]:bg-accent data-[selected=true]:text-accent-foreground [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4 [&_svg:not([class*='text-'])]:text-muted-foreground",
9336
+ className
9337
+ ),
9338
+ ...props
9339
+ }
9340
+ );
9341
+ }
9342
+ function CommandShortcut({
9343
+ className,
9344
+ ...props
9345
+ }) {
9346
+ return /* @__PURE__ */ jsxRuntime.jsx(
9347
+ "span",
9348
+ {
9349
+ "data-slot": "command-shortcut",
9350
+ className: cn(
9351
+ "ml-auto text-xs tracking-widest text-muted-foreground",
9352
+ className
9353
+ ),
9354
+ ...props
9355
+ }
9356
+ );
9357
+ }
9358
+
9359
+ // src/components/search/fuzzy.ts
9360
+ function normalize(value) {
9361
+ return value.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g, "");
9362
+ }
9363
+ function fuzzyMatch(query, target) {
9364
+ const q = normalize(query.trim());
9365
+ if (!q) return true;
9366
+ const t = normalize(target);
9367
+ if (t.includes(q)) return true;
9368
+ let qi = 0;
9369
+ for (let ti = 0; ti < t.length && qi < q.length; ti++) {
9370
+ if (t[ti] === q[qi]) qi++;
9371
+ }
9372
+ return qi === q.length;
9373
+ }
9374
+ var defaultLabels5 = {
9375
+ placeholder: "Buscar en toda la plataforma\u2026",
9376
+ dialogTitle: "Buscar",
9377
+ dialogDescription: "Busca funcionalidades, eventos, documentos y m\xE1s",
9378
+ loading: "Buscando\u2026",
9379
+ empty: "No se encontraron resultados",
9380
+ error: "No se pudo completar la b\xFAsqueda",
9381
+ featuresGroup: "Funcionalidades",
9382
+ defaultResultsGroup: "Resultados"
9383
+ };
9384
+ function groupHitsByType(hits) {
9385
+ const order = [];
9386
+ const byType = /* @__PURE__ */ new Map();
9387
+ for (const hit of hits) {
9388
+ if (!byType.has(hit.type)) {
9389
+ byType.set(hit.type, []);
9390
+ order.push(hit.type);
9391
+ }
9392
+ byType.get(hit.type)?.push(hit);
9393
+ }
9394
+ return order.map((type) => [type, byType.get(type) ?? []]);
9395
+ }
9396
+ function SearchCommand({
9397
+ open,
9398
+ onOpenChange,
9399
+ fetchResults,
9400
+ onSelect,
9401
+ features = [],
9402
+ typeLabels,
9403
+ labels: userLabels,
9404
+ minQueryLength = 2,
9405
+ debounceMs = 200,
9406
+ className
9407
+ }) {
9408
+ const labels = { ...defaultLabels5, ...userLabels };
9409
+ const [query, setQuery] = React7.useState("");
9410
+ const [hits, setHits] = React7.useState([]);
9411
+ const [isLoading, setIsLoading] = React7.useState(false);
9412
+ const [hasError, setHasError] = React7.useState(false);
9413
+ const debouncedQuery = useDebouncedValue(query, debounceMs);
9414
+ const requestIdRef = React7.useRef(0);
9415
+ React7.useEffect(() => {
9416
+ if (!open) {
9417
+ setQuery("");
9418
+ setHits([]);
9419
+ setHasError(false);
9420
+ }
9421
+ }, [open]);
9422
+ React7.useEffect(() => {
9423
+ const trimmed = debouncedQuery.trim();
9424
+ if (trimmed.length < minQueryLength) {
9425
+ setHits([]);
9426
+ setHasError(false);
9427
+ setIsLoading(false);
9428
+ return;
9429
+ }
9430
+ const requestId = ++requestIdRef.current;
9431
+ setIsLoading(true);
9432
+ setHasError(false);
9433
+ fetchResults(trimmed).then((result) => {
9434
+ if (requestIdRef.current !== requestId) return;
9435
+ setHits(result);
9436
+ }).catch(() => {
9437
+ if (requestIdRef.current !== requestId) return;
9438
+ setHits([]);
9439
+ setHasError(true);
9440
+ }).finally(() => {
9441
+ if (requestIdRef.current !== requestId) return;
9442
+ setIsLoading(false);
9443
+ });
9444
+ }, [debouncedQuery, minQueryLength, fetchResults]);
9445
+ const filteredFeatures = React7.useMemo(() => {
9446
+ if (!query.trim()) return features;
9447
+ return features.filter(
9448
+ (feature) => fuzzyMatch(query, feature.label) || feature.keywords?.some((keyword) => fuzzyMatch(query, keyword))
9449
+ );
9450
+ }, [features, query]);
9451
+ const groupedHits = React7.useMemo(() => groupHitsByType(hits), [hits]);
9452
+ function handleSelect(selection) {
9453
+ onSelect(selection);
9454
+ onOpenChange(false);
9455
+ }
9456
+ const hasAnyResults = filteredFeatures.length > 0 || hits.length > 0;
9457
+ return /* @__PURE__ */ jsxRuntime.jsxs(
9458
+ CommandDialog,
9459
+ {
9460
+ open,
9461
+ onOpenChange,
9462
+ title: labels.dialogTitle,
9463
+ description: labels.dialogDescription,
9464
+ className,
9465
+ commandProps: { shouldFilter: false },
9466
+ children: [
9467
+ /* @__PURE__ */ jsxRuntime.jsx(
9468
+ CommandInput,
9469
+ {
9470
+ placeholder: labels.placeholder,
9471
+ value: query,
9472
+ onValueChange: setQuery
9473
+ }
9474
+ ),
9475
+ /* @__PURE__ */ jsxRuntime.jsxs(CommandList, { children: [
9476
+ isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-6 text-center text-sm text-muted-foreground", children: labels.loading }) : null,
9477
+ hasError && !isLoading ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "py-6 text-center text-sm text-destructive", children: labels.error }) : null,
9478
+ !isLoading && !hasError && !hasAnyResults ? /* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: labels.empty }) : null,
9479
+ filteredFeatures.length > 0 ? /* @__PURE__ */ jsxRuntime.jsx(CommandGroup, { heading: labels.featuresGroup, children: filteredFeatures.map((feature) => /* @__PURE__ */ jsxRuntime.jsxs(
9480
+ CommandItem,
9481
+ {
9482
+ value: feature.id,
9483
+ onSelect: () => handleSelect({ kind: "feature", feature }),
9484
+ children: [
9485
+ feature.icon,
9486
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: feature.label })
9487
+ ]
9488
+ },
9489
+ feature.id
9490
+ )) }) : null,
9491
+ !isLoading && groupedHits.map(([type, typeHits]) => /* @__PURE__ */ jsxRuntime.jsx(
9492
+ CommandGroup,
9493
+ {
9494
+ heading: typeLabels?.[type] ?? labels.defaultResultsGroup,
9495
+ children: typeHits.map((hit) => /* @__PURE__ */ jsxRuntime.jsx(
9496
+ CommandItem,
9497
+ {
9498
+ value: hit.id,
9499
+ onSelect: () => handleSelect({ kind: "hit", hit }),
9500
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex min-w-0 flex-1 flex-col", children: [
9501
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: hit.title }),
9502
+ hit.snippet ? /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate text-xs text-muted-foreground", children: hit.snippet }) : null
9503
+ ] })
9504
+ },
9505
+ hit.id
9506
+ ))
9507
+ },
9508
+ type
9509
+ ))
9510
+ ] })
9511
+ ]
9512
+ }
9513
+ );
9514
+ }
9515
+ function useSearchHotkey(options = {}) {
9516
+ const { defaultOpen = false, disabled = false } = options;
9517
+ const [open, setOpen] = React7.useState(defaultOpen);
9518
+ const toggle = React7.useCallback(() => setOpen((prev) => !prev), []);
9519
+ React7.useEffect(() => {
9520
+ if (disabled) return;
9521
+ function handleKeyDown(event) {
9522
+ if (event.key.toLowerCase() !== "k") return;
9523
+ if (!event.metaKey && !event.ctrlKey) return;
9524
+ event.preventDefault();
9525
+ setOpen((prev) => !prev);
9526
+ }
9527
+ window.addEventListener("keydown", handleKeyDown);
9528
+ return () => window.removeEventListener("keydown", handleKeyDown);
9529
+ }, [disabled]);
9530
+ return { open, setOpen, toggle };
9531
+ }
9195
9532
  function onlyDigits(s, max) {
9196
9533
  return s.replace(/\D/g, "").slice(0, max);
9197
9534
  }
@@ -10145,6 +10482,15 @@ exports.ChatRoomView = ChatRoomView;
10145
10482
  exports.ChatSidebar = ChatSidebar;
10146
10483
  exports.ChatSidebarContext = ChatSidebarContext;
10147
10484
  exports.ChatSidebarProvider = ChatSidebarProvider;
10485
+ exports.Command = Command;
10486
+ exports.CommandDialog = CommandDialog;
10487
+ exports.CommandEmpty = CommandEmpty;
10488
+ exports.CommandGroup = CommandGroup;
10489
+ exports.CommandInput = CommandInput;
10490
+ exports.CommandItem = CommandItem;
10491
+ exports.CommandList = CommandList;
10492
+ exports.CommandSeparator = CommandSeparator;
10493
+ exports.CommandShortcut = CommandShortcut;
10148
10494
  exports.Dialog = Dialog;
10149
10495
  exports.DialogClose = DialogClose;
10150
10496
  exports.DialogContent = DialogContent;
@@ -10207,6 +10553,7 @@ exports.PopoverContent = PopoverContent;
10207
10553
  exports.PopoverTrigger = PopoverTrigger;
10208
10554
  exports.ScrollArea = ScrollArea;
10209
10555
  exports.ScrollBar = ScrollBar;
10556
+ exports.SearchCommand = SearchCommand;
10210
10557
  exports.Slider = Slider;
10211
10558
  exports.ThemeSwitcher = ThemeSwitcher;
10212
10559
  exports.Toggle = Toggle;
@@ -10224,6 +10571,7 @@ exports.createLiveHlsConfig = createLiveHlsConfig;
10224
10571
  exports.createVodHlsConfig = createVodHlsConfig;
10225
10572
  exports.defaultLanguages = defaultLanguages;
10226
10573
  exports.describePlaybackError = describePlaybackError;
10574
+ exports.fuzzyMatch = fuzzyMatch;
10227
10575
  exports.getEnvironmentDotClass = getEnvironmentDotClass;
10228
10576
  exports.getEnvironmentLabel = getEnvironmentLabel;
10229
10577
  exports.isBlocksDataEnvironment = isBlocksDataEnvironment;
@@ -10240,5 +10588,6 @@ exports.useHlsPlayback = useHlsPlayback;
10240
10588
  exports.useLanguageContext = useLanguageContext;
10241
10589
  exports.useNotificationsContext = useNotificationsContext;
10242
10590
  exports.usePlaybackStats = usePlaybackStats;
10591
+ exports.useSearchHotkey = useSearchHotkey;
10243
10592
  //# sourceMappingURL=index.cjs.map
10244
10593
  //# sourceMappingURL=index.cjs.map