tinacms 2.2.1 → 2.2.2

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.
@@ -0,0 +1,6 @@
1
+ export { NodeCache } from './node-cache';
2
+ export type Cache = {
3
+ get: (key: string) => Promise<any>;
4
+ makeKey: (key: any) => string;
5
+ set: (key: string, value: any) => Promise<void>;
6
+ };
@@ -0,0 +1,2 @@
1
+ import type { Cache } from './index';
2
+ export declare const NodeCache: (dir: string, fs: any) => Cache;
@@ -0,0 +1,4 @@
1
+ /**
2
+
3
+ */
4
+ export * from './cache/index';
package/dist/cache.js ADDED
@@ -0,0 +1,36 @@
1
+ (function(global, factory) {
2
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports) : typeof define === "function" && define.amd ? define(["exports"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.tinacms = {}));
3
+ })(this, function(exports2) {
4
+ "use strict";
5
+ const { createHash } = require("crypto");
6
+ const makeKey = (key) => {
7
+ const input = key && key instanceof Object ? JSON.stringify(key) : key || "";
8
+ return createHash("sha256").update(input).digest("hex");
9
+ };
10
+ const NodeCache = (dir, fs) => {
11
+ return {
12
+ makeKey,
13
+ get: async (key) => {
14
+ try {
15
+ const data = await fs.promises.readFile(`${dir}/${key}`, "utf-8");
16
+ return JSON.parse(data);
17
+ } catch (e) {
18
+ if (e.code === "ENOENT") {
19
+ return void 0;
20
+ }
21
+ throw e;
22
+ }
23
+ },
24
+ set: async (key, value) => {
25
+ await fs.promises.mkdir(dir, { recursive: true });
26
+ await fs.promises.writeFile(
27
+ `${dir}/${key}`,
28
+ JSON.stringify(value),
29
+ "utf-8"
30
+ );
31
+ }
32
+ };
33
+ };
34
+ exports2.NodeCache = NodeCache;
35
+ Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
36
+ });
package/dist/cache.mjs ADDED
@@ -0,0 +1,32 @@
1
+ const { createHash } = require("crypto");
2
+ const makeKey = (key) => {
3
+ const input = key && key instanceof Object ? JSON.stringify(key) : key || "";
4
+ return createHash("sha256").update(input).digest("hex");
5
+ };
6
+ const NodeCache = (dir, fs) => {
7
+ return {
8
+ makeKey,
9
+ get: async (key) => {
10
+ try {
11
+ const data = await fs.promises.readFile(`${dir}/${key}`, "utf-8");
12
+ return JSON.parse(data);
13
+ } catch (e) {
14
+ if (e.code === "ENOENT") {
15
+ return void 0;
16
+ }
17
+ throw e;
18
+ }
19
+ },
20
+ set: async (key, value) => {
21
+ await fs.promises.mkdir(dir, { recursive: true });
22
+ await fs.promises.writeFile(
23
+ `${dir}/${key}`,
24
+ JSON.stringify(value),
25
+ "utf-8"
26
+ );
27
+ }
28
+ };
29
+ };
30
+ export {
31
+ NodeCache
32
+ };
package/dist/client.js CHANGED
@@ -11,12 +11,17 @@
11
11
  token,
12
12
  url,
13
13
  queries,
14
- errorPolicy
14
+ errorPolicy,
15
+ cacheDir
15
16
  }) {
16
17
  this.apiUrl = url;
17
18
  this.readonlyToken = token == null ? void 0 : token.trim();
18
19
  this.queries = queries(this);
19
20
  this.errorPolicy = errorPolicy || "throw";
21
+ if (cacheDir && typeof require !== "undefined") {
22
+ const { NodeCache } = require("tinacms/dist/cache");
23
+ this.cache = NodeCache(cacheDir, require("fs"));
24
+ }
20
25
  }
