hazo_ui 2.3.1 → 2.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var React23 = require('react');
3
+ var React27 = require('react');
4
4
  var reactSlot = require('@radix-ui/react-slot');
5
5
  var classVarianceAuthority = require('class-variance-authority');
6
6
  var clsx = require('clsx');
@@ -53,6 +53,8 @@ var lu = require('react-icons/lu');
53
53
  var rx = require('react-icons/rx');
54
54
  var core = require('@tiptap/core');
55
55
  var TabsPrimitive = require('@radix-ui/react-tabs');
56
+ var Suggestion = require('@tiptap/suggestion');
57
+ var reactDom = require('react-dom');
56
58
 
57
59
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
58
60
 
@@ -74,7 +76,7 @@ function _interopNamespace(e) {
74
76
  return Object.freeze(n);
75
77
  }
76
78
 
77
- var React23__namespace = /*#__PURE__*/_interopNamespace(React23);
79
+ var React27__namespace = /*#__PURE__*/_interopNamespace(React27);
78
80
  var DialogPrimitive__namespace = /*#__PURE__*/_interopNamespace(DialogPrimitive);
79
81
  var PopoverPrimitive__namespace = /*#__PURE__*/_interopNamespace(PopoverPrimitive);
80
82
  var SelectPrimitive__namespace = /*#__PURE__*/_interopNamespace(SelectPrimitive);
@@ -110,6 +112,7 @@ var TableHeader__default = /*#__PURE__*/_interopDefault(TableHeader);
110
112
  var TaskList__default = /*#__PURE__*/_interopDefault(TaskList);
111
113
  var TaskItem__default = /*#__PURE__*/_interopDefault(TaskItem);
112
114
  var TabsPrimitive__namespace = /*#__PURE__*/_interopNamespace(TabsPrimitive);
115
+ var Suggestion__default = /*#__PURE__*/_interopDefault(Suggestion);
113
116
 
114
117
  var __create = Object.create;
115
118
  var __defProp = Object.defineProperty;
@@ -196,7 +199,7 @@ var buttonVariants = classVarianceAuthority.cva(
196
199
  }
197
200
  }
198
201
  );
