@mattilsynet/design 0.2.6 → 0.2.7
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/mtds/index.iife.js +1 -1
- package/mtds/index.iife.js.map +1 -1
- package/mtds/logo/logo.stories.d.ts +1 -0
- package/mtds/popover/popover.js +27 -27
- package/mtds/popover/popover.js.map +1 -1
- package/mtds/popover/popover.stories.d.ts +1 -0
- package/mtds/styles.css +1 -1
- package/mtds/styles.json +33 -33
- package/mtds/styles.module.css.js +31 -31
- package/mtds/tag/tag.stories.d.ts +2 -1
- package/package.json +2 -1
package/mtds/index.iife.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var mtds=function(
|
|
1
|
+
var mtds=function(p){"use strict";const k="_validation_ub4hk_1 _ds-validation-message_14y6r_1",A="_tag_ub4hk_1 _ds-tag_14y6r_1",S="_tabs_ub4hk_1",$="_table_ub4hk_1 _ds-table_14y6r_1",M="_scrollShadow_ub4hk_1",E="_tableChildAdded_ub4hk_1",C="_skeleton_ub4hk_1 _ds-skeleton_14y6r_1",T="_popover_ub4hk_1",w="_pagination_ub4hk_1 _ds-pagination_14y6r_1",I="_modal_ub4hk_1 _ds-modal_14y6r_1",x="_logo_ub4hk_1 _ds-focus_14y6r_1",N="_link_ub4hk_1",L="_grid_ub4hk_1",B="_flex_ub4hk_1",O="_box_ub4hk_1",D="_input_ub4hk_1 _ds-input_14y6r_1",H="_fieldset_ub4hk_1 _ds-fieldset_14y6r_1",P="_fieldsetValidationAdded_ub4hk_1",V="_field_ub4hk_1 _ds-field_14y6r_1",U="_fieldChildAdded_ub4hk_1",W="_affixes_ub4hk_1 _ds-field-affixes_14y6r_1",j="_count_ub4hk_1",F="_errorsummary_ub4hk_1 _ds-error-summary_14y6r_1",z="_details_ub4hk_1 _ds-details_14y6r_1",X="_chip_ub4hk_1 _ds-chip_14y6r_1",Y="_card_ub4hk_1",q="_info_ub4hk_1",K="_button_ub4hk_1 _ds-button_14y6r_1",Q="_breadcrumbs_ub4hk_1 _ds-breadcrumbs_14y6r_1",R="_badge_ub4hk_1",G="_avatar_ub4hk_1 _ds-avatar_14y6r_1",J="_alert_ub4hk_1 _ds-alert_14y6r_1",Z="_body_ub4hk_99",r={validation:k,tag:A,tabs:S,table:$,scrollShadow:M,tableChildAdded:E,skeleton:C,popover:T,pagination:w,modal:I,logo:x,link:N,grid:L,flex:B,box:O,input:D,fieldset:H,fieldsetValidationAdded:P,field:V,fieldChildAdded:U,affixes:W,count:j,errorsummary:F,details:z,chip:X,card:Y,info:q,button:K,breadcrumbs:Q,badge:R,avatar:G,alert:J,body:Z},bt=Object.freeze(Object.defineProperty({__proto__:null,affixes:W,alert:J,avatar:G,badge:R,body:Z,box:O,breadcrumbs:Q,button:K,card:Y,chip:X,count:j,default:r,details:z,errorsummary:F,field:V,fieldChildAdded:U,fieldset:H,fieldsetValidationAdded:P,flex:B,grid:L,info:q,input:D,link:N,logo:x,modal:I,pagination:w,popover:T,scrollShadow:M,skeleton:C,table:$,tableChildAdded:E,tabs:S,tag:A,validation:k},Symbol.toStringTag,{value:"Module"})),tt=typeof window<"u"&&typeof document<"u",d={capture:!0,passive:!0};let pt=0;const gt=`${Date.now().toString(36)}${Math.random().toString(36).slice(2,5)}`;function g(t){return t.id||(t.id=`${gt}${++pt}`),t.id}const et=(t,e,n)=>{for(const s of n[0].split(","))n[0]=s,Element.prototype[`${t}EventListener`].apply(e,n)},u=(t,...e)=>et("add",t,e),b=(t,...e)=>et("remove",t,e),m=(t,e)=>{let n=0;const s=o=>{o.animationName===t&&(cancelAnimationFrame(n),n=requestAnimationFrame(e))};return{observe:o=>u(o,"animationend",s,d),disconnect:o=>b(o,"animationstart",s,d)}},y=t=>t instanceof HTMLElement&&"validity"in t&&!(t instanceof HTMLButtonElement),ht=r.field.split(" ")[0],ot=r.validation.split(" "),mt=ot[0],nt=new WeakMap;function yt(t){for(const e of t){const n=[],s=[];let o=null,a=!0;for(const i of e.getElementsByTagName("*"))i instanceof HTMLLabelElement?n.push(i):y(i)?o=i:i.classList.contains(mt)?(a=i.getAttribute("data-color")==="success",s.unshift(g(i))):i instanceof HTMLParagraphElement&&s.push(g(i));if(o)for(const i of n)i.htmlFor=g(o);o&&it(o),o==null||o.setAttribute("aria-describedby",s.join(" ")),o==null||o.setAttribute("aria-invalid",`${!a}`)}}function st({target:t}){y(t)&&it(t)}function it(t){const e=t==null?void 0:t.nextElementSibling,n=e==null?void 0:e.getAttribute("data-count");if(e&&n){const s=Number(n)-t.value.length,o=s<0;if(e.getAttribute("aria-live")==="polite"!==o){e.setAttribute("aria-live",o?"polite":"off");for(const i of ot)e.classList.toggle(i,o)}e.textContent=`${Math.abs(s)} tegn ${o?"for mye":"igjen"}`}}function vt(t){const e=t.getElementsByClassName(ht),n=m(r.fieldChildAdded,()=>yt(e));nt.set(t,n),n.observe(t),u(t,"input",st,d)}function kt(t){var e;(e=nt.get(t))==null||e.disconnect(t),b(t,"input",st,d)}const At=r.fieldset.split(" ")[0],St=r.validation.split(" ")[0],at=new WeakMap;function $t(t){for(const e of t){const n=[];let s="";for(const o of e.getElementsByTagName("*"))o.classList.contains(St)?s=g(o):y(o)&&n.push(o);if(s)for(const o of n)o.setAttribute("aria-describedby",s),o.setAttribute("aria-invalid","true")}}function Mt(t){const e=t.getElementsByClassName(At),n=m(r.fieldsetValidationAdded,()=>$t(e));at.set(t,n),n.observe(t)}function Et(t){var e;(e=at.get(t))==null||e.disconnect(t)}function Ct(t){u(t,"click",rt),u(t,"toggle",ct,d)}function Tt(t){b(t,"click",rt),b(t,"toggle",ct,d)}const dt=r.popover.split(" ")[0],l=tt?document.createElement("div"):null;l&&(l.style.cssText="position:absolute;padding:1px");function ct({target:t,newState:e}){var o;const s=e==="open"&&t instanceof HTMLElement&&t.classList.contains(dt)&&((o=t.getRootNode())==null?void 0:o.querySelector(`[popovertarget="${t.id}"]`));if(s){const a=t.getAttribute("data-position")==="over",i=()=>wt(s,t,a),_=({newState:f})=>{f!=="open"&&(b(document,"DOMContentReady",i,d),b(t,"toggle",_,d),b(window,"load,resize,scroll",i,d),l==null||l.remove())};document.body.append(l||""),document.fonts.ready.then(i),u(window,"load,resize,scroll",i,d),u(document,"DOMContentReady",i,d),u(t,"toggle",_,d)}}function rt(t){var n;const e=t.target instanceof Element&&t.target.closest("a");if(e){const s=e.getRootNode(),o=((n=s.getElementById)==null?void 0:n.call(s,e.getAttribute("popovertarget")||""))||e.closest(`.${dt}`),a=e.getAttribute("popovertargetaction")||"toggle";t.defaultPrevented||o==null||o.togglePopover(a==="show"||(a==="hide"?!1:void 0))}}function wt(t,e,n=!1){const{innerWidth:s,innerHeight:o,scrollY:a,scrollX:i}=window,{offsetWidth:_,offsetHeight:f}=e;let ft=-i,h=-a,c=t;do ft+=(c==null?void 0:c.offsetLeft)||0,h+=(c==null?void 0:c.offsetTop)||0,c=(c==null?void 0:c.offsetParent)||null;while(c);const v=h+((t==null?void 0:t.offsetHeight)||0),Ht=v+f<o,Pt=h-f>0,ut=!n&&Ht||!Pt,Vt=ut?a+v+f+30:0;e.style.left=`${Math.round(Math.min(Math.max(10,ft),s-_-10))}px`,e.style.top=`${Math.round(ut?v:h-f)}px`,l==null||l.style.setProperty("top",`${Math.round(Vt)}px`)}const It=r.table.split(" ")[0],lt=new WeakMap;function xt(t){var e,n;for(const s of t)if(s instanceof HTMLTableElement){const o=Array.from(((n=(e=s.tHead)==null?void 0:e.rows[0])==null?void 0:n.cells)||[],a=>{var i;return(i=a.innerText)==null?void 0:i.trim()});for(const a of s.tBodies)for(const i of a.rows)for(const _ of i.cells)_.setAttribute("data-th",o[_.cellIndex]||":empty")}}function Nt(t){const e=t.getElementsByClassName(It),n=m(r.tableChildAdded,()=>xt(e));lt.set(t,n),n.observe(t)}function Lt(t){var e;(e=lt.get(t))==null||e.disconnect(t)}const Bt=(t,e,n)=>{const s=(n-1)/2,o=Math.min(Math.max(t-Math.floor(s),1),e-n+1),a=Math.min(Math.max(t+Math.ceil(s),n),e),i=Array.from({length:a+1-o},(_,f)=>f+o);return n>4&&o>1&&i.splice(0,2,1,0),n>3&&a<e&&i.splice(-2,2,0,e),i},Ot=({current:t=1,total:e=10,show:n=7})=>({prev:t>1?t-1:0,next:t<e?t+1:0,pages:Bt(t,e,n).map((s,o)=>({current:s===t&&"page",key:`key-${s}-${o}`,page:s}))});tt&&_t(document);function _t(t){vt(t),Mt(t),Ct(t),Nt(t)}function Dt(t){kt(t),Et(t),Tt(t),Lt(t)}return p.observe=_t,p.pagination=Ot,p.styles=bt,p.unobserve=Dt,Object.defineProperty(p,Symbol.toStringTag,{value:"Module"}),p}({});
|
|
2
2
|
//# sourceMappingURL=index.iife.js.map
|
package/mtds/index.iife.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.iife.js","sources":["../designsystem/utils.ts","../designsystem/field/field.ts","../designsystem/fieldset/fieldset.ts","../designsystem/popover/popover.ts","../designsystem/table/table.ts","../designsystem/pagination/pagination.ts","../designsystem/index.ts"],"sourcesContent":["export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';\nexport const QUICK_EVENT = { capture: true, passive: true };\n\n/**\n * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n const queue: MutationRecord[] = [];\n const observer = new MutationObserver((mutations) => {\n if (!queue[0]) requestAnimationFrame(process);\n queue.push(...mutations);\n });\n\n const process = () => {\n callback(queue, observer);\n queue.length = 0; // Reset queue\n };\n\n return observer;\n}\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\trest: Parameters<typeof Element.prototype.addEventListener>,\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\tElement.prototype[`${action}EventListener`].apply(element, rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => events(\"add\", element, rest);\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\n/**\n * Child added event inspired by:\n * https://davidwalsh.name/detect-node-insertion\n */\nexport const onAdd = (animationName: string, callback: () => void) => {\n let timer: ReturnType<typeof requestAnimationFrame> | number = 0;\n const onAnimation = (event: Event & { animationName?: string }) => {\n if (event.animationName === animationName) {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(callback);\n }\n };\n\n\treturn {\n\t\tobserve: (el: Element | Document, ) => on(el, 'animationend', onAnimation, QUICK_EVENT),\n\t\tdisconnect: (el: Element | Document, ) => off(el, 'animationstart', onAnimation, QUICK_EVENT)\n\t};\n}\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement && 'validity' in el && !(el instanceof HTMLButtonElement);\n\n// Make React support popover=\"\"target attribute\n// https://github.com/facebook/react/issues/27479\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicAttributes {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: string | boolean;\n\t\t}\n\t}\n\tnamespace React {\n\t\tinterface HTMLAttributes<T> {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: \"\" | \"auto\" | \"manual\" | undefined;\n\t\t}\n\t}\n}","import styles from '../styles.module.css';\nimport { QUICK_EVENT, isInputLike, off, on, onAdd, useId } from '../utils';\n\nconst CSS_FIELD = styles.field.split(' ')[0];\nconst CSS_VALIDATIONS = styles.validation.split(' ');\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction renderAria(fields: HTMLCollectionOf<Element>) {\n for(const field of fields) {\n const labels: HTMLLabelElement[] = [];\n const descs: string[] = [];\n let input: HTMLInputElement | null = null;\n let valid = true;\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n else if (isInputLike(el)) input = el;\n else if (el.classList.contains(CSS_VALIDATION)) { // Must be before instanceof HTMLParagraphElement since validation can also be a <p>\n valid = el.getAttribute('data-color') === 'success';\n descs.unshift(useId(el));\n } else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\n }\n\n if (input) for (const label of labels) label.htmlFor = useId(input);\n if (input) renderCounter(input);\n\n input?.setAttribute('aria-describedby', descs.join(' '));\n input?.setAttribute('aria-invalid', `${!valid}`);\n }\n}\nfunction handleInput({ target }: Event) {\n if (isInputLike(target)) renderCounter(target);\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n const el = input?.nextElementSibling;\n const limit = el?.getAttribute('data-count');\n\n if (el && limit) {\n const remainder = Number(limit) - input.value.length;\n const nextInvalid = remainder < 0;\n const prevInvalid = el.getAttribute('aria-live') === 'polite';\n\n if (prevInvalid !== nextInvalid) {\n el.setAttribute('aria-live', nextInvalid ? 'polite' : 'off');\n for (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n }\n el.textContent = `${Math.abs(remainder)} tegn ${nextInvalid ? 'for mye' : 'igjen'}`;\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELD);\n const add = onAdd(styles.fieldChildAdded, () => renderAria(fields));\n BOUND.set(el, add);\n add.observe(el);\n on(el, 'input', handleInput, QUICK_EVENT);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n off(el, 'input', handleInput, QUICK_EVENT);\n}\n","import styles from '../styles.module.css';\nimport { isInputLike, onAdd, useId } from '../utils';\nconst CSS_FIELDSET = styles.fieldset.split(' ')[0];\nconst CSS_VALIDATION = styles.validation.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(fieldsets: HTMLCollectionOf<Element>) {\n for(const fieldset of fieldsets) {\n const inputs: HTMLInputElement[] = [];\n let validationId = '';\n\n for (const el of fieldset.getElementsByTagName('*')) {\n if (el.classList.contains(CSS_VALIDATION)) validationId = useId(el);\n else if (isInputLike(el)) inputs.push(el);\n }\n\n if (validationId) \n for(const input of inputs) {\n input.setAttribute('aria-describedby', validationId);\n input.setAttribute('aria-invalid', 'true');\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELDSET);\n const add = onAdd(styles.fieldsetValidationAdded, () => process(fields));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","import styles from '../styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, off, on } from '../utils';\n\nexport function observe(el: Node) {\n on(el, 'click', handleLinkClick); // Allow `<a>` to use `popovertarget` as well\n on(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\nexport function unobserve(el: Node) {\n off(el, 'click', handleLinkClick);\n off(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\n\ntype Toggle = Event & { newState?: string };\nconst CSS_POPOVER = styles.popover.split(' ')[0];\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) SCROLLER.style.cssText = 'position:absolute;padding:1px';\n\nfunction handleToggle ({ target: el, newState }: Toggle){\n const isPopping = newState === 'open' && el instanceof HTMLElement && el.classList.contains(CSS_POPOVER);\n const anchor = isPopping && (el.getRootNode() as ShadowRoot)?.querySelector<HTMLElement>(`[popovertarget=\"${el.id}\"]`);\n\n if (anchor) {\n const isOver = el.getAttribute('data-position') === 'over';\n const update = () => place(anchor, el, isOver);\n const removeEvent = ({ newState }: Toggle) => {\n if (newState === 'open') return;\n off(document, 'DOMContentReady', update, QUICK_EVENT);\n off(el, 'toggle', removeEvent, QUICK_EVENT);\n off(window, 'load,resize,scroll', update, QUICK_EVENT);\n SCROLLER?.remove();\n }\n\n document.body.append(SCROLLER || '');\n document.fonts.ready.then(update); // Inital render and when fonts load\n on(window, 'load,resize,scroll', update, QUICK_EVENT);\n on(document, 'DOMContentReady', update, QUICK_EVENT);\n on(el, 'toggle', removeEvent, QUICK_EVENT);\n }\n}\n\n// Polyfill popovertarget for <a> (not supported by native)\nfunction handleLinkClick ({ target }: Event){\n const el = target instanceof Element && target.closest('a[popovertarget]');\n\n if (el) {\n const root = el.getRootNode() as ShadowRoot;\n const target = root.getElementById?.(el.getAttribute('popovertarget') || '');\n const action = el.getAttribute('popovertargetaction') || 'toggle';\n\n target?.togglePopover(action === 'show' || (action === 'hide' ? false : undefined));\n }\n}\n\nfunction place (anchor: HTMLElement | null, poppe: HTMLElement, isOver = false) {\n const { innerWidth: winW, innerHeight: winH, scrollY: winY, scrollX: winX } = window;\n const { offsetWidth: popperW, offsetHeight: popperH } = poppe;\n let anchorX = -winX;\n let anchorY = -winY;\n let el = anchor;\n\n do {\n anchorX += el?.offsetLeft || 0;\n anchorY += el?.offsetTop || 0;\n el = (el?.offsetParent || null) as HTMLElement | null;\n } while (el);\n\n const anchorBottom = anchorY + (anchor?.offsetHeight || 0);\n const hasSpaceUnder = anchorBottom + popperH < winH;\n const hasSpaceOver = anchorY - popperH > 0\n const placeUnder = (!isOver && hasSpaceUnder) || !hasSpaceOver // Always place under when no hasSpaceOver, as no OS can scroll further up than 0\n const scroll = placeUnder ? winY + anchorBottom + popperH + 30 : 0\n\n poppe.style.left = `${Math.round(Math.min(Math.max(10, anchorX), winW - popperW - 10))}px`\n poppe.style.top = `${Math.round(placeUnder ? anchorBottom : anchorY - popperH)}px`\n SCROLLER?.style.setProperty('top', `${Math.round(scroll)}px`);\n}\n","import styles from '../styles.module.css';\nimport { onAdd } from '../utils';\nconst CSS_TABLE = styles.table.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(tables: HTMLCollectionOf<Element>) {\n for(const table of tables) if (table instanceof HTMLTableElement) {\n const ths = Array.from(table.tHead?.rows[0]?.cells || [], (el) => el.innerText?.trim()); // Using innerText to only include visible text\n for (const tbody of table.tBodies) {\n for (const row of tbody.rows) {\n for (const cell of row.cells) {\n cell.setAttribute('data-th', ths[cell.cellIndex] || ':empty'); // Using U+200B to prevent empty string from collapsing\n }\n }\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const tables = el.getElementsByClassName(CSS_TABLE);\n const add = onAdd(styles.tableChildAdded, () => process(tables));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","const getSteps = (now: number, max: number, show: number) => {\n const offset = (show - 1) / 2;\n const start = Math.min(Math.max(now - Math.floor(offset), 1), max - show + 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);\n if (show > 3 && end < max) pages.splice(-2, 2, 0, max);\n return pages;\n};\n\nexport const pagination = ({\n current = 1,\n total = 10,\n show = 7,\n}) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && 'page' as const,\n key: `key-${page}-${index}`,\n page,\n })),\n});\n","import * as field from './field/field';\nimport * as fieldset from './fieldset/fieldset';\nimport * as popover from './popover/popover';\nimport * as table from './table/table';\nimport { IS_BROWSER } from './utils';\nexport { pagination } from './pagination/pagination';\nexport * as styles from './styles.module.css';\n\nif (IS_BROWSER) observe(document); // Automatic observe on browser\n\nexport function observe(el: Element | Document) {\n field.observe(el);\n fieldset.observe(el);\n popover.observe(el);\n table.observe(el);\n}\n\nexport function unobserve(el: Element | Document) {\n field.unobserve(el);\n fieldset.unobserve(el);\n popover.unobserve(el);\n table.unobserve(el);\n}"],"names":["IS_BROWSER","QUICK_EVENT","id","UUID","useId","el","events","action","element","rest","type","on","off","onAdd","animationName","callback","timer","onAnimation","event","isInputLike","CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","BOUND","renderAria","fields","field","labels","descs","input","valid","label","handleInput","target","renderCounter","limit","remainder","nextInvalid","css","observe","add","unobserve","CSS_FIELDSET","process","fieldsets","fieldset","inputs","validationId","handleLinkClick","handleToggle","CSS_POPOVER","SCROLLER","newState","anchor","_a","isOver","update","place","removeEvent","root","poppe","winW","winH","winY","winX","popperW","popperH","anchorX","anchorY","anchorBottom","hasSpaceUnder","hasSpaceOver","placeUnder","scroll","CSS_TABLE","tables","table","ths","_b","tbody","row","cell","getSteps","now","max","show","offset","start","end","pages","i","pagination","current","total","page","index","field.observe","fieldset.observe","popover.observe","table.observe","field.unobserve","fieldset.unobserve","popover.unobserve","table.unobserve"],"mappings":"01DAAaA,GAAa,OAAO,OAAW,KAAe,OAAO,SAAa,IAClEC,EAAc,CAAE,QAAS,GAAM,QAAS,EAAK,EAM1D,IAAIC,GAAK,EACT,MAAMC,GAAO,GAAG,KAAK,IAAM,EAAA,SAAS,EAAE,CAAC,GAAG,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,EAAG,CAAC,CAAC,GACzE,SAASC,EAAOC,EAAa,CAC9B,OAACA,EAAG,KAAIA,EAAG,GAAK,GAAGF,EAAI,GAAG,EAAED,EAAE,IAC5BG,EAAG,EACX,CAsBA,MAAMC,GAAS,CACdC,EACAC,EACAC,IACU,CACV,UAAWC,KAAQD,EAAK,CAAC,EAAE,MAAM,GAAG,EACnCA,EAAK,CAAC,EAAIC,EACV,QAAQ,UAAU,GAAGH,CAAM,eA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ACpB"}
|
|
1
|
+
{"version":3,"file":"index.iife.js","sources":["../designsystem/utils.ts","../designsystem/field/field.ts","../designsystem/fieldset/fieldset.ts","../designsystem/popover/popover.ts","../designsystem/table/table.ts","../designsystem/pagination/pagination.ts","../designsystem/index.ts"],"sourcesContent":["export const IS_BROWSER = typeof window !== 'undefined' && typeof document !== 'undefined';\nexport const QUICK_EVENT = { capture: true, passive: true };\n\n/**\n * useId\n * @return A generated unique ID\n */\nlet id = 0;\nconst UUID = `${Date.now().toString(36)}${Math.random().toString(36).slice(2, 5)}`;\nexport function useId (el: Element) {\n if (!el.id) el.id = `${UUID}${++id}`;\n\treturn el.id;\n};\n\n/**\n * Speed up MutationObserver by debouncing and only running when page is visible\n * @return new MutaionObserver\n */\nexport function createOptimizedMutationObserver(callback: MutationCallback) {\n const queue: MutationRecord[] = [];\n const observer = new MutationObserver((mutations) => {\n if (!queue[0]) requestAnimationFrame(process);\n queue.push(...mutations);\n });\n\n const process = () => {\n callback(queue, observer);\n queue.length = 0; // Reset queue\n };\n\n return observer;\n}\n\n// Internal helper for on / off\nconst events = (\n\taction: \"add\" | \"remove\",\n\telement: Node | Window,\n\trest: Parameters<typeof Element.prototype.addEventListener>,\n): void => {\n\tfor (const type of rest[0].split(\",\")) {\n\t\trest[0] = type;\n\t\tElement.prototype[`${action}EventListener`].apply(element, rest);\n\t}\n};\n\n/**\n * on\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const on = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.addEventListener>\n): void => events(\"add\", element, rest);\n\n/**\n * off\n * @param element The Element to use as EventTarget\n * @param types A comma separated string of event types\n * @param listener An event listener function or listener object\n */\nexport const off = (\n\telement: Node | Window,\n\t...rest: Parameters<typeof Element.prototype.removeEventListener>\n): void => events(\"remove\", element, rest);\n\n/**\n * Child added event inspired by:\n * https://davidwalsh.name/detect-node-insertion\n */\nexport const onAdd = (animationName: string, callback: () => void) => {\n let timer: ReturnType<typeof requestAnimationFrame> | number = 0;\n const onAnimation = (event: Event & { animationName?: string }) => {\n if (event.animationName === animationName) {\n cancelAnimationFrame(timer);\n timer = requestAnimationFrame(callback);\n }\n };\n\n\treturn {\n\t\tobserve: (el: Element | Document, ) => on(el, 'animationend', onAnimation, QUICK_EVENT),\n\t\tdisconnect: (el: Element | Document, ) => off(el, 'animationstart', onAnimation, QUICK_EVENT)\n\t};\n}\n\nexport const isInputLike = (el: unknown): el is HTMLInputElement =>\n\tel instanceof HTMLElement && 'validity' in el && !(el instanceof HTMLButtonElement);\n\n// Make React support popover=\"\"target attribute\n// https://github.com/facebook/react/issues/27479\ndeclare global {\n\tnamespace React.JSX {\n\t\tinterface IntrinsicAttributes {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: string | boolean;\n\t\t}\n\t}\n\tnamespace React {\n\t\tinterface HTMLAttributes<T> {\n\t\t\tpopovertargetaction?: string;\n\t\t\tpopovertarget?: string;\n\t\t\tpopover?: \"\" | \"auto\" | \"manual\" | undefined;\n\t\t}\n\t}\n}","import styles from '../styles.module.css';\nimport { QUICK_EVENT, isInputLike, off, on, onAdd, useId } from '../utils';\n\nconst CSS_FIELD = styles.field.split(' ')[0];\nconst CSS_VALIDATIONS = styles.validation.split(' ');\nconst CSS_VALIDATION = CSS_VALIDATIONS[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction renderAria(fields: HTMLCollectionOf<Element>) {\n for(const field of fields) {\n const labels: HTMLLabelElement[] = [];\n const descs: string[] = [];\n let input: HTMLInputElement | null = null;\n let valid = true;\n\n for (const el of field.getElementsByTagName('*')) {\n if (el instanceof HTMLLabelElement) labels.push(el);\n else if (isInputLike(el)) input = el;\n else if (el.classList.contains(CSS_VALIDATION)) { // Must be before instanceof HTMLParagraphElement since validation can also be a <p>\n valid = el.getAttribute('data-color') === 'success';\n descs.unshift(useId(el));\n } else if (el instanceof HTMLParagraphElement) descs.push(useId(el));\n }\n\n if (input) for (const label of labels) label.htmlFor = useId(input);\n if (input) renderCounter(input);\n\n input?.setAttribute('aria-describedby', descs.join(' '));\n input?.setAttribute('aria-invalid', `${!valid}`);\n }\n}\nfunction handleInput({ target }: Event) {\n if (isInputLike(target)) renderCounter(target);\n}\n\nfunction renderCounter(input: HTMLInputElement) {\n const el = input?.nextElementSibling;\n const limit = el?.getAttribute('data-count');\n\n if (el && limit) {\n const remainder = Number(limit) - input.value.length;\n const nextInvalid = remainder < 0;\n const prevInvalid = el.getAttribute('aria-live') === 'polite';\n\n if (prevInvalid !== nextInvalid) {\n el.setAttribute('aria-live', nextInvalid ? 'polite' : 'off');\n for (const css of CSS_VALIDATIONS) el.classList.toggle(css, nextInvalid);\n }\n el.textContent = `${Math.abs(remainder)} tegn ${nextInvalid ? 'for mye' : 'igjen'}`;\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELD);\n const add = onAdd(styles.fieldChildAdded, () => renderAria(fields));\n BOUND.set(el, add);\n add.observe(el);\n on(el, 'input', handleInput, QUICK_EVENT);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n off(el, 'input', handleInput, QUICK_EVENT);\n}\n","import styles from '../styles.module.css';\nimport { isInputLike, onAdd, useId } from '../utils';\nconst CSS_FIELDSET = styles.fieldset.split(' ')[0];\nconst CSS_VALIDATION = styles.validation.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(fieldsets: HTMLCollectionOf<Element>) {\n for(const fieldset of fieldsets) {\n const inputs: HTMLInputElement[] = [];\n let validationId = '';\n\n for (const el of fieldset.getElementsByTagName('*')) {\n if (el.classList.contains(CSS_VALIDATION)) validationId = useId(el);\n else if (isInputLike(el)) inputs.push(el);\n }\n\n if (validationId) \n for(const input of inputs) {\n input.setAttribute('aria-describedby', validationId);\n input.setAttribute('aria-invalid', 'true');\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const fields = el.getElementsByClassName(CSS_FIELDSET);\n const add = onAdd(styles.fieldsetValidationAdded, () => process(fields));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","import styles from '../styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, off, on } from '../utils';\n\nexport function observe(el: Node) {\n on(el, 'click', handleLinkClick); // Allow `<a>` to use `popovertarget` as well\n on(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\nexport function unobserve(el: Node) {\n off(el, 'click', handleLinkClick);\n off(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\n\ntype Toggle = Event & { newState?: string };\nconst CSS_POPOVER = styles.popover.split(' ')[0];\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) SCROLLER.style.cssText = 'position:absolute;padding:1px';\n\nfunction handleToggle ({ target: el, newState }: Toggle){\n const isPopping = newState === 'open' && el instanceof HTMLElement && el.classList.contains(CSS_POPOVER);\n const anchor = isPopping && (el.getRootNode() as ShadowRoot)?.querySelector<HTMLElement>(`[popovertarget=\"${el.id}\"]`);\n\n if (anchor) {\n const isOver = el.getAttribute('data-position') === 'over';\n const update = () => place(anchor, el, isOver);\n const removeEvent = ({ newState }: Toggle) => {\n if (newState === 'open') return;\n off(document, 'DOMContentReady', update, QUICK_EVENT);\n off(el, 'toggle', removeEvent, QUICK_EVENT);\n off(window, 'load,resize,scroll', update, QUICK_EVENT);\n SCROLLER?.remove();\n }\n\n document.body.append(SCROLLER || '');\n document.fonts.ready.then(update); // Inital render and when fonts load\n on(window, 'load,resize,scroll', update, QUICK_EVENT);\n on(document, 'DOMContentReady', update, QUICK_EVENT);\n on(el, 'toggle', removeEvent, QUICK_EVENT);\n }\n}\n\n// Polyfill popovertarget for <a> (not supported by native)\n// and automatically assume popovertarget is the closest parent popover\n// but respect the popovertarget and popovertargetaction attribute\nfunction handleLinkClick (event: Event){\n const link = event.target instanceof Element && event.target.closest('a');\n if (link) {\n const root = link.getRootNode() as ShadowRoot;\n const target = root.getElementById?.(link.getAttribute('popovertarget') || '') || link.closest(`.${CSS_POPOVER}`);\n const action = link.getAttribute('popovertargetaction') || 'toggle';\n\n if (!event.defaultPrevented) target?.togglePopover(action === 'show' || (action === 'hide' ? false : undefined));\n }\n}\n\nfunction place (anchor: HTMLElement | null, poppe: HTMLElement, isOver = false) {\n const { innerWidth: winW, innerHeight: winH, scrollY: winY, scrollX: winX } = window;\n const { offsetWidth: popperW, offsetHeight: popperH } = poppe;\n let anchorX = -winX;\n let anchorY = -winY;\n let el = anchor;\n\n do {\n anchorX += el?.offsetLeft || 0;\n anchorY += el?.offsetTop || 0;\n el = (el?.offsetParent || null) as HTMLElement | null;\n } while (el);\n\n const anchorBottom = anchorY + (anchor?.offsetHeight || 0);\n const hasSpaceUnder = anchorBottom + popperH < winH;\n const hasSpaceOver = anchorY - popperH > 0\n const placeUnder = (!isOver && hasSpaceUnder) || !hasSpaceOver // Always place under when no hasSpaceOver, as no OS can scroll further up than 0\n const scroll = placeUnder ? winY + anchorBottom + popperH + 30 : 0\n\n poppe.style.left = `${Math.round(Math.min(Math.max(10, anchorX), winW - popperW - 10))}px`\n poppe.style.top = `${Math.round(placeUnder ? anchorBottom : anchorY - popperH)}px`\n SCROLLER?.style.setProperty('top', `${Math.round(scroll)}px`);\n}\n","import styles from '../styles.module.css';\nimport { onAdd } from '../utils';\nconst CSS_TABLE = styles.table.split(' ')[0];\nconst BOUND = new WeakMap<Element | Document, ReturnType<typeof onAdd>>();\n\nfunction process(tables: HTMLCollectionOf<Element>) {\n for(const table of tables) if (table instanceof HTMLTableElement) {\n const ths = Array.from(table.tHead?.rows[0]?.cells || [], (el) => el.innerText?.trim()); // Using innerText to only include visible text\n for (const tbody of table.tBodies) {\n for (const row of tbody.rows) {\n for (const cell of row.cells) {\n cell.setAttribute('data-th', ths[cell.cellIndex] || ':empty'); // Using U+200B to prevent empty string from collapsing\n }\n }\n }\n }\n}\n\nexport function observe (el: Element | Document) {\n const tables = el.getElementsByClassName(CSS_TABLE);\n const add = onAdd(styles.tableChildAdded, () => process(tables));\n BOUND.set(el, add);\n add.observe(el);\n}\n\nexport function unobserve (el: Element | Document) {\n BOUND.get(el)?.disconnect(el);\n}\n","const getSteps = (now: number, max: number, show: number) => {\n const offset = (show - 1) / 2;\n const start = Math.min(Math.max(now - Math.floor(offset), 1), max - show + 1);\n const end = Math.min(Math.max(now + Math.ceil(offset), show), max);\n const pages = Array.from({ length: end + 1 - start }, (_, i) => i + start);\n\n if (show > 4 && start > 1) pages.splice(0, 2, 1, 0);\n if (show > 3 && end < max) pages.splice(-2, 2, 0, max);\n return pages;\n};\n\nexport const pagination = ({\n current = 1,\n total = 10,\n show = 7,\n}) => ({\n prev: current > 1 ? current - 1 : 0,\n next: current < total ? current + 1 : 0,\n pages: getSteps(current, total, show).map((page, index) => ({\n current: page === current && 'page' as const,\n key: `key-${page}-${index}`,\n page,\n })),\n});\n","import * as field from './field/field';\nimport * as fieldset from './fieldset/fieldset';\nimport * as popover from './popover/popover';\nimport * as table from './table/table';\nimport { IS_BROWSER } from './utils';\nexport { pagination } from './pagination/pagination';\nexport * as styles from './styles.module.css';\n\nif (IS_BROWSER) observe(document); // Automatic observe on browser\n\nexport function observe(el: Element | Document) {\n field.observe(el);\n fieldset.observe(el);\n popover.observe(el);\n table.observe(el);\n}\n\nexport function unobserve(el: Element | Document) {\n field.unobserve(el);\n fieldset.unobserve(el);\n popover.unobserve(el);\n table.unobserve(el);\n}"],"names":["IS_BROWSER","QUICK_EVENT","id","UUID","useId","el","events","action","element","rest","type","on","off","onAdd","animationName","callback","timer","onAnimation","event","isInputLike","CSS_FIELD","styles","CSS_VALIDATIONS","CSS_VALIDATION","BOUND","renderAria","fields","field","labels","descs","input","valid","label","handleInput","target","renderCounter","limit","remainder","nextInvalid","css","observe","add","unobserve","CSS_FIELDSET","process","fieldsets","fieldset","inputs","validationId","handleLinkClick","handleToggle","CSS_POPOVER","SCROLLER","newState","anchor","_a","isOver","update","place","removeEvent","link","root","poppe","winW","winH","winY","winX","popperW","popperH","anchorX","anchorY","anchorBottom","hasSpaceUnder","hasSpaceOver","placeUnder","scroll","CSS_TABLE","tables","table","ths","_b","tbody","row","cell","getSteps","now","max","show","offset","start","end","pages","i","pagination","current","total","page","index","field.observe","fieldset.observe","popover.observe","table.observe","field.unobserve","fieldset.unobserve","popover.unobserve","table.unobserve"],"mappings":"01DAAaA,GAAa,OAAO,OAAW,KAAe,OAAO,SAAa,IAClEC,EAAc,CAAE,QAAS,GAAM,QAAS,EAAK,EAM1D,IAAIC,GAAK,EACT,MAAMC,GAAO,GAAG,KAAK,IAAM,EAAA,SAAS,EAAE,CAAC,GAAG,KAAK,SAAS,SAAS,EAAE,EAAE,MAAM,EAAG,CAAC,CAAC,GACzE,SAASC,EAAOC,EAAa,CAC9B,OAACA,EAAG,KAAIA,EAAG,GAAK,GAAGF,EAAI,GAAG,EAAED,EAAE,IAC5BG,EAAG,EACX,CAsBA,MAAMC,GAAS,CACdC,EACAC,EACAC,IACU,CACV,UAAWC,KAAQD,EAAK,CAAC,EAAE,MAAM,GAAG,EACnCA,EAAK,CAAC,EAAIC,EACV,QAAQ,UAAU,GAAGH,CAAM,eAAe,EAAE,MAAMC,EAASC,CAAI,CAEjE,EAQaE,EAAK,CACjBH,KACGC,IACOH,GAAO,MAAOE,EAASC,CAAI,EAQzBG,EAAM,CAClBJ,KACGC,IACOH,GAAO,SAAUE,EAASC,CAAI,EAM5BI,EAAQ,CAACC,EAAuBC,IAAyB,CACpE,IAAIC,EAA2D,EACzD,MAAAC,EAAeC,GAA8C,CAC7DA,EAAM,gBAAkBJ,IAC1B,qBAAqBE,CAAK,EAC1BA,EAAQ,sBAAsBD,CAAQ,EAE1C,EAEM,MAAA,CACN,QAAUV,GAA6BM,EAAGN,EAAI,eAAgBY,E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,KAAK,KAAKG,CAAM,EAAGD,CAAI,EAAGD,CAAG,EAC3DK,EAAQ,MAAM,KAAK,CAAE,OAAQD,EAAM,EAAID,CAAS,EAAA,CAAC,EAAGG,IAAMA,EAAIH,CAAK,EAErE,OAAAF,EAAO,GAAKE,EAAQ,KAAS,OAAO,EAAG,EAAG,EAAG,CAAC,EAC9CF,EAAO,GAAKG,EAAMJ,KAAW,OAAO,GAAI,EAAG,EAAGA,CAAG,EAC9CK,CACT,EAEaE,GAAa,CAAC,CACzB,QAAAC,EAAU,EACV,MAAAC,EAAQ,GACR,KAAAR,EAAO,CACT,KAAO,CACL,KAAMO,EAAU,EAAIA,EAAU,EAAI,EAClC,KAAMA,EAAUC,EAAQD,EAAU,EAAI,EACtC,MAAOV,GAASU,EAASC,EAAOR,CAAI,EAAE,IAAI,CAACS,EAAMC,KAAW,CAC1D,QAASD,IAASF,GAAW,OAC7B,IAAK,OAAOE,CAAI,IAAIC,CAAK,GACzB,KAAAD,CAAA,EACA,CACJ,GCfIhG,OAAoB,QAAQ,EAEzB,SAASwC,GAAQnC,EAAwB,CAC9C6F,GAAc7F,CAAE,EAChB8F,GAAiB9F,CAAE,EACnB+F,GAAgB/F,CAAE,EAClBgG,GAAchG,CAAE,CAClB,CAEO,SAASqC,GAAUrC,EAAwB,CAChDiG,GAAgBjG,CAAE,EAClBkG,GAAmBlG,CAAE,EACrBmG,GAAkBnG,CAAE,EACpBoG,GAAgBpG,CAAE,CACpB"}
|
package/mtds/popover/popover.js
CHANGED
|
@@ -1,42 +1,42 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { IS_BROWSER as
|
|
3
|
-
function
|
|
4
|
-
|
|
1
|
+
import E from "../styles.module.css.js";
|
|
2
|
+
import { IS_BROWSER as H, on as p, QUICK_EVENT as c, off as f } from "../utils.js";
|
|
3
|
+
function W(t) {
|
|
4
|
+
p(t, "click", M), p(t, "toggle", y, c);
|
|
5
5
|
}
|
|
6
|
-
function
|
|
7
|
-
f(t, "click",
|
|
6
|
+
function $(t) {
|
|
7
|
+
f(t, "click", M), f(t, "toggle", y, c);
|
|
8
8
|
}
|
|
9
|
-
const
|
|
9
|
+
const w = E.popover.split(" ")[0], n = H ? document.createElement("div") : null;
|
|
10
10
|
n && (n.style.cssText = "position:absolute;padding:1px");
|
|
11
|
-
function
|
|
11
|
+
function y({ target: t, newState: o }) {
|
|
12
12
|
var i;
|
|
13
|
-
const s =
|
|
13
|
+
const s = o === "open" && t instanceof HTMLElement && t.classList.contains(w) && ((i = t.getRootNode()) == null ? void 0 : i.querySelector(`[popovertarget="${t.id}"]`));
|
|
14
14
|
if (s) {
|
|
15
|
-
const r = t.getAttribute("data-position") === "over", a = () =>
|
|
16
|
-
|
|
15
|
+
const r = t.getAttribute("data-position") === "over", a = () => k(s, t, r), g = ({ newState: l }) => {
|
|
16
|
+
l !== "open" && (f(document, "DOMContentReady", a, c), f(t, "toggle", g, c), f(window, "load,resize,scroll", a, c), n == null || n.remove());
|
|
17
17
|
};
|
|
18
|
-
document.body.append(n || ""), document.fonts.ready.then(a),
|
|
18
|
+
document.body.append(n || ""), document.fonts.ready.then(a), p(window, "load,resize,scroll", a, c), p(document, "DOMContentReady", a, c), p(t, "toggle", g, c);
|
|
19
19
|
}
|
|
20
20
|
}
|
|
21
|
-
function
|
|
22
|
-
var
|
|
23
|
-
const
|
|
24
|
-
if (
|
|
25
|
-
const s =
|
|
26
|
-
i == null || i.togglePopover(r === "show" || (r === "hide" ? !1 : void 0));
|
|
21
|
+
function M(t) {
|
|
22
|
+
var d;
|
|
23
|
+
const o = t.target instanceof Element && t.target.closest("a");
|
|
24
|
+
if (o) {
|
|
25
|
+
const s = o.getRootNode(), i = ((d = s.getElementById) == null ? void 0 : d.call(s, o.getAttribute("popovertarget") || "")) || o.closest(`.${w}`), r = o.getAttribute("popovertargetaction") || "toggle";
|
|
26
|
+
t.defaultPrevented || i == null || i.togglePopover(r === "show" || (r === "hide" ? !1 : void 0));
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
function
|
|
30
|
-
const { innerWidth: s, innerHeight: i, scrollY: r, scrollX: a } = window, { offsetWidth: g, offsetHeight:
|
|
31
|
-
let h = -a, u = -r,
|
|
29
|
+
function k(t, o, d = !1) {
|
|
30
|
+
const { innerWidth: s, innerHeight: i, scrollY: r, scrollX: a } = window, { offsetWidth: g, offsetHeight: l } = o;
|
|
31
|
+
let h = -a, u = -r, e = t;
|
|
32
32
|
do
|
|
33
|
-
h += (
|
|
34
|
-
while (
|
|
35
|
-
const m = u + ((t == null ? void 0 : t.offsetHeight) || 0),
|
|
36
|
-
|
|
33
|
+
h += (e == null ? void 0 : e.offsetLeft) || 0, u += (e == null ? void 0 : e.offsetTop) || 0, e = (e == null ? void 0 : e.offsetParent) || null;
|
|
34
|
+
while (e);
|
|
35
|
+
const m = u + ((t == null ? void 0 : t.offsetHeight) || 0), P = m + l < i, b = u - l > 0, v = !d && P || !b, x = v ? r + m + l + 30 : 0;
|
|
36
|
+
o.style.left = `${Math.round(Math.min(Math.max(10, h), s - g - 10))}px`, o.style.top = `${Math.round(v ? m : u - l)}px`, n == null || n.style.setProperty("top", `${Math.round(x)}px`);
|
|
37
37
|
}
|
|
38
38
|
export {
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
W as observe,
|
|
40
|
+
$ as unobserve
|
|
41
41
|
};
|
|
42
42
|
//# sourceMappingURL=popover.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"popover.js","sources":["../../designsystem/popover/popover.ts"],"sourcesContent":["import styles from '../styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, off, on } from '../utils';\n\nexport function observe(el: Node) {\n on(el, 'click', handleLinkClick); // Allow `<a>` to use `popovertarget` as well\n on(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\nexport function unobserve(el: Node) {\n off(el, 'click', handleLinkClick);\n off(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\n\ntype Toggle = Event & { newState?: string };\nconst CSS_POPOVER = styles.popover.split(' ')[0];\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) SCROLLER.style.cssText = 'position:absolute;padding:1px';\n\nfunction handleToggle ({ target: el, newState }: Toggle){\n const isPopping = newState === 'open' && el instanceof HTMLElement && el.classList.contains(CSS_POPOVER);\n const anchor = isPopping && (el.getRootNode() as ShadowRoot)?.querySelector<HTMLElement>(`[popovertarget=\"${el.id}\"]`);\n\n if (anchor) {\n const isOver = el.getAttribute('data-position') === 'over';\n const update = () => place(anchor, el, isOver);\n const removeEvent = ({ newState }: Toggle) => {\n if (newState === 'open') return;\n off(document, 'DOMContentReady', update, QUICK_EVENT);\n off(el, 'toggle', removeEvent, QUICK_EVENT);\n off(window, 'load,resize,scroll', update, QUICK_EVENT);\n SCROLLER?.remove();\n }\n\n document.body.append(SCROLLER || '');\n document.fonts.ready.then(update); // Inital render and when fonts load\n on(window, 'load,resize,scroll', update, QUICK_EVENT);\n on(document, 'DOMContentReady', update, QUICK_EVENT);\n on(el, 'toggle', removeEvent, QUICK_EVENT);\n }\n}\n\n// Polyfill popovertarget for <a> (not supported by native)\nfunction handleLinkClick (
|
|
1
|
+
{"version":3,"file":"popover.js","sources":["../../designsystem/popover/popover.ts"],"sourcesContent":["import styles from '../styles.module.css';\nimport { IS_BROWSER, QUICK_EVENT, off, on } from '../utils';\n\nexport function observe(el: Node) {\n on(el, 'click', handleLinkClick); // Allow `<a>` to use `popovertarget` as well\n on(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\nexport function unobserve(el: Node) {\n off(el, 'click', handleLinkClick);\n off(el, 'toggle', handleToggle, QUICK_EVENT); // Use capture since toggle does not bubble\n}\n\ntype Toggle = Event & { newState?: string };\nconst CSS_POPOVER = styles.popover.split(' ')[0];\nconst SCROLLER = IS_BROWSER ? document.createElement('div') : null // Used to ensure we have scrollability under\nif (SCROLLER) SCROLLER.style.cssText = 'position:absolute;padding:1px';\n\nfunction handleToggle ({ target: el, newState }: Toggle){\n const isPopping = newState === 'open' && el instanceof HTMLElement && el.classList.contains(CSS_POPOVER);\n const anchor = isPopping && (el.getRootNode() as ShadowRoot)?.querySelector<HTMLElement>(`[popovertarget=\"${el.id}\"]`);\n\n if (anchor) {\n const isOver = el.getAttribute('data-position') === 'over';\n const update = () => place(anchor, el, isOver);\n const removeEvent = ({ newState }: Toggle) => {\n if (newState === 'open') return;\n off(document, 'DOMContentReady', update, QUICK_EVENT);\n off(el, 'toggle', removeEvent, QUICK_EVENT);\n off(window, 'load,resize,scroll', update, QUICK_EVENT);\n SCROLLER?.remove();\n }\n\n document.body.append(SCROLLER || '');\n document.fonts.ready.then(update); // Inital render and when fonts load\n on(window, 'load,resize,scroll', update, QUICK_EVENT);\n on(document, 'DOMContentReady', update, QUICK_EVENT);\n on(el, 'toggle', removeEvent, QUICK_EVENT);\n }\n}\n\n// Polyfill popovertarget for <a> (not supported by native)\n// and automatically assume popovertarget is the closest parent popover\n// but respect the popovertarget and popovertargetaction attribute\nfunction handleLinkClick (event: Event){\n const link = event.target instanceof Element && event.target.closest('a');\n if (link) {\n const root = link.getRootNode() as ShadowRoot;\n const target = root.getElementById?.(link.getAttribute('popovertarget') || '') || link.closest(`.${CSS_POPOVER}`);\n const action = link.getAttribute('popovertargetaction') || 'toggle';\n\n if (!event.defaultPrevented) target?.togglePopover(action === 'show' || (action === 'hide' ? false : undefined));\n }\n}\n\nfunction place (anchor: HTMLElement | null, poppe: HTMLElement, isOver = false) {\n const { innerWidth: winW, innerHeight: winH, scrollY: winY, scrollX: winX } = window;\n const { offsetWidth: popperW, offsetHeight: popperH } = poppe;\n let anchorX = -winX;\n let anchorY = -winY;\n let el = anchor;\n\n do {\n anchorX += el?.offsetLeft || 0;\n anchorY += el?.offsetTop || 0;\n el = (el?.offsetParent || null) as HTMLElement | null;\n } while (el);\n\n const anchorBottom = anchorY + (anchor?.offsetHeight || 0);\n const hasSpaceUnder = anchorBottom + popperH < winH;\n const hasSpaceOver = anchorY - popperH > 0\n const placeUnder = (!isOver && hasSpaceUnder) || !hasSpaceOver // Always place under when no hasSpaceOver, as no OS can scroll further up than 0\n const scroll = placeUnder ? winY + anchorBottom + popperH + 30 : 0\n\n poppe.style.left = `${Math.round(Math.min(Math.max(10, anchorX), winW - popperW - 10))}px`\n poppe.style.top = `${Math.round(placeUnder ? anchorBottom : anchorY - popperH)}px`\n SCROLLER?.style.setProperty('top', `${Math.round(scroll)}px`);\n}\n"],"names":["observe","el","on","handleLinkClick","handleToggle","QUICK_EVENT","unobserve","off","CSS_POPOVER","styles","SCROLLER","IS_BROWSER","newState","anchor","_a","isOver","update","place","removeEvent","event","link","root","target","action","poppe","winW","winH","winY","winX","popperW","popperH","anchorX","anchorY","anchorBottom","hasSpaceUnder","hasSpaceOver","placeUnder","scroll"],"mappings":";;AAGO,SAASA,EAAQC,GAAU;AAC7B,EAAAC,EAAAD,GAAI,SAASE,CAAe,GAC5BD,EAAAD,GAAI,UAAUG,GAAcC,CAAW;AAC5C;AACO,SAASC,EAAUL,GAAU;AAC9B,EAAAM,EAAAN,GAAI,SAASE,CAAe,GAC5BI,EAAAN,GAAI,UAAUG,GAAcC,CAAW;AAC7C;AAGA,MAAMG,IAAcC,EAAO,QAAQ,MAAM,GAAG,EAAE,CAAC,GACzCC,IAAWC,IAAa,SAAS,cAAc,KAAK,IAAI;AAC1DD,MAAmBA,EAAA,MAAM,UAAU;AAEvC,SAASN,EAAc,EAAE,QAAQH,GAAI,UAAAW,KAAmB;;AAEhD,QAAAC,IADYD,MAAa,UAAUX,aAAc,eAAeA,EAAG,UAAU,SAASO,CAAW,OAC1EM,IAAAb,EAAG,kBAAH,gBAAAa,EAAiC,cAA2B,mBAAmBb,EAAG,EAAE;AAEjH,MAAIY,GAAQ;AACV,UAAME,IAASd,EAAG,aAAa,eAAe,MAAM,QAC9Ce,IAAS,MAAMC,EAAMJ,GAAQZ,GAAIc,CAAM,GACv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