@crashbytes/contentful-richtext-editor 1.0.8 → 1.0.11

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.esm.js CHANGED
@@ -1,7 +1,78 @@
1
1
  import { jsxs, jsx, Fragment as Fragment$1 } from 'react/jsx-runtime';
2
- import React, { forwardRef, useRef, useState, useDebugValue, useEffect, createContext, useContext, useLayoutEffect, useCallback } from 'react';
2
+ import React, { forwardRef, useRef, useState, useDebugValue, useEffect, createContext, useContext, useLayoutEffect, useMemo, useCallback } from 'react';
3
3
  import ReactDOM from 'react-dom';
4
4
 
5
+ /******************************************************************************
6
+ Copyright (c) Microsoft Corporation.
7
+
8
+ Permission to use, copy, modify, and/or distribute this software for any
9
+ purpose with or without fee is hereby granted.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
16
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17
+ PERFORMANCE OF THIS SOFTWARE.
18
+ ***************************************************************************** */
19
+ /* global Reflect, Promise, SuppressedError, Symbol, Iterator */
20
+
21
+
22
+ var __assign = function() {
23
+ __assign = Object.assign || function __assign(t) {
24
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
25
+ s = arguments[i];
26
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
27
+ }
28
+ return t;
29
+ };
30
+ return __assign.apply(this, arguments);
31
+ };
32
+
33
+ function __awaiter(thisArg, _arguments, P, generator) {
34
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
35
+ return new (P || (P = Promise))(function (resolve, reject) {
36
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
37
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
38
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
39
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
40
+ });
41
+ }
42
+
43
+ function __generator(thisArg, body) {
44
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
45
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
46
+ function verb(n) { return function (v) { return step([n, v]); }; }
47
+ function step(op) {
48
+ if (f) throw new TypeError("Generator is already executing.");
49
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
50
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
51
+ if (y = 0, t) op = [op[0] & 2, t.value];
52
+ switch (op[0]) {
53
+ case 0: case 1: t = op; break;
54
+ case 4: _.label++; return { value: op[1], done: false };
55
+ case 5: _.label++; y = op[1]; op = [0]; continue;
56
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
57
+ default:
58
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
59
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
60
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
61
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
62
+ if (t[2]) _.ops.pop();
63
+ _.trys.pop(); continue;
64
+ }
65
+ op = body.call(thisArg, _);
66
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
67
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
68
+ }
69
+ }
70
+
71
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
72
+ var e = new Error(message);
73
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
74
+ };
75
+
5
76
  // ::- Persistent data structure representing an ordered mapping from
6
77
  // strings to values, with some convenient update methods.
7
78
  function OrderedMap(content) {
@@ -26529,12 +26600,13 @@ const Underline = Mark.create({
26529
26600
  },
26530
26601
  });
26531
26602
 
