@silverbulletmd/silverbullet 2.8.1 → 2.10.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.
Files changed (65) hide show
  1. package/README.md +42 -25
  2. package/client/plugos/hooks/syscall.ts +24 -10
  3. package/client/plugos/syscalls/asset.ts +61 -23
  4. package/client/plugos/syscalls/clientStore.ts +32 -6
  5. package/client/plugos/syscalls/client_code_widget.ts +9 -4
  6. package/client/plugos/syscalls/code_widget.ts +26 -11
  7. package/client/plugos/syscalls/config.ts +146 -30
  8. package/client/plugos/syscalls/datastore.ts +146 -40
  9. package/client/plugos/syscalls/editor.ts +1432 -700
  10. package/client/plugos/syscalls/event.ts +46 -13
  11. package/client/plugos/syscalls/fetch.ts +123 -82
  12. package/client/plugos/syscalls/index.ts +243 -114
  13. package/client/plugos/syscalls/jsonschema.ts +107 -8
  14. package/client/plugos/syscalls/language.ts +38 -12
  15. package/client/plugos/syscalls/markdown.ts +166 -50
  16. package/client/plugos/syscalls/mq.ts +93 -20
  17. package/client/plugos/syscalls/schema_introspection.ts +33 -0
  18. package/client/plugos/syscalls/service_registry.ts +74 -20
  19. package/client/plugos/syscalls/shell.ts +51 -20
  20. package/client/plugos/syscalls/space.ts +169 -113
  21. package/client/plugos/syscalls/sync.ts +50 -19
  22. package/client/plugos/syscalls/system.ts +236 -139
  23. package/client/plugos/system.ts +21 -5
  24. package/client/space_lua/api_documentation.ts +107 -0
  25. package/client/space_lua/ast.ts +13 -0
  26. package/client/space_lua/eval.ts +12 -4
  27. package/client/space_lua/parse.ts +254 -119
  28. package/client/space_lua/pretty_print.ts +465 -0
  29. package/client/space_lua/query_collection.ts +3 -3
  30. package/client/space_lua/render_widget.ts +156 -0
  31. package/client/space_lua/runtime.ts +83 -22
  32. package/client/space_lua/stdlib/crypto.ts +8 -3
  33. package/client/space_lua/stdlib/encoding.ts +27 -9
  34. package/client/space_lua/stdlib/js.ts +137 -22
  35. package/client/space_lua/stdlib/load.ts +26 -17
  36. package/client/space_lua/stdlib/math.ts +323 -118
  37. package/client/space_lua/stdlib/net.ts +57 -9
  38. package/client/space_lua/stdlib/os.ts +111 -44
  39. package/client/space_lua/stdlib/space_lua.ts +397 -13
  40. package/client/space_lua/stdlib/string.ts +282 -104
  41. package/client/space_lua/stdlib/string_pack.ts +58 -19
  42. package/client/space_lua/stdlib/table.ts +195 -40
  43. package/client/space_lua/stdlib.ts +336 -94
  44. package/client/space_lua/syscalls.ts +270 -0
  45. package/dist/plug-compile.js +1 -1
  46. package/package.json +12 -4
  47. package/plug-api/lib/ref.ts +96 -0
  48. package/plug-api/lib/shortcut.ts +2 -1
  49. package/plug-api/syscalls/config.ts +5 -3
  50. package/plug-api/syscalls/editor.ts +23 -2
  51. package/plug-api/syscalls/index.ts +24 -1
  52. package/plug-api/syscalls/jsonschema.ts +9 -0
  53. package/plug-api/syscalls/lua.ts +28 -1
  54. package/plug-api/syscalls/shell.ts +0 -1
  55. package/plug-api/syscalls/system.ts +7 -0
  56. package/plug-api/system_mock.ts +2 -2
  57. package/plug-api/types/config.ts +1 -1
  58. package/plug-api/types/index.ts +52 -1
  59. package/plug-api/types/manifest.ts +22 -4
  60. package/plug-api/ui/cx.ts +4 -0
  61. package/plug-api/ui/index.ts +22 -0
  62. package/plug-api/ui/panel_styles.ts +33 -0
  63. package/plug-api/ui/slugify.ts +44 -0
  64. package/plugs/builtin_plugs.ts +1 -0
  65. package/client/plugos/syscalls/lua.ts +0 -58
