@carlonicora/nextjs-jsonapi 6.11.0 → 6.12.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 (85) hide show
  1. package/dist/{AbstractService-Ckm2X5fW.d.mts → AbstractService-N0wFgaHD.d.mts} +1 -1
  2. package/dist/{AbstractService-V3VGQMhL.d.ts → AbstractService-kNAykPDk.d.ts} +1 -1
  3. package/dist/{BlockNoteEditor-GY5R25YI.js → BlockNoteEditor-CBYKEXAQ.js} +84 -43
  4. package/dist/BlockNoteEditor-CBYKEXAQ.js.map +1 -0
  5. package/dist/{BlockNoteEditor-5WM5DX3J.mjs → BlockNoteEditor-N2NBYCPC.mjs} +61 -20
  6. package/dist/BlockNoteEditor-N2NBYCPC.mjs.map +1 -0
  7. package/dist/{BlockNoteViewer-UCA3LV3N.mjs → BlockNoteViewer-MTGS6YJV.mjs} +2 -2
  8. package/dist/{BlockNoteViewer-FLUHEXE6.js → BlockNoteViewer-WGCDB7IJ.js} +3 -3
  9. package/dist/{BlockNoteViewer-FLUHEXE6.js.map → BlockNoteViewer-WGCDB7IJ.js.map} +1 -1
  10. package/dist/billing/index.js +491 -491
  11. package/dist/billing/index.mjs +3 -3
  12. package/dist/{chunk-6RLATJ2L.mjs → chunk-4FNGWALA.mjs} +2 -2
  13. package/dist/{chunk-MP3DV2I5.js → chunk-6NZKWIOR.js} +908 -908
  14. package/dist/{chunk-MP3DV2I5.js.map → chunk-6NZKWIOR.js.map} +1 -1
  15. package/dist/{chunk-3PRLRCMF.mjs → chunk-6XJOQFCP.mjs} +5 -5
  16. package/dist/{chunk-BGLOFZ3K.mjs → chunk-AA52ORW2.mjs} +11 -15
  17. package/dist/chunk-AA52ORW2.mjs.map +1 -0
  18. package/dist/{chunk-YP6W4AB5.mjs → chunk-EWCY6QJA.mjs} +2 -2
  19. package/dist/{chunk-YGEOX2XX.js → chunk-FF4EIQ6H.js} +11 -15
  20. package/dist/chunk-FF4EIQ6H.js.map +1 -0
  21. package/dist/{chunk-FNPXCYHO.js → chunk-L6PYFQTO.js} +8 -8
  22. package/dist/{chunk-FNPXCYHO.js.map → chunk-L6PYFQTO.js.map} +1 -1
  23. package/dist/{chunk-OHJSI6L2.js → chunk-O3PDL2CV.js} +4 -4
  24. package/dist/{chunk-OHJSI6L2.js.map → chunk-O3PDL2CV.js.map} +1 -1
  25. package/dist/client/index.js +4 -4
  26. package/dist/client/index.mjs +3 -3
  27. package/dist/components/index.d.mts +24 -3
  28. package/dist/components/index.d.ts +24 -3
  29. package/dist/components/index.js +4 -4
  30. package/dist/components/index.mjs +3 -3
  31. package/dist/contexts/index.js +4 -4
  32. package/dist/contexts/index.mjs +3 -3
  33. package/dist/core/index.d.mts +7 -7
  34. package/dist/core/index.d.ts +7 -7
  35. package/dist/core/index.js +2 -2
  36. package/dist/core/index.mjs +1 -1
  37. package/dist/email-automations/index.js +93 -93
  38. package/dist/email-automations/index.mjs +3 -3
  39. package/dist/features/analytics/index.d.mts +1 -1
  40. package/dist/features/analytics/index.d.ts +1 -1
  41. package/dist/features/analytics/index.js +120 -120
  42. package/dist/features/analytics/index.mjs +3 -3
  43. package/dist/features/analytics/server.js +4 -4
  44. package/dist/features/analytics/server.mjs +2 -2
  45. package/dist/features/blog/index.js +150 -150
  46. package/dist/features/blog/index.mjs +3 -3
  47. package/dist/features/blog/server.js +16 -16
  48. package/dist/features/blog/server.mjs +1 -1
  49. package/dist/features/help/index.js +37 -37
  50. package/dist/features/help/index.mjs +3 -3
  51. package/dist/features/tokenusage/index.d.mts +1 -1
  52. package/dist/features/tokenusage/index.d.ts +1 -1
  53. package/dist/features/tokenusage/index.js +126 -126
  54. package/dist/features/tokenusage/index.mjs +3 -3
  55. package/dist/index.d.mts +4 -4
  56. package/dist/index.d.ts +4 -4
  57. package/dist/index.js +3 -3
  58. package/dist/index.mjs +2 -2
  59. package/dist/{referral-admin.interface-CMwl5NiV.d.ts → referral-admin.interface-CnytdDaQ.d.ts} +1 -1
  60. package/dist/{referral-admin.interface-C87ApGMR.d.mts → referral-admin.interface-RVO-ZTJz.d.mts} +1 -1
  61. package/dist/{s3.service-BG136Btz.d.mts → s3.service-CeUsKm-d.d.mts} +1 -1
  62. package/dist/{s3.service-CsrsRPRn.d.ts → s3.service-SkZnngeR.d.ts} +1 -1
  63. package/dist/server/index.d.mts +2 -2
  64. package/dist/server/index.d.ts +2 -2
  65. package/dist/server/index.js +3 -3
  66. package/dist/server/index.mjs +2 -2
  67. package/package.json +8 -3
  68. package/src/components/editors/BlockNoteEditor.tsx +52 -20
  69. package/src/components/editors/__tests__/blocknote-editor-options.spec.ts +81 -0
  70. package/src/components/editors/blockNoteEditorOptions.ts +58 -0
  71. package/src/core/abstracts/AbstractService.ts +5 -11
  72. package/src/core/abstracts/ClientAbstractService.ts +5 -11
  73. package/src/core/abstracts/__tests__/AbstractService.locale.spec.ts +43 -0
  74. package/src/core/abstracts/__tests__/ClientAbstractService.locale.spec.ts +69 -0
  75. package/src/i18n/__tests__/config.spec.ts +22 -1
  76. package/src/i18n/config.ts +5 -0
  77. package/src/i18n/index.ts +1 -0
  78. package/dist/BlockNoteEditor-5WM5DX3J.mjs.map +0 -1
  79. package/dist/BlockNoteEditor-GY5R25YI.js.map +0 -1
  80. package/dist/chunk-BGLOFZ3K.mjs.map +0 -1
  81. package/dist/chunk-YGEOX2XX.js.map +0 -1
  82. /package/dist/{BlockNoteViewer-UCA3LV3N.mjs.map → BlockNoteViewer-MTGS6YJV.mjs.map} +0 -0
  83. /package/dist/{chunk-6RLATJ2L.mjs.map → chunk-4FNGWALA.mjs.map} +0 -0
  84. /package/dist/{chunk-3PRLRCMF.mjs.map → chunk-6XJOQFCP.mjs.map} +0 -0
  85. /package/dist/{chunk-YP6W4AB5.mjs.map → chunk-EWCY6QJA.mjs.map} +0 -0
