@empathyco/x-archetype-utils 2.0.0-alpha.4 → 2.0.0-alpha.40
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/README.md +1 -1
- package/dist/{types/build → build}/rollup/rollup.config.d.ts +9 -9
- package/dist/{types/build → build}/webpack/webpack.config.d.ts +35 -35
- package/dist/{types/css-injector → css-injector}/css-injector.d.ts +59 -47
- package/dist/{types/css-injector → css-injector}/css-injector.types.d.ts +22 -15
- package/dist/home/home-template.html +2 -1
- package/dist/{types/i18n → i18n}/i18n.plugin.d.ts +78 -74
- package/dist/{types/i18n → i18n}/i18n.types.d.ts +53 -53
- package/dist/index.cjs.js +2 -0
- package/dist/index.cjs.js.map +1 -0
- package/dist/{types/index.d.ts → index.d.ts} +6 -6
- package/dist/index.es.js +202 -0
- package/dist/index.es.js.map +1 -0
- package/package.json +38 -39
- package/dist/cjs/build/rollup/rollup.config.js +0 -14
- package/dist/cjs/build/webpack/webpack.config.js +0 -26
- package/dist/cjs/css-injector/css-injector.js +0 -81
- package/dist/cjs/i18n/i18n.plugin.js +0 -138
- package/dist/cjs/index.js +0 -14
- package/dist/esm/build/rollup/rollup.config.js +0 -12
- package/dist/esm/build/webpack/webpack.config.js +0 -24
- package/dist/esm/css-injector/css-injector.js +0 -78
- package/dist/esm/i18n/i18n.plugin.js +0 -136
- package/dist/esm/index.js +0 -4
package/dist/index.es.js
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
import { isObject as h, deepMerge as d } from "@empathyco/x-utils";
|
|
2
|
+
import { createI18n as u } from "vue-i18n";
|
|
3
|
+
const w = {
|
|
4
|
+
replace: {
|
|
5
|
+
// Replace X CSS injector by our custom one.
|
|
6
|
+
"export default injectCss": "export default (css) => window.xCSSInjector.addStyle({ source: css });",
|
|
7
|
+
delimiters: ["", ""]
|
|
8
|
+
},
|
|
9
|
+
styles: {
|
|
10
|
+
mode: ["inject", (a) => `window.xCSSInjector.addStyle({ source: ${a} });`]
|
|
11
|
+
}
|
|
12
|
+
}, y = {
|
|
13
|
+
transpileDependencies: ["@empathyco/x-components"],
|
|
14
|
+
configureWebpack: {
|
|
15
|
+
module: {
|
|
16
|
+
rules: [
|
|
17
|
+
{
|
|
18
|
+
test: /\.ts|js|vue$/,
|
|
19
|
+
enforce: "pre",
|
|
20
|
+
use: ["source-map-loader"]
|
|
21
|
+
}
|
|
22
|
+
]
|
|
23
|
+
},
|
|
24
|
+
output: {
|
|
25
|
+
devtoolModuleFilenameTemplate: ({
|
|
26
|
+
resourcePath: a,
|
|
27
|
+
hash: e,
|
|
28
|
+
query: s
|
|
29
|
+
}) => a.match(/\.vue$/) && !s.match(/type=script/) && !s.match(/\?rollup-plugin-vue=script.ts/) ? `webpack-generated:///${a}?${e}` : `sources://${a}`,
|
|
30
|
+
devtoolFallbackModuleFilenameTemplate: "webpack:///[resource-path]?[hash]"
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
let i = null;
|
|
35
|
+
class n {
|
|
36
|
+
/**
|
|
37
|
+
* Initializes the instance of the injector if it's not already initialized and sets it in the
|
|
38
|
+
* window object if it's required.
|
|
39
|
+
*
|
|
40
|
+
* @param setInWindow - Whether to set the injector instance in the window object.
|
|
41
|
+
*/
|
|
42
|
+
constructor(e = !0) {
|
|
43
|
+
return this.hosts = /* @__PURE__ */ new Set(), this.stylesToAdopt = [], i instanceof n || (i = this), e && this.setInWindow(), i;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Adds the style to the host element.
|
|
47
|
+
*
|
|
48
|
+
* @param style - The styles to be added.
|
|
49
|
+
* @param style.source - Styles source.
|
|
50
|
+
*/
|
|
51
|
+
addStyle(e) {
|
|
52
|
+
const s = new CSSStyleSheet();
|
|
53
|
+
s.replaceSync(e.source), this.stylesToAdopt.push(s), this.hosts.forEach((t) => t.adoptedStyleSheets = this.stylesToAdopt);
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Sets the host element. Alias of addHost method.
|
|
57
|
+
*
|
|
58
|
+
* @param host - The host element.
|
|
59
|
+
* @deprecated Use addHost instead.
|
|
60
|
+
*/
|
|
61
|
+
setHost(e) {
|
|
62
|
+
this.addHost(e instanceof ShadowRoot ? e : document);
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Adds the element to the hosts set.
|
|
66
|
+
*
|
|
67
|
+
* @param host - The host element.
|
|
68
|
+
*/
|
|
69
|
+
addHost(e) {
|
|
70
|
+
this.hosts.add(e), e.adoptedStyleSheets = this.stylesToAdopt;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Removes the element from the hosts set.
|
|
74
|
+
*
|
|
75
|
+
* @param host - The host element to remove.
|
|
76
|
+
*/
|
|
77
|
+
removeHost(e) {
|
|
78
|
+
this.hosts.delete(e);
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Sets the injector instance in the window object.
|
|
82
|
+
*/
|
|
83
|
+
setInWindow() {
|
|
84
|
+
typeof window < "u" && i && (window.xCSSInjector = i);
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Checks if the injector instance is in the window object.
|
|
88
|
+
*
|
|
89
|
+
* @returns Whether the injector instance is in the window object.
|
|
90
|
+
*/
|
|
91
|
+
isInWindow() {
|
|
92
|
+
return typeof window > "u" ? !1 : window.xCSSInjector === i;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const m = new n(typeof window < "u");
|
|
96
|
+
class c {
|
|
97
|
+
/**
|
|
98
|
+
* Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
|
|
99
|
+
*
|
|
100
|
+
* @param options - The new {@link I18nOptions | i18n options}.
|
|
101
|
+
* @param options.locale - i18n locale.
|
|
102
|
+
* @param options.messages - i18n messages.
|
|
103
|
+
* @param options.device - i18n device.
|
|
104
|
+
* @param options.fallbackLocale - i18n fallbackLocale.
|
|
105
|
+
*/
|
|
106
|
+
constructor({ locale: e, messages: s, device: t, fallbackLocale: o }) {
|
|
107
|
+
this.locale = e, this.device = t, this.messages = s, this.fallbackLocale = o;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Creates a new {@link I18n} instance.
|
|
111
|
+
*
|
|
112
|
+
* @param options - The new {@link I18nOptions | i18n options}.
|
|
113
|
+
*
|
|
114
|
+
* @returns The new instance.
|
|
115
|
+
*/
|
|
116
|
+
static async create(e) {
|
|
117
|
+
const s = new c(e);
|
|
118
|
+
return s.currentMessages = await s.getCurrentMessages(), s;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Installs VueI18n plugin.
|
|
122
|
+
*
|
|
123
|
+
* @param vue - The Vue instance.
|
|
124
|
+
*/
|
|
125
|
+
install(e) {
|
|
126
|
+
this.vueI18n = u({
|
|
127
|
+
legacy: !1,
|
|
128
|
+
locale: this.locale,
|
|
129
|
+
silentFallbackWarn: !0,
|
|
130
|
+
// eslint-disable-next-line ts/no-unsafe-assignment
|
|
131
|
+
messages: this.currentMessages ? { [this.locale]: this.currentMessages } : {},
|
|
132
|
+
missing: (s, t) => this.getMessageWithDotsInKey(t) ?? `[i18n] Key '${t}' is missing for locale: '${this.locale}'`
|
|
133
|
+
}), e.use(this.vueI18n);
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Tries to get a value from the messages object accessing it key by key.
|
|
137
|
+
* When a key fails, takes the remaining key parts and tries to access the message
|
|
138
|
+
* joining them into a single key.
|
|
139
|
+
*
|
|
140
|
+
* @param path - A dot separated key to access the message object.
|
|
141
|
+
* @returns The message corresponding to the provided key, or empty string if it doesn't exist.
|
|
142
|
+
*/
|
|
143
|
+
getMessageWithDotsInKey(e) {
|
|
144
|
+
const s = e.split(".").reduce(
|
|
145
|
+
(t, o, l, r) => (
|
|
146
|
+
// eslint-disable-next-line ts/no-unsafe-return
|
|
147
|
+
h(t) ? t[o] ?? t[r.slice(l).join(".")] : t
|
|
148
|
+
),
|
|
149
|
+
this.currentMessages
|
|
150
|
+
);
|
|
151
|
+
return typeof s == "string" ? s : null;
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Sets the new locale and updates the messages accordingly.
|
|
155
|
+
*
|
|
156
|
+
* @param newLocale - The new locale.
|
|
157
|
+
*
|
|
158
|
+
* @returns The new messages.
|
|
159
|
+
*/
|
|
160
|
+
async setLocale(e) {
|
|
161
|
+
this.locale !== e && (this.locale = e, await this.changeMessages(), this.vueI18n.global.locale.value = this.locale);
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Sets the new device and updates the messages accordingly.
|
|
165
|
+
*
|
|
166
|
+
* @param newDevice - The new device.
|
|
167
|
+
*
|
|
168
|
+
* @returns The new messages.
|
|
169
|
+
*/
|
|
170
|
+
async setDevice(e) {
|
|
171
|
+
this.device !== e && (this.device = e, await this.changeMessages());
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Updates the current messages based on the new locale and/or device.
|
|
175
|
+
*/
|
|
176
|
+
async changeMessages() {
|
|
177
|
+
this.currentMessages = await this.getCurrentMessages(), this.vueI18n.global.setLocaleMessage(this.locale, this.currentMessages);
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Retrieves the corresponding messages for the set locale and device.
|
|
181
|
+
*
|
|
182
|
+
* @remarks By default, it merges `base` messages with the specific `device` ones. If there are
|
|
183
|
+
* no messages for the current locale, the fallback locale is used instead.
|
|
184
|
+
*
|
|
185
|
+
* @returns The messages for the current locale and device.
|
|
186
|
+
*/
|
|
187
|
+
async getCurrentMessages() {
|
|
188
|
+
const e = this.locale in this.messages ? this.messages[this.locale] : this.messages[this.fallbackLocale], s = g(e) ? (await e()).default : e;
|
|
189
|
+
return d({}, s.base, s[this.device]);
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function g(a) {
|
|
193
|
+
return typeof a == "function";
|
|
194
|
+
}
|
|
195
|
+
export {
|
|
196
|
+
n as CssInjector,
|
|
197
|
+
c as I18n,
|
|
198
|
+
m as cssInjector,
|
|
199
|
+
w as rollupCssInjectorConfig,
|
|
200
|
+
y as webpackConfig
|
|
201
|
+
};
|
|
202
|
+
//# sourceMappingURL=index.es.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../src/build/rollup/rollup.config.ts","../src/build/webpack/webpack.config.ts","../src/css-injector/css-injector.ts","../src/i18n/i18n.plugin.ts"],"sourcesContent":["export const rollupCssInjectorConfig = {\n replace: {\n // Replace X CSS injector by our custom one.\n 'export default injectCss':\n 'export default (css) => window.xCSSInjector.addStyle({ source: css });',\n delimiters: ['', ''],\n },\n styles: {\n mode: ['inject', (varname: string) => `window.xCSSInjector.addStyle({ source: ${varname} });`],\n },\n}\n","/**.\n * Self-made interface since Webpack does not provide a type for this object.\n * Https://github.com/webpack/webpack/blob/main/declarations/WebpackOptions.d.ts#L463\n *\n * @internal\n */\ninterface webpackFilenameTemplateInfo {\n identifier: string\n shortIdentifier: string\n resource: string\n resourcePath: string\n absoluteResourcePath: string\n allLoaders: string\n query: string\n moduleId: string\n hash: string\n namespace: string\n}\n\nexport const webpackConfig = {\n transpileDependencies: ['@empathyco/x-components'],\n configureWebpack: {\n module: {\n rules: [\n {\n test: /\\.ts|js|vue$/,\n enforce: 'pre',\n use: ['source-map-loader'],\n },\n ],\n },\n output: {\n devtoolModuleFilenameTemplate: ({\n resourcePath,\n hash,\n query,\n }: webpackFilenameTemplateInfo) =>\n resourcePath.match(/\\.vue$/) &&\n !query.match(/type=script/) &&\n !query.match(/\\?rollup-plugin-vue=script.ts/)\n ? `webpack-generated:///${resourcePath}?${hash}`\n : `sources://${resourcePath}`,\n devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]',\n },\n },\n}\n","import type { Style, WindowWithInjector, XCSSInjector } from './css-injector.types'\n\n/** Singleton instance of the injector that will be used across all the initializations. */\nlet instance: CssInjector | null = null\n\n/**\n * Custom CSS injector that allows to inject styles into a host element.\n *\n * @public\n */\nexport class CssInjector implements XCSSInjector {\n protected hosts = new Set<Document | ShadowRoot>()\n protected stylesToAdopt: CSSStyleSheet[] = []\n\n /**\n * Initializes the instance of the injector if it's not already initialized and sets it in the\n * window object if it's required.\n *\n * @param setInWindow - Whether to set the injector instance in the window object.\n */\n public constructor(setInWindow = true) {\n if (!(instance instanceof CssInjector)) {\n // eslint-disable-next-line ts/no-this-alias\n instance = this\n }\n\n if (setInWindow) {\n this.setInWindow()\n }\n\n return instance\n }\n\n /**\n * Adds the style to the host element.\n *\n * @param style - The styles to be added.\n * @param style.source - Styles source.\n */\n addStyle(style: Style): void {\n const sheet = new CSSStyleSheet()\n sheet.replaceSync(style.source)\n this.stylesToAdopt.push(sheet)\n this.hosts.forEach(host => (host.adoptedStyleSheets = this.stylesToAdopt))\n }\n\n /**\n * Sets the host element. Alias of addHost method.\n *\n * @param host - The host element.\n * @deprecated Use addHost instead.\n */\n setHost(host: Element | ShadowRoot): void {\n this.addHost(host instanceof ShadowRoot ? host : document)\n }\n\n /**\n * Adds the element to the hosts set.\n *\n * @param host - The host element.\n */\n addHost(host: Document | ShadowRoot): void {\n this.hosts.add(host)\n host.adoptedStyleSheets = this.stylesToAdopt\n }\n\n /**\n * Removes the element from the hosts set.\n *\n * @param host - The host element to remove.\n */\n removeHost(host: Document | ShadowRoot): void {\n this.hosts.delete(host)\n }\n\n /**\n * Sets the injector instance in the window object.\n */\n setInWindow(): void {\n if (typeof window !== 'undefined' && instance) {\n ;(window as WindowWithInjector).xCSSInjector = instance\n }\n }\n\n /**\n * Checks if the injector instance is in the window object.\n *\n * @returns Whether the injector instance is in the window object.\n */\n isInWindow(): boolean {\n return typeof window === 'undefined'\n ? false\n : (window as WindowWithInjector).xCSSInjector === instance\n }\n}\n\n/**\n * Instance of the injector.\n *\n * @public\n */\nexport const cssInjector = new CssInjector(typeof window !== 'undefined')\n","import type { App } from 'vue'\nimport type { LocaleMessageObject, I18n as VueI18n } from 'vue-i18n'\nimport type {\n AnyMessages,\n Device,\n I18nOptions,\n LoadLazyMessagesByDevice,\n Locale,\n} from './i18n.types'\nimport { deepMerge, isObject } from '@empathyco/x-utils'\nimport { createI18n } from 'vue-i18n'\n\n/**\n * I18n settings manager.\n *\n * @public\n */\nexport class I18n<SomeMessages> {\n public vueI18n!: VueI18n<\n Record<string, unknown>,\n Record<string, unknown>,\n Record<string, unknown>,\n Locale,\n false\n >\n protected locale!: Locale\n protected device!: Device\n protected messages!: Record<Locale, AnyMessages<SomeMessages>>\n protected currentMessages!: LocaleMessageObject\n protected fallbackLocale!: Locale\n\n /**\n * Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n * @param options.locale - i18n locale.\n * @param options.messages - i18n messages.\n * @param options.device - i18n device.\n * @param options.fallbackLocale - i18n fallbackLocale.\n */\n public constructor({ locale, messages, device, fallbackLocale }: I18nOptions<SomeMessages>) {\n this.locale = locale\n this.device = device\n this.messages = messages\n this.fallbackLocale = fallbackLocale\n }\n\n /**\n * Creates a new {@link I18n} instance.\n *\n * @param options - The new {@link I18nOptions | i18n options}.\n *\n * @returns The new instance.\n */\n static async create<SomeMessages>(\n options: I18nOptions<SomeMessages>,\n ): Promise<I18n<SomeMessages>> {\n const instance = new I18n(options)\n instance.currentMessages = await instance.getCurrentMessages()\n return instance\n }\n\n /**\n * Installs VueI18n plugin.\n *\n * @param vue - The Vue instance.\n */\n install(vue: App): void {\n this.vueI18n = createI18n({\n legacy: false,\n locale: this.locale,\n silentFallbackWarn: true,\n // eslint-disable-next-line ts/no-unsafe-assignment\n messages: this.currentMessages ? ({ [this.locale]: this.currentMessages } as any) : {},\n missing: (_, key: string) => {\n return (\n this.getMessageWithDotsInKey(key) ??\n `[i18n] Key '${key}' is missing for locale: '${this.locale}'`\n )\n },\n })\n vue.use(this.vueI18n)\n }\n\n /**\n * Tries to get a value from the messages object accessing it key by key.\n * When a key fails, takes the remaining key parts and tries to access the message\n * joining them into a single key.\n *\n * @param path - A dot separated key to access the message object.\n * @returns The message corresponding to the provided key, or empty string if it doesn't exist.\n */\n protected getMessageWithDotsInKey(path: string): string | null {\n // TO-DO Support function or array messages\n // eslint-disable-next-line ts/no-unsafe-assignment\n const message = path.split('.').reduce<any>(\n (messages, key, index, pathParts) =>\n // eslint-disable-next-line ts/no-unsafe-return\n isObject(messages)\n ? (messages[key] ?? messages[pathParts.slice(index).join('.')])\n : messages,\n this.currentMessages,\n )\n return typeof message === 'string' ? message : null\n }\n\n /**\n * Sets the new locale and updates the messages accordingly.\n *\n * @param newLocale - The new locale.\n *\n * @returns The new messages.\n */\n async setLocale(newLocale: Locale): Promise<void> {\n if (this.locale !== newLocale) {\n this.locale = newLocale\n\n await this.changeMessages()\n this.vueI18n.global.locale.value = this.locale\n }\n }\n\n /**\n * Sets the new device and updates the messages accordingly.\n *\n * @param newDevice - The new device.\n *\n * @returns The new messages.\n */\n async setDevice(newDevice: Device): Promise<void> {\n if (this.device !== newDevice) {\n this.device = newDevice\n\n await this.changeMessages()\n }\n }\n\n /**\n * Updates the current messages based on the new locale and/or device.\n */\n protected async changeMessages(): Promise<void> {\n this.currentMessages = await this.getCurrentMessages()\n\n this.vueI18n.global.setLocaleMessage(this.locale, this.currentMessages)\n }\n\n /**\n * Retrieves the corresponding messages for the set locale and device.\n *\n * @remarks By default, it merges `base` messages with the specific `device` ones. If there are\n * no messages for the current locale, the fallback locale is used instead.\n *\n * @returns The messages for the current locale and device.\n */\n protected async getCurrentMessages(): Promise<LocaleMessageObject> {\n const rawMessages =\n this.locale in this.messages ? this.messages[this.locale] : this.messages[this.fallbackLocale]\n\n const messages = areLazyMessages(rawMessages) ? (await rawMessages()).default : rawMessages\n // eslint-disable-next-line ts/no-unsafe-return\n return deepMerge({}, messages.base, messages[this.device])\n }\n}\n\n/**\n * Type-guard to check if the passed messages should be lazy-loaded.\n *\n * @param messages - The messages to check.\n *\n * @returns True if the messages are lazy or false otherwise.\n */\nfunction areLazyMessages<SomeMessages>(\n messages: AnyMessages<SomeMessages>,\n): messages is LoadLazyMessagesByDevice<SomeMessages> {\n return typeof messages === 'function'\n}\n"],"names":["rollupCssInjectorConfig","varname","webpackConfig","resourcePath","hash","query","instance","CssInjector","setInWindow","style","sheet","host","cssInjector","I18n","locale","messages","device","fallbackLocale","options","vue","createI18n","_","key","path","message","index","pathParts","isObject","newLocale","newDevice","rawMessages","areLazyMessages","deepMerge"],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,66 +1,65 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@empathyco/x-archetype-utils",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.40",
|
|
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",
|
|
11
16
|
"x-archetype"
|
|
12
17
|
],
|
|
13
|
-
"main": "dist/
|
|
14
|
-
"module": "dist/
|
|
15
|
-
"types": "dist/
|
|
18
|
+
"main": "dist/index.cjs.js",
|
|
19
|
+
"module": "dist/index.es.js",
|
|
20
|
+
"types": "dist/index.d.ts",
|
|
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": ">=
|
|
25
|
+
"node": ">=22"
|
|
26
26
|
},
|
|
27
27
|
"scripts": {
|
|
28
|
-
"prebuild": "
|
|
29
|
-
"build": "
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"lint": "eslint
|
|
34
|
-
"
|
|
35
|
-
"
|
|
28
|
+
"prebuild": "rm -rf dist *.tgz",
|
|
29
|
+
"build": "vite build",
|
|
30
|
+
"pack": "pnpm pack",
|
|
31
|
+
"lint": "eslint --fix",
|
|
32
|
+
"lint:check": "eslint",
|
|
33
|
+
"lint:inspect": "eslint --inspect-config .",
|
|
34
|
+
"format": "prettier --write .",
|
|
35
|
+
"format:check": "prettier --check .",
|
|
36
|
+
"test": "vitest run",
|
|
37
|
+
"test:unit": "vitest run",
|
|
38
|
+
"test:unit-coverage": "vitest run --coverage",
|
|
39
|
+
"test:unit-watch": "vitest",
|
|
36
40
|
"prepublishOnly": "pnpm run build"
|
|
37
41
|
},
|
|
42
|
+
"peerDependencies": {
|
|
43
|
+
"vue": "^3.5.32",
|
|
44
|
+
"vue-i18n": "^9.14.5"
|
|
45
|
+
},
|
|
38
46
|
"dependencies": {
|
|
39
|
-
"@empathyco/x-
|
|
40
|
-
"
|
|
41
|
-
"tslib": "~2.6.0",
|
|
42
|
-
"vue-i18n": "~9.14.0"
|
|
47
|
+
"@empathyco/x-utils": "1.0.3-alpha.18",
|
|
48
|
+
"vue-i18n": "~9.14.5"
|
|
43
49
|
},
|
|
44
50
|
"devDependencies": {
|
|
45
|
-
"@
|
|
46
|
-
"@
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
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"
|
|
51
|
+
"@vitest/coverage-v8": "4.1.2",
|
|
52
|
+
"@vue/test-utils": "2.4.6",
|
|
53
|
+
"jsdom": "28.1.0",
|
|
54
|
+
"typescript": "5.9.3",
|
|
55
|
+
"vite": "6.4.1",
|
|
56
|
+
"vite-plugin-dts": "4.5.4",
|
|
57
|
+
"vite-plugin-static-copy": "3.4.0",
|
|
58
|
+
"vitest": "4.1.2",
|
|
59
|
+
"vue": "3.5.32"
|
|
61
60
|
},
|
|
62
61
|
"publishConfig": {
|
|
63
62
|
"access": "public"
|
|
64
63
|
},
|
|
65
|
-
"gitHead": "
|
|
64
|
+
"gitHead": "b01aaf8f64804f2ec094bff4a267f0dd8317c0d7"
|
|
66
65
|
}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const rollupCssInjectorConfig = {
|
|
4
|
-
replace: {
|
|
5
|
-
// Replace X CSS injector by our custom one.
|
|
6
|
-
'export default injectCss;': 'export default (css) => window.xCSSInjector.addStyle({ source: css });',
|
|
7
|
-
delimiters: ['', '']
|
|
8
|
-
},
|
|
9
|
-
styles: {
|
|
10
|
-
mode: ['inject', (varname) => `window.xCSSInjector.addStyle({ source: ${varname} });`]
|
|
11
|
-
}
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
exports.rollupCssInjectorConfig = rollupCssInjectorConfig;
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const webpackConfig = {
|
|
4
|
-
transpileDependencies: ['@empathyco/x-components'],
|
|
5
|
-
configureWebpack: {
|
|
6
|
-
module: {
|
|
7
|
-
rules: [
|
|
8
|
-
{
|
|
9
|
-
test: /\.ts|js|vue$/,
|
|
10
|
-
enforce: 'pre',
|
|
11
|
-
use: ['source-map-loader']
|
|
12
|
-
}
|
|
13
|
-
]
|
|
14
|
-
},
|
|
15
|
-
output: {
|
|
16
|
-
devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }) => resourcePath.match(/\.vue$/) &&
|
|
17
|
-
!query.match(/type=script/) &&
|
|
18
|
-
!query.match(/\?rollup-plugin-vue=script.ts/)
|
|
19
|
-
? `webpack-generated:///${resourcePath}?${hash}`
|
|
20
|
-
: `sources://${resourcePath}`,
|
|
21
|
-
devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]'
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.webpackConfig = webpackConfig;
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Instance of the injector that will be used across all the initializations.
|
|
5
|
-
*/
|
|
6
|
-
let instance = null;
|
|
7
|
-
/**
|
|
8
|
-
* Custom CSS injector that allows to inject styles into a host element.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
class CssInjector {
|
|
13
|
-
/**
|
|
14
|
-
* Initializes the instance of the injector if it's not already initialized and sets it in the
|
|
15
|
-
* window object if it's required.
|
|
16
|
-
*
|
|
17
|
-
* @param setInWindow - Whether to set the injector instance in the window object.
|
|
18
|
-
*/
|
|
19
|
-
constructor(setInWindow = true) {
|
|
20
|
-
this.stylesQueue = [];
|
|
21
|
-
if (!(instance instanceof CssInjector)) {
|
|
22
|
-
// eslint-disable-next-line @typescript-eslint/no-this-alias
|
|
23
|
-
instance = this;
|
|
24
|
-
}
|
|
25
|
-
if (setInWindow) {
|
|
26
|
-
this.setInWindow();
|
|
27
|
-
}
|
|
28
|
-
return instance;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Adds the styles to the host element.
|
|
32
|
-
*
|
|
33
|
-
* @param styles - The styles to be added.
|
|
34
|
-
*/
|
|
35
|
-
addStyle(styles) {
|
|
36
|
-
this.stylesQueue.push(styles.source);
|
|
37
|
-
if (this.host) {
|
|
38
|
-
this.stylesQueue.forEach(styles => {
|
|
39
|
-
const styleTag = document.createElement('style');
|
|
40
|
-
styleTag.textContent = styles;
|
|
41
|
-
this.host.appendChild(styleTag);
|
|
42
|
-
});
|
|
43
|
-
this.stylesQueue = [];
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Sets the host element.
|
|
48
|
-
*
|
|
49
|
-
* @param host - The host element.
|
|
50
|
-
*/
|
|
51
|
-
setHost(host) {
|
|
52
|
-
this.host = host;
|
|
53
|
-
}
|
|
54
|
-
/**
|
|
55
|
-
* Sets the injector instance in the window object.
|
|
56
|
-
*/
|
|
57
|
-
setInWindow() {
|
|
58
|
-
if (typeof window !== 'undefined' && instance) {
|
|
59
|
-
window.xCSSInjector = instance;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Checks if the injector instance is in the window object.
|
|
64
|
-
*
|
|
65
|
-
* @returns Whether the injector instance is in the window object.
|
|
66
|
-
*/
|
|
67
|
-
isInWindow() {
|
|
68
|
-
return typeof window === 'undefined'
|
|
69
|
-
? false
|
|
70
|
-
: window.xCSSInjector === instance;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/**
|
|
74
|
-
* Instance of the injector.
|
|
75
|
-
*
|
|
76
|
-
* @public
|
|
77
|
-
*/
|
|
78
|
-
const cssInjector = new CssInjector(typeof window !== 'undefined');
|
|
79
|
-
|
|
80
|
-
exports.CssInjector = CssInjector;
|
|
81
|
-
exports.cssInjector = cssInjector;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var xUtils = require('@empathyco/x-utils');
|
|
4
|
-
var vueI18n = require('vue-i18n');
|
|
5
|
-
var xDeepMerge = require('@empathyco/x-deep-merge');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* I18n settings manager.
|
|
9
|
-
*
|
|
10
|
-
* @public
|
|
11
|
-
*/
|
|
12
|
-
class I18n {
|
|
13
|
-
/**
|
|
14
|
-
* Constructs a new {@link I18n} instance with the passed {@link I18nOptions | i18n options}.
|
|
15
|
-
*
|
|
16
|
-
* @param options - The new {@link I18nOptions | i18n options}.
|
|
17
|
-
*/
|
|
18
|
-
constructor({ locale, messages, device, fallbackLocale }) {
|
|
19
|
-
this.locale = locale;
|
|
20
|
-
this.device = device;
|
|
21
|
-
this.messages = messages;
|
|
22
|
-
this.fallbackLocale = fallbackLocale;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Creates a new {@link I18n} instance.
|
|
26
|
-
*
|
|
27
|
-
* @param options - The new {@link I18nOptions | i18n options}.
|
|
28
|
-
*
|
|
29
|
-
* @returns The new instance.
|
|
30
|
-
*/
|
|
31
|
-
static async create(options) {
|
|
32
|
-
const instance = new I18n(options);
|
|
33
|
-
instance.currentMessages = await instance.getCurrentMessages();
|
|
34
|
-
return instance;
|
|
35
|
-
}
|
|
36
|
-
/**
|
|
37
|
-
* Installs VueI18n plugin.
|
|
38
|
-
*
|
|
39
|
-
* @param vue - The Vue instance.
|
|
40
|
-
*/
|
|
41
|
-
install(vue) {
|
|
42
|
-
this.vueI18n = vueI18n.createI18n({
|
|
43
|
-
legacy: false,
|
|
44
|
-
locale: this.locale,
|
|
45
|
-
silentFallbackWarn: true,
|
|
46
|
-
messages: this.currentMessages ? { [this.locale]: this.currentMessages } : {},
|
|
47
|
-
missing: (_, key) => {
|
|
48
|
-
var _a;
|
|
49
|
-
return ((_a = this.getMessageWithDotsInKey(key)) !== null && _a !== void 0 ? _a : `[i18n] Key '${key}' is missing for locale: '${this.locale}'`);
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
53
|
-
vue.use(this.vueI18n);
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Tries to get a value from the messages object accessing it key by key.
|
|
57
|
-
* When a key fails, takes the remaining key parts and tries to access the message
|
|
58
|
-
* joining them into a single key.
|
|
59
|
-
*
|
|
60
|
-
* @param path - A dot separated key to access the message object.
|
|
61
|
-
* @returns The message corresponding to the provided key, or empty string if it doesn't exist.
|
|
62
|
-
*/
|
|
63
|
-
getMessageWithDotsInKey(path) {
|
|
64
|
-
// TO-DO Support function or array messages
|
|
65
|
-
const message = path
|
|
66
|
-
.split('.')
|
|
67
|
-
.reduce((messages, key, index, pathParts) => {
|
|
68
|
-
var _a;
|
|
69
|
-
return xUtils.isObject(messages)
|
|
70
|
-
? (_a = messages[key]) !== null && _a !== void 0 ? _a : messages[pathParts.slice(index).join('.')]
|
|
71
|
-
: messages;
|
|
72
|
-
}, this.currentMessages);
|
|
73
|
-
return typeof message === 'string' ? message : null;
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Sets the new locale and updates the messages accordingly.
|
|
77
|
-
*
|
|
78
|
-
* @param newLocale - The new locale.
|
|
79
|
-
*
|
|
80
|
-
* @returns The new messages.
|
|
81
|
-
*/
|
|
82
|
-
async setLocale(newLocale) {
|
|
83
|
-
if (this.locale !== newLocale) {
|
|
84
|
-
this.locale = newLocale;
|
|
85
|
-
await this.changeMessages();
|
|
86
|
-
this.vueI18n.global.locale.value = this.locale;
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Sets the new device and updates the messages accordingly.
|
|
91
|
-
*
|
|
92
|
-
* @param newDevice - The new device.
|
|
93
|
-
*
|
|
94
|
-
* @returns The new messages.
|
|
95
|
-
*/
|
|
96
|
-
async setDevice(newDevice) {
|
|
97
|
-
if (this.device !== newDevice) {
|
|
98
|
-
this.device = newDevice;
|
|
99
|
-
await this.changeMessages();
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
/**
|
|
103
|
-
* Updates the current messages based on the new locale and/or device.
|
|
104
|
-
*/
|
|
105
|
-
async changeMessages() {
|
|
106
|
-
this.currentMessages = await this.getCurrentMessages();
|
|
107
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
108
|
-
this.vueI18n.global.setLocaleMessage(this.locale, this.currentMessages);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Retrieves the corresponding messages for the set locale and device.
|
|
112
|
-
*
|
|
113
|
-
* @remarks By default, it merges `base` messages with the specific `device` ones. If there are
|
|
114
|
-
* no messages for the current locale, the fallback locale is used instead.
|
|
115
|
-
*
|
|
116
|
-
* @returns The messages for the current locale and device.
|
|
117
|
-
*/
|
|
118
|
-
async getCurrentMessages() {
|
|
119
|
-
const rawMessages = this.locale in this.messages
|
|
120
|
-
? this.messages[this.locale]
|
|
121
|
-
: this.messages[this.fallbackLocale];
|
|
122
|
-
const messages = areLazyMessages(rawMessages) ? (await rawMessages()).default : rawMessages;
|
|
123
|
-
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
|
124
|
-
return xDeepMerge.deepMerge({}, messages.base, messages[this.device]);
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Type-guard to check if the passed messages should be lazy-loaded.
|
|
129
|
-
*
|
|
130
|
-
* @param messages - The messages to check.
|
|
131
|
-
*
|
|
132
|
-
* @returns True if the messages are lazy or false otherwise.
|
|
133
|
-
*/
|
|
134
|
-
function areLazyMessages(messages) {
|
|
135
|
-
return typeof messages === 'function';
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
exports.I18n = I18n;
|
package/dist/cjs/index.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var i18n_plugin = require('./i18n/i18n.plugin.js');
|
|
4
|
-
var webpack_config = require('./build/webpack/webpack.config.js');
|
|
5
|
-
var rollup_config = require('./build/rollup/rollup.config.js');
|
|
6
|
-
var cssInjector = require('./css-injector/css-injector.js');
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
exports.I18n = i18n_plugin.I18n;
|
|
11
|
-
exports.webpackConfig = webpack_config.webpackConfig;
|
|
12
|
-
exports.rollupCssInjectorConfig = rollup_config.rollupCssInjectorConfig;
|
|
13
|
-
exports.CssInjector = cssInjector.CssInjector;
|
|
14
|
-
exports.cssInjector = cssInjector.cssInjector;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
const rollupCssInjectorConfig = {
|
|
2
|
-
replace: {
|
|
3
|
-
// Replace X CSS injector by our custom one.
|
|
4
|
-
'export default injectCss;': 'export default (css) => window.xCSSInjector.addStyle({ source: css });',
|
|
5
|
-
delimiters: ['', '']
|
|
6
|
-
},
|
|
7
|
-
styles: {
|
|
8
|
-
mode: ['inject', (varname) => `window.xCSSInjector.addStyle({ source: ${varname} });`]
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
export { rollupCssInjectorConfig };
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const webpackConfig = {
|
|
2
|
-
transpileDependencies: ['@empathyco/x-components'],
|
|
3
|
-
configureWebpack: {
|
|
4
|
-
module: {
|
|
5
|
-
rules: [
|
|
6
|
-
{
|
|
7
|
-
test: /\.ts|js|vue$/,
|
|
8
|
-
enforce: 'pre',
|
|
9
|
-
use: ['source-map-loader']
|
|
10
|
-
}
|
|
11
|
-
]
|
|
12
|
-
},
|
|
13
|
-
output: {
|
|
14
|
-
devtoolModuleFilenameTemplate: ({ resourcePath, hash, query }) => resourcePath.match(/\.vue$/) &&
|
|
15
|
-
!query.match(/type=script/) &&
|
|
16
|
-
!query.match(/\?rollup-plugin-vue=script.ts/)
|
|
17
|
-
? `webpack-generated:///${resourcePath}?${hash}`
|
|
18
|
-
: `sources://${resourcePath}`,
|
|
19
|
-
devtoolFallbackModuleFilenameTemplate: 'webpack:///[resource-path]?[hash]'
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export { webpackConfig };
|