hazo_ui 2.4.4 → 2.5.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 CHANGED
@@ -361,7 +361,7 @@ var CommandGroup = React27__namespace.forwardRef(({ className, heading, children
361
361
  }
362
362
  ));
363
363
  CommandGroup.displayName = "CommandGroup";
364
- var CommandItem = React27__namespace.forwardRef(({ className, onSelect, value, style, ...props }, ref) => {
364
+ var CommandItem = React27__namespace.forwardRef(({ className, onSelect, value, selected, style, ...props }, ref) => {
365
365
  const handleClick = () => {
366
366
  if (onSelect && value) {
367
367
  onSelect(value);
@@ -374,13 +374,16 @@ var CommandItem = React27__namespace.forwardRef(({ className, onSelect, value, s
374
374
  className: cn(
375
375
  "cls_command_item",
376
376
  "relative flex cursor-pointer select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none hover:bg-accent hover:text-accent-foreground aria-selected:bg-accent aria-selected:text-accent-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50",
377
+ // When selected, apply accent background and ensure all text is visible
378
+ selected && "bg-accent text-accent-foreground [&_.text-muted-foreground]:text-accent-foreground/70",
377
379
  className
378
380
  ),
379
- style: {
380
- // Ensure items have opaque background (inherit from popover container)
381
- backgroundColor: "inherit",
381
+ style: selected ? {
382
+ // Explicit inline styles as fallback for consumers with non-HSL CSS variables
383
+ backgroundColor: "var(--accent, #f1f5f9)",
384
+ color: "var(--accent-foreground, #0f172a)",
382
385
  ...style
383
- },
386
+ } : style,
384
387
  onClick: handleClick,
385
388
  ...props
386
389
  }
@@ -4335,8 +4338,21 @@ var get_variant_classes = (variant = "default") => {
4335
4338
  return "bg-primary/10 text-primary border-primary/20";
4336
4339
  }
4337
4340
  };
4341
+ var get_custom_color_styles = (color_bg, color_fg, color_border) => {
4342
+ if (!color_bg && !color_fg && !color_border) {
4343
+ return {};
4344
+ }
4345
+ return {
4346
+ ...color_bg && { backgroundColor: color_bg },
4347
+ ...color_fg && { color: color_fg },
4348
+ ...color_border && { borderColor: color_border }
4349
+ };
4350
+ };
4351
+ var has_custom_colors = (color_bg, color_fg, color_border) => {
4352
+ return Boolean(color_bg || color_fg || color_border);
4353
+ };
4338
4354
  var CommandPillView = ({ node, selected, editor }) => {
4339
- const { prefix, action, action_label, id, variant } = node.attrs;
4355
+ const { prefix, action, action_label, id, variant, color_bg, color_fg, color_border } = node.attrs;
4340
4356
  const handle_click = () => {
4341
4357
  const event = new CustomEvent("command-pill-click", {
4342
4358
  detail: {
@@ -4350,6 +4366,8 @@ var CommandPillView = ({ node, selected, editor }) => {
4350
4366
  });
4351
4367
  document.dispatchEvent(event);
4352
4368
  };
4369
+ const use_custom_colors = has_custom_colors(color_bg, color_fg, color_border);
4370
+ const custom_styles = get_custom_color_styles(color_bg, color_fg, color_border);
4353
4371
  return /* @__PURE__ */ jsxRuntime.jsx(react.NodeViewWrapper, { as: "span", className: "inline", children: /* @__PURE__ */ jsxRuntime.jsxs(
4354
4372
  "span",
4355
4373
  {
@@ -4362,17 +4380,19 @@ var CommandPillView = ({ node, selected, editor }) => {
4362
4380
  "border",
4363
4381
  "cursor-pointer select-none",
4364
4382
  "transition-all duration-150",
4365
- get_variant_classes(variant),
4383
+ // Only apply variant classes if no custom colors
4384
+ !use_custom_colors && get_variant_classes(variant),
4366
4385
  selected && "ring-2 ring-ring ring-offset-1",
4367
4386
  "hover:opacity-80"
4368
4387
  ),
4388
+ style: custom_styles,
4369
4389
  contentEditable: false,
4370
4390
  "data-command-id": id,
4371
4391
  "data-command-prefix": prefix,
4372
4392
  "data-command-action": action,
4373
4393
  onClick: handle_click,
4374
4394
  children: [
4375
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground opacity-70", children: prefix }),
4395
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn(!use_custom_colors && "text-muted-foreground opacity-70"), style: use_custom_colors ? { opacity: 0.7 } : void 0, children: prefix }),
4376
4396
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: action_label })
4377
4397
  ]
4378
4398
  }
@@ -4424,6 +4444,27 @@ var CommandNodeExtension = core.Node.create({
4424
4444
  renderHTML: (attributes) => ({
4425
4445
  "data-command-variant": attributes.variant
4426
4446
  })
4447
+ },
4448
+ color_bg: {
4449
+ default: null,
4450
+ parseHTML: (element) => element.getAttribute("data-command-color-bg"),
4451
+ renderHTML: (attributes) => ({
4452
+ "data-command-color-bg": attributes.color_bg
4453
+ })
4454
+ },
4455
+ color_fg: {
4456
+ default: null,
4457
+ parseHTML: (element) => element.getAttribute("data-command-color-fg"),
4458
+ renderHTML: (attributes) => ({
4459
+ "data-command-color-fg": attributes.color_fg
4460
+ })
4461
+ },
4462
+ color_border: {
4463
+ default: null,
4464
+ parseHTML: (element) => element.getAttribute("data-command-color-border"),
4465
+ renderHTML: (attributes) => ({
4466
+ "data-command-color-border": attributes.color_border
4467
+ })
4427
4468
  }
4428
4469
  };
4429
4470
  },
@@ -4454,11 +4495,15 @@ var CommandNodeExtension = core.Node.create({
4454
4495
  addCommands() {
4455
4496
  return {
4456
4497
  insertCommand: (attrs) => ({ commands }) => {
4498
+ const { color: color2, ...rest_attrs } = attrs;
4457
4499
  return commands.insertContent({
4458
4500
  type: this.name,
4459
4501
  attrs: {
4460
- ...attrs,
4461
- id: generate_command_id()
4502
+ ...rest_attrs,
4503
+ id: generate_command_id(),
4504
+ ...color2?.bg && { color_bg: color2.bg },
4505
+ ...color2?.fg && { color_fg: color2.fg },
4506
+ ...color2?.border && { color_border: color2.border }
4462
4507
  }
4463
4508
  });
4464
4509
  },
@@ -4583,12 +4628,13 @@ var create_command_suggestion_extension = (config) => {
4583
4628
  });
4584
4629
  });
4585
4630
  };
4586
- var insert_command_at_position = (editor, command, prefix, range, variant = "default") => {
4631
+ var insert_command_at_position = (editor, command, prefix, range, variant = "default", color2) => {
4587
4632
  editor.chain().focus().deleteRange(range).insertCommand({
4588
4633
  prefix,
4589
4634
  action: command.action,
4590
4635
  action_label: command.action_label,
4591
- variant
4636
+ variant,
4637
+ color: color2
4592
4638
  }).run();
4593
4639
  };
4594
4640
  var get_variant_classes2 = (variant = "default") => {
@@ -4602,6 +4648,16 @@ var get_variant_classes2 = (variant = "default") => {
4602
4648
  return "bg-primary/10 text-primary border-primary/20 hover:bg-primary/15";
4603
4649
  }
4604
4650
  };
4651
+ var get_custom_color_styles2 = (color2) => {
4652
+ if (!color2) {
4653
+ return {};
4654
+ }
4655
+ return {
4656
+ ...color2.bg && { backgroundColor: color2.bg },
4657
+ ...color2.fg && { color: color2.fg },
4658
+ ...color2.border && { borderColor: color2.border }
4659
+ };
4660
+ };
4605
4661
  var CommandPill = ({
4606
4662
  prefix,
4607
4663
  action,
@@ -4609,8 +4665,11 @@ var CommandPill = ({
4609
4665
  id,
4610
4666
  selected = false,
4611
4667
  variant = "default",
4668
+ color: color2,
4612
4669
  on_click
4613
4670
  }) => {
4671
+ const use_custom_colors = Boolean(color2?.bg || color2?.fg || color2?.border);
4672
+ const custom_styles = get_custom_color_styles2(color2);
4614
4673
  return /* @__PURE__ */ jsxRuntime.jsxs(
4615
4674
  "span",
4616
4675
  {
@@ -4622,10 +4681,12 @@ var CommandPill = ({
4622
4681
  "text-sm font-medium",
4623
4682
  "border",
4624
4683
  "transition-all duration-150",
4625
- get_variant_classes2(variant),
4684
+ // Only apply variant classes if no custom colors
4685
+ !use_custom_colors && get_variant_classes2(variant),
4626
4686
  selected && "ring-2 ring-ring ring-offset-1",
4627
4687
  on_click && "cursor-pointer"
4628
4688
  ),
4689
+ style: custom_styles,
4629
4690
  "data-command-id": id,
4630
4691
  "data-command-prefix": prefix,
4631
4692
  "data-command-action": action,
@@ -4639,7 +4700,7 @@ var CommandPill = ({
4639
4700
  }
4640
4701
  },
4641
4702
  children: [
4642
- /* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-muted-foreground opacity-70", children: prefix }),
4703
+ /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn(!use_custom_colors && "text-muted-foreground opacity-70"), style: use_custom_colors ? { opacity: 0.7 } : void 0, children: prefix }),
4643
4704
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: action_label })
4644
4705
  ]
4645
4706
  }
@@ -4666,7 +4727,8 @@ var CommandPopover = ({
4666
4727
  position,
4667
4728
  on_select,
4668
4729
  on_close,
4669
- on_selection_change: _on_selection_change
4730
+ on_selection_change: _on_selection_change,
4731
+ prefix_color
4670
4732
  }) => {
4671
4733
  const container_ref = React27__namespace.useRef(null);
4672
4734
  const grouped_commands = React27__namespace.useMemo(
@@ -4740,10 +4802,18 @@ var CommandPopover = ({
4740
4802
  {
4741
4803
  value: cmd.action,
4742
4804
  onSelect: () => on_select(cmd),
4743
- className: cn(
4744
- flat_idx === selected_index && "bg-accent"
4745
- ),
4805
+ selected: flat_idx === selected_index,
4746
4806
  children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex items-center gap-2 w-full", children: [
4807
+ prefix_color && (prefix_color.bg || prefix_color.fg) && /* @__PURE__ */ jsxRuntime.jsx(
4808
+ "span",
4809
+ {
4810
+ className: "flex-shrink-0 w-2 h-2 rounded-full",
4811
+ style: {
4812
+ backgroundColor: prefix_color.bg || prefix_color.fg,
4813
+ border: prefix_color.border ? `1px solid ${prefix_color.border}` : void 0
4814
+ }
4815
+ }
4816
+ ),
4747
4817
  cmd.icon && /* @__PURE__ */ jsxRuntime.jsx("span", { className: "flex-shrink-0 text-muted-foreground", children: cmd.icon }),
4748
4818
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex-1 min-w-0", children: [
4749
4819
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "font-medium truncate", children: [
@@ -4776,7 +4846,8 @@ var parse_commands_from_text = (text, prefixes) => {
4776
4846
  for (const cmd of prefix_config.commands) {
4777
4847
  action_to_label.set(`${prefix_config.char}${cmd.action}`, {
4778
4848
  label: cmd.action_label,
4779
- prefix: prefix_config.char
4849
+ prefix: prefix_config.char,
4850
+ color: prefix_config.color
4780
4851
  });
4781
4852
  }
4782
4853
  }
@@ -4795,7 +4866,8 @@ var parse_commands_from_text = (text, prefixes) => {
4795
4866
  action_label: info.label,
4796
4867
  prefix,
4797
4868
  position: match.index,
4798
- length: full_match.length
4869
+ length: full_match.length,
4870
+ color: info.color
4799
4871
  });
4800
4872
  }
4801
4873
  }
@@ -4834,7 +4906,10 @@ var text_to_tiptap_content = (text, prefixes, variant = "default") => {
4834
4906
  prefix: cmd.prefix,
4835
4907
  action: cmd.action,
4836
4908
  action_label: cmd.action_label,
4837
- variant
4909
+ variant,
4910
+ ...cmd.color?.bg && { color_bg: cmd.color.bg },
4911
+ ...cmd.color?.fg && { color_fg: cmd.color.fg },
4912
+ ...cmd.color?.border && { color_border: cmd.color.border }
4838
4913
  }
4839
4914
  });
4840
4915
  last_end = cmd.position + cmd.length;
@@ -5077,19 +5152,22 @@ var HazoUiTextbox = ({
5077
5152
  const handle_command_select = React27__namespace.useCallback(
5078
5153
  (command) => {
5079
5154
  if (!editor || !suggestion_state) return;
5155
+ const prefix_config = prefixes.find((p) => p.char === suggestion_state.prefix);
5156
+ const prefix_color = prefix_config?.color;
5080
5157
  insert_command_at_position(
5081
5158
  editor,
5082
5159
  command,
5083
5160
  suggestion_state.prefix,
5084
5161
  suggestion_state.range,
5085
- pill_variant
5162
+ pill_variant,
5163
+ prefix_color
5086
5164
  );
5087
5165
  if (on_command_insert) {
5088
5166
  on_command_insert(command, suggestion_state.prefix);
5089
5167
  }
5090
5168
  set_suggestion_state(null);
5091
5169
  },
5092
- [editor, suggestion_state, pill_variant, on_command_insert]
5170
+ [editor, suggestion_state, pill_variant, on_command_insert, prefixes]
5093
5171
  );
5094
5172
  const handle_popover_close = React27__namespace.useCallback(() => {
5095
5173
  set_suggestion_state(null);
@@ -5311,7 +5389,8 @@ var HazoUiTextbox = ({
5311
5389
  },
5312
5390
  on_select: handle_command_select,
5313
5391
  on_close: handle_popover_close,
5314
- on_selection_change: set_selected_index
5392
+ on_selection_change: set_selected_index,
5393
+ prefix_color: prefixes.find((p) => p.char === suggestion_state.prefix)?.color
5315
5394
  }
5316
5395
  ),
5317
5396
  edit_context && mounted && reactDom.createPortal(
@@ -5617,19 +5696,22 @@ var HazoUiTextarea = ({
5617
5696
  const handle_command_select = React27__namespace.useCallback(
5618
5697
  (command) => {
5619
5698
  if (!editor || !suggestion_state) return;
5699
+ const prefix_config = prefixes.find((p) => p.char === suggestion_state.prefix);
5700
+ const prefix_color = prefix_config?.color;
5620
5701
  insert_command_at_position(
5621
5702
  editor,
5622
5703
  command,
5623
5704
  suggestion_state.prefix,
5624
5705
  suggestion_state.range,
5625
- pill_variant
5706
+ pill_variant,
5707
+ prefix_color
5626
5708
  );
5627
5709
  if (on_command_insert) {
5628
5710
  on_command_insert(command, suggestion_state.prefix);
5629
5711
  }
5630
5712
  set_suggestion_state(null);
5631
5713
  },
5632
- [editor, suggestion_state, pill_variant, on_command_insert]
5714
+ [editor, suggestion_state, pill_variant, on_command_insert, prefixes]
5633
5715
  );
5634
5716
  const handle_popover_close = React27__namespace.useCallback(() => {
5635
5717
  set_suggestion_state(null);
@@ -5855,7 +5937,8 @@ var HazoUiTextarea = ({
5855
5937
  },
5856
5938
  on_select: handle_command_select,
5857
5939
  on_close: handle_popover_close,
5858
- on_selection_change: set_selected_index
5940
+ on_selection_change: set_selected_index,
5941
+ prefix_color: prefixes.find((p) => p.char === suggestion_state.prefix)?.color
5859
5942
  }
5860
5943
  ),
5861
5944
  edit_context && mounted && reactDom.createPortal(