A fully open source & end-to-end encrypted note taking alternative to Evernote.
TypeScript asp-net-coredotnet-coreelectronfosshacktoberfestnote-managmentnote-takingnote-taking-appnotebooknotesnotes-appopen-sourceopensourceprivacyproductivityreactreact-nativereactjsself-hosted
chore: export as es & cjs both
thecodrr286a76da81e8
diff --git a/packages/editor/dist/components/actionsheet/index.d.ts b/packages/editor/dist/cjs/components/actionsheet/index.d.tssimilarity index 100%rename from packages/editor/dist/components/actionsheet/index.d.tsrename to packages/editor/dist/cjs/components/actionsheet/index.d.tsdiff --git a/packages/editor/dist/components/actionsheet/index.js b/packages/editor/dist/cjs/components/actionsheet/index.jssimilarity index 50%rename from packages/editor/dist/components/actionsheet/index.jsrename to packages/editor/dist/cjs/components/actionsheet/index.jsindex 46e31eaa6..a22f465f3 100644--- a/packages/editor/dist/components/actionsheet/index.js+++ b/packages/editor/dist/cjs/components/actionsheet/index.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {if (k2 === undefined) k2 = k;var desc = Object.getOwnPropertyDescriptor(m, k);@@ -33,39 +22,23 @@ var __importStar = (this && this.__importStar) || function (mod) {__setModuleDefault(result, mod);return result;};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};var __importDefault = (this && this.__importDefault) || function (mod) {return (mod && mod.__esModule) ? mod : { "default": mod };};Object.defineProperty(exports, "__esModule", { value: true });exports.ActionSheetPresenter = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importStar(require("react"));-var emotion_theming_1 = require("emotion-theming");-var rebass_1 = require("rebass");-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var menubutton_1 = require("../menu/menubutton");-var menuseparator_1 = require("../menu/menuseparator");-var react_modal_1 = __importDefault(require("react-modal"));-var framer_motion_1 = require("framer-motion");-var AnimatedFlex = (0, framer_motion_1.motion)(rebass_1.Flex);-var TRANSITION = {+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importStar(require("react"));+const emotion_theming_1 = require("emotion-theming");+const rebass_1 = require("rebass");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const menubutton_1 = require("../menu/menubutton");+const menuseparator_1 = require("../menu/menuseparator");+const react_modal_1 = __importDefault(require("react-modal"));+const framer_motion_1 = require("framer-motion");+const AnimatedFlex = (0, framer_motion_1.motion)(rebass_1.Flex);+const TRANSITION = {type: "spring",stiffness: 300,damping: 30,@@ -73,40 +46,40 @@ var TRANSITION = {duration: 300,};function useHistory(initial) {- var _a = __read((0, react_1.useState)(initial), 2), current = _a[0], setCurrent = _a[1];- var _b = __read((0, react_1.useState)(false), 2), canGoBack = _b[0], setCanGoBack = _b[1];- var stack = (0, react_1.useRef)([initial]);- var goBack = (0, react_1.useCallback)(function () {+ const [current, setCurrent] = (0, react_1.useState)(initial);+ const [canGoBack, setCanGoBack] = (0, react_1.useState)(false);+ const stack = (0, react_1.useRef)([initial]);+ const goBack = (0, react_1.useCallback)(() => {if (!canGoBack)return;- var prev = stack.current.pop();+ const prev = stack.current.pop();setCurrent(prev);if (stack.current.length <= 1)setCanGoBack(false);}, [canGoBack]);- var navigate = (0, react_1.useCallback)(function (state) {+ const navigate = (0, react_1.useCallback)((state) => {console.log("NAVI", state);- setCurrent(function (prev) {+ setCurrent((prev) => {if (prev)stack.current.push(prev);return state;});setCanGoBack(true);}, []);- return { current: current, goBack: goBack, navigate: navigate, canGoBack: canGoBack };+ return { current, goBack, navigate, canGoBack };}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, _d = props.draggable, draggable = _d === void 0 ? true : _d, children = props.children;- var theme = (0, emotion_theming_1.useTheme)();- var contentRef = (0, react_1.useRef)();- var y = (0, framer_motion_1.useMotionValue)(0);- var opacity = (0, framer_motion_1.useTransform)(y, [0, ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || window.innerHeight], [1, 0]);- var animation = (0, framer_motion_1.useAnimation)();- var onBeforeClose = (0, react_1.useCallback)(function () {+ const { isOpen, title, items, onClose, blocking = true, focusOnRender = true, draggable = true, children, } = props;+ const theme = (0, emotion_theming_1.useTheme)();+ const contentRef = (0, react_1.useRef)();+ const y = (0, framer_motion_1.useMotionValue)(0);+ const opacity = (0, framer_motion_1.useTransform)(y, [0, ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || window.innerHeight], [1, 0]);+ const animation = (0, framer_motion_1.useAnimation)();+ const onBeforeClose = (0, react_1.useCallback)(() => {var _a;- var height = ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || window.innerHeight;- setTimeout(function () {+ const height = ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || window.innerHeight;+ setTimeout(() => {onClose === null || onClose === void 0 ? void 0 : onClose();}, TRANSITION.duration - 50);animation.start({@@ -114,35 +87,35 @@ function ActionSheetPresenter(props) {y: height + 100,});}, [animation, onClose, contentRef.current]);- var handleBackPress = (0, react_1.useCallback)(function (event) {+ const handleBackPress = (0, react_1.useCallback)((event) => {if (!isOpen)return;event.preventDefault();onBeforeClose();}, [isOpen, onBeforeClose]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {// Note: this is a custom event implemented on the React Native// side to handle back button when action sheet is opened.window.addEventListener("handleBackPress", handleBackPress);- return function () {+ return () => {window.removeEventListener("handleBackPress", handleBackPress);};}, [handleBackPress]);if (!isOpen)return null;- return ((0, jsx_runtime_1.jsx)(react_modal_1.default, __assign({ contentRef: function (ref) { return (contentRef.current = ref); }, className: "bottom-sheet-presenter", role: "menu", isOpen: isOpen, appElement: document.body, shouldCloseOnEsc: blocking, shouldReturnFocusAfterClose: focusOnRender, shouldCloseOnOverlayClick: blocking, shouldFocusAfterRender: focusOnRender, ariaHideApp: blocking, preventScroll: blocking, onRequestClose: function () { return onBeforeClose(); }, portalClassName: "bottom-sheet-presenter-portal", onAfterOpen: function () {+ return ((0, jsx_runtime_1.jsx)(react_modal_1.default, Object.assign({ contentRef: (ref) => (contentRef.current = ref), className: "bottom-sheet-presenter", role: "menu", isOpen: isOpen, appElement: document.body, shouldCloseOnEsc: blocking, shouldReturnFocusAfterClose: focusOnRender, shouldCloseOnOverlayClick: blocking, shouldFocusAfterRender: focusOnRender, ariaHideApp: blocking, preventScroll: blocking, onRequestClose: () => onBeforeClose(), portalClassName: "bottom-sheet-presenter-portal", onAfterOpen: () => {animation.start({ transition: TRANSITION, y: 0 });- }, overlayElement: function (props, contentEl) {- return ((0, jsx_runtime_1.jsxs)(rebass_1.Box, __assign({}, props, {+ }, overlayElement: (props, contentEl) => {+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Box, Object.assign({}, props, {//@ts-ignore- style: __assign(__assign({}, props.style), { position: blocking ? "fixed" : "sticky", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }), tabIndex: -1 }, { children: [blocking && ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { id: "action-sheet-overlay", style: {+ style: Object.assign(Object.assign({}, props.style), { position: blocking ? "fixed" : "sticky", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }), tabIndex: -1 }, { children: [blocking && ((0, jsx_runtime_1.jsx)(framer_motion_1.motion.div, { id: "action-sheet-overlay", style: {height: "100%",width: "100%",- opacity: opacity,+ opacity,position: "absolute",backgroundColor: "var(--overlay)",}, tabIndex: -1 })), contentEl] })));- }, contentElement: function (props, children) { return ((0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({}, props, { style: {}, sx: {+ }, contentElement: (props, children) => ((0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({}, props, { style: {}, sx: {// top: 0,left: 0,right: 0,@@ -156,30 +129,28 @@ function ActionSheetPresenter(props) {zIndex: 0,outline: 0,isolation: "isolate",- } }, { children: children }))); } }, { children: (0, jsx_runtime_1.jsxs)(AnimatedFlex, __assign({ animate: animation, style: { y: y }, initial: { y: 1000 }, sx: {+ } }, { children: children }))) }, { children: (0, jsx_runtime_1.jsxs)(AnimatedFlex, Object.assign({ animate: animation, style: { y }, initial: { y: 1000 }, sx: {bg: "background",borderTopLeftRadius: 15,borderTopRightRadius: 15,boxShadow: theme.shadows.menu,flex: 1,flexDirection: "column",- } }, { children: [draggable && ((0, jsx_runtime_1.jsx)(AnimatedFlex, __assign({ drag: "y",+ } }, { children: [draggable && ((0, jsx_runtime_1.jsx)(AnimatedFlex, Object.assign({ drag: "y",// @ts-ignore- onDrag: function (_, _a) {- var delta = _a.delta;+ onDrag: (_, { delta }) => {y.set(Math.max(y.get() + delta.y, 0));},// @ts-ignore- onDragEnd: function (_, _a) {- var velocity = _a.velocity;+ onDragEnd: (_, { velocity }) => {if (velocity.y >= 500) {onClose === null || onClose === void 0 ? void 0 : onClose();return;}- var sheetEl = contentRef.current;- var contentHeight = sheetEl.offsetHeight;- var threshold = 30;- var closingHeight = (contentHeight * threshold) / 100;+ const sheetEl = contentRef.current;+ const contentHeight = sheetEl.offsetHeight;+ const threshold = 30;+ const closingHeight = (contentHeight * threshold) / 100;if (y.get() >= closingHeight) {onBeforeClose();}@@ -196,32 +167,32 @@ function ActionSheetPresenter(props) {width: 60,height: 8,borderRadius: 100,- } }) }))), (0, jsx_runtime_1.jsx)(ContentContainer, __assign({ items: items, title: title, onClose: onClose }, { children: children }))] })) })));+ } }) }))), (0, jsx_runtime_1.jsx)(ContentContainer, Object.assign({ items: items, title: title, onClose: onClose }, { children: children }))] })) })));}exports.ActionSheetPresenter = ActionSheetPresenter;function ContentContainer(props) {var _a;- var title = props.title, items = props.items, onClose = props.onClose, children = props.children;- var _b = useHistory({- title: title,- items: items,- }), current = _b.current, goBack = _b.goBack, canGoBack = _b.canGoBack, navigate = _b.navigate;- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { flexDirection: "column" } }, { children: [canGoBack || (current === null || current === void 0 ? void 0 : current.title) ? ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ id: "header", sx: { alignItems: "center", mx: 0, mb: 1 } }, { children: [canGoBack && ((0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({ variant: "icon", sx: { p: 1, ml: 1 }, onClick: goBack }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.arrowLeft, size: "big" }) }))), (current === null || current === void 0 ? void 0 : current.title) && ((0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "title", sx: { ml: 1, fontSize: "title" } }, { children: current === null || current === void 0 ? void 0 : current.title })))] }))) : null, children+ const { title, items, onClose, children } = props;+ const { current, goBack, canGoBack, navigate } = useHistory({+ title,+ items,+ });+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { flexDirection: "column" } }, { children: [canGoBack || (current === null || current === void 0 ? void 0 : current.title) ? ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ id: "header", sx: { alignItems: "center", mx: 0, mb: 1 } }, { children: [canGoBack && ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({ variant: "icon", sx: { p: 1, ml: 1 }, onClick: goBack }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.arrowLeft, size: "big" }) }))), (current === null || current === void 0 ? void 0 : current.title) && ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.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) {+ : (_a = current === null || current === void 0 ? void 0 : current.items) === null || _a === void 0 ? void 0 : _a.map((item) => {if (item.isHidden)return null;switch (item.type) {case "separator":return (0, jsx_runtime_1.jsx)(menuseparator_1.MenuSeparator, {}, item.key);case "button":- return ((0, jsx_runtime_1.jsx)(menubutton_1.MenuButton, { item: item, onClick: function (e) {+ return ((0, jsx_runtime_1.jsx)(menubutton_1.MenuButton, { item: item, onClick: (e) => {if (item.menu) {navigate(item.menu);}else if (item.onClick) {onClose === null || onClose === void 0 ? void 0 : onClose();- setTimeout(function () {+ setTimeout(() => {var _a;(_a = item.onClick) === null || _a === void 0 ? void 0 : _a.call(item);}, 300);diff --git a/packages/editor/dist/components/button.d.ts b/packages/editor/dist/cjs/components/button.d.tssimilarity index 100%rename from packages/editor/dist/components/button.d.tsrename to packages/editor/dist/cjs/components/button.d.tsdiff --git a/packages/editor/dist/cjs/components/button.js b/packages/editor/dist/cjs/components/button.jsnew file mode 100644index 000000000..b6ee899ad--- /dev/null+++ b/packages/editor/dist/cjs/components/button.js@@ -0,0 +1,34 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Button = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const react_2 = require("react");+const rebass_1 = require("rebass");+exports.Button = (0, react_1.forwardRef)((props, forwardedRef) => {+ const buttonRef = (0, react_1.useRef)();+ (0, react_2.useEffect)(() => {+ if (!buttonRef.current)+ return;+ buttonRef.current.addEventListener("mousedown", onMouseDown, {+ passive: false,+ capture: true,+ });+ return () => {+ var _a;+ (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("mousedown", onMouseDown, {+ capture: true,+ });+ };+ }, []);+ const onMouseDown = (0, react_1.useCallback)((e) => {+ e.preventDefault();+ }, []);+ return ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({}, props, { ref: (ref) => {+ buttonRef.current = ref;+ if (typeof forwardedRef === "function")+ forwardedRef(ref);+ else if (forwardedRef)+ forwardedRef.current = ref;+ }, onClick: props.onClick, onMouseDown: () => { } })));+});diff --git a/packages/editor/dist/components/inlineinput/index.d.ts b/packages/editor/dist/cjs/components/inlineinput/index.d.tssimilarity index 100%rename from packages/editor/dist/components/inlineinput/index.d.tsrename to packages/editor/dist/cjs/components/inlineinput/index.d.tsdiff --git a/packages/editor/dist/cjs/components/inlineinput/index.js b/packages/editor/dist/cjs/components/inlineinput/index.jsnew file mode 100644index 000000000..75a2f2e30--- /dev/null+++ b/packages/editor/dist/cjs/components/inlineinput/index.js@@ -0,0 +1,30 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.InlineInput = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const forms_1 = require("@rebass/forms");+const rebass_1 = require("rebass");+function InlineInput(props) {+ const { label, containerProps, sx } = props, inputProps = __rest(props, ["label", "containerProps", "sx"]);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({}, containerProps, { sx: Object.assign(Object.assign({ flex: 1 }, containerProps === null || containerProps === void 0 ? void 0 : containerProps.sx), { outline: "1px solid var(--border)", p: 2, borderRadius: "default", ":focus-within": {+ outlineColor: "primary",+ outlineWidth: "1.8px",+ } }) }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, Object.assign({ variant: "clean", sx: Object.assign(Object.assign({}, sx), { p: 0 }) }, inputProps)), (0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "body", sx: {+ flexShrink: 0,+ color: "fontTertiary",+ borderLeft: "1px solid var(--border)",+ pl: 1,+ } }, { children: label }))] })));+}+exports.InlineInput = InlineInput;diff --git a/packages/editor/dist/components/menu/index.d.ts b/packages/editor/dist/cjs/components/menu/index.d.tssimilarity index 100%rename from packages/editor/dist/components/menu/index.d.tsrename to packages/editor/dist/cjs/components/menu/index.d.tsdiff --git a/packages/editor/dist/components/menu/index.js b/packages/editor/dist/cjs/components/menu/index.jssimilarity index 57%rename from packages/editor/dist/components/menu/index.jsrename to packages/editor/dist/cjs/components/menu/index.jsindex c1b700bcd..69ee647a5 100644--- a/packages/editor/dist/components/menu/index.js+++ b/packages/editor/dist/cjs/components/menu/index.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __rest = (this && this.__rest) || function (s, e) {var t = {};for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)@@ -23,18 +12,18 @@ var __rest = (this && this.__rest) || function (s, e) {};Object.defineProperty(exports, "__esModule", { value: true });exports.MenuPresenter = exports.Menu = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var rebass_1 = require("rebass");-var position_1 = require("../../utils/position");-var usefocus_1 = require("./usefocus");-var menuseparator_1 = require("./menuseparator");-var menubutton_1 = require("./menubutton");-var popuppresenter_1 = require("../popuppresenter");+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const rebass_1 = require("rebass");+const position_1 = require("../../utils/position");+const usefocus_1 = require("./usefocus");+const menuseparator_1 = require("./menuseparator");+const menubutton_1 = require("./menubutton");+const popuppresenter_1 = require("../popuppresenter");function Menu(props) {- var _a = props.items, items = _a === void 0 ? [] : _a, title = props.title, onClose = props.onClose, containerProps = __rest(props, ["items", "title", "onClose"]);- var hoverTimeout = (0, react_1.useRef)();- var onAction = (0, react_1.useCallback)(function (e, item) {+ const { items = [], title, onClose } = props, containerProps = __rest(props, ["items", "title", "onClose"]);+ const hoverTimeout = (0, react_1.useRef)();+ const onAction = (0, react_1.useCallback)((e, item) => {e === null || e === void 0 ? void 0 : e.stopPropagation();if (item === null || item === void 0 ? void 0 : item.onClick) {item.onClick();@@ -42,48 +31,48 @@ function Menu(props) {if (onClose)onClose();}, [onClose]);- var _b = (0, usefocus_1.useFocus)(items, function (e) {- var item = items[focusIndex];+ const { focusIndex, setFocusIndex, isSubmenuOpen, setIsSubmenuOpen } = (0, usefocus_1.useFocus)(items, (e) => {+ const item = items[focusIndex];if (item && item.type === "button")onAction(e, item);- }, function () { return onClose(); }), focusIndex = _b.focusIndex, setFocusIndex = _b.setFocusIndex, isSubmenuOpen = _b.isSubmenuOpen, setIsSubmenuOpen = _b.setIsSubmenuOpen;- var focusedItem = items[focusIndex];- var subMenuRef = (0, react_1.useRef)(null);- (0, react_1.useEffect)(function () {- var item = items[focusIndex];+ }, () => onClose());+ const focusedItem = items[focusIndex];+ const subMenuRef = (0, react_1.useRef)(null);+ (0, react_1.useEffect)(() => {+ const item = items[focusIndex];if (!item || !subMenuRef.current)return;- var menuItemElement = document.getElementById(item.key);+ const menuItemElement = document.getElementById(item.key);if (!menuItemElement)return;if (!isSubmenuOpen) {subMenuRef.current.style.visibility = "hidden";return;}- var _a = (0, position_1.getPosition)(subMenuRef.current, {+ const { top, left } = (0, position_1.getPosition)(subMenuRef.current, {// yOffset: menuItemElement.offsetHeight,target: menuItemElement,location: "right",- }), top = _a.top, left = _a.left;+ });subMenuRef.current.style.visibility = "visible";- subMenuRef.current.style.top = "".concat(top, "px");- subMenuRef.current.style.left = "".concat(left, "px");+ subMenuRef.current.style.top = `${top}px`;+ subMenuRef.current.style.left = `${left}px`;}, [isSubmenuOpen, focusIndex, items]);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MenuContainer, __assign({}, containerProps, { children: items.map(function (item, index) {+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MenuContainer, Object.assign({}, containerProps, { children: items.map((item, index) => {if (item.isHidden)return null;switch (item.type) {case "separator":return (0, jsx_runtime_1.jsx)(menuseparator_1.MenuSeparator, {}, item.key);case "button":- return ((0, jsx_runtime_1.jsx)(menubutton_1.MenuButton, { item: item, onClick: function (e) {+ return ((0, jsx_runtime_1.jsx)(menubutton_1.MenuButton, { item: item, onClick: (e) => {if (item.menu) {setFocusIndex(index);setIsSubmenuOpen(true);}elseonAction(e, item);- }, isFocused: focusIndex === index, onMouseEnter: function () {+ }, isFocused: focusIndex === index, onMouseEnter: () => {if (item.isDisabled) {setFocusIndex(-1);return;@@ -93,25 +82,25 @@ function Menu(props) {setFocusIndex(index);setIsSubmenuOpen(false);if (item.menu) {- hoverTimeout.current = setTimeout(function () {+ hoverTimeout.current = setTimeout(() => {setIsSubmenuOpen(true);}, 500);}- }, onMouseLeave: function () {+ }, onMouseLeave: () => {if (hoverTimeout.current)clearTimeout(hoverTimeout.current);} }, item.key));case "popup":- return (0, jsx_runtime_1.jsx)(item.component, { onClick: function (e) { return onAction(e); } });+ return (0, jsx_runtime_1.jsx)(item.component, { onClick: (e) => onAction(e) });}- }) })), (focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.type) === "button" && (focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.menu) && isSubmenuOpen && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ ref: subMenuRef, style: { visibility: "hidden" }, sx: {+ }) })), (focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.type) === "button" && (focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.menu) && isSubmenuOpen && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ ref: subMenuRef, style: { visibility: "hidden" }, sx: {position: "absolute",} }, { children: (0, jsx_runtime_1.jsx)(Menu, { items: focusedItem.menu.items, onClose: onClose }) })))] }));}exports.Menu = Menu;function MenuContainer(props) {- var children = props.children, title = props.title, sx = props.sx, flexProps = __rest(props, ["children", "title", "sx"]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Box, __assign({ className: "menuContainer", as: "ul", tabIndex: -1, sx: __assign({ bg: "background", py: 1, display: "flex", flexDirection: "column", position: "relative", listStyle: "none", padding: 0, margin: 0, borderRadius: "default", boxShadow: "menu", border: "1px solid var(--border)", minWidth: 220 }, sx) }, flexProps, { children: [title && ((0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ sx: {+ const { children, title, sx } = props, flexProps = __rest(props, ["children", "title", "sx"]);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Box, Object.assign({ className: "menuContainer", as: "ul", tabIndex: -1, sx: Object.assign({ bg: "background", py: 1, display: "flex", flexDirection: "column", position: "relative", listStyle: "none", padding: 0, margin: 0, borderRadius: "default", boxShadow: "menu", border: "1px solid var(--border)", minWidth: 220 }, sx) }, flexProps, { children: [title && ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ sx: {fontFamily: "body",fontSize: "subtitle",color: "primary",@@ -123,7 +112,7 @@ function MenuContainer(props) {} }, { children: title }))), children] })));}function MenuPresenter(props) {- var _a = props.items, items = _a === void 0 ? [] : _a, restProps = __rest(props, ["items"]);- return ((0, jsx_runtime_1.jsx)(popuppresenter_1.PopupPresenter, __assign({}, restProps, { children: props.children ? props.children : (0, jsx_runtime_1.jsx)(Menu, __assign({ items: items }, restProps)) })));+ const { items = [] } = props, restProps = __rest(props, ["items"]);+ return ((0, jsx_runtime_1.jsx)(popuppresenter_1.PopupPresenter, Object.assign({}, restProps, { children: props.children ? props.children : (0, jsx_runtime_1.jsx)(Menu, Object.assign({ items: items }, restProps)) })));}exports.MenuPresenter = MenuPresenter;diff --git a/packages/editor/dist/components/menu/menubutton.d.ts b/packages/editor/dist/cjs/components/menu/menubutton.d.tssimilarity index 100%rename from packages/editor/dist/components/menu/menubutton.d.tsrename to packages/editor/dist/cjs/components/menu/menubutton.d.tsdiff --git a/packages/editor/dist/cjs/components/menu/menubutton.js b/packages/editor/dist/cjs/components/menu/menubutton.jsnew file mode 100644index 000000000..443b5acc9--- /dev/null+++ b/packages/editor/dist/cjs/components/menu/menubutton.js@@ -0,0 +1,31 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.MenuButton = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const rebass_1 = require("rebass");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const toolbarstore_1 = require("../../toolbar/stores/toolbarstore");+const button_1 = require("../button");+function MenuButton(props) {+ const { item, isFocused, onMouseEnter, onMouseLeave, onClick } = props;+ const { title, key, icon, tooltip, isDisabled, isChecked, menu, modifier } = item;+ const itemRef = (0, react_1.useRef)(null);+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ const isBottom = toolbarLocation === "bottom";+ return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ as: "li", sx: { flexShrink: 0, flexDirection: "column" }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, { children: (0, jsx_runtime_1.jsxs)(button_1.Button, Object.assign({ id: key, "data-test-id": `MenuButton-${key}`, ref: itemRef, tabIndex: -1, variant: "menuitem", title: tooltip, disabled: isDisabled, onClick: onClick, sx: {+ bg: isFocused && !isBottom ? "hover" : "transparent",+ display: "flex",+ alignItems: "center",+ justifyContent: "space-between",+ ":hover": {+ bg: isBottom ? "transparent" : "hover",+ },+ } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [icon && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons[icon], color: "text", size: "medium", sx: { mr: 2 } })), (0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ as: "span", variant: "body", sx: { fontSize: "inherit" } }, { children: title }))] }), isChecked || menu || modifier ? ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { ml: 4 } }, { children: [isChecked && (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.check, size: 14 }), menu && (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.chevronRight, size: 14 }), modifier && ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ as: "span", sx: {+ fontFamily: "body",+ fontSize: "menu",+ color: "fontTertiary",+ } }, { children: modifier })))] }))) : null] }), key) })));+}+exports.MenuButton = MenuButton;diff --git a/packages/editor/dist/components/menu/menuseparator.d.ts b/packages/editor/dist/cjs/components/menu/menuseparator.d.tssimilarity index 100%rename from packages/editor/dist/components/menu/menuseparator.d.tsrename to packages/editor/dist/cjs/components/menu/menuseparator.d.tsdiff --git a/packages/editor/dist/components/menu/menuseparator.js b/packages/editor/dist/cjs/components/menu/menuseparator.jssimilarity index 81%rename from packages/editor/dist/components/menu/menuseparator.jsrename to packages/editor/dist/cjs/components/menu/menuseparator.jsindex f664ce2b7..420897f28 100644--- a/packages/editor/dist/components/menu/menuseparator.js+++ b/packages/editor/dist/cjs/components/menu/menuseparator.js@@ -1,8 +1,8 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.MenuSeparator = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");function MenuSeparator() {return ((0, jsx_runtime_1.jsx)(rebass_1.Box, { as: "li", sx: {width: "95%",diff --git a/packages/editor/dist/components/menu/types.d.ts b/packages/editor/dist/cjs/components/menu/types.d.tssimilarity index 100%rename from packages/editor/dist/components/menu/types.d.tsrename to packages/editor/dist/cjs/components/menu/types.d.tsdiff --git a/packages/editor/dist/components/menu/types.js b/packages/editor/dist/cjs/components/menu/types.jssimilarity index 100%rename from packages/editor/dist/components/menu/types.jsrename to packages/editor/dist/cjs/components/menu/types.jsdiff --git a/packages/editor/dist/components/menu/usefocus.d.ts b/packages/editor/dist/cjs/components/menu/usefocus.d.tssimilarity index 100%rename from packages/editor/dist/components/menu/usefocus.d.tsrename to packages/editor/dist/cjs/components/menu/usefocus.d.tsdiff --git a/packages/editor/dist/components/menu/usefocus.js b/packages/editor/dist/cjs/components/menu/usefocus.jssimilarity index 57%rename from packages/editor/dist/components/menu/usefocus.jsrename to packages/editor/dist/cjs/components/menu/usefocus.jsindex 47fe8cdb8..cbc30ce35 100644--- a/packages/editor/dist/components/menu/usefocus.js+++ b/packages/editor/dist/cjs/components/menu/usefocus.js@@ -1,59 +1,43 @@"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};Object.defineProperty(exports, "__esModule", { value: true });exports.useFocus = void 0;-var react_1 = require("react");+const react_1 = require("react");function useFocus(items, onAction, onClose) {- var _a = __read((0, react_1.useState)(-1), 2), focusIndex = _a[0], setFocusIndex = _a[1];- var _b = __read((0, react_1.useState)(false), 2), isSubmenuOpen = _b[0], setIsSubmenuOpen = _b[1];- var moveItemIntoView = (0, react_1.useCallback)(function (index) {- var item = items[index];+ const [focusIndex, setFocusIndex] = (0, react_1.useState)(-1);+ const [isSubmenuOpen, setIsSubmenuOpen] = (0, react_1.useState)(false);+ const moveItemIntoView = (0, react_1.useCallback)((index) => {+ const item = items[index];if (!item)return;- var element = document.getElementById(item.key);+ const element = document.getElementById(item.key);if (!element)return;element.scrollIntoView({behavior: "auto",});}, [items]);- var onKeyDown = (0, react_1.useCallback)(function (e) {- var as = function (i) { return items[i]; };- var isSeperator = function (i) {+ const onKeyDown = (0, react_1.useCallback)((e) => {+ const as = (i) => items[i];+ const isSeperator = (i) => {var _a, _b;return items &&(((_a = items[i]) === null || _a === void 0 ? void 0 : _a.type) === "separator" || ((_b = as(i)) === null || _b === void 0 ? void 0 : _b.isDisabled));};- var moveDown = function (i) { return (i < items.length - 1 ? ++i : 0); };- var moveUp = function (i) { return (i > 0 ? --i : items.length - 1); };- var hasSubmenu = function (i) { return items && as(i).menu; };- var openSubmenu = function (index) {+ const moveDown = (i) => (i < items.length - 1 ? ++i : 0);+ const moveUp = (i) => (i > 0 ? --i : items.length - 1);+ const hasSubmenu = (i) => items && as(i).menu;+ const openSubmenu = (index) => {if (!hasSubmenu(index))return;setIsSubmenuOpen(true);};- var closeSubmenu = function (index) {+ const closeSubmenu = (index) => {if (!hasSubmenu(index))return;setIsSubmenuOpen(false);};- setFocusIndex(function (i) {- var nextIndex = i;+ setFocusIndex((i) => {+ let nextIndex = i;switch (e.key) {case "ArrowUp":if (isSubmenuOpen)@@ -91,12 +75,12 @@ function useFocus(items, onAction, onClose) {return nextIndex;});}, [items, isSubmenuOpen, moveItemIntoView, onAction]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {window.addEventListener("keydown", onKeyDown);- return function () {+ return () => {window.removeEventListener("keydown", onKeyDown);};}, [onKeyDown]);- return { focusIndex: focusIndex, setFocusIndex: setFocusIndex, isSubmenuOpen: isSubmenuOpen, setIsSubmenuOpen: setIsSubmenuOpen };+ return { focusIndex, setFocusIndex, isSubmenuOpen, setIsSubmenuOpen };}exports.useFocus = useFocus;diff --git a/packages/editor/dist/components/popuppresenter/index.d.ts b/packages/editor/dist/cjs/components/popuppresenter/index.d.tssimilarity index 100%rename from packages/editor/dist/components/popuppresenter/index.d.tsrename to packages/editor/dist/cjs/components/popuppresenter/index.d.tsdiff --git a/packages/editor/dist/components/popuppresenter/index.js b/packages/editor/dist/cjs/components/popuppresenter/index.jssimilarity index 51%rename from packages/editor/dist/components/popuppresenter/index.jsrename to packages/editor/dist/cjs/components/popuppresenter/index.jsindex b60d0d5cd..c0900f1f7 100644--- a/packages/editor/dist/components/popuppresenter/index.js+++ b/packages/editor/dist/cjs/components/popuppresenter/index.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __rest = (this && this.__rest) || function (s, e) {var t = {};for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)@@ -26,49 +15,49 @@ var __importDefault = (this && this.__importDefault) || function (mod) {};Object.defineProperty(exports, "__esModule", { value: true });exports.showPopup = exports.PopupWrapper = exports.PopupPresenter = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var rebass_1 = require("rebass");-var position_1 = require("../../utils/position");-var react_modal_1 = __importDefault(require("react-modal"));-var react_dom_1 = __importDefault(require("react-dom"));-var emotion_theming_1 = require("emotion-theming");-var dom_1 = require("../../toolbar/utils/dom");-var toolbarstore_1 = require("../../toolbar/stores/toolbarstore");-var popuprenderer_1 = require("./popuprenderer");-var responsive_1 = require("../responsive");+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const rebass_1 = require("rebass");+const position_1 = require("../../utils/position");+const react_modal_1 = __importDefault(require("react-modal"));+const react_dom_1 = __importDefault(require("react-dom"));+const emotion_theming_1 = require("emotion-theming");+const dom_1 = require("../../toolbar/utils/dom");+const toolbarstore_1 = require("../../toolbar/stores/toolbarstore");+const popuprenderer_1 = require("./popuprenderer");+const responsive_1 = require("../responsive");function _PopupPresenter(props) {- var isOpen = props.isOpen, position = props.position, onClose = props.onClose, _a = props.blocking, blocking = _a === void 0 ? true : _a, _b = props.focusOnRender, focusOnRender = _b === void 0 ? true : _b, children = props.children;- var isMobile = (0, toolbarstore_1.useIsMobile)();- var contentRef = (0, react_1.useRef)();- var observerRef = (0, react_1.useRef)();- var repositionPopup = (0, react_1.useCallback)(function () {+ const { isOpen, position, onClose, blocking = true, focusOnRender = true, children, } = props;+ const isMobile = (0, toolbarstore_1.useIsMobile)();+ const contentRef = (0, react_1.useRef)();+ const observerRef = (0, react_1.useRef)();+ const repositionPopup = (0, react_1.useCallback)(() => {if (!contentRef.current || !position)return;- var popup = contentRef.current;- var popupPosition = (0, position_1.getPosition)(popup, position);+ const popup = contentRef.current;+ const popupPosition = (0, position_1.getPosition)(popup, position);popup.style.top = popupPosition.top + "px";popup.style.left = popupPosition.left + "px";}, [position]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {repositionPopup();}, [position]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {function onWindowResize() {repositionPopup();}window.addEventListener("resize", onWindowResize);- return function () {+ return () => {window.removeEventListener("resize", onWindowResize);};}, []);- var attachMoveHandlers = (0, react_1.useCallback)(function () {+ const attachMoveHandlers = (0, react_1.useCallback)(() => {if (!contentRef.current || !isOpen)return;- var movableBar = contentRef.current.querySelector(".movable");+ const movableBar = contentRef.current.querySelector(".movable");if (!movableBar)return;- var popup = contentRef.current;+ const popup = contentRef.current;var offset = { x: 0, y: 0 };function mouseDown(e) {offset.x = e.clientX - popup.offsetLeft;@@ -80,7 +69,7 @@ function _PopupPresenter(props) {mouseUp();var top = e.clientY - offset.y;var left = e.clientX - offset.x;- requestAnimationFrame(function () {+ requestAnimationFrame(() => {popup.style.top = top + "px";popup.style.left = left + "px";});@@ -91,23 +80,23 @@ function _PopupPresenter(props) {movableBar.addEventListener("mousedown", mouseDown);window.addEventListener("mouseup", mouseUp);}, [isOpen]);- var handleResize = (0, react_1.useCallback)(function () {- var popup = contentRef.current;+ const handleResize = (0, react_1.useCallback)(() => {+ const popup = contentRef.current;if (!popup)return;- var oldHeight = popup.offsetHeight;- observerRef.current = new ResizeObserver(function (e) {+ let oldHeight = popup.offsetHeight;+ observerRef.current = new ResizeObserver((e) => {if (isMobile) {repositionPopup();}else {- var _a = popup.getBoundingClientRect(), height = _a.height, y = _a.y;- var delta = height - oldHeight;+ const { height, y } = popup.getBoundingClientRect();+ const delta = height - oldHeight;if (delta > 0) {// means the new size is bigger so we need to adjust the position// if required. We only do this in case the newly resized popup// is going out of the window.- var windowHeight = document.body.clientHeight - 20;+ const windowHeight = document.body.clientHeight - 20;if (y + height > windowHeight) {popup.style.top = windowHeight - height + "px";}@@ -117,17 +106,17 @@ function _PopupPresenter(props) {});observerRef.current.observe(popup, { box: "border-box" });}, [isMobile]);- return ((0, jsx_runtime_1.jsx)(react_modal_1.default, __assign({ contentRef: function (ref) { return (contentRef.current = ref); }, className: "popup-presenter", role: "menu", isOpen: isOpen, appElement: document.body, shouldCloseOnEsc: true, shouldReturnFocusAfterClose: true, shouldCloseOnOverlayClick: true, shouldFocusAfterRender: focusOnRender, ariaHideApp: blocking, preventScroll: blocking, onRequestClose: onClose, portalClassName: "popup-presenter-portal", onAfterOpen: function (obj) {+ return ((0, jsx_runtime_1.jsx)(react_modal_1.default, Object.assign({ contentRef: (ref) => (contentRef.current = ref), className: "popup-presenter", role: "menu", isOpen: isOpen, appElement: document.body, shouldCloseOnEsc: true, shouldReturnFocusAfterClose: true, shouldCloseOnOverlayClick: true, shouldFocusAfterRender: focusOnRender, ariaHideApp: blocking, preventScroll: blocking, onRequestClose: onClose, portalClassName: "popup-presenter-portal", onAfterOpen: (obj) => {if (!obj || !position)return;repositionPopup();handleResize();attachMoveHandlers();- }, onAfterClose: function () { var _a; return (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect(); }, overlayElement: function (props, contentEl) {- return ((0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({}, props, {+ }, onAfterClose: () => { var _a; return (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect(); }, overlayElement: (props, contentEl) => {+ return ((0, jsx_runtime_1.jsx)(rebass_1.Box, Object.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 ((0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({}, props, { style: {},+ style: Object.assign(Object.assign({}, props.style), { position: !blocking ? "initial" : "fixed", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }) }, { children: contentEl })));+ }, contentElement: (props, children) => ((0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({}, props, { style: {},// TODO onMouseDown={(e) => {// console.log(e);// }}@@ -145,7 +134,7 @@ function _PopupPresenter(props) {zIndex: 0,outline: 0,isolation: "isolate",- } }, { children: children }))); }, style: {+ } }, { children: children }))), style: {content: {},overlay: {zIndex: 999,@@ -159,62 +148,61 @@ function PopupPresenter(props) {// if the popup is closed.if (!props.isOpen)return null;- return (0, jsx_runtime_1.jsx)(_PopupPresenter, __assign({}, props));+ return (0, jsx_runtime_1.jsx)(_PopupPresenter, Object.assign({}, props));}exports.PopupPresenter = PopupPresenter;function PopupWrapper(props) {- var id = props.id, group = props.group, position = props.position, renderPopup = props.renderPopup, isOpen = props.isOpen, onClosed = props.onClosed, autoCloseOnUnmount = props.autoCloseOnUnmount, presenterProps = __rest(props, ["id", "group", "position", "renderPopup", "isOpen", "onClosed", "autoCloseOnUnmount"]);- var PopupRenderer = (0, popuprenderer_1.usePopupRenderer)();- var isPopupOpen = (0, toolbarstore_1.useToolbarStore)(function (store) { return !!store.openedPopups[id]; });- var openPopup = (0, toolbarstore_1.useToolbarStore)(function (store) { return store.openPopup; });- var closePopup = (0, toolbarstore_1.useToolbarStore)(function (store) { return store.closePopup; });- var closePopupGroup = (0, toolbarstore_1.useToolbarStore)(function (store) { return store.closePopupGroup; });- var isBottom = (0, toolbarstore_1.useToolbarStore)(function (store) { return store.toolbarLocation === "bottom"; });+ let { id, group, position, renderPopup, isOpen, onClosed, autoCloseOnUnmount } = props, presenterProps = __rest(props, ["id", "group", "position", "renderPopup", "isOpen", "onClosed", "autoCloseOnUnmount"]);+ const PopupRenderer = (0, popuprenderer_1.usePopupRenderer)();+ const isPopupOpen = (0, toolbarstore_1.useToolbarStore)((store) => !!store.openedPopups[id]);+ const openPopup = (0, toolbarstore_1.useToolbarStore)((store) => store.openPopup);+ const closePopup = (0, toolbarstore_1.useToolbarStore)((store) => store.closePopup);+ const closePopupGroup = (0, toolbarstore_1.useToolbarStore)((store) => store.closePopupGroup);+ const isBottom = (0, toolbarstore_1.useToolbarStore)((store) => store.toolbarLocation === "bottom");if (isBottom)group = "popup";- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {if (isOpen)- openPopup({ id: id, group: group });+ openPopup({ id, group });elseclosePopup(id);}, [isOpen, id, group, openPopup, closePopup]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {if (!autoCloseOnUnmount)return;- return function () {+ return () => {PopupRenderer === null || PopupRenderer === void 0 ? void 0 : PopupRenderer.closePopup(id);};}, [autoCloseOnUnmount, id]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {if (!isPopupOpen)onClosed === null || onClosed === void 0 ? void 0 : onClosed();}, [isPopupOpen]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {if (isPopupOpen) {closePopupGroup(group, [id]);}}, [onClosed, isPopupOpen, closePopupGroup, id, group]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {if (!isOpen)closePopup(id);}, [isOpen, id, group, closePopup]);- (0, react_1.useEffect)(function () {+ (0, react_1.useEffect)(() => {if (PopupRenderer && isPopupOpen) {- PopupRenderer.openPopup(id, function Popup(_a) {- var id = _a.id;- var isPopupOpen = (0, toolbarstore_1.useToolbarStore)(function (store) { return !!store.openedPopups[id]; });- (0, react_1.useEffect)(function () {+ PopupRenderer.openPopup(id, function Popup({ id }) {+ const isPopupOpen = (0, toolbarstore_1.useToolbarStore)((store) => !!store.openedPopups[id]);+ (0, react_1.useEffect)(() => {if (!isPopupOpen) {PopupRenderer.closePopup(id);}}, [isPopupOpen]);- return ((0, jsx_runtime_1.jsx)(PopupPresenter, __assign({ isOpen: isPopupOpen, onClose: function () { return closePopup(id); }, position: position, blocking: true, focusOnRender: true }, presenterProps, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ sx: {+ return ((0, jsx_runtime_1.jsx)(PopupPresenter, Object.assign({ isOpen: isPopupOpen, onClose: () => closePopup(id), position: position, blocking: true, focusOnRender: true }, presenterProps, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {boxShadow: "menu",borderRadius: "default",overflow: "hidden",// width,- } }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Consumer, { children: function () {- return renderPopup(function () { return PopupRenderer.closePopup(id); });+ } }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Consumer, { children: () => {+ return renderPopup(() => PopupRenderer.closePopup(id));} }) })) }), id));});}@@ -223,11 +211,11 @@ function PopupWrapper(props) {}exports.PopupWrapper = PopupWrapper;function showPopup(options) {- var theme = options.theme, popup = options.popup, props = __rest(options, ["theme", "popup"]);+ const { theme, popup } = options, props = __rest(options, ["theme", "popup"]);function hide() {react_dom_1.default.unmountComponentAtNode((0, dom_1.getPopupContainer)());}- react_dom_1.default.render((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, __assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, __assign({ isOpen: true, onClose: hide, position: {+ react_dom_1.default.render((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, Object.assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, Object.assign({ isOpen: true, onClose: hide, position: {target: (0, dom_1.getToolbarElement)(),isTargetAbsolute: true,location: "below",diff --git a/packages/editor/dist/components/popuppresenter/popuprenderer.d.ts b/packages/editor/dist/cjs/components/popuppresenter/popuprenderer.d.tssimilarity index 100%rename from packages/editor/dist/components/popuppresenter/popuprenderer.d.tsrename to packages/editor/dist/cjs/components/popuppresenter/popuprenderer.d.tsdiff --git a/packages/editor/dist/cjs/components/popuppresenter/popuprenderer.js b/packages/editor/dist/cjs/components/popuppresenter/popuprenderer.jsnew file mode 100644index 000000000..ca65fed17--- /dev/null+++ b/packages/editor/dist/cjs/components/popuppresenter/popuprenderer.js@@ -0,0 +1,74 @@+"use strict";+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ var desc = Object.getOwnPropertyDescriptor(m, k);+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {+ desc = { enumerable: true, get: function() { return m[k]; } };+ }+ Object.defineProperty(o, k2, desc);+}) : (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ o[k2] = m[k];+}));+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {+ Object.defineProperty(o, "default", { enumerable: true, value: v });+}) : function(o, v) {+ o["default"] = v;+});+var __importStar = (this && this.__importStar) || function (mod) {+ if (mod && mod.__esModule) return mod;+ var result = {};+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);+ __setModuleDefault(result, mod);+ return result;+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.useEditorContext = exports.usePopupRenderer = exports.PopupRenderer = exports.EditorContext = exports.PopupRendererContext = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importStar(require("react"));+exports.PopupRendererContext = react_1.default.createContext(null);+exports.EditorContext = react_1.default.createContext(null);+class PopupRenderer extends react_1.default.Component {+ constructor() {+ super(...arguments);+ this.popupContainer = null;+ this.state = {+ popups: [],+ };+ this.openPopup = (id, popup) => {+ if (!popup)+ return;+ this.setState((prev) => {+ return {+ popups: [...prev.popups, { id, popup }],+ };+ });+ };+ this.closePopup = (id) => {+ this.setState((prev) => {+ const index = prev.popups.findIndex((p) => p.id === id);+ if (index <= -1)+ return prev;+ const clone = prev.popups.slice();+ clone.splice(index, 1);+ return {+ popups: clone,+ };+ });+ };+ }+ render() {+ return ((0, jsx_runtime_1.jsxs)(exports.PopupRendererContext.Provider, Object.assign({ value: this }, { children: [this.props.children, (0, jsx_runtime_1.jsxs)(exports.EditorContext.Provider, Object.assign({ value: this.props.editor }, { children: [this.state.popups.map(({ id, popup: Popup }) => {+ return (0, jsx_runtime_1.jsx)(Popup, { id: id }, id);+ }), (0, jsx_runtime_1.jsx)("div", { id: "popup-container" })] }))] })));+ }+}+exports.PopupRenderer = PopupRenderer;+function usePopupRenderer() {+ return (0, react_1.useContext)(exports.PopupRendererContext);+}+exports.usePopupRenderer = usePopupRenderer;+function useEditorContext() {+ return (0, react_1.useContext)(exports.EditorContext);+}+exports.useEditorContext = useEditorContext;diff --git a/packages/editor/dist/components/responsive/index.d.ts b/packages/editor/dist/cjs/components/responsive/index.d.tssimilarity index 100%rename from packages/editor/dist/components/responsive/index.d.tsrename to packages/editor/dist/cjs/components/responsive/index.d.tsdiff --git a/packages/editor/dist/components/responsive/index.js b/packages/editor/dist/cjs/components/responsive/index.jssimilarity index 62%rename from packages/editor/dist/components/responsive/index.jsrename to packages/editor/dist/cjs/components/responsive/index.jsindex d490514a8..077e67540 100644--- a/packages/editor/dist/components/responsive/index.js+++ b/packages/editor/dist/cjs/components/responsive/index.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __rest = (this && this.__rest) || function (s, e) {var t = {};for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)@@ -23,12 +12,12 @@ var __rest = (this && this.__rest) || function (s, e) {};Object.defineProperty(exports, "__esModule", { value: true });exports.ResponsivePresenter = exports.MobileOnly = exports.DesktopOnly = exports.ResponsiveContainer = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbarstore_1 = require("../../toolbar/stores/toolbarstore");-var actionsheet_1 = require("../actionsheet");-var menu_1 = require("../menu");+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbarstore_1 = require("../../toolbar/stores/toolbarstore");+const actionsheet_1 = require("../actionsheet");+const menu_1 = require("../menu");function ResponsiveContainer(props) {- var isMobile = (0, toolbarstore_1.useIsMobile)();+ const isMobile = (0, toolbarstore_1.useIsMobile)();if (isMobile)return props.mobile || null;else@@ -44,12 +33,12 @@ function MobileOnly(props) {}exports.MobileOnly = MobileOnly;function ResponsivePresenter(props) {- var _a = props.mobile, mobile = _a === void 0 ? "menu" : _a, _b = props.desktop, desktop = _b === void 0 ? "menu" : _b, restProps = __rest(props, ["mobile", "desktop"]);- var isMobile = (0, toolbarstore_1.useIsMobile)();+ const { mobile = "menu", desktop = "menu" } = props, restProps = __rest(props, ["mobile", "desktop"]);+ const isMobile = (0, toolbarstore_1.useIsMobile)();if (isMobile && mobile === "sheet")- return (0, jsx_runtime_1.jsx)(actionsheet_1.ActionSheetPresenter, __assign({}, restProps));+ return (0, jsx_runtime_1.jsx)(actionsheet_1.ActionSheetPresenter, Object.assign({}, restProps));else if (mobile === "menu" || desktop === "menu")- return (0, jsx_runtime_1.jsx)(menu_1.MenuPresenter, __assign({}, restProps));+ return (0, jsx_runtime_1.jsx)(menu_1.MenuPresenter, Object.assign({}, restProps));elsereturn props.isOpen ? (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.children }) : null;}diff --git a/packages/editor/dist/components/tabs/index.d.ts b/packages/editor/dist/cjs/components/tabs/index.d.tssimilarity index 100%rename from packages/editor/dist/components/tabs/index.d.tsrename to packages/editor/dist/cjs/components/tabs/index.d.tsdiff --git a/packages/editor/dist/components/tabs/index.js b/packages/editor/dist/cjs/components/tabs/index.jssimilarity index 54%rename from packages/editor/dist/components/tabs/index.jsrename to packages/editor/dist/cjs/components/tabs/index.jsindex fd202ee67..08548201d 100644--- a/packages/editor/dist/components/tabs/index.js+++ b/packages/editor/dist/cjs/components/tabs/index.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {if (k2 === undefined) k2 = k;var desc = Object.getOwnPropertyDescriptor(m, k);@@ -33,43 +22,25 @@ var __importStar = (this && this.__importStar) || function (mod) {__setModuleDefault(result, mod);return result;};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};Object.defineProperty(exports, "__esModule", { value: true });exports.Tabs = exports.Tab = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importStar(require("react"));-var rebass_1 = require("rebass");+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importStar(require("react"));+const rebass_1 = require("rebass");function Tab(props) {return (0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: props.children });}exports.Tab = Tab;function Tabs(props) {- var activeIndex = props.activeIndex, children = props.children, containerProps = props.containerProps, onTabChanged = props.onTabChanged;- var _a = __read((0, react_1.useState)(activeIndex || 0), 2), activeTab = _a[0], setActiveTab = _a[1];- var tabs = (0, react_1.useMemo)(function () {- return react_1.Children.map(children, function (child) {- if (react_1.default.isValidElement(child))- return { title: child.props.title, component: child };- });- }, [children]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { flexDirection: "column" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {+ const { activeIndex, children, containerProps, onTabChanged } = props;+ const [activeTab, setActiveTab] = (0, react_1.useState)(activeIndex || 0);+ const tabs = (0, react_1.useMemo)(() => react_1.Children.map(children, (child) => {+ if (react_1.default.isValidElement(child))+ return { title: child.props.title, component: child };+ }), [children]);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { flexDirection: "column" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {mb: 1,- } }, { children: tabs === null || tabs === void 0 ? void 0 : tabs.map(function (tab, index) { return ((0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({ sx: {+ } }, { children: tabs === null || tabs === void 0 ? void 0 : tabs.map((tab, index) => ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({ sx: {flex: 1,p: 0,py: 1,@@ -85,9 +56,9 @@ function Tabs(props) {":hover": {bg: "hover",},- }, onClick: function () {+ }, onClick: () => {setActiveTab(index);onTabChanged === null || onTabChanged === void 0 ? void 0 : onTabChanged(index);- } }, { children: tab.title }), index.toString())); }) })), (0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({}, containerProps, { children: tabs && tabs[activeTab].component }))] })));+ } }, { children: tab.title }), index.toString()))) })), (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({}, containerProps, { children: tabs && tabs[activeTab].component }))] })));}exports.Tabs = Tabs;diff --git a/packages/editor/dist/extensions.d.ts b/packages/editor/dist/cjs/extensions.d.tssimilarity index 100%rename from packages/editor/dist/extensions.d.tsrename to packages/editor/dist/cjs/extensions.d.tsdiff --git a/packages/editor/dist/extensions.js b/packages/editor/dist/cjs/extensions.jssimilarity index 100%rename from packages/editor/dist/extensions.jsrename to packages/editor/dist/cjs/extensions.jsdiff --git a/packages/editor/dist/extensions/attachment/attachment.d.ts b/packages/editor/dist/cjs/extensions/attachment/attachment.d.tssimilarity index 100%rename from packages/editor/dist/extensions/attachment/attachment.d.tsrename to packages/editor/dist/cjs/extensions/attachment/attachment.d.tsdiff --git a/packages/editor/dist/cjs/extensions/attachment/attachment.js b/packages/editor/dist/cjs/extensions/attachment/attachment.jsnew file mode 100644index 000000000..15beea53d--- /dev/null+++ b/packages/editor/dist/cjs/extensions/attachment/attachment.js@@ -0,0 +1,113 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.getDataAttribute = exports.AttachmentNode = void 0;+const core_1 = require("@tiptap/core");+const react_1 = require("../react");+const component_1 = require("./component");+exports.AttachmentNode = core_1.Node.create({+ name: "attachment",+ content: "inline*",+ marks: "",+ inline: true,+ atom: true,+ addOptions() {+ return {+ HTMLAttributes: {},+ onDownloadAttachment: () => false,+ onOpenAttachmentPicker: () => false,+ };+ },+ group() {+ return "inline";+ },+ draggable: true,+ addAttributes() {+ return {+ progress: {+ default: 0,+ rendered: false,+ },+ hash: getDataAttribute("hash"),+ filename: getDataAttribute("filename"),+ type: getDataAttribute("mime"),+ size: getDataAttribute("size"),+ };+ },+ parseHTML() {+ return [+ {+ tag: "span[data-hash]",+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "span",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),+ ];+ },+ addNodeView() {+ return (0, react_1.createSelectionBasedNodeView)(component_1.AttachmentComponent, {+ shouldUpdate: ({ attrs: prev }, { attrs: next }) => {+ return prev.progress !== next.progress;+ },+ });+ },+ addCommands() {+ return {+ insertAttachment: (attachment) => ({ commands }) => {+ return commands.insertContent({+ type: this.name,+ attrs: attachment,+ });+ },+ removeAttachment: () => ({ commands }) => commands.deleteNode(this.name),+ downloadAttachment: (attachment) => ({ editor }) => {+ return this.options.onDownloadAttachment(editor, attachment);+ },+ openAttachmentPicker: (type) => ({ editor }) => {+ return this.options.onOpenAttachmentPicker(editor, type);+ },+ setAttachmentProgress: (options) => ({ state, tr, dispatch }) => {+ const { hash, progress, type } = options;+ const attachments = (0, core_1.findChildren)(state.doc, (node) => (node.type.name === this.name || node.type.name === "image") &&+ node.attrs.hash === hash);+ for (const attachment of attachments) {+ tr.setNodeMarkup(attachment.pos, attachment.node.type, Object.assign(Object.assign({}, attachment.node.attrs), { progress: progress === 100 ? null : progress }));+ }+ tr.setMeta("preventUpdate", true);+ tr.setMeta("addToHistory", false);+ if (dispatch)+ dispatch(tr);+ return true;+ },+ };+ },+ // addInputRules() {+ // return [+ // nodeInputRule({+ // find: inputRegex,+ // type: this.type,+ // getAttributes: (match) => {+ // const [, , alt, src, title] = match;+ // return { src, alt, title };+ // },+ // }),+ // ];+ // },+});+function getDataAttribute(name, def) {+ return {+ default: def,+ parseHTML: (element) => element.dataset[name],+ renderHTML: (attributes) => {+ if (!attributes[name]) {+ return {};+ }+ return {+ [`data-${name}`]: attributes[name],+ };+ },+ };+}+exports.getDataAttribute = getDataAttribute;diff --git a/packages/editor/dist/extensions/attachment/component.d.ts b/packages/editor/dist/cjs/extensions/attachment/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/attachment/component.d.tsrename to packages/editor/dist/cjs/extensions/attachment/component.d.tsdiff --git a/packages/editor/dist/extensions/attachment/component.js b/packages/editor/dist/cjs/extensions/attachment/component.jssimilarity index 51%rename from packages/editor/dist/extensions/attachment/component.jsrename to packages/editor/dist/cjs/extensions/attachment/component.jsindex 89979d868..38ae1fc41 100644--- a/packages/editor/dist/extensions/attachment/component.js+++ b/packages/editor/dist/cjs/extensions/attachment/component.js@@ -1,30 +1,19 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};Object.defineProperty(exports, "__esModule", { value: true });exports.AttachmentComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("react");+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("react");// import { MenuPresenter } from "../../components/menu/menu";-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var toolbargroup_1 = require("../../toolbar/components/toolbargroup");-var responsive_1 = require("../../components/responsive");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const toolbargroup_1 = require("../../toolbar/components/toolbargroup");+const responsive_1 = require("../../components/responsive");function AttachmentComponent(props) {- var editor = props.editor, node = props.node, selected = props.selected;- var _a = node.attrs, hash = _a.hash, filename = _a.filename, size = _a.size, progress = _a.progress;- var elementRef = (0, react_1.useRef)();- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Box, __assign({ ref: elementRef, as: "span", contentEditable: false, variant: "body", sx: {+ const { editor, node, selected } = props;+ const { hash, filename, size, progress } = node.attrs;+ const elementRef = (0, react_1.useRef)();+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Box, Object.assign({ ref: elementRef, as: "span", contentEditable: false, variant: "body", sx: {display: "inline-flex",position: "relative",justifyContent: "center",@@ -40,18 +29,18 @@ function AttachmentComponent(props) {":hover": {bg: "hover",},- }, title: filename }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.attachment, size: 14 }), (0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ as: "span", sx: {+ }, title: filename }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.attachment, size: 14 }), (0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ as: "span", sx: {ml: "small",fontSize: "body",whiteSpace: "nowrap",textOverflow: "ellipsis",overflow: "hidden",- } }, { children: filename })), (0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ as: "span", sx: {+ } }, { children: filename })), (0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ as: "span", sx: {ml: 1,fontSize: "0.65rem",color: "fontTertiary",flexShrink: 0,- } }, { children: progress ? "".concat(progress, "%") : formatBytes(size) })), (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { editor: editor, tools: ["removeAttachment", "downloadAttachment"], sx: {+ } }, { children: progress ? `${progress}%` : formatBytes(size) })), (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { editor: editor, tools: ["removeAttachment", "downloadAttachment"], sx: {boxShadow: "menu",borderRadius: "default",bg: "background",@@ -60,13 +49,12 @@ function AttachmentComponent(props) {} })) })] })) }));}exports.AttachmentComponent = AttachmentComponent;-function formatBytes(bytes, decimals) {- if (decimals === void 0) { decimals = 1; }+function formatBytes(bytes, decimals = 1) {if (bytes === 0)return "0B";- var k = 1024;- var dm = decimals < 0 ? 0 : decimals;- var sizes = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];- var i = Math.floor(Math.log(bytes) / Math.log(k));+ const k = 1024;+ const dm = decimals < 0 ? 0 : decimals;+ const sizes = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];+ const i = Math.floor(Math.log(bytes) / Math.log(k));return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + sizes[i];}diff --git a/packages/editor/dist/extensions/attachment/index.d.ts b/packages/editor/dist/cjs/extensions/attachment/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/attachment/index.d.tsrename to packages/editor/dist/cjs/extensions/attachment/index.d.tsdiff --git a/packages/editor/dist/extensions/attachment/index.js b/packages/editor/dist/cjs/extensions/attachment/index.jssimilarity index 100%rename from packages/editor/dist/extensions/attachment/index.jsrename to packages/editor/dist/cjs/extensions/attachment/index.jsdiff --git a/packages/editor/dist/extensions/bulletlist/bulletlist.d.ts b/packages/editor/dist/cjs/extensions/bulletlist/bulletlist.d.tssimilarity index 100%rename from packages/editor/dist/extensions/bulletlist/bulletlist.d.tsrename to packages/editor/dist/cjs/extensions/bulletlist/bulletlist.d.tsdiff --git a/packages/editor/dist/extensions/bulletlist/bulletlist.js b/packages/editor/dist/cjs/extensions/bulletlist/bulletlist.jssimilarity index 63%rename from packages/editor/dist/extensions/bulletlist/bulletlist.jsrename to packages/editor/dist/cjs/extensions/bulletlist/bulletlist.jsindex 6ee9c5669..17294e416 100644--- a/packages/editor/dist/extensions/bulletlist/bulletlist.js+++ b/packages/editor/dist/cjs/extensions/bulletlist/bulletlist.js@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {};Object.defineProperty(exports, "__esModule", { value: true });exports.BulletList = void 0;-var extension_bullet_list_1 = __importDefault(require("@tiptap/extension-bullet-list"));+const extension_bullet_list_1 = __importDefault(require("@tiptap/extension-bullet-list"));exports.BulletList = extension_bullet_list_1.default.extend({- addAttributes: function () {+ addAttributes() {return {listType: {default: null,- parseHTML: function (element) { return element.style.listStyleType; },- renderHTML: function (attributes) {+ parseHTML: (element) => element.style.listStyleType,+ renderHTML: (attributes) => {if (!attributes.listType) {return {};}return {- style: "list-style-type: ".concat(attributes.listType),+ style: `list-style-type: ${attributes.listType}`,};},},diff --git a/packages/editor/dist/extensions/bulletlist/index.d.ts b/packages/editor/dist/cjs/extensions/bulletlist/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/bulletlist/index.d.tsrename to packages/editor/dist/cjs/extensions/bulletlist/index.d.tsdiff --git a/packages/editor/dist/extensions/bulletlist/index.js b/packages/editor/dist/cjs/extensions/bulletlist/index.jssimilarity index 94%rename from packages/editor/dist/extensions/bulletlist/index.jsrename to packages/editor/dist/cjs/extensions/bulletlist/index.jsindex ab6009d4e..d9a3f601a 100644--- a/packages/editor/dist/extensions/bulletlist/index.js+++ b/packages/editor/dist/cjs/extensions/bulletlist/index.js@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);};Object.defineProperty(exports, "__esModule", { value: true });-var bulletlist_1 = require("./bulletlist");+const bulletlist_1 = require("./bulletlist");__exportStar(require("./bulletlist"), exports);exports.default = bulletlist_1.BulletList;diff --git a/packages/editor/dist/extensions/codeblock/codeblock.d.ts b/packages/editor/dist/cjs/extensions/codeblock/codeblock.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codeblock/codeblock.d.tsrename to packages/editor/dist/cjs/extensions/codeblock/codeblock.d.tsdiff --git a/packages/editor/dist/cjs/extensions/codeblock/codeblock.js b/packages/editor/dist/cjs/extensions/codeblock/codeblock.jsnew file mode 100644index 000000000..c7e83230e--- /dev/null+++ b/packages/editor/dist/cjs/extensions/codeblock/codeblock.js@@ -0,0 +1,516 @@+"use strict";+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.toCodeLines = exports.getLines = exports.toCaretPosition = exports.CodeBlock = exports.tildeInputRegex = exports.backtickInputRegex = void 0;+const core_1 = require("@tiptap/core");+const core_2 = require("@tiptap/core");+const prosemirror_state_1 = require("prosemirror-state");+const component_1 = require("./component");+const highlighter_1 = require("./highlighter");+const react_1 = require("../react");+const detect_indent_1 = __importDefault(require("detect-indent"));+const redent_1 = __importDefault(require("redent"));+const strip_indent_1 = __importDefault(require("strip-indent"));+exports.backtickInputRegex = /^```([a-z]+)?[\s\n]$/;+exports.tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;+const ZERO_WIDTH_SPACE = "\u200b";+const NEWLINE = "\n";+exports.CodeBlock = core_2.Node.create({+ name: "codeblock",+ addOptions() {+ return {+ languageClassPrefix: "language-",+ exitOnTripleEnter: true,+ exitOnArrowDown: true,+ exitOnArrowUp: true,+ HTMLAttributes: {},+ };+ },+ content: "text*",+ marks: "",+ group: "block",+ code: true,+ defining: true,+ addAttributes() {+ return {+ caretPosition: {+ default: undefined,+ rendered: false,+ },+ lines: {+ default: [],+ rendered: false,+ },+ indentType: {+ default: "space",+ parseHTML: (element) => {+ const indentType = element.dataset.indentType;+ return indentType;+ },+ renderHTML: (attributes) => {+ if (!attributes.indentType) {+ return {};+ }+ return {+ "data-indent-type": attributes.indentType,+ };+ },+ },+ indentLength: {+ default: 2,+ parseHTML: (element) => {+ const indentLength = element.dataset.indentLength;+ return indentLength;+ },+ renderHTML: (attributes) => {+ if (!attributes.indentLength) {+ return {};+ }+ return {+ "data-indent-length": attributes.indentLength,+ };+ },+ },+ language: {+ default: null,+ parseHTML: (element) => {+ var _a;+ const { languageClassPrefix } = this.options;+ const classNames = [+ ...(element.classList || []),+ ...(((_a = element === null || element === void 0 ? void 0 : element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || []),+ ];+ const languages = classNames+ .filter((className) => className.startsWith(languageClassPrefix))+ .map((className) => className.replace(languageClassPrefix, ""));+ const language = languages[0];+ if (!language) {+ return null;+ }+ return language;+ },+ renderHTML: (attributes) => {+ if (!attributes.language) {+ return {};+ }+ return {+ class: `language-${attributes.language}`,+ };+ },+ },+ };+ },+ parseHTML() {+ return [+ {+ tag: "pre",+ preserveWhitespace: "full",+ // contentElement: (node) => {+ // if (node instanceof HTMLElement) {+ // node.innerText = node.innerText.replaceAll("\n\u200b\n", "\n\n");+ // }+ // return node;+ // },+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "pre",+ (0, core_2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),+ ["code", {}, 0],+ ];+ },+ addCommands() {+ return {+ setCodeBlock: (attributes) => ({ commands }) => {+ return commands.setNode(this.name, attributes);+ },+ toggleCodeBlock: (attributes) => ({ commands }) => {+ console.log("TOGGLING!");+ return commands.toggleNode(this.name, "paragraph", attributes);+ },+ changeCodeBlockIndentation: (options) => ({ editor, tr, commands }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from } = selection;+ if ($from.parent.type !== this.type) {+ return false;+ }+ const { lines } = $from.parent.attrs;+ for (const line of lines) {+ const text = line.text();+ const whitespaceLength = text.length - text.trimStart().length;+ if (!whitespaceLength)+ continue;+ const indentLength = whitespaceLength;+ const indentToken = indent({+ type: options.type,+ amount: indentLength,+ });+ tr.insertText(indentToken, tr.mapping.map(line.from), tr.mapping.map(line.from + whitespaceLength));+ }+ commands.updateAttributes(this.type, {+ indentType: options.type,+ indentLength: options.amount,+ });+ return true;+ },+ };+ },+ addKeyboardShortcuts() {+ return {+ "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),+ "Mod-a": ({ editor }) => {+ const { $anchor } = this.editor.state.selection;+ if ($anchor.parent.type.name !== this.name) {+ return false;+ }+ const codeblock = (0, core_1.findParentNodeClosestToPos)($anchor, (node) => node.type.name === this.type.name);+ if (!codeblock)+ return false;+ return editor.commands.setTextSelection({+ from: codeblock.pos,+ to: codeblock.pos + codeblock.node.nodeSize,+ });+ },+ // remove code block when at start of document or code block is empty+ Backspace: () => {+ const { empty, $anchor } = this.editor.state.selection;+ const isAtStart = $anchor.pos === 1;+ if (!empty || $anchor.parent.type.name !== this.name) {+ return false;+ }+ if (isAtStart || !$anchor.parent.textContent.length) {+ return this.editor.commands.deleteNode(this.type);+ }+ return false;+ },+ // exit node on triple enter+ Enter: ({ editor }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from, empty } = selection;+ if (!empty || $from.parent.type !== this.type) {+ return false;+ }+ const indentation = parseIndentation($from.parent);+ return ((this.options.exitOnTripleEnter &&+ exitOnTripleEnter(editor, $from)) ||+ indentOnEnter(editor, $from, indentation));+ },+ // exit node on arrow up+ ArrowUp: ({ editor }) => {+ if (!this.options.exitOnArrowUp) {+ return false;+ }+ const { state } = editor;+ const { selection } = state;+ const { $anchor, empty } = selection;+ if (!empty || $anchor.parent.type !== this.type) {+ return false;+ }+ const isAtStart = $anchor.pos === 1;+ if (!isAtStart) {+ return false;+ }+ return editor.commands.insertContentAt(0, "<p></p>");+ },+ // exit node on arrow down+ ArrowDown: ({ editor }) => {+ if (!this.options.exitOnArrowDown) {+ return false;+ }+ const { state } = editor;+ const { selection, doc } = state;+ const { $from, empty } = selection;+ if (!empty || $from.parent.type !== this.type) {+ return false;+ }+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;+ if (!isAtEnd) {+ return false;+ }+ const after = $from.after();+ if (after === undefined) {+ return false;+ }+ const nodeAfter = doc.nodeAt(after);+ if (nodeAfter) {+ editor.commands.setNodeSelection($from.before());+ return false;+ }+ return editor.commands.exitCode();+ },+ "Shift-Tab": ({ editor }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from } = selection;+ if ($from.parent.type !== this.type) {+ return false;+ }+ const indentation = parseIndentation($from.parent);+ const indentToken = indent(indentation);+ const { lines } = $from.parent.attrs;+ const selectedLines = getSelectedLines(lines, selection);+ return editor+ .chain()+ .command(({ tr }) => withSelection(tr, (tr) => {+ for (const line of selectedLines) {+ if (line.text(indentToken.length) !== indentToken)+ continue;+ tr.delete(tr.mapping.map(line.from), tr.mapping.map(line.from + indentation.amount));+ }+ }))+ .run();+ },+ Tab: ({ editor }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from } = selection;+ if ($from.parent.type !== this.type) {+ return false;+ }+ const { lines } = $from.parent.attrs;+ const selectedLines = getSelectedLines(lines, selection);+ return editor+ .chain()+ .command(({ tr }) => withSelection(tr, (tr) => {+ const indentToken = indent(parseIndentation($from.parent));+ if (selectedLines.length === 1)+ return tr.insertText(indentToken, $from.pos);+ for (const line of selectedLines) {+ tr.insertText(indentToken, tr.mapping.map(line.from));+ }+ }))+ .run();+ },+ };+ },+ addInputRules() {+ return [+ (0, core_2.textblockTypeInputRule)({+ find: exports.backtickInputRegex,+ type: this.type,+ getAttributes: (match) => ({+ language: match[1],+ }),+ }),+ (0, core_2.textblockTypeInputRule)({+ find: exports.tildeInputRegex,+ type: this.type,+ getAttributes: (match) => ({+ language: match[1],+ }),+ }),+ ];+ },+ addProseMirrorPlugins() {+ return [+ // this plugin creates a code block for pasted content from VS Code+ // we can also detect the copied code language+ new prosemirror_state_1.Plugin({+ key: new prosemirror_state_1.PluginKey("codeBlockVSCodeHandler"),+ props: {+ handlePaste: (view, event) => {+ if (!event.clipboardData) {+ return false;+ }+ const text = event.clipboardData.getData("text/plain");+ const vscode = event.clipboardData.getData("vscode-editor-data");+ const vscodeData = vscode ? JSON.parse(vscode) : undefined;+ const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;+ if (!text || !language) {+ return false;+ }+ const indent = fixIndentation(text, parseIndentation(view.state.selection.$from.parent));+ const { tr } = view.state;+ // create an empty code block if not already within one+ if (!this.editor.isActive(this.type.name)) {+ tr.replaceSelectionWith(this.type.create({+ language,+ indentType: indent.type,+ indentLength: indent.amount,+ }));+ }+ // // put cursor inside the newly created code block+ // tr.setSelection(+ // TextSelection.near(+ // tr.doc.resolve(Math.max(0, tr.selection.from - 2))+ // )+ // );+ // add text to code block+ // strip carriage return chars from text pasted as code+ // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd+ tr.insertText(indent.code.replace(/\r\n?/g, "\n"));+ // store meta information+ // this is useful for other plugins that depends on the paste event+ // like the paste rule plugin+ tr.setMeta("paste", true);+ view.dispatch(tr);+ return true;+ },+ },+ }),+ (0, highlighter_1.HighlighterPlugin)({ name: this.name, defaultLanguage: "txt" }),+ ];+ },+ addNodeView() {+ return (0, react_1.createNodeView)(component_1.CodeblockComponent, {+ contentDOMFactory: () => {+ const content = document.createElement("div");+ content.classList.add("node-content-wrapper");+ content.style.whiteSpace = "inherit";+ // caret is not visible if content element width is 0px+ content.style.minWidth = `20px`;+ return { dom: content };+ },+ shouldUpdate: ({ attrs: prev }, { attrs: next }) => {+ return (compareCaretPosition(prev.caretPosition, next.caretPosition) ||+ prev.language !== next.language ||+ prev.indentType !== next.indentType);+ },+ });+ },+});+function toCaretPosition(selection, lines) {+ const { $from, $to, $head } = selection;+ if ($from.parent.type.name !== exports.CodeBlock.name)+ return;+ lines = lines || getLines($from.parent);+ for (const line of lines) {+ if ($head.pos >= line.from && $head.pos <= line.to) {+ const lineLength = line.length + 1;+ return {+ line: line.index + 1,+ column: lineLength - (line.to - $head.pos),+ selected: $to.pos - $from.pos,+ total: lines.length,+ from: line.from,+ };+ }+ }+ return;+}+exports.toCaretPosition = toCaretPosition;+function getLines(node) {+ const { lines } = node.attrs;+ return lines || [];+}+exports.getLines = getLines;+function exitOnTripleEnter(editor, $from) {+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;+ const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");+ if (!isAtEnd || !endsWithDoubleNewline) {+ return false;+ }+ return editor+ .chain()+ .command(({ tr }) => {+ tr.delete($from.pos - 2, $from.pos);+ return true;+ })+ .exitCode()+ .run();+}+function indentOnEnter(editor, $from, options) {+ const { indentation, newline } = getNewline($from, options) || {};+ if (!newline)+ return false;+ return editor+ .chain()+ .insertContent(`${newline}${indentation}`, {+ parseOptions: { preserveWhitespace: "full" },+ })+ .focus()+ .run();+}+function getNewline($from, options) {+ const { lines } = $from.parent.attrs;+ const currentLine = getLineAt(lines, $from.pos);+ if (!currentLine)+ return false;+ const text = currentLine.text();+ const indentLength = text.length - text.trimStart().length;+ return {+ newline: NEWLINE,+ indentation: indent({ amount: indentLength, type: options.type }),+ };+}+function toCodeLines(code, pos) {+ const positions = [];+ let start = 0;+ let from = pos + 1;+ let index = 0;+ while (start <= code.length) {+ let end = code.indexOf("\n", start);+ if (end <= -1)+ end = code.length;+ const lineLength = end - start;+ const to = from + lineLength;+ const lineStart = start;+ positions.push({+ index,+ length: lineLength,+ from,+ to,+ text: (length) => {+ return code.slice(lineStart, length ? lineStart + length : lineStart + lineLength);+ },+ });+ from = to + 1;+ start = end + 1;+ ++index;+ }+ return positions;+}+exports.toCodeLines = toCodeLines;+function getSelectedLines(lines, selection) {+ const { $from, $to } = selection;+ return lines.filter((line) => inRange(line.from, $from.pos, $to.pos) ||+ inRange(line.to, $from.pos, $to.pos) ||+ inRange($from.pos, line.from, line.to));+}+function parseIndentation(node) {+ if (node.type.name !== exports.CodeBlock.name)+ return undefined;+ const { indentType, indentLength } = node.attrs;+ return {+ type: indentType,+ amount: parseInt(indentLength),+ };+}+function getLineAt(lines, pos) {+ return lines.find((line) => pos >= line.from && pos <= line.to);+}+function inRange(x, a, b) {+ return x >= a && x <= b;+}+function indent(options) {+ const char = options.type === "space" ? " " : "\t";+ return char.repeat(options.amount);+}+function compareCaretPosition(prev, next) {+ return (next === undefined ||+ (prev === null || prev === void 0 ? void 0 : prev.column) !== (next === null || next === void 0 ? void 0 : next.column) ||+ (prev === null || prev === void 0 ? void 0 : prev.line) !== (next === null || next === void 0 ? void 0 : next.line));+}+/**+ * Persist selection between transaction steps+ */+function withSelection(tr, callback) {+ const { $anchor, $head } = tr.selection;+ callback(tr);+ tr.setSelection(new prosemirror_state_1.TextSelection(tr.doc.resolve(tr.mapping.map($anchor.pos)), tr.doc.resolve(tr.mapping.map($head.pos))));+ return true;+}+function fixIndentation(code, indent) {+ const { amount, type = "space" } = indent || (0, detect_indent_1.default)(code);+ const fixed = (0, redent_1.default)(code, amount, {+ includeEmptyLines: false,+ indent: type === "space" ? " " : "\t",+ });+ return { code: (0, strip_indent_1.default)(fixed), amount, type };+}diff --git a/packages/editor/dist/extensions/codeblock/component.d.ts b/packages/editor/dist/cjs/extensions/codeblock/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codeblock/component.d.tsrename to packages/editor/dist/cjs/extensions/codeblock/component.d.tsdiff --git a/packages/editor/dist/cjs/extensions/codeblock/component.js b/packages/editor/dist/cjs/extensions/codeblock/component.jsnew file mode 100644index 000000000..bf3fc12bb--- /dev/null+++ b/packages/editor/dist/cjs/extensions/codeblock/component.js@@ -0,0 +1,149 @@+"use strict";+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.CodeblockComponent = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const loader_1 = require("./loader");+const core_1 = require("refractor/lib/core");+const rebass_1 = require("rebass");+const languages_json_1 = __importDefault(require("./languages.json"));+const forms_1 = require("@rebass/forms");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const responsive_1 = require("../../components/responsive");+const popup_1 = require("../../toolbar/components/popup");+const button_1 = require("../../components/button");+function CodeblockComponent(props) {+ const { editor, updateAttributes, node, forwardRef } = props;+ const { language, indentLength, indentType, caretPosition } = node === null || node === void 0 ? void 0 : node.attrs;+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ // const [caretPosition, setCaretPosition] = useState<CaretPosition>();+ const toolbarRef = (0, react_1.useRef)(null);+ const languageDefinition = languages_json_1.default.find((l) => { var _a; return l.filename === language || ((_a = l.alias) === null || _a === void 0 ? void 0 : _a.some((a) => a === language)); });+ (0, react_1.useEffect)(() => {+ (function () {+ return __awaiter(this, void 0, void 0, function* () {+ if (!language || !languageDefinition || (0, loader_1.isLanguageLoaded)(language))+ return;+ const syntax = yield (0, loader_1.loadLanguage)(languageDefinition.filename);+ if (!syntax)+ return;+ core_1.refractor.register(syntax);+ updateAttributes({+ language: languageDefinition.filename,+ });+ });+ })();+ }, [language]);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ flexDirection: "column",+ borderRadius: "default",+ overflow: "hidden",+ } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, { ref: forwardRef, as: "pre", sx: {+ "div, span.token, span.line-number-widget, span.line-number::before": {+ fontFamily: "monospace",+ fontSize: "code",+ whiteSpace: "pre !important",+ tabSize: 1,+ },+ position: "relative",+ lineHeight: "20px",+ bg: "codeBg",+ color: "static",+ overflowX: "auto",+ display: "flex",+ px: 2,+ pt: 2,+ pb: 1,+ }, spellCheck: false }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ ref: toolbarRef, contentEditable: false, sx: {+ bg: "codeBg",+ alignItems: "center",+ justifyContent: "end",+ borderTop: "1px solid var(--codeBorder)",+ } }, { children: [caretPosition ? ((0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "subBody", sx: { mr: 2, color: "codeFg" } }, { children: ["Line ", caretPosition.line, ", Column ", caretPosition.column, " ", caretPosition.selected+ ? `(${caretPosition.selected} selected)`+ : ""] }))) : null, (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ variant: "icon", sx: { p: 1, mr: 1, ":hover": { bg: "codeSelection" } }, title: "Toggle indentation mode", onClick: () => {+ editor.commands.changeCodeBlockIndentation({+ type: indentType === "space" ? "tab" : "space",+ amount: indentLength,+ });+ } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "subBody", sx: { color: "codeFg" } }, { children: [indentType === "space" ? "Spaces" : "Tabs", ": ", indentLength] })) })), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ variant: "icon", sx: {+ p: 1,+ mr: 1,+ bg: isOpen ? "codeSelection" : "transparent",+ ":hover": { bg: "codeSelection" },+ }, onClick: () => {+ setIsOpen(true);+ }, title: "Change language" }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "subBody", spellCheck: false, sx: { color: "codeFg" } }, { children: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.title) || "Plaintext" })) }))] }))] })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, Object.assign({ isOpen: isOpen, onClose: () => {+ setIsOpen(false);+ // NOTE: for some reason the language selection action sheet+ // does not return focus to the last focused position after+ // closing. We have to set focusOnRender=false & manually+ // restore focus. I think this has something to do with custom+ // node views.+ // TRY: perhaps use SelectionBasedReactNodeView?+ editor.commands.focus();+ }, focusOnRender: false, mobile: "sheet", desktop: "menu", position: {+ target: toolbarRef.current || undefined,+ align: "end",+ isTargetAbsolute: true,+ location: "top",+ yOffset: 5,+ }, title: "Change code block language" }, { children: (0, jsx_runtime_1.jsx)(LanguageSelector, { selectedLanguage: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.filename) || "Plaintext", onLanguageSelected: (language) => {+ updateAttributes({ language });+ setIsOpen(false);+ }, onClose: () => setIsOpen(false) }) }))] }));+}+exports.CodeblockComponent = CodeblockComponent;+function LanguageSelector(props) {+ const { onLanguageSelected, selectedLanguage, onClose } = props;+ const [languages, setLanguages] = (0, react_1.useState)(languages_json_1.default);+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ title: "Select language", onClose: onClose }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ flexDirection: "column",+ height: 200,+ width: ["auto", 300],+ overflowY: "auto",+ bg: "background",+ } }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { onFocus: () => {+ console.log("EHLLO!");+ }, autoFocus: true, placeholder: "Search languages", sx: {+ width: "auto",+ position: "sticky",+ top: 0,+ bg: "background",+ mx: 2,+ p: "7px",+ zIndex: 999,+ }, onChange: (e) => {+ if (!e.target.value)+ return setLanguages(languages_json_1.default);+ const query = e.target.value.toLowerCase();+ setLanguages(languages_json_1.default.filter((lang) => {+ var _a;+ return (lang.title.toLowerCase().indexOf(query) > -1 ||+ ((_a = lang.alias) === null || _a === void 0 ? void 0 : _a.some((alias) => alias.toLowerCase().indexOf(query) > -1)));+ }));+ } }), (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {+ flexDirection: "column",+ pt: 1,+ mt: 1,+ } }, { children: languages.map((lang) => ((0, jsx_runtime_1.jsxs)(button_1.Button, Object.assign({ variant: "menuitem", sx: {+ textAlign: "left",+ py: 1,+ display: "flex",+ justifyContent: "space-between",+ alignItems: "center",+ }, onClick: () => onLanguageSelected(lang.filename) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "body" }, { children: lang.title })), selectedLanguage === lang.filename ? ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.check, size: "small" })) : lang.alias ? ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "subBody", sx: { fontSize: "10px" } }, { children: lang.alias.slice(0, 3).join(", ") }))) : null] }), lang.title))) }))] })) })));+}diff --git a/packages/editor/dist/extensions/codeblock/highlighter.d.ts b/packages/editor/dist/cjs/extensions/codeblock/highlighter.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codeblock/highlighter.d.tsrename to packages/editor/dist/cjs/extensions/codeblock/highlighter.d.tsdiff --git a/packages/editor/dist/cjs/extensions/codeblock/highlighter.js b/packages/editor/dist/cjs/extensions/codeblock/highlighter.jsnew file mode 100644index 000000000..bcaeb260d--- /dev/null+++ b/packages/editor/dist/cjs/extensions/codeblock/highlighter.js@@ -0,0 +1,211 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.HighlighterPlugin = void 0;+const prosemirror_state_1 = require("prosemirror-state");+const prosemirror_view_1 = require("prosemirror-view");+const core_1 = require("@tiptap/core");+const core_2 = require("refractor/lib/core");+const codeblock_1 = require("./codeblock");+function parseNodes(nodes, className = []) {+ return nodes.reduce((result, node) => {+ if (node.type === "comment" || node.type === "doctype")+ return result;+ const classes = [...className];+ if (node.type === "element" && node.properties)+ classes.push(...node.properties.className);+ // this is required so that even plain text is wrapped in a span+ // during highlighting. Without this, Prosemirror's selection acts+ // weird for the first highlighted node/span.+ else+ classes.push("token", "text");+ if (node.type === "element") {+ result.push(...parseNodes(node.children, classes));+ }+ else {+ result.push({ classes, text: node.value });+ }+ return result;+ }, []);+}+function getHighlightNodes(result) {+ return result.children || [];+}+function getLineDecoration(from, line, total, isActive) {+ const maxLength = String(total).length;+ const attributes = {+ class: `line-number ${isActive ? "active" : ""}`,+ "data-line": String(line).padEnd(maxLength, " "),+ };+ const spec = {+ line: line,+ active: isActive,+ total,+ from,+ };+ // Prosemirror has a selection issue with the widget decoration+ // on the first line. To work around that we use inline decoration+ // for the first line.+ if (line === 1 ||+ // Android Composition API (aka the virtual keyboard) doesn't behave well+ // with Decoration widgets so we have to resort to inline line numbers.+ isAndroid()) {+ return prosemirror_view_1.Decoration.inline(from, from + 1, attributes, spec);+ }+ return prosemirror_view_1.Decoration.widget(from, () => {+ const element = document.createElement("span");+ element.classList.add("line-number-widget");+ if (isActive)+ element.classList.add("active");+ element.innerHTML = attributes["data-line"];+ return element;+ }, Object.assign(Object.assign({}, spec), {+ // should rerender when any of these change:+ // 1. line number+ // 2. line active state+ // 3. the max length of all lines+ key: `${line}-${isActive ? "active" : ""}-${maxLength}` }));+}+function getDecorations({ doc, name, defaultLanguage, caretPosition, }) {+ const decorations = [];+ const languages = core_2.refractor.listLanguages();+ (0, core_1.findChildren)(doc, (node) => node.type.name === name).forEach((block) => {+ const code = block.node.textContent;+ const lines = (0, codeblock_1.toCodeLines)(code, block.pos);+ for (const line of lines || []) {+ const lineNumber = line.index + 1;+ const isActive = lineNumber === (caretPosition === null || caretPosition === void 0 ? void 0 : caretPosition.line) && line.from === (caretPosition === null || caretPosition === void 0 ? void 0 : caretPosition.from);+ const decoration = getLineDecoration(line.from, lineNumber, (lines === null || lines === void 0 ? void 0 : lines.length) || 0, isActive);+ decorations.push(decoration);+ }+ const language = block.node.attrs.language || defaultLanguage;+ const nodes = languages.includes(language)+ ? getHighlightNodes(core_2.refractor.highlight(code, language))+ : null;+ if (!nodes)+ return;+ let from = block.pos + 1;+ parseNodes(nodes).forEach((node) => {+ const to = from + node.text.length;+ if (node.classes.length) {+ const decoration = prosemirror_view_1.Decoration.inline(from, to, {+ class: node.classes.join(" "),+ });+ decorations.push(decoration);+ }+ from = to;+ });+ });+ return prosemirror_view_1.DecorationSet.create(doc, decorations);+}+function HighlighterPlugin({ name, defaultLanguage, }) {+ const key = new prosemirror_state_1.PluginKey("highlighter");+ return new prosemirror_state_1.Plugin({+ key,+ state: {+ init: () => {+ return prosemirror_view_1.DecorationSet.empty;+ },+ apply: (transaction, decorationSet, oldState, newState) => {+ const oldNodeName = oldState.selection.$head.parent.type.name;+ const newNodeName = newState.selection.$head.parent.type.name;+ const oldNodes = (0, core_1.findChildren)(oldState.doc, (node) => node.type.name === name);+ const newNodes = (0, core_1.findChildren)(newState.doc, (node) => node.type.name === name);+ const position = (0, codeblock_1.toCaretPosition)(newState.selection);+ // const isDocChanged =+ // transaction.docChanged &&+ // // TODO+ // !transaction.steps.every((step) => step instanceof ReplaceAroundStep);+ // console.log("Selection", transaction.docChanged, isDocChanged);+ if (transaction.docChanged &&+ // Apply decorations if:+ // selection includes named node,+ ([oldNodeName, newNodeName].includes(name) ||+ // OR transaction adds/removes named node,+ newNodes.length !== oldNodes.length ||+ // OR transaction has changes that completely encapsulte a node+ // (for example, a transaction that affects the entire document).+ // Such transactions can happen during collab syncing via y-prosemirror, for example.+ transaction.steps.some((step) => {+ return (step.from !== undefined &&+ step.to !== undefined &&+ oldNodes.some((node) => {+ return (node.pos >= step.from &&+ node.pos + node.node.nodeSize <= step.to);+ }));+ }))) {+ return getDecorations({+ doc: transaction.doc,+ name,+ defaultLanguage,+ caretPosition: position,+ });+ }+ decorationSet = getActiveLineDecorations(transaction.doc, decorationSet, position);+ return decorationSet.map(transaction.mapping, transaction.doc);+ },+ },+ props: {+ decorations(state) {+ return key.getState(state);+ },+ },+ appendTransaction: (transactions, prevState, nextState) => {+ const tr = nextState.tr;+ let modified = false;+ const docChanged = transactions.some((transaction) => transaction.docChanged);+ const selectionChanged = (nextState.selection.$from.parent.type.name === name ||+ prevState.selection.$from.parent.type.name === name) &&+ prevState.selection.$from.pos !== nextState.selection.$from.pos;+ (0, core_1.findChildren)(nextState.doc, (node) => node.type.name === name).forEach((block) => {+ const { node, pos } = block;+ const attributes = Object.assign({}, node.attrs);+ if (docChanged) {+ const lines = (0, codeblock_1.toCodeLines)(node.textContent, pos);+ attributes.lines = lines.slice();+ }+ if (selectionChanged) {+ const position = (0, codeblock_1.toCaretPosition)(nextState.selection, docChanged ? (0, codeblock_1.toCodeLines)(node.textContent, pos) : undefined);+ attributes.caretPosition = position;+ }+ if (docChanged || selectionChanged) {+ tr.setNodeMarkup(pos, node.type, attributes);+ modified = true;+ }+ });+ return modified ? tr : null;+ },+ });+}+exports.HighlighterPlugin = HighlighterPlugin;+/**+ * When `position` is undefined, all active line decorations+ * are reset (e.g. when you focus out of the code block).+ */+function getActiveLineDecorations(doc, decorations, position) {+ const lineDecorations = decorations.find(undefined, undefined, ({ line, active, from }) => {+ const isSame = position+ ? line === position.line && from === position.from+ : false;+ return isSame || active;+ });+ if (!lineDecorations.length)+ return decorations;+ // we have to clone because prosemirror operates in-place+ const cloned = lineDecorations.slice();+ // remove old line decorations which inclue the current line decoration+ // and the previous current line decoration. We'll replace these with+ // new decorations.+ decorations = decorations.remove(lineDecorations);+ const newDecorations = [];+ for (const decoration of cloned) {+ const { from, spec: { line, total }, } = decoration;+ const isActive = line === (position === null || position === void 0 ? void 0 : position.line);+ const newDecoration = getLineDecoration(from, line, (position === null || position === void 0 ? void 0 : position.total) || total, isActive);+ newDecorations.push(newDecoration);+ }+ return decorations.add(doc, newDecorations);+}+function isAndroid() {+ var ua = navigator.userAgent.toLowerCase();+ return ua.indexOf("android") > -1; //&& ua.indexOf("mobile");+}diff --git a/packages/editor/dist/extensions/codeblock/index.d.ts b/packages/editor/dist/cjs/extensions/codeblock/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codeblock/index.d.tsrename to packages/editor/dist/cjs/extensions/codeblock/index.d.tsdiff --git a/packages/editor/dist/extensions/codeblock/index.js b/packages/editor/dist/cjs/extensions/codeblock/index.jssimilarity index 100%rename from packages/editor/dist/extensions/codeblock/index.jsrename to packages/editor/dist/cjs/extensions/codeblock/index.jsdiff --git a/packages/editor/dist/extensions/codeblock/languages.json b/packages/editor/dist/cjs/extensions/codeblock/languages.jsonsimilarity index 100%rename from packages/editor/dist/extensions/codeblock/languages.jsonrename to packages/editor/dist/cjs/extensions/codeblock/languages.jsondiff --git a/packages/editor/dist/extensions/codeblock/loader.d.ts b/packages/editor/dist/cjs/extensions/codeblock/loader.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codeblock/loader.d.tsrename to packages/editor/dist/cjs/extensions/codeblock/loader.d.tsdiff --git a/packages/editor/dist/cjs/extensions/codeblock/loader.js b/packages/editor/dist/cjs/extensions/codeblock/loader.jsnew file mode 100644index 000000000..d889fa1e7--- /dev/null+++ b/packages/editor/dist/cjs/extensions/codeblock/loader.js@@ -0,0 +1,50 @@+"use strict";+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.loadLanguage = exports.isLanguageLoaded = void 0;+const loadedLanguages = {};+function isLanguageLoaded(name) {+ return !!loadedLanguages[name];+}+exports.isLanguageLoaded = isLanguageLoaded;+function loadLanguage(shortName) {+ return __awaiter(this, void 0, void 0, function* () {+ if (loadedLanguages[shortName])+ return loadedLanguages[shortName];+ const url = `https://esm.sh/[email protected]/lang/${shortName}.js?bundle=true`;+ const result = yield loadScript(shortName, url);+ loadedLanguages[shortName] = result;+ return result;+ });+}+exports.loadLanguage = loadLanguage;+function loadScript(id, url) {+ return __awaiter(this, void 0, void 0, function* () {+ return new Promise((resolve, reject) => {+ const callbackName = `on${id}Loaded`;+ const script = document.createElement("script");+ script.type = "module";+ script.innerHTML = `+ import LanguageDefinition from "${url}";+ if (window["${callbackName}"]) {+ window["${callbackName}"](LanguageDefinition)+ }+`;+ window[callbackName] = (lang) => {+ script.remove();+ window[callbackName] = null;+ resolve(lang);+ };+ // Append to the `head` element+ document.head.appendChild(script);+ });+ });+}diff --git a/packages/editor/dist/extensions/codemark/codemark.d.ts b/packages/editor/dist/cjs/extensions/codemark/codemark.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codemark/codemark.d.tsrename to packages/editor/dist/cjs/extensions/codemark/codemark.d.tsdiff --git a/packages/editor/dist/extensions/codemark/codemark.js b/packages/editor/dist/cjs/extensions/codemark/codemark.jssimilarity index 72%rename from packages/editor/dist/extensions/codemark/codemark.jsrename to packages/editor/dist/cjs/extensions/codemark/codemark.jsindex 5fe411ca0..d4cc94490 100644--- a/packages/editor/dist/extensions/codemark/codemark.js+++ b/packages/editor/dist/cjs/extensions/codemark/codemark.js@@ -4,11 +4,11 @@ var __importDefault = (this && this.__importDefault) || function (mod) {};Object.defineProperty(exports, "__esModule", { value: true });exports.Codemark = void 0;-var core_1 = require("@tiptap/core");-var prosemirror_codemark_1 = __importDefault(require("prosemirror-codemark"));+const core_1 = require("@tiptap/core");+const prosemirror_codemark_1 = __importDefault(require("prosemirror-codemark"));exports.Codemark = core_1.Extension.create({name: "codemarkPlugin",- addProseMirrorPlugins: function () {+ addProseMirrorPlugins() {return (0, prosemirror_codemark_1.default)({ markType: this.editor.schema.marks.code });},});diff --git a/packages/editor/dist/extensions/codemark/index.d.ts b/packages/editor/dist/cjs/extensions/codemark/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/codemark/index.d.tsrename to packages/editor/dist/cjs/extensions/codemark/index.d.tsdiff --git a/packages/editor/dist/extensions/codemark/index.js b/packages/editor/dist/cjs/extensions/codemark/index.jssimilarity index 100%rename from packages/editor/dist/extensions/codemark/index.jsrename to packages/editor/dist/cjs/extensions/codemark/index.jsdiff --git a/packages/editor/dist/extensions/dropcursor/dropcursor.d.ts b/packages/editor/dist/cjs/extensions/dropcursor/dropcursor.d.tssimilarity index 100%rename from packages/editor/dist/extensions/dropcursor/dropcursor.d.tsrename to packages/editor/dist/cjs/extensions/dropcursor/dropcursor.d.tsdiff --git a/packages/editor/dist/extensions/dropcursor/dropcursor.js b/packages/editor/dist/cjs/extensions/dropcursor/dropcursor.jssimilarity index 69%rename from packages/editor/dist/extensions/dropcursor/dropcursor.jsrename to packages/editor/dist/cjs/extensions/dropcursor/dropcursor.jsindex f983df8f9..a35f092a1 100644--- a/packages/editor/dist/extensions/dropcursor/dropcursor.js+++ b/packages/editor/dist/cjs/extensions/dropcursor/dropcursor.js@@ -1,18 +1,18 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.Dropcursor = void 0;-var core_1 = require("@tiptap/core");-var dropcursor_pm_1 = require("./dropcursor.pm");+const core_1 = require("@tiptap/core");+const dropcursor_pm_1 = require("./dropcursor.pm");exports.Dropcursor = core_1.Extension.create({name: "dropCursor",- addOptions: function () {+ addOptions() {return {color: "currentColor",width: 1,class: null,};},- addProseMirrorPlugins: function () {+ addProseMirrorPlugins() {return [(0, dropcursor_pm_1.dropCursor)(this.options)];},});diff --git a/packages/editor/dist/extensions/dropcursor/dropcursor.pm.d.ts b/packages/editor/dist/cjs/extensions/dropcursor/dropcursor.pm.d.tssimilarity index 100%rename from packages/editor/dist/extensions/dropcursor/dropcursor.pm.d.tsrename to packages/editor/dist/cjs/extensions/dropcursor/dropcursor.pm.d.tsdiff --git a/packages/editor/dist/extensions/dropcursor/dropcursor.pm.js b/packages/editor/dist/cjs/extensions/dropcursor/dropcursor.pm.jssimilarity index 61%rename from packages/editor/dist/extensions/dropcursor/dropcursor.pm.jsrename to packages/editor/dist/cjs/extensions/dropcursor/dropcursor.pm.jsindex f618634c4..fe07d9ded 100644--- a/packages/editor/dist/extensions/dropcursor/dropcursor.pm.js+++ b/packages/editor/dist/cjs/extensions/dropcursor/dropcursor.pm.js@@ -1,8 +1,8 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.dropCursor = void 0;-var prosemirror_state_1 = require("prosemirror-state");-var prosemirror_transform_1 = require("prosemirror-transform");+const prosemirror_state_1 = require("prosemirror-state");+const prosemirror_transform_1 = require("prosemirror-transform");// :: (options: ?Object) → Plugin// Create a plugin that, when added to a ProseMirror instance,// causes a decoration to show up at the drop position when something@@ -23,18 +23,16 @@ var prosemirror_transform_1 = require("prosemirror-transform");//// class:: ?string// A CSS class name to add to the cursor element.-function dropCursor(options) {- if (options === void 0) { options = {}; }+function dropCursor(options = {}) {return new prosemirror_state_1.Plugin({- view: function (editorView) {+ view(editorView) {return new DropCursorView(editorView, options);},});}exports.dropCursor = dropCursor;-var DropCursorView = /** @class */ (function () {- function DropCursorView(editorView, options) {- var _this = this;+class DropCursorView {+ constructor(editorView, options) {this.editorView = editorView;this.width = options.width || 1;this.color = options.color || "black";@@ -42,28 +40,24 @@ var DropCursorView = /** @class */ (function () {this.cursorPos = null;this.element = null;this.timeout = null;- this.handlers = ["dragover", "dragend", "drop", "dragleave"].map(function (name) {- var handler = function (e) { return _this[name](e); };+ this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((name) => {+ let handler = (e) => this[name](e);editorView.dom.addEventListener(name, handler);- return { name: name, handler: handler };+ return { name, handler };});}- DropCursorView.prototype.destroy = function () {- var _this = this;- this.handlers.forEach(function (_a) {- var name = _a.name, handler = _a.handler;- return _this.editorView.dom.removeEventListener(name, handler);- });- };- DropCursorView.prototype.update = function (editorView, prevState) {+ destroy() {+ this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));+ }+ update(editorView, prevState) {if (this.cursorPos != null && prevState.doc != editorView.state.doc) {if (this.cursorPos > editorView.state.doc.content.size)this.setCursor(null);elsethis.updateOverlay();}- };- DropCursorView.prototype.setCursor = function (pos) {+ }+ setCursor(pos) {if (pos == this.cursorPos)return;this.cursorPos = pos;@@ -74,35 +68,35 @@ var DropCursorView = /** @class */ (function () {else {this.updateOverlay();}- };- DropCursorView.prototype.updateOverlay = function () {+ }+ updateOverlay() {if (!this.cursorPos)return;- var $pos = this.editorView.state.doc.resolve(this.cursorPos), rect;+ let $pos = this.editorView.state.doc.resolve(this.cursorPos), rect;if (!$pos.parent.inlineContent) {- var before = $pos.nodeBefore, after = $pos.nodeAfter;+ let before = $pos.nodeBefore, after = $pos.nodeAfter;if (before || after) {- var node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));+ const node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));if (!node)return;- var nodeRect = node.getBoundingClientRect();- var top_1 = before ? nodeRect.bottom : nodeRect.top;+ let nodeRect = node.getBoundingClientRect();+ let top = before ? nodeRect.bottom : nodeRect.top;if (before && after) {- var cursor = this.editorView.nodeDOM(this.cursorPos);+ const cursor = this.editorView.nodeDOM(this.cursorPos);if (!cursor)return;- top_1 = (top_1 + cursor.getBoundingClientRect().top) / 2;+ top = (top + cursor.getBoundingClientRect().top) / 2;}rect = {left: nodeRect.left,right: nodeRect.right,- top: top_1 - this.width / 2,- bottom: top_1 + this.width / 2,+ top: top - this.width / 2,+ bottom: top + this.width / 2,};}}if (!rect) {- var coords = this.editorView.coordsAtPos(this.cursorPos);+ let coords = this.editorView.coordsAtPos(this.cursorPos);rect = {left: coords.left - this.width / 2,right: coords.left + this.width / 2,@@ -110,7 +104,7 @@ var DropCursorView = /** @class */ (function () {bottom: coords.bottom,};}- var parent = this.editorView.dom.offsetParent;+ let parent = this.editorView.dom.offsetParent;if (!this.element && parent) {this.element = parent.appendChild(document.createElement("div"));if (this.class)@@ -119,16 +113,16 @@ var DropCursorView = /** @class */ (function () {"position: absolute; z-index: 50; pointer-events: none; background-color: " +this.color;}- var parentLeft, parentTop;+ let parentLeft, parentTop;if (!parent ||(parent == document.body && getComputedStyle(parent).position == "static")) {parentLeft = -pageXOffset;parentTop = -pageYOffset;}else {- var rect_1 = parent.getBoundingClientRect();- parentLeft = rect_1.left - parent.scrollLeft;- parentTop = rect_1.top - parent.scrollTop;+ let rect = parent.getBoundingClientRect();+ parentLeft = rect.left - parent.scrollLeft;+ parentTop = rect.top - parent.scrollTop;}if (!this.element)return;@@ -136,28 +130,27 @@ var DropCursorView = /** @class */ (function () {this.element.style.top = rect.top - parentTop + "px";this.element.style.width = rect.right - rect.left + "px";this.element.style.height = rect.bottom - rect.top + "px";- };- DropCursorView.prototype.scheduleRemoval = function (timeout) {- var _this = this;+ }+ scheduleRemoval(timeout) {clearTimeout(this.timeout || undefined);- this.timeout = (setTimeout(function () { return _this.setCursor(null); }, timeout));- };- DropCursorView.prototype.dragover = function (event) {+ this.timeout = (setTimeout(() => this.setCursor(null), timeout));+ }+ dragover(event) {if (!this.editorView.editable)return;- var pos = this.editorView.posAtCoords({+ let pos = this.editorView.posAtCoords({left: event.clientX,top: event.clientY,});- var node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);- var disableDropCursor = node && node.type.spec.disableDropCursor;- var disabled = typeof disableDropCursor == "function"+ let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);+ let disableDropCursor = node && node.type.spec.disableDropCursor;+ let disabled = typeof disableDropCursor == "function"? disableDropCursor(this.editorView, pos): disableDropCursor;if (pos && !disabled) {- var target = pos.pos;+ let target = pos.pos;if (this.editorView.dragging && this.editorView.dragging.slice) {- var point = (0, prosemirror_transform_1.dropPoint)(this.editorView.state.doc, target, this.editorView.dragging.slice);+ const point = (0, prosemirror_transform_1.dropPoint)(this.editorView.state.doc, target, this.editorView.dragging.slice);if (!point)return this.setCursor(null);target = point;@@ -165,17 +158,16 @@ var DropCursorView = /** @class */ (function () {this.setCursor(target);this.scheduleRemoval(5000);}- };- DropCursorView.prototype.dragend = function () {+ }+ dragend() {this.scheduleRemoval(20);- };- DropCursorView.prototype.drop = function () {+ }+ drop() {this.scheduleRemoval(20);- };- DropCursorView.prototype.dragleave = function (event) {+ }+ dragleave(event) {if (event.target == this.editorView.dom ||!this.editorView.dom.contains(event.relatedTarget))this.setCursor(null);- };- return DropCursorView;-}());+ }+}diff --git a/packages/editor/dist/extensions/dropcursor/index.d.ts b/packages/editor/dist/cjs/extensions/dropcursor/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/dropcursor/index.d.tsrename to packages/editor/dist/cjs/extensions/dropcursor/index.d.tsdiff --git a/packages/editor/dist/extensions/dropcursor/index.js b/packages/editor/dist/cjs/extensions/dropcursor/index.jssimilarity index 94%rename from packages/editor/dist/extensions/dropcursor/index.jsrename to packages/editor/dist/cjs/extensions/dropcursor/index.jsindex 8a45ee72f..ca013fdf7 100644--- a/packages/editor/dist/extensions/dropcursor/index.js+++ b/packages/editor/dist/cjs/extensions/dropcursor/index.js@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);};Object.defineProperty(exports, "__esModule", { value: true });-var dropcursor_1 = require("./dropcursor");+const dropcursor_1 = require("./dropcursor");__exportStar(require("./dropcursor"), exports);exports.default = dropcursor_1.Dropcursor;diff --git a/packages/editor/dist/extensions/embed/component.d.ts b/packages/editor/dist/cjs/extensions/embed/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/embed/component.d.tsrename to packages/editor/dist/cjs/extensions/embed/component.d.tsdiff --git a/packages/editor/dist/extensions/embed/component.js b/packages/editor/dist/cjs/extensions/embed/component.jssimilarity index 68%rename from packages/editor/dist/extensions/embed/component.jsrename to packages/editor/dist/cjs/extensions/embed/component.jsindex 23c2f5e13..89297abf0 100644--- a/packages/editor/dist/extensions/embed/component.js+++ b/packages/editor/dist/cjs/extensions/embed/component.js@@ -1,31 +1,20 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};Object.defineProperty(exports, "__esModule", { value: true });exports.EmbedComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var re_resizable_1 = require("re-resizable");-var react_1 = require("react");-var responsive_1 = require("../../components/responsive");-var toolbargroup_1 = require("../../toolbar/components/toolbargroup");+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const re_resizable_1 = require("re-resizable");+const react_1 = require("react");+const responsive_1 = require("../../components/responsive");+const toolbargroup_1 = require("../../toolbar/components/toolbargroup");function EmbedComponent(props) {- var editor = props.editor, updateAttributes = props.updateAttributes, selected = props.selected, node = props.node;- var embedRef = (0, react_1.useRef)();- var _a = node.attrs, src = _a.src, width = _a.width, height = _a.height, align = _a.align;- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ sx: {+ const { editor, updateAttributes, selected, node } = props;+ const embedRef = (0, react_1.useRef)();+ const { src, width, height, align } = node.attrs;+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {display: "flex",justifyContent: align === "center" ? "center" : align === "left" ? "start" : "end",- } }, { children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, __assign({ enable: {+ } }, { children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, Object.assign({ enable: {bottom: editor.isEditable,left: editor.isEditable,right: editor.isEditable,@@ -37,12 +26,12 @@ function EmbedComponent(props) {}, size: {height: height || "auto",width: width || "auto",- }, maxWidth: "100%", onResizeStop: function (e, direction, ref, d) {+ }, maxWidth: "100%", onResizeStop: (e, direction, ref, d) => {updateAttributes({width: ref.clientWidth,height: ref.clientHeight,});- }, lockAspectRatio: true }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ width: "100%", sx: {+ }, lockAspectRatio: true }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ width: "100%", sx: {position: "relative",justifyContent: "end",borderTop: editor.isEditable@@ -55,7 +44,7 @@ function EmbedComponent(props) {":hover": {borderColor: "border",},- } }, { children: (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: { position: "relative", justifyContent: "end" } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {+ } }, { children: (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: { position: "relative", justifyContent: "end" } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {position: "absolute",top: -40,mb: 2,@@ -69,7 +58,7 @@ function EmbedComponent(props) {boxShadow: "menu",borderRadius: "default",bg: "background",- } }) })) }))) }) })), (0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ as: "iframe", ref: embedRef, src: src, width: "100%", height: "100%", sx: {+ } }) })) }))) }) })), (0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ as: "iframe", ref: embedRef, src: src, width: "100%", height: "100%", sx: {border: selected? "2px solid var(--primary)": "2px solid transparent",diff --git a/packages/editor/dist/extensions/embed/embed.d.ts b/packages/editor/dist/cjs/extensions/embed/embed.d.tssimilarity index 100%rename from packages/editor/dist/extensions/embed/embed.d.tsrename to packages/editor/dist/cjs/extensions/embed/embed.d.tsdiff --git a/packages/editor/dist/cjs/extensions/embed/embed.js b/packages/editor/dist/cjs/extensions/embed/embed.jsnew file mode 100644index 000000000..bd80544ad--- /dev/null+++ b/packages/editor/dist/cjs/extensions/embed/embed.js@@ -0,0 +1,65 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.EmbedNode = void 0;+const core_1 = require("@tiptap/core");+const react_1 = require("../react");+const component_1 = require("./component");+exports.EmbedNode = core_1.Node.create({+ name: "embed",+ content: "",+ marks: "",+ draggable: true,+ addOptions() {+ return {+ HTMLAttributes: {},+ };+ },+ group() {+ return "block";+ },+ addAttributes() {+ return {+ src: {+ default: null,+ },+ width: { default: null },+ height: { default: null },+ align: { default: "left" },+ };+ },+ parseHTML() {+ return [+ {+ tag: "iframe[src]",+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "iframe",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),+ ];+ },+ addNodeView() {+ return (0, react_1.createSelectionBasedNodeView)(component_1.EmbedComponent);+ },+ addCommands() {+ return {+ insertEmbed: (options) => ({ commands }) => {+ return commands.insertContent({+ type: this.name,+ attrs: options,+ });+ },+ setEmbedAlignment: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ setEmbedSize: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ setEmbedSource: (src) => ({ commands }) => {+ return commands.updateAttributes(this.name, { src });+ },+ };+ },+});diff --git a/packages/editor/dist/extensions/embed/index.d.ts b/packages/editor/dist/cjs/extensions/embed/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/embed/index.d.tsrename to packages/editor/dist/cjs/extensions/embed/index.d.tsdiff --git a/packages/editor/dist/extensions/embed/index.js b/packages/editor/dist/cjs/extensions/embed/index.jssimilarity index 100%rename from packages/editor/dist/extensions/embed/index.jsrename to packages/editor/dist/cjs/extensions/embed/index.jsdiff --git a/packages/editor/dist/extensions/fontsize/fontsize.d.ts b/packages/editor/dist/cjs/extensions/fontsize/fontsize.d.tssimilarity index 100%rename from packages/editor/dist/extensions/fontsize/fontsize.d.tsrename to packages/editor/dist/cjs/extensions/fontsize/fontsize.d.tsdiff --git a/packages/editor/dist/cjs/extensions/fontsize/fontsize.js b/packages/editor/dist/cjs/extensions/fontsize/fontsize.jsnew file mode 100644index 000000000..645d48a46--- /dev/null+++ b/packages/editor/dist/cjs/extensions/fontsize/fontsize.js@@ -0,0 +1,46 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.FontSize = void 0;+const core_1 = require("@tiptap/core");+require("@tiptap/extension-text-style");+exports.FontSize = core_1.Extension.create({+ name: "fontSize",+ defaultOptions: {+ types: ["textStyle"],+ defaultFontSize: 16,+ },+ addGlobalAttributes() {+ return [+ {+ types: this.options.types,+ attributes: {+ fontSize: {+ default: `${this.options.defaultFontSize}px`,+ parseHTML: (element) => element.style.fontSize,+ renderHTML: (attributes) => {+ if (!attributes.fontSize) {+ return {};+ }+ return {+ style: `font-size: ${attributes.fontSize}`,+ };+ },+ },+ },+ },+ ];+ },+ addCommands() {+ return {+ setFontSize: (fontSize) => ({ chain }) => {+ return chain().setMark("textStyle", { fontSize }).run();+ },+ unsetFontSize: () => ({ chain }) => {+ return chain()+ .setMark("textStyle", { fontSize: null })+ .removeEmptyTextStyle()+ .run();+ },+ };+ },+});diff --git a/packages/editor/dist/extensions/fontsize/index.d.ts b/packages/editor/dist/cjs/extensions/fontsize/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/fontsize/index.d.tsrename to packages/editor/dist/cjs/extensions/fontsize/index.d.tsdiff --git a/packages/editor/dist/extensions/fontsize/index.js b/packages/editor/dist/cjs/extensions/fontsize/index.jssimilarity index 95%rename from packages/editor/dist/extensions/fontsize/index.jsrename to packages/editor/dist/cjs/extensions/fontsize/index.jsindex f466a7472..167f5a0cd 100644--- a/packages/editor/dist/extensions/fontsize/index.js+++ b/packages/editor/dist/cjs/extensions/fontsize/index.js@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);};Object.defineProperty(exports, "__esModule", { value: true });-var fontsize_1 = require("./fontsize");+const fontsize_1 = require("./fontsize");__exportStar(require("./fontsize"), exports);exports.default = fontsize_1.FontSize;diff --git a/packages/editor/dist/extensions/image/component.d.ts b/packages/editor/dist/cjs/extensions/image/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/image/component.d.tsrename to packages/editor/dist/cjs/extensions/image/component.d.tsdiff --git a/packages/editor/dist/cjs/extensions/image/component.js b/packages/editor/dist/cjs/extensions/image/component.jsnew file mode 100644index 000000000..1bf6973b1--- /dev/null+++ b/packages/editor/dist/cjs/extensions/image/component.js@@ -0,0 +1,106 @@+"use strict";+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.ImageComponent = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const re_resizable_1 = require("re-resizable");+const react_1 = require("react");+const responsive_1 = require("../../components/responsive");+const toolbargroup_1 = require("../../toolbar/components/toolbargroup");+function ImageComponent(props) {+ const { editor, updateAttributes, node, selected } = props;+ const { src, alt, title, width, height, align, float } = node.attrs;+ const imageRef = (0, react_1.useRef)();+ (0, react_1.useEffect)(() => {+ (() => __awaiter(this, void 0, void 0, function* () {+ if (!imageRef.current || !src)+ return;+ imageRef.current.src = yield dataUriToBlobURL(src);+ }))();+ }, [src, imageRef]);+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {+ display: float ? "block" : "flex",+ justifyContent: float+ ? "stretch"+ : align === "center"+ ? "center"+ : align === "left"+ ? "start"+ : "end",+ ":hover .drag-handle, :active .drag-handle": {+ opacity: 1,+ },+ } }, { children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, Object.assign({ enable: {+ bottom: editor.isEditable,+ left: editor.isEditable,+ right: editor.isEditable,+ top: editor.isEditable,+ bottomLeft: editor.isEditable,+ bottomRight: editor.isEditable,+ topLeft: editor.isEditable,+ topRight: editor.isEditable,+ }, style: {+ position: "relative",+ float: float ? (align === "left" ? "left" : "right") : "none",+ }, size: {+ height: height || "auto",+ width: width || "auto",+ }, maxWidth: "100%", onResizeStop: (e, direction, ref, d) => {+ updateAttributes({+ width: ref.clientWidth,+ height: ref.clientHeight,+ });+ }, lockAspectRatio: true }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ width: "100%", "data-drag-handle": true, draggable: true, sx: {+ position: "relative",+ justifyContent: "end",+ borderTop: editor.isEditable+ ? "20px solid var(--bgSecondary)"+ : "none",+ borderTopLeftRadius: "default",+ borderTopRightRadius: "default",+ borderColor: selected ? "border" : "bgSecondary",+ cursor: "pointer",+ ":hover": {+ borderColor: "border",+ },+ } }, { children: (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: { position: "relative", justifyContent: "end" } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {+ position: "absolute",+ top: -40,+ mb: 2,+ alignItems: "end",+ } }, { children: (0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { editor: editor, tools: [+ "imageAlignLeft",+ "imageAlignCenter",+ "imageAlignRight",+ "imageProperties",+ ], sx: {+ boxShadow: "menu",+ borderRadius: "default",+ bg: "background",+ } }) })) }))) }) })), (0, jsx_runtime_1.jsx)(rebass_1.Image, Object.assign({ "data-drag-image": true, ref: imageRef, alt: alt, src: "/placeholder.svg", title: title, width: "100%", height: "100%", sx: {+ bg: "bgSecondary",+ border: selected+ ? "2px solid var(--primary)"+ : "2px solid transparent",+ borderRadius: "default",+ } }, props))] })) })) }));+}+exports.ImageComponent = ImageComponent;+function dataUriToBlobURL(dataurl) {+ return __awaiter(this, void 0, void 0, function* () {+ if (!dataurl.startsWith("data:image"))+ return dataurl;+ const response = yield fetch(dataurl);+ const blob = yield response.blob();+ return URL.createObjectURL(blob);+ });+}diff --git a/packages/editor/dist/extensions/image/image.d.ts b/packages/editor/dist/cjs/extensions/image/image.d.tssimilarity index 100%rename from packages/editor/dist/extensions/image/image.d.tsrename to packages/editor/dist/cjs/extensions/image/image.d.tsdiff --git a/packages/editor/dist/cjs/extensions/image/image.js b/packages/editor/dist/cjs/extensions/image/image.jsnew file mode 100644index 000000000..8d9d464b8--- /dev/null+++ b/packages/editor/dist/cjs/extensions/image/image.js@@ -0,0 +1,109 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.ImageNode = exports.inputRegex = void 0;+const core_1 = require("@tiptap/core");+const attachment_1 = require("../attachment");+const react_1 = require("../react");+const component_1 = require("./component");+exports.inputRegex = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;+exports.ImageNode = core_1.Node.create({+ name: "image",+ addOptions() {+ return {+ inline: false,+ allowBase64: false,+ HTMLAttributes: {},+ };+ },+ inline() {+ return this.options.inline;+ },+ group() {+ return this.options.inline ? "inline" : "block";+ },+ draggable: true,+ addAttributes() {+ return {+ src: {+ default: null,+ },+ alt: {+ default: null,+ },+ title: {+ default: null,+ },+ width: { default: null },+ height: { default: null },+ float: (0, attachment_1.getDataAttribute)("float", false),+ align: (0, attachment_1.getDataAttribute)("align", "left"),+ hash: (0, attachment_1.getDataAttribute)("hash"),+ filename: (0, attachment_1.getDataAttribute)("filename"),+ type: (0, attachment_1.getDataAttribute)("mime"),+ size: (0, attachment_1.getDataAttribute)("size"),+ };+ },+ parseHTML() {+ return [+ {+ tag: this.options.allowBase64 ? "img" : 'img:not([src^="data:"])',+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "img",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),+ ];+ },+ addNodeView() {+ return (0, react_1.createSelectionBasedNodeView)(component_1.ImageComponent);+ },+ addCommands() {+ return {+ insertImage: (options) => ({ commands }) => {+ return commands.insertContent({+ type: this.name,+ attrs: options,+ });+ },+ setImageAlignment: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ setImageSize: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ updateImage: (options) => ({ state, tr, dispatch }) => {+ const query = options.hash+ ? { key: "hash", value: options.hash }+ : options.src+ ? { key: "src", value: options.src }+ : null;+ if (!query)+ return false;+ const images = (0, core_1.findChildren)(state.doc, (node) => node.type.name === this.name &&+ node.attrs[query.key] === query.value);+ for (const image of images) {+ tr.setNodeMarkup(image.pos, image.node.type, Object.assign(Object.assign({}, image.node.attrs), options));+ }+ tr.setMeta("preventUpdate", true);+ tr.setMeta("addToHistory", false);+ if (dispatch)+ dispatch(tr);+ return true;+ },+ };+ },+ addInputRules() {+ return [+ (0, core_1.nodeInputRule)({+ find: exports.inputRegex,+ type: this.type,+ getAttributes: (match) => {+ const [, , alt, src, title] = match;+ return { src, alt, title };+ },+ }),+ ];+ },+});diff --git a/packages/editor/dist/extensions/image/index.d.ts b/packages/editor/dist/cjs/extensions/image/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/image/index.d.tsrename to packages/editor/dist/cjs/extensions/image/index.d.tsdiff --git a/packages/editor/dist/extensions/image/index.js b/packages/editor/dist/cjs/extensions/image/index.jssimilarity index 100%rename from packages/editor/dist/extensions/image/index.jsrename to packages/editor/dist/cjs/extensions/image/index.jsdiff --git a/packages/editor/dist/extensions/listitem/commands.d.ts b/packages/editor/dist/cjs/extensions/listitem/commands.d.tssimilarity index 100%rename from packages/editor/dist/extensions/listitem/commands.d.tsrename to packages/editor/dist/cjs/extensions/listitem/commands.d.tsdiff --git a/packages/editor/dist/extensions/listitem/commands.js b/packages/editor/dist/cjs/extensions/listitem/commands.jssimilarity index 69%rename from packages/editor/dist/extensions/listitem/commands.jsrename to packages/editor/dist/cjs/extensions/listitem/commands.jsindex 3a0ae5af8..cc26f7b66 100644--- a/packages/editor/dist/extensions/listitem/commands.js+++ b/packages/editor/dist/cjs/extensions/listitem/commands.js@@ -1,19 +1,19 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.onBackspacePressed = void 0;-var prosemirror_utils_1 = require("prosemirror-utils");+const prosemirror_utils_1 = require("prosemirror-utils");// WORKAROUND: if we're at the start of a list item, we need to either// backspace directly to an empty list item above, or outdent this nodefunction onBackspacePressed(editor, name, type) {- var selection = editor.state.selection;- var empty = selection.empty, $from = selection.$from;+ const { selection } = editor.state;+ const { empty, $from } = selection;if (!empty ||!isInside(name, type, editor.state) ||$from.parentOffset !== 0 ||!isFirstChildOfParent(editor.state) ||!editor.can().liftListItem(type))return false;- var isEmpty = isListItemEmpty(type, editor.state);+ const isEmpty = isListItemEmpty(type, editor.state);if (isFirstOfType(type, editor.state)) {return editor.commands.liftListItem(type);}@@ -29,30 +29,30 @@ function onBackspacePressed(editor, name, type) {}exports.onBackspacePressed = onBackspacePressed;function isInside(name, type, state) {- var $from = state.selection.$from;- var node = type || state.schema.nodes[name];- var paragraph = state.schema.nodes.paragraph;+ const { $from } = state.selection;+ let node = type || state.schema.nodes[name];+ const { paragraph } = state.schema.nodes;return ((0, prosemirror_utils_1.hasParentNodeOfType)(node)(state.selection) &&$from.parent.type === paragraph);}function isFirstChildOfParent(state) {- var $from = state.selection.$from;+ const { $from } = state.selection;return $from.depth > 1? $from.parentOffset === 0 || $from.index($from.depth - 1) === 0: true;}-var isFirstOfType = function (type, state) {- var block = (0, prosemirror_utils_1.findParentNodeOfType)(type)(state.selection);+const isFirstOfType = (type, state) => {+ const block = (0, prosemirror_utils_1.findParentNodeOfType)(type)(state.selection);if (!block)return false;- var pos = block.pos;- var resolved = state.doc.resolve(pos);+ const { pos } = block;+ const resolved = state.doc.resolve(pos);return !resolved.nodeBefore;};function isListItemEmpty(type, state) {- var block = (0, prosemirror_utils_1.findParentNodeOfType)(type)(state.selection);+ const block = (0, prosemirror_utils_1.findParentNodeOfType)(type)(state.selection);if (!block)return false;- var node = block.node;+ const { node } = block;return !node.textContent.length;}diff --git a/packages/editor/dist/extensions/listitem/index.d.ts b/packages/editor/dist/cjs/extensions/listitem/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/listitem/index.d.tsrename to packages/editor/dist/cjs/extensions/listitem/index.d.tsdiff --git a/packages/editor/dist/extensions/listitem/index.js b/packages/editor/dist/cjs/extensions/listitem/index.jssimilarity index 100%rename from packages/editor/dist/extensions/listitem/index.jsrename to packages/editor/dist/cjs/extensions/listitem/index.jsdiff --git a/packages/editor/dist/extensions/listitem/listitem.d.ts b/packages/editor/dist/cjs/extensions/listitem/listitem.d.tssimilarity index 100%rename from packages/editor/dist/extensions/listitem/listitem.d.tsrename to packages/editor/dist/cjs/extensions/listitem/listitem.d.tsdiff --git a/packages/editor/dist/cjs/extensions/listitem/listitem.js b/packages/editor/dist/cjs/extensions/listitem/listitem.jsnew file mode 100644index 000000000..f3be4edf2--- /dev/null+++ b/packages/editor/dist/cjs/extensions/listitem/listitem.js@@ -0,0 +1,11 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.ListItem = void 0;+const extension_list_item_1 = require("@tiptap/extension-list-item");+const commands_1 = require("./commands");+exports.ListItem = extension_list_item_1.ListItem.extend({+ addKeyboardShortcuts() {+ var _a;+ return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { Backspace: ({ editor }) => (0, commands_1.onBackspacePressed)(editor, this.name, this.type) });+ },+});diff --git a/packages/editor/dist/extensions/math/index.d.ts b/packages/editor/dist/cjs/extensions/math/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/index.d.tsrename to packages/editor/dist/cjs/extensions/math/index.d.tsdiff --git a/packages/editor/dist/extensions/math/index.js b/packages/editor/dist/cjs/extensions/math/index.jssimilarity index 100%rename from packages/editor/dist/extensions/math/index.jsrename to packages/editor/dist/cjs/extensions/math/index.jsdiff --git a/packages/editor/dist/extensions/math/mathblock.d.ts b/packages/editor/dist/cjs/extensions/math/mathblock.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/mathblock.d.tsrename to packages/editor/dist/cjs/extensions/math/mathblock.d.tsdiff --git a/packages/editor/dist/cjs/extensions/math/mathblock.js b/packages/editor/dist/cjs/extensions/math/mathblock.jsnew file mode 100644index 000000000..d3786f64e--- /dev/null+++ b/packages/editor/dist/cjs/extensions/math/mathblock.js@@ -0,0 +1,40 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.MathBlock = void 0;+const core_1 = require("@tiptap/core");+const prosemirror_inputrules_1 = require("prosemirror-inputrules");+const plugin_1 = require("./plugin");+exports.MathBlock = core_1.Node.create({+ name: "mathBlock",+ group: "block math",+ content: "text*",+ atom: true,+ code: true,+ parseHTML() {+ return [+ {+ tag: `div[class*='math-block']`, // important!+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "div",+ (0, core_1.mergeAttributes)({ class: "math-block math-node" }, HTMLAttributes),+ 0,+ ];+ },+ addCommands() {+ return {+ insertMathBlock: () => ({ state, dispatch, view }) => {+ return (0, plugin_1.insertMathNode)(this.type)(state, dispatch, view);+ },+ };+ },+ addProseMirrorPlugins() {+ const inputRulePlugin = (0, prosemirror_inputrules_1.inputRules)({+ rules: [(0, plugin_1.makeBlockMathInputRule)(plugin_1.REGEX_BLOCK_MATH_DOLLARS, this.type)],+ });+ return [inputRulePlugin];+ },+});diff --git a/packages/editor/dist/extensions/math/mathinline.d.ts b/packages/editor/dist/cjs/extensions/math/mathinline.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/mathinline.d.tsrename to packages/editor/dist/cjs/extensions/math/mathinline.d.tsdiff --git a/packages/editor/dist/extensions/math/mathinline.js b/packages/editor/dist/cjs/extensions/math/mathinline.jssimilarity index 53%rename from packages/editor/dist/extensions/math/mathinline.jsrename to packages/editor/dist/cjs/extensions/math/mathinline.jsindex a1b8df859..87b5ebd5e 100644--- a/packages/editor/dist/extensions/math/mathinline.js+++ b/packages/editor/dist/cjs/extensions/math/mathinline.js@@ -1,9 +1,9 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.MathInline = void 0;-var core_1 = require("@tiptap/core");-var prosemirror_inputrules_1 = require("prosemirror-inputrules");-var plugin_1 = require("./plugin");+const core_1 = require("@tiptap/core");+const prosemirror_inputrules_1 = require("prosemirror-inputrules");+const plugin_1 = require("./plugin");exports.MathInline = core_1.Node.create({name: "mathInline",group: "inline math",@@ -11,34 +11,29 @@ exports.MathInline = core_1.Node.create({inline: true,atom: true,code: true,- parseHTML: function () {+ parseHTML() {return [{tag: "span[class*='math-inline']", // important!,},];},- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;+ renderHTML({ HTMLAttributes }) {return ["span",(0, core_1.mergeAttributes)({ class: "math-inline math-node" }, HTMLAttributes),0,];},- addCommands: function () {- var _this = this;+ addCommands() {return {- insertMathInline: function () {- return function (_a) {- var state = _a.state, dispatch = _a.dispatch, view = _a.view;- return (0, plugin_1.insertMathNode)(_this.type)(state, dispatch, view);- };+ insertMathInline: () => ({ state, dispatch, view }) => {+ return (0, plugin_1.insertMathNode)(this.type)(state, dispatch, view);},};},- addProseMirrorPlugins: function () {- var inputRulePlugin = (0, prosemirror_inputrules_1.inputRules)({+ addProseMirrorPlugins() {+ const inputRulePlugin = (0, prosemirror_inputrules_1.inputRules)({rules: [(0, plugin_1.makeInlineMathInputRule)(plugin_1.REGEX_INLINE_MATH_DOLLARS, this.type)],});return [plugin_1.mathPlugin, inputRulePlugin];diff --git a/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/commands/collapsemathnode.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/commands/collapsemathnode.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.js b/packages/editor/dist/cjs/extensions/math/plugin/commands/collapsemathnode.jssimilarity index 79%rename from packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.jsrename to packages/editor/dist/cjs/extensions/math/plugin/commands/collapsemathnode.jsindex 98dbe1c45..2a9bce44e 100644--- a/packages/editor/dist/extensions/math/plugin/commands/collapsemathnode.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/commands/collapsemathnode.js@@ -1,7 +1,7 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.collapseMathNode = void 0;-var prosemirror_state_1 = require("prosemirror-state");+const prosemirror_state_1 = require("prosemirror-state");/*** A ProseMirror command for determining whether to exit a math block, based on* specific conditions. Normally called when the user has@@ -15,24 +15,23 @@ var prosemirror_state_1 = require("prosemirror-state");* (inner) selection is empty.* @returns A new ProseMirror command based on the input configuration.*/-function collapseMathNode(outerView, dir, requireOnBorder, requireEmptySelection) {- if (requireEmptySelection === void 0) { requireEmptySelection = true; }+function collapseMathNode(outerView, dir, requireOnBorder, requireEmptySelection = true) {// create a new ProseMirror command based on the input conditions- return function (innerState, dispatch) {+ return (innerState, dispatch) => {// get selection info- var outerState = outerView.state;- var _a = outerState.selection, outerTo = _a.to, outerFrom = _a.from;- var _b = innerState.selection, innerTo = _b.to, innerFrom = _b.from;+ let outerState = outerView.state;+ let { to: outerTo, from: outerFrom } = outerState.selection;+ let { to: innerTo, from: innerFrom } = innerState.selection;// only exit math node when selection is emptyif (requireEmptySelection && innerTo !== innerFrom) {return false;}- var currentPos = dir > 0 ? innerTo : innerFrom;+ let currentPos = dir > 0 ? innerTo : innerFrom;// when requireOnBorder is TRUE, collapse only when cursor// is about to leave the bounds of the math nodeif (requireOnBorder) {// (subtract two from nodeSize to account for start and end tokens)- var nodeSize = innerState.doc.nodeSize - 2;+ let nodeSize = innerState.doc.nodeSize - 2;// early return if exit conditions not metif (dir > 0 && currentPos < nodeSize) {return false;@@ -44,7 +43,7 @@ function collapseMathNode(outerView, dir, requireOnBorder, requireEmptySelection// all exit conditions met, so close the math node by moving the cursor outsideif (dispatch) {// set outer selection to be outside of the nodeview- var targetPos = dir > 0 ? outerTo : outerFrom;+ let targetPos = dir > 0 ? outerTo : outerFrom;outerView.dispatch(outerState.tr.setSelection(prosemirror_state_1.TextSelection.create(outerState.doc, targetPos)));// must return focus to the outer view, otherwise no cursor will appearouterView.focus();diff --git a/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/commands/insertmathnode.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/commands/insertmathnode.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/commands/insertmathnode.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.js b/packages/editor/dist/cjs/extensions/math/plugin/commands/insertmathnode.jssimilarity index 74%rename from packages/editor/dist/extensions/math/plugin/commands/insertmathnode.jsrename to packages/editor/dist/cjs/extensions/math/plugin/commands/insertmathnode.jsindex e9c86a6db..a79632c05 100644--- a/packages/editor/dist/extensions/math/plugin/commands/insertmathnode.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/commands/insertmathnode.js@@ -1,7 +1,7 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.insertMathNode = void 0;-var prosemirror_state_1 = require("prosemirror-state");+const prosemirror_state_1 = require("prosemirror-state");/////////////////////////////////////////////////////////////////////////////////*** Returns a new command that can be used to inserts a new math node at the@@ -12,16 +12,15 @@ var prosemirror_state_1 = require("prosemirror-state");* NodeType. Must belong to the same schema that your EditorState uses!* @param initialText (optional) The initial source content for the math editor.*/-function insertMathNode(mathNodeType, initialText) {- if (initialText === void 0) { initialText = ""; }+function insertMathNode(mathNodeType, initialText = "") {return function (state, dispatch) {- var $from = state.selection.$from, index = $from.index();+ let { $from } = state.selection, index = $from.index();if (!$from.parent.canReplaceWith(index, index, mathNodeType)) {return false;}if (dispatch) {- var mathNode = mathNodeType.create({}, initialText ? state.schema.text(initialText) : null);- var tr = state.tr.replaceSelectionWith(mathNode);+ let mathNode = mathNodeType.create({}, initialText ? state.schema.text(initialText) : null);+ let tr = state.tr.replaceSelectionWith(mathNode);tr = tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, $from.pos));dispatch(tr);}diff --git a/packages/editor/dist/extensions/math/plugin/commands/move-cursor-cmd.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/commands/move-cursor-cmd.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/commands/move-cursor-cmd.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/commands/move-cursor-cmd.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/commands/move-cursor-cmd.js b/packages/editor/dist/cjs/extensions/math/plugin/commands/move-cursor-cmd.jssimilarity index 68%rename from packages/editor/dist/extensions/math/plugin/commands/move-cursor-cmd.jsrename to packages/editor/dist/cjs/extensions/math/plugin/commands/move-cursor-cmd.jsindex 94e98199c..796cac8e1 100644--- a/packages/editor/dist/extensions/math/plugin/commands/move-cursor-cmd.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/commands/move-cursor-cmd.js@@ -1,7 +1,7 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.nudgeCursorBackCmd = exports.nudgeCursorForwardCmd = exports.nudgeCursorCmd = void 0;-var prosemirror_state_1 = require("prosemirror-state");+const prosemirror_state_1 = require("prosemirror-state");/////////////////////////////////////////////////////////////////////////////////*** Some browsers (cough firefox cough) don't properly handle cursor movement on@@ -10,14 +10,14 @@ var prosemirror_state_1 = require("prosemirror-state");* @see https://bugzilla.mozilla.org/show_bug.cgi?id=1252108*/function nudgeCursorCmd(dir) {- return function (innerState, dispatch) {- var _a = innerState.selection, to = _a.to, from = _a.from;+ return (innerState, dispatch) => {+ let { to, from } = innerState.selection;// compute target position- var emptySelection = to === from;- var currentPos = dir < 0 ? from : to;- var increment = emptySelection ? dir : 0;- var nodeSize = innerState.doc.nodeSize;- var targetPos = Math.max(0, Math.min(nodeSize, currentPos + increment));+ let emptySelection = to === from;+ let currentPos = dir < 0 ? from : to;+ let increment = emptySelection ? dir : 0;+ let nodeSize = innerState.doc.nodeSize;+ let targetPos = Math.max(0, Math.min(nodeSize, currentPos + increment));if (dispatch) {dispatch(innerState.tr.setSelection(prosemirror_state_1.TextSelection.create(innerState.doc, targetPos)));}diff --git a/packages/editor/dist/extensions/math/plugin/index.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/index.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/index.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/index.js b/packages/editor/dist/cjs/extensions/math/plugin/index.jssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/index.jsrename to packages/editor/dist/cjs/extensions/math/plugin/index.jsdiff --git a/packages/editor/dist/extensions/math/plugin/math-nodeview.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/math-nodeview.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/math-nodeview.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/math-nodeview.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/math-nodeview.js b/packages/editor/dist/cjs/extensions/math/plugin/math-nodeview.jssimilarity index 76%rename from packages/editor/dist/extensions/math/plugin/math-nodeview.jsrename to packages/editor/dist/cjs/extensions/math/plugin/math-nodeview.jsindex 2c547f58c..d1852cf17 100644--- a/packages/editor/dist/extensions/math/plugin/math-nodeview.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/math-nodeview.js@@ -5,13 +5,13 @@*--------------------------------------------------------*/Object.defineProperty(exports, "__esModule", { value: true });exports.MathView = void 0;-var prosemirror_state_1 = require("prosemirror-state");-var prosemirror_view_1 = require("prosemirror-view");-var prosemirror_transform_1 = require("prosemirror-transform");-var prosemirror_keymap_1 = require("prosemirror-keymap");-var prosemirror_commands_1 = require("prosemirror-commands");-var collapsemathnode_1 = require("./commands/collapsemathnode");-var MathView = /** @class */ (function () {+const prosemirror_state_1 = require("prosemirror-state");+const prosemirror_view_1 = require("prosemirror-view");+const prosemirror_transform_1 = require("prosemirror-transform");+const prosemirror_keymap_1 = require("prosemirror-keymap");+const prosemirror_commands_1 = require("prosemirror-commands");+const collapsemathnode_1 = require("./commands/collapsemathnode");+class MathView {// == Lifecycle ===================================== ///*** @param onDestroy Callback for when this NodeView is destroyed.@@ -22,8 +22,7 @@ var MathView = /** @class */ (function () {* @option tagName HTML tag name to use for this NodeView. If none is provided,* will use the node name with underscores converted to hyphens.*/- function MathView(node, view, getPos, options, mathPluginKey, onDestroy) {- var _this = this;+ constructor(node, view, getPos, options, mathPluginKey, onDestroy) {// store argumentsthis.options = options;this._node = node;@@ -48,11 +47,11 @@ var MathView = /** @class */ (function () {this._mathSrcElt.classList.add("math-src");this.dom.appendChild(this._mathSrcElt);// ensure- this.dom.addEventListener("click", function () { return _this.ensureFocus(); });+ this.dom.addEventListener("click", () => this.ensureFocus());// render initial contentthis.renderMath();}- MathView.prototype.destroy = function () {+ destroy() {// close the inner editor without renderingthis.closeEditor(false);// clean up dom elements@@ -65,29 +64,29 @@ var MathView = /** @class */ (function () {delete this._mathSrcElt;}this.dom.remove();- };+ }/*** Ensure focus on the inner editor whenever this node has focus.* This helps to prevent accidental deletions of math blocks.*/- MathView.prototype.ensureFocus = function () {+ ensureFocus() {if (this._innerView && this._outerView.hasFocus()) {this._innerView.focus();}- };+ }// == Updates ======================================= //- MathView.prototype.update = function (node, _decorations, _innerDecorations) {+ update(node, _decorations, _innerDecorations) {if (!node.sameMarkup(this._node))return false;this._node = node;if (this._innerView) {- var state = this._innerView.state;- var start = node.content.findDiffStart(state.doc.content);+ let state = this._innerView.state;+ let start = node.content.findDiffStart(state.doc.content);if (start != null) {- var diff = node.content.findDiffEnd(state.doc.content);+ let diff = node.content.findDiffEnd(state.doc.content);if (diff) {- var endA = diff.a, endB = diff.b;- var overlap = start - Math.min(endA, endB);+ let { a: endA, b: endB } = diff;+ let overlap = start - Math.min(endA, endB);if (overlap > 0) {endA += overlap;endB += overlap;@@ -102,17 +101,17 @@ var MathView = /** @class */ (function () {this.renderMath();}return true;- };- MathView.prototype.updateCursorPos = function (state) {- var pos = this._getPos();- var size = this._node.nodeSize;- var inPmSelection = state.selection.from < pos + size && pos < state.selection.to;+ }+ updateCursorPos(state) {+ const pos = this._getPos();+ const size = this._node.nodeSize;+ const inPmSelection = state.selection.from < pos + size && pos < state.selection.to;if (!inPmSelection) {this.cursorSide = pos < state.selection.from ? "end" : "start";}- };+ }// == Events ===================================== //- MathView.prototype.selectNode = function () {+ selectNode() {if (!this._outerView.editable) {return;}@@ -120,29 +119,29 @@ var MathView = /** @class */ (function () {if (!this._isEditing) {this.openEditor();}- };- MathView.prototype.deselectNode = function () {+ }+ deselectNode() {this.dom.classList.remove("ProseMirror-selectednode");if (this._isEditing) {this.closeEditor();}- };- MathView.prototype.stopEvent = function (event) {+ }+ stopEvent(event) {return (this._innerView !== undefined &&event.target !== undefined &&this._innerView.dom.contains(event.target));- };- MathView.prototype.ignoreMutation = function () {+ }+ ignoreMutation() {return true;- };+ }// == Rendering ===================================== //- MathView.prototype.renderMath = function () {+ renderMath() {if (!this._mathRenderElt) {return;}// get tex string to render- var content = this._node.content.content;- var texString = "";+ let content = this._node.content.content;+ let texString = "";if (content.length > 0 && content[0].textContent !== null) {texString = content[0].textContent.trim();}@@ -172,20 +171,20 @@ var MathView = /** @class */ (function () {this.dom.setAttribute("title", err.toString());}}- };+ }// == Inner Editor ================================== //- MathView.prototype.dispatchInner = function (tr) {+ dispatchInner(tr) {if (!this._innerView) {return;}- var _a = this._innerView.state.applyTransaction(tr), state = _a.state, transactions = _a.transactions;+ let { state, transactions } = this._innerView.state.applyTransaction(tr);this._innerView.updateState(state);if (!tr.getMeta("fromOutside")) {- var outerTr = this._outerView.state.tr, offsetMap = prosemirror_transform_1.StepMap.offset(this._getPos() + 1);- for (var i = 0; i < transactions.length; i++) {- var steps = transactions[i].steps;- for (var j = 0; j < steps.length; j++) {- var mapped = steps[j].map(offsetMap);+ let outerTr = this._outerView.state.tr, offsetMap = prosemirror_transform_1.StepMap.offset(this._getPos() + 1);+ for (let i = 0; i < transactions.length; i++) {+ let steps = transactions[i].steps;+ for (let j = 0; j < steps.length; j++) {+ let mapped = steps[j].map(offsetMap);if (!mapped) {throw Error("step discarded!");}@@ -195,9 +194,8 @@ var MathView = /** @class */ (function () {if (outerTr.docChanged)this._outerView.dispatch(outerTr);}- };- MathView.prototype.openEditor = function () {- var _this = this;+ }+ openEditor() {var _a;if (this._innerView) {throw Error("inner view should not exist!");@@ -210,24 +208,24 @@ var MathView = /** @class */ (function () {doc: this._node,plugins: [(0, prosemirror_keymap_1.keymap)({- Tab: function (state, dispatch) {+ Tab: (state, dispatch) => {if (dispatch) {dispatch(state.tr.insertText("\t"));}return true;},- Backspace: (0, prosemirror_commands_1.chainCommands)(prosemirror_commands_1.deleteSelection, function (state, dispatch, tr_inner) {+ Backspace: (0, prosemirror_commands_1.chainCommands)(prosemirror_commands_1.deleteSelection, (state, dispatch, tr_inner) => {// default backspace behavior for non-empty selectionsif (!state.selection.empty) {return false;}// default backspace behavior when math node is non-empty- if (_this._node.textContent.length > 0) {+ if (this._node.textContent.length > 0) {return false;}// otherwise, we want to delete the empty math node and focus the outer view- _this._outerView.dispatch(_this._outerView.state.tr.insertText(""));- _this._outerView.focus();+ this._outerView.dispatch(this._outerView.state.tr.insertText(""));+ this._outerView.focus();return true;}),// "Ctrl-Backspace": (state, dispatch, tr_inner) => {@@ -248,27 +246,26 @@ var MathView = /** @class */ (function () {dispatchTransaction: this.dispatchInner.bind(this),});// focus element- var innerState = this._innerView.state;+ let innerState = this._innerView.state;this._innerView.focus();// request outer cursor position before math node was selected- var maybePos = (_a = this._mathPluginKey.getState(this._outerView.state)) === null || _a === void 0 ? void 0 : _a.prevCursorPos;+ let maybePos = (_a = this._mathPluginKey.getState(this._outerView.state)) === null || _a === void 0 ? void 0 : _a.prevCursorPos;if (maybePos === null || maybePos === undefined) {console.error("[prosemirror-math] Error: Unable to fetch math plugin state from key.");}- var prevCursorPos = maybePos !== null && maybePos !== void 0 ? maybePos : 0;+ let prevCursorPos = maybePos !== null && maybePos !== void 0 ? maybePos : 0;// compute position that cursor should appear within the expanded math node- var innerPos = prevCursorPos <= this._getPos() ? 0 : this._node.nodeSize - 2;+ let innerPos = prevCursorPos <= this._getPos() ? 0 : this._node.nodeSize - 2;this._innerView.dispatch(innerState.tr.setSelection(prosemirror_state_1.TextSelection.create(innerState.doc, innerPos)));this._isEditing = true;- };+ }/*** Called when the inner ProseMirror editor should close.** @param render Optionally update the rendered math after closing. (which* is generally what we want to do, since the user is done editing!)*/- MathView.prototype.closeEditor = function (render) {- if (render === void 0) { render = true; }+ closeEditor(render = true) {if (this._innerView) {this._innerView.destroy();this._innerView = undefined;@@ -277,7 +274,6 @@ var MathView = /** @class */ (function () {this.renderMath();}this._isEditing = false;- };- return MathView;-}());+ }+}exports.MathView = MathView;diff --git a/packages/editor/dist/extensions/math/plugin/math-plugin.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/math-plugin.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/math-plugin.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/math-plugin.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/math-plugin.js b/packages/editor/dist/cjs/extensions/math/plugin/math-plugin.jssimilarity index 76%rename from packages/editor/dist/extensions/math/plugin/math-plugin.jsrename to packages/editor/dist/cjs/extensions/math/plugin/math-plugin.jsindex b2a8f9ba1..bdb935e9d 100644--- a/packages/editor/dist/extensions/math/plugin/math-plugin.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/math-plugin.js@@ -5,33 +5,33 @@*--------------------------------------------------------*/Object.defineProperty(exports, "__esModule", { value: true });exports.mathPlugin = exports.createMathView = void 0;-var prosemirror_state_1 = require("prosemirror-state");-var math_nodeview_1 = require("./math-nodeview");-var katex_1 = require("./renderers/katex");+const prosemirror_state_1 = require("prosemirror-state");+const math_nodeview_1 = require("./math-nodeview");+const katex_1 = require("./renderers/katex");// uniquely identifies the prosemirror-math plugin-var MATH_PLUGIN_KEY = new prosemirror_state_1.PluginKey("prosemirror-math");+const MATH_PLUGIN_KEY = new prosemirror_state_1.PluginKey("prosemirror-math");/*** Returns a function suitable for passing as a field in `EditorProps.nodeViews`.* @param inline TRUE for block math, FALSE for inline math.* @see https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews*/function createMathView(inline) {- return function (node, view, getPos) {+ return (node, view, getPos) => {/** @todo is this necessary?* Docs says that for any function proprs, the current plugin instance* will be bound to `this`. However, the typings don't reflect this.*/- var pluginState = MATH_PLUGIN_KEY.getState(view.state);+ let pluginState = MATH_PLUGIN_KEY.getState(view.state);if (!pluginState) {throw new Error("no math plugin!");}- var nodeViews = pluginState.activeNodeViews;+ let nodeViews = pluginState.activeNodeViews;// set up NodeView- var nodeView = new math_nodeview_1.MathView(node, view, getPos, {+ let nodeView = new math_nodeview_1.MathView(node, view, getPos, {className: inline ? "math-inline" : "math-block",renderer: inline ? katex_1.KatexRenderer.inline : katex_1.KatexRenderer.block,tagName: inline ? "span" : "div",- }, MATH_PLUGIN_KEY, function () {+ }, MATH_PLUGIN_KEY, () => {nodeViews.splice(nodeViews.indexOf(nodeView));});nodeViews.push(nodeView);@@ -39,20 +39,20 @@ function createMathView(inline) {};}exports.createMathView = createMathView;-var mathPluginSpec = {+let mathPluginSpec = {key: MATH_PLUGIN_KEY,state: {- init: function (config, instance) {+ init(config, instance) {return {macros: {},activeNodeViews: [],prevCursorPos: 0,};},- apply: function (tr, value, oldState, newState) {+ apply(tr, value, oldState, newState) {// produce updated state field for this plugin- var newPos = newState.selection.from;- var oldPos = oldState.selection.from;+ const newPos = newState.selection.from;+ const oldPos = oldState.selection.from;return {// these values are left unchangedactiveNodeViews: value.activeNodeViews,diff --git a/packages/editor/dist/extensions/math/plugin/math-schema.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/math-schema.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/math-schema.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/math-schema.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/math-schema.js b/packages/editor/dist/cjs/extensions/math/plugin/math-schema.jssimilarity index 52%rename from packages/editor/dist/extensions/math/plugin/math-schema.jsrename to packages/editor/dist/cjs/extensions/math/plugin/math-schema.jsindex 640d1a87f..8e31a309d 100644--- a/packages/editor/dist/extensions/math/plugin/math-schema.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/math-schema.js@@ -3,47 +3,11 @@* Author: Benjamin R. Bray* License: MIT (see LICENSE in project root for details)*--------------------------------------------------------*/-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};Object.defineProperty(exports, "__esModule", { value: true });exports.extendMathSchemaSpec = exports.createMathSchema = exports.mathSchemaSpec = void 0;// prosemirror imports-var prosemirror_model_1 = require("prosemirror-model");-var math_paste_rules_1 = require("./plugins/math-paste-rules");+const prosemirror_model_1 = require("prosemirror-model");+const math_paste_rules_1 = require("./plugins/math-paste-rules");////////////////////////////////////////////////////////////// force typescript to infer generic type arguments for SchemaSpecfunction createSchemaSpec(spec) {@@ -60,7 +24,7 @@ exports.mathSchemaSpec = createSchemaSpec({content: "inline*",group: "block",parseDOM: [{ tag: "p" }],- toDOM: function () {+ toDOM() {return ["p", 0];},},@@ -69,16 +33,16 @@ exports.mathSchemaSpec = createSchemaSpec({content: "text*",inline: true,atom: true,- toDOM: function () { return ["math-inline", { class: "math-node" }, 0]; },- parseDOM: __spreadArray([{ tag: "math-inline" }], __read(math_paste_rules_1.defaultInlineMathParseRules), false),+ toDOM: () => ["math-inline", { class: "math-node" }, 0],+ parseDOM: [{ tag: "math-inline" }, ...math_paste_rules_1.defaultInlineMathParseRules],},math_display: {group: "block math",content: "text*",atom: true,code: true,- toDOM: function () { return ["math-display", { class: "math-node" }, 0]; },- parseDOM: __spreadArray([{ tag: "math-display" }], __read(math_paste_rules_1.defaultBlockMathParseRules), false),+ toDOM: () => ["math-display", { class: "math-node" }, 0],+ parseDOM: [{ tag: "math-display" }, ...math_paste_rules_1.defaultBlockMathParseRules],},text: {group: "inline",@@ -86,7 +50,7 @@ exports.mathSchemaSpec = createSchemaSpec({},marks: {math_select: {- toDOM: function () {+ toDOM() {return ["math-select", 0];},parseDOM: [{ tag: "math-select" }],@@ -112,8 +76,8 @@ exports.createMathSchema = createMathSchema;* must be a raw object (not an OrderedMap).*/function extendMathSchemaSpec(baseSpec) {- var nodes = __assign(__assign({}, baseSpec.nodes), exports.mathSchemaSpec.nodes);- var marks = __assign(__assign({}, baseSpec.marks), exports.mathSchemaSpec.marks);- return { nodes: nodes, marks: marks, topNode: baseSpec.topNode };+ let nodes = Object.assign(Object.assign({}, baseSpec.nodes), exports.mathSchemaSpec.nodes);+ let marks = Object.assign(Object.assign({}, baseSpec.marks), exports.mathSchemaSpec.marks);+ return { nodes, marks, topNode: baseSpec.topNode };}exports.extendMathSchemaSpec = extendMathSchemaSpec;diff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-backspace.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-backspace.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/plugins/math-backspace.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-backspace.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-backspace.js b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-backspace.jssimilarity index 70%rename from packages/editor/dist/extensions/math/plugin/plugins/math-backspace.jsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-backspace.jsindex 85d630a36..cfb9d7118 100644--- a/packages/editor/dist/extensions/math/plugin/plugins/math-backspace.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-backspace.js@@ -1,18 +1,18 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.mathBackspaceCmd = void 0;-var prosemirror_state_1 = require("prosemirror-state");-var mathBackspaceCmd = function (state, dispatch) {+const prosemirror_state_1 = require("prosemirror-state");+const mathBackspaceCmd = (state, dispatch) => {// check node before- var $from = state.selection.$from;- var nodeBefore = $from.nodeBefore;+ let { $from } = state.selection;+ let nodeBefore = $from.nodeBefore;if (!nodeBefore) {return false;}if (nodeBefore.type.name == "math_inline") {// select math node- var index = $from.index($from.depth);- var $beforePos = state.doc.resolve($from.posAtIndex(index - 1));+ let index = $from.index($from.depth);+ let $beforePos = state.doc.resolve($from.posAtIndex(index - 1));if (dispatch) {dispatch(state.tr.setSelection(new prosemirror_state_1.NodeSelection($beforePos)));}diff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-inputrules.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-inputrules.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/plugins/math-inputrules.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-inputrules.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-inputrules.js b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-inputrules.jssimilarity index 76%rename from packages/editor/dist/extensions/math/plugin/plugins/math-inputrules.jsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-inputrules.jsindex 26d1c485f..4bb70b42a 100644--- a/packages/editor/dist/extensions/math/plugin/plugins/math-inputrules.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-inputrules.js@@ -5,8 +5,8 @@*--------------------------------------------------------*/Object.defineProperty(exports, "__esModule", { value: true });exports.makeBlockMathInputRule = exports.makeInlineMathInputRule = exports.REGEX_BLOCK_MATH_DOLLARS = exports.REGEX_INLINE_MATH_DOLLARS_ESCAPED = exports.REGEX_INLINE_MATH_DOLLARS = void 0;-var prosemirror_inputrules_1 = require("prosemirror-inputrules");-var prosemirror_state_1 = require("prosemirror-state");+const prosemirror_inputrules_1 = require("prosemirror-inputrules");+const prosemirror_state_1 = require("prosemirror-state");////////////////////////////////////////////////////////////// ---- Inline Input Rules ------------------------------ //// simple input rule for inline math@@ -14,7 +14,7 @@ exports.REGEX_INLINE_MATH_DOLLARS = /\$\$(.+)\$\$/; //new RegExp("\$(.+)\$", "i"// negative lookbehind regex notation allows for escaped \$ delimiters// (requires browser supporting ECMA2018 standard -- currently only Chrome / FF)// (see https://javascript.info/regexp-lookahead-lookbehind)-exports.REGEX_INLINE_MATH_DOLLARS_ESCAPED = (function () {+exports.REGEX_INLINE_MATH_DOLLARS_ESCAPED = (() => {// attempt to create regex with negative lookbehindtry {return new RegExp("(?<!\\\\)\\$(.+)(?<!\\\\)\\$");@@ -28,12 +28,12 @@ exports.REGEX_INLINE_MATH_DOLLARS_ESCAPED = (function () {exports.REGEX_BLOCK_MATH_DOLLARS = /\$\$\$\s+$/; //new RegExp("\$\$\s+$", "i");////////////////////////////////////////////////////////////function makeInlineMathInputRule(pattern, nodeType, getAttrs) {- return new prosemirror_inputrules_1.InputRule(pattern, function (state, match, start, end) {- var $start = state.doc.resolve(start);- var index = $start.index();- var $end = state.doc.resolve(end);+ return new prosemirror_inputrules_1.InputRule(pattern, (state, match, start, end) => {+ let $start = state.doc.resolve(start);+ let index = $start.index();+ let $end = state.doc.resolve(end);// get attrs- var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;+ let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;// check if replacement validif (!$start.parent.canReplaceWith(index, $end.index(), nodeType)) {return null;@@ -44,14 +44,14 @@ function makeInlineMathInputRule(pattern, nodeType, getAttrs) {}exports.makeInlineMathInputRule = makeInlineMathInputRule;function makeBlockMathInputRule(pattern, nodeType, getAttrs) {- return new prosemirror_inputrules_1.InputRule(pattern, function (state, match, start, end) {- var $start = state.doc.resolve(start);- var attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;+ return new prosemirror_inputrules_1.InputRule(pattern, (state, match, start, end) => {+ let $start = state.doc.resolve(start);+ let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;if (!$start.node(-1).canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType))return null;- var tr = state.tr+ let tr = state.tr.delete(start, end).setBlockType(start, start, nodeType, attrs);return tr.setSelection(prosemirror_state_1.NodeSelection.create(tr.doc, tr.mapping.map($start.pos - 1)));diff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-paste-rules.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-paste-rules.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/plugins/math-paste-rules.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-paste-rules.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-paste-rules.js b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-paste-rules.jssimilarity index 75%rename from packages/editor/dist/extensions/math/plugin/plugins/math-paste-rules.jsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-paste-rules.jsindex 075868e08..31b773359 100644--- a/packages/editor/dist/extensions/math/plugin/plugins/math-paste-rules.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-paste-rules.js@@ -9,38 +9,16 @@* rule from matching, while returning `null` indicates that* the default set of note attributes should be used.*/-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};Object.defineProperty(exports, "__esModule", { value: true });exports.defaultBlockMathParseRules = exports.defaultInlineMathParseRules = exports.wikipediaInlineMathParseRule = exports.wikipediaBlockMathParseRule = void 0;-var prosemirror_model_1 = require("prosemirror-model");+const prosemirror_model_1 = require("prosemirror-model");////////////////////////////////////////////////////////////function getFirstMatch(root, rules) {- var e_1, _a;- try {- for (var rules_1 = __values(rules), rules_1_1 = rules_1.next(); !rules_1_1.done; rules_1_1 = rules_1.next()) {- var rule = rules_1_1.value;- var match = rule(root);- if (match !== false) {- return match;- }- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (rules_1_1 && !rules_1_1.done && (_a = rules_1.return)) _a.call(rules_1);+ for (let rule of rules) {+ let match = rule(root);+ if (match !== false) {+ return match;}- finally { if (e_1) throw e_1.error; }}return false;}@@ -57,7 +35,7 @@ function makeTextFragment(text, schema) {*/function texFromMediaWikiFallbackImage(root) {var _a;- var match = root.querySelector("img.mwe-math-fallback-image-inline[alt]");+ let match = root.querySelector("img.mwe-math-fallback-image-inline[alt]");return (_a = match === null || match === void 0 ? void 0 : match.getAttribute("alt")) !== null && _a !== void 0 ? _a : false;}/**@@ -66,7 +44,7 @@ function texFromMediaWikiFallbackImage(root) {*/function texFromMathML_01(root) {var _a;- var match = root.querySelector("math[alttext]");+ let match = root.querySelector("math[alttext]");return (_a = match === null || match === void 0 ? void 0 : match.getAttribute("alttext")) !== null && _a !== void 0 ? _a : false;}/**@@ -75,7 +53,7 @@ function texFromMathML_01(root) {*/function texFromMathML_02(root) {var _a;- var match = root.querySelector("math annotation[encoding='application/x-tex'");+ let match = root.querySelector("math annotation[encoding='application/x-tex'");return (_a = match === null || match === void 0 ? void 0 : match.textContent) !== null && _a !== void 0 ? _a : false;}/**@@ -84,11 +62,11 @@ function texFromMathML_02(root) {*/function texFromScriptTag(root) {var _a;- var match = root.querySelector("script[type*='math/tex']");+ let match = root.querySelector("script[type*='math/tex']");return (_a = match === null || match === void 0 ? void 0 : match.textContent) !== null && _a !== void 0 ? _a : false;}function matchWikipedia(root) {- var match = getFirstMatch(root, [+ let match = getFirstMatch(root, [texFromMediaWikiFallbackImage,texFromMathML_01,texFromMathML_02,@@ -120,13 +98,13 @@ function matchWikipedia(root) {*/exports.wikipediaBlockMathParseRule = {tag: "dl",- getAttrs: function (p) {- var dl = p;+ getAttrs(p) {+ let dl = p;// <dl> must contain exactly one childif (dl.childElementCount !== 1) {return false;}- var dd = dl.firstChild;+ let dd = dl.firstChild;if (dd.tagName !== "DD") {return false;}@@ -134,18 +112,18 @@ exports.wikipediaBlockMathParseRule = {if (dd.childElementCount !== 1) {return false;}- var mweElt = dd.firstChild;+ let mweElt = dd.firstChild;if (!mweElt.classList.contains("mwe-math-element")) {return false;}// success! proceed to `getContent` for further processingreturn null;},- getContent: function (p, schema) {+ getContent(p, schema) {// search the matched element for a TeX string- var match = matchWikipedia(p);+ let match = matchWikipedia(p);// return a fragment representing the math node's children- var texString = match || "\\text{\\color{red}(paste error)}";+ let texString = match || "\\text{\\color{red}(paste error)}";return makeTextFragment(texString, schema);},};@@ -170,19 +148,19 @@ exports.wikipediaBlockMathParseRule = {*/exports.wikipediaInlineMathParseRule = {tag: "span",- getAttrs: function (p) {- var span = p;+ getAttrs(p) {+ let span = p;if (!span.classList.contains("mwe-math-element")) {return false;}// success! proceed to `getContent` for further processingreturn null;},- getContent: function (p, schema) {+ getContent(p, schema) {// search the matched element for a TeX string- var match = matchWikipedia(p);+ let match = matchWikipedia(p);// return a fragment representing the math node's children- var texString = match || "\\text{\\color{red}(paste error)}";+ let texString = match || "\\text{\\color{red}(paste error)}";return makeTextFragment(texString, schema);},};diff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-select.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-select.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/plugins/math-select.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-select.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/plugins/math-select.js b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-select.jssimilarity index 72%rename from packages/editor/dist/extensions/math/plugin/plugins/math-select.jsrename to packages/editor/dist/cjs/extensions/math/plugin/plugins/math-select.jsindex 68ad02e4a..1a212d909 100644--- a/packages/editor/dist/extensions/math/plugin/plugins/math-select.js+++ b/packages/editor/dist/cjs/extensions/math/plugin/plugins/math-select.js@@ -6,8 +6,8 @@Object.defineProperty(exports, "__esModule", { value: true });exports.mathSelectPlugin = void 0;// prosemirror imports-var prosemirror_state_1 = require("prosemirror-state");-var prosemirror_view_1 = require("prosemirror-view");+const prosemirror_state_1 = require("prosemirror-state");+const prosemirror_view_1 = require("prosemirror-view");/////////////////////////////////////////////////////////////*** Uses the selection to determine which math_select decorations@@ -15,11 +15,11 @@ var prosemirror_view_1 = require("prosemirror-view");* @param arg Should be either a Transaction or an EditorState,* although any object with `selection` and `doc` will work.*/-var checkSelection = function (arg) {- var _a = arg.selection, from = _a.from, to = _a.to;- var content = arg.selection.content().content;- var result = [];- content.descendants(function (node, pos, parent) {+const checkSelection = (arg) => {+ let { from, to } = arg.selection;+ let content = arg.selection.content().content;+ let result = [];+ content.descendants((node, pos, parent) => {if (node.type.name == "text") {return false;}@@ -32,10 +32,7 @@ var checkSelection = function (arg) {}return true;});- return prosemirror_view_1.DecorationSet.create(arg.doc, result.map(function (_a) {- var start = _a.start, end = _a.end;- return prosemirror_view_1.Decoration.node(start, end, { class: "math-select" });- }));+ return prosemirror_view_1.DecorationSet.create(arg.doc, result.map(({ start, end }) => prosemirror_view_1.Decoration.node(start, end, { class: "math-select" })));};/*** Due to the internals of KaTeX, by default, selecting rendered@@ -49,19 +46,19 @@ var checkSelection = function (arg) {*/exports.mathSelectPlugin = new prosemirror_state_1.Plugin({state: {- init: function (config, partialState) {+ init(config, partialState) {return checkSelection(partialState);},- apply: function (tr, value, oldState, newState) {+ apply(tr, value, oldState, newState) {if (!tr.selection || !tr.selectionSet) {return oldState;}- var sel = checkSelection(tr);+ let sel = checkSelection(tr);return sel;},},props: {- decorations: function (state) {+ decorations: (state) => {return exports.mathSelectPlugin.getState(state);},},diff --git a/packages/editor/dist/extensions/math/plugin/renderers/katex.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/renderers/katex.d.tssimilarity index 70%rename from packages/editor/dist/extensions/math/plugin/renderers/katex.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/renderers/katex.d.tsindex 5a0ac882a..0b716cff8 100644--- a/packages/editor/dist/extensions/math/plugin/renderers/katex.d.ts+++ b/packages/editor/dist/cjs/extensions/math/plugin/renderers/katex.d.ts@@ -1,3 +1,2 @@import { MathRenderer } from "./types";-import "katex/contrib/mhchem/mhchem";export declare const KatexRenderer: MathRenderer;diff --git a/packages/editor/dist/cjs/extensions/math/plugin/renderers/katex.js b/packages/editor/dist/cjs/extensions/math/plugin/renderers/katex.jsnew file mode 100644index 000000000..db876e50c--- /dev/null+++ b/packages/editor/dist/cjs/extensions/math/plugin/renderers/katex.js@@ -0,0 +1,65 @@+"use strict";+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ var desc = Object.getOwnPropertyDescriptor(m, k);+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {+ desc = { enumerable: true, get: function() { return m[k]; } };+ }+ Object.defineProperty(o, k2, desc);+}) : (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ o[k2] = m[k];+}));+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {+ Object.defineProperty(o, "default", { enumerable: true, value: v });+}) : function(o, v) {+ o["default"] = v;+});+var __importStar = (this && this.__importStar) || function (mod) {+ if (mod && mod.__esModule) return mod;+ var result = {};+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);+ __setModuleDefault(result, mod);+ return result;+};+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.KatexRenderer = void 0;+function loadKatex() {+ return __awaiter(this, void 0, void 0, function* () {+ // @ts-ignore+ const { default: katex } = yield Promise.resolve().then(() => __importStar(require("katex")));+ // Chemistry formulas support+ // @ts-ignore+ yield Promise.resolve().then(() => __importStar(require("katex/contrib/mhchem/mhchem")));+ return katex;+ });+}+exports.KatexRenderer = {+ inline: (text, element) => {+ loadKatex().then((katex) => {+ katex.render(text, element, {+ displayMode: false,+ globalGroup: true,+ throwOnError: false,+ });+ });+ },+ block: (text, element) => {+ loadKatex().then((katex) => {+ katex.render(text, element, {+ displayMode: true,+ globalGroup: true,+ throwOnError: false,+ });+ });+ },+};diff --git a/packages/editor/dist/extensions/math/plugin/renderers/types.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/renderers/types.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/renderers/types.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/renderers/types.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/renderers/types.js b/packages/editor/dist/cjs/extensions/math/plugin/renderers/types.jssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/renderers/types.jsrename to packages/editor/dist/cjs/extensions/math/plugin/renderers/types.jsdiff --git a/packages/editor/dist/extensions/math/plugin/utils/text-serializer.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/utils/text-serializer.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/utils/text-serializer.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/utils/text-serializer.d.tsdiff --git a/packages/editor/dist/cjs/extensions/math/plugin/utils/text-serializer.js b/packages/editor/dist/cjs/extensions/math/plugin/utils/text-serializer.jsnew file mode 100644index 000000000..79f089921--- /dev/null+++ b/packages/editor/dist/cjs/extensions/math/plugin/utils/text-serializer.js@@ -0,0 +1,61 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.mathSerializer = void 0;+class ProseMirrorTextSerializer {+ constructor(fns, base) {+ // use base serializer as a fallback+ this.nodes = Object.assign(Object.assign({}, base === null || base === void 0 ? void 0 : base.nodes), fns.nodes);+ this.marks = Object.assign(Object.assign({}, base === null || base === void 0 ? void 0 : base.marks), fns.marks);+ }+ serializeFragment(fragment) {+ // adapted from the undocumented `Fragment.textBetween` function+ // https://github.com/ProseMirror/prosemirror-model/blob/eef20c8c6dbf841b1d70859df5d59c21b5108a4f/src/fragment.js#L46+ let blockSeparator = "\n\n";+ let leafText = undefined;+ let text = "";+ let separated = true;+ let from = 0;+ let to = fragment.size;+ fragment.nodesBetween(from, to, (node, pos) => {+ var _a;+ // check if one of our custom serializers handles this node+ let serialized = this.serializeNode(node);+ if (serialized !== null) {+ text += serialized;+ return false;+ }+ if (node.isText) {+ text += ((_a = node.text) === null || _a === void 0 ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos)) || "";+ separated = !blockSeparator;+ }+ else if (node.isLeaf && leafText) {+ text += leafText;+ separated = !blockSeparator;+ }+ else if (!separated && node.isBlock) {+ text += blockSeparator;+ separated = true;+ }+ }, 0);+ return text;+ }+ serializeSlice(slice) {+ return this.serializeFragment(slice.content);+ }+ serializeNode(node) {+ // check if one of our custom serializers handles this node+ let nodeSerializer = this.nodes[node.type.name];+ if (nodeSerializer !== undefined) {+ return nodeSerializer(node);+ }+ else {+ return null;+ }+ }+}+exports.mathSerializer = new ProseMirrorTextSerializer({+ nodes: {+ math_inline: (node) => `$${node.textContent}$`,+ math_display: (node) => `\n\n$$\n${node.textContent}\n$$`,+ },+});diff --git a/packages/editor/dist/extensions/math/plugin/utils/types.d.ts b/packages/editor/dist/cjs/extensions/math/plugin/utils/types.d.tssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/utils/types.d.tsrename to packages/editor/dist/cjs/extensions/math/plugin/utils/types.d.tsdiff --git a/packages/editor/dist/extensions/math/plugin/utils/types.js b/packages/editor/dist/cjs/extensions/math/plugin/utils/types.jssimilarity index 100%rename from packages/editor/dist/extensions/math/plugin/utils/types.jsrename to packages/editor/dist/cjs/extensions/math/plugin/utils/types.jsdiff --git a/packages/editor/dist/extensions/orderedlist/index.d.ts b/packages/editor/dist/cjs/extensions/orderedlist/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/orderedlist/index.d.tsrename to packages/editor/dist/cjs/extensions/orderedlist/index.d.tsdiff --git a/packages/editor/dist/extensions/orderedlist/index.js b/packages/editor/dist/cjs/extensions/orderedlist/index.jssimilarity index 94%rename from packages/editor/dist/extensions/orderedlist/index.jsrename to packages/editor/dist/cjs/extensions/orderedlist/index.jsindex 868ebaf66..c06028c9a 100644--- a/packages/editor/dist/extensions/orderedlist/index.js+++ b/packages/editor/dist/cjs/extensions/orderedlist/index.js@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);};Object.defineProperty(exports, "__esModule", { value: true });-var orderedlist_1 = require("./orderedlist");+const orderedlist_1 = require("./orderedlist");__exportStar(require("./orderedlist"), exports);exports.default = orderedlist_1.OrderedList;diff --git a/packages/editor/dist/extensions/orderedlist/orderedlist.d.ts b/packages/editor/dist/cjs/extensions/orderedlist/orderedlist.d.tssimilarity index 100%rename from packages/editor/dist/extensions/orderedlist/orderedlist.d.tsrename to packages/editor/dist/cjs/extensions/orderedlist/orderedlist.d.tsdiff --git a/packages/editor/dist/extensions/orderedlist/orderedlist.js b/packages/editor/dist/cjs/extensions/orderedlist/orderedlist.jssimilarity index 63%rename from packages/editor/dist/extensions/orderedlist/orderedlist.jsrename to packages/editor/dist/cjs/extensions/orderedlist/orderedlist.jsindex e39e7ff00..f43da163c 100644--- a/packages/editor/dist/extensions/orderedlist/orderedlist.js+++ b/packages/editor/dist/cjs/extensions/orderedlist/orderedlist.js@@ -4,19 +4,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {};Object.defineProperty(exports, "__esModule", { value: true });exports.OrderedList = void 0;-var extension_ordered_list_1 = __importDefault(require("@tiptap/extension-ordered-list"));+const extension_ordered_list_1 = __importDefault(require("@tiptap/extension-ordered-list"));exports.OrderedList = extension_ordered_list_1.default.extend({- addAttributes: function () {+ addAttributes() {return {listType: {default: null,- parseHTML: function (element) { return element.style.listStyleType; },- renderHTML: function (attributes) {+ parseHTML: (element) => element.style.listStyleType,+ renderHTML: (attributes) => {if (!attributes.listType) {return {};}return {- style: "list-style-type: ".concat(attributes.listType),+ style: `list-style-type: ${attributes.listType}`,};},},diff --git a/packages/editor/dist/extensions/outlinelist/component.d.ts b/packages/editor/dist/cjs/extensions/outlinelist/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/outlinelist/component.d.tsrename to packages/editor/dist/cjs/extensions/outlinelist/component.d.tsdiff --git a/packages/editor/dist/extensions/outlinelist/component.js b/packages/editor/dist/cjs/extensions/outlinelist/component.jssimilarity index 64%rename from packages/editor/dist/extensions/outlinelist/component.jsrename to packages/editor/dist/cjs/extensions/outlinelist/component.jsindex a35c5e882..2c26f7202 100644--- a/packages/editor/dist/extensions/outlinelist/component.js+++ b/packages/editor/dist/cjs/extensions/outlinelist/component.js@@ -1,16 +1,16 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.OutlineListComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("react");-var outlinelistitem_1 = require("../outlinelistitem");+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("react");+const outlinelistitem_1 = require("../outlinelistitem");function OutlineListComponent(props) {- var editor = props.editor, getPos = props.getPos, node = props.node, updateAttributes = props.updateAttributes, forwardRef = props.forwardRef;- var collapsed = node.attrs.collapsed;- var isNested = (0, react_1.useMemo)(function () {+ const { editor, getPos, node, updateAttributes, forwardRef } = props;+ const { collapsed } = node.attrs;+ const isNested = (0, react_1.useMemo)(() => {var _a;- var pos = editor.state.doc.resolve(getPos());+ const pos = editor.state.doc.resolve(getPos());return ((_a = pos.parent) === null || _a === void 0 ? void 0 : _a.type.name) === outlinelistitem_1.OutlineListItem.name;}, []);return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(rebass_1.Text, { className: "outline-list", as: "div", ref: forwardRef, sx: {diff --git a/packages/editor/dist/extensions/outlinelist/index.d.ts b/packages/editor/dist/cjs/extensions/outlinelist/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/outlinelist/index.d.tsrename to packages/editor/dist/cjs/extensions/outlinelist/index.d.tsdiff --git a/packages/editor/dist/extensions/outlinelist/index.js b/packages/editor/dist/cjs/extensions/outlinelist/index.jssimilarity index 100%rename from packages/editor/dist/extensions/outlinelist/index.jsrename to packages/editor/dist/cjs/extensions/outlinelist/index.jsdiff --git a/packages/editor/dist/extensions/outlinelist/outlinelist.d.ts b/packages/editor/dist/cjs/extensions/outlinelist/outlinelist.d.tssimilarity index 100%rename from packages/editor/dist/extensions/outlinelist/outlinelist.d.tsrename to packages/editor/dist/cjs/extensions/outlinelist/outlinelist.d.tsdiff --git a/packages/editor/dist/cjs/extensions/outlinelist/outlinelist.js b/packages/editor/dist/cjs/extensions/outlinelist/outlinelist.jsnew file mode 100644index 000000000..f1221b053--- /dev/null+++ b/packages/editor/dist/cjs/extensions/outlinelist/outlinelist.js@@ -0,0 +1,77 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.OutlineList = exports.inputRegex = void 0;+const core_1 = require("@tiptap/core");+const react_1 = require("../react");+const component_1 = require("./component");+exports.inputRegex = /^\s*(-o)\s$/;+const outlineListItemName = `outlineListItem`;+exports.OutlineList = core_1.Node.create({+ name: "outlineList",+ addOptions() {+ return {+ HTMLAttributes: {},+ };+ },+ addAttributes() {+ return {+ collapsed: {+ default: false,+ keepOnSplit: false,+ parseHTML: (element) => element.dataset.collapsed === "true",+ renderHTML: (attributes) => ({+ "data-collapsed": attributes.collapsed === true,+ }),+ },+ };+ },+ group: "block list",+ content: `${outlineListItemName}+`,+ parseHTML() {+ return [+ {+ tag: `ul[data-type="${this.name}"]`,+ priority: 52,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "ul",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {+ "data-type": this.name,+ }),+ 0,+ ];+ },+ addCommands() {+ return {+ toggleOutlineList: () => ({ commands }) => {+ return commands.toggleList(this.name, outlineListItemName);+ },+ };+ },+ addKeyboardShortcuts() {+ return {+ "Mod-Shift-O": () => this.editor.commands.toggleOutlineList(),+ };+ },+ addInputRules() {+ return [+ (0, core_1.wrappingInputRule)({+ find: exports.inputRegex,+ type: this.type,+ }),+ ];+ },+ addNodeView() {+ return (0, react_1.createNodeView)(component_1.OutlineListComponent, {+ contentDOMFactory: () => {+ const content = document.createElement("ul");+ content.classList.add(`${this.name.toLowerCase()}-content-wrapper`);+ content.style.whiteSpace = "inherit";+ return { dom: content };+ },+ });+ },+});diff --git a/packages/editor/dist/extensions/outlinelistitem/component.d.ts b/packages/editor/dist/cjs/extensions/outlinelistitem/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/outlinelistitem/component.d.tsrename to packages/editor/dist/cjs/extensions/outlinelistitem/component.d.tsdiff --git a/packages/editor/dist/extensions/outlinelistitem/component.js b/packages/editor/dist/cjs/extensions/outlinelistitem/component.jssimilarity index 51%rename from packages/editor/dist/extensions/outlinelistitem/component.jsrename to packages/editor/dist/cjs/extensions/outlinelistitem/component.jsindex 0eca89271..62f767bad 100644--- a/packages/editor/dist/extensions/outlinelistitem/component.js+++ b/packages/editor/dist/cjs/extensions/outlinelistitem/component.js@@ -1,45 +1,18 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};Object.defineProperty(exports, "__esModule", { value: true });exports.OutlineListItemComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var core_1 = require("@tiptap/core");-var outlinelist_1 = require("../outline-list/outlinelist");+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const core_1 = require("@tiptap/core");+const outlinelist_1 = require("../outline-list/outlinelist");function OutlineListItemComponent(props) {var _a, _b;- var editor = props.editor, updateAttributes = props.updateAttributes, node = props.node, getPos = props.getPos, forwardRef = props.forwardRef;- var isNested = ((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.type.name) === outlinelist_1.OutlineList.name;- var isCollapsed = isNested && ((_b = node.lastChild) === null || _b === void 0 ? void 0 : _b.attrs.collapsed);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ className: "outline", sx: {+ const { editor, updateAttributes, node, getPos, forwardRef } = props;+ const isNested = ((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.type.name) === outlinelist_1.OutlineList.name;+ const isCollapsed = isNested && ((_b = node.lastChild) === null || _b === void 0 ? void 0 : _b.attrs.collapsed);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ className: "outline", sx: {flexDirection: "column",alignItems: "center",mt: "3px",@@ -47,18 +20,18 @@ function OutlineListItemComponent(props) {? "Click to uncollapse list": "Click to collapse list", sx: {cursor: "pointer",- transition: "all .2s ease-in-out",+ transition: `all .2s ease-in-out`,":hover": {transform: "scale(1.3)",},".icon:hover path": {fill: "var(--checked) !important",},- }, size: 18, onMouseDown: function (e) { return e.preventDefault(); }, onClick: function () {- var _a = __read((0, core_1.findChildren)(node, function (node) { return node.type.name === outlinelist_1.OutlineList.name; }), 1), subList = _a[0];+ }, size: 18, onMouseDown: (e) => e.preventDefault(), onClick: () => {+ const [subList] = (0, core_1.findChildren)(node, (node) => node.type.name === outlinelist_1.OutlineList.name);if (!subList)return;- var pos = subList.pos;+ const { pos } = subList;editor.commands.toggleOutlineCollapse(pos + getPos() + 1, !isCollapsed);} })) : ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.circle, size: 18, sx: { transform: "scale(0.4)" } })), isNested && !isCollapsed && ((0, jsx_runtime_1.jsx)(rebass_1.Box, { sx: {flex: 1,@@ -68,7 +41,7 @@ function OutlineListItemComponent(props) {borderRadius: 50,flexShrink: 0,cursor: "pointer",- transition: "all .2s ease-in-out",+ transition: `all .2s ease-in-out`,":hover": {backgroundColor: "fontTertiary",width: 4,diff --git a/packages/editor/dist/extensions/outlinelistitem/index.d.ts b/packages/editor/dist/cjs/extensions/outlinelistitem/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/outlinelistitem/index.d.tsrename to packages/editor/dist/cjs/extensions/outlinelistitem/index.d.tsdiff --git a/packages/editor/dist/extensions/outlinelistitem/index.js b/packages/editor/dist/cjs/extensions/outlinelistitem/index.jssimilarity index 100%rename from packages/editor/dist/extensions/outlinelistitem/index.jsrename to packages/editor/dist/cjs/extensions/outlinelistitem/index.jsdiff --git a/packages/editor/dist/extensions/outlinelistitem/outlinelistitem.d.ts b/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.d.tssimilarity index 100%rename from packages/editor/dist/extensions/outlinelistitem/outlinelistitem.d.tsrename to packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.d.tsdiff --git a/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.js b/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.jsnew file mode 100644index 000000000..737c5dc40--- /dev/null+++ b/packages/editor/dist/cjs/extensions/outlinelistitem/outlinelistitem.js@@ -0,0 +1,103 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.OutlineListItem = void 0;+const core_1 = require("@tiptap/core");+const prosemirror_utils_1 = require("prosemirror-utils");+const commands_1 = require("../list-item/commands");+const outlinelist_1 = require("../outline-list/outlinelist");+const react_1 = require("../react");+const component_1 = require("./component");+exports.OutlineListItem = core_1.Node.create({+ name: "outlineListItem",+ addOptions() {+ return {+ HTMLAttributes: {},+ };+ },+ content: "heading* block*",+ defining: true,+ parseHTML() {+ return [+ {+ tag: `li[data-type="${this.name}"]`,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "li",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {+ "data-type": this.name,+ }),+ 0,+ ];+ },+ addKeyboardShortcuts() {+ return {+ "Mod-Space": ({ editor }) => {+ const subList = findSublist(editor, this.type);+ if (!subList)+ return false;+ const { isCollapsed, subListPos } = subList;+ return this.editor.commands.toggleOutlineCollapse(subListPos, !isCollapsed);+ },+ Enter: ({ editor }) => {+ const subList = findSublist(editor, this.type);+ if (!subList)+ return false;+ const { isCollapsed, subListPos } = subList;+ if (isCollapsed) {+ return this.editor.commands.toggleOutlineCollapse(subListPos, false);+ }+ return this.editor.commands.splitListItem(this.name);+ },+ Tab: () => this.editor.commands.sinkListItem(this.name),+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name),+ Backspace: ({ editor }) => (0, commands_1.onBackspacePressed)(editor, this.name, this.type),+ };+ },+ addCommands() {+ return {+ toggleOutlineCollapse: (pos, state) => ({ tr }) => {+ tr.setNodeMarkup(pos, undefined, {+ collapsed: state,+ });+ return true;+ },+ };+ },+ addNodeView() {+ return (0, react_1.createNodeView)(component_1.OutlineListItemComponent, {+ contentDOMFactory: true,+ // wrapperFactory: () => document.createElement("li"),+ });+ },+});+function findSublist(editor, type) {+ var _a, _b;+ const { selection } = editor.state;+ const { $from } = selection;+ const listItem = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($from, type);+ if (!listItem)+ return false;+ const [subList] = (0, core_1.findChildren)(listItem.node, (node) => node.type.name === outlinelist_1.OutlineList.name);+ if (!subList)+ return false;+ const isNested = ((_a = subList === null || subList === void 0 ? void 0 : subList.node) === null || _a === void 0 ? void 0 : _a.type.name) === outlinelist_1.OutlineList.name;+ const isCollapsed = (_b = subList === null || subList === void 0 ? void 0 : subList.node) === null || _b === void 0 ? void 0 : _b.attrs.collapsed;+ const subListPos = listItem.pos + subList.pos + 1;+ return { isCollapsed, isNested, subListPos };+ // return (+ // this.editor+ // .chain()+ // .command(({ tr }) => {+ // tr.setNodeMarkup(listItem.pos + subList.pos + 1, undefined, {+ // collapsed: !isCollapsed,+ // });+ // return true;+ // })+ // //.setTextSelection(listItem.pos + subList.pos + 1)+ // //.splitListItem(this.name)+ // .run()+ // );+}diff --git a/packages/editor/dist/extensions/react/eventdispatcher.d.ts b/packages/editor/dist/cjs/extensions/react/eventdispatcher.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/eventdispatcher.d.tsrename to packages/editor/dist/cjs/extensions/react/eventdispatcher.d.tsdiff --git a/packages/editor/dist/extensions/react/eventdispatcher.js b/packages/editor/dist/cjs/extensions/react/eventdispatcher.jssimilarity index 65%rename from packages/editor/dist/extensions/react/eventdispatcher.jsrename to packages/editor/dist/cjs/extensions/react/eventdispatcher.jsindex a1f9b8311..eb0bb40f3 100644--- a/packages/editor/dist/extensions/react/eventdispatcher.js+++ b/packages/editor/dist/cjs/extensions/react/eventdispatcher.js@@ -1,46 +1,45 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.createDispatch = exports.EventDispatcher = void 0;-var EventDispatcher = /** @class */ (function () {- function EventDispatcher() {+class EventDispatcher {+ constructor() {this.listeners = {};}- EventDispatcher.prototype.on = function (event, cb) {+ on(event, cb) {if (!this.listeners[event]) {this.listeners[event] = new Set();}this.listeners[event].add(cb);- };- EventDispatcher.prototype.off = function (event, cb) {+ }+ off(event, cb) {if (!this.listeners[event]) {return;}if (this.listeners[event].has(cb)) {this.listeners[event].delete(cb);}- };- EventDispatcher.prototype.emit = function (event, data) {+ }+ emit(event, data) {if (!this.listeners[event]) {return;}- this.listeners[event].forEach(function (cb) { return cb(data); });- };- EventDispatcher.prototype.destroy = function () {+ this.listeners[event].forEach((cb) => cb(data));+ }+ destroy() {this.listeners = {};- };- return EventDispatcher;-}());+ }+}exports.EventDispatcher = EventDispatcher;/*** Creates a dispatch function that can be called inside ProseMirror Plugin* to notify listeners about that plugin's state change.*/function createDispatch(eventDispatcher) {- return function (eventName, data) {+ return (eventName, data) => {if (!eventName) {throw new Error("event name is required!");}- var event = typeof eventName === "string"+ const event = typeof eventName === "string"? eventName: eventName.key;eventDispatcher.emit(event, data);diff --git a/packages/editor/dist/extensions/react/index.d.ts b/packages/editor/dist/cjs/extensions/react/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/index.d.tsrename to packages/editor/dist/cjs/extensions/react/index.d.tsdiff --git a/packages/editor/dist/extensions/react/index.js b/packages/editor/dist/cjs/extensions/react/index.jssimilarity index 100%rename from packages/editor/dist/extensions/react/index.jsrename to packages/editor/dist/cjs/extensions/react/index.jsdiff --git a/packages/editor/dist/extensions/react/plugin.d.ts b/packages/editor/dist/cjs/extensions/react/plugin.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/plugin.d.tsrename to packages/editor/dist/cjs/extensions/react/plugin.d.tsdiff --git a/packages/editor/dist/cjs/extensions/react/plugin.js b/packages/editor/dist/cjs/extensions/react/plugin.jsnew file mode 100644index 000000000..33e068e6e--- /dev/null+++ b/packages/editor/dist/cjs/extensions/react/plugin.js@@ -0,0 +1,47 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.NodeViewSelectionNotifier = exports.NodeViewSelectionNotifierPlugin = exports.stateKey = exports.ReactNodeViewState = void 0;+const prosemirror_state_1 = require("prosemirror-state");+const core_1 = require("@tiptap/core");+class ReactNodeViewState {+ constructor() {+ this.changeHandlers = [];+ this.changeHandlers = [];+ }+ subscribe(cb) {+ this.changeHandlers.push(cb);+ }+ unsubscribe(cb) {+ this.changeHandlers = this.changeHandlers.filter((ch) => ch !== cb);+ }+ notifyNewSelection(fromPos, toPos) {+ this.changeHandlers.forEach((cb) => cb(fromPos, toPos));+ }+}+exports.ReactNodeViewState = ReactNodeViewState;+exports.stateKey = new prosemirror_state_1.PluginKey("reactNodeView");+exports.NodeViewSelectionNotifierPlugin = new prosemirror_state_1.Plugin({+ state: {+ init() {+ return new ReactNodeViewState();+ },+ apply(_tr, pluginState) {+ return pluginState;+ },+ },+ key: exports.stateKey,+ view: (view) => {+ const pluginState = exports.stateKey.getState(view.state);+ return {+ update: (view) => {+ const { from, to } = view.state.selection;+ pluginState.notifyNewSelection(from, to);+ },+ };+ },+});+exports.NodeViewSelectionNotifier = core_1.Extension.create({+ addProseMirrorPlugins() {+ return [exports.NodeViewSelectionNotifierPlugin];+ },+});diff --git a/packages/editor/dist/extensions/react/reactnodeview.d.ts b/packages/editor/dist/cjs/extensions/react/reactnodeview.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/reactnodeview.d.tsrename to packages/editor/dist/cjs/extensions/react/reactnodeview.d.tsdiff --git a/packages/editor/dist/extensions/react/reactnodeview.js b/packages/editor/dist/cjs/extensions/react/reactnodeview.jssimilarity index 56%rename from packages/editor/dist/extensions/react/reactnodeview.jsrename to packages/editor/dist/cjs/extensions/react/reactnodeview.jsindex 29e66fff7..f1747fd31 100644--- a/packages/editor/dist/extensions/react/reactnodeview.js+++ b/packages/editor/dist/cjs/extensions/react/reactnodeview.js@@ -1,55 +1,18 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};Object.defineProperty(exports, "__esModule", { value: true });exports.createNodeView = exports.ReactNodeView = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var prosemirror_state_1 = require("prosemirror-state");-var emotion_theming_1 = require("emotion-theming");+const jsx_runtime_1 = require("react/jsx-runtime");+const prosemirror_state_1 = require("prosemirror-state");+const emotion_theming_1 = require("emotion-theming");// @ts-ignore-var prosemirror_view_1 = require("prosemirror-view");-var ReactNodeView = /** @class */ (function () {- function ReactNodeView(node, editor, getPos, options) {- var _this = this;+const prosemirror_view_1 = require("prosemirror-view");+class ReactNodeView {+ constructor(node, editor, getPos, options) {this.editor = editor;this.getPos = getPos;this.options = options;this.isDragging = false;- this.handleRef = function (node) { return _this._handleRef(node); };+ this.handleRef = (node) => this._handleRef(node);this.portalProviderAPI = editor.storage.portalProviderAPI;this.node = node;@@ -63,15 +26,14 @@ var ReactNodeView = /** @class */ (function () {* constructor, which leads to some methods being undefined during the* first render.*/- ReactNodeView.prototype.init = function () {- var _this = this;+ init() {this.domRef = this.createDomRef();- this.domRef.ondragstart = function (ev) { return _this.onDragStart(ev); };+ this.domRef.ondragstart = (ev) => this.onDragStart(ev);// this.setDomAttrs(this.node, this.domRef);- var _a = this.getContentDOM() || {+ const { dom: contentDOMWrapper, contentDOM } = this.getContentDOM() || {dom: undefined,contentDOM: undefined,- }, contentDOMWrapper = _a.dom, contentDOM = _a.contentDOM;+ };if (this.domRef && contentDOMWrapper) {this.domRef.appendChild(contentDOMWrapper);this.contentDOM = contentDOM ? contentDOM : contentDOMWrapper;@@ -81,73 +43,66 @@ var ReactNodeView = /** @class */ (function () {// something gets messed up during mutation processing inside of a// nodeView if DOM structure has nested plain "div"s, it doesn't see the// difference between them and it kills the nodeView- this.domRef.classList.add("".concat(this.node.type.name, "-view-content-wrap"));- this.renderReactComponent(function () {- return _this.render(_this.options.props, _this.handleRef);- });+ this.domRef.classList.add(`${this.node.type.name}-view-content-wrap`);+ this.renderReactComponent(() => this.render(this.options.props, this.handleRef));return this;- };- ReactNodeView.prototype.renderReactComponent = function (component) {+ }+ renderReactComponent(component) {if (!this.domRef || !component || !this.portalProviderAPI) {console.warn("Cannot render node view", this.editor.storage);return;}this.portalProviderAPI.render(component, this.domRef);- };- ReactNodeView.prototype.createDomRef = function () {+ }+ createDomRef() {if (this.options.wrapperFactory)return this.options.wrapperFactory();if (!this.node.isInline) {return document.createElement("div");}- var htmlElement = document.createElement("span");+ const htmlElement = document.createElement("span");return htmlElement;- };- ReactNodeView.prototype.getContentDOM = function () {+ }+ getContentDOM() {var _a, _b;if (!this.options.contentDOMFactory)return;if (this.options.contentDOMFactory === true) {- var content = document.createElement("div");- content.classList.add("".concat(this.node.type.name.toLowerCase(), "-content-wrapper"));+ const content = document.createElement("div");+ content.classList.add(`${this.node.type.name.toLowerCase()}-content-wrapper`);content.style.whiteSpace = "inherit";// caret is not visible if content element width is 0px- content.style.minWidth = "20px";+ content.style.minWidth = `20px`;return { dom: content };}return (_b = (_a = this.options).contentDOMFactory) === null || _b === void 0 ? void 0 : _b.call(_a);- };- ReactNodeView.prototype._handleRef = function (node) {- var contentDOM = this.contentDOMWrapper || this.contentDOM;+ }+ _handleRef(node) {+ const contentDOM = this.contentDOMWrapper || this.contentDOM;// move the contentDOM node inside the inner reference after renderingif (node && contentDOM && !node.contains(contentDOM)) {node.appendChild(contentDOM);}- };- ReactNodeView.prototype.render = function (props, forwardRef) {- var _this = this;- if (props === void 0) { props = {}; }+ }+ render(props = {}, forwardRef) {if (!this.options.component)return null;- var theme = this.editor.storage.theme;- var pos = this.getPos();- return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, __assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(this.options.component, __assign({}, props, { editor: this.editor, getPos: this.getPos, node: this.node, forwardRef: forwardRef, updateAttributes: function (attr) { return _this.updateAttributes(attr, pos); } })) })));- };- ReactNodeView.prototype.updateAttributes = function (attributes, pos) {- var _this = this;- this.editor.commands.command(function (_a) {- var tr = _a.tr;- tr.setNodeMarkup(pos, undefined, __assign(__assign({}, _this.node.attrs), attributes));+ const theme = this.editor.storage.theme;+ const pos = this.getPos();+ return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, Object.assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(this.options.component, Object.assign({}, props, { editor: this.editor, getPos: this.getPos, node: this.node, forwardRef: forwardRef, updateAttributes: (attr) => this.updateAttributes(attr, pos) })) })));+ }+ updateAttributes(attributes, pos) {+ this.editor.commands.command(({ tr }) => {+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), attributes));return true;});- };- ReactNodeView.prototype.update = function (node, _decorations, _innerDecorations+ }+ update(node, _decorations, _innerDecorations// _innerDecorations?: Array<Decoration>,// validUpdate: (currentNode: PMNode, newNode: PMNode) => boolean = () => true) {- var _this = this;// @see https://github.com/ProseMirror/prosemirror/issues/648- var isValidUpdate = this.node.type === node.type; // && validUpdate(this.node, node);+ const isValidUpdate = this.node.type === node.type; // && validUpdate(this.node, node);if (!isValidUpdate) {return false;}@@ -161,46 +116,43 @@ var ReactNodeView = /** @class */ (function () {return true;}this.node = node;- this.renderReactComponent(function () {- return _this.render(_this.options.props, _this.handleRef);- });+ this.renderReactComponent(() => this.render(this.options.props, this.handleRef));return true;- };- ReactNodeView.prototype.onDragStart = function (event) {+ }+ onDragStart(event) {var _a, _b, _c, _d, _e, _f, _g;- var view = this.editor.view;- var target = event.target;+ const { view } = this.editor;+ const target = event.target;// get the drag handle element// `closest` is not available for text nodes so we may have to use its parent- var dragHandle = target.nodeType === 3+ const dragHandle = target.nodeType === 3? (_a = target.parentElement) === null || _a === void 0 ? void 0 : _a.closest("[data-drag-handle]"): target.closest("[data-drag-handle]");if (!this.dom || ((_b = this.contentDOM) === null || _b === void 0 ? void 0 : _b.contains(target)) || !dragHandle) {return;}- var dragImage = this.dom.querySelector("[data-drag-image]") || this.dom;- var x = 0;- var y = 0;+ const dragImage = this.dom.querySelector("[data-drag-image]") || this.dom;+ let x = 0;+ let y = 0;// calculate offset for drag element if we use a different drag handle elementif (dragImage !== dragHandle) {- var domBox = dragImage.getBoundingClientRect();- var handleBox = dragHandle.getBoundingClientRect();+ const domBox = dragImage.getBoundingClientRect();+ const handleBox = dragHandle.getBoundingClientRect();// In React, we have to go through nativeEvent to reach offsetX/offsetY.- var offsetX = (_c = event.offsetX) !== null && _c !== void 0 ? _c : (_d = event.nativeEvent) === null || _d === void 0 ? void 0 : _d.offsetX;- var offsetY = (_e = event.offsetY) !== null && _e !== void 0 ? _e : (_f = event.nativeEvent) === null || _f === void 0 ? void 0 : _f.offsetY;+ const offsetX = (_c = event.offsetX) !== null && _c !== void 0 ? _c : (_d = event.nativeEvent) === null || _d === void 0 ? void 0 : _d.offsetX;+ const offsetY = (_e = event.offsetY) !== null && _e !== void 0 ? _e : (_f = event.nativeEvent) === null || _f === void 0 ? void 0 : _f.offsetY;x = handleBox.x - domBox.x + offsetX;y = handleBox.y - domBox.y + offsetY;}// we need to tell ProseMirror that we want to move the whole node// so we create a NodeSelection- var selection = prosemirror_state_1.NodeSelection.create(view.state.doc, this.getPos());- var transaction = view.state.tr.setSelection(selection);+ const selection = prosemirror_state_1.NodeSelection.create(view.state.doc, this.getPos());+ const transaction = view.state.tr.setSelection(selection);view.dispatch(transaction);(_g = event.dataTransfer) === null || _g === void 0 ? void 0 : _g.setDragImage(dragImage, x, y);forceHandleDrag(event, this.editor);- };- ReactNodeView.prototype.stopEvent = function (event) {- var _this = this;+ }+ stopEvent(event) {var _a;if (!this.dom) {return false;@@ -208,28 +160,28 @@ var ReactNodeView = /** @class */ (function () {// if (typeof this.options.stopEvent === 'function') {// return this.options.stopEvent({ event })// }- var target = event.target;- var isInElement = this.dom.contains(target) && !((_a = this.contentDOM) === null || _a === void 0 ? void 0 : _a.contains(target));+ const target = event.target;+ const isInElement = this.dom.contains(target) && !((_a = this.contentDOM) === null || _a === void 0 ? void 0 : _a.contains(target));// any event from child nodes should be handled by ProseMirrorif (!isInElement) {return false;}- var isDropEvent = event.type === "drop";- var isInput = ["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(target.tagName) ||+ const isDropEvent = event.type === "drop";+ const isInput = ["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(target.tagName) ||target.isContentEditable;// any input event within node views should be ignored by ProseMirrorif (isInput && !isDropEvent) {return true;}- var isEditable = this.editor.isEditable;- var isDragging = this.isDragging;- var isDraggable = !!this.node.type.spec.draggable;- var isSelectable = prosemirror_state_1.NodeSelection.isSelectable(this.node);- var isCopyEvent = event.type === "copy";- var isPasteEvent = event.type === "paste";- var isCutEvent = event.type === "cut";- var isClickEvent = event.type === "mousedown";- var isDragEvent = event.type.startsWith("drag");+ const { isEditable } = this.editor;+ const { isDragging } = this;+ const isDraggable = !!this.node.type.spec.draggable;+ const isSelectable = prosemirror_state_1.NodeSelection.isSelectable(this.node);+ const isCopyEvent = event.type === "copy";+ const isPasteEvent = event.type === "paste";+ const isCutEvent = event.type === "cut";+ const isClickEvent = event.type === "mousedown";+ const isDragEvent = event.type.startsWith("drag");// if (event instanceof DragEvent && event.dataTransfer) {// console.log(// `[${event.type}]:`,@@ -251,16 +203,16 @@ var ReactNodeView = /** @class */ (function () {}// we have to store that dragging startedif (isDraggable && isEditable && !isDragging && isClickEvent) {- var dragHandle = target.closest("[data-drag-handle]");- var isValidDragHandle = dragHandle &&+ const dragHandle = target.closest("[data-drag-handle]");+ const isValidDragHandle = dragHandle &&(this.dom === dragHandle || this.dom.contains(dragHandle));if (isValidDragHandle) {this.isDragging = true;- document.addEventListener("dragend", function () {- _this.isDragging = false;+ document.addEventListener("dragend", () => {+ this.isDragging = false;}, { once: true });- document.addEventListener("mouseup", function () {- _this.isDragging = false;+ document.addEventListener("mouseup", () => {+ this.isDragging = false;}, { once: true });}}@@ -274,8 +226,8 @@ var ReactNodeView = /** @class */ (function () {return false;}return true;- };- ReactNodeView.prototype.ignoreMutation = function (mutation) {+ }+ ignoreMutation(mutation) {if (!this.dom || !this.contentDOM) {return true;}@@ -298,10 +250,13 @@ var ReactNodeView = /** @class */ (function () {if (this.dom.contains(mutation.target) &&mutation.type === "childList" &&this.editor.isFocused) {- var changedNodes = __spreadArray(__spreadArray([], __read(Array.from(mutation.addedNodes)), false), __read(Array.from(mutation.removedNodes)), false);+ const changedNodes = [+ ...Array.from(mutation.addedNodes),+ ...Array.from(mutation.removedNodes),+ ];// we’ll check if every changed node is contentEditable// to make sure it’s probably mutated by ProseMirror- if (changedNodes.every(function (node) { return node.isContentEditable; })) {+ if (changedNodes.every((node) => node.isContentEditable)) {return false;}}@@ -315,29 +270,25 @@ var ReactNodeView = /** @class */ (function () {return false;}return true;- };- ReactNodeView.prototype.viewShouldUpdate = function (nextNode) {+ }+ viewShouldUpdate(nextNode) {if (this.options.shouldUpdate)return this.options.shouldUpdate(this.node, nextNode);return true;- };+ }/*** Copies the attributes from a ProseMirror Node to a DOM node.* @param node The Prosemirror Node from which to source the attributes*/- ReactNodeView.prototype.setDomAttrs = function (node, element) {- Object.keys(node.attrs || {}).forEach(function (attr) {+ setDomAttrs(node, element) {+ Object.keys(node.attrs || {}).forEach((attr) => {element.setAttribute(attr, node.attrs[attr]);});- };- Object.defineProperty(ReactNodeView.prototype, "dom", {- get: function () {- return this.domRef;- },- enumerable: false,- configurable: true- });- ReactNodeView.prototype.destroy = function () {+ }+ get dom() {+ return this.domRef;+ }+ destroy() {if (!this.domRef || !this.portalProviderAPI) {return;}@@ -345,15 +296,13 @@ var ReactNodeView = /** @class */ (function () {// @ts-ignore NEW PM APIthis.domRef = undefined;this.contentDOM = undefined;- };- return ReactNodeView;-}());+ }+}exports.ReactNodeView = ReactNodeView;function createNodeView(component, options) {- return function (_a) {- var node = _a.node, getPos = _a.getPos, editor = _a.editor;- var _getPos = function () { return (typeof getPos === "boolean" ? -1 : getPos()); };- return new ReactNodeView(node, editor, _getPos, __assign(__assign({}, options), { component: component })).init();+ return ({ node, getPos, editor }) => {+ const _getPos = () => (typeof getPos === "boolean" ? -1 : getPos());+ return new ReactNodeView(node, editor, _getPos, Object.assign(Object.assign({}, options), { component })).init();};}exports.createNodeView = createNodeView;@@ -374,13 +323,13 @@ exports.createNodeView = createNodeView;function forceHandleDrag(event, editor) {if (!event.dataTransfer)return;- var view = editor.view;- var slice = view.state.selection.content();- var _a = (0, prosemirror_view_1.__serializeForClipboard)(view, slice), dom = _a.dom, text = _a.text;+ const { view } = editor;+ const slice = view.state.selection.content();+ const { dom, text } = (0, prosemirror_view_1.__serializeForClipboard)(view, slice);event.dataTransfer.clearData();event.dataTransfer.setData("Text", text);event.dataTransfer.setData("text/plain", text);event.dataTransfer.setData("text/html", dom.innerHTML);event.dataTransfer.effectAllowed = "copyMove";- view.dragging = { slice: slice, move: true };+ view.dragging = { slice, move: true };}diff --git a/packages/editor/dist/extensions/react/reactportalprovider.d.ts b/packages/editor/dist/cjs/extensions/react/reactportalprovider.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/reactportalprovider.d.tsrename to packages/editor/dist/cjs/extensions/react/reactportalprovider.d.tsdiff --git a/packages/editor/dist/cjs/extensions/react/reactportalprovider.js b/packages/editor/dist/cjs/extensions/react/reactportalprovider.jsnew file mode 100644index 000000000..ee2d612b4--- /dev/null+++ b/packages/editor/dist/cjs/extensions/react/reactportalprovider.js@@ -0,0 +1,99 @@+"use strict";+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ var desc = Object.getOwnPropertyDescriptor(m, k);+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {+ desc = { enumerable: true, get: function() { return m[k]; } };+ }+ Object.defineProperty(o, k2, desc);+}) : (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ o[k2] = m[k];+}));+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {+ Object.defineProperty(o, "default", { enumerable: true, value: v });+}) : function(o, v) {+ o["default"] = v;+});+var __importStar = (this && this.__importStar) || function (mod) {+ if (mod && mod.__esModule) return mod;+ var result = {};+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);+ __setModuleDefault(result, mod);+ return result;+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.PortalRenderer = exports.PortalProvider = exports.usePortalProvider = exports.PortalProviderAPI = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importStar(require("react"));+const react_dom_1 = require("react-dom");+const eventdispatcher_1 = require("./eventdispatcher");+class PortalProviderAPI extends eventdispatcher_1.EventDispatcher {+ constructor() {+ super();+ this.portals = new Map();+ this.setContext = (context) => {+ this.context = context;+ };+ }+ render(children, container) {+ this.portals.set(container, {+ children,+ });+ let wrappedChildren = children();+ (0, react_dom_1.unstable_renderSubtreeIntoContainer)(this.context, wrappedChildren, container);+ }+ // TODO: until https://product-fabric.atlassian.net/browse/ED-5013+ // we (unfortunately) need to re-render to pass down any updated context.+ // selectively do this for nodeviews that opt-in via `hasAnalyticsContext`+ forceUpdate() { }+ remove(container) {+ this.portals.delete(container);+ // There is a race condition that can happen caused by Prosemirror vs React,+ // where Prosemirror removes the container from the DOM before React gets+ // around to removing the child from the container+ // This will throw a NotFoundError: The node to be removed is not a child of this node+ // Both Prosemirror and React remove the elements asynchronously, and in edge+ // cases Prosemirror beats React+ try {+ (0, react_dom_1.unmountComponentAtNode)(container);+ }+ catch (error) {+ // IGNORE console.error(error);+ }+ }+}+exports.PortalProviderAPI = PortalProviderAPI;+const PortalProviderContext = react_1.default.createContext(undefined);+function usePortalProvider() {+ return (0, react_1.useContext)(PortalProviderContext);+}+exports.usePortalProvider = usePortalProvider;+class PortalProvider extends react_1.default.Component {+ constructor(props) {+ super(props);+ this.portalProviderAPI = new PortalProviderAPI();+ }+ render() {+ return ((0, jsx_runtime_1.jsxs)(PortalProviderContext.Provider, Object.assign({ value: this.portalProviderAPI }, { children: [this.props.children, (0, jsx_runtime_1.jsx)(PortalRenderer, { portalProviderAPI: this.portalProviderAPI })] })));+ }+ componentDidUpdate() {+ this.portalProviderAPI.forceUpdate();+ }+}+exports.PortalProvider = PortalProvider;+PortalProvider.displayName = "PortalProvider";+class PortalRenderer extends react_1.default.Component {+ constructor(props) {+ super(props);+ this.handleUpdate = (portals) => this.setState({ portals });+ props.portalProviderAPI.setContext(this);+ props.portalProviderAPI.on("update", this.handleUpdate);+ this.state = { portals: new Map() };+ }+ render() {+ const { portals } = this.state;+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: Array.from(portals.entries()).map(([container, children]) => (0, react_dom_1.createPortal)(children, container)) }));+ }+}+exports.PortalRenderer = PortalRenderer;diff --git a/packages/editor/dist/extensions/react/selectionbasedreactnodeview.d.ts b/packages/editor/dist/cjs/extensions/react/selectionbasedreactnodeview.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/selectionbasedreactnodeview.d.tsrename to packages/editor/dist/cjs/extensions/react/selectionbasedreactnodeview.d.tsdiff --git a/packages/editor/dist/cjs/extensions/react/selectionbasedreactnodeview.js b/packages/editor/dist/cjs/extensions/react/selectionbasedreactnodeview.jsnew file mode 100644index 000000000..3423db3a5--- /dev/null+++ b/packages/editor/dist/cjs/extensions/react/selectionbasedreactnodeview.js@@ -0,0 +1,150 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.createSelectionBasedNodeView = exports.SelectionBasedNodeView = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const prosemirror_view_1 = require("prosemirror-view");+const prosemirror_state_1 = require("prosemirror-state");+const plugin_1 = require("./plugin");+const reactnodeview_1 = require("./reactnodeview");+const emotion_theming_1 = require("emotion-theming");+/**+ * A ReactNodeView that handles React components sensitive+ * to selection changes.+ *+ * If the selection changes, it will attempt to re-render the+ * React component. Otherwise it does nothing.+ *+ * You can subclass `viewShouldUpdate` to include other+ * props that your component might want to consider before+ * entering the React lifecycle. These are usually props you+ * compare in `shouldComponentUpdate`.+ *+ * An example:+ *+ * ```+ * viewShouldUpdate(nextNode) {+ * if (nextNode.attrs !== this.node.attrs) {+ * return true;+ * }+ *+ * return super.viewShouldUpdate(nextNode);+ * }```+ */+class SelectionBasedNodeView extends reactnodeview_1.ReactNodeView {+ constructor(node, editor, getPos, options) {+ super(node, editor, getPos, options);+ this.pos = -1;+ this.isNodeInsideSelection = (from, to, pos, posEnd) => {+ ({ pos, posEnd } = this.getPositionsWithDefault(pos, posEnd));+ if (typeof pos !== "number" || typeof posEnd !== "number") {+ return false;+ }+ return from <= pos && to >= posEnd;+ };+ this.isSelectionInsideNode = (from, to, pos, posEnd) => {+ ({ pos, posEnd } = this.getPositionsWithDefault(pos, posEnd));+ if (typeof pos !== "number" || typeof posEnd !== "number") {+ return false;+ }+ return pos < from && to < posEnd;+ };+ this.isSelectedNode = (selection) => {+ if (selection instanceof prosemirror_state_1.NodeSelection) {+ const { selection: { from, to }, } = this.editor.view.state;+ return (selection.node === this.node ||+ // If nodes are not the same object, we check if they are referring to the same document node+ (this.pos === from &&+ this.posEnd === to &&+ selection.node.eq(this.node)));+ }+ return false;+ };+ this.insideSelection = () => {+ const { selection: { from, to }, } = this.editor.view.state;+ return (this.isSelectedNode(this.editor.view.state.selection) ||+ this.isSelectionInsideNode(from, to));+ };+ this.nodeInsideSelection = () => {+ const { selection } = this.editor.view.state;+ const { from, to } = selection;+ return (this.isSelectedNode(selection) || this.isNodeInsideSelection(from, to));+ };+ this.onSelectionChange = () => {+ this.update(this.node, [], prosemirror_view_1.DecorationSet.empty);+ };+ this.updatePos();+ this.oldSelection = editor.view.state.selection;+ this.selectionChangeState = plugin_1.stateKey.getState(this.editor.view.state);+ this.selectionChangeState.subscribe(this.onSelectionChange);+ }+ render(props = {}, forwardRef) {+ if (!this.options.component)+ return null;+ const theme = this.editor.storage.theme;+ const isSelected = this.editor.isEditable &&+ (this.insideSelection() || this.nodeInsideSelection());+ return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, Object.assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(this.options.component, Object.assign({}, props, { editor: this.editor, getPos: this.getPos, node: this.node, forwardRef: forwardRef, selected: isSelected, updateAttributes: (attr) => this.updateAttributes(attr, this.pos) })) })));+ }+ /**+ * Update current node's start and end positions.+ *+ * Prefer `this.pos` rather than getPos(), because calling getPos is+ * expensive, unless you know you're definitely going to render.+ */+ updatePos() {+ if (typeof this.getPos === "boolean") {+ return;+ }+ this.pos = this.getPos();+ this.posEnd = this.pos + this.node.nodeSize;+ }+ getPositionsWithDefault(pos, posEnd) {+ return {+ pos: typeof pos !== "number" ? this.pos : pos,+ posEnd: typeof posEnd !== "number" ? this.posEnd : posEnd,+ };+ }+ viewShouldUpdate(nextNode) {+ if (super.viewShouldUpdate(nextNode))+ return true;+ const { state: { selection }, } = this.editor.view;+ // update selection+ const oldSelection = this.oldSelection;+ this.oldSelection = selection;+ // update cached positions+ const { pos: oldPos, posEnd: oldPosEnd } = this;+ this.updatePos();+ const { from, to } = selection;+ const { from: oldFrom, to: oldTo } = oldSelection;+ if (this.node.type.spec.selectable) {+ const newNodeSelection = selection instanceof prosemirror_state_1.NodeSelection && selection.from === this.pos;+ const oldNodeSelection = oldSelection instanceof prosemirror_state_1.NodeSelection && oldSelection.from === this.pos;+ if ((newNodeSelection && !oldNodeSelection) ||+ (oldNodeSelection && !newNodeSelection)) {+ return true;+ }+ }+ const movedInToSelection = this.isNodeInsideSelection(from, to) &&+ !this.isNodeInsideSelection(oldFrom, oldTo);+ const movedOutOfSelection = !this.isNodeInsideSelection(from, to) &&+ this.isNodeInsideSelection(oldFrom, oldTo);+ const moveOutFromOldSelection = this.isNodeInsideSelection(from, to, oldPos, oldPosEnd) &&+ !this.isNodeInsideSelection(from, to);+ if (movedInToSelection || movedOutOfSelection || moveOutFromOldSelection) {+ return true;+ }+ return false;+ }+ destroy() {+ this.selectionChangeState.unsubscribe(this.onSelectionChange);+ super.destroy();+ }+}+exports.SelectionBasedNodeView = SelectionBasedNodeView;+function createSelectionBasedNodeView(component, options) {+ return ({ node, getPos, editor }) => {+ const _getPos = () => (typeof getPos === "boolean" ? -1 : getPos());+ return new SelectionBasedNodeView(node, editor, _getPos, Object.assign(Object.assign({}, options), { component })).init();+ };+}+exports.createSelectionBasedNodeView = createSelectionBasedNodeView;diff --git a/packages/editor/dist/extensions/react/types.d.ts b/packages/editor/dist/cjs/extensions/react/types.d.tssimilarity index 100%rename from packages/editor/dist/extensions/react/types.d.tsrename to packages/editor/dist/cjs/extensions/react/types.d.tsdiff --git a/packages/editor/dist/extensions/react/types.js b/packages/editor/dist/cjs/extensions/react/types.jssimilarity index 100%rename from packages/editor/dist/extensions/react/types.jsrename to packages/editor/dist/cjs/extensions/react/types.jsdiff --git a/packages/editor/dist/extensions/searchreplace/index.d.ts b/packages/editor/dist/cjs/extensions/searchreplace/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/searchreplace/index.d.tsrename to packages/editor/dist/cjs/extensions/searchreplace/index.d.tsdiff --git a/packages/editor/dist/extensions/searchreplace/index.js b/packages/editor/dist/cjs/extensions/searchreplace/index.jssimilarity index 100%rename from packages/editor/dist/extensions/searchreplace/index.jsrename to packages/editor/dist/cjs/extensions/searchreplace/index.jsdiff --git a/packages/editor/dist/extensions/searchreplace/searchreplace.d.ts b/packages/editor/dist/cjs/extensions/searchreplace/searchreplace.d.tssimilarity index 100%rename from packages/editor/dist/extensions/searchreplace/searchreplace.d.tsrename to packages/editor/dist/cjs/extensions/searchreplace/searchreplace.d.tsdiff --git a/packages/editor/dist/cjs/extensions/searchreplace/searchreplace.js b/packages/editor/dist/cjs/extensions/searchreplace/searchreplace.jsnew file mode 100644index 000000000..c07b5c02a--- /dev/null+++ b/packages/editor/dist/cjs/extensions/searchreplace/searchreplace.js@@ -0,0 +1,214 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.SearchReplace = void 0;+const core_1 = require("@tiptap/core");+const prosemirror_view_1 = require("prosemirror-view");+const prosemirror_state_1 = require("prosemirror-state");+const updateView = (state, dispatch) => dispatch(state.tr);+const regex = (s, settings) => {+ const { enableRegex, matchCase, matchWholeWord } = settings;+ const boundary = matchWholeWord ? "\\b" : "";+ console.log(boundary);+ return RegExp(boundary ++ (enableRegex ? s : s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")) ++ boundary, matchCase ? "gu" : "gui");+};+function searchDocument(doc, searchResultClass, searchTerm) {+ if (!searchTerm)+ return { decorationSet: prosemirror_view_1.DecorationSet.empty, results: [] };+ const decorations = [];+ const results = [];+ let index = 0;+ let textNodesWithPosition = [];+ doc === null || doc === void 0 ? void 0 : doc.descendants((node, pos) => {+ if (node.isText) {+ if (textNodesWithPosition[index]) {+ textNodesWithPosition[index] = {+ text: textNodesWithPosition[index].text + node.text,+ pos: textNodesWithPosition[index].pos,+ };+ }+ else {+ textNodesWithPosition[index] = {+ text: node.text || "",+ pos,+ };+ }+ }+ else {+ index += 1;+ }+ });+ textNodesWithPosition = textNodesWithPosition.filter(Boolean);+ for (const { text, pos } of textNodesWithPosition) {+ const matches = text.matchAll(searchTerm);+ for (const m of matches) {+ if (m[0] === "")+ break;+ if (m.index !== undefined) {+ results.push({+ from: pos + m.index,+ to: pos + m.index + m[0].length,+ });+ }+ }+ }+ for (const { from, to } of results) {+ decorations.push(prosemirror_view_1.Decoration.inline(from, to, { class: searchResultClass }));+ }+ return {+ decorationSet: prosemirror_view_1.DecorationSet.create(doc, decorations),+ results,+ };+}+const replaceAll = (replaceTerm, results, tr) => {+ let offset = 0;+ if (!results.length)+ return;+ const map = tr.mapping;+ for (let i = 0; i < results.length; i += 1) {+ const { from, to } = results[i];+ tr.insertText(replaceTerm, from, to);+ if (i + 1 < results.length) {+ const { from, to } = results[i + 1];+ results[i + 1] = {+ from: map.map(from),+ to: map.map(to),+ };+ }+ }+ return tr;+};+exports.SearchReplace = core_1.Extension.create({+ name: "searchreplace",+ addOptions() {+ return {+ searchResultClass: "search-result",+ };+ },+ addCommands() {+ return {+ startSearch: () => ({ state }) => {+ this.storage.isSearching = true;+ if (!state.selection.empty) {+ this.storage.selectedText = state.doc.textBetween(state.selection.$from.pos, state.selection.$to.pos);+ }+ return true;+ },+ endSearch: () => ({ state, dispatch }) => {+ this.storage.isSearching = false;+ this.storage.searchTerm = "";+ updateView(state, dispatch);+ return true;+ },+ search: (term, options) => ({ state, dispatch }) => {+ this.storage.searchTerm = term;+ 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;+ },+ moveToNextResult: () => ({ chain }) => {+ const { selectedIndex, results } = this.storage;+ if (!results || results.length <= 0)+ return false;+ let nextIndex = selectedIndex + 1;+ if (isNaN(nextIndex) || nextIndex >= results.length)+ nextIndex = 0;+ const { from, to } = results[nextIndex];+ console.log("[moveToNextResult]", from, to);+ const result = chain()+ .focus(undefined, { scrollIntoView: true })+ .setTextSelection({ from, to })+ .run();+ if (result)+ this.storage.selectedIndex = nextIndex;+ return result;+ },+ moveToPreviousResult: () => ({ chain }) => {+ const { selectedIndex, results } = this.storage;+ if (!results || results.length <= 0)+ return false;+ let prevIndex = selectedIndex - 1;+ if (isNaN(prevIndex) || prevIndex < 0)+ prevIndex = results.length - 1;+ const { from, to } = results[prevIndex];+ const result = chain()+ .focus(undefined, { scrollIntoView: true })+ .setTextSelection({ from, to })+ .run();+ if (result)+ this.storage.selectedIndex = prevIndex;+ return result;+ },+ replace: (term) => ({ commands, tr, dispatch }) => {+ const { selectedIndex, results } = this.storage;+ if (!dispatch || !results || results.length <= 0)+ return false;+ const index = selectedIndex === undefined ? 0 : selectedIndex;+ const { from, to } = results[index];+ tr.insertText(term, from, to);+ if (index + 1 < results.length) {+ const { from, to } = results[index + 1];+ const nextResult = (results[index + 1] = {+ from: tr.mapping.map(from),+ to: tr.mapping.map(to),+ });+ commands.focus();+ tr.setSelection(new prosemirror_state_1.TextSelection(tr.doc.resolve(nextResult.from), tr.doc.resolve(nextResult.to)));+ }+ dispatch(tr);+ results.splice(index, 1);+ return true;+ },+ replaceAll: (term) => ({ state, tr, dispatch }) => {+ if (!dispatch)+ return false;+ const { results } = this.storage;+ if (!dispatch || !results || results.length <= 0)+ return false;+ dispatch(replaceAll(term, results, tr));+ return true;+ },+ };+ },+ addKeyboardShortcuts() {+ return {+ "Mod-f": ({ editor }) => editor.commands.startSearch(),+ Escape: ({ editor }) => editor.commands.endSearch(),+ };+ },+ addProseMirrorPlugins() {+ const key = new prosemirror_state_1.PluginKey("searchreplace");+ return [+ new prosemirror_state_1.Plugin({+ key,+ state: {+ init() {+ return prosemirror_view_1.DecorationSet.empty;+ },+ apply: ({ doc, docChanged, setSelection }) => {+ const { searchTerm, enableRegex, matchCase, matchWholeWord } = this.storage;+ const { searchResultClass } = this.options;+ if (docChanged || searchTerm) {+ const searchRegex = searchTerm+ ? regex(searchTerm, { enableRegex, matchCase, matchWholeWord })+ : undefined;+ const { decorationSet, results } = searchDocument(doc, searchResultClass, searchRegex);+ this.storage.results = results;+ return decorationSet;+ }+ return prosemirror_view_1.DecorationSet.empty;+ },+ },+ props: {+ decorations(state) {+ return key.getState(state);+ },+ },+ }),+ ];+ },+});diff --git a/packages/editor/dist/extensions/table/actions.d.ts b/packages/editor/dist/cjs/extensions/table/actions.d.tssimilarity index 100%rename from packages/editor/dist/extensions/table/actions.d.tsrename to packages/editor/dist/cjs/extensions/table/actions.d.tsdiff --git a/packages/editor/dist/extensions/table/actions.js b/packages/editor/dist/cjs/extensions/table/actions.jssimilarity index 51%rename from packages/editor/dist/extensions/table/actions.jsrename to packages/editor/dist/cjs/extensions/table/actions.jsindex 9b9f43cb2..878fcf1ae 100644--- a/packages/editor/dist/extensions/table/actions.js+++ b/packages/editor/dist/cjs/extensions/table/actions.js@@ -1,88 +1,86 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.moveRowUp = exports.moveRowDown = exports.moveColumnRight = exports.moveColumnLeft = void 0;-var prosemirror_tables_1 = require("@_ueberdosis/prosemirror-tables");+const prosemirror_tables_1 = require("@_ueberdosis/prosemirror-tables");function moveColumnRight(editor) {- var tr = editor.state.tr;- var rect = (0, prosemirror_tables_1.selectedRect)(editor.state);+ const { tr } = editor.state;+ const rect = (0, prosemirror_tables_1.selectedRect)(editor.state);if (rect.right === rect.map.width)return;- var transaction = moveColumn(tr, rect, rect.left, rect.left + 1);+ const transaction = moveColumn(tr, rect, rect.left, rect.left + 1);if (!transaction)return;editor.view.dispatch(transaction);}exports.moveColumnRight = moveColumnRight;function moveColumnLeft(editor) {- var tr = editor.state.tr;- var rect = (0, prosemirror_tables_1.selectedRect)(editor.state);+ const { tr } = editor.state;+ const rect = (0, prosemirror_tables_1.selectedRect)(editor.state);if (rect.left === 0)return;- var transaction = moveColumn(tr, rect, rect.left, rect.left - 1);+ const transaction = moveColumn(tr, rect, rect.left, rect.left - 1);if (!transaction)return;editor.view.dispatch(transaction);}exports.moveColumnLeft = moveColumnLeft;function moveRowDown(editor) {- var tr = editor.state.tr;- var rect = (0, prosemirror_tables_1.selectedRect)(editor.state);+ const { tr } = editor.state;+ const rect = (0, prosemirror_tables_1.selectedRect)(editor.state);if (rect.top + 1 === rect.map.height)return;- var transaction = moveRow(tr, rect, rect.top, rect.top + 1);+ const transaction = moveRow(tr, rect, rect.top, rect.top + 1);if (!transaction)return;editor.view.dispatch(transaction);}exports.moveRowDown = moveRowDown;function moveRowUp(editor) {- var tr = editor.state.tr;- var rect = (0, prosemirror_tables_1.selectedRect)(editor.state);+ const { tr } = editor.state;+ const rect = (0, prosemirror_tables_1.selectedRect)(editor.state);if (rect.top === 0)return;- var transaction = moveRow(tr, rect, rect.top, rect.top - 1);+ const transaction = moveRow(tr, rect, rect.top, rect.top - 1);if (!transaction)return;editor.view.dispatch(transaction);}exports.moveRowUp = moveRowUp;function moveColumn(tr, rect, from, to) {- var fromCells = getColumnCells(rect, from);- var toCells = getColumnCells(rect, to);+ let fromCells = getColumnCells(rect, from);+ let toCells = getColumnCells(rect, to);return moveCells(tr, rect, fromCells, toCells);}-function getColumnCells(_a, col) {- var map = _a.map, table = _a.table;- var cells = [];- for (var row = 0; row < map.height;) {- var index = row * map.width + col;+function getColumnCells({ map, table }, col) {+ let cells = [];+ for (let row = 0; row < map.height;) {+ let index = row * map.width + col;if (index >= map.map.length)break;- var pos = map.map[index];- var cell = table.nodeAt(pos);+ let pos = map.map[index];+ let cell = table.nodeAt(pos);if (!cell)continue;- cells.push({ cell: cell, pos: pos });+ cells.push({ cell, pos });row += cell.attrs.rowspan;}return cells;}function moveRow(tr, rect, from, to) {- var fromCells = getRowCells(rect, from);- var toCells = getRowCells(rect, to);+ let fromCells = getRowCells(rect, from);+ let toCells = getRowCells(rect, to);return moveCells(tr, rect, fromCells, toCells);}-function getRowCells(_a, row) {- var map = _a.map, table = _a.table;- var cells = [];- for (var col = 0, index = row * map.width; col < map.width; col++, index++) {+function getRowCells({ map, table }, row) {+ let cells = [];+ for (let col = 0, index = row * map.width; col < map.width; col++, index++) {if (index >= map.map.length)break;- var pos = map.map[index];- var cell = table.nodeAt(pos);+ let pos = map.map[index];+ let cell = table.nodeAt(pos);if (!cell)continue;- cells.push({ cell: cell, pos: pos });+ cells.push({ cell, pos });col += cell.attrs.colspan - 1;}return cells;@@ -90,20 +88,20 @@ function getRowCells(_a, row) {function moveCells(tr, rect, fromCells, toCells) {if (fromCells.length !== toCells.length)return;- var mapStart = tr.mapping.maps.length;- for (var i = 0; i < toCells.length; ++i) {- var fromCell = fromCells[i];- var toCell = toCells[i];- var fromStart = tr.mapping+ let mapStart = tr.mapping.maps.length;+ for (let i = 0; i < toCells.length; ++i) {+ const fromCell = fromCells[i];+ const toCell = toCells[i];+ let fromStart = tr.mapping.slice(mapStart).map(rect.tableStart + fromCell.pos);- var fromEnd = fromStart + fromCell.cell.nodeSize;- var fromSlice = tr.doc.slice(fromStart, fromEnd);- var toStart = tr.mapping+ let fromEnd = fromStart + fromCell.cell.nodeSize;+ const fromSlice = tr.doc.slice(fromStart, fromEnd);+ const toStart = tr.mapping.slice(mapStart).map(rect.tableStart + toCell.pos);- var toEnd = toStart + toCell.cell.nodeSize;- var toSlice = tr.doc.slice(toStart, toEnd);+ const toEnd = toStart + toCell.cell.nodeSize;+ const toSlice = tr.doc.slice(toStart, toEnd);tr.replace(toStart, toEnd, fromSlice);fromStart = tr.mapping.slice(mapStart).map(rect.tableStart + fromCell.pos);fromEnd = fromStart + fromCell.cell.nodeSize;diff --git a/packages/editor/dist/extensions/table/component.d.ts b/packages/editor/dist/cjs/extensions/table/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/table/component.d.tsrename to packages/editor/dist/cjs/extensions/table/component.d.tsdiff --git a/packages/editor/dist/cjs/extensions/table/component.js b/packages/editor/dist/cjs/extensions/table/component.jsnew file mode 100644index 000000000..2e508c6e8--- /dev/null+++ b/packages/editor/dist/cjs/extensions/table/component.js@@ -0,0 +1,126 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.TableNodeView = exports.TableComponent = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("../react");+const react_2 = require("react");+const prosemirror_tables_1 = require("@_ueberdosis/prosemirror-tables");+const table_1 = require("../../toolbar/tools/table");+const tooldefinitions_1 = require("../../toolbar/tooldefinitions");+const position_1 = require("../../utils/position");+const prosemirror_1 = require("../../toolbar/utils/prosemirror");+const responsive_1 = require("../../components/responsive");+function TableComponent(props) {+ const { editor, node, forwardRef } = props;+ const colgroupRef = (0, react_2.useRef)(null);+ const tableRef = (0, react_2.useRef)();+ const selected = editor.isActive("table");+ (0, react_2.useEffect)(() => {+ if (!colgroupRef.current || !tableRef.current)+ return;+ (0, prosemirror_tables_1.updateColumnsOnResize)(node, colgroupRef.current, tableRef.current, 50);+ }, [node]);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableRowToolbar, { editor: editor, table: tableRef.current }), (0, jsx_runtime_1.jsx)(TableColumnToolbar, { editor: editor, table: tableRef.current })] })) }), (0, jsx_runtime_1.jsx)("div", Object.assign({ className: "tableWrapper" }, { children: (0, jsx_runtime_1.jsx)("table", Object.assign({ ref: (ref) => {+ forwardRef === null || forwardRef === void 0 ? void 0 : forwardRef(ref);+ tableRef.current = ref || undefined;+ } }, { children: (0, jsx_runtime_1.jsx)("colgroup", { ref: colgroupRef }) })) }))] }));+}+exports.TableComponent = TableComponent;+function TableNodeView(editor) {+ class TableNode extends react_1.SelectionBasedNodeView {+ constructor(node, cellMinWidth) {+ super(node, editor, () => 0, // todo+ {+ component: TableComponent,+ shouldUpdate: (prev, next) => {+ return prev.type === next.type;+ },+ contentDOMFactory: () => {+ const dom = document.createElement("tbody");+ return { dom };+ },+ wrapperFactory: () => {+ const dom = document.createElement("div");+ dom.style.position = "relative";+ return dom;+ },+ });+ super.init();+ }+ }+ return TableNode;+}+exports.TableNodeView = TableNodeView;+function TableRowToolbar(props) {+ const { editor } = props;+ const rowToolsRef = (0, react_2.useRef)(null);+ (0, react_2.useEffect)(() => {+ if (!rowToolsRef.current) {+ return;+ }+ const currentRow = (0, prosemirror_1.findSelectedDOMNode)(editor, ["tableRow"]);+ if (!currentRow)+ return;+ const pos = (0, position_1.getPosition)(rowToolsRef.current, {+ location: "left",+ target: currentRow,+ align: "start",+ xOffset: -5,+ yOffset: -3,+ });+ rowToolsRef.current.style.top = `${pos.top}px`;+ rowToolsRef.current.style.left = `${pos.left}px`;+ }, [editor.state.selection, rowToolsRef.current]);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ ref: rowToolsRef, sx: {+ zIndex: 999,+ top: 0,+ left: 0,+ position: "absolute",+ bg: "background",+ flexWrap: "nowrap",+ borderRadius: "default",+ opacity: 0.3,+ ":hover": {+ opacity: 1,+ },+ } }, { children: [(0, jsx_runtime_1.jsx)(table_1.RowProperties, Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("rowProperties"), { icon: "more", variant: "small", editor: editor })), (0, jsx_runtime_1.jsx)(table_1.InsertRowBelow, Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("insertRowBelow"), { editor: editor, variant: "small" }))] })));+}+function TableColumnToolbar(props) {+ const { editor, table } = props;+ const columnToolsRef = (0, react_2.useRef)(null);+ (0, react_2.useEffect)(() => {+ if (!columnToolsRef.current || !table) {+ return;+ }+ const currentCell = (0, prosemirror_1.findSelectedDOMNode)(editor, [+ "tableCell",+ "tableHeader",+ ]);+ if (!currentCell)+ return;+ // tableRef.current+ const pos = (0, position_1.getPosition)(columnToolsRef.current, {+ location: "top",+ align: "center",+ target: currentCell,+ yAnchor: table,+ yOffset: 2,+ });+ columnToolsRef.current.style.left = `${pos.left}px`;+ columnToolsRef.current.style.top = `${pos.top}px`;+ }, [editor.state.selection, columnToolsRef.current, table]);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ ref: columnToolsRef, sx: {+ zIndex: 999,+ top: 0,+ left: 0,+ position: "absolute",+ bg: "background",+ flexWrap: "nowrap",+ borderRadius: "default",+ opacity: 0.3,+ ":hover": {+ opacity: 1,+ },+ } }, { children: [(0, jsx_runtime_1.jsx)(table_1.TableProperties, { editor: editor, title: "tableProperties", icon: "more", variant: "small" }), (0, jsx_runtime_1.jsx)(table_1.InsertColumnRight, Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("insertColumnRight"), { editor: editor, variant: "small", icon: "plus" }))] })));+}diff --git a/packages/editor/dist/extensions/table/index.d.ts b/packages/editor/dist/cjs/extensions/table/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/table/index.d.tsrename to packages/editor/dist/cjs/extensions/table/index.d.tsdiff --git a/packages/editor/dist/extensions/table/index.js b/packages/editor/dist/cjs/extensions/table/index.jssimilarity index 100%rename from packages/editor/dist/extensions/table/index.jsrename to packages/editor/dist/cjs/extensions/table/index.jsdiff --git a/packages/editor/dist/extensions/table/table.d.ts b/packages/editor/dist/cjs/extensions/table/table.d.tssimilarity index 100%rename from packages/editor/dist/extensions/table/table.d.tsrename to packages/editor/dist/cjs/extensions/table/table.d.tsdiff --git a/packages/editor/dist/cjs/extensions/table/table.js b/packages/editor/dist/cjs/extensions/table/table.jsnew file mode 100644index 000000000..3ca8dcb2e--- /dev/null+++ b/packages/editor/dist/cjs/extensions/table/table.js@@ -0,0 +1,28 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Table = void 0;+const extension_table_1 = require("@tiptap/extension-table");+const prosemirror_tables_1 = require("@_ueberdosis/prosemirror-tables");+const component_1 = require("./component");+exports.Table = extension_table_1.Table.extend({+ addProseMirrorPlugins() {+ const isResizable = this.options.resizable && this.editor.isEditable;+ return [+ ...(isResizable+ ? [+ (0, prosemirror_tables_1.columnResizing)({+ handleWidth: this.options.handleWidth,+ cellMinWidth: this.options.cellMinWidth,+ View: (0, component_1.TableNodeView)(this.editor),+ // TODO: PR for @types/prosemirror-tables+ // @ts-ignore (incorrect type)+ lastColumnResizable: this.options.lastColumnResizable,+ }),+ ]+ : []),+ (0, prosemirror_tables_1.tableEditing)({+ allowTableNodeSelection: this.options.allowTableNodeSelection,+ }),+ ];+ },+});diff --git a/packages/editor/dist/extensions/tablecell/index.d.ts b/packages/editor/dist/cjs/extensions/tablecell/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/tablecell/index.d.tsrename to packages/editor/dist/cjs/extensions/tablecell/index.d.tsdiff --git a/packages/editor/dist/extensions/tablecell/index.js b/packages/editor/dist/cjs/extensions/tablecell/index.jssimilarity index 95%rename from packages/editor/dist/extensions/tablecell/index.jsrename to packages/editor/dist/cjs/extensions/tablecell/index.jsindex 452274449..9b43e4704 100644--- a/packages/editor/dist/extensions/tablecell/index.js+++ b/packages/editor/dist/cjs/extensions/tablecell/index.js@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);};Object.defineProperty(exports, "__esModule", { value: true });-var tablecell_1 = require("./tablecell");+const tablecell_1 = require("./tablecell");__exportStar(require("./tablecell"), exports);exports.default = tablecell_1.TableCell;diff --git a/packages/editor/dist/extensions/tablecell/tablecell.d.ts b/packages/editor/dist/cjs/extensions/tablecell/tablecell.d.tssimilarity index 100%rename from packages/editor/dist/extensions/tablecell/tablecell.d.tsrename to packages/editor/dist/cjs/extensions/tablecell/tablecell.d.tsdiff --git a/packages/editor/dist/cjs/extensions/tablecell/tablecell.js b/packages/editor/dist/cjs/extensions/tablecell/tablecell.jsnew file mode 100644index 000000000..2be64b0d2--- /dev/null+++ b/packages/editor/dist/cjs/extensions/tablecell/tablecell.js@@ -0,0 +1,32 @@+"use strict";+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.TableCell = void 0;+const extension_table_cell_1 = __importDefault(require("@tiptap/extension-table-cell"));+exports.TableCell = extension_table_cell_1.default.extend({+ addAttributes() {+ var _a;+ return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { backgroundColor: addStyleAttribute("backgroundColor", "background-color"), color: addStyleAttribute("color", "color"), borderWidth: addStyleAttribute("borderWidth", "border-width", "px"), borderStyle: addStyleAttribute("borderStyle", "border-style"), borderColor: addStyleAttribute("borderColor", "border-color") });+ },+});+function addStyleAttribute(name, cssName, unit) {+ return {+ default: null,+ parseHTML: (element) => {+ var _a;+ return unit+ ? (_a = element.style[name]) === null || _a === void 0 ? void 0 : _a.toString().replace(unit, "")+ : element.style[name];+ },+ renderHTML: (attributes) => {+ if (!attributes[name]) {+ return {};+ }+ return {+ style: `${cssName}: ${attributes[name]}${unit || ""}`,+ };+ },+ };+}diff --git a/packages/editor/dist/extensions/taskitem/component.d.ts b/packages/editor/dist/cjs/extensions/taskitem/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/taskitem/component.d.tsrename to packages/editor/dist/cjs/extensions/taskitem/component.d.tsdiff --git a/packages/editor/dist/cjs/extensions/taskitem/component.js b/packages/editor/dist/cjs/extensions/taskitem/component.jsnew file mode 100644index 000000000..52caf57d5--- /dev/null+++ b/packages/editor/dist/cjs/extensions/taskitem/component.js@@ -0,0 +1,85 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.TaskItemComponent = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const core_1 = require("@tiptap/core");+const react_1 = require("react");+const taskitem_1 = require("./taskitem");+function TaskItemComponent(props) {+ const { editor, updateAttributes, node, getPos, forwardRef } = props;+ const { checked } = props.node.attrs;+ const toggle = (0, react_1.useCallback)(() => {+ if (!editor.isEditable)+ return false;+ updateAttributes({ checked: !checked });+ editor.commands.command(({ tr }) => {+ const parentPos = getPos();+ toggleChildren(node, tr, !checked, parentPos);+ return true;+ });+ return true;+ }, [editor, getPos, node, checked]);+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ "data-drag-image": true, sx: {+ ":hover > .dragHandle": {+ opacity: editor.isEditable ? 1 : 0,+ },+ } }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { className: "dragHandle", draggable: "true", "data-drag-handle": true, path: icons_1.Icons.dragHandle, sx: {+ opacity: [1, 1, 0],+ alignSelf: "start",+ mr: 2,+ bg: "transparent",+ cursor: "grab",+ ".icon:hover path": {+ fill: "var(--checked) !important",+ },+ }, size: 20 }), (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: checked ? icons_1.Icons.check : "", stroke: "1px", sx: {+ border: "2px solid",+ borderColor: checked ? "checked" : "icon",+ borderRadius: "default",+ alignSelf: "start",+ mr: 2,+ p: "1px",+ cursor: editor.isEditable ? "pointer" : "unset",+ ":hover": {+ borderColor: "checked",+ },+ ":hover .icon path": {+ fill: "var(--checked) !important",+ },+ }, onMouseDown: (e) => {+ e.preventDefault();+ toggle();+ }, color: checked ? "checked" : "icon", size: 13 }), (0, jsx_runtime_1.jsx)(rebass_1.Text, { as: "div", ref: forwardRef, sx: {+ textDecorationLine: checked ? "line-through" : "none",+ color: checked ? "var(--checked)" : "var(--text)",+ flex: 1,+ } })] })) }));+}+exports.TaskItemComponent = TaskItemComponent;+function toggleChildren(node, tr, toggleState, parentPos) {+ const children = (0, core_1.findChildren)(node, (node) => node.type.name === taskitem_1.TaskItemNode.name);+ for (const { pos } of children) {+ // need to add 1 to get inside the node+ const actualPos = pos + parentPos + 1;+ tr.setNodeMarkup(actualPos, undefined, {+ checked: toggleState,+ });+ }+ return tr;+}+function getChildren(node, parentPos) {+ const children = [];+ node.forEach((node, offset) => {+ children.push({ node, pos: parentPos + offset + 1 });+ });+ return children;+}+function areAllChecked(node) {+ const children = (0, core_1.findChildren)(node, (node) => node.type.name === taskitem_1.TaskItemNode.name);+ if (children.length <= 0)+ return undefined;+ return children.every((node) => node.node.attrs.checked);+}diff --git a/packages/editor/dist/extensions/taskitem/index.d.ts b/packages/editor/dist/cjs/extensions/taskitem/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/taskitem/index.d.tsrename to packages/editor/dist/cjs/extensions/taskitem/index.d.tsdiff --git a/packages/editor/dist/extensions/taskitem/index.js b/packages/editor/dist/cjs/extensions/taskitem/index.jssimilarity index 100%rename from packages/editor/dist/extensions/taskitem/index.jsrename to packages/editor/dist/cjs/extensions/taskitem/index.jsdiff --git a/packages/editor/dist/extensions/taskitem/taskitem.d.ts b/packages/editor/dist/cjs/extensions/taskitem/taskitem.d.tssimilarity index 100%rename from packages/editor/dist/extensions/taskitem/taskitem.d.tsrename to packages/editor/dist/cjs/extensions/taskitem/taskitem.d.tsdiff --git a/packages/editor/dist/cjs/extensions/taskitem/taskitem.js b/packages/editor/dist/cjs/extensions/taskitem/taskitem.jsnew file mode 100644index 000000000..94c34cc19--- /dev/null+++ b/packages/editor/dist/cjs/extensions/taskitem/taskitem.js@@ -0,0 +1,63 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.TaskItemNode = void 0;+const core_1 = require("@tiptap/core");+const commands_1 = require("../list-item/commands");+const extension_task_item_1 = require("@tiptap/extension-task-item");+const component_1 = require("./component");+const react_1 = require("../react");+exports.TaskItemNode = extension_task_item_1.TaskItem.extend({+ draggable: true,+ addAttributes() {+ return {+ checked: {+ default: false,+ keepOnSplit: false,+ parseHTML: (element) => element.classList.contains("checked"),+ renderHTML: (attributes) => ({+ class: attributes.checked ? "checked" : "",+ }),+ },+ };+ },+ renderHTML({ node, HTMLAttributes }) {+ return [+ "li",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {+ class: "checklist--item",+ }),+ 0,+ ];+ },+ parseHTML() {+ return [+ {+ tag: `li`,+ getAttrs: (node) => {+ var _a;+ if (node instanceof Node && node instanceof HTMLElement) {+ return node.classList.contains("checklist--item") ||+ ((_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains("checklist"))+ ? null+ : false;+ }+ return false;+ },+ priority: 51,+ },+ ];+ },+ addKeyboardShortcuts() {+ var _a;+ return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { Backspace: ({ editor }) => (0, commands_1.onBackspacePressed)(editor, this.name, this.type) });+ },+ addNodeView() {+ return (0, react_1.createNodeView)(component_1.TaskItemComponent, {+ contentDOMFactory: true,+ wrapperFactory: () => document.createElement("li"),+ shouldUpdate: ({ attrs: prev }, { attrs: next }) => {+ return (prev.checked !== next.checked || prev.collapsed !== next.collapsed);+ },+ });+ },+});diff --git a/packages/editor/dist/extensions/tasklist/component.d.ts b/packages/editor/dist/cjs/extensions/tasklist/component.d.tssimilarity index 100%rename from packages/editor/dist/extensions/tasklist/component.d.tsrename to packages/editor/dist/cjs/extensions/tasklist/component.d.tsdiff --git a/packages/editor/dist/cjs/extensions/tasklist/component.js b/packages/editor/dist/cjs/extensions/tasklist/component.jsnew file mode 100644index 000000000..b98308c8b--- /dev/null+++ b/packages/editor/dist/cjs/extensions/tasklist/component.js@@ -0,0 +1,102 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.TaskListComponent = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const core_1 = require("@tiptap/core");+const icon_1 = require("../../toolbar/components/icon");+const icons_1 = require("../../toolbar/icons");+const react_1 = require("react");+const forms_1 = require("@rebass/forms");+const taskitem_1 = require("../taskitem");+const prosemirror_utils_1 = require("prosemirror-utils");+function TaskListComponent(props) {+ const { editor, getPos, node, updateAttributes, forwardRef } = props;+ const taskItemType = (0, core_1.getNodeType)(taskitem_1.TaskItemNode.name, editor.schema);+ const { title, collapsed } = node.attrs;+ const [stats, setStats] = (0, react_1.useState)({ checked: 0, total: 0, percentage: 0 });+ const parentTaskItem = (0, react_1.useMemo)(() => {+ const pos = editor.state.doc.resolve(getPos());+ return (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(pos, taskItemType);+ }, []);+ const nested = !!parentTaskItem;+ (0, react_1.useEffect)(() => {+ if (!parentTaskItem)+ return;+ const { node, pos } = parentTaskItem;+ const allChecked = areAllChecked(node, pos, editor.state.doc);+ // check parent item if all child items are checked.+ editor.commands.command(({ tr }) => {+ tr.setNodeMarkup(pos, undefined, { checked: allChecked });+ return true;+ });+ }, [node, parentTaskItem]);+ (0, react_1.useEffect)(() => {+ const children = (0, core_1.findChildren)(node, (node) => node.type.name === taskitem_1.TaskItemNode.name);+ const checked = children.filter((node) => node.node.attrs.checked).length;+ const total = children.length;+ const percentage = Math.round((checked / total) * 100);+ setStats({ checked, total, percentage });+ }, [nested, node]);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {+ flexDirection: "column",+ ":hover > div > .toggleSublist": { opacity: 1 },+ } }, { children: nested ? ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ position: "absolute",+ top: 0,+ right: 0,+ }, contentEditable: false }, { children: [collapsed && ((0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "body", sx: { color: "fontTertiary", mr: 35 } }, { children: [stats.checked, "/", stats.total] }))), (0, jsx_runtime_1.jsx)(icon_1.Icon, { className: "toggleSublist", path: collapsed ? icons_1.Icons.chevronDown : icons_1.Icons.chevronUp, sx: {+ opacity: collapsed ? 1 : 0,+ position: "absolute",+ right: 0,+ alignSelf: "start",+ mr: 2,+ cursor: "pointer",+ ".icon:hover path": {+ fill: "var(--checked) !important",+ },+ }, size: 20, onClick: () => {+ updateAttributes({ collapsed: !collapsed });+ } })] }))) : ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ position: "relative",+ bg: "bgSecondary",+ py: 1,+ borderRadius: "default",+ mb: 2,+ alignItems: "center",+ justifyContent: "end",+ overflow: "hidden",+ }, contentEditable: false }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { sx: {+ height: "100%",+ width: `${stats.percentage}%`,+ position: "absolute",+ bg: "border",+ zIndex: 0,+ left: 0,+ transition: "width 250ms ease-out",+ } }), (0, jsx_runtime_1.jsx)(forms_1.Input, { readOnly: !editor.isEditable, value: title || "", variant: "clean", sx: { p: 0, px: 2, zIndex: 1, color: "fontTertiary" }, placeholder: "Untitled", onChange: (e) => {+ updateAttributes({ title: e.target.value });+ } }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { flexShrink: 0, pr: 2 } }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.checkbox, size: 15, color: "fontTertiary" }), (0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "body", sx: { ml: 1, color: "fontTertiary" } }, { children: [stats.checked, "/", stats.total] }))] }))] }))) })), (0, jsx_runtime_1.jsx)(rebass_1.Text, { as: "div", ref: forwardRef, sx: {+ ul: {+ display: collapsed ? "none" : "block",+ paddingInlineStart: 0,+ marginBlockStart: nested ? 10 : 0,+ marginBlockEnd: 0,+ },+ li: {+ listStyleType: "none",+ position: "relative",+ },+ } })] }));+}+exports.TaskListComponent = TaskListComponent;+function areAllChecked(node, pos, doc) {+ const children = (0, core_1.findChildren)(node, (node) => node.type.name === taskitem_1.TaskItemNode.name);+ for (const child of children) {+ const childPos = pos + child.pos + 1;+ const node = doc.nodeAt(childPos);+ if (!(node === null || node === void 0 ? void 0 : node.attrs.checked))+ return false;+ }+ return true;+}diff --git a/packages/editor/dist/extensions/tasklist/index.d.ts b/packages/editor/dist/cjs/extensions/tasklist/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/tasklist/index.d.tsrename to packages/editor/dist/cjs/extensions/tasklist/index.d.tsdiff --git a/packages/editor/dist/extensions/tasklist/index.js b/packages/editor/dist/cjs/extensions/tasklist/index.jssimilarity index 100%rename from packages/editor/dist/extensions/tasklist/index.jsrename to packages/editor/dist/cjs/extensions/tasklist/index.jsdiff --git a/packages/editor/dist/extensions/tasklist/tasklist.d.ts b/packages/editor/dist/cjs/extensions/tasklist/tasklist.d.tssimilarity index 100%rename from packages/editor/dist/extensions/tasklist/tasklist.d.tsrename to packages/editor/dist/cjs/extensions/tasklist/tasklist.d.tsdiff --git a/packages/editor/dist/cjs/extensions/tasklist/tasklist.js b/packages/editor/dist/cjs/extensions/tasklist/tasklist.jsnew file mode 100644index 000000000..e383b0d6f--- /dev/null+++ b/packages/editor/dist/cjs/extensions/tasklist/tasklist.js@@ -0,0 +1,87 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.TaskListNode = void 0;+const core_1 = require("@tiptap/core");+const extension_task_list_1 = require("@tiptap/extension-task-list");+const react_1 = require("../react");+const component_1 = require("./component");+exports.TaskListNode = extension_task_list_1.TaskList.extend({+ addAttributes() {+ return {+ collapsed: {+ default: false,+ keepOnSplit: false,+ parseHTML: (element) => element.dataset.collapsed === "true",+ renderHTML: (attributes) => ({+ "data-collapsed": attributes.collapsed === true,+ }),+ },+ title: {+ default: null,+ keepOnSplit: false,+ parseHTML: (element) => element.dataset.title,+ renderHTML: (attributes) => {+ if (!attributes.title || attributes.nested) {+ return {};+ }+ return {+ "data-title": attributes.title,+ };+ },+ },+ };+ },+ parseHTML() {+ return [+ {+ tag: `ul`,+ getAttrs: (node) => {+ if (node instanceof Node && node instanceof HTMLElement) {+ return node.classList.contains("checklist") && null;+ }+ return false;+ },+ priority: 51,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "ul",+ (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {+ class: "checklist",+ }),+ 0,+ ];+ },+ addCommands() {+ return {+ toggleTaskList: () => ({ editor, commands, state, tr }) => {+ const { $from, $to } = state.selection;+ commands.toggleList(this.name, this.options.itemTypeName);+ const position = {+ from: tr.mapping.map($from.pos),+ to: tr.mapping.map($to.pos),+ };+ // There is a minor bug in Prosemirror or Tiptap where creating+ // nested node view causes the editor selection to act weird.+ // The solution is to manually force the editor back to the correct+ // position.+ // NOTE: We have to wrap this in setTimeout & use the editor+ // directly or else it won't run.+ setTimeout(() => editor.commands.setTextSelection(position), 0);+ return true;+ },+ };+ },+ addNodeView() {+ return (0, react_1.createNodeView)(component_1.TaskListComponent, {+ contentDOMFactory: () => {+ const content = document.createElement("ul");+ content.classList.add(`${this.name.toLowerCase()}-content-wrapper`);+ content.style.whiteSpace = "inherit";+ return { dom: content };+ },+ });+ },+});diff --git a/packages/editor/dist/extensions/textdirection/index.d.ts b/packages/editor/dist/cjs/extensions/textdirection/index.d.tssimilarity index 100%rename from packages/editor/dist/extensions/textdirection/index.d.tsrename to packages/editor/dist/cjs/extensions/textdirection/index.d.tsdiff --git a/packages/editor/dist/extensions/textdirection/index.js b/packages/editor/dist/cjs/extensions/textdirection/index.jssimilarity index 94%rename from packages/editor/dist/extensions/textdirection/index.jsrename to packages/editor/dist/cjs/extensions/textdirection/index.jsindex e3d121469..e9313321a 100644--- a/packages/editor/dist/extensions/textdirection/index.js+++ b/packages/editor/dist/cjs/extensions/textdirection/index.js@@ -14,6 +14,6 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);};Object.defineProperty(exports, "__esModule", { value: true });-var textdirection_1 = require("./textdirection");+const textdirection_1 = require("./textdirection");__exportStar(require("./textdirection"), exports);exports.default = textdirection_1.TextDirection;diff --git a/packages/editor/dist/extensions/textdirection/textdirection.d.ts b/packages/editor/dist/cjs/extensions/textdirection/textdirection.d.tssimilarity index 100%rename from packages/editor/dist/extensions/textdirection/textdirection.d.tsrename to packages/editor/dist/cjs/extensions/textdirection/textdirection.d.tsdiff --git a/packages/editor/dist/extensions/textdirection/textdirection.js b/packages/editor/dist/cjs/extensions/textdirection/textdirection.jssimilarity index 60%rename from packages/editor/dist/extensions/textdirection/textdirection.jsrename to packages/editor/dist/cjs/extensions/textdirection/textdirection.jsindex 75e5c02e2..2094d2b0c 100644--- a/packages/editor/dist/extensions/textdirection/textdirection.js+++ b/packages/editor/dist/cjs/extensions/textdirection/textdirection.js@@ -1,7 +1,7 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.TextDirection = void 0;-var core_1 = require("@tiptap/core");+const core_1 = require("@tiptap/core");require("@tiptap/extension-text-style");exports.TextDirection = core_1.Extension.create({name: "textDirection",@@ -9,15 +9,15 @@ exports.TextDirection = core_1.Extension.create({types: ["paragraph", "heading"],defaultDirection: "ltr",},- addGlobalAttributes: function () {+ addGlobalAttributes() {return [{types: this.options.types,attributes: {textDirection: {default: this.options.defaultDirection,- parseHTML: function (element) { return element.dir; },- renderHTML: function (attributes) {+ parseHTML: (element) => element.dir,+ renderHTML: (attributes) => {if (!attributes.textDirection) {return {};}@@ -30,16 +30,10 @@ exports.TextDirection = core_1.Extension.create({},];},- addCommands: function () {- var _this = this;+ addCommands() {return {- setTextDirection: function (direction) {- return function (_a) {- var commands = _a.commands;- return _this.options.types.every(function (type) {- return commands.updateAttributes(type, { textDirection: direction });- });- };+ setTextDirection: (direction) => ({ commands }) => {+ return this.options.types.every((type) => commands.updateAttributes(type, { textDirection: direction }));},};},diff --git a/packages/editor/dist/cjs/hooks/useEditor.d.ts b/packages/editor/dist/cjs/hooks/useEditor.d.tsnew file mode 100644index 000000000..9c4401648--- /dev/null+++ b/packages/editor/dist/cjs/hooks/useEditor.d.ts@@ -0,0 +1,4 @@+import { EditorOptions } from "@tiptap/core";+import { DependencyList } from "react";+import { Editor as EditorType } from "../types";+export declare const useEditor: (options?: Partial<EditorOptions>, deps?: DependencyList) => EditorType;diff --git a/packages/editor/dist/cjs/hooks/useEditor.js b/packages/editor/dist/cjs/hooks/useEditor.jsnew file mode 100644index 000000000..df6995466--- /dev/null+++ b/packages/editor/dist/cjs/hooks/useEditor.js@@ -0,0 +1,33 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.useEditor = void 0;+const core_1 = require("@tiptap/core");+const react_1 = require("react");+function useForceUpdate() {+ const [, setValue] = (0, react_1.useState)(0);+ return () => setValue((value) => value + 1);+}+const useEditor = (options = {}, deps = []) => {+ const [editor, setEditor] = (0, react_1.useState)(null);+ const forceUpdate = useForceUpdate();+ (0, react_1.useEffect)(() => {+ let isMounted = true;+ const instance = new core_1.Editor(options);+ setEditor(instance);+ instance.on("transaction", () => {+ requestAnimationFrame(() => {+ requestAnimationFrame(() => {+ if (isMounted) {+ forceUpdate();+ }+ });+ });+ });+ return () => {+ instance.destroy();+ isMounted = false;+ };+ }, deps);+ return editor;+};+exports.useEditor = useEditor;diff --git a/packages/editor/dist/hooks/useRefValue.d.ts b/packages/editor/dist/cjs/hooks/useRefValue.d.tssimilarity index 100%rename from packages/editor/dist/hooks/useRefValue.d.tsrename to packages/editor/dist/cjs/hooks/useRefValue.d.tsdiff --git a/packages/editor/dist/hooks/useRefValue.js b/packages/editor/dist/cjs/hooks/useRefValue.jssimilarity index 67%rename from packages/editor/dist/hooks/useRefValue.jsrename to packages/editor/dist/cjs/hooks/useRefValue.jsindex 5a728b9cc..5e12e9374 100644--- a/packages/editor/dist/hooks/useRefValue.js+++ b/packages/editor/dist/cjs/hooks/useRefValue.js@@ -1,10 +1,10 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.useRefValue = void 0;-var react_1 = require("react");+const react_1 = require("react");function useRefValue(value) {- var refValue = (0, react_1.useRef)(value);- (0, react_1.useEffect)(function () {+ const refValue = (0, react_1.useRef)(value);+ (0, react_1.useEffect)(() => {refValue.current = value;}, [value]);return refValue;diff --git a/packages/editor/dist/index.d.ts b/packages/editor/dist/cjs/index.d.tssimilarity index 64%rename from packages/editor/dist/index.d.tsrename to packages/editor/dist/cjs/index.d.tsindex 5faf010a1..cd47cb2da 100644--- a/packages/editor/dist/index.d.ts+++ b/packages/editor/dist/cjs/index.d.ts@@ -1,14 +1,14 @@/// <reference types="react" />import "./extensions";-import { EditorOptions } from "@tiptap/react";import Toolbar from "./toolbar";import { Theme } from "@notesnook/theme";import { AttachmentOptions } from "./extensions/attachment";-import { Editor } from "./types";+import { EditorOptions } from "@tiptap/core";declare const useTiptap: (options?: Partial<EditorOptions & AttachmentOptions & {theme: Theme;-}>, deps?: import("react").DependencyList) => Editor | null;+}>, deps?: import("react").DependencyList) => import("./types").Editor;export { useTiptap, Toolbar };export * from "./types";export * from "./extensions/react";-export * from "./toolbar/tool-definitions";+export * from "./toolbar";+export { type AttachmentType } from "./extensions/attachment";diff --git a/packages/editor/dist/index.js b/packages/editor/dist/cjs/index.jssimilarity index 56%rename from packages/editor/dist/index.jsrename to packages/editor/dist/cjs/index.jsindex 5c2876507..98787115b 100644--- a/packages/editor/dist/index.js+++ b/packages/editor/dist/cjs/index.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {if (k2 === undefined) k2 = k;var desc = Object.getOwnPropertyDescriptor(m, k);@@ -41,60 +30,58 @@ var __importDefault = (this && this.__importDefault) || function (mod) {Object.defineProperty(exports, "__esModule", { value: true });exports.Toolbar = exports.useTiptap = void 0;require("./extensions");-var extension_character_count_1 = __importDefault(require("@tiptap/extension-character-count"));-var extension_placeholder_1 = __importDefault(require("@tiptap/extension-placeholder"));-var extension_underline_1 = __importDefault(require("@tiptap/extension-underline"));-var react_1 = require("@tiptap/react");-var starter_kit_1 = __importDefault(require("@tiptap/starter-kit"));-var react_2 = require("react");-var prosemirror_view_1 = require("prosemirror-view");-var toolbar_1 = __importDefault(require("./toolbar"));+const extension_character_count_1 = __importDefault(require("@tiptap/extension-character-count"));+const extension_placeholder_1 = __importDefault(require("@tiptap/extension-placeholder"));+const extension_underline_1 = __importDefault(require("@tiptap/extension-underline"));+const starter_kit_1 = __importDefault(require("@tiptap/starter-kit"));+const react_1 = require("react");+const prosemirror_view_1 = require("prosemirror-view");+const toolbar_1 = __importDefault(require("./toolbar"));exports.Toolbar = toolbar_1.default;-var extension_text_align_1 = __importDefault(require("@tiptap/extension-text-align"));-var extension_subscript_1 = __importDefault(require("@tiptap/extension-subscript"));-var extension_superscript_1 = __importDefault(require("@tiptap/extension-superscript"));-var fontsize_1 = __importDefault(require("./extensions/fontsize"));-var textdirection_1 = __importDefault(require("./extensions/textdirection"));-var extension_text_style_1 = __importDefault(require("@tiptap/extension-text-style"));-var extension_font_family_1 = __importDefault(require("@tiptap/extension-font-family"));-var bulletlist_1 = __importDefault(require("./extensions/bulletlist"));-var orderedlist_1 = __importDefault(require("./extensions/orderedlist"));-var extension_highlight_1 = __importDefault(require("@tiptap/extension-highlight"));-var extension_color_1 = __importDefault(require("@tiptap/extension-color"));-var extension_table_row_1 = __importDefault(require("@tiptap/extension-table-row"));-var tablecell_1 = __importDefault(require("./extensions/tablecell"));-var extension_table_header_1 = __importDefault(require("@tiptap/extension-table-header"));-var image_1 = require("./extensions/image");-var attachment_1 = require("./extensions/attachment");-var tasklist_1 = require("./extensions/tasklist");-var taskitem_1 = require("./extensions/taskitem");-var dropcursor_1 = require("./extensions/dropcursor");-var searchreplace_1 = require("./extensions/searchreplace");-var embed_1 = require("./extensions/embed");-var codeblock_1 = require("./extensions/codeblock");-var listitem_1 = require("./extensions/listitem");-var extension_link_1 = require("@tiptap/extension-link");-var codemark_1 = require("./extensions/codemark");-var math_1 = require("./extensions/math");-var react_3 = require("./extensions/react");-var outlinelist_1 = require("./extensions/outlinelist");-var outlinelistitem_1 = require("./extensions/outlinelistitem");-var table_1 = require("./extensions/table");-var toolbarstore_1 = require("./toolbar/stores/toolbarstore");+const extension_text_align_1 = __importDefault(require("@tiptap/extension-text-align"));+const extension_subscript_1 = __importDefault(require("@tiptap/extension-subscript"));+const extension_superscript_1 = __importDefault(require("@tiptap/extension-superscript"));+const fontsize_1 = __importDefault(require("./extensions/fontsize"));+const textdirection_1 = __importDefault(require("./extensions/textdirection"));+const extension_text_style_1 = __importDefault(require("@tiptap/extension-text-style"));+const extension_font_family_1 = __importDefault(require("@tiptap/extension-font-family"));+const bulletlist_1 = __importDefault(require("./extensions/bulletlist"));+const orderedlist_1 = __importDefault(require("./extensions/orderedlist"));+const extension_highlight_1 = __importDefault(require("@tiptap/extension-highlight"));+const extension_color_1 = __importDefault(require("@tiptap/extension-color"));+const extension_table_row_1 = __importDefault(require("@tiptap/extension-table-row"));+const tablecell_1 = __importDefault(require("./extensions/tablecell"));+const extension_table_header_1 = __importDefault(require("@tiptap/extension-table-header"));+const image_1 = require("./extensions/image");+const attachment_1 = require("./extensions/attachment");+const tasklist_1 = require("./extensions/tasklist");+const taskitem_1 = require("./extensions/taskitem");+const dropcursor_1 = require("./extensions/dropcursor");+const searchreplace_1 = require("./extensions/searchreplace");+const embed_1 = require("./extensions/embed");+const codeblock_1 = require("./extensions/codeblock");+const listitem_1 = require("./extensions/listitem");+const extension_link_1 = require("@tiptap/extension-link");+const codemark_1 = require("./extensions/codemark");+const math_1 = require("./extensions/math");+const react_2 = require("./extensions/react");+const outlinelist_1 = require("./extensions/outlinelist");+const outlinelistitem_1 = require("./extensions/outlinelistitem");+const table_1 = require("./extensions/table");+const toolbarstore_1 = require("./toolbar/stores/toolbarstore");+const useEditor_1 = require("./hooks/useEditor");prosemirror_view_1.EditorView.prototype.updateState = function updateState(state) {if (!this.docView)return; // This prevents the matchesNode error on hot reloadsthis.updateStateInner(state, this.state.plugins != state.plugins);};-var useTiptap = function (options, deps) {- if (options === void 0) { options = {}; }- if (deps === void 0) { deps = []; }- var theme = options.theme, onDownloadAttachment = options.onDownloadAttachment, onOpenAttachmentPicker = options.onOpenAttachmentPicker, restOptions = __rest(options, ["theme", "onDownloadAttachment", "onOpenAttachmentPicker"]);- var PortalProviderAPI = (0, react_3.usePortalProvider)();- var isMobile = (0, toolbarstore_1.useIsMobile)();- var defaultOptions = (0, react_2.useMemo)(function () { return ({+const useTiptap = (options = {}, deps = []) => {+ const { theme, onDownloadAttachment, onOpenAttachmentPicker } = options, restOptions = __rest(options, ["theme", "onDownloadAttachment", "onOpenAttachmentPicker"]);+ const PortalProviderAPI = (0, react_2.usePortalProvider)();+ const isMobile = (0, toolbarstore_1.useIsMobile)();+ const defaultOptions = (0, react_1.useMemo)(() => ({extensions: [- react_3.NodeViewSelectionNotifier,+ react_2.NodeViewSelectionNotifier,searchreplace_1.SearchReplace,extension_text_style_1.default,starter_kit_1.default.configure({@@ -147,8 +134,8 @@ var useTiptap = function (options, deps) {image_1.ImageNode,embed_1.EmbedNode,attachment_1.AttachmentNode.configure({- onDownloadAttachment: onDownloadAttachment,- onOpenAttachmentPicker: onOpenAttachmentPicker,+ onDownloadAttachment,+ onOpenAttachmentPicker,}),outlinelistitem_1.OutlineListItem,outlinelist_1.OutlineList,@@ -157,31 +144,30 @@ var useTiptap = function (options, deps) {math_1.MathInline,math_1.MathBlock,],- onBeforeCreate: function (_a) {- var editor = _a.editor;+ onBeforeCreate: ({ editor }) => {if (theme) {editor.storage.theme = theme;}editor.storage.portalProviderAPI = PortalProviderAPI;},injectCSS: false,- }); }, [+ }), [theme,onDownloadAttachment,onOpenAttachmentPicker,PortalProviderAPI,isMobile,]);- var editor = (0, react_1.useEditor)(__assign(__assign({}, defaultOptions), restOptions), deps);- var editorRef = (0, react_2.useRef)(editor);- (0, react_2.useEffect)(function () {+ const editor = (0, useEditor_1.useEditor)(Object.assign(Object.assign({}, defaultOptions), restOptions), deps);+ const editorRef = (0, react_1.useRef)(editor);+ (0, react_1.useEffect)(() => {editorRef.current = editor;if (editor && !editor.current)Object.defineProperty(editor, "current", {- get: function () { return editorRef.current; },+ get: () => editorRef.current,});}, [editor]);- (0, react_2.useEffect)(function () {+ (0, react_1.useEffect)(() => {function onDragEnter(event) {if (!!(editor === null || editor === void 0 ? void 0 : editor.view.dragging)) {event.preventDefault();@@ -189,7 +175,7 @@ var useTiptap = function (options, deps) {}}editor === null || editor === void 0 ? void 0 : editor.view.dom.addEventListener("dragenter", onDragEnter);- return function () {+ return () => {editor === null || editor === void 0 ? void 0 : editor.view.dom.removeEventListener("dragenter", onDragEnter);};}, [editor === null || editor === void 0 ? void 0 : editor.view.dom]);@@ -198,4 +184,4 @@ var useTiptap = function (options, deps) {exports.useTiptap = useTiptap;__exportStar(require("./types"), exports);__exportStar(require("./extensions/react"), exports);-__exportStar(require("./toolbar/tooldefinitions"), exports);+__exportStar(require("./toolbar"), exports);diff --git a/packages/editor/dist/cjs/package.json b/packages/editor/dist/cjs/package.jsonnew file mode 100644index 000000000..1cd945a3b--- /dev/null+++ b/packages/editor/dist/cjs/package.json@@ -0,0 +1,3 @@+{+ "type": "commonjs"+}diff --git a/packages/editor/dist/toolbar/components/counter.d.ts b/packages/editor/dist/cjs/toolbar/components/counter.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/counter.d.tsrename to packages/editor/dist/cjs/toolbar/components/counter.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/components/counter.js b/packages/editor/dist/cjs/toolbar/components/counter.jsnew file mode 100644index 000000000..ea7b50427--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/counter.js@@ -0,0 +1,31 @@+"use strict";+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.Counter = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importDefault(require("react"));+const rebass_1 = require("rebass");+const button_1 = require("../../components/button");+const toolbutton_1 = require("./toolbutton");+function _Counter(props) {+ const { title, onDecrease, onIncrease, onReset, value } = props;+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ alignItems: "center",+ mr: 1,+ ":last-of-type": {+ mr: 0,+ },+ } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: `Decrease ${title}`, icon: "minus", variant: "small", onClick: onDecrease }), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ sx: {+ color: "text",+ bg: "transparent",+ px: 0,+ fontSize: "subBody",+ mx: 1,+ textAlign: "center",+ }, onClick: onReset, title: `Reset ${title}` }, { children: value })), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: `Increase ${title}`, icon: "plus", variant: "small", onClick: onIncrease })] })));+}+exports.Counter = react_1.default.memo(_Counter, (prev, next) => {+ return prev.value === next.value;+});diff --git a/packages/editor/dist/toolbar/components/dropdown.d.ts b/packages/editor/dist/cjs/toolbar/components/dropdown.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/dropdown.d.tsrename to packages/editor/dist/cjs/toolbar/components/dropdown.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/components/dropdown.js b/packages/editor/dist/cjs/toolbar/components/dropdown.jsnew file mode 100644index 000000000..bf3eb0004--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/dropdown.js@@ -0,0 +1,52 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Dropdown = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const rebass_1 = require("rebass");+const icon_1 = require("./icon");+const icons_1 = require("../icons");+const toolbarstore_1 = require("../stores/toolbarstore");+const menu_1 = require("../../components/menu");+const dom_1 = require("../utils/dom");+function Dropdown(props) {+ const { items, selectedItem, buttonRef, menuWidth } = props;+ const internalRef = (0, react_1.useRef)();+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ const isMobile = (0, toolbarstore_1.useIsMobile)();+ const isBottom = toolbarLocation === "bottom";+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Button, Object.assign({ ref: (ref) => {+ internalRef.current = ref;+ if (buttonRef)+ buttonRef.current = ref;+ }, sx: {+ p: 1,+ m: 0,+ bg: isOpen ? "hover" : "transparent",+ mr: 1,+ display: "flex",+ alignItems: "center",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onClick: () => setIsOpen((s) => !s), onMouseDown: (e) => e.preventDefault() }, { children: [typeof selectedItem === "string" ? ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: isBottom ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, size: "small", color: "text" })] })), (0, jsx_runtime_1.jsx)(menu_1.MenuPresenter, { isOpen: isOpen, items: items, onClose: () => setIsOpen(false), position: {+ target: isBottom+ ? (0, dom_1.getToolbarElement)()+ : internalRef.current || "mouse",+ isTargetAbsolute: true,+ location: isBottom ? "top" : "below",+ align: "center",+ yOffset: 5,+ }, blocking: !isMobile, focusOnRender: !isMobile, sx: {+ minWidth: menuWidth,+ maxWidth: isBottom ? "95vw" : "auto",+ flexDirection: isBottom ? "row" : "column",+ overflowX: isBottom ? "auto" : "hidden",+ marginRight: isBottom ? "10px" : 0,+ display: "flex",+ alignItems: isBottom ? "center" : "unset",+ } })] }));+}+exports.Dropdown = Dropdown;diff --git a/packages/editor/dist/toolbar/components/icon.d.ts b/packages/editor/dist/cjs/toolbar/components/icon.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/icon.d.tsrename to packages/editor/dist/cjs/toolbar/components/icon.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/components/icon.js b/packages/editor/dist/cjs/toolbar/components/icon.jsnew file mode 100644index 000000000..3871155dc--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/icon.js@@ -0,0 +1,36 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.Icon = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importDefault(require("@mdi/react"));+const emotion_theming_1 = require("emotion-theming");+const rebass_1 = require("rebass");+function MDIIconWrapper({ title, path, size = 24, color = "icon", stroke, rotate, }) {+ const theme = (0, emotion_theming_1.useTheme)();+ const themedColor = theme.colors+ ? theme.colors[color]+ : color;+ return ((0, jsx_runtime_1.jsx)(react_1.default, { className: "icon", title: title, path: path, size: typeof size === "string" ? `${theme.iconSizes[size]}px` : `${size}px`, style: {+ strokeWidth: stroke || "0px",+ stroke: themedColor,+ }, color: themedColor, spin: rotate }));+}+function Icon(props) {+ const { sx, title, color, size, stroke, rotate, path } = props, restProps = __rest(props, ["sx", "title", "color", "size", "stroke", "rotate", "path"]);+ return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: Object.assign({ flexShrink: 0, justifyContent: "center", alignItems: "center" }, sx) }, restProps, { children: (0, jsx_runtime_1.jsx)(MDIIconWrapper, { title: title, path: path, rotate: rotate, color: color, stroke: stroke, size: size }) })));+}+exports.Icon = Icon;diff --git a/packages/editor/dist/toolbar/components/moretools.d.ts b/packages/editor/dist/cjs/toolbar/components/moretools.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/moretools.d.tsrename to packages/editor/dist/cjs/toolbar/components/moretools.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/components/moretools.js b/packages/editor/dist/cjs/toolbar/components/moretools.jsnew file mode 100644index 000000000..a50c616b3--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/moretools.js@@ -0,0 +1,33 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.MoreTools = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const popuppresenter_1 = require("../../components/popuppresenter");+const toolbutton_1 = require("../components/toolbutton");+const toolbarstore_1 = require("../stores/toolbarstore");+const dom_1 = require("../utils/dom");+const toolbargroup_1 = require("./toolbargroup");+function MoreTools(props) {+ const { popupId, editor, tools, autoCloseOnUnmount } = props;+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ const isBottom = toolbarLocation === "bottom";+ const buttonRef = (0, react_1.useRef)();+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: isOpen, buttonRef: buttonRef, onClick: () => setIsOpen((s) => !s) })), (0, jsx_runtime_1.jsx)(popuppresenter_1.PopupWrapper, { isOpen: isOpen, group: "toolbarGroup", id: popupId, onClosed: () => setIsOpen(false), position: {+ isTargetAbsolute: true,+ target: isBottom ? (0, dom_1.getToolbarElement)() : buttonRef.current || "mouse",+ align: "center",+ location: isBottom ? "top" : "below",+ yOffset: isBottom ? 10 : 5,+ }, autoCloseOnUnmount: autoCloseOnUnmount, focusOnRender: false, blocking: false, renderPopup: () => ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { tools: tools, editor: editor, sx: {+ flex: 1,+ p: 1,+ boxShadow: "menu",+ bg: "background",+ borderRadius: "default",+ overflowX: "auto",+ maxWidth: "95vw",+ } })) })] }));+}+exports.MoreTools = MoreTools;diff --git a/packages/editor/dist/toolbar/components/popup.d.ts b/packages/editor/dist/cjs/toolbar/components/popup.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/popup.d.tsrename to packages/editor/dist/cjs/toolbar/components/popup.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/components/popup.js b/packages/editor/dist/cjs/toolbar/components/popup.jsnew file mode 100644index 000000000..05d5c6e1e--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/popup.js@@ -0,0 +1,31 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Popup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const icon_1 = require("./icon");+const icons_1 = require("../icons");+const responsive_1 = require("../../components/responsive");+function Popup(props) {+ const { title, onClose, action, children } = props;+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ overflow: "hidden",+ bg: "background",+ flexDirection: "column",+ borderRadius: "default",+ // border: "1px solid var(--border)",+ boxShadow: "menu",+ minWidth: 200,+ } }, { children: [title && ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ className: "movable", sx: {+ justifyContent: "space-between",+ alignItems: "center",+ p: 2,+ } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "title" }, { children: title })), (0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({ variant: "tool", sx: { p: 0, bg: "transparent" }, onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.close, size: "big" }) }))] }))), children, title && action && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: { justifyContent: "end" }, bg: "bgSecondary", p: 1, px: 2, mt: 2 }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({ variant: "dialog", onClick: action.disabled || action.loading ? undefined : action.onClick, disabled: action.disabled || action.loading }, { children: action.loading ? ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.loading, rotate: true, size: "medium" })) : (action.title) })) })))] })) }), (0, jsx_runtime_1.jsxs)(responsive_1.MobileOnly, { children: [children, action && ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({ variant: "primary", sx: {+ alignSelf: "stretch",+ mb: 1,+ mt: 2,+ mx: 1,+ py: 2,+ }, onClick: action.disabled ? undefined : action === null || action === void 0 ? void 0 : action.onClick, disabled: action.disabled }, { children: action.loading ? ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.loading, rotate: true, size: "medium" })) : (action.title) })))] })] }));+}+exports.Popup = Popup;diff --git a/packages/editor/dist/toolbar/components/splitbutton.d.ts b/packages/editor/dist/cjs/toolbar/components/splitbutton.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/splitbutton.d.tsrename to packages/editor/dist/cjs/toolbar/components/splitbutton.d.tsdiff --git a/packages/editor/dist/toolbar/components/splitbutton.js b/packages/editor/dist/cjs/toolbar/components/splitbutton.jssimilarity index 55%rename from packages/editor/dist/toolbar/components/splitbutton.jsrename to packages/editor/dist/cjs/toolbar/components/splitbutton.jsindex dadabc1b5..a27cee118 100644--- a/packages/editor/dist/toolbar/components/splitbutton.js+++ b/packages/editor/dist/cjs/toolbar/components/splitbutton.js@@ -1,15 +1,4 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};var __rest = (this && this.__rest) || function (s, e) {var t = {};for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)@@ -26,24 +15,24 @@ var __importDefault = (this && this.__importDefault) || function (mod) {};Object.defineProperty(exports, "__esModule", { value: true });exports.SplitButton = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var rebass_1 = require("rebass");-var icons_1 = require("../icons");-var icon_1 = require("./icon");-var toolbutton_1 = require("./toolbutton");-var toolbarstore_1 = require("../stores/toolbarstore");-var button_1 = require("../../components/button");-var react_2 = __importDefault(require("react"));+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const rebass_1 = require("rebass");+const icons_1 = require("../icons");+const icon_1 = require("./icon");+const toolbutton_1 = require("./toolbutton");+const toolbarstore_1 = require("../stores/toolbarstore");+const button_1 = require("../../components/button");+const react_2 = __importDefault(require("react"));function _SplitButton(props) {- var children = props.children, toggled = props.toggled, onOpen = props.onOpen, toolButtonProps = __rest(props, ["children", "toggled", "onOpen"]);- var ref = (0, react_1.useRef)(null);- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ ref: ref, sx: {+ const { children, toggled, onOpen } = props, toolButtonProps = __rest(props, ["children", "toggled", "onOpen"]);+ const ref = (0, react_1.useRef)(null);+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ ref: ref, sx: {borderRadius: "default",bg: toggled ? "hover" : "transparent",":hover": { bg: "hover" },- } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, toolButtonProps, { toggled: toggled })), (0, jsx_runtime_1.jsx)(button_1.Button, __assign({ sx: {+ } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolButtonProps, { toggled: toggled })), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ sx: {p: 0,m: 0,bg: toggled ? "hover" : "transparent",@@ -53,6 +42,6 @@ function _SplitButton(props) {},}, onClick: onOpen }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: toolbarLocation === "bottom" ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, color: "text", size: "small" }) }))] })), children] }));}-exports.SplitButton = react_2.default.memo(_SplitButton, function (prev, next) {+exports.SplitButton = react_2.default.memo(_SplitButton, (prev, next) => {return prev.toggled === next.toggled;});diff --git a/packages/editor/dist/toolbar/components/toolbargroup.d.ts b/packages/editor/dist/cjs/toolbar/components/toolbargroup.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/components/toolbargroup.d.tsrename to packages/editor/dist/cjs/toolbar/components/toolbargroup.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/components/toolbargroup.js b/packages/editor/dist/cjs/toolbar/components/toolbargroup.jsnew file mode 100644index 000000000..666079473--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/toolbargroup.js@@ -0,0 +1,33 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.ToolbarGroup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const tools_1 = require("../tools");+const rebass_1 = require("rebass");+const moretools_1 = require("./moretools");+const tooldefinitions_1 = require("../tooldefinitions");+function ToolbarGroup(props) {+ const { tools, editor, force, selectedNode } = props, flexProps = __rest(props, ["tools", "editor", "force", "selectedNode"]);+ return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ className: "toolbar-group" }, flexProps, { children: tools.map((toolId) => {+ if (Array.isArray(toolId)) {+ return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, { title: "More", icon: "more", popupId: toolId.join(""), tools: toolId, editor: editor }, "more-tools"));+ }+ else {+ const Component = (0, tools_1.findTool)(toolId);+ const toolDefinition = (0, tooldefinitions_1.getToolDefinition)(toolId);+ return ((0, jsx_runtime_1.jsx)(Component, Object.assign({ editor: editor, force: force, selectedNode: selectedNode }, toolDefinition), toolDefinition.title));+ }+ }) })));+}+exports.ToolbarGroup = ToolbarGroup;diff --git a/packages/editor/dist/toolbar/components/toolbutton.d.ts b/packages/editor/dist/cjs/toolbar/components/toolbutton.d.tssimilarity index 72%rename from packages/editor/dist/toolbar/components/toolbutton.d.tsrename to packages/editor/dist/cjs/toolbar/components/toolbutton.d.tsindex c5b117976..d7cb97dd4 100644--- a/packages/editor/dist/toolbar/components/toolbutton.d.ts+++ b/packages/editor/dist/cjs/toolbar/components/toolbutton.d.ts@@ -14,8 +14,8 @@ export declare type ToolButtonProps = ButtonProps & {};export declare const ToolButton: React.NamedExoticComponent<ButtonProps & {icon: IconNames;- iconColor?: "background" | "border" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "icon" | "overlay" | "hover" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "bgSecondaryHover" | "fontSecondary" | "fontTertiary" | "secondary" | undefined;- iconSize?: number | "small" | "big" | "medium" | undefined;+ iconColor?: "background" | "border" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "icon" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "bgSecondaryHover" | "hover" | "fontSecondary" | "fontTertiary" | "overlay" | "secondary" | undefined;+ iconSize?: number | "big" | "small" | "medium" | undefined;toggled: boolean;buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined> | undefined;variant?: ToolButtonVariant | undefined;diff --git a/packages/editor/dist/cjs/toolbar/components/toolbutton.js b/packages/editor/dist/cjs/toolbar/components/toolbutton.jsnew file mode 100644index 000000000..21ca592ae--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/components/toolbutton.js@@ -0,0 +1,30 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.ToolButton = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importDefault(require("react"));+const icons_1 = require("../icons");+const button_1 = require("../../components/button");+const icon_1 = require("./icon");+exports.ToolButton = react_1.default.memo(function ToolButton(props) {+ const { id, icon, iconSize, iconColor, toggled, sx, buttonRef, variant = "normal" } = props, buttonProps = __rest(props, ["id", "icon", "iconSize", "iconColor", "toggled", "sx", "buttonRef", "variant"]);+ return ((0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ ref: buttonRef, tabIndex: -1, id: `tool-${id || icon}`, sx: Object.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: (e) => e.preventDefault() }, buttonProps, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons[icon], color: iconColor || "icon", size: iconSize || (variant === "small" ? "medium" : "big") }) })));+}, (prev, next) => {+ return prev.toggled === next.toggled;+});diff --git a/packages/editor/dist/toolbar/floatingmenus/hoverpopup/index.d.ts b/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/index.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/floatingmenus/hoverpopup/index.d.tsrename to packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/index.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/index.js b/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/index.jsnew file mode 100644index 000000000..265d9012e--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/index.js@@ -0,0 +1,70 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.HoverPopupHandler = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = require("react");+const popuppresenter_1 = require("../../../components/popuppresenter");+const link_1 = require("./link");+const handlers = Object.assign({}, link_1.LinkHoverPopupHandler);+const HOVER_TIMEOUT = 500;+function HoverPopupHandler(props) {+ const { editor } = props;+ const hoverTimeoutId = (0, react_1.useRef)();+ const activePopup = (0, react_1.useRef)();+ (0, react_1.useEffect)(() => {+ function onMouseOver(e) {+ if (!e.target ||+ !(e.target instanceof HTMLElement) ||+ e.target.classList.contains("ProseMirror"))+ return;+ const element = e.target;+ if (activePopup.current) {+ const isOutsideEditor = !element.closest(".ProseMirror");+ const isInsidePopup = element.closest(".popup-presenter-portal");+ const isActiveElement = activePopup.current.element === element;+ if (isInsidePopup)+ return;+ if (isOutsideEditor || !isActiveElement) {+ console.log("HIDING", isOutsideEditor, isActiveElement, element);+ activePopup.current.hide();+ activePopup.current = undefined;+ return;+ }+ }+ clearTimeout(hoverTimeoutId.current);+ hoverTimeoutId.current = setTimeout(() => {+ const nodeName = element.nodeName.toLowerCase();+ const PopupHandler = handlers[nodeName];+ if (!PopupHandler || !editor.current)+ return;+ const pos = editor.current.view.posAtDOM(element, 0);+ const node = editor.current.view.state.doc.nodeAt(pos);+ if (!node)+ return;+ const hidePopup = (0, popuppresenter_1.showPopup)({+ popup: () => ((0, jsx_runtime_1.jsx)(PopupHandler, { editor: editor, selectedNode: {+ node,+ from: pos,+ to: pos + node.nodeSize,+ } })),+ theme: editor.storage.theme,+ blocking: false,+ focusOnRender: false,+ position: {+ target: element,+ align: "center",+ location: "top",+ isTargetAbsolute: true,+ },+ });+ activePopup.current = { element, hide: hidePopup };+ }, HOVER_TIMEOUT, {});+ }+ window.addEventListener("mouseover", onMouseOver);+ return () => {+ window.removeEventListener("mouseover", onMouseOver);+ };+ }, []);+ return null;+}+exports.HoverPopupHandler = HoverPopupHandler;diff --git a/packages/editor/dist/toolbar/floatingmenus/hoverpopup/link.d.ts b/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/link.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/floatingmenus/hoverpopup/link.d.tsrename to packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/link.d.tsdiff --git a/packages/editor/dist/toolbar/floatingmenus/hoverpopup/link.js b/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/link.jssimilarity index 66%rename from packages/editor/dist/toolbar/floatingmenus/hoverpopup/link.jsrename to packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/link.jsindex 69503c1bd..235df0cd7 100644--- a/packages/editor/dist/toolbar/floatingmenus/hoverpopup/link.js+++ b/packages/editor/dist/cjs/toolbar/floatingmenus/hoverpopup/link.js@@ -1,14 +1,14 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.LinkHoverPopupHandler = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbargroup_1 = require("../../components/toolbargroup");+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbargroup_1 = require("../../components/toolbargroup");function LinkHoverPopup(props) {- var editor = props.editor, selectedNode = props.selectedNode;- var node = selectedNode.node;+ const { editor, selectedNode } = props;+ const { node } = selectedNode;if (!node.isText ||node.marks.length <= 0 ||- !node.marks.some(function (mark) { return mark.type.name === "link"; }))+ !node.marks.some((mark) => mark.type.name === "link"))return null;return ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { force: true, tools: ["openLink", "editLink", "removeLink"], editor: editor, selectedNode: selectedNode, sx: {bg: "background",diff --git a/packages/editor/dist/toolbar/floatingmenus/index.d.ts b/packages/editor/dist/cjs/toolbar/floatingmenus/index.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/floatingmenus/index.d.tsrename to packages/editor/dist/cjs/toolbar/floatingmenus/index.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/floatingmenus/index.js b/packages/editor/dist/cjs/toolbar/floatingmenus/index.jsnew file mode 100644index 000000000..ba8dc358d--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/floatingmenus/index.js@@ -0,0 +1,10 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.EditorFloatingMenus = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const hoverpopup_1 = require("./hoverpopup");+const searchreplace_1 = require("./searchreplace");+function EditorFloatingMenus(props) {+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(searchreplace_1.SearchReplaceFloatingMenu, Object.assign({}, props)), (0, jsx_runtime_1.jsx)(hoverpopup_1.HoverPopupHandler, Object.assign({}, props))] }));+}+exports.EditorFloatingMenus = EditorFloatingMenus;diff --git a/packages/editor/dist/toolbar/floatingmenus/searchreplace.d.ts b/packages/editor/dist/cjs/toolbar/floatingmenus/searchreplace.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/floatingmenus/searchreplace.d.tsrename to packages/editor/dist/cjs/toolbar/floatingmenus/searchreplace.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/floatingmenus/searchreplace.js b/packages/editor/dist/cjs/toolbar/floatingmenus/searchreplace.jsnew file mode 100644index 000000000..a00bb207a--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/floatingmenus/searchreplace.js@@ -0,0 +1,19 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.SearchReplaceFloatingMenu = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const searchreplace_1 = require("../popups/searchreplace");+const responsive_1 = require("../../components/responsive");+const dom_1 = require("../utils/dom");+function SearchReplaceFloatingMenu(props) {+ const { editor } = props;+ const { isSearching } = editor.storage.searchreplace;+ return ((0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, Object.assign({ mobile: "sheet", desktop: "menu", isOpen: isSearching, onClose: () => editor.commands.endSearch(), position: {+ target: (0, dom_1.getToolbarElement)(),+ isTargetAbsolute: true,+ location: "below",+ align: "end",+ yOffset: 5,+ }, blocking: false, focusOnRender: false, draggable: false }, { children: (0, jsx_runtime_1.jsx)(searchreplace_1.SearchReplacePopup, { editor: editor }) })));+}+exports.SearchReplaceFloatingMenu = SearchReplaceFloatingMenu;diff --git a/packages/editor/dist/toolbar/floatingmenus/types.d.ts b/packages/editor/dist/cjs/toolbar/floatingmenus/types.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/floatingmenus/types.d.tsrename to packages/editor/dist/cjs/toolbar/floatingmenus/types.d.tsdiff --git a/packages/editor/dist/toolbar/floatingmenus/types.js b/packages/editor/dist/cjs/toolbar/floatingmenus/types.jssimilarity index 100%rename from packages/editor/dist/toolbar/floatingmenus/types.jsrename to packages/editor/dist/cjs/toolbar/floatingmenus/types.jsdiff --git a/packages/editor/dist/toolbar/icons.d.ts b/packages/editor/dist/cjs/toolbar/icons.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/icons.d.tsrename to packages/editor/dist/cjs/toolbar/icons.d.tsdiff --git a/packages/editor/dist/toolbar/icons.js b/packages/editor/dist/cjs/toolbar/icons.jssimilarity index 98%rename from packages/editor/dist/toolbar/icons.jsrename to packages/editor/dist/cjs/toolbar/icons.jsindex e4ee57b95..a3a6af50e 100644--- a/packages/editor/dist/toolbar/icons.js+++ b/packages/editor/dist/cjs/toolbar/icons.js@@ -1,14 +1,14 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.Icons = void 0;-var js_1 = require("@mdi/js");+const js_1 = require("@mdi/js");exports.Icons = {bold: js_1.mdiFormatBold,italic: js_1.mdiFormatItalic,underline: js_1.mdiFormatUnderline,strikethrough: js_1.mdiFormatStrikethrough,code: js_1.mdiCodeTags,- codeRemove: "M3.62109375 1.83837892 2.26318358 3.13037107 6.46289063 7.536621 1.9995117 12l6.0000003 6 1.40039025-1.400391L4.80029295 12l3.0292968-3.0292965 7.0283205 7.371093-.2578125.2578125L16.000488 18l.224121-.224121 4.3125 4.52490225 1.35791025-1.29492225-4.34326125-4.55712825L22.000488 12l-6-6-1.40039025 1.40039063L19.19970675 12l-3.016113 3.016113L9.156738 7.6435545l.24316425-.24316387L7.999512 6l-.2109375.2109375Z",+ codeRemove: `M3.62109375 1.83837892 2.26318358 3.13037107 6.46289063 7.536621 1.9995117 12l6.0000003 6 1.40039025-1.400391L4.80029295 12l3.0292968-3.0292965 7.0283205 7.371093-.2578125.2578125L16.000488 18l.224121-.224121 4.3125 4.52490225 1.35791025-1.29492225-4.34326125-4.55712825L22.000488 12l-6-6-1.40039025 1.40039063L19.19970675 12l-3.016113 3.016113L9.156738 7.6435545l.24316425-.24316387L7.999512 6l-.2109375.2109375Z`,alignCenter: js_1.mdiFormatAlignCenter,alignLeft: js_1.mdiFormatAlignLeft,alignRight: js_1.mdiFormatAlignRight,diff --git a/packages/editor/dist/cjs/toolbar/index.d.ts b/packages/editor/dist/cjs/toolbar/index.d.tsnew file mode 100644index 000000000..37d1c1dbe--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/index.d.ts@@ -0,0 +1,7 @@+import { Toolbar } from "./toolbar";+export default Toolbar;+export * from "./types";+export * from "./icons";+export * from "./components/icon";+export * from "./tools";+export * from "./tool-definitions";diff --git a/packages/editor/dist/cjs/toolbar/index.js b/packages/editor/dist/cjs/toolbar/index.jsnew file mode 100644index 000000000..dae96e0b8--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/index.js@@ -0,0 +1,23 @@+"use strict";+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ var desc = Object.getOwnPropertyDescriptor(m, k);+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {+ desc = { enumerable: true, get: function() { return m[k]; } };+ }+ Object.defineProperty(o, k2, desc);+}) : (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ o[k2] = m[k];+}));+var __exportStar = (this && this.__exportStar) || function(m, exports) {+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);+};+Object.defineProperty(exports, "__esModule", { value: true });+const toolbar_1 = require("./toolbar");+exports.default = toolbar_1.Toolbar;+__exportStar(require("./types"), exports);+__exportStar(require("./icons"), exports);+__exportStar(require("./components/icon"), exports);+__exportStar(require("./tools"), exports);+__exportStar(require("./tooldefinitions"), exports);diff --git a/packages/editor/dist/toolbar/popups/cellproperties.d.ts b/packages/editor/dist/cjs/toolbar/popups/cellproperties.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/cellproperties.d.tsrename to packages/editor/dist/cjs/toolbar/popups/cellproperties.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/cellproperties.js b/packages/editor/dist/cjs/toolbar/popups/cellproperties.jsnew file mode 100644index 000000000..2d63b6395--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/cellproperties.js@@ -0,0 +1,26 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.CellProperties = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const tabs_1 = require("../../components/tabs");+const icon_1 = require("../components/icon");+// import { MenuPresenter } from "../../components/menu/menu";+const popup_1 = require("../components/popup");+const icons_1 = require("../icons");+const colorpicker_1 = require("./colorpicker");+function CellProperties(props) {+ const { editor, onClose } = props;+ const attributes = editor.getAttributes("tableCell");+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ title: "Cell properties", onClose: onClose }, { children: (0, jsx_runtime_1.jsxs)(tabs_1.Tabs, Object.assign({ activeIndex: 0 }, { children: [(0, jsx_runtime_1.jsxs)(tabs_1.Tab, Object.assign({ title: (0, jsx_runtime_1.jsx)(icon_1.Icon, { title: "Cell background color", path: icons_1.Icons.backgroundColor, size: 16 }) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { mt: 2 }), (0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { expanded: true, color: attributes.backgroundColor, onChange: (color) => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", color);+ }, onClear: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", undefined);+ } })] })), (0, jsx_runtime_1.jsxs)(tabs_1.Tab, Object.assign({ title: (0, jsx_runtime_1.jsx)(icon_1.Icon, { title: "Cell text color", path: icons_1.Icons.textColor, size: 16 }) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { mt: 2 }), (0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { expanded: true, color: attributes.color, onChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", color); }, onClear: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", undefined); } })] })), (0, jsx_runtime_1.jsxs)(tabs_1.Tab, Object.assign({ title: (0, jsx_runtime_1.jsx)(icon_1.Icon, { title: "Cell border color", path: icons_1.Icons.cellBorderColor, size: 16 }) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { mt: 2 }), (0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { expanded: true, color: attributes.borderColor, onChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", color); }, onClear: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", undefined);+ } })] }))] })) })));+}+exports.CellProperties = CellProperties;diff --git a/packages/editor/dist/toolbar/popups/colorpicker.d.ts b/packages/editor/dist/cjs/toolbar/popups/colorpicker.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/colorpicker.d.tsrename to packages/editor/dist/cjs/toolbar/popups/colorpicker.d.tsdiff --git a/packages/editor/dist/toolbar/popups/colorpicker.js b/packages/editor/dist/cjs/toolbar/popups/colorpicker.jssimilarity index 52%rename from packages/editor/dist/toolbar/popups/colorpicker.jsrename to packages/editor/dist/cjs/toolbar/popups/colorpicker.jsindex 3426bcf6f..adab10663 100644--- a/packages/editor/dist/toolbar/popups/colorpicker.js+++ b/packages/editor/dist/cjs/toolbar/popups/colorpicker.js@@ -1,46 +1,19 @@"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};var __importDefault = (this && this.__importDefault) || function (mod) {return (mod && mod.__esModule) ? mod : { "default": mod };};Object.defineProperty(exports, "__esModule", { value: true });exports.ColorPicker = exports.DEFAULT_COLORS = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var forms_1 = require("@rebass/forms");-var icon_1 = require("../components/icon");-var icons_1 = require("../icons");-var react_1 = require("react");-var tinycolor2_1 = __importDefault(require("tinycolor2"));-var react_colorful_1 = require("react-colorful");-var button_1 = require("../../components/button");-var debounce_1 = require("../../utils/debounce");+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const forms_1 = require("@rebass/forms");+const icon_1 = require("../components/icon");+const icons_1 = require("../icons");+const react_1 = require("react");+const tinycolor2_1 = __importDefault(require("tinycolor2"));+const react_colorful_1 = require("react-colorful");+const button_1 = require("../../components/button");+const debounce_1 = require("../../utils/debounce");exports.DEFAULT_COLORS = ["#e91e63","#9c27b0",@@ -57,23 +30,23 @@ exports.DEFAULT_COLORS = ["#ffc107","#f44336",];-var PALETTE_SIZE = [35, 35, 25];+const PALETTE_SIZE = [35, 35, 25];function ColorPicker(props) {- var _a = props.colors, colors = _a === void 0 ? exports.DEFAULT_COLORS : _a, color = props.color, onClear = props.onClear, onChange = props.onChange, title = props.title, onClose = props.onClose, expanded = props.expanded;- var ref = (0, react_1.useRef)();- var _b = __read((0, react_1.useState)(expanded || false), 2), isPickerOpen = _b[0], setIsPickerOpen = _b[1];- var _c = __read((0, react_1.useState)((0, tinycolor2_1.default)(color || colors[0]).toHexString()), 2), currentColor = _c[0], setCurrentColor = _c[1];- var tColor = (0, tinycolor2_1.default)(currentColor);- (0, react_1.useEffect)(function () {+ const { colors = exports.DEFAULT_COLORS, color, onClear, onChange, title, onClose, expanded, } = props;+ const ref = (0, react_1.useRef)();+ const [isPickerOpen, setIsPickerOpen] = (0, react_1.useState)(expanded || false);+ const [currentColor, setCurrentColor] = (0, react_1.useState)((0, tinycolor2_1.default)(color || colors[0]).toHexString());+ const tColor = (0, tinycolor2_1.default)(currentColor);+ (0, react_1.useEffect)(() => {if (!ref.current)return;if (isPickerOpen)ref.current.focus({ preventScroll: true });}, [isPickerOpen]);- var onColorChange = (0, react_1.useCallback)((0, debounce_1.debounce)(function (color) {+ const onColorChange = (0, react_1.useCallback)((0, debounce_1.debounce)((color) => {onChange(color);}, 500), [onChange]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ ref: ref, tabIndex: -1, sx: {+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ ref: ref, tabIndex: -1, sx: {bg: "background",flexDirection: "column",".react-colorful": {@@ -85,17 +58,17 @@ function ColorPicker(props) {},width: ["calc(100vw - 20px)", 250],// width: ["auto", 250],- } }, { children: [onClose && ((0, jsx_runtime_1.jsxs)(rebass_1.Box, __assign({ sx: {+ } }, { children: [onClose && ((0, jsx_runtime_1.jsxs)(rebass_1.Box, Object.assign({ sx: {display: ["none", "flex"],justifyContent: "space-between",p: 2,pb: isPickerOpen ? 2 : 0,//pb: 0,alignItems: "center",- }, onClick: onClose }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "title" }, { children: title })), (0, jsx_runtime_1.jsx)(button_1.Button, __assign({ variant: "icon", sx: { p: 0 } }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.close, size: "big" }) }))] }))), isPickerOpen ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_colorful_1.HexColorPicker, { onChange: function (color) {+ }, onClick: onClose }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "title" }, { children: title })), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ variant: "icon", sx: { p: 0 } }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.close, size: "big" }) }))] }))), isPickerOpen ? ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(react_colorful_1.HexColorPicker, { onChange: (color) => {setCurrentColor(color);onColorChange(color);- }, onTouchEnd: function () { return onChange(currentColor); }, onMouseUp: function () { return onChange(currentColor); } }), (0, jsx_runtime_1.jsx)(forms_1.Input, { variant: "clean", placeholder: "#000000", spellCheck: false, sx: {+ }, onTouchEnd: () => onChange(currentColor), onMouseUp: () => onChange(currentColor) }), (0, jsx_runtime_1.jsx)(forms_1.Input, { variant: "clean", placeholder: "#000000", spellCheck: false, sx: {my: 2,p: 0,borderRadius: 0,@@ -103,20 +76,20 @@ function ColorPicker(props) {color: "fontTertiary",textAlign: "center",letterSpacing: 1.5,- }, value: currentColor.toUpperCase(), maxLength: 7, onChange: function (e) {- var value = e.target.value;+ }, value: currentColor.toUpperCase(), maxLength: 7, onChange: (e) => {+ const { value } = e.target;if (!value)return;if ((0, tinycolor2_1.default)(value, { format: "hex" }).isValid()) {setCurrentColor(value);onChange(value);}- } })] })) : null, (0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ className: "hide-scrollbar", sx: {+ } })] })) : null, (0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ className: "hide-scrollbar", sx: {flex: 1,p: 1,overflowX: ["auto", "hidden"],flexWrap: ["nowrap", "wrap"],- } }, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, __assign({ variant: "icon", sx: {+ } }, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ variant: "icon", sx: {flexShrink: 0,width: PALETTE_SIZE,height: PALETTE_SIZE,@@ -124,7 +97,7 @@ function ColorPicker(props) {boxShadow: "menu",p: 0,ml: [2, 2, 1],- }, onClick: onClear }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.colorClear, color: "text", size: 15 }) })), (0, jsx_runtime_1.jsx)(button_1.Button, __assign({ variant: "secondary", sx: {+ }, onClick: onClear }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.colorClear, color: "text", size: 15 }) })), (0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ variant: "secondary", sx: {flexShrink: 0,bg: currentColor,width: PALETTE_SIZE,@@ -133,7 +106,7 @@ function ColorPicker(props) {// boxShadow: "menu",p: 0,ml: [2, 2, 1],- }, onClick: function () { return setIsPickerOpen(function (s) { return !s; }); } }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.palette, color: tColor.isDark() ? "static" : "icon", size: 18 }) })), colors.map(function (color) { return ((0, jsx_runtime_1.jsx)(button_1.Button, { variant: "secondary", sx: {+ }, onClick: () => setIsPickerOpen((s) => !s) }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.palette, color: tColor.isDark() ? "static" : "icon", size: 18 }) })), colors.map((color) => ((0, jsx_runtime_1.jsx)(button_1.Button, { variant: "secondary", sx: {flex: "0 0 auto",bg: color,width: PALETTE_SIZE,@@ -142,9 +115,9 @@ function ColorPicker(props) {mb: [0, 1, 1],borderRadius: 50,// boxShadow: "menu",- }, onClick: function () {+ }, onClick: () => {setCurrentColor(color);onChange(color);- } }, color)); })] })), onClose && ((0, jsx_runtime_1.jsx)(button_1.Button, __assign({ variant: "icon", sx: { display: ["block", "none"], px: 2 }, onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.close, size: "big" }) })))] })] })));+ } }, color)))] })), onClose && ((0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ variant: "icon", sx: { display: ["block", "none"], px: 2 }, onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.close, size: "big" }) })))] })] })));}exports.ColorPicker = ColorPicker;diff --git a/packages/editor/dist/toolbar/popups/embedpopup.d.ts b/packages/editor/dist/cjs/toolbar/popups/embedpopup.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/embedpopup.d.tsrename to packages/editor/dist/cjs/toolbar/popups/embedpopup.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/embedpopup.js b/packages/editor/dist/cjs/toolbar/popups/embedpopup.jsnew file mode 100644index 000000000..a913f63c8--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/embedpopup.js@@ -0,0 +1,90 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.EmbedPopup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("react");+const popup_1 = require("../components/popup");+const forms_1 = require("@rebass/forms");+const lib_1 = require("@social-embed/lib");+const inlineinput_1 = require("../../components/inlineinput");+const tabs_1 = require("../../components/tabs");+function EmbedPopup(props) {+ const { onClose, onSizeChanged, onSourceChanged, title, embed } = props;+ const [width, setWidth] = (0, react_1.useState)((embed === null || embed === void 0 ? void 0 : embed.width) || 300);+ const [height, setHeight] = (0, react_1.useState)((embed === null || embed === void 0 ? void 0 : embed.height) || 150);+ const [src, setSrc] = (0, react_1.useState)((embed === null || embed === void 0 ? void 0 : embed.src) || "");+ const [embedSource, setEmbedSource] = (0, react_1.useState)("url");+ const [error, setError] = (0, react_1.useState)(null);+ const onSizeChange = (0, react_1.useCallback)((newWidth, newHeight) => {+ const size = newWidth+ ? {+ width: newWidth,+ height: newWidth * (height / width),+ }+ : newHeight+ ? {+ width: newHeight * (width / height),+ height: newHeight,+ }+ : {+ width: 0,+ height: 0,+ };+ setWidth(size.width);+ setHeight(size.height);+ if (onSizeChanged)+ onSizeChanged(size);+ }, [width, height]);+ (0, react_1.useEffect)(() => {+ onSourceChanged && onSourceChanged(src);+ }, [onSourceChanged, src]);+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ title: title, onClose: () => onClose(), action: {+ title,+ onClick: () => {+ setError(null);+ let _src = src;+ let _width = width;+ let _height = height;+ if (embedSource === "code") {+ const document = new DOMParser().parseFromString(src, "text/html");+ if (document.getElementsByTagName("iframe").length <= 0)+ return setError("Embed code must include an iframe.");+ const srcValue = getAttribute(document, "src");+ if (!srcValue)+ return setError("Embed code must include an iframe with an src attribute.");+ _src = srcValue;+ const widthValue = getAttribute(document, "width");+ if (widthValue && !isNaN(parseInt(widthValue)))+ _width = parseInt(widthValue);+ const heightValue = getAttribute(document, "height");+ if (heightValue && !isNaN(parseInt(heightValue)))+ _height = parseInt(heightValue);+ }+ const convertedUrl = (0, lib_1.convertUrlToEmbedUrl)(_src);+ if (!!convertedUrl)+ _src = convertedUrl;+ onClose({+ height: _height,+ width: _width,+ src: _src,+ });+ },+ } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { flexDirection: "column", width: ["auto", 300] } }, { children: [error && ((0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "error", sx: {+ bg: "errorBg",+ color: "error",+ p: 1,+ borderRadius: "default",+ } }, { children: ["Error: ", error] }))), (0, jsx_runtime_1.jsxs)(tabs_1.Tabs, Object.assign({ activeIndex: 0, containerProps: { sx: { mx: 1, flexDirection: "column" } }, onTabChanged: (index) => setEmbedSource(index === 0 ? "url" : "code") }, { children: [(0, jsx_runtime_1.jsxs)(tabs_1.Tab, Object.assign({ title: "From URL" }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { placeholder: "Enter embed source URL", value: src, autoFocus: true, onChange: (e) => setSrc(e.target.value), autoCapitalize: "none", sx: { fontSize: "body" } }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { alignItems: "center", mt: 1 } }, { children: [(0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { containerProps: { sx: { mr: 1 } }, label: "width", type: "number", placeholder: "Width", value: width, sx: {+ mr: 1,+ fontSize: "body",+ }, onChange: (e) => onSizeChange(e.target.valueAsNumber) }), (0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "height", type: "number", placeholder: "Height", value: height, sx: { fontSize: "body" }, onChange: (e) => onSizeChange(undefined, e.target.valueAsNumber) })] }))] })), (0, jsx_runtime_1.jsx)(tabs_1.Tab, Object.assign({ title: "From code" }, { children: (0, jsx_runtime_1.jsx)(forms_1.Textarea, { autoFocus: true, variant: "forms.input", sx: { fontSize: "subBody", fontFamily: "monospace" }, minHeight: [200, 100], onChange: (e) => setSrc(e.target.value), placeholder: "Paste embed code here. Only iframes are supported." }) }))] }))] })) })));+}+exports.EmbedPopup = EmbedPopup;+function getAttribute(document, id) {+ const element = document.querySelector(`[${id}]`);+ if (!element)+ return null;+ const attribute = element.getAttribute(id);+ return attribute;+}diff --git a/packages/editor/dist/toolbar/popups/imageproperties.d.ts b/packages/editor/dist/cjs/toolbar/popups/imageproperties.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/imageproperties.d.tsrename to packages/editor/dist/cjs/toolbar/popups/imageproperties.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/imageproperties.js b/packages/editor/dist/cjs/toolbar/popups/imageproperties.jsnew file mode 100644index 000000000..38e18364b--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/imageproperties.js@@ -0,0 +1,36 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.ImageProperties = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("react");+const popup_1 = require("../components/popup");+const forms_1 = require("@rebass/forms");+const inlineinput_1 = require("../../components/inlineinput");+function ImageProperties(props) {+ const { height, width, float, editor, onClose } = props;+ const onSizeChange = (0, react_1.useCallback)((newWidth, newHeight) => {+ const size = newWidth+ ? {+ width: newWidth,+ height: newWidth * (height / width),+ }+ : newHeight+ ? {+ width: newHeight * (width / height),+ height: newHeight,+ }+ : {+ width: 0,+ height: 0,+ };+ editor.chain().setImageSize(size).run();+ }, [width, height]);+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ title: "Image properties", onClose: onClose }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { width: ["auto", 300], flexDirection: "column", p: 1 } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { justifyContent: "space-between", alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "body" }, { children: "Floating?" })), (0, jsx_runtime_1.jsx)(forms_1.Checkbox, { checked: float, onClick: () => editor+ .chain()+ .setImageAlignment({ float: !float, align: "left" })+ .run() })] })), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { alignItems: "center", mt: 2 } }, { children: [(0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "width", type: "number", value: width, containerProps: {+ sx: { mr: 1 },+ }, onChange: (e) => onSizeChange(e.target.valueAsNumber) }), (0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "height", type: "number", value: height, onChange: (e) => onSizeChange(undefined, e.target.valueAsNumber) })] }))] })) })));+}+exports.ImageProperties = ImageProperties;diff --git a/packages/editor/dist/toolbar/popups/imageupload.d.ts b/packages/editor/dist/cjs/toolbar/popups/imageupload.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/imageupload.d.tsrename to packages/editor/dist/cjs/toolbar/popups/imageupload.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/imageupload.js b/packages/editor/dist/cjs/toolbar/popups/imageupload.jsnew file mode 100644index 000000000..2afbccfa4--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/imageupload.js@@ -0,0 +1,78 @@+"use strict";+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.ImageUploadPopup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const forms_1 = require("@rebass/forms");+const react_1 = require("react");+const rebass_1 = require("rebass");+const popup_1 = require("../components/popup");+function ImageUploadPopup(props) {+ const { onInsert, onClose } = props;+ const [isDownloading, setIsDownloading] = (0, react_1.useState)(false);+ const [error, setError] = (0, react_1.useState)();+ const [url, setUrl] = (0, react_1.useState)("");+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ title: "Insert image from URL", onClose: onClose, action: {+ loading: isDownloading,+ title: "Insert image",+ disabled: !url,+ onClick: () => __awaiter(this, void 0, void 0, function* () {+ setIsDownloading(true);+ setError(undefined);+ try {+ const response = yield fetch(url);+ if (!response.ok)+ return setError(`invalid status code ${response.status}`);+ const contentType = response.headers.get("Content-Type");+ const contentLength = response.headers.get("Content-Length");+ if (!contentType ||+ !contentLength ||+ contentLength === "0" ||+ !contentType.startsWith("image/"))+ return setError("not an image");+ const size = parseInt(contentLength);+ const dataurl = yield toDataURL(yield response.blob());+ onInsert({ src: dataurl, type: contentType, size });+ }+ catch (e) {+ if (e instanceof Error)+ setError(e.message);+ }+ finally {+ setIsDownloading(false);+ }+ }),+ } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { px: 1, flexDirection: "column", width: ["auto", 350] } }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { type: "url", autoFocus: true, placeholder: "Paste Image URL here", value: url, onChange: (e) => {+ setUrl(e.target.value);+ setError(undefined);+ } }), error ? ((0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "error", sx: {+ bg: "errorBg",+ mt: 1,+ p: 1,+ borderRadius: "default",+ } }, { children: ["Failed to download image: ", error.toLowerCase(), "."] }))) : ((0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "subBody", sx: {+ bg: "shade",+ color: "primary",+ mt: 1,+ p: 1,+ borderRadius: "default",+ } }, { children: "To protect your privacy, we will download the image & add it to your attachments." })))] })) })));+}+exports.ImageUploadPopup = ImageUploadPopup;+function toDataURL(blob) {+ return new Promise((resolve, reject) => {+ const reader = new FileReader();+ reader.onload = (_e) => resolve(reader.result);+ reader.onerror = (_e) => reject(reader.error);+ reader.onabort = (_e) => reject(new Error("Read aborted"));+ reader.readAsDataURL(blob);+ });+}diff --git a/packages/editor/dist/toolbar/popups/linkpopup.d.ts b/packages/editor/dist/cjs/toolbar/popups/linkpopup.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/linkpopup.d.tsrename to packages/editor/dist/cjs/toolbar/popups/linkpopup.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/linkpopup.js b/packages/editor/dist/cjs/toolbar/popups/linkpopup.jsnew file mode 100644index 000000000..db4506749--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/linkpopup.js@@ -0,0 +1,18 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.LinkPopup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const forms_1 = require("@rebass/forms");+const react_1 = require("react");+const rebass_1 = require("rebass");+const popup_1 = require("../components/popup");+function LinkPopup(props) {+ const { text: _text, href: _href, isEditing = false, onDone, onClose, } = props;+ const [href, setHref] = (0, react_1.useState)(_href || "");+ const [text, setText] = (0, react_1.useState)(_text || "");+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ title: isEditing ? "Edit link" : "Insert link", onClose: onClose, action: {+ title: isEditing ? "Save edits" : "Insert link",+ onClick: () => onDone({ text, href }),+ } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { p: 1, flexDirection: "column", width: ["auto", 250] } }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { type: "text", placeholder: "Link text", value: text, onChange: (e) => setText(e.target.value) }), (0, jsx_runtime_1.jsx)(forms_1.Input, { type: "url", sx: { mt: 1 }, autoFocus: true, placeholder: "https://example.com/", value: href, onChange: (e) => setHref(e.target.value) })] })) })));+}+exports.LinkPopup = LinkPopup;diff --git a/packages/editor/dist/toolbar/popups/searchreplace.d.ts b/packages/editor/dist/cjs/toolbar/popups/searchreplace.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/searchreplace.d.tsrename to packages/editor/dist/cjs/toolbar/popups/searchreplace.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/searchreplace.js b/packages/editor/dist/cjs/toolbar/popups/searchreplace.jsnew file mode 100644index 000000000..8fcea7c56--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/searchreplace.js@@ -0,0 +1,86 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.SearchReplacePopup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const forms_1 = require("@rebass/forms");+const react_1 = require("react");+const rebass_1 = require("rebass");+const toolbutton_1 = require("../components/toolbutton");+function SearchReplacePopup(props) {+ const { editor } = props;+ const { selectedText, results } = editor.storage+ .searchreplace;+ const [isReplacing, setIsReplacing] = (0, react_1.useState)(false);+ const [isExpanded, setIsExpanded] = (0, react_1.useState)(false);+ const [matchCase, setMatchCase] = (0, react_1.useState)(false);+ const [matchWholeWord, setMatchWholeWord] = (0, react_1.useState)(false);+ const [enableRegex, setEnableRegex] = (0, react_1.useState)(false);+ const replaceText = (0, react_1.useRef)("");+ const searchInputRef = (0, react_1.useRef)();+ const search = (0, react_1.useCallback)((term) => {+ editor.commands.search(term, {+ matchCase,+ enableRegex,+ matchWholeWord,+ });+ }, [matchCase, enableRegex, matchWholeWord]);+ (0, react_1.useEffect)(() => {+ if (!searchInputRef.current)+ return;+ search(searchInputRef.current.value);+ }, [search, matchCase, matchWholeWord, enableRegex]);+ (0, react_1.useEffect)(() => {+ if (selectedText) {+ if (searchInputRef.current) {+ const input = searchInputRef.current;+ setTimeout(() => {+ input.value = selectedText;+ input.focus();+ }, 0);+ }+ search(selectedText);+ }+ }, [selectedText, search]);+ return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {+ p: 1,+ bg: "background",+ flexDirection: "column",+ boxShadow: ["none", "menu"],+ borderRadius: [0, "default"],+ } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { flexDirection: "column", flex: 1, width: ["auto", 300], mr: 1 } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.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: [(0, jsx_runtime_1.jsx)(forms_1.Input, { variant: "clean", defaultValue: selectedText, ref: searchInputRef, autoFocus: true, placeholder: "Find", sx: { p: 0 }, onChange: (e) => {+ search(e.target.value);+ } }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ flexShrink: 0,+ mr: 0,+ alignItems: "center",+ } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {+ mr: 0,+ }, toggled: isExpanded, title: "Expand", id: "expand", icon: isExpanded ? "chevronRight" : "chevronLeft", onClick: () => setIsExpanded((s) => !s), iconSize: "medium" }), isExpanded && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {+ mr: 0,+ }, toggled: matchCase, title: "Match case", id: "matchCase", icon: "caseSensitive", onClick: () => setMatchCase((s) => !s), iconSize: "medium" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {+ mr: 0,+ }, toggled: matchWholeWord, title: "Match whole word", id: "matchWholeWord", icon: "wholeWord", onClick: () => setMatchWholeWord((s) => !s), iconSize: "medium" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {+ mr: 0,+ }, toggled: enableRegex, title: "Enable regex", id: "enableRegex", icon: "regex", onClick: () => setEnableRegex((s) => !s), iconSize: "medium" })] })), (0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "subBody", sx: {+ flexShrink: 0,+ borderLeft: "1px solid var(--border)",+ color: "fontTertiary",+ px: 1,+ } }, { children: [results ? `${results.length}` : "0", isExpanded ? "" : " results"] }))] }))] })), isReplacing && ((0, jsx_runtime_1.jsx)(forms_1.Input, { sx: { mt: 1, p: "7px" }, placeholder: "Replace", onChange: (e) => (replaceText.current = e.target.value) }))] })), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { flexDirection: "column" } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { alignItems: "center", height: "33.2px" } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: isReplacing, title: "Toggle replace", id: "toggleReplace", icon: "replace", onClick: () => setIsReplacing((s) => !s), sx: { mr: 0 }, iconSize: "big" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Previous match", id: "previousMatch", icon: "previousMatch", onClick: () => editor.commands.moveToPreviousResult(), sx: { mr: 0 }, iconSize: "big" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Next match", id: "nextMatch", icon: "nextMatch", onClick: () => editor.commands.moveToNextResult(), sx: { mr: 0 }, iconSize: "big" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Close", id: "close", icon: "close", onClick: () => editor.chain().focus().endSearch().run(), sx: { mr: 0 }, iconSize: "big" })] })), isReplacing && ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { alignItems: "center", height: "33.2px", mt: 1 } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Replace", id: "replace", icon: "replaceOne", onClick: () => editor.commands.replace(replaceText.current), sx: { mr: 0 }, iconSize: 18 }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Replace all", id: "replaceAll", icon: "replaceAll", onClick: () => editor.commands.replaceAll(replaceText.current), sx: { mr: 0 }, iconSize: 18 })] })))] }))] }) })));+}+exports.SearchReplacePopup = SearchReplacePopup;diff --git a/packages/editor/dist/toolbar/popups/tablepopup.d.ts b/packages/editor/dist/cjs/toolbar/popups/tablepopup.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/popups/tablepopup.d.tsrename to packages/editor/dist/cjs/toolbar/popups/tablepopup.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/popups/tablepopup.js b/packages/editor/dist/cjs/toolbar/popups/tablepopup.jsnew file mode 100644index 000000000..33b2ba32a--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/popups/tablepopup.js@@ -0,0 +1,111 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.TablePopup = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("react");+const popup_1 = require("../components/popup");+const toolbarstore_1 = require("../stores/toolbarstore");+const inlineinput_1 = require("../../components/inlineinput");+const MAX_COLUMNS = 20;+const MAX_ROWS = 20;+const MIN_COLUMNS = 10;+const MIN_ROWS = 6;+function TablePopup(props) {+ const isMobile = (0, toolbarstore_1.useIsMobile)();+ const autoExpand = !isMobile;+ const cellSize = isMobile ? 30 : 15;+ const { onInsertTable } = props;+ const [cellLocation, setCellLocation] = (0, react_1.useState)({+ column: 0,+ row: 0,+ });+ const [tableSize, setTableSize] = (0, react_1.useState)({+ columns: MIN_COLUMNS,+ rows: MIN_ROWS,+ });+ (0, react_1.useEffect)(() => {+ if (!autoExpand)+ return;+ setTableSize((old) => {+ const { columns, rows } = old;+ const { column, row } = cellLocation;+ let isDecrease = row === rows - 2 || column === columns - 2;+ let rowFactor = Number(row === rows || row === rows - 2);+ let columnFactor = Number(column === columns || column === columns - 2);+ return {+ columns: isDecrease+ ? Math.max(column + columnFactor, MIN_COLUMNS)+ : Math.min(old.columns + columnFactor, MAX_COLUMNS),+ rows: isDecrease+ ? Math.max(row + rowFactor, MIN_ROWS)+ : Math.min(old.rows + rowFactor, MAX_ROWS),+ };+ });+ }, [cellLocation, autoExpand]);+ return ((0, jsx_runtime_1.jsx)(popup_1.Popup, Object.assign({ action: {+ title: !cellLocation.column || !cellLocation.row+ ? "Please set a table size"+ : `Insert a ${cellLocation.column} x ${cellLocation.row} table`,+ disabled: !cellLocation.column || !cellLocation.row,+ onClick: () => onInsertTable({+ columns: cellLocation.column,+ rows: cellLocation.row,+ }),+ } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { px: 1, pt: 1, flexDirection: "column", alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {+ display: "grid",+ gridTemplateColumns: `repeat(${tableSize.columns}, minmax(${cellSize}px, 1fr))`,+ gap: "small",+ bg: "background",+ width: "100%",+ }, onTouchMove: (e) => {+ const touch = e.touches.item(0);+ const element = document.elementFromPoint(touch.pageX, touch.pageY);+ if (!element)+ return;+ const index = element.dataset.index;+ if (!index)+ return;+ setCellLocation(getCellLocation(parseInt(index), tableSize));+ } }, { children: Array(tableSize.columns * tableSize.rows)+ .fill(0)+ .map((_, index) => ((0, jsx_runtime_1.jsx)(rebass_1.Box, { "data-index": index, height: cellSize || 15, sx: {+ border: "1px solid var(--disabled)",+ borderRadius: "small",+ bg: isCellHighlighted(index, cellLocation, tableSize)+ ? "disabled"+ : "transparent",+ }, onTouchStart: () => {+ setCellLocation(getCellLocation(index, tableSize));+ }, onMouseEnter: () => {+ setCellLocation(getCellLocation(index, tableSize));+ }, onClick: () => {+ onInsertTable({+ columns: cellLocation.column,+ rows: cellLocation.row,+ });+ } }, index))) })), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: {+ display: ["flex", "none", "none"],+ mt: 1,+ alignItems: "center",+ justifyContent: "center",+ } }, { children: [(0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { containerProps: { sx: { mr: 1 } }, label: "columns", placeholder: `${cellLocation.column} columns`, type: "number", value: cellLocation.column, onChange: (e) => {+ setCellLocation((l) => (Object.assign(Object.assign({}, l), { column: e.target.valueAsNumber || 0 })));+ } }), (0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "rows", placeholder: `${cellLocation.row} rows`, type: "number", value: cellLocation.row, onChange: (e) => {+ setCellLocation((l) => (Object.assign(Object.assign({}, l), { row: e.target.valueAsNumber || 0 })));+ } })] })), (0, jsx_runtime_1.jsxs)(rebass_1.Text, Object.assign({ variant: "body", sx: { mt: 1, display: ["none", "block", "block"] } }, { children: [cellLocation.column, " x ", cellLocation.row] }))] })) })));+}+exports.TablePopup = TablePopup;+function getCellLocation(index, tableSize) {+ const cellIndex = index + 1;+ const column = cellIndex % tableSize.columns;+ let row = cellIndex / tableSize.columns;+ const flooredRow = Math.floor(row);+ row = row === flooredRow ? row : flooredRow + 1;+ return { column: column ? column : tableSize.columns, row };+}+function isCellHighlighted(index, currentCellLocation, tableSize) {+ const cellLocation = getCellLocation(index, tableSize);+ return (cellLocation.row <= currentCellLocation.row &&+ cellLocation.column <= currentCellLocation.column);+}diff --git a/packages/editor/dist/toolbar/stores/toolbarstore.d.ts b/packages/editor/dist/cjs/toolbar/stores/toolbarstore.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/stores/toolbarstore.d.tsrename to packages/editor/dist/cjs/toolbar/stores/toolbarstore.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/stores/toolbarstore.js b/packages/editor/dist/cjs/toolbar/stores/toolbarstore.jsnew file mode 100644index 000000000..602d5c683--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/stores/toolbarstore.js@@ -0,0 +1,41 @@+"use strict";+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.useIsMobile = exports.useToolbarLocation = exports.useToolbarStore = void 0;+const zustand_1 = __importDefault(require("zustand"));+exports.useToolbarStore = (0, zustand_1.default)((set, get) => ({+ isMobile: false,+ openedPopups: {},+ setIsMobile: (isMobile) => set((state) => {+ state.isMobile = isMobile;+ }),+ toolbarLocation: "top",+ setToolbarLocation: (location) => set((state) => {+ state.toolbarLocation = location;+ }),+ closePopup: (id) => set((state) => {+ state.openedPopups = Object.assign(Object.assign({}, state.openedPopups), { [id]: false });+ }),+ isPopupOpen: (id) => !!get().openedPopups[id],+ openPopup: (ref) => set((state) => {+ state.openedPopups = Object.assign(Object.assign({}, state.openedPopups), { [ref.id]: ref });+ }),+ closePopupGroup: (group, excluded) => set((state) => {+ for (const key in state.openedPopups) {+ const ref = state.openedPopups[key];+ if (ref && ref.group === group && !excluded.includes(ref.id)) {+ state.openedPopups[key] = false;+ }+ }+ }),+}));+function useToolbarLocation() {+ return (0, exports.useToolbarStore)((store) => store.toolbarLocation);+}+exports.useToolbarLocation = useToolbarLocation;+function useIsMobile() {+ return (0, exports.useToolbarStore)((store) => store.isMobile);+}+exports.useIsMobile = useIsMobile;diff --git a/packages/editor/dist/toolbar/toolbar.d.ts b/packages/editor/dist/cjs/toolbar/toolbar.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/toolbar.d.tsrename to packages/editor/dist/cjs/toolbar/toolbar.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/toolbar.js b/packages/editor/dist/cjs/toolbar/toolbar.jsnew file mode 100644index 000000000..84ab58adc--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/toolbar.js@@ -0,0 +1,33 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Toolbar = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const emotion_theming_1 = require("emotion-theming");+const floatingmenus_1 = require("./floatingmenus");+const tooldefinitions_1 = require("./tooldefinitions");+const react_1 = require("react");+const toolbarstore_1 = require("./stores/toolbarstore");+const toolbargroup_1 = require("./components/toolbargroup");+const popuprenderer_1 = require("../components/popup-presenter/popuprenderer");+function Toolbar(props) {+ const { editor, theme, location, isMobile, tools = tooldefinitions_1.DEFAULT_TOOLS } = props;+ const setIsMobile = (0, toolbarstore_1.useToolbarStore)((store) => store.setIsMobile);+ const setToolbarLocation = (0, toolbarstore_1.useToolbarStore)((store) => store.setToolbarLocation);+ (0, react_1.useEffect)(() => {+ setIsMobile(isMobile || false);+ setToolbarLocation(location);+ }, [isMobile, location]);+ if (!editor)+ return null;+ return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, Object.assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Provider, Object.assign({ value: editor }, { children: (0, jsx_runtime_1.jsxs)(popuprenderer_1.PopupRenderer, Object.assign({ editor: editor }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ className: "editor-toolbar", sx: { flexWrap: ["nowrap", "wrap"], overflowX: ["auto", "hidden"] } }, { children: tools.map((tools) => {+ return ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { tools: tools, editor: editor, sx: {+ flexShrink: 0,+ pr: 2,+ mr: 2,+ borderRight: "1px solid var(--border)",+ ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },+ } }, tools.join("")));+ }) })), (0, jsx_runtime_1.jsx)(floatingmenus_1.EditorFloatingMenus, { editor: editor })] })) })) })));+}+exports.Toolbar = Toolbar;diff --git a/packages/editor/dist/cjs/toolbar/tooldefinitions.d.ts b/packages/editor/dist/cjs/toolbar/tooldefinitions.d.tsnew file mode 100644index 000000000..88e97b56c--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tooldefinitions.d.ts@@ -0,0 +1,5 @@+import { ToolbarDefinition, ToolDefinition } from "./types";+import { ToolId } from "./tools";+export declare function getToolDefinition(id: ToolId): ToolDefinition;+export declare function getAllTools(): Record<"fontSize" | "underline" | "bold" | "bulletList" | "code" | "italic" | "subscript" | "superscript" | "fontFamily" | "highlight" | "removeAttachment" | "downloadAttachment" | "deleteColumn" | "deleteRow" | "deleteTable" | "mergeCells" | "ltr" | "rtl" | "strikethrough" | "codeRemove" | "alignCenter" | "alignLeft" | "alignRight" | "alignJustify" | "numberedList" | "textColor" | "openLink" | "linkSettings" | "imageSettings" | "rowProperties" | "insertRowBelow" | "insertRowAbove" | "moveRowDown" | "moveRowUp" | "columnProperties" | "insertColumnRight" | "insertColumnLeft" | "moveColumnRight" | "moveColumnLeft" | "cellProperties" | "cellBorderColor" | "splitCells" | "attachmentSettings" | "embedSettings" | "tableSettings" | "math" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "insertBlock" | "headings" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "cellBackgroundColor" | "cellTextColor" | "cellBorderWidth", ToolDefinition>;+export declare const DEFAULT_TOOLS: ToolbarDefinition;diff --git a/packages/editor/dist/toolbar/tooldefinitions.js b/packages/editor/dist/cjs/toolbar/tooldefinitions.jssimilarity index 99%rename from packages/editor/dist/toolbar/tooldefinitions.jsrename to packages/editor/dist/cjs/toolbar/tooldefinitions.jsindex bf5e905de..5866f0389 100644--- a/packages/editor/dist/toolbar/tooldefinitions.js+++ b/packages/editor/dist/cjs/toolbar/tooldefinitions.js@@ -1,7 +1,7 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.DEFAULT_TOOLS = exports.getAllTools = exports.getToolDefinition = void 0;-var tools = {+const tools = {bold: {icon: "bold",title: "Bold",diff --git a/packages/editor/dist/toolbar/tools/alignment.d.ts b/packages/editor/dist/cjs/toolbar/tools/alignment.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/alignment.d.tsrename to packages/editor/dist/cjs/toolbar/tools/alignment.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/alignment.js b/packages/editor/dist/cjs/toolbar/tools/alignment.jsnew file mode 100644index 000000000..526c9ae45--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/alignment.js@@ -0,0 +1,36 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.AlignJustify = exports.AlignRight = exports.AlignLeft = exports.AlignCenter = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+function AlignmentTool(props) {+ const { editor, alignment } = props, toolProps = __rest(props, ["editor", "alignment"]);+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignment).run(); }, toggled: editor.isActive({ textAlign: alignment }) })));+}+function AlignCenter(props) {+ return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "center" }, props));+}+exports.AlignCenter = AlignCenter;+function AlignLeft(props) {+ return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "left" }, props));+}+exports.AlignLeft = AlignLeft;+function AlignRight(props) {+ return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "right" }, props));+}+exports.AlignRight = AlignRight;+function AlignJustify(props) {+ return (0, jsx_runtime_1.jsx)(AlignmentTool, Object.assign({ alignment: "justify" }, props));+}+exports.AlignJustify = AlignJustify;diff --git a/packages/editor/dist/toolbar/tools/attachment.d.ts b/packages/editor/dist/cjs/toolbar/tools/attachment.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/attachment.d.tsrename to packages/editor/dist/cjs/toolbar/tools/attachment.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/attachment.js b/packages/editor/dist/cjs/toolbar/tools/attachment.jsnew file mode 100644index 000000000..192fa05bd--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/attachment.js@@ -0,0 +1,31 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.RemoveAttachment = exports.DownloadAttachment = exports.AttachmentSettings = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+const moretools_1 = require("../components/moretools");+const toolbarstore_1 = require("../stores/toolbarstore");+const prosemirror_1 = require("../utils/prosemirror");+function AttachmentSettings(props) {+ const { editor } = props;+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ if (!editor.isActive("attachment") || !isBottom)+ return null;+ return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "attachmentSettings", tools: [] })));+}+exports.AttachmentSettings = AttachmentSettings;+function DownloadAttachment(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ const attachmentNode = (0, prosemirror_1.findSelectedNode)(editor, "attachment");+ const attachment = ((attachmentNode === null || attachmentNode === void 0 ? void 0 : attachmentNode.attrs) || {});+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().downloadAttachment(attachment).run();+ } })));+}+exports.DownloadAttachment = DownloadAttachment;+function RemoveAttachment(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().removeAttachment().run(); } })));+}+exports.RemoveAttachment = RemoveAttachment;diff --git a/packages/editor/dist/toolbar/tools/block.d.ts b/packages/editor/dist/cjs/toolbar/tools/block.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/block.d.tsrename to packages/editor/dist/cjs/toolbar/tools/block.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/block.js b/packages/editor/dist/cjs/toolbar/tools/block.jsnew file mode 100644index 000000000..1b9f57c94--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/block.js@@ -0,0 +1,243 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.InsertBlock = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const icons_1 = require("../icons");+const react_1 = require("react");+const icon_1 = require("../components/icon");+const embedpopup_1 = require("../popups/embedpopup");+const tablepopup_1 = require("../popups/tablepopup");+const toolbarstore_1 = require("../stores/toolbarstore");+const responsive_1 = require("../../components/responsive");+const popuppresenter_1 = require("../../components/popuppresenter");+const imageupload_1 = require("../popups/imageupload");+const button_1 = require("../../components/button");+function InsertBlock(props) {+ const { editor } = props;+ const buttonRef = (0, react_1.useRef)(null);+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ const isMobile = (0, toolbarstore_1.useIsMobile)();+ const menuItems = (0, react_1.useMemo)(() => {+ return [+ tasklist(editor),+ outlinelist(editor),+ horizontalRule(editor),+ codeblock(editor),+ mathblock(editor),+ blockquote(editor),+ image(editor, isMobile),+ attachment(editor),+ isMobile ? embedMobile(editor) : embedDesktop(editor),+ table(editor),+ ];+ }, [isMobile]);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, Object.assign({ ref: buttonRef, sx: {+ p: 1,+ m: 0,+ bg: isOpen ? "hover" : "transparent",+ mr: 1,+ display: "flex",+ alignItems: "center",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onMouseDown: (e) => e.preventDefault(), onClick: () => setIsOpen((s) => !s) }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.plus, size: 18, color: "primary" }) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { desktop: "menu", mobile: "sheet", title: "Choose a block to insert", isOpen: isOpen, items: menuItems, onClose: () => setIsOpen(false), position: {+ target: buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: toolbarLocation === "bottom" ? "top" : "below",+ yOffset: 5,+ } })] }));+}+exports.InsertBlock = InsertBlock;+const horizontalRule = (editor) => ({+ key: "hr",+ type: "button",+ title: "Horizontal rule",+ icon: "horizontalRule",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("horizontalRule"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setHorizontalRule().run(); },+});+const codeblock = (editor) => ({+ key: "codeblock",+ type: "button",+ title: "Code block",+ icon: "codeblock",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleCodeBlock().run(); },+});+const blockquote = (editor) => ({+ key: "blockquote",+ type: "button",+ title: "Quote",+ icon: "blockquote",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("blockQuote"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBlockquote().run(); },+});+const mathblock = (editor) => ({+ key: "math",+ type: "button",+ title: "Math & formulas",+ icon: "mathBlock",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("mathBlock"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathBlock().run(); },+});+const image = (editor, isMobile) => ({+ key: "image",+ type: "button",+ title: "Image",+ icon: "image",+ menu: {+ title: "Insert an image",+ items: [+ {+ key: "upload-from-disk",+ type: "button",+ title: "Upload from disk",+ icon: "upload",+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("image").run(); },+ },+ {+ key: "camera",+ type: "button",+ title: "Take a photo using camera",+ icon: "camera",+ isHidden: !isMobile,+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("camera").run(); },+ },+ isMobile ? uploadImageFromURLMobile(editor) : uploadImageFromURL(editor),+ ],+ },+});+const table = (editor) => ({+ key: "table",+ type: "button",+ title: "Table",+ icon: "table",+ menu: {+ title: "Insert a table",+ items: [+ {+ key: "table-size-selector",+ type: "popup",+ component: (props) => ((0, jsx_runtime_1.jsx)(tablepopup_1.TablePopup, { onInsertTable: (size) => {+ var _a, _b;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertTable({+ rows: size.rows,+ cols: size.columns,+ }).run();+ (_b = props.onClick) === null || _b === void 0 ? void 0 : _b.call(props);+ } })),+ },+ ],+ },+});+const embedMobile = (editor) => ({+ key: "embed",+ type: "button",+ title: "Embed",+ icon: "embed",+ menu: {+ title: "Insert an embed",+ items: [+ {+ key: "embed-popup",+ type: "popup",+ component: function ({ onClick }) {+ return ((0, jsx_runtime_1.jsx)(embedpopup_1.EmbedPopup, { title: "Insert embed", onClose: (embed) => {+ var _a;+ if (!embed)+ return onClick === null || onClick === void 0 ? void 0 : onClick();+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().insertEmbed(embed).run();+ onClick === null || onClick === void 0 ? void 0 : onClick();+ } }));+ },+ },+ ],+ },+});+const embedDesktop = (editor) => ({+ key: "embed",+ type: "button",+ title: "Embed",+ icon: "embed",+ onClick: () => {+ if (!editor)+ return;+ (0, popuppresenter_1.showPopup)({+ theme: editor.storage.theme,+ popup: (hide) => ((0, jsx_runtime_1.jsx)(embedpopup_1.EmbedPopup, { title: "Insert embed", onClose: (embed) => {+ var _a;+ if (!embed)+ return hide();+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().insertEmbed(embed).run();+ hide();+ } })),+ });+ },+});+const attachment = (editor) => ({+ key: "attachment",+ type: "button",+ title: "Attachment",+ icon: "attachment",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("attachment"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("file").run(); },+});+const tasklist = (editor) => ({+ key: "tasklist",+ type: "button",+ title: "Task list",+ icon: "checkbox",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("taskList"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleTaskList().run(); },+});+const outlinelist = (editor) => ({+ key: "outlinelist",+ type: "button",+ title: "Outline list",+ icon: "outlineList",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("outlineList"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOutlineList().run(); },+});+const uploadImageFromURLMobile = (editor) => ({+ key: "upload-from-url",+ type: "button",+ title: "Attach from URL",+ icon: "link",+ menu: {+ title: "Attach image from URL",+ items: [+ {+ key: "attach-image",+ type: "popup",+ component: ({ onClick }) => ((0, jsx_runtime_1.jsx)(imageupload_1.ImageUploadPopup, { onInsert: (image) => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertImage(image).run();+ onClick === null || onClick === void 0 ? void 0 : onClick();+ }, onClose: () => {+ onClick === null || onClick === void 0 ? void 0 : onClick();+ } })),+ },+ ],+ },+});+const uploadImageFromURL = (editor) => ({+ key: "upload-from-url",+ type: "button",+ title: "Attach from URL",+ icon: "link",+ onClick: () => {+ if (!editor)+ return;+ (0, popuppresenter_1.showPopup)({+ theme: editor.storage.theme,+ popup: (hide) => ((0, jsx_runtime_1.jsx)(imageupload_1.ImageUploadPopup, { onInsert: (image) => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertImage(image).run();+ hide();+ }, onClose: hide })),+ });+ },+});diff --git a/packages/editor/dist/toolbar/tools/colors.d.ts b/packages/editor/dist/cjs/toolbar/tools/colors.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/colors.d.tsrename to packages/editor/dist/cjs/toolbar/tools/colors.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/colors.js b/packages/editor/dist/cjs/toolbar/tools/colors.jsnew file mode 100644index 000000000..3e1f270f3--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/colors.js@@ -0,0 +1,97 @@+"use strict";+var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ var desc = Object.getOwnPropertyDescriptor(m, k);+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {+ desc = { enumerable: true, get: function() { return m[k]; } };+ }+ Object.defineProperty(o, k2, desc);+}) : (function(o, m, k, k2) {+ if (k2 === undefined) k2 = k;+ o[k2] = m[k];+}));+var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {+ Object.defineProperty(o, "default", { enumerable: true, value: v });+}) : function(o, v) {+ o["default"] = v;+});+var __importStar = (this && this.__importStar) || function (mod) {+ if (mod && mod.__esModule) return mod;+ var result = {};+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);+ __setModuleDefault(result, mod);+ return result;+};+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.TextColor = exports.Highlight = exports.ColorTool = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const react_1 = __importStar(require("react"));+const tinycolor2_1 = __importDefault(require("tinycolor2"));+const popuppresenter_1 = require("../../components/popuppresenter");+const config_1 = require("../../utils/config");+const splitbutton_1 = require("../components/splitbutton");+const colorpicker_1 = require("../popups/colorpicker");+const toolbarstore_1 = require("../stores/toolbarstore");+const dom_1 = require("../utils/dom");+// TODO test rerendering+function _ColorTool(props) {+ const { editor, onColorChange, getActiveColor, title, cacheKey } = props, toolProps = __rest(props, ["editor", "onColorChange", "getActiveColor", "title", "cacheKey"]);+ const activeColor = getActiveColor() || config_1.config.get(cacheKey);+ const tColor = (0, tinycolor2_1.default)(activeColor);+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ return ((0, jsx_runtime_1.jsx)(splitbutton_1.SplitButton, Object.assign({}, toolProps, { iconColor: activeColor && tColor.isDark() ? "static" : "icon", sx: {+ mr: 0,+ bg: activeColor || "transparent",+ ":hover": {+ bg: activeColor ? tColor.darken(5).toRgbString() : "transparent",+ },+ }, onOpen: () => setIsOpen((s) => !s), toggled: isOpen, onClick: () => onColorChange(activeColor) }, { children: (0, jsx_runtime_1.jsx)(popuppresenter_1.PopupWrapper, { isOpen: isOpen, id: props.icon, group: "color", position: {+ isTargetAbsolute: true,+ target: (0, dom_1.getToolbarElement)(),+ align: isBottom ? "center" : "end",+ location: isBottom ? "top" : "below",+ yOffset: 10,+ }, focusOnRender: false, blocking: false, renderPopup: (close) => ((0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { color: activeColor, onClear: () => {+ onColorChange();+ config_1.config.set(cacheKey, null);+ }, onChange: (color) => {+ onColorChange(color);+ config_1.config.set(cacheKey, color);+ }, onClose: close, title: title })) }) })));+}+exports.ColorTool = react_1.default.memo(_ColorTool, () => true);+function Highlight(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(exports.ColorTool, Object.assign({}, props, { cacheKey: "highlight", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("highlight").color; }, title: "Background color", onColorChange: (color) => {+ var _a, _b;+ return color+ ? (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleHighlight({ color }).run()+ : (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetHighlight().run();+ } })));+}+exports.Highlight = Highlight;+function TextColor(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(exports.ColorTool, Object.assign({}, props, { cacheKey: "textColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("textStyle").color; }, title: "Text color", onColorChange: (color) => {+ var _a, _b;+ return color+ ? (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setColor(color).run()+ : (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetColor().run();+ } })));+}+exports.TextColor = TextColor;diff --git a/packages/editor/dist/toolbar/tools/embed.d.ts b/packages/editor/dist/cjs/toolbar/tools/embed.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/embed.d.tsrename to packages/editor/dist/cjs/toolbar/tools/embed.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/embed.js b/packages/editor/dist/cjs/toolbar/tools/embed.jsnew file mode 100644index 000000000..6a7943637--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/embed.js@@ -0,0 +1,60 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.EmbedProperties = exports.EmbedAlignCenter = exports.EmbedAlignRight = exports.EmbedAlignLeft = exports.EmbedSettings = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+const react_1 = require("react");+const responsive_1 = require("../../components/responsive");+const moretools_1 = require("../components/moretools");+const toolbarstore_1 = require("../stores/toolbarstore");+const prosemirror_1 = require("../utils/prosemirror");+const embedpopup_1 = require("../popups/embedpopup");+function EmbedSettings(props) {+ const { editor } = props;+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ if (!editor.isActive("embed") || !isBottom)+ return null;+ return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "embedSettings", tools: [] })));+}+exports.EmbedSettings = EmbedSettings;+function EmbedAlignLeft(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "left" }).run();+ } })));+}+exports.EmbedAlignLeft = EmbedAlignLeft;+function EmbedAlignRight(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "right" }).run();+ } })));+}+exports.EmbedAlignRight = EmbedAlignRight;+function EmbedAlignCenter(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "center" }).run();+ } })));+}+exports.EmbedAlignCenter = EmbedAlignCenter;+// TODO: stop re-rendering+function EmbedProperties(props) {+ const { editor } = props;+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ const buttonRef = (0, react_1.useRef)();+ // TODO: improve perf by deferring this until user opens the popup+ const embedNode = (0, react_1.useMemo)(() => (0, prosemirror_1.findSelectedNode)(editor, "embed"), []);+ const embed = ((embedNode === null || embedNode === void 0 ? void 0 : embedNode.attrs) || {});+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({ buttonRef: buttonRef, toggled: isOpen }, props, { onClick: () => setIsOpen((s) => !s) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, Object.assign({ isOpen: isOpen, desktop: "menu", mobile: "sheet", onClose: () => setIsOpen(false), blocking: true, focusOnRender: false, position: {+ target: buttonRef.current || "mouse",+ align: "start",+ location: "below",+ yOffset: 10,+ isTargetAbsolute: true,+ } }, { children: (0, jsx_runtime_1.jsx)(embedpopup_1.EmbedPopup, { title: "Embed properties", onClose: () => setIsOpen(false), embed: embed, onSourceChanged: (src) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSource(src); }, onSizeChanged: (size) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSize(size); } }) }))] }));+}+exports.EmbedProperties = EmbedProperties;diff --git a/packages/editor/dist/toolbar/tools/font.d.ts b/packages/editor/dist/cjs/toolbar/tools/font.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/font.d.tsrename to packages/editor/dist/cjs/toolbar/tools/font.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/font.js b/packages/editor/dist/cjs/toolbar/tools/font.jsnew file mode 100644index 000000000..614856edb--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/font.js@@ -0,0 +1,56 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.FontFamily = exports.FontSize = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const dropdown_1 = require("../components/dropdown");+const react_1 = require("react");+const counter_1 = require("../components/counter");+const useRefValue_1 = require("../../hooks/useRefValue");+function FontSize(props) {+ const { editor } = props;+ const { fontSize: _fontSize } = editor.getAttributes("textStyle");+ const fontSize = _fontSize || "16px";+ const fontSizeAsNumber = (0, useRefValue_1.useRefValue)(parseInt(fontSize.replace("px", "")));+ const decreaseFontSize = (0, react_1.useCallback)(() => {+ return Math.max(8, fontSizeAsNumber.current - 1);+ }, []);+ const increaseFontSize = (0, react_1.useCallback)(() => {+ return Math.min(120, fontSizeAsNumber.current + 1);+ }, []);+ return ((0, jsx_runtime_1.jsx)(counter_1.Counter, { title: "font size", onDecrease: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize(`${decreaseFontSize()}px`).run();+ }, onIncrease: () => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize(`${increaseFontSize()}px`).run();+ }, onReset: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize(`16px`).run(); }, value: fontSize }));+}+exports.FontSize = FontSize;+const fontFamilies = {+ System: "Open Sans",+ Serif: "serif",+ Monospace: "monospace",+};+function FontFamily(props) {+ var _a, _b;+ const { editor } = props;+ const currentFontFamily = ((_b = (_a = Object.entries(fontFamilies)+ .find(([key, value]) => editor.isActive("textStyle", { fontFamily: value }))) === null || _a === void 0 ? void 0 : _a.map((a) => a)) === null || _b === void 0 ? void 0 : _b.at(0)) || "System";+ const items = (0, react_1.useMemo)(() => toMenuItems(editor, currentFontFamily), [currentFontFamily]);+ return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentFontFamily, items: items, menuWidth: 130 }));+}+exports.FontFamily = FontFamily;+function toMenuItems(editor, currentFontFamily) {+ const menuItems = [];+ for (const key in fontFamilies) {+ const value = fontFamilies[key];+ menuItems.push({+ key,+ type: "button",+ title: key,+ isChecked: key === currentFontFamily,+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontFamily(value).run(); },+ });+ }+ return menuItems;+}diff --git a/packages/editor/dist/toolbar/tools/headings.d.ts b/packages/editor/dist/cjs/toolbar/tools/headings.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/headings.d.tsrename to packages/editor/dist/cjs/toolbar/tools/headings.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/headings.js b/packages/editor/dist/cjs/toolbar/tools/headings.jsnew file mode 100644index 000000000..9c7b79797--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/headings.js@@ -0,0 +1,36 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Headings = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const dropdown_1 = require("../components/dropdown");+const toolbarstore_1 = require("../stores/toolbarstore");+const react_1 = require("react");+const defaultLevels = [1, 2, 3, 4, 5, 6];+function Headings(props) {+ const { editor } = props;+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ const currentHeadingLevel = defaultLevels.find((level) => editor.isActive("heading", { level }));+ const items = (0, react_1.useMemo)(() => toMenuItems(editor, toolbarLocation, currentHeadingLevel), [currentHeadingLevel]);+ return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph", items: items, menuWidth: 130 }));+}+exports.Headings = Headings;+function toMenuItems(editor, toolbarLocation, currentHeadingLevel) {+ const menuItems = defaultLevels.map((level) => ({+ type: "button",+ key: `heading-${level}`,+ title: toolbarLocation === "bottom" ? `H${level}` : `Heading ${level}`,+ isChecked: level === currentHeadingLevel,+ onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().updateAttributes("textStyle", { fontSize: null, fontStyle: null }).setHeading({ level: level }).run();+ },+ }));+ const paragraph = {+ key: "paragraph",+ type: "button",+ title: "Paragraph",+ isChecked: !currentHeadingLevel,+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setParagraph().run(); },+ };+ return [paragraph, ...menuItems];+}diff --git a/packages/editor/dist/toolbar/tools/image.d.ts b/packages/editor/dist/cjs/toolbar/tools/image.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/image.d.tsrename to packages/editor/dist/cjs/toolbar/tools/image.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/image.js b/packages/editor/dist/cjs/toolbar/tools/image.jsnew file mode 100644index 000000000..9dee47d86--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/image.js@@ -0,0 +1,68 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.ImageProperties = exports.ImageAlignCenter = exports.ImageAlignRight = exports.ImageAlignLeft = exports.ImageSettings = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+const react_1 = require("react");+const responsive_1 = require("../../components/responsive");+const moretools_1 = require("../components/moretools");+const toolbarstore_1 = require("../stores/toolbarstore");+const imageproperties_1 = require("../popups/imageproperties");+const prosemirror_1 = require("../utils/prosemirror");+function ImageSettings(props) {+ var _a, _b;+ const { editor } = props;+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ if (!editor.isActive("image") || !isBottom)+ return null;+ return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "imageSettings", tools: ((_b = (_a = (0, prosemirror_1.findSelectedNode)(editor, "image")) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.float)+ ? ["imageAlignLeft", "imageAlignRight", "imageProperties"]+ : [+ "imageAlignLeft",+ "imageAlignCenter",+ "imageAlignRight",+ "imageProperties",+ ] })));+}+exports.ImageSettings = ImageSettings;+function ImageAlignLeft(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "left" }).run();+ } })));+}+exports.ImageAlignLeft = ImageAlignLeft;+function ImageAlignRight(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "right" }).run();+ } })));+}+exports.ImageAlignRight = ImageAlignRight;+function ImageAlignCenter(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "center" }).run();+ } })));+}+exports.ImageAlignCenter = ImageAlignCenter;+function ImageProperties(props) {+ const { editor } = props;+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ const buttonRef = (0, react_1.useRef)();+ // TODO: defer until user opens the popup+ const image = (0, react_1.useMemo)(() => (0, prosemirror_1.findSelectedNode)(editor, "image"), []);+ const { float, align, width, height } = ((image === null || image === void 0 ? void 0 : image.attrs) ||+ {});+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({ buttonRef: buttonRef, toggled: isOpen }, props, { onClick: () => setIsOpen((s) => !s) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, Object.assign({ isOpen: isOpen, desktop: "menu", mobile: "sheet", onClose: () => setIsOpen(false), blocking: true, focusOnRender: false, position: {+ target: buttonRef.current || "mouse",+ align: "start",+ location: "below",+ yOffset: 10,+ isTargetAbsolute: true,+ } }, { children: (0, jsx_runtime_1.jsx)(imageproperties_1.ImageProperties, { editor: editor, height: height, width: width, align: align, float: float, onClose: () => setIsOpen(false) }) }))] }));+}+exports.ImageProperties = ImageProperties;diff --git a/packages/editor/dist/toolbar/tools/index.d.ts b/packages/editor/dist/cjs/toolbar/tools/index.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/index.d.tsrename to packages/editor/dist/cjs/toolbar/tools/index.d.tsdiff --git a/packages/editor/dist/toolbar/tools/index.js b/packages/editor/dist/cjs/toolbar/tools/index.jssimilarity index 83%rename from packages/editor/dist/toolbar/tools/index.jsrename to packages/editor/dist/cjs/toolbar/tools/index.jsindex bb422e155..d6450a27d 100644--- a/packages/editor/dist/toolbar/tools/index.js+++ b/packages/editor/dist/cjs/toolbar/tools/index.js@@ -1,20 +1,20 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.findTool = void 0;-var inline_1 = require("./inline");-var block_1 = require("./block");-var font_1 = require("./font");-var alignment_1 = require("./alignment");-var headings_1 = require("./headings");-var lists_1 = require("./lists");-var textdirection_1 = require("./textdirection");-var colors_1 = require("./colors");-var table_1 = require("./table");-var image_1 = require("./image");-var attachment_1 = require("./attachment");-var embed_1 = require("./embed");-var link_1 = require("./link");-var tools = {+const inline_1 = require("./inline");+const block_1 = require("./block");+const font_1 = require("./font");+const alignment_1 = require("./alignment");+const headings_1 = require("./headings");+const lists_1 = require("./lists");+const textdirection_1 = require("./textdirection");+const colors_1 = require("./colors");+const table_1 = require("./table");+const image_1 = require("./image");+const attachment_1 = require("./attachment");+const embed_1 = require("./embed");+const link_1 = require("./link");+const tools = {bold: inline_1.Bold,italic: inline_1.Italic,underline: inline_1.Underline,diff --git a/packages/editor/dist/toolbar/tools/inline.d.ts b/packages/editor/dist/cjs/toolbar/tools/inline.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/inline.d.tsrename to packages/editor/dist/cjs/toolbar/tools/inline.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/inline.js b/packages/editor/dist/cjs/toolbar/tools/inline.jsnew file mode 100644index 000000000..9010cc88a--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/inline.js@@ -0,0 +1,62 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.Math = exports.CodeRemove = exports.ClearFormatting = exports.Superscript = exports.Subscript = exports.Bold = exports.Code = exports.Underline = exports.Strikethrough = exports.Italic = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+const toolbarstore_1 = require("../stores/toolbarstore");+function Italic(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("italic"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleItalic().run(); } })));+}+exports.Italic = Italic;+function Strikethrough(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("strike"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleStrike().run(); } })));+}+exports.Strikethrough = Strikethrough;+function Underline(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("underline"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleUnderline().run(); } })));+}+exports.Underline = Underline;+function Code(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("code"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleCode().run(); } })));+}+exports.Code = Code;+function Bold(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("bold"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBold().run(); } })));+}+exports.Bold = Bold;+function Subscript(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("subscript"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleSubscript().run(); } })));+}+exports.Subscript = Subscript;+function Superscript(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: editor.isActive("superscript"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleSuperscript().run(); } })));+}+exports.Superscript = Superscript;+function ClearFormatting(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().clearNodes().unsetAllMarks().unsetMark("link").run();+ } })));+}+exports.ClearFormatting = ClearFormatting;+function CodeRemove(props) {+ const { editor } = props;+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ if (!editor.isActive("code") || !isBottom)+ return null;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().unsetMark("code").run(); } })));+}+exports.CodeRemove = CodeRemove;+function Math(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathInline().run(); } })));+}+exports.Math = Math;diff --git a/packages/editor/dist/toolbar/tools/link.d.ts b/packages/editor/dist/cjs/toolbar/tools/link.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/link.d.tsrename to packages/editor/dist/cjs/toolbar/tools/link.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/link.js b/packages/editor/dist/cjs/toolbar/tools/link.jsnew file mode 100644index 000000000..2d55544a6--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/link.js@@ -0,0 +1,127 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.OpenLink = exports.RemoveLink = exports.EditLink = exports.AddLink = exports.LinkSettings = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+const react_1 = require("react");+const responsive_1 = require("../../components/responsive");+const linkpopup_1 = require("../popups/linkpopup");+const toolbarstore_1 = require("../stores/toolbarstore");+const moretools_1 = require("../components/moretools");+const useRefValue_1 = require("../../hooks/useRefValue");+const prosemirror_1 = require("../utils/prosemirror");+const prosemirror_utils_1 = require("prosemirror-utils");+const rebass_1 = require("rebass");+function LinkSettings(props) {+ const { editor } = props;+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ if (!editor.isActive("link") || !isBottom)+ return null;+ return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "linkSettings", tools: ["openLink", "editLink", "removeLink"] })));+}+exports.LinkSettings = LinkSettings;+function AddLink(props) {+ const { editor } = props;+ const isActive = props.editor.isActive("link");+ const onDone = (0, react_1.useCallback)((href, text) => {+ var _a;+ if (!href)+ return;+ let commandChain = (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus();+ if (!commandChain)+ return;+ commandChain+ .extendMarkRange("link")+ .toggleLink({ href, target: "_blank" })+ .insertContent(text || href)+ .focus()+ .unsetMark("link")+ .insertContent(" ")+ .run();+ }, []);+ if (isActive)+ return (0, jsx_runtime_1.jsx)(EditLink, Object.assign({}, props));+ return ((0, jsx_runtime_1.jsx)(LinkTool, Object.assign({}, props, { onDone: onDone, onClick: () => {+ let { from, to } = editor.state.selection;+ const selectedText = editor.state.doc.textBetween(from, to);+ return { text: selectedText };+ } })));+}+exports.AddLink = AddLink;+function EditLink(props) {+ const { editor, selectedNode: _selectedNode } = props;+ const selectedNode = (0, useRefValue_1.useRefValue)(_selectedNode || (0, prosemirror_1.selectionToOffset)(editor.state.selection));+ const onDone = (0, react_1.useCallback)((href, text) => {+ if (!href || !editor.current)+ return;+ const { from, node, to } = selectedNode.current;+ const mark = (0, prosemirror_1.findMark)(node, "link");+ if (!mark)+ return;+ editor.current+ .chain()+ .command(({ tr }) => {+ tr.removeMark(from, to, mark.type);+ tr.addMark(from, to, mark.type.create({ href }));+ tr.insertText(text || node.textContent, from, to);+ (0, prosemirror_utils_1.setTextSelection)(tr.mapping.map(from))(tr);+ return true;+ })+ .focus(undefined, { scrollIntoView: true })+ .run();+ }, []);+ return ((0, jsx_runtime_1.jsx)(LinkTool, Object.assign({}, props, { isEditing: true, onDone: onDone, onClick: () => {+ const { node } = selectedNode.current;+ const selectedText = node.textContent;+ const mark = (0, prosemirror_1.findMark)(node, "link");+ if (!mark)+ return;+ return { text: selectedText, href: mark.attrs.href };+ } })));+}+exports.EditLink = EditLink;+function RemoveLink(props) {+ const { editor, selectedNode } = props;+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a, _b;+ if (selectedNode)+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setTextSelection(selectedNode.from);+ (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetLink().run();+ } })));+}+exports.RemoveLink = RemoveLink;+function OpenLink(props) {+ const { editor, selectedNode } = props;+ const node = (selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.node) || editor.state.selection.$anchor.node();+ const link = selectedNode ? (0, prosemirror_1.findMark)(node, "link") : null;+ if (!link)+ return null;+ const href = link === null || link === void 0 ? void 0 : link.attrs.href;+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ as: "a", href: href, target: "_blank", variant: "body", sx: { mr: 1 } }, { children: href })), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { toggled: false, onClick: () => window.open(href, "_blank") }))] })));+}+exports.OpenLink = OpenLink;+function LinkTool(props) {+ const { isEditing, onClick, onDone } = props;+ const buttonRef = (0, react_1.useRef)(null);+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ const [href, setHref] = (0, react_1.useState)();+ const [text, setText] = (0, react_1.useState)();+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { buttonRef: buttonRef, onClick: () => {+ const result = onClick();+ if (!result)+ return;+ const { text, href } = result;+ setHref(href);+ setText(text);+ setIsOpen(true);+ }, toggled: isOpen })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, Object.assign({ mobile: "sheet", desktop: "menu", position: {+ target: buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ align: "center",+ yOffset: 5,+ }, title: isEditing ? "Edit link" : "Insert link", isOpen: isOpen, items: [], onClose: () => setIsOpen(false), focusOnRender: false }, { children: (0, jsx_runtime_1.jsx)(linkpopup_1.LinkPopup, { href: href, text: text, isEditing: isEditing, onClose: () => setIsOpen(false), onDone: ({ href, text }) => {+ onDone(href, text);+ setIsOpen(false);+ } }) }))] }));+}diff --git a/packages/editor/dist/toolbar/tools/lists.d.ts b/packages/editor/dist/cjs/toolbar/tools/lists.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/lists.d.tsrename to packages/editor/dist/cjs/toolbar/tools/lists.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/lists.js b/packages/editor/dist/cjs/toolbar/tools/lists.jsnew file mode 100644index 000000000..2365e66e8--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/lists.js@@ -0,0 +1,114 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+var __importDefault = (this && this.__importDefault) || function (mod) {+ return (mod && mod.__esModule) ? mod : { "default": mod };+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.BulletList = exports.NumberedList = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const rebass_1 = require("rebass");+const react_1 = require("react");+const splitbutton_1 = require("../components/splitbutton");+const toolbarstore_1 = require("../stores/toolbarstore");+const dom_1 = require("../utils/dom");+const popuppresenter_1 = require("../../components/popuppresenter");+const react_2 = __importDefault(require("react"));+function _ListTool(props) {+ const { editor, onClick, isActive, subTypes, type } = props, toolProps = __rest(props, ["editor", "onClick", "isActive", "subTypes", "type"]);+ const toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();+ const isBottom = toolbarLocation === "bottom";+ const [isOpen, setIsOpen] = (0, react_1.useState)(false);+ const buttonRef = (0, react_1.useRef)();+ return ((0, jsx_runtime_1.jsx)(splitbutton_1.SplitButton, Object.assign({}, toolProps, { buttonRef: buttonRef, onClick: onClick, toggled: isActive || isOpen, sx: { mr: 0 }, onOpen: () => setIsOpen((s) => !s) }, { children: (0, jsx_runtime_1.jsx)(popuppresenter_1.PopupWrapper, { isOpen: isOpen, group: "lists", id: toolProps.title, blocking: false, focusOnRender: false, position: {+ isTargetAbsolute: true,+ target: isBottom ? (0, dom_1.getToolbarElement)() : buttonRef.current || "mouse",+ align: "center",+ location: isBottom ? "top" : "below",+ yOffset: isBottom ? 10 : 5,+ }, onClosed: () => setIsOpen(false), renderPopup: () => ((0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ sx: {+ bg: "background",+ display: "grid",+ gridTemplateColumns: "1fr 1fr 1fr",+ p: 1,+ } }, { children: subTypes.map((item) => ((0, jsx_runtime_1.jsx)(rebass_1.Button, Object.assign({ variant: "menuitem", sx: { width: 80 }, onClick: () => {+ var _a;+ let chain = (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus();+ if (!chain)+ return;+ if (!isActive) {+ if (type === "bulletList")+ chain = chain.toggleBulletList();+ else+ chain = chain.toggleOrderedList();+ }+ return chain+ .updateAttributes(type, { listType: item.type })+ .run();+ } }, { children: (0, jsx_runtime_1.jsx)(ListThumbnail, { listStyleType: item.type }) }), item.title))) }))) }) })));+}+const ListTool = react_2.default.memo(_ListTool, (prev, next) => {+ return prev.isActive === next.isActive;+});+function NumberedList(props) {+ const { editor } = props;+ const onClick = (0, react_1.useCallback)(() => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOrderedList().run(); }, []);+ return ((0, jsx_runtime_1.jsx)(ListTool, Object.assign({}, props, { type: "orderedList", isActive: editor.isActive("orderedList"), onClick: onClick, subTypes: [+ { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },+ { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },+ {+ type: "upper-roman",+ title: "Upper Roman",+ items: ["I", "II", "III"],+ },+ {+ type: "lower-roman",+ title: "Lower Roman",+ items: ["i", "ii", "iii"],+ },+ { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },+ ] })));+}+exports.NumberedList = NumberedList;+function BulletList(props) {+ const { editor } = props;+ const onClick = (0, react_1.useCallback)(() => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOrderedList().run(); }, []);+ return ((0, jsx_runtime_1.jsx)(ListTool, Object.assign({}, props, { type: "bulletList", onClick: onClick, isActive: editor.isActive("bulletList"), subTypes: [+ { type: "disc", title: "Decimal", items: ["1", "2", "3"] },+ { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },+ ] })));+}+exports.BulletList = BulletList;+function ListThumbnail(props) {+ const { listStyleType } = props;+ return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ as: "ul", sx: {+ flexDirection: "column",+ flex: 1,+ p: 0,+ listStyleType,+ } }, { children: [0, 1, 2].map((i) => ((0, jsx_runtime_1.jsx)(rebass_1.Box, Object.assign({ as: "li", sx: {+ display: "list-item",+ color: "text",+ fontSize: 8,+ mb: "1px",+ } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, Object.assign({ sx: {+ alignItems: "center",+ } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, { sx: {+ width: "100%",+ flexShrink: 0,+ height: 4,+ bg: "#cbcbcb",+ borderRadius: "small",+ } }) })) }), i.toString()))) })));+}diff --git a/packages/editor/dist/toolbar/tools/table.d.ts b/packages/editor/dist/cjs/toolbar/tools/table.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/table.d.tsrename to packages/editor/dist/cjs/toolbar/tools/table.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/table.js b/packages/editor/dist/cjs/toolbar/tools/table.jsnew file mode 100644index 000000000..3f3ad8961--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/table.js@@ -0,0 +1,179 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.DeleteTable = exports.DeleteRow = exports.MoveRowDown = exports.MoveRowUp = exports.InsertRowBelow = exports.InsertRowAbove = exports.MergeCells = exports.SplitCells = exports.DeleteColumn = exports.MoveColumnRight = exports.MoveColumnLeft = exports.InsertColumnRight = exports.InsertColumnLeft = exports.CellBorderWidth = exports.CellBorderColor = exports.CellTextColor = exports.CellBackgroundColor = exports.CellProperties = exports.TableProperties = exports.ColumnProperties = exports.RowProperties = exports.TableSettings = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+const react_1 = require("react");+const rebass_1 = require("rebass");+const responsive_1 = require("../../components/responsive");+const actions_1 = require("../../extensions/table/actions");+const moretools_1 = require("../components/moretools");+const utils_1 = require("./utils");+const tooldefinitions_1 = require("../tooldefinitions");+const cellproperties_1 = require("../popups/cellproperties");+const colors_1 = require("./colors");+const counter_1 = require("../components/counter");+const toolbarstore_1 = require("../stores/toolbarstore");+const popuppresenter_1 = require("../../components/popuppresenter");+function TableSettings(props) {+ const { editor } = props;+ const isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";+ if (!editor.isActive("table") || !isBottom)+ return null;+ return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "tableSettings", tools: [+ "insertColumnLeft",+ "insertColumnRight",+ "insertRowAbove",+ "insertRowBelow",+ "cellProperties",+ "columnProperties",+ "rowProperties",+ "deleteRow",+ "deleteColumn",+ "deleteTable",+ ] })));+}+exports.TableSettings = TableSettings;+function RowProperties(props) {+ const { editor } = props;+ const buttonRef = (0, react_1.useRef)();+ const [isMenuOpen, setIsMenuOpen] = (0, react_1.useState)(false);+ const items = (0, react_1.useMemo)(() => [+ insertRowAbove(editor),+ insertRowBelow(editor),+ moveRowUp(editor),+ moveRowDown(editor),+ deleteRow(editor),+ ], []);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: () => setIsMenuOpen(true) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { title: "Row properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: () => setIsMenuOpen(false), position: {+ target: buttonRef.current,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ }, items: items })] }));+}+exports.RowProperties = RowProperties;+function ColumnProperties(props) {+ const { editor } = props;+ const buttonRef = (0, react_1.useRef)();+ const [isMenuOpen, setIsMenuOpen] = (0, react_1.useState)(false);+ const items = (0, react_1.useMemo)(() => [+ insertColumnLeft(editor),+ insertColumnRight(editor),+ moveColumnLeft(editor),+ moveColumnRight(editor),+ deleteColumn(editor),+ ], []);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: () => setIsMenuOpen(true) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { title: "Column properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: () => setIsMenuOpen(false), position: {+ target: buttonRef.current,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ }, items: items })] }));+}+exports.ColumnProperties = ColumnProperties;+function TableProperties(props) {+ const { editor } = props;+ const buttonRef = (0, react_1.useRef)();+ const [isMenuOpen, setIsMenuOpen] = (0, react_1.useState)(false);+ const items = (0, react_1.useMemo)(() => [+ insertColumnLeft(editor),+ insertColumnRight(editor),+ moveColumnLeft(editor),+ moveColumnRight(editor),+ deleteColumn(editor),+ { type: "separator", key: "cellSeperator" },+ mergeCells(editor),+ splitCells(editor),+ cellProperties(editor),+ { type: "separator", key: "tableSeperator" },+ deleteTable(editor),+ ], []);+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: () => setIsMenuOpen(true) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { title: "Table properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: () => setIsMenuOpen(false), position: {+ target: buttonRef.current,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ }, items: items })] }));+}+exports.TableProperties = TableProperties;+function CellProperties(props) {+ return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(moretools_1.MoreTools, Object.assign({}, props, { popupId: "cellProperties", tools: [+ "mergeCells",+ "splitCells",+ "cellBackgroundColor",+ "cellTextColor",+ "cellBorderColor",+ "cellBorderWidth",+ ] })) }));+}+exports.CellProperties = CellProperties;+function CellBackgroundColor(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(colors_1.ColorTool, Object.assign({}, props, { cacheKey: "cellBackgroundColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").backgroundColor; }, title: "Cell background color", onColorChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().setCellAttribute("backgroundColor", color).run(); } })));+}+exports.CellBackgroundColor = CellBackgroundColor;+function CellTextColor(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(colors_1.ColorTool, Object.assign({}, props, { cacheKey: "cellTextColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").color; }, title: "Cell text color", onColorChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setCellAttribute("color", color).run(); } })));+}+exports.CellTextColor = CellTextColor;+function CellBorderColor(props) {+ const { editor } = props;+ return ((0, jsx_runtime_1.jsx)(colors_1.ColorTool, Object.assign({}, props, { cacheKey: "cellBorderColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").borderColor; }, title: "Cell border color", onColorChange: (color) => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setCellAttribute("borderColor", color).run();+ } })));+}+exports.CellBorderColor = CellBorderColor;+function CellBorderWidth(props) {+ const { editor } = props;+ const { borderWidth: _borderWidth } = editor.getAttributes("tableCell");+ const borderWidth = _borderWidth ? _borderWidth : 1;+ const decreaseBorderWidth = (0, react_1.useCallback)(() => {+ return Math.max(1, borderWidth - 1);+ }, [borderWidth]);+ const increaseBorderWidth = (0, react_1.useCallback)(() => {+ return Math.min(10, borderWidth + 1);+ }, [borderWidth]);+ return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, Object.assign({ sx: { justifyContent: "center", alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, Object.assign({ variant: "subBody", sx: { mx: 1 } }, { children: "Border width:" })), (0, jsx_runtime_1.jsx)(counter_1.Counter, { title: "cell border width", onDecrease: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", decreaseBorderWidth());+ }, onIncrease: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", increaseBorderWidth());+ }, onReset: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", 1); }, value: borderWidth + "px" })] })));+}+exports.CellBorderWidth = CellBorderWidth;+const insertColumnLeft = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("insertColumnLeft")), { key: "addColumnLeft", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnBefore().run(); } }));+const insertColumnRight = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("insertColumnRight")), { key: "addColumnRight", type: "button", title: "Add column right", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnAfter().run(); }, icon: "insertColumnRight" }));+const moveColumnLeft = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("moveColumnLeft")), { key: "moveColumnLeft", type: "button", onClick: () => (0, actions_1.moveColumnLeft)(editor) }));+const moveColumnRight = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("moveColumnRight")), { key: "moveColumnRight", type: "button", onClick: () => (0, actions_1.moveColumnRight)(editor) }));+const deleteColumn = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("deleteColumn")), { key: "deleteColumn", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteColumn().run(); } }));+const splitCells = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("splitCells")), { key: "splitCells", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().splitCell().run(); } }));+const mergeCells = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("mergeCells")), { key: "mergeCells", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().mergeCells().run(); } }));+const insertRowAbove = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("insertRowAbove")), { key: "insertRowAbove", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addRowBefore().run(); } }));+const insertRowBelow = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("insertRowBelow")), { key: "insertRowBelow", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addRowAfter().run(); } }));+const moveRowUp = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("moveRowUp")), { key: "moveRowUp", type: "button", onClick: () => (0, actions_1.moveRowUp)(editor) }));+const moveRowDown = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("moveRowDown")), { key: "moveRowDown", type: "button", onClick: () => (0, actions_1.moveRowDown)(editor) }));+const deleteRow = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("deleteRow")), { key: "deleteRow", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteRow().run(); } }));+const deleteTable = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("deleteTable")), { key: "deleteTable", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteTable().run(); } }));+const cellProperties = (editor) => (Object.assign(Object.assign({}, (0, tooldefinitions_1.getToolDefinition)("cellProperties")), { key: "cellProperties", type: "button", onClick: () => {+ (0, popuppresenter_1.showPopup)({+ theme: editor.storage.theme,+ popup: (hide) => (0, jsx_runtime_1.jsx)(cellproperties_1.CellProperties, { onClose: hide, editor: editor }),+ });+ } }));+exports.InsertColumnLeft = (0, utils_1.menuButtonToTool)(insertColumnLeft);+exports.InsertColumnRight = (0, utils_1.menuButtonToTool)(insertColumnRight);+exports.MoveColumnLeft = (0, utils_1.menuButtonToTool)(moveColumnLeft);+exports.MoveColumnRight = (0, utils_1.menuButtonToTool)(moveColumnRight);+exports.DeleteColumn = (0, utils_1.menuButtonToTool)(deleteColumn);+exports.SplitCells = (0, utils_1.menuButtonToTool)(splitCells);+exports.MergeCells = (0, utils_1.menuButtonToTool)(mergeCells);+exports.InsertRowAbove = (0, utils_1.menuButtonToTool)(insertRowAbove);+exports.InsertRowBelow = (0, utils_1.menuButtonToTool)(insertRowBelow);+exports.MoveRowUp = (0, utils_1.menuButtonToTool)(moveRowUp);+exports.MoveRowDown = (0, utils_1.menuButtonToTool)(moveRowDown);+exports.DeleteRow = (0, utils_1.menuButtonToTool)(deleteRow);+exports.DeleteTable = (0, utils_1.menuButtonToTool)(deleteTable);diff --git a/packages/editor/dist/toolbar/tools/textdirection.d.ts b/packages/editor/dist/cjs/toolbar/tools/textdirection.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/textdirection.d.tsrename to packages/editor/dist/cjs/toolbar/tools/textdirection.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/textdirection.js b/packages/editor/dist/cjs/toolbar/tools/textdirection.jsnew file mode 100644index 000000000..8afc01850--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/textdirection.js@@ -0,0 +1,28 @@+"use strict";+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+Object.defineProperty(exports, "__esModule", { value: true });+exports.LeftToRight = exports.RightToLeft = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+function TextDirectionTool(props) {+ const { editor, direction } = props, toolProps = __rest(props, ["editor", "direction"]);+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(direction).run(); }, toggled: editor.isActive({ textDirection: direction }) })));+}+function RightToLeft(props) {+ return (0, jsx_runtime_1.jsx)(TextDirectionTool, Object.assign({ direction: "rtl" }, props));+}+exports.RightToLeft = RightToLeft;+function LeftToRight(props) {+ return (0, jsx_runtime_1.jsx)(TextDirectionTool, Object.assign({ direction: "ltr" }, props));+}+exports.LeftToRight = LeftToRight;diff --git a/packages/editor/dist/toolbar/tools/utils.d.ts b/packages/editor/dist/cjs/toolbar/tools/utils.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/tools/utils.d.tsrename to packages/editor/dist/cjs/toolbar/tools/utils.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/tools/utils.js b/packages/editor/dist/cjs/toolbar/tools/utils.jsnew file mode 100644index 000000000..6d30fe29c--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/tools/utils.js@@ -0,0 +1,12 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.menuButtonToTool = void 0;+const jsx_runtime_1 = require("react/jsx-runtime");+const toolbutton_1 = require("../components/toolbutton");+function menuButtonToTool(constructItem) {+ return function (props) {+ const item = constructItem(props.editor);+ return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, Object.assign({}, props, { icon: item.icon || props.icon, toggled: item.isChecked || false, title: item.title, onClick: item.onClick })));+ };+}+exports.menuButtonToTool = menuButtonToTool;diff --git a/packages/editor/dist/toolbar/types.d.ts b/packages/editor/dist/cjs/toolbar/types.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/types.d.tsrename to packages/editor/dist/cjs/toolbar/types.d.tsdiff --git a/packages/editor/dist/toolbar/types.js b/packages/editor/dist/cjs/toolbar/types.jssimilarity index 100%rename from packages/editor/dist/toolbar/types.jsrename to packages/editor/dist/cjs/toolbar/types.jsdiff --git a/packages/editor/dist/toolbar/utils/dom.d.ts b/packages/editor/dist/cjs/toolbar/utils/dom.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/utils/dom.d.tsrename to packages/editor/dist/cjs/toolbar/utils/dom.d.tsdiff --git a/packages/editor/dist/toolbar/utils/dom.js b/packages/editor/dist/cjs/toolbar/utils/dom.jssimilarity index 100%rename from packages/editor/dist/toolbar/utils/dom.jsrename to packages/editor/dist/cjs/toolbar/utils/dom.jsdiff --git a/packages/editor/dist/toolbar/utils/prosemirror.d.ts b/packages/editor/dist/cjs/toolbar/utils/prosemirror.d.tssimilarity index 100%rename from packages/editor/dist/toolbar/utils/prosemirror.d.tsrename to packages/editor/dist/cjs/toolbar/utils/prosemirror.d.tsdiff --git a/packages/editor/dist/cjs/toolbar/utils/prosemirror.js b/packages/editor/dist/cjs/toolbar/utils/prosemirror.jsnew file mode 100644index 000000000..cce718844--- /dev/null+++ b/packages/editor/dist/cjs/toolbar/utils/prosemirror.js@@ -0,0 +1,38 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.selectionToOffset = exports.findMark = exports.findSelectedNode = exports.findSelectedDOMNode = void 0;+const core_1 = require("@tiptap/core");+function findSelectedDOMNode(editor, types) {+ var _a;+ const { $anchor } = editor.state.selection;+ const selectedNode = editor.state.doc.nodeAt($anchor.pos);+ const pos = types.includes((selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type.name) || "")+ ? $anchor.pos+ : (_a = (0, core_1.findParentNode)((node) => types.includes(node.type.name))(editor.state.selection)) === null || _a === void 0 ? void 0 : _a.pos;+ if (!pos)+ return null;+ return editor.view.nodeDOM(pos) || null;+}+exports.findSelectedDOMNode = findSelectedDOMNode;+function findSelectedNode(editor, type) {+ var _a;+ const { $anchor } = editor.state.selection;+ const selectedNode = editor.state.doc.nodeAt($anchor.pos);+ const pos = (selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type.name) === type+ ? $anchor.pos+ : (_a = (0, core_1.findParentNode)((node) => node.type.name === type)(editor.state.selection)) === null || _a === void 0 ? void 0 : _a.pos;+ if (!pos)+ return null;+ return editor.state.doc.nodeAt(pos);+}+exports.findSelectedNode = findSelectedNode;+function findMark(node, type) {+ const mark = node.marks.find((m) => m.type.name === type);+ return mark;+}+exports.findMark = findMark;+function selectionToOffset(selection) {+ const { $from, from } = selection;+ return { node: $from.node(), from, to: from + $from.node().nodeSize };+}+exports.selectionToOffset = selectionToOffset;diff --git a/packages/editor/dist/types.d.ts b/packages/editor/dist/cjs/types.d.tssimilarity index 100%rename from packages/editor/dist/types.d.tsrename to packages/editor/dist/cjs/types.d.tsdiff --git a/packages/editor/dist/types.js b/packages/editor/dist/cjs/types.jssimilarity index 100%rename from packages/editor/dist/types.jsrename to packages/editor/dist/cjs/types.jsdiff --git a/packages/editor/dist/utils/config.d.ts b/packages/editor/dist/cjs/utils/config.d.tssimilarity index 100%rename from packages/editor/dist/utils/config.d.tsrename to packages/editor/dist/cjs/utils/config.d.tsdiff --git a/packages/editor/dist/utils/config.js b/packages/editor/dist/cjs/utils/config.jssimilarity index 85%rename from packages/editor/dist/utils/config.jsrename to packages/editor/dist/cjs/utils/config.jsindex 96965211d..9e9e639d9 100644--- a/packages/editor/dist/utils/config.js+++ b/packages/editor/dist/cjs/utils/config.js@@ -7,12 +7,12 @@ function set(key, value) {window.localStorage.setItem(key, JSON.stringify(value));}function get(key, def) {- var value = window.localStorage.getItem(key);+ const value = window.localStorage.getItem(key);if (!value)return def;return tryParse(value);}-exports.config = { set: set, get: get };+exports.config = { set, get };function tryParse(val) {if (val === "undefined" || val === "null")return;diff --git a/packages/editor/dist/utils/debounce.d.ts b/packages/editor/dist/cjs/utils/debounce.d.tssimilarity index 100%rename from packages/editor/dist/utils/debounce.d.tsrename to packages/editor/dist/cjs/utils/debounce.d.tsdiff --git a/packages/editor/dist/cjs/utils/debounce.js b/packages/editor/dist/cjs/utils/debounce.jsnew file mode 100644index 000000000..dba6b5144--- /dev/null+++ b/packages/editor/dist/cjs/utils/debounce.js@@ -0,0 +1,13 @@+"use strict";+Object.defineProperty(exports, "__esModule", { value: true });+exports.debounce = void 0;+function debounce(func, waitFor) {+ let timeout;+ const debounced = (...args) => {+ if (timeout)+ clearTimeout(timeout);+ timeout = setTimeout(() => func(...args), waitFor);+ };+ return debounced;+}+exports.debounce = debounce;diff --git a/packages/editor/dist/utils/position.d.ts b/packages/editor/dist/cjs/utils/position.d.tssimilarity index 100%rename from packages/editor/dist/utils/position.d.tsrename to packages/editor/dist/cjs/utils/position.d.tsdiff --git a/packages/editor/dist/utils/position.js b/packages/editor/dist/cjs/utils/position.jssimilarity index 67%rename from packages/editor/dist/utils/position.jsrename to packages/editor/dist/cjs/utils/position.jsindex 666828b87..cc2ec2c8a 100644--- a/packages/editor/dist/utils/position.js+++ b/packages/editor/dist/cjs/utils/position.js@@ -1,26 +1,26 @@"use strict";Object.defineProperty(exports, "__esModule", { value: true });exports.getElementPosition = exports.getPosition = void 0;-var mousePosition = { x: 0, y: 0, actualX: 0, actualY: 0 };-window.addEventListener("mousemove", function (e) {- var _a = getMousePosition(e), x = _a.x, y = _a.y, actualX = _a.actualX, actualY = _a.actualY;+const mousePosition = { x: 0, y: 0, actualX: 0, actualY: 0 };+window.addEventListener("mousemove", (e) => {+ const { x, y, actualX, actualY } = getMousePosition(e);mousePosition.x = x;mousePosition.y = y;mousePosition.actualX = actualX;mousePosition.actualY = actualY;});function getPosition(element, options) {- var _a = options || {}, _b = _a.target, target = _b === void 0 ? "mouse" : _b, _c = _a.isTargetAbsolute, isTargetAbsolute = _c === void 0 ? false : _c, _d = _a.location, location = _d === void 0 ? undefined : _d, _e = _a.yOffset, yOffset = _e === void 0 ? 0 : _e, _f = _a.xOffset, xOffset = _f === void 0 ? 0 : _f, _g = _a.align, align = _g === void 0 ? "start" : _g, _h = _a.parent, parent = _h === void 0 ? document.body : _h, yAnchor = _a.yAnchor;- var _j = target === "mouse"+ const { target = "mouse", isTargetAbsolute = false, location = undefined, yOffset = 0, xOffset = 0, align = "start", parent = document.body, yAnchor, } = options || {};+ const { x, y, width, height, actualX, actualY } = target === "mouse"? mousePosition- : getElementPosition(target, isTargetAbsolute), x = _j.x, y = _j.y, width = _j.width, height = _j.height, actualX = _j.actualX, actualY = _j.actualY;- var elementWidth = element.offsetWidth;- var elementHeight = element.offsetHeight;- var windowWidth = parent.clientWidth;- var windowHeight = parent.clientHeight;- var position = { top: 0, left: 0 };+ : getElementPosition(target, isTargetAbsolute);+ const elementWidth = element.offsetWidth;+ const elementHeight = element.offsetHeight;+ const windowWidth = parent.clientWidth;+ const windowHeight = parent.clientHeight;+ let position = { top: 0, left: 0 };if (windowWidth - actualX < elementWidth) {- var xDiff = actualX - x;+ const xDiff = actualX - x;position.left = windowWidth - elementWidth;position.left -= xDiff;}@@ -55,10 +55,10 @@ function getPosition(element, options) {}// Adjust menu heightif (elementHeight > windowHeight - position.top) {- element.style.maxHeight = "".concat(windowHeight - 20, "px");+ element.style.maxHeight = `${windowHeight - 20}px`;}if (yAnchor) {- var anchorY = getElementPosition(yAnchor, isTargetAbsolute);+ const anchorY = getElementPosition(yAnchor, isTargetAbsolute);position.top = anchorY.y - elementHeight;}position.top = isTargetAbsolute && position.top < 0 ? 0 : position.top;@@ -93,8 +93,8 @@ function getMousePosition(e) {};}function getElementPosition(element, absolute) {- var rect = element.getBoundingClientRect();- var position = {+ const rect = element.getBoundingClientRect();+ const position = {x: element.offsetLeft,y: element.offsetTop,width: rect.width,diff --git a/packages/editor/dist/components/button.js b/packages/editor/dist/components/button.jsdeleted file mode 100644index 71eadcbe4..000000000--- a/packages/editor/dist/components/button.js+++ /dev/null@@ -1,45 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Button = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var react_2 = require("react");-var rebass_1 = require("rebass");-exports.Button = (0, react_1.forwardRef)(function (props, forwardedRef) {- var buttonRef = (0, react_1.useRef)();- (0, react_2.useEffect)(function () {- if (!buttonRef.current)- return;- buttonRef.current.addEventListener("mousedown", onMouseDown, {- passive: false,- capture: true,- });- return function () {- var _a;- (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("mousedown", onMouseDown, {- capture: true,- });- };- }, []);- var onMouseDown = (0, react_1.useCallback)(function (e) {- e.preventDefault();- }, []);- return ((0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({}, props, { ref: function (ref) {- buttonRef.current = ref;- if (typeof forwardedRef === "function")- forwardedRef(ref);- else if (forwardedRef)- forwardedRef.current = ref;- }, onClick: props.onClick, onMouseDown: function () { } })));-});diff --git a/packages/editor/dist/components/inlineinput/index.js b/packages/editor/dist/components/inlineinput/index.jsdeleted file mode 100644index d0bfa349e..000000000--- a/packages/editor/dist/components/inlineinput/index.js+++ /dev/null@@ -1,41 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.InlineInput = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var forms_1 = require("@rebass/forms");-var rebass_1 = require("rebass");-function InlineInput(props) {- var label = props.label, containerProps = props.containerProps, sx = props.sx, inputProps = __rest(props, ["label", "containerProps", "sx"]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({}, containerProps, { sx: __assign(__assign({ flex: 1 }, containerProps === null || containerProps === void 0 ? void 0 : containerProps.sx), { outline: "1px solid var(--border)", p: 2, borderRadius: "default", ":focus-within": {- outlineColor: "primary",- outlineWidth: "1.8px",- } }) }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, __assign({ variant: "clean", sx: __assign(__assign({}, sx), { p: 0 }) }, inputProps)), (0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "body", sx: {- flexShrink: 0,- color: "fontTertiary",- borderLeft: "1px solid var(--border)",- pl: 1,- } }, { children: label }))] })));-}-exports.InlineInput = InlineInput;diff --git a/packages/editor/dist/components/menu/menubutton.js b/packages/editor/dist/components/menu/menubutton.jsdeleted file mode 100644index 5fe8caa80..000000000--- a/packages/editor/dist/components/menu/menubutton.js+++ /dev/null@@ -1,42 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.MenuButton = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var rebass_1 = require("rebass");-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var toolbarstore_1 = require("../../toolbar/stores/toolbarstore");-var button_1 = require("../button");-function MenuButton(props) {- var item = props.item, isFocused = props.isFocused, onMouseEnter = props.onMouseEnter, onMouseLeave = props.onMouseLeave, onClick = props.onClick;- var title = item.title, key = item.key, icon = item.icon, tooltip = item.tooltip, isDisabled = item.isDisabled, isChecked = item.isChecked, menu = item.menu, modifier = item.modifier;- var itemRef = (0, react_1.useRef)(null);- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- var isBottom = toolbarLocation === "bottom";- return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ as: "li", sx: { flexShrink: 0, flexDirection: "column" }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, { children: (0, jsx_runtime_1.jsxs)(button_1.Button, __assign({ id: key, "data-test-id": "MenuButton-".concat(key), ref: itemRef, tabIndex: -1, variant: "menuitem", title: tooltip, disabled: isDisabled, onClick: onClick, sx: {- bg: isFocused && !isBottom ? "hover" : "transparent",- display: "flex",- alignItems: "center",- justifyContent: "space-between",- ":hover": {- bg: isBottom ? "transparent" : "hover",- },- } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [icon && ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons[icon], color: "text", size: "medium", sx: { mr: 2 } })), (0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ as: "span", variant: "body", sx: { fontSize: "inherit" } }, { children: title }))] }), isChecked || menu || modifier ? ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { ml: 4 } }, { children: [isChecked && (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.check, size: 14 }), menu && (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.chevronRight, size: 14 }), modifier && ((0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ as: "span", sx: {- fontFamily: "body",- fontSize: "menu",- color: "fontTertiary",- } }, { children: modifier })))] }))) : null] }), key) })));-}-exports.MenuButton = MenuButton;diff --git a/packages/editor/dist/components/popuppresenter/popuprenderer.js b/packages/editor/dist/components/popuppresenter/popuprenderer.jsdeleted file mode 100644index f13b717ba..000000000--- a/packages/editor/dist/components/popuppresenter/popuprenderer.js+++ /dev/null@@ -1,129 +0,0 @@-"use strict";-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {- if (k2 === undefined) k2 = k;- var desc = Object.getOwnPropertyDescriptor(m, k);- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {- desc = { enumerable: true, get: function() { return m[k]; } };- }- Object.defineProperty(o, k2, desc);-}) : (function(o, m, k, k2) {- if (k2 === undefined) k2 = k;- o[k2] = m[k];-}));-var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {- Object.defineProperty(o, "default", { enumerable: true, value: v });-}) : function(o, v) {- o["default"] = v;-});-var __importStar = (this && this.__importStar) || function (mod) {- if (mod && mod.__esModule) return mod;- var result = {};- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);- __setModuleDefault(result, mod);- return result;-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.useEditorContext = exports.usePopupRenderer = exports.PopupRenderer = exports.EditorContext = exports.PopupRendererContext = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importStar(require("react"));-exports.PopupRendererContext = react_1.default.createContext(null);-exports.EditorContext = react_1.default.createContext(null);-var PopupRenderer = /** @class */ (function (_super) {- __extends(PopupRenderer, _super);- function PopupRenderer() {- var _this = _super !== null && _super.apply(this, arguments) || this;- _this.popupContainer = null;- _this.state = {- popups: [],- };- _this.openPopup = function (id, popup) {- if (!popup)- return;- _this.setState(function (prev) {- return {- popups: __spreadArray(__spreadArray([], __read(prev.popups), false), [{ id: id, popup: popup }], false),- };- });- };- _this.closePopup = function (id) {- _this.setState(function (prev) {- var index = prev.popups.findIndex(function (p) { return p.id === id; });- if (index <= -1)- return prev;- var clone = prev.popups.slice();- clone.splice(index, 1);- return {- popups: clone,- };- });- };- return _this;- }- PopupRenderer.prototype.render = function () {- return ((0, jsx_runtime_1.jsxs)(exports.PopupRendererContext.Provider, __assign({ value: this }, { children: [this.props.children, (0, jsx_runtime_1.jsxs)(exports.EditorContext.Provider, __assign({ value: this.props.editor }, { children: [this.state.popups.map(function (_a) {- var id = _a.id, Popup = _a.popup;- return (0, jsx_runtime_1.jsx)(Popup, { id: id }, id);- }), (0, jsx_runtime_1.jsx)("div", { id: "popup-container" })] }))] })));- };- return PopupRenderer;-}(react_1.default.Component));-exports.PopupRenderer = PopupRenderer;-function usePopupRenderer() {- return (0, react_1.useContext)(exports.PopupRendererContext);-}-exports.usePopupRenderer = usePopupRenderer;-function useEditorContext() {- return (0, react_1.useContext)(exports.EditorContext);-}-exports.useEditorContext = useEditorContext;diff --git a/packages/editor/dist/es/components/actionsheet/index.d.ts b/packages/editor/dist/es/components/actionsheet/index.d.tsnew file mode 100644index 000000000..b3a00090c--- /dev/null+++ b/packages/editor/dist/es/components/actionsheet/index.d.ts@@ -0,0 +1,12 @@+import { PropsWithChildren } from "react";+import { MenuItem } from "../menu/types";+export declare type ActionSheetPresenterProps = {+ items?: MenuItem[];+ isOpen: boolean;+ 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/es/components/actionsheet/index.js b/packages/editor/dist/es/components/actionsheet/index.jsnew file mode 100644index 000000000..951927fa3--- /dev/null+++ b/packages/editor/dist/es/components/actionsheet/index.js@@ -0,0 +1,175 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import React, { useCallback, useRef, useState, useEffect, } from "react";+import { useTheme } from "emotion-theming";+import { Box, Button, Flex, Text } from "rebass";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { MenuButton } from "../menu/menu-button";+import { MenuSeparator } from "../menu/menu-separator";+import Modal from "react-modal";+import { motion, useMotionValue, useTransform, useAnimation, } from "framer-motion";+const AnimatedFlex = motion(Flex);+const TRANSITION = {+ type: "spring",+ stiffness: 300,+ damping: 30,+ mass: 0.2,+ duration: 300,+};+function useHistory(initial) {+ const [current, setCurrent] = useState(initial);+ const [canGoBack, setCanGoBack] = useState(false);+ const stack = useRef([initial]);+ const goBack = useCallback(() => {+ if (!canGoBack)+ return;+ const prev = stack.current.pop();+ setCurrent(prev);+ if (stack.current.length <= 1)+ setCanGoBack(false);+ }, [canGoBack]);+ const navigate = useCallback((state) => {+ console.log("NAVI", state);+ setCurrent((prev) => {+ if (prev)+ stack.current.push(prev);+ return state;+ });+ setCanGoBack(true);+ }, []);+ return { current, goBack, navigate, canGoBack };+}+export function ActionSheetPresenter(props) {+ var _a;+ const { isOpen, title, items, onClose, blocking = true, focusOnRender = true, draggable = true, children, } = props;+ const theme = useTheme();+ const contentRef = useRef();+ const y = useMotionValue(0);+ const opacity = useTransform(y, [0, ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || window.innerHeight], [1, 0]);+ const animation = useAnimation();+ const onBeforeClose = useCallback(() => {+ var _a;+ const height = ((_a = contentRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || window.innerHeight;+ setTimeout(() => {+ onClose === null || onClose === void 0 ? void 0 : onClose();+ }, TRANSITION.duration - 50);+ animation.start({+ transition: TRANSITION,+ y: height + 100,+ });+ }, [animation, onClose, contentRef.current]);+ const handleBackPress = useCallback((event) => {+ if (!isOpen)+ return;+ event.preventDefault();+ onBeforeClose();+ }, [isOpen, onBeforeClose]);+ useEffect(() => {+ // Note: this is a custom event implemented on the React Native+ // side to handle back button when action sheet is opened.+ window.addEventListener("handleBackPress", handleBackPress);+ return () => {+ window.removeEventListener("handleBackPress", handleBackPress);+ };+ }, [handleBackPress]);+ if (!isOpen)+ return null;+ return (_jsx(Modal, Object.assign({ contentRef: (ref) => (contentRef.current = ref), className: "bottom-sheet-presenter", role: "menu", isOpen: isOpen, appElement: document.body, shouldCloseOnEsc: blocking, shouldReturnFocusAfterClose: focusOnRender, shouldCloseOnOverlayClick: blocking, shouldFocusAfterRender: focusOnRender, ariaHideApp: blocking, preventScroll: blocking, onRequestClose: () => onBeforeClose(), portalClassName: "bottom-sheet-presenter-portal", onAfterOpen: () => {+ animation.start({ transition: TRANSITION, y: 0 });+ }, overlayElement: (props, contentEl) => {+ return (_jsxs(Box, Object.assign({}, props, {+ //@ts-ignore+ style: Object.assign(Object.assign({}, props.style), { position: blocking ? "fixed" : "sticky", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }), tabIndex: -1 }, { children: [blocking && (_jsx(motion.div, { id: "action-sheet-overlay", style: {+ height: "100%",+ width: "100%",+ opacity,+ position: "absolute",+ backgroundColor: "var(--overlay)",+ }, tabIndex: -1 })), contentEl] })));+ }, contentElement: (props, children) => (_jsx(Box, Object.assign({}, props, { style: {}, sx: {+ // top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ display: "flex",+ width: "auto",+ height: "fit-content",+ position: "fixed",+ backgroundColor: undefined,+ padding: 0,+ zIndex: 0,+ outline: 0,+ isolation: "isolate",+ } }, { children: children }))) }, { children: _jsxs(AnimatedFlex, Object.assign({ animate: animation, style: { y }, initial: { y: 1000 }, sx: {+ bg: "background",+ borderTopLeftRadius: 15,+ borderTopRightRadius: 15,+ boxShadow: theme.shadows.menu,+ flex: 1,+ flexDirection: "column",+ } }, { children: [draggable && (_jsx(AnimatedFlex, Object.assign({ drag: "y",+ // @ts-ignore+ onDrag: (_, { delta }) => {+ y.set(Math.max(y.get() + delta.y, 0));+ },+ // @ts-ignore+ onDragEnd: (_, { velocity }) => {+ if (velocity.y >= 500) {+ onClose === null || onClose === void 0 ? void 0 : onClose();+ return;+ }+ const sheetEl = contentRef.current;+ const contentHeight = sheetEl.offsetHeight;+ const threshold = 30;+ const closingHeight = (contentHeight * threshold) / 100;+ if (y.get() >= closingHeight) {+ onBeforeClose();+ }+ else {+ animation.start({ transition: TRANSITION, y: 0 });+ }+ }, dragConstraints: { top: 0, bottom: 0 }, dragMomentum: false, dragElastic: false, sx: {+ bg: "transparent",+ alignItems: "center",+ justifyContent: "center",+ p: 2,+ } }, { children: _jsx(Box, { id: "pill", sx: {+ backgroundColor: "hover",+ width: 60,+ height: 8,+ borderRadius: 100,+ } }) }))), _jsx(ContentContainer, Object.assign({ items: items, title: title, onClose: onClose }, { children: children }))] })) })));+}+function ContentContainer(props) {+ var _a;+ const { title, items, onClose, children } = props;+ const { current, goBack, canGoBack, navigate } = useHistory({+ title,+ items,+ });+ return (_jsxs(Flex, Object.assign({ sx: { flexDirection: "column" } }, { children: [canGoBack || (current === null || current === void 0 ? void 0 : current.title) ? (_jsxs(Flex, Object.assign({ id: "header", sx: { alignItems: "center", mx: 0, mb: 1 } }, { children: [canGoBack && (_jsx(Button, Object.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, Object.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((item) => {+ if (item.isHidden)+ return null;+ switch (item.type) {+ case "separator":+ return _jsx(MenuSeparator, {}, item.key);+ case "button":+ return (_jsx(MenuButton, { item: item, onClick: (e) => {+ if (item.menu) {+ navigate(item.menu);+ }+ else if (item.onClick) {+ onClose === null || onClose === void 0 ? void 0 : onClose();+ setTimeout(() => {+ var _a;+ (_a = item.onClick) === null || _a === void 0 ? void 0 : _a.call(item);+ }, 300);+ }+ } }, item.key));+ case "popup":+ return (_jsx(React.Fragment, { children: _jsx(item.component, { onClick: onClose }) }, item.key));+ }+ })] })));+}diff --git a/packages/editor/dist/es/components/button.d.ts b/packages/editor/dist/es/components/button.d.tsnew file mode 100644index 000000000..f118730d4--- /dev/null+++ b/packages/editor/dist/es/components/button.d.ts@@ -0,0 +1,3 @@+/// <reference types="react" />+import { ButtonProps } from "rebass";+export declare const Button: import("react").ForwardRefExoticComponent<Pick<ButtonProps, "name" | "onFocus" | "onBlur" | "fontSize" | "style" | "textAlign" | "fontFamily" | "color" | "dir" | "content" | "draggable" | "alignContent" | "alignItems" | "alignSelf" | "backgroundColor" | "display" | "flex" | "flexBasis" | "flexDirection" | "flexGrow" | "flexShrink" | "flexWrap" | "fontStyle" | "fontWeight" | "height" | "justifyContent" | "justifyItems" | "justifySelf" | "letterSpacing" | "lineHeight" | "margin" | "marginBottom" | "marginLeft" | "marginRight" | "marginTop" | "maxHeight" | "maxWidth" | "minHeight" | "minWidth" | "opacity" | "order" | "overflow" | "overflowX" | "overflowY" | "padding" | "paddingBottom" | "paddingLeft" | "paddingRight" | "paddingTop" | "translate" | "verticalAlign" | "width" | "default" | "px" | "value" | "children" | "cite" | "data" | "form" | "label" | "p" | "slot" | "span" | "summary" | "title" | "pattern" | "sizes" | "key" | "selected" | "variant" | "tx" | "as" | "css" | "m" | "mt" | "mr" | "mb" | "ml" | "mx" | "marginX" | "my" | "marginY" | "pt" | "pr" | "pb" | "pl" | "paddingX" | "py" | "paddingY" | "size" | "bg" | "sx" | "accept" | "acceptCharset" | "action" | "allowFullScreen" | "allowTransparency" | "alt" | "async" | "autoComplete" | "autoFocus" | "autoPlay" | "capture" | "cellPadding" | "cellSpacing" | "charSet" | "challenge" | "checked" | "classID" | "cols" | "colSpan" | "controls" | "coords" | "crossOrigin" | "dateTime" | "defer" | "disabled" | "download" | "encType" | "formAction" | "formEncType" | "formMethod" | "formNoValidate" | "formTarget" | "frameBorder" | "headers" | "high" | "href" | "hrefLang" | "htmlFor" | "httpEquiv" | "integrity" | "keyParams" | "keyType" | "kind" | "list" | "loop" | "low" | "manifest" | "marginHeight" | "marginWidth" | "max" | "maxLength" | "media" | "mediaGroup" | "method" | "min" | "minLength" | "multiple" | "muted" | "nonce" | "noValidate" | "open" | "optimum" | "placeholder" | "playsInline" | "poster" | "preload" | "readOnly" | "rel" | "required" | "reversed" | "rows" | "rowSpan" | "sandbox" | "scope" | "scoped" | "scrolling" | "seamless" | "shape" | "src" | "srcDoc" | "srcLang" | "srcSet" | "start" | "step" | "target" | "type" | "useMap" | "wmode" | "wrap" | "defaultChecked" | "defaultValue" | "suppressContentEditableWarning" | "suppressHydrationWarning" | "accessKey" | "className" | "contentEditable" | "contextMenu" | "hidden" | "id" | "lang" | "spellCheck" | "tabIndex" | "radioGroup" | "role" | "about" | "datatype" | "inlist" | "prefix" | "property" | "resource" | "typeof" | "vocab" | "autoCapitalize" | "autoCorrect" | "autoSave" | "itemProp" | "itemScope" | "itemType" | "itemID" | "itemRef" | "results" | "security" | "unselectable" | "inputMode" | "is" | "aria-activedescendant" | "aria-atomic" | "aria-autocomplete" | "aria-busy" | "aria-checked" | "aria-colcount" | "aria-colindex" | "aria-colspan" | "aria-controls" | "aria-current" | "aria-describedby" | "aria-details" | "aria-disabled" | "aria-dropeffect" | "aria-errormessage" | "aria-expanded" | "aria-flowto" | "aria-grabbed" | "aria-haspopup" | "aria-hidden" | "aria-invalid" | "aria-keyshortcuts" | "aria-label" | "aria-labelledby" | "aria-level" | "aria-live" | "aria-modal" | "aria-multiline" | "aria-multiselectable" | "aria-orientation" | "aria-owns" | "aria-placeholder" | "aria-posinset" | "aria-pressed" | "aria-readonly" | "aria-relevant" | "aria-required" | "aria-roledescription" | "aria-rowcount" | "aria-rowindex" | "aria-rowspan" | "aria-selected" | "aria-setsize" | "aria-sort" | "aria-valuemax" | "aria-valuemin" | "aria-valuenow" | "aria-valuetext" | "dangerouslySetInnerHTML" | "onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocusCapture" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture"> & import("react").RefAttributes<HTMLButtonElement>>;diff --git a/packages/editor/dist/es/components/button.js b/packages/editor/dist/es/components/button.jsnew file mode 100644index 000000000..e523703f1--- /dev/null+++ b/packages/editor/dist/es/components/button.js@@ -0,0 +1,31 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { forwardRef, useCallback, useRef } from "react";+import { useEffect } from "react";+import { Button as RebassButton } from "rebass";+export const Button = forwardRef((props, forwardedRef) => {+ const buttonRef = useRef();+ useEffect(() => {+ if (!buttonRef.current)+ return;+ buttonRef.current.addEventListener("mousedown", onMouseDown, {+ passive: false,+ capture: true,+ });+ return () => {+ var _a;+ (_a = buttonRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener("mousedown", onMouseDown, {+ capture: true,+ });+ };+ }, []);+ const onMouseDown = useCallback((e) => {+ e.preventDefault();+ }, []);+ return (_jsx(RebassButton, Object.assign({}, props, { ref: (ref) => {+ buttonRef.current = ref;+ if (typeof forwardedRef === "function")+ forwardedRef(ref);+ else if (forwardedRef)+ forwardedRef.current = ref;+ }, onClick: props.onClick, onMouseDown: () => { } })));+});diff --git a/packages/editor/dist/es/components/inlineinput/index.d.ts b/packages/editor/dist/es/components/inlineinput/index.d.tsnew file mode 100644index 000000000..d9936bb07--- /dev/null+++ b/packages/editor/dist/es/components/inlineinput/index.d.ts@@ -0,0 +1,9 @@+/// <reference types="react" />+import { InputProps } from "@rebass/forms";+import { FlexProps } from "rebass";+declare type LabelInputProps = InputProps & {+ label: string;+ containerProps?: FlexProps;+};+export declare function InlineInput(props: LabelInputProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/components/inlineinput/index.js b/packages/editor/dist/es/components/inlineinput/index.jsnew file mode 100644index 000000000..619e320c8--- /dev/null+++ b/packages/editor/dist/es/components/inlineinput/index.js@@ -0,0 +1,26 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Input } from "@rebass/forms";+import { Flex, Text } from "rebass";+export function InlineInput(props) {+ const { label, containerProps, sx } = props, inputProps = __rest(props, ["label", "containerProps", "sx"]);+ return (_jsxs(Flex, Object.assign({}, containerProps, { sx: Object.assign(Object.assign({ flex: 1 }, containerProps === null || containerProps === void 0 ? void 0 : containerProps.sx), { outline: "1px solid var(--border)", p: 2, borderRadius: "default", ":focus-within": {+ outlineColor: "primary",+ outlineWidth: "1.8px",+ } }) }, { children: [_jsx(Input, Object.assign({ variant: "clean", sx: Object.assign(Object.assign({}, sx), { p: 0 }) }, inputProps)), _jsx(Text, Object.assign({ variant: "body", sx: {+ flexShrink: 0,+ color: "fontTertiary",+ borderLeft: "1px solid var(--border)",+ pl: 1,+ } }, { children: label }))] })));+}diff --git a/packages/editor/dist/es/components/menu/index.d.ts b/packages/editor/dist/es/components/menu/index.d.tsnew file mode 100644index 000000000..6af5e4dea--- /dev/null+++ b/packages/editor/dist/es/components/menu/index.d.ts@@ -0,0 +1,15 @@+import { PropsWithChildren } from "react";+import { FlexProps } from "rebass";+import { MenuItem as MenuItemType } from "./types";+import { PopupPresenterProps as _PopupPresenterProps } from "../popup-presenter";+declare type MenuProps = MenuContainerProps & {+ items?: MenuItemType[];+ onClose: () => void;+};+export declare function Menu(props: MenuProps): JSX.Element;+declare type MenuContainerProps = FlexProps & {+ title?: string;+};+export declare type MenuPresenterProps = _PopupPresenterProps & MenuProps;+export declare function MenuPresenter(props: PropsWithChildren<MenuPresenterProps>): JSX.Element;+export {};diff --git a/packages/editor/dist/es/components/menu/index.js b/packages/editor/dist/es/components/menu/index.jsnew file mode 100644index 000000000..18050aa40--- /dev/null+++ b/packages/editor/dist/es/components/menu/index.js@@ -0,0 +1,113 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { useCallback, useRef, useEffect, } from "react";+import { Box, Flex, Text } from "rebass";+import { getPosition } from "../../utils/position";+import { useFocus } from "./use-focus";+import { MenuSeparator } from "./menu-separator";+import { MenuButton } from "./menu-button";+import { PopupPresenter as _PopupPresenter, } from "../popup-presenter";+export function Menu(props) {+ const { items = [], title, onClose } = props, containerProps = __rest(props, ["items", "title", "onClose"]);+ const hoverTimeout = useRef();+ const onAction = useCallback((e, item) => {+ e === null || e === void 0 ? void 0 : e.stopPropagation();+ if (item === null || item === void 0 ? void 0 : item.onClick) {+ item.onClick();+ }+ if (onClose)+ onClose();+ }, [onClose]);+ const { focusIndex, setFocusIndex, isSubmenuOpen, setIsSubmenuOpen } = useFocus(items, (e) => {+ const item = items[focusIndex];+ if (item && item.type === "button")+ onAction(e, item);+ }, () => onClose());+ const focusedItem = items[focusIndex];+ const subMenuRef = useRef(null);+ useEffect(() => {+ const item = items[focusIndex];+ if (!item || !subMenuRef.current)+ return;+ const menuItemElement = document.getElementById(item.key);+ if (!menuItemElement)+ return;+ if (!isSubmenuOpen) {+ subMenuRef.current.style.visibility = "hidden";+ return;+ }+ const { top, left } = getPosition(subMenuRef.current, {+ // yOffset: menuItemElement.offsetHeight,+ target: menuItemElement,+ location: "right",+ });+ subMenuRef.current.style.visibility = "visible";+ subMenuRef.current.style.top = `${top}px`;+ subMenuRef.current.style.left = `${left}px`;+ }, [isSubmenuOpen, focusIndex, items]);+ return (_jsxs(_Fragment, { children: [_jsx(MenuContainer, Object.assign({}, containerProps, { children: items.map((item, index) => {+ if (item.isHidden)+ return null;+ switch (item.type) {+ case "separator":+ return _jsx(MenuSeparator, {}, item.key);+ case "button":+ return (_jsx(MenuButton, { item: item, onClick: (e) => {+ if (item.menu) {+ setFocusIndex(index);+ setIsSubmenuOpen(true);+ }+ else+ onAction(e, item);+ }, isFocused: focusIndex === index, onMouseEnter: () => {+ if (item.isDisabled) {+ setFocusIndex(-1);+ return;+ }+ if (hoverTimeout.current)+ clearTimeout(hoverTimeout.current);+ setFocusIndex(index);+ setIsSubmenuOpen(false);+ if (item.menu) {+ hoverTimeout.current = setTimeout(() => {+ setIsSubmenuOpen(true);+ }, 500);+ }+ }, onMouseLeave: () => {+ if (hoverTimeout.current)+ clearTimeout(hoverTimeout.current);+ } }, item.key));+ case "popup":+ return _jsx(item.component, { onClick: (e) => onAction(e) });+ }+ }) })), (focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.type) === "button" && (focusedItem === null || focusedItem === void 0 ? void 0 : focusedItem.menu) && isSubmenuOpen && (_jsx(Flex, Object.assign({ ref: subMenuRef, style: { visibility: "hidden" }, sx: {+ position: "absolute",+ } }, { children: _jsx(Menu, { items: focusedItem.menu.items, onClose: onClose }) })))] }));+}+function MenuContainer(props) {+ const { children, title, sx } = props, flexProps = __rest(props, ["children", "title", "sx"]);+ return (_jsxs(Box, Object.assign({ className: "menuContainer", as: "ul", tabIndex: -1, sx: Object.assign({ bg: "background", py: 1, display: "flex", flexDirection: "column", position: "relative", listStyle: "none", padding: 0, margin: 0, borderRadius: "default", boxShadow: "menu", border: "1px solid var(--border)", minWidth: 220 }, sx) }, flexProps, { children: [title && (_jsx(Text, Object.assign({ sx: {+ fontFamily: "body",+ fontSize: "subtitle",+ color: "primary",+ py: "8px",+ px: 3,+ borderBottom: "1px solid",+ borderBottomColor: "border",+ wordWrap: "break-word",+ } }, { children: title }))), children] })));+}+export function MenuPresenter(props) {+ const { items = [] } = props, restProps = __rest(props, ["items"]);+ return (_jsx(_PopupPresenter, Object.assign({}, restProps, { children: props.children ? props.children : _jsx(Menu, Object.assign({ items: items }, restProps)) })));+}diff --git a/packages/editor/dist/es/components/menu/menubutton.d.ts b/packages/editor/dist/es/components/menu/menubutton.d.tsnew file mode 100644index 000000000..11b6437af--- /dev/null+++ b/packages/editor/dist/es/components/menu/menubutton.d.ts@@ -0,0 +1,11 @@+/// <reference types="react" />+import { MenuButton } from "./types";+declare type MenuButtonProps = {+ item: MenuButton;+ isFocused?: boolean;+ onMouseEnter?: () => void;+ onMouseLeave?: () => void;+ onClick: (e?: any) => void;+};+export declare function MenuButton(props: MenuButtonProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/components/menu/menubutton.js b/packages/editor/dist/es/components/menu/menubutton.jsnew file mode 100644index 000000000..b62ac4f7e--- /dev/null+++ b/packages/editor/dist/es/components/menu/menubutton.js@@ -0,0 +1,27 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { useRef } from "react";+import { Flex, Text } from "rebass";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { useToolbarLocation } from "../../toolbar/stores/toolbar-store";+import { Button } from "../button";+export function MenuButton(props) {+ const { item, isFocused, onMouseEnter, onMouseLeave, onClick } = props;+ const { title, key, icon, tooltip, isDisabled, isChecked, menu, modifier } = item;+ const itemRef = useRef(null);+ const toolbarLocation = useToolbarLocation();+ const isBottom = toolbarLocation === "bottom";+ return (_jsx(Flex, Object.assign({ as: "li", sx: { flexShrink: 0, flexDirection: "column" }, onMouseEnter: onMouseEnter, onMouseLeave: onMouseLeave }, { children: _jsxs(Button, Object.assign({ id: key, "data-test-id": `MenuButton-${key}`, ref: itemRef, tabIndex: -1, variant: "menuitem", title: tooltip, disabled: isDisabled, onClick: onClick, sx: {+ bg: isFocused && !isBottom ? "hover" : "transparent",+ display: "flex",+ alignItems: "center",+ justifyContent: "space-between",+ ":hover": {+ bg: isBottom ? "transparent" : "hover",+ },+ } }, { children: [_jsxs(Flex, { children: [icon && (_jsx(Icon, { path: Icons[icon], color: "text", size: "medium", sx: { mr: 2 } })), _jsx(Text, Object.assign({ as: "span", variant: "body", sx: { fontSize: "inherit" } }, { children: title }))] }), isChecked || menu || modifier ? (_jsxs(Flex, Object.assign({ sx: { ml: 4 } }, { children: [isChecked && _jsx(Icon, { path: Icons.check, size: 14 }), menu && _jsx(Icon, { path: Icons.chevronRight, size: 14 }), modifier && (_jsx(Text, Object.assign({ as: "span", sx: {+ fontFamily: "body",+ fontSize: "menu",+ color: "fontTertiary",+ } }, { children: modifier })))] }))) : null] }), key) })));+}diff --git a/packages/editor/dist/es/components/menu/menuseparator.d.ts b/packages/editor/dist/es/components/menu/menuseparator.d.tsnew file mode 100644index 000000000..14ee7a7d6--- /dev/null+++ b/packages/editor/dist/es/components/menu/menuseparator.d.ts@@ -0,0 +1,2 @@+/// <reference types="react" />+export declare function MenuSeparator(): JSX.Element;diff --git a/packages/editor/dist/es/components/menu/menuseparator.js b/packages/editor/dist/es/components/menu/menuseparator.jsnew file mode 100644index 000000000..8e610c345--- /dev/null+++ b/packages/editor/dist/es/components/menu/menuseparator.js@@ -0,0 +1,11 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { Box } from "rebass";+export function MenuSeparator() {+ return (_jsx(Box, { as: "li", sx: {+ width: "95%",+ height: "0.5px",+ bg: "border",+ my: 2,+ alignSelf: "center",+ } }));+}diff --git a/packages/editor/dist/es/components/menu/types.d.ts b/packages/editor/dist/es/components/menu/types.d.tsnew file mode 100644index 000000000..82ecdffe2--- /dev/null+++ b/packages/editor/dist/es/components/menu/types.d.ts@@ -0,0 +1,30 @@+/// <reference types="react" />+import { IconNames } from "../../toolbar/icons";+declare type MenuItemComponentProps = {+ onClick?: (e?: any) => void;+};+export declare type MenuItemTypes = "button" | "separator" | "popup";+export declare type BaseMenuItem<TType extends MenuItemTypes> = {+ type: TType;+ key: string;+ isHidden?: boolean;+};+export declare type MenuSeperator = BaseMenuItem<"separator">;+export declare type MenuPopup = BaseMenuItem<"popup"> & {+ component: (props: MenuItemComponentProps) => JSX.Element;+};+export declare type MenuButton = BaseMenuItem<"button"> & {+ onClick?: () => void;+ title: string;+ icon?: IconNames;+ tooltip?: string;+ isDisabled?: boolean;+ isChecked?: boolean;+ modifier?: string;+ menu?: {+ title: string;+ items: MenuItem[];+ };+};+export declare type MenuItem = MenuButton | MenuSeperator | MenuPopup;+export {};diff --git a/packages/editor/dist/es/components/menu/types.js b/packages/editor/dist/es/components/menu/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/components/menu/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/components/menu/usefocus.d.ts b/packages/editor/dist/es/components/menu/usefocus.d.tsnew file mode 100644index 000000000..36b4ee2ca--- /dev/null+++ b/packages/editor/dist/es/components/menu/usefocus.d.ts@@ -0,0 +1,8 @@+/// <reference types="react" />+import { MenuItem } from "./types";+export declare function useFocus(items: MenuItem[], onAction: (event: KeyboardEvent) => void, onClose: (event: KeyboardEvent) => void): {+ focusIndex: number;+ setFocusIndex: import("react").Dispatch<import("react").SetStateAction<number>>;+ isSubmenuOpen: boolean;+ setIsSubmenuOpen: import("react").Dispatch<import("react").SetStateAction<boolean>>;+};diff --git a/packages/editor/dist/es/components/menu/usefocus.js b/packages/editor/dist/es/components/menu/usefocus.jsnew file mode 100644index 000000000..a5362f4e5--- /dev/null+++ b/packages/editor/dist/es/components/menu/usefocus.js@@ -0,0 +1,82 @@+import { useCallback, useEffect, useState } from "react";+export function useFocus(items, onAction, onClose) {+ const [focusIndex, setFocusIndex] = useState(-1);+ const [isSubmenuOpen, setIsSubmenuOpen] = useState(false);+ const moveItemIntoView = useCallback((index) => {+ const item = items[index];+ if (!item)+ return;+ const element = document.getElementById(item.key);+ if (!element)+ return;+ element.scrollIntoView({+ behavior: "auto",+ });+ }, [items]);+ const onKeyDown = useCallback((e) => {+ const as = (i) => items[i];+ const isSeperator = (i) => {+ var _a, _b;+ return items &&+ (((_a = items[i]) === null || _a === void 0 ? void 0 : _a.type) === "separator" || ((_b = as(i)) === null || _b === void 0 ? void 0 : _b.isDisabled));+ };+ const moveDown = (i) => (i < items.length - 1 ? ++i : 0);+ const moveUp = (i) => (i > 0 ? --i : items.length - 1);+ const hasSubmenu = (i) => items && as(i).menu;+ const openSubmenu = (index) => {+ if (!hasSubmenu(index))+ return;+ setIsSubmenuOpen(true);+ };+ const closeSubmenu = (index) => {+ if (!hasSubmenu(index))+ return;+ setIsSubmenuOpen(false);+ };+ setFocusIndex((i) => {+ let nextIndex = i;+ switch (e.key) {+ case "ArrowUp":+ if (isSubmenuOpen)+ break;+ nextIndex = moveUp(i);+ while (isSeperator(nextIndex)) {+ nextIndex = moveUp(nextIndex);+ }+ break;+ case "ArrowDown":+ if (isSubmenuOpen)+ break;+ nextIndex = moveDown(i);+ while (isSeperator(nextIndex)) {+ nextIndex = moveDown(nextIndex);+ }+ break;+ case "ArrowRight":+ openSubmenu(i);+ break;+ case "ArrowLeft":+ closeSubmenu(i);+ break;+ case "Enter":+ onAction && onAction(e);+ break;+ case "Escape":+ onClose && onClose(e);+ break;+ default:+ break;+ }+ if (nextIndex !== i)+ moveItemIntoView(nextIndex);+ return nextIndex;+ });+ }, [items, isSubmenuOpen, moveItemIntoView, onAction]);+ useEffect(() => {+ window.addEventListener("keydown", onKeyDown);+ return () => {+ window.removeEventListener("keydown", onKeyDown);+ };+ }, [onKeyDown]);+ return { focusIndex, setFocusIndex, isSubmenuOpen, setIsSubmenuOpen };+}diff --git a/packages/editor/dist/es/components/popuppresenter/index.d.ts b/packages/editor/dist/es/components/popuppresenter/index.d.tsnew file mode 100644index 000000000..14ae76e5d--- /dev/null+++ b/packages/editor/dist/es/components/popuppresenter/index.d.ts@@ -0,0 +1,30 @@+import { PropsWithChildren } from "react";+import { PositionOptions } from "../../utils/position";+import { Theme } from "@notesnook/theme";+import React from "react";+import { ResponsivePresenterProps } from "../responsive";+export declare type PopupPresenterProps = {+ isOpen: boolean;+ onClose: () => void;+ position: PositionOptions;+ blocking?: boolean;+ focusOnRender?: boolean;+ movable?: boolean;+};+export declare function PopupPresenter(props: PropsWithChildren<PopupPresenterProps>): JSX.Element | null;+export declare type PopupWrapperProps = {+ id: string;+ group: string;+ position: PositionOptions;+ isOpen: boolean;+ onClosed?: () => void;+ renderPopup: (closePopup: () => void) => React.ReactNode;+ autoCloseOnUnmount?: boolean;+} & Partial<Omit<PopupPresenterProps, "onClose">>;+export declare function PopupWrapper(props: PopupWrapperProps): null;+declare type ShowPopupOptions = {+ theme: Theme;+ popup: (closePopup: () => void) => React.ReactNode;+} & Partial<ResponsivePresenterProps>;+export declare function showPopup(options: ShowPopupOptions): () => void;+export {};diff --git a/packages/editor/dist/es/components/popuppresenter/index.js b/packages/editor/dist/es/components/popuppresenter/index.jsnew file mode 100644index 000000000..ac8b78304--- /dev/null+++ b/packages/editor/dist/es/components/popuppresenter/index.js@@ -0,0 +1,218 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import { useCallback, useRef, useEffect, } from "react";+import { Box } from "rebass";+import { getPosition } from "../../utils/position";+import Modal from "react-modal";+import ReactDOM from "react-dom";+import { ThemeProvider } from "emotion-theming";+import { getPopupContainer, getToolbarElement } from "../../toolbar/utils/dom";+import { useIsMobile, useToolbarStore, } from "../../toolbar/stores/toolbar-store";+import { EditorContext, usePopupRenderer, } from "./popuprenderer";+import { ResponsivePresenter } from "../responsive";+function _PopupPresenter(props) {+ const { isOpen, position, onClose, blocking = true, focusOnRender = true, children, } = props;+ const isMobile = useIsMobile();+ const contentRef = useRef();+ const observerRef = useRef();+ const repositionPopup = useCallback(() => {+ if (!contentRef.current || !position)+ return;+ const popup = contentRef.current;+ const popupPosition = getPosition(popup, position);+ popup.style.top = popupPosition.top + "px";+ popup.style.left = popupPosition.left + "px";+ }, [position]);+ useEffect(() => {+ repositionPopup();+ }, [position]);+ useEffect(() => {+ function onWindowResize() {+ repositionPopup();+ }+ window.addEventListener("resize", onWindowResize);+ return () => {+ window.removeEventListener("resize", onWindowResize);+ };+ }, []);+ const attachMoveHandlers = useCallback(() => {+ if (!contentRef.current || !isOpen)+ return;+ const movableBar = contentRef.current.querySelector(".movable");+ if (!movableBar)+ return;+ const popup = contentRef.current;+ var offset = { x: 0, y: 0 };+ function mouseDown(e) {+ offset.x = e.clientX - popup.offsetLeft;+ offset.y = e.clientY - popup.offsetTop;+ window.addEventListener("mousemove", mouseMove);+ }+ function mouseMove(e) {+ if (!e.buttons)+ mouseUp();+ var top = e.clientY - offset.y;+ var left = e.clientX - offset.x;+ requestAnimationFrame(() => {+ popup.style.top = top + "px";+ popup.style.left = left + "px";+ });+ }+ function mouseUp() {+ window.removeEventListener("mousemove", mouseMove);+ }+ movableBar.addEventListener("mousedown", mouseDown);+ window.addEventListener("mouseup", mouseUp);+ }, [isOpen]);+ const handleResize = useCallback(() => {+ const popup = contentRef.current;+ if (!popup)+ return;+ let oldHeight = popup.offsetHeight;+ observerRef.current = new ResizeObserver((e) => {+ if (isMobile) {+ repositionPopup();+ }+ else {+ const { height, y } = popup.getBoundingClientRect();+ const delta = height - oldHeight;+ if (delta > 0) {+ // means the new size is bigger so we need to adjust the position+ // if required. We only do this in case the newly resized popup+ // is going out of the window.+ const windowHeight = document.body.clientHeight - 20;+ if (y + height > windowHeight) {+ popup.style.top = windowHeight - height + "px";+ }+ }+ oldHeight = height;+ }+ });+ observerRef.current.observe(popup, { box: "border-box" });+ }, [isMobile]);+ return (_jsx(Modal, Object.assign({ contentRef: (ref) => (contentRef.current = ref), className: "popup-presenter", role: "menu", isOpen: isOpen, appElement: document.body, shouldCloseOnEsc: true, shouldReturnFocusAfterClose: true, shouldCloseOnOverlayClick: true, shouldFocusAfterRender: focusOnRender, ariaHideApp: blocking, preventScroll: blocking, onRequestClose: onClose, portalClassName: "popup-presenter-portal", onAfterOpen: (obj) => {+ if (!obj || !position)+ return;+ repositionPopup();+ handleResize();+ attachMoveHandlers();+ }, onAfterClose: () => { var _a; return (_a = observerRef.current) === null || _a === void 0 ? void 0 : _a.disconnect(); }, overlayElement: (props, contentEl) => {+ return (_jsx(Box, Object.assign({}, props, {+ //@ts-ignore+ style: Object.assign(Object.assign({}, props.style), { position: !blocking ? "initial" : "fixed", zIndex: 1000, backgroundColor: !blocking ? "transparent" : "unset" }) }, { children: contentEl })));+ }, contentElement: (props, children) => (_jsx(Box, Object.assign({}, props, { style: {},+ // TODO onMouseDown={(e) => {+ // console.log(e);+ // }}+ sx: {+ top: 0,+ left: 0,+ right: 0,+ bottom: 0,+ display: "flex",+ width: "fit-content",+ height: "fit-content",+ position: "fixed",+ backgroundColor: undefined,+ padding: 0,+ zIndex: 0,+ outline: 0,+ isolation: "isolate",+ } }, { children: children }))), style: {+ content: {},+ overlay: {+ zIndex: 999,+ background: "transparent",+ },+ } }, { children: children })));+}+export function PopupPresenter(props) {+ // HACK: we don't want to render the popup presenter for no reason+ // including it's effects etc. so we just wrap it and return null+ // if the popup is closed.+ if (!props.isOpen)+ return null;+ return _jsx(_PopupPresenter, Object.assign({}, props));+}+export function PopupWrapper(props) {+ let { id, group, position, renderPopup, isOpen, onClosed, autoCloseOnUnmount } = props, presenterProps = __rest(props, ["id", "group", "position", "renderPopup", "isOpen", "onClosed", "autoCloseOnUnmount"]);+ const PopupRenderer = usePopupRenderer();+ const isPopupOpen = useToolbarStore((store) => !!store.openedPopups[id]);+ const openPopup = useToolbarStore((store) => store.openPopup);+ const closePopup = useToolbarStore((store) => store.closePopup);+ const closePopupGroup = useToolbarStore((store) => store.closePopupGroup);+ const isBottom = useToolbarStore((store) => store.toolbarLocation === "bottom");+ if (isBottom)+ group = "popup";+ useEffect(() => {+ if (isOpen)+ openPopup({ id, group });+ else+ closePopup(id);+ }, [isOpen, id, group, openPopup, closePopup]);+ useEffect(() => {+ if (!autoCloseOnUnmount)+ return;+ return () => {+ PopupRenderer === null || PopupRenderer === void 0 ? void 0 : PopupRenderer.closePopup(id);+ };+ }, [autoCloseOnUnmount, id]);+ useEffect(() => {+ if (!isPopupOpen)+ onClosed === null || onClosed === void 0 ? void 0 : onClosed();+ }, [isPopupOpen]);+ useEffect(() => {+ if (isPopupOpen) {+ closePopupGroup(group, [id]);+ }+ }, [onClosed, isPopupOpen, closePopupGroup, id, group]);+ useEffect(() => {+ if (!isOpen)+ closePopup(id);+ }, [isOpen, id, group, closePopup]);+ useEffect(() => {+ if (PopupRenderer && isPopupOpen) {+ PopupRenderer.openPopup(id, function Popup({ id }) {+ const isPopupOpen = useToolbarStore((store) => !!store.openedPopups[id]);+ useEffect(() => {+ if (!isPopupOpen) {+ PopupRenderer.closePopup(id);+ }+ }, [isPopupOpen]);+ return (_jsx(PopupPresenter, Object.assign({ isOpen: isPopupOpen, onClose: () => closePopup(id), position: position, blocking: true, focusOnRender: true }, presenterProps, { children: _jsx(Box, Object.assign({ sx: {+ boxShadow: "menu",+ borderRadius: "default",+ overflow: "hidden",+ // width,+ } }, { children: _jsx(EditorContext.Consumer, { children: () => {+ return renderPopup(() => PopupRenderer.closePopup(id));+ } }) })) }), id));+ });+ }+ }, [PopupRenderer, isPopupOpen]);+ return null;+}+export function showPopup(options) {+ const { theme, popup } = options, props = __rest(options, ["theme", "popup"]);+ function hide() {+ ReactDOM.unmountComponentAtNode(getPopupContainer());+ }+ ReactDOM.render(_jsx(ThemeProvider, Object.assign({ theme: theme }, { children: _jsx(ResponsivePresenter, Object.assign({ isOpen: true, onClose: hide, position: {+ target: getToolbarElement(),+ isTargetAbsolute: true,+ location: "below",+ align: "end",+ yOffset: 10,+ }, blocking: true, focusOnRender: true }, props, { children: popup(hide) })) })), getPopupContainer());+ return hide;+}diff --git a/packages/editor/dist/es/components/popuppresenter/popuprenderer.d.ts b/packages/editor/dist/es/components/popuppresenter/popuprenderer.d.tsnew file mode 100644index 000000000..6a837ff5f--- /dev/null+++ b/packages/editor/dist/es/components/popuppresenter/popuprenderer.d.ts@@ -0,0 +1,26 @@+import React, { PropsWithChildren } from "react";+import { Editor } from "@tiptap/core";+export declare const PopupRendererContext: React.Context<PopupRenderer | null>;+export declare const EditorContext: React.Context<Editor | null>;+export declare type PopupRendererProps = PropsWithChildren<{+ editor: Editor;+}>;+declare type PopupComponent = React.FunctionComponent<{+ id: string;+}>;+declare type PopupRendererState = {+ popups: {+ id: string;+ popup: PopupComponent;+ }[];+};+export declare class PopupRenderer extends React.Component<PopupRendererProps, PopupRendererState, PopupRendererState> {+ popupContainer: HTMLDivElement | null;+ state: PopupRendererState;+ openPopup: (id: string, popup: PopupComponent) => void;+ closePopup: (id: string) => void;+ render(): React.ReactNode;+}+export declare function usePopupRenderer(): PopupRenderer | null;+export declare function useEditorContext(): Editor;+export {};diff --git a/packages/editor/dist/es/components/popuppresenter/popuprenderer.js b/packages/editor/dist/es/components/popuppresenter/popuprenderer.jsnew file mode 100644index 000000000..fc2126d58--- /dev/null+++ b/packages/editor/dist/es/components/popuppresenter/popuprenderer.js@@ -0,0 +1,45 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import React, { useContext } from "react";+export const PopupRendererContext = React.createContext(null);+export const EditorContext = React.createContext(null);+export class PopupRenderer extends React.Component {+ constructor() {+ super(...arguments);+ this.popupContainer = null;+ this.state = {+ popups: [],+ };+ this.openPopup = (id, popup) => {+ if (!popup)+ return;+ this.setState((prev) => {+ return {+ popups: [...prev.popups, { id, popup }],+ };+ });+ };+ this.closePopup = (id) => {+ this.setState((prev) => {+ const index = prev.popups.findIndex((p) => p.id === id);+ if (index <= -1)+ return prev;+ const clone = prev.popups.slice();+ clone.splice(index, 1);+ return {+ popups: clone,+ };+ });+ };+ }+ render() {+ return (_jsxs(PopupRendererContext.Provider, Object.assign({ value: this }, { children: [this.props.children, _jsxs(EditorContext.Provider, Object.assign({ value: this.props.editor }, { children: [this.state.popups.map(({ id, popup: Popup }) => {+ return _jsx(Popup, { id: id }, id);+ }), _jsx("div", { id: "popup-container" })] }))] })));+ }+}+export function usePopupRenderer() {+ return useContext(PopupRendererContext);+}+export function useEditorContext() {+ return useContext(EditorContext);+}diff --git a/packages/editor/dist/es/components/responsive/index.d.ts b/packages/editor/dist/es/components/responsive/index.d.tsnew file mode 100644index 000000000..f734f5329--- /dev/null+++ b/packages/editor/dist/es/components/responsive/index.d.ts@@ -0,0 +1,17 @@+import { PropsWithChildren } from "react";+import { ActionSheetPresenterProps } from "../action-sheet";+import { MenuPresenterProps } from "../menu";+declare type ResponsiveContainerProps = {+ mobile?: JSX.Element;+ desktop?: JSX.Element;+};+export declare function ResponsiveContainer(props: ResponsiveContainerProps): JSX.Element | null;+export declare function DesktopOnly(props: PropsWithChildren<{}>): JSX.Element;+export declare function MobileOnly(props: PropsWithChildren<{}>): JSX.Element;+export declare type PopupType = "sheet" | "menu" | "none";+export declare type ResponsivePresenterProps = MenuPresenterProps & ActionSheetPresenterProps & {+ mobile?: PopupType;+ desktop?: PopupType;+};+export declare function ResponsivePresenter(props: PropsWithChildren<ResponsivePresenterProps>): JSX.Element | null;+export {};diff --git a/packages/editor/dist/es/components/responsive/index.js b/packages/editor/dist/es/components/responsive/index.jsnew file mode 100644index 000000000..b8a4be0c8--- /dev/null+++ b/packages/editor/dist/es/components/responsive/index.js@@ -0,0 +1,38 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";+import { useIsMobile, } from "../../toolbar/stores/toolbar-store";+import { ActionSheetPresenter, } from "../action-sheet";+import { MenuPresenter } from "../menu";+export function ResponsiveContainer(props) {+ const isMobile = useIsMobile();+ if (isMobile)+ return props.mobile || null;+ else+ return props.desktop || null;+}+export function DesktopOnly(props) {+ return _jsx(ResponsiveContainer, { desktop: _jsx(_Fragment, { children: props.children }) });+}+export function MobileOnly(props) {+ return _jsx(ResponsiveContainer, { mobile: _jsx(_Fragment, { children: props.children }) });+}+export function ResponsivePresenter(props) {+ const { mobile = "menu", desktop = "menu" } = props, restProps = __rest(props, ["mobile", "desktop"]);+ const isMobile = useIsMobile();+ if (isMobile && mobile === "sheet")+ return _jsx(ActionSheetPresenter, Object.assign({}, restProps));+ else if (mobile === "menu" || desktop === "menu")+ return _jsx(MenuPresenter, Object.assign({}, restProps));+ else+ return props.isOpen ? _jsx(_Fragment, { children: props.children }) : null;+}diff --git a/packages/editor/dist/es/components/tabs/index.d.ts b/packages/editor/dist/es/components/tabs/index.d.tsnew file mode 100644index 000000000..28e7a9dac--- /dev/null+++ b/packages/editor/dist/es/components/tabs/index.d.ts@@ -0,0 +1,12 @@+import React, { PropsWithChildren } from "react";+import { FlexProps } from "rebass";+export declare type TabProps = {+ title: string | React.ReactElement;+};+export declare function Tab(props: PropsWithChildren<TabProps>): JSX.Element;+export declare type TabsProps = {+ activeIndex: number;+ containerProps?: FlexProps;+ onTabChanged?: (index: number) => void;+};+export declare function Tabs(props: PropsWithChildren<TabsProps>): JSX.Element;diff --git a/packages/editor/dist/es/components/tabs/index.js b/packages/editor/dist/es/components/tabs/index.jsnew file mode 100644index 000000000..a0b1262a3--- /dev/null+++ b/packages/editor/dist/es/components/tabs/index.js@@ -0,0 +1,36 @@+import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import React, { Children, useMemo, useState } from "react";+import { Button, Flex } from "rebass";+export function Tab(props) {+ return _jsx(_Fragment, { children: props.children });+}+export function Tabs(props) {+ const { activeIndex, children, containerProps, onTabChanged } = props;+ const [activeTab, setActiveTab] = useState(activeIndex || 0);+ const tabs = useMemo(() => Children.map(children, (child) => {+ if (React.isValidElement(child))+ return { title: child.props.title, component: child };+ }), [children]);+ return (_jsxs(Flex, Object.assign({ sx: { flexDirection: "column" } }, { children: [_jsx(Flex, Object.assign({ sx: {+ mb: 1,+ } }, { children: tabs === null || tabs === void 0 ? void 0 : tabs.map((tab, index) => (_jsx(Button, Object.assign({ sx: {+ flex: 1,+ p: 0,+ py: 1,+ borderRadius: 0,+ borderTopLeftRadius: "default",+ borderTopRightRadius: "default",+ bg: activeTab === index ? "bgSecondary" : "transparent",+ fontWeight: activeTab === index ? "bold" : "normal",+ color: "text",+ ":last-of-type": { mr: 0 },+ borderBottom: "2px solid",+ borderBottomColor: activeTab === index ? "primary" : "transparent",+ ":hover": {+ bg: "hover",+ },+ }, onClick: () => {+ setActiveTab(index);+ onTabChanged === null || onTabChanged === void 0 ? void 0 : onTabChanged(index);+ } }, { children: tab.title }), index.toString()))) })), _jsx(Flex, Object.assign({}, containerProps, { children: tabs && tabs[activeTab].component }))] })));+}diff --git a/packages/editor/dist/es/extensions.d.ts b/packages/editor/dist/es/extensions.d.tsnew file mode 100644index 000000000..04757fdce--- /dev/null+++ b/packages/editor/dist/es/extensions.d.ts@@ -0,0 +1,30 @@+import "@tiptap/extension-character-count";+import "@tiptap/extension-placeholder";+import "@tiptap/extension-underline";+import "@tiptap/starter-kit";+import "@tiptap/extension-text-align";+import "@tiptap/extension-subscript";+import "@tiptap/extension-superscript";+import "./extensions/font-size";+import "./extensions/text-direction";+import "@tiptap/extension-text-style";+import "@tiptap/extension-font-family";+import "./extensions/bullet-list";+import "./extensions/ordered-list";+import "@tiptap/extension-highlight";+import "@tiptap/extension-color";+import "@tiptap/extension-table-row";+import "./extensions/table-cell";+import "@tiptap/extension-table-header";+import "./extensions/image";+import "./extensions/attachment";+import "./extensions/task-list";+import "./extensions/task-item";+import "./extensions/drop-cursor";+import "./extensions/search-replace";+import "./extensions/embed";+import "./extensions/code-block";+import "./extensions/list-item";+import "./extensions/outline-list";+import "./extensions/outline-list-item";+import "./extensions/table";diff --git a/packages/editor/dist/es/extensions.js b/packages/editor/dist/es/extensions.jsnew file mode 100644index 000000000..04757fdce--- /dev/null+++ b/packages/editor/dist/es/extensions.js@@ -0,0 +1,30 @@+import "@tiptap/extension-character-count";+import "@tiptap/extension-placeholder";+import "@tiptap/extension-underline";+import "@tiptap/starter-kit";+import "@tiptap/extension-text-align";+import "@tiptap/extension-subscript";+import "@tiptap/extension-superscript";+import "./extensions/font-size";+import "./extensions/text-direction";+import "@tiptap/extension-text-style";+import "@tiptap/extension-font-family";+import "./extensions/bullet-list";+import "./extensions/ordered-list";+import "@tiptap/extension-highlight";+import "@tiptap/extension-color";+import "@tiptap/extension-table-row";+import "./extensions/table-cell";+import "@tiptap/extension-table-header";+import "./extensions/image";+import "./extensions/attachment";+import "./extensions/task-list";+import "./extensions/task-item";+import "./extensions/drop-cursor";+import "./extensions/search-replace";+import "./extensions/embed";+import "./extensions/code-block";+import "./extensions/list-item";+import "./extensions/outline-list";+import "./extensions/outline-list-item";+import "./extensions/table";diff --git a/packages/editor/dist/es/extensions/attachment/attachment.d.ts b/packages/editor/dist/es/extensions/attachment/attachment.d.tsnew file mode 100644index 000000000..cd34695f5--- /dev/null+++ b/packages/editor/dist/es/extensions/attachment/attachment.d.ts@@ -0,0 +1,33 @@+import { Node, Editor } from "@tiptap/core";+import { Attribute } from "@tiptap/core";+export declare type AttachmentType = "image" | "file" | "camera";+export interface AttachmentOptions {+ HTMLAttributes: Record<string, any>;+ onDownloadAttachment: (editor: Editor, attachment: Attachment) => boolean;+ onOpenAttachmentPicker: (editor: Editor, type: AttachmentType) => boolean;+}+export declare type AttachmentWithProgress = AttachmentProgress & Attachment;+export declare type Attachment = {+ hash: string;+ filename: string;+ type: string;+ size: number;+};+export declare type AttachmentProgress = {+ progress: number;+ type: "upload" | "download" | "encrypt";+ hash: string;+};+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ attachment: {+ openAttachmentPicker: (type: AttachmentType) => ReturnType;+ insertAttachment: (attachment: Attachment) => ReturnType;+ removeAttachment: () => ReturnType;+ downloadAttachment: (attachment: Attachment) => ReturnType;+ setAttachmentProgress: (progress: AttachmentProgress) => ReturnType;+ };+ }+}+export declare const AttachmentNode: Node<AttachmentOptions, any>;+export declare function getDataAttribute(name: string, def?: any | null): Partial<Attribute>;diff --git a/packages/editor/dist/es/extensions/attachment/attachment.js b/packages/editor/dist/es/extensions/attachment/attachment.jsnew file mode 100644index 000000000..8d681838e--- /dev/null+++ b/packages/editor/dist/es/extensions/attachment/attachment.js@@ -0,0 +1,109 @@+import { Node, mergeAttributes, findChildren } from "@tiptap/core";+import { createSelectionBasedNodeView } from "../react";+import { AttachmentComponent } from "./component";+export const AttachmentNode = Node.create({+ name: "attachment",+ content: "inline*",+ marks: "",+ inline: true,+ atom: true,+ addOptions() {+ return {+ HTMLAttributes: {},+ onDownloadAttachment: () => false,+ onOpenAttachmentPicker: () => false,+ };+ },+ group() {+ return "inline";+ },+ draggable: true,+ addAttributes() {+ return {+ progress: {+ default: 0,+ rendered: false,+ },+ hash: getDataAttribute("hash"),+ filename: getDataAttribute("filename"),+ type: getDataAttribute("mime"),+ size: getDataAttribute("size"),+ };+ },+ parseHTML() {+ return [+ {+ tag: "span[data-hash]",+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "span",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),+ ];+ },+ addNodeView() {+ return createSelectionBasedNodeView(AttachmentComponent, {+ shouldUpdate: ({ attrs: prev }, { attrs: next }) => {+ return prev.progress !== next.progress;+ },+ });+ },+ addCommands() {+ return {+ insertAttachment: (attachment) => ({ commands }) => {+ return commands.insertContent({+ type: this.name,+ attrs: attachment,+ });+ },+ removeAttachment: () => ({ commands }) => commands.deleteNode(this.name),+ downloadAttachment: (attachment) => ({ editor }) => {+ return this.options.onDownloadAttachment(editor, attachment);+ },+ openAttachmentPicker: (type) => ({ editor }) => {+ return this.options.onOpenAttachmentPicker(editor, type);+ },+ setAttachmentProgress: (options) => ({ state, tr, dispatch }) => {+ const { hash, progress, type } = options;+ const attachments = findChildren(state.doc, (node) => (node.type.name === this.name || node.type.name === "image") &&+ node.attrs.hash === hash);+ for (const attachment of attachments) {+ tr.setNodeMarkup(attachment.pos, attachment.node.type, Object.assign(Object.assign({}, attachment.node.attrs), { progress: progress === 100 ? null : progress }));+ }+ tr.setMeta("preventUpdate", true);+ tr.setMeta("addToHistory", false);+ if (dispatch)+ dispatch(tr);+ return true;+ },+ };+ },+ // addInputRules() {+ // return [+ // nodeInputRule({+ // find: inputRegex,+ // type: this.type,+ // getAttributes: (match) => {+ // const [, , alt, src, title] = match;+ // return { src, alt, title };+ // },+ // }),+ // ];+ // },+});+export function getDataAttribute(name, def) {+ return {+ default: def,+ parseHTML: (element) => element.dataset[name],+ renderHTML: (attributes) => {+ if (!attributes[name]) {+ return {};+ }+ return {+ [`data-${name}`]: attributes[name],+ };+ },+ };+}diff --git a/packages/editor/dist/es/extensions/attachment/component.d.ts b/packages/editor/dist/es/extensions/attachment/component.d.tsnew file mode 100644index 000000000..ea57c55f9--- /dev/null+++ b/packages/editor/dist/es/extensions/attachment/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { AttachmentWithProgress } from "./attachment";+import { SelectionBasedReactNodeViewProps } from "../react";+export declare function AttachmentComponent(props: SelectionBasedReactNodeViewProps<AttachmentWithProgress>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/attachment/component.js b/packages/editor/dist/es/extensions/attachment/component.jsnew file mode 100644index 000000000..11590223b--- /dev/null+++ b/packages/editor/dist/es/extensions/attachment/component.js@@ -0,0 +1,56 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { Box, Text } from "rebass";+import { useRef } from "react";+// import { MenuPresenter } from "../../components/menu/menu";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { ToolbarGroup } from "../../toolbar/components/toolbar-group";+import { DesktopOnly } from "../../components/responsive";+export function AttachmentComponent(props) {+ const { editor, node, selected } = props;+ const { hash, filename, size, progress } = node.attrs;+ const elementRef = useRef();+ return (_jsx(_Fragment, { children: _jsxs(Box, Object.assign({ ref: elementRef, as: "span", contentEditable: false, variant: "body", sx: {+ display: "inline-flex",+ position: "relative",+ justifyContent: "center",+ userSelect: "none",+ alignItems: "center",+ backgroundColor: "bgSecondary",+ px: 1,+ borderRadius: "default",+ border: "1px solid var(--border)",+ cursor: "pointer",+ maxWidth: 250,+ borderColor: selected ? "primary" : "border",+ ":hover": {+ bg: "hover",+ },+ }, title: filename }, { children: [_jsx(Icon, { path: Icons.attachment, size: 14 }), _jsx(Text, Object.assign({ as: "span", sx: {+ ml: "small",+ fontSize: "body",+ whiteSpace: "nowrap",+ textOverflow: "ellipsis",+ overflow: "hidden",+ } }, { children: filename })), _jsx(Text, Object.assign({ as: "span", sx: {+ ml: 1,+ fontSize: "0.65rem",+ color: "fontTertiary",+ flexShrink: 0,+ } }, { children: progress ? `${progress}%` : formatBytes(size) })), _jsx(DesktopOnly, { children: selected && (_jsx(ToolbarGroup, { editor: editor, tools: ["removeAttachment", "downloadAttachment"], sx: {+ boxShadow: "menu",+ borderRadius: "default",+ bg: "background",+ position: "absolute",+ top: -35,+ } })) })] })) }));+}+function formatBytes(bytes, decimals = 1) {+ if (bytes === 0)+ return "0B";+ const k = 1024;+ const dm = decimals < 0 ? 0 : decimals;+ const sizes = ["B", "K", "M", "G", "T", "P", "E", "Z", "Y"];+ const i = Math.floor(Math.log(bytes) / Math.log(k));+ return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + sizes[i];+}diff --git a/packages/editor/dist/es/extensions/attachment/index.d.ts b/packages/editor/dist/es/extensions/attachment/index.d.tsnew file mode 100644index 000000000..9f9f38860--- /dev/null+++ b/packages/editor/dist/es/extensions/attachment/index.d.ts@@ -0,0 +1 @@+export * from "./attachment";diff --git a/packages/editor/dist/es/extensions/attachment/index.js b/packages/editor/dist/es/extensions/attachment/index.jsnew file mode 100644index 000000000..9f9f38860--- /dev/null+++ b/packages/editor/dist/es/extensions/attachment/index.js@@ -0,0 +1 @@+export * from "./attachment";diff --git a/packages/editor/dist/es/extensions/bulletlist/bulletlist.d.ts b/packages/editor/dist/es/extensions/bulletlist/bulletlist.d.tsnew file mode 100644index 000000000..803ad33bd--- /dev/null+++ b/packages/editor/dist/es/extensions/bulletlist/bulletlist.d.ts@@ -0,0 +1 @@+export declare const BulletList: import("@tiptap/core").Node<import("@tiptap/extension-bullet-list").BulletListOptions, any>;diff --git a/packages/editor/dist/es/extensions/bulletlist/bulletlist.js b/packages/editor/dist/es/extensions/bulletlist/bulletlist.jsnew file mode 100644index 000000000..6c4c889b0--- /dev/null+++ b/packages/editor/dist/es/extensions/bulletlist/bulletlist.js@@ -0,0 +1,19 @@+import TiptapBulletList from "@tiptap/extension-bullet-list";+export const BulletList = TiptapBulletList.extend({+ addAttributes() {+ return {+ listType: {+ default: null,+ parseHTML: (element) => element.style.listStyleType,+ renderHTML: (attributes) => {+ if (!attributes.listType) {+ return {};+ }+ return {+ style: `list-style-type: ${attributes.listType}`,+ };+ },+ },+ };+ },+});diff --git a/packages/editor/dist/es/extensions/bulletlist/index.d.ts b/packages/editor/dist/es/extensions/bulletlist/index.d.tsnew file mode 100644index 000000000..c732326f2--- /dev/null+++ b/packages/editor/dist/es/extensions/bulletlist/index.d.ts@@ -0,0 +1,3 @@+import { BulletList } from "./bullet-list";+export * from "./bullet-list";+export default BulletList;diff --git a/packages/editor/dist/es/extensions/bulletlist/index.js b/packages/editor/dist/es/extensions/bulletlist/index.jsnew file mode 100644index 000000000..c732326f2--- /dev/null+++ b/packages/editor/dist/es/extensions/bulletlist/index.js@@ -0,0 +1,3 @@+import { BulletList } from "./bullet-list";+export * from "./bullet-list";+export default BulletList;diff --git a/packages/editor/dist/es/extensions/codeblock/codeblock.d.ts b/packages/editor/dist/es/extensions/codeblock/codeblock.d.tsnew file mode 100644index 000000000..19f8d3e16--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/codeblock.d.ts@@ -0,0 +1,83 @@+import { Node } from "@tiptap/core";+import { Selection } from "prosemirror-state";+import { Node as ProsemirrorNode } from "prosemirror-model";+interface Indent {+ type: "tab" | "space";+ amount: number;+}+export declare type CodeBlockAttributes = {+ indentType: Indent["type"];+ indentLength: number;+ language: string;+ lines: CodeLine[];+ caretPosition?: CaretPosition;+};+export interface CodeBlockOptions {+ /**+ * Adds a prefix to language classes that are applied to code tags.+ * Defaults to `'language-'`.+ */+ languageClassPrefix: string;+ /**+ * Define whether the node should be exited on triple enter.+ * Defaults to `true`.+ */+ exitOnTripleEnter: boolean;+ /**+ * Define whether the node should be exited on arrow down if there is no node after it.+ * Defaults to `true`.+ */+ exitOnArrowDown: boolean;+ /**+ * Define whether the node should be exited on arrow up if there is no node before it.+ * Defaults to `true`.+ */+ exitOnArrowUp: boolean;+ /**+ * Custom HTML attributes that should be added to the rendered HTML tag.+ */+ HTMLAttributes: Record<string, any>;+}+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ codeblock: {+ /**+ * Set a code block+ */+ setCodeBlock: (attributes?: {+ language: string;+ }) => ReturnType;+ /**+ * Toggle a code block+ */+ toggleCodeBlock: (attributes?: {+ language: string;+ }) => ReturnType;+ /**+ * Change code block indentation options+ */+ changeCodeBlockIndentation: (options: Indent) => ReturnType;+ };+ }+}+export declare const backtickInputRegex: RegExp;+export declare const tildeInputRegex: RegExp;+export declare const CodeBlock: Node<CodeBlockOptions, any>;+export declare type CaretPosition = {+ column: number;+ line: number;+ selected?: number;+ total: number;+ from: number;+};+export declare function toCaretPosition(selection: Selection, lines?: CodeLine[]): CaretPosition | undefined;+export declare function getLines(node: ProsemirrorNode): CodeLine[];+declare type CodeLine = {+ index: number;+ from: number;+ to: number;+ length: number;+ text: (length?: number) => string;+};+export declare function toCodeLines(code: string, pos: number): CodeLine[];+export {};diff --git a/packages/editor/dist/es/extensions/codeblock/codeblock.js b/packages/editor/dist/es/extensions/codeblock/codeblock.jsnew file mode 100644index 000000000..4a1ceb3e8--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/codeblock.js@@ -0,0 +1,507 @@+import { findParentNodeClosestToPos } from "@tiptap/core";+import { Node, textblockTypeInputRule, mergeAttributes } from "@tiptap/core";+import { Plugin, PluginKey, TextSelection, } from "prosemirror-state";+import { CodeblockComponent } from "./component";+import { HighlighterPlugin } from "./highlighter";+import { createNodeView } from "../react";+import detectIndent from "detect-indent";+import redent from "redent";+import stripIndent from "strip-indent";+export const backtickInputRegex = /^```([a-z]+)?[\s\n]$/;+export const tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;+const ZERO_WIDTH_SPACE = "\u200b";+const NEWLINE = "\n";+export const CodeBlock = Node.create({+ name: "codeblock",+ addOptions() {+ return {+ languageClassPrefix: "language-",+ exitOnTripleEnter: true,+ exitOnArrowDown: true,+ exitOnArrowUp: true,+ HTMLAttributes: {},+ };+ },+ content: "text*",+ marks: "",+ group: "block",+ code: true,+ defining: true,+ addAttributes() {+ return {+ caretPosition: {+ default: undefined,+ rendered: false,+ },+ lines: {+ default: [],+ rendered: false,+ },+ indentType: {+ default: "space",+ parseHTML: (element) => {+ const indentType = element.dataset.indentType;+ return indentType;+ },+ renderHTML: (attributes) => {+ if (!attributes.indentType) {+ return {};+ }+ return {+ "data-indent-type": attributes.indentType,+ };+ },+ },+ indentLength: {+ default: 2,+ parseHTML: (element) => {+ const indentLength = element.dataset.indentLength;+ return indentLength;+ },+ renderHTML: (attributes) => {+ if (!attributes.indentLength) {+ return {};+ }+ return {+ "data-indent-length": attributes.indentLength,+ };+ },+ },+ language: {+ default: null,+ parseHTML: (element) => {+ var _a;+ const { languageClassPrefix } = this.options;+ const classNames = [+ ...(element.classList || []),+ ...(((_a = element === null || element === void 0 ? void 0 : element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || []),+ ];+ const languages = classNames+ .filter((className) => className.startsWith(languageClassPrefix))+ .map((className) => className.replace(languageClassPrefix, ""));+ const language = languages[0];+ if (!language) {+ return null;+ }+ return language;+ },+ renderHTML: (attributes) => {+ if (!attributes.language) {+ return {};+ }+ return {+ class: `language-${attributes.language}`,+ };+ },+ },+ };+ },+ parseHTML() {+ return [+ {+ tag: "pre",+ preserveWhitespace: "full",+ // contentElement: (node) => {+ // if (node instanceof HTMLElement) {+ // node.innerText = node.innerText.replaceAll("\n\u200b\n", "\n\n");+ // }+ // return node;+ // },+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "pre",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),+ ["code", {}, 0],+ ];+ },+ addCommands() {+ return {+ setCodeBlock: (attributes) => ({ commands }) => {+ return commands.setNode(this.name, attributes);+ },+ toggleCodeBlock: (attributes) => ({ commands }) => {+ console.log("TOGGLING!");+ return commands.toggleNode(this.name, "paragraph", attributes);+ },+ changeCodeBlockIndentation: (options) => ({ editor, tr, commands }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from } = selection;+ if ($from.parent.type !== this.type) {+ return false;+ }+ const { lines } = $from.parent.attrs;+ for (const line of lines) {+ const text = line.text();+ const whitespaceLength = text.length - text.trimStart().length;+ if (!whitespaceLength)+ continue;+ const indentLength = whitespaceLength;+ const indentToken = indent({+ type: options.type,+ amount: indentLength,+ });+ tr.insertText(indentToken, tr.mapping.map(line.from), tr.mapping.map(line.from + whitespaceLength));+ }+ commands.updateAttributes(this.type, {+ indentType: options.type,+ indentLength: options.amount,+ });+ return true;+ },+ };+ },+ addKeyboardShortcuts() {+ return {+ "Mod-Alt-c": () => this.editor.commands.toggleCodeBlock(),+ "Mod-a": ({ editor }) => {+ const { $anchor } = this.editor.state.selection;+ if ($anchor.parent.type.name !== this.name) {+ return false;+ }+ const codeblock = findParentNodeClosestToPos($anchor, (node) => node.type.name === this.type.name);+ if (!codeblock)+ return false;+ return editor.commands.setTextSelection({+ from: codeblock.pos,+ to: codeblock.pos + codeblock.node.nodeSize,+ });+ },+ // remove code block when at start of document or code block is empty+ Backspace: () => {+ const { empty, $anchor } = this.editor.state.selection;+ const isAtStart = $anchor.pos === 1;+ if (!empty || $anchor.parent.type.name !== this.name) {+ return false;+ }+ if (isAtStart || !$anchor.parent.textContent.length) {+ return this.editor.commands.deleteNode(this.type);+ }+ return false;+ },+ // exit node on triple enter+ Enter: ({ editor }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from, empty } = selection;+ if (!empty || $from.parent.type !== this.type) {+ return false;+ }+ const indentation = parseIndentation($from.parent);+ return ((this.options.exitOnTripleEnter &&+ exitOnTripleEnter(editor, $from)) ||+ indentOnEnter(editor, $from, indentation));+ },+ // exit node on arrow up+ ArrowUp: ({ editor }) => {+ if (!this.options.exitOnArrowUp) {+ return false;+ }+ const { state } = editor;+ const { selection } = state;+ const { $anchor, empty } = selection;+ if (!empty || $anchor.parent.type !== this.type) {+ return false;+ }+ const isAtStart = $anchor.pos === 1;+ if (!isAtStart) {+ return false;+ }+ return editor.commands.insertContentAt(0, "<p></p>");+ },+ // exit node on arrow down+ ArrowDown: ({ editor }) => {+ if (!this.options.exitOnArrowDown) {+ return false;+ }+ const { state } = editor;+ const { selection, doc } = state;+ const { $from, empty } = selection;+ if (!empty || $from.parent.type !== this.type) {+ return false;+ }+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;+ if (!isAtEnd) {+ return false;+ }+ const after = $from.after();+ if (after === undefined) {+ return false;+ }+ const nodeAfter = doc.nodeAt(after);+ if (nodeAfter) {+ editor.commands.setNodeSelection($from.before());+ return false;+ }+ return editor.commands.exitCode();+ },+ "Shift-Tab": ({ editor }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from } = selection;+ if ($from.parent.type !== this.type) {+ return false;+ }+ const indentation = parseIndentation($from.parent);+ const indentToken = indent(indentation);+ const { lines } = $from.parent.attrs;+ const selectedLines = getSelectedLines(lines, selection);+ return editor+ .chain()+ .command(({ tr }) => withSelection(tr, (tr) => {+ for (const line of selectedLines) {+ if (line.text(indentToken.length) !== indentToken)+ continue;+ tr.delete(tr.mapping.map(line.from), tr.mapping.map(line.from + indentation.amount));+ }+ }))+ .run();+ },+ Tab: ({ editor }) => {+ const { state } = editor;+ const { selection } = state;+ const { $from } = selection;+ if ($from.parent.type !== this.type) {+ return false;+ }+ const { lines } = $from.parent.attrs;+ const selectedLines = getSelectedLines(lines, selection);+ return editor+ .chain()+ .command(({ tr }) => withSelection(tr, (tr) => {+ const indentToken = indent(parseIndentation($from.parent));+ if (selectedLines.length === 1)+ return tr.insertText(indentToken, $from.pos);+ for (const line of selectedLines) {+ tr.insertText(indentToken, tr.mapping.map(line.from));+ }+ }))+ .run();+ },+ };+ },+ addInputRules() {+ return [+ textblockTypeInputRule({+ find: backtickInputRegex,+ type: this.type,+ getAttributes: (match) => ({+ language: match[1],+ }),+ }),+ textblockTypeInputRule({+ find: tildeInputRegex,+ type: this.type,+ getAttributes: (match) => ({+ language: match[1],+ }),+ }),+ ];+ },+ addProseMirrorPlugins() {+ return [+ // this plugin creates a code block for pasted content from VS Code+ // we can also detect the copied code language+ new Plugin({+ key: new PluginKey("codeBlockVSCodeHandler"),+ props: {+ handlePaste: (view, event) => {+ if (!event.clipboardData) {+ return false;+ }+ const text = event.clipboardData.getData("text/plain");+ const vscode = event.clipboardData.getData("vscode-editor-data");+ const vscodeData = vscode ? JSON.parse(vscode) : undefined;+ const language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;+ if (!text || !language) {+ return false;+ }+ const indent = fixIndentation(text, parseIndentation(view.state.selection.$from.parent));+ const { tr } = view.state;+ // create an empty code block if not already within one+ if (!this.editor.isActive(this.type.name)) {+ tr.replaceSelectionWith(this.type.create({+ language,+ indentType: indent.type,+ indentLength: indent.amount,+ }));+ }+ // // put cursor inside the newly created code block+ // tr.setSelection(+ // TextSelection.near(+ // tr.doc.resolve(Math.max(0, tr.selection.from - 2))+ // )+ // );+ // add text to code block+ // strip carriage return chars from text pasted as code+ // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd+ tr.insertText(indent.code.replace(/\r\n?/g, "\n"));+ // store meta information+ // this is useful for other plugins that depends on the paste event+ // like the paste rule plugin+ tr.setMeta("paste", true);+ view.dispatch(tr);+ return true;+ },+ },+ }),+ HighlighterPlugin({ name: this.name, defaultLanguage: "txt" }),+ ];+ },+ addNodeView() {+ return createNodeView(CodeblockComponent, {+ contentDOMFactory: () => {+ const content = document.createElement("div");+ content.classList.add("node-content-wrapper");+ content.style.whiteSpace = "inherit";+ // caret is not visible if content element width is 0px+ content.style.minWidth = `20px`;+ return { dom: content };+ },+ shouldUpdate: ({ attrs: prev }, { attrs: next }) => {+ return (compareCaretPosition(prev.caretPosition, next.caretPosition) ||+ prev.language !== next.language ||+ prev.indentType !== next.indentType);+ },+ });+ },+});+export function toCaretPosition(selection, lines) {+ const { $from, $to, $head } = selection;+ if ($from.parent.type.name !== CodeBlock.name)+ return;+ lines = lines || getLines($from.parent);+ for (const line of lines) {+ if ($head.pos >= line.from && $head.pos <= line.to) {+ const lineLength = line.length + 1;+ return {+ line: line.index + 1,+ column: lineLength - (line.to - $head.pos),+ selected: $to.pos - $from.pos,+ total: lines.length,+ from: line.from,+ };+ }+ }+ return;+}+export function getLines(node) {+ const { lines } = node.attrs;+ return lines || [];+}+function exitOnTripleEnter(editor, $from) {+ const isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;+ const endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");+ if (!isAtEnd || !endsWithDoubleNewline) {+ return false;+ }+ return editor+ .chain()+ .command(({ tr }) => {+ tr.delete($from.pos - 2, $from.pos);+ return true;+ })+ .exitCode()+ .run();+}+function indentOnEnter(editor, $from, options) {+ const { indentation, newline } = getNewline($from, options) || {};+ if (!newline)+ return false;+ return editor+ .chain()+ .insertContent(`${newline}${indentation}`, {+ parseOptions: { preserveWhitespace: "full" },+ })+ .focus()+ .run();+}+function getNewline($from, options) {+ const { lines } = $from.parent.attrs;+ const currentLine = getLineAt(lines, $from.pos);+ if (!currentLine)+ return false;+ const text = currentLine.text();+ const indentLength = text.length - text.trimStart().length;+ return {+ newline: NEWLINE,+ indentation: indent({ amount: indentLength, type: options.type }),+ };+}+export function toCodeLines(code, pos) {+ const positions = [];+ let start = 0;+ let from = pos + 1;+ let index = 0;+ while (start <= code.length) {+ let end = code.indexOf("\n", start);+ if (end <= -1)+ end = code.length;+ const lineLength = end - start;+ const to = from + lineLength;+ const lineStart = start;+ positions.push({+ index,+ length: lineLength,+ from,+ to,+ text: (length) => {+ return code.slice(lineStart, length ? lineStart + length : lineStart + lineLength);+ },+ });+ from = to + 1;+ start = end + 1;+ ++index;+ }+ return positions;+}+function getSelectedLines(lines, selection) {+ const { $from, $to } = selection;+ return lines.filter((line) => inRange(line.from, $from.pos, $to.pos) ||+ inRange(line.to, $from.pos, $to.pos) ||+ inRange($from.pos, line.from, line.to));+}+function parseIndentation(node) {+ if (node.type.name !== CodeBlock.name)+ return undefined;+ const { indentType, indentLength } = node.attrs;+ return {+ type: indentType,+ amount: parseInt(indentLength),+ };+}+function getLineAt(lines, pos) {+ return lines.find((line) => pos >= line.from && pos <= line.to);+}+function inRange(x, a, b) {+ return x >= a && x <= b;+}+function indent(options) {+ const char = options.type === "space" ? " " : "\t";+ return char.repeat(options.amount);+}+function compareCaretPosition(prev, next) {+ return (next === undefined ||+ (prev === null || prev === void 0 ? void 0 : prev.column) !== (next === null || next === void 0 ? void 0 : next.column) ||+ (prev === null || prev === void 0 ? void 0 : prev.line) !== (next === null || next === void 0 ? void 0 : next.line));+}+/**+ * Persist selection between transaction steps+ */+function withSelection(tr, callback) {+ const { $anchor, $head } = tr.selection;+ callback(tr);+ tr.setSelection(new TextSelection(tr.doc.resolve(tr.mapping.map($anchor.pos)), tr.doc.resolve(tr.mapping.map($head.pos))));+ return true;+}+function fixIndentation(code, indent) {+ const { amount, type = "space" } = indent || detectIndent(code);+ const fixed = redent(code, amount, {+ includeEmptyLines: false,+ indent: type === "space" ? " " : "\t",+ });+ return { code: stripIndent(fixed), amount, type };+}diff --git a/packages/editor/dist/es/extensions/codeblock/component.d.ts b/packages/editor/dist/es/extensions/codeblock/component.d.tsnew file mode 100644index 000000000..cb8de2a9a--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { CodeBlockAttributes } from "./code-block";+import { ReactNodeViewProps } from "../react/types";+export declare function CodeblockComponent(props: ReactNodeViewProps<CodeBlockAttributes>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/codeblock/component.js b/packages/editor/dist/es/extensions/codeblock/component.jsnew file mode 100644index 000000000..8cd74eeec--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/component.js@@ -0,0 +1,142 @@+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { useEffect, useRef, useState } from "react";+import { isLanguageLoaded, loadLanguage } from "./loader";+import { refractor } from "refractor/lib/core";+import { Flex, Text } from "rebass";+import Languages from "./languages.json";+import { Input } from "@rebass/forms";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { ResponsivePresenter } from "../../components/responsive";+import { Popup } from "../../toolbar/components/popup";+import { Button } from "../../components/button";+export function CodeblockComponent(props) {+ const { editor, updateAttributes, node, forwardRef } = props;+ const { language, indentLength, indentType, caretPosition } = node === null || node === void 0 ? void 0 : node.attrs;+ const [isOpen, setIsOpen] = useState(false);+ // const [caretPosition, setCaretPosition] = useState<CaretPosition>();+ const toolbarRef = useRef(null);+ const languageDefinition = Languages.find((l) => { var _a; return l.filename === language || ((_a = l.alias) === null || _a === void 0 ? void 0 : _a.some((a) => a === language)); });+ useEffect(() => {+ (function () {+ return __awaiter(this, void 0, void 0, function* () {+ if (!language || !languageDefinition || isLanguageLoaded(language))+ return;+ const syntax = yield loadLanguage(languageDefinition.filename);+ if (!syntax)+ return;+ refractor.register(syntax);+ updateAttributes({+ language: languageDefinition.filename,+ });+ });+ })();+ }, [language]);+ return (_jsxs(_Fragment, { children: [_jsxs(Flex, Object.assign({ sx: {+ flexDirection: "column",+ borderRadius: "default",+ overflow: "hidden",+ } }, { children: [_jsx(Text, { ref: forwardRef, as: "pre", sx: {+ "div, span.token, span.line-number-widget, span.line-number::before": {+ fontFamily: "monospace",+ fontSize: "code",+ whiteSpace: "pre !important",+ tabSize: 1,+ },+ position: "relative",+ lineHeight: "20px",+ bg: "codeBg",+ color: "static",+ overflowX: "auto",+ display: "flex",+ px: 2,+ pt: 2,+ pb: 1,+ }, spellCheck: false }), _jsxs(Flex, Object.assign({ ref: toolbarRef, contentEditable: false, sx: {+ bg: "codeBg",+ alignItems: "center",+ justifyContent: "end",+ borderTop: "1px solid var(--codeBorder)",+ } }, { children: [caretPosition ? (_jsxs(Text, Object.assign({ variant: "subBody", sx: { mr: 2, color: "codeFg" } }, { children: ["Line ", caretPosition.line, ", Column ", caretPosition.column, " ", caretPosition.selected+ ? `(${caretPosition.selected} selected)`+ : ""] }))) : null, _jsx(Button, Object.assign({ variant: "icon", sx: { p: 1, mr: 1, ":hover": { bg: "codeSelection" } }, title: "Toggle indentation mode", onClick: () => {+ editor.commands.changeCodeBlockIndentation({+ type: indentType === "space" ? "tab" : "space",+ amount: indentLength,+ });+ } }, { children: _jsxs(Text, Object.assign({ variant: "subBody", sx: { color: "codeFg" } }, { children: [indentType === "space" ? "Spaces" : "Tabs", ": ", indentLength] })) })), _jsx(Button, Object.assign({ variant: "icon", sx: {+ p: 1,+ mr: 1,+ bg: isOpen ? "codeSelection" : "transparent",+ ":hover": { bg: "codeSelection" },+ }, onClick: () => {+ setIsOpen(true);+ }, title: "Change language" }, { children: _jsx(Text, Object.assign({ variant: "subBody", spellCheck: false, sx: { color: "codeFg" } }, { children: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.title) || "Plaintext" })) }))] }))] })), _jsx(ResponsivePresenter, Object.assign({ isOpen: isOpen, onClose: () => {+ setIsOpen(false);+ // NOTE: for some reason the language selection action sheet+ // does not return focus to the last focused position after+ // closing. We have to set focusOnRender=false & manually+ // restore focus. I think this has something to do with custom+ // node views.+ // TRY: perhaps use SelectionBasedReactNodeView?+ editor.commands.focus();+ }, focusOnRender: false, mobile: "sheet", desktop: "menu", position: {+ target: toolbarRef.current || undefined,+ align: "end",+ isTargetAbsolute: true,+ location: "top",+ yOffset: 5,+ }, title: "Change code block language" }, { children: _jsx(LanguageSelector, { selectedLanguage: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.filename) || "Plaintext", onLanguageSelected: (language) => {+ updateAttributes({ language });+ setIsOpen(false);+ }, onClose: () => setIsOpen(false) }) }))] }));+}+function LanguageSelector(props) {+ const { onLanguageSelected, selectedLanguage, onClose } = props;+ const [languages, setLanguages] = useState(Languages);+ return (_jsx(Popup, Object.assign({ title: "Select language", onClose: onClose }, { children: _jsxs(Flex, Object.assign({ sx: {+ flexDirection: "column",+ height: 200,+ width: ["auto", 300],+ overflowY: "auto",+ bg: "background",+ } }, { children: [_jsx(Input, { onFocus: () => {+ console.log("EHLLO!");+ }, autoFocus: true, placeholder: "Search languages", sx: {+ width: "auto",+ position: "sticky",+ top: 0,+ bg: "background",+ mx: 2,+ p: "7px",+ zIndex: 999,+ }, onChange: (e) => {+ if (!e.target.value)+ return setLanguages(Languages);+ const query = e.target.value.toLowerCase();+ setLanguages(Languages.filter((lang) => {+ var _a;+ return (lang.title.toLowerCase().indexOf(query) > -1 ||+ ((_a = lang.alias) === null || _a === void 0 ? void 0 : _a.some((alias) => alias.toLowerCase().indexOf(query) > -1)));+ }));+ } }), _jsx(Flex, Object.assign({ sx: {+ flexDirection: "column",+ pt: 1,+ mt: 1,+ } }, { children: languages.map((lang) => (_jsxs(Button, Object.assign({ variant: "menuitem", sx: {+ textAlign: "left",+ py: 1,+ display: "flex",+ justifyContent: "space-between",+ alignItems: "center",+ }, onClick: () => onLanguageSelected(lang.filename) }, { children: [_jsx(Text, Object.assign({ variant: "body" }, { children: lang.title })), selectedLanguage === lang.filename ? (_jsx(Icon, { path: Icons.check, size: "small" })) : lang.alias ? (_jsx(Text, Object.assign({ variant: "subBody", sx: { fontSize: "10px" } }, { children: lang.alias.slice(0, 3).join(", ") }))) : null] }), lang.title))) }))] })) })));+}diff --git a/packages/editor/dist/es/extensions/codeblock/highlighter.d.ts b/packages/editor/dist/es/extensions/codeblock/highlighter.d.tsnew file mode 100644index 000000000..e42464534--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/highlighter.d.ts@@ -0,0 +1,8 @@+import { Plugin } from "prosemirror-state";+import { DecorationSet } from "prosemirror-view";+import { AddMarkStep, RemoveMarkStep, ReplaceAroundStep, ReplaceStep } from "prosemirror-transform";+export declare type MergedStep = AddMarkStep | RemoveMarkStep | ReplaceAroundStep | ReplaceStep;+export declare function HighlighterPlugin({ name, defaultLanguage, }: {+ name: string;+ defaultLanguage: string | null | undefined;+}): Plugin<DecorationSet>;diff --git a/packages/editor/dist/es/extensions/codeblock/highlighter.js b/packages/editor/dist/es/extensions/codeblock/highlighter.jsnew file mode 100644index 000000000..d6d5b3ff9--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/highlighter.js@@ -0,0 +1,207 @@+import { Plugin, PluginKey } from "prosemirror-state";+import { Decoration, DecorationSet } from "prosemirror-view";+import { findChildren } from "@tiptap/core";+import { refractor } from "refractor/lib/core";+import { toCaretPosition, toCodeLines, } from "./code-block";+function parseNodes(nodes, className = []) {+ return nodes.reduce((result, node) => {+ if (node.type === "comment" || node.type === "doctype")+ return result;+ const classes = [...className];+ if (node.type === "element" && node.properties)+ classes.push(...node.properties.className);+ // this is required so that even plain text is wrapped in a span+ // during highlighting. Without this, Prosemirror's selection acts+ // weird for the first highlighted node/span.+ else+ classes.push("token", "text");+ if (node.type === "element") {+ result.push(...parseNodes(node.children, classes));+ }+ else {+ result.push({ classes, text: node.value });+ }+ return result;+ }, []);+}+function getHighlightNodes(result) {+ return result.children || [];+}+function getLineDecoration(from, line, total, isActive) {+ const maxLength = String(total).length;+ const attributes = {+ class: `line-number ${isActive ? "active" : ""}`,+ "data-line": String(line).padEnd(maxLength, " "),+ };+ const spec = {+ line: line,+ active: isActive,+ total,+ from,+ };+ // Prosemirror has a selection issue with the widget decoration+ // on the first line. To work around that we use inline decoration+ // for the first line.+ if (line === 1 ||+ // Android Composition API (aka the virtual keyboard) doesn't behave well+ // with Decoration widgets so we have to resort to inline line numbers.+ isAndroid()) {+ return Decoration.inline(from, from + 1, attributes, spec);+ }+ return Decoration.widget(from, () => {+ const element = document.createElement("span");+ element.classList.add("line-number-widget");+ if (isActive)+ element.classList.add("active");+ element.innerHTML = attributes["data-line"];+ return element;+ }, Object.assign(Object.assign({}, spec), {+ // should rerender when any of these change:+ // 1. line number+ // 2. line active state+ // 3. the max length of all lines+ key: `${line}-${isActive ? "active" : ""}-${maxLength}` }));+}+function getDecorations({ doc, name, defaultLanguage, caretPosition, }) {+ const decorations = [];+ const languages = refractor.listLanguages();+ findChildren(doc, (node) => node.type.name === name).forEach((block) => {+ const code = block.node.textContent;+ const lines = toCodeLines(code, block.pos);+ for (const line of lines || []) {+ const lineNumber = line.index + 1;+ const isActive = lineNumber === (caretPosition === null || caretPosition === void 0 ? void 0 : caretPosition.line) && line.from === (caretPosition === null || caretPosition === void 0 ? void 0 : caretPosition.from);+ const decoration = getLineDecoration(line.from, lineNumber, (lines === null || lines === void 0 ? void 0 : lines.length) || 0, isActive);+ decorations.push(decoration);+ }+ const language = block.node.attrs.language || defaultLanguage;+ const nodes = languages.includes(language)+ ? getHighlightNodes(refractor.highlight(code, language))+ : null;+ if (!nodes)+ return;+ let from = block.pos + 1;+ parseNodes(nodes).forEach((node) => {+ const to = from + node.text.length;+ if (node.classes.length) {+ const decoration = Decoration.inline(from, to, {+ class: node.classes.join(" "),+ });+ decorations.push(decoration);+ }+ from = to;+ });+ });+ return DecorationSet.create(doc, decorations);+}+export function HighlighterPlugin({ name, defaultLanguage, }) {+ const key = new PluginKey("highlighter");+ return new Plugin({+ key,+ state: {+ init: () => {+ return DecorationSet.empty;+ },+ apply: (transaction, decorationSet, oldState, newState) => {+ const oldNodeName = oldState.selection.$head.parent.type.name;+ const newNodeName = newState.selection.$head.parent.type.name;+ const oldNodes = findChildren(oldState.doc, (node) => node.type.name === name);+ const newNodes = findChildren(newState.doc, (node) => node.type.name === name);+ const position = toCaretPosition(newState.selection);+ // const isDocChanged =+ // transaction.docChanged &&+ // // TODO+ // !transaction.steps.every((step) => step instanceof ReplaceAroundStep);+ // console.log("Selection", transaction.docChanged, isDocChanged);+ if (transaction.docChanged &&+ // Apply decorations if:+ // selection includes named node,+ ([oldNodeName, newNodeName].includes(name) ||+ // OR transaction adds/removes named node,+ newNodes.length !== oldNodes.length ||+ // OR transaction has changes that completely encapsulte a node+ // (for example, a transaction that affects the entire document).+ // Such transactions can happen during collab syncing via y-prosemirror, for example.+ transaction.steps.some((step) => {+ return (step.from !== undefined &&+ step.to !== undefined &&+ oldNodes.some((node) => {+ return (node.pos >= step.from &&+ node.pos + node.node.nodeSize <= step.to);+ }));+ }))) {+ return getDecorations({+ doc: transaction.doc,+ name,+ defaultLanguage,+ caretPosition: position,+ });+ }+ decorationSet = getActiveLineDecorations(transaction.doc, decorationSet, position);+ return decorationSet.map(transaction.mapping, transaction.doc);+ },+ },+ props: {+ decorations(state) {+ return key.getState(state);+ },+ },+ appendTransaction: (transactions, prevState, nextState) => {+ const tr = nextState.tr;+ let modified = false;+ const docChanged = transactions.some((transaction) => transaction.docChanged);+ const selectionChanged = (nextState.selection.$from.parent.type.name === name ||+ prevState.selection.$from.parent.type.name === name) &&+ prevState.selection.$from.pos !== nextState.selection.$from.pos;+ findChildren(nextState.doc, (node) => node.type.name === name).forEach((block) => {+ const { node, pos } = block;+ const attributes = Object.assign({}, node.attrs);+ if (docChanged) {+ const lines = toCodeLines(node.textContent, pos);+ attributes.lines = lines.slice();+ }+ if (selectionChanged) {+ const position = toCaretPosition(nextState.selection, docChanged ? toCodeLines(node.textContent, pos) : undefined);+ attributes.caretPosition = position;+ }+ if (docChanged || selectionChanged) {+ tr.setNodeMarkup(pos, node.type, attributes);+ modified = true;+ }+ });+ return modified ? tr : null;+ },+ });+}+/**+ * When `position` is undefined, all active line decorations+ * are reset (e.g. when you focus out of the code block).+ */+function getActiveLineDecorations(doc, decorations, position) {+ const lineDecorations = decorations.find(undefined, undefined, ({ line, active, from }) => {+ const isSame = position+ ? line === position.line && from === position.from+ : false;+ return isSame || active;+ });+ if (!lineDecorations.length)+ return decorations;+ // we have to clone because prosemirror operates in-place+ const cloned = lineDecorations.slice();+ // remove old line decorations which inclue the current line decoration+ // and the previous current line decoration. We'll replace these with+ // new decorations.+ decorations = decorations.remove(lineDecorations);+ const newDecorations = [];+ for (const decoration of cloned) {+ const { from, spec: { line, total }, } = decoration;+ const isActive = line === (position === null || position === void 0 ? void 0 : position.line);+ const newDecoration = getLineDecoration(from, line, (position === null || position === void 0 ? void 0 : position.total) || total, isActive);+ newDecorations.push(newDecoration);+ }+ return decorations.add(doc, newDecorations);+}+function isAndroid() {+ var ua = navigator.userAgent.toLowerCase();+ return ua.indexOf("android") > -1; //&& ua.indexOf("mobile");+}diff --git a/packages/editor/dist/es/extensions/codeblock/index.d.ts b/packages/editor/dist/es/extensions/codeblock/index.d.tsnew file mode 100644index 000000000..80ea37c7c--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/index.d.ts@@ -0,0 +1 @@+export * from "./code-block";diff --git a/packages/editor/dist/es/extensions/codeblock/index.js b/packages/editor/dist/es/extensions/codeblock/index.jsnew file mode 100644index 000000000..80ea37c7c--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/index.js@@ -0,0 +1 @@+export * from "./code-block";diff --git a/packages/editor/dist/es/extensions/codeblock/languages.json b/packages/editor/dist/es/extensions/codeblock/languages.jsonnew file mode 100644index 000000000..d932b9f77--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/languages.json@@ -0,0 +1 @@+[{ "filename": "markup", "title": "Markup", "alias": ["html", "xml", "svg", "mathml", "ssml", "atom", "rss"] }, { "filename": "css", "title": "CSS" }, { "filename": "clike", "title": "C-like" }, { "filename": "javascript", "title": "JavaScript", "alias": ["js"] }, { "filename": "abap", "title": "ABAP" }, { "filename": "abnf", "title": "ABNF" }, { "filename": "actionscript", "title": "ActionScript" }, { "filename": "ada", "title": "Ada" }, { "filename": "agda", "title": "Agda" }, { "filename": "al", "title": "AL" }, { "filename": "antlr4", "title": "ANTLR4", "alias": ["g4"] }, { "filename": "apacheconf", "title": "Apache Configuration" }, { "filename": "apex", "title": "Apex" }, { "filename": "apl", "title": "APL" }, { "filename": "applescript", "title": "AppleScript" }, { "filename": "aql", "title": "AQL" }, { "filename": "arduino", "title": "Arduino", "alias": ["ino"] }, { "filename": "arff", "title": "ARFF" }, { "filename": "armasm", "title": "ARM Assembly", "alias": ["arm-asm"] }, { "filename": "arturo", "title": "Arturo", "alias": ["art"] }, { "filename": "asciidoc", "title": "AsciiDoc", "alias": ["adoc"] }, { "filename": "aspnet", "title": "ASP.NET (C#)" }, { "filename": "asm6502", "title": "6502 Assembly" }, { "filename": "asmatmel", "title": "Atmel AVR Assembly" }, { "filename": "autohotkey", "title": "AutoHotkey" }, { "filename": "autoit", "title": "AutoIt" }, { "filename": "avisynth", "title": "AviSynth", "alias": ["avs"] }, { "filename": "avro-idl", "title": "Avro IDL", "alias": ["avdl"] }, { "filename": "awk", "title": "AWK", "alias": ["gawk"] }, { "filename": "bash", "title": "Bash", "alias": ["shell"] }, { "filename": "basic", "title": "BASIC" }, { "filename": "batch", "title": "Batch" }, { "filename": "bbcode", "title": "BBcode", "alias": ["shortcode"] }, { "filename": "bicep", "title": "Bicep" }, { "filename": "birb", "title": "Birb" }, { "filename": "bison", "title": "Bison" }, { "filename": "bnf", "title": "BNF", "alias": ["rbnf"] }, { "filename": "brainfuck", "title": "Brainfuck" }, { "filename": "brightscript", "title": "BrightScript" }, { "filename": "bro", "title": "Bro" }, { "filename": "bsl", "title": "BSL (1C:Enterprise)", "alias": ["oscript"] }, { "filename": "c", "title": "C" }, { "filename": "csharp", "title": "C#", "alias": ["cs", "dotnet"] }, { "filename": "cpp", "title": "C++" }, { "filename": "cfscript", "title": "CFScript", "alias": ["cfc"] }, { "filename": "chaiscript", "title": "ChaiScript" }, { "filename": "cil", "title": "CIL" }, { "filename": "clojure", "title": "Clojure" }, { "filename": "cmake", "title": "CMake" }, { "filename": "cobol", "title": "COBOL" }, { "filename": "coffeescript", "title": "CoffeeScript", "alias": ["coffee"] }, { "filename": "concurnas", "title": "Concurnas", "alias": ["conc"] }, { "filename": "csp", "title": "Content-Security-Policy" }, { "filename": "cooklang", "title": "Cooklang" }, { "filename": "coq", "title": "Coq" }, { "filename": "crystal", "title": "Crystal" }, { "filename": "css-extras", "title": "CSS Extras" }, { "filename": "csv", "title": "CSV" }, { "filename": "cue", "title": "CUE" }, { "filename": "cypher", "title": "Cypher" }, { "filename": "d", "title": "D" }, { "filename": "dart", "title": "Dart" }, { "filename": "dataweave", "title": "DataWeave" }, { "filename": "dax", "title": "DAX" }, { "filename": "dhall", "title": "Dhall" }, { "filename": "diff", "title": "Diff" }, { "filename": "django", "title": "Django/Jinja2", "alias": ["jinja2"] }, { "filename": "dns-zone-file", "title": "DNS zone file", "alias": ["dns-zone"] }, { "filename": "docker", "title": "Docker", "alias": ["dockerfile"] }, { "filename": "dot", "title": "DOT (Graphviz)", "alias": ["gv"] }, { "filename": "ebnf", "title": "EBNF" }, { "filename": "editorconfig", "title": "EditorConfig" }, { "filename": "eiffel", "title": "Eiffel" }, { "filename": "ejs", "title": "EJS", "alias": ["eta"] }, { "filename": "elixir", "title": "Elixir" }, { "filename": "elm", "title": "Elm" }, { "filename": "etlua", "title": "Embedded Lua templating" }, { "filename": "erb", "title": "ERB" }, { "filename": "erlang", "title": "Erlang" }, { "filename": "excel-formula", "title": "Excel Formula", "alias": ["xlsx", "xls"] }, { "filename": "fsharp", "title": "F#" }, { "filename": "factor", "title": "Factor" }, { "filename": "false", "title": "False" }, { "filename": "firestore-security-rules", "title": "Firestore security rules" }, { "filename": "flow", "title": "Flow" }, { "filename": "fortran", "title": "Fortran" }, { "filename": "ftl", "title": "FreeMarker Template Language" }, { "filename": "gml", "title": "GameMaker Language", "alias": ["gamemakerlanguage"] }, { "filename": "gap", "title": "GAP (CAS)" }, { "filename": "gcode", "title": "G-code" }, { "filename": "gdscript", "title": "GDScript" }, { "filename": "gedcom", "title": "GEDCOM" }, { "filename": "gettext", "title": "gettext", "alias": ["po"] }, { "filename": "gherkin", "title": "Gherkin" }, { "filename": "git", "title": "Git" }, { "filename": "glsl", "title": "GLSL" }, { "filename": "gn", "title": "GN", "alias": ["gni"] }, { "filename": "linker-script", "title": "GNU Linker Script", "alias": ["ld"] }, { "filename": "go", "title": "Go" }, { "filename": "go-module", "title": "Go module", "alias": ["go-mod"] }, { "filename": "gradle", "title": "Gradle" }, { "filename": "graphql", "title": "GraphQL" }, { "filename": "groovy", "title": "Groovy" }, { "filename": "haml", "title": "Haml" }, { "filename": "handlebars", "title": "Handlebars", "alias": ["hbs", "mustache"] }, { "filename": "haskell", "title": "Haskell", "alias": ["hs"] }, { "filename": "haxe", "title": "Haxe" }, { "filename": "hcl", "title": "HCL" }, { "filename": "hlsl", "title": "HLSL" }, { "filename": "hoon", "title": "Hoon" }, { "filename": "http", "title": "HTTP" }, { "filename": "hpkp", "title": "HTTP Public-Key-Pins" }, { "filename": "hsts", "title": "HTTP Strict-Transport-Security" }, { "filename": "ichigojam", "title": "IchigoJam" }, { "filename": "icon", "title": "Icon" }, { "filename": "icu-message-format", "title": "ICU Message Format" }, { "filename": "idris", "title": "Idris", "alias": ["idr"] }, { "filename": "ignore", "title": ".ignore", "alias": ["gitignore", "hgignore", "npmignore"] }, { "filename": "inform7", "title": "Inform 7" }, { "filename": "ini", "title": "Ini" }, { "filename": "io", "title": "Io" }, { "filename": "j", "title": "J" }, { "filename": "java", "title": "Java" }, { "filename": "javadoc", "title": "JavaDoc" }, { "filename": "javadoclike", "title": "JavaDoc-like" }, { "filename": "javastacktrace", "title": "Java stack trace" }, { "filename": "jexl", "title": "Jexl" }, { "filename": "jolie", "title": "Jolie" }, { "filename": "jq", "title": "JQ" }, { "filename": "jsdoc", "title": "JSDoc" }, { "filename": "js-extras", "title": "JS Extras" }, { "filename": "json", "title": "JSON", "alias": ["webmanifest"] }, { "filename": "json5", "title": "JSON5" }, { "filename": "jsonp", "title": "JSONP" }, { "filename": "jsstacktrace", "title": "JS stack trace" }, { "filename": "js-templates", "title": "JS Templates" }, { "filename": "julia", "title": "Julia" }, { "filename": "keepalived", "title": "Keepalived Configure" }, { "filename": "keyman", "title": "Keyman" }, { "filename": "kotlin", "title": "Kotlin", "alias": ["kt", "kts"] }, { "filename": "kumir", "title": "KuMir (КуМир)", "alias": ["kum"] }, { "filename": "kusto", "title": "Kusto" }, { "filename": "latex", "title": "LaTeX", "alias": ["tex", "context"] }, { "filename": "latte", "title": "Latte" }, { "filename": "less", "title": "Less" }, { "filename": "lilypond", "title": "LilyPond", "alias": ["ly"] }, { "filename": "liquid", "title": "Liquid" }, { "filename": "lisp", "title": "Lisp", "alias": ["emacs", "elisp", "emacs-lisp"] }, { "filename": "livescript", "title": "LiveScript" }, { "filename": "llvm", "title": "LLVM IR" }, { "filename": "log", "title": "Log file" }, { "filename": "lolcode", "title": "LOLCODE" }, { "filename": "lua", "title": "Lua" }, { "filename": "magma", "title": "Magma (CAS)" }, { "filename": "makefile", "title": "Makefile" }, { "filename": "markdown", "title": "Markdown", "alias": ["md"] }, { "filename": "markup-templating", "title": "Markup templating" }, { "filename": "mata", "title": "Mata" }, { "filename": "matlab", "title": "MATLAB" }, { "filename": "maxscript", "title": "MAXScript" }, { "filename": "mel", "title": "MEL" }, { "filename": "mermaid", "title": "Mermaid" }, { "filename": "mizar", "title": "Mizar" }, { "filename": "mongodb", "title": "MongoDB" }, { "filename": "monkey", "title": "Monkey" }, { "filename": "moonscript", "title": "MoonScript", "alias": ["moon"] }, { "filename": "n1ql", "title": "N1QL" }, { "filename": "n4js", "title": "N4JS", "alias": ["n4jsd"] }, { "filename": "nand2tetris-hdl", "title": "Nand To Tetris HDL" }, { "filename": "naniscript", "title": "Naninovel Script", "alias": ["nani"] }, { "filename": "nasm", "title": "NASM" }, { "filename": "neon", "title": "NEON" }, { "filename": "nevod", "title": "Nevod" }, { "filename": "nginx", "title": "nginx" }, { "filename": "nim", "title": "Nim" }, { "filename": "nix", "title": "Nix" }, { "filename": "nsis", "title": "NSIS" }, { "filename": "objectivec", "title": "Objective-C", "alias": ["objc"] }, { "filename": "ocaml", "title": "OCaml" }, { "filename": "odin", "title": "Odin" }, { "filename": "opencl", "title": "OpenCL" }, { "filename": "openqasm", "title": "OpenQasm", "alias": ["qasm"] }, { "filename": "oz", "title": "Oz" }, { "filename": "parigp", "title": "PARI/GP" }, { "filename": "parser", "title": "Parser" }, { "filename": "pascal", "title": "Pascal", "alias": ["objectpascal"] }, { "filename": "pascaligo", "title": "Pascaligo" }, { "filename": "psl", "title": "PATROL Scripting Language" }, { "filename": "pcaxis", "title": "PC-Axis", "alias": ["px"] }, { "filename": "peoplecode", "title": "PeopleCode", "alias": ["pcode"] }, { "filename": "perl", "title": "Perl" }, { "filename": "php", "title": "PHP" }, { "filename": "phpdoc", "title": "PHPDoc" }, { "filename": "php-extras", "title": "PHP Extras" }, { "filename": "plant-uml", "title": "PlantUML", "alias": ["plantuml"] }, { "filename": "plsql", "title": "PL/SQL" }, { "filename": "powerquery", "title": "PowerQuery", "alias": ["pq", "mscript"] }, { "filename": "powershell", "title": "PowerShell" }, { "filename": "processing", "title": "Processing" }, { "filename": "prolog", "title": "Prolog" }, { "filename": "promql", "title": "PromQL" }, { "filename": "properties", "title": ".properties" }, { "filename": "protobuf", "title": "Protocol Buffers" }, { "filename": "pug", "title": "Pug" }, { "filename": "puppet", "title": "Puppet" }, { "filename": "pure", "title": "Pure" }, { "filename": "purebasic", "title": "PureBasic", "alias": ["pbfasm"] }, { "filename": "purescript", "title": "PureScript", "alias": ["purs"] }, { "filename": "python", "title": "Python", "alias": ["py"] }, { "filename": "qsharp", "title": "Q#", "alias": ["qs"] }, { "filename": "q", "title": "Q (kdb+ database)" }, { "filename": "qml", "title": "QML" }, { "filename": "qore", "title": "Qore" }, { "filename": "r", "title": "R" }, { "filename": "racket", "title": "Racket", "alias": ["rkt"] }, { "filename": "cshtml", "title": "Razor C#", "alias": ["razor"] }, { "filename": "jsx", "title": "React JSX" }, { "filename": "tsx", "title": "React TSX" }, { "filename": "reason", "title": "Reason" }, { "filename": "regex", "title": "Regex" }, { "filename": "rego", "title": "Rego" }, { "filename": "renpy", "title": "Ren'py", "alias": ["rpy"] }, { "filename": "rescript", "title": "ReScript", "alias": ["res"] }, { "filename": "rest", "title": "reST (reStructuredText)" }, { "filename": "rip", "title": "Rip" }, { "filename": "roboconf", "title": "Roboconf" }, { "filename": "robotframework", "title": "Robot Framework", "alias": ["robot"] }, { "filename": "ruby", "title": "Ruby", "alias": ["rb"] }, { "filename": "rust", "title": "Rust" }, { "filename": "sas", "title": "SAS" }, { "filename": "sass", "title": "Sass (Sass)" }, { "filename": "scss", "title": "Sass (Scss)" }, { "filename": "scala", "title": "Scala" }, { "filename": "scheme", "title": "Scheme" }, { "filename": "shell-session", "title": "Shell session", "alias": ["sh-session", "shellsession"] }, { "filename": "smali", "title": "Smali" }, { "filename": "smalltalk", "title": "Smalltalk" }, { "filename": "smarty", "title": "Smarty" }, { "filename": "sml", "title": "SML", "alias": ["smlnj"] }, { "filename": "solidity", "title": "Solidity (Ethereum)", "alias": ["sol"] }, { "filename": "solution-file", "title": "Solution file", "alias": ["sln"] }, { "filename": "soy", "title": "Soy (Closure Template)" }, { "filename": "sparql", "title": "SPARQL", "alias": ["rq"] }, { "filename": "splunk-spl", "title": "Splunk SPL" }, { "filename": "sqf", "title": "SQF: Status Quo Function (Arma 3)" }, { "filename": "sql", "title": "SQL" }, { "filename": "squirrel", "title": "Squirrel" }, { "filename": "stan", "title": "Stan" }, { "filename": "stata", "title": "Stata Ado" }, { "filename": "iecst", "title": "Structured Text (IEC 61131-3)" }, { "filename": "stylus", "title": "Stylus" }, { "filename": "supercollider", "title": "SuperCollider", "alias": ["sclang"] }, { "filename": "swift", "title": "Swift" }, { "filename": "systemd", "title": "Systemd configuration file" }, { "filename": "t4-templating", "title": "T4 templating" }, { "filename": "t4-cs", "title": "T4 Text Templates (C#)", "alias": ["t4"] }, { "filename": "t4-vb", "title": "T4 Text Templates (VB)" }, { "filename": "tap", "title": "TAP" }, { "filename": "tcl", "title": "Tcl" }, { "filename": "tt2", "title": "Template Toolkit 2" }, { "filename": "textile", "title": "Textile" }, { "filename": "toml", "title": "TOML" }, { "filename": "tremor", "title": "Tremor", "alias": ["trickle", "troy"] }, { "filename": "turtle", "title": "Turtle", "alias": ["trig"] }, { "filename": "twig", "title": "Twig" }, { "filename": "typescript", "title": "TypeScript", "alias": ["ts"] }, { "filename": "typoscript", "title": "TypoScript", "alias": ["tsconfig"] }, { "filename": "unrealscript", "title": "UnrealScript", "alias": ["uscript", "uc"] }, { "filename": "uorazor", "title": "UO Razor Script" }, { "filename": "uri", "title": "URI", "alias": ["url"] }, { "filename": "v", "title": "V" }, { "filename": "vala", "title": "Vala" }, { "filename": "vbnet", "title": "VB.Net" }, { "filename": "velocity", "title": "Velocity" }, { "filename": "verilog", "title": "Verilog" }, { "filename": "vhdl", "title": "VHDL" }, { "filename": "vim", "title": "vim" }, { "filename": "visual-basic", "title": "Visual Basic", "alias": ["vb", "vba"] }, { "filename": "warpscript", "title": "WarpScript" }, { "filename": "wasm", "title": "WebAssembly" }, { "filename": "web-idl", "title": "Web IDL", "alias": ["webidl"] }, { "filename": "wgsl", "title": "WGSL" }, { "filename": "wiki", "title": "Wiki markup" }, { "filename": "wolfram", "title": "Wolfram language", "alias": ["mathematica", "nb", "wl"] }, { "filename": "wren", "title": "Wren" }, { "filename": "xeora", "title": "Xeora", "alias": ["xeoracube"] }, { "filename": "xml-doc", "title": "XML doc (.net)" }, { "filename": "xojo", "title": "Xojo (REALbasic)" }, { "filename": "xquery", "title": "XQuery" }, { "filename": "yaml", "title": "YAML", "alias": ["yml"] }, { "filename": "yang", "title": "YANG" }, { "filename": "zig", "title": "Zig" }]diff --git a/packages/editor/dist/es/extensions/codeblock/loader.d.ts b/packages/editor/dist/es/extensions/codeblock/loader.d.tsnew file mode 100644index 000000000..5162f1715--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/loader.d.ts@@ -0,0 +1,2 @@+export declare function isLanguageLoaded(name: string): boolean;+export declare function loadLanguage(shortName: string): Promise<import("refractor/lib/core").Syntax | undefined>;diff --git a/packages/editor/dist/es/extensions/codeblock/loader.js b/packages/editor/dist/es/extensions/codeblock/loader.jsnew file mode 100644index 000000000..97ed418cf--- /dev/null+++ b/packages/editor/dist/es/extensions/codeblock/loader.js@@ -0,0 +1,45 @@+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+const loadedLanguages = {};+export function isLanguageLoaded(name) {+ return !!loadedLanguages[name];+}+export function loadLanguage(shortName) {+ return __awaiter(this, void 0, void 0, function* () {+ if (loadedLanguages[shortName])+ return loadedLanguages[shortName];+ const url = `https://esm.sh/[email protected]/lang/${shortName}.js?bundle=true`;+ const result = yield loadScript(shortName, url);+ loadedLanguages[shortName] = result;+ return result;+ });+}+function loadScript(id, url) {+ return __awaiter(this, void 0, void 0, function* () {+ return new Promise((resolve, reject) => {+ const callbackName = `on${id}Loaded`;+ const script = document.createElement("script");+ script.type = "module";+ script.innerHTML = `+ import LanguageDefinition from "${url}";+ if (window["${callbackName}"]) {+ window["${callbackName}"](LanguageDefinition)+ }+`;+ window[callbackName] = (lang) => {+ script.remove();+ window[callbackName] = null;+ resolve(lang);+ };+ // Append to the `head` element+ document.head.appendChild(script);+ });+ });+}diff --git a/packages/editor/dist/es/extensions/codemark/codemark.d.ts b/packages/editor/dist/es/extensions/codemark/codemark.d.tsnew file mode 100644index 000000000..003c47b2f--- /dev/null+++ b/packages/editor/dist/es/extensions/codemark/codemark.d.ts@@ -0,0 +1,2 @@+import { Extension } from "@tiptap/core";+export declare const Codemark: Extension<any, any>;diff --git a/packages/editor/dist/es/extensions/codemark/codemark.js b/packages/editor/dist/es/extensions/codemark/codemark.jsnew file mode 100644index 000000000..ac55412f3--- /dev/null+++ b/packages/editor/dist/es/extensions/codemark/codemark.js@@ -0,0 +1,8 @@+import { Extension } from "@tiptap/core";+import codemark from "prosemirror-codemark";+export const Codemark = Extension.create({+ name: "codemarkPlugin",+ addProseMirrorPlugins() {+ return codemark({ markType: this.editor.schema.marks.code });+ },+});diff --git a/packages/editor/dist/es/extensions/codemark/index.d.ts b/packages/editor/dist/es/extensions/codemark/index.d.tsnew file mode 100644index 000000000..8c4911b98--- /dev/null+++ b/packages/editor/dist/es/extensions/codemark/index.d.ts@@ -0,0 +1,2 @@+export * from "./code-mark";+export { Codemark as default } from "./code-mark";diff --git a/packages/editor/dist/es/extensions/codemark/index.js b/packages/editor/dist/es/extensions/codemark/index.jsnew file mode 100644index 000000000..8c4911b98--- /dev/null+++ b/packages/editor/dist/es/extensions/codemark/index.js@@ -0,0 +1,2 @@+export * from "./code-mark";+export { Codemark as default } from "./code-mark";diff --git a/packages/editor/dist/es/extensions/dropcursor/dropcursor.d.ts b/packages/editor/dist/es/extensions/dropcursor/dropcursor.d.tsnew file mode 100644index 000000000..5901f57f7--- /dev/null+++ b/packages/editor/dist/es/extensions/dropcursor/dropcursor.d.ts@@ -0,0 +1,7 @@+import { Extension } from "@tiptap/core";+export interface DropcursorOptions {+ color?: string | null;+ width?: number | null;+ class?: string | null;+}+export declare const Dropcursor: Extension<DropcursorOptions, any>;diff --git a/packages/editor/dist/es/extensions/dropcursor/dropcursor.js b/packages/editor/dist/es/extensions/dropcursor/dropcursor.jsnew file mode 100644index 000000000..d97683bc4--- /dev/null+++ b/packages/editor/dist/es/extensions/dropcursor/dropcursor.js@@ -0,0 +1,15 @@+import { Extension } from "@tiptap/core";+import { dropCursor } from "./drop-cursor.pm";+export const Dropcursor = Extension.create({+ name: "dropCursor",+ addOptions() {+ return {+ color: "currentColor",+ width: 1,+ class: null,+ };+ },+ addProseMirrorPlugins() {+ return [dropCursor(this.options)];+ },+});diff --git a/packages/editor/dist/es/extensions/dropcursor/dropcursor.pm.d.ts b/packages/editor/dist/es/extensions/dropcursor/dropcursor.pm.d.tsnew file mode 100644index 000000000..169767489--- /dev/null+++ b/packages/editor/dist/es/extensions/dropcursor/dropcursor.pm.d.ts@@ -0,0 +1,3 @@+import { Plugin } from "prosemirror-state";+import { DropcursorOptions } from "./drop-cursor";+export declare function dropCursor(options?: DropcursorOptions): Plugin<any>;diff --git a/packages/editor/dist/es/extensions/dropcursor/dropcursor.pm.js b/packages/editor/dist/es/extensions/dropcursor/dropcursor.pm.jsnew file mode 100644index 000000000..af6a5ac17--- /dev/null+++ b/packages/editor/dist/es/extensions/dropcursor/dropcursor.pm.js@@ -0,0 +1,169 @@+import { Plugin } from "prosemirror-state";+import { dropPoint } from "prosemirror-transform";+// :: (options: ?Object) → Plugin+// Create a plugin that, when added to a ProseMirror instance,+// causes a decoration to show up at the drop position when something+// is dragged over the editor.+//+// Nodes may add a `disableDropCursor` property to their spec to+// control the showing of a drop cursor inside them. This may be a+// boolean or a function, which will be called with a view and a+// position, and should return a boolean.+//+// options::- These options are supported:+//+// color:: ?string+// The color of the cursor. Defaults to `black`.+//+// width:: ?number+// The precise width of the cursor in pixels. Defaults to 1.+//+// class:: ?string+// A CSS class name to add to the cursor element.+export function dropCursor(options = {}) {+ return new Plugin({+ view(editorView) {+ return new DropCursorView(editorView, options);+ },+ });+}+class DropCursorView {+ constructor(editorView, options) {+ this.editorView = editorView;+ this.width = options.width || 1;+ this.color = options.color || "black";+ this.class = options.class || "";+ this.cursorPos = null;+ this.element = null;+ this.timeout = null;+ this.handlers = ["dragover", "dragend", "drop", "dragleave"].map((name) => {+ let handler = (e) => this[name](e);+ editorView.dom.addEventListener(name, handler);+ return { name, handler };+ });+ }+ destroy() {+ this.handlers.forEach(({ name, handler }) => this.editorView.dom.removeEventListener(name, handler));+ }+ update(editorView, prevState) {+ if (this.cursorPos != null && prevState.doc != editorView.state.doc) {+ if (this.cursorPos > editorView.state.doc.content.size)+ this.setCursor(null);+ else+ this.updateOverlay();+ }+ }+ setCursor(pos) {+ if (pos == this.cursorPos)+ return;+ this.cursorPos = pos;+ if (pos == null && this.element && this.element.parentNode) {+ this.element.parentNode.removeChild(this.element);+ this.element = null;+ }+ else {+ this.updateOverlay();+ }+ }+ updateOverlay() {+ if (!this.cursorPos)+ return;+ let $pos = this.editorView.state.doc.resolve(this.cursorPos), rect;+ if (!$pos.parent.inlineContent) {+ let before = $pos.nodeBefore, after = $pos.nodeAfter;+ if (before || after) {+ const node = this.editorView.nodeDOM(this.cursorPos - (before ? before.nodeSize : 0));+ if (!node)+ return;+ let nodeRect = node.getBoundingClientRect();+ let top = before ? nodeRect.bottom : nodeRect.top;+ if (before && after) {+ const cursor = this.editorView.nodeDOM(this.cursorPos);+ if (!cursor)+ return;+ top = (top + cursor.getBoundingClientRect().top) / 2;+ }+ rect = {+ left: nodeRect.left,+ right: nodeRect.right,+ top: top - this.width / 2,+ bottom: top + this.width / 2,+ };+ }+ }+ if (!rect) {+ let coords = this.editorView.coordsAtPos(this.cursorPos);+ rect = {+ left: coords.left - this.width / 2,+ right: coords.left + this.width / 2,+ top: coords.top,+ bottom: coords.bottom,+ };+ }+ let parent = this.editorView.dom.offsetParent;+ if (!this.element && parent) {+ this.element = parent.appendChild(document.createElement("div"));+ if (this.class)+ this.element.className = this.class;+ this.element.style.cssText =+ "position: absolute; z-index: 50; pointer-events: none; background-color: " ++ this.color;+ }+ let parentLeft, parentTop;+ if (!parent ||+ (parent == document.body && getComputedStyle(parent).position == "static")) {+ parentLeft = -pageXOffset;+ parentTop = -pageYOffset;+ }+ else {+ let rect = parent.getBoundingClientRect();+ parentLeft = rect.left - parent.scrollLeft;+ parentTop = rect.top - parent.scrollTop;+ }+ if (!this.element)+ return;+ this.element.style.left = rect.left - parentLeft + "px";+ this.element.style.top = rect.top - parentTop + "px";+ this.element.style.width = rect.right - rect.left + "px";+ this.element.style.height = rect.bottom - rect.top + "px";+ }+ scheduleRemoval(timeout) {+ clearTimeout(this.timeout || undefined);+ this.timeout = (setTimeout(() => this.setCursor(null), timeout));+ }+ dragover(event) {+ if (!this.editorView.editable)+ return;+ let pos = this.editorView.posAtCoords({+ left: event.clientX,+ top: event.clientY,+ });+ let node = pos && pos.inside >= 0 && this.editorView.state.doc.nodeAt(pos.inside);+ let disableDropCursor = node && node.type.spec.disableDropCursor;+ let disabled = typeof disableDropCursor == "function"+ ? disableDropCursor(this.editorView, pos)+ : disableDropCursor;+ if (pos && !disabled) {+ let target = pos.pos;+ if (this.editorView.dragging && this.editorView.dragging.slice) {+ const point = dropPoint(this.editorView.state.doc, target, this.editorView.dragging.slice);+ if (!point)+ return this.setCursor(null);+ target = point;+ }+ this.setCursor(target);+ this.scheduleRemoval(5000);+ }+ }+ dragend() {+ this.scheduleRemoval(20);+ }+ drop() {+ this.scheduleRemoval(20);+ }+ dragleave(event) {+ if (event.target == this.editorView.dom ||+ !this.editorView.dom.contains(event.relatedTarget))+ this.setCursor(null);+ }+}diff --git a/packages/editor/dist/es/extensions/dropcursor/index.d.ts b/packages/editor/dist/es/extensions/dropcursor/index.d.tsnew file mode 100644index 000000000..8b3d7693d--- /dev/null+++ b/packages/editor/dist/es/extensions/dropcursor/index.d.ts@@ -0,0 +1,3 @@+import { Dropcursor } from "./drop-cursor";+export * from "./drop-cursor";+export default Dropcursor;diff --git a/packages/editor/dist/es/extensions/dropcursor/index.js b/packages/editor/dist/es/extensions/dropcursor/index.jsnew file mode 100644index 000000000..8b3d7693d--- /dev/null+++ b/packages/editor/dist/es/extensions/dropcursor/index.js@@ -0,0 +1,3 @@+import { Dropcursor } from "./drop-cursor";+export * from "./drop-cursor";+export default Dropcursor;diff --git a/packages/editor/dist/es/extensions/embed/component.d.ts b/packages/editor/dist/es/extensions/embed/component.d.tsnew file mode 100644index 000000000..65b1ee648--- /dev/null+++ b/packages/editor/dist/es/extensions/embed/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { EmbedAlignmentOptions, EmbedAttributes } from "./embed";+import { SelectionBasedReactNodeViewProps } from "../react";+export declare function EmbedComponent(props: SelectionBasedReactNodeViewProps<EmbedAttributes & EmbedAlignmentOptions>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/embed/component.js b/packages/editor/dist/es/extensions/embed/component.jsnew file mode 100644index 000000000..fc73d4d70--- /dev/null+++ b/packages/editor/dist/es/extensions/embed/component.js@@ -0,0 +1,64 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { Box, Flex } from "rebass";+import { Resizable } from "re-resizable";+import { useRef } from "react";+import { DesktopOnly } from "../../components/responsive";+import { ToolbarGroup } from "../../toolbar/components/toolbar-group";+export function EmbedComponent(props) {+ const { editor, updateAttributes, selected, node } = props;+ const embedRef = useRef();+ const { src, width, height, align } = node.attrs;+ return (_jsx(_Fragment, { children: _jsx(Box, Object.assign({ sx: {+ display: "flex",+ justifyContent: align === "center" ? "center" : align === "left" ? "start" : "end",+ } }, { children: _jsxs(Resizable, Object.assign({ enable: {+ bottom: editor.isEditable,+ left: editor.isEditable,+ right: editor.isEditable,+ top: editor.isEditable,+ bottomLeft: editor.isEditable,+ bottomRight: editor.isEditable,+ topLeft: editor.isEditable,+ topRight: editor.isEditable,+ }, size: {+ height: height || "auto",+ width: width || "auto",+ }, maxWidth: "100%", onResizeStop: (e, direction, ref, d) => {+ updateAttributes({+ width: ref.clientWidth,+ height: ref.clientHeight,+ });+ }, lockAspectRatio: true }, { children: [_jsx(Flex, Object.assign({ width: "100%", sx: {+ position: "relative",+ justifyContent: "end",+ borderTop: editor.isEditable+ ? "20px solid var(--bgSecondary)"+ : "none",+ borderTopLeftRadius: "default",+ borderTopRightRadius: "default",+ borderColor: selected ? "border" : "bgSecondary",+ cursor: "pointer",+ ":hover": {+ borderColor: "border",+ },+ } }, { children: _jsx(DesktopOnly, { children: selected && (_jsx(Flex, Object.assign({ sx: { position: "relative", justifyContent: "end" } }, { children: _jsx(Flex, Object.assign({ sx: {+ position: "absolute",+ top: -40,+ mb: 2,+ alignItems: "end",+ } }, { children: _jsx(ToolbarGroup, { editor: editor, tools: [+ "embedAlignLeft",+ "embedAlignCenter",+ "embedAlignRight",+ "embedProperties",+ ], sx: {+ boxShadow: "menu",+ borderRadius: "default",+ bg: "background",+ } }) })) }))) }) })), _jsx(Box, Object.assign({ as: "iframe", ref: embedRef, src: src, width: "100%", height: "100%", sx: {+ border: selected+ ? "2px solid var(--primary)"+ : "2px solid transparent",+ borderRadius: "default",+ } }, props))] })) })) }));+}diff --git a/packages/editor/dist/es/extensions/embed/embed.d.ts b/packages/editor/dist/es/extensions/embed/embed.d.tsnew file mode 100644index 000000000..969f00b5a--- /dev/null+++ b/packages/editor/dist/es/extensions/embed/embed.d.ts@@ -0,0 +1,29 @@+import { Node } from "@tiptap/core";+export interface EmbedOptions {+ HTMLAttributes: Record<string, any>;+}+export declare type EmbedAttributes = Partial<EmbedSizeOptions> & {+ src: string;+};+export declare type EmbedAlignmentOptions = {+ align?: "center" | "left" | "right";+};+export declare type Embed = Required<EmbedAttributes> & EmbedAlignmentOptions;+export declare type EmbedSizeOptions = {+ width: number;+ height: number;+};+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ embed: {+ /**+ * Add an embed+ */+ insertEmbed: (options: EmbedAttributes) => ReturnType;+ setEmbedAlignment: (options: EmbedAlignmentOptions) => ReturnType;+ setEmbedSize: (options: EmbedSizeOptions) => ReturnType;+ setEmbedSource: (src: string) => ReturnType;+ };+ }+}+export declare const EmbedNode: Node<EmbedOptions, any>;diff --git a/packages/editor/dist/es/extensions/embed/embed.js b/packages/editor/dist/es/extensions/embed/embed.jsnew file mode 100644index 000000000..934daaa04--- /dev/null+++ b/packages/editor/dist/es/extensions/embed/embed.js@@ -0,0 +1,62 @@+import { Node, mergeAttributes } from "@tiptap/core";+import { createSelectionBasedNodeView, } from "../react";+import { EmbedComponent } from "./component";+export const EmbedNode = Node.create({+ name: "embed",+ content: "",+ marks: "",+ draggable: true,+ addOptions() {+ return {+ HTMLAttributes: {},+ };+ },+ group() {+ return "block";+ },+ addAttributes() {+ return {+ src: {+ default: null,+ },+ width: { default: null },+ height: { default: null },+ align: { default: "left" },+ };+ },+ parseHTML() {+ return [+ {+ tag: "iframe[src]",+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "iframe",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),+ ];+ },+ addNodeView() {+ return createSelectionBasedNodeView(EmbedComponent);+ },+ addCommands() {+ return {+ insertEmbed: (options) => ({ commands }) => {+ return commands.insertContent({+ type: this.name,+ attrs: options,+ });+ },+ setEmbedAlignment: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ setEmbedSize: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ setEmbedSource: (src) => ({ commands }) => {+ return commands.updateAttributes(this.name, { src });+ },+ };+ },+});diff --git a/packages/editor/dist/es/extensions/embed/index.d.ts b/packages/editor/dist/es/extensions/embed/index.d.tsnew file mode 100644index 000000000..12b3c5295--- /dev/null+++ b/packages/editor/dist/es/extensions/embed/index.d.ts@@ -0,0 +1 @@+export * from "./embed";diff --git a/packages/editor/dist/es/extensions/embed/index.js b/packages/editor/dist/es/extensions/embed/index.jsnew file mode 100644index 000000000..12b3c5295--- /dev/null+++ b/packages/editor/dist/es/extensions/embed/index.js@@ -0,0 +1 @@+export * from "./embed";diff --git a/packages/editor/dist/es/extensions/fontsize/fontsize.d.ts b/packages/editor/dist/es/extensions/fontsize/fontsize.d.tsnew file mode 100644index 000000000..5725a7a40--- /dev/null+++ b/packages/editor/dist/es/extensions/fontsize/fontsize.d.ts@@ -0,0 +1,22 @@+import { Extension } from "@tiptap/core";+import "@tiptap/extension-text-style";+declare type FontSizeOptions = {+ types: string[];+ defaultFontSize: number;+};+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ fontSize: {+ /**+ * Set the font family+ */+ setFontSize: (fontSize: string) => ReturnType;+ /**+ * Unset the font family+ */+ unsetFontSize: () => ReturnType;+ };+ }+}+export declare const FontSize: Extension<FontSizeOptions, any>;+export {};diff --git a/packages/editor/dist/es/extensions/fontsize/fontsize.js b/packages/editor/dist/es/extensions/fontsize/fontsize.jsnew file mode 100644index 000000000..21d2c567c--- /dev/null+++ b/packages/editor/dist/es/extensions/fontsize/fontsize.js@@ -0,0 +1,43 @@+import { Extension } from "@tiptap/core";+import "@tiptap/extension-text-style";+export const FontSize = Extension.create({+ name: "fontSize",+ defaultOptions: {+ types: ["textStyle"],+ defaultFontSize: 16,+ },+ addGlobalAttributes() {+ return [+ {+ types: this.options.types,+ attributes: {+ fontSize: {+ default: `${this.options.defaultFontSize}px`,+ parseHTML: (element) => element.style.fontSize,+ renderHTML: (attributes) => {+ if (!attributes.fontSize) {+ return {};+ }+ return {+ style: `font-size: ${attributes.fontSize}`,+ };+ },+ },+ },+ },+ ];+ },+ addCommands() {+ return {+ setFontSize: (fontSize) => ({ chain }) => {+ return chain().setMark("textStyle", { fontSize }).run();+ },+ unsetFontSize: () => ({ chain }) => {+ return chain()+ .setMark("textStyle", { fontSize: null })+ .removeEmptyTextStyle()+ .run();+ },+ };+ },+});diff --git a/packages/editor/dist/es/extensions/fontsize/index.d.ts b/packages/editor/dist/es/extensions/fontsize/index.d.tsnew file mode 100644index 000000000..0424657fa--- /dev/null+++ b/packages/editor/dist/es/extensions/fontsize/index.d.ts@@ -0,0 +1,3 @@+import { FontSize } from "./font-size";+export * from "./font-size";+export default FontSize;diff --git a/packages/editor/dist/es/extensions/fontsize/index.js b/packages/editor/dist/es/extensions/fontsize/index.jsnew file mode 100644index 000000000..0424657fa--- /dev/null+++ b/packages/editor/dist/es/extensions/fontsize/index.js@@ -0,0 +1,3 @@+import { FontSize } from "./font-size";+export * from "./font-size";+export default FontSize;diff --git a/packages/editor/dist/es/extensions/image/component.d.ts b/packages/editor/dist/es/extensions/image/component.d.tsnew file mode 100644index 000000000..0ae7c84cd--- /dev/null+++ b/packages/editor/dist/es/extensions/image/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ImageAlignmentOptions, ImageAttributes } from "./image";+import { SelectionBasedReactNodeViewProps } from "../react";+export declare function ImageComponent(props: SelectionBasedReactNodeViewProps<ImageAttributes & ImageAlignmentOptions>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/image/component.js b/packages/editor/dist/es/extensions/image/component.jsnew file mode 100644index 000000000..9b1c5cff4--- /dev/null+++ b/packages/editor/dist/es/extensions/image/component.js@@ -0,0 +1,102 @@+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { Box, Flex, Image } from "rebass";+import { Resizable } from "re-resizable";+import { useEffect, useRef } from "react";+import { DesktopOnly } from "../../components/responsive";+import { ToolbarGroup } from "../../toolbar/components/toolbar-group";+export function ImageComponent(props) {+ const { editor, updateAttributes, node, selected } = props;+ const { src, alt, title, width, height, align, float } = node.attrs;+ const imageRef = useRef();+ useEffect(() => {+ (() => __awaiter(this, void 0, void 0, function* () {+ if (!imageRef.current || !src)+ return;+ imageRef.current.src = yield dataUriToBlobURL(src);+ }))();+ }, [src, imageRef]);+ return (_jsx(_Fragment, { children: _jsx(Box, Object.assign({ sx: {+ display: float ? "block" : "flex",+ justifyContent: float+ ? "stretch"+ : align === "center"+ ? "center"+ : align === "left"+ ? "start"+ : "end",+ ":hover .drag-handle, :active .drag-handle": {+ opacity: 1,+ },+ } }, { children: _jsxs(Resizable, Object.assign({ enable: {+ bottom: editor.isEditable,+ left: editor.isEditable,+ right: editor.isEditable,+ top: editor.isEditable,+ bottomLeft: editor.isEditable,+ bottomRight: editor.isEditable,+ topLeft: editor.isEditable,+ topRight: editor.isEditable,+ }, style: {+ position: "relative",+ float: float ? (align === "left" ? "left" : "right") : "none",+ }, size: {+ height: height || "auto",+ width: width || "auto",+ }, maxWidth: "100%", onResizeStop: (e, direction, ref, d) => {+ updateAttributes({+ width: ref.clientWidth,+ height: ref.clientHeight,+ });+ }, lockAspectRatio: true }, { children: [_jsx(Flex, Object.assign({ width: "100%", "data-drag-handle": true, draggable: true, sx: {+ position: "relative",+ justifyContent: "end",+ borderTop: editor.isEditable+ ? "20px solid var(--bgSecondary)"+ : "none",+ borderTopLeftRadius: "default",+ borderTopRightRadius: "default",+ borderColor: selected ? "border" : "bgSecondary",+ cursor: "pointer",+ ":hover": {+ borderColor: "border",+ },+ } }, { children: _jsx(DesktopOnly, { children: selected && (_jsx(Flex, Object.assign({ sx: { position: "relative", justifyContent: "end" } }, { children: _jsx(Flex, Object.assign({ sx: {+ position: "absolute",+ top: -40,+ mb: 2,+ alignItems: "end",+ } }, { children: _jsx(ToolbarGroup, { editor: editor, tools: [+ "imageAlignLeft",+ "imageAlignCenter",+ "imageAlignRight",+ "imageProperties",+ ], sx: {+ boxShadow: "menu",+ borderRadius: "default",+ bg: "background",+ } }) })) }))) }) })), _jsx(Image, Object.assign({ "data-drag-image": true, ref: imageRef, alt: alt, src: "/placeholder.svg", title: title, width: "100%", height: "100%", sx: {+ bg: "bgSecondary",+ border: selected+ ? "2px solid var(--primary)"+ : "2px solid transparent",+ borderRadius: "default",+ } }, props))] })) })) }));+}+function dataUriToBlobURL(dataurl) {+ return __awaiter(this, void 0, void 0, function* () {+ if (!dataurl.startsWith("data:image"))+ return dataurl;+ const response = yield fetch(dataurl);+ const blob = yield response.blob();+ return URL.createObjectURL(blob);+ });+}diff --git a/packages/editor/dist/es/extensions/image/image.d.ts b/packages/editor/dist/es/extensions/image/image.d.tsnew file mode 100644index 000000000..eb963ae33--- /dev/null+++ b/packages/editor/dist/es/extensions/image/image.d.ts@@ -0,0 +1,35 @@+import { Node } from "@tiptap/core";+import { Attachment } from "../attachment";+export interface ImageOptions {+ inline: boolean;+ allowBase64: boolean;+ HTMLAttributes: Record<string, any>;+}+export declare type ImageAttributes = Partial<ImageSizeOptions> & Partial<Attachment> & {+ src: string;+ alt?: string;+ title?: string;+};+export declare type ImageAlignmentOptions = {+ float?: boolean;+ align?: "center" | "left" | "right";+};+export declare type ImageSizeOptions = {+ width: number;+ height: number;+};+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ image: {+ /**+ * Add an image+ */+ insertImage: (options: ImageAttributes) => ReturnType;+ updateImage: (options: ImageAttributes) => ReturnType;+ setImageAlignment: (options: ImageAlignmentOptions) => ReturnType;+ setImageSize: (options: ImageSizeOptions) => ReturnType;+ };+ }+}+export declare const inputRegex: RegExp;+export declare const ImageNode: Node<ImageOptions, any>;diff --git a/packages/editor/dist/es/extensions/image/image.js b/packages/editor/dist/es/extensions/image/image.jsnew file mode 100644index 000000000..bc7d34b1d--- /dev/null+++ b/packages/editor/dist/es/extensions/image/image.js@@ -0,0 +1,106 @@+import { Node, nodeInputRule, mergeAttributes, findChildren, } from "@tiptap/core";+import { getDataAttribute } from "../attachment";+import { createSelectionBasedNodeView, } from "../react";+import { ImageComponent } from "./component";+export const inputRegex = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;+export const ImageNode = Node.create({+ name: "image",+ addOptions() {+ return {+ inline: false,+ allowBase64: false,+ HTMLAttributes: {},+ };+ },+ inline() {+ return this.options.inline;+ },+ group() {+ return this.options.inline ? "inline" : "block";+ },+ draggable: true,+ addAttributes() {+ return {+ src: {+ default: null,+ },+ alt: {+ default: null,+ },+ title: {+ default: null,+ },+ width: { default: null },+ height: { default: null },+ float: getDataAttribute("float", false),+ align: getDataAttribute("align", "left"),+ hash: getDataAttribute("hash"),+ filename: getDataAttribute("filename"),+ type: getDataAttribute("mime"),+ size: getDataAttribute("size"),+ };+ },+ parseHTML() {+ return [+ {+ tag: this.options.allowBase64 ? "img" : 'img:not([src^="data:"])',+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "img",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes),+ ];+ },+ addNodeView() {+ return createSelectionBasedNodeView(ImageComponent);+ },+ addCommands() {+ return {+ insertImage: (options) => ({ commands }) => {+ return commands.insertContent({+ type: this.name,+ attrs: options,+ });+ },+ setImageAlignment: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ setImageSize: (options) => ({ commands }) => {+ return commands.updateAttributes(this.name, Object.assign({}, options));+ },+ updateImage: (options) => ({ state, tr, dispatch }) => {+ const query = options.hash+ ? { key: "hash", value: options.hash }+ : options.src+ ? { key: "src", value: options.src }+ : null;+ if (!query)+ return false;+ const images = findChildren(state.doc, (node) => node.type.name === this.name &&+ node.attrs[query.key] === query.value);+ for (const image of images) {+ tr.setNodeMarkup(image.pos, image.node.type, Object.assign(Object.assign({}, image.node.attrs), options));+ }+ tr.setMeta("preventUpdate", true);+ tr.setMeta("addToHistory", false);+ if (dispatch)+ dispatch(tr);+ return true;+ },+ };+ },+ addInputRules() {+ return [+ nodeInputRule({+ find: inputRegex,+ type: this.type,+ getAttributes: (match) => {+ const [, , alt, src, title] = match;+ return { src, alt, title };+ },+ }),+ ];+ },+});diff --git a/packages/editor/dist/es/extensions/image/index.d.ts b/packages/editor/dist/es/extensions/image/index.d.tsnew file mode 100644index 000000000..0aa9b4bbd--- /dev/null+++ b/packages/editor/dist/es/extensions/image/index.d.ts@@ -0,0 +1 @@+export * from "./image";diff --git a/packages/editor/dist/es/extensions/image/index.js b/packages/editor/dist/es/extensions/image/index.jsnew file mode 100644index 000000000..0aa9b4bbd--- /dev/null+++ b/packages/editor/dist/es/extensions/image/index.js@@ -0,0 +1 @@+export * from "./image";diff --git a/packages/editor/dist/es/extensions/listitem/commands.d.ts b/packages/editor/dist/es/extensions/listitem/commands.d.tsnew file mode 100644index 000000000..7ff452b25--- /dev/null+++ b/packages/editor/dist/es/extensions/listitem/commands.d.ts@@ -0,0 +1,3 @@+import { NodeType } from "prosemirror-model";+import { Editor } from "@tiptap/core";+export declare function onBackspacePressed(editor: Editor, name: string, type: NodeType): boolean;diff --git a/packages/editor/dist/es/extensions/listitem/commands.js b/packages/editor/dist/es/extensions/listitem/commands.jsnew file mode 100644index 000000000..03d1c54aa--- /dev/null+++ b/packages/editor/dist/es/extensions/listitem/commands.js@@ -0,0 +1,54 @@+import { findParentNodeOfType, hasParentNodeOfType } from "prosemirror-utils";+// WORKAROUND: if we're at the start of a list item, we need to either+// backspace directly to an empty list item above, or outdent this node+export function onBackspacePressed(editor, name, type) {+ const { selection } = editor.state;+ const { empty, $from } = selection;+ if (!empty ||+ !isInside(name, type, editor.state) ||+ $from.parentOffset !== 0 ||+ !isFirstChildOfParent(editor.state) ||+ !editor.can().liftListItem(type))+ return false;+ const isEmpty = isListItemEmpty(type, editor.state);+ if (isFirstOfType(type, editor.state)) {+ return editor.commands.liftListItem(type);+ }+ else if (isEmpty)+ return editor.commands.deleteNode(type);+ else {+ // we have to run join backward twice because on the first join+ // the two list items are joined i.e., the editor just puts their+ // paragraphs next to each other. The next join merges the paragraphs+ // like it should be.+ return editor.chain().joinBackward().joinBackward().run();+ }+}+function isInside(name, type, state) {+ const { $from } = state.selection;+ let node = type || state.schema.nodes[name];+ const { paragraph } = state.schema.nodes;+ return (hasParentNodeOfType(node)(state.selection) &&+ $from.parent.type === paragraph);+}+function isFirstChildOfParent(state) {+ const { $from } = state.selection;+ return $from.depth > 1+ ? $from.parentOffset === 0 || $from.index($from.depth - 1) === 0+ : true;+}+const isFirstOfType = (type, state) => {+ const block = findParentNodeOfType(type)(state.selection);+ if (!block)+ return false;+ const { pos } = block;+ const resolved = state.doc.resolve(pos);+ return !resolved.nodeBefore;+};+function isListItemEmpty(type, state) {+ const block = findParentNodeOfType(type)(state.selection);+ if (!block)+ return false;+ const { node } = block;+ return !node.textContent.length;+}diff --git a/packages/editor/dist/es/extensions/listitem/index.d.ts b/packages/editor/dist/es/extensions/listitem/index.d.tsnew file mode 100644index 000000000..24950c4f2--- /dev/null+++ b/packages/editor/dist/es/extensions/listitem/index.d.ts@@ -0,0 +1 @@+export * from "./list-item";diff --git a/packages/editor/dist/es/extensions/listitem/index.js b/packages/editor/dist/es/extensions/listitem/index.jsnew file mode 100644index 000000000..24950c4f2--- /dev/null+++ b/packages/editor/dist/es/extensions/listitem/index.js@@ -0,0 +1 @@+export * from "./list-item";diff --git a/packages/editor/dist/es/extensions/listitem/listitem.d.ts b/packages/editor/dist/es/extensions/listitem/listitem.d.tsnew file mode 100644index 000000000..8160a725a--- /dev/null+++ b/packages/editor/dist/es/extensions/listitem/listitem.d.ts@@ -0,0 +1 @@+export declare const ListItem: import("@tiptap/core").Node<import("@tiptap/extension-list-item").ListItemOptions, any>;diff --git a/packages/editor/dist/es/extensions/listitem/listitem.js b/packages/editor/dist/es/extensions/listitem/listitem.jsnew file mode 100644index 000000000..1522092eb--- /dev/null+++ b/packages/editor/dist/es/extensions/listitem/listitem.js@@ -0,0 +1,8 @@+import { ListItem as TiptapListItem } from "@tiptap/extension-list-item";+import { onBackspacePressed } from "./commands";+export const ListItem = TiptapListItem.extend({+ addKeyboardShortcuts() {+ var _a;+ return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { Backspace: ({ editor }) => onBackspacePressed(editor, this.name, this.type) });+ },+});diff --git a/packages/editor/dist/es/extensions/math/index.d.ts b/packages/editor/dist/es/extensions/math/index.d.tsnew file mode 100644index 000000000..1331fdb01--- /dev/null+++ b/packages/editor/dist/es/extensions/math/index.d.ts@@ -0,0 +1,2 @@+export { MathInline } from "./math-inline";+export { MathBlock } from "./math-block";diff --git a/packages/editor/dist/es/extensions/math/index.js b/packages/editor/dist/es/extensions/math/index.jsnew file mode 100644index 000000000..1331fdb01--- /dev/null+++ b/packages/editor/dist/es/extensions/math/index.js@@ -0,0 +1,2 @@+export { MathInline } from "./math-inline";+export { MathBlock } from "./math-block";diff --git a/packages/editor/dist/es/extensions/math/mathblock.d.ts b/packages/editor/dist/es/extensions/math/mathblock.d.tsnew file mode 100644index 000000000..5c266e9e8--- /dev/null+++ b/packages/editor/dist/es/extensions/math/mathblock.d.ts@@ -0,0 +1,9 @@+import { Node } from "@tiptap/core";+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ mathBlock: {+ insertMathBlock: () => ReturnType;+ };+ }+}+export declare const MathBlock: Node<any, any>;diff --git a/packages/editor/dist/es/extensions/math/mathblock.js b/packages/editor/dist/es/extensions/math/mathblock.jsnew file mode 100644index 000000000..a041c7b47--- /dev/null+++ b/packages/editor/dist/es/extensions/math/mathblock.js@@ -0,0 +1,37 @@+import { Node, mergeAttributes } from "@tiptap/core";+import { inputRules } from "prosemirror-inputrules";+import { insertMathNode, makeBlockMathInputRule, REGEX_BLOCK_MATH_DOLLARS, } from "./plugin";+export const MathBlock = Node.create({+ name: "mathBlock",+ group: "block math",+ content: "text*",+ atom: true,+ code: true,+ parseHTML() {+ return [+ {+ tag: `div[class*='math-block']`, // important!+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "div",+ mergeAttributes({ class: "math-block math-node" }, HTMLAttributes),+ 0,+ ];+ },+ addCommands() {+ return {+ insertMathBlock: () => ({ state, dispatch, view }) => {+ return insertMathNode(this.type)(state, dispatch, view);+ },+ };+ },+ addProseMirrorPlugins() {+ const inputRulePlugin = inputRules({+ rules: [makeBlockMathInputRule(REGEX_BLOCK_MATH_DOLLARS, this.type)],+ });+ return [inputRulePlugin];+ },+});diff --git a/packages/editor/dist/es/extensions/math/mathinline.d.ts b/packages/editor/dist/es/extensions/math/mathinline.d.tsnew file mode 100644index 000000000..56a7ec49f--- /dev/null+++ b/packages/editor/dist/es/extensions/math/mathinline.d.ts@@ -0,0 +1,9 @@+import { Node } from "@tiptap/core";+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ mathInline: {+ insertMathInline: () => ReturnType;+ };+ }+}+export declare const MathInline: Node<any, any>;diff --git a/packages/editor/dist/es/extensions/math/mathinline.js b/packages/editor/dist/es/extensions/math/mathinline.jsnew file mode 100644index 000000000..731eb3d88--- /dev/null+++ b/packages/editor/dist/es/extensions/math/mathinline.js@@ -0,0 +1,38 @@+import { Node, mergeAttributes } from "@tiptap/core";+import { inputRules } from "prosemirror-inputrules";+import { makeInlineMathInputRule, REGEX_INLINE_MATH_DOLLARS, mathPlugin, insertMathNode, } from "./plugin";+export const MathInline = Node.create({+ name: "mathInline",+ group: "inline math",+ content: "text*",+ inline: true,+ atom: true,+ code: true,+ parseHTML() {+ return [+ {+ tag: "span[class*='math-inline']", // important!,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "span",+ mergeAttributes({ class: "math-inline math-node" }, HTMLAttributes),+ 0,+ ];+ },+ addCommands() {+ return {+ insertMathInline: () => ({ state, dispatch, view }) => {+ return insertMathNode(this.type)(state, dispatch, view);+ },+ };+ },+ addProseMirrorPlugins() {+ const inputRulePlugin = inputRules({+ rules: [makeInlineMathInputRule(REGEX_INLINE_MATH_DOLLARS, this.type)],+ });+ return [mathPlugin, inputRulePlugin];+ },+});diff --git a/packages/editor/dist/es/extensions/math/plugin/commands/collapsemathnode.d.ts b/packages/editor/dist/es/extensions/math/plugin/commands/collapsemathnode.d.tsnew file mode 100644index 000000000..a3210bd68--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/commands/collapsemathnode.d.ts@@ -0,0 +1,16 @@+import { Command } from "prosemirror-state";+import { EditorView } from "prosemirror-view";+/**+ * A ProseMirror command for determining whether to exit a math block, based on+ * specific conditions. Normally called when the user has+ *+ * @param outerView The main ProseMirror EditorView containing this math node.+ * @param dir Used to indicate desired cursor position upon closing a math node.+ * When set to -1, cursor will be placed BEFORE the math node.+ * When set to +1, cursor will be placed AFTER the math node.+ * @param borderMode An exit condition based on cursor position and direction.+ * @param requireEmptySelection When TRUE, only exit the math node when the+ * (inner) selection is empty.+ * @returns A new ProseMirror command based on the input configuration.+ */+export declare function collapseMathNode(outerView: EditorView, dir: 1 | -1, requireOnBorder: boolean, requireEmptySelection?: boolean): Command;diff --git a/packages/editor/dist/es/extensions/math/plugin/commands/collapsemathnode.js b/packages/editor/dist/es/extensions/math/plugin/commands/collapsemathnode.jsnew file mode 100644index 000000000..f9a6a9104--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/commands/collapsemathnode.js@@ -0,0 +1,50 @@+import { TextSelection } from "prosemirror-state";+/**+ * A ProseMirror command for determining whether to exit a math block, based on+ * specific conditions. Normally called when the user has+ *+ * @param outerView The main ProseMirror EditorView containing this math node.+ * @param dir Used to indicate desired cursor position upon closing a math node.+ * When set to -1, cursor will be placed BEFORE the math node.+ * When set to +1, cursor will be placed AFTER the math node.+ * @param borderMode An exit condition based on cursor position and direction.+ * @param requireEmptySelection When TRUE, only exit the math node when the+ * (inner) selection is empty.+ * @returns A new ProseMirror command based on the input configuration.+ */+export function collapseMathNode(outerView, dir, requireOnBorder, requireEmptySelection = true) {+ // create a new ProseMirror command based on the input conditions+ return (innerState, dispatch) => {+ // get selection info+ let outerState = outerView.state;+ let { to: outerTo, from: outerFrom } = outerState.selection;+ let { to: innerTo, from: innerFrom } = innerState.selection;+ // only exit math node when selection is empty+ if (requireEmptySelection && innerTo !== innerFrom) {+ return false;+ }+ let currentPos = dir > 0 ? innerTo : innerFrom;+ // when requireOnBorder is TRUE, collapse only when cursor+ // is about to leave the bounds of the math node+ if (requireOnBorder) {+ // (subtract two from nodeSize to account for start and end tokens)+ let nodeSize = innerState.doc.nodeSize - 2;+ // early return if exit conditions not met+ if (dir > 0 && currentPos < nodeSize) {+ return false;+ }+ if (dir < 0 && currentPos > 0) {+ return false;+ }+ }+ // all exit conditions met, so close the math node by moving the cursor outside+ if (dispatch) {+ // set outer selection to be outside of the nodeview+ let targetPos = dir > 0 ? outerTo : outerFrom;+ outerView.dispatch(outerState.tr.setSelection(TextSelection.create(outerState.doc, targetPos)));+ // must return focus to the outer view, otherwise no cursor will appear+ outerView.focus();+ }+ return true;+ };+}diff --git a/packages/editor/dist/es/extensions/math/plugin/commands/insertmathnode.d.ts b/packages/editor/dist/es/extensions/math/plugin/commands/insertmathnode.d.tsnew file mode 100644index 000000000..4d8ba65ba--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/commands/insertmathnode.d.ts@@ -0,0 +1,12 @@+import { Command } from "prosemirror-state";+import { NodeType } from "prosemirror-model";+/**+ * Returns a new command that can be used to inserts a new math node at the+ * user's current document position, provided that the document schema actually+ * allows a math node to be placed there.+ *+ * @param mathNodeType An instance for either your math_inline or math_display+ * NodeType. Must belong to the same schema that your EditorState uses!+ * @param initialText (optional) The initial source content for the math editor.+ */+export declare function insertMathNode(mathNodeType: NodeType, initialText?: string): Command;diff --git a/packages/editor/dist/es/extensions/math/plugin/commands/insertmathnode.js b/packages/editor/dist/es/extensions/math/plugin/commands/insertmathnode.jsnew file mode 100644index 000000000..c0722ccb5--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/commands/insertmathnode.js@@ -0,0 +1,26 @@+import { NodeSelection } from "prosemirror-state";+////////////////////////////////////////////////////////////////////////////////+/**+ * Returns a new command that can be used to inserts a new math node at the+ * user's current document position, provided that the document schema actually+ * allows a math node to be placed there.+ *+ * @param mathNodeType An instance for either your math_inline or math_display+ * NodeType. Must belong to the same schema that your EditorState uses!+ * @param initialText (optional) The initial source content for the math editor.+ */+export function insertMathNode(mathNodeType, initialText = "") {+ return function (state, dispatch) {+ let { $from } = state.selection, index = $from.index();+ if (!$from.parent.canReplaceWith(index, index, mathNodeType)) {+ return false;+ }+ if (dispatch) {+ let mathNode = mathNodeType.create({}, initialText ? state.schema.text(initialText) : null);+ let tr = state.tr.replaceSelectionWith(mathNode);+ tr = tr.setSelection(NodeSelection.create(tr.doc, $from.pos));+ dispatch(tr);+ }+ return true;+ };+}diff --git a/packages/editor/dist/es/extensions/math/plugin/commands/move-cursor-cmd.d.ts b/packages/editor/dist/es/extensions/math/plugin/commands/move-cursor-cmd.d.tsnew file mode 100644index 000000000..d1361e53e--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/commands/move-cursor-cmd.d.ts@@ -0,0 +1,10 @@+import { Command } from "prosemirror-state";+/**+ * Some browsers (cough firefox cough) don't properly handle cursor movement on+ * the edges of a NodeView, so we need to make the desired behavior explicit.+ *+ * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1252108+ */+export declare function nudgeCursorCmd(dir: -1 | 0 | 1): Command;+export declare const nudgeCursorForwardCmd: Command;+export declare const nudgeCursorBackCmd: Command;diff --git a/packages/editor/dist/es/extensions/math/plugin/commands/move-cursor-cmd.js b/packages/editor/dist/es/extensions/math/plugin/commands/move-cursor-cmd.jsnew file mode 100644index 000000000..057856064--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/commands/move-cursor-cmd.js@@ -0,0 +1,25 @@+import { TextSelection } from "prosemirror-state";+////////////////////////////////////////////////////////////////////////////////+/**+ * Some browsers (cough firefox cough) don't properly handle cursor movement on+ * the edges of a NodeView, so we need to make the desired behavior explicit.+ *+ * @see https://bugzilla.mozilla.org/show_bug.cgi?id=1252108+ */+export function nudgeCursorCmd(dir) {+ return (innerState, dispatch) => {+ let { to, from } = innerState.selection;+ // compute target position+ let emptySelection = to === from;+ let currentPos = dir < 0 ? from : to;+ let increment = emptySelection ? dir : 0;+ let nodeSize = innerState.doc.nodeSize;+ let targetPos = Math.max(0, Math.min(nodeSize, currentPos + increment));+ if (dispatch) {+ dispatch(innerState.tr.setSelection(TextSelection.create(innerState.doc, targetPos)));+ }+ return true;+ };+}+export const nudgeCursorForwardCmd = nudgeCursorCmd(+1);+export const nudgeCursorBackCmd = nudgeCursorCmd(-1);diff --git a/packages/editor/dist/es/extensions/math/plugin/index.d.ts b/packages/editor/dist/es/extensions/math/plugin/index.d.tsnew file mode 100644index 000000000..13e02011b--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/index.d.ts@@ -0,0 +1,9 @@+export { MathView, type ICursorPosObserver } from "./math-node-view";+export { mathPlugin, createMathView, type IMathPluginState, } from "./math-plugin";+export { mathSchemaSpec, createMathSchema } from "./math-schema";+export { mathBackspaceCmd } from "./plugins/math-backspace";+export { makeBlockMathInputRule, makeInlineMathInputRule, REGEX_BLOCK_MATH_DOLLARS, REGEX_INLINE_MATH_DOLLARS, REGEX_INLINE_MATH_DOLLARS_ESCAPED, } from "./plugins/math-input-rules";+export { mathSelectPlugin } from "./plugins/math-select";+export { insertMathNode } from "./commands/insert-math-node";+export { mathSerializer } from "./utils/text-serializer";+export * from "./utils/types";diff --git a/packages/editor/dist/es/extensions/math/plugin/index.js b/packages/editor/dist/es/extensions/math/plugin/index.jsnew file mode 100644index 000000000..bb3ad0ec5--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/index.js@@ -0,0 +1,18 @@+/*---------------------------------------------------------+ * Author: Benjamin R. Bray+ * License: MIT (see LICENSE in project root for details)+ *--------------------------------------------------------*/+// core functionality+export { MathView } from "./math-node-view";+export { mathPlugin, createMathView, } from "./math-plugin";+export { mathSchemaSpec, createMathSchema } from "./math-schema";+// recommended plugins+export { mathBackspaceCmd } from "./plugins/math-backspace";+export { makeBlockMathInputRule, makeInlineMathInputRule, REGEX_BLOCK_MATH_DOLLARS, REGEX_INLINE_MATH_DOLLARS, REGEX_INLINE_MATH_DOLLARS_ESCAPED, } from "./plugins/math-input-rules";+// optional / experimental plugins+export { mathSelectPlugin } from "./plugins/math-select";+// commands+export { insertMathNode } from "./commands/insert-math-node";+// utilities+export { mathSerializer } from "./utils/text-serializer";+export * from "./utils/types";diff --git a/packages/editor/dist/es/extensions/math/plugin/math-nodeview.d.ts b/packages/editor/dist/es/extensions/math/plugin/math-nodeview.d.tsnew file mode 100644index 000000000..9d1e9ae52--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/math-nodeview.d.ts@@ -0,0 +1,66 @@+import { Node as ProseNode } from "prosemirror-model";+import { EditorState, Transaction, PluginKey } from "prosemirror-state";+import { NodeView, EditorView, Decoration, DecorationSource } from "prosemirror-view";+import { IMathPluginState } from "./math-plugin";+import { MathRenderFn } from "./renderers/types";+export interface ICursorPosObserver {+ /** indicates on which side cursor should appear when this node is selected */+ cursorSide: "start" | "end";+ /** */+ updateCursorPos(state: EditorState): void;+}+interface IMathViewOptions {+ /** Dom element name to use for this NodeView */+ tagName?: string;+ /** Used to render the Tex input */+ renderer: MathRenderFn;+ /** Should be true if node is inline */+ className?: string;+}+export declare class MathView implements NodeView, ICursorPosObserver {+ private _node;+ private _outerView;+ private _getPos;+ dom: HTMLElement;+ private _mathRenderElt;+ private _mathSrcElt;+ private _innerView;+ cursorSide: "start" | "end";+ private _tagName;+ private _isEditing;+ private _mathPluginKey;+ private options;+ /**+ * @param onDestroy Callback for when this NodeView is destroyed.+ * This NodeView should unregister itself from the list of ICursorPosObservers.+ *+ * Math Views support the following options:+ * @option displayMode If TRUE, will render math in display mode, otherwise in inline mode.+ * @option tagName HTML tag name to use for this NodeView. If none is provided,+ * will use the node name with underscores converted to hyphens.+ */+ constructor(node: ProseNode, view: EditorView, getPos: () => number, options: IMathViewOptions, mathPluginKey: PluginKey<IMathPluginState>, onDestroy?: () => void);+ destroy(): void;+ /**+ * Ensure focus on the inner editor whenever this node has focus.+ * This helps to prevent accidental deletions of math blocks.+ */+ ensureFocus(): void;+ update(node: ProseNode, _decorations: readonly Decoration[], _innerDecorations: DecorationSource): boolean;+ updateCursorPos(state: EditorState): void;+ selectNode(): void;+ deselectNode(): void;+ stopEvent(event: Event): boolean;+ ignoreMutation(): boolean;+ renderMath(): void;+ dispatchInner(tr: Transaction): void;+ openEditor(): void;+ /**+ * Called when the inner ProseMirror editor should close.+ *+ * @param render Optionally update the rendered math after closing. (which+ * is generally what we want to do, since the user is done editing!)+ */+ closeEditor(render?: boolean): void;+}+export {};diff --git a/packages/editor/dist/es/extensions/math/plugin/math-nodeview.js b/packages/editor/dist/es/extensions/math/plugin/math-nodeview.jsnew file mode 100644index 000000000..5777aec1f--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/math-nodeview.js@@ -0,0 +1,275 @@+/*---------------------------------------------------------+ * Author: Benjamin R. Bray+ * License: MIT (see LICENSE in project root for details)+ *--------------------------------------------------------*/+import { EditorState, TextSelection, } from "prosemirror-state";+import { EditorView, } from "prosemirror-view";+import { StepMap } from "prosemirror-transform";+import { keymap } from "prosemirror-keymap";+import { newlineInCode, chainCommands, deleteSelection, } from "prosemirror-commands";+import { collapseMathNode } from "./commands/collapse-math-node";+export class MathView {+ // == Lifecycle ===================================== //+ /**+ * @param onDestroy Callback for when this NodeView is destroyed.+ * This NodeView should unregister itself from the list of ICursorPosObservers.+ *+ * Math Views support the following options:+ * @option displayMode If TRUE, will render math in display mode, otherwise in inline mode.+ * @option tagName HTML tag name to use for this NodeView. If none is provided,+ * will use the node name with underscores converted to hyphens.+ */+ constructor(node, view, getPos, options, mathPluginKey, onDestroy) {+ // store arguments+ this.options = options;+ this._node = node;+ this._outerView = view;+ this._getPos = getPos;+ this._mathPluginKey = mathPluginKey;+ // editing state+ this.cursorSide = "start";+ this._isEditing = false;+ // options+ this._tagName = options.tagName || this._node.type.name.replace("_", "-");+ // create dom representation of nodeview+ this.dom = document.createElement(this._tagName);+ if (options.className)+ this.dom.classList.add(options.className);+ this.dom.classList.add("math-node");+ this._mathRenderElt = document.createElement("span");+ this._mathRenderElt.textContent = "";+ this._mathRenderElt.classList.add("math-render");+ this.dom.appendChild(this._mathRenderElt);+ this._mathSrcElt = document.createElement("span");+ this._mathSrcElt.classList.add("math-src");+ this.dom.appendChild(this._mathSrcElt);+ // ensure+ this.dom.addEventListener("click", () => this.ensureFocus());+ // render initial content+ this.renderMath();+ }+ destroy() {+ // close the inner editor without rendering+ this.closeEditor(false);+ // clean up dom elements+ if (this._mathRenderElt) {+ this._mathRenderElt.remove();+ delete this._mathRenderElt;+ }+ if (this._mathSrcElt) {+ this._mathSrcElt.remove();+ delete this._mathSrcElt;+ }+ this.dom.remove();+ }+ /**+ * Ensure focus on the inner editor whenever this node has focus.+ * This helps to prevent accidental deletions of math blocks.+ */+ ensureFocus() {+ if (this._innerView && this._outerView.hasFocus()) {+ this._innerView.focus();+ }+ }+ // == Updates ======================================= //+ update(node, _decorations, _innerDecorations) {+ if (!node.sameMarkup(this._node))+ return false;+ this._node = node;+ if (this._innerView) {+ let state = this._innerView.state;+ let start = node.content.findDiffStart(state.doc.content);+ if (start != null) {+ let diff = node.content.findDiffEnd(state.doc.content);+ if (diff) {+ let { a: endA, b: endB } = diff;+ let overlap = start - Math.min(endA, endB);+ if (overlap > 0) {+ endA += overlap;+ endB += overlap;+ }+ this._innerView.dispatch(state.tr+ .replace(start, endB, node.slice(start, endA))+ .setMeta("fromOutside", true));+ }+ }+ }+ if (!this._isEditing) {+ this.renderMath();+ }+ return true;+ }+ updateCursorPos(state) {+ const pos = this._getPos();+ const size = this._node.nodeSize;+ const inPmSelection = state.selection.from < pos + size && pos < state.selection.to;+ if (!inPmSelection) {+ this.cursorSide = pos < state.selection.from ? "end" : "start";+ }+ }+ // == Events ===================================== //+ selectNode() {+ if (!this._outerView.editable) {+ return;+ }+ this.dom.classList.add("ProseMirror-selectednode");+ if (!this._isEditing) {+ this.openEditor();+ }+ }+ deselectNode() {+ this.dom.classList.remove("ProseMirror-selectednode");+ if (this._isEditing) {+ this.closeEditor();+ }+ }+ stopEvent(event) {+ return (this._innerView !== undefined &&+ event.target !== undefined &&+ this._innerView.dom.contains(event.target));+ }+ ignoreMutation() {+ return true;+ }+ // == Rendering ===================================== //+ renderMath() {+ if (!this._mathRenderElt) {+ return;+ }+ // get tex string to render+ let content = this._node.content.content;+ let texString = "";+ if (content.length > 0 && content[0].textContent !== null) {+ texString = content[0].textContent.trim();+ }+ // empty math?+ if (texString.length < 1) {+ this.dom.classList.add("empty-math");+ // clear rendered math, since this node is in an invalid state+ while (this._mathRenderElt.firstChild) {+ this._mathRenderElt.firstChild.remove();+ }+ // do not render empty math+ return;+ }+ else {+ this.dom.classList.remove("empty-math");+ }+ // render katex, but fail gracefully+ try {+ this.options.renderer(texString, this._mathRenderElt);+ this._mathRenderElt.classList.remove("parse-error");+ this.dom.setAttribute("title", "");+ }+ catch (err) {+ if (err instanceof Error) {+ console.error(err);+ this._mathRenderElt.classList.add("parse-error");+ this.dom.setAttribute("title", err.toString());+ }+ }+ }+ // == Inner Editor ================================== //+ dispatchInner(tr) {+ if (!this._innerView) {+ return;+ }+ let { state, transactions } = this._innerView.state.applyTransaction(tr);+ this._innerView.updateState(state);+ if (!tr.getMeta("fromOutside")) {+ let outerTr = this._outerView.state.tr, offsetMap = StepMap.offset(this._getPos() + 1);+ for (let i = 0; i < transactions.length; i++) {+ let steps = transactions[i].steps;+ for (let j = 0; j < steps.length; j++) {+ let mapped = steps[j].map(offsetMap);+ if (!mapped) {+ throw Error("step discarded!");+ }+ outerTr.step(mapped);+ }+ }+ if (outerTr.docChanged)+ this._outerView.dispatch(outerTr);+ }+ }+ openEditor() {+ var _a;+ if (this._innerView) {+ throw Error("inner view should not exist!");+ }+ if (!this._mathSrcElt)+ throw new Error("_mathSrcElt does not exist!");+ // create a nested ProseMirror view+ this._innerView = new EditorView(this._mathSrcElt, {+ state: EditorState.create({+ doc: this._node,+ plugins: [+ keymap({+ Tab: (state, dispatch) => {+ if (dispatch) {+ dispatch(state.tr.insertText("\t"));+ }+ return true;+ },+ Backspace: chainCommands(deleteSelection, (state, dispatch, tr_inner) => {+ // default backspace behavior for non-empty selections+ if (!state.selection.empty) {+ return false;+ }+ // default backspace behavior when math node is non-empty+ if (this._node.textContent.length > 0) {+ return false;+ }+ // otherwise, we want to delete the empty math node and focus the outer view+ this._outerView.dispatch(this._outerView.state.tr.insertText(""));+ this._outerView.focus();+ return true;+ }),+ // "Ctrl-Backspace": (state, dispatch, tr_inner) => {+ // // delete math node and focus the outer view+ // this._outerView.dispatch(this._outerView.state.tr.insertText(""));+ // this._outerView.focus();+ // return true;+ // },+ Enter: chainCommands(newlineInCode, collapseMathNode(this._outerView, +1, false)),+ "Ctrl-Enter": collapseMathNode(this._outerView, +1, false),+ ArrowLeft: collapseMathNode(this._outerView, -1, true),+ ArrowRight: collapseMathNode(this._outerView, +1, true),+ ArrowUp: collapseMathNode(this._outerView, -1, true),+ ArrowDown: collapseMathNode(this._outerView, +1, true),+ }),+ ],+ }),+ dispatchTransaction: this.dispatchInner.bind(this),+ });+ // focus element+ let innerState = this._innerView.state;+ this._innerView.focus();+ // request outer cursor position before math node was selected+ let maybePos = (_a = this._mathPluginKey.getState(this._outerView.state)) === null || _a === void 0 ? void 0 : _a.prevCursorPos;+ if (maybePos === null || maybePos === undefined) {+ console.error("[prosemirror-math] Error: Unable to fetch math plugin state from key.");+ }+ let prevCursorPos = maybePos !== null && maybePos !== void 0 ? maybePos : 0;+ // compute position that cursor should appear within the expanded math node+ let innerPos = prevCursorPos <= this._getPos() ? 0 : this._node.nodeSize - 2;+ this._innerView.dispatch(innerState.tr.setSelection(TextSelection.create(innerState.doc, innerPos)));+ this._isEditing = true;+ }+ /**+ * Called when the inner ProseMirror editor should close.+ *+ * @param render Optionally update the rendered math after closing. (which+ * is generally what we want to do, since the user is done editing!)+ */+ closeEditor(render = true) {+ if (this._innerView) {+ this._innerView.destroy();+ this._innerView = undefined;+ }+ if (render) {+ this.renderMath();+ }+ this._isEditing = false;+ }+}diff --git a/packages/editor/dist/es/extensions/math/plugin/math-plugin.d.ts b/packages/editor/dist/es/extensions/math/plugin/math-plugin.d.tsnew file mode 100644index 000000000..b7bd86a3f--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/math-plugin.d.ts@@ -0,0 +1,24 @@+import { Node as ProseNode } from "prosemirror-model";+import { Plugin as ProsePlugin } from "prosemirror-state";+import { MathView } from "./math-node-view";+import { EditorView } from "prosemirror-view";+export interface IMathPluginState {+ macros: {+ [cmd: string]: string;+ };+ /** A list of currently active `NodeView`s, in insertion order. */+ activeNodeViews: MathView[];+ /**+ * Used to determine whether to place the cursor in the front- or back-most+ * position when expanding a math node, without overriding the default arrow+ * key behavior.+ */+ prevCursorPos: number;+}+/**+ * Returns a function suitable for passing as a field in `EditorProps.nodeViews`.+ * @param inline TRUE for block math, FALSE for inline math.+ * @see https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews+ */+export declare function createMathView(inline: boolean): (node: ProseNode, view: EditorView, getPos: boolean | (() => number)) => MathView;+export declare const mathPlugin: ProsePlugin<IMathPluginState>;diff --git a/packages/editor/dist/es/extensions/math/plugin/math-plugin.js b/packages/editor/dist/es/extensions/math/plugin/math-plugin.jsnew file mode 100644index 000000000..76c19e5be--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/math-plugin.js@@ -0,0 +1,71 @@+/*---------------------------------------------------------+ * Author: Benjamin R. Bray+ * License: MIT (see LICENSE in project root for details)+ *--------------------------------------------------------*/+import { Plugin as ProsePlugin, PluginKey, } from "prosemirror-state";+import { MathView } from "./math-node-view";+import { KatexRenderer } from "./renderers/katex";+// uniquely identifies the prosemirror-math plugin+const MATH_PLUGIN_KEY = new PluginKey("prosemirror-math");+/**+ * Returns a function suitable for passing as a field in `EditorProps.nodeViews`.+ * @param inline TRUE for block math, FALSE for inline math.+ * @see https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews+ */+export function createMathView(inline) {+ return (node, view, getPos) => {+ /** @todo is this necessary?+ * Docs says that for any function proprs, the current plugin instance+ * will be bound to `this`. However, the typings don't reflect this.+ */+ let pluginState = MATH_PLUGIN_KEY.getState(view.state);+ if (!pluginState) {+ throw new Error("no math plugin!");+ }+ let nodeViews = pluginState.activeNodeViews;+ // set up NodeView+ let nodeView = new MathView(node, view, getPos, {+ className: inline ? "math-inline" : "math-block",+ renderer: inline ? KatexRenderer.inline : KatexRenderer.block,+ tagName: inline ? "span" : "div",+ }, MATH_PLUGIN_KEY, () => {+ nodeViews.splice(nodeViews.indexOf(nodeView));+ });+ nodeViews.push(nodeView);+ return nodeView;+ };+}+let mathPluginSpec = {+ key: MATH_PLUGIN_KEY,+ state: {+ init(config, instance) {+ return {+ macros: {},+ activeNodeViews: [],+ prevCursorPos: 0,+ };+ },+ apply(tr, value, oldState, newState) {+ // produce updated state field for this plugin+ const newPos = newState.selection.from;+ const oldPos = oldState.selection.from;+ return {+ // these values are left unchanged+ activeNodeViews: value.activeNodeViews,+ macros: value.macros,+ // update with the second-most recent cursor pos+ prevCursorPos: oldPos !== newPos ? oldPos : value.prevCursorPos,+ };+ },+ /** @todo (8/21/20) implement serialization for math plugin */+ // toJSON(value) { },+ // fromJSON(config, value, state){ return {}; }+ },+ props: {+ nodeViews: {+ mathInline: createMathView(true),+ mathBlock: createMathView(false),+ },+ },+};+export const mathPlugin = new ProsePlugin(mathPluginSpec);diff --git a/packages/editor/dist/es/extensions/math/plugin/math-schema.d.ts b/packages/editor/dist/es/extensions/math/plugin/math-schema.d.tsnew file mode 100644index 000000000..1bf09c98a--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/math-schema.d.ts@@ -0,0 +1,45 @@+import { MarkSpec, NodeSpec, Schema, SchemaSpec } from "prosemirror-model";+import { SchemaSpecMarkT, SchemaSpecNodeT } from "./utils/types";+/**+ * Borrowed from ProseMirror typings, modified to exclude OrderedMaps in spec,+ * in order to help with the schema-building functions below.+ *+ * NOTE: TypeScript's typings for the spread operator { ...a, ...b } are only+ * an approximation to the true type, and have difficulty with optional fields.+ * So, unlike the SchemaSpec type, the `marks` field is NOT optional here.+ *+ * function example<T extends string>(x: { [name in T]: string; } | null) {+ * const s = { ...x }; // inferred to have type `{}`.+ * }+ *+ * @see https://github.com/microsoft/TypeScript/issues/10727+ */+interface SchemaSpecJson<N extends string = any, M extends string = any> extends SchemaSpec<N, M> {+ nodes: {+ [name in N]: NodeSpec;+ };+ marks: {+ [name in M]: MarkSpec;+ };+ topNode?: string;+}+declare type MathSpecNodeT = SchemaSpecNodeT<typeof mathSchemaSpec>;+declare type MathSpecMarkT = SchemaSpecMarkT<typeof mathSchemaSpec>;+export declare const mathSchemaSpec: SchemaSpecJson<"paragraph" | "text" | "doc" | "math_inline" | "math_display", "math_select">;+/**+ * Use the prosemirror-math default SchemaSpec to create a new Schema.+ */+export declare function createMathSchema(): Schema<"paragraph" | "text" | "doc" | "math_inline" | "math_display", "math_select">;+/**+ * Create a new SchemaSpec by adding math nodes to an existing spec.++ * @deprecated This function is included for demonstration/testing only. For the+ * time being, I highly recommend adding the math nodes manually to your own+ * ProseMirror spec to avoid unexpected interactions between the math nodes+ * and your own spec. Use the example spec for reference.+ *+ * @param baseSpec The SchemaSpec to extend. Must specify a `marks` field, and+ * must be a raw object (not an OrderedMap).+ */+export declare function extendMathSchemaSpec<N extends string, M extends string>(baseSpec: SchemaSpecJson<N, M>): SchemaSpecJson<N | MathSpecNodeT, M | MathSpecMarkT>;+export {};diff --git a/packages/editor/dist/es/extensions/math/plugin/math-schema.js b/packages/editor/dist/es/extensions/math/plugin/math-schema.jsnew file mode 100644index 000000000..b844a7eec--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/math-schema.js@@ -0,0 +1,78 @@+/*---------------------------------------------------------+ * Author: Benjamin R. Bray+ * License: MIT (see LICENSE in project root for details)+ *--------------------------------------------------------*/+// prosemirror imports+import { Schema, } from "prosemirror-model";+import { defaultBlockMathParseRules, defaultInlineMathParseRules, } from "./plugins/math-paste-rules";+////////////////////////////////////////////////////////////+// force typescript to infer generic type arguments for SchemaSpec+function createSchemaSpec(spec) {+ return spec;+}+// bare minimum ProseMirror schema for working with math nodes+export const mathSchemaSpec = createSchemaSpec({+ nodes: {+ // :: NodeSpec top-level document node+ doc: {+ content: "block+",+ },+ paragraph: {+ content: "inline*",+ group: "block",+ parseDOM: [{ tag: "p" }],+ toDOM() {+ return ["p", 0];+ },+ },+ math_inline: {+ group: "inline math",+ content: "text*",+ inline: true,+ atom: true,+ toDOM: () => ["math-inline", { class: "math-node" }, 0],+ parseDOM: [{ tag: "math-inline" }, ...defaultInlineMathParseRules],+ },+ math_display: {+ group: "block math",+ content: "text*",+ atom: true,+ code: true,+ toDOM: () => ["math-display", { class: "math-node" }, 0],+ parseDOM: [{ tag: "math-display" }, ...defaultBlockMathParseRules],+ },+ text: {+ group: "inline",+ },+ },+ marks: {+ math_select: {+ toDOM() {+ return ["math-select", 0];+ },+ parseDOM: [{ tag: "math-select" }],+ },+ },+});+/**+ * Use the prosemirror-math default SchemaSpec to create a new Schema.+ */+export function createMathSchema() {+ return new Schema(mathSchemaSpec);+}+/**+ * Create a new SchemaSpec by adding math nodes to an existing spec.++ * @deprecated This function is included for demonstration/testing only. For the+ * time being, I highly recommend adding the math nodes manually to your own+ * ProseMirror spec to avoid unexpected interactions between the math nodes+ * and your own spec. Use the example spec for reference.+ *+ * @param baseSpec The SchemaSpec to extend. Must specify a `marks` field, and+ * must be a raw object (not an OrderedMap).+ */+export function extendMathSchemaSpec(baseSpec) {+ let nodes = Object.assign(Object.assign({}, baseSpec.nodes), mathSchemaSpec.nodes);+ let marks = Object.assign(Object.assign({}, baseSpec.marks), mathSchemaSpec.marks);+ return { nodes, marks, topNode: baseSpec.topNode };+}diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-backspace.d.ts b/packages/editor/dist/es/extensions/math/plugin/plugins/math-backspace.d.tsnew file mode 100644index 000000000..634f31931--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-backspace.d.ts@@ -0,0 +1,2 @@+import { Command as ProseCommand } from "prosemirror-state";+export declare const mathBackspaceCmd: ProseCommand;diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-backspace.js b/packages/editor/dist/es/extensions/math/plugin/plugins/math-backspace.jsnew file mode 100644index 000000000..7fe2ab4a8--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-backspace.js@@ -0,0 +1,25 @@+import { NodeSelection } from "prosemirror-state";+export const mathBackspaceCmd = (state, dispatch) => {+ // check node before+ let { $from } = state.selection;+ let nodeBefore = $from.nodeBefore;+ if (!nodeBefore) {+ return false;+ }+ if (nodeBefore.type.name == "math_inline") {+ // select math node+ let index = $from.index($from.depth);+ let $beforePos = state.doc.resolve($from.posAtIndex(index - 1));+ if (dispatch) {+ dispatch(state.tr.setSelection(new NodeSelection($beforePos)));+ }+ return true;+ }+ else if (nodeBefore.type.name == "math_block") {+ /** @todo (8/1/20) implement backspace for math blocks+ * check how code blocks behave when pressing backspace+ */+ return false;+ }+ return false;+};diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-inputrules.d.ts b/packages/editor/dist/es/extensions/math/plugin/plugins/math-inputrules.d.tsnew file mode 100644index 000000000..92f1be7e5--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-inputrules.d.ts@@ -0,0 +1,7 @@+import { InputRule } from "prosemirror-inputrules";+import { NodeType } from "prosemirror-model";+export declare const REGEX_INLINE_MATH_DOLLARS: RegExp;+export declare const REGEX_INLINE_MATH_DOLLARS_ESCAPED: RegExp;+export declare const REGEX_BLOCK_MATH_DOLLARS: RegExp;+export declare function makeInlineMathInputRule(pattern: RegExp, nodeType: NodeType, getAttrs?: (match: string[]) => any): InputRule;+export declare function makeBlockMathInputRule(pattern: RegExp, nodeType: NodeType, getAttrs?: (match: string[]) => any): InputRule;diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-inputrules.js b/packages/editor/dist/es/extensions/math/plugin/plugins/math-inputrules.jsnew file mode 100644index 000000000..b0811ef69--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-inputrules.js@@ -0,0 +1,55 @@+/*---------------------------------------------------------+ * Author: Benjamin R. Bray+ * License: MIT (see LICENSE in project root for details)+ *--------------------------------------------------------*/+import { InputRule } from "prosemirror-inputrules";+import { NodeSelection } from "prosemirror-state";+////////////////////////////////////////////////////////////+// ---- Inline Input Rules ------------------------------ //+// simple input rule for inline math+export const REGEX_INLINE_MATH_DOLLARS = /\$\$(.+)\$\$/; //new RegExp("\$(.+)\$", "i");+// negative lookbehind regex notation allows for escaped \$ delimiters+// (requires browser supporting ECMA2018 standard -- currently only Chrome / FF)+// (see https://javascript.info/regexp-lookahead-lookbehind)+export const REGEX_INLINE_MATH_DOLLARS_ESCAPED = (() => {+ // attempt to create regex with negative lookbehind+ try {+ return new RegExp("(?<!\\\\)\\$(.+)(?<!\\\\)\\$");+ }+ catch (e) {+ return REGEX_INLINE_MATH_DOLLARS;+ }+})();+// ---- Block Input Rules ------------------------------- //+// simple inputrule for block math+export const REGEX_BLOCK_MATH_DOLLARS = /\$\$\$\s+$/; //new RegExp("\$\$\s+$", "i");+////////////////////////////////////////////////////////////+export function makeInlineMathInputRule(pattern, nodeType, getAttrs) {+ return new InputRule(pattern, (state, match, start, end) => {+ let $start = state.doc.resolve(start);+ let index = $start.index();+ let $end = state.doc.resolve(end);+ // get attrs+ let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;+ // check if replacement valid+ if (!$start.parent.canReplaceWith(index, $end.index(), nodeType)) {+ return null;+ }+ // perform replacement+ return state.tr.replaceRangeWith(start, end, nodeType.create(attrs, nodeType.schema.text(match[1])));+ });+}+export function makeBlockMathInputRule(pattern, nodeType, getAttrs) {+ return new InputRule(pattern, (state, match, start, end) => {+ let $start = state.doc.resolve(start);+ let attrs = getAttrs instanceof Function ? getAttrs(match) : getAttrs;+ if (!$start+ .node(-1)+ .canReplaceWith($start.index(-1), $start.indexAfter(-1), nodeType))+ return null;+ let tr = state.tr+ .delete(start, end)+ .setBlockType(start, start, nodeType, attrs);+ return tr.setSelection(NodeSelection.create(tr.doc, tr.mapping.map($start.pos - 1)));+ });+}diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-paste-rules.d.ts b/packages/editor/dist/es/extensions/math/plugin/plugins/math-paste-rules.d.tsnew file mode 100644index 000000000..f6fb45c04--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-paste-rules.d.ts@@ -0,0 +1,56 @@+/**+ * Note that for some of the `ParseRule`s defined below,+ * we define a `getAttrs` function, which, other than+ * defining node attributes, can be used to describe complex+ * match conditions for a rule.++ * Returning `false` from `ParseRule.getAttrs` prevents the+ * rule from matching, while returning `null` indicates that+ * the default set of note attributes should be used.+ */+import { ParseRule } from "prosemirror-model";+/**+ * Wikipedia formats block math inside a <dl>...</dl> element, as below.+ *+ * - Evidently no CSS class is used to distinguish inline vs block math+ * - Sometimes the `\displaystyle` TeX command is present even in inline math+ *+ * ```html+ * <dl><dd><span class="mwe-math-element">+ * <span class="mwe-math-mathml-inline mwe-math-mathml-ally" style="...">+ * <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">+ * <semantics>+ * <mrow class="MJX-TeXAtom-ORD">...</mrow>+ * <annotation encoding="application/x-tex">...</annotation>+ * </semantics>+ * </math>+ * <img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/..."+ * class="mwe-math-fallback-image-inline"+ * alt="..." />+ * </span>+ * </span></dd></dl>+ * ```+ */+export declare const wikipediaBlockMathParseRule: ParseRule;+/**+ * Parse rule for inline math content on Wikipedia of the following form:+ *+ * ```html+ * <span class="mwe-math-element">+ * <span class="mwe-math-mathml-inline mwe-math-mathml-ally" style="...">+ * <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">+ * <semantics>+ * <mrow class="MJX-TeXAtom-ORD">...</mrow>+ * <annotation encoding="application/x-tex">...</annotation>+ * </semantics>+ * </math>+ * <img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/..."+ * class="mwe-math-fallback-image-inline"+ * alt="..." />+ * </span>+ * </span>+ * ```+ */+export declare const wikipediaInlineMathParseRule: ParseRule;+export declare const defaultInlineMathParseRules: ParseRule[];+export declare const defaultBlockMathParseRules: ParseRule[];diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-paste-rules.js b/packages/editor/dist/es/extensions/math/plugin/plugins/math-paste-rules.jsnew file mode 100644index 000000000..007203e1f--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-paste-rules.js@@ -0,0 +1,171 @@+/**+ * Note that for some of the `ParseRule`s defined below,+ * we define a `getAttrs` function, which, other than+ * defining node attributes, can be used to describe complex+ * match conditions for a rule.++ * Returning `false` from `ParseRule.getAttrs` prevents the+ * rule from matching, while returning `null` indicates that+ * the default set of note attributes should be used.+ */+import { Fragment, } from "prosemirror-model";+////////////////////////////////////////////////////////////+function getFirstMatch(root, rules) {+ for (let rule of rules) {+ let match = rule(root);+ if (match !== false) {+ return match;+ }+ }+ return false;+}+function makeTextFragment(text, schema) {+ return Fragment.from(schema.text(text));+}+////////////////////////////////////////////////////////////+// -- Wikipedia ----------------------------------------- //+/**+ * Look for a child node that matches the following template:+ * <img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/..."+ * class="mwe-math-fallback-image-inline"+ * alt="..." />+ */+function texFromMediaWikiFallbackImage(root) {+ var _a;+ let match = root.querySelector("img.mwe-math-fallback-image-inline[alt]");+ return (_a = match === null || match === void 0 ? void 0 : match.getAttribute("alt")) !== null && _a !== void 0 ? _a : false;+}+/**+ * Look for a child node that matches the following template:+ * <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">+ */+function texFromMathML_01(root) {+ var _a;+ let match = root.querySelector("math[alttext]");+ return (_a = match === null || match === void 0 ? void 0 : match.getAttribute("alttext")) !== null && _a !== void 0 ? _a : false;+}+/**+ * Look for a child node that matches the following template:+ * <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">+ */+function texFromMathML_02(root) {+ var _a;+ let match = root.querySelector("math annotation[encoding='application/x-tex'");+ return (_a = match === null || match === void 0 ? void 0 : match.textContent) !== null && _a !== void 0 ? _a : false;+}+/**+ * Look for a child node that matches the following template:+ * <script type="math/tex"></script>+ */+function texFromScriptTag(root) {+ var _a;+ let match = root.querySelector("script[type*='math/tex']");+ return (_a = match === null || match === void 0 ? void 0 : match.textContent) !== null && _a !== void 0 ? _a : false;+}+function matchWikipedia(root) {+ let match = getFirstMatch(root, [+ texFromMediaWikiFallbackImage,+ texFromMathML_01,+ texFromMathML_02,+ ]);+ // TODO: if no tex string was found, but we have MathML, try to parse it+ return match;+}+/**+ * Wikipedia formats block math inside a <dl>...</dl> element, as below.+ *+ * - Evidently no CSS class is used to distinguish inline vs block math+ * - Sometimes the `\displaystyle` TeX command is present even in inline math+ *+ * ```html+ * <dl><dd><span class="mwe-math-element">+ * <span class="mwe-math-mathml-inline mwe-math-mathml-ally" style="...">+ * <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">+ * <semantics>+ * <mrow class="MJX-TeXAtom-ORD">...</mrow>+ * <annotation encoding="application/x-tex">...</annotation>+ * </semantics>+ * </math>+ * <img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/..."+ * class="mwe-math-fallback-image-inline"+ * alt="..." />+ * </span>+ * </span></dd></dl>+ * ```+ */+export const wikipediaBlockMathParseRule = {+ tag: "dl",+ getAttrs(p) {+ let dl = p;+ // <dl> must contain exactly one child+ if (dl.childElementCount !== 1) {+ return false;+ }+ let dd = dl.firstChild;+ if (dd.tagName !== "DD") {+ return false;+ }+ // <dd> must contain exactly one child+ if (dd.childElementCount !== 1) {+ return false;+ }+ let mweElt = dd.firstChild;+ if (!mweElt.classList.contains("mwe-math-element")) {+ return false;+ }+ // success! proceed to `getContent` for further processing+ return null;+ },+ getContent(p, schema) {+ // search the matched element for a TeX string+ let match = matchWikipedia(p);+ // return a fragment representing the math node's children+ let texString = match || "\\text{\\color{red}(paste error)}";+ return makeTextFragment(texString, schema);+ },+};+/**+ * Parse rule for inline math content on Wikipedia of the following form:+ *+ * ```html+ * <span class="mwe-math-element">+ * <span class="mwe-math-mathml-inline mwe-math-mathml-ally" style="...">+ * <math xmlns="http://www.w3.org/1998/Math/MathML" alttext="...">+ * <semantics>+ * <mrow class="MJX-TeXAtom-ORD">...</mrow>+ * <annotation encoding="application/x-tex">...</annotation>+ * </semantics>+ * </math>+ * <img src="https://wikimedia.org/api/rest_v1/media/math/render/svg/..."+ * class="mwe-math-fallback-image-inline"+ * alt="..." />+ * </span>+ * </span>+ * ```+ */+export const wikipediaInlineMathParseRule = {+ tag: "span",+ getAttrs(p) {+ let span = p;+ if (!span.classList.contains("mwe-math-element")) {+ return false;+ }+ // success! proceed to `getContent` for further processing+ return null;+ },+ getContent(p, schema) {+ // search the matched element for a TeX string+ let match = matchWikipedia(p);+ // return a fragment representing the math node's children+ let texString = match || "\\text{\\color{red}(paste error)}";+ return makeTextFragment(texString, schema);+ },+};+// -- MathJax ------------------------------------------- //+////////////////////////////////////////////////////////////+export const defaultInlineMathParseRules = [+ wikipediaInlineMathParseRule,+];+export const defaultBlockMathParseRules = [+ wikipediaBlockMathParseRule,+];diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-select.d.ts b/packages/editor/dist/es/extensions/math/plugin/plugins/math-select.d.tsnew file mode 100644index 000000000..fa6e7915e--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-select.d.ts@@ -0,0 +1,12 @@+import { Plugin as ProsePlugin } from "prosemirror-state";+/**+ * Due to the internals of KaTeX, by default, selecting rendered+ * math will put a box around each individual character of a+ * math expression. This plugin attempts to make math selections+ * slightly prettier by instead setting a background color on the node.+ *+ * (remember to use the included math.css!)+ *+ * @todo (6/13/20) math selection rectangles are not quite even with text+ */+export declare const mathSelectPlugin: ProsePlugin;diff --git a/packages/editor/dist/es/extensions/math/plugin/plugins/math-select.js b/packages/editor/dist/es/extensions/math/plugin/plugins/math-select.jsnew file mode 100644index 000000000..dedb5f71d--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/plugins/math-select.js@@ -0,0 +1,62 @@+/*---------------------------------------------------------+ * Author: Benjamin R. Bray+ * License: MIT (see LICENSE in project root for details)+ *--------------------------------------------------------*/+// prosemirror imports+import { Plugin as ProsePlugin, } from "prosemirror-state";+import { DecorationSet, Decoration } from "prosemirror-view";+////////////////////////////////////////////////////////////+/**+ * Uses the selection to determine which math_select decorations+ * should be applied to the given document.+ * @param arg Should be either a Transaction or an EditorState,+ * although any object with `selection` and `doc` will work.+ */+const checkSelection = (arg) => {+ let { from, to } = arg.selection;+ let content = arg.selection.content().content;+ let result = [];+ content.descendants((node, pos, parent) => {+ if (node.type.name == "text") {+ return false;+ }+ if (node.type.name.startsWith("math_")) {+ result.push({+ start: Math.max(from + pos - 1, 0),+ end: from + pos + node.nodeSize - 1,+ });+ return false;+ }+ return true;+ });+ return DecorationSet.create(arg.doc, result.map(({ start, end }) => Decoration.node(start, end, { class: "math-select" })));+};+/**+ * Due to the internals of KaTeX, by default, selecting rendered+ * math will put a box around each individual character of a+ * math expression. This plugin attempts to make math selections+ * slightly prettier by instead setting a background color on the node.+ *+ * (remember to use the included math.css!)+ *+ * @todo (6/13/20) math selection rectangles are not quite even with text+ */+export const mathSelectPlugin = new ProsePlugin({+ state: {+ init(config, partialState) {+ return checkSelection(partialState);+ },+ apply(tr, value, oldState, newState) {+ if (!tr.selection || !tr.selectionSet) {+ return oldState;+ }+ let sel = checkSelection(tr);+ return sel;+ },+ },+ props: {+ decorations: (state) => {+ return mathSelectPlugin.getState(state);+ },+ },+});diff --git a/packages/editor/dist/es/extensions/math/plugin/renderers/katex.d.ts b/packages/editor/dist/es/extensions/math/plugin/renderers/katex.d.tsnew file mode 100644index 000000000..0b716cff8--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/renderers/katex.d.ts@@ -0,0 +1,2 @@+import { MathRenderer } from "./types";+export declare const KatexRenderer: MathRenderer;diff --git a/packages/editor/dist/es/extensions/math/plugin/renderers/katex.js b/packages/editor/dist/es/extensions/math/plugin/renderers/katex.jsnew file mode 100644index 000000000..50f945424--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/renderers/katex.js@@ -0,0 +1,39 @@+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+function loadKatex() {+ return __awaiter(this, void 0, void 0, function* () {+ // @ts-ignore+ const { default: katex } = yield import("katex");+ // Chemistry formulas support+ // @ts-ignore+ yield import("katex/contrib/mhchem/mhchem");+ return katex;+ });+}+export const KatexRenderer = {+ inline: (text, element) => {+ loadKatex().then((katex) => {+ katex.render(text, element, {+ displayMode: false,+ globalGroup: true,+ throwOnError: false,+ });+ });+ },+ block: (text, element) => {+ loadKatex().then((katex) => {+ katex.render(text, element, {+ displayMode: true,+ globalGroup: true,+ throwOnError: false,+ });+ });+ },+};diff --git a/packages/editor/dist/es/extensions/math/plugin/renderers/types.d.ts b/packages/editor/dist/es/extensions/math/plugin/renderers/types.d.tsnew file mode 100644index 000000000..437b6338b--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/renderers/types.d.ts@@ -0,0 +1,5 @@+export declare type MathRenderFn = (text: string, element: HTMLElement) => void;+export declare type MathRenderer = {+ inline: MathRenderFn;+ block: MathRenderFn;+};diff --git a/packages/editor/dist/es/extensions/math/plugin/renderers/types.js b/packages/editor/dist/es/extensions/math/plugin/renderers/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/renderers/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/extensions/math/plugin/utils/text-serializer.d.ts b/packages/editor/dist/es/extensions/math/plugin/utils/text-serializer.d.tsnew file mode 100644index 000000000..4e03d2a81--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/utils/text-serializer.d.ts@@ -0,0 +1,34 @@+import { Node as ProseNode, Mark, Slice, NodeType, MarkType, Fragment } from "prosemirror-model";+declare type TypedNode<T extends string> = ProseNode & {+ type: NodeType & {+ name: T;+ };+};+declare type TypedMark<T extends string> = Mark & {+ type: MarkType & {+ name: T;+ };+};+declare type NodeSerializer<T extends string> = (node: TypedNode<T>) => string;+declare type MarkSerializer<T extends string> = (mark: TypedMark<T>) => string;+declare class ProseMirrorTextSerializer {+ nodes: {+ [name: string]: NodeSerializer<string> | undefined;+ };+ marks: {+ [name: string]: MarkSerializer<string> | undefined;+ };+ constructor(fns: {+ nodes?: {+ [name: string]: NodeSerializer<string> | undefined;+ };+ marks?: {+ [name: string]: MarkSerializer<string> | undefined;+ };+ }, base?: ProseMirrorTextSerializer);+ serializeFragment(fragment: Fragment): string;+ serializeSlice(slice: Slice): string;+ serializeNode(node: ProseNode): string | null;+}+export declare const mathSerializer: ProseMirrorTextSerializer;+export {};diff --git a/packages/editor/dist/es/extensions/math/plugin/utils/text-serializer.js b/packages/editor/dist/es/extensions/math/plugin/utils/text-serializer.jsnew file mode 100644index 000000000..50cd63595--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/utils/text-serializer.js@@ -0,0 +1,58 @@+class ProseMirrorTextSerializer {+ constructor(fns, base) {+ // use base serializer as a fallback+ this.nodes = Object.assign(Object.assign({}, base === null || base === void 0 ? void 0 : base.nodes), fns.nodes);+ this.marks = Object.assign(Object.assign({}, base === null || base === void 0 ? void 0 : base.marks), fns.marks);+ }+ serializeFragment(fragment) {+ // adapted from the undocumented `Fragment.textBetween` function+ // https://github.com/ProseMirror/prosemirror-model/blob/eef20c8c6dbf841b1d70859df5d59c21b5108a4f/src/fragment.js#L46+ let blockSeparator = "\n\n";+ let leafText = undefined;+ let text = "";+ let separated = true;+ let from = 0;+ let to = fragment.size;+ fragment.nodesBetween(from, to, (node, pos) => {+ var _a;+ // check if one of our custom serializers handles this node+ let serialized = this.serializeNode(node);+ if (serialized !== null) {+ text += serialized;+ return false;+ }+ if (node.isText) {+ text += ((_a = node.text) === null || _a === void 0 ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos)) || "";+ separated = !blockSeparator;+ }+ else if (node.isLeaf && leafText) {+ text += leafText;+ separated = !blockSeparator;+ }+ else if (!separated && node.isBlock) {+ text += blockSeparator;+ separated = true;+ }+ }, 0);+ return text;+ }+ serializeSlice(slice) {+ return this.serializeFragment(slice.content);+ }+ serializeNode(node) {+ // check if one of our custom serializers handles this node+ let nodeSerializer = this.nodes[node.type.name];+ if (nodeSerializer !== undefined) {+ return nodeSerializer(node);+ }+ else {+ return null;+ }+ }+}+export const mathSerializer = new ProseMirrorTextSerializer({+ nodes: {+ math_inline: (node) => `$${node.textContent}$`,+ math_display: (node) => `\n\n$$\n${node.textContent}\n$$`,+ },+});diff --git a/packages/editor/dist/es/extensions/math/plugin/utils/types.d.ts b/packages/editor/dist/es/extensions/math/plugin/utils/types.d.tsnew file mode 100644index 000000000..6792b9f33--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/utils/types.d.ts@@ -0,0 +1,5 @@+import { Schema, SchemaSpec } from "prosemirror-model";+export declare type SchemaSpecNodeT<Spec> = Spec extends SchemaSpec<infer N, infer _> ? N : never;+export declare type SchemaSpecMarkT<Spec> = Spec extends SchemaSpec<infer _, infer M> ? M : never;+export declare type SchemaNodeT<S> = S extends Schema<infer N, infer _> ? N : never;+export declare type SchemaMarkT<S> = S extends Schema<infer _, infer M> ? M : never;diff --git a/packages/editor/dist/es/extensions/math/plugin/utils/types.js b/packages/editor/dist/es/extensions/math/plugin/utils/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/extensions/math/plugin/utils/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/extensions/orderedlist/index.d.ts b/packages/editor/dist/es/extensions/orderedlist/index.d.tsnew file mode 100644index 000000000..e5d88c387--- /dev/null+++ b/packages/editor/dist/es/extensions/orderedlist/index.d.ts@@ -0,0 +1,3 @@+import { OrderedList } from "./ordered-list";+export * from "./ordered-list";+export default OrderedList;diff --git a/packages/editor/dist/es/extensions/orderedlist/index.js b/packages/editor/dist/es/extensions/orderedlist/index.jsnew file mode 100644index 000000000..e5d88c387--- /dev/null+++ b/packages/editor/dist/es/extensions/orderedlist/index.js@@ -0,0 +1,3 @@+import { OrderedList } from "./ordered-list";+export * from "./ordered-list";+export default OrderedList;diff --git a/packages/editor/dist/es/extensions/orderedlist/orderedlist.d.ts b/packages/editor/dist/es/extensions/orderedlist/orderedlist.d.tsnew file mode 100644index 000000000..16afc3a43--- /dev/null+++ b/packages/editor/dist/es/extensions/orderedlist/orderedlist.d.ts@@ -0,0 +1 @@+export declare const OrderedList: import("@tiptap/core").Node<import("@tiptap/extension-ordered-list").OrderedListOptions, any>;diff --git a/packages/editor/dist/es/extensions/orderedlist/orderedlist.js b/packages/editor/dist/es/extensions/orderedlist/orderedlist.jsnew file mode 100644index 000000000..fd2d9fc0a--- /dev/null+++ b/packages/editor/dist/es/extensions/orderedlist/orderedlist.js@@ -0,0 +1,19 @@+import TiptapOrderedList from "@tiptap/extension-ordered-list";+export const OrderedList = TiptapOrderedList.extend({+ addAttributes() {+ return {+ listType: {+ default: null,+ parseHTML: (element) => element.style.listStyleType,+ renderHTML: (attributes) => {+ if (!attributes.listType) {+ return {};+ }+ return {+ style: `list-style-type: ${attributes.listType}`,+ };+ },+ },+ };+ },+});diff --git a/packages/editor/dist/es/extensions/outlinelist/component.d.ts b/packages/editor/dist/es/extensions/outlinelist/component.d.tsnew file mode 100644index 000000000..2e64b6e02--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelist/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ReactNodeViewProps } from "../react";+import { OutlineListAttributes } from "./outline-list";+export declare function OutlineListComponent(props: ReactNodeViewProps<OutlineListAttributes>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/outlinelist/component.js b/packages/editor/dist/es/extensions/outlinelist/component.jsnew file mode 100644index 000000000..3c4106018--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelist/component.js@@ -0,0 +1,22 @@+import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";+import { Text } from "rebass";+import { useMemo } from "react";+import { OutlineListItem } from "../outline-list-item";+export function OutlineListComponent(props) {+ const { editor, getPos, node, updateAttributes, forwardRef } = props;+ const { collapsed } = node.attrs;+ const isNested = useMemo(() => {+ var _a;+ const pos = editor.state.doc.resolve(getPos());+ return ((_a = pos.parent) === null || _a === void 0 ? void 0 : _a.type.name) === OutlineListItem.name;+ }, []);+ return (_jsx(_Fragment, { children: _jsx(Text, { className: "outline-list", as: "div", ref: forwardRef, sx: {+ ul: {+ display: collapsed ? "none" : "block",+ paddingInlineStart: 0,+ paddingLeft: isNested ? 1 : 0,+ marginBlockStart: isNested ? 5 : 0,+ marginBlockEnd: 0,+ },+ } }) }));+}diff --git a/packages/editor/dist/es/extensions/outlinelist/index.d.ts b/packages/editor/dist/es/extensions/outlinelist/index.d.tsnew file mode 100644index 000000000..5aec1c8aa--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelist/index.d.ts@@ -0,0 +1 @@+export * from "./outline-list";diff --git a/packages/editor/dist/es/extensions/outlinelist/index.js b/packages/editor/dist/es/extensions/outlinelist/index.jsnew file mode 100644index 000000000..5aec1c8aa--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelist/index.js@@ -0,0 +1 @@+export * from "./outline-list";diff --git a/packages/editor/dist/es/extensions/outlinelist/outlinelist.d.ts b/packages/editor/dist/es/extensions/outlinelist/outlinelist.d.tsnew file mode 100644index 000000000..5c1a1f21f--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelist/outlinelist.d.ts@@ -0,0 +1,19 @@+import { Node } from "@tiptap/core";+export declare type OutlineListAttributes = {+ collapsed: boolean;+};+export interface OutlineListOptions {+ HTMLAttributes: Record<string, any>;+}+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ outlineList: {+ /**+ * Toggle a bullet list+ */+ toggleOutlineList: () => ReturnType;+ };+ }+}+export declare const inputRegex: RegExp;+export declare const OutlineList: Node<OutlineListOptions, any>;diff --git a/packages/editor/dist/es/extensions/outlinelist/outlinelist.js b/packages/editor/dist/es/extensions/outlinelist/outlinelist.jsnew file mode 100644index 000000000..90c113c63--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelist/outlinelist.js@@ -0,0 +1,74 @@+import { Node, mergeAttributes, wrappingInputRule } from "@tiptap/core";+import { createNodeView } from "../react";+import { OutlineListComponent } from "./component";+export const inputRegex = /^\s*(-o)\s$/;+const outlineListItemName = `outlineListItem`;+export const OutlineList = Node.create({+ name: "outlineList",+ addOptions() {+ return {+ HTMLAttributes: {},+ };+ },+ addAttributes() {+ return {+ collapsed: {+ default: false,+ keepOnSplit: false,+ parseHTML: (element) => element.dataset.collapsed === "true",+ renderHTML: (attributes) => ({+ "data-collapsed": attributes.collapsed === true,+ }),+ },+ };+ },+ group: "block list",+ content: `${outlineListItemName}+`,+ parseHTML() {+ return [+ {+ tag: `ul[data-type="${this.name}"]`,+ priority: 52,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "ul",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ "data-type": this.name,+ }),+ 0,+ ];+ },+ addCommands() {+ return {+ toggleOutlineList: () => ({ commands }) => {+ return commands.toggleList(this.name, outlineListItemName);+ },+ };+ },+ addKeyboardShortcuts() {+ return {+ "Mod-Shift-O": () => this.editor.commands.toggleOutlineList(),+ };+ },+ addInputRules() {+ return [+ wrappingInputRule({+ find: inputRegex,+ type: this.type,+ }),+ ];+ },+ addNodeView() {+ return createNodeView(OutlineListComponent, {+ contentDOMFactory: () => {+ const content = document.createElement("ul");+ content.classList.add(`${this.name.toLowerCase()}-content-wrapper`);+ content.style.whiteSpace = "inherit";+ return { dom: content };+ },+ });+ },+});diff --git a/packages/editor/dist/es/extensions/outlinelistitem/component.d.ts b/packages/editor/dist/es/extensions/outlinelistitem/component.d.tsnew file mode 100644index 000000000..26d37f4a2--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelistitem/component.d.ts@@ -0,0 +1,3 @@+/// <reference types="react" />+import { ReactNodeViewProps } from "../react";+export declare function OutlineListItemComponent(props: ReactNodeViewProps): JSX.Element;diff --git a/packages/editor/dist/es/extensions/outlinelistitem/component.js b/packages/editor/dist/es/extensions/outlinelistitem/component.jsnew file mode 100644index 000000000..8df9e140c--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelistitem/component.js@@ -0,0 +1,51 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Box, Flex, Text } from "rebass";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { findChildren, } from "@tiptap/core";+import { OutlineList } from "../outline-list/outline-list";+export function OutlineListItemComponent(props) {+ var _a, _b;+ const { editor, updateAttributes, node, getPos, forwardRef } = props;+ const isNested = ((_a = node.lastChild) === null || _a === void 0 ? void 0 : _a.type.name) === OutlineList.name;+ const isCollapsed = isNested && ((_b = node.lastChild) === null || _b === void 0 ? void 0 : _b.attrs.collapsed);+ return (_jsxs(Flex, { children: [_jsxs(Flex, Object.assign({ className: "outline", sx: {+ flexDirection: "column",+ alignItems: "center",+ mt: "3px",+ } }, { children: [isNested ? (_jsx(Icon, { path: isCollapsed ? Icons.chevronRight : Icons.chevronDown, title: isCollapsed+ ? "Click to uncollapse list"+ : "Click to collapse list", sx: {+ cursor: "pointer",+ transition: `all .2s ease-in-out`,+ ":hover": {+ transform: "scale(1.3)",+ },+ ".icon:hover path": {+ fill: "var(--checked) !important",+ },+ }, size: 18, onMouseDown: (e) => e.preventDefault(), onClick: () => {+ const [subList] = findChildren(node, (node) => node.type.name === OutlineList.name);+ if (!subList)+ return;+ const { pos } = subList;+ editor.commands.toggleOutlineCollapse(pos + getPos() + 1, !isCollapsed);+ } })) : (_jsx(Icon, { path: Icons.circle, size: 18, sx: { transform: "scale(0.4)" } })), isNested && !isCollapsed && (_jsx(Box, { sx: {+ flex: 1,+ width: 1,+ mt: 2,+ backgroundColor: "border",+ borderRadius: 50,+ flexShrink: 0,+ cursor: "pointer",+ transition: `all .2s ease-in-out`,+ ":hover": {+ backgroundColor: "fontTertiary",+ width: 4,+ },+ }, contentEditable: false }))] })), _jsx(Text, { as: "li", ref: forwardRef, sx: {+ pl: 2,+ listStyleType: "none",+ flex: 1,+ } })] }));+}diff --git a/packages/editor/dist/es/extensions/outlinelistitem/index.d.ts b/packages/editor/dist/es/extensions/outlinelistitem/index.d.tsnew file mode 100644index 000000000..1b1e56bc7--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelistitem/index.d.ts@@ -0,0 +1 @@+export * from "./outline-list-item";diff --git a/packages/editor/dist/es/extensions/outlinelistitem/index.js b/packages/editor/dist/es/extensions/outlinelistitem/index.jsnew file mode 100644index 000000000..1b1e56bc7--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelistitem/index.js@@ -0,0 +1 @@+export * from "./outline-list-item";diff --git a/packages/editor/dist/es/extensions/outlinelistitem/outlinelistitem.d.ts b/packages/editor/dist/es/extensions/outlinelistitem/outlinelistitem.d.tsnew file mode 100644index 000000000..d9742f1d1--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelistitem/outlinelistitem.d.ts@@ -0,0 +1,12 @@+import { Node } from "@tiptap/core";+export interface ListItemOptions {+ HTMLAttributes: Record<string, any>;+}+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ outlineListItem: {+ toggleOutlineCollapse: (subListPos: number, state: boolean) => ReturnType;+ };+ }+}+export declare const OutlineListItem: Node<ListItemOptions, any>;diff --git a/packages/editor/dist/es/extensions/outlinelistitem/outlinelistitem.js b/packages/editor/dist/es/extensions/outlinelistitem/outlinelistitem.jsnew file mode 100644index 000000000..de1446c1e--- /dev/null+++ b/packages/editor/dist/es/extensions/outlinelistitem/outlinelistitem.js@@ -0,0 +1,100 @@+import { Node, mergeAttributes, findChildren } from "@tiptap/core";+import { findParentNodeOfTypeClosestToPos } from "prosemirror-utils";+import { onBackspacePressed } from "../list-item/commands";+import { OutlineList } from "../outline-list/outline-list";+import { createNodeView } from "../react";+import { OutlineListItemComponent } from "./component";+export const OutlineListItem = Node.create({+ name: "outlineListItem",+ addOptions() {+ return {+ HTMLAttributes: {},+ };+ },+ content: "heading* block*",+ defining: true,+ parseHTML() {+ return [+ {+ tag: `li[data-type="${this.name}"]`,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "li",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ "data-type": this.name,+ }),+ 0,+ ];+ },+ addKeyboardShortcuts() {+ return {+ "Mod-Space": ({ editor }) => {+ const subList = findSublist(editor, this.type);+ if (!subList)+ return false;+ const { isCollapsed, subListPos } = subList;+ return this.editor.commands.toggleOutlineCollapse(subListPos, !isCollapsed);+ },+ Enter: ({ editor }) => {+ const subList = findSublist(editor, this.type);+ if (!subList)+ return false;+ const { isCollapsed, subListPos } = subList;+ if (isCollapsed) {+ return this.editor.commands.toggleOutlineCollapse(subListPos, false);+ }+ return this.editor.commands.splitListItem(this.name);+ },+ Tab: () => this.editor.commands.sinkListItem(this.name),+ "Shift-Tab": () => this.editor.commands.liftListItem(this.name),+ Backspace: ({ editor }) => onBackspacePressed(editor, this.name, this.type),+ };+ },+ addCommands() {+ return {+ toggleOutlineCollapse: (pos, state) => ({ tr }) => {+ tr.setNodeMarkup(pos, undefined, {+ collapsed: state,+ });+ return true;+ },+ };+ },+ addNodeView() {+ return createNodeView(OutlineListItemComponent, {+ contentDOMFactory: true,+ // wrapperFactory: () => document.createElement("li"),+ });+ },+});+function findSublist(editor, type) {+ var _a, _b;+ const { selection } = editor.state;+ const { $from } = selection;+ const listItem = findParentNodeOfTypeClosestToPos($from, type);+ if (!listItem)+ return false;+ const [subList] = findChildren(listItem.node, (node) => node.type.name === OutlineList.name);+ if (!subList)+ return false;+ const isNested = ((_a = subList === null || subList === void 0 ? void 0 : subList.node) === null || _a === void 0 ? void 0 : _a.type.name) === OutlineList.name;+ const isCollapsed = (_b = subList === null || subList === void 0 ? void 0 : subList.node) === null || _b === void 0 ? void 0 : _b.attrs.collapsed;+ const subListPos = listItem.pos + subList.pos + 1;+ return { isCollapsed, isNested, subListPos };+ // return (+ // this.editor+ // .chain()+ // .command(({ tr }) => {+ // tr.setNodeMarkup(listItem.pos + subList.pos + 1, undefined, {+ // collapsed: !isCollapsed,+ // });+ // return true;+ // })+ // //.setTextSelection(listItem.pos + subList.pos + 1)+ // //.splitListItem(this.name)+ // .run()+ // );+}diff --git a/packages/editor/dist/es/extensions/react/eventdispatcher.d.ts b/packages/editor/dist/es/extensions/react/eventdispatcher.d.tsnew file mode 100644index 000000000..f9fba57a4--- /dev/null+++ b/packages/editor/dist/es/extensions/react/eventdispatcher.d.ts@@ -0,0 +1,18 @@+import { PluginKey } from "prosemirror-state";+export interface Listeners {+ [name: string]: Set<Listener>;+}+export declare type Listener<T = any> = (data: T) => void;+export declare type Dispatch<T = any> = (eventName: PluginKey | string, data: T) => void;+export declare class EventDispatcher<T = any> {+ private listeners;+ on(event: string, cb: Listener<T>): void;+ off(event: string, cb: Listener<T>): void;+ emit(event: string, data: T): void;+ destroy(): void;+}+/**+ * Creates a dispatch function that can be called inside ProseMirror Plugin+ * to notify listeners about that plugin's state change.+ */+export declare function createDispatch<T>(eventDispatcher: EventDispatcher<T>): Dispatch<T>;diff --git a/packages/editor/dist/es/extensions/react/eventdispatcher.js b/packages/editor/dist/es/extensions/react/eventdispatcher.jsnew file mode 100644index 000000000..96ce55866--- /dev/null+++ b/packages/editor/dist/es/extensions/react/eventdispatcher.js@@ -0,0 +1,43 @@+export class EventDispatcher {+ constructor() {+ this.listeners = {};+ }+ on(event, cb) {+ if (!this.listeners[event]) {+ this.listeners[event] = new Set();+ }+ this.listeners[event].add(cb);+ }+ off(event, cb) {+ if (!this.listeners[event]) {+ return;+ }+ if (this.listeners[event].has(cb)) {+ this.listeners[event].delete(cb);+ }+ }+ emit(event, data) {+ if (!this.listeners[event]) {+ return;+ }+ this.listeners[event].forEach((cb) => cb(data));+ }+ destroy() {+ this.listeners = {};+ }+}+/**+ * Creates a dispatch function that can be called inside ProseMirror Plugin+ * to notify listeners about that plugin's state change.+ */+export function createDispatch(eventDispatcher) {+ return (eventName, data) => {+ if (!eventName) {+ throw new Error("event name is required!");+ }+ const event = typeof eventName === "string"+ ? eventName+ : eventName.key;+ eventDispatcher.emit(event, data);+ };+}diff --git a/packages/editor/dist/es/extensions/react/index.d.ts b/packages/editor/dist/es/extensions/react/index.d.tsnew file mode 100644index 000000000..db315768f--- /dev/null+++ b/packages/editor/dist/es/extensions/react/index.d.ts@@ -0,0 +1,6 @@+export * from "./react-node-view";+export * from "./types";+export * from "./react-portal-provider";+export * from "./selection-based-react-node-view";+export * from "./plugin";+export * from "./event-dispatcher";diff --git a/packages/editor/dist/es/extensions/react/index.js b/packages/editor/dist/es/extensions/react/index.jsnew file mode 100644index 000000000..db315768f--- /dev/null+++ b/packages/editor/dist/es/extensions/react/index.js@@ -0,0 +1,6 @@+export * from "./react-node-view";+export * from "./types";+export * from "./react-portal-provider";+export * from "./selection-based-react-node-view";+export * from "./plugin";+export * from "./event-dispatcher";diff --git a/packages/editor/dist/es/extensions/react/plugin.d.ts b/packages/editor/dist/es/extensions/react/plugin.d.tsnew file mode 100644index 000000000..032e5008b--- /dev/null+++ b/packages/editor/dist/es/extensions/react/plugin.d.ts@@ -0,0 +1,13 @@+import { Plugin, PluginKey } from "prosemirror-state";+import { Extension } from "@tiptap/core";+export declare type StateChangeHandler = (fromPos: number, toPos: number) => any;+export declare class ReactNodeViewState {+ private changeHandlers;+ constructor();+ subscribe(cb: StateChangeHandler): void;+ unsubscribe(cb: StateChangeHandler): void;+ notifyNewSelection(fromPos: number, toPos: number): void;+}+export declare const stateKey: PluginKey<any>;+export declare const NodeViewSelectionNotifierPlugin: Plugin<ReactNodeViewState>;+export declare const NodeViewSelectionNotifier: Extension<any, any>;diff --git a/packages/editor/dist/es/extensions/react/plugin.js b/packages/editor/dist/es/extensions/react/plugin.jsnew file mode 100644index 000000000..30e109baa--- /dev/null+++ b/packages/editor/dist/es/extensions/react/plugin.js@@ -0,0 +1,43 @@+import { Plugin, PluginKey } from "prosemirror-state";+import { Extension } from "@tiptap/core";+export class ReactNodeViewState {+ constructor() {+ this.changeHandlers = [];+ this.changeHandlers = [];+ }+ subscribe(cb) {+ this.changeHandlers.push(cb);+ }+ unsubscribe(cb) {+ this.changeHandlers = this.changeHandlers.filter((ch) => ch !== cb);+ }+ notifyNewSelection(fromPos, toPos) {+ this.changeHandlers.forEach((cb) => cb(fromPos, toPos));+ }+}+export const stateKey = new PluginKey("reactNodeView");+export const NodeViewSelectionNotifierPlugin = new Plugin({+ state: {+ init() {+ return new ReactNodeViewState();+ },+ apply(_tr, pluginState) {+ return pluginState;+ },+ },+ key: stateKey,+ view: (view) => {+ const pluginState = stateKey.getState(view.state);+ return {+ update: (view) => {+ const { from, to } = view.state.selection;+ pluginState.notifyNewSelection(from, to);+ },+ };+ },+});+export const NodeViewSelectionNotifier = Extension.create({+ addProseMirrorPlugins() {+ return [NodeViewSelectionNotifierPlugin];+ },+});diff --git a/packages/editor/dist/es/extensions/react/reactnodeview.d.ts b/packages/editor/dist/es/extensions/react/reactnodeview.d.tsnew file mode 100644index 000000000..ceb40eb0e--- /dev/null+++ b/packages/editor/dist/es/extensions/react/reactnodeview.d.ts@@ -0,0 +1,51 @@+import React from "react";+import { NodeView, Decoration, DecorationSource } from "prosemirror-view";+import { Node as PMNode } from "prosemirror-model";+import { PortalProviderAPI } from "./react-portal-provider";+import { ReactNodeViewProps, ReactNodeViewOptions, GetPosNode, ForwardRef, ContentDOM } from "./types";+import { Editor, NodeViewRendererProps } from "@tiptap/core";+export declare class ReactNodeView<P extends ReactNodeViewProps> implements NodeView {+ protected readonly editor: Editor;+ protected readonly getPos: GetPosNode;+ protected readonly options: ReactNodeViewOptions<P>;+ private domRef;+ private contentDOMWrapper?;+ contentDOM: HTMLElement | undefined;+ node: PMNode;+ isDragging: boolean;+ portalProviderAPI: PortalProviderAPI;+ constructor(node: PMNode, editor: Editor, getPos: GetPosNode, options: ReactNodeViewOptions<P>);+ /**+ * This method exists to move initialization logic out of the constructor,+ * so object can be initialized properly before calling render first time.+ *+ * Example:+ * Instance properties get added to an object only after super call in+ * constructor, which leads to some methods being undefined during the+ * first render.+ */+ init(): this;+ private renderReactComponent;+ createDomRef(): HTMLElement;+ getContentDOM(): ContentDOM;+ handleRef: (node: HTMLElement | null) => void;+ private _handleRef;+ render(props?: P, forwardRef?: ForwardRef): React.ReactElement<any> | null;+ updateAttributes(attributes: any, pos: number): void;+ update(node: PMNode, _decorations: readonly Decoration[], _innerDecorations: DecorationSource): boolean;+ onDragStart(event: DragEvent): void;+ stopEvent(event: Event): boolean;+ ignoreMutation(mutation: MutationRecord | {+ type: "selection";+ target: Element;+ }): boolean;+ viewShouldUpdate(nextNode: PMNode): boolean;+ /**+ * Copies the attributes from a ProseMirror Node to a DOM node.+ * @param node The Prosemirror Node from which to source the attributes+ */+ setDomAttrs(node: PMNode, element: HTMLElement): void;+ get dom(): HTMLElement;+ destroy(): void;+}+export declare function createNodeView<TProps extends ReactNodeViewProps>(component: React.ComponentType<TProps>, options?: Omit<ReactNodeViewOptions<TProps>, "component">): ({ node, getPos, editor }: NodeViewRendererProps) => ReactNodeView<TProps>;diff --git a/packages/editor/dist/es/extensions/react/reactnodeview.js b/packages/editor/dist/es/extensions/react/reactnodeview.jsnew file mode 100644index 000000000..2a232eb8f--- /dev/null+++ b/packages/editor/dist/es/extensions/react/reactnodeview.js@@ -0,0 +1,330 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { NodeSelection } from "prosemirror-state";+import { ThemeProvider } from "emotion-theming";+// @ts-ignore+import { __serializeForClipboard } from "prosemirror-view";+export class ReactNodeView {+ constructor(node, editor, getPos, options) {+ this.editor = editor;+ this.getPos = getPos;+ this.options = options;+ this.isDragging = false;+ this.handleRef = (node) => this._handleRef(node);+ this.portalProviderAPI = editor.storage+ .portalProviderAPI;+ this.node = node;+ }+ /**+ * This method exists to move initialization logic out of the constructor,+ * so object can be initialized properly before calling render first time.+ *+ * Example:+ * Instance properties get added to an object only after super call in+ * constructor, which leads to some methods being undefined during the+ * first render.+ */+ init() {+ this.domRef = this.createDomRef();+ this.domRef.ondragstart = (ev) => this.onDragStart(ev);+ // this.setDomAttrs(this.node, this.domRef);+ const { dom: contentDOMWrapper, contentDOM } = this.getContentDOM() || {+ dom: undefined,+ contentDOM: undefined,+ };+ if (this.domRef && contentDOMWrapper) {+ this.domRef.appendChild(contentDOMWrapper);+ this.contentDOM = contentDOM ? contentDOM : contentDOMWrapper;+ this.contentDOMWrapper = contentDOMWrapper || contentDOM;+ }+ // @see ED-3790+ // something gets messed up during mutation processing inside of a+ // nodeView if DOM structure has nested plain "div"s, it doesn't see the+ // difference between them and it kills the nodeView+ this.domRef.classList.add(`${this.node.type.name}-view-content-wrap`);+ this.renderReactComponent(() => this.render(this.options.props, this.handleRef));+ return this;+ }+ renderReactComponent(component) {+ if (!this.domRef || !component || !this.portalProviderAPI) {+ console.warn("Cannot render node view", this.editor.storage);+ return;+ }+ this.portalProviderAPI.render(component, this.domRef);+ }+ createDomRef() {+ if (this.options.wrapperFactory)+ return this.options.wrapperFactory();+ if (!this.node.isInline) {+ return document.createElement("div");+ }+ const htmlElement = document.createElement("span");+ return htmlElement;+ }+ getContentDOM() {+ var _a, _b;+ if (!this.options.contentDOMFactory)+ return;+ if (this.options.contentDOMFactory === true) {+ const content = document.createElement("div");+ content.classList.add(`${this.node.type.name.toLowerCase()}-content-wrapper`);+ content.style.whiteSpace = "inherit";+ // caret is not visible if content element width is 0px+ content.style.minWidth = `20px`;+ return { dom: content };+ }+ return (_b = (_a = this.options).contentDOMFactory) === null || _b === void 0 ? void 0 : _b.call(_a);+ }+ _handleRef(node) {+ const contentDOM = this.contentDOMWrapper || this.contentDOM;+ // move the contentDOM node inside the inner reference after rendering+ if (node && contentDOM && !node.contains(contentDOM)) {+ node.appendChild(contentDOM);+ }+ }+ render(props = {}, forwardRef) {+ if (!this.options.component)+ return null;+ const theme = this.editor.storage.theme;+ const pos = this.getPos();+ return (_jsx(ThemeProvider, Object.assign({ theme: theme }, { children: _jsx(this.options.component, Object.assign({}, props, { editor: this.editor, getPos: this.getPos, node: this.node, forwardRef: forwardRef, updateAttributes: (attr) => this.updateAttributes(attr, pos) })) })));+ }+ updateAttributes(attributes, pos) {+ this.editor.commands.command(({ tr }) => {+ tr.setNodeMarkup(pos, undefined, Object.assign(Object.assign({}, this.node.attrs), attributes));+ return true;+ });+ }+ update(node, _decorations, _innerDecorations+ // _innerDecorations?: Array<Decoration>,+ // validUpdate: (currentNode: PMNode, newNode: PMNode) => boolean = () => true+ ) {+ // @see https://github.com/ProseMirror/prosemirror/issues/648+ const isValidUpdate = this.node.type === node.type; // && validUpdate(this.node, node);+ if (!isValidUpdate) {+ return false;+ }+ // if (this.domRef && !this.node.sameMarkup(node)) {+ // this.setDomAttrs(node, this.domRef);+ // }+ // View should not process a re-render if this is false.+ // We dont want to destroy the view, so we return true.+ if (!this.viewShouldUpdate(node)) {+ this.node = node;+ return true;+ }+ this.node = node;+ this.renderReactComponent(() => this.render(this.options.props, this.handleRef));+ return true;+ }+ onDragStart(event) {+ var _a, _b, _c, _d, _e, _f, _g;+ const { view } = this.editor;+ const target = event.target;+ // get the drag handle element+ // `closest` is not available for text nodes so we may have to use its parent+ const dragHandle = target.nodeType === 3+ ? (_a = target.parentElement) === null || _a === void 0 ? void 0 : _a.closest("[data-drag-handle]")+ : target.closest("[data-drag-handle]");+ if (!this.dom || ((_b = this.contentDOM) === null || _b === void 0 ? void 0 : _b.contains(target)) || !dragHandle) {+ return;+ }+ const dragImage = this.dom.querySelector("[data-drag-image]") || this.dom;+ let x = 0;+ let y = 0;+ // calculate offset for drag element if we use a different drag handle element+ if (dragImage !== dragHandle) {+ const domBox = dragImage.getBoundingClientRect();+ const handleBox = dragHandle.getBoundingClientRect();+ // In React, we have to go through nativeEvent to reach offsetX/offsetY.+ const offsetX = (_c = event.offsetX) !== null && _c !== void 0 ? _c : (_d = event.nativeEvent) === null || _d === void 0 ? void 0 : _d.offsetX;+ const offsetY = (_e = event.offsetY) !== null && _e !== void 0 ? _e : (_f = event.nativeEvent) === null || _f === void 0 ? void 0 : _f.offsetY;+ x = handleBox.x - domBox.x + offsetX;+ y = handleBox.y - domBox.y + offsetY;+ }+ // we need to tell ProseMirror that we want to move the whole node+ // so we create a NodeSelection+ const selection = NodeSelection.create(view.state.doc, this.getPos());+ const transaction = view.state.tr.setSelection(selection);+ view.dispatch(transaction);+ (_g = event.dataTransfer) === null || _g === void 0 ? void 0 : _g.setDragImage(dragImage, x, y);+ forceHandleDrag(event, this.editor);+ }+ stopEvent(event) {+ var _a;+ if (!this.dom) {+ return false;+ }+ // if (typeof this.options.stopEvent === 'function') {+ // return this.options.stopEvent({ event })+ // }+ const target = event.target;+ const isInElement = this.dom.contains(target) && !((_a = this.contentDOM) === null || _a === void 0 ? void 0 : _a.contains(target));+ // any event from child nodes should be handled by ProseMirror+ if (!isInElement) {+ return false;+ }+ const isDropEvent = event.type === "drop";+ const isInput = ["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(target.tagName) ||+ target.isContentEditable;+ // any input event within node views should be ignored by ProseMirror+ if (isInput && !isDropEvent) {+ return true;+ }+ const { isEditable } = this.editor;+ const { isDragging } = this;+ const isDraggable = !!this.node.type.spec.draggable;+ const isSelectable = NodeSelection.isSelectable(this.node);+ const isCopyEvent = event.type === "copy";+ const isPasteEvent = event.type === "paste";+ const isCutEvent = event.type === "cut";+ const isClickEvent = event.type === "mousedown";+ const isDragEvent = event.type.startsWith("drag");+ // if (event instanceof DragEvent && event.dataTransfer) {+ // console.log(+ // `[${event.type}]:`,+ // this.editor.view.dragging,+ // event.dataTransfer.getData("Text"),+ // event.dataTransfer.getData("text/plain"),+ // event.dataTransfer.getData("text/html")+ // );+ // }+ // ProseMirror tries to drag selectable nodes+ // even if `draggable` is set to `false`+ // this fix prevents that+ if (!isDraggable && isSelectable && isDragEvent) {+ event.preventDefault();+ }+ if (isDraggable && isDragEvent && !isDragging) {+ event.preventDefault();+ return false;+ }+ // we have to store that dragging started+ if (isDraggable && isEditable && !isDragging && isClickEvent) {+ const dragHandle = target.closest("[data-drag-handle]");+ const isValidDragHandle = dragHandle &&+ (this.dom === dragHandle || this.dom.contains(dragHandle));+ if (isValidDragHandle) {+ this.isDragging = true;+ document.addEventListener("dragend", () => {+ this.isDragging = false;+ }, { once: true });+ document.addEventListener("mouseup", () => {+ this.isDragging = false;+ }, { once: true });+ }+ }+ // these events are handled by prosemirror+ if (isDragging ||+ isDropEvent ||+ isCopyEvent ||+ isPasteEvent ||+ isCutEvent ||+ (isClickEvent && isSelectable)) {+ return false;+ }+ return true;+ }+ ignoreMutation(mutation) {+ if (!this.dom || !this.contentDOM) {+ return true;+ }+ // TODO if (typeof this.options.ignoreMutation === 'function') {+ // return this.options.ignoreMutation({ mutation })+ // }+ // a leaf/atom node is like a black box for ProseMirror+ // and should be fully handled by the node view+ if (this.node.isLeaf || this.node.isAtom) {+ return true;+ }+ // ProseMirror should handle any selections+ if (mutation.type === "selection") {+ return false;+ }+ // try to prevent a bug on mobiles that will break node views on enter+ // this is because ProseMirror can’t preventDispatch on enter+ // this will lead to a re-render of the node view on enter+ // see: https://github.com/ueberdosis/tiptap/issues/1214+ if (this.dom.contains(mutation.target) &&+ mutation.type === "childList" &&+ this.editor.isFocused) {+ const changedNodes = [+ ...Array.from(mutation.addedNodes),+ ...Array.from(mutation.removedNodes),+ ];+ // we’ll check if every changed node is contentEditable+ // to make sure it’s probably mutated by ProseMirror+ if (changedNodes.every((node) => node.isContentEditable)) {+ return false;+ }+ }+ // we will allow mutation contentDOM with attributes+ // so we can for example adding classes within our node view+ if (this.contentDOM === mutation.target && mutation.type === "attributes") {+ return true;+ }+ // ProseMirror should handle any changes within contentDOM+ if (this.contentDOM.contains(mutation.target)) {+ return false;+ }+ return true;+ }+ viewShouldUpdate(nextNode) {+ if (this.options.shouldUpdate)+ return this.options.shouldUpdate(this.node, nextNode);+ return true;+ }+ /**+ * Copies the attributes from a ProseMirror Node to a DOM node.+ * @param node The Prosemirror Node from which to source the attributes+ */+ setDomAttrs(node, element) {+ Object.keys(node.attrs || {}).forEach((attr) => {+ element.setAttribute(attr, node.attrs[attr]);+ });+ }+ get dom() {+ return this.domRef;+ }+ destroy() {+ if (!this.domRef || !this.portalProviderAPI) {+ return;+ }+ this.portalProviderAPI.remove(this.domRef);+ // @ts-ignore NEW PM API+ this.domRef = undefined;+ this.contentDOM = undefined;+ }+}+export function createNodeView(component, options) {+ return ({ node, getPos, editor }) => {+ const _getPos = () => (typeof getPos === "boolean" ? -1 : getPos());+ return new ReactNodeView(node, editor, _getPos, Object.assign(Object.assign({}, options), { component })).init();+ };+}+// function isiOS(): boolean {+// return (+// [+// "iPad Simulator",+// "iPhone Simulator",+// "iPod Simulator",+// "iPad",+// "iPhone",+// "iPod",+// ].includes(navigator.platform) ||+// // iPad on iOS 13 detection+// (navigator.userAgent.includes("Mac") && "ontouchend" in document)+// );+// }+function forceHandleDrag(event, editor) {+ if (!event.dataTransfer)+ return;+ const { view } = editor;+ const slice = view.state.selection.content();+ const { dom, text } = __serializeForClipboard(view, slice);+ event.dataTransfer.clearData();+ event.dataTransfer.setData("Text", text);+ event.dataTransfer.setData("text/plain", text);+ event.dataTransfer.setData("text/html", dom.innerHTML);+ event.dataTransfer.effectAllowed = "copyMove";+ view.dragging = { slice, move: true };+}diff --git a/packages/editor/dist/es/extensions/react/reactportalprovider.d.ts b/packages/editor/dist/es/extensions/react/reactportalprovider.d.tsnew file mode 100644index 000000000..a6a95fd3e--- /dev/null+++ b/packages/editor/dist/es/extensions/react/reactportalprovider.d.ts@@ -0,0 +1,37 @@+import React, { PropsWithChildren } from "react";+import { EventDispatcher } from "./event-dispatcher";+export declare type BasePortalProviderProps = PropsWithChildren<{}>;+export declare type Portals = Map<HTMLElement, React.ReactChild>;+export declare type PortalRendererState = {+ portals: Portals;+};+declare type MountedPortal = {+ children: () => React.ReactChild | null;+};+export declare class PortalProviderAPI extends EventDispatcher {+ portals: Map<HTMLElement, MountedPortal>;+ context: any;+ constructor();+ setContext: (context: any) => void;+ render(children: () => React.ReactChild | JSX.Element | null, container: HTMLElement): void;+ forceUpdate(): void;+ remove(container: HTMLElement): void;+}+export declare function usePortalProvider(): PortalProviderAPI | undefined;+export declare class PortalProvider extends React.Component<BasePortalProviderProps> {+ static displayName: string;+ portalProviderAPI: PortalProviderAPI;+ constructor(props: BasePortalProviderProps);+ render(): JSX.Element;+ componentDidUpdate(): void;+}+export declare class PortalRenderer extends React.Component<{+ portalProviderAPI: PortalProviderAPI;+}, PortalRendererState> {+ constructor(props: {+ portalProviderAPI: PortalProviderAPI;+ });+ handleUpdate: (portals: Portals) => void;+ render(): JSX.Element;+}+export {};diff --git a/packages/editor/dist/es/extensions/react/reactportalprovider.js b/packages/editor/dist/es/extensions/react/reactportalprovider.jsnew file mode 100644index 000000000..8bf1867bf--- /dev/null+++ b/packages/editor/dist/es/extensions/react/reactportalprovider.js@@ -0,0 +1,69 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import React, { useContext } from "react";+import { createPortal, unstable_renderSubtreeIntoContainer, unmountComponentAtNode, } from "react-dom";+import { EventDispatcher } from "./event-dispatcher";+export class PortalProviderAPI extends EventDispatcher {+ constructor() {+ super();+ this.portals = new Map();+ this.setContext = (context) => {+ this.context = context;+ };+ }+ render(children, container) {+ this.portals.set(container, {+ children,+ });+ let wrappedChildren = children();+ unstable_renderSubtreeIntoContainer(this.context, wrappedChildren, container);+ }+ // TODO: until https://product-fabric.atlassian.net/browse/ED-5013+ // we (unfortunately) need to re-render to pass down any updated context.+ // selectively do this for nodeviews that opt-in via `hasAnalyticsContext`+ forceUpdate() { }+ remove(container) {+ this.portals.delete(container);+ // There is a race condition that can happen caused by Prosemirror vs React,+ // where Prosemirror removes the container from the DOM before React gets+ // around to removing the child from the container+ // This will throw a NotFoundError: The node to be removed is not a child of this node+ // Both Prosemirror and React remove the elements asynchronously, and in edge+ // cases Prosemirror beats React+ try {+ unmountComponentAtNode(container);+ }+ catch (error) {+ // IGNORE console.error(error);+ }+ }+}+const PortalProviderContext = React.createContext(undefined);+export function usePortalProvider() {+ return useContext(PortalProviderContext);+}+export class PortalProvider extends React.Component {+ constructor(props) {+ super(props);+ this.portalProviderAPI = new PortalProviderAPI();+ }+ render() {+ return (_jsxs(PortalProviderContext.Provider, Object.assign({ value: this.portalProviderAPI }, { children: [this.props.children, _jsx(PortalRenderer, { portalProviderAPI: this.portalProviderAPI })] })));+ }+ componentDidUpdate() {+ this.portalProviderAPI.forceUpdate();+ }+}+PortalProvider.displayName = "PortalProvider";+export class PortalRenderer extends React.Component {+ constructor(props) {+ super(props);+ this.handleUpdate = (portals) => this.setState({ portals });+ props.portalProviderAPI.setContext(this);+ props.portalProviderAPI.on("update", this.handleUpdate);+ this.state = { portals: new Map() };+ }+ render() {+ const { portals } = this.state;+ return (_jsx(_Fragment, { children: Array.from(portals.entries()).map(([container, children]) => createPortal(children, container)) }));+ }+}diff --git a/packages/editor/dist/es/extensions/react/selectionbasedreactnodeview.d.ts b/packages/editor/dist/es/extensions/react/selectionbasedreactnodeview.d.tsnew file mode 100644index 000000000..dd4fec1a9--- /dev/null+++ b/packages/editor/dist/es/extensions/react/selectionbasedreactnodeview.d.ts@@ -0,0 +1,53 @@+import React from "react";+import { Node as PMNode } from "prosemirror-model";+import { ReactNodeViewOptions, GetPosNode, SelectionBasedReactNodeViewProps, ForwardRef } from "./types";+import { ReactNodeView } from "./react-node-view";+import { Editor, NodeViewRendererProps } from "@tiptap/core";+/**+ * A ReactNodeView that handles React components sensitive+ * to selection changes.+ *+ * If the selection changes, it will attempt to re-render the+ * React component. Otherwise it does nothing.+ *+ * You can subclass `viewShouldUpdate` to include other+ * props that your component might want to consider before+ * entering the React lifecycle. These are usually props you+ * compare in `shouldComponentUpdate`.+ *+ * An example:+ *+ * ```+ * viewShouldUpdate(nextNode) {+ * if (nextNode.attrs !== this.node.attrs) {+ * return true;+ * }+ *+ * return super.viewShouldUpdate(nextNode);+ * }```+ */+export declare class SelectionBasedNodeView<P extends SelectionBasedReactNodeViewProps> extends ReactNodeView<P> {+ private oldSelection;+ private selectionChangeState;+ pos: number;+ posEnd: number | undefined;+ constructor(node: PMNode, editor: Editor, getPos: GetPosNode, options: ReactNodeViewOptions<P>);+ render(props?: P, forwardRef?: ForwardRef): React.ReactElement<any> | null;+ /**+ * Update current node's start and end positions.+ *+ * Prefer `this.pos` rather than getPos(), because calling getPos is+ * expensive, unless you know you're definitely going to render.+ */+ private updatePos;+ private getPositionsWithDefault;+ isNodeInsideSelection: (from: number, to: number, pos?: number, posEnd?: number) => boolean;+ isSelectionInsideNode: (from: number, to: number, pos?: number, posEnd?: number) => boolean;+ private isSelectedNode;+ insideSelection: () => boolean;+ nodeInsideSelection: () => boolean;+ viewShouldUpdate(nextNode: PMNode): boolean;+ destroy(): void;+ private onSelectionChange;+}+export declare function createSelectionBasedNodeView<TProps extends SelectionBasedReactNodeViewProps>(component: React.ComponentType<TProps>, options?: Omit<ReactNodeViewOptions<TProps>, "component">): ({ node, getPos, editor }: NodeViewRendererProps) => SelectionBasedNodeView<TProps>;diff --git a/packages/editor/dist/es/extensions/react/selectionbasedreactnodeview.js b/packages/editor/dist/es/extensions/react/selectionbasedreactnodeview.jsnew file mode 100644index 000000000..21dd1b9c4--- /dev/null+++ b/packages/editor/dist/es/extensions/react/selectionbasedreactnodeview.js@@ -0,0 +1,145 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { DecorationSet } from "prosemirror-view";+import { NodeSelection } from "prosemirror-state";+import { stateKey as SelectionChangePluginKey, } from "./plugin";+import { ReactNodeView } from "./react-node-view";+import { ThemeProvider } from "emotion-theming";+/**+ * A ReactNodeView that handles React components sensitive+ * to selection changes.+ *+ * If the selection changes, it will attempt to re-render the+ * React component. Otherwise it does nothing.+ *+ * You can subclass `viewShouldUpdate` to include other+ * props that your component might want to consider before+ * entering the React lifecycle. These are usually props you+ * compare in `shouldComponentUpdate`.+ *+ * An example:+ *+ * ```+ * viewShouldUpdate(nextNode) {+ * if (nextNode.attrs !== this.node.attrs) {+ * return true;+ * }+ *+ * return super.viewShouldUpdate(nextNode);+ * }```+ */+export class SelectionBasedNodeView extends ReactNodeView {+ constructor(node, editor, getPos, options) {+ super(node, editor, getPos, options);+ this.pos = -1;+ this.isNodeInsideSelection = (from, to, pos, posEnd) => {+ ({ pos, posEnd } = this.getPositionsWithDefault(pos, posEnd));+ if (typeof pos !== "number" || typeof posEnd !== "number") {+ return false;+ }+ return from <= pos && to >= posEnd;+ };+ this.isSelectionInsideNode = (from, to, pos, posEnd) => {+ ({ pos, posEnd } = this.getPositionsWithDefault(pos, posEnd));+ if (typeof pos !== "number" || typeof posEnd !== "number") {+ return false;+ }+ return pos < from && to < posEnd;+ };+ this.isSelectedNode = (selection) => {+ if (selection instanceof NodeSelection) {+ const { selection: { from, to }, } = this.editor.view.state;+ return (selection.node === this.node ||+ // If nodes are not the same object, we check if they are referring to the same document node+ (this.pos === from &&+ this.posEnd === to &&+ selection.node.eq(this.node)));+ }+ return false;+ };+ this.insideSelection = () => {+ const { selection: { from, to }, } = this.editor.view.state;+ return (this.isSelectedNode(this.editor.view.state.selection) ||+ this.isSelectionInsideNode(from, to));+ };+ this.nodeInsideSelection = () => {+ const { selection } = this.editor.view.state;+ const { from, to } = selection;+ return (this.isSelectedNode(selection) || this.isNodeInsideSelection(from, to));+ };+ this.onSelectionChange = () => {+ this.update(this.node, [], DecorationSet.empty);+ };+ this.updatePos();+ this.oldSelection = editor.view.state.selection;+ this.selectionChangeState = SelectionChangePluginKey.getState(this.editor.view.state);+ this.selectionChangeState.subscribe(this.onSelectionChange);+ }+ render(props = {}, forwardRef) {+ if (!this.options.component)+ return null;+ const theme = this.editor.storage.theme;+ const isSelected = this.editor.isEditable &&+ (this.insideSelection() || this.nodeInsideSelection());+ return (_jsx(ThemeProvider, Object.assign({ theme: theme }, { children: _jsx(this.options.component, Object.assign({}, props, { editor: this.editor, getPos: this.getPos, node: this.node, forwardRef: forwardRef, selected: isSelected, updateAttributes: (attr) => this.updateAttributes(attr, this.pos) })) })));+ }+ /**+ * Update current node's start and end positions.+ *+ * Prefer `this.pos` rather than getPos(), because calling getPos is+ * expensive, unless you know you're definitely going to render.+ */+ updatePos() {+ if (typeof this.getPos === "boolean") {+ return;+ }+ this.pos = this.getPos();+ this.posEnd = this.pos + this.node.nodeSize;+ }+ getPositionsWithDefault(pos, posEnd) {+ return {+ pos: typeof pos !== "number" ? this.pos : pos,+ posEnd: typeof posEnd !== "number" ? this.posEnd : posEnd,+ };+ }+ viewShouldUpdate(nextNode) {+ if (super.viewShouldUpdate(nextNode))+ return true;+ const { state: { selection }, } = this.editor.view;+ // update selection+ const oldSelection = this.oldSelection;+ this.oldSelection = selection;+ // update cached positions+ const { pos: oldPos, posEnd: oldPosEnd } = this;+ this.updatePos();+ const { from, to } = selection;+ const { from: oldFrom, to: oldTo } = oldSelection;+ if (this.node.type.spec.selectable) {+ const newNodeSelection = selection instanceof NodeSelection && selection.from === this.pos;+ const oldNodeSelection = oldSelection instanceof NodeSelection && oldSelection.from === this.pos;+ if ((newNodeSelection && !oldNodeSelection) ||+ (oldNodeSelection && !newNodeSelection)) {+ return true;+ }+ }+ const movedInToSelection = this.isNodeInsideSelection(from, to) &&+ !this.isNodeInsideSelection(oldFrom, oldTo);+ const movedOutOfSelection = !this.isNodeInsideSelection(from, to) &&+ this.isNodeInsideSelection(oldFrom, oldTo);+ const moveOutFromOldSelection = this.isNodeInsideSelection(from, to, oldPos, oldPosEnd) &&+ !this.isNodeInsideSelection(from, to);+ if (movedInToSelection || movedOutOfSelection || moveOutFromOldSelection) {+ return true;+ }+ return false;+ }+ destroy() {+ this.selectionChangeState.unsubscribe(this.onSelectionChange);+ super.destroy();+ }+}+export function createSelectionBasedNodeView(component, options) {+ return ({ node, getPos, editor }) => {+ const _getPos = () => (typeof getPos === "boolean" ? -1 : getPos());+ return new SelectionBasedNodeView(node, editor, _getPos, Object.assign(Object.assign({}, options), { component })).init();+ };+}diff --git a/packages/editor/dist/es/extensions/react/types.d.ts b/packages/editor/dist/es/extensions/react/types.d.tsnew file mode 100644index 000000000..58d9a0b1b--- /dev/null+++ b/packages/editor/dist/es/extensions/react/types.d.ts@@ -0,0 +1,35 @@+/// <reference types="react" />+import { Editor } from "@tiptap/core";+import { Node as PMNode, Attrs } from "prosemirror-model";+export interface ReactNodeProps {+ selected: boolean;+}+export declare type NodeWithAttrs<T> = PMNode & {+ attrs: T;+};+export declare type GetPos = GetPosNode | boolean;+export declare type GetPosNode = () => number;+export declare type ForwardRef = (node: HTMLElement | null) => void;+export declare type ShouldUpdate = (prevNode: PMNode, nextNode: PMNode) => boolean;+export declare type UpdateAttributes<T> = (attributes: Partial<T>) => void;+export declare type ContentDOM = {+ dom: HTMLElement;+ contentDOM?: HTMLElement | null | undefined;+} | undefined;+export declare type ReactNodeViewProps<TAttributes = Attrs> = {+ getPos: GetPosNode;+ node: NodeWithAttrs<TAttributes>;+ editor: Editor;+ updateAttributes: UpdateAttributes<TAttributes>;+ forwardRef?: ForwardRef;+};+export declare type SelectionBasedReactNodeViewProps<TAttributes = Attrs> = ReactNodeViewProps<TAttributes> & {+ selected: boolean;+};+export declare type ReactNodeViewOptions<P> = {+ props?: P;+ component?: React.ComponentType<P>;+ shouldUpdate?: ShouldUpdate;+ contentDOMFactory?: (() => ContentDOM) | boolean;+ wrapperFactory?: () => HTMLElement;+};diff --git a/packages/editor/dist/es/extensions/react/types.js b/packages/editor/dist/es/extensions/react/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/extensions/react/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/extensions/searchreplace/index.d.ts b/packages/editor/dist/es/extensions/searchreplace/index.d.tsnew file mode 100644index 000000000..8a016dad8--- /dev/null+++ b/packages/editor/dist/es/extensions/searchreplace/index.d.ts@@ -0,0 +1 @@+export * from "./search-replace";diff --git a/packages/editor/dist/es/extensions/searchreplace/index.js b/packages/editor/dist/es/extensions/searchreplace/index.jsnew file mode 100644index 000000000..8a016dad8--- /dev/null+++ b/packages/editor/dist/es/extensions/searchreplace/index.js@@ -0,0 +1 @@+export * from "./search-replace";diff --git a/packages/editor/dist/es/extensions/searchreplace/searchreplace.d.ts b/packages/editor/dist/es/extensions/searchreplace/searchreplace.d.tsnew file mode 100644index 000000000..dc7b33bac--- /dev/null+++ b/packages/editor/dist/es/extensions/searchreplace/searchreplace.d.ts@@ -0,0 +1,35 @@+import { Extension } from "@tiptap/core";+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ searchreplace: {+ startSearch: () => ReturnType;+ endSearch: () => ReturnType;+ search: (term: string, options?: SearchSettings) => ReturnType;+ moveToNextResult: () => ReturnType;+ moveToPreviousResult: () => ReturnType;+ replace: (term: string) => ReturnType;+ replaceAll: (term: string) => ReturnType;+ };+ }+}+interface Result {+ from: number;+ to: number;+}+interface SearchOptions {+ searchResultClass: string;+}+interface SearchSettings {+ matchCase: boolean;+ enableRegex: boolean;+ matchWholeWord: boolean;+}+export declare type SearchStorage = SearchSettings & {+ searchTerm: string;+ selectedIndex: number;+ isSearching: boolean;+ selectedText?: string;+ results?: Result[];+};+export declare const SearchReplace: Extension<SearchOptions, SearchStorage>;+export {};diff --git a/packages/editor/dist/es/extensions/searchreplace/searchreplace.js b/packages/editor/dist/es/extensions/searchreplace/searchreplace.jsnew file mode 100644index 000000000..8b22abd47--- /dev/null+++ b/packages/editor/dist/es/extensions/searchreplace/searchreplace.js@@ -0,0 +1,211 @@+import { Extension } from "@tiptap/core";+import { Decoration, DecorationSet } from "prosemirror-view";+import { Plugin, PluginKey, TextSelection, } from "prosemirror-state";+const updateView = (state, dispatch) => dispatch(state.tr);+const regex = (s, settings) => {+ const { enableRegex, matchCase, matchWholeWord } = settings;+ const boundary = matchWholeWord ? "\\b" : "";+ console.log(boundary);+ return RegExp(boundary ++ (enableRegex ? s : s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")) ++ boundary, matchCase ? "gu" : "gui");+};+function searchDocument(doc, searchResultClass, searchTerm) {+ if (!searchTerm)+ return { decorationSet: DecorationSet.empty, results: [] };+ const decorations = [];+ const results = [];+ let index = 0;+ let textNodesWithPosition = [];+ doc === null || doc === void 0 ? void 0 : doc.descendants((node, pos) => {+ if (node.isText) {+ if (textNodesWithPosition[index]) {+ textNodesWithPosition[index] = {+ text: textNodesWithPosition[index].text + node.text,+ pos: textNodesWithPosition[index].pos,+ };+ }+ else {+ textNodesWithPosition[index] = {+ text: node.text || "",+ pos,+ };+ }+ }+ else {+ index += 1;+ }+ });+ textNodesWithPosition = textNodesWithPosition.filter(Boolean);+ for (const { text, pos } of textNodesWithPosition) {+ const matches = text.matchAll(searchTerm);+ for (const m of matches) {+ if (m[0] === "")+ break;+ if (m.index !== undefined) {+ results.push({+ from: pos + m.index,+ to: pos + m.index + m[0].length,+ });+ }+ }+ }+ for (const { from, to } of results) {+ decorations.push(Decoration.inline(from, to, { class: searchResultClass }));+ }+ return {+ decorationSet: DecorationSet.create(doc, decorations),+ results,+ };+}+const replaceAll = (replaceTerm, results, tr) => {+ let offset = 0;+ if (!results.length)+ return;+ const map = tr.mapping;+ for (let i = 0; i < results.length; i += 1) {+ const { from, to } = results[i];+ tr.insertText(replaceTerm, from, to);+ if (i + 1 < results.length) {+ const { from, to } = results[i + 1];+ results[i + 1] = {+ from: map.map(from),+ to: map.map(to),+ };+ }+ }+ return tr;+};+export const SearchReplace = Extension.create({+ name: "searchreplace",+ addOptions() {+ return {+ searchResultClass: "search-result",+ };+ },+ addCommands() {+ return {+ startSearch: () => ({ state }) => {+ this.storage.isSearching = true;+ if (!state.selection.empty) {+ this.storage.selectedText = state.doc.textBetween(state.selection.$from.pos, state.selection.$to.pos);+ }+ return true;+ },+ endSearch: () => ({ state, dispatch }) => {+ this.storage.isSearching = false;+ this.storage.searchTerm = "";+ updateView(state, dispatch);+ return true;+ },+ search: (term, options) => ({ state, dispatch }) => {+ this.storage.searchTerm = term;+ 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;+ },+ moveToNextResult: () => ({ chain }) => {+ const { selectedIndex, results } = this.storage;+ if (!results || results.length <= 0)+ return false;+ let nextIndex = selectedIndex + 1;+ if (isNaN(nextIndex) || nextIndex >= results.length)+ nextIndex = 0;+ const { from, to } = results[nextIndex];+ console.log("[moveToNextResult]", from, to);+ const result = chain()+ .focus(undefined, { scrollIntoView: true })+ .setTextSelection({ from, to })+ .run();+ if (result)+ this.storage.selectedIndex = nextIndex;+ return result;+ },+ moveToPreviousResult: () => ({ chain }) => {+ const { selectedIndex, results } = this.storage;+ if (!results || results.length <= 0)+ return false;+ let prevIndex = selectedIndex - 1;+ if (isNaN(prevIndex) || prevIndex < 0)+ prevIndex = results.length - 1;+ const { from, to } = results[prevIndex];+ const result = chain()+ .focus(undefined, { scrollIntoView: true })+ .setTextSelection({ from, to })+ .run();+ if (result)+ this.storage.selectedIndex = prevIndex;+ return result;+ },+ replace: (term) => ({ commands, tr, dispatch }) => {+ const { selectedIndex, results } = this.storage;+ if (!dispatch || !results || results.length <= 0)+ return false;+ const index = selectedIndex === undefined ? 0 : selectedIndex;+ const { from, to } = results[index];+ tr.insertText(term, from, to);+ if (index + 1 < results.length) {+ const { from, to } = results[index + 1];+ const nextResult = (results[index + 1] = {+ from: tr.mapping.map(from),+ to: tr.mapping.map(to),+ });+ commands.focus();+ tr.setSelection(new TextSelection(tr.doc.resolve(nextResult.from), tr.doc.resolve(nextResult.to)));+ }+ dispatch(tr);+ results.splice(index, 1);+ return true;+ },+ replaceAll: (term) => ({ state, tr, dispatch }) => {+ if (!dispatch)+ return false;+ const { results } = this.storage;+ if (!dispatch || !results || results.length <= 0)+ return false;+ dispatch(replaceAll(term, results, tr));+ return true;+ },+ };+ },+ addKeyboardShortcuts() {+ return {+ "Mod-f": ({ editor }) => editor.commands.startSearch(),+ Escape: ({ editor }) => editor.commands.endSearch(),+ };+ },+ addProseMirrorPlugins() {+ const key = new PluginKey("searchreplace");+ return [+ new Plugin({+ key,+ state: {+ init() {+ return DecorationSet.empty;+ },+ apply: ({ doc, docChanged, setSelection }) => {+ const { searchTerm, enableRegex, matchCase, matchWholeWord } = this.storage;+ const { searchResultClass } = this.options;+ if (docChanged || searchTerm) {+ const searchRegex = searchTerm+ ? regex(searchTerm, { enableRegex, matchCase, matchWholeWord })+ : undefined;+ const { decorationSet, results } = searchDocument(doc, searchResultClass, searchRegex);+ this.storage.results = results;+ return decorationSet;+ }+ return DecorationSet.empty;+ },+ },+ props: {+ decorations(state) {+ return key.getState(state);+ },+ },+ }),+ ];+ },+});diff --git a/packages/editor/dist/es/extensions/table/actions.d.ts b/packages/editor/dist/es/extensions/table/actions.d.tsnew file mode 100644index 000000000..c4a829775--- /dev/null+++ b/packages/editor/dist/es/extensions/table/actions.d.ts@@ -0,0 +1,6 @@+import { Editor } from "@tiptap/core";+declare function moveColumnRight(editor: Editor): void;+declare function moveColumnLeft(editor: Editor): void;+declare function moveRowDown(editor: Editor): void;+declare function moveRowUp(editor: Editor): void;+export { moveColumnLeft, moveColumnRight, moveRowDown, moveRowUp };diff --git a/packages/editor/dist/es/extensions/table/actions.js b/packages/editor/dist/es/extensions/table/actions.jsnew file mode 100644index 000000000..81ce084ac--- /dev/null+++ b/packages/editor/dist/es/extensions/table/actions.js@@ -0,0 +1,105 @@+import { selectedRect } from "@_ueberdosis/prosemirror-tables";+function moveColumnRight(editor) {+ const { tr } = editor.state;+ const rect = selectedRect(editor.state);+ if (rect.right === rect.map.width)+ return;+ const transaction = moveColumn(tr, rect, rect.left, rect.left + 1);+ if (!transaction)+ return;+ editor.view.dispatch(transaction);+}+function moveColumnLeft(editor) {+ const { tr } = editor.state;+ const rect = selectedRect(editor.state);+ if (rect.left === 0)+ return;+ const transaction = moveColumn(tr, rect, rect.left, rect.left - 1);+ if (!transaction)+ return;+ editor.view.dispatch(transaction);+}+function moveRowDown(editor) {+ const { tr } = editor.state;+ const rect = selectedRect(editor.state);+ if (rect.top + 1 === rect.map.height)+ return;+ const transaction = moveRow(tr, rect, rect.top, rect.top + 1);+ if (!transaction)+ return;+ editor.view.dispatch(transaction);+}+function moveRowUp(editor) {+ const { tr } = editor.state;+ const rect = selectedRect(editor.state);+ if (rect.top === 0)+ return;+ const transaction = moveRow(tr, rect, rect.top, rect.top - 1);+ if (!transaction)+ return;+ editor.view.dispatch(transaction);+}+function moveColumn(tr, rect, from, to) {+ let fromCells = getColumnCells(rect, from);+ let toCells = getColumnCells(rect, to);+ return moveCells(tr, rect, fromCells, toCells);+}+function getColumnCells({ map, table }, col) {+ let cells = [];+ for (let row = 0; row < map.height;) {+ let index = row * map.width + col;+ if (index >= map.map.length)+ break;+ let pos = map.map[index];+ let cell = table.nodeAt(pos);+ if (!cell)+ continue;+ cells.push({ cell, pos });+ row += cell.attrs.rowspan;+ }+ return cells;+}+function moveRow(tr, rect, from, to) {+ let fromCells = getRowCells(rect, from);+ let toCells = getRowCells(rect, to);+ return moveCells(tr, rect, fromCells, toCells);+}+function getRowCells({ map, table }, row) {+ let cells = [];+ for (let col = 0, index = row * map.width; col < map.width; col++, index++) {+ if (index >= map.map.length)+ break;+ let pos = map.map[index];+ let cell = table.nodeAt(pos);+ if (!cell)+ continue;+ cells.push({ cell, pos });+ col += cell.attrs.colspan - 1;+ }+ return cells;+}+function moveCells(tr, rect, fromCells, toCells) {+ if (fromCells.length !== toCells.length)+ return;+ let mapStart = tr.mapping.maps.length;+ for (let i = 0; i < toCells.length; ++i) {+ const fromCell = fromCells[i];+ const toCell = toCells[i];+ let fromStart = tr.mapping+ .slice(mapStart)+ .map(rect.tableStart + fromCell.pos);+ let fromEnd = fromStart + fromCell.cell.nodeSize;+ const fromSlice = tr.doc.slice(fromStart, fromEnd);+ const toStart = tr.mapping+ .slice(mapStart)+ .map(rect.tableStart + toCell.pos);+ const toEnd = toStart + toCell.cell.nodeSize;+ const toSlice = tr.doc.slice(toStart, toEnd);+ tr.replace(toStart, toEnd, fromSlice);+ fromStart = tr.mapping.slice(mapStart).map(rect.tableStart + fromCell.pos);+ fromEnd = fromStart + fromCell.cell.nodeSize;+ tr.replace(fromStart, fromEnd, toSlice);+ }+ return tr;+}+export { moveColumnLeft, moveColumnRight, moveRowDown, moveRowUp };diff --git a/packages/editor/dist/es/extensions/table/component.d.ts b/packages/editor/dist/es/extensions/table/component.d.tsnew file mode 100644index 000000000..75bda7e5d--- /dev/null+++ b/packages/editor/dist/es/extensions/table/component.d.ts@@ -0,0 +1,6 @@+/// <reference types="react" />+import { SelectionBasedReactNodeViewProps } from "../react";+import { Editor } from "@tiptap/core";+import { NodeView } from "prosemirror-view";+export declare function TableComponent(props: SelectionBasedReactNodeViewProps): JSX.Element;+export declare function TableNodeView(editor: Editor): NodeView;diff --git a/packages/editor/dist/es/extensions/table/component.js b/packages/editor/dist/es/extensions/table/component.jsnew file mode 100644index 000000000..9fcb280b7--- /dev/null+++ b/packages/editor/dist/es/extensions/table/component.js@@ -0,0 +1,121 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { Flex } from "rebass";+import { SelectionBasedNodeView, } from "../react";+import { useEffect, useRef } from "react";+import { updateColumnsOnResize } from "@_ueberdosis/prosemirror-tables";+import { InsertColumnRight, InsertRowBelow, RowProperties, TableProperties, } from "../../toolbar/tools/table";+import { getToolDefinition } from "../../toolbar/tool-definitions";+import { getPosition } from "../../utils/position";+import { findSelectedDOMNode } from "../../toolbar/utils/prosemirror";+import { DesktopOnly } from "../../components/responsive";+export function TableComponent(props) {+ const { editor, node, forwardRef } = props;+ const colgroupRef = useRef(null);+ const tableRef = useRef();+ const selected = editor.isActive("table");+ useEffect(() => {+ if (!colgroupRef.current || !tableRef.current)+ return;+ updateColumnsOnResize(node, colgroupRef.current, tableRef.current, 50);+ }, [node]);+ return (_jsxs(_Fragment, { children: [_jsx(DesktopOnly, { children: selected && (_jsxs(_Fragment, { children: [_jsx(TableRowToolbar, { editor: editor, table: tableRef.current }), _jsx(TableColumnToolbar, { editor: editor, table: tableRef.current })] })) }), _jsx("div", Object.assign({ className: "tableWrapper" }, { children: _jsx("table", Object.assign({ ref: (ref) => {+ forwardRef === null || forwardRef === void 0 ? void 0 : forwardRef(ref);+ tableRef.current = ref || undefined;+ } }, { children: _jsx("colgroup", { ref: colgroupRef }) })) }))] }));+}+export function TableNodeView(editor) {+ class TableNode extends SelectionBasedNodeView {+ constructor(node, cellMinWidth) {+ super(node, editor, () => 0, // todo+ {+ component: TableComponent,+ shouldUpdate: (prev, next) => {+ return prev.type === next.type;+ },+ contentDOMFactory: () => {+ const dom = document.createElement("tbody");+ return { dom };+ },+ wrapperFactory: () => {+ const dom = document.createElement("div");+ dom.style.position = "relative";+ return dom;+ },+ });+ super.init();+ }+ }+ return TableNode;+}+function TableRowToolbar(props) {+ const { editor } = props;+ const rowToolsRef = useRef(null);+ useEffect(() => {+ if (!rowToolsRef.current) {+ return;+ }+ const currentRow = findSelectedDOMNode(editor, ["tableRow"]);+ if (!currentRow)+ return;+ const pos = getPosition(rowToolsRef.current, {+ location: "left",+ target: currentRow,+ align: "start",+ xOffset: -5,+ yOffset: -3,+ });+ rowToolsRef.current.style.top = `${pos.top}px`;+ rowToolsRef.current.style.left = `${pos.left}px`;+ }, [editor.state.selection, rowToolsRef.current]);+ return (_jsxs(Flex, Object.assign({ ref: rowToolsRef, sx: {+ zIndex: 999,+ top: 0,+ left: 0,+ position: "absolute",+ bg: "background",+ flexWrap: "nowrap",+ borderRadius: "default",+ opacity: 0.3,+ ":hover": {+ opacity: 1,+ },+ } }, { children: [_jsx(RowProperties, Object.assign({}, getToolDefinition("rowProperties"), { icon: "more", variant: "small", editor: editor })), _jsx(InsertRowBelow, Object.assign({}, getToolDefinition("insertRowBelow"), { editor: editor, variant: "small" }))] })));+}+function TableColumnToolbar(props) {+ const { editor, table } = props;+ const columnToolsRef = useRef(null);+ useEffect(() => {+ if (!columnToolsRef.current || !table) {+ return;+ }+ const currentCell = findSelectedDOMNode(editor, [+ "tableCell",+ "tableHeader",+ ]);+ if (!currentCell)+ return;+ // tableRef.current+ const pos = getPosition(columnToolsRef.current, {+ location: "top",+ align: "center",+ target: currentCell,+ yAnchor: table,+ yOffset: 2,+ });+ columnToolsRef.current.style.left = `${pos.left}px`;+ columnToolsRef.current.style.top = `${pos.top}px`;+ }, [editor.state.selection, columnToolsRef.current, table]);+ return (_jsxs(Flex, Object.assign({ ref: columnToolsRef, sx: {+ zIndex: 999,+ top: 0,+ left: 0,+ position: "absolute",+ bg: "background",+ flexWrap: "nowrap",+ borderRadius: "default",+ opacity: 0.3,+ ":hover": {+ opacity: 1,+ },+ } }, { children: [_jsx(TableProperties, { editor: editor, title: "tableProperties", icon: "more", variant: "small" }), _jsx(InsertColumnRight, Object.assign({}, getToolDefinition("insertColumnRight"), { editor: editor, variant: "small", icon: "plus" }))] })));+}diff --git a/packages/editor/dist/es/extensions/table/index.d.ts b/packages/editor/dist/es/extensions/table/index.d.tsnew file mode 100644index 000000000..0e948df9e--- /dev/null+++ b/packages/editor/dist/es/extensions/table/index.d.ts@@ -0,0 +1 @@+export * from "./table";diff --git a/packages/editor/dist/es/extensions/table/index.js b/packages/editor/dist/es/extensions/table/index.jsnew file mode 100644index 000000000..0e948df9e--- /dev/null+++ b/packages/editor/dist/es/extensions/table/index.js@@ -0,0 +1 @@+export * from "./table";diff --git a/packages/editor/dist/es/extensions/table/table.d.ts b/packages/editor/dist/es/extensions/table/table.d.tsnew file mode 100644index 000000000..e5a29b0de--- /dev/null+++ b/packages/editor/dist/es/extensions/table/table.d.ts@@ -0,0 +1,2 @@+import { TableOptions } from "@tiptap/extension-table";+export declare const Table: import("@tiptap/core").Node<TableOptions, any>;diff --git a/packages/editor/dist/es/extensions/table/table.js b/packages/editor/dist/es/extensions/table/table.jsnew file mode 100644index 000000000..7bcd80f95--- /dev/null+++ b/packages/editor/dist/es/extensions/table/table.js@@ -0,0 +1,25 @@+import { Table as TiptapTable } from "@tiptap/extension-table";+import { columnResizing, tableEditing } from "@_ueberdosis/prosemirror-tables";+import { TableNodeView } from "./component";+export const Table = TiptapTable.extend({+ addProseMirrorPlugins() {+ const isResizable = this.options.resizable && this.editor.isEditable;+ return [+ ...(isResizable+ ? [+ columnResizing({+ handleWidth: this.options.handleWidth,+ cellMinWidth: this.options.cellMinWidth,+ View: TableNodeView(this.editor),+ // TODO: PR for @types/prosemirror-tables+ // @ts-ignore (incorrect type)+ lastColumnResizable: this.options.lastColumnResizable,+ }),+ ]+ : []),+ tableEditing({+ allowTableNodeSelection: this.options.allowTableNodeSelection,+ }),+ ];+ },+});diff --git a/packages/editor/dist/es/extensions/tablecell/index.d.ts b/packages/editor/dist/es/extensions/tablecell/index.d.tsnew file mode 100644index 000000000..a85cac945--- /dev/null+++ b/packages/editor/dist/es/extensions/tablecell/index.d.ts@@ -0,0 +1,3 @@+import { TableCell } from "./table-cell";+export * from "./table-cell";+export default TableCell;diff --git a/packages/editor/dist/es/extensions/tablecell/index.js b/packages/editor/dist/es/extensions/tablecell/index.jsnew file mode 100644index 000000000..a85cac945--- /dev/null+++ b/packages/editor/dist/es/extensions/tablecell/index.js@@ -0,0 +1,3 @@+import { TableCell } from "./table-cell";+export * from "./table-cell";+export default TableCell;diff --git a/packages/editor/dist/es/extensions/tablecell/tablecell.d.ts b/packages/editor/dist/es/extensions/tablecell/tablecell.d.tsnew file mode 100644index 000000000..16c4d1e28--- /dev/null+++ b/packages/editor/dist/es/extensions/tablecell/tablecell.d.ts@@ -0,0 +1 @@+export declare const TableCell: import("@tiptap/core").Node<import("@tiptap/extension-table-cell").TableCellOptions, any>;diff --git a/packages/editor/dist/es/extensions/tablecell/tablecell.js b/packages/editor/dist/es/extensions/tablecell/tablecell.jsnew file mode 100644index 000000000..57012eb42--- /dev/null+++ b/packages/editor/dist/es/extensions/tablecell/tablecell.js@@ -0,0 +1,26 @@+import TiptapTableCell from "@tiptap/extension-table-cell";+export const TableCell = TiptapTableCell.extend({+ addAttributes() {+ var _a;+ return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { backgroundColor: addStyleAttribute("backgroundColor", "background-color"), color: addStyleAttribute("color", "color"), borderWidth: addStyleAttribute("borderWidth", "border-width", "px"), borderStyle: addStyleAttribute("borderStyle", "border-style"), borderColor: addStyleAttribute("borderColor", "border-color") });+ },+});+function addStyleAttribute(name, cssName, unit) {+ return {+ default: null,+ parseHTML: (element) => {+ var _a;+ return unit+ ? (_a = element.style[name]) === null || _a === void 0 ? void 0 : _a.toString().replace(unit, "")+ : element.style[name];+ },+ renderHTML: (attributes) => {+ if (!attributes[name]) {+ return {};+ }+ return {+ style: `${cssName}: ${attributes[name]}${unit || ""}`,+ };+ },+ };+}diff --git a/packages/editor/dist/es/extensions/taskitem/component.d.ts b/packages/editor/dist/es/extensions/taskitem/component.d.tsnew file mode 100644index 000000000..b01ab35de--- /dev/null+++ b/packages/editor/dist/es/extensions/taskitem/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ReactNodeViewProps } from "../react";+import { TaskItemAttributes } from "./task-item";+export declare function TaskItemComponent(props: ReactNodeViewProps<TaskItemAttributes>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/taskitem/component.js b/packages/editor/dist/es/extensions/taskitem/component.jsnew file mode 100644index 000000000..00cd6b965--- /dev/null+++ b/packages/editor/dist/es/extensions/taskitem/component.js@@ -0,0 +1,81 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { Flex, Text } from "rebass";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { findChildren, } from "@tiptap/core";+import { useCallback } from "react";+import { TaskItemNode } from "./task-item";+export function TaskItemComponent(props) {+ const { editor, updateAttributes, node, getPos, forwardRef } = props;+ const { checked } = props.node.attrs;+ const toggle = useCallback(() => {+ if (!editor.isEditable)+ return false;+ updateAttributes({ checked: !checked });+ editor.commands.command(({ tr }) => {+ const parentPos = getPos();+ toggleChildren(node, tr, !checked, parentPos);+ return true;+ });+ return true;+ }, [editor, getPos, node, checked]);+ return (_jsx(_Fragment, { children: _jsxs(Flex, Object.assign({ "data-drag-image": true, sx: {+ ":hover > .dragHandle": {+ opacity: editor.isEditable ? 1 : 0,+ },+ } }, { children: [_jsx(Icon, { className: "dragHandle", draggable: "true", "data-drag-handle": true, path: Icons.dragHandle, sx: {+ opacity: [1, 1, 0],+ alignSelf: "start",+ mr: 2,+ bg: "transparent",+ cursor: "grab",+ ".icon:hover path": {+ fill: "var(--checked) !important",+ },+ }, size: 20 }), _jsx(Icon, { path: checked ? Icons.check : "", stroke: "1px", sx: {+ border: "2px solid",+ borderColor: checked ? "checked" : "icon",+ borderRadius: "default",+ alignSelf: "start",+ mr: 2,+ p: "1px",+ cursor: editor.isEditable ? "pointer" : "unset",+ ":hover": {+ borderColor: "checked",+ },+ ":hover .icon path": {+ fill: "var(--checked) !important",+ },+ }, onMouseDown: (e) => {+ e.preventDefault();+ toggle();+ }, color: checked ? "checked" : "icon", size: 13 }), _jsx(Text, { as: "div", ref: forwardRef, sx: {+ textDecorationLine: checked ? "line-through" : "none",+ color: checked ? "var(--checked)" : "var(--text)",+ flex: 1,+ } })] })) }));+}+function toggleChildren(node, tr, toggleState, parentPos) {+ const children = findChildren(node, (node) => node.type.name === TaskItemNode.name);+ for (const { pos } of children) {+ // need to add 1 to get inside the node+ const actualPos = pos + parentPos + 1;+ tr.setNodeMarkup(actualPos, undefined, {+ checked: toggleState,+ });+ }+ return tr;+}+function getChildren(node, parentPos) {+ const children = [];+ node.forEach((node, offset) => {+ children.push({ node, pos: parentPos + offset + 1 });+ });+ return children;+}+function areAllChecked(node) {+ const children = findChildren(node, (node) => node.type.name === TaskItemNode.name);+ if (children.length <= 0)+ return undefined;+ return children.every((node) => node.node.attrs.checked);+}diff --git a/packages/editor/dist/es/extensions/taskitem/index.d.ts b/packages/editor/dist/es/extensions/taskitem/index.d.tsnew file mode 100644index 000000000..3518ff3b2--- /dev/null+++ b/packages/editor/dist/es/extensions/taskitem/index.d.ts@@ -0,0 +1 @@+export * from "./task-item";diff --git a/packages/editor/dist/es/extensions/taskitem/index.js b/packages/editor/dist/es/extensions/taskitem/index.jsnew file mode 100644index 000000000..3518ff3b2--- /dev/null+++ b/packages/editor/dist/es/extensions/taskitem/index.js@@ -0,0 +1 @@+export * from "./task-item";diff --git a/packages/editor/dist/es/extensions/taskitem/taskitem.d.ts b/packages/editor/dist/es/extensions/taskitem/taskitem.d.tsnew file mode 100644index 000000000..32494f7fa--- /dev/null+++ b/packages/editor/dist/es/extensions/taskitem/taskitem.d.ts@@ -0,0 +1,4 @@+export declare type TaskItemAttributes = {+ checked: boolean;+};+export declare const TaskItemNode: import("@tiptap/core").Node<import("@tiptap/extension-task-item").TaskItemOptions, any>;diff --git a/packages/editor/dist/es/extensions/taskitem/taskitem.js b/packages/editor/dist/es/extensions/taskitem/taskitem.jsnew file mode 100644index 000000000..6f3ae64e0--- /dev/null+++ b/packages/editor/dist/es/extensions/taskitem/taskitem.js@@ -0,0 +1,60 @@+import { mergeAttributes } from "@tiptap/core";+import { onBackspacePressed } from "../list-item/commands";+import { TaskItem } from "@tiptap/extension-task-item";+import { TaskItemComponent } from "./component";+import { createNodeView } from "../react";+export const TaskItemNode = TaskItem.extend({+ draggable: true,+ addAttributes() {+ return {+ checked: {+ default: false,+ keepOnSplit: false,+ parseHTML: (element) => element.classList.contains("checked"),+ renderHTML: (attributes) => ({+ class: attributes.checked ? "checked" : "",+ }),+ },+ };+ },+ renderHTML({ node, HTMLAttributes }) {+ return [+ "li",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "checklist--item",+ }),+ 0,+ ];+ },+ parseHTML() {+ return [+ {+ tag: `li`,+ getAttrs: (node) => {+ var _a;+ if (node instanceof Node && node instanceof HTMLElement) {+ return node.classList.contains("checklist--item") ||+ ((_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains("checklist"))+ ? null+ : false;+ }+ return false;+ },+ priority: 51,+ },+ ];+ },+ addKeyboardShortcuts() {+ var _a;+ return Object.assign(Object.assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { Backspace: ({ editor }) => onBackspacePressed(editor, this.name, this.type) });+ },+ addNodeView() {+ return createNodeView(TaskItemComponent, {+ contentDOMFactory: true,+ wrapperFactory: () => document.createElement("li"),+ shouldUpdate: ({ attrs: prev }, { attrs: next }) => {+ return (prev.checked !== next.checked || prev.collapsed !== next.collapsed);+ },+ });+ },+});diff --git a/packages/editor/dist/es/extensions/tasklist/component.d.ts b/packages/editor/dist/es/extensions/tasklist/component.d.tsnew file mode 100644index 000000000..5cc94955c--- /dev/null+++ b/packages/editor/dist/es/extensions/tasklist/component.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ReactNodeViewProps } from "../react";+import { TaskListAttributes } from "./task-list";+export declare function TaskListComponent(props: ReactNodeViewProps<TaskListAttributes>): JSX.Element;diff --git a/packages/editor/dist/es/extensions/tasklist/component.js b/packages/editor/dist/es/extensions/tasklist/component.jsnew file mode 100644index 000000000..9e974917f--- /dev/null+++ b/packages/editor/dist/es/extensions/tasklist/component.js@@ -0,0 +1,98 @@+import { jsxs as _jsxs, jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";+import { Box, Flex, Text } from "rebass";+import { findChildren, getNodeType, } from "@tiptap/core";+import { Icon } from "../../toolbar/components/icon";+import { Icons } from "../../toolbar/icons";+import { useEffect, useMemo, useState } from "react";+import { Input } from "@rebass/forms";+import { TaskItemNode } from "../task-item";+import { findParentNodeOfTypeClosestToPos } from "prosemirror-utils";+export function TaskListComponent(props) {+ const { editor, getPos, node, updateAttributes, forwardRef } = props;+ const taskItemType = getNodeType(TaskItemNode.name, editor.schema);+ const { title, collapsed } = node.attrs;+ const [stats, setStats] = useState({ checked: 0, total: 0, percentage: 0 });+ const parentTaskItem = useMemo(() => {+ const pos = editor.state.doc.resolve(getPos());+ return findParentNodeOfTypeClosestToPos(pos, taskItemType);+ }, []);+ const nested = !!parentTaskItem;+ useEffect(() => {+ if (!parentTaskItem)+ return;+ const { node, pos } = parentTaskItem;+ const allChecked = areAllChecked(node, pos, editor.state.doc);+ // check parent item if all child items are checked.+ editor.commands.command(({ tr }) => {+ tr.setNodeMarkup(pos, undefined, { checked: allChecked });+ return true;+ });+ }, [node, parentTaskItem]);+ useEffect(() => {+ const children = findChildren(node, (node) => node.type.name === TaskItemNode.name);+ const checked = children.filter((node) => node.node.attrs.checked).length;+ const total = children.length;+ const percentage = Math.round((checked / total) * 100);+ setStats({ checked, total, percentage });+ }, [nested, node]);+ return (_jsxs(_Fragment, { children: [_jsx(Flex, Object.assign({ sx: {+ flexDirection: "column",+ ":hover > div > .toggleSublist": { opacity: 1 },+ } }, { children: nested ? (_jsxs(Flex, Object.assign({ sx: {+ position: "absolute",+ top: 0,+ right: 0,+ }, contentEditable: false }, { children: [collapsed && (_jsxs(Text, Object.assign({ variant: "body", sx: { color: "fontTertiary", mr: 35 } }, { children: [stats.checked, "/", stats.total] }))), _jsx(Icon, { className: "toggleSublist", path: collapsed ? Icons.chevronDown : Icons.chevronUp, sx: {+ opacity: collapsed ? 1 : 0,+ position: "absolute",+ right: 0,+ alignSelf: "start",+ mr: 2,+ cursor: "pointer",+ ".icon:hover path": {+ fill: "var(--checked) !important",+ },+ }, size: 20, onClick: () => {+ updateAttributes({ collapsed: !collapsed });+ } })] }))) : (_jsxs(Flex, Object.assign({ sx: {+ position: "relative",+ bg: "bgSecondary",+ py: 1,+ borderRadius: "default",+ mb: 2,+ alignItems: "center",+ justifyContent: "end",+ overflow: "hidden",+ }, contentEditable: false }, { children: [_jsx(Box, { sx: {+ height: "100%",+ width: `${stats.percentage}%`,+ position: "absolute",+ bg: "border",+ zIndex: 0,+ left: 0,+ transition: "width 250ms ease-out",+ } }), _jsx(Input, { readOnly: !editor.isEditable, value: title || "", variant: "clean", sx: { p: 0, px: 2, zIndex: 1, color: "fontTertiary" }, placeholder: "Untitled", onChange: (e) => {+ updateAttributes({ title: e.target.value });+ } }), _jsxs(Flex, Object.assign({ sx: { flexShrink: 0, pr: 2 } }, { children: [_jsx(Icon, { path: Icons.checkbox, size: 15, color: "fontTertiary" }), _jsxs(Text, Object.assign({ variant: "body", sx: { ml: 1, color: "fontTertiary" } }, { children: [stats.checked, "/", stats.total] }))] }))] }))) })), _jsx(Text, { as: "div", ref: forwardRef, sx: {+ ul: {+ display: collapsed ? "none" : "block",+ paddingInlineStart: 0,+ marginBlockStart: nested ? 10 : 0,+ marginBlockEnd: 0,+ },+ li: {+ listStyleType: "none",+ position: "relative",+ },+ } })] }));+}+function areAllChecked(node, pos, doc) {+ const children = findChildren(node, (node) => node.type.name === TaskItemNode.name);+ for (const child of children) {+ const childPos = pos + child.pos + 1;+ const node = doc.nodeAt(childPos);+ if (!(node === null || node === void 0 ? void 0 : node.attrs.checked))+ return false;+ }+ return true;+}diff --git a/packages/editor/dist/es/extensions/tasklist/index.d.ts b/packages/editor/dist/es/extensions/tasklist/index.d.tsnew file mode 100644index 000000000..291e035cb--- /dev/null+++ b/packages/editor/dist/es/extensions/tasklist/index.d.ts@@ -0,0 +1 @@+export * from "./task-list";diff --git a/packages/editor/dist/es/extensions/tasklist/index.js b/packages/editor/dist/es/extensions/tasklist/index.jsnew file mode 100644index 000000000..291e035cb--- /dev/null+++ b/packages/editor/dist/es/extensions/tasklist/index.js@@ -0,0 +1 @@+export * from "./task-list";diff --git a/packages/editor/dist/es/extensions/tasklist/tasklist.d.ts b/packages/editor/dist/es/extensions/tasklist/tasklist.d.tsnew file mode 100644index 000000000..46bdb2668--- /dev/null+++ b/packages/editor/dist/es/extensions/tasklist/tasklist.d.ts@@ -0,0 +1,5 @@+export declare type TaskListAttributes = {+ title: string;+ collapsed: boolean;+};+export declare const TaskListNode: import("@tiptap/core").Node<import("@tiptap/extension-task-list").TaskListOptions, any>;diff --git a/packages/editor/dist/es/extensions/tasklist/tasklist.js b/packages/editor/dist/es/extensions/tasklist/tasklist.jsnew file mode 100644index 000000000..0e6d2512b--- /dev/null+++ b/packages/editor/dist/es/extensions/tasklist/tasklist.js@@ -0,0 +1,84 @@+import { mergeAttributes } from "@tiptap/core";+import { TaskList } from "@tiptap/extension-task-list";+import { createNodeView } from "../react";+import { TaskListComponent } from "./component";+export const TaskListNode = TaskList.extend({+ addAttributes() {+ return {+ collapsed: {+ default: false,+ keepOnSplit: false,+ parseHTML: (element) => element.dataset.collapsed === "true",+ renderHTML: (attributes) => ({+ "data-collapsed": attributes.collapsed === true,+ }),+ },+ title: {+ default: null,+ keepOnSplit: false,+ parseHTML: (element) => element.dataset.title,+ renderHTML: (attributes) => {+ if (!attributes.title || attributes.nested) {+ return {};+ }+ return {+ "data-title": attributes.title,+ };+ },+ },+ };+ },+ parseHTML() {+ return [+ {+ tag: `ul`,+ getAttrs: (node) => {+ if (node instanceof Node && node instanceof HTMLElement) {+ return node.classList.contains("checklist") && null;+ }+ return false;+ },+ priority: 51,+ },+ ];+ },+ renderHTML({ HTMLAttributes }) {+ return [+ "ul",+ mergeAttributes(this.options.HTMLAttributes, HTMLAttributes, {+ class: "checklist",+ }),+ 0,+ ];+ },+ addCommands() {+ return {+ toggleTaskList: () => ({ editor, commands, state, tr }) => {+ const { $from, $to } = state.selection;+ commands.toggleList(this.name, this.options.itemTypeName);+ const position = {+ from: tr.mapping.map($from.pos),+ to: tr.mapping.map($to.pos),+ };+ // There is a minor bug in Prosemirror or Tiptap where creating+ // nested node view causes the editor selection to act weird.+ // The solution is to manually force the editor back to the correct+ // position.+ // NOTE: We have to wrap this in setTimeout & use the editor+ // directly or else it won't run.+ setTimeout(() => editor.commands.setTextSelection(position), 0);+ return true;+ },+ };+ },+ addNodeView() {+ return createNodeView(TaskListComponent, {+ contentDOMFactory: () => {+ const content = document.createElement("ul");+ content.classList.add(`${this.name.toLowerCase()}-content-wrapper`);+ content.style.whiteSpace = "inherit";+ return { dom: content };+ },+ });+ },+});diff --git a/packages/editor/dist/es/extensions/textdirection/index.d.ts b/packages/editor/dist/es/extensions/textdirection/index.d.tsnew file mode 100644index 000000000..ea2fee63c--- /dev/null+++ b/packages/editor/dist/es/extensions/textdirection/index.d.ts@@ -0,0 +1,3 @@+import { TextDirection } from "./text-direction";+export * from "./text-direction";+export default TextDirection;diff --git a/packages/editor/dist/es/extensions/textdirection/index.js b/packages/editor/dist/es/extensions/textdirection/index.jsnew file mode 100644index 000000000..ea2fee63c--- /dev/null+++ b/packages/editor/dist/es/extensions/textdirection/index.js@@ -0,0 +1,3 @@+import { TextDirection } from "./text-direction";+export * from "./text-direction";+export default TextDirection;diff --git a/packages/editor/dist/es/extensions/textdirection/textdirection.d.ts b/packages/editor/dist/es/extensions/textdirection/textdirection.d.tsnew file mode 100644index 000000000..a29fdf91d--- /dev/null+++ b/packages/editor/dist/es/extensions/textdirection/textdirection.d.ts@@ -0,0 +1,19 @@+import { Extension } from "@tiptap/core";+import "@tiptap/extension-text-style";+declare type TextDirectionOptions = {+ types: string[];+ defaultDirection: TextDirections;+};+declare type TextDirections = "ltr" | "rtl";+declare module "@tiptap/core" {+ interface Commands<ReturnType> {+ textDirection: {+ /**+ * Set the font family+ */+ setTextDirection: (direction: TextDirections) => ReturnType;+ };+ }+}+export declare const TextDirection: Extension<TextDirectionOptions, any>;+export {};diff --git a/packages/editor/dist/es/extensions/textdirection/textdirection.js b/packages/editor/dist/es/extensions/textdirection/textdirection.jsnew file mode 100644index 000000000..01e32da55--- /dev/null+++ b/packages/editor/dist/es/extensions/textdirection/textdirection.js@@ -0,0 +1,37 @@+import { Extension } from "@tiptap/core";+import "@tiptap/extension-text-style";+export const TextDirection = Extension.create({+ name: "textDirection",+ defaultOptions: {+ types: ["paragraph", "heading"],+ defaultDirection: "ltr",+ },+ addGlobalAttributes() {+ return [+ {+ types: this.options.types,+ attributes: {+ textDirection: {+ default: this.options.defaultDirection,+ parseHTML: (element) => element.dir,+ renderHTML: (attributes) => {+ if (!attributes.textDirection) {+ return {};+ }+ return {+ dir: attributes.textDirection,+ };+ },+ },+ },+ },+ ];+ },+ addCommands() {+ return {+ setTextDirection: (direction) => ({ commands }) => {+ return this.options.types.every((type) => commands.updateAttributes(type, { textDirection: direction }));+ },+ };+ },+});diff --git a/packages/editor/dist/es/hooks/useEditor.d.ts b/packages/editor/dist/es/hooks/useEditor.d.tsnew file mode 100644index 000000000..9c4401648--- /dev/null+++ b/packages/editor/dist/es/hooks/useEditor.d.ts@@ -0,0 +1,4 @@+import { EditorOptions } from "@tiptap/core";+import { DependencyList } from "react";+import { Editor as EditorType } from "../types";+export declare const useEditor: (options?: Partial<EditorOptions>, deps?: DependencyList) => EditorType;diff --git a/packages/editor/dist/es/hooks/useEditor.js b/packages/editor/dist/es/hooks/useEditor.jsnew file mode 100644index 000000000..6194357e3--- /dev/null+++ b/packages/editor/dist/es/hooks/useEditor.js@@ -0,0 +1,29 @@+import { Editor } from "@tiptap/core";+import { useEffect, useState } from "react";+function useForceUpdate() {+ const [, setValue] = useState(0);+ return () => setValue((value) => value + 1);+}+export const useEditor = (options = {}, deps = []) => {+ const [editor, setEditor] = useState(null);+ const forceUpdate = useForceUpdate();+ useEffect(() => {+ let isMounted = true;+ const instance = new Editor(options);+ setEditor(instance);+ instance.on("transaction", () => {+ requestAnimationFrame(() => {+ requestAnimationFrame(() => {+ if (isMounted) {+ forceUpdate();+ }+ });+ });+ });+ return () => {+ instance.destroy();+ isMounted = false;+ };+ }, deps);+ return editor;+};diff --git a/packages/editor/dist/es/hooks/useRefValue.d.ts b/packages/editor/dist/es/hooks/useRefValue.d.tsnew file mode 100644index 000000000..de0bdea82--- /dev/null+++ b/packages/editor/dist/es/hooks/useRefValue.d.ts@@ -0,0 +1,2 @@+/// <reference types="react" />+export declare function useRefValue<T>(value: T): import("react").MutableRefObject<T>;diff --git a/packages/editor/dist/es/hooks/useRefValue.js b/packages/editor/dist/es/hooks/useRefValue.jsnew file mode 100644index 000000000..d86f8befb--- /dev/null+++ b/packages/editor/dist/es/hooks/useRefValue.js@@ -0,0 +1,8 @@+import { useEffect, useRef } from "react";+export function useRefValue(value) {+ const refValue = useRef(value);+ useEffect(() => {+ refValue.current = value;+ }, [value]);+ return refValue;+}diff --git a/packages/editor/dist/es/index.d.ts b/packages/editor/dist/es/index.d.tsnew file mode 100644index 000000000..cd47cb2da--- /dev/null+++ b/packages/editor/dist/es/index.d.ts@@ -0,0 +1,14 @@+/// <reference types="react" />+import "./extensions";+import Toolbar from "./toolbar";+import { Theme } from "@notesnook/theme";+import { AttachmentOptions } from "./extensions/attachment";+import { EditorOptions } from "@tiptap/core";+declare const useTiptap: (options?: Partial<EditorOptions & AttachmentOptions & {+ theme: Theme;+}>, deps?: import("react").DependencyList) => import("./types").Editor;+export { useTiptap, Toolbar };+export * from "./types";+export * from "./extensions/react";+export * from "./toolbar";+export { type AttachmentType } from "./extensions/attachment";diff --git a/packages/editor/dist/es/index.js b/packages/editor/dist/es/index.jsnew file mode 100644index 000000000..b29e28b64--- /dev/null+++ b/packages/editor/dist/es/index.js@@ -0,0 +1,166 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import "./extensions";+import CharacterCount from "@tiptap/extension-character-count";+import Placeholder from "@tiptap/extension-placeholder";+import Underline from "@tiptap/extension-underline";+import StarterKit from "@tiptap/starter-kit";+import { useEffect, useMemo, useRef } from "react";+import { EditorView } from "prosemirror-view";+import Toolbar from "./toolbar";+import TextAlign from "@tiptap/extension-text-align";+import Subscript from "@tiptap/extension-subscript";+import Superscript from "@tiptap/extension-superscript";+import FontSize from "./extensions/font-size";+import TextDirection from "./extensions/text-direction";+import TextStyle from "@tiptap/extension-text-style";+import FontFamily from "@tiptap/extension-font-family";+import BulletList from "./extensions/bullet-list";+import OrderedList from "./extensions/ordered-list";+import Highlight from "@tiptap/extension-highlight";+import Color from "@tiptap/extension-color";+import TableRow from "@tiptap/extension-table-row";+import TableCell from "./extensions/table-cell";+import TableHeader from "@tiptap/extension-table-header";+import { ImageNode } from "./extensions/image";+import { AttachmentNode } from "./extensions/attachment";+import { TaskListNode } from "./extensions/task-list";+import { TaskItemNode } from "./extensions/task-item";+import { Dropcursor } from "./extensions/drop-cursor";+import { SearchReplace } from "./extensions/search-replace";+import { EmbedNode } from "./extensions/embed";+import { CodeBlock } from "./extensions/code-block";+import { ListItem } from "./extensions/list-item";+import { Link } from "@tiptap/extension-link";+import { Codemark } from "./extensions/code-mark";+import { MathInline, MathBlock } from "./extensions/math";+import { NodeViewSelectionNotifier, usePortalProvider, } from "./extensions/react";+import { OutlineList } from "./extensions/outline-list";+import { OutlineListItem } from "./extensions/outline-list-item";+import { Table } from "./extensions/table";+import { useIsMobile } from "./toolbar/stores/toolbar-store";+import { useEditor } from "./hooks/use-editor";+EditorView.prototype.updateState = function updateState(state) {+ if (!this.docView)+ return; // This prevents the matchesNode error on hot reloads+ this.updateStateInner(state, this.state.plugins != state.plugins);+};+const useTiptap = (options = {}, deps = []) => {+ const { theme, onDownloadAttachment, onOpenAttachmentPicker } = options, restOptions = __rest(options, ["theme", "onDownloadAttachment", "onOpenAttachmentPicker"]);+ const PortalProviderAPI = usePortalProvider();+ const isMobile = useIsMobile();+ const defaultOptions = useMemo(() => ({+ extensions: [+ NodeViewSelectionNotifier,+ SearchReplace,+ TextStyle,+ StarterKit.configure({+ dropcursor: false,+ codeBlock: false,+ listItem: false,+ orderedList: false,+ bulletList: false,+ history: {+ depth: 200,+ newGroupDelay: 1000,+ },+ }),+ Dropcursor.configure({+ class: "drop-cursor",+ }),+ CharacterCount,+ Underline,+ Subscript,+ Superscript,+ FontSize,+ TextDirection,+ FontFamily,+ BulletList,+ OrderedList,+ TaskItemNode.configure({ nested: true }),+ TaskListNode,+ Link.configure({ openOnClick: !isMobile }),+ Table.configure({+ resizable: true,+ allowTableNodeSelection: true,+ cellMinWidth: 50,+ }),+ TableRow,+ TableCell,+ TableHeader,+ Highlight.configure({+ multicolor: true,+ }),+ CodeBlock,+ Color,+ TextAlign.configure({+ types: ["heading", "paragraph"],+ alignments: ["left", "right", "center", "justify"],+ defaultAlignment: "left",+ }),+ Placeholder.configure({+ placeholder: "Start writing your note...",+ }),+ ImageNode,+ EmbedNode,+ AttachmentNode.configure({+ onDownloadAttachment,+ onOpenAttachmentPicker,+ }),+ OutlineListItem,+ OutlineList,+ ListItem,+ Codemark,+ MathInline,+ MathBlock,+ ],+ onBeforeCreate: ({ editor }) => {+ if (theme) {+ editor.storage.theme = theme;+ }+ editor.storage.portalProviderAPI = PortalProviderAPI;+ },+ injectCSS: false,+ }), [+ theme,+ onDownloadAttachment,+ onOpenAttachmentPicker,+ PortalProviderAPI,+ isMobile,+ ]);+ const editor = useEditor(Object.assign(Object.assign({}, defaultOptions), restOptions), deps);+ const editorRef = useRef(editor);+ useEffect(() => {+ editorRef.current = editor;+ if (editor && !editor.current)+ Object.defineProperty(editor, "current", {+ get: () => editorRef.current,+ });+ }, [editor]);+ useEffect(() => {+ function onDragEnter(event) {+ if (!!(editor === null || editor === void 0 ? void 0 : editor.view.dragging)) {+ event.preventDefault();+ return true;+ }+ }+ editor === null || editor === void 0 ? void 0 : editor.view.dom.addEventListener("dragenter", onDragEnter);+ return () => {+ editor === null || editor === void 0 ? void 0 : editor.view.dom.removeEventListener("dragenter", onDragEnter);+ };+ }, [editor === null || editor === void 0 ? void 0 : editor.view.dom]);+ return editor;+};+export { useTiptap, Toolbar };+export * from "./types";+export * from "./extensions/react";+export * from "./toolbar";diff --git a/packages/editor/dist/es/package.json b/packages/editor/dist/es/package.jsonnew file mode 100644index 000000000..472002573--- /dev/null+++ b/packages/editor/dist/es/package.json@@ -0,0 +1,3 @@+{+ "type": "module"+}diff --git a/packages/editor/dist/es/toolbar/components/counter.d.ts b/packages/editor/dist/es/toolbar/components/counter.d.tsnew file mode 100644index 000000000..bfbe39347--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/counter.d.ts@@ -0,0 +1,11 @@+import React from "react";+export declare type CounterProps = {+ title: string;+ onIncrease: () => void;+ onDecrease: () => void;+ onReset: () => void;+ value: string;+};+declare function _Counter(props: CounterProps): JSX.Element;+export declare const Counter: React.MemoExoticComponent<typeof _Counter>;+export {};diff --git a/packages/editor/dist/es/toolbar/components/counter.js b/packages/editor/dist/es/toolbar/components/counter.jsnew file mode 100644index 000000000..eae647190--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/counter.js@@ -0,0 +1,25 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import React from "react";+import { Flex } from "rebass";+import { Button } from "../../components/button";+import { ToolButton } from "./tool-button";+function _Counter(props) {+ const { title, onDecrease, onIncrease, onReset, value } = props;+ return (_jsxs(Flex, Object.assign({ sx: {+ alignItems: "center",+ mr: 1,+ ":last-of-type": {+ mr: 0,+ },+ } }, { children: [_jsx(ToolButton, { toggled: false, title: `Decrease ${title}`, icon: "minus", variant: "small", onClick: onDecrease }), _jsx(Button, Object.assign({ sx: {+ color: "text",+ bg: "transparent",+ px: 0,+ fontSize: "subBody",+ mx: 1,+ textAlign: "center",+ }, onClick: onReset, title: `Reset ${title}` }, { children: value })), _jsx(ToolButton, { toggled: false, title: `Increase ${title}`, icon: "plus", variant: "small", onClick: onIncrease })] })));+}+export const Counter = React.memo(_Counter, (prev, next) => {+ return prev.value === next.value;+});diff --git a/packages/editor/dist/es/toolbar/components/dropdown.d.ts b/packages/editor/dist/es/toolbar/components/dropdown.d.tsnew file mode 100644index 000000000..f1011513b--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/dropdown.d.ts@@ -0,0 +1,10 @@+/// <reference types="react" />+import { MenuItem } from "../../components/menu/types";+declare type DropdownProps = {+ selectedItem: string | JSX.Element;+ items: MenuItem[];+ buttonRef?: React.MutableRefObject<HTMLButtonElement | undefined>;+ menuWidth?: number;+};+export declare function Dropdown(props: DropdownProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/components/dropdown.js b/packages/editor/dist/es/toolbar/components/dropdown.jsnew file mode 100644index 000000000..4f8170599--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/dropdown.js@@ -0,0 +1,48 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { useRef, useState } from "react";+import { Button, Text } from "rebass";+import { Icon } from "./icon";+import { Icons } from "../icons";+import { useIsMobile, useToolbarLocation } from "../stores/toolbar-store";+import { MenuPresenter } from "../../components/menu";+import { getToolbarElement } from "../utils/dom";+export function Dropdown(props) {+ const { items, selectedItem, buttonRef, menuWidth } = props;+ const internalRef = useRef();+ const [isOpen, setIsOpen] = useState(false);+ const toolbarLocation = useToolbarLocation();+ const isMobile = useIsMobile();+ const isBottom = toolbarLocation === "bottom";+ return (_jsxs(_Fragment, { children: [_jsxs(Button, Object.assign({ ref: (ref) => {+ internalRef.current = ref;+ if (buttonRef)+ buttonRef.current = ref;+ }, sx: {+ p: 1,+ m: 0,+ bg: isOpen ? "hover" : "transparent",+ mr: 1,+ display: "flex",+ alignItems: "center",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onClick: () => setIsOpen((s) => !s), onMouseDown: (e) => e.preventDefault() }, { children: [typeof selectedItem === "string" ? (_jsx(Text, Object.assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), _jsx(Icon, { path: isBottom ? Icons.chevronUp : Icons.chevronDown, size: "small", color: "text" })] })), _jsx(MenuPresenter, { isOpen: isOpen, items: items, onClose: () => setIsOpen(false), position: {+ target: isBottom+ ? getToolbarElement()+ : internalRef.current || "mouse",+ isTargetAbsolute: true,+ location: isBottom ? "top" : "below",+ align: "center",+ yOffset: 5,+ }, blocking: !isMobile, focusOnRender: !isMobile, sx: {+ minWidth: menuWidth,+ maxWidth: isBottom ? "95vw" : "auto",+ flexDirection: isBottom ? "row" : "column",+ overflowX: isBottom ? "auto" : "hidden",+ marginRight: isBottom ? "10px" : 0,+ display: "flex",+ alignItems: isBottom ? "center" : "unset",+ } })] }));+}diff --git a/packages/editor/dist/es/toolbar/components/icon.d.ts b/packages/editor/dist/es/toolbar/components/icon.d.tsnew file mode 100644index 000000000..2cf292b4a--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/icon.d.ts@@ -0,0 +1,15 @@+/// <reference types="react" />+import { Theme } from "@notesnook/theme";+import { SchemeColors } from "@notesnook/theme/dist/theme/colorscheme";+import { FlexProps } from "rebass";+declare type IconProps = {+ title?: string;+ path: string;+ size?: keyof Theme["iconSizes"] | number;+ color?: keyof SchemeColors;+ stroke?: string;+ rotate?: boolean;+};+export declare type NNIconProps = FlexProps & IconProps;+export declare function Icon(props: NNIconProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/components/icon.js b/packages/editor/dist/es/toolbar/components/icon.jsnew file mode 100644index 000000000..9cf5d090e--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/icon.js@@ -0,0 +1,29 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import MDIIcon from "@mdi/react";+import { useTheme } from "emotion-theming";+import { Flex } from "rebass";+function MDIIconWrapper({ title, path, size = 24, color = "icon", stroke, rotate, }) {+ const theme = useTheme();+ const themedColor = theme.colors+ ? theme.colors[color]+ : color;+ return (_jsx(MDIIcon, { className: "icon", title: title, path: path, size: typeof size === "string" ? `${theme.iconSizes[size]}px` : `${size}px`, style: {+ strokeWidth: stroke || "0px",+ stroke: themedColor,+ }, color: themedColor, spin: rotate }));+}+export function Icon(props) {+ const { sx, title, color, size, stroke, rotate, path } = props, restProps = __rest(props, ["sx", "title", "color", "size", "stroke", "rotate", "path"]);+ return (_jsx(Flex, Object.assign({ sx: Object.assign({ flexShrink: 0, justifyContent: "center", alignItems: "center" }, sx) }, restProps, { children: _jsx(MDIIconWrapper, { title: title, path: path, rotate: rotate, color: color, stroke: stroke, size: size }) })));+}diff --git a/packages/editor/dist/es/toolbar/components/moretools.d.ts b/packages/editor/dist/es/toolbar/components/moretools.d.tsnew file mode 100644index 000000000..f630e403e--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/moretools.d.ts@@ -0,0 +1,10 @@+/// <reference types="react" />+import { ToolProps } from "../types";+import { ToolId } from "../tools";+declare type MoreToolsProps = ToolProps & {+ popupId: string;+ tools: ToolId[];+ autoCloseOnUnmount?: boolean;+};+export declare function MoreTools(props: MoreToolsProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/components/moretools.js b/packages/editor/dist/es/toolbar/components/moretools.jsnew file mode 100644index 000000000..c206a9691--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/moretools.js@@ -0,0 +1,29 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { useRef, useState } from "react";+import { PopupWrapper } from "../../components/popup-presenter";+import { ToolButton } from "../components/tool-button";+import { useToolbarLocation } from "../stores/toolbar-store";+import { getToolbarElement } from "../utils/dom";+import { ToolbarGroup } from "./toolbar-group";+export function MoreTools(props) {+ const { popupId, editor, tools, autoCloseOnUnmount } = props;+ const toolbarLocation = useToolbarLocation();+ const isBottom = toolbarLocation === "bottom";+ const buttonRef = useRef();+ const [isOpen, setIsOpen] = useState(false);+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({}, props, { toggled: isOpen, buttonRef: buttonRef, onClick: () => setIsOpen((s) => !s) })), _jsx(PopupWrapper, { isOpen: isOpen, group: "toolbarGroup", id: popupId, onClosed: () => setIsOpen(false), position: {+ isTargetAbsolute: true,+ target: isBottom ? getToolbarElement() : buttonRef.current || "mouse",+ align: "center",+ location: isBottom ? "top" : "below",+ yOffset: isBottom ? 10 : 5,+ }, autoCloseOnUnmount: autoCloseOnUnmount, focusOnRender: false, blocking: false, renderPopup: () => (_jsx(ToolbarGroup, { tools: tools, editor: editor, sx: {+ flex: 1,+ p: 1,+ boxShadow: "menu",+ bg: "background",+ borderRadius: "default",+ overflowX: "auto",+ maxWidth: "95vw",+ } })) })] }));+}diff --git a/packages/editor/dist/es/toolbar/components/popup.d.ts b/packages/editor/dist/es/toolbar/components/popup.d.tsnew file mode 100644index 000000000..fb521b343--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/popup.d.ts@@ -0,0 +1,14 @@+import { PropsWithChildren } from "react";+declare type Action = {+ title: string;+ onClick: () => void;+ loading?: boolean;+ disabled?: boolean;+};+export declare type PopupProps = {+ title?: string;+ onClose?: () => void;+ action?: Action;+};+export declare function Popup(props: PropsWithChildren<PopupProps>): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/components/popup.js b/packages/editor/dist/es/toolbar/components/popup.jsnew file mode 100644index 000000000..567163ec6--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/popup.js@@ -0,0 +1,27 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { Button, Flex, Text } from "rebass";+import { Icon } from "./icon";+import { Icons } from "../icons";+import { DesktopOnly, MobileOnly } from "../../components/responsive";+export function Popup(props) {+ const { title, onClose, action, children } = props;+ return (_jsxs(_Fragment, { children: [_jsx(DesktopOnly, { children: _jsxs(Flex, Object.assign({ sx: {+ overflow: "hidden",+ bg: "background",+ flexDirection: "column",+ borderRadius: "default",+ // border: "1px solid var(--border)",+ boxShadow: "menu",+ minWidth: 200,+ } }, { children: [title && (_jsxs(Flex, Object.assign({ className: "movable", sx: {+ justifyContent: "space-between",+ alignItems: "center",+ p: 2,+ } }, { children: [_jsx(Text, Object.assign({ variant: "title" }, { children: title })), _jsx(Button, Object.assign({ variant: "tool", sx: { p: 0, bg: "transparent" }, onClick: onClose }, { children: _jsx(Icon, { path: Icons.close, size: "big" }) }))] }))), children, title && action && (_jsx(Flex, Object.assign({ sx: { justifyContent: "end" }, bg: "bgSecondary", p: 1, px: 2, mt: 2 }, { children: _jsx(Button, Object.assign({ variant: "dialog", onClick: action.disabled || action.loading ? undefined : action.onClick, disabled: action.disabled || action.loading }, { children: action.loading ? (_jsx(Icon, { path: Icons.loading, rotate: true, size: "medium" })) : (action.title) })) })))] })) }), _jsxs(MobileOnly, { children: [children, action && (_jsx(Button, Object.assign({ variant: "primary", sx: {+ alignSelf: "stretch",+ mb: 1,+ mt: 2,+ mx: 1,+ py: 2,+ }, onClick: action.disabled ? undefined : action === null || action === void 0 ? void 0 : action.onClick, disabled: action.disabled }, { children: action.loading ? (_jsx(Icon, { path: Icons.loading, rotate: true, size: "medium" })) : (action.title) })))] })] }));+}diff --git a/packages/editor/dist/es/toolbar/components/splitbutton.d.ts b/packages/editor/dist/es/toolbar/components/splitbutton.d.tsnew file mode 100644index 000000000..0db2f1020--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/splitbutton.d.ts@@ -0,0 +1,9 @@+import { PropsWithChildren } from "react";+import { ToolButtonProps } from "./tool-button";+import React from "react";+export declare type SplitButtonProps = ToolButtonProps & {+ onOpen: () => void;+};+declare function _SplitButton(props: PropsWithChildren<SplitButtonProps>): JSX.Element;+export declare const SplitButton: React.MemoExoticComponent<typeof _SplitButton>;+export {};diff --git a/packages/editor/dist/es/toolbar/components/splitbutton.js b/packages/editor/dist/es/toolbar/components/splitbutton.jsnew file mode 100644index 000000000..bf67ffdae--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/splitbutton.js@@ -0,0 +1,41 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { useRef } from "react";+import { Flex } from "rebass";+import { Icons } from "../icons";+import { Icon } from "./icon";+import { ToolButton } from "./tool-button";+import { useToolbarLocation } from "../stores/toolbar-store";+import { Button } from "../../components/button";+import React from "react";+function _SplitButton(props) {+ const { children, toggled, onOpen } = props, toolButtonProps = __rest(props, ["children", "toggled", "onOpen"]);+ const ref = useRef(null);+ const toolbarLocation = useToolbarLocation();+ return (_jsxs(_Fragment, { children: [_jsxs(Flex, Object.assign({ ref: ref, sx: {+ borderRadius: "default",+ bg: toggled ? "hover" : "transparent",+ ":hover": { bg: "hover" },+ } }, { children: [_jsx(ToolButton, Object.assign({}, toolButtonProps, { toggled: toggled })), _jsx(Button, Object.assign({ sx: {+ p: 0,+ m: 0,+ bg: toggled ? "hover" : "transparent",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onClick: onOpen }, { children: _jsx(Icon, { path: toolbarLocation === "bottom" ? Icons.chevronUp : Icons.chevronDown, color: "text", size: "small" }) }))] })), children] }));+}+export const SplitButton = React.memo(_SplitButton, (prev, next) => {+ return prev.toggled === next.toggled;+});diff --git a/packages/editor/dist/es/toolbar/components/toolbargroup.d.ts b/packages/editor/dist/es/toolbar/components/toolbargroup.d.tsnew file mode 100644index 000000000..a76c88195--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/toolbargroup.d.ts@@ -0,0 +1,13 @@+/// <reference types="react" />+import { ToolbarGroupDefinition, ToolButtonVariant } from "../types";+import { FlexProps } from "rebass";+import { Editor } from "@tiptap/core";+import { NodeWithOffset } from "../utils/prosemirror";+export declare type ToolbarGroupProps = FlexProps & {+ tools: ToolbarGroupDefinition;+ editor: Editor;+ variant?: ToolButtonVariant;+ force?: boolean;+ selectedNode?: NodeWithOffset;+};+export declare function ToolbarGroup(props: ToolbarGroupProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/components/toolbargroup.js b/packages/editor/dist/es/toolbar/components/toolbargroup.jsnew file mode 100644index 000000000..14ab942d9--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/toolbargroup.js@@ -0,0 +1,29 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import { findTool } from "../tools";+import { Flex } from "rebass";+import { MoreTools } from "./more-tools";+import { getToolDefinition } from "../tool-definitions";+export function ToolbarGroup(props) {+ const { tools, editor, force, selectedNode } = props, flexProps = __rest(props, ["tools", "editor", "force", "selectedNode"]);+ return (_jsx(Flex, Object.assign({ className: "toolbar-group" }, flexProps, { children: tools.map((toolId) => {+ if (Array.isArray(toolId)) {+ return (_jsx(MoreTools, { title: "More", icon: "more", popupId: toolId.join(""), tools: toolId, editor: editor }, "more-tools"));+ }+ else {+ const Component = findTool(toolId);+ const toolDefinition = getToolDefinition(toolId);+ return (_jsx(Component, Object.assign({ editor: editor, force: force, selectedNode: selectedNode }, toolDefinition), toolDefinition.title));+ }+ }) })));+}diff --git a/packages/editor/dist/es/toolbar/components/toolbutton.d.ts b/packages/editor/dist/es/toolbar/components/toolbutton.d.tsnew file mode 100644index 000000000..d7cb97dd4--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/toolbutton.d.ts@@ -0,0 +1,22 @@+import { Theme } from "@notesnook/theme";+import { SchemeColors } from "@notesnook/theme/dist/theme/colorscheme";+import React from "react";+import { ButtonProps } from "rebass";+import { IconNames } from "../icons";+import { ToolButtonVariant } from "../types";+export declare type ToolButtonProps = ButtonProps & {+ icon: IconNames;+ iconColor?: keyof SchemeColors;+ iconSize?: keyof Theme["iconSizes"] | number;+ toggled: boolean;+ buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined>;+ variant?: ToolButtonVariant;+};+export declare const ToolButton: React.NamedExoticComponent<ButtonProps & {+ icon: IconNames;+ iconColor?: "background" | "border" | "text" | "blue" | "gray" | "green" | "orange" | "purple" | "red" | "yellow" | "checked" | "disabled" | "placeholder" | "icon" | keyof import("@notesnook/theme/dist/theme/colorscheme/static").StaticColors | "primary" | "bgTransparent" | "accent" | "bgSecondary" | "bgSecondaryText" | "bgSecondaryHover" | "hover" | "fontSecondary" | "fontTertiary" | "overlay" | "secondary" | undefined;+ iconSize?: number | "big" | "small" | "medium" | undefined;+ toggled: boolean;+ buttonRef?: React.MutableRefObject<HTMLButtonElement | null | undefined> | undefined;+ variant?: ToolButtonVariant | undefined;+}>;diff --git a/packages/editor/dist/es/toolbar/components/toolbutton.js b/packages/editor/dist/es/toolbar/components/toolbutton.jsnew file mode 100644index 000000000..b54d1bf2a--- /dev/null+++ b/packages/editor/dist/es/toolbar/components/toolbutton.js@@ -0,0 +1,24 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import React from "react";+import { Icons } from "../icons";+import { Button } from "../../components/button";+import { Icon } from "./icon";+export const ToolButton = React.memo(function ToolButton(props) {+ const { id, icon, iconSize, iconColor, toggled, sx, buttonRef, variant = "normal" } = props, buttonProps = __rest(props, ["id", "icon", "iconSize", "iconColor", "toggled", "sx", "buttonRef", "variant"]);+ return (_jsx(Button, Object.assign({ ref: buttonRef, tabIndex: -1, id: `tool-${id || icon}`, sx: Object.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: (e) => e.preventDefault() }, buttonProps, { children: _jsx(Icon, { path: Icons[icon], color: iconColor || "icon", size: iconSize || (variant === "small" ? "medium" : "big") }) })));+}, (prev, next) => {+ return prev.toggled === next.toggled;+});diff --git a/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/index.d.ts b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/index.d.tsnew file mode 100644index 000000000..e23f86eea--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/index.d.ts@@ -0,0 +1,8 @@+import { Editor } from "../../../types";+import { NodeWithOffset } from "../../utils/prosemirror";+import { FloatingMenuProps } from "../types";+export declare type HoverPopupProps = {+ editor: Editor;+ selectedNode: NodeWithOffset;+};+export declare function HoverPopupHandler(props: FloatingMenuProps): null;diff --git a/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/index.js b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/index.jsnew file mode 100644index 000000000..1cebb628a--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/index.js@@ -0,0 +1,66 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { useEffect, useRef } from "react";+import { showPopup } from "../../../components/popup-presenter";+import { LinkHoverPopupHandler } from "./link";+const handlers = Object.assign({}, LinkHoverPopupHandler);+const HOVER_TIMEOUT = 500;+export function HoverPopupHandler(props) {+ const { editor } = props;+ const hoverTimeoutId = useRef();+ const activePopup = useRef();+ useEffect(() => {+ function onMouseOver(e) {+ if (!e.target ||+ !(e.target instanceof HTMLElement) ||+ e.target.classList.contains("ProseMirror"))+ return;+ const element = e.target;+ if (activePopup.current) {+ const isOutsideEditor = !element.closest(".ProseMirror");+ const isInsidePopup = element.closest(".popup-presenter-portal");+ const isActiveElement = activePopup.current.element === element;+ if (isInsidePopup)+ return;+ if (isOutsideEditor || !isActiveElement) {+ console.log("HIDING", isOutsideEditor, isActiveElement, element);+ activePopup.current.hide();+ activePopup.current = undefined;+ return;+ }+ }+ clearTimeout(hoverTimeoutId.current);+ hoverTimeoutId.current = setTimeout(() => {+ const nodeName = element.nodeName.toLowerCase();+ const PopupHandler = handlers[nodeName];+ if (!PopupHandler || !editor.current)+ return;+ const pos = editor.current.view.posAtDOM(element, 0);+ const node = editor.current.view.state.doc.nodeAt(pos);+ if (!node)+ return;+ const hidePopup = showPopup({+ popup: () => (_jsx(PopupHandler, { editor: editor, selectedNode: {+ node,+ from: pos,+ to: pos + node.nodeSize,+ } })),+ theme: editor.storage.theme,+ blocking: false,+ focusOnRender: false,+ position: {+ target: element,+ align: "center",+ location: "top",+ isTargetAbsolute: true,+ },+ });+ activePopup.current = { element, hide: hidePopup };+ }, HOVER_TIMEOUT, {});+ }+ window.addEventListener("mouseover", onMouseOver);+ return () => {+ window.removeEventListener("mouseover", onMouseOver);+ };+ }, []);+ return null;+}diff --git a/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/link.d.ts b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/link.d.tsnew file mode 100644index 000000000..6463e2600--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/link.d.ts@@ -0,0 +1,7 @@+/// <reference types="react" />+import { HoverPopupProps } from ".";+declare function LinkHoverPopup(props: HoverPopupProps): JSX.Element | null;+export declare const LinkHoverPopupHandler: {+ a: typeof LinkHoverPopup;+};+export {};diff --git a/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/link.js b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/link.jsnew file mode 100644index 000000000..85cd23066--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/hoverpopup/link.js@@ -0,0 +1,17 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { ToolbarGroup } from "../../components/toolbar-group";+function LinkHoverPopup(props) {+ const { editor, selectedNode } = props;+ const { node } = selectedNode;+ if (!node.isText ||+ node.marks.length <= 0 ||+ !node.marks.some((mark) => mark.type.name === "link"))+ return null;+ return (_jsx(ToolbarGroup, { force: true, tools: ["openLink", "editLink", "removeLink"], editor: editor, selectedNode: selectedNode, sx: {+ bg: "background",+ boxShadow: "menu",+ borderRadius: "default",+ p: 1,+ } }));+}+export const LinkHoverPopupHandler = { a: LinkHoverPopup };diff --git a/packages/editor/dist/es/toolbar/floatingmenus/index.d.ts b/packages/editor/dist/es/toolbar/floatingmenus/index.d.tsnew file mode 100644index 000000000..b02c024c2--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/index.d.ts@@ -0,0 +1,3 @@+/// <reference types="react" />+import { FloatingMenuProps } from "./types";+export declare function EditorFloatingMenus(props: FloatingMenuProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/floatingmenus/index.js b/packages/editor/dist/es/toolbar/floatingmenus/index.jsnew file mode 100644index 000000000..1be8629e8--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/index.js@@ -0,0 +1,6 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { HoverPopupHandler } from "./hover-popup";+import { SearchReplaceFloatingMenu } from "./search-replace";+export function EditorFloatingMenus(props) {+ return (_jsxs(_Fragment, { children: [_jsx(SearchReplaceFloatingMenu, Object.assign({}, props)), _jsx(HoverPopupHandler, Object.assign({}, props))] }));+}diff --git a/packages/editor/dist/es/toolbar/floatingmenus/searchreplace.d.ts b/packages/editor/dist/es/toolbar/floatingmenus/searchreplace.d.tsnew file mode 100644index 000000000..66a0fa228--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/searchreplace.d.ts@@ -0,0 +1,3 @@+/// <reference types="react" />+import { FloatingMenuProps } from "./types";+export declare function SearchReplaceFloatingMenu(props: FloatingMenuProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/floatingmenus/searchreplace.js b/packages/editor/dist/es/toolbar/floatingmenus/searchreplace.jsnew file mode 100644index 000000000..443b9382d--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/searchreplace.js@@ -0,0 +1,15 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { SearchReplacePopup } from "../popups/search-replace";+import { ResponsivePresenter, } from "../../components/responsive";+import { getToolbarElement } from "../utils/dom";+export function SearchReplaceFloatingMenu(props) {+ const { editor } = props;+ const { isSearching } = editor.storage.searchreplace;+ return (_jsx(ResponsivePresenter, Object.assign({ mobile: "sheet", desktop: "menu", isOpen: isSearching, onClose: () => editor.commands.endSearch(), position: {+ target: getToolbarElement(),+ isTargetAbsolute: true,+ location: "below",+ align: "end",+ yOffset: 5,+ }, blocking: false, focusOnRender: false, draggable: false }, { children: _jsx(SearchReplacePopup, { editor: editor }) })));+}diff --git a/packages/editor/dist/es/toolbar/floatingmenus/types.d.ts b/packages/editor/dist/es/toolbar/floatingmenus/types.d.tsnew file mode 100644index 000000000..f3ea5ebf6--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/types.d.ts@@ -0,0 +1,4 @@+import { Editor } from "../../types";+export declare type FloatingMenuProps = {+ editor: Editor;+};diff --git a/packages/editor/dist/es/toolbar/floatingmenus/types.js b/packages/editor/dist/es/toolbar/floatingmenus/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/toolbar/floatingmenus/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/toolbar/icons.d.ts b/packages/editor/dist/es/toolbar/icons.d.tsnew file mode 100644index 000000000..7954bdda5--- /dev/null+++ b/packages/editor/dist/es/toolbar/icons.d.ts@@ -0,0 +1,96 @@+export declare const Icons: {+ bold: string;+ italic: string;+ underline: string;+ strikethrough: string;+ code: string;+ codeRemove: string;+ alignCenter: string;+ alignLeft: string;+ alignRight: string;+ alignJustify: string;+ subscript: string;+ superscript: string;+ horizontalRule: string;+ codeblock: string;+ blockquote: string;+ formatClear: string;+ ltr: string;+ rtl: string;+ numberedList: string;+ bulletList: string;+ highlight: string;+ textColor: string;+ link: string;+ linkRemove: string;+ openLink: string;+ linkEdit: string;+ linkSettings: string;+ url: string;+ image: string;+ imageSettings: string;+ colorClear: string;+ check: string;+ checkbox: string;+ loading: string;+ more: string;+ upload: string;+ camera: string;+ attachment: string;+ table: string;+ rowProperties: string;+ insertRowBelow: string;+ insertRowAbove: string;+ moveRowDown: string;+ moveRowUp: string;+ deleteRow: string;+ toggleHeaderRow: string;+ columnProperties: string;+ insertColumnRight: string;+ insertColumnLeft: string;+ moveColumnRight: string;+ moveColumnLeft: string;+ deleteColumn: string;+ cellProperties: string;+ cellBorderColor: string;+ backgroundColor: string;+ borderColor: string;+ sortDesc: string;+ deleteTable: string;+ mergeCells: string;+ splitCells: string;+ checklist: string;+ dragHandle: string;+ previousMatch: string;+ nextMatch: string;+ replaceOne: string;+ replaceAll: string;+ replace: string;+ attachmentSettings: string;+ caseSensitive: string;+ wholeWord: string;+ regex: string;+ embed: string;+ embedSettings: string;+ palette: string;+ tableSettings: string;+ math: string;+ mathBlock: string;+ outlineList: string;+ fontFamily: string;+ fontSize: string;+ heading: string;+ plus: string;+ minus: string;+ close: string;+ delete: string;+ download: string;+ chevronDown: string;+ chevronUp: string;+ chevronRight: string;+ chevronLeft: string;+ circle: string;+ arrowLeft: string;+ none: string;+};+export declare type IconNames = keyof typeof Icons;diff --git a/packages/editor/dist/es/toolbar/icons.js b/packages/editor/dist/es/toolbar/icons.jsnew file mode 100644index 000000000..9f79e87c4--- /dev/null+++ b/packages/editor/dist/es/toolbar/icons.js@@ -0,0 +1,96 @@+import { mdiAttachment, mdiBorderHorizontal, mdiCheck, mdiChevronDown, mdiCodeBraces, mdiCodeTags, mdiDotsVertical, mdiFormatAlignCenter, mdiFormatAlignJustify, mdiFormatAlignLeft, mdiFormatAlignRight, mdiFormatBold, mdiFormatClear, mdiFormatColorHighlight, mdiFormatColorText, mdiFormatItalic, mdiFormatListBulleted, mdiFormatListNumbered, mdiFormatQuoteClose, mdiFormatStrikethrough, mdiFormatSubscript, mdiFormatSuperscript, mdiFormatTextdirectionLToR, mdiFormatTextdirectionRToL, mdiFormatUnderline, mdiImage, mdiInvertColorsOff, mdiLinkPlus, mdiLoading, mdiTable, mdiTableBorder, mdiTableRowPlusAfter, mdiTableRowPlusBefore, mdiTableRowRemove, mdiTableColumnPlusAfter, mdiTableColumnPlusBefore, mdiTableColumnRemove, mdiUploadOutline, mdiPlus, mdiFormatColorFill, mdiClose, mdiSortDescending, mdiArrowExpandRight, mdiArrowExpandLeft, mdiArrowExpandDown, mdiArrowExpandUp, mdiTableMergeCells, mdiTableSplitCell, mdiDeleteOutline, mdiDownloadOutline, mdiFormatListCheckbox, mdiDrag, mdiCheckboxMarkedOutline, mdiChevronUp, mdiArrowUp, mdiArrowDown, mdiRegex, mdiFormatLetterCase, mdiFormatLetterMatches, mdiMoviePlusOutline, mdiLink, mdiChevronRight, mdiTableColumnWidth, mdiTableRowHeight, mdiMinus, mdiPaletteOutline, mdiCircle, mdiChevronLeft, mdiTableCog, mdiTableOff, mdiRectangle, mdiImageEditOutline, mdiArrowLeft, mdiMovieCogOutline, mdiLinkOff, mdiOpenInNew, mdiCameraOutline, mdiMathIntegral, mdiFunctionVariant, mdiFileTreeOutline, mdiFormatFont, mdiFormatFontSizeIncrease, mdiFormatHeaderPound, } from "@mdi/js";+export const Icons = {+ bold: mdiFormatBold,+ italic: mdiFormatItalic,+ underline: mdiFormatUnderline,+ strikethrough: mdiFormatStrikethrough,+ code: mdiCodeTags,+ codeRemove: `M3.62109375 1.83837892 2.26318358 3.13037107 6.46289063 7.536621 1.9995117 12l6.0000003 6 1.40039025-1.400391L4.80029295 12l3.0292968-3.0292965 7.0283205 7.371093-.2578125.2578125L16.000488 18l.224121-.224121 4.3125 4.52490225 1.35791025-1.29492225-4.34326125-4.55712825L22.000488 12l-6-6-1.40039025 1.40039063L19.19970675 12l-3.016113 3.016113L9.156738 7.6435545l.24316425-.24316387L7.999512 6l-.2109375.2109375Z`,+ alignCenter: mdiFormatAlignCenter,+ alignLeft: mdiFormatAlignLeft,+ alignRight: mdiFormatAlignRight,+ alignJustify: mdiFormatAlignJustify,+ subscript: mdiFormatSubscript,+ superscript: mdiFormatSuperscript,+ horizontalRule: mdiBorderHorizontal,+ codeblock: mdiCodeBraces,+ blockquote: mdiFormatQuoteClose,+ formatClear: mdiFormatClear,+ ltr: mdiFormatTextdirectionLToR,+ rtl: mdiFormatTextdirectionRToL,+ numberedList: mdiFormatListNumbered,+ bulletList: mdiFormatListBulleted,+ highlight: mdiFormatColorHighlight,+ textColor: mdiFormatColorText,+ link: mdiLinkPlus,+ linkRemove: mdiLinkOff,+ openLink: mdiOpenInNew,+ linkEdit: "m19 14 1.28 1.28c.22.21.22.56 0 .77l-1 1L17.23 15l1-1c.11-.11.25-.17.39-.17s.27.06.38.17m-.3 3.63-6.06 6.07h-2.06v-2.06l6.07-6.06zM7 7h4v2H7c-1.6568542 0-3 1.343146-3 3s1.3431458 3 3 3h4v2H7c-2.7614237 0-5-2.238576-5-5 0-2.7614237 2.2385763-5 5-5m10 0c2.761424 0 5 2.2385763 5 5h-2c0-1.656854-1.343146-3-3-3h-4V7h4m-9 4h8v2H8v-2",+ linkSettings: "M7 7h4v2H7c-1.6568542 0-3 1.343146-3 3s1.3431458 3 3 3h4v2H7c-2.7614237 0-5-2.238576-5-5 0-2.7614237 2.2385763-5 5-5m10 0c2.761424 0 5 2.2385763 5 5h-2c0-1.656854-1.343146-3-3-3h-4V7h4m-9 4h8v2H8v-2m15.119777 8.323608-1.07-.82c.02-.17.04-.33.04-.5 0-.17-.01-.33-.04-.5l1.06-.82c.09258-.07939.117526-.212463.06-.32l-1-1.73c-.06-.13-.19-.13-.33-.13l-1.22.5c-.28-.18-.54-.35-.85-.47l-.19-1.32c-.01-.12-.12-.21-.24-.21h-2c-.12 0-.23.09-.25.21l-.19 1.32c-.3.13-.59.29-.85.47l-1.24-.5c-.11 0-.24 0-.31.13l-1 1.73c-.06.11-.04.24.06.32l1.06.82c-.03989.33214-.03989.66786 0 1l-1.06.82c-.09258.07939-.117526.212462-.06.32l1 1.73c.06.13.19.13.31.13l1.24-.5c.26.18.54.35.85.47l.19 1.32c.02.12.12.21.25.21h2c.12 0 .23-.09.25-.21l.19-1.32c.3-.13.56-.29.84-.47l1.22.5c.14 0 .27 0 .34-.13l1-1.73c.05753-.107538.03258-.240607-.06-.32m-4.78.18c-.83 0-1.5-.67-1.5-1.5s.68-1.5 1.5-1.5 1.5.67 1.5 1.5-.66 1.5-1.5 1.5z",+ url: mdiLink,+ image: mdiImage,+ imageSettings: mdiImageEditOutline,+ colorClear: mdiInvertColorsOff,+ check: mdiCheck,+ checkbox: mdiCheckboxMarkedOutline,+ loading: mdiLoading,+ more: mdiDotsVertical,+ upload: mdiUploadOutline,+ camera: mdiCameraOutline,+ attachment: mdiAttachment,+ table: mdiTable,+ rowProperties: mdiTableRowHeight,+ insertRowBelow: mdiTableRowPlusAfter,+ insertRowAbove: mdiTableRowPlusBefore,+ moveRowDown: mdiArrowExpandDown,+ moveRowUp: mdiArrowExpandUp,+ deleteRow: mdiTableRowRemove,+ toggleHeaderRow: mdiTableBorder,+ columnProperties: mdiTableColumnWidth,+ insertColumnRight: mdiTableColumnPlusAfter,+ insertColumnLeft: mdiTableColumnPlusBefore,+ moveColumnRight: mdiArrowExpandRight,+ moveColumnLeft: mdiArrowExpandLeft,+ deleteColumn: mdiTableColumnRemove,+ cellProperties: mdiRectangle,+ cellBorderColor: "M4 24q-.825 0-1.412-.587Q2 22.825 2 22q0-.825.588-1.413Q3.175 20 4 20h16q.825 0 1.413.587Q22 21.175 22 22q0 .825-.587 1.413Q20.825 24 20 24Zm1-6q-.425 0-.713-.288Q4 17.425 4 17v-2.325q0-.2.075-.388q.075-.187.225-.337l8.75-8.75l3.75 3.75l-8.75 8.75q-.15.15-.337.225q-.188.075-.388.075Zm1-2h.9L14 8.95L13.05 8L6 15.1Zm11.925-8.15l-3.75-3.75l1.8-1.8q.275-.3.7-.288q.425.013.7.288l2.35 2.35q.275.275.275.688q0 .412-.275.712ZM6 16Z",+ backgroundColor: mdiFormatColorFill,+ borderColor: "M4 24q-.825 0-1.412-.587Q2 22.825 2 22q0-.825.588-1.413Q3.175 20 4 20h16q.825 0 1.413.587Q22 21.175 22 22q0 .825-.587 1.413Q20.825 24 20 24Zm1-6q-.425 0-.713-.288Q4 17.425 4 17v-2.325q0-.2.075-.388q.075-.187.225-.337l8.75-8.75l3.75 3.75l-8.75 8.75q-.15.15-.337.225q-.188.075-.388.075Zm1-2h.9L14 8.95L13.05 8L6 15.1Zm11.925-8.15l-3.75-3.75l1.8-1.8q.275-.3.7-.288q.425.013.7.288l2.35 2.35q.275.275.275.688q0 .412-.275.712ZM6 16Z",+ sortDesc: mdiSortDescending,+ deleteTable: mdiTableOff,+ mergeCells: mdiTableMergeCells,+ splitCells: mdiTableSplitCell,+ checklist: mdiFormatListCheckbox,+ dragHandle: mdiDrag,+ previousMatch: mdiArrowUp,+ 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",+ attachmentSettings: "m24.0138 20.223188-1.07-.82c.02-.17.04-.33.04-.5 0-.17-.01-.33-.04-.5l1.06-.82c.09258-.07939.117526-.212463.06-.32l-1-1.73c-.06-.13-.19-.13-.33-.13l-1.22.5c-.28-.18-.54-.35-.85-.47l-.19-1.32c-.01-.12-.12-.21-.24-.21h-2c-.12 0-.23.09-.25.21l-.19 1.32c-.3.13-.59.29-.85.47l-1.24-.5c-.11 0-.24 0-.31.13l-1 1.73c-.06.11-.04.24.06.32l1.06.82c-.03989.33214-.03989.66786 0 1l-1.06.82c-.09258.07939-.117526.212463-.06.32l1 1.73c.06.13.19.13.31.13l1.24-.5c.26.18.54.35.85.47l.19 1.32c.02.12.12.21.25.21h2c.12 0 .23-.09.25-.21l.19-1.32c.3-.13.56-.29.84-.47l1.22.5c.14 0 .27 0 .34-.13l1-1.73c.05753-.107537.03258-.240606-.06-.32m-4.78.18c-.83 0-1.5-.67-1.5-1.5s.68-1.5 1.5-1.5 1.5.67 1.5 1.5-.66 1.5-1.5 1.5zM16.61 13.5c-.8.35-1.5.86-2.07 1.5H9.5c-3.3333319 0-3.3333319-5 0-5H17v1.5H9.5c-.55 0-1 .45-1 1s.45 1 1 1h7.11m-13.11-1c0-2.21 1.79-4 4-4H18c2.434718-.00632 3.435847 3.121347 1.45 4.53.6.04 1.18.17 1.72.38.52-.67.83-1.5.83-2.41 0-2.21-1.79-4-4-4H7.5C4.46 7 2 9.46 2 12.5S4.46 18 7.5 18h5.59c.09-.53.25-1.03.46-1.5H7.5c-2.21 0-4-1.79-4-4",+ caseSensitive: mdiFormatLetterCase,+ wholeWord: mdiFormatLetterMatches,+ regex: mdiRegex,+ embed: mdiMoviePlusOutline,+ embedSettings: mdiMovieCogOutline,+ palette: mdiPaletteOutline,+ tableSettings: mdiTableCog,+ math: mdiFunctionVariant,+ mathBlock: mdiMathIntegral,+ outlineList: mdiFileTreeOutline,+ fontFamily: mdiFormatFont,+ fontSize: mdiFormatFontSizeIncrease,+ heading: mdiFormatHeaderPound,+ plus: mdiPlus,+ minus: mdiMinus,+ close: mdiClose,+ delete: mdiDeleteOutline,+ download: mdiDownloadOutline,+ chevronDown: mdiChevronDown,+ chevronUp: mdiChevronUp,+ chevronRight: mdiChevronRight,+ chevronLeft: mdiChevronLeft,+ circle: mdiCircle,+ arrowLeft: mdiArrowLeft,+ none: "",+};diff --git a/packages/editor/dist/es/toolbar/index.d.ts b/packages/editor/dist/es/toolbar/index.d.tsnew file mode 100644index 000000000..37d1c1dbe--- /dev/null+++ b/packages/editor/dist/es/toolbar/index.d.ts@@ -0,0 +1,7 @@+import { Toolbar } from "./toolbar";+export default Toolbar;+export * from "./types";+export * from "./icons";+export * from "./components/icon";+export * from "./tools";+export * from "./tool-definitions";diff --git a/packages/editor/dist/es/toolbar/index.js b/packages/editor/dist/es/toolbar/index.jsnew file mode 100644index 000000000..37d1c1dbe--- /dev/null+++ b/packages/editor/dist/es/toolbar/index.js@@ -0,0 +1,7 @@+import { Toolbar } from "./toolbar";+export default Toolbar;+export * from "./types";+export * from "./icons";+export * from "./components/icon";+export * from "./tools";+export * from "./tool-definitions";diff --git a/packages/editor/dist/es/toolbar/popups/cellproperties.d.ts b/packages/editor/dist/es/toolbar/popups/cellproperties.d.tsnew file mode 100644index 000000000..7c0de5a61--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/cellproperties.d.ts@@ -0,0 +1,8 @@+/// <reference types="react" />+import { Editor } from "../../types";+declare type CellPropertiesProps = {+ editor: Editor;+ onClose: () => void;+};+export declare function CellProperties(props: CellPropertiesProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/popups/cellproperties.js b/packages/editor/dist/es/toolbar/popups/cellproperties.jsnew file mode 100644index 000000000..baabde8ac--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/cellproperties.js@@ -0,0 +1,22 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Box } from "rebass";+import { Tab, Tabs } from "../../components/tabs";+import { Icon } from "../components/icon";+// import { MenuPresenter } from "../../components/menu/menu";+import { Popup } from "../components/popup";+import { Icons } from "../icons";+import { ColorPicker } from "./color-picker";+export function CellProperties(props) {+ const { editor, onClose } = props;+ const attributes = editor.getAttributes("tableCell");+ return (_jsx(Popup, Object.assign({ title: "Cell properties", onClose: onClose }, { children: _jsxs(Tabs, Object.assign({ activeIndex: 0 }, { children: [_jsxs(Tab, Object.assign({ title: _jsx(Icon, { title: "Cell background color", path: Icons.backgroundColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.backgroundColor, onChange: (color) => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", color);+ }, onClear: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", undefined);+ } })] })), _jsxs(Tab, Object.assign({ title: _jsx(Icon, { title: "Cell text color", path: Icons.textColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.color, onChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", color); }, onClear: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", undefined); } })] })), _jsxs(Tab, Object.assign({ title: _jsx(Icon, { title: "Cell border color", path: Icons.cellBorderColor, size: 16 }) }, { children: [_jsx(Box, { mt: 2 }), _jsx(ColorPicker, { expanded: true, color: attributes.borderColor, onChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", color); }, onClear: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", undefined);+ } })] }))] })) })));+}diff --git a/packages/editor/dist/es/toolbar/popups/colorpicker.d.ts b/packages/editor/dist/es/toolbar/popups/colorpicker.d.tsnew file mode 100644index 000000000..e9870067d--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/colorpicker.d.ts@@ -0,0 +1,13 @@+/// <reference types="react" />+export declare const DEFAULT_COLORS: string[];+declare type ColorPickerProps = {+ colors?: string[];+ color?: string;+ onClear: () => void;+ expanded?: boolean;+ onChange: (color: string) => void;+ onClose?: () => void;+ title?: string;+};+export declare function ColorPicker(props: ColorPickerProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/popups/colorpicker.js b/packages/editor/dist/es/toolbar/popups/colorpicker.jsnew file mode 100644index 000000000..f403e7e3c--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/colorpicker.js@@ -0,0 +1,116 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { Box, Flex, Text } from "rebass";+import { Input } from "@rebass/forms";+import { Icon } from "../components/icon";+import { Icons } from "../icons";+import { useCallback, useEffect, useRef, useState } from "react";+import tinycolor from "tinycolor2";+import { HexColorPicker } from "react-colorful";+import { Button } from "../../components/button";+import { debounce } from "../../utils/debounce";+export const DEFAULT_COLORS = [+ "#e91e63",+ "#9c27b0",+ "#673ab7",+ "#3f51b5",+ "#2196f3",+ "#03a9f4",+ "#00bcd4",+ "#009688",+ "#4caf50",+ "#8bc34a",+ "#cddc39",+ "#ffeb3b",+ "#ffc107",+ "#f44336",+];+const PALETTE_SIZE = [35, 35, 25];+export function ColorPicker(props) {+ const { colors = DEFAULT_COLORS, color, onClear, onChange, title, onClose, expanded, } = props;+ const ref = useRef();+ const [isPickerOpen, setIsPickerOpen] = useState(expanded || false);+ const [currentColor, setCurrentColor] = useState(tinycolor(color || colors[0]).toHexString());+ const tColor = tinycolor(currentColor);+ useEffect(() => {+ if (!ref.current)+ return;+ if (isPickerOpen)+ ref.current.focus({ preventScroll: true });+ }, [isPickerOpen]);+ const onColorChange = useCallback(debounce((color) => {+ onChange(color);+ }, 500), [onChange]);+ return (_jsxs(Flex, Object.assign({ ref: ref, tabIndex: -1, sx: {+ bg: "background",+ flexDirection: "column",+ ".react-colorful": {+ width: "auto",+ height: 150,+ },+ ".react-colorful__saturation": {+ borderRadius: ["default", 0],+ },+ width: ["calc(100vw - 20px)", 250],+ // width: ["auto", 250],+ } }, { children: [onClose && (_jsxs(Box, Object.assign({ sx: {+ display: ["none", "flex"],+ justifyContent: "space-between",+ p: 2,+ pb: isPickerOpen ? 2 : 0,+ //pb: 0,+ alignItems: "center",+ }, onClick: onClose }, { children: [_jsx(Text, Object.assign({ variant: "title" }, { children: title })), _jsx(Button, Object.assign({ variant: "icon", sx: { p: 0 } }, { children: _jsx(Icon, { path: Icons.close, size: "big" }) }))] }))), isPickerOpen ? (_jsxs(_Fragment, { children: [_jsx(HexColorPicker, { onChange: (color) => {+ setCurrentColor(color);+ onColorChange(color);+ }, onTouchEnd: () => onChange(currentColor), onMouseUp: () => onChange(currentColor) }), _jsx(Input, { variant: "clean", placeholder: "#000000", spellCheck: false, sx: {+ my: 2,+ p: 0,+ borderRadius: 0,+ fontSize: ["title", "title", "body"],+ color: "fontTertiary",+ textAlign: "center",+ letterSpacing: 1.5,+ }, value: currentColor.toUpperCase(), maxLength: 7, onChange: (e) => {+ const { value } = e.target;+ if (!value)+ return;+ if (tinycolor(value, { format: "hex" }).isValid()) {+ setCurrentColor(value);+ onChange(value);+ }+ } })] })) : null, _jsxs(Flex, { children: [_jsxs(Flex, Object.assign({ className: "hide-scrollbar", sx: {+ flex: 1,+ p: 1,+ overflowX: ["auto", "hidden"],+ flexWrap: ["nowrap", "wrap"],+ } }, { children: [_jsx(Button, Object.assign({ variant: "icon", sx: {+ flexShrink: 0,+ width: PALETTE_SIZE,+ height: PALETTE_SIZE,+ borderRadius: 50,+ boxShadow: "menu",+ p: 0,+ ml: [2, 2, 1],+ }, onClick: onClear }, { children: _jsx(Icon, { path: Icons.colorClear, color: "text", size: 15 }) })), _jsx(Button, Object.assign({ variant: "secondary", sx: {+ flexShrink: 0,+ bg: currentColor,+ width: PALETTE_SIZE,+ height: PALETTE_SIZE,+ borderRadius: 50,+ // boxShadow: "menu",+ p: 0,+ ml: [2, 2, 1],+ }, onClick: () => setIsPickerOpen((s) => !s) }, { children: _jsx(Icon, { path: Icons.palette, color: tColor.isDark() ? "static" : "icon", size: 18 }) })), colors.map((color) => (_jsx(Button, { variant: "secondary", sx: {+ flex: "0 0 auto",+ bg: color,+ width: PALETTE_SIZE,+ height: PALETTE_SIZE,+ ml: [2, 1, 1],+ mb: [0, 1, 1],+ borderRadius: 50,+ // boxShadow: "menu",+ }, onClick: () => {+ setCurrentColor(color);+ onChange(color);+ } }, color)))] })), onClose && (_jsx(Button, Object.assign({ variant: "icon", sx: { display: ["block", "none"], px: 2 }, onClick: onClose }, { children: _jsx(Icon, { path: Icons.close, size: "big" }) })))] })] })));+}diff --git a/packages/editor/dist/es/toolbar/popups/embedpopup.d.ts b/packages/editor/dist/es/toolbar/popups/embedpopup.d.tsnew file mode 100644index 000000000..04e4e1dd6--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/embedpopup.d.ts@@ -0,0 +1,10 @@+/// <reference types="react" />+import { Embed, EmbedSizeOptions } from "../../extensions/embed";+export declare type EmbedPopupProps = {+ onClose: (embed?: Embed) => void;+ title: string;+ embed?: Embed;+ onSizeChanged?: (size: EmbedSizeOptions) => void;+ onSourceChanged?: (src: string) => void;+};+export declare function EmbedPopup(props: EmbedPopupProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/popups/embedpopup.js b/packages/editor/dist/es/toolbar/popups/embedpopup.jsnew file mode 100644index 000000000..256522b8c--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/embedpopup.js@@ -0,0 +1,86 @@+import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";+import { Flex, Text } from "rebass";+import { useCallback, useEffect, useState } from "react";+import { Popup } from "../components/popup";+import { Input, Textarea } from "@rebass/forms";+import { convertUrlToEmbedUrl } from "@social-embed/lib";+import { InlineInput } from "../../components/inline-input";+import { Tabs, Tab } from "../../components/tabs";+export function EmbedPopup(props) {+ const { onClose, onSizeChanged, onSourceChanged, title, embed } = props;+ const [width, setWidth] = useState((embed === null || embed === void 0 ? void 0 : embed.width) || 300);+ const [height, setHeight] = useState((embed === null || embed === void 0 ? void 0 : embed.height) || 150);+ const [src, setSrc] = useState((embed === null || embed === void 0 ? void 0 : embed.src) || "");+ const [embedSource, setEmbedSource] = useState("url");+ const [error, setError] = useState(null);+ const onSizeChange = useCallback((newWidth, newHeight) => {+ const size = newWidth+ ? {+ width: newWidth,+ height: newWidth * (height / width),+ }+ : newHeight+ ? {+ width: newHeight * (width / height),+ height: newHeight,+ }+ : {+ width: 0,+ height: 0,+ };+ setWidth(size.width);+ setHeight(size.height);+ if (onSizeChanged)+ onSizeChanged(size);+ }, [width, height]);+ useEffect(() => {+ onSourceChanged && onSourceChanged(src);+ }, [onSourceChanged, src]);+ return (_jsx(Popup, Object.assign({ title: title, onClose: () => onClose(), action: {+ title,+ onClick: () => {+ setError(null);+ let _src = src;+ let _width = width;+ let _height = height;+ if (embedSource === "code") {+ const document = new DOMParser().parseFromString(src, "text/html");+ if (document.getElementsByTagName("iframe").length <= 0)+ return setError("Embed code must include an iframe.");+ const srcValue = getAttribute(document, "src");+ if (!srcValue)+ return setError("Embed code must include an iframe with an src attribute.");+ _src = srcValue;+ const widthValue = getAttribute(document, "width");+ if (widthValue && !isNaN(parseInt(widthValue)))+ _width = parseInt(widthValue);+ const heightValue = getAttribute(document, "height");+ if (heightValue && !isNaN(parseInt(heightValue)))+ _height = parseInt(heightValue);+ }+ const convertedUrl = convertUrlToEmbedUrl(_src);+ if (!!convertedUrl)+ _src = convertedUrl;+ onClose({+ height: _height,+ width: _width,+ src: _src,+ });+ },+ } }, { children: _jsxs(Flex, Object.assign({ sx: { flexDirection: "column", width: ["auto", 300] } }, { children: [error && (_jsxs(Text, Object.assign({ variant: "error", sx: {+ bg: "errorBg",+ color: "error",+ p: 1,+ borderRadius: "default",+ } }, { children: ["Error: ", error] }))), _jsxs(Tabs, Object.assign({ activeIndex: 0, containerProps: { sx: { mx: 1, flexDirection: "column" } }, onTabChanged: (index) => setEmbedSource(index === 0 ? "url" : "code") }, { children: [_jsxs(Tab, Object.assign({ title: "From URL" }, { children: [_jsx(Input, { placeholder: "Enter embed source URL", value: src, autoFocus: true, onChange: (e) => setSrc(e.target.value), autoCapitalize: "none", sx: { fontSize: "body" } }), _jsxs(Flex, Object.assign({ sx: { alignItems: "center", mt: 1 } }, { children: [_jsx(InlineInput, { containerProps: { sx: { mr: 1 } }, label: "width", type: "number", placeholder: "Width", value: width, sx: {+ mr: 1,+ fontSize: "body",+ }, onChange: (e) => onSizeChange(e.target.valueAsNumber) }), _jsx(InlineInput, { label: "height", type: "number", placeholder: "Height", value: height, sx: { fontSize: "body" }, onChange: (e) => onSizeChange(undefined, e.target.valueAsNumber) })] }))] })), _jsx(Tab, Object.assign({ title: "From code" }, { children: _jsx(Textarea, { autoFocus: true, variant: "forms.input", sx: { fontSize: "subBody", fontFamily: "monospace" }, minHeight: [200, 100], onChange: (e) => setSrc(e.target.value), placeholder: "Paste embed code here. Only iframes are supported." }) }))] }))] })) })));+}+function getAttribute(document, id) {+ const element = document.querySelector(`[${id}]`);+ if (!element)+ return null;+ const attribute = element.getAttribute(id);+ return attribute;+}diff --git a/packages/editor/dist/es/toolbar/popups/imageproperties.d.ts b/packages/editor/dist/es/toolbar/popups/imageproperties.d.tsnew file mode 100644index 000000000..5ed787264--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/imageproperties.d.ts@@ -0,0 +1,8 @@+/// <reference types="react" />+import { ImageAlignmentOptions, ImageSizeOptions } from "../../extensions/image";+import { Editor } from "@tiptap/core";+export declare type ImagePropertiesProps = ImageSizeOptions & ImageAlignmentOptions & {+ editor: Editor;+ onClose: () => void;+};+export declare function ImageProperties(props: ImagePropertiesProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/popups/imageproperties.js b/packages/editor/dist/es/toolbar/popups/imageproperties.jsnew file mode 100644index 000000000..50bc47da4--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/imageproperties.js@@ -0,0 +1,32 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Flex, Text } from "rebass";+import { useCallback } from "react";+import { Popup } from "../components/popup";+import { Checkbox } from "@rebass/forms";+import { InlineInput } from "../../components/inline-input";+export function ImageProperties(props) {+ const { height, width, float, editor, onClose } = props;+ const onSizeChange = useCallback((newWidth, newHeight) => {+ const size = newWidth+ ? {+ width: newWidth,+ height: newWidth * (height / width),+ }+ : newHeight+ ? {+ width: newHeight * (width / height),+ height: newHeight,+ }+ : {+ width: 0,+ height: 0,+ };+ editor.chain().setImageSize(size).run();+ }, [width, height]);+ return (_jsx(Popup, Object.assign({ title: "Image properties", onClose: onClose }, { children: _jsxs(Flex, Object.assign({ sx: { width: ["auto", 300], flexDirection: "column", p: 1 } }, { children: [_jsxs(Flex, Object.assign({ sx: { justifyContent: "space-between", alignItems: "center" } }, { children: [_jsx(Text, Object.assign({ variant: "body" }, { children: "Floating?" })), _jsx(Checkbox, { checked: float, onClick: () => editor+ .chain()+ .setImageAlignment({ float: !float, align: "left" })+ .run() })] })), _jsxs(Flex, Object.assign({ sx: { alignItems: "center", mt: 2 } }, { children: [_jsx(InlineInput, { label: "width", type: "number", value: width, containerProps: {+ sx: { mr: 1 },+ }, onChange: (e) => onSizeChange(e.target.valueAsNumber) }), _jsx(InlineInput, { label: "height", type: "number", value: height, onChange: (e) => onSizeChange(undefined, e.target.valueAsNumber) })] }))] })) })));+}diff --git a/packages/editor/dist/es/toolbar/popups/imageupload.d.ts b/packages/editor/dist/es/toolbar/popups/imageupload.d.tsnew file mode 100644index 000000000..306f74f64--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/imageupload.d.ts@@ -0,0 +1,7 @@+/// <reference types="react" />+import { ImageAttributes } from "../../extensions/image";+export declare type ImageUploadPopupProps = {+ onInsert: (image: ImageAttributes) => void;+ onClose: () => void;+};+export declare function ImageUploadPopup(props: ImageUploadPopupProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/popups/imageupload.js b/packages/editor/dist/es/toolbar/popups/imageupload.jsnew file mode 100644index 000000000..a4526f146--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/imageupload.js@@ -0,0 +1,74 @@+var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }+ return new (P || (P = Promise))(function (resolve, reject) {+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }+ step((generator = generator.apply(thisArg, _arguments || [])).next());+ });+};+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Input } from "@rebass/forms";+import { useState } from "react";+import { Flex, Text } from "rebass";+import { Popup } from "../components/popup";+export function ImageUploadPopup(props) {+ const { onInsert, onClose } = props;+ const [isDownloading, setIsDownloading] = useState(false);+ const [error, setError] = useState();+ const [url, setUrl] = useState("");+ return (_jsx(Popup, Object.assign({ title: "Insert image from URL", onClose: onClose, action: {+ loading: isDownloading,+ title: "Insert image",+ disabled: !url,+ onClick: () => __awaiter(this, void 0, void 0, function* () {+ setIsDownloading(true);+ setError(undefined);+ try {+ const response = yield fetch(url);+ if (!response.ok)+ return setError(`invalid status code ${response.status}`);+ const contentType = response.headers.get("Content-Type");+ const contentLength = response.headers.get("Content-Length");+ if (!contentType ||+ !contentLength ||+ contentLength === "0" ||+ !contentType.startsWith("image/"))+ return setError("not an image");+ const size = parseInt(contentLength);+ const dataurl = yield toDataURL(yield response.blob());+ onInsert({ src: dataurl, type: contentType, size });+ }+ catch (e) {+ if (e instanceof Error)+ setError(e.message);+ }+ finally {+ setIsDownloading(false);+ }+ }),+ } }, { children: _jsxs(Flex, Object.assign({ sx: { px: 1, flexDirection: "column", width: ["auto", 350] } }, { children: [_jsx(Input, { type: "url", autoFocus: true, placeholder: "Paste Image URL here", value: url, onChange: (e) => {+ setUrl(e.target.value);+ setError(undefined);+ } }), error ? (_jsxs(Text, Object.assign({ variant: "error", sx: {+ bg: "errorBg",+ mt: 1,+ p: 1,+ borderRadius: "default",+ } }, { children: ["Failed to download image: ", error.toLowerCase(), "."] }))) : (_jsx(Text, Object.assign({ variant: "subBody", sx: {+ bg: "shade",+ color: "primary",+ mt: 1,+ p: 1,+ borderRadius: "default",+ } }, { children: "To protect your privacy, we will download the image & add it to your attachments." })))] })) })));+}+function toDataURL(blob) {+ return new Promise((resolve, reject) => {+ const reader = new FileReader();+ reader.onload = (_e) => resolve(reader.result);+ reader.onerror = (_e) => reject(reader.error);+ reader.onabort = (_e) => reject(new Error("Read aborted"));+ reader.readAsDataURL(blob);+ });+}diff --git a/packages/editor/dist/es/toolbar/popups/linkpopup.d.ts b/packages/editor/dist/es/toolbar/popups/linkpopup.d.tsnew file mode 100644index 000000000..1d6894848--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/linkpopup.d.ts@@ -0,0 +1,12 @@+/// <reference types="react" />+export declare type LinkPopupProps = {+ text?: string;+ href?: string;+ isEditing?: boolean;+ onDone: (link: {+ text: string;+ href: string;+ }) => void;+ onClose: () => void;+};+export declare function LinkPopup(props: LinkPopupProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/popups/linkpopup.js b/packages/editor/dist/es/toolbar/popups/linkpopup.jsnew file mode 100644index 000000000..90add5bce--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/linkpopup.js@@ -0,0 +1,14 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Input } from "@rebass/forms";+import { useState } from "react";+import { Flex } from "rebass";+import { Popup } from "../components/popup";+export function LinkPopup(props) {+ const { text: _text, href: _href, isEditing = false, onDone, onClose, } = props;+ const [href, setHref] = useState(_href || "");+ const [text, setText] = useState(_text || "");+ return (_jsx(Popup, Object.assign({ title: isEditing ? "Edit link" : "Insert link", onClose: onClose, action: {+ title: isEditing ? "Save edits" : "Insert link",+ onClick: () => onDone({ text, href }),+ } }, { children: _jsxs(Flex, Object.assign({ sx: { p: 1, flexDirection: "column", width: ["auto", 250] } }, { children: [_jsx(Input, { type: "text", placeholder: "Link text", value: text, onChange: (e) => setText(e.target.value) }), _jsx(Input, { type: "url", sx: { mt: 1 }, autoFocus: true, placeholder: "https://example.com/", value: href, onChange: (e) => setHref(e.target.value) })] })) })));+}diff --git a/packages/editor/dist/es/toolbar/popups/searchreplace.d.ts b/packages/editor/dist/es/toolbar/popups/searchreplace.d.tsnew file mode 100644index 000000000..74cbb2e62--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/searchreplace.d.ts@@ -0,0 +1,6 @@+/// <reference types="react" />+import { Editor } from "@tiptap/core";+export declare type SearchReplacePopupProps = {+ editor: Editor;+};+export declare function SearchReplacePopup(props: SearchReplacePopupProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/popups/searchreplace.js b/packages/editor/dist/es/toolbar/popups/searchreplace.jsnew file mode 100644index 000000000..1a7cd422f--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/searchreplace.js@@ -0,0 +1,82 @@+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, Text } from "rebass";+import { ToolButton } from "../components/tool-button";+export function SearchReplacePopup(props) {+ const { editor } = props;+ const { selectedText, results } = editor.storage+ .searchreplace;+ 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);+ const replaceText = useRef("");+ const searchInputRef = useRef();+ const search = useCallback((term) => {+ editor.commands.search(term, {+ matchCase,+ enableRegex,+ matchWholeWord,+ });+ }, [matchCase, enableRegex, matchWholeWord]);+ useEffect(() => {+ if (!searchInputRef.current)+ return;+ search(searchInputRef.current.value);+ }, [search, matchCase, matchWholeWord, enableRegex]);+ useEffect(() => {+ if (selectedText) {+ if (searchInputRef.current) {+ const input = searchInputRef.current;+ setTimeout(() => {+ input.value = selectedText;+ input.focus();+ }, 0);+ }+ search(selectedText);+ }+ }, [selectedText, search]);+ return (_jsx(Flex, Object.assign({ sx: {+ p: 1,+ bg: "background",+ flexDirection: "column",+ boxShadow: ["none", "menu"],+ borderRadius: [0, "default"],+ } }, { children: _jsxs(Flex, { children: [_jsxs(Flex, Object.assign({ sx: { flexDirection: "column", flex: 1, width: ["auto", 300], mr: 1 } }, { children: [_jsxs(Flex, Object.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: (e) => {+ search(e.target.value);+ } }), _jsxs(Flex, Object.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: () => setIsExpanded((s) => !s), iconSize: "medium" }), isExpanded && (_jsxs(_Fragment, { children: [_jsx(ToolButton, { sx: {+ mr: 0,+ }, toggled: matchCase, title: "Match case", id: "matchCase", icon: "caseSensitive", onClick: () => setMatchCase((s) => !s), iconSize: "medium" }), _jsx(ToolButton, { sx: {+ mr: 0,+ }, toggled: matchWholeWord, title: "Match whole word", id: "matchWholeWord", icon: "wholeWord", onClick: () => setMatchWholeWord((s) => !s), iconSize: "medium" }), _jsx(ToolButton, { sx: {+ mr: 0,+ }, toggled: enableRegex, title: "Enable regex", id: "enableRegex", icon: "regex", onClick: () => setEnableRegex((s) => !s), iconSize: "medium" })] })), _jsxs(Text, Object.assign({ variant: "subBody", sx: {+ flexShrink: 0,+ borderLeft: "1px solid var(--border)",+ color: "fontTertiary",+ px: 1,+ } }, { children: [results ? `${results.length}` : "0", isExpanded ? "" : " results"] }))] }))] })), isReplacing && (_jsx(Input, { sx: { mt: 1, p: "7px" }, placeholder: "Replace", onChange: (e) => (replaceText.current = e.target.value) }))] })), _jsxs(Flex, Object.assign({ sx: { flexDirection: "column" } }, { children: [_jsxs(Flex, Object.assign({ sx: { alignItems: "center", height: "33.2px" } }, { children: [_jsx(ToolButton, { toggled: isReplacing, title: "Toggle replace", id: "toggleReplace", icon: "replace", onClick: () => setIsReplacing((s) => !s), sx: { mr: 0 }, iconSize: "big" }), _jsx(ToolButton, { toggled: false, title: "Previous match", id: "previousMatch", icon: "previousMatch", onClick: () => editor.commands.moveToPreviousResult(), sx: { mr: 0 }, iconSize: "big" }), _jsx(ToolButton, { toggled: false, title: "Next match", id: "nextMatch", icon: "nextMatch", onClick: () => editor.commands.moveToNextResult(), sx: { mr: 0 }, iconSize: "big" }), _jsx(ToolButton, { toggled: false, title: "Close", id: "close", icon: "close", onClick: () => editor.chain().focus().endSearch().run(), sx: { mr: 0 }, iconSize: "big" })] })), isReplacing && (_jsxs(Flex, Object.assign({ sx: { alignItems: "center", height: "33.2px", mt: 1 } }, { children: [_jsx(ToolButton, { toggled: false, title: "Replace", id: "replace", icon: "replaceOne", onClick: () => editor.commands.replace(replaceText.current), sx: { mr: 0 }, iconSize: 18 }), _jsx(ToolButton, { toggled: false, title: "Replace all", id: "replaceAll", icon: "replaceAll", onClick: () => editor.commands.replaceAll(replaceText.current), sx: { mr: 0 }, iconSize: 18 })] })))] }))] }) })));+}diff --git a/packages/editor/dist/es/toolbar/popups/tablepopup.d.ts b/packages/editor/dist/es/toolbar/popups/tablepopup.d.tsnew file mode 100644index 000000000..0e35ac702--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/tablepopup.d.ts@@ -0,0 +1,10 @@+/// <reference types="react" />+declare type TableSize = {+ columns: number;+ rows: number;+};+export declare type TablePopupProps = {+ onInsertTable: (size: TableSize) => void;+};+export declare function TablePopup(props: TablePopupProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/popups/tablepopup.js b/packages/editor/dist/es/toolbar/popups/tablepopup.jsnew file mode 100644index 000000000..830001055--- /dev/null+++ b/packages/editor/dist/es/toolbar/popups/tablepopup.js@@ -0,0 +1,107 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Box, Flex, Text } from "rebass";+import { useEffect, useState } from "react";+import { Popup } from "../components/popup";+import { useIsMobile } from "../stores/toolbar-store";+import { InlineInput } from "../../components/inline-input";+const MAX_COLUMNS = 20;+const MAX_ROWS = 20;+const MIN_COLUMNS = 10;+const MIN_ROWS = 6;+export function TablePopup(props) {+ const isMobile = useIsMobile();+ const autoExpand = !isMobile;+ const cellSize = isMobile ? 30 : 15;+ const { onInsertTable } = props;+ const [cellLocation, setCellLocation] = useState({+ column: 0,+ row: 0,+ });+ const [tableSize, setTableSize] = useState({+ columns: MIN_COLUMNS,+ rows: MIN_ROWS,+ });+ useEffect(() => {+ if (!autoExpand)+ return;+ setTableSize((old) => {+ const { columns, rows } = old;+ const { column, row } = cellLocation;+ let isDecrease = row === rows - 2 || column === columns - 2;+ let rowFactor = Number(row === rows || row === rows - 2);+ let columnFactor = Number(column === columns || column === columns - 2);+ return {+ columns: isDecrease+ ? Math.max(column + columnFactor, MIN_COLUMNS)+ : Math.min(old.columns + columnFactor, MAX_COLUMNS),+ rows: isDecrease+ ? Math.max(row + rowFactor, MIN_ROWS)+ : Math.min(old.rows + rowFactor, MAX_ROWS),+ };+ });+ }, [cellLocation, autoExpand]);+ return (_jsx(Popup, Object.assign({ action: {+ title: !cellLocation.column || !cellLocation.row+ ? "Please set a table size"+ : `Insert a ${cellLocation.column} x ${cellLocation.row} table`,+ disabled: !cellLocation.column || !cellLocation.row,+ onClick: () => onInsertTable({+ columns: cellLocation.column,+ rows: cellLocation.row,+ }),+ } }, { children: _jsxs(Flex, Object.assign({ sx: { px: 1, pt: 1, flexDirection: "column", alignItems: "center" } }, { children: [_jsx(Box, Object.assign({ sx: {+ display: "grid",+ gridTemplateColumns: `repeat(${tableSize.columns}, minmax(${cellSize}px, 1fr))`,+ gap: "small",+ bg: "background",+ width: "100%",+ }, onTouchMove: (e) => {+ const touch = e.touches.item(0);+ const element = document.elementFromPoint(touch.pageX, touch.pageY);+ if (!element)+ return;+ const index = element.dataset.index;+ if (!index)+ return;+ setCellLocation(getCellLocation(parseInt(index), tableSize));+ } }, { children: Array(tableSize.columns * tableSize.rows)+ .fill(0)+ .map((_, index) => (_jsx(Box, { "data-index": index, height: cellSize || 15, sx: {+ border: "1px solid var(--disabled)",+ borderRadius: "small",+ bg: isCellHighlighted(index, cellLocation, tableSize)+ ? "disabled"+ : "transparent",+ }, onTouchStart: () => {+ setCellLocation(getCellLocation(index, tableSize));+ }, onMouseEnter: () => {+ setCellLocation(getCellLocation(index, tableSize));+ }, onClick: () => {+ onInsertTable({+ columns: cellLocation.column,+ rows: cellLocation.row,+ });+ } }, index))) })), _jsxs(Flex, Object.assign({ sx: {+ display: ["flex", "none", "none"],+ mt: 1,+ alignItems: "center",+ justifyContent: "center",+ } }, { children: [_jsx(InlineInput, { containerProps: { sx: { mr: 1 } }, label: "columns", placeholder: `${cellLocation.column} columns`, type: "number", value: cellLocation.column, onChange: (e) => {+ setCellLocation((l) => (Object.assign(Object.assign({}, l), { column: e.target.valueAsNumber || 0 })));+ } }), _jsx(InlineInput, { label: "rows", placeholder: `${cellLocation.row} rows`, type: "number", value: cellLocation.row, onChange: (e) => {+ setCellLocation((l) => (Object.assign(Object.assign({}, l), { row: e.target.valueAsNumber || 0 })));+ } })] })), _jsxs(Text, Object.assign({ variant: "body", sx: { mt: 1, display: ["none", "block", "block"] } }, { children: [cellLocation.column, " x ", cellLocation.row] }))] })) })));+}+function getCellLocation(index, tableSize) {+ const cellIndex = index + 1;+ const column = cellIndex % tableSize.columns;+ let row = cellIndex / tableSize.columns;+ const flooredRow = Math.floor(row);+ row = row === flooredRow ? row : flooredRow + 1;+ return { column: column ? column : tableSize.columns, row };+}+function isCellHighlighted(index, currentCellLocation, tableSize) {+ const cellLocation = getCellLocation(index, tableSize);+ return (cellLocation.row <= currentCellLocation.row &&+ cellLocation.column <= currentCellLocation.column);+}diff --git a/packages/editor/dist/es/toolbar/stores/toolbarstore.d.ts b/packages/editor/dist/es/toolbar/stores/toolbarstore.d.tsnew file mode 100644index 000000000..b5edf835b--- /dev/null+++ b/packages/editor/dist/es/toolbar/stores/toolbarstore.d.ts@@ -0,0 +1,20 @@+export declare type ToolbarLocation = "top" | "bottom";+export declare type PopupRef = {+ id: string;+ group: string;+};+interface ToolbarState {+ isMobile: boolean;+ openedPopups: Record<string, PopupRef | false>;+ setIsMobile: (isMobile: boolean) => void;+ toolbarLocation: ToolbarLocation;+ setToolbarLocation: (location: ToolbarLocation) => void;+ isPopupOpen: (popupId: string) => boolean;+ openPopup: (ref: PopupRef) => void;+ closePopup: (popupId: string) => void;+ closePopupGroup: (groupId: string, excluded: string[]) => void;+}+export declare const useToolbarStore: import("zustand").UseBoundStore<ToolbarState, import("zustand").StoreApi<ToolbarState>>;+export declare function useToolbarLocation(): ToolbarLocation;+export declare function useIsMobile(): boolean;+export {};diff --git a/packages/editor/dist/es/toolbar/stores/toolbarstore.js b/packages/editor/dist/es/toolbar/stores/toolbarstore.jsnew file mode 100644index 000000000..9f059d8d0--- /dev/null+++ b/packages/editor/dist/es/toolbar/stores/toolbarstore.js@@ -0,0 +1,33 @@+import create from "zustand";+export const useToolbarStore = create((set, get) => ({+ isMobile: false,+ openedPopups: {},+ setIsMobile: (isMobile) => set((state) => {+ state.isMobile = isMobile;+ }),+ toolbarLocation: "top",+ setToolbarLocation: (location) => set((state) => {+ state.toolbarLocation = location;+ }),+ closePopup: (id) => set((state) => {+ state.openedPopups = Object.assign(Object.assign({}, state.openedPopups), { [id]: false });+ }),+ isPopupOpen: (id) => !!get().openedPopups[id],+ openPopup: (ref) => set((state) => {+ state.openedPopups = Object.assign(Object.assign({}, state.openedPopups), { [ref.id]: ref });+ }),+ closePopupGroup: (group, excluded) => set((state) => {+ for (const key in state.openedPopups) {+ const ref = state.openedPopups[key];+ if (ref && ref.group === group && !excluded.includes(ref.id)) {+ state.openedPopups[key] = false;+ }+ }+ }),+}));+export function useToolbarLocation() {+ return useToolbarStore((store) => store.toolbarLocation);+}+export function useIsMobile() {+ return useToolbarStore((store) => store.isMobile);+}diff --git a/packages/editor/dist/es/toolbar/toolbar.d.ts b/packages/editor/dist/es/toolbar/toolbar.d.tsnew file mode 100644index 000000000..29e9038aa--- /dev/null+++ b/packages/editor/dist/es/toolbar/toolbar.d.ts@@ -0,0 +1,14 @@+/// <reference types="react" />+import { Theme } from "@notesnook/theme";+import { Editor } from "@tiptap/core";+import { ToolbarLocation } from "./stores/toolbar-store";+import { ToolbarDefinition } from "./types";+declare type ToolbarProps = {+ theme: Theme;+ editor: Editor | null;+ location: ToolbarLocation;+ isMobile?: boolean;+ tools?: ToolbarDefinition;+};+export declare function Toolbar(props: ToolbarProps): JSX.Element | null;+export {};diff --git a/packages/editor/dist/es/toolbar/toolbar.js b/packages/editor/dist/es/toolbar/toolbar.jsnew file mode 100644index 000000000..64e10bf69--- /dev/null+++ b/packages/editor/dist/es/toolbar/toolbar.js@@ -0,0 +1,29 @@+import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";+import { Flex } from "rebass";+import { ThemeProvider } from "emotion-theming";+import { EditorFloatingMenus } from "./floating-menus";+import { DEFAULT_TOOLS } from "./tool-definitions";+import { useEffect } from "react";+import { useToolbarStore, } from "./stores/toolbar-store";+import { ToolbarGroup } from "./components/toolbar-group";+import { EditorContext, PopupRenderer, } from "../components/popup-presenter/popuprenderer";+export function Toolbar(props) {+ const { editor, theme, location, isMobile, tools = DEFAULT_TOOLS } = props;+ const setIsMobile = useToolbarStore((store) => store.setIsMobile);+ const setToolbarLocation = useToolbarStore((store) => store.setToolbarLocation);+ useEffect(() => {+ setIsMobile(isMobile || false);+ setToolbarLocation(location);+ }, [isMobile, location]);+ if (!editor)+ return null;+ return (_jsx(ThemeProvider, Object.assign({ theme: theme }, { children: _jsx(EditorContext.Provider, Object.assign({ value: editor }, { children: _jsxs(PopupRenderer, Object.assign({ editor: editor }, { children: [_jsx(Flex, Object.assign({ className: "editor-toolbar", sx: { flexWrap: ["nowrap", "wrap"], overflowX: ["auto", "hidden"] } }, { children: tools.map((tools) => {+ return (_jsx(ToolbarGroup, { tools: tools, editor: editor, sx: {+ flexShrink: 0,+ pr: 2,+ mr: 2,+ borderRight: "1px solid var(--border)",+ ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },+ } }, tools.join("")));+ }) })), _jsx(EditorFloatingMenus, { editor: editor })] })) })) })));+}diff --git a/packages/editor/dist/es/toolbar/tooldefinitions.d.ts b/packages/editor/dist/es/toolbar/tooldefinitions.d.tsnew file mode 100644index 000000000..88e97b56c--- /dev/null+++ b/packages/editor/dist/es/toolbar/tooldefinitions.d.ts@@ -0,0 +1,5 @@+import { ToolbarDefinition, ToolDefinition } from "./types";+import { ToolId } from "./tools";+export declare function getToolDefinition(id: ToolId): ToolDefinition;+export declare function getAllTools(): Record<"fontSize" | "underline" | "bold" | "bulletList" | "code" | "italic" | "subscript" | "superscript" | "fontFamily" | "highlight" | "removeAttachment" | "downloadAttachment" | "deleteColumn" | "deleteRow" | "deleteTable" | "mergeCells" | "ltr" | "rtl" | "strikethrough" | "codeRemove" | "alignCenter" | "alignLeft" | "alignRight" | "alignJustify" | "numberedList" | "textColor" | "openLink" | "linkSettings" | "imageSettings" | "rowProperties" | "insertRowBelow" | "insertRowAbove" | "moveRowDown" | "moveRowUp" | "columnProperties" | "insertColumnRight" | "insertColumnLeft" | "moveColumnRight" | "moveColumnLeft" | "cellProperties" | "cellBorderColor" | "splitCells" | "attachmentSettings" | "embedSettings" | "tableSettings" | "math" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "insertBlock" | "headings" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "cellBackgroundColor" | "cellTextColor" | "cellBorderWidth", ToolDefinition>;+export declare const DEFAULT_TOOLS: ToolbarDefinition;diff --git a/packages/editor/dist/es/toolbar/tooldefinitions.js b/packages/editor/dist/es/toolbar/tooldefinitions.jsnew file mode 100644index 000000000..026120ef6--- /dev/null+++ b/packages/editor/dist/es/toolbar/tooldefinitions.js@@ -0,0 +1,331 @@+const tools = {+ bold: {+ icon: "bold",+ title: "Bold",+ },+ italic: {+ icon: "italic",+ title: "Italic",+ },+ underline: {+ icon: "underline",+ title: "Underline",+ },+ strikethrough: {+ icon: "strikethrough",+ title: "Strikethrough",+ },+ addLink: {+ icon: "link",+ title: "Link",+ },+ editLink: {+ icon: "linkEdit",+ title: "Edit link",+ conditional: true,+ },+ removeLink: {+ icon: "linkRemove",+ title: "Remove link",+ conditional: true,+ },+ openLink: {+ icon: "openLink",+ title: "Open link",+ conditional: true,+ },+ linkSettings: {+ icon: "linkSettings",+ title: "Link settings",+ conditional: true,+ },+ code: {+ icon: "code",+ title: "Code",+ },+ codeRemove: {+ icon: "codeRemove",+ title: "Code",+ conditional: true,+ },+ clearformatting: {+ icon: "formatClear",+ title: "Clear all formatting",+ },+ subscript: {+ icon: "subscript",+ title: "Subscript",+ },+ superscript: {+ icon: "superscript",+ title: "Superscript",+ },+ insertBlock: {+ icon: "plus",+ title: "Insert",+ conditional: true,+ },+ bulletList: {+ icon: "bulletList",+ title: "Bullet list",+ },+ numberedList: {+ icon: "numberedList",+ title: "Numbered list",+ },+ fontFamily: {+ icon: "fontFamily",+ title: "Font family",+ },+ fontSize: {+ icon: "fontSize",+ title: "Font size",+ },+ headings: {+ icon: "heading",+ title: "Headings",+ },+ alignCenter: {+ icon: "alignCenter",+ title: "Align center",+ },+ alignLeft: {+ icon: "alignLeft",+ title: "Align left",+ },+ alignRight: {+ icon: "alignRight",+ title: "Align right",+ },+ alignJustify: {+ icon: "alignJustify",+ title: "Justify",+ },+ ltr: {+ icon: "ltr",+ title: "Left to right",+ },+ rtl: {+ icon: "rtl",+ title: "Right to left",+ },+ highlight: {+ icon: "highlight",+ title: "Highlight",+ },+ textColor: {+ icon: "textColor",+ title: "Text color",+ },+ math: {+ icon: "math",+ title: "Math (inline)",+ },+ tableSettings: {+ icon: "tableSettings",+ title: "Table settings",+ conditional: true,+ },+ columnProperties: {+ icon: "columnProperties",+ title: "Column properties",+ conditional: true,+ },+ rowProperties: {+ icon: "rowProperties",+ title: "Row properties",+ conditional: true,+ },+ cellProperties: {+ icon: "cellProperties",+ title: "Cell properties",+ conditional: true,+ },+ insertColumnLeft: {+ icon: "insertColumnLeft",+ title: "Insert column left",+ conditional: true,+ },+ insertColumnRight: {+ icon: "insertColumnRight",+ title: "Insert column right",+ conditional: true,+ },+ moveColumnLeft: {+ icon: "moveColumnLeft",+ title: "Move column left",+ conditional: true,+ },+ moveColumnRight: {+ icon: "moveColumnRight",+ title: "Move column right",+ conditional: true,+ },+ deleteColumn: {+ icon: "deleteColumn",+ title: "Delete column",+ conditional: true,+ },+ splitCells: {+ icon: "splitCells",+ title: "Split cells",+ conditional: true,+ },+ mergeCells: {+ icon: "mergeCells",+ title: "Merge cells",+ conditional: true,+ },+ insertRowAbove: {+ icon: "insertRowAbove",+ title: "Insert row above",+ conditional: true,+ },+ insertRowBelow: {+ icon: "insertRowBelow",+ title: "Insert row below",+ conditional: true,+ },+ moveRowUp: {+ icon: "moveRowUp",+ title: "Move row up",+ conditional: true,+ },+ moveRowDown: {+ icon: "moveRowDown",+ title: "Move row down",+ conditional: true,+ },+ deleteRow: {+ icon: "deleteRow",+ title: "Delete row",+ conditional: true,+ },+ deleteTable: {+ icon: "deleteTable",+ title: "Delete table",+ conditional: true,+ },+ cellBackgroundColor: {+ icon: "backgroundColor",+ title: "Cell background color",+ conditional: true,+ },+ cellBorderColor: {+ icon: "cellBorderColor",+ title: "Cell border color",+ conditional: true,+ },+ cellTextColor: {+ icon: "textColor",+ title: "Cell text color",+ conditional: true,+ },+ cellBorderWidth: {+ icon: "none",+ title: "Cell border width",+ conditional: true,+ },+ imageSettings: {+ icon: "imageSettings",+ title: "Image settings",+ conditional: true,+ },+ imageAlignCenter: {+ icon: "alignCenter",+ title: "Align center",+ conditional: true,+ },+ imageAlignLeft: {+ icon: "alignLeft",+ title: "Align left",+ conditional: true,+ },+ imageAlignRight: {+ icon: "alignRight",+ title: "Align right",+ conditional: true,+ },+ imageProperties: {+ icon: "more",+ title: "Image properties",+ conditional: true,+ },+ attachmentSettings: {+ icon: "attachmentSettings",+ title: "Attachment settings",+ conditional: true,+ },+ downloadAttachment: {+ icon: "download",+ title: "Download attachment",+ conditional: true,+ },+ removeAttachment: {+ icon: "delete",+ title: "Remove attachment",+ conditional: true,+ },+ embedSettings: {+ icon: "embedSettings",+ title: "Embed settings",+ conditional: true,+ },+ embedAlignCenter: {+ icon: "alignCenter",+ title: "Align center",+ conditional: true,+ },+ embedAlignLeft: {+ icon: "alignLeft",+ title: "Align left",+ conditional: true,+ },+ embedAlignRight: {+ icon: "alignRight",+ title: "Align right",+ conditional: true,+ },+ embedProperties: {+ icon: "more",+ title: "Embed properties",+ conditional: true,+ },+};+export function getToolDefinition(id) {+ return tools[id];+}+export function getAllTools() {+ return tools;+}+export const DEFAULT_TOOLS = [+ [+ "insertBlock",+ "tableSettings",+ "imageSettings",+ "embedSettings",+ "attachmentSettings",+ "linkSettings",+ "codeRemove",+ ],+ [+ "bold",+ "italic",+ "underline",+ [+ "strikethrough",+ "code",+ "subscript",+ "superscript",+ "highlight",+ "textColor",+ "math",+ ],+ ],+ ["fontSize"],+ ["headings", "fontFamily"],+ ["numberedList", "bulletList"],+ ["addLink"],+ ["alignCenter", ["alignLeft", "alignRight", "alignJustify", "ltr", "rtl"]],+ ["clearformatting"],+];diff --git a/packages/editor/dist/es/toolbar/tools/alignment.d.ts b/packages/editor/dist/es/toolbar/tools/alignment.d.tsnew file mode 100644index 000000000..6e121e63e--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/alignment.d.ts@@ -0,0 +1,6 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function AlignCenter(props: ToolProps): JSX.Element;+export declare function AlignLeft(props: ToolProps): JSX.Element;+export declare function AlignRight(props: ToolProps): JSX.Element;+export declare function AlignJustify(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/alignment.js b/packages/editor/dist/es/toolbar/tools/alignment.jsnew file mode 100644index 000000000..459a89cf8--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/alignment.js@@ -0,0 +1,29 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+function AlignmentTool(props) {+ const { editor, alignment } = props, toolProps = __rest(props, ["editor", "alignment"]);+ return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignment).run(); }, toggled: editor.isActive({ textAlign: alignment }) })));+}+export function AlignCenter(props) {+ return _jsx(AlignmentTool, Object.assign({ alignment: "center" }, props));+}+export function AlignLeft(props) {+ return _jsx(AlignmentTool, Object.assign({ alignment: "left" }, props));+}+export function AlignRight(props) {+ return _jsx(AlignmentTool, Object.assign({ alignment: "right" }, props));+}+export function AlignJustify(props) {+ return _jsx(AlignmentTool, Object.assign({ alignment: "justify" }, props));+}diff --git a/packages/editor/dist/es/toolbar/tools/attachment.d.ts b/packages/editor/dist/es/toolbar/tools/attachment.d.tsnew file mode 100644index 000000000..6fb9c8012--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/attachment.d.ts@@ -0,0 +1,5 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function AttachmentSettings(props: ToolProps): JSX.Element | null;+export declare function DownloadAttachment(props: ToolProps): JSX.Element;+export declare function RemoveAttachment(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/attachment.js b/packages/editor/dist/es/toolbar/tools/attachment.jsnew file mode 100644index 000000000..18fc7a2c7--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/attachment.js@@ -0,0 +1,25 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+import { MoreTools } from "../components/more-tools";+import { useToolbarLocation } from "../stores/toolbar-store";+import { findSelectedNode } from "../utils/prosemirror";+export function AttachmentSettings(props) {+ const { editor } = props;+ const isBottom = useToolbarLocation() === "bottom";+ if (!editor.isActive("attachment") || !isBottom)+ return null;+ return (_jsx(MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "attachmentSettings", tools: [] })));+}+export function DownloadAttachment(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ const attachmentNode = findSelectedNode(editor, "attachment");+ const attachment = ((attachmentNode === null || attachmentNode === void 0 ? void 0 : attachmentNode.attrs) || {});+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().downloadAttachment(attachment).run();+ } })));+}+export function RemoveAttachment(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().removeAttachment().run(); } })));+}diff --git a/packages/editor/dist/es/toolbar/tools/block.d.ts b/packages/editor/dist/es/toolbar/tools/block.d.tsnew file mode 100644index 000000000..9ab2e4d50--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/block.d.ts@@ -0,0 +1,3 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function InsertBlock(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/block.js b/packages/editor/dist/es/toolbar/tools/block.jsnew file mode 100644index 000000000..fbc44a451--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/block.js@@ -0,0 +1,239 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { Icons } from "../icons";+import { useMemo, useRef, useState } from "react";+import { Icon } from "../components/icon";+import { EmbedPopup } from "../popups/embed-popup";+import { TablePopup } from "../popups/table-popup";+import { useIsMobile, useToolbarLocation } from "../stores/toolbar-store";+import { ResponsivePresenter } from "../../components/responsive";+import { showPopup } from "../../components/popup-presenter";+import { ImageUploadPopup } from "../popups/image-upload";+import { Button } from "../../components/button";+export function InsertBlock(props) {+ const { editor } = props;+ const buttonRef = useRef(null);+ const [isOpen, setIsOpen] = useState(false);+ const toolbarLocation = useToolbarLocation();+ const isMobile = useIsMobile();+ const menuItems = useMemo(() => {+ return [+ tasklist(editor),+ outlinelist(editor),+ horizontalRule(editor),+ codeblock(editor),+ mathblock(editor),+ blockquote(editor),+ image(editor, isMobile),+ attachment(editor),+ isMobile ? embedMobile(editor) : embedDesktop(editor),+ table(editor),+ ];+ }, [isMobile]);+ return (_jsxs(_Fragment, { children: [_jsx(Button, Object.assign({ ref: buttonRef, sx: {+ p: 1,+ m: 0,+ bg: isOpen ? "hover" : "transparent",+ mr: 1,+ display: "flex",+ alignItems: "center",+ ":hover": { bg: "hover" },+ ":last-of-type": {+ mr: 0,+ },+ }, onMouseDown: (e) => e.preventDefault(), onClick: () => setIsOpen((s) => !s) }, { children: _jsx(Icon, { path: Icons.plus, size: 18, color: "primary" }) })), _jsx(ResponsivePresenter, { desktop: "menu", mobile: "sheet", title: "Choose a block to insert", isOpen: isOpen, items: menuItems, onClose: () => setIsOpen(false), position: {+ target: buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: toolbarLocation === "bottom" ? "top" : "below",+ yOffset: 5,+ } })] }));+}+const horizontalRule = (editor) => ({+ key: "hr",+ type: "button",+ title: "Horizontal rule",+ icon: "horizontalRule",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("horizontalRule"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setHorizontalRule().run(); },+});+const codeblock = (editor) => ({+ key: "codeblock",+ type: "button",+ title: "Code block",+ icon: "codeblock",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleCodeBlock().run(); },+});+const blockquote = (editor) => ({+ key: "blockquote",+ type: "button",+ title: "Quote",+ icon: "blockquote",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("blockQuote"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBlockquote().run(); },+});+const mathblock = (editor) => ({+ key: "math",+ type: "button",+ title: "Math & formulas",+ icon: "mathBlock",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("mathBlock"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathBlock().run(); },+});+const image = (editor, isMobile) => ({+ key: "image",+ type: "button",+ title: "Image",+ icon: "image",+ menu: {+ title: "Insert an image",+ items: [+ {+ key: "upload-from-disk",+ type: "button",+ title: "Upload from disk",+ icon: "upload",+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("image").run(); },+ },+ {+ key: "camera",+ type: "button",+ title: "Take a photo using camera",+ icon: "camera",+ isHidden: !isMobile,+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("camera").run(); },+ },+ isMobile ? uploadImageFromURLMobile(editor) : uploadImageFromURL(editor),+ ],+ },+});+const table = (editor) => ({+ key: "table",+ type: "button",+ title: "Table",+ icon: "table",+ menu: {+ title: "Insert a table",+ items: [+ {+ key: "table-size-selector",+ type: "popup",+ component: (props) => (_jsx(TablePopup, { onInsertTable: (size) => {+ var _a, _b;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertTable({+ rows: size.rows,+ cols: size.columns,+ }).run();+ (_b = props.onClick) === null || _b === void 0 ? void 0 : _b.call(props);+ } })),+ },+ ],+ },+});+const embedMobile = (editor) => ({+ key: "embed",+ type: "button",+ title: "Embed",+ icon: "embed",+ menu: {+ title: "Insert an embed",+ items: [+ {+ key: "embed-popup",+ type: "popup",+ component: function ({ onClick }) {+ return (_jsx(EmbedPopup, { title: "Insert embed", onClose: (embed) => {+ var _a;+ if (!embed)+ return onClick === null || onClick === void 0 ? void 0 : onClick();+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().insertEmbed(embed).run();+ onClick === null || onClick === void 0 ? void 0 : onClick();+ } }));+ },+ },+ ],+ },+});+const embedDesktop = (editor) => ({+ key: "embed",+ type: "button",+ title: "Embed",+ icon: "embed",+ onClick: () => {+ if (!editor)+ return;+ showPopup({+ theme: editor.storage.theme,+ popup: (hide) => (_jsx(EmbedPopup, { title: "Insert embed", onClose: (embed) => {+ var _a;+ if (!embed)+ return hide();+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().insertEmbed(embed).run();+ hide();+ } })),+ });+ },+});+const attachment = (editor) => ({+ key: "attachment",+ type: "button",+ title: "Attachment",+ icon: "attachment",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("attachment"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("file").run(); },+});+const tasklist = (editor) => ({+ key: "tasklist",+ type: "button",+ title: "Task list",+ icon: "checkbox",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("taskList"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleTaskList().run(); },+});+const outlinelist = (editor) => ({+ key: "outlinelist",+ type: "button",+ title: "Outline list",+ icon: "outlineList",+ isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("outlineList"),+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOutlineList().run(); },+});+const uploadImageFromURLMobile = (editor) => ({+ key: "upload-from-url",+ type: "button",+ title: "Attach from URL",+ icon: "link",+ menu: {+ title: "Attach image from URL",+ items: [+ {+ key: "attach-image",+ type: "popup",+ component: ({ onClick }) => (_jsx(ImageUploadPopup, { onInsert: (image) => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertImage(image).run();+ onClick === null || onClick === void 0 ? void 0 : onClick();+ }, onClose: () => {+ onClick === null || onClick === void 0 ? void 0 : onClick();+ } })),+ },+ ],+ },+});+const uploadImageFromURL = (editor) => ({+ key: "upload-from-url",+ type: "button",+ title: "Attach from URL",+ icon: "link",+ onClick: () => {+ if (!editor)+ return;+ showPopup({+ theme: editor.storage.theme,+ popup: (hide) => (_jsx(ImageUploadPopup, { onInsert: (image) => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertImage(image).run();+ hide();+ }, onClose: hide })),+ });+ },+});diff --git a/packages/editor/dist/es/toolbar/tools/colors.d.ts b/packages/editor/dist/es/toolbar/tools/colors.d.tsnew file mode 100644index 000000000..e29d3e326--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/colors.d.ts@@ -0,0 +1,13 @@+import React from "react";+import { ToolProps } from "../types";+declare type ColorToolProps = ToolProps & {+ onColorChange: (color?: string) => void;+ getActiveColor: () => string;+ title: string;+ cacheKey: string;+};+declare function _ColorTool(props: ColorToolProps): JSX.Element;+export declare const ColorTool: React.MemoExoticComponent<typeof _ColorTool>;+export declare function Highlight(props: ToolProps): JSX.Element;+export declare function TextColor(props: ToolProps): JSX.Element;+export {};diff --git a/packages/editor/dist/es/toolbar/tools/colors.js b/packages/editor/dist/es/toolbar/tools/colors.jsnew file mode 100644index 000000000..ece0b98b8--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/colors.js@@ -0,0 +1,66 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import React, { useState } from "react";+import tinycolor from "tinycolor2";+import { PopupWrapper } from "../../components/popup-presenter";+import { config } from "../../utils/config";+import { SplitButton } from "../components/split-button";+import { ColorPicker } from "../popups/color-picker";+import { useToolbarLocation } from "../stores/toolbar-store";+import { getToolbarElement } from "../utils/dom";+// TODO test rerendering+function _ColorTool(props) {+ const { editor, onColorChange, getActiveColor, title, cacheKey } = props, toolProps = __rest(props, ["editor", "onColorChange", "getActiveColor", "title", "cacheKey"]);+ const activeColor = getActiveColor() || config.get(cacheKey);+ const tColor = tinycolor(activeColor);+ const isBottom = useToolbarLocation() === "bottom";+ const [isOpen, setIsOpen] = useState(false);+ return (_jsx(SplitButton, Object.assign({}, toolProps, { iconColor: activeColor && tColor.isDark() ? "static" : "icon", sx: {+ mr: 0,+ bg: activeColor || "transparent",+ ":hover": {+ bg: activeColor ? tColor.darken(5).toRgbString() : "transparent",+ },+ }, onOpen: () => setIsOpen((s) => !s), toggled: isOpen, onClick: () => onColorChange(activeColor) }, { children: _jsx(PopupWrapper, { isOpen: isOpen, id: props.icon, group: "color", position: {+ isTargetAbsolute: true,+ target: getToolbarElement(),+ align: isBottom ? "center" : "end",+ location: isBottom ? "top" : "below",+ yOffset: 10,+ }, focusOnRender: false, blocking: false, renderPopup: (close) => (_jsx(ColorPicker, { color: activeColor, onClear: () => {+ onColorChange();+ config.set(cacheKey, null);+ }, onChange: (color) => {+ onColorChange(color);+ config.set(cacheKey, color);+ }, onClose: close, title: title })) }) })));+}+export const ColorTool = React.memo(_ColorTool, () => true);+export function Highlight(props) {+ const { editor } = props;+ return (_jsx(ColorTool, Object.assign({}, props, { cacheKey: "highlight", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("highlight").color; }, title: "Background color", onColorChange: (color) => {+ var _a, _b;+ return color+ ? (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleHighlight({ color }).run()+ : (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetHighlight().run();+ } })));+}+export function TextColor(props) {+ const { editor } = props;+ return (_jsx(ColorTool, Object.assign({}, props, { cacheKey: "textColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("textStyle").color; }, title: "Text color", onColorChange: (color) => {+ var _a, _b;+ return color+ ? (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setColor(color).run()+ : (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetColor().run();+ } })));+}diff --git a/packages/editor/dist/es/toolbar/tools/embed.d.ts b/packages/editor/dist/es/toolbar/tools/embed.d.tsnew file mode 100644index 000000000..3c143f3c1--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/embed.d.ts@@ -0,0 +1,7 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function EmbedSettings(props: ToolProps): JSX.Element | null;+export declare function EmbedAlignLeft(props: ToolProps): JSX.Element;+export declare function EmbedAlignRight(props: ToolProps): JSX.Element;+export declare function EmbedAlignCenter(props: ToolProps): JSX.Element;+export declare function EmbedProperties(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/embed.js b/packages/editor/dist/es/toolbar/tools/embed.jsnew file mode 100644index 000000000..e3683b822--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/embed.js@@ -0,0 +1,52 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+import { useMemo, useRef, useState } from "react";+import { ResponsivePresenter } from "../../components/responsive";+import { MoreTools } from "../components/more-tools";+import { useToolbarLocation } from "../stores/toolbar-store";+import { findSelectedNode } from "../utils/prosemirror";+import { EmbedPopup } from "../popups/embed-popup";+export function EmbedSettings(props) {+ const { editor } = props;+ const isBottom = useToolbarLocation() === "bottom";+ if (!editor.isActive("embed") || !isBottom)+ return null;+ return (_jsx(MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "embedSettings", tools: [] })));+}+export function EmbedAlignLeft(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "left" }).run();+ } })));+}+export function EmbedAlignRight(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "right" }).run();+ } })));+}+export function EmbedAlignCenter(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "center" }).run();+ } })));+}+// TODO: stop re-rendering+export function EmbedProperties(props) {+ const { editor } = props;+ const [isOpen, setIsOpen] = useState(false);+ const buttonRef = useRef();+ // TODO: improve perf by deferring this until user opens the popup+ const embedNode = useMemo(() => findSelectedNode(editor, "embed"), []);+ const embed = ((embedNode === null || embedNode === void 0 ? void 0 : embedNode.attrs) || {});+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({ buttonRef: buttonRef, toggled: isOpen }, props, { onClick: () => setIsOpen((s) => !s) })), _jsx(ResponsivePresenter, Object.assign({ isOpen: isOpen, desktop: "menu", mobile: "sheet", onClose: () => setIsOpen(false), blocking: true, focusOnRender: false, position: {+ target: buttonRef.current || "mouse",+ align: "start",+ location: "below",+ yOffset: 10,+ isTargetAbsolute: true,+ } }, { children: _jsx(EmbedPopup, { title: "Embed properties", onClose: () => setIsOpen(false), embed: embed, onSourceChanged: (src) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSource(src); }, onSizeChanged: (size) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSize(size); } }) }))] }));+}diff --git a/packages/editor/dist/es/toolbar/tools/font.d.ts b/packages/editor/dist/es/toolbar/tools/font.d.tsnew file mode 100644index 000000000..e7818addd--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/font.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function FontSize(props: ToolProps): JSX.Element;+export declare function FontFamily(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/font.js b/packages/editor/dist/es/toolbar/tools/font.jsnew file mode 100644index 000000000..68a0b96ab--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/font.js@@ -0,0 +1,51 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { Dropdown } from "../components/dropdown";+import { useCallback, useMemo } from "react";+import { Counter } from "../components/counter";+import { useRefValue } from "../../hooks/use-ref-value";+export function FontSize(props) {+ const { editor } = props;+ const { fontSize: _fontSize } = editor.getAttributes("textStyle");+ const fontSize = _fontSize || "16px";+ const fontSizeAsNumber = useRefValue(parseInt(fontSize.replace("px", "")));+ const decreaseFontSize = useCallback(() => {+ return Math.max(8, fontSizeAsNumber.current - 1);+ }, []);+ const increaseFontSize = useCallback(() => {+ return Math.min(120, fontSizeAsNumber.current + 1);+ }, []);+ return (_jsx(Counter, { title: "font size", onDecrease: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize(`${decreaseFontSize()}px`).run();+ }, onIncrease: () => {+ var _a;+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize(`${increaseFontSize()}px`).run();+ }, onReset: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize(`16px`).run(); }, value: fontSize }));+}+const fontFamilies = {+ System: "Open Sans",+ Serif: "serif",+ Monospace: "monospace",+};+export function FontFamily(props) {+ var _a, _b;+ const { editor } = props;+ const currentFontFamily = ((_b = (_a = Object.entries(fontFamilies)+ .find(([key, value]) => editor.isActive("textStyle", { fontFamily: value }))) === null || _a === void 0 ? void 0 : _a.map((a) => a)) === null || _b === void 0 ? void 0 : _b.at(0)) || "System";+ const items = useMemo(() => toMenuItems(editor, currentFontFamily), [currentFontFamily]);+ return (_jsx(Dropdown, { selectedItem: currentFontFamily, items: items, menuWidth: 130 }));+}+function toMenuItems(editor, currentFontFamily) {+ const menuItems = [];+ for (const key in fontFamilies) {+ const value = fontFamilies[key];+ menuItems.push({+ key,+ type: "button",+ title: key,+ isChecked: key === currentFontFamily,+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontFamily(value).run(); },+ });+ }+ return menuItems;+}diff --git a/packages/editor/dist/es/toolbar/tools/headings.d.ts b/packages/editor/dist/es/toolbar/tools/headings.d.tsnew file mode 100644index 000000000..e237b7e5f--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/headings.d.ts@@ -0,0 +1,3 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function Headings(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/headings.js b/packages/editor/dist/es/toolbar/tools/headings.jsnew file mode 100644index 000000000..4fcde7e4b--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/headings.js@@ -0,0 +1,32 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { Dropdown } from "../components/dropdown";+import { useToolbarLocation } from "../stores/toolbar-store";+import { useMemo } from "react";+const defaultLevels = [1, 2, 3, 4, 5, 6];+export function Headings(props) {+ const { editor } = props;+ const toolbarLocation = useToolbarLocation();+ const currentHeadingLevel = defaultLevels.find((level) => editor.isActive("heading", { level }));+ const items = useMemo(() => toMenuItems(editor, toolbarLocation, currentHeadingLevel), [currentHeadingLevel]);+ return (_jsx(Dropdown, { selectedItem: currentHeadingLevel ? `Heading ${currentHeadingLevel}` : "Paragraph", items: items, menuWidth: 130 }));+}+function toMenuItems(editor, toolbarLocation, currentHeadingLevel) {+ const menuItems = defaultLevels.map((level) => ({+ type: "button",+ key: `heading-${level}`,+ title: toolbarLocation === "bottom" ? `H${level}` : `Heading ${level}`,+ isChecked: level === currentHeadingLevel,+ onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().updateAttributes("textStyle", { fontSize: null, fontStyle: null }).setHeading({ level: level }).run();+ },+ }));+ const paragraph = {+ key: "paragraph",+ type: "button",+ title: "Paragraph",+ isChecked: !currentHeadingLevel,+ onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setParagraph().run(); },+ };+ return [paragraph, ...menuItems];+}diff --git a/packages/editor/dist/es/toolbar/tools/image.d.ts b/packages/editor/dist/es/toolbar/tools/image.d.tsnew file mode 100644index 000000000..d192850d6--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/image.d.ts@@ -0,0 +1,7 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function ImageSettings(props: ToolProps): JSX.Element | null;+export declare function ImageAlignLeft(props: ToolProps): JSX.Element;+export declare function ImageAlignRight(props: ToolProps): JSX.Element;+export declare function ImageAlignCenter(props: ToolProps): JSX.Element;+export declare function ImageProperties(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/image.js b/packages/editor/dist/es/toolbar/tools/image.jsnew file mode 100644index 000000000..d12812d01--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/image.js@@ -0,0 +1,60 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+import { useMemo, useRef, useState } from "react";+import { ResponsivePresenter } from "../../components/responsive";+import { MoreTools } from "../components/more-tools";+import { useToolbarLocation } from "../stores/toolbar-store";+import { ImageProperties as ImagePropertiesPopup } from "../popups/image-properties";+import { findSelectedNode } from "../utils/prosemirror";+export function ImageSettings(props) {+ var _a, _b;+ const { editor } = props;+ const isBottom = useToolbarLocation() === "bottom";+ if (!editor.isActive("image") || !isBottom)+ return null;+ return (_jsx(MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "imageSettings", tools: ((_b = (_a = findSelectedNode(editor, "image")) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.float)+ ? ["imageAlignLeft", "imageAlignRight", "imageProperties"]+ : [+ "imageAlignLeft",+ "imageAlignCenter",+ "imageAlignRight",+ "imageProperties",+ ] })));+}+export function ImageAlignLeft(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "left" }).run();+ } })));+}+export function ImageAlignRight(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "right" }).run();+ } })));+}+export function ImageAlignCenter(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "center" }).run();+ } })));+}+export function ImageProperties(props) {+ const { editor } = props;+ const [isOpen, setIsOpen] = useState(false);+ const buttonRef = useRef();+ // TODO: defer until user opens the popup+ const image = useMemo(() => findSelectedNode(editor, "image"), []);+ const { float, align, width, height } = ((image === null || image === void 0 ? void 0 : image.attrs) ||+ {});+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({ buttonRef: buttonRef, toggled: isOpen }, props, { onClick: () => setIsOpen((s) => !s) })), _jsx(ResponsivePresenter, Object.assign({ isOpen: isOpen, desktop: "menu", mobile: "sheet", onClose: () => setIsOpen(false), blocking: true, focusOnRender: false, position: {+ target: buttonRef.current || "mouse",+ align: "start",+ location: "below",+ yOffset: 10,+ isTargetAbsolute: true,+ } }, { children: _jsx(ImagePropertiesPopup, { editor: editor, height: height, width: width, align: align, float: float, onClose: () => setIsOpen(false) }) }))] }));+}diff --git a/packages/editor/dist/es/toolbar/tools/index.d.ts b/packages/editor/dist/es/toolbar/tools/index.d.tsnew file mode 100644index 000000000..df50761f4--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/index.d.ts@@ -0,0 +1,83 @@+import React from "react";+import { ToolProps } from "../types";+import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math } from "./inline";+import { InsertBlock } from "./block";+import { FontSize, FontFamily } from "./font";+import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Headings } from "./headings";+import { NumberedList, BulletList } from "./lists";+import { LeftToRight, RightToLeft } from "./text-direction";+import { Highlight, TextColor } from "./colors";+import { TableSettings, ColumnProperties, RowProperties, CellProperties, CellBackgroundColor, CellBorderColor, CellTextColor, CellBorderWidth } from "./table";+import { ImageSettings, ImageAlignCenter, ImageAlignLeft, ImageAlignRight, ImageProperties } from "./image";+import { AttachmentSettings, DownloadAttachment, RemoveAttachment } from "./attachment";+import { EmbedAlignCenter, EmbedAlignLeft, EmbedAlignRight, EmbedProperties, EmbedSettings } from "./embed";+import { AddLink, EditLink, RemoveLink, LinkSettings, OpenLink } from "./link";+export declare type ToolId = keyof typeof tools;+declare const tools: {+ bold: typeof Bold;+ italic: typeof Italic;+ underline: typeof Underline;+ strikethrough: typeof Strikethrough;+ code: typeof Code;+ codeRemove: typeof CodeRemove;+ subscript: typeof Subscript;+ superscript: typeof Superscript;+ clearformatting: typeof ClearFormatting;+ addLink: typeof AddLink;+ editLink: typeof EditLink;+ removeLink: typeof RemoveLink;+ linkSettings: typeof LinkSettings;+ openLink: typeof OpenLink;+ insertBlock: typeof InsertBlock;+ numberedList: typeof NumberedList;+ bulletList: typeof BulletList;+ fontSize: typeof FontSize;+ fontFamily: typeof FontFamily;+ headings: typeof Headings;+ alignCenter: typeof AlignCenter;+ alignRight: typeof AlignRight;+ alignLeft: typeof AlignLeft;+ alignJustify: typeof AlignJustify;+ ltr: typeof LeftToRight;+ rtl: typeof RightToLeft;+ textColor: typeof TextColor;+ highlight: typeof Highlight;+ math: typeof Math;+ imageSettings: typeof ImageSettings;+ imageAlignCenter: typeof ImageAlignCenter;+ imageAlignLeft: typeof ImageAlignLeft;+ imageAlignRight: typeof ImageAlignRight;+ imageProperties: typeof ImageProperties;+ embedAlignCenter: typeof EmbedAlignCenter;+ embedAlignLeft: typeof EmbedAlignLeft;+ embedAlignRight: typeof EmbedAlignRight;+ embedProperties: typeof EmbedProperties;+ embedSettings: typeof EmbedSettings;+ attachmentSettings: typeof AttachmentSettings;+ downloadAttachment: typeof DownloadAttachment;+ removeAttachment: typeof RemoveAttachment;+ tableSettings: typeof TableSettings;+ columnProperties: typeof ColumnProperties;+ rowProperties: typeof RowProperties;+ cellProperties: typeof CellProperties;+ insertColumnLeft: (props: ToolProps) => JSX.Element;+ insertColumnRight: (props: ToolProps) => JSX.Element;+ moveColumnLeft: (props: ToolProps) => JSX.Element;+ moveColumnRight: (props: ToolProps) => JSX.Element;+ deleteColumn: (props: ToolProps) => JSX.Element;+ splitCells: (props: ToolProps) => JSX.Element;+ mergeCells: (props: ToolProps) => JSX.Element;+ cellBackgroundColor: typeof CellBackgroundColor;+ cellBorderColor: typeof CellBorderColor;+ cellTextColor: typeof CellTextColor;+ cellBorderWidth: typeof CellBorderWidth;+ insertRowAbove: (props: ToolProps) => JSX.Element;+ insertRowBelow: (props: ToolProps) => JSX.Element;+ moveRowUp: (props: ToolProps) => JSX.Element;+ moveRowDown: (props: ToolProps) => JSX.Element;+ deleteRow: (props: ToolProps) => JSX.Element;+ deleteTable: (props: ToolProps) => JSX.Element;+};+export declare function findTool(id: ToolId): React.FunctionComponent<ToolProps>;+export {};diff --git a/packages/editor/dist/es/toolbar/tools/index.js b/packages/editor/dist/es/toolbar/tools/index.jsnew file mode 100644index 000000000..761442bdf--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/index.js@@ -0,0 +1,81 @@+import { Bold, Italic, Underline, Strikethrough, Code, Subscript, Superscript, ClearFormatting, CodeRemove, Math, } from "./inline";+import { InsertBlock } from "./block";+import { FontSize, FontFamily } from "./font";+import { AlignCenter, AlignLeft, AlignRight, AlignJustify } from "./alignment";+import { Headings } from "./headings";+import { NumberedList, BulletList } from "./lists";+import { LeftToRight, RightToLeft } from "./text-direction";+import { Highlight, TextColor } from "./colors";+import { TableSettings, ColumnProperties, RowProperties, CellProperties, InsertColumnLeft, InsertColumnRight, MoveColumnLeft, MoveColumnRight, DeleteColumn, SplitCells, MergeCells, InsertRowAbove, InsertRowBelow, MoveRowUp, MoveRowDown, DeleteRow, DeleteTable, CellBackgroundColor, CellBorderColor, CellTextColor, CellBorderWidth, } from "./table";+import { ImageSettings, ImageAlignCenter, ImageAlignLeft, ImageAlignRight, ImageProperties, } from "./image";+import { AttachmentSettings, DownloadAttachment, RemoveAttachment, } from "./attachment";+import { EmbedAlignCenter, EmbedAlignLeft, EmbedAlignRight, EmbedProperties, EmbedSettings, } from "./embed";+import { AddLink, EditLink, RemoveLink, LinkSettings, OpenLink } from "./link";+const tools = {+ bold: Bold,+ italic: Italic,+ underline: Underline,+ strikethrough: Strikethrough,+ code: Code,+ codeRemove: CodeRemove,+ subscript: Subscript,+ superscript: Superscript,+ clearformatting: ClearFormatting,+ addLink: AddLink,+ editLink: EditLink,+ removeLink: RemoveLink,+ linkSettings: LinkSettings,+ openLink: OpenLink,+ insertBlock: InsertBlock,+ numberedList: NumberedList,+ bulletList: BulletList,+ fontSize: FontSize,+ fontFamily: FontFamily,+ headings: Headings,+ alignCenter: AlignCenter,+ alignRight: AlignRight,+ alignLeft: AlignLeft,+ alignJustify: AlignJustify,+ ltr: LeftToRight,+ rtl: RightToLeft,+ textColor: TextColor,+ highlight: Highlight,+ math: Math,+ imageSettings: ImageSettings,+ imageAlignCenter: ImageAlignCenter,+ imageAlignLeft: ImageAlignLeft,+ imageAlignRight: ImageAlignRight,+ imageProperties: ImageProperties,+ embedAlignCenter: EmbedAlignCenter,+ embedAlignLeft: EmbedAlignLeft,+ embedAlignRight: EmbedAlignRight,+ embedProperties: EmbedProperties,+ embedSettings: EmbedSettings,+ attachmentSettings: AttachmentSettings,+ downloadAttachment: DownloadAttachment,+ removeAttachment: RemoveAttachment,+ tableSettings: TableSettings,+ columnProperties: ColumnProperties,+ rowProperties: RowProperties,+ cellProperties: CellProperties,+ insertColumnLeft: InsertColumnLeft,+ insertColumnRight: InsertColumnRight,+ moveColumnLeft: MoveColumnLeft,+ moveColumnRight: MoveColumnRight,+ deleteColumn: DeleteColumn,+ splitCells: SplitCells,+ mergeCells: MergeCells,+ cellBackgroundColor: CellBackgroundColor,+ cellBorderColor: CellBorderColor,+ cellTextColor: CellTextColor,+ cellBorderWidth: CellBorderWidth,+ insertRowAbove: InsertRowAbove,+ insertRowBelow: InsertRowBelow,+ moveRowUp: MoveRowUp,+ moveRowDown: MoveRowDown,+ deleteRow: DeleteRow,+ deleteTable: DeleteTable,+};+export function findTool(id) {+ return tools[id];+}diff --git a/packages/editor/dist/es/toolbar/tools/inline.d.ts b/packages/editor/dist/es/toolbar/tools/inline.d.tsnew file mode 100644index 000000000..f8a5deb2c--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/inline.d.ts@@ -0,0 +1,12 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function Italic(props: ToolProps): JSX.Element;+export declare function Strikethrough(props: ToolProps): JSX.Element;+export declare function Underline(props: ToolProps): JSX.Element;+export declare function Code(props: ToolProps): JSX.Element;+export declare function Bold(props: ToolProps): JSX.Element;+export declare function Subscript(props: ToolProps): JSX.Element;+export declare function Superscript(props: ToolProps): JSX.Element;+export declare function ClearFormatting(props: ToolProps): JSX.Element;+export declare function CodeRemove(props: ToolProps): JSX.Element | null;+export declare function Math(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/inline.js b/packages/editor/dist/es/toolbar/tools/inline.jsnew file mode 100644index 000000000..e0c8958f5--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/inline.js@@ -0,0 +1,49 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+import { useToolbarLocation } from "../stores/toolbar-store";+export function Italic(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("italic"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleItalic().run(); } })));+}+export function Strikethrough(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("strike"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleStrike().run(); } })));+}+export function Underline(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("underline"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleUnderline().run(); } })));+}+export function Code(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("code"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleCode().run(); } })));+}+export function Bold(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("bold"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBold().run(); } })));+}+export function Subscript(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("subscript"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleSubscript().run(); } })));+}+export function Superscript(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: editor.isActive("superscript"), onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleSuperscript().run(); } })));+}+export function ClearFormatting(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().clearNodes().unsetAllMarks().unsetMark("link").run();+ } })));+}+export function CodeRemove(props) {+ const { editor } = props;+ const isBottom = useToolbarLocation() === "bottom";+ if (!editor.isActive("code") || !isBottom)+ return null;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().unsetMark("code").run(); } })));+}+export function Math(props) {+ const { editor } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathInline().run(); } })));+}diff --git a/packages/editor/dist/es/toolbar/tools/link.d.ts b/packages/editor/dist/es/toolbar/tools/link.d.tsnew file mode 100644index 000000000..58223feb4--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/link.d.ts@@ -0,0 +1,7 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function LinkSettings(props: ToolProps): JSX.Element | null;+export declare function AddLink(props: ToolProps): JSX.Element;+export declare function EditLink(props: ToolProps): JSX.Element;+export declare function RemoveLink(props: ToolProps): JSX.Element;+export declare function OpenLink(props: ToolProps): JSX.Element | null;diff --git a/packages/editor/dist/es/toolbar/tools/link.js b/packages/editor/dist/es/toolbar/tools/link.jsnew file mode 100644index 000000000..e949c33aa--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/link.js@@ -0,0 +1,119 @@+import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+import { useCallback, useRef, useState } from "react";+import { ResponsivePresenter } from "../../components/responsive";+import { LinkPopup } from "../popups/link-popup";+import { useToolbarLocation } from "../stores/toolbar-store";+import { MoreTools } from "../components/more-tools";+import { useRefValue } from "../../hooks/use-ref-value";+import { findMark, selectionToOffset } from "../utils/prosemirror";+import { setTextSelection } from "prosemirror-utils";+import { Flex, Text } from "rebass";+export function LinkSettings(props) {+ const { editor } = props;+ const isBottom = useToolbarLocation() === "bottom";+ if (!editor.isActive("link") || !isBottom)+ return null;+ return (_jsx(MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "linkSettings", tools: ["openLink", "editLink", "removeLink"] })));+}+export function AddLink(props) {+ const { editor } = props;+ const isActive = props.editor.isActive("link");+ const onDone = useCallback((href, text) => {+ var _a;+ if (!href)+ return;+ let commandChain = (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus();+ if (!commandChain)+ return;+ commandChain+ .extendMarkRange("link")+ .toggleLink({ href, target: "_blank" })+ .insertContent(text || href)+ .focus()+ .unsetMark("link")+ .insertContent(" ")+ .run();+ }, []);+ if (isActive)+ return _jsx(EditLink, Object.assign({}, props));+ return (_jsx(LinkTool, Object.assign({}, props, { onDone: onDone, onClick: () => {+ let { from, to } = editor.state.selection;+ const selectedText = editor.state.doc.textBetween(from, to);+ return { text: selectedText };+ } })));+}+export function EditLink(props) {+ const { editor, selectedNode: _selectedNode } = props;+ const selectedNode = useRefValue(_selectedNode || selectionToOffset(editor.state.selection));+ const onDone = useCallback((href, text) => {+ if (!href || !editor.current)+ return;+ const { from, node, to } = selectedNode.current;+ const mark = findMark(node, "link");+ if (!mark)+ return;+ editor.current+ .chain()+ .command(({ tr }) => {+ tr.removeMark(from, to, mark.type);+ tr.addMark(from, to, mark.type.create({ href }));+ tr.insertText(text || node.textContent, from, to);+ setTextSelection(tr.mapping.map(from))(tr);+ return true;+ })+ .focus(undefined, { scrollIntoView: true })+ .run();+ }, []);+ return (_jsx(LinkTool, Object.assign({}, props, { isEditing: true, onDone: onDone, onClick: () => {+ const { node } = selectedNode.current;+ const selectedText = node.textContent;+ const mark = findMark(node, "link");+ if (!mark)+ return;+ return { text: selectedText, href: mark.attrs.href };+ } })));+}+export function RemoveLink(props) {+ const { editor, selectedNode } = props;+ return (_jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => {+ var _a, _b;+ if (selectedNode)+ (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setTextSelection(selectedNode.from);+ (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetLink().run();+ } })));+}+export function OpenLink(props) {+ const { editor, selectedNode } = props;+ const node = (selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.node) || editor.state.selection.$anchor.node();+ const link = selectedNode ? findMark(node, "link") : null;+ if (!link)+ return null;+ const href = link === null || link === void 0 ? void 0 : link.attrs.href;+ return (_jsxs(Flex, Object.assign({ sx: { alignItems: "center" } }, { children: [_jsx(Text, Object.assign({ as: "a", href: href, target: "_blank", variant: "body", sx: { mr: 1 } }, { children: href })), _jsx(ToolButton, Object.assign({}, props, { toggled: false, onClick: () => window.open(href, "_blank") }))] })));+}+function LinkTool(props) {+ const { isEditing, onClick, onDone } = props;+ const buttonRef = useRef(null);+ const [isOpen, setIsOpen] = useState(false);+ const [href, setHref] = useState();+ const [text, setText] = useState();+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({}, props, { buttonRef: buttonRef, onClick: () => {+ const result = onClick();+ if (!result)+ return;+ const { text, href } = result;+ setHref(href);+ setText(text);+ setIsOpen(true);+ }, toggled: isOpen })), _jsx(ResponsivePresenter, Object.assign({ mobile: "sheet", desktop: "menu", position: {+ target: buttonRef.current || undefined,+ isTargetAbsolute: true,+ location: "below",+ align: "center",+ yOffset: 5,+ }, title: isEditing ? "Edit link" : "Insert link", isOpen: isOpen, items: [], onClose: () => setIsOpen(false), focusOnRender: false }, { children: _jsx(LinkPopup, { href: href, text: text, isEditing: isEditing, onClose: () => setIsOpen(false), onDone: ({ href, text }) => {+ onDone(href, text);+ setIsOpen(false);+ } }) }))] }));+}diff --git a/packages/editor/dist/es/toolbar/tools/lists.d.ts b/packages/editor/dist/es/toolbar/tools/lists.d.tsnew file mode 100644index 000000000..50718c842--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/lists.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function NumberedList(props: ToolProps): JSX.Element;+export declare function BulletList(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/lists.js b/packages/editor/dist/es/toolbar/tools/lists.jsnew file mode 100644index 000000000..312892468--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/lists.js@@ -0,0 +1,106 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import { Box, Button, Flex } from "rebass";+import { useCallback, useRef, useState } from "react";+import { SplitButton } from "../components/split-button";+import { useToolbarLocation } from "../stores/toolbar-store";+import { getToolbarElement } from "../utils/dom";+import { PopupWrapper } from "../../components/popup-presenter";+import React from "react";+function _ListTool(props) {+ const { editor, onClick, isActive, subTypes, type } = props, toolProps = __rest(props, ["editor", "onClick", "isActive", "subTypes", "type"]);+ const toolbarLocation = useToolbarLocation();+ const isBottom = toolbarLocation === "bottom";+ const [isOpen, setIsOpen] = useState(false);+ const buttonRef = useRef();+ return (_jsx(SplitButton, Object.assign({}, toolProps, { buttonRef: buttonRef, onClick: onClick, toggled: isActive || isOpen, sx: { mr: 0 }, onOpen: () => setIsOpen((s) => !s) }, { children: _jsx(PopupWrapper, { isOpen: isOpen, group: "lists", id: toolProps.title, blocking: false, focusOnRender: false, position: {+ isTargetAbsolute: true,+ target: isBottom ? getToolbarElement() : buttonRef.current || "mouse",+ align: "center",+ location: isBottom ? "top" : "below",+ yOffset: isBottom ? 10 : 5,+ }, onClosed: () => setIsOpen(false), renderPopup: () => (_jsx(Box, Object.assign({ sx: {+ bg: "background",+ display: "grid",+ gridTemplateColumns: "1fr 1fr 1fr",+ p: 1,+ } }, { children: subTypes.map((item) => (_jsx(Button, Object.assign({ variant: "menuitem", sx: { width: 80 }, onClick: () => {+ var _a;+ let chain = (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus();+ if (!chain)+ return;+ if (!isActive) {+ if (type === "bulletList")+ chain = chain.toggleBulletList();+ else+ chain = chain.toggleOrderedList();+ }+ return chain+ .updateAttributes(type, { listType: item.type })+ .run();+ } }, { children: _jsx(ListThumbnail, { listStyleType: item.type }) }), item.title))) }))) }) })));+}+const ListTool = React.memo(_ListTool, (prev, next) => {+ return prev.isActive === next.isActive;+});+export function NumberedList(props) {+ const { editor } = props;+ const onClick = useCallback(() => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOrderedList().run(); }, []);+ return (_jsx(ListTool, Object.assign({}, props, { type: "orderedList", isActive: editor.isActive("orderedList"), onClick: onClick, subTypes: [+ { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },+ { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },+ {+ type: "upper-roman",+ title: "Upper Roman",+ items: ["I", "II", "III"],+ },+ {+ type: "lower-roman",+ title: "Lower Roman",+ items: ["i", "ii", "iii"],+ },+ { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },+ ] })));+}+export function BulletList(props) {+ const { editor } = props;+ const onClick = useCallback(() => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOrderedList().run(); }, []);+ return (_jsx(ListTool, Object.assign({}, props, { type: "bulletList", onClick: onClick, isActive: editor.isActive("bulletList"), subTypes: [+ { type: "disc", title: "Decimal", items: ["1", "2", "3"] },+ { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },+ { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },+ ] })));+}+function ListThumbnail(props) {+ const { listStyleType } = props;+ return (_jsx(Flex, Object.assign({ as: "ul", sx: {+ flexDirection: "column",+ flex: 1,+ p: 0,+ listStyleType,+ } }, { children: [0, 1, 2].map((i) => (_jsx(Box, Object.assign({ as: "li", sx: {+ display: "list-item",+ color: "text",+ fontSize: 8,+ mb: "1px",+ } }, { children: _jsx(Flex, Object.assign({ sx: {+ alignItems: "center",+ } }, { children: _jsx(Box, { sx: {+ width: "100%",+ flexShrink: 0,+ height: 4,+ bg: "#cbcbcb",+ borderRadius: "small",+ } }) })) }), i.toString()))) })));+}diff --git a/packages/editor/dist/es/toolbar/tools/table.d.ts b/packages/editor/dist/es/toolbar/tools/table.d.tsnew file mode 100644index 000000000..8a7280fd5--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/table.d.ts@@ -0,0 +1,24 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function TableSettings(props: ToolProps): JSX.Element | null;+export declare function RowProperties(props: ToolProps): JSX.Element;+export declare function ColumnProperties(props: ToolProps): JSX.Element;+export declare function TableProperties(props: ToolProps): JSX.Element;+export declare function CellProperties(props: ToolProps): JSX.Element;+export declare function CellBackgroundColor(props: ToolProps): JSX.Element;+export declare function CellTextColor(props: ToolProps): JSX.Element;+export declare function CellBorderColor(props: ToolProps): JSX.Element;+export declare function CellBorderWidth(props: ToolProps): JSX.Element;+export declare const InsertColumnLeft: (props: ToolProps) => JSX.Element;+export declare const InsertColumnRight: (props: ToolProps) => JSX.Element;+export declare const MoveColumnLeft: (props: ToolProps) => JSX.Element;+export declare const MoveColumnRight: (props: ToolProps) => JSX.Element;+export declare const DeleteColumn: (props: ToolProps) => JSX.Element;+export declare const SplitCells: (props: ToolProps) => JSX.Element;+export declare const MergeCells: (props: ToolProps) => JSX.Element;+export declare const InsertRowAbove: (props: ToolProps) => JSX.Element;+export declare const InsertRowBelow: (props: ToolProps) => JSX.Element;+export declare const MoveRowUp: (props: ToolProps) => JSX.Element;+export declare const MoveRowDown: (props: ToolProps) => JSX.Element;+export declare const DeleteRow: (props: ToolProps) => JSX.Element;+export declare const DeleteTable: (props: ToolProps) => JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/table.js b/packages/editor/dist/es/toolbar/tools/table.jsnew file mode 100644index 000000000..3da5021b3--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/table.js@@ -0,0 +1,167 @@+import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+import { useCallback, useMemo, useRef, useState } from "react";+import { Flex, Text } from "rebass";+import { ResponsivePresenter } from "../../components/responsive";+import { moveColumnLeft as moveColumnLeftAction, moveColumnRight as moveColumnRightAction, moveRowDown as moveRowDownAction, moveRowUp as moveRowUpAction, } from "../../extensions/table/actions";+import { MoreTools } from "../components/more-tools";+import { menuButtonToTool } from "./utils";+import { getToolDefinition } from "../tool-definitions";+import { CellProperties as CellPropertiesPopup } from "../popups/cell-properties";+import { ColorTool } from "./colors";+import { Counter } from "../components/counter";+import { useToolbarLocation } from "../stores/toolbar-store";+import { showPopup } from "../../components/popup-presenter";+export function TableSettings(props) {+ const { editor } = props;+ const isBottom = useToolbarLocation() === "bottom";+ if (!editor.isActive("table") || !isBottom)+ return null;+ return (_jsx(MoreTools, Object.assign({}, props, { autoCloseOnUnmount: true, popupId: "tableSettings", tools: [+ "insertColumnLeft",+ "insertColumnRight",+ "insertRowAbove",+ "insertRowBelow",+ "cellProperties",+ "columnProperties",+ "rowProperties",+ "deleteRow",+ "deleteColumn",+ "deleteTable",+ ] })));+}+export function RowProperties(props) {+ const { editor } = props;+ const buttonRef = useRef();+ const [isMenuOpen, setIsMenuOpen] = useState(false);+ const items = useMemo(() => [+ insertRowAbove(editor),+ insertRowBelow(editor),+ moveRowUp(editor),+ moveRowDown(editor),+ deleteRow(editor),+ ], []);+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: () => setIsMenuOpen(true) })), _jsx(ResponsivePresenter, { title: "Row properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: () => setIsMenuOpen(false), position: {+ target: buttonRef.current,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ }, items: items })] }));+}+export function ColumnProperties(props) {+ const { editor } = props;+ const buttonRef = useRef();+ const [isMenuOpen, setIsMenuOpen] = useState(false);+ const items = useMemo(() => [+ insertColumnLeft(editor),+ insertColumnRight(editor),+ moveColumnLeft(editor),+ moveColumnRight(editor),+ deleteColumn(editor),+ ], []);+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: () => setIsMenuOpen(true) })), _jsx(ResponsivePresenter, { title: "Column properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: () => setIsMenuOpen(false), position: {+ target: buttonRef.current,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ }, items: items })] }));+}+export function TableProperties(props) {+ const { editor } = props;+ const buttonRef = useRef();+ const [isMenuOpen, setIsMenuOpen] = useState(false);+ const items = useMemo(() => [+ insertColumnLeft(editor),+ insertColumnRight(editor),+ moveColumnLeft(editor),+ moveColumnRight(editor),+ deleteColumn(editor),+ { type: "separator", key: "cellSeperator" },+ mergeCells(editor),+ splitCells(editor),+ cellProperties(editor),+ { type: "separator", key: "tableSeperator" },+ deleteTable(editor),+ ], []);+ return (_jsxs(_Fragment, { children: [_jsx(ToolButton, Object.assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: () => setIsMenuOpen(true) })), _jsx(ResponsivePresenter, { title: "Table properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: () => setIsMenuOpen(false), position: {+ target: buttonRef.current,+ isTargetAbsolute: true,+ location: "below",+ yOffset: 5,+ }, items: items })] }));+}+export function CellProperties(props) {+ return (_jsx(_Fragment, { children: _jsx(MoreTools, Object.assign({}, props, { popupId: "cellProperties", tools: [+ "mergeCells",+ "splitCells",+ "cellBackgroundColor",+ "cellTextColor",+ "cellBorderColor",+ "cellBorderWidth",+ ] })) }));+}+export function CellBackgroundColor(props) {+ const { editor } = props;+ return (_jsx(ColorTool, Object.assign({}, props, { cacheKey: "cellBackgroundColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").backgroundColor; }, title: "Cell background color", onColorChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().setCellAttribute("backgroundColor", color).run(); } })));+}+export function CellTextColor(props) {+ const { editor } = props;+ return (_jsx(ColorTool, Object.assign({}, props, { cacheKey: "cellTextColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").color; }, title: "Cell text color", onColorChange: (color) => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setCellAttribute("color", color).run(); } })));+}+export function CellBorderColor(props) {+ const { editor } = props;+ return (_jsx(ColorTool, Object.assign({}, props, { cacheKey: "cellBorderColor", getActiveColor: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").borderColor; }, title: "Cell border color", onColorChange: (color) => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setCellAttribute("borderColor", color).run();+ } })));+}+export function CellBorderWidth(props) {+ const { editor } = props;+ const { borderWidth: _borderWidth } = editor.getAttributes("tableCell");+ const borderWidth = _borderWidth ? _borderWidth : 1;+ const decreaseBorderWidth = useCallback(() => {+ return Math.max(1, borderWidth - 1);+ }, [borderWidth]);+ const increaseBorderWidth = useCallback(() => {+ return Math.min(10, borderWidth + 1);+ }, [borderWidth]);+ return (_jsxs(Flex, Object.assign({ sx: { justifyContent: "center", alignItems: "center" } }, { children: [_jsx(Text, Object.assign({ variant: "subBody", sx: { mx: 1 } }, { children: "Border width:" })), _jsx(Counter, { title: "cell border width", onDecrease: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", decreaseBorderWidth());+ }, onIncrease: () => {+ var _a;+ return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", increaseBorderWidth());+ }, onReset: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", 1); }, value: borderWidth + "px" })] })));+}+const insertColumnLeft = (editor) => (Object.assign(Object.assign({}, getToolDefinition("insertColumnLeft")), { key: "addColumnLeft", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnBefore().run(); } }));+const insertColumnRight = (editor) => (Object.assign(Object.assign({}, getToolDefinition("insertColumnRight")), { key: "addColumnRight", type: "button", title: "Add column right", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnAfter().run(); }, icon: "insertColumnRight" }));+const moveColumnLeft = (editor) => (Object.assign(Object.assign({}, getToolDefinition("moveColumnLeft")), { key: "moveColumnLeft", type: "button", onClick: () => moveColumnLeftAction(editor) }));+const moveColumnRight = (editor) => (Object.assign(Object.assign({}, getToolDefinition("moveColumnRight")), { key: "moveColumnRight", type: "button", onClick: () => moveColumnRightAction(editor) }));+const deleteColumn = (editor) => (Object.assign(Object.assign({}, getToolDefinition("deleteColumn")), { key: "deleteColumn", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteColumn().run(); } }));+const splitCells = (editor) => (Object.assign(Object.assign({}, getToolDefinition("splitCells")), { key: "splitCells", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().splitCell().run(); } }));+const mergeCells = (editor) => (Object.assign(Object.assign({}, getToolDefinition("mergeCells")), { key: "mergeCells", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().mergeCells().run(); } }));+const insertRowAbove = (editor) => (Object.assign(Object.assign({}, getToolDefinition("insertRowAbove")), { key: "insertRowAbove", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addRowBefore().run(); } }));+const insertRowBelow = (editor) => (Object.assign(Object.assign({}, getToolDefinition("insertRowBelow")), { key: "insertRowBelow", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addRowAfter().run(); } }));+const moveRowUp = (editor) => (Object.assign(Object.assign({}, getToolDefinition("moveRowUp")), { key: "moveRowUp", type: "button", onClick: () => moveRowUpAction(editor) }));+const moveRowDown = (editor) => (Object.assign(Object.assign({}, getToolDefinition("moveRowDown")), { key: "moveRowDown", type: "button", onClick: () => moveRowDownAction(editor) }));+const deleteRow = (editor) => (Object.assign(Object.assign({}, getToolDefinition("deleteRow")), { key: "deleteRow", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteRow().run(); } }));+const deleteTable = (editor) => (Object.assign(Object.assign({}, getToolDefinition("deleteTable")), { key: "deleteTable", type: "button", onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteTable().run(); } }));+const cellProperties = (editor) => (Object.assign(Object.assign({}, getToolDefinition("cellProperties")), { key: "cellProperties", type: "button", onClick: () => {+ showPopup({+ theme: editor.storage.theme,+ popup: (hide) => _jsx(CellPropertiesPopup, { onClose: hide, editor: editor }),+ });+ } }));+export const InsertColumnLeft = menuButtonToTool(insertColumnLeft);+export const InsertColumnRight = menuButtonToTool(insertColumnRight);+export const MoveColumnLeft = menuButtonToTool(moveColumnLeft);+export const MoveColumnRight = menuButtonToTool(moveColumnRight);+export const DeleteColumn = menuButtonToTool(deleteColumn);+export const SplitCells = menuButtonToTool(splitCells);+export const MergeCells = menuButtonToTool(mergeCells);+export const InsertRowAbove = menuButtonToTool(insertRowAbove);+export const InsertRowBelow = menuButtonToTool(insertRowBelow);+export const MoveRowUp = menuButtonToTool(moveRowUp);+export const MoveRowDown = menuButtonToTool(moveRowDown);+export const DeleteRow = menuButtonToTool(deleteRow);+export const DeleteTable = menuButtonToTool(deleteTable);diff --git a/packages/editor/dist/es/toolbar/tools/textdirection.d.ts b/packages/editor/dist/es/toolbar/tools/textdirection.d.tsnew file mode 100644index 000000000..a625990f0--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/textdirection.d.ts@@ -0,0 +1,4 @@+/// <reference types="react" />+import { ToolProps } from "../types";+export declare function RightToLeft(props: ToolProps): JSX.Element;+export declare function LeftToRight(props: ToolProps): JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/textdirection.js b/packages/editor/dist/es/toolbar/tools/textdirection.jsnew file mode 100644index 000000000..352a49c9e--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/textdirection.js@@ -0,0 +1,23 @@+var __rest = (this && this.__rest) || function (s, e) {+ var t = {};+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)+ t[p] = s[p];+ if (s != null && typeof Object.getOwnPropertySymbols === "function")+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))+ t[p[i]] = s[p[i]];+ }+ return t;+};+import { jsx as _jsx } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+function TextDirectionTool(props) {+ const { editor, direction } = props, toolProps = __rest(props, ["editor", "direction"]);+ return (_jsx(ToolButton, Object.assign({}, toolProps, { onClick: () => { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(direction).run(); }, toggled: editor.isActive({ textDirection: direction }) })));+}+export function RightToLeft(props) {+ return _jsx(TextDirectionTool, Object.assign({ direction: "rtl" }, props));+}+export function LeftToRight(props) {+ return _jsx(TextDirectionTool, Object.assign({ direction: "ltr" }, props));+}diff --git a/packages/editor/dist/es/toolbar/tools/utils.d.ts b/packages/editor/dist/es/toolbar/tools/utils.d.tsnew file mode 100644index 000000000..2aaf4fe1f--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/utils.d.ts@@ -0,0 +1,5 @@+/// <reference types="react" />+import { Editor } from "@tiptap/core";+import { MenuButton } from "../../components/menu/types";+import { ToolProps } from "../types";+export declare function menuButtonToTool(constructItem: (editor: Editor) => MenuButton): (props: ToolProps) => JSX.Element;diff --git a/packages/editor/dist/es/toolbar/tools/utils.js b/packages/editor/dist/es/toolbar/tools/utils.jsnew file mode 100644index 000000000..494464fee--- /dev/null+++ b/packages/editor/dist/es/toolbar/tools/utils.js@@ -0,0 +1,8 @@+import { jsx as _jsx } from "react/jsx-runtime";+import { ToolButton } from "../components/tool-button";+export function menuButtonToTool(constructItem) {+ return function (props) {+ const item = constructItem(props.editor);+ return (_jsx(ToolButton, Object.assign({}, props, { icon: item.icon || props.icon, toggled: item.isChecked || false, title: item.title, onClick: item.onClick })));+ };+}diff --git a/packages/editor/dist/es/toolbar/types.d.ts b/packages/editor/dist/es/toolbar/types.d.tsnew file mode 100644index 000000000..08982355e--- /dev/null+++ b/packages/editor/dist/es/toolbar/types.d.ts@@ -0,0 +1,19 @@+import { Editor } from "../types";+import { IconNames } from "./icons";+import { ToolId } from "./tools";+import { NodeWithOffset } from "./utils/prosemirror";+export declare type ToolButtonVariant = "small" | "normal";+export declare type ToolProps = ToolDefinition & {+ editor: Editor;+ variant?: ToolButtonVariant;+ force?: boolean;+ selectedNode?: NodeWithOffset;+};+export declare type ToolDefinition = {+ icon: IconNames;+ title: string;+ conditional?: boolean;+ description?: string;+};+export declare type ToolbarGroupDefinition = (ToolId | ToolId[])[];+export declare type ToolbarDefinition = ToolbarGroupDefinition[];diff --git a/packages/editor/dist/es/toolbar/types.js b/packages/editor/dist/es/toolbar/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/toolbar/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/toolbar/utils/dom.d.ts b/packages/editor/dist/es/toolbar/utils/dom.d.tsnew file mode 100644index 000000000..e3fdd7ffb--- /dev/null+++ b/packages/editor/dist/es/toolbar/utils/dom.d.ts@@ -0,0 +1,4 @@+export declare function getToolbarElement(): HTMLElement;+export declare function getPopupContainer(): HTMLElement;+export declare function getEditorContainer(): HTMLElement;+export declare function getEditorDOM(): HTMLElement;diff --git a/packages/editor/dist/es/toolbar/utils/dom.js b/packages/editor/dist/es/toolbar/utils/dom.jsnew file mode 100644index 000000000..729a9f754--- /dev/null+++ b/packages/editor/dist/es/toolbar/utils/dom.js@@ -0,0 +1,14 @@+export function getToolbarElement() {+ return (document.querySelector(".editor-toolbar") || undefined);+}+export function getPopupContainer() {+ return (document.getElementById("popup-container") || undefined);+}+export function getEditorContainer() {+ return (document.querySelector(".editor") ||+ getPopupContainer());+}+export function getEditorDOM() {+ return (document.querySelector(".ProseMirror") ||+ getEditorContainer()); // ProseMirror+}diff --git a/packages/editor/dist/es/toolbar/utils/prosemirror.d.ts b/packages/editor/dist/es/toolbar/utils/prosemirror.d.tsnew file mode 100644index 000000000..5dd849997--- /dev/null+++ b/packages/editor/dist/es/toolbar/utils/prosemirror.d.ts@@ -0,0 +1,12 @@+import { Editor } from "@tiptap/core";+import { Node, Mark } from "prosemirror-model";+import { Selection } from "prosemirror-state";+export declare type NodeWithOffset = {+ node: Node;+ from: number;+ to: number;+};+export declare function findSelectedDOMNode(editor: Editor, types: string[]): HTMLElement | null;+export declare function findSelectedNode(editor: Editor, type: string): Node | null;+export declare function findMark(node: Node, type: string): Mark | undefined;+export declare function selectionToOffset(selection: Selection): NodeWithOffset;diff --git a/packages/editor/dist/es/toolbar/utils/prosemirror.js b/packages/editor/dist/es/toolbar/utils/prosemirror.jsnew file mode 100644index 000000000..10b0ecede--- /dev/null+++ b/packages/editor/dist/es/toolbar/utils/prosemirror.js@@ -0,0 +1,31 @@+import { findParentNode, } from "@tiptap/core";+export function findSelectedDOMNode(editor, types) {+ var _a;+ const { $anchor } = editor.state.selection;+ const selectedNode = editor.state.doc.nodeAt($anchor.pos);+ const pos = types.includes((selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type.name) || "")+ ? $anchor.pos+ : (_a = findParentNode((node) => types.includes(node.type.name))(editor.state.selection)) === null || _a === void 0 ? void 0 : _a.pos;+ if (!pos)+ return null;+ return editor.view.nodeDOM(pos) || null;+}+export function findSelectedNode(editor, type) {+ var _a;+ const { $anchor } = editor.state.selection;+ const selectedNode = editor.state.doc.nodeAt($anchor.pos);+ const pos = (selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type.name) === type+ ? $anchor.pos+ : (_a = findParentNode((node) => node.type.name === type)(editor.state.selection)) === null || _a === void 0 ? void 0 : _a.pos;+ if (!pos)+ return null;+ return editor.state.doc.nodeAt(pos);+}+export function findMark(node, type) {+ const mark = node.marks.find((m) => m.type.name === type);+ return mark;+}+export function selectionToOffset(selection) {+ const { $from, from } = selection;+ return { node: $from.node(), from, to: from + $from.node().nodeSize };+}diff --git a/packages/editor/dist/es/types.d.ts b/packages/editor/dist/es/types.d.tsnew file mode 100644index 000000000..9aa191120--- /dev/null+++ b/packages/editor/dist/es/types.d.ts@@ -0,0 +1,9 @@+import { Editor as TiptapEditor } from "@tiptap/core";+export interface Editor extends TiptapEditor {+ /**+ * Use this to get the latest instance of the editor.+ * This is required to reduce unnecessary rerenders of+ * toolbar elements.+ */+ current?: TiptapEditor;+}diff --git a/packages/editor/dist/es/types.js b/packages/editor/dist/es/types.jsnew file mode 100644index 000000000..cb0ff5c3b--- /dev/null+++ b/packages/editor/dist/es/types.js@@ -0,0 +1 @@+export {};diff --git a/packages/editor/dist/es/utils/config.d.ts b/packages/editor/dist/es/utils/config.d.tsnew file mode 100644index 000000000..737bfd7e4--- /dev/null+++ b/packages/editor/dist/es/utils/config.d.ts@@ -0,0 +1,7 @@+declare function set<T>(key: string, value: T | null): void;+declare function get<T>(key: string, def?: T): T | undefined;+export declare const config: {+ set: typeof set;+ get: typeof get;+};+export {};diff --git a/packages/editor/dist/es/utils/config.js b/packages/editor/dist/es/utils/config.jsnew file mode 100644index 000000000..4e07c19fa--- /dev/null+++ b/packages/editor/dist/es/utils/config.js@@ -0,0 +1,22 @@+function set(key, value) {+ if (!value)+ return window.localStorage.removeItem(key);+ window.localStorage.setItem(key, JSON.stringify(value));+}+function get(key, def) {+ const value = window.localStorage.getItem(key);+ if (!value)+ return def;+ return tryParse(value);+}+export const config = { set, get };+function tryParse(val) {+ if (val === "undefined" || val === "null")+ return;+ try {+ return JSON.parse(val);+ }+ catch (e) {+ return val;+ }+}diff --git a/packages/editor/dist/es/utils/debounce.d.ts b/packages/editor/dist/es/utils/debounce.d.tsnew file mode 100644index 000000000..aa5951c17--- /dev/null+++ b/packages/editor/dist/es/utils/debounce.d.ts@@ -0,0 +1 @@+export declare function debounce<F extends (...args: any) => any>(func: F, waitFor: number): (...args: Parameters<F>) => ReturnType<F>;diff --git a/packages/editor/dist/es/utils/debounce.js b/packages/editor/dist/es/utils/debounce.jsnew file mode 100644index 000000000..bc2f92584--- /dev/null+++ b/packages/editor/dist/es/utils/debounce.js@@ -0,0 +1,9 @@+export function debounce(func, waitFor) {+ let timeout;+ const debounced = (...args) => {+ if (timeout)+ clearTimeout(timeout);+ timeout = setTimeout(() => func(...args), waitFor);+ };+ return debounced;+}diff --git a/packages/editor/dist/es/utils/position.d.ts b/packages/editor/dist/es/utils/position.d.tsnew file mode 100644index 000000000..85bee69bf--- /dev/null+++ b/packages/editor/dist/es/utils/position.d.ts@@ -0,0 +1,24 @@+declare type PositionData = {+ x: number;+ y: number;+ actualX: number;+ actualY: number;+ width?: number;+ height?: number;+};+export declare type PositionOptions = {+ target?: HTMLElement | "mouse";+ isTargetAbsolute?: boolean;+ location?: "right" | "left" | "below" | "top";+ align?: "center" | "start" | "end";+ yOffset?: number;+ xOffset?: number;+ yAnchor?: HTMLElement;+ parent?: HTMLElement | Element;+};+export declare function getPosition(element: HTMLElement, options: PositionOptions): {+ top: number;+ left: number;+};+export declare function getElementPosition(element: HTMLElement, absolute: boolean): PositionData;+export {};diff --git a/packages/editor/dist/es/utils/position.js b/packages/editor/dist/es/utils/position.jsnew file mode 100644index 000000000..ebed04e6a--- /dev/null+++ b/packages/editor/dist/es/utils/position.js@@ -0,0 +1,106 @@+const mousePosition = { x: 0, y: 0, actualX: 0, actualY: 0 };+window.addEventListener("mousemove", (e) => {+ const { x, y, actualX, actualY } = getMousePosition(e);+ mousePosition.x = x;+ mousePosition.y = y;+ mousePosition.actualX = actualX;+ mousePosition.actualY = actualY;+});+export function getPosition(element, options) {+ const { target = "mouse", isTargetAbsolute = false, location = undefined, yOffset = 0, xOffset = 0, align = "start", parent = document.body, yAnchor, } = options || {};+ const { x, y, width, height, actualX, actualY } = target === "mouse"+ ? mousePosition+ : getElementPosition(target, isTargetAbsolute);+ const elementWidth = element.offsetWidth;+ const elementHeight = element.offsetHeight;+ const windowWidth = parent.clientWidth;+ const windowHeight = parent.clientHeight;+ let position = { top: 0, left: 0 };+ if (windowWidth - actualX < elementWidth) {+ const xDiff = actualX - x;+ position.left = windowWidth - elementWidth;+ position.left -= xDiff;+ }+ else {+ position.left = x;+ }+ if (width && location === "right") {+ position.left += width;+ }+ else if (location === "left")+ position.left -= elementWidth;+ if (actualY + elementHeight > windowHeight) {+ position.top = windowHeight - elementHeight;+ }+ else {+ position.top = y;+ }+ if (height) {+ if (location === "below")+ position.top += height;+ else if (location === "top")+ position.top = y - elementHeight;+ }+ if (width && target !== "mouse" && align === "center" && elementWidth > 0) {+ position.left -= elementWidth / 2 - width / 2;+ }+ else if (width &&+ target !== "mouse" &&+ align === "end" &&+ elementWidth > 0) {+ position.left -= elementWidth - width;+ }+ // Adjust menu height+ if (elementHeight > windowHeight - position.top) {+ element.style.maxHeight = `${windowHeight - 20}px`;+ }+ if (yAnchor) {+ const anchorY = getElementPosition(yAnchor, isTargetAbsolute);+ position.top = anchorY.y - elementHeight;+ }+ position.top = isTargetAbsolute && position.top < 0 ? 0 : position.top;+ position.left = isTargetAbsolute && position.left < 0 ? 0 : position.left;+ position.top += location === "below" ? yOffset : -yOffset;+ position.left += xOffset;+ return position;+}+function getMousePosition(e) {+ var posx = 0;+ var posy = 0;+ if (!e && window.event)+ e = window.event;+ if (e.pageX || e.pageY) {+ posx = e.pageX;+ posy = e.pageY;+ }+ else if (e.clientX || e.clientY) {+ posx =+ e.clientX ++ document.body.scrollLeft ++ document.documentElement.scrollLeft;+ posy =+ e.clientY + document.body.scrollTop + document.documentElement.scrollTop;+ }+ return {+ x: posx,+ y: posy,+ actualY: posy,+ actualX: posx,+ };+}+export function getElementPosition(element, absolute) {+ const rect = element.getBoundingClientRect();+ const position = {+ x: element.offsetLeft,+ y: element.offsetTop,+ width: rect.width,+ height: rect.height,+ actualY: rect.y,+ actualX: rect.x,+ };+ if (absolute) {+ position.x = position.actualX;+ position.y = position.actualY;+ }+ return position;+}diff --git a/packages/editor/dist/extensions/attachment/attachment.js b/packages/editor/dist/extensions/attachment/attachment.jsdeleted file mode 100644index 5f639d352..000000000--- a/packages/editor/dist/extensions/attachment/attachment.js+++ /dev/null@@ -1,170 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.getDataAttribute = exports.AttachmentNode = void 0;-var core_1 = require("@tiptap/core");-var react_1 = require("../react");-var component_1 = require("./component");-exports.AttachmentNode = core_1.Node.create({- name: "attachment",- content: "inline*",- marks: "",- inline: true,- atom: true,- addOptions: function () {- return {- HTMLAttributes: {},- onDownloadAttachment: function () { return false; },- onOpenAttachmentPicker: function () { return false; },- };- },- group: function () {- return "inline";- },- draggable: true,- addAttributes: function () {- return {- progress: {- default: 0,- rendered: false,- },- hash: getDataAttribute("hash"),- filename: getDataAttribute("filename"),- type: getDataAttribute("mime"),- size: getDataAttribute("size"),- };- },- parseHTML: function () {- return [- {- tag: "span[data-hash]",- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "span",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),- ];- },- addNodeView: function () {- return (0, react_1.createSelectionBasedNodeView)(component_1.AttachmentComponent, {- shouldUpdate: function (_a, _b) {- var prev = _a.attrs;- var next = _b.attrs;- return prev.progress !== next.progress;- },- });- },- addCommands: function () {- var _this = this;- return {- insertAttachment: function (attachment) {- return function (_a) {- var commands = _a.commands;- return commands.insertContent({- type: _this.name,- attrs: attachment,- });- };- },- removeAttachment: function () {- return function (_a) {- var commands = _a.commands;- return commands.deleteNode(_this.name);- };- },- downloadAttachment: function (attachment) {- return function (_a) {- var editor = _a.editor;- return _this.options.onDownloadAttachment(editor, attachment);- };- },- openAttachmentPicker: function (type) {- return function (_a) {- var editor = _a.editor;- return _this.options.onOpenAttachmentPicker(editor, type);- };- },- setAttachmentProgress: function (options) {- return function (_a) {- var e_1, _b;- var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;- var hash = options.hash, progress = options.progress, type = options.type;- var attachments = (0, core_1.findChildren)(state.doc, function (node) {- return (node.type.name === _this.name || node.type.name === "image") &&- node.attrs.hash === hash;- });- try {- for (var attachments_1 = __values(attachments), attachments_1_1 = attachments_1.next(); !attachments_1_1.done; attachments_1_1 = attachments_1.next()) {- var attachment = attachments_1_1.value;- tr.setNodeMarkup(attachment.pos, attachment.node.type, __assign(__assign({}, attachment.node.attrs), { progress: progress === 100 ? null : progress }));- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (attachments_1_1 && !attachments_1_1.done && (_b = attachments_1.return)) _b.call(attachments_1);- }- finally { if (e_1) throw e_1.error; }- }- tr.setMeta("preventUpdate", true);- tr.setMeta("addToHistory", false);- if (dispatch)- dispatch(tr);- return true;- };- },- };- },- // addInputRules() {- // return [- // nodeInputRule({- // find: inputRegex,- // type: this.type,- // getAttributes: (match) => {- // const [, , alt, src, title] = match;- // return { src, alt, title };- // },- // }),- // ];- // },-});-function getDataAttribute(name, def) {- return {- default: def,- parseHTML: function (element) { return element.dataset[name]; },- renderHTML: function (attributes) {- var _a;- if (!attributes[name]) {- return {};- }- return _a = {},- _a["data-".concat(name)] = attributes[name],- _a;- },- };-}-exports.getDataAttribute = getDataAttribute;diff --git a/packages/editor/dist/extensions/codeblock/codeblock.js b/packages/editor/dist/extensions/codeblock/codeblock.jsdeleted file mode 100644index 446b156ee..000000000--- a/packages/editor/dist/extensions/codeblock/codeblock.js+++ /dev/null@@ -1,627 +0,0 @@-"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.toCodeLines = exports.getLines = exports.toCaretPosition = exports.CodeBlock = exports.tildeInputRegex = exports.backtickInputRegex = void 0;-var core_1 = require("@tiptap/core");-var core_2 = require("@tiptap/core");-var prosemirror_state_1 = require("prosemirror-state");-var component_1 = require("./component");-var highlighter_1 = require("./highlighter");-var react_1 = require("../react");-var detect_indent_1 = __importDefault(require("detect-indent"));-var redent_1 = __importDefault(require("redent"));-var strip_indent_1 = __importDefault(require("strip-indent"));-exports.backtickInputRegex = /^```([a-z]+)?[\s\n]$/;-exports.tildeInputRegex = /^~~~([a-z]+)?[\s\n]$/;-var ZERO_WIDTH_SPACE = "\u200b";-var NEWLINE = "\n";-exports.CodeBlock = core_2.Node.create({- name: "codeblock",- addOptions: function () {- return {- languageClassPrefix: "language-",- exitOnTripleEnter: true,- exitOnArrowDown: true,- exitOnArrowUp: true,- HTMLAttributes: {},- };- },- content: "text*",- marks: "",- group: "block",- code: true,- defining: true,- addAttributes: function () {- var _this = this;- return {- caretPosition: {- default: undefined,- rendered: false,- },- lines: {- default: [],- rendered: false,- },- indentType: {- default: "space",- parseHTML: function (element) {- var indentType = element.dataset.indentType;- return indentType;- },- renderHTML: function (attributes) {- if (!attributes.indentType) {- return {};- }- return {- "data-indent-type": attributes.indentType,- };- },- },- indentLength: {- default: 2,- parseHTML: function (element) {- var indentLength = element.dataset.indentLength;- return indentLength;- },- renderHTML: function (attributes) {- if (!attributes.indentLength) {- return {};- }- return {- "data-indent-length": attributes.indentLength,- };- },- },- language: {- default: null,- parseHTML: function (element) {- var _a;- var languageClassPrefix = _this.options.languageClassPrefix;- var classNames = __spreadArray(__spreadArray([], __read((element.classList || [])), false), __read((((_a = element === null || element === void 0 ? void 0 : element.firstElementChild) === null || _a === void 0 ? void 0 : _a.classList) || [])), false);- var languages = classNames- .filter(function (className) { return className.startsWith(languageClassPrefix); })- .map(function (className) { return className.replace(languageClassPrefix, ""); });- var language = languages[0];- if (!language) {- return null;- }- return language;- },- renderHTML: function (attributes) {- if (!attributes.language) {- return {};- }- return {- class: "language-".concat(attributes.language),- };- },- },- };- },- parseHTML: function () {- return [- {- tag: "pre",- preserveWhitespace: "full",- // contentElement: (node) => {- // if (node instanceof HTMLElement) {- // node.innerText = node.innerText.replaceAll("\n\u200b\n", "\n\n");- // }- // return node;- // },- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "pre",- (0, core_2.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),- ["code", {}, 0],- ];- },- addCommands: function () {- var _this = this;- return {- setCodeBlock: function (attributes) {- return function (_a) {- var commands = _a.commands;- return commands.setNode(_this.name, attributes);- };- },- toggleCodeBlock: function (attributes) {- return function (_a) {- var commands = _a.commands;- console.log("TOGGLING!");- return commands.toggleNode(_this.name, "paragraph", attributes);- };- },- changeCodeBlockIndentation: function (options) {- return function (_a) {- var e_1, _b;- var editor = _a.editor, tr = _a.tr, commands = _a.commands;- var state = editor.state;- var selection = state.selection;- var $from = selection.$from;- if ($from.parent.type !== _this.type) {- return false;- }- var lines = $from.parent.attrs.lines;- try {- for (var lines_1 = __values(lines), lines_1_1 = lines_1.next(); !lines_1_1.done; lines_1_1 = lines_1.next()) {- var line = lines_1_1.value;- var text = line.text();- var whitespaceLength = text.length - text.trimStart().length;- if (!whitespaceLength)- continue;- var indentLength = whitespaceLength;- var indentToken = indent({- type: options.type,- amount: indentLength,- });- tr.insertText(indentToken, tr.mapping.map(line.from), tr.mapping.map(line.from + whitespaceLength));- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (lines_1_1 && !lines_1_1.done && (_b = lines_1.return)) _b.call(lines_1);- }- finally { if (e_1) throw e_1.error; }- }- commands.updateAttributes(_this.type, {- indentType: options.type,- indentLength: options.amount,- });- return true;- };- },- };- },- addKeyboardShortcuts: function () {- var _this = this;- return {- "Mod-Alt-c": function () { return _this.editor.commands.toggleCodeBlock(); },- "Mod-a": function (_a) {- var editor = _a.editor;- var $anchor = _this.editor.state.selection.$anchor;- if ($anchor.parent.type.name !== _this.name) {- return false;- }- var codeblock = (0, core_1.findParentNodeClosestToPos)($anchor, function (node) { return node.type.name === _this.type.name; });- if (!codeblock)- return false;- return editor.commands.setTextSelection({- from: codeblock.pos,- to: codeblock.pos + codeblock.node.nodeSize,- });- },- // remove code block when at start of document or code block is empty- Backspace: function () {- var _a = _this.editor.state.selection, empty = _a.empty, $anchor = _a.$anchor;- var isAtStart = $anchor.pos === 1;- if (!empty || $anchor.parent.type.name !== _this.name) {- return false;- }- if (isAtStart || !$anchor.parent.textContent.length) {- return _this.editor.commands.deleteNode(_this.type);- }- return false;- },- // exit node on triple enter- Enter: function (_a) {- var editor = _a.editor;- var state = editor.state;- var selection = state.selection;- var $from = selection.$from, empty = selection.empty;- if (!empty || $from.parent.type !== _this.type) {- return false;- }- var indentation = parseIndentation($from.parent);- return ((_this.options.exitOnTripleEnter &&- exitOnTripleEnter(editor, $from)) ||- indentOnEnter(editor, $from, indentation));- },- // exit node on arrow up- ArrowUp: function (_a) {- var editor = _a.editor;- if (!_this.options.exitOnArrowUp) {- return false;- }- var state = editor.state;- var selection = state.selection;- var $anchor = selection.$anchor, empty = selection.empty;- if (!empty || $anchor.parent.type !== _this.type) {- return false;- }- var isAtStart = $anchor.pos === 1;- if (!isAtStart) {- return false;- }- return editor.commands.insertContentAt(0, "<p></p>");- },- // exit node on arrow down- ArrowDown: function (_a) {- var editor = _a.editor;- if (!_this.options.exitOnArrowDown) {- return false;- }- var state = editor.state;- var selection = state.selection, doc = state.doc;- var $from = selection.$from, empty = selection.empty;- if (!empty || $from.parent.type !== _this.type) {- return false;- }- var isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;- if (!isAtEnd) {- return false;- }- var after = $from.after();- if (after === undefined) {- return false;- }- var nodeAfter = doc.nodeAt(after);- if (nodeAfter) {- editor.commands.setNodeSelection($from.before());- return false;- }- return editor.commands.exitCode();- },- "Shift-Tab": function (_a) {- var editor = _a.editor;- var state = editor.state;- var selection = state.selection;- var $from = selection.$from;- if ($from.parent.type !== _this.type) {- return false;- }- var indentation = parseIndentation($from.parent);- var indentToken = indent(indentation);- var lines = $from.parent.attrs.lines;- var selectedLines = getSelectedLines(lines, selection);- return editor- .chain()- .command(function (_a) {- var tr = _a.tr;- return withSelection(tr, function (tr) {- var e_2, _a;- try {- for (var selectedLines_1 = __values(selectedLines), selectedLines_1_1 = selectedLines_1.next(); !selectedLines_1_1.done; selectedLines_1_1 = selectedLines_1.next()) {- var line = selectedLines_1_1.value;- if (line.text(indentToken.length) !== indentToken)- continue;- tr.delete(tr.mapping.map(line.from), tr.mapping.map(line.from + indentation.amount));- }- }- catch (e_2_1) { e_2 = { error: e_2_1 }; }- finally {- try {- if (selectedLines_1_1 && !selectedLines_1_1.done && (_a = selectedLines_1.return)) _a.call(selectedLines_1);- }- finally { if (e_2) throw e_2.error; }- }- });- })- .run();- },- Tab: function (_a) {- var editor = _a.editor;- var state = editor.state;- var selection = state.selection;- var $from = selection.$from;- if ($from.parent.type !== _this.type) {- return false;- }- var lines = $from.parent.attrs.lines;- var selectedLines = getSelectedLines(lines, selection);- return editor- .chain()- .command(function (_a) {- var tr = _a.tr;- return withSelection(tr, function (tr) {- var e_3, _a;- var indentToken = indent(parseIndentation($from.parent));- if (selectedLines.length === 1)- return tr.insertText(indentToken, $from.pos);- try {- for (var selectedLines_2 = __values(selectedLines), selectedLines_2_1 = selectedLines_2.next(); !selectedLines_2_1.done; selectedLines_2_1 = selectedLines_2.next()) {- var line = selectedLines_2_1.value;- tr.insertText(indentToken, tr.mapping.map(line.from));- }- }- catch (e_3_1) { e_3 = { error: e_3_1 }; }- finally {- try {- if (selectedLines_2_1 && !selectedLines_2_1.done && (_a = selectedLines_2.return)) _a.call(selectedLines_2);- }- finally { if (e_3) throw e_3.error; }- }- });- })- .run();- },- };- },- addInputRules: function () {- return [- (0, core_2.textblockTypeInputRule)({- find: exports.backtickInputRegex,- type: this.type,- getAttributes: function (match) { return ({- language: match[1],- }); },- }),- (0, core_2.textblockTypeInputRule)({- find: exports.tildeInputRegex,- type: this.type,- getAttributes: function (match) { return ({- language: match[1],- }); },- }),- ];- },- addProseMirrorPlugins: function () {- var _this = this;- return [- // this plugin creates a code block for pasted content from VS Code- // we can also detect the copied code language- new prosemirror_state_1.Plugin({- key: new prosemirror_state_1.PluginKey("codeBlockVSCodeHandler"),- props: {- handlePaste: function (view, event) {- if (!event.clipboardData) {- return false;- }- var text = event.clipboardData.getData("text/plain");- var vscode = event.clipboardData.getData("vscode-editor-data");- var vscodeData = vscode ? JSON.parse(vscode) : undefined;- var language = vscodeData === null || vscodeData === void 0 ? void 0 : vscodeData.mode;- if (!text || !language) {- return false;- }- var indent = fixIndentation(text, parseIndentation(view.state.selection.$from.parent));- var tr = view.state.tr;- // create an empty code block if not already within one- if (!_this.editor.isActive(_this.type.name)) {- tr.replaceSelectionWith(_this.type.create({- language: language,- indentType: indent.type,- indentLength: indent.amount,- }));- }- // // put cursor inside the newly created code block- // tr.setSelection(- // TextSelection.near(- // tr.doc.resolve(Math.max(0, tr.selection.from - 2))- // )- // );- // add text to code block- // strip carriage return chars from text pasted as code- // see: https://github.com/ProseMirror/prosemirror-view/commit/a50a6bcceb4ce52ac8fcc6162488d8875613aacd- tr.insertText(indent.code.replace(/\r\n?/g, "\n"));- // store meta information- // this is useful for other plugins that depends on the paste event- // like the paste rule plugin- tr.setMeta("paste", true);- view.dispatch(tr);- return true;- },- },- }),- (0, highlighter_1.HighlighterPlugin)({ name: this.name, defaultLanguage: "txt" }),- ];- },- addNodeView: function () {- return (0, react_1.createNodeView)(component_1.CodeblockComponent, {- contentDOMFactory: function () {- var content = document.createElement("div");- content.classList.add("node-content-wrapper");- content.style.whiteSpace = "inherit";- // caret is not visible if content element width is 0px- content.style.minWidth = "20px";- return { dom: content };- },- shouldUpdate: function (_a, _b) {- var prev = _a.attrs;- var next = _b.attrs;- return (compareCaretPosition(prev.caretPosition, next.caretPosition) ||- prev.language !== next.language ||- prev.indentType !== next.indentType);- },- });- },-});-function toCaretPosition(selection, lines) {- var e_4, _a;- var $from = selection.$from, $to = selection.$to, $head = selection.$head;- if ($from.parent.type.name !== exports.CodeBlock.name)- return;- lines = lines || getLines($from.parent);- try {- for (var lines_2 = __values(lines), lines_2_1 = lines_2.next(); !lines_2_1.done; lines_2_1 = lines_2.next()) {- var line = lines_2_1.value;- if ($head.pos >= line.from && $head.pos <= line.to) {- var lineLength = line.length + 1;- return {- line: line.index + 1,- column: lineLength - (line.to - $head.pos),- selected: $to.pos - $from.pos,- total: lines.length,- from: line.from,- };- }- }- }- catch (e_4_1) { e_4 = { error: e_4_1 }; }- finally {- try {- if (lines_2_1 && !lines_2_1.done && (_a = lines_2.return)) _a.call(lines_2);- }- finally { if (e_4) throw e_4.error; }- }- return;-}-exports.toCaretPosition = toCaretPosition;-function getLines(node) {- var lines = node.attrs.lines;- return lines || [];-}-exports.getLines = getLines;-function exitOnTripleEnter(editor, $from) {- var isAtEnd = $from.parentOffset === $from.parent.nodeSize - 2;- var endsWithDoubleNewline = $from.parent.textContent.endsWith("\n\n");- if (!isAtEnd || !endsWithDoubleNewline) {- return false;- }- return editor- .chain()- .command(function (_a) {- var tr = _a.tr;- tr.delete($from.pos - 2, $from.pos);- return true;- })- .exitCode()- .run();-}-function indentOnEnter(editor, $from, options) {- var _a = getNewline($from, options) || {}, indentation = _a.indentation, newline = _a.newline;- if (!newline)- return false;- return editor- .chain()- .insertContent("".concat(newline).concat(indentation), {- parseOptions: { preserveWhitespace: "full" },- })- .focus()- .run();-}-function getNewline($from, options) {- var lines = $from.parent.attrs.lines;- var currentLine = getLineAt(lines, $from.pos);- if (!currentLine)- return false;- var text = currentLine.text();- var indentLength = text.length - text.trimStart().length;- return {- newline: NEWLINE,- indentation: indent({ amount: indentLength, type: options.type }),- };-}-function toCodeLines(code, pos) {- var positions = [];- var start = 0;- var from = pos + 1;- var index = 0;- var _loop_1 = function () {- var end = code.indexOf("\n", start);- if (end <= -1)- end = code.length;- var lineLength = end - start;- var to = from + lineLength;- var lineStart = start;- positions.push({- index: index,- length: lineLength,- from: from,- to: to,- text: function (length) {- return code.slice(lineStart, length ? lineStart + length : lineStart + lineLength);- },- });- from = to + 1;- start = end + 1;- ++index;- };- while (start <= code.length) {- _loop_1();- }- return positions;-}-exports.toCodeLines = toCodeLines;-function getSelectedLines(lines, selection) {- var $from = selection.$from, $to = selection.$to;- return lines.filter(function (line) {- return inRange(line.from, $from.pos, $to.pos) ||- inRange(line.to, $from.pos, $to.pos) ||- inRange($from.pos, line.from, line.to);- });-}-function parseIndentation(node) {- if (node.type.name !== exports.CodeBlock.name)- return undefined;- var _a = node.attrs, indentType = _a.indentType, indentLength = _a.indentLength;- return {- type: indentType,- amount: parseInt(indentLength),- };-}-function getLineAt(lines, pos) {- return lines.find(function (line) { return pos >= line.from && pos <= line.to; });-}-function inRange(x, a, b) {- return x >= a && x <= b;-}-function indent(options) {- var char = options.type === "space" ? " " : "\t";- return char.repeat(options.amount);-}-function compareCaretPosition(prev, next) {- return (next === undefined ||- (prev === null || prev === void 0 ? void 0 : prev.column) !== (next === null || next === void 0 ? void 0 : next.column) ||- (prev === null || prev === void 0 ? void 0 : prev.line) !== (next === null || next === void 0 ? void 0 : next.line));-}-/**- * Persist selection between transaction steps- */-function withSelection(tr, callback) {- var _a = tr.selection, $anchor = _a.$anchor, $head = _a.$head;- callback(tr);- tr.setSelection(new prosemirror_state_1.TextSelection(tr.doc.resolve(tr.mapping.map($anchor.pos)), tr.doc.resolve(tr.mapping.map($head.pos))));- return true;-}-function fixIndentation(code, indent) {- var _a = indent || (0, detect_indent_1.default)(code), amount = _a.amount, _b = _a.type, type = _b === void 0 ? "space" : _b;- var fixed = (0, redent_1.default)(code, amount, {- includeEmptyLines: false,- indent: type === "space" ? " " : "\t",- });- return { code: (0, strip_indent_1.default)(fixed), amount: amount, type: type };-}diff --git a/packages/editor/dist/extensions/codeblock/component.js b/packages/editor/dist/extensions/codeblock/component.jsdeleted file mode 100644index 8ec17e24a..000000000--- a/packages/editor/dist/extensions/codeblock/component.js+++ /dev/null@@ -1,212 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }- return new (P || (P = Promise))(function (resolve, reject) {- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }- step((generator = generator.apply(thisArg, _arguments || [])).next());- });-};-var __generator = (this && this.__generator) || function (thisArg, body) {- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;- function verb(n) { return function (v) { return step([n, v]); }; }- function step(op) {- if (f) throw new TypeError("Generator is already executing.");- while (_) try {- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;- if (y = 0, t) op = [op[0] & 2, t.value];- switch (op[0]) {- case 0: case 1: t = op; break;- case 4: _.label++; return { value: op[1], done: false };- case 5: _.label++; y = op[1]; op = [0]; continue;- case 7: op = _.ops.pop(); _.trys.pop(); continue;- default:- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }- if (t[2]) _.ops.pop();- _.trys.pop(); continue;- }- op = body.call(thisArg, _);- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };- }-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.CodeblockComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var loader_1 = require("./loader");-var core_1 = require("refractor/lib/core");-var rebass_1 = require("rebass");-var languages_json_1 = __importDefault(require("./languages.json"));-var forms_1 = require("@rebass/forms");-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var responsive_1 = require("../../components/responsive");-var popup_1 = require("../../toolbar/components/popup");-var button_1 = require("../../components/button");-function CodeblockComponent(props) {- var editor = props.editor, updateAttributes = props.updateAttributes, node = props.node, forwardRef = props.forwardRef;- var _a = node === null || node === void 0 ? void 0 : node.attrs, language = _a.language, indentLength = _a.indentLength, indentType = _a.indentType, caretPosition = _a.caretPosition;- var _b = __read((0, react_1.useState)(false), 2), isOpen = _b[0], setIsOpen = _b[1];- // const [caretPosition, setCaretPosition] = useState<CaretPosition>();- var toolbarRef = (0, react_1.useRef)(null);- var languageDefinition = languages_json_1.default.find(function (l) { var _a; return l.filename === language || ((_a = l.alias) === null || _a === void 0 ? void 0 : _a.some(function (a) { return a === language; })); });- (0, react_1.useEffect)(function () {- (function () {- return __awaiter(this, void 0, void 0, function () {- var syntax;- return __generator(this, function (_a) {- switch (_a.label) {- case 0:- if (!language || !languageDefinition || (0, loader_1.isLanguageLoaded)(language))- return [2 /*return*/];- return [4 /*yield*/, (0, loader_1.loadLanguage)(languageDefinition.filename)];- case 1:- syntax = _a.sent();- if (!syntax)- return [2 /*return*/];- core_1.refractor.register(syntax);- updateAttributes({- language: languageDefinition.filename,- });- return [2 /*return*/];- }- });- });- })();- }, [language]);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- flexDirection: "column",- borderRadius: "default",- overflow: "hidden",- } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, { ref: forwardRef, as: "pre", sx: {- "div, span.token, span.line-number-widget, span.line-number::before": {- fontFamily: "monospace",- fontSize: "code",- whiteSpace: "pre !important",- tabSize: 1,- },- position: "relative",- lineHeight: "20px",- bg: "codeBg",- color: "static",- overflowX: "auto",- display: "flex",- px: 2,- pt: 2,- pb: 1,- }, spellCheck: false }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ ref: toolbarRef, contentEditable: false, sx: {- bg: "codeBg",- alignItems: "center",- justifyContent: "end",- borderTop: "1px solid var(--codeBorder)",- } }, { children: [caretPosition ? ((0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "subBody", sx: { mr: 2, color: "codeFg" } }, { children: ["Line ", caretPosition.line, ", Column ", caretPosition.column, " ", caretPosition.selected- ? "(".concat(caretPosition.selected, " selected)")- : ""] }))) : null, (0, jsx_runtime_1.jsx)(button_1.Button, __assign({ variant: "icon", sx: { p: 1, mr: 1, ":hover": { bg: "codeSelection" } }, title: "Toggle indentation mode", onClick: function () {- editor.commands.changeCodeBlockIndentation({- type: indentType === "space" ? "tab" : "space",- amount: indentLength,- });- } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "subBody", sx: { color: "codeFg" } }, { children: [indentType === "space" ? "Spaces" : "Tabs", ": ", indentLength] })) })), (0, jsx_runtime_1.jsx)(button_1.Button, __assign({ variant: "icon", sx: {- p: 1,- mr: 1,- bg: isOpen ? "codeSelection" : "transparent",- ":hover": { bg: "codeSelection" },- }, onClick: function () {- setIsOpen(true);- }, title: "Change language" }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "subBody", spellCheck: false, sx: { color: "codeFg" } }, { children: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.title) || "Plaintext" })) }))] }))] })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, __assign({ isOpen: isOpen, onClose: function () {- setIsOpen(false);- // NOTE: for some reason the language selection action sheet- // does not return focus to the last focused position after- // closing. We have to set focusOnRender=false & manually- // restore focus. I think this has something to do with custom- // node views.- // TRY: perhaps use SelectionBasedReactNodeView?- editor.commands.focus();- }, focusOnRender: false, mobile: "sheet", desktop: "menu", position: {- target: toolbarRef.current || undefined,- align: "end",- isTargetAbsolute: true,- location: "top",- yOffset: 5,- }, title: "Change code block language" }, { children: (0, jsx_runtime_1.jsx)(LanguageSelector, { selectedLanguage: (languageDefinition === null || languageDefinition === void 0 ? void 0 : languageDefinition.filename) || "Plaintext", onLanguageSelected: function (language) {- updateAttributes({ language: language });- setIsOpen(false);- }, onClose: function () { return setIsOpen(false); } }) }))] }));-}-exports.CodeblockComponent = CodeblockComponent;-function LanguageSelector(props) {- var onLanguageSelected = props.onLanguageSelected, selectedLanguage = props.selectedLanguage, onClose = props.onClose;- var _a = __read((0, react_1.useState)(languages_json_1.default), 2), languages = _a[0], setLanguages = _a[1];- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ title: "Select language", onClose: onClose }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- flexDirection: "column",- height: 200,- width: ["auto", 300],- overflowY: "auto",- bg: "background",- } }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { onFocus: function () {- console.log("EHLLO!");- }, autoFocus: true, placeholder: "Search languages", sx: {- width: "auto",- position: "sticky",- top: 0,- bg: "background",- mx: 2,- p: "7px",- zIndex: 999,- }, onChange: function (e) {- if (!e.target.value)- return setLanguages(languages_json_1.default);- var query = e.target.value.toLowerCase();- setLanguages(languages_json_1.default.filter(function (lang) {- var _a;- return (lang.title.toLowerCase().indexOf(query) > -1 ||- ((_a = lang.alias) === null || _a === void 0 ? void 0 : _a.some(function (alias) { return alias.toLowerCase().indexOf(query) > -1; })));- }));- } }), (0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {- flexDirection: "column",- pt: 1,- mt: 1,- } }, { children: languages.map(function (lang) { return ((0, jsx_runtime_1.jsxs)(button_1.Button, __assign({ variant: "menuitem", sx: {- textAlign: "left",- py: 1,- display: "flex",- justifyContent: "space-between",- alignItems: "center",- }, onClick: function () { return onLanguageSelected(lang.filename); } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "body" }, { children: lang.title })), selectedLanguage === lang.filename ? ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.check, size: "small" })) : lang.alias ? ((0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "subBody", sx: { fontSize: "10px" } }, { children: lang.alias.slice(0, 3).join(", ") }))) : null] }), lang.title)); }) }))] })) })));-}diff --git a/packages/editor/dist/extensions/codeblock/highlighter.js b/packages/editor/dist/extensions/codeblock/highlighter.jsdeleted file mode 100644index 44503613e..000000000--- a/packages/editor/dist/extensions/codeblock/highlighter.js+++ /dev/null@@ -1,284 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.HighlighterPlugin = void 0;-var prosemirror_state_1 = require("prosemirror-state");-var prosemirror_view_1 = require("prosemirror-view");-var core_1 = require("@tiptap/core");-var core_2 = require("refractor/lib/core");-var codeblock_1 = require("./codeblock");-function parseNodes(nodes, className) {- if (className === void 0) { className = []; }- return nodes.reduce(function (result, node) {- if (node.type === "comment" || node.type === "doctype")- return result;- var classes = __spreadArray([], __read(className), false);- if (node.type === "element" && node.properties)- classes.push.apply(classes, __spreadArray([], __read(node.properties.className), false));- // this is required so that even plain text is wrapped in a span- // during highlighting. Without this, Prosemirror's selection acts- // weird for the first highlighted node/span.- else- classes.push("token", "text");- if (node.type === "element") {- result.push.apply(result, __spreadArray([], __read(parseNodes(node.children, classes)), false));- }- else {- result.push({ classes: classes, text: node.value });- }- return result;- }, []);-}-function getHighlightNodes(result) {- return result.children || [];-}-function getLineDecoration(from, line, total, isActive) {- var maxLength = String(total).length;- var attributes = {- class: "line-number ".concat(isActive ? "active" : ""),- "data-line": String(line).padEnd(maxLength, " "),- };- var spec = {- line: line,- active: isActive,- total: total,- from: from,- };- // Prosemirror has a selection issue with the widget decoration- // on the first line. To work around that we use inline decoration- // for the first line.- if (line === 1 ||- // Android Composition API (aka the virtual keyboard) doesn't behave well- // with Decoration widgets so we have to resort to inline line numbers.- isAndroid()) {- return prosemirror_view_1.Decoration.inline(from, from + 1, attributes, spec);- }- return prosemirror_view_1.Decoration.widget(from, function () {- var element = document.createElement("span");- element.classList.add("line-number-widget");- if (isActive)- element.classList.add("active");- element.innerHTML = attributes["data-line"];- return element;- }, __assign(__assign({}, spec), {- // should rerender when any of these change:- // 1. line number- // 2. line active state- // 3. the max length of all lines- key: "".concat(line, "-").concat(isActive ? "active" : "", "-").concat(maxLength) }));-}-function getDecorations(_a) {- var doc = _a.doc, name = _a.name, defaultLanguage = _a.defaultLanguage, caretPosition = _a.caretPosition;- var decorations = [];- var languages = core_2.refractor.listLanguages();- (0, core_1.findChildren)(doc, function (node) { return node.type.name === name; }).forEach(function (block) {- var e_1, _a;- var code = block.node.textContent;- var lines = (0, codeblock_1.toCodeLines)(code, block.pos);- try {- for (var _b = __values(lines || []), _c = _b.next(); !_c.done; _c = _b.next()) {- var line = _c.value;- var lineNumber = line.index + 1;- var isActive = lineNumber === (caretPosition === null || caretPosition === void 0 ? void 0 : caretPosition.line) && line.from === (caretPosition === null || caretPosition === void 0 ? void 0 : caretPosition.from);- var decoration = getLineDecoration(line.from, lineNumber, (lines === null || lines === void 0 ? void 0 : lines.length) || 0, isActive);- decorations.push(decoration);- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);- }- finally { if (e_1) throw e_1.error; }- }- var language = block.node.attrs.language || defaultLanguage;- var nodes = languages.includes(language)- ? getHighlightNodes(core_2.refractor.highlight(code, language))- : null;- if (!nodes)- return;- var from = block.pos + 1;- parseNodes(nodes).forEach(function (node) {- var to = from + node.text.length;- if (node.classes.length) {- var decoration = prosemirror_view_1.Decoration.inline(from, to, {- class: node.classes.join(" "),- });- decorations.push(decoration);- }- from = to;- });- });- return prosemirror_view_1.DecorationSet.create(doc, decorations);-}-function HighlighterPlugin(_a) {- var name = _a.name, defaultLanguage = _a.defaultLanguage;- var key = new prosemirror_state_1.PluginKey("highlighter");- return new prosemirror_state_1.Plugin({- key: key,- state: {- init: function () {- return prosemirror_view_1.DecorationSet.empty;- },- apply: function (transaction, decorationSet, oldState, newState) {- var oldNodeName = oldState.selection.$head.parent.type.name;- var newNodeName = newState.selection.$head.parent.type.name;- var oldNodes = (0, core_1.findChildren)(oldState.doc, function (node) { return node.type.name === name; });- var newNodes = (0, core_1.findChildren)(newState.doc, function (node) { return node.type.name === name; });- var position = (0, codeblock_1.toCaretPosition)(newState.selection);- // const isDocChanged =- // transaction.docChanged &&- // // TODO- // !transaction.steps.every((step) => step instanceof ReplaceAroundStep);- // console.log("Selection", transaction.docChanged, isDocChanged);- if (transaction.docChanged &&- // Apply decorations if:- // selection includes named node,- ([oldNodeName, newNodeName].includes(name) ||- // OR transaction adds/removes named node,- newNodes.length !== oldNodes.length ||- // OR transaction has changes that completely encapsulte a node- // (for example, a transaction that affects the entire document).- // Such transactions can happen during collab syncing via y-prosemirror, for example.- transaction.steps.some(function (step) {- return (step.from !== undefined &&- step.to !== undefined &&- oldNodes.some(function (node) {- return (node.pos >= step.from &&- node.pos + node.node.nodeSize <= step.to);- }));- }))) {- return getDecorations({- doc: transaction.doc,- name: name,- defaultLanguage: defaultLanguage,- caretPosition: position,- });- }- decorationSet = getActiveLineDecorations(transaction.doc, decorationSet, position);- return decorationSet.map(transaction.mapping, transaction.doc);- },- },- props: {- decorations: function (state) {- return key.getState(state);- },- },- appendTransaction: function (transactions, prevState, nextState) {- var tr = nextState.tr;- var modified = false;- var docChanged = transactions.some(function (transaction) { return transaction.docChanged; });- var selectionChanged = (nextState.selection.$from.parent.type.name === name ||- prevState.selection.$from.parent.type.name === name) &&- prevState.selection.$from.pos !== nextState.selection.$from.pos;- (0, core_1.findChildren)(nextState.doc, function (node) { return node.type.name === name; }).forEach(function (block) {- var node = block.node, pos = block.pos;- var attributes = __assign({}, node.attrs);- if (docChanged) {- var lines = (0, codeblock_1.toCodeLines)(node.textContent, pos);- attributes.lines = lines.slice();- }- if (selectionChanged) {- var position = (0, codeblock_1.toCaretPosition)(nextState.selection, docChanged ? (0, codeblock_1.toCodeLines)(node.textContent, pos) : undefined);- attributes.caretPosition = position;- }- if (docChanged || selectionChanged) {- tr.setNodeMarkup(pos, node.type, attributes);- modified = true;- }- });- return modified ? tr : null;- },- });-}-exports.HighlighterPlugin = HighlighterPlugin;-/**- * When `position` is undefined, all active line decorations- * are reset (e.g. when you focus out of the code block).- */-function getActiveLineDecorations(doc, decorations, position) {- var e_2, _a;- var lineDecorations = decorations.find(undefined, undefined, function (_a) {- var line = _a.line, active = _a.active, from = _a.from;- var isSame = position- ? line === position.line && from === position.from- : false;- return isSame || active;- });- if (!lineDecorations.length)- return decorations;- // we have to clone because prosemirror operates in-place- var cloned = lineDecorations.slice();- // remove old line decorations which inclue the current line decoration- // and the previous current line decoration. We'll replace these with- // new decorations.- decorations = decorations.remove(lineDecorations);- var newDecorations = [];- try {- for (var cloned_1 = __values(cloned), cloned_1_1 = cloned_1.next(); !cloned_1_1.done; cloned_1_1 = cloned_1.next()) {- var decoration = cloned_1_1.value;- var from = decoration.from, _b = decoration.spec, line = _b.line, total = _b.total;- var isActive = line === (position === null || position === void 0 ? void 0 : position.line);- var newDecoration = getLineDecoration(from, line, (position === null || position === void 0 ? void 0 : position.total) || total, isActive);- newDecorations.push(newDecoration);- }- }- catch (e_2_1) { e_2 = { error: e_2_1 }; }- finally {- try {- if (cloned_1_1 && !cloned_1_1.done && (_a = cloned_1.return)) _a.call(cloned_1);- }- finally { if (e_2) throw e_2.error; }- }- return decorations.add(doc, newDecorations);-}-function isAndroid() {- var ua = navigator.userAgent.toLowerCase();- return ua.indexOf("android") > -1; //&& ua.indexOf("mobile");-}diff --git a/packages/editor/dist/extensions/codeblock/loader.js b/packages/editor/dist/extensions/codeblock/loader.jsdeleted file mode 100644index 3ce51329f..000000000--- a/packages/editor/dist/extensions/codeblock/loader.js+++ /dev/null@@ -1,82 +0,0 @@-"use strict";-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }- return new (P || (P = Promise))(function (resolve, reject) {- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }- step((generator = generator.apply(thisArg, _arguments || [])).next());- });-};-var __generator = (this && this.__generator) || function (thisArg, body) {- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;- function verb(n) { return function (v) { return step([n, v]); }; }- function step(op) {- if (f) throw new TypeError("Generator is already executing.");- while (_) try {- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;- if (y = 0, t) op = [op[0] & 2, t.value];- switch (op[0]) {- case 0: case 1: t = op; break;- case 4: _.label++; return { value: op[1], done: false };- case 5: _.label++; y = op[1]; op = [0]; continue;- case 7: op = _.ops.pop(); _.trys.pop(); continue;- default:- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }- if (t[2]) _.ops.pop();- _.trys.pop(); continue;- }- op = body.call(thisArg, _);- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };- }-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.loadLanguage = exports.isLanguageLoaded = void 0;-var loadedLanguages = {};-function isLanguageLoaded(name) {- return !!loadedLanguages[name];-}-exports.isLanguageLoaded = isLanguageLoaded;-function loadLanguage(shortName) {- return __awaiter(this, void 0, void 0, function () {- var url, result;- return __generator(this, function (_a) {- switch (_a.label) {- case 0:- if (loadedLanguages[shortName])- return [2 /*return*/, loadedLanguages[shortName]];- url = "https://esm.sh/[email protected]/lang/".concat(shortName, ".js?bundle=true");- return [4 /*yield*/, loadScript(shortName, url)];- case 1:- result = _a.sent();- loadedLanguages[shortName] = result;- return [2 /*return*/, result];- }- });- });-}-exports.loadLanguage = loadLanguage;-function loadScript(id, url) {- return __awaiter(this, void 0, void 0, function () {- return __generator(this, function (_a) {- return [2 /*return*/, new Promise(function (resolve, reject) {- var callbackName = "on".concat(id, "Loaded");- var script = document.createElement("script");- script.type = "module";- script.innerHTML = "\n import LanguageDefinition from \"".concat(url, "\";\n if (window[\"").concat(callbackName, "\"]) {\n window[\"").concat(callbackName, "\"](LanguageDefinition)\n }\n");- window[callbackName] = function (lang) {- script.remove();- window[callbackName] = null;- resolve(lang);- };- // Append to the `head` element- document.head.appendChild(script);- })];- });- });-}diff --git a/packages/editor/dist/extensions/embed/embed.js b/packages/editor/dist/extensions/embed/embed.jsdeleted file mode 100644index 33a029a35..000000000--- a/packages/editor/dist/extensions/embed/embed.js+++ /dev/null@@ -1,90 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.EmbedNode = void 0;-var core_1 = require("@tiptap/core");-var react_1 = require("../react");-var component_1 = require("./component");-exports.EmbedNode = core_1.Node.create({- name: "embed",- content: "",- marks: "",- draggable: true,- addOptions: function () {- return {- HTMLAttributes: {},- };- },- group: function () {- return "block";- },- addAttributes: function () {- return {- src: {- default: null,- },- width: { default: null },- height: { default: null },- align: { default: "left" },- };- },- parseHTML: function () {- return [- {- tag: "iframe[src]",- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "iframe",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),- ];- },- addNodeView: function () {- return (0, react_1.createSelectionBasedNodeView)(component_1.EmbedComponent);- },- addCommands: function () {- var _this = this;- return {- insertEmbed: function (options) {- return function (_a) {- var commands = _a.commands;- return commands.insertContent({- type: _this.name,- attrs: options,- });- };- },- setEmbedAlignment: function (options) {- return function (_a) {- var commands = _a.commands;- return commands.updateAttributes(_this.name, __assign({}, options));- };- },- setEmbedSize: function (options) {- return function (_a) {- var commands = _a.commands;- return commands.updateAttributes(_this.name, __assign({}, options));- };- },- setEmbedSource: function (src) {- return function (_a) {- var commands = _a.commands;- return commands.updateAttributes(_this.name, { src: src });- };- },- };- },-});diff --git a/packages/editor/dist/extensions/fontsize/fontsize.js b/packages/editor/dist/extensions/fontsize/fontsize.jsdeleted file mode 100644index dea9e9912..000000000--- a/packages/editor/dist/extensions/fontsize/fontsize.js+++ /dev/null@@ -1,52 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-exports.FontSize = void 0;-var core_1 = require("@tiptap/core");-require("@tiptap/extension-text-style");-exports.FontSize = core_1.Extension.create({- name: "fontSize",- defaultOptions: {- types: ["textStyle"],- defaultFontSize: 16,- },- addGlobalAttributes: function () {- return [- {- types: this.options.types,- attributes: {- fontSize: {- default: "".concat(this.options.defaultFontSize, "px"),- parseHTML: function (element) { return element.style.fontSize; },- renderHTML: function (attributes) {- if (!attributes.fontSize) {- return {};- }- return {- style: "font-size: ".concat(attributes.fontSize),- };- },- },- },- },- ];- },- addCommands: function () {- return {- setFontSize: function (fontSize) {- return function (_a) {- var chain = _a.chain;- return chain().setMark("textStyle", { fontSize: fontSize }).run();- };- },- unsetFontSize: function () {- return function (_a) {- var chain = _a.chain;- return chain()- .setMark("textStyle", { fontSize: null })- .removeEmptyTextStyle()- .run();- };- },- };- },-});diff --git a/packages/editor/dist/extensions/image/component.js b/packages/editor/dist/extensions/image/component.jsdeleted file mode 100644index feef3a5ca..000000000--- a/packages/editor/dist/extensions/image/component.js+++ /dev/null@@ -1,165 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }- return new (P || (P = Promise))(function (resolve, reject) {- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }- step((generator = generator.apply(thisArg, _arguments || [])).next());- });-};-var __generator = (this && this.__generator) || function (thisArg, body) {- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;- function verb(n) { return function (v) { return step([n, v]); }; }- function step(op) {- if (f) throw new TypeError("Generator is already executing.");- while (_) try {- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;- if (y = 0, t) op = [op[0] & 2, t.value];- switch (op[0]) {- case 0: case 1: t = op; break;- case 4: _.label++; return { value: op[1], done: false };- case 5: _.label++; y = op[1]; op = [0]; continue;- case 7: op = _.ops.pop(); _.trys.pop(); continue;- default:- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }- if (t[2]) _.ops.pop();- _.trys.pop(); continue;- }- op = body.call(thisArg, _);- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };- }-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ImageComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var re_resizable_1 = require("re-resizable");-var react_1 = require("react");-var responsive_1 = require("../../components/responsive");-var toolbargroup_1 = require("../../toolbar/components/toolbargroup");-function ImageComponent(props) {- var _this = this;- var editor = props.editor, updateAttributes = props.updateAttributes, node = props.node, selected = props.selected;- var _a = node.attrs, src = _a.src, alt = _a.alt, title = _a.title, width = _a.width, height = _a.height, align = _a.align, float = _a.float;- var imageRef = (0, react_1.useRef)();- (0, react_1.useEffect)(function () {- (function () { return __awaiter(_this, void 0, void 0, function () {- var _a;- return __generator(this, function (_b) {- switch (_b.label) {- case 0:- if (!imageRef.current || !src)- return [2 /*return*/];- _a = imageRef.current;- return [4 /*yield*/, dataUriToBlobURL(src)];- case 1:- _a.src = _b.sent();- return [2 /*return*/];- }- });- }); })();- }, [src, imageRef]);- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ sx: {- display: float ? "block" : "flex",- justifyContent: float- ? "stretch"- : align === "center"- ? "center"- : align === "left"- ? "start"- : "end",- ":hover .drag-handle, :active .drag-handle": {- opacity: 1,- },- } }, { children: (0, jsx_runtime_1.jsxs)(re_resizable_1.Resizable, __assign({ enable: {- bottom: editor.isEditable,- left: editor.isEditable,- right: editor.isEditable,- top: editor.isEditable,- bottomLeft: editor.isEditable,- bottomRight: editor.isEditable,- topLeft: editor.isEditable,- topRight: editor.isEditable,- }, style: {- position: "relative",- float: float ? (align === "left" ? "left" : "right") : "none",- }, size: {- height: height || "auto",- width: width || "auto",- }, maxWidth: "100%", onResizeStop: function (e, direction, ref, d) {- updateAttributes({- width: ref.clientWidth,- height: ref.clientHeight,- });- }, lockAspectRatio: true }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ width: "100%", "data-drag-handle": true, draggable: true, sx: {- position: "relative",- justifyContent: "end",- borderTop: editor.isEditable- ? "20px solid var(--bgSecondary)"- : "none",- borderTopLeftRadius: "default",- borderTopRightRadius: "default",- borderColor: selected ? "border" : "bgSecondary",- cursor: "pointer",- ":hover": {- borderColor: "border",- },- } }, { children: (0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: { position: "relative", justifyContent: "end" } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {- position: "absolute",- top: -40,- mb: 2,- alignItems: "end",- } }, { children: (0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { editor: editor, tools: [- "imageAlignLeft",- "imageAlignCenter",- "imageAlignRight",- "imageProperties",- ], sx: {- boxShadow: "menu",- borderRadius: "default",- bg: "background",- } }) })) }))) }) })), (0, jsx_runtime_1.jsx)(rebass_1.Image, __assign({ "data-drag-image": true, ref: imageRef, alt: alt, src: "/placeholder.svg", title: title, width: "100%", height: "100%", sx: {- bg: "bgSecondary",- border: selected- ? "2px solid var(--primary)"- : "2px solid transparent",- borderRadius: "default",- } }, props))] })) })) }));-}-exports.ImageComponent = ImageComponent;-function dataUriToBlobURL(dataurl) {- return __awaiter(this, void 0, void 0, function () {- var response, blob;- return __generator(this, function (_a) {- switch (_a.label) {- case 0:- if (!dataurl.startsWith("data:image"))- return [2 /*return*/, dataurl];- return [4 /*yield*/, fetch(dataurl)];- case 1:- response = _a.sent();- return [4 /*yield*/, response.blob()];- case 2:- blob = _a.sent();- return [2 /*return*/, URL.createObjectURL(blob)];- }- });- });-}diff --git a/packages/editor/dist/extensions/image/image.js b/packages/editor/dist/extensions/image/image.jsdeleted file mode 100644index 6b0996a44..000000000--- a/packages/editor/dist/extensions/image/image.js+++ /dev/null@@ -1,174 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ImageNode = exports.inputRegex = void 0;-var core_1 = require("@tiptap/core");-var attachment_1 = require("../attachment");-var react_1 = require("../react");-var component_1 = require("./component");-exports.inputRegex = /(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/;-exports.ImageNode = core_1.Node.create({- name: "image",- addOptions: function () {- return {- inline: false,- allowBase64: false,- HTMLAttributes: {},- };- },- inline: function () {- return this.options.inline;- },- group: function () {- return this.options.inline ? "inline" : "block";- },- draggable: true,- addAttributes: function () {- return {- src: {- default: null,- },- alt: {- default: null,- },- title: {- default: null,- },- width: { default: null },- height: { default: null },- float: (0, attachment_1.getDataAttribute)("float", false),- align: (0, attachment_1.getDataAttribute)("align", "left"),- hash: (0, attachment_1.getDataAttribute)("hash"),- filename: (0, attachment_1.getDataAttribute)("filename"),- type: (0, attachment_1.getDataAttribute)("mime"),- size: (0, attachment_1.getDataAttribute)("size"),- };- },- parseHTML: function () {- return [- {- tag: this.options.allowBase64 ? "img" : 'img:not([src^="data:"])',- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "img",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes),- ];- },- addNodeView: function () {- return (0, react_1.createSelectionBasedNodeView)(component_1.ImageComponent);- },- addCommands: function () {- var _this = this;- return {- insertImage: function (options) {- return function (_a) {- var commands = _a.commands;- return commands.insertContent({- type: _this.name,- attrs: options,- });- };- },- setImageAlignment: function (options) {- return function (_a) {- var commands = _a.commands;- return commands.updateAttributes(_this.name, __assign({}, options));- };- },- setImageSize: function (options) {- return function (_a) {- var commands = _a.commands;- return commands.updateAttributes(_this.name, __assign({}, options));- };- },- updateImage: function (options) {- return function (_a) {- var e_1, _b;- var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;- var query = options.hash- ? { key: "hash", value: options.hash }- : options.src- ? { key: "src", value: options.src }- : null;- if (!query)- return false;- var images = (0, core_1.findChildren)(state.doc, function (node) {- return node.type.name === _this.name &&- node.attrs[query.key] === query.value;- });- try {- for (var images_1 = __values(images), images_1_1 = images_1.next(); !images_1_1.done; images_1_1 = images_1.next()) {- var image = images_1_1.value;- tr.setNodeMarkup(image.pos, image.node.type, __assign(__assign({}, image.node.attrs), options));- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (images_1_1 && !images_1_1.done && (_b = images_1.return)) _b.call(images_1);- }- finally { if (e_1) throw e_1.error; }- }- tr.setMeta("preventUpdate", true);- tr.setMeta("addToHistory", false);- if (dispatch)- dispatch(tr);- return true;- };- },- };- },- addInputRules: function () {- return [- (0, core_1.nodeInputRule)({- find: exports.inputRegex,- type: this.type,- getAttributes: function (match) {- var _a = __read(match, 5), alt = _a[2], src = _a[3], title = _a[4];- return { src: src, alt: alt, title: title };- },- }),- ];- },-});diff --git a/packages/editor/dist/extensions/listitem/listitem.js b/packages/editor/dist/extensions/listitem/listitem.jsdeleted file mode 100644index 88b59970a..000000000--- a/packages/editor/dist/extensions/listitem/listitem.js+++ /dev/null@@ -1,26 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ListItem = void 0;-var extension_list_item_1 = require("@tiptap/extension-list-item");-var commands_1 = require("./commands");-exports.ListItem = extension_list_item_1.ListItem.extend({- addKeyboardShortcuts: function () {- var _this = this;- var _a;- return __assign(__assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { Backspace: function (_a) {- var editor = _a.editor;- return (0, commands_1.onBackspacePressed)(editor, _this.name, _this.type);- } });- },-});diff --git a/packages/editor/dist/extensions/math/mathblock.js b/packages/editor/dist/extensions/math/mathblock.jsdeleted file mode 100644index 4e7862f14..000000000--- a/packages/editor/dist/extensions/math/mathblock.js+++ /dev/null@@ -1,45 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-exports.MathBlock = void 0;-var core_1 = require("@tiptap/core");-var prosemirror_inputrules_1 = require("prosemirror-inputrules");-var plugin_1 = require("./plugin");-exports.MathBlock = core_1.Node.create({- name: "mathBlock",- group: "block math",- content: "text*",- atom: true,- code: true,- parseHTML: function () {- return [- {- tag: "div[class*='math-block']", // important!- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "div",- (0, core_1.mergeAttributes)({ class: "math-block math-node" }, HTMLAttributes),- 0,- ];- },- addCommands: function () {- var _this = this;- return {- insertMathBlock: function () {- return function (_a) {- var state = _a.state, dispatch = _a.dispatch, view = _a.view;- return (0, plugin_1.insertMathNode)(_this.type)(state, dispatch, view);- };- },- };- },- addProseMirrorPlugins: function () {- var inputRulePlugin = (0, prosemirror_inputrules_1.inputRules)({- rules: [(0, plugin_1.makeBlockMathInputRule)(plugin_1.REGEX_BLOCK_MATH_DOLLARS, this.type)],- });- return [inputRulePlugin];- },-});diff --git a/packages/editor/dist/extensions/math/plugin/renderers/katex.js b/packages/editor/dist/extensions/math/plugin/renderers/katex.jsdeleted file mode 100644index c0189ba4c..000000000--- a/packages/editor/dist/extensions/math/plugin/renderers/katex.js+++ /dev/null@@ -1,25 +0,0 @@-"use strict";-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.KatexRenderer = void 0;-var katex_1 = __importDefault(require("katex"));-// Chemistry formulas support-require("katex/contrib/mhchem/mhchem");-exports.KatexRenderer = {- inline: function (text, element) {- katex_1.default.render(text, element, {- displayMode: false,- globalGroup: true,- throwOnError: false,- });- },- block: function (text, element) {- katex_1.default.render(text, element, {- displayMode: true,- globalGroup: true,- throwOnError: false,- });- },-};diff --git a/packages/editor/dist/extensions/math/plugin/utils/text-serializer.js b/packages/editor/dist/extensions/math/plugin/utils/text-serializer.jsdeleted file mode 100644index 7b7c2a335..000000000--- a/packages/editor/dist/extensions/math/plugin/utils/text-serializer.js+++ /dev/null@@ -1,74 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.mathSerializer = void 0;-var ProseMirrorTextSerializer = /** @class */ (function () {- function ProseMirrorTextSerializer(fns, base) {- // use base serializer as a fallback- this.nodes = __assign(__assign({}, base === null || base === void 0 ? void 0 : base.nodes), fns.nodes);- this.marks = __assign(__assign({}, base === null || base === void 0 ? void 0 : base.marks), fns.marks);- }- ProseMirrorTextSerializer.prototype.serializeFragment = function (fragment) {- var _this = this;- // adapted from the undocumented `Fragment.textBetween` function- // https://github.com/ProseMirror/prosemirror-model/blob/eef20c8c6dbf841b1d70859df5d59c21b5108a4f/src/fragment.js#L46- var blockSeparator = "\n\n";- var leafText = undefined;- var text = "";- var separated = true;- var from = 0;- var to = fragment.size;- fragment.nodesBetween(from, to, function (node, pos) {- var _a;- // check if one of our custom serializers handles this node- var serialized = _this.serializeNode(node);- if (serialized !== null) {- text += serialized;- return false;- }- if (node.isText) {- text += ((_a = node.text) === null || _a === void 0 ? void 0 : _a.slice(Math.max(from, pos) - pos, to - pos)) || "";- separated = !blockSeparator;- }- else if (node.isLeaf && leafText) {- text += leafText;- separated = !blockSeparator;- }- else if (!separated && node.isBlock) {- text += blockSeparator;- separated = true;- }- }, 0);- return text;- };- ProseMirrorTextSerializer.prototype.serializeSlice = function (slice) {- return this.serializeFragment(slice.content);- };- ProseMirrorTextSerializer.prototype.serializeNode = function (node) {- // check if one of our custom serializers handles this node- var nodeSerializer = this.nodes[node.type.name];- if (nodeSerializer !== undefined) {- return nodeSerializer(node);- }- else {- return null;- }- };- return ProseMirrorTextSerializer;-}());-exports.mathSerializer = new ProseMirrorTextSerializer({- nodes: {- math_inline: function (node) { return "$".concat(node.textContent, "$"); },- math_display: function (node) { return "\n\n$$\n".concat(node.textContent, "\n$$"); },- },-});diff --git a/packages/editor/dist/extensions/outlinelist/outlinelist.js b/packages/editor/dist/extensions/outlinelist/outlinelist.jsdeleted file mode 100644index 193404c13..000000000--- a/packages/editor/dist/extensions/outlinelist/outlinelist.js+++ /dev/null@@ -1,84 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-exports.OutlineList = exports.inputRegex = void 0;-var core_1 = require("@tiptap/core");-var react_1 = require("../react");-var component_1 = require("./component");-exports.inputRegex = /^\s*(-o)\s$/;-var outlineListItemName = "outlineListItem";-exports.OutlineList = core_1.Node.create({- name: "outlineList",- addOptions: function () {- return {- HTMLAttributes: {},- };- },- addAttributes: function () {- return {- collapsed: {- default: false,- keepOnSplit: false,- parseHTML: function (element) { return element.dataset.collapsed === "true"; },- renderHTML: function (attributes) { return ({- "data-collapsed": attributes.collapsed === true,- }); },- },- };- },- group: "block list",- content: "".concat(outlineListItemName, "+"),- parseHTML: function () {- return [- {- tag: "ul[data-type=\"".concat(this.name, "\"]"),- priority: 52,- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "ul",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {- "data-type": this.name,- }),- 0,- ];- },- addCommands: function () {- var _this = this;- return {- toggleOutlineList: function () {- return function (_a) {- var commands = _a.commands;- return commands.toggleList(_this.name, outlineListItemName);- };- },- };- },- addKeyboardShortcuts: function () {- var _this = this;- return {- "Mod-Shift-O": function () { return _this.editor.commands.toggleOutlineList(); },- };- },- addInputRules: function () {- return [- (0, core_1.wrappingInputRule)({- find: exports.inputRegex,- type: this.type,- }),- ];- },- addNodeView: function () {- var _this = this;- return (0, react_1.createNodeView)(component_1.OutlineListComponent, {- contentDOMFactory: function () {- var content = document.createElement("ul");- content.classList.add("".concat(_this.name.toLowerCase(), "-content-wrapper"));- content.style.whiteSpace = "inherit";- return { dom: content };- },- });- },-});diff --git a/packages/editor/dist/extensions/outlinelistitem/outlinelistitem.js b/packages/editor/dist/extensions/outlinelistitem/outlinelistitem.jsdeleted file mode 100644index ac1e5684b..000000000--- a/packages/editor/dist/extensions/outlinelistitem/outlinelistitem.js+++ /dev/null@@ -1,129 +0,0 @@-"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.OutlineListItem = void 0;-var core_1 = require("@tiptap/core");-var prosemirror_utils_1 = require("prosemirror-utils");-var commands_1 = require("../list-item/commands");-var outlinelist_1 = require("../outline-list/outlinelist");-var react_1 = require("../react");-var component_1 = require("./component");-exports.OutlineListItem = core_1.Node.create({- name: "outlineListItem",- addOptions: function () {- return {- HTMLAttributes: {},- };- },- content: "heading* block*",- defining: true,- parseHTML: function () {- return [- {- tag: "li[data-type=\"".concat(this.name, "\"]"),- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "li",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {- "data-type": this.name,- }),- 0,- ];- },- addKeyboardShortcuts: function () {- var _this = this;- return {- "Mod-Space": function (_a) {- var editor = _a.editor;- var subList = findSublist(editor, _this.type);- if (!subList)- return false;- var isCollapsed = subList.isCollapsed, subListPos = subList.subListPos;- return _this.editor.commands.toggleOutlineCollapse(subListPos, !isCollapsed);- },- Enter: function (_a) {- var editor = _a.editor;- var subList = findSublist(editor, _this.type);- if (!subList)- return false;- var isCollapsed = subList.isCollapsed, subListPos = subList.subListPos;- if (isCollapsed) {- return _this.editor.commands.toggleOutlineCollapse(subListPos, false);- }- return _this.editor.commands.splitListItem(_this.name);- },- Tab: function () { return _this.editor.commands.sinkListItem(_this.name); },- "Shift-Tab": function () { return _this.editor.commands.liftListItem(_this.name); },- Backspace: function (_a) {- var editor = _a.editor;- return (0, commands_1.onBackspacePressed)(editor, _this.name, _this.type);- },- };- },- addCommands: function () {- return {- toggleOutlineCollapse: function (pos, state) {- return function (_a) {- var tr = _a.tr;- tr.setNodeMarkup(pos, undefined, {- collapsed: state,- });- return true;- };- },- };- },- addNodeView: function () {- return (0, react_1.createNodeView)(component_1.OutlineListItemComponent, {- contentDOMFactory: true,- // wrapperFactory: () => document.createElement("li"),- });- },-});-function findSublist(editor, type) {- var _a, _b;- var selection = editor.state.selection;- var $from = selection.$from;- var listItem = (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)($from, type);- if (!listItem)- return false;- var _c = __read((0, core_1.findChildren)(listItem.node, function (node) { return node.type.name === outlinelist_1.OutlineList.name; }), 1), subList = _c[0];- if (!subList)- return false;- var isNested = ((_a = subList === null || subList === void 0 ? void 0 : subList.node) === null || _a === void 0 ? void 0 : _a.type.name) === outlinelist_1.OutlineList.name;- var isCollapsed = (_b = subList === null || subList === void 0 ? void 0 : subList.node) === null || _b === void 0 ? void 0 : _b.attrs.collapsed;- var subListPos = listItem.pos + subList.pos + 1;- return { isCollapsed: isCollapsed, isNested: isNested, subListPos: subListPos };- // return (- // this.editor- // .chain()- // .command(({ tr }) => {- // tr.setNodeMarkup(listItem.pos + subList.pos + 1, undefined, {- // collapsed: !isCollapsed,- // });- // return true;- // })- // //.setTextSelection(listItem.pos + subList.pos + 1)- // //.splitListItem(this.name)- // .run()- // );-}diff --git a/packages/editor/dist/extensions/react/plugin.js b/packages/editor/dist/extensions/react/plugin.jsdeleted file mode 100644index 940b26d20..000000000--- a/packages/editor/dist/extensions/react/plugin.js+++ /dev/null@@ -1,48 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-exports.NodeViewSelectionNotifier = exports.NodeViewSelectionNotifierPlugin = exports.stateKey = exports.ReactNodeViewState = void 0;-var prosemirror_state_1 = require("prosemirror-state");-var core_1 = require("@tiptap/core");-var ReactNodeViewState = /** @class */ (function () {- function ReactNodeViewState() {- this.changeHandlers = [];- this.changeHandlers = [];- }- ReactNodeViewState.prototype.subscribe = function (cb) {- this.changeHandlers.push(cb);- };- ReactNodeViewState.prototype.unsubscribe = function (cb) {- this.changeHandlers = this.changeHandlers.filter(function (ch) { return ch !== cb; });- };- ReactNodeViewState.prototype.notifyNewSelection = function (fromPos, toPos) {- this.changeHandlers.forEach(function (cb) { return cb(fromPos, toPos); });- };- return ReactNodeViewState;-}());-exports.ReactNodeViewState = ReactNodeViewState;-exports.stateKey = new prosemirror_state_1.PluginKey("reactNodeView");-exports.NodeViewSelectionNotifierPlugin = new prosemirror_state_1.Plugin({- state: {- init: function () {- return new ReactNodeViewState();- },- apply: function (_tr, pluginState) {- return pluginState;- },- },- key: exports.stateKey,- view: function (view) {- var pluginState = exports.stateKey.getState(view.state);- return {- update: function (view) {- var _a = view.state.selection, from = _a.from, to = _a.to;- pluginState.notifyNewSelection(from, to);- },- };- },-});-exports.NodeViewSelectionNotifier = core_1.Extension.create({- addProseMirrorPlugins: function () {- return [exports.NodeViewSelectionNotifierPlugin];- },-});diff --git a/packages/editor/dist/extensions/react/reactportalprovider.js b/packages/editor/dist/extensions/react/reactportalprovider.jsdeleted file mode 100644index 47a36204e..000000000--- a/packages/editor/dist/extensions/react/reactportalprovider.js+++ /dev/null@@ -1,153 +0,0 @@-"use strict";-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {- if (k2 === undefined) k2 = k;- var desc = Object.getOwnPropertyDescriptor(m, k);- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {- desc = { enumerable: true, get: function() { return m[k]; } };- }- Object.defineProperty(o, k2, desc);-}) : (function(o, m, k, k2) {- if (k2 === undefined) k2 = k;- o[k2] = m[k];-}));-var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {- Object.defineProperty(o, "default", { enumerable: true, value: v });-}) : function(o, v) {- o["default"] = v;-});-var __importStar = (this && this.__importStar) || function (mod) {- if (mod && mod.__esModule) return mod;- var result = {};- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);- __setModuleDefault(result, mod);- return result;-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.PortalRenderer = exports.PortalProvider = exports.usePortalProvider = exports.PortalProviderAPI = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importStar(require("react"));-var react_dom_1 = require("react-dom");-var eventdispatcher_1 = require("./eventdispatcher");-var PortalProviderAPI = /** @class */ (function (_super) {- __extends(PortalProviderAPI, _super);- function PortalProviderAPI() {- var _this = _super.call(this) || this;- _this.portals = new Map();- _this.setContext = function (context) {- _this.context = context;- };- return _this;- }- PortalProviderAPI.prototype.render = function (children, container) {- this.portals.set(container, {- children: children,- });- var wrappedChildren = children();- (0, react_dom_1.unstable_renderSubtreeIntoContainer)(this.context, wrappedChildren, container);- };- // TODO: until https://product-fabric.atlassian.net/browse/ED-5013- // we (unfortunately) need to re-render to pass down any updated context.- // selectively do this for nodeviews that opt-in via `hasAnalyticsContext`- PortalProviderAPI.prototype.forceUpdate = function () { };- PortalProviderAPI.prototype.remove = function (container) {- this.portals.delete(container);- // There is a race condition that can happen caused by Prosemirror vs React,- // where Prosemirror removes the container from the DOM before React gets- // around to removing the child from the container- // This will throw a NotFoundError: The node to be removed is not a child of this node- // Both Prosemirror and React remove the elements asynchronously, and in edge- // cases Prosemirror beats React- try {- (0, react_dom_1.unmountComponentAtNode)(container);- }- catch (error) {- // IGNORE console.error(error);- }- };- return PortalProviderAPI;-}(eventdispatcher_1.EventDispatcher));-exports.PortalProviderAPI = PortalProviderAPI;-var PortalProviderContext = react_1.default.createContext(undefined);-function usePortalProvider() {- return (0, react_1.useContext)(PortalProviderContext);-}-exports.usePortalProvider = usePortalProvider;-var PortalProvider = /** @class */ (function (_super) {- __extends(PortalProvider, _super);- function PortalProvider(props) {- var _this = _super.call(this, props) || this;- _this.portalProviderAPI = new PortalProviderAPI();- return _this;- }- PortalProvider.prototype.render = function () {- return ((0, jsx_runtime_1.jsxs)(PortalProviderContext.Provider, __assign({ value: this.portalProviderAPI }, { children: [this.props.children, (0, jsx_runtime_1.jsx)(PortalRenderer, { portalProviderAPI: this.portalProviderAPI })] })));- };- PortalProvider.prototype.componentDidUpdate = function () {- this.portalProviderAPI.forceUpdate();- };- PortalProvider.displayName = "PortalProvider";- return PortalProvider;-}(react_1.default.Component));-exports.PortalProvider = PortalProvider;-var PortalRenderer = /** @class */ (function (_super) {- __extends(PortalRenderer, _super);- function PortalRenderer(props) {- var _this = _super.call(this, props) || this;- _this.handleUpdate = function (portals) { return _this.setState({ portals: portals }); };- props.portalProviderAPI.setContext(_this);- props.portalProviderAPI.on("update", _this.handleUpdate);- _this.state = { portals: new Map() };- return _this;- }- PortalRenderer.prototype.render = function () {- var portals = this.state.portals;- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: Array.from(portals.entries()).map(function (_a) {- var _b = __read(_a, 2), container = _b[0], children = _b[1];- return (0, react_dom_1.createPortal)(children, container);- }) }));- };- return PortalRenderer;-}(react_1.default.Component));-exports.PortalRenderer = PortalRenderer;diff --git a/packages/editor/dist/extensions/react/selectionbasedreactnodeview.js b/packages/editor/dist/extensions/react/selectionbasedreactnodeview.jsdeleted file mode 100644index e4564a57c..000000000--- a/packages/editor/dist/extensions/react/selectionbasedreactnodeview.js+++ /dev/null@@ -1,184 +0,0 @@-"use strict";-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.createSelectionBasedNodeView = exports.SelectionBasedNodeView = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var prosemirror_view_1 = require("prosemirror-view");-var prosemirror_state_1 = require("prosemirror-state");-var plugin_1 = require("./plugin");-var reactnodeview_1 = require("./reactnodeview");-var emotion_theming_1 = require("emotion-theming");-/**- * A ReactNodeView that handles React components sensitive- * to selection changes.- *- * If the selection changes, it will attempt to re-render the- * React component. Otherwise it does nothing.- *- * You can subclass `viewShouldUpdate` to include other- * props that your component might want to consider before- * entering the React lifecycle. These are usually props you- * compare in `shouldComponentUpdate`.- *- * An example:- *- * ```- * viewShouldUpdate(nextNode) {- * if (nextNode.attrs !== this.node.attrs) {- * return true;- * }- *- * return super.viewShouldUpdate(nextNode);- * }```- */-var SelectionBasedNodeView = /** @class */ (function (_super) {- __extends(SelectionBasedNodeView, _super);- function SelectionBasedNodeView(node, editor, getPos, options) {- var _this = _super.call(this, node, editor, getPos, options) || this;- _this.pos = -1;- _this.isNodeInsideSelection = function (from, to, pos, posEnd) {- var _a;- (_a = _this.getPositionsWithDefault(pos, posEnd), pos = _a.pos, posEnd = _a.posEnd);- if (typeof pos !== "number" || typeof posEnd !== "number") {- return false;- }- return from <= pos && to >= posEnd;- };- _this.isSelectionInsideNode = function (from, to, pos, posEnd) {- var _a;- (_a = _this.getPositionsWithDefault(pos, posEnd), pos = _a.pos, posEnd = _a.posEnd);- if (typeof pos !== "number" || typeof posEnd !== "number") {- return false;- }- return pos < from && to < posEnd;- };- _this.isSelectedNode = function (selection) {- if (selection instanceof prosemirror_state_1.NodeSelection) {- var _a = _this.editor.view.state.selection, from = _a.from, to = _a.to;- return (selection.node === _this.node ||- // If nodes are not the same object, we check if they are referring to the same document node- (_this.pos === from &&- _this.posEnd === to &&- selection.node.eq(_this.node)));- }- return false;- };- _this.insideSelection = function () {- var _a = _this.editor.view.state.selection, from = _a.from, to = _a.to;- return (_this.isSelectedNode(_this.editor.view.state.selection) ||- _this.isSelectionInsideNode(from, to));- };- _this.nodeInsideSelection = function () {- var selection = _this.editor.view.state.selection;- var from = selection.from, to = selection.to;- return (_this.isSelectedNode(selection) || _this.isNodeInsideSelection(from, to));- };- _this.onSelectionChange = function () {- _this.update(_this.node, [], prosemirror_view_1.DecorationSet.empty);- };- _this.updatePos();- _this.oldSelection = editor.view.state.selection;- _this.selectionChangeState = plugin_1.stateKey.getState(_this.editor.view.state);- _this.selectionChangeState.subscribe(_this.onSelectionChange);- return _this;- }- SelectionBasedNodeView.prototype.render = function (props, forwardRef) {- var _this = this;- if (props === void 0) { props = {}; }- if (!this.options.component)- return null;- var theme = this.editor.storage.theme;- var isSelected = this.editor.isEditable &&- (this.insideSelection() || this.nodeInsideSelection());- return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, __assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(this.options.component, __assign({}, props, { editor: this.editor, getPos: this.getPos, node: this.node, forwardRef: forwardRef, selected: isSelected, updateAttributes: function (attr) { return _this.updateAttributes(attr, _this.pos); } })) })));- };- /**- * Update current node's start and end positions.- *- * Prefer `this.pos` rather than getPos(), because calling getPos is- * expensive, unless you know you're definitely going to render.- */- SelectionBasedNodeView.prototype.updatePos = function () {- if (typeof this.getPos === "boolean") {- return;- }- this.pos = this.getPos();- this.posEnd = this.pos + this.node.nodeSize;- };- SelectionBasedNodeView.prototype.getPositionsWithDefault = function (pos, posEnd) {- return {- pos: typeof pos !== "number" ? this.pos : pos,- posEnd: typeof posEnd !== "number" ? this.posEnd : posEnd,- };- };- SelectionBasedNodeView.prototype.viewShouldUpdate = function (nextNode) {- if (_super.prototype.viewShouldUpdate.call(this, nextNode))- return true;- var selection = this.editor.view.state.selection;- // update selection- var oldSelection = this.oldSelection;- this.oldSelection = selection;- // update cached positions- var _a = this, oldPos = _a.pos, oldPosEnd = _a.posEnd;- this.updatePos();- var from = selection.from, to = selection.to;- var oldFrom = oldSelection.from, oldTo = oldSelection.to;- if (this.node.type.spec.selectable) {- var newNodeSelection = selection instanceof prosemirror_state_1.NodeSelection && selection.from === this.pos;- var oldNodeSelection = oldSelection instanceof prosemirror_state_1.NodeSelection && oldSelection.from === this.pos;- if ((newNodeSelection && !oldNodeSelection) ||- (oldNodeSelection && !newNodeSelection)) {- return true;- }- }- var movedInToSelection = this.isNodeInsideSelection(from, to) &&- !this.isNodeInsideSelection(oldFrom, oldTo);- var movedOutOfSelection = !this.isNodeInsideSelection(from, to) &&- this.isNodeInsideSelection(oldFrom, oldTo);- var moveOutFromOldSelection = this.isNodeInsideSelection(from, to, oldPos, oldPosEnd) &&- !this.isNodeInsideSelection(from, to);- if (movedInToSelection || movedOutOfSelection || moveOutFromOldSelection) {- return true;- }- return false;- };- SelectionBasedNodeView.prototype.destroy = function () {- this.selectionChangeState.unsubscribe(this.onSelectionChange);- _super.prototype.destroy.call(this);- };- return SelectionBasedNodeView;-}(reactnodeview_1.ReactNodeView));-exports.SelectionBasedNodeView = SelectionBasedNodeView;-function createSelectionBasedNodeView(component, options) {- return function (_a) {- var node = _a.node, getPos = _a.getPos, editor = _a.editor;- var _getPos = function () { return (typeof getPos === "boolean" ? -1 : getPos()); };- return new SelectionBasedNodeView(node, editor, _getPos, __assign(__assign({}, options), { component: component })).init();- };-}-exports.createSelectionBasedNodeView = createSelectionBasedNodeView;diff --git a/packages/editor/dist/extensions/searchreplace/searchreplace.js b/packages/editor/dist/extensions/searchreplace/searchreplace.jsdeleted file mode 100644index fca8e9bba..000000000--- a/packages/editor/dist/extensions/searchreplace/searchreplace.js+++ /dev/null@@ -1,286 +0,0 @@-"use strict";-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.SearchReplace = void 0;-var core_1 = require("@tiptap/core");-var prosemirror_view_1 = require("prosemirror-view");-var prosemirror_state_1 = require("prosemirror-state");-var updateView = function (state, dispatch) { return dispatch(state.tr); };-var regex = function (s, settings) {- var enableRegex = settings.enableRegex, matchCase = settings.matchCase, matchWholeWord = settings.matchWholeWord;- var boundary = matchWholeWord ? "\\b" : "";- console.log(boundary);- return RegExp(boundary +- (enableRegex ? s : s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&")) +- boundary, matchCase ? "gu" : "gui");-};-function searchDocument(doc, searchResultClass, searchTerm) {- var e_1, _a, e_2, _b, e_3, _c;- if (!searchTerm)- return { decorationSet: prosemirror_view_1.DecorationSet.empty, results: [] };- var decorations = [];- var results = [];- var index = 0;- var textNodesWithPosition = [];- doc === null || doc === void 0 ? void 0 : doc.descendants(function (node, pos) {- if (node.isText) {- if (textNodesWithPosition[index]) {- textNodesWithPosition[index] = {- text: textNodesWithPosition[index].text + node.text,- pos: textNodesWithPosition[index].pos,- };- }- else {- textNodesWithPosition[index] = {- text: node.text || "",- pos: pos,- };- }- }- else {- index += 1;- }- });- textNodesWithPosition = textNodesWithPosition.filter(Boolean);- try {- for (var textNodesWithPosition_1 = __values(textNodesWithPosition), textNodesWithPosition_1_1 = textNodesWithPosition_1.next(); !textNodesWithPosition_1_1.done; textNodesWithPosition_1_1 = textNodesWithPosition_1.next()) {- var _d = textNodesWithPosition_1_1.value, text = _d.text, pos = _d.pos;- var matches = text.matchAll(searchTerm);- try {- for (var matches_1 = (e_2 = void 0, __values(matches)), matches_1_1 = matches_1.next(); !matches_1_1.done; matches_1_1 = matches_1.next()) {- var m = matches_1_1.value;- if (m[0] === "")- break;- if (m.index !== undefined) {- results.push({- from: pos + m.index,- to: pos + m.index + m[0].length,- });- }- }- }- catch (e_2_1) { e_2 = { error: e_2_1 }; }- finally {- try {- if (matches_1_1 && !matches_1_1.done && (_b = matches_1.return)) _b.call(matches_1);- }- finally { if (e_2) throw e_2.error; }- }- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (textNodesWithPosition_1_1 && !textNodesWithPosition_1_1.done && (_a = textNodesWithPosition_1.return)) _a.call(textNodesWithPosition_1);- }- finally { if (e_1) throw e_1.error; }- }- try {- for (var results_1 = __values(results), results_1_1 = results_1.next(); !results_1_1.done; results_1_1 = results_1.next()) {- var _e = results_1_1.value, from = _e.from, to = _e.to;- decorations.push(prosemirror_view_1.Decoration.inline(from, to, { class: searchResultClass }));- }- }- catch (e_3_1) { e_3 = { error: e_3_1 }; }- finally {- try {- if (results_1_1 && !results_1_1.done && (_c = results_1.return)) _c.call(results_1);- }- finally { if (e_3) throw e_3.error; }- }- return {- decorationSet: prosemirror_view_1.DecorationSet.create(doc, decorations),- results: results,- };-}-var replaceAll = function (replaceTerm, results, tr) {- var offset = 0;- if (!results.length)- return;- var map = tr.mapping;- for (var i = 0; i < results.length; i += 1) {- var _a = results[i], from = _a.from, to = _a.to;- tr.insertText(replaceTerm, from, to);- if (i + 1 < results.length) {- var _b = results[i + 1], from_1 = _b.from, to_1 = _b.to;- results[i + 1] = {- from: map.map(from_1),- to: map.map(to_1),- };- }- }- return tr;-};-exports.SearchReplace = core_1.Extension.create({- name: "searchreplace",- addOptions: function () {- return {- searchResultClass: "search-result",- };- },- addCommands: function () {- var _this = this;- return {- startSearch: function () {- return function (_a) {- var state = _a.state;- _this.storage.isSearching = true;- if (!state.selection.empty) {- _this.storage.selectedText = state.doc.textBetween(state.selection.$from.pos, state.selection.$to.pos);- }- return true;- };- },- endSearch: function () {- return function (_a) {- var state = _a.state, dispatch = _a.dispatch;- _this.storage.isSearching = false;- _this.storage.searchTerm = "";- updateView(state, dispatch);- return true;- };- },- search: function (term, options) {- return function (_a) {- var state = _a.state, dispatch = _a.dispatch;- _this.storage.searchTerm = term;- _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;- };- },- moveToNextResult: function () {- return function (_a) {- var chain = _a.chain;- var _b = _this.storage, selectedIndex = _b.selectedIndex, results = _b.results;- if (!results || results.length <= 0)- return false;- var nextIndex = selectedIndex + 1;- if (isNaN(nextIndex) || nextIndex >= results.length)- nextIndex = 0;- var _c = results[nextIndex], from = _c.from, to = _c.to;- console.log("[moveToNextResult]", from, to);- var result = chain()- .focus(undefined, { scrollIntoView: true })- .setTextSelection({ from: from, to: to })- .run();- if (result)- _this.storage.selectedIndex = nextIndex;- return result;- };- },- moveToPreviousResult: function () {- return function (_a) {- var chain = _a.chain;- var _b = _this.storage, selectedIndex = _b.selectedIndex, results = _b.results;- if (!results || results.length <= 0)- return false;- var prevIndex = selectedIndex - 1;- if (isNaN(prevIndex) || prevIndex < 0)- prevIndex = results.length - 1;- var _c = results[prevIndex], from = _c.from, to = _c.to;- var result = chain()- .focus(undefined, { scrollIntoView: true })- .setTextSelection({ from: from, to: to })- .run();- if (result)- _this.storage.selectedIndex = prevIndex;- return result;- };- },- replace: function (term) {- 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 || results.length <= 0)- return false;- var index = selectedIndex === undefined ? 0 : selectedIndex;- var _c = results[index], from = _c.from, to = _c.to;- tr.insertText(term, from, to);- if (index + 1 < results.length) {- var _d = results[index + 1], from_2 = _d.from, to_2 = _d.to;- var nextResult = (results[index + 1] = {- from: tr.mapping.map(from_2),- to: tr.mapping.map(to_2),- });- commands.focus();- tr.setSelection(new prosemirror_state_1.TextSelection(tr.doc.resolve(nextResult.from), tr.doc.resolve(nextResult.to)));- }- dispatch(tr);- results.splice(index, 1);- return true;- };- },- replaceAll: function (term) {- return function (_a) {- var state = _a.state, tr = _a.tr, dispatch = _a.dispatch;- if (!dispatch)- return false;- var results = _this.storage.results;- if (!dispatch || !results || results.length <= 0)- return false;- dispatch(replaceAll(term, results, tr));- return true;- };- },- };- },- addKeyboardShortcuts: function () {- return {- "Mod-f": function (_a) {- var editor = _a.editor;- return editor.commands.startSearch();- },- Escape: function (_a) {- var editor = _a.editor;- return editor.commands.endSearch();- },- };- },- addProseMirrorPlugins: function () {- var _this = this;- var key = new prosemirror_state_1.PluginKey("searchreplace");- return [- new prosemirror_state_1.Plugin({- key: key,- state: {- init: function () {- return prosemirror_view_1.DecorationSet.empty;- },- apply: function (_a) {- var doc = _a.doc, docChanged = _a.docChanged, setSelection = _a.setSelection;- var _b = _this.storage, searchTerm = _b.searchTerm, enableRegex = _b.enableRegex, matchCase = _b.matchCase, matchWholeWord = _b.matchWholeWord;- var searchResultClass = _this.options.searchResultClass;- if (docChanged || searchTerm) {- var searchRegex = searchTerm- ? regex(searchTerm, { enableRegex: enableRegex, matchCase: matchCase, matchWholeWord: matchWholeWord })- : undefined;- var _c = searchDocument(doc, searchResultClass, searchRegex), decorationSet = _c.decorationSet, results = _c.results;- _this.storage.results = results;- return decorationSet;- }- return prosemirror_view_1.DecorationSet.empty;- },- },- props: {- decorations: function (state) {- return key.getState(state);- },- },- }),- ];- },-});diff --git a/packages/editor/dist/extensions/table/component.js b/packages/editor/dist/extensions/table/component.jsdeleted file mode 100644index 74fc8aeb8..000000000--- a/packages/editor/dist/extensions/table/component.js+++ /dev/null@@ -1,155 +0,0 @@-"use strict";-var __extends = (this && this.__extends) || (function () {- var extendStatics = function (d, b) {- extendStatics = Object.setPrototypeOf ||- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };- return extendStatics(d, b);- };- return function (d, b) {- if (typeof b !== "function" && b !== null)- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");- extendStatics(d, b);- function __() { this.constructor = d; }- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());- };-})();-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TableNodeView = exports.TableComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("../react");-var react_2 = require("react");-var prosemirror_tables_1 = require("@_ueberdosis/prosemirror-tables");-var table_1 = require("../../toolbar/tools/table");-var tooldefinitions_1 = require("../../toolbar/tooldefinitions");-var position_1 = require("../../utils/position");-var prosemirror_1 = require("../../toolbar/utils/prosemirror");-var responsive_1 = require("../../components/responsive");-function TableComponent(props) {- var editor = props.editor, node = props.node, forwardRef = props.forwardRef;- var colgroupRef = (0, react_2.useRef)(null);- var tableRef = (0, react_2.useRef)();- var selected = editor.isActive("table");- (0, react_2.useEffect)(function () {- if (!colgroupRef.current || !tableRef.current)- return;- (0, prosemirror_tables_1.updateColumnsOnResize)(node, colgroupRef.current, tableRef.current, 50);- }, [node]);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: selected && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(TableRowToolbar, { editor: editor, table: tableRef.current }), (0, jsx_runtime_1.jsx)(TableColumnToolbar, { editor: editor, table: tableRef.current })] })) }), (0, jsx_runtime_1.jsx)("div", __assign({ className: "tableWrapper" }, { children: (0, jsx_runtime_1.jsx)("table", __assign({ ref: function (ref) {- forwardRef === null || forwardRef === void 0 ? void 0 : forwardRef(ref);- tableRef.current = ref || undefined;- } }, { children: (0, jsx_runtime_1.jsx)("colgroup", { ref: colgroupRef }) })) }))] }));-}-exports.TableComponent = TableComponent;-function TableNodeView(editor) {- var TableNode = /** @class */ (function (_super) {- __extends(TableNode, _super);- function TableNode(node, cellMinWidth) {- var _this = _super.call(this, node, editor, function () { return 0; }, // todo- {- component: TableComponent,- shouldUpdate: function (prev, next) {- return prev.type === next.type;- },- contentDOMFactory: function () {- var dom = document.createElement("tbody");- return { dom: dom };- },- wrapperFactory: function () {- var dom = document.createElement("div");- dom.style.position = "relative";- return dom;- },- }) || this;- _super.prototype.init.call(_this);- return _this;- }- return TableNode;- }(react_1.SelectionBasedNodeView));- return TableNode;-}-exports.TableNodeView = TableNodeView;-function TableRowToolbar(props) {- var editor = props.editor;- var rowToolsRef = (0, react_2.useRef)(null);- (0, react_2.useEffect)(function () {- if (!rowToolsRef.current) {- return;- }- var currentRow = (0, prosemirror_1.findSelectedDOMNode)(editor, ["tableRow"]);- if (!currentRow)- return;- var pos = (0, position_1.getPosition)(rowToolsRef.current, {- location: "left",- target: currentRow,- align: "start",- xOffset: -5,- yOffset: -3,- });- rowToolsRef.current.style.top = "".concat(pos.top, "px");- rowToolsRef.current.style.left = "".concat(pos.left, "px");- }, [editor.state.selection, rowToolsRef.current]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ ref: rowToolsRef, sx: {- zIndex: 999,- top: 0,- left: 0,- position: "absolute",- bg: "background",- flexWrap: "nowrap",- borderRadius: "default",- opacity: 0.3,- ":hover": {- opacity: 1,- },- } }, { children: [(0, jsx_runtime_1.jsx)(table_1.RowProperties, __assign({}, (0, tooldefinitions_1.getToolDefinition)("rowProperties"), { icon: "more", variant: "small", editor: editor })), (0, jsx_runtime_1.jsx)(table_1.InsertRowBelow, __assign({}, (0, tooldefinitions_1.getToolDefinition)("insertRowBelow"), { editor: editor, variant: "small" }))] })));-}-function TableColumnToolbar(props) {- var editor = props.editor, table = props.table;- var columnToolsRef = (0, react_2.useRef)(null);- (0, react_2.useEffect)(function () {- if (!columnToolsRef.current || !table) {- return;- }- var currentCell = (0, prosemirror_1.findSelectedDOMNode)(editor, [- "tableCell",- "tableHeader",- ]);- if (!currentCell)- return;- // tableRef.current- var pos = (0, position_1.getPosition)(columnToolsRef.current, {- location: "top",- align: "center",- target: currentCell,- yAnchor: table,- yOffset: 2,- });- columnToolsRef.current.style.left = "".concat(pos.left, "px");- columnToolsRef.current.style.top = "".concat(pos.top, "px");- }, [editor.state.selection, columnToolsRef.current, table]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ ref: columnToolsRef, sx: {- zIndex: 999,- top: 0,- left: 0,- position: "absolute",- bg: "background",- flexWrap: "nowrap",- borderRadius: "default",- opacity: 0.3,- ":hover": {- opacity: 1,- },- } }, { children: [(0, jsx_runtime_1.jsx)(table_1.TableProperties, { editor: editor, title: "tableProperties", icon: "more", variant: "small" }), (0, jsx_runtime_1.jsx)(table_1.InsertColumnRight, __assign({}, (0, tooldefinitions_1.getToolDefinition)("insertColumnRight"), { editor: editor, variant: "small", icon: "plus" }))] })));-}diff --git a/packages/editor/dist/extensions/table/table.js b/packages/editor/dist/extensions/table/table.jsdeleted file mode 100644index 521a52322..000000000--- a/packages/editor/dist/extensions/table/table.js+++ /dev/null@@ -1,52 +0,0 @@-"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Table = void 0;-var extension_table_1 = require("@tiptap/extension-table");-var prosemirror_tables_1 = require("@_ueberdosis/prosemirror-tables");-var component_1 = require("./component");-exports.Table = extension_table_1.Table.extend({- addProseMirrorPlugins: function () {- var isResizable = this.options.resizable && this.editor.isEditable;- return __spreadArray(__spreadArray([], __read((isResizable- ? [- (0, prosemirror_tables_1.columnResizing)({- handleWidth: this.options.handleWidth,- cellMinWidth: this.options.cellMinWidth,- View: (0, component_1.TableNodeView)(this.editor),- // TODO: PR for @types/prosemirror-tables- // @ts-ignore (incorrect type)- lastColumnResizable: this.options.lastColumnResizable,- }),- ]- : [])), false), [- (0, prosemirror_tables_1.tableEditing)({- allowTableNodeSelection: this.options.allowTableNodeSelection,- }),- ], false);- },-});diff --git a/packages/editor/dist/extensions/tablecell/tablecell.js b/packages/editor/dist/extensions/tablecell/tablecell.jsdeleted file mode 100644index 1f798891c..000000000--- a/packages/editor/dist/extensions/tablecell/tablecell.js+++ /dev/null@@ -1,43 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TableCell = void 0;-var extension_table_cell_1 = __importDefault(require("@tiptap/extension-table-cell"));-exports.TableCell = extension_table_cell_1.default.extend({- addAttributes: function () {- var _a;- return __assign(__assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { backgroundColor: addStyleAttribute("backgroundColor", "background-color"), color: addStyleAttribute("color", "color"), borderWidth: addStyleAttribute("borderWidth", "border-width", "px"), borderStyle: addStyleAttribute("borderStyle", "border-style"), borderColor: addStyleAttribute("borderColor", "border-color") });- },-});-function addStyleAttribute(name, cssName, unit) {- return {- default: null,- parseHTML: function (element) {- var _a;- return unit- ? (_a = element.style[name]) === null || _a === void 0 ? void 0 : _a.toString().replace(unit, "")- : element.style[name];- },- renderHTML: function (attributes) {- if (!attributes[name]) {- return {};- }- return {- style: "".concat(cssName, ": ").concat(attributes[name]).concat(unit || ""),- };- },- };-}diff --git a/packages/editor/dist/extensions/taskitem/component.js b/packages/editor/dist/extensions/taskitem/component.jsdeleted file mode 100644index 6ee2c01e6..000000000--- a/packages/editor/dist/extensions/taskitem/component.js+++ /dev/null@@ -1,119 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TaskItemComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var core_1 = require("@tiptap/core");-var react_1 = require("react");-var taskitem_1 = require("./taskitem");-function TaskItemComponent(props) {- var editor = props.editor, updateAttributes = props.updateAttributes, node = props.node, getPos = props.getPos, forwardRef = props.forwardRef;- var checked = props.node.attrs.checked;- var toggle = (0, react_1.useCallback)(function () {- if (!editor.isEditable)- return false;- updateAttributes({ checked: !checked });- editor.commands.command(function (_a) {- var tr = _a.tr;- var parentPos = getPos();- toggleChildren(node, tr, !checked, parentPos);- return true;- });- return true;- }, [editor, getPos, node, checked]);- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ "data-drag-image": true, sx: {- ":hover > .dragHandle": {- opacity: editor.isEditable ? 1 : 0,- },- } }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { className: "dragHandle", draggable: "true", "data-drag-handle": true, path: icons_1.Icons.dragHandle, sx: {- opacity: [1, 1, 0],- alignSelf: "start",- mr: 2,- bg: "transparent",- cursor: "grab",- ".icon:hover path": {- fill: "var(--checked) !important",- },- }, size: 20 }), (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: checked ? icons_1.Icons.check : "", stroke: "1px", sx: {- border: "2px solid",- borderColor: checked ? "checked" : "icon",- borderRadius: "default",- alignSelf: "start",- mr: 2,- p: "1px",- cursor: editor.isEditable ? "pointer" : "unset",- ":hover": {- borderColor: "checked",- },- ":hover .icon path": {- fill: "var(--checked) !important",- },- }, onMouseDown: function (e) {- e.preventDefault();- toggle();- }, color: checked ? "checked" : "icon", size: 13 }), (0, jsx_runtime_1.jsx)(rebass_1.Text, { as: "div", ref: forwardRef, sx: {- textDecorationLine: checked ? "line-through" : "none",- color: checked ? "var(--checked)" : "var(--text)",- flex: 1,- } })] })) }));-}-exports.TaskItemComponent = TaskItemComponent;-function toggleChildren(node, tr, toggleState, parentPos) {- var e_1, _a;- var children = (0, core_1.findChildren)(node, function (node) { return node.type.name === taskitem_1.TaskItemNode.name; });- try {- for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {- var pos = children_1_1.value.pos;- // need to add 1 to get inside the node- var actualPos = pos + parentPos + 1;- tr.setNodeMarkup(actualPos, undefined, {- checked: toggleState,- });- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);- }- finally { if (e_1) throw e_1.error; }- }- return tr;-}-function getChildren(node, parentPos) {- var children = [];- node.forEach(function (node, offset) {- children.push({ node: node, pos: parentPos + offset + 1 });- });- return children;-}-function areAllChecked(node) {- var children = (0, core_1.findChildren)(node, function (node) { return node.type.name === taskitem_1.TaskItemNode.name; });- if (children.length <= 0)- return undefined;- return children.every(function (node) { return node.node.attrs.checked; });-}diff --git a/packages/editor/dist/extensions/taskitem/taskitem.js b/packages/editor/dist/extensions/taskitem/taskitem.jsdeleted file mode 100644index 983e3ba24..000000000--- a/packages/editor/dist/extensions/taskitem/taskitem.js+++ /dev/null@@ -1,81 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TaskItemNode = void 0;-var core_1 = require("@tiptap/core");-var commands_1 = require("../list-item/commands");-var extension_task_item_1 = require("@tiptap/extension-task-item");-var component_1 = require("./component");-var react_1 = require("../react");-exports.TaskItemNode = extension_task_item_1.TaskItem.extend({- draggable: true,- addAttributes: function () {- return {- checked: {- default: false,- keepOnSplit: false,- parseHTML: function (element) { return element.classList.contains("checked"); },- renderHTML: function (attributes) { return ({- class: attributes.checked ? "checked" : "",- }); },- },- };- },- renderHTML: function (_a) {- var node = _a.node, HTMLAttributes = _a.HTMLAttributes;- return [- "li",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {- class: "checklist--item",- }),- 0,- ];- },- parseHTML: function () {- return [- {- tag: "li",- getAttrs: function (node) {- var _a;- if (node instanceof Node && node instanceof HTMLElement) {- return node.classList.contains("checklist--item") ||- ((_a = node.parentElement) === null || _a === void 0 ? void 0 : _a.classList.contains("checklist"))- ? null- : false;- }- return false;- },- priority: 51,- },- ];- },- addKeyboardShortcuts: function () {- var _this = this;- var _a;- return __assign(__assign({}, (_a = this.parent) === null || _a === void 0 ? void 0 : _a.call(this)), { Backspace: function (_a) {- var editor = _a.editor;- return (0, commands_1.onBackspacePressed)(editor, _this.name, _this.type);- } });- },- addNodeView: function () {- return (0, react_1.createNodeView)(component_1.TaskItemComponent, {- contentDOMFactory: true,- wrapperFactory: function () { return document.createElement("li"); },- shouldUpdate: function (_a, _b) {- var prev = _a.attrs;- var next = _b.attrs;- return (prev.checked !== next.checked || prev.collapsed !== next.collapsed);- },- });- },-});diff --git a/packages/editor/dist/extensions/tasklist/component.js b/packages/editor/dist/extensions/tasklist/component.jsdeleted file mode 100644index 56abb7a04..000000000--- a/packages/editor/dist/extensions/tasklist/component.js+++ /dev/null@@ -1,152 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __values = (this && this.__values) || function(o) {- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;- if (m) return m.call(o);- if (o && typeof o.length === "number") return {- next: function () {- if (o && i >= o.length) o = void 0;- return { value: o && o[i++], done: !o };- }- };- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TaskListComponent = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var core_1 = require("@tiptap/core");-var icon_1 = require("../../toolbar/components/icon");-var icons_1 = require("../../toolbar/icons");-var react_1 = require("react");-var forms_1 = require("@rebass/forms");-var taskitem_1 = require("../taskitem");-var prosemirror_utils_1 = require("prosemirror-utils");-function TaskListComponent(props) {- var editor = props.editor, getPos = props.getPos, node = props.node, updateAttributes = props.updateAttributes, forwardRef = props.forwardRef;- var taskItemType = (0, core_1.getNodeType)(taskitem_1.TaskItemNode.name, editor.schema);- var _a = node.attrs, title = _a.title, collapsed = _a.collapsed;- var _b = __read((0, react_1.useState)({ checked: 0, total: 0, percentage: 0 }), 2), stats = _b[0], setStats = _b[1];- var parentTaskItem = (0, react_1.useMemo)(function () {- var pos = editor.state.doc.resolve(getPos());- return (0, prosemirror_utils_1.findParentNodeOfTypeClosestToPos)(pos, taskItemType);- }, []);- var nested = !!parentTaskItem;- (0, react_1.useEffect)(function () {- if (!parentTaskItem)- return;- var node = parentTaskItem.node, pos = parentTaskItem.pos;- var allChecked = areAllChecked(node, pos, editor.state.doc);- // check parent item if all child items are checked.- editor.commands.command(function (_a) {- var tr = _a.tr;- tr.setNodeMarkup(pos, undefined, { checked: allChecked });- return true;- });- }, [node, parentTaskItem]);- (0, react_1.useEffect)(function () {- var children = (0, core_1.findChildren)(node, function (node) { return node.type.name === taskitem_1.TaskItemNode.name; });- var checked = children.filter(function (node) { return node.node.attrs.checked; }).length;- var total = children.length;- var percentage = Math.round((checked / total) * 100);- setStats({ checked: checked, total: total, percentage: percentage });- }, [nested, node]);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {- flexDirection: "column",- ":hover > div > .toggleSublist": { opacity: 1 },- } }, { children: nested ? ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- position: "absolute",- top: 0,- right: 0,- }, contentEditable: false }, { children: [collapsed && ((0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "body", sx: { color: "fontTertiary", mr: 35 } }, { children: [stats.checked, "/", stats.total] }))), (0, jsx_runtime_1.jsx)(icon_1.Icon, { className: "toggleSublist", path: collapsed ? icons_1.Icons.chevronDown : icons_1.Icons.chevronUp, sx: {- opacity: collapsed ? 1 : 0,- position: "absolute",- right: 0,- alignSelf: "start",- mr: 2,- cursor: "pointer",- ".icon:hover path": {- fill: "var(--checked) !important",- },- }, size: 20, onClick: function () {- updateAttributes({ collapsed: !collapsed });- } })] }))) : ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- position: "relative",- bg: "bgSecondary",- py: 1,- borderRadius: "default",- mb: 2,- alignItems: "center",- justifyContent: "end",- overflow: "hidden",- }, contentEditable: false }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { sx: {- height: "100%",- width: "".concat(stats.percentage, "%"),- position: "absolute",- bg: "border",- zIndex: 0,- left: 0,- transition: "width 250ms ease-out",- } }), (0, jsx_runtime_1.jsx)(forms_1.Input, { readOnly: !editor.isEditable, value: title || "", variant: "clean", sx: { p: 0, px: 2, zIndex: 1, color: "fontTertiary" }, placeholder: "Untitled", onChange: function (e) {- updateAttributes({ title: e.target.value });- } }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { flexShrink: 0, pr: 2 } }, { children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.checkbox, size: 15, color: "fontTertiary" }), (0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "body", sx: { ml: 1, color: "fontTertiary" } }, { children: [stats.checked, "/", stats.total] }))] }))] }))) })), (0, jsx_runtime_1.jsx)(rebass_1.Text, { as: "div", ref: forwardRef, sx: {- ul: {- display: collapsed ? "none" : "block",- paddingInlineStart: 0,- marginBlockStart: nested ? 10 : 0,- marginBlockEnd: 0,- },- li: {- listStyleType: "none",- position: "relative",- },- } })] }));-}-exports.TaskListComponent = TaskListComponent;-function areAllChecked(node, pos, doc) {- var e_1, _a;- var children = (0, core_1.findChildren)(node, function (node) { return node.type.name === taskitem_1.TaskItemNode.name; });- try {- for (var children_1 = __values(children), children_1_1 = children_1.next(); !children_1_1.done; children_1_1 = children_1.next()) {- var child = children_1_1.value;- var childPos = pos + child.pos + 1;- var node_1 = doc.nodeAt(childPos);- if (!(node_1 === null || node_1 === void 0 ? void 0 : node_1.attrs.checked))- return false;- }- }- catch (e_1_1) { e_1 = { error: e_1_1 }; }- finally {- try {- if (children_1_1 && !children_1_1.done && (_a = children_1.return)) _a.call(children_1);- }- finally { if (e_1) throw e_1.error; }- }- return true;-}diff --git a/packages/editor/dist/extensions/tasklist/tasklist.js b/packages/editor/dist/extensions/tasklist/tasklist.jsdeleted file mode 100644index cc6cea69e..000000000--- a/packages/editor/dist/extensions/tasklist/tasklist.js+++ /dev/null@@ -1,93 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-exports.TaskListNode = void 0;-var core_1 = require("@tiptap/core");-var extension_task_list_1 = require("@tiptap/extension-task-list");-var react_1 = require("../react");-var component_1 = require("./component");-exports.TaskListNode = extension_task_list_1.TaskList.extend({- addAttributes: function () {- return {- collapsed: {- default: false,- keepOnSplit: false,- parseHTML: function (element) { return element.dataset.collapsed === "true"; },- renderHTML: function (attributes) { return ({- "data-collapsed": attributes.collapsed === true,- }); },- },- title: {- default: null,- keepOnSplit: false,- parseHTML: function (element) { return element.dataset.title; },- renderHTML: function (attributes) {- if (!attributes.title || attributes.nested) {- return {};- }- return {- "data-title": attributes.title,- };- },- },- };- },- parseHTML: function () {- return [- {- tag: "ul",- getAttrs: function (node) {- if (node instanceof Node && node instanceof HTMLElement) {- return node.classList.contains("checklist") && null;- }- return false;- },- priority: 51,- },- ];- },- renderHTML: function (_a) {- var HTMLAttributes = _a.HTMLAttributes;- return [- "ul",- (0, core_1.mergeAttributes)(this.options.HTMLAttributes, HTMLAttributes, {- class: "checklist",- }),- 0,- ];- },- addCommands: function () {- var _this = this;- return {- toggleTaskList: function () {- return function (_a) {- var editor = _a.editor, commands = _a.commands, state = _a.state, tr = _a.tr;- var _b = state.selection, $from = _b.$from, $to = _b.$to;- commands.toggleList(_this.name, _this.options.itemTypeName);- var position = {- from: tr.mapping.map($from.pos),- to: tr.mapping.map($to.pos),- };- // There is a minor bug in Prosemirror or Tiptap where creating- // nested node view causes the editor selection to act weird.- // The solution is to manually force the editor back to the correct- // position.- // NOTE: We have to wrap this in setTimeout & use the editor- // directly or else it won't run.- setTimeout(function () { return editor.commands.setTextSelection(position); }, 0);- return true;- };- },- };- },- addNodeView: function () {- var _this = this;- return (0, react_1.createNodeView)(component_1.TaskListComponent, {- contentDOMFactory: function () {- var content = document.createElement("ul");- content.classList.add("".concat(_this.name.toLowerCase(), "-content-wrapper"));- content.style.whiteSpace = "inherit";- return { dom: content };- },- });- },-});diff --git a/packages/editor/dist/toolbar/components/counter.js b/packages/editor/dist/toolbar/components/counter.jsdeleted file mode 100644index 17c91db6d..000000000--- a/packages/editor/dist/toolbar/components/counter.js+++ /dev/null@@ -1,42 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Counter = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importDefault(require("react"));-var rebass_1 = require("rebass");-var button_1 = require("../../components/button");-var toolbutton_1 = require("./toolbutton");-function _Counter(props) {- var title = props.title, onDecrease = props.onDecrease, onIncrease = props.onIncrease, onReset = props.onReset, value = props.value;- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- alignItems: "center",- mr: 1,- ":last-of-type": {- mr: 0,- },- } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Decrease ".concat(title), icon: "minus", variant: "small", onClick: onDecrease }), (0, jsx_runtime_1.jsx)(button_1.Button, __assign({ sx: {- color: "text",- bg: "transparent",- px: 0,- fontSize: "subBody",- mx: 1,- textAlign: "center",- }, onClick: onReset, title: "Reset ".concat(title) }, { children: value })), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Increase ".concat(title), icon: "plus", variant: "small", onClick: onIncrease })] })));-}-exports.Counter = react_1.default.memo(_Counter, function (prev, next) {- return prev.value === next.value;-});diff --git a/packages/editor/dist/toolbar/components/dropdown.js b/packages/editor/dist/toolbar/components/dropdown.jsdeleted file mode 100644index c376d2781..000000000--- a/packages/editor/dist/toolbar/components/dropdown.js+++ /dev/null@@ -1,79 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Dropdown = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var rebass_1 = require("rebass");-var icon_1 = require("./icon");-var icons_1 = require("../icons");-var toolbarstore_1 = require("../stores/toolbarstore");-var menu_1 = require("../../components/menu");-var dom_1 = require("../utils/dom");-function Dropdown(props) {- var items = props.items, selectedItem = props.selectedItem, buttonRef = props.buttonRef, menuWidth = props.menuWidth;- var internalRef = (0, react_1.useRef)();- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- var isMobile = (0, toolbarstore_1.useIsMobile)();- var isBottom = toolbarLocation === "bottom";- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Button, __assign({ ref: function (ref) {- internalRef.current = ref;- if (buttonRef)- buttonRef.current = ref;- }, sx: {- p: 1,- m: 0,- bg: isOpen ? "hover" : "transparent",- mr: 1,- display: "flex",- alignItems: "center",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }, onClick: function () { return setIsOpen(function (s) { return !s; }); }, onMouseDown: function (e) { return e.preventDefault(); } }, { children: [typeof selectedItem === "string" ? ((0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ sx: { fontSize: "subBody", mr: 1, color: "text" } }, { children: selectedItem }))) : (selectedItem), (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: isBottom ? icons_1.Icons.chevronUp : icons_1.Icons.chevronDown, size: "small", color: "text" })] })), (0, jsx_runtime_1.jsx)(menu_1.MenuPresenter, { isOpen: isOpen, items: items, onClose: function () { return setIsOpen(false); }, position: {- target: isBottom- ? (0, dom_1.getToolbarElement)()- : internalRef.current || "mouse",- isTargetAbsolute: true,- location: isBottom ? "top" : "below",- align: "center",- yOffset: 5,- }, blocking: !isMobile, focusOnRender: !isMobile, sx: {- minWidth: menuWidth,- maxWidth: isBottom ? "95vw" : "auto",- flexDirection: isBottom ? "row" : "column",- overflowX: isBottom ? "auto" : "hidden",- marginRight: isBottom ? "10px" : 0,- display: "flex",- alignItems: isBottom ? "center" : "unset",- } })] }));-}-exports.Dropdown = Dropdown;diff --git a/packages/editor/dist/toolbar/components/icon.js b/packages/editor/dist/toolbar/components/icon.jsdeleted file mode 100644index 814a33c0b..000000000--- a/packages/editor/dist/toolbar/components/icon.js+++ /dev/null@@ -1,48 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Icon = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importDefault(require("@mdi/react"));-var emotion_theming_1 = require("emotion-theming");-var rebass_1 = require("rebass");-function MDIIconWrapper(_a) {- var title = _a.title, path = _a.path, _b = _a.size, size = _b === void 0 ? 24 : _b, _c = _a.color, color = _c === void 0 ? "icon" : _c, stroke = _a.stroke, rotate = _a.rotate;- var theme = (0, emotion_theming_1.useTheme)();- var themedColor = theme.colors- ? theme.colors[color]- : color;- return ((0, jsx_runtime_1.jsx)(react_1.default, { className: "icon", title: title, path: path, size: typeof size === "string" ? "".concat(theme.iconSizes[size], "px") : "".concat(size, "px"), style: {- strokeWidth: stroke || "0px",- stroke: themedColor,- }, color: themedColor, spin: rotate }));-}-function Icon(props) {- var sx = props.sx, title = props.title, color = props.color, size = props.size, stroke = props.stroke, rotate = props.rotate, path = props.path, restProps = __rest(props, ["sx", "title", "color", "size", "stroke", "rotate", "path"]);- return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: __assign({ flexShrink: 0, justifyContent: "center", alignItems: "center" }, sx) }, restProps, { children: (0, jsx_runtime_1.jsx)(MDIIconWrapper, { title: title, path: path, rotate: rotate, color: color, stroke: stroke, size: size }) })));-}-exports.Icon = Icon;diff --git a/packages/editor/dist/toolbar/components/moretools.js b/packages/editor/dist/toolbar/components/moretools.jsdeleted file mode 100644index e58df6b92..000000000--- a/packages/editor/dist/toolbar/components/moretools.js+++ /dev/null@@ -1,60 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.MoreTools = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var popuppresenter_1 = require("../../components/popuppresenter");-var toolbutton_1 = require("../components/toolbutton");-var toolbarstore_1 = require("../stores/toolbarstore");-var dom_1 = require("../utils/dom");-var toolbargroup_1 = require("./toolbargroup");-function MoreTools(props) {- var popupId = props.popupId, editor = props.editor, tools = props.tools, autoCloseOnUnmount = props.autoCloseOnUnmount;- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- var isBottom = toolbarLocation === "bottom";- var buttonRef = (0, react_1.useRef)();- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: isOpen, buttonRef: buttonRef, onClick: function () { return setIsOpen(function (s) { return !s; }); } })), (0, jsx_runtime_1.jsx)(popuppresenter_1.PopupWrapper, { isOpen: isOpen, group: "toolbarGroup", id: popupId, onClosed: function () { return setIsOpen(false); }, position: {- isTargetAbsolute: true,- target: isBottom ? (0, dom_1.getToolbarElement)() : buttonRef.current || "mouse",- align: "center",- location: isBottom ? "top" : "below",- yOffset: isBottom ? 10 : 5,- }, autoCloseOnUnmount: autoCloseOnUnmount, focusOnRender: false, blocking: false, renderPopup: function () { return ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { tools: tools, editor: editor, sx: {- flex: 1,- p: 1,- boxShadow: "menu",- bg: "background",- borderRadius: "default",- overflowX: "auto",- maxWidth: "95vw",- } })); } })] }));-}-exports.MoreTools = MoreTools;diff --git a/packages/editor/dist/toolbar/components/popup.js b/packages/editor/dist/toolbar/components/popup.jsdeleted file mode 100644index b98e3e7c5..000000000--- a/packages/editor/dist/toolbar/components/popup.js+++ /dev/null@@ -1,42 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Popup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var icon_1 = require("./icon");-var icons_1 = require("../icons");-var responsive_1 = require("../../components/responsive");-function Popup(props) {- var title = props.title, onClose = props.onClose, action = props.action, children = props.children;- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(responsive_1.DesktopOnly, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- overflow: "hidden",- bg: "background",- flexDirection: "column",- borderRadius: "default",- // border: "1px solid var(--border)",- boxShadow: "menu",- minWidth: 200,- } }, { children: [title && ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ className: "movable", sx: {- justifyContent: "space-between",- alignItems: "center",- p: 2,- } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "title" }, { children: title })), (0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({ variant: "tool", sx: { p: 0, bg: "transparent" }, onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.close, size: "big" }) }))] }))), children, title && action && ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: { justifyContent: "end" }, bg: "bgSecondary", p: 1, px: 2, mt: 2 }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({ variant: "dialog", onClick: action.disabled || action.loading ? undefined : action.onClick, disabled: action.disabled || action.loading }, { children: action.loading ? ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.loading, rotate: true, size: "medium" })) : (action.title) })) })))] })) }), (0, jsx_runtime_1.jsxs)(responsive_1.MobileOnly, { children: [children, action && ((0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({ variant: "primary", sx: {- alignSelf: "stretch",- mb: 1,- mt: 2,- mx: 1,- py: 2,- }, onClick: action.disabled ? undefined : action === null || action === void 0 ? void 0 : action.onClick, disabled: action.disabled }, { children: action.loading ? ((0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.loading, rotate: true, size: "medium" })) : (action.title) })))] })] }));-}-exports.Popup = Popup;diff --git a/packages/editor/dist/toolbar/components/toolbargroup.js b/packages/editor/dist/toolbar/components/toolbargroup.jsdeleted file mode 100644index d0fe78557..000000000--- a/packages/editor/dist/toolbar/components/toolbargroup.js+++ /dev/null@@ -1,44 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ToolbarGroup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var tools_1 = require("../tools");-var rebass_1 = require("rebass");-var moretools_1 = require("./moretools");-var tooldefinitions_1 = require("../tooldefinitions");-function ToolbarGroup(props) {- var tools = props.tools, editor = props.editor, force = props.force, selectedNode = props.selectedNode, flexProps = __rest(props, ["tools", "editor", "force", "selectedNode"]);- return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ className: "toolbar-group" }, flexProps, { children: tools.map(function (toolId) {- if (Array.isArray(toolId)) {- return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, { title: "More", icon: "more", popupId: toolId.join(""), tools: toolId, editor: editor }, "more-tools"));- }- else {- var Component = (0, tools_1.findTool)(toolId);- var toolDefinition = (0, tooldefinitions_1.getToolDefinition)(toolId);- return ((0, jsx_runtime_1.jsx)(Component, __assign({ editor: editor, force: force, selectedNode: selectedNode }, toolDefinition), toolDefinition.title));- }- }) })));-}-exports.ToolbarGroup = ToolbarGroup;diff --git a/packages/editor/dist/toolbar/components/toolbutton.js b/packages/editor/dist/toolbar/components/toolbutton.jsdeleted file mode 100644index 30090fb10..000000000--- a/packages/editor/dist/toolbar/components/toolbutton.js+++ /dev/null@@ -1,41 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ToolButton = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importDefault(require("react"));-var icons_1 = require("../icons");-var button_1 = require("../../components/button");-var icon_1 = require("./icon");-exports.ToolButton = react_1.default.memo(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 ((0, jsx_runtime_1.jsx)(button_1.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: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons[icon], color: iconColor || "icon", size: iconSize || (variant === "small" ? "medium" : "big") }) })));-}, function (prev, next) {- return prev.toggled === next.toggled;-});diff --git a/packages/editor/dist/toolbar/floatingmenus/hoverpopup/index.js b/packages/editor/dist/toolbar/floatingmenus/hoverpopup/index.jsdeleted file mode 100644index cc709f466..000000000--- a/packages/editor/dist/toolbar/floatingmenus/hoverpopup/index.js+++ /dev/null@@ -1,81 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.HoverPopupHandler = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = require("react");-var popuppresenter_1 = require("../../../components/popuppresenter");-var link_1 = require("./link");-var handlers = __assign({}, link_1.LinkHoverPopupHandler);-var HOVER_TIMEOUT = 500;-function HoverPopupHandler(props) {- var editor = props.editor;- var hoverTimeoutId = (0, react_1.useRef)();- var activePopup = (0, react_1.useRef)();- (0, react_1.useEffect)(function () {- function onMouseOver(e) {- if (!e.target ||- !(e.target instanceof HTMLElement) ||- e.target.classList.contains("ProseMirror"))- return;- var element = e.target;- if (activePopup.current) {- var isOutsideEditor = !element.closest(".ProseMirror");- var isInsidePopup = element.closest(".popup-presenter-portal");- var isActiveElement = activePopup.current.element === element;- if (isInsidePopup)- return;- if (isOutsideEditor || !isActiveElement) {- console.log("HIDING", isOutsideEditor, isActiveElement, element);- activePopup.current.hide();- activePopup.current = undefined;- return;- }- }- clearTimeout(hoverTimeoutId.current);- hoverTimeoutId.current = setTimeout(function () {- var nodeName = element.nodeName.toLowerCase();- var PopupHandler = handlers[nodeName];- if (!PopupHandler || !editor.current)- return;- var pos = editor.current.view.posAtDOM(element, 0);- var node = editor.current.view.state.doc.nodeAt(pos);- if (!node)- return;- var hidePopup = (0, popuppresenter_1.showPopup)({- popup: function () { return ((0, jsx_runtime_1.jsx)(PopupHandler, { editor: editor, selectedNode: {- node: node,- from: pos,- to: pos + node.nodeSize,- } })); },- theme: editor.storage.theme,- blocking: false,- focusOnRender: false,- position: {- target: element,- align: "center",- location: "top",- isTargetAbsolute: true,- },- });- activePopup.current = { element: element, hide: hidePopup };- }, HOVER_TIMEOUT, {});- }- window.addEventListener("mouseover", onMouseOver);- return function () {- window.removeEventListener("mouseover", onMouseOver);- };- }, []);- return null;-}-exports.HoverPopupHandler = HoverPopupHandler;diff --git a/packages/editor/dist/toolbar/floatingmenus/index.js b/packages/editor/dist/toolbar/floatingmenus/index.jsdeleted file mode 100644index 4b776d751..000000000--- a/packages/editor/dist/toolbar/floatingmenus/index.js+++ /dev/null@@ -1,21 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.EditorFloatingMenus = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var hoverpopup_1 = require("./hoverpopup");-var searchreplace_1 = require("./searchreplace");-function EditorFloatingMenus(props) {- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(searchreplace_1.SearchReplaceFloatingMenu, __assign({}, props)), (0, jsx_runtime_1.jsx)(hoverpopup_1.HoverPopupHandler, __assign({}, props))] }));-}-exports.EditorFloatingMenus = EditorFloatingMenus;diff --git a/packages/editor/dist/toolbar/floatingmenus/searchreplace.js b/packages/editor/dist/toolbar/floatingmenus/searchreplace.jsdeleted file mode 100644index 2d319020a..000000000--- a/packages/editor/dist/toolbar/floatingmenus/searchreplace.js+++ /dev/null@@ -1,30 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.SearchReplaceFloatingMenu = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var searchreplace_1 = require("../popups/searchreplace");-var responsive_1 = require("../../components/responsive");-var dom_1 = require("../utils/dom");-function SearchReplaceFloatingMenu(props) {- var editor = props.editor;- var isSearching = editor.storage.searchreplace.isSearching;- return ((0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, __assign({ mobile: "sheet", desktop: "menu", isOpen: isSearching, onClose: function () { return editor.commands.endSearch(); }, position: {- target: (0, dom_1.getToolbarElement)(),- isTargetAbsolute: true,- location: "below",- align: "end",- yOffset: 5,- }, blocking: false, focusOnRender: false, draggable: false }, { children: (0, jsx_runtime_1.jsx)(searchreplace_1.SearchReplacePopup, { editor: editor }) })));-}-exports.SearchReplaceFloatingMenu = SearchReplaceFloatingMenu;diff --git a/packages/editor/dist/toolbar/index.d.ts b/packages/editor/dist/toolbar/index.d.tsdeleted file mode 100644index 868030ec7..000000000--- a/packages/editor/dist/toolbar/index.d.ts+++ /dev/null@@ -1,2 +0,0 @@-import { Toolbar } from "./toolbar";-export default Toolbar;diff --git a/packages/editor/dist/toolbar/index.js b/packages/editor/dist/toolbar/index.jsdeleted file mode 100644index f8741e8dd..000000000--- a/packages/editor/dist/toolbar/index.js+++ /dev/null@@ -1,4 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-var toolbar_1 = require("./toolbar");-exports.default = toolbar_1.Toolbar;diff --git a/packages/editor/dist/toolbar/popups/cellproperties.js b/packages/editor/dist/toolbar/popups/cellproperties.jsdeleted file mode 100644index 340d155f6..000000000--- a/packages/editor/dist/toolbar/popups/cellproperties.js+++ /dev/null@@ -1,37 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.CellProperties = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var tabs_1 = require("../../components/tabs");-var icon_1 = require("../components/icon");-// import { MenuPresenter } from "../../components/menu/menu";-var popup_1 = require("../components/popup");-var icons_1 = require("../icons");-var colorpicker_1 = require("./colorpicker");-function CellProperties(props) {- var editor = props.editor, onClose = props.onClose;- var attributes = editor.getAttributes("tableCell");- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ title: "Cell properties", onClose: onClose }, { children: (0, jsx_runtime_1.jsxs)(tabs_1.Tabs, __assign({ activeIndex: 0 }, { children: [(0, jsx_runtime_1.jsxs)(tabs_1.Tab, __assign({ title: (0, jsx_runtime_1.jsx)(icon_1.Icon, { title: "Cell background color", path: icons_1.Icons.backgroundColor, size: 16 }) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { mt: 2 }), (0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { expanded: true, color: attributes.backgroundColor, onChange: function (color) {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", color);- }, onClear: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("backgroundColor", undefined);- } })] })), (0, jsx_runtime_1.jsxs)(tabs_1.Tab, __assign({ title: (0, jsx_runtime_1.jsx)(icon_1.Icon, { title: "Cell text color", path: icons_1.Icons.textColor, size: 16 }) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { mt: 2 }), (0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { expanded: true, color: attributes.color, onChange: function (color) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", color); }, onClear: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("color", undefined); } })] })), (0, jsx_runtime_1.jsxs)(tabs_1.Tab, __assign({ title: (0, jsx_runtime_1.jsx)(icon_1.Icon, { title: "Cell border color", path: icons_1.Icons.cellBorderColor, size: 16 }) }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, { mt: 2 }), (0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { expanded: true, color: attributes.borderColor, onChange: function (color) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", color); }, onClear: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderColor", undefined);- } })] }))] })) })));-}-exports.CellProperties = CellProperties;diff --git a/packages/editor/dist/toolbar/popups/embedpopup.js b/packages/editor/dist/toolbar/popups/embedpopup.jsdeleted file mode 100644index 99fbb171b..000000000--- a/packages/editor/dist/toolbar/popups/embedpopup.js+++ /dev/null@@ -1,119 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.EmbedPopup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("react");-var popup_1 = require("../components/popup");-var forms_1 = require("@rebass/forms");-var lib_1 = require("@social-embed/lib");-var inlineinput_1 = require("../../components/inlineinput");-var tabs_1 = require("../../components/tabs");-function EmbedPopup(props) {- var onClose = props.onClose, onSizeChanged = props.onSizeChanged, onSourceChanged = props.onSourceChanged, title = props.title, embed = props.embed;- var _a = __read((0, react_1.useState)((embed === null || embed === void 0 ? void 0 : embed.width) || 300), 2), width = _a[0], setWidth = _a[1];- var _b = __read((0, react_1.useState)((embed === null || embed === void 0 ? void 0 : embed.height) || 150), 2), height = _b[0], setHeight = _b[1];- var _c = __read((0, react_1.useState)((embed === null || embed === void 0 ? void 0 : embed.src) || ""), 2), src = _c[0], setSrc = _c[1];- var _d = __read((0, react_1.useState)("url"), 2), embedSource = _d[0], setEmbedSource = _d[1];- var _e = __read((0, react_1.useState)(null), 2), error = _e[0], setError = _e[1];- var onSizeChange = (0, react_1.useCallback)(function (newWidth, newHeight) {- var size = newWidth- ? {- width: newWidth,- height: newWidth * (height / width),- }- : newHeight- ? {- width: newHeight * (width / height),- height: newHeight,- }- : {- width: 0,- height: 0,- };- setWidth(size.width);- setHeight(size.height);- if (onSizeChanged)- onSizeChanged(size);- }, [width, height]);- (0, react_1.useEffect)(function () {- onSourceChanged && onSourceChanged(src);- }, [onSourceChanged, src]);- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ title: title, onClose: function () { return onClose(); }, action: {- title: title,- onClick: function () {- setError(null);- var _src = src;- var _width = width;- var _height = height;- if (embedSource === "code") {- var document_1 = new DOMParser().parseFromString(src, "text/html");- if (document_1.getElementsByTagName("iframe").length <= 0)- return setError("Embed code must include an iframe.");- var srcValue = getAttribute(document_1, "src");- if (!srcValue)- return setError("Embed code must include an iframe with an src attribute.");- _src = srcValue;- var widthValue = getAttribute(document_1, "width");- if (widthValue && !isNaN(parseInt(widthValue)))- _width = parseInt(widthValue);- var heightValue = getAttribute(document_1, "height");- if (heightValue && !isNaN(parseInt(heightValue)))- _height = parseInt(heightValue);- }- var convertedUrl = (0, lib_1.convertUrlToEmbedUrl)(_src);- if (!!convertedUrl)- _src = convertedUrl;- onClose({- height: _height,- width: _width,- src: _src,- });- },- } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { flexDirection: "column", width: ["auto", 300] } }, { children: [error && ((0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "error", sx: {- bg: "errorBg",- color: "error",- p: 1,- borderRadius: "default",- } }, { children: ["Error: ", error] }))), (0, jsx_runtime_1.jsxs)(tabs_1.Tabs, __assign({ activeIndex: 0, containerProps: { sx: { mx: 1, flexDirection: "column" } }, onTabChanged: function (index) { return setEmbedSource(index === 0 ? "url" : "code"); } }, { children: [(0, jsx_runtime_1.jsxs)(tabs_1.Tab, __assign({ title: "From URL" }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { placeholder: "Enter embed source URL", value: src, autoFocus: true, onChange: function (e) { return setSrc(e.target.value); }, autoCapitalize: "none", sx: { fontSize: "body" } }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { alignItems: "center", mt: 1 } }, { children: [(0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { containerProps: { sx: { mr: 1 } }, label: "width", type: "number", placeholder: "Width", value: width, sx: {- mr: 1,- fontSize: "body",- }, onChange: function (e) { return onSizeChange(e.target.valueAsNumber); } }), (0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "height", type: "number", placeholder: "Height", value: height, sx: { fontSize: "body" }, onChange: function (e) {- return onSizeChange(undefined, e.target.valueAsNumber);- } })] }))] })), (0, jsx_runtime_1.jsx)(tabs_1.Tab, __assign({ title: "From code" }, { children: (0, jsx_runtime_1.jsx)(forms_1.Textarea, { autoFocus: true, variant: "forms.input", sx: { fontSize: "subBody", fontFamily: "monospace" }, minHeight: [200, 100], onChange: function (e) { return setSrc(e.target.value); }, placeholder: "Paste embed code here. Only iframes are supported." }) }))] }))] })) })));-}-exports.EmbedPopup = EmbedPopup;-function getAttribute(document, id) {- var element = document.querySelector("[".concat(id, "]"));- if (!element)- return null;- var attribute = element.getAttribute(id);- return attribute;-}diff --git a/packages/editor/dist/toolbar/popups/imageproperties.js b/packages/editor/dist/toolbar/popups/imageproperties.jsdeleted file mode 100644index 017f3f5b2..000000000--- a/packages/editor/dist/toolbar/popups/imageproperties.js+++ /dev/null@@ -1,49 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ImageProperties = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("react");-var popup_1 = require("../components/popup");-var forms_1 = require("@rebass/forms");-var inlineinput_1 = require("../../components/inlineinput");-function ImageProperties(props) {- var height = props.height, width = props.width, float = props.float, editor = props.editor, onClose = props.onClose;- var onSizeChange = (0, react_1.useCallback)(function (newWidth, newHeight) {- var size = newWidth- ? {- width: newWidth,- height: newWidth * (height / width),- }- : newHeight- ? {- width: newHeight * (width / height),- height: newHeight,- }- : {- width: 0,- height: 0,- };- editor.chain().setImageSize(size).run();- }, [width, height]);- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ title: "Image properties", onClose: onClose }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { width: ["auto", 300], flexDirection: "column", p: 1 } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { justifyContent: "space-between", alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "body" }, { children: "Floating?" })), (0, jsx_runtime_1.jsx)(forms_1.Checkbox, { checked: float, onClick: function () {- return editor- .chain()- .setImageAlignment({ float: !float, align: "left" })- .run();- } })] })), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { alignItems: "center", mt: 2 } }, { children: [(0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "width", type: "number", value: width, containerProps: {- sx: { mr: 1 },- }, onChange: function (e) { return onSizeChange(e.target.valueAsNumber); } }), (0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "height", type: "number", value: height, onChange: function (e) { return onSizeChange(undefined, e.target.valueAsNumber); } })] }))] })) })));-}-exports.ImageProperties = ImageProperties;diff --git a/packages/editor/dist/toolbar/popups/imageupload.js b/packages/editor/dist/toolbar/popups/imageupload.jsdeleted file mode 100644index fa96b7daa..000000000--- a/packages/editor/dist/toolbar/popups/imageupload.js+++ /dev/null@@ -1,149 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }- return new (P || (P = Promise))(function (resolve, reject) {- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }- step((generator = generator.apply(thisArg, _arguments || [])).next());- });-};-var __generator = (this && this.__generator) || function (thisArg, body) {- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;- function verb(n) { return function (v) { return step([n, v]); }; }- function step(op) {- if (f) throw new TypeError("Generator is already executing.");- while (_) try {- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;- if (y = 0, t) op = [op[0] & 2, t.value];- switch (op[0]) {- case 0: case 1: t = op; break;- case 4: _.label++; return { value: op[1], done: false };- case 5: _.label++; y = op[1]; op = [0]; continue;- case 7: op = _.ops.pop(); _.trys.pop(); continue;- default:- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }- if (t[2]) _.ops.pop();- _.trys.pop(); continue;- }- op = body.call(thisArg, _);- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };- }-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ImageUploadPopup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var forms_1 = require("@rebass/forms");-var react_1 = require("react");-var rebass_1 = require("rebass");-var popup_1 = require("../components/popup");-function ImageUploadPopup(props) {- var _this = this;- var onInsert = props.onInsert, onClose = props.onClose;- var _a = __read((0, react_1.useState)(false), 2), isDownloading = _a[0], setIsDownloading = _a[1];- var _b = __read((0, react_1.useState)(), 2), error = _b[0], setError = _b[1];- var _c = __read((0, react_1.useState)(""), 2), url = _c[0], setUrl = _c[1];- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ title: "Insert image from URL", onClose: onClose, action: {- loading: isDownloading,- title: "Insert image",- disabled: !url,- onClick: function () { return __awaiter(_this, void 0, void 0, function () {- var response, contentType, contentLength, size, dataurl, _a, e_1;- return __generator(this, function (_b) {- switch (_b.label) {- case 0:- setIsDownloading(true);- setError(undefined);- _b.label = 1;- case 1:- _b.trys.push([1, 5, 6, 7]);- return [4 /*yield*/, fetch(url)];- case 2:- response = _b.sent();- if (!response.ok)- return [2 /*return*/, setError("invalid status code ".concat(response.status))];- contentType = response.headers.get("Content-Type");- contentLength = response.headers.get("Content-Length");- if (!contentType ||- !contentLength ||- contentLength === "0" ||- !contentType.startsWith("image/"))- return [2 /*return*/, setError("not an image")];- size = parseInt(contentLength);- _a = toDataURL;- return [4 /*yield*/, response.blob()];- case 3: return [4 /*yield*/, _a.apply(void 0, [_b.sent()])];- case 4:- dataurl = _b.sent();- onInsert({ src: dataurl, type: contentType, size: size });- return [3 /*break*/, 7];- case 5:- e_1 = _b.sent();- if (e_1 instanceof Error)- setError(e_1.message);- return [3 /*break*/, 7];- case 6:- setIsDownloading(false);- return [7 /*endfinally*/];- case 7: return [2 /*return*/];- }- });- }); },- } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { px: 1, flexDirection: "column", width: ["auto", 350] } }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { type: "url", autoFocus: true, placeholder: "Paste Image URL here", value: url, onChange: function (e) {- setUrl(e.target.value);- setError(undefined);- } }), error ? ((0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "error", sx: {- bg: "errorBg",- mt: 1,- p: 1,- borderRadius: "default",- } }, { children: ["Failed to download image: ", error.toLowerCase(), "."] }))) : ((0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "subBody", sx: {- bg: "shade",- color: "primary",- mt: 1,- p: 1,- borderRadius: "default",- } }, { children: "To protect your privacy, we will download the image & add it to your attachments." })))] })) })));-}-exports.ImageUploadPopup = ImageUploadPopup;-function toDataURL(blob) {- return new Promise(function (resolve, reject) {- var reader = new FileReader();- reader.onload = function (_e) { return resolve(reader.result); };- reader.onerror = function (_e) { return reject(reader.error); };- reader.onabort = function (_e) { return reject(new Error("Read aborted")); };- reader.readAsDataURL(blob);- });-}diff --git a/packages/editor/dist/toolbar/popups/linkpopup.js b/packages/editor/dist/toolbar/popups/linkpopup.jsdeleted file mode 100644index 96f3297e7..000000000--- a/packages/editor/dist/toolbar/popups/linkpopup.js+++ /dev/null@@ -1,45 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.LinkPopup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var forms_1 = require("@rebass/forms");-var react_1 = require("react");-var rebass_1 = require("rebass");-var popup_1 = require("../components/popup");-function LinkPopup(props) {- var _text = props.text, _href = props.href, _a = props.isEditing, isEditing = _a === void 0 ? false : _a, onDone = props.onDone, onClose = props.onClose;- var _b = __read((0, react_1.useState)(_href || ""), 2), href = _b[0], setHref = _b[1];- var _c = __read((0, react_1.useState)(_text || ""), 2), text = _c[0], setText = _c[1];- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ title: isEditing ? "Edit link" : "Insert link", onClose: onClose, action: {- title: isEditing ? "Save edits" : "Insert link",- onClick: function () { return onDone({ text: text, href: href }); },- } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { p: 1, flexDirection: "column", width: ["auto", 250] } }, { children: [(0, jsx_runtime_1.jsx)(forms_1.Input, { type: "text", placeholder: "Link text", value: text, onChange: function (e) { return setText(e.target.value); } }), (0, jsx_runtime_1.jsx)(forms_1.Input, { type: "url", sx: { mt: 1 }, autoFocus: true, placeholder: "https://example.com/", value: href, onChange: function (e) { return setHref(e.target.value); } })] })) })));-}-exports.LinkPopup = LinkPopup;diff --git a/packages/editor/dist/toolbar/popups/searchreplace.js b/packages/editor/dist/toolbar/popups/searchreplace.jsdeleted file mode 100644index 846f396ad..000000000--- a/packages/editor/dist/toolbar/popups/searchreplace.js+++ /dev/null@@ -1,113 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.SearchReplacePopup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var forms_1 = require("@rebass/forms");-var react_1 = require("react");-var rebass_1 = require("rebass");-var toolbutton_1 = require("../components/toolbutton");-function SearchReplacePopup(props) {- var editor = props.editor;- var _a = editor.storage- .searchreplace, selectedText = _a.selectedText, results = _a.results;- var _b = __read((0, react_1.useState)(false), 2), isReplacing = _b[0], setIsReplacing = _b[1];- var _c = __read((0, react_1.useState)(false), 2), isExpanded = _c[0], setIsExpanded = _c[1];- var _d = __read((0, react_1.useState)(false), 2), matchCase = _d[0], setMatchCase = _d[1];- var _e = __read((0, react_1.useState)(false), 2), matchWholeWord = _e[0], setMatchWholeWord = _e[1];- var _f = __read((0, react_1.useState)(false), 2), enableRegex = _f[0], setEnableRegex = _f[1];- var replaceText = (0, react_1.useRef)("");- var searchInputRef = (0, react_1.useRef)();- var search = (0, react_1.useCallback)(function (term) {- editor.commands.search(term, {- matchCase: matchCase,- enableRegex: enableRegex,- matchWholeWord: matchWholeWord,- });- }, [matchCase, enableRegex, matchWholeWord]);- (0, react_1.useEffect)(function () {- if (!searchInputRef.current)- return;- search(searchInputRef.current.value);- }, [search, matchCase, matchWholeWord, enableRegex]);- (0, react_1.useEffect)(function () {- if (selectedText) {- if (searchInputRef.current) {- var input_1 = searchInputRef.current;- setTimeout(function () {- input_1.value = selectedText;- input_1.focus();- }, 0);- }- search(selectedText);- }- }, [selectedText, search]);- return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {- p: 1,- bg: "background",- flexDirection: "column",- boxShadow: ["none", "menu"],- borderRadius: [0, "default"],- } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { flexDirection: "column", flex: 1, width: ["auto", 300], mr: 1 } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.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: [(0, jsx_runtime_1.jsx)(forms_1.Input, { variant: "clean", defaultValue: selectedText, ref: searchInputRef, autoFocus: true, placeholder: "Find", sx: { p: 0 }, onChange: function (e) {- search(e.target.value);- } }), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- flexShrink: 0,- mr: 0,- alignItems: "center",- } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.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 && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {- mr: 0,- }, toggled: matchCase, title: "Match case", id: "matchCase", icon: "caseSensitive", onClick: function () { return setMatchCase(function (s) { return !s; }); }, iconSize: "medium" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {- mr: 0,- }, toggled: matchWholeWord, title: "Match whole word", id: "matchWholeWord", icon: "wholeWord", onClick: function () { return setMatchWholeWord(function (s) { return !s; }); }, iconSize: "medium" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { sx: {- mr: 0,- }, toggled: enableRegex, title: "Enable regex", id: "enableRegex", icon: "regex", onClick: function () { return setEnableRegex(function (s) { return !s; }); }, iconSize: "medium" })] })), (0, jsx_runtime_1.jsxs)(rebass_1.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 && ((0, jsx_runtime_1.jsx)(forms_1.Input, { sx: { mt: 1, p: "7px" }, placeholder: "Replace", onChange: function (e) { return (replaceText.current = e.target.value); } }))] })), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { flexDirection: "column" } }, { children: [(0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { alignItems: "center", height: "33.2px" } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: isReplacing, title: "Toggle replace", id: "toggleReplace", icon: "replace", onClick: function () { return setIsReplacing(function (s) { return !s; }); }, sx: { mr: 0 }, iconSize: "big" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Previous match", id: "previousMatch", icon: "previousMatch", onClick: function () { return editor.commands.moveToPreviousResult(); }, sx: { mr: 0 }, iconSize: "big" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Next match", id: "nextMatch", icon: "nextMatch", onClick: function () { return editor.commands.moveToNextResult(); }, sx: { mr: 0 }, iconSize: "big" }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Close", id: "close", icon: "close", onClick: function () { return editor.chain().focus().endSearch().run(); }, sx: { mr: 0 }, iconSize: "big" })] })), isReplacing && ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { alignItems: "center", height: "33.2px", mt: 1 } }, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Replace", id: "replace", icon: "replaceOne", onClick: function () { return editor.commands.replace(replaceText.current); }, sx: { mr: 0 }, iconSize: 18 }), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, { toggled: false, title: "Replace all", id: "replaceAll", icon: "replaceAll", onClick: function () { return editor.commands.replaceAll(replaceText.current); }, sx: { mr: 0 }, iconSize: 18 })] })))] }))] }) })));-}-exports.SearchReplacePopup = SearchReplacePopup;diff --git a/packages/editor/dist/toolbar/popups/tablepopup.js b/packages/editor/dist/toolbar/popups/tablepopup.jsdeleted file mode 100644index 66ba1de45..000000000--- a/packages/editor/dist/toolbar/popups/tablepopup.js+++ /dev/null@@ -1,140 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TablePopup = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("react");-var popup_1 = require("../components/popup");-var toolbarstore_1 = require("../stores/toolbarstore");-var inlineinput_1 = require("../../components/inlineinput");-var MAX_COLUMNS = 20;-var MAX_ROWS = 20;-var MIN_COLUMNS = 10;-var MIN_ROWS = 6;-function TablePopup(props) {- var isMobile = (0, toolbarstore_1.useIsMobile)();- var autoExpand = !isMobile;- var cellSize = isMobile ? 30 : 15;- var onInsertTable = props.onInsertTable;- var _a = __read((0, react_1.useState)({- column: 0,- row: 0,- }), 2), cellLocation = _a[0], setCellLocation = _a[1];- var _b = __read((0, react_1.useState)({- columns: MIN_COLUMNS,- rows: MIN_ROWS,- }), 2), tableSize = _b[0], setTableSize = _b[1];- (0, react_1.useEffect)(function () {- if (!autoExpand)- return;- setTableSize(function (old) {- var columns = old.columns, rows = old.rows;- var column = cellLocation.column, row = cellLocation.row;- var isDecrease = row === rows - 2 || column === columns - 2;- var rowFactor = Number(row === rows || row === rows - 2);- var columnFactor = Number(column === columns || column === columns - 2);- return {- columns: isDecrease- ? Math.max(column + columnFactor, MIN_COLUMNS)- : Math.min(old.columns + columnFactor, MAX_COLUMNS),- rows: isDecrease- ? Math.max(row + rowFactor, MIN_ROWS)- : Math.min(old.rows + rowFactor, MAX_ROWS),- };- });- }, [cellLocation, autoExpand]);- return ((0, jsx_runtime_1.jsx)(popup_1.Popup, __assign({ action: {- title: !cellLocation.column || !cellLocation.row- ? "Please set a table size"- : "Insert a ".concat(cellLocation.column, " x ").concat(cellLocation.row, " table"),- disabled: !cellLocation.column || !cellLocation.row,- onClick: function () {- return onInsertTable({- columns: cellLocation.column,- rows: cellLocation.row,- });- },- } }, { children: (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { px: 1, pt: 1, flexDirection: "column", alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ sx: {- display: "grid",- gridTemplateColumns: "repeat(".concat(tableSize.columns, ", minmax(").concat(cellSize, "px, 1fr))"),- gap: "small",- bg: "background",- width: "100%",- }, onTouchMove: function (e) {- var touch = e.touches.item(0);- var element = document.elementFromPoint(touch.pageX, touch.pageY);- if (!element)- return;- var index = element.dataset.index;- if (!index)- return;- setCellLocation(getCellLocation(parseInt(index), tableSize));- } }, { children: Array(tableSize.columns * tableSize.rows)- .fill(0)- .map(function (_, index) { return ((0, jsx_runtime_1.jsx)(rebass_1.Box, { "data-index": index, height: cellSize || 15, sx: {- border: "1px solid var(--disabled)",- borderRadius: "small",- bg: isCellHighlighted(index, cellLocation, tableSize)- ? "disabled"- : "transparent",- }, onTouchStart: function () {- setCellLocation(getCellLocation(index, tableSize));- }, onMouseEnter: function () {- setCellLocation(getCellLocation(index, tableSize));- }, onClick: function () {- onInsertTable({- columns: cellLocation.column,- rows: cellLocation.row,- });- } }, index)); }) })), (0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: {- display: ["flex", "none", "none"],- mt: 1,- alignItems: "center",- justifyContent: "center",- } }, { children: [(0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { containerProps: { sx: { mr: 1 } }, label: "columns", placeholder: "".concat(cellLocation.column, " columns"), type: "number", value: cellLocation.column, onChange: function (e) {- setCellLocation(function (l) { return (__assign(__assign({}, l), { column: e.target.valueAsNumber || 0 })); });- } }), (0, jsx_runtime_1.jsx)(inlineinput_1.InlineInput, { label: "rows", placeholder: "".concat(cellLocation.row, " rows"), type: "number", value: cellLocation.row, onChange: function (e) {- setCellLocation(function (l) { return (__assign(__assign({}, l), { row: e.target.valueAsNumber || 0 })); });- } })] })), (0, jsx_runtime_1.jsxs)(rebass_1.Text, __assign({ variant: "body", sx: { mt: 1, display: ["none", "block", "block"] } }, { children: [cellLocation.column, " x ", cellLocation.row] }))] })) })));-}-exports.TablePopup = TablePopup;-function getCellLocation(index, tableSize) {- var cellIndex = index + 1;- var column = cellIndex % tableSize.columns;- var row = cellIndex / tableSize.columns;- var flooredRow = Math.floor(row);- row = row === flooredRow ? row : flooredRow + 1;- return { column: column ? column : tableSize.columns, row: row };-}-function isCellHighlighted(index, currentCellLocation, tableSize) {- var cellLocation = getCellLocation(index, tableSize);- return (cellLocation.row <= currentCellLocation.row &&- cellLocation.column <= currentCellLocation.column);-}diff --git a/packages/editor/dist/toolbar/stores/toolbarstore.js b/packages/editor/dist/toolbar/stores/toolbarstore.jsdeleted file mode 100644index cc0656c9c..000000000--- a/packages/editor/dist/toolbar/stores/toolbarstore.js+++ /dev/null@@ -1,64 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.useIsMobile = exports.useToolbarLocation = exports.useToolbarStore = void 0;-var zustand_1 = __importDefault(require("zustand"));-exports.useToolbarStore = (0, zustand_1.default)(function (set, get) { return ({- isMobile: false,- openedPopups: {},- setIsMobile: function (isMobile) {- return set(function (state) {- state.isMobile = isMobile;- });- },- toolbarLocation: "top",- setToolbarLocation: function (location) {- return set(function (state) {- state.toolbarLocation = location;- });- },- closePopup: function (id) {- return set(function (state) {- var _a;- state.openedPopups = __assign(__assign({}, state.openedPopups), (_a = {}, _a[id] = false, _a));- });- },- isPopupOpen: function (id) { return !!get().openedPopups[id]; },- openPopup: function (ref) {- return set(function (state) {- var _a;- state.openedPopups = __assign(__assign({}, state.openedPopups), (_a = {}, _a[ref.id] = ref, _a));- });- },- closePopupGroup: function (group, excluded) {- return set(function (state) {- for (var key in state.openedPopups) {- var ref = state.openedPopups[key];- if (ref && ref.group === group && !excluded.includes(ref.id)) {- state.openedPopups[key] = false;- }- }- });- },-}); });-function useToolbarLocation() {- return (0, exports.useToolbarStore)(function (store) { return store.toolbarLocation; });-}-exports.useToolbarLocation = useToolbarLocation;-function useIsMobile() {- return (0, exports.useToolbarStore)(function (store) { return store.isMobile; });-}-exports.useIsMobile = useIsMobile;diff --git a/packages/editor/dist/toolbar/toolbar.js b/packages/editor/dist/toolbar/toolbar.jsdeleted file mode 100644index 9674507b9..000000000--- a/packages/editor/dist/toolbar/toolbar.js+++ /dev/null@@ -1,44 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Toolbar = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var emotion_theming_1 = require("emotion-theming");-var floatingmenus_1 = require("./floatingmenus");-var tooldefinitions_1 = require("./tooldefinitions");-var react_1 = require("react");-var toolbarstore_1 = require("./stores/toolbarstore");-var toolbargroup_1 = require("./components/toolbargroup");-var popuprenderer_1 = require("../components/popup-presenter/popuprenderer");-function Toolbar(props) {- var editor = props.editor, theme = props.theme, location = props.location, isMobile = props.isMobile, _a = props.tools, tools = _a === void 0 ? tooldefinitions_1.DEFAULT_TOOLS : _a;- var setIsMobile = (0, toolbarstore_1.useToolbarStore)(function (store) { return store.setIsMobile; });- var setToolbarLocation = (0, toolbarstore_1.useToolbarStore)(function (store) { return store.setToolbarLocation; });- (0, react_1.useEffect)(function () {- setIsMobile(isMobile || false);- setToolbarLocation(location);- }, [isMobile, location]);- if (!editor)- return null;- return ((0, jsx_runtime_1.jsx)(emotion_theming_1.ThemeProvider, __assign({ theme: theme }, { children: (0, jsx_runtime_1.jsx)(popuprenderer_1.EditorContext.Provider, __assign({ value: editor }, { children: (0, jsx_runtime_1.jsxs)(popuprenderer_1.PopupRenderer, __assign({ editor: editor }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ className: "editor-toolbar", sx: { flexWrap: ["nowrap", "wrap"], overflowX: ["auto", "hidden"] } }, { children: tools.map(function (tools) {- return ((0, jsx_runtime_1.jsx)(toolbargroup_1.ToolbarGroup, { tools: tools, editor: editor, sx: {- flexShrink: 0,- pr: 2,- mr: 2,- borderRight: "1px solid var(--border)",- ":last-of-type": { mr: 0, pr: 0, borderRight: "none" },- } }, tools.join("")));- }) })), (0, jsx_runtime_1.jsx)(floatingmenus_1.EditorFloatingMenus, { editor: editor })] })) })) })));-}-exports.Toolbar = Toolbar;diff --git a/packages/editor/dist/toolbar/tooldefinitions.d.ts b/packages/editor/dist/toolbar/tooldefinitions.d.tsdeleted file mode 100644index 71e62199d..000000000--- a/packages/editor/dist/toolbar/tooldefinitions.d.ts+++ /dev/null@@ -1,5 +0,0 @@-import { ToolbarDefinition, ToolDefinition } from "./types";-import { ToolId } from "./tools";-export declare function getToolDefinition(id: ToolId): ToolDefinition;-export declare function getAllTools(): Record<"bold" | "italic" | "underline" | "strikethrough" | "code" | "codeRemove" | "subscript" | "superscript" | "clearformatting" | "addLink" | "editLink" | "removeLink" | "linkSettings" | "openLink" | "insertBlock" | "numberedList" | "bulletList" | "fontSize" | "fontFamily" | "headings" | "alignCenter" | "alignRight" | "alignLeft" | "alignJustify" | "ltr" | "rtl" | "textColor" | "highlight" | "math" | "imageSettings" | "imageAlignCenter" | "imageAlignLeft" | "imageAlignRight" | "imageProperties" | "embedAlignCenter" | "embedAlignLeft" | "embedAlignRight" | "embedProperties" | "embedSettings" | "attachmentSettings" | "downloadAttachment" | "removeAttachment" | "tableSettings" | "columnProperties" | "rowProperties" | "cellProperties" | "insertColumnLeft" | "insertColumnRight" | "moveColumnLeft" | "moveColumnRight" | "deleteColumn" | "splitCells" | "mergeCells" | "cellBackgroundColor" | "cellBorderColor" | "cellTextColor" | "cellBorderWidth" | "insertRowAbove" | "insertRowBelow" | "moveRowUp" | "moveRowDown" | "deleteRow" | "deleteTable", ToolDefinition>;-export declare const DEFAULT_TOOLS: ToolbarDefinition;diff --git a/packages/editor/dist/toolbar/tools/alignment.js b/packages/editor/dist/toolbar/tools/alignment.jsdeleted file mode 100644index c7418a4a0..000000000--- a/packages/editor/dist/toolbar/tools/alignment.js+++ /dev/null@@ -1,47 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.AlignJustify = exports.AlignRight = exports.AlignLeft = exports.AlignCenter = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-function AlignmentTool(props) {- var editor = props.editor, alignment = props.alignment, toolProps = __rest(props, ["editor", "alignment"]);- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, toolProps, { onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextAlign(alignment).run(); }, toggled: editor.isActive({ textAlign: alignment }) })));-}-function AlignCenter(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, __assign({ alignment: "center" }, props));-}-exports.AlignCenter = AlignCenter;-function AlignLeft(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, __assign({ alignment: "left" }, props));-}-exports.AlignLeft = AlignLeft;-function AlignRight(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, __assign({ alignment: "right" }, props));-}-exports.AlignRight = AlignRight;-function AlignJustify(props) {- return (0, jsx_runtime_1.jsx)(AlignmentTool, __assign({ alignment: "justify" }, props));-}-exports.AlignJustify = AlignJustify;diff --git a/packages/editor/dist/toolbar/tools/attachment.js b/packages/editor/dist/toolbar/tools/attachment.jsdeleted file mode 100644index 4935853c9..000000000--- a/packages/editor/dist/toolbar/tools/attachment.js+++ /dev/null@@ -1,42 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.RemoveAttachment = exports.DownloadAttachment = exports.AttachmentSettings = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-var moretools_1 = require("../components/moretools");-var toolbarstore_1 = require("../stores/toolbarstore");-var prosemirror_1 = require("../utils/prosemirror");-function AttachmentSettings(props) {- var editor = props.editor;- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- if (!editor.isActive("attachment") || !isBottom)- return null;- return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, __assign({}, props, { autoCloseOnUnmount: true, popupId: "attachmentSettings", tools: [] })));-}-exports.AttachmentSettings = AttachmentSettings;-function DownloadAttachment(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- var attachmentNode = (0, prosemirror_1.findSelectedNode)(editor, "attachment");- var attachment = ((attachmentNode === null || attachmentNode === void 0 ? void 0 : attachmentNode.attrs) || {});- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().downloadAttachment(attachment).run();- } })));-}-exports.DownloadAttachment = DownloadAttachment;-function RemoveAttachment(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().removeAttachment().run(); } })));-}-exports.RemoveAttachment = RemoveAttachment;diff --git a/packages/editor/dist/toolbar/tools/block.js b/packages/editor/dist/toolbar/tools/block.jsdeleted file mode 100644index defa207b7..000000000--- a/packages/editor/dist/toolbar/tools/block.js+++ /dev/null@@ -1,274 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.InsertBlock = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var icons_1 = require("../icons");-var react_1 = require("react");-var icon_1 = require("../components/icon");-var embedpopup_1 = require("../popups/embedpopup");-var tablepopup_1 = require("../popups/tablepopup");-var toolbarstore_1 = require("../stores/toolbarstore");-var responsive_1 = require("../../components/responsive");-var popuppresenter_1 = require("../../components/popuppresenter");-var imageupload_1 = require("../popups/imageupload");-var button_1 = require("../../components/button");-function InsertBlock(props) {- var editor = props.editor;- var buttonRef = (0, react_1.useRef)(null);- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- var isMobile = (0, toolbarstore_1.useIsMobile)();- var menuItems = (0, react_1.useMemo)(function () {- return [- tasklist(editor),- outlinelist(editor),- horizontalRule(editor),- codeblock(editor),- mathblock(editor),- blockquote(editor),- image(editor, isMobile),- attachment(editor),- isMobile ? embedMobile(editor) : embedDesktop(editor),- table(editor),- ];- }, [isMobile]);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(button_1.Button, __assign({ ref: buttonRef, sx: {- p: 1,- m: 0,- bg: isOpen ? "hover" : "transparent",- mr: 1,- display: "flex",- alignItems: "center",- ":hover": { bg: "hover" },- ":last-of-type": {- mr: 0,- },- }, onMouseDown: function (e) { return e.preventDefault(); }, onClick: function () { return setIsOpen(function (s) { return !s; }); } }, { children: (0, jsx_runtime_1.jsx)(icon_1.Icon, { path: icons_1.Icons.plus, size: 18, color: "primary" }) })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { desktop: "menu", mobile: "sheet", title: "Choose a block to insert", isOpen: isOpen, items: menuItems, onClose: function () { return setIsOpen(false); }, position: {- target: buttonRef.current || undefined,- isTargetAbsolute: true,- location: toolbarLocation === "bottom" ? "top" : "below",- yOffset: 5,- } })] }));-}-exports.InsertBlock = InsertBlock;-var horizontalRule = function (editor) { return ({- key: "hr",- type: "button",- title: "Horizontal rule",- icon: "horizontalRule",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("horizontalRule"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setHorizontalRule().run(); },-}); };-var codeblock = function (editor) { return ({- key: "codeblock",- type: "button",- title: "Code block",- icon: "codeblock",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("codeBlock"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleCodeBlock().run(); },-}); };-var blockquote = function (editor) { return ({- key: "blockquote",- type: "button",- title: "Quote",- icon: "blockquote",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("blockQuote"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBlockquote().run(); },-}); };-var mathblock = function (editor) { return ({- key: "math",- type: "button",- title: "Math & formulas",- icon: "mathBlock",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("mathBlock"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathBlock().run(); },-}); };-var image = function (editor, isMobile) { return ({- key: "image",- type: "button",- title: "Image",- icon: "image",- menu: {- title: "Insert an image",- items: [- {- key: "upload-from-disk",- type: "button",- title: "Upload from disk",- icon: "upload",- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("image").run(); },- },- {- key: "camera",- type: "button",- title: "Take a photo using camera",- icon: "camera",- isHidden: !isMobile,- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("camera").run(); },- },- isMobile ? uploadImageFromURLMobile(editor) : uploadImageFromURL(editor),- ],- },-}); };-var table = function (editor) { return ({- key: "table",- type: "button",- title: "Table",- icon: "table",- menu: {- title: "Insert a table",- items: [- {- key: "table-size-selector",- type: "popup",- component: function (props) { return ((0, jsx_runtime_1.jsx)(tablepopup_1.TablePopup, { onInsertTable: function (size) {- var _a, _b;- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertTable({- rows: size.rows,- cols: size.columns,- }).run();- (_b = props.onClick) === null || _b === void 0 ? void 0 : _b.call(props);- } })); },- },- ],- },-}); };-var embedMobile = function (editor) { return ({- key: "embed",- type: "button",- title: "Embed",- icon: "embed",- menu: {- title: "Insert an embed",- items: [- {- key: "embed-popup",- type: "popup",- component: function (_a) {- var onClick = _a.onClick;- return ((0, jsx_runtime_1.jsx)(embedpopup_1.EmbedPopup, { title: "Insert embed", onClose: function (embed) {- var _a;- if (!embed)- return onClick === null || onClick === void 0 ? void 0 : onClick();- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().insertEmbed(embed).run();- onClick === null || onClick === void 0 ? void 0 : onClick();- } }));- },- },- ],- },-}); };-var embedDesktop = function (editor) { return ({- key: "embed",- type: "button",- title: "Embed",- icon: "embed",- onClick: function () {- if (!editor)- return;- (0, popuppresenter_1.showPopup)({- theme: editor.storage.theme,- popup: function (hide) { return ((0, jsx_runtime_1.jsx)(embedpopup_1.EmbedPopup, { title: "Insert embed", onClose: function (embed) {- var _a;- if (!embed)- return hide();- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().insertEmbed(embed).run();- hide();- } })); },- });- },-}); };-var attachment = function (editor) { return ({- key: "attachment",- type: "button",- title: "Attachment",- icon: "attachment",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("attachment"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().openAttachmentPicker("file").run(); },-}); };-var tasklist = function (editor) { return ({- key: "tasklist",- type: "button",- title: "Task list",- icon: "checkbox",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("taskList"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleTaskList().run(); },-}); };-var outlinelist = function (editor) { return ({- key: "outlinelist",- type: "button",- title: "Outline list",- icon: "outlineList",- isChecked: editor === null || editor === void 0 ? void 0 : editor.isActive("outlineList"),- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOutlineList().run(); },-}); };-var uploadImageFromURLMobile = function (editor) { return ({- key: "upload-from-url",- type: "button",- title: "Attach from URL",- icon: "link",- menu: {- title: "Attach image from URL",- items: [- {- key: "attach-image",- type: "popup",- component: function (_a) {- var onClick = _a.onClick;- return ((0, jsx_runtime_1.jsx)(imageupload_1.ImageUploadPopup, { onInsert: function (image) {- var _a;- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertImage(image).run();- onClick === null || onClick === void 0 ? void 0 : onClick();- }, onClose: function () {- onClick === null || onClick === void 0 ? void 0 : onClick();- } }));- },- },- ],- },-}); };-var uploadImageFromURL = function (editor) { return ({- key: "upload-from-url",- type: "button",- title: "Attach from URL",- icon: "link",- onClick: function () {- if (!editor)- return;- (0, popuppresenter_1.showPopup)({- theme: editor.storage.theme,- popup: function (hide) { return ((0, jsx_runtime_1.jsx)(imageupload_1.ImageUploadPopup, { onInsert: function (image) {- var _a;- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertImage(image).run();- hide();- }, onClose: hide })); },- });- },-}); };diff --git a/packages/editor/dist/toolbar/tools/colors.js b/packages/editor/dist/toolbar/tools/colors.jsdeleted file mode 100644index ae5883f57..000000000--- a/packages/editor/dist/toolbar/tools/colors.js+++ /dev/null@@ -1,124 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {- if (k2 === undefined) k2 = k;- var desc = Object.getOwnPropertyDescriptor(m, k);- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {- desc = { enumerable: true, get: function() { return m[k]; } };- }- Object.defineProperty(o, k2, desc);-}) : (function(o, m, k, k2) {- if (k2 === undefined) k2 = k;- o[k2] = m[k];-}));-var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {- Object.defineProperty(o, "default", { enumerable: true, value: v });-}) : function(o, v) {- o["default"] = v;-});-var __importStar = (this && this.__importStar) || function (mod) {- if (mod && mod.__esModule) return mod;- var result = {};- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);- __setModuleDefault(result, mod);- return result;-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.TextColor = exports.Highlight = exports.ColorTool = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var react_1 = __importStar(require("react"));-var tinycolor2_1 = __importDefault(require("tinycolor2"));-var popuppresenter_1 = require("../../components/popuppresenter");-var config_1 = require("../../utils/config");-var splitbutton_1 = require("../components/splitbutton");-var colorpicker_1 = require("../popups/colorpicker");-var toolbarstore_1 = require("../stores/toolbarstore");-var dom_1 = require("../utils/dom");-// TODO test rerendering-function _ColorTool(props) {- var editor = props.editor, onColorChange = props.onColorChange, getActiveColor = props.getActiveColor, title = props.title, cacheKey = props.cacheKey, toolProps = __rest(props, ["editor", "onColorChange", "getActiveColor", "title", "cacheKey"]);- var activeColor = getActiveColor() || config_1.config.get(cacheKey);- var tColor = (0, tinycolor2_1.default)(activeColor);- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- return ((0, jsx_runtime_1.jsx)(splitbutton_1.SplitButton, __assign({}, toolProps, { iconColor: activeColor && tColor.isDark() ? "static" : "icon", sx: {- mr: 0,- bg: activeColor || "transparent",- ":hover": {- bg: activeColor ? tColor.darken(5).toRgbString() : "transparent",- },- }, onOpen: function () { return setIsOpen(function (s) { return !s; }); }, toggled: isOpen, onClick: function () { return onColorChange(activeColor); } }, { children: (0, jsx_runtime_1.jsx)(popuppresenter_1.PopupWrapper, { isOpen: isOpen, id: props.icon, group: "color", position: {- isTargetAbsolute: true,- target: (0, dom_1.getToolbarElement)(),- align: isBottom ? "center" : "end",- location: isBottom ? "top" : "below",- yOffset: 10,- }, focusOnRender: false, blocking: false, renderPopup: function (close) { return ((0, jsx_runtime_1.jsx)(colorpicker_1.ColorPicker, { color: activeColor, onClear: function () {- onColorChange();- config_1.config.set(cacheKey, null);- }, onChange: function (color) {- onColorChange(color);- config_1.config.set(cacheKey, color);- }, onClose: close, title: title })); } }) })));-}-exports.ColorTool = react_1.default.memo(_ColorTool, function () { return true; });-function Highlight(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(exports.ColorTool, __assign({}, props, { cacheKey: "highlight", getActiveColor: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("highlight").color; }, title: "Background color", onColorChange: function (color) {- var _a, _b;- return color- ? (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleHighlight({ color: color }).run()- : (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetHighlight().run();- } })));-}-exports.Highlight = Highlight;-function TextColor(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(exports.ColorTool, __assign({}, props, { cacheKey: "textColor", getActiveColor: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("textStyle").color; }, title: "Text color", onColorChange: function (color) {- var _a, _b;- return color- ? (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setColor(color).run()- : (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetColor().run();- } })));-}-exports.TextColor = TextColor;diff --git a/packages/editor/dist/toolbar/tools/embed.js b/packages/editor/dist/toolbar/tools/embed.jsdeleted file mode 100644index b6a02c547..000000000--- a/packages/editor/dist/toolbar/tools/embed.js+++ /dev/null@@ -1,87 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.EmbedProperties = exports.EmbedAlignCenter = exports.EmbedAlignRight = exports.EmbedAlignLeft = exports.EmbedSettings = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-var react_1 = require("react");-var responsive_1 = require("../../components/responsive");-var moretools_1 = require("../components/moretools");-var toolbarstore_1 = require("../stores/toolbarstore");-var prosemirror_1 = require("../utils/prosemirror");-var embedpopup_1 = require("../popups/embedpopup");-function EmbedSettings(props) {- var editor = props.editor;- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- if (!editor.isActive("embed") || !isBottom)- return null;- return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, __assign({}, props, { autoCloseOnUnmount: true, popupId: "embedSettings", tools: [] })));-}-exports.EmbedSettings = EmbedSettings;-function EmbedAlignLeft(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "left" }).run();- } })));-}-exports.EmbedAlignLeft = EmbedAlignLeft;-function EmbedAlignRight(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "right" }).run();- } })));-}-exports.EmbedAlignRight = EmbedAlignRight;-function EmbedAlignCenter(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setEmbedAlignment({ align: "center" }).run();- } })));-}-exports.EmbedAlignCenter = EmbedAlignCenter;-// TODO: stop re-rendering-function EmbedProperties(props) {- var editor = props.editor;- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var buttonRef = (0, react_1.useRef)();- // TODO: improve perf by deferring this until user opens the popup- var embedNode = (0, react_1.useMemo)(function () { return (0, prosemirror_1.findSelectedNode)(editor, "embed"); }, []);- var embed = ((embedNode === null || embedNode === void 0 ? void 0 : embedNode.attrs) || {});- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({ buttonRef: buttonRef, toggled: isOpen }, props, { onClick: function () { return setIsOpen(function (s) { return !s; }); } })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, __assign({ isOpen: isOpen, desktop: "menu", mobile: "sheet", onClose: function () { return setIsOpen(false); }, blocking: true, focusOnRender: false, position: {- target: buttonRef.current || "mouse",- align: "start",- location: "below",- yOffset: 10,- isTargetAbsolute: true,- } }, { children: (0, jsx_runtime_1.jsx)(embedpopup_1.EmbedPopup, { title: "Embed properties", onClose: function () { return setIsOpen(false); }, embed: embed, onSourceChanged: function (src) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSource(src); }, onSizeChanged: function (size) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setEmbedSize(size); } }) }))] }));-}-exports.EmbedProperties = EmbedProperties;diff --git a/packages/editor/dist/toolbar/tools/font.js b/packages/editor/dist/toolbar/tools/font.jsdeleted file mode 100644index ec7549525..000000000--- a/packages/editor/dist/toolbar/tools/font.js+++ /dev/null@@ -1,78 +0,0 @@-"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.FontFamily = exports.FontSize = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var dropdown_1 = require("../components/dropdown");-var react_1 = require("react");-var counter_1 = require("../components/counter");-var useRefValue_1 = require("../../hooks/useRefValue");-function FontSize(props) {- var editor = props.editor;- var _fontSize = editor.getAttributes("textStyle").fontSize;- var fontSize = _fontSize || "16px";- var fontSizeAsNumber = (0, useRefValue_1.useRefValue)(parseInt(fontSize.replace("px", "")));- var decreaseFontSize = (0, react_1.useCallback)(function () {- return Math.max(8, fontSizeAsNumber.current - 1);- }, []);- var increaseFontSize = (0, react_1.useCallback)(function () {- return Math.min(120, fontSizeAsNumber.current + 1);- }, []);- return ((0, jsx_runtime_1.jsx)(counter_1.Counter, { title: "font size", onDecrease: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize("".concat(decreaseFontSize(), "px")).run();- }, onIncrease: function () {- var _a;- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize("".concat(increaseFontSize(), "px")).run();- }, onReset: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontSize("16px").run(); }, value: fontSize }));-}-exports.FontSize = FontSize;-var fontFamilies = {- System: "Open Sans",- Serif: "serif",- Monospace: "monospace",-};-function FontFamily(props) {- var _a, _b;- var editor = props.editor;- var currentFontFamily = ((_b = (_a = Object.entries(fontFamilies)- .find(function (_a) {- var _b = __read(_a, 2), key = _b[0], value = _b[1];- return editor.isActive("textStyle", { fontFamily: value });- })) === null || _a === void 0 ? void 0 : _a.map(function (a) { return a; })) === null || _b === void 0 ? void 0 : _b.at(0)) || "System";- var items = (0, react_1.useMemo)(function () { return toMenuItems(editor, currentFontFamily); }, [currentFontFamily]);- return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentFontFamily, items: items, menuWidth: 130 }));-}-exports.FontFamily = FontFamily;-function toMenuItems(editor, currentFontFamily) {- var menuItems = [];- var _loop_1 = function (key) {- var value = fontFamilies[key];- menuItems.push({- key: key,- type: "button",- title: key,- isChecked: key === currentFontFamily,- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setFontFamily(value).run(); },- });- };- for (var key in fontFamilies) {- _loop_1(key);- }- return menuItems;-}diff --git a/packages/editor/dist/toolbar/tools/headings.js b/packages/editor/dist/toolbar/tools/headings.jsdeleted file mode 100644index 811dffa22..000000000--- a/packages/editor/dist/toolbar/tools/headings.js+++ /dev/null@@ -1,63 +0,0 @@-"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Headings = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var dropdown_1 = require("../components/dropdown");-var toolbarstore_1 = require("../stores/toolbarstore");-var react_1 = require("react");-var defaultLevels = [1, 2, 3, 4, 5, 6];-function Headings(props) {- var editor = props.editor;- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- var currentHeadingLevel = defaultLevels.find(function (level) {- return editor.isActive("heading", { level: level });- });- var items = (0, react_1.useMemo)(function () { return toMenuItems(editor, toolbarLocation, currentHeadingLevel); }, [currentHeadingLevel]);- return ((0, jsx_runtime_1.jsx)(dropdown_1.Dropdown, { selectedItem: currentHeadingLevel ? "Heading ".concat(currentHeadingLevel) : "Paragraph", items: items, menuWidth: 130 }));-}-exports.Headings = Headings;-function toMenuItems(editor, toolbarLocation, currentHeadingLevel) {- var menuItems = defaultLevels.map(function (level) { return ({- type: "button",- key: "heading-".concat(level),- title: toolbarLocation === "bottom" ? "H".concat(level) : "Heading ".concat(level),- isChecked: level === currentHeadingLevel,- onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().updateAttributes("textStyle", { fontSize: null, fontStyle: null }).setHeading({ level: level }).run();- },- }); });- var paragraph = {- key: "paragraph",- type: "button",- title: "Paragraph",- isChecked: !currentHeadingLevel,- onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setParagraph().run(); },- };- return __spreadArray([paragraph], __read(menuItems), false);-}diff --git a/packages/editor/dist/toolbar/tools/image.js b/packages/editor/dist/toolbar/tools/image.jsdeleted file mode 100644index dccc86a59..000000000--- a/packages/editor/dist/toolbar/tools/image.js+++ /dev/null@@ -1,95 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.ImageProperties = exports.ImageAlignCenter = exports.ImageAlignRight = exports.ImageAlignLeft = exports.ImageSettings = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-var react_1 = require("react");-var responsive_1 = require("../../components/responsive");-var moretools_1 = require("../components/moretools");-var toolbarstore_1 = require("../stores/toolbarstore");-var imageproperties_1 = require("../popups/imageproperties");-var prosemirror_1 = require("../utils/prosemirror");-function ImageSettings(props) {- var _a, _b;- var editor = props.editor;- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- if (!editor.isActive("image") || !isBottom)- return null;- return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, __assign({}, props, { autoCloseOnUnmount: true, popupId: "imageSettings", tools: ((_b = (_a = (0, prosemirror_1.findSelectedNode)(editor, "image")) === null || _a === void 0 ? void 0 : _a.attrs) === null || _b === void 0 ? void 0 : _b.float)- ? ["imageAlignLeft", "imageAlignRight", "imageProperties"]- : [- "imageAlignLeft",- "imageAlignCenter",- "imageAlignRight",- "imageProperties",- ] })));-}-exports.ImageSettings = ImageSettings;-function ImageAlignLeft(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "left" }).run();- } })));-}-exports.ImageAlignLeft = ImageAlignLeft;-function ImageAlignRight(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "right" }).run();- } })));-}-exports.ImageAlignRight = ImageAlignRight;-function ImageAlignCenter(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setImageAlignment({ align: "center" }).run();- } })));-}-exports.ImageAlignCenter = ImageAlignCenter;-function ImageProperties(props) {- var editor = props.editor;- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var buttonRef = (0, react_1.useRef)();- // TODO: defer until user opens the popup- var image = (0, react_1.useMemo)(function () { return (0, prosemirror_1.findSelectedNode)(editor, "image"); }, []);- var _b = ((image === null || image === void 0 ? void 0 : image.attrs) ||- {}), float = _b.float, align = _b.align, width = _b.width, height = _b.height;- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({ buttonRef: buttonRef, toggled: isOpen }, props, { onClick: function () { return setIsOpen(function (s) { return !s; }); } })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, __assign({ isOpen: isOpen, desktop: "menu", mobile: "sheet", onClose: function () { return setIsOpen(false); }, blocking: true, focusOnRender: false, position: {- target: buttonRef.current || "mouse",- align: "start",- location: "below",- yOffset: 10,- isTargetAbsolute: true,- } }, { children: (0, jsx_runtime_1.jsx)(imageproperties_1.ImageProperties, { editor: editor, height: height, width: width, align: align, float: float, onClose: function () { return setIsOpen(false); } }) }))] }));-}-exports.ImageProperties = ImageProperties;diff --git a/packages/editor/dist/toolbar/tools/inline.js b/packages/editor/dist/toolbar/tools/inline.jsdeleted file mode 100644index 6902cb7fd..000000000--- a/packages/editor/dist/toolbar/tools/inline.js+++ /dev/null@@ -1,73 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.Math = exports.CodeRemove = exports.ClearFormatting = exports.Superscript = exports.Subscript = exports.Bold = exports.Code = exports.Underline = exports.Strikethrough = exports.Italic = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-var toolbarstore_1 = require("../stores/toolbarstore");-function Italic(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("italic"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleItalic().run(); } })));-}-exports.Italic = Italic;-function Strikethrough(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("strike"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleStrike().run(); } })));-}-exports.Strikethrough = Strikethrough;-function Underline(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("underline"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleUnderline().run(); } })));-}-exports.Underline = Underline;-function Code(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("code"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleCode().run(); } })));-}-exports.Code = Code;-function Bold(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("bold"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleBold().run(); } })));-}-exports.Bold = Bold;-function Subscript(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("subscript"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleSubscript().run(); } })));-}-exports.Subscript = Subscript;-function Superscript(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: editor.isActive("superscript"), onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleSuperscript().run(); } })));-}-exports.Superscript = Superscript;-function ClearFormatting(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().clearNodes().unsetAllMarks().unsetMark("link").run();- } })));-}-exports.ClearFormatting = ClearFormatting;-function CodeRemove(props) {- var editor = props.editor;- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- if (!editor.isActive("code") || !isBottom)- return null;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().unsetMark("code").run(); } })));-}-exports.CodeRemove = CodeRemove;-function Math(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().insertMathInline().run(); } })));-}-exports.Math = Math;diff --git a/packages/editor/dist/toolbar/tools/link.js b/packages/editor/dist/toolbar/tools/link.jsdeleted file mode 100644index 217b6b4d5..000000000--- a/packages/editor/dist/toolbar/tools/link.js+++ /dev/null@@ -1,156 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.OpenLink = exports.RemoveLink = exports.EditLink = exports.AddLink = exports.LinkSettings = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-var react_1 = require("react");-var responsive_1 = require("../../components/responsive");-var linkpopup_1 = require("../popups/linkpopup");-var toolbarstore_1 = require("../stores/toolbarstore");-var moretools_1 = require("../components/moretools");-var useRefValue_1 = require("../../hooks/useRefValue");-var prosemirror_1 = require("../utils/prosemirror");-var prosemirror_utils_1 = require("prosemirror-utils");-var rebass_1 = require("rebass");-function LinkSettings(props) {- var editor = props.editor;- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- if (!editor.isActive("link") || !isBottom)- return null;- return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, __assign({}, props, { autoCloseOnUnmount: true, popupId: "linkSettings", tools: ["openLink", "editLink", "removeLink"] })));-}-exports.LinkSettings = LinkSettings;-function AddLink(props) {- var editor = props.editor;- var isActive = props.editor.isActive("link");- var onDone = (0, react_1.useCallback)(function (href, text) {- var _a;- if (!href)- return;- var commandChain = (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus();- if (!commandChain)- return;- commandChain- .extendMarkRange("link")- .toggleLink({ href: href, target: "_blank" })- .insertContent(text || href)- .focus()- .unsetMark("link")- .insertContent(" ")- .run();- }, []);- if (isActive)- return (0, jsx_runtime_1.jsx)(EditLink, __assign({}, props));- return ((0, jsx_runtime_1.jsx)(LinkTool, __assign({}, props, { onDone: onDone, onClick: function () {- var _a = editor.state.selection, from = _a.from, to = _a.to;- var selectedText = editor.state.doc.textBetween(from, to);- return { text: selectedText };- } })));-}-exports.AddLink = AddLink;-function EditLink(props) {- var editor = props.editor, _selectedNode = props.selectedNode;- var selectedNode = (0, useRefValue_1.useRefValue)(_selectedNode || (0, prosemirror_1.selectionToOffset)(editor.state.selection));- var onDone = (0, react_1.useCallback)(function (href, text) {- if (!href || !editor.current)- return;- var _a = selectedNode.current, from = _a.from, node = _a.node, to = _a.to;- var mark = (0, prosemirror_1.findMark)(node, "link");- if (!mark)- return;- editor.current- .chain()- .command(function (_a) {- var tr = _a.tr;- tr.removeMark(from, to, mark.type);- tr.addMark(from, to, mark.type.create({ href: href }));- tr.insertText(text || node.textContent, from, to);- (0, prosemirror_utils_1.setTextSelection)(tr.mapping.map(from))(tr);- return true;- })- .focus(undefined, { scrollIntoView: true })- .run();- }, []);- return ((0, jsx_runtime_1.jsx)(LinkTool, __assign({}, props, { isEditing: true, onDone: onDone, onClick: function () {- var node = selectedNode.current.node;- var selectedText = node.textContent;- var mark = (0, prosemirror_1.findMark)(node, "link");- if (!mark)- return;- return { text: selectedText, href: mark.attrs.href };- } })));-}-exports.EditLink = EditLink;-function RemoveLink(props) {- var editor = props.editor, selectedNode = props.selectedNode;- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () {- var _a, _b;- if (selectedNode)- (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setTextSelection(selectedNode.from);- (_b = editor.current) === null || _b === void 0 ? void 0 : _b.chain().focus().unsetLink().run();- } })));-}-exports.RemoveLink = RemoveLink;-function OpenLink(props) {- var editor = props.editor, selectedNode = props.selectedNode;- var node = (selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.node) || editor.state.selection.$anchor.node();- var link = selectedNode ? (0, prosemirror_1.findMark)(node, "link") : null;- if (!link)- return null;- var href = link === null || link === void 0 ? void 0 : link.attrs.href;- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ as: "a", href: href, target: "_blank", variant: "body", sx: { mr: 1 } }, { children: href })), (0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { toggled: false, onClick: function () { return window.open(href, "_blank"); } }))] })));-}-exports.OpenLink = OpenLink;-function LinkTool(props) {- var isEditing = props.isEditing, onClick = props.onClick, onDone = props.onDone;- var buttonRef = (0, react_1.useRef)(null);- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var _b = __read((0, react_1.useState)(), 2), href = _b[0], setHref = _b[1];- var _c = __read((0, react_1.useState)(), 2), text = _c[0], setText = _c[1];- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { buttonRef: buttonRef, onClick: function () {- var result = onClick();- if (!result)- return;- var text = result.text, href = result.href;- setHref(href);- setText(text);- setIsOpen(true);- }, toggled: isOpen })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, __assign({ mobile: "sheet", desktop: "menu", position: {- target: buttonRef.current || undefined,- isTargetAbsolute: true,- location: "below",- align: "center",- yOffset: 5,- }, title: isEditing ? "Edit link" : "Insert link", isOpen: isOpen, items: [], onClose: function () { return setIsOpen(false); }, focusOnRender: false }, { children: (0, jsx_runtime_1.jsx)(linkpopup_1.LinkPopup, { href: href, text: text, isEditing: isEditing, onClose: function () { return setIsOpen(false); }, onDone: function (_a) {- var href = _a.href, text = _a.text;- onDone(href, text);- setIsOpen(false);- } }) }))] }));-}diff --git a/packages/editor/dist/toolbar/tools/lists.js b/packages/editor/dist/toolbar/tools/lists.jsdeleted file mode 100644index 323963b07..000000000--- a/packages/editor/dist/toolbar/tools/lists.js+++ /dev/null@@ -1,141 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __importDefault = (this && this.__importDefault) || function (mod) {- return (mod && mod.__esModule) ? mod : { "default": mod };-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.BulletList = exports.NumberedList = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var rebass_1 = require("rebass");-var react_1 = require("react");-var splitbutton_1 = require("../components/splitbutton");-var toolbarstore_1 = require("../stores/toolbarstore");-var dom_1 = require("../utils/dom");-var popuppresenter_1 = require("../../components/popuppresenter");-var react_2 = __importDefault(require("react"));-function _ListTool(props) {- var editor = props.editor, onClick = props.onClick, isActive = props.isActive, subTypes = props.subTypes, type = props.type, toolProps = __rest(props, ["editor", "onClick", "isActive", "subTypes", "type"]);- var toolbarLocation = (0, toolbarstore_1.useToolbarLocation)();- var isBottom = toolbarLocation === "bottom";- var _a = __read((0, react_1.useState)(false), 2), isOpen = _a[0], setIsOpen = _a[1];- var buttonRef = (0, react_1.useRef)();- return ((0, jsx_runtime_1.jsx)(splitbutton_1.SplitButton, __assign({}, toolProps, { buttonRef: buttonRef, onClick: onClick, toggled: isActive || isOpen, sx: { mr: 0 }, onOpen: function () { return setIsOpen(function (s) { return !s; }); } }, { children: (0, jsx_runtime_1.jsx)(popuppresenter_1.PopupWrapper, { isOpen: isOpen, group: "lists", id: toolProps.title, blocking: false, focusOnRender: false, position: {- isTargetAbsolute: true,- target: isBottom ? (0, dom_1.getToolbarElement)() : buttonRef.current || "mouse",- align: "center",- location: isBottom ? "top" : "below",- yOffset: isBottom ? 10 : 5,- }, onClosed: function () { return setIsOpen(false); }, renderPopup: function () { return ((0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ sx: {- bg: "background",- display: "grid",- gridTemplateColumns: "1fr 1fr 1fr",- p: 1,- } }, { children: subTypes.map(function (item) { return ((0, jsx_runtime_1.jsx)(rebass_1.Button, __assign({ variant: "menuitem", sx: { width: 80 }, onClick: function () {- var _a;- var chain = (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus();- if (!chain)- return;- if (!isActive) {- if (type === "bulletList")- chain = chain.toggleBulletList();- else- chain = chain.toggleOrderedList();- }- return chain- .updateAttributes(type, { listType: item.type })- .run();- } }, { children: (0, jsx_runtime_1.jsx)(ListThumbnail, { listStyleType: item.type }) }), item.title)); }) }))); } }) })));-}-var ListTool = react_2.default.memo(_ListTool, function (prev, next) {- return prev.isActive === next.isActive;-});-function NumberedList(props) {- var editor = props.editor;- var onClick = (0, react_1.useCallback)(function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOrderedList().run(); }, []);- return ((0, jsx_runtime_1.jsx)(ListTool, __assign({}, props, { type: "orderedList", isActive: editor.isActive("orderedList"), onClick: onClick, subTypes: [- { type: "decimal", title: "Decimal", items: ["1", "2", "3"] },- { type: "upper-alpha", title: "Upper alpha", items: ["A", "B", "C"] },- { type: "lower-alpha", title: "Lower alpha", items: ["a", "b", "c"] },- {- type: "upper-roman",- title: "Upper Roman",- items: ["I", "II", "III"],- },- {- type: "lower-roman",- title: "Lower Roman",- items: ["i", "ii", "iii"],- },- { type: "lower-greek", title: "Lower Greek", items: ["α", "β", "γ"] },- ] })));-}-exports.NumberedList = NumberedList;-function BulletList(props) {- var editor = props.editor;- var onClick = (0, react_1.useCallback)(function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().toggleOrderedList().run(); }, []);- return ((0, jsx_runtime_1.jsx)(ListTool, __assign({}, props, { type: "bulletList", onClick: onClick, isActive: editor.isActive("bulletList"), subTypes: [- { type: "disc", title: "Decimal", items: ["1", "2", "3"] },- { type: "circle", title: "Upper alpha", items: ["A", "B", "C"] },- { type: "square", title: "Lower alpha", items: ["a", "b", "c"] },- ] })));-}-exports.BulletList = BulletList;-function ListThumbnail(props) {- var listStyleType = props.listStyleType;- return ((0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ as: "ul", sx: {- flexDirection: "column",- flex: 1,- p: 0,- listStyleType: listStyleType,- } }, { children: [0, 1, 2].map(function (i) { return ((0, jsx_runtime_1.jsx)(rebass_1.Box, __assign({ as: "li", sx: {- display: "list-item",- color: "text",- fontSize: 8,- mb: "1px",- } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Flex, __assign({ sx: {- alignItems: "center",- } }, { children: (0, jsx_runtime_1.jsx)(rebass_1.Box, { sx: {- width: "100%",- flexShrink: 0,- height: 4,- bg: "#cbcbcb",- borderRadius: "small",- } }) })) }), i.toString())); }) })));-}diff --git a/packages/editor/dist/toolbar/tools/table.js b/packages/editor/dist/toolbar/tools/table.jsdeleted file mode 100644index 52bd4e6b3..000000000--- a/packages/editor/dist/toolbar/tools/table.js+++ /dev/null@@ -1,206 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.DeleteTable = exports.DeleteRow = exports.MoveRowDown = exports.MoveRowUp = exports.InsertRowBelow = exports.InsertRowAbove = exports.MergeCells = exports.SplitCells = exports.DeleteColumn = exports.MoveColumnRight = exports.MoveColumnLeft = exports.InsertColumnRight = exports.InsertColumnLeft = exports.CellBorderWidth = exports.CellBorderColor = exports.CellTextColor = exports.CellBackgroundColor = exports.CellProperties = exports.TableProperties = exports.ColumnProperties = exports.RowProperties = exports.TableSettings = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-var react_1 = require("react");-var rebass_1 = require("rebass");-var responsive_1 = require("../../components/responsive");-var actions_1 = require("../../extensions/table/actions");-var moretools_1 = require("../components/moretools");-var utils_1 = require("./utils");-var tooldefinitions_1 = require("../tooldefinitions");-var cellproperties_1 = require("../popups/cellproperties");-var colors_1 = require("./colors");-var counter_1 = require("../components/counter");-var toolbarstore_1 = require("../stores/toolbarstore");-var popuppresenter_1 = require("../../components/popuppresenter");-function TableSettings(props) {- var editor = props.editor;- var isBottom = (0, toolbarstore_1.useToolbarLocation)() === "bottom";- if (!editor.isActive("table") || !isBottom)- return null;- return ((0, jsx_runtime_1.jsx)(moretools_1.MoreTools, __assign({}, props, { autoCloseOnUnmount: true, popupId: "tableSettings", tools: [- "insertColumnLeft",- "insertColumnRight",- "insertRowAbove",- "insertRowBelow",- "cellProperties",- "columnProperties",- "rowProperties",- "deleteRow",- "deleteColumn",- "deleteTable",- ] })));-}-exports.TableSettings = TableSettings;-function RowProperties(props) {- var editor = props.editor;- var buttonRef = (0, react_1.useRef)();- var _a = __read((0, react_1.useState)(false), 2), isMenuOpen = _a[0], setIsMenuOpen = _a[1];- var items = (0, react_1.useMemo)(function () { return [- insertRowAbove(editor),- insertRowBelow(editor),- moveRowUp(editor),- moveRowDown(editor),- deleteRow(editor),- ]; }, []);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: function () { return setIsMenuOpen(true); } })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { title: "Row properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: function () { return setIsMenuOpen(false); }, position: {- target: buttonRef.current,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- }, items: items })] }));-}-exports.RowProperties = RowProperties;-function ColumnProperties(props) {- var editor = props.editor;- var buttonRef = (0, react_1.useRef)();- var _a = __read((0, react_1.useState)(false), 2), isMenuOpen = _a[0], setIsMenuOpen = _a[1];- var items = (0, react_1.useMemo)(function () { return [- insertColumnLeft(editor),- insertColumnRight(editor),- moveColumnLeft(editor),- moveColumnRight(editor),- deleteColumn(editor),- ]; }, []);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: function () { return setIsMenuOpen(true); } })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { title: "Column properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: function () { return setIsMenuOpen(false); }, position: {- target: buttonRef.current,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- }, items: items })] }));-}-exports.ColumnProperties = ColumnProperties;-function TableProperties(props) {- var editor = props.editor;- var buttonRef = (0, react_1.useRef)();- var _a = __read((0, react_1.useState)(false), 2), isMenuOpen = _a[0], setIsMenuOpen = _a[1];- var items = (0, react_1.useMemo)(function () { return [- insertColumnLeft(editor),- insertColumnRight(editor),- moveColumnLeft(editor),- moveColumnRight(editor),- deleteColumn(editor),- { type: "separator", key: "cellSeperator" },- mergeCells(editor),- splitCells(editor),- cellProperties(editor),- { type: "separator", key: "tableSeperator" },- deleteTable(editor),- ]; }, []);- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { buttonRef: buttonRef, toggled: isMenuOpen, onClick: function () { return setIsMenuOpen(true); } })), (0, jsx_runtime_1.jsx)(responsive_1.ResponsivePresenter, { title: "Table properties", mobile: "sheet", desktop: "menu", isOpen: isMenuOpen, onClose: function () { return setIsMenuOpen(false); }, position: {- target: buttonRef.current,- isTargetAbsolute: true,- location: "below",- yOffset: 5,- }, items: items })] }));-}-exports.TableProperties = TableProperties;-function CellProperties(props) {- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsx)(moretools_1.MoreTools, __assign({}, props, { popupId: "cellProperties", tools: [- "mergeCells",- "splitCells",- "cellBackgroundColor",- "cellTextColor",- "cellBorderColor",- "cellBorderWidth",- ] })) }));-}-exports.CellProperties = CellProperties;-function CellBackgroundColor(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(colors_1.ColorTool, __assign({}, props, { cacheKey: "cellBackgroundColor", getActiveColor: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").backgroundColor; }, title: "Cell background color", onColorChange: function (color) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().setCellAttribute("backgroundColor", color).run(); } })));-}-exports.CellBackgroundColor = CellBackgroundColor;-function CellTextColor(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(colors_1.ColorTool, __assign({}, props, { cacheKey: "cellTextColor", getActiveColor: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").color; }, title: "Cell text color", onColorChange: function (color) { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setCellAttribute("color", color).run(); } })));-}-exports.CellTextColor = CellTextColor;-function CellBorderColor(props) {- var editor = props.editor;- return ((0, jsx_runtime_1.jsx)(colors_1.ColorTool, __assign({}, props, { cacheKey: "cellBorderColor", getActiveColor: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.getAttributes("tableCell").borderColor; }, title: "Cell border color", onColorChange: function (color) {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setCellAttribute("borderColor", color).run();- } })));-}-exports.CellBorderColor = CellBorderColor;-function CellBorderWidth(props) {- var editor = props.editor;- var _borderWidth = editor.getAttributes("tableCell").borderWidth;- var borderWidth = _borderWidth ? _borderWidth : 1;- var decreaseBorderWidth = (0, react_1.useCallback)(function () {- return Math.max(1, borderWidth - 1);- }, [borderWidth]);- var increaseBorderWidth = (0, react_1.useCallback)(function () {- return Math.min(10, borderWidth + 1);- }, [borderWidth]);- return ((0, jsx_runtime_1.jsxs)(rebass_1.Flex, __assign({ sx: { justifyContent: "center", alignItems: "center" } }, { children: [(0, jsx_runtime_1.jsx)(rebass_1.Text, __assign({ variant: "subBody", sx: { mx: 1 } }, { children: "Border width:" })), (0, jsx_runtime_1.jsx)(counter_1.Counter, { title: "cell border width", onDecrease: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", decreaseBorderWidth());- }, onIncrease: function () {- var _a;- return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", increaseBorderWidth());- }, onReset: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.commands.setCellAttribute("borderWidth", 1); }, value: borderWidth + "px" })] })));-}-exports.CellBorderWidth = CellBorderWidth;-var insertColumnLeft = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("insertColumnLeft")), { key: "addColumnLeft", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnBefore().run(); } })); };-var insertColumnRight = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("insertColumnRight")), { key: "addColumnRight", type: "button", title: "Add column right", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addColumnAfter().run(); }, icon: "insertColumnRight" })); };-var moveColumnLeft = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("moveColumnLeft")), { key: "moveColumnLeft", type: "button", onClick: function () { return (0, actions_1.moveColumnLeft)(editor); } })); };-var moveColumnRight = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("moveColumnRight")), { key: "moveColumnRight", type: "button", onClick: function () { return (0, actions_1.moveColumnRight)(editor); } })); };-var deleteColumn = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("deleteColumn")), { key: "deleteColumn", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteColumn().run(); } })); };-var splitCells = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("splitCells")), { key: "splitCells", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().splitCell().run(); } })); };-var mergeCells = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("mergeCells")), { key: "mergeCells", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().mergeCells().run(); } })); };-var insertRowAbove = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("insertRowAbove")), { key: "insertRowAbove", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addRowBefore().run(); } })); };-var insertRowBelow = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("insertRowBelow")), { key: "insertRowBelow", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().addRowAfter().run(); } })); };-var moveRowUp = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("moveRowUp")), { key: "moveRowUp", type: "button", onClick: function () { return (0, actions_1.moveRowUp)(editor); } })); };-var moveRowDown = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("moveRowDown")), { key: "moveRowDown", type: "button", onClick: function () { return (0, actions_1.moveRowDown)(editor); } })); };-var deleteRow = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("deleteRow")), { key: "deleteRow", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteRow().run(); } })); };-var deleteTable = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("deleteTable")), { key: "deleteTable", type: "button", onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().deleteTable().run(); } })); };-var cellProperties = function (editor) { return (__assign(__assign({}, (0, tooldefinitions_1.getToolDefinition)("cellProperties")), { key: "cellProperties", type: "button", onClick: function () {- (0, popuppresenter_1.showPopup)({- theme: editor.storage.theme,- popup: function (hide) { return (0, jsx_runtime_1.jsx)(cellproperties_1.CellProperties, { onClose: hide, editor: editor }); },- });- } })); };-exports.InsertColumnLeft = (0, utils_1.menuButtonToTool)(insertColumnLeft);-exports.InsertColumnRight = (0, utils_1.menuButtonToTool)(insertColumnRight);-exports.MoveColumnLeft = (0, utils_1.menuButtonToTool)(moveColumnLeft);-exports.MoveColumnRight = (0, utils_1.menuButtonToTool)(moveColumnRight);-exports.DeleteColumn = (0, utils_1.menuButtonToTool)(deleteColumn);-exports.SplitCells = (0, utils_1.menuButtonToTool)(splitCells);-exports.MergeCells = (0, utils_1.menuButtonToTool)(mergeCells);-exports.InsertRowAbove = (0, utils_1.menuButtonToTool)(insertRowAbove);-exports.InsertRowBelow = (0, utils_1.menuButtonToTool)(insertRowBelow);-exports.MoveRowUp = (0, utils_1.menuButtonToTool)(moveRowUp);-exports.MoveRowDown = (0, utils_1.menuButtonToTool)(moveRowDown);-exports.DeleteRow = (0, utils_1.menuButtonToTool)(deleteRow);-exports.DeleteTable = (0, utils_1.menuButtonToTool)(deleteTable);diff --git a/packages/editor/dist/toolbar/tools/textdirection.js b/packages/editor/dist/toolbar/tools/textdirection.jsdeleted file mode 100644index 7093cb539..000000000--- a/packages/editor/dist/toolbar/tools/textdirection.js+++ /dev/null@@ -1,39 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-var __rest = (this && this.__rest) || function (s, e) {- var t = {};- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)- t[p] = s[p];- if (s != null && typeof Object.getOwnPropertySymbols === "function")- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))- t[p[i]] = s[p[i]];- }- return t;-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.LeftToRight = exports.RightToLeft = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-function TextDirectionTool(props) {- var editor = props.editor, direction = props.direction, toolProps = __rest(props, ["editor", "direction"]);- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, toolProps, { onClick: function () { var _a; return (_a = editor.current) === null || _a === void 0 ? void 0 : _a.chain().focus().setTextDirection(direction).run(); }, toggled: editor.isActive({ textDirection: direction }) })));-}-function RightToLeft(props) {- return (0, jsx_runtime_1.jsx)(TextDirectionTool, __assign({ direction: "rtl" }, props));-}-exports.RightToLeft = RightToLeft;-function LeftToRight(props) {- return (0, jsx_runtime_1.jsx)(TextDirectionTool, __assign({ direction: "ltr" }, props));-}-exports.LeftToRight = LeftToRight;diff --git a/packages/editor/dist/toolbar/tools/utils.js b/packages/editor/dist/toolbar/tools/utils.jsdeleted file mode 100644index 137d5f033..000000000--- a/packages/editor/dist/toolbar/tools/utils.js+++ /dev/null@@ -1,23 +0,0 @@-"use strict";-var __assign = (this && this.__assign) || function () {- __assign = Object.assign || function(t) {- for (var s, i = 1, n = arguments.length; i < n; i++) {- s = arguments[i];- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))- t[p] = s[p];- }- return t;- };- return __assign.apply(this, arguments);-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.menuButtonToTool = void 0;-var jsx_runtime_1 = require("react/jsx-runtime");-var toolbutton_1 = require("../components/toolbutton");-function menuButtonToTool(constructItem) {- return function (props) {- var item = constructItem(props.editor);- return ((0, jsx_runtime_1.jsx)(toolbutton_1.ToolButton, __assign({}, props, { icon: item.icon || props.icon, toggled: item.isChecked || false, title: item.title, onClick: item.onClick })));- };-}-exports.menuButtonToTool = menuButtonToTool;diff --git a/packages/editor/dist/toolbar/utils/prosemirror.js b/packages/editor/dist/toolbar/utils/prosemirror.jsdeleted file mode 100644index 5ef9ceda1..000000000--- a/packages/editor/dist/toolbar/utils/prosemirror.js+++ /dev/null@@ -1,38 +0,0 @@-"use strict";-Object.defineProperty(exports, "__esModule", { value: true });-exports.selectionToOffset = exports.findMark = exports.findSelectedNode = exports.findSelectedDOMNode = void 0;-var core_1 = require("@tiptap/core");-function findSelectedDOMNode(editor, types) {- var _a;- var $anchor = editor.state.selection.$anchor;- var selectedNode = editor.state.doc.nodeAt($anchor.pos);- var pos = types.includes((selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type.name) || "")- ? $anchor.pos- : (_a = (0, core_1.findParentNode)(function (node) { return types.includes(node.type.name); })(editor.state.selection)) === null || _a === void 0 ? void 0 : _a.pos;- if (!pos)- return null;- return editor.view.nodeDOM(pos) || null;-}-exports.findSelectedDOMNode = findSelectedDOMNode;-function findSelectedNode(editor, type) {- var _a;- var $anchor = editor.state.selection.$anchor;- var selectedNode = editor.state.doc.nodeAt($anchor.pos);- var pos = (selectedNode === null || selectedNode === void 0 ? void 0 : selectedNode.type.name) === type- ? $anchor.pos- : (_a = (0, core_1.findParentNode)(function (node) { return node.type.name === type; })(editor.state.selection)) === null || _a === void 0 ? void 0 : _a.pos;- if (!pos)- return null;- return editor.state.doc.nodeAt(pos);-}-exports.findSelectedNode = findSelectedNode;-function findMark(node, type) {- var mark = node.marks.find(function (m) { return m.type.name === type; });- return mark;-}-exports.findMark = findMark;-function selectionToOffset(selection) {- var $from = selection.$from, from = selection.from;- return { node: $from.node(), from: from, to: from + $from.node().nodeSize };-}-exports.selectionToOffset = selectionToOffset;diff --git a/packages/editor/dist/utils/debounce.js b/packages/editor/dist/utils/debounce.jsdeleted file mode 100644index 6b70504f4..000000000--- a/packages/editor/dist/utils/debounce.js+++ /dev/null@@ -1,42 +0,0 @@-"use strict";-var __read = (this && this.__read) || function (o, n) {- var m = typeof Symbol === "function" && o[Symbol.iterator];- if (!m) return o;- var i = m.call(o), r, ar = [], e;- try {- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);- }- catch (error) { e = { error: error }; }- finally {- try {- if (r && !r.done && (m = i["return"])) m.call(i);- }- finally { if (e) throw e.error; }- }- return ar;-};-var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {- if (ar || !(i in from)) {- if (!ar) ar = Array.prototype.slice.call(from, 0, i);- ar[i] = from[i];- }- }- return to.concat(ar || Array.prototype.slice.call(from));-};-Object.defineProperty(exports, "__esModule", { value: true });-exports.debounce = void 0;-function debounce(func, waitFor) {- var timeout;- var debounced = function () {- var args = [];- for (var _i = 0; _i < arguments.length; _i++) {- args[_i] = arguments[_i];- }- if (timeout)- clearTimeout(timeout);- timeout = setTimeout(function () { return func.apply(void 0, __spreadArray([], __read(args), false)); }, waitFor);- };- return debounced;-}-exports.debounce = debounce;diff --git a/packages/editor/package-lock.json b/packages/editor/package-lock.jsonindex 40c6d7dae..e48cf568f 100644--- a/packages/editor/package-lock.json+++ b/packages/editor/package-lock.json@@ -34,7 +34,6 @@"@tiptap/extension-text-align": "^2.0.0-beta.31","@tiptap/extension-text-style": "^2.0.0-beta.26","@tiptap/extension-underline": "^2.0.0-beta.25",- "@tiptap/react": "^2.0.0-beta.114","@tiptap/starter-kit": "^2.0.0-beta.190","detect-indent": "^7.0.0","emotion-theming": "^10.0.19",@@ -3331,15 +3330,6 @@"node": ">= 8"}},- "node_modules/@popperjs/core": {- "version": "2.11.5",- "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz",- "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw==",- "funding": {- "type": "opencollective",- "url": "https://opencollective.com/popperjs"- }- },"node_modules/@rebass/forms": {"version": "4.0.6","resolved": "https://registry.npmjs.org/@rebass/forms/-/forms-4.0.6.tgz",@@ -3872,23 +3862,6 @@"@tiptap/core": "^2.0.0-beta.1"}},- "node_modules/@tiptap/extension-bubble-menu": {- "version": "2.0.0-beta.61",- "resolved": "https://registry.npmjs.org/@tiptap/extension-bubble-menu/-/extension-bubble-menu-2.0.0-beta.61.tgz",- "integrity": "sha512-T3Yx+y1sUnXAJjK1CUfsQewSxOpDca9KzKqN2H9c9RZ9UlorR9XmZg6YYW7m9a7adeihj+o3cCO9jRd8dV+nnA==",- "dependencies": {- "prosemirror-state": "1.4.1",- "prosemirror-view": "1.26.2",- "tippy.js": "^6.3.7"- },- "funding": {- "type": "github",- "url": "https://github.com/sponsors/ueberdosis"- },- "peerDependencies": {- "@tiptap/core": "^2.0.0-beta.1"- }- },"node_modules/@tiptap/extension-bullet-list": {"version": "2.0.0-beta.29","resolved": "https://registry.npmjs.org/@tiptap/extension-bullet-list/-/extension-bullet-list-2.0.0-beta.29.tgz",@@ -3984,23 +3957,6 @@"@tiptap/core": "^2.0.0-beta.1"}},- "node_modules/@tiptap/extension-floating-menu": {- "version": "2.0.0-beta.56",- "resolved": "https://registry.npmjs.org/@tiptap/extension-floating-menu/-/extension-floating-menu-2.0.0-beta.56.tgz",- "integrity": "sha512-j/evHE/6UPGkIgXny9IGcAh0IrcnQmg0b2NBYebs2mqx9xYKYoe+0jVgNdLp/0M3MRgQCzyWTyatBDBFOUR2mw==",- "dependencies": {- "prosemirror-state": "1.4.1",- "prosemirror-view": "1.26.2",- "tippy.js": "^6.3.7"- },- "funding": {- "type": "github",- "url": "https://github.com/sponsors/ueberdosis"- },- "peerDependencies": {- "@tiptap/core": "^2.0.0-beta.1"- }- },"node_modules/@tiptap/extension-font-family": {"version": "2.0.0-beta.24","resolved": "https://registry.npmjs.org/@tiptap/extension-font-family/-/extension-font-family-2.0.0-beta.24.tgz",@@ -4340,25 +4296,6 @@"@tiptap/core": "^2.0.0-beta.1"}},- "node_modules/@tiptap/react": {- "version": "2.0.0-beta.114",- "resolved": "https://registry.npmjs.org/@tiptap/react/-/react-2.0.0-beta.114.tgz",- "integrity": "sha512-9JbRE+16WM6RxbBxzY74SrJtLodvjeRBnEbWxuhxVgGKxMunRj6r8oED87ODJgqLmkpofwE0KFHTPGdEXfdcKA==",- "dependencies": {- "@tiptap/extension-bubble-menu": "^2.0.0-beta.61",- "@tiptap/extension-floating-menu": "^2.0.0-beta.56",- "prosemirror-view": "1.26.2"- },- "funding": {- "type": "github",- "url": "https://github.com/sponsors/ueberdosis"- },- "peerDependencies": {- "@tiptap/core": "^2.0.0-beta.1",- "react": "^17.0.0 || ^18.0.0",- "react-dom": "^17.0.0 || ^18.0.0"- }- },"node_modules/@tiptap/starter-kit": {"version": "2.0.0-beta.190","resolved": "https://registry.npmjs.org/@tiptap/starter-kit/-/starter-kit-2.0.0-beta.190.tgz",@@ -22461,14 +22398,6 @@"node": "*"}},- "node_modules/tippy.js": {- "version": "6.3.7",- "resolved": "https://registry.npmjs.org/tippy.js/-/tippy.js-6.3.7.tgz",- "integrity": "sha512-E1d3oP2emgJ9dRQZdf3Kkn0qJgI6ZLpyS5z6ZkY1DF3kaQaBsGZsndEpHwx+eC+tYM41HaSNvNtLx8tU57FzTQ==",- "dependencies": {- "@popperjs/core": "^2.9.0"- }- },"node_modules/tmpl": {"version": "1.0.5","resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",@@ -27803,11 +27732,6 @@}}},- "@popperjs/core": {- "version": "2.11.5",- "resolved": "https://registry.npmjs.org/@popperjs/core/-/core-2.11.5.tgz",- "integrity": "sha512-9X2obfABZuDVLCgPK9aX0a/x4jaOEweTTWE2+9sr0Qqqevj2Uv5XorvusThmc9XGYpS9yI+fhh8RTafBtGposw=="- },"@rebass/forms": {"version": "4.0.6","resolved": "https://registry.npmjs.org/@rebass/forms/-/forms-4.0.6.tgz",@@ -28207,16 +28131,6 @@"integrity": "sha512-DY8GOzw9xjmTFrnvTbgHUNxTnDfKrkDgrhe0SUvdkT2udntWp8umPdhPiD3vczLgHOJw6tX68qMRjbsR1ZPcHQ==","requires": {}},- "@tiptap/extension-bubble-menu": {- "version": "2.0.0-beta.61",- "resolved": "https://registry.npmjs.org/@tiptap/extension-bubble-menu/-/extension-bubble-menu-2.0.0-beta.61.tgz",- "integrity": "sha512-T3Yx+y1sUnXAJjK1CUfsQewSxOpDca9KzKqN2H9c9RZ9UlorR9XmZg6YYW7m9a7adeihj+o3cCO9jRd8dV+nnA==",- "requires": {- "prosemirror-state": "1.4.1",- "prosemirror-view": "1.26.2",- "tippy.js": "^6.3.7"- }- },"@tiptap/extension-bullet-list": {"version": "2.0.0-beta.29","resolved": "https://registry.npmjs.org/@tiptap/extension-bullet-list/-/extension-bullet-list-2.0.0-beta.29.tgz",@@ -28266,16 +28180,6 @@"prosemirror-dropcursor": "1.5.0"}},- "@tiptap/extension-floating-menu": {- "version": "2.0.0-beta.56",- "resolved": "https://registry.npmjs.org/@tiptap/extension-floating-menu/-/extension-floating-menu-2.0.0-beta.56.tgz",- "integrity": "sha512-j/evHE/6UPGkIgXny9IGcAh0IrcnQmg0b2NBYebs2mqx9xYKYoe+0jVgNdLp/0M3MRgQCzyWTyatBDBFOUR2mw==",- "requires": {- "prosemirror-state": "1.4.1",- "prosemirror-view": "1.26.2",- "tippy.js": "^6.3.7"- }- },"@tiptap/extension-font-family": {"version": "2.0.0-beta.24","resolved": "https://registry.npmjs.org/@tiptap/extension-font-family/-/extension-font-family-2.0.0-beta.24.tgz",@@ -28451,16 +28355,6 @@"integrity": "sha512-kRDdb/mF6QWzFGV3cQuLh6xyXULXaKPL/TghefoOZhwkdIWV/M3zFar5tsZO54+tbIrzxoVP6t7mO2Y5G/SLDQ==","requires": {}},- "@tiptap/react": {- "version": "2.0.0-beta.114",- "resolved": "https://registry.npmjs.org/@tiptap/react/-/react-2.0.0-beta.114.tgz",- "integrity": "sha512-9JbRE+16WM6RxbBxzY74SrJtLodvjeRBnEbWxuhxVgGKxMunRj6r8oED87ODJgqLmkpofwE0KFHTPGdEXfdcKA==",- "requires": {- "@tiptap/extension-bubble-menu": "^2.0.0-beta.61",- "@tiptap/extension-floating-menu": "^2.0.0-beta.56",- "prosemirror-view": "1.26.2"- }- },"@tiptap/starter-kit": {"version": "2.0.0-beta.190","resolved": "https://registry.npmjs.org/@tiptap/starter-kit/-/starter-kit-2.0.0-beta.190.tgz",@@ -42844,14 +42738,6 @@"resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.2.tgz","integrity": "sha512-vJhccZPs965sV/L2sU4oRQVAos0pQXwsvTLkWYdqJ+a8Q5kPFzJTuOFwy7UniPli44NKQGAglksjvOcpo95aZA=="},- "tippy.js": {- "version": "6.3.7",- "resolved": "https://registry.npmjs.org/tippy.js/-/tippy.js-6.3.7.tgz",- "integrity": "sha512-E1d3oP2emgJ9dRQZdf3Kkn0qJgI6ZLpyS5z6ZkY1DF3kaQaBsGZsndEpHwx+eC+tYM41HaSNvNtLx8tU57FzTQ==",- "requires": {- "@popperjs/core": "^2.9.0"- }- },"tmpl": {"version": "1.0.5","resolved": "https://registry.npmjs.org/tmpl/-/tmpl-1.0.5.tgz",diff --git a/packages/editor/package.json b/packages/editor/package.jsonindex 41688d89c..7671adf10 100644--- a/packages/editor/package.json+++ b/packages/editor/package.json@@ -2,7 +2,14 @@"name": "notesnook-editor","version": "0.0.1","private": true,- "main": "./dist/index.js",+ "main": "dist/cjs/index.js",+ "module": "dist/es/index.js",+ "exports": {+ ".": {+ "import": "./dist/es/index.js",+ "require": "./dist/cjs/index.js"+ }+ },"dependencies": {"@_ueberdosis/prosemirror-tables": "^1.1.3","@mdi/js": "^6.9.96",@@ -30,7 +37,6 @@"@tiptap/extension-text-align": "^2.0.0-beta.31","@tiptap/extension-text-style": "^2.0.0-beta.26","@tiptap/extension-underline": "^2.0.0-beta.25",- "@tiptap/react": "^2.0.0-beta.114","@tiptap/starter-kit": "^2.0.0-beta.190","detect-indent": "^7.0.0","emotion-theming": "^10.0.19",diff --git a/packages/editor/scripts/compile.sh b/packages/editor/scripts/compile.shnew file mode 100755index 000000000..0d20a8397--- /dev/null+++ b/packages/editor/scripts/compile.sh@@ -0,0 +1,21 @@+rm -rf dist/+cp ./node_modules/katex/dist/katex.min.css $(realpath ./styles/)+cp -r ./node_modules/katex/dist/fonts/ $(realpath ./styles/)+cp ./node_modules/prism-themes/themes/prism-dracula.min.css $(realpath ./styles/)/prism-theme.css++ln -s $(realpath ./src/styles.css) $(realpath ./styles/)++yarn tsc --module commonjs --outDir ./dist/cjs --target es2015+yarn tsc --module esnext --outDir ./dist/es --target es6++cat >dist/cjs/package.json <<!EOF+{+ "type": "commonjs"+}+!EOF++cat >dist/es/package.json <<!EOF+{+ "type": "module"+}+!EOF\ No newline at end of filediff --git a/packages/editor/src/extensions/math/plugin/renderers/katex.ts b/packages/editor/src/extensions/math/plugin/renderers/katex.tsindex 2fb35f813..095c59ef8 100644--- a/packages/editor/src/extensions/math/plugin/renderers/katex.ts+++ b/packages/editor/src/extensions/math/plugin/renderers/katex.ts@@ -1,22 +1,31 @@import { MathRenderer } from "./types";-import katex from "katex";-// Chemistry formulas support-import "katex/contrib/mhchem/mhchem";+async function loadKatex() {+ // @ts-ignore+ const { default: katex } = await import("katex");+ // Chemistry formulas support+ // @ts-ignore+ await import("katex/contrib/mhchem/mhchem");+ return katex;+}export const KatexRenderer: MathRenderer = {inline: (text, element) => {- katex.render(text, element, {- displayMode: false,- globalGroup: true,- throwOnError: false,+ loadKatex().then((katex) => {+ katex.render(text, element, {+ displayMode: false,+ globalGroup: true,+ throwOnError: false,+ });});},block: (text, element) => {- katex.render(text, element, {- displayMode: true,- globalGroup: true,- throwOnError: false,+ loadKatex().then((katex) => {+ katex.render(text, element, {+ displayMode: true,+ globalGroup: true,+ throwOnError: false,+ });});},};diff --git a/packages/editor/src/hooks/use-editor.ts b/packages/editor/src/hooks/use-editor.tsnew file mode 100644index 000000000..6c707b6e4--- /dev/null+++ b/packages/editor/src/hooks/use-editor.ts@@ -0,0 +1,42 @@+import { EditorOptions, Editor } from "@tiptap/core";+import { DependencyList, useEffect, useState } from "react";+import { Editor as EditorType } from "../types";++function useForceUpdate() {+ const [, setValue] = useState(0);++ return () => setValue((value) => value + 1);+}++export const useEditor = (+ options: Partial<EditorOptions> = {},+ deps: DependencyList = []+) => {+ const [editor, setEditor] = useState<Editor | null>(null);+ const forceUpdate = useForceUpdate();++ useEffect(() => {+ let isMounted = true;++ const instance = new Editor(options);++ setEditor(instance);++ instance.on("transaction", () => {+ requestAnimationFrame(() => {+ requestAnimationFrame(() => {+ if (isMounted) {+ forceUpdate();+ }+ });+ });+ });++ return () => {+ instance.destroy();+ isMounted = false;+ };+ }, deps);++ return editor as EditorType;+};diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.tsindex 8d7338bb2..382d00bab 100644--- a/packages/editor/src/index.ts+++ b/packages/editor/src/index.ts@@ -2,7 +2,6 @@ import "./extensions";import CharacterCount from "@tiptap/extension-character-count";import Placeholder from "@tiptap/extension-placeholder";import Underline from "@tiptap/extension-underline";-import { EditorOptions, useEditor } from "@tiptap/react";import StarterKit from "@tiptap/starter-kit";import { useEffect, useMemo, useRef } from "react";import { EditorView } from "prosemirror-view";@@ -41,8 +40,9 @@ import {import { OutlineList } from "./extensions/outline-list";import { OutlineListItem } from "./extensions/outline-list-item";import { Table } from "./extensions/table";-import { Editor } from "./types";import { useIsMobile } from "./toolbar/stores/toolbar-store";+import { useEditor } from "./hooks/use-editor";+import { EditorOptions } from "@tiptap/core";EditorView.prototype.updateState = function updateState(state) {if (!(this as any).docView) return; // This prevents the matchesNode error on hot reloads@@ -152,7 +152,7 @@ const useTiptap = (...restOptions,},deps- ) as Editor | null;+ );const editorRef = useRef(editor);useEffect(() => {@@ -184,4 +184,5 @@ const useTiptap = (export { useTiptap, Toolbar };export * from "./types";export * from "./extensions/react";-export * from "./toolbar/tool-definitions";+export * from "./toolbar";+export { type AttachmentType } from "./extensions/attachment";diff --git a/packages/editor/src/toolbar/index.ts b/packages/editor/src/toolbar/index.tsindex f989b1228..e0caeec4b 100644--- a/packages/editor/src/toolbar/index.ts+++ b/packages/editor/src/toolbar/index.ts@@ -1,3 +1,8 @@import { Toolbar } from "./toolbar";export default Toolbar;+export * from "./types";+export * from "./icons";+export * from "./components/icon";+export * from "./tools";+export * from "./tool-definitions";diff --git a/packages/editor/tsconfig.json b/packages/editor/tsconfig.jsonindex fe8af7956..4f86e6043 100644--- a/packages/editor/tsconfig.json+++ b/packages/editor/tsconfig.json@@ -28,7 +28,7 @@// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. *//* Modules */- "module": "CommonJS" /* Specify what module code is generated. */,+ "module": "esnext" /* Specify what module code is generated. */,// "rootDir": "./", /* Specify the root folder within your source files. */"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */,// "baseUrl": "./", /* Specify the base directory to resolve non-relative module names. */