@assistant-ui/react
Version:
React components for AI chat.
89 lines (88 loc) • 4.75 kB
JavaScript
"use client";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/ui/branch-picker.tsx
var branch_picker_exports = {};
__export(branch_picker_exports, {
default: () => branch_picker_default
});
module.exports = __toCommonJS(branch_picker_exports);
var import_react = require("react");
var import_lucide_react = require("lucide-react");
var import_tooltip_icon_button = require("./base/tooltip-icon-button.cjs");
var import_withDefaults = require("./utils/withDefaults.cjs");
var import_thread_config = require("./thread-config.cjs");
var import_primitives = require("../primitives/index.cjs");
var import_context = require("../context/index.cjs");
var import_jsx_runtime = require("react/jsx-runtime");
var useAllowBranchPicker = (ensureCapability = false) => {
const { branchPicker: { allowBranchPicker = true } = {} } = (0, import_thread_config.useThreadConfig)();
const branchPickerSupported = (0, import_context.useThread)((t) => t.capabilities.edit);
return allowBranchPicker && (!ensureCapability || branchPickerSupported);
};
var BranchPicker = () => {
const allowBranchPicker = useAllowBranchPicker(true);
if (!allowBranchPicker) return null;
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(BranchPickerRoot, { hideWhenSingleBranch: true, children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(BranchPickerPrevious, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(BranchPickerState, {}),
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(BranchPickerNext, {})
] });
};
BranchPicker.displayName = "BranchPicker";
var BranchPickerRoot = (0, import_withDefaults.withDefaults)(import_primitives.BranchPickerPrimitive.Root, {
className: "aui-branch-picker-root"
});
BranchPickerRoot.displayName = "BranchPickerRoot";
var BranchPickerPrevious = (0, import_react.forwardRef)((props, ref) => {
const {
strings: {
branchPicker: { previous: { tooltip = "Previous" } = {} } = {}
} = {}
} = (0, import_thread_config.useThreadConfig)();
const allowBranchPicker = useAllowBranchPicker();
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.BranchPickerPrimitive.Previous, { disabled: !allowBranchPicker, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tooltip_icon_button.TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronLeftIcon, {}) }) });
});
BranchPickerPrevious.displayName = "BranchPickerPrevious";
var BranchPickerStateWrapper = (0, import_withDefaults.withDefaults)("span", {
className: "aui-branch-picker-state"
});
var BranchPickerState = (0, import_react.forwardRef)((props, ref) => {
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(BranchPickerStateWrapper, { ...props, ref, children: [
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.BranchPickerPrimitive.Number, {}),
" / ",
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.BranchPickerPrimitive.Count, {})
] });
});
BranchPickerState.displayName = "BranchPickerState";
var BranchPickerNext = (0, import_react.forwardRef)((props, ref) => {
const {
strings: { branchPicker: { next: { tooltip = "Next" } = {} } = {} } = {}
} = (0, import_thread_config.useThreadConfig)();
const allowBranchPicker = useAllowBranchPicker();
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_primitives.BranchPickerPrimitive.Next, { disabled: !allowBranchPicker, asChild: true, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_tooltip_icon_button.TooltipIconButton, { tooltip, ...props, ref, children: props.children ?? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_lucide_react.ChevronRightIcon, {}) }) });
});
BranchPickerNext.displayName = "BranchPickerNext";
var exports2 = {
Root: BranchPickerRoot,
Previous: BranchPickerPrevious,
Next: BranchPickerNext
};
var branch_picker_default = Object.assign(BranchPicker, exports2);
//# sourceMappingURL=branch-picker.js.map
;