@choice-ui/react 1.4.3 → 1.4.6
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/components/alert-dialog/dist/index.d.ts +20 -41
- package/dist/components/alert-dialog/dist/index.js +497 -0
- package/dist/components/alert-dialog/src/alert-dialog.js +1 -1
- package/dist/components/alert-dialog/src/hooks/use-alert-dialog.d.ts +1 -1
- package/dist/components/alert-dialog/src/index.d.ts +4 -5
- package/dist/components/alert-dialog/src/types.d.ts +11 -11
- package/dist/components/avatar/dist/index.js +4 -4
- package/dist/components/avatar/src/avatar.js +4 -4
- package/dist/components/badge/src/badge.js +2 -2
- package/dist/components/badge/src/index.d.ts +2 -1
- package/dist/components/button/dist/index.js +4 -4
- package/dist/components/button/src/button.js +4 -4
- package/dist/components/calendar/dist/index.d.ts +296 -296
- package/dist/components/calendar/dist/index.js +57 -56
- package/dist/components/calendar/src/date-range-input/date-range-input.d.ts +5 -5
- package/dist/components/calendar/src/time-calendar/time-calendar.d.ts +3 -3
- package/dist/components/calendar/src/time-calendar/time-calendar.js +2 -2
- package/dist/components/calendar/src/time-input/time-input.d.ts +9 -9
- package/dist/components/calendar/src/time-input/time-input.js +4 -4
- package/dist/components/calendar/src/types.d.ts +165 -165
- package/dist/components/calendar/src/utils/constants.js +32 -31
- package/dist/components/calendar/src/utils/date-comparisons.d.ts +34 -34
- package/dist/components/calendar/src/utils/locale.d.ts +12 -12
- package/dist/components/calendar/src/utils/month.d.ts +3 -3
- package/dist/components/calendar/src/utils/month.js +1 -1
- package/dist/components/calendar/src/utils/parsers/month-names.js +3 -3
- package/dist/components/calendar/src/utils/parsers/numeric-utils.d.ts +20 -20
- package/dist/components/calendar/src/utils/parsers/numeric-utils.js +8 -8
- package/dist/components/calendar/src/utils/parsers/parsers.d.ts +17 -17
- package/dist/components/calendar/src/utils/parsers/parsers.js +2 -2
- package/dist/components/calendar/src/utils/parsers/prediction.d.ts +7 -7
- package/dist/components/calendar/src/utils/parsers/relative-dates.js +6 -6
- package/dist/components/calendar/src/utils/quarter.d.ts +13 -13
- package/dist/components/calendar/src/utils/quarter.js +6 -6
- package/dist/components/calendar/src/utils/time.d.ts +8 -8
- package/dist/components/calendar/src/utils/year.d.ts +3 -3
- package/dist/components/calendar/src/utils/year.js +3 -3
- package/dist/components/checkbox/dist/index.d.ts +1 -12
- package/dist/components/checkbox/dist/index.js +9 -9
- package/dist/components/checkbox/src/checkbox-label.js +2 -2
- package/dist/components/checkbox/src/checkbox.js +6 -5
- package/dist/components/checkbox/src/context.js +1 -1
- package/dist/components/checkbox/src/index.d.ts +0 -3
- package/dist/components/chip/dist/index.js +6 -6
- package/dist/components/chip/src/chip.js +6 -6
- package/dist/components/chip/src/index.d.ts +2 -1
- package/dist/components/chips-input/dist/index.js +270 -0
- package/dist/components/chips-input/src/index.d.ts +2 -1
- package/dist/components/code-block/dist/index.d.ts +14 -32
- package/dist/components/code-block/dist/index.js +211 -147
- package/dist/components/code-block/src/code-block.d.ts +8 -1
- package/dist/components/code-block/src/code-block.js +14 -3
- package/dist/components/code-block/src/components/code-block-code.js +31 -5
- package/dist/components/code-block/src/components/code-block-header.js +45 -10
- package/dist/components/code-block/src/index.d.ts +3 -9
- package/dist/components/combobox/dist/index.d.ts +21 -2
- package/dist/components/combobox/dist/index.js +16 -13
- package/dist/components/combobox/src/combobox-trigger.d.ts +1 -1
- package/dist/components/combobox/src/combobox-trigger.js +7 -4
- package/dist/components/combobox/src/combobox.d.ts +20 -1
- package/dist/components/combobox/src/combobox.js +10 -10
- package/dist/components/command/dist/index.d.ts +65 -4
- package/dist/components/command/src/command.js +6 -5
- package/dist/components/command/src/components/command-divider.d.ts +4 -1
- package/dist/components/command/src/components/command-group.d.ts +16 -1
- package/dist/components/command/src/components/command-group.js +56 -54
- package/dist/components/command/src/components/command-input.js +3 -3
- package/dist/components/command/src/components/command-item.d.ts +1 -1
- package/dist/components/command/src/components/command-item.js +117 -115
- package/dist/components/command/src/components/command-loading.d.ts +8 -0
- package/dist/components/command/src/components/command-loading.js +1 -1
- package/dist/components/command/src/context/create-command-context.js +1 -1
- package/dist/components/command/src/hooks/use-schedule-layout-effect.d.ts +1 -1
- package/dist/components/command/src/hooks/use-value.js +2 -2
- package/dist/components/command/src/index.d.ts +16 -8
- package/dist/components/command/src/tv.d.ts +30 -0
- package/dist/components/command/src/tv.js +10 -0
- package/dist/components/command/src/types.d.ts +8 -0
- package/dist/components/command/src/utils/constants.d.ts +1 -1
- package/dist/components/command/src/utils/constants.js +1 -1
- package/dist/components/command/src/utils/helpers.d.ts +0 -1
- package/dist/components/command/src/utils/helpers.js +1 -3
- package/dist/components/command/src/utils/index.d.ts +1 -0
- package/dist/components/comments/src/comment-input/components/comment-input-mention-popover.js +4 -2
- package/dist/components/comments/src/comments.js +1 -1
- package/dist/components/context-input/dist/index.d.ts +47 -251
- package/dist/components/context-input/src/components/mention-menu.d.ts +5 -4
- package/dist/components/context-input/src/components/mention-menu.js +19 -4
- package/dist/components/context-input/src/components/mention.d.ts +2 -2
- package/dist/components/context-input/src/components/slate-editor.js +4 -2
- package/dist/components/context-input/src/context-input.js +31 -16
- package/dist/components/context-input/src/extensions/with-mentions.d.ts +1 -1
- package/dist/components/context-input/src/extensions/with-mentions.js +10 -9
- package/dist/components/context-input/src/hooks/use-context-input.js +87 -46
- package/dist/components/context-input/src/hooks/use-mentions.d.ts +11 -10
- package/dist/components/context-input/src/hooks/use-mentions.js +147 -128
- package/dist/components/context-input/src/index.d.ts +4 -5
- package/dist/components/context-input/src/types.d.ts +12 -12
- package/dist/components/context-input/src/utils/mention-spacing.d.ts +16 -16
- package/dist/components/context-input/src/utils/slate-converters.d.ts +6 -6
- package/dist/components/context-input/src/utils/slate-converters.js +2 -2
- package/dist/components/context-input/src/utils/text-extraction.js +7 -1
- package/dist/components/context-menu/src/context-menu.js +10 -4
- package/dist/components/dialog/dist/index.js +1 -2
- package/dist/components/dialog/src/dialog.js +0 -1
- package/dist/components/dialog/src/hooks/use-floating-dialog.js +1 -1
- package/dist/components/dialog/src/index.d.ts +3 -2
- package/dist/components/dropdown/dist/index.d.ts +1 -2
- package/dist/components/dropdown/dist/index.js +23 -8
- package/dist/components/dropdown/src/dropdown.d.ts +1 -2
- package/dist/components/dropdown/src/dropdown.js +23 -8
- package/dist/components/emoji-picker/dist/index.d.ts +33 -1
- package/dist/components/emoji-picker/dist/index.js +3 -1
- package/dist/components/emoji-picker/src/emoji-picker.d.ts +1 -1
- package/dist/components/emoji-picker/src/emoji-picker.js +3 -1
- package/dist/components/emoji-picker/src/index.d.ts +3 -1
- package/dist/components/form/dist/index.d.ts +93 -98
- package/dist/components/form/src/adapters/base-adapter.d.ts +3 -3
- package/dist/components/form/src/adapters/checkbox-adapter.d.ts +1 -1
- package/dist/components/form/src/adapters/chips-input-adapter.d.ts +9 -0
- package/dist/components/form/src/adapters/chips-input-adapter.js +38 -0
- package/dist/components/form/src/adapters/index.d.ts +8 -7
- package/dist/components/form/src/adapters/input-adapter.d.ts +1 -1
- package/dist/components/form/src/adapters/multi-select-adapter.d.ts +1 -1
- package/dist/components/form/src/adapters/numeric-input-adapter.d.ts +1 -1
- package/dist/components/form/src/adapters/raido-group-adapter.d.ts +1 -7
- package/dist/components/form/src/adapters/range-adapter.d.ts +1 -7
- package/dist/components/form/src/adapters/segmented-adapter.d.ts +1 -7
- package/dist/components/form/src/adapters/select-adapter.d.ts +1 -1
- package/dist/components/form/src/adapters/switch-adapter.d.ts +1 -1
- package/dist/components/form/src/adapters/textarea-adapter.d.ts +1 -1
- package/dist/components/form/src/index.d.ts +18 -16
- package/dist/components/form/src/index.js +16 -13
- package/dist/components/form/src/types.d.ts +58 -51
- package/dist/components/hint/dist/index.d.ts +10 -54
- package/dist/components/hint/src/components/info-content.d.ts +3 -5
- package/dist/components/hint/src/components/info-content.js +14 -6
- package/dist/components/hint/src/components/info-trigger.d.ts +2 -3
- package/dist/components/hint/src/components/info-trigger.js +4 -2
- package/dist/components/hint/src/context/hint-context.d.ts +2 -0
- package/dist/components/hint/src/context/hint-context.js +1 -1
- package/dist/components/hint/src/hint.d.ts +7 -7
- package/dist/components/hint/src/hint.js +24 -29
- package/dist/components/hint/src/hooks/use-hint.d.ts +4 -2
- package/dist/components/hint/src/hooks/use-hint.js +12 -4
- package/dist/components/hint/src/index.d.ts +3 -3
- package/dist/components/hint/src/tv.d.ts +33 -0
- package/dist/components/hint/src/tv.js +11 -0
- package/dist/components/icon-button/dist/index.js +2 -2
- package/dist/components/icon-button/src/icon-button.js +2 -2
- package/dist/components/index.d.ts +3 -0
- package/dist/components/input/dist/index.js +4 -4
- package/dist/components/input/src/input.js +3 -3
- package/dist/components/input/src/tv.js +1 -1
- package/dist/components/kbd/dist/index.js +4 -4
- package/dist/components/kbd/src/kbd.js +4 -4
- package/dist/components/label/dist/index.js +3 -3
- package/dist/components/label/src/tv.js +3 -3
- package/dist/components/link-button/dist/index.js +3 -3
- package/dist/components/link-button/src/link-button.js +3 -3
- package/dist/components/list/src/components/list-content.js +2 -2
- package/dist/components/list/src/components/list-divider.js +3 -3
- package/dist/components/list/src/components/list-item.js +5 -5
- package/dist/components/list/src/components/list-label.js +2 -2
- package/dist/components/list/src/components/list-sub-trigger.js +4 -4
- package/dist/components/list/src/list.js +2 -2
- package/dist/components/md-input/dist/index.d.ts +8 -104
- package/dist/components/md-input/src/components/extensions/md-input-mention.d.ts +6 -4
- package/dist/components/md-input/src/components/extensions/md-input-mention.js +23 -6
- package/dist/components/md-input/src/components/md-input-container.js +1 -0
- package/dist/components/md-input/src/components/md-input-editor.js +4 -1
- package/dist/components/md-input/src/components/md-input-footer.js +5 -1
- package/dist/components/md-input/src/components/toolbar/default-actions.d.ts +2 -2
- package/dist/components/md-input/src/components/toolbar/toolbar-button.d.ts +1 -0
- package/dist/components/md-input/src/components/toolbar/toolbar-button.js +1 -7
- package/dist/components/md-input/src/components/toolbar/toolbar.d.ts +2 -2
- package/dist/components/md-input/src/hooks/use-markdown-mentions.d.ts +5 -4
- package/dist/components/md-input/src/hooks/use-markdown-mentions.js +31 -4
- package/dist/components/md-input/src/index.d.ts +1 -4
- package/dist/components/md-input/src/md-input.js +18 -14
- package/dist/components/md-input/src/tv.d.ts +3 -0
- package/dist/components/md-input/src/tv.js +2 -1
- package/dist/components/md-input/src/types.d.ts +18 -16
- package/dist/components/md-render/dist/index.d.ts +1 -4
- package/dist/components/md-render/dist/index.js +8 -9
- package/dist/components/md-render/src/components/markdown-components.js +3 -3
- package/dist/components/md-render/src/index.d.ts +0 -1
- package/dist/components/md-render/src/md-render.js +5 -4
- package/dist/components/md-render/src/tv.js +1 -1
- package/dist/components/menubar/dist/index.d.ts +50 -0
- package/dist/components/menubar/src/components/index.d.ts +3 -0
- package/dist/components/menubar/src/components/menubar-divider.d.ts +8 -0
- package/dist/components/menubar/src/components/menubar-divider.js +24 -0
- package/dist/components/menubar/src/components/menubar-item.d.ts +8 -0
- package/dist/components/menubar/src/components/menubar-item.js +195 -0
- package/dist/components/menubar/src/components/menubar-trigger.d.ts +8 -0
- package/dist/components/menubar/src/components/menubar-trigger.js +45 -0
- package/dist/components/menubar/src/context/index.d.ts +1 -0
- package/dist/components/menubar/src/context/menubar-context.d.ts +34 -0
- package/dist/components/menubar/src/context/menubar-context.js +13 -0
- package/dist/components/menubar/src/index.d.ts +3 -0
- package/dist/components/menubar/src/menubar.d.ts +22 -0
- package/dist/components/menubar/src/menubar.js +177 -0
- package/dist/components/menubar/src/tv.d.ts +108 -0
- package/dist/components/menubar/src/tv.js +72 -0
- package/dist/components/menubar/tsup.config.d.ts +2 -0
- package/dist/components/menus/dist/index.d.ts +144 -143
- package/dist/components/menus/dist/index.js +50 -49
- package/dist/components/menus/src/components/menu-button.js +2 -2
- package/dist/components/menus/src/components/menu-checkbox.d.ts +1 -2
- package/dist/components/menus/src/components/menu-checkbox.js +2 -2
- package/dist/components/menus/src/components/menu-divider.js +3 -3
- package/dist/components/menus/src/components/menu-item.js +5 -5
- package/dist/components/menus/src/components/menu-label.js +2 -2
- package/dist/components/menus/src/components/menu-scroll-arrow.d.ts +2 -2
- package/dist/components/menus/src/components/menu-scroll-arrow.js +13 -3
- package/dist/components/menus/src/components/menu-search.js +3 -3
- package/dist/components/menus/src/components/menu-trigger.js +4 -4
- package/dist/components/menus/src/context/menu-context-item.d.ts +6 -6
- package/dist/components/menus/src/context/menu-context-item.js +2 -2
- package/dist/components/menus/src/context/menu-context-sub-trigger.js +4 -19
- package/dist/components/menus/src/context/menu-context.d.ts +2 -2
- package/dist/components/menus/src/hooks/use-menu-base-refs.d.ts +12 -12
- package/dist/components/menus/src/hooks/use-menu-children.d.ts +16 -16
- package/dist/components/menus/src/hooks/use-menu-floating.d.ts +22 -22
- package/dist/components/menus/src/hooks/use-menu-refs.d.ts +8 -8
- package/dist/components/menus/src/hooks/use-menu-refs.js +2 -2
- package/dist/components/menus/src/hooks/use-menu-scroll-height.d.ts +11 -11
- package/dist/components/menus/src/hooks/use-menu-scroll.d.ts +18 -18
- package/dist/components/menus/src/hooks/use-menu-selection.d.ts +21 -21
- package/dist/components/menus/src/hooks/use-menu-state.d.ts +11 -11
- package/dist/components/menus/src/hooks/use-menu-state.js +4 -4
- package/dist/components/menus/src/hooks/use-menu-touch.d.ts +11 -11
- package/dist/components/menus/src/hooks/use-menu-tree.d.ts +15 -15
- package/dist/components/menus/src/index.d.ts +5 -0
- package/dist/components/menus/src/menus.js +2 -2
- package/dist/components/menus/src/tv.d.ts +15 -0
- package/dist/components/menus/src/tv.js +8 -2
- package/dist/components/modal/dist/index.d.ts +3 -1
- package/dist/components/modal/dist/index.js +18 -11
- package/dist/components/modal/src/components/modal-content.js +2 -2
- package/dist/components/modal/src/components/modal-footer.js +2 -2
- package/dist/components/modal/src/components/modal-header.d.ts +3 -1
- package/dist/components/modal/src/components/modal-header.js +12 -5
- package/dist/components/modal/src/modal.js +2 -2
- package/dist/components/multi-select/dist/index.js +13 -11
- package/dist/components/multi-select/src/components/multi-select-trigger.js +8 -8
- package/dist/components/multi-select/src/multi-select.js +5 -3
- package/dist/components/numeric-input/dist/index.d.ts +10 -117
- package/dist/components/numeric-input/dist/index.js +18 -24
- package/dist/components/numeric-input/src/components/numeric-input-element.js +2 -2
- package/dist/components/numeric-input/src/components/numeric-input-menu-trigger.d.ts +1 -1
- package/dist/components/numeric-input/src/components/numeric-input-menu-trigger.js +2 -2
- package/dist/components/numeric-input/src/components/numeric-input-variable.d.ts +1 -2
- package/dist/components/numeric-input/src/components/numeric-input-variable.js +3 -3
- package/dist/components/numeric-input/src/hooks/use-input-interactions.d.ts +3 -3
- package/dist/components/numeric-input/src/hooks/use-numeric-input.d.ts +3 -3
- package/dist/components/numeric-input/src/hooks/use-numeric-value-processing.d.ts +3 -3
- package/dist/components/numeric-input/src/hooks/use-step-calculation.d.ts +6 -6
- package/dist/components/numeric-input/src/index.d.ts +5 -4
- package/dist/components/numeric-input/src/numeric-input.js +9 -9
- package/dist/components/numeric-input/src/utils/error-handler.d.ts +8 -8
- package/dist/components/numeric-input/src/utils/expression-evaluator.d.ts +11 -11
- package/dist/components/numeric-input/src/utils/input-parser.d.ts +8 -8
- package/dist/components/numeric-input/src/utils/numeric-value-processor.d.ts +6 -6
- package/dist/components/numeric-input/src/utils/pattern-parser.d.ts +7 -7
- package/dist/components/numeric-input/src/utils/value-comparator.d.ts +16 -16
- package/dist/components/numeric-input/src/utils/value-processor.d.ts +14 -14
- package/dist/components/pagination/src/components/pagination-items-per-page.js +1 -1
- package/dist/components/pagination/src/components/pagination-navigation.js +5 -5
- package/dist/components/pagination/src/components/pagination-root.js +3 -3
- package/dist/components/pagination/src/components/pagination-spinner.js +20 -19
- package/dist/components/pagination/src/context/index.d.ts +1 -0
- package/dist/components/popover/dist/index.d.ts +2 -4
- package/dist/components/popover/dist/index.js +25 -33
- package/dist/components/popover/src/components/popover-header.js +1 -1
- package/dist/components/popover/src/hooks/use-drag.d.ts +3 -3
- package/dist/components/popover/src/hooks/use-floating-popover.d.ts +0 -2
- package/dist/components/popover/src/hooks/use-floating-popover.js +16 -13
- package/dist/components/popover/src/index.d.ts +2 -1
- package/dist/components/popover/src/popover.d.ts +1 -2
- package/dist/components/popover/src/popover.js +11 -21
- package/dist/components/progress/src/index.d.ts +4 -2
- package/dist/components/radio/dist/index.d.ts +1 -17
- package/dist/components/radio/dist/index.js +7 -10
- package/dist/components/radio/src/context.js +1 -1
- package/dist/components/radio/src/index.d.ts +0 -4
- package/dist/components/radio/src/radio-label.js +2 -2
- package/dist/components/radio/src/radio.js +4 -4
- package/dist/components/range/dist/index.js +16 -16
- package/dist/components/range/src/index.d.ts +4 -2
- package/dist/components/range/src/range-tuple.js +10 -10
- package/dist/components/range/src/range.js +6 -6
- package/dist/components/rich-input/dist/index.d.ts +12 -366
- package/dist/components/rich-input/src/components/rich-input-editable-component.d.ts +2 -2
- package/dist/components/rich-input/src/components/rich-input-viewport.d.ts +2 -2
- package/dist/components/rich-input/src/hooks/use-editor-config.d.ts +1 -1
- package/dist/components/rich-input/src/hooks/use-editor-effects.js +3 -0
- package/dist/components/rich-input/src/hooks/use-floating-ui.js +1 -1
- package/dist/components/rich-input/src/hooks/use-keyboard-shortcuts.d.ts +9 -9
- package/dist/components/rich-input/src/hooks/use-rich-input.d.ts +2 -2
- package/dist/components/rich-input/src/hooks/use-rich-input.js +40 -17
- package/dist/components/rich-input/src/hooks/use-selection-events.js +1 -2
- package/dist/components/rich-input/src/index.d.ts +3 -5
- package/dist/components/rich-input/src/rich-input-base.js +1 -1
- package/dist/components/rich-input/src/utils/custom-options.js +1 -1
- package/dist/components/rich-input/src/utils/editor-utils.js +1 -1
- package/dist/components/rich-input/src/utils/markdown-to-slate.d.ts +2 -2
- package/dist/components/rich-input/src/utils/slate-to-markdown.d.ts +1 -1
- package/dist/components/rich-input/src/utils/slate-to-markdown.js +9 -0
- package/dist/components/scroll-area/dist/index.d.ts +19 -19
- package/dist/components/scroll-area/dist/index.js +24 -24
- package/dist/components/scroll-area/src/components/scroll-area-corner.js +2 -2
- package/dist/components/scroll-area/src/components/scroll-area-root.js +3 -3
- package/dist/components/scroll-area/src/components/scroll-area-scrollbar.js +2 -2
- package/dist/components/scroll-area/src/components/scroll-area-thumb.js +2 -2
- package/dist/components/scroll-area/src/hooks/use-scroll-performance-monitor.d.ts +6 -6
- package/dist/components/scroll-area/src/hooks/use-scroll-performance-monitor.js +3 -3
- package/dist/components/scroll-area/src/hooks/use-scroll-state-and-visibility.d.ts +1 -1
- package/dist/components/scroll-area/src/hooks/use-scroll-state-and-visibility.js +3 -3
- package/dist/components/scroll-area/src/hooks/use-scrollbar.d.ts +2 -2
- package/dist/components/scroll-area/src/hooks/use-thumb.d.ts +2 -2
- package/dist/components/scroll-area/src/tv.d.ts +18 -18
- package/dist/components/scroll-area/src/tv.js +12 -12
- package/dist/components/scroll-area/src/types.d.ts +8 -8
- package/dist/components/scroll-area/src/utils/index.d.ts +3 -3
- package/dist/components/search-input/dist/index.js +3 -3
- package/dist/components/search-input/src/index.d.ts +2 -1
- package/dist/components/search-input/src/search-input.js +3 -3
- package/dist/components/segmented/dist/index.js +5 -5
- package/dist/components/segmented/src/segmented-item.js +3 -3
- package/dist/components/segmented/src/segmented.js +2 -2
- package/dist/components/select/dist/index.js +4 -4
- package/dist/components/select/src/select.js +4 -4
- package/dist/components/separator/dist/index.d.ts +26 -0
- package/dist/components/separator/src/index.d.ts +2 -0
- package/dist/components/separator/src/separator.d.ts +22 -0
- package/dist/components/separator/src/separator.js +33 -0
- package/dist/components/separator/src/tv.d.ts +76 -0
- package/dist/components/separator/src/tv.js +25 -0
- package/dist/components/separator/tsup.config.d.ts +2 -0
- package/dist/components/skeleton/dist/index.d.ts +1 -28
- package/dist/components/skeleton/src/context/skeleton-context.js +1 -1
- package/dist/components/skeleton/src/hooks/use-skeleton.d.ts +1 -2
- package/dist/components/skeleton/src/hooks/use-skeleton.js +1 -1
- package/dist/components/skeleton/src/index.d.ts +1 -3
- package/dist/components/skeleton/src/skeleton.d.ts +0 -13
- package/dist/components/skeleton/src/skeleton.js +4 -6
- package/dist/components/skeleton/src/tv.d.ts +18 -12
- package/dist/components/skeleton/src/tv.js +10 -6
- package/dist/components/slot/dist/index.d.ts +10 -10
- package/dist/components/slot/dist/index.js +4 -2
- package/dist/components/slot/src/slot.d.ts +12 -12
- package/dist/components/slot/src/slot.js +6 -3
- package/dist/components/stackflow/src/context.js +1 -1
- package/dist/components/stackflow/src/index.d.ts +2 -1
- package/dist/components/switch/dist/index.d.ts +2 -2
- package/dist/components/switch/dist/index.js +6 -7
- package/dist/components/switch/src/index.d.ts +2 -1
- package/dist/components/switch/src/switch.js +6 -6
- package/dist/components/table/dist/index.d.ts +679 -0
- package/dist/components/table/index.d.ts +1 -0
- package/dist/components/table/src/components/column-resizer.d.ts +8 -0
- package/dist/components/table/src/components/column-resizer.js +58 -0
- package/dist/components/table/src/components/drag-guide.d.ts +6 -0
- package/dist/components/table/src/components/drag-guide.js +64 -0
- package/dist/components/table/src/components/index.d.ts +12 -0
- package/dist/components/table/src/components/resize-guide.d.ts +5 -0
- package/dist/components/table/src/components/resize-guide.js +25 -0
- package/dist/components/table/src/components/table-body.d.ts +6 -0
- package/dist/components/table/src/components/table-body.js +335 -0
- package/dist/components/table/src/components/table-cell.d.ts +6 -0
- package/dist/components/table/src/components/table-cell.js +89 -0
- package/dist/components/table/src/components/table-column.d.ts +5 -0
- package/dist/components/table/src/components/table-column.js +269 -0
- package/dist/components/table/src/components/table-empty.d.ts +8 -0
- package/dist/components/table/src/components/table-empty.js +10 -0
- package/dist/components/table/src/components/table-footer.d.ts +7 -0
- package/dist/components/table/src/components/table-footer.js +15 -0
- package/dist/components/table/src/components/table-header.d.ts +3 -0
- package/dist/components/table/src/components/table-header.js +88 -0
- package/dist/components/table/src/components/table-root.d.ts +3 -0
- package/dist/components/table/src/components/table-root.js +317 -0
- package/dist/components/table/src/components/table-row.d.ts +23 -0
- package/dist/components/table/src/components/table-row.js +166 -0
- package/dist/components/table/src/components/table-value.d.ts +6 -0
- package/dist/components/table/src/components/table-value.js +8 -0
- package/dist/components/table/src/context.d.ts +121 -0
- package/dist/components/table/src/context.js +63 -0
- package/dist/components/table/src/hooks/index.d.ts +4 -0
- package/dist/components/table/src/hooks/use-column-order.d.ts +26 -0
- package/dist/components/table/src/hooks/use-column-order.js +95 -0
- package/dist/components/table/src/hooks/use-column-resize.d.ts +17 -0
- package/dist/components/table/src/hooks/use-column-resize.js +75 -0
- package/dist/components/table/src/hooks/use-consecutive-selection-style.d.ts +12 -0
- package/dist/components/table/src/hooks/use-consecutive-selection-style.js +28 -0
- package/dist/components/table/src/hooks/use-table.d.ts +35 -0
- package/dist/components/table/src/hooks/use-table.js +245 -0
- package/dist/components/table/src/index.d.ts +4 -0
- package/dist/components/table/src/table.d.ts +88 -0
- package/dist/components/table/src/table.js +24 -0
- package/dist/components/table/src/tv.d.ts +176 -0
- package/dist/components/table/src/tv.js +97 -0
- package/dist/components/table/src/types.d.ts +292 -0
- package/dist/components/table/tsup.config.d.ts +2 -0
- package/dist/components/tabs/dist/index.js +4 -3
- package/dist/components/tabs/src/tabs.d.ts +2 -2
- package/dist/components/tabs/src/tabs.js +5 -4
- package/dist/components/text-field/dist/index.d.ts +1 -1
- package/dist/components/text-field/dist/index.js +10 -10
- package/dist/components/text-field/src/components/field-addon.d.ts +1 -2
- package/dist/components/text-field/src/index.d.ts +3 -1
- package/dist/components/text-field/src/text-field.js +10 -10
- package/dist/components/textarea/dist/index.d.ts +33 -5
- package/dist/components/textarea/dist/index.js +32 -7
- package/dist/components/textarea/src/components/autosize/index.d.ts +6 -1
- package/dist/components/textarea/src/components/autosize/index.js +31 -6
- package/dist/components/textarea/src/textarea.js +1 -1
- package/dist/components/textarea/src/types.d.ts +33 -5
- package/dist/components/toggle-button/dist/index.d.ts +26 -2
- package/dist/components/toggle-button/src/context.d.ts +11 -0
- package/dist/components/toggle-button/src/context.js +13 -0
- package/dist/components/toggle-button/src/index.d.ts +2 -0
- package/dist/components/toggle-button/src/toggle-button.js +4 -4
- package/dist/components/toggle-button/src/toggle-group.d.ts +26 -0
- package/dist/components/toggle-button/src/toggle-group.js +156 -0
- package/dist/components/toggle-button/src/tv.d.ts +67 -3
- package/dist/components/toggle-button/src/tv.js +45 -14
- package/dist/components/tooltip/dist/index.d.ts +10 -43
- package/dist/components/tooltip/dist/index.js +35 -33
- package/dist/components/tooltip/src/components/tooltip-arrow.js +1 -1
- package/dist/components/tooltip/src/components/tooltip-content.js +5 -4
- package/dist/components/tooltip/src/context/index.d.ts +1 -0
- package/dist/components/tooltip/src/hooks/use-tooltip.js +3 -3
- package/dist/components/tooltip/src/index.d.ts +2 -4
- package/dist/components/tooltip/src/tooltip.d.ts +7 -1
- package/dist/components/tooltip/src/tooltip.js +6 -1
- package/dist/components/tooltip/src/tv.js +1 -1
- package/dist/components/virtualized-grid/dist/index.d.ts +2 -2
- package/dist/components/virtualized-grid/src/use-item-pool.js +14 -26
- package/dist/components/virtualized-grid/src/use-virtualized-grid.d.ts +1 -1
- package/dist/components/virtualized-grid/src/use-virtualized-grid.js +14 -8
- package/dist/components/virtualized-grid/src/utility.d.ts +1 -1
- package/dist/components/virtualized-grid/src/utility.js +37 -31
- package/dist/components/virtualized-grid/src/virtualized-grid.js +27 -17
- package/dist/context/choice-ui-provider.d.ts +35 -0
- package/dist/context/choice-ui-provider.js +14 -0
- package/dist/context/index.d.ts +2 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +53 -177
- package/package.json +1 -1
- package/dist/components/code-block/src/index.js +0 -15
- package/dist/components/rich-input/src/hooks/use-mouse-events.js +0 -113
- package/dist/components/rich-input/src/hooks/use-validation.js +0 -80
- package/dist/components/rich-input/src/utils/markdown-to-slate.js +0 -219
- /package/dist/components/command/src/{command-score.d.ts → utils/command-score.d.ts} +0 -0
- /package/dist/components/command/src/{command-score.js → utils/command-score.js} +0 -0
- /package/dist/components/pagination/src/{components → context}/pagination-context.d.ts +0 -0
- /package/dist/components/pagination/src/{components → context}/pagination-context.js +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ReactNode, HTMLProps, RefObject } from 'react';
|
|
2
|
-
import * as
|
|
1
|
+
import { default as React__default, ReactNode, HTMLProps, RefObject } from 'react';
|
|
2
|
+
import * as React from 'react';
|
|
3
3
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
4
4
|
|
|
5
5
|
interface CodeBlockContextValue {
|
|
@@ -65,40 +65,22 @@ interface CodeBlockCodeProps extends HTMLProps<HTMLDivElement> {
|
|
|
65
65
|
/** 手动指定主题,覆盖自动检测 */
|
|
66
66
|
variant?: "light" | "dark";
|
|
67
67
|
}
|
|
68
|
-
interface UseCodeBlockOptions {
|
|
69
|
-
defaultCodeExpanded?: boolean;
|
|
70
|
-
defaultExpanded?: boolean;
|
|
71
|
-
onCodeExpandChange?: (expanded: boolean) => void;
|
|
72
|
-
onExpandChange?: (expanded: boolean) => void;
|
|
73
|
-
scrollToBottom?: () => void;
|
|
74
|
-
}
|
|
75
|
-
interface UseCodeBlockReturn {
|
|
76
|
-
codeExpanded: boolean;
|
|
77
|
-
copied: boolean;
|
|
78
|
-
handleCodeExpand: () => void;
|
|
79
|
-
handleCopy: (code: string) => void;
|
|
80
|
-
handleExpand: () => void;
|
|
81
|
-
isExpanded: boolean;
|
|
82
|
-
}
|
|
83
|
-
interface UseScrollDetectionOptions {
|
|
84
|
-
children?: ReactNode;
|
|
85
|
-
codeExpanded: boolean;
|
|
86
|
-
contentRef: RefObject<HTMLDivElement>;
|
|
87
|
-
isExpanded: boolean;
|
|
88
|
-
scrollRef: RefObject<HTMLDivElement>;
|
|
89
|
-
}
|
|
90
68
|
|
|
91
|
-
declare const CodeBlockCode:
|
|
69
|
+
declare const CodeBlockCode: React.NamedExoticComponent<CodeBlockCodeProps>;
|
|
92
70
|
|
|
93
|
-
declare
|
|
71
|
+
declare const CodeBlockHeader: React__default.NamedExoticComponent<CodeBlockHeaderProps>;
|
|
94
72
|
|
|
95
|
-
declare
|
|
73
|
+
declare const CodeBlockFooter: React.NamedExoticComponent<CodeBlockFooterProps>;
|
|
74
|
+
|
|
75
|
+
declare function CodeBlockContent(props: CodeBlockContentProps): react_jsx_runtime.JSX.Element | null;
|
|
96
76
|
|
|
97
|
-
declare const CodeBlock:
|
|
98
|
-
Code:
|
|
77
|
+
declare const CodeBlock: React__default.NamedExoticComponent<CodeBlockProps> & {
|
|
78
|
+
Code: React__default.NamedExoticComponent<CodeBlockCodeProps>;
|
|
99
79
|
Content: typeof CodeBlockContent;
|
|
100
|
-
Footer:
|
|
101
|
-
Header:
|
|
80
|
+
Footer: React__default.NamedExoticComponent<CodeBlockFooterProps>;
|
|
81
|
+
Header: React__default.NamedExoticComponent<CodeBlockHeaderProps>;
|
|
102
82
|
};
|
|
103
83
|
|
|
104
|
-
|
|
84
|
+
declare function getDefaultFilenameForLanguage(language: string): string;
|
|
85
|
+
|
|
86
|
+
export { CodeBlock, CodeBlockCode, type CodeBlockCodeProps, CodeBlockContent, type CodeBlockContentProps, CodeBlockFooter, type CodeBlockFooterProps, CodeBlockHeader, type CodeBlockHeaderProps, type CodeBlockProps, getDefaultFilenameForLanguage };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import React, { memo, useState, useEffect } from "react";
|
|
2
2
|
import { useStickToBottom } from "use-stick-to-bottom";
|
|
3
|
+
import { codeToHtml } from "shiki";
|
|
3
4
|
import { useEventCallback } from "usehooks-ts";
|
|
4
5
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
5
|
-
import { codeToHtml } from "shiki";
|
|
6
6
|
import { IconButton } from "../../icon-button/dist/index.js";
|
|
7
|
-
import { FileCode,
|
|
7
|
+
import { FileCode, Check, ClipboardSmall, Enlarge, ChevronUpSmall, ChevronDownSmall } from "@choiceform/icons-react";
|
|
8
8
|
import { ScrollArea } from "../../scroll-area/dist/index.js";
|
|
9
9
|
import { tcx, tcv } from "../../../shared/utils/tcx/tcx.js";
|
|
10
10
|
function useCodeBlock({
|
|
@@ -155,135 +155,23 @@ function useTheme() {
|
|
|
155
155
|
}, []);
|
|
156
156
|
return theme;
|
|
157
157
|
}
|
|
158
|
-
var
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
});
|
|
176
|
-
const codeContentRef = React.useRef("");
|
|
177
|
-
const {
|
|
178
|
-
isExpanded,
|
|
179
|
-
codeExpanded,
|
|
180
|
-
copied,
|
|
181
|
-
handleExpand,
|
|
182
|
-
handleCodeExpand,
|
|
183
|
-
handleCopy: originalHandleCopy
|
|
184
|
-
} = useCodeBlock({
|
|
185
|
-
defaultExpanded,
|
|
186
|
-
defaultCodeExpanded,
|
|
187
|
-
onExpandChange,
|
|
188
|
-
onCodeExpandChange,
|
|
189
|
-
scrollToBottom
|
|
190
|
-
});
|
|
191
|
-
const handleCopy = React.useCallback(
|
|
192
|
-
(code) => {
|
|
193
|
-
const codeToUse = code || codeContentRef.current;
|
|
194
|
-
if (codeToUse) {
|
|
195
|
-
originalHandleCopy(codeToUse);
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
[originalHandleCopy]
|
|
199
|
-
);
|
|
200
|
-
React.useEffect(() => {
|
|
201
|
-
try {
|
|
202
|
-
React.Children.forEach(children, (child) => {
|
|
203
|
-
if (React.isValidElement(child) && child.props) {
|
|
204
|
-
if (child.props.code && typeof child.props.code === "string") {
|
|
205
|
-
codeContentRef.current = child.props.code;
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
});
|
|
209
|
-
} catch {
|
|
210
|
-
}
|
|
211
|
-
}, [children]);
|
|
212
|
-
const lineCount = useLineCount(children);
|
|
213
|
-
const needsScroll = useScrollDetection({
|
|
214
|
-
scrollRef,
|
|
215
|
-
contentRef,
|
|
216
|
-
isExpanded,
|
|
217
|
-
codeExpanded,
|
|
218
|
-
children
|
|
219
|
-
});
|
|
220
|
-
const contextValue = React.useMemo(
|
|
221
|
-
() => ({
|
|
222
|
-
language,
|
|
223
|
-
filename,
|
|
224
|
-
lineCount,
|
|
225
|
-
isExpanded,
|
|
226
|
-
codeExpanded,
|
|
227
|
-
copied,
|
|
228
|
-
needsScroll,
|
|
229
|
-
expandable,
|
|
230
|
-
lineThreshold,
|
|
231
|
-
handleExpand,
|
|
232
|
-
handleCodeExpand,
|
|
233
|
-
handleCopy,
|
|
234
|
-
scrollRef,
|
|
235
|
-
contentRef,
|
|
236
|
-
variant
|
|
237
|
-
}),
|
|
238
|
-
[
|
|
239
|
-
language,
|
|
240
|
-
filename,
|
|
241
|
-
lineCount,
|
|
242
|
-
isExpanded,
|
|
243
|
-
codeExpanded,
|
|
244
|
-
copied,
|
|
245
|
-
needsScroll,
|
|
246
|
-
expandable,
|
|
247
|
-
lineThreshold,
|
|
248
|
-
handleExpand,
|
|
249
|
-
handleCodeExpand,
|
|
250
|
-
handleCopy,
|
|
251
|
-
scrollRef,
|
|
252
|
-
contentRef,
|
|
253
|
-
variant
|
|
254
|
-
]
|
|
255
|
-
);
|
|
256
|
-
const injectedChildren = React.useMemo(() => {
|
|
257
|
-
try {
|
|
258
|
-
return React.Children.map(children, (child) => {
|
|
259
|
-
if (React.isValidElement(child)) {
|
|
260
|
-
return React.cloneElement(
|
|
261
|
-
child,
|
|
262
|
-
{
|
|
263
|
-
codeBlock: contextValue
|
|
264
|
-
}
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
return child;
|
|
268
|
-
});
|
|
269
|
-
} catch {
|
|
270
|
-
return children;
|
|
271
|
-
}
|
|
272
|
-
}, [children, contextValue]);
|
|
273
|
-
return /* @__PURE__ */ jsx(
|
|
274
|
-
"div",
|
|
275
|
-
{
|
|
276
|
-
className: tcx(
|
|
277
|
-
"group relative overflow-hidden rounded-lg",
|
|
278
|
-
variant === "default" && "bg-secondary-background",
|
|
279
|
-
variant === "light" && "bg-gray-100",
|
|
280
|
-
variant === "dark" && "bg-gray-700",
|
|
281
|
-
className
|
|
282
|
-
),
|
|
283
|
-
children: injectedChildren
|
|
284
|
-
}
|
|
285
|
-
);
|
|
286
|
-
});
|
|
158
|
+
var LANGUAGE_ALIASES = {
|
|
159
|
+
node: "javascript",
|
|
160
|
+
nodejs: "javascript",
|
|
161
|
+
js: "javascript",
|
|
162
|
+
ts: "typescript",
|
|
163
|
+
sh: "bash",
|
|
164
|
+
shell: "bash",
|
|
165
|
+
zsh: "bash",
|
|
166
|
+
yml: "yaml",
|
|
167
|
+
dockerfile: "docker",
|
|
168
|
+
plaintext: "text",
|
|
169
|
+
plain: "text"
|
|
170
|
+
};
|
|
171
|
+
function resolveLanguage(lang) {
|
|
172
|
+
const normalized = lang.toLowerCase();
|
|
173
|
+
return LANGUAGE_ALIASES[normalized] ?? normalized;
|
|
174
|
+
}
|
|
287
175
|
var codeBlockCodeTv = tcv({
|
|
288
176
|
base: "text-message-code w-fit min-w-full bg-transparent font-mono [&>pre]:!bg-transparent [&>pre]:px-4 [&>pre]:py-4"
|
|
289
177
|
});
|
|
@@ -299,11 +187,20 @@ var CodeBlockCode = memo(function CodeBlockCode2(props) {
|
|
|
299
187
|
setHighlightedHtml("<pre><code></code></pre>");
|
|
300
188
|
return;
|
|
301
189
|
}
|
|
302
|
-
const
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
190
|
+
const resolvedLang = resolveLanguage(language);
|
|
191
|
+
try {
|
|
192
|
+
const html = await codeToHtml(code, {
|
|
193
|
+
lang: resolvedLang,
|
|
194
|
+
theme: theme === "light" ? "github-light" : "github-dark"
|
|
195
|
+
});
|
|
196
|
+
setHighlightedHtml(html);
|
|
197
|
+
} catch {
|
|
198
|
+
const html = await codeToHtml(code, {
|
|
199
|
+
lang: "text",
|
|
200
|
+
theme: theme === "light" ? "github-light" : "github-dark"
|
|
201
|
+
});
|
|
202
|
+
setHighlightedHtml(html);
|
|
203
|
+
}
|
|
307
204
|
}
|
|
308
205
|
highlight();
|
|
309
206
|
}, [code, language, theme]);
|
|
@@ -937,17 +834,51 @@ var codeBlockHeaderTv = tcv({
|
|
|
937
834
|
slots: {
|
|
938
835
|
header: "text-body-medium code-header flex h-8 items-center justify-between pr-1 pl-2",
|
|
939
836
|
title: "flex items-center gap-1",
|
|
940
|
-
filename: "
|
|
837
|
+
filename: "",
|
|
941
838
|
actions: "flex items-center",
|
|
942
|
-
button: "opacity-0 group-hover:opacity-100",
|
|
839
|
+
button: "opacity-0 group-hover/code-block:opacity-100",
|
|
943
840
|
lineCount: "text-success-foreground ml-2 font-strong"
|
|
944
841
|
},
|
|
945
842
|
variants: {
|
|
946
843
|
isExpanded: {
|
|
947
|
-
true: {
|
|
844
|
+
true: {},
|
|
948
845
|
false: {}
|
|
846
|
+
},
|
|
847
|
+
variant: {
|
|
848
|
+
default: {
|
|
849
|
+
filename: "text-secondary-foreground"
|
|
850
|
+
},
|
|
851
|
+
light: {
|
|
852
|
+
filename: "text-gray-900"
|
|
853
|
+
},
|
|
854
|
+
dark: {
|
|
855
|
+
filename: "text-white"
|
|
856
|
+
}
|
|
949
857
|
}
|
|
950
858
|
},
|
|
859
|
+
compoundVariants: [
|
|
860
|
+
{
|
|
861
|
+
variant: "default",
|
|
862
|
+
isExpanded: true,
|
|
863
|
+
class: {
|
|
864
|
+
header: "bg-secondary-background"
|
|
865
|
+
}
|
|
866
|
+
},
|
|
867
|
+
{
|
|
868
|
+
variant: "light",
|
|
869
|
+
isExpanded: true,
|
|
870
|
+
class: {
|
|
871
|
+
header: "bg-gray-100"
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
{
|
|
875
|
+
variant: "dark",
|
|
876
|
+
isExpanded: true,
|
|
877
|
+
class: {
|
|
878
|
+
header: "bg-gray-700"
|
|
879
|
+
}
|
|
880
|
+
}
|
|
881
|
+
],
|
|
951
882
|
defaultVariants: {
|
|
952
883
|
isExpanded: true
|
|
953
884
|
}
|
|
@@ -956,7 +887,7 @@ var CodeBlockHeader = memo(function CodeBlockHeader2(props) {
|
|
|
956
887
|
const {
|
|
957
888
|
className,
|
|
958
889
|
codeBlock,
|
|
959
|
-
showLineCount =
|
|
890
|
+
showLineCount = false,
|
|
960
891
|
i18n = {
|
|
961
892
|
collapse: "Collapse",
|
|
962
893
|
copied: "Copied",
|
|
@@ -974,12 +905,13 @@ var CodeBlockHeader = memo(function CodeBlockHeader2(props) {
|
|
|
974
905
|
copied = false,
|
|
975
906
|
expandable = true,
|
|
976
907
|
handleExpand,
|
|
977
|
-
handleCopy
|
|
908
|
+
handleCopy,
|
|
909
|
+
variant
|
|
978
910
|
} = codeBlock;
|
|
979
911
|
if (!handleExpand || !handleCopy) {
|
|
980
912
|
return null;
|
|
981
913
|
}
|
|
982
|
-
const tv = codeBlockHeaderTv({ isExpanded });
|
|
914
|
+
const tv = codeBlockHeaderTv({ isExpanded, variant });
|
|
983
915
|
let icon = null;
|
|
984
916
|
try {
|
|
985
917
|
if (filename && typeof filename === "string") {
|
|
@@ -1006,17 +938,17 @@ var CodeBlockHeader = memo(function CodeBlockHeader2(props) {
|
|
|
1006
938
|
IconButton,
|
|
1007
939
|
{
|
|
1008
940
|
className: tv.button(),
|
|
1009
|
-
variant: "ghost",
|
|
941
|
+
variant: variant === "dark" ? "dark" : "ghost",
|
|
1010
942
|
onClick: () => handleCopy(),
|
|
1011
943
|
tooltip: { content: copyTooltipContent },
|
|
1012
|
-
children: copied ? /* @__PURE__ */ jsx(
|
|
944
|
+
children: copied ? /* @__PURE__ */ jsx(Check, { className: "text-success-foreground" }) : /* @__PURE__ */ jsx(ClipboardSmall, {})
|
|
1013
945
|
}
|
|
1014
946
|
),
|
|
1015
947
|
expandable && /* @__PURE__ */ jsx(
|
|
1016
948
|
IconButton,
|
|
1017
949
|
{
|
|
1018
950
|
className: tv.button(),
|
|
1019
|
-
variant: "ghost",
|
|
951
|
+
variant: variant === "dark" ? "dark" : "ghost",
|
|
1020
952
|
onClick: handleExpand,
|
|
1021
953
|
tooltip: {
|
|
1022
954
|
content: expandTooltipContent
|
|
@@ -1127,14 +1059,146 @@ function CodeBlockContent(props) {
|
|
|
1127
1059
|
}
|
|
1128
1060
|
) }) });
|
|
1129
1061
|
}
|
|
1130
|
-
var
|
|
1062
|
+
var CodeBlockRoot = memo(function CodeBlock(props) {
|
|
1063
|
+
const {
|
|
1064
|
+
children,
|
|
1065
|
+
className,
|
|
1066
|
+
filename,
|
|
1067
|
+
language = "code",
|
|
1068
|
+
lineThreshold = 20,
|
|
1069
|
+
expandable = true,
|
|
1070
|
+
defaultExpanded = true,
|
|
1071
|
+
defaultCodeExpanded = false,
|
|
1072
|
+
variant = "default",
|
|
1073
|
+
onExpandChange,
|
|
1074
|
+
onCodeExpandChange
|
|
1075
|
+
} = props;
|
|
1076
|
+
const { scrollRef, contentRef, scrollToBottom } = useStickToBottom({
|
|
1077
|
+
resize: "smooth",
|
|
1078
|
+
initial: "smooth"
|
|
1079
|
+
});
|
|
1080
|
+
const codeContentRef = React.useRef("");
|
|
1081
|
+
const {
|
|
1082
|
+
isExpanded,
|
|
1083
|
+
codeExpanded,
|
|
1084
|
+
copied,
|
|
1085
|
+
handleExpand,
|
|
1086
|
+
handleCodeExpand,
|
|
1087
|
+
handleCopy: originalHandleCopy
|
|
1088
|
+
} = useCodeBlock({
|
|
1089
|
+
defaultExpanded,
|
|
1090
|
+
defaultCodeExpanded,
|
|
1091
|
+
onExpandChange,
|
|
1092
|
+
onCodeExpandChange,
|
|
1093
|
+
scrollToBottom
|
|
1094
|
+
});
|
|
1095
|
+
const handleCopy = React.useCallback(
|
|
1096
|
+
(code) => {
|
|
1097
|
+
const codeToUse = code || codeContentRef.current;
|
|
1098
|
+
if (codeToUse) {
|
|
1099
|
+
originalHandleCopy(codeToUse);
|
|
1100
|
+
}
|
|
1101
|
+
},
|
|
1102
|
+
[originalHandleCopy]
|
|
1103
|
+
);
|
|
1104
|
+
React.useEffect(() => {
|
|
1105
|
+
try {
|
|
1106
|
+
React.Children.forEach(children, (child) => {
|
|
1107
|
+
if (React.isValidElement(child) && child.props) {
|
|
1108
|
+
if (child.props.code && typeof child.props.code === "string") {
|
|
1109
|
+
codeContentRef.current = child.props.code;
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
});
|
|
1113
|
+
} catch {
|
|
1114
|
+
}
|
|
1115
|
+
}, [children]);
|
|
1116
|
+
const lineCount = useLineCount(children);
|
|
1117
|
+
const needsScroll = useScrollDetection({
|
|
1118
|
+
scrollRef,
|
|
1119
|
+
contentRef,
|
|
1120
|
+
isExpanded,
|
|
1121
|
+
codeExpanded,
|
|
1122
|
+
children
|
|
1123
|
+
});
|
|
1124
|
+
const contextValue = React.useMemo(
|
|
1125
|
+
() => ({
|
|
1126
|
+
language,
|
|
1127
|
+
filename,
|
|
1128
|
+
lineCount,
|
|
1129
|
+
isExpanded,
|
|
1130
|
+
codeExpanded,
|
|
1131
|
+
copied,
|
|
1132
|
+
needsScroll,
|
|
1133
|
+
expandable,
|
|
1134
|
+
lineThreshold,
|
|
1135
|
+
handleExpand,
|
|
1136
|
+
handleCodeExpand,
|
|
1137
|
+
handleCopy,
|
|
1138
|
+
scrollRef,
|
|
1139
|
+
contentRef,
|
|
1140
|
+
variant
|
|
1141
|
+
}),
|
|
1142
|
+
[
|
|
1143
|
+
language,
|
|
1144
|
+
filename,
|
|
1145
|
+
lineCount,
|
|
1146
|
+
isExpanded,
|
|
1147
|
+
codeExpanded,
|
|
1148
|
+
copied,
|
|
1149
|
+
needsScroll,
|
|
1150
|
+
expandable,
|
|
1151
|
+
lineThreshold,
|
|
1152
|
+
handleExpand,
|
|
1153
|
+
handleCodeExpand,
|
|
1154
|
+
handleCopy,
|
|
1155
|
+
scrollRef,
|
|
1156
|
+
contentRef,
|
|
1157
|
+
variant
|
|
1158
|
+
]
|
|
1159
|
+
);
|
|
1160
|
+
const injectedChildren = React.useMemo(() => {
|
|
1161
|
+
try {
|
|
1162
|
+
return React.Children.map(children, (child) => {
|
|
1163
|
+
if (React.isValidElement(child)) {
|
|
1164
|
+
return React.cloneElement(
|
|
1165
|
+
child,
|
|
1166
|
+
{
|
|
1167
|
+
codeBlock: contextValue
|
|
1168
|
+
}
|
|
1169
|
+
);
|
|
1170
|
+
}
|
|
1171
|
+
return child;
|
|
1172
|
+
});
|
|
1173
|
+
} catch {
|
|
1174
|
+
return children;
|
|
1175
|
+
}
|
|
1176
|
+
}, [children, contextValue]);
|
|
1177
|
+
return /* @__PURE__ */ jsx(
|
|
1178
|
+
"div",
|
|
1179
|
+
{
|
|
1180
|
+
className: tcx(
|
|
1181
|
+
"group/code-block relative overflow-hidden rounded-lg",
|
|
1182
|
+
variant === "default" && "bg-secondary-background",
|
|
1183
|
+
variant === "light" && "bg-gray-100",
|
|
1184
|
+
variant === "dark" && "bg-gray-700",
|
|
1185
|
+
className
|
|
1186
|
+
),
|
|
1187
|
+
children: injectedChildren
|
|
1188
|
+
}
|
|
1189
|
+
);
|
|
1190
|
+
});
|
|
1191
|
+
var CodeBlock2 = Object.assign(CodeBlockRoot, {
|
|
1131
1192
|
Code: CodeBlockCode,
|
|
1132
1193
|
Content: CodeBlockContent,
|
|
1133
1194
|
Footer: CodeBlockFooter,
|
|
1134
1195
|
Header: CodeBlockHeader
|
|
1135
1196
|
});
|
|
1136
1197
|
export {
|
|
1137
|
-
|
|
1198
|
+
CodeBlock2 as CodeBlock,
|
|
1138
1199
|
CodeBlockCode,
|
|
1200
|
+
CodeBlockContent,
|
|
1201
|
+
CodeBlockFooter,
|
|
1202
|
+
CodeBlockHeader,
|
|
1139
1203
|
getDefaultFilenameForLanguage
|
|
1140
1204
|
};
|
|
@@ -1,3 +1,10 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
import { CodeBlockContent } from './components';
|
|
2
3
|
import { CodeBlockProps } from './types';
|
|
3
|
-
export declare const
|
|
4
|
+
export declare const CodeBlockRoot: React.NamedExoticComponent<CodeBlockProps>;
|
|
5
|
+
export declare const CodeBlock: React.NamedExoticComponent<CodeBlockProps> & {
|
|
6
|
+
Code: React.NamedExoticComponent<import('../..').CodeBlockCodeProps>;
|
|
7
|
+
Content: typeof CodeBlockContent;
|
|
8
|
+
Footer: React.NamedExoticComponent<import('../..').CodeBlockFooterProps>;
|
|
9
|
+
Header: React.NamedExoticComponent<import('../..').CodeBlockHeaderProps>;
|
|
10
|
+
};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { jsx } from "react/jsx-runtime";
|
|
2
2
|
import React, { memo } from "react";
|
|
3
3
|
import { useStickToBottom } from "use-stick-to-bottom";
|
|
4
|
+
import { CodeBlockHeader } from "./components/code-block-header.js";
|
|
5
|
+
import { CodeBlockFooter } from "./components/code-block-footer.js";
|
|
6
|
+
import { CodeBlockContent } from "./components/code-block-content.js";
|
|
7
|
+
import { CodeBlockCode } from "./components/code-block-code.js";
|
|
4
8
|
import { useCodeBlock } from "./hooks/use-code-block.js";
|
|
5
9
|
import { useLineCount } from "./hooks/use-line-count.js";
|
|
6
10
|
import { useScrollDetection } from "./hooks/use-scroll-detection.js";
|
|
7
11
|
import { tcx } from "../../../shared/utils/tcx/tcx.js";
|
|
8
|
-
const
|
|
12
|
+
const CodeBlockRoot = memo(function CodeBlock2(props) {
|
|
9
13
|
const {
|
|
10
14
|
children,
|
|
11
15
|
className,
|
|
@@ -124,7 +128,7 @@ const CodeBlock = memo(function CodeBlock2(props) {
|
|
|
124
128
|
"div",
|
|
125
129
|
{
|
|
126
130
|
className: tcx(
|
|
127
|
-
"group relative overflow-hidden rounded-lg",
|
|
131
|
+
"group/code-block relative overflow-hidden rounded-lg",
|
|
128
132
|
variant === "default" && "bg-secondary-background",
|
|
129
133
|
variant === "light" && "bg-gray-100",
|
|
130
134
|
variant === "dark" && "bg-gray-700",
|
|
@@ -134,6 +138,13 @@ const CodeBlock = memo(function CodeBlock2(props) {
|
|
|
134
138
|
}
|
|
135
139
|
);
|
|
136
140
|
});
|
|
141
|
+
const CodeBlock = Object.assign(CodeBlockRoot, {
|
|
142
|
+
Code: CodeBlockCode,
|
|
143
|
+
Content: CodeBlockContent,
|
|
144
|
+
Footer: CodeBlockFooter,
|
|
145
|
+
Header: CodeBlockHeader
|
|
146
|
+
});
|
|
137
147
|
export {
|
|
138
|
-
CodeBlock
|
|
148
|
+
CodeBlock,
|
|
149
|
+
CodeBlockRoot
|
|
139
150
|
};
|
|
@@ -3,6 +3,23 @@ import { memo, useState, useEffect } from "react";
|
|
|
3
3
|
import { codeToHtml } from "shiki";
|
|
4
4
|
import { useTheme } from "../hooks/use-theme.js";
|
|
5
5
|
import { tcv, tcx } from "../../../../shared/utils/tcx/tcx.js";
|
|
6
|
+
const LANGUAGE_ALIASES = {
|
|
7
|
+
node: "javascript",
|
|
8
|
+
nodejs: "javascript",
|
|
9
|
+
js: "javascript",
|
|
10
|
+
ts: "typescript",
|
|
11
|
+
sh: "bash",
|
|
12
|
+
shell: "bash",
|
|
13
|
+
zsh: "bash",
|
|
14
|
+
yml: "yaml",
|
|
15
|
+
dockerfile: "docker",
|
|
16
|
+
plaintext: "text",
|
|
17
|
+
plain: "text"
|
|
18
|
+
};
|
|
19
|
+
function resolveLanguage(lang) {
|
|
20
|
+
const normalized = lang.toLowerCase();
|
|
21
|
+
return LANGUAGE_ALIASES[normalized] ?? normalized;
|
|
22
|
+
}
|
|
6
23
|
const codeBlockCodeTv = tcv({
|
|
7
24
|
base: "text-message-code w-fit min-w-full bg-transparent font-mono [&>pre]:!bg-transparent [&>pre]:px-4 [&>pre]:py-4"
|
|
8
25
|
});
|
|
@@ -18,11 +35,20 @@ const CodeBlockCode = memo(function CodeBlockCode2(props) {
|
|
|
18
35
|
setHighlightedHtml("<pre><code></code></pre>");
|
|
19
36
|
return;
|
|
20
37
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
38
|
+
const resolvedLang = resolveLanguage(language);
|
|
39
|
+
try {
|
|
40
|
+
const html = await codeToHtml(code, {
|
|
41
|
+
lang: resolvedLang,
|
|
42
|
+
theme: theme === "light" ? "github-light" : "github-dark"
|
|
43
|
+
});
|
|
44
|
+
setHighlightedHtml(html);
|
|
45
|
+
} catch {
|
|
46
|
+
const html = await codeToHtml(code, {
|
|
47
|
+
lang: "text",
|
|
48
|
+
theme: theme === "light" ? "github-light" : "github-dark"
|
|
49
|
+
});
|
|
50
|
+
setHighlightedHtml(html);
|
|
51
|
+
}
|
|
26
52
|
}
|
|
27
53
|
highlight();
|
|
28
54
|
}, [code, language, theme]);
|