| 1 |
(function(_elementor_icons, _elementor_editor_app_bar, _elementor_editor_panels, react, _wordpress_i18n, _elementor_ui, _wordpress_api_fetch, _elementor_query, _elementor_editor_documents, _elementor_editor_v1_adapters, _elementor_events, _elementor_env) { |
| 2 |
|
| 3 |
//#region \0rolldown/runtime.js |
| 4 |
var __create = Object.create; |
| 5 |
var __defProp = Object.defineProperty; |
| 6 |
var __name = (target, value) => __defProp(target, "name", { |
| 7 |
value, |
| 8 |
configurable: true |
| 9 |
}); |
| 10 |
var __getOwnPropDesc = Object.getOwnPropertyDescriptor; |
| 11 |
var __getOwnPropNames = Object.getOwnPropertyNames; |
| 12 |
var __getProtoOf = Object.getPrototypeOf; |
| 13 |
var __hasOwnProp = Object.prototype.hasOwnProperty; |
| 14 |
var __exportAll = (all, no_symbols) => { |
| 15 |
let target = {}; |
| 16 |
for (var name in all) { |
| 17 |
__defProp(target, name, { |
| 18 |
get: all[name], |
| 19 |
enumerable: true |
| 20 |
}); |
| 21 |
} |
| 22 |
if (!no_symbols) { |
| 23 |
__defProp(target, Symbol.toStringTag, { value: "Module" }); |
| 24 |
} |
| 25 |
return target; |
| 26 |
}; |
| 27 |
var __copyProps = (to, from, except, desc) => { |
| 28 |
if (from && typeof from === "object" || typeof from === "function") { |
| 29 |
for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { |
| 30 |
key = keys[i]; |
| 31 |
if (!__hasOwnProp.call(to, key) && key !== except) { |
| 32 |
__defProp(to, key, { |
| 33 |
get: ((k) => from[k]).bind(null, key), |
| 34 |
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable |
| 35 |
}); |
| 36 |
} |
| 37 |
} |
| 38 |
} |
| 39 |
return to; |
| 40 |
}; |
| 41 |
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { |
| 42 |
value: mod, |
| 43 |
enumerable: true |
| 44 |
}) : target, mod)); |
| 45 |
|
| 46 |
//#endregion |
| 47 |
react = __toESM(react); |
| 48 |
_wordpress_api_fetch = __toESM(_wordpress_api_fetch); |
| 49 |
|
| 50 |
//#region packages/packages/core/editor-site-navigation/src/icons-map.ts |
| 51 |
var initialIconsMap = { |
| 52 |
page: _elementor_icons.PageTemplateIcon, |
| 53 |
section: _elementor_icons.SectionTemplateIcon, |
| 54 |
container: _elementor_icons.ContainerTemplateIcon, |
| 55 |
"wp-page": _elementor_icons.PageTypeIcon, |
| 56 |
"wp-post": _elementor_icons.PostTypeIcon |
| 57 |
}; |
| 58 |
var iconsMap$1 = { ...initialIconsMap }; |
| 59 |
function extendIconsMap(additionalIcons) { |
| 60 |
Object.assign(iconsMap$1, additionalIcons); |
| 61 |
} |
| 62 |
function getIconsMap() { |
| 63 |
return iconsMap$1; |
| 64 |
} |
| 65 |
|
| 66 |
//#endregion |
| 67 |
//#region packages/packages/core/editor-site-navigation/src/contexts/post-list-context.tsx |
| 68 |
var defaultValues = { |
| 69 |
type: "page", |
| 70 |
editMode: { |
| 71 |
mode: "none", |
| 72 |
details: {} |
| 73 |
}, |
| 74 |
setEditMode: () => null, |
| 75 |
resetEditMode: () => null, |
| 76 |
setError: () => null |
| 77 |
}; |
| 78 |
var PostListContext = (0, react.createContext)(defaultValues); |
| 79 |
var PostListContextProvider = ({ type, setError, children }) => { |
| 80 |
const [editMode, setEditMode] = (0, react.useState)(defaultValues.editMode); |
| 81 |
const resetEditMode = () => { |
| 82 |
setEditMode(defaultValues.editMode); |
| 83 |
}; |
| 84 |
return /* @__PURE__ */ react.createElement(PostListContext.Provider, { value: { |
| 85 |
type, |
| 86 |
editMode, |
| 87 |
setEditMode, |
| 88 |
resetEditMode, |
| 89 |
setError |
| 90 |
} }, children); |
| 91 |
}; |
| 92 |
function usePostListContext() { |
| 93 |
const context = (0, react.useContext)(PostListContext); |
| 94 |
if (!context) throw new Error("The `usePostListContext()` hook must be used within an `<PostListContextProvider />`"); |
| 95 |
return context; |
| 96 |
} |
| 97 |
|
| 98 |
//#endregion |
| 99 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/error-snackbar.tsx |
| 100 |
var ErrorSnackbar = ({ open, onClose }) => { |
| 101 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Snackbar, { |
| 102 |
open, |
| 103 |
onClose, |
| 104 |
anchorOrigin: { |
| 105 |
vertical: "bottom", |
| 106 |
horizontal: "left" |
| 107 |
} |
| 108 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.Alert, { |
| 109 |
onClose, |
| 110 |
severity: "error", |
| 111 |
sx: { width: "100%" } |
| 112 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 113 |
component: "span", |
| 114 |
sx: { fontWeight: "bold" } |
| 115 |
}, "We couldn’t complete the action."), " ", "Please try again")); |
| 116 |
}; |
| 117 |
|
| 118 |
//#endregion |
| 119 |
//#region packages/packages/core/editor-site-navigation/src/api/post.ts |
| 120 |
var postTypesMap = { page: { |
| 121 |
labels: { |
| 122 |
singular_name: (0, _wordpress_i18n.__)("Page", "elementor"), |
| 123 |
plural_name: (0, _wordpress_i18n.__)("Pages", "elementor") |
| 124 |
}, |
| 125 |
rest_base: "pages" |
| 126 |
} }; |
| 127 |
var POST_PER_PAGE = 10; |
| 128 |
var getRequest$1 = /* @__PURE__ */ __name(async (postTypeSlug, page) => { |
| 129 |
const baseUri = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`; |
| 130 |
const queryParams = new URLSearchParams({ |
| 131 |
status: "any", |
| 132 |
order: "asc", |
| 133 |
page: page.toString(), |
| 134 |
per_page: 10 .toString(), |
| 135 |
_fields: [ |
| 136 |
"id", |
| 137 |
"type", |
| 138 |
"title", |
| 139 |
"link", |
| 140 |
"status", |
| 141 |
"user_can" |
| 142 |
].join(",") |
| 143 |
}); |
| 144 |
const result = await (0, _wordpress_api_fetch.default)({ |
| 145 |
path: baseUri + "?" + queryParams.toString(), |
| 146 |
parse: false |
| 147 |
}); |
| 148 |
return { |
| 149 |
data: await result.json(), |
| 150 |
totalPages: Number(result.headers.get("x-wp-totalpages")), |
| 151 |
totalPosts: Number(result.headers.get("x-wp-total")), |
| 152 |
currentPage: page |
| 153 |
}; |
| 154 |
}, "getRequest"); |
| 155 |
var createRequest = (postTypeSlug, newPost) => { |
| 156 |
return (0, _wordpress_api_fetch.default)({ |
| 157 |
path: `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`, |
| 158 |
method: "POST", |
| 159 |
data: newPost |
| 160 |
}); |
| 161 |
}; |
| 162 |
var updateRequest = (postTypeSlug, updatedPost) => { |
| 163 |
const path = `/wp/v2/${postTypesMap[postTypeSlug].rest_base}`; |
| 164 |
const { id, ...data } = updatedPost; |
| 165 |
return (0, _wordpress_api_fetch.default)({ |
| 166 |
path: `${path}/${id}`, |
| 167 |
method: "POST", |
| 168 |
data |
| 169 |
}); |
| 170 |
}; |
| 171 |
var deleteRequest = (postTypeSlug, postId) => { |
| 172 |
return (0, _wordpress_api_fetch.default)({ |
| 173 |
path: `${`/wp/v2/${postTypesMap[postTypeSlug].rest_base}`}/${postId}`, |
| 174 |
method: "DELETE" |
| 175 |
}); |
| 176 |
}; |
| 177 |
var duplicateRequest = (originalPost) => { |
| 178 |
return (0, _wordpress_api_fetch.default)({ |
| 179 |
path: `/elementor/v1/site-navigation/duplicate-post`, |
| 180 |
method: "POST", |
| 181 |
data: { |
| 182 |
post_id: originalPost.id, |
| 183 |
title: originalPost.title |
| 184 |
} |
| 185 |
}); |
| 186 |
}; |
| 187 |
|
| 188 |
//#endregion |
| 189 |
//#region packages/packages/core/editor-site-navigation/src/api/settings.ts |
| 190 |
var getSettings = () => { |
| 191 |
return (0, _wordpress_api_fetch.default)({ path: "/elementor/v1/site-navigation/homepage" }); |
| 192 |
}; |
| 193 |
var updateSettings = (settings) => { |
| 194 |
return (0, _wordpress_api_fetch.default)({ |
| 195 |
path: "/wp/v2/settings", |
| 196 |
method: "POST", |
| 197 |
data: settings |
| 198 |
}); |
| 199 |
}; |
| 200 |
|
| 201 |
//#endregion |
| 202 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-homepage.ts |
| 203 |
var settingsQueryKey = () => ["site-navigation", "homepage"]; |
| 204 |
function useHomepage() { |
| 205 |
return (0, _elementor_query.useQuery)({ |
| 206 |
queryKey: settingsQueryKey(), |
| 207 |
queryFn: () => getSettings() |
| 208 |
}); |
| 209 |
} |
| 210 |
|
| 211 |
//#endregion |
| 212 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-posts.ts |
| 213 |
var postsQueryKey = (postTypeSlug) => [ |
| 214 |
"site-navigation", |
| 215 |
"posts", |
| 216 |
postTypeSlug |
| 217 |
]; |
| 218 |
var flattenData = (data) => { |
| 219 |
if (!data) return data; |
| 220 |
const flattened = []; |
| 221 |
data.pages.forEach((page) => { |
| 222 |
flattened.push(...page.data); |
| 223 |
}); |
| 224 |
return flattened; |
| 225 |
}; |
| 226 |
function usePosts(postTypeSlug) { |
| 227 |
const query = (0, _elementor_query.useInfiniteQuery)({ |
| 228 |
queryKey: postsQueryKey(postTypeSlug), |
| 229 |
queryFn: ({ pageParam = 1 }) => getRequest$1(postTypeSlug, pageParam), |
| 230 |
initialPageParam: 1, |
| 231 |
getNextPageParam: (lastPage) => { |
| 232 |
return lastPage.currentPage < lastPage.totalPages ? lastPage.currentPage + 1 : void 0; |
| 233 |
} |
| 234 |
}); |
| 235 |
return { |
| 236 |
...query, |
| 237 |
data: { |
| 238 |
posts: flattenData(query.data), |
| 239 |
total: query.data?.pages[0]?.totalPosts ?? 0 |
| 240 |
} |
| 241 |
}; |
| 242 |
} |
| 243 |
|
| 244 |
//#endregion |
| 245 |
//#region packages/packages/core/editor-site-navigation/src/api/user.ts |
| 246 |
var getUser = () => { |
| 247 |
return (0, _wordpress_api_fetch.default)({ path: "/wp/v2/users/me?" + new URLSearchParams({ |
| 248 |
_fields: ["capabilities"].join(","), |
| 249 |
context: "edit" |
| 250 |
}).toString() }); |
| 251 |
}; |
| 252 |
|
| 253 |
//#endregion |
| 254 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-user.ts |
| 255 |
var userQueryKey = () => ["site-navigation", "user"]; |
| 256 |
function useUser() { |
| 257 |
return (0, _elementor_query.useQuery)({ |
| 258 |
queryKey: userQueryKey(), |
| 259 |
queryFn: getUser, |
| 260 |
staleTime: 1800 * 1e3 |
| 261 |
}); |
| 262 |
} |
| 263 |
|
| 264 |
//#endregion |
| 265 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/add-new-button.tsx |
| 266 |
function AddNewButton() { |
| 267 |
const { setEditMode } = usePostListContext(); |
| 268 |
const { data: user } = useUser(); |
| 269 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Button, { |
| 270 |
size: "small", |
| 271 |
startIcon: /* @__PURE__ */ react.createElement(_elementor_icons.PlusIcon, null), |
| 272 |
disabled: !user?.capabilities?.edit_pages, |
| 273 |
onClick: () => { |
| 274 |
setEditMode({ |
| 275 |
mode: "create", |
| 276 |
details: {} |
| 277 |
}); |
| 278 |
}, |
| 279 |
sx: { px: 1.5 } |
| 280 |
}, (0, _wordpress_i18n.__)("Add New", "elementor")); |
| 281 |
} |
| 282 |
|
| 283 |
//#endregion |
| 284 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/collapsible-list.tsx |
| 285 |
var RotateIcon = (0, _elementor_ui.styled)(_elementor_icons.ChevronDownIcon, { shouldForwardProp: (prop) => prop !== "isOpen" })(({ theme, isOpen }) => ({ |
| 286 |
transform: isOpen ? "rotate(0deg)" : "rotate(-90deg)", |
| 287 |
transition: theme.transitions.create("transform", { duration: theme.transitions.duration.standard }) |
| 288 |
})); |
| 289 |
var StyledListItemIcon = (0, _elementor_ui.styled)(_elementor_ui.ListItemIcon)(({ theme }) => ({ minWidth: theme.spacing(4) })); |
| 290 |
function CollapsibleList({ label, Icon, isOpenByDefault = false, children }) { |
| 291 |
const [isOpen, setIsOpen] = (0, react.useState)(isOpenByDefault); |
| 292 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, /* @__PURE__ */ react.createElement(_elementor_ui.ListItem, null, /* @__PURE__ */ react.createElement(StyledListItemIcon, { sx: { color: "text.secondary" } }, /* @__PURE__ */ react.createElement(_elementor_ui.IconButton, { |
| 293 |
onClick: () => setIsOpen((prev) => !prev), |
| 294 |
size: "small", |
| 295 |
sx: { color: "inherit" } |
| 296 |
}, /* @__PURE__ */ react.createElement(RotateIcon, { |
| 297 |
fontSize: "small", |
| 298 |
isOpen |
| 299 |
}))), /* @__PURE__ */ react.createElement(StyledListItemIcon, { |
| 300 |
size: "small", |
| 301 |
sx: { color: "inherit" } |
| 302 |
}, /* @__PURE__ */ react.createElement(Icon, { fontSize: "small" })), /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { |
| 303 |
primaryTypographyProps: { |
| 304 |
variant: "subtitle2", |
| 305 |
component: "span" |
| 306 |
}, |
| 307 |
primary: label |
| 308 |
})), /* @__PURE__ */ react.createElement(_elementor_ui.Collapse, { |
| 309 |
in: isOpen, |
| 310 |
timeout: "auto", |
| 311 |
unmountOnExit: true |
| 312 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.List, { dense: true }, children)), /* @__PURE__ */ react.createElement(_elementor_ui.Divider, { sx: { mt: 1 } })); |
| 313 |
} |
| 314 |
|
| 315 |
//#endregion |
| 316 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/error-state.tsx |
| 317 |
function ErrorState() { |
| 318 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Box, { sx: { |
| 319 |
display: "flex", |
| 320 |
flexDirection: "column", |
| 321 |
justifyContent: "center", |
| 322 |
alignItems: "center", |
| 323 |
pt: "40px", |
| 324 |
gap: "16px" |
| 325 |
} }, /* @__PURE__ */ react.createElement(_elementor_icons.Error404TemplateIcon, null), /* @__PURE__ */ react.createElement(_elementor_ui.Box, { sx: { |
| 326 |
display: "flex", |
| 327 |
flexDirection: "column", |
| 328 |
justifyContent: "center", |
| 329 |
alignItems: "center", |
| 330 |
gap: "8px" |
| 331 |
} }, /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 332 |
variant: "body1", |
| 333 |
color: "text.primary" |
| 334 |
}, (0, _wordpress_i18n.__)("We couldn’t display your pages.", "elementor")), /* @__PURE__ */ react.createElement(_elementor_ui.Box, null, /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 335 |
variant: "body2", |
| 336 |
color: "text.primary", |
| 337 |
sx: { textAlign: "center" } |
| 338 |
}, (0, _wordpress_i18n.__)("It’s probably a temporary issue.", "elementor")), /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 339 |
variant: "body2", |
| 340 |
color: "text.primary", |
| 341 |
sx: { textAlign: "center" } |
| 342 |
}, (0, _wordpress_i18n.__)("If the problem persists,", "elementor"), " ", /* @__PURE__ */ react.createElement(_elementor_ui.Link, { |
| 343 |
target: "_blank", |
| 344 |
href: "https://go.elementor.com/wp-editor-support-open-ticket/" |
| 345 |
}, "Notify support"))))); |
| 346 |
} |
| 347 |
|
| 348 |
//#endregion |
| 349 |
//#region packages/packages/core/editor-site-navigation/src/api/recent-posts.ts |
| 350 |
var baseUrl = "/elementor/v1/site-navigation/recent-posts"; |
| 351 |
var NUMBER_OF_RECENT_POSTS = 6; |
| 352 |
var getRequest = () => { |
| 353 |
const queryParams = new URLSearchParams({ posts_per_page: `${6}` }); |
| 354 |
return (0, _wordpress_api_fetch.default)({ path: `${baseUrl}?${queryParams.toString()}` }); |
| 355 |
}; |
| 356 |
|
| 357 |
//#endregion |
| 358 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-recent-posts.ts |
| 359 |
var recentPostsQueryKey = ["site-navigation", "recent-posts"]; |
| 360 |
function useRecentPosts() { |
| 361 |
return (0, _elementor_query.useQuery)({ |
| 362 |
queryKey: recentPostsQueryKey, |
| 363 |
queryFn: () => getRequest() |
| 364 |
}); |
| 365 |
} |
| 366 |
|
| 367 |
//#endregion |
| 368 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-posts-actions.ts |
| 369 |
function usePostActions(postTypeSlug) { |
| 370 |
const invalidatePosts = useInvalidatePosts(postTypeSlug); |
| 371 |
const onSuccess = () => invalidatePosts({ exact: true }); |
| 372 |
return { |
| 373 |
createPost: (0, _elementor_query.useMutation)({ |
| 374 |
mutationFn: (newPost) => createRequest(postTypeSlug, newPost), |
| 375 |
onSuccess |
| 376 |
}), |
| 377 |
updatePost: (0, _elementor_query.useMutation)({ |
| 378 |
mutationFn: (updatedPost) => updateRequest(postTypeSlug, updatedPost), |
| 379 |
onSuccess |
| 380 |
}), |
| 381 |
deletePost: (0, _elementor_query.useMutation)({ |
| 382 |
mutationFn: (postId) => deleteRequest(postTypeSlug, postId), |
| 383 |
onSuccess |
| 384 |
}), |
| 385 |
duplicatePost: (0, _elementor_query.useMutation)({ |
| 386 |
mutationFn: (originalPost) => duplicateRequest(originalPost), |
| 387 |
onSuccess |
| 388 |
}) |
| 389 |
}; |
| 390 |
} |
| 391 |
function useInvalidatePosts(postTypeSlug) { |
| 392 |
const queryClient = (0, _elementor_query.useQueryClient)(); |
| 393 |
return (options = {}) => { |
| 394 |
const queryKey = postsQueryKey(postTypeSlug); |
| 395 |
queryClient.invalidateQueries({ queryKey: recentPostsQueryKey }, options); |
| 396 |
return queryClient.invalidateQueries({ queryKey }, options); |
| 397 |
}; |
| 398 |
} |
| 399 |
|
| 400 |
//#endregion |
| 401 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/list-items/edit-mode-template.tsx |
| 402 |
function EditModeTemplate({ postTitle, isLoading, callback }) { |
| 403 |
const [title, setTitle] = (0, react.useState)(postTitle); |
| 404 |
const [touched, setTouched] = (0, react.useState)(false); |
| 405 |
const [inputError, setInputError] = (0, react.useState)(null); |
| 406 |
const closeButton = (0, react.useRef)(); |
| 407 |
const onBlur = (e) => { |
| 408 |
if (closeButton.current === e.relatedTarget) return; |
| 409 |
runCallback(); |
| 410 |
}; |
| 411 |
const onFormSubmit = (e) => { |
| 412 |
e.preventDefault(); |
| 413 |
runCallback(); |
| 414 |
}; |
| 415 |
const validateInput = (input) => { |
| 416 |
return input.trim() !== ""; |
| 417 |
}; |
| 418 |
const runCallback = () => { |
| 419 |
if (!validateInput(title)) return; |
| 420 |
callback(title); |
| 421 |
}; |
| 422 |
const onChange = (e) => { |
| 423 |
if (!touched) setTouched(true); |
| 424 |
const value = e.target.value; |
| 425 |
if (!validateInput(value)) setInputError((0, _wordpress_i18n.__)("Name is required", "elementor")); |
| 426 |
else setInputError(null); |
| 427 |
setTitle(value); |
| 428 |
}; |
| 429 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, /* @__PURE__ */ react.createElement(_elementor_ui.ListItem, { secondaryAction: /* @__PURE__ */ react.createElement(CloseButton, { |
| 430 |
isLoading, |
| 431 |
closeButton |
| 432 |
}) }, /* @__PURE__ */ react.createElement(_elementor_ui.Box, { |
| 433 |
width: "100%", |
| 434 |
component: "form", |
| 435 |
onSubmit: onFormSubmit |
| 436 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.TextField, { |
| 437 |
autoFocus: true, |
| 438 |
fullWidth: true, |
| 439 |
value: title, |
| 440 |
onChange, |
| 441 |
disabled: isLoading, |
| 442 |
error: !!inputError, |
| 443 |
onBlur, |
| 444 |
variant: "outlined", |
| 445 |
color: "secondary", |
| 446 |
size: "small" |
| 447 |
}))), inputError && /* @__PURE__ */ react.createElement(_elementor_ui.ListItem, null, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { sx: { color: "error.main" } }, inputError))); |
| 448 |
} |
| 449 |
function CloseButton({ isLoading, closeButton }) { |
| 450 |
const { resetEditMode } = usePostListContext(); |
| 451 |
return /* @__PURE__ */ react.createElement(_elementor_ui.IconButton, { |
| 452 |
size: "small", |
| 453 |
color: "secondary", |
| 454 |
onClick: resetEditMode, |
| 455 |
ref: closeButton, |
| 456 |
disabled: isLoading |
| 457 |
}, isLoading ? /* @__PURE__ */ react.createElement(_elementor_ui.CircularProgress, null) : /* @__PURE__ */ react.createElement(_elementor_icons.XIcon, { fontSize: "small" })); |
| 458 |
} |
| 459 |
|
| 460 |
//#endregion |
| 461 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/list-items/list-item-create.tsx |
| 462 |
function ListItemCreate() { |
| 463 |
const { type, resetEditMode } = usePostListContext(); |
| 464 |
const { createPost } = usePostActions(type); |
| 465 |
const navigateToDocument = (0, _elementor_editor_documents.__useNavigateToDocument)(); |
| 466 |
const { setError } = usePostListContext(); |
| 467 |
const createPostCallback = async (inputValue) => { |
| 468 |
try { |
| 469 |
const { id } = await createPost.mutateAsync({ |
| 470 |
title: inputValue, |
| 471 |
status: "draft" |
| 472 |
}); |
| 473 |
navigateToDocument(id); |
| 474 |
} catch { |
| 475 |
setError(); |
| 476 |
} finally { |
| 477 |
resetEditMode(); |
| 478 |
} |
| 479 |
}; |
| 480 |
return /* @__PURE__ */ react.createElement(EditModeTemplate, { |
| 481 |
postTitle: (0, _wordpress_i18n.__)("New Page", "elementor"), |
| 482 |
isLoading: createPost.isPending, |
| 483 |
callback: createPostCallback |
| 484 |
}); |
| 485 |
} |
| 486 |
|
| 487 |
//#endregion |
| 488 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/list-items/list-item-duplicate.tsx |
| 489 |
function ListItemDuplicate() { |
| 490 |
const { type, editMode, resetEditMode } = usePostListContext(); |
| 491 |
const navigateToDocument = (0, _elementor_editor_documents.__useNavigateToDocument)(); |
| 492 |
const { duplicatePost } = usePostActions(type); |
| 493 |
const { setError } = usePostListContext(); |
| 494 |
if ("duplicate" !== editMode.mode) return null; |
| 495 |
const duplicatePostCallback = async (inputValue) => { |
| 496 |
try { |
| 497 |
const { post_id: postId } = await duplicatePost.mutateAsync({ |
| 498 |
id: editMode.details.postId, |
| 499 |
title: inputValue |
| 500 |
}); |
| 501 |
navigateToDocument(postId); |
| 502 |
} catch { |
| 503 |
setError(); |
| 504 |
} finally { |
| 505 |
resetEditMode(); |
| 506 |
} |
| 507 |
}; |
| 508 |
return /* @__PURE__ */ react.createElement(EditModeTemplate, { |
| 509 |
postTitle: `${editMode.details.title} ${(0, _wordpress_i18n.__)("copy", "elementor")}`, |
| 510 |
isLoading: duplicatePost.isPending, |
| 511 |
callback: duplicatePostCallback |
| 512 |
}); |
| 513 |
} |
| 514 |
|
| 515 |
//#endregion |
| 516 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-rename-active-document.ts |
| 517 |
function getV1DocumentsManager() { |
| 518 |
const documentsManager = window.elementor?.documents; |
| 519 |
if (!documentsManager) throw new Error("Elementor Editor V1 documents manager not found"); |
| 520 |
return documentsManager; |
| 521 |
} |
| 522 |
function useRenameActiveDocument() { |
| 523 |
return async (title) => { |
| 524 |
const container = getV1DocumentsManager().getCurrent().container; |
| 525 |
await (0, _elementor_editor_v1_adapters.__privateRunCommand)("document/elements/settings", { |
| 526 |
container, |
| 527 |
settings: { post_title: title } |
| 528 |
}); |
| 529 |
}; |
| 530 |
} |
| 531 |
|
| 532 |
//#endregion |
| 533 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/list-items/list-item-rename.tsx |
| 534 |
function ListItemRename({ post }) { |
| 535 |
const { type, resetEditMode } = usePostListContext(); |
| 536 |
const { updatePost } = usePostActions(type); |
| 537 |
const { setError } = usePostListContext(); |
| 538 |
const activeDocument = (0, _elementor_editor_documents.__useActiveDocument)(); |
| 539 |
const rename = useRenameActiveDocument(); |
| 540 |
const isActive = activeDocument?.id === post.id; |
| 541 |
const title = isActive ? activeDocument?.title : post.title.rendered; |
| 542 |
const renamePostCallback = async (inputValue) => { |
| 543 |
if (inputValue === title) resetEditMode(); |
| 544 |
try { |
| 545 |
if (isActive) await rename(inputValue); |
| 546 |
else await updatePost.mutateAsync({ |
| 547 |
id: post.id, |
| 548 |
title: inputValue |
| 549 |
}); |
| 550 |
} catch { |
| 551 |
setError(); |
| 552 |
} finally { |
| 553 |
resetEditMode(); |
| 554 |
} |
| 555 |
}; |
| 556 |
return /* @__PURE__ */ react.createElement(EditModeTemplate, { |
| 557 |
postTitle: title, |
| 558 |
isLoading: updatePost.isPending, |
| 559 |
callback: renamePostCallback |
| 560 |
}); |
| 561 |
} |
| 562 |
|
| 563 |
//#endregion |
| 564 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-reverse-html-entities.ts |
| 565 |
function useReverseHtmlEntities(escapedHTML = "") { |
| 566 |
return (0, react.useMemo)(() => { |
| 567 |
const textarea = document.createElement("textarea"); |
| 568 |
textarea.innerHTML = escapedHTML; |
| 569 |
const { value } = textarea; |
| 570 |
textarea.remove(); |
| 571 |
return value; |
| 572 |
}, [escapedHTML]); |
| 573 |
} |
| 574 |
|
| 575 |
//#endregion |
| 576 |
//#region packages/packages/core/editor-site-navigation/src/components/shared/page-title-and-status.tsx |
| 577 |
var PageStatus = ({ status }) => { |
| 578 |
if ("publish" === status) return null; |
| 579 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 580 |
component: "span", |
| 581 |
variant: "body2", |
| 582 |
color: "text.secondary", |
| 583 |
sx: { |
| 584 |
textTransform: "capitalize", |
| 585 |
fontStyle: "italic", |
| 586 |
whiteSpace: "nowrap", |
| 587 |
flexBasis: "content" |
| 588 |
} |
| 589 |
}, "(", status, ")"); |
| 590 |
}; |
| 591 |
var PageTitle = ({ title }) => { |
| 592 |
const modifiedTitle = useReverseHtmlEntities(title); |
| 593 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 594 |
component: "span", |
| 595 |
variant: "body2", |
| 596 |
color: "text.secondary", |
| 597 |
noWrap: true, |
| 598 |
sx: { flexBasis: "auto" } |
| 599 |
}, modifiedTitle); |
| 600 |
}; |
| 601 |
function PageTitleAndStatus({ title, status }) { |
| 602 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Box, { display: "flex" }, /* @__PURE__ */ react.createElement(PageTitle, { title }), "\xA0", /* @__PURE__ */ react.createElement(PageStatus, { status })); |
| 603 |
} |
| 604 |
|
| 605 |
//#endregion |
| 606 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/actions-menu/action-menu-item.tsx |
| 607 |
function ActionMenuItem({ title, icon: Icon, MenuItemProps }) { |
| 608 |
return /* @__PURE__ */ react.createElement(_elementor_ui.MenuItem, { ...MenuItemProps }, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemIcon, { sx: { color: "inherit" } }, /* @__PURE__ */ react.createElement(Icon, null)), /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { primary: title })); |
| 609 |
} |
| 610 |
|
| 611 |
//#endregion |
| 612 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/actions-menu/actions/delete.tsx |
| 613 |
function Delete({ post }) { |
| 614 |
const [isDialogOpen, setIsDialogOpen] = (0, react.useState)(false); |
| 615 |
const isPostActive = (0, _elementor_editor_documents.__useActiveDocument)()?.id === post.id; |
| 616 |
const isDisabled = !post.user_can.delete || post.isHome || isPostActive; |
| 617 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, /* @__PURE__ */ react.createElement(ActionMenuItem, { |
| 618 |
title: (0, _wordpress_i18n.__)("Delete", "elementor"), |
| 619 |
icon: _elementor_icons.TrashIcon, |
| 620 |
MenuItemProps: { |
| 621 |
disabled: isDisabled, |
| 622 |
onClick: () => setIsDialogOpen(true), |
| 623 |
sx: { "&:hover": { color: "error.main" } } |
| 624 |
} |
| 625 |
}), isDialogOpen && /* @__PURE__ */ react.createElement(DeleteDialog, { |
| 626 |
post, |
| 627 |
setIsDialogOpen |
| 628 |
})); |
| 629 |
} |
| 630 |
function DeleteDialog({ post, setIsDialogOpen }) { |
| 631 |
const { type } = usePostListContext(); |
| 632 |
const { deletePost } = usePostActions(type); |
| 633 |
const { setError } = usePostListContext(); |
| 634 |
const dialogTitle = (0, _wordpress_i18n.sprintf)((0, _wordpress_i18n.__)("Delete \"%s\"?", "elementor"), post.title.rendered); |
| 635 |
const deletePage = async () => { |
| 636 |
try { |
| 637 |
await deletePost.mutateAsync(post.id); |
| 638 |
} catch { |
| 639 |
setError(); |
| 640 |
setIsDialogOpen(false); |
| 641 |
} |
| 642 |
}; |
| 643 |
const handleCancel = () => { |
| 644 |
if (deletePost.isPending) return; |
| 645 |
setIsDialogOpen(false); |
| 646 |
}; |
| 647 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Dialog, { |
| 648 |
open: true, |
| 649 |
onClose: handleCancel, |
| 650 |
"aria-labelledby": "delete-dialog" |
| 651 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.DialogTitle, { noWrap: true }, dialogTitle), /* @__PURE__ */ react.createElement(_elementor_ui.Divider, null), /* @__PURE__ */ react.createElement(_elementor_ui.DialogContent, null, /* @__PURE__ */ react.createElement(_elementor_ui.DialogContentText, null, (0, _wordpress_i18n.__)("The page and its content will be deleted forever and we won’t be able to recover them.", "elementor"))), /* @__PURE__ */ react.createElement(_elementor_ui.DialogActions, null, /* @__PURE__ */ react.createElement(_elementor_ui.Button, { |
| 652 |
variant: "contained", |
| 653 |
color: "secondary", |
| 654 |
onClick: handleCancel, |
| 655 |
disabled: deletePost.isPending |
| 656 |
}, (0, _wordpress_i18n.__)("Cancel", "elementor")), /* @__PURE__ */ react.createElement(_elementor_ui.Button, { |
| 657 |
variant: "contained", |
| 658 |
color: "error", |
| 659 |
onClick: deletePage, |
| 660 |
disabled: deletePost.isPending |
| 661 |
}, !deletePost.isPending ? (0, _wordpress_i18n.__)("Delete", "elementor") : /* @__PURE__ */ react.createElement(_elementor_ui.CircularProgress, null)))); |
| 662 |
} |
| 663 |
|
| 664 |
//#endregion |
| 665 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/actions-menu/actions/duplicate.tsx |
| 666 |
function Duplicate({ post, popupState }) { |
| 667 |
const { setEditMode } = usePostListContext(); |
| 668 |
const { data: user } = useUser(); |
| 669 |
const onClick = () => { |
| 670 |
popupState.close(); |
| 671 |
setEditMode({ |
| 672 |
mode: "duplicate", |
| 673 |
details: { |
| 674 |
postId: post.id, |
| 675 |
title: post.title.rendered |
| 676 |
} |
| 677 |
}); |
| 678 |
}; |
| 679 |
const isDisabled = !user?.capabilities?.edit_pages; |
| 680 |
return /* @__PURE__ */ react.createElement(ActionMenuItem, { |
| 681 |
title: (0, _wordpress_i18n.__)("Duplicate", "elementor"), |
| 682 |
icon: _elementor_icons.CopyIcon, |
| 683 |
MenuItemProps: { |
| 684 |
disabled: isDisabled, |
| 685 |
onClick |
| 686 |
} |
| 687 |
}); |
| 688 |
} |
| 689 |
|
| 690 |
//#endregion |
| 691 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/actions-menu/actions/rename.tsx |
| 692 |
function Rename({ post }) { |
| 693 |
const { setEditMode } = usePostListContext(); |
| 694 |
return /* @__PURE__ */ react.createElement(ActionMenuItem, { |
| 695 |
title: (0, _wordpress_i18n.__)("Rename", "elementor"), |
| 696 |
icon: _elementor_icons.EraseIcon, |
| 697 |
MenuItemProps: { |
| 698 |
disabled: !post.user_can.edit, |
| 699 |
onClick: () => { |
| 700 |
setEditMode({ |
| 701 |
mode: "rename", |
| 702 |
details: { postId: post.id } |
| 703 |
}); |
| 704 |
} |
| 705 |
} |
| 706 |
}); |
| 707 |
} |
| 708 |
|
| 709 |
//#endregion |
| 710 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-homepage-actions.ts |
| 711 |
function useHomepageActions() { |
| 712 |
const invalidateSettings = useInvalidateSettings(); |
| 713 |
const onSuccess = async () => invalidateSettings({ exact: true }); |
| 714 |
return { updateSettingsMutation: (0, _elementor_query.useMutation)({ |
| 715 |
mutationFn: (settings) => updateSettings(settings), |
| 716 |
onSuccess |
| 717 |
}) }; |
| 718 |
} |
| 719 |
function useInvalidateSettings() { |
| 720 |
const queryClient = (0, _elementor_query.useQueryClient)(); |
| 721 |
return (options = {}) => { |
| 722 |
const queryKey = settingsQueryKey(); |
| 723 |
return queryClient.invalidateQueries({ queryKey }, options); |
| 724 |
}; |
| 725 |
} |
| 726 |
|
| 727 |
//#endregion |
| 728 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/actions-menu/actions/set-home.tsx |
| 729 |
function SetHome({ post, closeMenu }) { |
| 730 |
const { updateSettingsMutation } = useHomepageActions(); |
| 731 |
const { setError } = usePostListContext(); |
| 732 |
const { data: user } = useUser(); |
| 733 |
const handleClick = async () => { |
| 734 |
try { |
| 735 |
await updateSettingsMutation.mutateAsync({ |
| 736 |
show_on_front: "page", |
| 737 |
page_on_front: post.id |
| 738 |
}); |
| 739 |
} catch { |
| 740 |
setError(); |
| 741 |
} finally { |
| 742 |
closeMenu(); |
| 743 |
} |
| 744 |
}; |
| 745 |
const canManageOptions = !!user?.capabilities?.manage_options; |
| 746 |
const isPostPublished = post.status === "publish"; |
| 747 |
const isPostHomepage = !!post.isHome; |
| 748 |
const isDisabled = !canManageOptions || isPostHomepage || !isPostPublished || updateSettingsMutation.isPending; |
| 749 |
return /* @__PURE__ */ react.createElement(ActionMenuItem, { |
| 750 |
title: (0, _wordpress_i18n.__)("Set as homepage", "elementor"), |
| 751 |
icon: !updateSettingsMutation.isPending ? _elementor_icons.HomeIcon : _elementor_ui.CircularProgress, |
| 752 |
MenuItemProps: { |
| 753 |
disabled: isDisabled, |
| 754 |
onClick: handleClick |
| 755 |
} |
| 756 |
}); |
| 757 |
} |
| 758 |
|
| 759 |
//#endregion |
| 760 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/actions-menu/actions/view.tsx |
| 761 |
function View({ post }) { |
| 762 |
const { type } = usePostListContext(); |
| 763 |
const title = (0, _wordpress_i18n.__)("View %s", "elementor").replace("%s", postTypesMap[type].labels.singular_name); |
| 764 |
return /* @__PURE__ */ react.createElement(ActionMenuItem, { |
| 765 |
title, |
| 766 |
icon: _elementor_icons.EyeIcon, |
| 767 |
MenuItemProps: { onClick: () => window.open(post.link, "_blank") } |
| 768 |
}); |
| 769 |
} |
| 770 |
|
| 771 |
//#endregion |
| 772 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/list-items/list-item-view.tsx |
| 773 |
var DisabledPostTooltip = ({ children, isDisabled }) => { |
| 774 |
if (isDisabled) { |
| 775 |
const title = /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { variant: "caption" }, "You cannot edit this page.", /* @__PURE__ */ react.createElement("br", null), "To edit it directly, contact the site owner"); |
| 776 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Tooltip, { |
| 777 |
title, |
| 778 |
placement: "bottom", |
| 779 |
arrow: false |
| 780 |
}, children); |
| 781 |
} |
| 782 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, children); |
| 783 |
}; |
| 784 |
function ListItemView({ post }) { |
| 785 |
const activeDocument = (0, _elementor_editor_documents.__useActiveDocument)(); |
| 786 |
const navigateToDocument = (0, _elementor_editor_documents.__useNavigateToDocument)(); |
| 787 |
const popupState = (0, _elementor_ui.usePopupState)({ |
| 788 |
variant: "popover", |
| 789 |
popupId: "post-actions", |
| 790 |
disableAutoFocus: true |
| 791 |
}); |
| 792 |
const isActive = activeDocument?.id === post.id; |
| 793 |
const status = isActive ? activeDocument?.status.value : post.status; |
| 794 |
const title = isActive ? activeDocument?.title : post.title.rendered; |
| 795 |
const isDisabled = !post.user_can.edit; |
| 796 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, /* @__PURE__ */ react.createElement(DisabledPostTooltip, { isDisabled }, /* @__PURE__ */ react.createElement(_elementor_ui.ListItem, { |
| 797 |
disablePadding: true, |
| 798 |
secondaryAction: /* @__PURE__ */ react.createElement(_elementor_ui.IconButton, { |
| 799 |
value: true, |
| 800 |
size: "small", |
| 801 |
...(0, _elementor_ui.bindTrigger)(popupState) |
| 802 |
}, /* @__PURE__ */ react.createElement(_elementor_icons.DotsVerticalIcon, { fontSize: "small" })) |
| 803 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemButton, { |
| 804 |
selected: isActive, |
| 805 |
disabled: isDisabled, |
| 806 |
onClick: () => { |
| 807 |
if (!isActive) navigateToDocument(post.id); |
| 808 |
}, |
| 809 |
dense: true |
| 810 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { disableTypography: true }, /* @__PURE__ */ react.createElement(PageTitleAndStatus, { |
| 811 |
title, |
| 812 |
status |
| 813 |
})), post.isHome && /* @__PURE__ */ react.createElement(_elementor_icons.HomeIcon, { |
| 814 |
titleAccess: (0, _wordpress_i18n.__)("Homepage", "elementor"), |
| 815 |
color: "disabled" |
| 816 |
})))), /* @__PURE__ */ react.createElement(_elementor_ui.Menu, { |
| 817 |
PaperProps: { sx: { |
| 818 |
mt: 2, |
| 819 |
width: 200 |
| 820 |
} }, |
| 821 |
MenuListProps: { dense: true }, |
| 822 |
...(0, _elementor_ui.bindMenu)(popupState) |
| 823 |
}, /* @__PURE__ */ react.createElement(Rename, { post }), /* @__PURE__ */ react.createElement(Duplicate, { |
| 824 |
post, |
| 825 |
popupState |
| 826 |
}), /* @__PURE__ */ react.createElement(Delete, { post }), /* @__PURE__ */ react.createElement(View, { post }), /* @__PURE__ */ react.createElement(_elementor_ui.Divider, null), /* @__PURE__ */ react.createElement(SetHome, { |
| 827 |
post, |
| 828 |
closeMenu: () => popupState.close() |
| 829 |
}))); |
| 830 |
} |
| 831 |
|
| 832 |
//#endregion |
| 833 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/post-list-item.tsx |
| 834 |
function PostListItem$1({ post }) { |
| 835 |
const { editMode } = usePostListContext(); |
| 836 |
if ("rename" === editMode.mode && post?.id && post?.id === editMode.details.postId) return /* @__PURE__ */ react.createElement(ListItemRename, { post }); |
| 837 |
if ("create" === editMode.mode && !post) return /* @__PURE__ */ react.createElement(ListItemCreate, null); |
| 838 |
if ("duplicate" === editMode.mode && !post) return /* @__PURE__ */ react.createElement(ListItemDuplicate, null); |
| 839 |
if (!post) return null; |
| 840 |
return /* @__PURE__ */ react.createElement(ListItemView, { post }); |
| 841 |
} |
| 842 |
__name(PostListItem$1, "PostListItem"); |
| 843 |
|
| 844 |
//#endregion |
| 845 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/posts-list/posts-collapsible-list.tsx |
| 846 |
function PostsCollapsibleList({ isOpenByDefault = false }) { |
| 847 |
const { type, editMode } = usePostListContext(); |
| 848 |
const { data: { posts, total }, isLoading: postsLoading, isError: postsError, fetchNextPage, hasNextPage, isFetchingNextPage } = usePosts(type); |
| 849 |
const { data: homepageId } = useHomepage(); |
| 850 |
if (postsError) return /* @__PURE__ */ react.createElement(ErrorState, null); |
| 851 |
if (!posts || postsLoading) return /* @__PURE__ */ react.createElement(_elementor_ui.Box, { sx: { px: 5 } }, /* @__PURE__ */ react.createElement(_elementor_ui.Box, { |
| 852 |
display: "flex", |
| 853 |
justifyContent: "flex-end", |
| 854 |
alignItems: "center" |
| 855 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.Skeleton, { |
| 856 |
sx: { my: 4 }, |
| 857 |
animation: "wave", |
| 858 |
variant: "rounded", |
| 859 |
width: "110px", |
| 860 |
height: "28px" |
| 861 |
})), /* @__PURE__ */ react.createElement(_elementor_ui.Box, null, /* @__PURE__ */ react.createElement(_elementor_ui.Skeleton, { |
| 862 |
sx: { my: 3 }, |
| 863 |
animation: "wave", |
| 864 |
variant: "rounded", |
| 865 |
width: "100%", |
| 866 |
height: "24px" |
| 867 |
}), /* @__PURE__ */ react.createElement(_elementor_ui.Skeleton, { |
| 868 |
sx: { my: 3 }, |
| 869 |
animation: "wave", |
| 870 |
variant: "rounded", |
| 871 |
width: "70%", |
| 872 |
height: "24px" |
| 873 |
}), /* @__PURE__ */ react.createElement(_elementor_ui.Skeleton, { |
| 874 |
sx: { my: 3 }, |
| 875 |
animation: "wave", |
| 876 |
variant: "rounded", |
| 877 |
width: "70%", |
| 878 |
height: "24px" |
| 879 |
}), /* @__PURE__ */ react.createElement(_elementor_ui.Skeleton, { |
| 880 |
sx: { my: 3 }, |
| 881 |
animation: "wave", |
| 882 |
variant: "rounded", |
| 883 |
width: "70%", |
| 884 |
height: "24px" |
| 885 |
}))); |
| 886 |
const label = `${postTypesMap[type].labels.plural_name} (${total.toString()})`; |
| 887 |
const sortedPosts = posts.map((post) => { |
| 888 |
if (post.id === homepageId) return { |
| 889 |
...post, |
| 890 |
isHome: true |
| 891 |
}; |
| 892 |
return post; |
| 893 |
}).sort((a, b) => { |
| 894 |
if (a.id === homepageId) return -1; |
| 895 |
if (b.id === homepageId) return 1; |
| 896 |
return 0; |
| 897 |
}); |
| 898 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, /* @__PURE__ */ react.createElement(_elementor_ui.Box, { |
| 899 |
display: "flex", |
| 900 |
justifyContent: "flex-end", |
| 901 |
alignItems: "center", |
| 902 |
sx: { |
| 903 |
py: 1, |
| 904 |
px: 2 |
| 905 |
} |
| 906 |
}, /* @__PURE__ */ react.createElement(AddNewButton, null)), /* @__PURE__ */ react.createElement(_elementor_ui.List, { dense: true }, /* @__PURE__ */ react.createElement(CollapsibleList, { |
| 907 |
label, |
| 908 |
Icon: _elementor_icons.PageTypeIcon, |
| 909 |
isOpenByDefault: isOpenByDefault || false |
| 910 |
}, sortedPosts.map((post) => { |
| 911 |
return /* @__PURE__ */ react.createElement(PostListItem$1, { |
| 912 |
key: post.id, |
| 913 |
post |
| 914 |
}); |
| 915 |
}), ["duplicate", "create"].includes(editMode.mode) && /* @__PURE__ */ react.createElement(PostListItem$1, null), hasNextPage && /* @__PURE__ */ react.createElement(_elementor_ui.Box, { sx: { |
| 916 |
display: "flex", |
| 917 |
justifyContent: "center" |
| 918 |
} }, /* @__PURE__ */ react.createElement(_elementor_ui.Button, { |
| 919 |
onClick: fetchNextPage, |
| 920 |
color: "secondary" |
| 921 |
}, isFetchingNextPage ? /* @__PURE__ */ react.createElement(_elementor_ui.CircularProgress, null) : "Load More"))))); |
| 922 |
} |
| 923 |
|
| 924 |
//#endregion |
| 925 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/shell.tsx |
| 926 |
var Shell = () => { |
| 927 |
const [isErrorSnackbarOpen, setIsErrorSnackbarOpen] = (0, react.useState)(false); |
| 928 |
return /* @__PURE__ */ react.createElement(_elementor_editor_panels.Panel, null, /* @__PURE__ */ react.createElement(_elementor_editor_panels.PanelHeader, null, /* @__PURE__ */ react.createElement(_elementor_editor_panels.PanelHeaderTitle, null, (0, _wordpress_i18n.__)("Pages", "elementor"))), /* @__PURE__ */ react.createElement(_elementor_editor_panels.PanelBody, null, /* @__PURE__ */ react.createElement(PostListContextProvider, { |
| 929 |
type: "page", |
| 930 |
setError: () => setIsErrorSnackbarOpen(true) |
| 931 |
}, /* @__PURE__ */ react.createElement(PostsCollapsibleList, { isOpenByDefault: true })), /* @__PURE__ */ react.createElement(ErrorSnackbar, { |
| 932 |
open: isErrorSnackbarOpen, |
| 933 |
onClose: () => setIsErrorSnackbarOpen(false) |
| 934 |
}))); |
| 935 |
}; |
| 936 |
|
| 937 |
//#endregion |
| 938 |
//#region packages/packages/core/editor-site-navigation/src/components/panel/panel.ts |
| 939 |
var { panel, usePanelStatus, usePanelActions } = (0, _elementor_editor_panels.createPanel)({ |
| 940 |
id: "site-navigation-panel", |
| 941 |
component: Shell |
| 942 |
}); |
| 943 |
|
| 944 |
//#endregion |
| 945 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-create-page.ts |
| 946 |
var endpointPath = "/elementor/v1/site-navigation/add-new-post"; |
| 947 |
function useCreatePage() { |
| 948 |
const [isLoading, setIsLoading] = (0, react.useState)(false); |
| 949 |
return { |
| 950 |
create: () => { |
| 951 |
setIsLoading(true); |
| 952 |
return addNewPage().then((newPost) => newPost).finally(() => setIsLoading(false)); |
| 953 |
}, |
| 954 |
isLoading |
| 955 |
}; |
| 956 |
} |
| 957 |
async function addNewPage() { |
| 958 |
return await (0, _wordpress_api_fetch.default)({ |
| 959 |
path: endpointPath, |
| 960 |
method: "POST", |
| 961 |
data: { post_type: "page" } |
| 962 |
}); |
| 963 |
} |
| 964 |
|
| 965 |
//#endregion |
| 966 |
//#region packages/packages/core/editor-site-navigation/src/components/top-bar/create-post-list-item.tsx |
| 967 |
function CreatePostListItem({ closePopup, ...props }) { |
| 968 |
const { create, isLoading } = useCreatePage(); |
| 969 |
const navigateToDocument = (0, _elementor_editor_documents.__useNavigateToDocument)(); |
| 970 |
const { data: user } = useUser(); |
| 971 |
const { dispatchEvent, config } = (0, _elementor_events.useMixpanel)(); |
| 972 |
return /* @__PURE__ */ react.createElement(_elementor_ui.MenuItem, { |
| 973 |
disabled: isLoading || !user?.capabilities?.edit_pages, |
| 974 |
onClick: async () => { |
| 975 |
const eventName = config?.names?.editorOne?.topBarPageList; |
| 976 |
if (eventName) dispatchEvent?.(eventName, { |
| 977 |
window_name: config?.appTypes?.editor, |
| 978 |
interaction_type: config?.triggers?.click?.toLowerCase(), |
| 979 |
target_type: config?.targetTypes?.dropdownItem, |
| 980 |
target_name: config?.targetNames?.pageList?.addNewPage, |
| 981 |
interaction_result: config?.interactionResults?.create, |
| 982 |
target_location: config?.locations?.topBar?.replace(/\s+/g, "_").toLowerCase(), |
| 983 |
location_l1: config?.secondaryLocations?.pageListDropdown?.replace(/\s+/g, "_").toLowerCase(), |
| 984 |
location_l2: config?.targetTypes?.dropdownItem |
| 985 |
}); |
| 986 |
const { id } = await create(); |
| 987 |
closePopup(); |
| 988 |
await navigateToDocument(id); |
| 989 |
}, |
| 990 |
...props |
| 991 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemIcon, null, isLoading ? /* @__PURE__ */ react.createElement(_elementor_ui.CircularProgress, { size: "1.25rem" }) : /* @__PURE__ */ react.createElement(_elementor_icons.PlusIcon, { fontSize: "small" })), /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { |
| 992 |
primaryTypographyProps: { variant: "body2" }, |
| 993 |
primary: (0, _wordpress_i18n.__)("Add new page", "elementor") |
| 994 |
})); |
| 995 |
} |
| 996 |
|
| 997 |
//#endregion |
| 998 |
//#region packages/packages/core/editor-site-navigation/src/components/top-bar/indicator.tsx |
| 999 |
function Indicator({ title, status }) { |
| 1000 |
return /* @__PURE__ */ react.createElement(Tooltip, { title }, /* @__PURE__ */ react.createElement(_elementor_ui.Stack, { |
| 1001 |
component: "span", |
| 1002 |
direction: "row", |
| 1003 |
alignItems: "center", |
| 1004 |
spacing: .5 |
| 1005 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 1006 |
component: "span", |
| 1007 |
variant: "body2", |
| 1008 |
sx: { maxWidth: "120px" }, |
| 1009 |
noWrap: true |
| 1010 |
}, title), status.value !== "publish" && /* @__PURE__ */ react.createElement(_elementor_ui.Typography, { |
| 1011 |
component: "span", |
| 1012 |
variant: "body2", |
| 1013 |
sx: { fontStyle: "italic" } |
| 1014 |
}, "(", status.label, ")"))); |
| 1015 |
} |
| 1016 |
function Tooltip(props) { |
| 1017 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Tooltip, { |
| 1018 |
PopperProps: { sx: { "&.MuiTooltip-popper .MuiTooltip-tooltip.MuiTooltip-tooltipPlacementBottom": { mt: 2.7 } } }, |
| 1019 |
...props |
| 1020 |
}); |
| 1021 |
} |
| 1022 |
|
| 1023 |
//#endregion |
| 1024 |
//#region packages/packages/core/editor-site-navigation/src/components/top-bar/chip-doc-type.tsx |
| 1025 |
var iconsMap = getIconsMap(); |
| 1026 |
function DocTypeChip({ postType, docType, label }) { |
| 1027 |
const color = "elementor_library" === postType ? "global" : "primary"; |
| 1028 |
const Icon = iconsMap[docType] || _elementor_icons.PostTypeIcon; |
| 1029 |
return /* @__PURE__ */ react.createElement(_elementor_ui.Chip, { |
| 1030 |
component: "span", |
| 1031 |
size: "small", |
| 1032 |
variant: "outlined", |
| 1033 |
label, |
| 1034 |
"data-value": docType, |
| 1035 |
color, |
| 1036 |
icon: /* @__PURE__ */ react.createElement(Icon, null), |
| 1037 |
sx: { |
| 1038 |
ml: 1, |
| 1039 |
cursor: "inherit" |
| 1040 |
} |
| 1041 |
}); |
| 1042 |
} |
| 1043 |
|
| 1044 |
//#endregion |
| 1045 |
//#region packages/packages/core/editor-site-navigation/src/components/top-bar/post-list-item.tsx |
| 1046 |
function PostListItem({ post, closePopup, ...props }) { |
| 1047 |
const navigateToDocument = (0, _elementor_editor_documents.__useNavigateToDocument)(); |
| 1048 |
const postTitle = useReverseHtmlEntities(post.title); |
| 1049 |
const { dispatchEvent, config } = (0, _elementor_events.useMixpanel)(); |
| 1050 |
return /* @__PURE__ */ react.createElement(_elementor_ui.MenuItem, { |
| 1051 |
disabled: !post.user_can.edit, |
| 1052 |
onClick: async () => { |
| 1053 |
const eventName = config?.names?.editorOne?.topBarPageList; |
| 1054 |
if (eventName) dispatchEvent?.(eventName, { |
| 1055 |
window_name: config?.appTypes?.editor, |
| 1056 |
interaction_type: config?.triggers?.click?.toLowerCase(), |
| 1057 |
target_type: config?.targetTypes?.dropdownItem, |
| 1058 |
target_name: postTitle, |
| 1059 |
interaction_result: config?.interactionResults?.navigate, |
| 1060 |
target_location: config?.locations?.topBar?.replace(/\s+/g, "_").toLowerCase(), |
| 1061 |
location_l1: config?.secondaryLocations?.pageListDropdown?.replace(/\s+/g, "_").toLowerCase(), |
| 1062 |
location_l2: config?.targetTypes?.dropdownItem |
| 1063 |
}); |
| 1064 |
closePopup(); |
| 1065 |
await navigateToDocument(post.id); |
| 1066 |
}, |
| 1067 |
...props |
| 1068 |
}, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { |
| 1069 |
sx: { flexGrow: 0 }, |
| 1070 |
primaryTypographyProps: { |
| 1071 |
variant: "body2", |
| 1072 |
noWrap: true |
| 1073 |
}, |
| 1074 |
primary: postTitle |
| 1075 |
}), /* @__PURE__ */ react.createElement(DocTypeChip, { |
| 1076 |
postType: post.type.post_type, |
| 1077 |
docType: post.type.doc_type, |
| 1078 |
label: post.type.label |
| 1079 |
})); |
| 1080 |
} |
| 1081 |
|
| 1082 |
//#endregion |
| 1083 |
//#region packages/packages/core/editor-site-navigation/src/components/top-bar/recently-edited.tsx |
| 1084 |
function RecentlyEdited() { |
| 1085 |
const activeDocument = (0, _elementor_editor_documents.__useActiveDocument)(); |
| 1086 |
const hostDocument = (0, _elementor_editor_documents.__useHostDocument)(); |
| 1087 |
const document = activeDocument && activeDocument.type.value !== "kit" ? activeDocument : hostDocument; |
| 1088 |
const { data } = useRecentPosts(); |
| 1089 |
const getRecentPosts = () => { |
| 1090 |
if (!data) return []; |
| 1091 |
return data.filter((post) => post.id !== document?.id).splice(0, 6 - 1); |
| 1092 |
}; |
| 1093 |
const recentPosts = getRecentPosts(); |
| 1094 |
const popupState = (0, _elementor_ui.usePopupState)({ |
| 1095 |
variant: "popover", |
| 1096 |
popupId: "elementor-v2-top-bar-recently-edited" |
| 1097 |
}); |
| 1098 |
const documentTitle = useReverseHtmlEntities(document?.title); |
| 1099 |
if (!document) return null; |
| 1100 |
const buttonProps = (0, _elementor_ui.bindTrigger)(popupState); |
| 1101 |
return /* @__PURE__ */ react.createElement(react.Fragment, null, /* @__PURE__ */ react.createElement(_elementor_ui.Button, { |
| 1102 |
color: "inherit", |
| 1103 |
size: "small", |
| 1104 |
endIcon: /* @__PURE__ */ react.createElement(_elementor_icons.ChevronDownIcon, { fontSize: "small" }), |
| 1105 |
...buttonProps, |
| 1106 |
onClick: (e) => { |
| 1107 |
const extendedWindow = window; |
| 1108 |
const config = extendedWindow?.elementorCommon?.eventsManager?.config; |
| 1109 |
if (config) extendedWindow.elementorCommon.eventsManager.dispatchEvent(config.names.topBar.documentNameDropdown, { |
| 1110 |
location: config.locations.topBar, |
| 1111 |
secondaryLocation: config.secondaryLocations.documentNameDropdown, |
| 1112 |
trigger: config.triggers.dropdownClick, |
| 1113 |
element: config.elements.dropdown |
| 1114 |
}); |
| 1115 |
buttonProps.onClick(e); |
| 1116 |
} |
| 1117 |
}, /* @__PURE__ */ react.createElement(Indicator, { |
| 1118 |
title: documentTitle, |
| 1119 |
status: document.status |
| 1120 |
})), /* @__PURE__ */ react.createElement(_elementor_ui.Menu, { |
| 1121 |
MenuListProps: { subheader: /* @__PURE__ */ react.createElement(_elementor_ui.ListSubheader, { |
| 1122 |
color: "primary", |
| 1123 |
sx: { |
| 1124 |
fontStyle: "italic", |
| 1125 |
fontWeight: "300" |
| 1126 |
} |
| 1127 |
}, (0, _wordpress_i18n.__)("Recent", "elementor")) }, |
| 1128 |
PaperProps: { sx: { |
| 1129 |
mt: 2.5, |
| 1130 |
width: 320 |
| 1131 |
} }, |
| 1132 |
...(0, _elementor_ui.bindMenu)(popupState) |
| 1133 |
}, recentPosts.map((post) => /* @__PURE__ */ react.createElement(PostListItem, { |
| 1134 |
key: post.id, |
| 1135 |
post, |
| 1136 |
closePopup: popupState.close |
| 1137 |
})), recentPosts.length === 0 && /* @__PURE__ */ react.createElement(_elementor_ui.MenuItem, { disabled: true }, /* @__PURE__ */ react.createElement(_elementor_ui.ListItemText, { |
| 1138 |
primaryTypographyProps: { |
| 1139 |
variant: "caption", |
| 1140 |
fontStyle: "italic" |
| 1141 |
}, |
| 1142 |
primary: (0, _wordpress_i18n.__)("There are no other pages or templates on this site yet.", "elementor") |
| 1143 |
})), /* @__PURE__ */ react.createElement(_elementor_ui.Divider, { disabled: recentPosts.length === 0 }), /* @__PURE__ */ react.createElement(CreatePostListItem, { closePopup: popupState.close }))); |
| 1144 |
} |
| 1145 |
|
| 1146 |
//#endregion |
| 1147 |
//#region packages/packages/core/editor-site-navigation/src/env.ts |
| 1148 |
var { env } = (0, _elementor_env.parseEnv)("@elementor/editor-site-navigation", (envData) => { |
| 1149 |
return envData; |
| 1150 |
}); |
| 1151 |
|
| 1152 |
//#endregion |
| 1153 |
//#region packages/packages/core/editor-site-navigation/src/hooks/use-toggle-button-props.ts |
| 1154 |
function useToggleButtonProps() { |
| 1155 |
const { isOpen: selectedState, isBlocked } = usePanelStatus(); |
| 1156 |
const { open, close } = usePanelActions(); |
| 1157 |
return { |
| 1158 |
title: (0, _wordpress_i18n.__)("Pages", "elementor"), |
| 1159 |
icon: _elementor_icons.PagesIcon, |
| 1160 |
onClick: () => { |
| 1161 |
const extendedWindow = window; |
| 1162 |
const config = extendedWindow?.elementorCommon?.eventsManager?.config; |
| 1163 |
if (config) extendedWindow.elementorCommon.eventsManager.dispatchEvent("top_bar_pages", { |
| 1164 |
location: config.locations.topBar, |
| 1165 |
secondaryLocation: config.secondaryLocations.elementorLogo, |
| 1166 |
trigger: config.triggers.click, |
| 1167 |
element: config.elements.buttonIcon |
| 1168 |
}); |
| 1169 |
return selectedState ? close() : open(); |
| 1170 |
}, |
| 1171 |
selected: selectedState, |
| 1172 |
disabled: isBlocked |
| 1173 |
}; |
| 1174 |
} |
| 1175 |
|
| 1176 |
//#endregion |
| 1177 |
//#region packages/packages/core/editor-site-navigation/src/init.ts |
| 1178 |
function init() { |
| 1179 |
registerTopBarMenuItems(); |
| 1180 |
if (env.is_pages_panel_active) { |
| 1181 |
(0, _elementor_editor_panels.registerPanel)(panel); |
| 1182 |
registerButton(); |
| 1183 |
} |
| 1184 |
} |
| 1185 |
function registerTopBarMenuItems() { |
| 1186 |
(0, _elementor_editor_app_bar.injectIntoPageIndication)({ |
| 1187 |
id: "document-recently-edited", |
| 1188 |
component: RecentlyEdited |
| 1189 |
}); |
| 1190 |
} |
| 1191 |
function registerButton() { |
| 1192 |
_elementor_editor_app_bar.toolsMenu.registerToggleAction({ |
| 1193 |
id: "toggle-site-navigation-panel", |
| 1194 |
priority: 6, |
| 1195 |
useProps: useToggleButtonProps |
| 1196 |
}); |
| 1197 |
} |
| 1198 |
|
| 1199 |
//#endregion |
| 1200 |
//#region packages/packages/core/editor-site-navigation/src/index.ts |
| 1201 |
var src_exports = /* @__PURE__ */ __exportAll({ |
| 1202 |
extendIconsMap: () => extendIconsMap, |
| 1203 |
init: () => init |
| 1204 |
}); |
| 1205 |
|
| 1206 |
//#endregion |
| 1207 |
//#region \0elementor-package-library-entry |
| 1208 |
(window.elementorV2 = window.elementorV2 || {}).editorSiteNavigation = src_exports; |
| 1209 |
|
| 1210 |
//#endregion |
| 1211 |
})(elementorV2.icons, elementorV2.editorAppBar, elementorV2.editorPanels, React, wp.i18n, elementorV2.ui, wp.apiFetch, elementorV2.query, elementorV2.editorDocuments, elementorV2.editorV1Adapters, elementorV2.events, elementorV2.env); |
| 1212 |
window.elementorV2.editorSiteNavigation?.init?.(); |
| 1213 |
//# sourceMappingURL=editor-site-navigation.js.map |