@empathyco/x-archetype-utils 2.0.0-alpha.2 → 2.0.0-alpha.21

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,47 +1,59 @@
1
- import { XCSSInjector } from './css-injector.types';
2
- /**
3
- * Custom CSS injector that allows to inject styles into a host element.
4
- *
5
- * @public
6
- */
7
- export declare class CssInjector implements XCSSInjector {
8
- protected host: Element | ShadowRoot;
9
- protected stylesQueue: string[];
10
- /**
11
- * Initializes the instance of the injector if it's not already initialized and sets it in the
12
- * window object if it's required.
13
- *
14
- * @param setInWindow - Whether to set the injector instance in the window object.
15
- */
16
- constructor(setInWindow?: boolean);
17
- /**
18
- * Adds the styles to the host element.
19
- *
20
- * @param styles - The styles to be added.
21
- */
22
- addStyle(styles: {
23
- source: string;
24
- }): void;
25
- /**
26
- * Sets the host element.
27
- *
28
- * @param host - The host element.
29
- */
30
- setHost(host: Element | ShadowRoot): void;
31
- /**
32
- * Sets the injector instance in the window object.
33
- */
34
- setInWindow(): void;
35
- /**
36
- * Checks if the injector instance is in the window object.
37
- *
38
- * @returns Whether the injector instance is in the window object.
39
- */
40
- isInWindow(): boolean;
41
- }
42
- /**
43
- * Instance of the injector.
44
- *
45
- * @public
46
- */
47
- export declare const cssInjector: CssInjector;
1
+ import type { Style, XCSSInjector } from './css-injector.types';
2
+ /**
3
+ * Custom CSS injector that allows to inject styles into a host element.
4
+ *
5
+ * @public
6
+ */
7
+ export declare class CssInjector implements XCSSInjector {
8
+ protected hosts: Set<ShadowRoot | Document>;
9
+ protected stylesToAdopt: CSSStyleSheet[];
10
+ /**
11
+ * Initializes the instance of the injector if it's not already initialized and sets it in the
12
+ * window object if it's required.
13
+ *
14
+ * @param setInWindow - Whether to set the injector instance in the window object.
15
+ */
16
+ constructor(setInWindow?: boolean);
17
+ /**
18
+ * Adds the style to the host element.
19
+ *
20
+ * @param style - The styles to be added.
21
+ * @param style.source - Styles source.
22
+ */
23
+ addStyle(style: Style): void;
24
+ /**
25
+ * Sets the host element. Alias of addHost method.
26
+ *
27
+ * @param host - The host element.
28
+ * @deprecated Use addHost instead.
29
+ */
30
+ setHost(host: Element | ShadowRoot): void;
31
+ /**
32
+ * Adds the element to the hosts set.
33
+ *
34
+ * @param host - The host element.
35
+ */
36
+ addHost(host: Document | ShadowRoot): void;
37
+ /**
38
+ * Removes the element from the hosts set.
39
+ *
40
+ * @param host - The host element to remove.
41
+ */
42
+ removeHost(host: Document | ShadowRoot): void;
43
+ /**
44
+ * Sets the injector instance in the window object.
45
+ */
46
+ setInWindow(): void;
47
+ /**
48
+ * Checks if the injector instance is in the window object.
49
+ *
50
+ * @returns Whether the injector instance is in the window object.
51
+ */
52
+ isInWindow(): boolean;
53
+ }
54
+ /**
55
+ * Instance of the injector.
56
+ *
57
+ * @public
58
+ */
59
+ export declare const cssInjector: CssInjector;
@@ -1,15 +1,22 @@
1
- export interface XCSSInjector {
2
- /** Function that will add the styles to the host. */
3
- addStyle: (styles: {
4
- source: string;
5
- }) => void;
6
- /** Function setting the host for the injector. */
7
- setHost: (el: Element | ShadowRoot) => void;
8
- /** Set injector instance in the window object. */
9
- setInWindow: () => void;
10
- /** Check if the instance is set in the window object. */
11
- isInWindow: () => boolean;
12
- }
13
- export type WindowWithInjector = Window & {
14
- xCSSInjector?: XCSSInjector;
15
- };
1
+ /** The style payload interface. */
2
+ export interface Style {
3
+ /** Css source. */
4
+ source: string;
5
+ }
6
+ export interface XCSSInjector {
7
+ /** Function that will add the styles to the host. */
8
+ addStyle: (style: Style) => void;
9
+ /** @deprecated Use addHost method. */
10
+ setHost: (el: Element | ShadowRoot) => void;
11
+ /** Adds the element to the hosts set. */
12
+ addHost: (el: Document | ShadowRoot) => void;
13
+ /** Removes the element from the hosts set. */
14
+ removeHost: (el: Document | ShadowRoot) => void;
15
+ /** Set injector instance in the window object. */
16
+ setInWindow: () => void;
17
+ /** Check if the instance is set in the window object. */
18
+ isInWindow: () => boolean;
19
+ }
20
+ export type WindowWithInjector = Window & {
21
+ xCSSInjector?: XCSSInjector;
22
+ };
@@ -1,74 +1,78 @@
1
- import { App } from 'vue';
2
- import { LocaleMessageObject, I18n as VueI18n } from 'vue-i18n';
3
- import { AnyMessages, Device, I18nOptions, Locale } from './i18n.types';
4
- /**
5
- * I18n settings manager.
6
- *
7
- * @public
8
- */
9
- export declare class I18n<SomeMessages> {
10
- vueI18n: VueI18n;
11
- protected locale: Locale;
12
- protected device: Device;
13
- protected messages: Record<Locale, AnyMessages<SomeMessages>>;
14
- protected currentMessages: LocaleMessageObject;
15
- protected fallbackLocale: Locale;
16
- /**
17
- * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
18
- *
19
- * @param options - The new {@link I18nOptions | i18n options}.
20
- */
21
- constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>);
22
- /**
23
- * Creates a new {@link I18n} instance.
24
- *
25
- * @param options - The new {@link I18nOptions | i18n options}.
26
- *
27
- * @returns The new instance.
28
- */
29
- static create<SomeMessages>(options: I18nOptions<SomeMessages>): Promise<I18n<SomeMessages>>;
30
- /**
31
- * Installs VueI18n plugin.
32
- *
33
- * @param vue - The Vue instance.
34
- */
35
- install(vue: App): void;
36
- /**
37
- * Tries to get a value from the messages object accessing it key by key.
38
- * When a key fails, takes the remaining key parts and tries to access the message
39
- * joining them into a single key.
40
- *
41
- * @param path - A dot separated key to access the message object.
42
- * @returns The message corresponding to the provided key, or empty string if it doesn't exist.
43
- */
44
- protected getMessageWithDotsInKey(path: string): string | null;
45
- /**
46
- * Sets the new locale and updates the messages accordingly.
47
- *
48
- * @param newLocale - The new locale.
49
- *
50
- * @returns The new messages.
51
- */
52
- setLocale(newLocale: Locale): Promise<void>;
53
- /**
54
- * Sets the new device and updates the messages accordingly.
55
- *
56
- * @param newDevice - The new device.
57
- *
58
- * @returns The new messages.
59
- */
60
- setDevice(newDevice: Device): Promise<void>;
61
- /**
62
- * Updates the current messages based on the new locale and/or device.
63
- */
64
- protected changeMessages(): Promise<void>;
65
- /**
66
- * Retrieves the corresponding messages for the set locale and device.
67
- *
68
- * @remarks By default, it merges `base` messages with the specific `device` ones. If there are
69
- * no messages for the current locale, the fallback locale is used instead.
70
- *
71
- * @returns The messages for the current locale and device.
72
- */
73
- protected getCurrentMessages(): Promise<LocaleMessageObject>;
74
- }
1
+ import type { App } from 'vue';
2
+ import type { LocaleMessageObject, I18n as VueI18n } from 'vue-i18n';
3
+ import type { AnyMessages, Device, I18nOptions, Locale } from './i18n.types';
4
+ /**
5
+ * I18n settings manager.
6
+ *
7
+ * @public
8
+ */
9
+ export declare class I18n<SomeMessages> {
10
+ vueI18n: VueI18n<Record<string, unknown>, Record<string, unknown>, Record<string, unknown>, Locale, false>;
11
+ protected locale: Locale;
12
+ protected device: Device;
13
+ protected messages: Record<Locale, AnyMessages<SomeMessages>>;
14
+ protected currentMessages: LocaleMessageObject;
15
+ protected fallbackLocale: Locale;
16
+ /**
17
+ * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
18
+ *
19
+ * @param options - The new {@link I18nOptions | i18n options}.
20
+ * @param options.locale - i18n locale.
21
+ * @param options.messages - i18n messages.
22
+ * @param options.device - i18n device.
23
+ * @param options.fallbackLocale - i18n fallbackLocale.
24
+ */
25
+ constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>);
26
+ /**
27
+ * Creates a new {@link I18n} instance.
28
+ *
29
+ * @param options - The new {@link I18nOptions | i18n options}.
30
+ *
31
+ * @returns The new instance.
32
+ */
33
+ static create<SomeMessages>(options: I18nOptions<SomeMessages>): Promise<I18n<SomeMessages>>;
34
+ /**
35
+ * Installs VueI18n plugin.
36
+ *
37
+ * @param vue - The Vue instance.
38
+ */
39
+ install(vue: App): void;
40
+ /**
41
+ * Tries to get a value from the messages object accessing it key by key.
42
+ * When a key fails, takes the remaining key parts and tries to access the message
43
+ * joining them into a single key.
44
+ *
45
+ * @param path - A dot separated key to access the message object.
46
+ * @returns The message corresponding to the provided key, or empty string if it doesn't exist.
47
+ */
48
+ protected getMessageWithDotsInKey(path: string): string | null;
49
+ /**
50
+ * Sets the new locale and updates the messages accordingly.
51
+ *
52
+ * @param newLocale - The new locale.
53
+ *
54
+ * @returns The new messages.
55
+ */
56
+ setLocale(newLocale: Locale): Promise<void>;
57
+ /**
58
+ * Sets the new device and updates the messages accordingly.
59
+ *
60
+ * @param newDevice - The new device.
61
+ *
62
+ * @returns The new messages.
63
+ */
64
+ setDevice(newDevice: Device): Promise<void>;
65
+ /**
66
+ * Updates the current messages based on the new locale and/or device.
67
+ */
68
+ protected changeMessages(): Promise<void>;
69
+ /**
70
+ * Retrieves the corresponding messages for the set locale and device.
71
+ *
72
+ * @remarks By default, it merges `base` messages with the specific `device` ones. If there are
73
+ * no messages for the current locale, the fallback locale is used instead.
74
+ *
75
+ * @returns The messages for the current locale and device.
76
+ */
77
+ protected getCurrentMessages(): Promise<LocaleMessageObject>;
78
+ }
@@ -1,53 +1,53 @@
1
- import { DeepPartial } from '@empathyco/x-utils';
2
- import { I18n as VueI18n } from 'vue-i18n';
3
- /** Supported locales. */
4
- export type Locale = string;
5
- /** Supported devices. */
6
- export type Device = string;
7
- /** Union type containing both eager and lazy messages. */
8
- export type AnyMessages<SomeMessages> = MessagesByDevice<SomeMessages> | LoadLazyMessagesByDevice<SomeMessages>;
9
- /** A function that loads on demand the messages for a specific locale. */
10
- export type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{
11
- default: MessagesByDevice<SomeMessages>;
12
- }>;
13
- /**
14
- * An object containing a base property with all the existing messages and the overridden ones for
15
- * each device.
16
- */
17
- export interface MessagesByDevice<SomeMessages> {
18
- base: SomeMessages;
19
- [device: Device]: DeepPartial<SomeMessages>;
20
- }
21
- /**
22
- * I18n settings.
23
- */
24
- export interface I18nOptions<SomeMessages> {
25
- /** The initial messages. */
26
- messages: Record<Locale, AnyMessages<SomeMessages>>;
27
- /** The initial device. */
28
- device: Device;
29
- /** The locale to fall back if no matching locale is available. */
30
- fallbackLocale: Locale;
31
- /** The initial locale. */
32
- locale: Locale;
33
- }
34
- /**
35
- * The VueI18n instance that should be passed to the root Vue instance and some runtime utility
36
- * functions.
37
- */
38
- export interface I18nAPI {
39
- /** The Vue I18n instance that should be passed to the root Vue component. */
40
- readonly vueI18n: Readonly<VueI18n>;
41
- /**
42
- * Sets the new locale.
43
- *
44
- * @param newLocale - The new locale.
45
- */
46
- setLocale: (newLocale: Locale) => Promise<void>;
47
- /**
48
- * Sets the new device.
49
- *
50
- * @param newDevice - The new device.
51
- */
52
- setDevice: (newDevice: Device) => Promise<void>;
53
- }
1
+ import type { DeepPartial } from '@empathyco/x-utils';
2
+ import type { I18n as VueI18n } from 'vue-i18n';
3
+ /** Supported locales. */
4
+ export type Locale = string;
5
+ /** Supported devices. */
6
+ export type Device = string;
7
+ /** Union type containing both eager and lazy messages. */
8
+ export type AnyMessages<SomeMessages> = MessagesByDevice<SomeMessages> | LoadLazyMessagesByDevice<SomeMessages>;
9
+ /** A function that loads on demand the messages for a specific locale. */
10
+ export type LoadLazyMessagesByDevice<SomeMessages> = () => Promise<{
11
+ default: MessagesByDevice<SomeMessages>;
12
+ }>;
13
+ /**
14
+ * An object containing a base property with all the existing messages and the overridden ones for
15
+ * each device.
16
+ */
17
+ export interface MessagesByDevice<SomeMessages> {
18
+ base: SomeMessages;
19
+ [device: Device]: DeepPartial<SomeMessages>;
20
+ }
21
+ /**
22
+ * I18n settings.
23
+ */
24
+ export interface I18nOptions<SomeMessages> {
25
+ /** The initial messages. */
26
+ messages: Record<Locale, AnyMessages<SomeMessages>>;
27
+ /** The initial device. */
28
+ device: Device;
29
+ /** The locale to fall back if no matching locale is available. */
30
+ fallbackLocale: Locale;
31
+ /** The initial locale. */
32
+ locale: Locale;
33
+ }
34
+ /**
35
+ * The VueI18n instance that should be passed to the root Vue instance and some runtime utility
36
+ * functions.
37
+ */
38
+ export interface I18nAPI {
39
+ /** The Vue I18n instance that should be passed to the root Vue component. */
40
+ readonly vueI18n: Readonly<VueI18n>;
41
+ /**
42
+ * Sets the new locale.
43
+ *
44
+ * @param newLocale - The new locale.
45
+ */
46
+ setLocale: (newLocale: Locale) => Promise<void>;
47
+ /**
48
+ * Sets the new device.
49
+ *
50
+ * @param newDevice - The new device.
51
+ */
52
+ setDevice: (newDevice: Device) => Promise<void>;
53
+ }
@@ -1,6 +1,6 @@
1
- export * from './i18n/i18n.plugin';
2
- export * from './i18n/i18n.types';
3
- export * from './build/webpack/webpack.config';
4
- export * from './build/rollup/rollup.config';
5
- export * from './css-injector/css-injector';
6
- export * from './css-injector/css-injector.types';
1
+ export * from './build/rollup/rollup.config';
2
+ export * from './build/webpack/webpack.config';
3
+ export * from './css-injector/css-injector';
4
+ export * from './css-injector/css-injector.types';
5
+ export * from './i18n/i18n.plugin';
6
+ export * from './i18n/i18n.types';
package/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@empathyco/x-archetype-utils",
3
- "version": "2.0.0-alpha.2",
3
+ "version": "2.0.0-alpha.21",
4
4
  "description": "Utilities for x-archetype",
