ember-primitives 0.45.0 → 0.46.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 +1 @@
1
- {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/components/heading.gts"],"names":[],"mappings":"AAoKA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAK3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAyHtC,qBAAa,OAAQ,SAAQ,SAAS,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE;QAAE,OAAO,EAAE,EAAE,CAAA;KAAE,CAAC;CACzB,CAAC;IACA,kBAAkB,EAAE,IAAI,CAAC;gBACb,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;IAMtC,IAAI,KAAK,WAWR;IAED,IAAI,MAAM,WAET;CAqBF"}
1
+ {"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../src/components/heading.gts"],"names":[],"mappings":"AAoCA,OAAO,SAAS,MAAM,oBAAoB,CAAC;AAK3C,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,qBAAa,OAAQ,SAAQ,SAAS,CAAC;IACrC,OAAO,EAAE,WAAW,CAAC;IACrB,MAAM,EAAE;QAAE,OAAO,EAAE,EAAE,CAAA;KAAE,CAAC;CACzB,CAAC;IACA,kBAAkB,EAAE,IAAI,CAAC;gBACb,KAAK,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM;IAMtC,IAAI,KAAK,WAER;IAED,IAAI,MAAM,WAET;CAqBF"}
@@ -105,4 +105,4 @@ export declare class Rating extends Component<Signature> {
105
105
  get isReadonly(): boolean;
106
106
  get needsDescription(): boolean;
107
107
  }
108
- //# sourceMappingURL=index.d.ts.map
108
+ //# sourceMappingURL=rating.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rating.d.ts","sourceRoot":"","sources":["../../../src/components/rating/rating.gts"],"names":[],"mappings":"A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,GAAG,cAAc,CAAC,CAAC;aACrF;SACF,CAAC;QACF,KAAK,EAAE;YACL,KAAK,EAAE;gBACL;;mBAEG;gBACH,KAAK,EAAE,MAAM,CAAC;gBAEd;;mBAEG;gBACH,KAAK,EAAE,MAAM,CAAC;aACf;SACF,CAAC;KACH,CAAC;CACH;AAED,qBAAa,MAAO,SAAQ,SAAS,CAAC,SAAS,CAAC;IAC9C,IAAI,SAA0B;IAE9B,IAAI,IAAI;;;;;;;;OAEP;IAED,IAAI,aAAa,YAEhB;IAED,IAAI,YAAY,YAIf;IAED,IAAI,UAAU,YAEb;IAED,IAAI,gBAAgB,YAEnB;CAgFF"}
@@ -1,4 +1,4 @@
1
- export { Rating } from './rating/index';
1
+ export { Rating } from './rating/rating';
2
2
  import type { ComponentIcons } from "./rating/public-types.ts";
3
3
  export type IconType = ComponentIcons["icon"];
4
4
  //# sourceMappingURL=rating.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"rating.d.ts","sourceRoot":"","sources":["../../src/components/rating.gts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAE5C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC"}
