ember-container-query 2.0.0 → 2.1.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/CHANGELOG.md CHANGED
@@ -1,3 +1,47 @@
1
+ ## 2.1.0 (2022-06-03)
2
+
3
+ ### Enhancement
4
+ * [#119](https://github.com/ijlee2/ember-container-query/pull/119) Introduced TypeScript (Part 3) ([@ijlee2](https://github.com/ijlee2))
5
+
6
+ ### Internal
7
+ * [#123](https://github.com/ijlee2/ember-container-query/pull/123) Updated GitHub actions to v3 ([@ijlee2](https://github.com/ijlee2))
8
+ * [#122](https://github.com/ijlee2/ember-container-query/pull/122) Updated Node version in CI to 16 ([@ijlee2](https://github.com/ijlee2))
9
+ * [#121](https://github.com/ijlee2/ember-container-query/pull/121) Updated ember-on-resize-modifier to v1.1.0 ([@ijlee2](https://github.com/ijlee2))
10
+ * [#117](https://github.com/ijlee2/ember-container-query/pull/117) Updated dependencies to their latest version ([@ijlee2](https://github.com/ijlee2))
11
+ * [#115](https://github.com/ijlee2/ember-container-query/pull/115) Updated eslint to v8 ([@ijlee2](https://github.com/ijlee2))
12
+
13
+ ### Documentation
14
+ * [#120](https://github.com/ijlee2/ember-container-query/pull/120) Introduced TypeScript (Part 4) ([@ijlee2](https://github.com/ijlee2))
15
+ * [#118](https://github.com/ijlee2/ember-container-query/pull/118) Introduced TypeScript (Part 2) ([@ijlee2](https://github.com/ijlee2))
16
+ * [#114](https://github.com/ijlee2/ember-container-query/pull/114) Introduced TypeScript (Part 1) ([@ijlee2](https://github.com/ijlee2))
17
+ * [#116](https://github.com/ijlee2/ember-container-query/pull/116) Updated demo app ([@ijlee2](https://github.com/ijlee2))
18
+
19
+ ### Committers: 1
20
+ - Isaac Lee ([@ijlee2](https://github.com/ijlee2))
21
+
22
+
23
+ ## 2.0.2 (2022-04-25)
24
+
25
+ ### Bug Fix
26
+ * [#113](https://github.com/ijlee2/ember-container-query/pull/113) Removed named exports for helpers ([@ijlee2](https://github.com/ijlee2))
27
+
28
+ ### Committers: 1
29
+ - Isaac Lee ([@ijlee2](https://github.com/ijlee2))
30
+
31
+
32
+ ## 2.0.1 (2022-04-25)
33
+
34
+ ### Bug Fix
35
+ * [#111](https://github.com/ijlee2/ember-container-query/pull/111) Added named exports for helpers ([@ijlee2](https://github.com/ijlee2))
36
+
37
+ ### Documentation
38
+ * [#112](https://github.com/ijlee2/ember-container-query/pull/112) Enabled ember-beta scenario ([@ijlee2](https://github.com/ijlee2))
39
+ * [#110](https://github.com/ijlee2/ember-container-query/pull/110) Refactored <Ui::Form> components in the demo app ([@ijlee2](https://github.com/ijlee2))
40
+
41
+ ### Committers: 1
42
+ - Isaac Lee ([@ijlee2](https://github.com/ijlee2))
43
+
44
+
1
45
  ## 2.0.0 (2022-04-09)
2
46
 
3
47
  ### Breaking Change
@@ -3,28 +3,49 @@ import Component from '@glimmer/component';
3
3
  import { tracked } from '@glimmer/tracking';
4
4
  import { debounce } from '@ember/runloop';
5
5
 
6
- export default class ContainerQueryComponent extends Component {
7
- @tracked queryResults = {};
8
- @tracked aspectRatio;
9
- @tracked height;
10
- @tracked width;
6
+ type Metadata = {
7
+ dimension: 'aspectRatio' | 'height' | 'width';
8
+ max: number;
9
+ min: number;
10
+ };
11
+
12
+ type Features = {
13
+ [featureName: string]: Metadata;
14
+ };
15
+
16
+ type QueryResults = {
17
+ [featureName: string]: boolean;
18
+ };
19
+
20
+ interface ContainerQueryComponentArgs {
21
+ dataAttributePrefix?: string;
22
+ debounce?: number;
23
+ features?: Features;
24
+ tagName?: string;
25
+ }
26
+
27
+ export default class ContainerQueryComponent extends Component<ContainerQueryComponentArgs> {
28
+ @tracked queryResults = {} as QueryResults;
29
+ @tracked aspectRatio?: number;
30
+ @tracked height?: number;
31
+ @tracked width?: number;
11
32
 
12
- get features() {
33
+ get features(): Features {
13
34
  return this.args.features ?? {};
14
35
  }
15
36
 
16
- get dataAttributePrefix() {
37
+ get dataAttributePrefix(): string {
17
38
  return this.args.dataAttributePrefix ?? 'container-query';
18
39
  }
19
40
 
20
- get debounce() {
41
+ get debounce(): number {
21
42
  return this.args.debounce ?? 0;
22
43
  }
23
44
 
24
45
  // The dynamic tag is restricted to be immutable
25
46
  tagName = this.args.tagName ?? 'div';
26
47
 
27
- @action onResize(resizeObserverEntry) {
48
+ @action onResize(resizeObserverEntry: ResizeObserverEntry): void {
28
49
  const element = resizeObserverEntry.target;
29
50
 
30
51
  if (this.debounce > 0) {
@@ -35,24 +56,24 @@ export default class ContainerQueryComponent extends Component {
35
56
  this.queryContainer(element);
36
57
  }
37
58
 
38
- @action queryContainer(element) {
59
+ @action queryContainer(element: Element): void {
39
60
  this.measureDimensions(element);
40
61
  this.evaluateQueries();
41
62
  this.setDataAttributes(element);
42
63
  }
43
64
 
44
- measureDimensions(element) {
65
+ measureDimensions(element: Element): void {
45
66
  this.height = element.clientHeight;
46
67
  this.width = element.clientWidth;
47
68
  this.aspectRatio = this.width / this.height;
48
69
  }
49
70
 
50
- evaluateQueries() {
51
- const queryResults = {};
71
+ evaluateQueries(): void {
72
+ const queryResults = {} as QueryResults;
52
73
 
53
74
  for (const [featureName, metadata] of Object.entries(this.features)) {
54
75
  const { dimension, min, max } = metadata;
55
- const value = this[dimension];
76
+ const value = this[dimension]!;
56
77
 
57
78
  queryResults[featureName] = min <= value && value < max;
58
79
  }
@@ -60,7 +81,7 @@ export default class ContainerQueryComponent extends Component {
60
81
  this.queryResults = queryResults;
61
82
  }
62
83
 
63
- setDataAttributes(element) {
84
+ setDataAttributes(element: Element): void {
64
85
  const prefix = this.dataAttributePrefix;
65
86
 
66
87
  for (const [featureName, meetsFeature] of Object.entries(
@@ -0,0 +1,20 @@
1
+ import { helper } from '@ember/component/helper';
2
+
3
+ type Metadata = {
4
+ dimension: 'aspectRatio' | 'height' | 'width';
5
+ max: number;
6
+ min: number;
7
+ };
8
+
9
+ function cqAspectRatio(
10
+ positional: unknown[],
11
+ named: Record<string, unknown>
12
+ ): Metadata {
13
+ const dimension = 'aspectRatio';
14
+ const max = (named['max'] as number | undefined) ?? Infinity;
15
+ const min = (named['min'] as number | undefined) ?? 0;
16
+
17
+ return { dimension, max, min };
18
+ }
19
+
20
+ export default helper(cqAspectRatio);
@@ -0,0 +1,20 @@
1
+ import { helper } from '@ember/component/helper';
2
+
3
+ type Metadata = {
4
+ dimension: 'aspectRatio' | 'height' | 'width';
5
+ max: number;
6
+ min: number;
7
+ };
8
+
9
+ function cqHeight(
10
+ positional: unknown[],
11
+ named: Record<string, unknown>
12
+ ): Metadata {
13
+ const dimension = 'height';
14
+ const max = (named['max'] as number | undefined) ?? Infinity;
15
+ const min = (named['min'] as number | undefined) ?? 0;
16
+
17
+ return { dimension, max, min };
18
+ }
19
+
20
+ export default helper(cqHeight);
@@ -0,0 +1,20 @@
1
+ import { helper } from '@ember/component/helper';
2
+
3
+ type Metadata = {
4
+ dimension: 'aspectRatio' | 'height' | 'width';
5
+ max: number;
6
+ min: number;
7
+ };
8
+
9
+ function cqWidth(
10
+ positional: unknown[],
11
+ named: Record<string, unknown>
12
+ ): Metadata {
13
+ const dimension = 'width';
14
+ const max = (named['max'] as number | undefined) ?? Infinity;
15
+ const min = (named['min'] as number | undefined) ?? 0;
16
+
17
+ return { dimension, max, min };
18
+ }
19
+
20
+ export default helper(cqWidth);
@@ -1,4 +1 @@
1
- export {
2
- default,
3
- cqAspectRatio,
4
- } from 'ember-container-query/helpers/cq-aspect-ratio';
1
+ export { default } from 'ember-container-query/helpers/cq-aspect-ratio';
@@ -1 +1 @@
1
- export { default, cqHeight } from 'ember-container-query/helpers/cq-height';
1
+ export { default } from 'ember-container-query/helpers/cq-height';
@@ -1 +1 @@
1
- export { default, cqWidth } from 'ember-container-query/helpers/cq-width';
1
+ export { default } from 'ember-container-query/helpers/cq-width';
@@ -0,0 +1,35 @@
1
+ import Component from '@glimmer/component';
2
+ declare type Metadata = {
3
+ dimension: 'aspectRatio' | 'height' | 'width';
4
+ max: number;
5
+ min: number;
6
+ };
7
+ declare type Features = {
8
+ [featureName: string]: Metadata;
9
+ };
10
+ declare type QueryResults = {
11
+ [featureName: string]: boolean;
12
+ };
13
+ interface ContainerQueryComponentArgs {
14
+ dataAttributePrefix?: string;
15
+ debounce?: number;
16
+ features?: Features;
17
+ tagName?: string;
18
+ }
19
+ export default class ContainerQueryComponent extends Component<ContainerQueryComponentArgs> {
20
+ queryResults: QueryResults;
21
+ aspectRatio?: number;
22
+ height?: number;
23
+ width?: number;
24
+ get features(): Features;
25
+ get dataAttributePrefix(): string;
26
+ get debounce(): number;
27
+ tagName: string;
28
+ onResize(resizeObserverEntry: ResizeObserverEntry): void;
29
+ queryContainer(element: Element): void;
30
+ measureDimensions(element: Element): void;
31
+ evaluateQueries(): void;
32
+ setDataAttributes(element: Element): void;
33
+ }
34
+ export {};
35
+ //# sourceMappingURL=container-query.d.ts.map
@@ -0,0 +1,14 @@
1
+ declare type Metadata = {
2
+ dimension: 'aspectRatio' | 'height' | 'width';
3
+ max: number;
4
+ min: number;
5
+ };
6
+ declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
7
+ Args: {
8
+ Positional: unknown[];
9
+ Named: Record<string, unknown>;
10
+ };
11
+ Return: Metadata;
12
+ }>;
13
+ export default _default;
14
+ //# sourceMappingURL=cq-aspect-ratio.d.ts.map
@@ -0,0 +1,14 @@
1
+ declare type Metadata = {
2
+ dimension: 'aspectRatio' | 'height' | 'width';
3
+ max: number;
4
+ min: number;
5
+ };
6
+ declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
7
+ Args: {
8
+ Positional: unknown[];
9
+ Named: Record<string, unknown>;
10
+ };
11
+ Return: Metadata;
12
+ }>;
13
+ export default _default;
14
+ //# sourceMappingURL=cq-height.d.ts.map
@@ -0,0 +1,14 @@
1
+ declare type Metadata = {
2
+ dimension: 'aspectRatio' | 'height' | 'width';
3
+ max: number;
4
+ min: number;
5
+ };
6
+ declare const _default: import("@ember/component/helper").FunctionBasedHelper<{
7
+ Args: {
8
+ Positional: unknown[];
9
+ Named: Record<string, unknown>;
10
+ };
11
+ Return: Metadata;
12
+ }>;
13
+ export default _default;
14
+ //# sourceMappingURL=cq-width.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ember-container-query",
3
- "version": "2.0.0",
3
+ "version": "2.1.0",
4
4
  "description": "Container queries using Ember modifiers",
5
5
  "keywords": [
6
6
  "container-queries",
@@ -31,8 +31,11 @@
31
31
  "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
32
32
  "lint:hbs": "ember-template-lint .",
33
33
  "lint:hbs:fix": "ember-template-lint . --fix",
34
- "lint:js": "eslint . --cache",
34
+ "lint:js": "eslint . --cache --ext=.js,.ts",
35
35
  "lint:js:fix": "eslint . --fix",
36
+ "lint:types": "tsc --noEmit",
37
+ "prepack": "ember ts:precompile",
38
+ "postpack": "ember ts:clean",
36
39
  "start": "ember serve",
37
40
  "test": "DEVICE='w3-h3' ember test",
38
41
  "test:ember": "ember test",
@@ -52,28 +55,53 @@
52
55
  "@ember/render-modifiers": "^2.0.4",
53
56
  "ember-cli-babel": "^7.26.11",
54
57
  "ember-cli-htmlbars": "^6.0.1",
55
- "ember-element-helper": "^0.6.0",
56
- "ember-on-resize-modifier": "^1.0.0"
58
+ "ember-cli-typescript": "^5.1.0",
59
+ "ember-element-helper": "^0.6.1",
60
+ "ember-on-resize-modifier": "^1.1.0"
57
61
  },
58
62
  "devDependencies": {
59
63
  "@ember/optional-features": "^2.0.0",
60
- "@ember/test-helpers": "^2.7.0",
61
- "@embroider/test-setup": "^1.6.0",
62
- "@glimmer/component": "^1.1.1",
63
- "@glimmer/tracking": "^1.1.1",
64
- "@percy/cli": "^1.0.5",
64
+ "@ember/test-helpers": "^2.8.1",
65
+ "@embroider/test-setup": "^1.7.1",
66
+ "@glimmer/component": "^1.1.2",
67
+ "@glimmer/tracking": "^1.1.2",
68
+ "@percy/cli": "^1.2.1",
65
69
  "@percy/ember": "^3.0.0",
66
- "babel-eslint": "^10.1.0",
70
+ "@types/ember-qunit": "^5.0.0",
71
+ "@types/ember-resolver": "^5.0.11",
72
+ "@types/ember__application": "^4.0.0",
73
+ "@types/ember__array": "^4.0.1",
74
+ "@types/ember__component": "^4.0.8",
75
+ "@types/ember__controller": "^4.0.0",
76
+ "@types/ember__debug": "^4.0.1",
77
+ "@types/ember__engine": "^4.0.0",
78
+ "@types/ember__error": "^4.0.0",
79
+ "@types/ember__object": "^4.0.2",
80
+ "@types/ember__polyfills": "^4.0.0",
81
+ "@types/ember__routing": "^4.0.7",
82
+ "@types/ember__runloop": "^4.0.1",
83
+ "@types/ember__service": "^4.0.0",
84
+ "@types/ember__string": "^3.0.9",
85
+ "@types/ember__template": "^4.0.0",
86
+ "@types/ember__test": "^4.0.0",
87
+ "@types/ember__test-helpers": "^2.6.1",
88
+ "@types/ember__utils": "^4.0.0",
89
+ "@types/htmlbars-inline-precompile": "^3.0.0",
90
+ "@types/qunit": "^2.19.0",
91
+ "@types/rsvp": "^4.0.4",
92
+ "@typescript-eslint/eslint-plugin": "^5.27.0",
93
+ "@typescript-eslint/parser": "^5.27.0",
67
94
  "broccoli-asset-rev": "^3.0.0",
68
- "d3-array": "^3.1.5",
95
+ "d3-array": "^3.1.6",
69
96
  "d3-axis": "^3.0.0",
70
97
  "d3-scale": "^4.0.2",
71
98
  "d3-selection": "^3.0.0",
72
99
  "d3-shape": "^3.1.0",
100
+ "ember-a11y-refocus": "^2.3.0",
73
101
  "ember-a11y-testing": "^5.0.0",
74
- "ember-auto-import": "^2.4.1",
75
- "ember-cli": "~4.3.0",
76
- "ember-cli-dependency-checker": "^3.3.0",
102
+ "ember-auto-import": "^2.4.2",
103
+ "ember-cli": "~4.4.0",
104
+ "ember-cli-dependency-checker": "^3.3.1",
77
105
  "ember-cli-dependency-lint": "^2.0.1",
78
106
  "ember-cli-inject-live-reload": "^2.1.0",
79
107
  "ember-cli-netlify": "^0.4.1",
@@ -83,28 +111,30 @@
83
111
  "ember-disable-prototype-extensions": "^1.1.3",
84
112
  "ember-export-application-global": "^2.0.1",
85
113
  "ember-load-initializers": "^2.1.2",
114
+ "ember-named-blocks-polyfill": "^0.2.5",
86
115
  "ember-page-title": "^7.0.0",
87
116
  "ember-qunit": "^5.1.5",
88
117
  "ember-resolver": "^8.0.3",
89
- "ember-source": "~4.3.0",
118
+ "ember-source": "~4.4.0",
90
119
  "ember-source-channel-url": "^3.0.0",
91
120
  "ember-svg-jar": "^2.3.4",
92
- "ember-template-lint": "^4.3.0",
121
+ "ember-template-lint": "^4.10.0",
93
122
  "ember-test-selectors": "^6.0.0",
94
123
  "ember-truth-helpers": "^3.0.0",
95
124
  "ember-try": "^2.0.0",
96
- "eslint": "^7.32.0",
125
+ "eslint": "^8.16.0",
97
126
  "eslint-config-prettier": "^8.5.0",
98
- "eslint-plugin-ember": "^10.6.0",
127
+ "eslint-plugin-ember": "^10.6.1",
99
128
  "eslint-plugin-node": "^11.1.0",
100
129
  "eslint-plugin-prettier": "^4.0.0",
101
130
  "lerna-changelog": "^2.2.0",
102
131
  "loader.js": "^4.7.0",
103
132
  "npm-run-all": "^4.1.5",
104
133
  "prettier": "^2.6.2",
105
- "qunit": "^2.18.1",
134
+ "qunit": "^2.19.1",
106
135
  "qunit-dom": "^2.0.0",
107
- "webpack": "^5.72.0"
136
+ "typescript": "^4.7.2",
137
+ "webpack": "^5.73.0"
108
138
  },
109
139
  "engines": {
110
140
  "node": "12.* || 14.* || >= 16"
package/tsconfig.json ADDED
@@ -0,0 +1,104 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ES2020",
5
+ "moduleResolution": "node",
6
+
7
+ // Trying to check Ember apps and addons with `allowJs: true` is a recipe
8
+ // for many unresolveable type errors, because with *considerable* extra
9
+ // configuration it ends up including many files which are *not* valid and
10
+ // cannot be: they *appear* to be resolve-able to TS, but are in fact not in
11
+ // valid Node-resolveable locations and may not have TS-ready types. This
12
+ // will likely improve over time
13
+ "allowJs": false,
14
+
15
+ // Don't check the types of dependencies
16
+ "skipLibCheck": true,
17
+
18
+ // --- TS for SemVer Types compatibility
19
+ // Strictness settings -- you should *not* change these: Ember code is not
20
+ // guaranteed to type check with these set to looser values.
21
+ "strict": true,
22
+ "noUncheckedIndexedAccess": true,
23
+
24
+ // Interop: these are viral and will require anyone downstream of your
25
+ // package to *also* set them to true. If you *must* enable them to consume
26
+ // an upstream package, you should document that for downstream consumers to
27
+ // be aware of.
28
+ //
29
+ // These *are* safe for apps to enable, since they do not *have* downstream
30
+ // consumers; but leaving them off is still preferred when possible, since
31
+ // it makes it easier to switch between apps and addons and have the same
32
+ // rules for what can be imported and how.
33
+ "allowSyntheticDefaultImports": false,
34
+ "esModuleInterop": false,
35
+
36
+ // --- Lint-style rules
37
+
38
+ // TypeScript also supplies some lint-style checks; nearly all of them are
39
+ // better handled by ESLint with the `@typescript-eslint`. This one is more
40
+ // like a safety check, though, so we leave it on.
41
+ "noPropertyAccessFromIndexSignature": true,
42
+
43
+ // --- Compilation/integration settings
44
+ // Setting `noEmitOnError` here allows ember-cli-typescript to catch errors
45
+ // and inject them into Ember CLI's build error reporting, which provides
46
+ // nice feedback for when
47
+ "noEmitOnError": false,
48
+
49
+ // We use Babel for emitting runtime code, because it's very important that
50
+ // we always and only use the same transpiler for non-stable features, in
51
+ // particular decorators. If you were to change this to `true`, it could
52
+ // lead to accidentally generating code with `tsc` instead of Babel, and
53
+ // could thereby result in broken code at runtime.
54
+ "noEmit": true,
55
+
56
+ // Ember makes heavy use of decorators; TS does not support them at all
57
+ // without this flag.
58
+ "experimentalDecorators": true,
59
+
60
+ // Support generation of source maps. Note: you must *also* enable source
61
+ // maps in your `ember-cli-babel` config and/or `babel.config.js`.
62
+ "declaration": true,
63
+ "declarationMap": true,
64
+ "inlineSourceMap": true,
65
+ "inlineSources": true,
66
+
67
+ // The combination of `baseUrl` with `paths` allows Ember's classic package
68
+ // layout, which is not resolveable with the Node resolution algorithm, to
69
+ // work with TypeScript.
70
+ "baseUrl": ".",
71
+ "paths": {
72
+ "dummy/tests/*": [
73
+ "tests/*"
74
+ ],
75
+ "dummy/*": [
76
+ "tests/dummy/app/*",
77
+ "app/*"
78
+ ],
79
+ "ember-container-query": [
80
+ "addon"
81
+ ],
82
+ "ember-container-query/*": [
83
+ "addon/*"
84
+ ],
85
+ "ember-container-query/test-support": [
86
+ "addon-test-support"
87
+ ],
88
+ "ember-container-query/test-support/*": [
89
+ "addon-test-support/*"
90
+ ],
91
+ "*": [
92
+ "types/*"
93
+ ]
94
+ }
95
+ },
96
+ "include": [
97
+ "app/**/*",
98
+ "addon/**/*",
99
+ "tests/**/*",
100
+ "types/**/*",
101
+ "test-support/**/*",
102
+ "addon-test-support/**/*"
103
+ ]
104
+ }
File without changes
@@ -0,0 +1,6 @@
1
+ // Types for compiled templates
2
+ declare module 'ember-container-query/templates/*' {
3
+ import { TemplateFactory } from 'htmlbars-inline-precompile';
4
+ const tmpl: TemplateFactory;
5
+ export default tmpl;
6
+ }
@@ -1,8 +0,0 @@
1
- import { helper } from '@ember/component/helper';
2
-
3
- export default helper(function cqAspectRatio(params, hash) {
4
- const dimension = 'aspectRatio';
5
- const { min = 0, max = Infinity } = hash;
6
-
7
- return { dimension, min, max };
8
- });
@@ -1,8 +0,0 @@
1
- import { helper } from '@ember/component/helper';
2
-
3
- export default helper(function cqHeight(params, hash) {
4
- const dimension = 'height';
5
- const { min = 0, max = Infinity } = hash;
6
-
7
- return { dimension, min, max };
8
- });
@@ -1,8 +0,0 @@
1
- import { helper } from '@ember/component/helper';
2
-
3
- export default helper(function cqWidth(params, hash) {
4
- const dimension = 'width';
5
- const { min = 0, max = Infinity } = hash;
6
-
7
- return { dimension, min, max };
8
- });