5
5
  "author": "Empathy Systems Corporation S.L.",
6
6
  "license": "Apache-2.0",
7
7
  "homepage": "https://github.com/empathyco/x/tree/main/packages/x-archetype-utils#readme",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/empathyco/x.git",
11
+ "directory": "packages/x-archetype-utils"
12
+ },
8
13
  "keywords": [
9
14
  "utils",
10
15
  "x",
@@ -16,51 +21,50 @@
16
21
  "files": [
17
22
  "dist"
18
23
  ],
19
- "repository": {
20
- "type": "git",
21
- "url": "https://github.com/empathyco/x.git",
22
- "directory": "packages/x-archetype-utils"
23
- },
24
24
  "engines": {
25
- "node": ">=18"
25
+ "node": ">=22"
26
26
  },
27
27
  "scripts": {
28
28
  "prebuild": "rimraf dist ./*.tgz",
29
29
  "build": "rollup -c",
30
30
  "build:cjs": "tsc --project tsconfig.cjs.json",
31
31
  "build:esm": "tsc --project tsconfig.esm.json",
32
- "postbuild": "pnpm pack",
33
- "lint": "eslint . --ext .ts",
32
+ "pack": "pnpm pack",
33
+ "lint": "eslint --fix",
34
+ "lint:check": "eslint",
35
+ "lint:inspect": "eslint --inspect-config .",
36
+ "format": "prettier --write .",
37
+ "format:check": "prettier --check .",
34
38
  "test": "jest",
35
39
  "test:unit": "jest",
36
40
  "prepublishOnly": "pnpm run build"
37
41
  },
42
+ "peerDependencies": {
43
+ "vue": "^3.5.25",
44
+ "vue-i18n": "^9.14.5"
45
+ },
38
46
  "dependencies": {
39
- "@empathyco/x-deep-merge": "^2.0.3-alpha.1",
40
- "@empathyco/x-utils": "^1.0.3-alpha.1",
41
- "tslib": "~2.6.0",
42
- "vue-i18n": "~9.14.0"
47
+ "@empathyco/x-deep-merge": "^2.0.3-alpha.9",
48
+ "@empathyco/x-utils": "^1.0.3-alpha.8",
49
+ "tslib": "~2.8.1",
50
+ "vue-i18n": "~9.14.5"
43
51
  },
44
52
  "devDependencies": {
45
- "@types/jest": "~27.5.0",
46
- "@types/node": "~18.19.0",
47
- "@vue/test-utils": "~2.4.6",
48
- "jest": "~27.5.0",
49
- "rimraf": "~3.0.2",
50
- "rollup": "~4.9.1",
51
- "rollup-plugin-copy": "~3.5.0",
52
- "rollup-plugin-delete": "~2.0.0",
53
- "rollup-plugin-typescript2": "~0.36.0",
54
- "ts-jest": "~27.1.0",
55
- "typescript": "~4.9.4",
56
- "vue": "~3.4.31"
57
- },
58
- "peerDependencies": {
59
- "vue": "^3.4.31",
60
- "vue-i18n": "^9.14.0"
53
+ "@types/jest": "29.5.14",
54
+ "@types/node": "24.10.1",
55
+ "@vue/test-utils": "2.4.6",
56
+ "jest": "29.7.0",
57
+ "rimraf": "3.0.2",
58
+ "rollup": "4.9.1",
59
+ "rollup-plugin-copy": "3.5.0",
60
+ "rollup-plugin-delete": "2.0.0",
61
+ "rollup-plugin-typescript2": "0.36.0",
62
+ "ts-jest": "29.4.0",
63
+ "typescript": "5.8.3",
64
+ "vue": "3.5.25"
61
65
  },
62
66
  "publishConfig": {
63
67
  "access": "public"
64
68
  },
65
- "gitHead": "d08f39adb09013b148fc99452757436547fba363"
69
+ "gitHead": "05d6df908678dd6a56434551d4db1daeca0ac832"
66
70
  }