@likable-hair/svelte 3.1.42 → 3.1.44

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.
@@ -108,7 +108,7 @@ function calcScrollY(elem) {
108
108
  while (!!parent) {
109
109
  scroll += parent.scrollTop;
110
110
  let parentPosition = getComputedStyle(parent).position;
111
- if (parentPosition === "absolute" || parentPosition === "fixed")
111
+ if (parentPosition === "absolute" || parentPosition === "fixed" || parentPosition === "relative")
112
112
  break;
113
113
  parent = parent.parentElement;
114
114
  }
@@ -121,7 +121,7 @@ $:
121
121
  while (!!parent) {
122
122
  let parentPosition = getComputedStyle(parent).position;
123
123
  parent.addEventListener("scroll", refreshMenuPosition);
124
- if (parentPosition == "absolute" || parentPosition == "fixed")
124
+ if (parentPosition == "absolute" || parentPosition == "fixed" || parentPosition === "relative")
125
125
  break;
126
126
  parent = parent.parentElement;
127
127
  }
@@ -204,7 +204,7 @@ $:
204
204
  function getPositionedAncestor(elem) {
205
205
  if (!elem)
206
206
  return null;
207
- if (["fixed", "absolute", "sticky"].includes(getComputedStyle(elem).position))
207
+ if (["fixed", "absolute", "sticky", "relative"].includes(getComputedStyle(elem).position))
208
208
  return elem;
209
209
  return getPositionedAncestor(elem.parentElement);
210
210
  }
@@ -224,7 +224,7 @@ function getParentInstanceFromViewport(activatorParent) {
224
224
  const computedStyle = getComputedStyle(currentParent);
225
225
  const position = computedStyle.position;
226
226
  const display = computedStyle.display;
227
- if ((position === "fixed" || position === "absolute") && display === "flex") {
227
+ if ((position === "fixed" || position === "absolute" || position === "relative") && display === "flex") {
228
228
  const boundingClientRect = activatorParent.getBoundingClientRect();
229
229
  top = top + boundingClientRect.top;
230
230
  left = left + boundingClientRect.left;
@@ -3,7 +3,7 @@ import "./FileInput.css";
3
3
  import { createEventDispatcher } from "svelte";
4
4
  let clazz = "";
5
5
  export { clazz as class };
6
- export let files = void 0, placeholder = void 0, persistOverUpload = true, disabled = false;
6
+ export let files = void 0, placeholder = void 0, persistOverUpload = true, disabled = false, maxFiles = void 0;
7
7
  let inputElement = void 0;
8
8
  let dropAreaActive = false;
9
9
  const highlight = (highlighted) => {
@@ -12,27 +12,41 @@ const highlight = (highlighted) => {
12
12
  const dispatch = createEventDispatcher();
13
13
  function handleFileDrop(event) {
14
14
  let droppedFiles = event.dataTransfer?.files;
15
+ let limitedFiles;
15
16
  if (droppedFiles) {
17
+ if (maxFiles !== void 0) {
18
+ let freeSlots = Math.max(0, maxFiles - (files?.length || 0));
19
+ limitedFiles = Array.from(droppedFiles).slice(0, freeSlots);
20
+ } else {
21
+ limitedFiles = Array.from(droppedFiles);
22
+ }
16
23
  if (!persistOverUpload)
17
- files = Array.from(droppedFiles);
24
+ files = limitedFiles;
18
25
  else
19
- files = files ? [...files, ...Array.from(droppedFiles)] : Array.from(droppedFiles);
26
+ files = files ? [...files, ...limitedFiles] : limitedFiles;
20
27
  dispatch("fileDrop", {
21
28
  nativeEvent: event,
22
- files: Array.from(droppedFiles)
29
+ files: limitedFiles
23
30
  });
24
31
  }
25
32
  }
26
33
  function handleFileFromInput(event) {
27
34
  let selectedFiles = event.target.files;
35
+ let limitedFiles;
28
36
  if (selectedFiles) {
37
+ if (maxFiles !== void 0) {
38
+ let freeSlots = Math.max(0, maxFiles - (files?.length || 0));
39
+ limitedFiles = Array.from(selectedFiles).slice(0, freeSlots);
40
+ } else {
41
+ limitedFiles = Array.from(selectedFiles);
42
+ }
29
43
  if (!persistOverUpload)
30
- files = Array.from(selectedFiles);
44
+ files = limitedFiles;
31
45
  else
32
- files = files ? [...files, ...Array.from(selectedFiles)] : Array.from(selectedFiles);
46
+ files = files ? [...files, ...limitedFiles] : limitedFiles;
33
47
  dispatch("fileSelect", {
34
48
  nativeEvent: event,
35
- files: Array.from(selectedFiles)
49
+ files: limitedFiles
36
50
  });
37
51
  }
38
52
  }
@@ -100,7 +114,7 @@ function handleFileFromInput(event) {
100
114
  .drop-area > input {
101
115
  display: none;
102
116
  }
103
- .drop-area:hover:not(.disabled) {
117
+ .drop-area:hover:not(.disabled) {
104
118
  box-shadow: var(
105
119
  --file-input-focus-shadow,
106
120
  var(--file-input-default-focus-shadow)
@@ -8,6 +8,7 @@ declare const __propDef: {
8
8
  placeholder?: string | undefined;
9
9
  persistOverUpload?: boolean | undefined;
10
10
  disabled?: boolean | undefined;
11
+ maxFiles?: number | undefined;
11
12
  };
12
13
  events: {
13
14
  fileDrop: CustomEvent<{
@@ -5,7 +5,7 @@ import FileInput from "./FileInput.svelte";
5
5
  import Icon from "../media/Icon.svelte";
6
6
  let clazz = "";
7
7
  export { clazz as class };
8
- export let files = [], persistOverUpload = true, dropAreaActive = true, icon = "mdi-file-document";
8
+ export let files = [], persistOverUpload = true, dropAreaActive = true, icon = "mdi-file-document", disabled = false, maxFiles = void 0;
9
9
  let fileActive = null;
10
10
  function handleFileMouseEnter(file) {
11
11
  dropAreaActive = false;
@@ -29,11 +29,13 @@ function handleRemove(file) {
29
29
  <FileInput
30
30
  bind:files
31
31
  {persistOverUpload}
32
+ disabled={disabled || (maxFiles !== undefined && files.length >= maxFiles)}
32
33
  --file-input-border-radius="var(--file-input-list-border-radius,var(--file-input-list-default-border-radius))"
33
34
  --file-input-background-color="var(--file-input-list-background-color,var(--file-input-list-default-background-color))"
34
35
  --file-input-color="var(--file-input-list-color,var(--file-input-list-default-color))"
35
36
  --file-input-height="var(--file-input-list-height,var(--file-input-list-default-height))"
36
37
  --file-input-width="var(--file-input-list-width,var(--file-input-list-default-width))"
38
+ {maxFiles}
37
39
  >
38
40
  <span
39
41
  slot="body"
@@ -115,7 +117,7 @@ function handleRemove(file) {
115
117
  var(--file-input-list-default-hover-color)
116
118
  );
117
119
  }
118
-
120
+
119
121
  .body-container {
120
122
  border: dotted;
121
123
  border-color: var(
@@ -128,7 +130,7 @@ function handleRemove(file) {
128
130
  );
129
131
  width: calc(100% - 20px);
130
132
  height: calc(100% - 20px);
131
- box-sizing: border-box;
133
+ box-sizing: border-box;
132
134
  margin: auto;
133
135
  position: relative;
134
136
  display: flex;
@@ -8,6 +8,8 @@ declare const __propDef: {
8
8
  persistOverUpload?: boolean | undefined;
9
9
  dropAreaActive?: boolean | undefined;
10
10
  icon?: string | undefined;
11
+ disabled?: boolean | undefined;
12
+ maxFiles?: number | undefined;
11
13
  };
12
14
  events: {
13
15
  [evt: string]: CustomEvent<any>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@likable-hair/svelte",
3
3
  "description": "A Svelte component for likablehair and others",
4
- "version": "3.1.42",
4
+ "version": "3.1.44",
5
5
  "scripts": {
6
6
  "host": "vite --host",
7
7
  "dev": "vite dev",