@acryldev/blends-frame 0.2.0 → 0.2.1

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.
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Share the whole app to GitHub from Settings > Share, through the app's own share command (`plugins/save/share-cli.ts`, the save plugin): the
3
+ * same command `npm run share` and ACRYL Control Center's Share run, so the rules (a plan first, sent only on the person's yes, refused on a
4
+ * secret, visibility kept in blend.yaml) live in one place. The command runs on the Node.js this host runs on (inside a desktop product that is
5
+ * Electron's, as Node).
6
+ */
7
+ import { type AppSharePlanView, type AppShareRequest, type AppSharedView } from './contract.ts';
8
+ export declare const SHARE_COMMAND: string;
9
+ /** A share the app refused, in its own words (not signed in, a secret in a file, the app changed since the plan). */
10
+ export declare class AppShareRefused extends Error {
11
+ }
12
+ export interface AppSharePort {
13
+ plan(request: AppShareRequest): Promise<AppSharePlanView>;
14
+ share(request: AppShareRequest, confirmed: AppSharePlanView): Promise<AppSharedView>;
15
+ }
16
+ type Run = (args: readonly string[]) => Promise<{
17
+ readonly code: number | null;
18
+ readonly stdout: string;
19
+ readonly stderr: string;
20
+ }>;
21
+ export declare function appShareCommand(root: string, env?: NodeJS.ProcessEnv, run?: Run): AppSharePort;
22
+ export {};
package/lib/client.js CHANGED
@@ -168,6 +168,30 @@ window.__ModuleLoader__.load({
168
168
  const FRAME_PLUGINS_PATH = `${FRAME_API_PREFIX}/plugins`;
169
169
  const FRAME_PLUGINS_SWITCH_PATH = `${FRAME_API_PREFIX}/plugins/switch`;
170
170
  /** POST `{ name }`: what sharing this local plugin would do (a {@link SharePlan}); nothing leaves the machine. */
171
+ /** POST `{ owner?, visibility? }`: what sharing the whole app to GitHub would send (Settings > Share); sends nothing. */
172
+ const FRAME_APP_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/app/share-plan`;
173
+ /** POST `{ owner?, visibility?, confirm }`: share the app exactly as the confirmed plan says, or nothing. */
174
+ const FRAME_APP_SHARE_PATH = `${FRAME_API_PREFIX}/app/share`;
175
+ function parseAppSharePlan(value) {
176
+ if (!isRecord$5(value)) throw new Error("app share plan: not a plan");
177
+ const { repository, create, visibility, changes } = value;
178
+ if (typeof repository !== "string" || repository === "" || typeof create !== "boolean") throw new Error("app share plan: repository");
179
+ if (visibility !== "private" && visibility !== "public") throw new Error("app share plan: visibility");
180
+ if (typeof changes !== "number" || !Number.isSafeInteger(changes) || changes < 0) throw new Error("app share plan: changes");
181
+ return {
182
+ repository,
183
+ create,
184
+ visibility,
185
+ changes
186
+ };
187
+ }
188
+ function parseAppShared(value) {
189
+ if (!isRecord$5(value) || typeof value.remote !== "string" || typeof value.created !== "boolean") throw new Error("app share: where it went");
190
+ return {
191
+ remote: value.remote,
192
+ created: value.created
193
+ };
194
+ }
171
195
  const FRAME_PLUGINS_SHARE_PLAN_PATH = `${FRAME_API_PREFIX}/plugins/share-plan`;
172
196
  /** POST `{ name, confirm }`: publish it, only when `confirm` is the plan the person said yes to and it still holds. */
173
197
  const FRAME_PLUGINS_SHARE_PATH = `${FRAME_API_PREFIX}/plugins/share`;
@@ -47879,7 +47903,7 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
47879
47903
  // src/client/PluginsSection.tsx
47880
47904
  /** The Plugins page of Settings: search, the groups as chips, and one row per plugin with who made it, its state and its switch. */
47881
47905
  /** Copy a text to the clipboard; false when the browser refuses (a copy the person can still make by hand from the shown text). */
47882
- async function copyText(text) {
47906
+ async function copyText$1(text) {
47883
47907
  try {
47884
47908
  await navigator.clipboard.writeText(text);
47885
47909
  return true;
@@ -47959,7 +47983,7 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
47959
47983
  const copy = async (plugin, text, what) => {
47960
47984
  setSaid({
47961
47985
  key: plugin.key,
47962
- text: await copyText(text) ? `Copied ${what}.` : `Your browser did not allow copying; select it here: ${text}`
47986
+ text: await copyText$1(text) ? `Copied ${what}.` : `Your browser did not allow copying; select it here: ${text}`
47963
47987
  });
47964
47988
  };
47965
47989
  const viewSource = (plugin) => {
@@ -48193,7 +48217,7 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48193
48217
  plugin,
48194
48218
  readGithub: registry.github,
48195
48219
  connectGithub: registry.connect,
48196
- copy: copyText,
48220
+ copy: copyText$1,
48197
48221
  onSaved: (saved) => {
48198
48222
  mark(plugin.key, { saved: {
48199
48223
  version: saved.version,
@@ -48631,6 +48655,221 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48631
48655
  ]
48632
48656
  });
48633
48657
  }
48658
+ // src/client/ShareAppSection.tsx
48659
+ /**
48660
+ * Settings > Share, in every app (window or browser tab): send the whole app, as it is now, to a GitHub repository of the person's own. The plan
48661
+ * comes first (which repository, who can see it, what is saved first) and nothing leaves the computer until the person says yes. GitHub is
48662
+ * connected here the way the Plugins page connects it. Laid out as the App page is: a title, one line under it, one bordered row per thing.
48663
+ */
48664
+ function createShareAppApi(fetcher = (input, init) => fetch(input, init)) {
48665
+ const post = async (path, body) => {
48666
+ const response = await fetcher(path, {
48667
+ method: "POST",
48668
+ credentials: "same-origin",
48669
+ headers: {
48670
+ "Content-Type": "application/json",
48671
+ Accept: "application/json"
48672
+ },
48673
+ body: JSON.stringify(body)
48674
+ });
48675
+ if (!response.ok) throw await failureOf(response);
48676
+ return response.json();
48677
+ };
48678
+ return {
48679
+ plan: async (request) => parseAppSharePlan(await post(FRAME_APP_SHARE_PLAN_PATH, request)),
48680
+ share: async (request, confirm) => parseAppShared(await post(FRAME_APP_SHARE_PATH, {
48681
+ ...request,
48682
+ confirm
48683
+ }))
48684
+ };
48685
+ }
48686
+ async function copyText(text) {
48687
+ try {
48688
+ await navigator.clipboard.writeText(text);
48689
+ return true;
48690
+ } catch {
48691
+ return false;
48692
+ }
48693
+ }
48694
+ /** `github.com/ana/shop` from a remote address, for reading. */
48695
+ const readable = (remote) => remote.replace(/^git\+/u, "").replace(/^https?:\/\//u, "").replace(/\.git$/u, "");
48696
+ function ShareAppSection({ share, registry }) {
48697
+ const [github, setGithub] = (0, react.useState)({ status: "checking" });
48698
+ const [owner, setOwner] = (0, react.useState)("");
48699
+ const [visibility, setVisibility] = (0, react.useState)("private");
48700
+ const [step, setStep] = (0, react.useState)({ kind: "ask" });
48701
+ const [failure, setFailure] = (0, react.useState)(void 0);
48702
+ const readGithub = (0, react.useCallback)(() => {
48703
+ registry.github().then(setGithub, () => {
48704
+ setGithub({ status: "checking" });
48705
+ });
48706
+ }, [registry]);
48707
+ (0, react.useEffect)(() => {
48708
+ readGithub();
48709
+ }, [readGithub]);
48710
+ const request = {
48711
+ ...owner.trim() === "" ? {} : { owner: owner.trim() },
48712
+ visibility
48713
+ };
48714
+ const fail = (cause) => {
48715
+ setFailure(cause instanceof PlainFailure || cause instanceof Error ? cause.message : String(cause));
48716
+ };
48717
+ const review = (event) => {
48718
+ event.preventDefault();
48719
+ setFailure(void 0);
48720
+ setStep({ kind: "busy" });
48721
+ share.plan(request).then((plan) => {
48722
+ setStep({
48723
+ kind: "plan",
48724
+ plan
48725
+ });
48726
+ }, (cause) => {
48727
+ setStep({ kind: "ask" });
48728
+ fail(cause);
48729
+ });
48730
+ };
48731
+ const send = (plan) => {
48732
+ setFailure(void 0);
48733
+ setStep({
48734
+ kind: "sending",
48735
+ plan
48736
+ });
48737
+ share.share(request, plan).then((shared) => {
48738
+ setStep({
48739
+ kind: "shared",
48740
+ shared
48741
+ });
48742
+ }, (cause) => {
48743
+ setStep({
48744
+ kind: "plan",
48745
+ plan
48746
+ });
48747
+ fail(cause);
48748
+ });
48749
+ };
48750
+ const ready = github.status === "ready";
48751
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48752
+ className: "acrylBlendsApp",
48753
+ children: [
48754
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "Share" }),
48755
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
48756
+ className: "acrylBlendsPluginsSub",
48757
+ children: "Send this app, as it is now, to a GitHub repository of your own. Nothing is sent until you say yes."
48758
+ }),
48759
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GithubNote, {
48760
+ github,
48761
+ copy: copyText,
48762
+ connect: registry.connect,
48763
+ onConnected: readGithub
48764
+ }),
48765
+ failure !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
48766
+ className: "acrylBlendsNote",
48767
+ "data-error": true,
48768
+ role: "alert",
48769
+ children: failure
48770
+ }),
48771
+ step.kind === "shared" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48772
+ className: "acrylBlendsAppRow",
48773
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Shared" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", {
48774
+ role: "status",
48775
+ children: [
48776
+ "Sent to ",
48777
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
48778
+ className: "acrylBlendsMeta",
48779
+ children: readable(step.shared.remote)
48780
+ }),
48781
+ step.shared.created ? " (a new repository)" : "",
48782
+ ". Every later version is saved there too. Someone you give access makes their own copy with",
48783
+ " ",
48784
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: `git clone ${step.shared.remote.replace(/^git\+/u, "")}` })
48785
+ ]
48786
+ })]
48787
+ }) : step.kind === "plan" || step.kind === "sending" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
48788
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48789
+ className: "acrylBlendsAppRow",
48790
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Repository" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", { children: [readable(step.plan.create ? `github.com/${step.plan.repository}` : step.plan.repository), step.plan.create ? " (a new repository)" : ""] })]
48791
+ }),
48792
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48793
+ className: "acrylBlendsAppRow",
48794
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Who can see it" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: step.plan.visibility === "private" ? "Only you and people you invite (private)" : "Anyone (public); listed in the Blends registry as Community" })]
48795
+ }),
48796
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48797
+ className: "acrylBlendsAppRow",
48798
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "What is sent" }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: step.plan.changes === 0 ? "The versions saved so far" : `${String(step.plan.changes)} changed ${step.plan.changes === 1 ? "file is" : "files are"} saved first, then every saved version` })]
48799
+ }),
48800
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48801
+ className: "acrylBlendsAppRow",
48802
+ children: [
48803
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Send it?" }),
48804
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
48805
+ className: "acrylBlendsAppControls",
48806
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48807
+ type: "button",
48808
+ className: "acrylBlendsAppButton",
48809
+ disabled: step.kind === "sending",
48810
+ onClick: () => {
48811
+ send(step.plan);
48812
+ },
48813
+ children: step.kind === "sending" ? "Sending…" : "Yes, share this app"
48814
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48815
+ type: "button",
48816
+ className: "acrylBlendsAppButton",
48817
+ disabled: step.kind === "sending",
48818
+ onClick: () => {
48819
+ setStep({ kind: "ask" });
48820
+ },
48821
+ children: "Not yet"
48822
+ })]
48823
+ }),
48824
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "Nothing has been sent. It is sent only when you say yes." })
48825
+ ]
48826
+ })
48827
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
48828
+ className: "acrylBlendsAppRow",
48829
+ onSubmit: review,
48830
+ children: [
48831
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Share to GitHub" }),
48832
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
48833
+ className: "acrylBlendsAppControls",
48834
+ children: [
48835
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
48836
+ className: "acrylBlendsSearch",
48837
+ "aria-label": "GitHub account",
48838
+ placeholder: "GitHub account (blank: yours)",
48839
+ value: owner,
48840
+ onChange: (event) => {
48841
+ setOwner(event.target.value);
48842
+ }
48843
+ }),
48844
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
48845
+ className: "acrylBlendsSearch",
48846
+ "aria-label": "Who can see it",
48847
+ value: visibility,
48848
+ onChange: (event) => {
48849
+ setVisibility(event.target.value === "public" ? "public" : "private");
48850
+ },
48851
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
48852
+ value: "private",
48853
+ children: "Private: only you and people you invite"
48854
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
48855
+ value: "public",
48856
+ children: "Public: anyone, listed as Community"
48857
+ })]
48858
+ }),
48859
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48860
+ type: "submit",
48861
+ className: "acrylBlendsAppButton",
48862
+ disabled: !ready || step.kind === "busy",
48863
+ children: step.kind === "busy" ? "Reading…" : "Review what would be sent"
48864
+ })
48865
+ ]
48866
+ }),
48867
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: ready ? "The plan comes first: which repository, who can see it, and what is saved first." : "Connect GitHub first (above)." })
48868
+ ]
48869
+ })
48870
+ ]
48871
+ });
48872
+ }
48634
48873
  // src/client/NameYourApp.tsx
48635
48874
  /**
48636
48875
  * The first start of a desktop product asks one thing, in the app's own window: "Name your app" (app-storage.md, "What the person sees"). The product's
@@ -50242,11 +50481,13 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
50242
50481
  child.effect(() => child.locale.register(LOCALE_NAMESPACE, {
50243
50482
  en: {
50244
50483
  plugins: "Plugins",
50245
- app: "App"
50484
+ app: "App",
50485
+ share: "Share"
50246
50486
  },
50247
50487
  zh: {
50248
50488
  plugins: "插件",
50249
- app: "应用"
50489
+ app: "应用",
50490
+ share: "分享"
50250
50491
  }
50251
50492
  }), "@acryldev/blends-frame: dictionary");
50252
50493
  const t = child.locale.bind(LOCALE_NAMESPACE);
@@ -50258,6 +50499,18 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
50258
50499
  locale: LOCALE_NAMESPACE,
50259
50500
  inject: () => ({ app: desktop })
50260
50501
  }, AppSection));
50502
+ const shareApp = createShareAppApi();
50503
+ child.slots.inject("settings.section", () => child.slots.register({
50504
+ name: "settings.section",
50505
+ id: "acryl-blends-share",
50506
+ order: 6,
50507
+ label: () => t("share"),
50508
+ locale: LOCALE_NAMESPACE,
50509
+ inject: () => ({
50510
+ share: shareApp,
50511
+ registry
50512
+ })
50513
+ }, ShareAppSection));
50261
50514
  child.slots.inject("settings.section", () => child.slots.register({
50262
50515
  name: "settings.section",
50263
50516
  id: "acryl-blends-plugins",