@placeholderco/placeholder-ui 3.1.0 → 3.1.2
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/editors/tiptap/TipTap.svelte +24 -3
- package/dist/editors/tiptap/TipTap.svelte.d.ts +7 -2
- package/dist/editors/tiptap/TipTapBubble.svelte +24 -3
- package/dist/editors/tiptap/TipTapBubble.svelte.d.ts +7 -2
- package/dist/ui/DialogEvents.svelte.d.ts +1 -7
- package/dist/ui/DialogEvents.svelte.js +3 -3
- package/dist/ui/Tabs.svelte +57 -15
- package/dist/ui/Tabs.svelte.d.ts +4 -1
- package/package.json +20 -20
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount, onDestroy } from 'svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { useDialogEvents } from '../../ui/DialogEvents.svelte.js';
|
|
4
|
+
import { Editor, Extension, type AnyExtension, type FocusPosition } from '@tiptap/core';
|
|
4
5
|
import { StarterKit } from '@tiptap/starter-kit';
|
|
5
6
|
import { BubbleMenu } from '@tiptap/extension-bubble-menu';
|
|
6
7
|
import Underline from '@tiptap/extension-underline';
|
|
@@ -77,6 +78,11 @@
|
|
|
77
78
|
editable?: boolean;
|
|
78
79
|
/** Placeholder text when editor is empty */
|
|
79
80
|
placeholder?: string;
|
|
81
|
+
/** Auto-focus the editor on mount. `true` places the cursor at the start; pass
|
|
82
|
+
* 'end', 'all' or a document position to choose where. Ignored when not editable. */
|
|
83
|
+
autofocus?: FocusPosition;
|
|
84
|
+
/** Auto-focus the editor every time the parent Dialog opens */
|
|
85
|
+
autofocusDialog?: boolean;
|
|
80
86
|
/** Additional CSS classes */
|
|
81
87
|
class?: string;
|
|
82
88
|
/** Async handler for image uploads, returns URL or null */
|
|
@@ -105,6 +111,8 @@
|
|
|
105
111
|
tooltipLocation = 'top',
|
|
106
112
|
editable = true,
|
|
107
113
|
placeholder = 'Start typing...',
|
|
114
|
+
autofocus = false,
|
|
115
|
+
autofocusDialog = false,
|
|
108
116
|
class: className = '',
|
|
109
117
|
onImageUpload,
|
|
110
118
|
onDocumentUpload,
|
|
@@ -350,6 +358,7 @@
|
|
|
350
358
|
extensions,
|
|
351
359
|
content: collaboration ? undefined : value,
|
|
352
360
|
editable: editable,
|
|
361
|
+
autofocus: editable ? autofocus : false,
|
|
353
362
|
editorProps: {
|
|
354
363
|
transformPastedHTML: stripPastedColors
|
|
355
364
|
},
|
|
@@ -373,6 +382,18 @@
|
|
|
373
382
|
}
|
|
374
383
|
});
|
|
375
384
|
|
|
385
|
+
// Content inside a Dialog mounts while it is closed, so the mount-time autofocus
|
|
386
|
+
// can't take; focus again once the dialog is showing
|
|
387
|
+
useDialogEvents({
|
|
388
|
+
onFirstOpen: () => {
|
|
389
|
+
if (!editable) return;
|
|
390
|
+
if (autofocus !== false && autofocus !== null && !autofocusDialog) focus(autofocus);
|
|
391
|
+
},
|
|
392
|
+
onOpen: () => {
|
|
393
|
+
if (editable && autofocusDialog) focus(autofocus || true);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
376
397
|
onDestroy(() => {
|
|
377
398
|
element?.removeEventListener('click', handleEditorClick, true);
|
|
378
399
|
element?.removeEventListener('paste', handlePaste as unknown as EventListener);
|
|
@@ -404,10 +425,10 @@
|
|
|
404
425
|
editor.commands.clearContent();
|
|
405
426
|
}
|
|
406
427
|
|
|
407
|
-
export function focus() {
|
|
428
|
+
export function focus(position?: FocusPosition) {
|
|
408
429
|
const editor = editorState.editor;
|
|
409
430
|
if (!editor || editor.isDestroyed) return;
|
|
410
|
-
editor.commands.focus();
|
|
431
|
+
editor.commands.focus(position);
|
|
411
432
|
}
|
|
412
433
|
</script>
|
|
413
434
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyExtension } from '@tiptap/core';
|
|
1
|
+
import { type AnyExtension, type FocusPosition } from '@tiptap/core';
|
|
2
2
|
import { type CodeBlocksOptions } from './extensions/index.js';
|
|
3
3
|
import type { CollaborationConfig } from './collaboration.js';
|
|
4
4
|
/** Result returned from a document upload: the link text and its destination URL */
|
|
@@ -25,6 +25,11 @@ export interface TipTapProps {
|
|
|
25
25
|
editable?: boolean;
|
|
26
26
|
/** Placeholder text when editor is empty */
|
|
27
27
|
placeholder?: string;
|
|
28
|
+
/** Auto-focus the editor on mount. `true` places the cursor at the start; pass
|
|
29
|
+
* 'end', 'all' or a document position to choose where. Ignored when not editable. */
|
|
30
|
+
autofocus?: FocusPosition;
|
|
31
|
+
/** Auto-focus the editor every time the parent Dialog opens */
|
|
32
|
+
autofocusDialog?: boolean;
|
|
28
33
|
/** Additional CSS classes */
|
|
29
34
|
class?: string;
|
|
30
35
|
/** Async handler for image uploads, returns URL or null */
|
|
@@ -48,7 +53,7 @@ declare const TipTap: import("svelte").Component<TipTapProps, {
|
|
|
48
53
|
getJSON: () => object;
|
|
49
54
|
setContent: (html: string) => void;
|
|
50
55
|
clear: () => void;
|
|
51
|
-
focus: () => void;
|
|
56
|
+
focus: (position?: FocusPosition) => void;
|
|
52
57
|
}, "value">;
|
|
53
58
|
type TipTap = ReturnType<typeof TipTap>;
|
|
54
59
|
export default TipTap;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import { onMount, onDestroy } from 'svelte';
|
|
3
|
-
import {
|
|
3
|
+
import { useDialogEvents } from '../../ui/DialogEvents.svelte.js';
|
|
4
|
+
import { Editor, Extension, type AnyExtension, type FocusPosition } from '@tiptap/core';
|
|
4
5
|
import { StarterKit } from '@tiptap/starter-kit';
|
|
5
6
|
import { BubbleMenu } from '@tiptap/extension-bubble-menu';
|
|
6
7
|
import Underline from '@tiptap/extension-underline';
|
|
@@ -56,6 +57,11 @@
|
|
|
56
57
|
editable?: boolean;
|
|
57
58
|
/** Placeholder text when editor is empty */
|
|
58
59
|
placeholder?: string;
|
|
60
|
+
/** Auto-focus the editor on mount. `true` places the cursor at the start; pass
|
|
61
|
+
* 'end', 'all' or a document position to choose where. Ignored when not editable. */
|
|
62
|
+
autofocus?: FocusPosition;
|
|
63
|
+
/** Auto-focus the editor every time the parent Dialog opens */
|
|
64
|
+
autofocusDialog?: boolean;
|
|
59
65
|
/** Additional CSS classes */
|
|
60
66
|
class?: string;
|
|
61
67
|
/** Async handler for image uploads, returns URL or null */
|
|
@@ -81,6 +87,8 @@
|
|
|
81
87
|
tooltipLocation = 'top',
|
|
82
88
|
editable = true,
|
|
83
89
|
placeholder = 'Start typing...',
|
|
90
|
+
autofocus = false,
|
|
91
|
+
autofocusDialog = false,
|
|
84
92
|
class: className = '',
|
|
85
93
|
onImageUpload,
|
|
86
94
|
onUpdate,
|
|
@@ -327,6 +335,7 @@
|
|
|
327
335
|
extensions,
|
|
328
336
|
content: collaboration ? undefined : value,
|
|
329
337
|
editable: editable,
|
|
338
|
+
autofocus: editable ? autofocus : false,
|
|
330
339
|
editorProps: {
|
|
331
340
|
transformPastedHTML: stripPastedColors
|
|
332
341
|
},
|
|
@@ -348,6 +357,18 @@
|
|
|
348
357
|
}
|
|
349
358
|
});
|
|
350
359
|
|
|
360
|
+
// Content inside a Dialog mounts while it is closed, so the mount-time autofocus
|
|
361
|
+
// can't take; focus again once the dialog is showing
|
|
362
|
+
useDialogEvents({
|
|
363
|
+
onFirstOpen: () => {
|
|
364
|
+
if (!editable) return;
|
|
365
|
+
if (autofocus !== false && autofocus !== null && !autofocusDialog) focus(autofocus);
|
|
366
|
+
},
|
|
367
|
+
onOpen: () => {
|
|
368
|
+
if (editable && autofocusDialog) focus(autofocus || true);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
|
|
351
372
|
onDestroy(() => {
|
|
352
373
|
element?.removeEventListener('click', handleEditorClick, true);
|
|
353
374
|
element?.removeEventListener('paste', handlePaste as unknown as EventListener);
|
|
@@ -379,10 +400,10 @@
|
|
|
379
400
|
editor.commands.clearContent();
|
|
380
401
|
}
|
|
381
402
|
|
|
382
|
-
export function focus() {
|
|
403
|
+
export function focus(position?: FocusPosition) {
|
|
383
404
|
const editor = editorState.editor;
|
|
384
405
|
if (!editor || editor.isDestroyed) return;
|
|
385
|
-
editor.commands.focus();
|
|
406
|
+
editor.commands.focus(position);
|
|
386
407
|
}
|
|
387
408
|
</script>
|
|
388
409
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type AnyExtension } from '@tiptap/core';
|
|
1
|
+
import { type AnyExtension, type FocusPosition } from '@tiptap/core';
|
|
2
2
|
import { type CodeBlocksOptions } from './extensions/index.js';
|
|
3
3
|
import type { CollaborationConfig } from './collaboration.js';
|
|
4
4
|
export interface TipTapBubbleProps {
|
|
@@ -18,6 +18,11 @@ export interface TipTapBubbleProps {
|
|
|
18
18
|
editable?: boolean;
|
|
19
19
|
/** Placeholder text when editor is empty */
|
|
20
20
|
placeholder?: string;
|
|
21
|
+
/** Auto-focus the editor on mount. `true` places the cursor at the start; pass
|
|
22
|
+
* 'end', 'all' or a document position to choose where. Ignored when not editable. */
|
|
23
|
+
autofocus?: FocusPosition;
|
|
24
|
+
/** Auto-focus the editor every time the parent Dialog opens */
|
|
25
|
+
autofocusDialog?: boolean;
|
|
21
26
|
/** Additional CSS classes */
|
|
22
27
|
class?: string;
|
|
23
28
|
/** Async handler for image uploads, returns URL or null */
|
|
@@ -38,7 +43,7 @@ declare const TipTapBubble: import("svelte").Component<TipTapBubbleProps, {
|
|
|
38
43
|
getJSON: () => object;
|
|
39
44
|
setContent: (html: string) => void;
|
|
40
45
|
clear: () => void;
|
|
41
|
-
focus: () => void;
|
|
46
|
+
focus: (position?: FocusPosition) => void;
|
|
42
47
|
}, "value">;
|
|
43
48
|
type TipTapBubble = ReturnType<typeof TipTapBubble>;
|
|
44
49
|
export default TipTapBubble;
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
export interface DialogContext {
|
|
2
|
-
isOpen: boolean;
|
|
3
|
-
onOpen: () => void;
|
|
4
|
-
onClose: () => void;
|
|
5
|
-
onFirstOpen: () => void;
|
|
6
|
-
}
|
|
7
1
|
export declare function useDialog(): DialogContext;
|
|
8
2
|
export declare function useDialogEvents(callbacks: {
|
|
9
3
|
onOpen?: () => void;
|
|
10
4
|
onClose?: () => void;
|
|
11
5
|
onFirstOpen?: () => void;
|
|
12
|
-
}):
|
|
6
|
+
}): any;
|
|
@@ -10,13 +10,13 @@ export function useDialogEvents(callbacks) {
|
|
|
10
10
|
return null;
|
|
11
11
|
}
|
|
12
12
|
if (callbacks.onOpen) {
|
|
13
|
-
context.onOpen
|
|
13
|
+
context.onOpen(callbacks.onOpen);
|
|
14
14
|
}
|
|
15
15
|
if (callbacks.onClose) {
|
|
16
|
-
context.onClose
|
|
16
|
+
context.onClose(callbacks.onClose);
|
|
17
17
|
}
|
|
18
18
|
if (callbacks.onFirstOpen) {
|
|
19
|
-
context.onFirstOpen
|
|
19
|
+
context.onFirstOpen(callbacks.onFirstOpen);
|
|
20
20
|
}
|
|
21
21
|
return context;
|
|
22
22
|
}
|
package/dist/ui/Tabs.svelte
CHANGED
|
@@ -3,7 +3,10 @@
|
|
|
3
3
|
import { onMount } from 'svelte';
|
|
4
4
|
|
|
5
5
|
export interface TabsProps {
|
|
6
|
-
/**
|
|
6
|
+
/**
|
|
7
|
+
* Available tab options. `class` is added to the tab button (style it with `:global()`),
|
|
8
|
+
* and a divider is drawn between neighbouring tabs whose `groupName` differs
|
|
9
|
+
*/
|
|
7
10
|
tabOptions: ComboBoxItem[];
|
|
8
11
|
/** Currently active tab value (bindable) */
|
|
9
12
|
activeTab?: string;
|
|
@@ -15,6 +18,7 @@
|
|
|
15
18
|
|
|
16
19
|
let { tabOptions, activeTab = $bindable(''), solidBg = false, onchange }: TabsProps = $props();
|
|
17
20
|
let containerRef: HTMLDivElement;
|
|
21
|
+
let scrollRef: HTMLDivElement;
|
|
18
22
|
let buttonElements = $state<HTMLButtonElement[]>([]);
|
|
19
23
|
let underlineStyle = $state('');
|
|
20
24
|
|
|
@@ -45,6 +49,7 @@
|
|
|
45
49
|
$effect(() => {
|
|
46
50
|
if (selectedIndex >= 0 && buttonElements[selectedIndex] && containerRef) {
|
|
47
51
|
recalculateUnderline();
|
|
52
|
+
scrollSelectedIntoView();
|
|
48
53
|
}
|
|
49
54
|
});
|
|
50
55
|
|
|
@@ -59,29 +64,56 @@
|
|
|
59
64
|
underlineStyle = `left: ${offsetLeft}px; width: ${width}px;`;
|
|
60
65
|
}
|
|
61
66
|
|
|
67
|
+
// Scroll the bar (not the page) so the selected tab is fully visible
|
|
68
|
+
function scrollSelectedIntoView() {
|
|
69
|
+
const selectedButton = buttonElements[selectedIndex];
|
|
70
|
+
const scrollRect = scrollRef.getBoundingClientRect();
|
|
71
|
+
const buttonRect = selectedButton.getBoundingClientRect();
|
|
72
|
+
|
|
73
|
+
if (buttonRect.left < scrollRect.left) {
|
|
74
|
+
scrollRef.scrollLeft -= scrollRect.left - buttonRect.left;
|
|
75
|
+
} else if (buttonRect.right > scrollRect.right) {
|
|
76
|
+
scrollRef.scrollLeft += buttonRect.right - scrollRect.right;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
62
80
|
function setValue(newValue: any) {
|
|
63
81
|
activeTab = newValue;
|
|
64
82
|
onchange?.(newValue);
|
|
65
83
|
}
|
|
66
84
|
</script>
|
|
67
85
|
|
|
68
|
-
<div class="tabs" bind:this={
|
|
69
|
-
|
|
70
|
-
{
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
86
|
+
<div class="tabs-scroll" bind:this={scrollRef}>
|
|
87
|
+
<div class="tabs" bind:this={containerRef}>
|
|
88
|
+
{#each tabOptions as option, index}
|
|
89
|
+
{@const isSelected = option.value === activeTab}
|
|
90
|
+
|
|
91
|
+
{#if index > 0 && (option.groupName ?? '') !== (tabOptions[index - 1].groupName ?? '')}
|
|
92
|
+
<span class="tab-divider" aria-hidden="true"></span>
|
|
93
|
+
{/if}
|
|
94
|
+
<button
|
|
95
|
+
type="button"
|
|
96
|
+
bind:this={buttonElements[index]}
|
|
97
|
+
class="tab-item {isSelected ? 'selected' : ''} {solidBg ? 'solid' : ''} {option.class ??
|
|
98
|
+
''}"
|
|
99
|
+
onclick={() => setValue(option.value)}
|
|
100
|
+
>
|
|
101
|
+
{option.label}
|
|
102
|
+
</button>
|
|
103
|
+
{/each}
|
|
104
|
+
<div class="tab-underline" style={underlineStyle}></div>
|
|
105
|
+
</div>
|
|
82
106
|
</div>
|
|
83
107
|
|
|
84
108
|
<style>
|
|
109
|
+
.tabs-scroll {
|
|
110
|
+
display: inline-block;
|
|
111
|
+
max-width: 100%;
|
|
112
|
+
vertical-align: bottom;
|
|
113
|
+
overflow-x: auto;
|
|
114
|
+
overflow-y: hidden;
|
|
115
|
+
}
|
|
116
|
+
|
|
85
117
|
.tabs {
|
|
86
118
|
position: relative;
|
|
87
119
|
display: inline-flex;
|
|
@@ -105,6 +137,16 @@
|
|
|
105
137
|
transition: color 0.2s ease-in-out;
|
|
106
138
|
z-index: 1;
|
|
107
139
|
border-bottom: 2px solid transparent;
|
|
140
|
+
flex-shrink: 0;
|
|
141
|
+
white-space: nowrap;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
.tab-divider {
|
|
145
|
+
flex-shrink: 0;
|
|
146
|
+
align-self: center;
|
|
147
|
+
width: 1px;
|
|
148
|
+
height: 1.25rem;
|
|
149
|
+
background-color: var(--border-color);
|
|
108
150
|
}
|
|
109
151
|
|
|
110
152
|
.tab-item:hover {
|
package/dist/ui/Tabs.svelte.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import type { ComboBoxItem } from '../models/ComboBoxItem.js';
|
|
2
2
|
export interface TabsProps {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Available tab options. `class` is added to the tab button (style it with `:global()`),
|
|
5
|
+
* and a divider is drawn between neighbouring tabs whose `groupName` differs
|
|
6
|
+
*/
|
|
4
7
|
tabOptions: ComboBoxItem[];
|
|
5
8
|
/** Currently active tab value (bindable) */
|
|
6
9
|
activeTab?: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@placeholderco/placeholder-ui",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.2",
|
|
4
4
|
"description": "A modern, customizable Svelte 5 UI component library with comprehensive theming support. Re-brand it with a single config object.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "Placeholderco",
|
|
@@ -56,7 +56,7 @@
|
|
|
56
56
|
"@sveltejs/kit": "^3.1.0",
|
|
57
57
|
"@sveltejs/package": "^3.0.1",
|
|
58
58
|
"@sveltejs/vite-plugin-svelte": "^7.3.1",
|
|
59
|
-
"@types/node": "^26.6.
|
|
59
|
+
"@types/node": "^26.6.6",
|
|
60
60
|
"globals": "^17.13.0",
|
|
61
61
|
"prettier": "^3.9.10",
|
|
62
62
|
"prettier-plugin-svelte": "^4.1.1",
|
|
@@ -84,25 +84,25 @@
|
|
|
84
84
|
"@codemirror/theme-one-dark": "^6.1.3",
|
|
85
85
|
"@codemirror/view": "^6.43.15",
|
|
86
86
|
"@lezer/highlight": "^1.2.5",
|
|
87
|
-
"@tiptap/core": "^3.32.
|
|
88
|
-
"@tiptap/extension-bubble-menu": "^3.32.
|
|
89
|
-
"@tiptap/extension-code-block": "^3.32.
|
|
90
|
-
"@tiptap/extension-collaboration": "^3.32.
|
|
91
|
-
"@tiptap/extension-collaboration-caret": "^3.32.
|
|
92
|
-
"@tiptap/extension-color": "^3.32.
|
|
93
|
-
"@tiptap/extension-image": "^3.32.
|
|
94
|
-
"@tiptap/extension-link": "^3.32.
|
|
95
|
-
"@tiptap/extension-placeholder": "^3.32.
|
|
96
|
-
"@tiptap/extension-subscript": "^3.32.
|
|
97
|
-
"@tiptap/extension-superscript": "^3.32.
|
|
98
|
-
"@tiptap/extension-table": "^3.32.
|
|
99
|
-
"@tiptap/extension-text-align": "^3.32.
|
|
100
|
-
"@tiptap/extension-text-style": "^3.32.
|
|
101
|
-
"@tiptap/extension-underline": "^3.32.
|
|
102
|
-
"@tiptap/pm": "^3.32.
|
|
103
|
-
"@tiptap/starter-kit": "^3.32.
|
|
87
|
+
"@tiptap/core": "^3.32.1",
|
|
88
|
+
"@tiptap/extension-bubble-menu": "^3.32.1",
|
|
89
|
+
"@tiptap/extension-code-block": "^3.32.1",
|
|
90
|
+
"@tiptap/extension-collaboration": "^3.32.1",
|
|
91
|
+
"@tiptap/extension-collaboration-caret": "^3.32.1",
|
|
92
|
+
"@tiptap/extension-color": "^3.32.1",
|
|
93
|
+
"@tiptap/extension-image": "^3.32.1",
|
|
94
|
+
"@tiptap/extension-link": "^3.32.1",
|
|
95
|
+
"@tiptap/extension-placeholder": "^3.32.1",
|
|
96
|
+
"@tiptap/extension-subscript": "^3.32.1",
|
|
97
|
+
"@tiptap/extension-superscript": "^3.32.1",
|
|
98
|
+
"@tiptap/extension-table": "^3.32.1",
|
|
99
|
+
"@tiptap/extension-text-align": "^3.32.1",
|
|
100
|
+
"@tiptap/extension-text-style": "^3.32.1",
|
|
101
|
+
"@tiptap/extension-underline": "^3.32.1",
|
|
102
|
+
"@tiptap/pm": "^3.32.1",
|
|
103
|
+
"@tiptap/starter-kit": "^3.32.1",
|
|
104
104
|
"dayjs": "^1.11.23",
|
|
105
|
-
"svelte-sonner": "^1.2.
|
|
105
|
+
"svelte-sonner": "^1.2.2",
|
|
106
106
|
"yjs": "^13.6.33"
|
|
107
107
|
},
|
|
108
108
|
"publishConfig": {
|