ropav 0.1.4 → 0.1.5

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.
Files changed (79) hide show
  1. package/README.md +16 -0
  2. package/dist/alert.css +18 -18
  3. package/dist/alert.js +15 -10
  4. package/dist/avatar.css +19 -19
  5. package/dist/avatar.js +14 -9
  6. package/dist/badge.css +16 -16
  7. package/dist/badge.js +12 -7
  8. package/dist/base.css +196 -56
  9. package/dist/button-link.css +32 -28
  10. package/dist/button-link.js +9 -5
  11. package/dist/button.css +32 -28
  12. package/dist/button.js +9 -5
  13. package/dist/checkbox.css +32 -32
  14. package/dist/checkbox.js +17 -9
  15. package/dist/chevron-right.js +12 -0
  16. package/dist/collectionNavigation.js +120 -0
  17. package/dist/color-input.js +2 -1
  18. package/dist/componentColors.js +94 -22
  19. package/dist/components/alert/types.d.ts +1 -0
  20. package/dist/components/alert/useAlertColor.d.ts +1 -1
  21. package/dist/components/avatar/types.d.ts +1 -0
  22. package/dist/components/avatar/useAvatarColor.d.ts +1 -1
  23. package/dist/components/badge/types.d.ts +1 -0
  24. package/dist/components/badge/useBadgeColor.d.ts +1 -1
  25. package/dist/components/button/types.d.ts +1 -0
  26. package/dist/components/button/useButtonColor.d.ts +1 -1
  27. package/dist/components/button-link/types.d.ts +1 -0
  28. package/dist/components/checkbox/types.d.ts +1 -0
  29. package/dist/components/dropdown-menu/dropdown-menu-primitive-core.d.ts +1 -0
  30. package/dist/components/dropdown-menu/dropdown-menu-utils.d.ts +0 -2
  31. package/dist/components/dropdown-menu/index.d.ts +1 -0
  32. package/dist/components/dropdown-menu/types.d.ts +4 -0
  33. package/dist/components/dropdown-menu/useDropdownMenuInteractions.d.ts +2 -1
  34. package/dist/components/dropdown-menu/useDropdownMenuNavigation.d.ts +1 -0
  35. package/dist/components/icon-button/types.d.ts +1 -0
  36. package/dist/components/pagination/index.d.ts +4 -0
  37. package/dist/components/pagination/index.js +2 -0
  38. package/dist/components/pagination/pagination.d.ts +49 -0
  39. package/dist/components/pagination/types.d.ts +54 -0
  40. package/dist/components/pagination/usePagination.d.ts +19 -0
  41. package/dist/components/radio/types.d.ts +3 -0
  42. package/dist/components/select/useSelect.d.ts +1 -1
  43. package/dist/components/slider/range-slider-tooltip.d.ts +2 -0
  44. package/dist/components/slider/types.d.ts +1 -1
  45. package/dist/components/slider/useRangeSlider.d.ts +2 -0
  46. package/dist/components/slider/useSlider.d.ts +2 -0
  47. package/dist/components/toast/types.d.ts +2 -0
  48. package/dist/components/toast/useToastColor.d.ts +1 -1
  49. package/dist/components/tooltip/types.d.ts +1 -0
  50. package/dist/components/tooltip/useTooltip.d.ts +1 -1
  51. package/dist/dropdown-menu.js +55 -30
  52. package/dist/icon-button.css +39 -35
  53. package/dist/icon-button.js +9 -5
  54. package/dist/index.d.ts +1 -0
  55. package/dist/index.js +2 -1
  56. package/dist/input.js +2 -1
  57. package/dist/number-input.js +2 -1
  58. package/dist/pagination.css +140 -0
  59. package/dist/pagination.js +442 -0
  60. package/dist/radio.js +15 -5
  61. package/dist/select.js +65 -46
  62. package/dist/slider.css +191 -191
  63. package/dist/slider.js +49 -31
  64. package/dist/switch.js +2 -1
  65. package/dist/textarea.js +2 -1
  66. package/dist/toast.css +26 -26
  67. package/dist/toast.js +16 -9
  68. package/dist/tooltip.css +12 -12
  69. package/dist/tooltip.js +13 -8
  70. package/dist/unplugin-icons.js +38 -25
  71. package/dist/useButtonColor.js +6 -3
  72. package/dist/useControllableValue.js +27 -0
  73. package/dist/useFormControl.js +2 -27
  74. package/dist/utils/componentColors.d.ts +14 -1
  75. package/docs/public-styles-api.md +1 -1
  76. package/docs/public-tokens.md +648 -508
  77. package/package.json +7 -1
  78. package/src/styles/_tokens.scss +459 -319
  79. package/src/styles/styles-manifest.json +1122 -2
