@wavv/ui 2.2.2-alpha.5 → 2.2.2-alpha.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/build/assets/icons/CaretDown.js +18 -0
  2. package/build/assets/icons/CaretUp.js +18 -0
  3. package/build/assets/icons/Checkbox.js +15 -0
  4. package/build/assets/icons/CheckboxOff.js +15 -0
  5. package/build/assets/icons/CheckboxPartial.js +15 -0
  6. package/build/assets/icons/Dialpad.js +18 -0
  7. package/build/assets/icons/Exclamation.js +25 -0
  8. package/build/assets/icons/Phone.js +13 -0
  9. package/build/assets/icons/PhoneAdd.js +21 -0
  10. package/build/assets/icons/PhoneBlocked.js +22 -0
  11. package/build/assets/icons/PhoneCallback.js +21 -0
  12. package/build/assets/icons/PhoneEnd.js +28 -0
  13. package/build/assets/icons/PhoneForward.js +22 -0
  14. package/build/assets/icons/PhoneHistory.js +21 -0
  15. package/build/assets/icons/PhoneHold.js +22 -0
  16. package/build/assets/icons/PhoneIncoming.js +22 -0
  17. package/build/assets/icons/PhoneMissed.js +22 -0
  18. package/build/assets/icons/PhoneTalk.js +22 -0
  19. package/build/assets/icons/PhoneTransfer.js +21 -0
  20. package/build/assets/icons/RadioButton.js +22 -0
  21. package/build/assets/icons/RadioButtonOff.js +15 -0
  22. package/build/assets/icons/Record.js +18 -0
  23. package/build/assets/icons/Screenshot.js +39 -0
  24. package/build/assets/icons/ShieldWavv.js +30 -0
  25. package/build/assets/icons/Spotify.js +15 -0
  26. package/build/assets/icons/SubArrow.js +16 -0
  27. package/build/assets/icons/ToggleOff.js +15 -0
  28. package/build/assets/icons/ToggleOn.js +15 -0
  29. package/build/assets/icons/TransferCancel.js +60 -0
  30. package/build/components/Accordion/Accordion.js +26 -0
  31. package/build/components/Accordion/Header.js +86 -0
  32. package/build/components/Accordion/Item.js +25 -0
  33. package/build/components/Accordion/Panel.js +64 -0
  34. package/build/components/Accordion/index.js +2 -0
  35. package/build/components/Audio.js +248 -0
  36. package/build/components/BarChart.js +123 -0
  37. package/build/components/Button/Button.js +258 -0
  38. package/build/components/Button/ButtonLoader.js +20 -0
  39. package/build/components/Button/ButtonTypes.js +0 -0
  40. package/build/components/Button/Group.js +58 -0
  41. package/build/components/Button/index.js +2 -0
  42. package/build/components/Calendar.js +49 -0
  43. package/build/components/CalendarParts/CalendarContainerStyles.js +15 -0
  44. package/build/components/CalendarParts/CalendarContent.js +138 -0
  45. package/build/components/CalendarParts/CalendarHeader.js +146 -0
  46. package/build/components/CalendarParts/useMinMax.js +23 -0
  47. package/build/components/CalendarParts/utils.js +6 -0
  48. package/build/components/ChartHelpers.js +121 -0
  49. package/build/components/Checkbox.js +85 -0
  50. package/build/components/Code/Code.js +117 -0
  51. package/build/components/Code/Copy.js +50 -0
  52. package/build/components/Code/Endpoint.js +82 -0
  53. package/build/components/Code/index.js +3 -0
  54. package/build/components/ComboBox.js +190 -0
  55. package/build/components/CommandMenu/CommandItem.js +32 -0
  56. package/build/components/CommandMenu/CommandMenu.js +136 -0
  57. package/build/components/CommandMenu/CommandOptions.js +24 -0
  58. package/build/components/CommandMenu/CommandSection.js +19 -0
  59. package/build/components/CommandMenu/index.js +2 -0
  60. package/build/components/DateRangeSelect.js +359 -0
  61. package/build/components/DocTable.js +32 -0
  62. package/build/components/Dot.js +60 -0
  63. package/build/components/DraftEditor.js +188 -0
  64. package/build/components/Dropdown.js +130 -0
  65. package/build/components/DropdownMenu.js +131 -0
  66. package/build/components/DropdownMenuParts/Menu.js +6 -0
  67. package/build/components/DropdownMenuParts/MenuItem.js +54 -0
  68. package/build/components/DropdownMenuParts/MenuOptions.js +47 -0
  69. package/build/components/DropdownMenuParts/MenuSection.js +14 -0
  70. package/build/components/DropdownSelect.js +171 -0
  71. package/build/components/DynamicIcon.js +49 -0
  72. package/build/components/Editor/Editor.js +356 -0
  73. package/build/components/Editor/EditorStyles.js +259 -0
  74. package/build/components/Editor/MergeFieldExtension.js +110 -0
  75. package/build/components/Editor/RichTextToolbar.js +515 -0
  76. package/build/components/Editor/editorUtils.js +213 -0
  77. package/build/components/Editor/index.js +3 -0
  78. package/build/components/Ellipsis.js +22 -0
  79. package/build/components/Focusable.js +20 -0
  80. package/build/components/Form.js +68 -0
  81. package/build/components/FormControl.js +72 -0
  82. package/build/components/Grid.js +53 -0
  83. package/build/components/Icon/Icon.js +89 -0
  84. package/build/components/Icon/customIcons.js +48 -0
  85. package/build/components/Icon/icons.js +145 -0
  86. package/build/components/Icon/index.js +3 -0
  87. package/build/components/ImageViewer.js +142 -0
  88. package/build/components/InlineCode.js +10 -0
  89. package/build/components/InputHelpers.js +106 -0
  90. package/build/components/Inputs/DatePicker.js +111 -0
  91. package/build/components/Inputs/DateRangePicker.js +166 -0
  92. package/build/components/Inputs/InlineInput.js +71 -0
  93. package/build/components/Inputs/NumberInput.js +117 -0
  94. package/build/components/Inputs/PhoneInput.js +96 -0
  95. package/build/components/Inputs/SearchInput.js +84 -0
  96. package/build/components/Inputs/TextArea.js +164 -0
  97. package/build/components/Inputs/TextInput.js +74 -0
  98. package/build/components/Inputs/TimeInput.js +74 -0
  99. package/build/components/Inputs/helpers/AriaButton.js +19 -0
  100. package/build/components/Inputs/helpers/DateSegment.js +22 -0
  101. package/build/components/Inputs/helpers/Description.js +11 -0
  102. package/build/components/Inputs/helpers/ErrorMessage.js +11 -0
  103. package/build/components/Inputs/helpers/Input.js +6 -0
  104. package/build/components/Inputs/helpers/InputContainerStyles.js +78 -0
  105. package/build/components/Inputs/helpers/InputMessage.js +30 -0
  106. package/build/components/Inputs/helpers/InputStyles.js +43 -0
  107. package/build/components/Inputs/helpers/Label.js +42 -0
  108. package/build/components/Inputs/helpers/LabelWrapper.js +14 -0
  109. package/build/components/Inputs/helpers/PickerToggle.js +7 -0
  110. package/build/components/Inputs/helpers/TextArea.js +8 -0
  111. package/build/components/Inputs/helpers/filterPastedText.js +9 -0
  112. package/build/components/Inputs/helpers/handlePaste.js +12 -0
  113. package/build/components/Inputs/helpers/isAcceptable.js +7 -0
  114. package/build/components/Inputs/helpers/useDynamicWidth.js +39 -0
  115. package/build/components/Inputs/helpers/useInputFocus.js +19 -0
  116. package/build/components/Label.js +42 -0
  117. package/build/components/LineChart.js +80 -0
  118. package/build/components/ListBoxParts/GridListItem.js +34 -0
  119. package/build/components/ListBoxParts/ListBoxItem.js +32 -0
  120. package/build/components/ListBoxParts/ListOptions.js +45 -0
  121. package/build/components/ListHelpers/GridListHeader.js +14 -0
  122. package/build/components/ListHelpers/GridListSection.js +14 -0
  123. package/build/components/ListHelpers/ItemHeaderBody.js +36 -0
  124. package/build/components/ListHelpers/ListHeader.js +14 -0
  125. package/build/components/ListHelpers/ListItemStyles.js +52 -0
  126. package/build/components/ListHelpers/ListRootStyles.js +14 -0
  127. package/build/components/ListHelpers/ListSection.js +14 -0
  128. package/build/components/ListHelpers/ListStyles.js +29 -0
  129. package/build/components/Menu.js +159 -0
  130. package/build/components/Message.js +107 -0
  131. package/build/components/MessageHr.js +32 -0
  132. package/build/components/Modal.js +212 -0
  133. package/build/components/MotionPopover.js +39 -0
  134. package/build/components/MultiSelect/MultiSelect.js +263 -0
  135. package/build/components/MultiSelect/SearchDropdown.js +155 -0
  136. package/build/components/MultiSelect/index.js +2 -0
  137. package/build/components/OptionHelpers/Container.js +34 -0
  138. package/build/components/OptionHelpers/Item.js +59 -0
  139. package/build/components/OptionHelpers/types.js +0 -0
  140. package/build/components/Pagination.js +121 -0
  141. package/build/components/PieChart.js +40 -0
  142. package/build/components/Popover.js +40 -0
  143. package/build/components/PortalScope.js +8 -0
  144. package/build/components/Progress/CirclePercent.js +56 -0
  145. package/build/components/Progress/Progress.js +59 -0
  146. package/build/components/Progress/index.js +3 -0
  147. package/build/components/Radio.js +45 -0
  148. package/build/components/RangeCalendar.js +60 -0
  149. package/build/components/Select.js +162 -0
  150. package/build/components/Slider.js +50 -0
  151. package/build/components/Spinner.js +70 -0
  152. package/build/components/Table/Body.js +49 -0
  153. package/build/components/Table/Cell.js +63 -0
  154. package/build/components/Table/Check.js +35 -0
  155. package/build/components/Table/Column.js +129 -0
  156. package/build/components/Table/ColumnSort.js +26 -0
  157. package/build/components/Table/Header.js +64 -0
  158. package/build/components/Table/Resizer.js +25 -0
  159. package/build/components/Table/Row.js +84 -0
  160. package/build/components/Table/SortCaret.js +24 -0
  161. package/build/components/Table/Table.js +88 -0
  162. package/build/components/Table/contentStyles.js +20 -0
  163. package/build/components/Table/context.js +4 -0
  164. package/build/components/Table/index.js +2 -0
  165. package/build/components/Table/types.js +0 -0
  166. package/build/components/Tabs.js +151 -0
  167. package/build/components/Tag.js +71 -0
  168. package/build/components/Toggle.js +59 -0
  169. package/build/components/ToggleButton/ToggleButton.js +104 -0
  170. package/build/components/ToggleButton/ToggleButtonGroup.js +36 -0
  171. package/build/components/ToggleButton/context.js +8 -0
  172. package/build/components/ToggleButton/index.js +3 -0
  173. package/build/components/Tooltip.js +136 -0
  174. package/build/components/TransferList.js +234 -0
  175. package/build/components/Tree/Tree.js +69 -0
  176. package/build/components/Tree/TreeContext.js +3 -0
  177. package/build/components/Tree/TreeItem.js +93 -0
  178. package/build/components/Tree/index.js +2 -0
  179. package/build/components/UnstyledButton.js +8 -0
  180. package/build/components/Waveform.js +243 -0
  181. package/build/components/draftUtils.js +193 -0
  182. package/build/components/helpers/getIcon.js +28 -0
  183. package/build/components/helpers/getPopPosition.js +20 -0
  184. package/build/components/helpers/isPropAllowed.js +3 -0
  185. package/build/components/helpers/mergePadding.js +47 -0
  186. package/build/components/helpers/styledProps.js +34 -0
  187. package/build/components/typeDefs/elementTypes.js +0 -0
  188. package/build/components/typeDefs/inputTypes.js +0 -0
  189. package/build/components/typeDefs/selectionTypes.js +0 -0
  190. package/build/components/typeDefs/tagTypes.js +0 -0
  191. package/build/components/types.js +0 -0
  192. package/build/global-styles/GlobalStorybookStyles.js +108 -0
  193. package/build/global-styles/ResetStyles.js +33 -0
  194. package/build/global-styles/ScrollbarStyles.js +26 -0
  195. package/build/global-styles/ToastStyles.js +66 -0
  196. package/build/global-styles/index.js +4 -0
  197. package/build/hooks/index.js +9 -0
  198. package/build/hooks/useConfirm.js +91 -0
  199. package/build/hooks/useControlledOpenState.js +22 -0
  200. package/build/hooks/useCopy.js +28 -0
  201. package/build/hooks/useElementObserver.js +6 -0
  202. package/build/hooks/useEventListener.js +19 -0
  203. package/build/hooks/useOnClickOutside.js +21 -0
  204. package/build/hooks/usePrevious.js +12 -0
  205. package/build/hooks/useSelectAll.js +60 -0
  206. package/build/hooks/useWindowSize.js +25 -0
  207. package/build/theme/ThemeTypes.js +0 -0
  208. package/build/theme/common/button.js +33 -0
  209. package/build/theme/common/common.js +38 -0
  210. package/build/theme/common/index.js +4 -0
  211. package/build/theme/core/colors.js +77 -0
  212. package/build/theme/core/dark/dark.js +457 -0
  213. package/build/theme/core/dark/darkScale.js +36 -0
  214. package/build/theme/core/light/light.js +456 -0
  215. package/build/theme/core/light/lightScale.js +35 -0
  216. package/build/theme/eighties/colors.js +78 -0
  217. package/build/theme/eighties/dark/dark.js +457 -0
  218. package/build/theme/eighties/dark/darkScale.js +36 -0
  219. package/build/theme/eighties/light/light.js +456 -0
  220. package/build/theme/eighties/light/lightScale.js +35 -0
  221. package/build/theme/index.js +28 -0
  222. package/build/utils/chunk.js +13 -0
  223. package/build/utils/copyToClipboard.js +29 -0
  224. package/build/utils/flattenListOptions.js +4 -0
  225. package/build/utils/formatDate.js +55 -0
  226. package/build/utils/index.js +6 -0
  227. package/build/utils/numberWithCommas.js +3 -0
  228. package/build/utils/range.js +11 -0
  229. package/package.json +1 -1
