@scaleflex/ui-tw 0.0.159 → 0.0.161

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.
@@ -3,7 +3,7 @@ import { Dialog } from '@scaleflex/ui-tw/dialog';
3
3
  import { Command as CommandPrimitive } from 'cmdk';
4
4
  import React from 'react';
5
5
  import type { ComponentProps } from 'react';
6
- declare function Command({ className, ...props }: ComponentProps<typeof CommandPrimitive>): React.JSX.Element;
6
+ declare function Command({ className, filter, ...props }: ComponentProps<typeof CommandPrimitive>): React.JSX.Element;
7
7
  declare function CommandDialog({ title, description, children, ...props }: ComponentProps<typeof Dialog> & {
8
8
  title?: string;
9
9
  description?: string;
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  import _extends from "@babel/runtime/helpers/extends";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
4
- var _excluded = ["className"],
4
+ var _excluded = ["className", "filter"],
5
5
  _excluded2 = ["title", "description", "children"],
6
6
  _excluded3 = ["className", "size", "wrapperClassName"],
7
7
  _excluded4 = ["className", "onCleared", "cancelDebounce", "size"],
@@ -30,12 +30,14 @@ import { Command as CommandPrimitive, useCommandState } from 'cmdk';
30
30
  import { CheckIcon, SearchIcon, UserCircle2Icon, XIcon } from 'lucide-react';
31
31
  import React from 'react';
32
32
  import { useCallback } from 'react';
33
- import { selectCommandHeadingOptions } from './command.utils';
33
+ import { commandPrefixFilter, selectCommandHeadingOptions } from './command.utils';
34
34
  function Command(_ref) {
35
35
  var className = _ref.className,
36
+ filter = _ref.filter,
36
37
  props = _objectWithoutProperties(_ref, _excluded);
37
38
  return /*#__PURE__*/React.createElement(CommandPrimitive, _extends({
38
39
  "data-slot": "command",
40
+ filter: filter !== null && filter !== void 0 ? filter : commandPrefixFilter,
39
41
  className: cn('text-popover-foreground relative flex h-full w-full flex-col overflow-hidden', className)
40
42
  }, props));
41
43
  }
@@ -1,3 +1,4 @@
1
+ export declare function commandPrefixFilter(value: string, search: string, keywords?: string[]): number;
1
2
  export declare const selectCommandHeadingOptions: {
2
3
  readonly sm: "[&_[cmdk-group-heading]]:py-2 [&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:min-h-8 [&_[cmdk-group-heading]]:text-xs";
3
4
  readonly md: "[&_[cmdk-group-heading]]:py-3 [&_[cmdk-group-heading]]:px-4 [&_[cmdk-group-heading]]:min-h-10 [&_[cmdk-group-heading]]:text-sm";
@@ -1,3 +1,49 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t["return"] || t["return"](); } finally { if (u) throw o; } } }; }
4
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
5
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
2
6
  import { FormSize } from '@scaleflex/ui-tw/types/form-size';
7
+
8
+ /**
9
+ * Word-prefix filter for cmdk's `Command`.
10
+ *
11
+ * cmdk's default filter (`command-score`) is a fuzzy matcher: it keeps any item
12
+ * whose characters appear in the search order as a subsequence (e.g. typing
13
+ * "ride" also matches "rideaux", "gridded", ...). A plain substring match is
14
+ * still too loose — typing "me" would keep "Recent Documents" via "docuMEnts".
15
+ *
16
+ * Autocomplete should match the *beginning of a word*, so an item is kept when
17
+ * the whole value starts with the search term (ranked highest) or any word
18
+ * within it does (e.g. "ride" -> "rideaux", "doc" -> "Recent Documents").
19
+ */
20
+ var WORD_BOUNDARY = /[\s\-_/.,]+/;
21
+ export function commandPrefixFilter(value, search, keywords) {
22
+ var normalizedSearch = search.trim().toLowerCase();
23
+ if (!normalizedSearch) return 1;
24
+ var haystacks = [value].concat(_toConsumableArray(keywords !== null && keywords !== void 0 ? keywords : [])).map(function (item) {
25
+ return item.toLowerCase();
26
+ });
27
+ var score = 0;
28
+ var _iterator = _createForOfIteratorHelper(haystacks),
29
+ _step;
30
+ try {
31
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
32
+ var haystack = _step.value;
33
+ // Whole value starts with the search term — best match.
34
+ if (haystack.startsWith(normalizedSearch)) return 1;
35
+ // A word within the value starts with the search term.
36
+ if (haystack.split(WORD_BOUNDARY).some(function (word) {
37
+ return word.startsWith(normalizedSearch);
38
+ })) {
39
+ score = 0.5;
40
+ }
41
+ }
42
+ } catch (err) {
43
+ _iterator.e(err);
44
+ } finally {
45
+ _iterator.f();
46
+ }
47
+ return score;
48
+ }
3
49
  export var selectCommandHeadingOptions = _defineProperty(_defineProperty(_defineProperty({}, FormSize.Sm, '[&_[cmdk-group-heading]]:py-2 [&_[cmdk-group-heading]]:px-3 [&_[cmdk-group-heading]]:min-h-8 [&_[cmdk-group-heading]]:text-xs'), FormSize.Md, '[&_[cmdk-group-heading]]:py-3 [&_[cmdk-group-heading]]:px-4 [&_[cmdk-group-heading]]:min-h-10 [&_[cmdk-group-heading]]:text-sm'), FormSize.Lg, '[&_[cmdk-group-heading]]:py-3 [&_[cmdk-group-heading]]:px-4 [&_[cmdk-group-heading]]:min-h-12 [&_[cmdk-group-heading]]:text-base');
