ember-primitives 0.22.0 → 0.23.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.
@@ -1,4 +1,5 @@
1
1
  import type RouterService from '@ember/routing/router-service';
2
+ export { shouldHandle } from 'should-handle-link';
2
3
  export interface Options {
3
4
  ignore?: string[];
4
5
  }
@@ -19,11 +20,5 @@ export declare function properLinks<Instance extends {}, Klass = {
19
20
  * This function only requires that a framework object with an owner is passed.
20
21
  */
21
22
  export declare function setup(parent: object, ignore?: string[]): void;
22
- export declare function isLink(event: Event): HTMLAnchorElement | undefined;
23
23
  export declare function handle(router: RouterService, element: HTMLAnchorElement, ignore: string[], event: MouseEvent): false | undefined;
24
- /**
25
- * Returns `true` if the link should be handled by the Ember router
26
- * Returns `false` if the link should be handled by the browser
27
- */
28
- export declare function shouldHandle(href: string, element: HTMLAnchorElement, ignore: string[], event: MouseEvent): boolean;
29
24
  //# sourceMappingURL=proper-links.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proper-links.d.ts","sourceRoot":"","sources":["../src/proper-links.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAI/D,MAAM,WAAW,OAAO;IACtB,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;CACnB;AAED,wBAAgB,WAAW,CACzB,OAAO,EAAE,OAAO,GACf,CAAC,QAAQ,SAAS,EAAE,EAAE,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAA;CAAE,EAAE,KAAK,EAAE,KAAK,KAAK,KAAK,CAAC;AAE5F,wBAAgB,WAAW,CAAC,QAAQ,SAAS,EAAE,EAAE,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAA;CAAE,EACzF,KAAK,EAAE,KAAK,GACX,KAAK,CAAC;AACT;;GAEG;AACH,wBAAgB,WAAW,CAAC,Q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EG;AACH,wBAAgB,WAAW,CAAC,QAAQ,SAAS,EAAE,EAAE,KAAK,GAAG;IAAE,KAAK,GAAG,IAAI,EAAE,GAAG,EAAE,GAAG,QAAQ,CAAA;CAAE,EACzF,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,KAAK,GACX,KAAK,CAAC;AAoCT;;;GAGG;AACH,wBAAgB,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,QAsBtD;AAED,wBAAgB,MAAM,CACpB,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,iBAAiB,EAC1B,MAAM,EAAE,MAAM,EAAE,EAChB,KAAK,EAAE,UAAU,qBAwClB"}
@@ -1,4 +1,5 @@
1
1
  .ember-primitives__hero__wrapper {
2
2
  width: 100dvw;
3
3
  height: 100dvh;
4
+ position: relative;
4
5
  }
@@ -1,6 +1,8 @@
1
1
  import { assert } from '@ember/debug';
2
2
  import { registerDestructor } from '@ember/destroyable';
3
3
  import { getOwner } from '@ember/owner';
4
+ import { shouldHandle, getAnchor } from 'should-handle-link';
5
+ export { shouldHandle } from 'should-handle-link';
4
6
 
5
7
  /* eslint-disable @typescript-eslint/no-explicit-any */
6
8
 
@@ -44,7 +46,7 @@ function setup(parent, ignore) {
44
46
  * event.target may not be an anchor,
45
47
  * it may be a span, svg, img, or any number of elements nested in <a>...</a>
46
48
  */
47
- let interactive = isLink(event);
49
+ let interactive = getAnchor(event);
48
50
  if (!interactive) return;
49
51
  let owner = getOwner(parent);
50
52
  assert('owner is not present', owner);
@@ -54,20 +56,8 @@ function setup(parent, ignore) {
54
56
  document.body.addEventListener('click', handler, false);
55
57
  registerDestructor(parent, () => document.body.removeEventListener('click', handler));
56
58
  }
57
- function isLink(event) {
58
- /**
59
- * Using composed path in case the link is removed from the DOM
60
- * before the event handler evaluates
61
- */
62
- let composedPath = event.composedPath();
63
- for (let element of composedPath) {
64
- if (element instanceof HTMLAnchorElement) {
65
- return element;
66
- }
67
- }
68
- }
69
59
  function handle(router, element, ignore, event) {
70
- if (!shouldHandle(location.href, element, ignore, event)) {
60
+ if (!shouldHandle(location.href, element, event, ignore)) {
71
61
  return;
72
62
  }
73
63
  let url = new URL(element.href);
@@ -98,101 +88,5 @@ function handle(router, element, ignore, event) {
98
88
  }
99
89
  }
100
90
 
101
- /**
102
- * Returns `true` if the link should be handled by the Ember router
103
- * Returns `false` if the link should be handled by the browser
104
- */
105
- function shouldHandle(href, element, ignore, event) {
106
- if (!element) return false;
107
- /**
108
- * If we don't have an href, the <a> is invalid.
109
- * If you're debugging your code and end up finding yourself
110
- * early-returning here, please add an href ;)
111
- */
112
- if (!element.href) return false;
113
-
114
- /**
115
- * This is partially an escape hatch, but any time target is set,
116
- * we are usually wanting to escape the behavior of single-page-apps.
117
- *
118
- * Some folks desire to have in-SPA links, but still do native browser behavior
119
- * (which for the case of SPAs is a full page refresh)
120
- * but they can set target="_self" to get that behavior back if they want.
121
- *
122
- * I expect that this'll be a super edge case, because the whole goal of
123
- * "proper links" is to do what is expected, always -- for in-app SPA links
124
- * as well as external, cross-domain links
125
- */
126
- if (element.target) return false;
127
-
128
- /**
129
- * If the click is not a "left click" we don't want to intercept the event.
130
- * This allows folks to
131
- * - middle click (usually open the link in a new tab)
132
- * - right click (usually opens the context menu)
133
- */
134
- if (event.button !== 0) return false;
135
-
136
- /**
137
- * for MacOS users, this default behavior opens the link in a new tab
138
- */
139
- if (event.metaKey) return false;
140
-
141
- /**
142
- * for for everyone else, this default behavior opens the link in a new tab
143
- */
144
- if (event.ctrlKey) return false;
145
-
146
- /**
147
- * The default behavior here downloads the link content
148
- */
149
- if (event.altKey) return false;
150
-
151
- /**
152
- * The default behavior here opens the link in a new window
153
- */
154
- if (event.shiftKey) return false;
155
-
156
- /**
157
- * If another event listener called event.preventDefault(), we don't want to proceed.
158
- */
159
- if (event.defaultPrevented) return false;
160
-
161
- /**
162
- * The href includes the protocol/host/etc
163
- * In order to not have the page look like a full page refresh,
164
- * we need to chop that "origin" off, and just use the path
165
- */
166
- let url = new URL(element.href);
167
- let location = new URL(href);
168
-
169
- /**
170
- * If the domains are different, we want to fall back to normal link behavior
171
- *
172
- */
173
- if (location.origin !== url.origin) return false;
174
-
175
- /**
176
- * Hash-only links are handled by the browser, except for the case where the
177
- * hash is being removed entirely, e.g. /foo#bar to /foo. In that case the
178
- * browser will do a full page refresh which is not what we want. Instead
179
- * we let the router handle such transitions. The current implementation of
180
- * the Ember router will skip the transition in this case because the path
181
- * is the same.
182
- */
183
- let [prehash, posthash] = url.href.split('#');
184
- if (posthash !== undefined && prehash === location.href.split('#')[0]) {
185
- return false;
186
- }
187
-
188
- /**
189
- * We can optionally declare some paths as ignored,
190
- * or "let the browser do its default thing,
191
- * because there is other server-based routing to worry about"
192
- */
193
- if (ignore.includes(url.pathname)) return false;
194
- return true;
195
- }
196
-
197
- export { handle, isLink, properLinks, setup, shouldHandle };
91
+ export { handle, properLinks, setup };
198
92
  //# sourceMappingURL=proper-links.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"proper-links.js","sources":["../src/proper-links.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { assert } from '@ember/debug';\nimport { registerDestructor } from '@ember/destroyable';\nimport { getOwner } from '@ember/owner';\n\nimport type EmberRouter from '@ember/routing/router';\nimport type RouterService from '@ember/routing/router-service';\n\ntype Constructor<T extends {} = {}> = { new (...args: any[]): T };\n\nexport interface Options {\n ignore?: string[];\n}\n\nexport function properLinks(\n options: Options\n): <Instance extends {}, Klass = { new (...args: any[]): Instance }>(klass: Klass) => Klass;\n\nexport function properLinks<Instance extends {}, Klass = { new (...args: any[]): Instance }>(\n klass: Klass\n): Klass;\n/**\n * @internal\n */\nexport function properLinks<Instance extends {}, Klass = { new (...args: any[]): Instance }>(\n options: Options,\n klass: Klass\n): Klass;\n\nexport function properLinks<Instance extends {}, 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] as Options;\n klass = args[1] as Klass;\n } else if (args.length === 1) {\n if (typeof args[0] === 'object') {\n // TODO: how to get first arg type correct?\n return (klass: Klass) => properLinks(args[0] as any, klass);\n } else {\n klass = args[0];\n }\n }\n\n let 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 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 let interactive = isLink(event);\n\n if (!interactive) return;\n\n let owner = getOwner(parent);\n\n assert('owner is not present', owner);\n\n let 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 isLink(event: Event) {\n /**\n * Using composed path in case the link is removed from the DOM\n * before the event handler evaluates\n */\n let composedPath = event.composedPath();\n\n for (let element of composedPath) {\n if (element instanceof HTMLAnchorElement) {\n return element;\n }\n }\n}\n\nexport function handle(\n router: RouterService,\n element: HTMLAnchorElement,\n ignore: string[],\n event: MouseEvent\n) {\n if (!shouldHandle(location.href, element, ignore, event)) {\n return;\n }\n\n let url = new URL(element.href);\n\n let fullHref = `${url.pathname}${url.search}${url.hash}`;\n\n let 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 let 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\n/**\n * Returns `true` if the link should be handled by the Ember router\n * Returns `false` if the link should be handled by the browser\n */\nexport function shouldHandle(\n href: string,\n element: HTMLAnchorElement,\n ignore: string[],\n event: MouseEvent\n) {\n if (!element) return false;\n /**\n * If we don't have an href, the <a> is invalid.\n * If you're debugging your code and end up finding yourself\n * early-returning here, please add an href ;)\n */\n if (!element.href) return false;\n\n /**\n * This is partially an escape hatch, but any time target is set,\n * we are usually wanting to escape the behavior of single-page-apps.\n *\n * Some folks desire to have in-SPA links, but still do native browser behavior\n * (which for the case of SPAs is a full page refresh)\n * but they can set target=\"_self\" to get that behavior back if they want.\n *\n * I expect that this'll be a super edge case, because the whole goal of\n * \"proper links\" is to do what is expected, always -- for in-app SPA links\n * as well as external, cross-domain links\n */\n if (element.target) return false;\n\n /**\n * If the click is not a \"left click\" we don't want to intercept the event.\n * This allows folks to\n * - middle click (usually open the link in a new tab)\n * - right click (usually opens the context menu)\n */\n if (event.button !== 0) return false;\n\n /**\n * for MacOS users, this default behavior opens the link in a new tab\n */\n if (event.metaKey) return false;\n\n /**\n * for for everyone else, this default behavior opens the link in a new tab\n */\n if (event.ctrlKey) return false;\n\n /**\n * The default behavior here downloads the link content\n */\n if (event.altKey) return false;\n\n /**\n * The default behavior here opens the link in a new window\n */\n if (event.shiftKey) return false;\n\n /**\n * If another event listener called event.preventDefault(), we don't want to proceed.\n */\n if (event.defaultPrevented) return false;\n\n /**\n * The href includes the protocol/host/etc\n * In order to not have the page look like a full page refresh,\n * we need to chop that \"origin\" off, and just use the path\n */\n let url = new URL(element.href);\n let location = new URL(href);\n\n /**\n * If the domains are different, we want to fall back to normal link behavior\n *\n */\n if (location.origin !== url.origin) return false;\n\n /**\n * Hash-only links are handled by the browser, except for the case where the\n * hash is being removed entirely, e.g. /foo#bar to /foo. In that case the\n * browser will do a full page refresh which is not what we want. Instead\n * we let the router handle such transitions. The current implementation of\n * the Ember router will skip the transition in this case because the path\n * is the same.\n */\n let [prehash, posthash] = url.href.split('#');\n\n if (posthash !== undefined && prehash === location.href.split('#')[0]) {\n return false;\n }\n\n /**\n * We can optionally declare some paths as ignored,\n * or \"let the browser do its default thing,\n * because there is other server-based routing to worry about\"\n */\n if (ignore.includes(url.pathname)) return false;\n\n return true;\n}\n"],"names":["properLinks","args","options","klass","undefined","length","ignore","assert","RouterWithProperLinks","constructor","setup","parent","handler","event","interactive","isLink","owner","getOwner","routerService","lookup","handle","document","body","addEventListener","registerDestructor","removeEventListener","composedPath","element","HTMLAnchorElement","router","shouldHandle","location","href","url","URL","fullHref","pathname","search","hash","rootURL","withoutRootURL","slice","startsWith","routeInfo","recognize","preventDefault","stopImmediatePropagation","stopPropagation","transitionTo","e","Error","name","target","button","metaKey","ctrlKey","altKey","shiftKey","defaultPrevented","origin","prehash","posthash","split","includes"],"mappings":";;;;AAAA;;AAqBA;AACA;AACA;;AAMO,SAASA,WAAWA,CACzB,GAAGC,IAA4C,EACZ;EACnC,IAAIC,OAAgB,GAAG,EAAE,CAAA;EAEzB,IAAIC,KAAwB,GAAGC,SAAS,CAAA;AAExC,EAAA,IAAIH,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;AACrBH,IAAAA,OAAO,GAAGD,IAAI,CAAC,CAAC,CAAY,CAAA;AAC5BE,IAAAA,KAAK,GAAGF,IAAI,CAAC,CAAC,CAAU,CAAA;AAC1B,GAAC,MAAM,IAAIA,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;AAC5B,IAAA,IAAI,OAAOJ,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;AAC/B;MACA,OAAQE,KAAY,IAAKH,WAAW,CAAC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I5C,KAAK,CAAC6C,gBAAgB,EAAE,OAAO,KAAK,CAAA;;AAExC;AACF;AACA;AACA;AACA;EACE,IAAIzB,GAAG,GAAG,IAAIC,GAAG,CAACP,OAAO,CAACK,IAAI,CAAC,CAAA;AAC/B,EAAA,IAAID,QAAQ,GAAG,IAAIG,GAAG,CAACF,IAAI,CAAC,CAAA;;AAE5B;AACF;AACA;AACA;EACE,IAAID,QAAQ,CAAC4B,MAAM,KAAK1B,GAAG,CAAC0B,MAAM,EAAE,OAAO,KAAK,CAAA;;AAEhD;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACE,EAAA,IAAI,CAACC,OAAO,EAAEC,QAAQ,CAAC,GAAG5B,GAAG,CAACD,IAAI,CAAC8B,KAAK,CAAC,GAAG,CAAC,CAAA;AAE7C,EAAA,IAAID,QAAQ,KAAKzD,SAAS,IAAIwD,OAAO,KAAK7B,QAAQ,CAACC,IAAI,CAAC8B,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE;AACrE,IAAA,OAAO,KAAK,CAAA;AACd,GAAA;;AAEA;AACF;AACA;AACA;AACA;EACE,IAAIxD,MAAM,CAACyD,QAAQ,CAAC9B,GAAG,CAACG,QAAQ,CAAC,EAAE,OAAO,KAAK,CAAA;AAE/C,EAAA,OAAO,IAAI,CAAA;AACb;;;;"}
1
+ {"version":3,"file":"proper-links.js","sources":["../src/proper-links.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { 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 {} = {}> = { new (...args: any[]): T };\n\nexport interface Options {\n ignore?: string[];\n}\n\nexport function properLinks(\n options: Options\n): <Instance extends {}, Klass = { new (...args: any[]): Instance }>(klass: Klass) => Klass;\n\nexport function properLinks<Instance extends {}, Klass = { new (...args: any[]): Instance }>(\n klass: Klass\n): Klass;\n/**\n * @internal\n */\nexport function properLinks<Instance extends {}, Klass = { new (...args: any[]): Instance }>(\n options: Options,\n klass: Klass\n): Klass;\n\nexport function properLinks<Instance extends {}, 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] as Options;\n klass = args[1] as Klass;\n } else if (args.length === 1) {\n if (typeof args[0] === 'object') {\n // TODO: how to get first arg type correct?\n return (klass: Klass) => properLinks(args[0] as any, klass);\n } else {\n klass = args[0];\n }\n }\n\n let 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 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 let interactive = getAnchor(event);\n\n if (!interactive) return;\n\n let owner = getOwner(parent);\n\n assert('owner is not present', owner);\n\n let 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 let url = new URL(element.href);\n\n let fullHref = `${url.pathname}${url.search}${url.hash}`;\n\n let 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 let 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":";;;;;;AAAA;;AAyBA;AACA;AACA;;AAMO,SAASA,WAAWA,CACzB,GAAGC,IAA4C,EACZ;EACnC,IAAIC,OAAgB,GAAG,EAAE,CAAA;EAEzB,IAAIC,KAAwB,GAAGC,SAAS,CAAA;AAExC,EAAA,IAAIH,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;AACrBH,IAAAA,OAAO,GAAGD,IAAI,CAAC,CAAC,CAAY,CAAA;AAC5BE,IAAAA,KAAK,GAAGF,IAAI,CAAC,CAAC,CAAU,CAAA;AAC1B,GAAC,MAAM,IAAIA,IAAI,CAACI,MAAM,KAAK,CAAC,EAAE;AAC5B,IAAA,IAAI,OAAOJ,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,EAAE;AAC/B;MACA,OAAQE,KAAY,IAAKH,WAAW,CAACC,IAAI,CAAC,CAAC,CAAC,EAASE,KAAK,CAAC,CAAA;AAC7D,KAAC,MAAM;AACLA,MAAAA,KAAK,GAAGF,IAAI,CAAC,C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ACF;;;;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-primitives",
3
- "version": "0.22.0",
3
+ "version": "0.23.0",
4
4
  "description": "Making apps easier to build",
5
5
  "sideEffects": [
6
6
  "*.css"
@@ -19,12 +19,13 @@
19
19
  "dependencies": {
20
20
  "@babel/runtime": "^7.24.1",
21
21
  "@embroider/addon-shim": "^1.8.7",
22
- "@embroider/macros": "1.16.1",
22
+ "@embroider/macros": "1.16.5",
23
23
  "@floating-ui/dom": "^1.5.3",
24
24
  "decorator-transforms": "^2.0.0",
25
25
  "ember-element-helper": ">= 0.8.6",
26
26
  "form-data-utils": "^0.6.0",
27
27
  "reactiveweb": "^1.2.2",
28
+ "should-handle-link": "^1.2.0",
28
29
  "tabster": "^7.1.0",
29
30
  "tracked-built-ins": "^3.2.0",
30
31
  "tracked-toolbox": "^2.0.0"