drab 3.0.1 → 3.0.3
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/components/CopyButton.svelte +16 -13
- package/dist/components/CopyButton.svelte.d.ts +6 -4
- package/dist/components/Editor.svelte +6 -0
- package/dist/components/Editor.svelte.d.ts +6 -0
- package/dist/components/Popover.svelte +24 -10
- package/dist/components/Popover.svelte.d.ts +2 -2
- package/dist/components/Sheet.svelte.d.ts +1 -1
- package/package.json +1 -1
@@ -3,13 +3,12 @@
|
|
3
3
|
|
4
4
|
### CopyButton
|
5
5
|
|
6
|
-
Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) to copy data to the clipboard. Falls back to `writeText` if `write` is not supported and `blob.type` is text.
|
6
|
+
Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) to copy data to the clipboard. Falls back to `writeText` if `write` is not supported and `blob.type` is text.
|
7
7
|
|
8
8
|
@props
|
9
9
|
|
10
10
|
- `blobParts` - array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
|
11
11
|
- `blob` - use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)`
|
12
|
-
- `classNoscript` - `noscript` class
|
13
12
|
- `class`
|
14
13
|
- `id`
|
15
14
|
- `options` - defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
|
@@ -27,9 +26,13 @@ Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipbo
|
|
27
26
|
```svelte
|
28
27
|
<script lang="ts">
|
29
28
|
import { CopyButton } from "drab";
|
29
|
+
|
30
|
+
let value = "Text to copy";
|
30
31
|
</script>
|
31
32
|
|
32
|
-
<
|
33
|
+
<input class="input mb-4" type="text" bind:value />
|
34
|
+
|
35
|
+
<CopyButton class="btn" blobParts={[value]} />
|
33
36
|
```
|
34
37
|
-->
|
35
38
|
|
@@ -42,13 +45,14 @@ export let title = "";
|
|
42
45
|
export let options = { type: "text/plain" };
|
43
46
|
export let blobParts = void 0;
|
44
47
|
export let blob = new Blob(blobParts, options);
|
45
|
-
export let classNoscript = "";
|
46
48
|
let disabled = true;
|
47
49
|
let complete = false;
|
50
|
+
let blobText;
|
51
|
+
const setBlobText = async (blob2) => blobText = await blob2.text();
|
48
52
|
const writeSupport = () => "write" in navigator.clipboard;
|
49
|
-
const typeText = blob.type.startsWith("text");
|
50
53
|
const canWriteText = () => {
|
51
54
|
const writeTextSupport = "writeText" in navigator.clipboard;
|
55
|
+
const typeText = blob.type.startsWith("text");
|
52
56
|
return writeTextSupport && typeText;
|
53
57
|
};
|
54
58
|
const copyText = async () => {
|
@@ -57,7 +61,7 @@ const copyText = async () => {
|
|
57
61
|
const data = [new ClipboardItem({ [blob.type]: blob })];
|
58
62
|
await navigator.clipboard.write(data);
|
59
63
|
} else if (canWriteText()) {
|
60
|
-
await navigator.clipboard.writeText(
|
64
|
+
await navigator.clipboard.writeText(blobText);
|
61
65
|
}
|
62
66
|
complete = true;
|
63
67
|
setTimeout(() => complete = false, delay);
|
@@ -65,10 +69,15 @@ const copyText = async () => {
|
|
65
69
|
console.error(error);
|
66
70
|
}
|
67
71
|
};
|
68
|
-
onMount(() => {
|
72
|
+
onMount(async () => {
|
69
73
|
if (writeSupport() || canWriteText())
|
70
74
|
disabled = false;
|
71
75
|
});
|
76
|
+
$:
|
77
|
+
if (blobParts)
|
78
|
+
blob = new Blob(blobParts, options);
|
79
|
+
$:
|
80
|
+
setBlobText(blob);
|
72
81
|
</script>
|
73
82
|
|
74
83
|
<button
|
@@ -85,9 +94,3 @@ onMount(() => {
|
|
85
94
|
<slot>Copy</slot>
|
86
95
|
{/if}
|
87
96
|
</button>
|
88
|
-
|
89
|
-
{#if typeText}
|
90
|
-
<noscript>
|
91
|
-
<span class={classNoscript}>{blobParts ? blobParts.join() : ""}</span>
|
92
|
-
</noscript>
|
93
|
-
{/if}
|
@@ -7,7 +7,6 @@ declare const __propDef: {
|
|
7
7
|
/** defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters) */ options?: BlobPropertyBag | undefined;
|
8
8
|
/** array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters) */ blobParts?: BlobPart[] | undefined;
|
9
9
|
/** use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)` */ blob?: Blob | undefined;
|
10
|
-
/** `noscript` class */ classNoscript?: string | undefined;
|
11
10
|
};
|
12
11
|
events: {
|
13
12
|
[evt: string]: CustomEvent<any>;
|
@@ -23,13 +22,12 @@ export type CopyButtonSlots = typeof __propDef.slots;
|
|
23
22
|
/**
|
24
23
|
* ### CopyButton
|
25
24
|
*
|
26
|
-
* Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) to copy data to the clipboard. Falls back to `writeText` if `write` is not supported and `blob.type` is text.
|
25
|
+
* Uses the [Clipboard API](https://developer.mozilla.org/en-US/docs/Web/API/Clipboard) to copy data to the clipboard. Falls back to `writeText` if `write` is not supported and `blob.type` is text.
|
27
26
|
*
|
28
27
|
* @props
|
29
28
|
*
|
30
29
|
* - `blobParts` - array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
|
31
30
|
* - `blob` - use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)`
|
32
|
-
* - `classNoscript` - `noscript` class
|
33
31
|
* - `class`
|
34
32
|
* - `id`
|
35
33
|
* - `options` - defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
|
@@ -47,9 +45,13 @@ export type CopyButtonSlots = typeof __propDef.slots;
|
|
47
45
|
* ```svelte
|
48
46
|
* <script lang="ts">
|
49
47
|
* import { CopyButton } from "drab";
|
48
|
+
*
|
49
|
+
* let value = "Text to copy";
|
50
50
|
* </script>
|
51
51
|
*
|
52
|
-
* <
|
52
|
+
* <input class="input mb-4" type="text" bind:value />
|
53
|
+
*
|
54
|
+
* <CopyButton class="btn" blobParts={[value]} />
|
53
55
|
* ```
|
54
56
|
*/
|
55
57
|
export default class CopyButton extends SvelteComponent<CopyButtonProps, CopyButtonEvents, CopyButtonSlots> {
|
@@ -21,6 +21,12 @@
|
|
21
21
|
- `selectionStartTextarea` - `selectionStart` value of the `textarea`
|
22
22
|
- `valueTextarea` - `value` of the `textarea` element
|
23
23
|
|
24
|
+
@Events
|
25
|
+
|
26
|
+
| name | event |
|
27
|
+
| ------- | ----------------------- |
|
28
|
+
| `input` | forward from `textarea` |
|
29
|
+
|
24
30
|
@example
|
25
31
|
|
26
32
|
```svelte
|
@@ -60,6 +60,12 @@ export type EditorSlots = typeof __propDef.slots;
|
|
60
60
|
* - `selectionStartTextarea` - `selectionStart` value of the `textarea`
|
61
61
|
* - `valueTextarea` - `value` of the `textarea` element
|
62
62
|
*
|
63
|
+
* @Events
|
64
|
+
*
|
65
|
+
* | name | event |
|
66
|
+
* | ------- | ----------------------- |
|
67
|
+
* | `input` | forward from `textarea` |
|
68
|
+
*
|
63
69
|
* @example
|
64
70
|
*
|
65
71
|
* ```svelte
|
@@ -13,7 +13,7 @@ Displays a popover in relation to the `target`.
|
|
13
13
|
- `class`
|
14
14
|
- `display` - shows / hides the popover
|
15
15
|
- `id`
|
16
|
-
- `position` - where the popover is displayed in relation to the `target`
|
16
|
+
- `position` - where the popover is displayed in relation to the `target`, ex: `br` is bottom, right aligned
|
17
17
|
- `target` - target element to position the popover in relation to
|
18
18
|
- `transition` - scales the popover, set to `false` to disable
|
19
19
|
|
@@ -66,33 +66,46 @@ export let transition = { duration, start };
|
|
66
66
|
let popover;
|
67
67
|
let coordinates = { x: 0, y: 0 };
|
68
68
|
const setPosition = async () => {
|
69
|
-
if (position
|
70
|
-
|
71
|
-
if (position === "t") {
|
69
|
+
if (position.startsWith("t") || position.startsWith("b")) {
|
70
|
+
if (position.startsWith("t")) {
|
72
71
|
coordinates.y = -popover.offsetHeight;
|
73
72
|
} else {
|
74
73
|
coordinates.y = target.offsetHeight;
|
75
74
|
}
|
75
|
+
if (position.endsWith("l")) {
|
76
|
+
coordinates.x = 0;
|
77
|
+
} else if (position.endsWith("r")) {
|
78
|
+
coordinates.x = target.offsetWidth - popover.offsetWidth;
|
79
|
+
} else {
|
80
|
+
coordinates.x = target.offsetWidth / 2 - popover.offsetWidth / 2;
|
81
|
+
}
|
76
82
|
} else {
|
77
|
-
|
78
|
-
if (position === "l") {
|
83
|
+
if (position.startsWith("l")) {
|
79
84
|
coordinates.x = -popover.offsetWidth;
|
80
85
|
} else {
|
81
86
|
coordinates.x = target.offsetWidth;
|
82
87
|
}
|
88
|
+
if (position.endsWith("t")) {
|
89
|
+
coordinates.y = 0;
|
90
|
+
} else if (position.endsWith("b")) {
|
91
|
+
coordinates.y = target.offsetHeight - popover.offsetHeight;
|
92
|
+
} else {
|
93
|
+
coordinates.y = target.offsetHeight / 2 - popover.offsetHeight / 2;
|
94
|
+
}
|
83
95
|
}
|
84
96
|
const targetRect = target.getBoundingClientRect();
|
85
97
|
coordinates.x += targetRect.x + window.scrollX;
|
86
98
|
coordinates.y += targetRect.y + window.scrollY;
|
87
99
|
await tick();
|
88
100
|
const popoverRect = popover.getBoundingClientRect();
|
89
|
-
|
90
|
-
|
101
|
+
const extraMargin = 10;
|
102
|
+
if (popoverRect.x < extraMargin) {
|
103
|
+
coordinates.x += Math.abs(popoverRect.x) + extraMargin;
|
91
104
|
} else if (popoverRect.x + popover.offsetWidth > window.innerWidth) {
|
92
|
-
coordinates.x -= popoverRect.x + popover.offsetWidth - window.innerWidth +
|
105
|
+
coordinates.x -= popoverRect.x + popover.offsetWidth - window.innerWidth + extraMargin;
|
93
106
|
}
|
94
107
|
if (popoverRect.y < 0) {
|
95
|
-
coordinates.y += Math.abs(popoverRect.y);
|
108
|
+
coordinates.y += Math.abs(popoverRect.y) + extraMargin;
|
96
109
|
} else if (popoverRect.y + popover.offsetHeight > window.innerHeight) {
|
97
110
|
coordinates.y -= popoverRect.y + popover.offsetHeight - window.innerHeight;
|
98
111
|
}
|
@@ -130,5 +143,6 @@ onMount(() => {
|
|
130
143
|
<style>
|
131
144
|
div {
|
132
145
|
position: absolute;
|
146
|
+
margin: 0;
|
133
147
|
}
|
134
148
|
</style>
|
@@ -5,7 +5,7 @@ declare const __propDef: {
|
|
5
5
|
class?: string | undefined;
|
6
6
|
id?: string | undefined;
|
7
7
|
/** shows / hides the popover */ display?: boolean | undefined;
|
8
|
-
/** where the popover is displayed in relation to the `target` */ position?: "t" | "b" | "l" | "
|
8
|
+
/** where the popover is displayed in relation to the `target`, ex: `br` is bottom, right aligned */ position?: ("tr" | "tl" | "t" | "rt" | "r" | "rb" | "br" | "b" | "bl" | "lb" | "l" | "lt") | undefined;
|
9
9
|
/** target element to position the popover in relation to */ target: HTMLElement;
|
10
10
|
/** scales the popover, set to `false` to disable */ transition?: false | ScaleParams | undefined;
|
11
11
|
};
|
@@ -32,7 +32,7 @@ export type PopoverSlots = typeof __propDef.slots;
|
|
32
32
|
* - `class`
|
33
33
|
* - `display` - shows / hides the popover
|
34
34
|
* - `id`
|
35
|
-
* - `position` - where the popover is displayed in relation to the `target`
|
35
|
+
* - `position` - where the popover is displayed in relation to the `target`, ex: `br` is bottom, right aligned
|
36
36
|
* - `target` - target element to position the popover in relation to
|
37
37
|
* - `transition` - scales the popover, set to `false` to disable
|
38
38
|
*
|
@@ -7,7 +7,7 @@ declare const __propDef: {
|
|
7
7
|
/** sheet class - not the backdrop */ classSheet?: string | undefined;
|
8
8
|
/** controls whether the sheet is displayed*/ display?: boolean | undefined;
|
9
9
|
/** blurs the entire component, set to `false` to remove */ transition?: false | BlurParams | undefined;
|
10
|
-
/** determines the position of sheet */ position?: "t" | "
|
10
|
+
/** determines the position of sheet */ position?: "t" | "r" | "b" | "l" | undefined;
|
11
11
|
/** max width/height of sheet based on the `side` - can also use css instead */ maxSize?: number | undefined;
|
12
12
|
/** flies the sheet, set to `false` to remove */ transitionSheet?: false | FlyParams | undefined;
|
13
13
|
};
|