@@ -1,6 +1,6 @@
1
1
  import * as DialogPrimitive from '@radix-ui/react-dialog';
2
2
  import React, { type ComponentProps } from 'react';
3
- import type { DialogContentProps, DialogHeaderProps, DialogTitleProps } from './dialog.types';
3
+ import type { DialogContentProps, DialogDescriptionProps, DialogHeaderProps, DialogTitleProps } from './dialog.types';
4
4
  declare function Dialog({ ...props }: ComponentProps<typeof DialogPrimitive.Root>): React.JSX.Element;
5
5
  declare function DialogTrigger({ ...props }: ComponentProps<typeof DialogPrimitive.Trigger>): React.JSX.Element;
6
6
  declare function DialogPortal({ ...props }: ComponentProps<typeof DialogPrimitive.Portal>): React.JSX.Element;
@@ -9,7 +9,7 @@ declare function DialogOverlay({ className, ...props }: ComponentProps<typeof Di
9
9
  declare function DialogContent({ className, children, overlayClassName, variant, headerSize, maxWidth, hideCloseButton, ...props }: DialogContentProps): React.JSX.Element;
10
10
  declare function DialogHeader({ className, size, ...props }: DialogHeaderProps): React.JSX.Element;
11
11
  declare function DialogTitle({ className, size, align, ...props }: DialogTitleProps): React.JSX.Element;
12
- declare function DialogDescription({ className, ...props }: ComponentProps<typeof DialogPrimitive.Description>): React.JSX.Element;
12
+ declare function DialogDescription({ className, visuallyHidden, ...props }: DialogDescriptionProps): React.JSX.Element;
13
13
  declare function DialogBody({ className, ...props }: ComponentProps<'div'>): React.JSX.Element;
14
14
  declare function DialogFooter({ className, ...props }: ComponentProps<'div'>): React.JSX.Element;
15
15
  declare function DialogIcon({ className, ...props }: ComponentProps<'div'>): React.JSX.Element;
@@ -5,13 +5,14 @@ var _excluded = ["className"],
5
5
  _excluded2 = ["className", "children", "overlayClassName", "variant", "headerSize", "maxWidth", "hideCloseButton"],
6
6
  _excluded3 = ["className", "size"],
7
7
  _excluded4 = ["className", "size", "align"],
8
- _excluded5 = ["className"],
8
+ _excluded5 = ["className", "visuallyHidden"],
9
9
  _excluded6 = ["className"],
10
10
  _excluded7 = ["className"],
11
11
  _excluded8 = ["className"],
12
12
  _excluded9 = ["className"],
13
13
  _excluded10 = ["className"];
14
14
  import * as DialogPrimitive from '@radix-ui/react-dialog';
15
+ import { VisuallyHidden } from '@radix-ui/react-visually-hidden';
15
16
  import { Button } from '@scaleflex/ui-tw/button';
16
17
  import { focusRingClassNames } from '@scaleflex/ui-tw/styles/shared-classes';
17
18
  import { cn } from '@scaleflex/ui-tw/utils/cn';
@@ -160,9 +161,22 @@ function DialogTitle(_ref8) {
160
161
  }), className)
