@sentropic/design-system-svelte 0.41.5 → 0.43.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.
- package/dist/CommentAuthorship.svelte +186 -0
- package/dist/CommentAuthorship.svelte.d.ts +18 -0
- package/dist/CommentAuthorship.svelte.d.ts.map +1 -0
- package/dist/CommentComposer.svelte +336 -0
- package/dist/CommentComposer.svelte.d.ts +33 -0
- package/dist/CommentComposer.svelte.d.ts.map +1 -0
- package/dist/CommentLayer.svelte +1621 -0
- package/dist/CommentLayer.svelte.d.ts +64 -0
- package/dist/CommentLayer.svelte.d.ts.map +1 -0
- package/dist/CommentPin.svelte +219 -0
- package/dist/CommentPin.svelte.d.ts +26 -0
- package/dist/CommentPin.svelte.d.ts.map +1 -0
- package/dist/CommentThread.svelte +801 -0
- package/dist/CommentThread.svelte.d.ts +42 -0
- package/dist/CommentThread.svelte.d.ts.map +1 -0
- package/dist/DiagramCard.svelte +24 -4
- package/dist/DiagramCard.svelte.d.ts.map +1 -1
- package/dist/DiagramCardHeader.svelte +5 -2
- package/dist/DiagramCardHeader.svelte.d.ts +2 -0
- package/dist/DiagramCardHeader.svelte.d.ts.map +1 -1
- package/dist/DiagramSceneFigure.svelte +11 -13
- package/dist/DiagramSceneFigure.svelte.d.ts +4 -0
- package/dist/DiagramSceneFigure.svelte.d.ts.map +1 -1
- package/dist/DiagramZone.svelte +37 -11
- package/dist/DiagramZone.svelte.d.ts.map +1 -1
- package/dist/DiagramZoneHeader.svelte +9 -2
- package/dist/DiagramZoneHeader.svelte.d.ts +4 -0
- package/dist/DiagramZoneHeader.svelte.d.ts.map +1 -1
- package/dist/Drawer.svelte +96 -4
- package/dist/Drawer.svelte.d.ts.map +1 -1
- package/dist/OrphanList.svelte +267 -0
- package/dist/OrphanList.svelte.d.ts +18 -0
- package/dist/OrphanList.svelte.d.ts.map +1 -0
- package/dist/ReviewModeToggle.svelte +110 -0
- package/dist/ReviewModeToggle.svelte.d.ts +19 -0
- package/dist/ReviewModeToggle.svelte.d.ts.map +1 -0
- package/dist/ThreadPanel.svelte +654 -0
- package/dist/ThreadPanel.svelte.d.ts +42 -0
- package/dist/ThreadPanel.svelte.d.ts.map +1 -0
- package/dist/diagram-render/renderCardSvg.d.ts.map +1 -1
- package/dist/diagram-render/renderCardSvg.js +9 -4
- package/dist/diagram-render/renderZoneSvg.d.ts.map +1 -1
- package/dist/diagram-render/renderZoneSvg.js +8 -3
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -0
- package/dist/review-markdown.d.ts +90 -0
- package/dist/review-markdown.d.ts.map +1 -0
- package/dist/review-markdown.js +379 -0
- package/package.json +5 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { CollaborationActor } from "@sentropic/design-system-review-core";
|
|
4
|
+
import type { AvatarSize } from "./Avatar.svelte";
|
|
5
|
+
|
|
6
|
+
export type CommentAuthorshipProps = Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
|
|
7
|
+
/** True author (human, agent, or NHI). */
|
|
8
|
+
author: CollaborationActor;
|
|
9
|
+
/** Sponsoring human owner when the true author is an agent/NHI. */
|
|
10
|
+
sponsor?: CollaborationActor;
|
|
11
|
+
/** Vignette size matching AvatarGroup scale. */
|
|
12
|
+
size?: AvatarSize;
|
|
13
|
+
/** Whether to render the textual attribution line beside the icon stack. */
|
|
14
|
+
showLabel?: boolean;
|
|
15
|
+
class?: string;
|
|
16
|
+
};
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<script lang="ts">
|
|
20
|
+
import { Bot, Cpu } from "@lucide/svelte";
|
|
21
|
+
import AvatarGroup from "./AvatarGroup.svelte";
|
|
22
|
+
import Badge from "./Badge.svelte";
|
|
23
|
+
import { deriveInitials } from "./Header.svelte";
|
|
24
|
+
import { sanitizeActorColor } from "./review-markdown.js";
|
|
25
|
+
|
|
26
|
+
let {
|
|
27
|
+
author,
|
|
28
|
+
sponsor,
|
|
29
|
+
size = "sm",
|
|
30
|
+
showLabel = true,
|
|
31
|
+
class: className,
|
|
32
|
+
...rest
|
|
33
|
+
}: CommentAuthorshipProps = $props();
|
|
34
|
+
|
|
35
|
+
const isNonHuman = $derived(author.kind !== "human");
|
|
36
|
+
const authorColor = $derived(sanitizeActorColor(author.color));
|
|
37
|
+
const sponsorColor = $derived(sponsor ? sanitizeActorColor(sponsor.color) : undefined);
|
|
38
|
+
const authorInitials = $derived(deriveInitials(author.displayLabel));
|
|
39
|
+
const sponsorInitials = $derived(sponsor ? deriveInitials(sponsor.displayLabel) : "");
|
|
40
|
+
const iconSize = $derived(
|
|
41
|
+
size === "sm" ? 13 : size === "md" ? 16 : size === "lg" ? 18 : 22,
|
|
42
|
+
);
|
|
43
|
+
const kindBadgeLabel = $derived(author.kind === "nhi" ? "NHI" : "Agent");
|
|
44
|
+
|
|
45
|
+
const accessibleName = $derived.by(() => {
|
|
46
|
+
if (sponsor) {
|
|
47
|
+
return `Comment by ${author.displayLabel}, ${author.kind}, on behalf of ${sponsor.displayLabel}`;
|
|
48
|
+
}
|
|
49
|
+
if (isNonHuman) {
|
|
50
|
+
return `Comment by ${author.displayLabel}, ${author.kind}`;
|
|
51
|
+
}
|
|
52
|
+
return `Comment by ${author.displayLabel}`;
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
const classes = $derived(
|
|
56
|
+
["st-review-authorship", `st-review-authorship--${size}`, className]
|
|
57
|
+
.filter(Boolean)
|
|
58
|
+
.join(" "),
|
|
59
|
+
);
|
|
60
|
+
</script>
|
|
61
|
+
|
|
62
|
+
<div {...rest} class={classes} data-author-kind={author.kind}>
|
|
63
|
+
<!-- Composed on AvatarGroup (not bare Avatar) so inner vignettes stay aria-hidden
|
|
64
|
+
under a single role="img" carrying the full attribution name (SPEC-r6 §3). -->
|
|
65
|
+
<AvatarGroup
|
|
66
|
+
{size}
|
|
67
|
+
class="st-review-authorship__stack"
|
|
68
|
+
role="img"
|
|
69
|
+
aria-label={accessibleName}
|
|
70
|
+
>
|
|
71
|
+
<span
|
|
72
|
+
class="st-review-authorship__vignette st-review-authorship__vignette--{size}"
|
|
73
|
+
class:st-review-authorship__vignette--agent={isNonHuman}
|
|
74
|
+
data-actor-kind={author.kind}
|
|
75
|
+
style:--st-review-actor-color={authorColor}
|
|
76
|
+
aria-hidden="true"
|
|
77
|
+
>
|
|
78
|
+
{#if author.kind === "agent"}
|
|
79
|
+
<Bot size={iconSize} strokeWidth={2} aria-hidden="true" />
|
|
80
|
+
{:else if author.kind === "nhi"}
|
|
81
|
+
<Cpu size={iconSize} strokeWidth={2} aria-hidden="true" />
|
|
82
|
+
{:else}
|
|
83
|
+
<span class="st-review-authorship__initials">{authorInitials}</span>
|
|
84
|
+
{/if}
|
|
85
|
+
</span>
|
|
86
|
+
|
|
87
|
+
{#if sponsor}
|
|
88
|
+
<span
|
|
89
|
+
class="st-review-authorship__vignette st-review-authorship__vignette--{size} st-review-authorship__vignette--sponsor"
|
|
90
|
+
data-actor-kind="sponsor"
|
|
91
|
+
style:--st-review-actor-color={sponsorColor}
|
|
92
|
+
aria-hidden="true"
|
|
93
|
+
>
|
|
94
|
+
<span class="st-review-authorship__initials">{sponsorInitials}</span>
|
|
95
|
+
</span>
|
|
96
|
+
{/if}
|
|
97
|
+
</AvatarGroup>
|
|
98
|
+
|
|
99
|
+
{#if showLabel}
|
|
100
|
+
<span class="st-review-authorship__label">
|
|
101
|
+
<span class="st-review-authorship__name">{author.displayLabel}</span>
|
|
102
|
+
{#if isNonHuman}
|
|
103
|
+
<Badge size="sm" tone="info" class="st-review-authorship__kind">{kindBadgeLabel}</Badge>
|
|
104
|
+
{/if}
|
|
105
|
+
{#if sponsor}
|
|
106
|
+
<span class="st-review-authorship__sponsor"> · on behalf of {sponsor.displayLabel}</span>
|
|
107
|
+
{/if}
|
|
108
|
+
</span>
|
|
109
|
+
{/if}
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<style>
|
|
113
|
+
.st-review-authorship {
|
|
114
|
+
align-items: center;
|
|
115
|
+
display: inline-flex;
|
|
116
|
+
flex-wrap: wrap;
|
|
117
|
+
gap: var(--st-component-review-authorship-gap, var(--st-spacing-2, 0.5rem));
|
|
118
|
+
min-width: 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
.st-review-authorship__vignette {
|
|
122
|
+
align-items: center;
|
|
123
|
+
background: var(--st-review-actor-color, var(--st-semantic-action-primary, #2563eb));
|
|
124
|
+
border-radius: 999px;
|
|
125
|
+
color: var(--st-semantic-text-inverse, #ffffff);
|
|
126
|
+
display: inline-flex;
|
|
127
|
+
flex: 0 0 auto;
|
|
128
|
+
font-weight: 700;
|
|
129
|
+
justify-content: center;
|
|
130
|
+
letter-spacing: 0.01em;
|
|
131
|
+
line-height: 1;
|
|
132
|
+
user-select: none;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.st-review-authorship__vignette--sm {
|
|
136
|
+
font-size: 0.625rem;
|
|
137
|
+
height: 1.5rem;
|
|
138
|
+
width: 1.5rem;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
.st-review-authorship__vignette--md {
|
|
142
|
+
font-size: 0.75rem;
|
|
143
|
+
height: 2rem;
|
|
144
|
+
width: 2rem;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.st-review-authorship__vignette--lg {
|
|
148
|
+
font-size: 0.875rem;
|
|
149
|
+
height: 2.5rem;
|
|
150
|
+
width: 2.5rem;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.st-review-authorship__vignette--xl {
|
|
154
|
+
font-size: 1.125rem;
|
|
155
|
+
height: 3.5rem;
|
|
156
|
+
width: 3.5rem;
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
.st-review-authorship__vignette--agent {
|
|
160
|
+
border-radius: var(--st-radius-sm, 0.375rem);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
.st-review-authorship__initials {
|
|
164
|
+
pointer-events: none;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
.st-review-authorship__label {
|
|
168
|
+
align-items: center;
|
|
169
|
+
color: var(--st-component-review-text, var(--st-semantic-text-primary));
|
|
170
|
+
display: inline-flex;
|
|
171
|
+
flex-wrap: wrap;
|
|
172
|
+
font-size: 0.8125rem;
|
|
173
|
+
gap: var(--st-spacing-1, 0.25rem);
|
|
174
|
+
line-height: 1.3;
|
|
175
|
+
min-width: 0;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.st-review-authorship__name {
|
|
179
|
+
font-weight: 600;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
.st-review-authorship__sponsor {
|
|
183
|
+
color: var(--st-component-review-mutedText, var(--st-semantic-text-secondary));
|
|
184
|
+
font-weight: 400;
|
|
185
|
+
}
|
|
186
|
+
</style>
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
2
|
+
import type { CollaborationActor } from "@sentropic/design-system-review-core";
|
|
3
|
+
import type { AvatarSize } from "./Avatar.svelte";
|
|
4
|
+
export type CommentAuthorshipProps = Omit<HTMLAttributes<HTMLDivElement>, "class"> & {
|
|
5
|
+
/** True author (human, agent, or NHI). */
|
|
6
|
+
author: CollaborationActor;
|
|
7
|
+
/** Sponsoring human owner when the true author is an agent/NHI. */
|
|
8
|
+
sponsor?: CollaborationActor;
|
|
9
|
+
/** Vignette size matching AvatarGroup scale. */
|
|
10
|
+
size?: AvatarSize;
|
|
11
|
+
/** Whether to render the textual attribution line beside the icon stack. */
|
|
12
|
+
showLabel?: boolean;
|
|
13
|
+
class?: string;
|
|
14
|
+
};
|
|
15
|
+
declare const CommentAuthorship: import("svelte").Component<CommentAuthorshipProps, {}, "">;
|
|
16
|
+
type CommentAuthorship = ReturnType<typeof CommentAuthorship>;
|
|
17
|
+
export default CommentAuthorship;
|
|
18
|
+
//# sourceMappingURL=CommentAuthorship.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommentAuthorship.svelte.d.ts","sourceRoot":"","sources":["../src/lib/CommentAuthorship.svelte.ts"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAC/E,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAElD,MAAM,MAAM,sBAAsB,GAAG,IAAI,CAAC,cAAc,CAAC,cAAc,CAAC,EAAE,OAAO,CAAC,GAAG;IACnF,0CAA0C;IAC1C,MAAM,EAAE,kBAAkB,CAAC;IAC3B,mEAAmE;IACnE,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,gDAAgD;IAChD,IAAI,CAAC,EAAE,UAAU,CAAC;IAClB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AA2FJ,QAAA,MAAM,iBAAiB,4DAAwC,CAAC;AAChE,KAAK,iBAAiB,GAAG,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC9D,eAAe,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
<script lang="ts" module>
|
|
2
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
3
|
+
import type { CollaborationActor } from "@sentropic/design-system-review-core";
|
|
4
|
+
|
|
5
|
+
export type CommentComposerProps = Omit<HTMLAttributes<HTMLFormElement>, "class" | "onsubmit"> & {
|
|
6
|
+
author: CollaborationActor;
|
|
7
|
+
sponsor?: CollaborationActor;
|
|
8
|
+
placeholder?: string;
|
|
9
|
+
submitLabel?: string;
|
|
10
|
+
cancelLabel?: string;
|
|
11
|
+
initialBody?: string;
|
|
12
|
+
autofocus?: boolean;
|
|
13
|
+
/** Traps Tab/Shift+Tab within the composer (true by default for floating composers). */
|
|
14
|
+
trapFocus?: boolean;
|
|
15
|
+
disabled?: boolean;
|
|
16
|
+
submitting?: boolean;
|
|
17
|
+
/** Inline anchor-cap or validation error (rejects submission inline per SPEC-r6 §2/§3). */
|
|
18
|
+
anchorError?: string | null;
|
|
19
|
+
/** External submission error displayed inline in role="alert". */
|
|
20
|
+
error?: string | null;
|
|
21
|
+
/** Optional anchor quote preview shown above the textarea. */
|
|
22
|
+
quotePreview?: string;
|
|
23
|
+
/** Accessible name for the composer textarea. */
|
|
24
|
+
label?: string;
|
|
25
|
+
/** Clear the textarea after a successful submission (defaults to true when initialBody is empty). */
|
|
26
|
+
clearOnSubmit?: boolean;
|
|
27
|
+
class?: string;
|
|
28
|
+
onSubmit?: (body: string) => void | Promise<void>;
|
|
29
|
+
onCancel?: () => void;
|
|
30
|
+
onDraftChange?: (body: string) => void;
|
|
31
|
+
};
|
|
32
|
+
</script>
|
|
33
|
+
|
|
34
|
+
<script lang="ts">
|
|
35
|
+
import { tick, untrack } from "svelte";
|
|
36
|
+
import Button from "./Button.svelte";
|
|
37
|
+
import CommentAuthorship from "./CommentAuthorship.svelte";
|
|
38
|
+
import { formatReviewError, handleFocusTrapKeydown } from "./review-markdown.js";
|
|
39
|
+
|
|
40
|
+
let {
|
|
41
|
+
author,
|
|
42
|
+
sponsor,
|
|
43
|
+
placeholder = "Add a comment…",
|
|
44
|
+
submitLabel = "Comment",
|
|
45
|
+
cancelLabel = "Cancel",
|
|
46
|
+
initialBody = "",
|
|
47
|
+
autofocus = true,
|
|
48
|
+
trapFocus = true,
|
|
49
|
+
disabled = false,
|
|
50
|
+
submitting = false,
|
|
51
|
+
anchorError = null,
|
|
52
|
+
error = null,
|
|
53
|
+
quotePreview,
|
|
54
|
+
label = "Comment body",
|
|
55
|
+
clearOnSubmit,
|
|
56
|
+
class: className,
|
|
57
|
+
onSubmit,
|
|
58
|
+
onCancel,
|
|
59
|
+
onDraftChange,
|
|
60
|
+
...rest
|
|
61
|
+
}: CommentComposerProps = $props();
|
|
62
|
+
|
|
63
|
+
let formEl: HTMLFormElement | undefined = $state();
|
|
64
|
+
let textareaEl: HTMLTextAreaElement | undefined = $state();
|
|
65
|
+
let body = $state(untrack(() => initialBody));
|
|
66
|
+
let localError = $state<string | null>(null);
|
|
67
|
+
let internalSubmitting = $state(false);
|
|
68
|
+
let didAutofocus = false;
|
|
69
|
+
|
|
70
|
+
const uid = $props.id();
|
|
71
|
+
const errorId = `st-review-composer-err-${uid}`;
|
|
72
|
+
const isBusy = $derived(submitting || internalSubmitting);
|
|
73
|
+
const displayedError = $derived(anchorError ?? localError ?? error);
|
|
74
|
+
const shouldClearOnSubmit = $derived(clearOnSubmit ?? initialBody.length === 0);
|
|
75
|
+
|
|
76
|
+
const classes = $derived(["st-review-composer", className].filter(Boolean).join(" "));
|
|
77
|
+
|
|
78
|
+
$effect(() => {
|
|
79
|
+
if (autofocus && textareaEl && !didAutofocus) {
|
|
80
|
+
didAutofocus = true;
|
|
81
|
+
textareaEl.focus();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Attach direct DOM listener on the form so Escape stopPropagation happens BEFORE
|
|
86
|
+
// leaving the composer (Svelte 5 delegates template `onkeydown` to document).
|
|
87
|
+
// Only intercept Escape when `onCancel` is bound so permanent inline reply composers
|
|
88
|
+
// let Escape bubble up to close the enclosing ThreadPanel / bottom-sheet Drawer.
|
|
89
|
+
$effect(() => {
|
|
90
|
+
const node = formEl;
|
|
91
|
+
if (!node) return;
|
|
92
|
+
const onKeydown = (event: KeyboardEvent) => {
|
|
93
|
+
if (event.key === "Escape") {
|
|
94
|
+
if (onCancel) {
|
|
95
|
+
event.preventDefault();
|
|
96
|
+
event.stopPropagation();
|
|
97
|
+
handleCancel();
|
|
98
|
+
}
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (trapFocus && event.key === "Tab") {
|
|
102
|
+
event.stopPropagation();
|
|
103
|
+
handleFocusTrapKeydown(event, node);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
node.addEventListener("keydown", onKeydown);
|
|
107
|
+
return () => node.removeEventListener("keydown", onKeydown);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
function handleInput() {
|
|
111
|
+
if (localError !== null) {
|
|
112
|
+
localError = null;
|
|
113
|
+
}
|
|
114
|
+
onDraftChange?.(body);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
async function submitBody() {
|
|
118
|
+
if (disabled || isBusy) return;
|
|
119
|
+
|
|
120
|
+
if (anchorError) {
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const trimmed = body.trim();
|
|
125
|
+
if (trimmed.length === 0) {
|
|
126
|
+
localError = "Comment cannot be empty.";
|
|
127
|
+
textareaEl?.focus();
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
localError = null;
|
|
132
|
+
if (!onSubmit) return;
|
|
133
|
+
|
|
134
|
+
const shouldClear = shouldClearOnSubmit;
|
|
135
|
+
const doc = formEl?.ownerDocument ?? (typeof document !== "undefined" ? document : null);
|
|
136
|
+
let failed = false;
|
|
137
|
+
internalSubmitting = true;
|
|
138
|
+
try {
|
|
139
|
+
await onSubmit(trimmed);
|
|
140
|
+
if (shouldClear) {
|
|
141
|
+
body = "";
|
|
142
|
+
onDraftChange?.("");
|
|
143
|
+
}
|
|
144
|
+
} catch (err) {
|
|
145
|
+
failed = true;
|
|
146
|
+
localError = formatReviewError(err);
|
|
147
|
+
} finally {
|
|
148
|
+
internalSubmitting = false;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
// Wait for `disabled={disabled || isBusy}` to clear before restoring focus.
|
|
152
|
+
// Keep focus in the textarea on error, or on success when the composer remains mounted
|
|
153
|
+
// and focus was dropped to document.body (or stayed inside the form).
|
|
154
|
+
await tick();
|
|
155
|
+
if (textareaEl?.isConnected && !disabled) {
|
|
156
|
+
const active = doc?.activeElement ?? null;
|
|
157
|
+
const focusDroppedOrInside =
|
|
158
|
+
active === null || active === doc?.body || (formEl !== undefined && formEl.contains(active));
|
|
159
|
+
if (failed || focusDroppedOrInside) {
|
|
160
|
+
textareaEl.focus();
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function handleFormSubmit(event: SubmitEvent) {
|
|
166
|
+
event.preventDefault();
|
|
167
|
+
void submitBody();
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
function handleCancel() {
|
|
171
|
+
if (isBusy) return;
|
|
172
|
+
onCancel?.();
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function handleTextareaKeydown(event: KeyboardEvent) {
|
|
176
|
+
if ((event.metaKey || event.ctrlKey) && event.key === "Enter" && !event.isComposing) {
|
|
177
|
+
event.preventDefault();
|
|
178
|
+
event.stopPropagation();
|
|
179
|
+
void submitBody();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
</script>
|
|
183
|
+
|
|
184
|
+
<form
|
|
185
|
+
{...rest}
|
|
186
|
+
bind:this={formEl}
|
|
187
|
+
class={classes}
|
|
188
|
+
novalidate
|
|
189
|
+
onsubmit={handleFormSubmit}
|
|
190
|
+
>
|
|
191
|
+
<div class="st-review-composer__header">
|
|
192
|
+
<CommentAuthorship {author} {sponsor} size="sm" />
|
|
193
|
+
</div>
|
|
194
|
+
|
|
195
|
+
{#if quotePreview}
|
|
196
|
+
<p class="st-review-composer__quote">{quotePreview}</p>
|
|
197
|
+
{/if}
|
|
198
|
+
|
|
199
|
+
<div class="st-review-composer__field">
|
|
200
|
+
<textarea
|
|
201
|
+
bind:this={textareaEl}
|
|
202
|
+
class="st-review-composer__textarea"
|
|
203
|
+
bind:value={body}
|
|
204
|
+
{placeholder}
|
|
205
|
+
rows="3"
|
|
206
|
+
disabled={disabled || isBusy}
|
|
207
|
+
aria-label={label}
|
|
208
|
+
aria-invalid={displayedError ? "true" : undefined}
|
|
209
|
+
aria-describedby={displayedError ? errorId : undefined}
|
|
210
|
+
oninput={handleInput}
|
|
211
|
+
onkeydown={handleTextareaKeydown}
|
|
212
|
+
></textarea>
|
|
213
|
+
</div>
|
|
214
|
+
|
|
215
|
+
{#if displayedError}
|
|
216
|
+
<div id={errorId} class="st-review-composer__error" role="alert">
|
|
217
|
+
{displayedError}
|
|
218
|
+
</div>
|
|
219
|
+
{/if}
|
|
220
|
+
|
|
221
|
+
<div class="st-review-composer__footer">
|
|
222
|
+
<span class="st-review-composer__hint">
|
|
223
|
+
{onCancel ? "Cmd/Ctrl+Enter to submit · Esc to cancel" : "Cmd/Ctrl+Enter to submit"}
|
|
224
|
+
</span>
|
|
225
|
+
<div class="st-review-composer__actions">
|
|
226
|
+
{#if onCancel}
|
|
227
|
+
<Button
|
|
228
|
+
type="button"
|
|
229
|
+
variant="ghost"
|
|
230
|
+
size="sm"
|
|
231
|
+
disabled={isBusy}
|
|
232
|
+
onclick={handleCancel}
|
|
233
|
+
>
|
|
234
|
+
{cancelLabel}
|
|
235
|
+
</Button>
|
|
236
|
+
{/if}
|
|
237
|
+
<Button
|
|
238
|
+
type="submit"
|
|
239
|
+
variant="primary"
|
|
240
|
+
size="sm"
|
|
241
|
+
disabled={disabled || isBusy}
|
|
242
|
+
>
|
|
243
|
+
{submitLabel}
|
|
244
|
+
</Button>
|
|
245
|
+
</div>
|
|
246
|
+
</div>
|
|
247
|
+
</form>
|
|
248
|
+
|
|
249
|
+
<style>
|
|
250
|
+
.st-review-composer {
|
|
251
|
+
background: var(
|
|
252
|
+
--st-component-review-composer-background,
|
|
253
|
+
var(--st-semantic-surface-raised, #ffffff)
|
|
254
|
+
);
|
|
255
|
+
border: 1px solid
|
|
256
|
+
var(--st-component-review-composer-border, var(--st-semantic-border-subtle));
|
|
257
|
+
border-radius: var(--st-component-review-composer-radius, var(--st-radius-md, 0.5rem));
|
|
258
|
+
color: var(--st-semantic-text-primary);
|
|
259
|
+
display: grid;
|
|
260
|
+
gap: var(--st-spacing-2, 0.5rem);
|
|
261
|
+
padding: var(--st-spacing-3, 0.75rem);
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.st-review-composer__header {
|
|
265
|
+
align-items: center;
|
|
266
|
+
display: flex;
|
|
267
|
+
justify-content: space-between;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
.st-review-composer__quote {
|
|
271
|
+
background: var(--st-semantic-surface-subtle, #f8fafc);
|
|
272
|
+
border-radius: var(--st-radius-sm, 0.375rem);
|
|
273
|
+
box-shadow: inset 3px 0 0 var(--st-semantic-border-interactive, #2563eb);
|
|
274
|
+
color: var(--st-semantic-text-secondary);
|
|
275
|
+
font-size: 0.8125rem;
|
|
276
|
+
line-height: 1.4;
|
|
277
|
+
margin: 0;
|
|
278
|
+
padding: var(--st-spacing-1, 0.25rem) var(--st-spacing-2, 0.5rem);
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
.st-review-composer__field {
|
|
282
|
+
display: grid;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
.st-review-composer__textarea {
|
|
286
|
+
background: var(--st-component-control-background, var(--st-semantic-surface-default));
|
|
287
|
+
border: 1px solid var(--st-component-control-border, var(--st-semantic-border-subtle));
|
|
288
|
+
border-radius: var(--st-component-control-radius, 0.375rem);
|
|
289
|
+
box-sizing: border-box;
|
|
290
|
+
color: var(--st-component-control-text, var(--st-semantic-text-primary));
|
|
291
|
+
font: inherit;
|
|
292
|
+
font-size: 0.875rem;
|
|
293
|
+
line-height: 1.5;
|
|
294
|
+
min-height: 4.5rem;
|
|
295
|
+
padding: var(--st-spacing-2, 0.5rem);
|
|
296
|
+
resize: vertical;
|
|
297
|
+
width: 100%;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
.st-review-composer__textarea:focus-visible {
|
|
301
|
+
outline: 2px solid
|
|
302
|
+
var(--st-component-review-focusRing, var(--st-semantic-border-interactive, #2563eb));
|
|
303
|
+
outline-offset: 1px;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
.st-review-composer__textarea[aria-invalid="true"] {
|
|
307
|
+
border-color: var(--st-semantic-feedback-danger, #b91c1c);
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
.st-review-composer__error {
|
|
311
|
+
color: var(--st-semantic-feedback-danger, #b91c1c);
|
|
312
|
+
font-size: 0.8125rem;
|
|
313
|
+
font-weight: 500;
|
|
314
|
+
line-height: 1.4;
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
.st-review-composer__footer {
|
|
318
|
+
align-items: center;
|
|
319
|
+
display: flex;
|
|
320
|
+
flex-wrap: wrap;
|
|
321
|
+
gap: var(--st-spacing-2, 0.5rem);
|
|
322
|
+
justify-content: space-between;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
.st-review-composer__hint {
|
|
326
|
+
color: var(--st-semantic-text-secondary);
|
|
327
|
+
font-size: 0.75rem;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
.st-review-composer__actions {
|
|
331
|
+
align-items: center;
|
|
332
|
+
display: inline-flex;
|
|
333
|
+
gap: var(--st-spacing-2, 0.5rem);
|
|
334
|
+
margin-left: auto;
|
|
335
|
+
}
|
|
336
|
+
</style>
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { HTMLAttributes } from "svelte/elements";
|
|
2
|
+
import type { CollaborationActor } from "@sentropic/design-system-review-core";
|
|
3
|
+
export type CommentComposerProps = Omit<HTMLAttributes<HTMLFormElement>, "class" | "onsubmit"> & {
|
|
4
|
+
author: CollaborationActor;
|
|
5
|
+
sponsor?: CollaborationActor;
|
|
6
|
+
placeholder?: string;
|
|
7
|
+
submitLabel?: string;
|
|
8
|
+
cancelLabel?: string;
|
|
9
|
+
initialBody?: string;
|
|
10
|
+
autofocus?: boolean;
|
|
11
|
+
/** Traps Tab/Shift+Tab within the composer (true by default for floating composers). */
|
|
12
|
+
trapFocus?: boolean;
|
|
13
|
+
disabled?: boolean;
|
|
14
|
+
submitting?: boolean;
|
|
15
|
+
/** Inline anchor-cap or validation error (rejects submission inline per SPEC-r6 §2/§3). */
|
|
16
|
+
anchorError?: string | null;
|
|
17
|
+
/** External submission error displayed inline in role="alert". */
|
|
18
|
+
error?: string | null;
|
|
19
|
+
/** Optional anchor quote preview shown above the textarea. */
|
|
20
|
+
quotePreview?: string;
|
|
21
|
+
/** Accessible name for the composer textarea. */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** Clear the textarea after a successful submission (defaults to true when initialBody is empty). */
|
|
24
|
+
clearOnSubmit?: boolean;
|
|
25
|
+
class?: string;
|
|
26
|
+
onSubmit?: (body: string) => void | Promise<void>;
|
|
27
|
+
onCancel?: () => void;
|
|
28
|
+
onDraftChange?: (body: string) => void;
|
|
29
|
+
};
|
|
30
|
+
declare const CommentComposer: import("svelte").Component<CommentComposerProps, {}, "">;
|
|
31
|
+
type CommentComposer = ReturnType<typeof CommentComposer>;
|
|
32
|
+
export default CommentComposer;
|
|
33
|
+
//# sourceMappingURL=CommentComposer.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CommentComposer.svelte.d.ts","sourceRoot":"","sources":["../src/lib/CommentComposer.svelte.ts"],"names":[],"mappings":"AAGE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,sCAAsC,CAAC;AAE/E,MAAM,MAAM,oBAAoB,GAAG,IAAI,CAAC,cAAc,CAAC,eAAe,CAAC,EAAE,OAAO,GAAG,UAAU,CAAC,GAAG;IAC/F,MAAM,EAAE,kBAAkB,CAAC;IAC3B,OAAO,CAAC,EAAE,kBAAkB,CAAC;IAC7B,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,wFAAwF;IACxF,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,2FAA2F;IAC3F,WAAW,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAC5B,kEAAkE;IAClE,KAAK,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACtB,8DAA8D;IAC9D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,iDAAiD;IACjD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qGAAqG;IACrG,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,aAAa,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACxC,CAAC;AAwMJ,QAAA,MAAM,eAAe,0DAAwC,CAAC;AAC9D,KAAK,eAAe,GAAG,UAAU,CAAC,OAAO,eAAe,CAAC,CAAC;AAC1D,eAAe,eAAe,CAAC"}
|