21
26
  async request({ errorPolicy, ...args }, options) {
22
27
  var _a;
@@ -28,8 +33,8 @@
28
33
  headers.append("Content-Type", "application/json");
29
34
  if (options == null ? void 0 : options.fetchOptions) {
30
35
  if ((_a = options == null ? void 0 : options.fetchOptions) == null ? void 0 : _a.headers) {
31
- Object.entries(options.fetchOptions.headers).forEach(([key, value]) => {
32
- headers.append(key, value);
36
+ Object.entries(options.fetchOptions.headers).forEach(([key2, value]) => {
37
+ headers.append(key2, value);
33
38
  });
34
39
  }
35
40
  }
@@ -46,6 +51,14 @@
46
51
  redirect: "follow",
47
52
  ...providedFetchOptions
48
53
  };
54
+ let key = "";
55
+ if (this.cache) {
56
+ key = this.cache.makeKey(bodyString);
57
+ const value = await this.cache.get(key);
58
+ if (value) {
59
+ return value;
60
+ }
61
+ }
49
62
  const res = await fetchDefined(url, optionsObject);
50
63
  if (!res.ok) {
51
64
  let additionalInfo = "";
@@ -64,11 +77,15 @@
64
77
  ${json.errors.map((error) => error.message).join("\n")}`
65
78
  );
66
79
  }
67
- return {
80
+ const result = {
68
81
  data: json == null ? void 0 : json.data,
69
82
  errors: (json == null ? void 0 : json.errors) || null,
70
83
  query: args.query
71
84
  };
85
+ if (this.cache) {
86
+ await this.cache.set(key, result);
87
+ }
88
+ return result;
72
89
  }
73
90
  }
74
91
  function createClient(args) {
package/dist/client.mjs CHANGED
@@ -8,12 +8,17 @@ class TinaClient {
8
8
  token,
9
9
  url,
10
10
  queries,
11
- errorPolicy
11
+ errorPolicy,
12
+ cacheDir
12
13
  }) {
13
14
  this.apiUrl = url;
14
15
  this.readonlyToken = token == null ? void 0 : token.trim();
15
16
  this.queries = queries(this);
16
17
  this.errorPolicy = errorPolicy || "throw";
18
+ if (cacheDir && typeof require !== "undefined") {
19
+ const { NodeCache } = require("tinacms/dist/cache");
20
+ this.cache = NodeCache(cacheDir, require("fs"));
21
+ }
17
22
  }
18
23
  async request({ errorPolicy, ...args }, options) {
19
24
  var _a;
@@ -25,8 +30,8 @@ class TinaClient {
25
30
  headers.append("Content-Type", "application/json");
26
31
  if (options == null ? void 0 : options.fetchOptions) {
27
32
  if ((_a = options == null ? void 0 : options.fetchOptions) == null ? void 0 : _a.headers) {
28
- Object.entries(options.fetchOptions.headers).forEach(([key, value]) => {
29
- headers.append(key, value);
33
+ Object.entries(options.fetchOptions.headers).forEach(([key2, value]) => {
34
+ headers.append(key2, value);
30
35
  });
31
36
  }
32
37
  }
@@ -43,6 +48,14 @@ class TinaClient {
43
48
  redirect: "follow",
44
49
  ...providedFetchOptions
45
50
  };
51
+ let key = "";
52
+ if (this.cache) {
53
+ key = this.cache.makeKey(bodyString);
54
+ const value = await this.cache.get(key);
55
+ if (value) {
56
+ return value;
57
+ }
58
+ }
46
59
  const res = await fetchDefined(url, optionsObject);
47
60
  if (!res.ok) {
48
61
  let additionalInfo = "";
@@ -61,11 +74,15 @@ class TinaClient {
61
74
  ${json.errors.map((error) => error.message).join("\n")}`
62
75
  );
63
76
  }
64
- return {
77
+ const result = {
65
78
  data: json == null ? void 0 : json.data,
66
79
  errors: (json == null ? void 0 : json.errors) || null,
67
80
  query: args.query
68
81
  };
82
+ if (this.cache) {
83
+ await this.cache.set(key, result);
84
+ }
85
+ return result;
69
86
  }
70
87
  }
