drab 3.0.2 → 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.
@@ -1,65 +1,71 @@
1
- <!--
2
- @component
3
-
4
- ### Editor
5
-
6
- `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, the `valueTextarea` is just a `string`, so you can easily store it in a database or manipulate it without learning a separate API.
7
-
8
- - This component is used to create [Typo](https://typo.robino.dev)
9
-
10
- @props
11
-
12
- - `classButton` - `class` of all the `button` elements
13
- - `classControls` - `class` of the `div` that wraps the controls
14
- - `classTextarea` - `class` of the `textarea` element
15
- - `contentElements` - an array of `EditorContentElement`s for the controls
16
- - `idControls` - `id` of the `div` that wraps the controls
17
- - `idTextarea` - `id` of the `textarea` element
18
- - `keyPairs` - keys that will auto-close if typed, value is their closing character
19
- - `nameTextarea` - `name` of the `textarea` element
20
- - `placeholderTextarea` - `placeholder` of the `textarea` element
21
- - `selectionStartTextarea` - `selectionStart` value of the `textarea`
22
- - `valueTextarea` - `value` of the `textarea` element
23
-
24
- @example
25
-
26
- ```svelte
27
- <script lang="ts">
28
- import { Editor } from "drab";
29
- </script>
30
-
31
- <Editor
32
- classButton="btn"
33
- classControls="flex gap-2"
34
- classTextarea="border w-full h-36 p-2 rounded mb-2"
35
- placeholderTextarea="asterisk: ctrl+i, anchor: ctrl+["
36
- contentElements={[
37
- {
38
- title: "Bullet",
39
- text: "- ",
40
- display: "block",
41
- icon: "Bullet",
42
- },
43
- {
44
- title: "Italic",
45
- text: "*",
46
- display: "wrap",
47
- icon: "Italic",
48
- key: "i",
49
- class: "italic",
50
- },
51
- {
52
- title: "Anchor",
53
- text: "[text](href)",
54
- display: "inline",
55
- icon: "Anchor",
56
- key: "[",
57
- },
58
- ]}
59
- />
60
- ```
61
- -->
62
-
1
+ <!--
2
+ @component
3
+
4
+ ### Editor
5
+
6
+ `textarea` element with controls to add content and keyboard shortcuts. Compared to other WYSIWYG editors, the `valueTextarea` is just a `string`, so you can easily store it in a database or manipulate it without learning a separate API.
7
+
8
+ - This component is used to create [Typo](https://typo.robino.dev)
9
+
10
+ @props
11
+
12
+ - `classButton` - `class` of all the `button` elements
13
+ - `classControls` - `class` of the `div` that wraps the controls
14
+ - `classTextarea` - `class` of the `textarea` element
15
+ - `contentElements` - an array of `EditorContentElement`s for the controls
16
+ - `idControls` - `id` of the `div` that wraps the controls
17
+ - `idTextarea` - `id` of the `textarea` element
18
+ - `keyPairs` - keys that will auto-close if typed, value is their closing character
19
+ - `nameTextarea` - `name` of the `textarea` element
20
+ - `placeholderTextarea` - `placeholder` of the `textarea` element
21
+ - `selectionStartTextarea` - `selectionStart` value of the `textarea`
22
+ - `valueTextarea` - `value` of the `textarea` element
23
+
24
+ @Events
25
+
26
+ | name | event |
27
+ | ------- | ----------------------- |
28
+ | `input` | forward from `textarea` |
29
+
30
+ @example
31
+
32
+ ```svelte
33
+ <script lang="ts">
34
+ import { Editor } from "drab";
35
+ </script>
36
+
37
+ <Editor
38
+ classButton="btn"
39
+ classControls="flex gap-2"
40
+ classTextarea="border w-full h-36 p-2 rounded mb-2"
41
+ placeholderTextarea="asterisk: ctrl+i, anchor: ctrl+["
42
+ contentElements={[
43
+ {
44
+ title: "Bullet",
45
+ text: "- ",
46
+ display: "block",
47
+ icon: "Bullet",
48
+ },
49
+ {
50
+ title: "Italic",
51
+ text: "*",
52
+ display: "wrap",
53
+ icon: "Italic",
54
+ key: "i",
55
+ class: "italic",
56
+ },
57
+ {
58
+ title: "Anchor",
59
+ text: "[text](href)",
60
+ display: "inline",
61
+ icon: "Anchor",
62
+ key: "[",
63
+ },
64
+ ]}
65
+ />
66
+ ```
67
+ -->
68
+
63
69
  <script>import { onMount } from "svelte";
64
70
  export let contentElements = [];
65
71
  export let valueTextarea = "";
@@ -338,39 +344,39 @@ const correctFollowing = (currentLineNumber, decrement = false) => {
338
344
  valueTextarea = lines.join("\n");
339
345
  };
340
346
  onMount(() => clientJs = true);
341
- </script>
342
-
343
- <textarea
344
- id={idTextarea}
345
- class={classTextarea}
346
- name={nameTextarea}
347
- placeholder={placeholderTextarea}
348
- on:keydown={onKeyDown}
349
- on:keyup={updateSelectionStart}
350
- on:dblclick={trimSelection}
351
- bind:value={valueTextarea}
352
- bind:this={textArea}
353
- on:click={() => {
354
- openChars = [];
355
- updateSelectionStart();
356
- }}
357
- on:input
358
- />
359
-
360
- <div id={idControls} class={classControls}>
361
- {#each contentElements as el}
362
- <button
363
- type="button"
364
- class={el.class ? `${classButton} ${el.class}` : classButton}
365
- on:click={() => addContent(el)}
366
- title={el.title}
367
- disabled={!clientJs}
368
- >
369
- {#if typeof el.icon !== "string"}
370
- <svelte:component this={el.icon} />
371
- {:else}
372
- {el.icon}
373
- {/if}
374
- </button>
375
- {/each}
376
- </div>
347
+ </script>
348
+
349
+ <textarea
350
+ id={idTextarea}
351
+ class={classTextarea}
352
+ name={nameTextarea}
353
+ placeholder={placeholderTextarea}
354
+ on:keydown={onKeyDown}
355
+ on:keyup={updateSelectionStart}
356
+ on:dblclick={trimSelection}
357
+ bind:value={valueTextarea}
358
+ bind:this={textArea}
359
+ on:click={() => {
360
+ openChars = [];
361
+ updateSelectionStart();
362
+ }}
363
+ on:input
364
+ />
365
+
366
+ <div id={idControls} class={classControls}>
367
+ {#each contentElements as el}
368
+ <button
369
+ type="button"
370
+ class={el.class ? `${classButton} ${el.class}` : classButton}
371
+ on:click={() => addContent(el)}
372
+ title={el.title}
373
+ disabled={!clientJs}
374
+ >
375
+ {#if typeof el.icon !== "string"}
376
+ <svelte:component this={el.icon} />
377
+ {:else}
378
+ {el.icon}
379
+ {/if}
380
+ </button>
381
+ {/each}
382
+ </div>
@@ -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
@@ -1,57 +1,57 @@
1
- <!--
2
- @component
3
-
4
- ### FrettedChord
5
-
6
- Generates a fretted chord `svg` for instruments like guitar and ukulele.
7
-
8
- Try it out and generate code: [FrettedChord Creator](https://svelte.dev/repl/5771d5c3f3c34137a174c8c402ca0b2d?version=4.2.0)
9
-
10
- @props
11
-
12
- - `class`
13
- - `id`
14
- - `name` - name of chord
15
- - `notes` - list of the positioning of the notes required for the chord
16
- - `size` - total size of chord square in pixels, defaults to `150`
17
- - `strings` - total number of strings for the instrument
18
-
19
- @example
20
-
21
- ```svelte
22
- <script lang="ts">
23
- import { FrettedChord } from "drab";
24
- </script>
25
-
26
- <FrettedChord
27
- class="font-mono text-neutral-950"
28
- name="D"
29
- notes={[
30
- {
31
- finger: 0,
32
- string: 4,
33
- fret: 0,
34
- },
35
- {
36
- finger: 1,
37
- string: 3,
38
- fret: 2,
39
- },
40
- {
41
- finger: 2,
42
- string: 1,
43
- fret: 2,
44
- },
45
- {
46
- finger: 3,
47
- string: 2,
48
- fret: 3,
49
- },
50
- ]}
51
- />
52
- ```
53
- -->
54
-
1
+ <!--
2
+ @component
3
+
4
+ ### FrettedChord
5
+
6
+ Generates a fretted chord `svg` for instruments like guitar and ukulele.
7
+
8
+ Try it out and generate code: [FrettedChord Creator](https://svelte.dev/repl/5771d5c3f3c34137a174c8c402ca0b2d?version=4.2.0)
9
+
10
+ @props
11
+
12
+ - `class`
13
+ - `id`
14
+ - `name` - name of chord
15
+ - `notes` - list of the positioning of the notes required for the chord
16
+ - `size` - total size of chord square in pixels, defaults to `150`
17
+ - `strings` - total number of strings for the instrument
18
+
19
+ @example
20
+
21
+ ```svelte
22
+ <script lang="ts">
23
+ import { FrettedChord } from "drab";
24
+ </script>
25
+
26
+ <FrettedChord
27
+ class="font-mono text-neutral-950"
28
+ name="D"
29
+ notes={[
30
+ {
31
+ finger: 0,
32
+ string: 4,
33
+ fret: 0,
34
+ },
35
+ {
36
+ finger: 1,
37
+ string: 3,
38
+ fret: 2,
39
+ },
40
+ {
41
+ finger: 2,
42
+ string: 1,
43
+ fret: 2,
44
+ },
45
+ {
46
+ finger: 3,
47
+ string: 2,
48
+ fret: 3,
49
+ },
50
+ ]}
51
+ />
52
+ ```
53
+ -->
54
+
55
55
  <script>let className = "";
56
56
  export { className as class };
57
57
  export let id = "";
@@ -111,103 +111,103 @@ const noteX = (string) => {
111
111
  const noteY = (fret) => {
112
112
  return boxSize / fretRange * fret + offset / 2 - boxSize / fretRange / 2;
113
113
  };
114
- </script>
115
-
116
- {#if notes.length}
117
- <svg
118
- width={size}
119
- height={size}
120
- stroke="currentColor"
121
- fill="currentColor"
122
- class={className}
123
- {id}
124
- >
125
- <title>{name}</title>
126
-
127
- <!-- BACKGROUND -->
128
- <rect
129
- width={boxSize}
130
- height={boxSize}
131
- fill="transparent"
132
- x={offset}
133
- y={offset / 2}
134
- stroke-width={strokeWidth}
135
- />
136
- <line
137
- x1={offset - strokeWidth / 2}
138
- y1={offset / 2 - strokeWidth / 2}
139
- x2={boxSize + offset + strokeWidth / 2}
140
- y2={offset / 2 - strokeWidth / 2}
141
- stroke-width={strokeWidth * 2}
142
- />
143
-
144
- <!-- FRETS -->
145
- {#each Array.from(Array(fretRange).keys()) as fret}
146
- <line
147
- x1={offset}
148
- y1={fretY(fret) - offset / 2}
149
- x2={boxSize + offset}
150
- y2={fretY(fret) - offset / 2}
151
- stroke-width={strokeWidth}
152
- opacity="0.2"
153
- />
154
- {/each}
155
-
156
- <!-- STRINGS -->
157
- {#each stringList as string}
158
- <line
159
- x1={stringX(string)}
160
- y1={offset / 2}
161
- x2={stringX(string)}
162
- y2={boxSize + offset / 2}
163
- stroke-width={strokeWidth}
164
- />
165
- {/each}
166
-
167
- <!-- NOTES -->
168
- {#each notesList as note}
169
- {#if note.fret !== 0}
170
- <circle
171
- cx={noteX(note.string)}
172
- cy={noteY(note.fret)}
173
- r={circleRadius}
174
- />
175
- {/if}
176
- {#if note.finger !== 0}
177
- <!-- RECOMMENDED FINGER -->
178
- <text
179
- x={noteX(note.string) - size / 50}
180
- y={note.fret === 0
181
- ? offset / 2 - strokeWidth * 2.4
182
- : size - offset * 1.1}
183
- color="currentColor"
184
- fill="currentColor"
185
- font-size={size / 13}
186
- >
187
- {note.finger}
188
- </text>
189
- {/if}
190
- {/each}
191
-
192
- <!-- CHORD NAME -->
193
- <text
194
- x={offset}
195
- y={size - offset / 2.5}
196
- font-size={boxSize / 6}
197
- font-weight="600"
198
- >
199
- {name}
200
- </text>
201
-
202
- <!-- STARTING FRET -->
203
- {#if firstFret > 1}
204
- <text
205
- x={size - offset / 1.8}
206
- y={offset / 2 + boxSize / 7}
207
- font-size={size / 13}
208
- >
209
- {firstFret}f
210
- </text>
211
- {/if}
212
- </svg>
213
- {/if}
114
+ </script>
115
+
116
+ {#if notes.length}
117
+ <svg
118
+ width={size}
119
+ height={size}
120
+ stroke="currentColor"
121
+ fill="currentColor"
122
+ class={className}
123
+ {id}
124
+ >
125
+ <title>{name}</title>
126
+
127
+ <!-- BACKGROUND -->
128
+ <rect
129
+ width={boxSize}
130
+ height={boxSize}
131
+ fill="transparent"
132
+ x={offset}
133
+ y={offset / 2}
134
+ stroke-width={strokeWidth}
135
+ />
136
+ <line
137
+ x1={offset - strokeWidth / 2}
138
+ y1={offset / 2 - strokeWidth / 2}
139
+ x2={boxSize + offset + strokeWidth / 2}
140
+ y2={offset / 2 - strokeWidth / 2}
141
+ stroke-width={strokeWidth * 2}
142
+ />
143
+
144
+ <!-- FRETS -->
145
+ {#each Array.from(Array(fretRange).keys()) as fret}
146
+ <line
147
+ x1={offset}
148
+ y1={fretY(fret) - offset / 2}
149
+ x2={boxSize + offset}
150
+ y2={fretY(fret) - offset / 2}
151
+ stroke-width={strokeWidth}
152
+ opacity="0.2"
153
+ />
154
+ {/each}
155
+
156
+ <!-- STRINGS -->
157
+ {#each stringList as string}
158
+ <line
159
+ x1={stringX(string)}
160
+ y1={offset / 2}
161
+ x2={stringX(string)}
162
+ y2={boxSize + offset / 2}
163
+ stroke-width={strokeWidth}
164
+ />
165
+ {/each}
166
+
167
+ <!-- NOTES -->
168
+ {#each notesList as note}
169
+ {#if note.fret !== 0}
170
+ <circle
171
+ cx={noteX(note.string)}
172
+ cy={noteY(note.fret)}
173
+ r={circleRadius}
174
+ />
175
+ {/if}
176
+ {#if note.finger !== 0}
177
+ <!-- RECOMMENDED FINGER -->
178
+ <text
179
+ x={noteX(note.string) - size / 50}
180
+ y={note.fret === 0
181
+ ? offset / 2 - strokeWidth * 2.4
182
+ : size - offset * 1.1}
183
+ color="currentColor"
184
+ fill="currentColor"
185
+ font-size={size / 13}
186
+ >
187
+ {note.finger}
188
+ </text>
189
+ {/if}
190
+ {/each}
191
+
192
+ <!-- CHORD NAME -->
193
+ <text
194
+ x={offset}
195
+ y={size - offset / 2.5}
196
+ font-size={boxSize / 6}
197
+ font-weight="600"
198
+ >
199
+ {name}
200
+ </text>
201
+
202
+ <!-- STARTING FRET -->
203
+ {#if firstFret > 1}
204
+ <text
205
+ x={size - offset / 1.8}
206
+ y={offset / 2 + boxSize / 7}
207
+ font-size={size / 13}
208
+ >
209
+ {firstFret}f
210
+ </text>
211
+ {/if}
212
+ </svg>
213
+ {/if}
@@ -1,45 +1,45 @@
1
- <!--
2
- @component
3
-
4
- ### FullscreenButton
5
-
6
- Make the document or a `target` element fullscreen.
7
-
8
- @props
9
-
10
- - `class`
11
- - `confirmMessage` - message to display in the `confirm` popup, defaults to empty string `""` -- disabled
12
- - `id`
13
- - `target` - element to make fullscreen (defaults to `document.documentElement` upon mount)
14
- - `title`
15
-
16
- @slots
17
-
18
- | name | purpose | default value |
19
- | ---------- | ---------------------------------------------- | -------------------- |
20
- | `default` | content to display when fullscreen is disabled | `Enabled Fullscreen` |
21
- | `enabled` | content to display when fullscreen is enabled | `Exit Fullscreen` |
22
-
23
- @example
24
-
25
- ```svelte
26
- <script lang="ts">
27
- import { FullscreenButton } from "drab";
28
-
29
- let target: HTMLDivElement;
30
- </script>
31
-
32
- <FullscreenButton class="btn" />
33
-
34
- <div bind:this={target} class="mt-8 rounded bg-neutral-800 p-4 text-neutral-50">
35
- <div class="mb-2">Target element</div>
36
- <FullscreenButton {target} class="btn btn-s bg-neutral-50">
37
- Enable Element Fullscreen
38
- </FullscreenButton>
39
- </div>
40
- ```
41
- -->
42
-
1
+ <!--
2
+ @component
3
+
4
+ ### FullscreenButton
5
+
6
+ Make the document or a `target` element fullscreen.
7
+
8
+ @props
9
+
10
+ - `class`
11
+ - `confirmMessage` - message to display in the `confirm` popup, defaults to empty string `""` -- disabled
12
+ - `id`
13
+ - `target` - element to make fullscreen (defaults to `document.documentElement` upon mount)
14
+ - `title`
15
+
16
+ @slots
17
+
18
+ | name | purpose | default value |
19
+ | ---------- | ---------------------------------------------- | -------------------- |
20
+ | `default` | content to display when fullscreen is disabled | `Enabled Fullscreen` |
21
+ | `enabled` | content to display when fullscreen is enabled | `Exit Fullscreen` |
22
+
23
+ @example
24
+
25
+ ```svelte
26
+ <script lang="ts">
27
+ import { FullscreenButton } from "drab";
28
+
29
+ let target: HTMLDivElement;
30
+ </script>
31
+
32
+ <FullscreenButton class="btn" />
33
+
34
+ <div bind:this={target} class="mt-8 rounded bg-neutral-800 p-4 text-neutral-50">
35
+ <div class="mb-2">Target element</div>
36
+ <FullscreenButton {target} class="btn btn-s bg-neutral-50">
37
+ Enable Element Fullscreen
38
+ </FullscreenButton>
39
+ </div>
40
+ ```
41
+ -->
42
+
43
43
  <script>import { onMount } from "svelte";
44
44
  let className = "";
45
45
  export { className as class };
@@ -75,21 +75,21 @@ onMount(() => {
75
75
  if (!target)
76
76
  target = document.documentElement;
77
77
  });
78
- </script>
79
-
80
- <svelte:window on:fullscreenchange={syncFullscreen} />
81
-
82
- <button
83
- type="button"
84
- {disabled}
85
- on:click={onClick}
86
- class={className}
87
- {id}
88
- {title}
89
- >
90
- {#if fullscreen}
91
- <slot name="enabled">Exit Fullscreen</slot>
92
- {:else}
93
- <slot>Enable Fullscreen</slot>
94
- {/if}
95
- </button>
78
+ </script>
79
+
80
+ <svelte:window on:fullscreenchange={syncFullscreen} />
81
+
82
+ <button
83
+ type="button"
84
+ {disabled}
85
+ on:click={onClick}
86
+ class={className}
87
+ {id}
88
+ {title}
89
+ >
90
+ {#if fullscreen}
91
+ <slot name="enabled">Exit Fullscreen</slot>
92
+ {:else}
93
+ <slot>Enable Fullscreen</slot>
94
+ {/if}
95
+ </button>