package/dist/select.js CHANGED
@@ -3,10 +3,12 @@ import { t as x_default } from "./x.js";
3
3
  import { t as bem } from "./bem.js";
4
4
  import { n as useStylesApi, t as presence } from "./styles-api.js";
5
5
  import { t as _plugin_vue_export_helper_default } from "./_plugin-vue_export-helper.js";
6
- import { i as useFormControl, o as useControllableValue } from "./useFormControl.js";
6
+ import { t as useControllableValue } from "./useControllableValue.js";
7
+ import { i as useFormControl } from "./useFormControl.js";
7
8
  import { t as useControlState } from "./useControlState.js";
9
+ import { n as getNextEnabledIndex, r as useTypeahead, t as getEnabledIndexes } from "./collectionNavigation.js";
8
10
  import { t as scroll_area_default } from "./scroll-area.js";
9
- import { VaporTransition, child, computed, createComponent, createFor, createIf, createInvoker, createSlot, createTemplateRefSetter, defineVaporComponent, delegateEvents, extend, markRaw, next, nextTick, on, onBeforeUnmount, onMounted, ref, renderEffect, setDynamicProps, setInsertionState, setProp, setText, setValue, template, toDisplayString, txt, unref, useId, watch, watchEffect, withModifiers, withVaporModifiers } from "vue";
11
+ import { VaporTransition, child, computed, createComponent, createFor, createIf, createInvoker, createSlot, createTemplateRefSetter, defineVaporComponent, delegateEvents, extend, markRaw, next, nextTick, on, onBeforeUnmount, onMounted, ref, renderEffect, setDynamicProps, setInsertionState, setProp, setText, setValue, shallowRef, template, toDisplayString, txt, unref, useId, watch, watchEffect, withModifiers, withVaporModifiers } from "vue";
10
12
  //#region ~icons/lucide/chevrons-up-down
11
13
  var t0$1 = template("<svg viewBox=\"0 0 24 24\"width=1.2em height=1.2em><path fill=none stroke=currentColor stroke-linecap=round stroke-linejoin=round stroke-width=2 d=\"m7 15l5 5l5-5M7 9l5-5l5 5\">", 3, 1);
12
14
  function render(_ctx) {
@@ -39,61 +41,61 @@ function useClickOutside(target, active, callback) {
39
41
  });
40
42
  }
41
43
  //#endregion
