@widgetic/design-system 0.5.27 → 0.5.29

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 (64) hide show
  1. package/dist/components/CopyableHeader.svelte +29 -10
  2. package/dist/components/CopyableHeader.svelte.d.ts +3 -0
  3. package/dist/components/EmptyState.svelte +13 -3
  4. package/dist/components/chat/ChatHeader.svelte +29 -3
  5. package/dist/components/chat/ChatHeader.svelte.d.ts +5 -0
  6. package/dist/components/chat/Composer.svelte +58 -1
  7. package/dist/components/chat/Composer.svelte.d.ts +8 -0
  8. package/dist/components/chat/MessageCheckpointRow.svelte +87 -0
  9. package/dist/components/chat/MessageCheckpointRow.svelte.d.ts +21 -0
  10. package/dist/components/chat/MessageRatingActions.svelte +157 -0
  11. package/dist/components/chat/MessageRatingActions.svelte.d.ts +26 -0
  12. package/dist/components/chat/chatHeaderLogic.d.ts +8 -0
  13. package/dist/components/chat/chatHeaderLogic.js +14 -0
  14. package/dist/components/chat/composerModelMenuLogic.d.ts +9 -0
  15. package/dist/components/chat/composerModelMenuLogic.js +12 -0
  16. package/dist/components/chat/index.d.ts +10 -0
  17. package/dist/components/chat/index.js +8 -0
  18. package/dist/components/chat/messageRatingActionsLogic.d.ts +11 -0
  19. package/dist/components/chat/messageRatingActionsLogic.js +17 -0
  20. package/dist/components/chat/messageRatingTypes.d.ts +2 -0
  21. package/dist/components/chat/messageRatingTypes.js +1 -0
  22. package/dist/components/modals/BaseModal.svelte +133 -11
  23. package/dist/components/modals/BaseModal.svelte.d.ts +1 -0
  24. package/dist/components/modals/NewItemDialog.svelte +2 -0
  25. package/dist/components/shad-editor/custom/Extentions/SearchAndReplace.js +0 -1
  26. package/dist/components/shad-editor/custom/utils.d.ts +1 -1
  27. package/dist/components/shad-editor/custom/utils.js +0 -1
  28. package/dist/components/shell/ErrorState.svelte +5 -2
  29. package/dist/components/shell/ErrorState.svelte.d.ts +2 -1
  30. package/dist/components/shell/NavRow.svelte +5 -4
  31. package/dist/components/shell/NavRow.svelte.d.ts +3 -3
  32. package/dist/components/shell/SettingsDialog.svelte +65 -4
  33. package/dist/components/shell/WidgetRow.svelte +6 -6
  34. package/dist/components/shell/WidgetRow.svelte.d.ts +2 -2
  35. package/dist/components/ui/accordion/accordion-content.svelte +5 -1
  36. package/dist/components/ui/accordion/accordion-item.svelte +2 -1
  37. package/dist/components/ui/accordion/accordion-trigger.svelte +38 -0
  38. package/dist/components/ui/button/button.svelte +1 -1
  39. package/dist/components/ui/button/button.svelte.d.ts +3 -3
  40. package/dist/components/ui/calendar/calendar.svelte.d.ts +1 -1
  41. package/dist/components/ui/checkbox/checkbox.svelte +1 -1
  42. package/dist/components/ui/dialog/dialog-overlay.svelte +8 -1
  43. package/dist/components/ui/icon-button/icon-button.svelte +1 -1
  44. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +2 -2
  45. package/dist/components/ui/input-otp/input-otp-slot.svelte.d.ts +1 -1
  46. package/dist/components/ui/radio-group/radio-group-item.svelte +1 -1
  47. package/dist/components/ui/range-calendar/range-calendar.svelte.d.ts +1 -1
  48. package/dist/components/ui/scroll-area/scroll-area-scrollbar.svelte +1 -1
  49. package/dist/components/ui/select/select-content.svelte +2 -2
  50. package/dist/components/ui/select/select-scroll-down-button.svelte +1 -1
  51. package/dist/components/ui/select/select-scroll-up-button.svelte +1 -1
  52. package/dist/components/ui/select/select-trigger.svelte +1 -1
  53. package/dist/components/ui/stepper-button/stepper-button.svelte +1 -1
  54. package/dist/components/ui/tooltip/tooltip-content.svelte +1 -1
  55. package/dist/components/widget-system/Moveable.svelte +24 -21
  56. package/dist/utils/isEditableEventTarget.d.ts +5 -0
  57. package/dist/utils/isEditableEventTarget.js +25 -0
  58. package/dist/utils/modalFocusTrap.d.ts +28 -0
  59. package/dist/utils/modalFocusTrap.js +135 -0
  60. package/dist/utils/overlayMotion.d.ts +6 -0
  61. package/dist/utils/overlayMotion.js +7 -0
  62. package/dist/utils/overlayStacking.d.ts +47 -0
  63. package/dist/utils/overlayStacking.js +63 -0
  64. package/package.json +1 -1