161
162
  }, props));
162
163
  }
164
+
165
+ // Radix warns ("Missing `Description`...") when a Dialog has no description in the a11y tree.
166
+ // `visuallyHidden` keeps the description for screen readers (silencing the warning) but hides it visually.
163
167
  function DialogDescription(_ref9) {
164
168
  var className = _ref9.className,
169
+ visuallyHidden = _ref9.visuallyHidden,
165
170
  props = _objectWithoutProperties(_ref9, _excluded5);
171
+ if (visuallyHidden) {
172
+ // `asChild` applies the hidden styles to the Description itself, so it stays the `aria-describedby` target without an extra wrapper.
173
+ return /*#__PURE__*/React.createElement(VisuallyHidden, {
174
+ asChild: true
175
+ }, /*#__PURE__*/React.createElement(DialogPrimitive.Description, _extends({
176
+ "data-slot": "dialog-description",
177
+ className: className
178
+ }, props)));
179
+ }
166
180
  return /*#__PURE__*/React.createElement(DialogPrimitive.Description, _extends({
167
181
  "data-slot": "dialog-description",
168
182
  className: cn('text-muted-foreground text-sm', className)
@@ -20,6 +20,10 @@ export interface DialogTitleProps extends ComponentProps<typeof DialogPrimitive.
20
20
  size?: DialogHeaderSize;
21
21
  align?: DialogTitleAlign;
22
22
  }
23
+ export interface DialogDescriptionProps extends ComponentProps<typeof DialogPrimitive.Description> {
24
+ /** Render the description in the a11y tree but hide it visually. Satisfies Radix's `aria-describedby` requirement without showing description text. */
25
+ visuallyHidden?: boolean;
26
+ }
23
27
  /** @deprecated Use `DialogHeaderSize` instead */
24
28
  export type DialogSize = DialogHeaderSize;
25
29
  /** @deprecated Use `DialogTitleAlign` instead */
package/dialog/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
1
  export { Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogErrorIcon, DialogFooter, DialogHeader, DialogIcon, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DialogWarningIcon, DialogFormBody, DialogFormContent, DialogFormDescription, DialogFormErrorIcon, DialogFormFooter, DialogFormHeader, DialogFormIcon, DialogFormTitle, DialogFormWarningIcon, DialogWideBody, DialogWideContent, DialogWideFooter, DialogWideHeader, DialogWideTitle, } from './dialog.component';
2
2
  export { dialogCloseButtonPositionVariants, dialogContentWidthVariants, dialogHeaderDefaultVariants, dialogTitleDefaultVariants, dialogWideHeaderVariants, dialogWideTitleVariants, } from './dialog.constants';
3
- export type { DialogAlign, DialogContentProps, DialogContentWidth, DialogFormContentProps, DialogHeaderProps, DialogHeaderSize, DialogSize, DialogTitleAlign, DialogTitleProps, DialogVariant, DialogWideContentProps, DialogWideHeaderProps, DialogWideTitleProps, } from './dialog.types';
3
+ export type { DialogAlign, DialogContentProps, DialogContentWidth, DialogDescriptionProps, DialogFormContentProps, DialogHeaderProps, DialogHeaderSize, DialogSize, DialogTitleAlign, DialogTitleProps, DialogVariant, DialogWideContentProps, DialogWideHeaderProps, DialogWideTitleProps, } from './dialog.types';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleflex/ui-tw",
3
- "version": "0.0.159",
3
+ "version": "0.0.161",
4
4
  "author": "scaleflex",
5
5
  "repository": "github:scaleflex/ui",
6
6
  "homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
@@ -29,7 +29,8 @@
29
29
  "@radix-ui/react-switch": "^1.0.1",
30
30
  "@radix-ui/react-tabs": "^1.1.13",
31
31
  "@radix-ui/react-tooltip": "^1.2.6",
32
- "@scaleflex/icons-tw": "^0.0.159",
32
+ "@radix-ui/react-visually-hidden": "^1.2.4",
33
+ "@scaleflex/icons-tw": "^0.0.161",
33
34
  "@tanstack/react-table": "^8.21.3",
34
35
  "@types/lodash.merge": "^4.6.9",
35
36
  "class-variance-authority": "^0.7.1",