tinacms 2.2.1 → 2.2.3

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,18 @@ 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
+ } else {
4631
+ setFilteredOptionsList(optionSets);
4632
+ }
4633
+ }, [optionSets, field.experimental___filter]);
4606
4634
  if (loading === true) {
4607
4635
  return /* @__PURE__ */ React__namespace.createElement(LoadingDots, { color: "var(--tina-color-primary)" });
4608
4636
  }
@@ -4619,41 +4647,52 @@ var __publicField = (obj, key, value) => {
4619
4647
  )), /* @__PURE__ */ React__namespace.createElement(PopoverContent, { className: "p-0 relative" }, /* @__PURE__ */ React__namespace.createElement(
4620
4648
  Command,
4621
4649
  {
4650
+ shouldFilter: !field.experimental___filter,
4622
4651
  filter: (value2, search) => {
4623
4652
  if (value2.toLowerCase().replace(/\//g, "").includes(search.toLowerCase()))
4624
4653
  return 1;
4625
4654
  return 0;
4626
4655
  }
4627
4656
  },
4628
- /* @__PURE__ */ React__namespace.createElement(CommandInput, { placeholder: "Search reference..." }),
4657
+ /* @__PURE__ */ React__namespace.createElement(
4658
+ CommandInput,
4659
+ {
4660
+ placeholder: "Search reference...",
4661
+ onValueChange: (search) => {
4662
+ if (field.experimental___filter) {
4663
+ setFilteredOptionsList(
4664
+ field.experimental___filter(optionSets, search)
4665
+ );
4666
+ }
4667
+ }
4668
+ }
4669
+ ),
4629
4670
  /* @__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(
4671
+ /* @__PURE__ */ React__namespace.createElement(CommandList, null, filteredOptionsList.length > 0 && (filteredOptionsList == null ? void 0 : filteredOptionsList.map(({ collection, edges }) => /* @__PURE__ */ React__namespace.createElement(
4631
4672
  CommandGroup,
4632
4673
  {
4633
4674
  key: `${collection}-group`,
4634
4675
  heading: collection
4635
4676
  },
4636
- /* @__PURE__ */ React__namespace.createElement(CommandList, null, edges.map(({ node }) => {
4677
+ /* @__PURE__ */ React__namespace.createElement(CommandList, null, edges == null ? void 0 : edges.map(({ node }) => {
4637
4678
  const { id, _values } = node;
4638
4679
  return /* @__PURE__ */ React__namespace.createElement(
4639
- CommandItem,
4680
+ OptionComponent,
4640
4681
  {
4641
- key: `${id}-option`,
4642
- value: id,
4682
+ id,
4683
+ key: id,
4684
+ value,
4685
+ field,
4686
+ _values,
4687
+ node,
4643
4688
  onSelect: (currentValue) => {
4644
- setValue(
4645
- currentValue === value ? "" : currentValue
4646
- );
4689
+ setValue(currentValue);
4647
4690
  setOpen(false);
4648
4691
  }
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)))
4692
+ }
4654
4693
  );
4655
4694
  }))
4656
- )))
4695
+ ))))
4657
4696
  ))));
4658
4697
  };
4659
4698
  const useGetNode = (cms, id) => {
@@ -10683,6 +10722,7 @@ var __publicField = (obj, key, value) => {
10683
10722
  setLoadFolders(true);
10684
10723
  resetOffset();
10685
10724
  resetList();
10725
+ setActiveItem(false);
10686
10726
  } else {
10687
10727
  setActiveItem(item);
10688
10728
  }
@@ -10845,6 +10885,7 @@ var __publicField = (obj, key, value) => {
10845
10885
  setLoadFolders(true);
10846
10886
  resetOffset();
10847
10887
  resetList();
10888
+ setActiveItem(false);
10848
10889
  }
10849
10890
  }
