Use <datasette-sql-editor> on core SQL pages

The five SQL pages now render the element wrapping a plain
<textarea name=sql> fallback that keeps working without JavaScript
(the element adopts and removes it on mount). The element also gained
a parser-timing guard: when its definition loads from <head> the
browser connects it at the start tag before its children are parsed,
so mounting defers to DOMContentLoaded in that case. window.editor
back-compat preserved; cm global deprecation deferred.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Alex Garcia 2026-07-10 11:42:04 -07:00
commit 4ec0f94ed8
14 changed files with 86 additions and 42 deletions

View file

@ -280,7 +280,7 @@ async def test_query_page_with_no_sql(ds_client):
# https://github.com/simonw/datasette/issues/2743
response = await ds_client.get("/fixtures/-/query")
assert response.status_code == 200
assert '<textarea id="sql-editor" name="sql"' in response.text
assert '<datasette-sql-editor id="sql-editor" name="sql"' in response.text
assert 'class="rows-and-columns"' not in response.text
@ -306,16 +306,16 @@ async def test_query_page_default_table_from_table_scoped_link(ds_client):
href = soup.find("span", string="View and edit SQL").find_parent("a")["href"]
response = await ds_client.get(href, follow_redirects=True)
assert response.status_code == 200
assert 'defaultTable: "facetable"' in response.text
assert 'default-table="facetable"' in response.text
@pytest.mark.asyncio
async def test_query_page_no_default_table_without_table_scope(ds_client):
# The plain database query page (no focal table) should not set
# defaultTable at all.
# default-table at all.
response = await ds_client.get("/fixtures/-/query?sql=select+1")
assert response.status_code == 200
assert "defaultTable" not in response.text
assert "default-table=" not in response.text
@pytest.mark.asyncio
@ -328,7 +328,7 @@ async def test_query_page_ignores_invalid_table_param(ds_client):
"/fixtures/-/query?sql=select+1&_table=not_a_real_table"
)
assert response.status_code == 200
assert "defaultTable" not in response.text
assert "default-table=" not in response.text
@pytest.mark.asyncio
@ -923,7 +923,8 @@ async def test_query_error(ds_client):
response = await ds_client.get("/fixtures/-/query?sql=select+*+from+notatable")
html = response.text
assert '<p class="message-error">no such table: notatable</p>' in html
assert '<textarea id="sql-editor" name="sql" style="height: 3em' in html
assert '<datasette-sql-editor id="sql-editor" name="sql"' in html
assert '<textarea name="sql" style="height: 3em' in html
assert ">select * from notatable</textarea>" in html
assert "0 results" not in html

View file

@ -1888,7 +1888,10 @@ async def test_execute_write_get_prepopulates_without_executing():
actor={"id": "root"},
)
assert '<p class="sql-editor sql-editor-min-lines">' in empty_response.text
assert '<textarea id="sql-editor" name="sql"></textarea>' in empty_response.text
assert (
'<datasette-sql-editor id="sql-editor" name="sql"><textarea name="sql"></textarea></datasette-sql-editor>'
in empty_response.text
)
assert "min-height: calc(5.6em + 8px);" in empty_response.text
assert 'executeWriteSqlInput.value = "\\n\\n\\n";' not in empty_response.text
assert "Enter writable SQL before executing." in empty_response.text