tinacms 3.2.0 → 3.3.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/index.js CHANGED
@@ -7,7 +7,7 @@ var __publicField = (obj, key, value) => {
7
7
  var _a;
8
8
  import { z } from "zod";
9
9
  import * as React from "react";
10
- import React__default, { useState, useCallback, useContext, createContext, forwardRef, useRef, useReducer, useMemo, useEffect, useLayoutEffect, Component, memo as memo$1, useDebugValue, useId, startTransition, useImperativeHandle } from "react";
10
+ import React__default, { useState, useCallback, useContext, createContext, forwardRef, useRef, useReducer, useMemo, useEffect, useLayoutEffect, Component, memo, useDebugValue, useId, startTransition, useImperativeHandle } from "react";
11
11
  import ReactDOM, { createPortal } from "react-dom";
12
12
  import { createForm, FORM_ERROR, getIn } from "final-form";
13
13
  import arrayMutators from "final-form-arrays";
@@ -1995,21 +1995,29 @@ function isDraftable$1(value) {
1995
1995
  return isPlainObject$4(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a2 = value.constructor) == null ? void 0 : _a2[DRAFTABLE]) || isMap$2(value) || isSet$2(value);
1996
1996
  }
1997
1997
  var objectCtorString$1 = Object.prototype.constructor.toString();
1998
+ var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
1998
1999
  function isPlainObject$4(value) {
1999
2000
  if (!value || typeof value !== "object")
2000
2001
  return false;
2001
- const proto = getPrototypeOf(value);
2002
- if (proto === null) {
2002
+ const proto = Object.getPrototypeOf(value);
2003
+ if (proto === null || proto === Object.prototype)
2003
2004
  return true;
2004
- }
2005
2005
  const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
2006
2006
  if (Ctor === Object)
2007
2007
  return true;
2008
- return typeof Ctor == "function" && Function.toString.call(Ctor) === objectCtorString$1;
2008
+ if (typeof Ctor !== "function")
2009
+ return false;
2010
+ let ctorString = cachedCtorStrings.get(Ctor);
2011
+ if (ctorString === void 0) {
2012
+ ctorString = Function.toString.call(Ctor);
2013
+ cachedCtorStrings.set(Ctor, ctorString);
2014
+ }
2015
+ return ctorString === objectCtorString$1;
2009
2016
  }
