@monolith-forensics/monolith-ui 1.8.1-dev.3 → 1.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (171) hide show
  1. package/dist/Button/Button.js +58 -9
  2. package/dist/Calendar/Calendar.d.ts +2 -7
  3. package/dist/Calendar/Calendar.js +49 -226
  4. package/dist/Calendar/CalendarStyles.d.ts +2 -6
  5. package/dist/Calendar/CalendarStyles.js +33 -153
  6. package/dist/Calendar/calendarHelpers.d.ts +2 -6
  7. package/dist/Calendar/calendarHelpers.js +5 -13
  8. package/dist/Charts/BarChart/BarChart.js +28 -14
  9. package/dist/Charts/BarChart/BarChart.styled.d.ts +7 -2
  10. package/dist/Charts/BarChart/BarChart.styled.js +5 -1
  11. package/dist/Charts/BarChart/BarChart.types.d.ts +13 -5
  12. package/dist/Charts/ChartUtils/chartSizing.d.ts +20 -0
  13. package/dist/Charts/ChartUtils/chartSizing.js +83 -0
  14. package/dist/Charts/ChartUtils/index.d.ts +1 -0
  15. package/dist/Charts/ChartUtils/index.js +1 -0
  16. package/dist/Charts/HeatMap/HeatMap.js +28 -7
  17. package/dist/Charts/HeatMap/HeatMap.styled.d.ts +6 -2
  18. package/dist/Charts/HeatMap/HeatMap.styled.js +3 -0
  19. package/dist/Charts/HeatMap/HeatMap.types.d.ts +7 -1
  20. package/dist/Charts/LineChart/LineChart.js +34 -15
  21. package/dist/Charts/LineChart/LineChart.styled.d.ts +7 -2
  22. package/dist/Charts/LineChart/LineChart.styled.js +5 -1
  23. package/dist/Charts/LineChart/LineChart.types.d.ts +13 -5
  24. package/dist/Charts/PieChart/PieChart.js +48 -33
  25. package/dist/Charts/PieChart/PieChart.styled.d.ts +7 -2
  26. package/dist/Charts/PieChart/PieChart.styled.js +6 -1
  27. package/dist/Charts/PieChart/PieChart.types.d.ts +7 -3
  28. package/dist/CheckBox/CheckBox.js +19 -36
  29. package/dist/DateInput/DateInput.js +143 -198
  30. package/dist/DropDownMenu/DropDownMenu.js +15 -25
  31. package/dist/DropDownMenu/components/MenuComponent.js +2 -8
  32. package/dist/DropDownMenu/components/MenuItem.d.ts +0 -2
  33. package/dist/DropDownMenu/components/MenuItem.js +21 -25
  34. package/dist/DropDownMenu/components/MenuItemList.d.ts +0 -3
  35. package/dist/DropDownMenu/components/MenuItemList.js +86 -192
  36. package/dist/DropDownMenu/components/StyledContent.js +2 -1
  37. package/dist/DropDownMenu/components/StyledFloatContainer.js +1 -1
  38. package/dist/DropDownMenu/types.d.ts +0 -3
  39. package/dist/FieldLabel/FieldLabel.js +12 -4
  40. package/dist/FileInputField/FileInputField.js +23 -4
  41. package/dist/FileViewer/viewers/ImageViewer.js +18 -75
  42. package/dist/FormSection/FormSection.js +25 -5
  43. package/dist/IconButton/IconButton.js +16 -2
  44. package/dist/Input/Input.js +56 -7
  45. package/dist/MonolithUIProvider/MonolithUIProvider.d.ts +4 -1
  46. package/dist/Pill/Pill.js +79 -8
  47. package/dist/Popover/Popover.context.d.ts +1 -2
  48. package/dist/Popover/Popover.js +2 -5
  49. package/dist/Popover/Popover.styles.d.ts +6 -1
  50. package/dist/Popover/Popover.styles.js +28 -11
  51. package/dist/Popover/Popover.transitions.d.ts +2 -4
  52. package/dist/Popover/Popover.transitions.js +49 -23
  53. package/dist/Popover/PopoverDropdown.js +8 -6
  54. package/dist/Popover/PopoverTarget.js +3 -6
  55. package/dist/QueryFilter/DefaultOperators.d.ts +76 -1
  56. package/dist/QueryFilter/DefaultOperators.js +21 -1
  57. package/dist/QueryFilter/QueryFilter.d.ts +1 -1
  58. package/dist/QueryFilter/QueryFilter.js +303 -3
  59. package/dist/QueryFilter/index.d.ts +2 -3
  60. package/dist/QueryFilter/index.js +2 -3
  61. package/dist/QueryFilter/types.d.ts +52 -1
  62. package/dist/QueryFilter/types.js +1 -1
  63. package/dist/QueryFilter/useQueryFilter.d.ts +1 -1
  64. package/dist/QueryFilter/useQueryFilter.js +19 -23
  65. package/dist/RichTextEditor/Components/CodeBlockBaseButton.d.ts +18 -0
  66. package/dist/RichTextEditor/Components/CodeBlockBaseButton.js +6 -0
  67. package/dist/RichTextEditor/Components/CodeBlockCopyButton.d.ts +9 -0
  68. package/dist/RichTextEditor/Components/CodeBlockCopyButton.js +42 -0
  69. package/dist/RichTextEditor/Components/CodeBlockFormatButton.d.ts +10 -0
  70. package/dist/RichTextEditor/Components/CodeBlockFormatButton.js +60 -0
  71. package/dist/RichTextEditor/Components/CodeBlockLanguageSelect.d.ts +9 -0
  72. package/dist/RichTextEditor/Components/CodeBlockLanguageSelect.js +30 -0
  73. package/dist/RichTextEditor/Components/CodeBlockNodeView.d.ts +3 -0
  74. package/dist/RichTextEditor/Components/CodeBlockNodeView.js +28 -0
  75. package/dist/RichTextEditor/Components/CodeBlockWrapButton.d.ts +10 -0
  76. package/dist/RichTextEditor/Components/CodeBlockWrapButton.js +17 -0
  77. package/dist/RichTextEditor/Components/LinkEditor.d.ts +8 -0
  78. package/dist/RichTextEditor/Components/LinkEditor.js +94 -0
  79. package/dist/RichTextEditor/Components/TableTools/TableCornerMenu.d.ts +2 -0
  80. package/dist/RichTextEditor/Components/TableTools/TableCornerMenu.js +19 -0
  81. package/dist/RichTextEditor/Components/TableTools/TableInsertControls.d.ts +2 -0
  82. package/dist/RichTextEditor/Components/TableTools/TableInsertControls.js +24 -0
  83. package/dist/RichTextEditor/Components/TableTools/TableRails.d.ts +2 -0
  84. package/dist/RichTextEditor/Components/TableTools/TableRails.js +180 -0
  85. package/dist/RichTextEditor/Components/TableTools/TableToolMenu.d.ts +5 -0
  86. package/dist/RichTextEditor/Components/TableTools/TableToolMenu.js +6 -0
  87. package/dist/RichTextEditor/Components/TableTools/TableTools.actions.d.ts +5 -0
  88. package/dist/RichTextEditor/Components/TableTools/TableTools.actions.js +183 -0
  89. package/dist/RichTextEditor/Components/TableTools/TableTools.commands.d.ts +16 -0
  90. package/dist/RichTextEditor/Components/TableTools/TableTools.commands.js +217 -0
  91. package/dist/RichTextEditor/Components/TableTools/TableTools.constants.d.ts +8 -0
  92. package/dist/RichTextEditor/Components/TableTools/TableTools.constants.js +11 -0
  93. package/dist/RichTextEditor/Components/TableTools/TableTools.d.ts +3 -0
  94. package/dist/RichTextEditor/Components/TableTools/TableTools.geometry.d.ts +23 -0
  95. package/dist/RichTextEditor/Components/TableTools/TableTools.geometry.js +75 -0
  96. package/dist/RichTextEditor/Components/TableTools/TableTools.js +3 -0
  97. package/dist/RichTextEditor/Components/TableTools/TableTools.selectors.d.ts +16 -0
  98. package/dist/RichTextEditor/Components/TableTools/TableTools.selectors.js +53 -0
  99. package/dist/RichTextEditor/Components/TableTools/TableTools.styled.d.ts +40 -0
  100. package/dist/RichTextEditor/Components/TableTools/TableTools.styled.js +167 -0
  101. package/dist/RichTextEditor/Components/TableTools/TableTools.types.d.ts +76 -0
  102. package/dist/RichTextEditor/Components/TableTools/TableTools.types.js +1 -0
  103. package/dist/RichTextEditor/Components/TableTools/TableTools.utils.d.ts +4 -0
  104. package/dist/RichTextEditor/Components/TableTools/TableTools.utils.js +4 -0
  105. package/dist/RichTextEditor/Components/TableTools/TableToolsPopover.d.ts +2 -0
  106. package/dist/RichTextEditor/Components/TableTools/TableToolsPopover.js +12 -0
  107. package/dist/RichTextEditor/Components/TableTools/index.d.ts +3 -0
  108. package/dist/RichTextEditor/Components/TableTools/index.js +2 -0
  109. package/dist/RichTextEditor/Enums/HighlightColors.d.ts +9 -0
  110. package/dist/RichTextEditor/Enums/HighlightColors.js +10 -0
  111. package/dist/RichTextEditor/Extensions/getTiptapExtensions.js +15 -5
  112. package/dist/RichTextEditor/Plugins/ImageActionsPlugin.js +4 -7
  113. package/dist/RichTextEditor/Plugins/UploadImagesPlugin.d.ts +0 -15
  114. package/dist/RichTextEditor/Plugins/UploadImagesPlugin.js +51 -115
  115. package/dist/RichTextEditor/Plugins/index.d.ts +0 -1
  116. package/dist/RichTextEditor/Plugins/index.js +0 -1
  117. package/dist/RichTextEditor/RichTextEditor.d.ts +2 -3
  118. package/dist/RichTextEditor/RichTextEditor.js +35 -302
  119. package/dist/RichTextEditor/Utils/codeBlockUtils.d.ts +20 -0
  120. package/dist/RichTextEditor/Utils/codeBlockUtils.js +137 -0
  121. package/dist/RichTextEditor/Utils/codeUtils.d.ts +3 -0
  122. package/dist/RichTextEditor/Utils/codeUtils.js +12 -0
  123. package/dist/RichTextEditor/Utils/linkUtils.d.ts +19 -0
  124. package/dist/RichTextEditor/Utils/linkUtils.js +57 -0
  125. package/dist/RichTextEditor/Utils/tableUtils.d.ts +1 -0
  126. package/dist/RichTextEditor/Utils/tableUtils.js +1 -0
  127. package/dist/SegmentedControl/SegmentedControl.utils.d.ts +2 -2
  128. package/dist/SegmentedControl/SegmentedControl.utils.js +30 -3
  129. package/dist/SelectBox/SelectBox.js +5 -5
  130. package/dist/SelectBox/select-box.styled-components.d.ts +1 -4
  131. package/dist/SelectBox/select-box.styled-components.js +48 -11
  132. package/dist/SelectBox/types.d.ts +0 -1
  133. package/dist/Switch/Switch.d.ts +2 -2
  134. package/dist/Switch/Switch.js +83 -18
  135. package/dist/Table/ColumnResizer.d.ts +9 -6
  136. package/dist/Table/ColumnResizer.js +10 -30
  137. package/dist/Table/StateStorage.d.ts +0 -4
  138. package/dist/Table/StateStorage.js +0 -13
  139. package/dist/Table/Table.js +12 -160
  140. package/dist/Table/TableComponents.d.ts +0 -10
  141. package/dist/Table/TableComponents.js +10 -71
  142. package/dist/Table/TableDefaults.d.ts +0 -7
  143. package/dist/Table/TableDefaults.js +0 -7
  144. package/dist/Table/TableHeader.js +16 -31
  145. package/dist/Table/TableMenu/TableMenu.js +1 -1
  146. package/dist/Table/TableProvider.js +75 -354
  147. package/dist/Table/TableRow.js +16 -28
  148. package/dist/Table/Utils/index.d.ts +1 -0
  149. package/dist/Table/Utils/index.js +1 -0
  150. package/dist/Table/types.d.ts +19 -70
  151. package/dist/TagBox/TagBox.d.ts +1 -1
  152. package/dist/TagBox/TagBox.js +80 -22
  153. package/dist/TagBox/types.d.ts +0 -1
  154. package/dist/TextArea/TextArea.js +23 -9
  155. package/dist/TextInput/TextInput.js +6 -12
  156. package/dist/Utilities/parseTimestamp.js +6 -11
  157. package/dist/core/ArrowButton.d.ts +0 -2
  158. package/dist/core/ArrowButton.js +3 -7
  159. package/dist/core/ClearButton.d.ts +0 -2
  160. package/dist/core/ClearButton.js +3 -7
  161. package/dist/core/controlSizes.js +9 -9
  162. package/dist/core/index.d.ts +0 -1
  163. package/dist/core/index.js +0 -1
  164. package/dist/index.d.ts +0 -3
  165. package/dist/index.js +0 -2
  166. package/dist/theme/variants.js +8 -2
  167. package/package.json +18 -26
  168. package/dist/DateTimeRangePicker/DateTimeRangePicker.d.ts +0 -41
  169. package/dist/DateTimeRangePicker/DateTimeRangePicker.js +0 -363
  170. package/dist/DateTimeRangePicker/index.d.ts +0 -2
  171. package/dist/DateTimeRangePicker/index.js +0 -2
