|
@@ -13,12 +13,12 @@ import { useSetupGlobalSocket, useSetupGlobalAdminSocket } from '~/stores/websoc
|
|
|
import {
|
|
import {
|
|
|
useSiteUrl,
|
|
useSiteUrl,
|
|
|
useCurrentCreatedAt, useDeleteUsername, useDeletedAt, useHasChildren, useHasDraftOnHackmd,
|
|
useCurrentCreatedAt, useDeleteUsername, useDeletedAt, useHasChildren, useHasDraftOnHackmd,
|
|
|
- useIsDeleted, useIsNotCreatable, useIsTrashPage, useIsUserPage, useLastUpdateUsername,
|
|
|
|
|
|
|
+ useIsNotCreatable, useIsTrashPage, useIsUserPage, useLastUpdateUsername,
|
|
|
useCurrentPageId, usePageIdOnHackmd, usePageUser, useCurrentPagePath, useRevisionCreatedAt, useRevisionId, useRevisionIdHackmdSynced,
|
|
useCurrentPageId, usePageIdOnHackmd, usePageUser, useCurrentPagePath, useRevisionCreatedAt, useRevisionId, useRevisionIdHackmdSynced,
|
|
|
useShareLinkId, useShareLinksNumber, useTemplateTagData, useCurrentUpdatedAt, useCreator, useRevisionAuthor, useCurrentUser, useTargetAndAncestors,
|
|
useShareLinkId, useShareLinksNumber, useTemplateTagData, useCurrentUpdatedAt, useCreator, useRevisionAuthor, useCurrentUser, useTargetAndAncestors,
|
|
|
useNotFoundTargetPathOrId, useIsSearchPage, useIsForbidden, useIsIdenticalPath, useHasParent,
|
|
useNotFoundTargetPathOrId, useIsSearchPage, useIsForbidden, useIsIdenticalPath, useHasParent,
|
|
|
useIsAclEnabled, useIsSearchServiceConfigured, useIsSearchServiceReachable, useIsEnabledAttachTitleHeader, useIsNotFoundPermalink,
|
|
useIsAclEnabled, useIsSearchServiceConfigured, useIsSearchServiceReachable, useIsEnabledAttachTitleHeader, useIsNotFoundPermalink,
|
|
|
- useDefaultIndentSize, useIsIndentSizeForced,
|
|
|
|
|
|
|
+ useDefaultIndentSize, useIsIndentSizeForced, useCsrfToken, useIsEmptyPage, useEmptyPageId, useGrowiVersion,
|
|
|
} from '../../stores/context';
|
|
} from '../../stores/context';
|
|
|
|
|
|
|
|
const { isTrashPage: _isTrashPage } = pagePathUtils;
|
|
const { isTrashPage: _isTrashPage } = pagePathUtils;
|
|
@@ -29,9 +29,14 @@ const ContextExtractorOnce: FC = () => {
|
|
|
|
|
|
|
|
const mainContent = document.querySelector('#content-main');
|
|
const mainContent = document.querySelector('#content-main');
|
|
|
const notFoundContentForPt = document.getElementById('growi-pagetree-not-found-context');
|
|
const notFoundContentForPt = document.getElementById('growi-pagetree-not-found-context');
|
|
|
- const notFoundContent = document.getElementById('growi-not-found-context');
|
|
|
|
|
|
|
+ const notFoundContext = document.getElementById('growi-not-found-context');
|
|
|
const forbiddenContent = document.getElementById('forbidden-page');
|
|
const forbiddenContent = document.getElementById('forbidden-page');
|
|
|
|
|
|
|
|
|
|
+ // get csrf token from body element
|
|
|
|
|
+ // DO NOT REMOVE: uploading attachment data requires appContainer.csrfToken
|
|
|
|
|
+ const body = document.querySelector('body');
|
|
|
|
|
+ const csrfToken = body?.dataset.csrftoken;
|
|
|
|
|
+
|
|
|
/*
|
|
/*
|
|
|
* App Context from DOM
|
|
* App Context from DOM
|
|
|
*/
|
|
*/
|
|
@@ -52,7 +57,10 @@ const ContextExtractorOnce: FC = () => {
|
|
|
*/
|
|
*/
|
|
|
const revisionId = mainContent?.getAttribute('data-page-revision-id');
|
|
const revisionId = mainContent?.getAttribute('data-page-revision-id');
|
|
|
const path = decodeURI(mainContent?.getAttribute('data-path') || '');
|
|
const path = decodeURI(mainContent?.getAttribute('data-path') || '');
|
|
|
|
|
+ // assign `null` to avoid returning empty string
|
|
|
const pageId = mainContent?.getAttribute('data-page-id') || null;
|
|
const pageId = mainContent?.getAttribute('data-page-id') || null;
|
|
|
|
|
+ const emptyPageId = notFoundContext?.getAttribute('data-page-id') || null;
|
|
|
|
|
+
|
|
|
const revisionCreatedAt = +(mainContent?.getAttribute('data-page-revision-created') || '');
|
|
const revisionCreatedAt = +(mainContent?.getAttribute('data-page-revision-created') || '');
|
|
|
|
|
|
|
|
// createdAt
|
|
// createdAt
|
|
@@ -66,7 +74,6 @@ const ContextExtractorOnce: FC = () => {
|
|
|
const isIdenticalPath = JSON.parse(mainContent?.getAttribute('data-identical-path') || jsonNull) ?? false;
|
|
const isIdenticalPath = JSON.parse(mainContent?.getAttribute('data-identical-path') || jsonNull) ?? false;
|
|
|
const isUserPage = JSON.parse(mainContent?.getAttribute('data-page-user') || jsonNull) != null;
|
|
const isUserPage = JSON.parse(mainContent?.getAttribute('data-page-user') || jsonNull) != null;
|
|
|
const isTrashPage = _isTrashPage(path);
|
|
const isTrashPage = _isTrashPage(path);
|
|
|
- const isDeleted = JSON.parse(mainContent?.getAttribute('data-page-is-deleted') || jsonNull) ?? false;
|
|
|
|
|
const isNotCreatable = JSON.parse(mainContent?.getAttribute('data-page-is-not-creatable') || jsonNull) ?? false;
|
|
const isNotCreatable = JSON.parse(mainContent?.getAttribute('data-page-is-not-creatable') || jsonNull) ?? false;
|
|
|
const isForbidden = forbiddenContent != null;
|
|
const isForbidden = forbiddenContent != null;
|
|
|
const pageUser = JSON.parse(mainContent?.getAttribute('data-page-user') || jsonNull);
|
|
const pageUser = JSON.parse(mainContent?.getAttribute('data-page-user') || jsonNull);
|
|
@@ -84,8 +91,9 @@ const ContextExtractorOnce: FC = () => {
|
|
|
const revisionAuthor = JSON.parse(mainContent?.getAttribute('data-page-revision-author') || jsonNull);
|
|
const revisionAuthor = JSON.parse(mainContent?.getAttribute('data-page-revision-author') || jsonNull);
|
|
|
const targetAndAncestors = JSON.parse(document.getElementById('growi-pagetree-target-and-ancestors')?.textContent || jsonNull);
|
|
const targetAndAncestors = JSON.parse(document.getElementById('growi-pagetree-target-and-ancestors')?.textContent || jsonNull);
|
|
|
const notFoundTargetPathOrId = JSON.parse(notFoundContentForPt?.getAttribute('data-not-found-target-path-or-id') || jsonNull);
|
|
const notFoundTargetPathOrId = JSON.parse(notFoundContentForPt?.getAttribute('data-not-found-target-path-or-id') || jsonNull);
|
|
|
- const isNotFoundPermalink = JSON.parse(notFoundContent?.getAttribute('data-is-not-found-permalink') || jsonNull);
|
|
|
|
|
|
|
+ const isNotFoundPermalink = JSON.parse(notFoundContext?.getAttribute('data-is-not-found-permalink') || jsonNull);
|
|
|
const isSearchPage = document.getElementById('search-page') != null;
|
|
const isSearchPage = document.getElementById('search-page') != null;
|
|
|
|
|
+ const isEmptyPage = JSON.parse(mainContent?.getAttribute('data-page-is-empty') || jsonNull) ?? false;
|
|
|
|
|
|
|
|
const grant = +(mainContent?.getAttribute('data-page-grant') || 1);
|
|
const grant = +(mainContent?.getAttribute('data-page-grant') || 1);
|
|
|
const grantGroupId = mainContent?.getAttribute('data-page-grant-group') || null;
|
|
const grantGroupId = mainContent?.getAttribute('data-page-grant-group') || null;
|
|
@@ -94,13 +102,15 @@ const ContextExtractorOnce: FC = () => {
|
|
|
/*
|
|
/*
|
|
|
* use static swr
|
|
* use static swr
|
|
|
*/
|
|
*/
|
|
|
|
|
+ useCsrfToken(csrfToken);
|
|
|
|
|
+
|
|
|
// App
|
|
// App
|
|
|
useCurrentUser(currentUser);
|
|
useCurrentUser(currentUser);
|
|
|
|
|
|
|
|
// UserUISettings
|
|
// UserUISettings
|
|
|
- usePreferDrawerModeByUser(userUISettings?.preferDrawerModeByUser);
|
|
|
|
|
|
|
+ usePreferDrawerModeByUser(userUISettings?.preferDrawerModeByUser ?? configByContextHydrate.isSidebarDrawerMode);
|
|
|
usePreferDrawerModeOnEditByUser(userUISettings?.preferDrawerModeOnEditByUser);
|
|
usePreferDrawerModeOnEditByUser(userUISettings?.preferDrawerModeOnEditByUser);
|
|
|
- useSidebarCollapsed(userUISettings?.isSidebarCollapsed);
|
|
|
|
|
|
|
+ useSidebarCollapsed(userUISettings?.isSidebarCollapsed ?? configByContextHydrate.isSidebarClosedAtDockMode);
|
|
|
useCurrentSidebarContents(userUISettings?.currentSidebarContents);
|
|
useCurrentSidebarContents(userUISettings?.currentSidebarContents);
|
|
|
useCurrentProductNavWidth(userUISettings?.currentProductNavWidth);
|
|
useCurrentProductNavWidth(userUISettings?.currentProductNavWidth);
|
|
|
|
|
|
|
@@ -112,7 +122,7 @@ const ContextExtractorOnce: FC = () => {
|
|
|
useIsEnabledAttachTitleHeader(configByContextHydrate.isEnabledAttachTitleHeader);
|
|
useIsEnabledAttachTitleHeader(configByContextHydrate.isEnabledAttachTitleHeader);
|
|
|
useIsIndentSizeForced(configByContextHydrate.isIndentSizeForced);
|
|
useIsIndentSizeForced(configByContextHydrate.isIndentSizeForced);
|
|
|
useDefaultIndentSize(configByContextHydrate.adminPreferredIndentSize);
|
|
useDefaultIndentSize(configByContextHydrate.adminPreferredIndentSize);
|
|
|
-
|
|
|
|
|
|
|
+ useGrowiVersion(configByContextHydrate.crowi.version);
|
|
|
|
|
|
|
|
// Page
|
|
// Page
|
|
|
useCurrentCreatedAt(createdAt);
|
|
useCurrentCreatedAt(createdAt);
|
|
@@ -121,13 +131,13 @@ const ContextExtractorOnce: FC = () => {
|
|
|
useHasChildren(hasChildren);
|
|
useHasChildren(hasChildren);
|
|
|
useHasDraftOnHackmd(hasDraftOnHackmd);
|
|
useHasDraftOnHackmd(hasDraftOnHackmd);
|
|
|
useIsIdenticalPath(isIdenticalPath);
|
|
useIsIdenticalPath(isIdenticalPath);
|
|
|
- useIsDeleted(isDeleted);
|
|
|
|
|
useIsNotCreatable(isNotCreatable);
|
|
useIsNotCreatable(isNotCreatable);
|
|
|
useIsForbidden(isForbidden);
|
|
useIsForbidden(isForbidden);
|
|
|
useIsTrashPage(isTrashPage);
|
|
useIsTrashPage(isTrashPage);
|
|
|
useIsUserPage(isUserPage);
|
|
useIsUserPage(isUserPage);
|
|
|
useLastUpdateUsername(lastUpdateUsername);
|
|
useLastUpdateUsername(lastUpdateUsername);
|
|
|
useCurrentPageId(pageId);
|
|
useCurrentPageId(pageId);
|
|
|
|
|
+ useEmptyPageId(emptyPageId);
|
|
|
usePageIdOnHackmd(pageIdOnHackmd);
|
|
usePageIdOnHackmd(pageIdOnHackmd);
|
|
|
usePageUser(pageUser);
|
|
usePageUser(pageUser);
|
|
|
useCurrentPagePath(path);
|
|
useCurrentPagePath(path);
|
|
@@ -144,6 +154,7 @@ const ContextExtractorOnce: FC = () => {
|
|
|
useNotFoundTargetPathOrId(notFoundTargetPathOrId);
|
|
useNotFoundTargetPathOrId(notFoundTargetPathOrId);
|
|
|
useIsNotFoundPermalink(isNotFoundPermalink);
|
|
useIsNotFoundPermalink(isNotFoundPermalink);
|
|
|
useIsSearchPage(isSearchPage);
|
|
useIsSearchPage(isSearchPage);
|
|
|
|
|
+ useIsEmptyPage(isEmptyPage);
|
|
|
useHasParent(hasParent);
|
|
useHasParent(hasParent);
|
|
|
|
|
|
|
|
// Navigation
|
|
// Navigation
|
|
@@ -166,7 +177,8 @@ const ContextExtractorOnce: FC = () => {
|
|
|
|
|
|
|
|
// Global Socket
|
|
// Global Socket
|
|
|
useSetupGlobalSocket();
|
|
useSetupGlobalSocket();
|
|
|
- useSetupGlobalAdminSocket();
|
|
|
|
|
|
|
+ const shouldInitAdminSock = !!currentUser?.isAdmin;
|
|
|
|
|
+ useSetupGlobalAdminSocket(shouldInitAdminSock);
|
|
|
|
|
|
|
|
return null;
|
|
return null;
|
|
|
};
|
|
};
|