@docx-editor.dev/pro 2.9.2 → 2.11.0

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 (78) hide show
  1. package/README.md +1 -7
  2. package/dist/chunk-32RB7HPL.js +3 -0
  3. package/dist/chunk-4HGT2OVX.cjs +3 -0
  4. package/dist/chunk-6DEUT2RQ.js +1 -0
  5. package/dist/chunk-7QSJBMZV.js +3 -0
  6. package/dist/chunk-EMO6YTKO.cjs +1 -0
  7. package/dist/chunk-GDTCNTK7.cjs +1 -0
  8. package/dist/chunk-HJB77VBO.js +1 -0
  9. package/dist/chunk-LUUFBXJ5.cjs +1 -0
  10. package/dist/chunk-NQW54J56.js +1 -0
  11. package/dist/chunk-Q2VBO66F.js +1 -0
  12. package/dist/chunk-Q4YPX2DT.cjs +1 -0
  13. package/dist/chunk-QLZH2Q2C.cjs +1 -0
  14. package/dist/chunk-W3V54DWZ.js +1 -0
  15. package/dist/chunk-YJM6R76M.cjs +3 -0
  16. package/dist/collaboration/hocuspocus.cjs +1 -0
  17. package/dist/collaboration/hocuspocus.d.cts +58 -0
  18. package/dist/collaboration/hocuspocus.d.ts +58 -0
  19. package/dist/collaboration/hocuspocus.js +1 -0
  20. package/dist/collaboration/index.cjs +2 -0
  21. package/dist/collaboration/index.d.cts +22 -0
  22. package/dist/collaboration/index.d.ts +22 -0
  23. package/dist/collaboration/index.js +2 -0
  24. package/dist/collaboration/webrtc.cjs +2 -0
  25. package/dist/collaboration/webrtc.d.cts +86 -0
  26. package/dist/collaboration/webrtc.d.ts +86 -0
  27. package/dist/collaboration/webrtc.js +2 -0
  28. package/dist/collaboration-module-BgRxhW5b.d.cts +45 -0
  29. package/dist/collaboration-module-BgRxhW5b.d.ts +45 -0
  30. package/dist/{define-custom-node-Bk8kFO27.d.cts → define-custom-node-B_p2nr9T.d.cts} +2 -20
  31. package/dist/{define-custom-node-Bk8kFO27.d.ts → define-custom-node-BehI3jWX.d.ts} +2 -20
  32. package/dist/document-session-2B3QFWBQ.cjs +1 -0
  33. package/dist/document-session-6UET6BWT.js +1 -0
  34. package/dist/document-session-DVa53DAw.d.cts +94 -0
  35. package/dist/document-session-DiBuzWwA.d.ts +94 -0
  36. package/dist/document-session-RGNZHMWF.js +1 -0
  37. package/dist/document-session-TU7WVBRB.cjs +1 -0
  38. package/dist/hocuspocus-EUC4BGDD.js +1 -0
  39. package/dist/hocuspocus-YIKH6ENE.cjs +1 -0
  40. package/dist/index.cjs +1 -1
  41. package/dist/index.d.cts +4 -2
  42. package/dist/index.d.ts +4 -2
  43. package/dist/index.js +1 -1
  44. package/dist/react/hocuspocus.cjs +1 -0
  45. package/dist/react/hocuspocus.d.cts +104 -0
  46. package/dist/react/hocuspocus.d.ts +104 -0
  47. package/dist/react/hocuspocus.js +1 -0
  48. package/dist/react/index.cjs +2 -2
  49. package/dist/react/index.d.cts +320 -5
  50. package/dist/react/index.d.ts +320 -5
  51. package/dist/react/index.js +2 -2
  52. package/dist/react/webrtc.cjs +1 -0
  53. package/dist/react/webrtc.d.cts +98 -0
  54. package/dist/react/webrtc.d.ts +98 -0
  55. package/dist/react/webrtc.js +1 -0
  56. package/dist/room-id-BfudXOZz.d.cts +13 -0
  57. package/dist/room-id-BfudXOZz.d.ts +13 -0
  58. package/dist/session-BH7Qgyp6.d.cts +140 -0
  59. package/dist/session-BH7Qgyp6.d.ts +140 -0
  60. package/dist/session-okdqygLg.d.cts +82 -0
  61. package/dist/session-okdqygLg.d.ts +82 -0
  62. package/dist/vue/hocuspocus.cjs +1 -0
  63. package/dist/vue/hocuspocus.d.cts +105 -0
  64. package/dist/vue/hocuspocus.d.ts +105 -0
  65. package/dist/vue/hocuspocus.js +1 -0
  66. package/dist/vue/index.cjs +2 -2
  67. package/dist/vue/index.d.cts +437 -1
  68. package/dist/vue/index.d.ts +437 -1
  69. package/dist/vue/index.js +2 -2
  70. package/dist/vue/webrtc.cjs +1 -0
  71. package/dist/vue/webrtc.d.cts +99 -0
  72. package/dist/vue/webrtc.d.ts +99 -0
  73. package/dist/vue/webrtc.js +1 -0
  74. package/dist/webrtc-36GPPCW4.js +2 -0
  75. package/dist/webrtc-CDIFHCQY.cjs +2 -0
  76. package/package.json +62 -7
  77. package/dist/chunk-4LFF2FXG.cjs +0 -1
  78. package/dist/chunk-TH5PXU6L.js +0 -1
@@ -1,12 +1,20 @@
1
- import { a as CustomNodeDefinition, b as ActivatedCustomNode, A as AnyCustomNodeDefinition } from '../define-custom-node-Bk8kFO27.js';
2
- export { P as ProLicenseOptions, j as ReviewModuleOptions, q as reviewModule } from '../define-custom-node-Bk8kFO27.js';
1
+ import { a as CustomNodeDefinition, b as ActivatedCustomNode, A as AnyCustomNodeDefinition } from '../define-custom-node-BehI3jWX.js';
2
+ export { j as ReviewModuleOptions, q as reviewModule } from '../define-custom-node-BehI3jWX.js';
3
+ export { C as CollaborationModuleOptions, P as ProLicenseOptions, c as collaborationModule } from '../collaboration-module-BgRxhW5b.js';
3
4
  import * as react from 'react';
4
5
  import { ReactNode } from 'react';
5
- import { ToolbarTranslate, ReviewAuthorInfo } from '@docx-editor.dev/react';
6
+ import { ToolbarTranslate, ReviewAuthorInfo, DocxEditorRootProps } from '@docx-editor.dev/react';
6
7
  import { ReviewItemPlacement, ReviewActivationOptions, ReviewItemQuery, Editor } from '@docx-editor.dev/core/contracts/editor';
7
8
  export { ReviewActivationOptions } from '@docx-editor.dev/core/contracts/editor';
8
- import '@docx-editor.dev/core/editor';
9
+ import { CollaborationParticipant, CollaborationRemoteSelection, CollaborationStatus, CollaborationFailure } from '@docx-editor.dev/core/collaboration';
10
+ export { CollaborationFailure, CollaborationFailureCode, CollaborationIdentity, CollaborationParticipant, CollaborationRemoteSelection, CollaborationRemoteSelectionAddress, CollaborationSelectionKind, CollaborationStatus, CollaborationStatusSnapshot } from '@docx-editor.dev/core/collaboration';
11
+ import { C as CollaborationSession } from '../session-BH7Qgyp6.js';
12
+ export { a as CollaborationBootstrap, b as CollaborationIdentityUpdate } from '../session-BH7Qgyp6.js';
13
+ import { EditorModule } from '@docx-editor.dev/core/editor';
14
+ import { C as CreateDocumentCollaborationOptions } from '../document-session-DiBuzWwA.js';
9
15
  import '@docx-editor.dev/core/store';
16
+ import 'yjs';
17
+ import 'y-protocols/awareness';
10
18
 
11
19
  /**
12
20
  * One card's data plus where it belongs on screen.
@@ -530,6 +538,137 @@ interface DocxEditorReviewNamespace {
530
538
  */
531
539
  declare const DocxEditorReview: DocxEditorReviewNamespace;
532
540
 
541
+ /**
542
+ * What a custom remote-caret label renders with.
543
+ *
544
+ * The renderer mounts inside the adapter's provider tree, so every hook works in it —
545
+ * `useDocxEditor`, `useEditorState`, the review hooks. It has the opened document, not only
546
+ * the collaborator.
547
+ *
548
+ * @public
549
+ */
550
+ interface CollaborationCaretLabelRenderProps {
551
+ /** The remote selection this label marks, resolved into this replica's addresses. */
552
+ readonly selection: CollaborationRemoteSelection;
553
+ /** The session roster entry for the selection's actor, or null while presence catches up. */
554
+ readonly participant: CollaborationParticipant | null;
555
+ /**
556
+ * The resolved accent: the published colour when the engine can paint it, otherwise the
557
+ * review roster's colour for the name — the same resolution the painted label uses.
558
+ */
559
+ readonly color: string;
560
+ /**
561
+ * The image declared for this collaborator with `DocxEditor.AuthorStyle`, or `undefined`.
562
+ *
563
+ * Presence carries no picture, so this is the host's own declaration, resolved by display
564
+ * name — the same key a comment card resolves. Declare it once and it reaches the caret,
565
+ * the avatar stack and the review card together.
566
+ */
567
+ readonly avatarUrl?: string;
568
+ }
569
+ /**
570
+ * Props for {@link DocxEditorCollaboration}.CaretLabels.
571
+ *
572
+ * The rendered content lands in the engine's label layer, which is furniture: the layer is
573
+ * `aria-hidden` and takes no pointer events. Assistive technology does not read a label,
574
+ * and nothing inside one is clickable or focusable. Keep interactive or announced presence
575
+ * UI in your own chrome, such as the avatar stack.
576
+ *
577
+ * @public
578
+ */
579
+ interface CollaborationCaretLabelsProps {
580
+ /**
581
+ * The session whose collaborators label the carets. Omit it and the part uses the one the
582
+ * editor above holds; `null` renders nothing.
583
+ */
584
+ readonly session?: CollaborationSession | null;
585
+ /**
586
+ * Renders one label's content. Without it the label shows the collaborator's name,
587
+ * matching the engine default, so mounting the part bare changes nothing visible.
588
+ */
589
+ readonly children?: (props: CollaborationCaretLabelRenderProps) => ReactNode;
590
+ }
591
+ /** Render props for {@link DocxEditorCollaboration}.Avatars' per-participant override. @public */
592
+ interface CollaborationAvatarRenderProps {
593
+ readonly participant: CollaborationParticipant;
594
+ /** The resolved accent — published colour, or the review roster's colour for the name. */
595
+ readonly color: string;
596
+ /** The first letter of up to two name words, uppercased. */
597
+ readonly initials: string;
598
+ /** The image declared for this participant with `DocxEditor.AuthorStyle`, or `undefined`. */
599
+ readonly avatarUrl?: string;
600
+ }
601
+ /** Props for {@link DocxEditorCollaboration}.Avatars. @public */
602
+ interface CollaborationAvatarsProps {
603
+ /**
604
+ * The session whose participants the stack shows. Omit it and the part uses the one the
605
+ * editor above holds; `null` renders nothing.
606
+ */
607
+ readonly session?: CollaborationSession | null;
608
+ /** Avatars shown before the rest collapse into one "+N" chip. Omit to show everyone. */
609
+ readonly max?: number;
610
+ readonly className?: string;
611
+ /** Renders one participant's avatar in place of the packaged disc. */
612
+ readonly children?: (props: CollaborationAvatarRenderProps) => ReactNode;
613
+ }
614
+ /** Props for {@link DocxEditorCollaboration}.Avatar. @public */
615
+ interface CollaborationAvatarProps {
616
+ readonly participant: CollaborationParticipant;
617
+ readonly className?: string;
618
+ /** Replaces the initials inside the disc; the accent background stays. */
619
+ readonly children?: ReactNode;
620
+ }
621
+ /**
622
+ * One collaborator's avatar: their declared picture, or initials in a disc filled with their
623
+ * resolved accent — the published colour, or the review roster's colour for their name, so
624
+ * the disc matches their tracked changes and comments with no wiring.
625
+ */
626
+ declare function CollaborationAvatar({ participant, className, children }: CollaborationAvatarProps): react.JSX.Element;
627
+ /**
628
+ * The avatar stack: everyone in the room, the local participant first, coloured by the same
629
+ * review-roster derivation the painted presence and the review cards use.
630
+ */
631
+ declare function CollaborationAvatars({ session, max, className, children }: CollaborationAvatarsProps): react.JSX.Element | null;
632
+ /**
633
+ * Host-rendered remote-caret labels.
634
+ *
635
+ * Mount it anywhere inside `DocxEditor.Root`. It registers this tree as the engine's
636
+ * remote-caret label host: the engine keeps creating, positioning and colouring each label,
637
+ * and this part portals the host's content into it — so the content lives in the NORMAL
638
+ * React tree and every provider above this part reaches it. Unmounting restores the
639
+ * engine's default name labels.
640
+ */
641
+ declare function CollaborationCaretLabels({ session, children }: CollaborationCaretLabelsProps): react.JSX.Element | null;
642
+ /**
643
+ * The collaboration presence compound.
644
+ *
645
+ * @public
646
+ */
647
+ interface DocxEditorCollaborationNamespace {
648
+ /** Host-rendered remote-caret labels, with full adapter context inside each label. */
649
+ readonly CaretLabels: typeof CollaborationCaretLabels;
650
+ /** The packaged avatar stack, coloured to match the review module's author colours. */
651
+ readonly Avatars: typeof CollaborationAvatars;
652
+ /** One participant's avatar, for hosts arranging their own presence chrome. */
653
+ readonly Avatar: typeof CollaborationAvatar;
654
+ }
655
+ /**
656
+ * Presence chrome over a live collaboration session.
657
+ *
658
+ * Compose the parts inside `DocxEditor.Root` with the collaboration module registered:
659
+ *
660
+ * @example
661
+ * ```tsx
662
+ * <DocxEditorCollaboration.Avatars session={session} max={4} />
663
+ * <DocxEditorCollaboration.CaretLabels session={session}>
664
+ * {({ selection, color }) => <MyLabel name={selection.name} color={color} />}
665
+ * </DocxEditorCollaboration.CaretLabels>
666
+ * ```
667
+ *
668
+ * @public
669
+ */
670
+ declare const DocxEditorCollaboration: DocxEditorCollaborationNamespace;
671
+
533
672
  /**
534
673
  * Props for {@link CustomNodeChrome}: which definitions to paint, and where activation goes.
535
674
  *
@@ -664,4 +803,180 @@ declare function activatedCustomNodeOf(resolved: ResolvedCustomNodeActivation, e
664
803
  */
665
804
  declare function resolveCustomNodeActivation(target: EventTarget | null, nodes: readonly AnyCustomNodeDefinition[]): ResolvedCustomNodeActivation | null;
666
805
 