@@ -0,0 +1,180 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { MoreHorizontalIcon, MoreVerticalIcon } from "lucide-react";
3
+ import { useCallback, useEffect, useRef, useState } from "react";
4
+ import { Button } from "../../../Button";
5
+ import { Popover } from "../../../Popover";
6
+ import { TableCornerMenu } from "./TableCornerMenu";
7
+ import { getColumnActionGroups, getRowActionGroups, } from "./TableTools.actions";
8
+ import { RAIL_HIDE_DELAY } from "./TableTools.constants";
9
+ import { getRailRect, getRailTargetFromCell } from "./TableTools.geometry";
10
+ import { MenuDropdown, RailRoot } from "./TableTools.styled";
11
+ import { getCellsInTableTarget, getCellsInTarget, hasTableExtension, } from "./TableTools.selectors";
12
+ import { TableToolMenu } from "./TableToolMenu";
13
+ export const TableRails = ({ editor }) => {
14
+ const [hoverTarget, setHoverTarget] = useState(null);
15
+ const [lockedTarget, setLockedTarget] = useState(null);
16
+ const [openRail, setOpenRail] = useState(null);
17
+ const hideTimerRef = useRef(null);
18
+ const lastPointerRef = useRef(null);
19
+ const activeTarget = openRail && lockedTarget ? lockedTarget : hoverTarget;
20
+ const clearHideTimer = useCallback(() => {
21
+ if (hideTimerRef.current) {
22
+ clearTimeout(hideTimerRef.current);
23
+ hideTimerRef.current = null;
24
+ }
25
+ }, []);
26
+ const clearTarget = useCallback(() => {
27
+ var _a;
28
+ clearHideTimer();
29
+ if (!openRail) {
30
+ const pointer = lastPointerRef.current;
31
+ const element = pointer
32
+ ? document.elementFromPoint(pointer.x, pointer.y)
33
+ : null;
34
+ if ((_a = element === null || element === void 0 ? void 0 : element.closest) === null || _a === void 0 ? void 0 : _a.call(element, "[data-monolith-table-rail]")) {
35
+ return;
36
+ }
37
+ setHoverTarget(null);
38
+ }
39
+ }, [clearHideTimer, openRail]);
40
+ const scheduleClearTarget = useCallback(() => {
41
+ clearHideTimer();
42
+ hideTimerRef.current = setTimeout(clearTarget, RAIL_HIDE_DELAY);
43
+ }, [clearHideTimer, clearTarget]);
44
+ const refreshTargetFromPoint = useCallback(() => {
45
+ var _a, _b;
46
+ if (!editor || !lastPointerRef.current) {
47
+ setHoverTarget(null);
48
+ return;
49
+ }
50
+ const element = document.elementFromPoint(lastPointerRef.current.x, lastPointerRef.current.y);
51
+ if ((_a = element === null || element === void 0 ? void 0 : element.closest) === null || _a === void 0 ? void 0 : _a.call(element, "[data-monolith-table-rail]")) {
52
+ return;
53
+ }
54
+ const cell = (_b = element === null || element === void 0 ? void 0 : element.closest) === null || _b === void 0 ? void 0 : _b.call(element, "td, th");
55
+ if (cell instanceof HTMLTableCellElement &&
56
+ editor.view.dom.contains(cell)) {
57
+ const target = getRailTargetFromCell(editor, cell);
58
+ setHoverTarget(target);
59
+ return;
60
+ }
61
+ setHoverTarget(null);
62
+ }, [editor]);
63
+ const closeMenu = useCallback(() => {
64
+ setOpenRail(null);
65
+ setLockedTarget(null);
66
+ requestAnimationFrame(refreshTargetFromPoint);
67
+ }, [refreshTargetFromPoint]);
68
+ useEffect(() => {
69
+ if (!editor || !hasTableExtension(editor))
70
+ return;
71
+ const handleMouseMove = (event) => {
72
+ var _a, _b;
73
+ const target = event.target;
74
+ const cell = (_a = target === null || target === void 0 ? void 0 : target.closest) === null || _a === void 0 ? void 0 : _a.call(target, "td, th");
75
+ lastPointerRef.current = { x: event.clientX, y: event.clientY };
76
+ if ((_b = target === null || target === void 0 ? void 0 : target.closest) === null || _b === void 0 ? void 0 : _b.call(target, "[data-monolith-table-rail]")) {
77
+ clearHideTimer();
78
+ return;
79
+ }
80
+ if (openRail) {
81
+ clearHideTimer();
82
+ return;
83
+ }
84
+ if (!(cell instanceof HTMLTableCellElement) ||
85
+ !editor.view.dom.contains(cell)) {
86
+ if (!openRail) {
87
+ scheduleClearTarget();
88
+ }
89
+ return;
90
+ }
91
+ const railTarget = getRailTargetFromCell(editor, cell);
92
+ if (railTarget) {
93
+ clearHideTimer();
94
+ setHoverTarget(railTarget);
95
+ }
96
+ };
97
+ const handleMouseLeave = () => {
98
+ if (!openRail) {
99
+ scheduleClearTarget();
100
+ }
101
+ };
102
+ editor.view.dom.addEventListener("mousemove", handleMouseMove);
103
+ editor.view.dom.addEventListener("mouseleave", handleMouseLeave);
104
+ window.addEventListener("mousemove", handleMouseMove);
105
+ window.addEventListener("scroll", refreshTargetFromPoint, true);
106
+ window.addEventListener("resize", refreshTargetFromPoint);
107
+ return () => {
108
+ editor.view.dom.removeEventListener("mousemove", handleMouseMove);
109
+ editor.view.dom.removeEventListener("mouseleave", handleMouseLeave);
110
+ window.removeEventListener("mousemove", handleMouseMove);
111
+ window.removeEventListener("scroll", refreshTargetFromPoint, true);
112
+ window.removeEventListener("resize", refreshTargetFromPoint);
113
+ clearHideTimer();
114
+ };
115
+ }, [
116
+ clearHideTimer,
117
+ editor,
118
+ openRail,
119
+ refreshTargetFromPoint,
120
+ scheduleClearTarget,
121
+ ]);
122
+ useEffect(() => {
123
+ const highlighted = Array.from(document.querySelectorAll(".monolith-table-rail-target"));
124
+ highlighted.forEach((element) => element.classList.remove("monolith-table-rail-target"));
125
+ if (!activeTarget || !openRail)
126
+ return;
127
+ const cells = openRail === "table"
128
+ ? getCellsInTableTarget(activeTarget)
129
+ : getCellsInTarget(Object.assign(Object.assign({}, activeTarget), { kind: openRail }));
130
+ cells.forEach((cell) => {
131
+ const dom = editor === null || editor === void 0 ? void 0 : editor.view.nodeDOM(activeTarget.tableContext.start + cell.pos);
132
+ if (dom instanceof HTMLElement) {
133
+ dom.classList.add("monolith-table-rail-target");
134
+ }
135
+ });
136
+ return () => {
137
+ cells.forEach((cell) => {
138
+ const dom = editor === null || editor === void 0 ? void 0 : editor.view.nodeDOM(activeTarget.tableContext.start + cell.pos);
139
+ if (dom instanceof HTMLElement) {
140
+ dom.classList.remove("monolith-table-rail-target");
141
+ }
142
+ });
143
+ };
144
+ }, [activeTarget, editor, openRail]);
145
+ const keepEditorSelection = (event) => {
146
+ event.preventDefault();
147
+ };
148
+ if (!activeTarget || !(editor === null || editor === void 0 ? void 0 : editor.isEditable))
149
+ return null;
150
+ const keepTargetVisible = () => {
151
+ clearHideTimer();
152
+ };
153
+ const scheduleTargetClearIfClosed = () => {
154
+ if (!openRail) {
155
+ scheduleClearTarget();
156
+ }
157
+ };
158
+ const renderRail = (kind) => {
159
+ const railTarget = Object.assign(Object.assign({}, activeTarget), { kind });
160
+ const groups = kind === "column"
161
+ ? getColumnActionGroups(editor, railTarget)
162
+ : getRowActionGroups(editor, railTarget);
163
+ return (_jsx(RailRoot, { "data-monolith-table-rail": true, "$kind": kind, "$rect": getRailRect(activeTarget, kind), onMouseEnter: keepTargetVisible, onMouseLeave: scheduleTargetClearIfClosed, children: _jsxs(Popover, { opened: openRail === kind, onChange: (opened) => {
164
+ if (opened) {
165
+ clearHideTimer();
166
+ setLockedTarget(railTarget);
167
+ setOpenRail(kind);
168
+ return;
169
+ }
170
+ setOpenRail(null);
171
+ setLockedTarget(null);
172
+ refreshTargetFromPoint();
173
+ }, position: kind === "column" ? "bottom" : "right", width: 245, trapFocus: true, children: [_jsx(Popover.Target, { children: _jsx(Button, { type: "button", size: "xs", variant: "outlined", title: kind === "column" ? "Column options" : "Row options", "aria-label": kind === "column" ? "Column options" : "Row options", selected: openRail === kind, onMouseDown: keepEditorSelection, children: kind === "column" ? (_jsx(MoreHorizontalIcon, { size: 14 })) : (_jsx(MoreVerticalIcon, { size: 14 })) }) }), _jsx(MenuDropdown, { children: _jsx(TableToolMenu, { groups: groups, onAction: closeMenu }) })] }) }, kind));
174
+ };
175
+ return (_jsxs(_Fragment, { children: [_jsx(TableCornerMenu, { editor: editor, target: activeTarget, opened: openRail === "table", onOpen: () => {
176
+ clearHideTimer();
177
+ setLockedTarget(activeTarget);
178
+ setOpenRail("table");
179
+ }, onClose: closeMenu, onAction: closeMenu, onMouseEnter: keepTargetVisible, onMouseLeave: scheduleTargetClearIfClosed, onMouseDown: keepEditorSelection }), renderRail("column"), renderRail("row")] }));
180
+ };
@@ -0,0 +1,5 @@
1
+ import type { TableToolActionGroup } from "./TableTools.types";
2
+ export declare const TableToolMenu: ({ groups, onAction, }: {
3
+ groups: TableToolActionGroup[];
4
+ onAction: () => void;
5
+ }) => import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,6 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { MenuButton, MenuGroup, MenuPanel } from "./TableTools.styled";
3
+ export const TableToolMenu = ({ groups, onAction, }) => (_jsx(MenuPanel, { children: groups.map((group, index) => (_jsx(MenuGroup, { "$withDivider": index > 0, children: group.actions.map((action) => (_jsx(MenuButton, { "$danger": action.danger, size: "sm", variant: "subtle", leftSection: action.leftSection, disabled: action.disabled, justify: "start", onClick: () => {
4
+ action.onClick();
5
+ onAction();
6
+ }, children: action.label }, action.label))) }, group.label))) }));
@@ -0,0 +1,5 @@
1
+ import type { Editor } from "@tiptap/react";
2
+ import type { RailTarget, TableRailTarget, TableToolActionGroup } from "./TableTools.types";
3
+ export declare const getColumnActionGroups: (editor: Editor | null, target: RailTarget) => TableToolActionGroup[];
4
+ export declare const getRowActionGroups: (editor: Editor | null, target: RailTarget) => TableToolActionGroup[];
5
+ export declare const getTableActionGroups: (editor: Editor | null, target: TableRailTarget) => TableToolActionGroup[];
@@ -0,0 +1,183 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { ArrowDownToLineIcon, ArrowLeftToLineIcon, ArrowRightToLineIcon, ArrowUpToLineIcon, CopyIcon, EraserIcon, MoveDownIcon, MoveLeftIcon, MoveRightIcon, MoveUpIcon, PanelTopIcon, Trash2Icon, } from "lucide-react";
3
+ import { clearTableContents, clearTargetContents, deleteColumnAt, deleteRowAt, deleteTable, duplicateColumn, duplicateRow, duplicateTable, insertColumnAt, insertRowAt, moveColumn, moveRow, toggleTopHeaderRow, } from "./TableTools.commands";
4
+ import { getTopRowIsHeader, hasRiskyMergedCells } from "./TableTools.selectors";
5
+ export const getColumnActionGroups = (editor, target) => {
6
+ const risky = hasRiskyMergedCells(target);
7
+ const lastColumn = target.tableContext.map.width - 1;
8
+ return [
9
+ {
10
+ label: "Move",
11
+ actions: [
12
+ {
13
+ label: "Move column left",
14
+ leftSection: _jsx(MoveLeftIcon, { size: 14 }),
15
+ disabled: risky || target.colIndex === 0,
16
+ onClick: () => moveColumn(editor, target, -1),
17
+ },
18
+ {
19
+ label: "Move column right",
20
+ leftSection: _jsx(MoveRightIcon, { size: 14 }),
21
+ disabled: risky || target.colIndex === lastColumn,
22
+ onClick: () => moveColumn(editor, target, 1),
23
+ },
24
+ ],
25
+ },
26
+ {
27
+ label: "Insert",
28
+ actions: [
29
+ {
30
+ label: "Insert column left",
31
+ leftSection: _jsx(ArrowLeftToLineIcon, { size: 14 }),
32
+ onClick: () => insertColumnAt(editor, target, target.colIndex),
33
+ },
34
+ {
35
+ label: "Insert column right",
36
+ leftSection: _jsx(ArrowRightToLineIcon, { size: 14 }),
37
+ onClick: () => insertColumnAt(editor, target, target.colIndex + 1),
38
+ },
39
+ ],
40
+ },
41
+ {
42
+ label: "Content",
43
+ actions: [
44
+ {
45
+ label: "Clear column contents",
46
+ leftSection: _jsx(EraserIcon, { size: 14 }),
47
+ disabled: risky,
48
+ onClick: () => clearTargetContents(editor, target),
49
+ },
50
+ {
51
+ label: "Duplicate column",
52
+ leftSection: _jsx(CopyIcon, { size: 14 }),
53
+ disabled: risky,
54
+ onClick: () => duplicateColumn(editor, target),
55
+ },
56
+ ],
57
+ },
58
+ {
59
+ label: "Delete",
60
+ actions: [
61
+ {
62
+ label: "Delete column",
63
+ leftSection: _jsx(Trash2Icon, { size: 14 }),
64
+ danger: true,
65
+ disabled: risky || target.tableContext.map.width <= 1,
66
+ onClick: () => deleteColumnAt(editor, target),
67
+ },
68
+ ],
69
+ },
70
+ ];
71
+ };
72
+ export const getRowActionGroups = (editor, target) => {
73
+ const risky = hasRiskyMergedCells(target);
74
+ const topRowIsHeader = getTopRowIsHeader(target);
75
+ const lastRow = target.tableContext.map.height - 1;
76
+ return [
77
+ {
78
+ label: "Header",
79
+ actions: [
80
+ {
81
+ label: topRowIsHeader ? "Unset header row" : "Set header row",
82
+ leftSection: _jsx(PanelTopIcon, { size: 14 }),
83
+ disabled: target.rowIndex !== 0,
84
+ onClick: () => toggleTopHeaderRow(editor, target),
85
+ },
86
+ ],
87
+ },
88
+ {
89
+ label: "Move",
90
+ actions: [
91
+ {
92
+ label: "Move row up",
93
+ leftSection: _jsx(MoveUpIcon, { size: 14 }),
94
+ disabled: risky ||
95
+ target.rowIndex === 0 ||
96
+ (topRowIsHeader && target.rowIndex === 1),
97
+ onClick: () => moveRow(editor, target, -1),
98
+ },
99
+ {
100
+ label: "Move row down",
101
+ leftSection: _jsx(MoveDownIcon, { size: 14 }),
102
+ disabled: risky ||
103
+ target.rowIndex === lastRow ||
104
+ (topRowIsHeader && target.rowIndex === 0),
105
+ onClick: () => moveRow(editor, target, 1),
106
+ },
107
+ ],
108
+ },
109
+ {
110
+ label: "Insert",
111
+ actions: [
112
+ {
113
+ label: "Insert row above",
114
+ leftSection: _jsx(ArrowUpToLineIcon, { size: 14 }),
115
+ disabled: topRowIsHeader && target.rowIndex === 0,
116
+ onClick: () => insertRowAt(editor, target, target.rowIndex),
117
+ },
118
+ {
119
+ label: "Insert row below",
120
+ leftSection: _jsx(ArrowDownToLineIcon, { size: 14 }),
121
+ onClick: () => insertRowAt(editor, target, target.rowIndex + 1),
122
+ },
123
+ ],
124
+ },
125
+ {
126
+ label: "Content",
127
+ actions: [
128
+ {
129
+ label: "Clear row contents",
130
+ leftSection: _jsx(EraserIcon, { size: 14 }),
131
+ disabled: risky,
132
+ onClick: () => clearTargetContents(editor, target),
133
+ },
134
+ {
135
+ label: "Duplicate row",
136
+ leftSection: _jsx(CopyIcon, { size: 14 }),
137
+ disabled: risky,
138
+ onClick: () => duplicateRow(editor, target),
139
+ },
140
+ ],
141
+ },
142
+ {
143
+ label: "Delete",
144
+ actions: [
145
+ {
146
+ label: "Delete row",
147
+ leftSection: _jsx(Trash2Icon, { size: 14 }),
148
+ danger: true,
149
+ disabled: risky || target.tableContext.map.height <= 1,
150
+ onClick: () => deleteRowAt(editor, target),
151
+ },
152
+ ],
153
+ },
154
+ ];
155
+ };
156
+ export const getTableActionGroups = (editor, target) => [
157
+ {
158
+ label: "Content",
159
+ actions: [
160
+ {
161
+ label: "Clear table contents",
162
+ leftSection: _jsx(EraserIcon, { size: 14 }),
163
+ onClick: () => clearTableContents(editor, target),
164
+ },
165
+ {
166
+ label: "Duplicate table",
167
+ leftSection: _jsx(CopyIcon, { size: 14 }),
168
+ onClick: () => duplicateTable(editor, target),
169
+ },
170
+ ],
171
+ },
172
+ {
173
+ label: "Delete",
174
+ actions: [
175
+ {
176
+ label: "Delete table",
177
+ leftSection: _jsx(Trash2Icon, { size: 14 }),
178
+ danger: true,
179
+ onClick: () => deleteTable(editor, target),
180
+ },
181
+ ],
182
+ },
183
+ ];
@@ -0,0 +1,16 @@
1
+ import type { Editor } from "@tiptap/react";
2
+ import type { RailTarget, TableRailTarget } from "./TableTools.types";
3
+ export declare const runTableCommand: (editor: Editor | null, command: string, args?: unknown[]) => void;
4
+ export declare const insertRowAt: (editor: Editor | null, target: RailTarget, row: number) => boolean;
5
+ export declare const insertColumnAt: (editor: Editor | null, target: RailTarget, column: number) => boolean;
6
+ export declare const deleteRowAt: (editor: Editor | null, target: RailTarget) => boolean;
7
+ export declare const deleteColumnAt: (editor: Editor | null, target: RailTarget) => boolean;
8
+ export declare const clearTargetContents: (editor: Editor | null, target: RailTarget) => boolean;
9
+ export declare const duplicateRow: (editor: Editor | null, target: RailTarget) => boolean;
10
+ export declare const duplicateColumn: (editor: Editor | null, target: RailTarget) => boolean;
11
+ export declare const moveRow: (editor: Editor | null, target: RailTarget, direction: -1 | 1) => boolean;
12
+ export declare const moveColumn: (editor: Editor | null, target: RailTarget, direction: -1 | 1) => boolean;
13
+ export declare const toggleTopHeaderRow: (editor: Editor | null, target: RailTarget) => boolean;
14
+ export declare const clearTableContents: (editor: Editor | null, target: TableRailTarget) => boolean;
15
+ export declare const duplicateTable: (editor: Editor | null, target: TableRailTarget) => boolean;
16
+ export declare const deleteTable: (editor: Editor | null, target: TableRailTarget) => boolean;
@@ -0,0 +1,217 @@
1
+ import { Fragment } from "@tiptap/pm/model";
2
+ import { TextSelection } from "@tiptap/pm/state";
3
+ import { addColumn, addRow, removeColumn, removeRow } from "@tiptap/pm/tables";
4
+ import { getCellsInTableTarget, getCellsInTarget, getTopRowIsHeader, } from "./TableTools.selectors";
5
+ export const runTableCommand = (editor, command, args = []) => {
6
+ const chain = editor === null || editor === void 0 ? void 0 : editor.chain().focus();
7
+ if (!(chain === null || chain === void 0 ? void 0 : chain[command]))
8
+ return;
9
+ chain[command](...args).run();
10
+ };
11
+ const getTableRect = (tableContext) => ({
12
+ left: 0,
13
+ top: 0,
14
+ right: tableContext.map.width,
15
+ bottom: tableContext.map.height,
16
+ tableStart: tableContext.start,
17
+ map: tableContext.map,
18
+ table: tableContext.node,
19
+ });
20
+ const getRowStartOffset = (table, rowIndex) => {
21
+ let offset = 0;
22
+ for (let index = 0; index < rowIndex; index += 1) {
23
+ offset += table.child(index).nodeSize;
24
+ }
25
+ return offset;
26
+ };
27
+ const getCellChildIndex = (table, rowIndex, cellPos) => {
28
+ const row = table.child(rowIndex);
29
+ let offset = getRowStartOffset(table, rowIndex) + 1;
30
+ for (let index = 0; index < row.childCount; index += 1) {
31
+ if (offset === cellPos)
32
+ return index;
33
+ offset += row.child(index).nodeSize;
34
+ }
35
+ return -1;
36
+ };
37
+ export const insertRowAt = (editor, target, row) => {
38
+ if (!editor)
39
+ return false;
40
+ editor.view.dispatch(addRow(editor.state.tr, getTableRect(target.tableContext), row));
41
+ return true;
42
+ };
43
+ export const insertColumnAt = (editor, target, column) => {
44
+ if (!editor)
45
+ return false;
46
+ editor.view.dispatch(addColumn(editor.state.tr, getTableRect(target.tableContext), column));
47
+ return true;
48
+ };
49
+ export const deleteRowAt = (editor, target) => {
50
+ if (!editor || target.tableContext.map.height <= 1)
51
+ return false;
52
+ const tr = editor.state.tr;
53
+ removeRow(tr, getTableRect(target.tableContext), target.rowIndex);
54
+ editor.view.dispatch(tr);
55
+ return true;
56
+ };
57
+ export const deleteColumnAt = (editor, target) => {
58
+ if (!editor || target.tableContext.map.width <= 1)
59
+ return false;
60
+ const tr = editor.state.tr;
61
+ removeColumn(tr, getTableRect(target.tableContext), target.colIndex);
62
+ editor.view.dispatch(tr);
63
+ return true;
64
+ };
65
+ export const clearTargetContents = (editor, target) => {
66
+ if (!editor)
67
+ return false;
68
+ const paragraph = editor.state.schema.nodes.paragraph.createAndFill();
69
+ if (!paragraph)
70
+ return false;
71
+ const tr = editor.state.tr;
72
+ const cells = getCellsInTarget(target).sort((a, b) => b.pos - a.pos);
73
+ cells.forEach((cell) => {
74
+ const from = target.tableContext.start + cell.pos + 1;
75
+ const to = target.tableContext.start + cell.pos + cell.node.nodeSize - 1;
76
+ tr.replaceWith(from, to, paragraph);
77
+ });
78
+ editor.view.dispatch(tr);
79
+ return true;
80
+ };
81
+ export const duplicateRow = (editor, target) => {
82
+ if (!editor)
83
+ return false;
84
+ const row = target.tableContext.node.child(target.rowIndex);
85
+ const insertPosition = target.tableContext.start +
86
+ getRowStartOffset(target.tableContext.node, target.rowIndex + 1);
87
+ editor.view.dispatch(editor.state.tr.insert(insertPosition, row.copy(row.content)));
88
+ return true;
89
+ };
90
+ export const duplicateColumn = (editor, target) => {
91
+ if (!editor)
92
+ return false;
93
+ const tr = editor.state.tr;
94
+ const inserts = [];
95
+ for (let row = 0; row < target.tableContext.map.height; row += 1) {
96
+ const cellPos = target.tableContext.map.positionAt(row, target.colIndex, target.tableContext.node);
97
+ const cell = target.tableContext.node.nodeAt(cellPos);
98
+ if (cell) {
99
+ inserts.push({
100
+ pos: target.tableContext.start + cellPos + cell.nodeSize,
101
+ node: cell.copy(cell.content),
102
+ });
103
+ }
104
+ }
105
+ inserts
106
+ .sort((a, b) => b.pos - a.pos)
107
+ .forEach((insert) => tr.insert(insert.pos, insert.node));
108
+ editor.view.dispatch(tr);
109
+ return true;
110
+ };
111
+ export const moveRow = (editor, target, direction) => {
112
+ if (!editor)
113
+ return false;
114
+ const to = target.rowIndex + direction;
115
+ if (to < 0 || to >= target.tableContext.map.height)
116
+ return false;
117
+ const rows = [];
118
+ target.tableContext.node.forEach((row) => {
119
+ rows.push(row);
120
+ });
121
+ const [row] = rows.splice(target.rowIndex, 1);
122
+ rows.splice(to, 0, row);
123
+ const nextTable = target.tableContext.node.copy(Fragment.from(rows));
124
+ editor.view.dispatch(editor.state.tr.replaceWith(target.tableContext.pos, target.tableContext.pos + target.tableContext.node.nodeSize, nextTable));
125
+ return true;
126
+ };
127
+ export const moveColumn = (editor, target, direction) => {
128
+ if (!editor)
129
+ return false;
130
+ const to = target.colIndex + direction;
131
+ if (to < 0 || to >= target.tableContext.map.width)
132
+ return false;
133
+ const rows = [];
134
+ for (let row = 0; row < target.tableContext.map.height; row += 1) {
135
+ const rowNode = target.tableContext.node.child(row);
136
+ const cells = [];
137
+ const cellPos = target.tableContext.map.positionAt(row, target.colIndex, target.tableContext.node);
138
+ const cellIndex = getCellChildIndex(target.tableContext.node, row, cellPos);
139
+ rowNode.forEach((cell) => {
140
+ cells.push(cell);
141
+ });
142
+ if (cellIndex < 0) {
143
+ rows.push(rowNode);
144
+ continue;
145
+ }
146
+ const [cell] = cells.splice(cellIndex, 1);
147
+ const insertIndex = direction > 0 ? cellIndex + 1 : cellIndex - 1;
148
+ cells.splice(insertIndex, 0, cell);
149
+ rows.push(rowNode.copy(Fragment.from(cells)));
150
+ }
151
+ const nextTable = target.tableContext.node.copy(Fragment.from(rows));
152
+ editor.view.dispatch(editor.state.tr.replaceWith(target.tableContext.pos, target.tableContext.pos + target.tableContext.node.nodeSize, nextTable));
153
+ return true;
154
+ };
155
+ export const toggleTopHeaderRow = (editor, target) => {
156
+ if (!editor || target.rowIndex !== 0)
157
+ return false;
158
+ const headerType = editor.state.schema.nodes.tableHeader;
159
+ const cellType = editor.state.schema.nodes.tableCell;
160
+ if (!headerType || !cellType)
161
+ return false;
162
+ const makeHeader = !getTopRowIsHeader(target);
163
+ const tr = editor.state.tr;
164
+ const cells = getCellsInTarget(target);
165
+ cells.forEach((cell) => {
166
+ tr.setNodeMarkup(target.tableContext.start + cell.pos, makeHeader ? headerType : cellType, cell.node.attrs);
167
+ });
168
+ editor.view.dispatch(tr);
169
+ return true;
170
+ };
171
+ export const clearTableContents = (editor, target) => {
172
+ if (!editor)
173
+ return false;
174
+ const paragraph = editor.state.schema.nodes.paragraph.createAndFill();
175
+ if (!paragraph)
176
+ return false;
177
+ const tr = editor.state.tr;
178
+ const cells = getCellsInTableTarget(target).sort((a, b) => b.pos - a.pos);
179
+ cells.forEach((cell) => {
180
+ const from = target.tableContext.start + cell.pos + 1;
181
+ const to = target.tableContext.start + cell.pos + cell.node.nodeSize - 1;
182
+ tr.replaceWith(from, to, paragraph);
183
+ });
184
+ editor.view.dispatch(tr);
185
+ return true;
186
+ };
187
+ export const duplicateTable = (editor, target) => {
188
+ if (!editor)
189
+ return false;
190
+ const { tableContext } = target;
191
+ const paragraph = editor.state.schema.nodes.paragraph.createAndFill();
192
+ if (!paragraph)
193
+ return false;
194
+ const insertPosition = tableContext.pos + tableContext.node.nodeSize;
195
+ const duplicatedTable = tableContext.node.copy(tableContext.node.content);
196
+ const tr = editor.state.tr.insert(insertPosition, [
197
+ paragraph,
198
+ duplicatedTable,
199
+ ]);
200
+ const firstCellPosition = tableContext.map.positionAt(0, 0, duplicatedTable);
201
+ if (firstCellPosition !== null) {
202
+ const duplicatePosition = insertPosition + paragraph.nodeSize;
203
+ const firstCellContentPosition = duplicatePosition + 1 + firstCellPosition + 1;
204
+ tr.setSelection(TextSelection.near(tr.doc.resolve(firstCellContentPosition)));
205
+ }
206
+ editor.view.dispatch(tr.scrollIntoView());
207
+ return true;
208
+ };
209
+ export const deleteTable = (editor, target) => {
210
+ if (!editor)
211
+ return false;
212
+ const { tableContext } = target;
213
+ editor.view.dispatch(editor.state.tr
214
+ .delete(tableContext.pos, tableContext.pos + tableContext.node.nodeSize)
215
+ .scrollIntoView());
216
+ return true;
217
+ };
@@ -0,0 +1,8 @@
1
+ import type { TableInsertOptions } from "./TableTools.types";
2
+ export declare const DEFAULT_TABLE_OPTIONS: TableInsertOptions;
3
+ export declare const MIN_TABLE_SIZE = 1;
4
+ export declare const MAX_TABLE_SIZE = 20;
5
+ export declare const RAIL_THICKNESS = 8;
6
+ export declare const RAIL_HIDE_DELAY = 250;
7
+ export declare const VIEWPORT_PADDING = 8;
8
+ export declare const CORNER_BUTTON_SIZE = 18;
@@ -0,0 +1,11 @@
1
+ export const DEFAULT_TABLE_OPTIONS = {
2
+ rows: 3,
3
+ cols: 3,
4
+ withHeaderRow: true,
5
+ };
6
+ export const MIN_TABLE_SIZE = 1;
7
+ export const MAX_TABLE_SIZE = 20;
8
+ export const RAIL_THICKNESS = 8;
9
+ export const RAIL_HIDE_DELAY = 250;
10
+ export const VIEWPORT_PADDING = 8;
11
+ export const CORNER_BUTTON_SIZE = 18;
@@ -0,0 +1,3 @@
1
+ export { TableRails } from "./TableRails";
2
+ export { TableToolsContent } from "./TableInsertControls";
3
+ export { TableToolsPopover } from "./TableToolsPopover";
@@ -0,0 +1,23 @@
1
+ import { TableMap } from "@tiptap/pm/tables";
2
+ import type { Editor } from "@tiptap/react";
3
+ import type { RailKind, RailRect, RailTarget, TableRailTarget } from "./TableTools.types";
4
+ export declare const getRailTargetFromCell: (editor: Editor, cell: HTMLTableCellElement) => {
5
+ kind: RailKind;
6
+ rowIndex: number;
7
+ colIndex: number;
8
+ tableElement: HTMLTableElement;
9
+ tableRect: RailRect;
10
+ tableContext: {
11
+ node: import("prosemirror-model").Node;
12
+ pos: number;
13
+ start: number;
14
+ map: TableMap;
15
+ };
16
+ rowRect: RailRect;
17
+ columnRect: RailRect;
18
+ } | null;
19
+ export declare const getRailRect: (target: RailTarget, kind: RailKind) => RailRect;
20
+ export declare const getCornerRect: (target: TableRailTarget) => {
21
+ top: number;
22
+ left: number;
23
+ };