199
- var Button = React23__namespace.forwardRef(
202
+ var Button = React27__namespace.forwardRef(
200
203
  ({ className, variant, size, asChild = false, ...props }, ref) => {
201
204
  const Comp = asChild ? reactSlot.Slot : "button";
202
205
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -213,7 +216,7 @@ Button.displayName = "Button";
213
216
  var Dialog = DialogPrimitive__namespace.Root;
214
217
  var DialogTrigger = DialogPrimitive__namespace.Trigger;
215
218
  var DialogPortal = DialogPrimitive__namespace.Portal;
216
- var DialogOverlay = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
219
+ var DialogOverlay = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
217
220
  DialogPrimitive__namespace.Overlay,
218
221
  {
219
222
  ref,
@@ -225,7 +228,7 @@ var DialogOverlay = React23__namespace.forwardRef(({ className, ...props }, ref)
225
228
  }
226
229
  ));
227
230
  DialogOverlay.displayName = DialogPrimitive__namespace.Overlay.displayName;
228
- var DialogContent = React23__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
231
+ var DialogContent = React27__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(DialogPortal, { children: [
229
232
  /* @__PURE__ */ jsxRuntime.jsx(DialogOverlay, {}),
230
233
  /* @__PURE__ */ jsxRuntime.jsxs(
231
234
  DialogPrimitive__namespace.Content,
@@ -275,7 +278,7 @@ var DialogFooter = ({
275
278
  }
276
279
  );
277
280
  DialogFooter.displayName = "DialogFooter";
278
- var DialogTitle = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
281
+ var DialogTitle = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
279
282
  DialogPrimitive__namespace.Title,
280
283
  {
281
284
  ref,
@@ -287,7 +290,7 @@ var DialogTitle = React23__namespace.forwardRef(({ className, ...props }, ref) =
287
290
  }
288
291
  ));
289
292
  DialogTitle.displayName = DialogPrimitive__namespace.Title.displayName;
290
- var DialogDescription = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
293
+ var DialogDescription = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
291
294
  DialogPrimitive__namespace.Description,
292
295
  {
293
296
  ref,
@@ -296,7 +299,7 @@ var DialogDescription = React23__namespace.forwardRef(({ className, ...props },
296
299
  }
297
300
  ));
298
301
  DialogDescription.displayName = DialogPrimitive__namespace.Description.displayName;
299
- var Command = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
302
+ var Command = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
300
303
  "div",
301
304
  {
302
305
  ref,
@@ -308,7 +311,7 @@ var Command = React23__namespace.forwardRef(({ className, ...props }, ref) => /*
308
311
  }
309
312
  ));
310
313
  Command.displayName = "Command";
311
- var CommandInput = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
314
+ var CommandInput = React27__namespace.forwardRef(({ className, onValueChange, onChange, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
312
315
  "input",
313
316
  {
314
317
  ref,
@@ -316,11 +319,15 @@ var CommandInput = React23__namespace.forwardRef(({ className, ...props }, ref)
316
319
  "flex h-11 w-full rounded-md border border-input bg-transparent py-3 text-sm outline-none placeholder:text-muted-foreground disabled:cursor-not-allowed disabled:opacity-50 px-3",
317
320
  className
318
321
  ),
322
+ onChange: (e) => {
323
+ onChange?.(e);
324
+ onValueChange?.(e.target.value);
325
+ },
319
326
  ...props
320
327
  }
321
328
  ));
322
329
  CommandInput.displayName = "CommandInput";
323
- var CommandList = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
330
+ var CommandList = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
324
331
  "div",
325
332
  {
326
333
  ref,
@@ -329,7 +336,7 @@ var CommandList = React23__namespace.forwardRef(({ className, ...props }, ref) =
329
336
  }
330
337
  ));
331
338
  CommandList.displayName = "CommandList";
332
- var CommandEmpty = React23__namespace.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
339
+ var CommandEmpty = React27__namespace.forwardRef((props, ref) => /* @__PURE__ */ jsxRuntime.jsx(
333
340
  "div",
334
341
  {
335
342
  ref,
@@ -338,19 +345,23 @@ var CommandEmpty = React23__namespace.forwardRef((props, ref) => /* @__PURE__ */
338
345
  }
339
346
  ));
340
347
  CommandEmpty.displayName = "CommandEmpty";
341
- var CommandGroup = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
348
+ var CommandGroup = React27__namespace.forwardRef(({ className, heading, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
342
349
  "div",
343
350
  {
344
351
  ref,
345
352
  className: cn(
346
- "overflow-hidden p-1 text-foreground [&_[cmdk-group-heading]]:px-2 [&_[cmdk-group-heading]]:py-1.5 [&_[cmdk-group-heading]]:text-xs [&_[cmdk-group-heading]]:font-medium [&_[cmdk-group-heading]]:text-muted-foreground",
353
+ "overflow-hidden p-1 text-foreground",
347
354
  className
348
355
  ),
349
- ...props
356
+ ...props,
357
+ children: [
358
+ heading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-2 py-1.5 text-xs font-medium text-muted-foreground", children: heading }),
359
+ children
360
+ ]
350
361
  }
351
362
  ));
352
363
  CommandGroup.displayName = "CommandGroup";
353
- var CommandItem = React23__namespace.forwardRef(({ className, onSelect, value, ...props }, ref) => {
364
+ var CommandItem = React27__namespace.forwardRef(({ className, onSelect, value, ...props }, ref) => {
354
365
  const handleClick = () => {
355
366
  if (onSelect && value) {
356
367
  onSelect(value);
@@ -372,7 +383,7 @@ var CommandItem = React23__namespace.forwardRef(({ className, onSelect, value, .
372
383
  CommandItem.displayName = "CommandItem";
373
384
  var Popover = PopoverPrimitive__namespace.Root;
374
385
  var PopoverTrigger = PopoverPrimitive__namespace.Trigger;
375
- var PopoverContent = React23__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
386
+ var PopoverContent = React27__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(PopoverPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsx(
376
387
  PopoverPrimitive__namespace.Content,
377
388
  {
378
389
  ref,
@@ -386,7 +397,7 @@ var PopoverContent = React23__namespace.forwardRef(({ className, align = "center
386
397
  }
387
398
  ) }));
388
399
  PopoverContent.displayName = PopoverPrimitive__namespace.Content.displayName;
389
- var Input = React23__namespace.forwardRef(
400
+ var Input = React27__namespace.forwardRef(
390
401
  ({ className, type, ...props }, ref) => {
391
402
  return /* @__PURE__ */ jsxRuntime.jsx(
392
403
  "input",
@@ -405,7 +416,7 @@ var Input = React23__namespace.forwardRef(
405
416
  Input.displayName = "Input";
406
417
  var Select = SelectPrimitive__namespace.Root;
407
418
  var SelectValue = SelectPrimitive__namespace.Value;
408
- var SelectTrigger = React23__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
419
+ var SelectTrigger = React27__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
409
420
  SelectPrimitive__namespace.Trigger,
410
421
  {
411
422
  ref,
@@ -421,7 +432,7 @@ var SelectTrigger = React23__namespace.forwardRef(({ className, children, ...pro
421
432
  }
422
433
  ));
423
434
  SelectTrigger.displayName = SelectPrimitive__namespace.Trigger.displayName;
424
- var SelectScrollUpButton = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
435
+ var SelectScrollUpButton = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
425
436
  SelectPrimitive__namespace.ScrollUpButton,
426
437
  {
427
438
  ref,
@@ -434,7 +445,7 @@ var SelectScrollUpButton = React23__namespace.forwardRef(({ className, ...props
434
445
  }
435
446
  ));
436
447
  SelectScrollUpButton.displayName = SelectPrimitive__namespace.ScrollUpButton.displayName;
437
- var SelectScrollDownButton = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
448
+ var SelectScrollDownButton = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
438
449
  SelectPrimitive__namespace.ScrollDownButton,
439
450
  {
440
451
  ref,
@@ -447,7 +458,7 @@ var SelectScrollDownButton = React23__namespace.forwardRef(({ className, ...prop
447
458
  }
448
459
  ));
449
460
  SelectScrollDownButton.displayName = SelectPrimitive__namespace.ScrollDownButton.displayName;
450
- var SelectContent = React23__namespace.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
461
+ var SelectContent = React27__namespace.forwardRef(({ className, children, position = "popper", ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(SelectPrimitive__namespace.Portal, { children: /* @__PURE__ */ jsxRuntime.jsxs(
451
462
  SelectPrimitive__namespace.Content,
452
463
  {
453
464
  ref,
@@ -475,7 +486,7 @@ var SelectContent = React23__namespace.forwardRef(({ className, children, positi
475
486
  }
476
487
  ) }));
477
488
  SelectContent.displayName = SelectPrimitive__namespace.Content.displayName;
478
- var SelectLabel = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
489
+ var SelectLabel = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
479
490
  SelectPrimitive__namespace.Label,
480
491
  {
481
492
  ref,
@@ -484,7 +495,7 @@ var SelectLabel = React23__namespace.forwardRef(({ className, ...props }, ref) =
484
495
  }
485
496
  ));
486
497
  SelectLabel.displayName = SelectPrimitive__namespace.Label.displayName;
487
- var SelectItem = React23__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
498
+ var SelectItem = React27__namespace.forwardRef(({ className, children, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsxs(
488
499
  SelectPrimitive__namespace.Item,
489
500
  {
490
501
  ref,
@@ -500,7 +511,7 @@ var SelectItem = React23__namespace.forwardRef(({ className, children, ...props
500
511
  }
501
512
  ));
502
513
  SelectItem.displayName = SelectPrimitive__namespace.Item.displayName;
503
- var SelectSeparator = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
514
+ var SelectSeparator = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
504
515
  SelectPrimitive__namespace.Separator,
505
516
  {
506
517
  ref,
@@ -512,7 +523,7 @@ SelectSeparator.displayName = SelectPrimitive__namespace.Separator.displayName;
512
523
  var TooltipProvider = TooltipPrimitive__namespace.Provider;
513
524
  var Tooltip = TooltipPrimitive__namespace.Root;
514
525
  var TooltipTrigger = TooltipPrimitive__namespace.Trigger;
515
- var TooltipContent = React23__namespace.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
526
+ var TooltipContent = React27__namespace.forwardRef(({ className, sideOffset = 4, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
516
527
  TooltipPrimitive__namespace.Content,
517
528
  {
518
529
  ref,
@@ -580,7 +591,7 @@ function FilterFieldItem({
580
591
  onOperatorChange,
581
592
  onDelete
582
593
  }) {
583
- const [isCalendarOpen, setIsCalendarOpen] = React23.useState(false);
594
+ const [isCalendarOpen, setIsCalendarOpen] = React27.useState(false);
584
595
  const renderInput = () => {
585
596
  switch (fieldConfig.type) {
586
597
  case "text":
@@ -767,10 +778,10 @@ function HazoUiMultiFilterDialog({
767
778
  title = "Filter",
768
779
  description = "Add multiple fields to filter by. Select a field and set its filter value."
769
780
  }) {
770
- const [isOpen, setIsOpen] = React23.useState(false);
771
- const [filterFields, setFilterFields] = React23.useState(initialFilters);
772
- const [isComboboxOpen, setIsComboboxOpen] = React23.useState(false);
773
- React23.useEffect(() => {
781
+ const [isOpen, setIsOpen] = React27.useState(false);
782
+ const [filterFields, setFilterFields] = React27.useState(initialFilters);
783
+ const [isComboboxOpen, setIsComboboxOpen] = React27.useState(false);
784
+ React27.useEffect(() => {
774
785
  if (isOpen) {
775
786
  setFilterFields(initialFilters);
776
787
  }
@@ -983,7 +994,7 @@ function HazoUiMultiFilterDialog({
983
994
  ] })
984
995
  ] });
985
996
  }
986
- var Switch = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
997
+ var Switch = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
987
998
  SwitchPrimitives__namespace.Root,
988
999
  {
989
1000
  className: cn(
@@ -1003,7 +1014,7 @@ var Switch = React23__namespace.forwardRef(({ className, ...props }, ref) => /*
1003
1014
  }
1004
1015
  ));
1005
1016
  Switch.displayName = SwitchPrimitives__namespace.Root.displayName;
1006
- var Label2 = React23__namespace.forwardRef(
1017
+ var Label2 = React27__namespace.forwardRef(
1007
1018
  ({ className, ...props }, ref) => {
1008
1019
  return /* @__PURE__ */ jsxRuntime.jsx(
1009
1020
  "label",
@@ -1089,16 +1100,16 @@ function HazoUiMultiSortDialog({
1089
1100
  title = "Sort",
1090
1101
  description = "Add multiple fields to sort by and reorder them. Use the switch to toggle between ascending and descending."
1091
1102
  }) {
1092
- const [isOpen, setIsOpen] = React23.useState(false);
1093
- const [sortFields, setSortFields] = React23.useState(initialSortFields);
1094
- const [isComboboxOpen, setIsComboboxOpen] = React23.useState(false);
1103
+ const [isOpen, setIsOpen] = React27.useState(false);
1104
+ const [sortFields, setSortFields] = React27.useState(initialSortFields);
1105
+ const [isComboboxOpen, setIsComboboxOpen] = React27.useState(false);
1095
1106
  const sensors = core$1.useSensors(
1096
1107
  core$1.useSensor(core$1.PointerSensor),
1097
1108
  core$1.useSensor(core$1.KeyboardSensor, {
1098
1109
  coordinateGetter: sortable.sortableKeyboardCoordinates
1099
1110
  })
1100
1111
  );
1101
- React23.useEffect(() => {
1112
+ React27.useEffect(() => {
1102
1113
  if (isOpen) {
1103
1114
  setSortFields(initialSortFields);
1104
1115
  }
@@ -1297,7 +1308,7 @@ function HazoUiMultiSortDialog({
1297
1308
  ] })
1298
1309
  ] });
1299
1310
  }
1300
- var RadioGroup = React23__namespace.forwardRef(({ className, ...props }, ref) => {
1311
+ var RadioGroup = React27__namespace.forwardRef(({ className, ...props }, ref) => {
1301
1312
  return /* @__PURE__ */ jsxRuntime.jsx(
1302
1313
  RadioGroupPrimitive__namespace.Root,
1303
1314
  {
@@ -1308,7 +1319,7 @@ var RadioGroup = React23__namespace.forwardRef(({ className, ...props }, ref) =>
1308
1319
  );
1309
1320
  });
1310
1321
  RadioGroup.displayName = RadioGroupPrimitive__namespace.Root.displayName;
1311
- var RadioGroupItem = React23__namespace.forwardRef(({ className, ...props }, ref) => {
1322
+ var RadioGroupItem = React27__namespace.forwardRef(({ className, ...props }, ref) => {
1312
1323
  return /* @__PURE__ */ jsxRuntime.jsx(
1313
1324
  RadioGroupPrimitive__namespace.Item,
1314
1325
  {
@@ -1662,7 +1673,7 @@ function filterInputValue(value, input_type, num_decimals) {
1662
1673
  }
1663
1674
  }
1664
1675
  }
1665
- var HazoUiFlexInput = React23__namespace.forwardRef(
1676
+ var HazoUiFlexInput = React27__namespace.forwardRef(
1666
1677
  ({
1667
1678
  className,
1668
1679
  input_type = "mixed",
@@ -1679,13 +1690,13 @@ var HazoUiFlexInput = React23__namespace.forwardRef(
1679
1690
  onBlur,
1680
1691
  ...props
1681
1692
  }, ref) => {
1682
- const [internalValue, setInternalValue] = React23__namespace.useState(
1693
+ const [internalValue, setInternalValue] = React27__namespace.useState(
1683
1694
  typeof controlledValue === "string" ? controlledValue : typeof controlledValue === "number" ? String(controlledValue) : ""
1684
1695
  );
1685
- const [errorMessage, setErrorMessage] = React23__namespace.useState();
1696
+ const [errorMessage, setErrorMessage] = React27__namespace.useState();
1686
1697
  const isControlled = controlledValue !== void 0;
1687
1698
  const currentValue = isControlled ? typeof controlledValue === "string" ? controlledValue : String(controlledValue || "") : internalValue;
1688
- React23__namespace.useEffect(() => {
1699
+ React27__namespace.useEffect(() => {
1689
1700
  if (isControlled) {
1690
1701
  const newValue = typeof controlledValue === "string" ? controlledValue : String(controlledValue || "");
1691
1702
  if (newValue !== internalValue) {
@@ -1765,7 +1776,7 @@ var HazoUiFlexInput = React23__namespace.forwardRef(
1765
1776
  }
1766
1777
  );
1767
1778
  HazoUiFlexInput.displayName = "HazoUiFlexInput";
1768
- var ToolbarButton = React23__namespace.forwardRef(
1779
+ var ToolbarButton = React27__namespace.forwardRef(
1769
1780
  ({ onClick, is_active = false, disabled = false, tooltip, className, children }, ref) => {
1770
1781
  const button = /* @__PURE__ */ jsxRuntime.jsx(
1771
1782
  "button",
@@ -2052,11 +2063,11 @@ var validHex = (hex) => /^#?([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
2052
2063
  var import_extends2 = __toESM(require_extends());
2053
2064
  var import_objectWithoutPropertiesLoose = __toESM(require_objectWithoutPropertiesLoose());
2054
2065
  function useEventCallback(handler) {
2055
- var callbackRef = React23.useRef(handler);
2056
- React23.useEffect(() => {
2066
+ var callbackRef = React27.useRef(handler);
2067
+ React27.useEffect(() => {
2057
2068
  callbackRef.current = handler;
2058
2069
  });
2059
- return React23.useCallback((value, event) => callbackRef.current && callbackRef.current(value, event), []);
2070
+ return React27.useCallback((value, event) => callbackRef.current && callbackRef.current(value, event), []);
2060
2071
  }
2061
2072
  var isTouch = (event) => "touches" in event;
2062
2073
  var preventDefaultMove = (event) => {
@@ -2084,16 +2095,16 @@ var getRelativePosition = (node, event) => {
2084
2095
  };
2085
2096
  };
2086
2097
  var _excluded = ["prefixCls", "className", "onMove", "onDown"];
2087
- var Interactive = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2098
+ var Interactive = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2088
2099
  var {
2089
2100
  prefixCls = "w-color-interactive",
2090
2101
  className,
2091
2102
  onMove,
2092
2103
  onDown
2093
2104
  } = props, reset = (0, import_objectWithoutPropertiesLoose.default)(props, _excluded);
2094
- var container = React23.useRef(null);
2095
- var hasTouched = React23.useRef(false);
2096
- var [isDragging, setDragging] = React23.useState(false);
2105
+ var container = React27.useRef(null);
2106
+ var hasTouched = React27.useRef(false);
2107
+ var [isDragging, setDragging] = React27.useState(false);
2097
2108
  var onMoveCallback = useEventCallback(onMove);
2098
2109
  var onKeyCallback = useEventCallback(onDown);
2099
2110
  var isValid = (event) => {
@@ -2101,7 +2112,7 @@ var Interactive = /* @__PURE__ */ React23__namespace.default.forwardRef((props,
2101
2112
  hasTouched.current = isTouch(event);
2102
2113
  return true;
2103
2114
  };
2104
- var handleMove = React23.useCallback((event) => {
2115
+ var handleMove = React27.useCallback((event) => {
2105
2116
  preventDefaultMove(event);
2106
2117
  if (!container.current) return;
2107
2118
  var isDown = isTouch(event) ? event.touches.length > 0 : event.buttons > 0;
@@ -2111,8 +2122,8 @@ var Interactive = /* @__PURE__ */ React23__namespace.default.forwardRef((props,
2111
2122
  }
2112
2123
  onMoveCallback == null || onMoveCallback(getRelativePosition(container.current, event), event);
2113
2124
  }, [onMoveCallback]);
2114
- var handleMoveEnd = React23.useCallback(() => setDragging(false), []);
2115
- var toggleDocumentEvents = React23.useCallback((state) => {
2125
+ var handleMoveEnd = React27.useCallback(() => setDragging(false), []);
2126
+ var toggleDocumentEvents = React27.useCallback((state) => {
2116
2127
  if (state) {
2117
2128
  window.addEventListener(hasTouched.current ? "touchmove" : "mousemove", handleMove);
2118
2129
  window.addEventListener(hasTouched.current ? "touchend" : "mouseup", handleMoveEnd);
@@ -2123,13 +2134,13 @@ var Interactive = /* @__PURE__ */ React23__namespace.default.forwardRef((props,
2123
2134
  window.removeEventListener("touchend", handleMoveEnd);
2124
2135
  }
2125
2136
  }, [handleMove, handleMoveEnd]);
2126
- React23.useEffect(() => {
2137
+ React27.useEffect(() => {
2127
2138
  toggleDocumentEvents(isDragging);
2128
2139
  return () => {
2129
2140
  toggleDocumentEvents(false);
2130
2141
  };
2131
2142
  }, [isDragging, handleMove, handleMoveEnd, toggleDocumentEvents]);
2132
- var handleMoveStart = React23.useCallback((event) => {
2143
+ var handleMoveStart = React27.useCallback((event) => {
2133
2144
  var activeEl = document.activeElement;
2134
2145
  activeEl == null || activeEl.blur();
2135
2146
  preventDefaultMove(event.nativeEvent);
@@ -2173,7 +2184,7 @@ var Pointer = (_ref) => {
2173
2184
  borderRadius: "50%",
2174
2185
  backgroundColor: color2
2175
2186
  };
2176
- return React23.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("div", {
2187
+ return React27.useMemo(() => /* @__PURE__ */ jsxRuntime.jsx("div", {
2177
2188
  className: prefixCls + "-pointer " + (className || ""),
2178
2189
  style,
2179
2190
  children: /* @__PURE__ */ jsxRuntime.jsx("div", {
@@ -2183,7 +2194,7 @@ var Pointer = (_ref) => {
2183
2194
  }), [top, left, color2, className, prefixCls]);
2184
2195
  };
2185
2196
  var _excluded2 = ["prefixCls", "radius", "pointer", "className", "hue", "style", "hsva", "onChange"];
2186
- var Saturation = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2197
+ var Saturation = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2187
2198
  var _hsva$h;
2188
2199
  var {
2189
2200
  prefixCls = "w-color-saturation",
@@ -2211,7 +2222,7 @@ var Saturation = /* @__PURE__ */ React23__namespace.default.forwardRef((props, r
2211
2222
  // source: 'hsv',
2212
2223
  });
2213
2224
  };
2214
- var handleKeyDown = React23.useCallback((event) => {
2225
+ var handleKeyDown = React27.useCallback((event) => {
2215
2226
  if (!hsva || !onChange) return;
2216
2227
  var step = 1;
2217
2228
  var newS = hsva.s;
@@ -2250,7 +2261,7 @@ var Saturation = /* @__PURE__ */ React23__namespace.default.forwardRef((props, r
2250
2261
  });
2251
2262
  }
2252
2263
  }, [hsva, onChange]);
2253
- var pointerElement = React23.useMemo(() => {
2264
+ var pointerElement = React27.useMemo(() => {
2254
2265
  if (!hsva) return null;
2255
2266
  var comProps = {
2256
2267
  top: 100 - hsva.v + "%",
@@ -2266,7 +2277,7 @@ var Saturation = /* @__PURE__ */ React23__namespace.default.forwardRef((props, r
2266
2277
  prefixCls
2267
2278
  }, comProps));
2268
2279
  }, [hsva, pointer, prefixCls]);
2269
- var handleClick = React23.useCallback((event) => {
2280
+ var handleClick = React27.useCallback((event) => {
2270
2281
  event.target.focus();
2271
2282
  }, []);
2272
2283
  return /* @__PURE__ */ jsxRuntime.jsx(esm_default, (0, import_extends3.default)({
@@ -2335,7 +2346,7 @@ var Pointer2 = (_ref) => {
2335
2346
  };
2336
2347
  var _excluded4 = ["prefixCls", "className", "hsva", "background", "bgProps", "innerProps", "pointerProps", "radius", "width", "height", "direction", "style", "onChange", "pointer"];
2337
2348
  var BACKGROUND_IMG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAMUlEQVQ4T2NkYGAQYcAP3uCTZhw1gGGYhAGBZIA/nYDCgBDAm9BGDWAAJyRCgLaBCAAgXwixzAS0pgAAAABJRU5ErkJggg==";
2338
- var Alpha = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2349
+ var Alpha = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2339
2350
  var {
2340
2351
  prefixCls = "w-color-alpha",
2341
2352
  className,
@@ -2380,7 +2391,7 @@ var Alpha = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) =
2380
2391
  }, style, {
2381
2392
  position: "relative"
2382
2393
  });
2383
- var handleKeyDown = React23.useCallback((event) => {
2394
+ var handleKeyDown = React27.useCallback((event) => {
2384
2395
  var step = 0.01;
2385
2396
  var currentAlpha = hsva.a;
2386
2397
  var newAlpha = currentAlpha;
@@ -2426,7 +2437,7 @@ var Alpha = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) =
2426
2437
  }), syntheticOffset);
2427
2438
  }
2428
2439
  }, [hsva, direction, onChange]);
2429
- var handleClick = React23.useCallback((event) => {
2440
+ var handleClick = React27.useCallback((event) => {
2430
2441
  event.target.focus();
2431
2442
  }, []);
2432
2443
  var pointerElement = pointer && typeof pointer === "function" ? pointer((0, import_extends5.default)({
@@ -2469,7 +2480,7 @@ var import_objectWithoutPropertiesLoose5 = __toESM(require_objectWithoutProperti
2469
2480
  var _excluded5 = ["prefixCls", "placement", "label", "value", "className", "style", "labelStyle", "inputStyle", "onChange", "onBlur", "renderInput"];
2470
2481
  var validHex2 = (hex) => /^#?([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
2471
2482
  var getNumberValue = (value) => Number(String(value).replace(/%/g, ""));
2472
- var EditableInput = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2483
+ var EditableInput = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2473
2484
  var {
2474
2485
  prefixCls = "w-color-editable-input",
2475
2486
  placement = "bottom",
@@ -2483,9 +2494,9 @@ var EditableInput = /* @__PURE__ */ React23__namespace.default.forwardRef((props
2483
2494
  onBlur,
2484
2495
  renderInput
2485
2496
  } = props, other = (0, import_objectWithoutPropertiesLoose5.default)(props, _excluded5);
2486
- var [value, setValue] = React23.useState(initValue);
2487
- var isFocus = React23.useRef(false);
2488
- React23.useEffect(() => {
2497
+ var [value, setValue] = React27.useState(initValue);
2498
+ var isFocus = React27.useRef(false);
2499
+ React27.useEffect(() => {
2489
2500
  if (props.value !== value) {
2490
2501
  if (!isFocus.current) {
2491
2502
  setValue(props.value);
@@ -2574,7 +2585,7 @@ var esm_default4 = EditableInput;
2574
2585
  var import_extends7 = __toESM(require_extends());
2575
2586
  var import_objectWithoutPropertiesLoose6 = __toESM(require_objectWithoutPropertiesLoose());
2576
2587
  var _excluded6 = ["prefixCls", "hsva", "placement", "rProps", "gProps", "bProps", "aProps", "className", "style", "onChange"];
2577
- var EditableInputRGBA = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2588
+ var EditableInputRGBA = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2578
2589
  var {
2579
2590
  prefixCls = "w-color-editable-input-rgba",
2580
2591
  hsva,
@@ -2697,7 +2708,7 @@ var esm_default5 = EditableInputRGBA;
2697
2708
  var import_extends8 = __toESM(require_extends());
2698
2709
  var import_objectWithoutPropertiesLoose7 = __toESM(require_objectWithoutPropertiesLoose());
2699
2710
  var _excluded7 = ["prefixCls", "className", "hue", "onChange", "direction"];
2700
- var Hue = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2711
+ var Hue = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2701
2712
  var {
2702
2713
  prefixCls = "w-color-hue",
2703
2714
  className,
@@ -2731,7 +2742,7 @@ var esm_default6 = Hue;
2731
2742
  var import_extends9 = __toESM(require_extends());
2732
2743
  var import_objectWithoutPropertiesLoose8 = __toESM(require_objectWithoutPropertiesLoose());
2733
2744
  var _excluded8 = ["prefixCls", "className", "color", "colors", "style", "rectProps", "onChange", "addonAfter", "addonBefore", "rectRender"];
2734
- var Swatch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2745
+ var Swatch = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2735
2746
  var {
2736
2747
  prefixCls = "w-color-swatch",
2737
2748
  className,
@@ -2768,7 +2779,7 @@ var Swatch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref)
2768
2779
  flexWrap: "wrap",
2769
2780
  position: "relative"
2770
2781
  }, style),
2771
- children: [addonBefore && /* @__PURE__ */ React23__namespace.default.isValidElement(addonBefore) && addonBefore, colors && Array.isArray(colors) && colors.map((item, idx) => {
2782
+ children: [addonBefore && /* @__PURE__ */ React27__namespace.default.isValidElement(addonBefore) && addonBefore, colors && Array.isArray(colors) && colors.map((item, idx) => {
2772
2783
  var title = "";
2773
2784
  var background = "";
2774
2785
  if (typeof item === "string") {
@@ -2790,11 +2801,11 @@ var Swatch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref)
2790
2801
  onClick: (evn) => handleClick(background, evn)
2791
2802
  });
2792
2803
  if (render) {
2793
- return /* @__PURE__ */ jsxRuntime.jsx(React23.Fragment, {
2804
+ return /* @__PURE__ */ jsxRuntime.jsx(React27.Fragment, {
2794
2805
  children: render
2795
2806
  }, idx);
2796
2807
  }
2797
- var child = rectProps.children && /* @__PURE__ */ React23__namespace.default.isValidElement(rectProps.children) ? /* @__PURE__ */ React23__namespace.default.cloneElement(rectProps.children, {
2808
+ var child = rectProps.children && /* @__PURE__ */ React27__namespace.default.isValidElement(rectProps.children) ? /* @__PURE__ */ React27__namespace.default.cloneElement(rectProps.children, {
2798
2809
  color: background,
2799
2810
  checked
2800
2811
  }) : null;
@@ -2808,7 +2819,7 @@ var Swatch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref)
2808
2819
  background
2809
2820
  })
2810
2821
  }), idx);
2811
- }), addonAfter && /* @__PURE__ */ React23__namespace.default.isValidElement(addonAfter) && addonAfter]
2822
+ }), addonAfter && /* @__PURE__ */ React27__namespace.default.isValidElement(addonAfter) && addonAfter]
2812
2823
  }));
2813
2824
  });
2814
2825
  Swatch.displayName = "Swatch";
@@ -2827,7 +2838,7 @@ var Bar = (props) => /* @__PURE__ */ jsxRuntime.jsx("div", {
2827
2838
  backgroundColor: "#fff"
2828
2839
  }
2829
2840
  });
2830
- var Sketch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref) => {
2841
+ var Sketch = /* @__PURE__ */ React27__namespace.default.forwardRef((props, ref) => {
2831
2842
  var {
2832
2843
  prefixCls = "w-color-sketch",
2833
2844
  className,
@@ -2839,13 +2850,13 @@ var Sketch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref)
2839
2850
  disableAlpha = false,
2840
2851
  style
2841
2852
  } = props, other = (0, import_objectWithoutPropertiesLoose9.default)(props, _excluded9);
2842
- var [hsva, setHsva] = React23.useState({
2853
+ var [hsva, setHsva] = React27.useState({
2843
2854
  h: 209,
2844
2855
  s: 36,
2845
2856
  v: 90,
2846
2857
  a: 1
2847
2858
  });
2848
- React23.useEffect(() => {
2859
+ React27.useEffect(() => {
2849
2860
  if (typeof color2 === "string" && validHex(color2)) {
2850
2861
  setHsva(hexToHsva(color2));
2851
2862
  }
@@ -2963,7 +2974,7 @@ var Sketch = /* @__PURE__ */ React23__namespace.default.forwardRef((props, ref)
2963
2974
  innerProps: {
2964
2975
  style: styleAlpha
2965
2976
  },
2966
- pointer: () => /* @__PURE__ */ jsxRuntime.jsx(React23.Fragment, {})
2977
+ pointer: () => /* @__PURE__ */ jsxRuntime.jsx(React27.Fragment, {})
2967
2978
  })]
2968
2979
  })]
2969
2980
  }), editableDisable && /* @__PURE__ */ jsxRuntime.jsxs("div", {
@@ -3078,19 +3089,19 @@ var Toolbar = ({
3078
3089
  on_attachments_change,
3079
3090
  disabled = false
3080
3091
  }) => {
3081
- const [link_url, set_link_url] = React23__namespace.useState("https://");
3082
- const [link_popover_open, set_link_popover_open] = React23__namespace.useState(false);
3083
- const [text_color_open, set_text_color_open] = React23__namespace.useState(false);
3084
- const [highlight_color_open, set_highlight_color_open] = React23__namespace.useState(false);
3085
- const [variables_menu_open, set_variables_menu_open] = React23__namespace.useState(false);
3086
- const [table_menu_open, set_table_menu_open] = React23__namespace.useState(false);
3087
- const [text_color, set_text_color] = React23__namespace.useState("#000000");
3088
- const [highlight_color, set_highlight_color] = React23__namespace.useState("#ffff00");
3089
- const [table_rows, set_table_rows] = React23__namespace.useState(3);
3090
- const [table_cols, set_table_cols] = React23__namespace.useState(3);
3091
- const [hovered_cell, set_hovered_cell] = React23__namespace.useState(null);
3092
- const file_input_ref = React23__namespace.useRef(null);
3093
- const image_input_ref = React23__namespace.useRef(null);
3092
+ const [link_url, set_link_url] = React27__namespace.useState("https://");
3093
+ const [link_popover_open, set_link_popover_open] = React27__namespace.useState(false);
3094
+ const [text_color_open, set_text_color_open] = React27__namespace.useState(false);
3095
+ const [highlight_color_open, set_highlight_color_open] = React27__namespace.useState(false);
3096
+ const [variables_menu_open, set_variables_menu_open] = React27__namespace.useState(false);
3097
+ const [table_menu_open, set_table_menu_open] = React27__namespace.useState(false);
3098
+ const [text_color, set_text_color] = React27__namespace.useState("#000000");
3099
+ const [highlight_color, set_highlight_color] = React27__namespace.useState("#ffff00");
3100
+ const [table_rows, set_table_rows] = React27__namespace.useState(3);
3101
+ const [table_cols, set_table_cols] = React27__namespace.useState(3);
3102
+ const [hovered_cell, set_hovered_cell] = React27__namespace.useState(null);
3103
+ const file_input_ref = React27__namespace.useRef(null);
3104
+ const image_input_ref = React27__namespace.useRef(null);
3094
3105
  if (!editor) {
3095
3106
  return null;
3096
3107
  }
@@ -4023,7 +4034,7 @@ var VariableExtension = core.Node.create({
4023
4034
  }
4024
4035
  });
4025
4036
  var Tabs = TabsPrimitive__namespace.Root;
4026
- var TabsList = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4037
+ var TabsList = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4027
4038
  TabsPrimitive__namespace.List,
4028
4039
  {
4029
4040
  ref,
@@ -4035,7 +4046,7 @@ var TabsList = React23__namespace.forwardRef(({ className, ...props }, ref) => /
4035
4046
  }
4036
4047
  ));
4037
4048
  TabsList.displayName = TabsPrimitive__namespace.List.displayName;
4038
- var TabsTrigger = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4049
+ var TabsTrigger = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4039
4050
  TabsPrimitive__namespace.Trigger,
4040
4051
  {
4041
4052
  ref,
@@ -4047,7 +4058,7 @@ var TabsTrigger = React23__namespace.forwardRef(({ className, ...props }, ref) =
4047
4058
  }
4048
4059
  ));
4049
4060
  TabsTrigger.displayName = TabsPrimitive__namespace.Trigger.displayName;
4050
- var TabsContent = React23__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4061
+ var TabsContent = React27__namespace.forwardRef(({ className, ...props }, ref) => /* @__PURE__ */ jsxRuntime.jsx(
4051
4062
  TabsPrimitive__namespace.Content,
4052
4063
  {
4053
4064
  ref,
@@ -4082,14 +4093,14 @@ var HazoUiRte = ({
4082
4093
  className,
4083
4094
  show_output_viewer = false
4084
4095
  }) => {
4085
- const [attachments, set_attachments] = React23__namespace.useState(
4096
+ const [attachments, set_attachments] = React27__namespace.useState(
4086
4097
  initial_attachments
4087
4098
  );
4088
- const [active_tab, set_active_tab] = React23__namespace.useState("html");
4099
+ const [active_tab, set_active_tab] = React27__namespace.useState("html");
4089
4100
  const is_view_only = active_tab !== "html";
4090
- const attachments_ref = React23__namespace.useRef(attachments);
4101
+ const attachments_ref = React27__namespace.useRef(attachments);
4091
4102
  attachments_ref.current = attachments;
4092
- const debounced_on_change = React23__namespace.useMemo(
4103
+ const debounced_on_change = React27__namespace.useMemo(
4093
4104
  () => debounce_fn((output) => {
4094
4105
  if (on_change) {
4095
4106
  on_change(output);
@@ -4188,7 +4199,7 @@ var HazoUiRte = ({
4188
4199
  debounced_on_change(output);
4189
4200
  }
4190
4201
  });
4191
- React23__namespace.useEffect(() => {
4202
+ React27__namespace.useEffect(() => {
4192
4203
  if (editor && html !== void 0) {
4193
4204
  const current_html = editor.getHTML();
4194
4205
  if (html !== current_html && !editor.isFocused) {
@@ -4196,21 +4207,21 @@ var HazoUiRte = ({
4196
4207
  }
4197
4208
  }
4198
4209
  }, [html, editor]);
4199
- React23__namespace.useEffect(() => {
4210
+ React27__namespace.useEffect(() => {
4200
4211
  if (editor) {
4201
4212
  editor.setEditable(!disabled);
4202
4213
  }
4203
4214
  }, [disabled, editor]);
4204
- const attachments_from_props_ref = React23__namespace.useRef(false);
4205
- const prev_initial_attachments_ref = React23__namespace.useRef(initial_attachments);
4206
- React23__namespace.useEffect(() => {
4215
+ const attachments_from_props_ref = React27__namespace.useRef(false);
4216
+ const prev_initial_attachments_ref = React27__namespace.useRef(initial_attachments);
4217
+ React27__namespace.useEffect(() => {
4207
4218
  if (JSON.stringify(initial_attachments) !== JSON.stringify(prev_initial_attachments_ref.current)) {
4208
4219
  prev_initial_attachments_ref.current = initial_attachments;
4209
4220
  attachments_from_props_ref.current = true;
4210
4221
  set_attachments(initial_attachments);
4211
4222
  }
4212
4223
  }, [initial_attachments]);
4213
- React23__namespace.useEffect(() => {
4224
+ React27__namespace.useEffect(() => {
4214
4225
  if (attachments_from_props_ref.current) {
4215
4226
  attachments_from_props_ref.current = false;
4216
4227
  return;
@@ -4304,11 +4315,1606 @@ var HazoUiRte = ({
4304
4315
  );
4305
4316
  };
4306
4317
  HazoUiRte.displayName = "HazoUiRte";
4318
+ var generate_command_id = () => {
4319
+ return `cmd_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
4320
+ };
4321
+ var get_variant_classes = (variant = "default") => {
4322
+ switch (variant) {
4323
+ case "outline":
4324
+ return "bg-transparent border-primary/40 text-primary";
4325
+ case "subtle":
4326
+ return "bg-muted border-transparent text-muted-foreground";
4327
+ case "default":
4328
+ default:
4329
+ return "bg-primary/10 text-primary border-primary/20";
4330
+ }
4331
+ };
4332
+ var CommandPillView = ({ node, selected, editor }) => {
4333
+ const { prefix, action, action_label, id, variant } = node.attrs;
4334
+ const handle_click = () => {
4335
+ const event = new CustomEvent("command-pill-click", {
4336
+ detail: {
4337
+ id,
4338
+ prefix,
4339
+ action,
4340
+ action_label,
4341
+ node_pos: editor.state.selection.from - 1
4342
+ },
4343
+ bubbles: true
4344
+ });
4345
+ document.dispatchEvent(event);
4346
+ };
4347
+ return /* @__PURE__ */ jsxRuntime.jsx(react.NodeViewWrapper, { as: "span", className: "inline", children: /* @__PURE__ */ jsxRuntime.jsxs(
4348
+ "span",
4349
+ {
4350
+ className: cn(
4351
+ "cls_command_pill",
4352
+ "inline-flex items-center",
4353
+ "px-1.5 py-0.5 mx-0.5",
4354
+ "rounded-md",
4355
+ "text-sm font-medium",
4356
+ "border",
4357
+ "cursor-pointer select-none",
4358
+ "transition-all duration-150",
4359
+ get_variant_classes(variant),
4360
+ selected && "ring-2 ring-ring ring-offset-1",
4361
+ "hover:opacity-80"
4362
+ ),
4363
+ contentEditable: false,
4364
+ "data-command-id": id,
4365
+ "data-command-prefix": prefix,
4366
+ "data-command-action": action,
4367
+ onClick: handle_click,
4368
+ children: [
4369
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground opacity-70", children: prefix }),
4370
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: action_label })
4371
+ ]
4372
+ }
4373
+ ) });
4374
+ };
4375
+ var CommandNodeExtension = core.Node.create({
4376
+ name: "commandNode",
4377
+ group: "inline",
4378
+ inline: true,
4379
+ // Atomic means the node cannot be split or merged
4380
+ atom: true,
4381
+ // Draggable in the editor
4382
+ draggable: true,
4383
+ // Selectable as a whole unit
4384
+ selectable: true,
4385
+ addAttributes() {
4386
+ return {
4387
+ id: {
4388
+ default: null,
4389
+ parseHTML: (element) => element.getAttribute("data-command-id"),
4390
+ renderHTML: (attributes) => ({
4391
+ "data-command-id": attributes.id
4392
+ })
4393
+ },
4394
+ prefix: {
4395
+ default: "",
4396
+ parseHTML: (element) => element.getAttribute("data-command-prefix"),
4397
+ renderHTML: (attributes) => ({
4398
+ "data-command-prefix": attributes.prefix
4399
+ })
4400
+ },
4401
+ action: {
4402
+ default: "",
4403
+ parseHTML: (element) => element.getAttribute("data-command-action"),
4404
+ renderHTML: (attributes) => ({
4405
+ "data-command-action": attributes.action
4406
+ })
4407
+ },
4408
+ action_label: {
4409
+ default: "",
4410
+ parseHTML: (element) => element.getAttribute("data-command-label"),
4411
+ renderHTML: (attributes) => ({
4412
+ "data-command-label": attributes.action_label
4413
+ })
4414
+ },
4415
+ variant: {
4416
+ default: "default",
4417
+ parseHTML: (element) => element.getAttribute("data-command-variant") || "default",
4418
+ renderHTML: (attributes) => ({
4419
+ "data-command-variant": attributes.variant
4420
+ })
4421
+ }
4422
+ };
4423
+ },
4424
+ parseHTML() {
4425
+ return [
4426
+ {
4427
+ tag: "span[data-command-id]"
4428
+ }
4429
+ ];
4430
+ },
4431
+ renderHTML({ HTMLAttributes }) {
4432
+ return [
4433
+ "span",
4434
+ core.mergeAttributes(HTMLAttributes, {
4435
+ class: "cls_command_pill",
4436
+ contenteditable: "false"
4437
+ }),
4438
+ `${HTMLAttributes["data-command-prefix"]}${HTMLAttributes["data-command-label"]}`
4439
+ ];
4440
+ },
4441
+ // Output format: prefix + action (e.g., "@user_123", "/due_date")
4442
+ renderText({ node }) {
4443
+ return `${node.attrs.prefix}${node.attrs.action}`;
4444
+ },
4445
+ addNodeView() {
4446
+ return react.ReactNodeViewRenderer(CommandPillView);
4447
+ },
4448
+ addCommands() {
4449
+ return {
4450
+ insertCommand: (attrs) => ({ commands }) => {
4451
+ return commands.insertContent({
4452
+ type: this.name,
4453
+ attrs: {
4454
+ ...attrs,
4455
+ id: generate_command_id()
4456
+ }
4457
+ });
4458
+ },
4459
+ updateCommand: (id, attrs) => ({ tr, state }) => {
4460
+ let updated = false;
4461
+ state.doc.descendants((node, pos) => {
4462
+ if (node.type.name === this.name && node.attrs.id === id) {
4463
+ tr.setNodeMarkup(pos, void 0, {
4464
+ ...node.attrs,
4465
+ ...attrs
4466
+ });
4467
+ updated = true;
4468
+ return false;
4469
+ }
4470
+ });
4471
+ return updated;
4472
+ }
4473
+ };
4474
+ },
4475
+ // Keyboard behavior - delete entire node on backspace
4476
+ addKeyboardShortcuts() {
4477
+ return {
4478
+ Backspace: () => this.editor.commands.command(({ tr, state }) => {
4479
+ let is_command = false;
4480
+ const { selection } = state;
4481
+ const { empty, anchor } = selection;
4482
+ if (!empty) {
4483
+ return false;
4484
+ }
4485
+ state.doc.nodesBetween(anchor - 1, anchor, (node, pos) => {
4486
+ if (node.type.name === this.name) {
4487
+ is_command = true;
4488
+ tr.insertText("", pos, pos + node.nodeSize);
4489
+ return false;
4490
+ }
4491
+ });
4492
+ return is_command;
4493
+ })
4494
+ };
4495
+ }
4496
+ });
4497
+ var create_suggestion_config = (prefix_config, on_suggestion_change, on_insert_command) => {
4498
+ return {
4499
+ char: prefix_config.char,
4500
+ allowSpaces: false,
4501
+ startOfLine: false,
4502
+ items: ({ query }) => {
4503
+ if (!query) return prefix_config.commands;
4504
+ const lower_query = query.toLowerCase();
4505
+ return prefix_config.commands.filter(
4506
+ (cmd) => cmd.action_label.toLowerCase().includes(lower_query) || cmd.action.toLowerCase().includes(lower_query) || cmd.action_description?.toLowerCase().includes(lower_query)
4507
+ );
4508
+ },
4509
+ render: () => {
4510
+ return {
4511
+ onStart: (props) => {
4512
+ on_suggestion_change({
4513
+ is_active: true,
4514
+ query: props.query,
4515
+ prefix: prefix_config.char,
4516
+ client_rect: props.clientRect,
4517
+ commands: prefix_config.commands,
4518
+ range: props.range
4519
+ });
4520
+ },
4521
+ onUpdate: (props) => {
4522
+ on_suggestion_change({
4523
+ is_active: true,
4524
+ query: props.query,
4525
+ prefix: prefix_config.char,
4526
+ client_rect: props.clientRect,
4527
+ commands: prefix_config.commands,
4528
+ range: props.range
4529
+ });
4530
+ },
4531
+ onKeyDown: (props) => {
4532
+ if (props.event.key === "Escape") {
4533
+ on_suggestion_change(null);
4534
+ return true;
4535
+ }
4536
+ if (props.event.key === "ArrowUp" || props.event.key === "ArrowDown" || props.event.key === "Enter") {
4537
+ return true;
4538
+ }
4539
+ return false;
4540
+ },
4541
+ onExit: () => {
4542
+ on_suggestion_change(null);
4543
+ }
4544
+ };
4545
+ },
4546
+ command: ({ range, props }) => {
4547
+ const command = props;
4548
+ on_insert_command(command, prefix_config.char, range);
4549
+ }
4550
+ };
4551
+ };
4552
+ var create_command_suggestion_extension = (config) => {
4553
+ const { prefixes, on_suggestion_change, on_insert_command } = config;
4554
+ return prefixes.map((prefix_config, index) => {
4555
+ return core.Extension.create({
4556
+ name: `commandSuggestion_${prefix_config.char}_${index}`,
4557
+ addProseMirrorPlugins() {
4558
+ return [
4559
+ Suggestion__default.default({
4560
+ editor: this.editor,
4561
+ ...create_suggestion_config(
4562
+ prefix_config,
4563
+ on_suggestion_change,
4564
+ on_insert_command
4565
+ )
4566
+ })
4567
+ ];
4568
+ }
4569
+ });
4570
+ });
4571
+ };
4572
+ var insert_command_at_position = (editor, command, prefix, range, variant = "default") => {
4573
+ editor.chain().focus().deleteRange(range).insertCommand({
4574
+ prefix,
4575
+ action: command.action,
4576
+ action_label: command.action_label,
4577
+ variant
4578
+ }).run();
4579
+ };
4580
+ var get_variant_classes2 = (variant = "default") => {
4581
+ switch (variant) {
4582
+ case "outline":
4583
+ return "bg-transparent border-primary/40 text-primary hover:bg-primary/5";
4584
+ case "subtle":
4585
+ return "bg-muted border-transparent text-muted-foreground hover:bg-muted/80";
4586
+ case "default":
4587
+ default:
4588
+ return "bg-primary/10 text-primary border-primary/20 hover:bg-primary/15";
4589
+ }
4590
+ };
4591
+ var CommandPill = ({
4592
+ prefix,
4593
+ action,
4594
+ action_label,
4595
+ id,
4596
+ selected = false,
4597
+ variant = "default",
4598
+ on_click
4599
+ }) => {
4600
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4601
+ "span",
4602
+ {
4603
+ className: cn(
4604
+ "cls_command_pill_standalone",
4605
+ "inline-flex items-center",
4606
+ "px-1.5 py-0.5",
4607
+ "rounded-md",
4608
+ "text-sm font-medium",
4609
+ "border",
4610
+ "transition-all duration-150",
4611
+ get_variant_classes2(variant),
4612
+ selected && "ring-2 ring-ring ring-offset-1",
4613
+ on_click && "cursor-pointer"
4614
+ ),
4615
+ "data-command-id": id,
4616
+ "data-command-prefix": prefix,
4617
+ "data-command-action": action,
4618
+ onClick: on_click,
4619
+ role: on_click ? "button" : void 0,
4620
+ tabIndex: on_click ? 0 : void 0,
4621
+ onKeyDown: (e) => {
4622
+ if (on_click && (e.key === "Enter" || e.key === " ")) {
4623
+ e.preventDefault();
4624
+ on_click();
4625
+ }
4626
+ },
4627
+ children: [
4628
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground opacity-70", children: prefix }),
4629
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: action_label })
4630
+ ]
4631
+ }
4632
+ );
4633
+ };
4634
+ CommandPill.displayName = "CommandPill";
4635
+ var group_commands = (commands) => {
4636
+ const groups = /* @__PURE__ */ new Map();
4637
+ for (const cmd of commands) {
4638
+ const group_name = cmd.group || "";
4639
+ if (!groups.has(group_name)) {
4640
+ groups.set(group_name, []);
4641
+ }
4642
+ groups.get(group_name).push(cmd);
4643
+ }
4644
+ return groups;
4645
+ };
4646
+ var CommandPopover = ({
4647
+ is_open,
4648
+ commands,
4649
+ prefix,
4650
+ query,
4651
+ selected_index,
4652
+ position,
4653
+ on_select,
4654
+ on_close,
4655
+ on_selection_change: _on_selection_change
4656
+ }) => {
4657
+ const container_ref = React27__namespace.useRef(null);
4658
+ const grouped_commands = React27__namespace.useMemo(
4659
+ () => group_commands(commands),
4660
+ [commands]
4661
+ );
4662
+ React27__namespace.useEffect(() => {
4663
+ const handle_click_outside = (e) => {
4664
+ if (container_ref.current && !container_ref.current.contains(e.target)) {
4665
+ on_close();
4666
+ }
4667
+ };
4668
+ if (is_open) {
4669
+ document.addEventListener("mousedown", handle_click_outside);
4670
+ return () => {
4671
+ document.removeEventListener("mousedown", handle_click_outside);
4672
+ };
4673
+ }
4674
+ }, [is_open, on_close]);
4675
+ const [mounted, set_mounted] = React27__namespace.useState(false);
4676
+ React27__namespace.useEffect(() => {
4677
+ set_mounted(true);
4678
+ }, []);
4679
+ if (!is_open || !mounted) return null;
4680
+ const popover_content = /* @__PURE__ */ jsxRuntime.jsx(
4681
+ "div",
4682
+ {
4683
+ ref: container_ref,
4684
+ className: cn(
4685
+ "cls_command_popover",
4686
+ "fixed z-[9999]",
4687
+ "w-64 min-w-[200px] max-w-[300px]",
4688
+ "rounded-md border bg-popover text-popover-foreground shadow-lg",
4689
+ "animate-in fade-in-0 zoom-in-95"
4690
+ ),
4691
+ style: {
4692
+ top: position.top,
4693
+ left: position.left
4694
+ },
4695
+ children: /* @__PURE__ */ jsxRuntime.jsxs(Command, { className: "rounded-md", children: [
4696
+ query && /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "px-3 py-2 text-xs text-muted-foreground border-b", children: [
4697
+ "Searching: ",
4698
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { className: "font-medium", children: [
4699
+ prefix,
4700
+ query
4701
+ ] })
4702
+ ] }),
4703
+ /* @__PURE__ */ jsxRuntime.jsxs(CommandList, { className: "max-h-[200px]", children: [
4704
+ commands.length === 0 && /* @__PURE__ */ jsxRuntime.jsx(CommandEmpty, { children: "No commands found." }),
4705
+ Array.from(grouped_commands.entries()).map(([group_name, group_commands2]) => /* @__PURE__ */ jsxRuntime.jsx(
4706
+ CommandGroup,
4707
+ {
4708
+ heading: group_name || void 0,
4709
+ children: group_commands2.map((cmd, idx) => {
4710
+ let flat_idx = 0;
4711
+ for (const [g, cmds] of grouped_commands.entries()) {
4712
+ if (g === group_name) {
4713
+ flat_idx += idx;
4714
+ break;
4715
+ }
4716
+ flat_idx += cmds.length;
4717
+ }
4718
+ return /* @__PURE__ */ jsxRuntime.jsx(
4719
+ CommandItem,
4720
+ {
4721
+ value: cmd.action,
4722
+ onSelect: () => on_select(cmd),
4723
+ className: cn(
4724
+ flat_idx === selected_index && "bg-accent"
4725
+ ),
4726
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 w-full", children: [
4727
+ cmd.icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-shrink-0 text-muted-foreground", children: cmd.icon }),
4728
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
4729
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-medium truncate", children: [
4730
+ prefix,
4731
+ cmd.action_label
4732
+ ] }),
4733
+ cmd.action_description && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-muted-foreground truncate", children: cmd.action_description })
4734
+ ] })
4735
+ ] })
4736
+ },
4737
+ cmd.action
4738
+ );
4739
+ })
4740
+ },
4741
+ group_name || "default"
4742
+ ))
4743
+ ] })
4744
+ ] })
4745
+ }
4746
+ );
4747
+ return reactDom.createPortal(popover_content, document.body);
4748
+ };
4749
+ CommandPopover.displayName = "CommandPopover";
4750
+
4751
+ // src/components/hazo_ui_command/index.tsx
4752
+ var parse_commands_from_text = (text, prefixes) => {
4753
+ const result = [];
4754
+ const action_to_label = /* @__PURE__ */ new Map();
4755
+ for (const prefix_config of prefixes) {
4756
+ for (const cmd of prefix_config.commands) {
4757
+ action_to_label.set(`${prefix_config.char}${cmd.action}`, {
4758
+ label: cmd.action_label,
4759
+ prefix: prefix_config.char
4760
+ });
4761
+ }
4762
+ }
4763
+ const prefix_chars = prefixes.map((p) => escape_regex(p.char)).join("|");
4764
+ const pattern = new RegExp(`(${prefix_chars})(\\w+)`, "g");
4765
+ let match;
4766
+ while ((match = pattern.exec(text)) !== null) {
4767
+ const full_match = match[0];
4768
+ const prefix = match[1];
4769
+ const action = match[2];
4770
+ const lookup_key = `${prefix}${action}`;
4771
+ const info = action_to_label.get(lookup_key);
4772
+ if (info) {
4773
+ result.push({
4774
+ action,
4775
+ action_label: info.label,
4776
+ prefix,
4777
+ position: match.index,
4778
+ length: full_match.length
4779
+ });
4780
+ }
4781
+ }
4782
+ return result;
4783
+ };
4784
+ var escape_regex = (str) => {
4785
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
4786
+ };
4787
+ var text_to_tiptap_content = (text, prefixes, variant = "default") => {
4788
+ const commands = parse_commands_from_text(text, prefixes);
4789
+ if (commands.length === 0) {
4790
+ return {
4791
+ type: "doc",
4792
+ content: [
4793
+ {
4794
+ type: "paragraph",
4795
+ content: text ? [{ type: "text", text }] : []
4796
+ }
4797
+ ]
4798
+ };
4799
+ }
4800
+ commands.sort((a, b) => a.position - b.position);
4801
+ const content = [];
4802
+ let last_end = 0;
4803
+ for (const cmd of commands) {
4804
+ if (cmd.position > last_end) {
4805
+ content.push({
4806
+ type: "text",
4807
+ text: text.slice(last_end, cmd.position)
4808
+ });
4809
+ }
4810
+ content.push({
4811
+ type: "commandNode",
4812
+ attrs: {
4813
+ id: `cmd_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`,
4814
+ prefix: cmd.prefix,
4815
+ action: cmd.action,
4816
+ action_label: cmd.action_label,
4817
+ variant
4818
+ }
4819
+ });
4820
+ last_end = cmd.position + cmd.length;
4821
+ }
4822
+ if (last_end < text.length) {
4823
+ content.push({
4824
+ type: "text",
4825
+ text: text.slice(last_end)
4826
+ });
4827
+ }
4828
+ return {
4829
+ type: "doc",
4830
+ content: [
4831
+ {
4832
+ type: "paragraph",
4833
+ content
4834
+ }
4835
+ ]
4836
+ };
4837
+ };
4838
+ var Document = core.Node.create({
4839
+ name: "doc",
4840
+ topNode: true,
4841
+ content: "block+",
4842
+ renderMarkdown: (node, h) => {
4843
+ if (!node.content) {
4844
+ return "";
4845
+ }
4846
+ return h.renderChildren(node.content, "\n\n");
4847
+ }
4848
+ });
4849
+ var index_default = Document;
4850
+ var Paragraph = core.Node.create({
4851
+ name: "paragraph",
4852
+ priority: 1e3,
4853
+ addOptions() {
4854
+ return {
4855
+ HTMLAttributes: {}
4856
+ };
4857
+ },
4858
+ group: "block",
4859
+ content: "inline*",
4860
+ parseHTML() {
4861
+ return [{ tag: "p" }];
4862
+ },
4863
+ renderHTML({ HTMLAttributes }) {
4864
+ return ["p", core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0];
4865
+ },
4866
+ parseMarkdown: (token, helpers) => {
4867
+ const tokens = token.tokens || [];
4868
+ if (tokens.length === 1 && tokens[0].type === "image") {
4869
+ return helpers.parseChildren([tokens[0]]);
4870
+ }
4871
+ return helpers.createNode(
4872
+ "paragraph",
4873
+ void 0,
4874
+ // no attributes for paragraph
4875
+ helpers.parseInline(tokens)
4876
+ );
4877
+ },
4878
+ renderMarkdown: (node, h) => {
4879
+ if (!node || !Array.isArray(node.content)) {
4880
+ return "";
4881
+ }
4882
+ return h.renderChildren(node.content);
4883
+ },
4884
+ addCommands() {
4885
+ return {
4886
+ setParagraph: () => ({ commands }) => {
4887
+ return commands.setNode(this.name);
4888
+ }
4889
+ };
4890
+ },
4891
+ addKeyboardShortcuts() {
4892
+ return {
4893
+ "Mod-Alt-0": () => this.editor.commands.setParagraph()
4894
+ };
4895
+ }
4896
+ });
4897
+ var index_default2 = Paragraph;
4898
+ var Text = core.Node.create({
4899
+ name: "text",
4900
+ group: "inline",
4901
+ parseMarkdown: (token) => {
4902
+ return {
4903
+ type: "text",
4904
+ text: token.text || ""
4905
+ };
4906
+ },
4907
+ renderMarkdown: (node) => node.text || ""
4908
+ });
4909
+ var index_default3 = Text;
4910
+ var SingleLineDocument = index_default.extend({
4911
+ content: "paragraph"
4912
+ });
4913
+ var get_editor_output = (editor) => {
4914
+ if (!editor) {
4915
+ return { plain_text: "", display_text: "", commands: [] };
4916
+ }
4917
+ const plain_text = editor.getText();
4918
+ const commands = [];
4919
+ let display_text = "";
4920
+ let position = 0;
4921
+ editor.state.doc.descendants((node, _pos) => {
4922
+ if (node.type.name === "text") {
4923
+ display_text += node.text || "";
4924
+ position += (node.text || "").length;
4925
+ } else if (node.type.name === "commandNode") {
4926
+ const { id, prefix, action, action_label } = node.attrs;
4927
+ const cmd_plain_text = `${prefix}${action}`;
4928
+ const cmd_display_text = `${prefix}${action_label}`;
4929
+ commands.push({
4930
+ id,
4931
+ prefix,
4932
+ action,
4933
+ action_label,
4934
+ position,
4935
+ length: cmd_plain_text.length
4936
+ });
4937
+ display_text += cmd_display_text;
4938
+ position += cmd_plain_text.length;
4939
+ }
4940
+ });
4941
+ return { plain_text, display_text, commands };
4942
+ };
4943
+ var HazoUiTextbox = ({
4944
+ value,
4945
+ default_value,
4946
+ prefixes,
4947
+ placeholder = "Type here...",
4948
+ disabled = false,
4949
+ className,
4950
+ pill_variant = "default",
4951
+ on_change,
4952
+ on_submit,
4953
+ on_command_insert,
4954
+ on_command_change,
4955
+ on_command_remove
4956
+ }) => {
4957
+ const [suggestion_state, set_suggestion_state] = React27__namespace.useState(null);
4958
+ const [selected_index, set_selected_index] = React27__namespace.useState(0);
4959
+ const [popover_position, set_popover_position] = React27__namespace.useState({ top: 0, left: 0 });
4960
+ const [edit_context, set_edit_context] = React27__namespace.useState(null);
4961
+ const [edit_selected_index, set_edit_selected_index] = React27__namespace.useState(0);
4962
+ const is_controlled = value !== void 0;
4963
+ const editor_container_ref = React27__namespace.useRef(null);
4964
+ const edit_popover_ref = React27__namespace.useRef(null);
4965
+ const [mounted, set_mounted] = React27__namespace.useState(false);
4966
+ React27__namespace.useEffect(() => {
4967
+ set_mounted(true);
4968
+ }, []);
4969
+ const suggestion_extensions = React27__namespace.useMemo(() => {
4970
+ return create_command_suggestion_extension({
4971
+ prefixes,
4972
+ on_suggestion_change: (state) => {
4973
+ set_suggestion_state(state);
4974
+ set_selected_index(0);
4975
+ },
4976
+ on_insert_command: (_command, _prefix, _range) => {
4977
+ }
4978
+ });
4979
+ }, [prefixes]);
4980
+ const editor = react.useEditor({
4981
+ extensions: [
4982
+ SingleLineDocument,
4983
+ index_default2,
4984
+ index_default3,
4985
+ Placeholder__default.default.configure({
4986
+ placeholder
4987
+ }),
4988
+ CommandNodeExtension.configure({}),
4989
+ ...suggestion_extensions
4990
+ ],
4991
+ content: is_controlled ? text_to_tiptap_content(value || "", prefixes, pill_variant) : text_to_tiptap_content(default_value || "", prefixes, pill_variant),
4992
+ editable: !disabled,
4993
+ immediatelyRender: false,
4994
+ editorProps: {
4995
+ attributes: {
4996
+ class: cn(
4997
+ "cls_textbox_editor",
4998
+ "w-full outline-none",
4999
+ "whitespace-nowrap overflow-x-auto"
5000
+ )
5001
+ },
5002
+ handleKeyDown: (_view, event) => {
5003
+ if (event.key === "Enter" && !suggestion_state?.is_active) {
5004
+ event.preventDefault();
5005
+ if (on_submit && editor) {
5006
+ on_submit(get_editor_output(editor));
5007
+ }
5008
+ return true;
5009
+ }
5010
+ return false;
5011
+ }
5012
+ },
5013
+ onUpdate: ({ editor: editor2 }) => {
5014
+ if (on_change) {
5015
+ on_change(get_editor_output(editor2));
5016
+ }
5017
+ }
5018
+ });
5019
+ React27__namespace.useEffect(() => {
5020
+ if (suggestion_state?.is_active && editor) {
5021
+ requestAnimationFrame(() => {
5022
+ const { from } = suggestion_state.range;
5023
+ try {
5024
+ const coords = editor.view.coordsAtPos(from);
5025
+ if (coords) {
5026
+ set_popover_position({
5027
+ top: coords.bottom + 4,
5028
+ left: coords.left
5029
+ });
5030
+ }
5031
+ } catch {
5032
+ const rect = suggestion_state.client_rect?.();
5033
+ if (rect) {
5034
+ set_popover_position({
5035
+ top: rect.bottom + 4,
5036
+ left: rect.left
5037
+ });
5038
+ }
5039
+ }
5040
+ });
5041
+ }
5042
+ }, [suggestion_state, editor]);
5043
+ React27__namespace.useEffect(() => {
5044
+ if (is_controlled && editor && !editor.isFocused) {
5045
+ const current_text = editor.getText();
5046
+ if (value !== current_text) {
5047
+ const content = text_to_tiptap_content(value || "", prefixes, pill_variant);
5048
+ editor.commands.setContent(content, { emitUpdate: false });
5049
+ }
5050
+ }
5051
+ }, [value, editor, is_controlled, prefixes, pill_variant]);
5052
+ React27__namespace.useEffect(() => {
5053
+ if (editor) {
5054
+ editor.setEditable(!disabled);
5055
+ }
5056
+ }, [disabled, editor]);
5057
+ const handle_command_select = React27__namespace.useCallback(
5058
+ (command) => {
5059
+ if (!editor || !suggestion_state) return;
5060
+ insert_command_at_position(
5061
+ editor,
5062
+ command,
5063
+ suggestion_state.prefix,
5064
+ suggestion_state.range,
5065
+ pill_variant
5066
+ );
5067
+ if (on_command_insert) {
5068
+ on_command_insert(command, suggestion_state.prefix);
5069
+ }
5070
+ set_suggestion_state(null);
5071
+ },
5072
+ [editor, suggestion_state, pill_variant, on_command_insert]
5073
+ );
5074
+ const handle_popover_close = React27__namespace.useCallback(() => {
5075
+ set_suggestion_state(null);
5076
+ editor?.commands.focus();
5077
+ }, [editor]);
5078
+ const handle_edit_close = React27__namespace.useCallback(() => {
5079
+ set_edit_context(null);
5080
+ editor?.commands.focus();
5081
+ }, [editor]);
5082
+ const handle_command_update = React27__namespace.useCallback(
5083
+ (new_command) => {
5084
+ if (!editor || !edit_context) return;
5085
+ const old_command = edit_context.command;
5086
+ editor.commands.updateCommand(old_command.id, {
5087
+ action: new_command.action,
5088
+ action_label: new_command.action_label
5089
+ });
5090
+ if (on_command_change) {
5091
+ on_command_change(old_command, new_command);
5092
+ }
5093
+ set_edit_context(null);
5094
+ editor.commands.focus();
5095
+ },
5096
+ [editor, edit_context, on_command_change]
5097
+ );
5098
+ const handle_command_remove = React27__namespace.useCallback(() => {
5099
+ if (!editor || !edit_context) return;
5100
+ const command = edit_context.command;
5101
+ editor.state.doc.descendants((node, pos) => {
5102
+ if (node.type.name === "commandNode" && node.attrs.id === command.id) {
5103
+ editor.chain().focus().deleteRange({ from: pos, to: pos + node.nodeSize }).run();
5104
+ return false;
5105
+ }
5106
+ });
5107
+ if (on_command_remove) {
5108
+ on_command_remove(command);
5109
+ }
5110
+ set_edit_context(null);
5111
+ }, [editor, edit_context, on_command_remove]);
5112
+ const filtered_commands = React27__namespace.useMemo(() => {
5113
+ if (!suggestion_state) return [];
5114
+ const query = suggestion_state.query.toLowerCase();
5115
+ if (!query) return suggestion_state.commands;
5116
+ return suggestion_state.commands.filter(
5117
+ (cmd) => cmd.action_label.toLowerCase().includes(query) || cmd.action.toLowerCase().includes(query) || cmd.action_description?.toLowerCase().includes(query)
5118
+ );
5119
+ }, [suggestion_state]);
5120
+ React27__namespace.useEffect(() => {
5121
+ if (!suggestion_state?.is_active) return;
5122
+ const handle_keydown = (e) => {
5123
+ switch (e.key) {
5124
+ case "ArrowDown":
5125
+ e.preventDefault();
5126
+ set_selected_index(
5127
+ (prev) => Math.min(prev + 1, filtered_commands.length - 1)
5128
+ );
5129
+ break;
5130
+ case "ArrowUp":
5131
+ e.preventDefault();
5132
+ set_selected_index((prev) => Math.max(prev - 1, 0));
5133
+ break;
5134
+ case "Enter":
5135
+ e.preventDefault();
5136
+ if (filtered_commands[selected_index]) {
5137
+ handle_command_select(filtered_commands[selected_index]);
5138
+ }
5139
+ break;
5140
+ case "Escape":
5141
+ e.preventDefault();
5142
+ handle_popover_close();
5143
+ break;
5144
+ }
5145
+ };
5146
+ window.addEventListener("keydown", handle_keydown);
5147
+ return () => window.removeEventListener("keydown", handle_keydown);
5148
+ }, [
5149
+ suggestion_state?.is_active,
5150
+ filtered_commands,
5151
+ selected_index,
5152
+ handle_command_select,
5153
+ handle_popover_close
5154
+ ]);
5155
+ React27__namespace.useEffect(() => {
5156
+ if (!edit_context) return;
5157
+ const handle_click_outside = (e) => {
5158
+ if (edit_popover_ref.current && !edit_popover_ref.current.contains(e.target)) {
5159
+ set_edit_context(null);
5160
+ }
5161
+ };
5162
+ const timeout = setTimeout(() => {
5163
+ document.addEventListener("mousedown", handle_click_outside);
5164
+ }, 100);
5165
+ return () => {
5166
+ clearTimeout(timeout);
5167
+ document.removeEventListener("mousedown", handle_click_outside);
5168
+ };
5169
+ }, [edit_context]);
5170
+ const edit_commands = React27__namespace.useMemo(() => {
5171
+ if (!edit_context) return [];
5172
+ const prefix_config = prefixes.find((p) => p.char === edit_context.command.prefix);
5173
+ return prefix_config?.commands || [];
5174
+ }, [edit_context, prefixes]);
5175
+ React27__namespace.useEffect(() => {
5176
+ if (!edit_context) return;
5177
+ const handle_keydown = (e) => {
5178
+ switch (e.key) {
5179
+ case "ArrowDown":
5180
+ e.preventDefault();
5181
+ set_edit_selected_index(
5182
+ (prev) => Math.min(prev + 1, edit_commands.length)
5183
+ );
5184
+ break;
5185
+ case "ArrowUp":
5186
+ e.preventDefault();
5187
+ set_edit_selected_index((prev) => Math.max(prev - 1, 0));
5188
+ break;
5189
+ case "Enter":
5190
+ e.preventDefault();
5191
+ if (edit_selected_index === edit_commands.length) {
5192
+ handle_command_remove();
5193
+ } else if (edit_commands[edit_selected_index]) {
5194
+ handle_command_update(edit_commands[edit_selected_index]);
5195
+ }
5196
+ break;
5197
+ case "Escape":
5198
+ e.preventDefault();
5199
+ handle_edit_close();
5200
+ break;
5201
+ }
5202
+ };
5203
+ window.addEventListener("keydown", handle_keydown);
5204
+ return () => window.removeEventListener("keydown", handle_keydown);
5205
+ }, [
5206
+ edit_context,
5207
+ edit_commands,
5208
+ edit_selected_index,
5209
+ handle_command_update,
5210
+ handle_command_remove,
5211
+ handle_edit_close
5212
+ ]);
5213
+ React27__namespace.useEffect(() => {
5214
+ const handle_pill_click = (e) => {
5215
+ const detail = e.detail;
5216
+ const { id, prefix, action, action_label, node_pos } = detail;
5217
+ if (editor) {
5218
+ try {
5219
+ const coords = editor.view.coordsAtPos(node_pos);
5220
+ if (coords) {
5221
+ const prefix_config = prefixes.find((p) => p.char === prefix);
5222
+ const current_index = prefix_config?.commands.findIndex(
5223
+ (cmd) => cmd.action === action
5224
+ ) ?? 0;
5225
+ set_edit_context({
5226
+ command: {
5227
+ id,
5228
+ prefix,
5229
+ action,
5230
+ action_label,
5231
+ position: node_pos,
5232
+ length: 0
5233
+ },
5234
+ node_pos,
5235
+ rect: new DOMRect(
5236
+ coords.left,
5237
+ coords.bottom + 4,
5238
+ 0,
5239
+ 0
5240
+ )
5241
+ });
5242
+ set_edit_selected_index(Math.max(0, current_index));
5243
+ }
5244
+ } catch {
5245
+ }
5246
+ }
5247
+ };
5248
+ document.addEventListener("command-pill-click", handle_pill_click);
5249
+ return () => document.removeEventListener("command-pill-click", handle_pill_click);
5250
+ }, [editor, prefixes]);
5251
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5252
+ "div",
5253
+ {
5254
+ ref: editor_container_ref,
5255
+ className: cn(
5256
+ "cls_hazo_ui_textbox",
5257
+ "relative flex h-10 w-full rounded-md border border-input bg-background px-3 py-2",
5258
+ "text-sm ring-offset-background",
5259
+ "focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
5260
+ disabled && "cursor-not-allowed opacity-50",
5261
+ className
5262
+ ),
5263
+ children: [
5264
+ /* @__PURE__ */ jsxRuntime.jsx(
5265
+ react.EditorContent,
5266
+ {
5267
+ editor,
5268
+ className: cn(
5269
+ "cls_textbox_content",
5270
+ "flex-1 min-w-0",
5271
+ "[&_.ProseMirror]:outline-none",
5272
+ "[&_.ProseMirror_p]:m-0",
5273
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]",
5274
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:text-muted-foreground",
5275
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:pointer-events-none",
5276
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:float-left",
5277
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:h-0"
5278
+ )
5279
+ }
5280
+ ),
5281
+ suggestion_state?.is_active && /* @__PURE__ */ jsxRuntime.jsx(
5282
+ CommandPopover,
5283
+ {
5284
+ is_open: true,
5285
+ commands: filtered_commands,
5286
+ prefix: suggestion_state.prefix,
5287
+ query: suggestion_state.query,
5288
+ selected_index,
5289
+ position: popover_position,
5290
+ on_query_change: () => {
5291
+ },
5292
+ on_select: handle_command_select,
5293
+ on_close: handle_popover_close,
5294
+ on_selection_change: set_selected_index
5295
+ }
5296
+ ),
5297
+ edit_context && mounted && reactDom.createPortal(
5298
+ /* @__PURE__ */ jsxRuntime.jsx(
5299
+ "div",
5300
+ {
5301
+ ref: edit_popover_ref,
5302
+ className: cn(
5303
+ "cls_edit_popover",
5304
+ "fixed z-[9999]",
5305
+ "w-64 min-w-[200px] max-w-[300px]",
5306
+ "rounded-md border bg-popover text-popover-foreground shadow-lg",
5307
+ "animate-in fade-in-0 zoom-in-95"
5308
+ ),
5309
+ style: {
5310
+ top: edit_context.rect.y,
5311
+ left: edit_context.rect.x
5312
+ },
5313
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-1", children: [
5314
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3 py-2 text-xs text-muted-foreground border-b", children: "Change command" }),
5315
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-h-[200px] overflow-y-auto", children: [
5316
+ edit_commands.map((cmd, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
5317
+ "div",
5318
+ {
5319
+ className: cn(
5320
+ "px-3 py-2 cursor-pointer flex items-center gap-2",
5321
+ "hover:bg-accent",
5322
+ idx === edit_selected_index && "bg-accent",
5323
+ cmd.action === edit_context.command.action && "font-medium"
5324
+ ),
5325
+ onClick: () => handle_command_update(cmd),
5326
+ children: [
5327
+ cmd.icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-shrink-0 text-muted-foreground", children: cmd.icon }),
5328
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
5329
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "truncate", children: [
5330
+ edit_context.command.prefix,
5331
+ cmd.action_label
5332
+ ] }),
5333
+ cmd.action_description && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-muted-foreground truncate", children: cmd.action_description })
5334
+ ] }),
5335
+ cmd.action === edit_context.command.action && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: "current" })
5336
+ ]
5337
+ },
5338
+ cmd.action
5339
+ )),
5340
+ /* @__PURE__ */ jsxRuntime.jsx(
5341
+ "div",
5342
+ {
5343
+ className: cn(
5344
+ "px-3 py-2 cursor-pointer flex items-center gap-2 text-destructive border-t",
5345
+ "hover:bg-destructive/10",
5346
+ edit_selected_index === edit_commands.length && "bg-destructive/10"
5347
+ ),
5348
+ onClick: handle_command_remove,
5349
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Remove" })
5350
+ }
5351
+ )
5352
+ ] })
5353
+ ] })
5354
+ }
5355
+ ),
5356
+ document.body
5357
+ )
5358
+ ]
5359
+ }
5360
+ );
5361
+ };
5362
+ HazoUiTextbox.displayName = "HazoUiTextbox";
5363
+ var HardBreak = core.Node.create({
5364
+ name: "hardBreak",
5365
+ markdownTokenName: "br",
5366
+ addOptions() {
5367
+ return {
5368
+ keepMarks: true,
5369
+ HTMLAttributes: {}
5370
+ };
5371
+ },
5372
+ inline: true,
5373
+ group: "inline",
5374
+ selectable: false,
5375
+ linebreakReplacement: true,
5376
+ parseHTML() {
5377
+ return [{ tag: "br" }];
5378
+ },
5379
+ renderHTML({ HTMLAttributes }) {
5380
+ return ["br", core.mergeAttributes(this.options.HTMLAttributes, HTMLAttributes)];
5381
+ },
5382
+ renderText() {
5383
+ return "\n";
5384
+ },
5385
+ renderMarkdown: () => `
5386
+ `,
5387
+ parseMarkdown: () => {
5388
+ return {
5389
+ type: "hardBreak"
5390
+ };
5391
+ },
5392
+ addCommands() {
5393
+ return {
5394
+ setHardBreak: () => ({ commands, chain, state, editor }) => {
5395
+ return commands.first([
5396
+ () => commands.exitCode(),
5397
+ () => commands.command(() => {
5398
+ const { selection, storedMarks } = state;
5399
+ if (selection.$from.parent.type.spec.isolating) {
5400
+ return false;
5401
+ }
5402
+ const { keepMarks } = this.options;
5403
+ const { splittableMarks } = editor.extensionManager;
5404
+ const marks = storedMarks || selection.$to.parentOffset && selection.$from.marks();
5405
+ return chain().insertContent({ type: this.name }).command(({ tr, dispatch }) => {
5406
+ if (dispatch && marks && keepMarks) {
5407
+ const filteredMarks = marks.filter((mark) => splittableMarks.includes(mark.type.name));
5408
+ tr.ensureMarks(filteredMarks);
5409
+ }
5410
+ return true;
5411
+ }).run();
5412
+ })
5413
+ ]);
5414
+ }
5415
+ };
5416
+ },
5417
+ addKeyboardShortcuts() {
5418
+ return {
5419
+ "Mod-Enter": () => this.editor.commands.setHardBreak(),
5420
+ "Shift-Enter": () => this.editor.commands.setHardBreak()
5421
+ };
5422
+ }
5423
+ });
5424
+ var index_default4 = HardBreak;
5425
+ var get_editor_output2 = (editor) => {
5426
+ if (!editor) {
5427
+ return { plain_text: "", display_text: "", commands: [] };
5428
+ }
5429
+ const plain_text = editor.getText();
5430
+ const commands = [];
5431
+ let display_text = "";
5432
+ let position = 0;
5433
+ editor.state.doc.descendants((node, _pos) => {
5434
+ if (node.type.name === "text") {
5435
+ display_text += node.text || "";
5436
+ position += (node.text || "").length;
5437
+ } else if (node.type.name === "commandNode") {
5438
+ const { id, prefix, action, action_label } = node.attrs;
5439
+ const cmd_plain_text = `${prefix}${action}`;
5440
+ const cmd_display_text = `${prefix}${action_label}`;
5441
+ commands.push({
5442
+ id,
5443
+ prefix,
5444
+ action,
5445
+ action_label,
5446
+ position,
5447
+ length: cmd_plain_text.length
5448
+ });
5449
+ display_text += cmd_display_text;
5450
+ position += cmd_plain_text.length;
5451
+ } else if (node.type.name === "hardBreak") {
5452
+ display_text += "\n";
5453
+ position += 1;
5454
+ }
5455
+ });
5456
+ return { plain_text, display_text, commands };
5457
+ };
5458
+ var multiline_text_to_tiptap_content = (text, prefixes, variant = "default") => {
5459
+ const lines = text.split("\n");
5460
+ const paragraphs = [];
5461
+ for (const line of lines) {
5462
+ const line_content = text_to_tiptap_content(line, prefixes, variant);
5463
+ const para = line_content.content?.[0];
5464
+ if (para) {
5465
+ paragraphs.push(para);
5466
+ } else {
5467
+ paragraphs.push({ type: "paragraph", content: [] });
5468
+ }
5469
+ }
5470
+ return {
5471
+ type: "doc",
5472
+ content: paragraphs.length > 0 ? paragraphs : [{ type: "paragraph", content: [] }]
5473
+ };
5474
+ };
5475
+ var HazoUiTextarea = ({
5476
+ value,
5477
+ default_value,
5478
+ prefixes,
5479
+ placeholder = "Type here...",
5480
+ disabled = false,
5481
+ className,
5482
+ pill_variant = "default",
5483
+ min_height = "80px",
5484
+ max_height = "200px",
5485
+ rows,
5486
+ on_change,
5487
+ on_submit,
5488
+ on_command_insert,
5489
+ on_command_change,
5490
+ on_command_remove
5491
+ }) => {
5492
+ const [suggestion_state, set_suggestion_state] = React27__namespace.useState(null);
5493
+ const [selected_index, set_selected_index] = React27__namespace.useState(0);
5494
+ const [popover_position, set_popover_position] = React27__namespace.useState({ top: 0, left: 0 });
5495
+ const [edit_context, set_edit_context] = React27__namespace.useState(null);
5496
+ const [edit_selected_index, set_edit_selected_index] = React27__namespace.useState(0);
5497
+ const is_controlled = value !== void 0;
5498
+ const editor_container_ref = React27__namespace.useRef(null);
5499
+ const edit_popover_ref = React27__namespace.useRef(null);
5500
+ const [mounted, set_mounted] = React27__namespace.useState(false);
5501
+ React27__namespace.useEffect(() => {
5502
+ set_mounted(true);
5503
+ }, []);
5504
+ const calculated_min_height = rows ? `${rows * 1.5}em` : min_height;
5505
+ const suggestion_extensions = React27__namespace.useMemo(() => {
5506
+ return create_command_suggestion_extension({
5507
+ prefixes,
5508
+ on_suggestion_change: (state) => {
5509
+ set_suggestion_state(state);
5510
+ set_selected_index(0);
5511
+ },
5512
+ on_insert_command: (_command, _prefix, _range) => {
5513
+ }
5514
+ });
5515
+ }, [prefixes]);
5516
+ const editor = react.useEditor({
5517
+ extensions: [
5518
+ index_default,
5519
+ index_default2,
5520
+ index_default3,
5521
+ index_default4,
5522
+ Placeholder__default.default.configure({
5523
+ placeholder
5524
+ }),
5525
+ CommandNodeExtension.configure({}),
5526
+ ...suggestion_extensions
5527
+ ],
5528
+ content: is_controlled ? multiline_text_to_tiptap_content(value || "", prefixes, pill_variant) : multiline_text_to_tiptap_content(default_value || "", prefixes, pill_variant),
5529
+ editable: !disabled,
5530
+ immediatelyRender: false,
5531
+ editorProps: {
5532
+ attributes: {
5533
+ class: cn("cls_textarea_editor", "w-full outline-none"),
5534
+ style: `min-height: ${calculated_min_height}; max-height: ${max_height}`
5535
+ },
5536
+ handleKeyDown: (_view, event) => {
5537
+ if (event.key === "Enter" && (event.metaKey || event.ctrlKey) && !suggestion_state?.is_active) {
5538
+ event.preventDefault();
5539
+ if (on_submit && editor) {
5540
+ on_submit(get_editor_output2(editor));
5541
+ }
5542
+ return true;
5543
+ }
5544
+ return false;
5545
+ }
5546
+ },
5547
+ onUpdate: ({ editor: editor2 }) => {
5548
+ if (on_change) {
5549
+ on_change(get_editor_output2(editor2));
5550
+ }
5551
+ }
5552
+ });
5553
+ React27__namespace.useEffect(() => {
5554
+ if (suggestion_state?.is_active && editor) {
5555
+ requestAnimationFrame(() => {
5556
+ const { from } = suggestion_state.range;
5557
+ try {
5558
+ const coords = editor.view.coordsAtPos(from);
5559
+ if (coords) {
5560
+ set_popover_position({
5561
+ top: coords.bottom + 4,
5562
+ left: coords.left
5563
+ });
5564
+ }
5565
+ } catch {
5566
+ const rect = suggestion_state.client_rect?.();
5567
+ if (rect) {
5568
+ set_popover_position({
5569
+ top: rect.bottom + 4,
5570
+ left: rect.left
5571
+ });
5572
+ }
5573
+ }
5574
+ });
5575
+ }
5576
+ }, [suggestion_state, editor]);
5577
+ React27__namespace.useEffect(() => {
5578
+ if (is_controlled && editor && !editor.isFocused) {
5579
+ const current_text = editor.getText();
5580
+ if (value !== current_text) {
5581
+ const content = multiline_text_to_tiptap_content(
5582
+ value || "",
5583
+ prefixes,
5584
+ pill_variant
5585
+ );
5586
+ editor.commands.setContent(content, { emitUpdate: false });
5587
+ }
5588
+ }
5589
+ }, [value, editor, is_controlled, prefixes, pill_variant]);
5590
+ React27__namespace.useEffect(() => {
5591
+ if (editor) {
5592
+ editor.setEditable(!disabled);
5593
+ }
5594
+ }, [disabled, editor]);
5595
+ const handle_command_select = React27__namespace.useCallback(
5596
+ (command) => {
5597
+ if (!editor || !suggestion_state) return;
5598
+ insert_command_at_position(
5599
+ editor,
5600
+ command,
5601
+ suggestion_state.prefix,
5602
+ suggestion_state.range,
5603
+ pill_variant
5604
+ );
5605
+ if (on_command_insert) {
5606
+ on_command_insert(command, suggestion_state.prefix);
5607
+ }
5608
+ set_suggestion_state(null);
5609
+ },
5610
+ [editor, suggestion_state, pill_variant, on_command_insert]
5611
+ );
5612
+ const handle_popover_close = React27__namespace.useCallback(() => {
5613
+ set_suggestion_state(null);
5614
+ editor?.commands.focus();
5615
+ }, [editor]);
5616
+ const handle_edit_close = React27__namespace.useCallback(() => {
5617
+ set_edit_context(null);
5618
+ editor?.commands.focus();
5619
+ }, [editor]);
5620
+ const handle_command_update = React27__namespace.useCallback(
5621
+ (new_command) => {
5622
+ if (!editor || !edit_context) return;
5623
+ const old_command = edit_context.command;
5624
+ editor.commands.updateCommand(old_command.id, {
5625
+ action: new_command.action,
5626
+ action_label: new_command.action_label
5627
+ });
5628
+ if (on_command_change) {
5629
+ on_command_change(old_command, new_command);
5630
+ }
5631
+ set_edit_context(null);
5632
+ editor.commands.focus();
5633
+ },
5634
+ [editor, edit_context, on_command_change]
5635
+ );
5636
+ const handle_command_remove = React27__namespace.useCallback(() => {
5637
+ if (!editor || !edit_context) return;
5638
+ const command = edit_context.command;
5639
+ editor.state.doc.descendants((node, pos) => {
5640
+ if (node.type.name === "commandNode" && node.attrs.id === command.id) {
5641
+ editor.chain().focus().deleteRange({ from: pos, to: pos + node.nodeSize }).run();
5642
+ return false;
5643
+ }
5644
+ });
5645
+ if (on_command_remove) {
5646
+ on_command_remove(command);
5647
+ }
5648
+ set_edit_context(null);
5649
+ }, [editor, edit_context, on_command_remove]);
5650
+ const filtered_commands = React27__namespace.useMemo(() => {
5651
+ if (!suggestion_state) return [];
5652
+ const query = suggestion_state.query.toLowerCase();
5653
+ if (!query) return suggestion_state.commands;
5654
+ return suggestion_state.commands.filter(
5655
+ (cmd) => cmd.action_label.toLowerCase().includes(query) || cmd.action.toLowerCase().includes(query) || cmd.action_description?.toLowerCase().includes(query)
5656
+ );
5657
+ }, [suggestion_state]);
5658
+ React27__namespace.useEffect(() => {
5659
+ if (!suggestion_state?.is_active) return;
5660
+ const handle_keydown = (e) => {
5661
+ switch (e.key) {
5662
+ case "ArrowDown":
5663
+ e.preventDefault();
5664
+ set_selected_index(
5665
+ (prev) => Math.min(prev + 1, filtered_commands.length - 1)
5666
+ );
5667
+ break;
5668
+ case "ArrowUp":
5669
+ e.preventDefault();
5670
+ set_selected_index((prev) => Math.max(prev - 1, 0));
5671
+ break;
5672
+ case "Enter":
5673
+ e.preventDefault();
5674
+ if (filtered_commands[selected_index]) {
5675
+ handle_command_select(filtered_commands[selected_index]);
5676
+ }
5677
+ break;
5678
+ case "Escape":
5679
+ e.preventDefault();
5680
+ handle_popover_close();
5681
+ break;
5682
+ }
5683
+ };
5684
+ window.addEventListener("keydown", handle_keydown);
5685
+ return () => window.removeEventListener("keydown", handle_keydown);
5686
+ }, [
5687
+ suggestion_state?.is_active,
5688
+ filtered_commands,
5689
+ selected_index,
5690
+ handle_command_select,
5691
+ handle_popover_close
5692
+ ]);
5693
+ React27__namespace.useEffect(() => {
5694
+ if (!edit_context) return;
5695
+ const handle_click_outside = (e) => {
5696
+ if (edit_popover_ref.current && !edit_popover_ref.current.contains(e.target)) {
5697
+ set_edit_context(null);
5698
+ }
5699
+ };
5700
+ const timeout = setTimeout(() => {
5701
+ document.addEventListener("mousedown", handle_click_outside);
5702
+ }, 100);
5703
+ return () => {
5704
+ clearTimeout(timeout);
5705
+ document.removeEventListener("mousedown", handle_click_outside);
5706
+ };
5707
+ }, [edit_context]);
5708
+ const edit_commands = React27__namespace.useMemo(() => {
5709
+ if (!edit_context) return [];
5710
+ const prefix_config = prefixes.find((p) => p.char === edit_context.command.prefix);
5711
+ return prefix_config?.commands || [];
5712
+ }, [edit_context, prefixes]);
5713
+ React27__namespace.useEffect(() => {
5714
+ if (!edit_context) return;
5715
+ const handle_keydown = (e) => {
5716
+ switch (e.key) {
5717
+ case "ArrowDown":
5718
+ e.preventDefault();
5719
+ set_edit_selected_index(
5720
+ (prev) => Math.min(prev + 1, edit_commands.length)
5721
+ );
5722
+ break;
5723
+ case "ArrowUp":
5724
+ e.preventDefault();
5725
+ set_edit_selected_index((prev) => Math.max(prev - 1, 0));
5726
+ break;
5727
+ case "Enter":
5728
+ e.preventDefault();
5729
+ if (edit_selected_index === edit_commands.length) {
5730
+ handle_command_remove();
5731
+ } else if (edit_commands[edit_selected_index]) {
5732
+ handle_command_update(edit_commands[edit_selected_index]);
5733
+ }
5734
+ break;
5735
+ case "Escape":
5736
+ e.preventDefault();
5737
+ handle_edit_close();
5738
+ break;
5739
+ }
5740
+ };
5741
+ window.addEventListener("keydown", handle_keydown);
5742
+ return () => window.removeEventListener("keydown", handle_keydown);
5743
+ }, [
5744
+ edit_context,
5745
+ edit_commands,
5746
+ edit_selected_index,
5747
+ handle_command_update,
5748
+ handle_command_remove,
5749
+ handle_edit_close
5750
+ ]);
5751
+ React27__namespace.useEffect(() => {
5752
+ const handle_pill_click = (e) => {
5753
+ const detail = e.detail;
5754
+ const { id, prefix, action, action_label, node_pos } = detail;
5755
+ if (editor) {
5756
+ try {
5757
+ const coords = editor.view.coordsAtPos(node_pos);
5758
+ if (coords) {
5759
+ const prefix_config = prefixes.find((p) => p.char === prefix);
5760
+ const current_index = prefix_config?.commands.findIndex(
5761
+ (cmd) => cmd.action === action
5762
+ ) ?? 0;
5763
+ set_edit_context({
5764
+ command: {
5765
+ id,
5766
+ prefix,
5767
+ action,
5768
+ action_label,
5769
+ position: node_pos,
5770
+ length: 0
5771
+ },
5772
+ node_pos,
5773
+ rect: new DOMRect(
5774
+ coords.left,
5775
+ coords.bottom + 4,
5776
+ 0,
5777
+ 0
5778
+ )
5779
+ });
5780
+ set_edit_selected_index(Math.max(0, current_index));
5781
+ }
5782
+ } catch {
5783
+ }
5784
+ }
5785
+ };
5786
+ document.addEventListener("command-pill-click", handle_pill_click);
5787
+ return () => document.removeEventListener("command-pill-click", handle_pill_click);
5788
+ }, [editor, prefixes]);
5789
+ return /* @__PURE__ */ jsxRuntime.jsxs(
5790
+ "div",
5791
+ {
5792
+ ref: editor_container_ref,
5793
+ className: cn(
5794
+ "cls_hazo_ui_textarea",
5795
+ "relative flex w-full rounded-md border border-input bg-background px-3 py-2",
5796
+ "text-sm ring-offset-background",
5797
+ "focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2",
5798
+ disabled && "cursor-not-allowed opacity-50",
5799
+ className
5800
+ ),
5801
+ style: {
5802
+ minHeight: calculated_min_height,
5803
+ maxHeight: max_height
5804
+ },
5805
+ children: [
5806
+ /* @__PURE__ */ jsxRuntime.jsx(
5807
+ react.EditorContent,
5808
+ {
5809
+ editor,
5810
+ className: cn(
5811
+ "cls_textarea_content",
5812
+ "flex-1 min-w-0 overflow-y-auto",
5813
+ "[&_.ProseMirror]:outline-none",
5814
+ "[&_.ProseMirror_p]:m-0 [&_.ProseMirror_p]:mb-1",
5815
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:content-[attr(data-placeholder)]",
5816
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:text-muted-foreground",
5817
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:pointer-events-none",
5818
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:float-left",
5819
+ "[&_.ProseMirror_.is-editor-empty:first-child::before]:h-0"
5820
+ )
5821
+ }
5822
+ ),
5823
+ suggestion_state?.is_active && /* @__PURE__ */ jsxRuntime.jsx(
5824
+ CommandPopover,
5825
+ {
5826
+ is_open: true,
5827
+ commands: filtered_commands,
5828
+ prefix: suggestion_state.prefix,
5829
+ query: suggestion_state.query,
5830
+ selected_index,
5831
+ position: popover_position,
5832
+ on_query_change: () => {
5833
+ },
5834
+ on_select: handle_command_select,
5835
+ on_close: handle_popover_close,
5836
+ on_selection_change: set_selected_index
5837
+ }
5838
+ ),
5839
+ edit_context && mounted && reactDom.createPortal(
5840
+ /* @__PURE__ */ jsxRuntime.jsx(
5841
+ "div",
5842
+ {
5843
+ ref: edit_popover_ref,
5844
+ className: cn(
5845
+ "cls_edit_popover",
5846
+ "fixed z-[9999]",
5847
+ "w-64 min-w-[200px] max-w-[300px]",
5848
+ "rounded-md border bg-popover text-popover-foreground shadow-lg",
5849
+ "animate-in fade-in-0 zoom-in-95"
5850
+ ),
5851
+ style: {
5852
+ top: edit_context.rect.y,
5853
+ left: edit_context.rect.x
5854
+ },
5855
+ children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "py-1", children: [
5856
+ /* @__PURE__ */ jsxRuntime.jsx("div", { className: "px-3 py-2 text-xs text-muted-foreground border-b", children: "Change command" }),
5857
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "max-h-[200px] overflow-y-auto", children: [
5858
+ edit_commands.map((cmd, idx) => /* @__PURE__ */ jsxRuntime.jsxs(
5859
+ "div",
5860
+ {
5861
+ className: cn(
5862
+ "px-3 py-2 cursor-pointer flex items-center gap-2",
5863
+ "hover:bg-accent",
5864
+ idx === edit_selected_index && "bg-accent",
5865
+ cmd.action === edit_context.command.action && "font-medium"
5866
+ ),
5867
+ onClick: () => handle_command_update(cmd),
5868
+ children: [
5869
+ cmd.icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-shrink-0 text-muted-foreground", children: cmd.icon }),
5870
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
5871
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "truncate", children: [
5872
+ edit_context.command.prefix,
5873
+ cmd.action_label
5874
+ ] }),
5875
+ cmd.action_description && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "text-xs text-muted-foreground truncate", children: cmd.action_description })
5876
+ ] }),
5877
+ cmd.action === edit_context.command.action && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-xs text-muted-foreground", children: "current" })
5878
+ ]
5879
+ },
5880
+ cmd.action
5881
+ )),
5882
+ /* @__PURE__ */ jsxRuntime.jsx(
5883
+ "div",
5884
+ {
5885
+ className: cn(
5886
+ "px-3 py-2 cursor-pointer flex items-center gap-2 text-destructive border-t",
5887
+ "hover:bg-destructive/10",
5888
+ edit_selected_index === edit_commands.length && "bg-destructive/10"
5889
+ ),
5890
+ onClick: handle_command_remove,
5891
+ children: /* @__PURE__ */ jsxRuntime.jsx("span", { children: "Remove" })
5892
+ }
5893
+ )
5894
+ ] })
5895
+ ] })
5896
+ }
5897
+ ),
5898
+ document.body
5899
+ )
5900
+ ]
5901
+ }
5902
+ );
5903
+ };
5904
+ HazoUiTextarea.displayName = "HazoUiTextarea";
4307
5905
 
5906
+ exports.CommandNodeExtension = CommandNodeExtension;
5907
+ exports.CommandPill = CommandPill;
5908
+ exports.CommandPopover = CommandPopover;
4308
5909
  exports.HazoUiFlexInput = HazoUiFlexInput;
4309
5910
  exports.HazoUiFlexRadio = HazoUiFlexRadio;
4310
5911
  exports.HazoUiMultiFilterDialog = HazoUiMultiFilterDialog;
4311
5912
  exports.HazoUiMultiSortDialog = HazoUiMultiSortDialog;
4312
5913
  exports.HazoUiRte = HazoUiRte;
5914
+ exports.HazoUiTextarea = HazoUiTextarea;
5915
+ exports.HazoUiTextbox = HazoUiTextbox;
5916
+ exports.create_command_suggestion_extension = create_command_suggestion_extension;
5917
+ exports.parse_commands_from_text = parse_commands_from_text;
5918
+ exports.text_to_tiptap_content = text_to_tiptap_content;
4313
5919
  //# sourceMappingURL=index.cjs.map
4314
5920
  //# sourceMappingURL=index.cjs.map