71
88
  function createClient(args) {
package/dist/index.js CHANGED
@@ -4508,6 +4508,26 @@ var __publicField = (obj, key, value) => {
4508
4508
  }
4509
4509
  ));
4510
4510
  CommandItem.displayName = cmdk.Command.Item.displayName;
4511
+ const OptionComponent = ({
4512
+ id,
4513
+ value,
4514
+ field,
4515
+ _values,
4516
+ node,
4517
+ onSelect
4518
+ }) => {
4519
+ return /* @__PURE__ */ React.createElement(
4520
+ CommandItem,
4521
+ {
4522
+ key: `${id}-option`,
4523
+ value: id,
4524
+ onSelect: (currentValue) => {
4525
+ onSelect(currentValue === value ? "" : currentValue);
4526
+ }
4527
+ },
4528
+ /* @__PURE__ */ React.createElement("div", { className: "flex flex-col w-full" }, (field == null ? void 0 : field.optionComponent) && _values ? field.optionComponent(_values, node._internalSys) : /* @__PURE__ */ React.createElement("span", { className: "text-x" }, id))
4529
+ );
4530
+ };
4511
4531
  const Popover = PopoverPrimitive__namespace.Root;
4512
4532
  const PopoverTrigger = PopoverPrimitive__namespace.Trigger;
