@kolkrabbi/kol-workshop 0.43.0 → 0.45.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kolkrabbi/kol-workshop",
3
- "version": "0.43.0",
3
+ "version": "0.45.0",
4
4
  "private": false,
5
5
  "description": "Docs viewer, shell and tag system",
6
6
  "license": "MIT",
@@ -13,9 +13,9 @@
13
13
  },
14
14
  "dependencies": {
15
15
  "d3": "^7.9.0",
16
- "@kolkrabbi/kol-brand": "^0.2.0",
17
16
  "@kolkrabbi/kol-markdown": "^0.2.0",
18
- "@kolkrabbi/kol-search": "^0.3.0"
17
+ "@kolkrabbi/kol-search": "^0.3.0",
18
+ "@kolkrabbi/kol-brand": "^0.2.0"
19
19
  },
20
20
  "peerDependencies": {
21
21
  "@kolkrabbi/kol-component": ">=0.296.0",
@@ -29,11 +29,11 @@
29
29
  "react-router-dom": "^6.0.0 || ^7.0.0"
30
30
  },
31
31
  "devDependencies": {
32
- "@kolkrabbi/kol-framework": "^0.64.0",
33
- "@kolkrabbi/kol-icons": "^0.52.0",
34
- "@kolkrabbi/kol-component": "^0.316.0",
35
- "@kolkrabbi/kol-theme": "^0.199.0",
36
- "@kolkrabbi/kol-shell": "^0.89.1"
32
+ "@kolkrabbi/kol-icons": "^0.66.0",
33
+ "@kolkrabbi/kol-framework": "^0.70.0",
34
+ "@kolkrabbi/kol-shell": "^0.113.0",
35
+ "@kolkrabbi/kol-theme": "^0.214.0",
36
+ "@kolkrabbi/kol-component": "^0.344.0"
37
37
  },
