ember-primitives 0.32.0 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/declarations/-private.d.ts +0 -1
- package/declarations/color-scheme.d.ts +0 -1
- package/declarations/components/-private/typed-elements.d.ts +0 -1
- package/declarations/components/-private/utils.d.ts +0 -1
- package/declarations/components/accordion/content.d.ts +0 -1
- package/declarations/components/accordion/header.d.ts +0 -1
- package/declarations/components/accordion/item.d.ts +0 -1
- package/declarations/components/accordion/public.d.ts +0 -1
- package/declarations/components/accordion/trigger.d.ts +0 -1
- package/declarations/components/accordion.d.ts +0 -1
- package/declarations/components/avatar.d.ts +0 -1
- package/declarations/components/dialog.d.ts +0 -1
- package/declarations/components/external-link.d.ts +0 -1
- package/declarations/components/form.d.ts +0 -1
- package/declarations/components/keys.d.ts +0 -1
- package/declarations/components/layout/hero.d.ts +0 -1
- package/declarations/components/layout/sticky-footer.d.ts +0 -1
- package/declarations/components/link.d.ts +0 -1
- package/declarations/components/menu.d.ts +0 -1
- package/declarations/components/one-time-password/buttons.d.ts +0 -1
- package/declarations/components/one-time-password/index.d.ts +0 -1
- package/declarations/components/one-time-password/input.d.ts +0 -1
- package/declarations/components/one-time-password/otp.d.ts +0 -1
- package/declarations/components/one-time-password/utils.d.ts +0 -1
- package/declarations/components/popover.d.ts +0 -1
- package/declarations/components/portal-targets.d.ts +0 -1
- package/declarations/components/portal.d.ts +0 -1
- package/declarations/components/progress.d.ts +0 -1
- package/declarations/components/rating/index.d.ts +0 -1
- package/declarations/components/rating/public-types.d.ts +0 -1
- package/declarations/components/rating/range.d.ts +0 -1
- package/declarations/components/rating/stars.d.ts +0 -1
- package/declarations/components/rating/state.d.ts +0 -1
- package/declarations/components/rating/utils.d.ts +0 -1
- package/declarations/components/rating.d.ts +0 -1
- package/declarations/components/scroller.d.ts +0 -1
- package/declarations/components/shadowed.d.ts +0 -1
- package/declarations/components/switch.d.ts +0 -1
- package/declarations/components/toggle-group.d.ts +0 -1
- package/declarations/components/toggle.d.ts +0 -1
- package/declarations/components/visually-hidden.d.ts +0 -1
- package/declarations/components/zoetrope/index.d.ts +0 -1
- package/declarations/components/zoetrope/types.d.ts +0 -1
- package/declarations/components/zoetrope.d.ts +0 -1
- package/declarations/floating-ui/component.d.ts +0 -1
- package/declarations/floating-ui/middleware.d.ts +0 -1
- package/declarations/floating-ui/modifier.d.ts +0 -1
- package/declarations/floating-ui.d.ts +0 -1
- package/declarations/helpers/body-class.d.ts +0 -1
- package/declarations/helpers/link.d.ts +0 -1
- package/declarations/helpers/service.d.ts +0 -1
- package/declarations/helpers.d.ts +0 -1
- package/declarations/iframe.d.ts +0 -1
- package/declarations/index.d.ts +0 -1
- package/declarations/on-resize.d.ts +0 -1
- package/declarations/proper-links.d.ts +0 -1
- package/declarations/qp.d.ts +73 -0
- package/declarations/styles.css.d.ts +0 -1
- package/declarations/tabster.d.ts +0 -1
- package/declarations/template-registry.d.ts +0 -1
- package/declarations/test-support/a11y.d.ts +0 -1
- package/declarations/test-support/index.d.ts +0 -1
- package/declarations/test-support/otp.d.ts +0 -1
- package/declarations/test-support/rating.d.ts +0 -1
- package/declarations/test-support/routing.d.ts +0 -1
- package/declarations/test-support/zoetrope.d.ts +0 -1
- package/declarations/utils.d.ts +0 -1
- package/dist/components/-private/typed-elements.js.map +1 -1
- package/dist/components/accordion.js.map +1 -1
- package/dist/components/avatar.js.map +1 -1
- package/dist/components/dialog.js.map +1 -1
- package/dist/components/external-link.js.map +1 -1
- package/dist/components/form.js.map +1 -1
- package/dist/components/keys.js.map +1 -1
- package/dist/components/layout/hero.js.map +1 -1
- package/dist/components/layout/sticky-footer.js.map +1 -1
- package/dist/components/link.js.map +1 -1
- package/dist/components/menu.js.map +1 -1
- package/dist/components/one-time-password/buttons.js.map +1 -1
- package/dist/components/one-time-password/input.js.map +1 -1
- package/dist/components/one-time-password/otp.js.map +1 -1
- package/dist/components/one-time-password/utils.js.map +1 -1
- package/dist/components/popover.js.map +1 -1
- package/dist/components/portal-targets.js.map +1 -1
- package/dist/components/portal.js.map +1 -1
- package/dist/components/progress.js.map +1 -1
- package/dist/components/rating/index.js.map +1 -1
- package/dist/components/rating/range.js.map +1 -1
- package/dist/components/rating/stars.js.map +1 -1
- package/dist/components/rating/state.js.map +1 -1
- package/dist/components/scroller.js.map +1 -1
- package/dist/components/shadowed.js.map +1 -1
- package/dist/components/switch.js.map +1 -1
- package/dist/components/toggle-group.js.map +1 -1
- package/dist/components/toggle.js.map +1 -1
- package/dist/components/violations.css +8 -8
- package/dist/components/visually-hidden.js.map +1 -1
- package/dist/components/zoetrope/index.js.map +1 -1
- package/dist/floating-ui/component.js.map +1 -1
- package/dist/floating-ui/modifier.js.map +1 -1
- package/dist/item-D6pwWzMs.js.map +1 -1
- package/dist/proper-links.js.map +1 -1
- package/dist/qp.js +92 -0
- package/dist/qp.js.map +1 -0
- package/dist/test-support/otp.js.map +1 -1
- package/dist/test-support/rating.js.map +1 -1
- package/package.json +13 -13
- package/declarations/-private.d.ts.map +0 -1
- package/declarations/color-scheme.d.ts.map +0 -1
- package/declarations/components/-private/typed-elements.d.ts.map +0 -1
- package/declarations/components/-private/utils.d.ts.map +0 -1
- package/declarations/components/accordion/content.d.ts.map +0 -1
- package/declarations/components/accordion/header.d.ts.map +0 -1
- package/declarations/components/accordion/item.d.ts.map +0 -1
- package/declarations/components/accordion/public.d.ts.map +0 -1
- package/declarations/components/accordion/trigger.d.ts.map +0 -1
- package/declarations/components/accordion.d.ts.map +0 -1
- package/declarations/components/avatar.d.ts.map +0 -1
- package/declarations/components/dialog.d.ts.map +0 -1
- package/declarations/components/external-link.d.ts.map +0 -1
- package/declarations/components/form.d.ts.map +0 -1
- package/declarations/components/keys.d.ts.map +0 -1
- package/declarations/components/layout/hero.d.ts.map +0 -1
- package/declarations/components/layout/sticky-footer.d.ts.map +0 -1
- package/declarations/components/link.d.ts.map +0 -1
- package/declarations/components/menu.d.ts.map +0 -1
- package/declarations/components/one-time-password/buttons.d.ts.map +0 -1
- package/declarations/components/one-time-password/index.d.ts.map +0 -1
- package/declarations/components/one-time-password/input.d.ts.map +0 -1
- package/declarations/components/one-time-password/otp.d.ts.map +0 -1
- package/declarations/components/one-time-password/utils.d.ts.map +0 -1
- package/declarations/components/popover.d.ts.map +0 -1
- package/declarations/components/portal-targets.d.ts.map +0 -1
- package/declarations/components/portal.d.ts.map +0 -1
- package/declarations/components/progress.d.ts.map +0 -1
- package/declarations/components/rating/index.d.ts.map +0 -1
- package/declarations/components/rating/public-types.d.ts.map +0 -1
- package/declarations/components/rating/range.d.ts.map +0 -1
- package/declarations/components/rating/stars.d.ts.map +0 -1
- package/declarations/components/rating/state.d.ts.map +0 -1
- package/declarations/components/rating/utils.d.ts.map +0 -1
- package/declarations/components/rating.d.ts.map +0 -1
- package/declarations/components/scroller.d.ts.map +0 -1
- package/declarations/components/shadowed.d.ts.map +0 -1
- package/declarations/components/switch.d.ts.map +0 -1
- package/declarations/components/toggle-group.d.ts.map +0 -1
- package/declarations/components/toggle.d.ts.map +0 -1
- package/declarations/components/visually-hidden.d.ts.map +0 -1
- package/declarations/components/zoetrope/index.d.ts.map +0 -1
- package/declarations/components/zoetrope/types.d.ts.map +0 -1
- package/declarations/components/zoetrope.d.ts.map +0 -1
- package/declarations/floating-ui/component.d.ts.map +0 -1
- package/declarations/floating-ui/middleware.d.ts.map +0 -1
- package/declarations/floating-ui/modifier.d.ts.map +0 -1
- package/declarations/floating-ui.d.ts.map +0 -1
- package/declarations/helpers/body-class.d.ts.map +0 -1
- package/declarations/helpers/link.d.ts.map +0 -1
- package/declarations/helpers/service.d.ts.map +0 -1
- package/declarations/helpers.d.ts.map +0 -1
- package/declarations/iframe.d.ts.map +0 -1
- package/declarations/index.d.ts.map +0 -1
- package/declarations/on-resize.d.ts.map +0 -1
- package/declarations/proper-links.d.ts.map +0 -1
- package/declarations/styles.css.d.ts.map +0 -1
- package/declarations/tabster.d.ts.map +0 -1
- package/declarations/template-registry.d.ts.map +0 -1
- package/declarations/test-support/a11y.d.ts.map +0 -1
- package/declarations/test-support/index.d.ts.map +0 -1
- package/declarations/test-support/otp.d.ts.map +0 -1
- package/declarations/test-support/rating.d.ts.map +0 -1
- package/declarations/test-support/routing.d.ts.map +0 -1
- package/declarations/test-support/zoetrope.d.ts.map +0 -1
- package/declarations/utils.d.ts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scroller.js","sources":["../../src/components/scroller.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\nimport { isDestroyed, isDestroying } from \"@ember/destroyable\";\nimport { hash } from \"@ember/helper\";\n\nimport { modifier } from \"ember-modifier\";\n\n/**\n * Utility component for helping with scrolling in any direction within\n * any of the 4 directions: up, down, left, right.\n *\n * This can be used to auto-scroll content as new content is inserted into the scrollable area, or possibly to bring focus to something on the page.\n */\nexport class Scroller extends Component<{\n /**\n * A containing element is required - in this case, a div.\n * It must be scrollable for this component to work, but can be customized.\n *\n * By default, this element will have some styling applied:\n * overflow: auto;\n *\n * By default, this element will have tabindex=\"0\" to support keyboard usage.\n *\n * The scroll-behavior is \"auto\", which can be controlled via CSS\n * https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior\n *\n */\n Element: HTMLDivElement;\n Blocks: {\n default: [\n {\n /**\n * Scroll the content to the bottom\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToBottom) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToBottom: () => void;\n /**\n * Scroll the content to the top\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToTop) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToTop: () => void;\n /**\n * Scroll the content to the left\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToLeft) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToLeft: () => void;\n /**\n * Scroll the content to the right\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToRight) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToRight: () => void;\n },\n ];\n };\n}> {\n declare withinElement: HTMLDivElement;\n\n ref = modifier((el: HTMLDivElement) => {\n this.withinElement = el;\n });\n\n #frame?: number;\n\n scrollToBottom = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n top: this.withinElement.scrollHeight,\n behavior: \"auto\",\n });\n });\n };\n\n scrollToTop = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n top: 0,\n behavior: \"auto\",\n });\n });\n };\n\n scrollToLeft = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n left: 0,\n behavior: \"auto\",\n });\n });\n };\n\n scrollToRight = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n left: this.withinElement.scrollWidth,\n behavior: \"auto\",\n });\n });\n };\n\n <template>\n <div tabindex=\"0\" ...attributes {{this.ref}}>\n {{yield\n (hash\n scrollToBottom=this.scrollToBottom\n scrollToTop=this.scrollToTop\n scrollToLeft=this.scrollToLeft\n scrollToRight=this.scrollToRight\n )\n }}\n </div>\n </template>\n}\n"],"names":["Scroller","Component","ref","modifier","el","withinElement","scrollToBottom","cancelAnimationFrame","requestAnimationFrame","isDestroyed","isDestroying","scrollTo","top","scrollHeight","behavior","scrollToTop","scrollToLeft","left","scrollToRight","scrollWidth","setComponentTemplate","precompileTemplate","strictMode","scope","hash"],"mappings":";;;;;;;AAYO,MAAMA,
|
|
1
|
+
{"version":3,"file":"scroller.js","sources":["../../src/components/scroller.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\nimport { isDestroyed, isDestroying } from \"@ember/destroyable\";\nimport { hash } from \"@ember/helper\";\n\nimport { modifier } from \"ember-modifier\";\n\n/**\n * Utility component for helping with scrolling in any direction within\n * any of the 4 directions: up, down, left, right.\n *\n * This can be used to auto-scroll content as new content is inserted into the scrollable area, or possibly to bring focus to something on the page.\n */\nexport class Scroller extends Component<{\n /**\n * A containing element is required - in this case, a div.\n * It must be scrollable for this component to work, but can be customized.\n *\n * By default, this element will have some styling applied:\n * overflow: auto;\n *\n * By default, this element will have tabindex=\"0\" to support keyboard usage.\n *\n * The scroll-behavior is \"auto\", which can be controlled via CSS\n * https://developer.mozilla.org/en-US/docs/Web/CSS/scroll-behavior\n *\n */\n Element: HTMLDivElement;\n Blocks: {\n default: [\n {\n /**\n * Scroll the content to the bottom\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToBottom) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToBottom: () => void;\n /**\n * Scroll the content to the top\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToTop) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToTop: () => void;\n /**\n * Scroll the content to the left\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToLeft) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToLeft: () => void;\n /**\n * Scroll the content to the right\n *\n * ```gjs\n * import { Scroller } from 'ember-primitives';\n *\n * <template>\n * <Scroller as |s|>\n * ...\n *\n * {{ (s.scrollToRight) }}\n * </Scroller>\n * </template>\n * ```\n */\n scrollToRight: () => void;\n },\n ];\n };\n}> {\n declare withinElement: HTMLDivElement;\n\n ref = modifier((el: HTMLDivElement) => {\n this.withinElement = el;\n });\n\n #frame?: number;\n\n scrollToBottom = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n top: this.withinElement.scrollHeight,\n behavior: \"auto\",\n });\n });\n };\n\n scrollToTop = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n top: 0,\n behavior: \"auto\",\n });\n });\n };\n\n scrollToLeft = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n left: 0,\n behavior: \"auto\",\n });\n });\n };\n\n scrollToRight = () => {\n if (this.#frame) {\n cancelAnimationFrame(this.#frame);\n }\n\n this.#frame = requestAnimationFrame(() => {\n if (isDestroyed(this) || isDestroying(this)) return;\n\n this.withinElement.scrollTo({\n left: this.withinElement.scrollWidth,\n behavior: \"auto\",\n });\n });\n };\n\n <template>\n <div tabindex=\"0\" ...attributes {{this.ref}}>\n {{yield\n (hash\n scrollToBottom=this.scrollToBottom\n scrollToTop=this.scrollToTop\n scrollToLeft=this.scrollToLeft\n scrollToRight=this.scrollToRight\n )\n }}\n </div>\n </template>\n}\n"],"names":["Scroller","Component","ref","modifier","el","withinElement","scrollToBottom","cancelAnimationFrame","requestAnimationFrame","isDestroyed","isDestroying","scrollTo","top","scrollHeight","behavior","scrollToTop","scrollToLeft","left","scrollToRight","scrollWidth","setComponentT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ClC,IAAIC,WAAA,CAAY,IAAI,CAAA,IAAKC,YAAA,CAAa,IAAI,CAAA,EAAG;AAE7C,MAAA,IAAI,CAACL,aAAa,CAACM,QAAQ,CAAC;AAC1BM,QAAAA,IAAA,EAAM,CAAA;AACNH,QAAAA,QAAA,EAAU;AACZ,OAAA,CAAA;AACF,KAAA,CAAA;GACF;EAEAI,aAAA,GAAgBA,MAAA;AACd,IAAA,IAAI,IAAI,CAAC,MAAM,EAAE;AACfX,MAAAA,oBAAA,CAAqB,IAAI,CAAC,MAAM,CAAA;AAClC;AAEA,IAAA,IAAI,CAAC,MAAM,GAAGC,qBAAA,CAAsB,MAAA;MAClC,IAAIC,WAAA,CAAY,IAAI,CAAA,IAAKC,YAAA,CAAa,IAAI,CAAA,EAAG;AAE7C,MAAA,IAAI,CAACL,aAAa,CAACM,QAAQ,CAAC;AAC1BM,QAAAA,IAAA,EAAM,IAAI,CAACZ,aAAa,CAACc,WAAW;AACpCL,QAAAA,QAAA,EAAU;AACZ,OAAA,CAAA;AACF,KAAA,CAAA;GACF;AAEA,EAAA;IAAAM,oBAAA,CAAAC,kBAAA,CAAA,+NAAA,EAWA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shadowed.js","sources":["../../src/components/shadowed.gts"],"sourcesContent":["import { modifier } from \"ember-modifier\";\nimport { cell } from \"ember-resources\";\n\nimport type { TOC } from \"@ember/component/template-only\";\n\nconst Shadow = () => {\n const shadow = cell<Element>();\n\n return {\n get root() {\n return shadow.current;\n },\n attach: modifier((element: Element) => {\n const shadowRoot = element.attachShadow({ mode: \"open\" });\n const div = document.createElement(\"div\");\n\n // ember-source 5.6 broke the ability to in-element\n // natively into a shadowroot.\n //\n // See these ember-source bugs:\n // - https://github.com/emberjs/ember.js/issues/20643\n // - https://github.com/emberjs/ember.js/issues/20642\n // - https://github.com/emberjs/ember.js/issues/20641\n shadowRoot.appendChild(div);\n\n shadow.set(div);\n }),\n };\n};\n\n// index.html has the production-fingerprinted references to these links\n// Ideally, we'd have some pre-processor scan everything for references to\n// assets in public, but idk how to set that up\nconst getStyles = () => [...document.querySelectorAll(\"link\")].map((link) => link.href);\n\n/**\n * style + native @import\n * is the only robust way to load styles in a shadowroot.\n *\n * link is only valid in the head element.\n */\nconst Styles = <template>\n <style>\n {{#each (getStyles) as |styleHref|}}\n\n @import \"{{styleHref}}\";\n\n {{/each}}\n </style>\n</template>;\n\n/**\n * Render content in a shadow dom, attached to a div.\n *\n * Uses the [shadow DOM][mdn-shadow-dom] API.\n *\n * [mdn-shadow-dom]: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM\n *\n * This is useful when you want to render content that escapes your app's styles.\n */\nexport const Shadowed: TOC<{\n /**\n * The shadow dom attaches to a div element.\n * You may specify any attribute, and it'll be applied to this host element.\n */\n Element: HTMLDivElement;\n Args: {\n /**\n * @public\n *\n * By default, shadow-dom does not include any styles.\n * Setting this to true will include all the `<style>` tags\n * that are present in the `<head>` element.\n */\n includeStyles?: boolean;\n };\n Blocks: {\n /**\n * Content to be placed within the ShadowDOM\n */\n default: [];\n };\n}> = <template>\n {{#let (Shadow) as |shadow|}}\n {{! TODO: We need a way in ember to render in to a shadow dom without an effect }}\n <div {{shadow.attach}} ...attributes></div>\n\n {{#if shadow.root}}\n {{#in-element shadow.root}}\n\n {{#if @includeStyles}}\n <Styles />\n {{/if}}\n\n {{yield}}\n\n {{/in-element}}\n {{/if}}\n {{/let}}\n</template>;\n\nexport default Shadowed;\n"],"names":["Shadow","shadow","cell","root","current","attach","modifier","element","shadowRoot","attachShadow","mode","div","document","createElement","appendChild","set","getStyles","querySelectorAll","map","link","href","Styles","setComponentTemplate","precompileTemplate","strictMode","scope","templateOnly","Shadowed"],"mappings":";;;;;;AAKA,MAAMA,
|
|
1
|
+
{"version":3,"file":"shadowed.js","sources":["../../src/components/shadowed.gts"],"sourcesContent":["import { modifier } from \"ember-modifier\";\nimport { cell } from \"ember-resources\";\n\nimport type { TOC } from \"@ember/component/template-only\";\n\nconst Shadow = () => {\n const shadow = cell<Element>();\n\n return {\n get root() {\n return shadow.current;\n },\n attach: modifier((element: Element) => {\n const shadowRoot = element.attachShadow({ mode: \"open\" });\n const div = document.createElement(\"div\");\n\n // ember-source 5.6 broke the ability to in-element\n // natively into a shadowroot.\n //\n // See these ember-source bugs:\n // - https://github.com/emberjs/ember.js/issues/20643\n // - https://github.com/emberjs/ember.js/issues/20642\n // - https://github.com/emberjs/ember.js/issues/20641\n shadowRoot.appendChild(div);\n\n shadow.set(div);\n }),\n };\n};\n\n// index.html has the production-fingerprinted references to these links\n// Ideally, we'd have some pre-processor scan everything for references to\n// assets in public, but idk how to set that up\nconst getStyles = () => [...document.querySelectorAll(\"link\")].map((link) => link.href);\n\n/**\n * style + native @import\n * is the only robust way to load styles in a shadowroot.\n *\n * link is only valid in the head element.\n */\nconst Styles = <template>\n <style>\n {{#each (getStyles) as |styleHref|}}\n\n @import \"{{styleHref}}\";\n\n {{/each}}\n </style>\n</template>;\n\n/**\n * Render content in a shadow dom, attached to a div.\n *\n * Uses the [shadow DOM][mdn-shadow-dom] API.\n *\n * [mdn-shadow-dom]: https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_shadow_DOM\n *\n * This is useful when you want to render content that escapes your app's styles.\n */\nexport const Shadowed: TOC<{\n /**\n * The shadow dom attaches to a div element.\n * You may specify any attribute, and it'll be applied to this host element.\n */\n Element: HTMLDivElement;\n Args: {\n /**\n * @public\n *\n * By default, shadow-dom does not include any styles.\n * Setting this to true will include all the `<style>` tags\n * that are present in the `<head>` element.\n */\n includeStyles?: boolean;\n };\n Blocks: {\n /**\n * Content to be placed within the ShadowDOM\n */\n default: [];\n };\n}> = <template>\n {{#let (Shadow) as |shadow|}}\n {{! TODO: We need a way in ember to render in to a shadow dom without an effect }}\n <div {{shadow.attach}} ...attributes></div>\n\n {{#if shadow.root}}\n {{#in-element shadow.root}}\n\n {{#if @includeStyles}}\n <Styles />\n {{/if}}\n\n {{yield}}\n\n {{/in-element}}\n {{/if}}\n {{/let}}\n</template>;\n\nexport default Shadowed;\n"],"names":["Shadow","shadow","cell","root","current","attach","modifier","element","shadowRoot","attachShadow","mode","div","document","createElement","appendChild","set","getStyles","querySelectorAll","map","link","href","Styles","setComponentTemplate","precompileTemplate","strictMode","scope","templateOnly","Shadowed"],"mappings":";;;;;;AAKA,MAAMA,MAAA,GAASA,MAAA;AACb,EAAA,MAAMC,SAASC,IAAA,EAAK;EAEpB,OAAO;IACL,IAAIC,IAAAA,GAAO;MACT,OAAOF,OAAOG,OAAO;KACvB;AACAC,IAAAA,MAAA,EAAQC,QAAA,CAAUC,OAAS,IAAA;AACzB,MAAA,MAAMC,UAAA,GAAaD,OAAA,CAAQE,YAAY,CAAC;AAAEC,QAAAA,IAAA,EAAM;AAAO,OAAA,CAAA;AACvD,MAAA,MAAMC,GAAA,GAAMC,QAAA,CAASC,aAAa,CAAC,KAAA,CAAA;AAEnC;AACA;AACA;AACA;AACA;AACA;AACA;AACAL,MAAAA,UAAA,CAAWM,WAAW,CAACH,GAAA,CAAA;AAEvBV,MAAAA,MAAA,CAAOc,GAAG,CAACJ,GAAA,CAAA;KACb;GACF;AACF,CAAA;AAEA;AACA;AACA;AACA,MAAMK,YAAYA,MAAM,CAAI,GAAAJ,QAAA,CAASK,gBAAgB,CAAC,MAAA,CAAA,CAAQ,CAACC,GAAG,CAAEC,IAAA,IAASA,KAAKC,IAAI,CAAA;AAEtF;;;;;;AAMA,MAAMC,MAAA,GAAAC,oBAAA,CAASC,kBAAA,CAAA,0HAAA,EAQf;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;AAAAT,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAU,YAAA,EAAA,CAAA;AAEV;;;;;;;;;MASaC,QAsBR,GAAAL,oBAAA,CAAAC,kBAAA,CAAA,gYAAA,EAiBL;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;IAAAzB,MAAA;AAAAqB,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAK,YAAA,EAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"switch.js","sources":["../../src/components/switch.gts"],"sourcesContent":["import { fn, hash } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\n\nimport { cell } from \"ember-resources\";\n\nimport { uniqueId } from \"../utils.ts\";\nimport { Label } from \"./-private/typed-elements.gts\";\nimport { toggleWithFallback } from \"./-private/utils.ts\";\n\nimport type { TOC } from \"@ember/component/template-only\";\nimport type { WithBoundArgs } from \"@glint/template\";\n\nexport interface Signature {\n Element: HTMLInputElement;\n Args: {\n /**\n * The initial checked value of the Switch.\n * This value is reactive, so if the value that\n * `@checked` is set to updates, the state of the Switch will also update.\n */\n checked?: boolean;\n /**\n * Callback when the Switch state is toggled\n */\n onChange?: (checked: boolean, event: Event) => void;\n };\n Blocks: {\n default?: [\n {\n /**\n * The Switch Element.\n * It has a pre-wired `id` so that the relevant Label is\n * appropriately associated via the `for` property of the Label.\n *\n * ```gjs\n * import { Switch } from 'ember-primitives';\n *\n * <template>\n * <Switch as |s|>\n * <s.Control />\n * </Switch>\n * </template>\n * ```\n */\n Control: WithBoundArgs<typeof Checkbox, \"checked\" | \"id\" | \"onChange\">;\n /**\n * The Switch element requires a label, and this label already has\n * the association to the Control by setting the `for` attribute to the `id` of the Control\n *\n * ```gjs\n * import { Switch } from 'ember-primitives';\n *\n * <template>\n * <Switch as |s|>\n * <s.Label />\n * </Switch>\n * </template>\n * ```\n */\n Label: WithBoundArgs<typeof Label, \"for\">;\n },\n ];\n };\n}\n\ninterface ControlSignature {\n Element: HTMLInputElement;\n Args: { id: string; checked?: boolean; onChange: () => void };\n}\n\nconst Checkbox: TOC<ControlSignature> = <template>\n {{#let (cell @checked) as |checked|}}\n <input\n id={{@id}}\n type=\"checkbox\"\n role=\"switch\"\n checked={{checked.current}}\n aria-checked={{checked.current}}\n data-state={{if checked.current \"on\" \"off\"}}\n {{on \"click\" (fn toggleWithFallback checked.toggle @onChange)}}\n ...attributes\n />\n {{/let}}\n</template>;\n\n/**\n * @public\n */\nexport const Switch: TOC<Signature> = <template>\n <div ...attributes data-prim-switch>\n {{! @glint-nocheck }}\n {{#let (uniqueId) as |id|}}\n {{yield\n (hash\n Control=(component Checkbox checked=@checked id=id onChange=@onChange)\n Label=(component Label for=id)\n )\n }}\n {{/let}}\n </div>\n</template>;\n\nexport default Switch;\n"],"names":["Checkbox","setComponentTemplate","precompileTemplate","strictMode","scope","cell","on","fn","toggleWithFallback","templateOnly","Switch","uniqueId","hash","Label"],"mappings":";;;;;;;;;;AAsEA,MAAMA,
|
|
1
|
+
{"version":3,"file":"switch.js","sources":["../../src/components/switch.gts"],"sourcesContent":["import { fn, hash } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\n\nimport { cell } from \"ember-resources\";\n\nimport { uniqueId } from \"../utils.ts\";\nimport { Label } from \"./-private/typed-elements.gts\";\nimport { toggleWithFallback } from \"./-private/utils.ts\";\n\nimport type { TOC } from \"@ember/component/template-only\";\nimport type { WithBoundArgs } from \"@glint/template\";\n\nexport interface Signature {\n Element: HTMLInputElement;\n Args: {\n /**\n * The initial checked value of the Switch.\n * This value is reactive, so if the value that\n * `@checked` is set to updates, the state of the Switch will also update.\n */\n checked?: boolean;\n /**\n * Callback when the Switch state is toggled\n */\n onChange?: (checked: boolean, event: Event) => void;\n };\n Blocks: {\n default?: [\n {\n /**\n * The Switch Element.\n * It has a pre-wired `id` so that the relevant Label is\n * appropriately associated via the `for` property of the Label.\n *\n * ```gjs\n * import { Switch } from 'ember-primitives';\n *\n * <template>\n * <Switch as |s|>\n * <s.Control />\n * </Switch>\n * </template>\n * ```\n */\n Control: WithBoundArgs<typeof Checkbox, \"checked\" | \"id\" | \"onChange\">;\n /**\n * The Switch element requires a label, and this label already has\n * the association to the Control by setting the `for` attribute to the `id` of the Control\n *\n * ```gjs\n * import { Switch } from 'ember-primitives';\n *\n * <template>\n * <Switch as |s|>\n * <s.Label />\n * </Switch>\n * </template>\n * ```\n */\n Label: WithBoundArgs<typeof Label, \"for\">;\n },\n ];\n };\n}\n\ninterface ControlSignature {\n Element: HTMLInputElement;\n Args: { id: string; checked?: boolean; onChange: () => void };\n}\n\nconst Checkbox: TOC<ControlSignature> = <template>\n {{#let (cell @checked) as |checked|}}\n <input\n id={{@id}}\n type=\"checkbox\"\n role=\"switch\"\n checked={{checked.current}}\n aria-checked={{checked.current}}\n data-state={{if checked.current \"on\" \"off\"}}\n {{on \"click\" (fn toggleWithFallback checked.toggle @onChange)}}\n ...attributes\n />\n {{/let}}\n</template>;\n\n/**\n * @public\n */\nexport const Switch: TOC<Signature> = <template>\n <div ...attributes data-prim-switch>\n {{! @glint-nocheck }}\n {{#let (uniqueId) as |id|}}\n {{yield\n (hash\n Control=(component Checkbox checked=@checked id=id onChange=@onChange)\n Label=(component Label for=id)\n )\n }}\n {{/let}}\n </div>\n</template>;\n\nexport default Switch;\n"],"names":["Checkbox","setComponentTemplate","precompileTemplate","strictMode","scope","cell","on","fn","toggleWithFallback","templateOnly","Switch","uniqueId","hash","Label"],"mappings":";;;;;;;;;;AAsEA,MAAMA,QAAc,GAAAC,oBAAA,CAAoBC,kBAAA,CAAA,mTAAA,EAaxC;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;IAAAC,IAAA;IAAAC,EAAA;IAAAC,EAAA;AAAAC,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAC,YAAA,EAAA,CAAA;AAEV;;AAEC;MACYC,MAAY,GAAAT,oBAAA,CAAaC,kBAAA,CAAA,kQAAA,EAYtC;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;IAAAO,QAAA;IAAAC,IAAA;IAAAZ,QAAA;AAAAa,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAJ,YAAA,EAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle-group.js","sources":["../../src/components/toggle-group.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\nimport { cached } from \"@glimmer/tracking\";\nimport { hash } from \"@ember/helper\";\n\nimport { getTabsterAttribute, MoverDirections } from \"tabster\";\nimport { TrackedSet } from \"tracked-built-ins\";\n// The consumer will need to provide types for tracked-toolbox.\n// Or.. better yet, we PR to trakcked-toolbox to provide them\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { localCopy } from \"tracked-toolbox\";\n\nimport { Toggle } from \"./toggle.gts\";\n\nimport type { ComponentLike } from \"@glint/template\";\n\nconst TABSTER_CONFIG = getTabsterAttribute(\n {\n mover: {\n direction: MoverDirections.Both,\n cyclic: true,\n },\n },\n true,\n);\n\nexport interface ItemSignature<Value = any> {\n /**\n * The button element will have aria-pressed=\"true\" on it when the button is in the pressed state.\n */\n Element: HTMLButtonElement;\n Args: {\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */\n value?: Value;\n };\n Blocks: {\n default: [\n /**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */\n pressed: boolean,\n ];\n };\n}\n\nexport type Item<Value = any> = ComponentLike<ItemSignature<Value>>;\n\nexport interface SingleSignature<Value> {\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */\n value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [\n {\n /**\n * The Toggle Switch\n */\n Item: Item;\n },\n ];\n };\n}\n\nexport interface MultiSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */\n value?: Value[] | Set<Value> | Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Set<Value>) => void;\n };\n Blocks: {\n default: [\n {\n /**\n * The Toggle Switch\n */\n Item: Item;\n },\n ];\n };\n}\n\ninterface PrivateSingleSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n type?: \"single\";\n\n /**\n * Optionally set the initial toggle state\n */\n value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [\n {\n Item: Item;\n },\n ];\n };\n}\n\ninterface PrivateMultiSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n type: \"multi\";\n /**\n * Optionally set the initial toggle state\n */\n value?: Value[] | Set<Value> | Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Set<Value>) => void;\n };\n Blocks: {\n default: [\n {\n Item: Item;\n },\n ];\n };\n}\n\nfunction isMulti(x: \"single\" | \"multi\" | undefined): x is \"multi\" {\n return x === \"multi\";\n}\n\nexport class ToggleGroup<Value = any> extends Component<\n PrivateSingleSignature<Value> | PrivateMultiSignature<Value>\n> {\n // See: https://github.com/typed-ember/glint/issues/715\n <template>\n {{#if (isMulti this.args.type)}}\n <MultiToggleGroup\n @value={{this.args.value}}\n @onChange={{this.args.onChange}}\n ...attributes\n as |x|\n >\n {{yield x}}\n </MultiToggleGroup>\n {{else}}\n <SingleToggleGroup\n @value={{this.args.value}}\n @onChange={{this.args.onChange}}\n ...attributes\n as |x|\n >\n {{yield x}}\n </SingleToggleGroup>\n {{/if}}\n </template>\n}\n\nclass SingleToggleGroup<Value = any> extends Component<SingleSignature<Value>> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n @localCopy(\"args.value\") activePressed?: Value;\n\n handleToggle = (value: Value) => {\n if (this.activePressed === value) {\n this.activePressed = undefined;\n\n return;\n }\n\n this.activePressed = value;\n\n this.args.onChange?.(this.activePressed);\n };\n\n isPressed = (value: Value | undefined) => value === this.activePressed;\n\n <template>\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n </template>\n}\n\nclass MultiToggleGroup<Value = any> extends Component<MultiSignature<Value>> {\n /**\n * Normalizes @value to a Set\n * and makes sure that even if the input Set is reactive,\n * we don't mistakenly dirty it.\n */\n @cached\n get activePressed(): TrackedSet<Value> {\n const value = this.args.value;\n\n if (!value) {\n return new TrackedSet();\n }\n\n if (Array.isArray(value)) {\n return new TrackedSet(value);\n }\n\n if (value instanceof Set) {\n return new TrackedSet(value);\n }\n\n return new TrackedSet([value]);\n }\n\n handleToggle = (value: Value) => {\n if (this.activePressed.has(value)) {\n this.activePressed.delete(value);\n } else {\n this.activePressed.add(value);\n }\n\n this.args.onChange?.(new Set<Value>(this.activePressed.values()));\n };\n\n isPressed = (value: Value) => this.activePressed.has(value);\n\n <template>\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n </template>\n}\n"],"names":["TABSTER_CONFIG","getTabsterAttribute","mover","direction","MoverDirections","Both","cyclic","isMulti","x","ToggleGroup","Component","setComponentTemplate","precompileTemplate","strictMode","scope","MultiToggleGroup","SingleToggleGroup","g","prototype","localCopy","i","void 0","handleToggle","value","activePressed","undefined","args","onChange","isPressed","hash","Toggle","TrackedSet","Array","isArray","Set","n","cached","has","delete","add","values"],"mappings":";;;;;;;;;;;AAgBA,MAAMA,iBAAiBC,
|
|
1
|
+
{"version":3,"file":"toggle-group.js","sources":["../../src/components/toggle-group.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\nimport { cached } from \"@glimmer/tracking\";\nimport { hash } from \"@ember/helper\";\n\nimport { getTabsterAttribute, MoverDirections } from \"tabster\";\nimport { TrackedSet } from \"tracked-built-ins\";\n// The consumer will need to provide types for tracked-toolbox.\n// Or.. better yet, we PR to trakcked-toolbox to provide them\n// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-ignore\nimport { localCopy } from \"tracked-toolbox\";\n\nimport { Toggle } from \"./toggle.gts\";\n\nimport type { ComponentLike } from \"@glint/template\";\n\nconst TABSTER_CONFIG = getTabsterAttribute(\n {\n mover: {\n direction: MoverDirections.Both,\n cyclic: true,\n },\n },\n true,\n);\n\nexport interface ItemSignature<Value = any> {\n /**\n * The button element will have aria-pressed=\"true\" on it when the button is in the pressed state.\n */\n Element: HTMLButtonElement;\n Args: {\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */\n value?: Value;\n };\n Blocks: {\n default: [\n /**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */\n pressed: boolean,\n ];\n };\n}\n\nexport type Item<Value = any> = ComponentLike<ItemSignature<Value>>;\n\nexport interface SingleSignature<Value> {\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */\n value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [\n {\n /**\n * The Toggle Switch\n */\n Item: Item;\n },\n ];\n };\n}\n\nexport interface MultiSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n /**\n * Optionally set the initial toggle state\n */\n value?: Value[] | Set<Value> | Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Set<Value>) => void;\n };\n Blocks: {\n default: [\n {\n /**\n * The Toggle Switch\n */\n Item: Item;\n },\n ];\n };\n}\n\ninterface PrivateSingleSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n type?: \"single\";\n\n /**\n * Optionally set the initial toggle state\n */\n value?: Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Value | undefined) => void;\n };\n Blocks: {\n default: [\n {\n Item: Item;\n },\n ];\n };\n}\n\ninterface PrivateMultiSignature<Value = any> {\n Element: HTMLDivElement;\n Args: {\n type: \"multi\";\n /**\n * Optionally set the initial toggle state\n */\n value?: Value[] | Set<Value> | Value;\n /**\n * Callback for when the toggle-group's state is changed.\n *\n * Can be used to control the state of the component.\n *\n *\n * When none of the toggles are selected, undefined will be passed.\n */\n onChange?: (value: Set<Value>) => void;\n };\n Blocks: {\n default: [\n {\n Item: Item;\n },\n ];\n };\n}\n\nfunction isMulti(x: \"single\" | \"multi\" | undefined): x is \"multi\" {\n return x === \"multi\";\n}\n\nexport class ToggleGroup<Value = any> extends Component<\n PrivateSingleSignature<Value> | PrivateMultiSignature<Value>\n> {\n // See: https://github.com/typed-ember/glint/issues/715\n <template>\n {{#if (isMulti this.args.type)}}\n <MultiToggleGroup\n @value={{this.args.value}}\n @onChange={{this.args.onChange}}\n ...attributes\n as |x|\n >\n {{yield x}}\n </MultiToggleGroup>\n {{else}}\n <SingleToggleGroup\n @value={{this.args.value}}\n @onChange={{this.args.onChange}}\n ...attributes\n as |x|\n >\n {{yield x}}\n </SingleToggleGroup>\n {{/if}}\n </template>\n}\n\nclass SingleToggleGroup<Value = any> extends Component<SingleSignature<Value>> {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-call\n @localCopy(\"args.value\") activePressed?: Value;\n\n handleToggle = (value: Value) => {\n if (this.activePressed === value) {\n this.activePressed = undefined;\n\n return;\n }\n\n this.activePressed = value;\n\n this.args.onChange?.(this.activePressed);\n };\n\n isPressed = (value: Value | undefined) => value === this.activePressed;\n\n <template>\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n </template>\n}\n\nclass MultiToggleGroup<Value = any> extends Component<MultiSignature<Value>> {\n /**\n * Normalizes @value to a Set\n * and makes sure that even if the input Set is reactive,\n * we don't mistakenly dirty it.\n */\n @cached\n get activePressed(): TrackedSet<Value> {\n const value = this.args.value;\n\n if (!value) {\n return new TrackedSet();\n }\n\n if (Array.isArray(value)) {\n return new TrackedSet(value);\n }\n\n if (value instanceof Set) {\n return new TrackedSet(value);\n }\n\n return new TrackedSet([value]);\n }\n\n handleToggle = (value: Value) => {\n if (this.activePressed.has(value)) {\n this.activePressed.delete(value);\n } else {\n this.activePressed.add(value);\n }\n\n this.args.onChange?.(new Set<Value>(this.activePressed.values()));\n };\n\n isPressed = (value: Value) => this.activePressed.has(value);\n\n <template>\n <div data-tabster={{TABSTER_CONFIG}} ...attributes>\n {{yield (hash Item=(component Toggle onChange=this.handleToggle isPressed=this.isPressed))}}\n </div>\n </template>\n}\n"],"names":["TABSTER_CONFIG","getTabsterAttribute","mover","direction","MoverDirections","Both","cyclic","isMulti","x","ToggleGroup","Component","setComponentTemplate","precompileTemplate","strictMode","scope","MultiToggleGroup","SingleToggleGroup","g","prototype","localCopy","i","void 0","handleToggle","value","activePressed","undefined","args","onChange","isPressed","hash","Toggle","TrackedSet","Array","isArray","Set","n","cached","has","delete","add","values"],"mappings":";;;;;;;;;;;AAgBA,MAAMA,iBAAiBC,mBAAA,CACrB;AACEC,EAAAA,KAAA,EAAO;IACLC,SAAA,EAAWC,gBAAgBC,IAAI;AAC/BC,IAAAA,MAAA,EAAQ;AACV;AACF,CAAA,EACA,IAAA,CAAA;AA+IF,SAASC,QAAQC,CAAiC,EAAQ;EACxD,OAAOA,CAA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IAAIQ,UAAA,EAAA;AACb;AAEA,IAAA,IAAIC,KAAA,CAAMC,OAAO,CAACV,KAAA,CAAA,EAAQ;AACxB,MAAA,OAAO,IAAIQ,UAAA,CAAWR,KAAA,CAAA;AACxB;IAEA,IAAIA,iBAAiBW,GAAA,EAAK;AACxB,MAAA,OAAO,IAAIH,UAAA,CAAWR,KAAA,CAAA;AACxB;AAEA,IAAA,OAAO,IAAIQ,UAAA,CAAW,CAACR,KAAA,CAAM,CAAA;AAC/B;AAAA,EAAA;IAAAY,CAAA,CAAA,IAAA,CAAAjB,SAAA,EAAA,eAAA,EAAA,CAjBCkB,MAAA,CAAA,CAAA;AAAA;EAmBDd,YAAA,GAAgBC,KAAO,IAAA;IACrB,IAAI,IAAI,CAACC,aAAa,CAACa,GAAG,CAACd,KAAA,CAAA,EAAQ;AACjC,MAAA,IAAI,CAACC,aAAa,CAACc,MAAM,CAACf,KAAA,CAAA;AAC5B,KAAA,MAAO;AACL,MAAA,IAAI,CAACC,aAAa,CAACe,GAAG,CAAChB,KAAA,CAAA;AACzB;AAEA,IAAA,IAAI,CAACG,IAAI,CAACC,QAAQ,GAAG,IAAIO,GAAA,CAAW,IAAI,CAACV,aAAa,CAACgB,MAAM,EAAA,CAAA,CAAA;GAC/D;EAEAZ,SAAA,GAAaL,KAAO,IAAU,IAAI,CAACC,aAAa,CAACa,GAAG,CAACd,KAAA,CAAA;AAErD,EAAA;IAAAZ,oBAAA,CAAAC,kBAAA,CAAA,+KAAA,EAIA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAd,cAAA;QAAA6B,IAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"toggle.js","sources":["../../src/components/toggle.gts"],"sourcesContent":["// import Component from '@glimmer/component';\nimport { fn } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\n\nimport { cell } from \"ember-resources\";\n\nimport { toggleWithFallback } from \"./-private/utils.ts\";\n\nimport type { TOC } from \"@ember/component/template-only\";\n\nexport interface Signature<Value = any> {\n Element: HTMLButtonElement;\n Args: {\n /**\n * The pressed-state of the toggle.\n *\n * Can be used to control the state of the component.\n */\n pressed?: boolean;\n /**\n * Callback for when the toggle's state is changed.\n *\n * Can be used to control the state of the component.\n *\n * if a `@value` is passed to this `<Toggle>`, that @value will\n * be passed to the `@onChange` handler.\n *\n * This can be useful when using the same function for the `@onChange`\n * handler with multiple `<Toggle>` components.\n */\n onChange?: (value: Value | undefined, pressed: boolean) => void;\n\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */\n value?: Value;\n\n /**\n * When controlling state in a wrapping component, this function can be used in conjunction with `@value` to determine if this `<Toggle>` should appear pressed.\n */\n isPressed?: (value?: Value) => boolean;\n };\n Blocks: {\n default: [\n /**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */\n pressed: boolean,\n ];\n };\n}\n\nfunction isPressed(\n pressed?: boolean,\n value?: unknown,\n isPressed?: (value?: unknown) => boolean,\n): boolean {\n if (!value) return Boolean(pressed);\n if (!isPressed) return Boolean(pressed);\n\n return isPressed(value);\n}\n\nexport const Toggle: TOC<Signature> = <template>\n {{#let (cell (isPressed @pressed @value @isPressed)) as |pressed|}}\n <button\n type=\"button\"\n aria-pressed=\"{{pressed.current}}\"\n {{on \"click\" (fn toggleWithFallback pressed.toggle @onChange @value)}}\n ...attributes\n >\n {{yield pressed.current}}\n </button>\n {{/let}}\n</template>;\n\nexport default Toggle;\n"],"names":["isPressed","pressed","value","Boolean","Toggle","setComponentTemplate","precompileTemplate","strictMode","scope","cell","on","fn","toggleWithFallback","templateOnly"],"mappings":";;;;;;;;AAAA;;AAwDA,SAASA,
|
|
1
|
+
{"version":3,"file":"toggle.js","sources":["../../src/components/toggle.gts"],"sourcesContent":["// import Component from '@glimmer/component';\nimport { fn } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\n\nimport { cell } from \"ember-resources\";\n\nimport { toggleWithFallback } from \"./-private/utils.ts\";\n\nimport type { TOC } from \"@ember/component/template-only\";\n\nexport interface Signature<Value = any> {\n Element: HTMLButtonElement;\n Args: {\n /**\n * The pressed-state of the toggle.\n *\n * Can be used to control the state of the component.\n */\n pressed?: boolean;\n /**\n * Callback for when the toggle's state is changed.\n *\n * Can be used to control the state of the component.\n *\n * if a `@value` is passed to this `<Toggle>`, that @value will\n * be passed to the `@onChange` handler.\n *\n * This can be useful when using the same function for the `@onChange`\n * handler with multiple `<Toggle>` components.\n */\n onChange?: (value: Value | undefined, pressed: boolean) => void;\n\n /**\n * When used in a group of Toggles, this option will be helpful to\n * know which toggle was pressed if you're using the same @onChange\n * handler for multiple toggles.\n */\n value?: Value;\n\n /**\n * When controlling state in a wrapping component, this function can be used in conjunction with `@value` to determine if this `<Toggle>` should appear pressed.\n */\n isPressed?: (value?: Value) => boolean;\n };\n Blocks: {\n default: [\n /**\n * the current pressed state of the toggle button\n *\n * Useful when using the toggle button as an uncontrolled component\n */\n pressed: boolean,\n ];\n };\n}\n\nfunction isPressed(\n pressed?: boolean,\n value?: unknown,\n isPressed?: (value?: unknown) => boolean,\n): boolean {\n if (!value) return Boolean(pressed);\n if (!isPressed) return Boolean(pressed);\n\n return isPressed(value);\n}\n\nexport const Toggle: TOC<Signature> = <template>\n {{#let (cell (isPressed @pressed @value @isPressed)) as |pressed|}}\n <button\n type=\"button\"\n aria-pressed=\"{{pressed.current}}\"\n {{on \"click\" (fn toggleWithFallback pressed.toggle @onChange @value)}}\n ...attributes\n >\n {{yield pressed.current}}\n </button>\n {{/let}}\n</template>;\n\nexport default Toggle;\n"],"names":["isPressed","pressed","value","Boolean","Toggle","setComponentTemplate","precompileTemplate","strictMode","scope","cell","on","fn","toggleWithFallback","templateOnly"],"mappings":";;;;;;;;AAAA;;AAwDA,SAASA,SAAAA,CACPC,OAAiB,EACjBC,KAAe,EACfF,SAAwC,EAChC;AACR,EAAA,IAAI,CAACE,KAAA,EAAO,OAAOC,OAAA,CAAQF,OAAA,CAAA;AAC3B,EAAA,IAAI,CAACD,SAAA,EAAW,OAAOG,OAAA,CAAQF,OAAA,CAAA;EAE/B,OAAOD,SAAA,CAAUE,KAAA,CAAA;AACnB;MAEaE,MAAY,GAAAC,oBAAA,CAAaC,kBAAA,CAAA,iSAAA,EAWtC;EAAAC,UAAA,EAAA,IAAA;AAAAC,EAAAA,KAAA,EAAAA,OAAA;IAAAC,IAAA;IAAAT,SAAA;IAAAU,EAAA;IAAAC,EAAA;AAAAC,IAAAA;AAAA,GAAA;AAAU,CAAA,CAAA,EAAAC,YAAA,EAAA;;;;"}
|
|
@@ -75,10 +75,10 @@ div[data-prim-switch]:not(:has(label)):has(input[role="switch"]) input[role="swi
|
|
|
75
75
|
border-color: black;
|
|
76
76
|
}
|
|
77
77
|
:is(
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
78
|
+
a[href="##missing##"],
|
|
79
|
+
span[data-prim-avatar]:has(img[alt="__missing__"]),
|
|
80
|
+
div[data-prim-switch]:not(:has(label)):has(input[role="switch"]) input[role="switch"]
|
|
81
|
+
):after {
|
|
82
82
|
background: white;
|
|
83
83
|
border: 1px solid black;
|
|
84
84
|
color: darkred;
|
|
@@ -94,10 +94,10 @@ div[data-prim-switch]:not(:has(label)):has(input[role="switch"]) input[role="swi
|
|
|
94
94
|
border-color: red;
|
|
95
95
|
}
|
|
96
96
|
:is(
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
97
|
+
a[href="##missing##"],
|
|
98
|
+
span[data-prim-avatar]:has(img[alt="__missing__"]),
|
|
99
|
+
div[data-prim-switch]:not(:has(label)):has(input[role="switch"]) input[role="switch"]
|
|
100
|
+
):after {
|
|
101
101
|
background: #222;
|
|
102
102
|
border: 1px solid red;
|
|
103
103
|
color: red;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"visually-hidden.js","sources":["../../src/components/visually-hidden.gts"],"sourcesContent":["import \"./visually-hidden.css\";\n\nimport type { TOC } from \"@ember/component/template-only\";\n\nexport const VisuallyHidden: TOC<{\n Element: HTMLSpanElement;\n Blocks: {\n /**\n * Content to hide visually\n */\n default: [];\n };\n}> = <template>\n <span class=\"ember-primitives__visually-hidden\" ...attributes>{{yield}}</span>\n</template>;\n"],"names":["VisuallyHidden","setComponentTemplate","precompileTemplate","strictMode","templateOnly"],"mappings":";;;;;MAIaA,cAQR,GAAAC,oBAAA,CAAAC,kBAAA,
|
|
1
|
+
{"version":3,"file":"visually-hidden.js","sources":["../../src/components/visually-hidden.gts"],"sourcesContent":["import \"./visually-hidden.css\";\n\nimport type { TOC } from \"@ember/component/template-only\";\n\nexport const VisuallyHidden: TOC<{\n Element: HTMLSpanElement;\n Blocks: {\n /**\n * Content to hide visually\n */\n default: [];\n };\n}> = <template>\n <span class=\"ember-primitives__visually-hidden\" ...attributes>{{yield}}</span>\n</template>;\n"],"names":["VisuallyHidden","setComponentTemplate","precompileTemplate","strictMode","templateOnly"],"mappings":";;;;;MAIaA,cAQR,GAAAC,oBAAA,CAAAC,kBAAA,CAAA,wFAAA,EAEL;EAAAC,UAAA,EAAA;AAAU,CAAA,CAAA,EAAAC,YAAA,EAAA;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../../src/components/zoetrope/index.gts"],"sourcesContent":["import \"./styles.css\";\n\nimport Component from \"@glimmer/component\";\nimport { tracked } from \"@glimmer/tracking\";\nimport { hash } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\nimport { buildWaiter, waitForPromise } from \"@ember/test-waiters\";\nimport { isTesting, macroCondition } from \"@embroider/macros\";\n\nimport { modifier } from \"ember-modifier\";\n\nimport type { ScrollBehavior, Signature } from \"./types.ts\";\n\nconst testWaiter = buildWaiter(\"ember-primitive:zoetrope-waiter\");\nconst DEFAULT_GAP = 8;\nconst DEFAULT_OFFSET = 0;\n\nexport class Zoetrope extends Component<Signature> {\n @tracked scrollerElement: HTMLElement | null = null;\n @tracked currentlyScrolled = 0;\n @tracked scrollWidth = 0;\n @tracked offsetWidth = 0;\n\n private setCSSVariables = modifier(\n (element: HTMLElement, _: unknown, { gap, offset }: { gap: number; offset: number }) => {\n if (gap) element.style.setProperty(\"--zoetrope-gap\", `${gap}px`);\n if (offset) element.style.setProperty(\"--zoetrope-offset\", `${offset}px`);\n },\n );\n\n scrollerWaiter = testWaiter.beginAsync();\n noScrollWaiter = () => {\n testWaiter.endAsync(this.scrollerWaiter);\n };\n\n private configureScroller = modifier((element: HTMLElement) => {\n this.scrollerElement = element;\n this.currentlyScrolled = element.scrollLeft;\n\n const zoetropeResizeObserver = new ResizeObserver(() => {\n this.scrollWidth = element.scrollWidth;\n this.offsetWidth = element.offsetWidth;\n });\n\n zoetropeResizeObserver.observe(element);\n\n element.addEventListener(\"scroll\", this.scrollListener, { passive: true });\n element.addEventListener(\"keydown\", this.tabListener);\n\n requestAnimationFrame(() => {\n testWaiter.endAsync(this.scrollerWaiter);\n });\n\n return () => {\n element.removeEventListener(\"scroll\", this.scrollListener);\n element.removeEventListener(\"keydown\", this.tabListener);\n\n zoetropeResizeObserver.unobserve(element);\n };\n });\n\n private tabListener = (event: KeyboardEvent) => {\n const target = event.target as HTMLElement;\n const { key, shiftKey } = event;\n\n if (!this.scrollerElement || this.scrollerElement === target) {\n return;\n }\n\n if (key !== \"Tab\") {\n return;\n }\n\n const nextElement = target.nextElementSibling;\n const previousElement = target.previousElementSibling;\n\n if ((!shiftKey && !nextElement) || (shiftKey && !previousElement)) {\n return;\n }\n\n event.preventDefault();\n\n let newTarget: HTMLElement | null = null;\n\n if (shiftKey) {\n newTarget = previousElement as HTMLElement;\n } else {\n newTarget = nextElement as HTMLElement;\n }\n\n if (!newTarget) {\n return;\n }\n\n newTarget?.focus({ preventScroll: true });\n\n const rect = getRelativeBoundingClientRect(newTarget, this.scrollerElement);\n\n this.scrollerElement?.scrollBy({\n left: rect.left,\n behavior: this.scrollBehavior,\n });\n };\n\n private scrollListener = () => {\n this.currentlyScrolled = this.scrollerElement?.scrollLeft || 0;\n };\n\n get offset() {\n return this.args.offset ?? DEFAULT_OFFSET;\n }\n\n get gap() {\n return this.args.gap ?? DEFAULT_GAP;\n }\n\n get canScroll() {\n return this.scrollWidth > this.offsetWidth + this.offset;\n }\n\n get cannotScrollLeft() {\n return this.currentlyScrolled <= this.offset;\n }\n\n get cannotScrollRight() {\n return this.scrollWidth - this.offsetWidth - this.offset < this.currentlyScrolled;\n }\n\n get scrollBehavior(): ScrollBehavior {\n if (macroCondition(isTesting())) {\n return \"instant\";\n }\n\n return this.args.scrollBehavior || \"smooth\";\n }\n\n scrollLeft = () => {\n if (!(this.scrollerElement instanceof HTMLElement)) {\n return;\n }\n\n const { firstChild } = this.findOverflowingElement();\n\n if (!firstChild) {\n return;\n }\n\n const children = [...this.scrollerElement.children];\n\n const firstChildIndex = children.indexOf(firstChild);\n\n let targetElement = firstChild;\n let accumalatedWidth = 0;\n\n for (let i = firstChildIndex; i >= 0; i--) {\n const child = children[i];\n\n if (!(child instanceof HTMLElement)) {\n continue;\n }\n\n accumalatedWidth += child.offsetWidth + this.gap;\n\n if (accumalatedWidth >= this.offsetWidth) {\n break;\n }\n\n targetElement = child;\n }\n\n const rect = getRelativeBoundingClientRect(targetElement, this.scrollerElement);\n\n this.scrollerElement.scrollBy({\n left: rect.left,\n behavior: this.scrollBehavior,\n });\n\n void waitForPromise(new Promise(requestAnimationFrame));\n };\n\n scrollRight = () => {\n if (!(this.scrollerElement instanceof HTMLElement)) {\n return;\n }\n\n const { activeSlide, lastChild } = this.findOverflowingElement();\n\n if (!lastChild) {\n return;\n }\n\n let rect = getRelativeBoundingClientRect(lastChild, this.scrollerElement);\n\n // If the card is larger than the container then skip to the next card\n if (rect.width > this.offsetWidth && activeSlide === lastChild) {\n const children = [...this.scrollerElement.children];\n const lastChildIndex = children.indexOf(lastChild);\n const targetElement = children[lastChildIndex + 1];\n\n if (!targetElement) {\n return;\n }\n\n rect = getRelativeBoundingClientRect(targetElement, this.scrollerElement);\n }\n\n this.scrollerElement?.scrollBy({\n left: rect.left,\n behavior: this.scrollBehavior,\n });\n\n void waitForPromise(new Promise(requestAnimationFrame));\n };\n\n private findOverflowingElement() {\n const returnObj: {\n activeSlide?: Element;\n firstChild?: Element;\n lastChild?: Element;\n } = {\n firstChild: undefined,\n lastChild: undefined,\n activeSlide: undefined,\n };\n\n if (!this.scrollerElement) {\n return returnObj;\n }\n\n const parentElement = this.scrollerElement.parentElement;\n\n if (!parentElement) {\n return returnObj;\n }\n\n const containerRect = getRelativeBoundingClientRect(this.scrollerElement, parentElement);\n\n const children = [...this.scrollerElement.children];\n\n // Find the first child that is overflowing the left edge of the container\n // and the last child that is overflowing the right edge of the container\n for (const child of children) {\n const rect = getRelativeBoundingClientRect(child, this.scrollerElement);\n\n if (rect.right + this.gap >= containerRect.left && !returnObj.firstChild) {\n returnObj.firstChild = child;\n }\n\n if (rect.left >= this.offset && !returnObj.activeSlide) {\n returnObj.activeSlide = child;\n }\n\n if (rect.right >= containerRect.width && !returnObj.lastChild) {\n returnObj.lastChild = child;\n\n break;\n }\n }\n\n if (!returnObj.firstChild) {\n returnObj.firstChild = children[0];\n }\n\n if (!returnObj.lastChild) {\n returnObj.lastChild = children[children.length - 1];\n }\n\n return returnObj;\n }\n\n <template>\n <section\n class=\"ember-primitives__zoetrope\"\n {{this.setCSSVariables gap=this.gap offset=this.offset}}\n ...attributes\n >\n {{#if (has-block \"header\")}}\n <div class=\"ember-primitives__zoetrope__header\">\n {{yield to=\"header\"}}\n </div>\n {{/if}}\n\n {{#if (has-block \"controls\")}}\n {{yield\n (hash\n cannotScrollLeft=this.cannotScrollLeft\n cannotScrollRight=this.cannotScrollRight\n canScroll=this.canScroll\n scrollLeft=this.scrollLeft\n scrollRight=this.scrollRight\n )\n to=\"controls\"\n }}\n {{else}}\n {{#if this.canScroll}}\n <div class=\"ember-primitives__zoetrope__controls\">\n <button\n type=\"button\"\n {{on \"click\" this.scrollLeft}}\n disabled={{this.cannotScrollLeft}}\n >Left</button>\n\n <button\n type=\"button\"\n {{on \"click\" this.scrollRight}}\n disabled={{this.cannotScrollRight}}\n >Right</button>\n </div>\n {{/if}}\n {{/if}}\n {{#if (has-block \"content\")}}\n <div class=\"ember-primitives__zoetrope__scroller\" {{this.configureScroller}}>\n {{yield to=\"content\"}}\n </div>\n {{else}}\n {{(this.noScrollWaiter)}}\n {{/if}}\n </section>\n </template>\n}\n\nexport default Zoetrope;\n\nfunction getRelativeBoundingClientRect(childElement: Element, parentElement: Element) {\n if (!childElement || !parentElement) {\n throw new Error(\"Both childElement and parentElement must be provided\");\n }\n\n // Get the bounding rect of the child and parent elements\n const childRect = childElement.getBoundingClientRect();\n const parentRect = parentElement.getBoundingClientRect();\n\n // Get computed styles of the parent element\n const parentStyles = window.getComputedStyle(parentElement);\n\n // Extract and parse parent's padding, and border, for all sides\n const parentPaddingTop = parseFloat(parentStyles.paddingTop);\n const parentPaddingLeft = parseFloat(parentStyles.paddingLeft);\n\n const parentBorderTopWidth = parseFloat(parentStyles.borderTopWidth);\n const parentBorderLeftWidth = parseFloat(parentStyles.borderLeftWidth);\n\n // Calculate child's position relative to parent's content area (including padding and borders)\n return {\n width: childRect.width,\n height: childRect.height,\n top: childRect.top - parentRect.top - parentBorderTopWidth - parentPaddingTop,\n left: childRect.left - parentRect.left - parentBorderLeftWidth - parentPaddingLeft,\n bottom:\n childRect.top - parentRect.top - parentBorderTopWidth - parentPaddingTop + childRect.height,\n right:\n childRect.left -\n parentRect.left -\n parentBorderLeftWidth -\n parentPaddingLeft +\n childRect.width,\n };\n}\n"],"names":["testWaiter","buildWaiter","DEFAULT_GAP","DEFAULT_OFFSET","Zoetrope","Component","g","prototype","tracked","i","void 0","setCSSVariables","modifier","element","_","gap","offset","style","setProperty","scrollerWaiter","beginAsync","noScrollWaiter","endAsync","configureScroller","scrollerElement","currentlyScrolled","scrollLeft","zoetropeResizeObserver","ResizeObserver","scrollWidth","offsetWidth","observe","addEventListener","scrollListener","passive","tabListener","requestAnimationFrame","removeEventListener","unobserve","event","target","key","shiftKey","nextElement","nextElementSibling","previousElement","previousElementSibling","preventDefault","newTarget","focus","preventScroll","rect","getRelativeBoundingClientRect","scrollBy","left","behavior","scrollBehavior","args","canScroll","cannotScrollLeft","cannotScrollRight","macroCondition","isTesting","HTMLElement","firstChild","findOverflowingElement","children","firstChildIndex","indexOf","targetElement","accumalatedWidth","child","waitForPromise","Promise","scrollRight","activeSlide","lastChild","width","lastChildIndex","returnObj","undefined","parentElement","containerRect","right","length","setComponentTemplate","precompileTemplate","strictMode","scope","hash","on","childElement","Error","childRect","getBoundingClientRect","parentRect","parentStyles","window","getComputedStyle","parentPaddingTop","parseFloat","paddingTop","parentPaddingLeft","paddingLeft","parentBorderTopWidth","borderTopWidth","parentBorderLeftWidth","borderLeftWidth","height","top","bottom"],"mappings":";;;;;;;;;;;;AAaA,MAAMA,aAAaC,WAAY,CAAA,iCAAA,CAAA;AAC/B,MAAMC,WAAc,GAAA,CAAA;AACpB,MAAMC,cAAiB,GAAA,CAAA;AAEhB,MAAMC,iBAAiBC,SAAU,CAAA;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,iBAAA,EAAA,CACrCC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA8C,IAAK;AAAA,KAAA,CAAA;AAAA;AAAA,EAAA,gBAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,iBAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAJ,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,mBAAA,EAAA,CACnDC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA4B,CAAE;AAAA,KAAA,CAAA;AAAA;AAAA,EAAA,kBAAA,IAAAC,CAAA,CAAA,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ACE,EAAAjB,SAAA,CAAUgB,GAAG,GAAGd,UAAA,CAAWc,GAAG,GAAGL,oBAAA,GAAuBL,gBAAmB,GAAAN,SAAA,CAAUe,MAAM;AAC7FzB,IAAAA,KACE,EAAAU,SAAA,CAAUvC,IAAI,GACdyC,UAAA,CAAWzC,IAAI,GACfoD,qBAAA,GACAJ,iBACA,GAAAT,SAAA,CAAUhB;GACd;AACF;;;;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../src/components/zoetrope/index.gts"],"sourcesContent":["import \"./styles.css\";\n\nimport Component from \"@glimmer/component\";\nimport { tracked } from \"@glimmer/tracking\";\nimport { hash } from \"@ember/helper\";\nimport { on } from \"@ember/modifier\";\nimport { buildWaiter, waitForPromise } from \"@ember/test-waiters\";\nimport { isTesting, macroCondition } from \"@embroider/macros\";\n\nimport { modifier } from \"ember-modifier\";\n\nimport type { ScrollBehavior, Signature } from \"./types.ts\";\n\nconst testWaiter = buildWaiter(\"ember-primitive:zoetrope-waiter\");\nconst DEFAULT_GAP = 8;\nconst DEFAULT_OFFSET = 0;\n\nexport class Zoetrope extends Component<Signature> {\n @tracked scrollerElement: HTMLElement | null = null;\n @tracked currentlyScrolled = 0;\n @tracked scrollWidth = 0;\n @tracked offsetWidth = 0;\n\n private setCSSVariables = modifier(\n (element: HTMLElement, _: unknown, { gap, offset }: { gap: number; offset: number }) => {\n if (gap) element.style.setProperty(\"--zoetrope-gap\", `${gap}px`);\n if (offset) element.style.setProperty(\"--zoetrope-offset\", `${offset}px`);\n },\n );\n\n scrollerWaiter = testWaiter.beginAsync();\n noScrollWaiter = () => {\n testWaiter.endAsync(this.scrollerWaiter);\n };\n\n private configureScroller = modifier((element: HTMLElement) => {\n this.scrollerElement = element;\n this.currentlyScrolled = element.scrollLeft;\n\n const zoetropeResizeObserver = new ResizeObserver(() => {\n this.scrollWidth = element.scrollWidth;\n this.offsetWidth = element.offsetWidth;\n });\n\n zoetropeResizeObserver.observe(element);\n\n element.addEventListener(\"scroll\", this.scrollListener, { passive: true });\n element.addEventListener(\"keydown\", this.tabListener);\n\n requestAnimationFrame(() => {\n testWaiter.endAsync(this.scrollerWaiter);\n });\n\n return () => {\n element.removeEventListener(\"scroll\", this.scrollListener);\n element.removeEventListener(\"keydown\", this.tabListener);\n\n zoetropeResizeObserver.unobserve(element);\n };\n });\n\n private tabListener = (event: KeyboardEvent) => {\n const target = event.target as HTMLElement;\n const { key, shiftKey } = event;\n\n if (!this.scrollerElement || this.scrollerElement === target) {\n return;\n }\n\n if (key !== \"Tab\") {\n return;\n }\n\n const nextElement = target.nextElementSibling;\n const previousElement = target.previousElementSibling;\n\n if ((!shiftKey && !nextElement) || (shiftKey && !previousElement)) {\n return;\n }\n\n event.preventDefault();\n\n let newTarget: HTMLElement | null = null;\n\n if (shiftKey) {\n newTarget = previousElement as HTMLElement;\n } else {\n newTarget = nextElement as HTMLElement;\n }\n\n if (!newTarget) {\n return;\n }\n\n newTarget?.focus({ preventScroll: true });\n\n const rect = getRelativeBoundingClientRect(newTarget, this.scrollerElement);\n\n this.scrollerElement?.scrollBy({\n left: rect.left,\n behavior: this.scrollBehavior,\n });\n };\n\n private scrollListener = () => {\n this.currentlyScrolled = this.scrollerElement?.scrollLeft || 0;\n };\n\n get offset() {\n return this.args.offset ?? DEFAULT_OFFSET;\n }\n\n get gap() {\n return this.args.gap ?? DEFAULT_GAP;\n }\n\n get canScroll() {\n return this.scrollWidth > this.offsetWidth + this.offset;\n }\n\n get cannotScrollLeft() {\n return this.currentlyScrolled <= this.offset;\n }\n\n get cannotScrollRight() {\n return this.scrollWidth - this.offsetWidth - this.offset < this.currentlyScrolled;\n }\n\n get scrollBehavior(): ScrollBehavior {\n if (macroCondition(isTesting())) {\n return \"instant\";\n }\n\n return this.args.scrollBehavior || \"smooth\";\n }\n\n scrollLeft = () => {\n if (!(this.scrollerElement instanceof HTMLElement)) {\n return;\n }\n\n const { firstChild } = this.findOverflowingElement();\n\n if (!firstChild) {\n return;\n }\n\n const children = [...this.scrollerElement.children];\n\n const firstChildIndex = children.indexOf(firstChild);\n\n let targetElement = firstChild;\n let accumalatedWidth = 0;\n\n for (let i = firstChildIndex; i >= 0; i--) {\n const child = children[i];\n\n if (!(child instanceof HTMLElement)) {\n continue;\n }\n\n accumalatedWidth += child.offsetWidth + this.gap;\n\n if (accumalatedWidth >= this.offsetWidth) {\n break;\n }\n\n targetElement = child;\n }\n\n const rect = getRelativeBoundingClientRect(targetElement, this.scrollerElement);\n\n this.scrollerElement.scrollBy({\n left: rect.left,\n behavior: this.scrollBehavior,\n });\n\n void waitForPromise(new Promise(requestAnimationFrame));\n };\n\n scrollRight = () => {\n if (!(this.scrollerElement instanceof HTMLElement)) {\n return;\n }\n\n const { activeSlide, lastChild } = this.findOverflowingElement();\n\n if (!lastChild) {\n return;\n }\n\n let rect = getRelativeBoundingClientRect(lastChild, this.scrollerElement);\n\n // If the card is larger than the container then skip to the next card\n if (rect.width > this.offsetWidth && activeSlide === lastChild) {\n const children = [...this.scrollerElement.children];\n const lastChildIndex = children.indexOf(lastChild);\n const targetElement = children[lastChildIndex + 1];\n\n if (!targetElement) {\n return;\n }\n\n rect = getRelativeBoundingClientRect(targetElement, this.scrollerElement);\n }\n\n this.scrollerElement?.scrollBy({\n left: rect.left,\n behavior: this.scrollBehavior,\n });\n\n void waitForPromise(new Promise(requestAnimationFrame));\n };\n\n private findOverflowingElement() {\n const returnObj: {\n activeSlide?: Element;\n firstChild?: Element;\n lastChild?: Element;\n } = {\n firstChild: undefined,\n lastChild: undefined,\n activeSlide: undefined,\n };\n\n if (!this.scrollerElement) {\n return returnObj;\n }\n\n const parentElement = this.scrollerElement.parentElement;\n\n if (!parentElement) {\n return returnObj;\n }\n\n const containerRect = getRelativeBoundingClientRect(this.scrollerElement, parentElement);\n\n const children = [...this.scrollerElement.children];\n\n // Find the first child that is overflowing the left edge of the container\n // and the last child that is overflowing the right edge of the container\n for (const child of children) {\n const rect = getRelativeBoundingClientRect(child, this.scrollerElement);\n\n if (rect.right + this.gap >= containerRect.left && !returnObj.firstChild) {\n returnObj.firstChild = child;\n }\n\n if (rect.left >= this.offset && !returnObj.activeSlide) {\n returnObj.activeSlide = child;\n }\n\n if (rect.right >= containerRect.width && !returnObj.lastChild) {\n returnObj.lastChild = child;\n\n break;\n }\n }\n\n if (!returnObj.firstChild) {\n returnObj.firstChild = children[0];\n }\n\n if (!returnObj.lastChild) {\n returnObj.lastChild = children[children.length - 1];\n }\n\n return returnObj;\n }\n\n <template>\n <section\n class=\"ember-primitives__zoetrope\"\n {{this.setCSSVariables gap=this.gap offset=this.offset}}\n ...attributes\n >\n {{#if (has-block \"header\")}}\n <div class=\"ember-primitives__zoetrope__header\">\n {{yield to=\"header\"}}\n </div>\n {{/if}}\n\n {{#if (has-block \"controls\")}}\n {{yield\n (hash\n cannotScrollLeft=this.cannotScrollLeft\n cannotScrollRight=this.cannotScrollRight\n canScroll=this.canScroll\n scrollLeft=this.scrollLeft\n scrollRight=this.scrollRight\n )\n to=\"controls\"\n }}\n {{else}}\n {{#if this.canScroll}}\n <div class=\"ember-primitives__zoetrope__controls\">\n <button\n type=\"button\"\n {{on \"click\" this.scrollLeft}}\n disabled={{this.cannotScrollLeft}}\n >Left</button>\n\n <button\n type=\"button\"\n {{on \"click\" this.scrollRight}}\n disabled={{this.cannotScrollRight}}\n >Right</button>\n </div>\n {{/if}}\n {{/if}}\n {{#if (has-block \"content\")}}\n <div class=\"ember-primitives__zoetrope__scroller\" {{this.configureScroller}}>\n {{yield to=\"content\"}}\n </div>\n {{else}}\n {{(this.noScrollWaiter)}}\n {{/if}}\n </section>\n </template>\n}\n\nexport default Zoetrope;\n\nfunction getRelativeBoundingClientRect(childElement: Element, parentElement: Element) {\n if (!childElement || !parentElement) {\n throw new Error(\"Both childElement and parentElement must be provided\");\n }\n\n // Get the bounding rect of the child and parent elements\n const childRect = childElement.getBoundingClientRect();\n const parentRect = parentElement.getBoundingClientRect();\n\n // Get computed styles of the parent element\n const parentStyles = window.getComputedStyle(parentElement);\n\n // Extract and parse parent's padding, and border, for all sides\n const parentPaddingTop = parseFloat(parentStyles.paddingTop);\n const parentPaddingLeft = parseFloat(parentStyles.paddingLeft);\n\n const parentBorderTopWidth = parseFloat(parentStyles.borderTopWidth);\n const parentBorderLeftWidth = parseFloat(parentStyles.borderLeftWidth);\n\n // Calculate child's position relative to parent's content area (including padding and borders)\n return {\n width: childRect.width,\n height: childRect.height,\n top: childRect.top - parentRect.top - parentBorderTopWidth - parentPaddingTop,\n left: childRect.left - parentRect.left - parentBorderLeftWidth - parentPaddingLeft,\n bottom:\n childRect.top - parentRect.top - parentBorderTopWidth - parentPaddingTop + childRect.height,\n right:\n childRect.left -\n parentRect.left -\n parentBorderLeftWidth -\n parentPaddingLeft +\n childRect.width,\n };\n}\n"],"names":["testWaiter","buildWaiter","DEFAULT_GAP","DEFAULT_OFFSET","Zoetrope","Component","g","prototype","tracked","i","void 0","setCSSVariables","modifier","element","_","gap","offset","style","setProperty","scrollerWaiter","beginAsync","noScrollWaiter","endAsync","configureScroller","scrollerElement","currentlyScrolled","scrollLeft","zoetropeResizeObserver","ResizeObserver","scrollWidth","offsetWidth","observe","addEventListener","scrollListener","passive","tabListener","requestAnimationFrame","removeEventListener","unobserve","event","target","key","shiftKey","nextElement","nextElementSibling","previousElement","previousElementSibling","preventDefault","newTarget","focus","preventScroll","rect","getRelativeBoundingClientRect","scrollBy","left","behavior","scrollBehavior","args","canScroll","cannotScrollLeft","cannotScrollRight","macroCondition","isTesting","HTMLElement","firstChild","findOverflowingElement","children","firstChildIndex","indexOf","targetElement","accumalatedWidth","child","waitForPromise","Promise","scrollRight","activeSlide","lastChild","width","lastChildIndex","returnObj","undefined","parentElement","containerRect","right","length","setComponentTemplate","precompileTemplate","strictMode","scope","hash","on","childElement","Error","childRect","getBoundingClientRect","parentRect","parentStyles","window","getComputedStyle","parentPaddingTop","parseFloat","paddingTop","parentPaddingLeft","paddingLeft","parentBorderTopWidth","borderTopWidth","parentBorderLeftWidth","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C;AACA,EAAA,MAAMkB,gBAAA,GAAmBC,UAAA,CAAWJ,YAAA,CAAaK,UAAU,CAAA;AAC3D,EAAA,MAAMC,iBAAA,GAAoBF,UAAA,CAAWJ,YAAA,CAAaO,WAAW,CAAA;AAE7D,EAAA,MAAMC,oBAAA,GAAuBJ,UAAA,CAAWJ,YAAA,CAAaS,cAAc,CAAA;AACnE,EAAA,MAAMC,qBAAA,GAAwBN,UAAA,CAAWJ,YAAA,CAAaW,eAAe,CAAA;AAErE;EACA,OAAO;IACL9B,KAAA,EAAOgB,UAAUhB,KAAK;IACtB+B,MAAA,EAAQf,UAAUe,MAAM;IACxBC,GAAA,EAAKhB,UAAUgB,GAAG,GAAGd,UAAA,CAAWc,GAAG,GAAGL,oBAAA,GAAuBL,gBAAA;IAC7D7C,IAAA,EAAMuC,UAAUvC,IAAI,GAAGyC,UAAA,CAAWzC,IAAI,GAAGoD,qBAAA,GAAwBJ,iBAAA;AACjEQ,IAAAA,MAAA,EACEjB,SAAA,CAAUgB,GAAG,GAAGd,UAAA,CAAWc,GAAG,GAAGL,oBAAA,GAAuBL,gBAAA,GAAmBN,SAAA,CAAUe,MAAM;AAC7FzB,IAAAA,KAAA,EACEU,SAAA,CAAUvC,IAAI,GACdyC,UAAA,CAAWzC,IAAI,GACfoD,qBAAA,GACAJ,iBAAA,GACAT,SAAA,CAAUhB;GACd;AACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"component.js","sources":["../../src/floating-ui/component.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\nimport { tracked } from \"@glimmer/tracking\";\nimport { hash } from \"@ember/helper\";\n\nimport { modifier as eModifier } from \"ember-modifier\";\n\nimport { anchorTo } from \"./modifier.ts\";\n\nimport type { Signature as ModifierSignature } from \"./modifier.ts\";\nimport type { MiddlewareState } from \"@floating-ui/dom\";\nimport type { ModifierLike } from \"@glint/template\";\n\ntype ModifierArgs = ModifierSignature[\"Args\"][\"Named\"];\n\ninterface ReferenceSignature {\n Element: HTMLElement | SVGElement;\n}\n\nexport interface Signature {\n Args: {\n /**\n * Additional middleware to pass to FloatingUI.\n *\n * See: [The middleware docs](https://floating-ui.com/docs/middleware)\n */\n middleware?: ModifierArgs[\"middleware\"];\n /**\n * Where to place the floating element relative to its reference element.\n * The default is 'bottom'.\n *\n * See: [The placement docs](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: ModifierArgs[\"placement\"];\n /**\n * This is the type of CSS position property to use.\n * By default this is 'fixed', but can also be 'absolute'.\n *\n * See: [The strategy docs](https://floating-ui.com/docs/computePosition#strategy)\n */\n strategy?: ModifierArgs[\"strategy\"];\n /**\n * Options to pass to the [flip middleware](https://floating-ui.com/docs/flip)\n */\n flipOptions?: ModifierArgs[\"flipOptions\"];\n /**\n * Options to pass to the [hide middleware](https://floating-ui.com/docs/hide)\n */\n hideOptions?: ModifierArgs[\"hideOptions\"];\n /**\n * Options to pass to the [shift middleware](https://floating-ui.com/docs/shift)\n */\n shiftOptions?: ModifierArgs[\"shiftOptions\"];\n /**\n * Options to pass to the [offset middleware](https://floating-ui.com/docs/offset)\n */\n offsetOptions?: ModifierArgs[\"offsetOptions\"];\n };\n Blocks: {\n default: [\n /**\n * A modifier to apply to the _reference_ element.\n * This is what the floating element will use to anchor to.\n *\n * Example\n * ```gjs\n * import { FloatingUI } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <FloatingUI as |reference floating|>\n * <button {{reference}}> ... </button>\n * ...\n * </FloatingUI>\n * </template>\n * ```\n */\n reference: ModifierLike<ReferenceSignature>,\n /**\n * A modifier to apply to the _floating_ element.\n * This is what will anchor to the reference element.\n *\n * Example\n * ```gjs\n * import { FloatingUI } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <FloatingUI as |reference floating|>\n * <button {{reference}}> ... </button>\n * <menu {{floating}}> ... </menu>\n * </FloatingUI>\n * </template>\n * ```\n */\n floating:\n | undefined\n | ModifierLike<{\n Element: HTMLElement;\n Args: {\n Named: ModifierArgs;\n };\n }>,\n /**\n * Special utilities for advanced usage\n */\n util: {\n /**\n * If you want to have a single modifier with custom behavior\n * on your reference element, you may use this `setReference`\n * function to set the reference, rather than having multiple modifiers\n * on that element.\n */\n setReference: (element: HTMLElement | SVGElement) => void;\n /**\n * Metadata exposed from floating-ui.\n * Gives you x, y position, among other things.\n */\n data?: MiddlewareState;\n },\n ];\n };\n}\n\nconst ref = eModifier<{\n Element: HTMLElement | SVGElement;\n Args: {\n Positional: [setRef: (element: HTMLElement | SVGElement) => void];\n };\n}>((element: HTMLElement | SVGElement, positional) => {\n const fn = positional[0];\n\n fn(element);\n});\n\n/**\n * A component that provides no DOM and yields two modifiers for creating\n * creating floating uis, such as menus, popovers, tooltips, etc.\n * This component currently uses [Floating UI](https://floating-ui.com/)\n * but will be switching to [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning) when that lands.\n *\n * Example usage:\n * ```gjs\n * import { FloatingUI } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <FloatingUI as |reference floating|>\n * <button {{reference}}> ... </button>\n * <menu {{floating}}> ... </menu>\n * </FloatingUI>\n * </template>\n * ```\n */\nexport class FloatingUI extends Component<Signature> {\n @tracked reference?: HTMLElement | SVGElement = undefined;\n @tracked data?: MiddlewareState = undefined;\n\n setData: ModifierArgs[\"setData\"] = (data) => (this.data = data);\n\n setReference = (element: HTMLElement | SVGElement) => {\n this.reference = element;\n };\n\n <template>\n {{#let\n (modifier\n anchorTo\n flipOptions=@flipOptions\n hideOptions=@hideOptions\n middleware=@middleware\n offsetOptions=@offsetOptions\n placement=@placement\n shiftOptions=@shiftOptions\n strategy=@strategy\n setData=this.setData\n )\n as |prewiredAnchorTo|\n }}\n {{#let (if this.reference (modifier prewiredAnchorTo this.reference)) as |floating|}}\n {{! @glint-nocheck -- Excessively deep, possibly infinite }}\n {{yield\n (modifier ref this.setReference)\n floating\n (hash setReference=this.setReference data=this.data)\n }}\n {{/let}}\n {{/let}}\n </template>\n}\n"],"names":["ref","eModifier","element","positional","fn","FloatingUI","Component","g","prototype","tracked","undefined","i","void 0","setData","data","setReference","reference","setComponentTemplate","precompileTemplate","strictMode","scope","anchorTo","hash"],"mappings":";;;;;;;;;AAyHA,MAAMA,
|
|
1
|
+
{"version":3,"file":"component.js","sources":["../../src/floating-ui/component.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\nimport { tracked } from \"@glimmer/tracking\";\nimport { hash } from \"@ember/helper\";\n\nimport { modifier as eModifier } from \"ember-modifier\";\n\nimport { anchorTo } from \"./modifier.ts\";\n\nimport type { Signature as ModifierSignature } from \"./modifier.ts\";\nimport type { MiddlewareState } from \"@floating-ui/dom\";\nimport type { ModifierLike } from \"@glint/template\";\n\ntype ModifierArgs = ModifierSignature[\"Args\"][\"Named\"];\n\ninterface ReferenceSignature {\n Element: HTMLElement | SVGElement;\n}\n\nexport interface Signature {\n Args: {\n /**\n * Additional middleware to pass to FloatingUI.\n *\n * See: [The middleware docs](https://floating-ui.com/docs/middleware)\n */\n middleware?: ModifierArgs[\"middleware\"];\n /**\n * Where to place the floating element relative to its reference element.\n * The default is 'bottom'.\n *\n * See: [The placement docs](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: ModifierArgs[\"placement\"];\n /**\n * This is the type of CSS position property to use.\n * By default this is 'fixed', but can also be 'absolute'.\n *\n * See: [The strategy docs](https://floating-ui.com/docs/computePosition#strategy)\n */\n strategy?: ModifierArgs[\"strategy\"];\n /**\n * Options to pass to the [flip middleware](https://floating-ui.com/docs/flip)\n */\n flipOptions?: ModifierArgs[\"flipOptions\"];\n /**\n * Options to pass to the [hide middleware](https://floating-ui.com/docs/hide)\n */\n hideOptions?: ModifierArgs[\"hideOptions\"];\n /**\n * Options to pass to the [shift middleware](https://floating-ui.com/docs/shift)\n */\n shiftOptions?: ModifierArgs[\"shiftOptions\"];\n /**\n * Options to pass to the [offset middleware](https://floating-ui.com/docs/offset)\n */\n offsetOptions?: ModifierArgs[\"offsetOptions\"];\n };\n Blocks: {\n default: [\n /**\n * A modifier to apply to the _reference_ element.\n * This is what the floating element will use to anchor to.\n *\n * Example\n * ```gjs\n * import { FloatingUI } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <FloatingUI as |reference floating|>\n * <button {{reference}}> ... </button>\n * ...\n * </FloatingUI>\n * </template>\n * ```\n */\n reference: ModifierLike<ReferenceSignature>,\n /**\n * A modifier to apply to the _floating_ element.\n * This is what will anchor to the reference element.\n *\n * Example\n * ```gjs\n * import { FloatingUI } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <FloatingUI as |reference floating|>\n * <button {{reference}}> ... </button>\n * <menu {{floating}}> ... </menu>\n * </FloatingUI>\n * </template>\n * ```\n */\n floating:\n | undefined\n | ModifierLike<{\n Element: HTMLElement;\n Args: {\n Named: ModifierArgs;\n };\n }>,\n /**\n * Special utilities for advanced usage\n */\n util: {\n /**\n * If you want to have a single modifier with custom behavior\n * on your reference element, you may use this `setReference`\n * function to set the reference, rather than having multiple modifiers\n * on that element.\n */\n setReference: (element: HTMLElement | SVGElement) => void;\n /**\n * Metadata exposed from floating-ui.\n * Gives you x, y position, among other things.\n */\n data?: MiddlewareState;\n },\n ];\n };\n}\n\nconst ref = eModifier<{\n Element: HTMLElement | SVGElement;\n Args: {\n Positional: [setRef: (element: HTMLElement | SVGElement) => void];\n };\n}>((element: HTMLElement | SVGElement, positional) => {\n const fn = positional[0];\n\n fn(element);\n});\n\n/**\n * A component that provides no DOM and yields two modifiers for creating\n * creating floating uis, such as menus, popovers, tooltips, etc.\n * This component currently uses [Floating UI](https://floating-ui.com/)\n * but will be switching to [CSS Anchor Positioning](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_anchor_positioning) when that lands.\n *\n * Example usage:\n * ```gjs\n * import { FloatingUI } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <FloatingUI as |reference floating|>\n * <button {{reference}}> ... </button>\n * <menu {{floating}}> ... </menu>\n * </FloatingUI>\n * </template>\n * ```\n */\nexport class FloatingUI extends Component<Signature> {\n @tracked reference?: HTMLElement | SVGElement = undefined;\n @tracked data?: MiddlewareState = undefined;\n\n setData: ModifierArgs[\"setData\"] = (data) => (this.data = data);\n\n setReference = (element: HTMLElement | SVGElement) => {\n this.reference = element;\n };\n\n <template>\n {{#let\n (modifier\n anchorTo\n flipOptions=@flipOptions\n hideOptions=@hideOptions\n middleware=@middleware\n offsetOptions=@offsetOptions\n placement=@placement\n shiftOptions=@shiftOptions\n strategy=@strategy\n setData=this.setData\n )\n as |prewiredAnchorTo|\n }}\n {{#let (if this.reference (modifier prewiredAnchorTo this.reference)) as |floating|}}\n {{! @glint-nocheck -- Excessively deep, possibly infinite }}\n {{yield\n (modifier ref this.setReference)\n floating\n (hash setReference=this.setReference data=this.data)\n }}\n {{/let}}\n {{/let}}\n </template>\n}\n"],"names":["ref","eModifier","element","positional","fn","FloatingUI","Component","g","prototype","tracked","undefined","i","void 0","setData","data","setReference","reference","setComponentTemplate","precompileTemplate","strictMode","scope","anchorTo","hash"],"mappings":";;;;;;;;;AAyHA,MAAMA,GAAA,GAAMC,QAAA,CAKT,CAACC,OAAuB,EAAYC,UAAA,KAAA;AACrC,EAAA,MAAMC,EAAA,GAAKD,UAAU,CAAC,CAAA,CAAE;EAExBC,EAAA,CAAGF,OAAA,CAAA;AACL,CAAA,CAAA;AAEA;;;;;;;;;;;;;;;;;;AAkBO,MAAMG,UAAA,SAAmBC,SAAA,CAAU;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,WAAA,EAAA,CACvCC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAA+CC,SAAA;AAAA,KAAA,CAAA;AAAA;AAAA,EAAA,UAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,WAAA,CAAA,EAAAC,MAAA;AAAA,EAAA;IAAAL,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,MAAA,EAAA,CAC/CC,OAAA,CAAA,EAAA,YAAA;AAAA,MAAA,OAAiCC,SAAA;AAAA,KAAA,CAAA;AAAA;AAAA,EAAA,KAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,MAAA,CAAA,EAAAC,MAAA;AAElCC,EAAAA,OAAA,GAAoCC,IAAA,IAAU,IAAI,CAACA,IAAI,GAAGA,IAAI;EAE9DC,YAAA,GAAgBb,OAAuB,IAAA;IACrC,IAAI,CAACc,SAAS,GAAGd,OAAA;GACnB;AAEA,EAAA;IAAAe,oBAAA,CAAAC,kBAAA,CAAA,mjBAAA,EAwBA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;QAAAC,QAAA;QAAArB,GAAA;AAAAsB,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;AACZ;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"modifier.js","sources":["../../src/floating-ui/modifier.ts"],"sourcesContent":["import { assert } from '@ember/debug';\n\nimport { autoUpdate, computePosition, flip, hide, offset, shift } from '@floating-ui/dom';\nimport { modifier as eModifier } from 'ember-modifier';\n\nimport { exposeMetadata } from './middleware.ts';\n\nimport type {\n FlipOptions,\n HideOptions,\n Middleware,\n OffsetOptions,\n Placement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom';\n\nexport interface Signature {\n /**\n *\n */\n Element: HTMLElement;\n Args: {\n Positional: [\n /**\n * What do use as the reference element.\n * Can be a selector or element instance.\n *\n * Example:\n * ```gjs\n * import { anchorTo } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <div id=\"reference\">...</div>\n * <div {{anchorTo \"#reference\"}}> ... </div>\n * </template>\n * ```\n */\n referenceElement: string | HTMLElement | SVGElement,\n ];\n Named: {\n /**\n * This is the type of CSS position property to use.\n * By default this is 'fixed', but can also be 'absolute'.\n *\n * See: [The strategy docs](https://floating-ui.com/docs/computePosition#strategy)\n */\n strategy?: Strategy;\n /**\n * Options to pass to the [offset middleware](https://floating-ui.com/docs/offset)\n */\n offsetOptions?: OffsetOptions;\n /**\n * Where to place the floating element relative to its reference element.\n * The default is 'bottom'.\n *\n * See: [The placement docs](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n /**\n * Options to pass to the [flip middleware](https://floating-ui.com/docs/flip)\n */\n flipOptions?: FlipOptions;\n /**\n * Options to pass to the [shift middleware](https://floating-ui.com/docs/shift)\n */\n shiftOptions?: ShiftOptions;\n /**\n * Options to pass to the [hide middleware](https://floating-ui.com/docs/hide)\n */\n hideOptions?: HideOptions;\n /**\n * Additional middleware to pass to FloatingUI.\n *\n * See: [The middleware docs](https://floating-ui.com/docs/middleware)\n */\n middleware?: Middleware[];\n /**\n * A callback for when data changes about the position / placement / etc\n * of the floating element.\n */\n setData?: Middleware['fn'];\n };\n };\n}\n\n/**\n * A modifier to apply to the _floating_ element.\n * This is what will anchor to the reference element.\n *\n * Example\n * ```gjs\n * import { anchorTo } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <button id=\"my-button\"> ... </button>\n * <menu {{anchorTo \"#my-button\"}}> ... </menu>\n * </template>\n * ```\n */\nexport const anchorTo = eModifier<Signature>(\n (\n floatingElement,\n [_referenceElement],\n {\n strategy = 'fixed',\n offsetOptions = 0,\n placement = 'bottom',\n flipOptions,\n shiftOptions,\n middleware = [],\n setData,\n }\n ) => {\n const referenceElement: null | HTMLElement | SVGElement =\n typeof _referenceElement === 'string'\n ? document.querySelector(_referenceElement)\n : _referenceElement;\n\n assert(\n 'no reference element defined',\n referenceElement instanceof HTMLElement || referenceElement instanceof SVGElement\n );\n\n assert(\n 'no floating element defined',\n floatingElement instanceof HTMLElement || _referenceElement instanceof SVGElement\n );\n\n assert(\n 'reference and floating elements cannot be the same element',\n floatingElement !== _referenceElement\n );\n\n assert('@middleware must be an array of one or more objects', Array.isArray(middleware));\n\n Object.assign(floatingElement.style, {\n position: strategy,\n top: '0',\n left: '0',\n });\n\n const update = async () => {\n const { middlewareData, x, y } = await computePosition(referenceElement, floatingElement, {\n middleware: [\n offset(offsetOptions),\n flip(flipOptions),\n shift(shiftOptions),\n ...middleware,\n hide({ strategy: 'referenceHidden' }),\n hide({ strategy: 'escaped' }),\n exposeMetadata(),\n ],\n placement,\n strategy,\n });\n\n const referenceHidden = middlewareData.hide?.referenceHidden;\n\n Object.assign(floatingElement.style, {\n top: `${y}px`,\n left: `${x}px`,\n margin: 0,\n visibility: referenceHidden ? 'hidden' : 'visible',\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n void setData?.(middlewareData['metadata']);\n };\n\n void update();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n const cleanup = autoUpdate(referenceElement, floatingElement, update);\n\n /**\n * in the function-modifier manager, teardown of the previous modifier\n * occurs before setup of the next\n * https://github.com/ember-modifier/ember-modifier/blob/main/ember-modifier/src/-private/function-based/modifier-manager.ts#L58\n */\n return cleanup;\n }\n);\n"],"names":["anchorTo","eModifier","floatingElement","_referenceElement","strategy","offsetOptions","placement","flipOptions","shiftOptions","middleware","setData","referenceElement","document","querySelector","assert","HTMLElement","SVGElement","Array","isArray","Object","assign","style","position","top","left","update","middlewareData","x","y","computePosition","offset","flip","shift","hide","exposeMetadata","referenceHidden","margin","visibility","cleanup","autoUpdate"],"mappings":";;;;;AAsFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAGC,QAAS,CAC/B,CACEC,eAAe,EACf,CAACC,iBAAiB,CAAC,EACnB;AACEC,EAAAA,QAAQ,GAAG,OAAO;AAClBC,EAAAA,aAAa,GAAG,CAAC;AACjBC,EAAAA,SAAS,GAAG,QAAQ;EACpBC,WAAW;EACXC,YAAY;AACZC,EAAAA,UAAU,GAAG,EAAE;AACfC,EAAAA;AACF,CAAC,KACE;AACH,EAAA,MAAMC,gBAAiD,GACrD,OAAOR,iBAAiB,KAAK,QAAQ,GACjCS,QAAQ,CAACC,aAAa,CAACV,iBAAiB,CAAC,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sourcesContent":["import { assert } from '@ember/debug';\n\nimport { autoUpdate, computePosition, flip, hide, offset, shift } from '@floating-ui/dom';\nimport { modifier as eModifier } from 'ember-modifier';\n\nimport { exposeMetadata } from './middleware.ts';\n\nimport type {\n FlipOptions,\n HideOptions,\n Middleware,\n OffsetOptions,\n Placement,\n ShiftOptions,\n Strategy,\n} from '@floating-ui/dom';\n\nexport interface Signature {\n /**\n *\n */\n Element: HTMLElement;\n Args: {\n Positional: [\n /**\n * What do use as the reference element.\n * Can be a selector or element instance.\n *\n * Example:\n * ```gjs\n * import { anchorTo } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <div id=\"reference\">...</div>\n * <div {{anchorTo \"#reference\"}}> ... </div>\n * </template>\n * ```\n */\n referenceElement: string | HTMLElement | SVGElement,\n ];\n Named: {\n /**\n * This is the type of CSS position property to use.\n * By default this is 'fixed', but can also be 'absolute'.\n *\n * See: [The strategy docs](https://floating-ui.com/docs/computePosition#strategy)\n */\n strategy?: Strategy;\n /**\n * Options to pass to the [offset middleware](https://floating-ui.com/docs/offset)\n */\n offsetOptions?: OffsetOptions;\n /**\n * Where to place the floating element relative to its reference element.\n * The default is 'bottom'.\n *\n * See: [The placement docs](https://floating-ui.com/docs/computePosition#placement)\n */\n placement?: Placement;\n /**\n * Options to pass to the [flip middleware](https://floating-ui.com/docs/flip)\n */\n flipOptions?: FlipOptions;\n /**\n * Options to pass to the [shift middleware](https://floating-ui.com/docs/shift)\n */\n shiftOptions?: ShiftOptions;\n /**\n * Options to pass to the [hide middleware](https://floating-ui.com/docs/hide)\n */\n hideOptions?: HideOptions;\n /**\n * Additional middleware to pass to FloatingUI.\n *\n * See: [The middleware docs](https://floating-ui.com/docs/middleware)\n */\n middleware?: Middleware[];\n /**\n * A callback for when data changes about the position / placement / etc\n * of the floating element.\n */\n setData?: Middleware['fn'];\n };\n };\n}\n\n/**\n * A modifier to apply to the _floating_ element.\n * This is what will anchor to the reference element.\n *\n * Example\n * ```gjs\n * import { anchorTo } from 'ember-primitives/floating-ui';\n *\n * <template>\n * <button id=\"my-button\"> ... </button>\n * <menu {{anchorTo \"#my-button\"}}> ... </menu>\n * </template>\n * ```\n */\nexport const anchorTo = eModifier<Signature>(\n (\n floatingElement,\n [_referenceElement],\n {\n strategy = 'fixed',\n offsetOptions = 0,\n placement = 'bottom',\n flipOptions,\n shiftOptions,\n middleware = [],\n setData,\n }\n ) => {\n const referenceElement: null | HTMLElement | SVGElement =\n typeof _referenceElement === 'string'\n ? document.querySelector(_referenceElement)\n : _referenceElement;\n\n assert(\n 'no reference element defined',\n referenceElement instanceof HTMLElement || referenceElement instanceof SVGElement\n );\n\n assert(\n 'no floating element defined',\n floatingElement instanceof HTMLElement || _referenceElement instanceof SVGElement\n );\n\n assert(\n 'reference and floating elements cannot be the same element',\n floatingElement !== _referenceElement\n );\n\n assert('@middleware must be an array of one or more objects', Array.isArray(middleware));\n\n Object.assign(floatingElement.style, {\n position: strategy,\n top: '0',\n left: '0',\n });\n\n const update = async () => {\n const { middlewareData, x, y } = await computePosition(referenceElement, floatingElement, {\n middleware: [\n offset(offsetOptions),\n flip(flipOptions),\n shift(shiftOptions),\n ...middleware,\n hide({ strategy: 'referenceHidden' }),\n hide({ strategy: 'escaped' }),\n exposeMetadata(),\n ],\n placement,\n strategy,\n });\n\n const referenceHidden = middlewareData.hide?.referenceHidden;\n\n Object.assign(floatingElement.style, {\n top: `${y}px`,\n left: `${x}px`,\n margin: 0,\n visibility: referenceHidden ? 'hidden' : 'visible',\n });\n\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n void setData?.(middlewareData['metadata']);\n };\n\n void update();\n\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n const cleanup = autoUpdate(referenceElement, floatingElement, update);\n\n /**\n * in the function-modifier manager, teardown of the previous modifier\n * occurs before setup of the next\n * https://github.com/ember-modifier/ember-modifier/blob/main/ember-modifier/src/-private/function-based/modifier-manager.ts#L58\n */\n return cleanup;\n }\n);\n"],"names":["anchorTo","eModifier","floatingElement","_referenceElement","strategy","offsetOptions","placement","flipOptions","shiftOptions","middleware","setData","referenceElement","document","querySelector","assert","HTMLElement","SVGElement","Array","isArray","Object","assign","style","position","top","left","update","middlewareData","x","y","computePosition","offset","flip","shift","hide","exposeMetadata","referenceHidden","margin","visibility","cleanup","autoUpdate"],"mappings":";;;;;AAsFA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAGC,QAAS,CAC/B,CACEC,eAAe,EACf,CAACC,iBAAiB,CAAC,EACnB;AACEC,EAAAA,QAAQ,GAAG,OAAO;AAClBC,EAAAA,aAAa,GAAG,CAAC;AACjBC,EAAAA,SAAS,GAAG,QAAQ;EACpBC,WAAW;EACXC,YAAY;AACZC,EAAAA,UAAU,GAAG,EAAE;AACfC,EAAAA;AACF,CAAC,KACE;AACH,EAAA,MAAMC,gBAAiD,GACrD,OAAOR,iBAAiB,KAAK,QAAQ,GACjCS,QAAQ,CAACC,aAAa,CAACV,iBAAiB,CAAC,GACzCA,iBAAiB;EAEvBW,MAAM,CACJ,8BAA8B,EAC9BH,gBAAgB,YAAYI,WAAW,IAAIJ,gBAAgB,YAAYK,UACzE,CAAC;EAEDF,MAAM,CACJ,6BAA6B,EAC7BZ,eAAe,YAAYa,WAAW,IAAIZ,iBAAiB,YAAYa,UACzE,CAAC;AAEDF,EAAAA,MAAM,CACJ,4DAA4D,EAC5DZ,eAAe,KAAKC,iBACtB,CAAC;EAEDW,MAAM,CAAC,qDAAqD,EAAEG,KAAK,CAACC,OAAO,CAACT,UAAU,CAAC,CAAC;AAExFU,EAAAA,MAAM,CAACC,MAAM,CAAClB,eAAe,CAACmB,KAAK,EAAE;AACnCC,IAAAA,QAAQ,EAAElB,QAAQ;AAClBmB,IAAAA,GAAG,EAAE,GAAG;AACRC,IAAAA,IAAI,EAAE;AACR,GAAC,CAAC;AAEF,EAAA,MAAMC,MAAM,GAAG,YAAY;IACzB,MAAM;MAAEC,cAAc;MAAEC,CAAC;AAAEC,MAAAA;AAAE,KAAC,GAAG,MAAMC,eAAe,CAAClB,gBAAgB,EAAET,eAAe,EAAE;MACxFO,UAAU,EAAE,CACVqB,MAAM,CAACzB,aAAa,CAAC,EACrB0B,IAAI,CAACxB,WAAW,CAAC,EACjByB,KAAK,CAACxB,YAAY,CAAC,EACnB,GAAGC,UAAU,EACbwB,IAAI,CAAC;AAAE7B,QAAAA,QAAQ,EAAE;OAAmB,CAAC,EACrC6B,IAAI,CAAC;AAAE7B,QAAAA,QAAQ,EAAE;AAAU,OAAC,CAAC,EAC7B8B,cAAc,EAAE,CACjB;MACD5B,SAAS;AACTF,MAAAA;AACF,KAAC,CAAC;AAEF,IAAA,MAAM+B,eAAe,GAAGT,cAAc,CAACO,IAAI,EAAEE,eAAe;AAE5DhB,IAAAA,MAAM,CAACC,MAAM,CAAClB,eAAe,CAACmB,KAAK,EAAE;MACnCE,GAAG,EAAE,CAAA,EAAGK,CAAC,CAAA,EAAA,CAAI;MACbJ,IAAI,EAAE,CAAA,EAAGG,CAAC,CAAA,EAAA,CAAI;AACdS,MAAAA,MAAM,EAAE,CAAC;AACTC,MAAAA,UAAU,EAAEF,eAAe,GAAG,QAAQ,GAAG;AAC3C,KAAC,CAAC;;AAEF;AACA,IAAA,KAAKzB,OAAO,GAAGgB,cAAc,CAAC,UAAU,CAAC,CAAC;GAC3C;EAED,KAAKD,MAAM,EAAE;;AAEb;EACA,MAAMa,OAAO,GAAGC,UAAU,CAAC5B,gBAAgB,EAAET,eAAe,EAAEuB,MAAM,CAAC;;AAErE;AACJ;AACA;AACA;AACA;AACI,EAAA,OAAOa,OAAO;AAChB,CACF;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"item-D6pwWzMs.js","sources":["../src/components/accordion/content.gts","../src/components/accordion/trigger.gts","../src/components/accordion/header.gts","../src/components/accordion/item.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\n\nimport { getDataState } from \"./item.gts\";\n\nimport type { AccordionContentExternalSignature } from \"./public.ts\";\n\ninterface Signature extends AccordionContentExternalSignature {\n Args: {\n isExpanded: boolean;\n value: string;\n disabled?: boolean;\n };\n}\n\nexport class AccordionContent extends Component<Signature> {\n <template>\n <div\n role=\"region\"\n id={{@value}}\n data-state={{getDataState @isExpanded}}\n hidden={{this.isHidden}}\n data-disabled={{@disabled}}\n ...attributes\n >\n {{yield}}\n </div>\n </template>\n\n get isHidden() {\n return !this.args.isExpanded;\n }\n}\n\nexport default AccordionContent;\n","import { on } from \"@ember/modifier\";\n\nimport { getDataState } from \"./item.gts\";\n\nimport type { AccordionTriggerExternalSignature } from \"./public.ts\";\nimport type { TOC } from \"@ember/component/template-only\";\n\ninterface Signature extends AccordionTriggerExternalSignature {\n Args: {\n isExpanded: boolean;\n value: string;\n disabled?: boolean;\n toggleItem: () => void;\n };\n}\n\nexport const AccordionTrigger: TOC<Signature> = <template>\n <button\n type=\"button\"\n aria-controls={{@value}}\n aria-expanded={{@isExpanded}}\n data-state={{getDataState @isExpanded}}\n data-disabled={{@disabled}}\n aria-disabled={{if @disabled \"true\" \"false\"}}\n {{on \"click\" @toggleItem}}\n ...attributes\n >\n {{yield}}\n </button>\n</template>;\n\nexport default AccordionTrigger;\n","import { hash } from \"@ember/helper\";\n\nimport { getDataState } from \"./item.gts\";\nimport Trigger from \"./trigger.gts\";\n\nimport type { AccordionHeaderExternalSignature } from \"./public.ts\";\nimport type { TOC } from \"@ember/component/template-only\";\n\ninterface Signature extends AccordionHeaderExternalSignature {\n Args: {\n value: string;\n isExpanded: boolean;\n disabled?: boolean;\n toggleItem: () => void;\n };\n}\n\nexport const AccordionHeader: TOC<Signature> = <template>\n <div\n role=\"heading\"\n aria-level=\"3\"\n data-state={{getDataState @isExpanded}}\n data-disabled={{@disabled}}\n ...attributes\n >\n {{yield\n (hash\n Trigger=(component\n Trigger value=@value isExpanded=@isExpanded disabled=@disabled toggleItem=@toggleItem\n )\n )\n }}\n </div>\n</template>;\n\nexport default AccordionHeader;\n","import Component from \"@glimmer/component\";\nimport { hash } from \"@ember/helper\";\n\nimport Content from \"./content.gts\";\nimport Header from \"./header.gts\";\n\nimport type { AccordionItemExternalSignature } from \"./public.ts\";\n\nexport function getDataState(isExpanded: boolean): string {\n return isExpanded ? \"open\" : \"closed\";\n}\n\ninterface Signature extends AccordionItemExternalSignature {\n Args: AccordionItemExternalSignature[\"Args\"] & {\n selectedValue?: string | string[];\n disabled?: boolean;\n toggleItem: (value: string) => void;\n };\n}\n\nexport class AccordionItem extends Component<Signature> {\n <template>\n <div data-state={{getDataState this.isExpanded}} data-disabled={{@disabled}} ...attributes>\n {{yield\n (hash\n isExpanded=this.isExpanded\n Header=(component\n Header\n value=@value\n isExpanded=this.isExpanded\n disabled=@disabled\n toggleItem=this.toggleItem\n )\n Content=(component Content value=@value isExpanded=this.isExpanded disabled=@disabled)\n )\n }}\n </div>\n </template>\n\n get isExpanded(): boolean {\n if (Array.isArray(this.args.selectedValue)) {\n return this.args.selectedValue.includes(this.args.value);\n }\n\n return this.args.selectedValue === this.args.value;\n }\n\n toggleItem = (): void => {\n if (this.args.disabled) return;\n\n this.args.toggleItem(this.args.value);\n };\n}\n\nexport default AccordionItem;\n"],"names":["AccordionContent","Component","setComponentTemplate","precompileTemplate","strictMode","scope","getDataState","isHidden","args","isExpanded","AccordionTrigger","on","templateOnly","AccordionHeader","hash","Trigger","AccordionItem","Header","Content","Array","isArray","selectedValue","includes","value","toggleItem","disabled"],"mappings":";;;;;;;AAcO,MAAMA,yBAAyBC,
|
|
1
|
+
{"version":3,"file":"item-D6pwWzMs.js","sources":["../src/components/accordion/content.gts","../src/components/accordion/trigger.gts","../src/components/accordion/header.gts","../src/components/accordion/item.gts"],"sourcesContent":["import Component from \"@glimmer/component\";\n\nimport { getDataState } from \"./item.gts\";\n\nimport type { AccordionContentExternalSignature } from \"./public.ts\";\n\ninterface Signature extends AccordionContentExternalSignature {\n Args: {\n isExpanded: boolean;\n value: string;\n disabled?: boolean;\n };\n}\n\nexport class AccordionContent extends Component<Signature> {\n <template>\n <div\n role=\"region\"\n id={{@value}}\n data-state={{getDataState @isExpanded}}\n hidden={{this.isHidden}}\n data-disabled={{@disabled}}\n ...attributes\n >\n {{yield}}\n </div>\n </template>\n\n get isHidden() {\n return !this.args.isExpanded;\n }\n}\n\nexport default AccordionContent;\n","import { on } from \"@ember/modifier\";\n\nimport { getDataState } from \"./item.gts\";\n\nimport type { AccordionTriggerExternalSignature } from \"./public.ts\";\nimport type { TOC } from \"@ember/component/template-only\";\n\ninterface Signature extends AccordionTriggerExternalSignature {\n Args: {\n isExpanded: boolean;\n value: string;\n disabled?: boolean;\n toggleItem: () => void;\n };\n}\n\nexport const AccordionTrigger: TOC<Signature> = <template>\n <button\n type=\"button\"\n aria-controls={{@value}}\n aria-expanded={{@isExpanded}}\n data-state={{getDataState @isExpanded}}\n data-disabled={{@disabled}}\n aria-disabled={{if @disabled \"true\" \"false\"}}\n {{on \"click\" @toggleItem}}\n ...attributes\n >\n {{yield}}\n </button>\n</template>;\n\nexport default AccordionTrigger;\n","import { hash } from \"@ember/helper\";\n\nimport { getDataState } from \"./item.gts\";\nimport Trigger from \"./trigger.gts\";\n\nimport type { AccordionHeaderExternalSignature } from \"./public.ts\";\nimport type { TOC } from \"@ember/component/template-only\";\n\ninterface Signature extends AccordionHeaderExternalSignature {\n Args: {\n value: string;\n isExpanded: boolean;\n disabled?: boolean;\n toggleItem: () => void;\n };\n}\n\nexport const AccordionHeader: TOC<Signature> = <template>\n <div\n role=\"heading\"\n aria-level=\"3\"\n data-state={{getDataState @isExpanded}}\n data-disabled={{@disabled}}\n ...attributes\n >\n {{yield\n (hash\n Trigger=(component\n Trigger value=@value isExpanded=@isExpanded disabled=@disabled toggleItem=@toggleItem\n )\n )\n }}\n </div>\n</template>;\n\nexport default AccordionHeader;\n","import Component from \"@glimmer/component\";\nimport { hash } from \"@ember/helper\";\n\nimport Content from \"./content.gts\";\nimport Header from \"./header.gts\";\n\nimport type { AccordionItemExternalSignature } from \"./public.ts\";\n\nexport function getDataState(isExpanded: boolean): string {\n return isExpanded ? \"open\" : \"closed\";\n}\n\ninterface Signature extends AccordionItemExternalSignature {\n Args: AccordionItemExternalSignature[\"Args\"] & {\n selectedValue?: string | string[];\n disabled?: boolean;\n toggleItem: (value: string) => void;\n };\n}\n\nexport class AccordionItem extends Component<Signature> {\n <template>\n <div data-state={{getDataState this.isExpanded}} data-disabled={{@disabled}} ...attributes>\n {{yield\n (hash\n isExpanded=this.isExpanded\n Header=(component\n Header\n value=@value\n isExpanded=this.isExpanded\n disabled=@disabled\n toggleItem=this.toggleItem\n )\n Content=(component Content value=@value isExpanded=this.isExpanded disabled=@disabled)\n )\n }}\n </div>\n </template>\n\n get isExpanded(): boolean {\n if (Array.isArray(this.args.selectedValue)) {\n return this.args.selectedValue.includes(this.args.value);\n }\n\n return this.args.selectedValue === this.args.value;\n }\n\n toggleItem = (): void => {\n if (this.args.disabled) return;\n\n this.args.toggleItem(this.args.value);\n };\n}\n\nexport default AccordionItem;\n"],"names":["AccordionContent","Component","setComponentTemplate","precompileTemplate","strictMode","scope","getDataState","isHidden","args","isExpanded","AccordionTrigger","on","templateOnly","AccordionHeader","hash","Trigger","AccordionItem","Header","Content","Array","isArray","selectedValue","includes","value","toggleItem","disabled"],"mappings":";;;;;;;AAcO,MAAMA,yBAAyBC,SAAA,CAAU;AAC9C,EAAA;IAAAC,oBAAA,CAAAC,kBAAA,CAAA,uLAAA,EAWA;MAAAC,UAAA,EAAA,IAAA;AAAAC,MAAAA,KAAA,EAAAA,OAAA;AAAAC,QAAAA;AAAA,OAAA;KAAU,CAAA,EAAV,IAAW,CAAA;AAAD;EAEV,IAAIC,QAAAA,GAAW;AACb,IAAA,OAAO,CAAC,IAAI,CAACC,IAAI,CAACC,UAAU;AAC9B;AACF;;MCfaC,gBAAsB,GAAAR,oBAAA,CAAaC,kBAAA,CAAA,oRAAA,EAahD;EAAAC,UAAA,EAAA,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
-
{"version":3,"file":"proper-links.js","sources":["../src/proper-links.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { registerDestructor } from '@ember/destroyable';\nimport { getOwner } from '@ember/owner';\n\nimport { getAnchor, shouldHandle } from 'should-handle-link';\n\nimport type EmberRouter from '@ember/routing/router';\nimport type RouterService from '@ember/routing/router-service';\n\nexport { shouldHandle } from 'should-handle-link';\n\ntype Constructor<T extends object = object> = { new (...args: any[]): T };\n\nexport interface Options {\n ignore?: string[];\n}\n\nexport function properLinks(\n options: Options\n): <Instance extends object, Klass = { new (...args: any[]): Instance }>(klass: Klass) => Klass;\n\nexport function properLinks<Instance extends object, Klass = { new (...args: any[]): Instance }>(\n klass: Klass\n): Klass;\n/**\n * @internal\n */\nexport function properLinks<Instance extends object, Klass = { new (...args: any[]): Instance }>(\n options: Options,\n klass: Klass\n): Klass;\n\nexport function properLinks<Instance extends object, Klass = { new (...args: any[]): Instance }>(\n ...args: [Options] | [Klass] | [Options, Klass]\n): Klass | ((klass: Klass) => Klass) {\n let options: Options = {};\n\n let klass: undefined | Klass = undefined;\n\n if (args.length === 2) {\n options = args[0];\n klass = args[1];\n } else if (args.length === 1) {\n if (typeof args[0] === 'object') {\n // TODO: how to get first arg type correct?\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return (klass: Klass) => properLinks(args[0] as any, klass);\n } else {\n klass = args[0];\n }\n }\n\n const ignore = options.ignore || [];\n\n assert(`klass was not defined. possibile incorrect arity given to properLinks`, klass);\n\n return class RouterWithProperLinks extends (klass as unknown as Constructor<EmberRouter>) {\n // SAFETY: we literally do not care about the args' type here,\n // because we just call super\n constructor(...args: any[]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n super(...args);\n\n setup(this, ignore);\n }\n } as unknown as Klass;\n}\n\n/**\n * Setup proper links without a decorator.\n * This function only requires that a framework object with an owner is passed.\n */\nexport function setup(parent: object, ignore?: string[]) {\n const handler = (event: MouseEvent) => {\n /**\n * event.target may not be an anchor,\n * it may be a span, svg, img, or any number of elements nested in <a>...</a>\n */\n const interactive = getAnchor(event);\n\n if (!interactive) return;\n\n const owner = getOwner(parent);\n\n assert('owner is not present', owner);\n\n const routerService = owner.lookup('service:router');\n\n handle(routerService, interactive, ignore ?? [], event);\n };\n\n document.body.addEventListener('click', handler, false);\n\n registerDestructor(parent, () => document.body.removeEventListener('click', handler));\n}\n\nexport function handle(\n router: RouterService,\n element: HTMLAnchorElement,\n ignore: string[],\n event: MouseEvent\n) {\n if (!shouldHandle(location.href, element, event, ignore)) {\n return;\n }\n\n const url = new URL(element.href);\n\n const fullHref = `${url.pathname}${url.search}${url.hash}`;\n\n const rootURL = router.rootURL;\n\n let withoutRootURL = fullHref.slice(rootURL.length);\n\n // re-add the \"root\" sigil\n // we removed it when we chopped off the rootURL,\n // because the rootURL often has this attached to it as well\n if (!withoutRootURL.startsWith('/')) {\n withoutRootURL = `/${withoutRootURL}`;\n }\n\n try {\n const routeInfo = router.recognize(fullHref);\n\n if (routeInfo) {\n event.preventDefault();\n event.stopImmediatePropagation();\n event.stopPropagation();\n\n router.transitionTo(withoutRootURL);\n\n return false;\n }\n } catch (e) {\n if (e instanceof Error && e.name === 'UnrecognizedURLError') {\n return;\n }\n\n throw e;\n }\n}\n"],"names":["properLinks","args","options","klass","undefined","length","ignore","assert","RouterWithProperLinks","constructor","setup","parent","handler","event","interactive","getAnchor","owner","getOwner","routerService","lookup","handle","document","body","addEventListener","registerDestructor","removeEventListener","router","element","shouldHandle","location","href","url","URL","fullHref","pathname","search","hash","rootURL","withoutRootURL","slice","startsWith","routeInfo","recognize","preventDefault","stopImmediatePropagation","stopPropagation","transitionTo","e","Error","name"],"mappings":";;;;;;AAwBA;AACA;AACA;;AAMO,SAASA,WAAWA,CACzB,GAAGC,IAA4C,EACZ;EACnC,IAAIC,OAAgB,GAAG,EAAE;EAEzB,IAAIC,KAAwB,GAAGC,SAAS;AAExC,EAAA,IAAIH,IAAI,CAACI,MAAM,KAAK,CAAC,EA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O,KAAK,CAAC;GACxD;EAEDQ,QAAQ,CAACC,IAAI,CAACC,gBAAgB,CAAC,OAAO,EAAEX,OAAO,EAAE,KAAK,CAAC;AAEvDY,EAAAA,kBAAkB,CAACb,MAAM,EAAE,MAAMU,QAAQ,CAACC,IAAI,CAACG,mBAAmB,CAAC,OAAO,EAAEb,OAAO,CAAC,CAAC;AACvF;AAEO,SAASQ,MAAMA,CACpBM,MAAqB,EACrBC,OAA0B,EAC1BrB,MAAgB,EAChBO,KAAiB,EACjB;AACA,EAAA,IAAI,CAACe,YAAY,CAACC,QAAQ,CAACC,IAAI,EAAEH,OAAO,EAAEd,KAAK,EAAEP,MAAM,CAAC,EAAE;AACxD,IAAA;AACF;EAEA,MAAMyB,GAAG,GAAG,IAAIC,GAAG,CAACL,OAAO,CAACG,IAAI,CAAC;AAEjC,EAAA,MAAMG,QAAQ,GAAG,
|
|
1
|
+
{"version":3,"file":"proper-links.js","sources":["../src/proper-links.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { registerDestructor } from '@ember/destroyable';\nimport { getOwner } from '@ember/owner';\n\nimport { getAnchor, shouldHandle } from 'should-handle-link';\n\nimport type EmberRouter from '@ember/routing/router';\nimport type RouterService from '@ember/routing/router-service';\n\nexport { shouldHandle } from 'should-handle-link';\n\ntype Constructor<T extends object = object> = { new (...args: any[]): T };\n\nexport interface Options {\n ignore?: string[];\n}\n\nexport function properLinks(\n options: Options\n): <Instance extends object, Klass = { new (...args: any[]): Instance }>(klass: Klass) => Klass;\n\nexport function properLinks<Instance extends object, Klass = { new (...args: any[]): Instance }>(\n klass: Klass\n): Klass;\n/**\n * @internal\n */\nexport function properLinks<Instance extends object, Klass = { new (...args: any[]): Instance }>(\n options: Options,\n klass: Klass\n): Klass;\n\nexport function properLinks<Instance extends object, Klass = { new (...args: any[]): Instance }>(\n ...args: [Options] | [Klass] | [Options, Klass]\n): Klass | ((klass: Klass) => Klass) {\n let options: Options = {};\n\n let klass: undefined | Klass = undefined;\n\n if (args.length === 2) {\n options = args[0];\n klass = args[1];\n } else if (args.length === 1) {\n if (typeof args[0] === 'object') {\n // TODO: how to get first arg type correct?\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n return (klass: Klass) => properLinks(args[0] as any, klass);\n } else {\n klass = args[0];\n }\n }\n\n const ignore = options.ignore || [];\n\n assert(`klass was not defined. possibile incorrect arity given to properLinks`, klass);\n\n return class RouterWithProperLinks extends (klass as unknown as Constructor<EmberRouter>) {\n // SAFETY: we literally do not care about the args' type here,\n // because we just call super\n constructor(...args: any[]) {\n // eslint-disable-next-line @typescript-eslint/no-unsafe-argument\n super(...args);\n\n setup(this, ignore);\n }\n } as unknown as Klass;\n}\n\n/**\n * Setup proper links without a decorator.\n * This function only requires that a framework object with an owner is passed.\n */\nexport function setup(parent: object, ignore?: string[]) {\n const handler = (event: MouseEvent) => {\n /**\n * event.target may not be an anchor,\n * it may be a span, svg, img, or any number of elements nested in <a>...</a>\n */\n const interactive = getAnchor(event);\n\n if (!interactive) return;\n\n const owner = getOwner(parent);\n\n assert('owner is not present', owner);\n\n const routerService = owner.lookup('service:router');\n\n handle(routerService, interactive, ignore ?? [], event);\n };\n\n document.body.addEventListener('click', handler, false);\n\n registerDestructor(parent, () => document.body.removeEventListener('click', handler));\n}\n\nexport function handle(\n router: RouterService,\n element: HTMLAnchorElement,\n ignore: string[],\n event: MouseEvent\n) {\n if (!shouldHandle(location.href, element, event, ignore)) {\n return;\n }\n\n const url = new URL(element.href);\n\n const fullHref = `${url.pathname}${url.search}${url.hash}`;\n\n const rootURL = router.rootURL;\n\n let withoutRootURL = fullHref.slice(rootURL.length);\n\n // re-add the \"root\" sigil\n // we removed it when we chopped off the rootURL,\n // because the rootURL often has this attached to it as well\n if (!withoutRootURL.startsWith('/')) {\n withoutRootURL = `/${withoutRootURL}`;\n }\n\n try {\n const routeInfo = router.recognize(fullHref);\n\n if (routeInfo) {\n event.preventDefault();\n event.stopImmediatePropagation();\n event.stopPropagation();\n\n router.transitionTo(withoutRootURL);\n\n return false;\n }\n } catch (e) {\n if (e instanceof Error && e.name === 'UnrecognizedURLError') {\n return;\n }\n\n throw e;\n }\n}\n"],"names":["properLinks","args","options","klass","undefined","length","ignore","assert","RouterWithProperLinks","constructor","setup","parent","handler","event","interactive","getAnchor","owner","getOwner","routerService","lookup","handle","document","body","addEventListener","registerDestructor","removeEventListener","router","element","shouldHandle","location","href","url","URL","fullHref","pathname","search","hash","rootURL","withoutRootURL","slice","startsWith","routeInfo","recognize","preventDefault","stopImmediatePropagation","stopPropagation","transitionTo","e","Error","name"],"mappings":";;;;;;AAwBA;AACA;AACA;;AAMO,SAASA,WAAWA,CACzB,GAAGC,IAA4C,EACZ;EACnC,IAAIC,OAAgB,GAAG,EAAE;EAEzB,IAAIC,KAAwB,GAAGC,SAAS;AAExC,EAAA,IAAIH,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;AACrBH,IAAAA,OAAO,GAAGD,IAAI,CAAC,CAAC,CAAC;AACjBE,IAAAA,KAAK,GAAGF,IAAI,CAAC,CAAC,CAAC;AACjB,GAAC,MAAM,IAAIA,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;AAC5B,IAAA,IAAI,OAAOJ,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;AAC/B;AACA;MACA,OAAQE,KAAY,IAAKH,WAAW,CAACC,IAAI,CAAC,CAAC,CAAC,EAASE,KAAK,CAAC;AAC7D,KAAC,MAAM;AACLA,MAAAA,KAAK,GAAGF,IAAI,CAAC,CAAC,CAAC;AACjB;AACF;AAEA,EAAA,MAAMK,MAAM,GAAGJ,OAAO,CAACI,MAAM,IAAI,EAAE;AAEnCC,EAAAA,MAAM,CAAC,CAAA,qEAAA,CAAuE,EAAEJ,KAAK,CAAC;AAEtF,EAAA,OAAO,MAAMK,qBAAqB,SAAUL,KAAK,CAAyC;AACxF;AACA;IACAM,WAAWA,CAAC,GAAGR,IAAW,EAAE;AAC1B;MACA,KAAK,CAAC,GAAG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O,GAAGX,MAAM,CAACW,OAAO;EAE9B,IAAIC,cAAc,GAAGL,QAAQ,CAACM,KAAK,CAACF,OAAO,CAAChC,MAAM,CAAC;;AAEnD;AACA;AACA;AACA,EAAA,IAAI,CAACiC,cAAc,CAACE,UAAU,CAAC,GAAG,CAAC,EAAE;IACnCF,cAAc,GAAG,CAAA,CAAA,EAAIA,cAAc,CAAA,CAAE;AACvC;EAEA,IAAI;AACF,IAAA,MAAMG,SAAS,GAAGf,MAAM,CAACgB,SAAS,CAACT,QAAQ,CAAC;AAE5C,IAAA,IAAIQ,SAAS,EAAE;MACb5B,KAAK,CAAC8B,cAAc,EAAE;MACtB9B,KAAK,CAAC+B,wBAAwB,EAAE;MAChC/B,KAAK,CAACgC,eAAe,EAAE;AAEvBnB,MAAAA,MAAM,CAACoB,YAAY,CAACR,cAAc,CAAC;AAEnC,MAAA,OAAO,KAAK;AACd;GACD,CAAC,OAAOS,CAAC,EAAE;IACV,IAAIA,CAAC,YAAYC,KAAK,IAAID,CAAC,CAACE,IAAI,KAAK,sBAAsB,EAAE;AAC3D,MAAA;AACF;AAEA,IAAA,MAAMF,CAAC;AACT;AACF;;;;"}
|
package/dist/qp.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import Helper from '@ember/component/helper';
|
|
2
|
+
import { assert } from '@ember/debug';
|
|
3
|
+
import { service } from '@ember/service';
|
|
4
|
+
import { g, i } from 'decorator-transforms/runtime';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Grabs a query-param off the current route from the router service.
|
|
8
|
+
*
|
|
9
|
+
* ```gjs
|
|
10
|
+
* import { qp } from 'ember-primitives/qp';
|
|
11
|
+
*
|
|
12
|
+
* <template>
|
|
13
|
+
* {{qp "query-param"}}
|
|
14
|
+
* </template>
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
class qp extends Helper {
|
|
18
|
+
static {
|
|
19
|
+
g(this.prototype, "router", [service]);
|
|
20
|
+
}
|
|
21
|
+
#router = (i(this, "router"), void 0);
|
|
22
|
+
compute([name]) {
|
|
23
|
+
assert('A queryParam name is required', name);
|
|
24
|
+
return this.router.currentRoute?.queryParams?.[name];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns a string for use as an `href` on `<a>` tags, updated with the passed query param
|
|
30
|
+
*
|
|
31
|
+
* ```gjs
|
|
32
|
+
* import { withQP } from 'ember-primitives/qp';
|
|
33
|
+
*
|
|
34
|
+
* <template>
|
|
35
|
+
* <a href={{withQP "foo" "2"}}>
|
|
36
|
+
* ...
|
|
37
|
+
* </a>
|
|
38
|
+
* </template>
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
class withQP extends Helper {
|
|
42
|
+
static {
|
|
43
|
+
g(this.prototype, "router", [service]);
|
|
44
|
+
}
|
|
45
|
+
#router = (i(this, "router"), void 0);
|
|
46
|
+
compute([qpName, nextValue]) {
|
|
47
|
+
const existing = this.router.currentURL;
|
|
48
|
+
assert('A queryParam name is required', qpName);
|
|
49
|
+
assert('There is no currentURL', existing);
|
|
50
|
+
const url = new URL(existing, location.origin);
|
|
51
|
+
url.searchParams.set(qpName, nextValue);
|
|
52
|
+
return url.href;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Cast a query-param string value to a boolean
|
|
58
|
+
*
|
|
59
|
+
* ```gjs
|
|
60
|
+
* import { castToBoolean, qp } from 'ember-primitives/qp';
|
|
61
|
+
*
|
|
62
|
+
* <template>
|
|
63
|
+
* {{#if (castToBoolean (qp 'the-qp'))}}
|
|
64
|
+
* ...
|
|
65
|
+
* {{/if}}
|
|
66
|
+
* </template>
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* The following values are considered "false"
|
|
70
|
+
* - undefined
|
|
71
|
+
* - ""
|
|
72
|
+
* - "0"
|
|
73
|
+
* - false
|
|
74
|
+
* - "f"
|
|
75
|
+
* - "off"
|
|
76
|
+
* - "no"
|
|
77
|
+
* - "null"
|
|
78
|
+
* - "undefined"
|
|
79
|
+
*
|
|
80
|
+
* All other values are considered truthy
|
|
81
|
+
*/
|
|
82
|
+
function castToBoolean(x) {
|
|
83
|
+
if (!x) return false;
|
|
84
|
+
const isFalsey = x === '0' || x === 'false' || x === 'f' || x === 'null' || x === 'off' || x === 'undefined' || x === 'no';
|
|
85
|
+
if (isFalsey) return false;
|
|
86
|
+
|
|
87
|
+
// All other values are considered truthy
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
export { castToBoolean, qp, withQP };
|
|
92
|
+
//# sourceMappingURL=qp.js.map
|
package/dist/qp.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"qp.js","sources":["../src/qp.ts"],"sourcesContent":["import Helper from '@ember/component/helper';\nimport { assert } from '@ember/debug';\nimport { service } from '@ember/service';\n\nimport type RouterService from '@ember/routing/router-service';\n\ninterface Signature {\n Args: {\n Positional: [string];\n };\n Return: string | undefined;\n}\n\n/**\n * Grabs a query-param off the current route from the router service.\n *\n * ```gjs\n * import { qp } from 'ember-primitives/qp';\n *\n * <template>\n * {{qp \"query-param\"}}\n * </template>\n * ```\n */\nexport class qp extends Helper<Signature> {\n @service declare router: RouterService;\n\n compute([name]: [string]): string | undefined {\n assert('A queryParam name is required', name);\n\n return this.router.currentRoute?.queryParams?.[name] as string | undefined;\n }\n}\n\n/**\n * Returns a string for use as an `href` on `<a>` tags, updated with the passed query param\n *\n * ```gjs\n * import { withQP } from 'ember-primitives/qp';\n *\n * <template>\n * <a href={{withQP \"foo\" \"2\"}}>\n * ...\n * </a>\n * </template>\n * ```\n */\nexport class withQP extends Helper<{ Args: { Positional: [string, string] }; Return: string }> {\n @service declare router: RouterService;\n\n compute([qpName, nextValue]: [string, string]) {\n const existing = this.router.currentURL;\n\n assert('A queryParam name is required', qpName);\n assert('There is no currentURL', existing);\n\n const url = new URL(existing, location.origin);\n\n url.searchParams.set(qpName, nextValue);\n\n return url.href;\n }\n}\n\n/**\n * Cast a query-param string value to a boolean\n *\n * ```gjs\n * import { castToBoolean, qp } from 'ember-primitives/qp';\n *\n * <template>\n * {{#if (castToBoolean (qp 'the-qp'))}}\n * ...\n * {{/if}}\n * </template>\n * ```\n *\n * The following values are considered \"false\"\n * - undefined\n * - \"\"\n * - \"0\"\n * - false\n * - \"f\"\n * - \"off\"\n * - \"no\"\n * - \"null\"\n * - \"undefined\"\n *\n * All other values are considered truthy\n */\nexport function castToBoolean(x: string | undefined) {\n if (!x) return false;\n\n const isFalsey =\n x === '0' ||\n x === 'false' ||\n x === 'f' ||\n x === 'null' ||\n x === 'off' ||\n x === 'undefined' ||\n x === 'no';\n\n if (isFalsey) return false;\n\n // All other values are considered truthy\n return true;\n}\n"],"names":["qp","Helper","g","prototype","service","i","void 0","compute","name","assert","router","currentRoute","queryParams","withQP","qpName","nextValue","existing","currentURL","url","URL","location","origin","searchParams","set","href","castToBoolean","x","isFalsey"],"mappings":";;;;;AAaA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,EAAE,SAASC,MAAM,CAAY;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CACvCC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACC,IAAI,CAAW,EAAsB;AAC5CC,IAAAA,MAAM,CAAC,+BAA+B,EAAED,IAAI,CAAC;IAE7C,OAAO,IAAI,CAACE,MAAM,CAACC,YAAY,EAAEC,WAAW,GAAGJ,IAAI,CAAC;AACtD;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMK,MAAM,SAASZ,MAAM,CAA6D;AAAA,EAAA;IAAAC,CAAA,CAAA,IAAA,CAAAC,SAAA,EAAA,QAAA,EAAA,CAC5FC,OAAO,CAAA,CAAA;AAAA;AAAA,EAAA,OAAA,IAAAC,CAAA,CAAA,IAAA,EAAA,QAAA,CAAA,EAAAC,MAAA;AAERC,EAAAA,OAAOA,CAAC,CAACO,MAAM,EAAEC,SAAS,CAAmB,EAAE;AAC7C,IAAA,MAAMC,QAAQ,GAAG,IAAI,CAACN,MAAM,CAACO,UAAU;AAEvCR,IAAAA,MAAM,CAAC,+BAA+B,EAAEK,MAAM,CAAC;AAC/CL,IAAAA,MAAM,CAAC,wBAAwB,EAAEO,QAAQ,CAAC;IAE1C,MAAME,GAAG,GAAG,IAAIC,GAAG,CAACH,QAAQ,EAAEI,QAAQ,CAACC,MAAM,CAAC;IAE9CH,GAAG,CAACI,YAAY,CAACC,GAAG,CAACT,MAAM,EAAEC,SAAS,CAAC;IAEvC,OAAOG,GAAG,CAACM,IAAI;AACjB;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,aAAaA,CAACC,CAAqB,EAAE;AACnD,EAAA,IAAI,CAACA,CAAC,EAAE,OAAO,KAAK;AAEpB,EAAA,MAAMC,QAAQ,GACZD,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,OAAO,IACbA,CAAC,KAAK,GAAG,IACTA,CAAC,KAAK,MAAM,IACZA,CAAC,KAAK,KAAK,IACXA,CAAC,KAAK,WAAW,IACjBA,CAAC,KAAK,IAAI;EAEZ,IAAIC,QAAQ,EAAE,OAAO,KAAK;;AAE1B;AACA,EAAA,OAAO,IAAI;AACb;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otp.js","sources":["../../src/test-support/otp.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { fillIn, find, settled } from '@ember/test-helpers';\n\n/**\n * @param {string} code the code to fill the input(s) with.\n * @param {string} [ selector ] if there are multiple OTP components on a page, this can be used to select one of them.\n */\nexport async function fillOTP(code: string, selector?: string) {\n const ancestor = selector ? find(selector) : document;\n\n assert(\n `Could not find ancestor element, does your selector match an existing element?`,\n ancestor\n );\n\n const fieldset =\n ancestor instanceof HTMLFieldSetElement ? ancestor : ancestor.querySelector('fieldset');\n\n assert(\n `Could not find containing fieldset element (this holds the OTP Input fields). Was the OTP component rendered?`,\n fieldset\n );\n\n const inputs = fieldset.querySelectorAll('input');\n\n assert(\n `code cannot be longer than the available inputs. code is of length ${code.length} but there are ${inputs.length}`,\n code.length <= inputs.length\n );\n\n const chars = code.split('');\n\n assert(`OTP Input for index 0 is missing!`, inputs[0]);\n assert(`Character at index 0 is missing`, chars[0]);\n\n for (let i = 0; i < chars.length; i++) {\n const input = inputs[i];\n const char = chars[i];\n\n assert(`Input at index ${i} is missing`, input);\n assert(`Character at index ${i} is missing`, char);\n\n input.value = char;\n }\n\n await fillIn(inputs[0], chars[0]);\n\n // Account for out-of-settled-system delay due to RAF debounce.\n await new Promise((resolve) => requestAnimationFrame(resolve));\n await settled();\n}\n"],"names":["fillOTP","code","selector","ancestor","find","document","assert","fieldset","HTMLFieldSetElement","querySelector","inputs","querySelectorAll","length","chars","split","i","input","char","value","fillIn","Promise","resolve","requestAnimationFrame","settled"],"mappings":";;;AAGA;AACA;AACA;AACA;AACO,eAAeA,OAAOA,CAACC,IAAY,EAAEC,QAAiB,EAAE;EAC7D,MAAMC,QAAQ,GAAGD,QAAQ,GAAGE,IAAI,CAACF,QAAQ,CAAC,GAAGG,QAAQ;AAErDC,EAAAA,MAAM,CACJ,CAAA,8EAAA,CAAgF,EAChFH,QACF,CAAC;AAED,EAAA,MAAMI,QAAQ,GACZJ,QAAQ,YAAYK,mBAAmB,GAAGL,QAAQ,GAAGA,QAAQ,CAACM,aAAa,CAAC,UAAU,CAAC;AAEzFH,EAAAA,MAAM,CACJ,CAAA,6GAAA,CAA+G,EAC/GC,QACF,CAAC;AAED,EAAA,MAAMG,MAAM,GAAGH,QAAQ,CAACI,gBAAgB,CAAC,OAAO,CAAC;AAEjDL,EAAAA,MAAM,CACJ,
|
|
1
|
+
{"version":3,"file":"otp.js","sources":["../../src/test-support/otp.ts"],"sourcesContent":["import { assert } from '@ember/debug';\nimport { fillIn, find, settled } from '@ember/test-helpers';\n\n/**\n * @param {string} code the code to fill the input(s) with.\n * @param {string} [ selector ] if there are multiple OTP components on a page, this can be used to select one of them.\n */\nexport async function fillOTP(code: string, selector?: string) {\n const ancestor = selector ? find(selector) : document;\n\n assert(\n `Could not find ancestor element, does your selector match an existing element?`,\n ancestor\n );\n\n const fieldset =\n ancestor instanceof HTMLFieldSetElement ? ancestor : ancestor.querySelector('fieldset');\n\n assert(\n `Could not find containing fieldset element (this holds the OTP Input fields). Was the OTP component rendered?`,\n fieldset\n );\n\n const inputs = fieldset.querySelectorAll('input');\n\n assert(\n `code cannot be longer than the available inputs. code is of length ${code.length} but there are ${inputs.length}`,\n code.length <= inputs.length\n );\n\n const chars = code.split('');\n\n assert(`OTP Input for index 0 is missing!`, inputs[0]);\n assert(`Character at index 0 is missing`, chars[0]);\n\n for (let i = 0; i < chars.length; i++) {\n const input = inputs[i];\n const char = chars[i];\n\n assert(`Input at index ${i} is missing`, input);\n assert(`Character at index ${i} is missing`, char);\n\n input.value = char;\n }\n\n await fillIn(inputs[0], chars[0]);\n\n // Account for out-of-settled-system delay due to RAF debounce.\n await new Promise((resolve) => requestAnimationFrame(resolve));\n await settled();\n}\n"],"names":["fillOTP","code","selector","ancestor","find","document","assert","fieldset","HTMLFieldSetElement","querySelector","inputs","querySelectorAll","length","chars","split","i","input","char","value","fillIn","Promise","resolve","requestAnimationFrame","settled"],"mappings":";;;AAGA;AACA;AACA;AACA;AACO,eAAeA,OAAOA,CAACC,IAAY,EAAEC,QAAiB,EAAE;EAC7D,MAAMC,QAAQ,GAAGD,QAAQ,GAAGE,IAAI,CAACF,QAAQ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