vueless 0.0.633 → 0.0.635

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.
@@ -125,14 +125,17 @@ export default function useUI<T>(
125
125
  const attrs = useAttrs() as KeyAttrs;
126
126
  const isDev = isCSR && import.meta.env?.DEV;
127
127
  const isTopLevelKey = (topLevelClassKey || firstClassKey) === configKey;
128
- const nestedComponent = getNestedComponent(config.value[configKey] || "");
128
+
129
+ const extendsKeyConfig = getExtendsKeyConfig(configKey);
130
+ const extendsKeyNestedComponent = getNestedComponent(extendsKeyConfig);
131
+ const keyNestedComponent = getNestedComponent(config.value[configKey]);
132
+ const nestedComponent = extendsKeyNestedComponent || keyNestedComponent || componentName;
129
133
 
130
134
  const commonAttrs: KeyAttrs = {
131
135
  ...(isTopLevelKey ? attrs : {}),
132
136
  "vl-component": isDev ? attrs["vl-component"] || componentName || null : null,
133
137
  "vl-key": isDev ? attrs["vl-key"] || configKey || null : null,
134
- "vl-child-component":
135
- isDev && attrs["vl-component"] ? nestedComponent || componentName : null,
138
+ "vl-child-component": isDev && attrs["vl-component"] ? nestedComponent : null,
136
139
  "vl-child-key": isDev && attrs["vl-component"] ? configKey : null,
137
140
  };
138
141
 
@@ -145,25 +148,25 @@ export default function useUI<T>(
145
148
  * Updating Vueless attributes.
146
149
  */
147
150
  function updateVuelessAttrs() {
148
- let configAttr: NestedComponent = {};
151
+ let keyConfig: NestedComponent = {};
149
152
 
150
153
  if (typeof config.value[configKey] === "object") {
151
- configAttr = config.value[configKey] as NestedComponent;
154
+ keyConfig = config.value[configKey] as NestedComponent;
152
155
  }
153
156
 
154
157
  const extendsClasses = getExtendsClasses(configKey);
155
- const extendsConfigAttr = getExtendsConfigAttr(configKey);
158
+ const extendsKeyConfig = getExtendsKeyConfig(configKey);
156
159
 
157
160
  vuelessAttrs.value = {
158
161
  ...commonAttrs,
159
162
  class: cx([...extendsClasses, toValue(classes)]),
160
163
  config: getMergedConfig({
161
- defaultConfig: extendsConfigAttr,
162
- globalConfig: configAttr,
164
+ defaultConfig: extendsKeyConfig,
165
+ globalConfig: keyConfig,
163
166
  }),
164
167
  ...getDefaults({
165
- ...(extendsConfigAttr.defaults || {}),
166
- ...(configAttr.defaults || {}),
168
+ ...(extendsKeyConfig.defaults || {}),
169
+ ...(keyConfig.defaults || {}),
167
170
  }),
168
171
  };
169
172
  }
@@ -195,8 +198,8 @@ export default function useUI<T>(
195
198
  * Merge extends nested component configs.
196
199
  * TODO: Add ability to merge multiple keys in one (now works for merging only 1 first key).
197
200
  */
198
- function getExtendsConfigAttr(configKey: string) {
199
- let extendsConfigAttr: NestedComponent = {};
201
+ function getExtendsKeyConfig(configKey: string) {
202
+ let extendsKeyConfig: NestedComponent = {};
200
203
 
201
204
  const propsConfig = props.config as ComponentConfig<T>;
202
205
  const extendsKeys = getExtendsKeys(config.value[configKey]);
@@ -204,14 +207,14 @@ export default function useUI<T>(
204
207
  if (extendsKeys.length) {
205
208
  const [firstKey] = extendsKeys;
206
209
 
207
- extendsConfigAttr = getMergedConfig({
210
+ extendsKeyConfig = getMergedConfig({
208
211
  defaultConfig: config.value[firstKey],
209
212
  globalConfig: globalConfig[firstKey],
210
213
  propsConfig: propsConfig[firstKey],
211
214
  }) as NestedComponent;
212
215
  }
213
216
 
214
- return extendsConfigAttr;
217
+ return extendsKeyConfig;
215
218
  }
216
219
 
217
220
  /**
@@ -242,7 +245,7 @@ export default function useUI<T>(
242
245
  /**
243
246
  * Return base classes.
244
247
  */
245
- function getBaseClasses(value: string | CVA | undefined) {
248
+ function getBaseClasses(value?: string | CVA | NestedComponent) {
246
249
  return typeof value === "object" ? value.base || "" : value || "";
247
250
  }
248
251
 
@@ -250,7 +253,7 @@ function getBaseClasses(value: string | CVA | undefined) {
250
253
  * Retrieves extends keys from patterns:
251
254
  * Example: `{>someKey} {>someOtherKey}` >>> `["someKey", "someOtherKey"]`.
252
255
  */
253
- function getExtendsKeys(configItemValue?: CVA | string): string[] {
256
+ function getExtendsKeys(configItemValue?: string | CVA | NestedComponent): string[] {
254
257
  const values = getBaseClasses(configItemValue);
255
258
  const matches = values.match(EXTENDS_PATTERN_REG_EXP);
256
259
 
@@ -260,7 +263,7 @@ function getExtendsKeys(configItemValue?: CVA | string): string[] {
260
263
  /**
261
264
  * Check is config key contains component name and returns it.
262
265
  */
263
- function getNestedComponent(value: string | CVA) {
266
+ function getNestedComponent(value?: string | CVA | NestedComponent) {
264
267
  const classes = getBaseClasses(value);
265
268
  const match = classes.match(NESTED_COMPONENT_PATTERN_REG_EXP);
266
269
 
package/constants.js CHANGED
@@ -223,7 +223,7 @@ export const VUELESS_CONFIGS_CACHED_DIR = `${VUELESS_CACHE_DIR}/configs`;
223
223
 
224
224
  /* Other */
225
225
  export const PX_IN_REM = 16;
226
- export const NESTED_COMPONENT_PATTERN_REG_EXP = /\{U[^}]*}/g;
226
+ export const NESTED_COMPONENT_PATTERN_REG_EXP = /\{(U[^}]*)}/;
227
227
  export const EXTENDS_PATTERN_REG_EXP = /\{>[^}]*}/g;
228
228
  export const DYNAMIC_COLOR_PATTERN = "{color}";
229
229
  export const TAILWIND_COLOR_OPACITY_DELIMITER = "/";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.633",
3
+ "version": "0.0.635",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
package/types.ts CHANGED
@@ -252,6 +252,7 @@ export type ComponentConfig<T> = Partial<{
252
252
  NestedComponent;
253
253
 
254
254
  export interface NestedComponent {
255
+ base?: string;
255
256
  defaults?: Record<string, string | UnknownObject>;
256
257
  [key: string]: Record<string, string | UnknownObject> | string | undefined;
257
258
  }
@@ -91,7 +91,7 @@ const mutatedProps = computed(() => ({
91
91
  selected: isSelected.value,
92
92
  }));
93
93
 
94
- const { toggleButtonAttrs, toggleButtonActiveAttrs, toggleInputAttrs } = useUI<Config>(
94
+ const { toggleButtonInactiveAttrs, toggleButtonActiveAttrs, toggleInputAttrs } = useUI<Config>(
95
95
  defaultConfig,
96
96
  mutatedProps,
97
97
  );
@@ -110,7 +110,7 @@ const { toggleButtonAttrs, toggleButtonActiveAttrs, toggleInputAttrs } = useUI<C
110
110
  :square="getToggleSquare()"
111
111
  :disabled="getToggleDisabled() || disabled"
112
112
  :no-ring="getToggleNoRing() || !getToggleSplit()"
113
- v-bind="isSelected ? toggleButtonActiveAttrs : toggleButtonAttrs"
113
+ v-bind="isSelected ? toggleButtonActiveAttrs : toggleButtonInactiveAttrs"
114
114
  @click="onClickSetValue"
115
115
  >
116
116
  <template #left>
@@ -1,15 +1,15 @@
1
1
  export default /*tw*/ {
2
2
  toggleButton: {
3
- base: "{UButton} font-normal text-gray-900",
3
+ base: "{UButton} font-normal",
4
4
  defaults: {
5
5
  variant: "thirdary",
6
+ color: "brand",
6
7
  },
7
8
  },
9
+ toggleButtonInactive: "{>toggleButton} text-gray-900",
8
10
  toggleButtonActive: {
9
- base: "{UButton} font-normal !bg-{color}-600/15",
11
+ base: "{>toggleButton} !bg-{color}-600/15",
10
12
  defaults: {
11
- variant: "thirdary",
12
- color: "brand",
13
13
  filled: true,
14
14
  },
15
15
  },
@@ -43,6 +43,8 @@ const elementId = props.id || useId();
43
43
 
44
44
  function onClickOption(option: Option) {
45
45
  emit("clickOption", option);
46
+
47
+ hideOptions();
46
48
  }
47
49
 
48
50
  function onClickButton() {
@@ -57,10 +59,6 @@ function hideOptions() {
57
59
  isShownOptions.value = false;
58
60
  }
59
61
 
60
- function onClickList() {
61
- hideOptions();
62
- }
63
-
64
62
  /**
65
63
  * Get element / nested component attributes for each config token ✨
66
64
  * Applies: `class`, `config`, redefined default `props` and dev `vl-...` attributes.
@@ -132,7 +130,6 @@ const { config, dropdownButtonAttrs, dropdownListAttrs, dropdownIconAttrs, wrapp
132
130
  :label-key="labelKey"
133
131
  v-bind="dropdownListAttrs"
134
132
  :data-test="`${dataTest}-list`"
135
- @click="onClickList"
136
133
  @click-option="onClickOption"
137
134
  />
138
135
  </div>
@@ -53,12 +53,10 @@ function hideOptions() {
53
53
  isShownOptions.value = false;
54
54
  }
55
55
 
56
- function onClickList() {
57
- hideOptions();
58
- }
59
-
60
56
  function onClickOption(option: Option) {
61
57
  emit("clickOption", option);
58
+
59
+ hideOptions();
62
60
  }
63
61
 
64
62
  /**
@@ -136,7 +134,6 @@ const { config, wrapperAttrs, dropdownLinkAttrs, dropdownListAttrs, dropdownIcon
136
134
  :label-key="labelKey"
137
135
  v-bind="dropdownListAttrs"
138
136
  :data-test="`${dataTest}-list`"
139
- @click="onClickList"
140
137
  @click-option="onClickOption"
141
138
  />
142
139
  </div>
@@ -20,7 +20,7 @@ export interface Props {
20
20
  /**
21
21
  * Selected item.
22
22
  */
23
- modelValue: string | number | UnknownObject;
23
+ modelValue?: string | number | UnknownObject;
24
24
 
25
25
  /**
26
26
  * List options.
@@ -30,7 +30,7 @@ export function getFormattedValue(value: string | number, options: FormatOptions
30
30
  } = options;
31
31
 
32
32
  const invalidValuesRegExp = new RegExp("[^\\d,\\d.\\s-" + decimalSeparator + "]", "g");
33
- const doubleValueRegExp = new RegExp("([,\\.\\s-" + decimalSeparator + "])+", "g");
33
+ const doubleValueRegExp = new RegExp("([,\\.\\s" + decimalSeparator + "])+", "g");
34
34
 
35
35
  // slice to first decimal mark
36
36
  value = String(value)
@@ -51,11 +51,16 @@ export function getFormattedValue(value: string | number, options: FormatOptions
51
51
  const isNumber = isNumberValueRegExp.test(value);
52
52
  const isFloat = value.endsWith(rawDecimalMark) || value.endsWith(".0");
53
53
  const isMinus = value === minus;
54
+ const isMinusWithin = value.includes(minus) && !value.startsWith(minus);
54
55
 
55
56
  if (isMinus && positiveOnly) {
56
57
  value = "";
57
58
  }
58
59
 
60
+ if (isMinusWithin) {
61
+ value = value.replaceAll(minus, "");
62
+ }
63
+
59
64
  if (!value || !isNumber || isFloat || isMinus) {
60
65
  return `${prefix}${value.replaceAll(rawDecimalMark, decimalSeparator)}`;
61
66
  }
package/utils/theme.ts CHANGED
@@ -42,11 +42,13 @@ export function themeInit() {
42
42
 
43
43
  setTheme();
44
44
 
45
- const prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
45
+ if (vuelessConfig?.colorMode === ColorMode.Auto) {
46
+ const prefersColorSchemeDark = window.matchMedia("(prefers-color-scheme: dark)");
46
47
 
47
- prefersColorSchemeDark.addEventListener("change", (event) =>
48
- setTheme({ colorMode: event.matches ? ColorMode.Dark : ColorMode.Light }),
49
- );
48
+ prefersColorSchemeDark.addEventListener("change", (event) => {
49
+ setTheme({ colorMode: event.matches ? ColorMode.Dark : ColorMode.Light });
50
+ });
51
+ }
50
52
  }
51
53
 
52
54
  export function setColorMode(colorMode: `${ColorMode}`) {
@@ -98,7 +100,7 @@ export function setColorMode(colorMode: `${ColorMode}`) {
98
100
  }
99
101
 
100
102
  export function setTheme(config: Config = {}) {
101
- setColorMode(config?.colorMode || vuelessConfig?.colorMode || ColorMode.Auto);
103
+ setColorMode(vuelessConfig?.colorMode || config?.colorMode || ColorMode.Light);
102
104
 
103
105
  const roundingSm = config?.roundingSm ?? vuelessConfig?.roundingSm ?? DEFAULT_ROUNDING_SM;
104
106
  const rounding = config?.rounding ?? vuelessConfig.rounding ?? DEFAULT_ROUNDING;
package/utils/ui.ts CHANGED
@@ -79,8 +79,7 @@ export const {
79
79
  cva: classVarianceAuthority,
80
80
  } = defineConfig({
81
81
  hooks: {
82
- onComplete: (classNames) =>
83
- twMerge(classNames).replaceAll(NESTED_COMPONENT_PATTERN_REG_EXP, ""),
82
+ onComplete: (classNames) => twMerge(classNames).replace(NESTED_COMPONENT_PATTERN_REG_EXP, ""),
84
83
  },
85
84
  });
86
85