@silverbulletmd/silverbullet 2.9.0 → 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 (63) hide show
  1. package/README.md +36 -23
  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 -711
  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 +242 -116
  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 +243 -108
  28. package/client/space_lua/pretty_print.ts +128 -54
  29. package/client/space_lua/query_collection.ts +4 -4
  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 +24 -15
  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 +344 -20
  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 +335 -93
  44. package/client/space_lua/syscalls.ts +270 -0
  45. package/dist/plug-compile.js +1 -1
  46. package/package.json +3 -3
  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 +16 -0
  51. package/plug-api/syscalls/index.ts +17 -1
  52. package/plug-api/syscalls/jsonschema.ts +9 -0
  53. package/plug-api/syscalls/lua.ts +7 -0
  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/index.ts +52 -1
  58. package/plug-api/types/manifest.ts +22 -4
  59. package/plug-api/ui/cx.ts +1 -3
  60. package/plug-api/ui/index.ts +3 -0
  61. package/plug-api/ui/panel_styles.ts +4 -3
  62. package/plug-api/ui/slugify.ts +44 -0
  63. package/client/plugos/syscalls/lua.ts +0 -81
@@ -15,9 +15,10 @@ export type PanelStylesOptions = {
15
15
  * Order: components first (base), then space styles (so user theming wins),
16
16
  * leaving any plug-specific CSS you append afterwards highest-precedence.
17
17
  */
18
- export async function panelStyles(
19
- { components = true, spaceStyles = true }: PanelStylesOptions = {},
20
- ): Promise<string> {
18
+ export async function panelStyles({
19
+ components = true,
20
+ spaceStyles = true,
21
+ }: PanelStylesOptions = {}): Promise<string> {
21
22
  let out = "";
22
23
  if (components) {
23
24
  out += `<link rel="stylesheet" href=".client/components.css">`;
@@ -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
+ }
@@ -1,81 +0,0 @@
1
- import type { SysCallMapping } from "../system.ts";
2
- import { evalExpression } from "../../space_lua/eval.ts";
3
- import { parseBlock, parseExpressionString } from "../../space_lua/parse.ts";
4
- import {
5
- type PrintOptions,
6
- prettyPrintBlock,
7
- prettyPrintExpression,
8
- } from "../../space_lua/pretty_print.ts";
9
- import {
10
- LuaStackFrame,
11
- luaToString,
12
- luaValueToJS,
13
- } from "../../space_lua/runtime.ts";
14
- import { buildThreadLocalEnv } from "../../space_lua_api.ts";
15
- import { isSendable } from "../util.ts";
16
- import type { LuaBlock, LuaExpression } from "../../space_lua/ast.ts";
17
- import type { ClientSystem } from "../../client_system.ts";
18
-
19
- export function luaSyscalls(clientSystem: ClientSystem): SysCallMapping {
20
- return {
21
- "lua.parseBlock": (_ctx, code: string): LuaBlock => {
22
- return parseBlock(code);
23
- },
24
- // Deprecated alias for `lua.parseBlock`, kept for backwards compatibility.
25
- "lua.parse": (_ctx, code: string): LuaBlock => {
26
- return parseBlock(code);
27
- },
28
- "lua.parseExpression": (_ctx, expression: string): LuaExpression => {
29
- return parseExpressionString(expression);
30
- },
31
- "lua.prettyPrintBlock": (
32
- _ctx,
33
- block: LuaBlock,
34
- opts?: PrintOptions,
35
- ): string => {
36
- return prettyPrintBlock(block, opts);
37
- },
38
- "lua.prettyPrintExpression": (
39
- _ctx,
40
- expression: LuaExpression,
41
- opts?: PrintOptions,
42
- ): string => {
43
- return prettyPrintExpression(expression, opts);
44
- },
45
- /**
46
- * Evaluates a Lua expression and returns the result as a JavaScript value
47
- * @param _ctx
48
- * @param expression
49
- * @returns
50
- */
51
- "lua.evalExpression": async (_ctx, expression: string) => {
52
- try {
53
- const ast = parseExpressionString(expression);
54
- const env = await buildThreadLocalEnv(
55
- clientSystem.system,
56
- clientSystem.spaceLuaEnv.env,
57
- );
58
- const sf = new LuaStackFrame(env, null);
59
- const luaResult = await evalExpression(
60
- ast,
61
- clientSystem.spaceLuaEnv.env,
62
- sf,
63
- );
64
- const jsResult = luaValueToJS(luaResult, sf);
65
- if (isSendable(jsResult)) {
66
- return jsResult;
67
- } else {
68
- // 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
69
- console.warn(
70
- "Lua eval result is not sendable, returning stringified version",
71
- jsResult,
72
- );
73
- return luaToString(luaResult);
74
- }
75
- } catch (e: any) {
76
- console.error("Lua eval error: ", e.message, e.sf?.astCtx);
77
- throw e;
78
- }
79
- },
80
- };
81
- }