@carlonicora/nextjs-jsonapi 0.0.1

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.
Files changed (222) hide show
  1. package/README.md +889 -0
  2. package/dist/AbstractService-BKlpJA61.d.mts +109 -0
  3. package/dist/AbstractService-D9eSVKNa.d.ts +109 -0
  4. package/dist/ApiData-DPKNfY-9.d.mts +10 -0
  5. package/dist/ApiData-DPKNfY-9.d.ts +10 -0
  6. package/dist/ApiDataInterface-DPP8s46n.d.mts +21 -0
  7. package/dist/ApiDataInterface-DPP8s46n.d.ts +21 -0
  8. package/dist/ApiRequestDataTypeInterface-CUKFDBx2.d.mts +20 -0
  9. package/dist/ApiRequestDataTypeInterface-CUKFDBx2.d.ts +20 -0
  10. package/dist/ApiResponseInterface-BHN5D9r5.d.mts +16 -0
  11. package/dist/ApiResponseInterface-DDI7QQPR.d.ts +16 -0
  12. package/dist/BlockNoteEditor-UVO3VZZE.mjs +396 -0
  13. package/dist/BlockNoteEditor-UVO3VZZE.mjs.map +1 -0
  14. package/dist/BlockNoteEditor-VFWG6LXI.js +396 -0
  15. package/dist/BlockNoteEditor-VFWG6LXI.js.map +1 -0
  16. package/dist/JsonApiRequest-S3ICLM7B.mjs +20 -0
  17. package/dist/JsonApiRequest-S3ICLM7B.mjs.map +1 -0
  18. package/dist/JsonApiRequest-ZZLSP26T.js +20 -0
  19. package/dist/JsonApiRequest-ZZLSP26T.js.map +1 -0
  20. package/dist/atoms/index.d.mts +12 -0
  21. package/dist/atoms/index.d.ts +12 -0
  22. package/dist/atoms/index.js +9 -0
  23. package/dist/atoms/index.js.map +1 -0
  24. package/dist/atoms/index.mjs +9 -0
  25. package/dist/atoms/index.mjs.map +1 -0
  26. package/dist/breadcrumb.item.data.interface-CgB4_1EE.d.mts +6 -0
  27. package/dist/breadcrumb.item.data.interface-CgB4_1EE.d.ts +6 -0
  28. package/dist/chunk-2K3Q24UF.js +89 -0
  29. package/dist/chunk-2K3Q24UF.js.map +1 -0
  30. package/dist/chunk-2LM6LCJW.mjs +1091 -0
  31. package/dist/chunk-2LM6LCJW.mjs.map +1 -0
  32. package/dist/chunk-366S2JCC.mjs +31 -0
  33. package/dist/chunk-366S2JCC.mjs.map +1 -0
  34. package/dist/chunk-3FBCC4G3.js +8 -0
  35. package/dist/chunk-3FBCC4G3.js.map +1 -0
  36. package/dist/chunk-4HCRAOS5.js +28 -0
  37. package/dist/chunk-4HCRAOS5.js.map +1 -0
  38. package/dist/chunk-5W6AKZE6.mjs +131 -0
  39. package/dist/chunk-5W6AKZE6.mjs.map +1 -0
  40. package/dist/chunk-6GKHCVF6.js +98 -0
  41. package/dist/chunk-6GKHCVF6.js.map +1 -0
  42. package/dist/chunk-7QVYU63E.js +7 -0
  43. package/dist/chunk-7QVYU63E.js.map +1 -0
  44. package/dist/chunk-A3J3AAYM.mjs +97 -0
  45. package/dist/chunk-A3J3AAYM.mjs.map +1 -0
  46. package/dist/chunk-A5DDIABK.js +4209 -0
  47. package/dist/chunk-A5DDIABK.js.map +1 -0
  48. package/dist/chunk-AUXK7QSA.mjs +15 -0
  49. package/dist/chunk-AUXK7QSA.mjs.map +1 -0
  50. package/dist/chunk-AWONBQQP.js +97 -0
  51. package/dist/chunk-AWONBQQP.js.map +1 -0
  52. package/dist/chunk-BLWVZK6J.mjs +28 -0
  53. package/dist/chunk-BLWVZK6J.mjs.map +1 -0
  54. package/dist/chunk-C7C7VY4F.mjs +77 -0
  55. package/dist/chunk-C7C7VY4F.mjs.map +1 -0
  56. package/dist/chunk-CXQOWQSY.js +55 -0
  57. package/dist/chunk-CXQOWQSY.js.map +1 -0
  58. package/dist/chunk-DD3KISNB.mjs +98 -0
  59. package/dist/chunk-DD3KISNB.mjs.map +1 -0
  60. package/dist/chunk-DKKMWBP4.mjs +1 -0
  61. package/dist/chunk-DKKMWBP4.mjs.map +1 -0
  62. package/dist/chunk-DO2HLAZO.js +48 -0
  63. package/dist/chunk-DO2HLAZO.js.map +1 -0
  64. package/dist/chunk-DZXDB3K2.mjs +17 -0
  65. package/dist/chunk-DZXDB3K2.mjs.map +1 -0
  66. package/dist/chunk-ECDTZBYO.mjs +230 -0
  67. package/dist/chunk-ECDTZBYO.mjs.map +1 -0
  68. package/dist/chunk-EFJEWLRL.js +16 -0
  69. package/dist/chunk-EFJEWLRL.js.map +1 -0
  70. package/dist/chunk-FY4SXJGU.js +806 -0
  71. package/dist/chunk-FY4SXJGU.js.map +1 -0
  72. package/dist/chunk-GYWPEPOH.mjs +1354 -0
  73. package/dist/chunk-GYWPEPOH.mjs.map +1 -0
  74. package/dist/chunk-H6FMOA6B.js +1 -0
  75. package/dist/chunk-H6FMOA6B.js.map +1 -0
  76. package/dist/chunk-HR4H2FP7.mjs +89 -0
  77. package/dist/chunk-HR4H2FP7.mjs.map +1 -0
  78. package/dist/chunk-I2REI7OA.js +462 -0
  79. package/dist/chunk-I2REI7OA.js.map +1 -0
  80. package/dist/chunk-IBS6NI7D.js +77 -0
  81. package/dist/chunk-IBS6NI7D.js.map +1 -0
  82. package/dist/chunk-IWFGEPAA.mjs +4209 -0
  83. package/dist/chunk-IWFGEPAA.mjs.map +1 -0
  84. package/dist/chunk-J4Q36PMP.js +31 -0
  85. package/dist/chunk-J4Q36PMP.js.map +1 -0
  86. package/dist/chunk-JC3WJK65.js +1091 -0
  87. package/dist/chunk-JC3WJK65.js.map +1 -0
  88. package/dist/chunk-L6EQEAXU.mjs +462 -0
  89. package/dist/chunk-L6EQEAXU.mjs.map +1 -0
  90. package/dist/chunk-LXKSUWAV.js +15 -0
  91. package/dist/chunk-LXKSUWAV.js.map +1 -0
  92. package/dist/chunk-MFO27OHB.mjs +48 -0
  93. package/dist/chunk-MFO27OHB.mjs.map +1 -0
  94. package/dist/chunk-PAWJFY3S.mjs +7 -0
  95. package/dist/chunk-PAWJFY3S.mjs.map +1 -0
  96. package/dist/chunk-Q2N6SQYW.mjs +8 -0
  97. package/dist/chunk-Q2N6SQYW.mjs.map +1 -0
  98. package/dist/chunk-RAF7PNLG.js +131 -0
  99. package/dist/chunk-RAF7PNLG.js.map +1 -0
  100. package/dist/chunk-RUR22SVM.js +17 -0
  101. package/dist/chunk-RUR22SVM.js.map +1 -0
  102. package/dist/chunk-TEGF6ZWG.js +109 -0
  103. package/dist/chunk-TEGF6ZWG.js.map +1 -0
  104. package/dist/chunk-TMVHSY3Y.js +230 -0
  105. package/dist/chunk-TMVHSY3Y.js.map +1 -0
  106. package/dist/chunk-V2JJPI7N.js +1354 -0
  107. package/dist/chunk-V2JJPI7N.js.map +1 -0
  108. package/dist/chunk-WWWMJZEF.mjs +806 -0
  109. package/dist/chunk-WWWMJZEF.mjs.map +1 -0
  110. package/dist/chunk-X4BIHJ2B.mjs +55 -0
  111. package/dist/chunk-X4BIHJ2B.mjs.map +1 -0
  112. package/dist/chunk-YDVTFM7X.mjs +109 -0
  113. package/dist/chunk-YDVTFM7X.mjs.map +1 -0
  114. package/dist/chunk-YF5XQZDR.mjs +16 -0
  115. package/dist/chunk-YF5XQZDR.mjs.map +1 -0
  116. package/dist/client/index.d.mts +252 -0
  117. package/dist/client/index.d.ts +252 -0
  118. package/dist/client/index.js +275 -0
  119. package/dist/client/index.js.map +1 -0
  120. package/dist/client/index.mjs +274 -0
  121. package/dist/client/index.mjs.map +1 -0
  122. package/dist/components/index.d.mts +441 -0
  123. package/dist/components/index.d.ts +441 -0
  124. package/dist/components/index.js +2474 -0
  125. package/dist/components/index.js.map +1 -0
  126. package/dist/components/index.mjs +2474 -0
  127. package/dist/components/index.mjs.map +1 -0
  128. package/dist/config-hXufftVS.d.mts +34 -0
  129. package/dist/config-hXufftVS.d.ts +34 -0
  130. package/dist/content.interface-BhyAiOFq.d.ts +35 -0
  131. package/dist/content.interface-Dg2lt_An.d.mts +35 -0
  132. package/dist/contexts/index.d.mts +56 -0
  133. package/dist/contexts/index.d.ts +56 -0
  134. package/dist/contexts/index.js +21 -0
  135. package/dist/contexts/index.js.map +1 -0
  136. package/dist/contexts/index.mjs +21 -0
  137. package/dist/contexts/index.mjs.map +1 -0
  138. package/dist/core/index.d.mts +152 -0
  139. package/dist/core/index.d.ts +152 -0
  140. package/dist/core/index.js +47 -0
  141. package/dist/core/index.js.map +1 -0
  142. package/dist/core/index.mjs +47 -0
  143. package/dist/core/index.mjs.map +1 -0
  144. package/dist/d3.link.interface-QMdB22bC.d.mts +20 -0
  145. package/dist/d3.link.interface-QMdB22bC.d.ts +20 -0
  146. package/dist/features/index.d.mts +553 -0
  147. package/dist/features/index.d.ts +553 -0
  148. package/dist/features/index.js +94 -0
  149. package/dist/features/index.js.map +1 -0
  150. package/dist/features/index.mjs +94 -0
  151. package/dist/features/index.mjs.map +1 -0
  152. package/dist/hooks/index.d.mts +94 -0
  153. package/dist/hooks/index.d.ts +94 -0
  154. package/dist/hooks/index.js +43 -0
  155. package/dist/hooks/index.js.map +1 -0
  156. package/dist/hooks/index.mjs +43 -0
  157. package/dist/hooks/index.mjs.map +1 -0
  158. package/dist/index.d.mts +72 -0
  159. package/dist/index.d.ts +72 -0
  160. package/dist/index.js +84 -0
  161. package/dist/index.js.map +1 -0
  162. package/dist/index.mjs +84 -0
  163. package/dist/index.mjs.map +1 -0
  164. package/dist/interfaces/index.d.mts +3 -0
  165. package/dist/interfaces/index.d.ts +3 -0
  166. package/dist/interfaces/index.js +2 -0
  167. package/dist/interfaces/index.js.map +1 -0
  168. package/dist/interfaces/index.mjs +2 -0
  169. package/dist/interfaces/index.mjs.map +1 -0
  170. package/dist/permissions/index.d.mts +41 -0
  171. package/dist/permissions/index.d.ts +41 -0
  172. package/dist/permissions/index.js +14 -0
  173. package/dist/permissions/index.js.map +1 -0
  174. package/dist/permissions/index.mjs +14 -0
  175. package/dist/permissions/index.mjs.map +1 -0
  176. package/dist/request-7FE3LJLV.mjs +9 -0
  177. package/dist/request-7FE3LJLV.mjs.map +1 -0
  178. package/dist/request-FYMQK5CX.mjs +9 -0
  179. package/dist/request-FYMQK5CX.mjs.map +1 -0
  180. package/dist/request-QFS7NEIE.js +9 -0
  181. package/dist/request-QFS7NEIE.js.map +1 -0
  182. package/dist/request-ZYY6RI5X.js +9 -0
  183. package/dist/request-ZYY6RI5X.js.map +1 -0
  184. package/dist/roles/index.d.mts +33 -0
  185. package/dist/roles/index.d.ts +33 -0
  186. package/dist/roles/index.js +12 -0
  187. package/dist/roles/index.js.map +1 -0
  188. package/dist/roles/index.mjs +12 -0
  189. package/dist/roles/index.mjs.map +1 -0
  190. package/dist/server/index.d.mts +44 -0
  191. package/dist/server/index.d.ts +44 -0
  192. package/dist/server/index.js +29 -0
  193. package/dist/server/index.js.map +1 -0
  194. package/dist/server/index.mjs +29 -0
  195. package/dist/server/index.mjs.map +1 -0
  196. package/dist/shadcnui/index.d.mts +698 -0
  197. package/dist/shadcnui/index.d.ts +698 -0
  198. package/dist/shadcnui/index.js +466 -0
  199. package/dist/shadcnui/index.js.map +1 -0
  200. package/dist/shadcnui/index.mjs +465 -0
  201. package/dist/shadcnui/index.mjs.map +1 -0
  202. package/dist/token-IJSPOMW6.mjs +9 -0
  203. package/dist/token-IJSPOMW6.mjs.map +1 -0
  204. package/dist/token-MJMC26ON.js +9 -0
  205. package/dist/token-MJMC26ON.js.map +1 -0
  206. package/dist/token-UADJQ7VC.mjs +9 -0
  207. package/dist/token-UADJQ7VC.mjs.map +1 -0
  208. package/dist/token-UYE7CV6X.js +9 -0
  209. package/dist/token-UYE7CV6X.js.map +1 -0
  210. package/dist/types-DluCaP1I.d.ts +95 -0
  211. package/dist/types-lQVA8d_P.d.mts +95 -0
  212. package/dist/useDataListRetriever-futhx3OP.d.mts +32 -0
  213. package/dist/useDataListRetriever-futhx3OP.d.ts +32 -0
  214. package/dist/user.interface-CAsTIbuQ.d.mts +85 -0
  215. package/dist/user.interface-CbWqMaaU.d.ts +85 -0
  216. package/dist/utils/index.d.mts +201 -0
  217. package/dist/utils/index.d.ts +201 -0
  218. package/dist/utils/index.js +32 -0
  219. package/dist/utils/index.js.map +1 -0
  220. package/dist/utils/index.mjs +32 -0
  221. package/dist/utils/index.mjs.map +1 -0
  222. package/package.json +205 -0
