Skip to content

A fully open source & end-to-end encrypted note taking alternative to Evernote.

feat: finalize search/replace

thecodrr89f5ed046434
diff --git a/packages/editor/dist/components/actionsheet/index.d.ts b/packages/editor/dist/components/actionsheet/index.d.ts
index c172db20d..b3a00090c 100644
--- a/packages/editor/dist/components/actionsheet/index.d.ts
+++ b/packages/editor/dist/components/actionsheet/index.d.ts
@@ -6,6 +6,7 @@ export declare type ActionSheetPresenterProps = {
onClose?: () => void;
blocking?: boolean;
focusOnRender?: boolean;
+ draggable?: boolean;
title?: string;
};
export declare function ActionSheetPresenter(props: PropsWithChildren<ActionSheetPresenterProps>): JSX.Element | null;
diff --git a/packages/editor/dist/components/actionsheet/index.js b/packages/editor/dist/components/actionsheet/index.js
index 6937f9e0f..0cacd5d7d 100644
--- a/packages/editor/dist/components/actionsheet/index.js
+++ b/packages/editor/dist/components/actionsheet/index.js
@@ -68,7 +68,7 @@ function useHistory(initial) {
}
export function ActionSheetPresenter(props) {
var _a;
- var isOpen = props.isOpen, title = props.title, items = props.items, onClose = props.onClose, _b = props.blocking, blocking = _b === void 0 ? true : _b, _c = props.focusOnRender, focusOnRender = _c === void 0 ? true : _c, children = props.children;
+ var isOpen = props.isOpen, title = props.title, items = props.items, onClose = props.onClose, _b = props.blocking, blocking = _b === void 0 ? true : _b, _c = props.focusOnRender, focusOnRender = _c === void 0 ? true : _c, _d = props.draggable, draggable = _d === void 0 ? true : _d, children = props.children;
var theme = useTheme();
var contentRef = useRef();
var focusedElement = useRef();
@@ -93,15 +93,13 @@ export function ActionSheetPresenter(props) {
}, overlayElement: function (props, contentEl) {
return (_jsxs(Box, __assign({}, props, {
//@ts-ignore
- style: __assign(__assign({}, props.style), {
- // position: blocking ? "initial" : "fixed",
- zIndex: 1000, backgroundColor: "unset" }), tabIndex: -1 }, { children: [_jsx(motion.div, { style: {
+ style: __assign(__assign({}, props.style), { position: "sticky", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }), tabIndex: -1 }, { children: [blocking && (_jsx(motion.div, { style: {
height: "100%",
width: "100%",
opacity: opacity,
position: "absolute",
- backgroundColor: blocking ? "var(--overlay)" : "transparent",
- }, tabIndex: -1 }), contentEl] })));
+ backgroundColor: "var(--overlay)",
+ }, tabIndex: -1 })), contentEl] })));
}, contentElement: function (props, children) { return (_jsx(Box, __assign({}, props, { style: {}, sx: {
// top: 0,
left: 0,
@@ -111,7 +109,7 @@ export function ActionSheetPresenter(props) {
width: "auto",
height: "fit-content",
position: "fixed",
- backgroundColor: "transparent",
+ backgroundColor: undefined,
padding: 0,
zIndex: 0,
outline: 0,
@@ -123,7 +121,7 @@ export function ActionSheetPresenter(props) {
boxShadow: theme.shadows.menu,
flex: 1,
flexDirection: "column",
- } }, { children: [_jsx(AnimatedFlex, __assign({ drag: "y",
+ } }, { children: [draggable && (_jsx(AnimatedFlex, __assign({ drag: "y",
// @ts-ignore
onDrag: function (_, _a) {
var delta = _a.delta;
@@ -146,8 +144,6 @@ export function ActionSheetPresenter(props) {
else {
animation.start({ transition: TRANSITION, y: 0 });
}
- }, onAnimationComplete: function () {
- console.log("ED!");
}, dragConstraints: { top: 0, bottom: 0 }, dragMomentum: false, dragElastic: false, sx: {
bg: "transparent",
alignItems: "center",
@@ -158,7 +154,7 @@ export function ActionSheetPresenter(props) {
width: 60,
height: 8,
borderRadius: 100,
- } }) })), _jsx(ContentContainer, __assign({ items: items, title: title, onClose: onClose }, { children: children }))] })) })));
+ } }) }))), _jsx(ContentContainer, __assign({ items: items, title: title, onClose: onClose }, { children: children }))] })) })));
}
function ContentContainer(props) {
var _a;
@@ -167,7 +163,7 @@ function ContentContainer(props) {
title: title,
items: items,
}), current = _b.current, goBack = _b.goBack, canGoBack = _b.canGoBack, navigate = _b.navigate;
- return (_jsxs(Flex, __assign({ sx: { flexDirection: "column" } }, { children: [_jsxs(Flex, __assign({ id: "header", sx: { alignItems: "center", mx: 0, mb: 1 } }, { children: [canGoBack && (_jsx(Button, __assign({ variant: "icon", sx: { p: 1, ml: 1 }, onClick: goBack }, { children: _jsx(Icon, { path: Icons.arrowLeft, size: "big" }) }))), (current === null || current === void 0 ? void 0 : current.title) && (_jsx(Text, __assign({ variant: "title", sx: { ml: 1, fontSize: "title" } }, { children: current === null || current === void 0 ? void 0 : current.title })))] })), children
+ return (_jsxs(Flex, __assign({ sx: { flexDirection: "column" } }, { children: [canGoBack || (current === null || current === void 0 ? void 0 : current.title) ? (_jsxs(Flex, __assign({ id: "header", sx: { alignItems: "center", mx: 0, mb: 1 } }, { children: [canGoBack && (_jsx(Button, __assign({ variant: "icon", sx: { p: 1, ml: 1 }, onClick: goBack }, { children: _jsx(Icon, { path: Icons.arrowLeft, size: "big" }) }))), (current === null || current === void 0 ? void 0 : current.title) && (_jsx(Text, __assign({ variant: "title", sx: { ml: 1, fontSize: "title" } }, { children: current === null || current === void 0 ? void 0 : current.title })))] }))) : null, children
? children
: (_a = current === null || current === void 0 ? void 0 : current.items) === null || _a === void 0 ? void 0 : _a.map(function (item) {
switch (item.type) {
diff --git a/packages/editor/dist/components/popuppresenter/index.js b/packages/editor/dist/components/popuppresenter/index.js
index d27cb0bc0..cac9e03de 100644
--- a/packages/editor/dist/components/popuppresenter/index.js
+++ b/packages/editor/dist/components/popuppresenter/index.js
@@ -121,7 +121,11 @@ function _PopupPresenter(props) {
return (_jsx(Box, __assign({}, props, {
//@ts-ignore
style: __assign(__assign({}, props.style), { position: !blocking ? "initial" : "fixed", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }) }, { children: contentEl })));
- }, contentElement: function (props, children) { return (_jsx(Box, __assign({}, props, { style: {}, onMouseDown: function (e) { return e.preventDefault(); }, sx: {
+ }, contentElement: function (props, children) { return (_jsx(Box, __assign({}, props, { style: {},
+ // TODO onMouseDown={(e) => {
+ // console.log(e);
+ // }}
+ sx: {
top: 0,
left: 0,
right: 0,
diff --git a/packages/editor/dist/extensions/attachment/attachment.js b/packages/editor/dist/extensions/attachment/attachment.js
index aaf0d909c..f5e540bcf 100644
--- a/packages/editor/dist/extensions/attachment/attachment.js
+++ b/packages/editor/dist/extensions/attachment/attachment.js
@@ -123,7 +123,8 @@ export var AttachmentNode = Node.create({
}
finally { if (e_1) throw e_1.error; }
}
- tr.skipUpdate = true;
+ tr.setMeta("preventUpdate", true);
+ tr.setMeta("addToHistory", false);
if (dispatch)
dispatch(tr);
return true;
diff --git a/packages/editor/dist/extensions/react/reactnodeview.js b/packages/editor/dist/extensions/react/reactnodeview.js
index 5abca4f57..b779e84c6 100644
--- a/packages/editor/dist/extensions/react/reactnodeview.js
+++ b/packages/editor/dist/extensions/react/reactnodeview.js
@@ -83,7 +83,7 @@ var ReactNodeView = /** @class */ (function () {
return this;
};
ReactNodeView.prototype.renderReactComponent = function (component) {
- if (!this.domRef || !component) {
+ if (!this.domRef || !component || !this.portalProviderAPI) {
return;
}
this.portalProviderAPI.render(component, this.domRef);
@@ -322,7 +322,7 @@ var ReactNodeView = /** @class */ (function () {
configurable: true
});
ReactNodeView.prototype.destroy = function () {
- if (!this.domRef) {
+ if (!this.domRef || !this.portalProviderAPI) {
return;
}
this.portalProviderAPI.remove(this.domRef);
diff --git a/packages/editor/dist/extensions/react/reactportalprovider.d.ts b/packages/editor/dist/extensions/react/reactportalprovider.d.ts
index b3df1ee34..62e1d0f5c 100644
--- a/packages/editor/dist/extensions/react/reactportalprovider.d.ts
+++ b/packages/editor/dist/extensions/react/reactportalprovider.d.ts
@@ -23,7 +23,7 @@ export declare class PortalProvider extends React.Component<BasePortalProviderPr
static displayName: string;
portalProviderAPI: PortalProviderAPI;
constructor(props: BasePortalProviderProps);
- render(): React.ReactChild | JSX.Element | null;
+ render(): JSX.Element | React.ReactChild | null;
componentDidUpdate(): void;
}
export declare class PortalRenderer extends React.Component<{
diff --git a/packages/editor/dist/extensions/searchreplace/searchreplace.d.ts b/packages/editor/dist/extensions/searchreplace/searchreplace.d.ts
index dc199dc44..dc7b33bac 100644
--- a/packages/editor/dist/extensions/searchreplace/searchreplace.d.ts
+++ b/packages/editor/dist/extensions/searchreplace/searchreplace.d.ts
@@ -28,8 +28,8 @@ export declare type SearchStorage = SearchSettings & {
searchTerm: string;
selectedIndex: number;
isSearching: boolean;
- selectedText: string;
- results: Result[];
+ selectedText?: string;
+ results?: Result[];
};
export declare const SearchReplace: Extension<SearchOptions, SearchStorage>;
export {};
diff --git a/packages/editor/dist/extensions/searchreplace/searchreplace.js b/packages/editor/dist/extensions/searchreplace/searchreplace.js
index dabc9b8b2..0edaff4f2 100644
--- a/packages/editor/dist/extensions/searchreplace/searchreplace.js
+++ b/packages/editor/dist/extensions/searchreplace/searchreplace.js
@@ -154,6 +154,7 @@ export var SearchReplace = Extension.create({
_this.storage.enableRegex = (options === null || options === void 0 ? void 0 : options.enableRegex) || false;
_this.storage.matchCase = (options === null || options === void 0 ? void 0 : options.matchCase) || false;
_this.storage.matchWholeWord = (options === null || options === void 0 ? void 0 : options.matchWholeWord) || false;
+ _this.storage.results = [];
updateView(state, dispatch);
return true;
};
@@ -162,7 +163,7 @@ export var SearchReplace = Extension.create({
return function (_a) {
var chain = _a.chain;
var _b = _this.storage, selectedIndex = _b.selectedIndex, results = _b.results;
- if (results.length <= 0)
+ if (!results || results.length <= 0)
return false;
var nextIndex = selectedIndex + 1;
if (isNaN(nextIndex) || nextIndex >= results.length)
@@ -182,7 +183,7 @@ export var SearchReplace = Extension.create({
return function (_a) {
var chain = _a.chain;
var _b = _this.storage, selectedIndex = _b.selectedIndex, results = _b.results;
- if (results.length <= 0)
+ if (!results || results.length <= 0)
return false;
var prevIndex = selectedIndex - 1;
if (isNaN(prevIndex) || prevIndex < 0)
@@ -201,7 +202,7 @@ export var SearchReplace = Extension.create({
return function (_a) {
var commands = _a.commands, tr = _a.tr, dispatch = _a.dispatch;
var _b = _this.storage, selectedIndex = _b.selectedIndex, results = _b.results;
- if (!dispatch || results.length <= 0)
+ if (!dispatch || !results || results.length <= 0)
return false;
var index = selectedIndex === undefined ? 0 : selectedIndex;
var _c = results[index], from = _c.from, to = _c.to;
@@ -225,7 +226,9 @@ export var SearchReplace = Extension.create({
var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;
if (!dispatch)
return false;
- var _b = _this.storage, selectedIndex = _b.selectedIndex, results = _b.results;
+ var results = _this.storage.results;
+ if (!dispatch || !results || results.length <= 0)
+ return false;
dispatch(replaceAll(term, results, tr));
return true;
};
diff --git a/packages/editor/dist/index.js b/packages/editor/dist/index.js
index 4b1fa9c0a..9ded9f496 100644
--- a/packages/editor/dist/index.js
+++ b/packages/editor/dist/index.js
@@ -64,7 +64,7 @@ EditorView.prototype.updateState = function updateState(state) {
};
var useTiptap = function (options, deps) {
if (options === void 0) { options = {}; }
- var theme = options.theme, onCreate = options.onCreate, onUpdate = options.onUpdate, onDownloadAttachment = options.onDownloadAttachment, onOpenAttachmentPicker = options.onOpenAttachmentPicker, portalProviderAPI = options.portalProviderAPI, restOptions = __rest(options, ["theme", "onCreate", "onUpdate", "onDownloadAttachment", "onOpenAttachmentPicker", "portalProviderAPI"]);
+ var theme = options.theme, onCreate = options.onCreate, onDownloadAttachment = options.onDownloadAttachment, onOpenAttachmentPicker = options.onOpenAttachmentPicker, portalProviderAPI = options.portalProviderAPI, restOptions = __rest(options, ["theme", "onCreate", "onDownloadAttachment", "onOpenAttachmentPicker", "portalProviderAPI"]);
var eventDispatcher = useMemo(function () { return new EventDispatcher(); }, []);
var defaultOptions = useMemo(function () { return ({
extensions: [
@@ -140,19 +140,10 @@ var useTiptap = function (options, deps) {
if (onCreate)
onCreate({ editor: editor });
},
- onUpdate: function (_a) {
- var editor = _a.editor, transaction = _a.transaction;
- // a custom extension to transaction that indicates whether
- // this is an actual update or not.
- if (transaction.skipUpdate)
- return;
- onUpdate === null || onUpdate === void 0 ? void 0 : onUpdate({ editor: editor, transaction: transaction });
- },
injectCSS: false,
}); }, [
theme,
onCreate,
- onUpdate,
onDownloadAttachment,
onOpenAttachmentPicker,
portalProviderAPI,
diff --git a/packages/editor/dist/toolbar/components/toolbutton.d.ts b/packages/editor/dist/toolbar/components/toolbutton.d.ts
index daf2d4209..a3ee82353 100644
--- a/packages/editor/dist/toolbar/components/toolbutton.d.ts
+++ b/packages/editor/dist/toolbar/components/toolbutton.d.ts
@@ -1,3 +1,4 @@
+import { Theme } from "@notesnook/theme";
import { SchemeColors } from "@notesnook/theme/dist/theme/colorscheme";
import React from "react";
import { ButtonProps } from "rebass";
@@ -6,7 +7,7 @@ import { ToolButtonVariant } from "../types";
export declare type ToolButtonProps = ButtonProps & {
icon: IconNames;
iconColor?: keyof SchemeColors;
- iconSize?: number;
+ iconSize?: keyof Theme["iconSizes"] | number;
toggled: boolean;
buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined>;
variant?: ToolButtonVariant;
diff --git a/packages/editor/dist/toolbar/components/toolbutton.js b/packages/editor/dist/toolbar/components/toolbutton.js
index 7aa98ce4d..84c026088 100644
--- a/packages/editor/dist/toolbar/components/toolbutton.js
+++ b/packages/editor/dist/toolbar/components/toolbutton.js
@@ -28,5 +28,5 @@ export function ToolButton(props) {
var id = props.id, icon = props.icon, iconSize = props.iconSize, iconColor = props.iconColor, toggled = props.toggled, sx = props.sx, buttonRef = props.buttonRef, _a = props.variant, variant = _a === void 0 ? "normal" : _a, buttonProps = __rest(props, ["id", "icon", "iconSize", "iconColor", "toggled", "sx", "buttonRef", "variant"]);
return (_jsx(Button, __assign({ ref: buttonRef, tabIndex: -1, id: "tool-".concat(id || icon), sx: __assign({ flexShrink: 0, p: variant === "small" ? "small" : 1, borderRadius: variant === "small" ? "small" : "default", m: 0, bg: toggled ? "hover" : "transparent", mr: variant === "small" ? 0 : 1, ":hover": { bg: ["transparent", "hover"] }, ":active": { bg: "hover" }, ":last-of-type": {
mr: 0,
- } }, sx), onMouseDown: function (e) { return e.preventDefault(); } }, buttonProps, { children: _jsx(Icon, { path: Icons[icon], color: iconColor || "icon", size: iconSize || variant === "small" ? "medium" : "big" }) })));
+ } }, sx), onMouseDown: function (e) { return e.preventDefault(); } }, buttonProps, { children: _jsx(Icon, { path: Icons[icon], color: iconColor || "icon", size: iconSize || (variant === "small" ? "medium" : "big") }) })));
}
diff --git a/packages/editor/dist/toolbar/floatingmenus/searchreplace.js b/packages/editor/dist/toolbar/floatingmenus/searchreplace.js
index bba00fcea..d2285373e 100644
--- a/packages/editor/dist/toolbar/floatingmenus/searchreplace.js
+++ b/packages/editor/dist/toolbar/floatingmenus/searchreplace.js
@@ -22,5 +22,5 @@ export function SearchReplaceFloatingMenu(props) {
location: "below",
align: "end",
yOffset: 5,
- } }, { children: _jsx(SearchReplacePopup, { editor: editor }) })));
+ }, blocking: false, focusOnRender: false, draggable: false }, { children: _jsx(SearchReplacePopup, { editor: editor }) })));
}
diff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/toolbar/icons.d.ts
index 7a2ee08a1..ae97caf98 100644
--- a/packages/editor/dist/toolbar/icons.d.ts
+++ b/packages/editor/dist/toolbar/icons.d.ts
@@ -59,6 +59,7 @@ export declare const Icons: {
nextMatch: string;
replaceOne: string;
replaceAll: string;
+ replace: string;
caseSensitive: string;
wholeWord: string;
regex: string;
diff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/toolbar/icons.js
index 17a234a15..c7a4cab1f 100644
--- a/packages/editor/dist/toolbar/icons.js
+++ b/packages/editor/dist/toolbar/icons.js
@@ -60,6 +60,7 @@ export var Icons = {
nextMatch: mdiArrowDown,
replaceOne: "m5.4 5.42 3.48 3.5 3.43-3.43-1.08-1.08-1.57 1.55V3.5a.8.8 0 0 1 .76-.81h2.35v-1.5h-2.35a2.29 2.29 0 0 0-2.28 2.3v2.5L6.48 4.33Zm10.3 2.77c.3.48.7.72 1.25.72.61 0 1.1-.26 1.45-.78.37-.51.55-1.2.55-2.05 0-.8-.15-1.41-.46-1.87a1.51 1.51 0 0 0-1.33-.68c-.63 0-1.11.3-1.45.9h-.02V1.19h-1.37v7.6h1.37v-.6Zm-.03-1.64v-.52c0-.39.09-.7.27-.93a.83.83 0 0 1 .69-.36.76.76 0 0 1 .67.36c.16.24.24.57.24 1 0 .5-.09.9-.26 1.18a.8.8 0 0 1-.73.42.76.76 0 0 1-.63-.33 1.32 1.32 0 0 1-.25-.82zm-1.35 12.82c-.4.23-.97.35-1.71.35-.87 0-1.58-.27-2.12-.82a2.9 2.9 0 0 1-.8-2.12c0-1 .28-1.8.86-2.37a3.12 3.12 0 0 1 2.31-.87c.67 0 1.16.1 1.46.28v1.54a1.95 1.95 0 0 0-1.23-.42c-.5 0-.9.15-1.2.46-.29.3-.43.72-.43 1.26 0 .52.14.93.42 1.23.28.3.67.44 1.16.44.43 0 .86-.14 1.28-.43zm-7.73-8.91L5.05 12v9.27l1.54 1.54h10.82l1.54-1.54V12l-1.54-1.54zm0 1.54h10.82v9.27H6.59Z",
replaceAll: "M16.53 4.22c.22-.45.52-.68.92-.68.36 0 .64.17.83.52.2.34.3.81.3 1.4a3.1 3.1 0 0 1-.35 1.57c-.22.39-.53.59-.91.59-.35 0-.61-.19-.79-.55h-.01v.45h-.87V1.77h.87v2.45h.01zm-.02 1.6a1.14 1.14 0 0 0 .15.63c.1.17.24.25.4.25.2 0 .35-.1.46-.32a2 2 0 0 0 .17-.9c0-.32-.05-.57-.15-.75-.1-.18-.24-.27-.43-.27-.17 0-.32.09-.43.27a1.3 1.3 0 0 0-.17.7ZM5.6 11.56l-3.1-3.1.97-.97 1.47 1.46v-2.2A2.03 2.03 0 0 1 6.96 4.7h3.43v1.32H6.96a.72.72 0 0 0-.68.73l.01 2.19 1.39-1.38.96.96-3.04 3.04Zm7.65-4.04h.94v-2.5c0-1.18-.46-1.78-1.38-1.78-.2 0-.41.04-.66.1a2.11 2.11 0 0 0-.56.25v.97c.34-.3.71-.44 1.1-.44.38 0 .57.23.57.68l-.88.16c-.74.12-1.11.59-1.11 1.4 0 .38.09.7.27.92a.9.9 0 0 0 .74.35c.42 0 .74-.24.96-.7h.01zm0-1.98v.28a1.1 1.1 0 0 1-.17.64.54.54 0 0 1-.46.25.4.4 0 0 1-.32-.14.56.56 0 0 1-.11-.36c0-.33.16-.51.48-.57l.59-.1zM9.82 19.21h-.94v-.6h-.02c-.21.46-.53.7-.96.7a.9.9 0 0 1-.74-.35 1.47 1.47 0 0 1-.27-.92c0-.8.38-1.28 1.12-1.4l.87-.15c0-.46-.19-.69-.57-.69-.38 0-.75.15-1.1.45v-.98c.14-.09.33-.17.57-.24.24-.07.46-.1.66-.1.92 0 1.38.59 1.38 1.78zm-.94-1.7v-.29l-.58.1c-.33.06-.49.25-.49.57 0 .15.04.27.12.36a.4.4 0 0 0 .32.14.54.54 0 0 0 .46-.25c.11-.17.17-.38.17-.63zm4.24 1.8c.47 0 .83-.09 1.08-.26v-1.03a1.32 1.32 0 0 1-.8.3.9.9 0 0 1-.74-.31c-.17-.22-.26-.5-.26-.88s.1-.68.28-.9a.94.94 0 0 1 .75-.32c.28 0 .54.1.77.3v-1.1c-.19-.12-.5-.19-.91-.19-.61 0-1.1.2-1.47.62-.36.4-.54.97-.54 1.68 0 .61.17 1.11.5 1.5.35.4.8.59 1.34.59zM2.5 13.46 3.96 12h13.16l1.46 1.46v7.3l-1.46 1.47H3.96L2.5 20.77Zm1.46 0v7.3h13.16v-7.3Zm4.39-2.92L9.8 9.08h10.23l1.46 1.46v7.3l-1.46 1.47v-8.77z",
+ replace: "M21 4.5000005V14.25a1.5000007 1.5000005 0 0 1-1.500007 1.500005h-8.999996v1.49999a.74999993.74999995 0 0 1-.459373.693747.79687482.79687478 0 0 1-.290624.056263.77812509.77812509 0 0 1-.534375-.215621l-2.25-2.25a.759375.759375 0 0 1 0-1.068763l2.25-2.25a.7875.7875 0 0 1 .824999-.159371.74999993.74999995 0 0 1 .459373.693745V14.25h8.999996V4.5000005H9.0000007v.7499997a.75000036.75000039 0 0 1-1.5000007 0v-.7499997A1.5000007 1.5000005 0 0 1 9.0000007 3H19.499993A1.5000007 1.5000005 0 0 1 21 4.5000005ZM15.750007 18.000005a.74999993.74999995 0 0 0-.750014.749995v.749995H4.5000007V9.7500002h9.0000063v1.5000048a.759375.759375 0 0 0 .459381.693745.79687482.79687478 0 0 0 .290612.05631.77812509.77812509 0 0 0 .534372-.215621l2.25-2.2500079a.759375.759375 0 0 0 0-1.06875l-2.25-2.25a.76875023.76875019 0 0 0-.824984-.1594227.74999993.74999995 0 0 0-.459381.6937502v1.4999978H4.5000007A1.5000007 1.5000005 0 0 0 3 9.7500002v9.7499948A1.5000007 1.5000005 0 0 0 4.5000007 21H14.999993A1.5000007 1.5000005 0 0 0 16.5 19.499995V18.75a.74999993.74999995 0 0 0-.749993-.749995z",
caseSensitive: mdiFormatLetterCase,
wholeWord: mdiFormatLetterMatches,
regex: mdiRegex,
diff --git a/packages/editor/dist/toolbar/popups/searchreplace.js b/packages/editor/dist/toolbar/popups/searchreplace.js
index 35128de4d..48ed63c71 100644
--- a/packages/editor/dist/toolbar/popups/searchreplace.js
+++ b/packages/editor/dist/toolbar/popups/searchreplace.js
@@ -25,17 +25,20 @@ var __read = (this && this.__read) || function (o, n) {
}
return ar;
};
-import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import { Input } from "@rebass/forms";
import { useCallback, useEffect, useRef, useState } from "react";
-import { Flex } from "rebass";
+import { Flex, Text } from "rebass";
import { ToolButton } from "../components/tool-button";
export function SearchReplacePopup(props) {
var editor = props.editor;
- var selectedText = editor.storage.searchreplace.selectedText;
- var _a = __read(useState(false), 2), matchCase = _a[0], setMatchCase = _a[1];
- var _b = __read(useState(false), 2), matchWholeWord = _b[0], setMatchWholeWord = _b[1];
- var _c = __read(useState(false), 2), enableRegex = _c[0], setEnableRegex = _c[1];
+ var _a = editor.storage
+ .searchreplace, selectedText = _a.selectedText, results = _a.results;
+ var _b = __read(useState(false), 2), isReplacing = _b[0], setIsReplacing = _b[1];
+ var _c = __read(useState(false), 2), isExpanded = _c[0], setIsExpanded = _c[1];
+ var _d = __read(useState(false), 2), matchCase = _d[0], setMatchCase = _d[1];
+ var _e = __read(useState(false), 2), matchWholeWord = _e[0], setMatchWholeWord = _e[1];
+ var _f = __read(useState(false), 2), enableRegex = _f[0], setEnableRegex = _f[1];
var replaceText = useRef("");
var searchInputRef = useRef();
var search = useCallback(function (term) {
@@ -62,42 +65,45 @@ export function SearchReplacePopup(props) {
search(selectedText);
}
}, [selectedText, search]);
- return (
- // <MenuPresenter
- // isOpen
- // items={[]}
- // onClose={() => {}}
- // options={{
- // type: "autocomplete",
- // position: {
- // target:
- // document.querySelector<HTMLElement>(".editor-toolbar") || "mouse",
- // isTargetAbsolute: true,
- // location: "below",
- // align: "end",
- // },
- // }}
- // >
- // <Popup>
- _jsxs(Flex, __assign({ sx: { p: 1, flexDirection: "column" } }, { children: [_jsxs(Flex, __assign({ sx: { alignItems: "start", flexShrink: 0 } }, { children: [_jsxs(Flex, __assign({ sx: {
- position: "relative",
- mr: 1,
- width: 200,
- alignItems: "center",
- } }, { children: [_jsx(Input, { defaultValue: selectedText, ref: searchInputRef, autoFocus: true, sx: { p: 1 }, placeholder: "Find", onChange: function (e) {
- search(e.target.value);
- } }), _jsxs(Flex, __assign({ sx: {
- position: "absolute",
- right: 0,
- mr: 0,
- } }, { children: [_jsx(ToolButton, { sx: {
- mr: 0,
- }, toggled: matchCase, title: "Match case", id: "matchCase", icon: "caseSensitive", onClick: function () { return setMatchCase(function (s) { return !s; }); }, iconSize: 14 }), _jsx(ToolButton, { sx: {
- mr: 0,
- }, toggled: matchWholeWord, title: "Match whole word", id: "matchWholeWord", icon: "wholeWord", onClick: function () { return setMatchWholeWord(function (s) { return !s; }); }, iconSize: 14 }), _jsx(ToolButton, { sx: {
- mr: 0,
- }, toggled: enableRegex, title: "Enable regex", id: "enableRegex", icon: "regex", onClick: function () { return setEnableRegex(function (s) { return !s; }); }, iconSize: 14 })] }))] })), _jsx(ToolButton, { toggled: false, title: "Previous match", id: "previousMatch", icon: "previousMatch", onClick: function () { return editor.commands.moveToPreviousResult(); }, sx: { mr: 0 }, iconSize: 16 }), _jsx(ToolButton, { toggled: false, title: "Next match", id: "nextMatch", icon: "nextMatch", onClick: function () { return editor.commands.moveToNextResult(); }, sx: { mr: 0 }, iconSize: 16 }), _jsx(ToolButton, { toggled: false, title: "Close", id: "close", icon: "close", onClick: function () { return editor.chain().focus().endSearch().run(); }, iconSize: 16, sx: { mr: 0 } })] })), _jsxs(Flex, __assign({ sx: { alignItems: "start", flexShrink: 0, mt: 1 } }, { children: [_jsx(Input, { sx: { p: 1, width: 200, mr: 1 }, placeholder: "Replace", onChange: function (e) { return (replaceText.current = e.target.value); } }), _jsx(ToolButton, { toggled: false, title: "Replace", id: "replace", icon: "replaceOne", onClick: function () { return editor.commands.replace(replaceText.current); }, sx: { mr: 0 }, iconSize: 16 }), _jsx(ToolButton, { toggled: false, title: "Replace all", id: "replaceAll", icon: "replaceAll", onClick: function () { return editor.commands.replaceAll(replaceText.current); }, sx: { mr: 0 }, iconSize: 16 })] }))] }))
- // </Popup>
- // </MenuPresenter>
- );
+ return (_jsx(Flex, __assign({ sx: {
+ p: 1,
+ bg: "background",
+ flexDirection: "column",
+ boxShadow: ["none", "menu"],
+ borderRadius: [0, "default"],
+ } }, { children: _jsxs(Flex, { children: [_jsxs(Flex, __assign({ sx: { flexDirection: "column", flex: 1, width: ["auto", 300], mr: 1 } }, { children: [_jsxs(Flex, __assign({ sx: {
+ flex: 1,
+ position: "relative",
+ alignItems: "center",
+ outline: "1px solid var(--border)",
+ borderRadius: "default",
+ p: 1,
+ py: 0,
+ ":focus-within": {
+ outlineColor: "primary",
+ outlineWidth: "1.8px",
+ },
+ ":hover": {
+ outlineColor: "primary",
+ },
+ } }, { children: [_jsx(Input, { variant: "clean", defaultValue: selectedText, ref: searchInputRef, autoFocus: true, placeholder: "Find", sx: { p: 0 }, onChange: function (e) {
+ search(e.target.value);
+ } }), _jsxs(Flex, __assign({ sx: {
+ flexShrink: 0,
+ mr: 0,
+ alignItems: "center",
+ } }, { children: [_jsx(ToolButton, { sx: {
+ mr: 0,
+ }, toggled: isExpanded, title: "Expand", id: "expand", icon: isExpanded ? "chevronRight" : "chevronLeft", onClick: function () { return setIsExpanded(function (s) { return !s; }); }, iconSize: "medium" }), isExpanded && (_jsxs(_Fragment, { children: [_jsx(ToolButton, { sx: {
+ mr: 0,
+ }, toggled: matchCase, title: "Match case", id: "matchCase", icon: "caseSensitive", onClick: function () { return setMatchCase(function (s) { return !s; }); }, iconSize: "medium" }), _jsx(ToolButton, { sx: {
+ mr: 0,
+ }, toggled: matchWholeWord, title: "Match whole word", id: "matchWholeWord", icon: "wholeWord", onClick: function () { return setMatchWholeWord(function (s) { return !s; }); }, iconSize: "medium" }), _jsx(ToolButton, { sx: {
+ mr: 0,
+ }, toggled: enableRegex, title: "Enable regex", id: "enableRegex", icon: "regex", onClick: function () { return setEnableRegex(function (s) { return !s; }); }, iconSize: "medium" })] })), _jsxs(Text, __assign({ variant: "subBody", sx: {
+ flexShrink: 0,
+ borderLeft: "1px solid var(--border)",
+ color: "fontTertiary",
+ px: 1,
+ } }, { children: [results ? "".concat(results.length) : "0", isExpanded ? "" : " results"] }))] }))] })), isReplacing && (_jsx(Input, { sx: { mt: 1, p: "7px" }, placeholder: "Replace", onChange: function (e) { return (replaceText.current = e.target.value); } }))] })), _jsxs(Flex, __assign({ sx: { flexDirection: "column" } }, { children: [_jsxs(Flex, __assign({ sx: { alignItems: "center", height: "33.2px" } }, { children: [_jsx(ToolButton, { toggled: isReplacing, title: "Toggle replace", id: "toggleReplace", icon: "replace", onClick: function () { return setIsReplacing(function (s) { return !s; }); }, sx: { mr: 0 }, iconSize: "big" }), _jsx(ToolButton, { toggled: false, title: "Previous match", id: "previousMatch", icon: "previousMatch", onClick: function () { return editor.commands.moveToPreviousResult(); }, sx: { mr: 0 }, iconSize: "big" }), _jsx(ToolButton, { toggled: false, title: "Next match", id: "nextMatch", icon: "nextMatch", onClick: function () { return editor.commands.moveToNextResult(); }, sx: { mr: 0 }, iconSize: "big" }), _jsx(ToolButton, { toggled: false, title: "Close", id: "close", icon: "close", onClick: function () { return editor.chain().focus().endSearch().run(); }, sx: { mr: 0 }, iconSize: "big" })] })), isReplacing && (_jsxs(Flex, __assign({ sx: { alignItems: "center", height: "33.2px", mt: 1 } }, { children: [_jsx(ToolButton, { toggled: false, title: "Replace", id: "replace", icon: "replaceOne", onClick: function () { return editor.commands.replace(replaceText.current); }, sx: { mr: 0 }, iconSize: 18 }), _jsx(ToolButton, { toggled: false, title: "Replace all", id: "replaceAll", icon: "replaceAll", onClick: function () { return editor.commands.replaceAll(replaceText.current); }, sx: { mr: 0 }, iconSize: 18 })] })))] }))] }) })));
}
diff --git a/packages/editor/src/components/action-sheet/index.tsx b/packages/editor/src/components/action-sheet/index.tsx
index 458fd5c98..a45de771b 100644
--- a/packages/editor/src/components/action-sheet/index.tsx
+++ b/packages/editor/src/components/action-sheet/index.tsx
@@ -61,6 +61,7 @@ export type ActionSheetPresenterProps = {
onClose?: () => void;
blocking?: boolean;
focusOnRender?: boolean;
+ draggable?: boolean;
title?: string;
};
@@ -74,6 +75,7 @@ export function ActionSheetPresenter(
onClose,
blocking = true,
focusOnRender = true,
+ draggable = true,
children,
} = props;
const theme: Theme = useTheme();
@@ -125,22 +127,24 @@ export function ActionSheetPresenter(
//@ts-ignore
style={{
...props.style,
- // position: blocking ? "initial" : "fixed",
+ position: "sticky",
zIndex: 1000,
- backgroundColor: "unset",
+ backgroundColor: !blocking ? "transparent" : "unset",
}}
tabIndex={-1}
>
- <motion.div
- style={{
- height: "100%",
- width: "100%",
- opacity,
- position: "absolute",
- backgroundColor: blocking ? "var(--overlay)" : "transparent",
- }}
- tabIndex={-1}
- />
+ {blocking && (
+ <motion.div
+ style={{
+ height: "100%",
+ width: "100%",
+ opacity,
+ position: "absolute",
+ backgroundColor: "var(--overlay)",
+ }}
+ tabIndex={-1}
+ />
+ )}
{contentEl}
</Box>
);
@@ -158,7 +162,7 @@ export function ActionSheetPresenter(
width: "auto",
height: "fit-content",
position: "fixed",
- backgroundColor: "transparent",
+ backgroundColor: undefined,
padding: 0,
zIndex: 0,
outline: 0,
@@ -182,52 +186,51 @@ export function ActionSheetPresenter(
flexDirection: "column",
}}
>
- <AnimatedFlex
- drag="y"
- // @ts-ignore
- onDrag={(_, { delta }: PanInfo) => {
- y.set(Math.max(y.get() + delta.y, 0));
- }}
- // @ts-ignore
- onDragEnd={(_, { velocity }: PanInfo) => {
- if (velocity.y >= 500) {
- onClose?.();
- return;
- }
- const sheetEl = contentRef.current as HTMLDivElement;
- const contentHeight = sheetEl.offsetHeight;
- const threshold = 30;
- const closingHeight = (contentHeight * threshold) / 100;
+ {draggable && (
+ <AnimatedFlex
+ drag="y"
+ // @ts-ignore
+ onDrag={(_, { delta }: PanInfo) => {
+ y.set(Math.max(y.get() + delta.y, 0));
+ }}
+ // @ts-ignore
+ onDragEnd={(_, { velocity }: PanInfo) => {
+ if (velocity.y >= 500) {
+ onClose?.();
+ return;
+ }
+ const sheetEl = contentRef.current as HTMLDivElement;
+ const contentHeight = sheetEl.offsetHeight;
+ const threshold = 30;
+ const closingHeight = (contentHeight * threshold) / 100;
- if (y.get() >= closingHeight) {
- onBeforeClose();
- } else {
- animation.start({ transition: TRANSITION, y: 0 });
- }
- }}
- onAnimationComplete={() => {
- console.log("ED!");
- }}
- dragConstraints={{ top: 0, bottom: 0 }}
- dragMomentum={false}
- dragElastic={false}
- sx={{
- bg: "transparent",
- alignItems: "center",
- justifyContent: "center",
- p: 2,
- }}
- >
- <Box
- id="pill"
+ if (y.get() >= closingHeight) {
+ onBeforeClose();
+ } else {
+ animation.start({ transition: TRANSITION, y: 0 });
+ }
+ }}
+ dragConstraints={{ top: 0, bottom: 0 }}
+ dragMomentum={false}
+ dragElastic={false}
sx={{
- backgroundColor: "hover",
- width: 60,
- height: 8,
- borderRadius: 100,
+ bg: "transparent",
+ alignItems: "center",
+ justifyContent: "center",
+ p: 2,
}}
- />
- </AnimatedFlex>
+ >
+ <Box
+ id="pill"
+ sx={{
+ backgroundColor: "hover",
+ width: 60,
+ height: 8,
+ borderRadius: 100,
+ }}
+ />
+ </AnimatedFlex>
+ )}
<ContentContainer items={items} title={title} onClose={onClose}>
{children}
</ContentContainer>
@@ -252,18 +255,20 @@ function ContentContainer(props: PropsWithChildren<ContentContainerProps>) {
return (
<Flex sx={{ flexDirection: "column" }}>
- <Flex id="header" sx={{ alignItems: "center", mx: 0, mb: 1 }}>
- {canGoBack && (
- <Button variant={"icon"} sx={{ p: 1, ml: 1 }} onClick={goBack}>
- <Icon path={Icons.arrowLeft} size={"big"} />
- </Button>
- )}
- {current?.title && (
- <Text variant={"title"} sx={{ ml: 1, fontSize: "title" }}>
- {current?.title}
- </Text>
- )}
- </Flex>
+ {canGoBack || current?.title ? (
+ <Flex id="header" sx={{ alignItems: "center", mx: 0, mb: 1 }}>
+ {canGoBack && (
+ <Button variant={"icon"} sx={{ p: 1, ml: 1 }} onClick={goBack}>
+ <Icon path={Icons.arrowLeft} size={"big"} />
+ </Button>
+ )}
+ {current?.title && (
+ <Text variant={"title"} sx={{ ml: 1, fontSize: "title" }}>
+ {current?.title}
+ </Text>
+ )}
+ </Flex>
+ ) : null}
{children
? children
: current?.items?.map((item) => {
diff --git a/packages/editor/src/components/popup-presenter/index.tsx b/packages/editor/src/components/popup-presenter/index.tsx
index 565449527..d4c3db9fe 100644
--- a/packages/editor/src/components/popup-presenter/index.tsx
+++ b/packages/editor/src/components/popup-presenter/index.tsx
@@ -184,7 +184,9 @@ function _PopupPresenter(props: PropsWithChildren<PopupPresenterProps>) {
<Box
{...props}
style={{}}
- onMouseDown={(e) => e.preventDefault()}
+ // TODO onMouseDown={(e) => {
+ // console.log(e);
+ // }}
sx={{
top: 0,
left: 0,
diff --git a/packages/editor/src/extensions/attachment/attachment.ts b/packages/editor/src/extensions/attachment/attachment.ts
index 544e7d3f8..373bbd0dc 100644
--- a/packages/editor/src/extensions/attachment/attachment.ts
+++ b/packages/editor/src/extensions/attachment/attachment.ts
@@ -131,7 +131,8 @@ export const AttachmentNode = Node.create<AttachmentOptions>({
progress,
});
}
- (tr as any).skipUpdate = true;
+ tr.setMeta("preventUpdate", true);
+ tr.setMeta("addToHistory", false);
if (dispatch) dispatch(tr);
return true;
},
diff --git a/packages/editor/src/extensions/react/react-node-view.tsx b/packages/editor/src/extensions/react/react-node-view.tsx
index a431be0e3..f40a15644 100644
--- a/packages/editor/src/extensions/react/react-node-view.tsx
+++ b/packages/editor/src/extensions/react/react-node-view.tsx
@@ -75,7 +75,7 @@ export class ReactNodeView<P extends ReactNodeViewProps> implements NodeView {
private renderReactComponent(
component: () => React.ReactElement<any> | null
) {
- if (!this.domRef || !component) {
+ if (!this.domRef || !component || !this.portalProviderAPI) {
return;
}
@@ -398,7 +398,7 @@ export class ReactNodeView<P extends ReactNodeViewProps> implements NodeView {
}
destroy() {
- if (!this.domRef) {
+ if (!this.domRef || !this.portalProviderAPI) {
return;
}
diff --git a/packages/editor/src/extensions/search-replace/search-replace.ts b/packages/editor/src/extensions/search-replace/search-replace.ts
index 169d3e798..a1fa9eab9 100644
--- a/packages/editor/src/extensions/search-replace/search-replace.ts
+++ b/packages/editor/src/extensions/search-replace/search-replace.ts
@@ -42,8 +42,8 @@ export type SearchStorage = SearchSettings & {
searchTerm: string;
selectedIndex: number;
isSearching: boolean;
- selectedText: string;
- results: Result[];
+ selectedText?: string;
+ results?: Result[];
};
interface TextNodesWithPosition {
@@ -187,6 +187,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
this.storage.enableRegex = options?.enableRegex || false;
this.storage.matchCase = options?.matchCase || false;
this.storage.matchWholeWord = options?.matchWholeWord || false;
+ this.storage.results = [];
updateView(state, dispatch);
return true;
},
@@ -194,7 +195,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
() =>
({ chain }) => {
const { selectedIndex, results } = this.storage;
- if (results.length <= 0) return false;
+ if (!results || results.length <= 0) return false;
let nextIndex = selectedIndex + 1;
if (isNaN(nextIndex) || nextIndex >= results.length) nextIndex = 0;
@@ -213,7 +214,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
() =>
({ chain }) => {
const { selectedIndex, results } = this.storage;
- if (results.length <= 0) return false;
+ if (!results || results.length <= 0) return false;
let prevIndex = selectedIndex - 1;
if (isNaN(prevIndex) || prevIndex < 0) prevIndex = results.length - 1;
@@ -232,7 +233,7 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
({ commands, tr, dispatch }) => {
const { selectedIndex, results } = this.storage;
- if (!dispatch || results.length <= 0) return false;
+ if (!dispatch || !results || results.length <= 0) return false;
const index = selectedIndex === undefined ? 0 : selectedIndex;
const { from, to } = results[index];
@@ -262,7 +263,9 @@ export const SearchReplace = Extension.create<SearchOptions, SearchStorage>({
(term) =>
({ state, tr, dispatch }) => {
if (!dispatch) return false;
- const { selectedIndex, results } = this.storage;
+ const { results } = this.storage;
+ if (!dispatch || !results || results.length <= 0) return false;
+
dispatch(replaceAll(term, results, tr));
return true;
},
diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts
index 8c7aaaa18..507a5b209 100644
--- a/packages/editor/src/index.ts
+++ b/packages/editor/src/index.ts
@@ -56,7 +56,6 @@ const useTiptap = (
const {
theme,
onCreate,
- onUpdate,
onDownloadAttachment,
onOpenAttachmentPicker,
portalProviderAPI,
@@ -132,25 +131,18 @@ const useTiptap = (
if (theme) {
editor.storage.theme = theme;
}
+
if (portalProviderAPI)
editor.storage.portalProviderAPI = portalProviderAPI;
if (eventDispatcher) editor.storage.eventDispatcher = eventDispatcher;
if (onCreate) onCreate({ editor });
},
- onUpdate: ({ editor, transaction }) => {
- // a custom extension to transaction that indicates whether
- // this is an actual update or not.
- if ((transaction as any).skipUpdate) return;
-
- onUpdate?.({ editor, transaction });
- },
injectCSS: false,
}),
[
theme,
onCreate,
- onUpdate,
onDownloadAttachment,
onOpenAttachmentPicker,
portalProviderAPI,
diff --git a/packages/editor/src/toolbar/components/tool-button.tsx b/packages/editor/src/toolbar/components/tool-button.tsx
index 113eeef10..3e1b23ff6 100644
--- a/packages/editor/src/toolbar/components/tool-button.tsx
+++ b/packages/editor/src/toolbar/components/tool-button.tsx
@@ -11,7 +11,7 @@ import { Icon } from "./icon";
export type ToolButtonProps = ButtonProps & {
icon: IconNames;
iconColor?: keyof SchemeColors;
- iconSize?: number;
+ iconSize?: keyof Theme["iconSizes"] | number;
toggled: boolean;
buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined>;
variant?: ToolButtonVariant;
@@ -54,7 +54,7 @@ export function ToolButton(props: ToolButtonProps) {
<Icon
path={Icons[icon]}
color={iconColor || "icon"}
- size={iconSize || variant === "small" ? "medium" : "big"}
+ size={iconSize || (variant === "small" ? "medium" : "big")}
/>
</Button>
);
diff --git a/packages/editor/src/toolbar/floating-menus/search-replace.tsx b/packages/editor/src/toolbar/floating-menus/search-replace.tsx
index d3da75863..38fa9907a 100644
--- a/packages/editor/src/toolbar/floating-menus/search-replace.tsx
+++ b/packages/editor/src/toolbar/floating-menus/search-replace.tsx
@@ -25,6 +25,9 @@ export function SearchReplaceFloatingMenu(props: FloatingMenuProps) {
align: "end",
yOffset: 5,
}}
+ blocking={false}
+ focusOnRender={false}
+ draggable={false}
>
<SearchReplacePopup editor={editor} />
</ResponsivePresenter>
diff --git a/packages/editor/src/toolbar/icons.ts b/packages/editor/src/toolbar/icons.ts
index 65ee56e0b..9bd90b1ab 100644
--- a/packages/editor/src/toolbar/icons.ts
+++ b/packages/editor/src/toolbar/icons.ts
@@ -162,6 +162,8 @@ export const Icons = {
"m5.4 5.42 3.48 3.5 3.43-3.43-1.08-1.08-1.57 1.55V3.5a.8.8 0 0 1 .76-.81h2.35v-1.5h-2.35a2.29 2.29 0 0 0-2.28 2.3v2.5L6.48 4.33Zm10.3 2.77c.3.48.7.72 1.25.72.61 0 1.1-.26 1.45-.78.37-.51.55-1.2.55-2.05 0-.8-.15-1.41-.46-1.87a1.51 1.51 0 0 0-1.33-.68c-.63 0-1.11.3-1.45.9h-.02V1.19h-1.37v7.6h1.37v-.6Zm-.03-1.64v-.52c0-.39.09-.7.27-.93a.83.83 0 0 1 .69-.36.76.76 0 0 1 .67.36c.16.24.24.57.24 1 0 .5-.09.9-.26 1.18a.8.8 0 0 1-.73.42.76.76 0 0 1-.63-.33 1.32 1.32 0 0 1-.25-.82zm-1.35 12.82c-.4.23-.97.35-1.71.35-.87 0-1.58-.27-2.12-.82a2.9 2.9 0 0 1-.8-2.12c0-1 .28-1.8.86-2.37a3.12 3.12 0 0 1 2.31-.87c.67 0 1.16.1 1.46.28v1.54a1.95 1.95 0 0 0-1.23-.42c-.5 0-.9.15-1.2.46-.29.3-.43.72-.43 1.26 0 .52.14.93.42 1.23.28.3.67.44 1.16.44.43 0 .86-.14 1.28-.43zm-7.73-8.91L5.05 12v9.27l1.54 1.54h10.82l1.54-1.54V12l-1.54-1.54zm0 1.54h10.82v9.27H6.59Z",
replaceAll:
"M16.53 4.22c.22-.45.52-.68.92-.68.36 0 .64.17.83.52.2.34.3.81.3 1.4a3.1 3.1 0 0 1-.35 1.57c-.22.39-.53.59-.91.59-.35 0-.61-.19-.79-.55h-.01v.45h-.87V1.77h.87v2.45h.01zm-.02 1.6a1.14 1.14 0 0 0 .15.63c.1.17.24.25.4.25.2 0 .35-.1.46-.32a2 2 0 0 0 .17-.9c0-.32-.05-.57-.15-.75-.1-.18-.24-.27-.43-.27-.17 0-.32.09-.43.27a1.3 1.3 0 0 0-.17.7ZM5.6 11.56l-3.1-3.1.97-.97 1.47 1.46v-2.2A2.03 2.03 0 0 1 6.96 4.7h3.43v1.32H6.96a.72.72 0 0 0-.68.73l.01 2.19 1.39-1.38.96.96-3.04 3.04Zm7.65-4.04h.94v-2.5c0-1.18-.46-1.78-1.38-1.78-.2 0-.41.04-.66.1a2.11 2.11 0 0 0-.56.25v.97c.34-.3.71-.44 1.1-.44.38 0 .57.23.57.68l-.88.16c-.74.12-1.11.59-1.11 1.4 0 .38.09.7.27.92a.9.9 0 0 0 .74.35c.42 0 .74-.24.96-.7h.01zm0-1.98v.28a1.1 1.1 0 0 1-.17.64.54.54 0 0 1-.46.25.4.4 0 0 1-.32-.14.56.56 0 0 1-.11-.36c0-.33.16-.51.48-.57l.59-.1zM9.82 19.21h-.94v-.6h-.02c-.21.46-.53.7-.96.7a.9.9 0 0 1-.74-.35 1.47 1.47 0 0 1-.27-.92c0-.8.38-1.28 1.12-1.4l.87-.15c0-.46-.19-.69-.57-.69-.38 0-.75.15-1.1.45v-.98c.14-.09.33-.17.57-.24.24-.07.46-.1.66-.1.92 0 1.38.59 1.38 1.78zm-.94-1.7v-.29l-.58.1c-.33.06-.49.25-.49.57 0 .15.04.27.12.36a.4.4 0 0 0 .32.14.54.54 0 0 0 .46-.25c.11-.17.17-.38.17-.63zm4.24 1.8c.47 0 .83-.09 1.08-.26v-1.03a1.32 1.32 0 0 1-.8.3.9.9 0 0 1-.74-.31c-.17-.22-.26-.5-.26-.88s.1-.68.28-.9a.94.94 0 0 1 .75-.32c.28 0 .54.1.77.3v-1.1c-.19-.12-.5-.19-.91-.19-.61 0-1.1.2-1.47.62-.36.4-.54.97-.54 1.68 0 .61.17 1.11.5 1.5.35.4.8.59 1.34.59zM2.5 13.46 3.96 12h13.16l1.46 1.46v7.3l-1.46 1.47H3.96L2.5 20.77Zm1.46 0v7.3h13.16v-7.3Zm4.39-2.92L9.8 9.08h10.23l1.46 1.46v7.3l-1.46 1.47v-8.77z",
+ replace:
+ "M21 4.5000005V14.25a1.5000007 1.5000005 0 0 1-1.500007 1.500005h-8.999996v1.49999a.74999993.74999995 0 0 1-.459373.693747.79687482.79687478 0 0 1-.290624.056263.77812509.77812509 0 0 1-.534375-.215621l-2.25-2.25a.759375.759375 0 0 1 0-1.068763l2.25-2.25a.7875.7875 0 0 1 .824999-.159371.74999993.74999995 0 0 1 .459373.693745V14.25h8.999996V4.5000005H9.0000007v.7499997a.75000036.75000039 0 0 1-1.5000007 0v-.7499997A1.5000007 1.5000005 0 0 1 9.0000007 3H19.499993A1.5000007 1.5000005 0 0 1 21 4.5000005ZM15.750007 18.000005a.74999993.74999995 0 0 0-.750014.749995v.749995H4.5000007V9.7500002h9.0000063v1.5000048a.759375.759375 0 0 0 .459381.693745.79687482.79687478 0 0 0 .290612.05631.77812509.77812509 0 0 0 .534372-.215621l2.25-2.2500079a.759375.759375 0 0 0 0-1.06875l-2.25-2.25a.76875023.76875019 0 0 0-.824984-.1594227.74999993.74999995 0 0 0-.459381.6937502v1.4999978H4.5000007A1.5000007 1.5000005 0 0 0 3 9.7500002v9.7499948A1.5000007 1.5000005 0 0 0 4.5000007 21H14.999993A1.5000007 1.5000005 0 0 0 16.5 19.499995V18.75a.74999993.74999995 0 0 0-.749993-.749995z",
caseSensitive: mdiFormatLetterCase,
wholeWord: mdiFormatLetterMatches,
regex: mdiRegex,
diff --git a/packages/editor/src/toolbar/popups/search-replace.tsx b/packages/editor/src/toolbar/popups/search-replace.tsx
index 947d0fbd6..6617c1ebd 100644
--- a/packages/editor/src/toolbar/popups/search-replace.tsx
+++ b/packages/editor/src/toolbar/popups/search-replace.tsx
@@ -1,6 +1,6 @@
import { Input } from "@rebass/forms";
import { useCallback, useEffect, useRef, useState } from "react";
-import { Flex } from "rebass";
+import { Flex, Text } from "rebass";
import { SearchStorage } from "../../extensions/search-replace";
import { ToolButton } from "../components/tool-button";
import { Editor } from "@tiptap/core";
@@ -8,8 +8,11 @@ import { Editor } from "@tiptap/core";
export type SearchReplacePopupProps = { editor: Editor };
export function SearchReplacePopup(props: SearchReplacePopupProps) {
const { editor } = props;
- const { selectedText } = editor.storage.searchreplace as SearchStorage;
+ const { selectedText, results } = editor.storage
+ .searchreplace as SearchStorage;
+ const [isReplacing, setIsReplacing] = useState(false);
+ const [isExpanded, setIsExpanded] = useState(false);
const [matchCase, setMatchCase] = useState(false);
const [matchWholeWord, setMatchWholeWord] = useState(false);
const [enableRegex, setEnableRegex] = useState(false);
@@ -46,139 +49,188 @@ export function SearchReplacePopup(props: SearchReplacePopupProps) {
}, [selectedText, search]);
return (
- // <MenuPresenter
- // isOpen
- // items={[]}
- // onClose={() => {}}
- // options={{
- // type: "autocomplete",
- // position: {
- // target:
- // document.querySelector<HTMLElement>(".editor-toolbar") || "mouse",
- // isTargetAbsolute: true,
- // location: "below",
- // align: "end",
- // },
- // }}
- // >
- // <Popup>
- <Flex sx={{ p: 1, flexDirection: "column" }}>
- <Flex sx={{ alignItems: "start", flexShrink: 0 }}>
+ <Flex
+ sx={{
+ p: 1,
+ bg: "background",
+ flexDirection: "column",
+ boxShadow: ["none", "menu"],
+ borderRadius: [0, "default"],
+ }}
+ >
+ <Flex>
<Flex
- sx={{
- position: "relative",
- mr: 1,
- width: 200,
- alignItems: "center",
- }}
+ sx={{ flexDirection: "column", flex: 1, width: ["auto", 300], mr: 1 }}
>
- <Input
- defaultValue={selectedText}
- ref={searchInputRef}
- autoFocus
- sx={{ p: 1 }}
- placeholder="Find"
- onChange={(e) => {
- search(e.target.value);
- }}
- />
<Flex
sx={{
- position: "absolute",
- right: 0,
- mr: 0,
+ flex: 1,
+ position: "relative",
+ alignItems: "center",
+ outline: "1px solid var(--border)",
+ borderRadius: "default",
+ p: 1,
+ py: 0,
+ ":focus-within": {
+ outlineColor: "primary",
+ outlineWidth: "1.8px",
+ },
+ ":hover": {
+ outlineColor: "primary",
+ },
}}
>
- <ToolButton
- sx={{
- mr: 0,
+ <Input
+ variant={"clean"}
+ defaultValue={selectedText}
+ ref={searchInputRef}
+ autoFocus
+ placeholder="Find"
+ sx={{ p: 0 }}
+ onChange={(e) => {
+ search(e.target.value);
}}
- toggled={matchCase}
- title="Match case"
- id="matchCase"
- icon="caseSensitive"
- onClick={() => setMatchCase((s) => !s)}
- iconSize={14}
/>
- <ToolButton
+ <Flex
sx={{
+ flexShrink: 0,
mr: 0,
+ alignItems: "center",
}}
- toggled={matchWholeWord}
- title="Match whole word"
- id="matchWholeWord"
- icon="wholeWord"
- onClick={() => setMatchWholeWord((s) => !s)}
- iconSize={14}
+ >
+ <ToolButton
+ sx={{
+ mr: 0,
+ }}
+ toggled={isExpanded}
+ title="Expand"
+ id="expand"
+ icon={isExpanded ? "chevronRight" : "chevronLeft"}
+ onClick={() => setIsExpanded((s) => !s)}
+ iconSize={"medium"}
+ />
+ {isExpanded && (
+ <>
+ <ToolButton
+ sx={{
+ mr: 0,
+ }}
+ toggled={matchCase}
+ title="Match case"
+ id="matchCase"
+ icon="caseSensitive"
+ onClick={() => setMatchCase((s) => !s)}
+ iconSize={"medium"}
+ />
+ <ToolButton
+ sx={{
+ mr: 0,
+ }}
+ toggled={matchWholeWord}
+ title="Match whole word"
+ id="matchWholeWord"
+ icon="wholeWord"
+ onClick={() => setMatchWholeWord((s) => !s)}
+ iconSize={"medium"}
+ />
+ <ToolButton
+ sx={{
+ mr: 0,
+ }}
+ toggled={enableRegex}
+ title="Enable regex"
+ id="enableRegex"
+ icon="regex"
+ onClick={() => setEnableRegex((s) => !s)}
+ iconSize={"medium"}
+ />
+ </>
+ )}
+ <Text
+ variant={"subBody"}
+ sx={{
+ flexShrink: 0,
+ borderLeft: "1px solid var(--border)",
+ color: "fontTertiary",
+ px: 1,
+ }}
+ >
+ {results ? `${results.length}` : "0"}
+ {isExpanded ? "" : " results"}
+ </Text>
+ </Flex>
+ </Flex>
+ {isReplacing && (
+ <Input
+ sx={{ mt: 1, p: "7px" }}
+ placeholder="Replace"
+ onChange={(e) => (replaceText.current = e.target.value)}
/>
+ )}
+ </Flex>
+ <Flex sx={{ flexDirection: "column" }}>
+ <Flex sx={{ alignItems: "center", height: "33.2px" }}>
<ToolButton
- sx={{
- mr: 0,
- }}
- toggled={enableRegex}
- title="Enable regex"
- id="enableRegex"
- icon="regex"
- onClick={() => setEnableRegex((s) => !s)}
- iconSize={14}
+ toggled={isReplacing}
+ title="Toggle replace"
+ id="toggleReplace"
+ icon="replace"
+ onClick={() => setIsReplacing((s) => !s)}
+ sx={{ mr: 0 }}
+ iconSize={"big"}
+ />
+ <ToolButton
+ toggled={false}
+ title="Previous match"
+ id="previousMatch"
+ icon="previousMatch"
+ onClick={() => editor.commands.moveToPreviousResult()}
+ sx={{ mr: 0 }}
+ iconSize={"big"}
+ />
+ <ToolButton
+ toggled={false}
+ title="Next match"
+ id="nextMatch"
+ icon="nextMatch"
+ onClick={() => editor.commands.moveToNextResult()}
+ sx={{ mr: 0 }}
+ iconSize={"big"}
+ />
+ <ToolButton
+ toggled={false}
+ title="Close"
+ id="close"
+ icon="close"
+ onClick={() => editor.chain().focus().endSearch().run()}
+ sx={{ mr: 0 }}
+ iconSize={"big"}
/>
</Flex>
+ {isReplacing && (
+ <Flex sx={{ alignItems: "center", height: "33.2px", mt: 1 }}>
+ <ToolButton
+ toggled={false}
+ title="Replace"
+ id="replace"
+ icon="replaceOne"
+ onClick={() => editor.commands.replace(replaceText.current)}
+ sx={{ mr: 0 }}
+ iconSize={18}
+ />
+ <ToolButton
+ toggled={false}
+ title="Replace all"
+ id="replaceAll"
+ icon="replaceAll"
+ onClick={() => editor.commands.replaceAll(replaceText.current)}
+ sx={{ mr: 0 }}
+ iconSize={18}
+ />
+ </Flex>
+ )}
</Flex>
- <ToolButton
- toggled={false}
- title="Previous match"
- id="previousMatch"
- icon="previousMatch"
- onClick={() => editor.commands.moveToPreviousResult()}
- sx={{ mr: 0 }}
- iconSize={16}
- />
- <ToolButton
- toggled={false}
- title="Next match"
- id="nextMatch"
- icon="nextMatch"
- onClick={() => editor.commands.moveToNextResult()}
- sx={{ mr: 0 }}
- iconSize={16}
- />
- <ToolButton
- toggled={false}
- title="Close"
- id="close"
- icon="close"
- onClick={() => editor.chain().focus().endSearch().run()}
- iconSize={16}
- sx={{ mr: 0 }}
- />
- </Flex>
- <Flex sx={{ alignItems: "start", flexShrink: 0, mt: 1 }}>
- <Input
- sx={{ p: 1, width: 200, mr: 1 }}
- placeholder="Replace"
- onChange={(e) => (replaceText.current = e.target.value)}
- />
- <ToolButton
- toggled={false}
- title="Replace"
- id="replace"
- icon="replaceOne"
- onClick={() => editor.commands.replace(replaceText.current)}
- sx={{ mr: 0 }}
- iconSize={16}
- />
- <ToolButton
- toggled={false}
- title="Replace all"
- id="replaceAll"
- icon="replaceAll"
- onClick={() => editor.commands.replaceAll(replaceText.current)}
- sx={{ mr: 0 }}
- iconSize={16}
- />
</Flex>
</Flex>
- // </Popup>
- // </MenuPresenter>
);
}