Skip to content

Commit

Permalink
Build
Browse files Browse the repository at this point in the history
  • Loading branch information
smoores-dev committed Nov 13, 2024
1 parent 2dcc825 commit 3fc9d12
Show file tree
Hide file tree
Showing 95 changed files with 2,475 additions and 1,387 deletions.
308 changes: 190 additions & 118 deletions dist/cjs/components/ChildNodeViews.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/cjs/components/CursorWrapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
return newObj;
}
const CursorWrapper = /*#__PURE__*/ (0, _react.forwardRef)(function CursorWrapper(param, ref) {
let { widget , pos , ...props } = param;
let { widget , getPos , ...props } = param;
const [shouldRender, setShouldRender] = (0, _react.useState)(true);
const innerRef = (0, _react.useRef)(null);
(0, _react.useImperativeHandle)(ref, ()=>{
Expand Down
26 changes: 19 additions & 7 deletions dist/cjs/components/DocNodeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,29 +51,41 @@ function _interopRequireWildcard(obj, nodeInterop) {
}
return newObj;
}
const DocNodeView = /*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(param, ref) {
const getPos = {
current () {
return -1;
}
};
const DocNodeView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(param, ref) {
let { className , node , innerDeco , outerDeco , as , viewDesc , ...elementProps } = param;
const innerRef = (0, _react.useRef)(null);
(0, _react.useImperativeHandle)(ref, ()=>{
return innerRef.current;
}, []);
const { childDescriptors } = (0, _useNodeViewDescriptorJs.useNodeViewDescriptor)(node, innerRef, innerRef, innerDeco, outerDeco, viewDesc);
const { childDescriptors , nodeViewDescRef } = (0, _useNodeViewDescriptorJs.useNodeViewDescriptor)(node, ()=>getPos.current(), innerRef, innerRef, innerDeco, outerDeco, viewDesc);
const childContextValue = (0, _react.useMemo)(()=>({
parentRef: nodeViewDescRef,
siblingsRef: childDescriptors
}), [
childDescriptors,
nodeViewDescRef
]);
const props = {
...elementProps,
ref: innerRef,
className,
suppressContentEditableWarning: true
};
const element = as ? /*#__PURE__*/ (0, _react.cloneElement)(as, props, /*#__PURE__*/ _react.default.createElement(_childDescriptorsContextJs.ChildDescriptorsContext.Provider, {
value: childDescriptors
value: childContextValue
}, /*#__PURE__*/ _react.default.createElement(_childNodeViewsJs.ChildNodeViews, {
pos: -1,
getPos: getPos,
node: node,
innerDecorations: innerDeco
}))) : /*#__PURE__*/ (0, _react.createElement)("div", props, /*#__PURE__*/ _react.default.createElement(_childDescriptorsContextJs.ChildDescriptorsContext.Provider, {
value: childDescriptors
value: childContextValue
}, /*#__PURE__*/ _react.default.createElement(_childNodeViewsJs.ChildNodeViews, {
pos: -1,
getPos: getPos,
node: node,
innerDecorations: innerDeco
})));
Expand All @@ -85,4 +97,4 @@ const DocNodeView = /*#__PURE__*/ (0, _react.forwardRef)(function DocNodeView(pa
}
const wrapped = nodeDecorations.reduce(_childNodeViewsJs.wrapInDeco, element);
return wrapped;
});
}));
57 changes: 45 additions & 12 deletions dist/cjs/components/MarkView.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,62 @@ function _interopRequireWildcard(obj, nodeInterop) {
}
return newObj;
}
const MarkView = /*#__PURE__*/ (0, _react.forwardRef)(function MarkView(param, ref) {
let { mark , children } = param;
const siblingDescriptors = (0, _react.useContext)(_childDescriptorsContextJs.ChildDescriptorsContext);
const childDescriptors = [];
const MarkView = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function MarkView(param, ref) {
let { mark , getPos , children } = param;
const { siblingsRef , parentRef } = (0, _react.useContext)(_childDescriptorsContextJs.ChildDescriptorsContext);
const viewDescRef = (0, _react.useRef)(undefined);
const childDescriptors = (0, _react.useRef)([]);
const domRef = (0, _react.useRef)(null);
(0, _react.useImperativeHandle)(ref, ()=>{
return domRef.current;
}, []);
const outputSpec = mark.type.spec.toDOM?.(mark, true);
const outputSpec = (0, _react.useMemo)(()=>mark.type.spec.toDOM?.(mark, true), [
mark
]);
if (!outputSpec) throw new Error(`Mark spec for ${mark.type.name} is missing toDOM`);
(0, _react.useLayoutEffect)(()=>{
const siblings = siblingsRef.current;
return ()=>{
if (!viewDescRef.current) return;
if (siblings.includes(viewDescRef.current)) {
const index = siblings.indexOf(viewDescRef.current);
siblings.splice(index, 1);
}
};
}, [
siblingsRef
]);
(0, _react.useLayoutEffect)(()=>{
if (!domRef.current) return;
const firstChildDesc = childDescriptors[0];
const desc = new _viewdescJs.MarkViewDesc(undefined, childDescriptors, mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current);
siblingDescriptors.push(desc);
for (const childDesc of childDescriptors){
childDesc.parent = desc;
const firstChildDesc = childDescriptors.current[0];
if (!viewDescRef.current) {
viewDescRef.current = new _viewdescJs.MarkViewDesc(parentRef.current, childDescriptors.current, ()=>getPos.current(), mark, domRef.current, firstChildDesc?.dom.parentElement ?? domRef.current);
} else {
viewDescRef.current.parent = parentRef.current;
viewDescRef.current.dom = domRef.current;
viewDescRef.current.contentDOM = firstChildDesc?.dom.parentElement ?? domRef.current;
viewDescRef.current.mark = mark;
viewDescRef.current.getPos = ()=>getPos.current();
}
if (!siblingsRef.current.includes(viewDescRef.current)) {
siblingsRef.current.push(viewDescRef.current);
}
siblingsRef.current.sort(_viewdescJs.sortViewDescs);
for (const childDesc of childDescriptors.current){
childDesc.parent = viewDescRef.current;
}
});
const childContextValue = (0, _react.useMemo)(()=>({
parentRef: viewDescRef,
siblingsRef: childDescriptors
}), [
childDescriptors,
viewDescRef
]);
return /*#__PURE__*/ _react.default.createElement(_outputSpecJs.OutputSpec, {
ref: domRef,
outputSpec: outputSpec
}, /*#__PURE__*/ _react.default.createElement(_childDescriptorsContextJs.ChildDescriptorsContext.Provider, {
value: childDescriptors
value: childContextValue
}, children));
});
}));
35 changes: 28 additions & 7 deletions dist/cjs/components/NativeWidgetView.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,27 @@ function _interopRequireWildcard(obj, nodeInterop) {
return newObj;
}
function NativeWidgetView(param) {
let { widget , pos } = param;
const siblingDescriptors = (0, _react.useContext)(_childDescriptorsContextJs.ChildDescriptorsContext);
let { widget , getPos } = param;
const { siblingsRef , parentRef } = (0, _react.useContext)(_childDescriptorsContextJs.ChildDescriptorsContext);
const viewDescRef = (0, _react.useRef)(null);
const rootDomRef = (0, _react.useRef)(null);
const posRef = (0, _react.useRef)(pos);
posRef.current = pos;
(0, _react.useLayoutEffect)(()=>{
const siblings = siblingsRef.current;
return ()=>{
if (!viewDescRef.current) return;
if (siblings.includes(viewDescRef.current)) {
const index = siblings.indexOf(viewDescRef.current);
siblings.splice(index, 1);
}
};
}, [
siblingsRef
]);
(0, _useEditorEffectJs.useEditorEffect)((view)=>{
if (!rootDomRef.current) return;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const toDOM = widget.type.toDOM;
let dom = typeof toDOM === "function" ? toDOM(view, ()=>posRef.current) : toDOM;
let dom = typeof toDOM === "function" ? toDOM(view, ()=>getPos.current()) : toDOM;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
if (!widget.type.spec.raw) {
if (dom.nodeType != 1) {
Expand All @@ -75,8 +86,18 @@ function NativeWidgetView(param) {
});
(0, _react.useLayoutEffect)(()=>{
if (!rootDomRef.current) return;
const desc = new _viewdescJs.WidgetViewDesc(undefined, widget, rootDomRef.current);
siblingDescriptors.push(desc);
if (!viewDescRef.current) {
viewDescRef.current = new _viewdescJs.WidgetViewDesc(parentRef.current, ()=>getPos.current(), widget, rootDomRef.current);
} else {
viewDescRef.current.parent = parentRef.current;
viewDescRef.current.widget = widget;
viewDescRef.current.getPos = ()=>getPos.current();
viewDescRef.current.dom = rootDomRef.current;
}
if (!siblingsRef.current.includes(viewDescRef.current)) {
siblingsRef.current.push(viewDescRef.current);
}
siblingsRef.current.sort(_viewdescJs.sortViewDescs);
});
return /*#__PURE__*/ _react.default.createElement("span", {
ref: rootDomRef
Expand Down
76 changes: 49 additions & 27 deletions dist/cjs/components/NodeView.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ Object.defineProperty(exports, "NodeView", {
enumerable: true,
get: ()=>NodeView
});
const _prosemirrorState = require("prosemirror-state");
const _react = /*#__PURE__*/ _interopRequireWildcard(require("react"));
const _reactDom = require("react-dom");
const _childDescriptorsContextJs = require("../contexts/ChildDescriptorsContext.js");
const _editorContextJs = require("../contexts/EditorContext.js");
const _nodeViewContextJs = require("../contexts/NodeViewContext.js");
const _selectNodeContextJs = require("../contexts/SelectNodeContext.js");
const _stopEventContextJs = require("../contexts/StopEventContext.js");
const _useEditorStateJs = require("../hooks/useEditorState.js");
const _useNodeViewDescriptorJs = require("../hooks/useNodeViewDescriptor.js");
const _childNodeViewsJs = require("./ChildNodeViews.js");
const _markViewJs = require("./MarkView.js");
Expand Down Expand Up @@ -71,24 +70,26 @@ function _interopRequireWildcard(obj, nodeInterop) {
}
return newObj;
}
function NodeView(param) {
let { outerDeco , pos , node , innerDeco , ...props } = param;
const NodeView = /*#__PURE__*/ (0, _react.memo)(function NodeView(param) {
let { outerDeco , getPos , node , innerDeco , ...props } = param;
const domRef = (0, _react.useRef)(null);
const nodeDomRef = (0, _react.useRef)(null);
const contentDomRef = (0, _react.useRef)(null);
const getPosFunc = (0, _react.useRef)(()=>getPos.current()).current;
// this is ill-conceived; should revisit
const initialNode = (0, _react.useRef)(node);
const initialOuterDeco = (0, _react.useRef)(outerDeco);
const initialInnerDeco = (0, _react.useRef)(innerDeco);
const posRef = (0, _react.useRef)(pos);
posRef.current = pos;
const customNodeViewRootRef = (0, _react.useRef)(null);
const customNodeViewRef = (0, _react.useRef)(null);
const state = (0, _useEditorStateJs.useEditorState)();
// const state = useEditorState();
const { nodeViews } = (0, _react.useContext)(_nodeViewContextJs.NodeViewContext);
const { view } = (0, _react.useContext)(_editorContextJs.EditorContext);
let element = null;
const Component = nodeViews[node.type.name];
const outputSpec = (0, _react.useMemo)(()=>node.type.spec.toDOM?.(node), [
node
]);
// TODO: Would be great to pull all of the custom node view stuff into
// a hook
const customNodeView = view?.someProp("nodeViews", (nodeViews)=>nodeViews?.[node.type.name]);
Expand All @@ -114,7 +115,7 @@ function NodeView(param) {
customNodeViewRef.current = customNodeView(initialNode.current, // customNodeView will only be set if view is set, and we can only reach
// this line if customNodeView is set
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
view, ()=>posRef.current, initialOuterDeco.current, initialInnerDeco.current);
view, ()=>getPos.current(), initialOuterDeco.current, initialInnerDeco.current);
const { dom } = customNodeViewRef.current;
nodeDomRef.current = customNodeViewRootRef.current;
customNodeViewRootRef.current.appendChild(dom);
Expand All @@ -123,21 +124,33 @@ function NodeView(param) {
view,
innerDeco,
node,
outerDeco,
getPos
]);
const { hasContentDOM , childDescriptors , setStopEvent , setSelectNode , nodeViewDescRef } = (0, _useNodeViewDescriptorJs.useNodeViewDescriptor)(node, ()=>getPos.current(), domRef, nodeDomRef, innerDeco, outerDeco, undefined, contentDomRef);
const finalProps = {
...props,
...!hasContentDOM && {
contentEditable: false
}
};
const nodeProps = (0, _react.useMemo)(()=>({
node: node,
getPos: getPosFunc,
decorations: outerDeco,
innerDecorations: innerDeco
}), [
getPosFunc,
innerDeco,
node,
outerDeco
]);
const { childDescriptors , setStopEvent } = (0, _useNodeViewDescriptorJs.useNodeViewDescriptor)(node, domRef, nodeDomRef, innerDeco, outerDeco, undefined, contentDomRef);
if (Component) {
element = /*#__PURE__*/ _react.default.createElement(Component, _extends({}, props, {
element = /*#__PURE__*/ _react.default.createElement(Component, _extends({}, finalProps, {
ref: nodeDomRef,
nodeProps: {
node: node,
pos: pos,
decorations: outerDeco,
innerDecorations: innerDeco,
isSelected: state.selection instanceof _prosemirrorState.NodeSelection && state.selection.node === node
}
nodeProps: nodeProps
}), /*#__PURE__*/ _react.default.createElement(_childNodeViewsJs.ChildNodeViews, {
pos: pos,
getPos: getPos,
node: node,
innerDecorations: innerDeco
}));
Expand All @@ -146,7 +159,7 @@ function NodeView(param) {
customNodeViewRef.current = customNodeView(initialNode.current, // customNodeView will only be set if view is set, and we can only reach
// this line if customNodeView is set
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
view, ()=>posRef.current, initialOuterDeco.current, initialInnerDeco.current);
view, ()=>getPos.current(), initialOuterDeco.current, initialInnerDeco.current);
}
const { contentDOM } = customNodeViewRef.current;
contentDomRef.current = contentDOM ?? null;
Expand All @@ -155,18 +168,17 @@ function NodeView(param) {
contentEditable: !!contentDOM,
suppressContentEditableWarning: true
}, contentDOM && /*#__PURE__*/ (0, _reactDom.createPortal)(/*#__PURE__*/ _react.default.createElement(_childNodeViewsJs.ChildNodeViews, {
pos: pos,
getPos: getPos,
node: node,
innerDecorations: innerDeco
}), contentDOM));
} else {
const outputSpec = node.type.spec.toDOM?.(node);
if (outputSpec) {
element = /*#__PURE__*/ _react.default.createElement(_outputSpecJs.OutputSpec, _extends({}, props, {
element = /*#__PURE__*/ _react.default.createElement(_outputSpecJs.OutputSpec, _extends({}, finalProps, {
ref: nodeDomRef,
outputSpec: outputSpec
}), /*#__PURE__*/ _react.default.createElement(_childNodeViewsJs.ChildNodeViews, {
pos: pos,
getPos: getPos,
node: node,
innerDecorations: innerDeco
}));
Expand All @@ -184,16 +196,26 @@ function NodeView(param) {
// TODO: Should we only be wrapping non-inline elements? Inline elements have
// already been wrapped in ChildNodeViews/InlineView?
const markedElement = node.marks.reduce((element, mark)=>/*#__PURE__*/ _react.default.createElement(_markViewJs.MarkView, {
getPos: getPos,
mark: mark
}, element), decoratedElement);
return /*#__PURE__*/ _react.default.createElement(_stopEventContextJs.StopEventContext.Provider, {
const childContextValue = (0, _react.useMemo)(()=>({
parentRef: nodeViewDescRef,
siblingsRef: childDescriptors
}), [
childDescriptors,
nodeViewDescRef
]);
return /*#__PURE__*/ _react.default.createElement(_selectNodeContextJs.SelectNodeContext.Provider, {
value: setSelectNode
}, /*#__PURE__*/ _react.default.createElement(_stopEventContextJs.StopEventContext.Provider, {
value: setStopEvent
}, /*#__PURE__*/ _react.default.createElement(_childDescriptorsContextJs.ChildDescriptorsContext.Provider, {
value: childDescriptors
value: childContextValue
}, /*#__PURE__*/ (0, _react.cloneElement)(markedElement, node.marks.length || // eslint-disable-next-line @typescript-eslint/no-explicit-any
outerDeco.some((d)=>d.type.attrs.nodeName) ? {
ref: domRef
} : // we've already passed the domRef to the NodeView component
// as a prop
undefined)));
}
undefined))));
});
5 changes: 2 additions & 3 deletions dist/cjs/components/OutputSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function _interopRequireWildcard(obj, nodeInterop) {
}
return newObj;
}
const ForwardedOutputSpec = /*#__PURE__*/ (0, _react.forwardRef)(function OutputSpec(param, ref) {
const ForwardedOutputSpec = /*#__PURE__*/ (0, _react.memo)(/*#__PURE__*/ (0, _react.forwardRef)(function OutputSpec(param, ref) {
let { outputSpec , children , ...propOverrides } = param;
if (typeof outputSpec === "string") {
return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, outputSpec);
Expand Down Expand Up @@ -77,9 +77,8 @@ const ForwardedOutputSpec = /*#__PURE__*/ (0, _react.forwardRef)(function Output
return /*#__PURE__*/ (0, _react.createElement)(tagName, props, children);
}
content.push(/*#__PURE__*/ _react.default.createElement(ForwardedOutputSpec, {
ref: undefined,
outputSpec: child
}, children));
}
return /*#__PURE__*/ (0, _react.createElement)(tagName, props, ...content);
});
}));
Loading

0 comments on commit 3fc9d12

Please sign in to comment.