@krantho/ui-react 0.0.0-stage → 1.0.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/LICENSE +21 -0
- package/dist/components/client/CMSImage.d.ts +4 -0
- package/dist/components/client/CMSImage.d.ts.map +1 -0
- package/dist/components/client/CMSImage.js +23 -0
- package/dist/components/client/CMSImage.js.map +1 -0
- package/dist/components/client/CMSMarkdown.d.ts +4 -0
- package/dist/components/client/CMSMarkdown.d.ts.map +1 -0
- package/dist/components/client/CMSMarkdown.js +15 -0
- package/dist/components/client/CMSMarkdown.js.map +1 -0
- package/dist/components/client/CMSText.d.ts +4 -0
- package/dist/components/client/CMSText.d.ts.map +1 -0
- package/dist/components/client/CMSText.js +15 -0
- package/dist/components/client/CMSText.js.map +1 -0
- package/dist/components/server/CMSImageServer.d.ts +4 -0
- package/dist/components/server/CMSImageServer.d.ts.map +1 -0
- package/dist/components/server/CMSImageServer.js +27 -0
- package/dist/components/server/CMSImageServer.js.map +1 -0
- package/dist/components/server/CMSMarkdownServer.d.ts +4 -0
- package/dist/components/server/CMSMarkdownServer.d.ts.map +1 -0
- package/dist/components/server/CMSMarkdownServer.js +24 -0
- package/dist/components/server/CMSMarkdownServer.js.map +1 -0
- package/dist/components/server/CMSTextServer.d.ts +4 -0
- package/dist/components/server/CMSTextServer.d.ts.map +1 -0
- package/dist/components/server/CMSTextServer.js +22 -0
- package/dist/components/server/CMSTextServer.js.map +1 -0
- package/dist/components/utils.d.ts +4 -0
- package/dist/components/utils.d.ts.map +1 -0
- package/dist/components/utils.js +18 -0
- package/dist/components/utils.js.map +1 -0
- package/dist/context.d.ts +4 -0
- package/dist/context.d.ts.map +1 -0
- package/dist/context.js +12 -0
- package/dist/context.js.map +1 -0
- package/dist/hooks/content-context.d.ts +10 -0
- package/dist/hooks/content-context.d.ts.map +1 -0
- package/dist/hooks/content-context.js +12 -0
- package/dist/hooks/content-context.js.map +1 -0
- package/dist/hooks/use-cms-config.d.ts +3 -0
- package/dist/hooks/use-cms-config.d.ts.map +1 -0
- package/dist/hooks/use-cms-config.js +12 -0
- package/dist/hooks/use-cms-config.js.map +1 -0
- package/dist/hooks/use-content.d.ts +3 -0
- package/dist/hooks/use-content.d.ts.map +1 -0
- package/dist/hooks/use-content.js +79 -0
- package/dist/hooks/use-content.js.map +1 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/provider.d.ts +9 -0
- package/dist/provider.d.ts.map +1 -0
- package/dist/provider.js +25 -0
- package/dist/provider.js.map +1 -0
- package/dist/server/cms-context.d.ts +19 -0
- package/dist/server/cms-context.d.ts.map +1 -0
- package/dist/server/cms-context.js +45 -0
- package/dist/server/cms-context.js.map +1 -0
- package/dist/server/content-loader.d.ts +26 -0
- package/dist/server/content-loader.d.ts.map +1 -0
- package/dist/server/content-loader.js +110 -0
- package/dist/server/content-loader.js.map +1 -0
- package/dist/server/seo-jsonld.d.ts +27 -0
- package/dist/server/seo-jsonld.d.ts.map +1 -0
- package/dist/server/seo-jsonld.js +45 -0
- package/dist/server/seo-jsonld.js.map +1 -0
- package/dist/server/seo-resolver.d.ts +32 -0
- package/dist/server/seo-resolver.d.ts.map +1 -0
- package/dist/server/seo-resolver.js +84 -0
- package/dist/server/seo-resolver.js.map +1 -0
- package/dist/server.d.ts +11 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +12 -0
- package/dist/server.js.map +1 -0
- package/dist/types.d.ts +87 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +45 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Descoped
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSImage.d.ts","sourceRoot":"","sources":["../../../src/components/client/CMSImage.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAGhD,wBAAgB,QAAQ,CAAC,EACvB,IAAI,EACJ,KAAK,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAW,EACX,SAAS,GACV,EAAE,aAAa,GAAG,KAAK,CAAC,YAAY,CAiBpC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { kranthoField } from '@krantho/core/marks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useContent } from '../../hooks/use-content';
|
|
5
|
+
import { semanticClasses } from '../utils';
|
|
6
|
+
export function CMSImage({ slug, field, alt, width, height, lazy = true, className, }) {
|
|
7
|
+
const { fields, document } = useContent(slug);
|
|
8
|
+
const src = String(fields[field] ?? '');
|
|
9
|
+
// Prefer the explicit `alt` prop; otherwise look for a sibling `${field}-alt`
|
|
10
|
+
// CMS field. Result is always a string (empty string for missing alt is
|
|
11
|
+
// semantically different from undefined and signals "decorative image").
|
|
12
|
+
const resolvedAlt = alt || String(fields[`${field}-alt`] ?? '');
|
|
13
|
+
return React.createElement('img', {
|
|
14
|
+
src,
|
|
15
|
+
alt: resolvedAlt,
|
|
16
|
+
width,
|
|
17
|
+
height,
|
|
18
|
+
loading: lazy ? 'lazy' : undefined,
|
|
19
|
+
className: semanticClasses('cms-image', {}, className),
|
|
20
|
+
...kranthoField(document, field),
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=CMSImage.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSImage.js","sourceRoot":"","sources":["../../../src/components/client/CMSImage.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,MAAM,UAAU,QAAQ,CAAC,EACvB,IAAI,EACJ,KAAK,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAI,GAAG,IAAI,EACX,SAAS,GACK;IACd,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,GAAG,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;IACvC,8EAA8E;IAC9E,wEAAwE;IACxE,yEAAyE;IACzE,MAAM,WAAW,GAAG,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;IAE/D,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE;QAChC,GAAG;QACH,GAAG,EAAE,WAAW;QAChB,KAAK;QACL,MAAM;QACN,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;QAClC,SAAS,EAAE,eAAe,CAAC,WAAW,EAAE,EAAE,EAAE,SAAS,CAAC;QACtD,GAAG,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC;KACjC,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSMarkdown.d.ts","sourceRoot":"","sources":["../../../src/components/client/CMSMarkdown.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAA;AAGnD,wBAAgB,WAAW,CAAC,EAC1B,IAAI,EACJ,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,GACV,EAAE,gBAAgB,GAAG,KAAK,CAAC,YAAY,CASvC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { kranthoSection, markBodySections } from '@krantho/core/marks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useContent } from '../../hooks/use-content';
|
|
5
|
+
import { semanticClasses } from '../utils';
|
|
6
|
+
export function CMSMarkdown({ slug, section, variant, color, align, className, }) {
|
|
7
|
+
const { html, sections, content, document } = useContent(slug);
|
|
8
|
+
const rendered = section ? (sections[section] ?? '') : markBodySections(html, content, document);
|
|
9
|
+
return React.createElement('div', {
|
|
10
|
+
className: semanticClasses('cms-markdown', { variant, color, align }, className),
|
|
11
|
+
...(section ? kranthoSection(document, section) : {}),
|
|
12
|
+
dangerouslySetInnerHTML: { __html: rendered },
|
|
13
|
+
});
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=CMSMarkdown.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSMarkdown.js","sourceRoot":"","sources":["../../../src/components/client/CMSMarkdown.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AACtE,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,MAAM,UAAU,WAAW,CAAC,EAC1B,IAAI,EACJ,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,GACQ;IACjB,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9D,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,gBAAgB,CAAC,IAAI,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAA;IAEhG,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE;QAChC,SAAS,EAAE,eAAe,CAAC,cAAc,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,SAAS,CAAC;QAChF,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,cAAc,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QACrD,uBAAuB,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE;KAC9C,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSText.d.ts","sourceRoot":"","sources":["../../../src/components/client/CMSText.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAA;AAG/C,wBAAgB,OAAO,CAAC,EACtB,IAAI,EACJ,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAa,EACb,SAAS,EACT,SAAS,GACV,EAAE,YAAY,GAAG,KAAK,CAAC,YAAY,CAanC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { kranthoField } from '@krantho/core/marks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { useContent } from '../../hooks/use-content';
|
|
5
|
+
import { semanticClasses, variantToTag } from '../utils';
|
|
6
|
+
export function CMSText({ slug, field, variant, color, align, weight, size, fallback = '', className, component, }) {
|
|
7
|
+
const { fields, document } = useContent(slug);
|
|
8
|
+
const text = String(fields[field] ?? fallback);
|
|
9
|
+
const Tag = (component || variantToTag(variant));
|
|
10
|
+
return React.createElement(Tag, {
|
|
11
|
+
className: semanticClasses('cms-text', { variant, color, align, weight, size }, className),
|
|
12
|
+
...kranthoField(document, field),
|
|
13
|
+
}, text);
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=CMSText.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSText.js","sourceRoot":"","sources":["../../../src/components/client/CMSText.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAA;AAEpD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAExD,MAAM,UAAU,OAAO,CAAC,EACtB,IAAI,EACJ,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAQ,GAAG,EAAE,EACb,SAAS,EACT,SAAS,GACI;IACb,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,UAAU,CAAC,IAAI,CAAC,CAAA;IAC7C,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAA;IAC9C,MAAM,GAAG,GAAG,CAAC,SAAS,IAAI,YAAY,CAAC,OAAO,CAAC,CAAsC,CAAA;IAErF,OAAO,KAAK,CAAC,aAAa,CACxB,GAAG,EACH;QACE,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,SAAS,CAAC;QAC1F,GAAG,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC;KACjC,EACD,IAAI,CACL,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CMSImageServerProps } from '../../types';
|
|
3
|
+
export declare function CMSImageServer({ collection, slug, locale, field, alt, width, height, lazy, className, }: CMSImageServerProps): Promise<React.ReactElement>;
|
|
4
|
+
//# sourceMappingURL=CMSImageServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSImageServer.d.ts","sourceRoot":"","sources":["../../../src/components/server/CMSImageServer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAGtD,wBAAsB,cAAc,CAAC,EACnC,UAAU,EACV,IAAI,EACJ,MAAM,EACN,KAAK,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAY,EACZ,SAAS,GACV,EAAE,mBAAmB,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAoBnD"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { kranthoField } from '@krantho/core/marks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { getCMSContent } from '../../server/cms-context';
|
|
5
|
+
import { semanticClasses } from '../utils';
|
|
6
|
+
export async function CMSImageServer({ collection, slug, locale, field, alt, width, height, lazy = false, className, }) {
|
|
7
|
+
try {
|
|
8
|
+
const content = await getCMSContent(collection, slug, locale ? { locale } : undefined);
|
|
9
|
+
const src = String(content.fields[field] ?? '');
|
|
10
|
+
const altText = alt || String(content.fields[`${field}-alt`] ?? '');
|
|
11
|
+
return React.createElement('img', {
|
|
12
|
+
src,
|
|
13
|
+
alt: altText,
|
|
14
|
+
width,
|
|
15
|
+
height,
|
|
16
|
+
loading: lazy ? 'lazy' : undefined,
|
|
17
|
+
className: semanticClasses('cms-image', {}, className),
|
|
18
|
+
...kranthoField(content, field),
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
if (process.env.NODE_ENV !== 'production')
|
|
23
|
+
console.error(`[CMSImageServer] ${collection}/${slug} field="${field}"`, error);
|
|
24
|
+
return _jsx("span", {});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=CMSImageServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSImageServer.js","sourceRoot":"","sources":["../../../src/components/server/CMSImageServer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAA;AAE1C,MAAM,CAAC,KAAK,UAAU,cAAc,CAAC,EACnC,UAAU,EACV,IAAI,EACJ,MAAM,EACN,KAAK,EACL,GAAG,EACH,KAAK,EACL,MAAM,EACN,IAAI,GAAG,KAAK,EACZ,SAAS,GACW;IACpB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QACtF,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;QAC/C,MAAM,OAAO,GAAG,GAAG,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,KAAK,MAAM,CAAC,IAAI,EAAE,CAAC,CAAA;QAEnE,OAAO,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE;YAChC,GAAG;YACH,GAAG,EAAE,OAAO;YACZ,KAAK;YACL,MAAM;YACN,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS;YAClC,SAAS,EAAE,eAAe,CAAC,WAAW,EAAE,EAAE,EAAE,SAAS,CAAC;YACtD,GAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACvC,OAAO,CAAC,KAAK,CAAC,oBAAoB,UAAU,IAAI,IAAI,WAAW,KAAK,GAAG,EAAE,KAAK,CAAC,CAAA;QACjF,OAAO,gBAAQ,CAAA;IACjB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CMSMarkdownServerProps } from '../../types';
|
|
3
|
+
export declare function CMSMarkdownServer({ collection, slug, locale, section, variant, color, align, className, }: CMSMarkdownServerProps): Promise<React.ReactElement>;
|
|
4
|
+
//# sourceMappingURL=CMSMarkdownServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSMarkdownServer.d.ts","sourceRoot":"","sources":["../../../src/components/server/CMSMarkdownServer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,aAAa,CAAA;AAGzD,wBAAsB,iBAAiB,CAAC,EACtC,UAAU,EACV,IAAI,EACJ,MAAM,EACN,OAAO,EACP,OAAO,EACP,KAAK,EACL,KAAK,EACL,SAAS,GACV,EAAE,sBAAsB,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAiBtD"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { kranthoSection, markBodySections } from '@krantho/core/marks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { getCMSContent } from '../../server/cms-context';
|
|
5
|
+
import { semanticClasses } from '../utils';
|
|
6
|
+
export async function CMSMarkdownServer({ collection, slug, locale, section, variant, color, align, className, }) {
|
|
7
|
+
try {
|
|
8
|
+
const content = await getCMSContent(collection, slug, locale ? { locale } : undefined);
|
|
9
|
+
const html = section
|
|
10
|
+
? (content.sections[section] ?? '')
|
|
11
|
+
: markBodySections(content.html, content.rawContent, content);
|
|
12
|
+
return React.createElement('div', {
|
|
13
|
+
className: semanticClasses('cms-markdown', { variant, color, align }, className),
|
|
14
|
+
...(section ? kranthoSection(content, section) : {}),
|
|
15
|
+
dangerouslySetInnerHTML: { __html: html },
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (error) {
|
|
19
|
+
if (process.env.NODE_ENV !== 'production')
|
|
20
|
+
console.error(`[CMSMarkdownServer] ${collection}/${slug}`, error);
|
|
21
|
+
return _jsx("div", {});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=CMSMarkdownServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"C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CAAC,uBAAuB,UAAU,IAAI,IAAI,EAAE,EAAE,KAAK,CAAC,CAAA;QACnE,OAAO,eAAO,CAAA;IAChB,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import type { CMSTextServerProps } from '../../types';
|
|
3
|
+
export declare function CMSTextServer({ collection, slug, locale, field, variant, color, align, weight, size, fallback, className, component, }: CMSTextServerProps): Promise<React.ReactElement>;
|
|
4
|
+
//# sourceMappingURL=CMSTextServer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSTextServer.d.ts","sourceRoot":"","sources":["../../../src/components/server/CMSTextServer.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAA;AAEzB,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAGrD,wBAAsB,aAAa,CAAC,EAClC,UAAU,EACV,IAAI,EACJ,MAAM,EACN,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAa,EACb,SAAS,EACT,SAAS,GACV,EAAE,kBAAkB,GAAG,OAAO,CAAC,KAAK,CAAC,YAAY,CAAC,CAmBlD"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { kranthoField } from '@krantho/core/marks';
|
|
3
|
+
import React from 'react';
|
|
4
|
+
import { getCMSContent } from '../../server/cms-context';
|
|
5
|
+
import { semanticClasses, variantToTag } from '../utils';
|
|
6
|
+
export async function CMSTextServer({ collection, slug, locale, field, variant, color, align, weight, size, fallback = '', className, component, }) {
|
|
7
|
+
try {
|
|
8
|
+
const content = await getCMSContent(collection, slug, locale ? { locale } : undefined);
|
|
9
|
+
const text = String(content.fields[field] ?? fallback);
|
|
10
|
+
const Tag = (component || variantToTag(variant));
|
|
11
|
+
return React.createElement(Tag, {
|
|
12
|
+
className: semanticClasses('cms-text', { variant, color, align, weight, size }, className),
|
|
13
|
+
...kranthoField(content, field),
|
|
14
|
+
}, text);
|
|
15
|
+
}
|
|
16
|
+
catch (error) {
|
|
17
|
+
if (process.env.NODE_ENV !== 'production')
|
|
18
|
+
console.error(`[CMSTextServer] ${collection}/${slug} field="${field}"`, error);
|
|
19
|
+
return _jsx("span", { children: fallback });
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=CMSTextServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"CMSTextServer.js","sourceRoot":"","sources":["../../../src/components/server/CMSTextServer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAA;AAClD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,0BAA0B,CAAA;AAExD,OAAO,EAAE,eAAe,EAAE,YAAY,EAAE,MAAM,UAAU,CAAA;AAExD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,EAClC,UAAU,EACV,IAAI,EACJ,MAAM,EACN,KAAK,EACL,OAAO,EACP,KAAK,EACL,KAAK,EACL,MAAM,EACN,IAAI,EACJ,QAAQ,GAAG,EAAE,EACb,SAAS,EACT,SAAS,GACU;IACnB,IAAI,CAAC;QACH,MAAM,OAAO,GAAG,MAAM,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAA;QACtF,MAAM,IAAI,GAAG,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,QAAQ,CAAC,CAAA;QACtD,MAAM,GAAG,GAAG,CAAC,SAAS,IAAI,YAAY,CAAC,OAAO,CAAC,CAAsC,CAAA;QAErF,OAAO,KAAK,CAAC,aAAa,CACxB,GAAG,EACH;YACE,SAAS,EAAE,eAAe,CAAC,UAAU,EAAE,EAAE,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,EAAE,SAAS,CAAC;YAC1F,GAAG,YAAY,CAAC,OAAO,EAAE,KAAK,CAAC;SAChC,EACD,IAAI,CACL,CAAA;IACH,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;YACvC,OAAO,CAAC,KAAK,CAAC,mBAAmB,UAAU,IAAI,IAAI,WAAW,KAAK,GAAG,EAAE,KAAK,CAAC,CAAA;QAChF,OAAO,yBAAO,QAAQ,GAAQ,CAAA;IAChC,CAAC;AACH,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/components/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAElD,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,CAAC,aAAa,CAAC,EAC7B,SAAS,CAAC,EAAE,MAAM,GACjB,MAAM,CASR"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export { variantToTag } from '@krantho/core';
|
|
2
|
+
export function semanticClasses(base, style, className) {
|
|
3
|
+
const classes = [base];
|
|
4
|
+
if (style.variant)
|
|
5
|
+
classes.push(`cms-variant-${style.variant}`);
|
|
6
|
+
if (style.color)
|
|
7
|
+
classes.push(`cms-color-${style.color}`);
|
|
8
|
+
if (style.align)
|
|
9
|
+
classes.push(`cms-align-${style.align}`);
|
|
10
|
+
if (style.weight)
|
|
11
|
+
classes.push(`cms-weight-${style.weight}`);
|
|
12
|
+
if (style.size)
|
|
13
|
+
classes.push(`cms-size-${style.size}`);
|
|
14
|
+
if (className)
|
|
15
|
+
classes.push(className);
|
|
16
|
+
return classes.join(' ');
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/components/utils.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,eAAe,CAAA;AAE5C,MAAM,UAAU,eAAe,CAC7B,IAAY,EACZ,KAA6B,EAC7B,SAAkB;IAElB,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,CAAA;IACtB,IAAI,KAAK,CAAC,OAAO;QAAE,OAAO,CAAC,IAAI,CAAC,eAAe,KAAK,CAAC,OAAO,EAAE,CAAC,CAAA;IAC/D,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;IACzD,IAAI,KAAK,CAAC,KAAK;QAAE,OAAO,CAAC,IAAI,CAAC,aAAa,KAAK,CAAC,KAAK,EAAE,CAAC,CAAA;IACzD,IAAI,KAAK,CAAC,MAAM;QAAE,OAAO,CAAC,IAAI,CAAC,cAAc,KAAK,CAAC,MAAM,EAAE,CAAC,CAAA;IAC5D,IAAI,KAAK,CAAC,IAAI;QAAE,OAAO,CAAC,IAAI,CAAC,YAAY,KAAK,CAAC,IAAI,EAAE,CAAC,CAAA;IACtD,IAAI,SAAS;QAAE,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,CAAA;IACtC,OAAO,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,CAAA;AAC1B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,eAAO,MAAM,UAAU,2CAAwC,CAAA;AAE/D,eAAO,MAAM,aAAa,EAAE,SAO3B,CAAA"}
|
package/dist/context.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { createContext } from 'react';
|
|
3
|
+
export const CMSContext = createContext(null);
|
|
4
|
+
export const defaultConfig = {
|
|
5
|
+
contentPath: '/content',
|
|
6
|
+
assetsPath: '/assets',
|
|
7
|
+
imagesPath: '/images',
|
|
8
|
+
autoReload: process.env.NODE_ENV === 'development',
|
|
9
|
+
errorBoundary: true,
|
|
10
|
+
cacheContent: process.env.NODE_ENV === 'production',
|
|
11
|
+
};
|
|
12
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AAGrC,MAAM,CAAC,MAAM,UAAU,GAAG,aAAa,CAAmB,IAAI,CAAC,CAAA;AAE/D,MAAM,CAAC,MAAM,aAAa,GAAc;IACtC,WAAW,EAAE,UAAU;IACvB,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,SAAS;IACrB,UAAU,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa;IAClD,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,YAAY;CACpD,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { ContentData } from '@krantho/core';
|
|
2
|
+
import React, { type ReactNode } from 'react';
|
|
3
|
+
type ContentCache = Record<string, ContentData>;
|
|
4
|
+
export declare function CMSContentProvider({ data, children, }: {
|
|
5
|
+
data: ContentCache;
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
}): React.ReactElement;
|
|
8
|
+
export declare function usePreloadedContent(slug: string): ContentData | null;
|
|
9
|
+
export {};
|
|
10
|
+
//# sourceMappingURL=content-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-context.d.ts","sourceRoot":"","sources":["../../src/hooks/content-context.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,KAAK,EAAE,EAAiB,KAAK,SAAS,EAAc,MAAM,OAAO,CAAA;AAExE,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAI/C,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,YAAY,CAAA;IAClB,QAAQ,EAAE,SAAS,CAAA;CACpB,GAAG,KAAK,CAAC,YAAY,CAErB;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,GAAG,IAAI,CAGpE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import React, { createContext, useContext } from 'react';
|
|
4
|
+
const CMSContentContext = createContext({});
|
|
5
|
+
export function CMSContentProvider({ data, children, }) {
|
|
6
|
+
return _jsx(CMSContentContext.Provider, { value: data, children: children });
|
|
7
|
+
}
|
|
8
|
+
export function usePreloadedContent(slug) {
|
|
9
|
+
const cache = useContext(CMSContentContext);
|
|
10
|
+
return cache[slug] || null;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=content-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-context.js","sourceRoot":"","sources":["../../src/hooks/content-context.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,KAAK,EAAE,EAAE,aAAa,EAAkB,UAAU,EAAE,MAAM,OAAO,CAAA;AAIxE,MAAM,iBAAiB,GAAG,aAAa,CAAe,EAAE,CAAC,CAAA;AAEzD,MAAM,UAAU,kBAAkB,CAAC,EACjC,IAAI,EACJ,QAAQ,GAIT;IACC,OAAO,KAAC,iBAAiB,CAAC,QAAQ,IAAC,KAAK,EAAE,IAAI,YAAG,QAAQ,GAA8B,CAAA;AACzF,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,IAAY;IAC9C,MAAM,KAAK,GAAG,UAAU,CAAC,iBAAiB,CAAC,CAAA;IAC3C,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,IAAI,CAAA;AAC5B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cms-config.d.ts","sourceRoot":"","sources":["../../src/hooks/use-cms-config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAG5C,wBAAgB,YAAY,IAAI,SAAS,CAMxC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { useContext } from 'react';
|
|
3
|
+
import { CMSContext } from '../context.js';
|
|
4
|
+
import { ConfigurationError } from '../types.js';
|
|
5
|
+
export function useCMSConfig() {
|
|
6
|
+
const config = useContext(CMSContext);
|
|
7
|
+
if (!config) {
|
|
8
|
+
throw new ConfigurationError('useCMSConfig must be used within CMSProvider', 'React Context');
|
|
9
|
+
}
|
|
10
|
+
return config;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=use-cms-config.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-cms-config.js","sourceRoot":"","sources":["../../src/hooks/use-cms-config.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AAEZ,OAAO,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAA;AAE1C,OAAO,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAEhD,MAAM,UAAU,YAAY;IAC1B,MAAM,MAAM,GAAG,UAAU,CAAC,UAAU,CAAC,CAAA;IACrC,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,MAAM,IAAI,kBAAkB,CAAC,8CAA8C,EAAE,eAAe,CAAC,CAAA;IAC/F,CAAC;IACD,OAAO,MAAM,CAAA;AACf,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-content.d.ts","sourceRoot":"","sources":["../../src/hooks/use-content.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAiC,MAAM,eAAe,CAAA;AAuC/E,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,WAAW,CAwDpD"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { ClientFetchLoader, ContentEngineFactory, NetworkError } from '@krantho/core';
|
|
3
|
+
import { useEffect, useState } from 'react';
|
|
4
|
+
import { usePreloadedContent } from './content-context.js';
|
|
5
|
+
import { useCMSConfig } from './use-cms-config.js';
|
|
6
|
+
let clientContentEngine = null;
|
|
7
|
+
let clientContentPath = null;
|
|
8
|
+
function getClientContentEngine(contentPath) {
|
|
9
|
+
if (!clientContentEngine || clientContentPath !== contentPath) {
|
|
10
|
+
clientContentPath = contentPath;
|
|
11
|
+
const fetchLoader = new ClientFetchLoader(contentPath);
|
|
12
|
+
clientContentEngine = ContentEngineFactory.create(fetchLoader, {
|
|
13
|
+
contentPath,
|
|
14
|
+
cacheEnabled: true,
|
|
15
|
+
cacheTTL: 5 * 60 * 1000,
|
|
16
|
+
maxCacheSize: 50,
|
|
17
|
+
enableAtNotation: true,
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
return clientContentEngine;
|
|
21
|
+
}
|
|
22
|
+
function emptyContentData(loading, error = null) {
|
|
23
|
+
return { fields: {}, content: '', html: '', sections: {}, loading, error };
|
|
24
|
+
}
|
|
25
|
+
function contentResultToContentData(coreResult) {
|
|
26
|
+
return {
|
|
27
|
+
fields: coreResult.fields,
|
|
28
|
+
content: coreResult.content,
|
|
29
|
+
html: coreResult.html,
|
|
30
|
+
sections: coreResult.sections,
|
|
31
|
+
loading: coreResult.loading,
|
|
32
|
+
error: coreResult.error ? new NetworkError(coreResult.error.message, 500) : null,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function useContent(slug) {
|
|
36
|
+
const config = useCMSConfig();
|
|
37
|
+
const preloaded = usePreloadedContent(slug);
|
|
38
|
+
const [data, setData] = useState(() => {
|
|
39
|
+
if (preloaded)
|
|
40
|
+
return preloaded;
|
|
41
|
+
return emptyContentData(true);
|
|
42
|
+
});
|
|
43
|
+
// Re-run when slug or contentPath changes. `preloaded` is in the dependency
|
|
44
|
+
// array so that if a parent replaces the preloaded map at runtime (rare but
|
|
45
|
+
// possible in SSR hydration edge cases), the effect re-evaluates and skips
|
|
46
|
+
// the network fetch. The `if (preloaded) return` guard is correct for both
|
|
47
|
+
// the initial render and subsequent re-runs.
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (preloaded)
|
|
50
|
+
return;
|
|
51
|
+
let cancelled = false;
|
|
52
|
+
async function loadContent() {
|
|
53
|
+
try {
|
|
54
|
+
if (!cancelled) {
|
|
55
|
+
setData((prev) => ({ ...prev, loading: true, error: null }));
|
|
56
|
+
}
|
|
57
|
+
const engine = getClientContentEngine(`${config.contentPath}/pages`);
|
|
58
|
+
const coreResult = await engine.loadContent(slug);
|
|
59
|
+
if (cancelled)
|
|
60
|
+
return;
|
|
61
|
+
const adaptedData = contentResultToContentData(coreResult);
|
|
62
|
+
if (!cancelled) {
|
|
63
|
+
setData(adaptedData);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
if (!cancelled) {
|
|
68
|
+
setData(emptyContentData(false, new NetworkError(error instanceof Error ? error.message : 'Unexpected error occurred')));
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
void loadContent();
|
|
73
|
+
return () => {
|
|
74
|
+
cancelled = true;
|
|
75
|
+
};
|
|
76
|
+
}, [slug, config.contentPath, preloaded]);
|
|
77
|
+
return preloaded || data;
|
|
78
|
+
}
|
|
79
|
+
//# sourceMappingURL=use-content.js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AG,0BAA0B,CAAC,UAAU,CAAC,CAAA;gBAE1D,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,OAAO,CAAC,WAAW,CAAC,CAAA;gBACtB,CAAC;YACH,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,IAAI,CAAC,SAAS,EAAE,CAAC;oBACf,OAAO,CACL,gBAAgB,CACd,KAAK,EACL,IAAI,YAAY,CACd,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,2BAA2B,CACrE,CACF,CACF,CAAA;gBACH,CAAC;YACH,CAAC;QACH,CAAC;QAED,KAAK,WAAW,EAAE,CAAA;QAClB,OAAO,GAAG,EAAE;YACV,SAAS,GAAG,IAAI,CAAA;QAClB,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC,CAAA;IAEzC,OAAO,SAAS,IAAI,IAAI,CAAA;AAC1B,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export { CMSImage } from './components/client/CMSImage.js';
|
|
2
|
+
export { CMSMarkdown } from './components/client/CMSMarkdown.js';
|
|
3
|
+
export { CMSText } from './components/client/CMSText.js';
|
|
4
|
+
export { CMSContentProvider, usePreloadedContent } from './hooks/content-context.js';
|
|
5
|
+
export { useCMSConfig } from './hooks/use-cms-config.js';
|
|
6
|
+
export { useContent } from './hooks/use-content.js';
|
|
7
|
+
export { CMSProvider } from './provider.js';
|
|
8
|
+
export type { CMSConfig, CMSContent, CMSImageProps, CMSMarkdownProps, CMSTextProps, ContentLoaderOptions, } from './types.js';
|
|
9
|
+
export { ConfigurationError } from './types.js';
|
|
10
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AAExD,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AAEnD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAC3C,YAAY,EACV,SAAS,EACT,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,YAAY,EACZ,oBAAoB,GACrB,MAAM,YAAY,CAAA;AAEnB,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Client components
|
|
2
|
+
export { CMSImage } from './components/client/CMSImage.js';
|
|
3
|
+
export { CMSMarkdown } from './components/client/CMSMarkdown.js';
|
|
4
|
+
export { CMSText } from './components/client/CMSText.js';
|
|
5
|
+
export { CMSContentProvider, usePreloadedContent } from './hooks/content-context.js';
|
|
6
|
+
export { useCMSConfig } from './hooks/use-cms-config.js';
|
|
7
|
+
// Hooks
|
|
8
|
+
export { useContent } from './hooks/use-content.js';
|
|
9
|
+
// Provider
|
|
10
|
+
export { CMSProvider } from './provider.js';
|
|
11
|
+
// Types
|
|
12
|
+
export { ConfigurationError } from './types.js';
|
|
13
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,oBAAoB;AAEpB,OAAO,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAA;AAC1D,OAAO,EAAE,WAAW,EAAE,MAAM,oCAAoC,CAAA;AAChE,OAAO,EAAE,OAAO,EAAE,MAAM,gCAAgC,CAAA;AACxD,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,4BAA4B,CAAA;AACpF,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAA;AACxD,QAAQ;AACR,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,WAAW;AACX,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAS3C,QAAQ;AACR,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ReactElement, ReactNode } from 'react';
|
|
2
|
+
import type { CMSConfig } from './types.js';
|
|
3
|
+
interface CMSProviderProps {
|
|
4
|
+
children: ReactNode;
|
|
5
|
+
config?: Partial<CMSConfig>;
|
|
6
|
+
}
|
|
7
|
+
export declare function CMSProvider({ children, config }: CMSProviderProps): ReactElement;
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.d.ts","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,OAAO,CAAA;AAGpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAA;AAE3C,UAAU,gBAAgB;IACxB,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,CAAC,EAAE,OAAO,CAAC,SAAS,CAAC,CAAA;CAC5B;AAED,wBAAgB,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAW,EAAE,EAAE,gBAAgB,GAAG,YAAY,CAuBrF"}
|
package/dist/provider.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useMemo } from 'react';
|
|
4
|
+
import { CMSContext, defaultConfig } from './context.js';
|
|
5
|
+
export function CMSProvider({ children, config = {} }) {
|
|
6
|
+
const contentPath = config.contentPath;
|
|
7
|
+
const assetsPath = config.assetsPath;
|
|
8
|
+
const imagesPath = config.imagesPath;
|
|
9
|
+
const autoReload = config.autoReload;
|
|
10
|
+
const errorBoundary = config.errorBoundary;
|
|
11
|
+
const cacheContent = config.cacheContent;
|
|
12
|
+
const mergedConfig = useMemo(() => {
|
|
13
|
+
const overrides = Object.fromEntries(Object.entries({
|
|
14
|
+
contentPath,
|
|
15
|
+
assetsPath,
|
|
16
|
+
imagesPath,
|
|
17
|
+
autoReload,
|
|
18
|
+
errorBoundary,
|
|
19
|
+
cacheContent,
|
|
20
|
+
}).filter(([, v]) => v != null));
|
|
21
|
+
return { ...defaultConfig, ...overrides };
|
|
22
|
+
}, [contentPath, assetsPath, imagesPath, autoReload, errorBoundary, cacheContent]);
|
|
23
|
+
return _jsx(CMSContext.Provider, { value: mergedConfig, children: children });
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAGZ,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAA;AAC/B,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,cAAc,CAAA;AAQxD,MAAM,UAAU,WAAW,CAAC,EAAE,QAAQ,EAAE,MAAM,GAAG,EAAE,EAAoB;IACrE,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAA;IACtC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IACpC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IACpC,MAAM,UAAU,GAAG,MAAM,CAAC,UAAU,CAAA;IACpC,MAAM,aAAa,GAAG,MAAM,CAAC,aAAa,CAAA;IAC1C,MAAM,YAAY,GAAG,MAAM,CAAC,YAAY,CAAA;IAExC,MAAM,YAAY,GAAG,OAAO,CAAC,GAAc,EAAE;QAC3C,MAAM,SAAS,GAAG,MAAM,CAAC,WAAW,CAClC,MAAM,CAAC,OAAO,CAAC;YACb,WAAW;YACX,UAAU;YACV,UAAU;YACV,UAAU;YACV,aAAa;YACb,YAAY;SACb,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,IAAI,CAAC,CAChC,CAAA;QACD,OAAO,EAAE,GAAG,aAAa,EAAE,GAAG,SAAS,EAAE,CAAA;IAC3C,CAAC,EAAE,CAAC,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,UAAU,EAAE,aAAa,EAAE,YAAY,CAAC,CAAC,CAAA;IAElF,OAAO,KAAC,UAAU,CAAC,QAAQ,IAAC,KAAK,EAAE,YAAY,YAAG,QAAQ,GAAuB,CAAA;AACnF,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { CMSContent, CMSContentOptions, CMSSummary, CMSSummaryOptions } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Load the published version of a document. The returned `fields` is
|
|
4
|
+
* `Record<string, unknown>` — callers can narrow to `Record<string, string>`
|
|
5
|
+
* when they know the content shape. Throws a 404 `NetworkError` when the
|
|
6
|
+
* document has no published version.
|
|
7
|
+
*/
|
|
8
|
+
export declare const getCMSContent: (collection: string, slug: string, options?: CMSContentOptions) => Promise<CMSContent>;
|
|
9
|
+
/** The slugs of the published documents in a collection */
|
|
10
|
+
export declare const getCMSSlugs: (collection: string, locale?: string | undefined) => Promise<string[]>;
|
|
11
|
+
/** Every published document in a collection */
|
|
12
|
+
export declare const getAllCMSContent: (collection: string, options?: CMSContentOptions) => Promise<CMSContent[]>;
|
|
13
|
+
/**
|
|
14
|
+
* The published documents of a collection without their bodies: the fields a
|
|
15
|
+
* list, a card or a navigation shows. Nothing is rendered; a page that shows a
|
|
16
|
+
* document's body reads `getAllCMSContent` or `getCMSContent`.
|
|
17
|
+
*/
|
|
18
|
+
export declare const getAllCMSSummaries: (collection: string, options?: CMSSummaryOptions) => Promise<CMSSummary[]>;
|
|
19
|
+
//# sourceMappingURL=cms-context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cms-context.d.ts","sourceRoot":"","sources":["../../src/server/cms-context.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,iBAAiB,EAAE,UAAU,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAG5F;;;;;GAKG;AACH,eAAO,MAAM,aAAa,eACL,MAAM,QAAQ,MAAM,YAAY,iBAAiB,KAAG,OAAO,CAAC,UAAU,CAG1F,CAAA;AAED,2DAA2D;AAC3D,eAAO,MAAM,WAAW,eACH,MAAM,WAAW,MAAM,GAAG,SAAS,KAAG,OAAO,CAAC,MAAM,EAAE,CAI1E,CAAA;AAED,+CAA+C;AAC/C,eAAO,MAAM,gBAAgB,eACR,MAAM,YAAY,iBAAiB,KAAG,OAAO,CAAC,UAAU,EAAE,CAU9E,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,eACV,MAAM,YAAY,iBAAiB,KAAG,OAAO,CAAC,UAAU,EAAE,CAU9E,CAAA"}
|