@@ -0,0 +1,1091 @@
1
+ import {
2
+ __name
3
+ } from "./chunk-PAWJFY3S.mjs";
4
+
5
+ // src/utils/cn.ts
6
+ import { clsx } from "clsx";
7
+ import { twMerge } from "tailwind-merge";
8
+ function cn(...inputs) {
9
+ return twMerge(clsx(inputs));
10
+ }
11
+ __name(cn, "cn");
12
+
13
+ // src/utils/compose-refs.ts
14
+ import * as React from "react";
15
+ function setRef(ref, value) {
16
+ if (typeof ref === "function") {
17
+ return ref(value);
18
+ }
19
+ if (ref !== null && ref !== void 0) {
20
+ ref.current = value;
21
+ }
22
+ }
23
+ __name(setRef, "setRef");
24
+ function composeRefs(...refs) {
25
+ return (node) => {
26
+ let hasCleanup = false;
27
+ const cleanups = refs.map((ref) => {
28
+ const cleanup = setRef(ref, node);
29
+ if (!hasCleanup && typeof cleanup === "function") {
30
+ hasCleanup = true;
31
+ }
32
+ return cleanup;
33
+ });
34
+ if (hasCleanup) {
35
+ return () => {
36
+ for (let i = 0; i < cleanups.length; i++) {
37
+ const cleanup = cleanups[i];
38
+ if (typeof cleanup === "function") {
39
+ cleanup();
40
+ } else {
41
+ setRef(refs[i], null);
42
+ }
43
+ }
44
+ };
45
+ }
46
+ };
47
+ }
48
+ __name(composeRefs, "composeRefs");
49
+ function useComposedRefs(...refs) {
50
+ return React.useCallback(composeRefs(...refs), refs);
51
+ }
52
+ __name(useComposedRefs, "useComposedRefs");
53
+
54
+ // src/utils/use-mobile.tsx
55
+ import * as React2 from "react";
56
+ var MOBILE_BREAKPOINT = 768;
57
+ function useIsMobile() {
58
+ const [isMobile, setIsMobile] = React2.useState(void 0);
59
+ React2.useEffect(() => {
60
+ const mql = window.matchMedia(`(max-width: ${MOBILE_BREAKPOINT - 1}px)`);
61
+ const onChange = /* @__PURE__ */ __name(() => {
62
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
63
+ }, "onChange");
64
+ mql.addEventListener("change", onChange);
65
+ setIsMobile(window.innerWidth < MOBILE_BREAKPOINT);
66
+ return () => mql.removeEventListener("change", onChange);
67
+ }, []);
68
+ return !!isMobile;
69
+ }
70
+ __name(useIsMobile, "useIsMobile");
71
+
72
+ // src/utils/date-formatter.ts
73
+ var formatDate = /* @__PURE__ */ __name((eventDate, formatOption) => {
74
+ const browserLocale = navigator.language || "en-US";
75
+ const formatPart = /* @__PURE__ */ __name((date, options) => new Intl.DateTimeFormat(browserLocale, options).format(date), "formatPart");
76
+ const now = /* @__PURE__ */ new Date();
77
+ const diff = now.getTime() - eventDate.getTime();
78
+ if (formatOption === "default") {
79
+ if (diff < 24 * 60 * 60 * 1e3) formatOption = "timeSince";
80
+ else formatOption = "dateTime";
81
+ }
82
+ if (formatOption === "timeSince") {
83
+ const seconds = Math.floor(diff / 1e3);
84
+ const minutes = Math.floor(seconds / 60);
85
+ const hours = Math.floor(minutes / 60);
86
+ const days = Math.floor(hours / 24);
87
+ if (days > 0) return `${days} days ago`;
88
+ if (hours > 0) return `${hours} hours ago`;
89
+ if (minutes > 0) return `${minutes} minutes ago`;
90
+ return `${seconds} seconds ago`;
91
+ }
92
+ const dateOptions = {
93
+ year: "numeric",
94
+ month: "2-digit",
95
+ day: "2-digit"
96
+ };
97
+ const timeOptions = {
98
+ hour: "2-digit",
99
+ minute: "2-digit"
100
+ };
101
+ switch (formatOption) {
102
+ case "date":
103
+ return formatPart(eventDate, dateOptions);
104
+ case "time":
105
+ return formatPart(eventDate, timeOptions);
106
+ case "dateTime":
107
+ return `${formatPart(eventDate, dateOptions)} ${formatPart(eventDate, timeOptions)}`;
108
+ default:
109
+ throw new Error("Invalid format option");
110
+ }
111
+ }, "formatDate");
112
+
113
+ // src/utils/exists.ts
114
+ var exists = /* @__PURE__ */ __name((itemOrArray) => {
115
+ if (!itemOrArray) return false;
116
+ if (Array.isArray(itemOrArray)) {
117
+ return itemOrArray.length > 0;
118
+ }
119
+ return true;
120
+ }, "exists");
121
+
122
+ // src/utils/table-options.ts
123
+ import { cloneElement, createElement, Fragment } from "react";
124
+ var TableOptions = class {
125
+ static {
126
+ __name(this, "TableOptions");
127
+ }
128
+ _components;
129
+ _hasPermissionToModule;
130
+ constructor(hasPermissionToModule) {
131
+ this._hasPermissionToModule = hasPermissionToModule;
132
+ this._components = [];
133
+ }
134
+ addOption(component, module, action) {
135
+ if (!component || module && action && !this._hasPermissionToModule({ module, action })) return;
136
+ this._components.push(component);
137
+ }
138
+ getComponents() {
139
+ return this._components;
140
+ }
141
+ getOptions() {
142
+ if (this._components.length === 0) return null;
143
+ const response = this._components.map(
144
+ (option, index) => cloneElement(option, { key: option.key ?? index })
145
+ );
146
+ return createElement(Fragment, {}, response);
147
+ }
148
+ };
149
+ function getTableOptions(params) {
150
+ const tableOptions = new TableOptions(params.hasPermissionToModule);
151
+ params.options.forEach((option) => tableOptions.addOption(option.component, option.module, option.action));
152
+ return tableOptions.getOptions();
153
+ }
154
+ __name(getTableOptions, "getTableOptions");
155
+ function getTableComponents(params) {
156
+ const tableOptions = new TableOptions(params.hasPermissionToModule);
157
+ params.options.forEach((option) => tableOptions.addOption(option.component, option.module, option.action));
158
+ return tableOptions.getComponents();
159
+ }
160
+ __name(getTableComponents, "getTableComponents");
161
+
162
+ // src/utils/schemas/user.object.schema.ts
163
+ import { z } from "zod";
164
+ var userObjectSchema = z.object({
165
+ id: z.string(),
166
+ name: z.string(),
167
+ avatar: z.string().optional()
168
+ });
169
+
170
+ // src/utils/schemas/entity.object.schema.ts
171
+ import { z as z2 } from "zod";
172
+ var entityObjectSchema = z2.object({
173
+ id: z2.uuidv4(),
174
+ name: z2.string()
175
+ });
176
+
177
+ // src/utils/blocknote-diff.util.ts
178
+ var BlockNoteDiffUtil = class {
179
+ static {
180
+ __name(this, "BlockNoteDiffUtil");
181
+ }
182
+ static DEFAULT_OPTIONS = {
183
+ ignoreIds: false,
184
+ compareContent: true,
185
+ similarityThreshold: 0.8
186
+ };
187
+ /**
188
+ * Compare two BlockNote documents and return diff result
189
+ */
190
+ static diff(originalBlocks = [], newBlocks = [], options = {}) {
191
+ const opts = { ...this.DEFAULT_OPTIONS, ...options };
192
+ const originalMap = /* @__PURE__ */ new Map();
193
+ const newMap = /* @__PURE__ */ new Map();
194
+ originalBlocks.forEach((block) => {
195
+ if (block.id) {
196
+ originalMap.set(block.id, block);
197
+ }
198
+ });
199
+ newBlocks.forEach((block) => {
200
+ if (block.id) {
201
+ newMap.set(block.id, block);
202
+ }
203
+ });
204
+ const diffBlocks = [];
205
+ const processedNewIds = /* @__PURE__ */ new Set();
206
+ for (const originalBlock of originalBlocks) {
207
+ const blockId = originalBlock.id;
208
+ const processId = blockId || crypto.randomUUID();
209
+ const newBlock = blockId ? newMap.get(blockId) : null;
210
+ if (!newBlock) {
211
+ const removedBlock = {
212
+ ...originalBlock,
213
+ id: processId,
214
+ diffType: "removed",
215
+ diffId: `removed-${processId}`
216
+ };
217
+ diffBlocks.push(removedBlock);
218
+ } else {
219
+ if (blockId) {
220
+ processedNewIds.add(blockId);
221
+ }
222
+ if (this.areBlocksEqual(originalBlock, newBlock, opts)) {
223
+ const unchangedBlock = {
224
+ ...newBlock,
225
+ diffType: "unchanged"
226
+ };
227
+ diffBlocks.push(unchangedBlock);
228
+ } else {
229
+ const wordDiffs = this.generateWordDiffs(originalBlock.content, newBlock.content, processId);
230
+ const modifiedBlock = {
231
+ ...newBlock,
232
+ diffType: "modified",
233
+ originalContent: originalBlock.content,
234
+ diffId: `modified-${processId}`,
235
+ wordDiffs
236
+ };
237
+ diffBlocks.push(modifiedBlock);
238
+ }
239
+ }
240
+ }
241
+ for (const newBlock of newBlocks) {
242
+ const blockId = newBlock.id;
243
+ if (blockId && processedNewIds.has(blockId)) continue;
244
+ const generatedId = blockId || crypto.randomUUID();
245
+ const addedBlock = {
246
+ ...newBlock,
247
+ id: generatedId,
248
+ diffType: "added",
249
+ diffId: `added-${generatedId}`
250
+ };
251
+ diffBlocks.push(addedBlock);
252
+ }
253
+ const sortedDiffBlocks = this.sortDiffBlocks(diffBlocks, originalBlocks, newBlocks);
254
+ return {
255
+ blocks: sortedDiffBlocks,
256
+ hasChanges: sortedDiffBlocks.some((block) => block.diffType !== "unchanged")
257
+ };
258
+ }
259
+ /**
260
+ * Compare two blocks for equality
261
+ */
262
+ static areBlocksEqual(block1, block2, options) {
263
+ if (block1.type !== block2.type) {
264
+ return false;
265
+ }
266
+ if (!this.deepEqual(block1.props, block2.props)) {
267
+ return false;
268
+ }
269
+ if (options.compareContent) {
270
+ if (!this.deepEqual(block1.content, block2.content)) {
271
+ return false;
272
+ }
273
+ }
274
+ const children1 = block1.children || [];
275
+ const children2 = block2.children || [];
276
+ if (children1.length !== children2.length) {
277
+ return false;
278
+ }
279
+ for (let i = 0; i < children1.length; i++) {
280
+ if (!this.areBlocksEqual(children1[i], children2[i], options)) {
281
+ return false;
282
+ }
283
+ }
284
+ return true;
285
+ }
286
+ /**
287
+ * Deep equality comparison for objects
288
+ */
289
+ static deepEqual(obj1, obj2) {
290
+ if (obj1 === obj2) return true;
291
+ if (obj1 == null || obj2 == null) return obj1 === obj2;
292
+ if (typeof obj1 !== typeof obj2) return false;
293
+ if (typeof obj1 !== "object") return obj1 === obj2;
294
+ if (Array.isArray(obj1) !== Array.isArray(obj2)) return false;
295
+ if (Array.isArray(obj1)) {
296
+ if (obj1.length !== obj2.length) return false;
297
+ for (let i = 0; i < obj1.length; i++) {
298
+ if (!this.deepEqual(obj1[i], obj2[i])) return false;
299
+ }
300
+ return true;
301
+ }
302
+ const keys1 = Object.keys(obj1);
303
+ const keys2 = Object.keys(obj2);
304
+ if (keys1.length !== keys2.length) return false;
305
+ for (const key of keys1) {
306
+ if (!keys2.includes(key)) return false;
307
+ if (!this.deepEqual(obj1[key], obj2[key])) return false;
308
+ }
309
+ return true;
310
+ }
311
+ /**
312
+ * Sort diff blocks to maintain logical order
313
+ */
314
+ static sortDiffBlocks(diffBlocks, originalBlocks, newBlocks) {
315
+ const originalPositions = /* @__PURE__ */ new Map();
316
+ const newPositions = /* @__PURE__ */ new Map();
317
+ originalBlocks.forEach((block, index) => {
318
+ if (block.id) {
319
+ originalPositions.set(block.id, index);
320
+ }
321
+ });
322
+ newBlocks.forEach((block, index) => {
323
+ if (block.id) {
324
+ newPositions.set(block.id, index);
325
+ }
326
+ });
327
+ return diffBlocks.sort((a, b) => {
328
+ const aId = a.id;
329
+ const bId = b.id;
330
+ if (!aId || !bId) return 0;
331
+ const aPos = newPositions.get(aId) ?? originalPositions.get(aId) ?? Infinity;
332
+ const bPos = newPositions.get(bId) ?? originalPositions.get(bId) ?? Infinity;
333
+ return aPos - bPos;
334
+ });
335
+ }
336
+ /**
337
+ * Calculate similarity between two text contents
338
+ */
339
+ static calculateSimilarity(content1, content2) {
340
+ if (!content1 || !content2) return 0;
341
+ const text1 = this.extractTextFromContent(content1);
342
+ const text2 = this.extractTextFromContent(content2);
343
+ if (text1 === text2) return 1;
344
+ if (!text1 || !text2) return 0;
345
+ const maxLength = Math.max(text1.length, text2.length);
346
+ const distance = this.levenshteinDistance(text1, text2);
347
+ return 1 - distance / maxLength;
348
+ }
349
+ /**
350
+ * Extract plain text from BlockNote content array
351
+ */
352
+ static extractTextFromContent(content) {
353
+ if (!Array.isArray(content)) return "";
354
+ return content.map((item) => {
355
+ if (item.type === "text") {
356
+ return item.text || "";
357
+ }
358
+ return "";
359
+ }).join("");
360
+ }
361
+ /**
362
+ * Calculate Levenshtein distance between two strings
363
+ */
364
+ static levenshteinDistance(str1, str2) {
365
+ const matrix = Array(str2.length + 1).fill(null).map(() => Array(str1.length + 1).fill(null));
366
+ for (let i = 0; i <= str1.length; i++) {
367
+ matrix[0][i] = i;
368
+ }
369
+ for (let j = 0; j <= str2.length; j++) {
370
+ matrix[j][0] = j;
371
+ }
372
+ for (let j = 1; j <= str2.length; j++) {
373
+ for (let i = 1; i <= str1.length; i++) {
374
+ const substitutionCost = str1[i - 1] === str2[j - 1] ? 0 : 1;
375
+ matrix[j][i] = Math.min(
376
+ matrix[j][i - 1] + 1,
377
+ // deletion
378
+ matrix[j - 1][i] + 1,
379
+ // insertion
380
+ matrix[j - 1][i - 1] + substitutionCost
381
+ // substitution
382
+ );
383
+ }
384
+ }
385
+ return matrix[str2.length][str1.length];
386
+ }
387
+ /**
388
+ * Generate word-level diffs between two content arrays
389
+ */
390
+ static generateWordDiffs(originalContent, newContent, blockId) {
391
+ const originalText = this.extractTextFromContent(originalContent || []);
392
+ const newText = this.extractTextFromContent(newContent || []);
393
+ if (!originalText && !newText) return [];
394
+ if (!originalText) {
395
+ return newText.split(/\s+/).filter((word) => word.trim()).map((word, index) => ({
396
+ type: "added",
397
+ text: word,
398
+ diffId: `${blockId}-add-${index}`,
399
+ accepted: false,
400
+ rejected: false
401
+ }));
402
+ }
403
+ if (!newText) {
404
+ return originalText.split(/\s+/).filter((word) => word.trim()).map((word, index) => ({
405
+ type: "removed",
406
+ text: word,
407
+ diffId: `${blockId}-remove-${index}`,
408
+ accepted: false,
409
+ rejected: false
410
+ }));
411
+ }
412
+ return this.diffWords(originalText, newText, blockId);
413
+ }
414
+ /**
415
+ * Perform word-level diff using word-only approach (no space tokenization)
416
+ */
417
+ static diffWords(text1, text2, blockId) {
418
+ const words1 = text1.split(/\s+/).filter((word) => word.length > 0);
419
+ const words2 = text2.split(/\s+/).filter((word) => word.length > 0);
420
+ const diffs = this.myersDiff(words1, words2);
421
+ const consolidatedDiffs = this.consolidateAdjacentChanges(diffs);
422
+ const result = [];
423
+ let diffIndex = 0;
424
+ for (let i = 0; i < consolidatedDiffs.length; i++) {
425
+ const diff = consolidatedDiffs[i];
426
+ const isLastDiff = i === consolidatedDiffs.length - 1;
427
+ switch (diff.type) {
428
+ case "equal":
429
+ result.push({
430
+ type: "unchanged",
431
+ text: diff.value,
432
+ diffId: `${blockId}-unchanged-${diffIndex++}`,
433
+ accepted: true,
434
+ rejected: false
435
+ });
436
+ if (!isLastDiff) {
437
+ result.push({
438
+ type: "unchanged",
439
+ text: " ",
440
+ diffId: `${blockId}-space-${diffIndex++}`,
441
+ accepted: true,
442
+ rejected: false
443
+ });
444
+ }
445
+ break;
446
+ case "delete":
447
+ if (diff.consolidated) {
448
+ const nextDiff = i + 1 < consolidatedDiffs.length ? consolidatedDiffs[i + 1] : null;
449
+ const isConsolidatedReplacement = nextDiff && nextDiff.type === "insert" && nextDiff.consolidated;
450
+ if (isConsolidatedReplacement) {
451
+ const replacementId = `${blockId}-replace-${diffIndex++}`;
452
+ result.push({
453
+ type: "removed",
454
+ text: diff.value,
455
+ diffId: replacementId,
456
+ accepted: false,
457
+ rejected: false
458
+ });
459
+ result.push({
460
+ type: "added",
461
+ text: nextDiff.value,
462
+ diffId: replacementId,
463
+ accepted: false,
464
+ rejected: false
465
+ });
466
+ i++;
467
+ if (i < consolidatedDiffs.length - 1) {
468
+ result.push({
469
+ type: "unchanged",
470
+ text: " ",
471
+ diffId: `${blockId}-space-${diffIndex++}`,
472
+ accepted: true,
473
+ rejected: false
474
+ });
475
+ }
476
+ } else {
477
+ result.push({
478
+ type: "removed",
479
+ text: diff.value,
480
+ diffId: `${blockId}-remove-${diffIndex++}`,
481
+ accepted: false,
482
+ rejected: false
483
+ });
484
+ if (!isLastDiff) {
485
+ result.push({
486
+ type: "unchanged",
487
+ text: " ",
488
+ diffId: `${blockId}-space-${diffIndex++}`,
489
+ accepted: true,
490
+ rejected: false
491
+ });
492
+ }
493
+ }
494
+ } else {
495
+ const nextDiff = i + 1 < consolidatedDiffs.length ? consolidatedDiffs[i + 1] : null;
496
+ const isReplacement = nextDiff && nextDiff.type === "insert" && this.areWordsSimilar(diff.value, nextDiff.value);
497
+ if (isReplacement) {
498
+ const replacementId = `${blockId}-replace-${diffIndex++}`;
499
+ result.push({
500
+ type: "removed",
501
+ text: diff.value,
502
+ diffId: replacementId,
503
+ accepted: false,
504
+ rejected: false
505
+ });
506
+ result.push({
507
+ type: "added",
508
+ text: nextDiff.value,
509
+ diffId: replacementId,
510
+ accepted: false,
511
+ rejected: false
512
+ });
513
+ i++;
514
+ if (i < consolidatedDiffs.length - 1) {
515
+ result.push({
516
+ type: "unchanged",
517
+ text: " ",
518
+ diffId: `${blockId}-space-${diffIndex++}`,
519
+ accepted: true,
520
+ rejected: false
521
+ });
522
+ }
523
+ } else {
524
+ result.push({
525
+ type: "removed",
526
+ text: diff.value,
527
+ diffId: `${blockId}-remove-${diffIndex++}`,
528
+ accepted: false,
529
+ rejected: false
530
+ });
531
+ if (!isLastDiff) {
532
+ result.push({
533
+ type: "unchanged",
534
+ text: " ",
535
+ diffId: `${blockId}-space-${diffIndex++}`,
536
+ accepted: true,
537
+ rejected: false
538
+ });
539
+ }
540
+ }
541
+ }
542
+ break;
543
+ case "insert":
544
+ if (diff.consolidated) {
545
+ const prevDiff = i > 0 ? consolidatedDiffs[i - 1] : null;
546
+ const wasProcessedAsConsolidatedReplacement = prevDiff && prevDiff.type === "delete" && prevDiff.consolidated;
547
+ if (!wasProcessedAsConsolidatedReplacement) {
548
+ result.push({
549
+ type: "added",
550
+ text: diff.value,
551
+ diffId: `${blockId}-add-${diffIndex++}`,
552
+ accepted: false,
553
+ rejected: false
554
+ });
555
+ if (!isLastDiff) {
556
+ result.push({
557
+ type: "unchanged",
558
+ text: " ",
559
+ diffId: `${blockId}-space-${diffIndex++}`,
560
+ accepted: true,
561
+ rejected: false
562
+ });
563
+ }
564
+ }
565
+ } else {
566
+ const prevDiff = i > 0 ? consolidatedDiffs[i - 1] : null;
567
+ const wasProcessedAsReplacement = prevDiff && prevDiff.type === "delete" && this.areWordsSimilar(prevDiff.value, diff.value);
568
+ if (!wasProcessedAsReplacement) {
569
+ result.push({
570
+ type: "added",
571
+ text: diff.value,
572
+ diffId: `${blockId}-add-${diffIndex++}`,
573
+ accepted: false,
574
+ rejected: false
575
+ });
576
+ if (!isLastDiff) {
577
+ result.push({
578
+ type: "unchanged",
579
+ text: " ",
580
+ diffId: `${blockId}-space-${diffIndex++}`,
581
+ accepted: true,
582
+ rejected: false
583
+ });
584
+ }
585
+ }
586
+ }
587
+ break;
588
+ }
589
+ }
590
+ return result;
591
+ }
592
+ /**
593
+ * Improved diff algorithm that better handles word insertions
594
+ * Uses a combination of LCS and heuristics to minimize false changes
595
+ */
596
+ static myersDiff(a, b) {
597
+ if (a.length === 0) {
598
+ return b.map((value) => ({ type: "insert", value }));
599
+ }
600
+ if (b.length === 0) {
601
+ return a.map((value) => ({ type: "delete", value }));
602
+ }
603
+ const dp = this.computeEditScript(a, b);
604
+ return this.reconstructDiff(a, b, dp);
605
+ }
606
+ /**
607
+ * Compute edit script using dynamic programming
608
+ */
609
+ static computeEditScript(a, b) {
610
+ const m = a.length;
611
+ const n = b.length;
612
+ const dp = Array(m + 1).fill(null).map(() => Array(n + 1).fill(0));
613
+ for (let i = 0; i <= m; i++) dp[i][0] = i;
614
+ for (let j = 0; j <= n; j++) dp[0][j] = j;
615
+ for (let i = 1; i <= m; i++) {
616
+ for (let j = 1; j <= n; j++) {
617
+ if (a[i - 1] === b[j - 1]) {
618
+ dp[i][j] = dp[i - 1][j - 1];
619
+ } else {
620
+ dp[i][j] = 1 + Math.min(
621
+ dp[i - 1][j],
622
+ // Delete from a
623
+ dp[i][j - 1],
624
+ // Insert into a
625
+ dp[i - 1][j - 1]
626
+ // Replace
627
+ );
628
+ }
629
+ }
630
+ }
631
+ return dp;
632
+ }
633
+ /**
634
+ * Reconstruct the actual diff from the DP table
635
+ */
636
+ static reconstructDiff(a, b, dp) {
637
+ const result = [];
638
+ let i = a.length;
639
+ let j = b.length;
640
+ while (i > 0 || j > 0) {
641
+ if (i > 0 && j > 0 && a[i - 1] === b[j - 1]) {
642
+ result.unshift({ type: "equal", value: a[i - 1] });
643
+ i--;
644
+ j--;
645
+ } else {
646
+ const deleteCost = i > 0 ? dp[i - 1][j] : Infinity;
647
+ const insertCost = j > 0 ? dp[i][j - 1] : Infinity;
648
+ const replaceCost = i > 0 && j > 0 ? dp[i - 1][j - 1] : Infinity;
649
+ const minCost = Math.min(deleteCost, insertCost, replaceCost);
650
+ if (minCost === insertCost && j > 0) {
651
+ result.unshift({ type: "insert", value: b[j - 1] });
652
+ j--;
653
+ } else if (minCost === deleteCost && i > 0) {
654
+ result.unshift({ type: "delete", value: a[i - 1] });
655
+ i--;
656
+ } else if (minCost === replaceCost && i > 0 && j > 0) {
657
+ if (this.areWordsSimilar(a[i - 1], b[j - 1])) {
658
+ result.unshift({ type: "insert", value: b[j - 1], sharedDiffId: true });
659
+ result.unshift({ type: "delete", value: a[i - 1], sharedDiffId: true });
660
+ i--;
661
+ j--;
662
+ } else {
663
+ result.unshift({ type: "insert", value: b[j - 1] });
664
+ j--;
665
+ }
666
+ }
667
+ }
668
+ }
669
+ return result;
670
+ }
671
+ /**
672
+ * Consolidate adjacent changes to reduce fragmentation
673
+ * e.g., if we have: delete "Key", insert "Key!", delete "Challenges"
674
+ * We can consolidate this into: replace ["Key", "Challenges"] with ["Key!"]
675
+ */
676
+ static consolidateAdjacentChanges(diffs) {
677
+ const result = [];
678
+ let i = 0;
679
+ while (i < diffs.length) {
680
+ const current = diffs[i];
681
+ if (current.type === "equal") {
682
+ result.push(current);
683
+ i++;
684
+ continue;
685
+ }
686
+ const changeSequence = [];
687
+ let j = i;
688
+ while (j < diffs.length && diffs[j].type !== "equal") {
689
+ changeSequence.push(diffs[j]);
690
+ j++;
691
+ }
692
+ if (changeSequence.length <= 1) {
693
+ result.push(current);
694
+ i++;
695
+ continue;
696
+ }
697
+ const shouldConsolidate = this.shouldConsolidateChanges(
698
+ changeSequence
699
+ );
700
+ if (shouldConsolidate) {
701
+ const deletedWords = changeSequence.filter((c) => c.type === "delete").map((c) => c.value);
702
+ const insertedWords = changeSequence.filter((c) => c.type === "insert").map((c) => c.value);
703
+ if (deletedWords.length > 0) {
704
+ result.push({
705
+ type: "delete",
706
+ value: deletedWords.join(" "),
707
+ consolidated: true
708
+ });
709
+ }
710
+ if (insertedWords.length > 0) {
711
+ result.push({
712
+ type: "insert",
713
+ value: insertedWords.join(" "),
714
+ consolidated: true
715
+ });
716
+ }
717
+ } else {
718
+ changeSequence.forEach((change) => result.push(change));
719
+ }
720
+ i = j;
721
+ }
722
+ return result;
723
+ }
724
+ /**
725
+ * Determine if a sequence of changes should be consolidated
726
+ */
727
+ static shouldConsolidateChanges(changes) {
728
+ const hasDeletes = changes.some((c) => c.type === "delete");
729
+ const hasInserts = changes.some((c) => c.type === "insert");
730
+ return hasDeletes && hasInserts;
731
+ }
732
+ /**
733
+ * Check if two words are similar enough to be considered a replacement
734
+ */
735
+ static areWordsSimilar(word1, word2) {
736
+ if (word1 === word2) return true;
737
+ const maxLen = Math.max(word1.length, word2.length);
738
+ const minLen = Math.min(word1.length, word2.length);
739
+ if (maxLen > minLen * 2) {
740
+ return false;
741
+ }
742
+ const word1Clean = word1.replace(/[^\w]/g, "");
743
+ const word2Clean = word2.replace(/[^\w]/g, "");
744
+ if (word1Clean === word2Clean && word1 !== word2) {
745
+ return false;
746
+ }
747
+ const distance = this.levenshteinDistance(word1, word2);
748
+ const similarity = 1 - distance / maxLen;
749
+ return similarity > 0.7;
750
+ }
751
+ };
752
+
753
+ // src/utils/blocknote-word-diff-renderer.util.ts
754
+ var BlockNoteWordDiffRendererUtil = class {
755
+ static {
756
+ __name(this, "BlockNoteWordDiffRendererUtil");
757
+ }
758
+ static renderWordDiffs(diffBlocks, onAcceptChange, onRejectChange, acceptedChanges, rejectedChanges) {
759
+ if (acceptedChanges || rejectedChanges) {
760
+ diffBlocks = this.updateWordDiffStates(diffBlocks, acceptedChanges, rejectedChanges);
761
+ }
762
+ return diffBlocks.map((block) => this.renderDiffBlock(block, onAcceptChange, onRejectChange));
763
+ }
764
+ static updateWordDiffStates(diffBlocks, acceptedChanges, rejectedChanges) {
765
+ return diffBlocks.map((block) => {
766
+ const updatedBlock = { ...block };
767
+ if (updatedBlock.diffId) {
768
+ updatedBlock.accepted = acceptedChanges?.has(updatedBlock.diffId) || false;
769
+ updatedBlock.rejected = rejectedChanges?.has(updatedBlock.diffId) || false;
770
+ }
771
+ if (updatedBlock.wordDiffs) {
772
+ updatedBlock.wordDiffs = updatedBlock.wordDiffs.map((wordDiff) => ({
773
+ ...wordDiff,
774
+ accepted: acceptedChanges?.has(wordDiff.diffId) || false,
775
+ rejected: rejectedChanges?.has(wordDiff.diffId) || false
776
+ }));
777
+ }
778
+ if (updatedBlock.children) {
779
+ updatedBlock.children = this.updateWordDiffStates(
780
+ updatedBlock.children,
781
+ acceptedChanges,
782
+ rejectedChanges
783
+ );
784
+ }
785
+ return updatedBlock;
786
+ });
787
+ }
788
+ static renderDiffBlock(block, onAcceptChange, onRejectChange) {
789
+ if (block.diffType === "modified" && block.wordDiffs) {
790
+ return this.renderWordLevelDiff(block, onAcceptChange, onRejectChange);
791
+ }
792
+ if (block.diffType === "added" || block.diffType === "removed") {
793
+ return this.renderBlockLevelDiff(block, onAcceptChange, onRejectChange);
794
+ }
795
+ const baseBlock = {
796
+ id: block.id || crypto.randomUUID(),
797
+ type: block.type || "paragraph",
798
+ props: this.getBlockProps(block),
799
+ content: Array.isArray(block.content) ? block.content : [],
800
+ children: block.children?.map(
801
+ (child) => this.renderDiffBlock(child, onAcceptChange, onRejectChange)
802
+ )
803
+ };
804
+ return baseBlock;
805
+ }
806
+ static renderBlockLevelDiff(block, onAcceptChange, onRejectChange) {
807
+ if (!block.diffId) {
808
+ return {
809
+ id: block.id || crypto.randomUUID(),
810
+ type: block.type || "paragraph",
811
+ props: block.props || {},
812
+ content: Array.isArray(block.content) ? block.content : [],
813
+ children: block.children?.map(
814
+ (child) => this.renderDiffBlock(child, onAcceptChange, onRejectChange)
815
+ )
816
+ };
817
+ }
818
+ const blockAccepted = block.accepted || false;
819
+ const blockRejected = block.rejected || false;
820
+ let content = Array.isArray(block.content) ? [...block.content] : [];
821
+ if (block.diffType === "added") {
822
+ if (blockRejected) {
823
+ return {
824
+ id: block.id || crypto.randomUUID(),
825
+ type: "paragraph",
826
+ props: {},
827
+ content: [],
828
+ children: []
829
+ };
830
+ } else if (!blockAccepted) {
831
+ content = content.map((item) => ({
832
+ ...item,
833
+ styles: { ...item.styles, bold: true }
834
+ }));
835
+ content.push({
836
+ type: "diffActions",
837
+ props: { diffIds: block.diffId }
838
+ });
839
+ }
840
+ } else if (block.diffType === "removed") {
841
+ if (blockAccepted) {
842
+ return {
843
+ id: block.id || crypto.randomUUID(),
844
+ type: "paragraph",
845
+ props: {},
846
+ content: [],
847
+ children: []
848
+ };
849
+ } else if (!blockRejected) {
850
+ content = content.map((item) => ({
851
+ ...item,
852
+ styles: { ...item.styles, strike: true }
853
+ }));
854
+ content.push({
855
+ type: "diffActions",
856
+ props: { diffIds: block.diffId }
857
+ });
858
+ }
859
+ }
860
+ const baseBlock = {
861
+ id: block.id || crypto.randomUUID(),
862
+ type: block.type || "paragraph",
863
+ props: this.getBlockProps(block),
864
+ content,
865
+ children: block.children?.map(
866
+ (child) => this.renderDiffBlock(child, onAcceptChange, onRejectChange)
867
+ )
868
+ };
869
+ return baseBlock;
870
+ }
871
+ static renderWordLevelDiff(block, onAcceptChange, onRejectChange) {
872
+ if (!block.wordDiffs) {
873
+ return {
874
+ id: block.id || crypto.randomUUID(),
875
+ type: block.type || "paragraph",
876
+ props: block.props || {},
877
+ content: Array.isArray(block.content) ? block.content : [],
878
+ children: []
879
+ };
880
+ }
881
+ const content = this.groupAndRenderWordDiffs(block.wordDiffs);
882
+ return {
883
+ id: block.id || crypto.randomUUID(),
884
+ type: block.type || "paragraph",
885
+ props: block.props || {},
886
+ content: Array.isArray(content) ? content : [],
887
+ children: block.children?.map((child) => this.renderDiffBlock(child, onAcceptChange, onRejectChange)) || []
888
+ };
889
+ }
890
+ static groupAndRenderWordDiffs(wordDiffs) {
891
+ const content = [];
892
+ for (let i = 0; i < wordDiffs.length; i++) {
893
+ const wordDiff = wordDiffs[i];
894
+ const isLastOfGroup = this.isLastDiffInGroup(wordDiffs, i);
895
+ const textContent = this.createTextContent(wordDiff, isLastOfGroup);
896
+ if (textContent) {
897
+ if (Array.isArray(textContent)) {
898
+ content.push(...textContent);
899
+ } else {
900
+ content.push(textContent);
901
+ }
902
+ }
903
+ }
904
+ const cleanedContent = this.cleanupSpaces(content);
905
+ return cleanedContent;
906
+ }
907
+ static cleanupSpaces(content) {
908
+ const filtered = content.filter((item) => item !== null && item !== void 0);
909
+ const cleaned = [];
910
+ for (let i = 0; i < filtered.length; i++) {
911
+ const current = filtered[i];
912
+ if (current.type === "text" && current.text === " ") {
913
+ const lastItem = cleaned[cleaned.length - 1];
914
+ if (i === 0 || i === filtered.length - 1 || lastItem && lastItem.type === "text" && lastItem.text === " " || lastItem && lastItem.type === "diffActions") {
915
+ continue;
916
+ }
917
+ }
918
+ if (current.type === "diffActions") {
919
+ const nextItem = i + 1 < filtered.length ? filtered[i + 1] : null;
920
+ cleaned.push(current);
921
+ if (nextItem && nextItem.type === "text" && nextItem.text !== " " && nextItem.type !== "diffActions") {
922
+ cleaned.push({
923
+ type: "text",
924
+ text: " ",
925
+ styles: {}
926
+ });
927
+ }
928
+ continue;
929
+ }
930
+ cleaned.push(current);
931
+ }
932
+ return cleaned;
933
+ }
934
+ static isLastDiffInGroup(wordDiffs, currentIndex) {
935
+ const currentDiff = wordDiffs[currentIndex];
936
+ if (currentDiff.type === "unchanged") {
937
+ return false;
938
+ }
939
+ for (let i = currentIndex + 1; i < wordDiffs.length; i++) {
940
+ const nextDiff = wordDiffs[i];
941
+ if (nextDiff.diffId === currentDiff.diffId && (nextDiff.type === "added" || nextDiff.type === "removed")) {
942
+ return false;
943
+ }
944
+ if (nextDiff.type !== "unchanged" && nextDiff.diffId !== currentDiff.diffId) {
945
+ break;
946
+ }
947
+ }
948
+ return true;
949
+ }
950
+ static createTextContent(wordDiff, isLastOfGroup) {
951
+ switch (wordDiff.type) {
952
+ case "added":
953
+ if (wordDiff.accepted) {
954
+ return {
955
+ type: "text",
956
+ text: wordDiff.text,
957
+ styles: {}
958
+ };
959
+ } else if (wordDiff.rejected) {
960
+ return null;
961
+ } else {
962
+ if (wordDiff.text.trim() === "") {
963
+ return {
964
+ type: "text",
965
+ text: wordDiff.text,
966
+ styles: { backgroundColor: "#dcfce7" }
967
+ };
968
+ } else {
969
+ const baseContent = {
970
+ type: "text",
971
+ text: wordDiff.text,
972
+ styles: { bold: true }
973
+ };
974
+ if (isLastOfGroup) {
975
+ return [
976
+ baseContent,
977
+ {
978
+ type: "diffActions",
979
+ props: { diffIds: wordDiff.diffId }
980
+ }
981
+ ];
982
+ } else {
983
+ return baseContent;
984
+ }
985
+ }
986
+ }
987
+ case "removed":
988
+ if (wordDiff.accepted) {
989
+ return null;
990
+ } else if (wordDiff.rejected) {
991
+ return {
992
+ type: "text",
993
+ text: wordDiff.text,
994
+ styles: {}
995
+ };
996
+ } else {
997
+ if (wordDiff.text.trim() === "") {
998
+ return {
999
+ type: "text",
1000
+ text: wordDiff.text,
1001
+ styles: { strike: true }
1002
+ };
1003
+ } else {
1004
+ const baseContent = {
1005
+ type: "text",
1006
+ text: wordDiff.text,
1007
+ styles: { strike: true }
1008
+ };
1009
+ if (isLastOfGroup) {
1010
+ return [
1011
+ baseContent,
1012
+ {
1013
+ type: "diffActions",
1014
+ props: { diffIds: wordDiff.diffId }
1015
+ }
1016
+ ];
1017
+ } else {
1018
+ return baseContent;
1019
+ }
1020
+ }
1021
+ }
1022
+ case "unchanged":
1023
+ default:
1024
+ return {
1025
+ type: "text",
1026
+ text: wordDiff.text,
1027
+ styles: {}
1028
+ };
1029
+ }
1030
+ }
1031
+ static getBlockProps(block) {
1032
+ const baseProps = block.props || {};
1033
+ return baseProps;
1034
+ }
1035
+ static generateChangeSummary(diffBlocks) {
1036
+ let totalWords = 0;
1037
+ let addedWords = 0;
1038
+ let removedWords = 0;
1039
+ let acceptedChanges = 0;
1040
+ let rejectedChanges = 0;
1041
+ let pendingChanges = 0;
1042
+ const processBlock = /* @__PURE__ */ __name((block) => {
1043
+ if (block.wordDiffs) {
1044
+ block.wordDiffs.forEach((wordDiff) => {
1045
+ totalWords++;
1046
+ if (wordDiff.type === "added") {
1047
+ addedWords++;
1048
+ } else if (wordDiff.type === "removed") {
1049
+ removedWords++;
1050
+ }
1051
+ if (wordDiff.accepted) {
1052
+ acceptedChanges++;
1053
+ } else if (wordDiff.rejected) {
1054
+ rejectedChanges++;
1055
+ } else if (wordDiff.type !== "unchanged") {
1056
+ pendingChanges++;
1057
+ }
1058
+ });
1059
+ }
1060
+ if (block.children) {
1061
+ block.children.forEach((child) => processBlock(child));
1062
+ }
1063
+ }, "processBlock");
1064
+ diffBlocks.forEach(processBlock);
1065
+ return {
1066
+ totalWords,
1067
+ addedWords,
1068
+ removedWords,
1069
+ acceptedChanges,
1070
+ rejectedChanges,
1071
+ pendingChanges
1072
+ };
1073
+ }
1074
+ };
1075
+
1076
+ export {
1077
+ cn,
1078
+ composeRefs,
1079
+ useComposedRefs,
1080
+ useIsMobile,
1081
+ formatDate,
1082
+ exists,
1083
+ TableOptions,
1084
+ getTableOptions,
1085
+ getTableComponents,
1086
+ userObjectSchema,
1087
+ entityObjectSchema,
1088
+ BlockNoteDiffUtil,
1089
+ BlockNoteWordDiffRendererUtil
1090
+ };
1091
+ //# sourceMappingURL=chunk-2LM6LCJW.mjs.map