ember-velcro 1.0.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 ADDED
@@ -0,0 +1,36 @@
1
+ # 1.0.0 (2022-09-27)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * cleanup popper ([da193d9](https://github.com/camskene/ember-velcro/commit/da193d97e696d12a2c5ba44f63d1c7a1d09e926c))
7
+ * cleanup ResizeObserver ([5a05ff2](https://github.com/camskene/ember-velcro/commit/5a05ff26fb8981a1ba28401dc66cb80508ffb834))
8
+ * **release:** add semantic release config to package.json ([e3f9ccb](https://github.com/camskene/ember-velcro/commit/e3f9ccbb412d37c095e654fa3857b9b648227709))
9
+ * remove unused dependency ([3fa4854](https://github.com/camskene/ember-velcro/commit/3fa4854505d7309d4f9615eb8281cf05299a5f21))
10
+ * rename offset args ([8fdf4e1](https://github.com/camskene/ember-velcro/commit/8fdf4e18a5737f44211b4ee9a6f09f73678f4dca))
11
+ * update readme and package details ([21dd7f6](https://github.com/camskene/ember-velcro/commit/21dd7f6744be5efa5708c8e476e9266b1eb1f5d6))
12
+ * update to Ember v4.6.0 ([a529ef0](https://github.com/camskene/ember-velcro/commit/a529ef09a9370f974304b8e9debf1880eb5ffe7b))
13
+
14
+
15
+ * feat!: add velcro modifier ([4724a30](https://github.com/camskene/ember-velcro/commit/4724a30e4f3326a3909efede31124cc3cced2862))
16
+
17
+
18
+ ### Features
19
+
20
+ * add modifiers, strategy, and onFirstUpdate to args ([0a12c39](https://github.com/camskene/ember-velcro/commit/0a12c3948fdebe59388d1c25b129a1b199efc465))
21
+ * add offsetX, offsetY, and placement to args ([0dfa444](https://github.com/camskene/ember-velcro/commit/0dfa4440063a0e2d6ee74fd0ceb42879c92630ce))
22
+ * add options for flip and shift middleware ([2229496](https://github.com/camskene/ember-velcro/commit/2229496be892572a0953ab113541f0eda490787d))
23
+ * add velcro component ([b5e6f31](https://github.com/camskene/ember-velcro/commit/b5e6f313a38b0eb359bdc7d5d6ce96d38295c6f1))
24
+ * basic demo ([1484983](https://github.com/camskene/ember-velcro/commit/148498338e5eac273eb2f16da0f7a72e68152a1e))
25
+ * create popper and yield modifiers ([50cc8bc](https://github.com/camskene/ember-velcro/commit/50cc8bc2118ea1202ad24f200b957d728fab2b51))
26
+ * handle targetElement or popoverElement resize ([1398f89](https://github.com/camskene/ember-velcro/commit/1398f89a9586b901248e85490a6427df67a4e50c))
27
+ * migrate from popperjs to floating-ui ([06d6e90](https://github.com/camskene/ember-velcro/commit/06d6e90cd706159b6b189d644d0bc8a65229c5c4))
28
+
29
+
30
+ ### BREAKING CHANGES
31
+
32
+ * arguments to middleware are now composed of the
33
+ middleware name + 'Options'.
34
+
35
+ eg `@offset` -> `@offsetOptions`
36
+ * https://floating-ui.com/docs/migration
package/LICENSE.md ADDED
@@ -0,0 +1,9 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,106 @@
1
+ Ember Velcro
2
+ ==============================================================================
3
+
4
+ Ember Velcro sticks one element to another with [Floating UI](https://floating-ui.com/), it can be used as a modifier or a component.
5
+
6
+ Several of Floating UI's functions and [middleware](https://floating-ui.com/docs/middleware) are used to create an experience out of the box that is useful and expected.
7
+
8
+ See Floating UI's [documentation](https://floating-ui.com/docs/getting-started) for more information on any of the following included functionality.
9
+
10
+ Functions:
11
+
12
+ [computePosition](https://floating-ui.com/docs/computePosition) - computes the x and y coordinates needed to anchor a floating element to a reference element.
13
+
14
+ [autoUpdate](https://floating-ui.com/docs/autoUpdate) - updates the x and y coordinates of the floating element so it remains anchored to the reference element when the page scrolls or when either the reference or floating elements are resized.
15
+
16
+ Middleware:
17
+
18
+ [offset](https://floating-ui.com/docs/offset) - the first of the middleware included; allows you to offset the floating element from the reference element by a given amount.
19
+
20
+ [flip](https://floating-ui.com/docs/flip) - flips the floating element to the opposite side of the reference element to keep it in view.
21
+
22
+ [shift](https://floating-ui.com/docs/shift) - shifts the floating element along the x or y axis to keep it in view
23
+ * x-axis for 'top' and 'bottom' placements
24
+ * y-axis for 'left' and 'right' placements
25
+
26
+ [hide](https://floating-ui.com/docs/hide) - hides the floating element when the reference element is no longer visible or when the floating element has escaped the reference element's clipping context.
27
+
28
+
29
+ API
30
+ ------------------------------------------------------------------------------
31
+
32
+ * `@flipOptions` - see [flip docs](https://floating-ui.com/docs/flip) for option values
33
+ * `@middleware` - array of one or more objects to add to the [middleware](https://floating-ui.com/docs/middleware) array
34
+ * `@offsetOptions` - see [offset docs](https://floating-ui.com/docs/offset) for option values
35
+ * `@placement` - list of [expected values](https://floating-ui.com/docs/computeposition#placement)
36
+ * `@shiftOptions` - see [shift docs](https://floating-ui.com/docs/shift) for option values
37
+ * `@strategy` - CSS position property, either 'fixed' or 'absolute'. Pros and cons of each strategy is [here](https://floating-ui.com/docs/computePosition#strategy)
38
+
39
+
40
+ Default values
41
+ ------------------------------------------------------------------------------
42
+
43
+ * `@placement`: 'bottom'
44
+ * `@strategy`: 'fixed'
45
+ * `offset`, `flip`, and `shift` middleware all use their defaults.
46
+ * `hide` middleware uses both `referenceHidden` and `escaped` [options](https://floating-ui.com/docs/hide#options).
47
+
48
+ Usage as Modifier
49
+ ------------------------------------------------------------------------------
50
+
51
+ ```hbs
52
+ <div id="hook">The `reference` element (the hook)</div>
53
+ <div {{velcro "#hook"}}>The `floating` element (the loop)</div>
54
+ ```
55
+
56
+ Usage as Component
57
+ ------------------------------------------------------------------------------
58
+
59
+ The `Velcro` component yields a single hash - 2 modifiers and 'velcro data':
60
+
61
+ ```hbs
62
+ <Velcro as |velcro|>
63
+ <div {{velcro.hook}}>Velcro hook</div>
64
+ <div {{velcro.loop}}>Velcro loop stuck to Velcro hook!</div>
65
+ {{log "velcro data" velcro.data}}
66
+ </Velcro>
67
+ ```
68
+
69
+ `velcro.data` is the `MiddlewareArguments` object, it contains the following values:
70
+
71
+ * x
72
+ * y
73
+ * initialPlacement
74
+ * placement
75
+ * strategy
76
+ * middlewareData
77
+ * rects
78
+ * platform
79
+ * elements
80
+
81
+ See [MiddlewareArguments](https://floating-ui.com/docs/middleware#middlewarearguments) for a description of each.
82
+
83
+ Compatibility
84
+ ------------------------------------------------------------------------------
85
+
86
+ * Ember.js v3.20 or above
87
+ * Ember CLI v3.20 or above
88
+ * Node.js v14 or above
89
+
90
+
91
+ Installation
92
+ ------------------------------------------------------------------------------
93
+
94
+ ```
95
+ ember install github:camskene/ember-velcro
96
+ ```
97
+
98
+ Contributing
99
+ ------------------------------------------------------------------------------
100
+
101
+ Ember Velcro is currently written primarily for my own fun and education.
102
+
103
+ License
104
+ ------------------------------------------------------------------------------
105
+
106
+ This project is licensed under the [MIT License](LICENSE.md).
@@ -0,0 +1,16 @@
1
+ {{yield (hash
2
+ hook=this.velcroHook
3
+ loop=(if this.hook (modifier this.velcroLoop
4
+ this.hook
5
+ flipOptions=@flipOptions
6
+ hideOptions=@hideOptions
7
+ middleware=@middleware
8
+ offsetOptions=@offsetOptions
9
+ placement=@placement
10
+ shiftOptions=@shiftOptions
11
+ strategy=@strategy
12
+ setVelcroData=this.setVelcroData
13
+ ))
14
+ data=this.velcroData
15
+ )}}
16
+
@@ -0,0 +1,23 @@
1
+ import Component from '@glimmer/component';
2
+ import { tracked } from '@glimmer/tracking';
3
+
4
+ import { modifier } from 'ember-modifier';
5
+ import VelcroModifier from 'ember-velcro/modifiers/velcro';
6
+
7
+ export default class VelcroComponent extends Component {
8
+ @tracked hook = undefined;
9
+
10
+ // set by VelcroModifier
11
+ @tracked velcroData = undefined;
12
+
13
+ setVelcroData = (data) => (this.velcroData = data);
14
+
15
+ velcroHook = modifier(
16
+ (element) => {
17
+ this.hook = element;
18
+ },
19
+ { eager: false }
20
+ );
21
+
22
+ velcroLoop = VelcroModifier;
23
+ }
@@ -0,0 +1,11 @@
1
+ export function velcroData() {
2
+ return {
3
+ name: 'metadata',
4
+ fn: (data) => {
5
+ // https://floating-ui.com/docs/middleware#always-return-an-object
6
+ return {
7
+ data,
8
+ };
9
+ },
10
+ };
11
+ }
@@ -0,0 +1,71 @@
1
+ import { assert } from '@ember/debug';
2
+ import { registerDestructor } from '@ember/destroyable';
3
+
4
+ import { autoUpdate, computePosition, flip, hide, offset, shift } from '@floating-ui/dom';
5
+ import Modifier from 'ember-modifier';
6
+ import { velcroData } from 'ember-velcro/middleware/velcro-data';
7
+
8
+ export default class VelcroModifier extends Modifier {
9
+ modify(
10
+ floatingElement,
11
+ [referenceElement],
12
+ {
13
+ strategy = 'fixed',
14
+ offsetOptions = 0,
15
+ placement = 'bottom',
16
+ flipOptions,
17
+ shiftOptions,
18
+ middleware = [],
19
+ setVelcroData,
20
+ }
21
+ ) {
22
+ if (typeof referenceElement === 'string') {
23
+ referenceElement = document.querySelector(referenceElement);
24
+ }
25
+
26
+ assert('no reference element defined', referenceElement instanceof HTMLElement);
27
+
28
+ assert('no floating element defined', floatingElement instanceof HTMLElement);
29
+
30
+ assert(
31
+ 'reference and floating elements cannot be the same element',
32
+ floatingElement !== referenceElement
33
+ );
34
+
35
+ assert('@middleware must be an array of one or more objects', Array.isArray(middleware));
36
+
37
+ Object.assign(floatingElement.style, {
38
+ position: strategy,
39
+ top: '0',
40
+ left: '0',
41
+ });
42
+
43
+ let update = async () => {
44
+ let { x, y, middlewareData } = await computePosition(referenceElement, floatingElement, {
45
+ middleware: [
46
+ offset(offsetOptions),
47
+ flip(flipOptions),
48
+ shift(shiftOptions),
49
+ ...middleware,
50
+ hide({ strategy: 'referenceHidden' }),
51
+ hide({ strategy: 'escaped' }),
52
+ velcroData(),
53
+ ],
54
+ placement,
55
+ strategy,
56
+ });
57
+
58
+ Object.assign(floatingElement.style, {
59
+ strategy,
60
+ transform: `translate3d(${Math.round(x)}px, ${Math.round(y)}px, 0)`,
61
+ visibility: middlewareData.hide.referenceHidden ? 'hidden' : 'visible',
62
+ });
63
+
64
+ setVelcroData?.(middlewareData.metadata);
65
+ };
66
+
67
+ let cleanup = autoUpdate(referenceElement, floatingElement, update);
68
+
69
+ registerDestructor(this, cleanup);
70
+ }
71
+ }
@@ -0,0 +1 @@
1
+ export { default } from 'ember-velcro/components/velcro';
@@ -0,0 +1 @@
1
+ export { default } from 'ember-velcro/modifiers/velcro';
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * The goal of commitlint in this repo is not to enforce
5
+ * eerily similar commit messages across comitters, but
6
+ * to give juuust enough enformation for automated releasing.
7
+ *
8
+ * Beyond major/minor/patch indicators, most of the commit
9
+ * message's conventions are irrelevant, and should instead be
10
+ * focused on content / release notes.
11
+ *
12
+ * And for contributors to the repository, following convential commits
13
+ * is not needed. The maintainer of ember-headless-table merging a PR
14
+ * can specify chore/feat/fix/breaking in the merge commit in the GitHub
15
+ * UI.
16
+ */
17
+ module.exports = {
18
+ extends: ['@commitlint/config-conventional'],
19
+ // https://commitlint.js.org/#/reference-rules
20
+ // Level [0..2]: 0 disables the rule. For 1 it will be considered a warning for 2 an error.
21
+ // Applicable always|never: never inverts the rule.
22
+ // Value: value to use for this rule.
23
+ rules: {
24
+ // 72, the default, is a little short
25
+ 'header-max-length': [1, 'always', 100],
26
+ // Let people use caps
27
+ 'header-case': [0],
28
+ // Let people write sentences
29
+ 'header-full-stop': [0],
30
+ // Casing doesn't really matter
31
+ 'subject-case': [0],
32
+ },
33
+ };
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ module.exports = function (/* environment, appConfig */) {
4
+ return {};
5
+ };
package/index.js ADDED
@@ -0,0 +1,5 @@
1
+ 'use strict';
2
+
3
+ module.exports = {
4
+ name: require('./package').name,
5
+ };
package/package.json ADDED
@@ -0,0 +1,110 @@
1
+ {
2
+ "name": "ember-velcro",
3
+ "version": "1.0.0",
4
+ "description": "Ember Velcro sticks one element to another with Floating UI.",
5
+ "keywords": [
6
+ "ember-addon"
7
+ ],
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://camskene@github.com/camskene/ember-velcro.git"
11
+ },
12
+ "license": "MIT",
13
+ "author": "Cam Skene",
14
+ "directories": {
15
+ "test": "tests"
16
+ },
17
+ "scripts": {
18
+ "build": "ember build --environment=production",
19
+ "lint": "npm-run-all --aggregate-output --continue-on-error --parallel \"lint:!(fix)\"",
20
+ "lint:fix": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*:fix",
21
+ "lint:hbs": "ember-template-lint .",
22
+ "lint:hbs:fix": "ember-template-lint . --fix",
23
+ "lint:js": "eslint . --cache",
24
+ "lint:js:fix": "eslint . --fix",
25
+ "start": "ember serve",
26
+ "test": "npm-run-all lint test:*",
27
+ "test:ember": "ember test",
28
+ "test:ember-compatibility": "ember try:each"
29
+ },
30
+ "dependencies": {
31
+ "@floating-ui/dom": "^1.0.1",
32
+ "ember-auto-import": "^2.4.2",
33
+ "ember-cli-babel": "^7.26.11",
34
+ "ember-cli-htmlbars": "^6.1.0",
35
+ "ember-modifier": "^3.2.7"
36
+ },
37
+ "devDependencies": {
38
+ "@ember/optional-features": "^2.0.0",
39
+ "@ember/test-helpers": "^2.8.1",
40
+ "@embroider/test-setup": "^1.8.3",
41
+ "@glimmer/component": "^1.1.2",
42
+ "@glimmer/tracking": "^1.1.2",
43
+ "@nullvoxpopuli/eslint-configs": "^2.2.58",
44
+ "@semantic-release/changelog": "^6.0.0",
45
+ "@semantic-release/git": "^10.0.0",
46
+ "babel-eslint": "^10.1.0",
47
+ "broccoli-asset-rev": "^3.0.0",
48
+ "ember-cli": "~4.7.0",
49
+ "ember-cli-dependency-checker": "^3.3.1",
50
+ "ember-cli-inject-live-reload": "^2.1.0",
51
+ "ember-cli-postcss": "^8.2.0",
52
+ "ember-cli-sri": "^2.1.1",
53
+ "ember-cli-terser": "^4.0.2",
54
+ "ember-disable-prototype-extensions": "^1.1.3",
55
+ "ember-functions-as-helper-polyfill": "^2.1.1",
56
+ "ember-load-initializers": "^2.1.2",
57
+ "ember-page-title": "^7.0.0",
58
+ "ember-qunit": "^5.1.5",
59
+ "ember-resolver": "^8.0.3",
60
+ "ember-source": "~4.7.0",
61
+ "ember-source-channel-url": "^3.0.0",
62
+ "ember-template-lint": "^4.10.1",
63
+ "ember-try": "^2.0.0",
64
+ "eslint": "^7.0.0",
65
+ "eslint-config-prettier": "^8.5.0",
66
+ "eslint-plugin-decorator-position": "^5.0.1",
67
+ "eslint-plugin-ember": "^11.0.2",
68
+ "eslint-plugin-import": "^2.26.0",
69
+ "eslint-plugin-node": "^11.1.0",
70
+ "eslint-plugin-prettier": "^4.2.1",
71
+ "eslint-plugin-qunit": "^7.3.1",
72
+ "loader.js": "^4.7.0",
73
+ "npm-run-all": "^4.1.5",
74
+ "prettier": "^2.7.1",
75
+ "qunit": "^2.19.1",
76
+ "qunit-console-grouper": "^0.3.0",
77
+ "qunit-dom": "^2.0.0",
78
+ "semantic-release": "^19.0.0",
79
+ "tailwindcss": "^3.1.8",
80
+ "webpack": "^5.74.0"
81
+ },
82
+ "engines": {
83
+ "node": "14.* || >= 16"
84
+ },
85
+ "ember": {
86
+ "edition": "octane"
87
+ },
88
+ "ember-addon": {
89
+ "configPath": "tests/dummy/config"
90
+ },
91
+ "release": {
92
+ "branches": [
93
+ "main",
94
+ "master"
95
+ ],
96
+ "plugins": [
97
+ "@semantic-release/commit-analyzer",
98
+ "@semantic-release/release-notes-generator",
99
+ "@semantic-release/changelog",
100
+ "@semantic-release/npm",
101
+ "@semantic-release/github",
102
+ "@semantic-release/git"
103
+ ]
104
+ },
105
+ "main": "index.js",
106
+ "bugs": {
107
+ "url": "https://github.com/camskene/ember-velcro/issues"
108
+ },
109
+ "homepage": "https://github.com/camskene/ember-velcro#readme"
110
+ }
@@ -0,0 +1,12 @@
1
+ /** @type {import('tailwindcss').Config} */
2
+
3
+ module.exports = {
4
+ content: ['./tests/**/app/**/*.hbs'],
5
+ theme: {
6
+ extend: {},
7
+ },
8
+ plugins: [],
9
+ ...(process.env.EMBER_ENV == 'development' && {
10
+ safelist: [{ pattern: /.*/ }],
11
+ }),
12
+ };