UNPKG

@blocknote/react

Version:

A "Notion-style" block-based extensible text editor built on top of Prosemirror and Tiptap.

2 lines 7.77 kB
var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},s=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},c=(n,r,a)=>(a=n==null?{}:e(i(n)),s(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let l=require(`react`),u=require(`@floating-ui/react`),d=require(`@tanstack/react-store`),f=require(`@blocknote/core`),p=require(`react/jsx-runtime`),m=require(`fast-deep-equal/es6/react.js`);m=c(m,1);let h=require(`use-sync-external-store/shim/with-selector`),g=require(`@tiptap/core`);var _=(0,l.createContext)(void 0);function v(e){return(0,l.useContext)(_)}function y(e){let t=v(e);if(!t?.editor)throw Error(`useBlockNoteEditor was called outside of a BlockNoteContext provider or BlockNoteView component`);return t.editor}function b(e,t){let n=(t?.editor??y()).getExtension(e);if(!n)throw Error(`Extension not found`,{cause:{plugin:e}});return n}function x(e,t){let{store:n}=b(e,t);if(!n)throw Error(`Store not found on plugin`,{cause:{plugin:e}});return(0,d.useStore)(n,t?.selector)}function S(e){let t=new DOMRect,n=`getBoundingClientRect`in e?()=>e.getBoundingClientRect():()=>e.element.getBoundingClientRect();return()=>e.element&&(e.cacheMountedBoundingClientRect??!0)?(e.element.isConnected&&(t=n()),t):n()}function C(e,t){return e?t?(n,r,i)=>{let a=e(n,r,i),o=t(n,r,i);return()=>{a?.(),o?.()}}:e:t}var w=e=>{let t=y(),n=e.portalElement===null?typeof document<`u`?document.body:void 0:e.portalElement??t?.portalElement;if(!n)throw Error(`Portal element not found`);let{whileElementsMounted:r,...i}=e.useFloatingOptions??{},{refs:a,floatingStyles:o,context:s}=(0,u.useFloating)({whileElementsMounted:C(u.autoUpdate,e.useFloatingOptions?.whileElementsMounted),...i}),{isMounted:c,styles:d}=(0,u.useTransitionStyles)(s,e.useTransitionStylesProps),{status:f}=(0,u.useTransitionStatus)(s,e.useTransitionStatusProps),{getFloatingProps:m}=(0,u.useInteractions)([(0,u.useDismiss)(s,e.useDismissProps),(0,u.useHover)(s,{enabled:!1,...e.useHoverProps})]),h=(0,l.useRef)(``),g=(0,l.useRef)(null),_=(0,u.useMergeRefs)([g,a.setFloating]);if((0,l.useEffect)(()=>{if(e.reference){let n=`element`in e.reference?e.reference.element:void 0;n!==void 0&&(e.focusManagerProps?.disabled||!t.isWithinEditor(n))&&a.setReference(n),a.setPositionReference({getBoundingClientRect:S(e.reference),contextElement:n})}},[e.reference,a,e.focusManagerProps?.disabled,t]),(0,l.useEffect)(()=>{(f===`initial`||f===`open`)&&g.current?.innerHTML&&(h.current=g.current.innerHTML)},[f,e.reference,e.children]),!c)return!1;let v={...e.elementProps,style:{display:`flex`,...e.elementProps?.style,zIndex:`calc(var(--bn-ui-base-z-index, 0) + ${e.elementProps?.style?.zIndex||0})`,...o,...d},...m()};return f===`close`?(0,p.jsx)(u.FloatingPortal,{root:n,children:(0,p.jsx)(`div`,{ref:_,...v,dangerouslySetInnerHTML:{__html:h.current}})}):e.focusManagerProps?.disabled?(0,p.jsx)(u.FloatingPortal,{root:n,children:(0,p.jsx)(`div`,{ref:_,...v,children:e.children})}):(0,p.jsx)(u.FloatingPortal,{root:n,children:(0,p.jsx)(u.FloatingFocusManager,{...e.focusManagerProps,context:s,children:(0,p.jsx)(`div`,{ref:_,...v,children:e.children})})})},T=(0,l.createContext)(void 0);function E(){return(0,l.useContext)(T)}function D(){return v().editor.dictionary}var O=typeof window<`u`?l.useLayoutEffect:l.useEffect,k=class{transactionNumber=0;lastTransactionNumber=0;lastSnapshot;editor;subscribers=new Set;constructor(e){this.editor=e,this.lastSnapshot={editor:e,transactionNumber:0},this.getSnapshot=this.getSnapshot.bind(this),this.getServerSnapshot=this.getServerSnapshot.bind(this),this.watch=this.watch.bind(this),this.subscribe=this.subscribe.bind(this)}getSnapshot(){return this.transactionNumber===this.lastTransactionNumber?this.lastSnapshot:(this.lastTransactionNumber=this.transactionNumber,this.lastSnapshot={editor:this.editor,transactionNumber:this.transactionNumber},this.lastSnapshot)}getServerSnapshot(){return{editor:null,transactionNumber:0}}subscribe(e){return this.subscribers.add(e),()=>{this.subscribers.delete(e)}}watch(e,t){if(this.editor=e,this.editor){let e=()=>{this.transactionNumber+=1,this.subscribers.forEach(e=>e())},n=this.editor._tiptapEditor,r={all:[`transaction`,`create`,`mount`,`unmount`],mount:[`create`,`mount`,`unmount`],selection:[`selectionUpdate`],change:[`update`]};for(let i of r[t])n.on(i,e);return()=>{for(let i of r[t])n.off(i,e)}}}};function A(e){let t=v(),n=e.editor||t?.editor||null,r=e.on||`all`,[i]=(0,l.useState)(()=>new k(n)),a=(0,h.useSyncExternalStoreWithSelector)(i.subscribe,i.getSnapshot,i.getServerSnapshot,e.selector,e.equalityFn??m.default);return O(()=>i.watch(n,r),[n,i,r]),(0,l.useDebugValue)(a),a}function j(e){let t=v();return e||=t?.editor,A({editor:e,selector:e=>e.editor?.domElement,equalityFn:(e,t)=>e===t,on:`mount`})}var M=e=>{let{position:t,children:n,portalElement:r,...i}=e,{from:a,to:o}=t||{},s=y(),c=j();return(0,p.jsx)(w,{reference:(0,l.useMemo)(()=>{if(!(a===void 0||o===void 0))return{element:c?.firstElementChild||void 0,getBoundingClientRect:()=>(0,g.posToDOMRect)(s.prosemirrorView,a,o??a)}},[s,c,a,o]),portalElement:r,...i,children:t!==void 0&&n})},N=(e={},t=[])=>(0,l.useMemo)(()=>{let t=f.BlockNoteEditor.create(e);return window&&(window.ProseMirror=t._tiptapEditor),t},t),P=e=>{let[t,n]=(0,l.useState)(!1),r=A({editor:e.editor,selector:({editor:e})=>e.isEmpty}),i=E(),a=(0,l.useCallback)(()=>{n(!0)},[]),o=(0,l.useCallback)(()=>{n(!1)},[]);return(0,l.useEffect)(()=>{e.editable&&e.autoFocus&&e.editor.focus()},[e.autoFocus,e.editable,e.editor]),(0,p.jsxs)(p.Fragment,{children:[(0,p.jsx)(i.Comments.Editor,{autoFocus:e.autoFocus,className:`bn-comment-editor`,editor:e.editor,onFocus:a,onBlur:o,editable:e.editable}),e.actions&&(0,p.jsx)(`div`,{className:`bn-comment-actions-wrapper`,children:e.actions({isFocused:t,isEmpty:r})})]})},{textColor:F,backgroundColor:I,...L}=f.defaultStyleSpecs,R=f.BlockNoteSchema.create({blockSpecs:{paragraph:(0,f.createParagraphBlockSpec)()},styleSpecs:L});Object.defineProperty(exports,`_`,{enumerable:!0,get:function(){return o}}),Object.defineProperty(exports,`a`,{enumerable:!0,get:function(){return j}}),Object.defineProperty(exports,`c`,{enumerable:!0,get:function(){return T}}),Object.defineProperty(exports,`d`,{enumerable:!0,get:function(){return S}}),Object.defineProperty(exports,`f`,{enumerable:!0,get:function(){return b}}),Object.defineProperty(exports,`g`,{enumerable:!0,get:function(){return v}}),Object.defineProperty(exports,`h`,{enumerable:!0,get:function(){return _}}),Object.defineProperty(exports,`i`,{enumerable:!0,get:function(){return M}}),Object.defineProperty(exports,`l`,{enumerable:!0,get:function(){return E}}),Object.defineProperty(exports,`m`,{enumerable:!0,get:function(){return y}}),Object.defineProperty(exports,`n`,{enumerable:!0,get:function(){return P}}),Object.defineProperty(exports,`o`,{enumerable:!0,get:function(){return A}}),Object.defineProperty(exports,`p`,{enumerable:!0,get:function(){return x}}),Object.defineProperty(exports,`r`,{enumerable:!0,get:function(){return N}}),Object.defineProperty(exports,`s`,{enumerable:!0,get:function(){return D}}),Object.defineProperty(exports,`t`,{enumerable:!0,get:function(){return R}}),Object.defineProperty(exports,`u`,{enumerable:!0,get:function(){return w}}),Object.defineProperty(exports,`v`,{enumerable:!0,get:function(){return c}}); //# sourceMappingURL=defaultCommentEditorSchema-Cow33c_f.cjs.map