@andesine/extensions 0.0.0-stage → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +65 -0
- package/LICENSE +21 -0
- package/README.md +104 -3
- package/dist/index.d.ts +289 -0
- package/dist/index.js +173 -0
- package/dist/index.js.map +1 -0
- package/dist/solid.d.ts +397 -0
- package/dist/solid.js +558 -0
- package/dist/solid.js.map +1 -0
- package/package.json +60 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../private/contracts/src/primitives/unique.ts","../../../private/contracts/src/extensions/configuration.ts","../src/index.ts"],"sourcesContent":["const uniqueItems = <T>(values: T[]): boolean => new Set(values).size === values.length;\n\nexport { uniqueItems };\n","import * as z from \"zod\";\nimport { uniqueItems } from \"../primitives/unique\";\n\ntype ExtensionConfiguration = z.output<typeof extensionConfigurationType>;\ntype ExtensionConfigurationField = ExtensionConfiguration[\"properties\"][string];\ntype ExtensionConfigurationItem = Exclude<ExtensionConfigurationField, { type: \"array\" }>;\ntype ExtensionConfigurationPrimitive = string | number | boolean;\ntype ExtensionConfigurationValue =\n ExtensionConfigurationPrimitive | ExtensionConfigurationPrimitive[];\n\nconst JSON_SCHEMA_DIALECT = \"https://json-schema.org/draft/2020-12/schema\";\nconst MAX_CONFIGURATION_FIELDS = 50;\nconst MAX_CONFIGURATION_STRING_LENGTH = 10_000;\nconst MAX_CONFIGURATION_ARRAY_ITEMS = 100;\nconst MAX_CONFIGURATION_ENUM_VALUES = 100;\nconst MAX_CONFIGURATION_PATTERN_LENGTH = 500;\nconst isValidPattern = (pattern: string): boolean => {\n try {\n new RegExp(pattern);\n\n return true;\n } catch {\n return false;\n }\n};\nconst fieldKeyType = z\n .string()\n .regex(/^[A-Za-z][A-Za-z0-9_]{0,63}$/, \"Use a letter, then letters, digits, or underscores\");\nconst lengthType = z.int().min(0).max(MAX_CONFIGURATION_STRING_LENGTH);\nconst metadata = {\n title: z.string().min(1).max(100).optional(),\n description: z.string().min(1).max(500).optional()\n};\nconst stringItemType = z.strictObject({\n type: z.literal(\"string\"),\n minLength: lengthType.optional(),\n maxLength: lengthType.optional(),\n pattern: z\n .string()\n .min(1)\n .max(MAX_CONFIGURATION_PATTERN_LENGTH)\n .refine(isValidPattern, \"Use a valid regular expression\")\n .optional(),\n format: z.enum([\"uri\", \"email\"]).optional()\n});\nconst enumItemType = z.strictObject({\n type: z.literal(\"string\"),\n enum: z\n .array(z.string().min(1).max(200))\n .min(1)\n .max(MAX_CONFIGURATION_ENUM_VALUES)\n .refine(uniqueItems, \"Options must be unique\")\n});\nconst numberItemType = z.strictObject({\n type: z.enum([\"number\", \"integer\"]),\n minimum: z.number().optional(),\n maximum: z.number().optional(),\n exclusiveMinimum: z.number().optional(),\n exclusiveMaximum: z.number().optional(),\n multipleOf: z.number().positive().optional()\n});\nconst booleanItemType = z.strictObject({ type: z.literal(\"boolean\") });\nconst stringFormatTypes = { uri: z.url(), email: z.email() };\nconst itemType = z.union([stringItemType, enumItemType, numberItemType, booleanItemType]);\nconst fieldType = z.union([\n stringItemType.extend({\n ...metadata,\n default: z.string().optional(),\n // Secret values are write-only and readable only by the extension backend.\n secret: z.literal(true).optional(),\n control: z.literal(\"textarea\").optional()\n }),\n enumItemType.extend({ ...metadata, default: z.string().optional() }),\n numberItemType.extend({ ...metadata, default: z.number().optional() }),\n booleanItemType.extend({ ...metadata, default: z.boolean().optional() }),\n z.strictObject({\n ...metadata,\n type: z.literal(\"array\"),\n items: itemType,\n minItems: z.int().min(0).max(MAX_CONFIGURATION_ARRAY_ITEMS).optional(),\n maxItems: z.int().min(0).max(MAX_CONFIGURATION_ARRAY_ITEMS).optional(),\n uniqueItems: z.boolean().optional(),\n default: z.array(z.union([z.string(), z.number(), z.boolean()])).optional()\n })\n]);\n/** Flat JSON Schema 2020-12 subset; the host validates it without running extension code. */\nconst extensionConfigurationType = z\n .strictObject({\n $schema: z.literal(JSON_SCHEMA_DIALECT).optional(),\n type: z.literal(\"object\"),\n properties: z\n .record(fieldKeyType, fieldType)\n .refine(\n (properties) => Object.keys(properties).length <= MAX_CONFIGURATION_FIELDS,\n `Use at most ${MAX_CONFIGURATION_FIELDS} fields`\n ),\n required: z.array(fieldKeyType).refine(uniqueItems, \"Fields must be unique\").optional(),\n additionalProperties: z.literal(false)\n })\n .superRefine((configuration, context) => {\n for (const [index, key] of (configuration.required || []).entries()) {\n if (!configuration.properties[key]) {\n context.addIssue({ code: \"custom\", path: [\"required\", index], message: \"Unknown field\" });\n }\n }\n\n for (const [key, field] of Object.entries(configuration.properties)) {\n const isSecretWithDefault = \"secret\" in field && field.secret && field.default !== undefined;\n\n if (isSecretWithDefault) {\n context.addIssue({\n code: \"custom\",\n path: [\"properties\", key, \"default\"],\n message: \"Secret fields cannot have defaults\"\n });\n } else if (field.default !== undefined) {\n const result = createConfigurationValueType(field).safeParse(field.default);\n\n if (!result.success) {\n context.addIssue({\n code: \"custom\",\n path: [\"properties\", key, \"default\"],\n message: \"The default does not match the field\"\n });\n }\n }\n }\n });\nconst createConfigurationValueType = (\n field: ExtensionConfigurationField | ExtensionConfigurationItem\n): z.ZodType<ExtensionConfigurationValue> => {\n if (field.type === \"boolean\") return z.boolean();\n\n if (field.type === \"array\") {\n const maxItems = Math.min(\n field.maxItems ?? MAX_CONFIGURATION_ARRAY_ITEMS,\n MAX_CONFIGURATION_ARRAY_ITEMS\n );\n const items = z\n .array(\n createConfigurationValueType(field.items) as z.ZodType<ExtensionConfigurationPrimitive>\n )\n .min(field.minItems ?? 0)\n .max(maxItems);\n\n return field.uniqueItems ? items.refine(uniqueItems, \"Values must be unique\") : items;\n }\n\n if (\"enum\" in field) return z.enum(field.enum as [string, ...string[]]);\n\n if (field.type === \"string\") {\n const maxLength = Math.min(\n field.maxLength ?? MAX_CONFIGURATION_STRING_LENGTH,\n MAX_CONFIGURATION_STRING_LENGTH\n );\n const value = (field.format ? stringFormatTypes[field.format] : z.string())\n .min(field.minLength ?? 0)\n .max(maxLength);\n\n return field.pattern ? value.regex(new RegExp(field.pattern)) : value;\n }\n\n let value = field.type === \"integer\" ? z.int() : z.number();\n\n if (field.minimum !== undefined) value = value.gte(field.minimum);\n\n if (field.maximum !== undefined) value = value.lte(field.maximum);\n\n if (field.exclusiveMinimum !== undefined) value = value.gt(field.exclusiveMinimum);\n\n if (field.exclusiveMaximum !== undefined) value = value.lt(field.exclusiveMaximum);\n\n if (field.multipleOf !== undefined) value = value.multipleOf(field.multipleOf);\n\n return value;\n};\n/** Known fields only; missing required fields are a state, not a validation error. */\nconst createConfigurationValuesType = (\n configuration: ExtensionConfiguration\n): z.ZodType<Record<string, ExtensionConfigurationValue>> => {\n const shape = Object.fromEntries(\n Object.entries(configuration.properties).map(([key, field]) => {\n return [key, createConfigurationValueType(field).optional()];\n })\n );\n\n return z.strictObject(shape) as z.ZodType<Record<string, ExtensionConfigurationValue>>;\n};\n/** Converts an authoring Zod object to the configuration subset; unsupported constructs throw. */\nconst toExtensionConfiguration = (schema: z.ZodObject): ExtensionConfiguration => {\n const jsonSchema = z.toJSONSchema(schema, {\n io: \"input\",\n target: \"draft-2020-12\",\n unrepresentable: \"throw\"\n });\n const result = extensionConfigurationType.safeParse({\n additionalProperties: false,\n ...jsonSchema\n });\n\n if (!result.success) {\n throw new Error(`Unsupported configuration schema:\\n${z.prettifyError(result.error)}`);\n }\n\n return result.data;\n};\n\nexport {\n MAX_CONFIGURATION_FIELDS,\n extensionConfigurationType,\n createConfigurationValueType,\n createConfigurationValuesType,\n toExtensionConfiguration\n};\nexport type { ExtensionConfiguration, ExtensionConfigurationField, ExtensionConfigurationValue };\n","import { type extensionManifestType } from \"@andesine/contracts/extensions\";\n// The configuration module alone, so the bundle carries no other contracts code.\nimport {\n type ExtensionConfiguration,\n toExtensionConfiguration\n} from \"@andesine/contracts/extensions/configuration\";\nimport type * as z from \"zod\";\n\ninterface ExtensionDefinition extends Omit<ExtensionManifestInput, \"configuration\"> {\n /** A Zod object of flat fields, or the configuration schema it converts to. */\n configuration?: z.ZodObject | ExtensionConfiguration;\n}\n/** Options of `andesine extensions build`, exported from the config file as `build`. */\ninterface ExtensionBuildOptions {\n /** The module exporting the manifest's view entries (default: `src/frontend/index.tsx`). */\n frontend?: string;\n /** Custom icon sets: a set prefix and a directory of SVG files, e.g. `{ acme: \"./icons\" }`. */\n icons?: Record<string, string>;\n}\n\ntype ExtensionManifestInput = z.input<typeof extensionManifestType>;\n\nconst isZodObject = (value: object): value is z.ZodObject => \"_zod\" in value;\n/** Defines the `andesine.config.ts` manifest; a Zod configuration becomes JSON Schema. */\nconst defineExtension = (definition: ExtensionDefinition): ExtensionManifestInput => {\n const { configuration, ...manifest } = definition;\n\n if (!configuration) return manifest;\n\n return {\n ...manifest,\n configuration: isZodObject(configuration)\n ? toExtensionConfiguration(configuration)\n : configuration\n };\n};\nconst defineBuild = (options: ExtensionBuildOptions): ExtensionBuildOptions => options;\n\nexport { defineExtension, defineBuild };\nexport type { ExtensionDefinition, ExtensionBuildOptions, ExtensionManifestInput };\n"],"mappings":";;AAAA,MAAM,eAAkB,WAAyB,IAAI,IAAI,MAAM,CAAC,CAAC,SAAS,OAAO;;;ACUjF,MAAM,sBAAsB;AAE5B,MAAM,kCAAkC;AACxC,MAAM,gCAAgC;AACtC,MAAM,gCAAgC;AACtC,MAAM,mCAAmC;AACzC,MAAM,kBAAkB,YAA6B;CACnD,IAAI;EACF,IAAI,OAAO,OAAO;EAElB,OAAO;CACT,QAAQ;EACN,OAAO;CACT;AACF;AACA,MAAM,eAAe,EAClB,OAAO,CAAC,CACR,MAAM,gCAAgC,oDAAoD;AAC7F,MAAM,aAAa,EAAE,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,+BAA+B;AACrE,MAAM,WAAW;CACf,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,SAAS;CAC3C,aAAa,EAAE,OA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AAS;EAEhB,OAAO,MAAM,UAAU,MAAM,MAAM,IAAI,OAAO,MAAM,OAAO,CAAC,IAAI;CAClE;CAEA,IAAI,QAAQ,MAAM,SAAS,YAAY,EAAE,IAAI,IAAI,EAAE,OAAO;CAE1D,IAAI,MAAM,YAAY,KAAA,GAAW,QAAQ,MAAM,IAAI,MAAM,OAAO;CAEhE,IAAI,MAAM,YAAY,KAAA,GAAW,QAAQ,MAAM,IAAI,MAAM,OAAO;CAEhE,IAAI,MAAM,qBAAqB,KAAA,GAAW,QAAQ,MAAM,GAAG,MAAM,gBAAgB;CAEjF,IAAI,MAAM,qBAAqB,KAAA,GAAW,QAAQ,MAAM,GAAG,MAAM,gBAAgB;CAEjF,IAAI,MAAM,eAAe,KAAA,GAAW,QAAQ,MAAM,WAAW,MAAM,UAAU;CAE7E,OAAO;AACT;;AAcA,MAAM,4BAA4B,WAAgD;CAChF,MAAM,aAAa,EAAE,aAAa,QAAQ;EACxC,IAAI;EACJ,QAAQ;EACR,iBAAiB;CACnB,CAAC;CACD,MAAM,SAAS,2BAA2B,UAAU;EAClD,sBAAsB;EACtB,GAAG;CACL,CAAC;CAED,IAAI,CAAC,OAAO,SACV,MAAM,IAAI,MAAM,sCAAsC,EAAE,cAAc,OAAO,KAAK,GAAG;CAGvF,OAAO,OAAO;AAChB;;;ACvLA,MAAM,eAAe,UAAwC,UAAU;;AAEvE,MAAM,mBAAmB,eAA4D;CACnF,MAAM,EAAE,eAAe,GAAG,aAAa;CAEvC,IAAI,CAAC,eAAe,OAAO;CAE3B,OAAO;EACL,GAAG;EACH,eAAe,YAAY,aAAa,IACpC,yBAAyB,aAAa,IACtC;CACN;AACF;AACA,MAAM,eAAe,YAA0D"}
|
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,397 @@
|
|
|
1
|
+
import { Component, JSX } from "solid-js";
|
|
2
|
+
//#region src/solid/protocol.d.ts
|
|
3
|
+
type RequestErrorCode = "invalid_request" | "forbidden" | "too_many_requests" | "user_interaction_required" | "unavailable" | "failed";
|
|
4
|
+
type JSONValue = string | number | boolean | null | JSONValue[] | {
|
|
5
|
+
[key: string]: JSONValue;
|
|
6
|
+
};
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/solid/renderer.d.ts
|
|
9
|
+
/** A node of the serialized view tree; it mirrors the host tree, which has the real DOM. */
|
|
10
|
+
interface ViewNode {
|
|
11
|
+
id: number;
|
|
12
|
+
type: string;
|
|
13
|
+
parent?: ViewNode;
|
|
14
|
+
children: ViewNode[];
|
|
15
|
+
callbacks: Map<string, number>;
|
|
16
|
+
}
|
|
17
|
+
export declare const render: (code: () => ViewNode, node: ViewNode) => () => void, effect: <T>(fn: (prev?: T) => T, init?: T) => void, memo: <T>(fn: () => T, equal: boolean) => () => T, createComponent: <T>(Comp: (props: T) => ViewNode, props: T) => ViewNode, createElement: (tag: string) => ViewNode, createTextNode: (value: string) => ViewNode, insertNode: (parent: ViewNode, node: ViewNode, anchor?: ViewNode | undefined) => void, insert: <T>(parent: any, accessor: T | (() => T), marker?: any | null, initial?: any) => ViewNode, spread: <T>(node: any, accessor: (() => T) | T, skipChildren?: boolean) => void, setProp: <T>(node: ViewNode, name: string, value: T, prev?: T | undefined) => T, mergeProps: (...sources: unknown[]) => unknown, use: <A, T>(fn: (element: ViewNode, arg: A) => T, element: ViewNode, arg: A) => T;
|
|
18
|
+
//#endregion
|
|
19
|
+
//#region src/solid/components.d.ts
|
|
20
|
+
interface ParentProps {
|
|
21
|
+
children?: JSX.Element;
|
|
22
|
+
}
|
|
23
|
+
interface StyleProps {
|
|
24
|
+
/** Utility classes of the Andesine UnoCSS preset; the extension build generates their CSS. */
|
|
25
|
+
class?: string;
|
|
26
|
+
}
|
|
27
|
+
interface ButtonBaseProps {
|
|
28
|
+
/** Defaults to `secondary` for buttons and `ghost` for icon buttons. */
|
|
29
|
+
variant?: "primary" | "secondary" | "ghost" | "link" | "danger";
|
|
30
|
+
size?: "small" | "medium";
|
|
31
|
+
disabled?: boolean;
|
|
32
|
+
onClick?(): void;
|
|
33
|
+
}
|
|
34
|
+
interface FieldProps {
|
|
35
|
+
value?: string;
|
|
36
|
+
placeholder?: string;
|
|
37
|
+
label?: string;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
onInput?(value: string): void;
|
|
40
|
+
}
|
|
41
|
+
interface Option {
|
|
42
|
+
value: string;
|
|
43
|
+
label: string;
|
|
44
|
+
}
|
|
45
|
+
interface ChoiceProps {
|
|
46
|
+
value?: string;
|
|
47
|
+
options: Option[];
|
|
48
|
+
placeholder?: string;
|
|
49
|
+
disabled?: boolean;
|
|
50
|
+
onChange?(value: string): void;
|
|
51
|
+
}
|
|
52
|
+
interface ToggleProps {
|
|
53
|
+
checked?: boolean;
|
|
54
|
+
label?: string;
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
onChange?(checked: boolean): void;
|
|
57
|
+
}
|
|
58
|
+
interface StackProps extends ParentProps, StyleProps {
|
|
59
|
+
direction?: "row" | "column";
|
|
60
|
+
gap?: Gap;
|
|
61
|
+
align?: "start" | "center" | "end" | "stretch";
|
|
62
|
+
justify?: "start" | "center" | "end" | "between";
|
|
63
|
+
wrap?: boolean;
|
|
64
|
+
}
|
|
65
|
+
interface GridProps extends ParentProps, StyleProps {
|
|
66
|
+
columns?: number;
|
|
67
|
+
gap?: Gap;
|
|
68
|
+
}
|
|
69
|
+
interface BoxProps extends ParentProps, StyleProps {
|
|
70
|
+
padding?: Gap;
|
|
71
|
+
background?: "none" | "soft" | "contrast";
|
|
72
|
+
border?: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface ScrollAreaProps extends ParentProps {
|
|
75
|
+
maxHeight?: Size;
|
|
76
|
+
}
|
|
77
|
+
interface TextProps extends ParentProps, StyleProps {
|
|
78
|
+
size?: "xs" | "sm" | "base" | "lg";
|
|
79
|
+
weight?: "normal" | "medium" | "semibold";
|
|
80
|
+
tone?: Tone;
|
|
81
|
+
}
|
|
82
|
+
interface HeadingProps extends ParentProps, StyleProps {
|
|
83
|
+
level?: 1 | 2 | 3;
|
|
84
|
+
}
|
|
85
|
+
interface LinkProps extends ParentProps {
|
|
86
|
+
/** An `https:` URL within the extension's declared request URLs. */
|
|
87
|
+
href: string;
|
|
88
|
+
}
|
|
89
|
+
interface BadgeProps extends ParentProps {
|
|
90
|
+
color?: "base" | "primary" | "danger" | "success";
|
|
91
|
+
}
|
|
92
|
+
interface IconProps {
|
|
93
|
+
/** An icon class, e.g. `i-lucide:rocket`, or `i-acme:logo?bg` for a colored icon. */
|
|
94
|
+
name: string;
|
|
95
|
+
size?: Size;
|
|
96
|
+
tone?: Tone;
|
|
97
|
+
}
|
|
98
|
+
interface ButtonProps extends ButtonBaseProps, ParentProps {
|
|
99
|
+
loading?: boolean;
|
|
100
|
+
}
|
|
101
|
+
interface IconButtonProps extends ButtonBaseProps {
|
|
102
|
+
icon: string;
|
|
103
|
+
label: string;
|
|
104
|
+
}
|
|
105
|
+
interface InputProps extends FieldProps {
|
|
106
|
+
type?: "text" | "url" | "number";
|
|
107
|
+
onEnter?(): void;
|
|
108
|
+
}
|
|
109
|
+
interface TextareaProps extends FieldProps {
|
|
110
|
+
rows?: number;
|
|
111
|
+
}
|
|
112
|
+
interface ToggleGroupProps {
|
|
113
|
+
value?: string;
|
|
114
|
+
options: Option[];
|
|
115
|
+
disabled?: boolean;
|
|
116
|
+
onChange?(value: string): void;
|
|
117
|
+
}
|
|
118
|
+
interface ColorInputProps {
|
|
119
|
+
/** A hex color, e.g. `#ff3617`. */
|
|
120
|
+
value?: string;
|
|
121
|
+
disabled?: boolean;
|
|
122
|
+
onInput?(value: string): void;
|
|
123
|
+
}
|
|
124
|
+
interface TooltipProps extends ParentProps {
|
|
125
|
+
content: string;
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* A modal, shown while rendered. Outside block actions, render it right after an interaction,
|
|
129
|
+
* e.g. from `onClick`; otherwise it isn't shown. In a block action, closing it closes the action.
|
|
130
|
+
*/
|
|
131
|
+
interface DialogProps extends ParentProps {
|
|
132
|
+
title: string;
|
|
133
|
+
description?: string;
|
|
134
|
+
size?: Size;
|
|
135
|
+
/** Whether Escape, an outside click, or the close button call `onClose` (default true). */
|
|
136
|
+
dismissible?: boolean;
|
|
137
|
+
onClose?(): void;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* A dropdown menu of `MenuItem`, `MenuGroup`, `MenuSeparator`, and `MenuContent` children,
|
|
141
|
+
* opened by its `MenuTrigger`, or with `contextMenu` by a right click on it. At a block action
|
|
142
|
+
* view's root it needs no trigger: it opens where the block menu was, and closing it closes the action.
|
|
143
|
+
*/
|
|
144
|
+
interface MenuProps extends ParentProps {
|
|
145
|
+
/** The title of the bottom sheet on small screens. */
|
|
146
|
+
title?: string;
|
|
147
|
+
/** Controls the open state; without it, the menu opens and closes on its own. */
|
|
148
|
+
opened?: boolean;
|
|
149
|
+
contextMenu?: boolean;
|
|
150
|
+
placement?: "bottom-start" | "bottom-end" | "top-start" | "top-end" | "right-start" | "left-start";
|
|
151
|
+
size?: "small" | "medium";
|
|
152
|
+
onOpenChange?(opened: boolean): void;
|
|
153
|
+
}
|
|
154
|
+
/** Nested items make a submenu, which replaces `onSelect`. */
|
|
155
|
+
interface MenuItemProps extends ParentProps {
|
|
156
|
+
label: string;
|
|
157
|
+
icon?: string;
|
|
158
|
+
/** Shown next to the label; handle the keys yourself. */
|
|
159
|
+
shortcut?: string;
|
|
160
|
+
color?: "base" | "danger";
|
|
161
|
+
disabled?: boolean;
|
|
162
|
+
/** A spinner replaces the icon, and the item is disabled. */
|
|
163
|
+
loading?: boolean;
|
|
164
|
+
selected?: boolean;
|
|
165
|
+
closeOnSelect?: boolean;
|
|
166
|
+
onSelect?(): void;
|
|
167
|
+
}
|
|
168
|
+
interface MenuGroupProps extends ParentProps {
|
|
169
|
+
label?: string;
|
|
170
|
+
}
|
|
171
|
+
interface SettingProps extends ParentProps {
|
|
172
|
+
label: string;
|
|
173
|
+
description?: string;
|
|
174
|
+
}
|
|
175
|
+
interface ListProps extends ParentProps {
|
|
176
|
+
addLabel?: string;
|
|
177
|
+
emptyLabel?: string;
|
|
178
|
+
disabled?: boolean;
|
|
179
|
+
onAdd?(): void;
|
|
180
|
+
onRemove?(index: number): void;
|
|
181
|
+
onMove?(from: number, to: number): void;
|
|
182
|
+
}
|
|
183
|
+
interface CardProps extends ParentProps {
|
|
184
|
+
color?: "base" | "contrast" | "soft";
|
|
185
|
+
}
|
|
186
|
+
interface TreeItem {
|
|
187
|
+
id: string;
|
|
188
|
+
label: string;
|
|
189
|
+
icon?: string;
|
|
190
|
+
/** The parent item ID; top level when unset. */
|
|
191
|
+
parent?: string;
|
|
192
|
+
}
|
|
193
|
+
interface TreeProps {
|
|
194
|
+
items: TreeItem[];
|
|
195
|
+
selected?: string;
|
|
196
|
+
emptyLabel?: string;
|
|
197
|
+
onSelect?(id: string): void;
|
|
198
|
+
}
|
|
199
|
+
interface TabsProps extends ParentProps {
|
|
200
|
+
value?: string;
|
|
201
|
+
onChange?(value: string): void;
|
|
202
|
+
}
|
|
203
|
+
interface TabProps extends ParentProps {
|
|
204
|
+
value: string;
|
|
205
|
+
label: string;
|
|
206
|
+
}
|
|
207
|
+
interface DisclosureProps extends ParentProps {
|
|
208
|
+
label: string;
|
|
209
|
+
open?: boolean;
|
|
210
|
+
}
|
|
211
|
+
interface CalloutProps extends ParentProps {
|
|
212
|
+
tone?: "info" | "warning" | "danger" | "success";
|
|
213
|
+
title?: string;
|
|
214
|
+
}
|
|
215
|
+
interface StepProps extends ParentProps {
|
|
216
|
+
title: string;
|
|
217
|
+
}
|
|
218
|
+
interface FigureProps {
|
|
219
|
+
/** An `https:` image URL within the extension's declared request URLs. */
|
|
220
|
+
src: string;
|
|
221
|
+
alt: string;
|
|
222
|
+
caption?: string;
|
|
223
|
+
}
|
|
224
|
+
interface CodeBlockProps {
|
|
225
|
+
code: string;
|
|
226
|
+
language?: string;
|
|
227
|
+
}
|
|
228
|
+
interface TimeAgoProps {
|
|
229
|
+
/** An ISO date-time. */
|
|
230
|
+
date: string;
|
|
231
|
+
}
|
|
232
|
+
interface SpinnerProps {
|
|
233
|
+
size?: Size;
|
|
234
|
+
}
|
|
235
|
+
interface SkeletonProps {
|
|
236
|
+
height?: Size;
|
|
237
|
+
}
|
|
238
|
+
type Gap = "none" | "small" | "medium" | "large";
|
|
239
|
+
type Size = "small" | "medium" | "large";
|
|
240
|
+
type Tone = "default" | "muted" | "danger" | "success";
|
|
241
|
+
type EmptyProps = Record<string, never>;
|
|
242
|
+
declare const Stack: (props: StackProps) => JSX.Element;
|
|
243
|
+
declare const Grid: (props: GridProps) => JSX.Element;
|
|
244
|
+
declare const Box: (props: BoxProps) => JSX.Element;
|
|
245
|
+
declare const Divider: (props: EmptyProps) => JSX.Element;
|
|
246
|
+
declare const ScrollArea: (props: ScrollAreaProps) => JSX.Element;
|
|
247
|
+
declare const Text: (props: TextProps) => JSX.Element;
|
|
248
|
+
declare const Heading: (props: HeadingProps) => JSX.Element;
|
|
249
|
+
declare const Code: (props: ParentProps) => JSX.Element;
|
|
250
|
+
declare const Link: (props: LinkProps) => JSX.Element;
|
|
251
|
+
declare const Badge: (props: BadgeProps) => JSX.Element;
|
|
252
|
+
declare const Icon: (props: IconProps) => JSX.Element;
|
|
253
|
+
declare const Button: (props: ButtonProps) => JSX.Element;
|
|
254
|
+
declare const IconButton: (props: IconButtonProps) => JSX.Element;
|
|
255
|
+
declare const Input: (props: InputProps) => JSX.Element;
|
|
256
|
+
declare const Textarea: (props: TextareaProps) => JSX.Element;
|
|
257
|
+
declare const Select: (props: ChoiceProps) => JSX.Element;
|
|
258
|
+
declare const Combobox: (props: ChoiceProps) => JSX.Element;
|
|
259
|
+
declare const Checkbox: (props: ToggleProps) => JSX.Element;
|
|
260
|
+
declare const Toggle: (props: ToggleProps) => JSX.Element;
|
|
261
|
+
declare const ToggleGroup: (props: ToggleGroupProps) => JSX.Element;
|
|
262
|
+
declare const ColorInput: (props: ColorInputProps) => JSX.Element;
|
|
263
|
+
declare const Tooltip: (props: TooltipProps) => JSX.Element;
|
|
264
|
+
declare const Dialog: (props: DialogProps) => JSX.Element;
|
|
265
|
+
declare const Menu: (props: MenuProps) => JSX.Element;
|
|
266
|
+
declare const MenuTrigger: (props: ParentProps) => JSX.Element;
|
|
267
|
+
declare const MenuItem: (props: MenuItemProps) => JSX.Element;
|
|
268
|
+
declare const MenuGroup: (props: MenuGroupProps) => JSX.Element;
|
|
269
|
+
declare const MenuSeparator: (props: EmptyProps) => JSX.Element;
|
|
270
|
+
/** A custom menu item: any content, e.g. a result or a form. */
|
|
271
|
+
declare const MenuContent: (props: ParentProps) => JSX.Element;
|
|
272
|
+
declare const Setting: (props: SettingProps) => JSX.Element;
|
|
273
|
+
declare const List: (props: ListProps) => JSX.Element;
|
|
274
|
+
declare const Card: (props: CardProps) => JSX.Element;
|
|
275
|
+
declare const Tree: (props: TreeProps) => JSX.Element;
|
|
276
|
+
declare const Tabs: (props: TabsProps) => JSX.Element;
|
|
277
|
+
declare const Tab: (props: TabProps) => JSX.Element;
|
|
278
|
+
declare const Disclosure: (props: DisclosureProps) => JSX.Element;
|
|
279
|
+
declare const Callout: (props: CalloutProps) => JSX.Element;
|
|
280
|
+
declare const Steps: (props: ParentProps) => JSX.Element;
|
|
281
|
+
declare const Step: (props: StepProps) => JSX.Element;
|
|
282
|
+
declare const Figure: (props: FigureProps) => JSX.Element;
|
|
283
|
+
declare const CodeBlock: (props: CodeBlockProps) => JSX.Element;
|
|
284
|
+
declare const TimeAgo: (props: TimeAgoProps) => JSX.Element;
|
|
285
|
+
declare const Spinner: (props: SpinnerProps) => JSX.Element;
|
|
286
|
+
declare const Skeleton: (props: SkeletonProps) => JSX.Element;
|
|
287
|
+
/** Where an element view shows the element's editable content (element views only). */
|
|
288
|
+
declare const ContentSlot: (props: EmptyProps) => JSX.Element;
|
|
289
|
+
//#endregion
|
|
290
|
+
//#region src/solid/runtime.d.ts
|
|
291
|
+
type ExtensionViews = Record<string, Component<never>>;
|
|
292
|
+
/** Starts the frontend worker; `entries` maps manifest view entries to Solid components. */
|
|
293
|
+
declare const startExtension: (entries: ExtensionViews) => void;
|
|
294
|
+
//#endregion
|
|
295
|
+
//#region src/solid/actions.d.ts
|
|
296
|
+
/** Copies text; the host shows a fallback dialog if the browser refuses. */
|
|
297
|
+
declare const copyText: (text: string) => Promise<void>;
|
|
298
|
+
/** Downloads a text file, for example `downloadFile("andesine.config.ts", source)`. */
|
|
299
|
+
declare const downloadFile: (name: string, text: string, type?: string) => Promise<void>;
|
|
300
|
+
/** Opens an `https:` URL in a new tab; URLs outside the declared URLs need confirmation. */
|
|
301
|
+
declare const openURL: (url: string) => Promise<void>;
|
|
302
|
+
/** Shows a short notification, e.g. the result of a block action without UI; it needs no interaction. */
|
|
303
|
+
declare const notify: (text: string, type?: "success" | "error") => Promise<void>;
|
|
304
|
+
//#endregion
|
|
305
|
+
//#region src/solid/requests.d.ts
|
|
306
|
+
/** A host request failed; `code` says why, for example `user_interaction_required`. */
|
|
307
|
+
declare class ExtensionRequestError extends Error {
|
|
308
|
+
readonly code: RequestErrorCode;
|
|
309
|
+
constructor(code: RequestErrorCode, message: string);
|
|
310
|
+
}
|
|
311
|
+
//#endregion
|
|
312
|
+
//#region src/solid/editor.d.ts
|
|
313
|
+
/** Editor JSON block, e.g. `{ type: "paragraph", content: [{ type: "text", text: "Hi" }] }`. */
|
|
314
|
+
interface ContentNode {
|
|
315
|
+
type: string;
|
|
316
|
+
attrs?: Record<string, JSONValue>;
|
|
317
|
+
content?: ContentNode[];
|
|
318
|
+
marks?: Array<{
|
|
319
|
+
type: string;
|
|
320
|
+
attrs?: Record<string, JSONValue>;
|
|
321
|
+
}>;
|
|
322
|
+
text?: string;
|
|
323
|
+
}
|
|
324
|
+
interface ViewEditor {
|
|
325
|
+
/** Block action views: replaces the blocks the action was opened for. */
|
|
326
|
+
replace(content: ContentNode[]): Promise<void>;
|
|
327
|
+
/** Block action views: inserts blocks after those the action was opened for. */
|
|
328
|
+
insertAfter(content: ContentNode[]): Promise<void>;
|
|
329
|
+
/** Element views: updates the element's props; call it from a user interaction. */
|
|
330
|
+
setElementProps(props: Record<string, JSONValue>): Promise<void>;
|
|
331
|
+
/** Block action views: closes the view. */
|
|
332
|
+
close(): Promise<void>;
|
|
333
|
+
}
|
|
334
|
+
/** Edits the document as the member; invalid edits reject with `ExtensionRequestError`. */
|
|
335
|
+
declare const useEditor: () => ViewEditor;
|
|
336
|
+
//#endregion
|
|
337
|
+
//#region src/solid/storage.d.ts
|
|
338
|
+
interface StorageEntry<T extends JSONValue = JSONValue> {
|
|
339
|
+
key: string;
|
|
340
|
+
value: T;
|
|
341
|
+
/** An ISO date-time. */
|
|
342
|
+
updatedAt: string;
|
|
343
|
+
}
|
|
344
|
+
interface StorageListOptions {
|
|
345
|
+
/** Only keys that start with the prefix. */
|
|
346
|
+
prefix?: string;
|
|
347
|
+
/** Entries after this key, from the previous page. */
|
|
348
|
+
after?: string;
|
|
349
|
+
/** At most 100 (the default). */
|
|
350
|
+
limit?: number;
|
|
351
|
+
}
|
|
352
|
+
interface StoragePage {
|
|
353
|
+
data: StorageEntry[];
|
|
354
|
+
hasMore: boolean;
|
|
355
|
+
}
|
|
356
|
+
/**
|
|
357
|
+
* JSON key-value storage shared with the backend; the last write wins.
|
|
358
|
+
* Limits: 256-character keys, 128 KiB values, 10,000 entries, and 10 MiB in total.
|
|
359
|
+
*/
|
|
360
|
+
declare const storage: {
|
|
361
|
+
/** The entry, or null when the key is not set. */
|
|
362
|
+
get<T extends JSONValue = JSONValue>(key: string): Promise<StorageEntry<T> | null>;
|
|
363
|
+
/** Creates or replaces an entry; resolves with its update time. */
|
|
364
|
+
set(key: string, value: JSONValue): Promise<{
|
|
365
|
+
updatedAt: string;
|
|
366
|
+
}>;
|
|
367
|
+
/** Resolves with whether the key was set. */
|
|
368
|
+
delete(key: string): Promise<boolean>;
|
|
369
|
+
/** Entries in key order; a page can have fewer entries than `limit` when values are large. */
|
|
370
|
+
list(options?: StorageListOptions): Promise<StoragePage>;
|
|
371
|
+
};
|
|
372
|
+
//#endregion
|
|
373
|
+
//#region src/solid/context.d.ts
|
|
374
|
+
/** The origin `apiFetch` accepts; use it as the SDK `baseURL`. */
|
|
375
|
+
declare const EXTENSION_API_URL = "https://api.andesine.invalid";
|
|
376
|
+
/** The non-secret configuration values with defaults (reactive); only the backend reads secrets. */
|
|
377
|
+
declare const useConfiguration: <T extends Record<string, JSONValue> = Record<string, JSONValue>>() => () => Partial<T>;
|
|
378
|
+
/** The member's effective permissions for this extension (reactive), e.g. `read:entries`. */
|
|
379
|
+
declare const usePermissions: () => import("solid-js").Accessor<string[]>;
|
|
380
|
+
/** Whether the effective permissions include `permission`; a write permission includes its read. */
|
|
381
|
+
declare const hasPermission: (permission: string) => boolean;
|
|
382
|
+
/**
|
|
383
|
+
* SDK `fetch` that calls Andesine with the member's session; forbidden operations return HTTP 403.
|
|
384
|
+
* @example createClient({ baseURL: EXTENSION_API_URL, fetch: apiFetch })
|
|
385
|
+
*/
|
|
386
|
+
declare const apiFetch: typeof fetch;
|
|
387
|
+
/** The extension's own backend, as declared in the manifest. */
|
|
388
|
+
declare const backend: {
|
|
389
|
+
/**
|
|
390
|
+
* Fetches a backend path with `Authorization`, `Andesine-Extension`, and `Andesine-Instance`
|
|
391
|
+
* headers (CORS must allow them); verify them with `verifySession` of `@andesine/sdk/extensions`.
|
|
392
|
+
*/
|
|
393
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
394
|
+
};
|
|
395
|
+
//#endregion
|
|
396
|
+
export { Badge, type BadgeProps, Box, type BoxProps, Button, type ButtonProps, Callout, type CalloutProps, Card, type CardProps, Checkbox, type ChoiceProps, Code, CodeBlock, type CodeBlockProps, ColorInput, type ColorInputProps, Combobox, type ContentNode, ContentSlot, Dialog, type DialogProps, Disclosure, type DisclosureProps, Divider, EXTENSION_API_URL, type EmptyProps, ExtensionRequestError, Figure, type FigureProps, Grid, type GridProps, Heading, type HeadingProps, Icon, IconButton, type IconButtonProps, type IconProps, Input, type InputProps, Link, type LinkProps, List, type ListProps, Menu, MenuContent, MenuGroup, type MenuGroupProps, MenuItem, type MenuItemProps, type MenuProps, MenuSeparator, MenuTrigger, type Option, type ParentProps, ScrollArea, type ScrollAreaProps, Select, Setting, type SettingProps, Skeleton, type SkeletonProps, Spinner, type SpinnerProps, Stack, type StackProps, Step, type StepProps, Steps, type StorageEntry, type StorageListOptions, type StoragePage, type StyleProps, Tab, type TabProps, Tabs, type TabsProps, Text, type TextProps, Textarea, type TextareaProps, TimeAgo, type TimeAgoProps, Toggle, ToggleGroup, type ToggleGroupProps, type ToggleProps, Tooltip, type TooltipProps, Tree, type TreeItem, type TreeProps, type ViewEditor, apiFetch, backend, copyText, downloadFile, hasPermission, notify, openURL, startExtension, storage, useConfiguration, useEditor, usePermissions };
|
|
397
|
+
//# sourceMappingURL=solid.d.ts.map
|