ember-style-modifier 0.3.0 → 0.6.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/.ember-cli.js ADDED
@@ -0,0 +1,9 @@
1
+ module.exports = {
2
+ /**
3
+ Ember CLI sends analytics information by default. The data is completely
4
+ anonymous, but there are times when you might want to disable this behavior.
5
+
6
+ Setting `disableAnalytics` to true will prevent any data from being sent.
7
+ */
8
+ "disableAnalytics": false
9
+ }
@@ -0,0 +1,14 @@
1
+ {
2
+ "git": {
3
+ "tagName": "v${version}"
4
+ },
5
+ "github": {
6
+ "release": true,
7
+ "tokenRef": "GITHUB_AUTH"
8
+ },
9
+ "plugins": {
10
+ "release-it-lerna-changelog": {
11
+ "infile": "CHANGELOG.md"
12
+ }
13
+ }
14
+ }
package/CHANGELOG.md ADDED
@@ -0,0 +1,69 @@
1
+ ## v0.6.0 (2020-08-03)
2
+
3
+ #### :boom: Breaking Change
4
+ * [#19](https://github.com/jelhan/ember-style-modifier/pull/19) Update ember-modifier to 2.1.0 and drop support for Ember < 3.4 ([@andreyfel](https://github.com/andreyfel))
5
+
6
+ #### Committers: 2
7
+ - Andrey Fel ([@andreyfel](https://github.com/andreyfel))
8
+ - Jeldrik Hanschke ([@jelhan](https://github.com/jelhan))
9
+
10
+ ## v0.5.0 (2019-12-04)
11
+
12
+ #### :boom: Breaking Change
13
+ * [#12](https://github.com/jelhan/ember-style-modifier/pull/12) use public APIs through ember-modifier and upgrade dependencies ([@andreyfel](https://github.com/andreyfel))
14
+
15
+ #### :house: Internal
16
+ * [#14](https://github.com/jelhan/ember-style-modifier/pull/14) automate releases with release-it and lerna-changelog ([@jelhan](https://github.com/jelhan))
17
+ * [#12](https://github.com/jelhan/ember-style-modifier/pull/12) use public APIs through ember-modifier and upgrade dependencies ([@andreyfel](https://github.com/andreyfel))
18
+
19
+ #### Committers: 2
20
+ - Andrey Fel ([@andreyfel](https://github.com/andreyfel))
21
+ - Jeldrik Hanschke ([@jelhan](https://github.com/jelhan))
22
+
23
+
24
+ ## v0.4.1 (2019-03-28)
25
+
26
+ #### :rocket: Enhancement
27
+ * [#10](https://github.com/jelhan/ember-style-modifier/pull/10) better assertion message for wrong value type ([@jelhan](https://github.com/jelhan))
28
+
29
+ #### Committers: 1
30
+ - Jeldrik Hanschke ([@jelhan](https://github.com/jelhan))
31
+
32
+
33
+ ## v0.4.0 (2019-03-18)
34
+
35
+ #### :house: Internal
36
+ * [#8](https://github.com/jelhan/ember-style-modifier/pull/8) refactor: drop ember-functional-modifiers ([@buschtoens](https://github.com/buschtoens))
37
+
38
+ #### Committers: 1
39
+ - Jan Buschtöns ([@buschtoens](https://github.com/buschtoens))
40
+
41
+
42
+ ## v0.3.0 (2019-03-13)
43
+
44
+ #### :rocket: Enhancement
45
+ * [#6](https://github.com/jelhan/ember-style-modifier/pull/6) support setting CSS rules using a POJO ([@jelhan](https://github.com/jelhan))
46
+
47
+ #### Committers: 1
48
+ - Jeldrik Hanschke ([@jelhan](https://github.com/jelhan))
49
+
50
+
51
+ ## v0.2.0 (2019-03-12)
52
+
53
+ #### :boom: Breaking Change
54
+ * [#4](https://github.com/jelhan/ember-style-modifier/pull/4) support a more compact style for declaring CSS rules ([@jelhan](https://github.com/jelhan))
55
+
56
+ #### :rocket: Enhancement
57
+ * [#4](https://github.com/jelhan/ember-style-modifier/pull/4) support a more compact style for declaring CSS rules ([@jelhan](https://github.com/jelhan))
58
+
59
+ #### Committers: 1
60
+ - Jeldrik Hanschke ([@jelhan](https://github.com/jelhan))
61
+
62
+
63
+ ## v0.1.0 (2019-03-11)
64
+
65
+ Initial proof of concept
66
+
67
+ #### Committers: 1
68
+ - Jeldrik Hanschke ([@jelhan](https://github.com/jelhan))
69
+ -
package/README.md CHANGED
@@ -1,27 +1,27 @@
1
- ember-style-modifier
2
- ==============================================================================
1
+ # ember-style-modifier
3
2
 
4
3
  [![Build Status](https://travis-ci.org/jelhan/ember-style-modifier.svg?branch=master)](https://travis-ci.org/jelhan/ember-style-modifier)
4
+ [![Ember Observer Score](http://emberobserver.com/badges/ember-style-modifier.svg)](http://emberobserver.com/addons/ember-style-modifier)
5
+ [![npm version](https://badge.fury.io/js/ember-style-modifier.svg)](https://badge.fury.io/js/ember-style-modifier)
5
6
 
6
7
  This addon provides a `{{style}}` element modifier to set element's style.
7
8
  This allows to set custom CSS of an element without requiring a [Content Security Policy](https://content-security-policy.com/) `style-src-attr: "unsafe-inline"`.
8
9
 
9
- Compatibility
10
- ------------------------------------------------------------------------------
10
+ ## Compatibility
11
11
 
12
- It supports the same versions as [`ember-functional-modifiers`](https://github.com/spencer516/ember-functional-modifiers#compatibility) does.
12
+ * Ember.js v3.4 or above
13
+ * Ember CLI v2.13 or above
14
+ * Node.js v10 or above
13
15
 
14
- Installation
15
- ------------------------------------------------------------------------------
16
+ ## Installation
16
17
 
17
18
  ```sh
18
19
  ember install ember-style-modifier
19
20
  ```
20
21
 
21
- Usage
22
- ------------------------------------------------------------------------------
22
+ ## Usage
23
23
 
24
- It expects CSS declarations as named arguments or as a hash as first positional
24
+ It expects CSS declarations as named arguments or as a hash as positional
25
25
  argument. Property names are supported in dasherized as well as in camelCase
26
26
  spelling. Value must be a string or `undefined`. You may set a priority by
27
27
  adding an `"!important"` suffix.
@@ -32,7 +32,8 @@ adding an `"!important"` suffix.
32
32
  border="1px"
33
33
  padding="1em !important"
34
34
  }}
35
- ></p>
35
+ >
36
+ </p>
36
37
 
37
38
  <p
38
39
  {{style
@@ -42,19 +43,17 @@ adding an `"!important"` suffix.
42
43
  </p>
43
44
  ```
44
45
 
45
- If option hash and named arguments contain CSS declarations for the same
46
- property, named argument wins.
47
-
48
- Attaching style modifier multiple times to the same element is not supported.
46
+ You may pass multiple hashes as positional arguments and combine hashes
47
+ with named arguments. If multiple hashes are passed and contain CSS
48
+ declarations for the same property, last one wins. If hashes and named
49
+ arguments declare same property, named argument wins.
49
50
 
50
51
  Adding styles to pseudo-elements is not supported.
51
52
 
52
- Contributing
53
- ------------------------------------------------------------------------------
53
+ ## Contributing
54
54
 
55
55
  See the [Contributing](CONTRIBUTING.md) guide for details.
56
56
 
57
- License
58
- ------------------------------------------------------------------------------
57
+ ## License
59
58
 
60
59
  This project is licensed under the [MIT License](LICENSE.md).
@@ -1,49 +1,75 @@
1
- import makeFunctionalModifier from 'ember-functional-modifiers';
2
- import { assign } from '@ember/polyfills';
1
+ import Modifier from 'ember-modifier';
3
2
  import { dasherize } from '@ember/string';
4
3
  import { assert } from '@ember/debug';
5
4
  import { typeOf } from '@ember/utils';
6
5
 
7
- // Store holds information which properties were set
8
- // for an element (key) in last run. This allows us
9
- // to clean up properties that were set but aren't
10
- // present in options hash anymore.
11
- const STORE = new WeakMap();
6
+ function isObject(o) {
7
+ return typeof o === 'object' && Boolean(o);
8
+ }
12
9
 
13
- export default makeFunctionalModifier((element, [optionsHash = {}], namedOptions = {}) => {
14
- let options = assign({}, optionsHash, namedOptions);
15
- let properties = [];
10
+ export default class StyleModifier extends Modifier {
11
+ /**
12
+ * Returns a two-dimensional array, like:
13
+ *
14
+ * ```js
15
+ * [
16
+ * ['font-size', '16px'],
17
+ * ['text-align', 'center'],
18
+ * ['color', 'red']
19
+ * ]
20
+ * ```
21
+ *
22
+ * This data structure is slightly faster to process than an object / dictionary.
23
+ */
24
+ get styles() {
25
+ const { positional, named } = this.args;
16
26
 
17
- for (let property in options) {
18
- let value = options[property];
19
- assert(`Value must be a string or undefined, ${typeOf(value)} given`, value === undefined || typeOf(value) === "string");
27
+ // This is a workaround for the missing `Array#flat` in IE11.
28
+ return [].concat(
29
+ ...[...positional.filter(isObject), named].map(obj =>
30
+ Object.entries(obj).map(([k, v]) => [dasherize(k), v])
31
+ )
32
+ );
33
+ }
20
34
 
21
- // priorty must be specified as separate argument
22
- // value must not contain "!important"
23
- let priority = "";
24
- if (value && value.includes("!important")) {
25
- priority = "important";
26
- value = value.replace("!important", "");
27
- }
35
+ setStyles(newStyles) {
36
+ const rulesToRemove = this._oldStyles || new Set();
28
37
 
29
- // support camelCase property name
30
- property = dasherize(property);
38
+ newStyles.forEach(([property, value]) => {
39
+ assert(
40
+ `Your given value for property '${property}' is ${value} (${typeOf(value)}). ` +
41
+ 'Accepted types are string and undefined. Please change accordingly.',
42
+ typeof value === 'undefined' || typeOf(value) === 'string'
43
+ );
31
44
 
32
- element.style.setProperty(property, value, priority);
45
+ // priority must be specified as separate argument
46
+ // value must not contain "!important"
47
+ let priority = '';
48
+ if (value && value.includes('!important')) {
49
+ priority = 'important';
50
+ value = value.replace('!important', '');
51
+ }
33
52
 
34
- properties.push(property);
35
- }
53
+ // support camelCase property name
54
+ property = dasherize(property);
36
55
 
37
- // remove styles that were set in last run but aren't present in this run anymore
38
- if (STORE.has(element)) {
39
- let previousProps = STORE.get(element);
40
- let removedProps = previousProps.filter((_) => !properties.includes(_));
56
+ // update CSSOM
57
+ this.element.style.setProperty(property, value, priority);
41
58
 
42
- removedProps.forEach((prop) => {
43
- element.style.removeProperty(prop);
59
+ // should not remove rules that have been updated in this cycle
60
+ rulesToRemove.delete(property);
44
61
  });
62
+
63
+ // remove rules that were present in last cycle but aren't present in this one
64
+ rulesToRemove.forEach(rule => this.element.style.removeProperty(rule));
65
+
66
+ // cache styles that in this rendering cycle for the next one
67
+ this._oldStyles = new Set(
68
+ newStyles.map(e => e[0])
69
+ );
45
70
  }
46
71
 
47
- // store properties set on element for next run
48
- STORE.set(element, properties);
49
- });
72
+ didReceiveArguments() {
73
+ this.setStyles(this.styles);
74
+ }
75
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "ember-style-modifier",
3
- "version": "0.3.0",
4
- "description": "The default blueprint for ember-cli addons.",
3
+ "version": "0.6.0",
4
+ "description": "{{style}} modifier to set an element's style using the CSSStyleDeclaration API.",
5
5
  "keywords": [
6
6
  "ember-addon"
7
7
  ],
@@ -13,52 +13,62 @@
13
13
  "test": "tests"
14
14
  },
15
15
  "scripts": {
16
- "build": "ember build",
16
+ "build": "ember build --environment=production",
17
+ "lint": "npm-run-all --aggregate-output --continue-on-error --parallel lint:*",
17
18
  "lint:hbs": "ember-template-lint .",
18
19
  "lint:js": "eslint .",
20
+ "release": "release-it",
19
21
  "start": "ember serve",
20
- "test": "ember test",
21
- "test:all": "ember try:each"
22
+ "test": "npm-run-all lint:* test:*",
23
+ "test:ember": "ember test",
24
+ "test:ember-compatibility": "ember try:each"
22
25
  },
23
26
  "dependencies": {
24
- "ember-cli-babel": "^7.1.2",
25
- "ember-functional-modifiers": "^0.2.0"
27
+ "ember-cli-babel": "^7.21.0",
28
+ "ember-modifier": "^2.1.0"
26
29
  },
27
30
  "devDependencies": {
28
- "@ember/optional-features": "^0.6.3",
29
- "broccoli-asset-rev": "^2.7.0",
30
- "ember-cli": "~3.8.1",
31
- "ember-cli-content-security-policy": "^1.1.1",
32
- "ember-cli-dependency-checker": "^3.1.0",
33
- "ember-cli-eslint": "^4.2.3",
34
- "ember-cli-htmlbars": "^3.0.0",
35
- "ember-cli-htmlbars-inline-precompile": "^1.0.3",
36
- "ember-cli-inject-live-reload": "^1.8.2",
37
- "ember-cli-release": "^1.0.0-beta.2",
31
+ "@ember/optional-features": "^1.3.0",
32
+ "@glimmer/component": "^1.0.1",
33
+ "@glimmer/tracking": "^1.0.1",
34
+ "babel-eslint": "^10.1.0",
35
+ "broccoli-asset-rev": "^3.0.0",
36
+ "ember-cli": "~3.20.0",
37
+ "ember-cli-content-security-policy": "^2.0.0-1",
38
+ "ember-cli-dependency-checker": "^3.2.0",
39
+ "ember-cli-htmlbars": "^5.2.0",
40
+ "ember-cli-inject-live-reload": "^2.0.2",
38
41
  "ember-cli-sri": "^2.1.1",
39
- "ember-cli-template-lint": "^1.0.0-beta.1",
40
- "ember-cli-uglify": "^2.1.0",
42
+ "ember-cli-uglify": "^3.0.0",
41
43
  "ember-disable-prototype-extensions": "^1.1.3",
42
- "ember-export-application-global": "^2.0.0",
43
- "ember-load-initializers": "^1.1.0",
44
+ "ember-export-application-global": "^2.0.1",
45
+ "ember-load-initializers": "^2.1.1",
44
46
  "ember-maybe-import-regenerator": "^0.1.6",
45
- "ember-qunit": "^3.4.1",
46
- "ember-resolver": "^5.0.1",
47
- "ember-source": "~3.8.0",
48
- "ember-source-channel-url": "^1.1.0",
49
- "ember-try": "^1.0.0",
50
- "eslint-plugin-ember": "^5.2.0",
51
- "eslint-plugin-node": "^7.0.1",
47
+ "ember-qunit": "^4.6.0",
48
+ "ember-resolver": "^8.0.0",
49
+ "ember-source": "~3.20.2",
50
+ "ember-source-channel-url": "^3.0.0",
51
+ "ember-template-lint": "^2.9.1",
52
+ "ember-try": "^1.4.0",
53
+ "eslint": "^7.5.0",
54
+ "eslint-plugin-ember": "^8.9.1",
55
+ "eslint-plugin-node": "^11.1.0",
52
56
  "loader.js": "^4.7.0",
53
- "qunit-dom": "^0.8.0"
57
+ "npm-run-all": "^4.1.5",
58
+ "qunit-dom": "^1.2.0",
59
+ "release-it": "^13.5.2",
60
+ "release-it-lerna-changelog": "^2.1.2"
54
61
  },
55
62
  "engines": {
56
- "node": "6.* || 8.* || >= 10.*"
63
+ "node": "10.* || >= 12"
64
+ },
65
+ "publishConfig": {
66
+ "registry": "https://registry.npmjs.org"
67
+ },
68
+ "ember": {
69
+ "edition": "octane"
57
70
  },
58
71
  "ember-addon": {
59
72
  "configPath": "tests/dummy/config"
60
- },
61
- "resolutions": {
62
- "qunit": "^2.9.1"
63
73
  }
64
74
  }
package/config/release.js DELETED
@@ -1,21 +0,0 @@
1
- /* jshint node:true */
2
- // var RSVP = require('rsvp');
3
-
4
- // For details on each option run `ember help release`
5
- module.exports = {
6
- // local: true,
7
- // remote: 'some_remote',
8
- // annotation: "Release %@",
9
- // message: "Bumped version to %@",
10
- // manifest: [ 'package.json', 'bower.json', 'someconfig.json' ],
11
- // publish: true,
12
- // strategy: 'date',
13
- // format: 'YYYY-MM-DD',
14
- // timezone: 'America/Los_Angeles',
15
- //
16
- // beforeCommit: function(project, versions) {
17
- // return new RSVP.Promise(function(resolve, reject) {
18
- // // Do custom things here...
19
- // });
20
- // }
21
- };
package/jsconfig.json DELETED
@@ -1 +0,0 @@
1
- {"compilerOptions":{"target":"es6","experimentalDecorators":true},"exclude":["node_modules","bower_components","tmp","vendor",".git","dist"]}