From 199b54b33a864017b9276558f3ffd43292986ce6 Mon Sep 17 00:00:00 2001
From: Federico Brigante <me@fregante.com>
Date: Thu, 2 Nov 2023 02:12:05 +0800
Subject: `table-input` - Restore feature (#7022)

---
 source/features/table-input.tsx | 51 ++++++++++++++++++++++++++++++++++++++---
 1 file changed, 48 insertions(+), 3 deletions(-)

(limited to 'source/features/table-input.tsx')

diff --git a/source/features/table-input.tsx b/source/features/table-input.tsx
index 3dd2cced..c90c462f 100644
--- a/source/features/table-input.tsx
+++ b/source/features/table-input.tsx
@@ -5,6 +5,8 @@ import * as pageDetect from 'github-url-detection';
 import * as textFieldEdit from 'text-field-edit';
 import delegate, {DelegateEvent} from 'delegate-it';
 
+import {elementExists} from 'select-dom';
+
 import features from '../feature-manager.js';
 import smartBlockWrap from '../helpers/smart-block-wrap.js';
 import observe from '../helpers/selector-observer.js';
@@ -39,10 +41,42 @@ function highlightSquares({delegateTarget: hover}: DelegateEvent<MouseEvent, HTM
 }
 
 function add(anchor: HTMLElement): void {
+	const wrapperClasses = [
+		'details-reset',
+		'details-overlay',
+		'flex-auto',
+		'select-menu',
+		'select-menu-modal-right',
+		'hx_rsm',
+	];
+	if (elementExists('md-ref', anchor)) {
+		wrapperClasses.push(
+			'toolbar-item',
+			'btn-octicon',
+			'mx-1',
+		);
+	}
+
+	const buttonClasses
+	= elementExists('md-ref', anchor)
+		? [
+			'text-center',
+			'menu-target',
+			'p-2',
+			'p-md-1',
+			'hx_rsm-trigger',
+		]
+		: [
+			'Button',
+			'Button--iconOnly',
+			'Button--invisible',
+			'Button--medium',
+		];
+
 	anchor.after(
-		<details className="details-reset details-overlay flex-auto toolbar-item btn-octicon mx-1 select-menu select-menu-modal-right hx_rsm">
+		<details className={wrapperClasses.join(' ')}>
 			<summary
-				className="text-center menu-target p-2 p-md-1 hx_rsm-trigger"
+				className={buttonClasses.join(' ')}
 				role="button"
 				aria-label="Add a table"
 				aria-haspopup="menu"
@@ -72,7 +106,10 @@ function add(anchor: HTMLElement): void {
 }
 
 function init(signal: AbortSignal): void {
-	observe('md-ref', add, {signal});
+	observe([
+		'md-ref', // TODO: Drop in June 2024, cleanup button JSX above too
+		'.ActionBar-item:has([data-md-button=\'ref\'])',
+	], add, {signal});
 	delegate('.rgh-tic', 'click', addTable, {signal});
 	if (!isHasSelectorSupported()) {
 		delegate('.rgh-tic', 'mouseenter', highlightSquares, {capture: true, signal});
@@ -85,3 +122,11 @@ void features.add(import.meta.url, {
 	],
 	init,
 });
+
+/*
+
+Test URLs:
+
+- Any issue or PR
+
+*/
-- 
cgit v1.2.3