42
- //#region src/composables/useListNavigation.ts
43
- function useListNavigation(options) {
44
- const localFocusedIndex = ref(-1);
44
+ //#region src/composables/useCollectionNavigation.ts
45
+ function useCollectionNavigation(options) {
46
+ const activeKey = shallowRef(null);
47
+ const isDisabled = options.isDisabled ?? (() => false);
45
48
  const loop = options.loop ?? true;
46
- const enabledIndexes = computed(() => options.items().map((item, index) => item.disabled ? -1 : index).filter((index) => index >= 0));
47
- function resetFocus() {
48
- localFocusedIndex.value = -1;
49
+ const activeIndex = computed(() => {
50
+ if (activeKey.value == null) return -1;
51
+ return options.items().findIndex((item) => options.getKey(item) === activeKey.value && !isDisabled(item));
52
+ });
53
+ const enabledIndexes = computed(() => getEnabledIndexes(options.items(), isDisabled));
54
+ function resetActive() {
55
+ activeKey.value = null;
49
56
  }
50
- function setNearest(index, direction) {
51
- const indexes = enabledIndexes.value;
52
- if (indexes.length === 0) {
53
- resetFocus();
54
- return;
55
- }
56
- if (options.items()[index] && !options.items()[index]?.disabled) {
57
- localFocusedIndex.value = index;
58
- return;
59
- }
60
- let next;
61
- if (direction === 1) next = indexes.find((i) => i > index);
62
- else for (let i = indexes.length - 1; i >= 0; i -= 1) {
63
- const candidate = indexes[i];
64
- if (candidate < index) {
65
- next = candidate;
66
- break;
67
- }
68
- }
69
- if (next !== void 0) localFocusedIndex.value = next;
70
- else if (loop) localFocusedIndex.value = direction === 1 ? indexes[0] : indexes[indexes.length - 1];
57
+ function setActiveIndex(index) {
58
+ const item = options.items()[index];
59
+ if (!item || isDisabled(item)) return false;
60
+ activeKey.value = options.getKey(item);
61
+ return true;
71
62
  }
72
63
  function focusSelected() {
73
64
  const items = options.items();
74
- const selectedIndex = options.isSelected ? items.findIndex((item) => options.isSelected(item) && !item.disabled) : -1;
75
- if (selectedIndex >= 0) localFocusedIndex.value = selectedIndex;
65
+ const selectedIndex = options.isSelected ? items.findIndex((item) => options.isSelected(item) && !isDisabled(item)) : -1;
66
+ if (selectedIndex >= 0) setActiveIndex(selectedIndex);
76
67
  else focusFirst();
77
68
  }
78
69
  function focusFirst() {
79
70
  const first = enabledIndexes.value[0];
80
- localFocusedIndex.value = first ?? -1;
71
+ if (first === void 0) resetActive();
72
+ else setActiveIndex(first);
81
73
  }
82
74
  function focusLast() {
83
75
  const indexes = enabledIndexes.value;
84
- localFocusedIndex.value = indexes[indexes.length - 1] ?? -1;
76
+ const last = indexes[indexes.length - 1];
77
+ if (last === void 0) resetActive();
78
+ else setActiveIndex(last);
85
79
  }
86
- function moveFocus(delta) {
87
- if (localFocusedIndex.value < 0) {
88
- if (delta === 1) focusFirst();
80
+ function moveFocus(direction) {
81
+ if (activeIndex.value < 0) {
82
+ if (direction === 1) focusFirst();
89
83
  else focusLast();
90
84
  return;
91
85
  }
92
- setNearest(localFocusedIndex.value + delta, delta);
86
+ const nextIndex = getNextEnabledIndex(options.items(), activeIndex.value, direction, isDisabled, loop);
87
+ if (nextIndex === void 0) resetActive();
88
+ else setActiveIndex(nextIndex);
93
89
  }
90
+ watch(activeIndex, (index) => {
91
+ if (activeKey.value != null && index < 0) resetActive();
92
+ }, { flush: "sync" });
94
93
  return {
95
- focusedIndex: localFocusedIndex,
96
- resetFocus,
94
+ activeKey,
95
+ activeIndex,
96
+ enabledIndexes,
97
+ resetActive,
98
+ setActiveIndex,
97
99
  focusSelected,
98
100
  focusFirst,
99
101
  focusLast,
@@ -109,8 +111,8 @@ function getSelectDisplayLabel(options, value) {
109
111
  if (!hasSelectValue(value)) return "";
110
112
  return options?.find((option) => option.value === value)?.label ?? "";
111
113
  }
112
- function getSelectActiveDescendantId(baseId, focusedIndex) {
113
- return focusedIndex < 0 ? void 0 : `${baseId}-option-${focusedIndex}`;
114
+ function getSelectActiveDescendantId(baseId, focusedIndex, isOpen) {
115
+ return !isOpen || focusedIndex < 0 ? void 0 : `${baseId}-option-${focusedIndex}`;
114
116
  }
115
117
  function useSelect(props, emitUpdate, getValue = () => props.modelValue ?? null, triggerRef = ref(null)) {
116
118
  const selectRef = ref(null);
@@ -120,12 +122,26 @@ function useSelect(props, emitUpdate, getValue = () => props.modelValue ?? null,
120
122
  const control = useControlState(props);
121
123
  const visibleOptions = computed(() => props.options ?? []);
122
124
  const value = computed(getValue);
123
- const navigation = useListNavigation({
125
+ const navigation = useCollectionNavigation({
124
126
  items: () => visibleOptions.value,
127
+ getKey: (item) => item.value,
128
+ isDisabled: (item) => Boolean(item.disabled),
125
129
  isSelected: (item) => item.value === value.value
126
130
  });
127
- const focusedIndex = navigation.focusedIndex;
128
- const activeDescendantId = computed(() => getSelectActiveDescendantId(selectId, focusedIndex.value));
131
+ const focusedIndex = navigation.activeIndex;
132
+ const selectedIndex = computed(() => visibleOptions.value.findIndex((option) => option.value === value.value && !option.disabled));
133
+ const activeDescendantId = computed(() => getSelectActiveDescendantId(selectId, focusedIndex.value, isOpen.value));
134
+ const typeahead = useTypeahead({
135
+ items: () => visibleOptions.value,
136
+ activeIndex: () => isOpen.value ? focusedIndex.value : selectedIndex.value,
137
+ getKey: (item) => item.value,
138
+ getTextValue: (item) => item.label,
139
+ isDisabled: (item) => Boolean(item.disabled),
140
+ onMatch(item, index) {
141
+ if (isOpen.value) navigation.setActiveIndex(index);
142
+ else if (item.value !== value.value) emitUpdate(item.value);
143
+ }
144
+ });
129
145
  const rootClass = computed(() => bem("rp-select", {
130
146
  open: isOpen.value,
131
147
  [`size-${props.size}`]: Boolean(props.size),
@@ -141,12 +157,14 @@ function useSelect(props, emitUpdate, getValue = () => props.modelValue ?? null,
141
157
  }
142
158
  function open() {
143
159
  if (control.disabled || isOpen.value) return;
160
+ typeahead.reset();
144
161
  isOpen.value = true;
145
162
  navigation.focusSelected();
146
163
  }
147
164
  function close() {
148
165
  isOpen.value = false;
149
- navigation.resetFocus();
166
+ navigation.resetActive();
167
+ typeahead.reset();
150
168
  }
151
169
  function toggle() {
152
170
  if (control.disabled) return;
@@ -168,7 +186,7 @@ function useSelect(props, emitUpdate, getValue = () => props.modelValue ?? null,
168
186
  focusTrigger();
169
187
  }
170
188
  function onOptionMouseenter(option, index) {
171
- if (!option.disabled) focusedIndex.value = index;
189
+ if (!option.disabled) navigation.setActiveIndex(index);
172
190
  }
173
191
  function onFocusout(event) {
174
192
  const nextTarget = event.relatedTarget;
@@ -181,6 +199,7 @@ function useSelect(props, emitUpdate, getValue = () => props.modelValue ?? null,
181
199
  }
182
200
  function onTriggerKeydown(e) {
183
201
  if (control.disabled) return;
202
+ if (typeahead.handleKey(e)) return;
184
203
  switch (e.key) {
185
204
  case "Enter":
186
205
  e.preventDefault();