@@ -37,7 +37,7 @@ declare abstract class AbstractService {
37
37
  /**
38
38
  * Extract locale from client-side URL pathname
39
39
  * URL structure: /{locale}/route-path (e.g., /it/accounts)
40
- * Fallback chain: URL locale → navigator.language → "en"
40
+ * Fallback chain: URL locale → the app's default locale (first supported locale)
41
41
  */
42
42
  private static getClientLocale;
43
43
  static next<T>(params: {
@@ -37,7 +37,7 @@ declare abstract class AbstractService {
37
37
  /**
38
38
  * Extract locale from client-side URL pathname
39
39
  * URL structure: /{locale}/route-path (e.g., /it/accounts)
40
- * Fallback chain: URL locale → navigator.language → "en"
40
+ * Fallback chain: URL locale → the app's default locale (first supported locale)
41
41
  */
42
42
  private static getClientLocale;
43
43
  static next<T>(params: {
@@ -6,10 +6,10 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkMP3DV2I5js = require('./chunk-MP3DV2I5.js');
9
+ var _chunk6NZKWIORjs = require('./chunk-6NZKWIOR.js');
10
10
 
11
11
 
12
- var _chunkFNPXCYHOjs = require('./chunk-FNPXCYHO.js');
12
+ var _chunkL6PYFQTOjs = require('./chunk-L6PYFQTO.js');
13
13
  require('./chunk-G4JR3SFV.js');
14
14
 
15
15
 
@@ -17,7 +17,7 @@ require('./chunk-G4JR3SFV.js');
17
17
 
18
18
 
19
19
 
20
- var _chunkYGEOX2XXjs = require('./chunk-YGEOX2XX.js');
20
+ var _chunkFF4EIQ6Hjs = require('./chunk-FF4EIQ6H.js');
21
21
  require('./chunk-GHE4VT2R.js');
22
22
 
23
23
 
@@ -30,7 +30,7 @@ var _chunk7QVYU63Ejs = require('./chunk-7QVYU63E.js');
30
30
 
31
31
  // src/components/editors/BlockNoteEditor.tsx
32
32
  var _core = require('@blocknote/core');
33
- var _locales = require('@blocknote/core/locales'); var coreLocales = _interopRequireWildcard(_locales);
33
+ var _locales = require('@blocknote/core/locales'); var coreLocales2 = _interopRequireWildcard(_locales); var coreLocales = _interopRequireWildcard(_locales);
34
34
 
35
35
 
36
36
 
@@ -122,6 +122,29 @@ function BlockNoteEditorFormattingToolbar({ showAI = false }) {
122
122
  }
123
123
  _chunk7QVYU63Ejs.__name.call(void 0, BlockNoteEditorFormattingToolbar, "BlockNoteEditorFormattingToolbar");
124
124
 
125
+ // src/components/editors/blockNoteEditorOptions.ts
126
+
127
+ var _yjs = require('@blocknote/core/yjs');
128
+ function buildBlockNoteEditorOptions(params) {
129
+ const { aiExtension, coreDictionary, aiDictionary, collaboration } = params;
130
+ const options = {
131
+ placeholders: {
132
+ emptyDocument: params.placeholder
133
+ },
134
+ schema: params.schema,
135
+ uploadFile: params.disableUploads ? void 0 : params.uploadFile,
136
+ extensions: aiExtension ? [aiExtension] : void 0,
137
+ dictionary: aiExtension ? { ...coreDictionary, ai: aiDictionary } : coreDictionary === coreLocales.en ? void 0 : coreDictionary
138
+ };
139
+ if (collaboration) return _yjs.withCollaboration.call(void 0, { ...options, collaboration });
140
+ return { ...options, initialContent: params.initialContent };
141
+ }
142
+ _chunk7QVYU63Ejs.__name.call(void 0, buildBlockNoteEditorOptions, "buildBlockNoteEditorOptions");
143
+ function resolveEditable(params) {
144
+ return params.editable !== void 0 ? params.editable : params.onChange !== void 0;
145
+ }
146
+ _chunk7QVYU63Ejs.__name.call(void 0, resolveEditable, "resolveEditable");
147
+
125
148
  // src/components/editors/BlockNoteEditor.tsx
126
149
 
127
150
  function isBlockEmpty(block) {
@@ -166,7 +189,7 @@ var createDiffActionsInlineContentSpec = /* @__PURE__ */ _chunk7QVYU63Ejs.__name
166
189
  const diffIds = props.inlineContent.props.diffIds;
167
190
  return /* @__PURE__ */ _jsxruntime.jsxs.call(void 0, "span", { className: "diff-actions-container mx-2 inline-flex items-center gap-1 align-middle", children: [
168
191
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
169
- _chunkMP3DV2I5js.Button,
192
+ _chunk6NZKWIORjs.Button,
170
193
  {
171
194
  title: labels.accept,
172
195
  onClick: (e) => {
@@ -178,7 +201,7 @@ var createDiffActionsInlineContentSpec = /* @__PURE__ */ _chunk7QVYU63Ejs.__name
178
201
  }
179
202
  ),
180
203
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
181
- _chunkMP3DV2I5js.Button,
204
+ _chunk6NZKWIORjs.Button,
182
205
  {
183
206
  title: labels.reject,
184
207
  className: "mx-2 p-0",
@@ -364,12 +387,16 @@ function BlockNoteEditor({
364
387
  aiConfig,
365
388
  stretch,
366
389
  aiEnabled = true,
367
- aiHandleRef
390
+ aiHandleRef,
391
+ collaboration,
392
+ disableUploads,
393
+ editable
368
394
  }) {
395
+ const isEditable = resolveEditable({ editable, onChange });
369
396
  const t = _nextintl.useTranslations.call(void 0, );
370
- const locale = _chunkYGEOX2XXjs.useI18nLocale.call(void 0, );
397
+ const locale = _chunkFF4EIQ6Hjs.useI18nLocale.call(void 0, );
371
398
  const { resolvedTheme } = _nextthemes.useTheme.call(void 0, );
372
- const company = _nullishCoalesce(_optionalChain([_chunkMP3DV2I5js.useCurrentUserContextOptional.call(void 0, ), 'optionalAccess', _6 => _6.company]), () => ( null));
399
+ const company = _nullishCoalesce(_optionalChain([_chunk6NZKWIORjs.useCurrentUserContextOptional.call(void 0, ), 'optionalAccess', _6 => _6.company]), () => ( null));
373
400
  const [acceptedChanges, setAcceptedChanges] = _react3.useState.call(void 0, /* @__PURE__ */ new Set());
374
401
  const [rejectedChanges, setRejectedChanges] = _react3.useState.call(void 0, /* @__PURE__ */ new Set());
375
402
  const editorRef = _react3.useRef.call(void 0, null);
@@ -410,7 +437,7 @@ function BlockNoteEditor({
410
437
  [handleAcceptChange, handleRejectChange, t]
411
438
  );
412
439
  const mentionSpec = _react3.useMemo.call(void 0,
413
- () => _chunkMP3DV2I5js.createMentionInlineContentSpec.call(void 0, mentionResolveFn, disableMentions, mentionNameResolver),
440
+ () => _chunk6NZKWIORjs.createMentionInlineContentSpec.call(void 0, mentionResolveFn, disableMentions, mentionNameResolver),
414
441
  [disableMentions, mentionResolveFn, mentionNameResolver]
415
442
  );
416
443
  const schema = _react3.useMemo.call(void 0,
@@ -434,7 +461,7 @@ function BlockNoteEditor({
434
461
  const aiEndpoint = _optionalChain([aiConfig, 'optionalAccess', _14 => _14.endpoint]);
435
462
  const aiExtension = _react3.useMemo.call(void 0, () => {
436
463
  if (!hasAiConfig || !aiEndpoint) return void 0;
437
- const base = _chunkFNPXCYHOjs.getPublicApiUrl.call(void 0, );
464
+ const base = _chunkL6PYFQTOjs.getPublicApiUrl.call(void 0, );
438
465
  const url = new URL(aiEndpoint, base.endsWith("/") ? base : base + "/").toString();
439
466
  return _xlai.AIExtension.call(void 0, {
440
467
  transport: new (0, _ai.DefaultChatTransport)({
@@ -479,7 +506,7 @@ function BlockNoteEditor({
479
506
  const uploadImage = _react3.useCallback.call(void 0,
480
507
  async (file) => {
481
508
  if (!company && !uploadKeyPrefix) {
482
- _chunkMP3DV2I5js.errorToast.call(void 0, {
509
+ _chunk6NZKWIORjs.errorToast.call(void 0, {
483
510
  title: t(`common.errors.upload`),
484
511
  error: t(`common.errors.upload_description`)
485
512
  });
@@ -487,7 +514,7 @@ function BlockNoteEditor({
487
514
  }
488
515
  const fileType = file.type;
489
516
  const key = uploadKeyPrefix ? `${uploadKeyPrefix}/${id}/${file.name}` : `companies/${company.id}/${type}/${id}/${file.name}`;
490
- const s3 = await _chunkYGEOX2XXjs.S3Service.getPreSignedUrl({
517
+ const s3 = await _chunkFF4EIQ6Hjs.S3Service.getPreSignedUrl({
491
518
  key,
492
519
  contentType: fileType,
493
520
  isPublic: true
@@ -497,7 +524,7 @@ function BlockNoteEditor({
497
524
  headers: s3.headers,
498
525
  body: file
499
526
  });
500
- const signedImage = await _chunkYGEOX2XXjs.S3Service.getSignedUrl({
527
+ const signedImage = await _chunkFF4EIQ6Hjs.S3Service.getSignedUrl({
501
528
  key,
502
529
  isPublic: true
503
530
  });
@@ -526,8 +553,8 @@ function BlockNoteEditor({
526
553
  const processedContent = _react3.useMemo.call(void 0, () => {
527
554
  if (diffContent && initialContent) {
528
555
  try {
529
- const diffResult = _chunkYGEOX2XXjs.BlockNoteDiffUtil.diff(initialContent, diffContent);
530
- const renderedDiff = _chunkYGEOX2XXjs.BlockNoteWordDiffRendererUtil.renderWordDiffs(
556
+ const diffResult = _chunkFF4EIQ6Hjs.BlockNoteDiffUtil.diff(initialContent, diffContent);
557
+ const renderedDiff = _chunkFF4EIQ6Hjs.BlockNoteWordDiffRendererUtil.renderWordDiffs(
531
558
  diffResult.blocks,
532
559
  handleAcceptChange,
533
560
  handleRejectChange,
@@ -567,21 +594,33 @@ function BlockNoteEditor({
567
594
  return void 0;
568
595
  }, [processedContent]);
569
596
  const language = locale.split("-")[0];
570
- const coreDictionary = _nullishCoalesce(coreLocales[language], () => ( coreLocales.en));
597
+ const coreDictionary = _nullishCoalesce(coreLocales2[language], () => ( coreLocales2.en));
571
598
  const aiDictionary = _nullishCoalesce(aiLocales[language], () => ( aiLocales.en));
572
599
  const editor = _react.useCreateBlockNote.call(void 0,
573
600
  _react3.useMemo.call(void 0,
574
- () => ({
575
- placeholders: {
576
- emptyDocument: placeholder || t(`common.blocknote.placeholder`)
577
- },
601
+ () => buildBlockNoteEditorOptions({
602
+ placeholder: placeholder || t(`common.blocknote.placeholder`),
578
603
  schema,
579
604
  initialContent: validatedInitialContent,
580
605
  uploadFile: uploadImage,
581
- extensions: aiExtension ? [aiExtension] : void 0,
582
- dictionary: aiExtension ? { ...coreDictionary, ai: aiDictionary } : coreDictionary === coreLocales.en ? void 0 : coreDictionary
606
+ disableUploads,
607
+ aiExtension,
608
+ coreDictionary,
609
+ aiDictionary,
610
+ collaboration
583
611
  }),
584
- [placeholder, t, schema, validatedInitialContent, uploadImage, aiExtension, coreDictionary, aiDictionary]
612
+ [
613
+ placeholder,
614
+ t,
615
+ schema,
616
+ validatedInitialContent,
617
+ uploadImage,
618
+ disableUploads,
619
+ aiExtension,
620
+ coreDictionary,
621
+ aiDictionary,
622
+ collaboration
623
+ ]
585
624
  ),
586
625
  // useCreateBlockNote memoises on THIS list, not on the options' identity
587
626
  // (@blocknote/react: useMemo(() => BlockNoteEditor.create(options), deps),
@@ -590,7 +629,8 @@ function BlockNoteEditor({
590
629
  // rendered the AI UI over an editor with no AIExtension, and BlockNote's
591
630
  // useExtension threw "Extension not found". The other options keep their
592
631
  // first-render values, as before. `aiEnabled` is deliberately not here.
593
- [aiExtension]
632
+ // A new Yjs fragment (another document) needs a new editor bound to it.
633
+ [aiExtension, _optionalChain([collaboration, 'optionalAccess', _19 => _19.fragment])]
594
634
  );
595
635
  const hasAiExtension = !!editor.getExtension(_xlai.AIExtension);
596
636
  const aiActive = hasAiExtension && aiEnabled;
@@ -622,8 +662,8 @@ function BlockNoteEditor({
622
662
  if (!ai) return;
623
663
  editor.focus();
624
664
  const blocks = editor.document;
625
- const anchor = _optionalChain([blocks, 'optionalAccess', _19 => _19[blocks.length - 1]]);
626
- if (_optionalChain([anchor, 'optionalAccess', _20 => _20.id])) ai.openAIMenuAtBlock(anchor.id);
665
+ const anchor = _optionalChain([blocks, 'optionalAccess', _20 => _20[blocks.length - 1]]);
666
+ if (_optionalChain([anchor, 'optionalAccess', _21 => _21.id])) ai.openAIMenuAtBlock(anchor.id);
627
667
  void ai.invokeAI({
628
668
  userPrompt: type2,
629
669
  useSelection: false,
@@ -709,6 +749,7 @@ function BlockNoteEditor({
709
749
  const previousContentHashRef = _react3.useRef.call(void 0, null);
710
750
  _react3.useEffect.call(void 0, () => {
711
751
  if (!processedContent || !editor) return;
752
+ if (collaboration) return;
712
753
  const hash = JSON.stringify(processedContent);
713
754
  if (previousContentHashRef.current === hash) return;
714
755
  if (lastEmittedHashRef.current === hash) {
@@ -722,23 +763,23 @@ function BlockNoteEditor({
722
763
  }
723
764
  editor.replaceBlocks(editor.document, processedContent);
724
765
  previousContentHashRef.current = hash;
725
- }, [processedContent, editor]);
766
+ }, [processedContent, editor, collaboration]);
726
767
  _react3.useEffect.call(void 0, () => {
727
768
  if (!onWarmMentions || !initialContent || !Array.isArray(initialContent) || initialContent.length === 0) return;
728
769
  onWarmMentions(initialContent);
729
770
  }, [onWarmMentions, initialContent]);
730
771
  _react3.useEffect.call(void 0, () => {
731
- docRef.current.getDoc = () => _nullishCoalesce(_optionalChain([editor, 'optionalAccess', _21 => _21.document]), () => ( []));
772
+ docRef.current.getDoc = () => _nullishCoalesce(_optionalChain([editor, 'optionalAccess', _22 => _22.document]), () => ( []));
732
773
  selectionRef.current.getSelectedBlocks = () => {
733
- const sel = _optionalChain([editor, 'optionalAccess', _22 => _22.getSelection, 'optionalCall', _23 => _23()]);
734
- const blocks = _optionalChain([sel, 'optionalAccess', _24 => _24.blocks]);
774
+ const sel = _optionalChain([editor, 'optionalAccess', _23 => _23.getSelection, 'optionalCall', _24 => _24()]);
775
+ const blocks = _optionalChain([sel, 'optionalAccess', _25 => _25.blocks]);
735
776
  return Array.isArray(blocks) ? blocks : [];
736
777
  };
737
778
  }, [editor]);
738
779
  const _handleAudioReceived = _react3.useCallback.call(void 0,
739
780
  (message) => {
740
781
  try {
741
- const editorElement = _optionalChain([editorRef, 'access', _25 => _25.current, 'optionalAccess', _26 => _26.querySelector, 'call', _27 => _27('[contenteditable="true"]')]);
782
+ const editorElement = _optionalChain([editorRef, 'access', _26 => _26.current, 'optionalAccess', _27 => _27.querySelector, 'call', _28 => _28('[contenteditable="true"]')]);
742
783
  if (editorElement && document.activeElement !== editorElement) {
743
784
  editorElement.focus();
744
785
  }
@@ -763,7 +804,7 @@ function BlockNoteEditor({
763
804
  "div",
764
805
  {
765
806
  ref: editorRef,
766
- className: _chunkYGEOX2XXjs.cn.call(void 0,
807
+ className: _chunkFF4EIQ6Hjs.cn.call(void 0,
767
808
  bordered ? "rounded-md border border-input bg-input/20 dark:bg-input/30" : "",
768
809
  "flex flex-col w-full",
769
810
  // Pin BlockNote's font-size so it doesn't jump from 14→16px when the
@@ -774,7 +815,7 @@ function BlockNoteEditor({
774
815
  // Phone: an editable field types at 16px, or iPhone Safari zooms the
775
816
  // page in on focus. The two ranges never overlap, so neither depends on
776
817
  // CSS source order to win.
777
- onChange ? "md:[&_.bn-default-styles]:!text-sm max-md:[&_.bn-default-styles]:!text-base" : "[&_.bn-default-styles]:!text-sm",
818
+ isEditable ? "md:[&_.bn-default-styles]:!text-sm max-md:[&_.bn-default-styles]:!text-base" : "[&_.bn-default-styles]:!text-sm",
778
819
  className
779
820
  ),
780
821
  children: /* @__PURE__ */ _jsxruntime.jsxs.call(void 0,
@@ -782,19 +823,19 @@ function BlockNoteEditor({
782
823
  {
783
824
  editor,
784
825
  onChange: handleChange,
785
- editable: onChange !== void 0,
826
+ editable: isEditable,
786
827
  formattingToolbar: false,
787
828
  slashMenu: !aiActive,
788
829
  theme: resolvedTheme === "dark" ? "dark" : "light",
789
- className: _chunkYGEOX2XXjs.cn.call(void 0,
830
+ className: _chunkFF4EIQ6Hjs.cn.call(void 0,
790
831
  "BlockNoteView flex-1",
791
- onChange && "[&.bn-container]:p-4",
832
+ isEditable && "[&.bn-container]:p-4",
792
833
  // In stretch mode the parent chain caps our height via flex; without
793
834
  // these two classes the `.bn-container` keeps `min-height: auto`
794
835
  // (its content's intrinsic height) and pushes the bordered wrapper
795
836
  // — and the surrounding EditorSheet form — to scroll instead of
796
837
  // scrolling internally.
797
- onChange && stretch && "[&.bn-container]:min-h-0 [&.bn-container]:overflow-y-auto",
838
+ isEditable && stretch && "[&.bn-container]:min-h-0 [&.bn-container]:overflow-y-auto",
798
839
  // Phone — these reach the floating menus because BlockNote puts this
799
840
  // className on its portal root too. The formatting toolbar (~450px)
800
841
  // scrolls sideways instead of losing alignment and link off-screen;
@@ -807,7 +848,7 @@ function BlockNoteEditor({
807
848
  children: [
808
849
  /* @__PURE__ */ _jsxruntime.jsx.call(void 0, BlockNoteEditorFormattingToolbar, { showAI: aiActive }),
809
850
  enableMentions && mentionSearchFn && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
810
- _chunkMP3DV2I5js.BlockNoteEditorMentionSuggestionMenu,
851
+ _chunk6NZKWIORjs.BlockNoteEditorMentionSuggestionMenu,
811
852
  {
812
853
  editor,
813
854
  mentionSearchFn,
@@ -815,8 +856,8 @@ function BlockNoteEditor({
815
856
  suggestionMenuComponent
816
857
  }
817
858
  ),
818
- _optionalChain([renderOverlays, 'optionalCall', _28 => _28(editor)]),
819
- enableMentions && mentionResolveFn && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunkMP3DV2I5js.BlockNoteEditorMentionHoverCard, { containerRef: editorRef, mentionResolveFn }),
859
+ _optionalChain([renderOverlays, 'optionalCall', _29 => _29(editor)]),
860
+ enableMentions && mentionResolveFn && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _chunk6NZKWIORjs.BlockNoteEditorMentionHoverCard, { containerRef: editorRef, mentionResolveFn }),
820
861
  aiActive && /* @__PURE__ */ _jsxruntime.jsx.call(void 0,
821
862
  _react.SuggestionMenuController,
822
863
  {
@@ -824,7 +865,7 @@ function BlockNoteEditor({
824
865
  getItems: async (query) => _core.filterSuggestionItems.call(void 0, [..._react.getDefaultReactSlashMenuItems.call(void 0, editor), ..._xlai.getAISlashMenuItems.call(void 0, editor)], query)
825
866
  }
826
867
  ),
827
- aiActive && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xlai.AIMenuController, { aiMenu: () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NarrAIMenu, { actions: _optionalChain([aiConfig, 'optionalAccess', _29 => _29.actions]) }) })
868
+ aiActive && /* @__PURE__ */ _jsxruntime.jsx.call(void 0, _xlai.AIMenuController, { aiMenu: () => /* @__PURE__ */ _jsxruntime.jsx.call(void 0, NarrAIMenu, { actions: _optionalChain([aiConfig, 'optionalAccess', _30 => _30.actions]) }) })
828
869
  ]
829
870
  }
830
871
  )
@@ -835,4 +876,4 @@ _chunk7QVYU63Ejs.__name.call(void 0, BlockNoteEditor, "BlockNoteEditor");
835
876
 
836
877
 
837
878
  exports.default = BlockNoteEditor;
838
- //# sourceMappingURL=BlockNoteEditor-GY5R25YI.js.map
879
+ //# sourceMappingURL=BlockNoteEditor-CBYKEXAQ.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/BlockNoteEditor-CBYKEXAQ.js","../src/components/editors/BlockNoteEditor.tsx","../src/components/editors/BlockNoteEditorAiActions.tsx","../src/components/editors/BlockNoteEditorFormattingToolbar.tsx","../src/components/editors/blockNoteEditorOptions.ts"],"names":["jsx","jsxs","SparklesIcon","type"],"mappings":"AAAA,+8BAAY;AACZ;AACE;AACA;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACA;AACA;AACA;AACA;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B,+BAA4B;AAC5B,+BAA4B;AAC5B;AACE;AACF,sDAA4B;AAC5B;AACA;AC5BA,uCAAgG;AAChG,6JAA6B;AAC7B;AACE;AAEA;AACA;AAEA;AACA;AACA;AACA;AAAA,yCACK;AACP,2CAA8B;AAC9B,uCAAO;AACP;AACE;AACA;AACA;AACA;AACA;AACA;AAAA,wCACK;AACP,wGAA2B;AAC3B,sCAAO;AACP,wBAAqC;AACrC,2CAA0F;AAC1F,qCAAgC;AAChC,yCAAyB;AACzB,+BAAyE;AD4BzE;AACA;AE5DA;AA+BU,+CAAA;AApBH,IAAM,4BAAA,EAA2D,CAAC,eAAe,CAAA;AAexF,IAAM,MAAA,EAAqE;AAAA,EACzE,eAAA,EAAiB;AAAA,IACf,GAAA,EAAK,wBAAA;AAAA,IACL,QAAA,EAAU,qCAAA;AAAA,IACV,OAAA,EAAS,CAAC,UAAA,EAAY,UAAA,EAAY,MAAM,CAAA;AAAA,IACxC,IAAA,kBAAM,6BAAA,+BAAC,EAAA,EAAmB,IAAA,EAAM,GAAA,CAAI,CAAA;AAAA,IACpC,IAAA,EAAM;AAAA,EACR,CAAA;AAAA,EACA,kBAAA,EAAoB;AAAA,IAClB,GAAA,EAAK,oBAAA;AAAA,IACL,QAAA,EAAU,iCAAA;AAAA,IACV,OAAA,EAAS,CAAC,SAAA,EAAW,YAAY,CAAA;AAAA,IACjC,IAA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;AAEJ;AA1nBwB;ADwcwC;AACA;AACA","file":"/home/runner/work/nextjs-jsonapi/nextjs-jsonapi/dist/BlockNoteEditor-CBYKEXAQ.js","sourcesContent":[null,"\"use client\";\n\nimport { BlockNoteSchema, defaultInlineContentSpecs, filterSuggestionItems, PartialBlock } from \"@blocknote/core\";\nimport * as coreLocales from \"@blocknote/core/locales\";\nimport {\n createReactInlineContentSpec,\n DefaultReactSuggestionItem,\n getDefaultReactSlashMenuItems,\n SuggestionMenuController,\n SuggestionMenuProps,\n useBlockNoteEditor,\n useCreateBlockNote,\n useExtension,\n useExtensionState,\n} from \"@blocknote/react\";\nimport { BlockNoteView } from \"@blocknote/shadcn\";\nimport \"@blocknote/shadcn/style.css\";\nimport {\n AIExtension,\n AIMenuController,\n getAISlashMenuItems,\n getDefaultAIMenuItems,\n PromptSuggestionMenu,\n useAIDictionary,\n} from \"@blocknote/xl-ai\";\nimport * as aiLocales from \"@blocknote/xl-ai/locales\";\nimport \"@blocknote/xl-ai/style.css\";\nimport { DefaultChatTransport } from \"ai\";\nimport { CheckIcon, LanguagesIcon, SparklesIcon, TypeIcon, WandSparklesIcon, XIcon } from \"lucide-react\";\nimport { useTranslations } from \"next-intl\";\nimport { useTheme } from \"next-themes\";\nimport React, { useCallback, useEffect, useMemo, useRef, useState } from \"react\";\nimport { getPublicApiUrl } from \"../../client/config\";\nimport { getClientToken } from \"../../client/token\";\nimport { useCurrentUserContextOptional } from \"../../contexts\";\nimport { S3Interface } from \"../../features/s3/data\";\nimport { S3Service } from \"../../features/s3/data/s3.service\";\nimport { UserInterface } from \"../../features/user/data\";\nimport { useI18nLocale } from \"../../i18n/config\";\nimport { Button } from \"../../shadcnui\";\nimport { BlockNoteDiffUtil, BlockNoteWordDiffRendererUtil, cn } from \"../../utils\";\nimport { errorToast } from \"../errors\";\nimport { BlockNoteAiGenerateAction, generateActionItems } from \"./BlockNoteEditorAiActions\";\nimport { BlockNoteEditorFormattingToolbar } from \"./BlockNoteEditorFormattingToolbar\";\nimport { type BlockNoteCollaboration, buildBlockNoteEditorOptions, resolveEditable } from \"./blockNoteEditorOptions\";\nimport { BlockNoteEditorMentionHoverCard } from \"./BlockNoteEditorMentionHoverCard\";\nimport {\n createMentionInlineContentSpec,\n type MentionNameResolver,\n type MentionResolveFn,\n} from \"./BlockNoteEditorMentionInlineContent\";\nimport { BlockNoteEditorMentionSuggestionMenu } from \"./BlockNoteEditorSuggestionMenuController\";\n\n/**\n * Lets app code trigger a whole-document AI action from OUTSIDE the editor\n * (a visible button next to the field label, for instance) without owning the\n * BlockNote instance. Delivered through a plain prop, not a React `ref`:\n * `BlockNoteEditorContainer` is a `next/dynamic` import wrapped in\n * `React.memo`, and refs do not pass through that reliably.\n */\nexport type BlockNoteAiHandle = { invokeAi: (type: BlockNoteAiGenerateAction) => void };\n\nexport type BlockNoteAiConfig = {\n endpoint: string;\n entityType: string;\n entityId?: string;\n /** Whole-document actions shown when nothing is selected. Default: [\"fill-template\"]. */\n actions?: BlockNoteAiGenerateAction[];\n};\n\nexport type BlockNoteEditorProps = {\n id: string;\n type: string;\n initialContent?: PartialBlock[];\n onChange?: (content: any, isEmpty: boolean, hasUnresolvedDiff: boolean) => void;\n size?: \"sm\" | \"md\";\n className?: string;\n markdownContent?: string;\n diffContent?: PartialBlock[];\n placeholder?: string;\n bordered?: boolean;\n /**\n * Storage folder for pasted images, used instead of the current company's\n * `companies/<companyId>/<type>` folder: the image key becomes\n * `<uploadKeyPrefix>/<id>/<file name>`. For platform content edited by users\n * who belong to no company (the blog). Omitted: the company folder, as before.\n */\n uploadKeyPrefix?: string;\n inlineContentSpecs?: Record<string, any>;\n renderOverlays?: (editor: any) => React.ReactNode;\n enableMentions?: boolean;\n disableMentions?: boolean;\n mentionSearchFn?: (\n query: string,\n params?: Record<string, string>,\n ) => Promise<import(\"./BlockNoteEditorSuggestionMenuController\").MentionItem[]>;\n mentionSearchParams?: Record<string, string>;\n mentionResolveFn?: MentionResolveFn;\n suggestionMenuComponent?: React.FC<SuggestionMenuProps<DefaultReactSuggestionItem>>;\n mentionNameResolver?: MentionNameResolver;\n onWarmMentions?: (blocks: PartialBlock[]) => void;\n aiConfig?: BlockNoteAiConfig;\n // When the editor is inside a bounded flex column (parent gives it a real\n // height via flex-1+min-h-0), set this so `.bn-container` shrinks to that\n // height and scrolls internally. Without it the editor grows to fit its\n // content and pushes the surrounding form to scroll instead.\n stretch?: boolean;\n // Gates AI on top of `aiConfig` (credit availability, etc.). Defaults to\n // true so existing callers that only pass `aiConfig` are unaffected. When\n // false, the AI toolbar button and AI slash items are hidden, the editor\n // falls back to the plain slash menu, an open AI menu or run is closed, and\n // no AI request is sent. The AI extension itself stays: toggling this never\n // rebuilds the editor, so unsaved text survives credits running out.\n aiEnabled?: boolean;\n // Filled with a {@link BlockNoteAiHandle} while the editor is mounted and AI\n // is on, so a control outside the editor can run a whole-document AI action.\n // Cleared on unmount and whenever AI is unavailable.\n aiHandleRef?: React.MutableRefObject<BlockNoteAiHandle | null>;\n /**\n * Live co-editing (Yjs). When set, the Yjs document is the content: used\n * instead of `initialContent`/`onChange`. Changing `collaboration.fragment`\n * rebuilds the editor.\n */\n collaboration?: BlockNoteCollaboration;\n /** true: image uploads are off (no paste/drop upload, no upload tab). */\n disableUploads?: boolean;\n /**\n * Overrides the default `onChange !== undefined` editability, e.g. for a\n * collaborative editor, which has no `onChange`.\n */\n editable?: boolean;\n};\n\nfunction isBlockEmpty(block: any): boolean {\n if (!block || typeof block !== \"object\") return true;\n if (block.type !== \"paragraph\") return false;\n if (Array.isArray(block.children) && block.children.length > 0 && !isDocumentEmpty(block.children)) {\n return false;\n }\n if (Array.isArray(block.content)) {\n for (const inline of block.content) {\n if (typeof inline === \"string\") {\n if (inline.trim()) return false;\n } else if (inline && typeof inline === \"object\") {\n if (inline.type !== \"text\") return false;\n if (typeof inline.text === \"string\" && inline.text.trim()) return false;\n }\n }\n } else if (typeof block.content === \"string\" && block.content.trim()) {\n return false;\n }\n return true;\n}\n\nfunction isDocumentEmpty(blocks: any[]): boolean {\n if (!Array.isArray(blocks) || blocks.length === 0) return true;\n return blocks.every(isBlockEmpty);\n}\n\nconst createDiffActionsInlineContentSpec = (\n handleAcceptChange: (diffId: string) => void,\n handleRejectChange: (diffId: string) => void,\n labels: { accept: string; reject: string },\n) => {\n return createReactInlineContentSpec(\n {\n type: \"diffActions\",\n propSchema: {\n diffIds: {\n default: \"\",\n },\n },\n content: \"none\",\n },\n {\n render: (props) => {\n const diffIds = props.inlineContent.props.diffIds;\n\n return (\n <span className=\"diff-actions-container mx-2 inline-flex items-center gap-1 align-middle\">\n <Button\n title={labels.accept}\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n diffIds.split(\",\").forEach((id: string) => handleAcceptChange(id.trim()));\n }}\n >\n <CheckIcon className=\"text-success h-3 w-3\" />\n </Button>\n <Button\n title={labels.reject}\n className=\"mx-2 p-0\"\n onClick={(e) => {\n e.preventDefault();\n e.stopPropagation();\n diffIds.split(\",\").forEach((id: string) => handleRejectChange(id.trim()));\n }}\n >\n <XIcon className=\"text-destructive h-3 w-3\" />\n </Button>\n </span>\n );\n },\n },\n );\n};\n\n/**\n * Custom AI menu wrapper. Surfaces our backend-driven action items\n * (Improve Writing, Fix Spelling) above the free-form prompt input.\n *\n * Why a custom wrapper instead of `<AIMenu items={…}>` with the BlockNote\n * defaults: BlockNote's `PromptSuggestionMenu` hijacks Enter to pick the\n * highlighted item whenever `items.length > 0`. We gate items on\n * - status === \"user-input\"\n * - editor has a selection\n * - prompt input is empty\n * so the moment the user types, items disappear and Enter falls back to\n * free-form submission. Outside `user-input` (review / error states) we\n * keep BlockNote's default review buttons (accept/revert/retry/cancel).\n *\n * Each custom item passes a `type` discriminator on `chatRequestOptions.body`.\n * That field flows through `chat.sendMessage(msg, opts)` to the transport's\n * `prepareSendMessagesRequest({messages, body})` (see types.ts in\n * `@blocknote/xl-ai` — `ChatRequestOptions = Parameters<Chat[\"sendMessage\"]>[1]`).\n * The backend dispatcher reads `body.type` and routes to a per-type handler\n * with its own canonical prompt. NO prompt text lives in this file.\n */\nfunction NarrAIMenu({ actions }: { actions?: BlockNoteAiGenerateAction[] }) {\n const t = useTranslations();\n const editor = useBlockNoteEditor();\n const ai = useExtension(AIExtension);\n const dict = useAIDictionary();\n const status = useExtensionState(AIExtension, {\n selector: (s) => (s.aiMenuState !== \"closed\" ? s.aiMenuState.status : \"closed\"),\n });\n const [prompt, setPrompt] = useState(\"\");\n // Set by items that pre-fill the input (Translate) so handleSubmit knows\n // which `type` to attach when the user submits the captured text. Cleared\n // after submit or on status change.\n const pendingTypeRef = useRef<string | null>(null);\n\n useEffect(() => {\n if (status === \"ai-writing\" || status === \"user-reviewing\" || status === \"error\" || status === \"closed\") {\n setPrompt(\"\");\n pendingTypeRef.current = null;\n }\n }, [status]);\n\n // Selection-edit ops operate per-block. If the user's selection only\n // covers part of a block (cursor mid-paragraph dragged to mid-next), the\n // rewrite would silently replace the WHOLE containing blocks — beyond\n // what the user highlighted. Expand the selection to whole-block bounds\n // BEFORE invokeAI so the user sees exactly what will be rewritten.\n const expandSelectionToBlocks = useCallback(() => {\n const sel = editor.getSelection?.();\n const blocks = (sel as any)?.blocks;\n if (!Array.isArray(blocks) || blocks.length === 0) return;\n const first = blocks[0];\n const last = blocks[blocks.length - 1];\n try {\n (editor as any).setSelection?.(first, last);\n } catch {\n // If BlockNote's setSelection signature changes, fail silently — the\n // backend still operates per-block, so we just lose the visual hint.\n }\n }, [editor]);\n\n const items = useMemo(() => {\n // Outside user-input (reviewing / error), use BlockNote's default\n // review buttons (accept/revert/retry/cancel). Need to wrap onItemClick\n // because the default items expect a setPrompt argument.\n if (status !== \"user-input\") {\n return getDefaultAIMenuItems(editor, status).map((item) => ({\n ...item,\n onItemClick: () => item.onItemClick(setPrompt),\n }));\n }\n const hasSelection = editor.getSelection() !== undefined;\n const hasTyped = prompt.trim().length > 0;\n // Once the user starts typing, hide all items so Enter submits the\n // free-form (or pending-type) prompt instead of being hijacked.\n if (hasTyped) return [];\n\n const invokeGenerate = (type: BlockNoteAiGenerateAction) => {\n void ai.invokeAI({\n userPrompt: type,\n useSelection: false,\n chatRequestOptions: { body: { type } },\n });\n };\n // Whole-document items are shown in BOTH contexts (with and without\n // selection) because they operate on the whole document — they ignore any\n // active selection. Listed first so the first one is the\n // default-highlighted item.\n const generateItems = generateActionItems(actions, invokeGenerate, t);\n\n if (hasSelection) {\n // Selection-edit items + the always-available whole-document items.\n // Each selection item invokes ai.invokeAI with chatRequestOptions\n // carrying the `type` body field. The userPrompt is a short tag — the\n // backend ignores it and uses the canonical prompt for the type instead.\n return [\n ...generateItems,\n {\n key: \"improve_writing\",\n title: t(\"ui.editor.ai.improve_writing\"),\n aliases: [\"improve\", \"rewrite\", \"polish\"],\n icon: <SparklesIcon size={18} />,\n size: \"small\" as const,\n onItemClick: () => {\n expandSelectionToBlocks();\n void ai.invokeAI({\n userPrompt: \"improve-writing\",\n useSelection: true,\n chatRequestOptions: { body: { type: \"improve-writing\" } },\n });\n },\n },\n {\n key: \"fix_spelling\",\n title: t(\"ui.editor.ai.fix_spelling\"),\n aliases: [\"spelling\", \"grammar\", \"typo\"],\n icon: <TypeIcon size={18} />,\n size: \"small\" as const,\n onItemClick: () => {\n expandSelectionToBlocks();\n void ai.invokeAI({\n userPrompt: \"fix-spelling\",\n useSelection: true,\n chatRequestOptions: { body: { type: \"fix-spelling\" } },\n });\n },\n },\n {\n key: \"translate\",\n title: t(\"ui.editor.ai.translate\"),\n aliases: [\"translate\", \"language\"],\n icon: <LanguagesIcon size={18} />,\n size: \"small\" as const,\n // Pre-fills the input with a placeholder. User appends/replaces\n // with the target language and submits via Enter. handleSubmit\n // reads pendingTypeRef and forwards `type: \"translate\"`. We\n // expand the selection now so the user sees the scope before\n // typing the language — handleSubmit doesn't re-expand.\n onItemClick: () => {\n expandSelectionToBlocks();\n pendingTypeRef.current = \"translate\";\n setPrompt(t(\"ui.editor.ai.translate_prefill\"));\n },\n },\n {\n key: \"simplify\",\n title: t(\"ui.editor.ai.simplify\"),\n aliases: [\"simplify\", \"easier\", \"plain\"],\n icon: <WandSparklesIcon size={18} />,\n size: \"small\" as const,\n onItemClick: () => {\n expandSelectionToBlocks();\n void ai.invokeAI({\n userPrompt: \"simplify\",\n useSelection: true,\n chatRequestOptions: { body: { type: \"simplify\" } },\n });\n },\n },\n ];\n }\n\n // No selection (the /ai slash menu path): just the whole-document items.\n // Free-form typing still works — once the user types, items hide and\n // Enter submits with no type (backend defaults to fill-template).\n return generateItems;\n }, [editor, status, prompt, ai, expandSelectionToBlocks, actions, t]);\n\n const handleSubmit = useCallback(\n async (userPrompt: string) => {\n if (!userPrompt.trim()) return;\n const pendingType = pendingTypeRef.current;\n pendingTypeRef.current = null;\n const body = pendingType ? { type: pendingType } : undefined;\n await ai.invokeAI({\n userPrompt,\n useSelection: editor.getSelection() !== undefined,\n ...(body ? { chatRequestOptions: { body } } : {}),\n });\n },\n [ai, editor],\n );\n\n const placeholder =\n status === \"thinking\"\n ? dict.ai_menu.status.thinking\n : status === \"ai-writing\"\n ? dict.ai_menu.status.editing\n : status === \"error\"\n ? dict.ai_menu.status.error\n : dict.ai_menu.input_placeholder;\n\n const disabled = status === \"thinking\" || status === \"ai-writing\";\n\n return (\n <PromptSuggestionMenu\n items={items}\n onManualPromptSubmit={handleSubmit}\n promptText={prompt}\n onPromptTextChange={setPrompt}\n placeholder={placeholder}\n disabled={disabled}\n icon={\n <div className=\"bn-combobox-icon\">\n <SparklesIcon size={16} />\n </div>\n }\n />\n );\n}\n\nexport default function BlockNoteEditor({\n id,\n type,\n initialContent,\n onChange,\n size,\n className,\n markdownContent,\n diffContent,\n placeholder,\n bordered,\n uploadKeyPrefix,\n inlineContentSpecs,\n renderOverlays,\n enableMentions,\n disableMentions,\n mentionSearchFn,\n mentionSearchParams,\n mentionResolveFn,\n suggestionMenuComponent,\n mentionNameResolver,\n onWarmMentions,\n aiConfig,\n stretch,\n aiEnabled = true,\n aiHandleRef,\n collaboration,\n disableUploads,\n editable,\n}: BlockNoteEditorProps): React.JSX.Element {\n const isEditable = resolveEditable({ editable, onChange });\n const t = useTranslations();\n const locale = useI18nLocale();\n const { resolvedTheme } = useTheme();\n // Optional on purpose: a host app may mount its own user context instead of\n // this package's, and the editor already degrades without a company — image\n // upload reports it (`uploadImage`) and the AI transport simply omits the\n // company header. Throwing here would take the whole page down instead.\n const company = useCurrentUserContextOptional<UserInterface>()?.company ?? null;\n\n const [acceptedChanges, setAcceptedChanges] = useState<Set<string>>(new Set());\n const [rejectedChanges, setRejectedChanges] = useState<Set<string>>(new Set());\n\n const editorRef = useRef<HTMLDivElement>(null);\n\n // Ensure side menu buttons don't trigger form submission\n useEffect(() => {\n if (!editorRef.current) return;\n const setButtonTypes = () => {\n editorRef.current?.querySelectorAll(\".bn-side-menu button\").forEach((btn) => {\n if (!btn.getAttribute(\"type\")) {\n btn.setAttribute(\"type\", \"button\");\n }\n });\n };\n const observer = new MutationObserver(setButtonTypes);\n observer.observe(editorRef.current, { childList: true, subtree: true });\n return () => observer.disconnect();\n }, []);\n\n const handleAcceptChange = useCallback((diffId: string) => {\n setAcceptedChanges((prev) => new Set([...prev, diffId]));\n setRejectedChanges((prev) => {\n const newSet = new Set(prev);\n newSet.delete(diffId);\n return newSet;\n });\n }, []);\n\n const handleRejectChange = useCallback((diffId: string) => {\n setRejectedChanges((prev) => new Set([...prev, diffId]));\n setAcceptedChanges((prev) => {\n const newSet = new Set(prev);\n newSet.delete(diffId);\n return newSet;\n });\n }, []);\n\n const DiffActionsInlineContent = useMemo(\n () =>\n createDiffActionsInlineContentSpec(handleAcceptChange, handleRejectChange, {\n accept: t(\"ui.editor.accept_change\"),\n reject: t(\"ui.editor.reject_change\"),\n }),\n [handleAcceptChange, handleRejectChange, t],\n );\n\n const mentionSpec = useMemo(\n () => createMentionInlineContentSpec(mentionResolveFn, disableMentions, mentionNameResolver),\n [disableMentions, mentionResolveFn, mentionNameResolver],\n );\n\n const schema = useMemo(\n () =>\n BlockNoteSchema.create({\n inlineContentSpecs: {\n ...defaultInlineContentSpecs,\n diffActions: DiffActionsInlineContent,\n mention: mentionSpec,\n ...inlineContentSpecs,\n },\n } as any),\n [DiffActionsInlineContent, mentionSpec, inlineContentSpecs],\n );\n\n const docRef = useRef<{ getDoc: () => any[] }>({ getDoc: () => [] });\n // Selection getter used by the AI transport to attach `selectionBlocks` to\n // the outgoing request metadata. Populated in a useEffect once the editor\n // instance exists; reads the current BlockNote selection on every send.\n const selectionRef = useRef<{ getSelectedBlocks: () => any[] }>({ getSelectedBlocks: () => [] });\n\n // Callers pass `aiConfig` as an inline object, the company arrives after the\n // first render and `aiEnabled` flips with credits, so none of them may key\n // the AI extension: every new extension means a new editor, which restarts\n // from `initialContent` and drops unsaved text. The transport and the outside\n // handle read them through this ref at send time.\n const aiRequestRef = useRef({ aiConfig, companyId: company?.id, aiEnabled });\n useEffect(() => {\n aiRequestRef.current = { aiConfig, companyId: company?.id, aiEnabled };\n });\n\n const hasAiConfig = !!aiConfig;\n const aiEndpoint = aiConfig?.endpoint;\n const aiExtension = useMemo(() => {\n if (!hasAiConfig || !aiEndpoint) return undefined;\n const base = getPublicApiUrl();\n const url = new URL(aiEndpoint, base.endsWith(\"/\") ? base : base + \"/\").toString();\n return AIExtension({\n transport: new DefaultChatTransport({\n api: url,\n credentials: \"include\",\n headers: async () => {\n const headers: Record<string, string> = { \"x-language\": locale };\n const token = await getClientToken();\n if (token) headers[\"Authorization\"] = `Bearer ${token}`;\n const companyId = aiRequestRef.current.companyId;\n if (companyId) headers[\"x-companyid\"] = companyId;\n return headers;\n },\n prepareSendMessagesRequest: ({ messages, body }: any) => {\n // Last guard before the network: AI switched off while a request was\n // being started never reaches the endpoint. Throwing here puts the\n // AI menu in its error state instead of sending.\n if (!aiRequestRef.current.aiEnabled) throw new Error(\"AI is disabled\");\n const latestAiConfig = aiRequestRef.current.aiConfig;\n let lastUserIdx = -1;\n for (let i = messages.length - 1; i >= 0; i--) {\n if (messages[i]?.role === \"user\") {\n lastUserIdx = i;\n break;\n }\n }\n const selectedBlocks = selectionRef.current.getSelectedBlocks();\n const augmented = messages.map((m: any, i: number) =>\n i === lastUserIdx\n ? {\n ...m,\n metadata: {\n ...(m.metadata ?? {}),\n entityType: latestAiConfig?.entityType,\n entityId: latestAiConfig?.entityId,\n blocks: docRef.current.getDoc(),\n selectionBlocks: selectedBlocks,\n },\n }\n : m,\n );\n return { body: { ...(body ?? {}), messages: augmented } };\n },\n }),\n });\n }, [hasAiConfig, aiEndpoint, locale]);\n\n const uploadImage = useCallback(\n async (file: File): Promise<string> => {\n if (!company && !uploadKeyPrefix) {\n errorToast({\n title: t(`common.errors.upload`),\n error: t(`common.errors.upload_description`),\n });\n throw new Error(t(`common.errors.upload`));\n }\n\n const fileType = file.type;\n const key = uploadKeyPrefix\n ? `${uploadKeyPrefix}/${id}/${file.name}`\n : `companies/${company!.id}/${type}/${id}/${file.name}`;\n\n const s3: S3Interface = await S3Service.getPreSignedUrl({\n key: key,\n contentType: fileType,\n isPublic: true,\n });\n\n await fetch(s3.url, {\n method: \"PUT\",\n headers: s3.headers,\n body: file,\n });\n\n const signedImage: S3Interface = await S3Service.getSignedUrl({\n key: key,\n isPublic: true,\n });\n\n return signedImage.url;\n },\n [company, id, t, type, uploadKeyPrefix],\n );\n\n // Utility: Remove trailing empty blocks for read-only display\n const removeTrailingEmptyBlocks = useCallback(\n (blocks: PartialBlock[]): PartialBlock[] => {\n if (!blocks || blocks.length === 0) return blocks;\n\n // Only remove trailing empty blocks in read-only mode\n if (onChange !== undefined) return blocks;\n\n const result = [...blocks];\n\n // Remove trailing empty paragraph blocks, but keep at least one block\n while (result.length > 1) {\n const lastBlock = result[result.length - 1];\n\n // Check if it's an empty paragraph\n const isEmptyParagraph =\n lastBlock.type === \"paragraph\" &&\n (!lastBlock.content ||\n lastBlock.content.length === 0 ||\n (Array.isArray(lastBlock.content) && lastBlock.content.every((c: any) => !c.text || c.text.trim() === \"\")));\n\n if (isEmptyParagraph) {\n result.pop();\n } else {\n break;\n }\n }\n\n return result;\n },\n [onChange],\n );\n\n const processedContent = useMemo(() => {\n if (diffContent && initialContent) {\n try {\n const diffResult = BlockNoteDiffUtil.diff(initialContent, diffContent);\n const renderedDiff = BlockNoteWordDiffRendererUtil.renderWordDiffs(\n diffResult.blocks,\n handleAcceptChange,\n handleRejectChange,\n acceptedChanges,\n rejectedChanges,\n );\n return removeTrailingEmptyBlocks(renderedDiff);\n } catch (_error) {\n return initialContent && Array.isArray(initialContent) && initialContent.length > 0\n ? removeTrailingEmptyBlocks(initialContent)\n : [];\n }\n }\n\n if (!initialContent) {\n return [];\n }\n\n if (!Array.isArray(initialContent)) {\n return [];\n }\n\n return initialContent.length > 0 ? removeTrailingEmptyBlocks(initialContent) : [];\n }, [\n initialContent,\n diffContent,\n handleAcceptChange,\n handleRejectChange,\n acceptedChanges,\n rejectedChanges,\n removeTrailingEmptyBlocks,\n ]);\n\n const validatedInitialContent = useMemo(() => {\n if (processedContent && Array.isArray(processedContent) && processedContent.length > 0) {\n const validatedContent = processedContent.filter((block) => {\n if (!block || typeof block !== \"object\") return false;\n if (!(block as any).type) return false;\n return true;\n });\n return validatedContent.length > 0 ? (validatedContent as PartialBlock[]) : undefined;\n }\n return undefined;\n }, [processedContent]);\n\n // BlockNote's own UI text (slash menu, toolbar, AI menu) in the active\n // language; English when BlockNote has no dictionary for it.\n const language = locale.split(\"-\")[0];\n const coreDictionary = (coreLocales as Record<string, typeof coreLocales.en>)[language] ?? coreLocales.en;\n const aiDictionary = (aiLocales as Record<string, typeof aiLocales.en>)[language] ?? aiLocales.en;\n\n const editor = useCreateBlockNote(\n useMemo(\n () =>\n buildBlockNoteEditorOptions({\n placeholder: placeholder || t(`common.blocknote.placeholder`),\n schema,\n initialContent: validatedInitialContent,\n uploadFile: uploadImage,\n disableUploads,\n aiExtension,\n coreDictionary,\n aiDictionary,\n collaboration,\n }),\n [\n placeholder,\n t,\n schema,\n validatedInitialContent,\n uploadImage,\n disableUploads,\n aiExtension,\n coreDictionary,\n aiDictionary,\n collaboration,\n ],\n ),\n // useCreateBlockNote memoises on THIS list, not on the options' identity\n // (@blocknote/react: useMemo(() => BlockNoteEditor.create(options), deps),\n // deps defaulting to []). Without it the editor keeps the extensions of its\n // first render: AI config arriving later (user loaded after mount)\n // rendered the AI UI over an editor with no AIExtension, and BlockNote's\n // useExtension threw \"Extension not found\". The other options keep their\n // first-render values, as before. `aiEnabled` is deliberately not here.\n // A new Yjs fragment (another document) needs a new editor bound to it.\n [aiExtension, collaboration?.fragment],\n );\n\n // Every AI surface keys off the editor actually rendered, never off the\n // props: those can disagree with the options that editor was created with.\n // `aiEnabled` then hides that UI without touching the editor.\n const hasAiExtension = !!editor.getExtension(AIExtension);\n const aiActive = hasAiExtension && aiEnabled;\n\n // AI switched off while its menu is open or a run is streaming: hiding the\n // AIMenuController alone would leave the editor read-only (openAIMenuAtBlock\n // sets isEditable = false) and the AI suggestions in the document. Stop the\n // request, then reject the suggestions, or just close an idle prompt menu.\n useEffect(() => {\n if (aiEnabled || !hasAiExtension) return;\n const ai = editor.getExtension(AIExtension);\n if (!ai) return;\n const dismiss = async () => {\n const menu = ai.store.state.aiMenuState;\n if (menu === \"closed\") return;\n if (menu.status === \"thinking\" || menu.status === \"ai-writing\") await ai.abort(\"AI disabled\");\n const after = ai.store.state.aiMenuState;\n if (after === \"closed\") return;\n if (after.status === \"user-input\") ai.closeAIMenu();\n else ai.rejectChanges();\n };\n dismiss().catch((error) => console.error(\"Closing the AI menu failed:\", error));\n }, [aiEnabled, hasAiExtension, editor]);\n\n // Publish the outside-the-editor AI trigger. `editor.getExtension(AIExtension)`\n // is BlockNote 0.54's documented lookup by extension factory (core's\n // `getExtension` resolves a function argument through `extensionFactories`),\n // so the instance is reachable without the `useExtension` hook that only\n // works inside the BlockNote context (NarrAIMenu). The menu MUST be opened\n // first: `invokeAI` routes every status update through `setAIResponseStatus`,\n // which is a no-op while `aiMenuState === \"closed\"` — without the open menu\n // the request runs but the accept / reject UI never appears.\n useEffect(() => {\n if (!aiHandleRef) return;\n if (!aiActive) {\n aiHandleRef.current = null;\n return;\n }\n aiHandleRef.current = {\n invokeAi: (type: BlockNoteAiGenerateAction) => {\n // A caller may hold the handle across the render that turns AI off.\n if (!aiRequestRef.current.aiEnabled) return;\n const ai = editor.getExtension(AIExtension);\n if (!ai) return;\n editor.focus();\n const blocks = editor.document;\n const anchor = blocks?.[blocks.length - 1];\n if (anchor?.id) ai.openAIMenuAtBlock(anchor.id);\n void ai.invokeAI({\n userPrompt: type,\n useSelection: false,\n chatRequestOptions: { body: { type } },\n });\n },\n };\n return () => {\n aiHandleRef.current = null;\n };\n }, [aiHandleRef, aiActive, editor]);\n\n // Tracks the hash of the document the editor itself just emitted via onChange.\n // The sync effect below uses it to skip replaceBlocks when the parent's\n // initialContent is just an echo of our own emission (form-controlled flow).\n const lastEmittedHashRef = useRef<string | null>(null);\n\n const handleChange = useCallback(async () => {\n if (!onChange) return;\n const newBlocks = editor.document;\n lastEmittedHashRef.current = JSON.stringify(newBlocks);\n const isEmpty = isDocumentEmpty(newBlocks);\n\n function hasUnresolvedDiffsRecursive(block: any): boolean {\n if (!block || typeof block !== \"object\") return false;\n let diffId = undefined;\n if (block.props && block.props.diffId) diffId = block.props.diffId;\n if (!diffId && block.attrs && block.attrs.diffId) diffId = block.attrs.diffId;\n if (diffId && !acceptedChanges.has(diffId) && !rejectedChanges.has(diffId)) {\n return true;\n }\n\n if (block.content) {\n const contentArr = Array.isArray(block.content) ? block.content : [block.content];\n for (const inline of contentArr) {\n if (inline && typeof inline === \"object\") {\n if (inline.type === \"diffActions\" && inline.props && inline.props.diffIds) {\n const ids =\n typeof inline.props.diffIds === \"string\" ? inline.props.diffIds.split(\",\") : inline.props.diffIds;\n for (const id of ids) {\n const trimmed = (id || \"\").toString().trim();\n if (trimmed && !acceptedChanges.has(trimmed) && !rejectedChanges.has(trimmed)) {\n return true;\n }\n }\n }\n if (inline.props && inline.props.diffId) {\n const diffIdInline = inline.props.diffId;\n if (diffIdInline && !acceptedChanges.has(diffIdInline) && !rejectedChanges.has(diffIdInline)) {\n return true;\n }\n }\n if (inline.children && Array.isArray(inline.children)) {\n for (const child of inline.children) {\n if (hasUnresolvedDiffsRecursive(child)) return true;\n }\n }\n }\n }\n }\n if (Array.isArray(block.children)) {\n for (const child of block.children) {\n if (hasUnresolvedDiffsRecursive(child)) return true;\n }\n }\n return false;\n }\n\n let hasUnresolvedDiff = false;\n if (Array.isArray(newBlocks)) {\n hasUnresolvedDiff = newBlocks.some((block: any) => hasUnresolvedDiffsRecursive(block));\n }\n\n onChange(newBlocks, isEmpty, hasUnresolvedDiff);\n }, [editor, onChange, id, acceptedChanges, rejectedChanges]);\n\n // Utility: deep equality for arrays of blocks\n const areBlocksEqual = (a: any[], b: any[]): boolean => {\n return JSON.stringify(a) === JSON.stringify(b);\n };\n\n // Only initialize from markdownContent once per value, and only if different\n const hasInitializedFromMarkdown = useRef<string | null>(null);\n useEffect(() => {\n const updateContent = async (markdown: string) => {\n const blocks = await editor.tryParseMarkdownToBlocks(markdown);\n if (!areBlocksEqual(blocks, editor.document)) {\n editor.replaceBlocks(editor.document, blocks);\n }\n };\n\n if (markdownContent && hasInitializedFromMarkdown.current !== markdownContent) {\n hasInitializedFromMarkdown.current = markdownContent;\n updateContent(markdownContent).then(() => handleChange());\n }\n }, [markdownContent, editor]);\n\n // Update editor content when diff content changes, but only if different\n // Prevent unnecessary replaceBlocks calls that reset scroll/cursor.\n const previousContentHashRef = useRef<string | null>(null);\n useEffect(() => {\n if (!processedContent || !editor) return;\n // A collaborative editor's content IS the shared Yjs document: it has no initialContent,\n // so processedContent is [] and replaceBlocks would wipe the document it just loaded,\n // and that wipe would be synced to every other writer and stored.\n if (collaboration) return;\n const hash = JSON.stringify(processedContent);\n if (previousContentHashRef.current === hash) return; // no changes\n // Skip replaceBlocks when the new initialContent is just an echo of what\n // the editor itself emitted. Without this, a form-controlled parent\n // (FormBlockNote) round-trips field.value back as initialContent on every\n // keystroke and triggers replaceBlocks, which resets the cursor and can\n // strip just-inserted inline content like mentions.\n if (lastEmittedHashRef.current === hash) {\n previousContentHashRef.current = hash;\n return;\n }\n const currentHash = JSON.stringify(editor.document);\n if (currentHash === hash) {\n previousContentHashRef.current = hash;\n return; // already in sync\n }\n editor.replaceBlocks(editor.document, processedContent as PartialBlock[]);\n previousContentHashRef.current = hash;\n }, [processedContent, editor, collaboration]);\n\n useEffect(() => {\n if (!onWarmMentions || !initialContent || !Array.isArray(initialContent) || initialContent.length === 0) return;\n onWarmMentions(initialContent);\n }, [onWarmMentions, initialContent]);\n\n useEffect(() => {\n docRef.current.getDoc = () => editor?.document ?? [];\n selectionRef.current.getSelectedBlocks = () => {\n const sel = editor?.getSelection?.();\n const blocks = (sel as any)?.blocks;\n return Array.isArray(blocks) ? blocks : [];\n };\n }, [editor]);\n\n // Handle audio received from whisper transcription\n const _handleAudioReceived = useCallback(\n (message: string) => {\n try {\n // Ensure the editor has focus\n const editorElement = editorRef.current?.querySelector('[contenteditable=\"true\"]') as HTMLElement;\n if (editorElement && document.activeElement !== editorElement) {\n editorElement.focus();\n }\n\n // Insert the transcribed text at the current cursor position\n editor.insertInlineContent(message);\n } catch (error) {\n console.error(\"Error inserting transcribed text:\", error);\n // Fallback: try to insert at the end of the document\n try {\n const blocks = editor.document;\n if (blocks.length > 0) {\n const lastBlock = blocks[blocks.length - 1];\n editor.setTextCursorPosition(lastBlock.id, \"end\");\n editor.insertInlineContent(message);\n }\n } catch (fallbackError) {\n console.error(\"Fallback insertion also failed:\", fallbackError);\n }\n }\n },\n [editor],\n );\n\n return (\n <div\n ref={editorRef}\n className={cn(\n bordered ? \"rounded-md border border-input bg-input/20 dark:bg-input/30\" : \"\",\n \"flex flex-col w-full\",\n // Pin BlockNote's font-size so it doesn't jump from 14→16px when the\n // xl-ai AIMenu mounts. The shadcn theme sets `.bn-default-styles {\n // font-size: 16px }` explicitly; outside AI mode the form's text-sm\n // wins via cascade, but ForkYDocExtension re-evaluates the style\n // context on AI activation and the explicit 16px takes over.\n // Phone: an editable field types at 16px, or iPhone Safari zooms the\n // page in on focus. The two ranges never overlap, so neither depends on\n // CSS source order to win.\n isEditable\n ? \"md:[&_.bn-default-styles]:!text-sm max-md:[&_.bn-default-styles]:!text-base\"\n : \"[&_.bn-default-styles]:!text-sm\",\n className,\n )}\n >\n <BlockNoteView\n editor={editor}\n onChange={handleChange}\n editable={isEditable}\n formattingToolbar={false}\n slashMenu={!aiActive}\n // Follow the app theme: hardcoding \"light\" leaves dark (light-theme)\n // text on the dark card, which is nearly unreadable in dark mode.\n theme={resolvedTheme === \"dark\" ? \"dark\" : \"light\"}\n // `className` is applied by BlockNote to both the main `.bn-container`\n // AND `editor.portalElement` (the floating-UI portal root). Gate `p-4`\n // on `.bn-container` so it doesn't add padding to the empty portal\n // element and produce a phantom scrollbar on the wrapper.\n className={cn(\n \"BlockNoteView flex-1\",\n isEditable && \"[&.bn-container]:p-4\",\n // In stretch mode the parent chain caps our height via flex; without\n // these two classes the `.bn-container` keeps `min-height: auto`\n // (its content's intrinsic height) and pushes the bordered wrapper\n // — and the surrounding EditorSheet form — to scroll instead of\n // scrolling internally.\n isEditable && stretch && \"[&.bn-container]:min-h-0 [&.bn-container]:overflow-y-auto\",\n // Phone — these reach the floating menus because BlockNote puts this\n // className on its portal root too. The formatting toolbar (~450px)\n // scrolls sideways instead of losing alignment and link off-screen;\n // the slash menu is capped to the screen and drops its keyboard\n // shortcut badges, which mean nothing on a touch screen.\n \"max-md:[&_.bn-formatting-toolbar]:max-w-[calc(100vw-1rem)] max-md:[&_.bn-formatting-toolbar]:overflow-x-auto max-md:[&_.bn-formatting-toolbar>*]:shrink-0\",\n \"max-md:[&_.bn-suggestion-menu]:max-w-[calc(100vw-1rem)] max-md:[&_.bn-suggestion-menu_[role=option]>[data-position=right]]:hidden\",\n size === \"sm\" && \"small\",\n )}\n >\n <BlockNoteEditorFormattingToolbar showAI={aiActive} />\n {enableMentions && mentionSearchFn && (\n <BlockNoteEditorMentionSuggestionMenu\n editor={editor}\n mentionSearchFn={mentionSearchFn}\n mentionSearchParams={mentionSearchParams}\n suggestionMenuComponent={suggestionMenuComponent}\n />\n )}\n {renderOverlays?.(editor)}\n {enableMentions && mentionResolveFn && (\n <BlockNoteEditorMentionHoverCard containerRef={editorRef} mentionResolveFn={mentionResolveFn} />\n )}\n {aiActive && (\n <SuggestionMenuController\n triggerCharacter=\"/\"\n getItems={async (query: string) =>\n filterSuggestionItems([...getDefaultReactSlashMenuItems(editor), ...getAISlashMenuItems(editor)], query)\n }\n />\n )}\n {aiActive && <AIMenuController aiMenu={() => <NarrAIMenu actions={aiConfig?.actions} />} />}\n </BlockNoteView>\n </div>\n );\n}\n","import { LayoutTemplateIcon, SparklesIcon } from \"lucide-react\";\nimport React from \"react\";\n\n/**\n * Whole-document AI actions an editor can offer in its AI menu when nothing\n * is selected. Each maps to a backend `type` discriminator; NO prompt text\n * lives here. Selection-edit actions (Improve, Fix spelling, …) are separate\n * and always available.\n */\nexport type BlockNoteAiGenerateAction = \"fill-template\" | \"draft-impression\";\n\nexport const DEFAULT_AI_GENERATE_ACTIONS: BlockNoteAiGenerateAction[] = [\"fill-template\"];\n\nexport type AiGenerateMenuItem = {\n key: string;\n title: string;\n aliases: string[];\n /** BlockNote's DefaultReactSuggestionItem types icon as an element, not ReactNode. */\n icon: React.JSX.Element;\n size: \"small\";\n onItemClick: () => void;\n};\n\n/** `titleKey` is a message key; the caller's translator resolves it to the shown title. */\ntype AiGenerateItemDefinition = Omit<AiGenerateMenuItem, \"onItemClick\" | \"title\"> & { titleKey: string };\n\nconst ITEMS: Record<BlockNoteAiGenerateAction, AiGenerateItemDefinition> = {\n \"fill-template\": {\n key: \"generate_from_template\",\n titleKey: \"ui.editor.ai.generate_from_template\",\n aliases: [\"generate\", \"template\", \"fill\"],\n icon: <LayoutTemplateIcon size={18} />,\n size: \"small\",\n },\n \"draft-impression\": {\n key: \"suggest_impression\",\n titleKey: \"ui.editor.ai.suggest_impression\",\n aliases: [\"suggest\", \"impression\"],\n icon: <SparklesIcon size={18} />,\n size: \"small\",\n },\n};\n\nexport function generateActionItems(\n actions: BlockNoteAiGenerateAction[] | undefined,\n invoke: (type: BlockNoteAiGenerateAction) => void,\n translate: (key: string) => string,\n): AiGenerateMenuItem[] {\n return (actions ?? DEFAULT_AI_GENERATE_ACTIONS).map((type) => {\n const { titleKey, ...item } = ITEMS[type];\n return { ...item, title: translate(titleKey), onItemClick: () => invoke(type) };\n });\n}\n","\"use client\";\n\nimport {\n BasicTextStyleButton,\n BlockTypeSelect,\n CreateLinkButton,\n FileCaptionButton,\n FileReplaceButton,\n FormattingToolbar,\n FormattingToolbarController,\n TextAlignButton,\n} from \"@blocknote/react\";\nimport { AIToolbarButton } from \"@blocknote/xl-ai\";\n\nexport function BlockNoteEditorFormattingToolbar({ showAI = false }: { showAI?: boolean }) {\n return (\n <FormattingToolbarController\n formattingToolbar={() => (\n <FormattingToolbar>\n <BlockTypeSelect key={\"blockTypeSelect\"} />\n\n <FileCaptionButton key={\"fileCaptionButton\"} />\n <FileReplaceButton key={\"replaceFileButton\"} />\n\n <BasicTextStyleButton basicTextStyle={\"bold\"} key={\"boldStyleButton\"} />\n <BasicTextStyleButton basicTextStyle={\"italic\"} key={\"italicStyleButton\"} />\n <BasicTextStyleButton basicTextStyle={\"underline\"} key={\"underlineStyleButton\"} />\n <BasicTextStyleButton basicTextStyle={\"strike\"} key={\"strikeStyleButton\"} />\n\n <TextAlignButton textAlignment={\"left\"} key={\"textAlignLeftButton\"} />\n <TextAlignButton textAlignment={\"center\"} key={\"textAlignCenterButton\"} />\n <TextAlignButton textAlignment={\"right\"} key={\"textAlignRightButton\"} />\n\n <CreateLinkButton key={\"createLinkButton\"} />\n\n {showAI ? <AIToolbarButton key={\"aiToolbarButton\"} /> : null}\n </FormattingToolbar>\n )}\n />\n );\n}\n","import type { BlockNoteEditorOptions, PartialBlock } from \"@blocknote/core\";\nimport * as coreLocales from \"@blocknote/core/locales\";\nimport { type CollaborationOptions, withCollaboration } from \"@blocknote/core/yjs\";\n\n/**\n * Live co-editing options for the shared editor: `{ fragment, user: { name, color }, provider?, showCursorLabels? }`.\n * BlockNote 0.55 no longer reads `collaboration` from the editor options; it is applied through\n * `withCollaboration()` from `@blocknote/core/yjs`, which this module does.\n */\nexport type BlockNoteCollaboration = CollaborationOptions;\n\nexport type BuildBlockNoteEditorOptionsParams = {\n placeholder: string;\n schema: any;\n /** The validated initial content. Ignored when `collaboration` is set: the Yjs document is the content. */\n initialContent: PartialBlock[] | undefined;\n uploadFile: (file: File) => Promise<string>;\n /** true: no image uploads (no `uploadFile`, so BlockNote offers no upload). */\n disableUploads?: boolean;\n aiExtension: any;\n coreDictionary: typeof coreLocales.en;\n aiDictionary: any;\n collaboration?: BlockNoteCollaboration;\n};\n\n/**\n * The options handed to `useCreateBlockNote`. Without `collaboration` they are exactly the options the\n * editor has always built; with it, BlockNote's `withCollaboration` adds the collaboration extension,\n * disables the local history (Yjs owns undo) and replaces `initialContent` with its fixed placeholder.\n */\nexport function buildBlockNoteEditorOptions(\n params: BuildBlockNoteEditorOptionsParams,\n): Partial<BlockNoteEditorOptions<any, any, any>> {\n const { aiExtension, coreDictionary, aiDictionary, collaboration } = params;\n\n const options: Partial<BlockNoteEditorOptions<any, any, any>> = {\n placeholders: {\n emptyDocument: params.placeholder,\n },\n schema: params.schema,\n uploadFile: params.disableUploads ? undefined : params.uploadFile,\n extensions: aiExtension ? [aiExtension] : undefined,\n dictionary: aiExtension\n ? { ...coreDictionary, ai: aiDictionary }\n : coreDictionary === coreLocales.en\n ? undefined\n : coreDictionary,\n };\n\n if (collaboration) return withCollaboration({ ...options, collaboration });\n\n return { ...options, initialContent: params.initialContent };\n}\n\n/** An explicit `editable` wins; otherwise the editor is editable when it reports changes. */\nexport function resolveEditable(params: { editable?: boolean; onChange?: unknown }): boolean {\n return params.editable !== undefined ? params.editable : params.onChange !== undefined;\n}\n"]}