@awes-io/ui 2.63.0 → 2.63.2

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 CHANGED
@@ -3,6 +3,28 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [2.63.2](https://github.com/awes-io/client/compare/@awes-io/ui@2.63.1...@awes-io/ui@2.63.2) (2023-04-25)
7
+
8
+
9
+ ### Bug Fixes
10
+
11
+ * **ui:** dayjs locales mapped to i18n locales ([2b9ddd2](https://github.com/awes-io/client/commit/2b9ddd2e86a30a2fe56f85e72eb6e17e8eb8ad36))
12
+
13
+
14
+
15
+
16
+
17
+ ## [2.63.1](https://github.com/awes-io/client/compare/@awes-io/ui@2.63.0...@awes-io/ui@2.63.1) (2023-04-25)
18
+
19
+
20
+ ### Bug Fixes
21
+
22
+ * **ui:** dayjs locales autoload checks locale availability ([270a388](https://github.com/awes-io/client/commit/270a388ff2535d61bcbd91460432e46e4cd9b7f4))
23
+
24
+
25
+
26
+
27
+
6
28
  # [2.63.0](https://github.com/awes-io/client/compare/@awes-io/ui@2.62.0...@awes-io/ui@2.63.0) (2023-04-07)
7
29
 
8
30
 
package/nuxt/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { mergeDeepRight, pick, omit, uniq, endsWith, partition } from 'rambdax'
2
2
  import { existsSync, readdirSync, readFileSync, lstatSync } from 'fs'
3
- import { join, resolve, sep } from 'path'
3
+ import { join, resolve, sep, dirname } from 'path'
4
4
  import resolveConfig from 'tailwindcss/resolveConfig'
5
5
  import {
6
6
  default as configDefault,
@@ -12,6 +12,8 @@ import {
12
12
  } from './awes.config.js'
13
13
  import defaultTailwindConfig from '../tailwind.config.js'
14
14
 
15
+ const DEFAULT_DAYJS_LOCALE = 'en'
16
+
15
17
  const configDark = mergeDeepRight(configDefault, dark)
16
18
 
17
19
  export const MODULE_DIR = 'awes-io'
@@ -22,6 +24,28 @@ const fixWindowsPath = (path) =>
22
24
  .replace(/\\/g, '/')
23
25
  .replace(/\/\/+/g, '/')
24
26
 
27
+ const availableDayjsLocales = readdirSync(
28
+ join(dirname(require.resolve('dayjs')), 'locale')
29
+ )
30
+
31
+ const getDayjsLang = (code) => {
32
+ const fileName = code.toLowerCase() + '.js'
33
+
34
+ if (availableDayjsLocales.includes(fileName)) {
35
+ return fileName
36
+ }
37
+
38
+ const shortened = code.toLowerCase().substr(0, 2) + '.js'
39
+
40
+ if (availableDayjsLocales.includes(shortened)) {
41
+ return shortened
42
+ }
43
+
44
+ return false
45
+ }
46
+
47
+ const getDayjsLocaleNameFromFile = (file) => file.replace('.js', '')
48
+
25
49
  async function AwesIoUi() {
26
50
  /**
27
51
  * Check store existance
@@ -100,6 +124,28 @@ async function AwesIoUi() {
100
124
  }
101
125
  }
102
126
 
127
+ const localesMap = {}
128
+
129
+ const dayjsLocaleFiles = this.options.awesIo.lang.locales.reduce(
130
+ (acc, locale) => {
131
+ const _locale = locale.code || locale
132
+ const file = getDayjsLang(_locale)
133
+
134
+ localesMap[_locale] = getDayjsLocaleNameFromFile(file) || DEFAULT_DAYJS_LOCALE
135
+
136
+ return file ? acc.concat(file) : acc
137
+ },
138
+ []
139
+ )
140
+
141
+ this.options.awesIo.dayjs.localesMap = localesMap
142
+
143
+ this.options.awesIo.dayjs.langs = uniq(dayjsLocaleFiles).map((file) => {
144
+ const name = getDayjsLocaleNameFromFile(file)
145
+
146
+ return { name, variable: 'locale_' + name.replace('-', '_'), file }
147
+ })
148
+
103
149
  /**
104
150
  * Add font
105
151
  */
@@ -11,12 +11,11 @@ import <%=name%> from '<%=src%>'
11
11
  dayjs.extend(<%=name%>, <%=JSON.stringify(options)%>)
12
12
  <% }) %>
13
13
 
14
- <% if (options.lang && Array.isArray(options.lang.locales)) { %>
15
- <% options.lang.locales.forEach((locale) => {
16
- const code = locale.code || locale
14
+ <% if (options.dayjs.langs && Array.isArray(options.dayjs.langs)) { %>
15
+ <% options.dayjs.langs.forEach(({ name, variable, file }) => {
17
16
  %>
18
- import dayjsLocale<%=code%> from 'dayjs/locale/<%=code%>.js'
19
- dayjs.locale('<%=code%>', dayjsLocale<%=code%>)
17
+ import <%=variable%> from 'dayjs/locale/<%=file%>'
18
+ dayjs.locale('<%=name%>', <%=variable%>)
20
19
  <% }) %>
21
20
  <% } %>
22
21
  /* eslint-enable */
@@ -76,12 +75,14 @@ dayjs.locale('en')
76
75
 
77
76
  // dayjs.extend(defaultStringFormat, <%=JSON.stringify(options.dayjs.stringFormat)%>)
78
77
 
78
+ const localesMap = JSON.parse('<%=JSON.stringify(options.dayjs.localesMap)%>')
79
+
79
80
  export default function({ app: { i18n } }, inject) {
80
81
  i18n.onLanguageSwitched(async newLocale => {
81
- dayjs.locale(newLocale)
82
+ dayjs.locale(localesMap[newLocale])
82
83
  })
83
84
 
84
- dayjs.locale(i18n.locale)
85
+ dayjs.locale(localesMap[i18n.locale])
85
86
 
86
87
  Vue.prototype.$dayjs = dayjs
87
88
  inject('dayjs', dayjs)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@awes-io/ui",
3
- "version": "2.63.0",
3
+ "version": "2.63.2",
4
4
  "description": "User Interface (UI) components",
5
5
  "keywords": [
6
6
  "ui",
@@ -122,5 +122,5 @@
122
122
  "vue-template-compiler": "^2.6.10",
123
123
  "webfonts-generator": "^0.4.0"
124
124
  },
125
- "gitHead": "ba7458d978c7da739cb46dccdeac9f4a885c8cb2"
125
+ "gitHead": "d08ca39dcb2fb44ab52209078eace98adbebb81e"
126
126
  }