@@ -36,11 +36,62 @@ export type DocumentMeta = ObjectValue<
36
36
  extension: string;
37
37
  } & Record<string, any>
38
38
  >;
39
- export type SyscallMeta = {
39
+ export type SyscallMeta = LuaFunctionDocumentation & {
40
40
  name: string;
41
41
  requiredPermissions: string[];
42
42
  argCount: number;
43
43
  };
44
+
45
+ export type LuaFunctionParameterDocumentation = {
46
+ name: string;
47
+ type?: string;
48
+ description?: string;
49
+ optional?: boolean;
50
+ };
51
+
52
+ export type LuaFunctionReturnDocumentation = {
53
+ type?: string;
54
+ description?: string;
55
+ };
56
+
57
+ export type LuaFunctionExampleDocumentation = {
58
+ code: string;
59
+ description?: string;
60
+ language?: string;
61
+ };
62
+
63
+ /** Structured documentation shared by Lua functions, built-ins and syscalls. */
64
+ export type LuaFunctionDocumentation = {
65
+ description?: string;
66
+ parameters?: LuaFunctionParameterDocumentation[];
67
+ returns?: LuaFunctionReturnDocumentation[];
68
+ /** Full signatures, used for overloaded or otherwise non-standard functions. */
69
+ signatures?: string[];
70
+ examples?: LuaFunctionExampleDocumentation[];
71
+ deprecated?: string | boolean;
72
+ /** Page or page anchor containing the full documentation. */
73
+ see?: string;
74
+ };
75
+
76
+ export type LuaFunctionInfo = LuaFunctionDocumentation & {
77
+ name?: string;
78
+ kind: "lua" | "builtin" | "syscall";
79
+ source?: Record<string, unknown>;
80
+ };
81
+
82
+ export type LuaPropertyInspection = {
83
+ key: string;
84
+ type: string;
85
+ functionInfo?: LuaFunctionInfo;
86
+ definition?: string;
87
+ };
88
+
89
+ export type LuaValueInspection = {
90
+ type: string;
91
+ functionInfo?: LuaFunctionInfo;
92
+ definition?: string;
93
+ properties: LuaPropertyInspection[];
94
+ };
44
95
  /**
45
96
  * An ObjectValue that can be indexed by the `index` plug, needs to have a minimum of
46
97
  * of two fields:
@@ -1,5 +1,6 @@
1
1
  import type { Manifest as PlugosManifest } from "../../client/plugos/types.ts";
2
2
  import type { NamespaceOperation } from "./namespace.ts";
3
+ import type { LuaFunctionDocumentation } from "./index.ts";
3
4
 
4
5
  export type CodeWidgetT = {
5
6
  codeWidget?: string;
@@ -12,10 +13,23 @@ export type CodeWidgetT = {
12
13
  * Quit, About, etc.) instead of a command-dispatching item.
13
14
  */
14
15
  export type PredefinedMenuKind =
15
- | "quit" | "about" | "services" | "hide" | "hideOthers" | "showAll"
16
- | "closeWindow" | "minimize" | "maximize" | "fullscreen"
16
+ | "quit"
17
+ | "about"
18
+ | "services"
19
+ | "hide"
20
+ | "hideOthers"
21
+ | "showAll"
22
+ | "closeWindow"
23
+ | "minimize"
24
+ | "maximize"
25
+ | "fullscreen"
17
26
  | "separator"
18
- | "undo" | "redo" | "cut" | "copy" | "paste" | "selectAll";
27
+ | "undo"
28
+ | "redo"
29
+ | "cut"
30
+ | "copy"
31
+ | "paste"
32
+ | "selectAll";
19
33
 
20
34
  /**
21
35
  * A single native-menu placement for a command or submenu.
@@ -130,7 +144,11 @@ export type SlashCommandHookT = {
130
144
  };
131
145
 
132
146
  export type SyscallHookT = {
133
- syscall?: string;
147
+ syscall?:
148
+ | string
149
+ | ({
150
+ name: string;
151
+ } & LuaFunctionDocumentation);
134
152
  };
135
153
 
136
154
  export type DocumentEditorT = {
@@ -0,0 +1,4 @@
1
+ /** Join class-name parts, dropping falsy values. */
2
+ export function cx(...parts: Array<string | false | null | undefined>): string {
3
+ return parts.filter(Boolean).join(" ");
4
+ }
@@ -0,0 +1,22 @@
1
+ export { Button } from "./button.tsx";
2
+ export type { ButtonProps, ButtonVariant } from "./button.tsx";
3
+ export { Input } from "./input.tsx";
4
+ export type { InputProps } from "./input.tsx";
5
+ export { Select } from "./select.tsx";
6
+ export type { SelectProps } from "./select.tsx";
7
+ export { Checkbox } from "./checkbox.tsx";
8
+ export type { CheckboxProps } from "./checkbox.tsx";
9
+ export { Tabs } from "./tabs.tsx";
10
+ export type { TabItem, TabsProps } from "./tabs.tsx";
11
+ export { Alert } from "./alert.tsx";
12
+ export type { AlertProps, AlertVariant } from "./alert.tsx";
13
+ export { Badge } from "./badge.tsx";
14
+ export type { BadgeProps } from "./badge.tsx";
15
+ export { Progress } from "./progress.tsx";
16
+ export type { ProgressProps } from "./progress.tsx";
17
+ export { UrlPrefixInput } from "./url_prefix_input.tsx";
18
+ export type { UrlPrefixInputProps } from "./url_prefix_input.tsx";
19
+ export { normalizePrefix, prefixFromName, slugify } from "./slugify.ts";
20
+ export { cx } from "./cx.ts";
21
+ export { panelStyles } from "./panel_styles.ts";
22
+ export type { PanelStylesOptions } from "./panel_styles.ts";
@@ -0,0 +1,33 @@
1
+ import { getUiOption } from "../syscalls/editor.ts";
2
+
3
+ export type PanelStylesOptions = {
4
+ /** Include the shared component stylesheet link (default true). */
5
+ components?: boolean;
6
+ /** Include the user's space-style CSS (default true). */
7
+ spaceStyles?: boolean;
8
+ };
9
+
10
+ /**
11
+ * Build an HTML preamble that styles a plug panel/widget iframe like the rest
12
+ * of SilverBullet: the shared component stylesheet plus the user's space-style
13
+ * CSS. Prepend the result to the HTML you pass to `editor.showPanel`.
14
+ *
15
+ * Order: components first (base), then space styles (so user theming wins),
16
+ * leaving any plug-specific CSS you append afterwards highest-precedence.
17
+ */
18
+ export async function panelStyles({
19
+ components = true,
20
+ spaceStyles = true,
21
+ }: PanelStylesOptions = {}): Promise<string> {
22
+ let out = "";
23
+ if (components) {
24
+ out += `<link rel="stylesheet" href=".client/components.css">`;
25
+ }
26
+ if (spaceStyles) {
27
+ const custom = await getUiOption("customStyles");
28
+ if (typeof custom === "string" && custom) {
29
+ out += custom;
30
+ }
31
+ }
32
+ return out;
33
+ }
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Lower-cased, filesystem- and URL-safe version of a space name, used to
3
+ * derive its default folder and URL prefix.
4
+ *
5
+ * Mirrors the server's `slug::slugify`, so a prefix typed into the Space
6
+ * Manager, the first-run wizard, or the desktop app's space form all reach the
7
+ * server in the same shape.
8
+ */
9
+ export function slugify(name: string): string {
10
+ return name
11
+ .trim()
12
+ .toLowerCase()
13
+ .replace(/[^a-z0-9]+/g, "-")
14
+ .replace(/^-+|-+$/g, "");
15
+ }
16
+
17
+ /**
18
+ * The default URL prefix for a space called `name`, as an absolute path.
19
+ *
20
+ * The leading slash is part of the value, not decoration: a binding prefix is
21
+ * a path, the server stores and validates it that way, and showing it in the
22
+ * field is what makes the assembled URL in `UrlPrefixInput` read correctly. An
23
+ * empty name yields `""` rather than a bare `"/"`, which would bind the space
24
+ * to the server root.
25
+ */
26
+ export function prefixFromName(name: string): string {
27
+ const slug = slugify(name);
28
+ return slug ? `/${slug}` : "";
29
+ }
30
+
31
+ /**
32
+ * Force a user-typed prefix into the shape the server accepts: exactly one
33
+ * leading slash, and a slugified body.
34
+ *
35
+ * Callers that hand a prefix straight to an API need this because a value
36
+ * already starting with `/` is taken as-is by the desktop app's
37
+ * `provision_space` command — it only slugifies input that lacks the slash, so
38
+ * `/My Space!` would otherwise be sent through verbatim. Returns `""` for an
39
+ * empty or slash-only input, the server's spelling of a root binding.
40
+ */
41
+ export function normalizePrefix(raw: string): string {
42
+ const slug = slugify(raw.replace(/^\/+/, ""));
43
+ return slug ? `/${slug}` : "";
44
+ }
@@ -7,6 +7,7 @@ export const builtinPlugNames = [
7
7
  "emoji",
8
8
  "image-viewer",
9
9
  "configuration-manager",
10
+ "object-graph",
10
11
  ];
11
12
 
12
13
  export const builtinPlugPaths = builtinPlugNames.map(
@@ -1,58 +0,0 @@
1
- import type { SysCallMapping } from "../system.ts";
2
- import { evalExpression } from "../../space_lua/eval.ts";
3
- import { parse, parseExpressionString } from "../../space_lua/parse.ts";
4
- import {
5
- LuaStackFrame,
6
- luaToString,
7
- luaValueToJS,
8
- } from "../../space_lua/runtime.ts";
9
- import { buildThreadLocalEnv } from "../../space_lua_api.ts";
10
- import { isSendable } from "../util.ts";
11
- import type { LuaBlock, LuaExpression } from "../../space_lua/ast.ts";
12
- import type { ClientSystem } from "../../client_system.ts";
13
-
14
- export function luaSyscalls(clientSystem: ClientSystem): SysCallMapping {
15
- return {
16
- "lua.parse": (_ctx, code: string): LuaBlock => {
17
- return parse(code);
18
- },
19
- "lua.parseExpression": (_ctx, expression: string): LuaExpression => {
20
- return parseExpressionString(expression);
21
- },
22
- /**
23
- * Evaluates a Lua expression and returns the result as a JavaScript value
24
- * @param _ctx
25
- * @param expression
26
- * @returns
27
- */
28
- "lua.evalExpression": async (_ctx, expression: string) => {
29
- try {
30
- const ast = parseExpressionString(expression);
31
- const env = await buildThreadLocalEnv(
32
- clientSystem.system,
33
- clientSystem.spaceLuaEnv.env,
34
- );
35
- const sf = new LuaStackFrame(env, null);
36
- const luaResult = await evalExpression(
37
- ast,
38
- clientSystem.spaceLuaEnv.env,
39
- sf,
40
- );
41
- const jsResult = luaValueToJS(luaResult, sf);
42
- if (isSendable(jsResult)) {
43
- return jsResult;
44
- } else {
45
- // This may evaluate to e.g. a function, which is not sendable, in this case we'll console.warn and return a stringified version of the result
46
- console.warn(
47
- "Lua eval result is not sendable, returning stringified version",
48
- jsResult,
49
- );
50
- return luaToString(luaResult);
51
- }
52
- } catch (e: any) {
53
- console.error("Lua eval error: ", e.message, e.sf?.astCtx);
54
- throw e;
55
- }
56
- },
57
- };
58
- }