@pequity/squirrel 5.5.0 → 6.0.1

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.
@@ -1,9 +1,9 @@
1
1
  <template>
2
- <VDropdown ref="vPopper" v-bind="{ ...defaultAttrs, ...$attrs }" @show="onShow" @hide="destroy">
2
+ <Dropdown ref="vPopper" v-bind="{ ...defaultAttrs, ...$attrs }" @show="onShow" @hide="destroy">
3
3
  <template v-for="(_, slot) in $slots" #[slot]="scope">
4
4
  <slot :name="slot" v-bind="scope || {}" />
5
5
  </template>
6
- </VDropdown>
6
+ </Dropdown>
7
7
  </template>
8
8
 
9
9
  <script lang="ts">
@@ -88,7 +88,10 @@ import {
88
88
  type ListKeyboardNavigationInstance,
89
89
  setupListKeyboardNavigation,
90
90
  } from '@squirrel/utils/listKeyboardNavigation';
91
- import { defineComponent, type PropType } from 'vue';
91
+ import { Dropdown } from 'floating-vue';
92
+ import { defineComponent } from 'vue';
93
+
94
+ type DropdownProps = InstanceType<typeof Dropdown>['$props'];
92
95
 
93
96
  type VPopper = {
94
97
  $refs: {
@@ -98,19 +101,33 @@ type VPopper = {
98
101
  reference: HTMLElement;
99
102
  popper: {
100
103
  shown: boolean;
104
+ isShown: boolean;
101
105
  hide: (options?: { skipDelay: boolean }) => void;
106
+ show: () => void;
102
107
  $_detachPopperNode: () => void;
103
108
  $_referenceNode: HTMLElement;
104
109
  $_computePosition: () => void;
105
110
  $el: HTMLElement;
111
+ $emit: (event: string, ...args: unknown[]) => void;
106
112
  };
107
113
  };
108
114
  };
109
115
 
110
116
  const ESCAPE_KEY = 'Escape';
111
117
 
118
+ const nextFrame = () => {
119
+ return new Promise((resolve) =>
120
+ requestAnimationFrame(() => {
121
+ requestAnimationFrame(resolve);
122
+ })
123
+ );
124
+ };
125
+
112
126
  export default defineComponent({
113
127
  name: 'PDropdown',
128
+ components: {
129
+ Dropdown,
130
+ },
114
131
  inheritAttrs: false,
115
132
  props: {
116
133
  /**
@@ -138,49 +155,23 @@ export default defineComponent({
138
155
  display: 'inline-block',
139
156
  }),
140
157
  },
141
- /**
142
- * Custom reference element that is used to position the popper.
143
- * Can be changed at runtime to create a dynamically positioned dropdown.
144
- */
145
- reference: {
146
- type: HTMLElement as PropType<HTMLElement | null | undefined>,
147
- default: null,
148
- },
149
158
  },
150
159
  data() {
151
160
  return {
152
161
  defaultAttrs: {
153
162
  triggers: ['click'],
154
- 'auto-hide': true,
163
+ autoHide: true,
155
164
  theme: 'p-dropdown-theme',
156
- 'popper-class': 'dropdown',
165
+ popperClass: 'dropdown',
157
166
  placement: 'bottom-start',
158
167
  distance: 4,
159
168
  delay: 0,
160
169
  handleResize: true,
161
- },
170
+ } satisfies DropdownProps,
162
171
  navigationSvc: null as ListKeyboardNavigationInstance | null,
172
+ prevReference: null as HTMLElement | null,
163
173
  };
164
174
  },
165
- watch: {
166
- reference: {
167
- async handler(nV, oV) {
168
- if (nV && oV !== nV) {
169
- const popper = (this.$refs.vPopper as VPopper).$refs.popper;
170
-
171
- if (popper) {
172
- popper.$_detachPopperNode();
173
- if (popper.shown) {
174
- popper.hide({ skipDelay: true });
175
- }
176
- if (this.reference) {
177
- popper.$_referenceNode = this.reference;
178
- }
179
- }
180
- }
181
- },
182
- },
183
- },
184
175
  mounted() {
185
176
  Object.assign((this.$refs.vPopper as VPopper).$refs.popper.$el.style, this.triggerStyle);
186
177
  },
@@ -208,6 +199,37 @@ export default defineComponent({
208
199
  this.navigationSvc?.destroy();
209
200
  document.removeEventListener('keydown', this.popoverEscKeydown);
210
201
  },
202
+ async updateReference(newReference: HTMLElement) {
203
+ if (!newReference) {
204
+ throw Error('Reference element is required');
205
+ }
206
+
207
+ const popper = (this.$refs.vPopper as VPopper).$refs.popper;
208
+
209
+ if (popper) {
210
+ // Fixes popper flicker issue when changing reference
211
+ popper.$_detachPopperNode();
212
+
213
+ if (popper.isShown) {
214
+ popper.$emit('update:shown', false);
215
+
216
+ if (newReference === this.prevReference) {
217
+ return;
218
+ }
219
+ }
220
+
221
+ // Wait for the popper to hide
222
+ await nextFrame();
223
+
224
+ popper.$_referenceNode = newReference;
225
+ this.prevReference = newReference;
226
+
227
+ // Wait for the popper to update the reference
228
+ await nextFrame();
229
+
230
+ popper.$emit('update:shown', true);
231
+ }
232
+ },
211
233
  },
212
234
  });
