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