tinacms 0.68.13 → 0.69.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/dist/admin/api.d.ts +1 -1
- package/dist/admin/components/GetCollection.d.ts +4 -2
- package/dist/client.es.js +11 -4
- package/dist/client.js +11 -4
- package/dist/index.d.ts +2 -1
- package/dist/index.es.js +147 -63
- package/dist/index.js +145 -61
- package/dist/{rich-text.d.ts → rich-text/index.d.ts} +6 -0
- package/dist/rich-text/index.es.js +221 -0
- package/dist/{rich-text.js → rich-text/index.js} +142 -144
- package/dist/style.css +11 -2
- package/dist/tina-cms.d.ts +1 -131
- package/dist/types/cms.d.ts +64 -0
- package/dist/unifiedClient/index.d.ts +2 -2
- package/package.json +15 -8
- package/dist/rich-text.es.js +0 -223
package/dist/index.js
CHANGED
|
@@ -2477,7 +2477,6 @@ mutation addPendingDocumentMutation(
|
|
|
2477
2477
|
constructor(cms) {
|
|
2478
2478
|
this.api = cms.api.tina;
|
|
2479
2479
|
this.schema = cms.api.tina.schema;
|
|
2480
|
-
this.useDataLayer = cms.flags.get("experimentalData");
|
|
2481
2480
|
}
|
|
2482
2481
|
async isAuthenticated() {
|
|
2483
2482
|
return await this.api.isAuthenticated();
|
|
@@ -2502,11 +2501,10 @@ mutation addPendingDocumentMutation(
|
|
|
2502
2501
|
}
|
|
2503
2502
|
}`, { variables: { collection, relativePath } });
|
|
2504
2503
|
}
|
|
2505
|
-
async fetchCollection(collectionName, includeDocuments, after) {
|
|
2504
|
+
async fetchCollection(collectionName, includeDocuments, after, sortKey, order) {
|
|
2506
2505
|
if (includeDocuments === true) {
|
|
2507
|
-
|
|
2508
|
-
|
|
2509
|
-
const response = await this.api.request(`#graphql
|
|
2506
|
+
const sort = sortKey || this.schema.getIsTitleFieldName(collectionName);
|
|
2507
|
+
const response = order === "asc" ? await this.api.request(`#graphql
|
|
2510
2508
|
query($collection: String!, $includeDocuments: Boolean!, $sort: String, $limit: Float, $after: String){
|
|
2511
2509
|
collection(collection: $collection){
|
|
2512
2510
|
name
|
|
@@ -2540,45 +2538,56 @@ mutation addPendingDocumentMutation(
|
|
|
2540
2538
|
}
|
|
2541
2539
|
}
|
|
2542
2540
|
}`, {
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2546
|
-
|
|
2547
|
-
|
|
2548
|
-
|
|
2541
|
+
variables: {
|
|
2542
|
+
collection: collectionName,
|
|
2543
|
+
includeDocuments,
|
|
2544
|
+
sort,
|
|
2545
|
+
limit: 10,
|
|
2546
|
+
after
|
|
2547
|
+
}
|
|
2548
|
+
}) : await this.api.request(`#graphql
|
|
2549
|
+
query($collection: String!, $includeDocuments: Boolean!, $sort: String, $limit: Float, $after: String){
|
|
2550
|
+
collection(collection: $collection){
|
|
2551
|
+
name
|
|
2552
|
+
label
|
|
2553
|
+
format
|
|
2554
|
+
templates
|
|
2555
|
+
documents(sort: $sort, before: $after, last: $limit) @include(if: $includeDocuments) {
|
|
2556
|
+
totalCount
|
|
2557
|
+
pageInfo {
|
|
2558
|
+
hasPreviousPage
|
|
2559
|
+
hasNextPage
|
|
2560
|
+
startCursor
|
|
2561
|
+
endCursor
|
|
2549
2562
|
}
|
|
2550
|
-
|
|
2551
|
-
|
|
2552
|
-
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
node {
|
|
2564
|
-
... on Document {
|
|
2565
|
-
_sys {
|
|
2566
|
-
template
|
|
2567
|
-
breadcrumbs
|
|
2568
|
-
path
|
|
2569
|
-
basename
|
|
2570
|
-
relativePath
|
|
2571
|
-
filename
|
|
2572
|
-
extension
|
|
2563
|
+
edges {
|
|
2564
|
+
node {
|
|
2565
|
+
... on Document {
|
|
2566
|
+
_sys {
|
|
2567
|
+
title
|
|
2568
|
+
template
|
|
2569
|
+
breadcrumbs
|
|
2570
|
+
path
|
|
2571
|
+
basename
|
|
2572
|
+
relativePath
|
|
2573
|
+
filename
|
|
2574
|
+
extension
|
|
2575
|
+
}
|
|
2573
2576
|
}
|
|
2574
2577
|
}
|
|
2575
2578
|
}
|
|
2576
2579
|
}
|
|
2577
2580
|
}
|
|
2578
|
-
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2581
|
+
}`, {
|
|
2582
|
+
variables: {
|
|
2583
|
+
collection: collectionName,
|
|
2584
|
+
includeDocuments,
|
|
2585
|
+
sort,
|
|
2586
|
+
limit: 10,
|
|
2587
|
+
after
|
|
2588
|
+
}
|
|
2589
|
+
});
|
|
2590
|
+
return response.collection;
|
|
2582
2591
|
} else {
|
|
2583
2592
|
try {
|
|
2584
2593
|
const collection = this.schema.getCollection(collectionName);
|
|
@@ -3330,6 +3339,9 @@ mutation addPendingDocumentMutation(
|
|
|
3330
3339
|
.tina-tailwind .gap-4 {
|
|
3331
3340
|
gap: 16px;
|
|
3332
3341
|
}
|
|
3342
|
+
.tina-tailwind .gap-2 {
|
|
3343
|
+
gap: 8px;
|
|
3344
|
+
}
|
|
3333
3345
|
.tina-tailwind .gap-3 {
|
|
3334
3346
|
gap: 12px;
|
|
3335
3347
|
}
|
|
@@ -3348,6 +3360,9 @@ mutation addPendingDocumentMutation(
|
|
|
3348
3360
|
.tina-tailwind .overflow-y-auto {
|
|
3349
3361
|
overflow-y: auto;
|
|
3350
3362
|
}
|
|
3363
|
+
.tina-tailwind .whitespace-normal {
|
|
3364
|
+
white-space: normal;
|
|
3365
|
+
}
|
|
3351
3366
|
.tina-tailwind .whitespace-nowrap {
|
|
3352
3367
|
white-space: nowrap;
|
|
3353
3368
|
}
|
|
@@ -3469,8 +3484,8 @@ mutation addPendingDocumentMutation(
|
|
|
3469
3484
|
.tina-tailwind .pb-4 {
|
|
3470
3485
|
padding-bottom: 16px;
|
|
3471
3486
|
}
|
|
3472
|
-
.tina-tailwind .pt-
|
|
3473
|
-
padding-top:
|
|
3487
|
+
.tina-tailwind .pt-16 {
|
|
3488
|
+
padding-top: 64px;
|
|
3474
3489
|
}
|
|
3475
3490
|
.tina-tailwind .pt-3 {
|
|
3476
3491
|
padding-top: 12px;
|
|
@@ -3514,6 +3529,9 @@ mutation addPendingDocumentMutation(
|
|
|
3514
3529
|
.tina-tailwind .font-medium {
|
|
3515
3530
|
font-weight: 500;
|
|
3516
3531
|
}
|
|
3532
|
+
.tina-tailwind .font-semibold {
|
|
3533
|
+
font-weight: 600;
|
|
3534
|
+
}
|
|
3517
3535
|
.tina-tailwind .uppercase {
|
|
3518
3536
|
text-transform: uppercase;
|
|
3519
3537
|
}
|
|
@@ -4016,16 +4034,18 @@ mutation addPendingDocumentMutation(
|
|
|
4016
4034
|
...props
|
|
4017
4035
|
}) => {
|
|
4018
4036
|
var _a;
|
|
4019
|
-
|
|
4020
|
-
|
|
4021
|
-
if (!apiURL && !validOldSetup) {
|
|
4022
|
-
throw new Error(`Must provide apiUrl or a client to the TinaWrapper component`);
|
|
4037
|
+
if (props == null ? void 0 : props.apiURL) {
|
|
4038
|
+
console.warn("The apiURL prop is deprecated. Please see https://tina.io/blog/tina-v-0.68.14 for information on how to upgrade to the new API");
|
|
4023
4039
|
}
|
|
4040
|
+
const apiURL = ((_a = props == null ? void 0 : props.client) == null ? void 0 : _a.apiUrl) || (props == null ? void 0 : props.apiURL);
|
|
4024
4041
|
const { branch, clientId, isLocalClient } = apiURL ? parseURL(apiURL) : {
|
|
4025
4042
|
branch: props.branch,
|
|
4026
4043
|
clientId: props.clientId,
|
|
4027
|
-
isLocalClient: props.isLocalClient
|
|
4044
|
+
isLocalClient: props == null ? void 0 : props.isLocalClient
|
|
4028
4045
|
};
|
|
4046
|
+
if (typeof isLocalClient === "undefined" || !isLocalClient && (!branch || !clientId)) {
|
|
4047
|
+
throw new Error("Invalid setup. See https://tina.io/docs/tina-cloud/connecting-site/ for more information.");
|
|
4048
|
+
}
|
|
4029
4049
|
if (!schema) {
|
|
4030
4050
|
throw new Error("`schema` is required to be passed as a property to `TinaProvider`. You can learn more about this change here: https://github.com/tinacms/tinacms/pull/2823");
|
|
4031
4051
|
}
|
|
@@ -4608,7 +4628,7 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4608
4628
|
isLocalMode,
|
|
4609
4629
|
children
|
|
4610
4630
|
}) => /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, isLocalMode && /* @__PURE__ */ React__default["default"].createElement(toolkit.LocalWarning, null), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
4611
|
-
className: "bg-white pb-4 pt-
|
|
4631
|
+
className: "bg-white pb-4 pt-16 border-b border-gray-200 px-12"
|
|
4612
4632
|
}, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
4613
4633
|
className: "w-full mx-auto max-w-screen-xl"
|
|
4614
4634
|
}, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
@@ -4735,8 +4755,10 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4735
4755
|
fontWeight: "normal"
|
|
4736
4756
|
}
|
|
4737
4757
|
}, "Please wait, Tina is loading data..."))));
|
|
4738
|
-
const useGetCollection = (cms, collectionName, includeDocuments = true, after = "") => {
|
|
4758
|
+
const useGetCollection = (cms, collectionName, includeDocuments = true, after = "", sortKey) => {
|
|
4739
4759
|
const api = new TinaAdminApi(cms);
|
|
4760
|
+
const schema = cms.api.tina.schema;
|
|
4761
|
+
const collectionExtra = schema.getCollection(collectionName);
|
|
4740
4762
|
const [collection, setCollection] = React.useState(void 0);
|
|
4741
4763
|
const [loading, setLoading] = React.useState(true);
|
|
4742
4764
|
const [error, setError] = React.useState(void 0);
|
|
@@ -4744,8 +4766,10 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4744
4766
|
React.useEffect(() => {
|
|
4745
4767
|
const fetchCollection = async () => {
|
|
4746
4768
|
if (await api.isAuthenticated()) {
|
|
4769
|
+
const { name, order } = JSON.parse(sortKey || "{}");
|
|
4770
|
+
const validSortKey = collectionExtra.fields.map((x) => x.name).includes(name) ? name : void 0;
|
|
4747
4771
|
try {
|
|
4748
|
-
const collection2 = await api.fetchCollection(collectionName, includeDocuments, after);
|
|
4772
|
+
const collection2 = await api.fetchCollection(collectionName, includeDocuments, after, validSortKey, order);
|
|
4749
4773
|
setCollection(collection2);
|
|
4750
4774
|
} catch (error2) {
|
|
4751
4775
|
cms.alerts.error(`[${error2.name}] GetCollection failed: ${error2.message}`, 30 * 1e3);
|
|
@@ -4758,26 +4782,29 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4758
4782
|
};
|
|
4759
4783
|
setLoading(true);
|
|
4760
4784
|
fetchCollection();
|
|
4761
|
-
}, [cms, collectionName, resetState, after]);
|
|
4785
|
+
}, [cms, collectionName, resetState, after, sortKey]);
|
|
4762
4786
|
const reFetchCollection = () => setResetSate((x) => x + 1);
|
|
4763
|
-
return { collection, loading, error, reFetchCollection };
|
|
4787
|
+
return { collection, loading, error, reFetchCollection, collectionExtra };
|
|
4764
4788
|
};
|
|
4765
4789
|
const GetCollection = ({
|
|
4766
4790
|
cms,
|
|
4767
4791
|
collectionName,
|
|
4768
4792
|
includeDocuments = true,
|
|
4769
4793
|
startCursor,
|
|
4794
|
+
sortKey,
|
|
4770
4795
|
children
|
|
4771
4796
|
}) => {
|
|
4772
|
-
const { collection, loading, error, reFetchCollection } = useGetCollection(cms, collectionName, includeDocuments, startCursor || "");
|
|
4797
|
+
const { collection, loading, error, reFetchCollection, collectionExtra } = useGetCollection(cms, collectionName, includeDocuments, startCursor || "", sortKey) || {};
|
|
4773
4798
|
if (error) {
|
|
4774
4799
|
return null;
|
|
4775
4800
|
}
|
|
4776
4801
|
if (loading) {
|
|
4777
4802
|
return /* @__PURE__ */ React__default["default"].createElement(LoadingPage, null);
|
|
4778
4803
|
}
|
|
4779
|
-
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children(collection, loading, reFetchCollection));
|
|
4804
|
+
return /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, children(collection, loading, reFetchCollection, collectionExtra));
|
|
4780
4805
|
};
|
|
4806
|
+
const LOCAL_STORAGE_KEY = "tinacms.admin.collection.list.page";
|
|
4807
|
+
const isSSR = typeof window === "undefined";
|
|
4781
4808
|
const TemplateMenu = ({ templates }) => {
|
|
4782
4809
|
return /* @__PURE__ */ React__default["default"].createElement(react.Menu, {
|
|
4783
4810
|
as: "div",
|
|
@@ -4826,8 +4853,17 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4826
4853
|
});
|
|
4827
4854
|
const [endCursor, setEndCursor] = React.useState("");
|
|
4828
4855
|
const [prevCursors, setPrevCursors] = React.useState([]);
|
|
4856
|
+
const [sortKey, setSortKey] = React.useState(isSSR ? "" : window.localStorage.getItem(`${LOCAL_STORAGE_KEY}.${collectionName}`) || JSON.stringify({
|
|
4857
|
+
order: "asc",
|
|
4858
|
+
name: ""
|
|
4859
|
+
}));
|
|
4860
|
+
const [sortOrder, setSortOrder] = React.useState("asc");
|
|
4829
4861
|
const loc = reactRouterDom.useLocation();
|
|
4830
4862
|
React.useEffect(() => {
|
|
4863
|
+
setSortKey(window.localStorage.getItem(`${LOCAL_STORAGE_KEY}.${collectionName}`) || JSON.stringify({
|
|
4864
|
+
order: "asc",
|
|
4865
|
+
name: ""
|
|
4866
|
+
}));
|
|
4831
4867
|
setEndCursor("");
|
|
4832
4868
|
setPrevCursors([]);
|
|
4833
4869
|
}, [loc]);
|
|
@@ -4836,14 +4872,15 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4836
4872
|
cms,
|
|
4837
4873
|
collectionName,
|
|
4838
4874
|
includeDocuments: true,
|
|
4839
|
-
startCursor: endCursor
|
|
4840
|
-
|
|
4875
|
+
startCursor: endCursor,
|
|
4876
|
+
sortKey
|
|
4877
|
+
}, (collection, _loading, reFetchCollection, collectionExtra) => {
|
|
4841
4878
|
var _a, _b;
|
|
4842
4879
|
const totalCount = collection.documents.totalCount;
|
|
4843
4880
|
const documents = collection.documents.edges;
|
|
4844
4881
|
const admin = cms.api.admin;
|
|
4845
4882
|
const pageInfo = collection.documents.pageInfo;
|
|
4846
|
-
const
|
|
4883
|
+
const fields = collectionExtra.fields.filter((x) => ["string", "number", "datetime"].includes(x.type));
|
|
4847
4884
|
return /* @__PURE__ */ React__default["default"].createElement(PageWrapper, null, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, open && /* @__PURE__ */ React__default["default"].createElement(DeleteModal, {
|
|
4848
4885
|
filename: vars.relativePath,
|
|
4849
4886
|
deleteFunc: async () => {
|
|
@@ -4860,9 +4897,56 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4860
4897
|
close: () => setOpen(false)
|
|
4861
4898
|
}), /* @__PURE__ */ React__default["default"].createElement(PageHeader, {
|
|
4862
4899
|
isLocalMode: (_b = (_a = cms == null ? void 0 : cms.api) == null ? void 0 : _a.tina) == null ? void 0 : _b.isLocalMode
|
|
4863
|
-
}, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("
|
|
4900
|
+
}, /* @__PURE__ */ React__default["default"].createElement(React__default["default"].Fragment, null, /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
4901
|
+
className: "flex flex-col gap-4"
|
|
4902
|
+
}, /* @__PURE__ */ React__default["default"].createElement("h3", {
|
|
4864
4903
|
className: "font-sans text-2xl text-gray-700"
|
|
4865
|
-
}, collection.label ? collection.label : collection.name),
|
|
4904
|
+
}, collection.label ? collection.label : collection.name), fields.length > 0 && /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
4905
|
+
className: "flex gap-2 items-center"
|
|
4906
|
+
}, /* @__PURE__ */ React__default["default"].createElement("label", {
|
|
4907
|
+
htmlFor: "sort",
|
|
4908
|
+
className: "block font-sans text-xs font-semibold text-gray-500 whitespace-normal"
|
|
4909
|
+
}, "Sort by"), /* @__PURE__ */ React__default["default"].createElement(toolkit.Select, {
|
|
4910
|
+
name: "sort",
|
|
4911
|
+
options: [
|
|
4912
|
+
{
|
|
4913
|
+
label: "Default",
|
|
4914
|
+
value: JSON.stringify({
|
|
4915
|
+
order: "asc",
|
|
4916
|
+
name: ""
|
|
4917
|
+
})
|
|
4918
|
+
},
|
|
4919
|
+
...fields.map((x) => [
|
|
4920
|
+
{
|
|
4921
|
+
label: x.label + " (Ascending)",
|
|
4922
|
+
value: JSON.stringify({
|
|
4923
|
+
name: x.name,
|
|
4924
|
+
order: "asc"
|
|
4925
|
+
})
|
|
4926
|
+
},
|
|
4927
|
+
{
|
|
4928
|
+
label: x.label + " (Descending)",
|
|
4929
|
+
value: JSON.stringify({
|
|
4930
|
+
name: x.name,
|
|
4931
|
+
order: "desc"
|
|
4932
|
+
})
|
|
4933
|
+
}
|
|
4934
|
+
]).flat()
|
|
4935
|
+
],
|
|
4936
|
+
input: {
|
|
4937
|
+
id: "sort",
|
|
4938
|
+
name: "sort",
|
|
4939
|
+
value: sortKey,
|
|
4940
|
+
onChange: (e) => {
|
|
4941
|
+
const val = JSON.parse(e.target.value);
|
|
4942
|
+
setEndCursor("");
|
|
4943
|
+
setPrevCursors([]);
|
|
4944
|
+
window == null ? void 0 : window.localStorage.setItem(`${LOCAL_STORAGE_KEY}.${collectionName}`, e.target.value);
|
|
4945
|
+
setSortKey(e.target.value);
|
|
4946
|
+
setSortOrder(val.order);
|
|
4947
|
+
}
|
|
4948
|
+
}
|
|
4949
|
+
}))), !collection.templates && /* @__PURE__ */ React__default["default"].createElement(reactRouterDom.Link, {
|
|
4866
4950
|
to: `new`,
|
|
4867
4951
|
className: "icon-parent inline-flex items-center font-medium focus:outline-none focus:ring-2 focus:shadow-outline text-center rounded-full justify-center transition-all duration-150 ease-out shadow text-white bg-blue-500 hover:bg-blue-600 focus:ring-blue-500 text-sm h-10 px-6"
|
|
4868
4952
|
}, "Create New", " ", /* @__PURE__ */ React__default["default"].createElement(BiPlus, {
|
|
@@ -4946,11 +5030,11 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
4946
5030
|
}
|
|
4947
5031
|
]
|
|
4948
5032
|
})));
|
|
4949
|
-
}))),
|
|
5033
|
+
}))), /* @__PURE__ */ React__default["default"].createElement("div", {
|
|
4950
5034
|
className: "pt-3"
|
|
4951
5035
|
}, /* @__PURE__ */ React__default["default"].createElement(toolkit.CursorPaginator, {
|
|
4952
5036
|
variant: "white",
|
|
4953
|
-
hasNext: pageInfo == null ? void 0 : pageInfo.hasNextPage,
|
|
5037
|
+
hasNext: sortOrder === "asc" ? pageInfo == null ? void 0 : pageInfo.hasNextPage : pageInfo.hasPreviousPage,
|
|
4954
5038
|
navigateNext: () => {
|
|
4955
5039
|
const newState = [...prevCursors, endCursor];
|
|
4956
5040
|
setPrevCursors(newState);
|
|
@@ -5288,9 +5372,9 @@ This will work when developing locally but NOT when deployed to production.
|
|
|
5288
5372
|
return null;
|
|
5289
5373
|
};
|
|
5290
5374
|
const TinaAdmin = () => {
|
|
5291
|
-
const
|
|
5375
|
+
const isSSR2 = typeof window === "undefined";
|
|
5292
5376
|
const { edit } = sharedctx.useEditState();
|
|
5293
|
-
if (
|
|
5377
|
+
if (isSSR2) {
|
|
5294
5378
|
return null;
|
|
5295
5379
|
}
|
|
5296
5380
|
if (!edit) {
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
const TinaMarkdown = ({
|
|
3
|
+
content,
|
|
4
|
+
components = {}
|
|
5
|
+
}) => {
|
|
6
|
+
if (!content) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
const nodes = Array.isArray(content) ? content : content.children;
|
|
10
|
+
if (!nodes) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, nodes.map((child, index) => {
|
|
14
|
+
return /* @__PURE__ */ React.createElement(MemoNode, {
|
|
15
|
+
components,
|
|
16
|
+
key: index,
|
|
17
|
+
child
|
|
18
|
+
});
|
|
19
|
+
}));
|
|
20
|
+
};
|
|
21
|
+
const Leaf = (props) => {
|
|
22
|
+
if (props.bold) {
|
|
23
|
+
const { bold, ...rest } = props;
|
|
24
|
+
if (props.components.bold) {
|
|
25
|
+
const Component = props.components.bold;
|
|
26
|
+
return /* @__PURE__ */ React.createElement(Component, null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
27
|
+
...rest
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
return /* @__PURE__ */ React.createElement("strong", null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
31
|
+
...rest
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
if (props.italic) {
|
|
35
|
+
const { italic, ...rest } = props;
|
|
36
|
+
if (props.components.italic) {
|
|
37
|
+
const Component = props.components.italic;
|
|
38
|
+
return /* @__PURE__ */ React.createElement(Component, null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
39
|
+
...rest
|
|
40
|
+
}));
|
|
41
|
+
}
|
|
42
|
+
return /* @__PURE__ */ React.createElement("em", null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
43
|
+
...rest
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
if (props.underline) {
|
|
47
|
+
const { underline, ...rest } = props;
|
|
48
|
+
if (props.components.underline) {
|
|
49
|
+
const Component = props.components.underline;
|
|
50
|
+
return /* @__PURE__ */ React.createElement(Component, null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
51
|
+
...rest
|
|
52
|
+
}));
|
|
53
|
+
}
|
|
54
|
+
return /* @__PURE__ */ React.createElement("u", null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
55
|
+
...rest
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
if (props.strikethrough) {
|
|
59
|
+
const { strikethrough, ...rest } = props;
|
|
60
|
+
if (props.components.strikethrough) {
|
|
61
|
+
const Component = props.components.strikethrough;
|
|
62
|
+
return /* @__PURE__ */ React.createElement(Component, null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
63
|
+
...rest
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
66
|
+
return /* @__PURE__ */ React.createElement("s", null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
67
|
+
...rest
|
|
68
|
+
}));
|
|
69
|
+
}
|
|
70
|
+
if (props.code) {
|
|
71
|
+
const { code, ...rest } = props;
|
|
72
|
+
if (props.components.code) {
|
|
73
|
+
const Component = props.components.code;
|
|
74
|
+
return /* @__PURE__ */ React.createElement(Component, null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
75
|
+
...rest
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
return /* @__PURE__ */ React.createElement("code", null, /* @__PURE__ */ React.createElement(Leaf, {
|
|
79
|
+
...rest
|
|
80
|
+
}));
|
|
81
|
+
}
|
|
82
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, props.text);
|
|
83
|
+
};
|
|
84
|
+
const MemoNode = (props) => {
|
|
85
|
+
const MNode = React.useMemo(() => /* @__PURE__ */ React.createElement(Node, {
|
|
86
|
+
...props
|
|
87
|
+
}), [JSON.stringify(props)]);
|
|
88
|
+
return MNode;
|
|
89
|
+
};
|
|
90
|
+
const Node = ({ components, child }) => {
|
|
91
|
+
const { children, ...props } = child;
|
|
92
|
+
switch (child.type) {
|
|
93
|
+
case "h1":
|
|
94
|
+
case "h2":
|
|
95
|
+
case "h3":
|
|
96
|
+
case "h4":
|
|
97
|
+
case "h5":
|
|
98
|
+
case "h6":
|
|
99
|
+
case "p":
|
|
100
|
+
case "blockquote":
|
|
101
|
+
case "ol":
|
|
102
|
+
case "ul":
|
|
103
|
+
case "li":
|
|
104
|
+
if (components[child.type]) {
|
|
105
|
+
const Component2 = components[child.type];
|
|
106
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
107
|
+
...props
|
|
108
|
+
}, /* @__PURE__ */ React.createElement(TinaMarkdown, {
|
|
109
|
+
components,
|
|
110
|
+
content: children
|
|
111
|
+
}));
|
|
112
|
+
}
|
|
113
|
+
return React.createElement(child.type, {
|
|
114
|
+
children: /* @__PURE__ */ React.createElement(TinaMarkdown, {
|
|
115
|
+
components,
|
|
116
|
+
content: children
|
|
117
|
+
})
|
|
118
|
+
});
|
|
119
|
+
case "lic":
|
|
120
|
+
return /* @__PURE__ */ React.createElement("div", null, /* @__PURE__ */ React.createElement(TinaMarkdown, {
|
|
121
|
+
components,
|
|
122
|
+
content: child.children
|
|
123
|
+
}));
|
|
124
|
+
case "img":
|
|
125
|
+
if (components[child.type]) {
|
|
126
|
+
const Component2 = components[child.type];
|
|
127
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
128
|
+
...props
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
return /* @__PURE__ */ React.createElement("img", {
|
|
132
|
+
src: child.url,
|
|
133
|
+
alt: child.caption
|
|
134
|
+
});
|
|
135
|
+
case "a":
|
|
136
|
+
if (components[child.type]) {
|
|
137
|
+
const Component2 = components[child.type];
|
|
138
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
139
|
+
...props
|
|
140
|
+
}, /* @__PURE__ */ React.createElement(TinaMarkdown, {
|
|
141
|
+
components,
|
|
142
|
+
content: children
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
return /* @__PURE__ */ React.createElement("a", {
|
|
146
|
+
href: child.url
|
|
147
|
+
}, /* @__PURE__ */ React.createElement(TinaMarkdown, {
|
|
148
|
+
components,
|
|
149
|
+
content: children
|
|
150
|
+
}));
|
|
151
|
+
case "code_block":
|
|
152
|
+
const value = child.value;
|
|
153
|
+
if (components[child.type]) {
|
|
154
|
+
const Component2 = components[child.type];
|
|
155
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
156
|
+
...props
|
|
157
|
+
}, value);
|
|
158
|
+
}
|
|
159
|
+
return /* @__PURE__ */ React.createElement("pre", null, /* @__PURE__ */ React.createElement("code", null, value));
|
|
160
|
+
case "hr":
|
|
161
|
+
if (components[child.type]) {
|
|
162
|
+
const Component2 = components[child.type];
|
|
163
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
164
|
+
...props
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
return /* @__PURE__ */ React.createElement("hr", null);
|
|
168
|
+
case "break":
|
|
169
|
+
if (components[child.type]) {
|
|
170
|
+
const Component2 = components[child.type];
|
|
171
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
172
|
+
...props
|
|
173
|
+
});
|
|
174
|
+
}
|
|
175
|
+
return /* @__PURE__ */ React.createElement("br", null);
|
|
176
|
+
case "text":
|
|
177
|
+
return /* @__PURE__ */ React.createElement(Leaf, {
|
|
178
|
+
components,
|
|
179
|
+
...child
|
|
180
|
+
});
|
|
181
|
+
case "mdxJsxTextElement":
|
|
182
|
+
case "mdxJsxFlowElement":
|
|
183
|
+
const Component = components[child.name];
|
|
184
|
+
if (Component) {
|
|
185
|
+
const props2 = child.props ? child.props : {};
|
|
186
|
+
return /* @__PURE__ */ React.createElement(Component, {
|
|
187
|
+
...props2
|
|
188
|
+
});
|
|
189
|
+
} else {
|
|
190
|
+
const ComponentMissing = components["component_missing"];
|
|
191
|
+
if (ComponentMissing) {
|
|
192
|
+
return /* @__PURE__ */ React.createElement(ComponentMissing, {
|
|
193
|
+
name: child.name
|
|
194
|
+
});
|
|
195
|
+
} else {
|
|
196
|
+
return /* @__PURE__ */ React.createElement("span", null, `No component provided for ${child.name}`);
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
case "maybe_mdx":
|
|
200
|
+
return null;
|
|
201
|
+
case "html":
|
|
202
|
+
case "html_inline":
|
|
203
|
+
if (components[child.type]) {
|
|
204
|
+
const Component2 = components[child.type];
|
|
205
|
+
return /* @__PURE__ */ React.createElement(Component2, {
|
|
206
|
+
...props
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
return child.value;
|
|
210
|
+
case "invalid_markdown":
|
|
211
|
+
return /* @__PURE__ */ React.createElement("pre", null, child.value);
|
|
212
|
+
default:
|
|
213
|
+
if (typeof child.text === "string") {
|
|
214
|
+
return /* @__PURE__ */ React.createElement(Leaf, {
|
|
215
|
+
components,
|
|
216
|
+
...child
|
|
217
|
+
});
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
export { TinaMarkdown };
|