@vielzeug/refine 1.5.3 → 1.7.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/accordion.cjs +1 -1
- package/dist/accordion.cjs.map +1 -1
- package/dist/accordion.js +30 -28
- package/dist/accordion.js.map +1 -1
- package/dist/button-group.cjs.map +1 -1
- package/dist/button-group.js.map +1 -1
- package/dist/button.cjs +1 -1
- package/dist/button.cjs.map +1 -1
- package/dist/button.js +1 -0
- package/dist/button.js.map +1 -1
- package/dist/checkbox-group.cjs +3 -3
- package/dist/checkbox-group.cjs.map +1 -1
- package/dist/checkbox-group.js +51 -58
- package/dist/checkbox-group.js.map +1 -1
- package/dist/combobox.cjs +29 -28
- package/dist/combobox.cjs.map +1 -1
- package/dist/combobox.js +201 -195
- package/dist/combobox.js.map +1 -1
- package/dist/content/card/card.css.cjs +1 -1
- package/dist/content/card/card.css.cjs.map +1 -1
- package/dist/content/card/card.css.js +1 -1
- package/dist/content/card/card.css.js.map +1 -1
- package/dist/content/chat-message/chat-message.css.cjs +1 -1
- package/dist/content/chat-message/chat-message.css.cjs.map +1 -1
- package/dist/content/chat-message/chat-message.css.js +1 -1
- package/dist/content/chat-message/chat-message.css.js.map +1 -1
- package/dist/content/icon/icon.d.ts.map +1 -1
- package/dist/content/index.d.ts +4 -0
- package/dist/content/index.d.ts.map +1 -1
- package/dist/content/list/_list-item-reveal.cjs +2 -0
- package/dist/content/list/_list-item-reveal.cjs.map +1 -0
- package/dist/content/list/_list-item-reveal.d.ts +25 -0
- package/dist/content/list/_list-item-reveal.d.ts.map +1 -0
- package/dist/content/list/_list-item-reveal.js +33 -0
- package/dist/content/list/_list-item-reveal.js.map +1 -0
- package/dist/content/list/list-item.css.cjs +2 -0
- package/dist/content/list/list-item.css.cjs.map +1 -0
- package/dist/content/list/list-item.css.js +6 -0
- package/dist/content/list/list-item.css.js.map +1 -0
- package/dist/content/list/list-item.d.ts +111 -0
- package/dist/content/list/list-item.d.ts.map +1 -0
- package/dist/content/list/list.css.cjs +2 -0
- package/dist/content/list/list.css.cjs.map +1 -0
- package/dist/content/list/list.css.js +6 -0
- package/dist/content/list/list.css.js.map +1 -0
- package/dist/content/list/list.d.ts +93 -0
- package/dist/content/list/list.d.ts.map +1 -0
- package/dist/custom-elements.json +5224 -4621
- package/dist/date-picker.cjs +2 -1
- package/dist/date-picker.cjs.map +1 -1
- package/dist/date-picker.js +2 -0
- package/dist/date-picker.js.map +1 -1
- package/dist/disclosure/tab-item/tab-item.d.ts.map +1 -1
- package/dist/disclosure/tab-panel/tab-panel.d.ts.map +1 -1
- package/dist/disclosure/tabs/tabs.d.ts.map +1 -1
- package/dist/drawer.cjs +1 -1
- package/dist/drawer.cjs.map +1 -1
- package/dist/drawer.js +47 -48
- package/dist/drawer.js.map +1 -1
- package/dist/file-input.cjs +111 -45
- package/dist/file-input.cjs.map +1 -1
- package/dist/file-input.js +216 -156
- package/dist/file-input.js.map +1 -1
- package/dist/headless/aria-reflection.cjs +2 -0
- package/dist/headless/aria-reflection.cjs.map +1 -0
- package/dist/headless/aria-reflection.d.ts +27 -0
- package/dist/headless/aria-reflection.d.ts.map +1 -0
- package/dist/headless/aria-reflection.js +18 -0
- package/dist/headless/aria-reflection.js.map +1 -0
- package/dist/headless/checkable.cjs +1 -1
- package/dist/headless/checkable.cjs.map +1 -1
- package/dist/headless/checkable.d.ts +2 -10
- package/dist/headless/checkable.d.ts.map +1 -1
- package/dist/headless/checkable.js +29 -29
- package/dist/headless/checkable.js.map +1 -1
- package/dist/headless/choice-field.cjs +1 -1
- package/dist/headless/choice-field.cjs.map +1 -1
- package/dist/headless/choice-field.d.ts +2 -7
- package/dist/headless/choice-field.d.ts.map +1 -1
- package/dist/headless/choice-field.js +37 -37
- package/dist/headless/choice-field.js.map +1 -1
- package/dist/headless/field-base.cjs +1 -1
- package/dist/headless/field-base.cjs.map +1 -1
- package/dist/headless/field-base.d.ts +17 -0
- package/dist/headless/field-base.d.ts.map +1 -1
- package/dist/headless/field-base.js +21 -6
- package/dist/headless/field-base.js.map +1 -1
- package/dist/headless/focus.cjs +1 -1
- package/dist/headless/focus.cjs.map +1 -1
- package/dist/headless/focus.d.ts +7 -0
- package/dist/headless/focus.d.ts.map +1 -1
- package/dist/headless/focus.js +6 -6
- package/dist/headless/focus.js.map +1 -1
- package/dist/headless/index.d.ts +4 -2
- package/dist/headless/index.d.ts.map +1 -1
- package/dist/headless/nav.cjs +1 -1
- package/dist/headless/nav.cjs.map +1 -1
- package/dist/headless/nav.d.ts +12 -0
- package/dist/headless/nav.d.ts.map +1 -1
- package/dist/headless/nav.js +68 -50
- package/dist/headless/nav.js.map +1 -1
- package/dist/headless/overlay.cjs +1 -1
- package/dist/headless/overlay.cjs.map +1 -1
- package/dist/headless/overlay.d.ts +2 -0
- package/dist/headless/overlay.d.ts.map +1 -1
- package/dist/headless/overlay.js +8 -5
- package/dist/headless/overlay.js.map +1 -1
- package/dist/headless/ref-callback.cjs +2 -0
- package/dist/headless/ref-callback.cjs.map +1 -0
- package/dist/headless/ref-callback.d.ts +26 -0
- package/dist/headless/ref-callback.d.ts.map +1 -0
- package/dist/headless/ref-callback.js +13 -0
- package/dist/headless/ref-callback.js.map +1 -0
- package/dist/headless/swipe.cjs +1 -1
- package/dist/headless/swipe.cjs.map +1 -1
- package/dist/headless/swipe.d.ts +2 -0
- package/dist/headless/swipe.d.ts.map +1 -1
- package/dist/headless/swipe.js +26 -21
- package/dist/headless/swipe.js.map +1 -1
- package/dist/headless.cjs +1 -1
- package/dist/headless.js +28 -26
- package/dist/icon.cjs +1 -1
- package/dist/icon.cjs.map +1 -1
- package/dist/icon.js +36 -38
- package/dist/icon.js.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +63 -61
- package/dist/input.cjs +29 -26
- package/dist/input.cjs.map +1 -1
- package/dist/input.js +91 -79
- package/dist/input.js.map +1 -1
- package/dist/inputs/button/button.css.cjs +1 -1
- package/dist/inputs/button/button.css.cjs.map +1 -1
- package/dist/inputs/button/button.css.js +1 -1
- package/dist/inputs/button/button.css.js.map +1 -1
- package/dist/inputs/button/button.d.ts +8 -0
- package/dist/inputs/button/button.d.ts.map +1 -1
- package/dist/inputs/checkbox/checkbox.css.cjs +1 -1
- package/dist/inputs/checkbox/checkbox.css.cjs.map +1 -1
- package/dist/inputs/checkbox/checkbox.css.js +1 -1
- package/dist/inputs/checkbox/checkbox.css.js.map +1 -1
- package/dist/inputs/combobox/combobox.d.ts +1 -0
- package/dist/inputs/combobox/combobox.d.ts.map +1 -1
- package/dist/inputs/date-picker/date-picker.css.cjs +1 -1
- package/dist/inputs/date-picker/date-picker.css.cjs.map +1 -1
- package/dist/inputs/date-picker/date-picker.css.js +1 -1
- package/dist/inputs/date-picker/date-picker.css.js.map +1 -1
- package/dist/inputs/date-picker/date-picker.d.ts +6 -0
- package/dist/inputs/date-picker/date-picker.d.ts.map +1 -1
- package/dist/inputs/file-input/file-input-upload.cjs +2 -0
- package/dist/inputs/file-input/file-input-upload.cjs.map +1 -0
- package/dist/inputs/file-input/file-input-upload.d.ts +76 -0
- package/dist/inputs/file-input/file-input-upload.d.ts.map +1 -0
- package/dist/inputs/file-input/file-input-upload.js +145 -0
- package/dist/inputs/file-input/file-input-upload.js.map +1 -0
- package/dist/inputs/file-input/file-input.css.cjs +1 -1
- package/dist/inputs/file-input/file-input.css.cjs.map +1 -1
- package/dist/inputs/file-input/file-input.css.js +1 -1
- package/dist/inputs/file-input/file-input.css.js.map +1 -1
- package/dist/inputs/file-input/file-input.d.ts +54 -1
- package/dist/inputs/file-input/file-input.d.ts.map +1 -1
- package/dist/inputs/input/input.css.cjs +1 -1
- package/dist/inputs/input/input.css.cjs.map +1 -1
- package/dist/inputs/input/input.css.js +1 -1
- package/dist/inputs/input/input.css.js.map +1 -1
- package/dist/inputs/input/input.d.ts +13 -0
- package/dist/inputs/input/input.d.ts.map +1 -1
- package/dist/inputs/message-composer/message-composer.css.cjs +1 -1
- package/dist/inputs/message-composer/message-composer.css.cjs.map +1 -1
- package/dist/inputs/message-composer/message-composer.css.js +1 -1
- package/dist/inputs/message-composer/message-composer.css.js.map +1 -1
- package/dist/inputs/message-composer/message-composer.d.ts +7 -0
- package/dist/inputs/message-composer/message-composer.d.ts.map +1 -1
- package/dist/inputs/number-input/number-input.css.cjs +1 -1
- package/dist/inputs/number-input/number-input.css.cjs.map +1 -1
- package/dist/inputs/number-input/number-input.css.js +1 -1
- package/dist/inputs/number-input/number-input.css.js.map +1 -1
- package/dist/inputs/number-input/number-input.d.ts +15 -0
- package/dist/inputs/number-input/number-input.d.ts.map +1 -1
- package/dist/inputs/otp-input/otp-input.css.cjs +1 -1
- package/dist/inputs/otp-input/otp-input.css.cjs.map +1 -1
- package/dist/inputs/otp-input/otp-input.css.js +1 -1
- package/dist/inputs/otp-input/otp-input.css.js.map +1 -1
- package/dist/inputs/radio/radio.d.ts.map +1 -1
- package/dist/inputs/select/select.d.ts +1 -0
- package/dist/inputs/select/select.d.ts.map +1 -1
- package/dist/inputs/shared/index.d.ts +1 -1
- package/dist/inputs/shared/index.d.ts.map +1 -1
- package/dist/inputs/shared/templates.cjs +26 -3
- package/dist/inputs/shared/templates.cjs.map +1 -1
- package/dist/inputs/shared/templates.d.ts +20 -0
- package/dist/inputs/shared/templates.d.ts.map +1 -1
- package/dist/inputs/shared/templates.js +29 -5
- package/dist/inputs/shared/templates.js.map +1 -1
- package/dist/inputs/switch/switch.css.cjs +1 -1
- package/dist/inputs/switch/switch.css.cjs.map +1 -1
- package/dist/inputs/switch/switch.css.js +1 -1
- package/dist/inputs/switch/switch.css.js.map +1 -1
- package/dist/inputs/switch/switch.d.ts.map +1 -1
- package/dist/inputs/textarea/textarea.css.cjs +1 -1
- package/dist/inputs/textarea/textarea.css.cjs.map +1 -1
- package/dist/inputs/textarea/textarea.css.js +1 -1
- package/dist/inputs/textarea/textarea.css.js.map +1 -1
- package/dist/inputs/textarea/textarea.d.ts +14 -0
- package/dist/inputs/textarea/textarea.d.ts.map +1 -1
- package/dist/inputs/time-picker/time-picker.css.cjs +1 -1
- package/dist/inputs/time-picker/time-picker.css.cjs.map +1 -1
- package/dist/inputs/time-picker/time-picker.css.js +1 -1
- package/dist/inputs/time-picker/time-picker.css.js.map +1 -1
- package/dist/inputs/time-picker/time-picker.d.ts +6 -0
- package/dist/inputs/time-picker/time-picker.d.ts.map +1 -1
- package/dist/list-item.cjs +22 -0
- package/dist/list-item.cjs.map +1 -0
- package/dist/list-item.js +91 -0
- package/dist/list-item.js.map +1 -0
- package/dist/list.cjs +2 -0
- package/dist/list.cjs.map +1 -0
- package/dist/list.js +64 -0
- package/dist/list.js.map +1 -0
- package/dist/menu.cjs +4 -4
- package/dist/menu.cjs.map +1 -1
- package/dist/menu.js +60 -59
- package/dist/menu.js.map +1 -1
- package/dist/message-composer.cjs +14 -20
- package/dist/message-composer.cjs.map +1 -1
- package/dist/message-composer.js +63 -64
- package/dist/message-composer.js.map +1 -1
- package/dist/number-input.cjs +5 -3
- package/dist/number-input.cjs.map +1 -1
- package/dist/number-input.js +8 -4
- package/dist/number-input.js.map +1 -1
- package/dist/otp-input.cjs +9 -9
- package/dist/otp-input.cjs.map +1 -1
- package/dist/otp-input.js +70 -62
- package/dist/otp-input.js.map +1 -1
- package/dist/overlay/menu/menu-item.css.cjs +1 -1
- package/dist/overlay/menu/menu-item.css.cjs.map +1 -1
- package/dist/overlay/menu/menu-item.css.js +1 -1
- package/dist/overlay/menu/menu-item.css.js.map +1 -1
- package/dist/overlay/menu/menu-separator.css.cjs +1 -1
- package/dist/overlay/menu/menu-separator.css.cjs.map +1 -1
- package/dist/overlay/menu/menu-separator.css.js +1 -1
- package/dist/overlay/menu/menu-separator.css.js.map +1 -1
- package/dist/overlay/menu/menu.css.cjs +1 -1
- package/dist/overlay/menu/menu.css.cjs.map +1 -1
- package/dist/overlay/menu/menu.css.js +1 -1
- package/dist/overlay/menu/menu.css.js.map +1 -1
- package/dist/overlay/shared/use-dialog.cjs +1 -1
- package/dist/overlay/shared/use-dialog.cjs.map +1 -1
- package/dist/overlay/shared/use-dialog.d.ts.map +1 -1
- package/dist/overlay/shared/use-dialog.js +7 -6
- package/dist/overlay/shared/use-dialog.js.map +1 -1
- package/dist/radio-group.cjs +3 -3
- package/dist/radio-group.cjs.map +1 -1
- package/dist/radio-group.js +64 -70
- package/dist/radio-group.js.map +1 -1
- package/dist/radio.cjs +4 -4
- package/dist/radio.cjs.map +1 -1
- package/dist/radio.js +58 -58
- package/dist/radio.js.map +1 -1
- package/dist/rating.cjs.map +1 -1
- package/dist/rating.js.map +1 -1
- package/dist/refine.cjs +426 -233
- package/dist/refine.cjs.map +1 -1
- package/dist/refine.iife.js +431 -238
- package/dist/refine.iife.js.map +1 -1
- package/dist/refine.js +452 -259
- package/dist/refine.js.map +1 -1
- package/dist/select.cjs +21 -21
- package/dist/select.cjs.map +1 -1
- package/dist/select.js +135 -127
- package/dist/select.js.map +1 -1
- package/dist/shared/size-presets.cjs +1 -1
- package/dist/shared/size-presets.cjs.map +1 -1
- package/dist/shared/size-presets.d.ts +74 -0
- package/dist/shared/size-presets.d.ts.map +1 -1
- package/dist/shared/size-presets.js +48 -1
- package/dist/shared/size-presets.js.map +1 -1
- package/dist/shared/types.d.ts +5 -0
- package/dist/shared/types.d.ts.map +1 -1
- package/dist/styles/index.cjs +1 -1
- package/dist/styles/index.cjs.map +1 -1
- package/dist/styles/index.d.ts +1 -0
- package/dist/styles/index.d.ts.map +1 -1
- package/dist/styles/index.js +5 -4
- package/dist/styles/index.js.map +1 -1
- package/dist/styles/mixins/field-variants.css.cjs +85 -0
- package/dist/styles/mixins/field-variants.css.cjs.map +1 -0
- package/dist/styles/mixins/field-variants.css.d.ts +66 -0
- package/dist/styles/mixins/field-variants.css.d.ts.map +1 -0
- package/dist/styles/mixins/field-variants.css.js +90 -0
- package/dist/styles/mixins/field-variants.css.js.map +1 -0
- package/dist/switch.cjs +3 -3
- package/dist/switch.cjs.map +1 -1
- package/dist/switch.js +38 -36
- package/dist/switch.js.map +1 -1
- package/dist/tab-item.cjs +8 -8
- package/dist/tab-item.cjs.map +1 -1
- package/dist/tab-item.js +38 -28
- package/dist/tab-item.js.map +1 -1
- package/dist/tab-panel.cjs +7 -7
- package/dist/tab-panel.cjs.map +1 -1
- package/dist/tab-panel.js +34 -26
- package/dist/tab-panel.js.map +1 -1
- package/dist/tabs.cjs +4 -4
- package/dist/tabs.cjs.map +1 -1
- package/dist/tabs.js +64 -60
- package/dist/tabs.js.map +1 -1
- package/dist/textarea.cjs +15 -18
- package/dist/textarea.cjs.map +1 -1
- package/dist/textarea.js +83 -74
- package/dist/textarea.js.map +1 -1
- package/dist/time-picker.cjs +34 -31
- package/dist/time-picker.cjs.map +1 -1
- package/dist/time-picker.js +121 -109
- package/dist/time-picker.js.map +1 -1
- package/package.json +21 -9
- package/dist/headless/dialog-focus.cjs +0 -2
- package/dist/headless/dialog-focus.cjs.map +0 -1
- package/dist/headless/dialog-focus.d.ts +0 -40
- package/dist/headless/dialog-focus.d.ts.map +0 -1
- package/dist/headless/dialog-focus.js +0 -22
- package/dist/headless/dialog-focus.js.map +0 -1
- package/dist/headless/focus-trap.cjs +0 -2
- package/dist/headless/focus-trap.cjs.map +0 -1
- package/dist/headless/focus-trap.d.ts +0 -45
- package/dist/headless/focus-trap.d.ts.map +0 -1
- package/dist/headless/focus-trap.js +0 -51
- package/dist/headless/focus-trap.js.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-composer.cjs","names":[],"sources":["../src/inputs/message-composer/message-composer.ts"],"sourcesContent":["import { define, html, inject, prop, ref, bind, onCleanup, onElement, useEmit, useSlots } from '@vielzeug/ore';\nimport { live } from '@vielzeug/ore/directives';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed, watch } from '@vielzeug/ripple';\n\nimport type { ComponentSize, ThemeColor, VisualVariant } from '../../types';\n\nimport {\n counterClassName,\n createAutoResize,\n createComposerControl,\n createTextField,\n lifecycleSignal,\n type SendShortcut,\n} from '../../headless';\nimport {\n disablableBundle,\n loadableBundle,\n MESSAGE_COMPOSER_SIZE_PRESET,\n sizableBundle,\n themableBundle,\n} from '../../shared';\nimport {\n colorThemeMixin,\n coarsePointerMixin,\n disabledLoadingMixin,\n forcedColorsFocusMixin,\n forcedColorsMixin,\n reducedMotionMixin,\n sizeVariantMixin,\n} from '../../styles';\nimport { errorAttr } from '../shared/field-binding';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport '../../content/icon/icon';\nimport '../button/button';\nimport componentStyles from './message-composer.css?inline';\n\nexport type { SendShortcut } from '../../headless';\n\nconst DEFAULT_SEND_LABEL = 'Send message';\nconst SEND_ICON = 'arrow-up';\n\n/** Events emitted by the message composer */\nexport type OreMessageComposerEvents = {\n /** Fired on every keystroke with the current value. */\n input: { originalEvent: Event; value: string };\n /**\n * Fired for a send attempt (the resolved `send-shortcut` or the send button) while the\n * composer isn't blank/disabled/loading. Cancelable — call `preventDefault()` to keep the\n * current text in the field instead of the default clear + refocus.\n */\n send: { originalEvent: KeyboardEvent | MouseEvent; value: string };\n};\n\n/** Message composer properties */\nexport type OreMessageComposerProps = {\n /** Clear the value and refocus after a non-cancelled `send` (default `true`) */\n 'clear-on-send'?: boolean;\n /** Theme color (card focus ring + default send button color) */\n color?: ThemeColor;\n /** Disable the whole composer (field, slots, and send action) */\n disabled?: boolean;\n /** Error message shown below the field */\n error?: string;\n /** Stretch the composer to the full width of its container */\n fullwidth?: boolean;\n /** Helper text shown below the field */\n helper?: string;\n /** Accessible name for the field — never rendered visually, only as `aria-label` */\n label?: string;\n /** Blocks further sends (e.g. a send is already in flight) without disabling editing */\n loading?: boolean;\n /** Maximum character count; shows a counter */\n maxlength?: number;\n /** Form field name */\n name?: string;\n /** Placeholder text */\n placeholder?: string;\n /** Make the field read-only */\n readonly?: boolean;\n /**\n * JS-only callback fired with the inner `<textarea>` element when it mounts, and with\n * `null` when it unmounts. Set as a JS property: `composer.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLTextAreaElement | null) => void) | null;\n /** Require a non-blank value for `<ore-form>` validation */\n required?: boolean;\n /** Number of visible rows before auto-resize grows the field */\n rows?: number;\n /** Lucide icon name for the default send button (default `'arrow-up'`) */\n 'send-icon'?: string;\n /** Accessible label for the send button (default `'Send message'`) */\n 'send-label'?: string;\n /** Keyboard shortcut that sends: 'enter' (Shift+Enter for a newline) or 'mod+enter' (Enter always inserts a newline; Ctrl/Cmd+Enter sends) */\n 'send-shortcut'?: SendShortcut;\n /** Component size */\n size?: ComponentSize;\n /** Current text value */\n value?: string;\n /** Visual variant of the card — same variant set as `ore-textarea`, applied to the card. */\n variant?: Exclude<VisualVariant, 'frost' | 'text'>;\n};\n\n/**\n * A message/comment composer — a card with an auto-resizing field on top and a toolbar row\n * below it, built directly on the same headless primitives as `ore-textarea` (`createTextField`,\n * `createAutoResize`) rather than composing `ore-textarea` itself. Nesting a fully-styled sibling\n * component and suppressing most of its chrome (as an earlier version of this component did) is\n * a leaky composition — this owns its single `<textarea>` outright, so there's exactly one\n * implementation of the field's appearance to reason about, not two fighting each other.\n *\n * Handles the send gesture (Enter to send, Shift+Enter for a newline, or a Ctrl/Cmd+Enter\n * alternative), IME-safe composition, and clear-and-refocus after sending.\n *\n * @element ore-message-composer\n *\n * @attr {string} value - Current text value\n * @attr {string} placeholder - Placeholder text\n * @attr {string} label - Accessible name for the field (not rendered visually)\n * @attr {string} name - Form field name\n * @attr {string} helper - Helper text shown below the field\n * @attr {string} error - Error message shown below the field\n * @attr {boolean} disabled - Disable the whole composer\n * @attr {boolean} readonly - Read-only mode\n * @attr {boolean} required - Require a non-blank value for `<ore-form>` validation\n * @attr {boolean} loading - Blocks further sends without disabling editing\n * @attr {number} maxlength - Max character count; shows a counter\n * @attr {number} rows - Visible rows before auto-resize grows the field (default 1)\n * @attr {string} color - Theme color: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'\n * @attr {string} variant - Visual variant of the card: 'solid' | 'flat' | 'bordered' | 'outline' | 'ghost'\n * @attr {string} size - 'sm' | 'md' | 'lg'\n * @attr {boolean} fullwidth - Stretch to the full width of the container\n * @attr {string} send-icon - Lucide icon name for the default send button (default 'arrow-up')\n * @attr {string} send-label - Accessible label for the send button (default 'Send message')\n * @attr {string} send-shortcut - 'enter' (default) | 'mod+enter'\n * @attr {boolean} clear-on-send - Clear the value and refocus after a non-cancelled send (default true)\n *\n * @fires input - Fired on every keystroke. detail: { value, originalEvent }\n * @fires send - Fired on a send attempt. Cancelable. detail: { value, originalEvent }\n *\n * @slot prefix - Content at the start of the toolbar row (e.g. an attach menu)\n * @slot suffix - Content at the end of the toolbar row, before the send button (e.g. a model picker)\n * @slot send - Replaces the default send button entirely — the only supported way to customize it\n *\n * @cssprop --message-composer-bg - Card background color\n * @cssprop --message-composer-border-color - Card border color\n * @cssprop --message-composer-radius - Card border radius\n * @cssprop --message-composer-padding - Card inner padding\n * @cssprop --message-composer-gap - Gap between the field/toolbar rows and between toolbar items\n * @cssprop --message-composer-placeholder-color - Field placeholder text color\n * @cssprop --message-composer-min-height - Minimum field height (default one line)\n * @cssprop --message-composer-hover-bg - Card background on hover (flat/ghost variants)\n * @cssprop --message-composer-hover-border-color - Card border on hover (flat/bordered variants)\n * @cssprop --message-composer-focus-bg - Card background when focused (flat variant)\n * @cssprop --message-composer-focus-border-color - Card border when focused (flat variant)\n *\n * @part composer - Root card container\n * @part field - The native `<textarea>` element\n * @part helper - Helper text element\n * @part error - Error text element (`role=\"alert\"`)\n * @part toolbar - Toolbar row below the field\n * @part toolbar-start - Toolbar group holding the `prefix` slot\n * @part toolbar-end - Toolbar group holding the `suffix` slot and the send button\n * @part send-button - The default send button (absent when the `send` slot is used)\n *\n * @example\n * ```html\n * <ore-message-composer placeholder=\"Message…\" send-shortcut=\"mod+enter\"></ore-message-composer>\n * ```\n */\nexport const MESSAGE_COMPOSER_TAG = 'ore-message-composer' as const;\ndefine<OreMessageComposerProps>(MESSAGE_COMPOSER_TAG, {\n formAssociated: true,\n props: {\n ...themableBundle,\n ...sizableBundle,\n ...disablableBundle,\n ...loadableBundle,\n 'clear-on-send': prop.bool(true),\n error: prop.string(),\n fullwidth: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n maxlength: prop.json(undefined as number | undefined),\n name: prop.string(),\n placeholder: prop.string(),\n readonly: prop.bool(false),\n ref: prop.json(undefined as ((el: HTMLTextAreaElement | null) => void) | null | undefined),\n required: prop.bool(false),\n rows: prop.json(undefined as number | undefined),\n 'send-icon': prop.string(),\n 'send-label': prop.string(),\n 'send-shortcut': prop.oneOf(['enter', 'mod+enter'] as const, 'enter'),\n value: prop.string(),\n variant: prop.string<Exclude<VisualVariant, 'frost' | 'text'>>(),\n },\n setup(props) {\n const emit = useEmit<OreMessageComposerEvents>();\n const slots = useSlots<'prefix' | 'send' | 'suffix'>();\n\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n\n const abortSignal = lifecycleSignal(onCleanup);\n const textareaRef = ref<HTMLTextAreaElement>();\n const autoResize = createAutoResize();\n\n const tf = createTextField({\n disabled: isDisabled,\n error: props.error,\n helper: props.helper,\n maxLength: props.maxlength,\n onInput: (event, value) => emit('input', { originalEvent: event, value }),\n prefix: 'composer',\n readonly: props.readonly,\n required: props.required,\n signal: abortSignal,\n validateOn: formCtx?.validateOn,\n value: props.value,\n });\n\n // Directly form-associated now that the field is owned here rather than borrowed from a\n // nested `ore-textarea` (which previously registered with the ancestor `<form>` on this\n // component's behalf).\n tf.attachFormField(\n useField<string>({\n disabled: tf.disabled,\n onReset: () => {\n tf.reset();\n autoResize.recompute();\n },\n toFormValue: (v) => v,\n validationMessage: tf.validationMessage,\n validity: tf.validity,\n value: tf.value,\n }),\n );\n\n function attemptSend(event: KeyboardEvent | MouseEvent): void {\n const notPrevented = emit('send', { originalEvent: event, value: tf.value.value.trim() });\n\n // `preventDefault()` on `send` means \"keep the current text — skip the default clear\n // + refocus\" (see the event's own doc comment): both halves of that default are gated on\n // the same condition, not just the clear.\n if (notPrevented && props['clear-on-send'].value !== false) {\n tf.clear();\n autoResize.recompute();\n textareaRef.value?.focus();\n }\n }\n\n const composer = createComposerControl({\n disabled: isDisabled,\n loading: computed(() => Boolean(props.loading.value)),\n onSend: attemptSend,\n sendShortcut: props['send-shortcut'],\n value: tf.value,\n });\n\n onElement(textareaRef, (textareaEl) => {\n const unwireField = tf.wire(textareaEl);\n const unwireAutoResize = autoResize.wire(textareaEl);\n const handleKeydown = (e: KeyboardEvent) => composer.handleKeydown(e);\n\n textareaEl.addEventListener('keydown', handleKeydown);\n\n // Immediate fire for when the prop is already set on mount.\n props.ref.value?.(textareaEl);\n\n // Reactive watcher so that if props.ref is set *after* the inner <textarea> mounts\n // (e.g. a parent sets it via a ref callback after render), the new callback still\n // receives the live element.\n const refSub = watch(props.ref, (cb) => {\n cb?.(textareaEl);\n });\n\n return () => {\n textareaEl.removeEventListener('keydown', handleKeydown);\n unwireField();\n unwireAutoResize();\n refSub.dispose();\n props.ref.value?.(null);\n };\n });\n\n bind({\n attr: {\n error: errorAttr(tf.errorText),\n size: fCtxProps.size,\n variant: fCtxProps.variant,\n },\n });\n\n const counterClass = () => counterClassName(tf.counter?.value);\n const counterHidden = () => !tf.counter;\n const counterText = () => tf.counter?.value.counterText.replace(' / ', '/') ?? '';\n const helperHidden = () => !!tf.errorText.value || !tf.helperText.value;\n const errorHidden = () => !tf.errorText.value;\n\n return html`\n <div class=\"composer\" part=\"composer\">\n <textarea\n class=\"field\"\n part=\"field\"\n ref=\"${textareaRef}\"\n :rows=\"${() => props.rows.value ?? 1}\"\n :name=\"${() => props.name.value ?? ''}\"\n :placeholder=\"${() => props.placeholder.value ?? 'Message…'}\"\n :maxlength=\"${() => props.maxlength.value}\"\n ?disabled=\"${isDisabled}\"\n ?readonly=\"${() => Boolean(props.readonly.value)}\"\n ?required=\"${() => Boolean(props.required.value)}\"\n :value=\"${live(tf.value)}\"\n :aria-label=\"${() => props.label.value || 'Message'}\"\n :aria-keyshortcuts=\"${composer.keyShortcutsHint}\"\n :aria-describedby=\"${tf.ariaDescribedBy}\"\n :aria-errormessage=\"${tf.ariaErrorMessage}\"\n :aria-invalid=\"${tf.ariaInvalid}\"></textarea>\n <span class=\"${counterClass}\" aria-live=\"polite\" ?hidden=\"${counterHidden}\">${counterText}</span>\n <div id=\"${tf.assistiveId}\" class=\"helper-text\" aria-live=\"polite\" part=\"helper\" ?hidden=\"${helperHidden}\">\n ${() => tf.helperText.value}\n </div>\n <div id=\"${tf.errorId}\" class=\"helper-text\" role=\"alert\" part=\"error\" ?hidden=\"${errorHidden}\">\n ${() => tf.errorText.value}\n </div>\n <div class=\"toolbar\" part=\"toolbar\">\n <div class=\"toolbar-start\" part=\"toolbar-start\">\n <slot name=\"prefix\"></slot>\n </div>\n <div class=\"toolbar-end\" part=\"toolbar-end\">\n <slot name=\"suffix\"></slot>\n <slot name=\"send\"></slot>\n ${() =>\n slots.has('send').value\n ? ''\n : html`<ore-button\n class=\"send-btn\"\n part=\"send-button\"\n type=\"button\"\n icon-only\n variant=\"solid\"\n :color=\"${() => props.color.value || 'primary'}\"\n :size=\"${fCtxProps.size}\"\n :label=\"${() => props['send-label'].value || DEFAULT_SEND_LABEL}\"\n ?loading=\"${() => Boolean(props.loading.value)}\"\n ?disabled=\"${() => !composer.canSend.value}\"\n @click=\"${(e: MouseEvent) => composer.send(e)}\">\n <ore-icon name=\"${() => props['send-icon'].value || SEND_ICON}\" size=\"16\"></ore-icon>\n </ore-button>`}\n </div>\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n colorThemeMixin,\n coarsePointerMixin,\n reducedMotionMixin,\n disabledLoadingMixin,\n forcedColorsMixin,\n forcedColorsFocusMixin('.field'),\n sizeVariantMixin(MESSAGE_COMPOSER_SIZE_PRESET),\n componentStyles,\n ],\n});\n"],"mappings":"wyBAuCA,IAAM,EAAqB,eACrB,EAAY,WAkIL,EAAuB,oCACJ,EAAsB,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version":3,"file":"message-composer.cjs","names":[],"sources":["../src/inputs/message-composer/message-composer.ts"],"sourcesContent":["import { define, html, inject, prop, ref, bind, onCleanup, onElement, useEmit, useSlots } from '@vielzeug/ore';\nimport { live } from '@vielzeug/ore/directives';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed } from '@vielzeug/ripple';\n\nimport type { ComponentSize, ThemeColor, VisualVariant } from '../../types';\n\nimport {\n bindRefCallback,\n createAutoResize,\n createComposerControl,\n createTextField,\n lifecycleSignal,\n type SendShortcut,\n} from '../../headless';\nimport {\n disablableBundle,\n loadableBundle,\n MESSAGE_COMPOSER_SIZE_PRESET,\n sizableBundle,\n themableBundle,\n} from '../../shared';\nimport {\n colorThemeMixin,\n coarsePointerMixin,\n disabledLoadingMixin,\n fieldVariantMixin,\n forcedColorsFocusMixin,\n forcedColorsMixin,\n reducedMotionMixin,\n sizeVariantMixin,\n} from '../../styles';\nimport { errorAttr } from '../shared/field-binding';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport { renderFieldStatusRegion, renderStatusIcon } from '../shared/templates';\nimport '../../content/icon/icon';\nimport '../button/button';\nimport componentStyles from './message-composer.css?inline';\n\nexport type { SendShortcut } from '../../headless';\n\nconst DEFAULT_SEND_LABEL = 'Send message';\nconst SEND_ICON = 'arrow-up';\n\n/** Events emitted by the message composer */\nexport type OreMessageComposerEvents = {\n /** Fired on every keystroke with the current value. */\n input: { originalEvent: Event; value: string };\n /**\n * Fired for a send attempt (the resolved `send-shortcut` or the send button) while the\n * composer isn't blank/disabled/loading. Cancelable — call `preventDefault()` to keep the\n * current text in the field instead of the default clear + refocus.\n */\n send: { originalEvent: KeyboardEvent | MouseEvent; value: string };\n};\n\n/** Message composer properties */\nexport type OreMessageComposerProps = {\n /** Clear the value and refocus after a non-cancelled `send` (default `true`) */\n 'clear-on-send'?: boolean;\n /** Theme color (card focus ring + default send button color) */\n color?: ThemeColor;\n /** Disable the whole composer (field, slots, and send action) */\n disabled?: boolean;\n /** Error message shown below the field */\n error?: string;\n /** Stretch the composer to the full width of its container */\n fullwidth?: boolean;\n /** Helper text shown below the field */\n helper?: string;\n /** Accessible name for the field — never rendered visually, only as `aria-label` */\n label?: string;\n /** Blocks further sends (e.g. a send is already in flight) without disabling editing */\n loading?: boolean;\n /** Maximum character count; shows a counter */\n maxlength?: number;\n /** Form field name */\n name?: string;\n /** Placeholder text */\n placeholder?: string;\n /** Make the field read-only */\n readonly?: boolean;\n /**\n * JS-only callback fired with the inner `<textarea>` element when it mounts, and with\n * `null` when it unmounts. Set as a JS property: `composer.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLTextAreaElement | null) => void) | null;\n /** Require a non-blank value for `<ore-form>` validation */\n required?: boolean;\n /** Number of visible rows before auto-resize grows the field */\n rows?: number;\n /** Lucide icon name for the default send button (default `'arrow-up'`) */\n 'send-icon'?: string;\n /** Accessible label for the send button (default `'Send message'`) */\n 'send-label'?: string;\n /** Keyboard shortcut that sends: 'enter' (Shift+Enter for a newline) or 'mod+enter' (Enter always inserts a newline; Ctrl/Cmd+Enter sends) */\n 'send-shortcut'?: SendShortcut;\n /** Component size */\n size?: ComponentSize;\n /**\n * Shows an inline green check icon inside the field to confirm the value has\n * passed validation. Ignored while `error` is set — an error always wins.\n */\n success?: boolean;\n /** Current text value */\n value?: string;\n /** Visual variant of the card — same variant set as `ore-textarea`, applied to the card. */\n variant?: Exclude<VisualVariant, 'frost' | 'text'>;\n};\n\n/**\n * A message/comment composer — a card with an auto-resizing field on top and a toolbar row\n * below it, built directly on the same headless primitives as `ore-textarea` (`createTextField`,\n * `createAutoResize`) rather than composing `ore-textarea` itself. Nesting a fully-styled sibling\n * component and suppressing most of its chrome (as an earlier version of this component did) is\n * a leaky composition — this owns its single `<textarea>` outright, so there's exactly one\n * implementation of the field's appearance to reason about, not two fighting each other.\n *\n * Handles the send gesture (Enter to send, Shift+Enter for a newline, or a Ctrl/Cmd+Enter\n * alternative), IME-safe composition, and clear-and-refocus after sending.\n *\n * @element ore-message-composer\n *\n * @attr {string} value - Current text value\n * @attr {string} placeholder - Placeholder text\n * @attr {string} label - Accessible name for the field (not rendered visually)\n * @attr {string} name - Form field name\n * @attr {string} helper - Helper text shown below the field\n * @attr {string} error - Error message shown below the field\n * @attr {boolean} success - Show an inline success check icon (suppressed while `error` is set)\n * @attr {boolean} disabled - Disable the whole composer\n * @attr {boolean} readonly - Read-only mode\n * @attr {boolean} required - Require a non-blank value for `<ore-form>` validation\n * @attr {boolean} loading - Blocks further sends without disabling editing\n * @attr {number} maxlength - Max character count; shows a counter\n * @attr {number} rows - Visible rows before auto-resize grows the field (default 1)\n * @attr {string} color - Theme color: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'\n * @attr {string} variant - Visual variant of the card: 'solid' | 'flat' | 'bordered' | 'outline' | 'ghost'\n * @attr {string} size - 'sm' | 'md' | 'lg'\n * @attr {boolean} fullwidth - Stretch to the full width of the container\n * @attr {string} send-icon - Lucide icon name for the default send button (default 'arrow-up')\n * @attr {string} send-label - Accessible label for the send button (default 'Send message')\n * @attr {string} send-shortcut - 'enter' (default) | 'mod+enter'\n * @attr {boolean} clear-on-send - Clear the value and refocus after a non-cancelled send (default true)\n *\n * @fires input - Fired on every keystroke. detail: { value, originalEvent }\n * @fires send - Fired on a send attempt. Cancelable. detail: { value, originalEvent }\n *\n * @slot prefix - Content at the start of the toolbar row (e.g. an attach menu)\n * @slot suffix - Content at the end of the toolbar row, before the send button (e.g. a model picker)\n * @slot send - Replaces the default send button entirely — the only supported way to customize it\n *\n * @cssprop --message-composer-bg - Card background color\n * @cssprop --message-composer-border-color - Card border color\n * @cssprop --message-composer-radius - Card border radius\n * @cssprop --message-composer-padding - Card inner padding\n * @cssprop --message-composer-gap - Gap between the field/toolbar rows and between toolbar items\n * @cssprop --message-composer-placeholder-color - Field placeholder text color\n * @cssprop --message-composer-min-height - Minimum field height (default one line)\n * @cssprop --message-composer-hover-bg - Card background on hover (flat/ghost variants)\n * @cssprop --message-composer-hover-border-color - Card border on hover (flat/bordered variants)\n * @cssprop --message-composer-focus-bg - Card background when focused (flat variant)\n * @cssprop --message-composer-focus-border-color - Card border when focused (flat variant)\n *\n * @part composer - Root card container\n * @part field - The native `<textarea>` element\n * @part status-icon - The inline error/success icon shown inside the field\n * @part helper - Helper text element\n * @part error - Error text element (`role=\"alert\"`)\n * @part toolbar - Toolbar row below the field\n * @part toolbar-start - Toolbar group holding the `prefix` slot\n * @part toolbar-end - Toolbar group holding the `suffix` slot and the send button\n * @part send-button - The default send button (absent when the `send` slot is used)\n *\n * @example\n * ```html\n * <ore-message-composer placeholder=\"Message…\" send-shortcut=\"mod+enter\"></ore-message-composer>\n * ```\n */\nexport const MESSAGE_COMPOSER_TAG = 'ore-message-composer' as const;\ndefine<OreMessageComposerProps>(MESSAGE_COMPOSER_TAG, {\n formAssociated: true,\n props: {\n ...themableBundle,\n ...sizableBundle,\n ...disablableBundle,\n ...loadableBundle,\n 'clear-on-send': prop.bool(true),\n error: prop.string(),\n fullwidth: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n maxlength: prop.json(undefined as number | undefined),\n name: prop.string(),\n placeholder: prop.string(),\n readonly: prop.bool(false),\n ref: prop.data<((el: HTMLTextAreaElement | null) => void) | null>(),\n required: prop.bool(false),\n rows: prop.json(undefined as number | undefined),\n 'send-icon': prop.string(),\n 'send-label': prop.string(),\n 'send-shortcut': prop.oneOf(['enter', 'mod+enter'] as const, 'enter'),\n success: prop.bool(false),\n value: prop.string(),\n variant: prop.string<Exclude<VisualVariant, 'frost' | 'text'>>(),\n },\n setup(props) {\n const emit = useEmit<OreMessageComposerEvents>();\n const slots = useSlots<'prefix' | 'send' | 'suffix'>();\n\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n\n const abortSignal = lifecycleSignal(onCleanup);\n const textareaRef = ref<HTMLTextAreaElement>();\n const autoResize = createAutoResize();\n\n const tf = createTextField({\n disabled: isDisabled,\n error: props.error,\n helper: props.helper,\n maxLength: props.maxlength,\n onInput: (event, value) => emit('input', { originalEvent: event, value }),\n prefix: 'composer',\n readonly: props.readonly,\n required: props.required,\n signal: abortSignal,\n validateOn: formCtx?.validateOn,\n value: props.value,\n });\n\n // Directly form-associated now that the field is owned here rather than borrowed from a\n // nested `ore-textarea` (which previously registered with the ancestor `<form>` on this\n // component's behalf).\n tf.attachFormField(\n useField<string>({\n disabled: tf.disabled,\n onReset: () => {\n tf.reset();\n autoResize.recompute();\n },\n toFormValue: (v) => v,\n validationMessage: tf.validationMessage,\n validity: tf.validity,\n value: tf.value,\n }),\n );\n\n function attemptSend(event: KeyboardEvent | MouseEvent): void {\n const notPrevented = emit('send', { originalEvent: event, value: tf.value.value.trim() });\n\n // `preventDefault()` on `send` means \"keep the current text — skip the default clear\n // + refocus\" (see the event's own doc comment): both halves of that default are gated on\n // the same condition, not just the clear.\n if (notPrevented && props['clear-on-send'].value !== false) {\n tf.clear();\n autoResize.recompute();\n textareaRef.value?.focus();\n }\n }\n\n const composer = createComposerControl({\n disabled: isDisabled,\n loading: computed(() => Boolean(props.loading.value)),\n onSend: attemptSend,\n sendShortcut: props['send-shortcut'],\n value: tf.value,\n });\n\n onElement(textareaRef, (textareaEl) => {\n const unwireField = tf.wire(textareaEl);\n const unwireAutoResize = autoResize.wire(textareaEl);\n const unwireRef = bindRefCallback(props.ref, textareaEl);\n const handleKeydown = (e: KeyboardEvent) => composer.handleKeydown(e);\n\n textareaEl.addEventListener('keydown', handleKeydown);\n\n return () => {\n textareaEl.removeEventListener('keydown', handleKeydown);\n unwireField();\n unwireAutoResize();\n unwireRef();\n };\n });\n\n bind({\n attr: {\n error: errorAttr(tf.errorText),\n size: fCtxProps.size,\n // Reflects `success` only once `error` is confirmed empty — keeps the two host\n // attributes mutually exclusive even if a consumer sets both props at once.\n success: () => (props.success.value && !tf.errorText.value ? true : undefined),\n variant: fCtxProps.variant,\n },\n });\n\n return html`\n <div class=\"composer\" part=\"composer\">\n <textarea\n class=\"field\"\n part=\"field\"\n ref=\"${textareaRef}\"\n :rows=\"${() => props.rows.value ?? 1}\"\n :name=\"${() => props.name.value ?? ''}\"\n :placeholder=\"${() => props.placeholder.value ?? 'Message…'}\"\n :maxlength=\"${() => props.maxlength.value}\"\n ?disabled=\"${isDisabled}\"\n ?readonly=\"${() => Boolean(props.readonly.value)}\"\n ?required=\"${() => Boolean(props.required.value)}\"\n :value=\"${live(tf.value)}\"\n :aria-label=\"${() => props.label.value || 'Message'}\"\n :aria-keyshortcuts=\"${composer.keyShortcutsHint}\"\n :aria-describedby=\"${tf.ariaDescribedBy}\"\n :aria-errormessage=\"${tf.ariaErrorMessage}\"\n :aria-invalid=\"${tf.ariaInvalid}\"></textarea>\n ${renderStatusIcon(tf.errorText)} ${renderFieldStatusRegion(tf)}\n <div class=\"toolbar\" part=\"toolbar\">\n <div class=\"toolbar-start\" part=\"toolbar-start\">\n <slot name=\"prefix\"></slot>\n </div>\n <div class=\"toolbar-end\" part=\"toolbar-end\">\n <slot name=\"suffix\"></slot>\n <slot name=\"send\"></slot>\n ${() =>\n slots.has('send').value\n ? ''\n : html`<ore-button\n class=\"send-btn\"\n part=\"send-button\"\n type=\"button\"\n icon-only\n variant=\"solid\"\n :color=\"${() => props.color.value || 'primary'}\"\n :size=\"${fCtxProps.size}\"\n :label=\"${() => props['send-label'].value || DEFAULT_SEND_LABEL}\"\n ?loading=\"${() => Boolean(props.loading.value)}\"\n ?disabled=\"${() => !composer.canSend.value}\"\n @click=\"${(e: MouseEvent) => composer.send(e)}\">\n <ore-icon name=\"${() => props['send-icon'].value || SEND_ICON}\" size=\"16\"></ore-icon>\n </ore-button>`}\n </div>\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n colorThemeMixin,\n coarsePointerMixin,\n reducedMotionMixin,\n disabledLoadingMixin,\n forcedColorsMixin,\n forcedColorsFocusMixin('.field'),\n sizeVariantMixin(MESSAGE_COMPOSER_SIZE_PRESET),\n componentStyles,\n // Must come after `componentStyles` — see `ore-input`'s identical ordering note for why\n // (`@layer` precedence is fixed by which layer name is *first* referenced across this whole\n // array; `componentStyles` establishes `refine.base`, which this mixin's `refine.variants`\n // rules need to win over).\n fieldVariantMixin({ container: '.composer', text: '.field', tokenPrefix: 'message-composer' }),\n ],\n});\n"],"mappings":"y4BAyCA,IAAM,EAAqB,eACrB,EAAY,WAyIL,EAAuB,oCACJ,EAAsB,CACpD,eAAgB,GAChB,MAAO,CACL,GAAG,EAAA,eACH,GAAG,EAAA,cACH,GAAG,EAAA,iBACH,GAAG,EAAA,eACH,gBAAiB,EAAA,KAAK,KAAK,EAAI,EAC/B,MAAO,EAAA,KAAK,OAAO,EACnB,UAAW,EAAA,KAAK,KAAK,EAAK,EAC1B,OAAQ,EAAA,KAAK,OAAO,EACpB,MAAO,EAAA,KAAK,OAAO,EACnB,UAAW,EAAA,KAAK,KAAK,IAAA,EAA+B,EACpD,KAAM,EAAA,KAAK,OAAO,EAClB,YAAa,EAAA,KAAK,OAAO,EACzB,SAAU,EAAA,KAAK,KAAK,EAAK,EACzB,IAAK,EAAA,KAAK,KAAwD,EAClE,SAAU,EAAA,KAAK,KAAK,EAAK,EACzB,KAAM,EAAA,KAAK,KAAK,IAAA,EAA+B,EAC/C,YAAa,EAAA,KAAK,OAAO,EACzB,aAAc,EAAA,KAAK,OAAO,EAC1B,gBAAiB,EAAA,KAAK,MAAM,CAAC,QAAS,WAAW,EAAY,OAAO,EACpE,QAAS,EAAA,KAAK,KAAK,EAAK,EACxB,MAAO,EAAA,KAAK,OAAO,EACnB,QAAS,EAAA,KAAK,OAAiD,CACjE,EACA,MAAM,EAAO,CACX,IAAM,GAAA,EAAA,EAAA,QAAA,CAAyC,EACzC,GAAA,EAAA,EAAA,SAAA,CAA+C,EAE/C,GAAA,EAAA,EAAA,OAAA,CAAiB,EAAA,QAAQ,EACzB,EAAY,EAAA,eAAe,EAAO,CAAO,EACzC,EAAa,EAAU,SAEvB,EAAc,E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SAAU,YAAa,kBAAmB,CAAC,CAC/F,CACF,CAAC"}
|
package/dist/message-composer.js
CHANGED
|
@@ -2,49 +2,52 @@ import { coarsePointerMixin as e, reducedMotionMixin as t } from "./styles/mixin
|
|
|
2
2
|
import { sizeVariantMixin as n } from "./styles/mixins/shape.css.js";
|
|
3
3
|
import { disabledLoadingMixin as r } from "./styles/mixins/states.css.js";
|
|
4
4
|
import { colorThemeMixin as i, forcedColorsFocusMixin as a, forcedColorsMixin as o } from "./styles/mixins/theme.css.js";
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
import b from "./inputs/
|
|
15
|
-
import {
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
5
|
+
import { fieldVariantMixin as s } from "./styles/mixins/field-variants.css.js";
|
|
6
|
+
import { disablableBundle as c, loadableBundle as l, sizableBundle as u, themableBundle as d } from "./shared/prop-bundles.js";
|
|
7
|
+
import { MESSAGE_COMPOSER_SIZE_PRESET as f } from "./shared/size-presets.js";
|
|
8
|
+
import { lifecycleSignal as p } from "./headless/ore.js";
|
|
9
|
+
import { createAutoResize as m } from "./headless/auto-resize.js";
|
|
10
|
+
import { bindRefCallback as h } from "./headless/ref-callback.js";
|
|
11
|
+
import { createTextField as g } from "./headless/text-field.js";
|
|
12
|
+
import { createComposerControl as _ } from "./headless/composer.js";
|
|
13
|
+
import { errorAttr as v } from "./inputs/shared/field-binding.js";
|
|
14
|
+
import { FORM_CTX as y, useFormContext as b } from "./inputs/shared/form-context.js";
|
|
15
|
+
import { renderFieldStatusRegion as x, renderStatusIcon as S } from "./inputs/shared/templates.js";
|
|
16
|
+
import C from "./inputs/message-composer/message-composer.css.js";
|
|
17
|
+
import { bind as w, define as T, html as E, inject as D, onCleanup as O, onElement as k, prop as A, ref as j, useEmit as M, useSlots as N } from "@vielzeug/ore";
|
|
18
|
+
import { live as P } from "@vielzeug/ore/directives";
|
|
19
|
+
import { computed as F } from "@vielzeug/ripple";
|
|
20
|
+
import { useField as I } from "@vielzeug/ore/forms";
|
|
19
21
|
//#region src/inputs/message-composer/message-composer.ts
|
|
20
|
-
var
|
|
21
|
-
|
|
22
|
+
var L = "Send message", R = "arrow-up", z = "ore-message-composer";
|
|
23
|
+
T(z, {
|
|
22
24
|
formAssociated: !0,
|
|
23
25
|
props: {
|
|
26
|
+
...d,
|
|
24
27
|
...u,
|
|
25
|
-
...l,
|
|
26
|
-
...s,
|
|
27
28
|
...c,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
"send-
|
|
42
|
-
"send-
|
|
43
|
-
|
|
44
|
-
|
|
29
|
+
...l,
|
|
30
|
+
"clear-on-send": A.bool(!0),
|
|
31
|
+
error: A.string(),
|
|
32
|
+
fullwidth: A.bool(!1),
|
|
33
|
+
helper: A.string(),
|
|
34
|
+
label: A.string(),
|
|
35
|
+
maxlength: A.json(void 0),
|
|
36
|
+
name: A.string(),
|
|
37
|
+
placeholder: A.string(),
|
|
38
|
+
readonly: A.bool(!1),
|
|
39
|
+
ref: A.data(),
|
|
40
|
+
required: A.bool(!1),
|
|
41
|
+
rows: A.json(void 0),
|
|
42
|
+
"send-icon": A.string(),
|
|
43
|
+
"send-label": A.string(),
|
|
44
|
+
"send-shortcut": A.oneOf(["enter", "mod+enter"], "enter"),
|
|
45
|
+
success: A.bool(!1),
|
|
46
|
+
value: A.string(),
|
|
47
|
+
variant: A.string()
|
|
45
48
|
},
|
|
46
49
|
setup(e) {
|
|
47
|
-
let t =
|
|
50
|
+
let t = M(), n = N(), r = D(y), i = b(e, r), a = i.disabled, o = p(O), s = j(), c = m(), l = g({
|
|
48
51
|
disabled: a,
|
|
49
52
|
error: e.error,
|
|
50
53
|
helper: e.helper,
|
|
@@ -60,7 +63,7 @@ S(L, {
|
|
|
60
63
|
validateOn: r?.validateOn,
|
|
61
64
|
value: e.value
|
|
62
65
|
});
|
|
63
|
-
l.attachFormField(
|
|
66
|
+
l.attachFormField(I({
|
|
64
67
|
disabled: l.disabled,
|
|
65
68
|
onReset: () => {
|
|
66
69
|
l.reset(), c.recompute();
|
|
@@ -76,27 +79,24 @@ S(L, {
|
|
|
76
79
|
value: l.value.value.trim()
|
|
77
80
|
}) && e["clear-on-send"].value !== !1 && (l.clear(), c.recompute(), s.value?.focus());
|
|
78
81
|
}
|
|
79
|
-
let d =
|
|
82
|
+
let d = _({
|
|
80
83
|
disabled: a,
|
|
81
|
-
loading:
|
|
84
|
+
loading: F(() => !!e.loading.value),
|
|
82
85
|
onSend: u,
|
|
83
86
|
sendShortcut: e["send-shortcut"],
|
|
84
87
|
value: l.value
|
|
85
88
|
});
|
|
86
|
-
return
|
|
87
|
-
let n = l.wire(t), r = c.wire(t), i = (e) => d.handleKeydown(e);
|
|
88
|
-
t.addEventListener("keydown",
|
|
89
|
-
|
|
90
|
-
e?.(t);
|
|
91
|
-
});
|
|
92
|
-
return () => {
|
|
93
|
-
t.removeEventListener("keydown", i), n(), r(), a.dispose(), e.ref.value?.(null);
|
|
89
|
+
return k(s, (t) => {
|
|
90
|
+
let n = l.wire(t), r = c.wire(t), i = h(e.ref, t), a = (e) => d.handleKeydown(e);
|
|
91
|
+
return t.addEventListener("keydown", a), () => {
|
|
92
|
+
t.removeEventListener("keydown", a), n(), r(), i();
|
|
94
93
|
};
|
|
95
|
-
}),
|
|
96
|
-
error:
|
|
94
|
+
}), w({ attr: {
|
|
95
|
+
error: v(l.errorText),
|
|
97
96
|
size: i.size,
|
|
97
|
+
success: () => e.success.value && !l.errorText.value ? !0 : void 0,
|
|
98
98
|
variant: i.variant
|
|
99
|
-
} }),
|
|
99
|
+
} }), E`
|
|
100
100
|
<div class="composer" part="composer">
|
|
101
101
|
<textarea
|
|
102
102
|
class="field"
|
|
@@ -109,19 +109,13 @@ S(L, {
|
|
|
109
109
|
?disabled="${a}"
|
|
110
110
|
?readonly="${() => !!e.readonly.value}"
|
|
111
111
|
?required="${() => !!e.required.value}"
|
|
112
|
-
:value="${
|
|
112
|
+
:value="${P(l.value)}"
|
|
113
113
|
:aria-label="${() => e.label.value || "Message"}"
|
|
114
114
|
:aria-keyshortcuts="${d.keyShortcutsHint}"
|
|
115
115
|
:aria-describedby="${l.ariaDescribedBy}"
|
|
116
116
|
:aria-errormessage="${l.ariaErrorMessage}"
|
|
117
117
|
:aria-invalid="${l.ariaInvalid}"></textarea>
|
|
118
|
-
|
|
119
|
-
<div id="${l.assistiveId}" class="helper-text" aria-live="polite" part="helper" ?hidden="${() => !!l.errorText.value || !l.helperText.value}">
|
|
120
|
-
${() => l.helperText.value}
|
|
121
|
-
</div>
|
|
122
|
-
<div id="${l.errorId}" class="helper-text" role="alert" part="error" ?hidden="${() => !l.errorText.value}">
|
|
123
|
-
${() => l.errorText.value}
|
|
124
|
-
</div>
|
|
118
|
+
${S(l.errorText)} ${x(l)}
|
|
125
119
|
<div class="toolbar" part="toolbar">
|
|
126
120
|
<div class="toolbar-start" part="toolbar-start">
|
|
127
121
|
<slot name="prefix"></slot>
|
|
@@ -129,7 +123,7 @@ S(L, {
|
|
|
129
123
|
<div class="toolbar-end" part="toolbar-end">
|
|
130
124
|
<slot name="suffix"></slot>
|
|
131
125
|
<slot name="send"></slot>
|
|
132
|
-
${() => n.has("send").value ? "" :
|
|
126
|
+
${() => n.has("send").value ? "" : E`<ore-button
|
|
133
127
|
class="send-btn"
|
|
134
128
|
part="send-button"
|
|
135
129
|
type="button"
|
|
@@ -137,11 +131,11 @@ S(L, {
|
|
|
137
131
|
variant="solid"
|
|
138
132
|
:color="${() => e.color.value || "primary"}"
|
|
139
133
|
:size="${i.size}"
|
|
140
|
-
:label="${() => e["send-label"].value ||
|
|
134
|
+
:label="${() => e["send-label"].value || L}"
|
|
141
135
|
?loading="${() => !!e.loading.value}"
|
|
142
136
|
?disabled="${() => !d.canSend.value}"
|
|
143
137
|
@click="${(e) => d.send(e)}">
|
|
144
|
-
<ore-icon name="${() => e["send-icon"].value ||
|
|
138
|
+
<ore-icon name="${() => e["send-icon"].value || R}" size="16"></ore-icon>
|
|
145
139
|
</ore-button>`}
|
|
146
140
|
</div>
|
|
147
141
|
</div>
|
|
@@ -156,11 +150,16 @@ S(L, {
|
|
|
156
150
|
r,
|
|
157
151
|
o,
|
|
158
152
|
a(".field"),
|
|
159
|
-
n(
|
|
160
|
-
|
|
153
|
+
n(f),
|
|
154
|
+
C,
|
|
155
|
+
s({
|
|
156
|
+
container: ".composer",
|
|
157
|
+
text: ".field",
|
|
158
|
+
tokenPrefix: "message-composer"
|
|
159
|
+
})
|
|
161
160
|
]
|
|
162
161
|
});
|
|
163
162
|
//#endregion
|
|
164
|
-
export {
|
|
163
|
+
export { z as MESSAGE_COMPOSER_TAG };
|
|
165
164
|
|
|
166
165
|
//# sourceMappingURL=message-composer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message-composer.js","names":[],"sources":["../src/inputs/message-composer/message-composer.ts"],"sourcesContent":["import { define, html, inject, prop, ref, bind, onCleanup, onElement, useEmit, useSlots } from '@vielzeug/ore';\nimport { live } from '@vielzeug/ore/directives';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed, watch } from '@vielzeug/ripple';\n\nimport type { ComponentSize, ThemeColor, VisualVariant } from '../../types';\n\nimport {\n counterClassName,\n createAutoResize,\n createComposerControl,\n createTextField,\n lifecycleSignal,\n type SendShortcut,\n} from '../../headless';\nimport {\n disablableBundle,\n loadableBundle,\n MESSAGE_COMPOSER_SIZE_PRESET,\n sizableBundle,\n themableBundle,\n} from '../../shared';\nimport {\n colorThemeMixin,\n coarsePointerMixin,\n disabledLoadingMixin,\n forcedColorsFocusMixin,\n forcedColorsMixin,\n reducedMotionMixin,\n sizeVariantMixin,\n} from '../../styles';\nimport { errorAttr } from '../shared/field-binding';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport '../../content/icon/icon';\nimport '../button/button';\nimport componentStyles from './message-composer.css?inline';\n\nexport type { SendShortcut } from '../../headless';\n\nconst DEFAULT_SEND_LABEL = 'Send message';\nconst SEND_ICON = 'arrow-up';\n\n/** Events emitted by the message composer */\nexport type OreMessageComposerEvents = {\n /** Fired on every keystroke with the current value. */\n input: { originalEvent: Event; value: string };\n /**\n * Fired for a send attempt (the resolved `send-shortcut` or the send button) while the\n * composer isn't blank/disabled/loading. Cancelable — call `preventDefault()` to keep the\n * current text in the field instead of the default clear + refocus.\n */\n send: { originalEvent: KeyboardEvent | MouseEvent; value: string };\n};\n\n/** Message composer properties */\nexport type OreMessageComposerProps = {\n /** Clear the value and refocus after a non-cancelled `send` (default `true`) */\n 'clear-on-send'?: boolean;\n /** Theme color (card focus ring + default send button color) */\n color?: ThemeColor;\n /** Disable the whole composer (field, slots, and send action) */\n disabled?: boolean;\n /** Error message shown below the field */\n error?: string;\n /** Stretch the composer to the full width of its container */\n fullwidth?: boolean;\n /** Helper text shown below the field */\n helper?: string;\n /** Accessible name for the field — never rendered visually, only as `aria-label` */\n label?: string;\n /** Blocks further sends (e.g. a send is already in flight) without disabling editing */\n loading?: boolean;\n /** Maximum character count; shows a counter */\n maxlength?: number;\n /** Form field name */\n name?: string;\n /** Placeholder text */\n placeholder?: string;\n /** Make the field read-only */\n readonly?: boolean;\n /**\n * JS-only callback fired with the inner `<textarea>` element when it mounts, and with\n * `null` when it unmounts. Set as a JS property: `composer.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLTextAreaElement | null) => void) | null;\n /** Require a non-blank value for `<ore-form>` validation */\n required?: boolean;\n /** Number of visible rows before auto-resize grows the field */\n rows?: number;\n /** Lucide icon name for the default send button (default `'arrow-up'`) */\n 'send-icon'?: string;\n /** Accessible label for the send button (default `'Send message'`) */\n 'send-label'?: string;\n /** Keyboard shortcut that sends: 'enter' (Shift+Enter for a newline) or 'mod+enter' (Enter always inserts a newline; Ctrl/Cmd+Enter sends) */\n 'send-shortcut'?: SendShortcut;\n /** Component size */\n size?: ComponentSize;\n /** Current text value */\n value?: string;\n /** Visual variant of the card — same variant set as `ore-textarea`, applied to the card. */\n variant?: Exclude<VisualVariant, 'frost' | 'text'>;\n};\n\n/**\n * A message/comment composer — a card with an auto-resizing field on top and a toolbar row\n * below it, built directly on the same headless primitives as `ore-textarea` (`createTextField`,\n * `createAutoResize`) rather than composing `ore-textarea` itself. Nesting a fully-styled sibling\n * component and suppressing most of its chrome (as an earlier version of this component did) is\n * a leaky composition — this owns its single `<textarea>` outright, so there's exactly one\n * implementation of the field's appearance to reason about, not two fighting each other.\n *\n * Handles the send gesture (Enter to send, Shift+Enter for a newline, or a Ctrl/Cmd+Enter\n * alternative), IME-safe composition, and clear-and-refocus after sending.\n *\n * @element ore-message-composer\n *\n * @attr {string} value - Current text value\n * @attr {string} placeholder - Placeholder text\n * @attr {string} label - Accessible name for the field (not rendered visually)\n * @attr {string} name - Form field name\n * @attr {string} helper - Helper text shown below the field\n * @attr {string} error - Error message shown below the field\n * @attr {boolean} disabled - Disable the whole composer\n * @attr {boolean} readonly - Read-only mode\n * @attr {boolean} required - Require a non-blank value for `<ore-form>` validation\n * @attr {boolean} loading - Blocks further sends without disabling editing\n * @attr {number} maxlength - Max character count; shows a counter\n * @attr {number} rows - Visible rows before auto-resize grows the field (default 1)\n * @attr {string} color - Theme color: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'\n * @attr {string} variant - Visual variant of the card: 'solid' | 'flat' | 'bordered' | 'outline' | 'ghost'\n * @attr {string} size - 'sm' | 'md' | 'lg'\n * @attr {boolean} fullwidth - Stretch to the full width of the container\n * @attr {string} send-icon - Lucide icon name for the default send button (default 'arrow-up')\n * @attr {string} send-label - Accessible label for the send button (default 'Send message')\n * @attr {string} send-shortcut - 'enter' (default) | 'mod+enter'\n * @attr {boolean} clear-on-send - Clear the value and refocus after a non-cancelled send (default true)\n *\n * @fires input - Fired on every keystroke. detail: { value, originalEvent }\n * @fires send - Fired on a send attempt. Cancelable. detail: { value, originalEvent }\n *\n * @slot prefix - Content at the start of the toolbar row (e.g. an attach menu)\n * @slot suffix - Content at the end of the toolbar row, before the send button (e.g. a model picker)\n * @slot send - Replaces the default send button entirely — the only supported way to customize it\n *\n * @cssprop --message-composer-bg - Card background color\n * @cssprop --message-composer-border-color - Card border color\n * @cssprop --message-composer-radius - Card border radius\n * @cssprop --message-composer-padding - Card inner padding\n * @cssprop --message-composer-gap - Gap between the field/toolbar rows and between toolbar items\n * @cssprop --message-composer-placeholder-color - Field placeholder text color\n * @cssprop --message-composer-min-height - Minimum field height (default one line)\n * @cssprop --message-composer-hover-bg - Card background on hover (flat/ghost variants)\n * @cssprop --message-composer-hover-border-color - Card border on hover (flat/bordered variants)\n * @cssprop --message-composer-focus-bg - Card background when focused (flat variant)\n * @cssprop --message-composer-focus-border-color - Card border when focused (flat variant)\n *\n * @part composer - Root card container\n * @part field - The native `<textarea>` element\n * @part helper - Helper text element\n * @part error - Error text element (`role=\"alert\"`)\n * @part toolbar - Toolbar row below the field\n * @part toolbar-start - Toolbar group holding the `prefix` slot\n * @part toolbar-end - Toolbar group holding the `suffix` slot and the send button\n * @part send-button - The default send button (absent when the `send` slot is used)\n *\n * @example\n * ```html\n * <ore-message-composer placeholder=\"Message…\" send-shortcut=\"mod+enter\"></ore-message-composer>\n * ```\n */\nexport const MESSAGE_COMPOSER_TAG = 'ore-message-composer' as const;\ndefine<OreMessageComposerProps>(MESSAGE_COMPOSER_TAG, {\n formAssociated: true,\n props: {\n ...themableBundle,\n ...sizableBundle,\n ...disablableBundle,\n ...loadableBundle,\n 'clear-on-send': prop.bool(true),\n error: prop.string(),\n fullwidth: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n maxlength: prop.json(undefined as number | undefined),\n name: prop.string(),\n placeholder: prop.string(),\n readonly: prop.bool(false),\n ref: prop.json(undefined as ((el: HTMLTextAreaElement | null) => void) | null | undefined),\n required: prop.bool(false),\n rows: prop.json(undefined as number | undefined),\n 'send-icon': prop.string(),\n 'send-label': prop.string(),\n 'send-shortcut': prop.oneOf(['enter', 'mod+enter'] as const, 'enter'),\n value: prop.string(),\n variant: prop.string<Exclude<VisualVariant, 'frost' | 'text'>>(),\n },\n setup(props) {\n const emit = useEmit<OreMessageComposerEvents>();\n const slots = useSlots<'prefix' | 'send' | 'suffix'>();\n\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n\n const abortSignal = lifecycleSignal(onCleanup);\n const textareaRef = ref<HTMLTextAreaElement>();\n const autoResize = createAutoResize();\n\n const tf = createTextField({\n disabled: isDisabled,\n error: props.error,\n helper: props.helper,\n maxLength: props.maxlength,\n onInput: (event, value) => emit('input', { originalEvent: event, value }),\n prefix: 'composer',\n readonly: props.readonly,\n required: props.required,\n signal: abortSignal,\n validateOn: formCtx?.validateOn,\n value: props.value,\n });\n\n // Directly form-associated now that the field is owned here rather than borrowed from a\n // nested `ore-textarea` (which previously registered with the ancestor `<form>` on this\n // component's behalf).\n tf.attachFormField(\n useField<string>({\n disabled: tf.disabled,\n onReset: () => {\n tf.reset();\n autoResize.recompute();\n },\n toFormValue: (v) => v,\n validationMessage: tf.validationMessage,\n validity: tf.validity,\n value: tf.value,\n }),\n );\n\n function attemptSend(event: KeyboardEvent | MouseEvent): void {\n const notPrevented = emit('send', { originalEvent: event, value: tf.value.value.trim() });\n\n // `preventDefault()` on `send` means \"keep the current text — skip the default clear\n // + refocus\" (see the event's own doc comment): both halves of that default are gated on\n // the same condition, not just the clear.\n if (notPrevented && props['clear-on-send'].value !== false) {\n tf.clear();\n autoResize.recompute();\n textareaRef.value?.focus();\n }\n }\n\n const composer = createComposerControl({\n disabled: isDisabled,\n loading: computed(() => Boolean(props.loading.value)),\n onSend: attemptSend,\n sendShortcut: props['send-shortcut'],\n value: tf.value,\n });\n\n onElement(textareaRef, (textareaEl) => {\n const unwireField = tf.wire(textareaEl);\n const unwireAutoResize = autoResize.wire(textareaEl);\n const handleKeydown = (e: KeyboardEvent) => composer.handleKeydown(e);\n\n textareaEl.addEventListener('keydown', handleKeydown);\n\n // Immediate fire for when the prop is already set on mount.\n props.ref.value?.(textareaEl);\n\n // Reactive watcher so that if props.ref is set *after* the inner <textarea> mounts\n // (e.g. a parent sets it via a ref callback after render), the new callback still\n // receives the live element.\n const refSub = watch(props.ref, (cb) => {\n cb?.(textareaEl);\n });\n\n return () => {\n textareaEl.removeEventListener('keydown', handleKeydown);\n unwireField();\n unwireAutoResize();\n refSub.dispose();\n props.ref.value?.(null);\n };\n });\n\n bind({\n attr: {\n error: errorAttr(tf.errorText),\n size: fCtxProps.size,\n variant: fCtxProps.variant,\n },\n });\n\n const counterClass = () => counterClassName(tf.counter?.value);\n const counterHidden = () => !tf.counter;\n const counterText = () => tf.counter?.value.counterText.replace(' / ', '/') ?? '';\n const helperHidden = () => !!tf.errorText.value || !tf.helperText.value;\n const errorHidden = () => !tf.errorText.value;\n\n return html`\n <div class=\"composer\" part=\"composer\">\n <textarea\n class=\"field\"\n part=\"field\"\n ref=\"${textareaRef}\"\n :rows=\"${() => props.rows.value ?? 1}\"\n :name=\"${() => props.name.value ?? ''}\"\n :placeholder=\"${() => props.placeholder.value ?? 'Message…'}\"\n :maxlength=\"${() => props.maxlength.value}\"\n ?disabled=\"${isDisabled}\"\n ?readonly=\"${() => Boolean(props.readonly.value)}\"\n ?required=\"${() => Boolean(props.required.value)}\"\n :value=\"${live(tf.value)}\"\n :aria-label=\"${() => props.label.value || 'Message'}\"\n :aria-keyshortcuts=\"${composer.keyShortcutsHint}\"\n :aria-describedby=\"${tf.ariaDescribedBy}\"\n :aria-errormessage=\"${tf.ariaErrorMessage}\"\n :aria-invalid=\"${tf.ariaInvalid}\"></textarea>\n <span class=\"${counterClass}\" aria-live=\"polite\" ?hidden=\"${counterHidden}\">${counterText}</span>\n <div id=\"${tf.assistiveId}\" class=\"helper-text\" aria-live=\"polite\" part=\"helper\" ?hidden=\"${helperHidden}\">\n ${() => tf.helperText.value}\n </div>\n <div id=\"${tf.errorId}\" class=\"helper-text\" role=\"alert\" part=\"error\" ?hidden=\"${errorHidden}\">\n ${() => tf.errorText.value}\n </div>\n <div class=\"toolbar\" part=\"toolbar\">\n <div class=\"toolbar-start\" part=\"toolbar-start\">\n <slot name=\"prefix\"></slot>\n </div>\n <div class=\"toolbar-end\" part=\"toolbar-end\">\n <slot name=\"suffix\"></slot>\n <slot name=\"send\"></slot>\n ${() =>\n slots.has('send').value\n ? ''\n : html`<ore-button\n class=\"send-btn\"\n part=\"send-button\"\n type=\"button\"\n icon-only\n variant=\"solid\"\n :color=\"${() => props.color.value || 'primary'}\"\n :size=\"${fCtxProps.size}\"\n :label=\"${() => props['send-label'].value || DEFAULT_SEND_LABEL}\"\n ?loading=\"${() => Boolean(props.loading.value)}\"\n ?disabled=\"${() => !composer.canSend.value}\"\n @click=\"${(e: MouseEvent) => composer.send(e)}\">\n <ore-icon name=\"${() => props['send-icon'].value || SEND_ICON}\" size=\"16\"></ore-icon>\n </ore-button>`}\n </div>\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n colorThemeMixin,\n coarsePointerMixin,\n reducedMotionMixin,\n disabledLoadingMixin,\n forcedColorsMixin,\n forcedColorsFocusMixin('.field'),\n sizeVariantMixin(MESSAGE_COMPOSER_SIZE_PRESET),\n componentStyles,\n ],\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAuCA,IAAM,IAAqB,gBACrB,IAAY,YAkIL,IAAuB;AACpC,EAAgC,GAAsB;CACpD,gBAAgB;CAChB,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,iBAAiB,EAAK,KAAK,EAAI;EAC/B,OAAO,EAAK,OAAO;EACnB,WAAW,EAAK,KAAK,EAAK;EAC1B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K,GAuBe;mBAC/E,EAAG,YAAY,wEAvBH,CAAC,CAAC,EAAG,UAAU,SAAS,CAAC,EAAG,WAAW,MAuB2C;kBAC/F,EAAG,WAAW,MAAM;;mBAEnB,EAAG,QAAQ,iEAzBA,CAAC,EAAG,UAAU,MAyByD;kBACnF,EAAG,UAAU,MAAM;;;;;;;;;oBAUvB,EAAM,IAAI,MAAM,CAAC,CAAC,QACd,KACA,CAAI;;;;;;oCAMc,EAAM,MAAM,SAAS,UAAU;6BACtC,EAAU,KAAK;oCACR,EAAM,aAAa,CAAC,SAAS,EAAmB;sCAC9C,EAAQ,EAAM,QAAQ,MAAO;uCAC5B,CAAC,EAAS,QAAQ,MAAM;+BAChC,MAAkB,EAAS,KAAK,CAAC,EAAE;4CACtB,EAAM,YAAY,CAAC,SAAS,EAAU;iCACjD;;;;;CAK/B;CACA,QAAQ,EAAE,gBAAgB,GAAK;CAC/B,QAAQ;EACN;EACA;EACA;EACA;EACA;EACA,EAAuB,QAAQ;EAC/B,EAAiB,CAA4B;EAC7C;CACF;AACF,CAAC"}
|
|
1
|
+
{"version":3,"file":"message-composer.js","names":[],"sources":["../src/inputs/message-composer/message-composer.ts"],"sourcesContent":["import { define, html, inject, prop, ref, bind, onCleanup, onElement, useEmit, useSlots } from '@vielzeug/ore';\nimport { live } from '@vielzeug/ore/directives';\nimport { useField } from '@vielzeug/ore/forms';\nimport { computed } from '@vielzeug/ripple';\n\nimport type { ComponentSize, ThemeColor, VisualVariant } from '../../types';\n\nimport {\n bindRefCallback,\n createAutoResize,\n createComposerControl,\n createTextField,\n lifecycleSignal,\n type SendShortcut,\n} from '../../headless';\nimport {\n disablableBundle,\n loadableBundle,\n MESSAGE_COMPOSER_SIZE_PRESET,\n sizableBundle,\n themableBundle,\n} from '../../shared';\nimport {\n colorThemeMixin,\n coarsePointerMixin,\n disabledLoadingMixin,\n fieldVariantMixin,\n forcedColorsFocusMixin,\n forcedColorsMixin,\n reducedMotionMixin,\n sizeVariantMixin,\n} from '../../styles';\nimport { errorAttr } from '../shared/field-binding';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport { renderFieldStatusRegion, renderStatusIcon } from '../shared/templates';\nimport '../../content/icon/icon';\nimport '../button/button';\nimport componentStyles from './message-composer.css?inline';\n\nexport type { SendShortcut } from '../../headless';\n\nconst DEFAULT_SEND_LABEL = 'Send message';\nconst SEND_ICON = 'arrow-up';\n\n/** Events emitted by the message composer */\nexport type OreMessageComposerEvents = {\n /** Fired on every keystroke with the current value. */\n input: { originalEvent: Event; value: string };\n /**\n * Fired for a send attempt (the resolved `send-shortcut` or the send button) while the\n * composer isn't blank/disabled/loading. Cancelable — call `preventDefault()` to keep the\n * current text in the field instead of the default clear + refocus.\n */\n send: { originalEvent: KeyboardEvent | MouseEvent; value: string };\n};\n\n/** Message composer properties */\nexport type OreMessageComposerProps = {\n /** Clear the value and refocus after a non-cancelled `send` (default `true`) */\n 'clear-on-send'?: boolean;\n /** Theme color (card focus ring + default send button color) */\n color?: ThemeColor;\n /** Disable the whole composer (field, slots, and send action) */\n disabled?: boolean;\n /** Error message shown below the field */\n error?: string;\n /** Stretch the composer to the full width of its container */\n fullwidth?: boolean;\n /** Helper text shown below the field */\n helper?: string;\n /** Accessible name for the field — never rendered visually, only as `aria-label` */\n label?: string;\n /** Blocks further sends (e.g. a send is already in flight) without disabling editing */\n loading?: boolean;\n /** Maximum character count; shows a counter */\n maxlength?: number;\n /** Form field name */\n name?: string;\n /** Placeholder text */\n placeholder?: string;\n /** Make the field read-only */\n readonly?: boolean;\n /**\n * JS-only callback fired with the inner `<textarea>` element when it mounts, and with\n * `null` when it unmounts. Set as a JS property: `composer.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLTextAreaElement | null) => void) | null;\n /** Require a non-blank value for `<ore-form>` validation */\n required?: boolean;\n /** Number of visible rows before auto-resize grows the field */\n rows?: number;\n /** Lucide icon name for the default send button (default `'arrow-up'`) */\n 'send-icon'?: string;\n /** Accessible label for the send button (default `'Send message'`) */\n 'send-label'?: string;\n /** Keyboard shortcut that sends: 'enter' (Shift+Enter for a newline) or 'mod+enter' (Enter always inserts a newline; Ctrl/Cmd+Enter sends) */\n 'send-shortcut'?: SendShortcut;\n /** Component size */\n size?: ComponentSize;\n /**\n * Shows an inline green check icon inside the field to confirm the value has\n * passed validation. Ignored while `error` is set — an error always wins.\n */\n success?: boolean;\n /** Current text value */\n value?: string;\n /** Visual variant of the card — same variant set as `ore-textarea`, applied to the card. */\n variant?: Exclude<VisualVariant, 'frost' | 'text'>;\n};\n\n/**\n * A message/comment composer — a card with an auto-resizing field on top and a toolbar row\n * below it, built directly on the same headless primitives as `ore-textarea` (`createTextField`,\n * `createAutoResize`) rather than composing `ore-textarea` itself. Nesting a fully-styled sibling\n * component and suppressing most of its chrome (as an earlier version of this component did) is\n * a leaky composition — this owns its single `<textarea>` outright, so there's exactly one\n * implementation of the field's appearance to reason about, not two fighting each other.\n *\n * Handles the send gesture (Enter to send, Shift+Enter for a newline, or a Ctrl/Cmd+Enter\n * alternative), IME-safe composition, and clear-and-refocus after sending.\n *\n * @element ore-message-composer\n *\n * @attr {string} value - Current text value\n * @attr {string} placeholder - Placeholder text\n * @attr {string} label - Accessible name for the field (not rendered visually)\n * @attr {string} name - Form field name\n * @attr {string} helper - Helper text shown below the field\n * @attr {string} error - Error message shown below the field\n * @attr {boolean} success - Show an inline success check icon (suppressed while `error` is set)\n * @attr {boolean} disabled - Disable the whole composer\n * @attr {boolean} readonly - Read-only mode\n * @attr {boolean} required - Require a non-blank value for `<ore-form>` validation\n * @attr {boolean} loading - Blocks further sends without disabling editing\n * @attr {number} maxlength - Max character count; shows a counter\n * @attr {number} rows - Visible rows before auto-resize grows the field (default 1)\n * @attr {string} color - Theme color: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'\n * @attr {string} variant - Visual variant of the card: 'solid' | 'flat' | 'bordered' | 'outline' | 'ghost'\n * @attr {string} size - 'sm' | 'md' | 'lg'\n * @attr {boolean} fullwidth - Stretch to the full width of the container\n * @attr {string} send-icon - Lucide icon name for the default send button (default 'arrow-up')\n * @attr {string} send-label - Accessible label for the send button (default 'Send message')\n * @attr {string} send-shortcut - 'enter' (default) | 'mod+enter'\n * @attr {boolean} clear-on-send - Clear the value and refocus after a non-cancelled send (default true)\n *\n * @fires input - Fired on every keystroke. detail: { value, originalEvent }\n * @fires send - Fired on a send attempt. Cancelable. detail: { value, originalEvent }\n *\n * @slot prefix - Content at the start of the toolbar row (e.g. an attach menu)\n * @slot suffix - Content at the end of the toolbar row, before the send button (e.g. a model picker)\n * @slot send - Replaces the default send button entirely — the only supported way to customize it\n *\n * @cssprop --message-composer-bg - Card background color\n * @cssprop --message-composer-border-color - Card border color\n * @cssprop --message-composer-radius - Card border radius\n * @cssprop --message-composer-padding - Card inner padding\n * @cssprop --message-composer-gap - Gap between the field/toolbar rows and between toolbar items\n * @cssprop --message-composer-placeholder-color - Field placeholder text color\n * @cssprop --message-composer-min-height - Minimum field height (default one line)\n * @cssprop --message-composer-hover-bg - Card background on hover (flat/ghost variants)\n * @cssprop --message-composer-hover-border-color - Card border on hover (flat/bordered variants)\n * @cssprop --message-composer-focus-bg - Card background when focused (flat variant)\n * @cssprop --message-composer-focus-border-color - Card border when focused (flat variant)\n *\n * @part composer - Root card container\n * @part field - The native `<textarea>` element\n * @part status-icon - The inline error/success icon shown inside the field\n * @part helper - Helper text element\n * @part error - Error text element (`role=\"alert\"`)\n * @part toolbar - Toolbar row below the field\n * @part toolbar-start - Toolbar group holding the `prefix` slot\n * @part toolbar-end - Toolbar group holding the `suffix` slot and the send button\n * @part send-button - The default send button (absent when the `send` slot is used)\n *\n * @example\n * ```html\n * <ore-message-composer placeholder=\"Message…\" send-shortcut=\"mod+enter\"></ore-message-composer>\n * ```\n */\nexport const MESSAGE_COMPOSER_TAG = 'ore-message-composer' as const;\ndefine<OreMessageComposerProps>(MESSAGE_COMPOSER_TAG, {\n formAssociated: true,\n props: {\n ...themableBundle,\n ...sizableBundle,\n ...disablableBundle,\n ...loadableBundle,\n 'clear-on-send': prop.bool(true),\n error: prop.string(),\n fullwidth: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n maxlength: prop.json(undefined as number | undefined),\n name: prop.string(),\n placeholder: prop.string(),\n readonly: prop.bool(false),\n ref: prop.data<((el: HTMLTextAreaElement | null) => void) | null>(),\n required: prop.bool(false),\n rows: prop.json(undefined as number | undefined),\n 'send-icon': prop.string(),\n 'send-label': prop.string(),\n 'send-shortcut': prop.oneOf(['enter', 'mod+enter'] as const, 'enter'),\n success: prop.bool(false),\n value: prop.string(),\n variant: prop.string<Exclude<VisualVariant, 'frost' | 'text'>>(),\n },\n setup(props) {\n const emit = useEmit<OreMessageComposerEvents>();\n const slots = useSlots<'prefix' | 'send' | 'suffix'>();\n\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n\n const abortSignal = lifecycleSignal(onCleanup);\n const textareaRef = ref<HTMLTextAreaElement>();\n const autoResize = createAutoResize();\n\n const tf = createTextField({\n disabled: isDisabled,\n error: props.error,\n helper: props.helper,\n maxLength: props.maxlength,\n onInput: (event, value) => emit('input', { originalEvent: event, value }),\n prefix: 'composer',\n readonly: props.readonly,\n required: props.required,\n signal: abortSignal,\n validateOn: formCtx?.validateOn,\n value: props.value,\n });\n\n // Directly form-associated now that the field is owned here rather than borrowed from a\n // nested `ore-textarea` (which previously registered with the ancestor `<form>` on this\n // component's behalf).\n tf.attachFormField(\n useField<string>({\n disabled: tf.disabled,\n onReset: () => {\n tf.reset();\n autoResize.recompute();\n },\n toFormValue: (v) => v,\n validationMessage: tf.validationMessage,\n validity: tf.validity,\n value: tf.value,\n }),\n );\n\n function attemptSend(event: KeyboardEvent | MouseEvent): void {\n const notPrevented = emit('send', { originalEvent: event, value: tf.value.value.trim() });\n\n // `preventDefault()` on `send` means \"keep the current text — skip the default clear\n // + refocus\" (see the event's own doc comment): both halves of that default are gated on\n // the same condition, not just the clear.\n if (notPrevented && props['clear-on-send'].value !== false) {\n tf.clear();\n autoResize.recompute();\n textareaRef.value?.focus();\n }\n }\n\n const composer = createComposerControl({\n disabled: isDisabled,\n loading: computed(() => Boolean(props.loading.value)),\n onSend: attemptSend,\n sendShortcut: props['send-shortcut'],\n value: tf.value,\n });\n\n onElement(textareaRef, (textareaEl) => {\n const unwireField = tf.wire(textareaEl);\n const unwireAutoResize = autoResize.wire(textareaEl);\n const unwireRef = bindRefCallback(props.ref, textareaEl);\n const handleKeydown = (e: KeyboardEvent) => composer.handleKeydown(e);\n\n textareaEl.addEventListener('keydown', handleKeydown);\n\n return () => {\n textareaEl.removeEventListener('keydown', handleKeydown);\n unwireField();\n unwireAutoResize();\n unwireRef();\n };\n });\n\n bind({\n attr: {\n error: errorAttr(tf.errorText),\n size: fCtxProps.size,\n // Reflects `success` only once `error` is confirmed empty — keeps the two host\n // attributes mutually exclusive even if a consumer sets both props at once.\n success: () => (props.success.value && !tf.errorText.value ? true : undefined),\n variant: fCtxProps.variant,\n },\n });\n\n return html`\n <div class=\"composer\" part=\"composer\">\n <textarea\n class=\"field\"\n part=\"field\"\n ref=\"${textareaRef}\"\n :rows=\"${() => props.rows.value ?? 1}\"\n :name=\"${() => props.name.value ?? ''}\"\n :placeholder=\"${() => props.placeholder.value ?? 'Message…'}\"\n :maxlength=\"${() => props.maxlength.value}\"\n ?disabled=\"${isDisabled}\"\n ?readonly=\"${() => Boolean(props.readonly.value)}\"\n ?required=\"${() => Boolean(props.required.value)}\"\n :value=\"${live(tf.value)}\"\n :aria-label=\"${() => props.label.value || 'Message'}\"\n :aria-keyshortcuts=\"${composer.keyShortcutsHint}\"\n :aria-describedby=\"${tf.ariaDescribedBy}\"\n :aria-errormessage=\"${tf.ariaErrorMessage}\"\n :aria-invalid=\"${tf.ariaInvalid}\"></textarea>\n ${renderStatusIcon(tf.errorText)} ${renderFieldStatusRegion(tf)}\n <div class=\"toolbar\" part=\"toolbar\">\n <div class=\"toolbar-start\" part=\"toolbar-start\">\n <slot name=\"prefix\"></slot>\n </div>\n <div class=\"toolbar-end\" part=\"toolbar-end\">\n <slot name=\"suffix\"></slot>\n <slot name=\"send\"></slot>\n ${() =>\n slots.has('send').value\n ? ''\n : html`<ore-button\n class=\"send-btn\"\n part=\"send-button\"\n type=\"button\"\n icon-only\n variant=\"solid\"\n :color=\"${() => props.color.value || 'primary'}\"\n :size=\"${fCtxProps.size}\"\n :label=\"${() => props['send-label'].value || DEFAULT_SEND_LABEL}\"\n ?loading=\"${() => Boolean(props.loading.value)}\"\n ?disabled=\"${() => !composer.canSend.value}\"\n @click=\"${(e: MouseEvent) => composer.send(e)}\">\n <ore-icon name=\"${() => props['send-icon'].value || SEND_ICON}\" size=\"16\"></ore-icon>\n </ore-button>`}\n </div>\n </div>\n </div>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [\n colorThemeMixin,\n coarsePointerMixin,\n reducedMotionMixin,\n disabledLoadingMixin,\n forcedColorsMixin,\n forcedColorsFocusMixin('.field'),\n sizeVariantMixin(MESSAGE_COMPOSER_SIZE_PRESET),\n componentStyles,\n // Must come after `componentStyles` — see `ore-input`'s identical ordering note for why\n // (`@layer` precedence is fixed by which layer name is *first* referenced across this whole\n // array; `componentStyles` establishes `refine.base`, which this mixin's `refine.variants`\n // rules need to win over).\n fieldVariantMixin({ container: '.composer', text: '.field', tokenPrefix: 'message-composer' }),\n ],\n});\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAyCA,IAAM,IAAqB,gBACrB,IAAY,YAyIL,IAAuB;AACpC,EAAgC,GAAsB;CACpD,gBAAgB;CAChB,OAAO;EACL,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,iBAAiB,EAAK,KAAK,EAAI;EAC/B,OAAO,EAAK,OAAO;EACnB,WAAW,EAAK,KAAK,EAAK;EAC1B,QAAQ,EAAK,OAAO;EACpB,OAAO,EAAK,OAAO;EACnB,WAAW,EAAK,KAAK,KAAA,CAA+B;EACpD,MAA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,MAAO;uCAC5B,CAAC,EAAS,QAAQ,MAAM;+BAChC,MAAkB,EAAS,KAAK,CAAC,EAAE;4CACtB,EAAM,YAAY,CAAC,SAAS,EAAU;iCACjD;;;;;CAK/B;CACA,QAAQ,EAAE,gBAAgB,GAAK;CAC/B,QAAQ;EACN;EACA;EACA;EACA;EACA;EACA,EAAuB,QAAQ;EAC/B,EAAiB,CAA4B;EAC7C;EAKA,EAAkB;GAAE,WAAW;GAAa,MAAM;GAAU,aAAa;EAAmB,CAAC;CAC/F;AACF,CAAC"}
|
package/dist/number-input.cjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./styles/mixins/states.css.cjs"),t=require("./shared/prop-bundles.cjs"),n=require("./headless/spinner.cjs"),r=require("./inputs/shared/form-context.cjs"),i=require("./inputs/number-input/number-input.css.cjs");let a=require("@vielzeug/ore"),o=require("@vielzeug/ripple"),s=require("@vielzeug/arsenal");var c=`ore-number-input`;(0,a.define)(c,{formAssociated:!0,props:{...t.themableBundle,...t.sizableBundle,...t.disablableBundle,...t.roundableBundle,error:a.prop.string(),fullwidth:a.prop.bool(!1),helper:a.prop.string(),label:a.prop.string(),"label-placement":a.prop.oneOf([`inset`,`outside`],`inset`),"large-step":a.prop.json(void 0),max:a.prop.json(void 0),min:a.prop.json(void 0),name:a.prop.string(),placeholder:a.prop.string(),readonly:a.prop.bool(!1),ref:a.prop.
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./styles/mixins/states.css.cjs"),t=require("./shared/prop-bundles.cjs"),n=require("./headless/spinner.cjs"),r=require("./inputs/shared/form-context.cjs"),i=require("./inputs/number-input/number-input.css.cjs");let a=require("@vielzeug/ore"),o=require("@vielzeug/ripple"),s=require("@vielzeug/arsenal");var c=`ore-number-input`;(0,a.define)(c,{formAssociated:!0,props:{...t.themableBundle,...t.sizableBundle,...t.disablableBundle,...t.roundableBundle,error:a.prop.string(),fullwidth:a.prop.bool(!1),helper:a.prop.string(),label:a.prop.string(),"label-placement":a.prop.oneOf([`inset`,`outside`],`inset`),"large-step":a.prop.json(void 0),loading:a.prop.bool(!1),max:a.prop.json(void 0),min:a.prop.json(void 0),name:a.prop.string(),placeholder:a.prop.string(),readonly:a.prop.bool(!1),ref:a.prop.data(),step:a.prop.number(1),success:a.prop.bool(!1),value:a.prop.json(void 0),variant:a.prop.string()},setup(e){let t=(0,a.useEmit)(),i=a.watchEffect,c=r.useFormContext(e,(0,a.inject)(r.FORM_CTX)),l=(0,o.computed)(()=>c.disabled.value||e.loading.value),u=(0,o.computed)(()=>!!e.readonly.value),d=(0,o.signal)(e.value.value==null?``:String(e.value.value));(0,o.watch)(e.value,e=>{let t=e==null?``:String(e);d.value!==t&&(d.value=t)});function f(){let e=d.value.trim();if(!e)return null;let t=Number.parseFloat(e);return Number.isNaN(t)?null:t}function p(n,r){let i=e.min.value==null?void 0:Number(e.min.value),a=e.max.value==null?void 0:Number(e.max.value),o=n==null?null:(0,s.clamp)(n,i,a),c=o==null?``:String(o);d.value!==c&&(d.value=c),t(`change`,{originalEvent:r,value:o})}let m=n.createSpinnerControl({commit:p,disabled:l,largeStep:e[`large-step`],max:e.max,min:e.min,parse:f,readonly:u,step:e.step}),h=(0,a.ref)(),g=null,_=null,v=null,y=n=>{if(!n){g?.(),_?.(),v?.dispose(),g=null,_=null,v=null,e.ref.value?.(null);return}n.setAttribute(`inputmode`,`decimal`),n.setAttribute(`role`,`spinbutton`);let r=e=>{let t=e.target.value,n=t===``?null:Number.parseFloat(t);p(Number.isNaN(n??NaN)?null:n,e)},a=e=>{let n=e.target.value,r=n===``?null:Number.parseFloat(n);d.value=n,t(`input`,{originalEvent:e,value:Number.isNaN(r??NaN)?null:r})};n.addEventListener(`change`,r),n.addEventListener(`input`,a),_=()=>{n.removeEventListener(`change`,r),n.removeEventListener(`input`,a)},g=i(()=>{let t=f();t==null?n.removeAttribute(`aria-valuenow`):n.setAttribute(`aria-valuenow`,String(t)),e.min.value==null?n.removeAttribute(`aria-valuemin`):n.setAttribute(`aria-valuemin`,String(e.min.value)),e.max.value==null?n.removeAttribute(`aria-valuemax`):n.setAttribute(`aria-valuemax`,String(e.max.value)),u.value?n.setAttribute(`aria-readonly`,`true`):n.removeAttribute(`aria-readonly`)}),e.ref.value?.(n),v=(0,o.watch)(e.ref,e=>{e?.(n)})};(0,a.onElement)(h,e=>{e.ref=y}),(0,a.bind)({attr:{size:c.size,value:()=>d.value||null,variant:c.variant}});let b=(0,o.computed)(()=>l.value||u.value);return a.html`
|
|
2
2
|
<ore-input
|
|
3
3
|
class="field"
|
|
4
4
|
part="field control"
|
|
@@ -14,9 +14,11 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
|
|
|
14
14
|
:color="${()=>e.color.value??``}"
|
|
15
15
|
:variant="${()=>e.variant.value??``}"
|
|
16
16
|
:rounded="${()=>e.rounded.value}"
|
|
17
|
-
?disabled="${
|
|
17
|
+
?disabled="${c.disabled}"
|
|
18
18
|
?readonly="${u}"
|
|
19
19
|
?fullwidth="${()=>e.fullwidth.value}"
|
|
20
|
+
?loading="${()=>e.loading.value}"
|
|
21
|
+
?success="${()=>e.success.value}"
|
|
20
22
|
@keydown="${e=>m.handleKeydown(e)}">
|
|
21
23
|
<button
|
|
22
24
|
slot="prefix"
|
|
@@ -37,5 +39,5 @@ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=requi
|
|
|
37
39
|
<ore-icon name="plus" size="14" stroke-width="2.5" aria-hidden="true"></ore-icon>
|
|
38
40
|
</button>
|
|
39
41
|
</ore-input>
|
|
40
|
-
`},shadow:{delegatesFocus:!0},styles:[e.
|
|
42
|
+
`},shadow:{delegatesFocus:!0},styles:[e.disabledLoadingMixin,i.default]}),exports.NUMBER_INPUT_TAG=c;
|
|
41
43
|
//# sourceMappingURL=number-input.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number-input.cjs","names":[],"sources":["../src/inputs/number-input/number-input.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { define, html, inject, prop, ref, bind, onElement, useEmit, watchEffect } from '@vielzeug/ore';\nimport { computed, signal, watch as rippleWatch } from '@vielzeug/ripple';\n\nimport type { ComponentSize, ThemeColor, VisualVariant } from '../../types';\n\nimport { createSpinnerControl } from '../../headless';\nimport '../../content/icon/icon';\nimport '../input/input';\nimport { disablableBundle, roundableBundle, sizableBundle, themableBundle } from '../../shared';\nimport { disabledStateMixin } from '../../styles';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport styles from './number-input.css?inline';\n\nexport type OreNumberInputEvents = {\n change: { originalEvent?: Event; value: number | null };\n input: { originalEvent?: Event; value: number | null };\n};\n\n/** Number Input props */\nexport type OreNumberInputProps = {\n /** Theme color */\n color?: ThemeColor;\n /** Disable interaction */\n disabled?: boolean;\n /** Error message */\n error?: string;\n /** Stretch to full width of container */\n fullwidth?: boolean;\n /** Helper text */\n helper?: string;\n /** Visible label */\n label?: string;\n /** Label placement: 'inset' renders the label inside the control box, 'outside' renders it above */\n 'label-placement'?: 'inset' | 'outside';\n /** Large step (for Page Up/Down, default: 10 × step) */\n 'large-step'?: number;\n /** Maximum allowed value */\n max?: number;\n /** Minimum allowed value */\n min?: number;\n /** Form field name */\n name?: string;\n /** Placeholder text */\n placeholder?: string;\n /** Make the input read-only */\n readonly?: boolean;\n /**\n * JS-only callback fired with the inner `<input>` element when it mounts,\n * and with `null` when it unmounts.\n * Set as a JS property: `bitNumberInput.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLInputElement | null) => void) | null;\n /** Border radius */\n rounded?: string;\n /** Component size */\n size?: ComponentSize;\n /** Step size for increment/decrement */\n step?: number;\n /** Current numeric value */\n value?: number;\n /** Visual variant */\n variant?: VisualVariant;\n};\n\n/**\n * A numeric spin-button input with +/− controls, min/max clamping, and full keyboard support.\n *\n * @element ore-number-input\n *\n * @attr {number} value - Current value\n * @attr {number} min - Minimum value\n * @attr {number} max - Maximum value\n * @attr {number} step - Increment/decrement step (default: 1)\n * @attr {number} large-step - Step for Page Up/Down (default: 10)\n * @attr {boolean} disabled - Disables the control\n * @attr {boolean} readonly - Read-only mode\n * @attr {string} label - Visible label\n * @attr {string} name - Form field name\n * @attr {string} color - Theme color: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'\n * @attr {string} size - 'sm' | 'md' | 'lg'\n * @attr {string} placeholder - Input placeholder\n *\n * @fires change - On committed value change. detail: { value: number | null, originalEvent?: Event }\n * @fires input - On every keystroke. detail: { value: number | null, originalEvent?: Event }\n *\n * @slot prefix - Content before the input (e.g. icon)\n * @slot suffix - Content after the input (e.g. unit label)\n * @slot label - Custom label content\n * @slot helper - Custom helper text content\n * @slot error - Custom error content\n *\n * @cssprop --number-input-height - Control height\n * @cssprop --number-input-border-color - Border color\n * @cssprop --number-input-radius - Border radius\n * @cssprop --number-input-bg - Background\n * @cssprop --number-input-btn-bg - Spin button background\n *\n * @part control - Control container.\n * @part decrement-btn - Decrement stepper button.\n * @part input - Input element.\n * @part increment-btn - Increment stepper button.\n * @example\n * ```html\n * <ore-number-input label=\"Quantity\" value=\"1\" min=\"1\" max=\"99\" step=\"1\"></ore-number-input>\n * ```\n */\nexport const NUMBER_INPUT_TAG = 'ore-number-input' as const;\ndefine<OreNumberInputProps>(NUMBER_INPUT_TAG, {\n formAssociated: true,\n props: {\n ...themableBundle,\n ...sizableBundle,\n ...disablableBundle,\n ...roundableBundle,\n error: prop.string(),\n fullwidth: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n 'label-placement': prop.oneOf(['inset', 'outside'] as const, 'inset'),\n 'large-step': prop.json(undefined as number | undefined),\n max: prop.json(undefined as number | undefined),\n min: prop.json(undefined as number | undefined),\n name: prop.string(),\n placeholder: prop.string(),\n readonly: prop.bool(false),\n ref: prop.json(undefined as ((el: HTMLInputElement | null) => void) | null | undefined),\n step: prop.number(1),\n value: prop.json(undefined as number | undefined),\n variant: prop.string<VisualVariant>(),\n },\n setup(props) {\n const emit = useEmit<OreNumberInputEvents>();\n const watch = watchEffect;\n\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n const isDisabled = fCtxProps.disabled;\n const isReadonly = computed(() => Boolean(props.readonly.value));\n\n // Internal numeric value signal (string representation for the input)\n const fieldValue = signal(props.value.value != null ? String(props.value.value) : '');\n\n // Keep fieldValue in sync when props.value changes externally\n rippleWatch(props.value, (v) => {\n const next = v != null ? String(v) : '';\n\n if (fieldValue.value !== next) fieldValue.value = next;\n });\n\n function parseValue(): number | null {\n const v = fieldValue.value.trim();\n\n if (!v) return null;\n\n const n = Number.parseFloat(v);\n\n return Number.isNaN(n) ? null : n;\n }\n\n function commit(val: number | null, originalEvent?: Event) {\n const min = props.min.value != null ? Number(props.min.value) : undefined;\n const max = props.max.value != null ? Number(props.max.value) : undefined;\n const clamped = val != null ? clamp(val, min, max) : null;\n const nextValue = clamped != null ? String(clamped) : '';\n\n if (fieldValue.value !== nextValue) fieldValue.value = nextValue;\n\n emit('change', { originalEvent, value: clamped });\n }\n\n const spinner = createSpinnerControl({\n commit,\n disabled: isDisabled,\n largeStep: props['large-step'],\n max: props.max,\n min: props.min,\n parse: parseValue,\n readonly: isReadonly,\n step: props.step,\n });\n\n // Composition uses ore-input's own documented `ref` prop (fired with the raw\n // <input> on mount, `null` on unmount) instead of reaching into its shadow DOM —\n // see `packages/refine/AGENTS.md` / input.ts's `ref` JSDoc for the supported contract.\n // Set imperatively (rather than declared in the template) because ore's template\n // engine treats a function-valued attr binding as a reactive getter to invoke, not\n // a literal value to assign — a plain property assignment avoids that entirely.\n const bitInputRef = ref<HTMLElementTagNameMap['ore-input']>();\n let stopAriaWatch: (() => void) | null = null;\n let detachListeners: (() => void) | null = null;\n let refSub: { dispose(): void } | null = null;\n\n const handleFieldRef = (rawInput: HTMLInputElement | null): void => {\n if (!rawInput) {\n stopAriaWatch?.();\n detachListeners?.();\n refSub?.dispose();\n stopAriaWatch = null;\n detachListeners = null;\n refSub = null;\n props.ref.value?.(null);\n\n return;\n }\n\n rawInput.setAttribute('inputmode', 'decimal');\n // The wrapper div is a plain layout container — WAI-ARIA spinbutton semantics\n // live on the actually-focusable element (the raw <input> rendered by ore-input).\n rawInput.setAttribute('role', 'spinbutton');\n\n const handleChange = (e: Event) => {\n const val = (e.target as HTMLInputElement).value;\n const n = val !== '' ? Number.parseFloat(val) : null;\n\n commit(Number.isNaN(n ?? NaN) ? null : n, e);\n };\n\n const handleInput = (e: Event) => {\n const val = (e.target as HTMLInputElement).value;\n const n = val !== '' ? Number.parseFloat(val) : null;\n\n fieldValue.value = val;\n emit('input', { originalEvent: e, value: Number.isNaN(n ?? NaN) ? null : n });\n };\n\n rawInput.addEventListener('change', handleChange);\n rawInput.addEventListener('input', handleInput);\n detachListeners = () => {\n rawInput.removeEventListener('change', handleChange);\n rawInput.removeEventListener('input', handleInput);\n };\n\n stopAriaWatch = watch(() => {\n const now = parseValue();\n\n if (now == null) rawInput.removeAttribute('aria-valuenow');\n else rawInput.setAttribute('aria-valuenow', String(now));\n\n if (props.min.value != null) rawInput.setAttribute('aria-valuemin', String(props.min.value));\n else rawInput.removeAttribute('aria-valuemin');\n\n if (props.max.value != null) rawInput.setAttribute('aria-valuemax', String(props.max.value));\n else rawInput.removeAttribute('aria-valuemax');\n\n if (isReadonly.value) rawInput.setAttribute('aria-readonly', 'true');\n else rawInput.removeAttribute('aria-readonly');\n });\n\n // Fire user ref callback\n props.ref.value?.(rawInput);\n\n refSub = rippleWatch(props.ref, (cb) => {\n cb?.(rawInput);\n });\n };\n\n // ore-input's own onElement/ref lifecycle calls this back with `null` when its\n // inner <input> unmounts, so no explicit teardown is needed here.\n onElement(bitInputRef, (bitInputEl) => {\n bitInputEl.ref = handleFieldRef;\n });\n\n bind({\n attr: {\n size: fCtxProps.size,\n value: () => fieldValue.value || null,\n variant: fCtxProps.variant,\n },\n });\n\n const isNonInteractive = computed(() => isDisabled.value || isReadonly.value);\n\n // The stepper buttons are slotted *into* ore-input's own `prefix`/`suffix` slots instead of\n // sitting outside it in a separate wrapper — they render inside ore-input's own bordered\n // box (same as its built-in clear/password-toggle buttons), matching every other field's\n // single-box look instead of floating as two detached icon buttons either side of a\n // narrow field. `@keydown` moves to ore-input itself: native keyboard events are\n // `composed: true` and bubble out past a shadow boundary, so it still sees keydowns\n // originating from ore-input's internal <input> as well as from these slotted buttons.\n return html`\n <ore-input\n class=\"field\"\n part=\"field control\"\n ref=\"${bitInputRef}\"\n :value=\"${() => fieldValue.value}\"\n :label=\"${() => props.label.value ?? ''}\"\n :label-placement=\"${() => props['label-placement'].value ?? 'inset'}\"\n :placeholder=\"${() => props.placeholder.value ?? ''}\"\n :name=\"${() => props.name.value ?? ''}\"\n :helper=\"${() => props.helper.value ?? ''}\"\n :error=\"${() => props.error.value ?? ''}\"\n :size=\"${fCtxProps.size}\"\n :color=\"${() => props.color.value ?? ''}\"\n :variant=\"${() => props.variant.value ?? ''}\"\n :rounded=\"${() => props.rounded.value}\"\n ?disabled=\"${isDisabled}\"\n ?readonly=\"${isReadonly}\"\n ?fullwidth=\"${() => props.fullwidth.value}\"\n @keydown=\"${(e: KeyboardEvent) => spinner.handleKeydown(e)}\">\n <button\n slot=\"prefix\"\n type=\"button\"\n part=\"decrement-btn\"\n aria-label=\"Decrease\"\n ?disabled=\"${() => isNonInteractive.value || spinner.atMin()}\"\n @click=\"${(e: Event) => spinner.incrementBy(-(Number(props.step.value) || 1), e)}\">\n <ore-icon name=\"minus\" size=\"14\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n <button\n slot=\"suffix\"\n type=\"button\"\n part=\"increment-btn\"\n aria-label=\"Increase\"\n ?disabled=\"${() => isNonInteractive.value || spinner.atMax()}\"\n @click=\"${(e: Event) => spinner.incrementBy(Number(props.step.value) || 1, e)}\">\n <ore-icon name=\"plus\" size=\"14\" stroke-width=\"2.5\" aria-hidden=\"true\"></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,IAAI;;;;eAIA,EAAY;sBACH,EAAW,MAAM;sBACjB,EAAM,MAAM,OAAS,GAAG;gCACd,EAAM,kBAAkB,CAAC,OAAS,QAAQ;4BAC9C,EAAM,YAAY,OAAS,GAAG;qBACrC,EAAM,KAAK,OAAS,GAAG;uBACrB,EAAM,OAAO,OAAS,GAAG;sBAC1B,EAAM,MAAM,OAAS,GAAG;iBAC/B,EAAU,KAAK;sBACR,EAAM,MAAM,OAAS,GAAG;wBACtB,EAAM,QAAQ,OAAS,GAAG;wBAC1B,EAAM,QAAQ,MAAM;qBACzB,EAAW;qBACX,EAAW;0BACJ,EAAM,UAAU,MAAM;oBAC7B,GAAqB,EAAQ,cAAc,CAAC,EAAE;;;;;;2BAMtC,EAAiB,OAAS,EAAQ,MAAM,EAAE;oBAClD,GAAa,EAAQ,YAAY,EAAE,OAAO,EAAM,KAAK,KAAK,GAAK,GAAI,CAAC,EAAE;;;;;;;;2BAQ9D,EAAiB,OAAS,EAAQ,MAAM,EAAE;oBAClD,GAAa,EAAQ,YAAY,OAAO,EAAM,KAAK,KAAK,GAAK,EAAG,CAAC,EAAE;;;;KAKtF,EACA,OAAQ,CAAE,eAAgB,EAAK,EAC/B,OAAQ,CAAC,EAAA,mBAAoB,EAAA,OAAM,CACrC,CAAC"}
|
|
1
|
+
{"version":3,"file":"number-input.cjs","names":[],"sources":["../src/inputs/number-input/number-input.ts"],"sourcesContent":["import { clamp } from '@vielzeug/arsenal';\nimport { define, html, inject, prop, ref, bind, onElement, useEmit, watchEffect } from '@vielzeug/ore';\nimport { computed, signal, watch as rippleWatch } from '@vielzeug/ripple';\n\nimport type { ComponentSize, ThemeColor, VisualVariant } from '../../types';\n\nimport { createSpinnerControl } from '../../headless';\nimport '../../content/icon/icon';\nimport '../input/input';\nimport { disablableBundle, roundableBundle, sizableBundle, themableBundle } from '../../shared';\nimport { disabledLoadingMixin } from '../../styles';\nimport { FORM_CTX, useFormContext } from '../shared/form-context';\nimport componentStyles from './number-input.css?inline';\n\nexport type OreNumberInputEvents = {\n change: { originalEvent?: Event; value: number | null };\n input: { originalEvent?: Event; value: number | null };\n};\n\n/** Number Input props */\nexport type OreNumberInputProps = {\n /** Theme color */\n color?: ThemeColor;\n /** Disable interaction */\n disabled?: boolean;\n /** Error message */\n error?: string;\n /** Stretch to full width of container */\n fullwidth?: boolean;\n /** Helper text */\n helper?: string;\n /** Visible label */\n label?: string;\n /** Label placement: 'inset' renders the label inside the control box, 'outside' renders it above */\n 'label-placement'?: 'inset' | 'outside';\n /** Large step (for Page Up/Down, default: 10 × step) */\n 'large-step'?: number;\n /**\n * Shows an inline spinner inside the field and forces the control into `disabled` for the\n * duration — use while an async validation/submission request is in flight to prevent\n * double-submits.\n */\n loading?: boolean;\n /** Maximum allowed value */\n max?: number;\n /** Minimum allowed value */\n min?: number;\n /** Form field name */\n name?: string;\n /** Placeholder text */\n placeholder?: string;\n /** Make the input read-only */\n readonly?: boolean;\n /**\n * JS-only callback fired with the inner `<input>` element when it mounts,\n * and with `null` when it unmounts.\n * Set as a JS property: `bitNumberInput.ref = (el) => { ... }`.\n */\n ref?: ((el: HTMLInputElement | null) => void) | null;\n /** Border radius */\n rounded?: string;\n /** Component size */\n size?: ComponentSize;\n /** Step size for increment/decrement */\n step?: number;\n /**\n * Shows an inline green check icon inside the field to confirm the value has\n * passed validation. Ignored while `error` is set — an error always wins.\n */\n success?: boolean;\n /** Current numeric value */\n value?: number;\n /** Visual variant */\n variant?: VisualVariant;\n};\n\n/**\n * A numeric spin-button input with +/− controls, min/max clamping, and full keyboard support.\n *\n * @element ore-number-input\n *\n * @attr {number} value - Current value\n * @attr {number} min - Minimum value\n * @attr {number} max - Maximum value\n * @attr {number} step - Increment/decrement step (default: 1)\n * @attr {number} large-step - Step for Page Up/Down (default: 10)\n * @attr {boolean} disabled - Disables the control\n * @attr {boolean} readonly - Read-only mode\n * @attr {boolean} loading - Show an inline spinner and force the control disabled\n * @attr {boolean} success - Show an inline success check icon (suppressed while `error` is set)\n * @attr {string} label - Visible label\n * @attr {string} name - Form field name\n * @attr {string} color - Theme color: 'primary' | 'secondary' | 'info' | 'success' | 'warning' | 'error'\n * @attr {string} size - 'sm' | 'md' | 'lg'\n * @attr {string} placeholder - Input placeholder\n *\n * @fires change - On committed value change. detail: { value: number | null, originalEvent?: Event }\n * @fires input - On every keystroke. detail: { value: number | null, originalEvent?: Event }\n *\n * @slot prefix - Content before the input (e.g. icon)\n * @slot suffix - Content after the input (e.g. unit label)\n * @slot label - Custom label content\n * @slot helper - Custom helper text content\n * @slot error - Custom error content\n *\n * @cssprop --number-input-height - Control height\n * @cssprop --number-input-border-color - Border color\n * @cssprop --number-input-radius - Border radius\n * @cssprop --number-input-bg - Background\n * @cssprop --number-input-btn-bg - Spin button background\n *\n * @part control - Control container.\n * @part decrement-btn - Decrement stepper button.\n * @part input - Input element.\n * @part increment-btn - Increment stepper button.\n * @example\n * ```html\n * <ore-number-input label=\"Quantity\" value=\"1\" min=\"1\" max=\"99\" step=\"1\"></ore-number-input>\n * <ore-number-input label=\"Quantity\" success></ore-number-input>\n * <ore-number-input label=\"Quantity\" loading></ore-number-input>\n * ```\n */\nexport const NUMBER_INPUT_TAG = 'ore-number-input' as const;\ndefine<OreNumberInputProps>(NUMBER_INPUT_TAG, {\n formAssociated: true,\n props: {\n ...themableBundle,\n ...sizableBundle,\n ...disablableBundle,\n ...roundableBundle,\n error: prop.string(),\n fullwidth: prop.bool(false),\n helper: prop.string(),\n label: prop.string(),\n 'label-placement': prop.oneOf(['inset', 'outside'] as const, 'inset'),\n 'large-step': prop.json(undefined as number | undefined),\n loading: prop.bool(false),\n max: prop.json(undefined as number | undefined),\n min: prop.json(undefined as number | undefined),\n name: prop.string(),\n placeholder: prop.string(),\n readonly: prop.bool(false),\n ref: prop.data<((el: HTMLInputElement | null) => void) | null>(),\n step: prop.number(1),\n success: prop.bool(false),\n value: prop.json(undefined as number | undefined),\n variant: prop.string<VisualVariant>(),\n },\n setup(props) {\n const emit = useEmit<OreNumberInputEvents>();\n const watch = watchEffect;\n\n const formCtx = inject(FORM_CTX);\n const fCtxProps = useFormContext(props, formCtx);\n // `loading` behaves like a temporary `disabled` — see ore-input's identical computation.\n const isDisabled = computed(() => fCtxProps.disabled.value || props.loading.value);\n const isReadonly = computed(() => Boolean(props.readonly.value));\n\n // Internal numeric value signal (string representation for the input)\n const fieldValue = signal(props.value.value != null ? String(props.value.value) : '');\n\n // Keep fieldValue in sync when props.value changes externally\n rippleWatch(props.value, (v) => {\n const next = v != null ? String(v) : '';\n\n if (fieldValue.value !== next) fieldValue.value = next;\n });\n\n function parseValue(): number | null {\n const v = fieldValue.value.trim();\n\n if (!v) return null;\n\n const n = Number.parseFloat(v);\n\n return Number.isNaN(n) ? null : n;\n }\n\n function commit(val: number | null, originalEvent?: Event) {\n const min = props.min.value != null ? Number(props.min.value) : undefined;\n const max = props.max.value != null ? Number(props.max.value) : undefined;\n const clamped = val != null ? clamp(val, min, max) : null;\n const nextValue = clamped != null ? String(clamped) : '';\n\n if (fieldValue.value !== nextValue) fieldValue.value = nextValue;\n\n emit('change', { originalEvent, value: clamped });\n }\n\n const spinner = createSpinnerControl({\n commit,\n disabled: isDisabled,\n largeStep: props['large-step'],\n max: props.max,\n min: props.min,\n parse: parseValue,\n readonly: isReadonly,\n step: props.step,\n });\n\n // Composition uses ore-input's own documented `ref` prop (fired with the raw\n // <input> on mount, `null` on unmount) instead of reaching into its shadow DOM —\n // see `packages/refine/AGENTS.md` / input.ts's `ref` JSDoc for the supported contract.\n // Set imperatively (rather than declared in the template) because ore's template\n // engine treats a function-valued attr binding as a reactive getter to invoke, not\n // a literal value to assign — a plain property assignment avoids that entirely.\n const bitInputRef = ref<HTMLElementTagNameMap['ore-input']>();\n let stopAriaWatch: (() => void) | null = null;\n let detachListeners: (() => void) | null = null;\n let refSub: { dispose(): void } | null = null;\n\n const handleFieldRef = (rawInput: HTMLInputElement | null): void => {\n if (!rawInput) {\n stopAriaWatch?.();\n detachListeners?.();\n refSub?.dispose();\n stopAriaWatch = null;\n detachListeners = null;\n refSub = null;\n props.ref.value?.(null);\n\n return;\n }\n\n rawInput.setAttribute('inputmode', 'decimal');\n // The wrapper div is a plain layout container — WAI-ARIA spinbutton semantics\n // live on the actually-focusable element (the raw <input> rendered by ore-input).\n rawInput.setAttribute('role', 'spinbutton');\n\n const handleChange = (e: Event) => {\n const val = (e.target as HTMLInputElement).value;\n const n = val !== '' ? Number.parseFloat(val) : null;\n\n commit(Number.isNaN(n ?? NaN) ? null : n, e);\n };\n\n const handleInput = (e: Event) => {\n const val = (e.target as HTMLInputElement).value;\n const n = val !== '' ? Number.parseFloat(val) : null;\n\n fieldValue.value = val;\n emit('input', { originalEvent: e, value: Number.isNaN(n ?? NaN) ? null : n });\n };\n\n rawInput.addEventListener('change', handleChange);\n rawInput.addEventListener('input', handleInput);\n detachListeners = () => {\n rawInput.removeEventListener('change', handleChange);\n rawInput.removeEventListener('input', handleInput);\n };\n\n stopAriaWatch = watch(() => {\n const now = parseValue();\n\n if (now == null) rawInput.removeAttribute('aria-valuenow');\n else rawInput.setAttribute('aria-valuenow', String(now));\n\n if (props.min.value != null) rawInput.setAttribute('aria-valuemin', String(props.min.value));\n else rawInput.removeAttribute('aria-valuemin');\n\n if (props.max.value != null) rawInput.setAttribute('aria-valuemax', String(props.max.value));\n else rawInput.removeAttribute('aria-valuemax');\n\n if (isReadonly.value) rawInput.setAttribute('aria-readonly', 'true');\n else rawInput.removeAttribute('aria-readonly');\n });\n\n // Fire user ref callback\n props.ref.value?.(rawInput);\n\n refSub = rippleWatch(props.ref, (cb) => {\n cb?.(rawInput);\n });\n };\n\n // ore-input's own onElement/ref lifecycle calls this back with `null` when its\n // inner <input> unmounts, so no explicit teardown is needed here.\n onElement(bitInputRef, (bitInputEl) => {\n bitInputEl.ref = handleFieldRef;\n });\n\n bind({\n attr: {\n size: fCtxProps.size,\n value: () => fieldValue.value || null,\n variant: fCtxProps.variant,\n },\n });\n\n const isNonInteractive = computed(() => isDisabled.value || isReadonly.value);\n\n // The stepper buttons are slotted *into* ore-input's own `prefix`/`suffix` slots instead of\n // sitting outside it in a separate wrapper — they render inside ore-input's own bordered\n // box (same as its built-in clear/password-toggle buttons), matching every other field's\n // single-box look instead of floating as two detached icon buttons either side of a\n // narrow field. `@keydown` moves to ore-input itself: native keyboard events are\n // `composed: true` and bubble out past a shadow boundary, so it still sees keydowns\n // originating from ore-input's internal <input> as well as from these slotted buttons.\n return html`\n <ore-input\n class=\"field\"\n part=\"field control\"\n ref=\"${bitInputRef}\"\n :value=\"${() => fieldValue.value}\"\n :label=\"${() => props.label.value ?? ''}\"\n :label-placement=\"${() => props['label-placement'].value ?? 'inset'}\"\n :placeholder=\"${() => props.placeholder.value ?? ''}\"\n :name=\"${() => props.name.value ?? ''}\"\n :helper=\"${() => props.helper.value ?? ''}\"\n :error=\"${() => props.error.value ?? ''}\"\n :size=\"${fCtxProps.size}\"\n :color=\"${() => props.color.value ?? ''}\"\n :variant=\"${() => props.variant.value ?? ''}\"\n :rounded=\"${() => props.rounded.value}\"\n ?disabled=\"${fCtxProps.disabled}\"\n ?readonly=\"${isReadonly}\"\n ?fullwidth=\"${() => props.fullwidth.value}\"\n ?loading=\"${() => props.loading.value}\"\n ?success=\"${() => props.success.value}\"\n @keydown=\"${(e: KeyboardEvent) => spinner.handleKeydown(e)}\">\n <button\n slot=\"prefix\"\n type=\"button\"\n part=\"decrement-btn\"\n aria-label=\"Decrease\"\n ?disabled=\"${() => isNonInteractive.value || spinner.atMin()}\"\n @click=\"${(e: Event) => spinner.incrementBy(-(Number(props.step.value) || 1), e)}\">\n <ore-icon name=\"minus\" size=\"14\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n <button\n slot=\"suffix\"\n type=\"button\"\n part=\"increment-btn\"\n aria-label=\"Increase\"\n ?disabled=\"${() => isNonInteractive.value || spinner.atMax()}\"\n @click=\"${(e: Event) => spinner.incrementBy(Number(props.step.value) || 1, e)}\">\n <ore-icon name=\"plus\" size=\"14\" stroke-width=\"2.5\" aria-hidden=\"true\"></ore-icon>\n </button>\n </ore-input>\n `;\n },\n shadow: { delegatesFocus: true },\n styles: [disabledLoadingMixin, componentStyles],\n});\n"],"mappings":"kYA0HA,IAAa,EAAmB,gCACJ,EAAkB,CAC5C,eAAgB,GAChB,MAAO,CACL,GAAG,EAAA,eACH,GAAG,EAAA,cACH,GAAG,EAAA,iBACH,GAAG,EAAA,gBACH,MAAO,EAAA,KAAK,OAAO,EACnB,UAAW,EAAA,KAAK,KAAK,EAAK,EAC1B,OAAQ,EAAA,KAAK,OAAO,EACpB,MAAO,EAAA,KAAK,OAAO,EACnB,kBAAmB,EAAA,KAAK,MAAM,CAAC,QAAS,SAAS,EAAY,OAAO,EACpE,aAAc,EAAA,KAAK,KAAK,IAAA,EAA+B,EACvD,QAAS,EAAA,KAAK,KAAK,EAAK,EACxB,IAAK,EAAA,KAAK,KAAK,IAAA,EAA+B,EAC9C,IAAK,EAAA,KAAK,KAAK,IAAA,EAA+B,EAC9C,KAAM,EAAA,KAAK,OAAO,EAClB,YAAa,EAAA,KAAK,OAAO,EACzB,SAAU,EAAA,KAAK,KAAK,EAAK,EACzB,IAAK,EAAA,KAAK,KAAqD,EAC/D,KAAM,EAAA,KAAK,OAAO,CAAC,EACnB,QAAS,EAAA,KAAK,KAAK,EAAK,EACxB,MAAO,EAAA,KAAK,KAAK,IAAA,EAA+B,EAChD,QAAS,EAAA,KAAK,OAAsB,CACtC,EACA,MAAM,EAAO,CACX,IAAM,GAAA,EAAA,EAAA,QAAA,CAAqC,EACrC,EAAQ,EAAA,YAGR,EAAY,EAAA,eAAe,GAAA,EAAA,EAAA,OAAA,CADV,EAAA,QACiB,CAAO,EAEzC,GAAA,EAAA,EAAA,SAAA,KAA4B,EAAU,SAAS,OAAS,EAAM,QAAQ,KAAK,EAC3E,GAAA,EAAA,EAAA,SAAA,KAA4B,EAAQ,EAAM,SAAS,KAAM,EAGzD,GAAA,EAAA,EAAA,OAAA,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CACH,KAAM,CACJ,KAAM,EAAU,KAChB,UAAa,EAAW,OAAS,KACjC,QAAS,EAAU,OACrB,CACF,CAAC,EAED,IAAM,GAAA,EAAA,EAAA,SAAA,KAAkC,EAAW,OAAS,EAAW,KAAK,EAS5E,MAAO,GAAA,IAAI;;;;eAIA,EAAY;sBACH,EAAW,MAAM;sBACjB,EAAM,MAAM,OAAS,GAAG;gCACd,EAAM,kBAAkB,CAAC,OAAS,QAAQ;4BAC9C,EAAM,YAAY,OAAS,GAAG;qBACrC,EAAM,KAAK,OAAS,GAAG;uBACrB,EAAM,OAAO,OAAS,GAAG;sBAC1B,EAAM,MAAM,OAAS,GAAG;iBAC/B,EAAU,KAAK;sBACR,EAAM,MAAM,OAAS,GAAG;wBACtB,EAAM,QAAQ,OAAS,GAAG;wBAC1B,EAAM,QAAQ,MAAM;qBACzB,EAAU,SAAS;qBACnB,EAAW;0BACJ,EAAM,UAAU,MAAM;wBACxB,EAAM,QAAQ,MAAM;wBACpB,EAAM,QAAQ,MAAM;oBACzB,GAAqB,EAAQ,cAAc,CAAC,EAAE;;;;;;2BAMtC,EAAiB,OAAS,EAAQ,MAAM,EAAE;oBAClD,GAAa,EAAQ,YAAY,EAAE,OAAO,EAAM,KAAK,KAAK,GAAK,GAAI,CAAC,EAAE;;;;;;;;2BAQ9D,EAAiB,OAAS,EAAQ,MAAM,EAAE;oBAClD,GAAa,EAAQ,YAAY,OAAO,EAAM,KAAK,KAAK,GAAK,EAAG,CAAC,EAAE;;;;KAKtF,EACA,OAAQ,CAAE,eAAgB,EAAK,EAC/B,OAAQ,CAAC,EAAA,qBAAsB,EAAA,OAAe,CAChD,CAAC"}
|
package/dist/number-input.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { disabledLoadingMixin as e } from "./styles/mixins/states.css.js";
|
|
2
2
|
import { disablableBundle as t, roundableBundle as n, sizableBundle as r, themableBundle as i } from "./shared/prop-bundles.js";
|
|
3
3
|
import { createSpinnerControl as a } from "./headless/spinner.js";
|
|
4
4
|
import { FORM_CTX as o, useFormContext as s } from "./inputs/shared/form-context.js";
|
|
@@ -21,18 +21,20 @@ u(S, {
|
|
|
21
21
|
label: m.string(),
|
|
22
22
|
"label-placement": m.oneOf(["inset", "outside"], "inset"),
|
|
23
23
|
"large-step": m.json(void 0),
|
|
24
|
+
loading: m.bool(!1),
|
|
24
25
|
max: m.json(void 0),
|
|
25
26
|
min: m.json(void 0),
|
|
26
27
|
name: m.string(),
|
|
27
28
|
placeholder: m.string(),
|
|
28
29
|
readonly: m.bool(!1),
|
|
29
|
-
ref: m.
|
|
30
|
+
ref: m.data(),
|
|
30
31
|
step: m.number(1),
|
|
32
|
+
success: m.bool(!1),
|
|
31
33
|
value: m.json(void 0),
|
|
32
34
|
variant: m.string()
|
|
33
35
|
},
|
|
34
36
|
setup(e) {
|
|
35
|
-
let t = g(), n = _, r = s(e, f(o)), i = r.disabled, c = v(() => !!e.readonly.value), u = y(e.value.value == null ? "" : String(e.value.value));
|
|
37
|
+
let t = g(), n = _, r = s(e, f(o)), i = v(() => r.disabled.value || e.loading.value), c = v(() => !!e.readonly.value), u = y(e.value.value == null ? "" : String(e.value.value));
|
|
36
38
|
b(e.value, (e) => {
|
|
37
39
|
let t = e == null ? "" : String(e);
|
|
38
40
|
u.value !== t && (u.value = t);
|
|
@@ -108,9 +110,11 @@ u(S, {
|
|
|
108
110
|
:color="${() => e.color.value ?? ""}"
|
|
109
111
|
:variant="${() => e.variant.value ?? ""}"
|
|
110
112
|
:rounded="${() => e.rounded.value}"
|
|
111
|
-
?disabled="${
|
|
113
|
+
?disabled="${r.disabled}"
|
|
112
114
|
?readonly="${c}"
|
|
113
115
|
?fullwidth="${() => e.fullwidth.value}"
|
|
116
|
+
?loading="${() => e.loading.value}"
|
|
117
|
+
?success="${() => e.success.value}"
|
|
114
118
|
@keydown="${(e) => C.handleKeydown(e)}">
|
|
115
119
|
<button
|
|
116
120
|
slot="prefix"
|