drupal-decoupled 0.1.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/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Drupal-Decoupled
2
+
3
+ A list of utilities for a Decoupled integrations
4
+
5
+ ### Route Syncronization and comunication between FE and BE via the Iframe
6
+
7
+ Import the `syncDrupalPreviewRoutes` helper at `app/root.tsx`
8
+
9
+ ```typescript
10
+ import { syncDrupalPreviewRoutes } from "drupal-remix";
11
+ ```
12
+
13
+ Make sure your loader returns the current `environment` value
14
+
15
+ ```typescript
16
+ export const loader = async ({ context }: LoaderFunctionArgs ) => {
17
+ // Provide a variable to define the environment
18
+ const environment = context.cloudflare.env.ENVIRONMENT
19
+ return json(
20
+ {
21
+ environment,
22
+ },
23
+ { status: 200 }
24
+ );
25
+ };
26
+ ```
27
+
28
+ > NOTE: This example is using Cloudflare and taking advantage of Environemt Settings to define "environment" key/value, that is why we are using the `context.cloudflare.env.ENVIRONMENT` object to obtain the value and pass it from Server to Client.
29
+
30
+ Upate your `App` function
31
+
32
+ ```typescript
33
+ export default function App() {
34
+ // read environment from loader
35
+ const { environment } = useLoaderData<typeof loader>();
36
+ // use the useNavigation hook from @remix-run/react
37
+ const navigation = useNavigation();
38
+
39
+ // check if environment is preview and navigation.state is loading
40
+ // to call syncDrupalPreviewRoutes
41
+ if (environment === "preview" && navigation.state === "loading") {
42
+ syncDrupalPreviewRoutes(navigation.location.pathname);
43
+ }
44
+
45
+ return (
46
+ <>
47
+ <Outlet />
48
+ </>
49
+ );
50
+ }
51
+ ```
52
+
53
+ For a fully functional example visit any of those repositories:
54
+ - GraphQL:
55
+ - [Remix](https://github.com/octahedroid/drupal-remix/tree/main/examples/graphql)
56
+ - [Drupal]()
57
+
58
+ - JSON:API (TBD)
59
+
60
+ ## Supporting organizations
61
+
62
+ Development sponsored by [Octahedroid](https://octahedroid.com/)
@@ -0,0 +1,2 @@
1
+ import { syncDrupalPreviewRoutes } from "./syncPreview";
2
+ export { syncDrupalPreviewRoutes };
package/dist/index.js ADDED
@@ -0,0 +1 @@
1
+ var o=e=>{window&&window.top!==window.self&&window.parent.postMessage({type:"DECOUPLED_PREVIEW_IFRAME_ROUTE_SYNC",path:e},"*")};export{o as syncDrupalPreviewRoutes};
@@ -0,0 +1 @@
1
+ export declare const syncDrupalPreviewRoutes: (path: string) => void;
@@ -0,0 +1 @@
1
+ var o=e=>{window&&window.top!==window.self&&window.parent.postMessage({type:"DECOUPLED_PREVIEW_IFRAME_ROUTE_SYNC",path:e},"*")};export{o as syncDrupalPreviewRoutes};
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "drupal-decoupled",
3
+ "version": "0.1.0",
4
+ "description": "Drupal utils for Decoupled integrations",
5
+ "type": "module",
6
+ "keywords": [
7
+ "graphql",
8
+ "drupal",
9
+ "decoupled",
10
+ "remix",
11
+ "next.js"
12
+ ],
13
+ "main": "dist/index.js",
14
+ "types": "dist/index.d.ts",
15
+ "files": [
16
+ "dist"
17
+ ],
18
+ "bundlesize": [
19
+ {
20
+ "path": "./dist/index.js"
21
+ }
22
+ ],
23
+ "scripts": {
24
+ "prepublish": "yarn build",
25
+ "ts-types": " tsc --emitDeclarationOnly --outDir dist",
26
+ "build": "rimraf dist && node ./esbuild.js && yarn ts-types"
27
+ },
28
+ "author": "Octahedroid <opensource@octahedroid.com>",
29
+ "repository": {
30
+ "url": "https://github.com/octahedroid/drupal-decoupled/tree/main/packages/drupal-decoupled"
31
+ },
32
+ "license": "MIT",
33
+ "devDependencies": {
34
+ "@types/node": "^18.11.3",
35
+ "esbuild": "^0.17.18",
36
+ "rimraf": "^5.0.0",
37
+ "typescript": "^4.8.4"
38
+ },
39
+ "dependencies": {}
40
+ }