tinacms 0.0.0-bbfd415-20241202040226 → 0.0.0-bc986dd-20250128224550

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.mjs CHANGED
@@ -6,8 +6,8 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import { z } from "zod";
8
8
  import * as React from "react";
9
- import React__default, { useState, useCallback, useEffect, useRef, createContext, forwardRef, useContext, useMemo, startTransition, createElement, Component } from "react";
10
- import { createPortal, findDOMNode } from "react-dom";
9
+ import React__default, { useState, useCallback, useEffect, useRef, createContext, forwardRef, useContext, useMemo, startTransition } from "react";
10
+ import { createPortal } from "react-dom";
11
11
  import { withRef, cn as cn$1, withVariants, withProps, withCn, createPrimitiveElement } from "@udecode/cn";
12
12
  import { toggleList, ELEMENT_UL, ELEMENT_OL, ELEMENT_H1 as ELEMENT_H1$1, ELEMENT_H2 as ELEMENT_H2$1, ELEMENT_H3 as ELEMENT_H3$1, ELEMENT_H4, ELEMENT_H5, ELEMENT_H6, ELEMENT_PARAGRAPH, ELEMENT_BLOCKQUOTE, ELEMENT_CODE_BLOCK, ELEMENT_CODE_LINE, ELEMENT_CODE_SYNTAX, ELEMENT_LI, ELEMENT_LINK, MARK_CODE, MARK_UNDERLINE, MARK_STRIKETHROUGH, MARK_ITALIC, MARK_BOLD, ELEMENT_HR, ELEMENT_TABLE, ELEMENT_TR, ELEMENT_TD, ELEMENT_TH, unwrapList, ELEMENT_TODO_LI, createTrailingBlockPlugin, createAutoformatPlugin, createExitBreakPlugin, KEYS_HEADING, createResetNodePlugin, createHeadingPlugin, createParagraphPlugin, createBlockquotePlugin, createBoldPlugin, createItalicPlugin, createUnderlinePlugin, createCodePlugin, createListPlugin, createIndentListPlugin, createHorizontalRulePlugin, createNodeIdPlugin, createTablePlugin, getListItemEntry, useListToolbarButtonState, useListToolbarButton } from "@udecode/plate";
13
13
  import { PlateElement, isCollapsed, findNodePath, getPointAfter, insertNodes, ELEMENT_DEFAULT, focusEditor, getPointBefore, setNodes, isElement, PlateLeaf, createPluginFactory, useComposedRef, useEditorRef, createPointRef, insertText, moveSelection, toggleNodeType, useElement, useRemoveNodeButton, useEditorSelector, isSelectionExpanded, withHOC, normalizeEditor, getBlockAbove, queryNode, getParentNode, isType, someNode, isSelectionAtBlockStart, setElements, insertNode, getPluginType, isBlock, isBlockAboveEmpty, findNode, PlateContent, getNodeEntries, useEditorState, collapseSelection, useMarkToolbarButtonState, useMarkToolbarButton, insertEmptyElement, usePlateSelectors, useEventEditorSelectors, PortalBody, useFormInputProps, createPlugins, Plate } from "@udecode/plate-common";
@@ -1358,8 +1358,8 @@ const ListElementVariants = withVariants(PlateElement, listVariants, [
1358
1358
  ]);
1359
1359
  const ListElement = withRef(
1360
1360
  ({ children, variant = "ul", ...props }, ref) => {
1361
- const Component2 = variant;
1362
- return /* @__PURE__ */ React__default.createElement(ListElementVariants, { asChild: true, ref, variant, ...props }, /* @__PURE__ */ React__default.createElement(Component2, null, children));
1361
+ const Component = variant;
1362
+ return /* @__PURE__ */ React__default.createElement(ListElementVariants, { asChild: true, ref, variant, ...props }, /* @__PURE__ */ React__default.createElement(Component, null, children));
1363
1363
  }
1364
1364
  );
1365
1365
  const ELEMENT_MERMAID = "mermaid";
@@ -3679,7 +3679,7 @@ function TinaForm({ form, children }) {
3679
3679
  }));
3680
3680
  }
