vlite3 1.5.12 → 1.5.13

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.
Files changed (127) hide show
  1. package/README.md +20 -8
  2. package/components/Accordion/AccordionContent.vue.js +2 -2
  3. package/components/CommandPalette/CommandPaletteContent2.vue.js +1 -1
  4. package/components/CommandPalette/{CommandPaletteItem2.vue.js → CommandPaletteItem.vue.js} +1 -1
  5. package/components/Dropdown/DropdownMenu.vue.js +1 -1
  6. package/components/Form/AccordionView2.vue.js +1 -1
  7. package/components/Form/Form.vue.js +2 -2
  8. package/components/NavbarCommandPalette.vue.js +1 -1
  9. package/components/PanZoomViewport/PanZoomViewport.vue.d.ts +7 -7
  10. package/components/PanZoomViewport/PanZoomViewport.vue.js +1 -1
  11. package/components/Tabes/Tabes.vue.js +2 -2
  12. package/docs/README.md +17 -0
  13. package/docs/all-components.md +89 -0
  14. package/docs/component-index.md +313 -0
  15. package/docs/components/accordion.md +52 -0
  16. package/docs/components/alert.md +34 -0
  17. package/docs/components/app-shell.md +371 -0
  18. package/docs/components/async-select.md +264 -0
  19. package/docs/components/attachments-list.md +231 -0
  20. package/docs/components/avatar-group.md +74 -0
  21. package/docs/components/avatar-uploader.md +61 -0
  22. package/docs/components/avatar.md +28 -0
  23. package/docs/components/badge.md +81 -0
  24. package/docs/components/barcode.md +42 -0
  25. package/docs/components/beacon.md +29 -0
  26. package/docs/components/breadcrumb.md +317 -0
  27. package/docs/components/button-group.md +35 -0
  28. package/docs/components/button.md +86 -0
  29. package/docs/components/calendar.md +95 -0
  30. package/docs/components/carousel.md +122 -0
  31. package/docs/components/cart.md +533 -0
  32. package/docs/components/category-manager.md +269 -0
  33. package/docs/components/category-menu.md +251 -0
  34. package/docs/components/charts.md +1456 -0
  35. package/docs/components/chat.md +330 -0
  36. package/docs/components/checkbox.md +31 -0
  37. package/docs/components/chip.md +137 -0
  38. package/docs/components/choice-box.md +40 -0
  39. package/docs/components/clipboard.md +105 -0
  40. package/docs/components/clock.md +70 -0
  41. package/docs/components/color-picker.md +82 -0
  42. package/docs/components/command-palette.md +214 -0
  43. package/docs/components/comment-thread.md +171 -0
  44. package/docs/components/confirmation-modal.md +50 -0
  45. package/docs/components/custom-fields-display.md +94 -0
  46. package/docs/components/custom-fields.md +97 -0
  47. package/docs/components/data-list.md +93 -0
  48. package/docs/components/data-table.md +922 -0
  49. package/docs/components/date-picker.md +58 -0
  50. package/docs/components/date-range-picker.md +24 -0
  51. package/docs/components/date-time.md +104 -0
  52. package/docs/components/dropdown.md +740 -0
  53. package/docs/components/empty.md +100 -0
  54. package/docs/components/export-data.md +320 -0
  55. package/docs/components/file-picker.md +83 -0
  56. package/docs/components/file-preview.md +42 -0
  57. package/docs/components/file-tree.md +144 -0
  58. package/docs/components/footer.md +251 -0
  59. package/docs/components/forms.md +776 -0
  60. package/docs/components/gantt-chart.md +767 -0
  61. package/docs/components/google-login.md +67 -0
  62. package/docs/components/google-map.md +128 -0
  63. package/docs/components/heatmap.md +80 -0
  64. package/docs/components/icon-picker.md +58 -0
  65. package/docs/components/icon.md +176 -0
  66. package/docs/components/image-comparison.md +51 -0
  67. package/docs/components/image-magnifier.md +26 -0
  68. package/docs/components/import-data.md +521 -0
  69. package/docs/components/input.md +58 -0
  70. package/docs/components/invoice.md +339 -0
  71. package/docs/components/kanban.md +302 -0
  72. package/docs/components/label.md +25 -0
  73. package/docs/components/list.md +419 -0
  74. package/docs/components/masonry.md +55 -0
  75. package/docs/components/modal.md +133 -0
  76. package/docs/components/multi-select.md +54 -0
  77. package/docs/components/navbar.md +403 -0
  78. package/docs/components/number-input.md +41 -0
  79. package/docs/components/otp-input.md +68 -0
  80. package/docs/components/pagination.md +83 -0
  81. package/docs/components/pan-zoom-viewport.md +245 -0
  82. package/docs/components/permission-editor.md +322 -0
  83. package/docs/components/persona.md +56 -0
  84. package/docs/components/price.md +106 -0
  85. package/docs/components/pricing-plan.md +68 -0
  86. package/docs/components/progress-bar.md +53 -0
  87. package/docs/components/qr-code.md +59 -0
  88. package/docs/components/rating.md +59 -0
  89. package/docs/components/rich-text-editor.md +210 -0
  90. package/docs/components/scale-generator.md +101 -0
  91. package/docs/components/screen.md +208 -0
  92. package/docs/components/seo-provider.md +189 -0
  93. package/docs/components/side-panel.md +94 -0
  94. package/docs/components/sidebar-menu.md +422 -0
  95. package/docs/components/skeleton.md +115 -0
  96. package/docs/components/slider.md +48 -0
  97. package/docs/components/spinner.md +27 -0
  98. package/docs/components/splitter.md +97 -0
  99. package/docs/components/stats.md +234 -0
  100. package/docs/components/status-chip.md +232 -0
  101. package/docs/components/switch.md +23 -0
  102. package/docs/components/tabs.md +335 -0
  103. package/docs/components/tag-input.md +55 -0
  104. package/docs/components/textarea.md +31 -0
  105. package/docs/components/theme-provider.md +130 -0
  106. package/docs/components/theme-toggle.md +36 -0
  107. package/docs/components/thumbnail-selector.md +186 -0
  108. package/docs/components/timeline.md +225 -0
  109. package/docs/components/toast-notification.md +89 -0
  110. package/docs/components/tooltip.md +31 -0
  111. package/docs/components/workbook.md +102 -0
  112. package/docs/composables/use-theme.md +59 -0
  113. package/docs/getting-started/setup.md +176 -0
  114. package/docs/guides/draggable.md +211 -0
  115. package/docs/guides/internationalization.md +281 -0
  116. package/docs/guides/performance.md +118 -0
  117. package/docs/guides/testing-forms.md +154 -0
  118. package/docs/guides/testing-overlays.md +131 -0
  119. package/docs/guides/theming.md +124 -0
  120. package/docs/utilities/search.md +580 -0
  121. package/docs/utilities/utilities.md +371 -0
  122. package/docs-manifest.json +339 -0
  123. package/package.json +5 -13
  124. package/scripts/generate-docs-manifest.js +207 -0
  125. package/scripts/sync-docs.js +754 -0
  126. package/style.css +1 -1
  127. /package/components/Dropdown/{DropdownMenu2.vue.js → DropdownMenu3.vue.js} +0 -0
