@namroodinc/liquid-editorial 0.9.0 → 0.10.1

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 (67) hide show
  1. package/README.md +1 -1
  2. package/UPGRADING.md +55 -0
  3. package/dist/chunks/{EntryPicker-Baqn0SQM.cjs → EntryPicker-BhApdZtE.cjs} +2 -2
  4. package/dist/chunks/{EntryPicker-Baqn0SQM.cjs.map → EntryPicker-BhApdZtE.cjs.map} +1 -1
  5. package/dist/chunks/{EntryPicker-DIYjKmBf.js → EntryPicker-LBj_56_e.js} +2 -2
  6. package/dist/chunks/{EntryPicker-DIYjKmBf.js.map → EntryPicker-LBj_56_e.js.map} +1 -1
  7. package/dist/chunks/FormEditor-B5A38LZ4.cjs +2 -0
  8. package/dist/chunks/FormEditor-B5A38LZ4.cjs.map +1 -0
  9. package/dist/chunks/{FormEditor-HqqFmu7s.js → FormEditor-BEOp5EW-.js} +3 -3
  10. package/dist/chunks/FormEditor-BEOp5EW-.js.map +1 -0
  11. package/dist/chunks/frame-DJPTNz9f.cjs +2 -0
  12. package/dist/chunks/frame-DJPTNz9f.cjs.map +1 -0
  13. package/dist/chunks/frame-DUvTDV2g.js +157 -0
  14. package/dist/chunks/frame-DUvTDV2g.js.map +1 -0
  15. package/dist/chunks/group-7Z_xRlQx.js +34 -0
  16. package/dist/chunks/group-7Z_xRlQx.js.map +1 -0
  17. package/dist/chunks/group-nulIa2_8.cjs +2 -0
  18. package/dist/chunks/group-nulIa2_8.cjs.map +1 -0
  19. package/dist/components/Choice/index.cjs +1 -1
  20. package/dist/components/Choice/index.js +1 -1
  21. package/dist/components/EntryPicker/index.cjs +1 -1
  22. package/dist/components/EntryPicker/index.js +1 -1
  23. package/dist/components/EntryPicker/style.css +0 -4
  24. package/dist/components/Field/frame.d.cts +4 -2
  25. package/dist/components/Field/frame.d.cts.map +1 -1
  26. package/dist/components/Field/frame.d.ts +4 -2
  27. package/dist/components/Field/frame.d.ts.map +1 -1
  28. package/dist/components/Field/group.d.cts +1 -1
  29. package/dist/components/Field/group.d.cts.map +1 -1
  30. package/dist/components/Field/group.d.ts +1 -1
  31. package/dist/components/Field/group.d.ts.map +1 -1
  32. package/dist/components/Field/header.d.cts +2 -4
  33. package/dist/components/Field/header.d.cts.map +1 -1
  34. package/dist/components/Field/header.d.ts +2 -4
  35. package/dist/components/Field/header.d.ts.map +1 -1
  36. package/dist/components/Field/index.cjs +1 -1
  37. package/dist/components/Field/index.js +1 -1
  38. package/dist/components/Field/style.css +0 -18
  39. package/dist/components/Field/types.d.cts +4 -3
  40. package/dist/components/Field/types.d.cts.map +1 -1
  41. package/dist/components/Field/types.d.ts +4 -3
  42. package/dist/components/Field/types.d.ts.map +1 -1
  43. package/dist/components/FormEditor/README.md +11 -10
  44. package/dist/components/FormEditor/index.cjs +1 -1
  45. package/dist/components/FormEditor/index.d.cts.map +1 -1
  46. package/dist/components/FormEditor/index.d.ts.map +1 -1
  47. package/dist/components/FormEditor/index.js +1 -1
  48. package/dist/components/FormEditor/model.d.cts +0 -1
  49. package/dist/components/FormEditor/model.d.cts.map +1 -1
  50. package/dist/components/FormEditor/model.d.ts +0 -1
  51. package/dist/components/FormEditor/model.d.ts.map +1 -1
  52. package/dist/components/SelectionCard/index.cjs +1 -1
  53. package/dist/components/SelectionCard/index.js +1 -1
  54. package/dist/index.cjs +1 -1
  55. package/dist/index.js +2 -2
  56. package/package.json +1 -1
  57. package/dist/chunks/FormEditor-B7Pm_ZzT.cjs +0 -2
  58. package/dist/chunks/FormEditor-B7Pm_ZzT.cjs.map +0 -1
  59. package/dist/chunks/FormEditor-HqqFmu7s.js.map +0 -1
  60. package/dist/chunks/frame-CzadNYgy.js +0 -164
  61. package/dist/chunks/frame-CzadNYgy.js.map +0 -1
  62. package/dist/chunks/frame-Mh99nmhR.cjs +0 -2
  63. package/dist/chunks/frame-Mh99nmhR.cjs.map +0 -1
  64. package/dist/chunks/group-CJA3-3s5.js +0 -35
  65. package/dist/chunks/group-CJA3-3s5.js.map +0 -1
  66. package/dist/chunks/group-DRSLOsXu.cjs +0 -2
  67. package/dist/chunks/group-DRSLOsXu.cjs.map +0 -1
package/README.md CHANGED
@@ -610,7 +610,7 @@ Values accept Date, epoch milliseconds, or a date string; invalid values render
610
610
 
611
611
  ### Field
612
612
 
613
- Field owns a control's visible label, required marker, hint, and error. Spread its render-prop binding onto the control so IDs and accessible descriptions stay connected. Hints accept React nodes; an error replaces the hint and marks the control invalid.
613
+ Field owns a control's visible label, required marker, hint, and error. Spread its render-prop binding onto the control so IDs and accessible descriptions stay connected. Hints accept React nodes. An error renders above the hint, which stays so bounds and guidance remain while the value is fixed, and marks the control invalid. Empty hint content (empty strings, whitespace, or fragments and arrays of nothing) renders nothing; a bare `0` is treated as a failed `count && …` condition, so format a numeric hint as text.
614
614
 
