@placeholderco/placeholder-ui 3.1.0 → 3.1.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,6 +1,7 @@
1
1
  <script lang="ts">
2
2
  import { onMount, onDestroy } from 'svelte';
3
- import { Editor, Extension, type AnyExtension } from '@tiptap/core';
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 { Editor, Extension, type AnyExtension } from '@tiptap/core';
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;
@@ -17,6 +17,8 @@ export interface ComboBoxItem {
17
17
  groupName?: string;
18
18
  imageSrc?: string;
19
19
  description?: string;
20
+ /** Tooltip text shown on hover/focus (used by Tabs) */
21
+ tooltip?: string;
20
22
  /** Shows the option but prevents it from being selected */
21
23
  disabled?: boolean;
22
24
  /** Marks a synthetic "add new value" suggestion (see Autocomplete) */
@@ -318,6 +318,30 @@
318
318
  --badge-hover-text-color: var(--ui-primary-contrast-color);
319
319
  --badge-outline-color: var(--ui-focus-color);
320
320
  }
321
+
322
+ .primary-outline {
323
+ --badge-text-color: var(--text-color);
324
+ --badge-border: 1px solid var(--text-color);
325
+ --badge-border-color: var(--text-color);
326
+ }
327
+
328
+ .accent-outline {
329
+ --badge-text-color: var(--ui-accent);
330
+ --badge-border: 1px solid var(--ui-accent);
331
+ --badge-border-color: var(--ui-accent);
332
+ }
333
+
334
+ .tertiary-subtle {
335
+ --badge-text-color: var(--ui-tertiary);
336
+ --badge-border-color: var(--ui-tertiary);
337
+ --badge-bg-color: color-mix(in srgb, var(--ui-tertiary) 20%, transparent);
338
+ }
339
+
340
+ .tertiary-outline {
341
+ --badge-text-color: var(--ui-tertiary);
342
+ --badge-border: 1px solid var(--ui-tertiary);
343
+ --badge-border-color: var(--ui-tertiary);
344
+ }
321
345
  }
322
346
 
323
347
  .disabled {
@@ -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
- }): DialogContext | null;
6
+ }): any;
@@ -10,13 +10,13 @@ export function useDialogEvents(callbacks) {
10
10
  return null;
11
11
  }
12
12
  if (callbacks.onOpen) {
13
- context.onOpen = callbacks.onOpen;
13
+ context.onOpen(callbacks.onOpen);
14
14
  }
15
15
  if (callbacks.onClose) {
16
- context.onClose = callbacks.onClose;
16
+ context.onClose(callbacks.onClose);
17
17
  }
18
18
  if (callbacks.onFirstOpen) {
19
- context.onFirstOpen = callbacks.onFirstOpen;
19
+ context.onFirstOpen(callbacks.onFirstOpen);
20
20
  }
21
21
  return context;
22
22
  }
@@ -1,20 +1,34 @@
1
1
  <script lang="ts">
2
2
  import type { ComboBoxItem } from '../models/ComboBoxItem.js';
3
+ import Tooltip, { type TooltipLocation } from './Tooltip.svelte';
3
4
  import { onMount } from 'svelte';
4
5
 
5
6
  export interface TabsProps {
6
- /** Available tab options */
7
+ /**
8
+ * Available tab options. `class` is added to the tab button (style it with `:global()`),
9
+ * a divider is drawn between neighbouring tabs whose `groupName` differs, and `tooltip`
10
+ * is shown on hover/focus
11
+ */
7
12
  tabOptions: ComboBoxItem[];
8
13
  /** Currently active tab value (bindable) */
9
14
  activeTab?: string;
10
15
  /** Use solid background instead of transparent */
11
16
  solidBg?: boolean;
17
+ /** Preferred position of tab tooltips */
18
+ tooltipLocation?: TooltipLocation;
12
19
  /** Callback when active tab changes */
13
20
  onchange?: (newValue: string) => void;
14
21
  }
15
22
 
16
- let { tabOptions, activeTab = $bindable(''), solidBg = false, onchange }: TabsProps = $props();
23
+ let {
24
+ tabOptions,
25
+ activeTab = $bindable(''),
26
+ solidBg = false,
27
+ tooltipLocation = 'top',
28
+ onchange
29
+ }: TabsProps = $props();
17
30
  let containerRef: HTMLDivElement;
31
+ let scrollRef: HTMLDivElement;
18
32
  let buttonElements = $state<HTMLButtonElement[]>([]);
19
33
  let underlineStyle = $state('');
20
34
 
@@ -45,6 +59,7 @@
45
59
  $effect(() => {
46
60
  if (selectedIndex >= 0 && buttonElements[selectedIndex] && containerRef) {
47
61
  recalculateUnderline();
62
+ scrollSelectedIntoView();
48
63
  }
49
64
  });
50
65
 
@@ -59,29 +74,66 @@
59
74
  underlineStyle = `left: ${offsetLeft}px; width: ${width}px;`;
60
75
  }
61
76
 
77
+ // Scroll the bar (not the page) so the selected tab is fully visible
78
+ function scrollSelectedIntoView() {
79
+ const selectedButton = buttonElements[selectedIndex];
80
+ const scrollRect = scrollRef.getBoundingClientRect();
81
+ const buttonRect = selectedButton.getBoundingClientRect();
82
+
83
+ if (buttonRect.left < scrollRect.left) {
84
+ scrollRef.scrollLeft -= scrollRect.left - buttonRect.left;
85
+ } else if (buttonRect.right > scrollRect.right) {
86
+ scrollRef.scrollLeft += buttonRect.right - scrollRect.right;
87
+ }
88
+ }
89
+
62
90
  function setValue(newValue: any) {
63
91
  activeTab = newValue;
64
92
  onchange?.(newValue);
65
93
  }
