From 54f931b9ecd519d97471781bb49a5484e1ac0079 Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Fri, 4 Dec 2026 20:28:01 +0100 Subject: [PATCH 1/9] Document component parameters in templates and run native SQL examples --- examples/official-site/README.md | 41 ++++ examples/official-site/component.sql | 10 +- .../official-site/doc-examples/alert.01.sql | 7 + .../official-site/doc-examples/alert.02.sql | 23 +++ .../official-site/doc-examples/alert.03.sql | 19 ++ .../official-site/doc-examples/alert.04.sql | 14 ++ .../official-site/doc-examples/alert.05.sql | 9 + .../official-site/doc-examples/code.01.sql | 24 +++ .../official-site/doc-examples/columns.01.sql | 44 ++++ .../official-site/doc-examples/columns.02.sql | 38 ++++ .../official-site/doc-examples/divider.01.sql | 5 + .../official-site/doc-examples/divider.02.sql | 6 + .../official-site/doc-examples/divider.03.sql | 7 + .../official-site/doc-examples/divider.04.sql | 8 + .../official-site/doc-examples/divider.05.sql | 12 ++ .../doc-examples/empty_state.01.sql | 17 ++ .../doc-examples/empty_state.02.sql | 15 ++ .../doc-examples/foldable.01.sql | 9 + .../doc-examples/foldable.02.sql | 42 ++++ .../official-site/doc-examples/html.01.sql | 8 + .../official-site/doc-examples/html.02.sql | 17 ++ .../official-site/doc-examples/html.03.sql | 12 ++ .../official-site/doc-examples/toast.01.sql | 12 ++ .../official-site/doc-examples/toast.02.sql | 36 ++++ .../official-site/doc-examples/toast.03.sql | 29 +++ .../official-site/doc-examples/toast.04.sql | 35 ++++ .../official-site/doc-examples/toast.05.sql | 20 ++ .../sqlpage/docs-native-example.sql | 14 ++ .../sqlpage/migrations/01_documentation.sql | 10 + .../sqlpage/migrations/03_alert_component.sql | 190 ------------------ .../migrations/29_divider_component.sql | 145 ------------- .../sqlpage/migrations/35_code_title.sql | 54 ----- .../sqlpage/migrations/46_html.sql | 85 -------- .../sqlpage/migrations/51_column.sql | 113 ----------- .../sqlpage/migrations/52_foldable.sql | 25 --- .../sqlpage/migrations/60_empty_state.sql | 46 ----- .../sqlpage/migrations/76_toast.sql | 43 ---- .../migrations/82_reference_catalog.sql | 3 +- .../migrations/999_fts_search_index.sql | 5 + .../99_shared_id_class_attributes.sql | 9 - .../sqlpage/templates/docs-example.handlebars | 4 +- scripts/site-build.mjs | 2 + scripts/site-doc-examples.mjs | 86 ++++++++ sqlpage/templates/alert.handlebars | 18 +- sqlpage/templates/code.handlebars | 10 +- sqlpage/templates/columns.handlebars | 17 +- sqlpage/templates/divider.handlebars | 12 +- sqlpage/templates/empty_state.handlebars | 14 +- sqlpage/templates/foldable.handlebars | 11 +- sqlpage/templates/html.handlebars | 7 +- sqlpage/templates/toast.handlebars | 14 +- tests/js/component_documentation.checks.ts | 36 +++- 52 files changed, 770 insertions(+), 722 deletions(-) create mode 100644 examples/official-site/doc-examples/alert.01.sql create mode 100644 examples/official-site/doc-examples/alert.02.sql create mode 100644 examples/official-site/doc-examples/alert.03.sql create mode 100644 examples/official-site/doc-examples/alert.04.sql create mode 100644 examples/official-site/doc-examples/alert.05.sql create mode 100644 examples/official-site/doc-examples/code.01.sql create mode 100644 examples/official-site/doc-examples/columns.01.sql create mode 100644 examples/official-site/doc-examples/columns.02.sql create mode 100644 examples/official-site/doc-examples/divider.01.sql create mode 100644 examples/official-site/doc-examples/divider.02.sql create mode 100644 examples/official-site/doc-examples/divider.03.sql create mode 100644 examples/official-site/doc-examples/divider.04.sql create mode 100644 examples/official-site/doc-examples/divider.05.sql create mode 100644 examples/official-site/doc-examples/empty_state.01.sql create mode 100644 examples/official-site/doc-examples/empty_state.02.sql create mode 100644 examples/official-site/doc-examples/foldable.01.sql create mode 100644 examples/official-site/doc-examples/foldable.02.sql create mode 100644 examples/official-site/doc-examples/html.01.sql create mode 100644 examples/official-site/doc-examples/html.02.sql create mode 100644 examples/official-site/doc-examples/html.03.sql create mode 100644 examples/official-site/doc-examples/toast.01.sql create mode 100644 examples/official-site/doc-examples/toast.02.sql create mode 100644 examples/official-site/doc-examples/toast.03.sql create mode 100644 examples/official-site/doc-examples/toast.04.sql create mode 100644 examples/official-site/doc-examples/toast.05.sql create mode 100644 examples/official-site/sqlpage/docs-native-example.sql create mode 100644 scripts/site-doc-examples.mjs diff --git a/examples/official-site/README.md b/examples/official-site/README.md index 201f458af..008fab870 100644 --- a/examples/official-site/README.md +++ b/examples/official-site/README.md @@ -26,6 +26,47 @@ Add `theme=light` or `theme=dark` to a component reference URL to preview its live examples using SQLPage's stock theme. For example, visit `/component.sql?component=form&theme=light`. +## Component reference + +For components with an `@doc` block, add or change a parameter in its +`sqlpage/templates/.handlebars` file: + +```handlebars +{{!-- @doc +top id TEXT optional: HTML identifier of the container. +row contents TEXT required: A block of source code. +--}} +``` + +`top` describes the first row; `row` describes the following rows. The site +preparation reads this Handlebars comment. It does not add component runtime +logic. Component overviews and components without an `@doc` block still use the +existing documentation migrations. + +To add a runnable example, put a file such as `doc-examples/code.02.sql` in +this directory. The first line of the opening SQL comment is its title; the +rest is the optional Markdown explanation. + +```sql +/* +Show HTML source + +The tags are displayed as text, not rendered as markup. +*/ +select 'code' as component; +select 'html' as language, '

Hello