10850
10891
  )), cms.media.store.isStatic ? null : /* @__PURE__ */ React.createElement("div", { className: "flex flex-wrap items-center gap-4" }, /* @__PURE__ */ React.createElement(
@@ -10856,6 +10897,7 @@ var __publicField = (obj, key, value) => {
10856
10897
  setRefreshing(true);
10857
10898
  resetOffset();
10858
10899
  resetList();
10900
+ setActiveItem(false);
10859
10901
  },
10860
10902
  className: "whitespace-nowrap"
10861
10903
  },
@@ -31186,7 +31228,8 @@ This will work when developing locally but NOT when deployed to production.
31186
31228
  )), /* @__PURE__ */ React.createElement("div", { className: "flex w-full md:w-auto gap-3" }, /* @__PURE__ */ React.createElement(
31187
31229
  Button$1,
31188
31230
  {
31189
- onClick: () => {
31231
+ onClick: (e) => {
31232
+ e.preventDefault();
31190
31233
  setSearch(searchInput);
31191
31234
  setSearchLoaded(false);
31192
31235
  },
@@ -31198,7 +31241,8 @@ This will work when developing locally but NOT when deployed to production.
31198
31241
  ), search && searchLoaded && /* @__PURE__ */ React.createElement(
31199
31242
  Button$1,
31200
31243
  {
31201
- onClick: () => {
31244
+ onClick: (e) => {
31245
+ e.preventDefault();
31202
31246
  setSearch("");
31203
31247
  setSearchInput("");
31204
31248
  },
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,18 @@ 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
+ } else {
4654
+ setFilteredOptionsList(optionSets);
4655
+ }
4656
+ }, [optionSets, field.experimental___filter]);
4629
4657
  if (loading === true) {
4630
4658
  return /* @__PURE__ */ React.createElement(LoadingDots, { color: "var(--tina-color-primary)" });
4631
4659
  }
@@ -4642,41 +4670,52 @@ const ComboboxDemo = ({
4642
4670
  )), /* @__PURE__ */ React.createElement(PopoverContent, { className: "p-0 relative" }, /* @__PURE__ */ React.createElement(
4643
4671
  Command,
4644
4672
  {
4673
+ shouldFilter: !field.experimental___filter,
4645
4674
  filter: (value2, search) => {
4646
4675
  if (value2.toLowerCase().replace(/\//g, "").includes(search.toLowerCase()))
4647
4676
  return 1;
4648
4677
  return 0;
4649
4678
  }
4650
4679
  },
4651
- /* @__PURE__ */ React.createElement(CommandInput, { placeholder: "Search reference..." }),
4680
+ /* @__PURE__ */ React.createElement(
4681
+ CommandInput,
4682
+ {
4683
+ placeholder: "Search reference...",
4684
+ onValueChange: (search) => {
4685
+ if (field.experimental___filter) {
4686
+ setFilteredOptionsList(
4687
+ field.experimental___filter(optionSets, search)
4688
+ );
4689
+ }
4690
+ }
4691
+ }
4692
+ ),
4652
4693
  /* @__PURE__ */ React.createElement(CommandEmpty, null, "No reference found"),
4653
- /* @__PURE__ */ React.createElement(CommandList, null, optionSets.length > 0 && optionSets.map(({ collection, edges }) => /* @__PURE__ */ React.createElement(
4694
+ /* @__PURE__ */ React.createElement(CommandList, null, filteredOptionsList.length > 0 && (filteredOptionsList == null ? void 0 : filteredOptionsList.map(({ collection, edges }) => /* @__PURE__ */ React.createElement(
4654
4695
  CommandGroup,
4655
4696
  {
4656
4697
  key: `${collection}-group`,
4657
4698
  heading: collection
4658
4699
  },
4659
- /* @__PURE__ */ React.createElement(CommandList, null, edges.map(({ node }) => {
4700
+ /* @__PURE__ */ React.createElement(CommandList, null, edges == null ? void 0 : edges.map(({ node }) => {
4660
4701
  const { id, _values } = node;
4661
4702
  return /* @__PURE__ */ React.createElement(
4662
- CommandItem,
4703
+ OptionComponent,
4663
4704
  {
4664
- key: `${id}-option`,
4665
- value: id,
4705
+ id,
4706
+ key: id,
4707
+ value,
4708
+ field,
4709
+ _values,
4710
+ node,
4666
4711
  onSelect: (currentValue) => {
4667
- setValue(
4668
- currentValue === value ? "" : currentValue
4669
- );
4712
+ setValue(currentValue);
4670
4713
  setOpen(false);
4671
4714
  }
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)))
4715
+ }
4677
4716
  );
4678
4717
  }))
4679
- )))
4718
+ ))))
4680
4719
  ))));
4681
4720
  };
4682
4721
  const useGetNode = (cms, id) => {
@@ -10706,6 +10745,7 @@ function MediaPicker({
10706
10745
  setLoadFolders(true);
10707
10746
  resetOffset();
10708
10747
  resetList();
10748
+ setActiveItem(false);
10709
10749
  } else {
10710
10750
  setActiveItem(item);
10711
10751
  }
@@ -10868,6 +10908,7 @@ function MediaPicker({
10868
10908
  setLoadFolders(true);
10869
10909
  resetOffset();
10870
10910
  resetList();
10911
+ setActiveItem(false);
10871
10912
  }
10872
10913
  }
10873
10914
  )), cms.media.store.isStatic ? null : /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-wrap items-center gap-4" }, /* @__PURE__ */ React__default.createElement(
@@ -10879,6 +10920,7 @@ function MediaPicker({
10879
10920
  setRefreshing(true);
10880
10921
  resetOffset();
10881
10922
  resetList();
10923
+ setActiveItem(false);
10882
10924
  },
10883
10925
  className: "whitespace-nowrap"
10884
10926
  },
@@ -31209,7 +31251,8 @@ const SearchInput = ({
31209
31251
  )), /* @__PURE__ */ React__default.createElement("div", { className: "flex w-full md:w-auto gap-3" }, /* @__PURE__ */ React__default.createElement(
31210
31252
  Button$1,
31211
31253
  {
31212
- onClick: () => {
31254
+ onClick: (e) => {
31255
+ e.preventDefault();
31213
31256
  setSearch(searchInput);
31214
31257
  setSearchLoaded(false);
31215
31258
  },
@@ -31221,7 +31264,8 @@ const SearchInput = ({
31221
31264
  ), search && searchLoaded && /* @__PURE__ */ React__default.createElement(
31222
31265
  Button$1,
31223
31266
  {
31224
- onClick: () => {
31267
+ onClick: (e) => {
31268
+ e.preventDefault();
31225
31269
  setSearch("");
31226
31270
  setSearchInput("");
31227
31271
  },
@@ -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.3",
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",