@mieweb/ui 0.8.0-dev.17 → 0.8.0-dev.18

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.d.cts CHANGED
@@ -3250,6 +3250,11 @@ interface ChatComposerHandle {
3250
3250
  addFiles: (files: File[]) => void;
3251
3251
  /** Focus the text input. */
3252
3252
  focus: () => void;
3253
+ /**
3254
+ * The underlying textarea element, for host integrations that need caret
3255
+ * access (e.g. mention insertion via `setSelectionRange`).
3256
+ */
3257
+ getTextarea: () => HTMLTextAreaElement | null;
3253
3258
  }
3254
3259
  /** Structured context passed to `onError` so hosts can localize by reason. */
3255
3260
  interface ChatComposerError {
@@ -3280,6 +3285,27 @@ interface ChatComposerProps {
3280
3285
  maxLength?: number;
3281
3286
  /** Show a character counter (requires `maxLength`). */
3282
3287
  showCharacterCount?: boolean;
3288
+ /**
3289
+ * Allow sending while the composer itself is empty (e.g. when the host
3290
+ * stages attachments outside the composer). The host receives a message
3291
+ * with empty `content` and no attachments and owns any further guarding.
3292
+ * @default false
3293
+ */
3294
+ canSendWhenEmpty?: boolean;
3295
+ /**
3296
+ * Maximum height of the auto-growing input: a pixel number or any CSS
3297
+ * length (e.g. `'40vh'`).
3298
+ * @default 160
3299
+ */
3300
+ maxHeight?: number | string;
3301
+ /**
3302
+ * Extra props spread onto the underlying textarea. Event handlers run
3303
+ * before the composer's built-in handlers; call `event.preventDefault()`
3304
+ * in `onKeyDown` / `onPaste` to claim that event (e.g. for a mention
3305
+ * menu's arrow/Enter navigation). `className` and `style` are merged
3306
+ * with the composer's own.
3307
+ */
3308
+ textareaProps?: Omit<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'defaultValue'>;
3283
3309
  /** Extra entries for the `+` menu, rendered after the built-in items. */
3284
3310
  addMenuItems?: ChatComposerMenuItem[];
3285
3311
  /** Enable file attachments (built-in "Attach files" menu item, paste-to-attach, chips). @default true */
package/dist/index.d.ts CHANGED
@@ -3250,6 +3250,11 @@ interface ChatComposerHandle {
3250
3250
  addFiles: (files: File[]) => void;
3251
3251
  /** Focus the text input. */
3252
3252
  focus: () => void;
3253
+ /**
3254
+ * The underlying textarea element, for host integrations that need caret
3255
+ * access (e.g. mention insertion via `setSelectionRange`).
3256
+ */
3257
+ getTextarea: () => HTMLTextAreaElement | null;
3253
3258
  }
3254
3259
  /** Structured context passed to `onError` so hosts can localize by reason. */
3255
3260
  interface ChatComposerError {
@@ -3280,6 +3285,27 @@ interface ChatComposerProps {
3280
3285
  maxLength?: number;
3281
3286
  /** Show a character counter (requires `maxLength`). */
3282
3287
  showCharacterCount?: boolean;
3288
+ /**
3289
+ * Allow sending while the composer itself is empty (e.g. when the host
3290
+ * stages attachments outside the composer). The host receives a message
3291
+ * with empty `content` and no attachments and owns any further guarding.
3292
+ * @default false
3293
+ */
3294
+ canSendWhenEmpty?: boolean;
3295
+ /**
3296
+ * Maximum height of the auto-growing input: a pixel number or any CSS
3297
+ * length (e.g. `'40vh'`).
3298
+ * @default 160
3299
+ */
3300
+ maxHeight?: number | string;
3301
+ /**
3302
+ * Extra props spread onto the underlying textarea. Event handlers run
3303
+ * before the composer's built-in handlers; call `event.preventDefault()`
3304
+ * in `onKeyDown` / `onPaste` to claim that event (e.g. for a mention
3305
+ * menu's arrow/Enter navigation). `className` and `style` are merged
3306
+ * with the composer's own.
3307
+ */
3308
+ textareaProps?: Omit<React$1.TextareaHTMLAttributes<HTMLTextAreaElement>, 'value' | 'defaultValue'>;
3283
3309
  /** Extra entries for the `+` menu, rendered after the built-in items. */
3284
3310
  addMenuItems?: ChatComposerMenuItem[];
3285
3311
  /** Enable file attachments (built-in "Attach files" menu item, paste-to-attach, chips). @default true */
package/dist/index.js CHANGED
@@ -12524,6 +12524,9 @@ var ChatComposer = React13.forwardRef(function ChatComposer2({
12524
12524
  autoFocus = false,
12525
12525
  maxLength,
12526
12526
  showCharacterCount = false,
12527
+ canSendWhenEmpty = false,
12528
+ maxHeight = MAX_INPUT_HEIGHT,
12529
+ textareaProps,
12527
12530
  addMenuItems,
12528
12531
  allowAttachments = true,
12529
12532
  acceptedFileTypes,
@@ -12569,7 +12572,7 @@ var ChatComposer = React13.forwardRef(function ChatComposer2({
12569
12572
  const hasText = value.trim().length > 0;
12570
12573
  const hasContent = hasText || attachments.length > 0;
12571
12574
  const isOverLimit = maxLength !== void 0 && value.length > maxLength;
12572
- const canSend = hasContent && onSend !== void 0 && !disabled && !isSending && !isStreaming && !isOverLimit;
12575
+ const canSend = (hasContent || canSendWhenEmpty) && onSend !== void 0 && !disabled && !isSending && !isStreaming && !isOverLimit;
12573
12576
  const setValue = React13.useCallback(
12574
12577
  (next) => {
12575
12578
  if (!isControlled) setInternalValue(next);
@@ -12581,7 +12584,7 @@ var ChatComposer = React13.forwardRef(function ChatComposer2({
12581
12584
  const textarea = textareaRef.current;
12582
12585
  if (!textarea) return;
12583
12586
  textarea.style.height = "auto";
12584
- textarea.style.height = `${Math.min(textarea.scrollHeight, MAX_INPUT_HEIGHT)}px`;
12587
+ textarea.style.height = `${textarea.scrollHeight}px`;
12585
12588
  }, [value]);
12586
12589
  const addFiles = React13.useCallback(
12587
12590
  (files) => {
@@ -12668,7 +12671,8 @@ var ChatComposer = React13.forwardRef(function ChatComposer2({
12668
12671
  ref,
12669
12672
  () => ({
12670
12673
  addFiles,
12671
- focus: () => textareaRef.current?.focus()
12674
+ focus: () => textareaRef.current?.focus(),
12675
+ getTextarea: () => textareaRef.current
12672
12676
  }),
12673
12677
  [addFiles]
12674
12678
  );
@@ -12752,24 +12756,41 @@ var ChatComposer = React13.forwardRef(function ChatComposer2({
12752
12756
  /* @__PURE__ */ jsx("div", { className: "px-1 pt-1", children: /* @__PURE__ */ jsx(
12753
12757
  "textarea",
12754
12758
  {
12759
+ ...textareaProps,
12755
12760
  ref: textareaRef,
12756
12761
  "data-slot": "chat-composer-input",
12757
12762
  value,
12758
- onChange: (event) => setValue(event.target.value),
12759
- onKeyDown: handleKeyDown,
12760
- onPaste: handlePaste,
12763
+ onChange: (event) => {
12764
+ textareaProps?.onChange?.(event);
12765
+ setValue(event.target.value);
12766
+ },
12767
+ onKeyDown: (event) => {
12768
+ textareaProps?.onKeyDown?.(event);
12769
+ if (event.defaultPrevented) return;
12770
+ handleKeyDown(event);
12771
+ },
12772
+ onPaste: (event) => {
12773
+ textareaProps?.onPaste?.(event);
12774
+ if (event.defaultPrevented) return;
12775
+ handlePaste(event);
12776
+ },
12761
12777
  placeholder,
12762
12778
  disabled,
12763
12779
  autoFocus,
12764
12780
  rows: 1,
12765
12781
  "aria-label": inputLabel,
12782
+ style: {
12783
+ ...textareaProps?.style,
12784
+ maxHeight: typeof maxHeight === "number" ? `${maxHeight}px` : maxHeight
12785
+ },
12766
12786
  className: cn(
12767
12787
  "block w-full resize-none bg-transparent",
12768
12788
  "rounded-lg px-2 pt-2 pb-1 text-sm",
12769
12789
  "text-neutral-900 placeholder:text-neutral-400 dark:text-white dark:placeholder:text-neutral-500",
12770
12790
  // Ring the input itself on focus rather than the whole shell.
12771
12791
  "focus:ring-primary-500 focus:ring-1 focus:outline-none",
12772
- "disabled:cursor-not-allowed"
12792
+ "disabled:cursor-not-allowed",
12793
+ textareaProps?.className
12773
12794
  )
12774
12795
  }
12775
12796
  ) }),