3681
3681
  function TinaField({
3682
- Component: Component2,
3682
+ Component,
3683
3683
  children,
3684
3684
  ...fieldProps
3685
3685
  }) {
@@ -3687,7 +3687,7 @@ function TinaField({
3687
3687
  if (!isEditing)
3688
3688
  return children || null;
3689
3689
  return /* @__PURE__ */ React.createElement(Field, { ...fieldProps }, ({ input, meta }) => {
3690
- return /* @__PURE__ */ React.createElement(Component2, { input, meta, ...fieldProps });
3690
+ return /* @__PURE__ */ React.createElement(Component, { input, meta, ...fieldProps });
3691
3691
  });
3692
3692
  }
3693
3693
  TinaField.propTypes = {
@@ -3857,7 +3857,7 @@ var _excluded = ["attr", "size", "title"];
3857
3857
  function _objectWithoutProperties(source, excluded) {
3858
3858
  if (source == null)
3859
3859
  return {};
3860
- var target = _objectWithoutPropertiesLoose$1(source, excluded);
3860
+ var target = _objectWithoutPropertiesLoose(source, excluded);
3861
3861
  var key, i;
3862
3862
  if (Object.getOwnPropertySymbols) {
3863
3863
  var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
@@ -3872,7 +3872,7 @@ function _objectWithoutProperties(source, excluded) {
3872
3872
  }
3873
3873
  return target;
3874
3874
  }
3875
- function _objectWithoutPropertiesLoose$1(source, excluded) {
3875
+ function _objectWithoutPropertiesLoose(source, excluded) {
3876
3876
  if (source == null)
3877
3877
  return {};
3878
3878
  var target = {};
@@ -4962,7 +4962,28 @@ const NumberInput = ({
4962
4962
  onChange,
4963
4963
  value,
4964
4964
  step
4965
- }) => /* @__PURE__ */ React.createElement(Input, { type: "number", step, value, onChange });
4965
+ }) => /* @__PURE__ */ React.createElement(
4966
+ Input,
4967
+ {
4968
+ type: "number",
4969
+ step,
4970
+ value,
4971
+ onChange: (event) => {
4972
+ const inputValue = event.target.value;
4973
+ const newValue = inputValue === "" ? void 0 : inputValue;
4974
+ if (onChange) {
4975
+ const syntheticEvent = {
4976
+ ...event,
4977
+ target: {
4978
+ ...event.target,
4979
+ value: newValue
4980
+ }
4981
+ };
4982
+ onChange(syntheticEvent);
4983
+ }
4984
+ }
4985
+ }
4986
+ );
4966
4987
  function useCMS() {
4967
4988
  return useCMS$1();
4968
4989
  }
@@ -7215,244 +7236,65 @@ function pad(type, value) {
7215
7236
  str = "0" + str;
7216
7237
  return str;
7217
7238
  }
7218
- function _inheritsLoose(subClass, superClass) {
7219
- subClass.prototype = Object.create(superClass.prototype);
7220
- subClass.prototype.constructor = subClass;
7221
- _setPrototypeOf(subClass, superClass);
7222
- }
7223
- function _setPrototypeOf(o, p) {
7224
- _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf2(o2, p2) {
7225
- o2.__proto__ = p2;
7226
- return o2;
7227
- };
7228
- return _setPrototypeOf(o, p);
7229
- }
7230
- function _objectWithoutPropertiesLoose(source, excluded) {
7231
- if (source == null)
7232
- return {};
7233
- var target = {};
7234
- var sourceKeys = Object.keys(source);
7235
- var key, i;
7236
- for (i = 0; i < sourceKeys.length; i++) {
7237
- key = sourceKeys[i];
7238
- if (excluded.indexOf(key) >= 0)
7239
- continue;
7240
- target[key] = source[key];
7241
- }
7242
- return target;
7243
- }
7244
- function _assertThisInitialized(self) {
7245
- if (self === void 0) {
7246
- throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
7247
- }
7248
- return self;
7249
- }
7250
- function isNodeFound(current, componentNode, ignoreClass) {
7251
- if (current === componentNode) {
7252
- return true;
7253
- }
7254
- if (current.correspondingElement) {
7255
- return current.correspondingElement.classList.contains(ignoreClass);
7256
- }
7257
- return current.classList.contains(ignoreClass);
7258
- }
7259
- function findHighest(current, componentNode, ignoreClass) {
7260
- if (current === componentNode) {
7261
- return true;
7239
+ var useClickAway$1 = {};
7240
+ var util = {};
7241
+ Object.defineProperty(util, "__esModule", { value: true });
7242
+ util.isNavigator = util.isBrowser = util.off = util.on = util.noop = void 0;
7243
+ var noop = function() {
7244
+ };
7245
+ util.noop = noop;
7246
+ function on(obj) {
7247
+ var args = [];
7248
+ for (var _i = 1; _i < arguments.length; _i++) {
7249
+ args[_i - 1] = arguments[_i];
7262
7250
  }
7263
- while (current.parentNode || current.host) {
7264
- if (current.parentNode && isNodeFound(current, componentNode, ignoreClass)) {
7265
- return true;
7266
- }
7267
- current = current.parentNode || current.host;
7251
+ if (obj && obj.addEventListener) {
7252
+ obj.addEventListener.apply(obj, args);
7268
7253
  }
7269
- return current;
7270
7254
  }
7271
- function clickedScrollbar(evt) {
7272
- return document.documentElement.clientWidth <= evt.clientX || document.documentElement.clientHeight <= evt.clientY;
7273
- }
7274
- var testPassiveEventSupport = function testPassiveEventSupport2() {
7275
- if (typeof window === "undefined" || typeof window.addEventListener !== "function") {
7276
- return;
7255
+ util.on = on;
7256
+ function off(obj) {
7257
+ var args = [];
7258
+ for (var _i = 1; _i < arguments.length; _i++) {
7259
+ args[_i - 1] = arguments[_i];
7277
7260
  }
7278
- var passive = false;
7279
- var options = Object.defineProperty({}, "passive", {
7280
- get: function get2() {
7281
- passive = true;
7282
- }
7283
- });
7284
- var noop = function noop2() {
7285
- };
7286
- window.addEventListener("testPassiveEventSupport", noop, options);
7287
- window.removeEventListener("testPassiveEventSupport", noop, options);
7288
- return passive;
7289
- };
7290
- function autoInc(seed) {
7291
- if (seed === void 0) {
7292
- seed = 0;
7261
+ if (obj && obj.removeEventListener) {
7262
+ obj.removeEventListener.apply(obj, args);
7293
7263
  }
7294
- return function() {
7295
- return ++seed;
7296
- };
7297
- }
7298
- var uid = autoInc();
7299
- var passiveEventSupport;
7300
- var handlersMap = {};
7301
- var enabledInstances = {};
7302
- var touchEvents = ["touchstart", "touchmove"];
7303
- var IGNORE_CLASS_NAME = "ignore-react-onclickoutside";
7304
- function getEventHandlerOptions(instance, eventName) {
7305
- var handlerOptions = {};
7306
- var isTouchEvent = touchEvents.indexOf(eventName) !== -1;
7307
- if (isTouchEvent && passiveEventSupport) {
7308
- handlerOptions.passive = !instance.props.preventDefault;
7309
- }
7310
- return handlerOptions;
7311
7264
  }
7312
- function onClickOutsideHOC(WrappedComponent, config) {
7313
- var _class, _temp;
7314
- var componentName = WrappedComponent.displayName || WrappedComponent.name || "Component";
7315
- return _temp = _class = /* @__PURE__ */ function(_Component) {
7316
- _inheritsLoose(onClickOutside, _Component);
7317
- function onClickOutside(props) {
7318
- var _this;
7319
- _this = _Component.call(this, props) || this;
7320
- _this.__outsideClickHandler = function(event) {
7321
- if (typeof _this.__clickOutsideHandlerProp === "function") {
7322
- _this.__clickOutsideHandlerProp(event);
7323
- return;
7324
- }
7325
- var instance = _this.getInstance();
7326
- if (typeof instance.props.handleClickOutside === "function") {
7327
- instance.props.handleClickOutside(event);
7328
- return;
7329
- }
7330
- if (typeof instance.handleClickOutside === "function") {
7331
- instance.handleClickOutside(event);
7332
- return;
7333
- }
7334
- throw new Error("WrappedComponent: " + componentName + " lacks a handleClickOutside(event) function for processing outside click events.");
7335
- };
7336
- _this.__getComponentNode = function() {
7337
- var instance = _this.getInstance();
7338
- if (config && typeof config.setClickOutsideRef === "function") {
7339
- return config.setClickOutsideRef()(instance);
7340
- }
7341
- if (typeof instance.setClickOutsideRef === "function") {
7342
- return instance.setClickOutsideRef();
7343
- }
7344
- return findDOMNode(instance);
7345
- };
7346
- _this.enableOnClickOutside = function() {
7347
- if (typeof document === "undefined" || enabledInstances[_this._uid]) {
7348
- return;
7349
- }
7350
- if (typeof passiveEventSupport === "undefined") {
7351
- passiveEventSupport = testPassiveEventSupport();
7352
- }
7353
- enabledInstances[_this._uid] = true;
7354
- var events = _this.props.eventTypes;
7355
- if (!events.forEach) {
7356
- events = [events];
7357
- }
7358
- handlersMap[_this._uid] = function(event) {
7359
- if (_this.componentNode === null)
7360
- return;
7361
- if (_this.initTimeStamp > event.timeStamp)
7362
- return;
7363
- if (_this.props.preventDefault) {
7364
- event.preventDefault();
7365
- }
7366
- if (_this.props.stopPropagation) {
7367
- event.stopPropagation();
7368
- }
7369
- if (_this.props.excludeScrollbar && clickedScrollbar(event))
7370
- return;
7371
- var current = event.composed && event.composedPath && event.composedPath().shift() || event.target;
7372
- if (findHighest(current, _this.componentNode, _this.props.outsideClickIgnoreClass) !== document) {
7373
- return;
7374
- }
7375
- _this.__outsideClickHandler(event);
7376
- };
7377
- events.forEach(function(eventName) {
7378
- document.addEventListener(eventName, handlersMap[_this._uid], getEventHandlerOptions(_assertThisInitialized(_this), eventName));
7379
- });
7380
- };
7381
- _this.disableOnClickOutside = function() {
7382
- delete enabledInstances[_this._uid];
7383
- var fn = handlersMap[_this._uid];
7384
- if (fn && typeof document !== "undefined") {
7385
- var events = _this.props.eventTypes;
7386
- if (!events.forEach) {
7387
- events = [events];
7388
- }
7389
- events.forEach(function(eventName) {
7390
- return document.removeEventListener(eventName, fn, getEventHandlerOptions(_assertThisInitialized(_this), eventName));
7391
- });
7392
- delete handlersMap[_this._uid];
7393
- }
7394
- };
7395
- _this.getRef = function(ref) {
7396
- return _this.instanceRef = ref;
7397
- };
7398
- _this._uid = uid();
7399
- _this.initTimeStamp = performance.now();
7400
- return _this;
7401
- }
7402
- var _proto = onClickOutside.prototype;
7403
- _proto.getInstance = function getInstance() {
7404
- if (WrappedComponent.prototype && !WrappedComponent.prototype.isReactComponent) {
7405
- return this;
7406
- }
7407
- var ref = this.instanceRef;
7408
- return ref.getInstance ? ref.getInstance() : ref;
7409
- };
7410
- _proto.componentDidMount = function componentDidMount() {
7411
- if (typeof document === "undefined" || !document.createElement) {
7412
- return;
7413
- }
7414
- var instance = this.getInstance();
7415
- if (config && typeof config.handleClickOutside === "function") {
7416
- this.__clickOutsideHandlerProp = config.handleClickOutside(instance);
7417
- if (typeof this.__clickOutsideHandlerProp !== "function") {
7418
- throw new Error("WrappedComponent: " + componentName + " lacks a function for processing outside click events specified by the handleClickOutside config option.");
7419
- }
7420
- }
7421
- this.componentNode = this.__getComponentNode();
7422
- if (this.props.disableOnClickOutside)
7423
- return;
7424
- this.enableOnClickOutside();
7265
+ util.off = off;
7266
+ util.isBrowser = typeof window !== "undefined";
7267
+ util.isNavigator = typeof navigator !== "undefined";
7268
+ Object.defineProperty(useClickAway$1, "__esModule", { value: true });
7269
+ var react_1 = React__default;
7270
+ var util_1 = util;
7271
+ var defaultEvents = ["mousedown", "touchstart"];
7272
+ var useClickAway = function(ref, onClickAway, events) {
7273
+ if (events === void 0) {
7274
+ events = defaultEvents;
7275
+ }
7276
+ var savedCallback = react_1.useRef(onClickAway);
7277
+ react_1.useEffect(function() {
7278
+ savedCallback.current = onClickAway;
7279
+ }, [onClickAway]);
7280
+ react_1.useEffect(function() {
7281
+ var handler = function(event) {
7282
+ var el = ref.current;
7283
+ el && !el.contains(event.target) && savedCallback.current(event);
7425
7284
  };
7426
- _proto.componentDidUpdate = function componentDidUpdate() {
7427
- this.componentNode = this.__getComponentNode();
7428
- };
7429
- _proto.componentWillUnmount = function componentWillUnmount() {
7430
- this.disableOnClickOutside();
7431
- };
7432
- _proto.render = function render() {
7433
- var _this$props = this.props;
7434
- _this$props.excludeScrollbar;
7435
- var props = _objectWithoutPropertiesLoose(_this$props, ["excludeScrollbar"]);
7436
- if (WrappedComponent.prototype && WrappedComponent.prototype.isReactComponent) {
7437
- props.ref = this.getRef;
7438
- } else {
7439
- props.wrappedRef = this.getRef;
7285
+ for (var _i = 0, events_1 = events; _i < events_1.length; _i++) {
7286
+ var eventName = events_1[_i];
7287
+ util_1.on(document, eventName, handler);
7288
+ }
7289
+ return function() {
7290
+ for (var _i2 = 0, events_2 = events; _i2 < events_2.length; _i2++) {
7291
+ var eventName2 = events_2[_i2];
7292
+ util_1.off(document, eventName2, handler);
7440
7293
  }
7441
- props.disableOnClickOutside = this.disableOnClickOutside;
7442
- props.enableOnClickOutside = this.enableOnClickOutside;
7443
- return createElement(WrappedComponent, props);
7444
7294
  };
7445
- return onClickOutside;
7446
- }(Component), _class.displayName = "OnClickOutside(" + componentName + ")", _class.defaultProps = {
7447
- eventTypes: ["mousedown", "touchstart"],
7448
- excludeScrollbar: config && config.excludeScrollbar || false,
7449
- outsideClickIgnoreClass: IGNORE_CLASS_NAME,
7450
- preventDefault: false,
7451
- stopPropagation: false
7452
- }, _class.getClass = function() {
7453
- return WrappedComponent.getClass ? WrappedComponent.getClass() : WrappedComponent;
7454
- }, _temp;
7455
- }
7295
+ }, [events, ref]);
7296
+ };
7297
+ var _default = useClickAway$1.default = useClickAway;
7456
7298
  const viewModes = {
7457
7299
  YEARS: "years",
7458
7300
  MONTHS: "months",
@@ -7981,22 +7823,13 @@ function log(message, method) {
7981
7823
  }
7982
7824
  con[method]("***react-datetime:" + message);
7983
7825
  }
7984
- class ClickOutBase extends React__default.Component {
7985
- constructor() {
7986
- super(...arguments);
7987
- __publicField(this, "container", React__default.createRef());
7988
- }
7989
- render() {
7990
- return /* @__PURE__ */ React__default.createElement("div", { className: this.props.className, ref: this.container }, this.props.children);
7991
- }
7992
- handleClickOutside(e) {
7993
- this.props.onClickOut(e);
7994
- }
7995
- setClickOutsideRef() {
7996
- return this.container.current;
7997
- }
7826
+ function ClickableWrapper({ className, onClickOut, children }) {
7827
+ const containerRef = useRef(null);
7828
+ _default(containerRef, (event) => {
7829
+ onClickOut(event);
7830
+ });
7831
+ return /* @__PURE__ */ React__default.createElement("div", { className, ref: containerRef }, children);
7998
7832
  }
7999
- const ClickableWrapper = onClickOutsideHOC(ClickOutBase);
8000
7833
  const DEFAULT_DATE_DISPLAY_FORMAT = "MMM DD, YYYY";
8001
7834
  const DEFAULT_TIME_DISPLAY_FORMAT = "h:mm A";
8002
7835
  const format$1 = (val, _name, field) => {
@@ -8039,7 +7872,10 @@ const DateField = wrapFieldsWithMeta(
8039
7872
  ReactDateTimeWithStyles,
8040
7873
  {
8041
7874
  value: input.value,
8042
- onChange: input.onChange,
7875
+ onChange: (value) => {
7876
+ const newValue = value === "" ? void 0 : value;
7877
+ input.onChange(newValue);
7878
+ },
8043
7879
  dateFormat: dateFormat || DEFAULT_DATE_DISPLAY_FORMAT,
8044
7880
  timeFormat: timeFormat || false,
8045
7881
  inputProps: { className: textFieldClasses },
@@ -9491,6 +9327,20 @@ class TinaMediaStore {
9491
9327
  }
9492
9328
  }
9493
9329
  }
9330
+ const encodeUrlIfNeeded = (url) => {
9331
+ if (url) {
9332
+ try {
9333
+ const parsed = new URL(url);
9334
+ parsed.pathname = parsed.pathname.split("/").filter((part) => part !== "").map(encodeURIComponent).join("/");
9335
+ return parsed.toString();
9336
+ } catch (e) {
9337
+ console.error("Failed to parse URL:", e);
9338
+ return url;
9339
+ }
9340
+ } else {
9341
+ return url;
9342
+ }
9343
+ };
9494
9344
  let MediaManager$1 = class MediaManager {
9495
9345
  constructor(store, events) {
9496
9346
  this.store = store;
@@ -9563,6 +9413,20 @@ let MediaManager$1 = class MediaManager {
9563
9413
  try {
9564
9414
  this.events.dispatch({ type: "media:list:start", ...options });
9565
9415
  const media = await this.store.list(options);
9416
+ media.items = media.items.map((item) => {
9417
+ if (item.type === "dir") {
9418
+ return item;
9419
+ }
9420
+ if (item.thumbnails) {
9421
+ for (const [size, src] of Object.entries(item.thumbnails)) {
9422
+ item.thumbnails[size] = encodeUrlIfNeeded(src);
9423
+ }
9424
+ }
9425
+ return {
9426
+ ...item,
9427
+ src: encodeUrlIfNeeded(item.src)
9428
+ };
9429
+ });
9566
9430
  this.events.dispatch({ type: "media:list:success", ...options, media });
9567
9431
  return media;
9568
9432
  } catch (error) {
@@ -9850,7 +9714,7 @@ class SidebarState {
9850
9714
  }
9851
9715
  }
9852
9716
  function createScreen({
9853
- Component: Component2,
9717
+ Component,
9854
9718
  props,
9855
9719
  ...options
9856
9720
  }) {
@@ -9859,7 +9723,7 @@ function createScreen({
9859
9723
  layout: "popup",
9860
9724
  ...options,
9861
9725
  Component(screenProps) {
9862
- return /* @__PURE__ */ React__default.createElement(Component2, { ...screenProps, ...props });
9726
+ return /* @__PURE__ */ React__default.createElement(Component, { ...screenProps, ...props });
9863
9727
  }
9864
9728
  };
9865
9729
  }
@@ -10370,7 +10234,7 @@ const SyncStatus = ({ cms, setEventsOpen }) => {
10370
10234
  "Event Log"
10371
10235
  ));
10372
10236
  };
10373
- const version = "2.5.0";
10237
+ const version = "2.6.2";
10374
10238
  const Nav = ({
10375
10239
  isLocalMode,
10376
10240
  className = "",
@@ -13299,9 +13163,9 @@ const EllipsisIcon = ({ title }) => {
13299
13163
  ));
13300
13164
  };
13301
13165
  const Wrapper$1 = ({ inline, children }) => {
13302
- const Component2 = inline ? "span" : "div";
13166
+ const Component = inline ? "span" : "div";
13303
13167
  return /* @__PURE__ */ React__default.createElement(
13304
- Component2,
13168
+ Component,
13305
13169
  {
13306
13170
  contentEditable: false,
13307
13171
  style: { userSelect: "none" },
@@ -14089,13 +13953,13 @@ const TooltipContent = withCn(
14089
13953
  }),
14090
13954
  "z-[9999] overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-sm text-popover-foreground shadow-md"
14091
13955
  );
14092
- function withTooltip(Component2) {
13956
+ function withTooltip(Component) {
14093
13957
  return React__default.forwardRef(function ExtendComponent({ tooltip, tooltipContentProps, tooltipProps, ...props }, ref) {
14094
13958
  const [mounted, setMounted] = React__default.useState(false);
14095
13959
  React__default.useEffect(() => {
14096
13960
  setMounted(true);
14097
13961
  }, []);
14098
- const component = /* @__PURE__ */ React__default.createElement(Component2, { ref, ...props });
13962
+ const component = /* @__PURE__ */ React__default.createElement(Component, { ref, ...props });
14099
13963
  if (tooltip && mounted) {
14100
13964
  return /* @__PURE__ */ React__default.createElement(Tooltip, { ...tooltipProps }, /* @__PURE__ */ React__default.createElement(TooltipTrigger, { asChild: true }, component), /* @__PURE__ */ React__default.createElement(TooltipPortal, null, /* @__PURE__ */ React__default.createElement(TooltipContent, { ...tooltipContentProps }, tooltip)));
14101
13965
  }
@@ -14690,7 +14554,7 @@ const EmbedButton = ({ editor, templates }) => {
14690
14554
  key: template.name,
14691
14555
  onMouseDown: (e) => {
14692
14556
  e.preventDefault();
14693
- close();
14557
+ setOpen(false);
14694
14558
  insertMDX(editor, template);
14695
14559
  },
14696
14560
  className: ""
@@ -14776,7 +14640,12 @@ function FixedToolbarButtons() {
14776
14640
  const [itemsShown, setItemsShown] = React__default.useState(11);
14777
14641
  const { overrides, templates } = useToolbarContext();
14778
14642
  const showEmbedButton = templates.length > 0;
14779
- let items2 = overrides === void 0 ? Object.values(toolbarItems) : overrides.map((item) => toolbarItems[item]).filter((item) => item !== void 0);
14643
+ let items2 = [];
14644
+ if (Array.isArray(overrides)) {
14645
+ items2 = overrides === void 0 ? Object.values(toolbarItems) : overrides.map((item) => toolbarItems[item]).filter((item) => item !== void 0);
14646
+ } else {
14647
+ items2 = (overrides == null ? void 0 : overrides.toolbar) === void 0 ? Object.values(toolbarItems) : overrides.toolbar.map((item) => toolbarItems[item]).filter((item) => item !== void 0);
14648
+ }
14780
14649
  if (!showEmbedButton) {
14781
14650
  items2 = items2.filter((item) => item.label !== toolbarItems.embed.label);
14782
14651
  }
@@ -15104,6 +14973,9 @@ const isUrl = (string) => {
15104
14973
  if (typeof string !== "string") {
15105
14974
  return false;
15106
14975
  }
14976
+ if (string.startsWith("#")) {
14977
+ return true;
14978
+ }
15107
14979
  const generalMatch = string.match(protocolAndDomainRE);
15108
14980
  const emailLinkMatch = string.match(emailLintRE);
15109
14981
  const localUrlMatch = string.match(localUrlRE);
@@ -15125,12 +14997,12 @@ const isUrl = (string) => {
15125
14997
  }
15126
14998
  return localhostDomainRE.test(everythingAfterProtocol) || nonLocalhostDomainRE.test(everythingAfterProtocol);
15127
14999
  };
15128
- const RichEditor = (props) => {
15000
+ const RichEditor = ({ input, tinaForm, field }) => {
15129
15001
  var _a;
15130
15002
  const initialValue = React__default.useMemo(
15131
15003
  () => {
15132
15004
  var _a2, _b;
15133
- return ((_b = (_a2 = props.input.value) == null ? void 0 : _a2.children) == null ? void 0 : _b.length) ? props.input.value.children.map(helpers.normalize) : [{ type: "p", children: [{ type: "text", text: "" }] }];
15005
+ return ((_b = (_a2 = input.value) == null ? void 0 : _a2.children) == null ? void 0 : _b.length) ? input.value.children.map(helpers.normalize) : [{ type: "p", children: [{ type: "text", text: "" }] }];
15134
15006
  },
15135
15007
  []
15136
15008
  );
@@ -15158,7 +15030,7 @@ const RichEditor = (props) => {
15158
15030
  ),
15159
15031
  []
15160
15032
  );
15161
- const tempId = [props.tinaForm.id, props.input.name].join(".");
15033
+ const tempId = [tinaForm.id, input.name].join(".");
15162
15034
  const id = React__default.useMemo(() => uuid() + tempId, [tempId]);
15163
15035
  const ref = React__default.useRef(null);
15164
15036
  React__default.useEffect(() => {
@@ -15168,13 +15040,13 @@ const RichEditor = (props) => {
15168
15040
  const plateElement = (_a2 = ref.current) == null ? void 0 : _a2.querySelector(
15169
15041
  '[role="textbox"]'
15170
15042
  );
15171
- if (props.field.experimental_focusIntent && plateElement) {
15043
+ if (field.experimental_focusIntent && plateElement) {
15172
15044
  if (plateElement)
15173
15045
  plateElement.focus();
15174
15046
  }
15175
15047
  }, 100);
15176
15048
  }
15177
- }, [props.field.experimental_focusIntent, ref]);
15049
+ }, [field.experimental_focusIntent, ref]);
15178
15050
  return /* @__PURE__ */ React__default.createElement("div", { ref }, /* @__PURE__ */ React__default.createElement(
15179
15051
  Plate,
15180
15052
  {
@@ -15182,7 +15054,7 @@ const RichEditor = (props) => {
15182
15054
  initialValue,
15183
15055
  plugins: plugins$2,
15184
15056
  onChange: (value) => {
15185
- props.input.onChange({
15057
+ input.onChange({
15186
15058
  type: "root",
15187
15059
  children: value
15188
15060
  });
@@ -15191,12 +15063,12 @@ const RichEditor = (props) => {
15191
15063
  /* @__PURE__ */ React__default.createElement(TooltipProvider, null, /* @__PURE__ */ React__default.createElement(
15192
15064
  ToolbarProvider,
15193
15065
  {
15194
- tinaForm: props.tinaForm,
15195
- templates: props.field.templates,
15196
- overrides: (_a = props.field) == null ? void 0 : _a.toolbarOverride
15066
+ tinaForm,
15067
+ templates: field.templates,
15068
+ overrides: (field == null ? void 0 : field.toolbarOverride) ? field.toolbarOverride : field.overrides
15197
15069
  },
15198
15070
  /* @__PURE__ */ React__default.createElement(FixedToolbar, null, /* @__PURE__ */ React__default.createElement(FixedToolbarButtons, null)),
15199
- /* @__PURE__ */ React__default.createElement(FloatingToolbar, null, /* @__PURE__ */ React__default.createElement(FloatingToolbarButtons, null))
15071
+ ((_a = field == null ? void 0 : field.overrides) == null ? void 0 : _a.showFloatingToolbar) !== false ? /* @__PURE__ */ React__default.createElement(FloatingToolbar, null, /* @__PURE__ */ React__default.createElement(FloatingToolbarButtons, null)) : null
15200
15072
  ), /* @__PURE__ */ React__default.createElement(Editor, null))
15201
15073
  ));
15202
15074
  };
@@ -25,22 +25,35 @@ const NodeCache = async (dir) => {
25
25
  return createHash("sha256").update(input).digest("hex");
26
26
  },
27
27
  get: async (key) => {
28
+ let readValue;
29
+ const cacheFilename = `${cacheDir}/${key}`;
28
30
  try {
29
- const data = await fs.promises.readFile(`${cacheDir}/${key}`, "utf-8");
30
- return JSON.parse(data);
31
+ const data = await fs.promises.readFile(cacheFilename, "utf-8");
32
+ readValue = JSON.parse(data);
31
33
  } catch (e) {
32
- if (e.code === "ENOENT") {
33
- return void 0;
34
+ if (e.code !== "ENOENT") {
35
+ console.error(
36
+ `Failed to read cache file to ${cacheFilename}: ${e.message}`
37
+ );
34
38
  }
35
- throw e;
36
39
  }
40
+ return readValue;
37
41
  },
38
42
  set: async (key, value) => {
39
- await fs.promises.writeFile(
40
- `${cacheDir}/${key}`,
41
- JSON.stringify(value),
42
- "utf-8"
43
- );
43
+ const cacheFilename = `${cacheDir}/${key}`;
44
+ try {
45
+ await fs.promises.writeFile(cacheFilename, JSON.stringify(value), {
46
+ encoding: "utf-8",
47
+ flag: "wx"
48
+ // Don't overwrite existing caches
49
+ });
50
+ } catch (e) {
51
+ if (e.code !== "EEXIST") {
52
+ console.error(
53
+ `Failed to write cache file to ${cacheFilename}: ${e.message}`
54
+ );
55
+ }
56
+ }
44
57
  }
45
58
  };
46
59
  };