615
615
  ```tsx
616
616
  import { ChoiceGroup, Checkbox, Field, TextField } from "@namroodinc/liquid-editorial";
package/UPGRADING.md CHANGED
@@ -2,6 +2,61 @@
2
2
 
3
3
  ## Unreleased
4
4
 
5
+ ## 0.10.1
6
+
7
+ ## 0.10.0
8
+
9
+ ### Breaking changes
10
+
11
+ - Field, FormEditor schema fields and standalone field groups no longer accept
12
+ `labelHint`. Move that content into `hint`, appending it to existing help.
13
+ The `.ds-field__label-hint` and `.ds-field__support` hooks are removed.
14
+ Counter headers stay beside the label.
15
+ - `FormEditor` and `validateFormValues` throw `Field <id> uses the removed
16
+ labelHint; move its content into hint.` for a schema field that still carries
17
+ the key, rather than silently dropping it from JSON or untyped schemas.
18
+ - An error no longer replaces the hint. Field renders the error, then the hint
19
+ below it, and describes the control with both in that order, followed by any
20
+ usage. A control with hint `Keep it concise.` and error `Title is required.`
21
+ is now described as `Title is required. Keep it concise.`, and the hint stays
22
+ in the document. This applies to every Field-based control, group and
23
+ FormEditor field.
24
+
25
+ Smaller changes:
26
+
27
+ - A hint with no visible content (an empty or whitespace-only string, or a
28
+ fragment or array containing only such strings, `null`, `undefined` or
29
+ booleans) renders nothing and adds no description. Previously an empty
30
+ fragment or array rendered an empty `.ds-field__hint` that the control was
31
+ described by.
32
+ - A bare falsy number hint, such as the `0` from `count && …`, still renders
33
+ nothing. `0` inside text, a fragment or an array renders as React renders it.
34
+
35
+ Adoption:
36
+
37
+ 1. Merge `labelHint` into `hint`, in TypeScript and in stored or generated
38
+ schemas. Format numbers as text: `hint={String(minCount)}` or
39
+ `` hint={`min. ${minCount}`} `` keeps a zero, but `hint={minCount}` with
40
+ `minCount === 0` renders nothing. Composing parts such as
41
+ `hint={<>{field.hint} {bounds}</>}` is safe when both are absent.
42
+ 2. Remove local selectors and tests that expect the label-hint slot.
43
+ 3. Update tests that expected an error to hide the hint: assert the error then
44
+ the hint in accessible descriptions, and that the hint stays in the
45
+ document. Remove local styles or copy that repeated bounds in errors only
46
+ because the hint disappeared.
47
+
48
+ Verification:
49
+
50
+ - Load every stored FormEditor schema with the new version, for example through
51
+ `validateFormValues(schema, {})`; none should throw for `labelHint`.
52
+ - For a field with bounds in its hint, enter an invalid value: the error shows
53
+ above the hint, both remain visible, and the control's description reads the
54
+ error then the hint.
55
+ - Check a capped picker's fieldset: its counter stays beside the legend and its
56
+ description ends with the usage after any error and hint.
57
+ - Check a field whose composed hint parts are all absent renders no
58
+ `.ds-field__hint` and has no `aria-describedby` from it.
59
+
5
60
  ## 0.9.0
6
61
 
7
62
  ### Breaking changes
@@ -1,2 +1,2 @@
1
- const e=require("./Icon-WOhlu6Rp.cjs"),t=require("../components/Button/index.cjs"),n=require("./overlayLayer-seJG-EFn.cjs"),r=require("../components/Badge/index.cjs"),i=require("./limit-BNo4dlRj.cjs"),a=require("../components/LimitReading/index.cjs"),o=require("../components/Modal/index.cjs"),s=require("./group-DRSLOsXu.cjs"),c=require("./LoadState-BXLG-SkQ.cjs"),l=require("../components/SearchField/index.cjs"),u=require("../components/Choice/index.cjs"),d=require("../components/SortableList/index.cjs");let f=require("react"),p=require("react/jsx-runtime");function m(e,t,{isDisabled:n,searching:r,atMax:i}){if(n||r)return`inactive`;if(e.isDisabled)return`restricted`;if(!t&&i)return`full`}function h(e,t,n,r){let i=c.n(t,n,r);return t!==`error`&&i.state!==`pending`?null:(0,p.jsx)(c.r,{title:e,error:i.error,onRetry:i.retry,retryState:i.state})}function g({query:e,itemLabel:t,itemsLabel:n,canCreate:r}){let i=e.trim();return(0,p.jsxs)(`div`,{className:`ds-entry-picker__no-results`,children:[(0,p.jsx)(`p`,{children:i?`No ${n} match “${i}”`:`No ${n} yet`}),i&&(0,p.jsxs)(`p`,{children:[`Try a different search.`,r?` Or create the ${t} you need.`:``]})]})}function _(e,t){let r=e.closest(`.ds-entry-picker__scroll`)??e.parentElement,i=Array.from(r?.querySelectorAll(`.ds-entry-picker__result`)??[]);for(let e of[...i.slice(t),...i.slice(0,t).reverse()]){let t=n.h(e)[0];if(t)return t}}function v(e){let t=(0,f.useRef)(null),r=(0,f.useRef)(null),{more:i,offset:a}=e;return(0,f.useEffect)(()=>{let e=r.current,a=t.current;e!==null&&i.status!==`loading`&&(r.current=null,a&&n.d(document.activeElement)&&(i.status===`error`?n.h(a)[0]:_(a,e))?.focus())},[i.status,a]),{pagingRef:t,load:()=>{r.current=t.current?.contains(document.activeElement)?a:null,i.load()}}}function y(e,t){let r=(0,f.useRef)(t);(0,f.useEffect)(()=>{if(r.current===t)return;r.current=t;let i=e.current;i&&n.d(document.activeElement)&&(n.h(i)[0]??_(i,1/0))?.focus()},[e,t])}function b({count:e,total:n,isRemote:r,pageSize:i,remote:a,itemsLabel:o}){let{more:s}=a,{pagingRef:c,load:l}=v(a),u=h(`Couldn't load more ${o}`,s.status,s.error,l);return y(c,u?`failure`:r&&a.hasMore?`more`:`none`),n===0?null:(0,p.jsxs)(`div`,{ref:c,className:`ds-entry-picker__paging`,children:[u??(r&&a.hasMore&&(0,p.jsxs)(t.Button,{isPending:s.status===`loading`,isFocusableWhenDisabled:!0,isDisabled:!s.isAvailable,onClick:l,children:[`Load `,Math.min(i,n-a.offset),` more`]})),(0,p.jsx)(`span`,{children:e<n?`Showing ${e} of ${n}`:`All ${e} shown`})]})}function x(e){return e.isDisabled?e.disabledReason:void 0}function S(e){return e.tone===`removed`}function C(e){return S(e)?void 0:x(e)}function w({item:t,reasonId:n}){let i=x(t);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`span`,{className:`ds-entry__thumb`,children:t.imageUrl?(0,p.jsx)(`img`,{src:t.imageUrl,alt:``,loading:`lazy`}):(0,p.jsx)(e.t,{name:`file-text`,size:20})}),(0,p.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,p.jsx)(`span`,{className:`ds-entry__title`,"data-unavailable":t.isUnavailable||void 0,children:t.title}),t.metadata!=null&&(0,p.jsx)(`span`,{className:`ds-entry__meta`,children:t.metadata}),i&&(0,p.jsxs)(`span`,{id:n,className:`ds-entry__reason`,children:[(0,p.jsx)(r.Badge,{shape:`tag`,size:`sm`,children:i.label}),` `,(0,p.jsx)(`span`,{children:i.description})]})]})]})}function T({item:e,reasonId:t}){return S(e)?(0,p.jsxs)(`span`,{className:`ds-entry__removed`,children:[(0,p.jsx)(`strong`,{children:e.title}),` `,e.metadata??(0,p.jsx)(`code`,{children:e.id})]}):(0,p.jsx)(w,{item:e,reasonId:t})}function E({item:e}){return S(e)?(0,p.jsx)(r.Badge,{shape:`tag`,children:e.removedLabel??`Removed on save`}):null}function D({item:e,onEdit:n,isDisabled:r}){return!n||e.isUnavailable||e.isDisabled?null:(0,p.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`pencil`,"aria-label":`Edit ${e.title}`,isDisabled:r,onClick:()=>n(e)})}function O({items:e,selected:t,block:n,onToggle:r,onEdit:i}){let a=(0,f.useId)(),o=`${a}-full`;return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`span`,{id:o,hidden:!0,children:`The selection is full. Remove one to choose another.`}),(0,p.jsx)(`ul`,{className:`ds-entry-picker__results`,"data-searching":n.searching||void 0,children:e.map((e,s)=>{let c=t.includes(e.id),l=m(e,c,n),d=x(e)?`${a}-reason-${s}`:void 0;return(0,p.jsxs)(`li`,{className:`ds-entry-picker__result`,"data-selected":c||void 0,"data-blocked":l?!0:void 0,onClick:t=>{let n=t.target instanceof Element?t.target.closest(`button, input, label, a, select, textarea, summary, [tabindex]`):null;(!n||!t.currentTarget.contains(n))&&r(e.id)},children:[(0,p.jsx)(u.Checkbox,{checked:c,"aria-checked":c,"aria-label":`Select ${e.title}`,"aria-describedby":l===`full`?o:d,disabled:!!l,isFocusableWhenDisabled:l!==`inactive`,onChange:()=>r(e.id)}),(0,p.jsx)(`span`,{className:`ds-entry`,children:(0,p.jsx)(w,{item:e,reasonId:d})}),(0,p.jsx)(D,{item:e,onEdit:i,isDisabled:l===`inactive`})]},e.id)})})]})}function k(){let e=(0,f.useRef)(null),[t,n]=(0,f.useState)(!1);return{ref:e,scrolled:t,toTop:()=>{n(!1),e.current&&(e.current.scrollTop=0)},onScroll:e=>{n(e.currentTarget.scrollTop>0)}}}function A({isOpen:e,onClose:n,query:r,onQuery:i,selected:s,results:l,cap:u,block:d,isRemote:f,pageSize:m,remote:_,onToggle:v,onEdit:y,itemLabel:x,itemsLabel:S,addLabel:C,onCreate:w,isCreating:T,dialogTitle:E,dialogDescription:D,isDialogHidden:k}){let A=h(`Couldn't refresh ${S}`,_.refresh.status,_.refresh.error,_.refresh.retry);return(0,p.jsx)(o.Modal,{isOpen:e,isHidden:k,onClose:n,title:E??C,description:D??u.description,className:`ds-entry-picker__dialog`,footer:(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`span`,{className:`ds-entry-picker__selection`,role:`status`,children:u.reading?(0,p.jsx)(a.LimitReading,{...u.reading,size:`lg`}):`${s.length} selected`}),(0,p.jsx)(t.Button,{variant:`primary`,onClick:n,children:`Done`})]}),children:(0,p.jsx)(j,{query:r,onQuery:i,itemsLabel:S,isSearching:_.loading,action:w&&(0,p.jsx)(t.Button,{variant:`primary`,isPending:T,isFocusableWhenDisabled:!0,iconStart:`plus`,isDisabled:d.isDisabled||u.atMax,onClick:w,children:`New ${x}`}),banner:A,isBusy:_.loading||_.more.status===`loading`||_.refresh.status===`loading`,children:(0,p.jsxs)(c.t,{status:_.status,errorTitle:`Couldn't load ${S}`,error:_.error,onRetry:_.retry,children:[(0,p.jsx)(O,{items:l,selected:s,block:d,onToggle:v,onEdit:y}),!_.searching&&l.length===0&&(0,p.jsx)(g,{query:r,itemLabel:x,itemsLabel:S,canCreate:!!w}),(0,p.jsx)(b,{count:l.length,total:f?_.total:l.length,isRemote:f,pageSize:m,remote:_,itemsLabel:S})]})})})}function j({query:e,onQuery:t,itemsLabel:n,isSearching:r,action:i,banner:a,isBusy:o,children:s}){let{ref:c,scrolled:u,onScroll:d,toTop:f}=k(),m=e=>{f(),t(e)};return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`ds-entry-picker__search`,"data-scrolled":u||void 0,children:[(0,p.jsx)(l.SearchField,{"aria-label":`Search ${n}`,value:e,isBusy:r,placeholder:`Search ${n}`,onChange:e=>m(e.target.value),onClear:()=>m(``)}),i]}),a&&(0,p.jsx)(`div`,{className:`ds-entry-picker__refresh`,children:a}),(0,p.jsx)(`div`,{className:`ds-entry-picker__scroll`,ref:c,onScroll:d,"aria-busy":o,children:s})]})}function M({items:e,selected:n,onChange:r,onEdit:i,isDisabled:a,canReorder:o,emptyLabel:s}){let c=(0,f.useId)(),l=(e,t)=>C(e)?`${c}-reason-${t}`:void 0,u=(e,o)=>(0,p.jsxs)(`span`,{className:`ds-entry-picker__item-actions`,children:[(0,p.jsx)(E,{item:e}),(0,p.jsx)(D,{item:e,onEdit:e.tone===`removed`?void 0:i,isDisabled:a}),(0,p.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${e.title}`,"aria-describedby":o,isDisabled:a,onClick:()=>r(n.filter(t=>t!==e.id))})]});return e.length===0?(0,p.jsx)(`p`,{className:`ds-entry-picker__empty`,children:s}):o?(0,p.jsx)(d.SortableList,{items:n,onReorder:r,isDisabled:a,children:e.map((e,t)=>(0,p.jsx)(d.SortableListItem,{id:e.id,label:e.title,"data-tone":e.tone,handleDescribedBy:l(e,t),action:u(e,l(e,t)),children:(0,p.jsx)(`div`,{className:`ds-entry`,children:(0,p.jsx)(T,{item:e,reasonId:l(e,t)})})},e.id))}):(0,p.jsx)(`ul`,{className:`ds-entry-picker__list`,children:e.map((e,t)=>(0,p.jsxs)(`li`,{className:`ds-entry-picker__row`,"data-tone":e.tone,children:[(0,p.jsx)(`div`,{className:`ds-entry`,children:(0,p.jsx)(T,{item:e,reasonId:l(e,t)})}),u(e,l(e,t))]},e.id))})}function N(e,t,n){return{id:e,title:t,metadata:n,isUnavailable:!0}}function P({selected:e,items:t,pageItems:n,known:r,failures:i,hasResolver:a,itemLabel:o}){let s=new Map(t.map(e=>[e.id,e])),c=new Map(n.map(e=>[e.id,e]));return e.map(e=>(s.get(e)??(r.has(e)?r.get(e):c.get(e)))||(r.has(e)?N(e,`${`${o.charAt(0).toUpperCase()}${o.slice(1)}`} no longer available`,`Replace or clear this selection.`):a?N(e,i.has(e)?`Couldn't load ${o}`:`Loading…`):{id:e,title:e}))}function F(e,t){return e===`single`||t===1}function I(e,t,n){return F(e,n)?{count:t,max:1,tone:`neutral`}:e===`multiple`&&n!==void 0?{count:t,max:n}:void 0}function L(e,t,n){return F(e,n)?void 0:t}function ee(e,t,n,{itemLabel:r,itemsLabel:a}){let o=I(e,t,n),s=e===`multiple`&&o&&Number.isFinite(o.max)?o.max:void 0,c=`Choose as many ${a} as you need.`;return e===`single`||s===1?c=`Choose one ${r}.`:s!==void 0&&(c=`Choose up to ${s} ${a}.`),{limit:o,atMax:s!==void 0&&t>=s,description:c,reading:e===`multiple`&&i.r(o)?o:void 0}}function R(e){return e instanceof Error?e:null}function z(e,t){if(!t.some(t=>e.has(t)))return e;let n=new Map(e);for(let e of t)n.delete(e);return n}function B(e,t){return e!==t&&(e.length!==t.length||t.some(t=>!e.includes(t)))}function V(e,t,n){let r=e;if(Object.is(r.refreshKey,n)||(r={...r,refreshKey:n,known:new Map,stale:new Map([...r.stale,...r.known]),failures:new Map}),B(r.selected,t)){let e=r.selected.filter(e=>!t.includes(e));r={...r,selected:t,known:z(r.known,e),stale:z(r.stale,e),failures:z(r.failures,e)}}return r}function te(e,t,r,i){let a=n.u(r),o=n.u(e),[s,c]=(0,f.useState)(()=>({refreshKey:i,selected:e,known:new Map,stale:new Map,failures:new Map})),l=V(s,e,i);l!==s&&c(l);let{known:u,stale:d,failures:p}=l,m=(0,f.useMemo)(()=>d.size===0?u:new Map([...d,...u]),[d,u]),h=(e,t,n=o.current)=>{let r=e.filter(e=>e!==void 0&&n.includes(e.id)).map(e=>[e.id,e]);r.length!==0&&c(e=>{if(Object.is(e.refreshKey,t))return{...e,known:new Map([...e.known,...r])};let n=r.filter(([t])=>!e.known.has(t)&&!e.stale.has(t));return n.length===0?e:{...e,stale:new Map([...e.stale,...n])}})},g=new Set(t.map(e=>e.id)),_=r?e.filter(e=>!g.has(e)&&!u.has(e)&&!p.has(e)):[],v=JSON.stringify(_),y=(0,f.useRef)({refreshKey:i,tokens:new Map});(0,f.useEffect)(()=>{let e=a.current;if(!e)return;let t=JSON.parse(v);Object.is(y.current.refreshKey,i)||(y.current={refreshKey:i,tokens:new Map});let{tokens:n}=y.current;for(let e of n.keys())t.includes(e)||n.delete(e);for(let r of t.filter(e=>!n.has(e))){let t=Symbol(r);n.set(r,t);let a=e=>{y.current.tokens.get(r)===t&&(y.current.tokens.delete(r),c(t=>Object.is(t.refreshKey,i)&&t.selected.includes(r)?e(t):t))};Promise.resolve().then(()=>e(r)).then(e=>a(t=>t.known.has(r)?t:{...t,known:new Map(t.known).set(r,e??null)}),e=>a(t=>({...t,failures:new Map(t.failures).set(r,R(e))})))}},[v,i,a]);let b=e.filter(e=>p.has(e)&&!u.has(e));return{known:m,failures:p,remember:h,status:_.length>0?`loading`:b.length>0?`error`:`ready`,error:b.length>0?p.get(b[0])??null:null,retry:()=>c(e=>({...e,failures:z(e.failures,b)}))}}var H=250;function U(e){return Array.from(new Map(e.map(e=>[e.id,e])).values())}var W={items:[],offset:0,total:0},G={...W,key:null,revision:void 0,status:`ready`,error:null};function K(e,t){let n=e?.status===`error`&&t;return{status:e?.status===`loading`?`loading`:n?`error`:`ready`,error:n?e.error??null:null,isAvailable:t}}function q(e,t){return{items:U([...e.items,...t.items]),offset:e.offset+t.items.length,total:t.items.length===0?Math.min(t.total,e.offset):t.total}}function J(e,t,n,r){return e.key!==t||e.offset!==n?e:{...e,...q(e,r)}}async function Y(e,t,n,r,i){let a=Math.max(1,Math.ceil(r/n)),o=await Promise.all(Array.from({length:a},(r,i)=>e({offset:i*n,limit:n},{query:t}))),s=W;for(let[e,t]of o.entries()){if(s.offset!==e*n)break;s=q(s,t)}for(;s.offset<r&&s.offset<s.total&&i();)s=q(s,await e({offset:s.offset,limit:n},{query:t}));return s}function X(e,t,n,r){let i=e!==null&&t.key===e,a=i&&Object.is(t.revision,n),o=e!==null&&!a&&(!i||t.status===`error`),s=o&&t.key!==null&&t.status===`ready`,c=o&&!s?`loading`:t.status===`error`?`error`:`ready`,l=t.status===`ready`&&t.offset<t.total,u=i&&!a&&t.status===`ready`,d=u&&r?.key===e&&Object.is(r.revision,n);return{loading:o,searching:s,status:c,hasMore:l,refresh:u?d?`error`:`loading`:`ready`,refreshFailed:d}}function ne(e,t,r,i,a,o){let s=n.u(e),c=n.u(a),l=n.u(o),[u,d]=(0,f.useState)(0),[p,m]=(0,f.useState)(G),[h,g]=(0,f.useState)(null),[_,v]=(0,f.useState)(null),[y,b]=(0,f.useState)(i);y!==i&&(b(i),i||(m(G),g(null),v(null),d(e=>e+1)));let x=r.trim(),S=e&&i?JSON.stringify([x,t,u]):null,C=n.u(p),w=(0,f.useRef)(null),T=(0,f.useRef)(x),{loading:E,searching:D,status:O,hasMore:k,refresh:A,refreshFailed:j}=X(S,p,o,_),M=!E&&A===`ready`,N=E?`load`:A===`loading`?`refresh`:null;(0,f.useEffect)(()=>{if(S===null)return;let e=N===`load`&&x!==T.current?H:0;if(T.current=x,N===null)return;let n=N===`refresh`?C.current.offset+(w.current?t:0):0,r=!0,i=window.setTimeout(()=>{let e=s.current;e&&Y(e,x,t,n,()=>r).then(e=>{r&&(w.current=null,m({...e,key:S,revision:o,status:`ready`,error:null}),g(null),v(null),c.current(e.items,o))},e=>{r&&(N===`refresh`?v({key:S,revision:o,error:R(e)}):(w.current=null,m({...G,key:S,revision:o,status:`error`,error:R(e)}),g(null)))})},e);return()=>{r=!1,window.clearTimeout(i)}},[S,N,o,x,t,s,c,C]);let P=()=>{let e=s.current,n=p.key,{offset:r}=p;if(!e||n===null||!M||!k||w.current)return;let i=Symbol(`load more`),a=o;w.current=i,g({token:i,status:`loading`,error:null});let u=()=>w.current===i&&C.current.key===n&&C.current.offset===r&&Object.is(l.current,a),d=e=>{w.current===i&&(w.current=null),g(t=>t?.token===i?e:t)};Promise.resolve().then(()=>e({offset:r,limit:t},{query:x})).then(e=>{u()&&(m(t=>J(t,n,r,e)),c.current(e.items,a)),d(null)},e=>d(u()?{token:i,status:`error`,error:R(e)}:null))};return{items:p.items,total:p.total,offset:p.offset,hasMore:k,pageRevision:p.revision,loading:E,searching:D,status:O,error:p.error,retry:()=>d(e=>e+1),more:{...K(h,M),load:P},refresh:{status:A,error:j?_?.error??null:null,retry:()=>v(null)}}}var Z=[];function re(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>[e.title,...e.keywords??[]].join(` `).toLowerCase().includes(n)):e}function Q({items:e=Z,value:n,defaultValue:r=[],onValueChange:i,mode:a=`multiple`,max:o,label:c=`Entries`,emptyLabel:l=`Nothing selected yet.`,addLabel:u=`Choose entries`,itemLabel:d=`entry`,itemsLabel:g=`entries`,isReorderable:_=!0,isDisabled:v=!1,loadPage:y,pageSize:b=10,resolveItem:x,onEditItem:S,onCreate:C,isCreating:w=!1,refreshKey:T,dialogTitle:E,dialogDescription:D,isDialogHidden:O=!1,className:k,...j}){let[N,F]=(0,f.useState)(r),I=n??N,[R,z]=(0,f.useState)(!1),[B,V]=(0,f.useState)(``),H=te(I,e,x,T),U=ne(y,b,B,R,H.remember,T),W=h(`Couldn't load selected ${g}`,H.status,H.error,H.retry),G=!!y,K=(0,f.useMemo)(()=>G?Z:re(e,B),[G,e,B]),q=G?U.items:K,J=ee(a,I.length,o,{itemLabel:d,itemsLabel:g}),Y={isDisabled:v,searching:U.searching,atMax:J.atMax},X=e=>{v||(n===void 0&&F(e),i?.(e))},Q=(e,t)=>{let n=G?U.pageRevision:T;H.remember([t],n,e),X(e)},ie=e=>{let t=q.find(t=>t.id===e);t&&!m(t,I.includes(e),Y)&&(a===`single`?(Q(I[0]===e?[]:[e],t),z(!1)):I.includes(e)?X(I.filter(t=>t!==e)):Q([...I,e],t))},{known:$,failures:ae}=H,oe=!!x,se=(0,f.useMemo)(()=>P({selected:I,items:e,pageItems:U.items,known:$,failures:ae,hasResolver:oe,itemLabel:d}),[I,e,U.items,$,ae,oe,d]),ce=S?e=>{S(e)===!1&&z(!1)}:void 0;return(0,p.jsxs)(s.t,{...j,className:[`ds-entry-picker`,k].filter(Boolean).join(` `),label:c,count:L(a,I.length,o),limit:j.limit===void 0?J.limit:j.limit,children:[(0,p.jsx)(M,{items:se,selected:I,onChange:X,onEdit:ce,isDisabled:v,canReorder:_&&a===`multiple`&&se.length>1,emptyLabel:l}),W,(0,p.jsxs)(`div`,{className:`ds-entry-picker__actions`,children:[(0,p.jsx)(t.Button,{variant:`neutral`,size:`sm`,iconStart:`plus`,isDisabled:v,onClick:()=>z(!0),children:u}),I.length>0&&(0,p.jsx)(t.Button,{variant:`simple`,size:`sm`,isDisabled:v,onClick:()=>X([]),children:`Clear`})]}),(0,p.jsx)(A,{isOpen:R,onClose:()=>z(!1),query:B,onQuery:V,selected:I,results:q,cap:J,block:Y,isRemote:G,pageSize:b,remote:U,onToggle:ie,onEdit:ce,itemLabel:d,itemsLabel:g,addLabel:u,onCreate:C,isCreating:w,dialogTitle:E,dialogDescription:D,isDialogHidden:O})]})}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Q}});
2
- //# sourceMappingURL=EntryPicker-Baqn0SQM.cjs.map
1
+ const e=require("./Icon-WOhlu6Rp.cjs"),t=require("../components/Button/index.cjs"),n=require("./overlayLayer-seJG-EFn.cjs"),r=require("../components/Badge/index.cjs"),i=require("./limit-BNo4dlRj.cjs"),a=require("../components/LimitReading/index.cjs"),o=require("../components/Modal/index.cjs"),s=require("./group-nulIa2_8.cjs"),c=require("./LoadState-BXLG-SkQ.cjs"),l=require("../components/SearchField/index.cjs"),u=require("../components/Choice/index.cjs"),d=require("../components/SortableList/index.cjs");let f=require("react"),p=require("react/jsx-runtime");function m(e,t,{isDisabled:n,searching:r,atMax:i}){if(n||r)return`inactive`;if(e.isDisabled)return`restricted`;if(!t&&i)return`full`}function h(e,t,n,r){let i=c.n(t,n,r);return t!==`error`&&i.state!==`pending`?null:(0,p.jsx)(c.r,{title:e,error:i.error,onRetry:i.retry,retryState:i.state})}function g({query:e,itemLabel:t,itemsLabel:n,canCreate:r}){let i=e.trim();return(0,p.jsxs)(`div`,{className:`ds-entry-picker__no-results`,children:[(0,p.jsx)(`p`,{children:i?`No ${n} match “${i}”`:`No ${n} yet`}),i&&(0,p.jsxs)(`p`,{children:[`Try a different search.`,r?` Or create the ${t} you need.`:``]})]})}function _(e,t){let r=e.closest(`.ds-entry-picker__scroll`)??e.parentElement,i=Array.from(r?.querySelectorAll(`.ds-entry-picker__result`)??[]);for(let e of[...i.slice(t),...i.slice(0,t).reverse()]){let t=n.h(e)[0];if(t)return t}}function v(e){let t=(0,f.useRef)(null),r=(0,f.useRef)(null),{more:i,offset:a}=e;return(0,f.useEffect)(()=>{let e=r.current,a=t.current;e!==null&&i.status!==`loading`&&(r.current=null,a&&n.d(document.activeElement)&&(i.status===`error`?n.h(a)[0]:_(a,e))?.focus())},[i.status,a]),{pagingRef:t,load:()=>{r.current=t.current?.contains(document.activeElement)?a:null,i.load()}}}function y(e,t){let r=(0,f.useRef)(t);(0,f.useEffect)(()=>{if(r.current===t)return;r.current=t;let i=e.current;i&&n.d(document.activeElement)&&(n.h(i)[0]??_(i,1/0))?.focus()},[e,t])}function b({count:e,total:n,isRemote:r,pageSize:i,remote:a,itemsLabel:o}){let{more:s}=a,{pagingRef:c,load:l}=v(a),u=h(`Couldn't load more ${o}`,s.status,s.error,l);return y(c,u?`failure`:r&&a.hasMore?`more`:`none`),n===0?null:(0,p.jsxs)(`div`,{ref:c,className:`ds-entry-picker__paging`,children:[u??(r&&a.hasMore&&(0,p.jsxs)(t.Button,{isPending:s.status===`loading`,isFocusableWhenDisabled:!0,isDisabled:!s.isAvailable,onClick:l,children:[`Load `,Math.min(i,n-a.offset),` more`]})),(0,p.jsx)(`span`,{children:e<n?`Showing ${e} of ${n}`:`All ${e} shown`})]})}function x(e){return e.isDisabled?e.disabledReason:void 0}function S(e){return e.tone===`removed`}function C(e){return S(e)?void 0:x(e)}function w({item:t,reasonId:n}){let i=x(t);return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`span`,{className:`ds-entry__thumb`,children:t.imageUrl?(0,p.jsx)(`img`,{src:t.imageUrl,alt:``,loading:`lazy`}):(0,p.jsx)(e.t,{name:`file-text`,size:20})}),(0,p.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,p.jsx)(`span`,{className:`ds-entry__title`,"data-unavailable":t.isUnavailable||void 0,children:t.title}),t.metadata!=null&&(0,p.jsx)(`span`,{className:`ds-entry__meta`,children:t.metadata}),i&&(0,p.jsxs)(`span`,{id:n,className:`ds-entry__reason`,children:[(0,p.jsx)(r.Badge,{shape:`tag`,size:`sm`,children:i.label}),` `,(0,p.jsx)(`span`,{children:i.description})]})]})]})}function T({item:e,reasonId:t}){return S(e)?(0,p.jsxs)(`span`,{className:`ds-entry__removed`,children:[(0,p.jsx)(`strong`,{children:e.title}),` `,e.metadata??(0,p.jsx)(`code`,{children:e.id})]}):(0,p.jsx)(w,{item:e,reasonId:t})}function E({item:e}){return S(e)?(0,p.jsx)(r.Badge,{shape:`tag`,children:e.removedLabel??`Removed on save`}):null}function D({item:e,onEdit:n,isDisabled:r}){return!n||e.isUnavailable||e.isDisabled?null:(0,p.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`pencil`,"aria-label":`Edit ${e.title}`,isDisabled:r,onClick:()=>n(e)})}function O({items:e,selected:t,block:n,onToggle:r,onEdit:i}){let a=(0,f.useId)(),o=`${a}-full`;return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`span`,{id:o,hidden:!0,children:`The selection is full. Remove one to choose another.`}),(0,p.jsx)(`ul`,{className:`ds-entry-picker__results`,"data-searching":n.searching||void 0,children:e.map((e,s)=>{let c=t.includes(e.id),l=m(e,c,n),d=x(e)?`${a}-reason-${s}`:void 0;return(0,p.jsxs)(`li`,{className:`ds-entry-picker__result`,"data-selected":c||void 0,"data-blocked":l?!0:void 0,onClick:t=>{let n=t.target instanceof Element?t.target.closest(`button, input, label, a, select, textarea, summary, [tabindex]`):null;(!n||!t.currentTarget.contains(n))&&r(e.id)},children:[(0,p.jsx)(u.Checkbox,{checked:c,"aria-checked":c,"aria-label":`Select ${e.title}`,"aria-describedby":l===`full`?o:d,disabled:!!l,isFocusableWhenDisabled:l!==`inactive`,onChange:()=>r(e.id)}),(0,p.jsx)(`span`,{className:`ds-entry`,children:(0,p.jsx)(w,{item:e,reasonId:d})}),(0,p.jsx)(D,{item:e,onEdit:i,isDisabled:l===`inactive`})]},e.id)})})]})}function k(){let e=(0,f.useRef)(null),[t,n]=(0,f.useState)(!1);return{ref:e,scrolled:t,toTop:()=>{n(!1),e.current&&(e.current.scrollTop=0)},onScroll:e=>{n(e.currentTarget.scrollTop>0)}}}function A({isOpen:e,onClose:n,query:r,onQuery:i,selected:s,results:l,cap:u,block:d,isRemote:f,pageSize:m,remote:_,onToggle:v,onEdit:y,itemLabel:x,itemsLabel:S,addLabel:C,onCreate:w,isCreating:T,dialogTitle:E,dialogDescription:D,isDialogHidden:k}){let A=h(`Couldn't refresh ${S}`,_.refresh.status,_.refresh.error,_.refresh.retry);return(0,p.jsx)(o.Modal,{isOpen:e,isHidden:k,onClose:n,title:E??C,description:D??u.description,className:`ds-entry-picker__dialog`,footer:(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(`span`,{className:`ds-entry-picker__selection`,role:`status`,children:u.reading?(0,p.jsx)(a.LimitReading,{...u.reading,size:`lg`}):`${s.length} selected`}),(0,p.jsx)(t.Button,{variant:`primary`,onClick:n,children:`Done`})]}),children:(0,p.jsx)(j,{query:r,onQuery:i,itemsLabel:S,isSearching:_.loading,action:w&&(0,p.jsx)(t.Button,{variant:`primary`,isPending:T,isFocusableWhenDisabled:!0,iconStart:`plus`,isDisabled:d.isDisabled||u.atMax,onClick:w,children:`New ${x}`}),banner:A,isBusy:_.loading||_.more.status===`loading`||_.refresh.status===`loading`,children:(0,p.jsxs)(c.t,{status:_.status,errorTitle:`Couldn't load ${S}`,error:_.error,onRetry:_.retry,children:[(0,p.jsx)(O,{items:l,selected:s,block:d,onToggle:v,onEdit:y}),!_.searching&&l.length===0&&(0,p.jsx)(g,{query:r,itemLabel:x,itemsLabel:S,canCreate:!!w}),(0,p.jsx)(b,{count:l.length,total:f?_.total:l.length,isRemote:f,pageSize:m,remote:_,itemsLabel:S})]})})})}function j({query:e,onQuery:t,itemsLabel:n,isSearching:r,action:i,banner:a,isBusy:o,children:s}){let{ref:c,scrolled:u,onScroll:d,toTop:f}=k(),m=e=>{f(),t(e)};return(0,p.jsxs)(p.Fragment,{children:[(0,p.jsxs)(`div`,{className:`ds-entry-picker__search`,"data-scrolled":u||void 0,children:[(0,p.jsx)(l.SearchField,{"aria-label":`Search ${n}`,value:e,isBusy:r,placeholder:`Search ${n}`,onChange:e=>m(e.target.value),onClear:()=>m(``)}),i]}),a&&(0,p.jsx)(`div`,{className:`ds-entry-picker__refresh`,children:a}),(0,p.jsx)(`div`,{className:`ds-entry-picker__scroll`,ref:c,onScroll:d,"aria-busy":o,children:s})]})}function M({items:e,selected:n,onChange:r,onEdit:i,isDisabled:a,canReorder:o,emptyLabel:s}){let c=(0,f.useId)(),l=(e,t)=>C(e)?`${c}-reason-${t}`:void 0,u=(e,o)=>(0,p.jsxs)(`span`,{className:`ds-entry-picker__item-actions`,children:[(0,p.jsx)(E,{item:e}),(0,p.jsx)(D,{item:e,onEdit:e.tone===`removed`?void 0:i,isDisabled:a}),(0,p.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`x`,"aria-label":`Remove ${e.title}`,"aria-describedby":o,isDisabled:a,onClick:()=>r(n.filter(t=>t!==e.id))})]});return e.length===0?(0,p.jsx)(`p`,{className:`ds-entry-picker__empty`,children:s}):o?(0,p.jsx)(d.SortableList,{items:n,onReorder:r,isDisabled:a,children:e.map((e,t)=>(0,p.jsx)(d.SortableListItem,{id:e.id,label:e.title,"data-tone":e.tone,handleDescribedBy:l(e,t),action:u(e,l(e,t)),children:(0,p.jsx)(`div`,{className:`ds-entry`,children:(0,p.jsx)(T,{item:e,reasonId:l(e,t)})})},e.id))}):(0,p.jsx)(`ul`,{className:`ds-entry-picker__list`,children:e.map((e,t)=>(0,p.jsxs)(`li`,{className:`ds-entry-picker__row`,"data-tone":e.tone,children:[(0,p.jsx)(`div`,{className:`ds-entry`,children:(0,p.jsx)(T,{item:e,reasonId:l(e,t)})}),u(e,l(e,t))]},e.id))})}function N(e,t,n){return{id:e,title:t,metadata:n,isUnavailable:!0}}function P({selected:e,items:t,pageItems:n,known:r,failures:i,hasResolver:a,itemLabel:o}){let s=new Map(t.map(e=>[e.id,e])),c=new Map(n.map(e=>[e.id,e]));return e.map(e=>(s.get(e)??(r.has(e)?r.get(e):c.get(e)))||(r.has(e)?N(e,`${`${o.charAt(0).toUpperCase()}${o.slice(1)}`} no longer available`,`Replace or clear this selection.`):a?N(e,i.has(e)?`Couldn't load ${o}`:`Loading…`):{id:e,title:e}))}function F(e,t){return e===`single`||t===1}function I(e,t,n){return F(e,n)?{count:t,max:1,tone:`neutral`}:e===`multiple`&&n!==void 0?{count:t,max:n}:void 0}function L(e,t,n){return F(e,n)?void 0:t}function ee(e,t,n,{itemLabel:r,itemsLabel:a}){let o=I(e,t,n),s=e===`multiple`&&o&&Number.isFinite(o.max)?o.max:void 0,c=`Choose as many ${a} as you need.`;return e===`single`||s===1?c=`Choose one ${r}.`:s!==void 0&&(c=`Choose up to ${s} ${a}.`),{limit:o,atMax:s!==void 0&&t>=s,description:c,reading:e===`multiple`&&i.r(o)?o:void 0}}function R(e){return e instanceof Error?e:null}function z(e,t){if(!t.some(t=>e.has(t)))return e;let n=new Map(e);for(let e of t)n.delete(e);return n}function B(e,t){return e!==t&&(e.length!==t.length||t.some(t=>!e.includes(t)))}function V(e,t,n){let r=e;if(Object.is(r.refreshKey,n)||(r={...r,refreshKey:n,known:new Map,stale:new Map([...r.stale,...r.known]),failures:new Map}),B(r.selected,t)){let e=r.selected.filter(e=>!t.includes(e));r={...r,selected:t,known:z(r.known,e),stale:z(r.stale,e),failures:z(r.failures,e)}}return r}function te(e,t,r,i){let a=n.u(r),o=n.u(e),[s,c]=(0,f.useState)(()=>({refreshKey:i,selected:e,known:new Map,stale:new Map,failures:new Map})),l=V(s,e,i);l!==s&&c(l);let{known:u,stale:d,failures:p}=l,m=(0,f.useMemo)(()=>d.size===0?u:new Map([...d,...u]),[d,u]),h=(e,t,n=o.current)=>{let r=e.filter(e=>e!==void 0&&n.includes(e.id)).map(e=>[e.id,e]);r.length!==0&&c(e=>{if(Object.is(e.refreshKey,t))return{...e,known:new Map([...e.known,...r])};let n=r.filter(([t])=>!e.known.has(t)&&!e.stale.has(t));return n.length===0?e:{...e,stale:new Map([...e.stale,...n])}})},g=new Set(t.map(e=>e.id)),_=r?e.filter(e=>!g.has(e)&&!u.has(e)&&!p.has(e)):[],v=JSON.stringify(_),y=(0,f.useRef)({refreshKey:i,tokens:new Map});(0,f.useEffect)(()=>{let e=a.current;if(!e)return;let t=JSON.parse(v);Object.is(y.current.refreshKey,i)||(y.current={refreshKey:i,tokens:new Map});let{tokens:n}=y.current;for(let e of n.keys())t.includes(e)||n.delete(e);for(let r of t.filter(e=>!n.has(e))){let t=Symbol(r);n.set(r,t);let a=e=>{y.current.tokens.get(r)===t&&(y.current.tokens.delete(r),c(t=>Object.is(t.refreshKey,i)&&t.selected.includes(r)?e(t):t))};Promise.resolve().then(()=>e(r)).then(e=>a(t=>t.known.has(r)?t:{...t,known:new Map(t.known).set(r,e??null)}),e=>a(t=>({...t,failures:new Map(t.failures).set(r,R(e))})))}},[v,i,a]);let b=e.filter(e=>p.has(e)&&!u.has(e));return{known:m,failures:p,remember:h,status:_.length>0?`loading`:b.length>0?`error`:`ready`,error:b.length>0?p.get(b[0])??null:null,retry:()=>c(e=>({...e,failures:z(e.failures,b)}))}}var H=250;function U(e){return Array.from(new Map(e.map(e=>[e.id,e])).values())}var W={items:[],offset:0,total:0},G={...W,key:null,revision:void 0,status:`ready`,error:null};function K(e,t){let n=e?.status===`error`&&t;return{status:e?.status===`loading`?`loading`:n?`error`:`ready`,error:n?e.error??null:null,isAvailable:t}}function q(e,t){return{items:U([...e.items,...t.items]),offset:e.offset+t.items.length,total:t.items.length===0?Math.min(t.total,e.offset):t.total}}function J(e,t,n,r){return e.key!==t||e.offset!==n?e:{...e,...q(e,r)}}async function Y(e,t,n,r,i){let a=Math.max(1,Math.ceil(r/n)),o=await Promise.all(Array.from({length:a},(r,i)=>e({offset:i*n,limit:n},{query:t}))),s=W;for(let[e,t]of o.entries()){if(s.offset!==e*n)break;s=q(s,t)}for(;s.offset<r&&s.offset<s.total&&i();)s=q(s,await e({offset:s.offset,limit:n},{query:t}));return s}function X(e,t,n,r){let i=e!==null&&t.key===e,a=i&&Object.is(t.revision,n),o=e!==null&&!a&&(!i||t.status===`error`),s=o&&t.key!==null&&t.status===`ready`,c=o&&!s?`loading`:t.status===`error`?`error`:`ready`,l=t.status===`ready`&&t.offset<t.total,u=i&&!a&&t.status===`ready`,d=u&&r?.key===e&&Object.is(r.revision,n);return{loading:o,searching:s,status:c,hasMore:l,refresh:u?d?`error`:`loading`:`ready`,refreshFailed:d}}function ne(e,t,r,i,a,o){let s=n.u(e),c=n.u(a),l=n.u(o),[u,d]=(0,f.useState)(0),[p,m]=(0,f.useState)(G),[h,g]=(0,f.useState)(null),[_,v]=(0,f.useState)(null),[y,b]=(0,f.useState)(i);y!==i&&(b(i),i||(m(G),g(null),v(null),d(e=>e+1)));let x=r.trim(),S=e&&i?JSON.stringify([x,t,u]):null,C=n.u(p),w=(0,f.useRef)(null),T=(0,f.useRef)(x),{loading:E,searching:D,status:O,hasMore:k,refresh:A,refreshFailed:j}=X(S,p,o,_),M=!E&&A===`ready`,N=E?`load`:A===`loading`?`refresh`:null;(0,f.useEffect)(()=>{if(S===null)return;let e=N===`load`&&x!==T.current?H:0;if(T.current=x,N===null)return;let n=N===`refresh`?C.current.offset+(w.current?t:0):0,r=!0,i=window.setTimeout(()=>{let e=s.current;e&&Y(e,x,t,n,()=>r).then(e=>{r&&(w.current=null,m({...e,key:S,revision:o,status:`ready`,error:null}),g(null),v(null),c.current(e.items,o))},e=>{r&&(N===`refresh`?v({key:S,revision:o,error:R(e)}):(w.current=null,m({...G,key:S,revision:o,status:`error`,error:R(e)}),g(null)))})},e);return()=>{r=!1,window.clearTimeout(i)}},[S,N,o,x,t,s,c,C]);let P=()=>{let e=s.current,n=p.key,{offset:r}=p;if(!e||n===null||!M||!k||w.current)return;let i=Symbol(`load more`),a=o;w.current=i,g({token:i,status:`loading`,error:null});let u=()=>w.current===i&&C.current.key===n&&C.current.offset===r&&Object.is(l.current,a),d=e=>{w.current===i&&(w.current=null),g(t=>t?.token===i?e:t)};Promise.resolve().then(()=>e({offset:r,limit:t},{query:x})).then(e=>{u()&&(m(t=>J(t,n,r,e)),c.current(e.items,a)),d(null)},e=>d(u()?{token:i,status:`error`,error:R(e)}:null))};return{items:p.items,total:p.total,offset:p.offset,hasMore:k,pageRevision:p.revision,loading:E,searching:D,status:O,error:p.error,retry:()=>d(e=>e+1),more:{...K(h,M),load:P},refresh:{status:A,error:j?_?.error??null:null,retry:()=>v(null)}}}var Z=[];function re(e,t){let n=t.trim().toLowerCase();return n?e.filter(e=>[e.title,...e.keywords??[]].join(` `).toLowerCase().includes(n)):e}function Q({items:e=Z,value:n,defaultValue:r=[],onValueChange:i,mode:a=`multiple`,max:o,label:c=`Entries`,emptyLabel:l=`Nothing selected yet.`,addLabel:u=`Choose entries`,itemLabel:d=`entry`,itemsLabel:g=`entries`,isReorderable:_=!0,isDisabled:v=!1,loadPage:y,pageSize:b=10,resolveItem:x,onEditItem:S,onCreate:C,isCreating:w=!1,refreshKey:T,dialogTitle:E,dialogDescription:D,isDialogHidden:O=!1,className:k,...j}){let[N,F]=(0,f.useState)(r),I=n??N,[R,z]=(0,f.useState)(!1),[B,V]=(0,f.useState)(``),H=te(I,e,x,T),U=ne(y,b,B,R,H.remember,T),W=h(`Couldn't load selected ${g}`,H.status,H.error,H.retry),G=!!y,K=(0,f.useMemo)(()=>G?Z:re(e,B),[G,e,B]),q=G?U.items:K,J=ee(a,I.length,o,{itemLabel:d,itemsLabel:g}),Y={isDisabled:v,searching:U.searching,atMax:J.atMax},X=e=>{v||(n===void 0&&F(e),i?.(e))},Q=(e,t)=>{let n=G?U.pageRevision:T;H.remember([t],n,e),X(e)},ie=e=>{let t=q.find(t=>t.id===e);t&&!m(t,I.includes(e),Y)&&(a===`single`?(Q(I[0]===e?[]:[e],t),z(!1)):I.includes(e)?X(I.filter(t=>t!==e)):Q([...I,e],t))},{known:$,failures:ae}=H,oe=!!x,se=(0,f.useMemo)(()=>P({selected:I,items:e,pageItems:U.items,known:$,failures:ae,hasResolver:oe,itemLabel:d}),[I,e,U.items,$,ae,oe,d]),ce=S?e=>{S(e)===!1&&z(!1)}:void 0;return(0,p.jsxs)(s.t,{...j,className:[`ds-entry-picker`,k].filter(Boolean).join(` `),label:c,count:L(a,I.length,o),limit:j.limit===void 0?J.limit:j.limit,children:[(0,p.jsx)(M,{items:se,selected:I,onChange:X,onEdit:ce,isDisabled:v,canReorder:_&&a===`multiple`&&se.length>1,emptyLabel:l}),W,(0,p.jsxs)(`div`,{className:`ds-entry-picker__actions`,children:[(0,p.jsx)(t.Button,{variant:`neutral`,size:`sm`,iconStart:`plus`,isDisabled:v,onClick:()=>z(!0),children:u}),I.length>0&&(0,p.jsx)(t.Button,{variant:`simple`,size:`sm`,isDisabled:v,onClick:()=>X([]),children:`Clear`})]}),(0,p.jsx)(A,{isOpen:R,onClose:()=>z(!1),query:B,onQuery:V,selected:I,results:q,cap:J,block:Y,isRemote:G,pageSize:b,remote:U,onToggle:ie,onEdit:ce,itemLabel:d,itemsLabel:g,addLabel:u,onCreate:C,isCreating:w,dialogTitle:E,dialogDescription:D,isDialogHidden:O})]})}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return L}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return Q}});
2
+ //# sourceMappingURL=EntryPicker-BhApdZtE.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntryPicker-Baqn0SQM.cjs","names":["useRetryAttempt","LoadError","tabbableControls","useRef","cannotHoldFocus","Button","_Fragment","Icon","Badge","Button","useId","_Fragment","Checkbox","useRef","useState","Modal","_Fragment","LimitReading","Button","LoadState","SearchField","useId","Button","SortableList","SortableListItem","usableLimit","useLatest","useState","useMemo","useRef","useLatest","useState","useRef","useState","useMemo","FieldGroup","Button","require_Icon","require_components_Button_index","require_overlayLayer","require_components_Badge_index","require_limit","require_components_LimitReading_index","require_components_Modal_index","require_group","require_LoadState","require_components_SearchField_index","require_components_Choice_index","require_components_SortableList_index","react","react_jsx_runtime","resultBlock","isDisabled","searching","item","isSelected","atMax","useLoadError","retry","status","error","onRetry","NoResults","search","query","itemsLabel","canCreate","itemLabel","resultControl","scroll","paging","rows","row","start","control","usePagingFocus","pagingRef","focusFrom","remote","more","offset","useSwapFocus","shown","shows","PickerPaging","failure","load","isRemote","total","pageSize","count","entryReason","isRemovedSelection","selectedReason","EntryRow","reason","reasonId","SelectedEntry","RemovedLabel","EditItemButton","onEdit","PickerResults","id","fullId","block","items","selected","blocked","index","event","onToggle","usePickerScroll","ref","scrolled","setScrolled","PickerDialog","refreshFailure","isDialogHidden","dialogTitle","addLabel","dialogDescription","cap","onClose","PickerFrame","onCreate","isCreating","results","toTop","onQuery","next","isSearching","action","banner","isBusy","SelectedItems","actions","describedBy","onChange","emptyLabel","canReorder","placeholder","chosenItems","staticById","pageById","pageItems","known","hasResolver","failures","selectsOne","mode","max","selectionLimit","selectionCount","pickerCap","limit","description","asError","without","ids","map","changesIds","previous","update","copies","refreshKey","removed","useSelectedItems","resolve","resolveItem","selection","stored","setCopies","stale","remember","seen","revision","gaps","staticIds","unknown","unknownKey","requested","resolveOne","tokens","unseen","token","settle","describe","failed","SEARCH_DELAY_MS","unique","noRows","noPages","moreState","isAvailable","extend","page","appendPage","key","loadRows","target","pages","isCurrent","answered","loading","hasMore","isStale","refreshFailed","usePickerData","loadPage","report","onItems","round","setRound","setPages","setMore","setRefreshFailure","wasOpen","setWasOpen","isOpen","lastSearch","canLoadMore","refresh","plan","delay","timer","loadOne","loadMore","loadMorePage","requestKey","asked","applies","emptyItems","staticMatches","EntryPicker","fieldProps","internal","setInternal","defaultValue","value","setOpen","setQuery","resolutionError","filtered","commit","onValueChange","pick","toggle","result","selectedId","chosen","editItem","onEditItem","className","isReorderable"],"sources":["../../src/components/EntryPicker/blocked.ts","../../src/components/EntryPicker/feedback.tsx","../../src/components/EntryPicker/item.tsx","../../src/components/EntryPicker/results.tsx","../../src/components/EntryPicker/use-picker-scroll.ts","../../src/components/EntryPicker/dialog.tsx","../../src/components/EntryPicker/selected-items.tsx","../../src/components/EntryPicker/chosen.ts","../../src/components/EntryPicker/limit.ts","../../src/components/EntryPicker/use-selected-items.ts","../../src/components/EntryPicker/use-picker-data.ts","../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import type { EntryItem } from \"./types\";\n\nexport interface PickerBlockState {\n /** The whole picker is disabled. */\n isDisabled: boolean;\n /** A new search will replace the rows shown. */\n searching: boolean;\n /** A capped multiple selection is full. */\n atMax: boolean;\n}\n\n/**\n * Why a result can't be toggled now, or undefined when it can. The rows and the\n * picker's own toggle share this rule, so neither can bypass the other.\n *\n * - `\"inactive\"`: the picker can't act at all; its checkboxes are natively disabled.\n * - `\"restricted\"`: the item's own `isDisabled`, explained by its `disabledReason`.\n * - `\"full\"`: the selection has reached its cap.\n *\n * Restricted and full results keep a focusable checkbox, described by why.\n */\nexport function resultBlock(\n item: EntryItem,\n isSelected: boolean,\n { isDisabled, searching, atMax }: PickerBlockState,\n): \"inactive\" | \"restricted\" | \"full\" | undefined {\n if (isDisabled || searching) {\n return \"inactive\";\n }\n if (item.isDisabled) {\n return \"restricted\";\n }\n if (!isSelected && atMax) {\n return \"full\";\n }\n return undefined;\n}\n","import { useEffect, useRef, type RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport { LoadError, type LoadStatus } from \"../LoadState\";\nimport { useRetryAttempt } from \"../LoadState/useRetryAttempt\";\nimport { cannotHoldFocus, tabbableControls } from \"../../internal/dialogFocus\";\nimport type { PickerData } from \"./use-picker-data\";\n\n/** The shared failure banner while a load has failed or its retry runs; null otherwise. */\nexport function useLoadError(\n title: string,\n status: LoadStatus,\n error: Error | null,\n onRetry: () => void,\n) {\n const retry = useRetryAttempt(status, error, onRetry);\n if (status !== \"error\" && retry.state !== \"pending\") {\n return null;\n }\n return (\n <LoadError\n title={title}\n error={retry.error}\n onRetry={retry.retry}\n retryState={retry.state}\n />\n );\n}\n\nexport function NoResults({\n query,\n itemLabel,\n itemsLabel,\n canCreate,\n}: {\n query: string;\n itemLabel: string;\n itemsLabel: string;\n canCreate: boolean;\n}) {\n const search = query.trim();\n return (\n <div className=\"ds-entry-picker__no-results\">\n <p>{search ? `No ${itemsLabel} match “${search}”` : `No ${itemsLabel} yet`}</p>\n {search && (\n <p>Try a different search.{canCreate ? ` Or create the ${itemLabel} you need.` : \"\"}</p>\n )}\n </div>\n );\n}\n\n/** The first control in the result rows from `start`, else the nearest one before it. */\nfunction resultControl(paging: HTMLElement, start: number) {\n const scroll = paging.closest(\".ds-entry-picker__scroll\") ?? paging.parentElement;\n const rows = Array.from(scroll?.querySelectorAll<HTMLElement>(\".ds-entry-picker__result\") ?? []);\n for (const row of [...rows.slice(start), ...rows.slice(0, start).reverse()]) {\n const control = tabbableControls(row)[0];\n if (control) {\n return control;\n }\n }\n return undefined;\n}\n\n/**\n * Load more unmounts when the last page arrives or its request fails, and a\n * failure banner unmounts when its retry succeeds. When the paging held focus\n * and lost it that way, focus moves to the first new row, or to Try again.\n */\nfunction usePagingFocus(remote: PickerData) {\n const pagingRef = useRef<HTMLDivElement | null>(null);\n const focusFrom = useRef<number | null>(null);\n const { more, offset } = remote;\n const load = () => {\n focusFrom.current = pagingRef.current?.contains(document.activeElement) ? offset : null;\n more.load();\n };\n useEffect(() => {\n const start = focusFrom.current;\n const paging = pagingRef.current;\n if (start === null || more.status === \"loading\") {\n return;\n }\n focusFrom.current = null;\n if (paging && cannotHoldFocus(document.activeElement)) {\n const target =\n more.status === \"error\" ? tabbableControls(paging)[0] : resultControl(paging, start);\n target?.focus();\n }\n }, [more.status, offset]);\n return { pagingRef, load };\n}\n\n/**\n * A search or refresh also swaps the paging's control without the paging\n * asking: it hides a failed Load more, and the rows it brings hide the banner\n * or end paging. When that drops focus, focus moves to the control that\n * replaced it, else to the last row.\n */\nfunction useSwapFocus(\n pagingRef: RefObject<HTMLDivElement | null>,\n shows: \"failure\" | \"more\" | \"none\",\n) {\n const shown = useRef(shows);\n useEffect(() => {\n if (shown.current === shows) {\n return;\n }\n shown.current = shows;\n const paging = pagingRef.current;\n if (paging && cannotHoldFocus(document.activeElement)) {\n (tabbableControls(paging)[0] ?? resultControl(paging, Infinity))?.focus();\n }\n }, [pagingRef, shows]);\n}\n\n/** How much is shown, and for server results a Load more action with its own failure. */\nexport function PickerPaging({\n count,\n total,\n isRemote,\n pageSize,\n remote,\n itemsLabel,\n}: {\n count: number;\n total: number;\n isRemote: boolean;\n pageSize: number;\n remote: PickerData;\n itemsLabel: string;\n}) {\n const { more } = remote;\n const { pagingRef, load } = usePagingFocus(remote);\n const failure = useLoadError(`Couldn't load more ${itemsLabel}`, more.status, more.error, load);\n useSwapFocus(pagingRef, failure ? \"failure\" : isRemote && remote.hasMore ? \"more\" : \"none\");\n if (total === 0) {\n return null;\n }\n return (\n <div\n ref={pagingRef}\n className=\"ds-entry-picker__paging\"\n >\n {failure ??\n (isRemote && remote.hasMore && (\n <Button\n isPending={more.status === \"loading\"}\n isFocusableWhenDisabled\n isDisabled={!more.isAvailable}\n onClick={load}\n >\n Load {Math.min(pageSize, total - remote.offset)} more\n </Button>\n ))}\n <span>{count < total ? `Showing ${count} of ${total}` : `All ${count} shown`}</span>\n </div>\n );\n}\n","import { Button } from \"../Button\";\nimport { Badge } from \"../Badge\";\nimport { Icon } from \"../Icon\";\nimport type { EntryItem } from \"./types\";\n\n/**\n * The reason an item's row shows, which also describes the row's controls:\n * its own `disabledReason` while `isDisabled`. Rows and their `aria-describedby`\n * both read it, so a description never points at a reason that isn't shown.\n */\nexport function entryReason(item: EntryItem) {\n return item.isDisabled ? item.disabledReason : undefined;\n}\n\n/** A removed selection shows compactly, without thumbnail, pencil or reason. */\nfunction isRemovedSelection(item: EntryItem) {\n return item.tone === \"removed\";\n}\n\n/** The reason a selected row shows ({@link SelectedEntry}). */\nexport function selectedReason(item: EntryItem) {\n return isRemovedSelection(item) ? undefined : entryReason(item);\n}\n\n/** Thumbnail, title, app metadata and any restriction on the item. */\nexport function EntryRow({ item, reasonId }: { item: EntryItem; reasonId?: string }) {\n const reason = entryReason(item);\n return (\n <>\n <span className=\"ds-entry__thumb\">\n {item.imageUrl ? (\n <img\n src={item.imageUrl}\n alt=\"\"\n loading=\"lazy\"\n />\n ) : (\n <Icon\n name=\"file-text\"\n size={20}\n />\n )}\n </span>\n <span className=\"ds-entry__body\">\n <span\n className=\"ds-entry__title\"\n data-unavailable={item.isUnavailable || undefined}\n >\n {item.title}\n </span>\n {item.metadata != null && <span className=\"ds-entry__meta\">{item.metadata}</span>}\n {reason && (\n <span\n id={reasonId}\n className=\"ds-entry__reason\"\n >\n <Badge\n shape=\"tag\"\n size=\"sm\"\n >\n {reason.label}\n </Badge>{\" \"}\n <span>{reason.description}</span>\n </span>\n )}\n </span>\n </>\n );\n}\n\n/** A selected row: a removed record shows compactly, by title and metadata or ID. */\nexport function SelectedEntry({ item, reasonId }: { item: EntryItem; reasonId?: string }) {\n if (isRemovedSelection(item)) {\n return (\n <span className=\"ds-entry__removed\">\n <strong>{item.title}</strong> {item.metadata ?? <code>{item.id}</code>}\n </span>\n );\n }\n return (\n <EntryRow\n item={item}\n reasonId={reasonId}\n />\n );\n}\n\nexport function RemovedLabel({ item }: { item: EntryItem }) {\n return isRemovedSelection(item) ? (\n <Badge shape=\"tag\">{item.removedLabel ?? \"Removed on save\"}</Badge>\n ) : null;\n}\n\nexport function EditItemButton({\n item,\n onEdit,\n isDisabled,\n}: {\n item: EntryItem;\n onEdit?: (item: EntryItem) => void;\n isDisabled?: boolean;\n}) {\n if (!onEdit || item.isUnavailable || item.isDisabled) {\n return null;\n }\n return (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"pencil\"\n aria-label={`Edit ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => onEdit(item)}\n />\n );\n}\n","import { useId } from \"react\";\nimport { Checkbox } from \"../Choice\";\nimport { resultBlock, type PickerBlockState } from \"./blocked\";\nimport { EditItemButton, EntryRow, entryReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function PickerResults({\n items,\n selected,\n block,\n onToggle,\n onEdit,\n}: {\n items: EntryItem[];\n selected: string[];\n block: PickerBlockState;\n onToggle: (id: string) => void;\n onEdit?: (item: EntryItem) => void;\n}) {\n const id = useId();\n const fullId = `${id}-full`;\n return (\n <>\n {/* Describes results refused only because the selection is full. */}\n <span\n id={fullId}\n hidden\n >\n The selection is full. Remove one to choose another.\n </span>\n <ul\n className=\"ds-entry-picker__results\"\n data-searching={block.searching || undefined}\n >\n {items.map((item, index) => {\n const isSelected = selected.includes(item.id);\n const blocked = resultBlock(item, isSelected, block);\n const reasonId = entryReason(item) ? `${id}-reason-${index}` : undefined;\n return (\n <li\n key={item.id}\n className=\"ds-entry-picker__result\"\n data-selected={isSelected || undefined}\n data-blocked={blocked ? true : undefined}\n onClick={(event) => {\n const control =\n event.target instanceof Element\n ? event.target.closest(\n \"button, input, label, a, select, textarea, summary, [tabindex]\",\n )\n : null;\n // The picker's toggle refuses blocked results.\n if (!control || !event.currentTarget.contains(control)) {\n onToggle(item.id);\n }\n }}\n >\n <Checkbox\n checked={isSelected}\n aria-checked={isSelected}\n aria-label={`Select ${item.title}`}\n aria-describedby={blocked === \"full\" ? fullId : reasonId}\n disabled={Boolean(blocked)}\n isFocusableWhenDisabled={blocked !== \"inactive\"}\n onChange={() => onToggle(item.id)}\n />\n <span className=\"ds-entry\">\n <EntryRow\n item={item}\n reasonId={reasonId}\n />\n </span>\n <EditItemButton\n item={item}\n onEdit={onEdit}\n isDisabled={blocked === \"inactive\"}\n />\n </li>\n );\n })}\n </ul>\n </>\n );\n}\n","import { useRef, useState, type UIEvent } from \"react\";\n\n/**\n * The picker's results pane. Suspended dialogs stay laid out, so the browser\n * keeps the pane's position and nothing here restores it. Only a new search\n * moves the pane: `toTop` runs in the same event as the query change, so both\n * render once. Scrolling rerenders only when the pane reaches or leaves the top.\n */\nexport function usePickerScroll() {\n const ref = useRef<HTMLDivElement>(null);\n const [scrolled, setScrolled] = useState(false);\n return {\n ref,\n scrolled,\n toTop: () => {\n setScrolled(false);\n if (ref.current) {\n ref.current.scrollTop = 0;\n }\n },\n onScroll: (event: UIEvent<HTMLDivElement>) => {\n setScrolled(event.currentTarget.scrollTop > 0);\n },\n };\n}\n","import type { ReactNode } from \"react\";\nimport { Button } from \"../Button\";\nimport { LoadState } from \"../LoadState\";\nimport { LimitReading } from \"../LimitReading\";\nimport { Modal } from \"../Modal\";\nimport { SearchField } from \"../SearchField\";\nimport type { PickerBlockState } from \"./blocked\";\nimport { NoResults, PickerPaging, useLoadError } from \"./feedback\";\nimport type { PickerCap } from \"./limit\";\nimport { PickerResults } from \"./results\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport { usePickerScroll } from \"./use-picker-scroll\";\nimport type { PickerData } from \"./use-picker-data\";\ntype DialogProps = Pick<\n EntryPickerProps,\n \"onCreate\" | \"isCreating\" | \"dialogTitle\" | \"dialogDescription\" | \"isDialogHidden\"\n> & {\n itemLabel: string;\n itemsLabel: string;\n addLabel: string;\n isOpen: boolean;\n onClose: () => void;\n query: string;\n onQuery: (query: string) => void;\n selected: string[];\n results: EntryItem[];\n /** The picker's own cap, which its Field's counter may override. */\n cap: PickerCap;\n block: PickerBlockState;\n isRemote: boolean;\n pageSize: number;\n remote: PickerData;\n onToggle: (id: string) => void;\n onEdit?: (item: EntryItem) => void;\n};\nexport function PickerDialog({\n isOpen,\n onClose,\n query,\n onQuery,\n selected,\n results,\n cap,\n block,\n isRemote,\n pageSize,\n remote,\n onToggle,\n onEdit,\n itemLabel,\n itemsLabel,\n addLabel,\n onCreate,\n isCreating,\n dialogTitle,\n dialogDescription,\n isDialogHidden,\n}: DialogProps) {\n // The rows stay usable after a failed refresh; this offers to read them again.\n const refreshFailure = useLoadError(\n `Couldn't refresh ${itemsLabel}`,\n remote.refresh.status,\n remote.refresh.error,\n remote.refresh.retry,\n );\n return (\n <Modal\n isOpen={isOpen}\n isHidden={isDialogHidden}\n onClose={onClose}\n title={dialogTitle ?? addLabel}\n description={dialogDescription ?? cap.description}\n className=\"ds-entry-picker__dialog\"\n footer={\n <>\n <span\n className=\"ds-entry-picker__selection\"\n role=\"status\"\n >\n {cap.reading ? (\n <LimitReading\n {...cap.reading}\n size=\"lg\"\n />\n ) : (\n `${selected.length} selected`\n )}\n </span>\n <Button\n variant=\"primary\"\n onClick={onClose}\n >\n Done\n </Button>\n </>\n }\n >\n <PickerFrame\n query={query}\n onQuery={onQuery}\n itemsLabel={itemsLabel}\n isSearching={remote.loading}\n action={\n onCreate && (\n // Primary beside Done: Button's one recorded exception (decision 0086).\n // Focusable while blocked, so creation that ends at the cap keeps focus here.\n <Button\n variant=\"primary\"\n isPending={isCreating}\n isFocusableWhenDisabled\n iconStart=\"plus\"\n isDisabled={block.isDisabled || cap.atMax}\n onClick={onCreate}\n >\n {`New ${itemLabel}`}\n </Button>\n )\n }\n banner={refreshFailure}\n isBusy={\n remote.loading || remote.more.status === \"loading\" || remote.refresh.status === \"loading\"\n }\n >\n <LoadState\n status={remote.status}\n errorTitle={`Couldn't load ${itemsLabel}`}\n error={remote.error}\n onRetry={remote.retry}\n >\n <PickerResults\n items={results}\n selected={selected}\n block={block}\n onToggle={onToggle}\n onEdit={onEdit}\n />\n {!remote.searching && results.length === 0 && (\n <NoResults\n query={query}\n itemLabel={itemLabel}\n itemsLabel={itemsLabel}\n canCreate={Boolean(onCreate)}\n />\n )}\n <PickerPaging\n count={results.length}\n total={isRemote ? remote.total : results.length}\n isRemote={isRemote}\n pageSize={pageSize}\n remote={remote}\n itemsLabel={itemsLabel}\n />\n </LoadState>\n </PickerFrame>\n </Modal>\n );\n}\n\n/**\n * The search row, an optional banner and the scrolling results. Rendered inside\n * the Modal, so it mounts with each opening and starts at the top. A new search\n * returns to the top in the same event that changes the query, so both render\n * once.\n */\nfunction PickerFrame({\n query,\n onQuery,\n itemsLabel,\n isSearching,\n action,\n banner,\n isBusy,\n children,\n}: {\n query: string;\n onQuery: (query: string) => void;\n itemsLabel: string;\n isSearching: boolean;\n action: ReactNode;\n banner: ReactNode;\n isBusy: boolean;\n children: ReactNode;\n}) {\n const { ref, scrolled, onScroll, toTop } = usePickerScroll();\n const search = (next: string) => {\n toTop();\n onQuery(next);\n };\n return (\n <>\n <div\n className=\"ds-entry-picker__search\"\n data-scrolled={scrolled || undefined}\n >\n <SearchField\n aria-label={`Search ${itemsLabel}`}\n value={query}\n isBusy={isSearching}\n placeholder={`Search ${itemsLabel}`}\n onChange={(event) => search(event.target.value)}\n onClear={() => search(\"\")}\n />\n {action}\n </div>\n {banner && <div className=\"ds-entry-picker__refresh\">{banner}</div>}\n <div\n className=\"ds-entry-picker__scroll\"\n ref={ref}\n onScroll={onScroll}\n aria-busy={isBusy}\n >\n {children}\n </div>\n </>\n );\n}\n","import { useId } from \"react\";\nimport { Button } from \"../Button\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport { EditItemButton, RemovedLabel, SelectedEntry, selectedReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function SelectedItems({\n items,\n selected,\n onChange,\n onEdit,\n isDisabled,\n canReorder,\n emptyLabel,\n}: {\n items: EntryItem[];\n selected: string[];\n onChange: (ids: string[]) => void;\n onEdit?: (item: EntryItem) => void;\n isDisabled: boolean;\n canReorder: boolean;\n emptyLabel: string;\n}) {\n const id = useId();\n // A restricted selection's reason describes the row's Move, Edit and Remove controls.\n const reasonId = (item: EntryItem, index: number) =>\n selectedReason(item) ? `${id}-reason-${index}` : undefined;\n const actions = (item: EntryItem, describedBy: string | undefined) => (\n <span className=\"ds-entry-picker__item-actions\">\n <RemovedLabel item={item} />\n {/* A removed record has nothing left to edit. */}\n <EditItemButton\n item={item}\n onEdit={item.tone === \"removed\" ? undefined : onEdit}\n isDisabled={isDisabled}\n />\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n aria-describedby={describedBy}\n isDisabled={isDisabled}\n onClick={() => onChange(selected.filter((id) => id !== item.id))}\n />\n </span>\n );\n if (items.length === 0) {\n return <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>;\n }\n if (canReorder) {\n return (\n <SortableList\n items={selected}\n onReorder={onChange}\n isDisabled={isDisabled}\n >\n {items.map((item, index) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n data-tone={item.tone}\n handleDescribedBy={reasonId(item, index)}\n action={actions(item, reasonId(item, index))}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n </SortableListItem>\n ))}\n </SortableList>\n );\n }\n return (\n <ul className=\"ds-entry-picker__list\">\n {items.map((item, index) => (\n <li\n key={item.id}\n className=\"ds-entry-picker__row\"\n data-tone={item.tone}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n {actions(item, reasonId(item, index))}\n </li>\n ))}\n </ul>\n );\n}\n","import type { EntryItem } from \"./types\";\n\nfunction placeholder(id: string, title: string, metadata?: string): EntryItem {\n return { id, title, metadata, isUnavailable: true };\n}\n\n/**\n * The selected rows, in stored order. Static items come first, then the latest\n * known copy, then the current page. Without `resolveItem` an ID nothing\n * describes shows as itself: not knowing an item isn't the same as it being gone.\n */\nexport function chosenItems({\n selected,\n items,\n pageItems,\n known,\n failures,\n hasResolver,\n itemLabel,\n}: {\n selected: string[];\n items: EntryItem[];\n pageItems: EntryItem[];\n known: Map<string, EntryItem | null>;\n failures: Map<string, unknown>;\n hasResolver: boolean;\n itemLabel: string;\n}): EntryItem[] {\n const staticById = new Map(items.map((item) => [item.id, item]));\n const pageById = new Map(pageItems.map((item) => [item.id, item]));\n return selected.map((id) => {\n const item = staticById.get(id) ?? (known.has(id) ? known.get(id) : pageById.get(id));\n if (item) {\n return item;\n }\n if (known.has(id)) {\n const name = `${itemLabel.charAt(0).toUpperCase()}${itemLabel.slice(1)}`;\n return placeholder(id, `${name} no longer available`, \"Replace or clear this selection.\");\n }\n if (!hasResolver) {\n return { id, title: id };\n }\n return placeholder(id, failures.has(id) ? `Couldn't load ${itemLabel}` : \"Loading…\");\n });\n}\n","import type { FieldLimit } from \"../Field/types\";\nimport { usableLimit } from \"../LimitReading/limit\";\nimport type { EntryPickerMode } from \".\";\n\n/** A single selection, or a multiple one capped at one, holds one item. */\nfunction selectsOne(mode: EntryPickerMode, max: number | undefined) {\n return mode === \"single\" || max === 1;\n}\n\n/**\n * The selection's usage limit. A one-item selection is a slot to fill, read\n * neutrally; otherwise only an explicitly capped multiple selection has one.\n * Pure, so FormEditor's model derives the same server-rendered limit the\n * picker reports.\n */\nexport function selectionLimit(\n mode: EntryPickerMode,\n count: number,\n max: number | undefined,\n): FieldLimit | undefined {\n if (selectsOne(mode, max)) {\n return { count, max: 1, tone: \"neutral\" };\n }\n return mode === \"multiple\" && max !== undefined ? { count, max } : undefined;\n}\n\n/** The Field's count badge, which a one-item slot's own reading replaces. */\nexport function selectionCount(mode: EntryPickerMode, count: number, max: number | undefined) {\n return selectsOne(mode, max) ? undefined : count;\n}\n\nexport interface PickerCap {\n /** The Field counter's limit, as FormEditor's model derives it. */\n limit: FieldLimit | undefined;\n /** The selection has reached an enforced cap. */\n atMax: boolean;\n /** The dialog's default description. */\n description: string;\n /** The footer's LimitReading, when the limit reads as usage. */\n reading: FieldLimit | undefined;\n}\n\n/**\n * Everything the picker derives from its mode and max, so the cap is decided\n * in one place: only a finite max in multiple mode is enforced and described.\n * Infinity and NaN never fill, so they read as no limit.\n */\nexport function pickerCap(\n mode: EntryPickerMode,\n count: number,\n max: number | undefined,\n { itemLabel, itemsLabel }: { itemLabel: string; itemsLabel: string },\n): PickerCap {\n const limit = selectionLimit(mode, count, max);\n // Single mode replaces its one selection, so only a multiple cap blocks rows.\n const cap = mode === \"multiple\" && limit && Number.isFinite(limit.max) ? limit.max : undefined;\n let description = `Choose as many ${itemsLabel} as you need.`;\n if (mode === \"single\" || cap === 1) {\n description = `Choose one ${itemLabel}.`;\n } else if (cap !== undefined) {\n description = `Choose up to ${cap} ${itemsLabel}.`;\n }\n return {\n limit,\n atMax: cap !== undefined && count >= cap,\n description,\n // Single mode closes on its first pick, so its footer keeps the plain count.\n reading: mode === \"multiple\" && usableLimit(limit) ? limit : undefined,\n };\n}\n","import { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { LoadStatus } from \"../LoadState\";\nimport { useLatest } from \"../../internal/useLatest\";\nimport type { EntryItem, EntryPickerSource } from \"./types\";\n\ntype RefreshKey = EntryPickerSource[\"refreshKey\"];\n\nexport function asError(failure: unknown) {\n return failure instanceof Error ? failure : null;\n}\n\n/** The map without `ids`, or the same map when it holds none of them. */\nfunction without<V>(map: Map<string, V>, ids: string[]) {\n if (!ids.some((id) => map.has(id))) {\n return map;\n }\n const next = new Map(map);\n for (const id of ids) {\n next.delete(id);\n }\n return next;\n}\n\n/** What the picker knows about the selected IDs beyond its static items. */\ninterface Copies {\n /** The refresh that `known` and `failures` describe. */\n refreshKey: RefreshKey;\n /** The selected IDs the maps describe, in any order. */\n selected: string[];\n /** The copy a page, a pick or `resolveItem` supplied since the last refresh; null: unavailable. */\n known: Map<string, EntryItem | null>;\n /** Copies from before the last refresh, shown until a fresh copy replaces them. */\n stale: Map<string, EntryItem | null>;\n failures: Map<string, Error | null>;\n}\n\n/** Whether `next` adds or removes an ID. A reorder changes nothing the maps describe. */\nfunction changesIds(previous: string[], next: string[]) {\n return (\n previous !== next &&\n (previous.length !== next.length || next.some((id) => !previous.includes(id)))\n );\n}\n\n/**\n * A refresh makes every copy stale and clears failures, so each ID is described\n * again. Removing an ID forgets it, so a restored ID (an undo or a form reset)\n * is described afresh. Picks remembered before a controlled value catches up\n * are kept: they were never removed.\n */\nfunction update(copies: Copies, selected: string[], refreshKey: RefreshKey): Copies {\n let next = copies;\n if (!Object.is(next.refreshKey, refreshKey)) {\n next = {\n ...next,\n refreshKey,\n known: new Map(),\n stale: new Map([...next.stale, ...next.known]),\n failures: new Map(),\n };\n }\n if (changesIds(next.selected, selected)) {\n const removed = next.selected.filter((id) => !selected.includes(id));\n next = {\n ...next,\n selected,\n known: without(next.known, removed),\n stale: without(next.stale, removed),\n failures: without(next.failures, removed),\n };\n }\n return next;\n}\n\n/**\n * The latest copy of each selected item. Only IDs without a copy since the last\n * refresh are resolved, once each, and a retry re-resolves just the failed\n * ones. A stale copy stays on screen until its fresh one arrives, so a refresh\n * never blanks a row. A reply for an ID removed, described or refreshed since\n * it was requested is dropped.\n */\nexport function useSelectedItems(\n selected: string[],\n items: EntryItem[],\n resolveItem: EntryPickerSource[\"resolveItem\"],\n refreshKey?: RefreshKey,\n) {\n const resolve = useLatest(resolveItem);\n const selection = useLatest(selected);\n const [stored, setCopies] = useState<Copies>(() => ({\n refreshKey,\n selected,\n known: new Map(),\n stale: new Map(),\n failures: new Map(),\n }));\n const copies = update(stored, selected, refreshKey);\n if (copies !== stored) {\n setCopies(copies);\n }\n const { known, stale, failures } = copies;\n const shown = useMemo(\n () => (stale.size === 0 ? known : new Map([...stale, ...known])),\n [stale, known],\n );\n\n /**\n * Keep the latest copy of selected items a page or a pick shows, so edits\n * appear. A copy read at `revision`, before the latest refresh, is no fresher\n * than the stale copies: it only fills a gap among them, so a pick from older\n * rows keeps its title and actions while it is described again.\n */\n const remember = (\n seen: (EntryItem | undefined)[],\n revision: RefreshKey,\n ids = selection.current,\n ) => {\n const copies = seen\n .filter((item): item is EntryItem => item !== undefined && ids.includes(item.id))\n .map((item) => [item.id, item] as const);\n if (copies.length === 0) {\n return;\n }\n setCopies((previous) => {\n if (Object.is(previous.refreshKey, revision)) {\n return { ...previous, known: new Map([...previous.known, ...copies]) };\n }\n const gaps = copies.filter(([id]) => !previous.known.has(id) && !previous.stale.has(id));\n return gaps.length === 0\n ? previous\n : { ...previous, stale: new Map([...previous.stale, ...gaps]) };\n });\n };\n\n const staticIds = new Set(items.map((item) => item.id));\n const unknown = resolveItem\n ? selected.filter((id) => !staticIds.has(id) && !known.has(id) && !failures.has(id))\n : [];\n const unknownKey = JSON.stringify(unknown);\n /** Lookups in flight for the current refresh, by ID. */\n const requested = useRef({ refreshKey, tokens: new Map<string, symbol>() });\n useEffect(() => {\n const resolveOne = resolve.current;\n if (!resolveOne) {\n return;\n }\n const ids = JSON.parse(unknownKey) as string[];\n if (!Object.is(requested.current.refreshKey, refreshKey)) {\n requested.current = { refreshKey, tokens: new Map() };\n }\n const { tokens } = requested.current;\n // A lookup for an ID since described or removed no longer counts.\n for (const id of tokens.keys()) {\n if (!ids.includes(id)) {\n tokens.delete(id);\n }\n }\n for (const id of ids.filter((unseen) => !tokens.has(unseen))) {\n const token = Symbol(id);\n tokens.set(id, token);\n const settle = (describe: (previous: Copies) => Copies) => {\n if (requested.current.tokens.get(id) !== token) {\n return;\n }\n requested.current.tokens.delete(id);\n setCopies((previous) =>\n Object.is(previous.refreshKey, refreshKey) && previous.selected.includes(id)\n ? describe(previous)\n : previous,\n );\n };\n void Promise.resolve()\n .then(() => resolveOne(id))\n .then(\n // A page or pick that arrived meanwhile is at least as fresh.\n (item) =>\n settle((previous) =>\n previous.known.has(id)\n ? previous\n : { ...previous, known: new Map(previous.known).set(id, item ?? null) },\n ),\n (failure: unknown) =>\n settle((previous) => ({\n ...previous,\n failures: new Map(previous.failures).set(id, asError(failure)),\n })),\n );\n }\n }, [unknownKey, refreshKey, resolve]);\n\n const failed = selected.filter((id) => failures.has(id) && !known.has(id));\n const status: LoadStatus = unknown.length > 0 ? \"loading\" : failed.length > 0 ? \"error\" : \"ready\";\n return {\n known: shown,\n failures,\n remember,\n status,\n error: failed.length > 0 ? (failures.get(failed[0]) ?? null) : null,\n retry: () =>\n setCopies((previous) => ({ ...previous, failures: without(previous.failures, failed) })),\n };\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { LoadStatus } from \"../LoadState\";\nimport { useLatest } from \"../../internal/useLatest\";\nimport { asError } from \"./use-selected-items\";\nimport type { EntryItem, EntryPickerPage, EntryPickerSource } from \"./types\";\n\nconst SEARCH_DELAY_MS = 250;\n\ntype LoadPage = NonNullable<EntryPickerSource[\"loadPage\"]>;\ntype RefreshKey = EntryPickerSource[\"refreshKey\"];\n\nfunction unique(items: EntryItem[]) {\n return Array.from(new Map(items.map((item) => [item.id, item])).values());\n}\n\n/** Rows read from the start of a result list. */\ninterface Rows {\n items: EntryItem[];\n /** The next server offset; a duplicate row still advances it. */\n offset: number;\n total: number;\n}\nconst noRows: Rows = { items: [], offset: 0, total: 0 };\n\ninterface Pages extends Rows {\n /** The request these rows answer; null until an open dialog's first reply. */\n key: string | null;\n /** The `refreshKey` they were read at. */\n revision: RefreshKey;\n status: \"ready\" | \"error\";\n error: Error | null;\n}\nconst noPages: Pages = { ...noRows, key: null, revision: undefined, status: \"ready\", error: null };\n\ninterface MoreRequest {\n token: symbol;\n status: \"loading\" | \"error\";\n error: Error | null;\n}\n\n/**\n * What Load more reports for the shown rows. Paging extends only current rows,\n * so it waits while a search or refresh replaces them, and a failed Load more,\n * which belongs to the rows it extended, is no longer reported meanwhile. One in\n * flight stays loading: a refresh folds it in.\n */\nfunction moreState(more: MoreRequest | null, isAvailable: boolean) {\n const failed = more?.status === \"error\" && isAvailable;\n const status: LoadStatus = more?.status === \"loading\" ? \"loading\" : failed ? \"error\" : \"ready\";\n return { status, error: failed ? (more.error ?? null) : null, isAvailable };\n}\n\n/** A background refresh that failed, leaving the rows read at an earlier revision. */\ninterface RefreshFailure {\n key: string;\n revision: RefreshKey;\n error: Error | null;\n}\n\n/** The rows after `page`, which was requested at their offset. */\nfunction extend(rows: Rows, page: EntryPickerPage): Rows {\n return {\n items: unique([...rows.items, ...page.items]),\n offset: rows.offset + page.items.length,\n // An empty page ends paging even when the total overcounted.\n total: page.items.length === 0 ? Math.min(page.total, rows.offset) : page.total,\n };\n}\n\n/** Append a further page, unless a newer search or page replaced the rows meanwhile. */\nfunction appendPage(previous: Pages, key: string, offset: number, page: EntryPickerPage): Pages {\n if (previous.key !== key || previous.offset !== offset) {\n return previous;\n }\n return { ...previous, ...extend(previous, page) };\n}\n\n/**\n * At least one page, and at least the first `target` rows. Full pages are\n * requested together; a short page before the end moves every later offset, so\n * the rest is read one page at a time from where it stopped.\n */\nasync function loadRows(\n load: LoadPage,\n query: string,\n limit: number,\n target: number,\n isCurrent: () => boolean,\n) {\n const count = Math.max(1, Math.ceil(target / limit));\n const pages = await Promise.all(\n Array.from({ length: count }, (_, index) => load({ offset: index * limit, limit }, { query })),\n );\n let rows = noRows;\n for (const [index, page] of pages.entries()) {\n if (rows.offset !== index * limit) {\n break;\n }\n rows = extend(rows, page);\n }\n while (rows.offset < target && rows.offset < rows.total && isCurrent()) {\n rows = extend(rows, await load({ offset: rows.offset, limit }, { query }));\n }\n return rows;\n}\n\n/** What the shown rows mean for the request, at the revision, the picker wants answered. */\nfunction describe(\n key: string | null,\n pages: Pages,\n refreshKey: RefreshKey,\n failure: RefreshFailure | null,\n) {\n const answered = key !== null && pages.key === key;\n const isCurrent = answered && Object.is(pages.revision, refreshKey);\n // A new request, or a failed one whose source has since changed.\n const loading = key !== null && !isCurrent && (!answered || pages.status === \"error\");\n // Rows from the previous search stay, dimmed, until the new search answers.\n const searching = loading && pages.key !== null && pages.status === \"ready\";\n const status: LoadStatus =\n loading && !searching ? \"loading\" : pages.status === \"error\" ? \"error\" : \"ready\";\n const hasMore = pages.status === \"ready\" && pages.offset < pages.total;\n // Rows read before a refresh stay usable while they are read again.\n const isStale = answered && !isCurrent && pages.status === \"ready\";\n const refreshFailed = isStale && failure?.key === key && Object.is(failure.revision, refreshKey);\n const refresh: LoadStatus = isStale ? (refreshFailed ? \"error\" : \"loading\") : \"ready\";\n return { loading, searching, status, hasMore, refresh, refreshFailed };\n}\n\n/**\n * Server pages for an open picker. Opening, a new search, a page size or a\n * retry requests the first page; an older reply never overwrites a newer one.\n * Closing discards the pages and starts a new round, so the next opening reads\n * the source afresh and no reply from an earlier opening, Load more included,\n * matches it. A new `refreshKey` reads the shown rows again in the background;\n * they stay usable meanwhile, and stay on screen if that fails. `loadPage` is\n * read when called, so an inline callback never reloads.\n */\nexport function usePickerData(\n loadPage: EntryPickerSource[\"loadPage\"],\n pageSize: number,\n query: string,\n isOpen: boolean,\n onItems: (items: EntryItem[], revision: RefreshKey) => void,\n refreshKey?: RefreshKey,\n) {\n const load = useLatest(loadPage);\n const report = useLatest(onItems);\n const revision = useLatest(refreshKey);\n // Each retry and each closing starts a new round of requests.\n const [round, setRound] = useState(0);\n const [pages, setPages] = useState(noPages);\n const [more, setMore] = useState<MoreRequest | null>(null);\n const [refreshFailure, setRefreshFailure] = useState<RefreshFailure | null>(null);\n const [wasOpen, setWasOpen] = useState(isOpen);\n if (wasOpen !== isOpen) {\n setWasOpen(isOpen);\n if (!isOpen) {\n setPages(noPages);\n setMore(null);\n setRefreshFailure(null);\n setRound((count) => count + 1);\n }\n }\n const search = query.trim();\n const key = loadPage && isOpen ? JSON.stringify([search, pageSize, round]) : null;\n const shown = useLatest(pages);\n // The Load more request in flight; replacing the rows makes it obsolete.\n const paging = useRef<symbol | null>(null);\n const lastSearch = useRef(search);\n const { loading, searching, status, hasMore, refresh, refreshFailed } = describe(\n key,\n pages,\n refreshKey,\n refreshFailure,\n );\n // A new search or a refresh would page at an old offset.\n const canLoadMore = !loading && refresh === \"ready\";\n const plan = loading ? \"load\" : refresh === \"loading\" ? \"refresh\" : null;\n\n useEffect(() => {\n if (key === null) {\n return;\n }\n const delay = plan === \"load\" && search !== lastSearch.current ? SEARCH_DELAY_MS : 0;\n lastSearch.current = search;\n if (plan === null) {\n return;\n }\n // A Load more in flight joins the refreshed rows instead of appending to the old ones.\n const target = plan === \"refresh\" ? shown.current.offset + (paging.current ? pageSize : 0) : 0;\n let isCurrent = true;\n const timer = window.setTimeout(() => {\n const loadOne = load.current;\n if (!loadOne) {\n return;\n }\n void loadRows(loadOne, search, pageSize, target, () => isCurrent).then(\n (rows) => {\n if (isCurrent) {\n paging.current = null;\n setPages({ ...rows, key, revision: refreshKey, status: \"ready\", error: null });\n setMore(null);\n setRefreshFailure(null);\n report.current(rows.items, refreshKey);\n }\n },\n (failure: unknown) => {\n if (!isCurrent) {\n return;\n }\n if (plan === \"refresh\") {\n setRefreshFailure({ key, revision: refreshKey, error: asError(failure) });\n return;\n }\n // A failed search drops the previous rows, so none stay selectable or pageable.\n paging.current = null;\n setPages({\n ...noPages,\n key,\n revision: refreshKey,\n status: \"error\",\n error: asError(failure),\n });\n setMore(null);\n },\n );\n }, delay);\n return () => {\n isCurrent = false;\n window.clearTimeout(timer);\n };\n }, [key, plan, refreshKey, search, pageSize, load, report, shown]);\n\n const loadMore = () => {\n const loadMorePage = load.current;\n const requestKey = pages.key;\n const { offset } = pages;\n if (!loadMorePage || requestKey === null || !canLoadMore) {\n return;\n }\n if (!hasMore || paging.current) {\n return;\n }\n const token = Symbol(\"load more\");\n const asked = refreshKey;\n paging.current = token;\n setMore({ token, status: \"loading\", error: null });\n // A reply counts only while it extends the rows on screen and no refresh began since.\n const applies = () =>\n paging.current === token &&\n shown.current.key === requestKey &&\n shown.current.offset === offset &&\n Object.is(revision.current, asked);\n const settle = (next: MoreRequest | null) => {\n if (paging.current === token) {\n paging.current = null;\n }\n setMore((previous) => (previous?.token === token ? next : previous));\n };\n void Promise.resolve()\n .then(() => loadMorePage({ offset, limit: pageSize }, { query: search }))\n .then(\n (page) => {\n if (applies()) {\n setPages((previous) => appendPage(previous, requestKey, offset, page));\n report.current(page.items, asked);\n }\n settle(null);\n },\n (failure: unknown) =>\n settle(applies() ? { token, status: \"error\", error: asError(failure) } : null),\n );\n };\n\n return {\n items: pages.items,\n total: pages.total,\n offset: pages.offset,\n hasMore,\n /** The `refreshKey` the shown rows were read at. */\n pageRevision: pages.revision,\n loading,\n searching,\n status,\n error: pages.error,\n retry: () => setRound((count) => count + 1),\n /** `isAvailable` is false while a search or refresh replaces the rows; `load` then does nothing. */\n more: { ...moreState(more, canLoadMore), load: loadMore },\n refresh: {\n status: refresh,\n error: refreshFailed ? (refreshFailure?.error ?? null) : null,\n retry: () => setRefreshFailure(null),\n },\n };\n}\n\nexport type PickerData = ReturnType<typeof usePickerData>;\n","import { useMemo, useState } from \"react\";\nimport { FieldGroup } from \"../Field/group\";\nimport { Button } from \"../Button\";\nimport { resultBlock } from \"./blocked\";\nimport { PickerDialog } from \"./dialog\";\nimport { SelectedItems } from \"./selected-items\";\nimport { chosenItems } from \"./chosen\";\nimport { useLoadError } from \"./feedback\";\nimport { pickerCap, selectionCount } from \"./limit\";\nimport { usePickerData } from \"./use-picker-data\";\nimport { useSelectedItems } from \"./use-selected-items\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport \"./style.css\";\n\nexport type {\n EntryItem,\n EntryPickerMode,\n EntryPickerProps,\n EntryPickerSource,\n EntryPickerPage,\n EntryPickerPageRequest,\n} from \"./types\";\nconst emptyItems: EntryItem[] = [];\n/** Static choices whose title or keywords contain the trimmed query, as server searches trim it. */\nfunction staticMatches(items: EntryItem[], query: string) {\n const search = query.trim().toLowerCase();\n if (!search) {\n return items;\n }\n return items.filter((item) =>\n [item.title, ...(item.keywords ?? [])].join(\" \").toLowerCase().includes(search),\n );\n}\n\n/** Static or server-paged choices, with ordered selections and optional editing actions. */\nexport function EntryPicker({\n items = emptyItems,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n itemLabel = \"entry\",\n itemsLabel = \"entries\",\n isReorderable = true,\n isDisabled = false,\n loadPage,\n pageSize = 10,\n resolveItem,\n onEditItem,\n onCreate,\n isCreating = false,\n refreshKey,\n dialogTitle,\n dialogDescription,\n isDialogHidden = false,\n className,\n ...fieldProps\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n const selection = useSelectedItems(selected, items, resolveItem, refreshKey);\n const remote = usePickerData(loadPage, pageSize, query, isOpen, selection.remember, refreshKey);\n const resolutionError = useLoadError(\n `Couldn't load selected ${itemsLabel}`,\n selection.status,\n selection.error,\n selection.retry,\n );\n const isRemote = Boolean(loadPage);\n const filtered = useMemo(\n () => (isRemote ? emptyItems : staticMatches(items, query)),\n [isRemote, items, query],\n );\n const results = isRemote ? remote.items : filtered;\n const cap = pickerCap(mode, selected.length, max, { itemLabel, itemsLabel });\n const block = { isDisabled, searching: remote.searching, atMax: cap.atMax };\n const commit = (next: string[]) => {\n if (isDisabled) {\n return;\n }\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const pick = (next: string[], item: EntryItem) => {\n // The picked row describes the selection after the search moves on. A row\n // read before the latest refresh stays a stale copy, described again.\n const revision = isRemote ? remote.pageRevision : refreshKey;\n selection.remember([item], revision, next);\n commit(next);\n };\n // The one place selection rules are enforced, whichever control asked.\n const toggle = (id: string) => {\n const item = results.find((result) => result.id === id);\n if (!item || resultBlock(item, selected.includes(id), block)) {\n return;\n }\n if (mode === \"single\") {\n pick(selected[0] === id ? [] : [id], item);\n setOpen(false);\n } else if (selected.includes(id)) {\n commit(selected.filter((selectedId) => selectedId !== id));\n } else {\n pick([...selected, id], item);\n }\n };\n const { known, failures } = selection;\n const hasResolver = Boolean(resolveItem);\n const chosen = useMemo(\n () =>\n chosenItems({\n selected,\n items,\n pageItems: remote.items,\n known,\n failures,\n hasResolver,\n itemLabel,\n }),\n [selected, items, remote.items, known, failures, hasResolver, itemLabel],\n );\n const editItem = onEditItem\n ? (item: EntryItem) => {\n if (onEditItem(item) === false) {\n setOpen(false);\n }\n }\n : undefined;\n return (\n <FieldGroup\n {...fieldProps}\n className={[\"ds-entry-picker\", className].filter(Boolean).join(\" \")}\n label={label}\n count={selectionCount(mode, selected.length, max)}\n limit={fieldProps.limit === undefined ? cap.limit : fieldProps.limit}\n >\n <SelectedItems\n items={chosen}\n selected={selected}\n onChange={commit}\n onEdit={editItem}\n isDisabled={isDisabled}\n canReorder={isReorderable && mode === \"multiple\" && chosen.length > 1}\n emptyLabel={emptyLabel}\n />\n {resolutionError}\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => commit([])}\n >\n Clear\n </Button>\n )}\n </div>\n <PickerDialog\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n query={query}\n onQuery={setQuery}\n selected={selected}\n results={results}\n cap={cap}\n block={block}\n isRemote={isRemote}\n pageSize={pageSize}\n remote={remote}\n onToggle={toggle}\n onEdit={editItem}\n itemLabel={itemLabel}\n itemsLabel={itemsLabel}\n addLabel={addLabel}\n onCreate={onCreate}\n isCreating={isCreating}\n dialogTitle={dialogTitle}\n dialogDescription={dialogDescription}\n isDialogHidden={isDialogHidden}\n />\n </FieldGroup>\n );\n}\n"],"mappings":"A,mjBAqBA,SAAgBmD,EACd,EACA,EACA,CAAE,aAAY,YAAW,SACuB,CAChD,GAAIC,GAAcC,EAChB,MAAO,WAET,GAAIC,EAAK,WACP,MAAO,aAET,GAAI,CAACC,GAAcC,EACjB,MAAO,MAGX,CC5BA,SAAgBC,EACd,EACA,EACA,EACA,EACA,CACA,IAAMC,EAAQ1D,EAAAA,EAAgB2D,EAAQC,EAAOC,CAAO,EAIpD,OAHIF,IAAW,SAAWD,EAAM,QAAU,UACjC,MAGP,EAAAR,EAAA,IAAA,CAACjD,EAAAA,EAAD,CACS,QACP,MAAOyD,EAAM,MACb,QAASA,EAAM,MACf,WAAYA,EAAM,KACnB,CAAA,CAEL,CAEA,SAAgBI,EAAU,CACxB,QACA,YACA,aACA,aAMC,CACD,IAAMC,EAASC,EAAM,KAAK,EAC1B,OACE,EAAAd,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,8BAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,IAAD,CAAA,SAAIa,EAAS,MA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,CAACiE,EAAD,CACU,SACR,YAAe4H,EAAQ,EAAK,EACrB,QACP,QAASC,EACC,WACD,UACJ,MACE,QACG,WACA,WACF,SACR,SAAUM,GACV,OAAQI,GACG,YACC,aACF,WACA,WACE,aACC,cACM,oBACH,gBACjB,CAAA,CACS,C,EAEhB,C"}
1
+ {"version":3,"file":"EntryPicker-BhApdZtE.cjs","names":["useRetryAttempt","LoadError","tabbableControls","useRef","cannotHoldFocus","Button","_Fragment","Icon","Badge","Button","useId","_Fragment","Checkbox","useRef","useState","Modal","_Fragment","LimitReading","Button","LoadState","SearchField","useId","Button","SortableList","SortableListItem","usableLimit","useLatest","useState","useMemo","useRef","useLatest","useState","useRef","useState","useMemo","FieldGroup","Button","require_Icon","require_components_Button_index","require_overlayLayer","require_components_Badge_index","require_limit","require_components_LimitReading_index","require_components_Modal_index","require_group","require_LoadState","require_components_SearchField_index","require_components_Choice_index","require_components_SortableList_index","react","react_jsx_runtime","resultBlock","isDisabled","searching","item","isSelected","atMax","useLoadError","retry","status","error","onRetry","NoResults","search","query","itemsLabel","canCreate","itemLabel","resultControl","scroll","paging","rows","row","start","control","usePagingFocus","pagingRef","focusFrom","remote","more","offset","useSwapFocus","shown","shows","PickerPaging","failure","load","isRemote","total","pageSize","count","entryReason","isRemovedSelection","selectedReason","EntryRow","reason","reasonId","SelectedEntry","RemovedLabel","EditItemButton","onEdit","PickerResults","id","fullId","block","items","selected","blocked","index","event","onToggle","usePickerScroll","ref","scrolled","setScrolled","PickerDialog","refreshFailure","isDialogHidden","dialogTitle","addLabel","dialogDescription","cap","onClose","PickerFrame","onCreate","isCreating","results","toTop","onQuery","next","isSearching","action","banner","isBusy","SelectedItems","actions","describedBy","onChange","emptyLabel","canReorder","placeholder","chosenItems","staticById","pageById","pageItems","known","hasResolver","failures","selectsOne","mode","max","selectionLimit","selectionCount","pickerCap","limit","description","asError","without","ids","map","changesIds","previous","update","copies","refreshKey","removed","useSelectedItems","resolve","resolveItem","selection","stored","setCopies","stale","remember","seen","revision","gaps","staticIds","unknown","unknownKey","requested","resolveOne","tokens","unseen","token","settle","describe","failed","SEARCH_DELAY_MS","unique","noRows","noPages","moreState","isAvailable","extend","page","appendPage","key","loadRows","target","pages","isCurrent","answered","loading","hasMore","isStale","refreshFailed","usePickerData","loadPage","report","onItems","round","setRound","setPages","setMore","setRefreshFailure","wasOpen","setWasOpen","isOpen","lastSearch","canLoadMore","refresh","plan","delay","timer","loadOne","loadMore","loadMorePage","requestKey","asked","applies","emptyItems","staticMatches","EntryPicker","fieldProps","internal","setInternal","defaultValue","value","setOpen","setQuery","resolutionError","filtered","commit","onValueChange","pick","toggle","result","selectedId","chosen","editItem","onEditItem","className","isReorderable"],"sources":["../../src/components/EntryPicker/blocked.ts","../../src/components/EntryPicker/feedback.tsx","../../src/components/EntryPicker/item.tsx","../../src/components/EntryPicker/results.tsx","../../src/components/EntryPicker/use-picker-scroll.ts","../../src/components/EntryPicker/dialog.tsx","../../src/components/EntryPicker/selected-items.tsx","../../src/components/EntryPicker/chosen.ts","../../src/components/EntryPicker/limit.ts","../../src/components/EntryPicker/use-selected-items.ts","../../src/components/EntryPicker/use-picker-data.ts","../../src/components/EntryPicker/index.tsx"],"sourcesContent":["import type { EntryItem } from \"./types\";\n\nexport interface PickerBlockState {\n /** The whole picker is disabled. */\n isDisabled: boolean;\n /** A new search will replace the rows shown. */\n searching: boolean;\n /** A capped multiple selection is full. */\n atMax: boolean;\n}\n\n/**\n * Why a result can't be toggled now, or undefined when it can. The rows and the\n * picker's own toggle share this rule, so neither can bypass the other.\n *\n * - `\"inactive\"`: the picker can't act at all; its checkboxes are natively disabled.\n * - `\"restricted\"`: the item's own `isDisabled`, explained by its `disabledReason`.\n * - `\"full\"`: the selection has reached its cap.\n *\n * Restricted and full results keep a focusable checkbox, described by why.\n */\nexport function resultBlock(\n item: EntryItem,\n isSelected: boolean,\n { isDisabled, searching, atMax }: PickerBlockState,\n): \"inactive\" | \"restricted\" | \"full\" | undefined {\n if (isDisabled || searching) {\n return \"inactive\";\n }\n if (item.isDisabled) {\n return \"restricted\";\n }\n if (!isSelected && atMax) {\n return \"full\";\n }\n return undefined;\n}\n","import { useEffect, useRef, type RefObject } from \"react\";\nimport { Button } from \"../Button\";\nimport { LoadError, type LoadStatus } from \"../LoadState\";\nimport { useRetryAttempt } from \"../LoadState/useRetryAttempt\";\nimport { cannotHoldFocus, tabbableControls } from \"../../internal/dialogFocus\";\nimport type { PickerData } from \"./use-picker-data\";\n\n/** The shared failure banner while a load has failed or its retry runs; null otherwise. */\nexport function useLoadError(\n title: string,\n status: LoadStatus,\n error: Error | null,\n onRetry: () => void,\n) {\n const retry = useRetryAttempt(status, error, onRetry);\n if (status !== \"error\" && retry.state !== \"pending\") {\n return null;\n }\n return (\n <LoadError\n title={title}\n error={retry.error}\n onRetry={retry.retry}\n retryState={retry.state}\n />\n );\n}\n\nexport function NoResults({\n query,\n itemLabel,\n itemsLabel,\n canCreate,\n}: {\n query: string;\n itemLabel: string;\n itemsLabel: string;\n canCreate: boolean;\n}) {\n const search = query.trim();\n return (\n <div className=\"ds-entry-picker__no-results\">\n <p>{search ? `No ${itemsLabel} match “${search}”` : `No ${itemsLabel} yet`}</p>\n {search && (\n <p>Try a different search.{canCreate ? ` Or create the ${itemLabel} you need.` : \"\"}</p>\n )}\n </div>\n );\n}\n\n/** The first control in the result rows from `start`, else the nearest one before it. */\nfunction resultControl(paging: HTMLElement, start: number) {\n const scroll = paging.closest(\".ds-entry-picker__scroll\") ?? paging.parentElement;\n const rows = Array.from(scroll?.querySelectorAll<HTMLElement>(\".ds-entry-picker__result\") ?? []);\n for (const row of [...rows.slice(start), ...rows.slice(0, start).reverse()]) {\n const control = tabbableControls(row)[0];\n if (control) {\n return control;\n }\n }\n return undefined;\n}\n\n/**\n * Load more unmounts when the last page arrives or its request fails, and a\n * failure banner unmounts when its retry succeeds. When the paging held focus\n * and lost it that way, focus moves to the first new row, or to Try again.\n */\nfunction usePagingFocus(remote: PickerData) {\n const pagingRef = useRef<HTMLDivElement | null>(null);\n const focusFrom = useRef<number | null>(null);\n const { more, offset } = remote;\n const load = () => {\n focusFrom.current = pagingRef.current?.contains(document.activeElement) ? offset : null;\n more.load();\n };\n useEffect(() => {\n const start = focusFrom.current;\n const paging = pagingRef.current;\n if (start === null || more.status === \"loading\") {\n return;\n }\n focusFrom.current = null;\n if (paging && cannotHoldFocus(document.activeElement)) {\n const target =\n more.status === \"error\" ? tabbableControls(paging)[0] : resultControl(paging, start);\n target?.focus();\n }\n }, [more.status, offset]);\n return { pagingRef, load };\n}\n\n/**\n * A search or refresh also swaps the paging's control without the paging\n * asking: it hides a failed Load more, and the rows it brings hide the banner\n * or end paging. When that drops focus, focus moves to the control that\n * replaced it, else to the last row.\n */\nfunction useSwapFocus(\n pagingRef: RefObject<HTMLDivElement | null>,\n shows: \"failure\" | \"more\" | \"none\",\n) {\n const shown = useRef(shows);\n useEffect(() => {\n if (shown.current === shows) {\n return;\n }\n shown.current = shows;\n const paging = pagingRef.current;\n if (paging && cannotHoldFocus(document.activeElement)) {\n (tabbableControls(paging)[0] ?? resultControl(paging, Infinity))?.focus();\n }\n }, [pagingRef, shows]);\n}\n\n/** How much is shown, and for server results a Load more action with its own failure. */\nexport function PickerPaging({\n count,\n total,\n isRemote,\n pageSize,\n remote,\n itemsLabel,\n}: {\n count: number;\n total: number;\n isRemote: boolean;\n pageSize: number;\n remote: PickerData;\n itemsLabel: string;\n}) {\n const { more } = remote;\n const { pagingRef, load } = usePagingFocus(remote);\n const failure = useLoadError(`Couldn't load more ${itemsLabel}`, more.status, more.error, load);\n useSwapFocus(pagingRef, failure ? \"failure\" : isRemote && remote.hasMore ? \"more\" : \"none\");\n if (total === 0) {\n return null;\n }\n return (\n <div\n ref={pagingRef}\n className=\"ds-entry-picker__paging\"\n >\n {failure ??\n (isRemote && remote.hasMore && (\n <Button\n isPending={more.status === \"loading\"}\n isFocusableWhenDisabled\n isDisabled={!more.isAvailable}\n onClick={load}\n >\n Load {Math.min(pageSize, total - remote.offset)} more\n </Button>\n ))}\n <span>{count < total ? `Showing ${count} of ${total}` : `All ${count} shown`}</span>\n </div>\n );\n}\n","import { Button } from \"../Button\";\nimport { Badge } from \"../Badge\";\nimport { Icon } from \"../Icon\";\nimport type { EntryItem } from \"./types\";\n\n/**\n * The reason an item's row shows, which also describes the row's controls:\n * its own `disabledReason` while `isDisabled`. Rows and their `aria-describedby`\n * both read it, so a description never points at a reason that isn't shown.\n */\nexport function entryReason(item: EntryItem) {\n return item.isDisabled ? item.disabledReason : undefined;\n}\n\n/** A removed selection shows compactly, without thumbnail, pencil or reason. */\nfunction isRemovedSelection(item: EntryItem) {\n return item.tone === \"removed\";\n}\n\n/** The reason a selected row shows ({@link SelectedEntry}). */\nexport function selectedReason(item: EntryItem) {\n return isRemovedSelection(item) ? undefined : entryReason(item);\n}\n\n/** Thumbnail, title, app metadata and any restriction on the item. */\nexport function EntryRow({ item, reasonId }: { item: EntryItem; reasonId?: string }) {\n const reason = entryReason(item);\n return (\n <>\n <span className=\"ds-entry__thumb\">\n {item.imageUrl ? (\n <img\n src={item.imageUrl}\n alt=\"\"\n loading=\"lazy\"\n />\n ) : (\n <Icon\n name=\"file-text\"\n size={20}\n />\n )}\n </span>\n <span className=\"ds-entry__body\">\n <span\n className=\"ds-entry__title\"\n data-unavailable={item.isUnavailable || undefined}\n >\n {item.title}\n </span>\n {item.metadata != null && <span className=\"ds-entry__meta\">{item.metadata}</span>}\n {reason && (\n <span\n id={reasonId}\n className=\"ds-entry__reason\"\n >\n <Badge\n shape=\"tag\"\n size=\"sm\"\n >\n {reason.label}\n </Badge>{\" \"}\n <span>{reason.description}</span>\n </span>\n )}\n </span>\n </>\n );\n}\n\n/** A selected row: a removed record shows compactly, by title and metadata or ID. */\nexport function SelectedEntry({ item, reasonId }: { item: EntryItem; reasonId?: string }) {\n if (isRemovedSelection(item)) {\n return (\n <span className=\"ds-entry__removed\">\n <strong>{item.title}</strong> {item.metadata ?? <code>{item.id}</code>}\n </span>\n );\n }\n return (\n <EntryRow\n item={item}\n reasonId={reasonId}\n />\n );\n}\n\nexport function RemovedLabel({ item }: { item: EntryItem }) {\n return isRemovedSelection(item) ? (\n <Badge shape=\"tag\">{item.removedLabel ?? \"Removed on save\"}</Badge>\n ) : null;\n}\n\nexport function EditItemButton({\n item,\n onEdit,\n isDisabled,\n}: {\n item: EntryItem;\n onEdit?: (item: EntryItem) => void;\n isDisabled?: boolean;\n}) {\n if (!onEdit || item.isUnavailable || item.isDisabled) {\n return null;\n }\n return (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"pencil\"\n aria-label={`Edit ${item.title}`}\n isDisabled={isDisabled}\n onClick={() => onEdit(item)}\n />\n );\n}\n","import { useId } from \"react\";\nimport { Checkbox } from \"../Choice\";\nimport { resultBlock, type PickerBlockState } from \"./blocked\";\nimport { EditItemButton, EntryRow, entryReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function PickerResults({\n items,\n selected,\n block,\n onToggle,\n onEdit,\n}: {\n items: EntryItem[];\n selected: string[];\n block: PickerBlockState;\n onToggle: (id: string) => void;\n onEdit?: (item: EntryItem) => void;\n}) {\n const id = useId();\n const fullId = `${id}-full`;\n return (\n <>\n {/* Describes results refused only because the selection is full. */}\n <span\n id={fullId}\n hidden\n >\n The selection is full. Remove one to choose another.\n </span>\n <ul\n className=\"ds-entry-picker__results\"\n data-searching={block.searching || undefined}\n >\n {items.map((item, index) => {\n const isSelected = selected.includes(item.id);\n const blocked = resultBlock(item, isSelected, block);\n const reasonId = entryReason(item) ? `${id}-reason-${index}` : undefined;\n return (\n <li\n key={item.id}\n className=\"ds-entry-picker__result\"\n data-selected={isSelected || undefined}\n data-blocked={blocked ? true : undefined}\n onClick={(event) => {\n const control =\n event.target instanceof Element\n ? event.target.closest(\n \"button, input, label, a, select, textarea, summary, [tabindex]\",\n )\n : null;\n // The picker's toggle refuses blocked results.\n if (!control || !event.currentTarget.contains(control)) {\n onToggle(item.id);\n }\n }}\n >\n <Checkbox\n checked={isSelected}\n aria-checked={isSelected}\n aria-label={`Select ${item.title}`}\n aria-describedby={blocked === \"full\" ? fullId : reasonId}\n disabled={Boolean(blocked)}\n isFocusableWhenDisabled={blocked !== \"inactive\"}\n onChange={() => onToggle(item.id)}\n />\n <span className=\"ds-entry\">\n <EntryRow\n item={item}\n reasonId={reasonId}\n />\n </span>\n <EditItemButton\n item={item}\n onEdit={onEdit}\n isDisabled={blocked === \"inactive\"}\n />\n </li>\n );\n })}\n </ul>\n </>\n );\n}\n","import { useRef, useState, type UIEvent } from \"react\";\n\n/**\n * The picker's results pane. Suspended dialogs stay laid out, so the browser\n * keeps the pane's position and nothing here restores it. Only a new search\n * moves the pane: `toTop` runs in the same event as the query change, so both\n * render once. Scrolling rerenders only when the pane reaches or leaves the top.\n */\nexport function usePickerScroll() {\n const ref = useRef<HTMLDivElement>(null);\n const [scrolled, setScrolled] = useState(false);\n return {\n ref,\n scrolled,\n toTop: () => {\n setScrolled(false);\n if (ref.current) {\n ref.current.scrollTop = 0;\n }\n },\n onScroll: (event: UIEvent<HTMLDivElement>) => {\n setScrolled(event.currentTarget.scrollTop > 0);\n },\n };\n}\n","import type { ReactNode } from \"react\";\nimport { Button } from \"../Button\";\nimport { LoadState } from \"../LoadState\";\nimport { LimitReading } from \"../LimitReading\";\nimport { Modal } from \"../Modal\";\nimport { SearchField } from \"../SearchField\";\nimport type { PickerBlockState } from \"./blocked\";\nimport { NoResults, PickerPaging, useLoadError } from \"./feedback\";\nimport type { PickerCap } from \"./limit\";\nimport { PickerResults } from \"./results\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport { usePickerScroll } from \"./use-picker-scroll\";\nimport type { PickerData } from \"./use-picker-data\";\ntype DialogProps = Pick<\n EntryPickerProps,\n \"onCreate\" | \"isCreating\" | \"dialogTitle\" | \"dialogDescription\" | \"isDialogHidden\"\n> & {\n itemLabel: string;\n itemsLabel: string;\n addLabel: string;\n isOpen: boolean;\n onClose: () => void;\n query: string;\n onQuery: (query: string) => void;\n selected: string[];\n results: EntryItem[];\n /** The picker's own cap, which its Field's counter may override. */\n cap: PickerCap;\n block: PickerBlockState;\n isRemote: boolean;\n pageSize: number;\n remote: PickerData;\n onToggle: (id: string) => void;\n onEdit?: (item: EntryItem) => void;\n};\nexport function PickerDialog({\n isOpen,\n onClose,\n query,\n onQuery,\n selected,\n results,\n cap,\n block,\n isRemote,\n pageSize,\n remote,\n onToggle,\n onEdit,\n itemLabel,\n itemsLabel,\n addLabel,\n onCreate,\n isCreating,\n dialogTitle,\n dialogDescription,\n isDialogHidden,\n}: DialogProps) {\n // The rows stay usable after a failed refresh; this offers to read them again.\n const refreshFailure = useLoadError(\n `Couldn't refresh ${itemsLabel}`,\n remote.refresh.status,\n remote.refresh.error,\n remote.refresh.retry,\n );\n return (\n <Modal\n isOpen={isOpen}\n isHidden={isDialogHidden}\n onClose={onClose}\n title={dialogTitle ?? addLabel}\n description={dialogDescription ?? cap.description}\n className=\"ds-entry-picker__dialog\"\n footer={\n <>\n <span\n className=\"ds-entry-picker__selection\"\n role=\"status\"\n >\n {cap.reading ? (\n <LimitReading\n {...cap.reading}\n size=\"lg\"\n />\n ) : (\n `${selected.length} selected`\n )}\n </span>\n <Button\n variant=\"primary\"\n onClick={onClose}\n >\n Done\n </Button>\n </>\n }\n >\n <PickerFrame\n query={query}\n onQuery={onQuery}\n itemsLabel={itemsLabel}\n isSearching={remote.loading}\n action={\n onCreate && (\n // Primary beside Done: Button's one recorded exception (decision 0086).\n // Focusable while blocked, so creation that ends at the cap keeps focus here.\n <Button\n variant=\"primary\"\n isPending={isCreating}\n isFocusableWhenDisabled\n iconStart=\"plus\"\n isDisabled={block.isDisabled || cap.atMax}\n onClick={onCreate}\n >\n {`New ${itemLabel}`}\n </Button>\n )\n }\n banner={refreshFailure}\n isBusy={\n remote.loading || remote.more.status === \"loading\" || remote.refresh.status === \"loading\"\n }\n >\n <LoadState\n status={remote.status}\n errorTitle={`Couldn't load ${itemsLabel}`}\n error={remote.error}\n onRetry={remote.retry}\n >\n <PickerResults\n items={results}\n selected={selected}\n block={block}\n onToggle={onToggle}\n onEdit={onEdit}\n />\n {!remote.searching && results.length === 0 && (\n <NoResults\n query={query}\n itemLabel={itemLabel}\n itemsLabel={itemsLabel}\n canCreate={Boolean(onCreate)}\n />\n )}\n <PickerPaging\n count={results.length}\n total={isRemote ? remote.total : results.length}\n isRemote={isRemote}\n pageSize={pageSize}\n remote={remote}\n itemsLabel={itemsLabel}\n />\n </LoadState>\n </PickerFrame>\n </Modal>\n );\n}\n\n/**\n * The search row, an optional banner and the scrolling results. Rendered inside\n * the Modal, so it mounts with each opening and starts at the top. A new search\n * returns to the top in the same event that changes the query, so both render\n * once.\n */\nfunction PickerFrame({\n query,\n onQuery,\n itemsLabel,\n isSearching,\n action,\n banner,\n isBusy,\n children,\n}: {\n query: string;\n onQuery: (query: string) => void;\n itemsLabel: string;\n isSearching: boolean;\n action: ReactNode;\n banner: ReactNode;\n isBusy: boolean;\n children: ReactNode;\n}) {\n const { ref, scrolled, onScroll, toTop } = usePickerScroll();\n const search = (next: string) => {\n toTop();\n onQuery(next);\n };\n return (\n <>\n <div\n className=\"ds-entry-picker__search\"\n data-scrolled={scrolled || undefined}\n >\n <SearchField\n aria-label={`Search ${itemsLabel}`}\n value={query}\n isBusy={isSearching}\n placeholder={`Search ${itemsLabel}`}\n onChange={(event) => search(event.target.value)}\n onClear={() => search(\"\")}\n />\n {action}\n </div>\n {banner && <div className=\"ds-entry-picker__refresh\">{banner}</div>}\n <div\n className=\"ds-entry-picker__scroll\"\n ref={ref}\n onScroll={onScroll}\n aria-busy={isBusy}\n >\n {children}\n </div>\n </>\n );\n}\n","import { useId } from \"react\";\nimport { Button } from \"../Button\";\nimport { SortableList, SortableListItem } from \"../SortableList\";\nimport { EditItemButton, RemovedLabel, SelectedEntry, selectedReason } from \"./item\";\nimport type { EntryItem } from \"./types\";\nexport function SelectedItems({\n items,\n selected,\n onChange,\n onEdit,\n isDisabled,\n canReorder,\n emptyLabel,\n}: {\n items: EntryItem[];\n selected: string[];\n onChange: (ids: string[]) => void;\n onEdit?: (item: EntryItem) => void;\n isDisabled: boolean;\n canReorder: boolean;\n emptyLabel: string;\n}) {\n const id = useId();\n // A restricted selection's reason describes the row's Move, Edit and Remove controls.\n const reasonId = (item: EntryItem, index: number) =>\n selectedReason(item) ? `${id}-reason-${index}` : undefined;\n const actions = (item: EntryItem, describedBy: string | undefined) => (\n <span className=\"ds-entry-picker__item-actions\">\n <RemovedLabel item={item} />\n {/* A removed record has nothing left to edit. */}\n <EditItemButton\n item={item}\n onEdit={item.tone === \"removed\" ? undefined : onEdit}\n isDisabled={isDisabled}\n />\n <Button\n variant=\"simple\"\n size=\"sm\"\n isIconOnly\n iconStart=\"x\"\n aria-label={`Remove ${item.title}`}\n aria-describedby={describedBy}\n isDisabled={isDisabled}\n onClick={() => onChange(selected.filter((id) => id !== item.id))}\n />\n </span>\n );\n if (items.length === 0) {\n return <p className=\"ds-entry-picker__empty\">{emptyLabel}</p>;\n }\n if (canReorder) {\n return (\n <SortableList\n items={selected}\n onReorder={onChange}\n isDisabled={isDisabled}\n >\n {items.map((item, index) => (\n <SortableListItem\n key={item.id}\n id={item.id}\n label={item.title}\n data-tone={item.tone}\n handleDescribedBy={reasonId(item, index)}\n action={actions(item, reasonId(item, index))}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n </SortableListItem>\n ))}\n </SortableList>\n );\n }\n return (\n <ul className=\"ds-entry-picker__list\">\n {items.map((item, index) => (\n <li\n key={item.id}\n className=\"ds-entry-picker__row\"\n data-tone={item.tone}\n >\n <div className=\"ds-entry\">\n <SelectedEntry\n item={item}\n reasonId={reasonId(item, index)}\n />\n </div>\n {actions(item, reasonId(item, index))}\n </li>\n ))}\n </ul>\n );\n}\n","import type { EntryItem } from \"./types\";\n\nfunction placeholder(id: string, title: string, metadata?: string): EntryItem {\n return { id, title, metadata, isUnavailable: true };\n}\n\n/**\n * The selected rows, in stored order. Static items come first, then the latest\n * known copy, then the current page. Without `resolveItem` an ID nothing\n * describes shows as itself: not knowing an item isn't the same as it being gone.\n */\nexport function chosenItems({\n selected,\n items,\n pageItems,\n known,\n failures,\n hasResolver,\n itemLabel,\n}: {\n selected: string[];\n items: EntryItem[];\n pageItems: EntryItem[];\n known: Map<string, EntryItem | null>;\n failures: Map<string, unknown>;\n hasResolver: boolean;\n itemLabel: string;\n}): EntryItem[] {\n const staticById = new Map(items.map((item) => [item.id, item]));\n const pageById = new Map(pageItems.map((item) => [item.id, item]));\n return selected.map((id) => {\n const item = staticById.get(id) ?? (known.has(id) ? known.get(id) : pageById.get(id));\n if (item) {\n return item;\n }\n if (known.has(id)) {\n const name = `${itemLabel.charAt(0).toUpperCase()}${itemLabel.slice(1)}`;\n return placeholder(id, `${name} no longer available`, \"Replace or clear this selection.\");\n }\n if (!hasResolver) {\n return { id, title: id };\n }\n return placeholder(id, failures.has(id) ? `Couldn't load ${itemLabel}` : \"Loading…\");\n });\n}\n","import type { FieldLimit } from \"../Field/types\";\nimport { usableLimit } from \"../LimitReading/limit\";\nimport type { EntryPickerMode } from \".\";\n\n/** A single selection, or a multiple one capped at one, holds one item. */\nfunction selectsOne(mode: EntryPickerMode, max: number | undefined) {\n return mode === \"single\" || max === 1;\n}\n\n/**\n * The selection's usage limit. A one-item selection is a slot to fill, read\n * neutrally; otherwise only an explicitly capped multiple selection has one.\n * Pure, so FormEditor's model derives the same server-rendered limit the\n * picker reports.\n */\nexport function selectionLimit(\n mode: EntryPickerMode,\n count: number,\n max: number | undefined,\n): FieldLimit | undefined {\n if (selectsOne(mode, max)) {\n return { count, max: 1, tone: \"neutral\" };\n }\n return mode === \"multiple\" && max !== undefined ? { count, max } : undefined;\n}\n\n/** The Field's count badge, which a one-item slot's own reading replaces. */\nexport function selectionCount(mode: EntryPickerMode, count: number, max: number | undefined) {\n return selectsOne(mode, max) ? undefined : count;\n}\n\nexport interface PickerCap {\n /** The Field counter's limit, as FormEditor's model derives it. */\n limit: FieldLimit | undefined;\n /** The selection has reached an enforced cap. */\n atMax: boolean;\n /** The dialog's default description. */\n description: string;\n /** The footer's LimitReading, when the limit reads as usage. */\n reading: FieldLimit | undefined;\n}\n\n/**\n * Everything the picker derives from its mode and max, so the cap is decided\n * in one place: only a finite max in multiple mode is enforced and described.\n * Infinity and NaN never fill, so they read as no limit.\n */\nexport function pickerCap(\n mode: EntryPickerMode,\n count: number,\n max: number | undefined,\n { itemLabel, itemsLabel }: { itemLabel: string; itemsLabel: string },\n): PickerCap {\n const limit = selectionLimit(mode, count, max);\n // Single mode replaces its one selection, so only a multiple cap blocks rows.\n const cap = mode === \"multiple\" && limit && Number.isFinite(limit.max) ? limit.max : undefined;\n let description = `Choose as many ${itemsLabel} as you need.`;\n if (mode === \"single\" || cap === 1) {\n description = `Choose one ${itemLabel}.`;\n } else if (cap !== undefined) {\n description = `Choose up to ${cap} ${itemsLabel}.`;\n }\n return {\n limit,\n atMax: cap !== undefined && count >= cap,\n description,\n // Single mode closes on its first pick, so its footer keeps the plain count.\n reading: mode === \"multiple\" && usableLimit(limit) ? limit : undefined,\n };\n}\n","import { useEffect, useMemo, useRef, useState } from \"react\";\nimport type { LoadStatus } from \"../LoadState\";\nimport { useLatest } from \"../../internal/useLatest\";\nimport type { EntryItem, EntryPickerSource } from \"./types\";\n\ntype RefreshKey = EntryPickerSource[\"refreshKey\"];\n\nexport function asError(failure: unknown) {\n return failure instanceof Error ? failure : null;\n}\n\n/** The map without `ids`, or the same map when it holds none of them. */\nfunction without<V>(map: Map<string, V>, ids: string[]) {\n if (!ids.some((id) => map.has(id))) {\n return map;\n }\n const next = new Map(map);\n for (const id of ids) {\n next.delete(id);\n }\n return next;\n}\n\n/** What the picker knows about the selected IDs beyond its static items. */\ninterface Copies {\n /** The refresh that `known` and `failures` describe. */\n refreshKey: RefreshKey;\n /** The selected IDs the maps describe, in any order. */\n selected: string[];\n /** The copy a page, a pick or `resolveItem` supplied since the last refresh; null: unavailable. */\n known: Map<string, EntryItem | null>;\n /** Copies from before the last refresh, shown until a fresh copy replaces them. */\n stale: Map<string, EntryItem | null>;\n failures: Map<string, Error | null>;\n}\n\n/** Whether `next` adds or removes an ID. A reorder changes nothing the maps describe. */\nfunction changesIds(previous: string[], next: string[]) {\n return (\n previous !== next &&\n (previous.length !== next.length || next.some((id) => !previous.includes(id)))\n );\n}\n\n/**\n * A refresh makes every copy stale and clears failures, so each ID is described\n * again. Removing an ID forgets it, so a restored ID (an undo or a form reset)\n * is described afresh. Picks remembered before a controlled value catches up\n * are kept: they were never removed.\n */\nfunction update(copies: Copies, selected: string[], refreshKey: RefreshKey): Copies {\n let next = copies;\n if (!Object.is(next.refreshKey, refreshKey)) {\n next = {\n ...next,\n refreshKey,\n known: new Map(),\n stale: new Map([...next.stale, ...next.known]),\n failures: new Map(),\n };\n }\n if (changesIds(next.selected, selected)) {\n const removed = next.selected.filter((id) => !selected.includes(id));\n next = {\n ...next,\n selected,\n known: without(next.known, removed),\n stale: without(next.stale, removed),\n failures: without(next.failures, removed),\n };\n }\n return next;\n}\n\n/**\n * The latest copy of each selected item. Only IDs without a copy since the last\n * refresh are resolved, once each, and a retry re-resolves just the failed\n * ones. A stale copy stays on screen until its fresh one arrives, so a refresh\n * never blanks a row. A reply for an ID removed, described or refreshed since\n * it was requested is dropped.\n */\nexport function useSelectedItems(\n selected: string[],\n items: EntryItem[],\n resolveItem: EntryPickerSource[\"resolveItem\"],\n refreshKey?: RefreshKey,\n) {\n const resolve = useLatest(resolveItem);\n const selection = useLatest(selected);\n const [stored, setCopies] = useState<Copies>(() => ({\n refreshKey,\n selected,\n known: new Map(),\n stale: new Map(),\n failures: new Map(),\n }));\n const copies = update(stored, selected, refreshKey);\n if (copies !== stored) {\n setCopies(copies);\n }\n const { known, stale, failures } = copies;\n const shown = useMemo(\n () => (stale.size === 0 ? known : new Map([...stale, ...known])),\n [stale, known],\n );\n\n /**\n * Keep the latest copy of selected items a page or a pick shows, so edits\n * appear. A copy read at `revision`, before the latest refresh, is no fresher\n * than the stale copies: it only fills a gap among them, so a pick from older\n * rows keeps its title and actions while it is described again.\n */\n const remember = (\n seen: (EntryItem | undefined)[],\n revision: RefreshKey,\n ids = selection.current,\n ) => {\n const copies = seen\n .filter((item): item is EntryItem => item !== undefined && ids.includes(item.id))\n .map((item) => [item.id, item] as const);\n if (copies.length === 0) {\n return;\n }\n setCopies((previous) => {\n if (Object.is(previous.refreshKey, revision)) {\n return { ...previous, known: new Map([...previous.known, ...copies]) };\n }\n const gaps = copies.filter(([id]) => !previous.known.has(id) && !previous.stale.has(id));\n return gaps.length === 0\n ? previous\n : { ...previous, stale: new Map([...previous.stale, ...gaps]) };\n });\n };\n\n const staticIds = new Set(items.map((item) => item.id));\n const unknown = resolveItem\n ? selected.filter((id) => !staticIds.has(id) && !known.has(id) && !failures.has(id))\n : [];\n const unknownKey = JSON.stringify(unknown);\n /** Lookups in flight for the current refresh, by ID. */\n const requested = useRef({ refreshKey, tokens: new Map<string, symbol>() });\n useEffect(() => {\n const resolveOne = resolve.current;\n if (!resolveOne) {\n return;\n }\n const ids = JSON.parse(unknownKey) as string[];\n if (!Object.is(requested.current.refreshKey, refreshKey)) {\n requested.current = { refreshKey, tokens: new Map() };\n }\n const { tokens } = requested.current;\n // A lookup for an ID since described or removed no longer counts.\n for (const id of tokens.keys()) {\n if (!ids.includes(id)) {\n tokens.delete(id);\n }\n }\n for (const id of ids.filter((unseen) => !tokens.has(unseen))) {\n const token = Symbol(id);\n tokens.set(id, token);\n const settle = (describe: (previous: Copies) => Copies) => {\n if (requested.current.tokens.get(id) !== token) {\n return;\n }\n requested.current.tokens.delete(id);\n setCopies((previous) =>\n Object.is(previous.refreshKey, refreshKey) && previous.selected.includes(id)\n ? describe(previous)\n : previous,\n );\n };\n void Promise.resolve()\n .then(() => resolveOne(id))\n .then(\n // A page or pick that arrived meanwhile is at least as fresh.\n (item) =>\n settle((previous) =>\n previous.known.has(id)\n ? previous\n : { ...previous, known: new Map(previous.known).set(id, item ?? null) },\n ),\n (failure: unknown) =>\n settle((previous) => ({\n ...previous,\n failures: new Map(previous.failures).set(id, asError(failure)),\n })),\n );\n }\n }, [unknownKey, refreshKey, resolve]);\n\n const failed = selected.filter((id) => failures.has(id) && !known.has(id));\n const status: LoadStatus = unknown.length > 0 ? \"loading\" : failed.length > 0 ? \"error\" : \"ready\";\n return {\n known: shown,\n failures,\n remember,\n status,\n error: failed.length > 0 ? (failures.get(failed[0]) ?? null) : null,\n retry: () =>\n setCopies((previous) => ({ ...previous, failures: without(previous.failures, failed) })),\n };\n}\n","import { useEffect, useRef, useState } from \"react\";\nimport type { LoadStatus } from \"../LoadState\";\nimport { useLatest } from \"../../internal/useLatest\";\nimport { asError } from \"./use-selected-items\";\nimport type { EntryItem, EntryPickerPage, EntryPickerSource } from \"./types\";\n\nconst SEARCH_DELAY_MS = 250;\n\ntype LoadPage = NonNullable<EntryPickerSource[\"loadPage\"]>;\ntype RefreshKey = EntryPickerSource[\"refreshKey\"];\n\nfunction unique(items: EntryItem[]) {\n return Array.from(new Map(items.map((item) => [item.id, item])).values());\n}\n\n/** Rows read from the start of a result list. */\ninterface Rows {\n items: EntryItem[];\n /** The next server offset; a duplicate row still advances it. */\n offset: number;\n total: number;\n}\nconst noRows: Rows = { items: [], offset: 0, total: 0 };\n\ninterface Pages extends Rows {\n /** The request these rows answer; null until an open dialog's first reply. */\n key: string | null;\n /** The `refreshKey` they were read at. */\n revision: RefreshKey;\n status: \"ready\" | \"error\";\n error: Error | null;\n}\nconst noPages: Pages = { ...noRows, key: null, revision: undefined, status: \"ready\", error: null };\n\ninterface MoreRequest {\n token: symbol;\n status: \"loading\" | \"error\";\n error: Error | null;\n}\n\n/**\n * What Load more reports for the shown rows. Paging extends only current rows,\n * so it waits while a search or refresh replaces them, and a failed Load more,\n * which belongs to the rows it extended, is no longer reported meanwhile. One in\n * flight stays loading: a refresh folds it in.\n */\nfunction moreState(more: MoreRequest | null, isAvailable: boolean) {\n const failed = more?.status === \"error\" && isAvailable;\n const status: LoadStatus = more?.status === \"loading\" ? \"loading\" : failed ? \"error\" : \"ready\";\n return { status, error: failed ? (more.error ?? null) : null, isAvailable };\n}\n\n/** A background refresh that failed, leaving the rows read at an earlier revision. */\ninterface RefreshFailure {\n key: string;\n revision: RefreshKey;\n error: Error | null;\n}\n\n/** The rows after `page`, which was requested at their offset. */\nfunction extend(rows: Rows, page: EntryPickerPage): Rows {\n return {\n items: unique([...rows.items, ...page.items]),\n offset: rows.offset + page.items.length,\n // An empty page ends paging even when the total overcounted.\n total: page.items.length === 0 ? Math.min(page.total, rows.offset) : page.total,\n };\n}\n\n/** Append a further page, unless a newer search or page replaced the rows meanwhile. */\nfunction appendPage(previous: Pages, key: string, offset: number, page: EntryPickerPage): Pages {\n if (previous.key !== key || previous.offset !== offset) {\n return previous;\n }\n return { ...previous, ...extend(previous, page) };\n}\n\n/**\n * At least one page, and at least the first `target` rows. Full pages are\n * requested together; a short page before the end moves every later offset, so\n * the rest is read one page at a time from where it stopped.\n */\nasync function loadRows(\n load: LoadPage,\n query: string,\n limit: number,\n target: number,\n isCurrent: () => boolean,\n) {\n const count = Math.max(1, Math.ceil(target / limit));\n const pages = await Promise.all(\n Array.from({ length: count }, (_, index) => load({ offset: index * limit, limit }, { query })),\n );\n let rows = noRows;\n for (const [index, page] of pages.entries()) {\n if (rows.offset !== index * limit) {\n break;\n }\n rows = extend(rows, page);\n }\n while (rows.offset < target && rows.offset < rows.total && isCurrent()) {\n rows = extend(rows, await load({ offset: rows.offset, limit }, { query }));\n }\n return rows;\n}\n\n/** What the shown rows mean for the request, at the revision, the picker wants answered. */\nfunction describe(\n key: string | null,\n pages: Pages,\n refreshKey: RefreshKey,\n failure: RefreshFailure | null,\n) {\n const answered = key !== null && pages.key === key;\n const isCurrent = answered && Object.is(pages.revision, refreshKey);\n // A new request, or a failed one whose source has since changed.\n const loading = key !== null && !isCurrent && (!answered || pages.status === \"error\");\n // Rows from the previous search stay, dimmed, until the new search answers.\n const searching = loading && pages.key !== null && pages.status === \"ready\";\n const status: LoadStatus =\n loading && !searching ? \"loading\" : pages.status === \"error\" ? \"error\" : \"ready\";\n const hasMore = pages.status === \"ready\" && pages.offset < pages.total;\n // Rows read before a refresh stay usable while they are read again.\n const isStale = answered && !isCurrent && pages.status === \"ready\";\n const refreshFailed = isStale && failure?.key === key && Object.is(failure.revision, refreshKey);\n const refresh: LoadStatus = isStale ? (refreshFailed ? \"error\" : \"loading\") : \"ready\";\n return { loading, searching, status, hasMore, refresh, refreshFailed };\n}\n\n/**\n * Server pages for an open picker. Opening, a new search, a page size or a\n * retry requests the first page; an older reply never overwrites a newer one.\n * Closing discards the pages and starts a new round, so the next opening reads\n * the source afresh and no reply from an earlier opening, Load more included,\n * matches it. A new `refreshKey` reads the shown rows again in the background;\n * they stay usable meanwhile, and stay on screen if that fails. `loadPage` is\n * read when called, so an inline callback never reloads.\n */\nexport function usePickerData(\n loadPage: EntryPickerSource[\"loadPage\"],\n pageSize: number,\n query: string,\n isOpen: boolean,\n onItems: (items: EntryItem[], revision: RefreshKey) => void,\n refreshKey?: RefreshKey,\n) {\n const load = useLatest(loadPage);\n const report = useLatest(onItems);\n const revision = useLatest(refreshKey);\n // Each retry and each closing starts a new round of requests.\n const [round, setRound] = useState(0);\n const [pages, setPages] = useState(noPages);\n const [more, setMore] = useState<MoreRequest | null>(null);\n const [refreshFailure, setRefreshFailure] = useState<RefreshFailure | null>(null);\n const [wasOpen, setWasOpen] = useState(isOpen);\n if (wasOpen !== isOpen) {\n setWasOpen(isOpen);\n if (!isOpen) {\n setPages(noPages);\n setMore(null);\n setRefreshFailure(null);\n setRound((count) => count + 1);\n }\n }\n const search = query.trim();\n const key = loadPage && isOpen ? JSON.stringify([search, pageSize, round]) : null;\n const shown = useLatest(pages);\n // The Load more request in flight; replacing the rows makes it obsolete.\n const paging = useRef<symbol | null>(null);\n const lastSearch = useRef(search);\n const { loading, searching, status, hasMore, refresh, refreshFailed } = describe(\n key,\n pages,\n refreshKey,\n refreshFailure,\n );\n // A new search or a refresh would page at an old offset.\n const canLoadMore = !loading && refresh === \"ready\";\n const plan = loading ? \"load\" : refresh === \"loading\" ? \"refresh\" : null;\n\n useEffect(() => {\n if (key === null) {\n return;\n }\n const delay = plan === \"load\" && search !== lastSearch.current ? SEARCH_DELAY_MS : 0;\n lastSearch.current = search;\n if (plan === null) {\n return;\n }\n // A Load more in flight joins the refreshed rows instead of appending to the old ones.\n const target = plan === \"refresh\" ? shown.current.offset + (paging.current ? pageSize : 0) : 0;\n let isCurrent = true;\n const timer = window.setTimeout(() => {\n const loadOne = load.current;\n if (!loadOne) {\n return;\n }\n void loadRows(loadOne, search, pageSize, target, () => isCurrent).then(\n (rows) => {\n if (isCurrent) {\n paging.current = null;\n setPages({ ...rows, key, revision: refreshKey, status: \"ready\", error: null });\n setMore(null);\n setRefreshFailure(null);\n report.current(rows.items, refreshKey);\n }\n },\n (failure: unknown) => {\n if (!isCurrent) {\n return;\n }\n if (plan === \"refresh\") {\n setRefreshFailure({ key, revision: refreshKey, error: asError(failure) });\n return;\n }\n // A failed search drops the previous rows, so none stay selectable or pageable.\n paging.current = null;\n setPages({\n ...noPages,\n key,\n revision: refreshKey,\n status: \"error\",\n error: asError(failure),\n });\n setMore(null);\n },\n );\n }, delay);\n return () => {\n isCurrent = false;\n window.clearTimeout(timer);\n };\n }, [key, plan, refreshKey, search, pageSize, load, report, shown]);\n\n const loadMore = () => {\n const loadMorePage = load.current;\n const requestKey = pages.key;\n const { offset } = pages;\n if (!loadMorePage || requestKey === null || !canLoadMore) {\n return;\n }\n if (!hasMore || paging.current) {\n return;\n }\n const token = Symbol(\"load more\");\n const asked = refreshKey;\n paging.current = token;\n setMore({ token, status: \"loading\", error: null });\n // A reply counts only while it extends the rows on screen and no refresh began since.\n const applies = () =>\n paging.current === token &&\n shown.current.key === requestKey &&\n shown.current.offset === offset &&\n Object.is(revision.current, asked);\n const settle = (next: MoreRequest | null) => {\n if (paging.current === token) {\n paging.current = null;\n }\n setMore((previous) => (previous?.token === token ? next : previous));\n };\n void Promise.resolve()\n .then(() => loadMorePage({ offset, limit: pageSize }, { query: search }))\n .then(\n (page) => {\n if (applies()) {\n setPages((previous) => appendPage(previous, requestKey, offset, page));\n report.current(page.items, asked);\n }\n settle(null);\n },\n (failure: unknown) =>\n settle(applies() ? { token, status: \"error\", error: asError(failure) } : null),\n );\n };\n\n return {\n items: pages.items,\n total: pages.total,\n offset: pages.offset,\n hasMore,\n /** The `refreshKey` the shown rows were read at. */\n pageRevision: pages.revision,\n loading,\n searching,\n status,\n error: pages.error,\n retry: () => setRound((count) => count + 1),\n /** `isAvailable` is false while a search or refresh replaces the rows; `load` then does nothing. */\n more: { ...moreState(more, canLoadMore), load: loadMore },\n refresh: {\n status: refresh,\n error: refreshFailed ? (refreshFailure?.error ?? null) : null,\n retry: () => setRefreshFailure(null),\n },\n };\n}\n\nexport type PickerData = ReturnType<typeof usePickerData>;\n","import { useMemo, useState } from \"react\";\nimport { FieldGroup } from \"../Field/group\";\nimport { Button } from \"../Button\";\nimport { resultBlock } from \"./blocked\";\nimport { PickerDialog } from \"./dialog\";\nimport { SelectedItems } from \"./selected-items\";\nimport { chosenItems } from \"./chosen\";\nimport { useLoadError } from \"./feedback\";\nimport { pickerCap, selectionCount } from \"./limit\";\nimport { usePickerData } from \"./use-picker-data\";\nimport { useSelectedItems } from \"./use-selected-items\";\nimport type { EntryItem, EntryPickerProps } from \"./types\";\nimport \"./style.css\";\n\nexport type {\n EntryItem,\n EntryPickerMode,\n EntryPickerProps,\n EntryPickerSource,\n EntryPickerPage,\n EntryPickerPageRequest,\n} from \"./types\";\nconst emptyItems: EntryItem[] = [];\n/** Static choices whose title or keywords contain the trimmed query, as server searches trim it. */\nfunction staticMatches(items: EntryItem[], query: string) {\n const search = query.trim().toLowerCase();\n if (!search) {\n return items;\n }\n return items.filter((item) =>\n [item.title, ...(item.keywords ?? [])].join(\" \").toLowerCase().includes(search),\n );\n}\n\n/** Static or server-paged choices, with ordered selections and optional editing actions. */\nexport function EntryPicker({\n items = emptyItems,\n value,\n defaultValue = [],\n onValueChange,\n mode = \"multiple\",\n max,\n label = \"Entries\",\n emptyLabel = \"Nothing selected yet.\",\n addLabel = \"Choose entries\",\n itemLabel = \"entry\",\n itemsLabel = \"entries\",\n isReorderable = true,\n isDisabled = false,\n loadPage,\n pageSize = 10,\n resolveItem,\n onEditItem,\n onCreate,\n isCreating = false,\n refreshKey,\n dialogTitle,\n dialogDescription,\n isDialogHidden = false,\n className,\n ...fieldProps\n}: EntryPickerProps) {\n const [internal, setInternal] = useState<string[]>(defaultValue);\n const selected = value ?? internal;\n const [isOpen, setOpen] = useState(false);\n const [query, setQuery] = useState(\"\");\n const selection = useSelectedItems(selected, items, resolveItem, refreshKey);\n const remote = usePickerData(loadPage, pageSize, query, isOpen, selection.remember, refreshKey);\n const resolutionError = useLoadError(\n `Couldn't load selected ${itemsLabel}`,\n selection.status,\n selection.error,\n selection.retry,\n );\n const isRemote = Boolean(loadPage);\n const filtered = useMemo(\n () => (isRemote ? emptyItems : staticMatches(items, query)),\n [isRemote, items, query],\n );\n const results = isRemote ? remote.items : filtered;\n const cap = pickerCap(mode, selected.length, max, { itemLabel, itemsLabel });\n const block = { isDisabled, searching: remote.searching, atMax: cap.atMax };\n const commit = (next: string[]) => {\n if (isDisabled) {\n return;\n }\n if (value === undefined) {\n setInternal(next);\n }\n onValueChange?.(next);\n };\n const pick = (next: string[], item: EntryItem) => {\n // The picked row describes the selection after the search moves on. A row\n // read before the latest refresh stays a stale copy, described again.\n const revision = isRemote ? remote.pageRevision : refreshKey;\n selection.remember([item], revision, next);\n commit(next);\n };\n // The one place selection rules are enforced, whichever control asked.\n const toggle = (id: string) => {\n const item = results.find((result) => result.id === id);\n if (!item || resultBlock(item, selected.includes(id), block)) {\n return;\n }\n if (mode === \"single\") {\n pick(selected[0] === id ? [] : [id], item);\n setOpen(false);\n } else if (selected.includes(id)) {\n commit(selected.filter((selectedId) => selectedId !== id));\n } else {\n pick([...selected, id], item);\n }\n };\n const { known, failures } = selection;\n const hasResolver = Boolean(resolveItem);\n const chosen = useMemo(\n () =>\n chosenItems({\n selected,\n items,\n pageItems: remote.items,\n known,\n failures,\n hasResolver,\n itemLabel,\n }),\n [selected, items, remote.items, known, failures, hasResolver, itemLabel],\n );\n const editItem = onEditItem\n ? (item: EntryItem) => {\n if (onEditItem(item) === false) {\n setOpen(false);\n }\n }\n : undefined;\n return (\n <FieldGroup\n {...fieldProps}\n className={[\"ds-entry-picker\", className].filter(Boolean).join(\" \")}\n label={label}\n count={selectionCount(mode, selected.length, max)}\n limit={fieldProps.limit === undefined ? cap.limit : fieldProps.limit}\n >\n <SelectedItems\n items={chosen}\n selected={selected}\n onChange={commit}\n onEdit={editItem}\n isDisabled={isDisabled}\n canReorder={isReorderable && mode === \"multiple\" && chosen.length > 1}\n emptyLabel={emptyLabel}\n />\n {resolutionError}\n <div className=\"ds-entry-picker__actions\">\n <Button\n variant=\"neutral\"\n size=\"sm\"\n iconStart=\"plus\"\n isDisabled={isDisabled}\n onClick={() => setOpen(true)}\n >\n {addLabel}\n </Button>\n {selected.length > 0 && (\n <Button\n variant=\"simple\"\n size=\"sm\"\n isDisabled={isDisabled}\n onClick={() => commit([])}\n >\n Clear\n </Button>\n )}\n </div>\n <PickerDialog\n isOpen={isOpen}\n onClose={() => setOpen(false)}\n query={query}\n onQuery={setQuery}\n selected={selected}\n results={results}\n cap={cap}\n block={block}\n isRemote={isRemote}\n pageSize={pageSize}\n remote={remote}\n onToggle={toggle}\n onEdit={editItem}\n itemLabel={itemLabel}\n itemsLabel={itemsLabel}\n addLabel={addLabel}\n onCreate={onCreate}\n isCreating={isCreating}\n dialogTitle={dialogTitle}\n dialogDescription={dialogDescription}\n isDialogHidden={isDialogHidden}\n />\n </FieldGroup>\n );\n}\n"],"mappings":"A,mjBAqBA,SAAgBmD,EACd,EACA,EACA,CAAE,aAAY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U,IAAA,GAAYjH,EAAI,MAAQiH,EAAW,MALjE,SAAA,EAOE,EAAAxL,EAAA,IAAA,CAACoF,EAAD,CACE,MAAOmH,GACG,WACV,SAAUN,EACV,OAAQO,GACI,aACZ,WAAYG,GAAiBxG,IAAS,YAAcoG,GAAO,OAAS,EACxD,YACb,CAAA,EACAR,GACD,EAAA/L,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,2BAAf,SAAA,EACE,EAAAA,EAAA,IAAA,CAACd,EAAAA,OAAD,CACE,QAAQ,UACR,KAAK,KACL,UAAU,OACE,aACZ,YAAe2M,EAAQ,EAAI,EAE1B,SAAAxH,CACK,CAAA,EACPb,EAAS,OAAS,IACjB,EAAAxD,EAAA,IAAA,CAACd,EAAAA,OAAD,CACE,QAAQ,SACR,KAAK,KACO,aACZ,YAAe+M,EAAO,CAAC,CAAC,EACzB,SAAA,OAEO,CAAA,CAEP,C,IACL,EAAAjM,EAAA,IAAA,CAACiE,EAAD,CACU,SACR,YAAe4H,EAAQ,EAAK,EACrB,QACP,QAASC,EACC,WACD,UACJ,MACE,QACG,WACA,WACF,SACR,SAAUM,GACV,OAAQI,GACG,YACC,aACF,WACA,WACE,aACC,cACM,oBACH,gBACjB,CAAA,CACS,C,EAEhB,C"}
@@ -5,7 +5,7 @@ import { Badge as a } from "../components/Badge/index.js";
5
5
  import { r as o } from "./limit-s9zfxIMC.js";
6
6
  import { LimitReading as s } from "../components/LimitReading/index.js";
7
7
  import { Modal as c } from "../components/Modal/index.js";
8
- import { t as l } from "./group-CJA3-3s5.js";
8
+ import { t as l } from "./group-7Z_xRlQx.js";
9
9
  import { n as u, r as d, t as f } from "./LoadState-B056EPu7.js";
10
10
  import { SearchField as p } from "../components/SearchField/index.js";
11
11
  import { Checkbox as m } from "../components/Choice/index.js";
@@ -800,4 +800,4 @@ function pe({ items: e = de, value: n, defaultValue: r = [], onValueChange: i, m
800
800
  //#endregion
801
801
  export { ie as n, U as r, pe as t };
802
802
 
803
- //# sourceMappingURL=EntryPicker-DIYjKmBf.js.map
803
+ //# sourceMappingURL=EntryPicker-LBj_56_e.js.map