@empathyco/x-archetype-utils 2.0.0-alpha.6 → 2.0.0-alpha.8

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.
@@ -3,7 +3,7 @@
3
3
  const rollupCssInjectorConfig = {
4
4
  replace: {
5
5
  // Replace X CSS injector by our custom one.
6
- 'export default injectCss;': 'export default (css) => window.xCSSInjector.addStyle({ source: css });',
6
+ 'export default injectCss': 'export default (css) => window.xCSSInjector.addStyle({ source: css });',
7
7
  delimiters: ['', ''],
8
8
  },
9
9
  styles: {
@@ -28,21 +28,19 @@ class CssInjector {
28
28
  return instance;
29
29
  }
30
30
  /**
31
- * Adds the styles to the host element.
31
+ * Adds the style to the host element.
32
32
  *
33
- * @param styles - The styles to be added.
34
- * @param styles.source - Styles source.
33
+ * @param style - The styles to be added.
34
+ * @param style.source - Styles source.
35
35
  */
36
- addStyle(styles) {
37
- this.stylesQueue.push(styles.source);
38
- if (this.host) {
39
- this.stylesQueue.forEach(styles => {
40
- const styleTag = document.createElement('style');
41
- styleTag.textContent = styles;
42
- this.host.appendChild(styleTag);
43
- });
44
- this.stylesQueue = [];
36
+ addStyle(style) {
37
+ if (!this.host) {
38
+ this.stylesQueue.push(style);
39
+ return;
45
40
  }
41
+ const styleTag = document.createElement('style');
42
+ styleTag.textContent = style.source;
43
+ this.host.appendChild(styleTag);
46
44
  }
47
45
  /**
48
46
  * Sets the host element.
@@ -51,6 +49,9 @@ class CssInjector {
51
49
  */
52
50
  setHost(host) {
53
51
  this.host = host;
52
+ // Add all pending styles to the host element
53
+ this.stylesQueue.forEach(style => this.addStyle(style));
54
+ this.stylesQueue = [];
54
55
  }
55
56
  /**
56
57
  * Sets the injector instance in the window object.
@@ -1,7 +1,7 @@
1
1
  const rollupCssInjectorConfig = {
2
2
  replace: {
3
3
  // Replace X CSS injector by our custom one.
4
- 'export default injectCss;': 'export default (css) => window.xCSSInjector.addStyle({ source: css });',
4
+ 'export default injectCss': 'export default (css) => window.xCSSInjector.addStyle({ source: css });',
5
5
  delimiters: ['', ''],
6
6
  },
7
7
  styles: {
@@ -26,21 +26,19 @@ class CssInjector {
26
26
  return instance;
27
27
  }
28
28
  /**
29
- * Adds the styles to the host element.
29
+ * Adds the style to the host element.
30
30
  *
31
- * @param styles - The styles to be added.
32
- * @param styles.source - Styles source.
31
+ * @param style - The styles to be added.
32
+ * @param style.source - Styles source.
33
33
  */
34
- addStyle(styles) {
35
- this.stylesQueue.push(styles.source);
36
- if (this.host) {
37
- this.stylesQueue.forEach(styles => {
38
- const styleTag = document.createElement('style');
39
- styleTag.textContent = styles;
40
- this.host.appendChild(styleTag);
41
- });
42
- this.stylesQueue = [];
34
+ addStyle(style) {
35
+ if (!this.host) {
36
+ this.stylesQueue.push(style);
37
+ return;
43
38
  }
39
+ const styleTag = document.createElement('style');
40
+ styleTag.textContent = style.source;
41
+ this.host.appendChild(styleTag);
44
42
  }
45
43
  /**
46
44
  * Sets the host element.
@@ -49,6 +47,9 @@ class CssInjector {
49
47
  */
50
48
  setHost(host) {
51
49
  this.host = host;
50
+ // Add all pending styles to the host element
51
+ this.stylesQueue.forEach(style => this.addStyle(style));
52
+ this.stylesQueue = [];
52
53
  }
53
54
  /**
54
55
  * Sets the injector instance in the window object.
@@ -1,6 +1,6 @@
1
1
  export declare const rollupCssInjectorConfig: {
2
2
  replace: {
3
- 'export default injectCss;': string;
3
+ 'export default injectCss': string;
4
4
  delimiters: string[];
5
5
  };
6
6
  styles: {
@@ -1,12 +1,18 @@
1
1
  import type { XCSSInjector } from './css-injector.types';
2
+ /**
3
+ * The style interface that will be used to inject styles into the host element.
4
+ */
5
+ interface Style {
6
+ source: string;
7
+ }
2
8
  /**
3
9
  * Custom CSS injector that allows to inject styles into a host element.
4
10
  *
5
11
  * @public
6
12
  */
7
13
  export declare class CssInjector implements XCSSInjector {
8
- protected host: Element | ShadowRoot;
9
- protected stylesQueue: string[];
14
+ protected host: Element | ShadowRoot | undefined;
15
+ protected stylesQueue: Style[];
10
16
  /**
11
17
  * Initializes the instance of the injector if it's not already initialized and sets it in the
12
18
  * window object if it's required.
@@ -15,14 +21,12 @@ export declare class CssInjector implements XCSSInjector {
15
21
  */
16
22
  constructor(setInWindow?: boolean);
17
23
  /**
18
- * Adds the styles to the host element.
24
+ * Adds the style to the host element.
19
25
  *
20
- * @param styles - The styles to be added.
21
- * @param styles.source - Styles source.
26
+ * @param style - The styles to be added.
27
+ * @param style.source - Styles source.
22
28
  */
23
- addStyle(styles: {
24
- source: string;
25
- }): void;
29
+ addStyle(style: Style): void;
26
30
  /**
27
31
  * Sets the host element.
28
32
  *
@@ -46,3 +50,4 @@ export declare class CssInjector implements XCSSInjector {
46
50
  * @public
47
51
  */
48
52
  export declare const cssInjector: CssInjector;
53
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@empathyco/x-archetype-utils",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "Utilities for x-archetype",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "dependencies": {
47
47
  "@empathyco/x-deep-merge": "^2.0.3-alpha.4",
48
- "@empathyco/x-utils": "^1.0.3-alpha.2",
48
+ "@empathyco/x-utils": "^1.0.3-alpha.3",
49
49
  "tslib": "~2.6.0",
50
50
  "vue-i18n": "~9.14.0"
51
51
  },
@@ -66,5 +66,5 @@
66
66
  "publishConfig": {
67
67
  "access": "public"
68
68
  },
69
- "gitHead": "2dee976ba7a42a12e786176f541899185d852c5a"
69
+ "gitHead": "e685bba8473fff3c3456fb3176c5a4411353b9b2"
70
70
  }