38
38
  "files": [
39
39
  "src",
@@ -1,8 +1,9 @@
1
- import { Fragment, useEffect, useMemo, useRef, useState } from 'react'
1
+ import { Fragment, useContext, useEffect, useMemo, useRef, useState } from 'react'
2
2
  import { getTagColor } from '@kolkrabbi/kol-markdown'
3
3
  import { useNavigate, useSearchParams } from 'react-router-dom'
4
4
  import { EmptyState, Input, Tag } from '@kolkrabbi/kol-component'
5
5
  import ResultRow from './ResultRow.jsx'
6
+ import { ShellSearchScopeContext } from '../shell/ShellLayout.jsx'
6
7
  import { Icon } from '@kolkrabbi/kol-icons'
7
8
  import { createIndex, search, parseQuery } from '@kolkrabbi/kol-search'
8
9
 
@@ -48,12 +49,16 @@ const readToken = (t) => (t.kind === 'term'
48
49
  ? `${t.field} ${t.value}`
49
50
  : `${t.negate ? 'not ' : ''}${t.field === 'tags' ? 'tag' : t.field}: ${t.value}${t.via === 'smart' ? ' (from the word)' : ''}`)
50
51
 
51
- export default function SearchPage({ items = [], spaces = [], facets = DEFAULT_FACETS, limit = 60, rowVariant = 'underline', rowMeta = 'facts', kindIcons, resultsPath }) {
52
+ export default function SearchPage({ items = [], spaces: allSpaces = [], facets = DEFAULT_FACETS, limit = 60, rowVariant = 'underline', rowMeta = 'facts', kindIcons, resultsPath }) {
52
53
  const [params, setParams] = useSearchParams()
53
54
  const navigate = useNavigate()
54
55
  const q = params.get('q') ?? ''
55
56
  const index = useMemo(() => createIndex(items), [items])
56
- const out = useMemo(() => search(index, q, { limit }), [index, q, limit])
57
+ /* the shell's Settings › Search scope (WorkshopSearchScope, 2026-10-29): results and the scope row cover only the
58
+ * spaces in view; null (outside a shell, or All) = every space */
59
+ const inScope = useContext(ShellSearchScopeContext)
60
+ const spaces = inScope ? allSpaces.filter((sp) => inScope.includes(sp.value)) : allSpaces
61
+ const out = useMemo(() => search(index, q, { scope: inScope ? { space: inScope } : {}, limit }), [index, q, limit, inScope?.join('\n')])
57
62
 
58
63
  /* `resultsPath`: the query is written to THAT route — a box on a search home sends its first
59
64
  * keystroke straight to the results page instead of filtering in place */
@@ -55,6 +55,11 @@ export const ShellNavCollapsedContext = (globalThis[Symbol.for('@kolkrabbi/kol-w
55
55
  * const meta = usePageMetaValue() — in a rail
56
56
  * Cleared on unmount, so a page that says nothing gets an empty context, never
57
57
  * the previous page's. */
58
+ /* THE SEARCH SCOPE REACHES THE RESULTS PAGE (WorkshopSearchScope, kol-hq 2026-10-29 — user: let the user choose which
59
+ * repos' docs are in view, *"I dont want any reinventions"*). The shell provides the space ids Settings › Search has in
60
+ * scope, or null for all; `SearchPage` reads it so the page and quick search cover the same spaces. */
61
+ export const ShellSearchScopeContext = (globalThis[Symbol.for('@kolkrabbi/kol-workshop/ShellSearchScopeContext')] ??= createContext(null))
62
+
58
63
  const ShellPageMetaContext = (globalThis[Symbol.for('@kolkrabbi/kol-workshop/ShellPageMetaContext')] ??= createContext({ meta: null, setMeta: null }))
59
64
 
60
65
  export function usePageMeta(meta) {
@@ -192,6 +197,25 @@ const writeSettings = (next) => {
192
197
  /* A search item in either shape — the kol-search item (`title · kind · space ·
193
198
  * category · tags · headings · keywords · description · href`) or the search modal's
194
199
  * older row (`label · sectionLabel · …`). Both keep working. */
200
+ /* TIES TAKE TURNS (2026-11-05 — "chess" showed one icon row before All results): the engine breaks a tied score
201
+ * alphabetically, so a flat cut of 12 gave six Chess organisms (`Chess …` sorts ahead of `chess-bishop`) every slot
202
+ * the eighteen chess icons tied with. Inside one score the groups now take turns, each keeping its own order; a
203
+ * stronger hit still outranks a weaker one, and the cut is the same 12. */
204
+ const QUICK_MAX = 12
205
+ const quickList = (ranked) => {
206
+ const out = []
207
+ for (let i = 0; i < ranked.length && out.length < QUICK_MAX;) {
208
+ let j = i
209
+ while (j < ranked.length && ranked[j].score === ranked[i].score) j++
210
+ const lanes = new Map()
211
+ ranked.slice(i, j).forEach((r) => { const g = r.item.category ?? ''; lanes.set(g, [...(lanes.get(g) ?? []), r]) })
212
+ const queues = [...lanes.values()]
213
+ for (let k = 0; queues.some((q) => k < q.length); k++) queues.forEach((q) => { if (k < q.length) out.push(q[k]) })
214
+ i = j
215
+ }
216
+ return out.slice(0, QUICK_MAX)
217
+ }
218
+
195
219
  const toSearchItem = (item, i) => ({
196
220
  ...item,
197
221
  id: item.id ?? item.href ?? `${item.label ?? item.title}-${i}`,
@@ -460,7 +484,12 @@ const ShellLayout = ({ routes = [], basePath = '/', brand: brandProp, brandLogoS
460
484
 
461
485
  // Adapt the old flat `routes` + callbacks to the DS ShellHeader API
462
486
  // (brand node · nav[{label,href,icon}] · isActive · onNavigate · actions slot).
463
- const navItems = routes.map((r) => ({
487
+ /* THE SCOPE (WorkshopSearchScope, kol-hq 2026-10-29): `scope` is 'all' · 'this' · the picked space ids, and it
488
+ * replaces `limitToSpace` (an old `true` reads as 'this'). Search and the tab bar follow it; the active space's tab
489
+ * always stays, so the page you are on never disappears. null = every space; a Pick with nothing ticked reads as This. */
490
+ const scope = prefs.scope ?? (prefs.limitToSpace ? 'this' : 'all')
491
+ const scopedIds = Array.isArray(scope) && scope.length ? scope : scope !== 'all' && activeRoute ? [activeRoute.id] : null
492
+ const navItems = routes.filter((r) => !scopedIds || r === activeRoute || scopedIds.includes(r.id)).map((r) => ({
464
493
  label: r.label,
465
494
  href: r.path ? joinPath(r.path) : basePath,
466
495
  icon: r.icon,
@@ -519,12 +548,12 @@ const ShellLayout = ({ routes = [], basePath = '/', brand: brandProp, brandLogoS
519
548
  /* THE ENGINE IS kol-search (2026-09-28) — the search modal ran a first-substring
520
549
  * match, so `atom` ranked AppHub first on a word in its description and only
521
550
  * one row lit its match. Ranked now, every hit highlighted, and a word that
522
- * names a category (`atom`) filters by it. `limitToSpace` (settings) scopes
523
- * quick search to the space you are in. */
551
+ * names a category (`atom`) filters by it. The scope (settings) narrows quick
552
+ * search to the spaces in view. */
524
553
  const searchIndex = useMemo(() => createIndex((searchItems ?? []).map(toSearchItem)), [searchItems])
525
- const quickScope = prefs.limitToSpace && activeRoute ? { space: activeRoute.id } : {}
554
+ const quickScope = scopedIds ? { space: scopedIds } : {}
526
555
  const searchResults = searchQuery
527
- ? search(searchIndex, searchQuery, { scope: quickScope, limit: 12 }).results.map(({ item, reasons, highlights }) => {
556
+ ? quickList(search(searchIndex, searchQuery, { scope: quickScope }).results).map(({ item, reasons, highlights }) => {
528
557
  const titleHit = reasons.some((r) => r.field === 'title')
529
558
  const first = reasons.find((r) => r.hit)
530
559
  return {
@@ -555,7 +584,12 @@ const ShellLayout = ({ routes = [], basePath = '/', brand: brandProp, brandLogoS
555
584
  { id: 'toc', label: 'Right rail', type: 'switch', on: !tocCollapsed, onChange: (on) => { setTocCollapsed(!on); setPref('tocHidden', !on) } },
556
585
  ] },
557
586
  { label: 'Search', rows: [
558
- { id: 'scope', label: 'This space only', type: 'switch', on: !!prefs.limitToSpace, onChange: (on) => setPref('limitToSpace', on) },
587
+ /* Pick starts from what was in view — This → the active space, All → every space */
588
+ { id: 'scope', label: 'Scope', type: 'choice', value: Array.isArray(scope) ? 'pick' : scope,
589
+ options: [{ value: 'all', label: 'All' }, { value: 'this', label: 'This' }, { value: 'pick', label: 'Pick' }],
590
+ onChange: (v) => setPref('scope', v !== 'pick' ? v : scopedIds ?? routes.map((r) => r.id)) },
591
+ ...(Array.isArray(scope) ? routes.map((r) => ({ id: `scope-${r.id}`, label: r.label, type: 'switch', on: scope.includes(r.id),
592
+ onChange: (on) => setPref('scope', on ? [...scope, r.id] : scope.filter((id) => id !== r.id)) })) : []),
559
593
  ] },
560
594
  ...settings,
561
595
  ]
@@ -568,6 +602,7 @@ const ShellLayout = ({ routes = [], basePath = '/', brand: brandProp, brandLogoS
568
602
  }
569
603
 
570
604
  return (
605
+ <ShellSearchScopeContext.Provider value={scopedIds}>
571
606
  <ShellPageMetaContext.Provider value={{ meta: pageMeta, setMeta: setPageMeta }}>
572
607
  <ShellTocContext.Provider value={setTocContent}>
573
608
  <ShellFullHeightContext.Provider value={setIsFullHeight}>
@@ -737,6 +772,7 @@ const ShellLayout = ({ routes = [], basePath = '/', brand: brandProp, brandLogoS
737
772
  </ShellFullHeightContext.Provider>
738
773
  </ShellTocContext.Provider>
739
774
  </ShellPageMetaContext.Provider>
775
+ </ShellSearchScopeContext.Provider>
740
776
  )
741
777
  }
742
778
 
@@ -7,7 +7,7 @@
7
7
  * against.
8
8
  */
9
9
  export { default as ShellLayout } from './ShellLayout.jsx'
10
- export { ShellTocContext, ShellFullHeightContext, ShellTocCollapsedContext, ShellNavCollapsedContext, ShellContentWidthContext, SHELL_SCROLL_ROOT, usePageMeta, usePageMetaValue } from './ShellLayout.jsx'
10
+ export { ShellTocContext, ShellFullHeightContext, ShellTocCollapsedContext, ShellNavCollapsedContext, ShellContentWidthContext, ShellSearchScopeContext, SHELL_SCROLL_ROOT, usePageMeta, usePageMetaValue } from './ShellLayout.jsx'
11
11
  export { default as ShellSidebar } from './ShellSidebar.jsx'
12
12
  /* the workshop rail IS a NavRail preset (2026-10-24): `NavRail preset="workshop"` renders ShellSidebar once this
13
13
  * package is imported — kol-component cannot import kol-workshop, so the name is registered from here */