4513
4533
  const PopoverContent = React__namespace.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ React__namespace.createElement(PopoverPrimitive__namespace.Portal, null, /* @__PURE__ */ React__namespace.createElement(
@@ -4599,10 +4619,16 @@ var __publicField = (obj, key, value) => {
4599
4619
  const [value, setValue] = React__namespace.useState(input.value);
4600
4620
  const [displayText, setDisplayText] = React__namespace.useState(null);
4601
4621
  const { optionSets, loading } = useGetOptionSets(cms, field.collections);
4622
+ const [filteredOptionsList, setFilteredOptionsList] = React__namespace.useState(optionSets);
4602
4623
  React__namespace.useEffect(() => {
4603
4624
  setDisplayText(getFilename(optionSets, value));
4604
4625
  input.onChange(value);
4605
4626
  }, [value, input, optionSets]);
4627
+ React__namespace.useEffect(() => {
4628
+ if (field.experimental___filter && optionSets.length > 0) {
4629
+ setFilteredOptionsList(field.experimental___filter(optionSets, void 0));
4630
+ }
4631
+ }, [optionSets, field.experimental___filter]);
4606
4632
  if (loading === true) {
4607
4633
  return /* @__PURE__ */ React__namespace.createElement(LoadingDots, { color: "var(--tina-color-primary)" });
4608
4634
  }
@@ -4619,41 +4645,52 @@ var __publicField = (obj, key, value) => {
4619
4645
  )), /* @__PURE__ */ React__namespace.createElement(PopoverContent, { className: "p-0 relative" }, /* @__PURE__ */ React__namespace.createElement(
4620
4646
  Command,
4621
4647
  {
4648
+ shouldFilter: !field.experimental___filter,
4622
4649
  filter: (value2, search) => {
4623
4650
  if (value2.toLowerCase().replace(/\//g, "").includes(search.toLowerCase()))
4624
4651
  return 1;
4625
4652
  return 0;
4626
4653
  }
4627
4654
  },
4628
- /* @__PURE__ */ React__namespace.createElement(CommandInput, { placeholder: "Search reference..." }),
4655
+ /* @__PURE__ */ React__namespace.createElement(
4656
+ CommandInput,
4657
+ {
4658
+ placeholder: "Search reference...",
4659
+ onValueChange: (search) => {
4660
+ if (field.experimental___filter) {
4661
+ setFilteredOptionsList(
4662
+ field.experimental___filter(optionSets, search)
4663
+ );
4664
+ }
4665
+ }
4666
+ }
4667
+ ),
4629
4668
  /* @__PURE__ */ React__namespace.createElement(CommandEmpty, null, "No reference found"),
4630
- /* @__PURE__ */ React__namespace.createElement(CommandList, null, optionSets.length > 0 && optionSets.map(({ collection, edges }) => /* @__PURE__ */ React__namespace.createElement(
4669
+ /* @__PURE__ */ React__namespace.createElement(CommandList, null, filteredOptionsList.length > 0 && (filteredOptionsList == null ? void 0 : filteredOptionsList.map(({ collection, edges }) => /* @__PURE__ */ React__namespace.createElement(
4631
4670
  CommandGroup,
4632
4671
  {
4633
4672
  key: `${collection}-group`,
4634
4673
  heading: collection
4635
4674
  },
4636
- /* @__PURE__ */ React__namespace.createElement(CommandList, null, edges.map(({ node }) => {
4675
+ /* @__PURE__ */ React__namespace.createElement(CommandList, null, edges == null ? void 0 : edges.map(({ node }) => {
4637
4676
  const { id, _values } = node;
4638
4677
  return /* @__PURE__ */ React__namespace.createElement(
4639
- CommandItem,
4678
+ OptionComponent,
4640
4679
  {
4641
- key: `${id}-option`,
4642
- value: id,
4680
+ id,
4681
+ key: id,
4682
+ value,
4683
+ field,
4684
+ _values,
4685
+ node,
4643
4686
  onSelect: (currentValue) => {
4644
- setValue(
4645
- currentValue === value ? "" : currentValue
4646
- );
4687
+ setValue(currentValue);
4647
4688
  setOpen(false);
4648
4689
  }
4649
- },
4650
- /* @__PURE__ */ React__namespace.createElement("div", { className: "flex flex-col" }, /* @__PURE__ */ React__namespace.createElement("div", null, (field == null ? void 0 : field.optionComponent) && _values ? field.optionComponent(
4651
- _values,
4652
- node._internalSys
4653
- ) : /* @__PURE__ */ React__namespace.createElement("span", { className: "text-x" }, id)))
4690
+ }
4654
4691
  );
4655
4692
  }))
4656
- )))
4693
+ ))))
4657
4694
  ))));
4658
4695
  };
4659
4696
  const useGetNode = (cms, id) => {
@@ -10683,6 +10720,7 @@ var __publicField = (obj, key, value) => {
10683
10720
  setLoadFolders(true);
10684
10721
  resetOffset();
10685
10722
  resetList();
10723
+ setActiveItem(false);
10686
10724
  } else {
10687
10725
  setActiveItem(item);
10688
10726
  }
@@ -10845,6 +10883,7 @@ var __publicField = (obj, key, value) => {
10845
10883
  setLoadFolders(true);
10846
10884
  resetOffset();
10847
10885
  resetList();
10886
+ setActiveItem(false);
10848
10887
  }
10849
10888
  }
10850
10889
  )), cms.media.store.isStatic ? null : /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap items-center gap-4" }, /* @__PURE__ */ React.createElement(
@@ -10856,6 +10895,7 @@ var __publicField = (obj, key, value) => {
10856
10895
  setRefreshing(true);
10857
10896
  resetOffset();
10858
10897
  resetList();
10898
+ setActiveItem(false);
10859
10899
  },
10860
10900
  className: "whitespace-nowrap"
10861
10901
  },