@@ -0,0 +1,25 @@
1
+ const EDITABLE_SELECTOR = 'input, textarea, select, option, [contenteditable]:not([contenteditable="false"]), [role="textbox"], [role="combobox"], [role="searchbox"]';
2
+ function elementIsEditable(element) {
3
+ if (!element || typeof element !== 'object')
4
+ return false;
5
+ const htmlElement = element;
6
+ if (htmlElement.isContentEditable)
7
+ return true;
8
+ const contentEditable = htmlElement.getAttribute?.('contenteditable');
9
+ if (contentEditable !== null && contentEditable !== undefined && contentEditable !== 'false')
10
+ return true;
11
+ return typeof htmlElement.matches === 'function' && htmlElement.matches(EDITABLE_SELECTOR);
12
+ }
13
+ /**
14
+ * True when a keyboard event originated from (or should be treated as) typing in an editable control,
15
+ * including fields inside shadow roots and portaled popovers (composedPath).
16
+ */
17
+ export function isEditableEventTarget(event) {
18
+ for (const node of event.composedPath()) {
19
+ if (elementIsEditable(node))
20
+ return true;
21
+ }
22
+ if (elementIsEditable(event.target))
23
+ return true;
24
+ return elementIsEditable(typeof document !== 'undefined' ? document.activeElement : null);
25
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Pure helpers for BaseModal focus trapping (tab order, visibility, portaled bits-ui layers).
3
+ */
4
+ /** A new id for the title of one modal, so two modals open at once never share the id their `aria-labelledby` points at. */
5
+ export declare function nextModalTitleId(): string;
6
+ export declare function isElementVisible(element: HTMLElement): boolean;
7
+ export declare function isFocusable(element: HTMLElement): boolean;
8
+ export declare function getTabbableElements(root: HTMLElement): HTMLElement[];
9
+ /**
10
+ * The element that really has focus, looking inside open shadow roots too (`document.activeElement` alone stops at the host of a
11
+ * shadow root, and the file browser lives in one when an app embeds it).
12
+ */
13
+ export declare function deepActiveElement(root?: Document | ShadowRoot): HTMLElement | null;
14
+ /**
15
+ * Where focus must wrap to when Tab (or Shift+Tab) would otherwise leave the modal. `null` means the browser's own Tab is fine:
16
+ * the trap steps in only at the two ends of the modal (and when focus is not in the modal at all), so the tab order everywhere
17
+ * else stays the browser's own (radio groups, shadow DOM, anything the list of tabbable elements does not know).
18
+ */
19
+ export declare function tabWrapTarget(options: {
20
+ elements: HTMLElement[];
21
+ active: Element | null;
22
+ shiftKey: boolean;
23
+ modalRoot: HTMLElement;
24
+ }): HTMLElement | null;
25
+ /**
26
+ * Focus may sit on a bits-ui layer portaled outside the dialog if a control inside the modal opened it.
27
+ */
28
+ export declare function isFocusAllowed(modalRoot: HTMLElement, target: HTMLElement): boolean;
@@ -0,0 +1,135 @@
1
+ /**
2
+ * Pure helpers for BaseModal focus trapping (tab order, visibility, portaled bits-ui layers).
3
+ */
4
+ const TABBABLE_SELECTOR = [
5
+ 'a[href]',
6
+ 'button:not([disabled])',
7
+ 'input:not([disabled])',
8
+ 'select:not([disabled])',
9
+ 'textarea:not([disabled])',
10
+ '[tabindex]:not([tabindex="-1"])',
11
+ 'audio[controls]',
12
+ 'video[controls]',
13
+ '[contenteditable]:not([contenteditable="false"])'
14
+ ].join(',');
15
+ const FLOATING_LAYER_ROLES = new Set(['menu', 'listbox', 'dialog', 'tooltip', 'grid']);
16
+ let modalTitleIdCounter = 0;
17
+ /** A new id for the title of one modal, so two modals open at once never share the id their `aria-labelledby` points at. */
18
+ export function nextModalTitleId() {
19
+ modalTitleIdCounter += 1;
20
+ return `base-modal-title-${modalTitleIdCounter}`;
21
+ }
22
+ export function isElementVisible(element) {
23
+ if (element.hidden)
24
+ return false;
25
+ const style = element.ownerDocument?.defaultView?.getComputedStyle(element);
26
+ if (!style)
27
+ return true;
28
+ if (style.visibility === 'hidden' || style.display === 'none')
29
+ return false;
30
+ if (parseFloat(style.opacity) === 0)
31
+ return false;
32
+ return element.getClientRects().length > 0;
33
+ }
34
+ function isNaturallyTabbable(element) {
35
+ const tag = element.tagName;
36
+ if (tag === 'INPUT' || tag === 'SELECT' || tag === 'TEXTAREA' || tag === 'BUTTON') {
37
+ return !element.disabled;
38
+ }
39
+ if (tag === 'A')
40
+ return element.hasAttribute('href');
41
+ const tabIndex = element.tabIndex;
42
+ return tabIndex >= 0;
43
+ }
44
+ export function isFocusable(element) {
45
+ if (!isElementVisible(element))
46
+ return false;
47
+ if (element.tabIndex < 0 && !isNaturallyTabbable(element))
48
+ return false;
49
+ return true;
50
+ }
51
+ export function getTabbableElements(root) {
52
+ const doc = root.ownerDocument;
53
+ const nodes = root.querySelectorAll(TABBABLE_SELECTOR);
54
+ const result = [];
55
+ for (const node of nodes) {
56
+ if (!root.contains(node))
57
+ continue;
58
+ if (!isFocusable(node))
59
+ continue;
60
+ result.push(node);
61
+ }
62
+ const withTabIndex = root.querySelectorAll('[tabindex]');
63
+ for (const node of withTabIndex) {
64
+ if (result.includes(node))
65
+ continue;
66
+ if (node.tabIndex < 0)
67
+ continue;
68
+ if (!isFocusable(node))
69
+ continue;
70
+ result.push(node);
71
+ }
72
+ result.sort((a, b) => {
73
+ const ai = a.tabIndex > 0 ? a.tabIndex : 0;
74
+ const bi = b.tabIndex > 0 ? b.tabIndex : 0;
75
+ if (ai !== bi)
76
+ return ai - bi;
77
+ return a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1;
78
+ });
79
+ return result;
80
+ }
81
+ /**
82
+ * The element that really has focus, looking inside open shadow roots too (`document.activeElement` alone stops at the host of a
83
+ * shadow root, and the file browser lives in one when an app embeds it).
84
+ */
85
+ export function deepActiveElement(root = document) {
86
+ let active = root.activeElement;
87
+ while (active && active.shadowRoot && active.shadowRoot.activeElement) {
88
+ active = active.shadowRoot.activeElement;
89
+ }
90
+ return active instanceof HTMLElement ? active : null;
91
+ }
92
+ /**
93
+ * Where focus must wrap to when Tab (or Shift+Tab) would otherwise leave the modal. `null` means the browser's own Tab is fine:
94
+ * the trap steps in only at the two ends of the modal (and when focus is not in the modal at all), so the tab order everywhere
95
+ * else stays the browser's own (radio groups, shadow DOM, anything the list of tabbable elements does not know).
96
+ */
97
+ export function tabWrapTarget(options) {
98
+ const { elements, active, shiftKey, modalRoot } = options;
99
+ const first = elements[0];
100
+ const last = elements[elements.length - 1];
101
+ if (!first || !last)
102
+ return null;
103
+ // Focus is not in the modal (something moved it out): bring it back at the end the person is heading for
104
+ if (!active || !modalRoot.contains(active))
105
+ return shiftKey ? last : first;
106
+ // Focus is on the card itself: forward goes into the card by itself, backward would leave it
107
+ if (active === modalRoot)
108
+ return shiftKey ? last : null;
109
+ if (shiftKey)
110
+ return active === first ? last : null;
111
+ return active === last ? first : null;
112
+ }
113
+ function findOpenFloatingAncestor(target) {
114
+ let node = target;
115
+ while (node && node !== node.ownerDocument.body) {
116
+ const role = node.getAttribute('role');
117
+ const state = node.getAttribute('data-state');
118
+ if (state === 'open' && role && FLOATING_LAYER_ROLES.has(role)) {
119
+ return node;
120
+ }
121
+ node = node.parentElement;
122
+ }
123
+ return null;
124
+ }
125
+ /**
126
+ * Focus may sit on a bits-ui layer portaled outside the dialog if a control inside the modal opened it.
127
+ */
128
+ export function isFocusAllowed(modalRoot, target) {
129
+ if (modalRoot.contains(target))
130
+ return true;
131
+ const floating = findOpenFloatingAncestor(target);
132
+ if (!floating)
133
+ return false;
134
+ return modalRoot.querySelector('[aria-expanded="true"]') !== null;
135
+ }
@@ -42,6 +42,12 @@ export declare const overlayBackdropBlurClass = "backdrop-blur-[3px]";
42
42
  export declare const overlayScrimClasses = "bg-muted-foreground/80 backdrop-blur-[3px]";
43
43
  /** Tailwind arbitrary easing approximating Svelte `cubicOut` (ease-out cubic, 1 − (1 − t)³). */
44
44
  export declare const overlayEasingClass = "ease-[cubic-bezier(0.33,1,0.68,1)]";
45
+ /**
46
+ * A scrim drawn over another scrim only dims: the one below blurs the page already, and two backdrop blurs that fade
47
+ * in together flicker. `markStackedScrim` (`overlayStacking.ts`) puts `data-stacked` on such a scrim, and this takes its
48
+ * blur off. Literal so Tailwind's scanner emits it.
49
+ */
50
+ export declare const overlayStackedScrimClass = "data-[stacked]:backdrop-blur-none";
45
51
  /** Overlay + panel classes for bits-ui Dialog (aligned with BaseModal motion: fade, 200ms, cubic-out-like, zoom from 0.95). */
46
52
  export declare const overlayDialogOverlayClasses: string;
47
53
  export declare const overlayDialogContentClasses: string;
@@ -45,9 +45,16 @@ export const overlayBackdropBlurClass = 'backdrop-blur-[3px]';
45
45
  export const overlayScrimClasses = 'bg-muted-foreground/80 backdrop-blur-[3px]';
46
46
  /** Tailwind arbitrary easing approximating Svelte `cubicOut` (ease-out cubic, 1 − (1 − t)³). */
47
47
  export const overlayEasingClass = 'ease-[cubic-bezier(0.33,1,0.68,1)]';
48
+ /**
49
+ * A scrim drawn over another scrim only dims: the one below blurs the page already, and two backdrop blurs that fade
50
+ * in together flicker. `markStackedScrim` (`overlayStacking.ts`) puts `data-stacked` on such a scrim, and this takes its
51
+ * blur off. Literal so Tailwind's scanner emits it.
52
+ */
53
+ export const overlayStackedScrimClass = 'data-[stacked]:backdrop-blur-none';
48
54
  /** Overlay + panel classes for bits-ui Dialog (aligned with BaseModal motion: fade, 200ms, cubic-out-like, zoom from 0.95). */
49
55
  export const overlayDialogOverlayClasses = [
50
56
  overlayScrimClasses,
57
+ overlayStackedScrimClass,
51
58
  overlayDurationClass,
52
59
  overlayEasingClass,
53
60
  ...overlayDialogOpenClosedAnimationDurationClasses,
@@ -0,0 +1,47 @@
1
+ /**
2
+ * Stacked overlays blur the page once.
3
+ *
4
+ * Every dialog and modal draws a scrim: the muted foreground at 80% with a 3px backdrop blur (`overlayScrimClasses`). A
5
+ * dialog opened over another one (the settings dialog, then "Edit domain" on top of it) draws a second scrim over the
6
+ * first. Blurring a page that is already blurred adds nothing the eye can see, but the second scrim fades in, and a
7
+ * backdrop blur that fades is redrawn on every frame of the fade, over the first scrim's redrawn blur: two of them
8
+ * stacked are what made the background flicker when a second dialog opened.
9
+ *
10
+ * So a scrim drawn over another one only dims: it carries `data-stacked`, and the surface that draws it takes the blur
11
+ * off (the dialog overlay with `overlayStackedScrimClass`, the base modal with a rule of its own). The first scrim keeps
12
+ * the blur, so the page is blurred once, however many layers are above it.
13
+ *
14
+ * The mark is part of the scrim as it is created (`data-stacked={stackedScrimMark()}` in the template), not added a
15
+ * moment later: a scrim created with the blur and stripped of it after would first resolve its style with the blur, and
16
+ * the dialog overlay, which transitions every property over 200ms, would then animate the blur away.
17
+ *
18
+ * The decision is made from the page, not from the component tree: bits-ui knows a dialog is nested only when it is
19
+ * rendered inside the other dialog, and a dialog can be mounted somewhere else (the plan chooser, over the settings
20
+ * dialog) and still be drawn above it.
21
+ */
22
+ /** What marks a scrim that is drawn over another scrim. */
23
+ export declare const stackedScrimAttribute = "data-stacked";
24
+ /** The scrims that blur the page: the backdrop of a dialog (bits-ui) and the backdrop of a base modal. */
25
+ export declare const blurringScrimSelector = "[data-widgetic-overlay=\"dialog-backdrop\"], [data-widgetic-overlay=\"base-modal-backdrop\"]";
26
+ /** What the lookup needs of the page: the real `document`, or a stand-in in a test. */
27
+ type ScrimLookupRoot = Pick<ParentNode, 'querySelectorAll'>;
28
+ /**
29
+ * Whether a scrim that still blurs the page is drawn.
30
+ *
31
+ * A scrim that is closing (`data-state="closed"`: the fade out of a dialog that was just closed) does not count. When
32
+ * a dialog closes and another opens in the same moment, the new one is the first, and keeps the blur the old one
33
+ * takes away with it.
34
+ *
35
+ * @param root - Where to look; the page by default.
36
+ * @returns "A scrim is drawn": `true` when the scrim about to be created has to dim only.
37
+ */
38
+ export declare function isAnotherScrimDrawn(root?: ScrimLookupRoot): boolean;
39
+ /**
40
+ * The value of `data-stacked` for a scrim that is being created: an empty string (the attribute is set) when another
41
+ * scrim is drawn, `undefined` (no attribute) when this one is the first. Called from the template, so it runs once, as
42
+ * the scrim is created, before its first frame.
43
+ *
44
+ * @param root - Where to look; the page by default.
45
+ */
46
+ export declare function stackedScrimMark(root?: ScrimLookupRoot): '' | undefined;
47
+ export {};
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Stacked overlays blur the page once.
3
+ *
4
+ * Every dialog and modal draws a scrim: the muted foreground at 80% with a 3px backdrop blur (`overlayScrimClasses`). A
5
+ * dialog opened over another one (the settings dialog, then "Edit domain" on top of it) draws a second scrim over the
6
+ * first. Blurring a page that is already blurred adds nothing the eye can see, but the second scrim fades in, and a
7
+ * backdrop blur that fades is redrawn on every frame of the fade, over the first scrim's redrawn blur: two of them
8
+ * stacked are what made the background flicker when a second dialog opened.
9
+ *
10
+ * So a scrim drawn over another one only dims: it carries `data-stacked`, and the surface that draws it takes the blur
11
+ * off (the dialog overlay with `overlayStackedScrimClass`, the base modal with a rule of its own). The first scrim keeps
12
+ * the blur, so the page is blurred once, however many layers are above it.
13
+ *
14
+ * The mark is part of the scrim as it is created (`data-stacked={stackedScrimMark()}` in the template), not added a
15
+ * moment later: a scrim created with the blur and stripped of it after would first resolve its style with the blur, and
16
+ * the dialog overlay, which transitions every property over 200ms, would then animate the blur away.
17
+ *
18
+ * The decision is made from the page, not from the component tree: bits-ui knows a dialog is nested only when it is
19
+ * rendered inside the other dialog, and a dialog can be mounted somewhere else (the plan chooser, over the settings
20
+ * dialog) and still be drawn above it.
21
+ */
22
+ /** What marks a scrim that is drawn over another scrim. */
23
+ export const stackedScrimAttribute = 'data-stacked';
24
+ /** The scrims that blur the page: the backdrop of a dialog (bits-ui) and the backdrop of a base modal. */
25
+ export const blurringScrimSelector = '[data-widgetic-overlay="dialog-backdrop"], [data-widgetic-overlay="base-modal-backdrop"]';
26
+ /**
27
+ * Whether a scrim that still blurs the page is drawn.
28
+ *
29
+ * A scrim that is closing (`data-state="closed"`: the fade out of a dialog that was just closed) does not count. When
30
+ * a dialog closes and another opens in the same moment, the new one is the first, and keeps the blur the old one
31
+ * takes away with it.
32
+ *
33
+ * @param root - Where to look; the page by default.
34
+ * @returns "A scrim is drawn": `true` when the scrim about to be created has to dim only.
35
+ */
36
+ export function isAnotherScrimDrawn(root = document) {
37
+ for (const drawnScrim of root.querySelectorAll(blurringScrimSelector)) {
38
+ if (drawnScrim.getAttribute('data-state') === 'closed')
39
+ continue;
40
+ return true;
41
+ }
42
+ return false;
43
+ }
44
+ /**
45
+ * The value of `data-stacked` for a scrim that is being created: an empty string (the attribute is set) when another
46
+ * scrim is drawn, `undefined` (no attribute) when this one is the first. Called from the template, so it runs once, as
47
+ * the scrim is created, before its first frame.
48
+ *
49
+ * @param root - Where to look; the page by default.
50
+ */
51
+ export function stackedScrimMark(root) {
52
+ try {
53
+ // On the server there is no page, and no dialog is open.
54
+ if (root === undefined && typeof document === 'undefined')
55
+ return undefined;
56
+ return isAnotherScrimDrawn(root ?? document) ? '' : undefined;
57
+ }
58
+ catch (error) {
59
+ // The scrim keeps its blur: a double blur is only a flicker, not a broken dialog.
60
+ console.warn('[overlayStacking] Could not tell whether another scrim is drawn', error);
61
+ return undefined;
62
+ }
63
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@widgetic/design-system",
3
- "version": "0.5.27",
3
+ "version": "0.5.29",
4
4
  "license": "SEE LICENSE IN LICENSE",
5
5
  "type": "module",
6
6
  "svelte": "./dist/index.js",