vueless 0.0.190 → 0.0.192

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.
@@ -8,15 +8,35 @@ import {
8
8
  Text,
9
9
  Fragment,
10
10
  } from "vue";
11
- import { cx, globalComponentConfig, strategy, getColor, setColor } from "../service.ui";
11
+
12
+ import {
13
+ cx,
14
+ setColor,
15
+ getColor,
16
+ strategy,
17
+ nestedComponentRegEx,
18
+ globalComponentConfig,
19
+ } from "../service.ui";
20
+
12
21
  import { cloneDeep } from "../service.helper";
13
22
 
14
- const strategyType = {
23
+ const STRATEGY_TYPE = {
15
24
  merge: "merge",
16
25
  replace: "replace",
17
26
  overwrite: "overwrite",
18
27
  };
19
28
 
29
+ const SYSTEM_CONFIG_KEY = {
30
+ i18n: "i18n",
31
+ strategy: "strategy",
32
+ safelist: "safelist",
33
+ safelistColors: "safelistColors",
34
+ defaultVariants: "defaultVariants",
35
+ compoundVariants: "compoundVariants",
36
+ iconNameCapitalize: "IconName",
37
+ iconName: "iconName",
38
+ };
39
+
20
40
  /**
21
41
  Merging component configs in a given sequence (bigger number = bigger priority):
22
42
  1. Default component config
@@ -28,8 +48,8 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
28
48
  const { name: componentName } = getCurrentInstance().type;
29
49
  const globalConfig = globalComponentConfig[componentName];
30
50
 
31
- const isStrategyValid = strategy && Object.values(strategyType).includes(strategy);
32
- const vuelessStrategy = isStrategyValid ? strategy : strategyType.merge;
51
+ const isStrategyValid = strategy && Object.values(STRATEGY_TYPE).includes(strategy);
52
+ const vuelessStrategy = isStrategyValid ? strategy : STRATEGY_TYPE.merge;
33
53
 
34
54
  const [firstClassKey] = Object.keys(defaultConfig);
35
55
  const config = ref({});
@@ -50,7 +70,7 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
50
70
 
51
71
  function getAttrs(configKey, options) {
52
72
  const cvaClasses = options?.classes || "";
53
- const isComponent = options?.isComponent;
73
+ const nestedComponent = options?.isComponent || getNestedComponent(defaultConfig[configKey]); // TODO: Remove `options?.isComponent` when all `attrs.composable.js` will be migranted
54
74
 
55
75
  const attrs = useAttrs();
56
76
  const isDev = import.meta.env.DEV;
@@ -60,7 +80,7 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
60
80
  ...attrs,
61
81
  component: isDev ? attrs.component || componentName || null : null,
62
82
  "config-key": isDev ? attrs["config-key"] || configKey || null : null,
63
- "child-component": isDev && attrs.component ? componentName : null,
83
+ "child-component": isDev && attrs.component ? nestedComponent || componentName : null,
64
84
  "child-config-key": isDev && attrs.component ? configKey : null,
65
85
  };
66
86
 
@@ -78,7 +98,7 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
78
98
 
79
99
  const isTopLevelClassKey = configKey === (topLevelClassKey || firstClassKey);
80
100
 
81
- const attrClass = isTopLevelClassKey && !isComponent ? attrs.class : "";
101
+ const attrClass = isTopLevelClassKey && !nestedComponent ? attrs.class : "";
82
102
  const configKeyClass = isObject ? configKeyValue.base : configKeyValue;
83
103
 
84
104
  vuelessAttrs.value = {
@@ -96,6 +116,7 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
96
116
  getAttrs,
97
117
  getColor,
98
118
  setColor,
119
+ isSystemKey,
99
120
  hasSlotContent,
100
121
  };
101
122
  }
@@ -114,18 +135,18 @@ function getMergedConfig({ defaultConfig, globalConfig, propsConfig, vuelessStra
114
135
 
115
136
  const strategy =
116
137
  !globalConfig && !propsConfig
117
- ? strategyType.merge
138
+ ? STRATEGY_TYPE.merge
118
139
  : propsConfig?.strategy || globalConfig?.strategy || vuelessStrategy;
119
140
 
120
- if (strategy === strategyType.merge) {
141
+ if (strategy === STRATEGY_TYPE.merge) {
121
142
  return mergeConfigs({ defaultConfig, globalConfig, propsConfig });
122
143
  }
123
144
 
124
- if (strategy === strategyType.replace) {
145
+ if (strategy === STRATEGY_TYPE.replace) {
125
146
  return mergeConfigs({ defaultConfig, globalConfig, propsConfig, isReplace: true });
126
147
  }
127
148
 
128
- if (strategy === strategyType.overwrite) {
149
+ if (strategy === STRATEGY_TYPE.overwrite) {
129
150
  const isGlobalConfig = globalConfig && Object.keys(globalConfig).length;
130
151
  const isPropsConfig = propsConfig && Object.keys(propsConfig).length;
131
152
 
@@ -173,18 +194,29 @@ function mergeConfigs({
173
194
  }
174
195
  }
175
196
 
197
+ const {
198
+ i18n,
199
+ strategy,
200
+ safelist,
201
+ safelistColors,
202
+ defaultVariants,
203
+ compoundVariants,
204
+ iconNameCapitalize,
205
+ iconName,
206
+ } = SYSTEM_CONFIG_KEY;
207
+
176
208
  for (let key in composedConfig) {
177
209
  if (isGlobalConfig || isPropsConfig) {
178
- if (key === "strategy") {
210
+ if (key === strategy) {
179
211
  config[key] = propsConfig[key] || globalConfig[key] || defaultConfig[key];
180
- } else if (key === "safelist" || key === "safelistColors") {
212
+ } else if (key === safelist || key === safelistColors) {
181
213
  if (propsConfig[key]) {
182
214
  // eslint-disable-next-line no-console
183
215
  console.warn(`Passing '${key}' key by 'config' prop is not allowed.`);
184
216
  }
185
- } else if (key === "defaultVariants") {
217
+ } else if (key === defaultVariants) {
186
218
  config[key] = { ...defaultConfig[key], ...globalConfig[key], ...propsConfig[key] };
187
- } else if (key === "compoundVariants") {
219
+ } else if (key === compoundVariants) {
188
220
  config[key] = mergeCompoundVariants({
189
221
  defaultConfig: composedConfig,
190
222
  globalConfig,
@@ -199,8 +231,8 @@ function mergeConfigs({
199
231
 
200
232
  const isObject = isObjectComposedConfig || isObjectGlobalConfig || isObjectPropsConfig;
201
233
  const isEmpty = composedConfig[key] === null;
202
- const isIconName = /^.*(iconName|IconName)$/.test(key);
203
- const isI18n = key === "i18n";
234
+ const isIconName = key.includes(iconName) || key.includes(iconNameCapitalize);
235
+ const isI18n = key === i18n;
204
236
 
205
237
  config[key] =
206
238
  isObject && !isEmpty && !isI18n
@@ -327,6 +359,27 @@ function mergeClassesIntoConfig(config, topLevelClassKey, attrs) {
327
359
  return config;
328
360
  }
329
361
 
362
+ /**
363
+ Check is config key contains component name and if contains return it.
364
+ @param { String | Object } value
365
+ @returns { String }
366
+ */
367
+ function getNestedComponent(value) {
368
+ const classes = typeof value === "object" ? value.base || "" : value || "";
369
+ const match = classes.match(nestedComponentRegEx);
370
+
371
+ return match ? match[1] : "";
372
+ }
373
+
374
+ /**
375
+ Check is config key not contains classes or CVA config object.
376
+ @param { String } key
377
+ @returns { Boolean }
378
+ */
379
+ function isSystemKey(key) {
380
+ return Object.values(SYSTEM_CONFIG_KEY).some((value) => value.includes(key));
381
+ }
382
+
330
383
  /**
331
384
  Check if slot defined, and have a content.
332
385
  @param slot
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.190",
3
+ "version": "0.0.192",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -16,8 +16,12 @@ const [vuelessConfig] = Object.values(
16
16
  import.meta.glob("/vueless.config.js", { eager: true, import: "default" }),
17
17
  );
18
18
 
19
+ export const nestedComponentRegEx = /\{U[^}]*}/g;
20
+
19
21
  /*
20
- Export cva (class variance authority) methods extended with tailwind-merge.
22
+ Export cva (class variance authority) methods:
23
+ * extended with tailwind-merge
24
+ * remove all Vueless nested component names ({U...} strings) from class list string.
21
25
  It helps to make class variation switchers and removes class duplications.
22
26
  https://beta.cva.style
23
27
  */
@@ -26,7 +30,7 @@ export const {
26
30
  cx,
27
31
  compose,
28
32
  } = defineConfig({
29
- hooks: { onComplete: (className) => twMerge(className) },
33
+ hooks: { onComplete: (className) => twMerge(className).replace(nestedComponentRegEx, "") },
30
34
  });
31
35
 
32
36
  export const cva = ({ base = "", variants = {}, compoundVariants = [], defaultVariants = {} }) =>
@@ -212,23 +216,6 @@ export default class UIService {
212
216
  setColor(classes, color) {
213
217
  return classes?.replaceAll("{color}", color);
214
218
  }
215
-
216
- /**
217
- Check is config key not contains classes or CVA config object.
218
- @param { String } key
219
- @returns { Boolean }
220
- */
221
- isSystemKey(key) {
222
- return (
223
- key === "i18n" ||
224
- key === "strategy" ||
225
- key === "safelist" ||
226
- key === "safelistColors" ||
227
- key === "defaultVariants" ||
228
- key.includes("iconName") ||
229
- key.includes("IconName")
230
- );
231
- }
232
219
  }
233
220
 
234
221
  export const {
@@ -1,12 +1,13 @@
1
1
  import { computed } from "vue";
2
2
  import useUI from "../../composable.ui";
3
- import { cva, isSystemKey } from "../../service.ui";
3
+ import { cva } from "../../service.ui";
4
4
  import defaultConfig from "../configs/default.config";
5
5
 
6
- const componentKeys = ["icon", "divider"];
7
-
8
6
  export function useAttrs(props, { isOpened }) {
9
- const { config, getAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
7
+ const { config, getAttrs, hasSlotContent, isSystemKey } = useUI(
8
+ defaultConfig,
9
+ () => props.config,
10
+ );
10
11
  const attrs = {};
11
12
 
12
13
  for (const key in defaultConfig) {
@@ -26,7 +27,7 @@ export function useAttrs(props, { isOpened }) {
26
27
  );
27
28
  }
28
29
 
29
- attrs[`${key}Attrs`] = getAttrs(key, { classes, isComponent: componentKeys.includes(key) });
30
+ attrs[`${key}Attrs`] = getAttrs(key, { classes });
30
31
  }
31
32
 
32
33
  return {
@@ -24,10 +24,10 @@ export default /*tw*/ {
24
24
  },
25
25
  },
26
26
  },
27
- icon: "",
27
+ icon: "{UIcon}",
28
28
  expandIconName: "add",
29
29
  collapseIconName: "remove",
30
- divider: "group-last:hidden",
30
+ divider: "{UDivider} group-last:hidden",
31
31
  defaultVariants: {
32
32
  size: "md",
33
33
  },
@@ -1,12 +1,13 @@
1
1
  import { computed } from "vue";
2
2
  import useUI from "../../composable.ui";
3
- import { cva, cx, isSystemKey } from "../../service.ui";
3
+ import { cva, cx } from "../../service.ui";
4
4
  import defaultConfig from "../configs/default.config";
5
5
 
6
- const componentKeys = ["dropdownList", "toggleIcon", "clearIcon", "removeItemIcon", "label"];
7
-
8
6
  export default function useAttrs(props, { isTop, isOpen, selectedLabel: selectedLabelValue }) {
9
- const { config, getAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
7
+ const { config, getAttrs, hasSlotContent, isSystemKey } = useUI(
8
+ defaultConfig,
9
+ () => props.config,
10
+ );
10
11
  const attrs = {};
11
12
 
12
13
  const caretClasses = computed(() =>
@@ -35,7 +36,7 @@ export default function useAttrs(props, { isTop, isOpen, selectedLabel: selected
35
36
  );
36
37
  }
37
38
 
38
- attrs[`${key}Attrs`] = getAttrs(key, { classes, isComponent: componentKeys.includes(key) });
39
+ attrs[`${key}Attrs`] = getAttrs(key, { classes });
39
40
 
40
41
  if (key === "wrapper") {
41
42
  const wrapperAttrs = attrs[`${key}Attrs`];
@@ -1,5 +1,5 @@
1
1
  export default /*tw*/ {
2
- label: "w-full relative",
2
+ label: "{ULabel} w-full relative",
3
3
  wrapper: {
4
4
  base: `
5
5
  pb-2 pt-2 flex flex-row-reverse justify-between w-full min-h-full box-border relative
@@ -55,11 +55,11 @@ export default /*tw*/ {
55
55
  beforeCaretSlot: "",
56
56
  afterCaretSlot: "mr-3",
57
57
  caretToggle: "mr-3",
58
- toggleIcon: "transform transition duration-300 group-[]/active:rotate-180",
58
+ toggleIcon: "{UIcon} transform transition duration-300 group-[]/active:rotate-180",
59
59
  toggleIconName: "expand_more",
60
- clearIcon: "",
60
+ clearIcon: "{UIcon}",
61
61
  clearIconName: "close_small",
62
- removeItemIcon: "",
62
+ removeItemIcon: "{UIcon}",
63
63
  removeItemIconName: "close_small",
64
64
  caretRemoveItem: "flex items-center",
65
65
  caretClear: "",
@@ -112,7 +112,7 @@ export default /*tw*/ {
112
112
  { size: "lg", multiple: true, class: "text-lg" },
113
113
  ],
114
114
  },
115
- dropdownList: "group-[]/top:bottom-full group-[]/top:top-auto top-full",
115
+ dropdownList: "{UDropdownList} group-[]/top:bottom-full group-[]/top:top-auto top-full",
116
116
  i18n: {
117
117
  listIsEmpty: "List is empty.",
118
118
  noDataToShow: "No data to show.",
@@ -47,5 +47,6 @@ export function useAttrs(props) {
47
47
  return {
48
48
  loaderAttrs,
49
49
  ellipseAttrs,
50
+ config,
50
51
  };
51
52
  }
@@ -41,9 +41,17 @@ export default /*tw*/ {
41
41
  },
42
42
  },
43
43
  },
44
+ loaderTransition: {
45
+ moveClass: "transition duration-500",
46
+ enterActiveClass: "transition duration-500",
47
+ leaveActiveClass: "transition duration-500 absolute",
48
+ enterFromClass: "opacity-0",
49
+ leaveToClass: "opacity-0",
50
+ },
44
51
  defaultVariants: {
45
52
  color: "brand",
46
53
  size: "md",
54
+ loading: true,
47
55
  },
48
56
  safelist: (colors) => [{ pattern: `bg-(${colors})-600` }],
49
57
  };
@@ -1,7 +1,13 @@
1
1
  <template>
2
- <div v-bind="loaderAttrs">
3
- <div v-for="ellipse in ELLIPSES_AMOUNT" :key="ellipse" v-bind="ellipseAttrs(ellipseClasses)" />
4
- </div>
2
+ <Transition v-bind="config.loaderTransition">
3
+ <div v-if="!loading" v-bind="loaderAttrs">
4
+ <div
5
+ v-for="ellipse in ELLIPSES_AMOUNT"
6
+ :key="ellipse"
7
+ v-bind="ellipseAttrs(ellipseClasses)"
8
+ />
9
+ </div>
10
+ </Transition>
5
11
  </template>
6
12
 
7
13
  <script setup>
@@ -33,11 +39,19 @@ const props = defineProps({
33
39
  type: String,
34
40
  default: UIService.get(defaultConfig, ULoader).default.color,
35
41
  },
42
+
43
+ /**
44
+ * Turn off/on loader.
45
+ */
46
+ loading: {
47
+ type: Boolean,
48
+ default: UIService.get(defaultConfig, ULoader).default.loading,
49
+ },
36
50
  });
37
51
 
38
52
  const ELLIPSES_AMOUNT = 4;
39
53
 
40
- const { loaderAttrs, ellipseAttrs } = useAttrs(props);
54
+ const { loaderAttrs, ellipseAttrs, config } = useAttrs(props);
41
55
 
42
56
  const ellipseClasses = computed(() => [
43
57
  "vueless-internal-loader-ellipse",
@@ -23,7 +23,7 @@ export function useAttrs(props) {
23
23
  ),
24
24
  );
25
25
 
26
- const wrapperAttrs = getAttrs("wrapper", { classes: wrapperClasses });
26
+ const wrapperAttrs = getAttrs("wrapper", { classes: wrapperClasses, isComponent: true });
27
27
 
28
28
  return {
29
29
  wrapperAttrs,
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.190",
4
+ "version": "0.0.192",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",
@@ -4746,6 +4746,15 @@
4746
4746
  "type": "'brand' | 'grayscale' | 'gray' | 'red' | 'orange' | 'amber' | 'yellow' | 'lime' | 'green' | 'emerald' | 'teal' | 'cyan' | 'sky' | 'blue' | 'indigo' | 'violet' | 'purple' | 'fuchsia' | 'pink' | 'rose' | 'white'"
4747
4747
  },
4748
4748
  "default": "brand"
4749
+ },
4750
+ {
4751
+ "name": "loading",
4752
+ "description": "Turn off/on loader.",
4753
+ "value": {
4754
+ "kind": "expression",
4755
+ "type": "boolean"
4756
+ },
4757
+ "default": "true"
4749
4758
  }
4750
4759
  ],
4751
4760
  "source": {