@arbidocs/react 0.4.49 → 0.4.50

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/index.cjs CHANGED
@@ -1065,6 +1065,7 @@ var ChatBubble = React.memo(function ChatBubble2({
1065
1065
  classNames,
1066
1066
  renderMessage = (m) => m,
1067
1067
  formatTimestamp = (t) => t,
1068
+ attachments,
1068
1069
  "data-testid": testId
1069
1070
  }) {
1070
1071
  const [isHovered, setIsHovered] = React.useState(false);
@@ -1142,7 +1143,8 @@ var ChatBubble = React.memo(function ChatBubble2({
1142
1143
  highlightClass
1143
1144
  ),
1144
1145
  children: [
1145
- /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm [&_.markdown-content]:space-y-1.5 [&_pre]:max-w-full [&_pre]:overflow-x-auto", children: renderMessage(message) }),
1146
+ (message || !attachments) && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-sm [&_.markdown-content]:space-y-1.5 [&_pre]:max-w-full [&_pre]:overflow-x-auto", children: renderMessage(message) }),
1147
+ attachments && /* @__PURE__ */ jsxRuntime.jsx("div", { className: chunkS6A6FSG7_cjs.cn(message && "mt-1.5"), children: attachments }),
1146
1148
  isLastOfRun && /* @__PURE__ */ jsxRuntime.jsxs(
1147
1149
  "div",
1148
1150
  {
@@ -4331,21 +4333,45 @@ function DmComposer({
4331
4333
  disabled,
4332
4334
  busy,
4333
4335
  onSend,
4336
+ allowAttachments,
4334
4337
  error,
4335
4338
  children,
4336
4339
  classNames
4337
4340
  }) {
4338
4341
  const [draft, setDraft] = React.useState("");
4342
+ const [files, setFiles] = React.useState([]);
4343
+ const [attachError, setAttachError] = React.useState(null);
4344
+ const [dragging, setDragging] = React.useState(false);
4339
4345
  const inputRef = React.useRef(null);
4346
+ const fileInputRef = React.useRef(null);
4347
+ const addFiles = (added) => {
4348
+ if (!allowAttachments || added.length === 0) return;
4349
+ const next = [...files, ...added];
4350
+ try {
4351
+ browser.dm.checkDmAttachmentLimits(next);
4352
+ setFiles(next);
4353
+ setAttachError(null);
4354
+ } catch (err) {
4355
+ setAttachError(err instanceof Error ? err.message : "Could not attach the file");
4356
+ }
4357
+ };
4358
+ const removeFile = (index) => {
4359
+ setFiles((current) => current.filter((_, i) => i !== index));
4360
+ setAttachError(null);
4361
+ };
4340
4362
  const submit = async () => {
4341
4363
  const text = draft.trim();
4342
- if (!text || disabled || busy) return;
4364
+ if (!text && files.length === 0 || disabled || busy) return;
4365
+ const sending = files;
4343
4366
  setDraft("");
4367
+ setFiles([]);
4368
+ setAttachError(null);
4344
4369
  try {
4345
- await onSend(text);
4370
+ await onSend(text, sending);
4346
4371
  inputRef.current?.focus();
4347
4372
  } catch {
4348
4373
  setDraft(text);
4374
+ setFiles(sending);
4349
4375
  }
4350
4376
  };
4351
4377
  const onKeyDown = (e) => {
@@ -4354,41 +4380,143 @@ function DmComposer({
4354
4380
  void submit();
4355
4381
  }
4356
4382
  };
4357
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "border-t border-border p-3", children: [
4358
- children,
4359
- /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [
4360
- /* @__PURE__ */ jsxRuntime.jsx(
4361
- chunkATX7FAO6_cjs.Textarea,
4362
- {
4363
- ref: inputRef,
4364
- value: draft,
4365
- onChange: (e) => setDraft(e.target.value),
4366
- onKeyDown,
4367
- placeholder,
4368
- rows: 1,
4369
- disabled,
4370
- className: "max-h-40 min-h-[44px] resize-none",
4371
- "data-testid": "arbi-dm-input"
4372
- }
4383
+ const onPaste = (e) => {
4384
+ if (!allowAttachments) return;
4385
+ const pasted = Array.from(e.clipboardData?.files ?? []);
4386
+ if (pasted.length === 0) return;
4387
+ e.preventDefault();
4388
+ addFiles(pasted);
4389
+ };
4390
+ const hasFiles = (e) => Array.from(e.dataTransfer?.types ?? []).includes("Files");
4391
+ const dropHandlers = allowAttachments ? {
4392
+ onDragOver: (e) => {
4393
+ if (!hasFiles(e) || disabled) return;
4394
+ e.preventDefault();
4395
+ setDragging(true);
4396
+ },
4397
+ onDragLeave: (e) => {
4398
+ if (e.currentTarget.contains(e.relatedTarget)) return;
4399
+ setDragging(false);
4400
+ },
4401
+ onDrop: (e) => {
4402
+ setDragging(false);
4403
+ const dropped = Array.from(e.dataTransfer?.files ?? []);
4404
+ if (dropped.length === 0 || disabled) return;
4405
+ e.preventDefault();
4406
+ addFiles(dropped);
4407
+ }
4408
+ } : {};
4409
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4410
+ "div",
4411
+ {
4412
+ className: chunkS6A6FSG7_cjs.cn(
4413
+ "border-t border-border p-3",
4414
+ dragging && "bg-muted/60 outline-dashed outline-2 -outline-offset-4 outline-primary"
4373
4415
  ),
4374
- /* @__PURE__ */ jsxRuntime.jsxs(
4375
- chunkATX7FAO6_cjs.Button,
4376
- {
4377
- type: "button",
4378
- onClick: () => void submit(),
4379
- disabled: disabled || busy || !draft.trim(),
4380
- className: chunkS6A6FSG7_cjs.cn(classNames?.sendButton),
4381
- "data-testid": "arbi-dm-send",
4382
- "aria-label": "Send message",
4383
- children: [
4384
- busy ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "size-4 animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Send, { className: "size-4" }),
4385
- " Send"
4386
- ]
4387
- }
4388
- )
4389
- ] }),
4390
- error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-2 text-xs text-destructive", "data-testid": "arbi-dm-error", children: error })
4391
- ] });
4416
+ "data-testid": "arbi-dm-composer",
4417
+ ...dropHandlers,
4418
+ children: [
4419
+ children,
4420
+ files.length > 0 && /* @__PURE__ */ jsxRuntime.jsx("ul", { className: "mb-2 flex flex-wrap gap-2", "aria-label": "Attached files", children: files.map((f, index) => /* @__PURE__ */ jsxRuntime.jsxs(
4421
+ "li",
4422
+ {
4423
+ "data-testid": "arbi-dm-attachment-chip",
4424
+ className: "flex max-w-full items-center gap-2 rounded-md border border-border/70 bg-muted/30 px-2.5 py-1.5 text-xs",
4425
+ children: [
4426
+ /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Paperclip, { className: "size-3 shrink-0", "aria-hidden": "true" }),
4427
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "truncate", children: f.name }),
4428
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "shrink-0 text-muted-foreground", children: browser.formatFileSize(f.size) }),
4429
+ /* @__PURE__ */ jsxRuntime.jsx(
4430
+ "button",
4431
+ {
4432
+ type: "button",
4433
+ disabled: busy,
4434
+ "aria-label": `Remove ${f.name}`,
4435
+ onClick: () => removeFile(index),
4436
+ className: "shrink-0 rounded focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring",
4437
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { className: "size-3" })
4438
+ }
4439
+ )
4440
+ ]
4441
+ },
4442
+ `${f.name}-${index}`
4443
+ )) }),
4444
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-end gap-2", children: [
4445
+ allowAttachments && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4446
+ /* @__PURE__ */ jsxRuntime.jsx(
4447
+ chunkATX7FAO6_cjs.Button,
4448
+ {
4449
+ type: "button",
4450
+ variant: "ghost",
4451
+ size: "icon",
4452
+ disabled: disabled || busy,
4453
+ onClick: () => fileInputRef.current?.click(),
4454
+ "aria-label": "Attach files",
4455
+ title: "Attach files (or paste / drop them here)",
4456
+ "data-testid": "arbi-dm-attach",
4457
+ className: "min-h-[44px] shrink-0",
4458
+ children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Paperclip, { className: "size-4" })
4459
+ }
4460
+ ),
4461
+ /* @__PURE__ */ jsxRuntime.jsx(
4462
+ "input",
4463
+ {
4464
+ ref: fileInputRef,
4465
+ type: "file",
4466
+ multiple: true,
4467
+ hidden: true,
4468
+ "data-testid": "arbi-dm-file-input",
4469
+ onChange: (e) => {
4470
+ addFiles(Array.from(e.target.files ?? []));
4471
+ e.target.value = "";
4472
+ }
4473
+ }
4474
+ )
4475
+ ] }),
4476
+ /* @__PURE__ */ jsxRuntime.jsx(
4477
+ chunkATX7FAO6_cjs.Textarea,
4478
+ {
4479
+ ref: inputRef,
4480
+ value: draft,
4481
+ onChange: (e) => setDraft(e.target.value),
4482
+ onKeyDown,
4483
+ onPaste,
4484
+ placeholder,
4485
+ rows: 1,
4486
+ disabled,
4487
+ className: "max-h-40 min-h-[44px] resize-none",
4488
+ "data-testid": "arbi-dm-input"
4489
+ }
4490
+ ),
4491
+ /* @__PURE__ */ jsxRuntime.jsxs(
4492
+ chunkATX7FAO6_cjs.Button,
4493
+ {
4494
+ type: "button",
4495
+ onClick: () => void submit(),
4496
+ disabled: disabled || busy || !draft.trim() && files.length === 0,
4497
+ className: chunkS6A6FSG7_cjs.cn(classNames?.sendButton),
4498
+ "data-testid": "arbi-dm-send",
4499
+ "aria-label": "Send message",
4500
+ children: [
4501
+ busy ? /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Loader2, { className: "size-4 animate-spin" }) : /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Send, { className: "size-4" }),
4502
+ " Send"
4503
+ ]
4504
+ }
4505
+ )
4506
+ ] }),
4507
+ attachError && /* @__PURE__ */ jsxRuntime.jsx(
4508
+ "p",
4509
+ {
4510
+ className: "mt-2 text-xs text-destructive",
4511
+ role: "alert",
4512
+ "data-testid": "arbi-dm-attach-error",
4513
+ children: attachError
4514
+ }
4515
+ ),
4516
+ error && /* @__PURE__ */ jsxRuntime.jsx("p", { className: "mt-2 text-xs text-destructive", "data-testid": "arbi-dm-error", children: error })
4517
+ ]
4518
+ }
4519
+ );
4392
4520
  }
4393
4521
  var DEFAULT_START_BY_EMAIL_LABELS = {
4394
4522
  email: "Email address",