poe-svelte-ui-lib 1.98.0 → 1.99.0

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.
package/dist/Modal.svelte CHANGED
@@ -37,6 +37,16 @@
37
37
 
38
38
  let isTopmost = $derived($ModalStack.at(-1) === modalId)
39
39
 
40
+ /* При открытии фокус в первое доступное поле ввода окна - можно сразу печатать */
41
+ let mainElement: HTMLDivElement | undefined = $state()
42
+ $effect(() => {
43
+ if (!isOpen || !mainElement) return
44
+ const field = mainElement.querySelector<HTMLElement>(
45
+ "input:not([type=hidden]):not([type=checkbox]):not([type=radio]):not([type=range]):not([disabled]):not([readonly]), textarea:not([disabled]):not([readonly])",
46
+ )
47
+ field?.focus({ preventScroll: true })
48
+ })
49
+
40
50
  $effect(() => {
41
51
  if (isOpen) ModalStack.open(modalId)
42
52
  else ModalStack.close(modalId)
@@ -99,13 +109,13 @@
99
109
  </button>
100
110
  </div>
101
111
 
102
- <div class={twMerge("flex h-full w-full min-h-0 flex-col overflow-x-hidden overflow-y-auto p-5", mainClass)}>
112
+ <div bind:this={mainElement} class={twMerge("flex h-full w-full min-h-0 flex-col overflow-x-hidden overflow-y-auto p-5", mainClass)}>
103
113
  {@render main?.()}
104
114
  </div>
105
115
 
106
116
  {#if footer}
107
- <!-- Подтверждающее действие - крайнее справа; row-reverse сохранён, поэтому порядок сниппетов в вызовах менять не нужно -->
108
- <div class="flex flex-row-reverse items-center justify-start gap-2 border-t border-(--hairline-color) bg-(--container-color) px-5 py-3">
117
+ <!-- Кнопки по центру и одной ширины во всех окнах; row-reverse - подтверждающее действие первым в разметке, справа на экране -->
118
+ <div class="flex flex-row-reverse flex-wrap items-center justify-center gap-2 border-t border-(--hairline-color) bg-(--container-color) px-5 py-3 [&>*]:w-44!">
109
119
  {@render footer?.()}
110
120
  </div>
111
121
  {/if}
@@ -31,6 +31,27 @@
31
31
  anchorRect = { top: rect.top, bottom: rect.bottom, left: rect.left, width: rect.width }
32
32
  }
33
33
 
34
+ /* Список открывается вниз, а если снизу места меньше, чем ему нужно, и сверху больше - вверх; высота не больше свободного места */
35
+ const LIST_GAP = 4
36
+ const VIEWPORT_MARGIN = 8
37
+ const listMaxPx = $derived.by(() => {
38
+ const size = parseFloat(listHeight)
39
+ if (listHeight.endsWith("rem")) return size * parseFloat(getComputedStyle(document.documentElement).fontSize || "16")
40
+ return listHeight.endsWith("px") && size > 0 ? size : 256
41
+ })
42
+ const listPlacement = $derived.by(() => {
43
+ if (!anchorRect) return { style: "", maxHeight: listHeight }
44
+ const needed = Math.min(listMaxPx, options.length * 36 + 10)
45
+ const below = window.innerHeight - anchorRect.bottom - LIST_GAP - VIEWPORT_MARGIN
46
+ const above = anchorRect.top - LIST_GAP - VIEWPORT_MARGIN
47
+ const openUp = below < needed && above > below
48
+ const space = Math.max(openUp ? above : below, 72)
49
+ const position = openUp
50
+ ? `bottom: ${window.innerHeight - anchorRect.top + LIST_GAP}px;`
51
+ : `top: ${anchorRect.bottom + LIST_GAP}px;`
52
+ return { style: `${position} left: ${anchorRect.left}px; width: ${anchorRect.width}px;`, maxHeight: `${Math.min(listMaxPx, space)}px` }
53
+ })
54
+
34
55
  $effect(() => {
35
56
  if (!isDropdownOpen) return
36
57
  updateAnchorRect()
@@ -173,11 +194,11 @@
173
194
  use:portal
174
195
  bind:this={portalElement}
175
196
  data-ui-portal
176
- class="fixed z-[9999] mt-1"
177
- style="top: {anchorRect?.bottom ?? 0}px; left: {anchorRect?.left ?? 0}px; width: {anchorRect?.width ?? 0}px;"
197
+ class="fixed z-[9999]"
198
+ style={listPlacement.style}
178
199
  transition:slide={{ duration: 150 }}
179
200
  >
180
- <div class={listBase} style="max-height: {listHeight};" role="listbox">
201
+ <div class={listBase} style="max-height: {listPlacement.maxHeight};" role="listbox">
181
202
  {#each options as option (option.id)}
182
203
  <button
183
204
  id={option.id}
@@ -271,11 +292,11 @@
271
292
  use:portal
272
293
  bind:this={portalElement}
273
294
  data-ui-portal
274
- class="fixed z-[9999] mt-1 select-none"
275
- style="top: {anchorRect?.bottom ?? 0}px; left: {anchorRect?.left ?? 0}px; width: {anchorRect?.width ?? 0}px;"
295
+ class="fixed z-[9999] select-none"
296
+ style={listPlacement.style}
276
297
  transition:slide={{ duration: 150 }}
277
298
  >
278
- <div class={listBase} style="max-height: {listHeight};" role="listbox">
299
+ <div class={listBase} style="max-height: {listPlacement.maxHeight};" role="listbox">
279
300
  {#each filteredOptions as option (option.id)}
280
301
  <button
281
302
  id={option.id}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-svelte-ui-lib",
3
- "version": "1.98.0",
3
+ "version": "1.99.0",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/Oleg-Perevyshin/ElementsUI.git"