@powerhousedao/reactor-browser 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/hooks/useDocumentEditor.js +33 -28
- package/dist/hooks/useDocumentEditor.js.map +1 -1
- package/dist/src/hooks/useDocumentEditor.d.ts +2 -0
- package/dist/src/hooks/useDocumentEditor.d.ts.map +1 -1
- package/dist/utils/signature.js +30 -7
- package/dist/utils/signature.js.map +1 -1
- package/package.json +4 -4
|
@@ -1,41 +1,46 @@
|
|
|
1
|
-
import { useDocumentDispatch as
|
|
2
|
-
import { addActionContext as
|
|
3
|
-
import { useConnectDid as
|
|
4
|
-
import { useAddDebouncedOperations as
|
|
5
|
-
function
|
|
6
|
-
const {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
import { useDocumentDispatch as g } from "./useDocumentDispatch.js";
|
|
2
|
+
import { addActionContext as v, signOperation as x } from "../utils/signature.js";
|
|
3
|
+
import { useConnectDid as A, useConnectCrypto as k } from "./useConnectCrypto.js";
|
|
4
|
+
import { useAddDebouncedOperations as y } from "./useAddDebouncedOperations.js";
|
|
5
|
+
function j(n, c) {
|
|
6
|
+
const {
|
|
7
|
+
nodeId: o,
|
|
8
|
+
driveId: r,
|
|
9
|
+
documentModel: t,
|
|
10
|
+
document: d,
|
|
11
|
+
user: e
|
|
12
|
+
} = c, i = A(), { sign: s } = k(), u = y(n, {
|
|
13
|
+
driveId: r,
|
|
10
14
|
documentId: o
|
|
11
|
-
}), [
|
|
15
|
+
}), [m, a, p] = g(
|
|
12
16
|
t.reducer,
|
|
13
|
-
|
|
17
|
+
d
|
|
14
18
|
);
|
|
15
|
-
function
|
|
16
|
-
const
|
|
17
|
-
const { prevState:
|
|
18
|
-
|
|
19
|
-
h,
|
|
20
|
-
d,
|
|
21
|
-
o,
|
|
19
|
+
function D(f, h) {
|
|
20
|
+
const l = (C, b) => {
|
|
21
|
+
const { prevState: I } = b;
|
|
22
|
+
x(
|
|
22
23
|
C,
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
s,
|
|
25
|
+
o,
|
|
26
|
+
I,
|
|
27
|
+
t.reducer,
|
|
28
|
+
e
|
|
29
|
+
).then((O) => u(O)).catch(console.error);
|
|
25
30
|
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
31
|
+
a(
|
|
32
|
+
v(f, i, e),
|
|
33
|
+
l,
|
|
34
|
+
h
|
|
30
35
|
);
|
|
31
36
|
}
|
|
32
37
|
return {
|
|
33
|
-
dispatch:
|
|
34
|
-
document:
|
|
35
|
-
error:
|
|
38
|
+
dispatch: D,
|
|
39
|
+
document: m,
|
|
40
|
+
error: p
|
|
36
41
|
};
|
|
37
42
|
}
|
|
38
43
|
export {
|
|
39
|
-
|
|
44
|
+
j as useDocumentEditor
|
|
40
45
|
};
|
|
41
46
|
//# sourceMappingURL=useDocumentEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentEditor.js","sources":["../../src/hooks/useDocumentEditor.ts"],"sourcesContent":["import {\n Action,\n Document,\n Operation,\n BaseAction,\n DocumentModel,\n ActionErrorCallback,\n} from \"document-model/document\";\
|
|
1
|
+
{"version":3,"file":"useDocumentEditor.js","sources":["../../src/hooks/useDocumentEditor.ts"],"sourcesContent":["import {\n Action,\n Document,\n Operation,\n BaseAction,\n DocumentModel,\n ActionErrorCallback,\n} from \"document-model/document\";\nimport { useDocumentDispatch } from \"./useDocumentDispatch\";\nimport { signOperation, addActionContext } from \"../utils/signature\";\nimport { useConnectCrypto, useConnectDid } from \"./useConnectCrypto\";\nimport { useAddDebouncedOperations } from \"./useAddDebouncedOperations\";\nimport { IDocumentDriveServer } from \"document-drive\";\nimport { User } from \"../renown/types\";\n\nexport type DocumentDispatchCallback<State, A extends Action, LocalState> = (\n operation: Operation,\n state: {\n prevState: Document<State, A, LocalState>;\n newState: Document<State, A, LocalState>;\n },\n) => void;\n\nexport type UseDocumentEditorProps<\n T = unknown,\n A extends Action = Action,\n LocalState = unknown,\n> = {\n driveId: string;\n nodeId: string;\n document: Document<T, A, LocalState> | undefined;\n documentModel: DocumentModel<unknown, Action>;\n user?: User;\n onExport?: () => void;\n onOpenSwitchboardLink?: () => Promise<void>;\n onChange?: (document: Document<T, A, LocalState>) => void;\n};\n\nexport function useDocumentEditor(\n reactor: IDocumentDriveServer | undefined,\n props: UseDocumentEditorProps,\n) {\n const {\n nodeId,\n driveId,\n documentModel,\n document: initialDocument,\n user,\n } = props;\n\n const connectDid = useConnectDid();\n const { sign } = useConnectCrypto();\n\n const addDebouncedOprations = useAddDebouncedOperations(reactor, {\n driveId,\n documentId: nodeId,\n });\n\n const [document, _dispatch, error] = useDocumentDispatch(\n documentModel.reducer,\n initialDocument,\n );\n\n function dispatch(\n action: BaseAction | Action,\n onErrorCallback?: ActionErrorCallback,\n ) {\n const callback: DocumentDispatchCallback<unknown, Action, unknown> = (\n operation,\n state,\n ) => {\n const { prevState } = state;\n\n signOperation(\n operation,\n sign,\n nodeId,\n prevState,\n documentModel.reducer,\n user,\n )\n .then((op) => {\n return addDebouncedOprations(op);\n })\n .catch(console.error);\n };\n\n _dispatch(\n addActionContext(action, connectDid, user),\n callback,\n onErrorCallback,\n );\n }\n\n return {\n dispatch,\n document,\n error,\n };\n}\n"],"names":["useDocumentEditor","reactor","props","nodeId","driveId","documentModel","initialDocument","user","connectDid","useConnectDid","sign","useConnectCrypto","addDebouncedOprations","useAddDebouncedOperations","document","_dispatch","error","useDocumentDispatch","dispatch","action","onErrorCallback","callback","operation","state","prevState","signOperation","op","addActionContext"],"mappings":";;;;AAsCgB,SAAAA,EACdC,GACAC,GACA;AACM,QAAA;AAAA,IACJ,QAAAC;AAAA,IACA,SAAAC;AAAA,IACA,eAAAC;AAAA,IACA,UAAUC;AAAA,IACV,MAAAC;AAAA,EAAA,IACEL,GAEEM,IAAaC,EAAc,GAC3B,EAAE,MAAAC,EAAK,IAAIC,EAAiB,GAE5BC,IAAwBC,EAA0BZ,GAAS;AAAA,IAC/D,SAAAG;AAAA,IACA,YAAYD;AAAA,EAAA,CACb,GAEK,CAACW,GAAUC,GAAWC,CAAK,IAAIC;AAAA,IACnCZ,EAAc;AAAA,IACdC;AAAA,EACF;AAES,WAAAY,EACPC,GACAC,GACA;AACM,UAAAC,IAA+D,CACnEC,GACAC,MACG;AACG,YAAA,EAAE,WAAAC,MAAcD;AAEtB,MAAAE;AAAA,QACEH;AAAA,QACAZ;AAAA,QACAP;AAAA,QACAqB;AAAA,QACAnB,EAAc;AAAA,QACdE;AAAA,MAAA,EAEC,KAAK,CAACmB,MACEd,EAAsBc,CAAE,CAChC,EACA,MAAM,QAAQ,KAAK;AAAA,IACxB;AAEA,IAAAX;AAAA,MACEY,EAAiBR,GAAQX,GAAYD,CAAI;AAAA,MACzCc;AAAA,MACAD;AAAA,IACF;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,UAAAF;AAAA,IACA,UAAAJ;AAAA,IACA,OAAAE;AAAA,EACF;AACF;"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Action, Document, Operation, BaseAction, DocumentModel, ActionErrorCallback } from 'document-model/document';
|
|
2
2
|
import { IDocumentDriveServer } from 'document-drive';
|
|
3
|
+
import { User } from '../renown/types';
|
|
3
4
|
export type DocumentDispatchCallback<State, A extends Action, LocalState> = (operation: Operation, state: {
|
|
4
5
|
prevState: Document<State, A, LocalState>;
|
|
5
6
|
newState: Document<State, A, LocalState>;
|
|
@@ -9,6 +10,7 @@ export type UseDocumentEditorProps<T = unknown, A extends Action = Action, Local
|
|
|
9
10
|
nodeId: string;
|
|
10
11
|
document: Document<T, A, LocalState> | undefined;
|
|
11
12
|
documentModel: DocumentModel<unknown, Action>;
|
|
13
|
+
user?: User;
|
|
12
14
|
onExport?: () => void;
|
|
13
15
|
onOpenSwitchboardLink?: () => Promise<void>;
|
|
14
16
|
onChange?: (document: Document<T, A, LocalState>) => void;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDocumentEditor.d.ts","sourceRoot":"","sources":["../../../src/hooks/useDocumentEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,QAAQ,EACR,SAAS,EACT,UAAU,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"useDocumentEditor.d.ts","sourceRoot":"","sources":["../../../src/hooks/useDocumentEditor.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,QAAQ,EACR,SAAS,EACT,UAAU,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,yBAAyB,CAAC;AAKjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAAE,IAAI,EAAE,MAAM,iBAAiB,CAAC;AAEvC,MAAM,MAAM,wBAAwB,CAAC,KAAK,EAAE,CAAC,SAAS,MAAM,EAAE,UAAU,IAAI,CAC1E,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE;IACL,SAAS,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;IAC1C,QAAQ,EAAE,QAAQ,CAAC,KAAK,EAAE,CAAC,EAAE,UAAU,CAAC,CAAC;CAC1C,KACE,IAAI,CAAC;AAEV,MAAM,MAAM,sBAAsB,CAChC,CAAC,GAAG,OAAO,EACX,CAAC,SAAS,MAAM,GAAG,MAAM,EACzB,UAAU,GAAG,OAAO,IAClB;IACF,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,GAAG,SAAS,CAAC;IACjD,aAAa,EAAE,aAAa,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC9C,IAAI,CAAC,EAAE,IAAI,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;IACtB,qBAAqB,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5C,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,EAAE,UAAU,CAAC,KAAK,IAAI,CAAC;CAC3D,CAAC;AAEF,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,oBAAoB,GAAG,SAAS,EACzC,KAAK,EAAE,sBAAsB;uBAwBnB,UAAU,GAAG,MAAM,oBACT,mBAAmB;;;EAkCxC"}
|
package/dist/utils/signature.js
CHANGED
|
@@ -1,12 +1,35 @@
|
|
|
1
|
-
import "document-model/document";
|
|
2
|
-
async function
|
|
3
|
-
return n;
|
|
1
|
+
import { utils as d } from "document-model/document";
|
|
2
|
+
async function g(n, t, e, r, i, s) {
|
|
3
|
+
if (!s || !n.context || !n.context.signer) return n;
|
|
4
|
+
if (!i)
|
|
5
|
+
return console.error(
|
|
6
|
+
`Document model '${r.documentType}' does not have a reducer`
|
|
7
|
+
), n;
|
|
8
|
+
const c = {
|
|
9
|
+
documentId: e,
|
|
10
|
+
signer: n.context.signer
|
|
11
|
+
};
|
|
12
|
+
return await d.buildSignedOperation(n, i, r, c, t);
|
|
4
13
|
}
|
|
5
|
-
function
|
|
6
|
-
return
|
|
14
|
+
function a(n, t, e) {
|
|
15
|
+
return e ? {
|
|
16
|
+
context: { signer: {
|
|
17
|
+
app: {
|
|
18
|
+
name: "Connect",
|
|
19
|
+
key: t || ""
|
|
20
|
+
},
|
|
21
|
+
user: {
|
|
22
|
+
address: e.address,
|
|
23
|
+
networkId: e.networkId,
|
|
24
|
+
chainId: e.chainId
|
|
25
|
+
},
|
|
26
|
+
signatures: []
|
|
27
|
+
} },
|
|
28
|
+
...n
|
|
29
|
+
} : n;
|
|
7
30
|
}
|
|
8
31
|
export {
|
|
9
|
-
|
|
10
|
-
|
|
32
|
+
a as addActionContext,
|
|
33
|
+
g as signOperation
|
|
11
34
|
};
|
|
12
35
|
//# sourceMappingURL=signature.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"signature.js","sources":["../../src/utils/signature.ts"],"sourcesContent":["import {\n Action,\n ActionSigner,\n Document,\n Operation,\n OperationSignatureContext,\n Reducer,\n User,\n utils,\n} from \"document-model/document\";\nimport type { User as RenownUser } from \"../renown/types\";\n\nexport async function signOperation<\n State = unknown,\n A extends Action = Action,\n LocalState = unknown,\n>(\n operation: Operation<A>,\n sign: (data: Uint8Array) => Promise<Uint8Array>,\n documentId: string,\n document: Document<State, A, LocalState>,\n reducer?: Reducer<State, A, LocalState>,\n user?: User,\n): Promise<Operation<A>> {\n if (!user) return operation;\n if (!operation.context) return operation;\n if (!operation.context.signer) return operation;\n if (!reducer) {\n console.error(\n `Document model '${document.documentType}' does not have a reducer`,\n );\n return operation;\n }\n\n const context: Omit<\n OperationSignatureContext,\n \"operation\" | \"previousStateHash\"\n > = {\n documentId,\n signer: operation.context.signer,\n };\n\n const signedOperation = await utils.buildSignedOperation<\n State,\n A,\n LocalState\n >(operation, reducer, document, context, sign);\n\n return signedOperation as Operation<A>;\n}\n\nexport function addActionContext<A extends Action = Action>(\n action: A,\n connectDid?: string,\n user?: RenownUser,\n) {\n if (!user) return action;\n\n const signer: ActionSigner = {\n app: {\n name: \"Connect\",\n key: connectDid || \"\",\n },\n user: {\n address: user.address,\n networkId: user.networkId,\n chainId: user.chainId,\n },\n signatures: [],\n };\n\n return {\n context: { signer },\n ...action,\n };\n}\n"],"names":["signOperation","operation","sign","documentId","document","reducer","user","addActionContext","action","connectDid"],"mappings":";AAYA,eAAsBA,EAKpBC,GACAC,GACAC,GACAC,GACAC,GACAC,GACuB;
|
|
1
|
+
{"version":3,"file":"signature.js","sources":["../../src/utils/signature.ts"],"sourcesContent":["import {\n Action,\n ActionSigner,\n Document,\n Operation,\n OperationSignatureContext,\n Reducer,\n User,\n utils,\n} from \"document-model/document\";\nimport type { User as RenownUser } from \"../renown/types\";\n\nexport async function signOperation<\n State = unknown,\n A extends Action = Action,\n LocalState = unknown,\n>(\n operation: Operation<A>,\n sign: (data: Uint8Array) => Promise<Uint8Array>,\n documentId: string,\n document: Document<State, A, LocalState>,\n reducer?: Reducer<State, A, LocalState>,\n user?: User,\n): Promise<Operation<A>> {\n if (!user) return operation;\n if (!operation.context) return operation;\n if (!operation.context.signer) return operation;\n if (!reducer) {\n console.error(\n `Document model '${document.documentType}' does not have a reducer`,\n );\n return operation;\n }\n\n const context: Omit<\n OperationSignatureContext,\n \"operation\" | \"previousStateHash\"\n > = {\n documentId,\n signer: operation.context.signer,\n };\n\n const signedOperation = await utils.buildSignedOperation<\n State,\n A,\n LocalState\n >(operation, reducer, document, context, sign);\n\n return signedOperation as Operation<A>;\n}\n\nexport function addActionContext<A extends Action = Action>(\n action: A,\n connectDid?: string,\n user?: RenownUser,\n) {\n if (!user) return action;\n\n const signer: ActionSigner = {\n app: {\n name: \"Connect\",\n key: connectDid || \"\",\n },\n user: {\n address: user.address,\n networkId: user.networkId,\n chainId: user.chainId,\n },\n signatures: [],\n };\n\n return {\n context: { signer },\n ...action,\n };\n}\n"],"names":["signOperation","operation","sign","documentId","document","reducer","user","context","utils","addActionContext","action","connectDid"],"mappings":";AAYA,eAAsBA,EAKpBC,GACAC,GACAC,GACAC,GACAC,GACAC,GACuB;AAGvB,MAFI,CAACA,KACD,CAACL,EAAU,WACX,CAACA,EAAU,QAAQ,OAAe,QAAAA;AACtC,MAAI,CAACI;AACK,mBAAA;AAAA,MACN,mBAAmBD,EAAS,YAAY;AAAA,IAC1C,GACOH;AAGT,QAAMM,IAGF;AAAA,IACF,YAAAJ;AAAA,IACA,QAAQF,EAAU,QAAQ;AAAA,EAC5B;AAQO,SANiB,MAAMO,EAAM,qBAIlCP,GAAWI,GAASD,GAAUG,GAASL,CAAI;AAG/C;AAEgB,SAAAO,EACdC,GACAC,GACAL,GACA;AACI,SAACA,IAeE;AAAA,IACL,SAAS,EAAE,QAdgB;AAAA,MAC3B,KAAK;AAAA,QACH,MAAM;AAAA,QACN,KAAKK,KAAc;AAAA,MACrB;AAAA,MACA,MAAM;AAAA,QACJ,SAASL,EAAK;AAAA,QACd,WAAWA,EAAK;AAAA,QAChB,SAASA,EAAK;AAAA,MAChB;AAAA,MACA,YAAY,CAAA;AAAA,IACd,EAGoB;AAAA,IAClB,GAAGI;AAAA,EACL,IAlBkBA;AAmBpB;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/reactor-browser",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -20,16 +20,16 @@
|
|
|
20
20
|
"react-dom": "^18.3.1",
|
|
21
21
|
"@powerhousedao/config": "1.5.0",
|
|
22
22
|
"@powerhousedao/design-system": "1.19.0",
|
|
23
|
+
"@powerhousedao/scalars": "1.16.0",
|
|
23
24
|
"document-drive": "1.13.1",
|
|
24
25
|
"document-model": "2.15.0",
|
|
25
|
-
"document-model-libs": "1.125.1"
|
|
26
|
-
"@powerhousedao/scalars": "1.16.0"
|
|
26
|
+
"document-model-libs": "1.125.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"react": "^18.3.1",
|
|
30
30
|
"react-dom": "^18.3.1",
|
|
31
|
-
"@powerhousedao/design-system": "1.19.0",
|
|
32
31
|
"@powerhousedao/config": "1.5.0",
|
|
32
|
+
"@powerhousedao/design-system": "1.19.0",
|
|
33
33
|
"@powerhousedao/scalars": "1.16.0",
|
|
34
34
|
"document-drive": "1.13.1",
|
|
35
35
|
"document-model": "2.15.0",
|