2010
- function each(obj, iter) {
2017
+ function each(obj, iter, strict = true) {
2011
2018
  if (getArchtype(obj) === 0) {
2012
- Reflect.ownKeys(obj).forEach((key) => {
2019
+ const keys2 = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
2020
+ keys2.forEach((key) => {
2013
2021
  iter(key, obj[key], obj);
2014
2022
  });
2015
2023
  } else {
@@ -2092,17 +2100,27 @@ function freeze$1(obj, deep = false) {
2092
2100
  if (isFrozen(obj) || isDraft$1(obj) || !isDraftable$1(obj))
2093
2101
  return obj;
2094
2102
  if (getArchtype(obj) > 1) {
2095
- obj.set = obj.add = obj.clear = obj.delete = dontMutateFrozenCollections;
2103
+ Object.defineProperties(obj, {
2104
+ set: dontMutateMethodOverride,
2105
+ add: dontMutateMethodOverride,
2106
+ clear: dontMutateMethodOverride,
2107
+ delete: dontMutateMethodOverride
2108
+ });
2096
2109
  }
2097
2110
  Object.freeze(obj);
2098
2111
  if (deep)
2099
- Object.entries(obj).forEach(([key, value]) => freeze$1(value, true));
2112
+ Object.values(obj).forEach((value) => freeze$1(value, true));
2100
2113
  return obj;
2101
2114
  }
2102
2115
  function dontMutateFrozenCollections() {
2103
2116
  die(2);
2104
2117
  }
2118
+ var dontMutateMethodOverride = {
2119
+ value: dontMutateFrozenCollections
2120
+ };
2105
2121
  function isFrozen(obj) {
2122
+ if (obj === null || typeof obj !== "object")
2123
+ return true;
2106
2124
  return Object.isFrozen(obj);
2107
2125
  }
2108
2126
  var plugins = {};
@@ -2190,11 +2208,13 @@ function processResult(result, scope) {
2190
2208
  function finalize(rootScope, value, path3) {
2191
2209
  if (isFrozen(value))
2192
2210
  return value;
2211
+ const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
2193
2212
  const state = value[DRAFT_STATE];
2194
2213
  if (!state) {
2195
2214
  each(
2196
2215
  value,
2197
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path3)
2216
+ (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path3),
2217
+ useStrictIteration
2198
2218
  );
2199
2219
  return value;
2200
2220
  }
@@ -2217,7 +2237,16 @@ function finalize(rootScope, value, path3) {
2217
2237
  }
2218
2238
  each(
2219
2239
  resultEach,
2220
- (key, childValue) => finalizeProperty(rootScope, state, result, key, childValue, path3, isSet2)
2240
+ (key, childValue) => finalizeProperty(
2241
+ rootScope,
2242
+ state,
2243
+ result,
2244
+ key,
2245
+ childValue,
2246
+ path3,
2247
+ isSet2
2248
+ ),
2249
+ useStrictIteration
2221
2250
  );
2222
2251
  maybeFreeze(rootScope, result, false);
2223
2252
  if (path3 && rootScope.patches_) {
@@ -2232,6 +2261,16 @@ function finalize(rootScope, value, path3) {
2232
2261
  return state.copy_;
2233
2262
  }
2234
2263
  function finalizeProperty(rootScope, parentState, targetObject, prop2, childValue, rootPath, targetIsSet) {
2264
+ if (childValue == null) {
2265
+ return;
2266
+ }
2267
+ if (typeof childValue !== "object" && !targetIsSet) {
2268
+ return;
2269
+ }
2270
+ const childIsFrozen = isFrozen(childValue);
2271
+ if (childIsFrozen && !targetIsSet) {
2272
+ return;
2273
+ }
2235
2274
  if (process.env.NODE_ENV !== "production" && childValue === targetObject)
2236
2275
  die(5);
2237
2276
  if (isDraft$1(childValue)) {
@@ -2246,12 +2285,15 @@ function finalizeProperty(rootScope, parentState, targetObject, prop2, childValu
2246
2285
  } else if (targetIsSet) {
2247
2286
  targetObject.add(childValue);
2248
2287
  }
2249
- if (isDraftable$1(childValue) && !isFrozen(childValue)) {
2288
+ if (isDraftable$1(childValue) && !childIsFrozen) {
2250
2289
  if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
2251
2290
  return;
2252
2291
  }
2292
+ if (parentState && parentState.base_ && parentState.base_[prop2] === childValue && childIsFrozen) {
2293
+ return;
2294
+ }
2253
2295
  finalize(rootScope, childValue);
2254
- if ((!parentState || !parentState.scope_.parent_) && typeof prop2 !== "symbol" && Object.prototype.propertyIsEnumerable.call(targetObject, prop2))
2296
+ if ((!parentState || !parentState.scope_.parent_) && typeof prop2 !== "symbol" && (isMap$2(targetObject) ? targetObject.has(prop2) : Object.prototype.propertyIsEnumerable.call(targetObject, prop2)))
2255
2297
  maybeFreeze(rootScope, childValue);
2256
2298
  }
2257
2299
  }
@@ -2447,6 +2489,7 @@ var Immer2 = class {
2447
2489
  constructor(config) {
2448
2490
  this.autoFreeze_ = true;
2449
2491
  this.useStrictShallowCopy_ = false;
2492
+ this.useStrictIteration_ = true;
2450
2493
  this.produce = (base, recipe, patchListener) => {
2451
2494
  if (typeof base === "function" && typeof recipe !== "function") {
2452
2495
  const defaultBase = recipe;
@@ -2509,6 +2552,8 @@ var Immer2 = class {
2509
2552
  this.setAutoFreeze(config.autoFreeze);
2510
2553
  if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
2511
2554
  this.setUseStrictShallowCopy(config.useStrictShallowCopy);
2555
+ if (typeof (config == null ? void 0 : config.useStrictIteration) === "boolean")
2556
+ this.setUseStrictIteration(config.useStrictIteration);
2512
2557
  }
2513
2558
  createDraft(base) {
2514
2559
  if (!isDraftable$1(base))
@@ -2545,6 +2590,18 @@ var Immer2 = class {
2545
2590
  setUseStrictShallowCopy(value) {
2546
2591
  this.useStrictShallowCopy_ = value;
2547
2592
  }
2593
+ /**
2594
+ * Pass false to use faster iteration that skips non-enumerable properties
2595
+ * but still handles symbols for compatibility.
2596
+ *
2597
+ * By default, strict iteration is enabled (includes all own properties).
2598
+ */
2599
+ setUseStrictIteration(value) {
2600
+ this.useStrictIteration_ = value;
2601
+ }
2602
+ shouldUseStrictIteration() {
2603
+ return this.useStrictIteration_;
2604
+ }
2548
2605
  applyPatches(base, patches) {
2549
2606
  let i2;
2550
2607
  for (i2 = patches.length - 1; i2 >= 0; i2--) {
@@ -2583,17 +2640,23 @@ function currentImpl(value) {
2583
2640
  return value;
2584
2641
  const state = value[DRAFT_STATE];
2585
2642
  let copy2;
2643
+ let strict = true;
2586
2644
  if (state) {
2587
2645
  if (!state.modified_)
2588
2646
  return state.base_;
2589
2647
  state.finalized_ = true;
2590
2648
  copy2 = shallowCopy$1(value, state.scope_.immer_.useStrictShallowCopy_);
2649
+ strict = state.scope_.immer_.shouldUseStrictIteration();
2591
2650
  } else {
2592
2651
  copy2 = shallowCopy$1(value, true);
2593
2652
  }
2594
- each(copy2, (key, childValue) => {
2595
- set$3(copy2, key, currentImpl(childValue));
2596
- });
2653
+ each(
2654
+ copy2,
2655
+ (key, childValue) => {
2656
+ set$3(copy2, key, currentImpl(childValue));
2657
+ },
2658
+ strict
2659
+ );
2597
2660
  if (state) {
2598
2661
  state.finalized_ = false;
2599
2662
  }
@@ -2601,14 +2664,8 @@ function currentImpl(value) {
2601
2664
  }
2602
2665
  var immer = new Immer2();
2603
2666
  var produce = immer.produce;
2604
- immer.produceWithPatches.bind(
2605
- immer
2606
- );
2607
- immer.setAutoFreeze.bind(immer);
2608
- immer.setUseStrictShallowCopy.bind(immer);
2609
- immer.applyPatches.bind(immer);
2610
- var createDraft$1 = immer.createDraft.bind(immer);
2611
- var finishDraft = immer.finishDraft.bind(immer);
2667
+ var createDraft$1 = /* @__PURE__ */ immer.createDraft.bind(immer);
2668
+ var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer);
2612
2669
  var PathRef = {
2613
2670
  transform(ref, op) {
2614
2671
  var {
@@ -10992,7 +11049,7 @@ var TextString = (props) => {
10992
11049
  ref
10993
11050
  }, initialText);
10994
11051
  };
10995
- var MemoizedText$1 = /* @__PURE__ */ memo$1(/* @__PURE__ */ forwardRef((props, ref) => {
11052
+ var MemoizedText$1 = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef((props, ref) => {
10996
11053
  return /* @__PURE__ */ React__default.createElement("span", {
10997
11054
  "data-slate-string": true,
10998
11055
  ref
@@ -15604,8 +15661,9 @@ const devtoolsImpl = (fn, devtoolsOptions = {}) => (set2, get2, api) => {
15604
15661
  const r2 = set2(state, replace);
15605
15662
  if (!isRecording)
15606
15663
  return r2;
15607
- const inferredActionType = findCallerName(new Error().stack);
15608
- const action = nameOrAction === void 0 ? { type: anonymousActionType || inferredActionType || "anonymous" } : typeof nameOrAction === "string" ? { type: nameOrAction } : nameOrAction;
15664
+ const action = nameOrAction === void 0 ? {
15665
+ type: anonymousActionType || findCallerName(new Error().stack) || "anonymous"
15666
+ } : typeof nameOrAction === "string" ? { type: nameOrAction } : nameOrAction;
15609
15667
  if (store === void 0) {
15610
15668
  connection == null ? void 0 : connection.send(action, get2());
15611
15669
  return r2;
@@ -15893,12 +15951,12 @@ const persistImpl = (config, baseOptions) => (set2, get2, api) => {
15893
15951
  const savedSetState = api.setState;
15894
15952
  api.setState = (state, replace) => {
15895
15953
  savedSetState(state, replace);
15896
- void setItem();
15954
+ return setItem();
15897
15955
  };
15898
15956
  const configResult = config(
15899
15957
  (...args) => {
15900
15958
  set2(...args);
15901
- void setItem();
15959
+ return setItem();
15902
15960
  },
15903
15961
  get2,
15904
15962
  api
@@ -42921,7 +42979,10 @@ const formatCurrentDate = ({
42921
42979
  if (!dateFormat) {
42922
42980
  return format$1(displayDate, timeFormat);
42923
42981
  }
42924
- return `${format$1(displayDate, dateFormat)} ${format$1(displayDate, timeFormat)}`;
42982
+ return `${format$1(displayDate, dateFormat)} ${format$1(
42983
+ displayDate,
42984
+ timeFormat
42985
+ )}`;
42925
42986
  };
42926
42987
  function Calendar({
42927
42988
  className,
@@ -43323,7 +43384,8 @@ const DateTimePicker = React.forwardRef(
43323
43384
  }),
43324
43385
  [displayDate]
43325
43386
  );
43326
- const { options, localize: localize2, formatLong: formatLong2 } = locale;
43387
+ const localeAny = locale;
43388
+ const { options, localize: localize2, formatLong: formatLong2 } = localeAny || {};
43327
43389
  if (options && localize2 && formatLong2) {
43328
43390
  ({
43329
43391
  ...enUS,
@@ -46531,7 +46593,7 @@ const NavProvider = ({
46531
46593
  };
46532
46594
  return /* @__PURE__ */ React__default.createElement(NavContext.Provider, { value }, children);
46533
46595
  };
46534
- const version$1 = "3.2.0";
46596
+ const version$1 = "3.3.0";
46535
46597
  const VersionInfo = () => {
46536
46598
  var _a2, _b, _c, _d, _e, _f;
46537
46599
  const cms = useCMS();
@@ -52345,7 +52407,7 @@ const nld = [
52345
52407
  "in",
52346
52408
  "is",
52347
52409
  "ja",
52348
- "je ",
52410
+ "je",
52349
52411
  "kan",
52350
52412
  "kon",
52351
52413
  "kunnen",
@@ -63635,195 +63697,202 @@ var __publicField2 = (obj, key, value) => {
63635
63697
  __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
63636
63698
  return value;
63637
63699
  };
63700
+ const INDEXABLE_NODE_TYPES = ["text", "code_block", "html"];
63638
63701
  class StringBuilder {
63639
63702
  constructor(limit) {
63640
- __publicField2(this, "buffer");
63641
- __publicField2(this, "length", 0);
63703
+ __publicField2(this, "buffer", []);
63642
63704
  __publicField2(this, "limit");
63643
- this.buffer = [];
63705
+ __publicField2(this, "length", 0);
63644
63706
  this.limit = limit;
63645
63707
  }
63646
63708
  append(str) {
63647
- if (this.length + str.length > this.limit) {
63709
+ if (this.length + str.length > this.limit)
63648
63710
  return true;
63649
- } else {
63650
- this.buffer.push(str);
63651
- this.length += str.length;
63652
- if (this.length > this.limit) {
63653
- return true;
63654
- }
63655
- return false;
63656
- }
63711
+ this.buffer.push(str);
63712
+ this.length += str.length;
63713
+ return this.length > this.limit;
63657
63714
  }
63658
63715
  toString() {
63659
63716
  return this.buffer.join(" ");
63660
63717
  }
63661
63718
  }
63662
- const extractText = (data, acc, indexableNodeTypes) => {
63663
- var _a2, _b;
63664
- if (data) {
63665
- if (indexableNodeTypes.indexOf(data.type) !== -1 && (data.text || data.value)) {
63666
- const tokens = tokenizeString(data.text || data.value);
63667
- for (const token of tokens) {
63668
- if (acc.append(token)) {
63669
- return;
63670
- }
63671
- }
63719
+ const tokenizeString = (str) => {
63720
+ return str.split(/[\s\.,]+/).map((s2) => s2.toLowerCase()).filter((s2) => s2);
63721
+ };
63722
+ const extractText = (data, builder, nodeTypes) => {
63723
+ var _a2;
63724
+ if (!data)
63725
+ return;
63726
+ if (nodeTypes.includes(data.type ?? "") && (data.text || data.value)) {
63727
+ const tokens = tokenizeString(data.text || data.value || "");
63728
+ for (const token of tokens) {
63729
+ if (builder.append(token))
63730
+ return;
63672
63731
  }
63673
- (_b = (_a2 = data.children) == null ? void 0 : _a2.forEach) == null ? void 0 : _b.call(
63674
- _a2,
63675
- (child) => extractText(child, acc, indexableNodeTypes)
63676
- );
63677
63732
  }
63733
+ (_a2 = data.children) == null ? void 0 : _a2.forEach((child) => extractText(child, builder, nodeTypes));
63678
63734
  };
63679
- const relativePath = (path3, collection) => {
63735
+ const getRelativePath = (path3, collection) => {
63680
63736
  return path3.replace(/\\/g, "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
63681
63737
  };
63682
- const tokenizeString = (str) => {
63683
- return str.split(/[\s\.,]+/).map((s2) => s2.toLowerCase()).filter((s2) => s2);
63684
- };
63685
- const processTextFieldValue = (value, maxLen) => {
63738
+ const processTextField = (value, maxLength) => {
63686
63739
  const tokens = tokenizeString(value);
63687
- const builder = new StringBuilder(maxLen);
63740
+ const builder = new StringBuilder(maxLength);
63688
63741
  for (const part of tokens) {
63689
- if (builder.append(part)) {
63742
+ if (builder.append(part))
63690
63743
  break;
63691
- }
63692
63744
  }
63693
63745
  return builder.toString();
63694
63746
  };
63747
+ const processRichTextField = (value, maxLength) => {
63748
+ const builder = new StringBuilder(maxLength);
63749
+ extractText(value, builder, INDEXABLE_NODE_TYPES);
63750
+ return builder.toString();
63751
+ };
63752
+ const processObjectField = (data, path3, collection, textIndexLength, field) => {
63753
+ if (field.list) {
63754
+ return data.map(
63755
+ (obj) => processDocumentForIndexing(obj, path3, collection, textIndexLength, field)
63756
+ );
63757
+ }
63758
+ return processDocumentForIndexing(
63759
+ data,
63760
+ path3,
63761
+ collection,
63762
+ textIndexLength,
63763
+ field
63764
+ );
63765
+ };
63766
+ const processStringField = (data, maxLength, isList) => {
63767
+ if (isList) {
63768
+ return data.map(
63769
+ (value) => processTextField(value, maxLength)
63770
+ );
63771
+ }
63772
+ return processTextField(data, maxLength);
63773
+ };
63774
+ const processRichTextFieldData = (data, maxLength, isList) => {
63775
+ if (isList) {
63776
+ return data.map(
63777
+ (value) => processRichTextField(value, maxLength)
63778
+ );
63779
+ }
63780
+ return processRichTextField(data, maxLength);
63781
+ };
63695
63782
  const processDocumentForIndexing = (data, path3, collection, textIndexLength, field) => {
63696
63783
  if (!field) {
63697
- const relPath = relativePath(path3, collection);
63698
- data["_id"] = `${collection.name}:${relPath}`;
63699
- data["_relativePath"] = relPath;
63784
+ const relativePath = getRelativePath(path3, collection);
63785
+ data["_id"] = `${collection.name}:${relativePath}`;
63786
+ data["_relativePath"] = relativePath;
63700
63787
  }
63701
- for (const f2 of (field == null ? void 0 : field.fields) || collection.fields || []) {
63788
+ const fields = (field == null ? void 0 : field.fields) || collection.fields || [];
63789
+ for (const f2 of fields) {
63702
63790
  if (!f2.searchable) {
63703
63791
  delete data[f2.name];
63704
63792
  continue;
63705
63793
  }
63706
- const isList = f2.list;
63707
- if (data[f2.name]) {
63708
- if (f2.type === "object") {
63709
- if (isList) {
63710
- data[f2.name] = data[f2.name].map(
63711
- (obj) => processDocumentForIndexing(
63712
- obj,
63713
- path3,
63714
- collection,
63715
- textIndexLength,
63716
- f2
63717
- )
63718
- );
63719
- } else {
63720
- data[f2.name] = processDocumentForIndexing(
63721
- data[f2.name],
63722
- path3,
63723
- collection,
63724
- textIndexLength,
63725
- f2
63726
- );
63727
- }
63728
- } else if (f2.type === "string") {
63729
- const fieldTextIndexLength = f2.maxSearchIndexFieldLength || textIndexLength;
63730
- if (isList) {
63731
- data[f2.name] = data[f2.name].map(
63732
- (value) => processTextFieldValue(value, fieldTextIndexLength)
63733
- );
63734
- } else {
63735
- data[f2.name] = processTextFieldValue(
63736
- data[f2.name],
63737
- fieldTextIndexLength
63738
- );
63739
- }
63740
- } else if (f2.type === "rich-text") {
63741
- const fieldTextIndexLength = f2.maxSearchIndexFieldLength || textIndexLength;
63742
- if (isList) {
63743
- data[f2.name] = data[f2.name].map((value) => {
63744
- const acc = new StringBuilder(fieldTextIndexLength);
63745
- extractText(value, acc, ["text", "code_block", "html"]);
63746
- return acc.toString();
63747
- });
63748
- } else {
63749
- const acc = new StringBuilder(fieldTextIndexLength);
63750
- extractText(data[f2.name], acc, ["text", "code_block", "html"]);
63751
- data[f2.name] = acc.toString();
63752
- }
63753
- }
63794
+ if (!data[f2.name])
63795
+ continue;
63796
+ const fieldMaxLength = f2.maxSearchIndexFieldLength || textIndexLength;
63797
+ const isList = Boolean(f2.list);
63798
+ switch (f2.type) {
63799
+ case "object":
63800
+ data[f2.name] = processObjectField(
63801
+ data[f2.name],
63802
+ path3,
63803
+ collection,
63804
+ textIndexLength,
63805
+ f2
63806
+ );
63807
+ break;
63808
+ case "string":
63809
+ data[f2.name] = processStringField(
63810
+ data[f2.name],
63811
+ fieldMaxLength,
63812
+ isList
63813
+ );
63814
+ break;
63815
+ case "rich-text":
63816
+ data[f2.name] = processRichTextFieldData(
63817
+ data[f2.name],
63818
+ fieldMaxLength,
63819
+ isList
63820
+ );
63821
+ break;
63754
63822
  }
63755
63823
  }
63756
63824
  return data;
63757
63825
  };
63758
- const memo = {};
63826
+ const stopwordCache = {};
63759
63827
  const lookupStopwords = (keys2, defaultStopWords = eng) => {
63760
- let stopwords = defaultStopWords;
63761
- if (keys2) {
63762
- if (memo[keys2.join(",")]) {
63763
- return memo[keys2.join(",")];
63764
- }
63765
- stopwords = [];
63766
- for (const key of keys2) {
63767
- stopwords.push(...sw[key]);
63768
- }
63769
- memo[keys2.join(",")] = stopwords;
63828
+ if (!keys2) {
63829
+ return defaultStopWords;
63770
63830
  }
63831
+ const cacheKey = keys2.join(",");
63832
+ if (stopwordCache[cacheKey]) {
63833
+ return stopwordCache[cacheKey];
63834
+ }
63835
+ const stopwords = keys2.flatMap((key) => sw[key] || []);
63836
+ stopwordCache[cacheKey] = stopwords;
63771
63837
  return stopwords;
63772
63838
  };
63773
63839
  const queryToSearchIndexQuery = (query, stopwordLanguages) => {
63774
- let q2;
63775
63840
  const parts = query.split(" ");
63776
63841
  const stopwords = lookupStopwords(stopwordLanguages);
63777
63842
  if (parts.length === 1) {
63778
- q2 = { AND: [parts[0]] };
63779
- } else {
63780
- q2 = {
63781
- AND: parts.filter(
63782
- (part) => part.toLowerCase() !== "and" && stopwords.indexOf(part.toLowerCase()) === -1
63783
- )
63784
- };
63843
+ return { AND: [parts[0]] };
63785
63844
  }
63786
- return q2;
63845
+ const filteredParts = parts.filter(
63846
+ (part) => part.toLowerCase() !== "and" && !stopwords.includes(part.toLowerCase())
63847
+ );
63848
+ return { AND: filteredParts };
63787
63849
  };
63788
63850
  const optionsToSearchIndexOptions = (options) => {
63789
- const opt = {};
63790
- if (options == null ? void 0 : options.limit) {
63791
- opt["PAGE"] = {
63851
+ if (!(options == null ? void 0 : options.limit))
63852
+ return {};
63853
+ return {
63854
+ PAGE: {
63792
63855
  SIZE: options.limit,
63793
- NUMBER: (options == null ? void 0 : options.cursor) ? parseInt(options.cursor) : 0
63794
- };
63795
- }
63796
- return opt;
63856
+ NUMBER: options.cursor ? parseInt(options.cursor) : 0
63857
+ }
63858
+ };
63797
63859
  };
63798
63860
  const parseSearchIndexResponse = (data, options) => {
63799
- const results = data["RESULT"];
63800
- const total = data["RESULT_LENGTH"];
63801
- if ((options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
63802
- const prevCursor = options.cursor === "0" ? null : (parseInt(options.cursor) - 1).toString();
63803
- const nextCursor = total <= (parseInt(options.cursor) + 1) * options.limit ? null : (parseInt(options.cursor) + 1).toString();
63861
+ const resultArray = (data == null ? void 0 : data.RESULT) ?? (data == null ? void 0 : data.results);
63862
+ if (!data || !Array.isArray(resultArray)) {
63804
63863
  return {
63805
- results,
63806
- total,
63807
- prevCursor,
63808
- nextCursor
63864
+ results: [],
63865
+ total: 0,
63866
+ prevCursor: null,
63867
+ nextCursor: null,
63868
+ fuzzyMatches: void 0
63809
63869
  };
63810
- } else if (!(options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
63811
- const prevCursor = null;
63812
- const nextCursor = total <= options.limit ? null : "1";
63870
+ }
63871
+ const results = data.RESULT ?? data.results;
63872
+ const total = data.RESULT_LENGTH ?? data.total ?? 0;
63873
+ const fuzzyMatches = data.FUZZY_MATCHES ?? data.fuzzyMatches;
63874
+ const nextCursor = data.NEXT_CURSOR ?? data.nextCursor;
63875
+ const prevCursor = data.PREV_CURSOR ?? data.prevCursor;
63876
+ if (nextCursor !== void 0 || prevCursor !== void 0) {
63813
63877
  return {
63814
63878
  results,
63815
63879
  total,
63816
- prevCursor,
63817
- nextCursor
63818
- };
63819
- } else {
63820
- return {
63821
- results,
63822
- total,
63823
- prevCursor: null,
63824
- nextCursor: null
63880
+ prevCursor: prevCursor ?? null,
63881
+ nextCursor: nextCursor ?? null,
63882
+ fuzzyMatches
63825
63883
  };
63826
63884
  }
63885
+ const currentPage = (options == null ? void 0 : options.cursor) ? parseInt(options.cursor) : 0;
63886
+ const pageSize = options == null ? void 0 : options.limit;
63887
+ const hasPreviousPage = currentPage > 0;
63888
+ const hasNextPage = pageSize ? total > (currentPage + 1) * pageSize : false;
63889
+ return {
63890
+ results,
63891
+ total,
63892
+ prevCursor: hasPreviousPage ? (currentPage - 1).toString() : null,
63893
+ nextCursor: hasNextPage ? (currentPage + 1).toString() : null,
63894
+ fuzzyMatches
63895
+ };
63827
63896
  };
63828
63897
  const CREATE_DOCUMENT_GQL = `#graphql
63829
63898
  mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
@@ -63879,7 +63948,7 @@ class TinaAdminApi {
63879
63948
  fetchCollections() {
63880
63949
  return this.schema.getCollections();
63881
63950
  }
63882
- async renameDocument({ collection, relativePath: relativePath2, newRelativePath }) {
63951
+ async renameDocument({ collection, relativePath, newRelativePath }) {
63883
63952
  await this.api.request(
63884
63953
  `#graphql
63885
63954
  mutation RenameDocument($collection: String!, $relativePath: String! $newRelativePath: String!) {
@@ -63888,7 +63957,7 @@ class TinaAdminApi {
63888
63957
  }
63889
63958
  }
63890
63959
  `,
63891
- { variables: { collection, relativePath: relativePath2, newRelativePath } }
63960
+ { variables: { collection, relativePath, newRelativePath } }
63892
63961
  );
63893
63962
  if (this.searchClient) {
63894
63963
  const { document: doc } = await this.fetchDocument(
@@ -63902,18 +63971,18 @@ class TinaAdminApi {
63902
63971
  this.maxSearchIndexFieldLength
63903
63972
  );
63904
63973
  await this.searchClient.put([processed]);
63905
- await this.searchClient.del([`${collection.name}:${relativePath2}`]);
63974
+ await this.searchClient.del([`${collection.name}:${relativePath}`]);
63906
63975
  }
63907
63976
  }
63908
63977
  async deleteDocument({
63909
63978
  collection,
63910
- relativePath: relativePath2
63979
+ relativePath
63911
63980
  }) {
63912
63981
  var _a2;
63913
63982
  await this.api.request(DELETE_DOCUMENT_GQL, {
63914
- variables: { collection, relativePath: relativePath2 }
63983
+ variables: { collection, relativePath }
63915
63984
  });
63916
- await ((_a2 = this.searchClient) == null ? void 0 : _a2.del([`${collection}:${relativePath2}`]));
63985
+ await ((_a2 = this.searchClient) == null ? void 0 : _a2.del([`${collection}:${relativePath}`]));
63917
63986
  }
63918
63987
  async fetchCollection(collectionName, includeDocuments, folder = "", after3, sortKey, order, filterArgs) {
63919
63988
  let filter2 = null;
@@ -64068,7 +64137,7 @@ class TinaAdminApi {
64068
64137
  }
64069
64138
  }
64070
64139
  }
64071
- async fetchDocument(collectionName, relativePath2, values = true) {
64140
+ async fetchDocument(collectionName, relativePath, values = true) {
64072
64141
  let query;
64073
64142
  if (values) {
64074
64143
  query = `#graphql
@@ -64103,26 +64172,26 @@ class TinaAdminApi {
64103
64172
  }`;
64104
64173
  }
64105
64174
  const response = await this.api.request(query, {
64106
- variables: { collection: collectionName, relativePath: relativePath2 }
64175
+ variables: { collection: collectionName, relativePath }
64107
64176
  });
64108
64177
  return response;
64109
64178
  }
64110
- async createDocument(collection, relativePath2, params) {
64179
+ async createDocument(collection, relativePath, params) {
64111
64180
  const response = await this.api.request(CREATE_DOCUMENT_GQL, {
64112
64181
  variables: {
64113
64182
  collection: collection.name,
64114
- relativePath: relativePath2,
64183
+ relativePath,
64115
64184
  params
64116
64185
  }
64117
64186
  });
64118
64187
  if (this.searchClient) {
64119
64188
  const { document: doc } = await this.fetchDocument(
64120
64189
  collection.name,
64121
- relativePath2
64190
+ relativePath
64122
64191
  );
64123
64192
  const processed = processDocumentForIndexing(
64124
64193
  doc["_values"],
64125
- `${collection.path}/${relativePath2}`,
64194
+ `${collection.path}/${relativePath}`,
64126
64195
  collection,
64127
64196
  this.maxSearchIndexFieldLength
64128
64197
  );
@@ -64130,22 +64199,22 @@ class TinaAdminApi {
64130
64199
  }
64131
64200
  return response;
64132
64201
  }
64133
- async updateDocument(collection, relativePath2, params) {
64202
+ async updateDocument(collection, relativePath, params) {
64134
64203
  const response = await this.api.request(UPDATE_DOCUMENT_GQL, {
64135
64204
  variables: {
64136
64205
  collection: collection.name,
64137
- relativePath: relativePath2,
64206
+ relativePath,
64138
64207
  params
64139
64208
  }
64140
64209
  });
64141
64210
  if (this.searchClient) {
64142
64211
  const { document: doc } = await this.fetchDocument(
64143
64212
  collection.name,
64144
- relativePath2
64213
+ relativePath
64145
64214
  );
64146
64215
  const processed = processDocumentForIndexing(
64147
64216
  doc["_values"],
64148
- `${collection.path}/${relativePath2}`,
64217
+ `${collection.path}/${relativePath}`,
64149
64218
  collection,
64150
64219
  this.maxSearchIndexFieldLength
64151
64220
  );
@@ -64268,7 +64337,7 @@ const CreateBranchModal = ({
64268
64337
  }
64269
64338
  const collection = tinaApi.schema.getCollectionByFullPath(path3);
64270
64339
  const params = tinaApi.schema.transformPayload(collection.name, values);
64271
- const relativePath2 = pathRelativeToCollection(collection.path, path3);
64340
+ const relativePath = pathRelativeToCollection(collection.path, path3);
64272
64341
  const result = await tinaApi.executeEditorialWorkflow({
64273
64342
  branchName,
64274
64343
  baseBranch: tinaApi.branch,
@@ -64277,7 +64346,7 @@ const CreateBranchModal = ({
64277
64346
  query: graphql2,
64278
64347
  variables: {
64279
64348
  collection: collection.name,
64280
- relativePath: relativePath2,
64349
+ relativePath,
64281
64350
  params
64282
64351
  }
64283
64352
  },
@@ -64309,7 +64378,7 @@ const CreateBranchModal = ({
64309
64378
  0
64310
64379
  );
64311
64380
  if (crudType === "create") {
64312
- const folderPath = relativePath2.includes("/") ? relativePath2.substring(0, relativePath2.lastIndexOf("/")) : "";
64381
+ const folderPath = relativePath.includes("/") ? relativePath.substring(0, relativePath.lastIndexOf("/")) : "";
64313
64382
  window.location.hash = `#/collections/${collection.name}${folderPath ? `/${folderPath}` : ""}`;
64314
64383
  }
64315
64384
  close2();
@@ -64676,7 +64745,7 @@ const Emoji = ({ className = "", ...props }) => /* @__PURE__ */ React.createElem
64676
64745
  const CreateBranchModel = ({
64677
64746
  close: close2,
64678
64747
  safeSubmit,
64679
- relativePath: relativePath2,
64748
+ relativePath,
64680
64749
  values,
64681
64750
  crudType
64682
64751
  }) => /* @__PURE__ */ React.createElement(
@@ -64684,7 +64753,7 @@ const CreateBranchModel = ({
64684
64753
  {
64685
64754
  close: close2,
64686
64755
  safeSubmit,
64687
- path: relativePath2,
64756
+ path: relativePath,
64688
64757
  values,
64689
64758
  crudType
64690
64759
  }
@@ -119904,44 +119973,68 @@ class LocalClient extends Client {
119904
119973
  }
119905
119974
  class TinaCMSSearchClient {
119906
119975
  constructor(client, tinaSearchConfig) {
119976
+ __publicField(this, "client");
119977
+ __publicField(this, "fuzzyEnabled");
119978
+ __publicField(this, "stopwordLanguages");
119979
+ __publicField(this, "defaultFuzzyOptions");
119907
119980
  this.client = client;
119908
- this.tinaSearchConfig = tinaSearchConfig;
119981
+ this.fuzzyEnabled = (tinaSearchConfig == null ? void 0 : tinaSearchConfig.fuzzyEnabled) ?? true;
119982
+ this.stopwordLanguages = tinaSearchConfig == null ? void 0 : tinaSearchConfig.stopwordLanguages;
119983
+ this.defaultFuzzyOptions = tinaSearchConfig == null ? void 0 : tinaSearchConfig.fuzzyOptions;
119909
119984
  }
119910
- async query(query, options) {
119911
- var _a2;
119985
+ getSearchBaseUrl(useFuzzy) {
119986
+ const version2 = useFuzzy ? "v2" : "";
119987
+ const searchPath = version2 ? `${version2}/searchIndex` : "searchIndex";
119988
+ return `${this.client.contentApiBase}/${searchPath}/${this.client.clientId}/${this.client.getBranch()}`;
119989
+ }
119990
+ buildSearchUrl(query, options, useFuzzy) {
119991
+ const baseUrl = this.getSearchBaseUrl(useFuzzy);
119992
+ if (useFuzzy) {
119993
+ const params = new URLSearchParams();
119994
+ params.set("query", query);
119995
+ if (options == null ? void 0 : options.collection) {
119996
+ params.set("collection", options.collection);
119997
+ }
119998
+ if (options == null ? void 0 : options.limit) {
119999
+ params.set("limit", options.limit.toString());
120000
+ }
120001
+ if (options == null ? void 0 : options.cursor) {
120002
+ params.set("cursor", options.cursor);
120003
+ }
120004
+ return `${baseUrl}?${params.toString()}`;
120005
+ }
120006
+ const queryWithCollection = (options == null ? void 0 : options.collection) ? `${query} AND _collection:${options.collection}` : query;
119912
120007
  const q2 = queryToSearchIndexQuery(
119913
- query,
119914
- (_a2 = this.tinaSearchConfig) == null ? void 0 : _a2.stopwordLanguages
120008
+ queryWithCollection,
120009
+ this.stopwordLanguages
119915
120010
  );
119916
120011
  const opt = optionsToSearchIndexOptions(options);
119917
120012
  const optionsParam = opt["PAGE"] ? `&options=${JSON.stringify(opt)}` : "";
119918
- const res = await this.client.authProvider.fetchWithToken(
119919
- `${this.client.contentApiBase}/searchIndex/${this.client.clientId}/${this.client.getBranch()}?q=${JSON.stringify(q2)}${optionsParam}`
119920
- );
120013
+ return `${baseUrl}?q=${JSON.stringify(q2)}${optionsParam}`;
120014
+ }
120015
+ async query(query, options) {
120016
+ const useFuzzy = (options == null ? void 0 : options.fuzzy) !== void 0 ? options.fuzzy : this.fuzzyEnabled;
120017
+ const url = this.buildSearchUrl(query, options, useFuzzy);
120018
+ const res = await this.client.authProvider.fetchWithToken(url);
119921
120019
  return parseSearchIndexResponse(await res.json(), options);
119922
120020
  }
119923
120021
  async del(ids) {
120022
+ const baseUrl = this.getSearchBaseUrl(this.fuzzyEnabled);
119924
120023
  const res = await this.client.authProvider.fetchWithToken(
119925
- `${this.client.contentApiBase}/searchIndex/${this.client.clientId}/${this.client.getBranch()}?ids=${ids.join(",")}`,
119926
- {
119927
- method: "DELETE"
119928
- }
120024
+ `${baseUrl}?ids=${ids.join(",")}`,
120025
+ { method: "DELETE" }
119929
120026
  );
119930
120027
  if (res.status !== 200) {
119931
120028
  throw new Error("Failed to update search index");
119932
120029
  }
119933
120030
  }
119934
120031
  async put(docs) {
119935
- const res = await this.client.authProvider.fetchWithToken(
119936
- `${this.client.contentApiBase}/searchIndex/${this.client.clientId}/${this.client.getBranch()}`,
119937
- {
119938
- method: "POST",
119939
- body: JSON.stringify({ docs }),
119940
- headers: {
119941
- "Content-Type": "application/json"
119942
- }
119943
- }
119944
- );
120032
+ const baseUrl = this.getSearchBaseUrl(this.fuzzyEnabled);
120033
+ const res = await this.client.authProvider.fetchWithToken(baseUrl, {
120034
+ method: "POST",
120035
+ body: JSON.stringify({ docs }),
120036
+ headers: { "Content-Type": "application/json" }
120037
+ });
119945
120038
  if (res.status !== 200) {
119946
120039
  throw new Error("Failed to update search index");
119947
120040
  }
@@ -119949,29 +120042,62 @@ class TinaCMSSearchClient {
119949
120042
  supportsClientSideIndexing() {
119950
120043
  return true;
119951
120044
  }
120045
+ getDefaultLimit() {
120046
+ return 15;
120047
+ }
119952
120048
  }
119953
120049
  class LocalSearchClient {
119954
- constructor(client) {
120050
+ constructor(client, tinaSearchConfig) {
120051
+ __publicField(this, "client");
120052
+ __publicField(this, "fuzzyEnabled");
120053
+ __publicField(this, "defaultFuzzyOptions");
119955
120054
  this.client = client;
120055
+ this.fuzzyEnabled = (tinaSearchConfig == null ? void 0 : tinaSearchConfig.fuzzyEnabled) ?? true;
120056
+ this.defaultFuzzyOptions = tinaSearchConfig == null ? void 0 : tinaSearchConfig.fuzzyOptions;
119956
120057
  }
119957
- async query(query, options) {
119958
- const q2 = queryToSearchIndexQuery(query);
120058
+ getSearchBaseUrl(useFuzzy) {
120059
+ return useFuzzy ? "http://localhost:4001/v2/searchIndex" : "http://localhost:4001/searchIndex";
120060
+ }
120061
+ buildSearchUrl(query, options, useFuzzy) {
120062
+ const baseUrl = this.getSearchBaseUrl(!!useFuzzy);
120063
+ if (useFuzzy) {
120064
+ const params = new URLSearchParams();
120065
+ params.set("query", query);
120066
+ if (options == null ? void 0 : options.collection) {
120067
+ params.set("collection", options.collection);
120068
+ }
120069
+ if (options == null ? void 0 : options.limit) {
120070
+ params.set("limit", options.limit.toString());
120071
+ }
120072
+ if (options == null ? void 0 : options.cursor) {
120073
+ params.set("cursor", options.cursor);
120074
+ }
120075
+ return `${baseUrl}?${params.toString()}`;
120076
+ }
120077
+ const queryWithCollection = (options == null ? void 0 : options.collection) ? `${query} AND _collection:${options.collection}` : query;
120078
+ const q2 = queryToSearchIndexQuery(queryWithCollection);
119959
120079
  const opt = optionsToSearchIndexOptions(options);
119960
120080
  const optionsParam = opt["PAGE"] ? `&options=${JSON.stringify(opt)}` : "";
119961
- const res = await this.client.authProvider.fetchWithToken(
119962
- `http://localhost:4001/searchIndex?q=${JSON.stringify(q2)}${optionsParam}`
119963
- );
120081
+ return `${baseUrl}?q=${JSON.stringify(q2)}${optionsParam}`;
120082
+ }
120083
+ async query(query, options) {
120084
+ const useFuzzy = (options == null ? void 0 : options.fuzzy) !== void 0 ? options.fuzzy : this.fuzzyEnabled;
120085
+ const url = this.buildSearchUrl(query, options, useFuzzy);
120086
+ const res = await this.client.authProvider.fetchWithToken(url);
119964
120087
  return parseSearchIndexResponse(await res.json(), options);
119965
120088
  }
119966
- del(ids) {
119967
- return Promise.resolve(void 0);
120089
+ del(_ids) {
120090
+ return Promise.resolve();
119968
120091
  }
119969
- put(docs) {
119970
- return Promise.resolve(void 0);
120092
+ put(_docs) {
120093
+ return Promise.resolve();
119971
120094
  }
119972
120095
  supportsClientSideIndexing() {
119973
120096
  return false;
119974
120097
  }
120098
+ getDefaultLimit() {
120099
+ return 15;
120100
+ }
119975
120101
  }
119976
120102
  function ModalBuilder(modalProps) {
119977
120103
  return /* @__PURE__ */ React__default.createElement(Modal, null, /* @__PURE__ */ React__default.createElement(ModalPopup, null, /* @__PURE__ */ React__default.createElement(ModalHeader, null, modalProps.title), /* @__PURE__ */ React__default.createElement(ModalBody, { padded: true }, modalProps.message && (typeof modalProps.message === "string" ? /* @__PURE__ */ React__default.createElement("p", null, modalProps.message) : modalProps.message), modalProps.error && /* @__PURE__ */ React__default.createElement(ErrorLabel, null, modalProps.error), modalProps.children), /* @__PURE__ */ React__default.createElement(ModalActions, null, modalProps.actions.map((action) => /* @__PURE__ */ React__default.createElement(AsyncButton, { key: action.name, ...action })))));
@@ -120266,19 +120392,22 @@ const TinaCloudProvider = (props) => {
120266
120392
  cms.api.tina.setBranch(currentBranch);
120267
120393
  }
120268
120394
  useEffect(() => {
120269
- var _a3, _b2, _c2, _d, _e, _f;
120395
+ var _a3, _b2, _c2, _d, _e, _f, _g, _h;
120270
120396
  let searchClient;
120271
120397
  if (props.isLocalClient) {
120272
- searchClient = new LocalSearchClient(cms.api.tina);
120398
+ searchClient = new LocalSearchClient(
120399
+ cms.api.tina,
120400
+ (_b2 = (_a3 = props.schema.config) == null ? void 0 : _a3.search) == null ? void 0 : _b2.tina
120401
+ );
120273
120402
  } else {
120274
- const hasTinaSearch = Boolean((_b2 = (_a3 = props.schema.config) == null ? void 0 : _a3.search) == null ? void 0 : _b2.tina);
120403
+ const hasTinaSearch = Boolean((_d = (_c2 = props.schema.config) == null ? void 0 : _c2.search) == null ? void 0 : _d.tina);
120275
120404
  if (hasTinaSearch) {
120276
120405
  searchClient = new TinaCMSSearchClient(
120277
120406
  cms.api.tina,
120278
- (_d = (_c2 = props.schema.config) == null ? void 0 : _c2.search) == null ? void 0 : _d.tina
120407
+ (_f = (_e = props.schema.config) == null ? void 0 : _e.search) == null ? void 0 : _f.tina
120279
120408
  );
120280
120409
  } else {
120281
- searchClient = (_f = (_e = props.schema.config) == null ? void 0 : _e.search) == null ? void 0 : _f.searchClient;
120410
+ searchClient = (_h = (_g = props.schema.config) == null ? void 0 : _g.search) == null ? void 0 : _h.searchClient;
120282
120411
  }
120283
120412
  }
120284
120413
  if (searchClient) {
@@ -120412,18 +120541,18 @@ class ContentCreatorPlugin {
120412
120541
  this.onChange = options.onChange;
120413
120542
  this.initialValues = options.initialValues;
120414
120543
  }
120415
- async onSubmit({ collection, template, relativePath: relativePath2 }, cms) {
120544
+ async onSubmit({ collection, template, relativePath }, cms) {
120416
120545
  try {
120417
120546
  const selectedCollection = this.collections.find(
120418
120547
  (collectionItem) => collectionItem.slug === collection
120419
120548
  );
120420
120549
  const collectionFormat = selectedCollection.format;
120421
120550
  const extensionLength = -1 * (collectionFormat.length + 1);
120422
- let relativePathWithExt = relativePath2;
120423
- if (relativePath2.slice(extensionLength).toLocaleLowerCase() === `.${collectionFormat}`) {
120424
- relativePathWithExt = `${relativePath2.slice(0, -3)}.${collectionFormat}`;
120551
+ let relativePathWithExt = relativePath;
120552
+ if (relativePath.slice(extensionLength).toLocaleLowerCase() === `.${collectionFormat}`) {
120553
+ relativePathWithExt = `${relativePath.slice(0, -3)}.${collectionFormat}`;
120425
120554
  } else {
120426
- relativePathWithExt = `${relativePath2}.${collectionFormat}`;
120555
+ relativePathWithExt = `${relativePath}.${collectionFormat}`;
120427
120556
  }
120428
120557
  const payload = {
120429
120558
  relativePath: relativePathWithExt,
@@ -121324,6 +121453,10 @@ const CollectionListPage = () => {
121324
121453
  booleanEquals: null
121325
121454
  }));
121326
121455
  }, [collectionName]);
121456
+ useEffect(() => {
121457
+ setEndCursor("");
121458
+ setPrevCursors([]);
121459
+ }, [search]);
121327
121460
  const tableRowStyle = "hover:bg-gray-50/50 border-b-2 border-gray-50 transition-colors duration-300";
121328
121461
  const tableHeadingCellStyle = "px-3 py-3 text-left text-xs font-bold text-gray-700 tracking-wider";
121329
121462
  const tableHeadingStyle2 = "bg-gray-100 border-b-2 border-gray-200";
@@ -121583,6 +121716,8 @@ const CollectionListPage = () => {
121583
121716
  ))), /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-1 flex-row gap-2 items-end w-full" }, searchEnabled ? /* @__PURE__ */ React__default.createElement(
121584
121717
  SearchInput,
121585
121718
  {
121719
+ cms,
121720
+ collectionName,
121586
121721
  loading: _loading,
121587
121722
  search,
121588
121723
  setSearch,
@@ -121915,46 +122050,67 @@ const SearchInput = ({
121915
122050
  setSearchInput
121916
122051
  }) => {
121917
122052
  const [searchLoaded, setSearchLoaded] = useState(false);
122053
+ const inputRef = React__default.useRef(null);
121918
122054
  useEffect(() => {
121919
- if (loading) {
122055
+ setSearchLoaded(!loading);
122056
+ }, [loading]);
122057
+ const handleKeyDown = (e3) => {
122058
+ if (e3.key === "Enter") {
122059
+ e3.preventDefault();
122060
+ if (searchInput.trim()) {
122061
+ setSearch(searchInput);
122062
+ setSearchLoaded(false);
122063
+ }
122064
+ }
122065
+ };
122066
+ const handleSubmit = (e3) => {
122067
+ e3.preventDefault();
122068
+ if (searchInput.trim()) {
122069
+ setSearch(searchInput);
121920
122070
  setSearchLoaded(false);
121921
- } else {
121922
- setSearchLoaded(true);
121923
122071
  }
121924
- }, [loading]);
121925
- return /* @__PURE__ */ React__default.createElement("form", { className: "flex flex-1 flex-col gap-2 items-start w-full" }, /* @__PURE__ */ React__default.createElement("div", { className: "h-4" }), /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-col md:flex-row items-start md:items-center w-full md:w-auto gap-3" }, /* @__PURE__ */ React__default.createElement("div", { className: "flex-1 min-w-[200px] w-full md:w-auto relative" }, /* @__PURE__ */ React__default.createElement(BiSearch, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 pointer-events-none" }), /* @__PURE__ */ React__default.createElement(
121926
- "input",
122072
+ };
122073
+ return /* @__PURE__ */ React__default.createElement(
122074
+ "form",
121927
122075
  {
121928
- type: "text",
121929
- name: "search",
121930
- placeholder: "Search...",
121931
- value: searchInput,
121932
- onChange: (e3) => {
121933
- setSearchInput(e3.target.value);
121934
- },
121935
- onKeyDown: (e3) => {
121936
- if (e3.key === "Enter") {
122076
+ className: "flex flex-1 flex-col gap-2 items-start w-full",
122077
+ onSubmit: handleSubmit
122078
+ },
122079
+ /* @__PURE__ */ React__default.createElement("div", { className: "h-4" }),
122080
+ /* @__PURE__ */ React__default.createElement("div", { className: "flex items-center w-full md:w-auto gap-3" }, /* @__PURE__ */ React__default.createElement("div", { className: "flex-1 min-w-[200px] relative" }, /* @__PURE__ */ React__default.createElement(BiSearch, { className: "absolute left-3 top-1/2 -translate-y-1/2 w-5 h-5 text-gray-400 pointer-events-none z-10" }), /* @__PURE__ */ React__default.createElement(
122081
+ "input",
122082
+ {
122083
+ ref: inputRef,
122084
+ type: "text",
122085
+ name: "search",
122086
+ placeholder: "Search...",
122087
+ value: searchInput,
122088
+ onChange: (e3) => setSearchInput(e3.target.value),
122089
+ onKeyDown: handleKeyDown,
122090
+ className: "shadow appearance-none bg-white block pl-10 pr-10 py-2 truncate w-full text-base border border-gray-200 focus:outline-none focus:shadow-outline focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded placeholder:text-gray-300 text-gray-600 focus:text-gray-900",
122091
+ autoComplete: "off"
122092
+ }
122093
+ ), search && searchLoaded && /* @__PURE__ */ React__default.createElement(
122094
+ "button",
122095
+ {
122096
+ onClick: (e3) => {
121937
122097
  e3.preventDefault();
121938
- if (searchInput.trim()) {
121939
- setSearch(searchInput);
121940
- setSearchLoaded(false);
121941
- }
121942
- }
122098
+ setSearch("");
122099
+ setSearchInput("");
122100
+ },
122101
+ className: "absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors z-10"
121943
122102
  },
121944
- className: "shadow appearance-none bg-white block pl-10 pr-10 py-2 truncate w-full text-base border border-gray-200 focus:outline-none focus:shadow-outline focus:ring-blue-500 focus:border-blue-500 sm:text-sm rounded placeholder:text-gray-300 text-gray-600 focus:text-gray-900"
121945
- }
121946
- ), search && searchLoaded && /* @__PURE__ */ React__default.createElement(
121947
- "button",
121948
- {
121949
- onClick: (e3) => {
121950
- e3.preventDefault();
121951
- setSearch("");
121952
- setSearchInput("");
122103
+ /* @__PURE__ */ React__default.createElement(BiX, { className: "w-5 h-5" })
122104
+ )), /* @__PURE__ */ React__default.createElement(
122105
+ Button$2,
122106
+ {
122107
+ variant: "primary",
122108
+ type: "submit",
122109
+ className: "focus:ring-0 focus:shadow-none"
121953
122110
  },
121954
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors"
121955
- },
121956
- /* @__PURE__ */ React__default.createElement(BiX, { className: "w-5 h-5" })
121957
- ))));
122111
+ "Search"
122112
+ ))
122113
+ );
121958
122114
  };
121959
122115
  const Breadcrumb = ({ folder, navigate, collectionName }) => {
121960
122116
  const folderArray = folder.name.split("/");
@@ -122222,17 +122378,16 @@ const useSearchCollection = (cms, collectionName, includeDocuments = true, folde
122222
122378
  const searchCollection = async () => {
122223
122379
  if (await api.isAuthenticated() && !folder.loading && !cancelled) {
122224
122380
  try {
122225
- const response = await cms.api.search.query(
122226
- `${search} AND _collection:${collectionName}`,
122227
- {
122228
- limit: 15,
122229
- cursor: after3
122230
- }
122231
- );
122381
+ const response = await cms.api.search.query(search, {
122382
+ limit: 15,
122383
+ cursor: after3,
122384
+ collection: collectionName
122385
+ });
122386
+ const results = (response == null ? void 0 : response.results) ?? [];
122232
122387
  const docs = await Promise.allSettled(
122233
- response.results.map((result) => {
122234
- const [collection2, relativePath2] = result._id.split(":");
122235
- return api.fetchDocument(collection2, relativePath2, false);
122388
+ results.map((result) => {
122389
+ const [collection2, relativePath] = result._id.split(":");
122390
+ return api.fetchDocument(collection2, relativePath, false);
122236
122391
  })
122237
122392
  );
122238
122393
  const edges2 = docs.filter((p2) => {
@@ -122240,21 +122395,22 @@ const useSearchCollection = (cms, collectionName, includeDocuments = true, folde
122240
122395
  return p2.status === "fulfilled" && !!((_a2 = p2.value) == null ? void 0 : _a2.document);
122241
122396
  }).map((result) => ({ node: result.value.document }));
122242
122397
  const c2 = await api.fetchCollection(collectionName, false, "");
122243
- setCollection({
122244
- format: collection.format,
122245
- label: collection.label,
122398
+ const collectionData = {
122399
+ format: c2.format,
122400
+ label: c2.label,
122246
122401
  name: collectionName,
122247
- templates: collection.templates,
122402
+ templates: c2.templates,
122248
122403
  documents: {
122249
122404
  pageInfo: {
122250
- hasNextPage: !!response.nextCursor,
122251
- hasPreviousPage: !!response.prevCursor,
122405
+ hasNextPage: !!(response == null ? void 0 : response.nextCursor),
122406
+ hasPreviousPage: !!(response == null ? void 0 : response.prevCursor),
122252
122407
  startCursor: "",
122253
- endCursor: response.nextCursor || ""
122408
+ endCursor: (response == null ? void 0 : response.nextCursor) || ""
122254
122409
  },
122255
122410
  edges: edges2
122256
122411
  }
122257
- });
122412
+ };
122413
+ setCollection(collectionData);
122258
122414
  } catch (error22) {
122259
122415
  cms.alerts.error(
122260
122416
  `[${error22.name}] GetCollection failed: ${error22.message}`
@@ -122357,14 +122513,14 @@ const createDocument = async (cms, collection, template, mutationInfo, folder, v
122357
122513
  throw new Error("Filename must be a string");
122358
122514
  }
122359
122515
  const appendFolder = folder && !filename.startsWith("/") ? `/${folder}/` : "/";
122360
- const relativePath2 = `${appendFolder}${filename}.${collection.format}`;
122516
+ const relativePath = `${appendFolder}${filename}.${collection.format}`;
122361
122517
  const params = api.schema.transformPayload(collection.name, {
122362
122518
  _collection: collection.name,
122363
122519
  ...template && { _template: template.name },
122364
122520
  ...leftover
122365
122521
  });
122366
122522
  if (await api.isAuthenticated()) {
122367
- await api.createDocument(collection, relativePath2, params);
122523
+ await api.createDocument(collection, relativePath, params);
122368
122524
  } else {
122369
122525
  const authMessage = `CreateDocument failed: User is no longer authenticated; please login and try again.`;
122370
122526
  cms.alerts.error(authMessage);
@@ -122614,7 +122770,7 @@ const RenderForm$1 = ({
122614
122770
  ), /* @__PURE__ */ React__default.createElement(FormStatus, { pristine: formIsPristine }))
122615
122771
  ), activeForm && /* @__PURE__ */ React__default.createElement(FormBuilder, { form: activeForm, onPristineChange: setFormIsPristine })));
122616
122772
  };
122617
- const useGetDocument = (cms, collectionName, relativePath2) => {
122773
+ const useGetDocument = (cms, collectionName, relativePath) => {
122618
122774
  const api = new TinaAdminApi(cms);
122619
122775
  const [document2, setDocument] = useState(void 0);
122620
122776
  const [loading, setLoading] = useState(true);
@@ -122626,7 +122782,7 @@ const useGetDocument = (cms, collectionName, relativePath2) => {
122626
122782
  try {
122627
122783
  const response = await api.fetchDocument(
122628
122784
  collectionName,
122629
- relativePath2
122785
+ relativePath
122630
122786
  );
122631
122787
  if (!isCancelled) {
122632
122788
  setDocument(response.document);
@@ -122651,19 +122807,19 @@ const useGetDocument = (cms, collectionName, relativePath2) => {
122651
122807
  return () => {
122652
122808
  isCancelled = true;
122653
122809
  };
122654
- }, [cms, collectionName, relativePath2]);
122810
+ }, [cms, collectionName, relativePath]);
122655
122811
  return { document: document2, loading, error: error2 };
122656
122812
  };
122657
122813
  const GetDocument = ({
122658
122814
  cms,
122659
122815
  collectionName,
122660
- relativePath: relativePath2,
122816
+ relativePath,
122661
122817
  children
122662
122818
  }) => {
122663
122819
  const { document: document2, loading, error: error2 } = useGetDocument(
122664
122820
  cms,
122665
122821
  collectionName,
122666
- relativePath2
122822
+ relativePath
122667
122823
  );
122668
122824
  if (error2) {
122669
122825
  return /* @__PURE__ */ React__default.createElement(FullscreenError, null);
@@ -122686,7 +122842,7 @@ const CollectionDuplicatePage = () => {
122686
122842
  includeDocuments: false
122687
122843
  },
122688
122844
  (collection) => {
122689
- const relativePath2 = `${filename.startsWith("~/") ? filename.substring(2) : filename}.${collection.format}`;
122845
+ const relativePath = `${filename.startsWith("~/") ? filename.substring(2) : filename}.${collection.format}`;
122690
122846
  const mutationInfo = {
122691
122847
  includeCollection: true,
122692
122848
  includeTemplate: !!collection.templates
@@ -122696,7 +122852,7 @@ const CollectionDuplicatePage = () => {
122696
122852
  {
122697
122853
  cms,
122698
122854
  collectionName: collection.name,
122699
- relativePath: relativePath2
122855
+ relativePath
122700
122856
  },
122701
122857
  (document2) => {
122702
122858
  var _a2;
@@ -122716,11 +122872,11 @@ const CollectionDuplicatePage = () => {
122716
122872
  }
122717
122873
  ));
122718
122874
  };
122719
- const updateDocument = async (cms, relativePath2, collection, mutationInfo, values) => {
122875
+ const updateDocument = async (cms, relativePath, collection, mutationInfo, values) => {
122720
122876
  const api = new TinaAdminApi(cms);
122721
122877
  const params = api.schema.transformPayload(collection.name, values);
122722
122878
  if (await api.isAuthenticated()) {
122723
- await api.updateDocument(collection, relativePath2, params);
122879
+ await api.updateDocument(collection, relativePath, params);
122724
122880
  } else {
122725
122881
  const authMessage = `UpdateDocument failed: User is no longer authenticated; please login and try again.`;
122726
122882
  cms.alerts.error(authMessage);
@@ -122742,7 +122898,7 @@ const CollectionUpdatePage = () => {
122742
122898
  includeDocuments: false
122743
122899
  },
122744
122900
  (collection) => {
122745
- const relativePath2 = `${resolvedFile}.${collection.format}`;
122901
+ const relativePath = `${resolvedFile}.${collection.format}`;
122746
122902
  const mutationInfo = {
122747
122903
  includeCollection: true,
122748
122904
  includeTemplate: !!collection.templates
@@ -122752,7 +122908,7 @@ const CollectionUpdatePage = () => {
122752
122908
  {
122753
122909
  cms,
122754
122910
  collectionName: collection.name,
122755
- relativePath: relativePath2
122911
+ relativePath
122756
122912
  },
122757
122913
  (document2) => /* @__PURE__ */ React__default.createElement(
122758
122914
  RenderForm,
@@ -122760,7 +122916,7 @@ const CollectionUpdatePage = () => {
122760
122916
  cms,
122761
122917
  document: document2,
122762
122918
  filename: resolvedFile,
122763
- relativePath: relativePath2,
122919
+ relativePath,
122764
122920
  collection,
122765
122921
  mutationInfo
122766
122922
  }
@@ -122773,7 +122929,7 @@ const RenderForm = ({
122773
122929
  cms,
122774
122930
  document: document2,
122775
122931
  filename,
122776
- relativePath: relativePath2,
122932
+ relativePath,
122777
122933
  collection,
122778
122934
  mutationInfo
122779
122935
  }) => {
@@ -122794,7 +122950,7 @@ const RenderForm = ({
122794
122950
  const form = useMemo(() => {
122795
122951
  return new Form({
122796
122952
  // id is the full document path
122797
- id: canonicalPath(`${schemaCollection.path}/${relativePath2}`),
122953
+ id: canonicalPath(`${schemaCollection.path}/${relativePath}`),
122798
122954
  label: "form",
122799
122955
  fields: formInfo.fields,
122800
122956
  initialValues: document2._values,
@@ -122802,7 +122958,7 @@ const RenderForm = ({
122802
122958
  try {
122803
122959
  await updateDocument(
122804
122960
  cms,
122805
- relativePath2,
122961
+ relativePath,
122806
122962
  collection,
122807
122963
  mutationInfo,
122808
122964
  values
@@ -122823,7 +122979,7 @@ const RenderForm = ({
122823
122979
  }
122824
122980
  }
122825
122981
  });
122826
- }, [cms, document2, relativePath2, collection, mutationInfo]);
122982
+ }, [cms, document2, relativePath, collection, mutationInfo]);
122827
122983
  React__default.useEffect(() => {
122828
122984
  cms.dispatch({ type: "forms:add", value: form });
122829
122985
  cms.dispatch({ type: "forms:set-active-form-id", value: form.id });
@@ -122854,7 +123010,7 @@ const RenderForm = ({
122854
123010
  {
122855
123011
  defaultBranchName: (_a2 = cms.api.admin.api.schema.config.config.repoProvider) == null ? void 0 : _a2.defaultBranchName,
122856
123012
  historyUrl: (_b = cms.api.admin.api.schema.config.config.repoProvider) == null ? void 0 : _b.historyUrl,
122857
- contentRelativePath: relativePath2,
123013
+ contentRelativePath: relativePath,
122858
123014
  tinaBranch: cms.api.admin.api.branch,
122859
123015
  isLocalMode: (_d = (_c = cms.api) == null ? void 0 : _c.tina) == null ? void 0 : _d.isLocalMode
122860
123016
  }