@dxos/plugin-github 0.6.8-main.046e6cf

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 (106) hide show
  1. package/LICENSE +8 -0
  2. package/README.md +15 -0
  3. package/dist/lib/browser/chunk-NJP5BGD2.mjs +24 -0
  4. package/dist/lib/browser/chunk-NJP5BGD2.mjs.map +7 -0
  5. package/dist/lib/browser/index.css +7 -0
  6. package/dist/lib/browser/index.css.map +7 -0
  7. package/dist/lib/browser/index.mjs +1531 -0
  8. package/dist/lib/browser/index.mjs.map +7 -0
  9. package/dist/lib/browser/meta.json +1 -0
  10. package/dist/lib/browser/meta.mjs +11 -0
  11. package/dist/lib/browser/meta.mjs.map +7 -0
  12. package/dist/types/src/GithubPlugin.d.ts +4 -0
  13. package/dist/types/src/GithubPlugin.d.ts.map +1 -0
  14. package/dist/types/src/components/EmbeddedMain/EmbeddedMain.d.ts +4 -0
  15. package/dist/types/src/components/EmbeddedMain/EmbeddedMain.d.ts.map +1 -0
  16. package/dist/types/src/components/EmbeddedMain/GfmPreview.d.ts +9 -0
  17. package/dist/types/src/components/EmbeddedMain/GfmPreview.d.ts.map +1 -0
  18. package/dist/types/src/components/EmbeddedMain/index.d.ts +2 -0
  19. package/dist/types/src/components/EmbeddedMain/index.d.ts.map +1 -0
  20. package/dist/types/src/components/ExportDialog.d.ts +8 -0
  21. package/dist/types/src/components/ExportDialog.d.ts.map +1 -0
  22. package/dist/types/src/components/GithubApiProviders/GitHubSettings.d.ts +3 -0
  23. package/dist/types/src/components/GithubApiProviders/GitHubSettings.d.ts.map +1 -0
  24. package/dist/types/src/components/GithubApiProviders/OctokitProvider.d.ts +15 -0
  25. package/dist/types/src/components/GithubApiProviders/OctokitProvider.d.ts.map +1 -0
  26. package/dist/types/src/components/GithubApiProviders/index.d.ts +3 -0
  27. package/dist/types/src/components/GithubApiProviders/index.d.ts.map +1 -0
  28. package/dist/types/src/components/GithubEchoResolverProviders/DocumentTreeItem.d.ts +6 -0
  29. package/dist/types/src/components/GithubEchoResolverProviders/DocumentTreeItem.d.ts.map +1 -0
  30. package/dist/types/src/components/GithubEchoResolverProviders/ResolverContext.d.ts +7 -0
  31. package/dist/types/src/components/GithubEchoResolverProviders/ResolverContext.d.ts.map +1 -0
  32. package/dist/types/src/components/GithubEchoResolverProviders/ResolverDialog.d.ts +6 -0
  33. package/dist/types/src/components/GithubEchoResolverProviders/ResolverDialog.d.ts.map +1 -0
  34. package/dist/types/src/components/GithubEchoResolverProviders/ResolverProps.d.ts +16 -0
  35. package/dist/types/src/components/GithubEchoResolverProviders/ResolverProps.d.ts.map +1 -0
  36. package/dist/types/src/components/GithubEchoResolverProviders/ResolverTree.d.ts +3 -0
  37. package/dist/types/src/components/GithubEchoResolverProviders/ResolverTree.d.ts.map +1 -0
  38. package/dist/types/src/components/GithubEchoResolverProviders/SpacePickerTreeItem.d.ts +11 -0
  39. package/dist/types/src/components/GithubEchoResolverProviders/SpacePickerTreeItem.d.ts.map +1 -0
  40. package/dist/types/src/components/GithubEchoResolverProviders/index.d.ts +3 -0
  41. package/dist/types/src/components/GithubEchoResolverProviders/index.d.ts.map +1 -0
  42. package/dist/types/src/components/GithubEchoResolverProviders/spaceResolvers.d.ts +6 -0
  43. package/dist/types/src/components/GithubEchoResolverProviders/spaceResolvers.d.ts.map +1 -0
  44. package/dist/types/src/components/ImportDialog.d.ts +7 -0
  45. package/dist/types/src/components/ImportDialog.d.ts.map +1 -0
  46. package/dist/types/src/components/Issue.d.ts +5 -0
  47. package/dist/types/src/components/Issue.d.ts.map +1 -0
  48. package/dist/types/src/components/Loading/Loading.d.ts +15 -0
  49. package/dist/types/src/components/Loading/Loading.d.ts.map +1 -0
  50. package/dist/types/src/components/Loading/Loading.stories.d.ts +52 -0
  51. package/dist/types/src/components/Loading/Loading.stories.d.ts.map +1 -0
  52. package/dist/types/src/components/Loading/index.d.ts +2 -0
  53. package/dist/types/src/components/Loading/index.d.ts.map +1 -0
  54. package/dist/types/src/components/MarkdownActions.d.ts +7 -0
  55. package/dist/types/src/components/MarkdownActions.d.ts.map +1 -0
  56. package/dist/types/src/components/UrlDialog.d.ts +6 -0
  57. package/dist/types/src/components/UrlDialog.d.ts.map +1 -0
  58. package/dist/types/src/components/index.d.ts +9 -0
  59. package/dist/types/src/components/index.d.ts.map +1 -0
  60. package/dist/types/src/hooks/index.d.ts +3 -0
  61. package/dist/types/src/hooks/index.d.ts.map +1 -0
  62. package/dist/types/src/hooks/useDocGhId.d.ts +6 -0
  63. package/dist/types/src/hooks/useDocGhId.d.ts.map +1 -0
  64. package/dist/types/src/hooks/useGhIdFromUrl.d.ts +2 -0
  65. package/dist/types/src/hooks/useGhIdFromUrl.d.ts.map +1 -0
  66. package/dist/types/src/index.d.ts +4 -0
  67. package/dist/types/src/index.d.ts.map +1 -0
  68. package/dist/types/src/meta.d.ts +16 -0
  69. package/dist/types/src/meta.d.ts.map +1 -0
  70. package/dist/types/src/translations.d.ts +56 -0
  71. package/dist/types/src/translations.d.ts.map +1 -0
  72. package/dist/types/src/types.d.ts +30 -0
  73. package/dist/types/src/types.d.ts.map +1 -0
  74. package/package.json +76 -0
  75. package/src/GithubPlugin.tsx +129 -0
  76. package/src/components/EmbeddedMain/EmbeddedMain.tsx +296 -0
  77. package/src/components/EmbeddedMain/GfmPreview.tsx +110 -0
  78. package/src/components/EmbeddedMain/embedded.css +3 -0
  79. package/src/components/EmbeddedMain/index.ts +5 -0
  80. package/src/components/ExportDialog.tsx +157 -0
  81. package/src/components/GithubApiProviders/GitHubSettings.tsx +72 -0
  82. package/src/components/GithubApiProviders/OctokitProvider.tsx +60 -0
  83. package/src/components/GithubApiProviders/index.ts +6 -0
  84. package/src/components/GithubEchoResolverProviders/DocumentTreeItem.tsx +26 -0
  85. package/src/components/GithubEchoResolverProviders/ResolverContext.tsx +140 -0
  86. package/src/components/GithubEchoResolverProviders/ResolverDialog.tsx +34 -0
  87. package/src/components/GithubEchoResolverProviders/ResolverProps.ts +23 -0
  88. package/src/components/GithubEchoResolverProviders/ResolverTree.tsx +86 -0
  89. package/src/components/GithubEchoResolverProviders/SpacePickerTreeItem.tsx +105 -0
  90. package/src/components/GithubEchoResolverProviders/index.ts +6 -0
  91. package/src/components/GithubEchoResolverProviders/spaceResolvers.ts +86 -0
  92. package/src/components/ImportDialog.tsx +72 -0
  93. package/src/components/Issue.tsx +62 -0
  94. package/src/components/Loading/Loading.stories.tsx +28 -0
  95. package/src/components/Loading/Loading.tsx +70 -0
  96. package/src/components/Loading/index.ts +5 -0
  97. package/src/components/MarkdownActions.tsx +136 -0
  98. package/src/components/UrlDialog.tsx +52 -0
  99. package/src/components/index.ts +12 -0
  100. package/src/hooks/index.ts +6 -0
  101. package/src/hooks/useDocGhId.ts +38 -0
  102. package/src/hooks/useGhIdFromUrl.ts +26 -0
  103. package/src/index.ts +9 -0
  104. package/src/meta.tsx +21 -0
  105. package/src/translations.ts +72 -0
  106. package/src/types.ts +51 -0