26532
- const ContentfulToolbar = ({ editor, onEmbedEntry, onEmbedAsset, disabledFeatures = [], availableHeadings = [1, 2, 3, 4, 5, 6], availableMarks = ['bold', 'italic', 'underline'] }) => {
26533
- const [showLinkInput, setShowLinkInput] = useState(false);
26534
- const [linkUrl, setLinkUrl] = useState('');
26535
- const isDisabled = (feature) => disabledFeatures.includes(feature);
26536
- const isMarkAvailable = (mark) => availableMarks.includes(mark);
26537
- const handleHeadingChange = (level) => {
26603
+ var ContentfulToolbar = function (_a) {
26604
+ var editor = _a.editor, onEmbedEntry = _a.onEmbedEntry, onEmbedAsset = _a.onEmbedAsset, onEmbedInlineEntry = _a.onEmbedInlineEntry, _b = _a.disabledFeatures, disabledFeatures = _b === void 0 ? [] : _b, _c = _a.availableHeadings, availableHeadings = _c === void 0 ? [1, 2, 3, 4, 5, 6] : _c, _d = _a.availableMarks, availableMarks = _d === void 0 ? ['bold', 'italic', 'underline'] : _d, _e = _a.allowHyperlinks, allowHyperlinks = _e === void 0 ? true : _e;
26605
+ var _f = useState(false), showLinkInput = _f[0], setShowLinkInput = _f[1];
26606
+ var _g = useState(''), linkUrl = _g[0], setLinkUrl = _g[1];
26607
+ var isDisabled = function (feature) { return disabledFeatures.includes(feature); };
26608
+ var isMarkAvailable = function (mark) { return availableMarks.includes(mark); };
26609
+ var handleHeadingChange = function (level) {
26538
26610
  if (level === 0) {
26539
26611
  editor.chain().focus().setParagraph().run();
26540
26612
  }
@@ -26542,7 +26614,7 @@ const ContentfulToolbar = ({ editor, onEmbedEntry, onEmbedAsset, disabledFeature
26542
26614
  editor.chain().focus().toggleHeading({ level: level }).run();
26543
26615
  }
26544
26616
  };
26545
- const handleLinkToggle = () => {
26617
+ var handleLinkToggle = function () {
26546
26618
  if (editor.isActive('link')) {
26547
26619
  editor.chain().focus().unsetLink().run();
26548
26620
  }
@@ -26551,42 +26623,51 @@ const ContentfulToolbar = ({ editor, onEmbedEntry, onEmbedAsset, disabledFeature
26551
26623
  setLinkUrl(editor.getAttributes('link').href || '');
26552
26624
  }
26553
26625
  };
26554
- const handleLinkSubmit = () => {
26626
+ var handleLinkSubmit = function () {
26555
26627
  if (linkUrl) {
26556
26628
  editor.chain().focus().setLink({ href: linkUrl }).run();
26557
26629
  }
26558
26630
  setShowLinkInput(false);
26559
26631
  setLinkUrl('');
26560
26632
  };
26561
- const insertTable = () => {
26633
+ var handleLinkCancel = function () {
26634
+ setShowLinkInput(false);
26635
+ setLinkUrl('');
26636
+ };
26637
+ var insertTable = function () {
26562
26638
  editor.chain().focus().insertTable({ rows: 3, cols: 3, withHeaderRow: true }).run();
26563
26639
  };
26564
- const getActiveHeading = () => {
26565
- for (const level of availableHeadings) {
26566
- if (editor.isActive('heading', { level })) {
26567
- return `Heading ${level}`;
26640
+ var getActiveHeading = function () {
26641
+ for (var _i = 0, availableHeadings_1 = availableHeadings; _i < availableHeadings_1.length; _i++) {
26642
+ var level = availableHeadings_1[_i];
26643
+ if (editor.isActive('heading', { level: level })) {
26644
+ return "Heading ".concat(level);
26568
26645
  }
26569
26646
  }
26570
26647
  return 'Normal text';
26571
26648
  };
26572
- const hasHeadings = !isDisabled('headings') && availableHeadings.length > 0;
26573
- return (jsxs("div", { className: "contentful-toolbar", children: [jsxs("div", { className: "contentful-toolbar__group", children: [hasHeadings && (jsxs("select", { className: "contentful-toolbar__select", value: getActiveHeading(), onChange: (e) => {
26574
- const value = e.target.value;
26649
+ var hasHeadings = !isDisabled('headings') && availableHeadings.length > 0;
26650
+ var hasAnyEmbedOptions = onEmbedEntry || onEmbedAsset || onEmbedInlineEntry;
26651
+ var hasAnyTextFormatting = availableMarks.some(function (mark) { return !isDisabled(mark) && isMarkAvailable(mark); });
26652
+ return (jsxs("div", { className: "contentful-toolbar", children: [jsxs("div", { className: "contentful-toolbar__group", children: [hasHeadings && (jsxs("select", { className: "contentful-toolbar__select", value: getActiveHeading(), onChange: function (e) {
26653
+ var value = e.target.value;
26575
26654
  if (value === 'Normal text') {
26576
26655
  handleHeadingChange(0);
26577
26656
  }
26578
26657
  else {
26579
- const level = parseInt(value.replace('Heading ', ''));
26658
+ var level = parseInt(value.replace('Heading ', ''));
26580
26659
  handleHeadingChange(level);
26581
26660
  }
26582
- }, children: [jsx("option", { value: "Normal text", children: "Normal text" }), availableHeadings.map(level => (jsxs("option", { value: `Heading ${level}`, children: ["Heading ", level] }, level)))] })), jsx("button", { className: "contentful-toolbar__button", onClick: () => editor.chain().focus().undo().run(), disabled: !editor.can().undo(), title: "Undo", children: "\u21B6" }), jsx("button", { className: "contentful-toolbar__button", onClick: () => editor.chain().focus().redo().run(), disabled: !editor.can().redo(), title: "Redo", children: "\u21B7" })] }), jsx("div", { className: "contentful-toolbar__separator" }), jsxs("div", { className: "contentful-toolbar__group", children: [!isDisabled('bold') && isMarkAvailable('bold') && (jsx("button", { className: `contentful-toolbar__button ${editor.isActive('bold') ? 'contentful-toolbar__button--active' : ''}`, onClick: () => editor.chain().focus().toggleBold().run(), title: "Bold", children: jsx("strong", { children: "B" }) })), !isDisabled('italic') && isMarkAvailable('italic') && (jsx("button", { className: `contentful-toolbar__button ${editor.isActive('italic') ? 'contentful-toolbar__button--active' : ''}`, onClick: () => editor.chain().focus().toggleItalic().run(), title: "Italic", children: jsx("em", { children: "I" }) })), !isDisabled('underline') && isMarkAvailable('underline') && (jsx("button", { className: `contentful-toolbar__button ${editor.isActive('underline') ? 'contentful-toolbar__button--active' : ''}`, onClick: () => editor.chain().focus().toggleUnderline().run(), title: "Underline", children: jsx("u", { children: "U" }) })), jsx("button", { className: "contentful-toolbar__button", title: "More formatting options", children: "\u22EF" }), !isDisabled('link') && (jsxs(Fragment$1, { children: [jsx("button", { className: `contentful-toolbar__button ${editor.isActive('link') ? 'contentful-toolbar__button--active' : ''}`, onClick: handleLinkToggle, title: "Link", children: "\uD83D\uDD17" }), showLinkInput && (jsxs("div", { className: "contentful-toolbar__link-input", children: [jsx("input", { type: "url", value: linkUrl, onChange: (e) => setLinkUrl(e.target.value), placeholder: "Enter URL", onKeyDown: (e) => {
26583
- if (e.key === 'Enter') {
26584
- handleLinkSubmit();
26585
- }
26586
- if (e.key === 'Escape') {
26587
- setShowLinkInput(false);
26588
- }
26589
- }, autoFocus: true }), jsx("button", { onClick: handleLinkSubmit, children: "\u2713" }), jsx("button", { onClick: () => setShowLinkInput(false), children: "\u2717" })] }))] }))] }), jsx("div", { className: "contentful-toolbar__separator" }), jsxs("div", { className: "contentful-toolbar__group", children: [!isDisabled('lists') && (jsxs(Fragment$1, { children: [jsx("button", { className: `contentful-toolbar__button ${editor.isActive('bulletList') ? 'contentful-toolbar__button--active' : ''}`, onClick: () => editor.chain().focus().toggleBulletList().run(), title: "Bullet List", children: "\u2022 \u2261" }), jsx("button", { className: `contentful-toolbar__button ${editor.isActive('orderedList') ? 'contentful-toolbar__button--active' : ''}`, onClick: () => editor.chain().focus().toggleOrderedList().run(), title: "Numbered List", children: "1. \u2261" })] })), !isDisabled('quote') && (jsx("button", { className: `contentful-toolbar__button ${editor.isActive('blockquote') ? 'contentful-toolbar__button--active' : ''}`, onClick: () => editor.chain().focus().toggleBlockquote().run(), title: "Quote", children: "\"" })), jsx("button", { className: "contentful-toolbar__button", onClick: () => editor.chain().focus().setHorizontalRule().run(), title: "Horizontal Rule", children: "\u2014" }), !isDisabled('table') && (jsx("button", { className: "contentful-toolbar__button", onClick: insertTable, title: "Insert Table", children: "\u229E" }))] }), jsx("div", { className: "contentful-toolbar__separator" }), jsx("div", { className: "contentful-toolbar__group contentful-toolbar__group--right", children: !isDisabled('embed') && (jsxs("div", { className: "contentful-toolbar__embed-dropdown", children: [jsx("button", { className: "contentful-toolbar__embed-button", children: "+ Embed \u25BC" }), jsxs("div", { className: "contentful-toolbar__embed-menu", children: [onEmbedEntry && (jsx("button", { className: "contentful-toolbar__embed-option", onClick: onEmbedEntry, children: "Entry" })), onEmbedAsset && (jsx("button", { className: "contentful-toolbar__embed-option", onClick: onEmbedAsset, children: "Media" }))] })] })) })] }));
26661
+ }, children: [jsx("option", { value: "Normal text", children: "Normal text" }), availableHeadings.map(function (level) { return (jsxs("option", { value: "Heading ".concat(level), children: ["Heading ", level] }, level)); })] })), jsx("button", { className: "contentful-toolbar__button", onClick: function () { return editor.chain().focus().undo().run(); }, disabled: !editor.can().undo(), title: "Undo", children: "\u21B6" }), jsx("button", { className: "contentful-toolbar__button", onClick: function () { return editor.chain().focus().redo().run(); }, disabled: !editor.can().redo(), title: "Redo", children: "\u21B7" })] }), (hasAnyTextFormatting || allowHyperlinks) && (jsxs(Fragment$1, { children: [jsx("div", { className: "contentful-toolbar__separator" }), jsxs("div", { className: "contentful-toolbar__group", children: [!isDisabled('bold') && isMarkAvailable('bold') && (jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('bold') ? 'contentful-toolbar__button--active' : ''), onClick: function () { return editor.chain().focus().toggleBold().run(); }, title: "Bold", children: jsx("strong", { children: "B" }) })), !isDisabled('italic') && isMarkAvailable('italic') && (jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('italic') ? 'contentful-toolbar__button--active' : ''), onClick: function () { return editor.chain().focus().toggleItalic().run(); }, title: "Italic", children: jsx("em", { children: "I" }) })), !isDisabled('underline') && isMarkAvailable('underline') && (jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('underline') ? 'contentful-toolbar__button--active' : ''), onClick: function () { return editor.chain().focus().toggleUnderline().run(); }, title: "Underline", children: jsx("u", { children: "U" }) })), jsx("button", { className: "contentful-toolbar__button", title: "More formatting options", children: "\u22EF" }), !isDisabled('link') && allowHyperlinks && (jsxs(Fragment$1, { children: [jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('link') ? 'contentful-toolbar__button--active' : ''), onClick: handleLinkToggle, title: "Link", children: "\uD83D\uDD17" }), showLinkInput && (jsxs("div", { className: "contentful-toolbar__link-input", children: [jsx("input", { type: "url", value: linkUrl, onChange: function (e) { return setLinkUrl(e.target.value); }, placeholder: "Enter URL", onKeyDown: function (e) {
26662
+ if (e.key === 'Enter') {
26663
+ e.preventDefault();
26664
+ handleLinkSubmit();
26665
+ }
26666
+ if (e.key === 'Escape') {
26667
+ e.preventDefault();
26668
+ handleLinkCancel();
26669
+ }
26670
+ }, autoFocus: true }), jsx("button", { onClick: handleLinkSubmit, title: "Apply link", children: "\u2713" }), jsx("button", { onClick: handleLinkCancel, title: "Cancel", children: "\u2717" })] }))] }))] })] })), (!isDisabled('lists') || !isDisabled('quote') || !isDisabled('table')) && (jsxs(Fragment$1, { children: [jsx("div", { className: "contentful-toolbar__separator" }), jsxs("div", { className: "contentful-toolbar__group", children: [!isDisabled('lists') && (jsxs(Fragment$1, { children: [jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('bulletList') ? 'contentful-toolbar__button--active' : ''), onClick: function () { return editor.chain().focus().toggleBulletList().run(); }, title: "Bullet List", children: "\u2022 \u2261" }), jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('orderedList') ? 'contentful-toolbar__button--active' : ''), onClick: function () { return editor.chain().focus().toggleOrderedList().run(); }, title: "Numbered List", children: "1. \u2261" })] })), !isDisabled('quote') && (jsx("button", { className: "contentful-toolbar__button ".concat(editor.isActive('blockquote') ? 'contentful-toolbar__button--active' : ''), onClick: function () { return editor.chain().focus().toggleBlockquote().run(); }, title: "Quote", children: "\"" })), jsx("button", { className: "contentful-toolbar__button", onClick: function () { return editor.chain().focus().setHorizontalRule().run(); }, title: "Horizontal Rule", children: "\u2014" }), !isDisabled('table') && (jsx("button", { className: "contentful-toolbar__button", onClick: insertTable, title: "Insert Table", children: "\u229E" }))] })] })), hasAnyEmbedOptions && !isDisabled('embed') && (jsxs(Fragment$1, { children: [jsx("div", { className: "contentful-toolbar__separator" }), jsx("div", { className: "contentful-toolbar__group contentful-toolbar__group--right", children: jsxs("div", { className: "contentful-toolbar__embed-dropdown", children: [jsx("button", { className: "contentful-toolbar__embed-button", children: "+ Embed \u25BC" }), jsxs("div", { className: "contentful-toolbar__embed-menu", children: [onEmbedEntry && (jsx("button", { className: "contentful-toolbar__embed-option", onClick: onEmbedEntry, children: "\uD83D\uDCC4 Entry" })), onEmbedInlineEntry && (jsx("button", { className: "contentful-toolbar__embed-option", onClick: onEmbedInlineEntry, children: "\uD83D\uDCDD Inline Entry" })), onEmbedAsset && (jsx("button", { className: "contentful-toolbar__embed-option", onClick: onEmbedAsset, children: "\uD83D\uDDBC\uFE0F Media" }))] })] }) })] }))] }));
26590
26671
  };