@@ -31186,7 +31226,8 @@ This will work when developing locally but NOT when deployed to production.
31186
31226
  )), /* @__PURE__ */ React.createElement("div", { className: "flex w-full md:w-auto gap-3" }, /* @__PURE__ */ React.createElement(
31187
31227
  Button$1,
31188
31228
  {
31189
- onClick: () => {
31229
+ onClick: (e) => {
31230
+ e.preventDefault();
31190
31231
  setSearch(searchInput);
31191
31232
  setSearchLoaded(false);
31192
31233
  },
@@ -31198,7 +31239,8 @@ This will work when developing locally but NOT when deployed to production.
31198
31239
  ), search && searchLoaded && /* @__PURE__ */ React.createElement(
31199
31240
  Button$1,
31200
31241
  {
31201
- onClick: () => {
31242
+ onClick: (e) => {
31243
+ e.preventDefault();
31202
31244
  setSearch("");
31203
31245
  setSearchInput("");
31204
31246
  },
package/dist/index.mjs CHANGED
@@ -4531,6 +4531,26 @@ const CommandItem = React.forwardRef(({ className, ...props }, ref) => /* @__PUR
4531
4531
  }
4532
4532
  ));
4533
4533
  CommandItem.displayName = Command$1.Item.displayName;
4534
+ const OptionComponent = ({
4535
+ id,
4536
+ value,
4537
+ field,
4538
+ _values,
4539
+ node,
4540
+ onSelect
4541
+ }) => {
4542
+ return /* @__PURE__ */ React__default.createElement(
4543
+ CommandItem,
4544
+ {
4545
+ key: `${id}-option`,
4546
+ value: id,
4547
+ onSelect: (currentValue) => {
4548
+ onSelect(currentValue === value ? "" : currentValue);
4549
+ }
4550
+ },
4551
+ /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-col w-full" }, (field == null ? void 0 : field.optionComponent) && _values ? field.optionComponent(_values, node._internalSys) : /* @__PURE__ */ React__default.createElement("span", { className: "text-x" }, id))
4552
+ );
4553
+ };
4534
4554
  const Popover = PopoverPrimitive.Root;
4535
4555
  const PopoverTrigger = PopoverPrimitive.Trigger;
4536
4556
  const PopoverContent = React.forwardRef(({ className, align = "center", sideOffset = 4, ...props }, ref) => /* @__PURE__ */ React.createElement(PopoverPrimitive.Portal, null, /* @__PURE__ */ React.createElement(
@@ -4622,10 +4642,16 @@ const ComboboxDemo = ({
4622
4642
  const [value, setValue] = React.useState(input.value);
4623
4643
  const [displayText, setDisplayText] = React.useState(null);
4624
4644
  const { optionSets, loading } = useGetOptionSets(cms, field.collections);
4645
+ const [filteredOptionsList, setFilteredOptionsList] = React.useState(optionSets);
4625
4646
  React.useEffect(() => {
4626
4647
  setDisplayText(getFilename(optionSets, value));
4627
4648
  input.onChange(value);
4628
4649
  }, [value, input, optionSets]);
4650
+ React.useEffect(() => {
4651
+ if (field.experimental___filter && optionSets.length > 0) {
4652
+ setFilteredOptionsList(field.experimental___filter(optionSets, void 0));
4653
+ }
4654
+ }, [optionSets, field.experimental___filter]);
4629
4655
  if (loading === true) {
4630
4656
  return /* @__PURE__ */ React.createElement(LoadingDots, { color: "var(--tina-color-primary)" });
4631
4657
  }
@@ -4642,41 +4668,52 @@ const ComboboxDemo = ({
4642
4668
  )), /* @__PURE__ */ React.createElement(PopoverContent, { className: "p-0 relative" }, /* @__PURE__ */ React.createElement(
4643
4669
  Command,
4644
4670
  {
4671
+ shouldFilter: !field.experimental___filter,
4645
4672
  filter: (value2, search) => {
4646
4673
  if (value2.toLowerCase().replace(/\//g, "").includes(search.toLowerCase()))
4647
4674
  return 1;
4648
4675
  return 0;
4649
4676
  }
4650
4677
  },
4651
- /* @__PURE__ */ React.createElement(CommandInput, { placeholder: "Search reference..." }),
4678
+ /* @__PURE__ */ React.createElement(
4679
+ CommandInput,
4680
+ {
4681
+ placeholder: "Search reference...",
4682
+ onValueChange: (search) => {
4683
+ if (field.experimental___filter) {
4684
+ setFilteredOptionsList(
4685
+ field.experimental___filter(optionSets, search)
4686
+ );
4687
+ }
4688
+ }
4689
+ }
4690
+ ),
4652
4691
  /* @__PURE__ */ React.createElement(CommandEmpty, null, "No reference found"),
4653
- /* @__PURE__ */ React.createElement(CommandList, null, optionSets.length > 0 && optionSets.map(({ collection, edges }) => /* @__PURE__ */ React.createElement(
4692
+ /* @__PURE__ */ React.createElement(CommandList, null, filteredOptionsList.length > 0 && (filteredOptionsList == null ? void 0 : filteredOptionsList.map(({ collection, edges }) => /* @__PURE__ */ React.createElement(
4654
4693
  CommandGroup,
4655
4694
  {
4656
4695
  key: `${collection}-group`,
4657
4696
  heading: collection
4658
4697
  },
4659
- /* @__PURE__ */ React.createElement(CommandList, null, edges.map(({ node }) => {
4698
+ /* @__PURE__ */ React.createElement(CommandList, null, edges == null ? void 0 : edges.map(({ node }) => {
4660
4699
  const { id, _values } = node;
4661
4700
  return /* @__PURE__ */ React.createElement(
4662
- CommandItem,
4701
+ OptionComponent,
4663
4702
  {
4664
- key: `${id}-option`,
4665
- value: id,
4703
+ id,
4704
+ key: id,
4705
+ value,
4706
+ field,
4707
+ _values,
4708
+ node,
4666
4709
  onSelect: (currentValue) => {
4667
- setValue(
4668
- currentValue === value ? "" : currentValue
4669
- );
4710
+ setValue(currentValue);
4670
4711
  setOpen(false);
4671
4712
  }
4672
- },
4673
- /* @__PURE__ */ React.createElement("div", { className: "flex flex-col" }, /* @__PURE__ */ React.createElement("div", null, (field == null ? void 0 : field.optionComponent) && _values ? field.optionComponent(
4674
- _values,
4675
- node._internalSys
4676
- ) : /* @__PURE__ */ React.createElement("span", { className: "text-x" }, id)))
4713
+ }
4677
4714
  );
4678
4715
  }))
4679
- )))
4716
+ ))))
4680
4717
  ))));
4681
4718
  };
4682
4719
  const useGetNode = (cms, id) => {
@@ -10706,6 +10743,7 @@ function MediaPicker({
10706
10743
  setLoadFolders(true);
10707
10744
  resetOffset();
10708
10745
  resetList();
10746
+ setActiveItem(false);
10709
10747
  } else {
10710
10748
  setActiveItem(item);
10711
10749
  }
@@ -10868,6 +10906,7 @@ function MediaPicker({
10868
10906
  setLoadFolders(true);
10869
10907
  resetOffset();
10870
10908
  resetList();
10909
+ setActiveItem(false);
10871
10910
  }
10872
10911
  }
10873
10912
  )), cms.media.store.isStatic ? null : /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-wrap items-center gap-4" }, /* @__PURE__ */ React__default.createElement(
@@ -10879,6 +10918,7 @@ function MediaPicker({
10879
10918
  setRefreshing(true);
10880
10919
  resetOffset();
10881
10920
  resetList();
10921
+ setActiveItem(false);
10882
10922
  },
10883
10923
  className: "whitespace-nowrap"
10884
10924
  },
@@ -31209,7 +31249,8 @@ const SearchInput = ({
31209
31249
  )), /* @__PURE__ */ React__default.createElement("div", { className: "flex w-full md:w-auto gap-3" }, /* @__PURE__ */ React__default.createElement(
31210
31250
  Button$1,
31211
31251
  {
31212
- onClick: () => {
31252
+ onClick: (e) => {
31253
+ e.preventDefault();
31213
31254
  setSearch(searchInput);
31214
31255
  setSearchLoaded(false);
31215
31256
  },
@@ -31221,7 +31262,8 @@ const SearchInput = ({
31221
31262
  ), search && searchLoaded && /* @__PURE__ */ React__default.createElement(
31222
31263
  Button$1,
31223
31264
  {
31224
- onClick: () => {
31265
+ onClick: (e) => {
31266
+ e.preventDefault();
31225
31267
  setSearch("");
31226
31268
  setSearchInput("");
31227
31269
  },
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { OptionComponentProps } from '../model/option-component-props';
3
+ declare const OptionComponent: React.FC<OptionComponentProps>;
4
+ export default OptionComponent;
@@ -3,18 +3,21 @@ type Option = {
3
3
  value: string;
4
4
  label: string;
5
5
  };
6
+ type ReferenceFieldOptions = {
7
+ optionComponent?: OptionComponent;
8
+ experimental___filter?: (list: Array<any>, searchQuery: string) => Array<any>;
9
+ };
6
10
  type OptionComponent = (props: unknown, _sys: InternalSys) => React.ReactElement | string;
7
11
  export interface InternalSys {
8
12
  filename: string;
9
13
  path: string;
10
14
  }
11
- export interface ReferenceFieldProps {
15
+ export interface ReferenceFieldProps extends ReferenceFieldOptions {
12
16
  label?: string;
13
17
  name: string;
14
18
  component: string;
15
19
  collections: string[];
16
20
  options: (Option | string)[];
17
- optionComponent: OptionComponent;
18
21
  }
19
22
  export interface ReferenceProps {
20
23
  name: string;
@@ -0,0 +1,13 @@
1
+ import { InternalSys } from './reference-field-props';
2
+ export interface OptionComponentProps {
3
+ id: string;
4
+ value: string;
5
+ field?: {
6
+ optionComponent?: (values: unknown, internalSys: InternalSys) => React.ReactNode;
7
+ };
8
+ _values?: unknown;
9
+ node: {
10
+ _internalSys: InternalSys;
11
+ };
12
+ onSelect: (currentValue: string) => void;
13
+ }
@@ -0,0 +1,21 @@
1
+ export type Option = {
2
+ value: string;
3
+ label: string;
4
+ };
5
+ type OptionComponent = (props: unknown, _sys: InternalSys) => React.ReactElement | string;
6
+ export interface InternalSys {
7
+ filename: string;
8
+ path: string;
9
+ }
10
+ type ReferenceFieldOptions = {
11
+ optionComponent?: OptionComponent;
12
+ experimental___filter?: (list: Array<any>, searchQuery: string) => Array<any>;
13
+ };
14
+ export interface ReferenceFieldProps extends ReferenceFieldOptions {
15
+ label?: string;
16
+ name: string;
17
+ component: string;
18
+ collections: string[];
19
+ options: (Option | string)[];
20
+ }
21
+ export {};
@@ -0,0 +1,16 @@
1
+ import { TinaCMS } from '../../../../tina-cms';
2
+ export interface ReferenceLinkProps {
3
+ cms: TinaCMS;
4
+ input: any;
5
+ }
6
+ export type Document = {
7
+ _sys: {
8
+ collection: {
9
+ name: string;
10
+ };
11
+ breadcrumbs: string[];
12
+ };
13
+ };
14
+ export interface Response {
15
+ node: Document;
16
+ }
@@ -0,0 +1,8 @@
1
+ import { ReferenceFieldProps, Option } from './reference-field-props';
2
+ export interface ReferenceProps {
3
+ name: string;
4
+ input: any;
5
+ field: ReferenceFieldProps;
6
+ disabled?: boolean;
7
+ options?: (Option | string)[];
8
+ }
@@ -1,8 +1,4 @@
1
1
  import * as React from 'react';
2
- import type { TinaCMS } from '../../../tina-cms';
3
- interface ReferenceLinkProps {
4
- cms: TinaCMS;
5
- input: any;
6
- }
2
+ import { ReferenceLinkProps } from './model/reference-link-props';
7
3
  declare const ReferenceLink: React.FC<ReferenceLinkProps>;
8
4
  export default ReferenceLink;
@@ -1,7 +1,7 @@
1
- import { Field } from '../../../forms';
1
+ import type { Field } from '../../../forms';
2
2
  import type { TinaCMS } from '../../../tina-cms';
3
3
  import * as React from 'react';
4
- import type { ReferenceFieldProps } from './index';
4
+ import type { ReferenceFieldProps } from './model/reference-field-props';
5
5
  interface ReferenceSelectProps {
6
6
  cms: TinaCMS;
7
7
  input: any;
@@ -1,11 +1,12 @@
1
- import type { GraphQLError } from 'graphql';
2
1
  import type { Config } from '@tinacms/schema-tools';
2
+ import type { Cache } from '../cache/index';
3
3
  export declare const TINA_HOST = "content.tinajs.io";
4
4
  export interface TinaClientArgs<GenQueries = Record<string, unknown>> {
5
5
  url: string;
6
6
  token?: string;
7
7
  queries: (client: TinaClient<GenQueries>) => GenQueries;
8
8
  errorPolicy?: Config['client']['errorPolicy'];
9
+ cacheDir?: string;
9
10
  }
10
11
  export type TinaClientRequestArgs = {
11
12
  variables?: Record<string, any>;
@@ -23,13 +24,10 @@ export declare class TinaClient<GenQueries> {
23
24
  readonlyToken?: string;
24
25
  queries: GenQueries;
25
26
  errorPolicy: Config['client']['errorPolicy'];
26
- constructor({ token, url, queries, errorPolicy, }: TinaClientArgs<GenQueries>);
27
+ cache: Cache;
28
+ constructor({ token, url, queries, errorPolicy, cacheDir, }: TinaClientArgs<GenQueries>);
27
29
  request<DataType extends Record<string, any> = any>({ errorPolicy, ...args }: TinaClientRequestArgs, options: {
28
30
  fetchOptions?: Parameters<typeof fetch>[1];
29
- }): Promise<{
30
- data: DataType;
31
- errors: GraphQLError[] | null;
32
- query: string;
33
- }>;
31
+ }): Promise<any>;
34
32
  }
35
33
  export declare function createClient<GenQueries>(args: TinaClientArgs<GenQueries>): TinaClient<GenQueries>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tinacms",
3
- "version": "2.2.1",
3
+ "version": "2.2.2",
4
4
  "main": "dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "exports": {
@@ -14,6 +14,11 @@
14
14
  "import": "./dist/client.mjs",
15
15
  "require": "./dist/client.js"
16
16
  },
17
+ "./dist/cache": {
18
+ "types": "./dist/cache.d.ts",
19
+ "import": "./dist/cache.mjs",
20
+ "require": "./dist/cache.js"
21
+ },
17
22
  "./dist/edit-state": {
18
23
  "types": "./dist/edit-state.d.ts",
19
24
  "import": "./dist/edit-state.mjs",
@@ -44,7 +49,8 @@
44
49
  "src/rich-text/index.tsx",
45
50
  "src/rich-text/prism.tsx",
46
51
  "src/react.tsx",
47
- "src/client.ts"
52
+ "src/client.ts",
53
+ "src/cache.ts"
48
54
  ]
49
55
  },
50
56
  "typings": "dist/index.d.ts",
@@ -117,9 +123,9 @@
117
123
  "clsx": "^2.1.1",
118
124
  "yup": "^1.4.0",
119
125
  "zod": "^3.23.8",
120
- "@tinacms/mdx": "1.4.1",
121
- "@tinacms/schema-tools": "1.6.1",
122
- "@tinacms/search": "1.0.27"
126
+ "@tinacms/mdx": "1.4.2",
127
+ "@tinacms/schema-tools": "1.6.2",
128
+ "@tinacms/search": "1.0.28"
123
129
  },
124
130
  "devDependencies": {
125
131
  "@graphql-tools/utils": "^10.3.3",
@@ -152,7 +158,7 @@
152
158
  "typescript": "^5.5.4",
153
159
  "vite": "^5.3.5",
154
160
  "vitest": "^2.0.5",
155
- "@tinacms/scripts": "1.2.0"
161
+ "@tinacms/scripts": "1.2.1"
156
162
  },
157
163
  "peerDependencies": {
158
164
  "react": ">=16.14.0",