vueless 0.0.381 → 0.0.383

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.
@@ -22,11 +22,11 @@ import {
22
22
  } from "../constants.js";
23
23
 
24
24
  /**
25
- Merging component configs in a given sequence (bigger number = bigger priority):
26
- 1. Default component config
27
- 2. Custom global component config (/vueless.config.js)
28
- 3. Component config (:config="{...}" props)
29
- 4. Component classes (class="...")
25
+ * Merging component configs in a given sequence (bigger number = bigger priority):
26
+ * 1. Default component config
27
+ * 2. Custom global component config (/vueless.config.js)
28
+ * 3. Component config (:config="{...}" props)
29
+ * 4. Component classes (class="...")
30
30
  */
31
31
  export default function useUI(defaultConfig = {}, propsConfigGetter = null, topLevelClassKey) {
32
32
  const { type, props } = getCurrentInstance();
@@ -109,7 +109,7 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
109
109
  * @param keysToExtendConfig
110
110
  * @returns {Object}
111
111
  */
112
- function getKeysAttrs(mutatedProps, extendingKeys = [], keysToExtendConfig = {}) {
112
+ function getKeysAttrs(mutatedProps = {}, extendingKeys = [], keysToExtendConfig = {}) {
113
113
  const keysToExtend = Object.keys(keysToExtendConfig);
114
114
  const keysAttrs = {};
115
115
 
@@ -124,7 +124,6 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
124
124
  const { base, extend } = keysToExtendConfig[key];
125
125
  const keyAttrs = keysAttrs[`${key}Attrs`];
126
126
 
127
- // TODO: if value of the key contains keys related to the nested nested component it should be skipped
128
127
  keysAttrs[`${key}Attrs`] = computed(() => ({
129
128
  ...keyAttrs.value,
130
129
  class: cx([
@@ -210,13 +209,13 @@ export default function useUI(defaultConfig = {}, propsConfigGetter = null, topL
210
209
  }
211
210
 
212
211
  /**
213
- Get merged config based on config merging strategy.
214
- @param {Object} defaultConfig
215
- @param {Object} globalConfig
216
- @param {Object} propsConfig
217
- @param {string} vuelessStrategy - vueless top level merge strategy.
218
-
219
- @returns {Object}
212
+ * Get merged config based on config merging strategy.
213
+ * @param {Object} defaultConfig
214
+ * @param {Object} globalConfig
215
+ * @param {Object} propsConfig
216
+ * @param {string} vuelessStrategy - vueless top level merge strategy.
217
+ *
218
+ * @returns {Object}
220
219
  */
221
220
  function getMergedConfig({ defaultConfig, globalConfig, propsConfig, vuelessStrategy }) {
222
221
  defaultConfig = cloneDeep(defaultConfig);
@@ -243,15 +242,15 @@ function getMergedConfig({ defaultConfig, globalConfig, propsConfig, vuelessStra
243
242
  }
244
243
 
245
244
  /**
246
- Recursively merge config objects with removing tailwind classes duplicates.
247
- @param {Object} defaultConfig
248
- @param {Object} globalConfig
249
- @param {Object} propsConfig
250
- @param {Object} config - final merged config.
251
- @param {boolean} isReplace - enables class replacement instead of merge.
252
- @param {boolean} isVarinants - if true, prevents adding a "base" key into nested objects.
253
-
254
- @returns {Object}
245
+ * Recursively merge config objects with removing tailwind classes duplicates.
246
+ * @param {Object} defaultConfig
247
+ * @param {Object} globalConfig
248
+ * @param {Object} propsConfig
249
+ * @param {Object} config - final merged config.
250
+ * @param {boolean} isReplace - enables class replacement instead of merge.
251
+ * @param {boolean} isVarinants - if true, prevents adding a "base" key into nested objects.
252
+ *
253
+ * @returns {Object}
255
254
  */
256
255
  function mergeConfigs({
257
256
  defaultConfig,
@@ -369,14 +368,14 @@ function stringToObject(value, { addBase = false }) {
369
368
  }
370
369
 
371
370
  /**
372
- Merge CVA compound variants arrays.
373
- @param {Object} defaultConfig
374
- @param {Object} globalConfig
375
- @param {Object} propsConfig
376
- @param {string} key
377
- @param {boolean} isReplace - enables class replacement instead of merge.
378
-
379
- @returns {Array}
371
+ * Merge CVA compound variants arrays.
372
+ * @param {Object} defaultConfig
373
+ * @param {Object} globalConfig
374
+ * @param {Object} propsConfig
375
+ * @param {string} key
376
+ * @param {boolean} isReplace - enables class replacement instead of merge.
377
+ *
378
+ * @returns {Array}
380
379
  */
381
380
  function mergeCompoundVariants({ defaultConfig, globalConfig, propsConfig, key, isReplace }) {
382
381
  if (
@@ -393,9 +392,9 @@ function mergeCompoundVariants({ defaultConfig, globalConfig, propsConfig, key,
393
392
 
394
393
  const config = defaultConfig[key].map((defaultConfigItem) => {
395
394
  /**
396
- Compare two objects by keys for match.
397
- @param {Object} configItem
398
- @returns {Boolean}
395
+ * Compare two objects by keys for match.
396
+ * @param {Object} configItem
397
+ * @returns {Boolean}
399
398
  */
400
399
  function isSameItem(configItem) {
401
400
  const hasConfigItemKeys = Object.keys(defaultConfigItem)
@@ -410,9 +409,9 @@ function mergeCompoundVariants({ defaultConfig, globalConfig, propsConfig, key,
410
409
  }
411
410
 
412
411
  /**
413
- Find the same compound variant item in custom config if exist.
414
- @param {Object} config
415
- @returns {Object|undefined}
412
+ * Find the same compound variant item in custom config if exist.
413
+ * @param {Object} config
414
+ * @returns {Object|undefined}
416
415
  */
417
416
  function findItem(config = []) {
418
417
  const globalConfigUniqueItemIndex = globalConfigUniqueItems.findIndex(isSameItem);
@@ -446,12 +445,12 @@ function mergeCompoundVariants({ defaultConfig, globalConfig, propsConfig, key,
446
445
  }
447
446
 
448
447
  /**
449
- Merge component classes from "class" attribute into final config.
450
- @param {Object} config
451
- @param {Object} attrs
452
- @param {string} topLevelClassKey
453
-
454
- @returns {Object}
448
+ * Merge component classes from "class" attribute into final config.
449
+ * @param {Object} config
450
+ * @param {Object} attrs
451
+ * @param {string} topLevelClassKey
452
+ *
453
+ * @returns {Object}
455
454
  */
456
455
  function mergeClassesIntoConfig(config, topLevelClassKey, attrs) {
457
456
  if (typeof config[topLevelClassKey] === "object") {
@@ -464,18 +463,18 @@ function mergeClassesIntoConfig(config, topLevelClassKey, attrs) {
464
463
  }
465
464
 
466
465
  /**
467
- Return base classes.
468
- @param { String | Object } value
469
- @returns { String }
466
+ * Return base classes.
467
+ * @param { String | Object } value
468
+ * @returns { String }
470
469
  */
471
470
  function getBaseClasses(value) {
472
471
  return typeof value === "object" ? value.base || "" : value || "";
473
472
  }
474
473
 
475
474
  /**
476
- Check is config key contains component name and if contains return it.
477
- @param { String | Object } value
478
- @returns { String }
475
+ * Check is config key contains component name and if contains return it.
476
+ * @param { String | Object } value
477
+ * @returns { String }
479
478
  */
480
479
  function getNestedComponent(value) {
481
480
  const classes = getBaseClasses(value);
@@ -487,9 +486,9 @@ function getNestedComponent(value) {
487
486
  }
488
487
 
489
488
  /**
490
- Check is config key not contains classes or CVA config object.
491
- @param { String } key
492
- @returns { Boolean }
489
+ * Check is config key not contains classes or CVA config object.
490
+ * @param { String } key
491
+ * @returns { Boolean }
493
492
  */
494
493
  function isSystemKey(key) {
495
494
  const isExactKey = Object.values(SYSTEM_CONFIG_KEY).some((value) => value === key);
@@ -498,9 +497,9 @@ function isSystemKey(key) {
498
497
  }
499
498
 
500
499
  /**
501
- Check is config contains default CVA keys.
502
- @param { Object | String } config
503
- @returns { Boolean }
500
+ * Check is config contains default CVA keys.
501
+ * @param { Object | String } config
502
+ * @returns { Boolean }
504
503
  */
505
504
  function isCVA(config) {
506
505
  if (typeof config !== "object") return false;
@@ -511,11 +510,11 @@ function isCVA(config) {
511
510
  }
512
511
 
513
512
  /**
514
- Check if slot defined, and have a content.
515
- @param slot
516
- @param props
517
-
518
- @returns {boolean}
513
+ * Check if slot defined, and have a content.
514
+ * @param slot
515
+ * @param props
516
+ *
517
+ * @returns {boolean}
519
518
  */
520
519
  function hasSlotContent(slot, props = {}) {
521
520
  const asArray = (arg) => (Array.isArray(arg) ? arg : arg != null ? [arg] : []);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.381",
3
+ "version": "0.0.383",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless Component Framework.",
6
6
  "homepage": "https://vueless.com",
@@ -1,50 +1,28 @@
1
+ import { computed } from "vue";
1
2
  import useUI from "../composables/useUI.js";
2
- import { cva } from "../utils/utilUI.js";
3
+
3
4
  import defaultConfig from "./config.js";
4
- import { computed } from "vue";
5
5
 
6
6
  export default function useAttrs(props, { selected }) {
7
- const { config, getAttrs, isSystemKey, hasSlotContent, isCVA } = useUI(
8
- defaultConfig,
9
- () => props.config,
10
- );
11
- const attrs = {};
12
-
13
- for (const key in defaultConfig) {
14
- if (isSystemKey(key)) continue;
15
-
16
- const classes = computed(() => {
17
- let value = config.value[key];
7
+ const { config, getKeysAttrs, hasSlotContent } = useUI(defaultConfig, () => props.config);
18
8
 
19
- if (isCVA(value)) {
20
- value = cva(value)({
21
- ...props,
22
- });
23
- }
9
+ const keysAttrs = getKeysAttrs();
24
10
 
25
- return value;
26
- });
11
+ const { checkboxAttrs } = keysAttrs;
27
12
 
28
- attrs[`${key}Attrs`] = getAttrs(key, { classes });
29
-
30
- if (key === "checkbox") {
31
- const checkboxAttrs = attrs[`${key}Attrs`];
32
-
33
- attrs[`${key}Attrs`] = computed(() => {
34
- if (selected.value.icon) {
35
- checkboxAttrs.value.config = checkboxAttrs.value.config || {};
36
- checkboxAttrs.value.config.defaults = checkboxAttrs.value.config.defaults || {};
37
- checkboxAttrs.value.config.defaults.checkedIcon = selected.value.icon;
38
- }
39
-
40
- return checkboxAttrs.value;
41
- });
13
+ keysAttrs.checkboxAttrs = computed(() => {
14
+ if (selected.value.icon) {
15
+ checkboxAttrs.value.config = checkboxAttrs.value.config || {};
16
+ checkboxAttrs.value.config.defaults = checkboxAttrs.value.config.defaults || {};
17
+ checkboxAttrs.value.config.defaults.checkedIcon = selected.value.icon;
42
18
  }
43
- }
19
+
20
+ return checkboxAttrs.value;
21
+ });
44
22
 
45
23
  return {
46
- ...attrs,
47
24
  config,
25
+ ...keysAttrs,
48
26
  hasSlotContent,
49
27
  };
50
28
  }
@@ -1,9 +1,9 @@
1
1
  /**
2
- Deeply clone given object (same as lodash.cloneDeep).
3
- @param {Object} entity
4
- @param cache
5
-
6
- @returns {Object}
2
+ * Deeply clone given object (same as lodash.cloneDeep).
3
+ * @param {Object} entity
4
+ * @param cache
5
+ *
6
+ * @returns {Object}
7
7
  */
8
8
  export function cloneDeep(entity, cache = new WeakMap()) {
9
9
  // primitives
@@ -38,11 +38,11 @@ export function cloneDeep(entity, cache = new WeakMap()) {
38
38
  }
39
39
 
40
40
  /**
41
- Creates a debounced function with delay (same as lodash.debounce).
42
- @param {Function} func
43
- @param {Number} ms
44
-
45
- @returns {Function}
41
+ * Creates a debounced function with delay (same as lodash.debounce).
42
+ * @param {Function} func
43
+ * @param {Number} ms
44
+ *
45
+ * @returns {Function}
46
46
  */
47
47
  export function createDebounce(func, ms) {
48
48
  let timeout;
@@ -54,13 +54,13 @@ export function createDebounce(func, ms) {
54
54
  }
55
55
 
56
56
  /**
57
- Change page title in runtime by provided config.
58
- @param {Object} config
59
- @param {string} config.title
60
- @param {string} config.separator
61
- @param {string} config.suffix
62
-
63
- @returns {VoidFunction}
57
+ * Change page title in runtime by provided config.
58
+ * @param {Object} config
59
+ * @param {string} config.title
60
+ * @param {string} config.separator
61
+ * @param {string} config.suffix
62
+ *
63
+ * @returns {VoidFunction}
64
64
  */
65
65
  export function setTitle({ title, separator = " / ", suffix = "" }) {
66
66
  if (isCSR) {
@@ -69,13 +69,13 @@ export function setTitle({ title, separator = " / ", suffix = "" }) {
69
69
  }
70
70
 
71
71
  /**
72
- Check is code rendering on the server side.
73
- @returns {boolean}
72
+ * Check is code rendering on the server side.
73
+ * @returns {boolean}
74
74
  */
75
75
  export const isSSR = typeof window === "undefined";
76
76
 
77
77
  /**
78
- Check is code rendering on the client side.
79
- @returns {boolean}
78
+ * Check is code rendering on the client side.
79
+ * @returns {boolean}
80
80
  */
81
81
  export const isCSR = typeof window !== "undefined";
@@ -144,13 +144,6 @@ export function getSource(defaultConfig) {
144
144
  return defaultConfig.replace("export default /*tw*/ ", "").replace(";", "");
145
145
  }
146
146
 
147
- // TODO: remove it when allSlotsFragment will be replaced to getSlotsFragment
148
- export const allSlotsFragment = `
149
- <template v-for="(slot, index) of slots" :key="index" v-slot:[slot]>
150
- <template v-if="args[slot + 'Slot']">{{ args[slot + 'Slot'] }}</template>
151
- </template>
152
- `;
153
-
154
147
  export function getSlotsFragment(defaultTemplate) {
155
148
  return `
156
149
  <template v-for="(slot, index) of slots" :key="index" v-slot:[slot]>
package/utils/utilUI.js CHANGED
@@ -10,9 +10,9 @@ import {
10
10
  } from "../constants.js";
11
11
 
12
12
  /**
13
- Load Vueless config from the project root.
14
- Both for server and client side renderings.
15
- IIFE for SSR is used to prevent top level await issue.
13
+ * Load Vueless config from the project root.
14
+ * Both for server and client side renderings.
15
+ * IIFE for SSR is used to prevent top level await issue.
16
16
  */
17
17
  export let vuelessConfig = {};
18
18
 
@@ -35,9 +35,9 @@ if (isCSR) {
35
35
  }
36
36
 
37
37
  /**
38
- Extend twMerge (tailwind merge) by vueless and user config:
39
- All list of rules available here:
40
- https://github.com/dcastil/tailwind-merge/blob/v2.3.0/src/lib/default-config.ts
38
+ * Extend twMerge (tailwind merge) by vueless and user config:
39
+ * All list of rules available here:
40
+ * https://github.com/dcastil/tailwind-merge/blob/v2.3.0/src/lib/default-config.ts
41
41
  */
42
42
  const twMerge = extendTailwindMerge(
43
43
  merge(
@@ -59,11 +59,11 @@ const twMerge = extendTailwindMerge(
59
59
  );
60
60
 
61
61
  /**
62
- Export cva (class variance authority) methods:
63
- * extended with tailwind-merge
64
- * remove all Vueless nested component names ({U...} strings) from class list string.
65
- Learn more here: https://beta.cva.style
66
- */
62
+ * Export cva (class variance authority) methods:
63
+ * extended with tailwind-merge
64
+ * remove all Vueless nested component names ({U...} strings) from class list string.
65
+ * Learn more here: https://beta.cva.style
66
+ */
67
67
  export const {
68
68
  cx,
69
69
  compose,
@@ -84,11 +84,11 @@ export const cva = ({ base = "", variants = {}, compoundVariants = [], defaultVa
84
84
  });
85
85
 
86
86
  /**
87
- Return default values for component props, icons, etc..
88
- @param { Object } defaultConfig
89
- @param { String } name
90
-
91
- @returns { Object }
87
+ * Return default values for component props, icons, etc..
88
+ * @param { Object } defaultConfig
89
+ * @param { String } name
90
+ *
91
+ * @returns { Object }
92
92
  */
93
93
  export function getDefault(defaultConfig, name) {
94
94
  const defaults = merge(
@@ -102,10 +102,11 @@ export function getDefault(defaultConfig, name) {
102
102
  }
103
103
 
104
104
  /**
105
- Return `grayscale` color if in component config it `brand` but in vueless config it `grayscale`
106
- Otherwise return given color.
107
- @param { String } color
108
- @returns { String }
105
+ * Return `grayscale` color if in component config it `brand` but in vueless config it `grayscale`
106
+ * Otherwise return given color.
107
+ * @param { String } color
108
+ *
109
+ * @returns { String }
109
110
  */
110
111
  export function getColor(color) {
111
112
  return (vuelessConfig.brand ?? DEFAULT_BRAND_COLOR) === GRAYSCALE_COLOR && color === BRAND_COLOR
@@ -114,11 +115,11 @@ export function getColor(color) {
114
115
  }
115
116
 
116
117
  /**
117
- Replace in tailwind classes `{color}` variable into given color.
118
- @param { String } classes
119
- @param { String } color
120
-
121
- @returns { String }
118
+ * Replace in tailwind classes `{color}` variable into given color.
119
+ * @param { String } classes
120
+ * @param { String } color
121
+ *
122
+ * @returns { String }
122
123
  */
123
124
  export function setColor(classes, color) {
124
125
  if (typeof classes !== "string") {
@@ -129,9 +130,10 @@ export function setColor(classes, color) {
129
130
  }
130
131
 
131
132
  /**
132
- Generates simple unique identifier.
133
- @param { Number } length
134
- @returns { String }
133
+ * Generates simple unique identifier.
134
+ * @param { Number } length
135
+ *
136
+ * @returns { String }
135
137
  */
136
138
  export function getRandomId(length = 15) {
137
139
  const characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
package/web-types.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "framework": "vue",
3
3
  "name": "vueless",
4
- "version": "0.0.381",
4
+ "version": "0.0.383",
5
5
  "contributions": {
6
6
  "html": {
7
7
  "description-markup": "markdown",