chore(deps-dev): bump prettier from 2.1.2 to 2.8.8 (#5372)
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
@@ -25,9 +25,9 @@ function CommandBar() {
|
||||
|
||||
const { rootAction } = useKBar((state) => ({
|
||||
rootAction: state.currentRootActionId
|
||||
? ((state.actions[
|
||||
? (state.actions[
|
||||
state.currentRootActionId
|
||||
] as unknown) as CommandBarAction)
|
||||
] as unknown as CommandBarAction)
|
||||
: undefined,
|
||||
}));
|
||||
|
||||
|
||||
@@ -85,27 +85,33 @@ const ContentEditable = React.forwardRef(
|
||||
},
|
||||
}));
|
||||
|
||||
const wrappedEvent = (
|
||||
callback:
|
||||
| React.FocusEventHandler<HTMLSpanElement>
|
||||
| React.FormEventHandler<HTMLSpanElement>
|
||||
| React.KeyboardEventHandler<HTMLSpanElement>
|
||||
| undefined
|
||||
) => (event: any) => {
|
||||
const text = contentRef.current?.innerText || "";
|
||||
const wrappedEvent =
|
||||
(
|
||||
callback:
|
||||
| React.FocusEventHandler<HTMLSpanElement>
|
||||
| React.FormEventHandler<HTMLSpanElement>
|
||||
| React.KeyboardEventHandler<HTMLSpanElement>
|
||||
| undefined
|
||||
) =>
|
||||
(event: any) => {
|
||||
const text = contentRef.current?.innerText || "";
|
||||
|
||||
if (maxLength && isPrintableKeyEvent(event) && text.length >= maxLength) {
|
||||
event?.preventDefault();
|
||||
return;
|
||||
}
|
||||
if (
|
||||
maxLength &&
|
||||
isPrintableKeyEvent(event) &&
|
||||
text.length >= maxLength
|
||||
) {
|
||||
event?.preventDefault();
|
||||
return;
|
||||
}
|
||||
|
||||
if (text !== lastValue.current) {
|
||||
lastValue.current = text;
|
||||
onChange && onChange(text);
|
||||
}
|
||||
if (text !== lastValue.current) {
|
||||
lastValue.current = text;
|
||||
onChange && onChange(text);
|
||||
}
|
||||
|
||||
callback?.(event);
|
||||
};
|
||||
callback?.(event);
|
||||
};
|
||||
|
||||
// This is to account for being within a React.Suspense boundary, in this
|
||||
// case the component may be rendered with display: none. React 18 may solve
|
||||
|
||||
@@ -24,8 +24,12 @@ type Positions = {
|
||||
export default function MouseSafeArea(props: {
|
||||
parentRef: React.RefObject<HTMLElement | null>;
|
||||
}) {
|
||||
const { x = 0, y = 0, height: h = 0, width: w = 0 } =
|
||||
props.parentRef.current?.getBoundingClientRect() || {};
|
||||
const {
|
||||
x = 0,
|
||||
y = 0,
|
||||
height: h = 0,
|
||||
width: w = 0,
|
||||
} = props.parentRef.current?.getBoundingClientRect() || {};
|
||||
const [mouseX, mouseY] = useMousePosition();
|
||||
const positions = { x, y, h, w, mouseX, mouseY };
|
||||
|
||||
|
||||
@@ -45,9 +45,8 @@ function DocumentExplorer({ onSubmit, onSelect, items }: Props) {
|
||||
const [selectedNode, selectNode] = React.useState<NavigationNode | null>(
|
||||
null
|
||||
);
|
||||
const [initialScrollOffset, setInitialScrollOffset] = React.useState<number>(
|
||||
0
|
||||
);
|
||||
const [initialScrollOffset, setInitialScrollOffset] =
|
||||
React.useState<number>(0);
|
||||
const [activeNode, setActiveNode] = React.useState<number>(0);
|
||||
const [expandedNodes, setExpandedNodes] = React.useState<string[]>([]);
|
||||
const [itemRefs, setItemRefs] = React.useState<
|
||||
|
||||
@@ -181,7 +181,7 @@ const Actions = styled(EventBoundary)`
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
${NudeButton} {
|
||||
&: ${hover}, &[aria-expanded= "true" ] {
|
||||
&: ${hover}, &[aria-expanded= "true"] {
|
||||
background: ${s("sidebarControlHoverBackground")};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,9 +33,10 @@ function DocumentViews({ document, isOpen }: Props) {
|
||||
documentViews,
|
||||
(view) => !presentIds.includes(view.user.id)
|
||||
);
|
||||
const users = React.useMemo(() => sortedViews.map((v) => v.user), [
|
||||
sortedViews,
|
||||
]);
|
||||
const users = React.useMemo(
|
||||
() => sortedViews.map((v) => v.user),
|
||||
[sortedViews]
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
@@ -67,10 +67,8 @@ function Editor(props: Props, ref: React.RefObject<SharedEditor> | null) {
|
||||
const localRef = React.useRef<SharedEditor>();
|
||||
const preferences = auth.user?.preferences;
|
||||
const previousHeadings = React.useRef<Heading[] | null>(null);
|
||||
const [
|
||||
activeLinkElement,
|
||||
setActiveLink,
|
||||
] = React.useState<HTMLAnchorElement | null>(null);
|
||||
const [activeLinkElement, setActiveLink] =
|
||||
React.useState<HTMLAnchorElement | null>(null);
|
||||
const previousCommentIds = React.useRef<string[]>();
|
||||
|
||||
const handleLinkActive = React.useCallback((element: HTMLAnchorElement) => {
|
||||
|
||||
@@ -28,11 +28,8 @@ type Props = {
|
||||
function GroupListItem({ group, showFacepile, renderActions }: Props) {
|
||||
const { groupMemberships } = useStores();
|
||||
const { t } = useTranslation();
|
||||
const [
|
||||
membersModalOpen,
|
||||
setMembersModalOpen,
|
||||
setMembersModalClosed,
|
||||
] = useBoolean();
|
||||
const [membersModalOpen, setMembersModalOpen, setMembersModalClosed] =
|
||||
useBoolean();
|
||||
const memberCount = group.memberCount;
|
||||
const membershipsInGroup = groupMemberships.inGroup(group.id);
|
||||
const users = membershipsInGroup
|
||||
|
||||
@@ -76,9 +76,8 @@ function SearchPopover({ shareId }: Props) {
|
||||
[popover, cachedQuery]
|
||||
);
|
||||
|
||||
const searchInputRef = popover.unstable_referenceRef as React.RefObject<
|
||||
HTMLInputElement
|
||||
>;
|
||||
const searchInputRef =
|
||||
popover.unstable_referenceRef as React.RefObject<HTMLInputElement>;
|
||||
|
||||
const firstSearchItem = React.useRef<HTMLAnchorElement>(null);
|
||||
|
||||
|
||||
@@ -42,9 +42,10 @@ function DocumentLink(
|
||||
!!node.children.length || activeDocument?.parentDocumentId === node.id;
|
||||
const document = documents.get(node.id);
|
||||
|
||||
const showChildren = React.useMemo(() => !!hasChildDocuments, [
|
||||
hasChildDocuments,
|
||||
]);
|
||||
const showChildren = React.useMemo(
|
||||
() => !!hasChildDocuments,
|
||||
[hasChildDocuments]
|
||||
);
|
||||
|
||||
const [expanded, setExpanded] = React.useState(showChildren);
|
||||
|
||||
|
||||
@@ -30,9 +30,8 @@ type SocketWithAuthentication = Socket & {
|
||||
authenticated?: boolean;
|
||||
};
|
||||
|
||||
export const WebsocketContext = React.createContext<SocketWithAuthentication | null>(
|
||||
null
|
||||
);
|
||||
export const WebsocketContext =
|
||||
React.createContext<SocketWithAuthentication | null>(null);
|
||||
|
||||
type Props = RootStore;
|
||||
|
||||
|
||||
@@ -272,16 +272,15 @@ class LinkEditor extends React.Component<Props, State> {
|
||||
view.focus();
|
||||
};
|
||||
|
||||
handleSelectLink = (url: string, title: string) => (
|
||||
event: React.MouseEvent
|
||||
) => {
|
||||
event.preventDefault();
|
||||
this.save(url, title);
|
||||
handleSelectLink =
|
||||
(url: string, title: string) => (event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
this.save(url, title);
|
||||
|
||||
if (this.initialSelectionLength) {
|
||||
this.moveSelectionToEnd();
|
||||
}
|
||||
};
|
||||
if (this.initialSelectionLength) {
|
||||
this.moveSelectionToEnd();
|
||||
}
|
||||
};
|
||||
|
||||
moveSelectionToEnd = () => {
|
||||
const { to, view } = this.props;
|
||||
|
||||
@@ -197,10 +197,8 @@ export default function SelectionToolbar(props: Props) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const colIndex = getColumnIndex(
|
||||
(state.selection as unknown) as CellSelection
|
||||
);
|
||||
const rowIndex = getRowIndex((state.selection as unknown) as CellSelection);
|
||||
const colIndex = getColumnIndex(state.selection as unknown as CellSelection);
|
||||
const rowIndex = getRowIndex(state.selection as unknown as CellSelection);
|
||||
const isTableSelection = colIndex !== undefined && rowIndex !== undefined;
|
||||
const link = isMarkActive(state.schema.marks.link)(state);
|
||||
const range = getMarkRange(selection.$from, state.schema.marks.link);
|
||||
|
||||
@@ -464,9 +464,8 @@ export class Editor extends React.PureComponent<
|
||||
nodeViews: this.nodeViews,
|
||||
dispatchTransaction(transaction) {
|
||||
// callback is bound to have the view instance as its this binding
|
||||
const { state, transactions } = this.state.applyTransaction(
|
||||
transaction
|
||||
);
|
||||
const { state, transactions } =
|
||||
this.state.applyTransaction(transaction);
|
||||
|
||||
this.updateState(state);
|
||||
|
||||
@@ -520,9 +519,8 @@ export class Editor extends React.PureComponent<
|
||||
return trim ? content.trim() : content;
|
||||
}
|
||||
|
||||
return (trim
|
||||
? ProsemirrorHelper.trim(this.view.state.doc)
|
||||
: this.view.state.doc
|
||||
return (
|
||||
trim ? ProsemirrorHelper.trim(this.view.state.doc) : this.view.state.doc
|
||||
).toJSON();
|
||||
};
|
||||
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export default function useComponentSize(
|
||||
ref: React.RefObject<HTMLElement>
|
||||
): { width: number; height: number } {
|
||||
export default function useComponentSize(ref: React.RefObject<HTMLElement>): {
|
||||
width: number;
|
||||
height: number;
|
||||
} {
|
||||
const [size, setSize] = useState({
|
||||
width: ref.current?.clientWidth || 0,
|
||||
height: ref.current?.clientHeight || 0,
|
||||
|
||||
@@ -16,8 +16,7 @@ type MousePosition = [number, number];
|
||||
export const useMousePosition = () => {
|
||||
const isMounted = useIsMounted();
|
||||
const [mousePosition, setMousePosition] = React.useState<MousePosition>([
|
||||
0,
|
||||
0,
|
||||
0, 0,
|
||||
]);
|
||||
|
||||
const updateMousePosition = React.useMemo(
|
||||
|
||||
@@ -25,20 +25,12 @@ type Props = {
|
||||
function AddGroupsToCollection(props: Props) {
|
||||
const { collection } = props;
|
||||
|
||||
const [
|
||||
newGroupModalOpen,
|
||||
handleNewGroupModalOpen,
|
||||
handleNewGroupModalClose,
|
||||
] = useBoolean(false);
|
||||
const [newGroupModalOpen, handleNewGroupModalOpen, handleNewGroupModalClose] =
|
||||
useBoolean(false);
|
||||
const [query, setQuery] = React.useState("");
|
||||
|
||||
const {
|
||||
auth,
|
||||
collectionGroupMemberships,
|
||||
groups,
|
||||
policies,
|
||||
toasts,
|
||||
} = useStores();
|
||||
const { auth, collectionGroupMemberships, groups, policies, toasts } =
|
||||
useStores();
|
||||
const { fetchPage: fetchGroups } = groups;
|
||||
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -27,11 +27,8 @@ function AddPeopleToCollection({ collection }: Props) {
|
||||
const { showToast } = useToasts();
|
||||
const team = useCurrentTeam();
|
||||
const { t } = useTranslation();
|
||||
const [
|
||||
inviteModalOpen,
|
||||
setInviteModalOpen,
|
||||
setInviteModalClosed,
|
||||
] = useBoolean();
|
||||
const [inviteModalOpen, setInviteModalOpen, setInviteModalClosed] =
|
||||
useBoolean();
|
||||
const [query, setQuery] = React.useState("");
|
||||
|
||||
const handleFilter = (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
|
||||
@@ -44,11 +44,8 @@ function CollectionPermissions({ collectionId }: Props) {
|
||||
const collection = collections.get(collectionId);
|
||||
invariant(collection, "Collection not found");
|
||||
|
||||
const [
|
||||
addGroupModalOpen,
|
||||
handleAddGroupModalOpen,
|
||||
handleAddGroupModalClose,
|
||||
] = useBoolean();
|
||||
const [addGroupModalOpen, handleAddGroupModalOpen, handleAddGroupModalClose] =
|
||||
useBoolean();
|
||||
|
||||
const [
|
||||
addMemberModalOpen,
|
||||
|
||||
@@ -245,7 +245,7 @@ const Menu = styled(CommentMenu)<{ dir?: "rtl" | "ltr" }>`
|
||||
transition: opacity 100ms ease-in-out;
|
||||
color: ${s("textSecondary")};
|
||||
|
||||
&: ${hover}, &[aria-expanded= "true" ] {
|
||||
&: ${hover}, &[aria-expanded= "true"] {
|
||||
opacity: 1;
|
||||
background: ${s("sidebarActiveBackground")};
|
||||
}
|
||||
|
||||
@@ -376,16 +376,8 @@ class DocumentScene extends React.Component<Props> {
|
||||
};
|
||||
|
||||
render() {
|
||||
const {
|
||||
document,
|
||||
revision,
|
||||
readOnly,
|
||||
abilities,
|
||||
auth,
|
||||
ui,
|
||||
shareId,
|
||||
t,
|
||||
} = this.props;
|
||||
const { document, revision, readOnly, abilities, auth, ui, shareId, t } =
|
||||
this.props;
|
||||
const team = auth.team;
|
||||
const isShare = !!shareId;
|
||||
const embedsDisabled =
|
||||
|
||||
@@ -48,10 +48,8 @@ function MultiplayerEditor({ onSynced, ...props }: Props, ref: any) {
|
||||
const { presence, ui } = useStores();
|
||||
const token = useCurrentToken();
|
||||
const [showCursorNames, setShowCursorNames] = React.useState(false);
|
||||
const [
|
||||
remoteProvider,
|
||||
setRemoteProvider,
|
||||
] = React.useState<HocuspocusProvider | null>(null);
|
||||
const [remoteProvider, setRemoteProvider] =
|
||||
React.useState<HocuspocusProvider | null>(null);
|
||||
const [isLocalSynced, setLocalSynced] = React.useState(false);
|
||||
const [isRemoteSynced, setRemoteSynced] = React.useState(false);
|
||||
const [ydoc] = React.useState(() => new Y.Doc());
|
||||
|
||||
@@ -28,11 +28,8 @@ function AddPeopleToGroup(props: Props) {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const [query, setQuery] = React.useState("");
|
||||
const [
|
||||
inviteModalOpen,
|
||||
handleInviteModalOpen,
|
||||
handleInviteModalClose,
|
||||
] = useBoolean(false);
|
||||
const [inviteModalOpen, handleInviteModalOpen, handleInviteModalClose] =
|
||||
useBoolean(false);
|
||||
|
||||
const { fetchPage: fetchUsers } = users;
|
||||
const debouncedFetch = React.useMemo(
|
||||
|
||||
@@ -24,11 +24,8 @@ function Groups() {
|
||||
const { groups } = useStores();
|
||||
const team = useCurrentTeam();
|
||||
const can = usePolicy(team);
|
||||
const [
|
||||
newGroupModalOpen,
|
||||
handleNewGroupModalOpen,
|
||||
handleNewGroupModalClose,
|
||||
] = useBoolean();
|
||||
const [newGroupModalOpen, handleNewGroupModalOpen, handleNewGroupModalClose] =
|
||||
useBoolean();
|
||||
|
||||
return (
|
||||
<Scene
|
||||
|
||||
@@ -28,11 +28,8 @@ import UserStatusFilter from "./components/UserStatusFilter";
|
||||
function Members() {
|
||||
const location = useLocation();
|
||||
const history = useHistory();
|
||||
const [
|
||||
inviteModalOpen,
|
||||
handleInviteModalOpen,
|
||||
handleInviteModalClose,
|
||||
] = useBoolean();
|
||||
const [inviteModalOpen, handleInviteModalOpen, handleInviteModalClose] =
|
||||
useBoolean();
|
||||
const team = useCurrentTeam();
|
||||
const { users } = useStores();
|
||||
const { t } = useTranslation();
|
||||
|
||||
@@ -38,9 +38,11 @@ function Security() {
|
||||
inviteRequired: team.inviteRequired,
|
||||
});
|
||||
|
||||
const { data: providers, loading, request } = useRequest(() =>
|
||||
authenticationProviders.fetchPage({})
|
||||
);
|
||||
const {
|
||||
data: providers,
|
||||
loading,
|
||||
request,
|
||||
} = useRequest(() => authenticationProviders.fetchPage({}));
|
||||
|
||||
React.useEffect(() => {
|
||||
if (!providers && !loading) {
|
||||
|
||||
@@ -31,9 +31,8 @@ function DomainManagement({ onSuccess }: Props) {
|
||||
allowedDomains.length
|
||||
);
|
||||
|
||||
const [existingDomainsTouched, setExistingDomainsTouched] = React.useState(
|
||||
false
|
||||
);
|
||||
const [existingDomainsTouched, setExistingDomainsTouched] =
|
||||
React.useState(false);
|
||||
|
||||
const handleSaveDomains = React.useCallback(async () => {
|
||||
try {
|
||||
@@ -67,19 +66,18 @@ function DomainManagement({ onSuccess }: Props) {
|
||||
setAllowedDomains(newDomains);
|
||||
};
|
||||
|
||||
const createOnDomainChangedHandler = (index: number) => (
|
||||
ev: React.ChangeEvent<HTMLInputElement>
|
||||
) => {
|
||||
const newDomains = allowedDomains.slice();
|
||||
const createOnDomainChangedHandler =
|
||||
(index: number) => (ev: React.ChangeEvent<HTMLInputElement>) => {
|
||||
const newDomains = allowedDomains.slice();
|
||||
|
||||
newDomains[index] = ev.currentTarget.value;
|
||||
setAllowedDomains(newDomains);
|
||||
newDomains[index] = ev.currentTarget.value;
|
||||
setAllowedDomains(newDomains);
|
||||
|
||||
const touchedExistingDomain = index < lastKnownDomainCount;
|
||||
if (touchedExistingDomain) {
|
||||
setExistingDomainsTouched(true);
|
||||
}
|
||||
};
|
||||
const touchedExistingDomain = index < lastKnownDomainCount;
|
||||
if (touchedExistingDomain) {
|
||||
setExistingDomainsTouched(true);
|
||||
}
|
||||
};
|
||||
|
||||
const showSaveChanges =
|
||||
existingDomainsTouched ||
|
||||
|
||||
@@ -19,9 +19,11 @@ function UserDelete() {
|
||||
const { auth } = useStores();
|
||||
const { showToast } = useToasts();
|
||||
const { t } = useTranslation();
|
||||
const { register, handleSubmit: formHandleSubmit, formState } = useForm<
|
||||
FormData
|
||||
>();
|
||||
const {
|
||||
register,
|
||||
handleSubmit: formHandleSubmit,
|
||||
formState,
|
||||
} = useForm<FormData>();
|
||||
|
||||
const handleRequestDelete = React.useCallback(
|
||||
async (ev: React.SyntheticEvent) => {
|
||||
|
||||
@@ -2,9 +2,7 @@ import AuthenticationProvider from "~/models/AuthenticationProvider";
|
||||
import BaseStore, { RPCAction } from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
|
||||
export default class AuthenticationProvidersStore extends BaseStore<
|
||||
AuthenticationProvider
|
||||
> {
|
||||
export default class AuthenticationProvidersStore extends BaseStore<AuthenticationProvider> {
|
||||
actions = [RPCAction.List, RPCAction.Update];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
|
||||
@@ -7,9 +7,7 @@ import { client } from "~/utils/ApiClient";
|
||||
import BaseStore, { PAGINATION_SYMBOL, RPCAction } from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
|
||||
export default class CollectionGroupMembershipsStore extends BaseStore<
|
||||
CollectionGroupMembership
|
||||
> {
|
||||
export default class CollectionGroupMembershipsStore extends BaseStore<CollectionGroupMembership> {
|
||||
actions = [RPCAction.Create, RPCAction.Delete];
|
||||
|
||||
constructor(rootStore: RootStore) {
|
||||
|
||||
@@ -3,9 +3,7 @@ import WebhookSubscription from "~/models/WebhookSubscription";
|
||||
import BaseStore, { RPCAction } from "./BaseStore";
|
||||
import RootStore from "./RootStore";
|
||||
|
||||
export default class WebhookSubscriptionsStore extends BaseStore<
|
||||
WebhookSubscription
|
||||
> {
|
||||
export default class WebhookSubscriptionsStore extends BaseStore<WebhookSubscription> {
|
||||
actions = [
|
||||
RPCAction.List,
|
||||
RPCAction.Create,
|
||||
|
||||
@@ -328,7 +328,7 @@
|
||||
"lint-staged": "^13.1.0",
|
||||
"nodemon": "^2.0.22",
|
||||
"postinstall-postinstall": "^2.1.0",
|
||||
"prettier": "^2.0.5",
|
||||
"prettier": "^2.8.8",
|
||||
"react-refresh": "^0.14.0",
|
||||
"rimraf": "^2.5.4",
|
||||
"rollup-plugin-webpack-stats": "^0.2.0",
|
||||
|
||||
@@ -19,11 +19,8 @@ type Props = {
|
||||
const WebhookSubscriptionListItem = ({ webhook }: Props) => {
|
||||
const { t } = useTranslation();
|
||||
const { dialogs } = useStores();
|
||||
const [
|
||||
editModalOpen,
|
||||
handleEditModalOpen,
|
||||
handleEditModalClose,
|
||||
] = useBoolean();
|
||||
const [editModalOpen, handleEditModalOpen, handleEditModalClose] =
|
||||
useBoolean();
|
||||
|
||||
const showDeletionConfirmation = React.useCallback(() => {
|
||||
dialogs.openModal({
|
||||
|
||||
@@ -7,7 +7,7 @@ const emptyFn = function () {};
|
||||
const callableHandlers = {
|
||||
get<T, P extends keyof T>(_target: T, _prop: P, _receiver: any): T[P] {
|
||||
const newMock = new Proxy(emptyFn, callableHandlers);
|
||||
return (newMock as any) as T[P];
|
||||
return newMock as any as T[P];
|
||||
},
|
||||
|
||||
apply<T extends (...args: any) => any, A extends Parameters<T>>(
|
||||
@@ -16,7 +16,7 @@ const callableHandlers = {
|
||||
_args: A
|
||||
): ReturnType<T> {
|
||||
const newMock = new Proxy(emptyFn, callableHandlers);
|
||||
return (newMock as any) as ReturnType<T>;
|
||||
return newMock as any as ReturnType<T>;
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -88,9 +88,8 @@ export default class PersistenceExtension implements Extension {
|
||||
// Find the collaborators that have modified the document since it was last
|
||||
// persisted and clear the map, if there's no collaborators then we don't
|
||||
// need to persist the document.
|
||||
const documentCollaboratorIds = this.documentCollaboratorIds.get(
|
||||
documentName
|
||||
);
|
||||
const documentCollaboratorIds =
|
||||
this.documentCollaboratorIds.get(documentName);
|
||||
if (!documentCollaboratorIds) {
|
||||
Logger.debug("multiplayer", `No changes for ${documentName}`);
|
||||
return;
|
||||
|
||||
@@ -30,8 +30,7 @@ const importMapping: ImportableFile[] = [
|
||||
getMarkdown: docxToMarkdown,
|
||||
},
|
||||
{
|
||||
type:
|
||||
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
|
||||
getMarkdown: docxToMarkdown,
|
||||
},
|
||||
{
|
||||
|
||||
@@ -171,12 +171,12 @@ class Logger {
|
||||
|
||||
if (isString(input)) {
|
||||
if (sensitiveFields.some((field) => input.includes(field))) {
|
||||
return ("[Filtered]" as any) as T;
|
||||
return "[Filtered]" as any as T;
|
||||
}
|
||||
}
|
||||
|
||||
if (isArray(input)) {
|
||||
return (input.map(this.sanitize) as any) as T;
|
||||
return input.map(this.sanitize) as any as T;
|
||||
}
|
||||
|
||||
if (isObject(input)) {
|
||||
|
||||
@@ -26,7 +26,7 @@ import env from "@server/env";
|
||||
import tracer from "./tracer";
|
||||
import * as Tracing from "./tracer";
|
||||
|
||||
type DDTag = typeof DDTags[keyof typeof DDTags];
|
||||
type DDTag = (typeof DDTags)[keyof typeof DDTags];
|
||||
|
||||
type Tags = {
|
||||
[tag in DDTag]?: any;
|
||||
@@ -55,72 +55,74 @@ interface TraceConfig {
|
||||
*
|
||||
* @param config Optional configuration for the span that will be created for this trace.
|
||||
*/
|
||||
export const traceFunction = (config: TraceConfig) => <
|
||||
F extends (...args: any[]) => any,
|
||||
P extends Parameters<F>,
|
||||
R extends ReturnType<F>
|
||||
>(
|
||||
target: F
|
||||
): F =>
|
||||
env.ENVIRONMENT === "test"
|
||||
? target
|
||||
: (function wrapperFn(this: any, ...args: P): R {
|
||||
const { className, methodName = target.name, tags } = config;
|
||||
const childOf = config.isRoot
|
||||
? undefined
|
||||
: tracer.scope().active() || undefined;
|
||||
export const traceFunction =
|
||||
(config: TraceConfig) =>
|
||||
<
|
||||
F extends (...args: any[]) => any,
|
||||
P extends Parameters<F>,
|
||||
R extends ReturnType<F>
|
||||
>(
|
||||
target: F
|
||||
): F =>
|
||||
env.ENVIRONMENT === "test"
|
||||
? target
|
||||
: (function wrapperFn(this: any, ...args: P): R {
|
||||
const { className, methodName = target.name, tags } = config;
|
||||
const childOf = config.isRoot
|
||||
? undefined
|
||||
: tracer.scope().active() || undefined;
|
||||
|
||||
const spanName = config.spanName || className || "DEFAULT_SPAN_NAME";
|
||||
const spanName = config.spanName || className || "DEFAULT_SPAN_NAME";
|
||||
|
||||
const resourceName = config.resourceName
|
||||
? config.resourceName
|
||||
: methodName;
|
||||
const spanOptions: SpanOptions = {
|
||||
childOf,
|
||||
tags: {
|
||||
[DDTags.RESOURCE_NAME]: resourceName,
|
||||
...tags,
|
||||
},
|
||||
};
|
||||
const resourceName = config.resourceName
|
||||
? config.resourceName
|
||||
: methodName;
|
||||
const spanOptions: SpanOptions = {
|
||||
childOf,
|
||||
tags: {
|
||||
[DDTags.RESOURCE_NAME]: resourceName,
|
||||
...tags,
|
||||
},
|
||||
};
|
||||
|
||||
const span = tracer.startSpan(spanName, spanOptions);
|
||||
const span = tracer.startSpan(spanName, spanOptions);
|
||||
|
||||
if (!span) {
|
||||
return target.call(this, ...args);
|
||||
}
|
||||
|
||||
if (config.serviceName) {
|
||||
span.setTag(
|
||||
DDTags.SERVICE_NAME,
|
||||
`${env.DD_SERVICE}-${config.serviceName}`
|
||||
);
|
||||
}
|
||||
|
||||
if (config.makeSearchable) {
|
||||
span.setTag(DDTags.ANALYTICS, true);
|
||||
}
|
||||
|
||||
// The callback fn needs to be wrapped in an arrow fn as the activate fn clobbers `this`
|
||||
return tracer.scope().activate(span, () => {
|
||||
const output = target.call(this, ...args);
|
||||
|
||||
if (output && typeof output.then === "function") {
|
||||
output
|
||||
.catch((error: Error | undefined) => {
|
||||
if (error instanceof Error) {
|
||||
Tracing.setError(error, span);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
span.finish();
|
||||
});
|
||||
} else {
|
||||
span.finish();
|
||||
if (!span) {
|
||||
return target.call(this, ...args);
|
||||
}
|
||||
|
||||
return output;
|
||||
});
|
||||
} as F);
|
||||
if (config.serviceName) {
|
||||
span.setTag(
|
||||
DDTags.SERVICE_NAME,
|
||||
`${env.DD_SERVICE}-${config.serviceName}`
|
||||
);
|
||||
}
|
||||
|
||||
if (config.makeSearchable) {
|
||||
span.setTag(DDTags.ANALYTICS, true);
|
||||
}
|
||||
|
||||
// The callback fn needs to be wrapped in an arrow fn as the activate fn clobbers `this`
|
||||
return tracer.scope().activate(span, () => {
|
||||
const output = target.call(this, ...args);
|
||||
|
||||
if (output && typeof output.then === "function") {
|
||||
output
|
||||
.catch((error: Error | undefined) => {
|
||||
if (error instanceof Error) {
|
||||
Tracing.setError(error, span);
|
||||
}
|
||||
})
|
||||
.finally(() => {
|
||||
span.finish();
|
||||
});
|
||||
} else {
|
||||
span.finish();
|
||||
}
|
||||
|
||||
return output;
|
||||
});
|
||||
} as F);
|
||||
|
||||
const traceMethod = (config?: TraceConfig) =>
|
||||
function <R, A extends any[], F extends (...args: A) => R>(
|
||||
|
||||
@@ -98,8 +98,9 @@ class AuthenticationProvider extends Model {
|
||||
}
|
||||
|
||||
disable = async (options?: SaveOptions<AuthenticationProvider>) => {
|
||||
const res = await (this
|
||||
.constructor as typeof AuthenticationProvider).findAndCountAll({
|
||||
const res = await (
|
||||
this.constructor as typeof AuthenticationProvider
|
||||
).findAndCountAll({
|
||||
...options,
|
||||
where: {
|
||||
teamId: this.teamId,
|
||||
|
||||
@@ -527,8 +527,9 @@ class Document extends ParanoidModel {
|
||||
const getChildDocumentIds = async (
|
||||
...parentDocumentId: string[]
|
||||
): Promise<string[]> => {
|
||||
const childDocuments = await (this
|
||||
.constructor as typeof Document).findAll({
|
||||
const childDocuments = await (
|
||||
this.constructor as typeof Document
|
||||
).findAll({
|
||||
attributes: ["id"],
|
||||
where: {
|
||||
parentDocumentId,
|
||||
@@ -560,8 +561,9 @@ class Document extends ParanoidModel {
|
||||
|
||||
// Helper to archive all child documents for a document
|
||||
const archiveChildren = async (parentDocumentId: string) => {
|
||||
const childDocuments = await (this
|
||||
.constructor as typeof Document).findAll({
|
||||
const childDocuments = await (
|
||||
this.constructor as typeof Document
|
||||
).findAll({
|
||||
where: {
|
||||
parentDocumentId,
|
||||
},
|
||||
|
||||
@@ -1,15 +1,13 @@
|
||||
/* eslint-disable @typescript-eslint/ban-types */
|
||||
|
||||
const Deprecated = (message?: string) => (
|
||||
target: Object,
|
||||
propertyKey: string
|
||||
) => {
|
||||
if (process.env[propertyKey]) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`The environment variable ${propertyKey} is deprecated and will be removed in a future release. ${message}`
|
||||
);
|
||||
}
|
||||
};
|
||||
const Deprecated =
|
||||
(message?: string) => (target: Object, propertyKey: string) => {
|
||||
if (process.env[propertyKey]) {
|
||||
// eslint-disable-next-line no-console
|
||||
console.warn(
|
||||
`The environment variable ${propertyKey} is deprecated and will be removed in a future release. ${message}`
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
export default Deprecated;
|
||||
|
||||
@@ -4,9 +4,7 @@ import NotificationHelper from "@server/models/helpers/NotificationHelper";
|
||||
import { CollectionEvent } from "@server/types";
|
||||
import BaseTask, { TaskPriority } from "./BaseTask";
|
||||
|
||||
export default class CollectionCreatedNotificationsTask extends BaseTask<
|
||||
CollectionEvent
|
||||
> {
|
||||
export default class CollectionCreatedNotificationsTask extends BaseTask<CollectionEvent> {
|
||||
public async perform(event: CollectionEvent) {
|
||||
const collection = await Collection.findByPk(event.collectionId);
|
||||
|
||||
@@ -15,10 +13,11 @@ export default class CollectionCreatedNotificationsTask extends BaseTask<
|
||||
return;
|
||||
}
|
||||
|
||||
const recipients = await NotificationHelper.getCollectionNotificationRecipients(
|
||||
collection,
|
||||
NotificationEventType.CreateCollection
|
||||
);
|
||||
const recipients =
|
||||
await NotificationHelper.getCollectionNotificationRecipients(
|
||||
collection,
|
||||
NotificationEventType.CreateCollection
|
||||
);
|
||||
|
||||
for (const recipient of recipients) {
|
||||
// Suppress notifications for suspended users
|
||||
|
||||
@@ -7,9 +7,7 @@ import ProsemirrorHelper from "@server/models/helpers/ProsemirrorHelper";
|
||||
import { CommentEvent } from "@server/types";
|
||||
import BaseTask, { TaskPriority } from "./BaseTask";
|
||||
|
||||
export default class CommentCreatedNotificationsTask extends BaseTask<
|
||||
CommentEvent
|
||||
> {
|
||||
export default class CommentCreatedNotificationsTask extends BaseTask<CommentEvent> {
|
||||
public async perform(event: CommentEvent) {
|
||||
const [document, comment] = await Promise.all([
|
||||
Document.scope("withCollection").findOne({
|
||||
|
||||
@@ -4,9 +4,7 @@ import ProsemirrorHelper from "@server/models/helpers/ProsemirrorHelper";
|
||||
import { CommentEvent, CommentUpdateEvent } from "@server/types";
|
||||
import BaseTask, { TaskPriority } from "./BaseTask";
|
||||
|
||||
export default class CommentUpdatedNotificationsTask extends BaseTask<
|
||||
CommentEvent
|
||||
> {
|
||||
export default class CommentUpdatedNotificationsTask extends BaseTask<CommentEvent> {
|
||||
public async perform(event: CommentUpdateEvent) {
|
||||
const [document, comment] = await Promise.all([
|
||||
Document.scope("withCollection").findOne({
|
||||
|
||||
@@ -6,9 +6,7 @@ import NotificationHelper from "@server/models/helpers/NotificationHelper";
|
||||
import { DocumentEvent } from "@server/types";
|
||||
import BaseTask, { TaskPriority } from "./BaseTask";
|
||||
|
||||
export default class DocumentPublishedNotificationsTask extends BaseTask<
|
||||
DocumentEvent
|
||||
> {
|
||||
export default class DocumentPublishedNotificationsTask extends BaseTask<DocumentEvent> {
|
||||
public async perform(event: DocumentEvent) {
|
||||
const document = await Document.findByPk(event.documentId, {
|
||||
includeState: true,
|
||||
|
||||
@@ -287,7 +287,8 @@ export default class ImportNotionTask extends ImportTask {
|
||||
/**
|
||||
* Regex to find markdown images of all types
|
||||
*/
|
||||
private ImageRegex = /!\[(?<alt>[^\][]*?)]\((?<filename>[^\][]*?)(?=“|\))“?(?<title>[^\][”]+)?”?\)/g;
|
||||
private ImageRegex =
|
||||
/!\[(?<alt>[^\][]*?)]\((?<filename>[^\][]*?)(?=“|\))“?(?<title>[^\][”]+)?”?\)/g;
|
||||
|
||||
/**
|
||||
* Regex to find markdown links containing ID's that look like UUID's with the
|
||||
@@ -298,5 +299,6 @@ export default class ImportNotionTask extends ImportTask {
|
||||
/**
|
||||
* Regex to find Notion document UUID's in the title of a document.
|
||||
*/
|
||||
private NotionUUIDRegex = /\s([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}|[0-9a-fA-F]{32})$/;
|
||||
private NotionUUIDRegex =
|
||||
/\s([0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}|[0-9a-fA-F]{32})$/;
|
||||
}
|
||||
|
||||
@@ -11,9 +11,7 @@ import NotificationHelper from "@server/models/helpers/NotificationHelper";
|
||||
import { RevisionEvent } from "@server/types";
|
||||
import BaseTask, { TaskPriority } from "./BaseTask";
|
||||
|
||||
export default class RevisionCreatedNotificationsTask extends BaseTask<
|
||||
RevisionEvent
|
||||
> {
|
||||
export default class RevisionCreatedNotificationsTask extends BaseTask<RevisionEvent> {
|
||||
public async perform(event: RevisionEvent) {
|
||||
const [document, revision] = await Promise.all([
|
||||
Document.findByPk(event.documentId, { includeState: true }),
|
||||
|
||||
@@ -133,14 +133,12 @@ router.post("auth.info", auth(), async (ctx: APIContext) => {
|
||||
includeDetails: true,
|
||||
}),
|
||||
team: presentTeam(team),
|
||||
availableTeams: uniqBy(
|
||||
[...signedInTeams, ...availableTeams],
|
||||
"id"
|
||||
).map((team) =>
|
||||
presentAvailableTeam(
|
||||
team,
|
||||
signedInTeamIds.includes(team.id) || team.id === user.teamId
|
||||
)
|
||||
availableTeams: uniqBy([...signedInTeams, ...availableTeams], "id").map(
|
||||
(team) =>
|
||||
presentAvailableTeam(
|
||||
team,
|
||||
signedInTeamIds.includes(team.id) || team.id === user.teamId
|
||||
)
|
||||
),
|
||||
},
|
||||
policies: presentPolicies(user, [team]),
|
||||
|
||||
@@ -168,10 +168,8 @@ router.post(
|
||||
rateLimiter(RateLimiterStrategy.TenPerHour),
|
||||
auth(),
|
||||
async (ctx: APIContext) => {
|
||||
const {
|
||||
attachmentId,
|
||||
format = FileOperationFormat.MarkdownZip,
|
||||
} = ctx.request.body;
|
||||
const { attachmentId, format = FileOperationFormat.MarkdownZip } =
|
||||
ctx.request.body;
|
||||
assertUuid(attachmentId, "attachmentId is required");
|
||||
|
||||
const { user } = ctx.state.auth;
|
||||
@@ -630,16 +628,8 @@ router.post(
|
||||
);
|
||||
|
||||
router.post("collections.update", auth(), async (ctx: APIContext) => {
|
||||
const {
|
||||
id,
|
||||
name,
|
||||
description,
|
||||
icon,
|
||||
permission,
|
||||
color,
|
||||
sort,
|
||||
sharing,
|
||||
} = ctx.request.body;
|
||||
const { id, name, description, icon, permission, color, sort, sharing } =
|
||||
ctx.request.body;
|
||||
|
||||
if (color) {
|
||||
assertHexColor(color, "Invalid hex value (please use format #FFFFFF)");
|
||||
|
||||
@@ -995,21 +995,18 @@ router.post(
|
||||
}
|
||||
}
|
||||
|
||||
const {
|
||||
documents,
|
||||
collections,
|
||||
collectionChanged,
|
||||
} = await sequelize.transaction(async (transaction) =>
|
||||
documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
index,
|
||||
ip: ctx.request.ip,
|
||||
transaction,
|
||||
})
|
||||
);
|
||||
const { documents, collections, collectionChanged } =
|
||||
await sequelize.transaction(async (transaction) =>
|
||||
documentMover({
|
||||
user,
|
||||
document,
|
||||
collectionId,
|
||||
parentDocumentId,
|
||||
index,
|
||||
ip: ctx.request.ip,
|
||||
transaction,
|
||||
})
|
||||
);
|
||||
|
||||
ctx.body = {
|
||||
data: {
|
||||
|
||||
@@ -39,50 +39,49 @@ export default function init(
|
||||
],
|
||||
});
|
||||
|
||||
server.on("upgrade", function (
|
||||
req: IncomingMessage,
|
||||
socket: Duplex,
|
||||
head: Buffer
|
||||
) {
|
||||
if (req.url?.startsWith(path)) {
|
||||
// parse document id and close connection if not present in request
|
||||
const documentId = url
|
||||
.parse(req.url)
|
||||
.pathname?.replace(path, "")
|
||||
.split("/")
|
||||
.pop();
|
||||
server.on(
|
||||
"upgrade",
|
||||
function (req: IncomingMessage, socket: Duplex, head: Buffer) {
|
||||
if (req.url?.startsWith(path)) {
|
||||
// parse document id and close connection if not present in request
|
||||
const documentId = url
|
||||
.parse(req.url)
|
||||
.pathname?.replace(path, "")
|
||||
.split("/")
|
||||
.pop();
|
||||
|
||||
if (documentId) {
|
||||
wss.handleUpgrade(req, socket, head, (client) => {
|
||||
// Handle websocket connection errors as soon as the client is upgraded
|
||||
client.on("error", (error) => {
|
||||
Logger.error(
|
||||
`Websocket error`,
|
||||
error,
|
||||
{
|
||||
documentId,
|
||||
},
|
||||
req
|
||||
);
|
||||
if (documentId) {
|
||||
wss.handleUpgrade(req, socket, head, (client) => {
|
||||
// Handle websocket connection errors as soon as the client is upgraded
|
||||
client.on("error", (error) => {
|
||||
Logger.error(
|
||||
`Websocket error`,
|
||||
error,
|
||||
{
|
||||
documentId,
|
||||
},
|
||||
req
|
||||
);
|
||||
});
|
||||
|
||||
hocuspocus.handleConnection(client, req, documentId);
|
||||
});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
hocuspocus.handleConnection(client, req, documentId);
|
||||
});
|
||||
if (
|
||||
req.url?.startsWith("/realtime") &&
|
||||
serviceNames.includes("websockets")
|
||||
) {
|
||||
// Nothing to do, the websockets service will handle this request
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
req.url?.startsWith("/realtime") &&
|
||||
serviceNames.includes("websockets")
|
||||
) {
|
||||
// Nothing to do, the websockets service will handle this request
|
||||
return;
|
||||
// If the collaboration service is running it will close the connection
|
||||
socket.end(`HTTP/1.1 400 Bad Request\r\n`);
|
||||
}
|
||||
|
||||
// If the collaboration service is running it will close the connection
|
||||
socket.end(`HTTP/1.1 400 Bad Request\r\n`);
|
||||
});
|
||||
);
|
||||
|
||||
ShutdownHelper.add("collaboration", ShutdownOrder.normal, () =>
|
||||
hocuspocus.destroy()
|
||||
|
||||
@@ -53,25 +53,24 @@ export default function init(
|
||||
);
|
||||
}
|
||||
|
||||
server.on("upgrade", function (
|
||||
req: IncomingMessage,
|
||||
socket: Duplex,
|
||||
head: Buffer
|
||||
) {
|
||||
if (req.url?.startsWith(path)) {
|
||||
invariant(ioHandleUpgrade, "Existing upgrade handler must exist");
|
||||
ioHandleUpgrade(req, socket, head);
|
||||
return;
|
||||
}
|
||||
server.on(
|
||||
"upgrade",
|
||||
function (req: IncomingMessage, socket: Duplex, head: Buffer) {
|
||||
if (req.url?.startsWith(path)) {
|
||||
invariant(ioHandleUpgrade, "Existing upgrade handler must exist");
|
||||
ioHandleUpgrade(req, socket, head);
|
||||
return;
|
||||
}
|
||||
|
||||
if (serviceNames.includes("collaboration")) {
|
||||
// Nothing to do, the collaboration service will handle this request
|
||||
return;
|
||||
}
|
||||
if (serviceNames.includes("collaboration")) {
|
||||
// Nothing to do, the collaboration service will handle this request
|
||||
return;
|
||||
}
|
||||
|
||||
// If the collaboration service isn't running then we need to close the connection
|
||||
socket.end(`HTTP/1.1 400 Bad Request\r\n`);
|
||||
});
|
||||
// If the collaboration service isn't running then we need to close the connection
|
||||
socket.end(`HTTP/1.1 400 Bad Request\r\n`);
|
||||
}
|
||||
);
|
||||
|
||||
ShutdownHelper.add("websockets", ShutdownOrder.normal, async () => {
|
||||
Metrics.gaugePerInstance("websockets.count", 0);
|
||||
|
||||
@@ -55,7 +55,8 @@ it("should parse attachment ID from markdown with title", () => {
|
||||
it("should parse multiple attachment IDs from markdown", () => {
|
||||
const uuid = uuidv4();
|
||||
const uuid2 = uuidv4();
|
||||
const results = parseAttachmentIds(`
|
||||
const results =
|
||||
parseAttachmentIds(`
|
||||
|
||||
some text
|
||||
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
import { uniq, compact } from "lodash";
|
||||
|
||||
const attachmentRedirectRegex = /\/api\/attachments\.redirect\?id=(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
||||
const attachmentPublicRegex = /public\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
||||
const attachmentRedirectRegex =
|
||||
/\/api\/attachments\.redirect\?id=(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
||||
const attachmentPublicRegex =
|
||||
/public\/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})\/(?<id>[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/gi;
|
||||
|
||||
export default function parseAttachmentIds(
|
||||
text: string,
|
||||
|
||||
@@ -14,17 +14,13 @@ const UPDATES_KEY = "UPDATES_KEY";
|
||||
export async function checkUpdates() {
|
||||
const secret = env.SECRET_KEY.slice(0, 6) + env.URL;
|
||||
const id = crypto.createHash("sha256").update(secret).digest("hex");
|
||||
const [
|
||||
userCount,
|
||||
teamCount,
|
||||
collectionCount,
|
||||
documentCount,
|
||||
] = await Promise.all([
|
||||
User.count(),
|
||||
Team.count(),
|
||||
Collection.count(),
|
||||
Document.count(),
|
||||
]);
|
||||
const [userCount, teamCount, collectionCount, documentCount] =
|
||||
await Promise.all([
|
||||
User.count(),
|
||||
Team.count(),
|
||||
Collection.count(),
|
||||
Document.count(),
|
||||
]);
|
||||
const body = JSON.stringify({
|
||||
id,
|
||||
version: 1,
|
||||
|
||||
@@ -18,7 +18,7 @@ export function CannotUseWithout(
|
||||
options: validationOptions,
|
||||
validator: {
|
||||
validate<T>(value: T, args: ValidationArguments) {
|
||||
const object = (args.object as unknown) as T;
|
||||
const object = args.object as unknown as T;
|
||||
const required = args.constraints[0] as string;
|
||||
return object[required] !== undefined;
|
||||
},
|
||||
|
||||
@@ -96,9 +96,8 @@ export const newlineInCode = (state: EditorState, dispatch: Dispatch) => {
|
||||
|
||||
if (text) {
|
||||
const splitByNewLine = text.split("\n");
|
||||
const numOfSpaces = splitByNewLine[splitByNewLine.length - 1].search(
|
||||
/\S|$/
|
||||
);
|
||||
const numOfSpaces =
|
||||
splitByNewLine[splitByNewLine.length - 1].search(/\S|$/);
|
||||
newText += " ".repeat(numOfSpaces);
|
||||
}
|
||||
|
||||
|
||||
@@ -100,18 +100,18 @@ const Image = (
|
||||
document.removeEventListener("mousemove", handlePointerMove);
|
||||
};
|
||||
|
||||
const handlePointerDown = (dragging: "left" | "right") => (
|
||||
event: React.PointerEvent<HTMLDivElement>
|
||||
) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
setSizeAtDragStart({
|
||||
width: constrainWidth(size.width),
|
||||
height: size.height,
|
||||
});
|
||||
setOffset(event.pageX);
|
||||
setDragging(dragging);
|
||||
};
|
||||
const handlePointerDown =
|
||||
(dragging: "left" | "right") =>
|
||||
(event: React.PointerEvent<HTMLDivElement>) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
setSizeAtDragStart({
|
||||
width: constrainWidth(size.width),
|
||||
height: size.height,
|
||||
});
|
||||
setOffset(event.pageX);
|
||||
setDragging(dragging);
|
||||
};
|
||||
|
||||
const handleKeyDown = (event: KeyboardEvent) => {
|
||||
if (event.key === "Escape") {
|
||||
@@ -170,11 +170,14 @@ const Image = (
|
||||
onClick={dragging ? undefined : props.onClick}
|
||||
style={widthStyle}
|
||||
>
|
||||
{!dragging && size.width > 60 && size.height > 60 && props.onDownload && (
|
||||
<Button onClick={props.onDownload}>
|
||||
<DownloadIcon />
|
||||
</Button>
|
||||
)}
|
||||
{!dragging &&
|
||||
size.width > 60 &&
|
||||
size.height > 60 &&
|
||||
props.onDownload && (
|
||||
<Button onClick={props.onDownload}>
|
||||
<DownloadIcon />
|
||||
</Button>
|
||||
)}
|
||||
<ImageZoom zoomMargin={24}>
|
||||
<img
|
||||
style={{
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { useState, useEffect } from "react";
|
||||
|
||||
export default function useComponentSize(
|
||||
ref: React.RefObject<HTMLElement>
|
||||
): { width: number; height: number } {
|
||||
export default function useComponentSize(ref: React.RefObject<HTMLElement>): {
|
||||
width: number;
|
||||
height: number;
|
||||
} {
|
||||
const [size, setSize] = useState({
|
||||
width: ref.current?.clientWidth || 0,
|
||||
height: ref.current?.clientHeight || 0,
|
||||
|
||||
@@ -2,7 +2,8 @@ import * as React from "react";
|
||||
import Frame from "../components/Frame";
|
||||
import { EmbedProps as Props } from ".";
|
||||
|
||||
const URL_REGEX = /(?:https?:\/\/)?(www\.bilibili\.com)\/video\/([\w\d]+)?(\?\S+)?/i;
|
||||
const URL_REGEX =
|
||||
/(?:https?:\/\/)?(www\.bilibili\.com)\/video\/([\w\d]+)?(\?\S+)?/i;
|
||||
|
||||
export default function Bilibili(props: Props) {
|
||||
const { matches } = props.attrs;
|
||||
|
||||
@@ -3,8 +3,10 @@ import Frame from "../components/Frame";
|
||||
import ImageZoom from "../components/ImageZoom";
|
||||
import { EmbedProps as Props } from ".";
|
||||
|
||||
const IFRAME_REGEX = /^https:\/\/(invis\.io\/.*)|(projects\.invisionapp\.com\/share\/.*)$/;
|
||||
const IMAGE_REGEX = /^https:\/\/(opal\.invisionapp\.com\/static-signed\/live-embed\/.*)$/;
|
||||
const IFRAME_REGEX =
|
||||
/^https:\/\/(invis\.io\/.*)|(projects\.invisionapp\.com\/share\/.*)$/;
|
||||
const IMAGE_REGEX =
|
||||
/^https:\/\/(opal\.invisionapp\.com\/static-signed\/live-embed\/.*)$/;
|
||||
|
||||
function InVision(props: Props) {
|
||||
if (IMAGE_REGEX.test(props.attrs.href)) {
|
||||
|
||||
@@ -164,9 +164,8 @@ export default function Mermaid({
|
||||
}
|
||||
|
||||
if (diagramToggled) {
|
||||
pluginState.diagramVisibility[
|
||||
mermaidMeta.toggleDiagram
|
||||
] = !pluginState.diagramVisibility[mermaidMeta.toggleDiagram];
|
||||
pluginState.diagramVisibility[mermaidMeta.toggleDiagram] =
|
||||
!pluginState.diagramVisibility[mermaidMeta.toggleDiagram];
|
||||
}
|
||||
|
||||
if (
|
||||
|
||||
@@ -114,15 +114,13 @@ export default class Embed extends Node {
|
||||
}
|
||||
|
||||
commands({ type }: { type: NodeType }) {
|
||||
return (attrs: Record<string, any>) => (
|
||||
state: EditorState,
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
dispatch(
|
||||
state.tr.replaceSelectionWith(type.create(attrs)).scrollIntoView()
|
||||
);
|
||||
return true;
|
||||
};
|
||||
return (attrs: Record<string, any>) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
dispatch(
|
||||
state.tr.replaceSelectionWith(type.create(attrs)).scrollIntoView()
|
||||
);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
|
||||
|
||||
@@ -22,7 +22,8 @@ export default class Emoji extends Suggestion {
|
||||
return {
|
||||
type: SuggestionsMenuType.Emoji,
|
||||
openRegex: /(?:^|\s):([0-9a-zA-Z_+-]+)?$/,
|
||||
closeRegex: /(?:^|\s):(([0-9a-zA-Z_+-]*\s+)|(\s+[0-9a-zA-Z_+-]+)|[^0-9a-zA-Z_+-]+)$/,
|
||||
closeRegex:
|
||||
/(?:^|\s):(([0-9a-zA-Z_+-]*\s+)|(\s+[0-9a-zA-Z_+-]+)|[^0-9a-zA-Z_+-]+)$/,
|
||||
enabledInTable: true,
|
||||
};
|
||||
}
|
||||
@@ -77,24 +78,22 @@ export default class Emoji extends Suggestion {
|
||||
}
|
||||
|
||||
commands({ type }: { type: NodeType; schema: Schema }) {
|
||||
return (attrs: Record<string, string>) => (
|
||||
state: EditorState,
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
const { selection } = state;
|
||||
const position =
|
||||
selection instanceof TextSelection
|
||||
? selection.$cursor?.pos
|
||||
: selection.$to.pos;
|
||||
if (position === undefined) {
|
||||
return false;
|
||||
}
|
||||
return (attrs: Record<string, string>) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
const { selection } = state;
|
||||
const position =
|
||||
selection instanceof TextSelection
|
||||
? selection.$cursor?.pos
|
||||
: selection.$to.pos;
|
||||
if (position === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const node = type.create(attrs);
|
||||
const transaction = state.tr.insert(position, node);
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
};
|
||||
const node = type.create(attrs);
|
||||
const transaction = state.tr.insert(position, node);
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
|
||||
|
||||
@@ -28,15 +28,13 @@ export default class HorizontalRule extends Node {
|
||||
}
|
||||
|
||||
commands({ type }: { type: NodeType }) {
|
||||
return (attrs: Record<string, any>) => (
|
||||
state: EditorState,
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
dispatch(
|
||||
state.tr.replaceSelectionWith(type.create(attrs)).scrollIntoView()
|
||||
);
|
||||
return true;
|
||||
};
|
||||
return (attrs: Record<string, any>) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
dispatch(
|
||||
state.tr.replaceSelectionWith(type.create(attrs)).scrollIntoView()
|
||||
);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
keys({ type }: { type: NodeType }) {
|
||||
|
||||
@@ -189,35 +189,31 @@ export default class Image extends SimpleImage {
|
||||
];
|
||||
}
|
||||
|
||||
handleChangeSize = ({
|
||||
node,
|
||||
getPos,
|
||||
}: {
|
||||
node: ProsemirrorNode;
|
||||
getPos: () => number;
|
||||
}) => ({ width, height }: { width: number; height?: number }) => {
|
||||
const { view } = this.editor;
|
||||
const { tr } = view.state;
|
||||
handleChangeSize =
|
||||
({ node, getPos }: { node: ProsemirrorNode; getPos: () => number }) =>
|
||||
({ width, height }: { width: number; height?: number }) => {
|
||||
const { view } = this.editor;
|
||||
const { tr } = view.state;
|
||||
|
||||
const pos = getPos();
|
||||
const transaction = tr
|
||||
.setNodeMarkup(pos, undefined, {
|
||||
...node.attrs,
|
||||
width,
|
||||
height,
|
||||
})
|
||||
.setMeta("addToHistory", true);
|
||||
const $pos = transaction.doc.resolve(getPos());
|
||||
view.dispatch(transaction.setSelection(new NodeSelection($pos)));
|
||||
};
|
||||
const pos = getPos();
|
||||
const transaction = tr
|
||||
.setNodeMarkup(pos, undefined, {
|
||||
...node.attrs,
|
||||
width,
|
||||
height,
|
||||
})
|
||||
.setMeta("addToHistory", true);
|
||||
const $pos = transaction.doc.resolve(getPos());
|
||||
view.dispatch(transaction.setSelection(new NodeSelection($pos)));
|
||||
};
|
||||
|
||||
handleDownload = ({ node }: { node: ProsemirrorNode }) => (
|
||||
event: React.MouseEvent
|
||||
) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
downloadImageNode(node);
|
||||
};
|
||||
handleDownload =
|
||||
({ node }: { node: ProsemirrorNode }) =>
|
||||
(event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
downloadImageNode(node);
|
||||
};
|
||||
|
||||
component = (props: ComponentProps) => (
|
||||
<ImageComponent
|
||||
@@ -360,7 +356,8 @@ export default class Image extends SimpleImage {
|
||||
*  -> [, "", "image.jpg", "small"]
|
||||
*  -> [, "Lorem", "image.jpg", "small"]
|
||||
*/
|
||||
const IMAGE_INPUT_REGEX = /!\[(?<alt>[^\][]*?)]\((?<filename>[^\][]*?)(?=“|\))“?(?<layoutclass>[^\][”]+)?”?\)$/;
|
||||
const IMAGE_INPUT_REGEX =
|
||||
/!\[(?<alt>[^\][]*?)]\((?<filename>[^\][]*?)(?=“|\))“?(?<layoutclass>[^\][”]+)?”?\)$/;
|
||||
|
||||
return [
|
||||
new InputRule(IMAGE_INPUT_REGEX, (state, match, start, end) => {
|
||||
|
||||
@@ -80,24 +80,22 @@ export default class Mention extends Suggestion {
|
||||
}
|
||||
|
||||
commands({ type }: { type: NodeType; schema: Schema }) {
|
||||
return (attrs: Record<string, string>) => (
|
||||
state: EditorState,
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
const { selection } = state;
|
||||
const position =
|
||||
selection instanceof TextSelection
|
||||
? selection.$cursor?.pos
|
||||
: selection.$to.pos;
|
||||
if (position === undefined) {
|
||||
return false;
|
||||
}
|
||||
return (attrs: Record<string, string>) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
const { selection } = state;
|
||||
const position =
|
||||
selection instanceof TextSelection
|
||||
? selection.$cursor?.pos
|
||||
: selection.$to.pos;
|
||||
if (position === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const node = type.create(attrs);
|
||||
const transaction = state.tr.insert(position, node);
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
};
|
||||
const node = type.create(attrs);
|
||||
const transaction = state.tr.insert(position, node);
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
};
|
||||
}
|
||||
|
||||
toMarkdown(state: MarkdownSerializerState, node: ProsemirrorNode) {
|
||||
|
||||
@@ -75,73 +75,65 @@ export default class SimpleImage extends Node {
|
||||
};
|
||||
}
|
||||
|
||||
handleKeyDown = ({
|
||||
node,
|
||||
getPos,
|
||||
}: {
|
||||
node: ProsemirrorNode;
|
||||
getPos: () => number;
|
||||
}) => (event: React.KeyboardEvent<HTMLSpanElement>) => {
|
||||
// Pressing Enter in the caption field should move the cursor/selection
|
||||
// below the image
|
||||
if (event.key === "Enter") {
|
||||
handleKeyDown =
|
||||
({ node, getPos }: { node: ProsemirrorNode; getPos: () => number }) =>
|
||||
(event: React.KeyboardEvent<HTMLSpanElement>) => {
|
||||
// Pressing Enter in the caption field should move the cursor/selection
|
||||
// below the image
|
||||
if (event.key === "Enter") {
|
||||
event.preventDefault();
|
||||
|
||||
const { view } = this.editor;
|
||||
const $pos = view.state.doc.resolve(getPos() + node.nodeSize);
|
||||
view.dispatch(
|
||||
view.state.tr.setSelection(new TextSelection($pos)).split($pos.pos)
|
||||
);
|
||||
view.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Pressing Backspace in an an empty caption field should remove the entire
|
||||
// image, leaving an empty paragraph
|
||||
if (event.key === "Backspace" && event.currentTarget.innerText === "") {
|
||||
const { view } = this.editor;
|
||||
const $pos = view.state.doc.resolve(getPos());
|
||||
const tr = view.state.tr.setSelection(new NodeSelection($pos));
|
||||
view.dispatch(tr.deleteSelection());
|
||||
view.focus();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
handleBlur =
|
||||
({ node, getPos }: { node: ProsemirrorNode; getPos: () => number }) =>
|
||||
(event: React.FocusEvent<HTMLSpanElement>) => {
|
||||
const caption = event.currentTarget.innerText;
|
||||
if (caption === node.attrs.alt) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { view } = this.editor;
|
||||
const { tr } = view.state;
|
||||
|
||||
// update meta on object
|
||||
const pos = getPos();
|
||||
const transaction = tr.setNodeMarkup(pos, undefined, {
|
||||
...node.attrs,
|
||||
alt: caption,
|
||||
});
|
||||
view.dispatch(transaction);
|
||||
};
|
||||
|
||||
handleSelect =
|
||||
({ getPos }: { getPos: () => number }) =>
|
||||
(event: React.MouseEvent) => {
|
||||
event.preventDefault();
|
||||
|
||||
const { view } = this.editor;
|
||||
const $pos = view.state.doc.resolve(getPos() + node.nodeSize);
|
||||
view.dispatch(
|
||||
view.state.tr.setSelection(new TextSelection($pos)).split($pos.pos)
|
||||
);
|
||||
view.focus();
|
||||
return;
|
||||
}
|
||||
|
||||
// Pressing Backspace in an an empty caption field should remove the entire
|
||||
// image, leaving an empty paragraph
|
||||
if (event.key === "Backspace" && event.currentTarget.innerText === "") {
|
||||
const { view } = this.editor;
|
||||
const $pos = view.state.doc.resolve(getPos());
|
||||
const tr = view.state.tr.setSelection(new NodeSelection($pos));
|
||||
view.dispatch(tr.deleteSelection());
|
||||
view.focus();
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
handleBlur = ({
|
||||
node,
|
||||
getPos,
|
||||
}: {
|
||||
node: ProsemirrorNode;
|
||||
getPos: () => number;
|
||||
}) => (event: React.FocusEvent<HTMLSpanElement>) => {
|
||||
const caption = event.currentTarget.innerText;
|
||||
if (caption === node.attrs.alt) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { view } = this.editor;
|
||||
const { tr } = view.state;
|
||||
|
||||
// update meta on object
|
||||
const pos = getPos();
|
||||
const transaction = tr.setNodeMarkup(pos, undefined, {
|
||||
...node.attrs,
|
||||
alt: caption,
|
||||
});
|
||||
view.dispatch(transaction);
|
||||
};
|
||||
|
||||
handleSelect = ({ getPos }: { getPos: () => number }) => (
|
||||
event: React.MouseEvent
|
||||
) => {
|
||||
event.preventDefault();
|
||||
|
||||
const { view } = this.editor;
|
||||
const $pos = view.state.doc.resolve(getPos());
|
||||
const transaction = view.state.tr.setSelection(new NodeSelection($pos));
|
||||
view.dispatch(transaction);
|
||||
};
|
||||
const transaction = view.state.tr.setSelection(new NodeSelection($pos));
|
||||
view.dispatch(transaction);
|
||||
};
|
||||
|
||||
handleMouseDown = (ev: React.MouseEvent<HTMLParagraphElement>) => {
|
||||
if (document.activeElement !== ev.currentTarget) {
|
||||
@@ -189,12 +181,8 @@ export default class SimpleImage extends Node {
|
||||
}
|
||||
const { view } = this.editor;
|
||||
const { node } = state.selection;
|
||||
const {
|
||||
uploadFile,
|
||||
onFileUploadStart,
|
||||
onFileUploadStop,
|
||||
onShowToast,
|
||||
} = this.editor.props;
|
||||
const { uploadFile, onFileUploadStart, onFileUploadStop, onShowToast } =
|
||||
this.editor.props;
|
||||
|
||||
if (!uploadFile) {
|
||||
throw new Error("uploadFile prop is required to replace images");
|
||||
@@ -225,24 +213,23 @@ export default class SimpleImage extends Node {
|
||||
inputElement.click();
|
||||
return true;
|
||||
},
|
||||
createImage: (attrs: Record<string, any>) => (
|
||||
state: EditorState,
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
const { selection } = state;
|
||||
const position =
|
||||
selection instanceof TextSelection
|
||||
? selection.$cursor?.pos
|
||||
: selection.$to.pos;
|
||||
if (position === undefined) {
|
||||
return false;
|
||||
}
|
||||
createImage:
|
||||
(attrs: Record<string, any>) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
const { selection } = state;
|
||||
const position =
|
||||
selection instanceof TextSelection
|
||||
? selection.$cursor?.pos
|
||||
: selection.$to.pos;
|
||||
if (position === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const node = type.create(attrs);
|
||||
const transaction = state.tr.insert(position, node);
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
},
|
||||
const node = type.create(attrs);
|
||||
const transaction = state.tr.insert(position, node);
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -255,7 +242,8 @@ export default class SimpleImage extends Node {
|
||||
*  -> [, "", "image.jpg", "small"]
|
||||
*  -> [, "Lorem", "image.jpg", "small"]
|
||||
*/
|
||||
const IMAGE_INPUT_REGEX = /!\[(?<alt>[^\][]*?)]\((?<filename>[^\][]*?)(?=“|\))“?(?<layoutclass>[^\][”]+)?”?\)$/;
|
||||
const IMAGE_INPUT_REGEX =
|
||||
/!\[(?<alt>[^\][]*?)]\((?<filename>[^\][]*?)(?=“|\))“?(?<layoutclass>[^\][”]+)?”?\)$/;
|
||||
|
||||
return [
|
||||
new InputRule(IMAGE_INPUT_REGEX, (state, match, start, end) => {
|
||||
|
||||
@@ -60,56 +60,47 @@ export default class Table extends Node {
|
||||
|
||||
commands({ schema }: { schema: Schema }) {
|
||||
return {
|
||||
createTable: ({
|
||||
rowsCount,
|
||||
colsCount,
|
||||
}: {
|
||||
rowsCount: number;
|
||||
colsCount: number;
|
||||
}) => (state: EditorState, dispatch: Dispatch) => {
|
||||
const offset = state.tr.selection.anchor + 1;
|
||||
const nodes = createTable(schema, rowsCount, colsCount);
|
||||
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView();
|
||||
const resolvedPos = tr.doc.resolve(offset);
|
||||
createTable:
|
||||
({ rowsCount, colsCount }: { rowsCount: number; colsCount: number }) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
const offset = state.tr.selection.anchor + 1;
|
||||
const nodes = createTable(schema, rowsCount, colsCount);
|
||||
const tr = state.tr.replaceSelectionWith(nodes).scrollIntoView();
|
||||
const resolvedPos = tr.doc.resolve(offset);
|
||||
|
||||
tr.setSelection(TextSelection.near(resolvedPos));
|
||||
dispatch(tr);
|
||||
return true;
|
||||
},
|
||||
setColumnAttr: ({
|
||||
index,
|
||||
alignment,
|
||||
}: {
|
||||
index: number;
|
||||
alignment: string;
|
||||
}) => (state: EditorState, dispatch: Dispatch) => {
|
||||
const cells = getCellsInColumn(index)(state.selection) || [];
|
||||
let transaction = state.tr;
|
||||
cells.forEach(({ pos }) => {
|
||||
transaction = transaction.setNodeMarkup(pos, undefined, {
|
||||
alignment,
|
||||
tr.setSelection(TextSelection.near(resolvedPos));
|
||||
dispatch(tr);
|
||||
return true;
|
||||
},
|
||||
setColumnAttr:
|
||||
({ index, alignment }: { index: number; alignment: string }) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
const cells = getCellsInColumn(index)(state.selection) || [];
|
||||
let transaction = state.tr;
|
||||
cells.forEach(({ pos }) => {
|
||||
transaction = transaction.setNodeMarkup(pos, undefined, {
|
||||
alignment,
|
||||
});
|
||||
});
|
||||
});
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
},
|
||||
dispatch(transaction);
|
||||
return true;
|
||||
},
|
||||
addColumnBefore: () => addColumnBefore,
|
||||
addColumnAfter: () => addColumnAfter,
|
||||
deleteColumn: () => deleteColumn,
|
||||
addRowAfter: ({ index }: { index: number }) => (
|
||||
state: EditorState,
|
||||
dispatch: Dispatch
|
||||
) => {
|
||||
if (index === 0) {
|
||||
// A little hack to avoid cloning the heading row by cloning the row
|
||||
// beneath and then moving it to the right index.
|
||||
const tr = addRowAt(index + 2, true)(state.tr);
|
||||
dispatch(moveRow(index + 2, index + 1)(tr));
|
||||
} else {
|
||||
dispatch(addRowAt(index + 1, true)(state.tr));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
addRowAfter:
|
||||
({ index }: { index: number }) =>
|
||||
(state: EditorState, dispatch: Dispatch) => {
|
||||
if (index === 0) {
|
||||
// A little hack to avoid cloning the heading row by cloning the row
|
||||
// beneath and then moving it to the right index.
|
||||
const tr = addRowAt(index + 2, true)(state.tr);
|
||||
dispatch(moveRow(index + 2, index + 1)(tr));
|
||||
} else {
|
||||
dispatch(addRowAt(index + 1, true)(state.tr));
|
||||
}
|
||||
return true;
|
||||
},
|
||||
deleteRow: () => deleteRow,
|
||||
deleteTable: () => deleteTable,
|
||||
toggleHeaderColumn: () => toggleHeaderColumn,
|
||||
@@ -127,7 +118,7 @@ export default class Table extends Node {
|
||||
return false;
|
||||
}
|
||||
const index = getRowIndexFromText(
|
||||
(state.selection as unknown) as CellSelection
|
||||
state.selection as unknown as CellSelection
|
||||
);
|
||||
|
||||
if (index === 0) {
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
import { MarkType } from "prosemirror-model";
|
||||
import { EditorState } from "prosemirror-state";
|
||||
|
||||
const isMarkActive = (type: MarkType) => (state: EditorState): boolean => {
|
||||
if (!type) {
|
||||
return false;
|
||||
}
|
||||
const isMarkActive =
|
||||
(type: MarkType) =>
|
||||
(state: EditorState): boolean => {
|
||||
if (!type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { from, $from, to, empty } = state.selection;
|
||||
const { from, $from, to, empty } = state.selection;
|
||||
|
||||
return !!(empty
|
||||
? type.isInSet(state.storedMarks || $from.marks())
|
||||
: state.doc.rangeHasMark(from, to, type));
|
||||
};
|
||||
return !!(empty
|
||||
? type.isInSet(state.storedMarks || $from.marks())
|
||||
: state.doc.rangeHasMark(from, to, type));
|
||||
};
|
||||
|
||||
export default isMarkActive;
|
||||
|
||||
@@ -2,22 +2,22 @@ import { NodeType } from "prosemirror-model";
|
||||
import { EditorState } from "prosemirror-state";
|
||||
import { findParentNode, findSelectedNodeOfType } from "prosemirror-utils";
|
||||
|
||||
const isNodeActive = (type: NodeType, attrs: Record<string, any> = {}) => (
|
||||
state: EditorState
|
||||
) => {
|
||||
if (!type) {
|
||||
return false;
|
||||
}
|
||||
const isNodeActive =
|
||||
(type: NodeType, attrs: Record<string, any> = {}) =>
|
||||
(state: EditorState) => {
|
||||
if (!type) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const node =
|
||||
findSelectedNodeOfType(type)(state.selection) ||
|
||||
findParentNode((node) => node.type === type)(state.selection);
|
||||
const node =
|
||||
findSelectedNodeOfType(type)(state.selection) ||
|
||||
findParentNode((node) => node.type === type)(state.selection);
|
||||
|
||||
if (!Object.keys(attrs).length || !node) {
|
||||
return !!node;
|
||||
}
|
||||
if (!Object.keys(attrs).length || !node) {
|
||||
return !!node;
|
||||
}
|
||||
|
||||
return node.node.hasMarkup(type, { ...node.node.attrs, ...attrs });
|
||||
};
|
||||
return node.node.hasMarkup(type, { ...node.node.attrs, ...attrs });
|
||||
};
|
||||
|
||||
export default isNodeActive;
|
||||
|
||||
@@ -20,9 +20,9 @@ export const ellipsis = () => `
|
||||
*
|
||||
* @returns a theme value
|
||||
*/
|
||||
export const s = (key: keyof DefaultTheme) => (props: {
|
||||
theme: DefaultTheme;
|
||||
}) => String(props.theme[key]);
|
||||
export const s =
|
||||
(key: keyof DefaultTheme) => (props: { theme: DefaultTheme }) =>
|
||||
String(props.theme[key]);
|
||||
|
||||
/**
|
||||
* Mixin to hide scrollbars.
|
||||
|
||||
@@ -10568,10 +10568,10 @@ prettier-linter-helpers@^1.0.0:
|
||||
dependencies:
|
||||
fast-diff "^1.1.2"
|
||||
|
||||
prettier@^2.0.5:
|
||||
version "2.1.2"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.2.tgz#3050700dae2e4c8b67c4c3f666cdb8af405e1ce5"
|
||||
integrity sha512-16c7K+x4qVlJg9rEbXl7HEGmQyZlG4R9AgP+oHKRMsMsuk8s+ATStlf1NpDqyBI1HpVyfjLOeMhH2LvuNvV5Vg==
|
||||
prettier@^2.8.8:
|
||||
version "2.8.8"
|
||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.8.8.tgz#e8c5d7e98a4305ffe3de2e1fc4aca1a71c28b1da"
|
||||
integrity sha512-tdN8qQGvNjw4CHbY+XXk0JgCXn9QiF21a55rBe5LJAU+kDyC4WQn4+awm2Xfk2lQMk5fKup9XgzTZtGkjBdP9Q==
|
||||
|
||||
pretty-bytes@^5.3.0:
|
||||
version "5.6.0"
|
||||
|
||||
Reference in New Issue
Block a user