26591
26672
 
26592
26673
  var dist = {};
@@ -27019,75 +27100,75 @@ var distExports = requireDist();
27019
27100
  /**
27020
27101
  * Converts a Contentful Rich Text Document to Tiptap JSON format
27021
27102
  */
27022
- const contentfulToTiptap = (document) => {
27023
- const convertNode = (node) => {
27024
- var _a, _b, _c, _d, _e;
27103
+ var contentfulToTiptap = function (document) {
27104
+ var convertNode = function (node) {
27105
+ var _a, _b, _c, _d, _e, _f, _g;
27025
27106
  switch (node.nodeType) {
27026
27107
  case distExports.BLOCKS.DOCUMENT:
27027
27108
  return {
27028
27109
  type: 'doc',
27029
- content: node.content.map(child => convertNode(child)).flat(),
27110
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27030
27111
  };
27031
27112
  case distExports.BLOCKS.PARAGRAPH:
27032
27113
  return {
27033
27114
  type: 'paragraph',
27034
- content: node.content ? node.content.map(child => convertNode(child)).flat() : [],
27115
+ content: node.content ? node.content.map(function (child) { return convertNode(child); }).flat() : [],
27035
27116
  };
27036
27117
  case distExports.BLOCKS.HEADING_1:
27037
27118
  return {
27038
27119
  type: 'heading',
27039
27120
  attrs: { level: 1 },
27040
- content: node.content.map(child => convertNode(child)).flat(),
27121
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27041
27122
  };
27042
27123
  case distExports.BLOCKS.HEADING_2:
27043
27124
  return {
27044
27125
  type: 'heading',
27045
27126
  attrs: { level: 2 },
27046
- content: node.content.map(child => convertNode(child)).flat(),
27127
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27047
27128
  };
27048
27129
  case distExports.BLOCKS.HEADING_3:
27049
27130
  return {
27050
27131
  type: 'heading',
27051
27132
  attrs: { level: 3 },
27052
- content: node.content.map(child => convertNode(child)).flat(),
27133
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27053
27134
  };
27054
27135
  case distExports.BLOCKS.HEADING_4:
27055
27136
  return {
27056
27137
  type: 'heading',
27057
27138
  attrs: { level: 4 },
27058
- content: node.content.map(child => convertNode(child)).flat(),
27139
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27059
27140
  };
27060
27141
  case distExports.BLOCKS.HEADING_5:
27061
27142
  return {
27062
27143
  type: 'heading',
27063
27144
  attrs: { level: 5 },
27064
- content: node.content.map(child => convertNode(child)).flat(),
27145
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27065
27146
  };
27066
27147
  case distExports.BLOCKS.HEADING_6:
27067
27148
  return {
27068
27149
  type: 'heading',
27069
27150
  attrs: { level: 6 },
27070
- content: node.content.map(child => convertNode(child)).flat(),
27151
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27071
27152
  };
27072
27153
  case distExports.BLOCKS.UL_LIST:
27073
27154
  return {
27074
27155
  type: 'bulletList',
27075
- content: node.content.map(child => convertNode(child)).flat(),
27156
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27076
27157
  };
27077
27158
  case distExports.BLOCKS.OL_LIST:
27078
27159
  return {
27079
27160
  type: 'orderedList',
27080
- content: node.content.map(child => convertNode(child)).flat(),
27161
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27081
27162
  };
27082
27163
  case distExports.BLOCKS.LIST_ITEM:
27083
27164
  return {
27084
27165
  type: 'listItem',
27085
- content: node.content.map(child => convertNode(child)).flat(),
27166
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27086
27167
  };
27087
27168
  case distExports.BLOCKS.QUOTE:
27088
27169
  return {
27089
27170
  type: 'blockquote',
27090
- content: node.content.map(child => convertNode(child)).flat(),
27171
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27091
27172
  };
27092
27173
  case distExports.BLOCKS.HR:
27093
27174
  return {
@@ -27096,27 +27177,29 @@ const contentfulToTiptap = (document) => {
27096
27177
  case distExports.BLOCKS.TABLE:
27097
27178
  return {
27098
27179
  type: 'table',
27099
- content: node.content.map(child => convertNode(child)).flat(),
27180
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27100
27181
  };
27101
27182
  case distExports.BLOCKS.TABLE_ROW:
27102
27183
  return {
27103
27184
  type: 'tableRow',
27104
- content: node.content.map(child => convertNode(child)).flat(),
27185
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27105
27186
  };
27106
27187
  case distExports.BLOCKS.TABLE_CELL:
27107
27188
  return {
27108
27189
  type: 'tableCell',
27109
- content: node.content.map(child => convertNode(child)).flat(),
27190
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27110
27191
  };
27111
27192
  case distExports.BLOCKS.TABLE_HEADER_CELL:
27112
27193
  return {
27113
27194
  type: 'tableHeader',
27114
- content: node.content.map(child => convertNode(child)).flat(),
27195
+ content: node.content.map(function (child) { return convertNode(child); }).flat(),
27115
27196
  };
27116
27197
  case distExports.INLINES.HYPERLINK:
27117
27198
  return {
27118
27199
  type: 'text',
27119
- text: node.content.map(child => child.nodeType === 'text' ? child.value : '').join(''),
27200
+ text: node.content.map(function (child) {
27201
+ return child.nodeType === 'text' ? child.value : '';
27202
+ }).join(''),
27120
27203
  marks: [
27121
27204
  {
27122
27205
  type: 'link',
@@ -27124,13 +27207,20 @@ const contentfulToTiptap = (document) => {
27124
27207
  },
27125
27208
  ],
27126
27209
  };
27210
+ case distExports.INLINES.EMBEDDED_ENTRY:
27211
+ // Inline embedded entry
27212
+ return {
27213
+ type: 'text',
27214
+ text: "[Inline Entry: ".concat(((_b = (_a = node.data.target) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.id) || 'Unknown', "]"),
27215
+ marks: [{ type: 'bold' }],
27216
+ };
27127
27217
  case distExports.BLOCKS.EMBEDDED_ENTRY:
27128
27218
  return {
27129
27219
  type: 'paragraph',
27130
27220
  content: [
27131
27221
  {
27132
27222
  type: 'text',
27133
- text: `[Embedded Entry: ${((_b = (_a = node.data.target) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.id) || 'Unknown'}]`,
27223
+ text: "[Embedded Entry: ".concat(((_d = (_c = node.data.target) === null || _c === void 0 ? void 0 : _c.sys) === null || _d === void 0 ? void 0 : _d.id) || 'Unknown', "]"),
27134
27224
  marks: [{ type: 'bold' }],
27135
27225
  },
27136
27226
  ],
@@ -27141,14 +27231,14 @@ const contentfulToTiptap = (document) => {
27141
27231
  content: [
27142
27232
  {
27143
27233
  type: 'text',
27144
- text: `[Embedded Asset: ${((_d = (_c = node.data.target) === null || _c === void 0 ? void 0 : _c.sys) === null || _d === void 0 ? void 0 : _d.id) || 'Unknown'}]`,
27234
+ text: "[Embedded Asset: ".concat(((_f = (_e = node.data.target) === null || _e === void 0 ? void 0 : _e.sys) === null || _f === void 0 ? void 0 : _f.id) || 'Unknown', "]"),
27145
27235
  marks: [{ type: 'bold' }],
27146
27236
  },
27147
27237
  ],
27148
27238
  };
27149
27239
  case 'text':
27150
- const textNode = node;
27151
- const marks = ((_e = textNode.marks) === null || _e === void 0 ? void 0 : _e.map(mark => {
27240
+ var textNode = node;
27241
+ var marks = ((_g = textNode.marks) === null || _g === void 0 ? void 0 : _g.map(function (mark) {
27152
27242
  switch (mark.type) {
27153
27243
  case distExports.MARKS.BOLD:
27154
27244
  return { type: 'bold' };
@@ -27161,14 +27251,14 @@ const contentfulToTiptap = (document) => {
27161
27251
  default:
27162
27252
  return null;
27163
27253
  }
27164
- }).filter((mark) => mark !== null)) || [];
27254
+ }).filter(function (mark) { return mark !== null; })) || [];
27165
27255
  return {
27166
27256
  type: 'text',
27167
27257
  text: textNode.value,
27168
27258
  marks: marks.length > 0 ? marks : undefined,
27169
27259
  };
27170
27260
  default:
27171
- console.warn(`Unknown Contentful node type: ${node.nodeType}`);
27261
+ console.warn("Unknown Contentful node type: ".concat(node.nodeType));
27172
27262
  return {
27173
27263
  type: 'paragraph',
27174
27264
  content: [],
@@ -27180,25 +27270,25 @@ const contentfulToTiptap = (document) => {
27180
27270
  /**
27181
27271
  * Converts Tiptap JSON format to Contentful Rich Text Document
27182
27272
  */
27183
- const tiptapToContentful = (tiptapDoc) => {
27184
- const convertNode = (node) => {
27185
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
27273
+ var tiptapToContentful = function (tiptapDoc) {
27274
+ var convertNode = function (node) {
27275
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r;
27186
27276
  switch (node.type) {
27187
27277
  case 'doc':
27188
27278
  return {
27189
27279
  nodeType: distExports.BLOCKS.DOCUMENT,
27190
27280
  data: {},
27191
- content: (_a = node.content) === null || _a === void 0 ? void 0 : _a.map((child) => convertNode(child)),
27281
+ content: (_a = node.content) === null || _a === void 0 ? void 0 : _a.map(function (child) { return convertNode(child); }),
27192
27282
  };
27193
27283
  case 'paragraph':
27194
27284
  return {
27195
27285
  nodeType: distExports.BLOCKS.PARAGRAPH,
27196
27286
  data: {},
27197
- content: (_b = node.content) === null || _b === void 0 ? void 0 : _b.map((child) => convertNode(child)),
27287
+ content: (_b = node.content) === null || _b === void 0 ? void 0 : _b.map(function (child) { return convertNode(child); }),
27198
27288
  };
27199
27289
  case 'heading':
27200
- const level = ((_c = node.attrs) === null || _c === void 0 ? void 0 : _c.level) || 1;
27201
- const headingTypes = {
27290
+ var level = ((_c = node.attrs) === null || _c === void 0 ? void 0 : _c.level) || 1;
27291
+ var headingTypes = {
27202
27292
  1: distExports.BLOCKS.HEADING_1,
27203
27293
  2: distExports.BLOCKS.HEADING_2,
27204
27294
  3: distExports.BLOCKS.HEADING_3,
@@ -27206,35 +27296,35 @@ const tiptapToContentful = (tiptapDoc) => {
27206
27296
  5: distExports.BLOCKS.HEADING_5,
27207
27297
  6: distExports.BLOCKS.HEADING_6,
27208
27298
  };
27209
- const headingType = headingTypes[level] || distExports.BLOCKS.HEADING_1;
27299
+ var headingType = headingTypes[level] || distExports.BLOCKS.HEADING_1;
27210
27300
  return {
27211
27301
  nodeType: headingType,
27212
27302
  data: {},
27213
- content: (_d = node.content) === null || _d === void 0 ? void 0 : _d.map((child) => convertNode(child)),
27303
+ content: (_d = node.content) === null || _d === void 0 ? void 0 : _d.map(function (child) { return convertNode(child); }),
27214
27304
  };
27215
27305
  case 'bulletList':
27216
27306
  return {
27217
27307
  nodeType: distExports.BLOCKS.UL_LIST,
27218
27308
  data: {},
27219
- content: (_e = node.content) === null || _e === void 0 ? void 0 : _e.map((child) => convertNode(child)),
27309
+ content: (_e = node.content) === null || _e === void 0 ? void 0 : _e.map(function (child) { return convertNode(child); }),
27220
27310
  };
27221
27311
  case 'orderedList':
27222
27312
  return {
27223
27313
  nodeType: distExports.BLOCKS.OL_LIST,
27224
27314
  data: {},
27225
- content: (_f = node.content) === null || _f === void 0 ? void 0 : _f.map((child) => convertNode(child)),
27315
+ content: (_f = node.content) === null || _f === void 0 ? void 0 : _f.map(function (child) { return convertNode(child); }),
27226
27316
  };
27227
27317
  case 'listItem':
27228
27318
  return {
27229
27319
  nodeType: distExports.BLOCKS.LIST_ITEM,
27230
27320
  data: {},
27231
- content: (_g = node.content) === null || _g === void 0 ? void 0 : _g.map((child) => convertNode(child)),
27321
+ content: (_g = node.content) === null || _g === void 0 ? void 0 : _g.map(function (child) { return convertNode(child); }),
27232
27322
  };
27233
27323
  case 'blockquote':
27234
27324
  return {
27235
27325
  nodeType: distExports.BLOCKS.QUOTE,
27236
27326
  data: {},
27237
- content: (_h = node.content) === null || _h === void 0 ? void 0 : _h.map((child) => convertNode(child)),
27327
+ content: (_h = node.content) === null || _h === void 0 ? void 0 : _h.map(function (child) { return convertNode(child); }),
27238
27328
  };
27239
27329
  case 'horizontalRule':
27240
27330
  return {
@@ -27246,28 +27336,28 @@ const tiptapToContentful = (tiptapDoc) => {
27246
27336
  return {
27247
27337
  nodeType: distExports.BLOCKS.TABLE,
27248
27338
  data: {},
27249
- content: (_j = node.content) === null || _j === void 0 ? void 0 : _j.map((child) => convertNode(child)),
27339
+ content: (_j = node.content) === null || _j === void 0 ? void 0 : _j.map(function (child) { return convertNode(child); }),
27250
27340
  };
27251
27341
  case 'tableRow':
27252
27342
  return {
27253
27343
  nodeType: distExports.BLOCKS.TABLE_ROW,
27254
27344
  data: {},
27255
- content: (_k = node.content) === null || _k === void 0 ? void 0 : _k.map((child) => convertNode(child)),
27345
+ content: (_k = node.content) === null || _k === void 0 ? void 0 : _k.map(function (child) { return convertNode(child); }),
27256
27346
  };
27257
27347
  case 'tableCell':
27258
27348
  return {
27259
27349
  nodeType: distExports.BLOCKS.TABLE_CELL,
27260
27350
  data: {},
27261
- content: (_l = node.content) === null || _l === void 0 ? void 0 : _l.map((child) => convertNode(child)),
27351
+ content: (_l = node.content) === null || _l === void 0 ? void 0 : _l.map(function (child) { return convertNode(child); }),
27262
27352
  };
27263
27353
  case 'tableHeader':
27264
27354
  return {
27265
27355
  nodeType: distExports.BLOCKS.TABLE_HEADER_CELL,
27266
27356
  data: {},
27267
- content: (_m = node.content) === null || _m === void 0 ? void 0 : _m.map((child) => convertNode(child)),
27357
+ content: (_m = node.content) === null || _m === void 0 ? void 0 : _m.map(function (child) { return convertNode(child); }),
27268
27358
  };
27269
27359
  case 'text':
27270
- const marks = ((_o = node.marks) === null || _o === void 0 ? void 0 : _o.map((mark) => {
27360
+ var marks = ((_o = node.marks) === null || _o === void 0 ? void 0 : _o.map(function (mark) {
27271
27361
  switch (mark.type) {
27272
27362
  case 'bold':
27273
27363
  return { type: distExports.MARKS.BOLD };
@@ -27284,7 +27374,7 @@ const tiptapToContentful = (tiptapDoc) => {
27284
27374
  }
27285
27375
  }).filter(Boolean)) || [];
27286
27376
  // Check if this text has a link mark
27287
- const linkMark = (_p = node.marks) === null || _p === void 0 ? void 0 : _p.find((mark) => mark.type === 'link');
27377
+ var linkMark = (_p = node.marks) === null || _p === void 0 ? void 0 : _p.find(function (mark) { return mark.type === 'link'; });
27288
27378
  if (linkMark) {
27289
27379
  return {
27290
27380
  nodeType: distExports.INLINES.HYPERLINK,
@@ -27301,6 +27391,26 @@ const tiptapToContentful = (tiptapDoc) => {
27301
27391
  ],
27302
27392
  };
27303
27393
  }
27394
+ // Check if this is an inline entry (by looking for specific patterns)
27395
+ var isInlineEntry = node.text && node.text.startsWith('[Inline Entry:');
27396
+ if (isInlineEntry && ((_r = node.marks) === null || _r === void 0 ? void 0 : _r.some(function (mark) { return mark.type === 'bold'; }))) {
27397
+ // Extract entry ID from the text
27398
+ var match = node.text.match(/\[Inline Entry:\s*([^\]]+)\]/);
27399
+ var entryId = match ? match[1].trim() : 'Unknown';
27400
+ return {
27401
+ nodeType: distExports.INLINES.EMBEDDED_ENTRY,
27402
+ data: {
27403
+ target: {
27404
+ sys: {
27405
+ id: entryId,
27406
+ type: 'Link',
27407
+ linkType: 'Entry',
27408
+ },
27409
+ },
27410
+ },
27411
+ content: [],
27412
+ };
27413
+ }
27304
27414
  return {
27305
27415
  nodeType: 'text',
27306
27416
  value: node.text || '',
@@ -27308,7 +27418,7 @@ const tiptapToContentful = (tiptapDoc) => {
27308
27418
  data: {},
27309
27419
  };
27310
27420
  default:
27311
- console.warn(`Unknown Tiptap node type: ${node.type}`);
27421
+ console.warn("Unknown Tiptap node type: ".concat(node.type));
27312
27422
  return {
27313
27423
  nodeType: distExports.BLOCKS.PARAGRAPH,
27314
27424
  data: {},
@@ -27321,7 +27431,7 @@ const tiptapToContentful = (tiptapDoc) => {
27321
27431
  /**
27322
27432
  * Validates if a Contentful document is properly formatted
27323
27433
  */
27324
- const validateContentfulDocument = (document) => {
27434
+ var validateContentfulDocument = function (document) {
27325
27435
  if (!document || typeof document !== 'object') {
27326
27436
  return false;
27327
27437
  }
@@ -27336,7 +27446,7 @@ const validateContentfulDocument = (document) => {
27336
27446
  /**
27337
27447
  * Creates an empty Contentful document
27338
27448
  */
27339
- const createEmptyDocument = () => ({
27449
+ var createEmptyDocument = function () { return ({
27340
27450
  nodeType: distExports.BLOCKS.DOCUMENT,
27341
27451
  data: {},
27342
27452
  content: [
@@ -27346,76 +27456,352 @@ const createEmptyDocument = () => ({
27346
27456
  content: [],
27347
27457
  },
27348
27458
  ],
27349
- });
27459
+ }); };
27460
+ /**
27461
+ * Sanitizes a Contentful document by removing invalid nodes/marks based on configuration
27462
+ */
27463
+ var sanitizeContentfulDocument = function (document, allowedNodeTypes, allowedMarks) {
27464
+ var sanitizeNode = function (node) {
27465
+ var _a, _b;
27466
+ // Check if node type is allowed
27467
+ if (!allowedNodeTypes.includes(node.nodeType)) {
27468
+ // Convert to paragraph if it's a block that's not allowed
27469
+ if (node.nodeType.startsWith('heading-') ||
27470
+ node.nodeType === distExports.BLOCKS.QUOTE ||
27471
+ node.nodeType === distExports.BLOCKS.UL_LIST ||
27472
+ node.nodeType === distExports.BLOCKS.OL_LIST) {
27473
+ return {
27474
+ nodeType: distExports.BLOCKS.PARAGRAPH,
27475
+ data: {},
27476
+ content: (_a = node.content) === null || _a === void 0 ? void 0 : _a.map(function (child) { return sanitizeNode(child); }).filter(Boolean),
27477
+ };
27478
+ }
27479
+ return null;
27480
+ }
27481
+ if (node.nodeType === 'text') {
27482
+ var textNode = node;
27483
+ var sanitizedMarks = ((_b = textNode.marks) === null || _b === void 0 ? void 0 : _b.filter(function (mark) { return allowedMarks.includes(mark.type); })) || [];
27484
+ return __assign(__assign({}, textNode), { marks: sanitizedMarks });
27485
+ }
27486
+ if ('content' in node && node.content) {
27487
+ var sanitizedContent = node.content.map(function (child) { return sanitizeNode(child); }).filter(Boolean);
27488
+ return __assign(__assign({}, node), { content: sanitizedContent });
27489
+ }
27490
+ return node;
27491
+ };
27492
+ var sanitized = sanitizeNode(document);
27493
+ return sanitized;
27494
+ };
27495
+ /**
27496
+ * Extracts plain text from a Contentful document
27497
+ */
27498
+ var extractPlainText = function (document) {
27499
+ var extractFromNode = function (node) {
27500
+ if (node.nodeType === 'text') {
27501
+ return node.value;
27502
+ }
27503
+ if ('content' in node && node.content) {
27504
+ return node.content.map(function (child) { return extractFromNode(child); }).join('');
27505
+ }
27506
+ return '';
27507
+ };
27508
+ return extractFromNode(document);
27509
+ };
27510
+ /**
27511
+ * Counts words in a Contentful document
27512
+ */
27513
+ var countWords = function (document) {
27514
+ var plainText = extractPlainText(document);
27515
+ var words = plainText.trim().split(/\s+/).filter(function (word) { return word.length > 0; });
27516
+ return words.length;
27517
+ };
27518
+ /**
27519
+ * Finds all embedded entries/assets in a document
27520
+ */
27521
+ var findEmbeddedContent = function (document) {
27522
+ var entries = [];
27523
+ var assets = [];
27524
+ var inlineEntries = [];
27525
+ var searchNode = function (node) {
27526
+ var _a, _b, _c, _d, _e, _f;
27527
+ if (node.nodeType === distExports.BLOCKS.EMBEDDED_ENTRY) {
27528
+ var entryId = (_b = (_a = node.data.target) === null || _a === void 0 ? void 0 : _a.sys) === null || _b === void 0 ? void 0 : _b.id;
27529
+ if (entryId)
27530
+ entries.push(entryId);
27531
+ }
27532
+ else if (node.nodeType === distExports.BLOCKS.EMBEDDED_ASSET) {
27533
+ var assetId = (_d = (_c = node.data.target) === null || _c === void 0 ? void 0 : _c.sys) === null || _d === void 0 ? void 0 : _d.id;
27534
+ if (assetId)
27535
+ assets.push(assetId);
27536
+ }
27537
+ else if (node.nodeType === distExports.INLINES.EMBEDDED_ENTRY) {
27538
+ var entryId = (_f = (_e = node.data.target) === null || _e === void 0 ? void 0 : _e.sys) === null || _f === void 0 ? void 0 : _f.id;
27539
+ if (entryId)
27540
+ inlineEntries.push(entryId);
27541
+ }
27542
+ if ('content' in node && node.content) {
27543
+ node.content.forEach(function (child) { return searchNode(child); });
27544
+ }
27545
+ };
27546
+ searchNode(document);
27547
+ return {
27548
+ entries: Array.from(new Set(entries)), // Remove duplicates
27549
+ assets: Array.from(new Set(assets)),
27550
+ inlineEntries: Array.from(new Set(inlineEntries)),
27551
+ };
27552
+ };
27350
27553
 
27351
- const ContentfulRichTextEditor = ({ initialValue, onChange, onEmbedEntry, onEmbedAsset, className = '', readonly = false, placeholder = 'Start writing...', disabledFeatures = [], theme = 'contentful', availableHeadings = [1, 2, 3, 4, 5, 6], availableMarks = ['bold', 'italic', 'underline'] }) => {
27352
- // Build extensions array based on available features
27353
- const extensions = [];
27354
- // Add StarterKit with configuration
27355
- extensions.push(StarterKit.configure({
27356
- heading: {
27357
- levels: availableHeadings,
27358
- },
27359
- bold: availableMarks.includes('bold') ? {} : false,
27360
- italic: availableMarks.includes('italic') ? {} : false,
27361
- bulletList: {
27362
- HTMLAttributes: {
27363
- class: 'contentful-bullet-list',
27364
- },
27365
- },
27366
- orderedList: {
27367
- HTMLAttributes: {
27368
- class: 'contentful-ordered-list',
27369
- },
27370
- },
27371
- blockquote: {
27372
- HTMLAttributes: {
27373
- class: 'contentful-blockquote',
27374
- },
27375
- },
27376
- }));
27377
- // Always add underline extension to schema to support content with underline marks
27378
- // The availableMarks prop only controls toolbar visibility, not schema support
27379
- extensions.push(Underline);
27380
- // Add other extensions
27381
- extensions.push(Link.configure({
27382
- openOnClick: false,
27383
- HTMLAttributes: {
27384
- class: 'contentful-link',
27385
- rel: 'noopener noreferrer',
27386
- },
27387
- }), Table.configure({
27388
- resizable: true,
27389
- HTMLAttributes: {
27390
- class: 'contentful-table',
27391
- },
27392
- }), TableRow.configure({
27393
- HTMLAttributes: {
27394
- class: 'contentful-table-row',
27395
- },
27396
- }), TableHeader.configure({
27397
- HTMLAttributes: {
27398
- class: 'contentful-table-header',
27399
- },
27400
- }), TableCell.configure({
27401
- HTMLAttributes: {
27402
- class: 'contentful-table-cell',
27403
- },
27404
- }));
27405
- const editor = useEditor({
27406
- extensions,
27554
+ // Utility functions for parsing Contentful Rich Text field configurations
27555
+ /**
27556
+ * Parses Contentful field configuration to determine editor capabilities
27557
+ */
27558
+ var parseContentfulFieldConfig = function (fieldConfiguration) {
27559
+ var _a;
27560
+ // Default configuration when no field config is provided
27561
+ var defaultConfig = {
27562
+ availableHeadings: [1, 2, 3, 4, 5, 6],
27563
+ availableMarks: ['bold', 'italic', 'underline'],
27564
+ disabledFeatures: [],
27565
+ allowHyperlinks: true,
27566
+ allowEmbeddedEntries: true,
27567
+ allowEmbeddedAssets: true,
27568
+ allowInlineEntries: true,
27569
+ allowTables: true,
27570
+ allowQuotes: true,
27571
+ allowLists: true,
27572
+ };
27573
+ if (!((_a = fieldConfiguration === null || fieldConfiguration === void 0 ? void 0 : fieldConfiguration.validations) === null || _a === void 0 ? void 0 : _a[0])) {
27574
+ return defaultConfig;
27575
+ }
27576
+ var validation = fieldConfiguration.validations[0];
27577
+ var enabledMarks = validation.enabledMarks || [];
27578
+ var enabledNodeTypes = validation.enabledNodeTypes || [];
27579
+ // Parse available text marks
27580
+ var marks = [];
27581
+ if (enabledMarks.includes('bold'))
27582
+ marks.push('bold');
27583
+ if (enabledMarks.includes('italic'))
27584
+ marks.push('italic');
27585
+ if (enabledMarks.includes('underline'))
27586
+ marks.push('underline');
27587
+ // Parse available heading levels
27588
+ var headings = [];
27589
+ if (enabledNodeTypes.includes('heading-1'))
27590
+ headings.push(1);
27591
+ if (enabledNodeTypes.includes('heading-2'))
27592
+ headings.push(2);
27593
+ if (enabledNodeTypes.includes('heading-3'))
27594
+ headings.push(3);
27595
+ if (enabledNodeTypes.includes('heading-4'))
27596
+ headings.push(4);
27597
+ if (enabledNodeTypes.includes('heading-5'))
27598
+ headings.push(5);
27599
+ if (enabledNodeTypes.includes('heading-6'))
27600
+ headings.push(6);
27601
+ // Parse other features
27602
+ var allowHyperlinks = enabledNodeTypes.includes('hyperlink');
27603
+ var allowEmbeddedEntries = enabledNodeTypes.includes('embedded-entry-block');
27604
+ var allowEmbeddedAssets = enabledNodeTypes.includes('embedded-asset-block');
27605
+ var allowInlineEntries = enabledNodeTypes.includes('embedded-entry-inline');
27606
+ var allowTables = enabledNodeTypes.includes('table');
27607
+ var allowQuotes = enabledNodeTypes.includes('blockquote') || enabledNodeTypes.includes('quote');
27608
+ var allowLists = enabledNodeTypes.includes('unordered-list') || enabledNodeTypes.includes('ordered-list');
27609
+ // Build disabled features array
27610
+ var disabled = [];
27611
+ if (!marks.includes('bold'))
27612
+ disabled.push('bold');
27613
+ if (!marks.includes('italic'))
27614
+ disabled.push('italic');
27615
+ if (!marks.includes('underline'))
27616
+ disabled.push('underline');
27617
+ if (!allowHyperlinks)
27618
+ disabled.push('link');
27619
+ if (!allowLists)
27620
+ disabled.push('lists');
27621
+ if (headings.length === 0)
27622
+ disabled.push('headings');
27623
+ if (!allowQuotes)
27624
+ disabled.push('quote');
27625
+ if (!allowTables)
27626
+ disabled.push('table');
27627
+ if (!allowEmbeddedEntries && !allowEmbeddedAssets && !allowInlineEntries)
27628
+ disabled.push('embed');
27629
+ return {
27630
+ availableHeadings: headings,
27631
+ availableMarks: marks,
27632
+ disabledFeatures: disabled,
27633
+ allowHyperlinks: allowHyperlinks,
27634
+ allowEmbeddedEntries: allowEmbeddedEntries,
27635
+ allowEmbeddedAssets: allowEmbeddedAssets,
27636
+ allowInlineEntries: allowInlineEntries,
27637
+ allowTables: allowTables,
27638
+ allowQuotes: allowQuotes,
27639
+ allowLists: allowLists,
27640
+ };
27641
+ };
27642
+ /**
27643
+ * Helper function to fetch Contentful field configuration from Management API
27644
+ */
27645
+ var fetchContentfulFieldConfig = function (spaceId, contentTypeId, fieldId, accessToken) { return __awaiter(void 0, void 0, void 0, function () {
27646
+ var response, contentType, field, error_1;
27647
+ return __generator(this, function (_a) {
27648
+ switch (_a.label) {
27649
+ case 0:
27650
+ _a.trys.push([0, 3, , 4]);
27651
+ return [4 /*yield*/, fetch("https://api.contentful.com/spaces/".concat(spaceId, "/content_types/").concat(contentTypeId), {
27652
+ headers: {
27653
+ 'Authorization': "Bearer ".concat(accessToken),
27654
+ 'Content-Type': 'application/vnd.contentful.management.v1+json',
27655
+ },
27656
+ })];
27657
+ case 1:
27658
+ response = _a.sent();
27659
+ if (!response.ok) {
27660
+ throw new Error("Failed to fetch content type: ".concat(response.status, " ").concat(response.statusText));
27661
+ }
27662
+ return [4 /*yield*/, response.json()];
27663
+ case 2:
27664
+ contentType = _a.sent();
27665
+ field = contentType.fields.find(function (f) { return f.id === fieldId; });
27666
+ if (!field || field.type !== 'RichText') {
27667
+ console.warn("Field \"".concat(fieldId, "\" not found or is not a RichText field"));
27668
+ return [2 /*return*/, null];
27669
+ }
27670
+ return [2 /*return*/, {
27671
+ validations: field.validations || [],
27672
+ settings: {
27673
+ helpText: field.helpText,
27674
+ },
27675
+ }];
27676
+ case 3:
27677
+ error_1 = _a.sent();
27678
+ console.error('Error fetching Contentful field configuration:', error_1);
27679
+ return [2 /*return*/, null];
27680
+ case 4: return [2 /*return*/];
27681
+ }
27682
+ });
27683
+ }); };
27684
+ /**
27685
+ * Creates a mock field configuration for testing purposes
27686
+ */
27687
+ var createMockFieldConfig = function (options) {
27688
+ return {
27689
+ validations: [{
27690
+ enabledMarks: options.enabledMarks || ['bold', 'italic'],
27691
+ enabledNodeTypes: options.enabledNodeTypes || [
27692
+ 'paragraph',
27693
+ 'heading-1',
27694
+ 'heading-2',
27695
+ 'heading-3',
27696
+ 'unordered-list',
27697
+ 'ordered-list',
27698
+ 'hyperlink',
27699
+ 'embedded-entry-block',
27700
+ ],
27701
+ }],
27702
+ };
27703
+ };
27704
+
27705
+ var ContentfulRichTextEditor = function (_a) {
27706
+ var initialValue = _a.initialValue, onChange = _a.onChange, onEmbedEntry = _a.onEmbedEntry, onEmbedAsset = _a.onEmbedAsset, onEmbedInlineEntry = _a.onEmbedInlineEntry, _b = _a.className, className = _b === void 0 ? '' : _b, _c = _a.readonly, readonly = _c === void 0 ? false : _c, _d = _a.placeholder, placeholder = _d === void 0 ? 'Start writing...' : _d, fieldConfiguration = _a.fieldConfiguration, _e = _a.disabledFeatures, disabledFeatures = _e === void 0 ? [] : _e, _f = _a.theme, theme = _f === void 0 ? 'contentful' : _f, _g = _a.availableHeadings, availableHeadings = _g === void 0 ? [1, 2, 3, 4, 5, 6] : _g, _h = _a.availableMarks, availableMarks = _h === void 0 ? ['bold', 'italic', 'underline'] : _h, _j = _a.showBorder, showBorder = _j === void 0 ? true : _j;
27707
+ var editorConfig = useMemo(function () {
27708
+ if (fieldConfiguration) {
27709
+ return parseContentfulFieldConfig(fieldConfiguration);
27710
+ }
27711
+ var disabled = [];
27712
+ if (!availableMarks.includes('bold'))
27713
+ disabled.push('bold');
27714
+ if (!availableMarks.includes('italic'))
27715
+ disabled.push('italic');
27716
+ if (!availableMarks.includes('underline'))
27717
+ disabled.push('underline');
27718
+ disabled.push.apply(disabled, disabledFeatures);
27719
+ return {
27720
+ availableHeadings: availableHeadings,
27721
+ availableMarks: availableMarks,
27722
+ disabledFeatures: disabled,
27723
+ allowHyperlinks: !disabledFeatures.includes('link'),
27724
+ allowEmbeddedEntries: !disabledFeatures.includes('embed'),
27725
+ allowEmbeddedAssets: !disabledFeatures.includes('embed'),
27726
+ allowInlineEntries: !disabledFeatures.includes('embed'),
27727
+ allowTables: !disabledFeatures.includes('table'),
27728
+ allowQuotes: !disabledFeatures.includes('quote'),
27729
+ allowLists: !disabledFeatures.includes('lists'),
27730
+ };
27731
+ }, [fieldConfiguration, disabledFeatures, availableHeadings, availableMarks]);
27732
+ var extensions = useMemo(function () {
27733
+ var exts = [];
27734
+ exts.push(StarterKit.configure({
27735
+ heading: editorConfig.availableHeadings.length > 0 ? {
27736
+ levels: editorConfig.availableHeadings,
27737
+ } : false,
27738
+ bold: editorConfig.availableMarks.includes('bold') ? {} : false,
27739
+ italic: editorConfig.availableMarks.includes('italic') ? {} : false,
27740
+ bulletList: editorConfig.allowLists ? {
27741
+ HTMLAttributes: {
27742
+ class: 'contentful-bullet-list',
27743
+ },
27744
+ } : false,
27745
+ orderedList: editorConfig.allowLists ? {
27746
+ HTMLAttributes: {
27747
+ class: 'contentful-ordered-list',
27748
+ },
27749
+ } : false,
27750
+ blockquote: editorConfig.allowQuotes ? {
27751
+ HTMLAttributes: {
27752
+ class: 'contentful-blockquote',
27753
+ },
27754
+ } : false,
27755
+ }));
27756
+ if (editorConfig.availableMarks.includes('underline')) {
27757
+ exts.push(Underline);
27758
+ }
27759
+ if (editorConfig.allowHyperlinks) {
27760
+ exts.push(Link.configure({
27761
+ openOnClick: false,
27762
+ HTMLAttributes: {
27763
+ class: 'contentful-link',
27764
+ rel: 'noopener noreferrer',
27765
+ },
27766
+ }));
27767
+ }
27768
+ if (editorConfig.allowTables) {
27769
+ exts.push(Table.configure({
27770
+ resizable: true,
27771
+ HTMLAttributes: {
27772
+ class: 'contentful-table',
27773
+ },
27774
+ }), TableRow.configure({
27775
+ HTMLAttributes: {
27776
+ class: 'contentful-table-row',
27777
+ },
27778
+ }), TableHeader.configure({
27779
+ HTMLAttributes: {
27780
+ class: 'contentful-table-header',
27781
+ },
27782
+ }), TableCell.configure({
27783
+ HTMLAttributes: {
27784
+ class: 'contentful-table-cell',
27785
+ },
27786
+ }));
27787
+ }
27788
+ return exts;
27789
+ }, [editorConfig]);
27790
+ var editor = useEditor({
27791
+ extensions: extensions,
27407
27792
  content: initialValue ? contentfulToTiptap(initialValue) : '',
27408
27793
  editable: !readonly,
27409
27794
  editorProps: {
27410
27795
  attributes: {
27411
- class: `contentful-editor-content contentful-editor-content--${theme}`,
27796
+ class: "contentful-editor-content contentful-editor-content--".concat(theme),
27412
27797
  'data-placeholder': placeholder,
27413
27798
  },
27414
27799
  },
27415
- onUpdate: ({ editor }) => {
27800
+ onUpdate: function (_a) {
27801
+ var editor = _a.editor;
27416
27802
  if (onChange) {
27417
27803
  try {
27418
- const contentfulDoc = tiptapToContentful(editor.getJSON());
27804
+ var contentfulDoc = tiptapToContentful(editor.getJSON());
27419
27805
  onChange(contentfulDoc);
27420
27806
  }
27421
27807
  catch (error) {
@@ -27424,66 +27810,123 @@ const ContentfulRichTextEditor = ({ initialValue, onChange, onEmbedEntry, onEmbe
27424
27810
  }
27425
27811
  },
27426
27812
  });
27427
- // Update editor content when initialValue changes
27428
- useEffect(() => {
27813
+ useEffect(function () {
27429
27814
  if (editor && initialValue) {
27430
- const tiptapContent = contentfulToTiptap(initialValue);
27815
+ var tiptapContent = contentfulToTiptap(initialValue);
27431
27816
  editor.commands.setContent(tiptapContent, false);
27432
27817
  }
27433
27818
  }, [editor, initialValue]);
27434
- const handleEmbedEntry = useCallback(async () => {
27435
- var _a;
27436
- if (onEmbedEntry && editor) {
27437
- try {
27438
- const entry = await onEmbedEntry();
27439
- if (entry) {
27440
- // Insert embedded entry at cursor position
27441
- editor.chain().focus().insertContent({
27442
- type: 'paragraph',
27443
- content: [
27444
- {
27445
- type: 'text',
27446
- text: `[Embedded Entry: ${((_a = entry.sys) === null || _a === void 0 ? void 0 : _a.id) || 'Unknown'}]`,
27447
- marks: [{ type: 'bold' }],
27448
- },
27449
- ],
27450
- }).run();
27451
- }
27452
- }
27453
- catch (error) {
27454
- console.error('Error embedding entry:', error);
27819
+ var handleEmbedEntry = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
27820
+ var entry, error_1;
27821
+ var _a, _b;
27822
+ return __generator(this, function (_c) {
27823
+ switch (_c.label) {
27824
+ case 0:
27825
+ if (!(onEmbedEntry && editor && editorConfig.allowEmbeddedEntries)) return [3 /*break*/, 4];
27826
+ _c.label = 1;
27827
+ case 1:
27828
+ _c.trys.push([1, 3, , 4]);
27829
+ return [4 /*yield*/, onEmbedEntry()];
27830
+ case 2:
27831
+ entry = _c.sent();
27832
+ if (entry) {
27833
+ editor.chain().focus().insertContent({
27834
+ type: 'paragraph',
27835
+ content: [
27836
+ {
27837
+ type: 'text',
27838
+ text: "[Embedded Entry: ".concat(((_a = entry.sys) === null || _a === void 0 ? void 0 : _a.id) || ((_b = entry.fields) === null || _b === void 0 ? void 0 : _b.title) || 'Unknown', "]"),
27839
+ marks: [{ type: 'bold' }],
27840
+ },
27841
+ ],
27842
+ }).run();
27843
+ }
27844
+ return [3 /*break*/, 4];
27845
+ case 3:
27846
+ error_1 = _c.sent();
27847
+ console.error('Error embedding entry:', error_1);
27848
+ return [3 /*break*/, 4];
27849
+ case 4: return [2 /*return*/];
27455
27850
  }
27456
- }
27457
- }, [onEmbedEntry, editor]);
27458
- const handleEmbedAsset = useCallback(async () => {
27459
- var _a;
27460
- if (onEmbedAsset && editor) {
27461
- try {
27462
- const asset = await onEmbedAsset();
27463
- if (asset) {
27464
- // Insert embedded asset at cursor position
27465
- editor.chain().focus().insertContent({
27466
- type: 'paragraph',
27467
- content: [
27468
- {
27469
- type: 'text',
27470
- text: `[Embedded Asset: ${((_a = asset.sys) === null || _a === void 0 ? void 0 : _a.id) || 'Unknown'}]`,
27471
- marks: [{ type: 'bold' }],
27472
- },
27473
- ],
27474
- }).run();
27475
- }
27851
+ });
27852
+ }); }, [onEmbedEntry, editor, editorConfig.allowEmbeddedEntries]);
27853
+ var handleEmbedAsset = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
27854
+ var asset, error_2;
27855
+ var _a, _b;
27856
+ return __generator(this, function (_c) {
27857
+ switch (_c.label) {
27858
+ case 0:
27859
+ if (!(onEmbedAsset && editor && editorConfig.allowEmbeddedAssets)) return [3 /*break*/, 4];
27860
+ _c.label = 1;
27861
+ case 1:
27862
+ _c.trys.push([1, 3, , 4]);
27863
+ return [4 /*yield*/, onEmbedAsset()];
27864
+ case 2:
27865
+ asset = _c.sent();
27866
+ if (asset) {
27867
+ editor.chain().focus().insertContent({
27868
+ type: 'paragraph',
27869
+ content: [
27870
+ {
27871
+ type: 'text',
27872
+ text: "[Embedded Asset: ".concat(((_a = asset.sys) === null || _a === void 0 ? void 0 : _a.id) || ((_b = asset.fields) === null || _b === void 0 ? void 0 : _b.title) || 'Unknown', "]"),
27873
+ marks: [{ type: 'bold' }],
27874
+ },
27875
+ ],
27876
+ }).run();
27877
+ }
27878
+ return [3 /*break*/, 4];
27879
+ case 3:
27880
+ error_2 = _c.sent();
27881
+ console.error('Error embedding asset:', error_2);
27882
+ return [3 /*break*/, 4];
27883
+ case 4: return [2 /*return*/];
27476
27884
  }
27477
- catch (error) {
27478
- console.error('Error embedding asset:', error);
27885
+ });
27886
+ }); }, [onEmbedAsset, editor, editorConfig.allowEmbeddedAssets]);
27887
+ var handleEmbedInlineEntry = useCallback(function () { return __awaiter(void 0, void 0, void 0, function () {
27888
+ var entry, error_3;
27889
+ var _a, _b;
27890
+ return __generator(this, function (_c) {
27891
+ switch (_c.label) {
27892
+ case 0:
27893
+ if (!(onEmbedInlineEntry && editor && editorConfig.allowInlineEntries)) return [3 /*break*/, 4];
27894
+ _c.label = 1;
27895
+ case 1:
27896
+ _c.trys.push([1, 3, , 4]);
27897
+ return [4 /*yield*/, onEmbedInlineEntry()];
27898
+ case 2:
27899
+ entry = _c.sent();
27900
+ if (entry) {
27901
+ editor.chain().focus().insertContent({
27902
+ type: 'text',
27903
+ text: "[Inline Entry: ".concat(((_a = entry.sys) === null || _a === void 0 ? void 0 : _a.id) || ((_b = entry.fields) === null || _b === void 0 ? void 0 : _b.title) || 'Unknown', "]"),
27904
+ marks: [{ type: 'bold' }],
27905
+ }).run();
27906
+ }
27907
+ return [3 /*break*/, 4];
27908
+ case 3:
27909
+ error_3 = _c.sent();
27910
+ console.error('Error embedding inline entry:', error_3);
27911
+ return [3 /*break*/, 4];
27912
+ case 4: return [2 /*return*/];
27479
27913
  }
27480
- }
27481
- }, [onEmbedAsset, editor]);
27914
+ });
27915
+ }); }, [onEmbedInlineEntry, editor, editorConfig.allowInlineEntries]);
27916
+ var editorClass = [
27917
+ 'contentful-editor',
27918
+ "contentful-editor--".concat(theme),
27919
+ !showBorder ? 'contentful-editor--borderless' : '',
27920
+ className,
27921
+ ].filter(Boolean).join(' ');
27482
27922
  if (!editor) {
27483
- return (jsx("div", { className: `contentful-editor contentful-editor--loading ${className}`, children: jsx("div", { className: "contentful-editor__loading", children: "Loading editor..." }) }));
27923
+ return (jsx("div", { className: "contentful-editor contentful-editor--loading ".concat(className), children: jsx("div", { className: "contentful-editor__loading", children: "Loading editor..." }) }));
27484
27924
  }
27485
- return (jsxs("div", { className: `contentful-editor contentful-editor--${theme} ${className}`, children: [!readonly && (jsx(ContentfulToolbar, { editor: editor, onEmbedEntry: handleEmbedEntry, onEmbedAsset: handleEmbedAsset, disabledFeatures: disabledFeatures, availableHeadings: availableHeadings, availableMarks: availableMarks })), jsx("div", { className: "contentful-editor__content-wrapper", children: jsx(EditorContent, { editor: editor, className: "contentful-editor__content" }) })] }));
27925
+ return (jsxs("div", { className: editorClass, children: [!readonly && (jsx(ContentfulToolbar, { editor: editor, onEmbedEntry: editorConfig.allowEmbeddedEntries ? handleEmbedEntry : undefined, onEmbedAsset: editorConfig.allowEmbeddedAssets ? handleEmbedAsset : undefined, onEmbedInlineEntry: editorConfig.allowInlineEntries ? handleEmbedInlineEntry : undefined, disabledFeatures: editorConfig.disabledFeatures, availableHeadings: editorConfig.availableHeadings, availableMarks: editorConfig.availableMarks, allowHyperlinks: editorConfig.allowHyperlinks })), jsx("div", { className: "contentful-editor__content-wrapper", children: jsx(EditorContent, { editor: editor, className: "contentful-editor__content", "data-testid": "editor-content" }) })] }));
27486
27926
  };
27487
27927
 
27488
- export { ContentfulRichTextEditor, ContentfulToolbar, contentfulToTiptap, createEmptyDocument, tiptapToContentful, validateContentfulDocument };
27928
+ var BLOCKS = distExports.BLOCKS;
27929
+ var INLINES = distExports.INLINES;
27930
+ var MARKS = distExports.MARKS;
27931
+ export { BLOCKS, ContentfulRichTextEditor, ContentfulToolbar, INLINES, MARKS, contentfulToTiptap, countWords, createEmptyDocument, createMockFieldConfig, extractPlainText, fetchContentfulFieldConfig, findEmbeddedContent, parseContentfulFieldConfig, sanitizeContentfulDocument, tiptapToContentful, validateContentfulDocument };
27489
27932
  //# sourceMappingURL=index.esm.js.map