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