@allejo/decap-extras 0.0.3 → 0.0.4

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,4 +1,4 @@
1
- import { ComponentClass, ComponentType } from "react";
1
+ import { ComponentType } from "react";
2
2
  import { CMS, CmsConfig, CmsWidgetControlProps, CmsWidgetPreviewProps } from "decap-cms-core";
3
3
 
4
4
  //#region src/react/DecapInstance.d.ts
@@ -72,11 +72,11 @@ interface DecapInstanceProps {
72
72
  /**
73
73
  * Widget editor component used in the Decap entry form.
74
74
  */
75
- control: ComponentClass<CmsWidgetControlProps<unknown>>;
75
+ control: ComponentType<CmsWidgetControlProps>;
76
76
  /**
77
77
  * Widget preview component used in Decap preview rendering.
78
78
  */
79
- preview: ComponentType<CmsWidgetPreviewProps<unknown>>;
79
+ preview: ComponentType<CmsWidgetPreviewProps>;
80
80
  }>;
81
81
  }
82
82
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/react/DecapInstance.tsx"],"mappings":";;;;;;AAcA;;;;UAAiB,kBAAA;EA0BT;;;;;;;;;EAhBP,MAAA,EAAQ,SAAA;EAAA;;;;;;;EAQR,QAAA;EA8BA;;;;;;;EAtBA,KAAA,EAAO,MAAA,SAAe,aAAA;EA4CG;;AAAqB;AAoB/C;;;;;;;;;;;EAjDC,MAAA,IAAU,GAAA,EAAK,GAAA;EAiDc;;;;;;EA1C7B,aAAA;EA0C6B;;;;;;;AAOT;;;;EArCpB,OAAA,EAAS,MAAA;;;;IAMP,OAAA,EAAS,cAAA,CAAe,qBAAA;;;;IAIxB,OAAA,EAAS,aAAA,CAAc,qBAAA;EAAA;AAAA;;;;;;;;;;;;;;;;cAoBb,aAAA;EAAiB,MAAA;EAAA,QAAA;EAAA,MAAA;EAAA,KAAA;EAAA,aAAA;EAAA;AAAA,GAO3B,kBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../../src/react/DecapInstance.tsx"],"mappings":";;;;;;AAcA;;;;UAAiB,kBAAA;EA0BT;;;;;;;;;EAhBP,MAAA,EAAQ,SAAA;EAAA;;;;;;;EAQR,QAAA;EA8BA;;;;;;;EAtBA,KAAA,EAAO,MAAA,SAAe,aAAA;EA4CG;;AAAqB;AAoB/C;;;;;;;;;;;EAjDC,MAAA,IAAU,GAAA,EAAK,GAAA;EAiDc;;;;;;EA1C7B,aAAA;EA0C6B;;;;;;;AAOT;;;;EArCpB,OAAA,EAAS,MAAA;;;;IAMP,OAAA,EAAS,aAAA,CAAc,qBAAA;;;;IAIvB,OAAA,EAAS,aAAA,CAAc,qBAAA;EAAA;AAAA;;;;;;;;;;;;;;;;cAoBb,aAAA;EAAiB,MAAA;EAAA,QAAA;EAAA,MAAA;EAAA,KAAA;EAAA,aAAA;EAAA;AAAA,GAO3B,kBAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":["Component"],"sources":["../../src/react/DecapInstance.tsx"],"sourcesContent":["import type {\n\tCMS,\n\tCmsConfig,\n\tCmsWidgetControlProps,\n\tCmsWidgetPreviewProps,\n} from 'decap-cms-core';\nimport { ComponentClass, ComponentType, useEffect } from 'react';\n\n/**\n * Props for {@link DecapInstance}.\n *\n * This object describes everything needed to initialize the Decap CMS runtime\n * in a React/Next.js admin page.\n */\nexport interface DecapInstanceProps {\n\t/**\n\t * Decap CMS configuration object passed to `cms.init({ config })`.\n\t *\n\t * @example\n\t * const config = {\n\t * \tbackend: { name: 'git-gateway' },\n\t * \tcollections: [...],\n\t * } as const;\n\t */\n\tconfig: CmsConfig;\n\t/**\n\t * Stylesheets that should be available inside preview panes.\n\t *\n\t * This is commonly generated in Next.js via\n\t * `getCssFilesFromManifest(process.env.NODE_ENV, ['/', '/_app'])` and passed\n\t * through page props.\n\t */\n\tcssFiles: string[];\n\t/**\n\t * Map of preview template IDs to React components.\n\t *\n\t * Each component receives the serialized entry data as props\n\t * (`entry.get('data').toJSON()`). In practice, this lets you pair inferred\n\t * content types from `PropsByCollectionAndFile` with your preview templates.\n\t */\n\tpages: Record<string, ComponentType<never>>;\n\t/**\n\t * Optional callback invoked after Decap has been initialized and all\n\t * templates/widgets have been registered.\n\t *\n\t * Use this hook for custom registration that depends on the CMS instance.\n\t *\n\t * @example\n\t * onInit: (cms) => {\n\t * \tcms.registerEditorComponent({\n\t * \t\tid: 'callout',\n\t * \t\tlabel: 'Callout',\n\t * \t});\n\t * }\n\t */\n\tonInit?: (cms: CMS) => void;\n\t/**\n\t * Enables Cloudinary media library registration when set to `true`.\n\t *\n\t * Defaults to `false`. Pass this explicitly so the admin setup remains\n\t * obvious to future maintainers.\n\t */\n\tuseCloudinary?: boolean;\n\t/**\n\t * Registry of custom widgets to register with Decap.\n\t *\n\t * @example\n\t * widgets: {\n\t * \tcolor: {\n\t * \t\tcontrol: ColorControl,\n\t * \t\tpreview: ColorPreview,\n\t * \t},\n\t * }\n\t */\n\twidgets: Record<\n\t\tstring,\n\t\t{\n\t\t\t/**\n\t\t\t * Widget editor component used in the Decap entry form.\n\t\t\t */\n\t\t\tcontrol: ComponentClass<CmsWidgetControlProps<unknown>>;\n\t\t\t/**\n\t\t\t * Widget preview component used in Decap preview rendering.\n\t\t\t */\n\t\t\tpreview: ComponentType<CmsWidgetPreviewProps<unknown>>;\n\t\t}\n\t>;\n}\n\n/**\n * Initializes Decap CMS from a React component, then returns `null`.\n *\n * This component performs all setup in a `useEffect` call: it boots Decap,\n * registers preview CSS, wires preview templates, registers custom widgets,\n * optionally enables Cloudinary, and finally calls `onInit`.\n *\n * @example\n * import type { PropsByCollectionAndFile } from '@allejo/decap-extras';\n * import { DecapInstance } from '@allejo/decap-extras/react';\n *\n * import type { cmsConfig } from '@/cms/config';\n *\n * type HomePageProps = PropsByCollectionAndFile<typeof cmsConfig, 'pages', 'home'>;\n */\nexport const DecapInstance = ({\n\tconfig,\n\tcssFiles,\n\tonInit,\n\tpages,\n\tuseCloudinary = false,\n\twidgets,\n}: DecapInstanceProps) => {\n\tuseEffect(() => {\n\t\tPromise.all([\n\t\t\timport('decap-cms-app'),\n\t\t\tuseCloudinary\n\t\t\t\t? // @ts-expect-error package has no types\n\t\t\t\t\timport('decap-cms-media-library-cloudinary')\n\t\t\t\t: Promise.resolve(null),\n\t\t]).then(([cmsMod, cloudinaryMod]) => {\n\t\t\tconst cms = cmsMod.default;\n\t\t\tconst cloudinary = cloudinaryMod.default;\n\n\t\t\tcms.init({ config });\n\n\t\t\tcssFiles.forEach((css) => {\n\t\t\t\tcms.registerPreviewStyle(css);\n\t\t\t});\n\n\t\t\tObject.entries(pages).forEach(([pageId, PageComponent]) => {\n\t\t\t\tcms.registerPreviewTemplate(pageId, ({ entry }) => {\n\t\t\t\t\tconst Component = PageComponent as ComponentType<\n\t\t\t\t\t\tRecord<string, unknown>\n\t\t\t\t\t>;\n\n\t\t\t\t\treturn <Component {...entry.get('data').toJSON()} />;\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tObject.entries(widgets).forEach(([widgetId, { control, preview }]) => {\n\t\t\t\tcms.registerWidget(widgetId, control, preview);\n\t\t\t});\n\n\t\t\tif (cloudinaryMod) {\n\t\t\t\tcms.registerMediaLibrary(cloudinary);\n\t\t\t}\n\n\t\t\tonInit?.(cms);\n\t\t});\n\t}, [cssFiles]);\n\n\treturn null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwGA,MAAa,iBAAiB,EAC7B,QACA,UACA,QACA,OACA,gBAAgB,OAChB,cACyB;CACzB,gBAAgB;EACf,QAAQ,IAAI,CACX,OAAO,kBACP,gBAEE,OAAO,wCACN,QAAQ,QAAQ,IAAI,CACxB,CAAC,EAAE,MAAM,CAAC,QAAQ,mBAAmB;GACpC,MAAM,MAAM,OAAO;GACnB,MAAM,aAAa,cAAc;GAEjC,IAAI,KAAK,EAAE,OAAO,CAAC;GAEnB,SAAS,SAAS,QAAQ;IACzB,IAAI,qBAAqB,GAAG;GAC7B,CAAC;GAED,OAAO,QAAQ,KAAK,EAAE,SAAS,CAAC,QAAQ,mBAAmB;IAC1D,IAAI,wBAAwB,SAAS,EAAE,YAAY;KAKlD,OAAO,oBAACA,eAAD,EAAW,GAAI,MAAM,IAAI,MAAM,EAAE,OAAO,EAAI;IACpD,CAAC;GACF,CAAC;GAED,OAAO,QAAQ,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,eAAe;IACrE,IAAI,eAAe,UAAU,SAAS,OAAO;GAC9C,CAAC;GAED,IAAI,eACH,IAAI,qBAAqB,UAAU;GAGpC,SAAS,GAAG;EACb,CAAC;CACF,GAAG,CAAC,QAAQ,CAAC;CAEb,OAAO;AACR"}
1
+ {"version":3,"file":"index.mjs","names":["Component"],"sources":["../../src/react/DecapInstance.tsx"],"sourcesContent":["import type {\n\tCMS,\n\tCmsConfig,\n\tCmsWidgetControlProps,\n\tCmsWidgetPreviewProps,\n} from 'decap-cms-core';\nimport { ComponentType, useEffect } from 'react';\n\n/**\n * Props for {@link DecapInstance}.\n *\n * This object describes everything needed to initialize the Decap CMS runtime\n * in a React/Next.js admin page.\n */\nexport interface DecapInstanceProps {\n\t/**\n\t * Decap CMS configuration object passed to `cms.init({ config })`.\n\t *\n\t * @example\n\t * const config = {\n\t * \tbackend: { name: 'git-gateway' },\n\t * \tcollections: [...],\n\t * } as const;\n\t */\n\tconfig: CmsConfig;\n\t/**\n\t * Stylesheets that should be available inside preview panes.\n\t *\n\t * This is commonly generated in Next.js via\n\t * `getCssFilesFromManifest(process.env.NODE_ENV, ['/', '/_app'])` and passed\n\t * through page props.\n\t */\n\tcssFiles: string[];\n\t/**\n\t * Map of preview template IDs to React components.\n\t *\n\t * Each component receives the serialized entry data as props\n\t * (`entry.get('data').toJSON()`). In practice, this lets you pair inferred\n\t * content types from `PropsByCollectionAndFile` with your preview templates.\n\t */\n\tpages: Record<string, ComponentType<never>>;\n\t/**\n\t * Optional callback invoked after Decap has been initialized and all\n\t * templates/widgets have been registered.\n\t *\n\t * Use this hook for custom registration that depends on the CMS instance.\n\t *\n\t * @example\n\t * onInit: (cms) => {\n\t * \tcms.registerEditorComponent({\n\t * \t\tid: 'callout',\n\t * \t\tlabel: 'Callout',\n\t * \t});\n\t * }\n\t */\n\tonInit?: (cms: CMS) => void;\n\t/**\n\t * Enables Cloudinary media library registration when set to `true`.\n\t *\n\t * Defaults to `false`. Pass this explicitly so the admin setup remains\n\t * obvious to future maintainers.\n\t */\n\tuseCloudinary?: boolean;\n\t/**\n\t * Registry of custom widgets to register with Decap.\n\t *\n\t * @example\n\t * widgets: {\n\t * \tcolor: {\n\t * \t\tcontrol: ColorControl,\n\t * \t\tpreview: ColorPreview,\n\t * \t},\n\t * }\n\t */\n\twidgets: Record<\n\t\tstring,\n\t\t{\n\t\t\t/**\n\t\t\t * Widget editor component used in the Decap entry form.\n\t\t\t */\n\t\t\tcontrol: ComponentType<CmsWidgetControlProps>;\n\t\t\t/**\n\t\t\t * Widget preview component used in Decap preview rendering.\n\t\t\t */\n\t\t\tpreview: ComponentType<CmsWidgetPreviewProps>;\n\t\t}\n\t>;\n}\n\n/**\n * Initializes Decap CMS from a React component, then returns `null`.\n *\n * This component performs all setup in a `useEffect` call: it boots Decap,\n * registers preview CSS, wires preview templates, registers custom widgets,\n * optionally enables Cloudinary, and finally calls `onInit`.\n *\n * @example\n * import type { PropsByCollectionAndFile } from '@allejo/decap-extras';\n * import { DecapInstance } from '@allejo/decap-extras/react';\n *\n * import type { cmsConfig } from '@/cms/config';\n *\n * type HomePageProps = PropsByCollectionAndFile<typeof cmsConfig, 'pages', 'home'>;\n */\nexport const DecapInstance = ({\n\tconfig,\n\tcssFiles,\n\tonInit,\n\tpages,\n\tuseCloudinary = false,\n\twidgets,\n}: DecapInstanceProps) => {\n\tuseEffect(() => {\n\t\tPromise.all([\n\t\t\timport('decap-cms-app'),\n\t\t\tuseCloudinary\n\t\t\t\t? // @ts-expect-error package has no types\n\t\t\t\t\timport('decap-cms-media-library-cloudinary')\n\t\t\t\t: Promise.resolve(null),\n\t\t]).then(([cmsMod, cloudinaryMod]) => {\n\t\t\tconst cms = cmsMod.default;\n\t\t\tconst cloudinary = cloudinaryMod.default;\n\n\t\t\tcms.init({ config });\n\n\t\t\tcssFiles.forEach((css) => {\n\t\t\t\tcms.registerPreviewStyle(css);\n\t\t\t});\n\n\t\t\tObject.entries(pages).forEach(([pageId, PageComponent]) => {\n\t\t\t\tcms.registerPreviewTemplate(pageId, ({ entry }) => {\n\t\t\t\t\tconst Component = PageComponent as ComponentType<\n\t\t\t\t\t\tRecord<string, unknown>\n\t\t\t\t\t>;\n\n\t\t\t\t\treturn <Component {...entry.get('data').toJSON()} />;\n\t\t\t\t});\n\t\t\t});\n\n\t\t\tObject.entries(widgets).forEach(([widgetId, { control, preview }]) => {\n\t\t\t\tcms.registerWidget(widgetId, control, preview);\n\t\t\t});\n\n\t\t\tif (cloudinaryMod) {\n\t\t\t\tcms.registerMediaLibrary(cloudinary);\n\t\t\t}\n\n\t\t\tonInit?.(cms);\n\t\t});\n\t}, [cssFiles]);\n\n\treturn null;\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAwGA,MAAa,iBAAiB,EAC7B,QACA,UACA,QACA,OACA,gBAAgB,OAChB,cACyB;CACzB,gBAAgB;EACf,QAAQ,IAAI,CACX,OAAO,kBACP,gBAEE,OAAO,wCACN,QAAQ,QAAQ,IAAI,CACxB,CAAC,EAAE,MAAM,CAAC,QAAQ,mBAAmB;GACpC,MAAM,MAAM,OAAO;GACnB,MAAM,aAAa,cAAc;GAEjC,IAAI,KAAK,EAAE,OAAO,CAAC;GAEnB,SAAS,SAAS,QAAQ;IACzB,IAAI,qBAAqB,GAAG;GAC7B,CAAC;GAED,OAAO,QAAQ,KAAK,EAAE,SAAS,CAAC,QAAQ,mBAAmB;IAC1D,IAAI,wBAAwB,SAAS,EAAE,YAAY;KAKlD,OAAO,oBAACA,eAAD,EAAW,GAAI,MAAM,IAAI,MAAM,EAAE,OAAO,EAAI;IACpD,CAAC;GACF,CAAC;GAED,OAAO,QAAQ,OAAO,EAAE,SAAS,CAAC,UAAU,EAAE,SAAS,eAAe;IACrE,IAAI,eAAe,UAAU,SAAS,OAAO;GAC9C,CAAC;GAED,IAAI,eACH,IAAI,qBAAqB,UAAU;GAGpC,SAAS,GAAG;EACb,CAAC;CACF,GAAG,CAAC,QAAQ,CAAC;CAEb,OAAO;AACR"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@allejo/decap-extras",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A TypeScript utility library for Decap CMS with utility types to derive types from Decap CMS configuration files.",
5
5
  "keywords": [
6
6
  "decapcms"