213
235
  </script>
@@ -1,6 +1,6 @@
1
1
  import type { Config } from 'tailwindcss';
2
2
 
3
- export const config = {
3
+ export const squirrelTailwindConfig = {
4
4
  content: ['./index.html', './squirrel/**/*.{vue,js,ts,jsx,tsx,mdx}', './src/**/*.{vue,js,ts,jsx,tsx,mdx}'],
5
5
  theme: {
6
6
  colors: {
@@ -103,4 +103,4 @@ export const config = {
103
103
  },
104
104
  } as const satisfies Config;
105
105
 
106
- export type SquirrelTailwindConfig = typeof config;
106
+ export type SquirrelTailwindConfig = typeof squirrelTailwindConfig;
@@ -1,5 +1,5 @@
1
+ import { getScreen } from '@squirrel/utils/tailwind';
1
2
  import { cloneDeep } from 'lodash-es';
2
- import { getScreen } from './tailwind';
3
3
 
4
4
  const screens = { sm: '640px', md: '768px' };
5
5
 
@@ -1,6 +1,4 @@
1
- import { config as squirrelTailwindConfig } from '@squirrel/tailwind/config';
2
- // Relative import is used here because of
3
- // "Module source URI is not allowed in this document: “http://tailwind.config/”" error
1
+ import { squirrelTailwindConfig } from '@squirrel/tailwind/config';
4
2
  import { get } from 'lodash-es';
5
3
  import type { Config } from 'tailwindcss';
6
4
  import resolveConfig from 'tailwindcss/resolveConfig';
@@ -1,105 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.config = void 0;
4
- exports.config = {
5
- content: ['./index.html', './squirrel/**/*.{vue,js,ts,jsx,tsx,mdx}', './src/**/*.{vue,js,ts,jsx,tsx,mdx}'],
6
- theme: {
7
- colors: {
8
- transparent: 'transparent',
9
- current: 'currentColor',
10
- /* Design system colors */
11
- white: 'rgb(var(--color-white))',
12
- black: 'rgb(var(--color-black))',
13
- night: 'rgb(var(--color-night))',
14
- 'barley-white': 'rgb(var(--color-barley-white))',
15
- 'horses-neck': 'rgb(var(--color-horses-neck))',
16
- 'active-blue': 'rgb(var(--color-active-blue))',
17
- /* Pequity colors */
18
- 'p-gray': {
19
- 10: 'rgb(var(--color-p-gray-10))',
20
- 20: 'rgb(var(--color-p-gray-20))',
21
- 30: 'rgb(var(--color-p-gray-30))',
22
- 40: 'rgb(var(--color-p-gray-40))',
23
- 50: 'rgb(var(--color-p-gray-50))',
24
- 60: 'rgb(var(--color-p-gray-60))',
25
- 70: 'rgb(var(--color-p-gray-70))',
26
- 80: 'rgb(var(--color-p-gray-80))',
27
- 90: 'rgb(var(--color-p-gray-90))',
28
- 100: 'rgb(var(--color-p-gray-100))',
29
- },
30
- 'p-blue': {
31
- 10: 'rgb(var(--color-p-blue-10))',
32
- 15: 'rgb(var(--color-p-blue-15))',
33
- 20: 'rgb(var(--color-p-blue-20))',
34
- 30: 'rgb(var(--color-p-blue-30))',
35
- 40: 'rgb(var(--color-p-blue-40))',
36
- 50: 'rgb(var(--color-p-blue-50))',
37
- 60: 'rgb(var(--color-p-blue-60))',
38
- 70: 'rgb(var(--color-p-blue-70))',
39
- 80: 'rgb(var(--color-p-blue-80))',
40
- },
41
- 'p-purple': {
42
- 10: 'rgb(var(--color-p-purple-10))',
43
- 20: 'rgb(var(--color-p-purple-20))',
44
- 30: 'rgb(var(--color-p-purple-30))',
45
- 40: 'rgb(var(--color-p-purple-40))',
46
- 50: 'rgb(var(--color-p-purple-50))',
47
- 60: 'rgb(var(--color-p-purple-60))',
48
- },
49
- 'p-green': {
50
- 10: 'rgb(var(--color-p-green-10))',
51
- 20: 'rgb(var(--color-p-green-20))',
52
- 30: 'rgb(var(--color-p-green-30))',
53
- 40: 'rgb(var(--color-p-green-40))',
54
- 50: 'rgb(var(--color-p-green-50))',
55
- },
56
- 'p-red': {
57
- 10: 'rgb(var(--color-p-red-10))',
58
- 20: 'rgb(var(--color-p-red-20))',
59
- 30: 'rgb(var(--color-p-red-30))',
60
- 40: 'rgb(var(--color-p-red-40))',
61
- 50: 'rgb(var(--color-p-red-50))',
62
- },
63
- /* Aliases */
64
- primary: 'rgb(var(--color-primary))',
65
- accent: 'rgb(var(--color-accent))',
66
- surface: 'rgb(var(--color-surface))',
67
- 'on-surface': 'rgb(var(--color-on-surface))',
68
- error: 'rgb(var(--color-error))',
69
- 'on-error': 'rgb(var(--color-on-error))',
70
- info: 'rgb(var(--color-info))',
71
- 'on-info': 'rgb(var(--color-on-info))',
72
- success: 'rgb(var(--color-success))',
73
- 'on-success': 'rgb(var(--color-on-success))',
74
- warning: 'rgb(var(--color-warning))',
75
- 'on-warning': 'rgb(var(--color-on-warning))',
76
- },
77
- fontFamily: {
78
- sans: ['Inter', 'Helvetica', 'Arial', 'sans-serif'],
79
- },
80
- fontSize: {
81
- xs: '0.75rem',
82
- sm: '0.875rem',
83
- base: '1rem',
84
- lg: '1.125rem',
85
- xl: '1.25rem',
86
- '2xl': '1.5rem',
87
- '3xl': '1.875rem',
88
- '4xl': '2.25rem',
89
- '5xl': '3rem',
90
- '6xl': '4rem',
91
- },
92
- extend: {
93
- borderColor: {
94
- DEFAULT: 'rgb(var(--color-p-gray-30))',
95
- },
96
- spacing: {
97
- 7.5: '1.875rem',
98
- },
99
- zIndex: {
100
- 110: '110',
101
- },
102
- screens: {},
103
- },
104
- },
105
- };
File without changes