@domicile-desktop/sdk 0.0.0-alpha-eac3f852668d → 0.0.0-alpha-dfd80a336b89

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/dist/portal.d.ts CHANGED
@@ -4,8 +4,10 @@ export declare enum PortalKind {
4
4
  Access = 0,
5
5
  /** Pick an application to open a file or URI with. */
6
6
  AppChooser = 1,
7
+ /** Files to open, or where to save. */
8
+ FileChooser = 2,
7
9
  /** A kind this SDK cannot parse. Answer it with {@link PortalAnswer.Refused}. */
8
- Unknown = 2
10
+ Unknown = 3
9
11
  }
10
12
  /** What every request carries. */
11
13
  export type PortalRequestBase = {
@@ -36,6 +38,67 @@ export type AppChooserBody = {
36
38
  /** The file's name, without its directory. */
37
39
  filename: string | undefined;
38
40
  };
41
+ /** Which `FileChooser` method asked. */
42
+ export declare enum FileChooserMode {
43
+ /** Existing files, or a folder when `directory` is set. */
44
+ Open = 0,
45
+ /** One new path. */
46
+ Save = 1,
47
+ /** A folder to save `files` into. */
48
+ SaveFiles = 2
49
+ }
50
+ /** A named group of accepted extensions, such as "Images". */
51
+ export type FileChooserFilter = {
52
+ /** Lowercase and without the dot; empty accepts any file. */
53
+ extensions: readonly string[];
54
+ name: string;
55
+ };
56
+ /**
57
+ * A question asked beside the files. No options means a checkbox, answered
58
+ * `"true"` or `"false"`.
59
+ */
60
+ export type FileChoice = {
61
+ id: string;
62
+ /** The option id, or `"true"`/`"false"`, selected at first. */
63
+ initial: string;
64
+ label: string;
65
+ options: readonly {
66
+ id: string;
67
+ label: string;
68
+ }[];
69
+ };
70
+ /** A file chooser's request. Paths are absolute. */
71
+ export type FileChooserBody = {
72
+ /** The confirm button's label; the shell's own when absent. */
73
+ acceptLabel: string | undefined;
74
+ choices: readonly FileChoice[];
75
+ /** The index in `filters` to start with. */
76
+ currentFilter: number | undefined;
77
+ /** The folder to start in; the home when absent. */
78
+ currentFolder: string | undefined;
79
+ /** The suggested name for {@link FileChooserMode.Save}. */
80
+ currentName: string | undefined;
81
+ /** Open a folder rather than a file. */
82
+ directory: boolean;
83
+ /** The names {@link FileChooserMode.SaveFiles} saves into the folder. */
84
+ files: readonly string[];
85
+ /** Empty accepts any file. */
86
+ filters: readonly FileChooserFilter[];
87
+ /** The user's home directory, where the picker's places are. */
88
+ home: string;
89
+ mode: FileChooserMode;
90
+ multiple: boolean;
91
+ title: string;
92
+ };
93
+ /** What the user chose in a file chooser. */
94
+ export type FileChosen = {
95
+ /** Each {@link FileChoice}'s answer, by id. */
96
+ choices: ReadonlyMap<string, string>;
97
+ /** The index in the request's `filters` in use. */
98
+ currentFilter: number | undefined;
99
+ /** Absolute paths: the files, or the folder for `SaveFiles`. */
100
+ paths: readonly string[];
101
+ };
39
102
  export declare const PortalRequest: {
40
103
  Access: (base: PortalRequestBase, body: AccessBody) => {
41
104
  /** The id {@link answerPortalRequest} takes. */
@@ -57,6 +120,16 @@ export declare const PortalRequest: {
57
120
  body: AppChooserBody;
58
121
  kind: PortalKind.AppChooser;
59
122
  };
123
+ FileChooser: (base: PortalRequestBase, body: FileChooserBody) => {
124
+ /** The id {@link answerPortalRequest} takes. */
125
+ id: number;
126
+ /** The asking application's desktop file id. Empty when unknown. */
127
+ appId: string;
128
+ /** The `<app>` to show the dialog over, or the focused screen when absent. */
129
+ parentAppId: string | undefined;
130
+ body: FileChooserBody;
131
+ kind: PortalKind.FileChooser;
132
+ };
60
133
  Unknown: (base: PortalRequestBase, wireKind: string) => {
61
134
  /** The id {@link answerPortalRequest} takes. */
62
135
  id: number;
@@ -74,10 +147,12 @@ export declare enum PortalAnswerKind {
74
147
  Access = 0,
75
148
  /** The application the user picked in an {@link PortalKind.AppChooser}. */
76
149
  AppChooser = 1,
150
+ /** The user chose in a {@link PortalKind.FileChooser}. */
151
+ FileChooser = 2,
77
152
  /** The user dismissed or denied the dialog. */
78
- Canceled = 2,
153
+ Canceled = 3,
79
154
  /** The shell has no dialog for this kind. */
80
- Refused = 3
155
+ Refused = 4
81
156
  }
82
157
  export declare const PortalAnswer: {
83
158
  Access: () => {
@@ -91,6 +166,10 @@ export declare const PortalAnswer: {
91
166
  Canceled: () => {
92
167
  kind: PortalAnswerKind.Canceled;
93
168
  };
169
+ FileChooser: (chosen: FileChosen) => {
170
+ chosen: FileChosen;
171
+ kind: PortalAnswerKind.FileChooser;
172
+ };
94
173
  Refused: () => {
95
174
  kind: PortalAnswerKind.Refused;
96
175
  };
package/dist/portal.js CHANGED
@@ -11,9 +11,21 @@ export var PortalKind;
11
11
  PortalKind[PortalKind["Access"] = 0] = "Access";
12
12
  /** Pick an application to open a file or URI with. */
13
13
  PortalKind[PortalKind["AppChooser"] = 1] = "AppChooser";
14
+ /** Files to open, or where to save. */
15
+ PortalKind[PortalKind["FileChooser"] = 2] = "FileChooser";
14
16
  /** A kind this SDK cannot parse. Answer it with {@link PortalAnswer.Refused}. */
15
- PortalKind[PortalKind["Unknown"] = 2] = "Unknown";
17
+ PortalKind[PortalKind["Unknown"] = 3] = "Unknown";
16
18
  })(PortalKind || (PortalKind = {}));
19
+ /** Which `FileChooser` method asked. */
20
+ export var FileChooserMode;
21
+ (function (FileChooserMode) {
22
+ /** Existing files, or a folder when `directory` is set. */
23
+ FileChooserMode[FileChooserMode["Open"] = 0] = "Open";
24
+ /** One new path. */
25
+ FileChooserMode[FileChooserMode["Save"] = 1] = "Save";
26
+ /** A folder to save `files` into. */
27
+ FileChooserMode[FileChooserMode["SaveFiles"] = 2] = "SaveFiles";
28
+ })(FileChooserMode || (FileChooserMode = {}));
17
29
  export const PortalRequest = {
18
30
  Access: (base, body) => ({
19
31
  ...base,
@@ -25,6 +37,11 @@ export const PortalRequest = {
25
37
  body,
26
38
  kind: PortalKind.AppChooser,
27
39
  }),
40
+ FileChooser: (base, body) => ({
41
+ ...base,
42
+ body,
43
+ kind: PortalKind.FileChooser,
44
+ }),
28
45
  Unknown: (base, wireKind) => ({
29
46
  ...base,
30
47
  kind: PortalKind.Unknown,
@@ -37,10 +54,12 @@ export var PortalAnswerKind;
37
54
  PortalAnswerKind[PortalAnswerKind["Access"] = 0] = "Access";
38
55
  /** The application the user picked in an {@link PortalKind.AppChooser}. */
39
56
  PortalAnswerKind[PortalAnswerKind["AppChooser"] = 1] = "AppChooser";
57
+ /** The user chose in a {@link PortalKind.FileChooser}. */
58
+ PortalAnswerKind[PortalAnswerKind["FileChooser"] = 2] = "FileChooser";
40
59
  /** The user dismissed or denied the dialog. */
41
- PortalAnswerKind[PortalAnswerKind["Canceled"] = 2] = "Canceled";
60
+ PortalAnswerKind[PortalAnswerKind["Canceled"] = 3] = "Canceled";
42
61
  /** The shell has no dialog for this kind. */
43
- PortalAnswerKind[PortalAnswerKind["Refused"] = 3] = "Refused";
62
+ PortalAnswerKind[PortalAnswerKind["Refused"] = 4] = "Refused";
44
63
  })(PortalAnswerKind || (PortalAnswerKind = {}));
45
64
  export const PortalAnswer = {
46
65
  Access: () => ({ kind: PortalAnswerKind.Access }),
@@ -50,6 +69,10 @@ export const PortalAnswer = {
50
69
  kind: PortalAnswerKind.AppChooser,
51
70
  }),
52
71
  Canceled: () => ({ kind: PortalAnswerKind.Canceled }),
72
+ FileChooser: (chosen) => ({
73
+ chosen,
74
+ kind: PortalAnswerKind.FileChooser,
75
+ }),
53
76
  Refused: () => ({ kind: PortalAnswerKind.Refused }),
54
77
  };
55
78
  /**
@@ -102,6 +125,40 @@ const appChooserSchema = z
102
125
  lastChoice: body.last_choice,
103
126
  uri: body.uri,
104
127
  }));
128
+ const fileChooserSchema = z
129
+ .object({
130
+ accept_label: z.string().optional(),
131
+ choices: z.array(z.object({
132
+ id: z.string(),
133
+ initial: z.string(),
134
+ label: z.string(),
135
+ options: z.array(z.object({ id: z.string(), label: z.string() })),
136
+ })),
137
+ current_filter: z.number().optional(),
138
+ current_folder: z.string().optional(),
139
+ current_name: z.string().optional(),
140
+ directory: z.boolean(),
141
+ files: z.array(z.string()),
142
+ filters: z.array(z.object({ extensions: z.array(z.string()), name: z.string() })),
143
+ home: z.string(),
144
+ mode: z.enum(["open", "save", "save_files"]),
145
+ multiple: z.boolean(),
146
+ title: z.string(),
147
+ })
148
+ .transform((body) => ({
149
+ acceptLabel: body.accept_label,
150
+ choices: body.choices,
151
+ currentFilter: body.current_filter,
152
+ currentFolder: body.current_folder,
153
+ currentName: body.current_name,
154
+ directory: body.directory,
155
+ files: body.files,
156
+ filters: body.filters,
157
+ home: body.home,
158
+ mode: chooserMode(body.mode),
159
+ multiple: body.multiple,
160
+ title: body.title,
161
+ }));
105
162
  /** Each kind's wire name, and how to read its body into a request. */
106
163
  const KINDS = new Map([
107
164
  [
@@ -112,6 +169,10 @@ const KINDS = new Map([
112
169
  "app_chooser",
113
170
  (base, body) => PortalRequest.AppChooser(base, appChooserSchema.parse(body)),
114
171
  ],
172
+ [
173
+ "file_chooser",
174
+ (base, body) => PortalRequest.FileChooser(base, fileChooserSchema.parse(body)),
175
+ ],
115
176
  ]);
116
177
  const itemSchema = z.object({
117
178
  app_id: z.string(),
@@ -135,6 +196,16 @@ const parseRequest = (item) => {
135
196
  ? PortalRequest.Unknown(base, item.kind)
136
197
  : parse(base, item.body);
137
198
  };
199
+ const chooserMode = (mode) => {
200
+ switch (mode) {
201
+ case "open":
202
+ return FileChooserMode.Open;
203
+ case "save":
204
+ return FileChooserMode.Save;
205
+ case "save_files":
206
+ return FileChooserMode.SaveFiles;
207
+ }
208
+ };
138
209
  /** `answer` as the compositor reads it. */
139
210
  const wireAnswer = (answer) => {
140
211
  switch (answer.kind) {
@@ -144,6 +215,13 @@ const wireAnswer = (answer) => {
144
215
  return { choice: answer.choice, kind: "app_chooser" };
145
216
  case PortalAnswerKind.Canceled:
146
217
  return { kind: "canceled" };
218
+ case PortalAnswerKind.FileChooser:
219
+ return {
220
+ choices: Object.fromEntries(answer.chosen.choices),
221
+ current_filter: answer.chosen.currentFilter,
222
+ kind: "file_chooser",
223
+ paths: answer.chosen.paths,
224
+ };
147
225
  case PortalAnswerKind.Refused:
148
226
  return { kind: "refused" };
149
227
  }
package/package.json CHANGED
@@ -95,7 +95,7 @@
95
95
  "test:unit": "bun test"
96
96
  },
97
97
  "type": "module",
98
- "version": "0.0.0-alpha-eac3f852668d",
98
+ "version": "0.0.0-alpha-dfd80a336b89",
99
99
  "repository": {
100
100
  "type": "git",
101
101
  "url": "git+https://github.com/cprussin/domicile.git",