66
94
  </script>
67
95
 
68
- <div class="tabs" bind:this={containerRef}>
69
- {#each tabOptions as option, index}
70
- {@const isSelected = option.value === activeTab}
71
-
72
- <button
73
- type="button"
74
- bind:this={buttonElements[index]}
75
- class="tab-item {isSelected ? 'selected' : ''} {solidBg ? 'solid' : ''}"
76
- onclick={() => setValue(option.value)}
77
- >
78
- {option.label}
79
- </button>
80
- {/each}
81
- <div class="tab-underline" style={underlineStyle}></div>
96
+ <div class="tabs-scroll" bind:this={scrollRef}>
97
+ <div class="tabs" bind:this={containerRef}>
98
+ {#each tabOptions as option, index}
99
+ {@const isSelected = option.value === activeTab}
100
+
101
+ {#if index > 0 && (option.groupName ?? '') !== (tabOptions[index - 1].groupName ?? '')}
102
+ <span class="tab-divider" aria-hidden="true"></span>
103
+ {/if}
104
+ {#snippet tabButton()}
105
+ <button
106
+ type="button"
107
+ bind:this={buttonElements[index]}
108
+ class="tab-item {isSelected ? 'selected' : ''} {solidBg ? 'solid' : ''} {option.class ??
109
+ ''}"
110
+ onclick={() => setValue(option.value)}
111
+ >
112
+ {option.label}
113
+ </button>
114
+ {/snippet}
115
+
116
+ {#if option.tooltip}
117
+ <Tooltip text={option.tooltip} location={tooltipLocation}>
118
+ {@render tabButton()}
119
+ </Tooltip>
120
+ {:else}
121
+ {@render tabButton()}
122
+ {/if}
123
+ {/each}
124
+ <div class="tab-underline" style={underlineStyle}></div>
125
+ </div>
82
126
  </div>
83
127
 
84
128
  <style>
129
+ .tabs-scroll {
130
+ display: inline-block;
131
+ max-width: 100%;
132
+ vertical-align: bottom;
133
+ overflow-x: auto;
134
+ overflow-y: hidden;
135
+ }
136
+
85
137
  .tabs {
86
138
  position: relative;
87
139
  display: inline-flex;
@@ -89,6 +141,13 @@
89
141
  user-select: none;
90
142
  }
91
143
 
144
+ /* Tooltip wrappers are inline-block; flex keeps the button flush with the bar */
145
+ .tabs > :global(.tooltip-v2-container),
146
+ .tabs > :global(.tooltip-v2-container > .tooltip-v2-trigger) {
147
+ display: flex;
148
+ flex-shrink: 0;
149
+ }
150
+
92
151
  .tab-item {
93
152
  position: relative;
94
153
  display: flex;
@@ -105,6 +164,16 @@
105
164
  transition: color 0.2s ease-in-out;
106
165
  z-index: 1;
107
166
  border-bottom: 2px solid transparent;
167
+ flex-shrink: 0;
168
+ white-space: nowrap;
169
+ }
170
+
171
+ .tab-divider {
172
+ flex-shrink: 0;
173
+ align-self: center;
174
+ width: 1px;
175
+ height: 1.25rem;
176
+ background-color: var(--border-color);
108
177
  }
109
178
 
110
179
  .tab-item:hover {
@@ -1,11 +1,18 @@
1
1
  import type { ComboBoxItem } from '../models/ComboBoxItem.js';
2
+ import { type TooltipLocation } from './Tooltip.svelte';
2
3
  export interface TabsProps {
3
- /** Available tab options */
4
+ /**
5
+ * Available tab options. `class` is added to the tab button (style it with `:global()`),
6
+ * a divider is drawn between neighbouring tabs whose `groupName` differs, and `tooltip`
7
+ * is shown on hover/focus
8
+ */
4
9
  tabOptions: ComboBoxItem[];
5
10
  /** Currently active tab value (bindable) */
6
11
  activeTab?: string;
7
12
  /** Use solid background instead of transparent */
8
13
  solidBg?: boolean;
14
+ /** Preferred position of tab tooltips */
15
+ tooltipLocation?: TooltipLocation;
9
16
  /** Callback when active tab changes */
10
17
  onchange?: (newValue: string) => void;
11
18
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@placeholderco/placeholder-ui",
3
- "version": "3.1.0",
3
+ "version": "3.1.3",
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.5",
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.0",
88
- "@tiptap/extension-bubble-menu": "^3.32.0",
89
- "@tiptap/extension-code-block": "^3.32.0",
90
- "@tiptap/extension-collaboration": "^3.32.0",
91
- "@tiptap/extension-collaboration-caret": "^3.32.0",
92
- "@tiptap/extension-color": "^3.32.0",
93
- "@tiptap/extension-image": "^3.32.0",
94
- "@tiptap/extension-link": "^3.32.0",
95
- "@tiptap/extension-placeholder": "^3.32.0",
96
- "@tiptap/extension-subscript": "^3.32.0",
97
- "@tiptap/extension-superscript": "^3.32.0",
98
- "@tiptap/extension-table": "^3.32.0",
99
- "@tiptap/extension-text-align": "^3.32.0",
100
- "@tiptap/extension-text-style": "^3.32.0",
101
- "@tiptap/extension-underline": "^3.32.0",
102
- "@tiptap/pm": "^3.32.0",
103
- "@tiptap/starter-kit": "^3.32.0",
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.1",
105
+ "svelte-sonner": "^1.2.2",
106
106
  "yjs": "^13.6.33"
107
107
  },
108
108
  "publishConfig": {