|
@@ -1,5 +1,5 @@
|
|
|
import type { FC } from 'react';
|
|
import type { FC } from 'react';
|
|
|
-import { useCallback, useEffect, useRef } from 'react';
|
|
|
|
|
|
|
+import { useCallback } from 'react';
|
|
|
|
|
|
|
|
import path from 'path';
|
|
import path from 'path';
|
|
|
|
|
|
|
@@ -13,6 +13,7 @@ import { toastSuccess } from '~/client/util/toastr';
|
|
|
import {
|
|
import {
|
|
|
CREATING_PAGE_VIRTUAL_ID,
|
|
CREATING_PAGE_VIRTUAL_ID,
|
|
|
ROOT_PAGE_VIRTUAL_ID, usePageTreeInformationUpdate, usePageRename, usePageCreate,
|
|
ROOT_PAGE_VIRTUAL_ID, usePageTreeInformationUpdate, usePageRename, usePageCreate,
|
|
|
|
|
+ usePlaceholderRenameEffect,
|
|
|
NameInputAlternativeComponent,
|
|
NameInputAlternativeComponent,
|
|
|
} from '~/features/page-tree';
|
|
} from '~/features/page-tree';
|
|
|
import type { IPageForItem } from '~/interfaces/page';
|
|
import type { IPageForItem } from '~/interfaces/page';
|
|
@@ -118,35 +119,12 @@ export const SimplifiedPageTreeItem: FC<TreeItemProps> = ({
|
|
|
// Check if this is the creating placeholder node
|
|
// Check if this is the creating placeholder node
|
|
|
const isCreatingPlaceholder = itemData._id === CREATING_PAGE_VIRTUAL_ID;
|
|
const isCreatingPlaceholder = itemData._id === CREATING_PAGE_VIRTUAL_ID;
|
|
|
|
|
|
|
|
- // Track if renaming mode was ever activated for this placeholder
|
|
|
|
|
- const wasRenamingRef = useRef(false);
|
|
|
|
|
- const isRenamingNow = item.isRenaming();
|
|
|
|
|
-
|
|
|
|
|
- // Start renaming mode on placeholder node to enable getRenameInputProps()
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (isCreatingPlaceholder && !item.isRenaming()) {
|
|
|
|
|
- item.startRenaming();
|
|
|
|
|
- }
|
|
|
|
|
- }, [isCreatingPlaceholder, item]);
|
|
|
|
|
-
|
|
|
|
|
- // Track when renaming becomes active
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- if (isCreatingPlaceholder && isRenamingNow) {
|
|
|
|
|
- wasRenamingRef.current = true;
|
|
|
|
|
- }
|
|
|
|
|
- }, [isCreatingPlaceholder, isRenamingNow]);
|
|
|
|
|
-
|
|
|
|
|
- // Cancel creating when renaming mode ends on placeholder node (Esc key pressed)
|
|
|
|
|
- useEffect(() => {
|
|
|
|
|
- // Only cancel if renaming was previously active and is now inactive
|
|
|
|
|
- if (isCreatingPlaceholder && wasRenamingRef.current && !isRenamingNow) {
|
|
|
|
|
- cancelCreating();
|
|
|
|
|
- wasRenamingRef.current = false;
|
|
|
|
|
- }
|
|
|
|
|
- }, [isCreatingPlaceholder, isRenamingNow, cancelCreating]);
|
|
|
|
|
-
|
|
|
|
|
- // Show CreateInput only when renamingFeature is active (item.isRenaming() is true)
|
|
|
|
|
- const showCreateInput = isCreatingPlaceholder && item.isRenaming();
|
|
|
|
|
|
|
+ // Manage placeholder renaming mode (auto-start, track, and cancel on Esc)
|
|
|
|
|
+ usePlaceholderRenameEffect({
|
|
|
|
|
+ item,
|
|
|
|
|
+ isPlaceholder: isCreatingPlaceholder,
|
|
|
|
|
+ onCancelCreate: cancelCreating,
|
|
|
|
|
+ });
|
|
|
|
|
|
|
|
const itemSelectedHandler = useCallback((page: IPageForItem) => {
|
|
const itemSelectedHandler = useCallback((page: IPageForItem) => {
|
|
|
if (page.path == null || page._id == null) return;
|
|
if (page.path == null || page._id == null) return;
|