@scaleflex/ui-tw 0.0.160 → 0.0.162

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.
@@ -173,7 +173,7 @@ export function ComboboxUsers(_ref) {
173
173
  align: "start"
174
174
  }, popoverContentProps), /*#__PURE__*/React.createElement(Command, {
175
175
  filter: function filter(value, search) {
176
- return value.includes(search.trim().toLowerCase()) ? 1 : 0;
176
+ return value.toLowerCase().includes(search.trim().toLowerCase()) ? 1 : 0;
177
177
  }
178
178
  }, /*#__PURE__*/React.createElement(AutoScrollToSelected, null), /*#__PURE__*/React.createElement(CommandInput, {
179
179
  size: size,
@@ -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');
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@scaleflex/ui-tw",
3
- "version": "0.0.160",
3
+ "version": "0.0.162",
4
4
  "author": "scaleflex",
5
5
  "repository": "github:scaleflex/ui",
6
6
  "homepage": "https://github.com/scaleflex/ui/blob/master/README.md",
@@ -30,7 +30,7 @@
30
30
  "@radix-ui/react-tabs": "^1.1.13",
31
31
  "@radix-ui/react-tooltip": "^1.2.6",
32
32
  "@radix-ui/react-visually-hidden": "^1.2.4",
33
- "@scaleflex/icons-tw": "^0.0.160",
33
+ "@scaleflex/icons-tw": "^0.0.162",
34
34
  "@tanstack/react-table": "^8.21.3",
35
35
  "@types/lodash.merge": "^4.6.9",
36
36
  "class-variance-authority": "^0.7.1",