@namroodinc/liquid-editorial 0.12.0 → 0.13.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.
- package/README.md +17 -7
- package/UPGRADING.md +90 -0
- package/dist/chunks/{Avatar-DPnrvkwd.cjs → Avatar-BY0dAItT.cjs} +2 -2
- package/dist/chunks/{Avatar-DPnrvkwd.cjs.map → Avatar-BY0dAItT.cjs.map} +1 -1
- package/dist/chunks/{Avatar-BK8IdL5W.js → Avatar-UjhjcHh5.js} +2 -2
- package/dist/chunks/{Avatar-BK8IdL5W.js.map → Avatar-UjhjcHh5.js.map} +1 -1
- package/dist/chunks/{Board-BCS7sDXg.js → Board-6fXt1YFp.js} +2 -2
- package/dist/chunks/{Board-BCS7sDXg.js.map → Board-6fXt1YFp.js.map} +1 -1
- package/dist/chunks/{Board-CNVy8gHI.cjs → Board-DfVQSb_L.cjs} +2 -2
- package/dist/chunks/{Board-CNVy8gHI.cjs.map → Board-DfVQSb_L.cjs.map} +1 -1
- package/dist/chunks/{CollectionView-DrszOUOt.cjs → CollectionView-CIJdNwcq.cjs} +2 -2
- package/dist/chunks/{CollectionView-DrszOUOt.cjs.map → CollectionView-CIJdNwcq.cjs.map} +1 -1
- package/dist/chunks/{CollectionView-B0ZJxkNK.js → CollectionView-JRNdXHti.js} +2 -2
- package/dist/chunks/{CollectionView-B0ZJxkNK.js.map → CollectionView-JRNdXHti.js.map} +1 -1
- package/dist/chunks/{ColourField-C39pcjkG.js → ColourField-YaCEWiPA.js} +147 -153
- package/dist/chunks/ColourField-YaCEWiPA.js.map +1 -0
- package/dist/chunks/ColourField-bgi6TLOM.cjs +2 -0
- package/dist/chunks/ColourField-bgi6TLOM.cjs.map +1 -0
- package/dist/chunks/{DatePicker-Dpvfomrm.cjs → DatePicker-CCygKPuy.cjs} +2 -2
- package/dist/chunks/{DatePicker-Dpvfomrm.cjs.map → DatePicker-CCygKPuy.cjs.map} +1 -1
- package/dist/chunks/{DatePicker-DDc1nDTb.js → DatePicker-CHJYSaLU.js} +22 -22
- package/dist/chunks/{DatePicker-DDc1nDTb.js.map → DatePicker-CHJYSaLU.js.map} +1 -1
- package/dist/chunks/{Drawer-C3mWT9Kh.js → Drawer-Ck5XKT_V.js} +3 -3
- package/dist/chunks/{Drawer-C3mWT9Kh.js.map → Drawer-Ck5XKT_V.js.map} +1 -1
- package/dist/chunks/{Drawer-DTKZptua.cjs → Drawer-DdIH9jpe.cjs} +2 -2
- package/dist/chunks/{Drawer-DTKZptua.cjs.map → Drawer-DdIH9jpe.cjs.map} +1 -1
- package/dist/chunks/{EntryPicker-CgWbgWnc.cjs → EntryPicker-DmiAnu9l.cjs} +2 -2
- package/dist/chunks/{EntryPicker-CgWbgWnc.cjs.map → EntryPicker-DmiAnu9l.cjs.map} +1 -1
- package/dist/chunks/{EntryPicker-DlEsVCvA.js → EntryPicker-WERMwe0h.js} +3 -3
- package/dist/chunks/{EntryPicker-DlEsVCvA.js.map → EntryPicker-WERMwe0h.js.map} +1 -1
- package/dist/chunks/{FormEditor-iACd0El-.cjs → FormEditor-B8USzAky.cjs} +2 -2
- package/dist/chunks/{FormEditor-iACd0El-.cjs.map → FormEditor-B8USzAky.cjs.map} +1 -1
- package/dist/chunks/{FormEditor-CLLOHKiO.js → FormEditor-BG2RhC71.js} +16 -16
- package/dist/chunks/{FormEditor-CLLOHKiO.js.map → FormEditor-BG2RhC71.js.map} +1 -1
- package/dist/chunks/{Icon-CD3oeiNA.cjs → Icon-C12r4frL.cjs} +2 -2
- package/dist/chunks/Icon-C12r4frL.cjs.map +1 -0
- package/dist/chunks/{Icon-CYXOo0Kt.js → Icon-Peb0houB.js} +38 -36
- package/dist/chunks/Icon-Peb0houB.js.map +1 -0
- package/dist/chunks/{Message-CyLq9ef-.js → Message-CMoH7jcg.js} +5 -9
- package/dist/chunks/{Message-CyLq9ef-.js.map → Message-CMoH7jcg.js.map} +1 -1
- package/dist/chunks/{Message-D3b8HDhm.cjs → Message-qguX0uZk.cjs} +2 -2
- package/dist/chunks/{Message-D3b8HDhm.cjs.map → Message-qguX0uZk.cjs.map} +1 -1
- package/dist/chunks/RichTextEditor-BSA4uzKm.cjs +2 -0
- package/dist/chunks/RichTextEditor-BSA4uzKm.cjs.map +1 -0
- package/dist/chunks/{RichTextEditor-B0P53GFt.js → RichTextEditor-D8VQAM5h.js} +396 -375
- package/dist/chunks/RichTextEditor-D8VQAM5h.js.map +1 -0
- package/dist/chunks/{dialogLabel-D18maX-p.js → dialogLabel-DT7rCr3_.js} +19 -19
- package/dist/chunks/{dialogLabel-D18maX-p.js.map → dialogLabel-DT7rCr3_.js.map} +1 -1
- package/dist/chunks/{dialogLabel-2HRYMHbF.cjs → dialogLabel-_-MTckE_.cjs} +2 -2
- package/dist/chunks/{dialogLabel-2HRYMHbF.cjs.map → dialogLabel-_-MTckE_.cjs.map} +1 -1
- package/dist/chunks/overlayLayer-iGhuAByk.cjs +2 -0
- package/dist/chunks/overlayLayer-iGhuAByk.cjs.map +1 -0
- package/dist/chunks/{overlayLayer-IuoPVwTO.js → overlayLayer-lU4iWSjO.js} +32 -28
- package/dist/chunks/overlayLayer-lU4iWSjO.js.map +1 -0
- package/dist/chunks/{group-7Z_xRlQx.js → style-7Z_xRlQx.js} +1 -1
- package/dist/chunks/{group-7Z_xRlQx.js.map → style-7Z_xRlQx.js.map} +1 -1
- package/dist/chunks/{group-nulIa2_8.cjs → style-nulIa2_8.cjs} +1 -1
- package/dist/chunks/{group-nulIa2_8.cjs.map → style-nulIa2_8.cjs.map} +1 -1
- package/dist/chunks/{use-picker-session-DbfOJstX.cjs → use-picker-session-CM0zcEbf.cjs} +2 -2
- package/dist/chunks/{use-picker-session-DbfOJstX.cjs.map → use-picker-session-CM0zcEbf.cjs.map} +1 -1
- package/dist/chunks/{use-picker-session-BnMxbGAZ.js → use-picker-session-GCDShVBy.js} +3 -3
- package/dist/chunks/{use-picker-session-BnMxbGAZ.js.map → use-picker-session-GCDShVBy.js.map} +1 -1
- package/dist/chunks/{useTooltip-BXAvQwt4.cjs → useTooltip-C7ON4nkV.cjs} +2 -2
- package/dist/chunks/{useTooltip-BXAvQwt4.cjs.map → useTooltip-C7ON4nkV.cjs.map} +1 -1
- package/dist/chunks/{useTooltip-BrC7FdeH.js → useTooltip-DnJEFBLg.js} +2 -2
- package/dist/chunks/{useTooltip-BrC7FdeH.js.map → useTooltip-DnJEFBLg.js.map} +1 -1
- package/dist/components/AppShell/index.cjs +1 -1
- package/dist/components/AppShell/index.js +1 -1
- package/dist/components/AssetCard/index.cjs +1 -1
- package/dist/components/AssetCard/index.js +1 -1
- package/dist/components/AssetGrid/index.cjs +1 -1
- package/dist/components/AssetGrid/index.js +1 -1
- package/dist/components/Avatar/index.cjs +1 -1
- package/dist/components/Avatar/index.js +1 -1
- package/dist/components/Badge/style.css +9 -9
- package/dist/components/Banner/index.cjs +1 -1
- package/dist/components/Banner/index.js +1 -1
- package/dist/components/Board/index.cjs +1 -1
- package/dist/components/Board/index.js +1 -1
- package/dist/components/Board/style.css +3 -3
- package/dist/components/Button/index.cjs +1 -1
- package/dist/components/Button/index.js +1 -1
- package/dist/components/Button/style.css +4 -8
- package/dist/components/Choice/index.cjs +1 -1
- package/dist/components/Choice/index.cjs.map +1 -1
- package/dist/components/Choice/index.js +3 -3
- package/dist/components/Choice/index.js.map +1 -1
- package/dist/components/Choice/style.css +29 -18
- package/dist/components/CollectionView/index.cjs +1 -1
- package/dist/components/CollectionView/index.js +1 -1
- package/dist/components/ColourField/index.cjs +1 -1
- package/dist/components/ColourField/index.d.cts.map +1 -1
- package/dist/components/ColourField/index.d.ts.map +1 -1
- package/dist/components/ColourField/index.js +1 -1
- package/dist/components/ColourField/style.css +4 -4
- package/dist/components/DatePicker/index.cjs +1 -1
- package/dist/components/DatePicker/index.js +1 -1
- package/dist/components/Drawer/index.cjs +1 -1
- package/dist/components/Drawer/index.js +1 -1
- package/dist/components/Drawer/style.css +2 -4
- package/dist/components/EditLayout/index.cjs +1 -1
- package/dist/components/EditLayout/index.js +4 -4
- package/dist/components/EditLayout/style.css +1 -7
- package/dist/components/EntryPicker/index.cjs +1 -1
- package/dist/components/EntryPicker/index.js +1 -1
- package/dist/components/EntryPicker/style.css +3 -1
- package/dist/components/Field/style.css +1 -1
- package/dist/components/FormEditor/README.md +28 -33
- package/dist/components/FormEditor/index.cjs +1 -1
- package/dist/components/FormEditor/index.js +1 -1
- package/dist/components/FormEditor/style.css +1 -0
- package/dist/components/Icon/icons.d.cts +2 -0
- package/dist/components/Icon/icons.d.cts.map +1 -1
- package/dist/components/Icon/icons.d.ts +2 -0
- package/dist/components/Icon/icons.d.ts.map +1 -1
- package/dist/components/Icon/index.cjs +1 -1
- package/dist/components/Icon/index.js +1 -1
- package/dist/components/LimitReading/style.css +1 -1
- package/dist/components/Menu/index.cjs +1 -1
- package/dist/components/Menu/index.js +1 -1
- package/dist/components/Menu/style.css +3 -2
- package/dist/components/Modal/index.cjs +1 -1
- package/dist/components/Modal/index.js +2 -2
- package/dist/components/Modal/style.css +1 -3
- package/dist/components/Popover/index.cjs +1 -1
- package/dist/components/Popover/index.cjs.map +1 -1
- package/dist/components/Popover/index.d.cts.map +1 -1
- package/dist/components/Popover/index.d.ts.map +1 -1
- package/dist/components/Popover/index.js +58 -55
- package/dist/components/Popover/index.js.map +1 -1
- package/dist/components/RichTextEditor/index.cjs +1 -1
- package/dist/components/RichTextEditor/index.d.cts.map +1 -1
- package/dist/components/RichTextEditor/index.d.ts.map +1 -1
- package/dist/components/RichTextEditor/index.js +1 -1
- package/dist/components/RichTextEditor/storyblock-view.d.cts.map +1 -1
- package/dist/components/RichTextEditor/storyblock-view.d.ts.map +1 -1
- package/dist/components/RichTextEditor/style.css +141 -61
- package/dist/components/SearchField/index.cjs +1 -1
- package/dist/components/SearchField/index.js +1 -1
- package/dist/components/Select/index.cjs +1 -1
- package/dist/components/Select/index.js +2 -2
- package/dist/components/SelectionCard/index.cjs +1 -1
- package/dist/components/SelectionCard/index.cjs.map +1 -1
- package/dist/components/SelectionCard/index.d.cts.map +1 -1
- package/dist/components/SelectionCard/index.d.ts.map +1 -1
- package/dist/components/SelectionCard/index.js +2 -2
- package/dist/components/SelectionCard/index.js.map +1 -1
- package/dist/components/SelectionCard/style.css +20 -65
- package/dist/components/SideNav/index.cjs +1 -1
- package/dist/components/SideNav/index.js +1 -1
- package/dist/components/Skeleton/style.css +1 -1
- package/dist/components/Slider/style.css +12 -23
- package/dist/components/SortableList/index.cjs +1 -1
- package/dist/components/SortableList/index.js +1 -1
- package/dist/components/Stepper/index.cjs +1 -1
- package/dist/components/Stepper/index.js +1 -1
- package/dist/components/SubNav/index.cjs +1 -1
- package/dist/components/SubNav/index.js +1 -1
- package/dist/components/Switch/index.cjs +1 -1
- package/dist/components/Switch/index.cjs.map +1 -1
- package/dist/components/Switch/index.d.cts.map +1 -1
- package/dist/components/Switch/index.d.ts.map +1 -1
- package/dist/components/Switch/index.js +2 -1
- package/dist/components/Switch/index.js.map +1 -1
- package/dist/components/Switch/style.css +14 -2
- package/dist/components/Table/index.cjs +1 -1
- package/dist/components/Table/index.js +1 -1
- package/dist/components/TagsInput/style.css +3 -21
- package/dist/components/Time/index.cjs +1 -1
- package/dist/components/Time/index.js +1 -1
- package/dist/components/Toast/index.cjs +1 -1
- package/dist/components/Toast/index.js +1 -1
- package/dist/components/TopNav/index.cjs +1 -1
- package/dist/components/TopNav/index.js +1 -1
- package/dist/elements.css +2 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +30 -30
- package/dist/internal/dialogFocus.d.cts +2 -0
- package/dist/internal/dialogFocus.d.cts.map +1 -1
- package/dist/internal/dialogFocus.d.ts +2 -0
- package/dist/internal/dialogFocus.d.ts.map +1 -1
- package/dist/message.css +5 -3
- package/dist/tokens.css +83 -309
- package/package.json +1 -1
- package/dist/chunks/ColourField-BdobU76j.cjs +0 -2
- package/dist/chunks/ColourField-BdobU76j.cjs.map +0 -1
- package/dist/chunks/ColourField-C39pcjkG.js.map +0 -1
- package/dist/chunks/Icon-CD3oeiNA.cjs.map +0 -1
- package/dist/chunks/Icon-CYXOo0Kt.js.map +0 -1
- package/dist/chunks/RichTextEditor-B0P53GFt.js.map +0 -1
- package/dist/chunks/RichTextEditor-Wu_yjvD7.cjs +0 -2
- package/dist/chunks/RichTextEditor-Wu_yjvD7.cjs.map +0 -1
- package/dist/chunks/overlayLayer-IuoPVwTO.js.map +0 -1
- package/dist/chunks/overlayLayer-seJG-EFn.cjs +0 -2
- package/dist/chunks/overlayLayer-seJG-EFn.cjs.map +0 -1
- package/dist/components/ColourField/focus.d.cts +0 -3
- package/dist/components/ColourField/focus.d.cts.map +0 -1
- package/dist/components/ColourField/focus.d.ts +0 -3
- package/dist/components/ColourField/focus.d.ts.map +0 -1
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
const e=require("./useIsomorphicLayoutEffect-XM4Ot6x5.cjs");let t=require("react"),n=require("react/jsx-runtime");var r=`:is(button, [href], input:not([type='hidden']), select, textarea, [tabindex], [contenteditable]:not([contenteditable='false'])):not(:disabled):not([tabindex='-1']):not([aria-hidden='true'])`;function i(e){let t=e.closest(`[contenteditable]`);return!(e.matches(`a[href]`)&&t&&t!==e&&t.getAttribute(`contenteditable`)!==`false`&&!e.hasAttribute(`tabindex`))&&(e.checkVisibility?.()??!e.closest(`[hidden]`))&&!e.closest(`[inert]`)}function a(e){return!e||e===e.ownerDocument.body||!e.isConnected||e.closest(`[aria-hidden='true'], [inert]`)!==null}function o(e,t){let n=e;for(;n;){if(n instanceof HTMLElement&&!a(n)&&(n.focus(t),n.getRootNode().activeElement===n))return!0;n=n.parentElement?.closest(`[tabindex]`)??null}return!1}function s(e){return e instanceof HTMLInputElement&&e.type===`radio`}function c(e,t){return e===t||s(e)&&s(t)&&e.name!==``&&e.name===t.name&&e.form===t.form}function l(e){let t=Array.from(e.querySelectorAll(r)).filter(i);return t.filter(e=>!s(e)||e.checked||!t.some(t=>s(t)&&t.checked&&c(t,e)))}var u=new WeakMap;function d(e,t){return u.set(e,t),()=>{u.delete(e)}}function f(e){let t=e instanceof Element?e:e.parentElement;for(;t&&!u.has(t);)t=t.parentElement;return t}function p(e,t){let n=new Set,r=f(t);for(;r&&!n.has(r);){n.add(r);let t=u.get(r);if(e.contains(t))return!0;r=f(t)}return!1}function m(e,t){return t!==null&&(e.contains(t)||p(e,t))}function h(e,t){return!!(t.compareDocumentPosition(e)&Node.DOCUMENT_POSITION_PRECEDING)}function g(e,t){if(e.key!==`Tab`||e.defaultPrevented||!t)return;let n=l(t),r=n[0],i=n.at(-1);if(!r||!i)return;let a=t.getRootNode().activeElement??document.activeElement,o=a!==null&&t.contains(a);!o&&a&&p(t,a)||(!o||(e.shiftKey?c(a,r)||h(a,r):c(a,i)||h(i,a)))&&(e.preventDefault(),(e.shiftKey?i:r).focus())}function _(e){let t=l(e.closest(`[aria-modal='true']`)??document.body).filter(e=>!e.closest(`.ds-popover`));(t[t.map(t=>e.contains(t)).lastIndexOf(!0)+1]??t[0])?.focus({preventScroll:!0})}function v(n){let r=(0,t.useRef)(n);return e.t(()=>{r.current=n}),r}var y=(0,t.createContext)(null),b=[`data-theme`,`lang`,`dir`];function x(e){let t=e.closest(`[dir]`)?getComputedStyle(e).direction||e.closest(`[dir]`).getAttribute(`dir`):null;return{"data-theme":e.closest(`[data-theme]`)?.getAttribute(`data-theme`)??null,lang:e.closest(`[lang]`)?.getAttribute(`lang`)??null,dir:t}}function S(t,n,r,{keepDir:i=!1}={}){let a=v(r);e.t(()=>{let e=t.current,r=a.current?.();if(!n||!e||!r)return;let o=()=>{for(let[t,n]of Object.entries(x(r)))t===`dir`&&i||(n===null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n))};o();let s=new MutationObserver(o);for(let e=r;e;e=e.parentElement)s.observe(e,{attributes:!0,attributeFilter:b});return()=>s.disconnect()},[t,n,i,a])}function C(e,n,r){let i=(0,t.useContext)(y);S(e,n,i&&(()=>i.current),r)}var w=(0,t.createContext)(void 0);function T({layer:e,children:t}){return(0,n.jsx)(w.Provider,{value:e,children:t})}function E(){return(0,t.useContext)(w)}var D=(0,t.createContext)(!1);function O(){return(0,t.useContext)(D)}function k(e){let t=O();return e&&!t}function A({layer:e,isSuspended:t,children:r}){return(0,n.jsx)(w.Provider,{value:e,children:(0,n.jsx)(D.Provider,{value:t,children:r})})}function j(e,n){let[r,i]=(0,t.useState)(`closed`),a=e?n?r===`closed`?`shown`:r:r===`closed`?`closed`:`suspended`:`closed`;return a!==r&&i(a),a===`suspended`}function M(e,t,n){let r=E(),i=k(!t),a=j(e,i);return{layer:n??r,isVisible:i,isResumed:a}}Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return C}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return a}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return l}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return d}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return O}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return k}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return v}});
|
|
2
|
+
//# sourceMappingURL=overlayLayer-iGhuAByk.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlayLayer-iGhuAByk.cjs","names":["useRef","createContext","useContext","createContext","useContext","useState","require_useIsomorphicLayoutEffect","react","react_jsx_runtime","focusableSelector","canTakeFocus","editingHost","element","cannotHoldFocus","focusNearest","candidate","options","isRadio","sameStop","a","b","tabbableControls","controls","container","control","other","popupAnchors","registerPopup","popup","anchor","popupAround","node","inOwnedPopup","visited","panel","panelHoldsFocus","active","precedes","trapTabFocus","event","first","last","inside","focusAfterField","root","useLatest","ref","value","PortalScopeContext","scopeAttributes","scopeOf","direction","usePortalScope","latest","getAnchor","rootRef","isOpen","sync","name","keepDir","observer","useInheritedPortalScope","LayerContext","OverlayLayer","layer","useOverlayLayer","OverlayHiddenContext","useOverlayHidden","useOverlayOpen","hidden","open","DialogContent","isSuspended","useResumed","phase","setPhase","next","isVisible","useDialogPresence","inheritedLayer","isHidden","isResumed","overlayLayer"],"sources":["../../src/internal/dialogFocus.ts","../../src/internal/useLatest.ts","../../src/internal/portalScope.ts","../../src/internal/overlayLayer.tsx"],"sourcesContent":["const focusableSelector =\n \":is(button, [href], input:not([type='hidden']), select, textarea, [tabindex], [contenteditable]:not([contenteditable='false'])):not(:disabled):not([tabindex='-1']):not([aria-hidden='true'])\";\n\n// Unrendered controls (display: none, [hidden], closed <details>) and inert\n// subtrees cannot take focus. Environments without checkVisibility fall back\n// to the hidden attribute.\nfunction canTakeFocus(element: HTMLElement) {\n const editingHost = element.closest(\"[contenteditable]\");\n // A link being edited is document content, not a native Tab stop. Explicit\n // tabindex and links inside noneditable widgets still participate normally.\n const writingLink =\n element.matches(\"a[href]\") &&\n editingHost &&\n editingHost !== element &&\n editingHost.getAttribute(\"contenteditable\") !== \"false\" &&\n !element.hasAttribute(\"tabindex\");\n return (\n !writingLink &&\n (element.checkVisibility?.() ?? !element.closest(\"[hidden]\")) &&\n !element.closest(\"[inert]\")\n );\n}\n\n/** Removed, hidden and inert elements can't keep focus, and neither can the page. */\nexport function cannotHoldFocus(element: Element | null) {\n return (\n !element ||\n element === element.ownerDocument.body ||\n !element.isConnected ||\n element.closest(\"[aria-hidden='true'], [inert]\") !== null\n );\n}\n\n/**\n * Focuses `element`, or, when it can no longer take focus (disabled, or no\n * longer editable), its nearest ancestor with a tabindex, such as an enclosing\n * dialog panel. Returns whether anything took focus.\n */\nexport function focusNearest(element: Element | null, options?: FocusOptions) {\n let candidate = element;\n while (candidate) {\n if (candidate instanceof HTMLElement && !cannotHoldFocus(candidate)) {\n candidate.focus(options);\n if ((candidate.getRootNode() as Document | ShadowRoot).activeElement === candidate) {\n return true;\n }\n }\n candidate = candidate.parentElement?.closest(\"[tabindex]\") ?? null;\n }\n return false;\n}\n\nfunction isRadio(element: Element | null): element is HTMLInputElement {\n return element instanceof HTMLInputElement && element.type === \"radio\";\n}\n\n/** Radios sharing a name and form are one Tab stop. */\nfunction sameStop(a: Element, b: Element) {\n return (\n a === b || (isRadio(a) && isRadio(b) && a.name !== \"\" && a.name === b.name && a.form === b.form)\n );\n}\n\n/**\n * The controls Tab visits inside `container`, in document order. A radio group\n * contributes only its checked radio, or every radio while none is checked.\n */\nexport function tabbableControls(container: HTMLElement) {\n const controls = Array.from(container.querySelectorAll<HTMLElement>(focusableSelector)).filter(\n canTakeFocus,\n );\n return controls.filter(\n (control) =>\n !isRadio(control) ||\n control.checked ||\n !controls.some((other) => isRadio(other) && other.checked && sameStop(other, control)),\n );\n}\n\nconst popupAnchors = new WeakMap<Element, Element>();\n\n/**\n * Popups portal outside the dialog that opened them. Registering one with its\n * anchor lets that dialog's Tab trap treat the popup as its own.\n */\nexport function registerPopup(popup: Element, anchor: Element) {\n popupAnchors.set(popup, anchor);\n return () => {\n popupAnchors.delete(popup);\n };\n}\n\nfunction popupAround(node: Node) {\n let element = node instanceof Element ? node : node.parentElement;\n while (element && !popupAnchors.has(element)) {\n element = element.parentElement;\n }\n return element;\n}\n\n/** Inside a popup anchored in the panel, directly or through other popups. */\nfunction inOwnedPopup(panel: HTMLElement, node: Node) {\n const visited = new Set<Element>();\n let popup = popupAround(node);\n while (popup && !visited.has(popup)) {\n visited.add(popup);\n const anchor = popupAnchors.get(popup)!;\n if (panel.contains(anchor)) {\n return true;\n }\n popup = popupAround(anchor);\n }\n return false;\n}\n\n/** Focus in the panel or in a popup it owns, such as a menu that resumed with it. */\nexport function panelHoldsFocus(panel: HTMLElement, active: Element | null) {\n return active !== null && (panel.contains(active) || inOwnedPopup(panel, active));\n}\n\n/** `a` comes before `b` in document order, including as its ancestor. */\nfunction precedes(a: Node, b: Node) {\n return Boolean(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);\n}\n\n/**\n * Keeps Tab inside an aria-modal panel. Call only for the topmost dialog.\n * Focus that left the panel returns to its first control (last with Shift);\n * Tab inside a popup the panel owns is left to the popup and the browser.\n */\nexport function trapTabFocus(event: KeyboardEvent, panel: HTMLElement | null) {\n if (event.key !== \"Tab\" || event.defaultPrevented || !panel) {\n return;\n }\n const controls = tabbableControls(panel);\n const first = controls[0];\n const last = controls.at(-1);\n if (!first || !last) {\n return;\n }\n // document.activeElement stops at the host of a shadow root holding the panel.\n const active =\n (panel.getRootNode() as Document | ShadowRoot).activeElement ?? document.activeElement;\n const inside = active !== null && panel.contains(active);\n if (!inside && active && inOwnedPopup(panel, active)) {\n return;\n }\n // Focus on the panel itself, or on another untabbable element beyond the\n // first or last control, would otherwise leave the panel.\n const wraps =\n !inside ||\n (event.shiftKey\n ? sameStop(active, first) || precedes(active, first)\n : sameStop(active, last) || precedes(last, active));\n if (wraps) {\n event.preventDefault();\n (event.shiftKey ? last : first).focus();\n }\n}\n\n/** Continue after the composed field, respecting an enclosing modal's focus boundary. */\nexport function focusAfterField(root: HTMLElement) {\n const boundary = root.closest<HTMLElement>(\"[aria-modal='true']\") ?? document.body;\n const controls = tabbableControls(boundary).filter((element) => !element.closest(\".ds-popover\"));\n const last = controls.map((element) => root.contains(element)).lastIndexOf(true);\n const next = controls[last + 1] ?? controls[0];\n next?.focus({ preventScroll: true });\n}\n","import { useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\n\n/**\n * The latest value, read when a callback or effect runs, so inline callbacks\n * never restart effects. Updated before layout effects and passive effects that\n * are declared after it read it.\n */\nexport function useLatest<T>(value: T) {\n const ref = useRef(value);\n useIsomorphicLayoutEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n","import { createContext, useContext, type RefObject } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useLatest } from \"./useLatest\";\n\n/**\n * The inline element whose theme, direction and language body-mounted overlays\n * opened from inside it carry: RichTextEditor's frame, or a Popover's anchor.\n * Nested overlays inherit the same inline anchor rather than their parent's\n * panel, so they never depend on the order in which overlays mount.\n */\nexport const PortalScopeContext = createContext<RefObject<Element | null> | null>(null);\n\nconst scopeAttributes = [\"data-theme\", \"lang\", \"dir\"];\n\nfunction scopeOf(anchor: Element) {\n const direction = anchor.closest(\"[dir]\")\n ? getComputedStyle(anchor).direction || anchor.closest(\"[dir]\")!.getAttribute(\"dir\")\n : null;\n return {\n \"data-theme\": anchor.closest(\"[data-theme]\")?.getAttribute(\"data-theme\") ?? null,\n lang: anchor.closest(\"[lang]\")?.getAttribute(\"lang\") ?? null,\n dir: direction,\n };\n}\n\n/**\n * Copies the anchor's `data-theme`, `lang` and `dir` onto an overlay root while\n * it is open, and follows later changes to those attributes on the anchor's\n * ancestors. Attributes rather than resolved values, so the theme's whole\n * stylesheet keeps applying, including `color-scheme` and media queries.\n * Without an anchor the overlay inherits from the document root, as before.\n */\nexport function usePortalScope(\n rootRef: RefObject<HTMLElement | null>,\n isOpen: boolean,\n getAnchor: (() => Element | null | undefined) | null,\n { keepDir = false }: { keepDir?: boolean } = {},\n) {\n const latest = useLatest(getAnchor);\n\n useIsomorphicLayoutEffect(() => {\n const root = rootRef.current;\n const anchor = latest.current?.();\n if (!isOpen || !root || !anchor) {\n return;\n }\n const sync = () => {\n for (const [name, value] of Object.entries(scopeOf(anchor))) {\n if (name === \"dir\" && keepDir) {\n continue;\n }\n if (value === null) {\n root.removeAttribute(name);\n } else if (root.getAttribute(name) !== value) {\n root.setAttribute(name, value);\n }\n }\n };\n sync();\n // Only scoping attributes: class and style churn on ancestors never re-applies.\n const observer = new MutationObserver(sync);\n for (let node: Element | null = anchor; node; node = node.parentElement) {\n observer.observe(node, { attributes: true, attributeFilter: scopeAttributes });\n }\n return () => observer.disconnect();\n }, [rootRef, isOpen, keepDir, latest]);\n}\n\n/** Applies the scope of the inline anchor an enclosing editor or popover provides, if any. */\nexport function useInheritedPortalScope(\n rootRef: RefObject<HTMLElement | null>,\n isOpen: boolean,\n options?: { keepDir?: boolean },\n) {\n const anchor = useContext(PortalScopeContext);\n usePortalScope(rootRef, isOpen, anchor && (() => anchor.current), options);\n}\n","import { createContext, useContext, useState, type ReactNode } from \"react\";\n\nconst LayerContext = createContext<number | undefined>(undefined);\n\n/**\n * Layer used by dialogs and popovers opened from this content, including\n * portaled editors. Keep it below the toast layer (80) so toasts stay visible.\n */\nexport function OverlayLayer({ layer, children }: { layer: number; children: ReactNode }) {\n return <LayerContext.Provider value={layer}>{children}</LayerContext.Provider>;\n}\nexport function useOverlayLayer() {\n return useContext(LayerContext);\n}\n\nconst OverlayHiddenContext = createContext(false);\nexport function useOverlayHidden() {\n return useContext(OverlayHiddenContext);\n}\n/** Suspend nested overlay controllers without changing their owner's open state. */\nexport function useOverlayOpen(open: boolean) {\n const hidden = useOverlayHidden();\n return open && !hidden;\n}\n\n/**\n * What a dialog hands its content: its layer, so nested dialogs and popovers\n * paint above it, and its suspension, so their controllers pause with it.\n */\nexport function DialogContent({\n layer,\n isSuspended,\n children,\n}: {\n layer: number | undefined;\n isSuspended: boolean;\n children: ReactNode;\n}) {\n return (\n <LayerContext.Provider value={layer}>\n <OverlayHiddenContext.Provider value={isSuspended}>{children}</OverlayHiddenContext.Provider>\n </LayerContext.Provider>\n );\n}\n\n/**\n * True once an open dialog has been suspended, so it resumes in place instead\n * of replaying its entry motion. Opening again starts over.\n */\nfunction useResumed(isOpen: boolean, isVisible: boolean) {\n const [phase, setPhase] = useState<\"closed\" | \"shown\" | \"suspended\">(\"closed\");\n const next = !isOpen\n ? \"closed\"\n : isVisible\n ? phase === \"closed\"\n ? \"shown\"\n : phase\n : phase === \"closed\"\n ? \"closed\"\n : \"suspended\";\n if (next !== phase) {\n setPhase(next);\n }\n return next === \"suspended\";\n}\n\n/**\n * Where an open dialog sits: its layer (its own, else its surroundings'),\n * whether a suspended ancestor or `isHidden` hides it, and whether it is\n * resuming from such a suspension.\n */\nexport function useDialogPresence(isOpen: boolean, isHidden: boolean, overlayLayer?: number) {\n const inheritedLayer = useOverlayLayer();\n const isVisible = useOverlayOpen(!isHidden);\n const isResumed = useResumed(isOpen, isVisible);\n return { layer: overlayLayer ?? inheritedLayer, isVisible, isResumed };\n}\n"],"mappings":"A,kHAAA,IAAMS,EACJ,gMAKF,SAASC,EAAa,EAAsB,CAC1C,IAAMC,EAAcC,EAAQ,QAAQ,mBAAmB,EASvD,MACE,EANAA,EAAQ,QAAQ,SAAS,GACzBD,GACAA,IAAgBC,GAChBD,EAAY,aAAa,iBAAiB,IAAM,SAChD,CAACC,EAAQ,aAAa,UAAU,KAG/BA,EAAQ,kBAAkB,GAAK,CAACA,EAAQ,QAAQ,UAAU,IAC3D,CAACA,EAAQ,QAAQ,SAAS,CAE9B,CAGA,SAAgBC,EAAgB,EAAyB,CACvD,MACE,CAACD,GACDA,IAAYA,EAAQ,cAAc,MAClC,CAACA,EAAQ,aACTA,EAAQ,QAAQ,+BAA+B,IAAM,IAEzD,CAOA,SAAgBE,EAAa,EAAyB,EAAwB,CAC5E,IAAIC,EAAYH,EAChB,KAAOG,GAAW,CAChB,GAAIA,aAAqB,aAAe,CAACF,EAAgBE,CAAS,IAChEA,EAAU,MAAMC,CAAO,EAClBD,EAAU,YAAY,CAAC,CAA2B,gBAAkBA,GACvE,MAAO,GAGX,EAAYA,EAAU,eAAe,QAAQ,YAAY,GAAK,IAChE,CACA,MAAO,EACT,CAEA,SAASE,EAAQ,EAAsD,CACrE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A,EAAS,EAMhE,SAAgB4D,EAAa,CAAE,QAAO,YAAoD,CACxF,OAAO,EAAAvD,EAAA,IAAA,CAACsD,EAAa,SAAd,CAAuB,MAAOE,EAAQ,UAAgC,CAAA,CAC/E,CACA,SAAgBC,GAAkB,CAChC,OAAA,EAAO7D,EAAAA,WAAAA,CAAW0D,CAAY,CAChC,CAEA,IAAMI,GAAA,EAAuB/D,EAAAA,cAAAA,CAAc,EAAK,EAChD,SAAgBgE,GAAmB,CACjC,OAAA,EAAO/D,EAAAA,WAAAA,CAAW8D,CAAoB,CACxC,CAEA,SAAgBE,EAAe,EAAe,CAC5C,IAAMC,EAASF,EAAiB,EAChC,OAAOG,GAAQ,CAACD,CAClB,CAMA,SAAgBE,EAAc,CAC5B,QACA,cACA,YAKC,CACD,OACE,EAAA/D,EAAA,IAAA,CAACsD,EAAa,SAAd,CAAuB,MAAOE,EAC5B,UAAA,EAAAxD,EAAA,IAAA,CAAC0D,EAAqB,SAAtB,CAA+B,MAAOM,EAAc,UAAwC,CAAA,CACvE,CAAA,CAE3B,CAMA,SAASC,EAAW,EAAiB,EAAoB,CACvD,GAAM,CAACC,EAAOC,IAAA,EAAYtE,EAAAA,SAAAA,CAA2C,QAAQ,EACvEuE,EAAQpB,EAEVqB,EACEH,IAAU,SACR,QACAA,EACFA,IAAU,SACR,SACA,YAPJ,SAWJ,OAHIE,IAASF,GACXC,EAASC,CAAI,EAERA,IAAS,WAClB,CAOA,SAAgBE,EAAkB,EAAiB,EAAmB,EAAuB,CAC3F,IAAMC,EAAiBd,EAAgB,EACjCY,EAAYT,EAAe,CAACY,CAAQ,EACpCC,EAAYR,EAAWjB,EAAQqB,CAAS,EAC9C,MAAO,CAAE,MAAOK,GAAgBH,EAAgB,YAAW,WAAU,CACvE,C"}
|
|
@@ -62,9 +62,13 @@ function y(e, t) {
|
|
|
62
62
|
let a = t.getRootNode().activeElement ?? document.activeElement, o = a !== null && t.contains(a);
|
|
63
63
|
!o && a && g(t, a) || (!o || (e.shiftKey ? d(a, r) || v(a, r) : d(a, i) || v(i, a))) && (e.preventDefault(), (e.shiftKey ? i : r).focus());
|
|
64
64
|
}
|
|
65
|
+
function b(e) {
|
|
66
|
+
let t = f(e.closest("[aria-modal='true']") ?? document.body).filter((e) => !e.closest(".ds-popover"));
|
|
67
|
+
(t[t.map((t) => e.contains(t)).lastIndexOf(!0) + 1] ?? t[0])?.focus({ preventScroll: !0 });
|
|
68
|
+
}
|
|
65
69
|
//#endregion
|
|
66
70
|
//#region src/internal/useLatest.ts
|
|
67
|
-
function
|
|
71
|
+
function x(t) {
|
|
68
72
|
let n = r(t);
|
|
69
73
|
return e(() => {
|
|
70
74
|
n.current = t;
|
|
@@ -72,12 +76,12 @@ function b(t) {
|
|
|
72
76
|
}
|
|
73
77
|
//#endregion
|
|
74
78
|
//#region src/internal/portalScope.ts
|
|
75
|
-
var
|
|
79
|
+
var S = t(null), C = [
|
|
76
80
|
"data-theme",
|
|
77
81
|
"lang",
|
|
78
82
|
"dir"
|
|
79
83
|
];
|
|
80
|
-
function
|
|
84
|
+
function w(e) {
|
|
81
85
|
let t = e.closest("[dir]") ? getComputedStyle(e).direction || e.closest("[dir]").getAttribute("dir") : null;
|
|
82
86
|
return {
|
|
83
87
|
"data-theme": e.closest("[data-theme]")?.getAttribute("data-theme") ?? null,
|
|
@@ -85,19 +89,19 @@ function C(e) {
|
|
|
85
89
|
dir: t
|
|
86
90
|
};
|
|
87
91
|
}
|
|
88
|
-
function
|
|
89
|
-
let a =
|
|
92
|
+
function T(t, n, r, { keepDir: i = !1 } = {}) {
|
|
93
|
+
let a = x(r);
|
|
90
94
|
e(() => {
|
|
91
95
|
let e = t.current, r = a.current?.();
|
|
92
96
|
if (!n || !e || !r) return;
|
|
93
97
|
let o = () => {
|
|
94
|
-
for (let [t, n] of Object.entries(
|
|
98
|
+
for (let [t, n] of Object.entries(w(r))) t === "dir" && i || (n === null ? e.removeAttribute(t) : e.getAttribute(t) !== n && e.setAttribute(t, n));
|
|
95
99
|
};
|
|
96
100
|
o();
|
|
97
101
|
let s = new MutationObserver(o);
|
|
98
102
|
for (let e = r; e; e = e.parentElement) s.observe(e, {
|
|
99
103
|
attributes: !0,
|
|
100
|
-
attributeFilter:
|
|
104
|
+
attributeFilter: C
|
|
101
105
|
});
|
|
102
106
|
return () => s.disconnect();
|
|
103
107
|
}, [
|
|
@@ -107,45 +111,45 @@ function w(t, n, r, { keepDir: i = !1 } = {}) {
|
|
|
107
111
|
a
|
|
108
112
|
]);
|
|
109
113
|
}
|
|
110
|
-
function
|
|
111
|
-
let i = n(
|
|
112
|
-
|
|
114
|
+
function E(e, t, r) {
|
|
115
|
+
let i = n(S);
|
|
116
|
+
T(e, t, i && (() => i.current), r);
|
|
113
117
|
}
|
|
114
118
|
//#endregion
|
|
115
119
|
//#region src/internal/overlayLayer.tsx
|
|
116
|
-
var
|
|
117
|
-
function
|
|
118
|
-
return /* @__PURE__ */ a(
|
|
120
|
+
var D = t(void 0);
|
|
121
|
+
function O({ layer: e, children: t }) {
|
|
122
|
+
return /* @__PURE__ */ a(D.Provider, {
|
|
119
123
|
value: e,
|
|
120
124
|
children: t
|
|
121
125
|
});
|
|
122
126
|
}
|
|
123
|
-
function
|
|
124
|
-
return n(
|
|
127
|
+
function k() {
|
|
128
|
+
return n(D);
|
|
125
129
|
}
|
|
126
|
-
var
|
|
127
|
-
function
|
|
128
|
-
return n(
|
|
130
|
+
var A = t(!1);
|
|
131
|
+
function j() {
|
|
132
|
+
return n(A);
|
|
129
133
|
}
|
|
130
|
-
function
|
|
131
|
-
let t =
|
|
134
|
+
function M(e) {
|
|
135
|
+
let t = j();
|
|
132
136
|
return e && !t;
|
|
133
137
|
}
|
|
134
|
-
function
|
|
135
|
-
return /* @__PURE__ */ a(
|
|
138
|
+
function N({ layer: e, isSuspended: t, children: n }) {
|
|
139
|
+
return /* @__PURE__ */ a(D.Provider, {
|
|
136
140
|
value: e,
|
|
137
|
-
children: /* @__PURE__ */ a(
|
|
141
|
+
children: /* @__PURE__ */ a(A.Provider, {
|
|
138
142
|
value: t,
|
|
139
143
|
children: n
|
|
140
144
|
})
|
|
141
145
|
});
|
|
142
146
|
}
|
|
143
|
-
function
|
|
147
|
+
function P(e, t) {
|
|
144
148
|
let [n, r] = i("closed"), a = e ? t ? n === "closed" ? "shown" : n : n === "closed" ? "closed" : "suspended" : "closed";
|
|
145
149
|
return a !== n && r(a), a === "suspended";
|
|
146
150
|
}
|
|
147
|
-
function
|
|
148
|
-
let r =
|
|
151
|
+
function F(e, t, n) {
|
|
152
|
+
let r = k(), i = M(!t), a = P(e, i);
|
|
149
153
|
return {
|
|
150
154
|
layer: n ?? r,
|
|
151
155
|
isVisible: i,
|
|
@@ -153,6 +157,6 @@ function P(e, t, n) {
|
|
|
153
157
|
};
|
|
154
158
|
}
|
|
155
159
|
//#endregion
|
|
156
|
-
export {
|
|
160
|
+
export { y as _, k as a, E as c, c as d, b as f, f as g, m as h, j as i, T as l, _ as m, O as n, M as o, l as p, F as r, S as s, N as t, x as u };
|
|
157
161
|
|
|
158
|
-
//# sourceMappingURL=overlayLayer-
|
|
162
|
+
//# sourceMappingURL=overlayLayer-lU4iWSjO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlayLayer-lU4iWSjO.js","names":["useIsomorphicLayoutEffect","focusableSelector","canTakeFocus","editingHost","element","cannotHoldFocus","focusNearest","candidate","options","isRadio","sameStop","a","b","tabbableControls","controls","container","control","other","popupAnchors","registerPopup","popup","anchor","popupAround","node","inOwnedPopup","visited","panel","panelHoldsFocus","active","precedes","trapTabFocus","event","first","last","inside","focusAfterField","root","useLatest","ref","useRef","value","PortalScopeContext","createContext","scopeAttributes","scopeOf","direction","usePortalScope","latest","getAnchor","rootRef","isOpen","sync","name","keepDir","observer","useInheritedPortalScope","useContext","LayerContext","OverlayLayer","layer","useOverlayLayer","OverlayHiddenContext","useOverlayHidden","useOverlayOpen","hidden","open","DialogContent","isSuspended","useResumed","phase","setPhase","useState","next","isVisible","useDialogPresence","inheritedLayer","isHidden","isResumed","overlayLayer"],"sources":["../../src/internal/dialogFocus.ts","../../src/internal/useLatest.ts","../../src/internal/portalScope.ts","../../src/internal/overlayLayer.tsx"],"sourcesContent":["const focusableSelector =\n \":is(button, [href], input:not([type='hidden']), select, textarea, [tabindex], [contenteditable]:not([contenteditable='false'])):not(:disabled):not([tabindex='-1']):not([aria-hidden='true'])\";\n\n// Unrendered controls (display: none, [hidden], closed <details>) and inert\n// subtrees cannot take focus. Environments without checkVisibility fall back\n// to the hidden attribute.\nfunction canTakeFocus(element: HTMLElement) {\n const editingHost = element.closest(\"[contenteditable]\");\n // A link being edited is document content, not a native Tab stop. Explicit\n // tabindex and links inside noneditable widgets still participate normally.\n const writingLink =\n element.matches(\"a[href]\") &&\n editingHost &&\n editingHost !== element &&\n editingHost.getAttribute(\"contenteditable\") !== \"false\" &&\n !element.hasAttribute(\"tabindex\");\n return (\n !writingLink &&\n (element.checkVisibility?.() ?? !element.closest(\"[hidden]\")) &&\n !element.closest(\"[inert]\")\n );\n}\n\n/** Removed, hidden and inert elements can't keep focus, and neither can the page. */\nexport function cannotHoldFocus(element: Element | null) {\n return (\n !element ||\n element === element.ownerDocument.body ||\n !element.isConnected ||\n element.closest(\"[aria-hidden='true'], [inert]\") !== null\n );\n}\n\n/**\n * Focuses `element`, or, when it can no longer take focus (disabled, or no\n * longer editable), its nearest ancestor with a tabindex, such as an enclosing\n * dialog panel. Returns whether anything took focus.\n */\nexport function focusNearest(element: Element | null, options?: FocusOptions) {\n let candidate = element;\n while (candidate) {\n if (candidate instanceof HTMLElement && !cannotHoldFocus(candidate)) {\n candidate.focus(options);\n if ((candidate.getRootNode() as Document | ShadowRoot).activeElement === candidate) {\n return true;\n }\n }\n candidate = candidate.parentElement?.closest(\"[tabindex]\") ?? null;\n }\n return false;\n}\n\nfunction isRadio(element: Element | null): element is HTMLInputElement {\n return element instanceof HTMLInputElement && element.type === \"radio\";\n}\n\n/** Radios sharing a name and form are one Tab stop. */\nfunction sameStop(a: Element, b: Element) {\n return (\n a === b || (isRadio(a) && isRadio(b) && a.name !== \"\" && a.name === b.name && a.form === b.form)\n );\n}\n\n/**\n * The controls Tab visits inside `container`, in document order. A radio group\n * contributes only its checked radio, or every radio while none is checked.\n */\nexport function tabbableControls(container: HTMLElement) {\n const controls = Array.from(container.querySelectorAll<HTMLElement>(focusableSelector)).filter(\n canTakeFocus,\n );\n return controls.filter(\n (control) =>\n !isRadio(control) ||\n control.checked ||\n !controls.some((other) => isRadio(other) && other.checked && sameStop(other, control)),\n );\n}\n\nconst popupAnchors = new WeakMap<Element, Element>();\n\n/**\n * Popups portal outside the dialog that opened them. Registering one with its\n * anchor lets that dialog's Tab trap treat the popup as its own.\n */\nexport function registerPopup(popup: Element, anchor: Element) {\n popupAnchors.set(popup, anchor);\n return () => {\n popupAnchors.delete(popup);\n };\n}\n\nfunction popupAround(node: Node) {\n let element = node instanceof Element ? node : node.parentElement;\n while (element && !popupAnchors.has(element)) {\n element = element.parentElement;\n }\n return element;\n}\n\n/** Inside a popup anchored in the panel, directly or through other popups. */\nfunction inOwnedPopup(panel: HTMLElement, node: Node) {\n const visited = new Set<Element>();\n let popup = popupAround(node);\n while (popup && !visited.has(popup)) {\n visited.add(popup);\n const anchor = popupAnchors.get(popup)!;\n if (panel.contains(anchor)) {\n return true;\n }\n popup = popupAround(anchor);\n }\n return false;\n}\n\n/** Focus in the panel or in a popup it owns, such as a menu that resumed with it. */\nexport function panelHoldsFocus(panel: HTMLElement, active: Element | null) {\n return active !== null && (panel.contains(active) || inOwnedPopup(panel, active));\n}\n\n/** `a` comes before `b` in document order, including as its ancestor. */\nfunction precedes(a: Node, b: Node) {\n return Boolean(b.compareDocumentPosition(a) & Node.DOCUMENT_POSITION_PRECEDING);\n}\n\n/**\n * Keeps Tab inside an aria-modal panel. Call only for the topmost dialog.\n * Focus that left the panel returns to its first control (last with Shift);\n * Tab inside a popup the panel owns is left to the popup and the browser.\n */\nexport function trapTabFocus(event: KeyboardEvent, panel: HTMLElement | null) {\n if (event.key !== \"Tab\" || event.defaultPrevented || !panel) {\n return;\n }\n const controls = tabbableControls(panel);\n const first = controls[0];\n const last = controls.at(-1);\n if (!first || !last) {\n return;\n }\n // document.activeElement stops at the host of a shadow root holding the panel.\n const active =\n (panel.getRootNode() as Document | ShadowRoot).activeElement ?? document.activeElement;\n const inside = active !== null && panel.contains(active);\n if (!inside && active && inOwnedPopup(panel, active)) {\n return;\n }\n // Focus on the panel itself, or on another untabbable element beyond the\n // first or last control, would otherwise leave the panel.\n const wraps =\n !inside ||\n (event.shiftKey\n ? sameStop(active, first) || precedes(active, first)\n : sameStop(active, last) || precedes(last, active));\n if (wraps) {\n event.preventDefault();\n (event.shiftKey ? last : first).focus();\n }\n}\n\n/** Continue after the composed field, respecting an enclosing modal's focus boundary. */\nexport function focusAfterField(root: HTMLElement) {\n const boundary = root.closest<HTMLElement>(\"[aria-modal='true']\") ?? document.body;\n const controls = tabbableControls(boundary).filter((element) => !element.closest(\".ds-popover\"));\n const last = controls.map((element) => root.contains(element)).lastIndexOf(true);\n const next = controls[last + 1] ?? controls[0];\n next?.focus({ preventScroll: true });\n}\n","import { useRef } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\n\n/**\n * The latest value, read when a callback or effect runs, so inline callbacks\n * never restart effects. Updated before layout effects and passive effects that\n * are declared after it read it.\n */\nexport function useLatest<T>(value: T) {\n const ref = useRef(value);\n useIsomorphicLayoutEffect(() => {\n ref.current = value;\n });\n return ref;\n}\n","import { createContext, useContext, type RefObject } from \"react\";\nimport { useIsomorphicLayoutEffect } from \"./useIsomorphicLayoutEffect\";\nimport { useLatest } from \"./useLatest\";\n\n/**\n * The inline element whose theme, direction and language body-mounted overlays\n * opened from inside it carry: RichTextEditor's frame, or a Popover's anchor.\n * Nested overlays inherit the same inline anchor rather than their parent's\n * panel, so they never depend on the order in which overlays mount.\n */\nexport const PortalScopeContext = createContext<RefObject<Element | null> | null>(null);\n\nconst scopeAttributes = [\"data-theme\", \"lang\", \"dir\"];\n\nfunction scopeOf(anchor: Element) {\n const direction = anchor.closest(\"[dir]\")\n ? getComputedStyle(anchor).direction || anchor.closest(\"[dir]\")!.getAttribute(\"dir\")\n : null;\n return {\n \"data-theme\": anchor.closest(\"[data-theme]\")?.getAttribute(\"data-theme\") ?? null,\n lang: anchor.closest(\"[lang]\")?.getAttribute(\"lang\") ?? null,\n dir: direction,\n };\n}\n\n/**\n * Copies the anchor's `data-theme`, `lang` and `dir` onto an overlay root while\n * it is open, and follows later changes to those attributes on the anchor's\n * ancestors. Attributes rather than resolved values, so the theme's whole\n * stylesheet keeps applying, including `color-scheme` and media queries.\n * Without an anchor the overlay inherits from the document root, as before.\n */\nexport function usePortalScope(\n rootRef: RefObject<HTMLElement | null>,\n isOpen: boolean,\n getAnchor: (() => Element | null | undefined) | null,\n { keepDir = false }: { keepDir?: boolean } = {},\n) {\n const latest = useLatest(getAnchor);\n\n useIsomorphicLayoutEffect(() => {\n const root = rootRef.current;\n const anchor = latest.current?.();\n if (!isOpen || !root || !anchor) {\n return;\n }\n const sync = () => {\n for (const [name, value] of Object.entries(scopeOf(anchor))) {\n if (name === \"dir\" && keepDir) {\n continue;\n }\n if (value === null) {\n root.removeAttribute(name);\n } else if (root.getAttribute(name) !== value) {\n root.setAttribute(name, value);\n }\n }\n };\n sync();\n // Only scoping attributes: class and style churn on ancestors never re-applies.\n const observer = new MutationObserver(sync);\n for (let node: Element | null = anchor; node; node = node.parentElement) {\n observer.observe(node, { attributes: true, attributeFilter: scopeAttributes });\n }\n return () => observer.disconnect();\n }, [rootRef, isOpen, keepDir, latest]);\n}\n\n/** Applies the scope of the inline anchor an enclosing editor or popover provides, if any. */\nexport function useInheritedPortalScope(\n rootRef: RefObject<HTMLElement | null>,\n isOpen: boolean,\n options?: { keepDir?: boolean },\n) {\n const anchor = useContext(PortalScopeContext);\n usePortalScope(rootRef, isOpen, anchor && (() => anchor.current), options);\n}\n","import { createContext, useContext, useState, type ReactNode } from \"react\";\n\nconst LayerContext = createContext<number | undefined>(undefined);\n\n/**\n * Layer used by dialogs and popovers opened from this content, including\n * portaled editors. Keep it below the toast layer (80) so toasts stay visible.\n */\nexport function OverlayLayer({ layer, children }: { layer: number; children: ReactNode }) {\n return <LayerContext.Provider value={layer}>{children}</LayerContext.Provider>;\n}\nexport function useOverlayLayer() {\n return useContext(LayerContext);\n}\n\nconst OverlayHiddenContext = createContext(false);\nexport function useOverlayHidden() {\n return useContext(OverlayHiddenContext);\n}\n/** Suspend nested overlay controllers without changing their owner's open state. */\nexport function useOverlayOpen(open: boolean) {\n const hidden = useOverlayHidden();\n return open && !hidden;\n}\n\n/**\n * What a dialog hands its content: its layer, so nested dialogs and popovers\n * paint above it, and its suspension, so their controllers pause with it.\n */\nexport function DialogContent({\n layer,\n isSuspended,\n children,\n}: {\n layer: number | undefined;\n isSuspended: boolean;\n children: ReactNode;\n}) {\n return (\n <LayerContext.Provider value={layer}>\n <OverlayHiddenContext.Provider value={isSuspended}>{children}</OverlayHiddenContext.Provider>\n </LayerContext.Provider>\n );\n}\n\n/**\n * True once an open dialog has been suspended, so it resumes in place instead\n * of replaying its entry motion. Opening again starts over.\n */\nfunction useResumed(isOpen: boolean, isVisible: boolean) {\n const [phase, setPhase] = useState<\"closed\" | \"shown\" | \"suspended\">(\"closed\");\n const next = !isOpen\n ? \"closed\"\n : isVisible\n ? phase === \"closed\"\n ? \"shown\"\n : phase\n : phase === \"closed\"\n ? \"closed\"\n : \"suspended\";\n if (next !== phase) {\n setPhase(next);\n }\n return next === \"suspended\";\n}\n\n/**\n * Where an open dialog sits: its layer (its own, else its surroundings'),\n * whether a suspended ancestor or `isHidden` hides it, and whether it is\n * resuming from such a suspension.\n */\nexport function useDialogPresence(isOpen: boolean, isHidden: boolean, overlayLayer?: number) {\n const inheritedLayer = useOverlayLayer();\n const isVisible = useOverlayOpen(!isHidden);\n const isResumed = useResumed(isOpen, isVisible);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OM;GAAc;EAAwC,CAAA;CACvE,CAAA;AAE3B;AAMA,SAASC,EAAW,GAAiB,GAAoB;CACvD,IAAM,CAACC,GAAOC,KAAYC,EAA2C,QAAQ,GACvEC,IAAQtB,IAEVuB,IACEJ,MAAU,WACR,UACAA,IACFA,MAAU,WACR,WACA,cAPJ;CAWJ,OAHIG,MAASH,KACXC,EAASE,CAAI,GAERA,MAAS;AAClB;AAOA,SAAgBE,EAAkB,GAAiB,GAAmB,GAAuB;CAC3F,IAAMC,IAAiBf,EAAgB,GACjCa,IAAYV,EAAe,CAACa,CAAQ,GACpCC,IAAYT,EAAWlB,GAAQuB,CAAS;CAC9C,OAAO;EAAE,OAAOK,KAAgBH;EAAgB;EAAW;CAAU;AACvE"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"style-7Z_xRlQx.js","names":["FieldFrame","useGroupBinding","fieldAttributes","FieldGroup","binding","useReportedLimit","limit","useEffect","frame","count","attributes","children"],"sources":["../../src/components/Field/group.tsx"],"sourcesContent":["import { useEffect, type ReactNode } from \"react\";\nimport { FieldFrame } from \"./frame\";\nimport { fieldAttributes, useGroupBinding } from \"./binding\";\nimport type { FieldBinding, FieldProps } from \"./types\";\nimport { useReportedLimit } from \"./useLimit\";\n\nexport interface FieldGroupProps extends FieldBinding, Omit<FieldProps, \"children\" | \"isGroup\"> {\n children: ReactNode;\n className?: string;\n}\n\n/**\n * Standalone groups render their own Field frame. Bound to an enclosing Field,\n * they render only their controls and report their count to its label.\n */\nexport function FieldGroup({\n label,\n hint,\n error,\n isRequired,\n count,\n limit,\n limitDisplay,\n limitVisibility,\n showLimitRing,\n children,\n className,\n ...binding\n}: FieldGroupProps) {\n const { frame, attributes } = useGroupBinding(binding);\n useReportedLimit(binding, limit);\n useEffect(() => {\n if (!frame || count === undefined) {\n return;\n }\n frame.reportCount(count);\n return () => frame.reportCount(undefined);\n }, [frame, count]);\n if (frame) {\n return (\n <div\n {...attributes}\n className={className}\n >\n {children}\n </div>\n );\n }\n return (\n <FieldFrame\n label={label}\n hint={hint}\n error={error}\n isRequired={isRequired}\n count={count}\n limit={limit}\n limitDisplay={limitDisplay}\n limitVisibility={limitVisibility}\n showLimitRing={showLimitRing}\n isGroup\n className={className}\n groupBinding={fieldAttributes(binding)}\n >\n {() => children}\n </FieldFrame>\n );\n}\n"],"mappings":";;;;;;AAeA,SAAgBG,EAAW,EACzB,UACA,SACA,UACA,eACA,UACA,UACA,iBACA,oBACA,kBACA,aACA,cACA,GAAGC,KACe;CAClB,IAAM,EAAE,UAAO,kBAAeH,EAAgBG,CAAO;CAmBrD,OAlBAC,EAAiBD,GAASE,CAAK,GAC/BC,QAAgB;EACd,IAAKC,KAASC,MAAU,KAAA,GAIxB,OADAD,EAAM,YAAYC,CAAK,SACVD,EAAM,YAAY,KAAA,CAAS;CAC1C,GAAG,CAACA,GAAOC,CAAK,CAAC,GACbD,IAEA,kBAAC,OAAD;EACE,GAAIE;EACO;EAEV;CACE,CAAA,IAIP,kBAACV,GAAD;EACS;EACD;EACC;EACK;EACL;EACA;EACO;EACG;EACF;EACf,SAAA;EACW;EACX,cAAcE,EAAgBE,CAAO;EAE9B,gBAAAO;CACG,CAAA;AAEhB"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
const e=require("./frame-DJPTNz9f.cjs"),t=require("./useLimit-CCv6sAUS.cjs"),n=require("./binding-tMjrUzkU.cjs");let r=require("react"),i=require("react/jsx-runtime");function a({label:a,hint:o,error:s,isRequired:c,count:l,limit:u,limitDisplay:d,limitVisibility:f,showLimitRing:p,children:m,className:h,...g}){let{frame:_,attributes:v}=n.r(g);return t.t(g,u),(0,r.useEffect)(()=>{if(_&&l!==void 0)return _.reportCount(l),()=>_.reportCount(void 0)},[_,l]),_?(0,i.jsx)(`div`,{...v,className:h,children:m}):(0,i.jsx)(e.t,{label:a,hint:o,error:s,isRequired:c,count:l,limit:u,limitDisplay:d,limitVisibility:f,showLimitRing:p,isGroup:!0,className:h,groupBinding:n.t(g),children:()=>m})}Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return a}});
|
|
2
|
-
//# sourceMappingURL=
|
|
2
|
+
//# sourceMappingURL=style-nulIa2_8.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"
|
|
1
|
+
{"version":3,"file":"style-nulIa2_8.cjs","names":["useGroupBinding","FieldFrame","fieldAttributes","require_frame","require_useLimit","require_binding","react","react_jsx_runtime","FieldGroup","binding","limit","frame","count","attributes","children"],"sources":["../../src/components/Field/group.tsx"],"sourcesContent":["import { useEffect, type ReactNode } from \"react\";\nimport { FieldFrame } from \"./frame\";\nimport { fieldAttributes, useGroupBinding } from \"./binding\";\nimport type { FieldBinding, FieldProps } from \"./types\";\nimport { useReportedLimit } from \"./useLimit\";\n\nexport interface FieldGroupProps extends FieldBinding, Omit<FieldProps, \"children\" | \"isGroup\"> {\n children: ReactNode;\n className?: string;\n}\n\n/**\n * Standalone groups render their own Field frame. Bound to an enclosing Field,\n * they render only their controls and report their count to its label.\n */\nexport function FieldGroup({\n label,\n hint,\n error,\n isRequired,\n count,\n limit,\n limitDisplay,\n limitVisibility,\n showLimitRing,\n children,\n className,\n ...binding\n}: FieldGroupProps) {\n const { frame, attributes } = useGroupBinding(binding);\n useReportedLimit(binding, limit);\n useEffect(() => {\n if (!frame || count === undefined) {\n return;\n }\n frame.reportCount(count);\n return () => frame.reportCount(undefined);\n }, [frame, count]);\n if (frame) {\n return (\n <div\n {...attributes}\n className={className}\n >\n {children}\n </div>\n );\n }\n return (\n <FieldFrame\n label={label}\n hint={hint}\n error={error}\n isRequired={isRequired}\n count={count}\n limit={limit}\n limitDisplay={limitDisplay}\n limitVisibility={limitVisibility}\n showLimitRing={showLimitRing}\n isGroup\n className={className}\n groupBinding={fieldAttributes(binding)}\n >\n {() => children}\n </FieldFrame>\n );\n}\n"],"mappings":"A,uKAeA,SAAgBQ,EAAW,CACzB,QACA,OACA,QACA,aACA,QACA,QACA,eACA,kBACA,gBACA,WACA,YACA,GAAGC,GACe,CAClB,GAAM,CAAE,QAAO,cAAeT,EAAAA,EAAgBS,CAAO,EAmBrD,OAlBAL,EAAA,EAAiBK,EAASC,CAAK,GAC/B,EAAAJ,EAAA,UAAA,KAAgB,CACd,GAAKK,GAASC,IAAU,IAAA,GAIxB,OADAD,EAAM,YAAYC,CAAK,MACVD,EAAM,YAAY,IAAA,EAAS,CAC1C,EAAG,CAACA,EAAOC,CAAK,CAAC,EACbD,GAEA,EAAAJ,EAAA,IAAA,CAAC,MAAD,CACE,GAAIM,EACO,YAEV,UACE,CAAA,GAIP,EAAAN,EAAA,IAAA,CAACN,EAAAA,EAAD,CACS,QACD,OACC,QACK,aACL,QACA,QACO,eACG,kBACF,gBACf,QAAA,GACW,YACX,aAAcC,EAAAA,EAAgBO,CAAO,EAE9B,aAAAK,CACG,CAAA,CAEhB,C"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./Icon-CD3oeiNA.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("./LoadState-BXLG-SkQ.cjs"),c=require("../components/SearchField/index.cjs"),l=require("../components/Choice/index.cjs");let u=require("react"),d=require("react/jsx-runtime");function f(e){return e.isDisabled?e.disabledReason:void 0}function p(e){return e.tone===`removed`}function m(e){return p(e)?void 0:f(e)}function h({item:t,reasonId:n}){let i=f(t);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`ds-entry__thumb`,children:t.imageUrl?(0,d.jsx)(`img`,{src:t.imageUrl,alt:``,loading:`lazy`}):(0,d.jsx)(e.t,{name:`file-text`,size:20})}),(0,d.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,d.jsx)(`span`,{className:`ds-entry__title`,"data-unavailable":t.isUnavailable||void 0,children:t.title}),t.metadata!=null&&(0,d.jsx)(`span`,{className:`ds-entry__meta`,children:t.metadata}),i&&(0,d.jsxs)(`span`,{id:n,className:`ds-entry__reason`,children:[(0,d.jsx)(r.Badge,{shape:`tag`,size:`sm`,children:i.label}),` `,(0,d.jsx)(`span`,{children:i.description})]})]})]})}function g({item:e,reasonId:t}){return p(e)?(0,d.jsxs)(`span`,{className:`ds-entry__removed`,children:[(0,d.jsx)(`strong`,{children:e.title}),` `,e.metadata??(0,d.jsx)(`code`,{children:e.id})]}):(0,d.jsx)(h,{item:e,reasonId:t})}function _({item:e}){return p(e)?(0,d.jsx)(r.Badge,{shape:`tag`,children:e.removedLabel??`Removed on save`}):null}function v({item:e,onEdit:n,isDisabled:r}){return!n||e.isUnavailable||e.isDisabled?null:(0,d.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`pencil`,"aria-label":`Edit ${e.title}`,isDisabled:r,onClick:()=>n(e)})}function y(e,t,n){return{id:e,title:t,metadata:n,isUnavailable:!0}}function b({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)?y(e,`${`${o.charAt(0).toUpperCase()}${o.slice(1)}`} no longer available`,`Replace or clear this selection.`):a?y(e,i.has(e)?`Couldn't load ${o}`:`Loading…`):{id:e,title:e}))}function x(e){return e instanceof Error?e:null}function S(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 C(e,t,n){let r=n?t.flatMap(t=>{let r=n(t);return r?.item.id===t&&e.seeds.get(t)!==r?[r]:[]}):[];if(r.length===0)return e;let i=r.filter(t=>Object.is(t.revision,e.refreshKey)),a=r.filter(t=>!Object.is(t.revision,e.refreshKey)&&!e.known.has(t.item.id)&&!e.stale.has(t.item.id)),o=e=>e.map(e=>[e.item.id,e.item]);return{...e,seeds:new Map([...e.seeds,...r.map(e=>[e.item.id,e])]),known:i.length?new Map([...e.known,...o(i)]):e.known,stale:a.length?new Map([...e.stale,...o(a)]):e.stale,failures:S(e.failures,i.map(e=>e.item.id))}}function w(e,t){return e!==t&&(e.length!==t.length||t.some(t=>!e.includes(t)))}function T(e,t,n,r){let i=e;if(Object.is(i.refreshKey,n)||(i={...i,refreshKey:n,known:new Map,stale:new Map([...i.stale,...i.known]),failures:new Map}),w(i.selected,t)){let e=i.selected.filter(e=>!t.includes(e));i={...i,selected:t,known:S(i.known,e),stale:S(i.stale,e),failures:S(i.failures,e),seeds:S(i.seeds,e)}}return C(i,t,r)}function E(e,t,r,i,a){let o=n.u(r),s=n.u(e),[c,l]=(0,u.useState)(()=>C({refreshKey:i,selected:e,known:new Map,stale:new Map,failures:new Map,seeds:new Map},e,a)),d=T(c,e,i,a);d!==c&&l(d);let{known:f,stale:p,failures:m}=d,h=(0,u.useMemo)(()=>p.size===0?f:new Map([...p,...f]),[p,f]),g=(e,t,n=s.current)=>{let r=e.filter(e=>e!==void 0&&n.includes(e.id)).map(e=>[e.id,e]);r.length!==0&&l(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])}})},_=new Set(t.map(e=>e.id)),v=r?e.filter(e=>!_.has(e)&&!f.has(e)&&!m.has(e)):[],y=JSON.stringify(v),b=(0,u.useRef)({refreshKey:i,tokens:new Map});(0,u.useEffect)(()=>{let e=o.current;if(!e)return;let t=JSON.parse(y);Object.is(b.current.refreshKey,i)||(b.current={refreshKey:i,tokens:new Map});let{tokens:n}=b.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=>{b.current.tokens.get(r)===t&&(b.current.tokens.delete(r),l(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,x(e))})))}},[y,i,o]);let w=e.filter(e=>m.has(e)&&!f.has(e));return{known:h,failures:m,remember:g,status:v.length>0?`loading`:w.length>0?`error`:`ready`,error:w.length>0?m.get(w[0])??null:null,retry:()=>l(e=>({...e,failures:S(e.failures,w)}))}}function D(e,t,n,r){let i=s.n(t,n,r);return t!==`error`&&i.state!==`pending`?null:(0,d.jsx)(s.r,{title:e,error:i.error,onRetry:i.retry,retryState:i.state})}function O({query:e,itemLabel:t,itemsLabel:n,canCreate:r}){let i=e.trim();return(0,d.jsxs)(`div`,{className:`ds-entry-picker__no-results`,children:[(0,d.jsx)(`p`,{children:i?`No ${n} match “${i}”`:`No ${n} yet`}),i&&(0,d.jsxs)(`p`,{children:[`Try a different search.`,r?` Or create the ${t} you need.`:``]})]})}function k(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 A(e){let t=(0,u.useRef)(null),r=(0,u.useRef)(null),{more:i,offset:a}=e;return(0,u.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]:k(a,e))?.focus())},[i.status,a]),{pagingRef:t,load:()=>{r.current=t.current?.contains(document.activeElement)?a:null,i.load()}}}function j(e,t){let r=(0,u.useRef)(t);(0,u.useEffect)(()=>{if(r.current===t)return;r.current=t;let i=e.current;i&&n.d(document.activeElement)&&(n.h(i)[0]??k(i,1/0))?.focus()},[e,t])}function M({count:e,total:n,isRemote:r,pageSize:i,remote:a,itemsLabel:o}){let{more:s}=a,{pagingRef:c,load:l}=A(a),u=D(`Couldn't load more ${o}`,s.status,s.error,l);return j(c,u?`failure`:r&&a.hasMore?`more`:`none`),n===0?null:(0,d.jsxs)(`div`,{ref:c,className:`ds-entry-picker__paging`,children:[u??(r&&a.hasMore&&(0,d.jsxs)(t.Button,{isPending:s.status===`loading`,isFocusableWhenDisabled:!0,isDisabled:!s.isAvailable,onClick:l,children:[`Load `,Math.min(i,n-a.offset),` more`]})),(0,d.jsx)(`span`,{children:e<n?`Showing ${e} of ${n}`:`All ${e} shown`})]})}function N(e,t,{isDisabled:n,searching:r,atMax:i}){if(n||r)return`inactive`;if(e.isDisabled)return`restricted`;if(!t&&i)return`full`}function P({items:e,selected:t,block:n,onToggle:r,onEdit:i}){let a=(0,u.useId)(),o=`${a}-full`;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{id:o,hidden:!0,children:`The selection is full. Remove one to choose another.`}),(0,d.jsx)(`ul`,{className:`ds-entry-picker__results`,"data-searching":n.searching||void 0,children:e.map((e,s)=>{let c=t.includes(e.id),u=N(e,c,n),p=f(e)?`${a}-reason-${s}`:void 0;return(0,d.jsxs)(`li`,{className:`ds-entry-picker__result ds-field-surface`,"data-selected":c||void 0,"data-blocked":u?!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,d.jsx)(l.Checkbox,{checked:c,"aria-checked":c,"aria-label":`Select ${e.title}`,"aria-describedby":u===`full`?o:p,disabled:!!u,isFocusableWhenDisabled:u!==`inactive`,onChange:()=>r(e.id)}),(0,d.jsx)(`span`,{className:`ds-entry`,children:(0,d.jsx)(h,{item:e,reasonId:p})}),(0,d.jsx)(v,{item:e,onEdit:i,isDisabled:u===`inactive`})]},e.id)})})]})}function F(){let e=(0,u.useRef)(null),[t,n]=(0,u.useState)(!1);return{ref:e,scrolled:t,toTop:()=>{n(!1),e.current&&(e.current.scrollTop=0)},onScroll:e=>{n(e.currentTarget.scrollTop>0)}}}function I({isOpen:e,onClose:n,query:r,onQuery:i,selected:c,results:l,cap:u,block:f,isRemote:p,pageSize:m,remote:h,onToggle:g,onEdit:_,itemLabel:v,itemsLabel:y,addLabel:b,onCreate:x,isCreating:S,dialogTitle:C,dialogDescription:w,isDialogHidden:T}){let E=D(`Couldn't refresh ${y}`,h.refresh.status,h.refresh.error,h.refresh.retry);return(0,d.jsx)(o.Modal,{isOpen:e,isHidden:T,onClose:n,title:C??b,description:w??u.description,className:`ds-entry-picker__dialog`,footer:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`ds-entry-picker__selection`,role:`status`,children:u.reading?(0,d.jsx)(a.LimitReading,{...u.reading,size:`lg`}):`${c.length} selected`}),(0,d.jsx)(t.Button,{variant:`primary`,onClick:n,children:`Done`})]}),children:(0,d.jsx)(L,{query:r,onQuery:i,itemsLabel:y,isSearching:h.loading,action:x&&(0,d.jsx)(t.Button,{variant:`primary`,isPending:S,isFocusableWhenDisabled:!0,iconStart:`plus`,isDisabled:f.isDisabled||u.atMax,onClick:x,children:`New ${v}`}),banner:E,isBusy:h.loading||h.more.status===`loading`||h.refresh.status===`loading`,children:(0,d.jsxs)(s.t,{status:h.status,errorTitle:`Couldn't load ${y}`,error:h.error,onRetry:h.retry,children:[(0,d.jsx)(P,{items:l,selected:c,block:f,onToggle:g,onEdit:_}),!h.searching&&l.length===0&&(0,d.jsx)(O,{query:r,itemLabel:v,itemsLabel:y,canCreate:!!x}),(0,d.jsx)(M,{count:l.length,total:p?h.total:l.length,isRemote:p,pageSize:m,remote:h,itemsLabel:y})]})})})}function L({query:e,onQuery:t,itemsLabel:n,isSearching:r,action:i,banner:a,isBusy:o,children:s}){let{ref:l,scrolled:u,onScroll:f,toTop:p}=F(),m=e=>{p(),t(e)};return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`ds-entry-picker__search ds-field-surface`,"data-scrolled":u||void 0,children:[(0,d.jsx)(c.SearchField,{"aria-label":`Search ${n}`,value:e,isBusy:r,placeholder:`Search ${n}`,onChange:e=>m(e.target.value),onClear:()=>m(``)}),i]}),a&&(0,d.jsx)(`div`,{className:`ds-entry-picker__refresh`,children:a}),(0,d.jsx)(`div`,{className:`ds-entry-picker__scroll`,ref:l,onScroll:f,"aria-busy":o,children:s})]})}function R(e,t){return e===`single`||t===1}function z(e,t,n){return R(e,n)?{count:t,max:1,tone:`neutral`}:e===`multiple`&&n!==void 0?{count:t,max:n}:void 0}function B(e,t,n){return R(e,n)?void 0:t}function V(e,t,n,{itemLabel:r,itemsLabel:a}){let o=z(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}}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 Z(e,t,r,i,a,o){let s=n.u(e),c=n.u(a),l=n.u(o),[d,f]=(0,u.useState)(0),[p,m]=(0,u.useState)(G),[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,b]=(0,u.useState)(i);y!==i&&(b(i),i||(m(G),g(null),v(null),f(e=>e+1)));let S=r.trim(),C=e&&i?JSON.stringify([S,t,d]):null,w=n.u(p),T=(0,u.useRef)(null),E=(0,u.useRef)(S),{loading:D,searching:O,status:k,hasMore:A,refresh:j,refreshFailed:M}=X(C,p,o,_),N=!D&&j===`ready`,P=D?`load`:j===`loading`?`refresh`:null;(0,u.useEffect)(()=>{if(C===null)return;let e=P===`load`&&S!==E.current?H:0;if(E.current=S,P===null)return;let n=P===`refresh`?w.current.offset+(T.current?t:0):0,r=!0,i=window.setTimeout(()=>{let e=s.current;e&&Y(e,S,t,n,()=>r).then(e=>{r&&(T.current=null,m({...e,key:C,revision:o,status:`ready`,error:null}),g(null),v(null),c.current(e.items,o))},e=>{r&&(P===`refresh`?v({key:C,revision:o,error:x(e)}):(T.current=null,m({...G,key:C,revision:o,status:`error`,error:x(e)}),g(null)))})},e);return()=>{r=!1,window.clearTimeout(i)}},[C,P,o,S,t,s,c,w]);let F=()=>{let e=s.current,n=p.key,{offset:r}=p;if(!e||n===null||!N||!A||T.current)return;let i=Symbol(`load more`),a=o;T.current=i,g({token:i,status:`loading`,error:null});let u=()=>T.current===i&&w.current.key===n&&w.current.offset===r&&Object.is(l.current,a),d=e=>{T.current===i&&(T.current=null),g(t=>t?.token===i?e:t)};Promise.resolve().then(()=>e({offset:r,limit:t},{query:S})).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:x(e)}:null))};return{items:p.items,total:p.total,offset:p.offset,hasMore:A,pageRevision:p.revision,loading:D,searching:O,status:k,error:p.error,retry:()=>f(e=>e+1),more:{...K(h,N),load:F},refresh:{status:j,error:M?_?.error??null:null,retry:()=>v(null)}}}var Q=[];function $(e,t){return t?e.map(e=>{let n=e.isDisabled?void 0:t(e);return n?{...e,isDisabled:!0,disabledReason:n}:e}):e}function ee(e,t,n,{isOpen:r,isDisabled:i,itemLabel:a,itemsLabel:o,close:s,restrict:c}){let[l,d]=(0,u.useState)(``),{resolveItem:f,refreshKey:p,loadPage:m,pageSize:h=10,mode:g=`multiple`,max:_,onEditItem:v}=n,y=E(e,t,f,p),b=Z(m,h,l,r,y.remember,p),x=!!m,S=(0,u.useMemo)(()=>{let e=l.trim().toLowerCase();return x?Q:t.filter(t=>!e||[t.title,...t.keywords??[]].join(` `).toLowerCase().includes(e))},[x,t,l]),C=x?b.items:S,w=(0,u.useMemo)(()=>$(C,c),[C,c]),T=V(g,e.length,_,{itemLabel:a,itemsLabel:o}),D={isDisabled:i,searching:b.searching,atMax:T.atMax},O=v?e=>{v(e)===!1&&s()}:void 0;return{selection:y,remote:b,isRemote:x,results:w,cap:T,block:D,editItem:O,revision:x?b.pageRevision:p,choice:t=>{let n=w.find(e=>e.id===t);return n&&!N(n,e.includes(t),D)?n:void 0},dialog:{query:l,onQuery:d,selected:e,results:w,cap:T,block:D,isRemote:x,pageSize:h,remote:b,onEdit:O,itemLabel:a,itemsLabel:o}}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return _}});
|
|
2
|
-
//# sourceMappingURL=use-picker-session-
|
|
1
|
+
const e=require("./Icon-C12r4frL.cjs"),t=require("../components/Button/index.cjs"),n=require("./overlayLayer-iGhuAByk.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("./LoadState-BXLG-SkQ.cjs"),c=require("../components/SearchField/index.cjs"),l=require("../components/Choice/index.cjs");let u=require("react"),d=require("react/jsx-runtime");function f(e){return e.isDisabled?e.disabledReason:void 0}function p(e){return e.tone===`removed`}function m(e){return p(e)?void 0:f(e)}function h({item:t,reasonId:n}){let i=f(t);return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`ds-entry__thumb`,children:t.imageUrl?(0,d.jsx)(`img`,{src:t.imageUrl,alt:``,loading:`lazy`}):(0,d.jsx)(e.t,{name:`file-text`,size:20})}),(0,d.jsxs)(`span`,{className:`ds-entry__body`,children:[(0,d.jsx)(`span`,{className:`ds-entry__title`,"data-unavailable":t.isUnavailable||void 0,children:t.title}),t.metadata!=null&&(0,d.jsx)(`span`,{className:`ds-entry__meta`,children:t.metadata}),i&&(0,d.jsxs)(`span`,{id:n,className:`ds-entry__reason`,children:[(0,d.jsx)(r.Badge,{shape:`tag`,size:`sm`,children:i.label}),` `,(0,d.jsx)(`span`,{children:i.description})]})]})]})}function g({item:e,reasonId:t}){return p(e)?(0,d.jsxs)(`span`,{className:`ds-entry__removed`,children:[(0,d.jsx)(`strong`,{children:e.title}),` `,e.metadata??(0,d.jsx)(`code`,{children:e.id})]}):(0,d.jsx)(h,{item:e,reasonId:t})}function _({item:e}){return p(e)?(0,d.jsx)(r.Badge,{shape:`tag`,children:e.removedLabel??`Removed on save`}):null}function v({item:e,onEdit:n,isDisabled:r}){return!n||e.isUnavailable||e.isDisabled?null:(0,d.jsx)(t.Button,{variant:`simple`,size:`sm`,isIconOnly:!0,iconStart:`pencil`,"aria-label":`Edit ${e.title}`,isDisabled:r,onClick:()=>n(e)})}function y(e,t,n){return{id:e,title:t,metadata:n,isUnavailable:!0}}function b({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)?y(e,`${`${o.charAt(0).toUpperCase()}${o.slice(1)}`} no longer available`,`Replace or clear this selection.`):a?y(e,i.has(e)?`Couldn't load ${o}`:`Loading…`):{id:e,title:e}))}function x(e){return e instanceof Error?e:null}function S(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 C(e,t,n){let r=n?t.flatMap(t=>{let r=n(t);return r?.item.id===t&&e.seeds.get(t)!==r?[r]:[]}):[];if(r.length===0)return e;let i=r.filter(t=>Object.is(t.revision,e.refreshKey)),a=r.filter(t=>!Object.is(t.revision,e.refreshKey)&&!e.known.has(t.item.id)&&!e.stale.has(t.item.id)),o=e=>e.map(e=>[e.item.id,e.item]);return{...e,seeds:new Map([...e.seeds,...r.map(e=>[e.item.id,e])]),known:i.length?new Map([...e.known,...o(i)]):e.known,stale:a.length?new Map([...e.stale,...o(a)]):e.stale,failures:S(e.failures,i.map(e=>e.item.id))}}function w(e,t){return e!==t&&(e.length!==t.length||t.some(t=>!e.includes(t)))}function T(e,t,n,r){let i=e;if(Object.is(i.refreshKey,n)||(i={...i,refreshKey:n,known:new Map,stale:new Map([...i.stale,...i.known]),failures:new Map}),w(i.selected,t)){let e=i.selected.filter(e=>!t.includes(e));i={...i,selected:t,known:S(i.known,e),stale:S(i.stale,e),failures:S(i.failures,e),seeds:S(i.seeds,e)}}return C(i,t,r)}function E(e,t,r,i,a){let o=n.u(r),s=n.u(e),[c,l]=(0,u.useState)(()=>C({refreshKey:i,selected:e,known:new Map,stale:new Map,failures:new Map,seeds:new Map},e,a)),d=T(c,e,i,a);d!==c&&l(d);let{known:f,stale:p,failures:m}=d,h=(0,u.useMemo)(()=>p.size===0?f:new Map([...p,...f]),[p,f]),g=(e,t,n=s.current)=>{let r=e.filter(e=>e!==void 0&&n.includes(e.id)).map(e=>[e.id,e]);r.length!==0&&l(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])}})},_=new Set(t.map(e=>e.id)),v=r?e.filter(e=>!_.has(e)&&!f.has(e)&&!m.has(e)):[],y=JSON.stringify(v),b=(0,u.useRef)({refreshKey:i,tokens:new Map});(0,u.useEffect)(()=>{let e=o.current;if(!e)return;let t=JSON.parse(y);Object.is(b.current.refreshKey,i)||(b.current={refreshKey:i,tokens:new Map});let{tokens:n}=b.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=>{b.current.tokens.get(r)===t&&(b.current.tokens.delete(r),l(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,x(e))})))}},[y,i,o]);let w=e.filter(e=>m.has(e)&&!f.has(e));return{known:h,failures:m,remember:g,status:v.length>0?`loading`:w.length>0?`error`:`ready`,error:w.length>0?m.get(w[0])??null:null,retry:()=>l(e=>({...e,failures:S(e.failures,w)}))}}function D(e,t,n,r){let i=s.n(t,n,r);return t!==`error`&&i.state!==`pending`?null:(0,d.jsx)(s.r,{title:e,error:i.error,onRetry:i.retry,retryState:i.state})}function O({query:e,itemLabel:t,itemsLabel:n,canCreate:r}){let i=e.trim();return(0,d.jsxs)(`div`,{className:`ds-entry-picker__no-results`,children:[(0,d.jsx)(`p`,{children:i?`No ${n} match “${i}”`:`No ${n} yet`}),i&&(0,d.jsxs)(`p`,{children:[`Try a different search.`,r?` Or create the ${t} you need.`:``]})]})}function k(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.g(e)[0];if(t)return t}}function A(e){let t=(0,u.useRef)(null),r=(0,u.useRef)(null),{more:i,offset:a}=e;return(0,u.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.g(a)[0]:k(a,e))?.focus())},[i.status,a]),{pagingRef:t,load:()=>{r.current=t.current?.contains(document.activeElement)?a:null,i.load()}}}function j(e,t){let r=(0,u.useRef)(t);(0,u.useEffect)(()=>{if(r.current===t)return;r.current=t;let i=e.current;i&&n.d(document.activeElement)&&(n.g(i)[0]??k(i,1/0))?.focus()},[e,t])}function M({count:e,total:n,isRemote:r,pageSize:i,remote:a,itemsLabel:o}){let{more:s}=a,{pagingRef:c,load:l}=A(a),u=D(`Couldn't load more ${o}`,s.status,s.error,l);return j(c,u?`failure`:r&&a.hasMore?`more`:`none`),n===0?null:(0,d.jsxs)(`div`,{ref:c,className:`ds-entry-picker__paging`,children:[u??(r&&a.hasMore&&(0,d.jsxs)(t.Button,{isPending:s.status===`loading`,isFocusableWhenDisabled:!0,isDisabled:!s.isAvailable,onClick:l,children:[`Load `,Math.min(i,n-a.offset),` more`]})),(0,d.jsx)(`span`,{children:e<n?`Showing ${e} of ${n}`:`All ${e} shown`})]})}function N(e,t,{isDisabled:n,searching:r,atMax:i}){if(n||r)return`inactive`;if(e.isDisabled)return`restricted`;if(!t&&i)return`full`}function P({items:e,selected:t,block:n,onToggle:r,onEdit:i}){let a=(0,u.useId)(),o=`${a}-full`;return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{id:o,hidden:!0,children:`The selection is full. Remove one to choose another.`}),(0,d.jsx)(`ul`,{className:`ds-entry-picker__results`,"data-searching":n.searching||void 0,children:e.map((e,s)=>{let c=t.includes(e.id),u=N(e,c,n),p=f(e)?`${a}-reason-${s}`:void 0;return(0,d.jsxs)(`li`,{className:`ds-entry-picker__result ds-field-surface`,"data-selected":c||void 0,"data-blocked":u?!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,d.jsx)(l.Checkbox,{checked:c,"aria-checked":c,"aria-label":`Select ${e.title}`,"aria-describedby":u===`full`?o:p,disabled:!!u,isFocusableWhenDisabled:u!==`inactive`,onChange:()=>r(e.id)}),(0,d.jsx)(`span`,{className:`ds-entry`,children:(0,d.jsx)(h,{item:e,reasonId:p})}),(0,d.jsx)(v,{item:e,onEdit:i,isDisabled:u===`inactive`})]},e.id)})})]})}function F(){let e=(0,u.useRef)(null),[t,n]=(0,u.useState)(!1);return{ref:e,scrolled:t,toTop:()=>{n(!1),e.current&&(e.current.scrollTop=0)},onScroll:e=>{n(e.currentTarget.scrollTop>0)}}}function I({isOpen:e,onClose:n,query:r,onQuery:i,selected:c,results:l,cap:u,block:f,isRemote:p,pageSize:m,remote:h,onToggle:g,onEdit:_,itemLabel:v,itemsLabel:y,addLabel:b,onCreate:x,isCreating:S,dialogTitle:C,dialogDescription:w,isDialogHidden:T}){let E=D(`Couldn't refresh ${y}`,h.refresh.status,h.refresh.error,h.refresh.retry);return(0,d.jsx)(o.Modal,{isOpen:e,isHidden:T,onClose:n,title:C??b,description:w??u.description,className:`ds-entry-picker__dialog`,footer:(0,d.jsxs)(d.Fragment,{children:[(0,d.jsx)(`span`,{className:`ds-entry-picker__selection`,role:`status`,children:u.reading?(0,d.jsx)(a.LimitReading,{...u.reading,size:`lg`}):`${c.length} selected`}),(0,d.jsx)(t.Button,{variant:`primary`,onClick:n,children:`Done`})]}),children:(0,d.jsx)(L,{query:r,onQuery:i,itemsLabel:y,isSearching:h.loading,action:x&&(0,d.jsx)(t.Button,{variant:`primary`,isPending:S,isFocusableWhenDisabled:!0,iconStart:`plus`,isDisabled:f.isDisabled||u.atMax,onClick:x,children:`New ${v}`}),banner:E,isBusy:h.loading||h.more.status===`loading`||h.refresh.status===`loading`,children:(0,d.jsxs)(s.t,{status:h.status,errorTitle:`Couldn't load ${y}`,error:h.error,onRetry:h.retry,children:[(0,d.jsx)(P,{items:l,selected:c,block:f,onToggle:g,onEdit:_}),!h.searching&&l.length===0&&(0,d.jsx)(O,{query:r,itemLabel:v,itemsLabel:y,canCreate:!!x}),(0,d.jsx)(M,{count:l.length,total:p?h.total:l.length,isRemote:p,pageSize:m,remote:h,itemsLabel:y})]})})})}function L({query:e,onQuery:t,itemsLabel:n,isSearching:r,action:i,banner:a,isBusy:o,children:s}){let{ref:l,scrolled:u,onScroll:f,toTop:p}=F(),m=e=>{p(),t(e)};return(0,d.jsxs)(d.Fragment,{children:[(0,d.jsxs)(`div`,{className:`ds-entry-picker__search ds-field-surface`,"data-scrolled":u||void 0,children:[(0,d.jsx)(c.SearchField,{"aria-label":`Search ${n}`,value:e,isBusy:r,placeholder:`Search ${n}`,onChange:e=>m(e.target.value),onClear:()=>m(``)}),i]}),a&&(0,d.jsx)(`div`,{className:`ds-entry-picker__refresh`,children:a}),(0,d.jsx)(`div`,{className:`ds-entry-picker__scroll`,ref:l,onScroll:f,"aria-busy":o,children:s})]})}function R(e,t){return e===`single`||t===1}function z(e,t,n){return R(e,n)?{count:t,max:1,tone:`neutral`}:e===`multiple`&&n!==void 0?{count:t,max:n}:void 0}function B(e,t,n){return R(e,n)?void 0:t}function V(e,t,n,{itemLabel:r,itemsLabel:a}){let o=z(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}}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 Z(e,t,r,i,a,o){let s=n.u(e),c=n.u(a),l=n.u(o),[d,f]=(0,u.useState)(0),[p,m]=(0,u.useState)(G),[h,g]=(0,u.useState)(null),[_,v]=(0,u.useState)(null),[y,b]=(0,u.useState)(i);y!==i&&(b(i),i||(m(G),g(null),v(null),f(e=>e+1)));let S=r.trim(),C=e&&i?JSON.stringify([S,t,d]):null,w=n.u(p),T=(0,u.useRef)(null),E=(0,u.useRef)(S),{loading:D,searching:O,status:k,hasMore:A,refresh:j,refreshFailed:M}=X(C,p,o,_),N=!D&&j===`ready`,P=D?`load`:j===`loading`?`refresh`:null;(0,u.useEffect)(()=>{if(C===null)return;let e=P===`load`&&S!==E.current?H:0;if(E.current=S,P===null)return;let n=P===`refresh`?w.current.offset+(T.current?t:0):0,r=!0,i=window.setTimeout(()=>{let e=s.current;e&&Y(e,S,t,n,()=>r).then(e=>{r&&(T.current=null,m({...e,key:C,revision:o,status:`ready`,error:null}),g(null),v(null),c.current(e.items,o))},e=>{r&&(P===`refresh`?v({key:C,revision:o,error:x(e)}):(T.current=null,m({...G,key:C,revision:o,status:`error`,error:x(e)}),g(null)))})},e);return()=>{r=!1,window.clearTimeout(i)}},[C,P,o,S,t,s,c,w]);let F=()=>{let e=s.current,n=p.key,{offset:r}=p;if(!e||n===null||!N||!A||T.current)return;let i=Symbol(`load more`),a=o;T.current=i,g({token:i,status:`loading`,error:null});let u=()=>T.current===i&&w.current.key===n&&w.current.offset===r&&Object.is(l.current,a),d=e=>{T.current===i&&(T.current=null),g(t=>t?.token===i?e:t)};Promise.resolve().then(()=>e({offset:r,limit:t},{query:S})).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:x(e)}:null))};return{items:p.items,total:p.total,offset:p.offset,hasMore:A,pageRevision:p.revision,loading:D,searching:O,status:k,error:p.error,retry:()=>f(e=>e+1),more:{...K(h,N),load:F},refresh:{status:j,error:M?_?.error??null:null,retry:()=>v(null)}}}var Q=[];function $(e,t){return t?e.map(e=>{let n=e.isDisabled?void 0:t(e);return n?{...e,isDisabled:!0,disabledReason:n}:e}):e}function ee(e,t,n,{isOpen:r,isDisabled:i,itemLabel:a,itemsLabel:o,close:s,restrict:c}){let[l,d]=(0,u.useState)(``),{resolveItem:f,refreshKey:p,loadPage:m,pageSize:h=10,mode:g=`multiple`,max:_,onEditItem:v}=n,y=E(e,t,f,p),b=Z(m,h,l,r,y.remember,p),x=!!m,S=(0,u.useMemo)(()=>{let e=l.trim().toLowerCase();return x?Q:t.filter(t=>!e||[t.title,...t.keywords??[]].join(` `).toLowerCase().includes(e))},[x,t,l]),C=x?b.items:S,w=(0,u.useMemo)(()=>$(C,c),[C,c]),T=V(g,e.length,_,{itemLabel:a,itemsLabel:o}),D={isDisabled:i,searching:b.searching,atMax:T.atMax},O=v?e=>{v(e)===!1&&s()}:void 0;return{selection:y,remote:b,isRemote:x,results:w,cap:T,block:D,editItem:O,revision:x?b.pageRevision:p,choice:t=>{let n=w.find(e=>e.id===t);return n&&!N(n,e.includes(t),D)?n:void 0},dialog:{query:l,onQuery:d,selected:e,results:w,cap:T,block:D,isRemote:x,pageSize:h,remote:b,onEdit:O,itemLabel:a,itemsLabel:o}}}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return g}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return m}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return I}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return h}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return B}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return z}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return ee}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return _}});
|
|
2
|
+
//# sourceMappingURL=use-picker-session-CM0zcEbf.cjs.map
|