1
+ {"version":3,"file":"rating.d.ts","sourceRoot":"","sources":["../../src/components/rating.gts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAE7C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAE/D,MAAM,MAAM,QAAQ,GAAG,cAAc,CAAC,MAAM,CAAC,CAAC"}
@@ -1,3 +1,23 @@
1
+ /**
2
+ * A QUnit test utility for setting up the tabbing utility that a few of the components in ember-primitive use for providing enhanced keyboard support.
3
+ *
4
+ * ```gjs
5
+ * import { module, test } from 'qunit';
6
+ * import { setupRenderingTest } from 'ember-qunit';
7
+ * import { setupTabster } from 'ember-primitives/test-support';
8
+ *
9
+ * module('your suite', function (hooks) {
10
+ * setupRenderingTest(hooks);
11
+ * setupTabster(hooks);
12
+ *
13
+ * test('your test', async function (assert) {
14
+ * // ...
15
+ * });
16
+ * });
17
+ * ```
18
+ *
19
+ * This utility takes no options.
20
+ */
1
21
  export declare function setupTabster(hooks: {
2
22
  beforeEach: (callback: () => void | Promise<void>) => unknown;
3
23
  }): void;
@@ -1 +1 @@
1
- {"version":3,"file":"a11y.d.ts","sourceRoot":"","sources":["../../src/test-support/a11y.ts"],"names":[],"mappings":"AAgBA,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC;CAC/D,QAWA"}
1
+ {"version":3,"file":"a11y.d.ts","sourceRoot":"","sources":["../../src/test-support/a11y.ts"],"names":[],"mappings":"AAgBA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE;IAClC,UAAU,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC;CAC/D,QAWA"}
@@ -1,14 +1,82 @@
1
1
  import { find } from '@ember/test-helpers';
2
2
  type Findable = Parameters<typeof find>[0] | Element;
3
3
  /**
4
- * Find an element within a shadow-root.
4
+ * Find an element within a given element that has a shadow-root.
5
+ *
6
+ * If the `root` can't be found, or if there actually is no shadow root,
7
+ * nothing will be returned.
8
+ *
9
+ * ```gjs
10
+ * import { findInShadow } from 'ember-primitives/test-support';
11
+ *
12
+ * // ...
13
+ *
14
+ * test('...', async function (assert) {
15
+ * // ...
16
+ * const root = find('div.with-shadowdom');
17
+ * assert.dom(findInShadow(root, 'h1')).containsText('welcome');
18
+ * });
19
+ * ```
5
20
  */
6
21
  export declare function findInShadow(root: Findable, query: string): Element | null | undefined;
7
22
  /**
8
23
  * Does the element have a shadow root?
24
+ *
25
+ * Using this utility function will only save a few characters over using its implementation directly.
26
+ *
27
+ * ```gjs
28
+ * import { hasShadowRoot } from 'ember-primitives/test-support';
29
+ *
30
+ * // ...
31
+ *
32
+ * test('...', async function (assert) {
33
+ * // ...
34
+ * const el = find('div.with-shadowdom');
35
+ * assert.ok(hasShadowRoot(el), 'expecting el to have a shadow root');
36
+ * });
37
+ * ```
9
38
  */
10
39
  export declare function hasShadowRoot(el: Element): boolean;
40
+ /**
41
+ * Find an element within `root`, that has a shadow root.
42
+ * The `root` param is optional, and if not provided, all of `#ember-testing` will be searched.
43
+ *
44
+ * This only returns the first-found shadow, so if you want a specifc shadow root,
45
+ * you'll need to narrow down the search by specifying a `root`.
46
+ *
47
+ * ```gjs
48
+ * import { findShadow } from 'ember-primitives/test-support';
49
+ *
50
+ * // ...
51
+ *
52
+ * test('...', async function (assert) {
53
+ * // ...
54
+ * const el = findShadow('div.with-shadowdom');
55
+ * // ...
56
+ * });
57
+ * ```
58
+ */
11
59
  export declare function findShadow(root?: Findable): Element | undefined;
60
+ /**
61
+ * For the first available shadow root on the page, query in to it, like you would with `querySelector`.
62
+ *
63
+ *
64
+ * ```gjs
65
+ * import { findInFirstShadow } from 'ember-primitives/test-support';
66
+ *
67
+ * // ...
68
+ *
69
+ * test('...', async function (assert) {
70
+ * // ...
71
+ * assert.dom(findInFirstShadow('h1')).containsText('welcome');
72
+ * });
73
+ * ```
74
+ *
75
+ * If there are multiple shadow roots on the page / test-render,
76
+ * this is not the utility for you.
77
+ *
78
+ * For querying in specific shadow roots, you'll want to use `findInShadow`
79
+ */
12
80
  export declare function findInFirstShadow(query: string): Element | null | undefined;
13
81
  export {};
14
82
  //# sourceMappingURL=dom.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/test-support/dom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAErD;;GAEG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,8BAIzD;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,WAExC;AAED,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,uBAczC;AAED,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,8BAM9C"}
1
+ {"version":3,"file":"dom.d.ts","sourceRoot":"","sources":["../../src/test-support/dom.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAE3C,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC;AAErD;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,8BAIzD;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,OAAO,WAExC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,UAAU,CAAC,IAAI,CAAC,EAAE,QAAQ,uBAczC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,8BAM9C"}
@@ -1,4 +1,17 @@
1
1
  /**
2
+ * Fill the OTP input
3
+ *
4
+ * ```gjs
5
+ * import { fillOTP } from 'ember-primitives/test-support';
6
+ *
7
+ * test('...', async function(assert) {
8
+ * // ...
9
+ * await fillOTP('123456');
10
+ * // ...
11
+ * })
12
+ *
13
+ * ```
14
+ *
2
15
  * @param {string} code the code to fill the input(s) with.
3
16
  * @param {string} [ selector ] if there are multiple OTP components on a page, this can be used to select one of them.
4
17
  */
@@ -1 +1 @@
1
- {"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../src/test-support/otp.ts"],"names":[],"mappings":"AAGA;;;GAGG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,iBA2C5D"}
1
+ {"version":3,"file":"otp.d.ts","sourceRoot":"","sources":["../../src/test-support/otp.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAsB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,iBA2C5D"}
@@ -28,5 +28,8 @@ import type RouterService from '@ember/routing/router-service';
28
28
  export declare function setupRouting(owner: Owner, map: DSLCallback, options?: {
29
29
  rootURL: string;
30
30
  }): void;
31
+ /**
32
+ * A small utility that only gives you a _typed_ router service.
33
+ */
31
34
  export declare function getRouter(owner: Owner): RouterService;
32
35
  //# sourceMappingURL=routing.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/test-support/routing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,QAqBzF;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAErD"}
1
+ {"version":3,"file":"routing.d.ts","sourceRoot":"","sources":["../../src/test-support/routing.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AACtC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,aAAa,MAAM,+BAA+B,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,QAqBzF;AAED;;GAEG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,CAErD"}
@@ -1,83 +1,10 @@
1
1
 
2
2
  import Component from '@glimmer/component';
3
- import { assert } from '@ember/debug';
4
3
  import { element } from 'ember-element-helper';
4
+ import { getSectionHeadingLevel } from 'which-heading-do-i-need';
5
5
  import { precompileTemplate } from '@ember/template-compilation';
6
6
  import { setComponentTemplate } from '@ember/component';
7
7
 
8
- const LOOKUP = new WeakMap();
9
- const BOUNDARY_ELEMENTS = new Set(["SECTION", "ARTICLE", "ASIDE", "HEADER", "FOOTER", "MAIN", "NAV"]);
10
- /**
11
- * A set with both cases is more performant than calling toLowerCase
12
- */
13
- const SECTION_HEADINGS = new Set(["h1", "h2", "h3", "h4", "h5", "h6", "H1", "H2", "H3", "H4", "H5", "H6"]);
14
- const TEST_BOUNDARY = "ember-testing";
15
- function isRoot(element) {
16
- return element === document.body || element.id === TEST_BOUNDARY;
17
- }
18
- /**
19
- * The Platform native 'closest' function can't punch through shadow-boundaries
20
- */
21
- function nearestAncestor(node, matcher) {
22
- let parent = node.parentElement;
23
- if (!parent) return;
24
- while (parent) {
25
- if (parent instanceof Element) {
26
- if (matcher(parent)) return parent;
27
- }
28
- if (parent instanceof ShadowRoot) {
29
- parent = parent.host;
30
- }
31
- parent = parent.parentNode;
32
- }
33
- }
34
- /**
35
- * The algorithm:
36
- *
37
- * section <- "our" level-changing boundary element
38
- * h# <- the element we want to figure out the level of
39
- *
40
- * We start assuming we'll emit an h1.
41
- * We adjust this based on what we find crawling up the tree.
42
- *
43
- * While traversing up, when we go from the h# to the section,
44
- * and ignore it. Because this alone has no bearing on if the h# should be an h2.
45
- * We need to continue traversing upwards, until we hit the next boundary element.
46
- *
47
- * IF we would change the level the heading, we will find another heading between
48
- * these two boundary elements.
49
- * We'll need to check the subtrees between these elements, stopping if we
50
- * encounter other boundary elements.
51
- *
52
- */
53
- function levelOf(node) {
54
- const ourBoundary = nearestAncestor(node, el => BOUNDARY_ELEMENTS.has(el.tagName));
55
- /**
56
- * We are the top-level
57
- */
58
- if (!ourBoundary) {
59
- return 1;
60
- }
61
- const stopAt = nearestAncestor(ourBoundary, el => {
62
- if (BOUNDARY_ELEMENTS.has(el.tagName)) return true;
63
- return isRoot(el);
64
- });
65
- assert(`[BUG]: Could not find a stopping boundary for automatic heading level detection. Checked for ${[...BOUNDARY_ELEMENTS, "body", "#ember-testing"].map(x => x.toLowerCase()).join(", ")}`, stopAt);
66
- let current = ourBoundary.parentNode;
67
- while (current) {
68
- for (const child of current.children) {
69
- if (!SECTION_HEADINGS.has(child.tagName)) continue;
70
- const level = parseInt(child.tagName.replace("h", "").replace("H", ""));
71
- return level + 1;
72
- }
73
- if (current === stopAt) break;
74
- if (current instanceof ShadowRoot) {
75
- current = current.host;
76
- }
77
- current = current.parentNode;
78
- }
79
- return 1;
80
- }
81
8
  class Heading extends Component {
82
9
  headingScopeAnchor;
83
10
  constructor(owner, args) {
@@ -85,12 +12,7 @@ class Heading extends Component {
85
12
  this.headingScopeAnchor = document.createTextNode("");
86
13
  }
87
14
  get level() {
88
- const existing = LOOKUP.get(this.headingScopeAnchor);
89
- if (existing) return existing;
90
- const parentLevel = levelOf(this.headingScopeAnchor);
91
- const myLevel = parentLevel;
92
- LOOKUP.set(this.headingScopeAnchor, myLevel);
93
- return myLevel;
15
+ return getSectionHeadingLevel(this.headingScopeAnchor);
94
16
  }
95
17
  get hLevel() {
96
18
  return `h${this.level}`;
@@ -1,3 +1,3 @@
1
1
 
2
- export { R as Rating } from '../index-D052JWRa.js';
2
+ export { R as Rating } from '../rating-D052JWRa.js';
3
3
  //# sourceMappingURL=rating.js.map
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ export { Popover } from './components/popover.js';
14
14
  export { Portal } from './components/portal.js';
15
15
  export { TARGETS as PORTALS, PortalTargets } from './components/portal-targets.js';
16
16
  export { Progress } from './components/progress.js';
17
- export { R as Rating } from './index-D052JWRa.js';
17
+ export { R as Rating } from './rating-D052JWRa.js';
18
18
  export { Scroller } from './components/scroller.js';
19
19
  export { Shadowed } from './components/shadowed.js';
20
20
  export { Switch } from './components/switch.js';
@@ -146,4 +146,4 @@ class Rating extends Component {
146
146
  }
147
147
 
148
148
  export { Rating as R };
149
- //# sourceMappingURL=index-D052JWRa.js.map
149
+ //# sourceMappingURL=rating-D052JWRa.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rating-D052JWRa.js","sources":[],"sourcesContent":[],"names":[],"mappings":""}
@@ -16,6 +16,27 @@ async function setup(owner) {
16
16
  });
17
17
  document.querySelector('#ember-testing')?.setAttribute('data-tabster', '{ "root": {} }');
18
18
  }
19
+
20
+ /**
21
+ * A QUnit test utility for setting up the tabbing utility that a few of the components in ember-primitive use for providing enhanced keyboard support.
22
+ *
23
+ * ```gjs
24
+ * import { module, test } from 'qunit';
25
+ * import { setupRenderingTest } from 'ember-qunit';
26
+ * import { setupTabster } from 'ember-primitives/test-support';
27
+ *
28
+ * module('your suite', function (hooks) {
29
+ * setupRenderingTest(hooks);
30
+ * setupTabster(hooks);
31
+ *
32
+ * test('your test', async function (assert) {
33
+ * // ...
34
+ * });
35
+ * });
36
+ * ```
37
+ *
38
+ * This utility takes no options.
39
+ */
19
40
  function setupTabster(hooks) {
20
41
  hooks.beforeEach(async function () {
21
42
  const owner = this.owner;
@@ -25,7 +46,22 @@ function setupTabster(hooks) {
25
46
  }
26
47
 
27
48
  /**
28
- * Find an element within a shadow-root.
49
+ * Find an element within a given element that has a shadow-root.
50
+ *
51
+ * If the `root` can't be found, or if there actually is no shadow root,
52
+ * nothing will be returned.
53
+ *
54
+ * ```gjs
55
+ * import { findInShadow } from 'ember-primitives/test-support';
56
+ *
57
+ * // ...
58
+ *
59
+ * test('...', async function (assert) {
60
+ * // ...
61
+ * const root = find('div.with-shadowdom');
62
+ * assert.dom(findInShadow(root, 'h1')).containsText('welcome');
63
+ * });
64
+ * ```
29
65
  */
30
66
  function findInShadow(root, query) {
31
67
  const rootElement = root instanceof Element ? root : find(root);
@@ -34,10 +70,44 @@ function findInShadow(root, query) {
34
70
 
35
71
  /**
36
72
  * Does the element have a shadow root?
73
+ *
74
+ * Using this utility function will only save a few characters over using its implementation directly.
75
+ *
76
+ * ```gjs
77
+ * import { hasShadowRoot } from 'ember-primitives/test-support';
78
+ *
79
+ * // ...
80
+ *
81
+ * test('...', async function (assert) {
82
+ * // ...
83
+ * const el = find('div.with-shadowdom');
84
+ * assert.ok(hasShadowRoot(el), 'expecting el to have a shadow root');
85
+ * });
86
+ * ```
37
87
  */
38
88
  function hasShadowRoot(el) {
39
89
  return Boolean(el.shadowRoot);
40
90
  }
91
+
92
+ /**
93
+ * Find an element within `root`, that has a shadow root.
94
+ * The `root` param is optional, and if not provided, all of `#ember-testing` will be searched.
95
+ *
96
+ * This only returns the first-found shadow, so if you want a specifc shadow root,
97
+ * you'll need to narrow down the search by specifying a `root`.
98
+ *
99
+ * ```gjs
100
+ * import { findShadow } from 'ember-primitives/test-support';
101
+ *
102
+ * // ...
103
+ *
104
+ * test('...', async function (assert) {
105
+ * // ...
106
+ * const el = findShadow('div.with-shadowdom');
107
+ * // ...
108
+ * });
109
+ * ```
110
+ */
41
111
  function findShadow(root) {
42
112
  const rootElement = root ? root instanceof Element ? root : find(root) : document.getElementById('ember-testing');
43
113
  if (!rootElement) return;
@@ -47,6 +117,27 @@ function findShadow(root) {
47
117
  }
48
118
  }
49
119
  }
120
+
121
+ /**
122
+ * For the first available shadow root on the page, query in to it, like you would with `querySelector`.
123
+ *
124
+ *
125
+ * ```gjs
126
+ * import { findInFirstShadow } from 'ember-primitives/test-support';
127
+ *
128
+ * // ...
129
+ *
130
+ * test('...', async function (assert) {
131
+ * // ...
132
+ * assert.dom(findInFirstShadow('h1')).containsText('welcome');
133
+ * });
134
+ * ```
135
+ *
136
+ * If there are multiple shadow roots on the page / test-render,
137
+ * this is not the utility for you.
138
+ *
139
+ * For querying in specific shadow roots, you'll want to use `findInShadow`
140
+ */
50
141
  function findInFirstShadow(query) {
51
142
  const host = findShadow();
52
143
  assert(`No element with a shadow root could be found`, host);
@@ -54,6 +145,19 @@ function findInFirstShadow(query) {
54
145
  }
55
146
 
56
147
  /**
148
+ * Fill the OTP input
149
+ *
150
+ * ```gjs
151
+ * import { fillOTP } from 'ember-primitives/test-support';
152
+ *
153
+ * test('...', async function(assert) {
154
+ * // ...
155
+ * await fillOTP('123456');
156
+ * // ...
157
+ * })
158
+ *
159
+ * ```
160
+ *
57
161
  * @param {string} code the code to fill the input(s) with.
58
162
  * @param {string} [ selector ] if there are multiple OTP components on a page, this can be used to select one of them.
59
163
  */
@@ -209,6 +313,10 @@ function setupRouting(owner, map, options) {
209
313
  // eslint-disable-next-line @typescript-eslint/no-unsafe-call, @typescript-eslint/no-unsafe-member-access
210
314
  iKnowWhatIMDoing.setupRouter();
211
315
  }
316
+
317
+ /**
318
+ * A small utility that only gives you a _typed_ router service.
319
+ */
212
320
  function getRouter(owner) {
213
321
  return owner.lookup('service:router');
214
322
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-primitives",
3
- "version": "0.45.0",
3
+ "version": "0.46.0",
4
4
  "description": "Making apps easier to build",
5
5
  "keywords": [
6
6
  "ember-addon"
@@ -25,7 +25,8 @@
25
25
  "should-handle-link": "^1.2.2",
26
26
  "tabster": "^8.5.5",
27
27
  "tracked-built-ins": "^4.0.0",
28
- "tracked-toolbox": "^2.0.0"
28
+ "tracked-toolbox": "^2.0.0",
29
+ "which-heading-do-i-need": "0.1.0"
29
30
  },
30
31
  "devDependencies": {
31
32
  "@arethetypesw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