Skip to content

Commit 70d0b8b

Browse files
authored
Rhino horizontal rule (#619)
* remove shift click * add Horizontal rule package and button to editor
1 parent 1367b2a commit 70d0b8b

File tree

4 files changed

+71
-73
lines changed

4 files changed

+71
-73
lines changed

app/frontend/javascript/rhino/custom-editor.js

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ class CustomEditor extends TipTapEditor {
4949
<slot name="heading-button">${this.renderHeadingButton()}</slot>
5050
<slot name="after-heading-button"></slot>
5151
52+
<slot name="hr-button">${this.renderHorizontalRuleButton()}</slot>
53+
5254
<!-- Blockquote -->
5355
<slot name="before-blockquote-button"></slot>
5456
<slot name="blockquote-button">${this.renderBlockquoteButton()}</slot>
@@ -148,42 +150,10 @@ class CustomEditor extends TipTapEditor {
148150
<button
149151
type="button"
150152
class="toolbar__button rhino-toolbar-button"
151-
title="Insert grid (Shift + click to enter custom dimensions)"
152-
@click=${(event) => {
153-
this.editor.chain().focus();
154-
155-
if (event.shiftKey) {
156-
// Prompt user for custom dimensions
157-
const input = prompt(
158-
"Enter grid dimensions as columns,rows (e.g., 2,4):",
159-
"2,2",
160-
);
161-
if (!input) return;
162-
163-
const [colsStr, rowsStr] = input.split(",");
164-
const columns = parseInt(colsStr.trim(), 10);
165-
const rows = parseInt(rowsStr.trim(), 10);
166-
167-
if (
168-
isNaN(rows) ||
169-
isNaN(columns) ||
170-
rows <= 0 ||
171-
columns <= 0 ||
172-
rows > 6 ||
173-
columns > 6
174-
) {
175-
alert(
176-
"Invalid dimensions! Rows and columns must be between 1 and 6.",
177-
);
178-
return;
179-
}
180-
181-
this.editor.chain().insertGrid(columns, rows).run();
182-
} else {
183-
// Default grid insertion
184-
this.editor.chain().insertGrid().run();
185-
}
186-
}}
153+
title="Insert grid"
154+
@click="${(event) => {
155+
this.editor.chain().focus().insertGrid().run();
156+
}}"
187157
>
188158
<slot name="table-tooltip">
189159
<role-tooltip
@@ -200,6 +170,31 @@ class CustomEditor extends TipTapEditor {
200170
`;
201171
}
202172

173+
renderHorizontalRuleButton() {
174+
return html`
175+
<button
176+
class="toolbar__button rhino-toolbar-button"
177+
type="button"
178+
aria-describedby="horizontal rule"
179+
data-role="toolbar-item"
180+
@click="${(event) => {
181+
this.editor.chain().focus().setHorizontalRule().run();
182+
}}"
183+
>
184+
<slot name="table-tooltip">
185+
<role-tooltip
186+
id="horiztaon-rule"
187+
hoist
188+
part="toolbar-tooltip toolbar-tooltip__table"
189+
exportparts=${this.__tooltipExportParts}
190+
>
191+
Horizontal Rule
192+
</role-tooltip>
193+
</slot>
194+
<slot name="table-icon">---</slot>
195+
</button>
196+
`;
197+
}
203198
renderTableButton() {
204199
const tableEnabled = true; // Boolean(this.editor?.commands.setAttachment);
205200

Lines changed: 26 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,32 @@
1-
import "./custom-editor.js"
2-
import "./custom-editor.css"
3-
import { Table } from '@tiptap/extension-table'
4-
import { TableCell } from '@tiptap/extension-table-cell'
5-
import { TableHeader } from '@tiptap/extension-table-header'
6-
import { TableRow } from '@tiptap/extension-table-row'
7-
import Youtube from '@tiptap/extension-youtube'
8-
import TextAlign from '@tiptap/extension-text-align'
9-
import { Grid } from './grid/grid'
10-
import { GridCell } from './grid/gridCell'
1+
import "./custom-editor.js";
2+
import "./custom-editor.css";
3+
import { Table } from "@tiptap/extension-table";
4+
import { TableCell } from "@tiptap/extension-table-cell";
5+
import { TableHeader } from "@tiptap/extension-table-header";
6+
import { TableRow } from "@tiptap/extension-table-row";
7+
import Youtube from "@tiptap/extension-youtube";
8+
import TextAlign from "@tiptap/extension-text-align";
9+
import { Grid } from "./grid/grid";
10+
import { GridCell } from "./grid/gridCell";
11+
import HorizontalRule from "@tiptap/extension-horizontal-rule";
1112

1213
function extendRhinoEditor(event) {
13-
const rhinoEditor = event.target
14-
if (!rhinoEditor) return
14+
const rhinoEditor = event.target;
15+
if (!rhinoEditor) return;
1516

1617
rhinoEditor.addExtensions(
17-
Table,
18-
TableRow,
19-
TableHeader,
20-
TableCell,
21-
Youtube.configure({ nocookie: true }),
22-
TextAlign.configure({
23-
types: ['heading', 'paragraph'],
24-
}),
25-
Grid,
26-
GridCell
27-
)
18+
Table,
19+
TableRow,
20+
TableHeader,
21+
TableCell,
22+
Youtube.configure({ nocookie: true }),
23+
TextAlign.configure({
24+
types: ["heading", "paragraph"],
25+
}),
26+
Grid,
27+
GridCell,
28+
HorizontalRule,
29+
);
2830
}
2931

30-
document.addEventListener("rhino-before-initialize", extendRhinoEditor)
31-
32+
document.addEventListener("rhino-before-initialize", extendRhinoEditor);

package-lock.json

Lines changed: 13 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"@rails/actiontext": "^8.1.100",
1212
"@rails/request.js": "^0.0.12",
1313
"@tailwindcss/vite": "^4.1.13",
14+
"@tiptap/extension-horizontal-rule": "^3.14.0",
1415
"@tiptap/extension-table": "^3.13.0",
1516
"@tiptap/extension-table-cell": "^3.13.0",
1617
"@tiptap/extension-table-header": "^3.13.0",

0 commit comments

Comments
 (0)