@mobilizehub/payload-plugin 0.0.0 → 0.0.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.
@@ -1 +1 @@
1
- export { BeforeDashboardClient } from '../components/BeforeDashboardClient.js';
1
+ export {};
@@ -1,3 +1,2 @@
1
- export { BeforeDashboardClient } from '../components/BeforeDashboardClient.js';
2
1
 
3
2
  //# sourceMappingURL=client.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/client.ts"],"sourcesContent":["export { BeforeDashboardClient } from '../components/BeforeDashboardClient.js'\n"],"names":["BeforeDashboardClient"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,yCAAwC"}
1
+ {"version":3,"sources":["../../src/exports/client.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- export { BeforeDashboardServer } from '../components/BeforeDashboardServer.js';
1
+ export {};
@@ -1,3 +1,2 @@
1
- export { BeforeDashboardServer } from '../components/BeforeDashboardServer.js';
2
1
 
3
2
  //# sourceMappingURL=rsc.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/exports/rsc.ts"],"sourcesContent":["export { BeforeDashboardServer } from '../components/BeforeDashboardServer.js'\n"],"names":["BeforeDashboardServer"],"mappings":"AAAA,SAASA,qBAAqB,QAAQ,yCAAwC"}
1
+ {"version":3,"sources":["../../src/exports/rsc.ts"],"names":[],"mappings":""}
package/dist/index.d.ts CHANGED
@@ -1,9 +1,5 @@
1
- import type { CollectionSlug, Config } from 'payload';
2
- export type PayloadPluginConfig = {
3
- /**
4
- * List of collections to add a custom field
5
- */
6
- collections?: Partial<Record<CollectionSlug, true>>;
1
+ import type { Config } from 'payload';
2
+ export type MobilizehubPluginConfig = {
7
3
  disabled?: boolean;
8
4
  };
9
- export declare const payloadPlugin: (pluginOptions: PayloadPluginConfig) => (config: Config) => Config;
5
+ export declare const mobilizehubPlugin: (pluginOptions: MobilizehubPluginConfig) => (config: Config) => Config;
package/dist/index.js CHANGED
@@ -1,78 +1,15 @@
1
- import { customEndpointHandler } from './endpoints/customEndpointHandler.js';
2
- export const payloadPlugin = (pluginOptions)=>(config)=>{
1
+ export const mobilizehubPlugin = (pluginOptions)=>(config)=>{
3
2
  if (!config.collections) {
4
3
  config.collections = [];
5
4
  }
6
- config.collections.push({
7
- slug: 'plugin-collection',
8
- fields: [
9
- {
10
- name: 'id',
11
- type: 'text'
12
- }
13
- ]
14
- });
15
- if (pluginOptions.collections) {
16
- for(const collectionSlug in pluginOptions.collections){
17
- const collection = config.collections.find((collection)=>collection.slug === collectionSlug);
18
- if (collection) {
19
- collection.fields.push({
20
- name: 'addedByPlugin',
21
- type: 'text',
22
- admin: {
23
- position: 'sidebar'
24
- }
25
- });
26
- }
27
- }
28
- }
29
- /**
30
- * If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.
31
- * If your plugin heavily modifies the database schema, you may want to remove this property.
32
- */ if (pluginOptions.disabled) {
5
+ if (pluginOptions.disabled) {
33
6
  return config;
34
7
  }
35
- if (!config.endpoints) {
36
- config.endpoints = [];
37
- }
38
- if (!config.admin) {
39
- config.admin = {};
40
- }
41
- if (!config.admin.components) {
42
- config.admin.components = {};
43
- }
44
- if (!config.admin.components.beforeDashboard) {
45
- config.admin.components.beforeDashboard = [];
46
- }
47
- config.admin.components.beforeDashboard.push(`payload-plugin/client#BeforeDashboardClient`);
48
- config.admin.components.beforeDashboard.push(`payload-plugin/rsc#BeforeDashboardServer`);
49
- config.endpoints.push({
50
- handler: customEndpointHandler,
51
- method: 'get',
52
- path: '/my-plugin-endpoint'
53
- });
54
8
  const incomingOnInit = config.onInit;
55
9
  config.onInit = async (payload)=>{
56
- // Ensure we are executing any existing onInit functions before running our own.
57
10
  if (incomingOnInit) {
58
11
  await incomingOnInit(payload);
59
12
  }
60
- const { totalDocs } = await payload.count({
61
- collection: 'plugin-collection',
62
- where: {
63
- id: {
64
- equals: 'seeded-by-plugin'
65
- }
66
- }
67
- });
68
- if (totalDocs === 0) {
69
- await payload.create({
70
- collection: 'plugin-collection',
71
- data: {
72
- id: 'seeded-by-plugin'
73
- }
74
- });
75
- }
76
13
  };
77
14
  return config;
78
15
  };
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { CollectionSlug, Config } from 'payload'\n\nimport { customEndpointHandler } from './endpoints/customEndpointHandler.js'\n\nexport type PayloadPluginConfig = {\n /**\n * List of collections to add a custom field\n */\n collections?: Partial<Record<CollectionSlug, true>>\n disabled?: boolean\n}\n\nexport const payloadPlugin =\n (pluginOptions: PayloadPluginConfig) =>\n (config: Config): Config => {\n if (!config.collections) {\n config.collections = []\n }\n\n config.collections.push({\n slug: 'plugin-collection',\n fields: [\n {\n name: 'id',\n type: 'text',\n },\n ],\n })\n\n if (pluginOptions.collections) {\n for (const collectionSlug in pluginOptions.collections) {\n const collection = config.collections.find(\n (collection) => collection.slug === collectionSlug,\n )\n\n if (collection) {\n collection.fields.push({\n name: 'addedByPlugin',\n type: 'text',\n admin: {\n position: 'sidebar',\n },\n })\n }\n }\n }\n\n /**\n * If the plugin is disabled, we still want to keep added collections/fields so the database schema is consistent which is important for migrations.\n * If your plugin heavily modifies the database schema, you may want to remove this property.\n */\n if (pluginOptions.disabled) {\n return config\n }\n\n if (!config.endpoints) {\n config.endpoints = []\n }\n\n if (!config.admin) {\n config.admin = {}\n }\n\n if (!config.admin.components) {\n config.admin.components = {}\n }\n\n if (!config.admin.components.beforeDashboard) {\n config.admin.components.beforeDashboard = []\n }\n\n config.admin.components.beforeDashboard.push(\n `payload-plugin/client#BeforeDashboardClient`,\n )\n config.admin.components.beforeDashboard.push(\n `payload-plugin/rsc#BeforeDashboardServer`,\n )\n\n config.endpoints.push({\n handler: customEndpointHandler,\n method: 'get',\n path: '/my-plugin-endpoint',\n })\n\n const incomingOnInit = config.onInit\n\n config.onInit = async (payload) => {\n // Ensure we are executing any existing onInit functions before running our own.\n if (incomingOnInit) {\n await incomingOnInit(payload)\n }\n\n const { totalDocs } = await payload.count({\n collection: 'plugin-collection',\n where: {\n id: {\n equals: 'seeded-by-plugin',\n },\n },\n })\n\n if (totalDocs === 0) {\n await payload.create({\n collection: 'plugin-collection',\n data: {\n id: 'seeded-by-plugin',\n },\n })\n }\n }\n\n return config\n }\n"],"names":["customEndpointHandler","payloadPlugin","pluginOptions","config","collections","push","slug","fields","name","type","collectionSlug","collection","find","admin","position","disabled","endpoints","components","beforeDashboard","handler","method","path","incomingOnInit","onInit","payload","totalDocs","count","where","id","equals","create","data"],"mappings":"AAEA,SAASA,qBAAqB,QAAQ,uCAAsC;AAU5E,OAAO,MAAMC,gBACX,CAACC,gBACD,CAACC;QACC,IAAI,CAACA,OAAOC,WAAW,EAAE;YACvBD,OAAOC,WAAW,GAAG,EAAE;QACzB;QAEAD,OAAOC,WAAW,CAACC,IAAI,CAAC;YACtBC,MAAM;YACNC,QAAQ;gBACN;oBACEC,MAAM;oBACNC,MAAM;gBACR;aACD;QACH;QAEA,IAAIP,cAAcE,WAAW,EAAE;YAC7B,IAAK,MAAMM,kBAAkBR,cAAcE,WAAW,CAAE;gBACtD,MAAMO,aAAaR,OAAOC,WAAW,CAACQ,IAAI,CACxC,CAACD,aAAeA,WAAWL,IAAI,KAAKI;gBAGtC,IAAIC,YAAY;oBACdA,WAAWJ,MAAM,CAACF,IAAI,CAAC;wBACrBG,MAAM;wBACNC,MAAM;wBACNI,OAAO;4BACLC,UAAU;wBACZ;oBACF;gBACF;YACF;QACF;QAEA;;;KAGC,GACD,IAAIZ,cAAca,QAAQ,EAAE;YAC1B,OAAOZ;QACT;QAEA,IAAI,CAACA,OAAOa,SAAS,EAAE;YACrBb,OAAOa,SAAS,GAAG,EAAE;QACvB;QAEA,IAAI,CAACb,OAAOU,KAAK,EAAE;YACjBV,OAAOU,KAAK,GAAG,CAAC;QAClB;QAEA,IAAI,CAACV,OAAOU,KAAK,CAACI,UAAU,EAAE;YAC5Bd,OAAOU,KAAK,CAACI,UAAU,GAAG,CAAC;QAC7B;QAEA,IAAI,CAACd,OAAOU,KAAK,CAACI,UAAU,CAACC,eAAe,EAAE;YAC5Cf,OAAOU,KAAK,CAACI,UAAU,CAACC,eAAe,GAAG,EAAE;QAC9C;QAEAf,OAAOU,KAAK,CAACI,UAAU,CAACC,eAAe,CAACb,IAAI,CAC1C,CAAC,2CAA2C,CAAC;QAE/CF,OAAOU,KAAK,CAACI,UAAU,CAACC,eAAe,CAACb,IAAI,CAC1C,CAAC,wCAAwC,CAAC;QAG5CF,OAAOa,SAAS,CAACX,IAAI,CAAC;YACpBc,SAASnB;YACToB,QAAQ;YACRC,MAAM;QACR;QAEA,MAAMC,iBAAiBnB,OAAOoB,MAAM;QAEpCpB,OAAOoB,MAAM,GAAG,OAAOC;YACrB,gFAAgF;YAChF,IAAIF,gBAAgB;gBAClB,MAAMA,eAAeE;YACvB;YAEA,MAAM,EAAEC,SAAS,EAAE,GAAG,MAAMD,QAAQE,KAAK,CAAC;gBACxCf,YAAY;gBACZgB,OAAO;oBACLC,IAAI;wBACFC,QAAQ;oBACV;gBACF;YACF;YAEA,IAAIJ,cAAc,GAAG;gBACnB,MAAMD,QAAQM,MAAM,CAAC;oBACnBnB,YAAY;oBACZoB,MAAM;wBACJH,IAAI;oBACN;gBACF;YACF;QACF;QAEA,OAAOzB;IACT,EAAC"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["import type { Config } from 'payload'\n\nexport type MobilizehubPluginConfig = {\n disabled?: boolean\n}\n\nexport const mobilizehubPlugin =\n (pluginOptions: MobilizehubPluginConfig) =>\n (config: Config): Config => {\n if (!config.collections) {\n config.collections = []\n }\n\n if (pluginOptions.disabled) {\n return config\n }\n\n const incomingOnInit = config.onInit\n\n config.onInit = async (payload) => {\n if (incomingOnInit) {\n await incomingOnInit(payload)\n }\n }\n\n return config\n }\n"],"names":["mobilizehubPlugin","pluginOptions","config","collections","disabled","incomingOnInit","onInit","payload"],"mappings":"AAMA,OAAO,MAAMA,oBACX,CAACC,gBACD,CAACC;QACC,IAAI,CAACA,OAAOC,WAAW,EAAE;YACvBD,OAAOC,WAAW,GAAG,EAAE;QACzB;QAEA,IAAIF,cAAcG,QAAQ,EAAE;YAC1B,OAAOF;QACT;QAEA,MAAMG,iBAAiBH,OAAOI,MAAM;QAEpCJ,OAAOI,MAAM,GAAG,OAAOC;YACrB,IAAIF,gBAAgB;gBAClB,MAAMA,eAAeE;YACvB;QACF;QAEA,OAAOL;IACT,EAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mobilizehub/payload-plugin",
3
- "version": "0.0.0",
3
+ "version": "0.0.1",
4
4
  "description": "An advocacy plugin for Payload 3.0",
5
5
  "license": "MIT",
6
6
  "private": false,
@@ -1 +0,0 @@
1
- export declare const BeforeDashboardClient: () => import("react").JSX.Element;
@@ -1,36 +0,0 @@
1
- 'use client';
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useConfig } from '@payloadcms/ui';
4
- import { useEffect, useState } from 'react';
5
- export const BeforeDashboardClient = ()=>{
6
- const { config } = useConfig();
7
- const [message, setMessage] = useState('');
8
- useEffect(()=>{
9
- const fetchMessage = async ()=>{
10
- const response = await fetch(`${config.serverURL}${config.routes.api}/my-plugin-endpoint`);
11
- const result = await response.json();
12
- setMessage(result.message);
13
- };
14
- void fetchMessage();
15
- }, [
16
- config.serverURL,
17
- config.routes.api
18
- ]);
19
- return /*#__PURE__*/ _jsxs("div", {
20
- children: [
21
- /*#__PURE__*/ _jsx("h1", {
22
- children: "Added by the plugin: Before Dashboard Client"
23
- }),
24
- /*#__PURE__*/ _jsxs("div", {
25
- children: [
26
- "Message from the endpoint:",
27
- /*#__PURE__*/ _jsx("div", {
28
- children: message || 'Loading...'
29
- })
30
- ]
31
- })
32
- ]
33
- });
34
- };
35
-
36
- //# sourceMappingURL=BeforeDashboardClient.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/BeforeDashboardClient.tsx"],"sourcesContent":["'use client'\nimport { useConfig } from '@payloadcms/ui'\nimport { useEffect, useState } from 'react'\n\nexport const BeforeDashboardClient = () => {\n const { config } = useConfig()\n\n const [message, setMessage] = useState('')\n\n useEffect(() => {\n const fetchMessage = async () => {\n const response = await fetch(`${config.serverURL}${config.routes.api}/my-plugin-endpoint`)\n const result = await response.json()\n setMessage(result.message)\n }\n\n void fetchMessage()\n }, [config.serverURL, config.routes.api])\n\n return (\n <div>\n <h1>Added by the plugin: Before Dashboard Client</h1>\n <div>\n Message from the endpoint:\n <div>{message || 'Loading...'}</div>\n </div>\n </div>\n )\n}\n"],"names":["useConfig","useEffect","useState","BeforeDashboardClient","config","message","setMessage","fetchMessage","response","fetch","serverURL","routes","api","result","json","div","h1"],"mappings":"AAAA;;AACA,SAASA,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,SAAS,EAAEC,QAAQ,QAAQ,QAAO;AAE3C,OAAO,MAAMC,wBAAwB;IACnC,MAAM,EAAEC,MAAM,EAAE,GAAGJ;IAEnB,MAAM,CAACK,SAASC,WAAW,GAAGJ,SAAS;IAEvCD,UAAU;QACR,MAAMM,eAAe;YACnB,MAAMC,WAAW,MAAMC,MAAM,GAAGL,OAAOM,SAAS,GAAGN,OAAOO,MAAM,CAACC,GAAG,CAAC,mBAAmB,CAAC;YACzF,MAAMC,SAAS,MAAML,SAASM,IAAI;YAClCR,WAAWO,OAAOR,OAAO;QAC3B;QAEA,KAAKE;IACP,GAAG;QAACH,OAAOM,SAAS;QAAEN,OAAOO,MAAM,CAACC,GAAG;KAAC;IAExC,qBACE,MAACG;;0BACC,KAACC;0BAAG;;0BACJ,MAACD;;oBAAI;kCAEH,KAACA;kCAAKV,WAAW;;;;;;AAIzB,EAAC"}
@@ -1,2 +0,0 @@
1
- import type { ServerComponentProps } from 'payload';
2
- export declare const BeforeDashboardServer: (props: ServerComponentProps) => Promise<import("react").JSX.Element>;
@@ -1,22 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import styles from './BeforeDashboardServer.module.css';
3
- export const BeforeDashboardServer = async (props)=>{
4
- const { payload } = props;
5
- const { docs } = await payload.find({
6
- collection: 'plugin-collection'
7
- });
8
- return /*#__PURE__*/ _jsxs("div", {
9
- className: styles.wrapper,
10
- children: [
11
- /*#__PURE__*/ _jsx("h1", {
12
- children: "Added by the plugin: Before Dashboard Server"
13
- }),
14
- "Docs from Local API:",
15
- docs.map((doc)=>/*#__PURE__*/ _jsx("div", {
16
- children: doc.id
17
- }, doc.id))
18
- ]
19
- });
20
- };
21
-
22
- //# sourceMappingURL=BeforeDashboardServer.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/components/BeforeDashboardServer.tsx"],"sourcesContent":["import type { ServerComponentProps } from 'payload'\n\nimport styles from './BeforeDashboardServer.module.css'\n\nexport const BeforeDashboardServer = async (props: ServerComponentProps) => {\n const { payload } = props\n\n const { docs } = await payload.find({ collection: 'plugin-collection' })\n\n return (\n <div className={styles.wrapper}>\n <h1>Added by the plugin: Before Dashboard Server</h1>\n Docs from Local API:\n {docs.map((doc) => (\n <div key={doc.id}>{doc.id}</div>\n ))}\n </div>\n )\n}\n"],"names":["styles","BeforeDashboardServer","props","payload","docs","find","collection","div","className","wrapper","h1","map","doc","id"],"mappings":";AAEA,OAAOA,YAAY,qCAAoC;AAEvD,OAAO,MAAMC,wBAAwB,OAAOC;IAC1C,MAAM,EAAEC,OAAO,EAAE,GAAGD;IAEpB,MAAM,EAAEE,IAAI,EAAE,GAAG,MAAMD,QAAQE,IAAI,CAAC;QAAEC,YAAY;IAAoB;IAEtE,qBACE,MAACC;QAAIC,WAAWR,OAAOS,OAAO;;0BAC5B,KAACC;0BAAG;;YAAiD;YAEpDN,KAAKO,GAAG,CAAC,CAACC,oBACT,KAACL;8BAAkBK,IAAIC,EAAE;mBAAfD,IAAIC,EAAE;;;AAIxB,EAAC"}
@@ -1,5 +0,0 @@
1
- .wrapper {
2
- display: flex;
3
- gap: 5px;
4
- flex-direction: column;
5
- }
@@ -1,2 +0,0 @@
1
- import type { PayloadHandler } from 'payload';
2
- export declare const customEndpointHandler: PayloadHandler;
@@ -1,7 +0,0 @@
1
- export const customEndpointHandler = ()=>{
2
- return Response.json({
3
- message: 'Hello from custom endpoint'
4
- });
5
- };
6
-
7
- //# sourceMappingURL=customEndpointHandler.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../../src/endpoints/customEndpointHandler.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\n\nexport const customEndpointHandler: PayloadHandler = () => {\n return Response.json({ message: 'Hello from custom endpoint' })\n}\n"],"names":["customEndpointHandler","Response","json","message"],"mappings":"AAEA,OAAO,MAAMA,wBAAwC;IACnD,OAAOC,SAASC,IAAI,CAAC;QAAEC,SAAS;IAA6B;AAC/D,EAAC"}