@@ -0,0 +1,110 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import styled from "@emotion/styled";
3
+ import { Node, mergeAttributes } from "@tiptap/core";
4
+ import { NodeViewWrapper, ReactNodeViewRenderer } from "@tiptap/react";
5
+ const MergeFieldSpan = styled.span(({ theme, error })=>({
6
+ color: error ? theme.color.error : theme.accent,
7
+ backgroundColor: error ? theme.color.errorTint1 : theme.color.brandTint1,
8
+ borderRadius: 3,
9
+ padding: '0 4px',
10
+ margin: '0 1px',
11
+ fontSize: 'inherit',
12
+ fontFamily: 'inherit',
13
+ cursor: 'default',
14
+ userSelect: 'none',
15
+ '&:hover': {
16
+ backgroundColor: error ? theme.color.errorTint2 : theme.color.brandTint2
17
+ }
18
+ }));
19
+ const MergeFieldComponent = ({ node })=>{
20
+ const { id, label, isValid } = node.attrs;
21
+ return /*#__PURE__*/ jsx(NodeViewWrapper, {
22
+ as: "span",
23
+ style: {
24
+ display: 'contents'
25
+ },
26
+ children: /*#__PURE__*/ jsx(MergeFieldSpan, {
27
+ error: !isValid,
28
+ "data-merge-field-id": id,
29
+ children: label
30
+ })
31
+ });
32
+ };
33
+ const MergeField = Node.create({
34
+ name: 'mergeField',
35
+ group: 'inline',
36
+ inline: true,
37
+ atom: true,
38
+ addAttributes () {
39
+ return {
40
+ id: {
41
+ default: '',
42
+ parseHTML: (element)=>element.getAttribute('data-merge-field-id'),
43
+ renderHTML: (attributes)=>{
44
+ if (!attributes.id) return {};
45
+ return {
46
+ 'data-merge-field-id': attributes.id
47
+ };
48
+ }
49
+ },
50
+ label: {
51
+ default: ''
52
+ },
53
+ isValid: {
54
+ default: true
55
+ },
56
+ displayValue: {
57
+ default: false
58
+ }
59
+ };
60
+ },
61
+ parseHTML () {
62
+ return [
63
+ {
64
+ tag: 'span[data-merge-field-id]'
65
+ }
66
+ ];
67
+ },
68
+ renderHTML ({ HTMLAttributes, node }) {
69
+ return [
70
+ 'span',
71
+ mergeAttributes(HTMLAttributes, {
72
+ 'data-merge-field-id': node.attrs.id
73
+ }),
74
+ node.attrs.label
75
+ ];
76
+ },
77
+ addNodeView () {
78
+ return ReactNodeViewRenderer(MergeFieldComponent);
79
+ },
80
+ addKeyboardShortcuts () {
81
+ return {
82
+ Backspace: ()=>{
83
+ const { state, view } = this.editor;
84
+ const { selection } = state;
85
+ const $pos = selection.$from;
86
+ const nodeBefore = $pos.nodeBefore;
87
+ if (nodeBefore && 'mergeField' === nodeBefore.type.name) {
88
+ const tr = state.tr.delete($pos.pos - nodeBefore.nodeSize, $pos.pos);
89
+ view.dispatch(tr);
90
+ return true;
91
+ }
92
+ return false;
93
+ },
94
+ Delete: ()=>{
95
+ const { state, view } = this.editor;
96
+ const { selection } = state;
97
+ const $pos = selection.$to;
98
+ const nodeAfter = $pos.nodeAfter;
99
+ if (nodeAfter && 'mergeField' === nodeAfter.type.name) {
100
+ const tr = state.tr.delete($pos.pos, $pos.pos + nodeAfter.nodeSize);
101
+ view.dispatch(tr);
102
+ return true;
103
+ }
104
+ return false;
105
+ }
106
+ };
107
+ }
108
+ });
109
+ const MergeFieldExtension = MergeField;
110
+ export { MergeField, MergeFieldExtension as default };
@@ -0,0 +1,515 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import { useTheme } from "@emotion/react";
3
+ import styled from "@emotion/styled";
4
+ import { useEditorState } from "@tiptap/react";
5
+ import { useState } from "react";
6
+ import Button from "../Button/index.js";
7
+ import DropdownMenu from "../DropdownMenu.js";
8
+ import { marginProps } from "../helpers/styledProps.js";
9
+ import Icon from "../Icon/index.js";
10
+ import Popover from "../Popover.js";
11
+ import { getEditorCharacterCount } from "./editorUtils.js";
12
+ const RichTextToolbar_RichTextToolbar = ({ editor, insertField, mergeFields, maxLength })=>{
13
+ const { accent, editor: { highlight } } = useTheme();
14
+ const [showMergeFields, setShowMergeFields] = useState(false);
15
+ const [isListsOpen, setIsListsOpen] = useState(false);
16
+ const [isHeadingOpen, setIsHeadingOpen] = useState(false);
17
+ const [showHighlightColors, setShowHighlightColors] = useState(false);
18
+ const editorState = useEditorState({
19
+ editor,
20
+ selector: ({ editor: editorInstance })=>{
21
+ if (!editorInstance) return {
22
+ isBold: false,
23
+ isItalic: false,
24
+ isStrike: false,
25
+ isUnderline: false,
26
+ isCode: false,
27
+ isHighlight: false,
28
+ isBlockquote: false,
29
+ currentHeading: 0,
30
+ isBulletList: false,
31
+ isOrderedList: false,
32
+ isTaskList: false,
33
+ canUndo: false,
34
+ canRedo: false,
35
+ characterCount: 0
36
+ };
37
+ let currentHeading = 0;
38
+ for(let level = 1; level <= 6; level++)if (editorInstance.isActive('heading', {
39
+ level
40
+ })) {
41
+ currentHeading = level;
42
+ break;
43
+ }
44
+ return {
45
+ isBold: editorInstance.isActive('bold'),
46
+ isItalic: editorInstance.isActive('italic'),
47
+ isStrike: editorInstance.isActive('strike'),
48
+ isUnderline: editorInstance.isActive('underline'),
49
+ isCode: editorInstance.isActive('code'),
50
+ isHighlight: editorInstance.isActive('highlight'),
51
+ isBlockquote: editorInstance.isActive('blockquote'),
52
+ currentHeading,
53
+ isBulletList: editorInstance.isActive('bulletList'),
54
+ isOrderedList: editorInstance.isActive('orderedList'),
55
+ isTaskList: editorInstance.isActive('taskList'),
56
+ canUndo: editorInstance.can().undo(),
57
+ canRedo: editorInstance.can().redo(),
58
+ characterCount: getEditorCharacterCount(editorInstance)
59
+ };
60
+ }
61
+ });
62
+ const formatOptions = [
63
+ {
64
+ icon: 'bold',
65
+ format: 'bold',
66
+ title: 'Bold (⌘B)'
67
+ },
68
+ {
69
+ icon: 'italic',
70
+ format: 'italic',
71
+ title: 'Italic (⌘I)'
72
+ },
73
+ {
74
+ icon: 'strikethrough',
75
+ format: 'strike',
76
+ title: 'Strikethrough (⌘⇧S)'
77
+ },
78
+ {
79
+ icon: 'underline',
80
+ format: 'underline',
81
+ title: 'Underline (⌘U)'
82
+ },
83
+ {
84
+ icon: 'blockquote',
85
+ format: 'blockquote',
86
+ title: 'Blockquote (⌘⇧B)'
87
+ }
88
+ ];
89
+ const highlightColors = [
90
+ {
91
+ color: highlight.yellow,
92
+ label: 'Yellow'
93
+ },
94
+ {
95
+ color: highlight.blue,
96
+ label: 'Blue'
97
+ },
98
+ {
99
+ color: highlight.red,
100
+ label: 'Red'
101
+ },
102
+ {
103
+ color: highlight.green,
104
+ label: 'Green'
105
+ },
106
+ {
107
+ color: highlight.orange,
108
+ label: 'Orange'
109
+ }
110
+ ];
111
+ const headingOptions = [
112
+ {
113
+ id: '1',
114
+ value: 'Heading 1',
115
+ leftElement: /*#__PURE__*/ jsx(Icon, {
116
+ name: "heading-1",
117
+ size: "small",
118
+ marginRight: 4
119
+ })
120
+ },
121
+ {
122
+ id: '2',
123
+ value: 'Heading 2',
124
+ leftElement: /*#__PURE__*/ jsx(Icon, {
125
+ name: "heading-2",
126
+ size: "small",
127
+ marginRight: 4
128
+ })
129
+ },
130
+ {
131
+ id: '3',
132
+ value: 'Heading 3',
133
+ leftElement: /*#__PURE__*/ jsx(Icon, {
134
+ name: "heading-3",
135
+ size: "small",
136
+ marginRight: 4
137
+ })
138
+ },
139
+ {
140
+ id: '0',
141
+ value: 'Paragraph',
142
+ leftElement: /*#__PURE__*/ jsx(Icon, {
143
+ name: "paragraph",
144
+ size: "small",
145
+ marginRight: 4
146
+ })
147
+ }
148
+ ];
149
+ const listOptions = [
150
+ {
151
+ id: 'bullet',
152
+ value: 'Bullet List',
153
+ leftElement: /*#__PURE__*/ jsx(Icon, {
154
+ name: "list-bullet",
155
+ size: "small",
156
+ marginRight: 4
157
+ })
158
+ },
159
+ {
160
+ id: 'ordered',
161
+ value: 'Ordered List',
162
+ leftElement: /*#__PURE__*/ jsx(Icon, {
163
+ name: "list-ordered",
164
+ size: "small",
165
+ marginRight: 4
166
+ })
167
+ },
168
+ {
169
+ id: 'task',
170
+ value: 'Task List',
171
+ leftElement: /*#__PURE__*/ jsx(Icon, {
172
+ name: "list-task",
173
+ size: "small",
174
+ marginRight: 4
175
+ })
176
+ }
177
+ ];
178
+ const toggleFormat = (format)=>{
179
+ if (!editor) return;
180
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
181
+ switch(format){
182
+ case 'bold':
183
+ chain.toggleBold().run();
184
+ break;
185
+ case 'italic':
186
+ chain.toggleItalic().run();
187
+ break;
188
+ case 'strike':
189
+ chain.toggleStrike().run();
190
+ break;
191
+ case 'underline':
192
+ chain.toggleUnderline().run();
193
+ break;
194
+ case 'code':
195
+ chain.toggleCode().run();
196
+ break;
197
+ case 'blockquote':
198
+ chain.toggleBlockquote().run();
199
+ break;
200
+ case 'highlight':
201
+ break;
202
+ }
203
+ };
204
+ const handleHeadingChange = (value)=>{
205
+ if (!editor) return;
206
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
207
+ const level = Number.parseInt(value, 10);
208
+ if (0 === level) chain.setParagraph().run();
209
+ else chain.toggleHeading({
210
+ level: level
211
+ }).run();
212
+ };
213
+ const handleListChange = (value)=>{
214
+ if (!editor) return;
215
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
216
+ switch(value){
217
+ case 'bullet':
218
+ chain.toggleBulletList().run();
219
+ break;
220
+ case 'ordered':
221
+ chain.toggleOrderedList().run();
222
+ break;
223
+ case 'task':
224
+ chain.toggleTaskList().run();
225
+ break;
226
+ }
227
+ };
228
+ const handleUndo = ()=>{
229
+ if (!editor) return;
230
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
231
+ chain.undo().run();
232
+ };
233
+ const handleRedo = ()=>{
234
+ if (!editor) return;
235
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
236
+ chain.redo().run();
237
+ };
238
+ const handleHighlightColor = (color)=>{
239
+ if (!editor) return;
240
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
241
+ chain.toggleHighlight({
242
+ color
243
+ }).run();
244
+ setShowHighlightColors(false);
245
+ };
246
+ const handleRemoveHighlight = ()=>{
247
+ if (!editor) return;
248
+ const chain = editor.isFocused ? editor.chain() : editor.chain().focus();
249
+ chain.unsetHighlight().run();
250
+ setShowHighlightColors(false);
251
+ };
252
+ const isFormatActive = (format)=>{
253
+ switch(format){
254
+ case 'bold':
255
+ return editorState.isBold;
256
+ case 'italic':
257
+ return editorState.isItalic;
258
+ case 'strike':
259
+ return editorState.isStrike;
260
+ case 'underline':
261
+ return editorState.isUnderline;
262
+ case 'code':
263
+ return editorState.isCode;
264
+ case 'blockquote':
265
+ return editorState.isBlockquote;
266
+ case 'highlight':
267
+ return editorState.isHighlight;
268
+ default:
269
+ return false;
270
+ }
271
+ };
272
+ const isList = editorState.isBulletList || editorState.isOrderedList || editorState.isTaskList;
273
+ const isHeading = 0 !== editorState.currentHeading;
274
+ const listDropdownKey = `list-${editorState.isBulletList ? 'bullet' : editorState.isOrderedList ? 'ordered' : editorState.isTaskList ? 'task' : 'none'}`;
275
+ const getHeadingIcon = ()=>{
276
+ switch(editorState.currentHeading){
277
+ case 1:
278
+ return 'heading-1';
279
+ case 2:
280
+ return 'heading-2';
281
+ case 3:
282
+ return 'heading-3';
283
+ case 4:
284
+ return 'heading-4';
285
+ case 5:
286
+ return 'heading-5';
287
+ case 6:
288
+ return 'heading-6';
289
+ default:
290
+ return 'heading';
291
+ }
292
+ };
293
+ const getListIcon = ()=>{
294
+ if (editorState.isBulletList) return 'list-bullet';
295
+ if (editorState.isOrderedList) return 'list-ordered';
296
+ if (editorState.isTaskList) return 'list-task';
297
+ return 'list-bullet';
298
+ };
299
+ return /*#__PURE__*/ jsx(ToolbarContainer, {
300
+ children: /*#__PURE__*/ jsxs(Bar, {
301
+ marginLeft: -11,
302
+ marginRight: -11,
303
+ children: [
304
+ /*#__PURE__*/ jsx(Button, {
305
+ small: true,
306
+ subtle: true,
307
+ secondary: true,
308
+ disabled: !editorState.canUndo,
309
+ onClick: handleUndo,
310
+ title: "Undo (⌘Z)",
311
+ icon: "undo"
312
+ }),
313
+ /*#__PURE__*/ jsx(Button, {
314
+ small: true,
315
+ subtle: true,
316
+ secondary: true,
317
+ disabled: !editorState.canRedo,
318
+ onClick: handleRedo,
319
+ title: "Redo (⌘⇧Z)",
320
+ icon: "redo"
321
+ }),
322
+ /*#__PURE__*/ jsx(Divider, {}),
323
+ /*#__PURE__*/ jsx(DropdownMenu, {
324
+ trigger: /*#__PURE__*/ jsx(Button, {
325
+ small: true,
326
+ subtle: !isHeadingOpen && !isHeading,
327
+ iconColor: isHeading ? accent : void 0,
328
+ secondary: true,
329
+ title: "Text Format",
330
+ icon: getHeadingIcon()
331
+ }),
332
+ options: headingOptions,
333
+ onSelectionChange: handleHeadingChange,
334
+ selectionMode: "single",
335
+ selectedKeys: editorState.currentHeading.toString(),
336
+ isTriggerButton: true,
337
+ position: "bottom start",
338
+ onOpenChange: setIsHeadingOpen
339
+ }),
340
+ /*#__PURE__*/ jsx(DropdownMenu, {
341
+ trigger: /*#__PURE__*/ jsx(Button, {
342
+ small: true,
343
+ subtle: !isListsOpen && !isList,
344
+ iconColor: isList ? accent : void 0,
345
+ secondary: true,
346
+ title: "Lists",
347
+ icon: getListIcon()
348
+ }),
349
+ options: listOptions,
350
+ onSelectionChange: handleListChange,
351
+ selectionMode: "single",
352
+ selectedKeys: editorState.isBulletList ? 'bullet' : editorState.isOrderedList ? 'ordered' : editorState.isTaskList ? 'task' : void 0,
353
+ isTriggerButton: true,
354
+ position: "bottom start",
355
+ onOpenChange: setIsListsOpen
356
+ }, listDropdownKey),
357
+ /*#__PURE__*/ jsx(Divider, {}),
358
+ formatOptions.map(({ icon, format, title })=>{
359
+ const isActive = isFormatActive(format);
360
+ return /*#__PURE__*/ jsx(Button, {
361
+ small: true,
362
+ subtle: !isActive,
363
+ iconColor: isActive ? accent : void 0,
364
+ secondary: true,
365
+ onClick: ()=>toggleFormat(format),
366
+ title: title,
367
+ icon: icon
368
+ }, format);
369
+ }),
370
+ /*#__PURE__*/ jsx(Popover, {
371
+ open: showHighlightColors,
372
+ onOpenChange: setShowHighlightColors,
373
+ position: "bottom end",
374
+ trigger: /*#__PURE__*/ jsx(Button, {
375
+ small: true,
376
+ subtle: !showHighlightColors && !editorState.isHighlight,
377
+ iconColor: editorState.isHighlight ? accent : void 0,
378
+ secondary: true,
379
+ icon: "highlight",
380
+ title: "Highlight Colors"
381
+ }),
382
+ isTriggerButton: true,
383
+ children: /*#__PURE__*/ jsxs(HighlightColorGrid, {
384
+ children: [
385
+ highlightColors.map(({ color, label })=>/*#__PURE__*/ jsx(ColorButton, {
386
+ onClick: ()=>handleHighlightColor(color),
387
+ style: {
388
+ backgroundColor: color
389
+ },
390
+ title: label,
391
+ "aria-label": `Highlight with ${label}`
392
+ }, color)),
393
+ /*#__PURE__*/ jsx(RemoveHighlightButton, {
394
+ onClick: handleRemoveHighlight,
395
+ title: "Remove highlight",
396
+ "aria-label": "Remove highlight",
397
+ children: "\xd7"
398
+ })
399
+ ]
400
+ })
401
+ }),
402
+ mergeFields.length > 0 && /*#__PURE__*/ jsxs(Fragment, {
403
+ children: [
404
+ /*#__PURE__*/ jsx(Divider, {}),
405
+ /*#__PURE__*/ jsx(DropdownMenu, {
406
+ open: showMergeFields,
407
+ onOpenChange: setShowMergeFields,
408
+ position: "bottom end",
409
+ trigger: /*#__PURE__*/ jsx(Button, {
410
+ small: true,
411
+ subtle: !showMergeFields,
412
+ iconColor: showMergeFields ? accent : void 0,
413
+ secondary: true,
414
+ icon: "merge-field",
415
+ title: "Merge Fields"
416
+ }),
417
+ isTriggerButton: true,
418
+ options: mergeFields.map((field)=>({
419
+ id: field.id,
420
+ value: field.label,
421
+ onClick: ()=>insertField(field)
422
+ }))
423
+ })
424
+ ]
425
+ }),
426
+ maxLength && editorState.characterCount > 0.9 * maxLength && /*#__PURE__*/ jsxs(Count, {
427
+ children: [
428
+ editorState.characterCount,
429
+ "/",
430
+ maxLength
431
+ ]
432
+ })
433
+ ]
434
+ })
435
+ });
436
+ };
437
+ const ToolbarContainer = styled.div({
438
+ display: 'flex',
439
+ flexDirection: 'column',
440
+ gap: 4,
441
+ marginBottom: 16
442
+ });
443
+ const Bar = styled.div(({ theme, gap = 8, background, elevation })=>({
444
+ display: 'flex',
445
+ flexWrap: 'wrap',
446
+ alignItems: 'center',
447
+ gap,
448
+ borderRadius: 4,
449
+ padding: '8px 16px',
450
+ backgroundColor: background || theme.scale0,
451
+ boxShadow: elevation ? theme.elevation4 : void 0,
452
+ overflow: 'hidden'
453
+ }), marginProps);
454
+ const Divider = styled.div(({ theme })=>({
455
+ alignSelf: 'stretch',
456
+ width: 1,
457
+ backgroundColor: theme.scale1,
458
+ margin: '0 8px'
459
+ }));
460
+ const Count = styled.div(({ theme })=>({
461
+ color: theme.scale6,
462
+ marginLeft: 'auto',
463
+ fontSize: theme.font.size.sm
464
+ }));
465
+ const HighlightColorGrid = styled.div(({ theme })=>({
466
+ display: 'grid',
467
+ gridTemplateColumns: 'repeat(3, 1fr)',
468
+ gap: 8,
469
+ padding: 12,
470
+ minWidth: 120,
471
+ backgroundColor: theme.options.background,
472
+ borderRadius: 4,
473
+ boxShadow: theme.elevation3
474
+ }));
475
+ const ColorButton = styled.button(({ theme })=>({
476
+ width: 24,
477
+ height: 24,
478
+ border: `1px solid ${theme.scale2}`,
479
+ borderRadius: 4,
480
+ cursor: 'pointer',
481
+ transition: 'transform 0.1s ease',
482
+ '&:hover': {
483
+ transform: 'scale(1.1)',
484
+ borderColor: theme.accent
485
+ },
486
+ '&:focus': {
487
+ outline: `1px solid ${theme.accent}`,
488
+ outlineOffset: -1
489
+ }
490
+ }));
491
+ const RemoveHighlightButton = styled.button(({ theme })=>({
492
+ width: 24,
493
+ height: 24,
494
+ border: `1px solid ${theme.scale2}`,
495
+ borderRadius: 4,
496
+ cursor: 'pointer',
497
+ backgroundColor: theme.scale0,
498
+ color: theme.input.color.default,
499
+ fontSize: 16,
500
+ fontWeight: 'bold',
501
+ display: 'flex',
502
+ alignItems: 'center',
503
+ justifyContent: 'center',
504
+ transition: 'all 0.1s ease',
505
+ '&:hover': {
506
+ backgroundColor: theme.scale1,
507
+ borderColor: theme.accent
508
+ },
509
+ '&:focus': {
510
+ outline: `2px solid ${theme.accent}`,
511
+ outlineOffset: 2
512
+ }
513
+ }));
514
+ const RichTextToolbar = RichTextToolbar_RichTextToolbar;
515
+ export { RichTextToolbar as default };