@@ -0,0 +1,1531 @@
1
+ import {
2
+ GITHUB_PLUGIN,
3
+ GITHUB_PLUGIN_SHORT_ID,
4
+ meta_default
5
+ } from "./chunk-NJP5BGD2.mjs";
6
+
7
+ // packages/plugins/experimental/plugin-github/src/GithubPlugin.tsx
8
+ import { GithubLogo } from "@phosphor-icons/react";
9
+ import React16 from "react";
10
+ import { resolvePlugin } from "@dxos/app-framework";
11
+ import { LocalStorageStore } from "@dxos/local-storage";
12
+ import { log as log7 } from "@dxos/log";
13
+ import { parseClientPlugin } from "@dxos/plugin-client";
14
+ import { createExtension } from "@dxos/plugin-graph";
15
+ import { isMarkdownProperties } from "@dxos/plugin-markdown";
16
+ import { DocumentType as DocumentType3 } from "@dxos/plugin-markdown/types";
17
+ import { memoizeQuery } from "@dxos/plugin-space";
18
+ import { getMeta as getMeta4, isSpace, Filter as Filter2 } from "@dxos/react-client/echo";
19
+
20
+ // packages/plugins/experimental/plugin-github/src/components/EmbeddedMain/EmbeddedMain.tsx
21
+ import { ArrowSquareOut as ArrowSquareOut2, CaretDown as CaretDown2, DotsThreeVertical, Eye, Option, PencilSimpleLine, UserPlus } from "@phosphor-icons/react";
22
+ import React10, { useCallback as useCallback2, useContext as useContext4, useRef, useState as useState6 } from "react";
23
+ import { Surface, useIntent } from "@dxos/app-framework";
24
+ import { SPACE_PLUGIN, SpaceAction, getSpaceDisplayName as getSpaceDisplayName2 } from "@dxos/plugin-space";
25
+ import { useClient as useClient2 } from "@dxos/react-client";
26
+ import { getMeta as getMeta2 } from "@dxos/react-client/echo";
27
+ import { Avatar, Button as Button4, ButtonGroup, DensityProvider, Dialog as Dialog2, DropdownMenu, Main, Toggle, Tooltip as Tooltip2, toLocalizedString, useTranslation as useTranslation7 } from "@dxos/react-ui";
28
+ import { defaultTx, descriptionText, getSize as getSize3, mx as mx4 } from "@dxos/react-ui-theme";
29
+ import { hexToFallback } from "@dxos/util";
30
+
31
+ // packages/plugins/experimental/plugin-github/src/components/EmbeddedMain/GfmPreview.tsx
32
+ import "github-markdown-css/github-markdown.css";
33
+ import DOMPurify from "dompurify";
34
+ import React4, { useEffect as useEffect3, useState as useState3 } from "react";
35
+ import { useTranslation as useTranslation2 } from "@dxos/react-ui";
36
+
37
+ // packages/plugins/experimental/plugin-github/src/components/GithubApiProviders/GitHubSettings.tsx
38
+ import { ArrowSquareOut } from "@phosphor-icons/react";
39
+ import React2, { useEffect as useEffect2, useState as useState2 } from "react";
40
+ import { SettingsValue } from "@dxos/plugin-settings";
41
+ import { Link, Input, Trans, useTranslation, useId } from "@dxos/react-ui";
42
+ import { getSize, mx } from "@dxos/react-ui-theme";
43
+
44
+ // packages/plugins/experimental/plugin-github/src/components/GithubApiProviders/OctokitProvider.tsx
45
+ import { Octokit } from "octokit";
46
+ import React, { createContext, useContext, useEffect, useState } from "react";
47
+ import { log } from "@dxos/log";
48
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-github/src/components/GithubApiProviders/OctokitProvider.tsx";
49
+ var OctokitContext = /* @__PURE__ */ createContext({
50
+ setPat: () => {
51
+ },
52
+ patError: null,
53
+ octokit: null
54
+ });
55
+ var useOctokitContext = () => useContext(OctokitContext);
56
+ var OctokitProvider = ({ pat, onPatChanged, children }) => {
57
+ const [octokit, setOctokit] = useState(null);
58
+ const [patError, setPatError] = useState(null);
59
+ useEffect(() => {
60
+ if (pat && !octokit) {
61
+ void setPat(pat);
62
+ }
63
+ }, [
64
+ pat,
65
+ octokit
66
+ ]);
67
+ const setPat = async (pat2) => {
68
+ onPatChanged?.(pat2);
69
+ if (pat2) {
70
+ const octokit2 = new Octokit({
71
+ auth: pat2
72
+ });
73
+ return octokit2.rest.users.getAuthenticated().then(() => {
74
+ setPatError(null);
75
+ setOctokit(octokit2);
76
+ }, (err) => {
77
+ log.warn("Failed to authenticate Octokit from PAT", err, {
78
+ F: __dxlog_file,
79
+ L: 49,
80
+ S: void 0,
81
+ C: (f, a) => f(...a)
82
+ });
83
+ setPatError("failed");
84
+ setOctokit(null);
85
+ });
86
+ } else {
87
+ setOctokit(null);
88
+ }
89
+ };
90
+ return /* @__PURE__ */ React.createElement(OctokitContext.Provider, {
91
+ value: {
92
+ pat,
93
+ setPat,
94
+ patError,
95
+ octokit
96
+ }
97
+ }, children);
98
+ };
99
+
100
+ // packages/plugins/experimental/plugin-github/src/components/GithubApiProviders/GitHubSettings.tsx
101
+ var ExternalLink = ({ children }) => {
102
+ const { t } = useTranslation(GITHUB_PLUGIN);
103
+ const descriptionId = useId("link--external");
104
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Link, {
105
+ href: t("github pat description href"),
106
+ target: "_blank",
107
+ rel: "noreferrer",
108
+ "aria-describedby": descriptionId
109
+ }, children, /* @__PURE__ */ React2.createElement(ArrowSquareOut, {
110
+ weight: "bold",
111
+ className: mx(getSize(3), "inline-block leading-none -mbs-0.5 mli-px")
112
+ })), /* @__PURE__ */ React2.createElement("span", {
113
+ className: "sr-only",
114
+ id: descriptionId
115
+ }, t("target blank description", {
116
+ ns: GITHUB_PLUGIN
117
+ })));
118
+ };
119
+ var GitHubSettings = () => {
120
+ const { t } = useTranslation(GITHUB_PLUGIN);
121
+ const { pat, setPat } = useOctokitContext();
122
+ const [patValue, setPatValue] = useState2(pat);
123
+ useEffect2(() => {
124
+ setPatValue(pat);
125
+ }, [
126
+ pat
127
+ ]);
128
+ useEffect2(() => {
129
+ void setPat(patValue);
130
+ }, [
131
+ patValue
132
+ ]);
133
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(SettingsValue, {
134
+ label: t("github pat label"),
135
+ description: /* @__PURE__ */ React2.createElement(Trans, {
136
+ t,
137
+ i18nKey: "github pat description",
138
+ components: {
139
+ docsLink: /* @__PURE__ */ React2.createElement(ExternalLink, null)
140
+ }
141
+ })
142
+ }, /* @__PURE__ */ React2.createElement(Input.TextInput, {
143
+ autoFocus: true,
144
+ spellCheck: false,
145
+ classNames: "font-mono mlb-1",
146
+ value: patValue ?? "",
147
+ onChange: ({ target: { value } }) => setPatValue(value)
148
+ })));
149
+ };
150
+
151
+ // packages/plugins/experimental/plugin-github/src/components/Loading/Loading.tsx
152
+ import React3 from "react";
153
+ import { useId as useId2 } from "@dxos/react-ui";
154
+ import { mx as mx2 } from "@dxos/react-ui-theme";
155
+ var sizeMap = /* @__PURE__ */ new Map([
156
+ [
157
+ "sm",
158
+ "w-4 h-4"
159
+ ],
160
+ [
161
+ "md",
162
+ "w-8 h-8"
163
+ ],
164
+ [
165
+ "lg",
166
+ "w-12 h-12"
167
+ ],
168
+ [
169
+ "xl",
170
+ "w-16 h-16"
171
+ ]
172
+ ]);
173
+ var Loading = ({ size, color, label, slots = {} }) => {
174
+ const labelId = useId2("loading-label");
175
+ const sizeClassName = sizeMap.get(size ?? "md");
176
+ return /* @__PURE__ */ React3.createElement("div", {
177
+ ...slots.root,
178
+ className: mx2("flex justify-center p-4", slots.root?.className),
179
+ role: "status",
180
+ "aria-labelledby": labelId
181
+ }, /* @__PURE__ */ React3.createElement("svg", {
182
+ role: "none",
183
+ className: mx2(sizeClassName, "text-neutral-200/50 animate-spin dark:text-neutral-600/50", color === "neutral" ? "fill-neutral-400" : "fill-primary-400", slots.svg?.className),
184
+ viewBox: "0 0 100 101",
185
+ fill: "none",
186
+ xmlns: "http://www.w3.org/2000/svg"
187
+ }, /* @__PURE__ */ React3.createElement("path", {
188
+ d: "M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z",
189
+ fill: "currentColor"
190
+ }), /* @__PURE__ */ React3.createElement("path", {
191
+ d: "M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z",
192
+ fill: "currentFill"
193
+ })), /* @__PURE__ */ React3.createElement("span", {
194
+ className: "sr-only",
195
+ id: labelId
196
+ }, label));
197
+ };
198
+
199
+ // packages/plugins/experimental/plugin-github/src/components/EmbeddedMain/GfmPreview.tsx
200
+ var defaultOptions = {
201
+ ALLOWED_TAGS: [
202
+ "span",
203
+ "div",
204
+ "b",
205
+ "i",
206
+ "em",
207
+ "strong",
208
+ "a",
209
+ "p",
210
+ "h1",
211
+ "h2",
212
+ "h3",
213
+ "h4",
214
+ "h5",
215
+ "h6",
216
+ "table",
217
+ "td",
218
+ "th",
219
+ "tr",
220
+ "blockquote",
221
+ "ul",
222
+ "ol",
223
+ "li",
224
+ "dd",
225
+ "tt",
226
+ "dl",
227
+ "dt",
228
+ "details",
229
+ "figcaption",
230
+ "figure",
231
+ "summary",
232
+ "abbr",
233
+ "dfn",
234
+ "mark",
235
+ "sub",
236
+ "sup",
237
+ "img",
238
+ "code",
239
+ "kbd",
240
+ "pre",
241
+ "samp",
242
+ "hr",
243
+ "input",
244
+ "pre",
245
+ "del",
246
+ "g-emoji",
247
+ "label"
248
+ ],
249
+ ALLOWED_ATTR: [
250
+ "class",
251
+ "href",
252
+ "target",
253
+ "hidden",
254
+ "title",
255
+ "type",
256
+ "role",
257
+ "align",
258
+ "data-footnote-ref"
259
+ ]
260
+ };
261
+ var sanitize = (dirty, options) => ({
262
+ __html: DOMPurify.sanitize(dirty, {
263
+ ...defaultOptions,
264
+ ...options
265
+ })
266
+ });
267
+ var GfmPreview = ({ markdown, owner, repo }) => {
268
+ const [html, setHtml] = useState3("");
269
+ const { octokit } = useOctokitContext();
270
+ const { t } = useTranslation2(GITHUB_PLUGIN);
271
+ useEffect3(() => {
272
+ if (octokit && markdown) {
273
+ void octokit.request("POST /markdown", {
274
+ text: markdown,
275
+ ...owner && repo && {
276
+ context: `${owner}/${repo}`
277
+ }
278
+ }).then(({ data }) => setHtml(data), () => {
279
+ });
280
+ }
281
+ }, [
282
+ markdown,
283
+ octokit
284
+ ]);
285
+ return html ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("style", null, ".markdown-body ol, .markdown-body ul {list-style-type: disc; list-style-position: outside;}"), /* @__PURE__ */ React4.createElement("article", {
286
+ className: "markdown-body grow is-full max-is-[980px] mli-auto p-[15px] sm:pli-[45px] sm:plb-[30px]",
287
+ dangerouslySetInnerHTML: sanitize(html, {})
288
+ })) : /* @__PURE__ */ React4.createElement("div", {
289
+ role: "none",
290
+ className: "mli-auto max-is-md pli-2 text-center"
291
+ }, !octokit && /* @__PURE__ */ React4.createElement("p", {
292
+ className: "mlb-4 text-lg font-medium"
293
+ }, t("empty github pat message")), octokit ? /* @__PURE__ */ React4.createElement(Loading, {
294
+ label: t("loading preview message")
295
+ }) : /* @__PURE__ */ React4.createElement(GitHubSettings, null));
296
+ };
297
+
298
+ // packages/plugins/experimental/plugin-github/src/hooks/useDocGhId.ts
299
+ import { useMemo } from "react";
300
+ import { log as log2 } from "@dxos/log";
301
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-github/src/hooks/useDocGhId.ts";
302
+ var useDocGhId = (keys) => {
303
+ return useMemo(() => {
304
+ try {
305
+ const key = keys?.find((key2) => key2.source === "github.com");
306
+ const [owner, repo, type, ...rest] = key?.id?.split("/") ?? [];
307
+ if (type === "issues") {
308
+ return {
309
+ owner,
310
+ repo,
311
+ issueNumber: parseInt(rest[0], 10)
312
+ };
313
+ } else if (type === "blob") {
314
+ const [ref, ...pathParts] = rest;
315
+ return {
316
+ owner,
317
+ repo,
318
+ ref,
319
+ path: pathParts.join("/")
320
+ };
321
+ } else {
322
+ return null;
323
+ }
324
+ } catch (err) {
325
+ log2.catch(err, void 0, {
326
+ F: __dxlog_file2,
327
+ L: 34,
328
+ S: void 0,
329
+ C: (f, a) => f(...a)
330
+ });
331
+ return null;
332
+ }
333
+ }, [
334
+ keys
335
+ ]);
336
+ };
337
+
338
+ // packages/plugins/experimental/plugin-github/src/hooks/useGhIdFromUrl.ts
339
+ import { useMemo as useMemo2 } from "react";
340
+ var useGhIdFromUrl = (ghUrlValue) => useMemo2(() => {
341
+ try {
342
+ const url = new URL(ghUrlValue);
343
+ const [_, owner, repo, type, ...rest] = url.pathname.split("/");
344
+ if (type === "blob") {
345
+ const [ref, ...pathParts] = rest;
346
+ const path = pathParts.join("/");
347
+ const ext = pathParts[pathParts.length - 1].split(".")[1];
348
+ return ext === "md" ? `${owner}/${repo}/blob/${ref}/${path}` : null;
349
+ } else if (type === "issues") {
350
+ const [issueNumberString] = rest;
351
+ return `${owner}/${repo}/issues/${issueNumberString}`;
352
+ } else {
353
+ return null;
354
+ }
355
+ } catch (e) {
356
+ return null;
357
+ }
358
+ }, [
359
+ ghUrlValue
360
+ ]);
361
+
362
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverDialog.tsx
363
+ import React9 from "react";
364
+ import { Button as Button3, useTranslation as useTranslation6 } from "@dxos/react-ui";
365
+
366
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverTree.tsx
367
+ import React8, { useCallback, useContext as useContext3 } from "react";
368
+ import { useClient } from "@dxos/react-client";
369
+ import { useSpaces as useSpaces2 } from "@dxos/react-client/echo";
370
+ import { Button as Button2, Dialog, Tree as Tree2, useId as useId3, useTranslation as useTranslation5 } from "@dxos/react-ui";
371
+
372
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverContext.tsx
373
+ import React5, { createContext as createContext2, useContext as useContext2, useEffect as useEffect4, useMemo as useMemo3, useState as useState4 } from "react";
374
+ import { create } from "@dxos/echo-schema";
375
+ import { log as log3 } from "@dxos/log";
376
+ import { DocumentType, TextType } from "@dxos/plugin-markdown/types";
377
+ import { useMulticastObservable } from "@dxos/react-client";
378
+ import { getMeta, SpaceState, useQuery, useSpaces } from "@dxos/react-client/echo";
379
+ import { useIdentity } from "@dxos/react-client/halo";
380
+
381
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/spaceResolvers.ts
382
+ import get from "lodash.get";
383
+ import update from "lodash.update";
384
+ var ghMatch = (space, identityHex, id) => {
385
+ const [ghOwner, ghRepo, ..._ghEtc] = id.split("/");
386
+ return get(space.properties, [
387
+ "members",
388
+ identityHex,
389
+ "github",
390
+ "repos"
391
+ ], []).includes(`${ghOwner}/${ghRepo}`);
392
+ };
393
+ var matchSpace = (space, identityHex, source, id) => {
394
+ if (!id) {
395
+ return false;
396
+ }
397
+ switch (source) {
398
+ case "github.com":
399
+ return ghMatch(space, identityHex, id);
400
+ default:
401
+ return false;
402
+ }
403
+ };
404
+ var ghBind = (space, identityHex, id) => {
405
+ const [ghOwner, ghRepo, ..._ghEtc] = id.split("/");
406
+ update(space.properties, [
407
+ "members",
408
+ identityHex,
409
+ "github",
410
+ "repos"
411
+ ], (ghBindings) => {
412
+ return [
413
+ ...ghBindings ?? [],
414
+ `${ghOwner}/${ghRepo}`
415
+ ];
416
+ });
417
+ return space.properties.members?.[identityHex]?.github?.repos ?? [];
418
+ };
419
+ var bindSpace = (space, identityHex, source, id) => {
420
+ switch (source) {
421
+ case "github.com":
422
+ return ghBind(space, identityHex, id);
423
+ default:
424
+ return [];
425
+ }
426
+ };
427
+ var ghUnbind = (space, identityHex, id) => {
428
+ const [ghOwner, ghRepo, ..._ghEtc] = id.split("/");
429
+ update(space.properties, [
430
+ "members",
431
+ identityHex,
432
+ "github",
433
+ "repos"
434
+ ], (ghBindings) => {
435
+ const index = ghBindings.indexOf(`${ghOwner}/${ghRepo}`);
436
+ if (index >= 0) {
437
+ const result = [
438
+ ...ghBindings
439
+ ];
440
+ result.splice(index, 1);
441
+ return result;
442
+ } else {
443
+ return ghBindings;
444
+ }
445
+ });
446
+ return space.properties.members?.[identityHex]?.github?.repos ?? [];
447
+ };
448
+ var unbindSpace = (space, identityHex, source, id) => {
449
+ switch (source) {
450
+ case "github.com":
451
+ return ghUnbind(space, identityHex, id);
452
+ default:
453
+ return [];
454
+ }
455
+ };
456
+ var ghDisplayName = (id) => {
457
+ const [ghOwner, ghRepo, ghResource, ...etc] = id.split("/");
458
+ switch (ghResource) {
459
+ case "issues":
460
+ return `${ghOwner}/${ghRepo} #${etc[0]}`;
461
+ default:
462
+ return `${ghOwner}/${ghRepo} ${[
463
+ ghResource,
464
+ ...etc
465
+ ].join("/")}`;
466
+ }
467
+ };
468
+ var displayName = (source, id) => {
469
+ switch (source) {
470
+ case "github.com":
471
+ return ghDisplayName(id);
472
+ default:
473
+ return id;
474
+ }
475
+ };
476
+
477
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverContext.tsx
478
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverContext.tsx";
479
+ var getLocationIdentifier = () => {
480
+ const searchParams = new URLSearchParams(window.location.search);
481
+ const location2 = searchParams.get("location");
482
+ let source, id;
483
+ try {
484
+ const url = location2 ? new URL(location2) : void 0;
485
+ source = url?.hostname.split(".").reverse().join(".");
486
+ id = url?.pathname.slice(1);
487
+ } catch (err) {
488
+ log3.catch(err, void 0, {
489
+ F: __dxlog_file3,
490
+ L: 34,
491
+ S: void 0,
492
+ C: (f, a) => f(...a)
493
+ });
494
+ }
495
+ return [
496
+ source,
497
+ id
498
+ ];
499
+ };
500
+ var SpaceResolverContext = /* @__PURE__ */ createContext2({
501
+ space: null,
502
+ setSpace: (_space) => {
503
+ }
504
+ });
505
+ var SpaceResolverProvider = ({ children }) => {
506
+ const identity = useIdentity();
507
+ const identityHex = identity?.identityKey.toHex();
508
+ const [source, id] = getLocationIdentifier();
509
+ const spaces = useSpaces({
510
+ all: true
511
+ });
512
+ const [nextSpace, setSpace] = useState4(null);
513
+ const space = useMemo3(() => nextSpace ?? (identityHex ? spaces.find((space2) => matchSpace(space2, identityHex, source, id)) ?? null : null), [
514
+ spaces,
515
+ nextSpace,
516
+ identityHex,
517
+ source,
518
+ id
519
+ ]);
520
+ return /* @__PURE__ */ React5.createElement(SpaceResolverContext.Provider, {
521
+ value: {
522
+ space,
523
+ setSpace,
524
+ source,
525
+ id,
526
+ identityHex
527
+ }
528
+ }, children);
529
+ };
530
+ var defaultDocumentResolverContext = {
531
+ document: null,
532
+ setDocument: (_document) => {
533
+ }
534
+ };
535
+ var DocumentResolverContext = /* @__PURE__ */ createContext2(defaultDocumentResolverContext);
536
+ var DocumentResolverProviderImpl = ({ space, source, id, children }) => {
537
+ const spaceState = useMulticastObservable(space.state);
538
+ const [document2, setDocument] = useState4(null);
539
+ const defaultDisplayName = displayName(source, id);
540
+ const documents = useQuery(space, (obj) => {
541
+ const keys = getMeta(obj)?.keys;
542
+ return keys?.find((key) => key.source === source && key.id === id);
543
+ });
544
+ useEffect4(() => {
545
+ const handler = (event) => {
546
+ if (event.source !== window.parent || spaceState !== SpaceState.SPACE_READY) {
547
+ return;
548
+ }
549
+ if (event.data.type === "initial-data") {
550
+ const nextDocument = space.db.add(create(DocumentType, {
551
+ name: defaultDisplayName,
552
+ content: create(TextType, {
553
+ content: event.data.content
554
+ }),
555
+ threads: []
556
+ }, {
557
+ keys: [
558
+ {
559
+ source,
560
+ id
561
+ }
562
+ ]
563
+ }));
564
+ setDocument(nextDocument);
565
+ }
566
+ };
567
+ if (documents.length === 0) {
568
+ window.addEventListener("message", handler);
569
+ window.parent.postMessage({
570
+ type: "request-initial-data"
571
+ }, "https://github.com");
572
+ return () => window.removeEventListener("message", handler);
573
+ } else {
574
+ setDocument(documents[0]);
575
+ }
576
+ }, [
577
+ spaceState,
578
+ space,
579
+ documents
580
+ ]);
581
+ return /* @__PURE__ */ React5.createElement(DocumentResolverContext.Provider, {
582
+ value: {
583
+ document: document2,
584
+ setDocument
585
+ }
586
+ }, children);
587
+ };
588
+ var DocumentResolverProvider = ({ children }) => {
589
+ const { space, source, id } = useContext2(SpaceResolverContext);
590
+ return space && source && id ? /* @__PURE__ */ React5.createElement(DocumentResolverProviderImpl, {
591
+ space,
592
+ source,
593
+ id
594
+ }, children) : /* @__PURE__ */ React5.createElement(DocumentResolverContext.Provider, {
595
+ value: defaultDocumentResolverContext
596
+ }, children);
597
+ };
598
+
599
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/SpacePickerTreeItem.tsx
600
+ import { CaretDown, CaretRight } from "@phosphor-icons/react";
601
+ import React7, { useMemo as useMemo4, useState as useState5 } from "react";
602
+ import { DocumentType as DocumentType2 } from "@dxos/plugin-markdown/types";
603
+ import { getSpaceDisplayName } from "@dxos/plugin-space";
604
+ import { useMulticastObservable as useMulticastObservable2 } from "@dxos/react-client";
605
+ import { SpaceState as SpaceState2, useQuery as useQuery2, Filter } from "@dxos/react-client/echo";
606
+ import { Button, Tag, Tooltip, Tree, TreeItem as TreeItem2, useTranslation as useTranslation4 } from "@dxos/react-ui";
607
+ import { staticDisabled } from "@dxos/react-ui-theme";
608
+
609
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/DocumentTreeItem.tsx
610
+ import { TextAa } from "@phosphor-icons/react";
611
+ import React6 from "react";
612
+ import { useTranslation as useTranslation3, TreeItem } from "@dxos/react-ui";
613
+ import { getSize as getSize2, mx as mx3 } from "@dxos/react-ui-theme";
614
+ var DocumentTreeItem = ({ document: document2 }) => {
615
+ const { t } = useTranslation3(GITHUB_PLUGIN);
616
+ return /* @__PURE__ */ React6.createElement(TreeItem.Root, {
617
+ classNames: "flex gap-2"
618
+ }, /* @__PURE__ */ React6.createElement(TreeItem.Heading, {
619
+ classNames: "contents"
620
+ }, /* @__PURE__ */ React6.createElement(TextAa, {
621
+ weight: "regular",
622
+ className: mx3(getSize2(4), "shrink-0 mbs-2")
623
+ }), /* @__PURE__ */ React6.createElement("span", {
624
+ className: "grow mbs-2 text-sm no-leading"
625
+ }, document2.name || t("document title placeholder", {
626
+ ns: "dxos.org/plugin/markdown"
627
+ }))));
628
+ };
629
+
630
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/SpacePickerTreeItem.tsx
631
+ var SpacePickerTreeItem = ({ identityHex, space, source, id, setSpace, selected }) => {
632
+ const { t } = useTranslation4(GITHUB_PLUGIN);
633
+ const spaceSate = useMulticastObservable2(space.state);
634
+ const disabled = spaceSate !== SpaceState2.SPACE_READY;
635
+ const spaceDisplayName = getSpaceDisplayName(space);
636
+ const documents = useQuery2(space, Filter.schema(DocumentType2));
637
+ const hasDocuments = documents.length > 0;
638
+ const [open, setOpen] = useState5(false);
639
+ const nBoundMembers = useMemo4(() => {
640
+ return Object.keys(space.properties.members ?? {}).filter((identityHex2) => matchSpace(space, identityHex2, source, id)).length;
641
+ }, [
642
+ source,
643
+ id,
644
+ space.properties
645
+ ]);
646
+ const OpenTriggerIcon = open ? CaretDown : CaretRight;
647
+ return /* @__PURE__ */ React7.createElement(TreeItem2.Root, {
648
+ collapsible: true,
649
+ open,
650
+ onOpenChange: setOpen,
651
+ classNames: [
652
+ "mbe-2 block",
653
+ disabled && staticDisabled
654
+ ],
655
+ ...disabled && {
656
+ "aria-disabled": true
657
+ }
658
+ }, /* @__PURE__ */ React7.createElement("div", {
659
+ role: "none",
660
+ className: "flex items-center gap-2"
661
+ }, hasDocuments ? /* @__PURE__ */ React7.createElement(TreeItem2.OpenTrigger, null, /* @__PURE__ */ React7.createElement(OpenTriggerIcon, null)) : /* @__PURE__ */ React7.createElement(TreeItem2.OpenTrigger, {
662
+ disabled: true,
663
+ classNames: staticDisabled
664
+ }, /* @__PURE__ */ React7.createElement(CaretRight, null)), /* @__PURE__ */ React7.createElement(TreeItem2.Heading, {
665
+ classNames: "grow break-words pbs-1 text-base font-medium",
666
+ "data-testid": "composer.spaceTreeItemHeading"
667
+ }, Array.isArray(spaceDisplayName) ? t(...spaceDisplayName) : spaceDisplayName), nBoundMembers > 0 && /* @__PURE__ */ React7.createElement(Tooltip.Root, null, /* @__PURE__ */ React7.createElement(Tooltip.Trigger, {
668
+ asChild: true
669
+ }, /* @__PURE__ */ React7.createElement(Tag, {
670
+ palette: "info",
671
+ "aria-label": t("bound members message", {
672
+ count: nBoundMembers
673
+ })
674
+ }, nBoundMembers)), /* @__PURE__ */ React7.createElement(Tooltip.Portal, null, /* @__PURE__ */ React7.createElement(Tooltip.Content, {
675
+ side: "bottom"
676
+ }, /* @__PURE__ */ React7.createElement(Tooltip.Arrow, null), t("bound members message", {
677
+ count: nBoundMembers
678
+ })))), /* @__PURE__ */ React7.createElement(Button, {
679
+ disabled: selected,
680
+ density: "fine",
681
+ classNames: "shrink-0",
682
+ onClick: () => setSpace(space)
683
+ }, t(selected ? "selected label" : "select label"))), /* @__PURE__ */ React7.createElement(TreeItem2.Body, {
684
+ className: "pis-4"
685
+ }, hasDocuments && /* @__PURE__ */ React7.createElement(Tree.Branch, null, documents.map((document2) => /* @__PURE__ */ React7.createElement(DocumentTreeItem, {
686
+ key: document2.id,
687
+ document: document2
688
+ })))));
689
+ };
690
+
691
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverTree.tsx
692
+ var ResolverTree = () => {
693
+ const client = useClient();
694
+ const spaces = useSpaces2({
695
+ all: true
696
+ });
697
+ const treeLabel = useId3("treeLabel");
698
+ const { t } = useTranslation5(GITHUB_PLUGIN);
699
+ const { space: selectedSpace, setSpace: setSelectedSpace, source, id, identityHex } = useContext3(SpaceResolverContext);
700
+ const setSpace = useCallback((nextSpace) => {
701
+ if (identityHex && source && id) {
702
+ selectedSpace && unbindSpace(selectedSpace, identityHex, source, id);
703
+ nextSpace && bindSpace(nextSpace, identityHex, source, id);
704
+ }
705
+ setSelectedSpace(nextSpace);
706
+ }, [
707
+ selectedSpace,
708
+ setSelectedSpace,
709
+ identityHex,
710
+ source,
711
+ id
712
+ ]);
713
+ return spaces.length ? /* @__PURE__ */ React8.createElement(React8.Fragment, null, " ", /* @__PURE__ */ React8.createElement(Dialog.Title, {
714
+ tabIndex: -1,
715
+ classNames: "shrink-0"
716
+ }, t("resolver tree label")), /* @__PURE__ */ React8.createElement(Dialog.Description, null, t("resolver tree description")), /* @__PURE__ */ React8.createElement("div", {
717
+ role: "separator",
718
+ className: "shrink-0 bs-px bg-neutral-500/20 mlb-1"
719
+ }), /* @__PURE__ */ React8.createElement(Tree2.Root, {
720
+ "aria-label": t("resolver tree label"),
721
+ "data-testid": "composer.sidebarTree",
722
+ classNames: "overflow-y-auto -mli-2 p-2"
723
+ }, spaces.map((space) => {
724
+ return /* @__PURE__ */ React8.createElement(SpacePickerTreeItem, {
725
+ key: space.key.toHex(),
726
+ space,
727
+ selected: selectedSpace === space,
728
+ setSpace,
729
+ identityHex,
730
+ source,
731
+ id
732
+ });
733
+ }))) : /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement("h1", {
734
+ className: "text-lg font-normal",
735
+ id: treeLabel
736
+ }, t("resolver no spaces message")), /* @__PURE__ */ React8.createElement("div", {
737
+ role: "separator",
738
+ className: "bs-px bg-neutral-500/20 mlb-2"
739
+ }), /* @__PURE__ */ React8.createElement(Button2, {
740
+ classNames: "block is-full",
741
+ onClick: async () => {
742
+ const space = await client.spaces.create();
743
+ bindSpace(space, identityHex, source, id);
744
+ setSpace(space);
745
+ }
746
+ }, t("resolver create space label")));
747
+ };
748
+
749
+ // packages/plugins/experimental/plugin-github/src/components/GithubEchoResolverProviders/ResolverDialog.tsx
750
+ var ResolverDialog = ({ handleJoinSpace, handleCreateSpace }) => {
751
+ const { t } = useTranslation6(GITHUB_PLUGIN);
752
+ return /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement(ResolverTree, null), /* @__PURE__ */ React9.createElement("div", {
753
+ role: "group",
754
+ className: "shrink-0 flex is-full gap-2"
755
+ }, /* @__PURE__ */ React9.createElement(Button3, {
756
+ classNames: "grow",
757
+ onClick: handleCreateSpace
758
+ }, t("create space label", {
759
+ ns: "appkit"
760
+ })), /* @__PURE__ */ React9.createElement(Button3, {
761
+ classNames: "grow",
762
+ onClick: handleJoinSpace
763
+ }, t("join space label", {
764
+ ns: "appkit"
765
+ }))));
766
+ };
767
+
768
+ // packages/plugins/experimental/plugin-github/src/components/EmbeddedMain/EmbeddedMain.tsx
769
+ var overlayAttrs = {
770
+ side: "top",
771
+ sideOffset: 4
772
+ };
773
+ var EmbeddedLayoutImpl = () => {
774
+ const { t } = useTranslation7(GITHUB_PLUGIN);
775
+ const { space, source, id, identityHex } = useContext4(SpaceResolverContext);
776
+ const { document: document2 } = useContext4(DocumentResolverContext);
777
+ const { dispatch } = useIntent();
778
+ const client = useClient2();
779
+ const handleCloseEmbed = useCallback2(() => {
780
+ window.parent.postMessage({
781
+ type: "close-embed"
782
+ }, "https://github.com");
783
+ }, []);
784
+ const handleSaveAndCloseEmbed = useCallback2(() => {
785
+ document2 && window.parent.postMessage({
786
+ type: "save-data",
787
+ content: document2.content?.content
788
+ }, "https://github.com");
789
+ }, [
790
+ document2
791
+ ]);
792
+ const handleCreateSpace = () => dispatch({
793
+ action: SpaceAction.CREATE
794
+ });
795
+ const handleJoinSpace = () => dispatch({
796
+ action: SpaceAction.JOIN
797
+ });
798
+ const handleInvite = useCallback2(() => {
799
+ if (client && space) {
800
+ void client.shell.shareSpace({
801
+ spaceKey: space.key
802
+ });
803
+ }
804
+ }, [
805
+ client,
806
+ space
807
+ ]);
808
+ const [editorViewState, setEditorViewState] = useState6("editor");
809
+ const isPreviewing = editorViewState === "preview";
810
+ const suppressNextTooltip = useRef(false);
811
+ const [optionsTooltipOpen, setOptionsTooltipOpen] = useState6(false);
812
+ const [optionsMenuOpen, setOptionsMenuOpen] = useState6(false);
813
+ const [renameDialogOpen, setRenameDialogOpen] = useState6(false);
814
+ const [resolverDialogOpen, setResolverDialogOpen] = useState6(false);
815
+ const spaceFallbackValue = hexToFallback(space?.key.toHex() ?? "0");
816
+ const docGhId = useDocGhId((document2 ? getMeta2(document2)?.keys : []) ?? []);
817
+ const name = space && getSpaceDisplayName2(space);
818
+ return /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement("style", {
819
+ type: "text/css"
820
+ }, `
821
+ :root {
822
+ --surface-bg: #F6F8FA;
823
+ }
824
+ .dark:root {
825
+ --surface-bg: #161b22;
826
+ }
827
+ `), /* @__PURE__ */ React10.createElement(DensityProvider, {
828
+ density: "fine"
829
+ }, /* @__PURE__ */ React10.createElement("div", {
830
+ role: "none",
831
+ className: "fixed inline-end-2 block-end-2 z-10 flex gap-2"
832
+ }, /* @__PURE__ */ React10.createElement(Tooltip2.Root, null, /* @__PURE__ */ React10.createElement(Tooltip2.Trigger, {
833
+ asChild: true
834
+ }, /* @__PURE__ */ React10.createElement(Button4, {
835
+ disabled: !space,
836
+ onClick: handleInvite
837
+ }, /* @__PURE__ */ React10.createElement("span", {
838
+ className: "sr-only"
839
+ }, t("create invitation label", {
840
+ ns: "appkit"
841
+ })), /* @__PURE__ */ React10.createElement(UserPlus, {
842
+ className: getSize3(5)
843
+ }))), /* @__PURE__ */ React10.createElement(Tooltip2.Content, overlayAttrs, t("create invitation label", {
844
+ ns: "appkit"
845
+ }), /* @__PURE__ */ React10.createElement(Tooltip2.Arrow, null))), /* @__PURE__ */ React10.createElement(Tooltip2.Root, null, /* @__PURE__ */ React10.createElement(Tooltip2.Trigger, {
846
+ asChild: true
847
+ }, /* @__PURE__ */ React10.createElement(Toggle, {
848
+ disabled: !(space && document2),
849
+ pressed: isPreviewing,
850
+ onPressedChange: (nextPressed) => setEditorViewState(nextPressed ? "preview" : "editor")
851
+ }, /* @__PURE__ */ React10.createElement("span", {
852
+ className: "sr-only"
853
+ }, t(isPreviewing ? "exit gfm preview label" : "preview gfm label")), isPreviewing ? /* @__PURE__ */ React10.createElement(PencilSimpleLine, {
854
+ className: getSize3(5)
855
+ }) : /* @__PURE__ */ React10.createElement(Eye, {
856
+ className: getSize3(5)
857
+ }))), /* @__PURE__ */ React10.createElement(Tooltip2.Content, overlayAttrs, t(isPreviewing ? "exit gfm preview label" : "preview gfm label"), /* @__PURE__ */ React10.createElement(Tooltip2.Arrow, null))), /* @__PURE__ */ React10.createElement(Tooltip2.Root, {
858
+ open: optionsTooltipOpen,
859
+ onOpenChange: (nextOpen) => {
860
+ if (suppressNextTooltip.current) {
861
+ setOptionsTooltipOpen(false);
862
+ suppressNextTooltip.current = false;
863
+ } else {
864
+ setOptionsTooltipOpen(nextOpen);
865
+ }
866
+ }
867
+ }, /* @__PURE__ */ React10.createElement(DropdownMenu.Root, {
868
+ modal: false,
869
+ open: optionsMenuOpen,
870
+ onOpenChange: (nextOpen) => {
871
+ if (!nextOpen) {
872
+ suppressNextTooltip.current = true;
873
+ }
874
+ return setOptionsMenuOpen(nextOpen);
875
+ }
876
+ }, /* @__PURE__ */ React10.createElement(Tooltip2.Trigger, {
877
+ asChild: true
878
+ }, /* @__PURE__ */ React10.createElement(DropdownMenu.Trigger, {
879
+ asChild: true,
880
+ disabled: !(space && document2)
881
+ }, /* @__PURE__ */ React10.createElement(Button4, null, /* @__PURE__ */ React10.createElement(DotsThreeVertical, {
882
+ className: getSize3(5)
883
+ }), /* @__PURE__ */ React10.createElement("span", {
884
+ className: "sr-only"
885
+ }, t("embedded options label"))))), /* @__PURE__ */ React10.createElement(DropdownMenu.Content, overlayAttrs, /* @__PURE__ */ React10.createElement(DropdownMenu.Viewport, null, /* @__PURE__ */ React10.createElement(DropdownMenu.Item, {
886
+ asChild: true
887
+ }, /* @__PURE__ */ React10.createElement("a", {
888
+ target: "_blank",
889
+ rel: "noreferrer",
890
+ href: space && document2 ? `${location.origin}/dxos/space/${space?.key.toHex() ?? "never"}/${document2.id}` : "#"
891
+ }, /* @__PURE__ */ React10.createElement(ArrowSquareOut2, {
892
+ className: mx4("shrink-0", getSize3(5))
893
+ }), /* @__PURE__ */ React10.createElement("span", {
894
+ className: "grow"
895
+ }, t("open in composer label", {
896
+ ns: GITHUB_PLUGIN
897
+ })))), /* @__PURE__ */ React10.createElement(DropdownMenu.Separator, null), /* @__PURE__ */ React10.createElement(DropdownMenu.GroupLabel, null, t("active space label", {
898
+ ns: SPACE_PLUGIN
899
+ }), /* @__PURE__ */ React10.createElement(Avatar.Root, {
900
+ size: 5,
901
+ variant: "circle"
902
+ }, /* @__PURE__ */ React10.createElement("div", {
903
+ role: "none",
904
+ className: "flex gap-1 mlb-1 items-center"
905
+ }, /* @__PURE__ */ React10.createElement(Avatar.Frame, null, /* @__PURE__ */ React10.createElement(Avatar.Fallback, {
906
+ text: spaceFallbackValue.emoji
907
+ })), /* @__PURE__ */ React10.createElement(Avatar.Label, {
908
+ classNames: "text-sm text-[--surface-text]"
909
+ }, name && toLocalizedString(name, t))))), /* @__PURE__ */ React10.createElement(DropdownMenu.Item, {
910
+ onClick: () => setRenameDialogOpen(true)
911
+ }, /* @__PURE__ */ React10.createElement("span", {
912
+ className: "grow"
913
+ }, t("rename space label", {
914
+ ns: SPACE_PLUGIN
915
+ })), /* @__PURE__ */ React10.createElement(PencilSimpleLine, {
916
+ className: mx4("shrink-0", getSize3(5))
917
+ })), /* @__PURE__ */ React10.createElement(DropdownMenu.Item, {
918
+ onClick: () => setResolverDialogOpen(true)
919
+ }, /* @__PURE__ */ React10.createElement("span", {
920
+ className: "grow"
921
+ }, t("unset repo space label")), /* @__PURE__ */ React10.createElement(Option, {
922
+ className: mx4("shrink-0", getSize3(5))
923
+ }))), /* @__PURE__ */ React10.createElement(DropdownMenu.Arrow, null)), /* @__PURE__ */ React10.createElement(Tooltip2.Content, overlayAttrs, t("embedded options label"), /* @__PURE__ */ React10.createElement(Tooltip2.Arrow, null)))), /* @__PURE__ */ React10.createElement(ButtonGroup, {
924
+ classNames: [
925
+ !(space && document2) && "shadow-none"
926
+ ]
927
+ }, /* @__PURE__ */ React10.createElement(Button4, {
928
+ disabled: !(space && document2),
929
+ onClick: handleSaveAndCloseEmbed
930
+ }, t("save and close label")), /* @__PURE__ */ React10.createElement(DropdownMenu.Root, null, /* @__PURE__ */ React10.createElement(DropdownMenu.Trigger, {
931
+ asChild: true,
932
+ disabled: !(space && document2)
933
+ }, /* @__PURE__ */ React10.createElement(Button4, null, /* @__PURE__ */ React10.createElement(CaretDown2, null))), /* @__PURE__ */ React10.createElement(DropdownMenu.Portal, null, /* @__PURE__ */ React10.createElement(DropdownMenu.Content, overlayAttrs, /* @__PURE__ */ React10.createElement(DropdownMenu.Viewport, null, /* @__PURE__ */ React10.createElement(DropdownMenu.Item, {
934
+ onClick: handleSaveAndCloseEmbed,
935
+ classNames: "block"
936
+ }, /* @__PURE__ */ React10.createElement("p", null, t("save and close label")), /* @__PURE__ */ React10.createElement("p", {
937
+ className: descriptionText
938
+ }, t("save and close description"))), /* @__PURE__ */ React10.createElement(DropdownMenu.Item, {
939
+ onClick: handleCloseEmbed,
940
+ classNames: "block"
941
+ }, /* @__PURE__ */ React10.createElement("p", null, t("close label", {
942
+ ns: "appkit"
943
+ })), /* @__PURE__ */ React10.createElement("p", {
944
+ className: descriptionText
945
+ }, t("close embed description")))), /* @__PURE__ */ React10.createElement(DropdownMenu.Arrow, null)))))), space && document2 ? editorViewState === "preview" ? /* @__PURE__ */ React10.createElement(Main.Content, {
946
+ classNames: "min-bs-[100dvh] flex flex-col p-0.5"
947
+ }, /* @__PURE__ */ React10.createElement(GfmPreview, {
948
+ markdown: document2.content?.toString() ?? "",
949
+ ...docGhId && {
950
+ owner: docGhId.owner,
951
+ repo: docGhId.repo
952
+ }
953
+ })) : (
954
+ // TODO(burdon): This will break since model is not defined.
955
+ /* @__PURE__ */ React10.createElement(Surface, {
956
+ role: "main",
957
+ data: {
958
+ properties: document2,
959
+ view: "embedded"
960
+ }
961
+ })
962
+ ) : source && id && identityHex ? /* @__PURE__ */ React10.createElement(Dialog2.Root, {
963
+ open: true,
964
+ onOpenChange: () => true
965
+ }, /* @__PURE__ */ React10.createElement("div", {
966
+ role: "none",
967
+ className: defaultTx("dialog.overlay", "dialog--resolver__overlay", {}, "static bs-full")
968
+ }, /* @__PURE__ */ React10.createElement("div", {
969
+ role: "none",
970
+ className: defaultTx("dialog.content", "dialog--resolver__content", {}, "p-2 bs-72 flex flex-col shadow-none bg-transparent")
971
+ }, /* @__PURE__ */ React10.createElement(ResolverDialog, {
972
+ handleCreateSpace,
973
+ handleJoinSpace
974
+ })))) : null, space && /* @__PURE__ */ React10.createElement(Dialog2.Root, {
975
+ open: renameDialogOpen,
976
+ onOpenChange: setRenameDialogOpen
977
+ }, /* @__PURE__ */ React10.createElement(Dialog2.Overlay, {
978
+ classNames: "backdrop-blur"
979
+ }, /* @__PURE__ */ React10.createElement(Dialog2.Content, null, /* @__PURE__ */ React10.createElement(Surface, {
980
+ role: "dialog",
981
+ data: {
982
+ content: "dxos.org/plugin/space/RenameSpaceDialog",
983
+ subject: space
984
+ }
985
+ })))), /* @__PURE__ */ React10.createElement(Dialog2.Root, {
986
+ open: resolverDialogOpen,
987
+ onOpenChange: setResolverDialogOpen
988
+ }, /* @__PURE__ */ React10.createElement(Dialog2.Overlay, {
989
+ classNames: "backdrop-blur"
990
+ }, /* @__PURE__ */ React10.createElement(Dialog2.Content, null, /* @__PURE__ */ React10.createElement(ResolverDialog, {
991
+ handleCreateSpace,
992
+ handleJoinSpace
993
+ }))))));
994
+ };
995
+ var EmbeddedMain = () => {
996
+ return /* @__PURE__ */ React10.createElement(SpaceResolverProvider, null, /* @__PURE__ */ React10.createElement(DocumentResolverProvider, null, /* @__PURE__ */ React10.createElement(EmbeddedLayoutImpl, null)));
997
+ };
998
+
999
+ // packages/plugins/experimental/plugin-github/src/components/ExportDialog.tsx
1000
+ import React11, { useCallback as useCallback3, useState as useState7 } from "react";
1001
+ import { log as log4 } from "@dxos/log";
1002
+ import { Button as Button5, Dialog as Dialog3, Input as Input2, Trans as Trans2, useTranslation as useTranslation8 } from "@dxos/react-ui";
1003
+
1004
+ // packages/plugins/experimental/plugin-github/src/components/ImportDialog.tsx
1005
+ import React12, { useCallback as useCallback4 } from "react";
1006
+ import { log as log5 } from "@dxos/log";
1007
+ import { Button as Button6, Dialog as Dialog4, useTranslation as useTranslation9 } from "@dxos/react-ui";
1008
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-github/src/components/ImportDialog.tsx";
1009
+ var ImportDialog = ({ docGhId, onUpdate }) => {
1010
+ const { t } = useTranslation9(GITHUB_PLUGIN);
1011
+ const { octokit } = useOctokitContext();
1012
+ const importGhIssueContent = useCallback4(async () => {
1013
+ if (octokit && docGhId && "issueNumber") {
1014
+ try {
1015
+ const { owner, repo, issueNumber } = docGhId;
1016
+ const { data } = await octokit.rest.issues.get({
1017
+ owner,
1018
+ repo,
1019
+ issue_number: issueNumber
1020
+ });
1021
+ onUpdate(data.body ?? "");
1022
+ } catch (err) {
1023
+ log5.error("Failed to import from Github issue", err, {
1024
+ F: __dxlog_file4,
1025
+ L: 25,
1026
+ S: void 0,
1027
+ C: (f, a) => f(...a)
1028
+ });
1029
+ }
1030
+ } else {
1031
+ log5.error("Not prepared to import from Github issue when requested.", void 0, {
1032
+ F: __dxlog_file4,
1033
+ L: 28,
1034
+ S: void 0,
1035
+ C: (f, a) => f(...a)
1036
+ });
1037
+ }
1038
+ }, [
1039
+ octokit,
1040
+ docGhId
1041
+ ]);
1042
+ const importGhFileContent = useCallback4(async () => {
1043
+ if (octokit && docGhId && "path" in docGhId) {
1044
+ try {
1045
+ const { owner, repo, path } = docGhId;
1046
+ const { data } = await octokit.rest.repos.getContent({
1047
+ owner,
1048
+ repo,
1049
+ path
1050
+ });
1051
+ if (!Array.isArray(data) && data.type === "file") {
1052
+ onUpdate(atob(data.content));
1053
+ } else {
1054
+ log5.error("Did not receive file with content from Github.", void 0, {
1055
+ F: __dxlog_file4,
1056
+ L: 40,
1057
+ S: void 0,
1058
+ C: (f, a) => f(...a)
1059
+ });
1060
+ }
1061
+ } catch (err) {
1062
+ log5.error("Failed to import from Github file", err, {
1063
+ F: __dxlog_file4,
1064
+ L: 43,
1065
+ S: void 0,
1066
+ C: (f, a) => f(...a)
1067
+ });
1068
+ }
1069
+ } else {
1070
+ log5.error("Not prepared to import from Github file when requested.", void 0, {
1071
+ F: __dxlog_file4,
1072
+ L: 46,
1073
+ S: void 0,
1074
+ C: (f, a) => f(...a)
1075
+ });
1076
+ }
1077
+ }, [
1078
+ octokit,
1079
+ docGhId
1080
+ ]);
1081
+ const handleGhImport = useCallback4(() => {
1082
+ return docGhId && ("issueNumber" in docGhId ? importGhIssueContent() : "path" in docGhId ? importGhFileContent() : null);
1083
+ }, [
1084
+ importGhIssueContent,
1085
+ importGhFileContent,
1086
+ docGhId
1087
+ ]);
1088
+ return /* @__PURE__ */ React12.createElement(Dialog4.Content, null, /* @__PURE__ */ React12.createElement(Dialog4.Title, null, t("confirm import title")), /* @__PURE__ */ React12.createElement("p", {
1089
+ className: "plb-2"
1090
+ }, t("confirm import body")), /* @__PURE__ */ React12.createElement("div", {
1091
+ role: "none",
1092
+ className: "flex justify-end gap-2"
1093
+ }, /* @__PURE__ */ React12.createElement(Dialog4.Close, {
1094
+ asChild: true
1095
+ }, /* @__PURE__ */ React12.createElement(Button6, null, t("cancel label", {
1096
+ ns: "appkit"
1097
+ }))), /* @__PURE__ */ React12.createElement(Dialog4.Close, {
1098
+ asChild: true
1099
+ }, /* @__PURE__ */ React12.createElement(Button6, {
1100
+ variant: "primary",
1101
+ onClick: handleGhImport
1102
+ }, t("import from github label")))));
1103
+ };
1104
+
1105
+ // packages/plugins/experimental/plugin-github/src/components/Issue.tsx
1106
+ import { IconBase } from "@phosphor-icons/react";
1107
+ import React13, { forwardRef } from "react";
1108
+ var weights = /* @__PURE__ */ new Map([
1109
+ [
1110
+ "bold",
1111
+ /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("path", {
1112
+ d: "M128,20A108,108,0,1,0,236,128,108.12,108.12,0,0,0,128,20Zm0,192a84,84,0,1,1,84-84A84.09,84.09,0,0,1,128,212Z"
1113
+ }), /* @__PURE__ */ React13.createElement("path", {
1114
+ d: "M144,128a16,16,0,1,1-16-16A16,16,0,0,1,144,128Z"
1115
+ }))
1116
+ ],
1117
+ [
1118
+ "duotone",
1119
+ /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("path", {
1120
+ d: "M224,128a96,96,0,1,1-96-96A96,96,0,0,1,224,128Z",
1121
+ opacity: "0.2"
1122
+ }), /* @__PURE__ */ React13.createElement("path", {
1123
+ d: "M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Z"
1124
+ }), /* @__PURE__ */ React13.createElement("path", {
1125
+ d: "M176,128a48,48,0,1,1-48-48A48,48,0,0,1,176,128Z",
1126
+ opacity: "0.2"
1127
+ }), /* @__PURE__ */ React13.createElement("path", {
1128
+ d: "M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Z"
1129
+ }))
1130
+ ],
1131
+ [
1132
+ "fill",
1133
+ /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("path", {
1134
+ d: "M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Z"
1135
+ }), /* @__PURE__ */ React13.createElement("path", {
1136
+ d: "M128,80a48,48,0,1,0,48,48A48,48,0,0,0,128,80Zm0,60a12,12,0,1,1,12-12A12,12,0,0,1,128,140Z"
1137
+ }))
1138
+ ],
1139
+ [
1140
+ "light",
1141
+ /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("path", {
1142
+ d: "M128,26A102,102,0,1,0,230,128,102.12,102.12,0,0,0,128,26Zm0,192a90,90,0,1,1,90-90A90.1,90.1,0,0,1,128,218Z"
1143
+ }), /* @__PURE__ */ React13.createElement("path", {
1144
+ d: "M138,128a10,10,0,1,1-10-10A10,10,0,0,1,138,128Z"
1145
+ }))
1146
+ ],
1147
+ [
1148
+ "regular",
1149
+ /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("path", {
1150
+ d: "M128,24A104,104,0,1,0,232,128,104.11,104.11,0,0,0,128,24Zm0,192a88,88,0,1,1,88-88A88.1,88.1,0,0,1,128,216Z"
1151
+ }), /* @__PURE__ */ React13.createElement("path", {
1152
+ d: "M140,128a12,12,0,1,1-12-12A12,12,0,0,1,140,128Z"
1153
+ }))
1154
+ ],
1155
+ [
1156
+ "thin",
1157
+ /* @__PURE__ */ React13.createElement(React13.Fragment, null, /* @__PURE__ */ React13.createElement("path", {
1158
+ d: "M128,28A100,100,0,1,0,228,128,100.11,100.11,0,0,0,128,28Zm0,192a92,92,0,1,1,92-92A92.1,92.1,0,0,1,128,220Z"
1159
+ }), /* @__PURE__ */ React13.createElement("path", {
1160
+ d: "M136,128a8,8,0,1,1-8-8A8,8,0,0,1,136,128Z"
1161
+ }))
1162
+ ]
1163
+ ]);
1164
+ var Issue = /* @__PURE__ */ forwardRef((props, ref) => /* @__PURE__ */ React13.createElement(IconBase, {
1165
+ ref,
1166
+ ...props,
1167
+ weights
1168
+ }));
1169
+ Issue.displayName = "Issue";
1170
+
1171
+ // packages/plugins/experimental/plugin-github/src/components/MarkdownActions.tsx
1172
+ import { ArrowSquareOut as ArrowSquareOut3, FileArrowDown, FileArrowUp, Link as Link2, LinkBreak } from "@phosphor-icons/react";
1173
+ import React14, { useCallback as useCallback5 } from "react";
1174
+ import { LayoutAction, useIntent as useIntent2 } from "@dxos/app-framework";
1175
+ import { log as log6 } from "@dxos/log";
1176
+ import { getMeta as getMeta3 } from "@dxos/react-client/echo";
1177
+ import { DropdownMenu as DropdownMenu2, useTranslation as useTranslation10 } from "@dxos/react-ui";
1178
+ import { getSize as getSize4 } from "@dxos/react-ui-theme";
1179
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-github/src/components/MarkdownActions.tsx";
1180
+ var MarkdownActions = ({ content, properties }) => {
1181
+ const ghId = getMeta3(properties)?.keys?.find((key) => key.source === "github.com")?.id;
1182
+ const { octokit } = useOctokitContext();
1183
+ const { t } = useTranslation10(GITHUB_PLUGIN);
1184
+ const { dispatch } = useIntent2();
1185
+ const docGhId = useDocGhId(properties.__meta?.keys ?? []);
1186
+ const updateIssueContent = useCallback5(() => {
1187
+ const { owner, repo, issueNumber } = docGhId;
1188
+ return octokit.rest.issues.update({
1189
+ owner,
1190
+ repo,
1191
+ issue_number: issueNumber,
1192
+ body: content
1193
+ });
1194
+ }, [
1195
+ octokit,
1196
+ docGhId,
1197
+ content
1198
+ ]);
1199
+ const exportGhIssueContent = useCallback5(async () => {
1200
+ if (octokit && docGhId && "issueNumber" in docGhId && content) {
1201
+ try {
1202
+ const { data: { html_url: issueUrl } } = await updateIssueContent();
1203
+ await dispatch({
1204
+ action: LayoutAction.SET_LAYOUT,
1205
+ data: {
1206
+ element: "dialog",
1207
+ component: "dxos.org/plugin/github/ExportDialog",
1208
+ subject: {
1209
+ type: "response",
1210
+ target: issueUrl,
1211
+ docGhId,
1212
+ content
1213
+ }
1214
+ }
1215
+ });
1216
+ } catch (err) {
1217
+ log6.error("Failed to export to Github issue", void 0, {
1218
+ F: __dxlog_file5,
1219
+ L: 56,
1220
+ S: void 0,
1221
+ C: (f, a) => f(...a)
1222
+ });
1223
+ }
1224
+ } else {
1225
+ log6.error("Not prepared to export to Github issue when requested.", void 0, {
1226
+ F: __dxlog_file5,
1227
+ L: 59,
1228
+ S: void 0,
1229
+ C: (f, a) => f(...a)
1230
+ });
1231
+ }
1232
+ }, [
1233
+ octokit,
1234
+ docGhId,
1235
+ content
1236
+ ]);
1237
+ const handleGhExport = useCallback5(() => {
1238
+ if ("issueNumber" in docGhId) {
1239
+ void exportGhIssueContent();
1240
+ } else if ("path" in docGhId) {
1241
+ void dispatch({
1242
+ action: LayoutAction.SET_LAYOUT,
1243
+ data: {
1244
+ element: "dialog",
1245
+ component: "dxos.org/plugin/github/ExportDialog",
1246
+ subject: {
1247
+ type: "create-pr",
1248
+ content,
1249
+ docGhId
1250
+ }
1251
+ }
1252
+ });
1253
+ }
1254
+ }, [
1255
+ exportGhIssueContent,
1256
+ docGhId
1257
+ ]);
1258
+ return /* @__PURE__ */ React14.createElement(React14.Fragment, null, /* @__PURE__ */ React14.createElement(DropdownMenu2.GroupLabel, null, t("markdown actions label")), docGhId ? /* @__PURE__ */ React14.createElement(React14.Fragment, null, /* @__PURE__ */ React14.createElement(DropdownMenu2.Item, {
1259
+ classNames: "gap-2",
1260
+ disabled: !docGhId,
1261
+ onClick: () => (
1262
+ // TODO(burdon): Intent should return content value from dialog.
1263
+ dispatch({
1264
+ action: LayoutAction.SET_LAYOUT,
1265
+ data: {
1266
+ element: "dialog",
1267
+ component: "dxos.org/plugin/github/ImportDialog",
1268
+ subject: {
1269
+ docGhId
1270
+ }
1271
+ }
1272
+ })
1273
+ )
1274
+ }, /* @__PURE__ */ React14.createElement(FileArrowDown, {
1275
+ className: getSize4(4)
1276
+ }), /* @__PURE__ */ React14.createElement("span", {
1277
+ className: "grow"
1278
+ }, t("import from github label"))), /* @__PURE__ */ React14.createElement(DropdownMenu2.Item, {
1279
+ classNames: "gap-2",
1280
+ disabled: !docGhId,
1281
+ onClick: () => docGhId && handleGhExport()
1282
+ }, /* @__PURE__ */ React14.createElement(FileArrowUp, {
1283
+ className: getSize4(4)
1284
+ }), /* @__PURE__ */ React14.createElement("span", {
1285
+ className: "grow"
1286
+ }, t("export to github label"))), /* @__PURE__ */ React14.createElement(DropdownMenu2.Item, {
1287
+ asChild: true,
1288
+ classNames: "gap-2",
1289
+ disabled: !ghId
1290
+ }, /* @__PURE__ */ React14.createElement("a", ghId ? {
1291
+ href: `https://github.com/${ghId}`,
1292
+ target: "_blank",
1293
+ rel: "noreferrer"
1294
+ } : {
1295
+ href: "#"
1296
+ }, /* @__PURE__ */ React14.createElement(ArrowSquareOut3, {
1297
+ className: getSize4(4)
1298
+ }), /* @__PURE__ */ React14.createElement("span", {
1299
+ className: "grow"
1300
+ }, t("open in github label")))), /* @__PURE__ */ React14.createElement(DropdownMenu2.Item, {
1301
+ classNames: "gap-2",
1302
+ onClick: () => {
1303
+ const index = getMeta3(properties)?.keys?.findIndex((key) => key.source === "github.com");
1304
+ typeof index !== "undefined" && index >= 0 && properties.__meta?.keys?.splice(index, 1);
1305
+ }
1306
+ }, /* @__PURE__ */ React14.createElement(LinkBreak, {
1307
+ className: getSize4(4)
1308
+ }), /* @__PURE__ */ React14.createElement("span", {
1309
+ className: "grow"
1310
+ }, t("unbind to file in github label")))) : /* @__PURE__ */ React14.createElement(DropdownMenu2.Item, {
1311
+ classNames: "gap-2",
1312
+ onClick: () => dispatch({
1313
+ action: LayoutAction.SET_LAYOUT,
1314
+ data: {
1315
+ element: "dialog",
1316
+ component: "dxos.org/plugin/github/BindDialog",
1317
+ subject: properties
1318
+ }
1319
+ })
1320
+ }, /* @__PURE__ */ React14.createElement(Link2, {
1321
+ className: getSize4(4)
1322
+ }), /* @__PURE__ */ React14.createElement("span", {
1323
+ className: "grow"
1324
+ }, t("bind to file in github label"))));
1325
+ };
1326
+
1327
+ // packages/plugins/experimental/plugin-github/src/components/UrlDialog.tsx
1328
+ import React15, { useState as useState8 } from "react";
1329
+ import { Dialog as Dialog5, Button as Button7, useTranslation as useTranslation11, Input as Input3 } from "@dxos/react-ui";
1330
+ var UrlDialog = ({ properties }) => {
1331
+ const { t } = useTranslation11(GITHUB_PLUGIN);
1332
+ const [ghUrlValue, setGhUrlValue] = useState8("");
1333
+ const ghId = useGhIdFromUrl(ghUrlValue);
1334
+ return /* @__PURE__ */ React15.createElement(React15.Fragment, null, /* @__PURE__ */ React15.createElement(Dialog5.Title, {
1335
+ classNames: "mbe-2"
1336
+ }, t("bind to file in github label")), /* @__PURE__ */ React15.createElement(Input3.Root, {
1337
+ validationValence: "error"
1338
+ }, /* @__PURE__ */ React15.createElement(Input3.Label, null, t("paste url to file in github label")), /* @__PURE__ */ React15.createElement(Input3.TextInput, {
1339
+ placeholder: t("paste url to file in github placeholder"),
1340
+ value: ghUrlValue,
1341
+ onChange: ({ target: { value } }) => setGhUrlValue(value)
1342
+ }), /* @__PURE__ */ React15.createElement(Input3.DescriptionAndValidation, null, ghUrlValue.length > 0 && !ghId && /* @__PURE__ */ React15.createElement(Input3.Validation, null, t("error github markdown path message")), /* @__PURE__ */ React15.createElement(Input3.Description, null, t("paste url to file in github description")))), /* @__PURE__ */ React15.createElement("div", {
1343
+ role: "none",
1344
+ className: "flex justify-end gap-2"
1345
+ }, /* @__PURE__ */ React15.createElement(Dialog5.Close, {
1346
+ asChild: true
1347
+ }, /* @__PURE__ */ React15.createElement(Button7, {
1348
+ classNames: "mbs-2",
1349
+ onClick: () => {
1350
+ if (ghId && document) {
1351
+ properties.__meta.keys.push({
1352
+ source: "github.com",
1353
+ id: ghId
1354
+ });
1355
+ }
1356
+ }
1357
+ }, t("done label", {
1358
+ ns: "os"
1359
+ })))));
1360
+ };
1361
+
1362
+ // packages/plugins/experimental/plugin-github/src/translations.ts
1363
+ var translations_default = [
1364
+ {
1365
+ "en-US": {
1366
+ [GITHUB_PLUGIN]: {
1367
+ "plugin name": "GitHub",
1368
+ "markdown actions label": "GitHub actions",
1369
+ "unbind to file in github label": "Disconnect from\xA0GitHub",
1370
+ "bind to file in github label": "Connect to issue or file in\xA0GitHub",
1371
+ "github pat label": "GitHub personal access\xA0token:",
1372
+ "github pat description": "Composer needs this in order to communicate with GitHub. <docsLink>GitHub\u2019s documentation describes how to create a token.</docsLink> Composer only needs write access to issues, contents, and pull\xA0requests.",
1373
+ "github pat description href": "https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/managing-your-personal-access-tokens",
1374
+ "empty github pat message": "Set a GitHub personal access token to\xA0continue.",
1375
+ "set github pat label": "Set GitHub token",
1376
+ "error github pat message": "There was a problem authenticating with GitHub using the personal access token\xA0provided.",
1377
+ "error github markdown path message": "This is not a valid path to a Markdown file or Issue in\xA0GitHub.",
1378
+ "paste url to file in github label": "Paste the URL to the Issue or Markdown file in\xA0GitHub.",
1379
+ "paste url to file in github description": "Navigate to the issue or file in GitHub, then copy the URL in your browser and paste it\xA0here.",
1380
+ "paste url to file in github placeholder": "https://github.com/owner/repo/blob/main/path/to/README.md",
1381
+ "confirm export title": "Export to GitHub",
1382
+ "export to github success message": "<resultStyle>Success!</resultStyle> Your changes are now live here: <prLink>{{linkText}}</prLink>",
1383
+ "github branch name label": "Name of the branch to\xA0create",
1384
+ "github branch name placeholder": "update-readme",
1385
+ "github commit message label": "Commit message",
1386
+ "github commit message placeholder": "Updated README.md",
1387
+ "save and close description": "Save changes to GitHub and close the\xA0editor",
1388
+ "close embed description": "Close the editor without saving changes to GitHub. Your changes will still persist in\xA0Composer.",
1389
+ "resolver init document message": "Syncing this document, one\xA0moment\u2026",
1390
+ "comment stale title": "No longer in-sync",
1391
+ "comment stale body": "The document in GitHub was updated in another session. To re-sync, please save your changes, reload the page, and choose to edit from GitHub\xA0again.",
1392
+ "open in github label": "Open in GitHub",
1393
+ "stale rescue title": "Set a personal access\xA0token",
1394
+ "stale rescue description": "Another user has recently updated this issue, so GitHub won\u2019t accept your changes unless you set a personal access token (a PAT) here, or refresh the\xA0page.",
1395
+ "embedded options label": "Options",
1396
+ "unset repo space label": "Select a different space for this\xA0repository",
1397
+ "loading preview message": "Loading preview\u2026",
1398
+ "preview gfm label": "Preview Markdown",
1399
+ "exit gfm preview label": "Exit preview",
1400
+ "save and close label": "Save & close",
1401
+ "export to github label": "Export to GitHub",
1402
+ "import from github label": "Import from GitHub",
1403
+ "resolver tree label": "Choose a Space",
1404
+ "resolver tree description": "To collaborate on documents in this repository, choose the Space that will store and control access to the documents.",
1405
+ "resolver no spaces message": "You aren\u2019t in any spaces yet",
1406
+ "resolver create space label": "Create a space for this repository",
1407
+ "bound members message_one": "One member uses this space for this repository",
1408
+ "bound members message_other": "{{count}} members use this space for this repository",
1409
+ "select label": "Select",
1410
+ "selected label": "Selected",
1411
+ "open in composer label": "Open in Composer",
1412
+ "confirm import title": "Overwrite this document\u2019s content?",
1413
+ "confirm import body": "Importing will overwrite this document\u2019s content. If you\u2019d rather import into a new document, first create a new document and then import into it.",
1414
+ "target blank description": "Link opens in a new tab."
1415
+ }
1416
+ }
1417
+ }
1418
+ ];
1419
+
1420
+ // packages/plugins/experimental/plugin-github/src/GithubPlugin.tsx
1421
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/plugins/experimental/plugin-github/src/GithubPlugin.tsx";
1422
+ var GithubPlugin = () => {
1423
+ const settings = new LocalStorageStore(GITHUB_PLUGIN);
1424
+ return {
1425
+ meta: meta_default,
1426
+ ready: async () => {
1427
+ settings.prop({
1428
+ key: "pat",
1429
+ type: LocalStorageStore.string({
1430
+ allowUndefined: true
1431
+ })
1432
+ });
1433
+ },
1434
+ unload: async () => {
1435
+ settings.close();
1436
+ },
1437
+ provides: {
1438
+ settings: settings.values,
1439
+ translations: translations_default,
1440
+ graph: {
1441
+ builder: (plugins) => {
1442
+ const client = resolvePlugin(plugins, parseClientPlugin)?.provides.client;
1443
+ if (!client) {
1444
+ return [];
1445
+ }
1446
+ return createExtension({
1447
+ id: GITHUB_PLUGIN,
1448
+ filter: (node) => isSpace(node.data),
1449
+ connector: ({ node }) => {
1450
+ const documents = memoizeQuery(node.data, Filter2.schema(DocumentType3, (doc) => getMeta4(doc)?.keys?.find((key) => key?.source?.includes("github"))));
1451
+ if (documents.length > 0) {
1452
+ return [
1453
+ {
1454
+ id: `${GITHUB_PLUGIN_SHORT_ID}:${node.id}`,
1455
+ data: GITHUB_PLUGIN_SHORT_ID,
1456
+ type: GITHUB_PLUGIN,
1457
+ properties: {
1458
+ label: [
1459
+ "plugin name",
1460
+ {
1461
+ ns: GITHUB_PLUGIN
1462
+ }
1463
+ ],
1464
+ icon: (props) => /* @__PURE__ */ React16.createElement(GithubLogo, props),
1465
+ iconSymbol: "ph--github-logo--regular"
1466
+ }
1467
+ }
1468
+ ];
1469
+ }
1470
+ }
1471
+ });
1472
+ }
1473
+ },
1474
+ context: (props) => /* @__PURE__ */ React16.createElement(OctokitProvider, {
1475
+ pat: settings.values.pat,
1476
+ onPatChanged: (pat) => settings.values.pat = pat,
1477
+ ...props
1478
+ }),
1479
+ surface: {
1480
+ component: ({ data, role }) => {
1481
+ switch (data.component) {
1482
+ case `${GITHUB_PLUGIN}/embedded`:
1483
+ return /* @__PURE__ */ React16.createElement(EmbeddedMain, null);
1484
+ }
1485
+ switch (role) {
1486
+ case "dialog":
1487
+ switch (data.content) {
1488
+ case "dxos.org/plugin/github/BindDialog":
1489
+ return isMarkdownProperties(data.properties) ? /* @__PURE__ */ React16.createElement(UrlDialog, {
1490
+ properties: data.properties
1491
+ }) : null;
1492
+ case "dxos.org/plugin/github/ExportDialog":
1493
+ return null;
1494
+ case "dxos.org/plugin/github/ImportDialog":
1495
+ return /* @__PURE__ */ React16.createElement(ImportDialog, {
1496
+ docGhId: data.docGhId,
1497
+ onUpdate: (content) => {
1498
+ log7.info("onUpdate", content, {
1499
+ F: __dxlog_file6,
1500
+ L: 107,
1501
+ S: void 0,
1502
+ C: (f, a) => f(...a)
1503
+ });
1504
+ }
1505
+ });
1506
+ default:
1507
+ return null;
1508
+ }
1509
+ case "menuitem":
1510
+ return typeof data.content === "string" && isMarkdownProperties(data.properties) && !data.properties.readonly ? /* @__PURE__ */ React16.createElement(MarkdownActions, {
1511
+ content: data.content,
1512
+ properties: data.properties
1513
+ }) : null;
1514
+ case "settings":
1515
+ return data.plugin === meta_default.id ? /* @__PURE__ */ React16.createElement(GitHubSettings, null) : null;
1516
+ default:
1517
+ return null;
1518
+ }
1519
+ }
1520
+ }
1521
+ }
1522
+ };
1523
+ };
1524
+
1525
+ // packages/plugins/experimental/plugin-github/src/index.ts
1526
+ var src_default = GithubPlugin;
1527
+ export {
1528
+ GithubPlugin,
1529
+ src_default as default
1530
+ };
1531
+ //# sourceMappingURL=index.mjs.map