@andesine/extensions 0.0.0-stage → 0.5.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 +42 -0
- package/LICENSE +21 -0
- package/README.md +84 -3
- package/dist/index.d.ts +295 -0
- package/dist/index.js +177 -0
- package/dist/index.js.map +1 -0
- package/dist/solid.d.ts +356 -0
- package/dist/solid.js +555 -0
- package/dist/solid.js.map +1 -0
- package/package.json +60 -3
package/dist/solid.d.ts
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
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
|
+
variant?: "text" | "solid" | "outlined";
|
|
29
|
+
color?: "base" | "contrast" | "primary" | "danger" | "success";
|
|
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
|
+
interface SettingProps extends ParentProps {
|
|
128
|
+
label: string;
|
|
129
|
+
description?: string;
|
|
130
|
+
}
|
|
131
|
+
interface ListProps extends ParentProps {
|
|
132
|
+
addLabel?: string;
|
|
133
|
+
emptyLabel?: string;
|
|
134
|
+
disabled?: boolean;
|
|
135
|
+
onAdd?(): void;
|
|
136
|
+
onRemove?(index: number): void;
|
|
137
|
+
onMove?(from: number, to: number): void;
|
|
138
|
+
}
|
|
139
|
+
interface CardProps extends ParentProps {
|
|
140
|
+
color?: "base" | "contrast" | "soft";
|
|
141
|
+
}
|
|
142
|
+
interface TreeItem {
|
|
143
|
+
id: string;
|
|
144
|
+
label: string;
|
|
145
|
+
icon?: string;
|
|
146
|
+
/** The parent item ID; top level when unset. */
|
|
147
|
+
parent?: string;
|
|
148
|
+
}
|
|
149
|
+
interface TreeProps {
|
|
150
|
+
items: TreeItem[];
|
|
151
|
+
selected?: string;
|
|
152
|
+
emptyLabel?: string;
|
|
153
|
+
onSelect?(id: string): void;
|
|
154
|
+
}
|
|
155
|
+
interface TabsProps extends ParentProps {
|
|
156
|
+
value?: string;
|
|
157
|
+
onChange?(value: string): void;
|
|
158
|
+
}
|
|
159
|
+
interface TabProps extends ParentProps {
|
|
160
|
+
value: string;
|
|
161
|
+
label: string;
|
|
162
|
+
}
|
|
163
|
+
interface DisclosureProps extends ParentProps {
|
|
164
|
+
label: string;
|
|
165
|
+
open?: boolean;
|
|
166
|
+
}
|
|
167
|
+
interface CalloutProps extends ParentProps {
|
|
168
|
+
tone?: "info" | "warning" | "danger" | "success";
|
|
169
|
+
title?: string;
|
|
170
|
+
}
|
|
171
|
+
interface StepProps extends ParentProps {
|
|
172
|
+
title: string;
|
|
173
|
+
}
|
|
174
|
+
interface FigureProps {
|
|
175
|
+
/** An `https:` image URL within the extension's declared request URLs. */
|
|
176
|
+
src: string;
|
|
177
|
+
alt: string;
|
|
178
|
+
caption?: string;
|
|
179
|
+
}
|
|
180
|
+
interface CodeBlockProps {
|
|
181
|
+
code: string;
|
|
182
|
+
language?: string;
|
|
183
|
+
}
|
|
184
|
+
interface TimeAgoProps {
|
|
185
|
+
/** An ISO date-time. */
|
|
186
|
+
date: string;
|
|
187
|
+
}
|
|
188
|
+
interface SpinnerProps {
|
|
189
|
+
size?: Size;
|
|
190
|
+
}
|
|
191
|
+
interface SkeletonProps {
|
|
192
|
+
height?: Size;
|
|
193
|
+
}
|
|
194
|
+
type Gap = "none" | "small" | "medium" | "large";
|
|
195
|
+
type Size = "small" | "medium" | "large";
|
|
196
|
+
type Tone = "default" | "muted" | "danger" | "success";
|
|
197
|
+
type EmptyProps = Record<string, never>;
|
|
198
|
+
declare const Stack: (props: StackProps) => JSX.Element;
|
|
199
|
+
declare const Grid: (props: GridProps) => JSX.Element;
|
|
200
|
+
declare const Box: (props: BoxProps) => JSX.Element;
|
|
201
|
+
declare const Divider: (props: EmptyProps) => JSX.Element;
|
|
202
|
+
declare const ScrollArea: (props: ScrollAreaProps) => JSX.Element;
|
|
203
|
+
declare const Text: (props: TextProps) => JSX.Element;
|
|
204
|
+
declare const Heading: (props: HeadingProps) => JSX.Element;
|
|
205
|
+
declare const Code: (props: ParentProps) => JSX.Element;
|
|
206
|
+
declare const Link: (props: LinkProps) => JSX.Element;
|
|
207
|
+
declare const Badge: (props: BadgeProps) => JSX.Element;
|
|
208
|
+
declare const Icon: (props: IconProps) => JSX.Element;
|
|
209
|
+
declare const Button: (props: ButtonProps) => JSX.Element;
|
|
210
|
+
declare const IconButton: (props: IconButtonProps) => JSX.Element;
|
|
211
|
+
declare const Input: (props: InputProps) => JSX.Element;
|
|
212
|
+
declare const Textarea: (props: TextareaProps) => JSX.Element;
|
|
213
|
+
declare const Select: (props: ChoiceProps) => JSX.Element;
|
|
214
|
+
declare const Combobox: (props: ChoiceProps) => JSX.Element;
|
|
215
|
+
declare const Checkbox: (props: ToggleProps) => JSX.Element;
|
|
216
|
+
declare const Toggle: (props: ToggleProps) => JSX.Element;
|
|
217
|
+
declare const ToggleGroup: (props: ToggleGroupProps) => JSX.Element;
|
|
218
|
+
declare const ColorInput: (props: ColorInputProps) => JSX.Element;
|
|
219
|
+
declare const Tooltip: (props: TooltipProps) => JSX.Element;
|
|
220
|
+
declare const Setting: (props: SettingProps) => JSX.Element;
|
|
221
|
+
declare const List: (props: ListProps) => JSX.Element;
|
|
222
|
+
declare const Card: (props: CardProps) => JSX.Element;
|
|
223
|
+
declare const Tree: (props: TreeProps) => JSX.Element;
|
|
224
|
+
declare const Tabs: (props: TabsProps) => JSX.Element;
|
|
225
|
+
declare const Tab: (props: TabProps) => JSX.Element;
|
|
226
|
+
declare const Disclosure: (props: DisclosureProps) => JSX.Element;
|
|
227
|
+
declare const Callout: (props: CalloutProps) => JSX.Element;
|
|
228
|
+
declare const Steps: (props: ParentProps) => JSX.Element;
|
|
229
|
+
declare const Step: (props: StepProps) => JSX.Element;
|
|
230
|
+
declare const Figure: (props: FigureProps) => JSX.Element;
|
|
231
|
+
declare const CodeBlock: (props: CodeBlockProps) => JSX.Element;
|
|
232
|
+
declare const TimeAgo: (props: TimeAgoProps) => JSX.Element;
|
|
233
|
+
declare const Spinner: (props: SpinnerProps) => JSX.Element;
|
|
234
|
+
declare const Skeleton: (props: SkeletonProps) => JSX.Element;
|
|
235
|
+
/** Where an element view shows the element's editable content (element views only). */
|
|
236
|
+
declare const ContentSlot: (props: EmptyProps) => JSX.Element;
|
|
237
|
+
//#endregion
|
|
238
|
+
//#region src/solid/runtime.d.ts
|
|
239
|
+
type ExtensionViews = Record<string, Component<never>>;
|
|
240
|
+
/**
|
|
241
|
+
* Starts the extension frontend in its sandbox worker. `entries` maps the view entries that the
|
|
242
|
+
* manifest names to Solid components; each view receives its host props as reactive props.
|
|
243
|
+
*/
|
|
244
|
+
declare const startExtension: (entries: ExtensionViews) => void;
|
|
245
|
+
//#endregion
|
|
246
|
+
//#region src/solid/actions.d.ts
|
|
247
|
+
/** Copies text; the host shows a fallback dialog if the browser refuses. */
|
|
248
|
+
declare const copyText: (text: string) => Promise<void>;
|
|
249
|
+
/** Downloads a text file, for example `downloadFile("andesine.config.ts", source)`. */
|
|
250
|
+
declare const downloadFile: (name: string, text: string, type?: string) => Promise<void>;
|
|
251
|
+
/** Opens an `https:` URL in a new tab; URLs outside the declared URLs need confirmation. */
|
|
252
|
+
declare const openURL: (url: string) => Promise<void>;
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/solid/requests.d.ts
|
|
255
|
+
/** A host request failed; `code` says why, for example `user_interaction_required`. */
|
|
256
|
+
declare class ExtensionRequestError extends Error {
|
|
257
|
+
readonly code: RequestErrorCode;
|
|
258
|
+
constructor(code: RequestErrorCode, message: string);
|
|
259
|
+
}
|
|
260
|
+
//#endregion
|
|
261
|
+
//#region src/solid/editor.d.ts
|
|
262
|
+
/** A document block in editor JSON, e.g. `{ type: "paragraph", content: [{ type: "text", text: "Hi" }] }`. */
|
|
263
|
+
interface ContentNode {
|
|
264
|
+
type: string;
|
|
265
|
+
attrs?: Record<string, JSONValue>;
|
|
266
|
+
content?: ContentNode[];
|
|
267
|
+
marks?: Array<{
|
|
268
|
+
type: string;
|
|
269
|
+
attrs?: Record<string, JSONValue>;
|
|
270
|
+
}>;
|
|
271
|
+
text?: string;
|
|
272
|
+
}
|
|
273
|
+
interface ViewEditor {
|
|
274
|
+
/** Block action views: replaces the blocks the action was opened for. */
|
|
275
|
+
replace(content: ContentNode[]): Promise<void>;
|
|
276
|
+
/** Block action views: inserts blocks after those the action was opened for. */
|
|
277
|
+
insertAfter(content: ContentNode[]): Promise<void>;
|
|
278
|
+
/** Element views: updates the element's props; call it from a user interaction. */
|
|
279
|
+
setElementProps(props: Record<string, JSONValue>): Promise<void>;
|
|
280
|
+
/** Block action views: closes the view. */
|
|
281
|
+
close(): Promise<void>;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Edits the document from the current view. Andesine validates every edit and applies it as the
|
|
285
|
+
* member's own edit; edits reject with `ExtensionRequestError` when they do not fit.
|
|
286
|
+
*/
|
|
287
|
+
declare const useEditor: () => ViewEditor;
|
|
288
|
+
//#endregion
|
|
289
|
+
//#region src/solid/storage.d.ts
|
|
290
|
+
interface StorageEntry<T extends JSONValue = JSONValue> {
|
|
291
|
+
key: string;
|
|
292
|
+
value: T;
|
|
293
|
+
/** An ISO date-time. */
|
|
294
|
+
updatedAt: string;
|
|
295
|
+
}
|
|
296
|
+
interface StorageListOptions {
|
|
297
|
+
/** Only keys that start with the prefix. */
|
|
298
|
+
prefix?: string;
|
|
299
|
+
/** Entries after this key, from the previous page. */
|
|
300
|
+
after?: string;
|
|
301
|
+
/** At most 100 (the default). */
|
|
302
|
+
limit?: number;
|
|
303
|
+
}
|
|
304
|
+
interface StoragePage {
|
|
305
|
+
data: StorageEntry[];
|
|
306
|
+
hasMore: boolean;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* The extension's JSON key-value storage, shared with its backend. Keys have up to 256
|
|
310
|
+
* characters; values up to 128 KiB; the storage up to 10,000 entries and 10 MiB. The last write
|
|
311
|
+
* wins. Failed requests reject with `ExtensionRequestError`.
|
|
312
|
+
*/
|
|
313
|
+
declare const storage: {
|
|
314
|
+
/** The entry, or null when the key is not set. */
|
|
315
|
+
get<T extends JSONValue = JSONValue>(key: string): Promise<StorageEntry<T> | null>;
|
|
316
|
+
/** Creates or replaces an entry; resolves with its update time. */
|
|
317
|
+
set(key: string, value: JSONValue): Promise<{
|
|
318
|
+
updatedAt: string;
|
|
319
|
+
}>;
|
|
320
|
+
/** Resolves with whether the key was set. */
|
|
321
|
+
delete(key: string): Promise<boolean>;
|
|
322
|
+
/** Entries in key order; a page can have fewer entries than `limit` when values are large. */
|
|
323
|
+
list(options?: StorageListOptions): Promise<StoragePage>;
|
|
324
|
+
};
|
|
325
|
+
//#endregion
|
|
326
|
+
//#region src/solid/context.d.ts
|
|
327
|
+
/** The origin `apiFetch` accepts; use it as the SDK `baseURL`. */
|
|
328
|
+
declare const EXTENSION_API_URL = "https://api.andesine.invalid";
|
|
329
|
+
/**
|
|
330
|
+
* The configuration's non-secret values, with defaults for unset fields (reactive). Secret
|
|
331
|
+
* fields are readable only by the extension backend.
|
|
332
|
+
*/
|
|
333
|
+
declare const useConfiguration: <T extends Record<string, JSONValue> = Record<string, JSONValue>>() => () => Partial<T>;
|
|
334
|
+
/** The member's effective permissions for this extension (reactive), e.g. `read:entries`. */
|
|
335
|
+
declare const usePermissions: () => import("solid-js").Accessor<string[]>;
|
|
336
|
+
/** Whether the effective permissions include `permission`; a write permission includes its read. */
|
|
337
|
+
declare const hasPermission: (permission: string) => boolean;
|
|
338
|
+
/**
|
|
339
|
+
* A fetch implementation for the Andesine SDK: requests go through Andesine with the member's
|
|
340
|
+
* session, within the effective permissions. Forbidden operations answer with HTTP 403.
|
|
341
|
+
* @example createClient({ baseURL: EXTENSION_API_URL, fetch: apiFetch })
|
|
342
|
+
*/
|
|
343
|
+
declare const apiFetch: typeof fetch;
|
|
344
|
+
/** The extension's own backend, as declared in the manifest. */
|
|
345
|
+
declare const backend: {
|
|
346
|
+
/**
|
|
347
|
+
* Fetches a path of the backend URL with the member's session token in `Authorization`, and
|
|
348
|
+
* the extension ID and instance API URL in `Andesine-Extension` and `Andesine-Instance`; the
|
|
349
|
+
* backend verifies them with `verifySession` from `@andesine/sdk/extensions`. Its CORS
|
|
350
|
+
* configuration must allow these headers.
|
|
351
|
+
*/
|
|
352
|
+
fetch(path: string, init?: RequestInit): Promise<Response>;
|
|
353
|
+
};
|
|
354
|
+
//#endregion
|
|
355
|
+
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, 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, 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, openURL, startExtension, storage, useConfiguration, useEditor, usePermissions };
|
|
356
|
+
//# sourceMappingURL=solid.d.ts.map
|