@acryldev/blends-frame 0.2.0 → 0.2.2

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,250 @@ body[data-bf-settings-full] { --bf-pane-h: calc(100vh - 24px); }
48631
48655
  ]
48632
48656
  });
48633
48657
  }
48658
+ const KEY = "acrylBlends.recoveredAt";
48659
+ const KNOWN = /rendered without an installed adapter/u;
48660
+ /** Whether an error is the known one a reload cures. */
48661
+ function isRecoverable(error) {
48662
+ const text = error instanceof Error ? `${error.name} ${error.message}` : String(error);
48663
+ return KNOWN.test(text);
48664
+ }
48665
+ /** Install the recovery; returns its disposer. */
48666
+ function installRecovery(target, now = Date.now) {
48667
+ const listener = (event) => {
48668
+ if (!isRecoverable(event.error ?? event.reason ?? event.message)) return;
48669
+ let last = 0;
48670
+ try {
48671
+ last = Number(target.sessionStorage.getItem(KEY) ?? 0);
48672
+ } catch {}
48673
+ if (now() - last < 15e3) return;
48674
+ try {
48675
+ target.sessionStorage.setItem(KEY, String(now()));
48676
+ } catch {}
48677
+ target.location.reload();
48678
+ };
48679
+ target.addEventListener("error", listener);
48680
+ target.addEventListener("unhandledrejection", listener);
48681
+ return () => {
48682
+ target.removeEventListener("error", listener);
48683
+ target.removeEventListener("unhandledrejection", listener);
48684
+ };
48685
+ }
48686
+ // src/client/ShareAppSection.tsx
48687
+ /**
48688
+ * 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
48689
+ * comes first (which repository, who can see it, what is saved first) and nothing leaves the computer until the person says yes. GitHub is
48690
+ * 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.
48691
+ */
48692
+ function createShareAppApi(fetcher = (input, init) => fetch(input, init)) {
48693
+ const post = async (path, body) => {
48694
+ const response = await fetcher(path, {
48695
+ method: "POST",
48696
+ credentials: "same-origin",
48697
+ headers: {
48698
+ "Content-Type": "application/json",
48699
+ Accept: "application/json"
48700
+ },
48701
+ body: JSON.stringify(body)
48702
+ });
48703
+ if (!response.ok) throw await failureOf(response);
48704
+ return response.json();
48705
+ };
48706
+ return {
48707
+ plan: async (request) => parseAppSharePlan(await post(FRAME_APP_SHARE_PLAN_PATH, request)),
48708
+ share: async (request, confirm) => parseAppShared(await post(FRAME_APP_SHARE_PATH, {
48709
+ ...request,
48710
+ confirm
48711
+ }))
48712
+ };
48713
+ }
48714
+ async function copyText(text) {
48715
+ try {
48716
+ await navigator.clipboard.writeText(text);
48717
+ return true;
48718
+ } catch {
48719
+ return false;
48720
+ }
48721
+ }
48722
+ /** `github.com/ana/shop` from a remote address, for reading. */
48723
+ const readable = (remote) => remote.replace(/^git\+/u, "").replace(/^https?:\/\//u, "").replace(/\.git$/u, "");
48724
+ function ShareAppSection({ share, registry }) {
48725
+ const [github, setGithub] = (0, react.useState)({ status: "checking" });
48726
+ const [owner, setOwner] = (0, react.useState)("");
48727
+ const [visibility, setVisibility] = (0, react.useState)("private");
48728
+ const [step, setStep] = (0, react.useState)({ kind: "ask" });
48729
+ const [failure, setFailure] = (0, react.useState)(void 0);
48730
+ const readGithub = (0, react.useCallback)(() => {
48731
+ registry.github().then(setGithub, () => {
48732
+ setGithub({ status: "checking" });
48733
+ });
48734
+ }, [registry]);
48735
+ (0, react.useEffect)(() => {
48736
+ readGithub();
48737
+ }, [readGithub]);
48738
+ const request = {
48739
+ ...owner.trim() === "" ? {} : { owner: owner.trim() },
48740
+ visibility
48741
+ };
48742
+ const fail = (cause) => {
48743
+ setFailure(cause instanceof PlainFailure || cause instanceof Error ? cause.message : String(cause));
48744
+ };
48745
+ const review = (event) => {
48746
+ event.preventDefault();
48747
+ setFailure(void 0);
48748
+ setStep({ kind: "busy" });
48749
+ share.plan(request).then((plan) => {
48750
+ setStep({
48751
+ kind: "plan",
48752
+ plan
48753
+ });
48754
+ }, (cause) => {
48755
+ setStep({ kind: "ask" });
48756
+ fail(cause);
48757
+ });
48758
+ };
48759
+ const send = (plan) => {
48760
+ setFailure(void 0);
48761
+ setStep({
48762
+ kind: "sending",
48763
+ plan
48764
+ });
48765
+ share.share(request, plan).then((shared) => {
48766
+ setStep({
48767
+ kind: "shared",
48768
+ shared
48769
+ });
48770
+ }, (cause) => {
48771
+ setStep({
48772
+ kind: "plan",
48773
+ plan
48774
+ });
48775
+ fail(cause);
48776
+ });
48777
+ };
48778
+ const ready = github.status === "ready";
48779
+ return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48780
+ className: "acrylBlendsApp",
48781
+ children: [
48782
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: "Share" }),
48783
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
48784
+ className: "acrylBlendsPluginsSub",
48785
+ children: "Send this app, as it is now, to a GitHub repository of your own. Nothing is sent until you say yes."
48786
+ }),
48787
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)(GithubNote, {
48788
+ github,
48789
+ copy: copyText,
48790
+ connect: registry.connect,
48791
+ onConnected: readGithub
48792
+ }),
48793
+ failure !== void 0 && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("p", {
48794
+ className: "acrylBlendsNote",
48795
+ "data-error": true,
48796
+ role: "alert",
48797
+ children: failure
48798
+ }),
48799
+ step.kind === "shared" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48800
+ className: "acrylBlendsAppRow",
48801
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Shared" }), /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("small", {
48802
+ role: "status",
48803
+ children: [
48804
+ "Sent to ",
48805
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", {
48806
+ className: "acrylBlendsMeta",
48807
+ children: readable(step.shared.remote)
48808
+ }),
48809
+ step.shared.created ? " (a new repository)" : "",
48810
+ ". Every later version is saved there too. Someone you give access makes their own copy with",
48811
+ " ",
48812
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("code", { children: `git clone ${step.shared.remote.replace(/^git\+/u, "")}` })
48813
+ ]
48814
+ })]
48815
+ }) : step.kind === "plan" || step.kind === "sending" ? /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [
48816
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48817
+ className: "acrylBlendsAppRow",
48818
+ 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)" : ""] })]
48819
+ }),
48820
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48821
+ className: "acrylBlendsAppRow",
48822
+ 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" })]
48823
+ }),
48824
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48825
+ className: "acrylBlendsAppRow",
48826
+ 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` })]
48827
+ }),
48828
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", {
48829
+ className: "acrylBlendsAppRow",
48830
+ children: [
48831
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Send it?" }),
48832
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
48833
+ className: "acrylBlendsAppControls",
48834
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48835
+ type: "button",
48836
+ className: "acrylBlendsAppButton",
48837
+ disabled: step.kind === "sending",
48838
+ onClick: () => {
48839
+ send(step.plan);
48840
+ },
48841
+ children: step.kind === "sending" ? "Sending…" : "Yes, share this app"
48842
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48843
+ type: "button",
48844
+ className: "acrylBlendsAppButton",
48845
+ disabled: step.kind === "sending",
48846
+ onClick: () => {
48847
+ setStep({ kind: "ask" });
48848
+ },
48849
+ children: "Not yet"
48850
+ })]
48851
+ }),
48852
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: "Nothing has been sent. It is sent only when you say yes." })
48853
+ ]
48854
+ })
48855
+ ] }) : /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("form", {
48856
+ className: "acrylBlendsAppRow",
48857
+ "data-wide": "",
48858
+ onSubmit: review,
48859
+ children: [
48860
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("b", { children: "Share to GitHub" }),
48861
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("span", {
48862
+ className: "acrylBlendsAppControls",
48863
+ children: [
48864
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", {
48865
+ className: "acrylBlendsSearch",
48866
+ "aria-label": "GitHub account",
48867
+ placeholder: "GitHub account (blank: yours)",
48868
+ value: owner,
48869
+ onChange: (event) => {
48870
+ setOwner(event.target.value);
48871
+ }
48872
+ }),
48873
+ /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("select", {
48874
+ className: "acrylBlendsSearch",
48875
+ "aria-label": "Who can see it",
48876
+ value: visibility,
48877
+ onChange: (event) => {
48878
+ setVisibility(event.target.value === "public" ? "public" : "private");
48879
+ },
48880
+ children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
48881
+ value: "private",
48882
+ children: "Private: only you and people you invite"
48883
+ }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("option", {
48884
+ value: "public",
48885
+ children: "Public: anyone, listed as Community"
48886
+ })]
48887
+ }),
48888
+ /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
48889
+ type: "submit",
48890
+ className: "acrylBlendsAppButton",
48891
+ disabled: !ready || step.kind === "busy",
48892
+ children: step.kind === "busy" ? "Reading…" : "Review what would be sent"
48893
+ })
48894
+ ]
48895
+ }),
48896
+ /* @__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)." })
48897
+ ]
48898
+ })
48899
+ ]
48900
+ });
48901
+ }
48634
48902
  // src/client/NameYourApp.tsx
48635
48903
  /**
48636
48904
  * 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
@@ -49331,6 +49599,7 @@ button.acrylBlendsFrow:hover { background: var(--bf-surface-2); }
49331
49599
  .acrylBlendsAppRow small { grid-column: 1 / -1; color: var(--bf-dim); font-size: 11.5px; }
49332
49600
  .acrylBlendsAppControls { grid-row: 1; grid-column: 2; display: inline-flex; align-items: center; gap: 8px; }
49333
49601
  .acrylBlendsAppRow .acrylBlendsAppName { width: 220px; }
49602
+ .acrylBlendsAppRow[data-wide] .acrylBlendsAppControls { grid-row: 2; grid-column: 1 / -1; flex-wrap: wrap; }
49334
49603
  .acrylBlendsAppButton { padding: 4px 10px; border: 1px solid #34343a; border-radius: 6px; background: var(--bf-surface-2); color: #e8e8ea; font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap; }
49335
49604
  .acrylBlendsAppButton:hover:not(:disabled) { border-color: #4a4a52; color: #fff; }
49336
49605
  .acrylBlendsAppButton:disabled { opacity: .5; cursor: default; }
@@ -49923,6 +50192,7 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
49923
50192
  }
49924
50193
  }
49925
50194
  function apply(ctx) {
50195
+ ctx.effect(() => installRecovery(window), "@acryldev/blends-frame: recover a blank page");
49926
50196
  const layout = new _acryldev_app_shell_client.DesktopLayoutState();
49927
50197
  const canvas = new AppCanvasState();
49928
50198
  const selection = new SelectionStore();
@@ -50242,11 +50512,13 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
50242
50512
  child.effect(() => child.locale.register(LOCALE_NAMESPACE, {
50243
50513
  en: {
50244
50514
  plugins: "Plugins",
50245
- app: "App"
50515
+ app: "App",
50516
+ share: "Share"
50246
50517
  },
50247
50518
  zh: {
50248
50519
  plugins: "插件",
50249
- app: "应用"
50520
+ app: "应用",
50521
+ share: "分享"
50250
50522
  }
50251
50523
  }), "@acryldev/blends-frame: dictionary");
50252
50524
  const t = child.locale.bind(LOCALE_NAMESPACE);
@@ -50258,6 +50530,18 @@ body[data-bf-settings-full] [data-shortcut-modal="settings"] { width: calc(100vw
50258
50530
  locale: LOCALE_NAMESPACE,
50259
50531
  inject: () => ({ app: desktop })
50260
50532
  }, AppSection));
50533
+ const shareApp = createShareAppApi();
50534
+ child.slots.inject("settings.section", () => child.slots.register({
50535
+ name: "settings.section",
50536
+ id: "acryl-blends-share",
50537
+ order: 6,
50538
+ label: () => t("share"),
50539
+ locale: LOCALE_NAMESPACE,
50540
+ inject: () => ({
50541
+ share: shareApp,
50542
+ registry
50543
+ })
50544
+ }, ShareAppSection));
50261
50545
  child.slots.inject("settings.section", () => child.slots.register({
50262
50546
  name: "settings.section",
50263
50547
  id: "acryl-blends-plugins",