drab 4.1.6 → 5.0.0-beta.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.
Files changed (136) hide show
  1. package/animate/define.d.ts +2 -0
  2. package/animate/define.iife.js +1 -0
  3. package/animate/define.js +1 -0
  4. package/animate.d.ts +54 -0
  5. package/animate.iife.js +1 -0
  6. package/animate.js +1 -0
  7. package/base/define.d.ts +2 -0
  8. package/base/define.iife.js +1 -0
  9. package/base/define.js +1 -0
  10. package/base.d.ts +69 -0
  11. package/base.iife.js +1 -0
  12. package/base.js +1 -0
  13. package/breakpoint/define.d.ts +2 -0
  14. package/breakpoint/define.iife.js +1 -0
  15. package/breakpoint/define.js +1 -0
  16. package/breakpoint.d.ts +24 -0
  17. package/breakpoint.iife.js +1 -0
  18. package/breakpoint.js +1 -0
  19. package/chunk-2ZZQECRY.js +1 -0
  20. package/chunk-57VEEUFG.js +1 -0
  21. package/chunk-5JV4T7GM.js +1 -0
  22. package/chunk-6HYPZWQ4.js +1 -0
  23. package/chunk-7F7CQUEG.js +1 -0
  24. package/chunk-7KU2PRW5.js +1 -0
  25. package/chunk-7S6DTKGH.js +1 -0
  26. package/chunk-FNJ7AESC.js +9 -0
  27. package/chunk-IQJQPZUL.js +1 -0
  28. package/chunk-JMJUWKN2.js +1 -0
  29. package/chunk-MXKU7AKV.js +1 -0
  30. package/chunk-T7RZI3ZL.js +1 -0
  31. package/chunk-TSTTUEAF.js +1 -0
  32. package/chunk-VEVFQB5N.js +1 -0
  33. package/contextmenu/define.d.ts +2 -0
  34. package/contextmenu/define.iife.js +1 -0
  35. package/contextmenu/define.js +1 -0
  36. package/contextmenu.d.ts +15 -0
  37. package/contextmenu.iife.js +1 -0
  38. package/contextmenu.js +1 -0
  39. package/copy/define.d.ts +2 -0
  40. package/copy/define.iife.js +1 -0
  41. package/copy/define.js +1 -0
  42. package/copy.d.ts +13 -0
  43. package/copy.iife.js +1 -0
  44. package/copy.js +1 -0
  45. package/define.d.ts +2 -0
  46. package/define.iife.js +9 -0
  47. package/define.js +1 -0
  48. package/details/define.d.ts +2 -0
  49. package/details/define.iife.js +1 -0
  50. package/details/define.js +1 -0
  51. package/details.d.ts +23 -0
  52. package/details.iife.js +1 -0
  53. package/details.js +1 -0
  54. package/dialog/define.d.ts +2 -0
  55. package/dialog/define.iife.js +1 -0
  56. package/dialog/define.js +1 -0
  57. package/dialog.d.ts +20 -0
  58. package/dialog.iife.js +1 -0
  59. package/dialog.js +1 -0
  60. package/editor/define.d.ts +2 -0
  61. package/editor/define.iife.js +9 -0
  62. package/editor/define.js +1 -0
  63. package/editor.d.ts +58 -0
  64. package/editor.iife.js +9 -0
  65. package/editor.js +1 -0
  66. package/fullscreen/define.d.ts +2 -0
  67. package/fullscreen/define.iife.js +1 -0
  68. package/fullscreen/define.js +1 -0
  69. package/fullscreen.d.ts +23 -0
  70. package/fullscreen.iife.js +1 -0
  71. package/fullscreen.js +1 -0
  72. package/index-22PHGcPf.d.ts +17 -0
  73. package/index.d.ts +14 -0
  74. package/index.iife.js +9 -0
  75. package/index.js +1 -0
  76. package/package.json +131 -59
  77. package/popover/define.d.ts +2 -0
  78. package/popover/define.iife.js +1 -0
  79. package/popover/define.js +1 -0
  80. package/popover.d.ts +29 -0
  81. package/popover.iife.js +1 -0
  82. package/popover.js +1 -0
  83. package/share/define.d.ts +2 -0
  84. package/share/define.iife.js +1 -0
  85. package/share/define.js +1 -0
  86. package/share.d.ts +19 -0
  87. package/share.iife.js +1 -0
  88. package/share.js +1 -0
  89. package/tablesort/define.d.ts +2 -0
  90. package/tablesort/define.iife.js +1 -0
  91. package/tablesort/define.js +1 -0
  92. package/tablesort.d.ts +21 -0
  93. package/tablesort.iife.js +1 -0
  94. package/tablesort.js +1 -0
  95. package/youtube/define.d.ts +2 -0
  96. package/youtube/define.iife.js +1 -0
  97. package/youtube/define.js +1 -0
  98. package/youtube.d.ts +29 -0
  99. package/youtube.iife.js +1 -0
  100. package/youtube.js +1 -0
  101. package/LICENSE.md +0 -21
  102. package/README.md +0 -131
  103. package/dist/components/Breakpoint.svelte +0 -55
  104. package/dist/components/Breakpoint.svelte.d.ts +0 -46
  105. package/dist/components/ContextMenu.svelte +0 -150
  106. package/dist/components/ContextMenu.svelte.d.ts +0 -76
  107. package/dist/components/CopyButton.svelte +0 -97
  108. package/dist/components/CopyButton.svelte.d.ts +0 -60
  109. package/dist/components/DataTable.svelte +0 -208
  110. package/dist/components/DataTable.svelte.d.ts +0 -155
  111. package/dist/components/Details.svelte +0 -101
  112. package/dist/components/Details.svelte.d.ts +0 -67
  113. package/dist/components/Editor.svelte +0 -404
  114. package/dist/components/Editor.svelte.d.ts +0 -111
  115. package/dist/components/FrettedChord.svelte +0 -213
  116. package/dist/components/FrettedChord.svelte.d.ts +0 -79
  117. package/dist/components/FullscreenButton.svelte +0 -95
  118. package/dist/components/FullscreenButton.svelte.d.ts +0 -62
  119. package/dist/components/Popover.svelte +0 -153
  120. package/dist/components/Popover.svelte.d.ts +0 -80
  121. package/dist/components/ShareButton.svelte +0 -133
  122. package/dist/components/ShareButton.svelte.d.ts +0 -93
  123. package/dist/components/Sheet.svelte +0 -180
  124. package/dist/components/Sheet.svelte.d.ts +0 -99
  125. package/dist/components/Tablature.svelte +0 -173
  126. package/dist/components/Tablature.svelte.d.ts +0 -93
  127. package/dist/components/YouTube.svelte +0 -51
  128. package/dist/components/YouTube.svelte.d.ts +0 -49
  129. package/dist/index.d.ts +0 -14
  130. package/dist/index.js +0 -14
  131. package/dist/util/accessibility.d.ts +0 -6
  132. package/dist/util/accessibility.js +0 -11
  133. package/dist/util/delay.d.ts +0 -1
  134. package/dist/util/delay.js +0 -1
  135. package/dist/util/transition.d.ts +0 -2
  136. package/dist/util/transition.js +0 -2
