tinacms 3.1.3 → 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";
@@ -1402,6 +1402,7 @@ function wrapFieldsWithMeta(Field2) {
1402
1402
  error: props.meta.error,
1403
1403
  index: props.index,
1404
1404
  tinaForm: props.tinaForm,
1405
+ field: props.field,
1405
1406
  focusIntent: props.field.focusIntent,
1406
1407
  hoverIntent: props.field.hoverIntent
1407
1408
  },
@@ -1454,6 +1455,7 @@ const FieldMeta = ({
1454
1455
  children,
1455
1456
  index,
1456
1457
  tinaForm,
1458
+ field,
1457
1459
  focusIntent,
1458
1460
  hoverIntent,
1459
1461
  ...props
@@ -1481,6 +1483,7 @@ const FieldMeta = ({
1481
1483
  FieldWrapper,
1482
1484
  {
1483
1485
  margin,
1486
+ field,
1484
1487
  onMouseOver: () => setHoveredField({ id: tinaForm.id, fieldName: name }),
1485
1488
  onMouseOut: () => setHoveredField({ id: null, fieldName: null }),
1486
1489
  onClick: handleClick,
@@ -1497,9 +1500,10 @@ const FieldMeta = ({
1497
1500
  const FieldWrapper = ({
1498
1501
  margin,
1499
1502
  children,
1503
+ field,
1500
1504
  "data-tina-field-active": dataActive,
1501
1505
  "data-tina-field-hovering": dataHovering,
1502
- ...restProps
1506
+ ...props
1503
1507
  }) => {
1504
1508
  const isActive = dataActive === "true";
1505
1509
  const isHovering = dataHovering === "true";
@@ -1521,10 +1525,10 @@ const FieldWrapper = ({
1521
1525
  return /* @__PURE__ */ React.createElement(
1522
1526
  "div",
1523
1527
  {
1524
- className: `relative ${margin ? `mb-5 last:mb-0` : ``} ${getFieldStateClasses()}`,
1528
+ className: `relative w-full px-2 ${margin ? "mb-5 last:mb-0" : ""} ${(field == null ? void 0 : field.width) === "half" ? "@sm:w-1/2" : ""} ${getFieldStateClasses()}`,
1525
1529
  "data-tina-field-active": dataActive,
1526
1530
  "data-tina-field-hovering": dataHovering,
1527
- ...restProps
1531
+ ...props
1528
1532
  },
1529
1533
  children
1530
1534
  );
@@ -1991,21 +1995,29 @@ function isDraftable$1(value) {
1991
1995
  return isPlainObject$4(value) || Array.isArray(value) || !!value[DRAFTABLE] || !!((_a2 = value.constructor) == null ? void 0 : _a2[DRAFTABLE]) || isMap$2(value) || isSet$2(value);
1992
1996
  }
1993
1997
  var objectCtorString$1 = Object.prototype.constructor.toString();
1998
+ var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
1994
1999
  function isPlainObject$4(value) {
1995
2000
  if (!value || typeof value !== "object")
1996
2001
  return false;
1997
- const proto = getPrototypeOf(value);
1998
- if (proto === null) {
2002
+ const proto = Object.getPrototypeOf(value);
2003
+ if (proto === null || proto === Object.prototype)
1999
2004
  return true;
2000
- }
2001
2005
  const Ctor = Object.hasOwnProperty.call(proto, "constructor") && proto.constructor;
2002
2006
  if (Ctor === Object)
2003
2007
  return true;
2004
- 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;
2005
2016
  }
2006
- function each(obj, iter) {
2017
+ function each(obj, iter, strict = true) {
2007
2018
  if (getArchtype(obj) === 0) {
2008
- Reflect.ownKeys(obj).forEach((key) => {
2019
+ const keys2 = strict ? Reflect.ownKeys(obj) : Object.keys(obj);
2020
+ keys2.forEach((key) => {
2009
2021
  iter(key, obj[key], obj);
2010
2022
  });
2011
2023
  } else {
@@ -2088,17 +2100,27 @@ function freeze$1(obj, deep = false) {
2088
2100
  if (isFrozen(obj) || isDraft$1(obj) || !isDraftable$1(obj))
2089
2101
  return obj;
2090
2102
  if (getArchtype(obj) > 1) {
2091
- 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
+ });
2092
2109
  }
2093
2110
  Object.freeze(obj);
2094
2111
  if (deep)
2095
- Object.entries(obj).forEach(([key, value]) => freeze$1(value, true));
2112
+ Object.values(obj).forEach((value) => freeze$1(value, true));
2096
2113
  return obj;
2097
2114
  }
2098
2115
  function dontMutateFrozenCollections() {
2099
2116
  die(2);
2100
2117
  }
2118
+ var dontMutateMethodOverride = {
2119
+ value: dontMutateFrozenCollections
2120
+ };
2101
2121
  function isFrozen(obj) {
2122
+ if (obj === null || typeof obj !== "object")
2123
+ return true;
2102
2124
  return Object.isFrozen(obj);
2103
2125
  }
2104
2126
  var plugins = {};
@@ -2186,11 +2208,13 @@ function processResult(result, scope) {
2186
2208
  function finalize(rootScope, value, path3) {
2187
2209
  if (isFrozen(value))
2188
2210
  return value;
2211
+ const useStrictIteration = rootScope.immer_.shouldUseStrictIteration();
2189
2212
  const state = value[DRAFT_STATE];
2190
2213
  if (!state) {
2191
2214
  each(
2192
2215
  value,
2193
- (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path3)
2216
+ (key, childValue) => finalizeProperty(rootScope, state, value, key, childValue, path3),
2217
+ useStrictIteration
2194
2218
  );
2195
2219
  return value;
2196
2220
  }
@@ -2213,7 +2237,16 @@ function finalize(rootScope, value, path3) {
2213
2237
  }
2214
2238
  each(
2215
2239
  resultEach,
2216
- (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
2217
2250
  );
2218
2251
  maybeFreeze(rootScope, result, false);
2219
2252
  if (path3 && rootScope.patches_) {
@@ -2228,6 +2261,16 @@ function finalize(rootScope, value, path3) {
2228
2261
  return state.copy_;
2229
2262
  }
2230
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
+ }
2231
2274
  if (process.env.NODE_ENV !== "production" && childValue === targetObject)
2232
2275
  die(5);
2233
2276
  if (isDraft$1(childValue)) {
@@ -2242,12 +2285,15 @@ function finalizeProperty(rootScope, parentState, targetObject, prop2, childValu
2242
2285
  } else if (targetIsSet) {
2243
2286
  targetObject.add(childValue);
2244
2287
  }
2245
- if (isDraftable$1(childValue) && !isFrozen(childValue)) {
2288
+ if (isDraftable$1(childValue) && !childIsFrozen) {
2246
2289
  if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
2247
2290
  return;
2248
2291
  }
2292
+ if (parentState && parentState.base_ && parentState.base_[prop2] === childValue && childIsFrozen) {
2293
+ return;
2294
+ }
2249
2295
  finalize(rootScope, childValue);
2250
- 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)))
2251
2297
  maybeFreeze(rootScope, childValue);
2252
2298
  }
2253
2299
  }
@@ -2443,6 +2489,7 @@ var Immer2 = class {
2443
2489
  constructor(config) {
2444
2490
  this.autoFreeze_ = true;
2445
2491
  this.useStrictShallowCopy_ = false;
2492
+ this.useStrictIteration_ = true;
2446
2493
  this.produce = (base, recipe, patchListener) => {
2447
2494
  if (typeof base === "function" && typeof recipe !== "function") {
2448
2495
  const defaultBase = recipe;
@@ -2505,6 +2552,8 @@ var Immer2 = class {
2505
2552
  this.setAutoFreeze(config.autoFreeze);
2506
2553
  if (typeof (config == null ? void 0 : config.useStrictShallowCopy) === "boolean")
2507
2554
  this.setUseStrictShallowCopy(config.useStrictShallowCopy);
2555
+ if (typeof (config == null ? void 0 : config.useStrictIteration) === "boolean")
2556
+ this.setUseStrictIteration(config.useStrictIteration);
2508
2557
  }
2509
2558
  createDraft(base) {
2510
2559
  if (!isDraftable$1(base))
@@ -2541,6 +2590,18 @@ var Immer2 = class {
2541
2590
  setUseStrictShallowCopy(value) {
2542
2591
  this.useStrictShallowCopy_ = value;
2543
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
+ }
2544
2605
  applyPatches(base, patches) {
2545
2606
  let i2;
2546
2607
  for (i2 = patches.length - 1; i2 >= 0; i2--) {
@@ -2579,17 +2640,23 @@ function currentImpl(value) {
2579
2640
  return value;
2580
2641
  const state = value[DRAFT_STATE];
2581
2642
  let copy2;
2643
+ let strict = true;
2582
2644
  if (state) {
2583
2645
  if (!state.modified_)
2584
2646
  return state.base_;
2585
2647
  state.finalized_ = true;
2586
2648
  copy2 = shallowCopy$1(value, state.scope_.immer_.useStrictShallowCopy_);
2649
+ strict = state.scope_.immer_.shouldUseStrictIteration();
2587
2650
  } else {
2588
2651
  copy2 = shallowCopy$1(value, true);
2589
2652
  }
2590
- each(copy2, (key, childValue) => {
2591
- set$3(copy2, key, currentImpl(childValue));
2592
- });
2653
+ each(
2654
+ copy2,
2655
+ (key, childValue) => {
2656
+ set$3(copy2, key, currentImpl(childValue));
2657
+ },
2658
+ strict
2659
+ );
2593
2660
  if (state) {
2594
2661
  state.finalized_ = false;
2595
2662
  }
@@ -2597,14 +2664,8 @@ function currentImpl(value) {
2597
2664
  }
2598
2665
  var immer = new Immer2();
2599
2666
  var produce = immer.produce;
2600
- immer.produceWithPatches.bind(
2601
- immer
2602
- );
2603
- immer.setAutoFreeze.bind(immer);
2604
- immer.setUseStrictShallowCopy.bind(immer);
2605
- immer.applyPatches.bind(immer);
2606
- var createDraft$1 = immer.createDraft.bind(immer);
2607
- var finishDraft = immer.finishDraft.bind(immer);
2667
+ var createDraft$1 = /* @__PURE__ */ immer.createDraft.bind(immer);
2668
+ var finishDraft = /* @__PURE__ */ immer.finishDraft.bind(immer);
2608
2669
  var PathRef = {
2609
2670
  transform(ref, op) {
2610
2671
  var {
@@ -10988,7 +11049,7 @@ var TextString = (props) => {
10988
11049
  ref
10989
11050
  }, initialText);
10990
11051
  };
10991
- var MemoizedText$1 = /* @__PURE__ */ memo$1(/* @__PURE__ */ forwardRef((props, ref) => {
11052
+ var MemoizedText$1 = /* @__PURE__ */ memo(/* @__PURE__ */ forwardRef((props, ref) => {
10992
11053
  return /* @__PURE__ */ React__default.createElement("span", {
10993
11054
  "data-slate-string": true,
10994
11055
  ref
@@ -15600,8 +15661,9 @@ const devtoolsImpl = (fn, devtoolsOptions = {}) => (set2, get2, api) => {
15600
15661
  const r2 = set2(state, replace);
15601
15662
  if (!isRecording)
15602
15663
  return r2;
15603
- const inferredActionType = findCallerName(new Error().stack);
15604
- 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;
15605
15667
  if (store === void 0) {
15606
15668
  connection == null ? void 0 : connection.send(action, get2());
15607
15669
  return r2;
@@ -15889,12 +15951,12 @@ const persistImpl = (config, baseOptions) => (set2, get2, api) => {
15889
15951
  const savedSetState = api.setState;
15890
15952
  api.setState = (state, replace) => {
15891
15953
  savedSetState(state, replace);
15892
- void setItem();
15954
+ return setItem();
15893
15955
  };
15894
15956
  const configResult = config(
15895
15957
  (...args) => {
15896
15958
  set2(...args);
15897
- void setItem();
15959
+ return setItem();
15898
15960
  },
15899
15961
  get2,
15900
15962
  api
@@ -38245,7 +38307,7 @@ function FieldsBuilder({
38245
38307
  }, [setFieldPlugins]);
38246
38308
  React.useEffect(() => updateFieldPlugins(), []);
38247
38309
  useEventSubscription("plugin:add:field", () => updateFieldPlugins(), []);
38248
- return /* @__PURE__ */ React.createElement(FieldsGroup, { padding }, fields.map((field, index) => {
38310
+ return /* @__PURE__ */ React.createElement(FieldsGroup, null, fields.map((field, index) => {
38249
38311
  return /* @__PURE__ */ React.createElement(
38250
38312
  InnerField,
38251
38313
  {
@@ -38306,6 +38368,7 @@ const InnerField = ({
38306
38368
  {
38307
38369
  name: field.name,
38308
38370
  key: field.name,
38371
+ className: "w-full",
38309
38372
  isEqual: (a2, b) => isEqual(field, a2, b),
38310
38373
  type,
38311
38374
  parse: parse2 ? (value, name) => parse2(value, name, field) : void 0,
@@ -38354,13 +38417,12 @@ const InnerField = ({
38354
38417
  );
38355
38418
  };
38356
38419
  const FieldsGroup = ({
38357
- padding,
38358
38420
  children
38359
38421
  }) => {
38360
38422
  return /* @__PURE__ */ React.createElement(
38361
38423
  "div",
38362
38424
  {
38363
- className: `relative block w-full h-full whitespace-nowrap overflow-x-visible ${padding ? `pb-5` : ``}`
38425
+ className: `relative flex flex-wrap w-full h-full whitespace-nowrap overflow-x-visible`
38364
38426
  },
38365
38427
  children
38366
38428
  );
@@ -39977,7 +40039,7 @@ const Select$1 = ({
39977
40039
  ref.current.focus();
39978
40040
  }
39979
40041
  }, [field == null ? void 0 : field.focusIntent, ref]);
39980
- return /* @__PURE__ */ React.createElement("div", { className: "relative group w-full h-full md:w-auto" }, /* @__PURE__ */ React.createElement(
40042
+ return /* @__PURE__ */ React.createElement("div", { className: "relative group w-full h-fit md:w-auto" }, /* @__PURE__ */ React.createElement(
39981
40043
  "select",
39982
40044
  {
39983
40045
  id: input.name,
@@ -42917,7 +42979,10 @@ const formatCurrentDate = ({
42917
42979
  if (!dateFormat) {
42918
42980
  return format$1(displayDate, timeFormat);
42919
42981
  }
42920
- return `${format$1(displayDate, dateFormat)} ${format$1(displayDate, timeFormat)}`;
42982
+ return `${format$1(displayDate, dateFormat)} ${format$1(
42983
+ displayDate,
42984
+ timeFormat
42985
+ )}`;
42921
42986
  };
42922
42987
  function Calendar({
42923
42988
  className,
@@ -43319,7 +43384,8 @@ const DateTimePicker = React.forwardRef(
43319
43384
  }),
43320
43385
  [displayDate]
43321
43386
  );
43322
- const { options, localize: localize2, formatLong: formatLong2 } = locale;
43387
+ const localeAny = locale;
43388
+ const { options, localize: localize2, formatLong: formatLong2 } = localeAny || {};
43323
43389
  if (options && localize2 && formatLong2) {
43324
43390
  ({
43325
43391
  ...enUS,
@@ -46527,7 +46593,7 @@ const NavProvider = ({
46527
46593
  };
46528
46594
  return /* @__PURE__ */ React__default.createElement(NavContext.Provider, { value }, children);
46529
46595
  };
46530
- const version$1 = "3.1.3";
46596
+ const version$1 = "3.3.0";
46531
46597
  const VersionInfo = () => {
46532
46598
  var _a2, _b, _c, _d, _e, _f;
46533
46599
  const cms = useCMS();
@@ -52341,7 +52407,7 @@ const nld = [
52341
52407
  "in",
52342
52408
  "is",
52343
52409
  "ja",
52344
- "je ",
52410
+ "je",
52345
52411
  "kan",
52346
52412
  "kon",
52347
52413
  "kunnen",
@@ -63631,195 +63697,202 @@ var __publicField2 = (obj, key, value) => {
63631
63697
  __defNormalProp2(obj, typeof key !== "symbol" ? key + "" : key, value);
63632
63698
  return value;
63633
63699
  };
63700
+ const INDEXABLE_NODE_TYPES = ["text", "code_block", "html"];
63634
63701
  class StringBuilder {
63635
63702
  constructor(limit) {
63636
- __publicField2(this, "buffer");
63637
- __publicField2(this, "length", 0);
63703
+ __publicField2(this, "buffer", []);
63638
63704
  __publicField2(this, "limit");
63639
- this.buffer = [];
63705
+ __publicField2(this, "length", 0);
63640
63706
  this.limit = limit;
63641
63707
  }
63642
63708
  append(str) {
63643
- if (this.length + str.length > this.limit) {
63709
+ if (this.length + str.length > this.limit)
63644
63710
  return true;
63645
- } else {
63646
- this.buffer.push(str);
63647
- this.length += str.length;
63648
- if (this.length > this.limit) {
63649
- return true;
63650
- }
63651
- return false;
63652
- }
63711
+ this.buffer.push(str);
63712
+ this.length += str.length;
63713
+ return this.length > this.limit;
63653
63714
  }
63654
63715
  toString() {
63655
63716
  return this.buffer.join(" ");
63656
63717
  }
63657
63718
  }
63658
- const extractText = (data, acc, indexableNodeTypes) => {
63659
- var _a2, _b;
63660
- if (data) {
63661
- if (indexableNodeTypes.indexOf(data.type) !== -1 && (data.text || data.value)) {
63662
- const tokens = tokenizeString(data.text || data.value);
63663
- for (const token of tokens) {
63664
- if (acc.append(token)) {
63665
- return;
63666
- }
63667
- }
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;
63668
63731
  }
63669
- (_b = (_a2 = data.children) == null ? void 0 : _a2.forEach) == null ? void 0 : _b.call(
63670
- _a2,
63671
- (child) => extractText(child, acc, indexableNodeTypes)
63672
- );
63673
63732
  }
63733
+ (_a2 = data.children) == null ? void 0 : _a2.forEach((child) => extractText(child, builder, nodeTypes));
63674
63734
  };
63675
- const relativePath = (path3, collection) => {
63735
+ const getRelativePath = (path3, collection) => {
63676
63736
  return path3.replace(/\\/g, "/").replace(collection.path, "").replace(/^\/|\/$/g, "");
63677
63737
  };
63678
- const tokenizeString = (str) => {
63679
- return str.split(/[\s\.,]+/).map((s2) => s2.toLowerCase()).filter((s2) => s2);
63680
- };
63681
- const processTextFieldValue = (value, maxLen) => {
63738
+ const processTextField = (value, maxLength) => {
63682
63739
  const tokens = tokenizeString(value);
63683
- const builder = new StringBuilder(maxLen);
63740
+ const builder = new StringBuilder(maxLength);
63684
63741
  for (const part of tokens) {
63685
- if (builder.append(part)) {
63742
+ if (builder.append(part))
63686
63743
  break;
63687
- }
63688
63744
  }
63689
63745
  return builder.toString();
63690
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
+ };
63691
63782
  const processDocumentForIndexing = (data, path3, collection, textIndexLength, field) => {
63692
63783
  if (!field) {
63693
- const relPath = relativePath(path3, collection);
63694
- data["_id"] = `${collection.name}:${relPath}`;
63695
- data["_relativePath"] = relPath;
63784
+ const relativePath = getRelativePath(path3, collection);
63785
+ data["_id"] = `${collection.name}:${relativePath}`;
63786
+ data["_relativePath"] = relativePath;
63696
63787
  }
63697
- 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) {
63698
63790
  if (!f2.searchable) {
63699
63791
  delete data[f2.name];
63700
63792
  continue;
63701
63793
  }
63702
- const isList = f2.list;
63703
- if (data[f2.name]) {
63704
- if (f2.type === "object") {
63705
- if (isList) {
63706
- data[f2.name] = data[f2.name].map(
63707
- (obj) => processDocumentForIndexing(
63708
- obj,
63709
- path3,
63710
- collection,
63711
- textIndexLength,
63712
- f2
63713
- )
63714
- );
63715
- } else {
63716
- data[f2.name] = processDocumentForIndexing(
63717
- data[f2.name],
63718
- path3,
63719
- collection,
63720
- textIndexLength,
63721
- f2
63722
- );
63723
- }
63724
- } else if (f2.type === "string") {
63725
- const fieldTextIndexLength = f2.maxSearchIndexFieldLength || textIndexLength;
63726
- if (isList) {
63727
- data[f2.name] = data[f2.name].map(
63728
- (value) => processTextFieldValue(value, fieldTextIndexLength)
63729
- );
63730
- } else {
63731
- data[f2.name] = processTextFieldValue(
63732
- data[f2.name],
63733
- fieldTextIndexLength
63734
- );
63735
- }
63736
- } else if (f2.type === "rich-text") {
63737
- const fieldTextIndexLength = f2.maxSearchIndexFieldLength || textIndexLength;
63738
- if (isList) {
63739
- data[f2.name] = data[f2.name].map((value) => {
63740
- const acc = new StringBuilder(fieldTextIndexLength);
63741
- extractText(value, acc, ["text", "code_block", "html"]);
63742
- return acc.toString();
63743
- });
63744
- } else {
63745
- const acc = new StringBuilder(fieldTextIndexLength);
63746
- extractText(data[f2.name], acc, ["text", "code_block", "html"]);
63747
- data[f2.name] = acc.toString();
63748
- }
63749
- }
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;
63750
63822
  }
63751
63823
  }
63752
63824
  return data;
63753
63825
  };
63754
- const memo = {};
63826
+ const stopwordCache = {};
63755
63827
  const lookupStopwords = (keys2, defaultStopWords = eng) => {
63756
- let stopwords = defaultStopWords;
63757
- if (keys2) {
63758
- if (memo[keys2.join(",")]) {
63759
- return memo[keys2.join(",")];
63760
- }
63761
- stopwords = [];
63762
- for (const key of keys2) {
63763
- stopwords.push(...sw[key]);
63764
- }
63765
- memo[keys2.join(",")] = stopwords;
63828
+ if (!keys2) {
63829
+ return defaultStopWords;
63830
+ }
63831
+ const cacheKey = keys2.join(",");
63832
+ if (stopwordCache[cacheKey]) {
63833
+ return stopwordCache[cacheKey];
63766
63834
  }
63835
+ const stopwords = keys2.flatMap((key) => sw[key] || []);
63836
+ stopwordCache[cacheKey] = stopwords;
63767
63837
  return stopwords;
63768
63838
  };
63769
63839
  const queryToSearchIndexQuery = (query, stopwordLanguages) => {
63770
- let q2;
63771
63840
  const parts = query.split(" ");
63772
63841
  const stopwords = lookupStopwords(stopwordLanguages);
63773
63842
  if (parts.length === 1) {
63774
- q2 = { AND: [parts[0]] };
63775
- } else {
63776
- q2 = {
63777
- AND: parts.filter(
63778
- (part) => part.toLowerCase() !== "and" && stopwords.indexOf(part.toLowerCase()) === -1
63779
- )
63780
- };
63843
+ return { AND: [parts[0]] };
63781
63844
  }
63782
- return q2;
63845
+ const filteredParts = parts.filter(
63846
+ (part) => part.toLowerCase() !== "and" && !stopwords.includes(part.toLowerCase())
63847
+ );
63848
+ return { AND: filteredParts };
63783
63849
  };
63784
63850
  const optionsToSearchIndexOptions = (options) => {
63785
- const opt = {};
63786
- if (options == null ? void 0 : options.limit) {
63787
- opt["PAGE"] = {
63851
+ if (!(options == null ? void 0 : options.limit))
63852
+ return {};
63853
+ return {
63854
+ PAGE: {
63788
63855
  SIZE: options.limit,
63789
- NUMBER: (options == null ? void 0 : options.cursor) ? parseInt(options.cursor) : 0
63790
- };
63791
- }
63792
- return opt;
63856
+ NUMBER: options.cursor ? parseInt(options.cursor) : 0
63857
+ }
63858
+ };
63793
63859
  };
63794
63860
  const parseSearchIndexResponse = (data, options) => {
63795
- const results = data["RESULT"];
63796
- const total = data["RESULT_LENGTH"];
63797
- if ((options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
63798
- const prevCursor = options.cursor === "0" ? null : (parseInt(options.cursor) - 1).toString();
63799
- 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)) {
63800
63863
  return {
63801
- results,
63802
- total,
63803
- prevCursor,
63804
- nextCursor
63805
- };
63806
- } else if (!(options == null ? void 0 : options.cursor) && (options == null ? void 0 : options.limit)) {
63807
- const prevCursor = null;
63808
- const nextCursor = total <= options.limit ? null : "1";
63809
- return {
63810
- results,
63811
- total,
63812
- prevCursor,
63813
- nextCursor
63864
+ results: [],
63865
+ total: 0,
63866
+ prevCursor: null,
63867
+ nextCursor: null,
63868
+ fuzzyMatches: void 0
63814
63869
  };
63815
- } else {
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) {
63816
63877
  return {
63817
63878
  results,
63818
63879
  total,
63819
- prevCursor: null,
63820
- nextCursor: null
63880
+ prevCursor: prevCursor ?? null,
63881
+ nextCursor: nextCursor ?? null,
63882
+ fuzzyMatches
63821
63883
  };
63822
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
+ };
63823
63896
  };
63824
63897
  const CREATE_DOCUMENT_GQL = `#graphql
63825
63898
  mutation($collection: String!, $relativePath: String!, $params: DocumentMutation!) {
@@ -63875,7 +63948,7 @@ class TinaAdminApi {
63875
63948
  fetchCollections() {
63876
63949
  return this.schema.getCollections();
63877
63950
  }
63878
- async renameDocument({ collection, relativePath: relativePath2, newRelativePath }) {
63951
+ async renameDocument({ collection, relativePath, newRelativePath }) {
63879
63952
  await this.api.request(
63880
63953
  `#graphql
63881
63954
  mutation RenameDocument($collection: String!, $relativePath: String! $newRelativePath: String!) {
@@ -63884,7 +63957,7 @@ class TinaAdminApi {
63884
63957
  }
63885
63958
  }
63886
63959
  `,
63887
- { variables: { collection, relativePath: relativePath2, newRelativePath } }
63960
+ { variables: { collection, relativePath, newRelativePath } }
63888
63961
  );
63889
63962
  if (this.searchClient) {
63890
63963
  const { document: doc } = await this.fetchDocument(
@@ -63898,18 +63971,18 @@ class TinaAdminApi {
63898
63971
  this.maxSearchIndexFieldLength
63899
63972
  );
63900
63973
  await this.searchClient.put([processed]);
63901
- await this.searchClient.del([`${collection.name}:${relativePath2}`]);
63974
+ await this.searchClient.del([`${collection.name}:${relativePath}`]);
63902
63975
  }
63903
63976
  }
63904
63977
  async deleteDocument({
63905
63978
  collection,
63906
- relativePath: relativePath2
63979
+ relativePath
63907
63980
  }) {
63908
63981
  var _a2;
63909
63982
  await this.api.request(DELETE_DOCUMENT_GQL, {
63910
- variables: { collection, relativePath: relativePath2 }
63983
+ variables: { collection, relativePath }
63911
63984
  });
63912
- await ((_a2 = this.searchClient) == null ? void 0 : _a2.del([`${collection}:${relativePath2}`]));
63985
+ await ((_a2 = this.searchClient) == null ? void 0 : _a2.del([`${collection}:${relativePath}`]));
63913
63986
  }
63914
63987
  async fetchCollection(collectionName, includeDocuments, folder = "", after3, sortKey, order, filterArgs) {
63915
63988
  let filter2 = null;
@@ -64064,7 +64137,7 @@ class TinaAdminApi {
64064
64137
  }
64065
64138
  }
64066
64139
  }
64067
- async fetchDocument(collectionName, relativePath2, values = true) {
64140
+ async fetchDocument(collectionName, relativePath, values = true) {
64068
64141
  let query;
64069
64142
  if (values) {
64070
64143
  query = `#graphql
@@ -64099,26 +64172,26 @@ class TinaAdminApi {
64099
64172
  }`;
64100
64173
  }
64101
64174
  const response = await this.api.request(query, {
64102
- variables: { collection: collectionName, relativePath: relativePath2 }
64175
+ variables: { collection: collectionName, relativePath }
64103
64176
  });
64104
64177
  return response;
64105
64178
  }
64106
- async createDocument(collection, relativePath2, params) {
64179
+ async createDocument(collection, relativePath, params) {
64107
64180
  const response = await this.api.request(CREATE_DOCUMENT_GQL, {
64108
64181
  variables: {
64109
64182
  collection: collection.name,
64110
- relativePath: relativePath2,
64183
+ relativePath,
64111
64184
  params
64112
64185
  }
64113
64186
  });
64114
64187
  if (this.searchClient) {
64115
64188
  const { document: doc } = await this.fetchDocument(
64116
64189
  collection.name,
64117
- relativePath2
64190
+ relativePath
64118
64191
  );
64119
64192
  const processed = processDocumentForIndexing(
64120
64193
  doc["_values"],
64121
- `${collection.path}/${relativePath2}`,
64194
+ `${collection.path}/${relativePath}`,
64122
64195
  collection,
64123
64196
  this.maxSearchIndexFieldLength
64124
64197
  );
@@ -64126,22 +64199,22 @@ class TinaAdminApi {
64126
64199
  }
64127
64200
  return response;
64128
64201
  }
64129
- async updateDocument(collection, relativePath2, params) {
64202
+ async updateDocument(collection, relativePath, params) {
64130
64203
  const response = await this.api.request(UPDATE_DOCUMENT_GQL, {
64131
64204
  variables: {
64132
64205
  collection: collection.name,
64133
- relativePath: relativePath2,
64206
+ relativePath,
64134
64207
  params
64135
64208
  }
64136
64209
  });
64137
64210
  if (this.searchClient) {
64138
64211
  const { document: doc } = await this.fetchDocument(
64139
64212
  collection.name,
64140
- relativePath2
64213
+ relativePath
64141
64214
  );
64142
64215
  const processed = processDocumentForIndexing(
64143
64216
  doc["_values"],
64144
- `${collection.path}/${relativePath2}`,
64217
+ `${collection.path}/${relativePath}`,
64145
64218
  collection,
64146
64219
  this.maxSearchIndexFieldLength
64147
64220
  );
@@ -64264,7 +64337,7 @@ const CreateBranchModal = ({
64264
64337
  }
64265
64338
  const collection = tinaApi.schema.getCollectionByFullPath(path3);
64266
64339
  const params = tinaApi.schema.transformPayload(collection.name, values);
64267
- const relativePath2 = pathRelativeToCollection(collection.path, path3);
64340
+ const relativePath = pathRelativeToCollection(collection.path, path3);
64268
64341
  const result = await tinaApi.executeEditorialWorkflow({
64269
64342
  branchName,
64270
64343
  baseBranch: tinaApi.branch,
@@ -64273,7 +64346,7 @@ const CreateBranchModal = ({
64273
64346
  query: graphql2,
64274
64347
  variables: {
64275
64348
  collection: collection.name,
64276
- relativePath: relativePath2,
64349
+ relativePath,
64277
64350
  params
64278
64351
  }
64279
64352
  },
@@ -64305,7 +64378,7 @@ const CreateBranchModal = ({
64305
64378
  0
64306
64379
  );
64307
64380
  if (crudType === "create") {
64308
- const folderPath = relativePath2.includes("/") ? relativePath2.substring(0, relativePath2.lastIndexOf("/")) : "";
64381
+ const folderPath = relativePath.includes("/") ? relativePath.substring(0, relativePath.lastIndexOf("/")) : "";
64309
64382
  window.location.hash = `#/collections/${collection.name}${folderPath ? `/${folderPath}` : ""}`;
64310
64383
  }
64311
64384
  close2();
@@ -64657,9 +64730,9 @@ const FormWrapper = ({
64657
64730
  "div",
64658
64731
  {
64659
64732
  "data-test": `form:${id2 == null ? void 0 : id2.replace(/\\/g, "/")}`,
64660
- className: "h-full overflow-y-auto max-h-full bg-gray-50"
64733
+ className: "h-full overflow-y-auto max-h-full bg-gray-50 @container"
64661
64734
  },
64662
- /* @__PURE__ */ React.createElement("div", { className: "py-5 px-6" }, children)
64735
+ /* @__PURE__ */ React.createElement("div", { className: "py-5 px-4" }, children)
64663
64736
  );
64664
64737
  };
64665
64738
  const Emoji = ({ className = "", ...props }) => /* @__PURE__ */ React.createElement(
@@ -64672,7 +64745,7 @@ const Emoji = ({ className = "", ...props }) => /* @__PURE__ */ React.createElem
64672
64745
  const CreateBranchModel = ({
64673
64746
  close: close2,
64674
64747
  safeSubmit,
64675
- relativePath: relativePath2,
64748
+ relativePath,
64676
64749
  values,
64677
64750
  crudType
64678
64751
  }) => /* @__PURE__ */ React.createElement(
@@ -64680,7 +64753,7 @@ const CreateBranchModel = ({
64680
64753
  {
64681
64754
  close: close2,
64682
64755
  safeSubmit,
64683
- path: relativePath2,
64756
+ path: relativePath,
64684
64757
  values,
64685
64758
  crudType
64686
64759
  }
@@ -119900,44 +119973,68 @@ class LocalClient extends Client {
119900
119973
  }
119901
119974
  class TinaCMSSearchClient {
119902
119975
  constructor(client, tinaSearchConfig) {
119976
+ __publicField(this, "client");
119977
+ __publicField(this, "fuzzyEnabled");
119978
+ __publicField(this, "stopwordLanguages");
119979
+ __publicField(this, "defaultFuzzyOptions");
119903
119980
  this.client = client;
119904
- 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;
119905
119984
  }
119906
- async query(query, options) {
119907
- 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;
119908
120007
  const q2 = queryToSearchIndexQuery(
119909
- query,
119910
- (_a2 = this.tinaSearchConfig) == null ? void 0 : _a2.stopwordLanguages
120008
+ queryWithCollection,
120009
+ this.stopwordLanguages
119911
120010
  );
119912
120011
  const opt = optionsToSearchIndexOptions(options);
119913
120012
  const optionsParam = opt["PAGE"] ? `&options=${JSON.stringify(opt)}` : "";
119914
- const res = await this.client.authProvider.fetchWithToken(
119915
- `${this.client.contentApiBase}/searchIndex/${this.client.clientId}/${this.client.getBranch()}?q=${JSON.stringify(q2)}${optionsParam}`
119916
- );
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);
119917
120019
  return parseSearchIndexResponse(await res.json(), options);
119918
120020
  }
119919
120021
  async del(ids) {
120022
+ const baseUrl = this.getSearchBaseUrl(this.fuzzyEnabled);
119920
120023
  const res = await this.client.authProvider.fetchWithToken(
119921
- `${this.client.contentApiBase}/searchIndex/${this.client.clientId}/${this.client.getBranch()}?ids=${ids.join(",")}`,
119922
- {
119923
- method: "DELETE"
119924
- }
120024
+ `${baseUrl}?ids=${ids.join(",")}`,
120025
+ { method: "DELETE" }
119925
120026
  );
119926
120027
  if (res.status !== 200) {
119927
120028
  throw new Error("Failed to update search index");
119928
120029
  }
119929
120030
  }
119930
120031
  async put(docs) {
119931
- const res = await this.client.authProvider.fetchWithToken(
119932
- `${this.client.contentApiBase}/searchIndex/${this.client.clientId}/${this.client.getBranch()}`,
119933
- {
119934
- method: "POST",
119935
- body: JSON.stringify({ docs }),
119936
- headers: {
119937
- "Content-Type": "application/json"
119938
- }
119939
- }
119940
- );
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
+ });
119941
120038
  if (res.status !== 200) {
119942
120039
  throw new Error("Failed to update search index");
119943
120040
  }
@@ -119945,29 +120042,62 @@ class TinaCMSSearchClient {
119945
120042
  supportsClientSideIndexing() {
119946
120043
  return true;
119947
120044
  }
120045
+ getDefaultLimit() {
120046
+ return 15;
120047
+ }
119948
120048
  }
119949
120049
  class LocalSearchClient {
119950
- constructor(client) {
120050
+ constructor(client, tinaSearchConfig) {
120051
+ __publicField(this, "client");
120052
+ __publicField(this, "fuzzyEnabled");
120053
+ __publicField(this, "defaultFuzzyOptions");
119951
120054
  this.client = client;
120055
+ this.fuzzyEnabled = (tinaSearchConfig == null ? void 0 : tinaSearchConfig.fuzzyEnabled) ?? true;
120056
+ this.defaultFuzzyOptions = tinaSearchConfig == null ? void 0 : tinaSearchConfig.fuzzyOptions;
119952
120057
  }
119953
- async query(query, options) {
119954
- 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);
119955
120079
  const opt = optionsToSearchIndexOptions(options);
119956
120080
  const optionsParam = opt["PAGE"] ? `&options=${JSON.stringify(opt)}` : "";
119957
- const res = await this.client.authProvider.fetchWithToken(
119958
- `http://localhost:4001/searchIndex?q=${JSON.stringify(q2)}${optionsParam}`
119959
- );
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);
119960
120087
  return parseSearchIndexResponse(await res.json(), options);
119961
120088
  }
119962
- del(ids) {
119963
- return Promise.resolve(void 0);
120089
+ del(_ids) {
120090
+ return Promise.resolve();
119964
120091
  }
119965
- put(docs) {
119966
- return Promise.resolve(void 0);
120092
+ put(_docs) {
120093
+ return Promise.resolve();
119967
120094
  }
119968
120095
  supportsClientSideIndexing() {
119969
120096
  return false;
119970
120097
  }
120098
+ getDefaultLimit() {
120099
+ return 15;
120100
+ }
119971
120101
  }
119972
120102
  function ModalBuilder(modalProps) {
119973
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 })))));
@@ -120262,19 +120392,22 @@ const TinaCloudProvider = (props) => {
120262
120392
  cms.api.tina.setBranch(currentBranch);
120263
120393
  }
120264
120394
  useEffect(() => {
120265
- var _a3, _b2, _c2, _d, _e, _f;
120395
+ var _a3, _b2, _c2, _d, _e, _f, _g, _h;
120266
120396
  let searchClient;
120267
120397
  if (props.isLocalClient) {
120268
- 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
+ );
120269
120402
  } else {
120270
- 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);
120271
120404
  if (hasTinaSearch) {
120272
120405
  searchClient = new TinaCMSSearchClient(
120273
120406
  cms.api.tina,
120274
- (_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
120275
120408
  );
120276
120409
  } else {
120277
- 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;
120278
120411
  }
120279
120412
  }
120280
120413
  if (searchClient) {
@@ -120408,18 +120541,18 @@ class ContentCreatorPlugin {
120408
120541
  this.onChange = options.onChange;
120409
120542
  this.initialValues = options.initialValues;
120410
120543
  }
120411
- async onSubmit({ collection, template, relativePath: relativePath2 }, cms) {
120544
+ async onSubmit({ collection, template, relativePath }, cms) {
120412
120545
  try {
120413
120546
  const selectedCollection = this.collections.find(
120414
120547
  (collectionItem) => collectionItem.slug === collection
120415
120548
  );
120416
120549
  const collectionFormat = selectedCollection.format;
120417
120550
  const extensionLength = -1 * (collectionFormat.length + 1);
120418
- let relativePathWithExt = relativePath2;
120419
- if (relativePath2.slice(extensionLength).toLocaleLowerCase() === `.${collectionFormat}`) {
120420
- relativePathWithExt = `${relativePath2.slice(0, -3)}.${collectionFormat}`;
120551
+ let relativePathWithExt = relativePath;
120552
+ if (relativePath.slice(extensionLength).toLocaleLowerCase() === `.${collectionFormat}`) {
120553
+ relativePathWithExt = `${relativePath.slice(0, -3)}.${collectionFormat}`;
120421
120554
  } else {
120422
- relativePathWithExt = `${relativePath2}.${collectionFormat}`;
120555
+ relativePathWithExt = `${relativePath}.${collectionFormat}`;
120423
120556
  }
120424
120557
  const payload = {
120425
120558
  relativePath: relativePathWithExt,
@@ -121320,6 +121453,10 @@ const CollectionListPage = () => {
121320
121453
  booleanEquals: null
121321
121454
  }));
121322
121455
  }, [collectionName]);
121456
+ useEffect(() => {
121457
+ setEndCursor("");
121458
+ setPrevCursors([]);
121459
+ }, [search]);
121323
121460
  const tableRowStyle = "hover:bg-gray-50/50 border-b-2 border-gray-50 transition-colors duration-300";
121324
121461
  const tableHeadingCellStyle = "px-3 py-3 text-left text-xs font-bold text-gray-700 tracking-wider";
121325
121462
  const tableHeadingStyle2 = "bg-gray-100 border-b-2 border-gray-200";
@@ -121579,6 +121716,8 @@ const CollectionListPage = () => {
121579
121716
  ))), /* @__PURE__ */ React__default.createElement("div", { className: "flex flex-1 flex-row gap-2 items-end w-full" }, searchEnabled ? /* @__PURE__ */ React__default.createElement(
121580
121717
  SearchInput,
121581
121718
  {
121719
+ cms,
121720
+ collectionName,
121582
121721
  loading: _loading,
121583
121722
  search,
121584
121723
  setSearch,
@@ -121911,46 +122050,67 @@ const SearchInput = ({
121911
122050
  setSearchInput
121912
122051
  }) => {
121913
122052
  const [searchLoaded, setSearchLoaded] = useState(false);
122053
+ const inputRef = React__default.useRef(null);
121914
122054
  useEffect(() => {
121915
- 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);
121916
122070
  setSearchLoaded(false);
121917
- } else {
121918
- setSearchLoaded(true);
121919
122071
  }
121920
- }, [loading]);
121921
- 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(
121922
- "input",
122072
+ };
122073
+ return /* @__PURE__ */ React__default.createElement(
122074
+ "form",
121923
122075
  {
121924
- type: "text",
121925
- name: "search",
121926
- placeholder: "Search...",
121927
- value: searchInput,
121928
- onChange: (e3) => {
121929
- setSearchInput(e3.target.value);
121930
- },
121931
- onKeyDown: (e3) => {
121932
- 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) => {
121933
122097
  e3.preventDefault();
121934
- if (searchInput.trim()) {
121935
- setSearch(searchInput);
121936
- setSearchLoaded(false);
121937
- }
121938
- }
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"
121939
122102
  },
121940
- 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"
121941
- }
121942
- ), search && searchLoaded && /* @__PURE__ */ React__default.createElement(
121943
- "button",
121944
- {
121945
- onClick: (e3) => {
121946
- e3.preventDefault();
121947
- setSearch("");
121948
- 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"
121949
122110
  },
121950
- className: "absolute right-3 top-1/2 -translate-y-1/2 text-gray-400 hover:text-gray-600 transition-colors"
121951
- },
121952
- /* @__PURE__ */ React__default.createElement(BiX, { className: "w-5 h-5" })
121953
- ))));
122111
+ "Search"
122112
+ ))
122113
+ );
121954
122114
  };
121955
122115
  const Breadcrumb = ({ folder, navigate, collectionName }) => {
121956
122116
  const folderArray = folder.name.split("/");
@@ -122218,17 +122378,16 @@ const useSearchCollection = (cms, collectionName, includeDocuments = true, folde
122218
122378
  const searchCollection = async () => {
122219
122379
  if (await api.isAuthenticated() && !folder.loading && !cancelled) {
122220
122380
  try {
122221
- const response = await cms.api.search.query(
122222
- `${search} AND _collection:${collectionName}`,
122223
- {
122224
- limit: 15,
122225
- cursor: after3
122226
- }
122227
- );
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) ?? [];
122228
122387
  const docs = await Promise.allSettled(
122229
- response.results.map((result) => {
122230
- const [collection2, relativePath2] = result._id.split(":");
122231
- return api.fetchDocument(collection2, relativePath2, false);
122388
+ results.map((result) => {
122389
+ const [collection2, relativePath] = result._id.split(":");
122390
+ return api.fetchDocument(collection2, relativePath, false);
122232
122391
  })
122233
122392
  );
122234
122393
  const edges2 = docs.filter((p2) => {
@@ -122236,21 +122395,22 @@ const useSearchCollection = (cms, collectionName, includeDocuments = true, folde
122236
122395
  return p2.status === "fulfilled" && !!((_a2 = p2.value) == null ? void 0 : _a2.document);
122237
122396
  }).map((result) => ({ node: result.value.document }));
122238
122397
  const c2 = await api.fetchCollection(collectionName, false, "");
122239
- setCollection({
122240
- format: collection.format,
122241
- label: collection.label,
122398
+ const collectionData = {
122399
+ format: c2.format,
122400
+ label: c2.label,
122242
122401
  name: collectionName,
122243
- templates: collection.templates,
122402
+ templates: c2.templates,
122244
122403
  documents: {
122245
122404
  pageInfo: {
122246
- hasNextPage: !!response.nextCursor,
122247
- hasPreviousPage: !!response.prevCursor,
122405
+ hasNextPage: !!(response == null ? void 0 : response.nextCursor),
122406
+ hasPreviousPage: !!(response == null ? void 0 : response.prevCursor),
122248
122407
  startCursor: "",
122249
- endCursor: response.nextCursor || ""
122408
+ endCursor: (response == null ? void 0 : response.nextCursor) || ""
122250
122409
  },
122251
122410
  edges: edges2
122252
122411
  }
122253
- });
122412
+ };
122413
+ setCollection(collectionData);
122254
122414
  } catch (error22) {
122255
122415
  cms.alerts.error(
122256
122416
  `[${error22.name}] GetCollection failed: ${error22.message}`
@@ -122353,14 +122513,14 @@ const createDocument = async (cms, collection, template, mutationInfo, folder, v
122353
122513
  throw new Error("Filename must be a string");
122354
122514
  }
122355
122515
  const appendFolder = folder && !filename.startsWith("/") ? `/${folder}/` : "/";
122356
- const relativePath2 = `${appendFolder}${filename}.${collection.format}`;
122516
+ const relativePath = `${appendFolder}${filename}.${collection.format}`;
122357
122517
  const params = api.schema.transformPayload(collection.name, {
122358
122518
  _collection: collection.name,
122359
122519
  ...template && { _template: template.name },
122360
122520
  ...leftover
122361
122521
  });
122362
122522
  if (await api.isAuthenticated()) {
122363
- await api.createDocument(collection, relativePath2, params);
122523
+ await api.createDocument(collection, relativePath, params);
122364
122524
  } else {
122365
122525
  const authMessage = `CreateDocument failed: User is no longer authenticated; please login and try again.`;
122366
122526
  cms.alerts.error(authMessage);
@@ -122610,7 +122770,7 @@ const RenderForm$1 = ({
122610
122770
  ), /* @__PURE__ */ React__default.createElement(FormStatus, { pristine: formIsPristine }))
122611
122771
  ), activeForm && /* @__PURE__ */ React__default.createElement(FormBuilder, { form: activeForm, onPristineChange: setFormIsPristine })));
122612
122772
  };
122613
- const useGetDocument = (cms, collectionName, relativePath2) => {
122773
+ const useGetDocument = (cms, collectionName, relativePath) => {
122614
122774
  const api = new TinaAdminApi(cms);
122615
122775
  const [document2, setDocument] = useState(void 0);
122616
122776
  const [loading, setLoading] = useState(true);
@@ -122622,7 +122782,7 @@ const useGetDocument = (cms, collectionName, relativePath2) => {
122622
122782
  try {
122623
122783
  const response = await api.fetchDocument(
122624
122784
  collectionName,
122625
- relativePath2
122785
+ relativePath
122626
122786
  );
122627
122787
  if (!isCancelled) {
122628
122788
  setDocument(response.document);
@@ -122647,19 +122807,19 @@ const useGetDocument = (cms, collectionName, relativePath2) => {
122647
122807
  return () => {
122648
122808
  isCancelled = true;
122649
122809
  };
122650
- }, [cms, collectionName, relativePath2]);
122810
+ }, [cms, collectionName, relativePath]);
122651
122811
  return { document: document2, loading, error: error2 };
122652
122812
  };
122653
122813
  const GetDocument = ({
122654
122814
  cms,
122655
122815
  collectionName,
122656
- relativePath: relativePath2,
122816
+ relativePath,
122657
122817
  children
122658
122818
  }) => {
122659
122819
  const { document: document2, loading, error: error2 } = useGetDocument(
122660
122820
  cms,
122661
122821
  collectionName,
122662
- relativePath2
122822
+ relativePath
122663
122823
  );
122664
122824
  if (error2) {
122665
122825
  return /* @__PURE__ */ React__default.createElement(FullscreenError, null);
@@ -122682,7 +122842,7 @@ const CollectionDuplicatePage = () => {
122682
122842
  includeDocuments: false
122683
122843
  },
122684
122844
  (collection) => {
122685
- const relativePath2 = `${filename.startsWith("~/") ? filename.substring(2) : filename}.${collection.format}`;
122845
+ const relativePath = `${filename.startsWith("~/") ? filename.substring(2) : filename}.${collection.format}`;
122686
122846
  const mutationInfo = {
122687
122847
  includeCollection: true,
122688
122848
  includeTemplate: !!collection.templates
@@ -122692,7 +122852,7 @@ const CollectionDuplicatePage = () => {
122692
122852
  {
122693
122853
  cms,
122694
122854
  collectionName: collection.name,
122695
- relativePath: relativePath2
122855
+ relativePath
122696
122856
  },
122697
122857
  (document2) => {
122698
122858
  var _a2;
@@ -122712,11 +122872,11 @@ const CollectionDuplicatePage = () => {
122712
122872
  }
122713
122873
  ));
122714
122874
  };
122715
- const updateDocument = async (cms, relativePath2, collection, mutationInfo, values) => {
122875
+ const updateDocument = async (cms, relativePath, collection, mutationInfo, values) => {
122716
122876
  const api = new TinaAdminApi(cms);
122717
122877
  const params = api.schema.transformPayload(collection.name, values);
122718
122878
  if (await api.isAuthenticated()) {
122719
- await api.updateDocument(collection, relativePath2, params);
122879
+ await api.updateDocument(collection, relativePath, params);
122720
122880
  } else {
122721
122881
  const authMessage = `UpdateDocument failed: User is no longer authenticated; please login and try again.`;
122722
122882
  cms.alerts.error(authMessage);
@@ -122738,7 +122898,7 @@ const CollectionUpdatePage = () => {
122738
122898
  includeDocuments: false
122739
122899
  },
122740
122900
  (collection) => {
122741
- const relativePath2 = `${resolvedFile}.${collection.format}`;
122901
+ const relativePath = `${resolvedFile}.${collection.format}`;
122742
122902
  const mutationInfo = {
122743
122903
  includeCollection: true,
122744
122904
  includeTemplate: !!collection.templates
@@ -122748,7 +122908,7 @@ const CollectionUpdatePage = () => {
122748
122908
  {
122749
122909
  cms,
122750
122910
  collectionName: collection.name,
122751
- relativePath: relativePath2
122911
+ relativePath
122752
122912
  },
122753
122913
  (document2) => /* @__PURE__ */ React__default.createElement(
122754
122914
  RenderForm,
@@ -122756,7 +122916,7 @@ const CollectionUpdatePage = () => {
122756
122916
  cms,
122757
122917
  document: document2,
122758
122918
  filename: resolvedFile,
122759
- relativePath: relativePath2,
122919
+ relativePath,
122760
122920
  collection,
122761
122921
  mutationInfo
122762
122922
  }
@@ -122769,7 +122929,7 @@ const RenderForm = ({
122769
122929
  cms,
122770
122930
  document: document2,
122771
122931
  filename,
122772
- relativePath: relativePath2,
122932
+ relativePath,
122773
122933
  collection,
122774
122934
  mutationInfo
122775
122935
  }) => {
@@ -122790,7 +122950,7 @@ const RenderForm = ({
122790
122950
  const form = useMemo(() => {
122791
122951
  return new Form({
122792
122952
  // id is the full document path
122793
- id: canonicalPath(`${schemaCollection.path}/${relativePath2}`),
122953
+ id: canonicalPath(`${schemaCollection.path}/${relativePath}`),
122794
122954
  label: "form",
122795
122955
  fields: formInfo.fields,
122796
122956
  initialValues: document2._values,
@@ -122798,7 +122958,7 @@ const RenderForm = ({
122798
122958
  try {
122799
122959
  await updateDocument(
122800
122960
  cms,
122801
- relativePath2,
122961
+ relativePath,
122802
122962
  collection,
122803
122963
  mutationInfo,
122804
122964
  values
@@ -122819,7 +122979,7 @@ const RenderForm = ({
122819
122979
  }
122820
122980
  }
122821
122981
  });
122822
- }, [cms, document2, relativePath2, collection, mutationInfo]);
122982
+ }, [cms, document2, relativePath, collection, mutationInfo]);
122823
122983
  React__default.useEffect(() => {
122824
122984
  cms.dispatch({ type: "forms:add", value: form });
122825
122985
  cms.dispatch({ type: "forms:set-active-form-id", value: form.id });
@@ -122850,7 +123010,7 @@ const RenderForm = ({
122850
123010
  {
122851
123011
  defaultBranchName: (_a2 = cms.api.admin.api.schema.config.config.repoProvider) == null ? void 0 : _a2.defaultBranchName,
122852
123012
  historyUrl: (_b = cms.api.admin.api.schema.config.config.repoProvider) == null ? void 0 : _b.historyUrl,
122853
- contentRelativePath: relativePath2,
123013
+ contentRelativePath: relativePath,
122854
123014
  tinaBranch: cms.api.admin.api.branch,
122855
123015
  isLocalMode: (_d = (_c = cms.api) == null ? void 0 : _c.tina) == null ? void 0 : _d.isLocalMode
122856
123016
  }