react-datocms 7.1.0-0 → 7.2.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 +33 -14
- package/dist/cjs/StructuredText/index.js +14 -1
- package/dist/cjs/StructuredText/index.js.map +1 -1
- package/dist/cjs/useSiteSearch/index.js +1 -8
- package/dist/cjs/useSiteSearch/index.js.map +1 -1
- package/dist/esm/StructuredText/index.js +15 -2
- package/dist/esm/StructuredText/index.js.map +1 -1
- package/dist/esm/useSiteSearch/index.js +1 -8
- package/dist/esm/useSiteSearch/index.js.map +1 -1
- package/dist/types/StructuredText/index.d.ts +3 -1
- package/package.json +3 -3
- package/src/StructuredText/__tests__/__snapshots__/index.test.tsx.snap +15 -0
- package/src/StructuredText/__tests__/index.test.tsx +101 -78
- package/src/StructuredText/index.tsx +30 -0
- package/src/useSiteSearch/index.tsx +1 -4
package/README.md
CHANGED
|
@@ -52,26 +52,45 @@ npm run start
|
|
|
52
52
|
---
|
|
53
53
|
|
|
54
54
|
# What is DatoCMS?
|
|
55
|
-
|
|
55
|
+
|
|
56
|
+
<a href="https://www.datocms.com/"><img src="https://www.datocms.com/images/full_logo.svg" height="60" alt="DatoCMS - The Headless CMS for the Modern Web"></a>
|
|
56
57
|
|
|
57
58
|
[DatoCMS](https://www.datocms.com/) is the REST & GraphQL Headless CMS for the modern web.
|
|
58
59
|
|
|
59
|
-
Trusted by over 25,000 enterprise businesses,
|
|
60
|
+
Trusted by over 25,000 enterprise businesses, agencies, and individuals across the world, DatoCMS users create online content at scale from a central hub and distribute it via API. We ❤️ our [developers](https://www.datocms.com/team/best-cms-for-developers), [content editors](https://www.datocms.com/team/content-creators) and [marketers](https://www.datocms.com/team/cms-digital-marketing)!
|
|
61
|
+
|
|
62
|
+
**Why DatoCMS?**
|
|
63
|
+
|
|
64
|
+
- **API-First Architecture**: Built for both REST and GraphQL, enabling flexible content delivery
|
|
65
|
+
- **Just Enough Features**: We believe in keeping things simple, and giving you [the right feature-set tools](https://www.datocms.com/features) to get the job done
|
|
66
|
+
- **Developer Experience**: First-class TypeScript support with powerful developer tools
|
|
67
|
+
|
|
68
|
+
**Getting Started:**
|
|
69
|
+
|
|
70
|
+
- ⚡️ [Create Free Account](https://dashboard.datocms.com/signup) - Get started with DatoCMS in minutes
|
|
71
|
+
- 🔖 [Documentation](https://www.datocms.com/docs) - Comprehensive guides and API references
|
|
72
|
+
- ⚙️ [Community Support](https://community.datocms.com/) - Get help from our team and community
|
|
73
|
+
- 🆕 [Changelog](https://www.datocms.com/product-updates) - Latest features and improvements
|
|
74
|
+
|
|
75
|
+
**Official Libraries:**
|
|
76
|
+
|
|
77
|
+
- [**Content Delivery Client**](https://github.com/datocms/cda-client) - TypeScript GraphQL client for content fetching
|
|
78
|
+
- [**REST API Clients**](https://github.com/datocms/js-rest-api-clients) - Node.js/Browser clients for content management
|
|
79
|
+
- [**CLI Tools**](https://github.com/datocms/cli) - Command-line utilities for schema migrations (includes [Contentful](https://github.com/datocms/cli/tree/main/packages/cli-plugin-contentful) and [WordPress](https://github.com/datocms/cli/tree/main/packages/cli-plugin-wordpress) importers)
|
|
80
|
+
|
|
81
|
+
**Official Framework Integrations**
|
|
60
82
|
|
|
61
|
-
|
|
83
|
+
Helpers to manage SEO, images, video and Structured Text coming from your DatoCMS projects:
|
|
62
84
|
|
|
63
|
-
-
|
|
64
|
-
-
|
|
65
|
-
-
|
|
66
|
-
-
|
|
85
|
+
- [**React Components**](https://github.com/datocms/react-datocms)
|
|
86
|
+
- [**Vue Components**](https://github.com/datocms/vue-datocms)
|
|
87
|
+
- [**Svelte Components**](https://github.com/datocms/datocms-svelte)
|
|
88
|
+
- [**Astro Components**](https://github.com/datocms/astro-datocms)
|
|
67
89
|
|
|
68
|
-
**
|
|
69
|
-
- [datocms/react-datocms](https://github.com/datocms/react-datocms): React helper components for images, Structured Text rendering, and more
|
|
70
|
-
- [datocms/js-rest-api-clients](https://github.com/datocms/js-rest-api-clients): Node and browser JavaScript clients for updating and administering your content. For frontend fetches, we recommend using our [GraphQL Content Delivery API](https://www.datocms.com/docs/content-delivery-api) instead.
|
|
71
|
-
- [datocms/cli](https://github.com/datocms/cli): Command-line interface that includes our [Contentful importer](https://github.com/datocms/cli/tree/main/packages/cli-plugin-contentful) and [Wordpress importer](https://github.com/datocms/cli/tree/main/packages/cli-plugin-wordpress)
|
|
72
|
-
- [datocms/plugins](https://github.com/datocms/plugins): Example plugins we've made that extend the editor/admin dashboard
|
|
73
|
-
- [DatoCMS Starters](https://www.datocms.com/marketplace/starters) has examples for various Javascript frontend frameworks
|
|
90
|
+
**Additional Resources:**
|
|
74
91
|
|
|
75
|
-
|
|
92
|
+
- [**Plugin Examples**](https://github.com/datocms/plugins) - Example plugins we've made that extend the editor/admin dashboard
|
|
93
|
+
- [**Starter Projects**](https://www.datocms.com/marketplace/starters) - Example website implementations for popular frameworks
|
|
94
|
+
- [**All Public Repositories**](https://github.com/orgs/datocms/repositories?q=&type=public&language=&sort=stargazers)
|
|
76
95
|
|
|
77
96
|
<!--datocms-autoinclude-footer end-->
|
|
@@ -43,7 +43,7 @@ function appendKeyToValidElement(element, key) {
|
|
|
43
43
|
return element;
|
|
44
44
|
}
|
|
45
45
|
exports.appendKeyToValidElement = appendKeyToValidElement;
|
|
46
|
-
function StructuredText({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }) {
|
|
46
|
+
function StructuredText({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderInlineBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }) {
|
|
47
47
|
const result = (0, datocms_structured_text_generic_html_renderer_1.render)(data, {
|
|
48
48
|
adapter: {
|
|
49
49
|
renderText: renderText || exports.defaultAdapter.renderText,
|
|
@@ -101,6 +101,19 @@ function StructuredText({ data, renderInlineRecord, renderLinkToRecord, renderBl
|
|
|
101
101
|
}
|
|
102
102
|
return appendKeyToValidElement(renderBlock({ record: item }), key);
|
|
103
103
|
}),
|
|
104
|
+
(0, datocms_structured_text_generic_html_renderer_1.renderNodeRule)(datocms_structured_text_utils_1.isInlineBlock, ({ node, key }) => {
|
|
105
|
+
if (!renderInlineBlock) {
|
|
106
|
+
throw new datocms_structured_text_utils_1.RenderError(`The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`, node);
|
|
107
|
+
}
|
|
108
|
+
if (!((0, datocms_structured_text_utils_1.isStructuredText)(data) && data.blocks)) {
|
|
109
|
+
throw new datocms_structured_text_utils_1.RenderError(`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.blocks is not present!`, node);
|
|
110
|
+
}
|
|
111
|
+
const item = data.blocks.find((item) => item.id === node.item);
|
|
112
|
+
if (!item) {
|
|
113
|
+
throw new datocms_structured_text_utils_1.RenderError(`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.blocks!`, node);
|
|
114
|
+
}
|
|
115
|
+
return appendKeyToValidElement(renderInlineBlock({ record: item }), key);
|
|
116
|
+
}),
|
|
104
117
|
...(customNodeRules || customRules || []),
|
|
105
118
|
],
|
|
106
119
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAQuD;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iHAQuD;AAkB9B,+FApBvB,8DAAc,OAoBuB;AAA9B,+FAnBP,8DAAc,OAmBO;AAGI,2FAtBzB,8DAAc,OAsBqB;AApBrC,iFAcuC;AAGE,4FAfvC,2CAAW,OAeuC;AAFpD,+CAA+E;AAgBlE,QAAA,cAAc,GAAG;IAC5B,UAAU,EAAE,eAAK,CAAC,aAAg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,CAAC;gBACJ,CAAC;gBAED,IAAI,CAAC,CAAC,IAAA,gDAAgB,EAAC,IAAI,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC;oBAC7C,MAAM,IAAI,2CAAW,CACnB,iJAAiJ,EACjJ,IAAI,CACL,CAAC;gBACJ,CAAC;gBAED,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;gBAE/D,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,IAAI,2CAAW,CACnB,iGAAiG,IAAI,CAAC,IAAI,sBAAsB,EAChI,IAAI,CACL,CAAC;gBACJ,CAAC;gBAED,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;YAC3E,CAAC,CAAC;YACF,GAAG,CAAC,eAAe,IAAI,WAAW,IAAI,EAAE,CAAC;SAC1C;KACF,CAAC,CAAC;IAEH,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,8DAAG,MAAM,CAAI,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC;AA1JD,wCA0JC"}
|
|
@@ -43,19 +43,12 @@ function useSiteSearch(config) {
|
|
|
43
43
|
}
|
|
44
44
|
setResponse(undefined);
|
|
45
45
|
const request = {
|
|
46
|
-
filter: {
|
|
47
|
-
query: state.query,
|
|
48
|
-
locale: state.locale,
|
|
49
|
-
build_trigger_id: config.buildTriggerId,
|
|
50
|
-
},
|
|
46
|
+
filter: Object.assign({ query: state.query, locale: state.locale, build_trigger_id: config.buildTriggerId }, (config.fuzzySearch === true ? { fuzzy: true } : {})),
|
|
51
47
|
page: {
|
|
52
48
|
limit: resultsPerPage,
|
|
53
49
|
offset: resultsPerPage * state.page,
|
|
54
50
|
},
|
|
55
51
|
};
|
|
56
|
-
if (config.fuzzySearch) {
|
|
57
|
-
request.fuzzy = 'true';
|
|
58
|
-
}
|
|
59
52
|
const response = yield config.client.searchResults.rawList(request);
|
|
60
53
|
if (!isCancelled) {
|
|
61
54
|
setResponse(response);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useSiteSearch/index.tsx"],"names":[],"mappings":";AAAA,YAAY,CAAC;;;;;;;;;;;;;;;AAEb,yDAAyD;AACzD,kDAA0B;AAC1B,iCAAyD;AACzD,gFAAsD;AAiGtD,MAAM,kBAAkB,GAAgB,CAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CACrD,wCAAM,GAAG,EAAE,GAAG,IAAG,IAAI,CAAQ,CAC9B,CAAC;AAEF,SAAS,gBAAgB,CAAC,EACxB,QAAQ,EACR,WAAW,EACX,OAAO,GAKR;IACC,OAAO,CACL,8DACG,IAAA,8BAAkB,EAAC,QAAQ,EAAE,oBAAoB,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CACnE,WAAW,CAAC,KAAK,EAAE,KAAK,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC,CAC9C,CACA,CACJ,CAAC;AACJ,CAAC;AAED,SAAgB,aAAa,CAC3B,MAAmC;;IAEnC,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAI/B;QACD,KAAK,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,KAAK,KAAI,EAAE;QACvC,IAAI,EAAE,CAAA,MAAA,MAAM,CAAC,YAAY,0CAAE,IAAI,KAAI,CAAC;QACpC,MAAM,EAAE,MAAA,MAAM,CAAC,YAAY,0CAAE,MAAM;KACpC,CAAC,CAAC;IAEH,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,GAAsB,CAAC;IACzD,MAAM,CAAC,QAAQ,EAAE,WA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BAAC,gBAAgB,IACf,WAAW,EAAE,WAAW,EACxB,OAAO,EAAC,aAAa,IAEpB,eAAe,CAAC,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAC5B,CACpB,CAAC,CAAC,CAAC,CACF,eAAe,CAAC,UAAU,CAAC,YAAY,CACxC;wBACD,GAAG,EAAE,eAAe;qBACrB,CAAC,CAAC;oBACH,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;oBACvC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC;iBAClE;gBACH,CAAC,CAAC,SAAS;KAClB,CAAC;AACJ,CAAC;AApJD,sCAoJC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { defaultMetaTransformer, render, renderMarkRule, renderNodeRule, } from 'datocms-structured-text-generic-html-renderer';
|
|
2
|
-
import { RenderError, isBlock, isInlineItem, isItemLink, isStructuredText, } from 'datocms-structured-text-utils';
|
|
2
|
+
import { RenderError, isBlock, isInlineBlock, isInlineItem, isItemLink, isStructuredText, } from 'datocms-structured-text-utils';
|
|
3
3
|
import React, { cloneElement, isValidElement } from 'react';
|
|
4
4
|
export { renderNodeRule, renderMarkRule, RenderError };
|
|
5
5
|
// deprecated
|
|
@@ -15,7 +15,7 @@ export function appendKeyToValidElement(element, key) {
|
|
|
15
15
|
}
|
|
16
16
|
return element;
|
|
17
17
|
}
|
|
18
|
-
export function StructuredText({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }) {
|
|
18
|
+
export function StructuredText({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderInlineBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }) {
|
|
19
19
|
const result = render(data, {
|
|
20
20
|
adapter: {
|
|
21
21
|
renderText: renderText || defaultAdapter.renderText,
|
|
@@ -73,6 +73,19 @@ export function StructuredText({ data, renderInlineRecord, renderLinkToRecord, r
|
|
|
73
73
|
}
|
|
74
74
|
return appendKeyToValidElement(renderBlock({ record: item }), key);
|
|
75
75
|
}),
|
|
76
|
+
renderNodeRule(isInlineBlock, ({ node, key }) => {
|
|
77
|
+
if (!renderInlineBlock) {
|
|
78
|
+
throw new RenderError(`The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`, node);
|
|
79
|
+
}
|
|
80
|
+
if (!(isStructuredText(data) && data.blocks)) {
|
|
81
|
+
throw new RenderError(`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.blocks is not present!`, node);
|
|
82
|
+
}
|
|
83
|
+
const item = data.blocks.find((item) => item.id === node.item);
|
|
84
|
+
if (!item) {
|
|
85
|
+
throw new RenderError(`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.blocks!`, node);
|
|
86
|
+
}
|
|
87
|
+
return appendKeyToValidElement(renderInlineBlock({ record: item }), key);
|
|
88
|
+
}),
|
|
76
89
|
...(customNodeRules || customRules || []),
|
|
77
90
|
],
|
|
78
91
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/StructuredText/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAIL,sBAAsB,EACtB,MAAM,EACN,cAAc,EACd,cAAc,GACf,MAAM,+CAA+C,CAAC;AACvD,OAAO,EAEL,WAAW,EAOX,OAAO,EACP,YAAY,EACZ,UAAU,EACV,gBAAgB,GACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EAAE,EAAqB,YAAY,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAE/E,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,WAAW,EAAE,CAAC;AAEvD,aAAa;AACb,OAAO,EAAE,cAAc,IAAI,UAAU,EAAE,CAAC;AAWxC,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B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AI,CAAC,EAAE,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC;gBAE/D,IAAI,CAAC,IAAI,EAAE,CAAC;oBACV,MAAM,IAAI,WAAW,CACnB,iGAAiG,IAAI,CAAC,IAAI,sBAAsB,EAChI,IAAI,CACL,CAAC;gBACJ,CAAC;gBAED,OAAO,uBAAuB,CAAC,iBAAiB,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,CAAC;YAC3E,CAAC,CAAC;YACF,GAAG,CAAC,eAAe,IAAI,WAAW,IAAI,EAAE,CAAC;SAC1C;KACF,CAAC,CAAC;IAEH,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,0CAAG,MAAM,CAAI,CAAC;IACvB,CAAC;IAED,OAAO,MAAM,IAAI,IAAI,CAAC;AACxB,CAAC"}
|
|
@@ -37,19 +37,12 @@ export function useSiteSearch(config) {
|
|
|
37
37
|
}
|
|
38
38
|
setResponse(undefined);
|
|
39
39
|
const request = {
|
|
40
|
-
filter: {
|
|
41
|
-
query: state.query,
|
|
42
|
-
locale: state.locale,
|
|
43
|
-
build_trigger_id: config.buildTriggerId,
|
|
44
|
-
},
|
|
40
|
+
filter: Object.assign({ query: state.query, locale: state.locale, build_trigger_id: config.buildTriggerId }, (config.fuzzySearch === true ? { fuzzy: true } : {})),
|
|
45
41
|
page: {
|
|
46
42
|
limit: resultsPerPage,
|
|
47
43
|
offset: resultsPerPage * state.page,
|
|
48
44
|
},
|
|
49
45
|
};
|
|
50
|
-
if (config.fuzzySearch) {
|
|
51
|
-
request.fuzzy = 'true';
|
|
52
|
-
}
|
|
53
46
|
const response = yield config.client.searchResults.rawList(request);
|
|
54
47
|
if (!isCancelled) {
|
|
55
48
|
setResponse(response);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/useSiteSearch/index.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;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,YAAY,CACxC;wBACD,GAAG,EAAE,eAAe;qBACrB,CAAC,CAAC;oBACH,YAAY,EAAE,QAAQ,CAAC,IAAI,CAAC,WAAW;oBACvC,UAAU,EAAE,IAAI,CAAC,IAAI,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,GAAG,cAAc,CAAC;iBAClE;gBACH,CAAC,CAAC,SAAS;KAClB,CAAC;AACJ,CAAC"}
|
|
@@ -38,6 +38,8 @@ export type StructuredTextPropTypes<R1 extends StructuredTextGraphQlResponseReco
|
|
|
38
38
|
renderLinkToRecord?: (context: RenderRecordLinkContext<R2>) => ReactElement | null;
|
|
39
39
|
/** Fuction that converts a 'block' node into React **/
|
|
40
40
|
renderBlock?: (context: RenderBlockContext<R1>) => ReactElement | null;
|
|
41
|
+
/** Fuction that converts an 'inlineBlock' node into React **/
|
|
42
|
+
renderInlineBlock?: (context: RenderBlockContext<R1>) => ReactElement | null;
|
|
41
43
|
/** Function that converts 'link' and 'itemLink' `meta` into HTML props */
|
|
42
44
|
metaTransformer?: TransformMetaFn;
|
|
43
45
|
/** Fuction that converts a simple string text into React **/
|
|
@@ -49,4 +51,4 @@ export type StructuredTextPropTypes<R1 extends StructuredTextGraphQlResponseReco
|
|
|
49
51
|
/** @deprecated use customNodeRules **/
|
|
50
52
|
customRules?: RenderRule<H, T, F>[];
|
|
51
53
|
};
|
|
52
|
-
export declare function StructuredText<R1 extends StructuredTextGraphQlResponseRecord, R2 extends StructuredTextGraphQlResponseRecord = R1>({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }: StructuredTextPropTypes<R1, R2>): ReactElement | null;
|
|
54
|
+
export declare function StructuredText<R1 extends StructuredTextGraphQlResponseRecord, R2 extends StructuredTextGraphQlResponseRecord = R1>({ data, renderInlineRecord, renderLinkToRecord, renderBlock, renderInlineBlock, renderText, renderNode, renderFragment, customMarkRules, customRules, customNodeRules, metaTransformer, }: StructuredTextPropTypes<R1, R2>): ReactElement | null;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-datocms",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.2.0",
|
|
4
4
|
"engines": {
|
|
5
5
|
"node": ">=8.0.0"
|
|
6
6
|
},
|
|
@@ -135,8 +135,8 @@
|
|
|
135
135
|
"dependencies": {
|
|
136
136
|
"@mux/mux-player-react": "*",
|
|
137
137
|
"datocms-listen": "^0.1.9",
|
|
138
|
-
"datocms-structured-text-generic-html-renderer": "^4.
|
|
139
|
-
"datocms-structured-text-utils": "^4.
|
|
138
|
+
"datocms-structured-text-generic-html-renderer": "^4.1.2",
|
|
139
|
+
"datocms-structured-text-utils": "^4.1.2",
|
|
140
140
|
"react-intersection-observer": "^9.4.3",
|
|
141
141
|
"react-string-replace": "^1.1.0",
|
|
142
142
|
"use-deep-compare-effect": "^1.6.1"
|
|
@@ -224,6 +224,11 @@ exports[`StructuredText with links/blocks with default rules renders the documen
|
|
|
224
224
|
"id": "456",
|
|
225
225
|
"quote": "Foo bar.",
|
|
226
226
|
},
|
|
227
|
+
{
|
|
228
|
+
"__typename": "MentionRecord",
|
|
229
|
+
"id": "789",
|
|
230
|
+
"name": "Jane Doe",
|
|
231
|
+
},
|
|
227
232
|
],
|
|
228
233
|
"links": [
|
|
229
234
|
{
|
|
@@ -269,6 +274,10 @@ exports[`StructuredText with links/blocks with default rules renders the documen
|
|
|
269
274
|
],
|
|
270
275
|
"type": "itemLink",
|
|
271
276
|
},
|
|
277
|
+
{
|
|
278
|
+
"item": "789",
|
|
279
|
+
"type": "inlineBlock",
|
|
280
|
+
},
|
|
272
281
|
],
|
|
273
282
|
"level": 1,
|
|
274
283
|
"type": "heading",
|
|
@@ -285,6 +294,7 @@ exports[`StructuredText with links/blocks with default rules renders the documen
|
|
|
285
294
|
}
|
|
286
295
|
}
|
|
287
296
|
renderBlock={[Function]}
|
|
297
|
+
renderInlineBlock={[Function]}
|
|
288
298
|
renderInlineRecord={[Function]}
|
|
289
299
|
renderLinkToRecord={[Function]}
|
|
290
300
|
>
|
|
@@ -310,6 +320,11 @@ exports[`StructuredText with links/blocks with default rules renders the documen
|
|
|
310
320
|
>
|
|
311
321
|
here!
|
|
312
322
|
</a>
|
|
323
|
+
<em
|
|
324
|
+
key="t-4"
|
|
325
|
+
>
|
|
326
|
+
Jane Doe
|
|
327
|
+
</em>
|
|
313
328
|
</h1>
|
|
314
329
|
<figure
|
|
315
330
|
key="t-1"
|
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { renderMarkRule } from
|
|
2
|
-
import { isHeading } from
|
|
3
|
-
import { mount, render, shallow } from
|
|
4
|
-
import * as React from
|
|
1
|
+
import { renderMarkRule } from "datocms-structured-text-generic-html-renderer";
|
|
2
|
+
import { isHeading } from "datocms-structured-text-utils";
|
|
3
|
+
import { mount, render, shallow } from "enzyme";
|
|
4
|
+
import * as React from "react";
|
|
5
5
|
import {
|
|
6
6
|
RenderError,
|
|
7
7
|
StructuredText,
|
|
8
8
|
type StructuredTextDocument,
|
|
9
9
|
type StructuredTextGraphQlResponse,
|
|
10
10
|
renderNodeRule,
|
|
11
|
-
} from
|
|
11
|
+
} from "../index.js";
|
|
12
12
|
|
|
13
|
-
describe(
|
|
14
|
-
describe(
|
|
15
|
-
it(
|
|
13
|
+
describe("StructuredText", () => {
|
|
14
|
+
describe("with no value", () => {
|
|
15
|
+
it("renders null", () => {
|
|
16
16
|
const wrapper = mount(<StructuredText data={null} />);
|
|
17
17
|
expect(wrapper).toMatchSnapshot();
|
|
18
18
|
});
|
|
19
19
|
});
|
|
20
20
|
|
|
21
|
-
describe(
|
|
21
|
+
describe("simple dast /2", () => {
|
|
22
22
|
const structuredText: StructuredTextDocument = {
|
|
23
|
-
schema:
|
|
23
|
+
schema: "dast",
|
|
24
24
|
document: {
|
|
25
|
-
type:
|
|
25
|
+
type: "root",
|
|
26
26
|
children: [
|
|
27
27
|
{
|
|
28
|
-
type:
|
|
28
|
+
type: "heading",
|
|
29
29
|
level: 1,
|
|
30
30
|
children: [
|
|
31
31
|
{
|
|
32
|
-
type:
|
|
33
|
-
value:
|
|
32
|
+
type: "span",
|
|
33
|
+
value: "This\nis a ",
|
|
34
34
|
},
|
|
35
35
|
{
|
|
36
|
-
type:
|
|
37
|
-
marks: [
|
|
38
|
-
value:
|
|
36
|
+
type: "span",
|
|
37
|
+
marks: ["strong"],
|
|
38
|
+
value: "title",
|
|
39
39
|
},
|
|
40
40
|
],
|
|
41
41
|
},
|
|
@@ -43,49 +43,49 @@ describe('StructuredText', () => {
|
|
|
43
43
|
},
|
|
44
44
|
};
|
|
45
45
|
|
|
46
|
-
describe(
|
|
47
|
-
it(
|
|
46
|
+
describe("with default rules", () => {
|
|
47
|
+
it("renders the document", () => {
|
|
48
48
|
const wrapper = mount(<StructuredText data={structuredText} />);
|
|
49
49
|
expect(wrapper).toMatchSnapshot();
|
|
50
50
|
});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
-
describe(
|
|
54
|
-
it(
|
|
53
|
+
describe("with custom mark rules", () => {
|
|
54
|
+
it("renders the document", () => {
|
|
55
55
|
const wrapper = mount(
|
|
56
56
|
<StructuredText
|
|
57
57
|
data={structuredText}
|
|
58
58
|
customMarkRules={[
|
|
59
|
-
renderMarkRule(
|
|
59
|
+
renderMarkRule("strong", ({ children, key }) => (
|
|
60
60
|
<b key={key}>{children}</b>
|
|
61
61
|
)),
|
|
62
62
|
]}
|
|
63
|
-
|
|
63
|
+
/>
|
|
64
64
|
);
|
|
65
65
|
expect(wrapper).toMatchSnapshot();
|
|
66
66
|
});
|
|
67
67
|
});
|
|
68
68
|
});
|
|
69
69
|
|
|
70
|
-
describe(
|
|
70
|
+
describe("simple dast with no links/blocks", () => {
|
|
71
71
|
const structuredText: StructuredTextGraphQlResponse = {
|
|
72
72
|
value: {
|
|
73
|
-
schema:
|
|
73
|
+
schema: "dast",
|
|
74
74
|
document: {
|
|
75
|
-
type:
|
|
75
|
+
type: "root",
|
|
76
76
|
children: [
|
|
77
77
|
{
|
|
78
|
-
type:
|
|
78
|
+
type: "heading",
|
|
79
79
|
level: 1,
|
|
80
80
|
children: [
|
|
81
81
|
{
|
|
82
|
-
type:
|
|
83
|
-
value:
|
|
82
|
+
type: "span",
|
|
83
|
+
value: "This\nis a ",
|
|
84
84
|
},
|
|
85
85
|
{
|
|
86
|
-
type:
|
|
87
|
-
marks: [
|
|
88
|
-
value:
|
|
86
|
+
type: "span",
|
|
87
|
+
marks: ["strong"],
|
|
88
|
+
value: "title",
|
|
89
89
|
},
|
|
90
90
|
],
|
|
91
91
|
},
|
|
@@ -94,22 +94,22 @@ describe('StructuredText', () => {
|
|
|
94
94
|
},
|
|
95
95
|
};
|
|
96
96
|
|
|
97
|
-
describe(
|
|
98
|
-
it(
|
|
97
|
+
describe("with default rules", () => {
|
|
98
|
+
it("renders the document", () => {
|
|
99
99
|
const wrapper = mount(<StructuredText data={structuredText} />);
|
|
100
100
|
expect(wrapper).toMatchSnapshot();
|
|
101
101
|
});
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
-
describe(
|
|
105
|
-
it(
|
|
104
|
+
describe("with custom rules", () => {
|
|
105
|
+
it("renders the document", () => {
|
|
106
106
|
const wrapper = mount(
|
|
107
107
|
<StructuredText
|
|
108
108
|
data={structuredText}
|
|
109
109
|
renderText={(text, key) => {
|
|
110
110
|
return (
|
|
111
111
|
<React.Fragment key={key}>
|
|
112
|
-
{text.replace(/This/,
|
|
112
|
+
{text.replace(/This/, "That")}
|
|
113
113
|
</React.Fragment>
|
|
114
114
|
);
|
|
115
115
|
}}
|
|
@@ -118,98 +118,113 @@ describe('StructuredText', () => {
|
|
|
118
118
|
isHeading,
|
|
119
119
|
({ adapter: { renderNode }, node, children, key }) => {
|
|
120
120
|
return renderNode(`h${node.level + 1}`, { key }, children);
|
|
121
|
-
}
|
|
121
|
+
}
|
|
122
122
|
),
|
|
123
123
|
]}
|
|
124
|
-
|
|
124
|
+
/>
|
|
125
125
|
);
|
|
126
126
|
expect(wrapper).toMatchSnapshot();
|
|
127
127
|
});
|
|
128
128
|
});
|
|
129
129
|
});
|
|
130
130
|
|
|
131
|
-
describe(
|
|
131
|
+
describe("with links/blocks", () => {
|
|
132
132
|
type QuoteRecord = {
|
|
133
133
|
id: string;
|
|
134
|
-
__typename:
|
|
134
|
+
__typename: "QuoteRecord";
|
|
135
135
|
quote: string;
|
|
136
136
|
author: string;
|
|
137
137
|
};
|
|
138
138
|
|
|
139
|
+
type MentionRecord = {
|
|
140
|
+
id: string;
|
|
141
|
+
__typename: "MentionRecord";
|
|
142
|
+
name: string;
|
|
143
|
+
};
|
|
144
|
+
|
|
139
145
|
type DocPageRecord = {
|
|
140
146
|
id: string;
|
|
141
|
-
__typename:
|
|
147
|
+
__typename: "DocPageRecord";
|
|
142
148
|
slug: string;
|
|
143
149
|
title: string;
|
|
144
150
|
};
|
|
145
151
|
|
|
146
152
|
const structuredText: StructuredTextGraphQlResponse<
|
|
147
|
-
QuoteRecord,
|
|
153
|
+
QuoteRecord | MentionRecord,
|
|
148
154
|
DocPageRecord
|
|
149
155
|
> = {
|
|
150
156
|
value: {
|
|
151
|
-
schema:
|
|
157
|
+
schema: "dast",
|
|
152
158
|
document: {
|
|
153
|
-
type:
|
|
159
|
+
type: "root",
|
|
154
160
|
children: [
|
|
155
161
|
{
|
|
156
|
-
type:
|
|
162
|
+
type: "heading",
|
|
157
163
|
level: 1,
|
|
158
164
|
children: [
|
|
159
165
|
{
|
|
160
|
-
type:
|
|
161
|
-
value:
|
|
166
|
+
type: "span",
|
|
167
|
+
value: "This is a",
|
|
162
168
|
},
|
|
163
169
|
{
|
|
164
|
-
type:
|
|
165
|
-
marks: [
|
|
166
|
-
value:
|
|
170
|
+
type: "span",
|
|
171
|
+
marks: ["highlight"],
|
|
172
|
+
value: "title",
|
|
167
173
|
},
|
|
168
174
|
{
|
|
169
|
-
type:
|
|
170
|
-
item:
|
|
175
|
+
type: "inlineItem",
|
|
176
|
+
item: "123",
|
|
171
177
|
},
|
|
172
178
|
{
|
|
173
|
-
type:
|
|
174
|
-
item:
|
|
175
|
-
meta: [{ id:
|
|
176
|
-
children: [{ type:
|
|
179
|
+
type: "itemLink",
|
|
180
|
+
item: "123",
|
|
181
|
+
meta: [{ id: "target", value: "_blank" }],
|
|
182
|
+
children: [{ type: "span", value: "here!" }],
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
type: "inlineBlock",
|
|
186
|
+
item: "789",
|
|
177
187
|
},
|
|
178
188
|
],
|
|
179
189
|
},
|
|
180
190
|
{
|
|
181
|
-
type:
|
|
182
|
-
item:
|
|
191
|
+
type: "block",
|
|
192
|
+
item: "456",
|
|
183
193
|
},
|
|
184
194
|
],
|
|
185
195
|
},
|
|
186
196
|
},
|
|
187
197
|
blocks: [
|
|
188
198
|
{
|
|
189
|
-
id:
|
|
190
|
-
__typename:
|
|
191
|
-
quote:
|
|
192
|
-
author:
|
|
199
|
+
id: "456",
|
|
200
|
+
__typename: "QuoteRecord",
|
|
201
|
+
quote: "Foo bar.",
|
|
202
|
+
author: "Mark Smith",
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
id: "789",
|
|
206
|
+
__typename: "MentionRecord",
|
|
207
|
+
name: "Jane Doe",
|
|
193
208
|
},
|
|
194
209
|
],
|
|
195
210
|
links: [
|
|
196
211
|
{
|
|
197
|
-
id:
|
|
198
|
-
__typename:
|
|
199
|
-
title:
|
|
200
|
-
slug:
|
|
212
|
+
id: "123",
|
|
213
|
+
__typename: "DocPageRecord",
|
|
214
|
+
title: "How to code",
|
|
215
|
+
slug: "how-to-code",
|
|
201
216
|
},
|
|
202
217
|
],
|
|
203
218
|
};
|
|
204
219
|
|
|
205
|
-
describe(
|
|
206
|
-
it(
|
|
220
|
+
describe("with default rules", () => {
|
|
221
|
+
it("renders the document", () => {
|
|
207
222
|
const wrapper = mount(
|
|
208
223
|
<StructuredText
|
|
209
224
|
data={structuredText}
|
|
210
225
|
renderInlineRecord={({ record }) => {
|
|
211
226
|
switch (record.__typename) {
|
|
212
|
-
case
|
|
227
|
+
case "DocPageRecord":
|
|
213
228
|
return <a href={`/docs/${record.slug}`}>{record.title}</a>;
|
|
214
229
|
default:
|
|
215
230
|
return null;
|
|
@@ -217,7 +232,7 @@ describe('StructuredText', () => {
|
|
|
217
232
|
}}
|
|
218
233
|
renderLinkToRecord={({ record, children, transformedMeta }) => {
|
|
219
234
|
switch (record.__typename) {
|
|
220
|
-
case
|
|
235
|
+
case "DocPageRecord":
|
|
221
236
|
return (
|
|
222
237
|
<a {...transformedMeta} href={`/docs/${record.slug}`}>
|
|
223
238
|
{children}
|
|
@@ -229,7 +244,7 @@ describe('StructuredText', () => {
|
|
|
229
244
|
}}
|
|
230
245
|
renderBlock={({ record }) => {
|
|
231
246
|
switch (record.__typename) {
|
|
232
|
-
case
|
|
247
|
+
case "QuoteRecord":
|
|
233
248
|
return (
|
|
234
249
|
<figure>
|
|
235
250
|
<blockquote>{record.quote}</blockquote>
|
|
@@ -240,22 +255,30 @@ describe('StructuredText', () => {
|
|
|
240
255
|
return null;
|
|
241
256
|
}
|
|
242
257
|
}}
|
|
243
|
-
|
|
258
|
+
renderInlineBlock={({ record }) => {
|
|
259
|
+
switch (record.__typename) {
|
|
260
|
+
case "MentionRecord":
|
|
261
|
+
return <em>{record.name}</em>;
|
|
262
|
+
default:
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
}}
|
|
266
|
+
/>
|
|
244
267
|
);
|
|
245
268
|
expect(wrapper).toMatchSnapshot();
|
|
246
269
|
});
|
|
247
270
|
});
|
|
248
271
|
|
|
249
|
-
describe(
|
|
250
|
-
it(
|
|
272
|
+
describe("with missing renderInlineRecord prop", () => {
|
|
273
|
+
it("raises an error", () => {
|
|
251
274
|
expect(() => {
|
|
252
275
|
shallow(<StructuredText data={structuredText} />);
|
|
253
276
|
}).toThrow(RenderError);
|
|
254
277
|
});
|
|
255
278
|
});
|
|
256
279
|
|
|
257
|
-
describe(
|
|
258
|
-
it(
|
|
280
|
+
describe("with missing record", () => {
|
|
281
|
+
it("raises an error", () => {
|
|
259
282
|
expect(() => {
|
|
260
283
|
shallow(
|
|
261
284
|
<StructuredText
|
|
@@ -263,7 +286,7 @@ describe('StructuredText', () => {
|
|
|
263
286
|
renderInlineRecord={() => {
|
|
264
287
|
return null;
|
|
265
288
|
}}
|
|
266
|
-
|
|
289
|
+
/>
|
|
267
290
|
);
|
|
268
291
|
}).toThrow(RenderError);
|
|
269
292
|
});
|
|
@@ -17,6 +17,7 @@ import {
|
|
|
17
17
|
type Record as StructuredTextGraphQlResponseRecord,
|
|
18
18
|
type TypesafeStructuredText as TypesafeStructuredTextGraphQlResponse,
|
|
19
19
|
isBlock,
|
|
20
|
+
isInlineBlock,
|
|
20
21
|
isInlineItem,
|
|
21
22
|
isItemLink,
|
|
22
23
|
isStructuredText,
|
|
@@ -104,6 +105,8 @@ export type StructuredTextPropTypes<
|
|
|
104
105
|
) => ReactElement | null;
|
|
105
106
|
/** Fuction that converts a 'block' node into React **/
|
|
106
107
|
renderBlock?: (context: RenderBlockContext<R1>) => ReactElement | null;
|
|
108
|
+
/** Fuction that converts an 'inlineBlock' node into React **/
|
|
109
|
+
renderInlineBlock?: (context: RenderBlockContext<R1>) => ReactElement | null;
|
|
107
110
|
/** Function that converts 'link' and 'itemLink' `meta` into HTML props */
|
|
108
111
|
metaTransformer?: TransformMetaFn;
|
|
109
112
|
/** Fuction that converts a simple string text into React **/
|
|
@@ -124,6 +127,7 @@ export function StructuredText<
|
|
|
124
127
|
renderInlineRecord,
|
|
125
128
|
renderLinkToRecord,
|
|
126
129
|
renderBlock,
|
|
130
|
+
renderInlineBlock,
|
|
127
131
|
renderText,
|
|
128
132
|
renderNode,
|
|
129
133
|
renderFragment,
|
|
@@ -234,6 +238,32 @@ export function StructuredText<
|
|
|
234
238
|
|
|
235
239
|
return appendKeyToValidElement(renderBlock({ record: item }), key);
|
|
236
240
|
}),
|
|
241
|
+
renderNodeRule(isInlineBlock, ({ node, key }) => {
|
|
242
|
+
if (!renderInlineBlock) {
|
|
243
|
+
throw new RenderError(
|
|
244
|
+
`The Structured Text document contains an 'inlineBlock' node, but no 'renderInlineBlock' prop is specified!`,
|
|
245
|
+
node,
|
|
246
|
+
);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
if (!(isStructuredText(data) && data.blocks)) {
|
|
250
|
+
throw new RenderError(
|
|
251
|
+
`The document contains an 'inlineBlock' node, but the passed data prop is not a Structured Text GraphQL response, or data.blocks is not present!`,
|
|
252
|
+
node,
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
const item = data.blocks.find((item) => item.id === node.item);
|
|
257
|
+
|
|
258
|
+
if (!item) {
|
|
259
|
+
throw new RenderError(
|
|
260
|
+
`The Structured Text document contains an 'inlineBlock' node, but cannot find a record with ID ${node.item} inside data.blocks!`,
|
|
261
|
+
node,
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
return appendKeyToValidElement(renderInlineBlock({ record: item }), key);
|
|
266
|
+
}),
|
|
237
267
|
...(customNodeRules || customRules || []),
|
|
238
268
|
],
|
|
239
269
|
});
|
|
@@ -161,6 +161,7 @@ export function useSiteSearch<Client extends GenericClient>(
|
|
|
161
161
|
query: state.query,
|
|
162
162
|
locale: state.locale,
|
|
163
163
|
build_trigger_id: config.buildTriggerId,
|
|
164
|
+
...(config.fuzzySearch === true ? { fuzzy: true } : {}),
|
|
164
165
|
},
|
|
165
166
|
page: {
|
|
166
167
|
limit: resultsPerPage,
|
|
@@ -168,10 +169,6 @@ export function useSiteSearch<Client extends GenericClient>(
|
|
|
168
169
|
},
|
|
169
170
|
};
|
|
170
171
|
|
|
171
|
-
if (config.fuzzySearch) {
|
|
172
|
-
request.fuzzy = 'true';
|
|
173
|
-
}
|
|
174
|
-
|
|
175
172
|
const response = await config.client.searchResults.rawList(request);
|
|
176
173
|
|
|
177
174
|
if (!isCancelled) {
|