diff --git a/docs/reference/schemas/list.md b/docs/reference/schemas/list.md index bfa48cc1..8292f210 100644 --- a/docs/reference/schemas/list.md +++ b/docs/reference/schemas/list.md @@ -2,7 +2,7 @@ ```json { - // the list of items to display (required) + // the list of items to display (optional) "items": [ { // title of the item (required) diff --git a/extensions/google.sh b/extensions/google.sh new file mode 100755 index 00000000..e572deed --- /dev/null +++ b/extensions/google.sh @@ -0,0 +1,41 @@ +#!/bin/sh + +set -eu + +if [ $# -eq 0 ]; then + sunbeam query -n '{ + title: "Google Search", + commands: [ + { + name: "search", + mode: "list", + title: "Search", + } + ] + }' + exit 0 +fi + +COMMAND=$(echo "$1" | sunbeam query -r '.command') +if [ "$COMMAND" = "search" ]; then + QUERY=$(echo "$1" | sunbeam query -r '.query') + if [ "$QUERY" = "null" ]; then + sunbeam query -n '{ + dynamic: true, + emptyText: "Type something to search", + }' + exit 0 + fi + sunbeam fetch "https://suggestqueries.google.com/complete/search?client=firefox&q=$QUERY" | sunbeam query '.[1] | { + dynamic: true, + items: map({ + title: ., + actions: [ + { title: "Search", type: "open", target: "https://www.google.com/search?q=\(.)" } + ] + }) + }' +else + echo "Unknown command: $COMMAND" >&2 + exit 1 +fi diff --git a/pkg/schemas/list.schema.json b/pkg/schemas/list.schema.json index 5c1a5851..f6c2e2ab 100644 --- a/pkg/schemas/list.schema.json +++ b/pkg/schemas/list.schema.json @@ -2,9 +2,6 @@ "$schema": "http://json-schema.org/draft-07/schema#", "type": "object", "additionalProperties": false, - "required": [ - "items" - ], "properties": { "emptyText": { "type": "string" diff --git a/pkg/typescript/package-lock.json b/pkg/typescript/package-lock.json index cace750a..665c4419 100644 --- a/pkg/typescript/package-lock.json +++ b/pkg/typescript/package-lock.json @@ -1,12 +1,12 @@ { "name": "sunbeam-types", - "version": "0.23.25", + "version": "0.23.26", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "sunbeam-types", - "version": "0.23.25", + "version": "0.23.26", "license": "MIT", "devDependencies": { "tsup": "^7.2.0", diff --git a/pkg/typescript/package.json b/pkg/typescript/package.json index 87d6ae31..2f1726a0 100644 --- a/pkg/typescript/package.json +++ b/pkg/typescript/package.json @@ -1,6 +1,6 @@ { "name": "sunbeam-types", - "version": "0.23.25", + "version": "0.23.26", "description": "Types for sunbeam", "types": "dist/mod.d.ts", "license": "MIT", diff --git a/pkg/typescript/src/page.ts b/pkg/typescript/src/page.ts index be13cd89..83010f1b 100644 --- a/pkg/typescript/src/page.ts +++ b/pkg/typescript/src/page.ts @@ -1,7 +1,7 @@ import type { Action } from "./action"; export type List = { - items: ListItem[]; + items?: ListItem[]; actions?: Action[]; emptyText?: string; dynamic?: boolean;