667
- export { CustomNodeChrome, type CustomNodeChromeProps, CustomNodeContextMenu, type CustomNodeContextMenuProps, DocxEditorReview, type DocxEditorReviewNamespace, type ResolvedCustomNodeActivation, type ReviewActionProps, type ReviewItemView, type ReviewMarkersProps, type ReviewPartProps, type ReviewProps, type UseReviewReturn, activatedCustomNodeOf, resolveCustomNodeActivation, useCustomNodeDefinitions, useReview, useReviewAuthor, useReviewItem, useReviewOf, useStackedReviewPositions };
806
+ /** Status returned by {@link useCollaborationStatus}. @public */
807
+ interface UseCollaborationStatusReturn {
808
+ readonly status: CollaborationStatus | 'inactive';
809
+ readonly reason: CollaborationFailure | undefined;
810
+ readonly lastFailure: CollaborationFailure | undefined;
811
+ /**
812
+ * Edits made now reach the room.
813
+ *
814
+ * False while joining, while the transport is down, and after a terminal failure. A host
815
+ * that shows nothing else should show this, because the alternative is a user typing into
816
+ * a replica nobody receives.
817
+ */
818
+ readonly live: boolean;
819
+ /**
820
+ * This replica no longer agrees with the room, and waiting will not fix it.
821
+ *
822
+ * `error` and `destroyed`. The replica refused an update and kept the copy it had, so it is
823
+ * now editing a document the others do not have. The way out is
824
+ * {@link UseHocuspocusCollaborationReturn.rejoin}, not time — which is why this is separate
825
+ * from "not live" rather than folded into it.
826
+ */
827
+ readonly diverged: boolean;
828
+ /**
829
+ * An editor has attached its document port to this replica.
830
+ *
831
+ * False with a live session means the host did not remount the editor when the session
832
+ * appeared — pass `key={session.sessionId}` — so `collaborationModule` never attached and
833
+ * nothing replicates, whatever `status` says.
834
+ */
835
+ readonly attached: boolean;
836
+ }
837
+ /**
838
+ * Reactive status for the collaboration session, with `live` and `diverged` derived.
839
+ *
840
+ * Omit `session` and it reads the one the editor above holds. Pass it explicitly for a
841
+ * session this Root does not own.
842
+ *
843
+ * @public
844
+ */
845
+ declare function useCollaborationStatus(session?: CollaborationSession | null): UseCollaborationStatusReturn;
846
+
847
+ /**
848
+ * Reactive participant roster for the collaboration session.
849
+ *
850
+ * Omit `session` and it reads the one the editor above holds. Returns the same array
851
+ * reference until the roster actually changes, so a memoized consumer does not re-render on
852
+ * unrelated awareness traffic. No session yields a stable empty array.
853
+ *
854
+ * @public
855
+ */
856
+ declare function useCollaborationParticipants(session?: CollaborationSession | null): readonly CollaborationParticipant[];
857
+
858
+ /**
859
+ * The live collaboration session of the editor above this component, or null.
860
+ *
861
+ * The editor already holds the session a `collaborationModule` contributed, so presence
862
+ * chrome reads it from here instead of being handed it: every part and hook in this package
863
+ * takes `session` as an OPTIONAL prop and falls back to this. A host that has one Root and
864
+ * one room never passes it at all.
865
+ *
866
+ * Pass it explicitly when a component sits outside the Root that owns the room, or when one
867
+ * page renders two.
868
+ *
869
+ * @public
870
+ */
871
+ declare function useCollaborationSession(): CollaborationSession | null;
872
+
873
+ /**
874
+ * What this component needs from a room, which every collaboration hook already returns.
875
+ *
876
+ * Structural on purpose: `useHocuspocusCollaboration`, `useWebrtcCollaboration` and
877
+ * `useDocumentCollaboration` all satisfy it, and so does a host that owns its own resources.
878
+ *
879
+ * @public
880
+ */
881
+ interface CollaborationRootSource {
882
+ readonly document: Uint8Array | null;
883
+ readonly modules: readonly EditorModule[];
884
+ readonly session: CollaborationSession | null;
885
+ }
886
+ /**
887
+ * Props for {@link DocxEditorCollaborationRoot}.
888
+ *
889
+ * Everything `DocxEditor.Root` takes except the three this component owns.
890
+ *
891
+ * @public
892
+ */
893
+ interface DocxEditorCollaborationRootProps extends Omit<DocxEditorRootProps, 'document' | 'modules'> {
894
+ /** The room, straight from a collaboration hook. */
895
+ readonly collaboration: CollaborationRootSource;
896
+ /**
897
+ * What to render before the room has a document — while connecting, or after a failure.
898
+ *
899
+ * This component does not decide what "connecting" looks like, so without it nothing
900
+ * renders. Keep branching on the hook's `pending` and `error` for anything more specific.
901
+ */
902
+ readonly fallback?: ReactNode;
903
+ }
904
+ /**
905
+ * A `DocxEditor.Root` wired to a collaboration room.
906
+ *
907
+ * ```tsx
908
+ * const collaboration = useHocuspocusCollaboration({ modules: MODULES, room });
909
+ *
910
+ * <DocxEditorCollaborationRoot collaboration={collaboration} fallback={<p>Connecting…</p>}>
911
+ * <DocxEditor.Toolbar />
912
+ * <DocxEditor.Viewport>
913
+ * <DocxEditor.Content />
914
+ * <DocxEditorCollaboration.CaretLabels />
915
+ * </DocxEditor.Viewport>
916
+ * </DocxEditorCollaborationRoot>
917
+ * ```
918
+ *
919
+ * The presence parts take no `session`: they read it from the editor this mounts.
920
+ *
921
+ * @public
922
+ */
923
+ declare function DocxEditorCollaborationRoot({ collaboration, fallback, author, children, ...rest }: DocxEditorCollaborationRootProps): react.JSX.Element;
924
+
925
+ /**
926
+ * Arguments for {@link UseDocumentCollaborationReturn.connect}: the
927
+ * `createDocumentCollaboration` options. The consumer owns `ydoc`, `awareness`, and
928
+ * whatever provider replicates them.
929
+ *
930
+ * @public
931
+ */
932
+ type UseDocumentCollaborationConnectOptions = CreateDocumentCollaborationOptions;
933
+ /** Input for {@link useDocumentCollaboration}. @public */
934
+ interface UseDocumentCollaborationOptions {
935
+ /**
936
+ * Host modules. The hook adds `collaborationModule` when a room is ready.
937
+ * A host collaboration contribution is a configuration error and throws.
938
+ */
939
+ readonly modules?: readonly EditorModule[];
940
+ /**
941
+ * Connect this room on mount. Omit it and call
942
+ * {@link UseDocumentCollaborationReturn.connect} after the host has a `ydoc` and a room.
943
+ */
944
+ readonly room?: UseDocumentCollaborationConnectOptions | null;
945
+ }
946
+ /** Values {@link useDocumentCollaboration} returns. @public */
947
+ interface UseDocumentCollaborationReturn {
948
+ readonly document: Uint8Array | null;
949
+ readonly modules: readonly EditorModule[];
950
+ readonly session: CollaborationSession | null;
951
+ readonly pending: boolean;
952
+ readonly error: CollaborationFailure | null;
953
+ /**
954
+ * Connect a room. RESOLVES with the failure, or null on success — it does not reject.
955
+ *
956
+ * A rejection carried nothing the resolved value does not, and it made the ordinary call
957
+ * site wrong by default: `onClick={() => connect(options)}` produced an unhandled rejection
958
+ * on every failed connect. `error` reports the same failure for renderers.
959
+ */
960
+ readonly connect: (options: UseDocumentCollaborationConnectOptions) => Promise<CollaborationFailure | null>;
961
+ /**
962
+ * Destroy the session and carry on editing locally.
963
+ *
964
+ * The current bytes live in the editor, not in this hook, so the argument is required:
965
+ * pass `await editor.save()` to keep what the room typed. The consumer still owns `ydoc`
966
+ * and its provider; the hook destroys only the session it created.
967
+ */
968
+ readonly leave: (nextDocument: Uint8Array) => void;
969
+ }
970
+ /**
971
+ * Own a provider-agnostic collaboration session for a React host.
972
+ *
973
+ * The consumer creates the `ydoc`, the awareness, and whatever provider replicates them
974
+ * (WebSocket, WebRTC, offline persistence); this hook owns only the document session over
975
+ * them, with the same StrictMode-safe lifecycle as `useWebrtcCollaboration`. It imports no
976
+ * network provider.
977
+ *
978
+ * @public
979
+ */
980
+ declare function useDocumentCollaboration(options?: UseDocumentCollaborationOptions): UseDocumentCollaborationReturn;
981
+
982
+ export { type CollaborationAvatarProps, type CollaborationAvatarRenderProps, type CollaborationAvatarsProps, type CollaborationCaretLabelRenderProps, type CollaborationCaretLabelsProps, type CollaborationRootSource, CollaborationSession, CreateDocumentCollaborationOptions, CustomNodeChrome, type CustomNodeChromeProps, CustomNodeContextMenu, type CustomNodeContextMenuProps, DocxEditorCollaboration, type DocxEditorCollaborationNamespace, DocxEditorCollaborationRoot, type DocxEditorCollaborationRootProps, DocxEditorReview, type DocxEditorReviewNamespace, type ResolvedCustomNodeActivation, type ReviewActionProps, type ReviewItemView, type ReviewMarkersProps, type ReviewPartProps, type ReviewProps, type UseCollaborationStatusReturn, type UseDocumentCollaborationConnectOptions, type UseDocumentCollaborationOptions, type UseDocumentCollaborationReturn, type UseReviewReturn, activatedCustomNodeOf, resolveCustomNodeActivation, useCollaborationParticipants, useCollaborationSession, useCollaborationStatus, useCustomNodeDefinitions, useDocumentCollaboration, useReview, useReviewAuthor, useReviewItem, useReviewOf, useStackedReviewPositions };
@@ -1,2 +1,2 @@
1
- import {j,e,c,q as q$1,k}from'../chunk-TH5PXU6L.js';export{o as reviewModule}from'../chunk-TH5PXU6L.js';import {createContext,useMemo,useEffect,useCallback,useRef,useContext,useState,isValidElement,cloneElement,useId,Children,useSyncExternalStore,Fragment as Fragment$1}from'react';import {useDocxEditor,useEditorState,useTranslation,ReviewRailContext,useReviewGutter,REVIEW_PANE_GUTTER,useReviewAuthors,Slot,notificationYieldsToTask,useContextMenuTarget,ContextMenuItem}from'@docx-editor.dev/react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {customNodePayloadsByControl}from'@docx-editor.dev/core/store';import {partOfNodeId}from'@docx-editor.dev/core/editor';var Mn=new Set(["List","Markers","AddComment","Draft","Balloon"]),Tn=new Set(["Card","Empty"]);function Pe(e,o){let l=o==="root"?Mn:Tn,r={},s=[],n=a=>{if(Array.isArray(a)){for(let i of a)n(i);return}if(!isValidElement(a)){a!=null&&a!==false&&s.push(a);return}if(a.type===Fragment$1){n(a.props.children);return}let t=a.type.docxReviewPart;t&&l.has(t)?r[t]=a:s.push(a);};return n(e),{parts:r,rest:s}}function ze(e,o){if(!o)return e;let l=e.props.className;return cloneElement(e,{className:`${o}${l?` ${l}`:""}`})}var Dn={scale:96/72,top:0,left:null,compactCardLeft:null},Sn=16,me=300,On=12,ke=600;function Ot(e,o,l,r,s=false){let[n,a]=useState(Dn);return useEffect(()=>{let t=o.current;if(!e||!t)return;let i=t.offsetParent,c=i?.querySelector(".docx-paginated-surface")??null,f=()=>{a(p=>{let w=c&&i?c.getBoundingClientRect():null,b=w&&i?i.getBoundingClientRect():null,g=w&&b&&i?w.right-b.left-i.clientLeft+i.scrollLeft+Sn:null,R={scale:e.getRenderScale(),top:w&&b&&i?w.top-b.top-i.clientTop+i.scrollTop:0,left:g,compactCardLeft:g===null||!i?null:i.scrollLeft+i.clientWidth-g-me-On};return p.scale===R.scale&&p.top===R.top&&p.left===R.left&&p.compactCardLeft===R.compactCardLeft?p:R});};f();let v=new ResizeObserver(f);if(i&&v.observe(i),c&&v.observe(c),!s||!i)return ()=>v.disconnect();let u=0,d=()=>{u===0&&(u=requestAnimationFrame(()=>{u=0,f();}));};return i.addEventListener("scroll",d,{passive:true}),()=>{u!==0&&cancelAnimationFrame(u),i.removeEventListener("scroll",d),v.disconnect();}},[e,o,l,r,s]),n}function Lt(e,o,l){let[r,s]=useState(null);return useEffect(()=>{let n=o.current,a=n?.offsetParent;if(!a)return;let t=0,i=()=>{t=0,s(u=>{let d=a.scrollTop-ke,p=a.scrollTop+a.clientHeight+ke;return u&&u.top===d&&u.bottom===p?u:{top:d,bottom:p}});},c=0,f=()=>{t===0&&(t=requestAnimationFrame(i)),n?.setAttribute("data-scrolling",""),window.clearTimeout(c),c=window.setTimeout(()=>n?.removeAttribute("data-scrolling"),150);};i(),a.addEventListener("scroll",f,{passive:true});let v=new ResizeObserver(f);return v.observe(a),()=>{t!==0&&cancelAnimationFrame(t),window.clearTimeout(c),a.removeEventListener("scroll",f),v.disconnect();}},[e,o,l]),r}function Ht(e){let o=useRef(new WeakMap),l=useRef(new Map),r=useRef(null),s=useCallback((n,a)=>{let t=l.current.get(a);if(!n){t&&(r.current?.unobserve(t),o.current.delete(t),l.current.delete(a));return}typeof ResizeObserver>"u"||(e(a,n.offsetHeight),r.current??=new ResizeObserver(i=>{for(let c of i){let f=o.current.get(c.target);f&&e(f,c.target.offsetHeight);}}),!(t===n&&o.current.get(n)===a)&&(t&&(r.current.unobserve(t),o.current.delete(t)),o.current.set(n,a),l.current.set(a,n),r.current.observe(n)));},[e]);return useEffect(()=>()=>{r.current?.disconnect(),l.current.clear();},[]),s}function $n(e){let o=false;return ()=>{if(!o){if(!notificationYieldsToTask()){e();return}o=true,setTimeout(()=>{o=false,e();},0);}}}function Me(e){let o=useDocxEditor();return qt(o,e)}function qt(e,o){let l=useCallback(R=>{if(!e)return ()=>{};let h=false,N=$n(()=>{h||R();}),E=e.on("change",N),x=e.on("selectionChange",N),M=e.on("error",N);return ()=>{h=true,E(),x(),M();}},[e]),r=useSyncExternalStore(l,()=>e?`${e.getReviewRevision()}:${e.getEditingMode()}`:"none",()=>"none"),s=useMemo(()=>e?e.getReviewItems(o).filter(R=>R.item.kind!=="custom"||R.item.carded):[],[e,r,o]),n=useMemo(()=>s.find(R=>R.isActive)?.key??null,[s]),a=useCallback((R,h)=>e?e.setActiveReviewItem(R,h).ok:false,[e]),t=useCallback(R=>!e||R.kind!=="revision"||R.readOnly?false:e.acceptReviewItem(R.key).ok,[e]),i=useCallback(R=>!e||R.kind!=="revision"||R.readOnly?false:e.rejectReviewItem(R.key).ok,[e]),c=useCallback(R=>!e||R.kind!=="comment"?false:e.setCommentResolved(R.key,true).ok,[e]),f=useCallback(R=>!e||R.kind!=="comment"?false:e.setCommentResolved(R.key,false).ok,[e]),v=e?.getEditingMode()==="viewing"?"the document is open for viewing":null,u=useCallback(R=>!e||R.kind==="custom"||R.kind==="revision"&&R.readOnly?false:e.deleteReviewItem(R.key).ok,[e]),d=useCallback((R,h,N)=>h.trim().length===0||!e?false:e.replyToReviewItem(R.key,h,N).ok,[e]),p=useMemo(()=>e?e.getSelectionPlacement()?.anchorY??null:null,[e,r]),w=useCallback((R,h)=>R.trim().length===0||!e?false:e.addComment(R,h).ok,[e]),b=useMemo(()=>e?e.isReviewPaneOpen():true,[e,r]),g=useCallback(R=>{!e||e.isReviewPaneOpen()===R||e.exec({type:"toggleReviewPane"});},[e]);return useMemo(()=>({items:s,activeKey:n,setActive:a,accept:t,reject:i,resolve:c,reopen:f,commentResolutionDisabledReason:v,remove:u,reply:d,selectionAnchorY:p,comment:w,paneOpen:b,setPaneOpen:g,ready:e!==null&&!e.snapshot().isLoading&&e.snapshot().parseError===null}),[s,n,a,t,i,c,f,v,u,d,p,w,b,g,e])}function Yn(e,o,l={}){let r=l.gap??8,s=l.scale??1,n=l.defaultHeight??0;return useMemo(()=>{let a=new Map,t=Number.NEGATIVE_INFINITY;for(let i of e){let c=i.anchorY===null?Number.isFinite(t)?t:0:Math.max(i.anchorY,t);a.set(i.key,c),t=c+((o.get(i.key)??n)+r)/s;}return a},[e,o,r,s,n])}var Qe=8;function Xe(e,o){return e?.color??`var(--doc-review-author-${o%Qe})`}function ne(e,o,l){return e?{"--doc-review-author-current":Xe(o,l)}:{}}function ve(e,o){return (e?.slot??o)%Qe}function Kt(e,o,l,r){let s=useRef(new Map);return useMemo(()=>{let n=new Map;for(let t of e)n.set(t.author,t);let a=[...o.map(t=>t.author),r?.getConfiguredAuthor()];for(let t of a){if(!t||n.has(t))continue;let i=l.get(t)??0,c=r?.getReviewAuthorStyle(t),f=c?.color??`var(--doc-review-author-${i%Qe})`,v=s.current.get(t),u=v!==void 0&&v.slot===i&&v.color===f&&v.style===c?v:{author:t,slot:i,color:f,...c?{style:c}:{}};s.current.set(t,u),n.set(t,u);}return n},[e,o,l,r])}var q=e=>jsx("svg",{viewBox:"0 -960 960 960",width:16,height:16,"aria-hidden":"true",focusable:"false",children:jsx("path",{d:e,fill:"currentColor"})}),$t="M440-400h80v-120h120v-80H520v-120h-80v120H320v80h120v120ZM80-80v-720q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H240L80-80Zm126-240h594v-480H160v525l46-45Zm-46 0v-480 480Z",Vt="M240-400h480v-80H240v80Zm0-120h480v-80H240v80Zm0-120h480v-80H240v80ZM880-80 720-240H160q-33 0-56.5-23.5T80-320v-480q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v720ZM160-320h594l46 45v-525H160v480Zm0 0v-480 480Z",Bn="M880-80 720-240H160q-33 0-56.5-23.5T80-320v-480q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v720ZM160-320h594l46 45v-525H160v480Zm0 0v-480 480Z",fe="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z",De=()=>jsxs("span",{className:"docx-review__resolved-icon",children:[jsx("span",{className:"docx-review__resolved-comment",children:q(Bn)}),jsx("span",{className:"docx-review__resolved-tick",children:q(fe)})]}),Yt="M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z",Zt="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z",Ft="M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z",Un="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z",jn="M486-160q-76 0-135-45t-85-123l88-38q14 48 48.5 78t85.5 30q42 0 76-20t34-64q0-18-7-33t-19-27h112q5 14 7.5 28.5T694-341q0 86-61.5 133.5T486-160ZM80-520v-80h800v80H80Zm402-360q66 0 116 30t74 84l-88 38q-11-28-38.5-47T480-794q-42 0-72 19t-30 51q0 15 6 27t18 22H272q-6-13-9-27t-3-30q0-70 55-114t167-44Z",Wn="M360-160q-83 0-141.5-58.5T160-360v-360q0-83 58.5-141.5T360-920q83 0 141.5 58.5T560-720v360q0 83-58.5 141.5T360-160Zm0-80q50 0 85-35t35-85v-360q0-50-35-85t-85-35q-50 0-85 35t-35 85v360q0 50 35 85t85 35Zm300 80q29 0 49.5-20.5T730-230q0-22-12.5-40T684-296l-64-32v-232l100 100q23 23 51.5 35.5T832-412v-80q-17 0-32-6.5T773-517L633-657q-12-12-27.5-17.5T573-680h-13v520h100ZM360-720Z",zn="M580-360q-25 0-42.5-17.5T520-420v-160q0-25 17.5-42.5T580-640h160q25 0 42.5 17.5T800-580v260q0 66-47 113t-113 47v-80q33 0 56.5-23.5T720-320v-40H580Zm-360 0q-25 0-42.5-17.5T160-420v-160q0-25 17.5-42.5T220-640h160q25 0 42.5 17.5T440-580v260q0 66-47 113t-113 47v-80q33 0 56.5-23.5T360-320v-40H220Z";function Bt(e){if(e.kind==="comment")return Vt;if(e.kind==="custom")return e.item.icon??zn;switch(e.revisionKind){case "insert":case "moveTo":return Un;case "delete":case "moveFrom":return jn;case "format":return Wn;default:return Vt}}function Jn(e,o){return typeof o!="function"?e:typeof e!="function"?o:l=>{e(l),l.defaultPrevented||o(l);}}function eo(e,o){let l={...e,...o};for(let r of Object.keys(e))/^on[A-Z]/.test(r)?l[r]=Jn(o[r],e[r]):r==="className"?l[r]=[e[r],o[r]].filter(Boolean).join(" "):r==="style"&&(l[r]={...e[r],...o[r]});return l}function Wt(e){return e==="Enter"||e===" "}function to(e){return Wt(e.key)?(e.preventDefault(),e.stopPropagation(),true):false}function jt(e){return e.type==="button"}function no(e,o){return e.type==="a"||o.href!=null}function oo(e,o,l,r){let s=n=>{typeof l=="function"&&l(n);};return {onClick:n=>{typeof e=="function"&&e(n),n.defaultPrevented||s(n),r&&n.preventDefault();},onKeyDown:n=>{if(typeof o=="function"&&o(n),!Wt(n.key))return;n.defaultPrevented||s(n),r&&n.preventDefault();}}}function Q({engineDisabled:e,disabledReason:o,slotProps:l,children:r}){let s=Children.only(r);if(!isValidElement(s))return null;let n=s.props,a=eo(l,n);if(!e){if(!jt(s)){let t=oo(n.onClick,n.onKeyDown,l.onClick,no(s,n));a.onClick=t.onClick,a.onKeyDown=t.onKeyDown;}return cloneElement(s,a)}if(jt(s))a.disabled=true,delete a["aria-disabled"];else {delete a.disabled,a["aria-disabled"]=true,a["data-disabled"]="",a.tabIndex=-1,a.href=void 0,a.role===void 0&&(a.role="button");let t=a.onKeyDown;a.onKeyDown=i=>{to(i)||typeof t=="function"&&t(i);};}return o&&(a.title=o),a.onClick=t=>{t.preventDefault(),t.stopPropagation();},cloneElement(s,a)}var Qt=createContext({key:null,open:()=>{},close:()=>{}});function Xt({items:e,children:o}){let[l,r]=useState(null);useEffect(()=>{l!==null&&!e.some(n=>n.key===l&&n.kind==="comment"&&n.resolved)&&r(null);},[e,l]);let s=useMemo(()=>({key:l,open:n=>r(n),close:()=>r(null)}),[l]);return jsx(Qt.Provider,{value:s,children:o})}function Je(){return useContext(Qt)}function Jt({label:e,statusLabel:o,entryKey:l,onActivate:r,onDeactivate:s,children:n,...a}){let t=Je(),i=useRef(null);return useEffect(()=>{let c=f=>{let v=i.current;v?.open&&f.target instanceof Node&&!v.contains(f.target)&&(t.close(),s());};return document.addEventListener("pointerdown",c,true),()=>document.removeEventListener("pointerdown",c,true)},[t,s]),jsxs("details",{ref:i,...a,open:t.key===l,onToggle:c=>{c.currentTarget.open?(t.open(l),r()):(t.close(),s());},children:[jsxs("summary",{className:"docx-review__resolved-toggle","aria-label":e,children:[jsx("span",{className:"docx-review__resolved-status",children:o}),De()]}),n]})}function en(e){function o({className:r,asChild:s,hidden:n,children:a,icon:t}){let i=e.useReview(),c=e.useItem(),f=e.useLabel();if(n||!c||c.kind!=="comment"||c.resolved)return null;let v=f("comments.resolve"),u=i.commentResolutionDisabledReason!==null,d=u?f("editingMode.viewingHint"):null,p={type:"button",className:`docx-review__action${r?` ${r}`:""}`,"data-testid":"review-resolve","aria-label":v,title:d??v,disabled:u,onMouseDown:e.guardMousedown,onClick:w=>{w.stopPropagation(),!u&&i.resolve(c);}};return s?jsx(Q,{engineDisabled:u,disabledReason:d,slotProps:p,children:a}):jsx("button",{...p,children:t??a??q(fe)})}o.docxReviewPart="Resolve";function l({className:r,asChild:s,hidden:n,children:a,icon:t}){let i=e.useReview(),c=e.useItem(),f=e.useLabel();if(n||!c||c.kind!=="comment"||!c.resolved)return null;let v=f("comments.reopen"),u=i.commentResolutionDisabledReason!==null,d=u?f("editingMode.viewingHint"):null,p={type:"button",className:`docx-review__action${r?` ${r}`:""}`,"data-testid":"review-reopen","aria-label":v,title:d??v,disabled:u,onMouseDown:e.guardMousedown,onClick:w=>{w.stopPropagation(),!u&&i.reopen(c);}};return s?jsx(Q,{engineDisabled:u,disabledReason:d,slotProps:p,children:a}):jsx("button",{...p,children:t??a??q(Yt)})}return l.docxReviewPart="Reopen",{ReviewResolve:o,ReviewReopen:l}}function on(e){function o({top:r=0,left:s=null,className:n,hidden:a}){let{review:t,endDraft:i,measure:c,readOnly:f,draftAuthor:v,draftAuthorInfo:u,draftAuthorSlot:d}=e.useRail(),p=e.useLabel(),[w,b]=useState(""),[g,R]=useState(false),h=useRef(null),N=useId();useEffect(()=>{f||h.current?.focus({preventScroll:true});},[]);let E=useCallback(()=>{if(f||w.trim().length===0)return;let x=t.comment(w.trim());R(!x),x&&(b(""),i());},[f,w,t,i]);return a?null:jsx("div",{className:`docx-review__slot${n?` ${n}`:""}${s===null?"":" docx-review__slot--compact"}`,style:{position:"absolute",top:r,...s===null?{}:{left:s,width:me}},ref:x=>{c(x,e.composeKey);},children:jsx("div",{className:"docx-review__card","data-testid":"review-draft","data-draft":"",...v?{"data-review-author":v,"data-review-author-slot":d}:{},style:ne(v??void 0,u,d),children:jsxs("form",{className:"docx-review__reply-box",onSubmit:x=>{x.preventDefault(),E();},children:[jsx("label",{className:"docx-editor-sr-only",htmlFor:N,children:p("comments.addComment")}),jsx("input",{id:N,ref:h,"data-testid":"review-draft-input",className:"docx-review__input",value:w,placeholder:p("comments.addComment"),readOnly:f,...g?{"aria-invalid":true}:{},onChange:x=>{f||(R(false),b(x.target.value));},onKeyDown:x=>{if(x.key==="Escape"){x.preventDefault(),i();return}f||x.key!=="Enter"||(x.preventDefault(),E());}}),jsxs("div",{className:"docx-review__reply-actions",children:[jsx("button",{type:"button","data-testid":"review-draft-cancel",className:"docx-review__text-button",onMouseDown:e.guardMousedown,onClick:i,children:p("common.cancel")}),jsx("button",{type:"submit","data-testid":"review-draft-submit",className:"docx-review__submit",disabled:f||w.trim().length===0,title:f?p("editingMode.viewingHint"):void 0,children:p("common.comment")})]}),g?jsx("span",{className:"docx-review__refused",role:"alert",children:p("review.commentRefused")}):null]})})})}o.docxReviewPart="Draft";function l({className:r,hidden:s,children:n}){let{review:a,readOnly:t}=e.useRail(),i=e.useItem(),c=e.useLabel(),[f,v]=useState(""),[u,d]=useState(false),p=useId(),w=useCallback(()=>{if(!i||t||f.trim().length===0)return;let b=a.reply(i,f.trim());d(!b),b&&v("");},[i,t,f,a]);return s||!i||!i.isActive||i.kind==="comment"&&i.resolved?null:n?jsx(Fragment,{children:n}):jsxs("form",{className:`docx-review__reply-box${r?` ${r}`:""}`,onSubmit:b=>{b.preventDefault(),w();},children:[jsx("label",{className:"docx-editor-sr-only",htmlFor:p,children:c("comments.replyPlaceholder")}),jsx("input",{id:p,"data-testid":"review-reply-input",className:"docx-review__input",value:f,placeholder:c("comments.replyPlaceholder"),readOnly:t,...u?{"aria-invalid":true,"data-refused":""}:{},onChange:b=>{t||(d(false),v(b.target.value));},onClick:b=>b.stopPropagation(),onKeyDown:b=>{t||b.key!=="Enter"||(b.preventDefault(),w());}}),jsxs("div",{className:"docx-review__reply-actions",children:[jsx("button",{type:"button","data-testid":"review-reply-cancel",className:"docx-review__text-button",onMouseDown:e.guardMousedown,onClick:b=>{b.stopPropagation(),v(""),d(false),a.setActive(null);},children:c("common.cancel")}),jsx("button",{type:"submit","data-testid":"review-reply-submit",className:"docx-review__submit",disabled:t||f.trim().length===0,title:t?c("editingMode.viewingHint"):void 0,children:c("review.reply")})]}),u?jsx("span",{className:"docx-review__refused",role:"alert","data-testid":"review-reply-refused",children:c("review.replyRefused")}):null]})}return l.docxReviewPart="Reply",{ReviewDraft:o,ReviewReply:l}}function et(e,o){if(e==="paragraphMark")return o==="delete"?"revisions.paragraphMarkDeleted":o==="moveFrom"?"revisions.paragraphMarkMovedFrom":o==="moveTo"?"revisions.paragraphMarkMovedTo":"revisions.paragraphMarkInserted";switch(e){case "insert":return "review.inserted";case "delete":return "review.deleted";case "replace":return "review.replaced";case "moveFrom":return "review.movedFrom";case "moveTo":return "review.movedTo";case "format":return "revisions.runPropertiesChanged";default:return "review.structural"}}var go=e=>e.isLoading||e.parseError!==null||e.pageSetup==null,ho=e=>e.editingMode==="viewing",ot=createContext(null),P=createContext(null);function xo(){return useContext(P)}function Co(e){let{authorInfo:o}=H();return e===void 0?void 0:o.get(e)}var Le="\0compose",No=72,Eo=64,_o=480,Ao=30,Io=Object.freeze({placement:false});function rt(e,o){return e.kind!=="comment"?false:e.parentId!==void 0?o.has(e.parentId):e.parentRevisionId!==void 0?o.has(e.parentRevisionId):false}function it(e){return new Set(e.map(o=>o.id))}function F(e){let o=e.target?.tagName;o==="INPUT"||o==="SELECT"||o==="TEXTAREA"||e.preventDefault();}function H(){let e=useContext(ot);return e||Po}function K(){let{t:e}=useContext(ot)??{},{t:o}=useTranslation();return useCallback(l=>e?.(l)??o(l),[e,o])}var{ReviewResolve:cn,ReviewReopen:dn}=en({useReview:()=>H().review,useItem:()=>useContext(P),useLabel:K,guardMousedown:F}),{ReviewDraft:un,ReviewReply:mn}=on({useRail:H,useItem:()=>useContext(P),useLabel:K,guardMousedown:F,composeKey:Le}),Po={t:void 0,cardClassName:void 0,readOnly:false,review:{items:[],activeKey:null,setActive:()=>false,accept:()=>false,reject:()=>false,resolve:()=>false,reopen:()=>false,commentResolutionDisabledReason:null,remove:()=>false,reply:()=>false,selectionAnchorY:null,comment:()=>false,paneOpen:true,setPaneOpen:()=>{},ready:false},allItems:[],authorSlots:new Map,authorInfo:new Map,draftAuthor:null,draftAuthorInfo:void 0,draftAuthorSlot:0,byId:new Map,measure:()=>{},beginDraft:()=>{},endDraft:()=>{}};function ko({className:e,furniture:o,asChild:l,hidden:r,children:s,t:n,card:a,preset:t=true,stack:i=true,gap:c=8,filter:f,structural:v=false,formatting:u=false}){let d=useDocxEditor(),p=useEditorState(go),w=useEditorState(ho),b=useMemo(()=>{let y=[];return v||y.push("structural"),u||y.push("format"),y.length>0?y:void 0},[v,u]),g=useMemo(()=>b?{excludeRevisionKinds:b}:void 0,[b]);useEffect(()=>(d?.setReviewActivationExclusions(b??null),()=>d?.setReviewActivationExclusions(null)),[d,b]);let R=Me(Io),h=Me(g),N=h.setPaneOpen,{t:E}=useTranslation(),x=useCallback(y=>n?.(y)??E(y),[n,E]),M=useRef(null),J=useContext(ReviewRailContext);useEffect(()=>J?.register(),[J]);let B=h.paneOpen,le=useReviewGutter(),ee=B&&le.inlineEnd>0&&le.inlineEnd<REVIEW_PANE_GUTTER,Ce=B&&!ee,S=useMemo(()=>f?h.items.filter(y=>f(y)):h.items,[h.items,f]),V=d?.getConfiguredAuthor()??null,Ne=useMemo(()=>{let y=new Map;for(let C of S)C.author&&!y.has(C.author)&&y.set(C.author,y.size);return V&&!y.has(V)&&y.set(V,y.size),y},[S,V]),vt=useMemo(()=>{let y=new Map;for(let C of S)y.set(C.id,C);return y},[S]),[ft,yn]=useState(()=>new Map),bn=useCallback((y,C)=>{C<=0||yn(A=>{if(A.get(y)===C)return A;let T=new Map(A);return T.set(y,C),T});},[]),pt=Ht(bn),I=Ot(d,M,S,!p&&!r,ee),ce=Lt(d,M,!p&&!r);useEffect(()=>{let y=M.current;if(!d||!y)return;let C=A=>{let T=A.target;if(!(T instanceof Node)||y.contains(T))return;let D=y.offsetParent;!D||!D.contains(T)||D.querySelector(".docx-paginated-surface")?.contains(T)||d.setActiveReviewItem(null);};return document.addEventListener("mousedown",C,true),()=>document.removeEventListener("mousedown",C,true)},[d,p,r]);let[Y,Ye]=useState(null),Ze=useRef(null),U=useCallback(()=>{let y=Ze.current;y&&(y.editor.releaseSelection(y.pin),Ze.current=null);},[]),Ee=useCallback(()=>{if(!d||w)return;let y=d.getSelectionPlacement()?.anchorY??null;if(y===null)return;U();let C=d.retainSelection();C&&(Ze.current={editor:d,pin:C},N(true),Ye(y));},[d,w,U,N]);useEffect(()=>{if(!(r||w))return J?.registerCommentDraft(Ee)},[Ee,r,w,J]);let wt=useCallback(()=>{U(),Ye(null),d?.focus();},[d,U]);useEffect(()=>U,[U]),useEffect(()=>{B||Y===null||(U(),Ye(null));},[B,Y,U]);let Fe=Y??h.selectionAnchorY,Z=useMemo(()=>{let y=it(S);return S.filter(C=>!rt(C,y))},[S]),Rt=useMemo(()=>{if(Y===null)return Z;let y=Z.findIndex(A=>A.anchorY!==null&&A.anchorY>Y),C={key:Le,anchorY:Y};return y===-1?[...Z,C]:[...Z.slice(0,y),C,...Z.slice(y)]},[Z,Y]),yt=useMemo(()=>{let y=new Map(ft);for(let C of Z){if(y.has(C.key))continue;let A=C.text.length+(C.kind==="revision"?C.replacedText?.length??0:0),T=Math.min(6,Math.max(1,Math.ceil(A/36)));y.set(C.key,64+T*20);}return y},[ft,Z]),{stacked:Be,collapsedKeys:bt}=useMemo(()=>{let y=I.scale,C=new Map,A=new Set,T=Number.NEGATIVE_INFINITY;for(let D of Rt){let Ie=D.anchorY===null?Number.isFinite(T)?T:0:Math.max(D.anchorY,T);C.set(D.key,Ie);let Nn=D.anchorY===null?0:(Ie-D.anchorY)*y,En="isActive"in D&&D.isActive,It=Nn>_o&&!En&&D.key!==Le;It&&A.add(D.key);let _n=It?Eo:yt.get(D.key)??No;T=Ie+(_n+c)/y;}return {stacked:C,collapsedKeys:A}},[Rt,yt,c,I.scale]),Ue=Fe===null?null:I.top+(ee?Fe:Be.get(Le)??Fe)*I.scale,de=a?.className,gn=useReviewAuthors(),je=Kt(gn,S,Ne,d),gt=V?Ne.get(V)??0:0,ht=V?je.get(V):void 0,hn=useMemo(()=>({t:n,cardClassName:de,readOnly:w,review:{...h,items:S},allItems:R.items,authorSlots:Ne,authorInfo:je,draftAuthor:V,draftAuthorInfo:ht,draftAuthorSlot:gt,byId:vt,measure:pt,beginDraft:Ee,endDraft:wt}),[n,de,w,h,R.items,S,Ne,je,V,ht,gt,vt,pt,Ee,wt]);if(r||p)return null;let xt={ref:M,className:`docx-review${e?` ${e}`:""}`,"data-testid":"review-rail","data-count":S.length,"data-open":Ce?"":void 0,"data-compact":ee?"":void 0,role:"complementary","aria-label":x("review.ariaLabel"),onMouseDown:F,style:I.left===null?void 0:{left:I.left,right:"auto"}},W=typeof s=="function"?{parts:{},rest:s}:Pe(s,"root"),z=W.parts,ue=(y,C)=>{if(!(y in z))return C;let A=z[y];return !isValidElement(A)||!isValidElement(C)?A:cloneElement(A,{...C.props,...A.props})},Ct=jsxs(Fragment,{children:[t||"AddComment"in z?ue("AddComment",jsx(at,{top:Ue,drafting:Y!==null})):null,!B||Y===null||Ue===null||!t&&!("Draft"in z)?null:ue("Draft",jsx(un,{top:Ue,left:ee?I.compactCardLeft:null})),t||"Balloon"in z?ue("Balloon",jsx(lt,{})):null]}),xn=jsx(He,{stack:i,positions:Be,collapsed:bt,scale:I.scale,offset:I.top,window:ce,children:W.rest}),Nt=jsx(st,{scale:I.scale,offset:I.top,window:ce}),G=ee?Z.find(y=>y.key===h.activeKey)??null:null,Et=G===null?null:G.anchorY!==null?I.top+G.anchorY*I.scale:ce!==null?ce.top+ke+24:null,_e=l?null:W.rest,Ae=typeof _e=="function"?null:Pe(_e,"list"),_t=typeof _e=="function"?G&&_e(G):Ae?.parts.Card&&isValidElement(Ae.parts.Card)?ze(Ae.parts.Card,de):t?jsx(qe,{...de?{className:de}:{},children:Ae?.rest}):null,At=G&&Et!==null&&I.compactCardLeft!==null&&_t?jsx(P.Provider,{value:G,children:jsx("div",{className:"docx-review__slot docx-review__slot--compact","data-testid":"review-compact-card",style:{position:"absolute",top:Et,left:I.compactCardLeft,width:me},children:_t})}):null,Cn=Ce?t||"List"in z?ue("List",xn):typeof W.rest=="function"?null:W.rest:t||"Markers"in z?jsxs(Fragment,{children:[ue("Markers",Nt),At]}):typeof W.rest=="function"?null:W.rest;return jsx(Xt,{items:S,children:jsx(ot.Provider,{value:hn,children:l&&isValidElement(s)?jsx(Slot,{...xt,children:cloneElement(s,void 0,s.props.children,t?Ce?jsx(He,{stack:i,positions:Be,collapsed:bt,scale:I.scale,offset:I.top,window:ce}):jsxs(Fragment,{children:[Nt,At]}):null,Ct)}):jsxs("aside",{...xt,children:[Ce&&o!==void 0?jsx("div",{className:"docx-review__furniture","data-testid":"review-furniture",children:o}):null,Cn,Ct]})})})}function He({stack:e=true,positions:o,collapsed:l,scale:r=1,offset:s=0,window:n=null,children:a,className:t,hidden:i}){let{review:c,measure:f,cardClassName:v}=H();if(i)return null;let u=typeof a=="function"?null:Pe(a,"list"),d=it(c.items),p=c.items.filter(w=>!rt(w,d));return p.length===0?typeof a=="function"?null:u?.parts.Empty??jsx(ct,{}):jsx("div",{className:`docx-review__list${t?` ${t}`:""}`,children:p.map(w=>{let b=e?o?.get(w.key)??w.anchorY:w.anchorY,g=b==null?null:s+b*r;if(g!==null&&n&&(g<n.top||g>n.bottom))return null;let R=g===null?{}:{position:"absolute",top:g};return jsx(P.Provider,{value:w,children:jsx("div",{className:"docx-review__slot",style:R,...l?.has(w.key)?{"data-collapsed":""}:{},ref:h=>{f(h,w.key);},children:typeof a=="function"?a(w):u?.parts.Card&&isValidElement(u.parts.Card)?ze(u.parts.Card,v):jsx(qe,{...v?{className:v}:{},children:u?.rest})})},w.key)})})}He.docxReviewPart="List";function st({scale:e=1,offset:o=0,window:l=null,className:r,hidden:s,icon:n}){let{review:a,authorSlots:t,authorInfo:i}=H(),c=Je(),f=K(),{roots:v,stackedTops:u}=useMemo(()=>{let d=it(a.items),p=a.items.filter(g=>!rt(g,d)),w=new Map,b=Number.NEGATIVE_INFINITY;for(let g of p){if(g.anchorY===null)continue;let R=Math.max(o+g.anchorY*e,b);w.set(g.key,R),b=R+Ao;}return {roots:p,stackedTops:w}},[a.items,o,e]);return s?null:jsx("div",{className:`docx-review__markers${r?` ${r}`:""}`,children:v.map(d=>{let p=u.get(d.key);return p===void 0||l&&(p<l.top||p>l.bottom)?null:jsx("button",{type:"button",className:"docx-review__marker","data-testid":"review-marker","data-kind":d.kind==="revision"?d.revisionKind:d.kind,...d.author?{"data-review-author":d.author,"data-review-author-slot":ve(i.get(d.author),t.get(d.author)??0)}:{},style:{position:"absolute",top:p,...d.author?{"--doc-review-author-current":Xe(i.get(d.author),t.get(d.author)??0)}:{}},title:d.author?`${d.author}: ${d.text}`:d.text,"aria-label":`${f("review.showPane")}: ${d.author?`${d.author}. `:""}${d.text}`,onMouseDown:F,onClick:()=>{d.kind==="comment"&&d.resolved&&c.open(d.key),a.setPaneOpen(true),a.setActive(d.key);},children:(typeof n=="function"?n(d):n)??(d.kind==="comment"&&d.resolved?De():q(Bt(d)))},d.key)})})}st.docxReviewPart="Markers";function at({top:e=null,drafting:o=false,className:l,hidden:r,children:s}){let{beginDraft:n,readOnly:a}=H(),t=K();if(r||o||e===null||a)return null;let i={type:"button",className:`docx-review__add${l?` ${l}`:""}`,"data-testid":"review-add-comment",style:{position:"absolute",top:e},"aria-label":t("common.comment"),title:t("common.comment"),onMouseDown:F,onClick:n};return s?jsx(Slot,{...i,children:s}):jsx("button",{...i,children:q($t)})}at.docxReviewPart="AddComment";function lt({className:e,hidden:o}){let{review:l,allItems:r,authorSlots:s,authorInfo:n}=H(),a=K(),t=useRef(null),[i,c]=useState(null),f=useRef(false);f.current=i!==null,useEffect(()=>{let w=t.current,b=w?.closest(".docx-review"),g=b?.closest(".docx-editor__scroll-container")??b?.offsetParent;if(!w||!b||!g)return;let R=(N,E)=>{let x=b.getBoundingClientRect(),M=N.getBoundingClientRect(),J=N.ownerDocument.defaultView?.innerHeight??1/0,B=Number(N.dataset.start),le=Number(N.dataset.end);c({revisionId:N.dataset.revisionId,author:N.dataset.reviewAuthor??"",...N.dataset.revisionDate!==void 0?{date:N.dataset.revisionDate}:{},...N.dataset.revisionKind!==void 0?{kind:N.dataset.revisionKind}:{},structuralSite:E,...N.dataset.paragraphId!==void 0?{paragraphId:N.dataset.paragraphId}:{},...Number.isFinite(B)?{start:B}:{},...Number.isFinite(le)?{end:le}:{},left:M.left-x.left,top:M.top-x.top,bottom:M.bottom-x.top,above:M.bottom+220>J});},h=N=>{let E=N.target;if(!(E instanceof Element)||w.contains(E))return;let x=E.closest("[data-revision-id]");if(x instanceof HTMLElement&&g.contains(x)){let M=x.classList.contains("docx-table-row--revision");if(x.dataset.revisionKind==="format"||M){R(x,M);return}}f.current&&c(null);};return g.addEventListener("pointerdown",h,true),g.addEventListener("mousedown",h,true),()=>{g.removeEventListener("pointerdown",h,true),g.removeEventListener("mousedown",h,true);}},[]);let v=useMemo(()=>{if(!i)return null;let w=null,b=false,g=null,R=false,h=null,N=false;for(let E of r)if(!(E.kind!=="revision"||E.item.kind!=="revision")){for(let x of E.item.addresses)if(x.id===i.revisionId){if(x.author===i.author){if(x.date===i.date)return E;w===null?w=E:w!==E&&(b=true);}g===null?g=E:g!==E&&(R=true);}if(i.paragraphId!==void 0&&i.start!==void 0&&i.end!==void 0&&(E.revisionKind==="format"||E.revisionKind==="structural")){for(let x of E.item.ranges)if(x.start.paragraphId===i.paragraphId&&x.start.offset<i.end&&x.end.offset>i.start){h===null?h=E:h!==E&&(N=true);break}}}return w!==null&&!b?w:g!==null&&!R?g:h!==null&&!N?h:null},[r,i]),u=v&&(v.revisionKind==="format"||v.revisionKind==="structural")?v:null,d=useRef(false);if(useEffect(()=>{if(u){d.current=true;return}d.current&&(d.current=false,c(null));},[u]),o)return null;let p=i?.kind==="format"?"format":"structural";return jsx("div",{ref:t,className:`docx-review__balloon-root${e?` ${e}`:""}`,children:i===null?null:jsx("div",{className:"docx-review__balloon","data-testid":"review-balloon",style:{left:i.left,top:i.above?i.top-6:i.bottom+6,transform:i.above?"translateY(-100%)":void 0},onMouseDown:F,children:u?jsx(P.Provider,{value:u,children:jsxs("div",{className:"docx-review__card","data-testid":"review-balloon-card","data-kind":u.revisionKind??"revision",...u.author?{"data-review-author":u.author,"data-review-author-slot":ve(n.get(u.author),s.get(u.author)??0)}:{},style:ne(u.author,n.get(u.author),s.get(u.author)??0),onClick:()=>l.setActive(u.key),children:[jsxs("div",{className:"docx-review__head",children:[jsx(Re,{}),jsxs("div",{className:"docx-review__meta",children:[jsx(ye,{}),jsx(be,{})]}),u.kind==="revision"&&!u.readOnly?jsxs("div",{className:"docx-review__actions",children:[jsx(Ke,{}),jsx(Ve,{})]}):null]}),jsx(ge,{})]})}):jsxs("div",{className:"docx-review__card","data-testid":"review-balloon-card","data-kind":p,...i.author?{"data-review-author":i.author,"data-review-author-slot":ve(n.get(i.author),s.get(i.author)??0)}:{},style:ne(i.author,n.get(i.author),s.get(i.author)??0),children:[jsxs("div",{className:"docx-review__head",children:[jsx("span",{className:"docx-review__avatar","aria-hidden":"true",children:Mo(i.author)}),jsxs("div",{className:"docx-review__meta",children:[jsx("span",{className:"docx-review__author",children:i.author||a("comments.unknown")}),i.date?jsx(To,{raw:i.date}):null]})]}),jsx("div",{className:"docx-review__summary",children:jsx("span",{className:"docx-review__label","data-kind":p,children:a(et(p))})})]})})})}lt.docxReviewPart="Balloon";function Mo(e){let o=e.trim().split(/\s+/).filter(Boolean);return o.length===0?"?":o.slice(0,2).map(l=>l[0].toUpperCase()).join("")}function To({raw:e}){let o=new Date(e);return Number.isNaN(o.getTime())?null:jsx("time",{className:"docx-review__time",dateTime:e,children:vn.format(o)})}function ct({className:e,hidden:o,children:l}){let r=K();return o?null:jsx("div",{className:`docx-review__empty${e?` ${e}`:""}`,"data-testid":"review-empty",children:l??r("review.empty")})}ct.docxReviewPart="Empty";function qe({className:e,asChild:o,hidden:l,children:r}){let{review:s,authorSlots:n,authorInfo:a}=H(),t=useContext(P),i=useId(),c=K();if(l||!t)return null;let f=n.get(t.author)??0,v=!o&&t.kind==="comment"&&t.resolved,u={className:`docx-review__card${e?` ${e}`:""}`,"data-testid":"review-card",...v?{}:{"aria-labelledby":`${i}-author ${i}-summary`},"data-kind":t.kind==="revision"?t.revisionKind??"revision":t.kind,...t.author?{"data-review-author":t.author,"data-review-author-slot":ve(a.get(t.author),f)}:{},...t.kind==="custom"&&t.item.kind==="custom"?{"data-node-name":t.item.name}:{},...t.isActive?{"data-active":""}:{},...t.kind==="comment"&&t.resolved?{"data-resolved":""}:{},...v?{"data-resolved-miniature":""}:{},style:ne(t.author,a.get(t.author),f),...v?{}:{tabIndex:0,role:"button"},id:i,...v?{}:{onMouseDown:d=>{d.target?.closest("[data-review-selectable]")||d.currentTarget.focus({preventScroll:true});},onClick:()=>s.setActive(t.key),onKeyDown:d=>{d.target===d.currentTarget&&(d.key!=="Enter"&&d.key!==" "||(d.preventDefault(),s.setActive(t.key)));}}};return o?jsx(Slot,{...u,children:r}):v?jsx(Jt,{...u,label:c("review.showResolvedComment"),statusLabel:c("review.resolved"),entryKey:t.key,onActivate:()=>s.setActive(t.key),onDeactivate:()=>s.setActive(null),children:jsx(an,{children:r})}):jsx("div",{...u,children:jsx(an,{children:r})})}qe.docxReviewPart="Card";function an({children:e}){let o=useContext(P),l=useMemo(()=>Do(e),[e]),r=(n,a)=>n in l?l[n]:a;if(!o)return null;if(o.kind==="custom"&&o.item.kind==="custom"){let n=o.item;return jsxs(Fragment,{children:[jsxs("div",{className:"docx-review__head",children:[r("Avatar",null),jsx("div",{className:"docx-review__meta",children:r("Author",jsx("span",{className:"docx-review__author","data-testid":"review-custom-title",children:n.title}))})]}),r("Summary",n.detail?jsx("div",{className:"docx-review__summary","data-testid":"review-summary","data-review-selectable":"",children:jsx("span",{className:"docx-review__text",children:n.detail})}):null),l.__extra]})}let s=o.kind==="revision"&&!o.readOnly;return jsxs(Fragment,{children:[jsxs("div",{className:"docx-review__head",children:[r("Avatar",jsx(Re,{})),jsxs("div",{className:"docx-review__meta",children:[r("Author",jsx(ye,{})),r("Time",jsx(be,{}))]}),s||o.kind==="comment"?jsxs("div",{className:"docx-review__actions",children:[r("Accept",jsx(Ke,{})),r("Reject",jsx(Ve,{})),r("Resolve",jsx(cn,{})),r("Reopen",jsx(dn,{})),r("Delete",jsx($e,{}))]}):null]}),r("Summary",jsx(ge,{})),r("Replies",jsx(dt,{})),r("Reply",jsx(mn,{})),l.__extra]})}function Do(e){let o={},l=[],r=s=>{if(Array.isArray(s)){s.forEach(r);return}if(!s||typeof s!="object"||!("type"in s)){s&&l.push(s);return}if(s.type===Fragment$1){r(s.props.children);return}let n=s.type.docxReviewPart;n?o[n]=s:l.push(s);};return r(e),l.length>0&&(o.__extra=l),o}function Re({className:e,asChild:o,hidden:l,children:r}){let{authorInfo:s}=H(),n=useContext(P);if(l||!n||r===void 0&&!n.initials)return null;let a={className:`docx-review__avatar${e?` ${e}`:""}`,"data-testid":"review-avatar","aria-hidden":true};if(o)return jsx(Slot,{...a,children:r});let t=s.get(n.author)?.style?.avatarUrl,i=r??(t?jsx("img",{className:"docx-review__avatar-img",src:t,alt:"",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer"}):void 0)??n.initials;return jsx("span",{...a,children:i})}Re.docxReviewPart="Avatar";function ye({className:e,asChild:o,hidden:l,children:r}){let s=useContext(P),n=K();if(l||!s)return null;let a=s.author||n("comments.unknown"),t={className:`docx-review__author${e?` ${e}`:""}`,"data-testid":"review-author"};return o?jsx(Slot,{...t,children:r}):jsx("span",{...t,children:r??a})}ye.docxReviewPart="Author";function be({className:e,asChild:o,hidden:l,children:r}){let s=useContext(P);if(l||!s)return null;let n=s.date;if(!n)return null;let a=new Date(n);if(Number.isNaN(a.getTime()))return null;let t={className:`docx-review__time${e?` ${e}`:""}`,"data-testid":"review-time",dateTime:n};return o?jsx(Slot,{...t,children:r}):jsx("time",{...t,children:r??vn.format(a)})}be.docxReviewPart="Time";var vn=new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});function ge({className:e,asChild:o,hidden:l,children:r}){let s=useContext(P),n=K();if(l||!s)return null;let a=s.text,t=s.kind!=="revision"?null:n(et(s.revisionKind,s.item.markDirection)),i=s.kind==="revision"&&s.revisionKind==="replace",c={className:`docx-review__summary${e?` ${e}`:""}`,"data-testid":"review-summary","data-review-selectable":""};return o?jsx(Slot,{...c,children:r}):jsx("div",{...c,children:r??(i?jsxs("span",{className:"docx-review__text",children:[n("review.replaced")," ",jsxs("span",{className:"docx-review__removed",children:['"',s.replacedText,'"']})," ",n("review.replacedWith")," ",jsxs("span",{className:"docx-review__added",children:['"',a,'"']})]}):jsxs(Fragment,{children:[t?jsx("span",{className:"docx-review__label","data-kind":s.kind==="revision"?s.revisionKind:"revision",children:t}):null,a?jsx("span",{className:"docx-review__text",children:a}):null]}))})}ge.docxReviewPart="Summary";function Ke({className:e,asChild:o,hidden:l,children:r,icon:s}){let{readOnly:n,review:a}=H(),t=useContext(P),i=K();if(l||!t||t.kind!=="revision"||t.readOnly)return null;let c=i("review.accept"),f=n?i("editingMode.viewingHint"):null,v={type:"button",className:`docx-review__action${e?` ${e}`:""}`,"data-testid":"review-accept","aria-label":c,title:f??c,disabled:n,onMouseDown:F,onClick:u=>{u.stopPropagation(),!n&&a.accept(t);}};return o?jsx(Q,{engineDisabled:n,disabledReason:f,slotProps:v,children:r}):jsx("button",{...v,children:s??r??q(fe)})}Ke.docxReviewPart="Accept";function Ve({className:e,asChild:o,hidden:l,children:r,icon:s}){let{readOnly:n,review:a}=H(),t=useContext(P),i=K();if(l||!t||t.kind!=="revision"||t.readOnly)return null;let c=i("review.reject"),f=n?i("editingMode.viewingHint"):null,v={type:"button",className:`docx-review__action${e?` ${e}`:""}`,"data-testid":"review-reject","aria-label":c,title:f??c,disabled:n,onMouseDown:F,onClick:u=>{u.stopPropagation(),!n&&a.reject(t);}};return o?jsx(Q,{engineDisabled:n,disabledReason:f,slotProps:v,children:r}):jsx("button",{...v,children:s??r??q(Zt)})}Ve.docxReviewPart="Reject";function $e({className:e,asChild:o,hidden:l,children:r,icon:s}){let{readOnly:n,review:a}=H(),t=useContext(P),{t:i}=useTranslation();if(l||!t||t.kind==="custom"||t.kind==="revision"&&t.readOnly)return null;let c=t.kind==="comment"?i("review.deleteComment"):i("review.discardChange"),f=n?i("editingMode.viewingHint"):null,v={type:"button",className:`docx-review__action${e?` ${e}`:""}`,"data-testid":"review-delete","aria-label":c,title:f??c,disabled:n,onMouseDown:F,onClick:u=>{u.stopPropagation(),!n&&a.remove(t);}};return o?jsx(Q,{engineDisabled:n,disabledReason:f,slotProps:v,children:r}):jsx("button",{...v,children:s??r??q(Ft)})}$e.docxReviewPart="Delete";function dt({className:e,hidden:o}){let{byId:l}=H(),r=useContext(P);if(o||!r||r.kind==="custom")return null;let s=r.replyIds.map(n=>l.get(n)).filter(n=>n!==void 0);return s.length===0?null:jsx("ol",{className:`docx-review__replies${e?` ${e}`:""}`,children:s.map(n=>jsx(P.Provider,{value:n,children:jsxs("li",{className:"docx-review__reply","data-testid":"review-reply",children:[jsxs("div",{className:"docx-review__head",children:[jsx(Re,{}),jsxs("div",{className:"docx-review__meta",children:[jsx(ye,{}),jsx(be,{})]}),jsx("div",{className:"docx-review__actions",children:jsx($e,{})})]}),jsx(ge,{})]})},n.key))})}dt.docxReviewPart="Replies";var So=Object.assign(ko,{List:He,Empty:ct,Card:qe,Avatar:Re,Author:ye,Time:be,Summary:ge,Accept:Ke,Reject:Ve,Resolve:cn,Reopen:dn,Delete:$e,Replies:dt,Reply:mn,Markers:st,AddComment:at,Draft:un,Balloon:lt});function he(e){let o=useDocxEditor();return useMemo(()=>e||(o?.getCustomNodeDefinitions()??[]).filter(j),[e,o])}var Ko=".docx-content-control-boundary";function se(e,o){let{node:l,definition:r,controlId:s}=e,n=s?o?.getReviewItems().find(i=>i.kind==="custom"&&i.item.id===s):void 0;if(n&&n.kind==="custom"){let i=n.item;return {...l,attrs:i.attrs,text:i.text,...i.data===void 0?{}:{data:i.data},...s?{nodeId:s}:{}}}let a=s?Vo(o,s,r):void 0,t=r.fromDocx?r.fromDocx({attrs:l.attrs,text:"",...a===void 0?{}:{data:a}}):l.attrs;return t===null?null:{...l,attrs:t,...a===void 0?{}:{data:a},...s?{nodeId:s}:{}}}function Vo(e$1,o,l){let r=e$1?.surface;if(!r)return;let s=partOfNodeId(r.session,o),n=customNodePayloadsByControl(r.session.currentPackage(),(s??r.session.part()).name,r.session.part().name).get(o);if(!n)return;let a=e(l.schema,n.data);return a.ok?a.value:void 0}function ae(e,o){let l=e?.closest?.(Ko),r=l?.closest(".docx-content-control-chrome"),s=r?.getAttribute("data-tag"),n=s?c(s):null;if(!l||!n||!s)return null;let a=o.find(t=>t.tagPrefix===n.prefix&&t.name===n.name);return a?{node:{name:n.name,attrs:n.attrs,tag:s,rect:l.getBoundingClientRect()},definition:a,controlId:r?.getAttribute("data-docx-content-control")??null}:null}var ut=".docx-content-control-boundary",Yo=e=>{if(!k.test(e.tagPrefix)||!k.test(e.name))return [];let o=`${e.tagPrefix}:${e.name}`;return [`.docx-content-control-chrome[data-tag="${o}"]`,`.docx-content-control-chrome[data-tag^="${o}?"]`]};function Zo(e){let{onNodeClick:o,onNodeHover:l}=e,r=useDocxEditor(),s=he(e.nodes);return useEffect(()=>{let n=document.createElement("style"),a=[];for(let t of s){let i=Yo(t);if(i.length===0)continue;let c=t.chrome?.color!==void 0&&CSS.supports("color",t.chrome.color)?t.chrome.color:"var(--doc-accent)";a.push(`${i.map(f=>`${f} ${ut}`).join(", ")} {`," pointer-events: auto !important;"," opacity: 1;"," border: none;",` background: color-mix(in srgb, ${c} 12%, transparent);`," border-radius: 6px;"," cursor: default;","}");}return n.textContent=a.join(`
2
- `),document.head.append(n),()=>n.remove()},[s]),useEffect(()=>{let n=null,a=null,t=v=>ae(document.elementFromPoint(v.clientX,v.clientY),s),i=v=>{let u=v.button===0?t(v):null;n=u?.controlId??null,a=u?.node.tag??null;},c=v=>{let u=n,d=a;if(n=null,a=null,d===null)return;let p=t(v);if(!p||p.node.tag!==d||u!==null&&p.controlId!==u)return;let w=se(p,r);w&&(p.definition.onClick?.(w),o?.(w));},f=v=>{let u=ae(v.target,s);if(!u||v.relatedTarget?.closest?.(ut)===v.target.closest(ut))return;let p=se(u,r);p&&(u.definition.onHover?.(p),l?.(p));};return document.addEventListener("pointerdown",i,true),document.addEventListener("pointerup",c,true),document.addEventListener("mouseover",f),()=>{document.removeEventListener("pointerdown",i,true),document.removeEventListener("pointerup",c,true),document.removeEventListener("mouseover",f);}},[s,r,o,l]),null}var Wo=e=>e.editingMode==="viewing";function Rn(e){let{onEditNode:o,onRemoveRefused:l,remove:r=true}=e,s=he(e.nodes),n=useContextMenuTarget(),a=useDocxEditor(),{t}=useTranslation(),i=useMemo(()=>n?ae(n,s):null,[n,s]),c=useMemo(()=>i?se(i,a):null,[i,a]),f=useEditorState(Wo),v=useMemo(()=>!i?.definition.reviewCard||!c?null:i.definition.reviewCard({attrs:c.attrs,text:c.text??"",...c.data===void 0?{}:{data:c.data}}),[i,c]);if(!i||!c)return null;let{definition:u}=i,d=u.label??u.name,p=!f&&(u.onEdit!==void 0||o!==void 0),w=!f&&r&&c.nodeId!==void 0&&a!==null;return !v&&!p&&!w?null:jsxs(Fragment,{children:[v?jsxs("div",{className:"docx-contextmenu__custom-info","data-testid":"custom-node-info",children:[jsx("span",{className:"docx-contextmenu__custom-title",children:v.title}),v.detail?jsx("span",{className:"docx-contextmenu__custom-detail",children:v.detail}):null]}):null,p?jsx(ContextMenuItem,{label:t("contextMenu.editCustomNode",{label:d}),className:"docx-contextmenu__custom-edit",onSelect:()=>{u.onEdit?.(c),o?.(c,u);}}):null,w?jsx(ContextMenuItem,{label:t("contextMenu.removeCustomNode",{label:d}),className:"docx-contextmenu__custom-remove",onSelect:()=>{let b=q$1(a,c.nodeId);b.ok||l?.(c,b.reason);}}):null,jsx("div",{role:"separator",className:"docx-toolbar__menu-separator"})]})}Rn.docxRowPlacement="start";export{Zo as CustomNodeChrome,Rn as CustomNodeContextMenu,So as DocxEditorReview,se as activatedCustomNodeOf,ae as resolveCustomNodeActivation,he as useCustomNodeDefinitions,Me as useReview,Co as useReviewAuthor,xo as useReviewItem,qt as useReviewOf,Yn as useStackedReviewPositions};
1
+ import {j,e,c,q as q$1,k}from'../chunk-NQW54J56.js';export{o as reviewModule}from'../chunk-NQW54J56.js';import {b,a}from'../chunk-HJB77VBO.js';export{b as collaborationModule}from'../chunk-Q2VBO66F.js';import {createContext,useMemo,useEffect,useCallback,useRef,useContext,useState,isValidElement,cloneElement,useId,Children,useSyncExternalStore,Fragment as Fragment$1}from'react';import {useDocxEditor,useEditorState,useTranslation,ReviewRailContext,useReviewGutter,REVIEW_PANE_GUTTER,useReviewAuthors,Slot,notificationYieldsToTask,useContextMenuTarget,ContextMenuItem,DocxEditorRoot}from'@docx-editor.dev/react';import {jsxs,Fragment,jsx}from'react/jsx-runtime';import {createPortal}from'react-dom';import {safeParticipantColor}from'@docx-editor.dev/core/collaboration';import {customNodePayloadsByControl}from'@docx-editor.dev/core/store';import {partOfNodeId}from'@docx-editor.dev/core/editor';var rn=new Set(["List","Markers","AddComment","Draft","Balloon"]),an=new Set(["Card","Empty"]);function De(e,t){let r=t==="root"?rn:an,o={},a=[],i=l=>{if(Array.isArray(l)){for(let s of l)i(s);return}if(!isValidElement(l)){l!=null&&l!==false&&a.push(l);return}if(l.type===Fragment$1){i(l.props.children);return}let n=l.type.docxReviewPart;n&&r.has(n)?o[n]=l:a.push(l);};return i(e),{parts:o,rest:a}}function at(e,t){if(!t)return e;let r=e.props.className;return cloneElement(e,{className:`${t}${r?` ${r}`:""}`})}var sn={scale:96/72,top:0,left:null,compactCardLeft:null},ln=16,ve=300,cn=12,ke=600;function Xt(e,t,r,o,a=false){let[i,l]=useState(sn);return useEffect(()=>{let n=t.current;if(!e||!n)return;let s=n.offsetParent,d=s?.querySelector(".docx-paginated-surface")??null,f=()=>{l(p=>{let w=d&&s?d.getBoundingClientRect():null,R=w&&s?s.getBoundingClientRect():null,C=w&&R&&s?w.right-R.left-s.clientLeft+s.scrollLeft+ln:null,y={scale:e.getRenderScale(),top:w&&R&&s?w.top-R.top-s.clientTop+s.scrollTop:0,left:C,compactCardLeft:C===null||!s?null:s.scrollLeft+s.clientWidth-C-ve-cn};return p.scale===y.scale&&p.top===y.top&&p.left===y.left&&p.compactCardLeft===y.compactCardLeft?p:y});};f();let u=new ResizeObserver(f);if(s&&u.observe(s),d&&u.observe(d),!a||!s)return ()=>u.disconnect();let m=0,c=()=>{m===0&&(m=requestAnimationFrame(()=>{m=0,f();}));};return s.addEventListener("scroll",c,{passive:true}),()=>{m!==0&&cancelAnimationFrame(m),s.removeEventListener("scroll",c),u.disconnect();}},[e,t,r,o,a]),i}function Jt(e,t,r){let[o,a]=useState(null);return useEffect(()=>{let i=t.current,l=i?.offsetParent;if(!l)return;let n=0,s=()=>{n=0,a(m=>{let c=l.scrollTop-ke,p=l.scrollTop+l.clientHeight+ke;return m&&m.top===c&&m.bottom===p?m:{top:c,bottom:p}});},d=0,f=()=>{n===0&&(n=requestAnimationFrame(s)),i?.setAttribute("data-scrolling",""),window.clearTimeout(d),d=window.setTimeout(()=>i?.removeAttribute("data-scrolling"),150);};s(),l.addEventListener("scroll",f,{passive:true});let u=new ResizeObserver(f);return u.observe(l),()=>{n!==0&&cancelAnimationFrame(n),window.clearTimeout(d),l.removeEventListener("scroll",f),u.disconnect();}},[e,t,r]),o}function eo(e){let t=useRef(new WeakMap),r=useRef(new Map),o=useRef(null),a=useCallback((i,l)=>{let n=r.current.get(l);if(!i){n&&(o.current?.unobserve(n),t.current.delete(n),r.current.delete(l));return}typeof ResizeObserver>"u"||(e(l,i.offsetHeight),o.current??=new ResizeObserver(s=>{for(let d of s){let f=t.current.get(d.target);f&&e(f,d.target.offsetHeight);}}),!(n===i&&t.current.get(i)===l)&&(n&&(o.current.unobserve(n),t.current.delete(n)),t.current.set(i,l),r.current.set(l,i),o.current.observe(i)));},[e]);return useEffect(()=>()=>{o.current?.disconnect(),r.current.clear();},[]),a}function pn(e){let t=false;return ()=>{if(!t){if(!notificationYieldsToTask()){e();return}t=true,setTimeout(()=>{t=false,e();},0);}}}function Te(e){let t=useDocxEditor();return to(t,e)}function to(e,t){let r=useCallback(y=>{if(!e)return ()=>{};let g=false,A=pn(()=>{g||y();}),E=e.on("change",A),h=e.on("selectionChange",A),M=e.on("error",A);return ()=>{g=true,E(),h(),M();}},[e]),o=useSyncExternalStore(r,()=>e?`${e.getReviewRevision()}:${e.getEditingMode()}`:"none",()=>"none"),a=useMemo(()=>e?e.getReviewItems(t).filter(y=>y.item.kind!=="custom"||y.item.carded):[],[e,o,t]),i=useMemo(()=>a.find(y=>y.isActive)?.key??null,[a]),l=useCallback((y,g)=>e?e.setActiveReviewItem(y,g).ok:false,[e]),n=useCallback(y=>!e||y.kind!=="revision"||y.readOnly?false:e.acceptReviewItem(y.key).ok,[e]),s=useCallback(y=>!e||y.kind!=="revision"||y.readOnly?false:e.rejectReviewItem(y.key).ok,[e]),d=useCallback(y=>!e||y.kind!=="comment"?false:e.setCommentResolved(y.key,true).ok,[e]),f=useCallback(y=>!e||y.kind!=="comment"?false:e.setCommentResolved(y.key,false).ok,[e]),u=e?.getEditingMode()==="viewing"?"the document is open for viewing":null,m=useCallback(y=>!e||y.kind==="custom"||y.kind==="revision"&&y.readOnly?false:e.deleteReviewItem(y.key).ok,[e]),c=useCallback((y,g,A)=>g.trim().length===0||!e?false:e.replyToReviewItem(y.key,g,A).ok,[e]),p=useMemo(()=>e?e.getSelectionPlacement()?.anchorY??null:null,[e,o]),w=useCallback((y,g)=>y.trim().length===0||!e?false:e.addComment(y,g).ok,[e]),R=useMemo(()=>e?e.isReviewPaneOpen():true,[e,o]),C=useCallback(y=>{!e||e.isReviewPaneOpen()===y||e.exec({type:"toggleReviewPane"});},[e]);return useMemo(()=>({items:a,activeKey:i,setActive:l,accept:n,reject:s,resolve:d,reopen:f,commentResolutionDisabledReason:u,remove:m,reply:c,selectionAnchorY:p,comment:w,paneOpen:R,setPaneOpen:C,ready:e!==null&&!e.snapshot().isLoading&&e.snapshot().parseError===null}),[a,i,l,n,s,d,f,u,m,c,p,w,R,C,e])}function wn(e,t,r={}){let o=r.gap??8,a=r.scale??1,i=r.defaultHeight??0;return useMemo(()=>{let l=new Map,n=Number.NEGATIVE_INFINITY;for(let s of e){let d=s.anchorY===null?Number.isFinite(n)?n:0:Math.max(s.anchorY,n);l.set(s.key,d),n=d+((t.get(s.key)??i)+o)/a;}return l},[e,t,o,a,i])}var st=8;function lt(e,t){return e?.color??`var(--doc-review-author-${t%st})`}function re(e,t,r){return e?{"--doc-review-author-current":lt(t,r)}:{}}function pe(e,t){return (e?.slot??t)%st}function oo(e,t,r,o){let a=useRef(new Map);return useMemo(()=>{let i=new Map;for(let n of e)i.set(n.author,n);let l=[...t.map(n=>n.author),o?.getConfiguredAuthor()];for(let n of l){if(!n||i.has(n))continue;let s=r.get(n)??0,d=o?.getReviewAuthorStyle(n),f=d?.color??`var(--doc-review-author-${s%st})`,u=a.current.get(n),m=u!==void 0&&u.slot===s&&u.color===f&&u.style===d?u:{author:n,slot:s,color:f,...d?{style:d}:{}};a.current.set(n,m),i.set(n,m);}return i},[e,t,r,o])}var $=e=>jsx("svg",{viewBox:"0 -960 960 960",width:16,height:16,"aria-hidden":"true",focusable:"false",children:jsx("path",{d:e,fill:"currentColor"})}),ro="M440-400h80v-120h120v-80H520v-120h-80v120H320v80h120v120ZM80-80v-720q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v480q0 33-23.5 56.5T800-240H240L80-80Zm126-240h594v-480H160v525l46-45Zm-46 0v-480 480Z",no="M240-400h480v-80H240v80Zm0-120h480v-80H240v80Zm0-120h480v-80H240v80ZM880-80 720-240H160q-33 0-56.5-23.5T80-320v-480q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v720ZM160-320h594l46 45v-525H160v480Zm0 0v-480 480Z",bn="M880-80 720-240H160q-33 0-56.5-23.5T80-320v-480q0-33 23.5-56.5T160-880h640q33 0 56.5 23.5T880-800v720ZM160-320h594l46 45v-525H160v480Zm0 0v-480 480Z",we="M382-240 154-468l57-57 171 171 367-367 57 57-424 424Z",Le=()=>jsxs("span",{className:"docx-review__resolved-icon",children:[jsx("span",{className:"docx-review__resolved-comment",children:$(bn)}),jsx("span",{className:"docx-review__resolved-tick",children:$(we)})]}),ao="M480-160q-134 0-227-93t-93-227q0-134 93-227t227-93q69 0 132 28.5T720-690v-110h80v280H520v-80h168q-32-56-87.5-88T480-720q-100 0-170 70t-70 170q0 100 70 170t170 70q77 0 139-44t87-116h84q-28 106-114 173t-196 67Z",io="m256-200-56-56 224-224-224-224 56-56 224 224 224-224 56 56-224 224 224 224-56 56-224-224-224 224Z",so="M280-120q-33 0-56.5-23.5T200-200v-520h-40v-80h200v-40h240v40h200v80h-40v520q0 33-23.5 56.5T680-120H280Zm400-600H280v520h400v-520ZM360-280h80v-360h-80v360Zm160 0h80v-360h-80v360ZM280-720v520-520Z",Cn="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z",gn="M486-160q-76 0-135-45t-85-123l88-38q14 48 48.5 78t85.5 30q42 0 76-20t34-64q0-18-7-33t-19-27h112q5 14 7.5 28.5T694-341q0 86-61.5 133.5T486-160ZM80-520v-80h800v80H80Zm402-360q66 0 116 30t74 84l-88 38q-11-28-38.5-47T480-794q-42 0-72 19t-30 51q0 15 6 27t18 22H272q-6-13-9-27t-3-30q0-70 55-114t167-44Z",hn="M360-160q-83 0-141.5-58.5T160-360v-360q0-83 58.5-141.5T360-920q83 0 141.5 58.5T560-720v360q0 83-58.5 141.5T360-160Zm0-80q50 0 85-35t35-85v-360q0-50-35-85t-85-35q-50 0-85 35t-35 85v360q0 50 35 85t85 35Zm300 80q29 0 49.5-20.5T730-230q0-22-12.5-40T684-296l-64-32v-232l100 100q23 23 51.5 35.5T832-412v-80q-17 0-32-6.5T773-517L633-657q-12-12-27.5-17.5T573-680h-13v520h100ZM360-720Z",xn="M580-360q-25 0-42.5-17.5T520-420v-160q0-25 17.5-42.5T580-640h160q25 0 42.5 17.5T800-580v260q0 66-47 113t-113 47v-80q33 0 56.5-23.5T720-320v-40H580Zm-360 0q-25 0-42.5-17.5T160-420v-160q0-25 17.5-42.5T220-640h160q25 0 42.5 17.5T440-580v260q0 66-47 113t-113 47v-80q33 0 56.5-23.5T360-320v-40H220Z";function lo(e){if(e.kind==="comment")return no;if(e.kind==="custom")return e.item.icon??xn;switch(e.revisionKind){case "insert":case "moveTo":return Cn;case "delete":case "moveFrom":return gn;case "format":return hn;default:return no}}function Pn(e,t){return typeof t!="function"?e:typeof e!="function"?t:r=>{e(r),r.defaultPrevented||t(r);}}function In(e,t){let r={...e,...t};for(let o of Object.keys(e))/^on[A-Z]/.test(o)?r[o]=Pn(t[o],e[o]):o==="className"?r[o]=[e[o],t[o]].filter(Boolean).join(" "):o==="style"&&(r[o]={...e[o],...t[o]});return r}function mo(e){return e==="Enter"||e===" "}function _n(e){return mo(e.key)?(e.preventDefault(),e.stopPropagation(),true):false}function uo(e){return e.type==="button"}function Sn(e,t){return e.type==="a"||t.href!=null}function Mn(e,t,r,o){let a=i=>{typeof r=="function"&&r(i);};return {onClick:i=>{typeof e=="function"&&e(i),i.defaultPrevented||a(i),o&&i.preventDefault();},onKeyDown:i=>{if(typeof t=="function"&&t(i),!mo(i.key))return;i.defaultPrevented||a(i),o&&i.preventDefault();}}}function Q({engineDisabled:e,disabledReason:t,slotProps:r,children:o}){let a=Children.only(o);if(!isValidElement(a))return null;let i=a.props,l=In(r,i);if(!e){if(!uo(a)){let n=Mn(i.onClick,i.onKeyDown,r.onClick,Sn(a,i));l.onClick=n.onClick,l.onKeyDown=n.onKeyDown;}return cloneElement(a,l)}if(uo(a))l.disabled=true,delete l["aria-disabled"];else {delete l.disabled,l["aria-disabled"]=true,l["data-disabled"]="",l.tabIndex=-1,l.href=void 0,l.role===void 0&&(l.role="button");let n=l.onKeyDown;l.onKeyDown=s=>{_n(s)||typeof n=="function"&&n(s);};}return t&&(l.title=t),l.onClick=n=>{n.preventDefault(),n.stopPropagation();},cloneElement(a,l)}var po=createContext({key:null,open:()=>{},close:()=>{}});function wo({items:e,children:t}){let[r,o]=useState(null);useEffect(()=>{r!==null&&!e.some(i=>i.key===r&&i.kind==="comment"&&i.resolved)&&o(null);},[e,r]);let a=useMemo(()=>({key:r,open:i=>o(i),close:()=>o(null)}),[r]);return jsx(po.Provider,{value:a,children:t})}function ct(){return useContext(po)}function yo({label:e,statusLabel:t,entryKey:r,onActivate:o,onDeactivate:a,children:i,...l}){let n=ct(),s=useRef(null);return useEffect(()=>{let d=f=>{let u=s.current;u?.open&&f.target instanceof Node&&!u.contains(f.target)&&(n.close(),a());};return document.addEventListener("pointerdown",d,true),()=>document.removeEventListener("pointerdown",d,true)},[n,a]),jsxs("details",{ref:s,...l,open:n.key===r,onToggle:d=>{d.currentTarget.open?(n.open(r),o()):(n.close(),a());},children:[jsxs("summary",{className:"docx-review__resolved-toggle","aria-label":e,children:[jsx("span",{className:"docx-review__resolved-status",children:t}),Le()]}),i]})}function Ro(e){function t({className:o,asChild:a,hidden:i,children:l,icon:n}){let s=e.useReview(),d=e.useItem(),f=e.useLabel();if(i||!d||d.kind!=="comment"||d.resolved)return null;let u=f("comments.resolve"),m=s.commentResolutionDisabledReason!==null,c=m?f("editingMode.viewingHint"):null,p={type:"button",className:`docx-review__action${o?` ${o}`:""}`,"data-testid":"review-resolve","aria-label":u,title:c??u,disabled:m,onMouseDown:e.guardMousedown,onClick:w=>{w.stopPropagation(),!m&&s.resolve(d);}};return a?jsx(Q,{engineDisabled:m,disabledReason:c,slotProps:p,children:l}):jsx("button",{...p,children:n??l??$(we)})}t.docxReviewPart="Resolve";function r({className:o,asChild:a,hidden:i,children:l,icon:n}){let s=e.useReview(),d=e.useItem(),f=e.useLabel();if(i||!d||d.kind!=="comment"||!d.resolved)return null;let u=f("comments.reopen"),m=s.commentResolutionDisabledReason!==null,c=m?f("editingMode.viewingHint"):null,p={type:"button",className:`docx-review__action${o?` ${o}`:""}`,"data-testid":"review-reopen","aria-label":u,title:c??u,disabled:m,onMouseDown:e.guardMousedown,onClick:w=>{w.stopPropagation(),!m&&s.reopen(d);}};return a?jsx(Q,{engineDisabled:m,disabledReason:c,slotProps:p,children:l}):jsx("button",{...p,children:n??l??$(ao)})}return r.docxReviewPart="Reopen",{ReviewResolve:t,ReviewReopen:r}}function go(e){function t({top:o=0,left:a=null,className:i,hidden:l}){let{review:n,endDraft:s,measure:d,readOnly:f,draftAuthor:u,draftAuthorInfo:m,draftAuthorSlot:c}=e.useRail(),p=e.useLabel(),[w,R]=useState(""),[C,y]=useState(false),g=useRef(null),A=useId();useEffect(()=>{f||g.current?.focus({preventScroll:true});},[]);let E=useCallback(()=>{if(f||w.trim().length===0)return;let h=n.comment(w.trim());y(!h),h&&(R(""),s());},[f,w,n,s]);return l?null:jsx("div",{className:`docx-review__slot${i?` ${i}`:""}${a===null?"":" docx-review__slot--compact"}`,style:{position:"absolute",top:o,...a===null?{}:{left:a,width:ve}},ref:h=>{d(h,e.composeKey);},children:jsx("div",{className:"docx-review__card","data-testid":"review-draft","data-draft":"",...u?{"data-review-author":u,"data-review-author-slot":c}:{},style:re(u??void 0,m,c),children:jsxs("form",{className:"docx-review__reply-box",onSubmit:h=>{h.preventDefault(),E();},children:[jsx("label",{className:"docx-editor-sr-only",htmlFor:A,children:p("comments.addComment")}),jsx("input",{id:A,ref:g,"data-testid":"review-draft-input",className:"docx-review__input",value:w,placeholder:p("comments.addComment"),readOnly:f,...C?{"aria-invalid":true}:{},onChange:h=>{f||(y(false),R(h.target.value));},onKeyDown:h=>{if(h.key==="Escape"){h.preventDefault(),s();return}f||h.key!=="Enter"||(h.preventDefault(),E());}}),jsxs("div",{className:"docx-review__reply-actions",children:[jsx("button",{type:"button","data-testid":"review-draft-cancel",className:"docx-review__text-button",onMouseDown:e.guardMousedown,onClick:s,children:p("common.cancel")}),jsx("button",{type:"submit","data-testid":"review-draft-submit",className:"docx-review__submit",disabled:f||w.trim().length===0,title:f?p("editingMode.viewingHint"):void 0,children:p("common.comment")})]}),C?jsx("span",{className:"docx-review__refused",role:"alert",children:p("review.commentRefused")}):null]})})})}t.docxReviewPart="Draft";function r({className:o,hidden:a,children:i}){let{review:l,readOnly:n}=e.useRail(),s=e.useItem(),d=e.useLabel(),[f,u]=useState(""),[m,c]=useState(false),p=useId(),w=useCallback(()=>{if(!s||n||f.trim().length===0)return;let R=l.reply(s,f.trim());c(!R),R&&u("");},[s,n,f,l]);return a||!s||!s.isActive||s.kind==="comment"&&s.resolved?null:i?jsx(Fragment,{children:i}):jsxs("form",{className:`docx-review__reply-box${o?` ${o}`:""}`,onSubmit:R=>{R.preventDefault(),w();},children:[jsx("label",{className:"docx-editor-sr-only",htmlFor:p,children:d("comments.replyPlaceholder")}),jsx("input",{id:p,"data-testid":"review-reply-input",className:"docx-review__input",value:f,placeholder:d("comments.replyPlaceholder"),readOnly:n,...m?{"aria-invalid":true,"data-refused":""}:{},onChange:R=>{n||(c(false),u(R.target.value));},onClick:R=>R.stopPropagation(),onKeyDown:R=>{n||R.key!=="Enter"||(R.preventDefault(),w());}}),jsxs("div",{className:"docx-review__reply-actions",children:[jsx("button",{type:"button","data-testid":"review-reply-cancel",className:"docx-review__text-button",onMouseDown:e.guardMousedown,onClick:R=>{R.stopPropagation(),u(""),c(false),l.setActive(null);},children:d("common.cancel")}),jsx("button",{type:"submit","data-testid":"review-reply-submit",className:"docx-review__submit",disabled:n||f.trim().length===0,title:n?d("editingMode.viewingHint"):void 0,children:d("review.reply")})]}),m?jsx("span",{className:"docx-review__refused",role:"alert","data-testid":"review-reply-refused",children:d("review.replyRefused")}):null]})}return r.docxReviewPart="Reply",{ReviewDraft:t,ReviewReply:r}}function dt(e,t){if(e==="paragraphMark")return t==="delete"?"revisions.paragraphMarkDeleted":t==="moveFrom"?"revisions.paragraphMarkMovedFrom":t==="moveTo"?"revisions.paragraphMarkMovedTo":"revisions.paragraphMarkInserted";switch(e){case "insert":return "review.inserted";case "delete":return "review.deleted";case "replace":return "review.replaced";case "moveFrom":return "review.movedFrom";case "moveTo":return "review.movedTo";case "format":return "revisions.runPropertiesChanged";default:return "review.structural"}}var Bn=e=>e.isLoading||e.parseError!==null||e.pageSetup==null,zn=e=>e.editingMode==="viewing",ft=createContext(null),_=createContext(null);function Wn(){return useContext(_)}function Gn(e){let{authorInfo:t}=H();return e===void 0?void 0:t.get(e)}var qe="\0compose",Qn=72,Xn=64,Jn=480,er=30,tr=Object.freeze({placement:false});function vt(e,t){return e.kind!=="comment"?false:e.parentId!==void 0?t.has(e.parentId):e.parentRevisionId!==void 0?t.has(e.parentRevisionId):false}function pt(e){return new Set(e.map(t=>t.id))}function Y(e){let t=e.target?.tagName;t==="INPUT"||t==="SELECT"||t==="TEXTAREA"||e.preventDefault();}function H(){let e=useContext(ft);return e||or}function q(){let{t:e}=useContext(ft)??{},{t}=useTranslation();return useCallback(r=>e?.(r)??t(r),[e,t])}var{ReviewResolve:No,ReviewReopen:Po}=Ro({useReview:()=>H().review,useItem:()=>useContext(_),useLabel:q,guardMousedown:Y}),{ReviewDraft:Io,ReviewReply:_o}=go({useRail:H,useItem:()=>useContext(_),useLabel:q,guardMousedown:Y,composeKey:qe}),or={t:void 0,cardClassName:void 0,readOnly:false,review:{items:[],activeKey:null,setActive:()=>false,accept:()=>false,reject:()=>false,resolve:()=>false,reopen:()=>false,commentResolutionDisabledReason:null,remove:()=>false,reply:()=>false,selectionAnchorY:null,comment:()=>false,paneOpen:true,setPaneOpen:()=>{},ready:false},allItems:[],authorSlots:new Map,authorInfo:new Map,draftAuthor:null,draftAuthorInfo:void 0,draftAuthorSlot:0,byId:new Map,measure:()=>{},beginDraft:()=>{},endDraft:()=>{}};function nr({className:e,furniture:t,asChild:r,hidden:o,children:a,t:i,card:l,preset:n=true,stack:s=true,gap:d=8,filter:f,structural:u=false,formatting:m=false}){let c=useDocxEditor(),p=useEditorState(Bn),w=useEditorState(zn),R=useMemo(()=>{let b=[];return u||b.push("structural"),m||b.push("format"),b.length>0?b:void 0},[u,m]),C=useMemo(()=>R?{excludeRevisionKinds:R}:void 0,[R]);useEffect(()=>(c?.setReviewActivationExclusions(R??null),()=>c?.setReviewActivationExclusions(null)),[c,R]);let y=Te(tr),g=Te(C),A=g.setPaneOpen,{t:E}=useTranslation(),h=useCallback(b=>i?.(b)??E(b),[i,E]),M=useRef(null),te=useContext(ReviewRailContext);useEffect(()=>te?.register(),[te]);let Z=g.paneOpen,de=useReviewGutter(),oe=Z&&de.inlineEnd>0&&de.inlineEnd<REVIEW_PANE_GUTTER,Ne=Z&&!oe,T=useMemo(()=>f?g.items.filter(b=>f(b)):g.items,[g.items,f]),K=c?.getConfiguredAuthor()??null,Pe=useMemo(()=>{let b=new Map;for(let x of T)x.author&&!b.has(x.author)&&b.set(x.author,b.size);return K&&!b.has(K)&&b.set(K,b.size),b},[T,K]),It=useMemo(()=>{let b=new Map;for(let x of T)b.set(x.id,x);return b},[T]),[_t,Yo]=useState(()=>new Map),Zo=useCallback((b,x)=>{x<=0||Yo(P=>{if(P.get(b)===x)return P;let D=new Map(P);return D.set(b,x),D});},[]),St=eo(Zo),I=Xt(c,M,T,!p&&!o,oe),ue=Jt(c,M,!p&&!o);useEffect(()=>{let b=M.current;if(!c||!b)return;let x=P=>{let D=P.target;if(!(D instanceof Node)||b.contains(D))return;let k=b.offsetParent;!k||!k.contains(D)||k.querySelector(".docx-paginated-surface")?.contains(D)||c.setActiveReviewItem(null);};return document.addEventListener("mousedown",x,true),()=>document.removeEventListener("mousedown",x,true)},[c,p,o]);let[V,Xe]=useState(null),Je=useRef(null),j=useCallback(()=>{let b=Je.current;b&&(b.editor.releaseSelection(b.pin),Je.current=null);},[]),Ie=useCallback(()=>{if(!c||w)return;let b=c.getSelectionPlacement()?.anchorY??null;if(b===null)return;j();let x=c.retainSelection();x&&(Je.current={editor:c,pin:x},A(true),Xe(b));},[c,w,j,A]);useEffect(()=>{if(!(o||w))return te?.registerCommentDraft(Ie)},[Ie,o,w,te]);let Mt=useCallback(()=>{j(),Xe(null),c?.focus();},[c,j]);useEffect(()=>j,[j]),useEffect(()=>{Z||V===null||(j(),Xe(null));},[Z,V,j]);let et=V??g.selectionAnchorY,F=useMemo(()=>{let b=pt(T);return T.filter(x=>!vt(x,b))},[T]),Dt=useMemo(()=>{if(V===null)return F;let b=F.findIndex(P=>P.anchorY!==null&&P.anchorY>V),x={key:qe,anchorY:V};return b===-1?[...F,x]:[...F.slice(0,b),x,...F.slice(b)]},[F,V]),kt=useMemo(()=>{let b=new Map(_t);for(let x of F){if(b.has(x.key))continue;let P=x.text.length+(x.kind==="revision"?x.replacedText?.length??0:0),D=Math.min(6,Math.max(1,Math.ceil(P/36)));b.set(x.key,64+D*20);}return b},[_t,F]),{stacked:tt,collapsedKeys:Tt}=useMemo(()=>{let b=I.scale,x=new Map,P=new Set,D=Number.NEGATIVE_INFINITY;for(let k of Dt){let Me=k.anchorY===null?Number.isFinite(D)?D:0:Math.max(k.anchorY,D);x.set(k.key,Me);let Go=k.anchorY===null?0:(Me-k.anchorY)*b,Qo="isActive"in k&&k.isActive,Ft=Go>Jn&&!Qo&&k.key!==qe;Ft&&P.add(k.key);let Xo=Ft?Xn:kt.get(k.key)??Qn;D=Me+(Xo+d)/b;}return {stacked:x,collapsedKeys:P}},[Dt,kt,d,I.scale]),ot=et===null?null:I.top+(oe?et:tt.get(qe)??et)*I.scale,me=l?.className,jo=useReviewAuthors(),nt=oo(jo,T,Pe,c),Ot=K?Pe.get(K)??0:0,Lt=K?nt.get(K):void 0,Bo=useMemo(()=>({t:i,cardClassName:me,readOnly:w,review:{...g,items:T},allItems:y.items,authorSlots:Pe,authorInfo:nt,draftAuthor:K,draftAuthorInfo:Lt,draftAuthorSlot:Ot,byId:It,measure:St,beginDraft:Ie,endDraft:Mt}),[i,me,w,g,y.items,T,Pe,nt,K,Lt,Ot,It,St,Ie,Mt]);if(o||p)return null;let Ht={ref:M,className:`docx-review${e?` ${e}`:""}`,"data-testid":"review-rail","data-count":T.length,"data-open":Ne?"":void 0,"data-compact":oe?"":void 0,role:"complementary","aria-label":h("review.ariaLabel"),onMouseDown:Y,style:I.left===null?void 0:{left:I.left,right:"auto"}},z=typeof a=="function"?{parts:{},rest:a}:De(a,"root"),W=z.parts,fe=(b,x)=>{if(!(b in W))return x;let P=W[b];return !isValidElement(P)||!isValidElement(x)?P:cloneElement(P,{...x.props,...P.props})},$t=jsxs(Fragment,{children:[n||"AddComment"in W?fe("AddComment",jsx(yt,{top:ot,drafting:V!==null})):null,!Z||V===null||ot===null||!n&&!("Draft"in W)?null:fe("Draft",jsx(Io,{top:ot,left:oe?I.compactCardLeft:null})),n||"Balloon"in W?fe("Balloon",jsx(Rt,{})):null]}),zo=jsx(Ke,{stack:s,positions:tt,collapsed:Tt,scale:I.scale,offset:I.top,window:ue,children:z.rest}),qt=jsx(wt,{scale:I.scale,offset:I.top,window:ue}),G=oe?F.find(b=>b.key===g.activeKey)??null:null,Kt=G===null?null:G.anchorY!==null?I.top+G.anchorY*I.scale:ue!==null?ue.top+ke+24:null,_e=r?null:z.rest,Se=typeof _e=="function"?null:De(_e,"list"),Ut=typeof _e=="function"?G&&_e(G):Se?.parts.Card&&isValidElement(Se.parts.Card)?at(Se.parts.Card,me):n?jsx(Ue,{...me?{className:me}:{},children:Se?.rest}):null,Vt=G&&Kt!==null&&I.compactCardLeft!==null&&Ut?jsx(_.Provider,{value:G,children:jsx("div",{className:"docx-review__slot docx-review__slot--compact","data-testid":"review-compact-card",style:{position:"absolute",top:Kt,left:I.compactCardLeft,width:ve},children:Ut})}):null,Wo=Ne?n||"List"in W?fe("List",zo):typeof z.rest=="function"?null:z.rest:n||"Markers"in W?jsxs(Fragment,{children:[fe("Markers",qt),Vt]}):typeof z.rest=="function"?null:z.rest;return jsx(wo,{items:T,children:jsx(ft.Provider,{value:Bo,children:r&&isValidElement(a)?jsx(Slot,{...Ht,children:cloneElement(a,void 0,a.props.children,n?Ne?jsx(Ke,{stack:s,positions:tt,collapsed:Tt,scale:I.scale,offset:I.top,window:ue}):jsxs(Fragment,{children:[qt,Vt]}):null,$t)}):jsxs("aside",{...Ht,children:[Ne&&t!==void 0?jsx("div",{className:"docx-review__furniture","data-testid":"review-furniture",children:t}):null,Wo,$t]})})})}function Ke({stack:e=true,positions:t,collapsed:r,scale:o=1,offset:a=0,window:i=null,children:l,className:n,hidden:s}){let{review:d,measure:f,cardClassName:u}=H();if(s)return null;let m=typeof l=="function"?null:De(l,"list"),c=pt(d.items),p=d.items.filter(w=>!vt(w,c));return p.length===0?typeof l=="function"?null:m?.parts.Empty??jsx(bt,{}):jsx("div",{className:`docx-review__list${n?` ${n}`:""}`,children:p.map(w=>{let R=e?t?.get(w.key)??w.anchorY:w.anchorY,C=R==null?null:a+R*o;if(C!==null&&i&&(C<i.top||C>i.bottom))return null;let y=C===null?{}:{position:"absolute",top:C};return jsx(_.Provider,{value:w,children:jsx("div",{className:"docx-review__slot",style:y,...r?.has(w.key)?{"data-collapsed":""}:{},ref:g=>{f(g,w.key);},children:typeof l=="function"?l(w):m?.parts.Card&&isValidElement(m.parts.Card)?at(m.parts.Card,u):jsx(Ue,{...u?{className:u}:{},children:m?.rest})})},w.key)})})}Ke.docxReviewPart="List";function wt({scale:e=1,offset:t=0,window:r=null,className:o,hidden:a,icon:i}){let{review:l,authorSlots:n,authorInfo:s}=H(),d=ct(),f=q(),{roots:u,stackedTops:m}=useMemo(()=>{let c=pt(l.items),p=l.items.filter(C=>!vt(C,c)),w=new Map,R=Number.NEGATIVE_INFINITY;for(let C of p){if(C.anchorY===null)continue;let y=Math.max(t+C.anchorY*e,R);w.set(C.key,y),R=y+er;}return {roots:p,stackedTops:w}},[l.items,t,e]);return a?null:jsx("div",{className:`docx-review__markers${o?` ${o}`:""}`,children:u.map(c=>{let p=m.get(c.key);return p===void 0||r&&(p<r.top||p>r.bottom)?null:jsx("button",{type:"button",className:"docx-review__marker","data-testid":"review-marker","data-kind":c.kind==="revision"?c.revisionKind:c.kind,...c.author?{"data-review-author":c.author,"data-review-author-slot":pe(s.get(c.author),n.get(c.author)??0)}:{},style:{position:"absolute",top:p,...c.author?{"--doc-review-author-current":lt(s.get(c.author),n.get(c.author)??0)}:{}},title:c.author?`${c.author}: ${c.text}`:c.text,"aria-label":`${f("review.showPane")}: ${c.author?`${c.author}. `:""}${c.text}`,onMouseDown:Y,onClick:()=>{c.kind==="comment"&&c.resolved&&d.open(c.key),l.setPaneOpen(true),l.setActive(c.key);},children:(typeof i=="function"?i(c):i)??(c.kind==="comment"&&c.resolved?Le():$(lo(c)))},c.key)})})}wt.docxReviewPart="Markers";function yt({top:e=null,drafting:t=false,className:r,hidden:o,children:a}){let{beginDraft:i,readOnly:l}=H(),n=q();if(o||t||e===null||l)return null;let s={type:"button",className:`docx-review__add${r?` ${r}`:""}`,"data-testid":"review-add-comment",style:{position:"absolute",top:e},"aria-label":n("common.comment"),title:n("common.comment"),onMouseDown:Y,onClick:i};return a?jsx(Slot,{...s,children:a}):jsx("button",{...s,children:$(ro)})}yt.docxReviewPart="AddComment";function Rt({className:e,hidden:t}){let{review:r,allItems:o,authorSlots:a,authorInfo:i}=H(),l=q(),n=useRef(null),[s,d]=useState(null),f=useRef(false);f.current=s!==null,useEffect(()=>{let w=n.current,R=w?.closest(".docx-review"),C=R?.closest(".docx-editor__scroll-container")??R?.offsetParent;if(!w||!R||!C)return;let y=(A,E)=>{let h=R.getBoundingClientRect(),M=A.getBoundingClientRect(),te=A.ownerDocument.defaultView?.innerHeight??1/0,Z=Number(A.dataset.start),de=Number(A.dataset.end);d({revisionId:A.dataset.revisionId,author:A.dataset.reviewAuthor??"",...A.dataset.revisionDate!==void 0?{date:A.dataset.revisionDate}:{},...A.dataset.revisionKind!==void 0?{kind:A.dataset.revisionKind}:{},structuralSite:E,...A.dataset.paragraphId!==void 0?{paragraphId:A.dataset.paragraphId}:{},...Number.isFinite(Z)?{start:Z}:{},...Number.isFinite(de)?{end:de}:{},left:M.left-h.left,top:M.top-h.top,bottom:M.bottom-h.top,above:M.bottom+220>te});},g=A=>{let E=A.target;if(!(E instanceof Element)||w.contains(E))return;let h=E.closest("[data-revision-id]");if(h instanceof HTMLElement&&C.contains(h)){let M=h.classList.contains("docx-table-row--revision");if(h.dataset.revisionKind==="format"||M){y(h,M);return}}f.current&&d(null);};return C.addEventListener("pointerdown",g,true),C.addEventListener("mousedown",g,true),()=>{C.removeEventListener("pointerdown",g,true),C.removeEventListener("mousedown",g,true);}},[]);let u=useMemo(()=>{if(!s)return null;let w=null,R=false,C=null,y=false,g=null,A=false;for(let E of o)if(!(E.kind!=="revision"||E.item.kind!=="revision")){for(let h of E.item.addresses)if(h.id===s.revisionId){if(h.author===s.author){if(h.date===s.date)return E;w===null?w=E:w!==E&&(R=true);}C===null?C=E:C!==E&&(y=true);}if(s.paragraphId!==void 0&&s.start!==void 0&&s.end!==void 0&&(E.revisionKind==="format"||E.revisionKind==="structural")){for(let h of E.item.ranges)if(h.start.paragraphId===s.paragraphId&&h.start.offset<s.end&&h.end.offset>s.start){g===null?g=E:g!==E&&(A=true);break}}}return w!==null&&!R?w:C!==null&&!y?C:g!==null&&!A?g:null},[o,s]),m=u&&(u.revisionKind==="format"||u.revisionKind==="structural")?u:null,c=useRef(false);if(useEffect(()=>{if(m){c.current=true;return}c.current&&(c.current=false,d(null));},[m]),t)return null;let p=s?.kind==="format"?"format":"structural";return jsx("div",{ref:n,className:`docx-review__balloon-root${e?` ${e}`:""}`,children:s===null?null:jsx("div",{className:"docx-review__balloon","data-testid":"review-balloon",style:{left:s.left,top:s.above?s.top-6:s.bottom+6,transform:s.above?"translateY(-100%)":void 0},onMouseDown:Y,children:m?jsx(_.Provider,{value:m,children:jsxs("div",{className:"docx-review__card","data-testid":"review-balloon-card","data-kind":m.revisionKind??"revision",...m.author?{"data-review-author":m.author,"data-review-author-slot":pe(i.get(m.author),a.get(m.author)??0)}:{},style:re(m.author,i.get(m.author),a.get(m.author)??0),onClick:()=>r.setActive(m.key),children:[jsxs("div",{className:"docx-review__head",children:[jsx(be,{}),jsxs("div",{className:"docx-review__meta",children:[jsx(Ce,{}),jsx(ge,{})]}),m.kind==="revision"&&!m.readOnly?jsxs("div",{className:"docx-review__actions",children:[jsx(Ve,{}),jsx(Fe,{})]}):null]}),jsx(he,{})]})}):jsxs("div",{className:"docx-review__card","data-testid":"review-balloon-card","data-kind":p,...s.author?{"data-review-author":s.author,"data-review-author-slot":pe(i.get(s.author),a.get(s.author)??0)}:{},style:re(s.author,i.get(s.author),a.get(s.author)??0),children:[jsxs("div",{className:"docx-review__head",children:[jsx("span",{className:"docx-review__avatar","aria-hidden":"true",children:rr(s.author)}),jsxs("div",{className:"docx-review__meta",children:[jsx("span",{className:"docx-review__author",children:s.author||l("comments.unknown")}),s.date?jsx(ar,{raw:s.date}):null]})]}),jsx("div",{className:"docx-review__summary",children:jsx("span",{className:"docx-review__label","data-kind":p,children:l(dt(p))})})]})})})}Rt.docxReviewPart="Balloon";function rr(e){let t=e.trim().split(/\s+/).filter(Boolean);return t.length===0?"?":t.slice(0,2).map(r=>r[0].toUpperCase()).join("")}function ar({raw:e}){let t=new Date(e);return Number.isNaN(t.getTime())?null:jsx("time",{className:"docx-review__time",dateTime:e,children:So.format(t)})}function bt({className:e,hidden:t,children:r}){let o=q();return t?null:jsx("div",{className:`docx-review__empty${e?` ${e}`:""}`,"data-testid":"review-empty",children:r??o("review.empty")})}bt.docxReviewPart="Empty";function Ue({className:e,asChild:t,hidden:r,children:o}){let{review:a,authorSlots:i,authorInfo:l}=H(),n=useContext(_),s=useId(),d=q();if(r||!n)return null;let f=i.get(n.author)??0,u=!t&&n.kind==="comment"&&n.resolved,m={className:`docx-review__card${e?` ${e}`:""}`,"data-testid":"review-card",...u?{}:{"aria-labelledby":`${s}-author ${s}-summary`},"data-kind":n.kind==="revision"?n.revisionKind??"revision":n.kind,...n.author?{"data-review-author":n.author,"data-review-author-slot":pe(l.get(n.author),f)}:{},...n.kind==="custom"&&n.item.kind==="custom"?{"data-node-name":n.item.name}:{},...n.isActive?{"data-active":""}:{},...n.kind==="comment"&&n.resolved?{"data-resolved":""}:{},...u?{"data-resolved-miniature":""}:{},style:re(n.author,l.get(n.author),f),...u?{}:{tabIndex:0,role:"button"},id:s,...u?{}:{onMouseDown:c=>{c.target?.closest("[data-review-selectable]")||c.currentTarget.focus({preventScroll:true});},onClick:()=>a.setActive(n.key),onKeyDown:c=>{c.target===c.currentTarget&&(c.key!=="Enter"&&c.key!==" "||(c.preventDefault(),a.setActive(n.key)));}}};return t?jsx(Slot,{...m,children:o}):u?jsx(yo,{...m,label:d("review.showResolvedComment"),statusLabel:d("review.resolved"),entryKey:n.key,onActivate:()=>a.setActive(n.key),onDeactivate:()=>a.setActive(null),children:jsx(Ao,{children:o})}):jsx("div",{...m,children:jsx(Ao,{children:o})})}Ue.docxReviewPart="Card";function Ao({children:e}){let t=useContext(_),r=useMemo(()=>ir(e),[e]),o=(i,l)=>i in r?r[i]:l;if(!t)return null;if(t.kind==="custom"&&t.item.kind==="custom"){let i=t.item;return jsxs(Fragment,{children:[jsxs("div",{className:"docx-review__head",children:[o("Avatar",null),jsx("div",{className:"docx-review__meta",children:o("Author",jsx("span",{className:"docx-review__author","data-testid":"review-custom-title",children:i.title}))})]}),o("Summary",i.detail?jsx("div",{className:"docx-review__summary","data-testid":"review-summary","data-review-selectable":"",children:jsx("span",{className:"docx-review__text",children:i.detail})}):null),r.__extra]})}let a=t.kind==="revision"&&!t.readOnly;return jsxs(Fragment,{children:[jsxs("div",{className:"docx-review__head",children:[o("Avatar",jsx(be,{})),jsxs("div",{className:"docx-review__meta",children:[o("Author",jsx(Ce,{})),o("Time",jsx(ge,{}))]}),a||t.kind==="comment"?jsxs("div",{className:"docx-review__actions",children:[o("Accept",jsx(Ve,{})),o("Reject",jsx(Fe,{})),o("Resolve",jsx(No,{})),o("Reopen",jsx(Po,{})),o("Delete",jsx(Ye,{}))]}):null]}),o("Summary",jsx(he,{})),o("Replies",jsx(Ct,{})),o("Reply",jsx(_o,{})),r.__extra]})}function ir(e){let t={},r=[],o=a=>{if(Array.isArray(a)){a.forEach(o);return}if(!a||typeof a!="object"||!("type"in a)){a&&r.push(a);return}if(a.type===Fragment$1){o(a.props.children);return}let i=a.type.docxReviewPart;i?t[i]=a:r.push(a);};return o(e),r.length>0&&(t.__extra=r),t}function be({className:e,asChild:t,hidden:r,children:o}){let{authorInfo:a}=H(),i=useContext(_);if(r||!i||o===void 0&&!i.initials)return null;let l={className:`docx-review__avatar${e?` ${e}`:""}`,"data-testid":"review-avatar","aria-hidden":true};if(t)return jsx(Slot,{...l,children:o});let n=a.get(i.author)?.style?.avatarUrl,s=o??(n?jsx("img",{className:"docx-review__avatar-img",src:n,alt:"",loading:"lazy",decoding:"async",referrerPolicy:"no-referrer"}):void 0)??i.initials;return jsx("span",{...l,children:s})}be.docxReviewPart="Avatar";function Ce({className:e,asChild:t,hidden:r,children:o}){let a=useContext(_),i=q();if(r||!a)return null;let l=a.author||i("comments.unknown"),n={className:`docx-review__author${e?` ${e}`:""}`,"data-testid":"review-author"};return t?jsx(Slot,{...n,children:o}):jsx("span",{...n,children:o??l})}Ce.docxReviewPart="Author";function ge({className:e,asChild:t,hidden:r,children:o}){let a=useContext(_);if(r||!a)return null;let i=a.date;if(!i)return null;let l=new Date(i);if(Number.isNaN(l.getTime()))return null;let n={className:`docx-review__time${e?` ${e}`:""}`,"data-testid":"review-time",dateTime:i};return t?jsx(Slot,{...n,children:o}):jsx("time",{...n,children:o??So.format(l)})}ge.docxReviewPart="Time";var So=new Intl.DateTimeFormat(void 0,{month:"short",day:"numeric",hour:"numeric",minute:"2-digit"});function he({className:e,asChild:t,hidden:r,children:o}){let a=useContext(_),i=q();if(r||!a)return null;let l=a.text,n=a.kind!=="revision"?null:i(dt(a.revisionKind,a.item.markDirection)),s=a.kind==="revision"&&a.revisionKind==="replace",d={className:`docx-review__summary${e?` ${e}`:""}`,"data-testid":"review-summary","data-review-selectable":""};return t?jsx(Slot,{...d,children:o}):jsx("div",{...d,children:o??(s?jsxs("span",{className:"docx-review__text",children:[i("review.replaced")," ",jsxs("span",{className:"docx-review__removed",children:['"',a.replacedText,'"']})," ",i("review.replacedWith")," ",jsxs("span",{className:"docx-review__added",children:['"',l,'"']})]}):jsxs(Fragment,{children:[n?jsx("span",{className:"docx-review__label","data-kind":a.kind==="revision"?a.revisionKind:"revision",children:n}):null,l?jsx("span",{className:"docx-review__text",children:l}):null]}))})}he.docxReviewPart="Summary";function Ve({className:e,asChild:t,hidden:r,children:o,icon:a}){let{readOnly:i,review:l}=H(),n=useContext(_),s=q();if(r||!n||n.kind!=="revision"||n.readOnly)return null;let d=s("review.accept"),f=i?s("editingMode.viewingHint"):null,u={type:"button",className:`docx-review__action${e?` ${e}`:""}`,"data-testid":"review-accept","aria-label":d,title:f??d,disabled:i,onMouseDown:Y,onClick:m=>{m.stopPropagation(),!i&&l.accept(n);}};return t?jsx(Q,{engineDisabled:i,disabledReason:f,slotProps:u,children:o}):jsx("button",{...u,children:a??o??$(we)})}Ve.docxReviewPart="Accept";function Fe({className:e,asChild:t,hidden:r,children:o,icon:a}){let{readOnly:i,review:l}=H(),n=useContext(_),s=q();if(r||!n||n.kind!=="revision"||n.readOnly)return null;let d=s("review.reject"),f=i?s("editingMode.viewingHint"):null,u={type:"button",className:`docx-review__action${e?` ${e}`:""}`,"data-testid":"review-reject","aria-label":d,title:f??d,disabled:i,onMouseDown:Y,onClick:m=>{m.stopPropagation(),!i&&l.reject(n);}};return t?jsx(Q,{engineDisabled:i,disabledReason:f,slotProps:u,children:o}):jsx("button",{...u,children:a??o??$(io)})}Fe.docxReviewPart="Reject";function Ye({className:e,asChild:t,hidden:r,children:o,icon:a}){let{readOnly:i,review:l}=H(),n=useContext(_),{t:s}=useTranslation();if(r||!n||n.kind==="custom"||n.kind==="revision"&&n.readOnly)return null;let d=n.kind==="comment"?s("review.deleteComment"):s("review.discardChange"),f=i?s("editingMode.viewingHint"):null,u={type:"button",className:`docx-review__action${e?` ${e}`:""}`,"data-testid":"review-delete","aria-label":d,title:f??d,disabled:i,onMouseDown:Y,onClick:m=>{m.stopPropagation(),!i&&l.remove(n);}};return t?jsx(Q,{engineDisabled:i,disabledReason:f,slotProps:u,children:o}):jsx("button",{...u,children:a??o??$(so)})}Ye.docxReviewPart="Delete";function Ct({className:e,hidden:t}){let{byId:r}=H(),o=useContext(_);if(t||!o||o.kind==="custom")return null;let a=o.replyIds.map(i=>r.get(i)).filter(i=>i!==void 0);return a.length===0?null:jsx("ol",{className:`docx-review__replies${e?` ${e}`:""}`,children:a.map(i=>jsx(_.Provider,{value:i,children:jsxs("li",{className:"docx-review__reply","data-testid":"review-reply",children:[jsxs("div",{className:"docx-review__head",children:[jsx(be,{}),jsxs("div",{className:"docx-review__meta",children:[jsx(Ce,{}),jsx(ge,{})]}),jsx("div",{className:"docx-review__actions",children:jsx(Ye,{})})]}),jsx(he,{})]})},i.key))})}Ct.docxReviewPart="Replies";var sr=Object.assign(nr,{List:Ke,Empty:bt,Card:Ue,Avatar:be,Author:Ce,Time:ge,Summary:he,Accept:Ve,Reject:Fe,Resolve:No,Reopen:Po,Delete:Ye,Replies:Ct,Reply:_o,Markers:wt,AddComment:yt,Draft:Io,Balloon:Rt});var xe=8;function Mo(e){let t=/^var\(--doc-review-author-(\d{1,2})\)$/.exec(e);return t?Number(t[1])%xe:null}function je(e,t,r,o){let a=new Map(e.map(n=>[n.author,n])),i=new Map,l=new Map;for(let n of t){if(l.has(n.actorId))continue;let s=safeParticipantColor(o?.(n.name));if(s!==void 0){l.set(n.actorId,{color:s,slot:Mo(s)});continue}let d=safeParticipantColor(n.color);if(d!==void 0){l.set(n.actorId,{color:d,slot:null});continue}let f=a.get(n.name),u=safeParticipantColor(r?.(n.name));if(u!==void 0){l.set(n.actorId,{color:u,slot:Mo(u)??(f?f.slot%xe:null)});continue}if(f!==void 0){let c=f.slot%xe;l.set(n.actorId,{color:safeParticipantColor(f.color)??`var(--doc-review-author-${c})`,slot:c});continue}let m=i.get(n.name);m===void 0&&(m=e.length+i.size,i.set(n.name,m)),l.set(n.actorId,{color:`var(--doc-review-author-${m%xe})`,slot:m%xe});}return l}function gt(e,t,r,o){return je(e,[t],r,o).get(t.actorId)}function ht(e){let t=e.trim().split(/\s+/,2),r="";for(let o of t){let a=[...o][0];a!==void 0&&(r+=a.toUpperCase());}return r}function Do(e){return [...e].sort((t,r)=>{if(t.isLocal!==r.isLocal)return t.isLocal?-1:1;let o=t.name.localeCompare(r.name);return o!==0?o:t.actorId<r.actorId?-1:t.actorId>r.actorId?1:0})}function Be(e,t,r){for(let o of e)if(o.author===t)return o.style?.avatarUrl;return r?.(t)?.avatarUrl}var dr=e=>e.collaborationStatus;function J(){let e=useDocxEditor();return useEditorState(dr),e?.collaborationSession()??null}var xt=Object.freeze([]);function fr(e,t){if(e===t)return true;if(e.length!==t.length)return false;for(let r=0;r<e.length;r+=1){let o=e[r],a=t[r];if(o.actorId!==a.actorId||o.name!==a.name||o.color!==a.color||o.role!==a.role||o.isLocal!==a.isLocal)return false}return true}function ko(e,t){if(!e)return t.current=xt,xt;let r=e.participants();return fr(t.current,r)?t.current:(t.current=r,r)}function ze(e){let t=J(),r=e===void 0?t:e,o=useRef(xt);return useSyncExternalStore(a=>r?.subscribeParticipants(()=>a())??(()=>{}),()=>ko(r,o),()=>ko(r,o))}var To=createContext(null);function hr(e){return {"--doc-collaboration-accent":e.color}}function Oo(e){return e!==void 0?{avatarUrl:e}:{}}function Lo({participant:e,className:t,children:r}){let o=useDocxEditor(),a=useReviewAuthors(),l=useContext(To)?.get(e.actorId)??gt(a,e,o?s=>o.presenceColorFor(s):void 0,o?s=>o.getReviewAuthorStyle(s)?.color:void 0),n=xr(e.name);return jsx("span",{className:`docx-collaboration-avatar${t?` ${t}`:""}`,"data-collaboration-avatar":"",...e.isLocal?{"data-local":""}:{},...l.slot!==null?{"data-collaboration-author-slot":l.slot}:{},title:e.name,role:"img","aria-label":e.name,style:hr(l),children:r??(n!==void 0?jsx("img",{className:"docx-collaboration-avatar__image",src:n,alt:""}):ht(e.name))})}function xr(e){let t=useDocxEditor(),r=useReviewAuthors();return Be(r,e,t?o=>t.getReviewAuthorStyle(o):void 0)}function Ar({session:e,max:t,className:r,children:o}){let a=useDocxEditor(),i=ze(e),l=useReviewAuthors(),{t:n}=useTranslation(),s=useMemo(()=>je(l,i,a?p=>a.presenceColorFor(p):void 0,a?p=>a.getReviewAuthorStyle(p)?.color:void 0),[l,i,a]),d=useMemo(()=>{let p=a?R=>a.getReviewAuthorStyle(R):void 0,w=new Map;for(let R of i){if(w.has(R.name))continue;let C=Be(l,R.name,p);C!==void 0&&w.set(R.name,C);}return w},[a,i,l]),f=useMemo(()=>Do(i),[i]);if(f.length===0)return null;let u=t===void 0?f:f.slice(0,Math.max(0,t)),m=f.length-u.length,c=n("collaboration.moreParticipants",{count:m});return jsxs("span",{className:`docx-collaboration-avatars${r?` ${r}`:""}`,"data-collaboration-avatars":"",role:"group","aria-label":n("collaboration.participants"),children:[jsx(To.Provider,{value:s,children:u.map(p=>o?jsx(Fragment$1,{children:o({participant:p,color:s.get(p.actorId).color,initials:ht(p.name),...Oo(d.get(p.name))})},p.actorId):jsx(Lo,{participant:p},p.actorId))}),m>0?jsx("span",{className:"docx-collaboration-avatar","data-collaboration-avatar":"","data-overflow":"",title:c,role:"img","aria-label":c,children:`+${m}`}):null]})}var We=Object.freeze([]);function Er(){return We}function Nr(){let e=useRef(null);if(e.current===null){let t=We,r=false,o=new Set;e.current={subscribe:a=>(o.add(a),()=>o.delete(a)),read:()=>t,write:a=>{t=a.length===0?We:a,!r&&(r=true,queueMicrotask(()=>{r=false;for(let i of [...o])i();}));}};}return e.current}function Pr({session:e,children:t}){let r=useDocxEditor(),o=J(),a=e===void 0?o:e,i=ze(a),l=useReviewAuthors(),n=Nr(),s=useSyncExternalStore(n.subscribe,n.read,Er);if(useEffect(()=>{if(!(!r||!a))return r.setRemoteCaretLabelHost({publish:n.write}),()=>{r.setRemoteCaretLabelHost(null),n.write(We);}},[r,a,n]),s.length===0)return null;let d=je(l,i);return jsx(Fragment,{children:s.map(f=>{let{selection:u}=f,m=i.find(w=>w.actorId===u.actorId)??null,c=f.element.style.getPropertyValue("--doc-remote-color"),p=c!==""?c:d.get(u.actorId)?.color??gt(l,{actorId:u.actorId,name:u.name,...u.color!==void 0?{color:u.color}:{},isLocal:false}).color;return createPortal(t?t({selection:u,participant:m,color:p,...Oo(Be(l,u.name,r?w=>r.getReviewAuthorStyle(w):void 0))}):u.name,f.element,u.actorId)})})}var Ir=Object.freeze({CaretLabels:Pr,Avatars:Ar,Avatar:Lo});function Ae(e){let t=useDocxEditor();return useMemo(()=>e||(t?.getCustomNodeDefinitions()??[]).filter(j),[e,t])}var Or=".docx-content-control-boundary";function le(e,t){let{node:r,definition:o,controlId:a}=e,i=a?t?.getReviewItems().find(s=>s.kind==="custom"&&s.item.id===a):void 0;if(i&&i.kind==="custom"){let s=i.item;return {...r,attrs:s.attrs,text:s.text,...s.data===void 0?{}:{data:s.data},...a?{nodeId:a}:{}}}let l=a?Lr(t,a,o):void 0,n=o.fromDocx?o.fromDocx({attrs:r.attrs,text:"",...l===void 0?{}:{data:l}}):r.attrs;return n===null?null:{...r,attrs:n,...l===void 0?{}:{data:l},...a?{nodeId:a}:{}}}function Lr(e$1,t,r){let o=e$1?.surface;if(!o)return;let a=partOfNodeId(o.session,t),i=customNodePayloadsByControl(o.session.currentPackage(),(a??o.session.part()).name,o.session.part().name).get(t);if(!i)return;let l=e(r.schema,i.data);return l.ok?l.value:void 0}function ce(e,t){let r=e?.closest?.(Or),o=r?.closest(".docx-content-control-chrome"),a=o?.getAttribute("data-tag"),i=a?c(a):null;if(!r||!i||!a)return null;let l=t.find(n=>n.tagPrefix===i.prefix&&n.name===i.name);return l?{node:{name:i.name,attrs:i.attrs,tag:a,rect:r.getBoundingClientRect()},definition:l,controlId:o?.getAttribute("data-docx-content-control")??null}:null}var Et=".docx-content-control-boundary",$r=e=>{if(!k.test(e.tagPrefix)||!k.test(e.name))return [];let t=`${e.tagPrefix}:${e.name}`;return [`.docx-content-control-chrome[data-tag="${t}"]`,`.docx-content-control-chrome[data-tag^="${t}?"]`]};function qr(e){let{onNodeClick:t,onNodeHover:r}=e,o=useDocxEditor(),a=Ae(e.nodes);return useEffect(()=>{let i=document.createElement("style"),l=[];for(let n of a){let s=$r(n);if(s.length===0)continue;let d=n.chrome?.color!==void 0&&CSS.supports("color",n.chrome.color)?n.chrome.color:"var(--doc-accent)";l.push(`${s.map(f=>`${f} ${Et}`).join(", ")} {`," pointer-events: auto !important;"," opacity: 1;"," border: none;",` background: color-mix(in srgb, ${d} 12%, transparent);`," border-radius: 6px;"," cursor: default;","}");}return i.textContent=l.join(`
2
+ `),document.head.append(i),()=>i.remove()},[a]),useEffect(()=>{let i=null,l=null,n=u=>ce(document.elementFromPoint(u.clientX,u.clientY),a),s=u=>{let m=u.button===0?n(u):null;i=m?.controlId??null,l=m?.node.tag??null;},d=u=>{let m=i,c=l;if(i=null,l=null,c===null)return;let p=n(u);if(!p||p.node.tag!==c||m!==null&&p.controlId!==m)return;let w=le(p,o);w&&(p.definition.onClick?.(w),t?.(w));},f=u=>{let m=ce(u.target,a);if(!m||u.relatedTarget?.closest?.(Et)===u.target.closest(Et))return;let p=le(m,o);p&&(m.definition.onHover?.(p),r?.(p));};return document.addEventListener("pointerdown",s,true),document.addEventListener("pointerup",d,true),document.addEventListener("mouseover",f),()=>{document.removeEventListener("pointerdown",s,true),document.removeEventListener("pointerup",d,true),document.removeEventListener("mouseover",f);}},[a,o,t,r]),null}var Yr=e=>e.editingMode==="viewing";function Ko(e){let{onEditNode:t,onRemoveRefused:r,remove:o=true}=e,a=Ae(e.nodes),i=useContextMenuTarget(),l=useDocxEditor(),{t:n}=useTranslation(),s=useMemo(()=>i?ce(i,a):null,[i,a]),d=useMemo(()=>s?le(s,l):null,[s,l]),f=useEditorState(Yr),u=useMemo(()=>!s?.definition.reviewCard||!d?null:s.definition.reviewCard({attrs:d.attrs,text:d.text??"",...d.data===void 0?{}:{data:d.data}}),[s,d]);if(!s||!d)return null;let{definition:m}=s,c=m.label??m.name,p=!f&&(m.onEdit!==void 0||t!==void 0),w=!f&&o&&d.nodeId!==void 0&&l!==null;return !u&&!p&&!w?null:jsxs(Fragment,{children:[u?jsxs("div",{className:"docx-contextmenu__custom-info","data-testid":"custom-node-info",children:[jsx("span",{className:"docx-contextmenu__custom-title",children:u.title}),u.detail?jsx("span",{className:"docx-contextmenu__custom-detail",children:u.detail}):null]}):null,p?jsx(ContextMenuItem,{label:n("contextMenu.editCustomNode",{label:c}),className:"docx-contextmenu__custom-edit",onSelect:()=>{m.onEdit?.(d),t?.(d,m);}}):null,w?jsx(ContextMenuItem,{label:n("contextMenu.removeCustomNode",{label:c}),className:"docx-contextmenu__custom-remove",onSelect:()=>{let R=q$1(l,d.nodeId);R.ok||r?.(d,R.reason);}}):null,jsx("div",{role:"separator",className:"docx-toolbar__menu-separator"})]})}Ko.docxRowPlacement="start";var Pt=Object.freeze({status:"inactive",reason:void 0,lastFailure:void 0,live:false,diverged:false,attached:false});function Uo(e,t){return e===t?true:!e||!t?false:e.code===t.code&&e.detail===t.detail}function zr(e,t){return e.status===t.status&&Uo(e.reason,t.reason)&&Uo(e.lastFailure,t.lastFailure)}function Wr(e){return e.attached??false}function Vo(e,t){if(!e)return t.current=Pt,Pt;let r=e.statusSnapshot(),o=Wr(e);if(zr(t.current,r)&&t.current.attached===o)return t.current;let a=Object.freeze({status:r.status,reason:r.reason,lastFailure:r.lastFailure,live:r.status==="ready",diverged:r.status==="error"||r.status==="destroyed",attached:o});return t.current=a,a}function Gr(e){let t=J(),r=e===void 0?t:e,o=useRef(Pt);return useSyncExternalStore(a=>r?.subscribeStatus(()=>a())??(()=>{}),()=>Vo(r,o),()=>Vo(r,o))}function Xr({collaboration:e,fallback:t=null,author:r,children:o,...a}){let{document:i,modules:l,session:n}=e;if(!i)return jsx(Fragment,{children:t});let s=r??n?.identity.name;return jsx(DocxEditorRoot,{document:i,modules:l,...s!==void 0?{author:s}:{},...a,children:o},n?.sessionId??"local")}var oa=Symbol("useDocumentCollaboration.createRoom");async function na(e){let{createDocumentCollaboration:t}=await import('../document-session-6UET6BWT.js');return t(e)}function ra(e){return e[oa]??na}function aa(e){return e?`${e.documentId}:${e.bootstrap.kind}:${e.identity.actorId}`:""}function ia(e={}){let t=useId(),r=b({ownerKey:`react-document:${t}`,hookName:"useDocumentCollaboration",createRoom:ra(e),hostModules:e.modules??a,autoRoom:e.room??null,autoKey:aa(e.room??null),rejoinOptionsOf:o=>({...o,bootstrap:{kind:"join"}}),identityOf:o=>o.identity});return useMemo(()=>({document:r.document,modules:r.modules,session:r.session,pending:r.pending,error:r.error,connect:r.connect,leave:r.leave}),[r])}export{qr as CustomNodeChrome,Ko as CustomNodeContextMenu,Ir as DocxEditorCollaboration,Xr as DocxEditorCollaborationRoot,sr as DocxEditorReview,le as activatedCustomNodeOf,ce as resolveCustomNodeActivation,ze as useCollaborationParticipants,J as useCollaborationSession,Gr as useCollaborationStatus,Ae as useCustomNodeDefinitions,ia as useDocumentCollaboration,Te as useReview,Gn as useReviewAuthor,Wn as useReviewItem,to as useReviewOf,wn as useStackedReviewPositions};
@@ -0,0 +1 @@
1
+ 'use strict';var chunkGDTCNTK7_cjs=require('../chunk-GDTCNTK7.cjs');require('../chunk-QLZH2Q2C.cjs');var react=require('react');var s=Symbol("useWebrtcCollaboration.createRoom");function c(o){return o?`${o.signaling?o.signaling.join(","):""}:${o.roomId}:${o.bootstrap.kind}:${o.identity.actorId}`:""}async function d(o){let{createWebrtcCollaboration:t}=await import('../collaboration/webrtc.cjs');return t(o)}function b(o){return o[s]??d}function p(o={}){let t=react.useId(),e=chunkGDTCNTK7_cjs.b({ownerKey:`react-webrtc:${t}`,hookName:"useWebrtcCollaboration",createRoom:b(o),hostModules:o.modules??chunkGDTCNTK7_cjs.a,autoRoom:o.room??null,autoKey:c(o.room??null),rejoinOptionsOf:r=>({...r,bootstrap:{kind:"join"}}),identityOf:r=>r.identity});return react.useMemo(()=>({document:e.document,modules:e.modules,session:e.session,ydoc:e.room?.ydoc??null,provider:e.room?.provider??null,pending:e.pending,error:e.error,connect:e.connect,leave:e.leave,rejoin:e.rejoin}),[e])}exports.useWebrtcCollaboration=p;