@inkandswitch/patchwork 0.2.1 → 0.3.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.
- package/CHANGELOG.md +19 -0
- package/dist/createAccount.d.ts +2 -0
- package/dist/createAccount.js +18 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.js +3 -3
- package/dist/types.d.ts +2 -1
- package/dist/vite/importmap-plugin.js +8 -2
- package/package.json +4 -4
- package/src/createAccount.ts +31 -0
- package/src/index.ts +3 -4
- package/src/types.ts +6 -6
- package/src/vite/importmap-plugin.ts +8 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,24 @@
|
|
|
1
1
|
# @inkandswitch/patchwork
|
|
2
2
|
|
|
3
|
+
## 0.3.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 896fa22: Resolve built-in import-map packages through Vite during development so the site and dynamically loaded tools share module singletons.
|
|
8
|
+
|
|
9
|
+
## 0.3.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- 9e6e0e0: Add a `createAccount` setup option, create required account subdocuments before exposing a fresh account, and stop exposing the account handle as `window.accountDocHandle`.
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [9e6e0e0]
|
|
18
|
+
- @inkandswitch/patchwork-plugins@1.1.0
|
|
19
|
+
- @inkandswitch/patchwork-elements@5.0.0
|
|
20
|
+
- @inkandswitch/patchwork-bootloader@0.5.3
|
|
21
|
+
|
|
3
22
|
## 0.2.1
|
|
4
23
|
|
|
5
24
|
### Patch Changes
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createDocOfDatatype2, getRegistry, } from "@inkandswitch/patchwork-plugins";
|
|
2
|
+
export const createDefaultAccount = async (accountHandle, repo) => {
|
|
3
|
+
const fields = [
|
|
4
|
+
["rootFolderUrl", "folder"],
|
|
5
|
+
["moduleSettingsUrl", "patchwork:module-settings"],
|
|
6
|
+
["contactUrl", "contact"],
|
|
7
|
+
];
|
|
8
|
+
const registry = getRegistry("patchwork:datatype");
|
|
9
|
+
const subdocs = await Promise.all(fields.map(async ([field, datatypeId]) => {
|
|
10
|
+
const datatype = await registry.loadWhenReady(datatypeId);
|
|
11
|
+
const handle = await createDocOfDatatype2(datatype, repo);
|
|
12
|
+
return [field, handle.url];
|
|
13
|
+
}));
|
|
14
|
+
accountHandle.change((doc) => {
|
|
15
|
+
for (const [field, url] of subdocs)
|
|
16
|
+
doc[field] = url;
|
|
17
|
+
});
|
|
18
|
+
};
|
package/dist/index.d.ts
CHANGED
|
@@ -17,14 +17,12 @@
|
|
|
17
17
|
* `@inkandswitch/patchwork-bootloader` directly, which does SW registration
|
|
18
18
|
* and the automerge-worker handoff and nothing else.
|
|
19
19
|
*/
|
|
20
|
-
import {
|
|
20
|
+
import { Repo } from "@automerge/vanillajs/slim";
|
|
21
21
|
import type { AutomergeRepoKeyhive } from "@automerge/automerge-repo-keyhive";
|
|
22
|
-
import { type AccountDoc } from "@inkandswitch/patchwork-plugins";
|
|
23
22
|
import type { Patchwork, PatchworkOptions } from "./types.js";
|
|
24
23
|
declare global {
|
|
25
24
|
interface Window {
|
|
26
25
|
patchwork: Patchwork;
|
|
27
|
-
accountDocHandle: DocHandle<AccountDoc>;
|
|
28
26
|
repo: Repo;
|
|
29
27
|
Automerge: typeof import("@automerge/automerge");
|
|
30
28
|
AutomergeRepo: typeof import("@automerge/automerge-repo");
|
package/dist/index.js
CHANGED
|
@@ -30,6 +30,7 @@ import setupServiceWorker, { lifecycleLog, } from "@inkandswitch/patchwork-bootl
|
|
|
30
30
|
import debug from "debug";
|
|
31
31
|
import { createRepo, firstRepoPort, initWasm, removeAdapterFor, } from "./repo.js";
|
|
32
32
|
import { createRouter } from "./router.js";
|
|
33
|
+
import { createDefaultAccount } from "./createAccount.js";
|
|
33
34
|
const log = debug("patchwork:setup");
|
|
34
35
|
// ── Setup ────────────────────────────────────────────────────────────────
|
|
35
36
|
let setupCalled = false;
|
|
@@ -139,8 +140,8 @@ async function doSetup(options) {
|
|
|
139
140
|
const accountDocHandle = (await resolveAccountHandle(repo, {
|
|
140
141
|
storageKey: options.accountKey ?? "patchworkAccountURL",
|
|
141
142
|
hive,
|
|
143
|
+
createAccount: options.createAccount ?? createDefaultAccount,
|
|
142
144
|
}));
|
|
143
|
-
window.accountDocHandle = accountDocHandle;
|
|
144
145
|
wireModuleSettings(accountDocHandle, moduleWatcher);
|
|
145
146
|
const toolsLoaded = moduleWatcher.doneLoading.then(() => log("doneLoading, tools registered:", getRegistry("patchwork:tool")
|
|
146
147
|
.all()
|
|
@@ -246,8 +247,7 @@ function onModuleLoaded(name, mod) {
|
|
|
246
247
|
registerPlugins(mod.plugins, name);
|
|
247
248
|
}
|
|
248
249
|
/**
|
|
249
|
-
*
|
|
250
|
-
* appear and feed it to the ModuleWatcher.
|
|
250
|
+
* Feed the account's module settings document to the ModuleWatcher.
|
|
251
251
|
*/
|
|
252
252
|
function wireModuleSettings(accountDocHandle, moduleWatcher) {
|
|
253
253
|
const wire = () => {
|
package/dist/types.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { AutomergeUrl, DocHandle, Repo } from "@automerge/vanillajs/slim";
|
|
2
2
|
import type { AutomergeRepoKeyhive } from "@automerge/automerge-repo-keyhive";
|
|
3
3
|
import type { ModuleWatcher, HasPatchworkMetadata } from "@inkandswitch/patchwork-filesystem";
|
|
4
|
-
import type { AccountDoc } from "@inkandswitch/patchwork-plugins";
|
|
4
|
+
import type { AccountCreator, AccountDoc } from "@inkandswitch/patchwork-plugins";
|
|
5
5
|
import type { ServiceWorkerRepoChannelListener, SyncStateDocMessage } from "@inkandswitch/patchwork-bootloader/types";
|
|
6
6
|
import type * as pluginsNS from "@inkandswitch/patchwork-plugins";
|
|
7
7
|
export type PluginsApi = typeof pluginsNS;
|
|
@@ -45,6 +45,7 @@ export interface PatchworkOptions {
|
|
|
45
45
|
* other's accounts.
|
|
46
46
|
*/
|
|
47
47
|
accountKey?: string;
|
|
48
|
+
createAccount?: AccountCreator;
|
|
48
49
|
/**
|
|
49
50
|
* Brand word for this site: appended to the document title as
|
|
50
51
|
* `"<doc> | <name>"` when a document is open (the separator is provided
|
|
@@ -66,14 +66,20 @@ export function importmap(options) {
|
|
|
66
66
|
},
|
|
67
67
|
transformIndexHtml: {
|
|
68
68
|
order: "pre",
|
|
69
|
-
handler(html) {
|
|
69
|
+
handler(html, context) {
|
|
70
|
+
const activeImportmap = structuredClone(importmap);
|
|
71
|
+
if (context.server) {
|
|
72
|
+
for (const id of Object.keys(builtins)) {
|
|
73
|
+
activeImportmap.imports[id] = `/@id/${id}`;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
70
76
|
return {
|
|
71
77
|
html,
|
|
72
78
|
tags: [
|
|
73
79
|
{
|
|
74
80
|
tag: "script",
|
|
75
81
|
attrs: { type: "importmap" },
|
|
76
|
-
children: JSON.stringify(
|
|
82
|
+
children: JSON.stringify(activeImportmap, null, 2),
|
|
77
83
|
},
|
|
78
84
|
],
|
|
79
85
|
};
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"url": "git+https://github.com/inkandswitch/patchwork-system.git",
|
|
6
6
|
"directory": "core/patchwork"
|
|
7
7
|
},
|
|
8
|
-
"version": "0.
|
|
8
|
+
"version": "0.3.1",
|
|
9
9
|
"author": "Ink & Switch",
|
|
10
10
|
"type": "module",
|
|
11
11
|
"license": "MIT",
|
|
@@ -42,11 +42,11 @@
|
|
|
42
42
|
"debug": "^4.4.3",
|
|
43
43
|
"sharp": "^0.35.3",
|
|
44
44
|
"vite-plugin-wasm": "^3.6.0",
|
|
45
|
-
"@inkandswitch/patchwork-bootloader": "^0.5.2",
|
|
46
45
|
"@inkandswitch/patchwork-filesystem": "^0.2.5",
|
|
47
|
-
"@inkandswitch/patchwork-elements": "^
|
|
46
|
+
"@inkandswitch/patchwork-elements": "^5.0.0",
|
|
47
|
+
"@inkandswitch/patchwork-plugins": "^1.1.0",
|
|
48
48
|
"@inkandswitch/patchwork-providers": "^0.4.2",
|
|
49
|
-
"@inkandswitch/patchwork-
|
|
49
|
+
"@inkandswitch/patchwork-bootloader": "^0.5.3"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
52
|
"esbuild": "^0.23.1",
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AccountCreator,
|
|
3
|
+
type AccountDoc,
|
|
4
|
+
type DatatypeDescription,
|
|
5
|
+
createDocOfDatatype2,
|
|
6
|
+
getRegistry,
|
|
7
|
+
} from "@inkandswitch/patchwork-plugins";
|
|
8
|
+
|
|
9
|
+
export const createDefaultAccount: AccountCreator<AccountDoc> = async (
|
|
10
|
+
accountHandle,
|
|
11
|
+
repo
|
|
12
|
+
) => {
|
|
13
|
+
const fields = [
|
|
14
|
+
["rootFolderUrl", "folder"],
|
|
15
|
+
["moduleSettingsUrl", "patchwork:module-settings"],
|
|
16
|
+
["contactUrl", "contact"],
|
|
17
|
+
] as const;
|
|
18
|
+
const registry = getRegistry<DatatypeDescription>("patchwork:datatype");
|
|
19
|
+
|
|
20
|
+
const subdocs = await Promise.all(
|
|
21
|
+
fields.map(async ([field, datatypeId]) => {
|
|
22
|
+
const datatype = await registry.loadWhenReady(datatypeId);
|
|
23
|
+
const handle = await createDocOfDatatype2(datatype, repo);
|
|
24
|
+
return [field, handle.url] as const;
|
|
25
|
+
})
|
|
26
|
+
);
|
|
27
|
+
|
|
28
|
+
accountHandle.change((doc) => {
|
|
29
|
+
for (const [field, url] of subdocs) doc[field] = url;
|
|
30
|
+
});
|
|
31
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -60,6 +60,7 @@ import {
|
|
|
60
60
|
removeAdapterFor,
|
|
61
61
|
} from "./repo.js";
|
|
62
62
|
import { createRouter, type Router } from "./router.js";
|
|
63
|
+
import { createDefaultAccount } from "./createAccount.js";
|
|
63
64
|
|
|
64
65
|
const log = debug("patchwork:setup");
|
|
65
66
|
|
|
@@ -68,7 +69,6 @@ declare const __SITE_NAME__: string;
|
|
|
68
69
|
declare global {
|
|
69
70
|
interface Window {
|
|
70
71
|
patchwork: Patchwork;
|
|
71
|
-
accountDocHandle: DocHandle<AccountDoc>;
|
|
72
72
|
repo: Repo;
|
|
73
73
|
Automerge: typeof import("@automerge/automerge");
|
|
74
74
|
AutomergeRepo: typeof import("@automerge/automerge-repo");
|
|
@@ -222,9 +222,9 @@ async function doSetup(options: PatchworkOptions): Promise<Patchwork> {
|
|
|
222
222
|
const accountDocHandle = (await resolveAccountHandle(repo, {
|
|
223
223
|
storageKey: options.accountKey ?? "patchworkAccountURL",
|
|
224
224
|
hive,
|
|
225
|
+
createAccount: options.createAccount ?? createDefaultAccount,
|
|
225
226
|
})) as DocHandle<AccountDoc>;
|
|
226
227
|
|
|
227
|
-
window.accountDocHandle = accountDocHandle;
|
|
228
228
|
wireModuleSettings(accountDocHandle, moduleWatcher);
|
|
229
229
|
|
|
230
230
|
const toolsLoaded = moduleWatcher.doneLoading.then(
|
|
@@ -374,8 +374,7 @@ function onModuleLoaded(name: string, mod: any): void {
|
|
|
374
374
|
}
|
|
375
375
|
|
|
376
376
|
/**
|
|
377
|
-
*
|
|
378
|
-
* appear and feed it to the ModuleWatcher.
|
|
377
|
+
* Feed the account's module settings document to the ModuleWatcher.
|
|
379
378
|
*/
|
|
380
379
|
function wireModuleSettings(
|
|
381
380
|
accountDocHandle: DocHandle<AccountDoc>,
|
package/src/types.ts
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
AutomergeUrl,
|
|
3
|
-
DocHandle,
|
|
4
|
-
Repo,
|
|
5
|
-
} from "@automerge/vanillajs/slim";
|
|
1
|
+
import type { AutomergeUrl, DocHandle, Repo } from "@automerge/vanillajs/slim";
|
|
6
2
|
import type { AutomergeRepoKeyhive } from "@automerge/automerge-repo-keyhive";
|
|
7
3
|
import type {
|
|
8
4
|
ModuleWatcher,
|
|
9
5
|
HasPatchworkMetadata,
|
|
10
6
|
} from "@inkandswitch/patchwork-filesystem";
|
|
11
|
-
import type {
|
|
7
|
+
import type {
|
|
8
|
+
AccountCreator,
|
|
9
|
+
AccountDoc,
|
|
10
|
+
} from "@inkandswitch/patchwork-plugins";
|
|
12
11
|
import type {
|
|
13
12
|
ServiceWorkerRepoChannelListener,
|
|
14
13
|
SyncStateDocMessage,
|
|
@@ -63,6 +62,7 @@ export interface PatchworkOptions {
|
|
|
63
62
|
* other's accounts.
|
|
64
63
|
*/
|
|
65
64
|
accountKey?: string;
|
|
65
|
+
createAccount?: AccountCreator;
|
|
66
66
|
|
|
67
67
|
/**
|
|
68
68
|
* Brand word for this site: appended to the document title as
|
|
@@ -95,14 +95,20 @@ export function importmap(options?: PatchworkVitePluginOptions): Plugin {
|
|
|
95
95
|
},
|
|
96
96
|
transformIndexHtml: {
|
|
97
97
|
order: "pre",
|
|
98
|
-
handler(html) {
|
|
98
|
+
handler(html, context) {
|
|
99
|
+
const activeImportmap = structuredClone(importmap);
|
|
100
|
+
if (context.server) {
|
|
101
|
+
for (const id of Object.keys(builtins)) {
|
|
102
|
+
activeImportmap.imports[id] = `/@id/${id}`;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
99
105
|
return {
|
|
100
106
|
html,
|
|
101
107
|
tags: [
|
|
102
108
|
{
|
|
103
109
|
tag: "script",
|
|
104
110
|
attrs: { type: "importmap" },
|
|
105
|
-
children: JSON.stringify(
|
|
111
|
+
children: JSON.stringify(activeImportmap, null, 2),
|
|
106
112
|
},
|
|
107
113
|
],
|
|
108
114
|
};
|