' as contents; +``` + +The number gives the stable link `#example-2`; keep existing numbers when +adding or removing files. The site lists the file automatically the next +time you run `npm run site`. No registry entry, YAML or SQL rewrite is needed. +The reference reads the original file for copying and includes it with +`run_sql`; the same file is also a standalone demo. Keep examples with +response-wide effects (such as redirects or headers) separate from inline +reference examples. + +Run `npm run site:test` to validate the prepared reference. + ## Landing page The home page is rendered by `index.sql` and the `landing-page` custom template. diff --git a/examples/official-site/component.sql b/examples/official-site/component.sql index 747882aab..bd28cb5f2 100644 --- a/examples/official-site/component.sql +++ b/examples/official-site/component.sql @@ -11,7 +11,8 @@ select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-reference.sql', jso )) as properties; select 'title' as component, 2 as level, 'Examples' as contents, 'examples' as id -where exists (select 1 from example where component = $component); +where exists (select 1 from example where component = $component) + or exists (select 1 from native_example where component = $component); with examples as ( -- HTTP headers and shells can only run at the start of a response. @@ -35,3 +36,10 @@ select 'dynamic' as component, json_array( else json_array() end ) as properties from examples order by example_id; + + +-- Paths come from the trusted catalog, never from a request parameter. +select 'dynamic' as component, sqlpage.run_sql('sqlpage/docs-native-example.sql', + json_object('entry', component, 'number', cast(number as text))) as properties +from native_example where component = $component +order by number; diff --git a/examples/official-site/doc-examples/alert.01.sql b/examples/official-site/doc-examples/alert.01.sql new file mode 100644 index 000000000..048a59fff --- /dev/null +++ b/examples/official-site/doc-examples/alert.01.sql @@ -0,0 +1,7 @@ +/* +A basic alert message +*/ +select + 'alert' as "component", + 'Attention' as "title", + 'This is an important message.' as "description"; diff --git a/examples/official-site/doc-examples/alert.02.sql b/examples/official-site/doc-examples/alert.02.sql new file mode 100644 index 000000000..b0a7afcf7 --- /dev/null +++ b/examples/official-site/doc-examples/alert.02.sql @@ -0,0 +1,23 @@ +/* +A list of notifications +*/ +select + 'alert' as "component", + 'Success' as "title", + 'Item successfully added to your cart.' as "description", + 'check' as "icon", + 'green' as "color"; + +select + 'alert' as "component", + 'Warning' as "title", + 'Your cart is almost full.' as "description", + 'alert-triangle' as "icon", + 'yellow' as "color"; + +select + 'alert' as "component", + 'Error' as "title", + 'Your cart is full.' as "description", + 'alert-circle' as "icon", + 'red' as "color"; diff --git a/examples/official-site/doc-examples/alert.03.sql b/examples/official-site/doc-examples/alert.03.sql new file mode 100644 index 000000000..c0d98e3a7 --- /dev/null +++ b/examples/official-site/doc-examples/alert.03.sql @@ -0,0 +1,19 @@ +/* +A full-featured notification message with multiple links +*/ +select + 'alert' as "component", + 'Your dashboard is ready!' as "title", + 'analyze' as "icon", + 'teal' as "color", + TRUE as "dismissible", + 'Your public web dashboard was successfully created.' as "description"; + +select + 'dashboard.sql' as "link", + 'View your dashboard' as "title"; + +select + 'index.sql' as "link", + 'Back to home' as "title", + 'secondary' as "color"; diff --git a/examples/official-site/doc-examples/alert.04.sql b/examples/official-site/doc-examples/alert.04.sql new file mode 100644 index 000000000..066cd9497 --- /dev/null +++ b/examples/official-site/doc-examples/alert.04.sql @@ -0,0 +1,14 @@ +/* +A dismissible alert. `close_label` names the close button for screen readers +*/ +select + 'alert' as "component", + 'Alert' as "title", + 'alert-circle' as "icon", + 'red' as "color", + TRUE as "important", + TRUE as "dismissible", + 'Dismiss this alert' as "close_label", + 'SQLPage is entirely free and open source.' as "description", + 'https://github.com/sqlpage/SQLPage' as "link", + 'See source code' as "link_text"; diff --git a/examples/official-site/doc-examples/alert.05.sql b/examples/official-site/doc-examples/alert.05.sql new file mode 100644 index 000000000..46dcf08a2 --- /dev/null +++ b/examples/official-site/doc-examples/alert.05.sql @@ -0,0 +1,9 @@ +/* +An alert message with a Markdown-formatted description +*/ +select + 'alert' as "component", + 'Free and open source' as "title", + 'free-rights' as "icon", + 'info' as "color", + '*SQLPage* is entirely free and open source. You can **contribute** to it on [GitHub](https://github.com/sqlpage/SQLPage).' as "description_md"; diff --git a/examples/official-site/doc-examples/code.01.sql b/examples/official-site/doc-examples/code.01.sql new file mode 100644 index 000000000..37e6450e2 --- /dev/null +++ b/examples/official-site/doc-examples/code.01.sql @@ -0,0 +1,24 @@ +/* +Display HTML source + +Displays a block of HTML code. +*/ +select + 'code' as "component"; + +select + 'A HTML5 example' as "title", + 'html' as "language", + 'Here’s the very minimum that an HTML document should contain, assuming it has CSS and JavaScript linked to it.' as "description", + ' + + + + title + + + + + + +' as "contents"; diff --git a/examples/official-site/doc-examples/columns.01.sql b/examples/official-site/doc-examples/columns.01.sql new file mode 100644 index 000000000..b69c59267 --- /dev/null +++ b/examples/official-site/doc-examples/columns.01.sql @@ -0,0 +1,44 @@ +/* +Pricing Plans Display +*/ +select + 'columns' as "component"; + +select + 'Start Plan' as "title", + '€18' as "value", + 'Perfect for testing and small-scale projects' as "description", + '128MB Database' as "item", + 'SQLPage hosting' as "item", + 'Community support' as "item", + 'https://datapage.app' as "link", + 'Start Free Trial' as "button_text", + '/month' as "small_text"; + +select + 'Pro Plan' as "title", + '€40' as "value", + 'rocket' as "icon", + 'For growing projects needing enhanced features' as "description", + JSON('{"icon":"database","color":"blue","description":"1GB Database"}') as "item", + JSON('{"icon":"headset","color":"green","description":"Priority Support"}') as "item", + JSON('{"icon":"world","color":"purple","description":"Custom Domain"}') as "item", + 'https://datapage.app' as "link", + 'Start Free Trial' as "button_text", + 'indigo' as "button_color", + 'indigo' as "value_color", + '/month' as "small_text"; + +select + 'Enterprise Plan' as "title", + '€600' as "value", + 'building-skyscraper' as "icon", + 'For large-scale operations with custom needs' as "description", + JSON('{"icon":"database-plus","description_md":"**Custom Database Scaling**"}') as "item", + JSON('{"icon":"shield-lock","description_md":"**Enterprise Auth** with Single Sign-On"}') as "item", + JSON('{"icon":"headset","description_md":"**Monthly** Expert Support time"}') as "item", + JSON('{"icon":"file-certificate","description_md":"**SLA** with guaranteed uptime"}') as "item", + 'mailto:contact@datapage.app' as "link", + 'Contact Us' as "button_text", + '/month' as "small_text", + '_blank' as "target"; diff --git a/examples/official-site/doc-examples/columns.02.sql b/examples/official-site/doc-examples/columns.02.sql new file mode 100644 index 000000000..f7bd46bdd --- /dev/null +++ b/examples/official-site/doc-examples/columns.02.sql @@ -0,0 +1,38 @@ +/* +Tech Company KPIs Display +*/ +select + 'columns' as "component"; + +select + 'Monthly Active Users' as "title", + '10k' as "value", + 'blue' as "value_color", + 4 as "size", + 'Total active users this month, showcasing user engagement.' as "description", + JSON('[{"icon":"target","description":"Target: 12,000"}]') as "item", + '#' as "link", + 'User Activity Overview' as "button_text", + 'info' as "button_color"; + +select + 'Revenue' as "title", + '$49k' as "value", + 'blue' as "value_color", + 4 as "size", + 'Total revenue generated this month, indicating financial performance.' as "description", + JSON('[{"icon":"trending-down","color":"red","description":"down from $51k last month"}]') as "item", + '#' as "link", + 'Financial Dashboard' as "button_text", + 'info' as "button_color"; + +select + 'Customer Satisfaction' as "title", + '94%' as "value", + 'blue' as "value_color", + 4 as "size", + 'Percentage of satisfied customers, reflecting service quality.' as "description", + JSON('[{"icon":"trending-up","color":"green","description":"+ 2% this month"}]') as "item", + '#' as "link", + 'Open Google Ratings' as "button_text", + 'info' as "button_color"; diff --git a/examples/official-site/doc-examples/divider.01.sql b/examples/official-site/doc-examples/divider.01.sql new file mode 100644 index 000000000..cede8b5c6 --- /dev/null +++ b/examples/official-site/doc-examples/divider.01.sql @@ -0,0 +1,5 @@ +/* +An empty divider +*/ +select + 'divider' as "component"; diff --git a/examples/official-site/doc-examples/divider.02.sql b/examples/official-site/doc-examples/divider.02.sql new file mode 100644 index 000000000..a4aa74562 --- /dev/null +++ b/examples/official-site/doc-examples/divider.02.sql @@ -0,0 +1,6 @@ +/* +A divider with centered text +*/ +select + 'divider' as "component", + 'Hello' as "contents"; diff --git a/examples/official-site/doc-examples/divider.03.sql b/examples/official-site/doc-examples/divider.03.sql new file mode 100644 index 000000000..d2d59cd13 --- /dev/null +++ b/examples/official-site/doc-examples/divider.03.sql @@ -0,0 +1,7 @@ +/* +A divider with text at left +*/ +select + 'divider' as "component", + 'Hello' as "contents", + 'left' as "position"; diff --git a/examples/official-site/doc-examples/divider.04.sql b/examples/official-site/doc-examples/divider.04.sql new file mode 100644 index 000000000..a291f235e --- /dev/null +++ b/examples/official-site/doc-examples/divider.04.sql @@ -0,0 +1,8 @@ +/* +A divider with blue text and a link +*/ +select + 'divider' as "component", + 'SQLPage components' as "contents", + '/documentation.sql' as "link", + 'blue' as "color"; diff --git a/examples/official-site/doc-examples/divider.05.sql b/examples/official-site/doc-examples/divider.05.sql new file mode 100644 index 000000000..f1bf445e2 --- /dev/null +++ b/examples/official-site/doc-examples/divider.05.sql @@ -0,0 +1,12 @@ +/* +A divider with bold, italic, and underlined text +*/ +select + 'divider' as "component", + 'Important notice' as "contents", + 'left' as "position", + 'red' as "color", + 5 as "size", + TRUE as "bold", + TRUE as "italics", + TRUE as "underline"; diff --git a/examples/official-site/doc-examples/empty_state.01.sql b/examples/official-site/doc-examples/empty_state.01.sql new file mode 100644 index 000000000..316897519 --- /dev/null +++ b/examples/official-site/doc-examples/empty_state.01.sql @@ -0,0 +1,17 @@ +/* +Show a not-found message + +This example shows how to create a 404-style "Not Found" empty state with + - a prominent header displaying "404", + - a helpful description suggesting to adjust search parameters, and + - a "Search again" button with a search icon that links back to the search page. +*/ +select + 'empty_state' as "component", + 'No results found' as "title", + '404' as "header", + 'Try adjusting your search or filter to find what you''re looking for.' as "description", + 'Search again' as "link_text", + 'search' as "link_icon", + '#not-found' as "link", + 'not-found' as "id"; diff --git a/examples/official-site/doc-examples/empty_state.02.sql b/examples/official-site/doc-examples/empty_state.02.sql new file mode 100644 index 000000000..698f075cb --- /dev/null +++ b/examples/official-site/doc-examples/empty_state.02.sql @@ -0,0 +1,15 @@ +/* +Show an illustration + +It's possible to use an icon or an image to illustrate the problem. +*/ +select + 'empty_state' as "component", + 'A critical problem has occurred' as "title", + 'mood-wrrr' as "icon", + 'SQLPage can do a lot of things, but this is not one of them. + +Please restart your browser and **cross your fingers**.' as "description_md", + 'Close and restart' as "link_text", + 'rotate-clockwise' as "link_icon", + '#' as "link"; diff --git a/examples/official-site/doc-examples/foldable.01.sql b/examples/official-site/doc-examples/foldable.01.sql new file mode 100644 index 000000000..6e4617e9e --- /dev/null +++ b/examples/official-site/doc-examples/foldable.01.sql @@ -0,0 +1,9 @@ +/* +A single foldable paragraph of text +*/ +select + 'foldable' as "component"; + +select + 'The foldable component' as "title", + 'This is a simple foldable component. It can be used to show and hide content. It is a list of items, each with a title and a description. The description is displayed when the item is expanded.' as "description"; diff --git a/examples/official-site/doc-examples/foldable.02.sql b/examples/official-site/doc-examples/foldable.02.sql new file mode 100644 index 000000000..df1cfc544 --- /dev/null +++ b/examples/official-site/doc-examples/foldable.02.sql @@ -0,0 +1,42 @@ +/* +A SQLPage-themed foldable list with Markdown +*/ +select + 'foldable' as "component"; + +select + 'Quick Prototyping' as "title", + 'Build a functional web app prototype in minutes using just SQL queries: + +- Rapid development +- Ideal for MVPs +- Great for internal tools + +Learn more about [quick prototyping](/your-first-sql-website/).' as "description_md", + TRUE as "expanded"; + +select + 'Data Visualization' as "title", + 'Quickly transform your database into useful insights: + +1. **Charts**: Line, bar, pie +2. **KPIs**: Appealing visualizations of key metrics +3. **Maps**: Geospatial data + +As simple as: + +```sql +SELECT ''chart'' as component; +SELECT date as x, revenue as y FROM sales; +```' as "description_md"; + +select + 'Don''t stare, interact!' as "title", + 'SQLPage is not just a passive *Business Intelligence* tool. With SQLPage, you can act upon user input: + +- *User input collection*: Building a form is just as easy as building a chart. +- *Data validation*: Write your own validation rules in SQL. +- *Database updates*: `INSERT` and `UPDATE` are first-class citizens. +- *File uploads*: Upload `CSV` and other files, store and display them the way you want. + +> Let users interact with your data, not just look at it!' as "description_md"; diff --git a/examples/official-site/doc-examples/html.01.sql b/examples/official-site/doc-examples/html.01.sql new file mode 100644 index 000000000..b493ad02f --- /dev/null +++ b/examples/official-site/doc-examples/html.01.sql @@ -0,0 +1,8 @@ +/* +Render an HTML snippet + +Include a simple HTML snippet. In this example, the HTML code is hardcoded in the SQL query, so it is safe. You should never include data that may be manipulated by a user in the HTML content. +*/ +select + 'html' as "component", + '

This text is safe because it is hardcoded!

' as "html"; diff --git a/examples/official-site/doc-examples/html.02.sql b/examples/official-site/doc-examples/html.02.sql new file mode 100644 index 000000000..e963d54f1 --- /dev/null +++ b/examples/official-site/doc-examples/html.02.sql @@ -0,0 +1,17 @@ +/* +Render multiple HTML snippets + +Include multiple html snippets as row-level parameters. Again, be careful what you include in the HTML content. If the data comes from a user, it can be manipulated to include malicious code. +*/ +select + 'html' as "component", + '
' as "html"; + +select + '
20%
' as "html"; + +select + '
80%
' as "html"; + +select + '
' as "html"; diff --git a/examples/official-site/doc-examples/html.03.sql b/examples/official-site/doc-examples/html.03.sql new file mode 100644 index 000000000..4d0e20a4a --- /dev/null +++ b/examples/official-site/doc-examples/html.03.sql @@ -0,0 +1,12 @@ +/* +Sanitize text before rendering HTML + +In order to include user-generated content that should be sanitized, use the `text` property instead of `html`. The `text` property will display the text as-is, without interpreting any HTML tags. +*/ +select + 'html' as "component"; + +select + '

The following will be sanitized: ' as "html", + '' as "text", + '. Phew! That was close!

' as "post_html"; diff --git a/examples/official-site/doc-examples/toast.01.sql b/examples/official-site/doc-examples/toast.01.sql new file mode 100644 index 000000000..9405df517 --- /dev/null +++ b/examples/official-site/doc-examples/toast.01.sql @@ -0,0 +1,12 @@ +/* +Dismiss automatically + +A toast that opens when the page loads and disappears automatically after the default 5000 milliseconds. +*/ +select + 'toast' as "component", + 'toast-auto' as "id", + 'This is a SQLPage toast' as "title", + 'This toast will open automatically when the page loads.' as "description", + 'check' as "icon", + 'green' as "color"; diff --git a/examples/official-site/doc-examples/toast.02.sql b/examples/official-site/doc-examples/toast.02.sql new file mode 100644 index 000000000..066405a71 --- /dev/null +++ b/examples/official-site/doc-examples/toast.02.sql @@ -0,0 +1,36 @@ +/* +Dismiss manually + +A persistent error notification that disables automatic dismissal and requires the user to activate its close button. +*/ +select + 'toast' as "component", + 'toast-dismissible' as "id", + 'persistent-error' as "trigger", + 'Could not save' as "title", + 'Review the highlighted fields and try again.' as "description", + 'alert-triangle' as "icon", + 'black' as "color", + 0 as "duration", + TRUE as "dismissible"; + +select + 'toast' as "component", + 'toast-nondismissible' as "id", + 'persistent-status' as "trigger", + 'Connection unavailable' as "title", + 'This persistent notification has no manual close control.' as "description", + 0 as "duration", + FALSE as "dismissible"; + +select + 'button' as "component"; + +select + 'Show dismissible error' as "title", + '#persistent-error' as "link", + 'red' as "color"; + +select + 'Show non-dismissible status' as "title", + '#persistent-status' as "link"; diff --git a/examples/official-site/doc-examples/toast.03.sql b/examples/official-site/doc-examples/toast.03.sql new file mode 100644 index 000000000..3ae008454 --- /dev/null +++ b/examples/official-site/doc-examples/toast.03.sql @@ -0,0 +1,29 @@ +/* +Render Markdown + +A persistent rich Markdown notification. Markdown takes precedence over plain text and renders emphasis and a link as HTML, while plain-text content remains escaped. +*/ +select + 'toast' as "component", + 'toast-markdown' as "id", + 'rich-notifications' as "trigger", + 'Release available' as "title", + 'This fallback stays escaped' as "description", + 'Version **2.0** is ready. [Read the notes](https://example.com/releases).' as "description_md", + 'blue' as "color", + 0 as "duration"; + +select + 'toast' as "component", + 'toast-plain' as "id", + 'rich-notifications' as "trigger", + 'Plain text stays escaped' as "description", + 'white' as "color", + 0 as "duration"; + +select + 'button' as "component"; + +select + 'Show rich notifications' as "title", + '#rich-notifications' as "link"; diff --git a/examples/official-site/doc-examples/toast.04.sql b/examples/official-site/doc-examples/toast.04.sql new file mode 100644 index 000000000..92ac9f60b --- /dev/null +++ b/examples/official-site/doc-examples/toast.04.sql @@ -0,0 +1,35 @@ +/* +Queue notifications + +Several persistent queued notifications. Toasts with the same position share a container and stack instead of overlapping. +*/ +select + 'toast' as "component", + 'toast-stack-one' as "id", + 'queued notifications' as "trigger", + 'Import started' as "title", + 'Preparing records.' as "description", + 0 as "duration"; + +select + 'toast' as "component", + 'toast-stack-two' as "id", + 'queued notifications' as "trigger", + 'Import running' as "title", + 'Processing records.' as "description", + 0 as "duration"; + +select + 'toast' as "component", + 'toast-short' as "id", + 'queued notifications' as "trigger", + 'Temporary update' as "title", + 'This message closes shortly.' as "description", + 2000 as "duration"; + +select + 'button' as "component"; + +select + 'Show queued notifications' as "title", + '#queued notifications' as "link"; diff --git a/examples/official-site/doc-examples/toast.05.sql b/examples/official-site/doc-examples/toast.05.sql new file mode 100644 index 000000000..2de942e2c --- /dev/null +++ b/examples/official-site/doc-examples/toast.05.sql @@ -0,0 +1,20 @@ +/* +Choose a notification position + +A notification placed at the bottom center of the screen instead of the default top end. +*/ +select + 'toast' as "component", + 'toast-bottom-center' as "id", + 'bottom-notification' as "trigger", + 'Download ready' as "title", + 'Your export is ready.' as "description", + 'bottom-center' as "position", + 0 as "duration"; + +select + 'button' as "component"; + +select + 'Show bottom notification' as "title", + '#bottom-notification' as "link"; diff --git a/examples/official-site/sqlpage/docs-native-example.sql b/examples/official-site/sqlpage/docs-native-example.sql new file mode 100644 index 000000000..d9ed07726 --- /dev/null +++ b/examples/official-site/sqlpage/docs-native-example.sql @@ -0,0 +1,14 @@ +-- Resolve a catalog key, not a caller-supplied path. +set example_file = ( + select path from native_example where component = $entry and number = $number +); + +select 'docs-example' as component, number, title, description as description_md, + sqlpage.read_file_as_text(path) as source, path as demo_link, true as preview +from native_example where component = $entry and number = $number; + +select 'dynamic' as component, sqlpage.run_sql($example_file) as properties +where $example_file is not null; + +select 'docs-example' as component, true as end_result +where $example_file is not null; diff --git a/examples/official-site/sqlpage/migrations/01_documentation.sql b/examples/official-site/sqlpage/migrations/01_documentation.sql index 31cd392cd..9e9669544 100644 --- a/examples/official-site/sqlpage/migrations/01_documentation.sql +++ b/examples/official-site/sqlpage/migrations/01_documentation.sql @@ -29,6 +29,16 @@ CREATE TABLE example( FOREIGN KEY (component) REFERENCES component(name) ON DELETE CASCADE ); +CREATE TABLE native_example( + component TEXT NOT NULL REFERENCES component(name), + number INTEGER NOT NULL CHECK (number > 0), + title TEXT NOT NULL, + description TEXT NOT NULL, + path TEXT NOT NULL UNIQUE, + source TEXT NOT NULL, + PRIMARY KEY (component, number) +); + -- The reference shows the SQL and renders the same stored component rows. -- Arrays with several items become repeated column aliases, as in handwritten SQLPage files. CREATE VIEW example_with_source AS diff --git a/examples/official-site/sqlpage/migrations/03_alert_component.sql b/examples/official-site/sqlpage/migrations/03_alert_component.sql index 7fd2ee908..8876de633 100644 --- a/examples/official-site/sqlpage/migrations/03_alert_component.sql +++ b/examples/official-site/sqlpage/migrations/03_alert_component.sql @@ -5,193 +5,3 @@ VALUES ( 'alert-triangle', 'A visually distinctive message or notification.' ); -INSERT INTO parameter( - component, - name, - description, - type, - top_level, - optional - ) -VALUES ( - 'alert', - 'title', - 'Title of the alert message.', - 'TEXT', - TRUE, - FALSE - ), - ( - 'alert', - 'icon', - 'Icon name (from tabler-icons.io) to display next to the alert message.', - 'TEXT', - TRUE, - TRUE - ), - ( - 'alert', - 'color', - 'The color theme for the alert message. The default is `info`.', - 'COLOR', - TRUE, - TRUE - ), - ( - 'alert', - 'description', - 'Detailed description or content of the alert message.', - 'TEXT', - TRUE, - TRUE - ), - ( - 'alert', - 'description_md', - 'Detailed description or content of the alert message, in Markdown format, allowing you to use rich text formatting, including `**bold**` and `*italic*` text.', - 'TEXT', - TRUE, - TRUE - ), - ( - 'alert', - 'dismissible', - 'Whether the user can close the alert message.', - 'BOOLEAN', - TRUE, - TRUE - ), - ( - 'alert', - 'close_label', - 'Accessible name of the close button of a dismissible alert, which screen readers announce. The default is "Close".', - 'TEXT', - TRUE, - TRUE - ), - ( - 'alert', - 'important', - 'Set this to TRUE to make the alert message more prominent.', - 'BOOLEAN', - TRUE, - TRUE - ), - ( - 'alert', - 'link', - 'A URL to link to from the alert message.', - 'URL', - TRUE, - TRUE - ), - ( - 'alert', - 'link_text', - 'Customize the text of the link in the alert message. The default is "Ok".', - 'TEXT', - TRUE, - TRUE - ), - ( - 'alert', - 'link', - 'A URL to link to from the alert message.', - 'URL', - FALSE, - TRUE - ), - ( - 'alert', - 'title', - 'Customize the text of the link in the alert message. The default is "Ok".', - 'TEXT', - FALSE, - TRUE - ), - ( - 'alert', - 'color', - 'Customize the color of the link.', - 'COLOR', - FALSE, - TRUE - ); --- Insert example(s) for the component -INSERT INTO example(component, description, properties) -VALUES ( - 'alert', - 'A basic alert message', - JSON( - '[{"component":"alert", "title":"Attention", "description":"This is an important message."}]' - ) - ), - ( - 'alert', - 'A list of notifications', - JSON( - '[ - {"component" :"alert", "title":"Success","description":"Item successfully added to your cart.", "icon":"check", "color": "green"}, - {"component":"alert", "title":"Warning","description":"Your cart is almost full.", "icon":"alert-triangle", "color": "yellow"}, - {"component":"alert", "title":"Error","description":"Your cart is full.", "icon":"alert-circle", "color": "red"} - ]' - ) - ), - ( - 'alert', - 'A full-featured notification message with multiple links', - JSON( - '[ - { - "component" :"alert", - "title": "Your dashboard is ready!", - "icon":"analyze", - "color":"teal", - "dismissible": true, - "description":"Your public web dashboard was successfully created." - }, - { - "link":"dashboard.sql", - "title": "View your dashboard" - }, - { - "link" :"index.sql", - "title": "Back to home", - "color": "secondary" - } - ]' - ) - ), - ( - 'alert', - 'A dismissible alert. `close_label` names the close button for screen readers.', - JSON( - '[ - { - "component":"alert", - "title":"Alert", - "icon":"alert-circle", - "color":"red", - "important": true, - "dismissible": true, - "close_label": "Dismiss this alert", - "description":"SQLPage is entirely free and open source.", - "link":"https://github.com/sqlpage/SQLPage", - "link_text":"See source code" - }]' - ) - ), - ( - 'alert', - 'An alert message with a Markdown-formatted description', - JSON( - '[ - { - "component":"alert", - "title":"Free and open source", - "icon": "free-rights", - "color": "info", - "description_md":"*SQLPage* is entirely free and open source. You can **contribute** to it on [GitHub](https://github.com/sqlpage/SQLPage)." - }]' - ) - ); diff --git a/examples/official-site/sqlpage/migrations/29_divider_component.sql b/examples/official-site/sqlpage/migrations/29_divider_component.sql index 3acaa4e4b..fdb2fc919 100644 --- a/examples/official-site/sqlpage/migrations/29_divider_component.sql +++ b/examples/official-site/sqlpage/migrations/29_divider_component.sql @@ -5,148 +5,3 @@ VALUES ( 'separator', '0.18.0' ); - -INSERT INTO parameter ( - component, - name, - description, - type, - top_level, - optional - ) -VALUES ( - 'divider', - 'contents', - 'A text in the divider.', - 'TEXT', - TRUE, - TRUE - ), - ( - 'divider', - 'position', - 'Position of the text (e.g. left, right).', - 'TEXT', - TRUE, - TRUE - ), - ( - 'divider', - 'color', - 'The name of a color for this span of text.', - 'COLOR', - TRUE, - TRUE - ), - ( - 'divider', - 'size', - 'The size of the divider text, from 1 to 6.', - 'INTEGER', - TRUE, - TRUE - ), - ( - 'divider', - 'bold', - 'Whether the text is bold.', - 'BOOLEAN', - TRUE, - TRUE - ), - ( - 'divider', - 'italics', - 'Whether the text is italicized.', - 'BOOLEAN', - TRUE, - TRUE - ), - ( - 'divider', - 'underline', - 'Whether the text is underlined.', - 'BOOLEAN', - TRUE, - TRUE - ), - ( - 'divider', - 'link', - 'URL of the link for the divider text. Available only when contents is present.', - 'URL', - TRUE, - TRUE - ); - --- Insert example(s) for the component -INSERT INTO example(component, description, properties) -VALUES - ( - 'divider', - 'An empty divider', - JSON( - '[ - { - "component":"divider" - } - ]' - ) - ), - ( - 'divider', - 'A divider with centered text', - JSON( - '[ - { - "component":"divider", - "contents":"Hello" - } - ]' - ) - ), - ( - 'divider', - 'A divider with text at left', - JSON( - '[ - { - "component":"divider", - "contents":"Hello", - "position":"left" - } - ]' - ) - ), - ( - 'divider', - 'A divider with blue text and a link', - JSON( - '[ - { - "component":"divider", - "contents":"SQLPage components", - "link":"/documentation.sql", - "color":"blue" - } - ]' - ) - ), - ( - 'divider', - 'A divider with bold, italic, and underlined text', - JSON( - '[ - { - "component":"divider", - "contents":"Important notice", - "position":"left", - "color":"red", - "size":5, - "bold":true, - "italics":true, - "underline":true - } - ]' - ) - ); \ No newline at end of file diff --git a/examples/official-site/sqlpage/migrations/35_code_title.sql b/examples/official-site/sqlpage/migrations/35_code_title.sql index bfa8b12cc..67adb1daf 100644 --- a/examples/official-site/sqlpage/migrations/35_code_title.sql +++ b/examples/official-site/sqlpage/migrations/35_code_title.sql @@ -59,57 +59,3 @@ INSERT INTO component (name, description, icon, introduced_in_version) VALUES ( 'code', '0.19.0' ); - -INSERT INTO parameter (component,name,description,type,top_level,optional) VALUES ( - 'code', - 'title', - 'Set the heading level (default level is 1)', - 'TEXT', - FALSE, - TRUE -),( - 'code', - 'contents', - 'A block of code.', - 'TEXT', - FALSE, - FALSE -),( - 'code', - 'description', - 'Description of the snipet of code.', - 'TEXT', - FALSE, - TRUE -),( - 'code', - 'description_md', - 'Rich text in the markdown format. Among others, this allows you to write bold text using `**bold**`, italics using `*italics*`, and links using `[text](https://example.com)`.', - 'TEXT', - FALSE, - TRUE -),( - 'code', - 'language', - 'Set the programming language name.', - 'TEXT', - FALSE, - TRUE -); - --- Insert example(s) for the component -INSERT INTO example(component, description, properties) VALUES ( - 'code', - 'Displays a block of HTML code.', - JSON( - '[ - {"component":"code"}, - { - "title":"A HTML5 example", - "language":"html", - "description":"Here’s the very minimum that an HTML document should contain, assuming it has CSS and JavaScript linked to it.", - "contents":"\n\n\t\n\t\t\n\t\ttitle\n\t\t\n\t\t\n\t\n\t\n\t\t\n\t\n" - } - ]' - ) -); \ No newline at end of file diff --git a/examples/official-site/sqlpage/migrations/46_html.sql b/examples/official-site/sqlpage/migrations/46_html.sql index 58168c0d4..486bdf525 100644 --- a/examples/official-site/sqlpage/migrations/46_html.sql +++ b/examples/official-site/sqlpage/migrations/46_html.sql @@ -10,88 +10,3 @@ VALUES 'html', '0.25.0' ); - -INSERT INTO - parameter ( - component, - name, - description, - type, - top_level, - optional - ) -VALUES - ( - 'html', - 'html', - 'Raw HTML content to include in the page. This will not be sanitized or escaped. If you include content from an untrusted source, your page will be vulnerable to cross-site scripting attacks.', - 'TEXT', - TRUE, - TRUE - ), - ( - 'html', - 'html', - 'Raw HTML content to include in the page. This will not be sanitized or escaped. If you include content from an untrusted source, your page will be vulnerable to cross-site scripting attacks.', - 'TEXT', - FALSE, - TRUE - ), - ( - 'html', - 'text', - 'Text content to include in the page. This will be sanitized and escaped. Use this property to include user-generated content that should not contain HTML tags.', - 'TEXT', - FALSE, - TRUE - ), - ( - 'html', - 'post_html', - 'Raw HTML content to include after the text content. This will not be sanitized or escaped. If you include content from an untrusted source, your page will be vulnerable to cross-site scripting attacks.', - 'TEXT', - FALSE, - TRUE - ); - --- Insert example(s) for the component -INSERT INTO - example (component, description, properties) -VALUES - ( - 'html', - 'Include a simple HTML snippet. In this example, the HTML code is hardcoded in the SQL query, so it is safe. You should never include data that may be manipulated by a user in the HTML content. - ', - JSON ( - '[{ - "component": "html", - "html": "

This text is safe because it is hardcoded!

" - }]' - ) - ), - ( - 'html', - 'Include multiple html snippets as row-level parameters. Again, be careful what you include in the HTML content. If the data comes from a user, it can be manipulated to include malicious code.', - JSON ( - '[{"component":"html", "html":"
"}, - {"html":"
20%
"}, - {"html":"
80%
"}, - {"html":"
"} - ]' - ) - ), - ( - 'html', - 'In order to include user-generated content that should be sanitized, use the `text` property instead of `html`. The `text` property will display the text as-is, without interpreting any HTML tags.', - JSON ( - ' - [ - {"component": "html"}, - { - "html": "

The following will be sanitized: ", - "text": "", - "post_html": ". Phew! That was close!

" - } - ]' - ) - ); \ No newline at end of file diff --git a/examples/official-site/sqlpage/migrations/51_column.sql b/examples/official-site/sqlpage/migrations/51_column.sql index 8785b3955..02544ee61 100644 --- a/examples/official-site/sqlpage/migrations/51_column.sql +++ b/examples/official-site/sqlpage/migrations/51_column.sql @@ -3,116 +3,3 @@ -- Component Definition INSERT INTO component(name, icon, description, introduced_in_version) VALUES ('columns', 'columns', 'Use one row per plan, feature, or metric to compare them side by side. For a dashboard of values with trends and progress bars, see [`big_number`](?component=big_number).', '0.29.0'); - --- Inserting parameter information for the column component -INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'columns', * FROM (VALUES - ('title', 'The title or label for the item.', 'TEXT', FALSE, TRUE), - ('value', 'The value associated with the item.', 'TEXT', FALSE, TRUE), - ('description', 'A brief description of the item.', 'TEXT', FALSE, TRUE), - ('description_md', 'A brief description of the item, formatted using markdown.', 'TEXT', FALSE, TRUE), - ('item', 'A list of bullet points associated with the columns, represented either as text, or as a json object with "icon", "color", and "description" or "description_md" fields.', 'JSON', FALSE, TRUE), - ('link', 'A link associated with the item.', 'TEXT', FALSE, TRUE), - ('button_text', 'Text for the button.', 'TEXT', FALSE, TRUE), - ('button_color', 'Optional color for the button.', 'TEXT', FALSE, TRUE), - ('target', 'Optional target for the button. Set to "_blank" to open links in a new tab.', 'TEXT', FALSE, TRUE), - ('value_color', 'Color for the value text.', 'TEXT', FALSE, TRUE), - ('small_text', 'Optional small text to display after the value.', 'TEXT', FALSE, TRUE), - ('icon', 'Optional icon to display in a ribbon.', 'ICON', FALSE, TRUE), - ('icon_color', 'Color for the icon in the ribbon.', 'TEXT', FALSE, TRUE), - ('size', 'Width on a 12-column grid on larger screens. For three equal columns, return three rows with `size` set to 4.', 'INTEGER', FALSE, TRUE) -) x; - -INSERT INTO example(component, description, properties) VALUES - ('columns', 'Pricing Plans Display', - json('[ - {"component":"columns"}, - { - "title":"Start Plan", - "value":"€18", - "description":"Perfect for testing and small-scale projects", - "item": [ - "128MB Database", - "SQLPage hosting", - "Community support" - ], - "link":"https://datapage.app", - "button_text":"Start Free Trial", - "small_text":"/month" - }, - { - "title":"Pro Plan", - "value":"€40", - "icon":"rocket", - "description":"For growing projects needing enhanced features", - "item": [ - {"icon":"database", "color": "blue", "description":"1GB Database"}, - {"icon":"headset", "color": "green", "description":"Priority Support"}, - {"icon":"world", "color": "purple", "description":"Custom Domain"} - ], - "link":"https://datapage.app", - "button_text":"Start Free Trial", - "button_color":"indigo", - "value_color":"indigo", - "small_text":"/month" - }, - { - "title":"Enterprise Plan", - "value":"€600", - "icon":"building-skyscraper", - "description":"For large-scale operations with custom needs", - "item": [ - {"icon":"database-plus", "description_md":"**Custom Database Scaling**"}, - {"icon":"shield-lock", "description_md":"**Enterprise Auth** with Single Sign-On"}, - {"icon":"headset", "description_md":"**Monthly** Expert Support time"}, - {"icon":"file-certificate", "description_md":"**SLA** with guaranteed uptime"} - ], - "link":"mailto:contact@datapage.app", - "button_text":"Contact Us", - "small_text":"/month", - "target":"_blank" - } - ]')), - - ('columns', 'Tech Company KPIs Display', - json('[ - {"component":"columns"}, - { - "title":"Monthly Active Users", - "value":"10k", - "value_color":"blue", - "size": 4, - "description":"Total active users this month, showcasing user engagement.", - "item": [ - {"icon": "target", "description":"Target: 12,000"} - ], - "link":"#", - "button_text":"User Activity Overview", - "button_color":"info" - }, - { - "title":"Revenue", - "value":"$49k", - "value_color":"blue", - "size": 4, - "description":"Total revenue generated this month, indicating financial performance.", - "item": [ - {"icon":"trending-down", "color": "red", "description":"down from $51k last month" } - ], - "link":"#", - "button_text":"Financial Dashboard", - "button_color":"info" - }, - { - "title":"Customer Satisfaction", - "value":"94%", - "value_color":"blue", - "size": 4, - "description":"Percentage of satisfied customers, reflecting service quality.", - "item": [ - {"icon":"trending-up", "color": "green", "description":"+ 2% this month" } - ], - "link":"#", - "button_text": "Open Google Ratings", - "button_color":"info" - } - ]')); diff --git a/examples/official-site/sqlpage/migrations/52_foldable.sql b/examples/official-site/sqlpage/migrations/52_foldable.sql index d70201dfe..c72eb702b 100644 --- a/examples/official-site/sqlpage/migrations/52_foldable.sql +++ b/examples/official-site/sqlpage/migrations/52_foldable.sql @@ -1,27 +1,2 @@ INSERT INTO component(name, icon, description, introduced_in_version) VALUES ('foldable', 'chevrons-down', 'A foldable list of elements which can be expanded individually.', '0.29.0'); - -INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'foldable', * FROM (VALUES - ('id', 'ID attribute added to the container in HTML. Used for targeting through CSS or for scrolling via links. When set at the top level, applies to the entire foldable component.', 'TEXT', TRUE, TRUE), - ('class', 'CSS class(es) to add to the foldable container. When set at the top level, applies to the entire foldable component.', 'TEXT', TRUE, TRUE), - ('id', 'ID attribute added to individual foldable items. Used for targeting through CSS or for scrolling via links.', 'TEXT', FALSE, TRUE), - ('class', 'CSS class(es) to add to individual foldable items.', 'TEXT', FALSE, TRUE), - ('title', 'Title of the foldable item, displayed on the button.', 'TEXT', FALSE, TRUE), - ('description', 'Plain text description of the item, displayed when expanded.', 'TEXT', FALSE, TRUE), - ('description_md', 'Markdown description of the item, displayed when expanded.', 'TEXT', FALSE, TRUE), - ('expanded', 'If set to TRUE, the foldable item starts in an expanded state. Defaults FALSE', 'BOOLEAN', FALSE, TRUE) -) x; - -INSERT INTO example(component, description, properties) VALUES - ('foldable', 'A single foldable paragraph of text', json('[ - {"component":"foldable"}, - {"title":"The foldable component", "description": "This is a simple foldable component. It can be used to show and hide content. It is a list of items, each with a title and a description. The description is displayed when the item is expanded."}, - ]')); - -INSERT INTO example(component, description, properties) VALUES - ('foldable', 'A SQLPage-themed foldable list with Markdown', json('[ - {"component":"foldable"}, - {"title":"Quick Prototyping", "description_md": "Build a functional web app prototype in minutes using just SQL queries:\n\n- Rapid development\n- Ideal for MVPs\n- Great for internal tools\n\nLearn more about [quick prototyping](/your-first-sql-website/).", "expanded": true}, - {"title":"Data Visualization", "description_md": "Quickly transform your database into useful insights:\n\n1. **Charts**: Line, bar, pie\n2. **KPIs**: Appealing visualizations of key metrics\n3. **Maps**: Geospatial data\n\nAs simple as:\n\n```sql\nSELECT ''chart'' as component;\nSELECT date as x, revenue as y FROM sales;\n```"}, - {"title":"Don''t stare, interact!", "description_md": "SQLPage is not just a passive *Business Intelligence* tool. With SQLPage, you can act upon user input:\n\n- *User input collection*: Building a form is just as easy as building a chart.\n- *Data validation*: Write your own validation rules in SQL.\n- *Database updates*: `INSERT` and `UPDATE` are first-class citizens.\n- *File uploads*: Upload `CSV` and other files, store and display them the way you want.\n\n> Let users interact with your data, not just look at it!"} - ]')); \ No newline at end of file diff --git a/examples/official-site/sqlpage/migrations/60_empty_state.sql b/examples/official-site/sqlpage/migrations/60_empty_state.sql index 1f0b65518..53f40f725 100644 --- a/examples/official-site/sqlpage/migrations/60_empty_state.sql +++ b/examples/official-site/sqlpage/migrations/60_empty_state.sql @@ -4,49 +4,3 @@ INSERT INTO component(name, icon, description, introduced_in_version) VALUES Typically includes a title, an optional icon/image, descriptive text (rich text formatting and images supported via Markdown), and a call-to-action button. Ideal for first-use screens, empty data sets, "no results" pages, or error messages.', '0.35.0'); - -INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'empty_state', * FROM (VALUES - ('title','Description of the empty state.','TEXT',TRUE,FALSE), - ('header','Text displayed on the top of the empty state.','TEXT',TRUE,TRUE), - ('icon','Name of an icon to be displayed on the top of the empty state.','ICON',TRUE,TRUE), - ('image','The URL (absolute or relative) of an image to display at the top of the empty state.','URL',TRUE,TRUE), - ('description','A short text displayed below the title.','TEXT',TRUE,TRUE), - ('description_md','A short text displayed below the title, formatted using markdown.','TEXT',TRUE,TRUE), - ('link_text','The text displayed on the button.','TEXT',TRUE,FALSE), - ('link_icon','Name of an icon to be displayed on the left side of the button.','ICON',TRUE,FALSE), - ('link','The URL to which the button should navigate when clicked.','URL',TRUE,FALSE) - -- id and class come from 99_shared_id_class_attributes.sql -) x; - -INSERT INTO example(component, description, properties) VALUES - ('empty_state', ' -This example shows how to create a 404-style "Not Found" empty state with - - a prominent header displaying "404", - - a helpful description suggesting to adjust search parameters, and - - a "Search again" button with a search icon that links back to the search page. -', - json('[{ - "component": "empty_state", - "title": "No results found", - "header": "404", - "description": "Try adjusting your search or filter to find what you''re looking for.", - "link_text": "Search again", - "link_icon": "search", - "link": "#not-found", - "id": "not-found" - }]')), - ('empty_state', ' -It''s possible to use an icon or an image to illustrate the problem. -', - json('[{ - "component": "empty_state", - "title": "A critical problem has occurred", - "icon": "mood-wrrr", - "description_md": "SQLPage can do a lot of things, but this is not one of them. - -Please restart your browser and **cross your fingers**.", - "link_text": "Close and restart", - "link_icon": "rotate-clockwise", - "link": "#" - }]')); - diff --git a/examples/official-site/sqlpage/migrations/76_toast.sql b/examples/official-site/sqlpage/migrations/76_toast.sql index 4afc43fbd..131a8a338 100644 --- a/examples/official-site/sqlpage/migrations/76_toast.sql +++ b/examples/official-site/sqlpage/migrations/76_toast.sql @@ -3,46 +3,3 @@ INSERT INTO component(name, icon, description, introduced_in_version) VALUES Displays a brief notification above the page. Each top-level `toast` row creates one notification, and consecutive toasts at the same position are queued in a shared stack. Ordinary notifications use `role="status"` and `aria-live="polite"`. Colored variants retain a readable contrasting foreground. Automatic dismissal and the manual close control are configured independently.', '0.46.0'); - -INSERT INTO parameter(component, name, description, type, top_level, optional) SELECT 'toast', * FROM (VALUES - ('title', 'Optional notification heading.', 'TEXT', TRUE, TRUE), - ('description', 'Escaped plain-text body. This is used only when `description_md` is not supplied.', 'TEXT', TRUE, TRUE), - ('description_md', 'Rich-text alternative to `description`, rendered as Markdown. When both properties are supplied, `description_md` takes precedence.', 'TEXT', TRUE, TRUE), - ('icon', 'Optional [Tabler icon](https://tabler.io/icons) name.', 'ICON', TRUE, TRUE), - ('color', 'Optional Tabler color. The default is the neutral toast appearance; colored variants use the matching contrasting foreground utility.', 'COLOR', TRUE, TRUE), - ('dismissible', 'Whether to render an accessible manual close button. Defaults to true and is independent of automatic dismissal.', 'BOOLEAN', TRUE, TRUE), - ('duration', 'Automatic dismissal delay in milliseconds. Defaults to 5000. Set to 0 to keep the toast visible until manually dismissed (when `dismissible` is true) or the page is left.', 'INTEGER', TRUE, TRUE), - ('position', 'Screen placement: `top-start`, `top-center`, `top-end`, `bottom-start`, `bottom-center`, or `bottom-end`. Defaults to `top-end`; invalid values safely fall back to that default.', 'TEXT', TRUE, TRUE), - ('trigger', 'Optional URL fragment that opens the toast without reloading the page, with or without the leading `#`. When set, the toast does not open on page load and can be opened repeatedly by a link or button whose target is that fragment. Multiple toasts can share a trigger to open as a stack.', 'TEXT', TRUE, TRUE) - -- id and class come from 99_shared_id_class_attributes.sql -) x; - -INSERT INTO example(component, description, properties) VALUES - ('toast', 'A toast that opens when the page loads and disappears automatically after the default 5000 milliseconds.', json('[ - {"component":"toast","id":"toast-auto","title":"This is a SQLPage toast","description":"This toast will open automatically when the page loads.","icon":"check","color":"green"} - ]')), - ('toast', 'A persistent error notification that disables automatic dismissal and requires the user to activate its close button.', json('[ - {"component":"toast","id":"toast-dismissible","trigger":"persistent-error","title":"Could not save","description":"Review the highlighted fields and try again.","icon":"alert-triangle","color":"black","duration":0,"dismissible":true}, - {"component":"toast","id":"toast-nondismissible","trigger":"persistent-status","title":"Connection unavailable","description":"This persistent notification has no manual close control.","duration":0,"dismissible":false}, - {"component":"button"}, - {"title":"Show dismissible error","link":"#persistent-error","color":"red"}, - {"title":"Show non-dismissible status","link":"#persistent-status"} - ]')), - ('toast', 'A persistent rich Markdown notification. Markdown takes precedence over plain text and renders emphasis and a link as HTML, while plain-text content remains escaped.', json('[ - {"component":"toast","id":"toast-markdown","trigger":"rich-notifications","title":"Release available","description":"This fallback stays escaped","description_md":"Version **2.0** is ready. [Read the notes](https://example.com/releases).","color":"blue","duration":0}, - {"component":"toast","id":"toast-plain","trigger":"rich-notifications","description":"Plain text stays escaped","color":"white","duration":0}, - {"component":"button"}, - {"title":"Show rich notifications","link":"#rich-notifications"} - ]')), - ('toast', 'Several persistent queued notifications. Toasts with the same position share a container and stack instead of overlapping.', json('[ - {"component":"toast","id":"toast-stack-one","trigger":"queued notifications","title":"Import started","description":"Preparing records.","duration":0}, - {"component":"toast","id":"toast-stack-two","trigger":"queued notifications","title":"Import running","description":"Processing records.","duration":0}, - {"component":"toast","id":"toast-short","trigger":"queued notifications","title":"Temporary update","description":"This message closes shortly.","duration":2000}, - {"component":"button"}, - {"title":"Show queued notifications","link":"#queued notifications"} - ]')), - ('toast', 'A notification placed at the bottom center of the screen instead of the default top end.', json('[ - {"component":"toast","id":"toast-bottom-center","trigger":"bottom-notification","title":"Download ready","description":"Your export is ready.","position":"bottom-center","duration":0}, - {"component":"button"}, - {"title":"Show bottom notification","link":"#bottom-notification"} - ]')); diff --git a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql index 3f5be829d..c5f7f8a8f 100644 --- a/examples/official-site/sqlpage/migrations/82_reference_catalog.sql +++ b/examples/official-site/sqlpage/migrations/82_reference_catalog.sql @@ -146,7 +146,8 @@ WITH entries AS ( SELECT 'component' AS kind, name, icon, catalog_category, catalog_summary, description AS description_md, introduced_in_version, NULL AS return_type, '/component.sql?component=' || name AS link, - (SELECT count(*) FROM example WHERE example.component = component.name) AS example_count, + (SELECT count(*) FROM example WHERE example.component = component.name) + + (SELECT count(*) FROM native_example WHERE native_example.component = component.name) AS example_count, NULL AS arguments FROM component UNION ALL diff --git a/examples/official-site/sqlpage/migrations/999_fts_search_index.sql b/examples/official-site/sqlpage/migrations/999_fts_search_index.sql index ee0ba09e8..d85b76ff4 100644 --- a/examples/official-site/sqlpage/migrations/999_fts_search_index.sql +++ b/examples/official-site/sqlpage/migrations/999_fts_search_index.sql @@ -21,5 +21,10 @@ SELECT component || ' component example', description, properties, e.link, 'exam FROM example_with_source AS x JOIN reference_entry AS e ON e.kind = 'component' AND e.name = x.component; +INSERT INTO documentation_fts(title, description, example_source, page, fragment) +SELECT x.title, x.description, x.source, e.link, 'example-' || x.number +FROM native_example AS x +JOIN reference_entry AS e ON e.kind = 'component' AND e.name = x.component; + INSERT INTO documentation_fts(title, description, page, parameters) SELECT title, description, '/blog.sql', json_object('post', title) FROM blog_posts; diff --git a/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql b/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql index 712cb683f..073582957 100644 --- a/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql +++ b/examples/official-site/sqlpage/migrations/99_shared_id_class_attributes.sql @@ -13,17 +13,14 @@ INSERT INTO parameter(component, top_level, name, description, type, optional) SELECT *, 'id', 'id attribute added to the container in HTML. It can be used to target this item through css or for scrolling to this item through links (use "#id" in link url).', 'TEXT', TRUE FROM (VALUES - ('alert', TRUE), ('big_number', TRUE), ('big_number', FALSE), ('breadcrumb', TRUE), ('card', FALSE), ('chart', TRUE), - ('code', TRUE), ('csv', TRUE), ('datagrid', TRUE), ('datagrid', FALSE), - ('empty_state', TRUE), ('hero', TRUE), ('list', TRUE), ('list', FALSE), @@ -35,7 +32,6 @@ FROM (VALUES ('timeline', TRUE), ('timeline', FALSE), ('title', TRUE), - ('toast', TRUE), ('tracking', TRUE), ('text', TRUE), ('carousel', TRUE), @@ -53,7 +49,6 @@ FROM (VALUES INSERT INTO parameter(component, top_level, name, description, type, optional) SELECT *, 'class', 'class attribute added to the container in HTML. It can be used to apply custom styling to this item through css. Added in v0.18.0.', 'TEXT', TRUE FROM (VALUES - ('alert', TRUE), ('big_number', TRUE), ('big_number', FALSE), ('breadcrumb', TRUE), @@ -61,11 +56,8 @@ FROM (VALUES ('card', TRUE), ('card', FALSE), ('chart', TRUE), - ('code', TRUE), ('csv', TRUE), ('datagrid', TRUE), - ('divider', TRUE), - ('empty_state', TRUE), ('form', TRUE), ('list', TRUE), ('list', FALSE), @@ -78,7 +70,6 @@ FROM (VALUES ('timeline', TRUE), ('timeline', FALSE), ('title', TRUE), - ('toast', TRUE), ('tracking', TRUE), ('carousel', TRUE), ('login', TRUE), diff --git a/examples/official-site/sqlpage/templates/docs-example.handlebars b/examples/official-site/sqlpage/templates/docs-example.handlebars index 4d637c5e2..87e71c7cf 100644 --- a/examples/official-site/sqlpage/templates/docs-example.handlebars +++ b/examples/official-site/sqlpage/templates/docs-example.handlebars @@ -20,7 +20,9 @@ {{/if}} {{#if preview}}
-

{{icon_img "player-play" 16}} Result

+

{{icon_img "player-play" 16}} Result + {{#if demo_link}} · Open demo{{/if}} +

{{else}} diff --git a/scripts/site-build.mjs b/scripts/site-build.mjs index 96a3d5c90..dc78f8d78 100644 --- a/scripts/site-build.mjs +++ b/scripts/site-build.mjs @@ -8,6 +8,7 @@ import { rmSync, } from "node:fs"; import { dirname, join, relative, resolve } from "node:path"; +import { writeExampleCatalog } from "./site-doc-examples.mjs"; const repository = resolve(import.meta.dirname, ".."); const siteDirectory = join(repository, "target", "official-site"); @@ -36,6 +37,7 @@ function buildSite() { join(repository, "configuration.md"), join(next, "configuration.md"), ); + writeExampleCatalog(next, join(repository, "sqlpage/templates")); // Stage the complete site before exchanging the previous preview. try { renameSync(siteDirectory, previous); diff --git a/scripts/site-doc-examples.mjs b/scripts/site-doc-examples.mjs new file mode 100644 index 000000000..a7a6df2c4 --- /dev/null +++ b/scripts/site-doc-examples.mjs @@ -0,0 +1,86 @@ +import { readdirSync, readFileSync, writeFileSync } from "node:fs"; +import { join } from "node:path"; + +function literal(value) { + return typeof value === "number" + ? String(value) + : `'${value.replaceAll("'", "''")}'`; +} + +function insert(table, columns, values) { + return `INSERT INTO ${table} (${columns}) VALUES (${values.map(literal).join(", ")});`; +} + +// Only the metadata is generated. The executable SQL files are copied verbatim. +export function writeExampleCatalog(site, templates) { + const sql = ["-- Generated component parameters and native example index."]; + const components = new Set(); + + for (const file of readdirSync(templates).sort()) { + if (!file.endsWith(".handlebars")) continue; + const name = file.slice(0, -".handlebars".length); + const template = readFileSync(join(templates, file), "utf8"); + if (!template.startsWith("{{!-- @doc")) continue; + const block = /^\{\{!-- @doc\r?\n([\s\S]*?)\r?\n--\}\}/.exec(template); + if (!block) throw new Error(`Invalid @doc block in ${file}`); + components.add(name); + const seen = new Set(); + for (const line of block[1].split(/\r?\n/).filter((line) => line.trim())) { + const field = /^(top|row) (\w+) ([A-Z]+) (required|optional): (.+)$/.exec( + line, + ); + if (!field) throw new Error(`Invalid @doc line in ${file}: ${line}`); + const [, level, parameter, type, presence, description] = field; + const key = `${level}.${parameter}`; + if (seen.has(key)) + throw new Error(`Duplicate parameter ${key} in ${file}`); + seen.add(key); + sql.push( + insert( + "parameter", + "component, top_level, name, type, optional, description_md", + [ + name, + Number(level === "top"), + parameter, + type, + Number(presence === "optional"), + description, + ], + ), + ); + } + } + + const exampleKeys = new Set(); + for (const file of readdirSync(join(site, "doc-examples")).sort()) { + const parts = /^([a-z][a-z0-9_]*)\.([1-9]\d*|0[1-9])\.sql$/.exec(file); + if (!parts) throw new Error(`Expected ..sql: ${file}`); + const [, name, digits] = parts; + const number = Number(digits); + if (!Number.isSafeInteger(number)) + throw new Error(`Invalid example number: ${file}`); + if (!components.has(name)) throw new Error(`No @doc template for ${file}`); + const key = `${name}.${number}`; + if (exampleKeys.has(key)) + throw new Error(`Duplicate example number: ${file}`); + exampleKeys.add(key); + const path = `doc-examples/${file}`; + const source = readFileSync(join(site, path), "utf8"); + const header = /^\/\*\s*([^\r\n]+)([\s\S]*?)\*\//.exec(source); + if (!header?.[1].trim() || !source.slice(header[0].length).trim()) { + throw new Error(`Expected a title comment and runnable SQL: ${file}`); + } + sql.push( + insert( + "native_example", + "component, number, title, description, path, source", + [name, number, header[1].trim(), header[2].trim(), path, source], + ), + ); + } + writeFileSync( + join(site, "sqlpage/migrations/100_native_doc_examples.sql"), + `${sql.join("\n")}\n`, + ); +} diff --git a/sqlpage/templates/alert.handlebars b/sqlpage/templates/alert.handlebars index 5c4660f4f..93d356b15 100644 --- a/sqlpage/templates/alert.handlebars +++ b/sqlpage/templates/alert.handlebars @@ -1,4 +1,20 @@ -