diff --git a/helpers/nextgraph-react/.gitignore b/helpers/nextgraph-react/.gitignore index e69de29..53c37a1 100644 --- a/helpers/nextgraph-react/.gitignore +++ b/helpers/nextgraph-react/.gitignore @@ -0,0 +1 @@ +dist \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/esm/NextGraphAuthContext.js b/helpers/nextgraph-react/dist/esm/NextGraphAuthContext.js deleted file mode 100644 index 5b5c0dd..0000000 --- a/helpers/nextgraph-react/dist/esm/NextGraphAuthContext.js +++ /dev/null @@ -1,9 +0,0 @@ -import { createContext, useContext } from "react"; -// There is no initial value for this context. It will be given in the provider -// eslint-disable-next-line @typescript-eslint/ban-ts-comment -// @ts-ignore -export const NextGraphAuthContext = createContext(undefined); -export function useNextGraphAuth() { - return useContext(NextGraphAuthContext); -} -//# sourceMappingURL=NextGraphAuthContext.js.map \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/esm/NextGraphAuthContext.js.map b/helpers/nextgraph-react/dist/esm/NextGraphAuthContext.js.map deleted file mode 100644 index cda3189..0000000 --- a/helpers/nextgraph-react/dist/esm/NextGraphAuthContext.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"NextGraphAuthContext.js","sourceRoot":"","sources":["../../src/NextGraphAuthContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAYlD,+EAA+E;AAC/E,6DAA6D;AAC7D,aAAa;AACb,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAwB,SAAS,CAAC,CAAC;AAEpF,MAAM,UAAU,gBAAgB;IAC5B,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC5C,CAAC"} \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/esm/createBrowserNGReactMethods.js b/helpers/nextgraph-react/dist/esm/createBrowserNGReactMethods.js deleted file mode 100644 index 3c33623..0000000 --- a/helpers/nextgraph-react/dist/esm/createBrowserNGReactMethods.js +++ /dev/null @@ -1,80 +0,0 @@ -import { jsx as _jsx } from "react/jsx-runtime"; -import { useCallback, useEffect, useMemo, useState } from "react"; -import { NextGraphAuthContext, useNextGraphAuth } from "./NextGraphAuthContext.js"; -import { default as ng, init } from "nextgraphweb"; -/** - * Creates special react methods specific to the NextGraph Auth - * @param dataset the connectedLdoDataset with a nextGraphConnectedPlugin - * @returns { BrowserNGLdoProvider, useNextGraphAuth } - */ -export function createBrowserNGReactMethods(dataset) { - const BrowserNGLdoProvider = ({ children, }) => { - const [session, setSession] = useState({ - ng: undefined, - }); - const [ranInitialAuthCheck, setRanInitialAuthCheck] = useState(false); - const runInitialAuthCheck = useCallback(async () => { - //console.log("runInitialAuthCheck called", ranInitialAuthCheck) - if (ranInitialAuthCheck) - return; - //console.log("init called"); - setRanInitialAuthCheck(true); - // TODO: export the types for the session object coming from NG. - await init((event) => { - //console.log("called back in react", event) - // callback - // once you receive event.status == "loggedin" - // you can use the full API - if (event.status == "loggedin") { - setSession({ - ng, - sessionId: event.session.session_id, //FIXME: sessionId should be a Number. - protectedStoreId: event.session.protected_store_id, - privateStoreId: event.session.private_store_id, - publicStoreId: event.session.public_store_id - }); // TODO: add event.session.user too - dataset.setContext("nextgraph", { - ng, - sessionId: event.session.session_id - }); - } - else if (event.status == "cancelled" || event.status == "error" || event.status == "loggedout") { - setSession({ ng: undefined }); - dataset.setContext("nextgraph", { - ng: undefined, - }); - } - }, true // singleton: boolean (will your app create many docs in the system, or should it be launched as a unique instance) - , []); //list of AccessRequests (for now, leave this empty) - }, []); - const login = useCallback(async () => { - await ng.login(); - }, []); - const logout = useCallback(async () => { - await ng.logout(); - }, []); - useEffect(() => { - runInitialAuthCheck(); - }, []); - const nextGraphAuthFunctions = useMemo(() => ({ - runInitialAuthCheck, - login, - logout, - session, - ranInitialAuthCheck, - }), [ - login, - logout, - ranInitialAuthCheck, - runInitialAuthCheck, - session, - ]); - return (_jsx(NextGraphAuthContext.Provider, { value: nextGraphAuthFunctions, children: children })); - }; - return { - BrowserNGLdoProvider, - useNextGraphAuth: useNextGraphAuth - }; -} -; -//# sourceMappingURL=createBrowserNGReactMethods.js.map \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/esm/createBrowserNGReactMethods.js.map b/helpers/nextgraph-react/dist/esm/createBrowserNGReactMethods.js.map deleted file mode 100644 index 3843cd6..0000000 --- a/helpers/nextgraph-react/dist/esm/createBrowserNGReactMethods.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createBrowserNGReactMethods.js","sourceRoot":"","sources":["../../src/createBrowserNGReactMethods.tsx"],"names":[],"mappings":";AAAA,OAAc,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAE,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAEnF,OAAO,EAAC,OAAO,IAAI,EAAE,EAAE,IAAI,EAAC,MAAM,cAAc,CAAC;AAKjD;;;;GAIG;AACH,MAAM,UAAU,2BAA2B,CACzC,OAA4E;IAG5E,MAAM,oBAAoB,GAAyC,CAAC,EAClE,QAAQ,GACT,EAAE,EAAE;QACH,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CACpC;YACE,EAAE,EAAE,SAAS;SACd,CACF,CAAC;QACF,MAAM,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;QAEtE,MAAM,mBAAmB,GAAG,WAAW,CAAC,KAAK,IAAI,EAAE;YACjD,gEAAgE;YAChE,IAAI,mBAAmB;gBAAE,OAAO;YAEhC,6BAA6B;YAC7B,sBAAsB,CAAC,IAAI,CAAC,CAAC;YAC7B,gEAAgE;YAChE,MAAM,IAAI,CAAE,CAAC,KAA+I,EAAE,EAAE;gBAC9J,4CAA4C;gBAE5C,WAAW;gBACX,8CAA8C;gBAC9C,2BAA2B;gBAC3B,IAAI,KAAK,CAAC,MAAM,IAAI,UAAU,EAA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AG,EAAE,CAAC,CAAC;YACL,mBAAmB;YACnB,KAAK;YACL,MAAM;YACN,OAAO;YACP,mBAAmB;SACpB,CAAC,EACF;YACE,KAAK;YACL,MAAM;YACN,mBAAmB;YACnB,mBAAmB;YACnB,OAAO;SACR,CACF,CAAC;QAEF,OAAO,CACL,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,sBAAsB,YACzD,QAAQ,GACqB,CACjC,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO;QACL,oBAAoB;QACpB,gBAAgB,EAAE,gBAAgB;KACnC,CAAC;AACJ,CAAC;AAAA,CAAC"} \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/esm/index.js b/helpers/nextgraph-react/dist/esm/index.js deleted file mode 100644 index 778e8c4..0000000 --- a/helpers/nextgraph-react/dist/esm/index.js +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./createBrowserNGReactMethods.js"; -//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/esm/index.js.map b/helpers/nextgraph-react/dist/esm/index.js.map deleted file mode 100644 index 0678482..0000000 --- a/helpers/nextgraph-react/dist/esm/index.js.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"} \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/types/NextGraphAuthContext.d.ts b/helpers/nextgraph-react/dist/types/NextGraphAuthContext.d.ts deleted file mode 100644 index b9c52f9..0000000 --- a/helpers/nextgraph-react/dist/types/NextGraphAuthContext.d.ts +++ /dev/null @@ -1,12 +0,0 @@ -/** - * Functions for authenticating with NextGraph - */ -export interface NGWalletAuthFunctions { - login: () => Promise; - logout: () => Promise; - session: unknown; - ranInitialAuthCheck: boolean; -} -export declare const NextGraphAuthContext: import("react").Context; -export declare function useNextGraphAuth(): NGWalletAuthFunctions; -//# sourceMappingURL=NextGraphAuthContext.d.ts.map \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/types/NextGraphAuthContext.d.ts.map b/helpers/nextgraph-react/dist/types/NextGraphAuthContext.d.ts.map deleted file mode 100644 index cf003f8..0000000 --- a/helpers/nextgraph-react/dist/types/NextGraphAuthContext.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"NextGraphAuthContext.d.ts","sourceRoot":"","sources":["../../src/NextGraphAuthContext.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,qBAAqB;IAClC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,mBAAmB,EAAE,OAAO,CAAC;CAChC;AAKD,eAAO,MAAM,oBAAoB,gDAAkD,CAAC;AAEpF,wBAAgB,gBAAgB,IAAI,qBAAqB,CAExD"} \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/types/createBrowserNGReactMethods.d.ts b/helpers/nextgraph-react/dist/types/createBrowserNGReactMethods.d.ts deleted file mode 100644 index edad262..0000000 --- a/helpers/nextgraph-react/dist/types/createBrowserNGReactMethods.d.ts +++ /dev/null @@ -1,16 +0,0 @@ -import React from "react"; -import { useNextGraphAuth } from "./NextGraphAuthContext.js"; -import type { ConnectedLdoDataset, ConnectedPlugin } from "@ldo/connected"; -import type { NextGraphConnectedPlugin } from "@ldo/connected-nextgraph"; -/** - * Creates special react methods specific to the NextGraph Auth - * @param dataset the connectedLdoDataset with a nextGraphConnectedPlugin - * @returns { BrowserNGLdoProvider, useNextGraphAuth } - */ -export declare function createBrowserNGReactMethods(dataset: ConnectedLdoDataset<(NextGraphConnectedPlugin | ConnectedPlugin)[]>): { - BrowserNGLdoProvider: React.FunctionComponent<{ - children?: React.ReactNode | undefined; - }>; - useNextGraphAuth: typeof useNextGraphAuth; -}; -//# sourceMappingURL=createBrowserNGReactMethods.d.ts.map \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/types/createBrowserNGReactMethods.d.ts.map b/helpers/nextgraph-react/dist/types/createBrowserNGReactMethods.d.ts.map deleted file mode 100644 index 0e3095f..0000000 --- a/helpers/nextgraph-react/dist/types/createBrowserNGReactMethods.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"createBrowserNGReactMethods.d.ts","sourceRoot":"","sources":["../../src/createBrowserNGReactMethods.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAEzE,OAAO,EAAwB,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAInF,OAAO,KAAK,EAAE,mBAAmB,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAC3E,OAAO,KAAK,EAAE,wBAAwB,EAA6B,MAAM,0BAA0B,CAAC;AAEpG;;;;GAIG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,EAAE,mBAAmB,CAAC,CAAC,wBAAwB,GAAG,eAAe,CAAC,EAAE,CAAC;;;;;EAgG7E"} \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/types/index.d.ts b/helpers/nextgraph-react/dist/types/index.d.ts deleted file mode 100644 index 84f1b24..0000000 --- a/helpers/nextgraph-react/dist/types/index.d.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./createBrowserNGReactMethods.js"; -//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/helpers/nextgraph-react/dist/types/index.d.ts.map b/helpers/nextgraph-react/dist/types/index.d.ts.map deleted file mode 100644 index d743c90..0000000 --- a/helpers/nextgraph-react/dist/types/index.d.ts.map +++ /dev/null @@ -1 +0,0 @@ -{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kCAAkC,CAAC"} \ No newline at end of file diff --git a/helpers/nextgraph-react/package.json b/helpers/nextgraph-react/package.json index 23f8f64..cd0ced3 100644 --- a/helpers/nextgraph-react/package.json +++ b/helpers/nextgraph-react/package.json @@ -1,6 +1,6 @@ { "name": "nextgraph-react", - "version": "0.1.1-alpha.1", + "version": "0.1.1-alpha.3", "description": "A React library for LDO and NextGraph", "type": "module", "module": "./dist/esm/index.js", diff --git a/helpers/nextgraph-react/src/createNextGraphAuthMethods.tsx b/helpers/nextgraph-react/src/createNextGraphAuthMethods.tsx new file mode 100644 index 0000000..cea1575 --- /dev/null +++ b/helpers/nextgraph-react/src/createNextGraphAuthMethods.tsx @@ -0,0 +1,99 @@ +import React, { useCallback, useEffect, useMemo, useState } from "react"; +import type { FunctionComponent, PropsWithChildren } from "react"; +import { NextGraphAuthContext, useNextGraphAuth } from "./NextGraphAuthContext.js"; +import type { NextGraphConnectedContext } from "@ldo/connected-nextgraph"; +import {default as ng, init} from "nextgraphweb"; + +/** + * Creates special react methods specific to the NextGraph Auth + * @returns { BrowserNextGraphAuth, useNextGraphAuth } + */ +export function createNextGraphAuthMethod () { + + const NextGraphAuthMethod: FunctionComponent = ({ + children, + }) => { + const [session, setSession] = useState( + { + ng: undefined, + } + ); + const [ranInitialAuthCheck, setRanInitialAuthCheck] = useState(false); + + const runInitialAuthCheck = useCallback(async () => { + //console.log("runInitialAuthCheck called", ranInitialAuthCheck) + if (ranInitialAuthCheck) return; + + //console.log("init called"); + setRanInitialAuthCheck(true); + // TODO: export the types for the session object coming from NG. + await init( (event: { status: string; session: { session_id: unknown; protected_store_id: unknown; private_store_id: unknown; public_store_id: unknown; }; }) => { + //console.log("called back in react", event) + + // callback + // once you receive event.status == "loggedin" + // you can use the full API + if (event.status == "loggedin") { + setSession({ + ng, + sessionId: event.session.session_id as string, //FIXME: sessionId should be a Number. + protectedStoreId: event.session.protected_store_id as string, + privateStoreId: event.session.private_store_id as string, + publicStoreId: event.session.public_store_id as string + }); // TODO: add event.session.user too + + } + else if (event.status == "cancelled" || event.status == "error" || event.status == "loggedout") { + setSession({ ng: undefined }); + } + } + , true // singleton: boolean (will your app create many docs in the system, or should it be launched as a unique instance) + , []); //list of AccessRequests (for now, leave this empty) + + }, []); + + + const login = useCallback( + async () => { + await ng.login(); + }, + [], + ); + + const logout = useCallback(async () => { + await ng.logout(); + }, []); + + useEffect(() => { + runInitialAuthCheck(); + }, []); + + const nextGraphAuthFunctions = useMemo( + () => ({ + runInitialAuthCheck, + login, + logout, + session, + ranInitialAuthCheck, + }), + [ + login, + logout, + ranInitialAuthCheck, + runInitialAuthCheck, + session, + ], + ); + + return ( + + {children} + + ); + }; + + return { + NextGraphAuthMethod, + useNextGraphAuth: useNextGraphAuth + }; +}; \ No newline at end of file diff --git a/helpers/nextgraph-react/src/index.ts b/helpers/nextgraph-react/src/index.ts index fe1f0d0..fe23a89 100644 --- a/helpers/nextgraph-react/src/index.ts +++ b/helpers/nextgraph-react/src/index.ts @@ -1,2 +1,4 @@ export * from "./createBrowserNGReactMethods.js"; +export * from "./createNextGraphAuthMethods.js"; + diff --git a/ng-app/src/classes.ts b/ng-app/src/classes.ts index 61f7543..7220307 100644 --- a/ng-app/src/classes.ts +++ b/ng-app/src/classes.ts @@ -16,7 +16,7 @@ // "media:image", "media:reel", "media:album", "media:video", "media:audio", "media:song", "media:subtitle", "media:overlay", // "social:channel", "social:stream", "social:contact", "social:event", "social:calendar", "social:scheduler", "social:reaction", "social:chatroom", // "prod:task", "prod:project", "prod:issue", "prod:form", "prod:filling", "prod:cad", "prod:slides", "prod:question", "prod:answer", "prod:poll", "prod:vote" -// "file", "file:iana:*", "file:gimp", "file:inkscape", "file:kdenlive", "file:blender", "file:openscad", "file:lyx", "file:scribus", "file:libreoffice", "file:audacity", "file:godot", "file:obsstudio", "file:ardor", "file:krita" +// "file", "file:iana:*", "file:gimp", "file:inkscape", "file:kdenlive", "file:blender", "file:openscad", "file:freecad", "file:lyx", "file:scribus", "file:libreoffice", "file:audacity", "file:godot", "file:obsstudio", "file:ardor", "file:krita" // application/vnd.api+json @@ -43,6 +43,17 @@ export const official_classes = { }, "ng:compat": ["as:Article"], }, + "post:blocknote": { + "ng:crdt": "YXml", + "ng:n": "Post - BlockNote", + "ng:a": "A Post based on BlockNote Editor", + "ng:o": "n:g:z:post:rich", + "ng:w": "n:g:z:post_rich_editor", + "ng:x": { + "as":true, + }, + "ng:compat": ["as:Article"], + }, "post:md": { "ng:crdt": "YXml", "ng:n": "Post - MarkDown", // editor y-MilkDown, viewer: https://github.com/wooorm/markdown-rs