@@ -0,0 +1,124 @@
1
+ # 🎨 Theming & Customization (The Clean System)
2
+
3
+ Hello there! 👋 This guide will show you how to customize **vlite3** using our Tailwind CSS v4 theming system.
4
+
5
+ The **Clean** design system relies heavily on a semantic design token approach. It focuses on simplicity, minimalism, ample whitespace, and legible typography. By limiting our color palettes, we reduce visual clutter, letting users easily flow through your application.
6
+
7
+ ---
8
+
9
+ ## 🎨 Semantic Colors
10
+
11
+ We use CSS variables for all of our colors. Modifying them is incredibly straightforward! Override these variables in `:root` or within a `.dark` class (if you're using class-based dark mode) to create an interface that truly feels yours.
12
+
13
+ To keep things "Clean", try to opt for subtle, harmonious tones rather than highly saturated, clashing colors.
14
+
15
+ | Variable | Utility Class | Description | Recommended Usage |
16
+ | -------------------------------- | ----------------------------- | --------------------------------------- | ----------------------------------------------- |
17
+ | `--color-background` | `bg-background` | Default layout background (e.g. white/black) | Main application background. Keep it pure. |
18
+ | `--color-foreground` | `text-foreground` | Default text color (e.g. zinc-900/100) | Primary content text. Should have high contrast.|
19
+ | `--color-card` | `bg-card` | Card background | Use for surface elevations (cards, dialogs). |
20
+ | `--color-card-light` | `bg-card-light` | Lighter card background | Use for nested cards or softer elevations. |
21
+ | `--color-primary` | `bg-primary` | Primary brand color | Main actions, buttons, and active states. |
22
+ | `--color-primary-foreground` | `text-primary-foreground` | Text on primary background | Text/icons displayed on primary elements. |
23
+ | `--color-muted` | `bg-muted` | Muted/subtle background | Very soft surfaces for secondary importance. |
24
+ | `--color-muted` | `text-muted` | Muted/subtle text | Secondary text, inactive links, descriptions. |
25
+ | `--color-border` | `border` | Default border color | Use softly! Keep borders light (`/40` or `/30`).|
26
+ | `--radius` | `rounded` | Global border radius | A shared radius perfectly ties everything together.|
27
+
28
+ ---
29
+
30
+ ## Root Background and scoped Surface
31
+
32
+ `ThemeProvider` treats `bgColor` as the root palette seed. An optional
33
+ `surfaceColor` independently seeds every `.bg-card` descendant with a complete
34
+ local palette, so a dark card on a light page automatically receives readable
35
+ foreground, muted, border, input, semantic, chart, shadow, and scrollbar
36
+ tokens. The primary brand palette remains unchanged in both scopes.
37
+
38
+ `.bg-card-light` is a shallower companion to the selected Surface, while
39
+ nested `.bg-card` elements move progressively away from their parent color.
40
+ Without `surfaceColor`, existing root-derived card behavior remains unchanged.
41
+
42
+ `primaryColor` maps to the brand `--color-primary*` family. The similarly named
43
+ `--color-accent` variable is a neutral interaction token for hover and selected
44
+ states; these concepts are intentionally separate.
45
+
46
+ ## Optional base-font spacing
47
+
48
+ Typography always scales with `baseFontSize`. Tailwind geometry remains fixed
49
+ at `--spacing: 0.25rem` by default for backward compatibility. Set
50
+ `scaleSpacingWithBaseFontSize` to opt in to:
51
+
52
+ ```text
53
+ --spacing = 0.25rem * (baseFontSize / 16)
54
+ ```
55
+
56
+ This affects numeric Tailwind spacing utilities such as padding, margin, gap,
57
+ offset, width, height, and size. Percentage, viewport, full-size, arbitrary,
58
+ and fixed-pixel utilities are unchanged.
59
+
60
+ ---
61
+
62
+ ### Subtle & Extended Color Variants
63
+
64
+ For more complex and expressive components, vlite3 gives you extended variants for main semantic intents (`primary`, `danger`, `warning`, `info`, `success`). To follow our Clean aesthetic, heavily favor the **Light** backgrounds (e.g., `<color>-light`) paired with **Fg-Light** text, rather than relying on harsh, solid colors!
65
+
66
+ * **Primary Variants:** `--color-primary-light`, `--color-primary-dark`, `--color-primary-fg`, `--color-primary-fg-light`
67
+ * **Danger Variants:** `--color-danger-light`, `--color-danger-dark`, `--color-danger-fg`, `--color-danger-fg-light`
68
+ * **Success Variants:** `--color-success-light`, `--color-success-dark`, `--color-success-fg`, `--color-success-fg-light`
69
+
70
+ **Clean Usage Example:**
71
+
72
+ ```html
73
+ <!-- A beautifully subtle success badge without visual fatigue -->
74
+ <div class="bg-success-light text-success-fg-light border border-success/20 px-3 py-1 rounded-full text-sm">
75
+ Operation Completed
76
+ </div>
77
+
78
+ <!-- A clear, prominent danger action button -->
79
+ <button class="bg-danger text-danger-fg hover:bg-danger-dark transition-colors px-4 py-2 rounded-md">
80
+ Delete Project
81
+ </button>
82
+ ```
83
+
84
+ ---
85
+
86
+ ## ✒️ Typography Scale System
87
+
88
+ Legible typography is an absolute cornerstone of the Clean system. Our fluid scaling approach guarantees that your text will always sit perfectly within its whitespace.
89
+
90
+ We provide two unique scales to complement the standard Tailwind tokens (`text-sm`, `text-base`, etc.):
91
+
92
+ 1. **Compact scale** (Prefix: `--text--fs-*`): Perfect for incredibly dense internal tools where readability is required at small scales.
93
+ 2. **Progressive scale** (Prefix: `--text-fs-*`): Great for marketing or editorial pages needing fine-tuned sizing.
94
+
95
+ *Tip: For standard layout needs, always prefer Tailwind's default `text-*` classes to ensure perfect consistency!*
96
+
97
+ ### Usage Examples
98
+
99
+ ```html
100
+ <!-- Need a very specific large-but-not-too-large title? -->
101
+ <h1 class="text-fs-6 font-semibold tracking-tight text-foreground">
102
+ Clean Dashboard
103
+ </h1>
104
+
105
+ <!-- Beautiful, readable body text -->
106
+ <p class="text-base leading-relaxed text-muted-foreground mt-2">
107
+ Here is some beautifully spaced paragraph text that is very easy to read.
108
+ </p>
109
+ ```
110
+
111
+ ---
112
+
113
+ ## 📐 The "Clean" Hard Rules
114
+
115
+ To maintain the pristine, highly-usable feel of your interfaces, kindly follow these robust layout rules:
116
+
117
+ 1. **Keep Borders Invisible (or soft):** Rely on whitespace and soft shadows (glassmorphism) to separate content, instead of heavy box borders. If you use a border, make it subtle (`border-border/30`).
118
+ 2. **Use `bg-muted` Intelligently:** Use muted backgrounds for structure to contrast against pure `bg-background` cards.
119
+ 3. **Mind your Gaps:** Let the layout breathe! Rely on Flexbox/Grid `gap-x-*` and `gap-y-*` rather than injecting ad-hoc `mt-*` or `ml-*` margins on sibling items.
120
+ 4. **Tailwind Shortcuts:**
121
+ * Use `border` instead of `border-border`
122
+ * Use `rounded` instead of `rounded-md` or `rounded-rounded`
123
+
124
+ Enjoy building your gorgeous, Clean interface! ✨
@@ -0,0 +1,580 @@
1
+ # vlite3 — Search Utility (`search.util.ts`)
2
+
3
+ > Complete reference for the `search()` function — a high-performance, fully-typed
4
+ > search engine with indexing, caching, and query operators.
5
+
6
+ - **File:** `src/utils/search.util.ts`
7
+ - **Exports:** `search`, `lazySearch`, `resetSearchIndex`
8
+ - **Import:** `import { search, lazySearch, resetSearchIndex } from 'vlite3'`
9
+
10
+ ---
11
+
12
+ ## Table of Contents
13
+
14
+ - [Overview](#overview)
15
+ - [API Signature](#api-signature)
16
+ - [Return Value](#return-value)
17
+ - [Query Types](#query-types)
18
+ - [Operators](#operators)
19
+ - [Indexing & Caching](#indexing--caching)
20
+ - [Performance](#performance)
21
+ - [Examples](#examples)
22
+ - [TypeScript Types](#typescript-types)
23
+ - [Edge Cases & Best Practices](#edge-cases--best-practices)
24
+ - [Lazy Search](#lazy-search)
25
+
26
+ ---
27
+
28
+ ## Overview
29
+
30
+ `search()` is a zero-dependency, in-memory search engine for JavaScript/TypeScript
31
+ arrays. It works with both primitive arrays (`string[]`, `number[]`) and object
32
+ arrays (`Record<string, any>[]`). It automatically builds and caches indexes
33
+ for fast repeated queries.
34
+
35
+ Key features:
36
+ - **Inverted index** for case-insensitive substring matching on string fields
37
+ - **Hash index** for O(1) exact-match lookups
38
+ - **Sorted numeric index** for O(log n) range queries (`$gte`, `$lte`, etc.)
39
+ - **Model-key caching** — reuse indexes across calls (Mongoose-style model names)
40
+ - **10 query operators** — `$eq`, `$ne`, `$gt`, `$gte`, `$lt`, `$lte`, `$in`, `$nin`, `$regex`, `$exists`
41
+ - **AND / OR semantics** — multiple rest-params = AND; array of queries = OR
42
+ - **Nested object search** — query nested fields via dot-notation or nested objects
43
+ - **Fully typed** — generic TypeScript with autocomplete on field names
44
+
45
+ ---
46
+
47
+ ## API Signature
48
+
49
+ ```ts
50
+ function search<T>(
51
+ data: T[],
52
+ ...queries: [...QueryObject<T>[], modelKey?: string]
53
+ ): SearchResult<T>
54
+
55
+ function search<T>(
56
+ data: T[],
57
+ query: string, // primitive substring search
58
+ modelKey?: string
59
+ ): SearchResult<T>
60
+
61
+ function search<T>(
62
+ data: T[],
63
+ queries: QueryObject<T>[], // OR query (array)
64
+ modelKey?: string
65
+ ): SearchResult<T>
66
+ ```
67
+
68
+ ### Parameters
69
+
70
+ | Parameter | Type | Description |
71
+ |-------------|-------------------------------------------|------------------------------------------------|
72
+ | `data` | `T[]` | The dataset to search |
73
+ | `...queries`| `QueryObject<T>` / `QueryObject<T>[]` / `string` | One or more queries (see below) |
74
+ | `modelKey` | `string` (optional, last argument) | Cache key for index reuse (e.g., `'User'`) |
75
+
76
+ ### Rules for `modelKey`
77
+
78
+ The **last argument** is treated as a `modelKey` (cache key) when:
79
+ - The data contains objects (not primitives), AND
80
+ - The last argument is a plain string
81
+
82
+ ---
83
+
84
+ ## Return Value
85
+
86
+ ```ts
87
+ interface SearchResult<T> {
88
+ results: T[] // Matched items in original array order
89
+ reset: () => void // Clears cached index for this modelKey
90
+ loading: boolean // Whether the engine is building indexes (always false for sync search)
91
+ }
92
+ ```
93
+
94
+ ### Destructured usage
95
+
96
+ ```ts
97
+ const { results, reset } = search(data, { name: 'Jane' }, 'User')
98
+
99
+ // Later, if data changes:
100
+ reset() // Clears the 'User' index cache
101
+ ```
102
+
103
+ ### Standalone cache reset
104
+
105
+ ```ts
106
+ import { resetSearchIndex } from 'vlite3'
107
+
108
+ resetSearchIndex('User') // Clear one model's cache
109
+ resetSearchIndex() // Clear ALL caches
110
+ ```
111
+
112
+ ---
113
+
114
+ ## Query Types
115
+
116
+ ### 1. Primitive String Search
117
+
118
+ Searches a `string[]` for case-insensitive substring matches.
119
+
120
+ ```ts
121
+ search(['apple', 'banana', 'cherry', 'january'], 'an')
122
+ // results: ['banana', 'january']
123
+ ```
124
+
125
+ ### 2. Single Object Query (AND fields)
126
+
127
+ Each field in the query object is an AND condition.
128
+
129
+ ```ts
130
+ search(users, { name: 'Jane', age: 25 })
131
+ // Matches items where name contains 'Jane' AND age === 25
132
+ ```
133
+
134
+ ### 3. Multiple Object Queries (AND across queries)
135
+
136
+ Multiple query objects as rest parameters: the results are the **intersection** (AND).
137
+
138
+ ```ts
139
+ search(products, { category: 'clothes' }, { price: { $gte: 200 } }, 'Product')
140
+ // Matches items in category 'clothes' AND price >= 200
141
+ ```
142
+
143
+ ### 4. Array of Queries (OR)
144
+
145
+ An array of query objects: the results are the **union** (OR).
146
+
147
+ ```ts
148
+ search(users, [{ name: 'John' }, { age: 25 }], 'User')
149
+ // Matches items where name is 'John' OR age is 25
150
+ ```
151
+
152
+ ### 5. Direct Values vs. Operators
153
+
154
+ - **String values** → case-insensitive **substring** match
155
+ - **Number/boolean values** → **exact** match
156
+ - **Operator objects** (`{ $gte: 10 }`) → evaluated per operator rules
157
+
158
+ ### 6. Nested Object Queries
159
+
160
+ You can query nested object fields in two equivalent ways:
161
+
162
+ **Nested object syntax (auto-flattened):**
163
+ ```ts
164
+ search(people, { name: { firstName: 'Jesse' } })
165
+ ```
166
+
167
+ **Dot-notation syntax:**
168
+ ```ts
169
+ search(people, { 'name.firstName': 'Jesse' })
170
+ ```
171
+
172
+ Both are equivalent. Nested queries are automatically flattened to dot-notation
173
+ internally, and all nested paths are indexed for fast lookups.
174
+
175
+ ---
176
+
177
+ ## Operators
178
+
179
+ All operators are specified as values in a query object field:
180
+
181
+ ```ts
182
+ search(data, { fieldName: { $operator: value } })
183
+ ```
184
+
185
+ ### Reference Table
186
+
187
+ | Operator | Type | Description |
188
+ |-----------|-----------------|-------------------------------------------------------|
189
+ | `$eq` | `any` | Exact equality (`===`) |
190
+ | `$ne` | `any` | Not equal (`!==`) |
191
+ | `$gt` | `number` | Greater than |
192
+ | `$gte` | `number` | Greater than or equal |
193
+ | `$lt` | `number` | Less than |
194
+ | `$lte` | `number` | Less than or equal |
195
+ | `$in` | `string` | Case-insensitive substring match (works on arrays) |
196
+ | `$nin` | `string` | NOT substring match |
197
+ | `$regex` | `string\|RegExp`| Regular expression test |
198
+ | `$exists` | `boolean` | `true` = field must exist; `false` = must not exist |
199
+
200
+ ### Combining Operators
201
+
202
+ Multiple operators on the same field are ANDed:
203
+
204
+ ```ts
205
+ search(data, { price: { $gte: 100, $lte: 500 } })
206
+ // price >= 100 AND price <= 500
207
+ ```
208
+
209
+ ### `$in` on Array Fields
210
+
211
+ The `$in` operator checks if ANY element of an array field contains the substring:
212
+
213
+ ```ts
214
+ const data = [
215
+ { name: 'Shirt', sizes: ['sm', 'md', 'lg'] },
216
+ { name: 'Hat', sizes: ['one-size'] },
217
+ ]
218
+
219
+ search(data, { sizes: { $in: 'sm' } })
220
+ // results: [{ name: 'Shirt', sizes: ['sm', 'md', 'lg'] }]
221
+ ```
222
+
223
+ ---
224
+
225
+ ## Indexing & Caching
226
+
227
+ ### How Indexing Works
228
+
229
+ When `search()` is first called with a `modelKey`, it builds three types of indexes:
230
+
231
+ 1. **Hash Index** — Maps exact field values to row indices. O(1) lookup.
232
+ Used for: direct value matches on numbers/booleans, `$eq` operator.
233
+
234
+ 2. **Inverted Index** — Maps lowercase string values to row indices.
235
+ Used for: `$in` (substring), direct string value matches.
236
+
237
+ 3. **Sorted Numeric Index** — Sorted array of `{ value, index }` pairs.
238
+ Used for: `$gt`, `$gte`, `$lt`, `$lte` via binary search.
239
+
240
+ ### Caching Behavior
241
+
242
+ ```
243
+ First call: search(data, query, 'Product') → builds index, caches it
244
+ Second call: search(data, query, 'Product') → reuses cached index (instant)
245
+ Data changes: reset() or resetSearchIndex('Product') → clears cache
246
+ Next call: search(newData, query, 'Product') → rebuilds index
247
+ ```
248
+
249
+ The cache checks if the same data array reference is passed.
250
+ If the same data array reference is passed, the cached index is reused.
251
+ If a new array is passed, the index is rebuilt automatically.
252
+
253
+ ### Without modelKey
254
+
255
+ If no `modelKey` is provided, indexes are built fresh every call (no caching).
256
+ For one-off searches this is fine, but for repeated queries on the same dataset,
257
+ always provide a `modelKey`.
258
+
259
+ ---
260
+
261
+ ## Performance
262
+
263
+ | Operation | Data Size | Complexity | Notes |
264
+ |--------------------|-----------|----------------------|------------------------------|
265
+ | Index build | n items | O(n × k) | k = number of fields |
266
+ | Exact match | n items | O(1) amortized | Hash index lookup |
267
+ | Substring match | n items | O(m) amortized | m = unique values in field |
268
+ | Range query | n items | O(log n + r) | r = results in range |
269
+ | Cached re-query | any | O(1) for index fetch | Only query eval cost applies |
270
+
271
+ For datasets of 10,000+ items with repeated queries, using a `modelKey` provides
272
+ **order-of-magnitude** speedup by avoiding index rebuilds.
273
+
274
+ ---
275
+
276
+ ## Examples
277
+
278
+ ### Example 1 — Basic Object Search
279
+
280
+ ```ts
281
+ const data = [
282
+ { name: 'John', age: 30, city: 'New York' },
283
+ { name: 'Jane', age: 25, city: 'London' },
284
+ { name: 'Bob', age: 35, city: 'Paris' },
285
+ ]
286
+
287
+ const { results } = search(data, { name: 'Jane' })
288
+ // results: [{ name: 'Jane', age: 25, city: 'London' }]
289
+
290
+ const { results: r2 } = search(data, { age: 25 })
291
+ // r2: [{ name: 'Jane', age: 25, city: 'London' }]
292
+ ```
293
+
294
+ ### Example 2 — Primitive String Array
295
+
296
+ ```ts
297
+ const fruits = ['apple', 'banana', 'cherry', 'january']
298
+
299
+ const { results } = search(fruits, 'an')
300
+ // results: ['banana', 'january']
301
+ ```
302
+
303
+ ### Example 3 — Multi-Field AND
304
+
305
+ ```ts
306
+ const { results } = search(data, { name: 'Jane', age: 25 })
307
+ // results: [{ name: 'Jane', age: 25, city: 'London' }]
308
+ ```
309
+
310
+ ### Example 4 — OR Query (Array)
311
+
312
+ ```ts
313
+ const { results } = search(data, [{ name: 'John' }, { age: 25 }])
314
+ // results: [
315
+ // { name: 'John', age: 30, city: 'New York' },
316
+ // { name: 'Jane', age: 25, city: 'London' },
317
+ // ]
318
+ ```
319
+
320
+ ### Example 5 — E-commerce: Category Filter
321
+
322
+ ```ts
323
+ const products = [
324
+ { title: 'Product 1', price: 100, category: 'Electronics', sizes: ['sm', 'md'] },
325
+ { title: 'Product 2', price: 200, category: 'clothes', sizes: ['sm', 'md'] },
326
+ { title: 'Product 3', price: 300, category: 'Electronics', sizes: ['sm', 'md'] },
327
+ { title: 'Product 4', price: 400, category: 'clothes', sizes: ['sm', 'md'] },
328
+ { title: 'Product 5', price: 400, category: 'men-shoes', sizes: ['sm', 'md'] },
329
+ { title: 'Product 6', price: 400, category: 'men', sizes: ['sm', 'md'] },
330
+ ]
331
+
332
+ // Exact category match
333
+ const { results } = search(products, { category: 'Electronics' }, 'Product')
334
+ // results: [Product 1, Product 3]
335
+
336
+ // AND across multiple queries
337
+ const { results: r2 } = search(
338
+ products,
339
+ { category: 'clothes' },
340
+ { sizes: 'sm' },
341
+ { price: { $gte: 200, $lte: 300 } },
342
+ 'Product'
343
+ )
344
+ // results: [Product 2]
345
+
346
+ // Substring match with $in
347
+ const { results: r3 } = search(
348
+ products,
349
+ { category: { $in: 'men' } },
350
+ { title: { $in: 'product' } },
351
+ 'Product'
352
+ )
353
+ // results: [Product 5, Product 6]
354
+ ```
355
+
356
+ ### Example 6 — OR with $in Operator
357
+
358
+ ```ts
359
+ const { results } = search(
360
+ products,
361
+ [{ category: { $in: 'men' } }, { title: { $in: 'men' } }],
362
+ 'Product'
363
+ )
364
+ // results: [Product 5, Product 6]
365
+ ```
366
+
367
+ ### Example 7 — With Caching and Reset
368
+
369
+ ```ts
370
+ const { results, reset } = search(users, { name: 'Jane' }, 'User')
371
+
372
+ // ... later, user data changes ...
373
+ reset() // Clears the 'User' index
374
+
375
+ // Or clear all caches:
376
+ import { resetSearchIndex } from 'vlite3'
377
+ resetSearchIndex()
378
+ ```
379
+
380
+ ### Example 8 — Range Queries
381
+
382
+ ```ts
383
+ // Products between $100 and $300
384
+ const { results } = search(products, { price: { $gte: 100, $lte: 300 } }, 'Product')
385
+
386
+ // Products over $300
387
+ const { results: expensive } = search(products, { price: { $gt: 300 } }, 'Product')
388
+ ```
389
+
390
+ ### Example 9 — Regex Search
391
+
392
+ ```ts
393
+ const { results } = search(users, { name: { $regex: '^J' } }, 'User')
394
+ // Matches names starting with 'J': John, Jane
395
+ ```
396
+
397
+ ### Example 10 — Field Existence
398
+
399
+ ```ts
400
+ const { results } = search(data, { email: { $exists: true } })
401
+ // Only items that have a non-null/undefined email field
402
+ ```
403
+
404
+ ### Example 11 — Nested Object Search
405
+
406
+ ```ts
407
+ const people = [
408
+ { name: { firstName: 'Jesse', lastName: 'Bowen' }, state: 'Seattle' },
409
+ { name: { firstName: 'Jane', lastName: 'Doe' }, state: 'London' },
410
+ { name: { firstName: 'Bob', lastName: 'Smith' }, state: 'Paris' },
411
+ ]
412
+
413
+ // Nested object syntax
414
+ const { results } = search(people, { name: { firstName: 'Jesse' } }, 'Person')
415
+ // results: [{ name: { firstName: 'Jesse', lastName: 'Bowen' }, state: 'Seattle' }]
416
+
417
+ // Dot-notation syntax (equivalent)
418
+ const { results: r2 } = search(people, { 'name.lastName': 'Doe' }, 'Person')
419
+ // results: [{ name: { firstName: 'Jane', lastName: 'Doe' }, state: 'London' }]
420
+
421
+ // With operators on nested fields
422
+ const { results: r3 } = search(people, { name: { firstName: { $in: 'j' } } }, 'Person')
423
+ // results: [Jesse, Jane]
424
+ ```
425
+
426
+ ---
427
+
428
+ ## TypeScript Types
429
+
430
+ ```ts
431
+ /** Comparison operators */
432
+ interface SearchOperators<V = any> {
433
+ $eq?: V
434
+ $ne?: V
435
+ $gt?: number
436
+ $gte?: number
437
+ $lt?: number
438
+ $lte?: number
439
+ $in?: string
440
+ $nin?: string
441
+ $regex?: string | RegExp
442
+ $exists?: boolean
443
+ }
444
+
445
+ /** A query value: direct value or operator object */
446
+ type QueryValue<V = any> = V | SearchOperators<V>
447
+
448
+ /** Query object: partial map of field names to query values */
449
+ type QueryObject<T = Record<string, any>> = {
450
+ [K in keyof T]?: QueryValue<T[K]>
451
+ }
452
+
453
+ /** Return type of search() */
454
+ interface SearchResult<T> {
455
+ results: T[]
456
+ reset: () => void
457
+ }
458
+ ```
459
+
460
+ ---
461
+
462
+ ## Edge Cases & Best Practices
463
+
464
+ ### Matching Behavior Summary
465
+
466
+ | Data Type | Query Type | Behavior |
467
+ |-------------|-------------------|--------------------------------------|
468
+ | `string[]` | `string` | Case-insensitive substring match |
469
+ | `object[]` | `{ field: str }` | Case-insensitive substring on field |
470
+ | `object[]` | `{ field: num }` | Exact numeric equality |
471
+ | `object[]` | `{ field: bool }` | Exact boolean equality |
472
+ | `object[]` | `{ field: {$op} }`| Operator-based evaluation |
473
+
474
+ ### Best Practices
475
+
476
+ 1. **Always use a `modelKey`** for datasets you query more than once.
477
+ This avoids rebuilding indexes on every call.
478
+
479
+ 2. **Call `reset()`** whenever the underlying data array changes
480
+ (items added, removed, or modified).
481
+
482
+ 3. **Use `$in` for fuzzy text matching**, not `$eq`.
483
+ `$eq` does strict equality; `$in` does substring matching.
484
+
485
+ 4. **Combine operators** on the same field for range queries:
486
+ `{ price: { $gte: 100, $lte: 500 } }`.
487
+
488
+ 5. **Use OR queries (arrays)** when you want "match any of these conditions":
489
+ `search(data, [{ category: 'shoes' }, { category: 'boots' }])`.
490
+
491
+ 6. **Use multiple rest params** when you want "match ALL of these conditions":
492
+ `search(data, { color: 'red' }, { size: 'lg' })`.
493
+
494
+ 7. **Empty query** returns all items:
495
+ `search(data, {})` → returns everything.
496
+
497
+ 8. **Empty data** returns empty results:
498
+ `search([], { name: 'test' })` → `{ results: [] }`.
499
+
500
+ 9. For **array fields** (like `sizes: ['sm', 'md']`):
501
+ - Direct string value: `{ sizes: 'sm' }` → checks if any element contains 'sm' (substring)
502
+ - `$in` operator: `{ sizes: { $in: 'sm' } }` → same as above, explicit
503
+
504
+ 10. The search **preserves original order** — results appear in the same
505
+ order as they do in the source array.
506
+
507
+ 11. **Nested objects** are automatically indexed via dot-notation paths.
508
+ Query with `{ name: { firstName: 'X' } }` or `{ 'name.firstName': 'X' }`.
509
+ Both syntaxes are equivalent and fully indexed.
510
+
511
+ ---
512
+
513
+ ## Lazy Search
514
+
515
+ `lazySearch()` creates a pre-configured, reusable search instance. Unlike `search()`,
516
+ which takes a full query each time, `lazySearch()` accepts the dataset and searchable
517
+ fields upfront, builds the index once, and returns a fast `search(query)` function.
518
+
519
+ ### API Signature
520
+
521
+ ```ts
522
+ function lazySearch<T>(
523
+ data: T[],
524
+ keys?: string[], // Field paths to search across (dot-notation)
525
+ modelKey?: string // Cache key for index persistence
526
+ ): LazySearchResult<T>
527
+ ```
528
+
529
+ ### Return Value
530
+
531
+ ```ts
532
+ interface LazySearchResult<T> {
533
+ search: (query: string) => T[] // Search function
534
+ reset: () => void // Clear cached index
535
+ loading: boolean // Whether index is being built
536
+ }
537
+ ```
538
+
539
+ ### How It Works
540
+
541
+ 1. Call `lazySearch(data, keys)` — the index is built immediately
542
+ 2. Call `search(query)` repeatedly — fast substring search across the specified keys
543
+ 3. Results are OR’d across keys (matches in ANY key are returned)
544
+ 4. If `keys` is omitted, ALL fields are searched
545
+
546
+ ### Example 12 — Lazy Search with Objects
547
+
548
+ ```ts
549
+ const people = [
550
+ { name: { firstName: 'Jesse', lastName: 'Bowen' }, state: 'Seattle' },
551
+ { name: { firstName: 'Jane', lastName: 'Doe' }, state: 'London' },
552
+ { name: { firstName: 'Bob', lastName: 'Smith' }, state: 'Paris' },
553
+ ]
554
+
555
+ const { search, reset, loading } = lazySearch(people, ['name.firstName', 'state'])
556
+
557
+ search('ess') // [Jesse] — matches 'Jesse' (firstName contains 'ess')
558
+ search('lon') // [Jane] — matches 'London' (state contains 'lon')
559
+ search('o') // [Jesse, Bob] — 'Bowen' and 'Bob' both contain 'o'... wait,
560
+ // 'state' is also searched: no match. Only firstName matches.
561
+
562
+ reset() // Clears the index cache
563
+ ```
564
+
565
+ ### Example 13 — Lazy Search with Primitives
566
+
567
+ ```ts
568
+ const { search } = lazySearch(['apple', 'banana', 'cherry', 'january'])
569
+
570
+ search('an') // ['banana', 'january']
571
+ search('ch') // ['cherry']
572
+ ```
573
+
574
+ ### Example 14 — Lazy Search All Fields
575
+
576
+ ```ts
577
+ // Omit keys — searches across ALL fields
578
+ const { search } = lazySearch(products)
579
+ search('elect') // Products with 'Electronics' in any field
580
+ ```