@@ -0,0 +1 @@
1
+ "use strict";(()=>{var s=class extends HTMLElement{#t=new AbortController;constructor(){super()}get event(){return this.getAttribute("event")??"click"}set event(t){this.setAttribute("event",t)}getTrigger(){return this.querySelectorAll(this.getAttribute("trigger")??"[data-trigger]")}getContent(t=HTMLElement){let e=this.querySelector(this.getAttribute("content")??"[data-content]");if(e instanceof t)return e;throw new Error("Content not found")}swapContent(t=!0,e=800){let n=this.querySelector(this.getAttribute("swap")??"[data-swap]");if(n){let r=Array.from(this.getContent().childNodes);n instanceof HTMLTemplateElement?this.getContent().replaceChildren(n.content.cloneNode(!0)):this.getContent().replaceChildren(...n.childNodes),t&&setTimeout(()=>this.getContent().replaceChildren(...r),e)}}safeListener(t,e,n=document.body,r={}){r.signal=this.#t.signal,n.addEventListener(t,e,r)}triggerListener(t,e=this.event){for(let n of this.getTrigger())n.addEventListener(e,t)}mount(){}connectedCallback(){queueMicrotask(()=>this.mount())}disconnectedCallback(){this.#t.abort()}};var i=class extends s{static observedAttributes=["autoplay","start","uid"];constructor(){super()}get iframe(){return this.getContent(HTMLIFrameElement)}get autoplay(){return this.hasAttribute("autoplay")}set autoplay(t){t?this.setAttribute("autoplay",""):this.removeAttribute("autoplay")}get start(){return this.getAttribute("start")??"0"}set start(t){this.setAttribute("start",t)}get uid(){let t=this.getAttribute("uid");if(!t)throw new Error("YouTube: missing `uid` attribute.");return t}set uid(t){this.setAttribute("uid",t)}mount(){this.iframe.allowFullscreen=!0,this.iframe.allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"}attributeChangedCallback(){queueMicrotask(()=>{this.iframe.src=`https://www.youtube-nocookie.com/embed/${this.uid}?start=${this.start}${this.autoplay?"&autoplay=1":""}`})}};})();
package/youtube.js ADDED
@@ -0,0 +1 @@
1
+ import{a}from"./chunk-VEVFQB5N.js";import"./chunk-MXKU7AKV.js";export{a as YouTube};
package/LICENSE.md DELETED
@@ -1,21 +0,0 @@
1
- MIT License
2
-
3
- Copyright (c) 2023 Ross Robino
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
package/README.md DELETED
@@ -1,131 +0,0 @@
1
- # An Unstyled Svelte Component Library
2
-
3
- - [Docs](https://drab.robino.dev)
4
- - [GitHub](https://github.com/rossrobino/drab)
5
- - [npm](https://www.npmjs.com/package/drab)
6
- - [MIT License](https://github.com/rossrobino/drab/blob/main/LICENSE.md)
7
-
8
- ## About
9
-
10
- **drab** focuses on providing JavaScript functionality where it's most useful. Many of the components are helpful wrappers around browser APIs. Here are some of the features of the library.
11
-
12
- - Components are minimal in size, currently **drab** has one dependency--Svelte
13
- - Whenever possible, components are [progressively enhanced](https://drab.robino.dev/docs/ShareButton) or provide a fallback [noscript](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/noscript) message
14
- - Transitions are disabled for users who prefer reduced motion
15
- - All components support server side rendering--they will not break your application depending on your rendering preferences
16
-
17
- This library takes a more opinionated approach compared to some headless UI libraries by providing the basic HTML structure for every component, as well as default positioning for elements like the [sheet](https://drab.robino.dev/docs/Sheet). However, these components can still be further customized using styles, [slots](https://svelte.dev/tutorial/slots), and [slot props](https://svelte.dev/tutorial/slot-props).
18
-
19
- ## Install
20
-
21
- If you haven't used Svelte before, start with the [tutorial](https://svelte.dev/tutorial/basics). **drab** works anywhere Svelte does.
22
-
23
- - [SvelteKit](https://kit.svelte.dev)
24
- - [Astro](https://docs.astro.build/en/tutorial/1-setup/2/)
25
- - [Vite](https://vitejs.dev/guide/)
26
-
27
- ```bash
28
- npm i -D drab
29
- ```
30
-
31
- ## Documentation
32
-
33
- The library provides inline documentation for each component using JSDoc, allowing you to conveniently access the documentation by hovering over the component in your text editor after importing it. Additionally, every prop is documented using JSDoc and TypeScript. By hovering over a prop, you can retrieve its type and description.
34
-
35
- ## Other UI Libraries
36
-
37
- **drab** is a collection of useful components, not a complete UI kit. If **drab** isn't what you are looking for, here are some other libraries to check out.
38
-
39
- - [uico](https://uico.robino.dev) - a Tailwind plugin for CSS components designed to be complementary to **drab** (used to create this site)
40
- - [daisyUI](https://daisyui.com/)
41
- - [Skeleton](https://skeleton.dev)
42
- - [Carbon Components](https://carbon-components-svelte.onrender.com/)
43
- - [Melt UI](https://www.melt-ui.com/)
44
- - [shadcn-svelte](https://www.shadcn-svelte.com/)
45
- - [Svelte-HeadlessUI](https://captaincodeman.github.io/svelte-headlessui/)
46
-
47
- ## Styling
48
-
49
- Components without styles can appear rather drab. You have the freedom to bring your own styles to these components. Using unstyled components allows you to selectively choose what you need and avoid being tied to any specific library.
50
-
51
- To style the markup provided by the components, you can make use of [global styles](https://joyofcode.xyz/global-styles-in-sveltekit). Each component exports `class` and `id` props that can be leveraged for this purpose. This process can be expedited by utilizing CSS frameworks like [TailwindCSS](https://tailwindcss.com/). Tailwind generates a global stylesheet based on the utility classes used in your project. The examples in this documentation are styled with Tailwind with the [uico](https://uico.robino.dev) and [typography](https://tailwindcss.com/docs/typography-plugin) plugins. Tailwind does not have to be used with this library.
52
-
53
- ### Stylesheet
54
-
55
- Here's a SvelteKit example using CSS imported in a layout. By using a layout, these styles can be accessed anywhere.
56
-
57
- ```css
58
- /* src/app.css */
59
- .button {
60
- border-radius: 5px;
61
- background-color: black;
62
- padding: 5px;
63
- color: white;
64
- }
65
- ```
66
-
67
- ```svelte
68
- <!-- src/routes/+layout.svelte -->
69
- <script>
70
- import "../app.css";
71
- </script>
72
-
73
- <slot />
74
- ```
75
-
76
- ```svelte
77
- <!-- src/routes/+page.svelte -->
78
- <script>
79
- import { FullscreenButton } from "drab";
80
- </script>
81
-
82
- <FullscreenButton class="button" />
83
- ```
84
-
85
- ### Global modifier
86
-
87
- Alternatively, the [`:global()` modifier](https://svelte.dev/docs/svelte-components#style) can be used instead of a separate stylesheet.
88
-
89
- ```svelte
90
- <!-- src/routes/+page.svelte -->
91
- <script>
92
- import { FullscreenButton } from "drab";
93
- </script>
94
-
95
- <FullscreenButton class="button" />
96
-
97
- <style>
98
- :global(.button) {
99
- border-radius: 5px;
100
- background-color: black;
101
- padding: 5px;
102
- color: white;
103
- }
104
- </style>
105
- ```
106
-
107
- ## Contributing
108
-
109
- Find an bug or have an idea? Feel free to create an issue on [GitHub](https://github.com/rossrobino/drab). **drab** is meant to house all kinds of components including ones outside of the standard UI elements.
110
-
111
- Currently, **drab** has only one dependency - Svelte. Not to say it will never have another, but please consider this when proposing additional functionality. **drab** is meant to make the most of what Svelte and the web platform provide.
112
-
113
- Since this is an unstyled library, simple components like a badge that can be easily created with HTML and CSS are not included.
114
-
115
- ### Local Development
116
-
117
- Contribute to the project, or use **drab** as a template for another component library. This library is built with SvelteKit, and TypeScript. The package contents are located in `src/lib`, the site is contained within `src/routes` and `src/site`. If you are using this project as a template, be sure to [update the adapter](https://kit.svelte.dev/docs/adapters) based on how you deploy.
118
-
119
- #### Make changes
120
-
121
- 1. Clone the [repository](https://github.com/rossrobino/drab)
122
- 2. `bun i`
123
- 3. `bun run dev`
124
-
125
- #### Add or edit a component
126
-
127
- 1. Add or edit the component in `src/lib/components/Component.svelte` - if you're adding a new one, copy and paste an existing one to get started with the conventions
128
- 2. Add or edit the example in `src/routes/docs/Component/+page.svelte`
129
- 3. Document the component with an `@component` comment, include a description, and the `@slots` available. Add a placeholder `@props` and `@example` to the comment. These sections will be generated based on the JSDoc comment above each prop and the example route upon running `bun doc`
130
- 4. If new, add the link to `src/site/components/NavItems.svelte`
131
- 5. Run `bun package` to verify your build
@@ -1,55 +0,0 @@
1
- <!--
2
- @component
3
-
4
- ### Breakpoints
5
-
6
- Displays the current breakpoint and `window.innerWidth`, based on the `breakpoints` provided. Defaults to [TailwindCSS breakpoint sizes](https://tailwindcss.com/docs/responsive-design).
7
-
8
- With SvelteKit, this component can be wrapped in an `{#if dev}` block that checks for the [dev module](https://kit.svelte.dev/docs/modules#$app-environment-dev), to show only during development.
9
-
10
- @props
11
-
12
- - `breakpoints` - array of objects representing the breakpoints of the application
13
- - `class`
14
- - `id`
15
-
16
- @example
17
-
18
- ```svelte
19
- <script lang="ts">
20
- import { Breakpoint } from "drab";
21
- </script>
22
-
23
- <Breakpoint
24
- class="card inline-block px-3 py-2 font-mono text-sm tabular-nums"
25
- />
26
- ```
27
- -->
28
-
29
- <script>let className = "";
30
- export { className as class };
31
- export let id = "";
32
- export let breakpoints = [
33
- { name: "sm", width: 640 },
34
- { name: "md", width: 768 },
35
- { name: "lg", width: 1024 },
36
- { name: "xl", width: 1280 },
37
- { name: "2xl", width: 1536 }
38
- ];
39
- breakpoints.sort((a, b) => b.width - a.width);
40
- let innerWidth = 0;
41
- $:
42
- breakpoint = getBreakpoint(innerWidth);
43
- const getBreakpoint = (innerWidth2) => {
44
- for (let i = 0; i < breakpoints.length; i++) {
45
- if (innerWidth2 > breakpoints[i].width) {
46
- return breakpoints[i].name;
47
- }
48
- }
49
- return "none";
50
- };
51
- </script>
52
-
53
- <svelte:window bind:innerWidth />
54
-
55
- <div class={className} {id}>{breakpoint}:{innerWidth}</div>
@@ -1,46 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- class?: string | undefined;
5
- id?: string | undefined;
6
- /** array of objects representing the breakpoints of the application */ breakpoints?: {
7
- name: string;
8
- width: number;
9
- }[] | undefined;
10
- };
11
- events: {
12
- [evt: string]: CustomEvent<any>;
13
- };
14
- slots: {};
15
- };
16
- export type BreakpointProps = typeof __propDef.props;
17
- export type BreakpointEvents = typeof __propDef.events;
18
- export type BreakpointSlots = typeof __propDef.slots;
19
- /**
20
- * ### Breakpoints
21
- *
22
- * Displays the current breakpoint and `window.innerWidth`, based on the `breakpoints` provided. Defaults to [TailwindCSS breakpoint sizes](https://tailwindcss.com/docs/responsive-design).
23
- *
24
- * With SvelteKit, this component can be wrapped in an `{#if dev}` block that checks for the [dev module](https://kit.svelte.dev/docs/modules#$app-environment-dev), to show only during development.
25
- *
26
- * @props
27
- *
28
- * - `breakpoints` - array of objects representing the breakpoints of the application
29
- * - `class`
30
- * - `id`
31
- *
32
- * @example
33
- *
34
- * ```svelte
35
- * <script lang="ts">
36
- * import { Breakpoint } from "drab";
37
- * </script>
38
- *
39
- * <Breakpoint
40
- * class="card inline-block px-3 py-2 font-mono text-sm tabular-nums"
41
- * />
42
- * ```
43
- */
44
- export default class Breakpoint extends SvelteComponent<BreakpointProps, BreakpointEvents, BreakpointSlots> {
45
- }
46
- export {};
@@ -1,150 +0,0 @@
1
- <!--
2
- @component
3
-
4
- ### ContextMenu
5
-
6
- Displays when the `target` element is right clicked, or long pressed on mobile.
7
-
8
- @props
9
-
10
- - `class`
11
- - `display` - shows / hides the menu
12
- - `id`
13
- - `target` - target element to right click, defaults to the parent element
14
- - `transition` - scales the menu, set to `false` to disable
15
-
16
- @slots
17
-
18
- | name | purpose | default value |
19
- | ---------- | ------------------------------- | ------------- |
20
- | `default` | default | Context Menu |
21
-
22
- @example
23
-
24
- ```svelte
25
- <script lang="ts">
26
- import { ContextMenu } from "drab";
27
-
28
- let target: HTMLButtonElement;
29
- </script>
30
-
31
- <div class="mb-8 flex justify-center rounded border bg-muted p-12">
32
- <div>Parent right click</div>
33
- <ContextMenu class="z-10">
34
- <div class="card flex w-48 flex-col gap-2 p-2 shadow-md">
35
- <div class="font-bold">Context Menu</div>
36
- <button role="menuitem" class="button button-secondary">Button</button>
37
- <button role="menuitem" class="button button-secondary">Button</button>
38
- <button role="menuitem" class="button button-secondary">Button</button>
39
- </div>
40
- </ContextMenu>
41
- </div>
42
-
43
- <button type="button" class="button button-primary" bind:this={target}>
44
- Target Right Click
45
- </button>
46
- <ContextMenu {target} class="z-10">
47
- <div class="card flex w-48 flex-col gap-2 p-2 shadow-md">
48
- <div class="font-bold">Target</div>
49
- <button role="menuitem" class="button button-secondary">Button</button>
50
- <button role="menuitem" class="button button-secondary">Button</button>
51
- <button role="menuitem" class="button button-secondary">Button</button>
52
- </div>
53
- </ContextMenu>
54
- ```
55
- -->
56
-
57
- <script>import { onMount, tick } from "svelte";
58
- import { scale } from "svelte/transition";
59
- import { duration, start } from "../util/transition";
60
- import { prefersReducedMotion } from "../util/accessibility";
61
- import { delay } from "../util/delay";
62
- let className = "";
63
- export { className as class };
64
- export let id = "";
65
- export let display = false;
66
- export let transition = { duration, start };
67
- export let target = null;
68
- let contextMenu;
69
- let base;
70
- let coordinates = { x: 0, y: 0 };
71
- const hide = () => display = false;
72
- const onKeyDown = (e) => {
73
- if (e.key === "Escape") {
74
- display = false;
75
- }
76
- };
77
- const displayMenu = async (e) => {
78
- e.preventDefault();
79
- const scrollY = window.scrollY;
80
- const scrollX = window.scrollX;
81
- const clientX = e instanceof MouseEvent ? e.clientX : e.touches[0].clientX;
82
- const clientY = e instanceof MouseEvent ? e.clientY : e.touches[0].clientY;
83
- coordinates.x = clientX + scrollX;
84
- coordinates.y = clientY + scrollY;
85
- display = true;
86
- await tick();
87
- const offsetWidth = contextMenu.offsetWidth + 24;
88
- const offsetHeight = contextMenu.offsetHeight + 6;
89
- const innerWidth = window.innerWidth;
90
- const innerHeight = window.innerHeight;
91
- if (coordinates.x + offsetWidth > scrollX + innerWidth) {
92
- coordinates.x = scrollX + innerWidth - offsetWidth;
93
- }
94
- if (coordinates.y + offsetHeight > scrollY + innerHeight) {
95
- coordinates.y = scrollY + innerHeight - offsetHeight;
96
- }
97
- };
98
- let timer;
99
- const onTouchStart = (e) => {
100
- timer = setTimeout(() => {
101
- displayMenu(e);
102
- }, delay);
103
- };
104
- const onTouchEnd = () => {
105
- clearTimeout(timer);
106
- };
107
- onMount(async () => {
108
- if (prefersReducedMotion())
109
- transition = false;
110
- await tick();
111
- if (!target) {
112
- target = base.parentElement;
113
- }
114
- if (target) {
115
- target.addEventListener("contextmenu", displayMenu);
116
- target.addEventListener("touchstart", onTouchStart);
117
- target.addEventListener("touchend", onTouchEnd);
118
- target.addEventListener("touchcancel", onTouchEnd);
119
- }
120
- });
121
- </script>
122
-
123
- <svelte:body on:click={hide} on:keydown={onKeyDown} />
124
-
125
- <span bind:this={base} role="presentation"></span>
126
-
127
- {#if display}
128
- <div
129
- role="menu"
130
- class={className}
131
- {id}
132
- bind:this={contextMenu}
133
- style:top="{coordinates.y}px"
134
- style:left="{coordinates.x}px"
135
- transition:scale={transition ? transition : { duration: 0 }}
136
- >
137
- <slot>Context Menu</slot>
138
- </div>
139
- {/if}
140
-
141
- <style>
142
- span {
143
- opacity: 0;
144
- width: 0;
145
- height: 0;
146
- }
147
- div {
148
- position: absolute;
149
- }
150
- </style>
@@ -1,76 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- import { type ScaleParams } from "svelte/transition";
3
- declare const __propDef: {
4
- props: {
5
- class?: string | undefined;
6
- id?: string | undefined;
7
- /** shows / hides the menu */ display?: boolean | undefined;
8
- /** scales the menu, set to `false` to disable */ transition?: false | ScaleParams | undefined;
9
- /** target element to right click, defaults to the parent element */ target?: HTMLElement | null | undefined;
10
- };
11
- events: {
12
- [evt: string]: CustomEvent<any>;
13
- };
14
- slots: {
15
- default: {};
16
- };
17
- };
18
- export type ContextMenuProps = typeof __propDef.props;
19
- export type ContextMenuEvents = typeof __propDef.events;
20
- export type ContextMenuSlots = typeof __propDef.slots;
21
- /**
22
- * ### ContextMenu
23
- *
24
- * Displays when the `target` element is right clicked, or long pressed on mobile.
25
- *
26
- * @props
27
- *
28
- * - `class`
29
- * - `display` - shows / hides the menu
30
- * - `id`
31
- * - `target` - target element to right click, defaults to the parent element
32
- * - `transition` - scales the menu, set to `false` to disable
33
- *
34
- * @slots
35
- *
36
- * | name | purpose | default value |
37
- * | ---------- | ------------------------------- | ------------- |
38
- * | `default` | default | Context Menu |
39
- *
40
- * @example
41
- *
42
- * ```svelte
43
- * <script lang="ts">
44
- * import { ContextMenu } from "drab";
45
- *
46
- * let target: HTMLButtonElement;
47
- * </script>
48
- *
49
- * <div class="mb-8 flex justify-center rounded border bg-muted p-12">
50
- * <div>Parent right click</div>
51
- * <ContextMenu class="z-10">
52
- * <div class="card flex w-48 flex-col gap-2 p-2 shadow-md">
53
- * <div class="font-bold">Context Menu</div>
54
- * <button role="menuitem" class="button button-secondary">Button</button>
55
- * <button role="menuitem" class="button button-secondary">Button</button>
56
- * <button role="menuitem" class="button button-secondary">Button</button>
57
- * </div>
58
- * </ContextMenu>
59
- * </div>
60
- *
61
- * <button type="button" class="button button-primary" bind:this={target}>
62
- * Target Right Click
63
- * </button>
64
- * <ContextMenu {target} class="z-10">
65
- * <div class="card flex w-48 flex-col gap-2 p-2 shadow-md">
66
- * <div class="font-bold">Target</div>
67
- * <button role="menuitem" class="button button-secondary">Button</button>
68
- * <button role="menuitem" class="button button-secondary">Button</button>
69
- * <button role="menuitem" class="button button-secondary">Button</button>
70
- * </div>
71
- * </ContextMenu>
72
- * ```
73
- */
74
- export default class ContextMenu extends SvelteComponent<ContextMenuProps, ContextMenuEvents, ContextMenuSlots> {
75
- }
76
- export {};
@@ -1,97 +0,0 @@
1
- <!--
2
- @component
3
-
4
- ### CopyButton
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.
7
-
8
- @props
9
-
10
- - `blobParts` - array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
11
- - `blob` - use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)`
12
- - `class`
13
- - `id`
14
- - `options` - defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
15
- - `title`
16
-
17
- @slots
18
-
19
- | name | purpose | default value |
20
- | ---------- | ------------------------------- | ------------- |
21
- | `default` | default | `Copy` |
22
- | `complete` | displays after copy is complete | `Copied` |
23
-
24
- @example
25
-
26
- ```svelte
27
- <script lang="ts">
28
- import { CopyButton } from "drab";
29
-
30
- let value = "";
31
- </script>
32
-
33
- <label for="copyInput" class="label">Text to Copy</label>
34
- <input id="copyInput" class="input mb-4" type="text" bind:value />
35
-
36
- <CopyButton class="button button-primary" blobParts={[value]} />
37
- ```
38
- -->
39
-
40
- <script>import { onMount } from "svelte";
41
- import { delay } from "../util/delay";
42
- let className = "";
43
- export { className as class };
44
- export let id = "";
45
- export let title = "";
46
- export let options = { type: "text/plain" };
47
- export let blobParts = void 0;
48
- export let blob = new Blob(blobParts, options);
49
- let disabled = true;
50
- let complete = false;
51
- let blobText;
52
- const setBlobText = async (blob2) => blobText = await blob2.text();
53
- const writeSupport = () => "write" in navigator.clipboard;
54
- const canWriteText = () => {
55
- const writeTextSupport = "writeText" in navigator.clipboard;
56
- const typeText = blob.type.startsWith("text");
57
- return writeTextSupport && typeText;
58
- };
59
- const copyText = async () => {
60
- try {
61
- if (writeSupport()) {
62
- const data = [new ClipboardItem({ [blob.type]: blob })];
63
- await navigator.clipboard.write(data);
64
- } else if (canWriteText()) {
65
- await navigator.clipboard.writeText(blobText);
66
- }
67
- complete = true;
68
- setTimeout(() => complete = false, delay);
69
- } catch (error) {
70
- console.error(error);
71
- }
72
- };
73
- onMount(async () => {
74
- if (writeSupport() || canWriteText())
75
- disabled = false;
76
- });
77
- $:
78
- if (blobParts)
79
- blob = new Blob(blobParts, options);
80
- $:
81
- setBlobText(blob);
82
- </script>
83
-
84
- <button
85
- type="button"
86
- {disabled}
87
- on:click={copyText}
88
- class={className}
89
- {id}
90
- {title}
91
- >
92
- {#if complete}
93
- <slot name="complete">Copied</slot>
94
- {:else}
95
- <slot>Copy</slot>
96
- {/if}
97
- </button>
@@ -1,60 +0,0 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- class?: string | undefined;
5
- id?: string | undefined;
6
- title?: string | undefined;
7
- /** defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters) */ options?: BlobPropertyBag | undefined;
8
- /** array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters) */ blobParts?: BlobPart[] | undefined;
9
- /** use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)` */ blob?: Blob | undefined;
10
- };
11
- events: {
12
- [evt: string]: CustomEvent<any>;
13
- };
14
- slots: {
15
- complete: {};
16
- default: {};
17
- };
18
- };
19
- export type CopyButtonProps = typeof __propDef.props;
20
- export type CopyButtonEvents = typeof __propDef.events;
21
- export type CopyButtonSlots = typeof __propDef.slots;
22
- /**
23
- * ### CopyButton
24
- *
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.
26
- *
27
- * @props
28
- *
29
- * - `blobParts` - array of `BlobParts` to copy - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
30
- * - `blob` - use a blob in instead of `blobParts` and `options`, defaults to `new Blob(blobParts, options)`
31
- * - `class`
32
- * - `id`
33
- * - `options` - defaults to `{ type: "text/plain" }` - [MDN Reference](https://developer.mozilla.org/en-US/docs/Web/API/Blob/Blob#parameters)
34
- * - `title`
35
- *
36
- * @slots
37
- *
38
- * | name | purpose | default value |
39
- * | ---------- | ------------------------------- | ------------- |
40
- * | `default` | default | `Copy` |
41
- * | `complete` | displays after copy is complete | `Copied` |
42
- *
43
- * @example
44
- *
45
- * ```svelte
46
- * <script lang="ts">
47
- * import { CopyButton } from "drab";
48
- *
49
- * let value = "";
50
- * </script>
51
- *
52
- * <label for="copyInput" class="label">Text to Copy</label>
53
- * <input id="copyInput" class="input mb-4" type="text" bind:value />
54
- *
55
- * <CopyButton class="button button-primary" blobParts={[value]} />
56
- * ```
57
- */
58
- export default class CopyButton extends SvelteComponent<CopyButtonProps, CopyButtonEvents, CopyButtonSlots> {
59
- }
60
- export {};