first commit
This commit is contained in:
119
wp-includes/js/dist/script-modules/block-library/accordion/view.js
vendored
Normal file
119
wp-includes/js/dist/script-modules/block-library/accordion/view.js
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
// packages/block-library/build-module/accordion/view.mjs
|
||||
import { store, getContext, withSyncEvent } from "@wordpress/interactivity";
|
||||
var hashHandled = false;
|
||||
var { actions } = store(
|
||||
"core/accordion",
|
||||
{
|
||||
state: {
|
||||
get isOpen() {
|
||||
const { id, accordionItems } = getContext();
|
||||
const accordionItem = accordionItems.find(
|
||||
(item) => item.id === id
|
||||
);
|
||||
return accordionItem ? accordionItem.isOpen : false;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
toggle: () => {
|
||||
const context = getContext();
|
||||
const { id, autoclose, accordionItems } = context;
|
||||
const accordionItem = accordionItems.find(
|
||||
(item) => item.id === id
|
||||
);
|
||||
if (autoclose) {
|
||||
accordionItems.forEach((item) => {
|
||||
item.isOpen = item.id === id ? !accordionItem.isOpen : false;
|
||||
});
|
||||
} else {
|
||||
accordionItem.isOpen = !accordionItem.isOpen;
|
||||
}
|
||||
},
|
||||
handleKeyDown: withSyncEvent((event) => {
|
||||
if (event.key !== "ArrowUp" && event.key !== "ArrowDown" && event.key !== "Home" && event.key !== "End") {
|
||||
return;
|
||||
}
|
||||
event.preventDefault();
|
||||
const context = getContext();
|
||||
const { id, accordionItems } = context;
|
||||
const currentIndex = accordionItems.findIndex(
|
||||
(item) => item.id === id
|
||||
);
|
||||
let nextIndex;
|
||||
switch (event.key) {
|
||||
case "ArrowUp":
|
||||
nextIndex = Math.max(0, currentIndex - 1);
|
||||
break;
|
||||
case "ArrowDown":
|
||||
nextIndex = Math.min(
|
||||
currentIndex + 1,
|
||||
accordionItems.length - 1
|
||||
);
|
||||
break;
|
||||
case "Home":
|
||||
nextIndex = 0;
|
||||
break;
|
||||
case "End":
|
||||
nextIndex = accordionItems.length - 1;
|
||||
break;
|
||||
}
|
||||
const nextId = accordionItems[nextIndex].id;
|
||||
const nextButton = document.getElementById(nextId);
|
||||
if (nextButton) {
|
||||
nextButton.focus();
|
||||
}
|
||||
}),
|
||||
openPanelByHash: () => {
|
||||
if (hashHandled || !window.location?.hash?.length) {
|
||||
return;
|
||||
}
|
||||
const context = getContext();
|
||||
const { id, accordionItems, autoclose } = context;
|
||||
const hash = decodeURIComponent(
|
||||
window.location.hash.slice(1)
|
||||
);
|
||||
const targetElement = window.document.getElementById(hash);
|
||||
if (!targetElement) {
|
||||
return;
|
||||
}
|
||||
const panelElement = window.document.querySelector(
|
||||
'.wp-block-accordion-panel[aria-labelledby="' + id + '"]'
|
||||
);
|
||||
if (!panelElement || !panelElement.contains(targetElement)) {
|
||||
return;
|
||||
}
|
||||
hashHandled = true;
|
||||
if (autoclose) {
|
||||
accordionItems.forEach((item) => {
|
||||
item.isOpen = item.id === id;
|
||||
});
|
||||
} else {
|
||||
const targetItem = accordionItems.find(
|
||||
(item) => item.id === id
|
||||
);
|
||||
if (targetItem) {
|
||||
targetItem.isOpen = true;
|
||||
}
|
||||
}
|
||||
window.setTimeout(() => {
|
||||
targetElement.scrollIntoView();
|
||||
}, 0);
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
initAccordionItems: () => {
|
||||
const context = getContext();
|
||||
const { id, openByDefault, accordionItems } = context;
|
||||
accordionItems.push({
|
||||
id,
|
||||
isOpen: openByDefault
|
||||
});
|
||||
actions.openPanelByHash();
|
||||
},
|
||||
hashChange: () => {
|
||||
hashHandled = false;
|
||||
actions.openPanelByHash();
|
||||
}
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/accordion/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/accordion/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '2af01b43d30739c3fb8d');
|
||||
1
wp-includes/js/dist/script-modules/block-library/accordion/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/accordion/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as f,getContext as i,withSyncEvent as m}from"@wordpress/interactivity";var l=!1,{actions:h}=f("core/accordion",{state:{get isOpen(){let{id:e,accordionItems:t}=i(),c=t.find(o=>o.id===e);return c?c.isOpen:!1}},actions:{toggle:()=>{let e=i(),{id:t,autoclose:c,accordionItems:o}=e,s=o.find(n=>n.id===t);c?o.forEach(n=>{n.isOpen=n.id===t?!s.isOpen:!1}):s.isOpen=!s.isOpen},handleKeyDown:m(e=>{if(e.key!=="ArrowUp"&&e.key!=="ArrowDown"&&e.key!=="Home"&&e.key!=="End")return;e.preventDefault();let t=i(),{id:c,accordionItems:o}=t,s=o.findIndex(d=>d.id===c),n;switch(e.key){case"ArrowUp":n=Math.max(0,s-1);break;case"ArrowDown":n=Math.min(s+1,o.length-1);break;case"Home":n=0;break;case"End":n=o.length-1;break}let r=o[n].id,a=document.getElementById(r);a&&a.focus()}),openPanelByHash:()=>{if(l||!window.location?.hash?.length)return;let e=i(),{id:t,accordionItems:c,autoclose:o}=e,s=decodeURIComponent(window.location.hash.slice(1)),n=window.document.getElementById(s);if(!n)return;let r=window.document.querySelector('.wp-block-accordion-panel[aria-labelledby="'+t+'"]');if(!(!r||!r.contains(n))){if(l=!0,o)c.forEach(a=>{a.isOpen=a.id===t});else{let a=c.find(d=>d.id===t);a&&(a.isOpen=!0)}window.setTimeout(()=>{n.scrollIntoView()},0)}}},callbacks:{initAccordionItems:()=>{let e=i(),{id:t,openByDefault:c,accordionItems:o}=e;o.push({id:t,isOpen:c}),h.openPanelByHash()},hashChange:()=>{l=!1,h.openPanelByHash()}}},{lock:!0});
|
||||
44
wp-includes/js/dist/script-modules/block-library/file/view.js
vendored
Normal file
44
wp-includes/js/dist/script-modules/block-library/file/view.js
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
// packages/block-library/build-module/file/view.mjs
|
||||
import { store } from "@wordpress/interactivity";
|
||||
|
||||
// packages/block-library/build-module/file/utils/index.mjs
|
||||
var browserSupportsPdfs = () => {
|
||||
if (window.navigator.pdfViewerEnabled) {
|
||||
return true;
|
||||
}
|
||||
if (window.navigator.userAgent.indexOf("Mobi") > -1) {
|
||||
return false;
|
||||
}
|
||||
if (window.navigator.userAgent.indexOf("Android") > -1) {
|
||||
return false;
|
||||
}
|
||||
if (window.navigator.userAgent.indexOf("Macintosh") > -1 && window.navigator.maxTouchPoints && window.navigator.maxTouchPoints > 2) {
|
||||
return false;
|
||||
}
|
||||
if (!!(window.ActiveXObject || "ActiveXObject" in window) && !(createActiveXObject("AcroPDF.PDF") || createActiveXObject("PDF.PdfCtrl"))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
var createActiveXObject = (type) => {
|
||||
let ax;
|
||||
try {
|
||||
ax = new window.ActiveXObject(type);
|
||||
} catch (e) {
|
||||
ax = void 0;
|
||||
}
|
||||
return ax;
|
||||
};
|
||||
|
||||
// packages/block-library/build-module/file/view.mjs
|
||||
store(
|
||||
"core/file",
|
||||
{
|
||||
state: {
|
||||
get hasPdfPreview() {
|
||||
return browserSupportsPdfs();
|
||||
}
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/file/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/file/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '7d4d261d10dca47ebecb');
|
||||
1
wp-includes/js/dist/script-modules/block-library/file/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/file/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as n}from"@wordpress/interactivity";var t=()=>window.navigator.pdfViewerEnabled?!0:!(window.navigator.userAgent.indexOf("Mobi")>-1||window.navigator.userAgent.indexOf("Android")>-1||window.navigator.userAgent.indexOf("Macintosh")>-1&&window.navigator.maxTouchPoints&&window.navigator.maxTouchPoints>2||(window.ActiveXObject||"ActiveXObject"in window)&&!(r("AcroPDF.PDF")||r("PDF.PdfCtrl"))),r=i=>{let e;try{e=new window.ActiveXObject(i)}catch{e=void 0}return e};n("core/file",{state:{get hasPdfPreview(){return t()}}},{lock:!0});
|
||||
45
wp-includes/js/dist/script-modules/block-library/form/view.js
vendored
Normal file
45
wp-includes/js/dist/script-modules/block-library/form/view.js
vendored
Normal file
@@ -0,0 +1,45 @@
|
||||
// packages/block-library/build-module/form/view.mjs
|
||||
var formSettings;
|
||||
try {
|
||||
formSettings = JSON.parse(
|
||||
document.getElementById(
|
||||
"wp-script-module-data-@wordpress/block-library/form/view"
|
||||
)?.textContent
|
||||
);
|
||||
} catch {
|
||||
}
|
||||
document.querySelectorAll("form.wp-block-form").forEach(function(form) {
|
||||
if (!formSettings || !form.action || !form.action.startsWith("mailto:")) {
|
||||
return;
|
||||
}
|
||||
const redirectNotification = (status) => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
urlParams.append("wp-form-result", status);
|
||||
window.location.search = urlParams.toString();
|
||||
};
|
||||
form.addEventListener("submit", async function(event) {
|
||||
event.preventDefault();
|
||||
const formData = Object.fromEntries(new FormData(form).entries());
|
||||
formData.formAction = form.action;
|
||||
formData._ajax_nonce = formSettings.nonce;
|
||||
formData.action = formSettings.action;
|
||||
formData._wp_http_referer = window.location.href;
|
||||
formData.formAction = form.action;
|
||||
try {
|
||||
const response = await fetch(formSettings.ajaxUrl, {
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
},
|
||||
body: new URLSearchParams(formData).toString()
|
||||
});
|
||||
if (response.ok) {
|
||||
redirectNotification("success");
|
||||
} else {
|
||||
redirectNotification("error");
|
||||
}
|
||||
} catch (error) {
|
||||
redirectNotification("error");
|
||||
}
|
||||
});
|
||||
});
|
||||
1
wp-includes/js/dist/script-modules/block-library/form/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/form/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'version' => '5542f8ad251fe43ef09e');
|
||||
1
wp-includes/js/dist/script-modules/block-library/form/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/form/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
var o;try{o=JSON.parse(document.getElementById("wp-script-module-data-@wordpress/block-library/form/view")?.textContent)}catch{}document.querySelectorAll("form.wp-block-form").forEach(function(e){if(!o||!e.action||!e.action.startsWith("mailto:"))return;let r=n=>{let t=new URLSearchParams(window.location.search);t.append("wp-form-result",n),window.location.search=t.toString()};e.addEventListener("submit",async function(n){n.preventDefault();let t=Object.fromEntries(new FormData(e).entries());t.formAction=e.action,t._ajax_nonce=o.nonce,t.action=o.action,t._wp_http_referer=window.location.href,t.formAction=e.action;try{(await fetch(o.ajaxUrl,{method:"POST",headers:{"Content-Type":"application/x-www-form-urlencoded"},body:new URLSearchParams(t).toString()})).ok?r("success"):r("error")}catch{r("error")}})});
|
||||
462
wp-includes/js/dist/script-modules/block-library/image/view.js
vendored
Normal file
462
wp-includes/js/dist/script-modules/block-library/image/view.js
vendored
Normal file
@@ -0,0 +1,462 @@
|
||||
// packages/block-library/build-module/image/view.mjs
|
||||
import {
|
||||
store,
|
||||
getContext,
|
||||
getElement,
|
||||
getConfig,
|
||||
withSyncEvent,
|
||||
withScope
|
||||
} from "@wordpress/interactivity";
|
||||
|
||||
// packages/block-library/build-module/image/constants.mjs
|
||||
var IMAGE_PRELOAD_DELAY = 200;
|
||||
|
||||
// packages/block-library/build-module/image/view.mjs
|
||||
var isTouching = false;
|
||||
var lastTouchTime = 0;
|
||||
var touchStartEvent = {
|
||||
startX: 0,
|
||||
startY: 0,
|
||||
startTime: 0
|
||||
};
|
||||
var focusableSelectors = [
|
||||
".wp-lightbox-close-button",
|
||||
".wp-lightbox-navigation-button"
|
||||
];
|
||||
function getImageSrc({ uploadedSrc }) {
|
||||
return uploadedSrc || "data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=";
|
||||
}
|
||||
function getImageSrcset({ lightboxSrcset }) {
|
||||
return lightboxSrcset || "";
|
||||
}
|
||||
var { state, actions, callbacks } = store(
|
||||
"core/image",
|
||||
{
|
||||
state: {
|
||||
selectedImageId: null,
|
||||
selectedGalleryId: null,
|
||||
preloadTimers: /* @__PURE__ */ new Map(),
|
||||
preloadedImageIds: /* @__PURE__ */ new Set(),
|
||||
get galleryImages() {
|
||||
if (!state.selectedGalleryId) {
|
||||
return [state.selectedImageId];
|
||||
}
|
||||
return Object.entries(state.metadata).filter(
|
||||
([, value]) => value.galleryId === state.selectedGalleryId
|
||||
).sort(([, a], [, b]) => {
|
||||
const orderA = a.order ?? 0;
|
||||
const orderB = b.order ?? 0;
|
||||
return orderA - orderB;
|
||||
}).map(([key]) => key);
|
||||
},
|
||||
get selectedImageIndex() {
|
||||
return state.galleryImages.findIndex(
|
||||
(id) => id === state.selectedImageId
|
||||
);
|
||||
},
|
||||
get selectedImage() {
|
||||
return state.metadata[state.selectedImageId];
|
||||
},
|
||||
get hasNavigationIcon() {
|
||||
const { navigationButtonType } = state.selectedImage;
|
||||
return navigationButtonType === "icon" || navigationButtonType === "both";
|
||||
},
|
||||
get hasNavigationText() {
|
||||
const { navigationButtonType } = state.selectedImage;
|
||||
return navigationButtonType === "text" || navigationButtonType === "both";
|
||||
},
|
||||
get thisImage() {
|
||||
const { imageId } = getContext();
|
||||
return state.metadata[imageId];
|
||||
},
|
||||
get hasNavigation() {
|
||||
return state.galleryImages.length > 1;
|
||||
},
|
||||
get hasNextImage() {
|
||||
return state.selectedImageIndex + 1 < state.galleryImages.length;
|
||||
},
|
||||
get hasPreviousImage() {
|
||||
return state.selectedImageIndex - 1 >= 0;
|
||||
},
|
||||
get overlayOpened() {
|
||||
return state.selectedImageId !== null;
|
||||
},
|
||||
get roleAttribute() {
|
||||
return state.overlayOpened ? "dialog" : null;
|
||||
},
|
||||
get ariaModal() {
|
||||
return state.overlayOpened ? "true" : null;
|
||||
},
|
||||
get ariaLabel() {
|
||||
return state.selectedImage.customAriaLabel || getConfig().defaultAriaLabel;
|
||||
},
|
||||
get closeButtonAriaLabel() {
|
||||
return state.hasNavigationText ? void 0 : getConfig().closeButtonText;
|
||||
},
|
||||
get prevButtonAriaLabel() {
|
||||
return state.hasNavigationText ? void 0 : getConfig().prevButtonText;
|
||||
},
|
||||
get nextButtonAriaLabel() {
|
||||
return state.hasNavigationText ? void 0 : getConfig().nextButtonText;
|
||||
},
|
||||
get enlargedSrc() {
|
||||
return getImageSrc(state.selectedImage);
|
||||
},
|
||||
get enlargedSrcset() {
|
||||
return getImageSrcset(state.selectedImage);
|
||||
},
|
||||
get figureStyles() {
|
||||
return state.overlayOpened && `${state.selectedImage.figureStyles?.replace(
|
||||
/margin[^;]*;?/g,
|
||||
""
|
||||
)};`;
|
||||
},
|
||||
get imgStyles() {
|
||||
return state.overlayOpened && `${state.selectedImage.imgStyles?.replace(
|
||||
/;$/,
|
||||
""
|
||||
)}; object-fit:cover;`;
|
||||
},
|
||||
get isContentHidden() {
|
||||
const ctx = getContext();
|
||||
return state.overlayEnabled && state.selectedImageId === ctx.imageId;
|
||||
},
|
||||
get isContentVisible() {
|
||||
const ctx = getContext();
|
||||
return !state.overlayEnabled && state.selectedImageId === ctx.imageId;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
showLightbox() {
|
||||
const { imageId } = getContext();
|
||||
if (!state.metadata[imageId].imageRef?.complete) {
|
||||
return;
|
||||
}
|
||||
state.scrollTopReset = document.documentElement.scrollTop;
|
||||
state.scrollLeftReset = document.documentElement.scrollLeft;
|
||||
state.selectedImageId = imageId;
|
||||
const { galleryId } = getContext("core/gallery") || {};
|
||||
state.selectedGalleryId = galleryId || null;
|
||||
state.overlayEnabled = true;
|
||||
callbacks.setOverlayStyles();
|
||||
},
|
||||
hideLightbox() {
|
||||
if (state.overlayEnabled) {
|
||||
state.overlayEnabled = false;
|
||||
setTimeout(function() {
|
||||
state.selectedImage.buttonRef.focus({
|
||||
preventScroll: true
|
||||
});
|
||||
state.selectedImageId = null;
|
||||
state.selectedGalleryId = null;
|
||||
}, 450);
|
||||
}
|
||||
},
|
||||
showPreviousImage: withSyncEvent((event) => {
|
||||
event.stopPropagation();
|
||||
const nextIndex = state.hasPreviousImage ? state.selectedImageIndex - 1 : state.galleryImages.length - 1;
|
||||
state.selectedImageId = state.galleryImages[nextIndex];
|
||||
callbacks.setOverlayStyles();
|
||||
}),
|
||||
showNextImage: withSyncEvent((event) => {
|
||||
event.stopPropagation();
|
||||
const nextIndex = state.hasNextImage ? state.selectedImageIndex + 1 : 0;
|
||||
state.selectedImageId = state.galleryImages[nextIndex];
|
||||
callbacks.setOverlayStyles();
|
||||
}),
|
||||
handleKeydown: withSyncEvent((event) => {
|
||||
if (state.overlayEnabled) {
|
||||
if (event.key === "Escape") {
|
||||
actions.hideLightbox();
|
||||
} else if (event.key === "ArrowLeft") {
|
||||
actions.showPreviousImage(event);
|
||||
} else if (event.key === "ArrowRight") {
|
||||
actions.showNextImage(event);
|
||||
} else if (event.key === "Tab") {
|
||||
const focusableElements = Array.from(
|
||||
document.querySelectorAll(focusableSelectors)
|
||||
);
|
||||
const firstFocusableElement = focusableElements[0];
|
||||
const lastFocusableElement = focusableElements[focusableElements.length - 1];
|
||||
if (event.shiftKey && event.target === firstFocusableElement) {
|
||||
event.preventDefault();
|
||||
lastFocusableElement.focus();
|
||||
} else if (!event.shiftKey && event.target === lastFocusableElement) {
|
||||
event.preventDefault();
|
||||
firstFocusableElement.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
handleTouchMove: withSyncEvent((event) => {
|
||||
if (state.overlayEnabled) {
|
||||
event.preventDefault();
|
||||
}
|
||||
}),
|
||||
handleTouchStart(event) {
|
||||
isTouching = true;
|
||||
const t = event.touches && event.touches[0];
|
||||
if (t) {
|
||||
touchStartEvent.startX = t.clientX;
|
||||
touchStartEvent.startY = t.clientY;
|
||||
touchStartEvent.startTime = Date.now();
|
||||
}
|
||||
},
|
||||
handleTouchEnd: withSyncEvent((event) => {
|
||||
const touchEndEvent = event.changedTouches && event.changedTouches[0] || event.touches && event.touches[0];
|
||||
const now = Date.now();
|
||||
if (touchEndEvent && state.overlayEnabled) {
|
||||
const deltaX = touchEndEvent.clientX - touchStartEvent.startX;
|
||||
const deltaY = touchEndEvent.clientY - touchStartEvent.startY;
|
||||
const absDeltaX = Math.abs(deltaX);
|
||||
const absDeltaY = Math.abs(deltaY);
|
||||
const elapsedMs = now - touchStartEvent.startTime;
|
||||
const isHorizontalSwipe = (
|
||||
// Swipe distance is greater than 50px
|
||||
absDeltaX > 50 && // Horizontal movement is much larger than the vertical movement
|
||||
absDeltaX > absDeltaY * 1.5 && // Fast action of less than 800ms
|
||||
elapsedMs < 800
|
||||
);
|
||||
if (isHorizontalSwipe) {
|
||||
event.preventDefault();
|
||||
if (deltaX < 0) {
|
||||
actions.showNextImage(event);
|
||||
} else {
|
||||
actions.showPreviousImage(event);
|
||||
}
|
||||
}
|
||||
}
|
||||
lastTouchTime = now;
|
||||
isTouching = false;
|
||||
}),
|
||||
handleScroll() {
|
||||
if (state.overlayOpened) {
|
||||
if (!isTouching && Date.now() - lastTouchTime > 450) {
|
||||
window.scrollTo(
|
||||
state.scrollLeftReset,
|
||||
state.scrollTopReset
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
preloadImage() {
|
||||
const { imageId } = getContext();
|
||||
if (state.preloadedImageIds.has(imageId)) {
|
||||
return;
|
||||
}
|
||||
const imageMetadata = state.metadata[imageId];
|
||||
const imageLink = document.createElement("link");
|
||||
imageLink.rel = "preload";
|
||||
imageLink.as = "image";
|
||||
imageLink.href = getImageSrc(imageMetadata);
|
||||
const srcset = getImageSrcset(imageMetadata);
|
||||
if (srcset) {
|
||||
imageLink.setAttribute("imagesrcset", srcset);
|
||||
imageLink.setAttribute("imagesizes", "100vw");
|
||||
}
|
||||
document.head.appendChild(imageLink);
|
||||
state.preloadedImageIds.add(imageId);
|
||||
},
|
||||
preloadImageWithDelay() {
|
||||
const { imageId } = getContext();
|
||||
actions.cancelPreload();
|
||||
const timerId = setTimeout(
|
||||
withScope(() => {
|
||||
actions.preloadImage();
|
||||
state.preloadTimers.delete(imageId);
|
||||
}),
|
||||
IMAGE_PRELOAD_DELAY
|
||||
);
|
||||
state.preloadTimers.set(imageId, timerId);
|
||||
},
|
||||
cancelPreload() {
|
||||
const { imageId } = getContext();
|
||||
if (state.preloadTimers.has(imageId)) {
|
||||
clearTimeout(state.preloadTimers.get(imageId));
|
||||
state.preloadTimers.delete(imageId);
|
||||
}
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
setOverlayStyles() {
|
||||
if (!state.overlayEnabled) {
|
||||
return;
|
||||
}
|
||||
let {
|
||||
naturalWidth,
|
||||
naturalHeight,
|
||||
offsetWidth: originalWidth,
|
||||
offsetHeight: originalHeight
|
||||
} = state.selectedImage.imageRef;
|
||||
let { x: screenPosX, y: screenPosY } = state.selectedImage.imageRef.getBoundingClientRect();
|
||||
const naturalRatio = naturalWidth / naturalHeight;
|
||||
let originalRatio = originalWidth / originalHeight;
|
||||
if (state.selectedImage.scaleAttr === "contain") {
|
||||
if (naturalRatio > originalRatio) {
|
||||
const heightWithoutSpace = originalWidth / naturalRatio;
|
||||
screenPosY += (originalHeight - heightWithoutSpace) / 2;
|
||||
originalHeight = heightWithoutSpace;
|
||||
} else {
|
||||
const widthWithoutSpace = originalHeight * naturalRatio;
|
||||
screenPosX += (originalWidth - widthWithoutSpace) / 2;
|
||||
originalWidth = widthWithoutSpace;
|
||||
}
|
||||
}
|
||||
originalRatio = originalWidth / originalHeight;
|
||||
let imgMaxWidth = parseFloat(
|
||||
state.selectedImage.targetWidth && state.selectedImage.targetWidth !== "none" ? state.selectedImage.targetWidth : naturalWidth
|
||||
);
|
||||
let imgMaxHeight = parseFloat(
|
||||
state.selectedImage.targetHeight && state.selectedImage.targetHeight !== "none" ? state.selectedImage.targetHeight : naturalHeight
|
||||
);
|
||||
let imgRatio = imgMaxWidth / imgMaxHeight;
|
||||
let containerMaxWidth = imgMaxWidth;
|
||||
let containerMaxHeight = imgMaxHeight;
|
||||
let containerWidth = imgMaxWidth;
|
||||
let containerHeight = imgMaxHeight;
|
||||
if (naturalRatio.toFixed(2) !== imgRatio.toFixed(2)) {
|
||||
if (naturalRatio > imgRatio) {
|
||||
const reducedHeight = imgMaxWidth / naturalRatio;
|
||||
if (imgMaxHeight - reducedHeight > imgMaxWidth) {
|
||||
imgMaxHeight = reducedHeight;
|
||||
imgMaxWidth = reducedHeight * naturalRatio;
|
||||
} else {
|
||||
imgMaxHeight = imgMaxWidth / naturalRatio;
|
||||
}
|
||||
} else {
|
||||
const reducedWidth = imgMaxHeight * naturalRatio;
|
||||
if (imgMaxWidth - reducedWidth > imgMaxHeight) {
|
||||
imgMaxWidth = reducedWidth;
|
||||
imgMaxHeight = reducedWidth / naturalRatio;
|
||||
} else {
|
||||
imgMaxWidth = imgMaxHeight * naturalRatio;
|
||||
}
|
||||
}
|
||||
containerWidth = imgMaxWidth;
|
||||
containerHeight = imgMaxHeight;
|
||||
imgRatio = imgMaxWidth / imgMaxHeight;
|
||||
if (originalRatio > imgRatio) {
|
||||
containerMaxWidth = imgMaxWidth;
|
||||
containerMaxHeight = containerMaxWidth / originalRatio;
|
||||
} else {
|
||||
containerMaxHeight = imgMaxHeight;
|
||||
containerMaxWidth = containerMaxHeight * originalRatio;
|
||||
}
|
||||
}
|
||||
if (originalWidth > containerWidth || originalHeight > containerHeight) {
|
||||
containerWidth = originalWidth;
|
||||
containerHeight = originalHeight;
|
||||
}
|
||||
let horizontalPadding = 0;
|
||||
let verticalPadding = 160;
|
||||
if (480 < window.innerWidth) {
|
||||
horizontalPadding = 80;
|
||||
verticalPadding = 160;
|
||||
}
|
||||
if (960 < window.innerWidth) {
|
||||
horizontalPadding = state.hasNavigation ? 320 : 80;
|
||||
verticalPadding = 80;
|
||||
}
|
||||
const targetMaxWidth = Math.min(
|
||||
window.innerWidth - horizontalPadding,
|
||||
containerWidth
|
||||
);
|
||||
const targetMaxHeight = Math.min(
|
||||
window.innerHeight - verticalPadding,
|
||||
containerHeight
|
||||
);
|
||||
const targetContainerRatio = targetMaxWidth / targetMaxHeight;
|
||||
if (originalRatio > targetContainerRatio) {
|
||||
containerWidth = targetMaxWidth;
|
||||
containerHeight = containerWidth / originalRatio;
|
||||
} else {
|
||||
containerHeight = targetMaxHeight;
|
||||
containerWidth = containerHeight * originalRatio;
|
||||
}
|
||||
const containerScale = originalWidth / containerWidth;
|
||||
const lightboxImgWidth = imgMaxWidth * (containerWidth / containerMaxWidth);
|
||||
const lightboxImgHeight = imgMaxHeight * (containerHeight / containerMaxHeight);
|
||||
state.overlayStyles = `
|
||||
--wp--lightbox-initial-top-position: ${screenPosY}px;
|
||||
--wp--lightbox-initial-left-position: ${screenPosX}px;
|
||||
--wp--lightbox-container-width: ${containerWidth + 1}px;
|
||||
--wp--lightbox-container-height: ${containerHeight + 1}px;
|
||||
--wp--lightbox-image-width: ${lightboxImgWidth}px;
|
||||
--wp--lightbox-image-height: ${lightboxImgHeight}px;
|
||||
--wp--lightbox-scale: ${containerScale};
|
||||
--wp--lightbox-scrollbar-width: ${window.innerWidth - document.documentElement.clientWidth}px;
|
||||
`;
|
||||
},
|
||||
setButtonStyles() {
|
||||
const { ref } = getElement();
|
||||
if (!ref) {
|
||||
return;
|
||||
}
|
||||
const { imageId } = getContext();
|
||||
state.metadata[imageId].imageRef = ref;
|
||||
state.metadata[imageId].currentSrc = ref.currentSrc;
|
||||
const {
|
||||
naturalWidth,
|
||||
naturalHeight,
|
||||
offsetWidth,
|
||||
offsetHeight
|
||||
} = ref;
|
||||
if (naturalWidth === 0 || naturalHeight === 0) {
|
||||
return;
|
||||
}
|
||||
const figure = ref.parentElement;
|
||||
const figureWidth = ref.parentElement.clientWidth;
|
||||
let figureHeight = ref.parentElement.clientHeight;
|
||||
const caption = figure.querySelector("figcaption");
|
||||
if (caption) {
|
||||
const captionComputedStyle = window.getComputedStyle(caption);
|
||||
if (!["absolute", "fixed"].includes(
|
||||
captionComputedStyle.position
|
||||
)) {
|
||||
figureHeight = figureHeight - caption.offsetHeight - parseFloat(captionComputedStyle.marginTop) - parseFloat(captionComputedStyle.marginBottom);
|
||||
}
|
||||
}
|
||||
const buttonOffsetTop = figureHeight - offsetHeight;
|
||||
const buttonOffsetRight = figureWidth - offsetWidth;
|
||||
let buttonTop = buttonOffsetTop + 16;
|
||||
let buttonRight = buttonOffsetRight + 16;
|
||||
if (state.metadata[imageId].scaleAttr === "contain") {
|
||||
const naturalRatio = naturalWidth / naturalHeight;
|
||||
const offsetRatio = offsetWidth / offsetHeight;
|
||||
if (naturalRatio >= offsetRatio) {
|
||||
const referenceHeight = offsetWidth / naturalRatio;
|
||||
buttonTop = (offsetHeight - referenceHeight) / 2 + buttonOffsetTop + 16;
|
||||
buttonRight = buttonOffsetRight + 16;
|
||||
} else {
|
||||
const referenceWidth = offsetHeight * naturalRatio;
|
||||
buttonTop = buttonOffsetTop + 16;
|
||||
buttonRight = (offsetWidth - referenceWidth) / 2 + buttonOffsetRight + 16;
|
||||
}
|
||||
}
|
||||
state.metadata[imageId].buttonTop = buttonTop;
|
||||
state.metadata[imageId].buttonRight = buttonRight;
|
||||
},
|
||||
setOverlayFocus() {
|
||||
if (state.overlayEnabled) {
|
||||
const { ref } = getElement();
|
||||
ref.focus();
|
||||
}
|
||||
},
|
||||
setInertElements() {
|
||||
document.querySelectorAll("body > :not(.wp-lightbox-overlay)").forEach((el) => {
|
||||
if (state.overlayEnabled) {
|
||||
el.setAttribute("inert", "");
|
||||
} else {
|
||||
el.removeAttribute("inert");
|
||||
}
|
||||
});
|
||||
},
|
||||
initTriggerButton() {
|
||||
const { imageId } = getContext();
|
||||
const { ref } = getElement();
|
||||
state.metadata[imageId].buttonRef = ref;
|
||||
}
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/image/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/image/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '25ee935fd6c67371d0f3');
|
||||
10
wp-includes/js/dist/script-modules/block-library/image/view.min.js
vendored
Normal file
10
wp-includes/js/dist/script-modules/block-library/image/view.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
177
wp-includes/js/dist/script-modules/block-library/navigation/view.js
vendored
Normal file
177
wp-includes/js/dist/script-modules/block-library/navigation/view.js
vendored
Normal file
@@ -0,0 +1,177 @@
|
||||
// packages/block-library/build-module/navigation/view.mjs
|
||||
import {
|
||||
store,
|
||||
getContext,
|
||||
getElement,
|
||||
withSyncEvent
|
||||
} from "@wordpress/interactivity";
|
||||
var focusableSelectors = [
|
||||
"a[href]",
|
||||
'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',
|
||||
"select:not([disabled]):not([aria-hidden])",
|
||||
"textarea:not([disabled]):not([aria-hidden])",
|
||||
"button:not([disabled]):not([aria-hidden])",
|
||||
"[contenteditable]",
|
||||
'[tabindex]:not([tabindex^="-"])'
|
||||
];
|
||||
function getFocusableElements(ref) {
|
||||
const focusableElements = ref.querySelectorAll(focusableSelectors);
|
||||
return Array.from(focusableElements).filter((element) => {
|
||||
if (typeof element.checkVisibility === "function") {
|
||||
return element.checkVisibility({
|
||||
checkOpacity: false,
|
||||
checkVisibilityCSS: true
|
||||
});
|
||||
}
|
||||
return element.offsetParent !== null;
|
||||
});
|
||||
}
|
||||
document.addEventListener("click", () => {
|
||||
});
|
||||
var { state, actions } = store(
|
||||
"core/navigation",
|
||||
{
|
||||
state: {
|
||||
get roleAttribute() {
|
||||
const ctx = getContext();
|
||||
return ctx.type === "overlay" && state.isMenuOpen ? "dialog" : null;
|
||||
},
|
||||
get ariaModal() {
|
||||
const ctx = getContext();
|
||||
return ctx.type === "overlay" && state.isMenuOpen ? "true" : null;
|
||||
},
|
||||
get ariaLabel() {
|
||||
const ctx = getContext();
|
||||
return ctx.type === "overlay" && state.isMenuOpen ? ctx.ariaLabel : null;
|
||||
},
|
||||
get isMenuOpen() {
|
||||
return Object.values(state.menuOpenedBy).filter(Boolean).length > 0;
|
||||
},
|
||||
get menuOpenedBy() {
|
||||
const ctx = getContext();
|
||||
return ctx.type === "overlay" ? ctx.overlayOpenedBy : ctx.submenuOpenedBy;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
openMenuOnHover(event) {
|
||||
if (event?.pointerType === "touch") {
|
||||
return;
|
||||
}
|
||||
const { type, overlayOpenedBy } = getContext();
|
||||
if (type === "submenu" && // Only open on hover if the overlay is closed.
|
||||
Object.values(overlayOpenedBy || {}).filter(Boolean).length === 0) {
|
||||
actions.openMenu("hover");
|
||||
}
|
||||
},
|
||||
closeMenuOnHover(event) {
|
||||
if (event?.pointerType === "touch") {
|
||||
return;
|
||||
}
|
||||
const { type, overlayOpenedBy } = getContext();
|
||||
if (type === "submenu" && // Only close on hover if the overlay is closed.
|
||||
Object.values(overlayOpenedBy || {}).filter(Boolean).length === 0) {
|
||||
actions.closeMenu("hover");
|
||||
}
|
||||
},
|
||||
openMenuOnClick() {
|
||||
const ctx = getContext();
|
||||
const { ref } = getElement();
|
||||
ctx.previousFocus = ref;
|
||||
actions.openMenu("click");
|
||||
},
|
||||
closeMenuOnClick() {
|
||||
actions.closeMenu("click");
|
||||
actions.closeMenu("focus");
|
||||
},
|
||||
openMenuOnFocus() {
|
||||
actions.openMenu("focus");
|
||||
},
|
||||
toggleMenuOnClick() {
|
||||
const ctx = getContext();
|
||||
const { ref } = getElement();
|
||||
if (window.document.activeElement !== ref) {
|
||||
ref.focus();
|
||||
}
|
||||
const { menuOpenedBy } = state;
|
||||
if (menuOpenedBy.click || menuOpenedBy.focus) {
|
||||
actions.closeMenu("click");
|
||||
actions.closeMenu("focus");
|
||||
actions.closeMenu("hover");
|
||||
} else {
|
||||
ctx.previousFocus = ref;
|
||||
actions.openMenu("click");
|
||||
}
|
||||
},
|
||||
handleMenuKeydown: withSyncEvent((event) => {
|
||||
const { type, firstFocusableElement, lastFocusableElement } = getContext();
|
||||
if (state.menuOpenedBy.click) {
|
||||
if (event.key === "Escape") {
|
||||
event.stopPropagation();
|
||||
actions.closeMenu("click");
|
||||
actions.closeMenu("focus");
|
||||
return;
|
||||
}
|
||||
if (type === "overlay" && event.key === "Tab") {
|
||||
if (event.shiftKey && window.document.activeElement === firstFocusableElement) {
|
||||
event.preventDefault();
|
||||
lastFocusableElement.focus();
|
||||
} else if (!event.shiftKey && window.document.activeElement === lastFocusableElement) {
|
||||
event.preventDefault();
|
||||
firstFocusableElement.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
}),
|
||||
handleMenuFocusout: withSyncEvent((event) => {
|
||||
const { modal, type } = getContext();
|
||||
if (event.relatedTarget === null || !modal?.contains(event.relatedTarget) && event.target !== window.document.activeElement && type === "submenu") {
|
||||
actions.closeMenu("click");
|
||||
actions.closeMenu("focus");
|
||||
}
|
||||
}),
|
||||
openMenu(menuOpenedOn = "click") {
|
||||
const { type } = getContext();
|
||||
state.menuOpenedBy[menuOpenedOn] = true;
|
||||
if (type === "overlay") {
|
||||
document.documentElement.classList.add("has-modal-open");
|
||||
}
|
||||
},
|
||||
closeMenu(menuClosedOn = "click") {
|
||||
const ctx = getContext();
|
||||
state.menuOpenedBy[menuClosedOn] = false;
|
||||
if (!state.isMenuOpen) {
|
||||
if (ctx.modal?.contains(window.document.activeElement)) {
|
||||
ctx.previousFocus?.focus();
|
||||
}
|
||||
ctx.modal = null;
|
||||
ctx.previousFocus = null;
|
||||
if (ctx.type === "overlay") {
|
||||
document.documentElement.classList.remove(
|
||||
"has-modal-open"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
initMenu() {
|
||||
const ctx = getContext();
|
||||
const { ref } = getElement();
|
||||
if (state.isMenuOpen) {
|
||||
const focusableElements = getFocusableElements(ref);
|
||||
ctx.modal = ref;
|
||||
ctx.firstFocusableElement = focusableElements[0];
|
||||
ctx.lastFocusableElement = focusableElements[focusableElements.length - 1];
|
||||
}
|
||||
},
|
||||
focusFirstElement() {
|
||||
const { ref } = getElement();
|
||||
if (state.isMenuOpen) {
|
||||
const focusableElements = getFocusableElements(ref);
|
||||
focusableElements?.[0]?.focus();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/navigation/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/navigation/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '96a846e1d7b789c39ab9');
|
||||
1
wp-includes/js/dist/script-modules/block-library/navigation/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/navigation/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as r,getContext as c,getElement as s,withSyncEvent as i}from"@wordpress/interactivity";var d=["a[href]",'input:not([disabled]):not([type="hidden"]):not([aria-hidden])',"select:not([disabled]):not([aria-hidden])","textarea:not([disabled]):not([aria-hidden])","button:not([disabled]):not([aria-hidden])","[contenteditable]",'[tabindex]:not([tabindex^="-"])'];function a(e){let n=e.querySelectorAll(d);return Array.from(n).filter(t=>typeof t.checkVisibility=="function"?t.checkVisibility({checkOpacity:!1,checkVisibilityCSS:!0}):t.offsetParent!==null)}document.addEventListener("click",()=>{});var{state:l,actions:o}=r("core/navigation",{state:{get roleAttribute(){return c().type==="overlay"&&l.isMenuOpen?"dialog":null},get ariaModal(){return c().type==="overlay"&&l.isMenuOpen?"true":null},get ariaLabel(){let e=c();return e.type==="overlay"&&l.isMenuOpen?e.ariaLabel:null},get isMenuOpen(){return Object.values(l.menuOpenedBy).filter(Boolean).length>0},get menuOpenedBy(){let e=c();return e.type==="overlay"?e.overlayOpenedBy:e.submenuOpenedBy}},actions:{openMenuOnHover(e){if(e?.pointerType==="touch")return;let{type:n,overlayOpenedBy:t}=c();n==="submenu"&&Object.values(t||{}).filter(Boolean).length===0&&o.openMenu("hover")},closeMenuOnHover(e){if(e?.pointerType==="touch")return;let{type:n,overlayOpenedBy:t}=c();n==="submenu"&&Object.values(t||{}).filter(Boolean).length===0&&o.closeMenu("hover")},openMenuOnClick(){let e=c(),{ref:n}=s();e.previousFocus=n,o.openMenu("click")},closeMenuOnClick(){o.closeMenu("click"),o.closeMenu("focus")},openMenuOnFocus(){o.openMenu("focus")},toggleMenuOnClick(){let e=c(),{ref:n}=s();window.document.activeElement!==n&&n.focus();let{menuOpenedBy:t}=l;t.click||t.focus?(o.closeMenu("click"),o.closeMenu("focus"),o.closeMenu("hover")):(e.previousFocus=n,o.openMenu("click"))},handleMenuKeydown:i(e=>{let{type:n,firstFocusableElement:t,lastFocusableElement:u}=c();if(l.menuOpenedBy.click){if(e.key==="Escape"){e.stopPropagation(),o.closeMenu("click"),o.closeMenu("focus");return}n==="overlay"&&e.key==="Tab"&&(e.shiftKey&&window.document.activeElement===t?(e.preventDefault(),u.focus()):!e.shiftKey&&window.document.activeElement===u&&(e.preventDefault(),t.focus()))}}),handleMenuFocusout:i(e=>{let{modal:n,type:t}=c();(e.relatedTarget===null||!n?.contains(e.relatedTarget)&&e.target!==window.document.activeElement&&t==="submenu")&&(o.closeMenu("click"),o.closeMenu("focus"))}),openMenu(e="click"){let{type:n}=c();l.menuOpenedBy[e]=!0,n==="overlay"&&document.documentElement.classList.add("has-modal-open")},closeMenu(e="click"){let n=c();l.menuOpenedBy[e]=!1,l.isMenuOpen||(n.modal?.contains(window.document.activeElement)&&n.previousFocus?.focus(),n.modal=null,n.previousFocus=null,n.type==="overlay"&&document.documentElement.classList.remove("has-modal-open"))}},callbacks:{initMenu(){let e=c(),{ref:n}=s();if(l.isMenuOpen){let t=a(n);e.modal=n,e.firstFocusableElement=t[0],e.lastFocusableElement=t[t.length-1]}},focusFirstElement(){let{ref:e}=s();l.isMenuOpen&&a(e)?.[0]?.focus()}}},{lock:!0});
|
||||
64
wp-includes/js/dist/script-modules/block-library/playlist/view.js
vendored
Normal file
64
wp-includes/js/dist/script-modules/block-library/playlist/view.js
vendored
Normal file
@@ -0,0 +1,64 @@
|
||||
// packages/block-library/build-module/playlist/view.mjs
|
||||
import { store, getContext, getElement } from "@wordpress/interactivity";
|
||||
store(
|
||||
"core/playlist",
|
||||
{
|
||||
state: {
|
||||
playlists: {},
|
||||
get currentTrack() {
|
||||
const { currentId, playlistId } = getContext();
|
||||
if (!currentId || !playlistId) {
|
||||
return {};
|
||||
}
|
||||
const playlist = this.playlists[playlistId];
|
||||
if (!playlist) {
|
||||
return {};
|
||||
}
|
||||
return playlist.tracks[currentId] || {};
|
||||
},
|
||||
get isCurrentTrack() {
|
||||
const { currentId, uniqueId } = getContext();
|
||||
return currentId === uniqueId;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
changeTrack() {
|
||||
const context = getContext();
|
||||
context.currentId = context.uniqueId;
|
||||
context.isPlaying = true;
|
||||
},
|
||||
isPlaying() {
|
||||
const context = getContext();
|
||||
context.isPlaying = true;
|
||||
},
|
||||
isPaused() {
|
||||
const context = getContext();
|
||||
context.isPlaying = false;
|
||||
},
|
||||
nextSong() {
|
||||
const context = getContext();
|
||||
const currentIndex = context.tracks.findIndex(
|
||||
(uniqueId) => uniqueId === context.currentId
|
||||
);
|
||||
const nextTrack = context.tracks[currentIndex + 1];
|
||||
if (nextTrack) {
|
||||
context.currentId = nextTrack;
|
||||
const { ref } = getElement();
|
||||
setTimeout(() => {
|
||||
ref.play();
|
||||
}, 1e3);
|
||||
}
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
autoPlay() {
|
||||
const context = getContext();
|
||||
const { ref } = getElement();
|
||||
if (context.currentId && context.isPlaying) {
|
||||
ref.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/playlist/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/playlist/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '99f747d731f80246db11');
|
||||
1
wp-includes/js/dist/script-modules/block-library/playlist/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/playlist/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as a,getContext as e,getElement as s}from"@wordpress/interactivity";a("core/playlist",{state:{playlists:{},get currentTrack(){let{currentId:t,playlistId:n}=e();if(!t||!n)return{};let r=this.playlists[n];return r?r.tracks[t]||{}:{}},get isCurrentTrack(){let{currentId:t,uniqueId:n}=e();return t===n}},actions:{changeTrack(){let t=e();t.currentId=t.uniqueId,t.isPlaying=!0},isPlaying(){let t=e();t.isPlaying=!0},isPaused(){let t=e();t.isPlaying=!1},nextSong(){let t=e(),n=t.tracks.findIndex(c=>c===t.currentId),r=t.tracks[n+1];if(r){t.currentId=r;let{ref:c}=s();setTimeout(()=>{c.play()},1e3)}}},callbacks:{autoPlay(){let t=e(),{ref:n}=s();t.currentId&&t.isPlaying&&n.play()}}},{lock:!0});
|
||||
53
wp-includes/js/dist/script-modules/block-library/query/view.js
vendored
Normal file
53
wp-includes/js/dist/script-modules/block-library/query/view.js
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
// packages/block-library/build-module/query/view.mjs
|
||||
import {
|
||||
store,
|
||||
getContext,
|
||||
getElement,
|
||||
withSyncEvent
|
||||
} from "@wordpress/interactivity";
|
||||
var isValidLink = (ref) => ref && ref instanceof window.HTMLAnchorElement && ref.href && (!ref.target || ref.target === "_self") && ref.origin === window.location.origin;
|
||||
var isValidEvent = (event) => event.button === 0 && // Left clicks only.
|
||||
!event.metaKey && // Open in new tab (Mac).
|
||||
!event.ctrlKey && // Open in new tab (Windows).
|
||||
!event.altKey && // Download.
|
||||
!event.shiftKey && !event.defaultPrevented;
|
||||
store(
|
||||
"core/query",
|
||||
{
|
||||
actions: {
|
||||
navigate: withSyncEvent(function* (event) {
|
||||
const ctx = getContext();
|
||||
const { ref } = getElement();
|
||||
const queryRef = ref.closest(
|
||||
".wp-block-query[data-wp-router-region]"
|
||||
);
|
||||
if (isValidLink(ref) && isValidEvent(event)) {
|
||||
event.preventDefault();
|
||||
const { actions } = yield import("@wordpress/interactivity-router");
|
||||
yield actions.navigate(ref.href);
|
||||
ctx.url = ref.href;
|
||||
const firstAnchor = `.wp-block-post-template a[href]`;
|
||||
queryRef.querySelector(firstAnchor)?.focus();
|
||||
}
|
||||
}),
|
||||
*prefetch() {
|
||||
const { ref } = getElement();
|
||||
if (isValidLink(ref)) {
|
||||
const { actions } = yield import("@wordpress/interactivity-router");
|
||||
yield actions.prefetch(ref.href);
|
||||
}
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
*prefetch() {
|
||||
const { url } = getContext();
|
||||
const { ref } = getElement();
|
||||
if (url && isValidLink(ref)) {
|
||||
const { actions } = yield import("@wordpress/interactivity-router");
|
||||
yield actions.prefetch(ref.href);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/query/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/query/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static'), array('id' => '@wordpress/interactivity-router', 'import' => 'dynamic')), 'version' => '7a4ec5bfb61a7137cf4b');
|
||||
1
wp-includes/js/dist/script-modules/block-library/query/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/query/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as a,getContext as c,getElement as r,withSyncEvent as l}from"@wordpress/interactivity";var i=t=>t&&t instanceof window.HTMLAnchorElement&&t.href&&(!t.target||t.target==="_self")&&t.origin===window.location.origin,f=t=>t.button===0&&!t.metaKey&&!t.ctrlKey&&!t.altKey&&!t.shiftKey&&!t.defaultPrevented;a("core/query",{actions:{navigate:l(function*(t){let e=c(),{ref:o}=r(),n=o.closest(".wp-block-query[data-wp-router-region]");if(i(o)&&f(t)){t.preventDefault();let{actions:s}=yield import("@wordpress/interactivity-router");yield s.navigate(o.href),e.url=o.href,n.querySelector(".wp-block-post-template a[href]")?.focus()}}),*prefetch(){let{ref:t}=r();if(i(t)){let{actions:e}=yield import("@wordpress/interactivity-router");yield e.prefetch(t.href)}}},callbacks:{*prefetch(){let{url:t}=c(),{ref:e}=r();if(t&&i(e)){let{actions:o}=yield import("@wordpress/interactivity-router");yield o.prefetch(e.href)}}}},{lock:!0});
|
||||
63
wp-includes/js/dist/script-modules/block-library/search/view.js
vendored
Normal file
63
wp-includes/js/dist/script-modules/block-library/search/view.js
vendored
Normal file
@@ -0,0 +1,63 @@
|
||||
// packages/block-library/build-module/search/view.mjs
|
||||
import {
|
||||
store,
|
||||
getContext,
|
||||
getElement,
|
||||
withSyncEvent
|
||||
} from "@wordpress/interactivity";
|
||||
var { actions } = store(
|
||||
"core/search",
|
||||
{
|
||||
state: {
|
||||
get ariaLabel() {
|
||||
const {
|
||||
isSearchInputVisible,
|
||||
ariaLabelCollapsed,
|
||||
ariaLabelExpanded
|
||||
} = getContext();
|
||||
return isSearchInputVisible ? ariaLabelExpanded : ariaLabelCollapsed;
|
||||
},
|
||||
get ariaControls() {
|
||||
const { isSearchInputVisible, inputId } = getContext();
|
||||
return isSearchInputVisible ? null : inputId;
|
||||
},
|
||||
get type() {
|
||||
const { isSearchInputVisible } = getContext();
|
||||
return isSearchInputVisible ? "submit" : "button";
|
||||
},
|
||||
get tabindex() {
|
||||
const { isSearchInputVisible } = getContext();
|
||||
return isSearchInputVisible ? "0" : "-1";
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
openSearchInput: withSyncEvent((event) => {
|
||||
const ctx = getContext();
|
||||
const { ref } = getElement();
|
||||
if (!ctx.isSearchInputVisible) {
|
||||
event.preventDefault();
|
||||
ctx.isSearchInputVisible = true;
|
||||
ref.parentElement.querySelector("input").focus();
|
||||
}
|
||||
}),
|
||||
closeSearchInput() {
|
||||
const ctx = getContext();
|
||||
ctx.isSearchInputVisible = false;
|
||||
},
|
||||
handleSearchKeydown: withSyncEvent((event) => {
|
||||
const { ref } = getElement();
|
||||
if (event?.key === "Escape") {
|
||||
actions.closeSearchInput();
|
||||
ref.querySelector("button").focus();
|
||||
}
|
||||
}),
|
||||
handleSearchFocusout: withSyncEvent((event) => {
|
||||
const { ref } = getElement();
|
||||
if (!ref.contains(event.relatedTarget) && event.target !== window.document.activeElement) {
|
||||
actions.closeSearchInput();
|
||||
}
|
||||
})
|
||||
}
|
||||
},
|
||||
{ lock: true }
|
||||
);
|
||||
1
wp-includes/js/dist/script-modules/block-library/search/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/search/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '38bd0e230eaffa354d2a');
|
||||
1
wp-includes/js/dist/script-modules/block-library/search/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/search/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as i,getContext as n,getElement as a,withSyncEvent as c}from"@wordpress/interactivity";var{actions:s}=i("core/search",{state:{get ariaLabel(){let{isSearchInputVisible:e,ariaLabelCollapsed:t,ariaLabelExpanded:r}=n();return e?r:t},get ariaControls(){let{isSearchInputVisible:e,inputId:t}=n();return e?null:t},get type(){let{isSearchInputVisible:e}=n();return e?"submit":"button"},get tabindex(){let{isSearchInputVisible:e}=n();return e?"0":"-1"}},actions:{openSearchInput:c(e=>{let t=n(),{ref:r}=a();t.isSearchInputVisible||(e.preventDefault(),t.isSearchInputVisible=!0,r.parentElement.querySelector("input").focus())}),closeSearchInput(){let e=n();e.isSearchInputVisible=!1},handleSearchKeydown:c(e=>{let{ref:t}=a();e?.key==="Escape"&&(s.closeSearchInput(),t.querySelector("button").focus())}),handleSearchFocusout:c(e=>{let{ref:t}=a();!t.contains(e.relatedTarget)&&e.target!==window.document.activeElement&&s.closeSearchInput()})}},{lock:!0});
|
||||
246
wp-includes/js/dist/script-modules/block-library/tabs/view.js
vendored
Normal file
246
wp-includes/js/dist/script-modules/block-library/tabs/view.js
vendored
Normal file
@@ -0,0 +1,246 @@
|
||||
// packages/block-library/build-module/tabs/view.mjs
|
||||
import {
|
||||
store,
|
||||
getContext,
|
||||
getElement,
|
||||
withSyncEvent
|
||||
} from "@wordpress/interactivity";
|
||||
function createReadOnlyProxy(obj) {
|
||||
const arrayMutationMethods = /* @__PURE__ */ new Set([
|
||||
"push",
|
||||
"pop",
|
||||
"shift",
|
||||
"unshift",
|
||||
"splice",
|
||||
"sort",
|
||||
"reverse",
|
||||
"copyWithin",
|
||||
"fill"
|
||||
]);
|
||||
return new Proxy(obj, {
|
||||
get(target, prop) {
|
||||
if (Array.isArray(target) && arrayMutationMethods.has(prop)) {
|
||||
return () => {
|
||||
};
|
||||
}
|
||||
const value = target[prop];
|
||||
if (typeof value === "object" && value !== null) {
|
||||
return createReadOnlyProxy(value);
|
||||
}
|
||||
return value;
|
||||
},
|
||||
set() {
|
||||
return false;
|
||||
},
|
||||
deleteProperty() {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
var { actions: privateActions, state: privateState } = store(
|
||||
"core/tabs/private",
|
||||
{
|
||||
state: {
|
||||
/**
|
||||
* Gets a contextually aware list of tabs for the current tabs block.
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
get tabsList() {
|
||||
const context = getContext();
|
||||
const tabsId = context?.tabsId;
|
||||
const tabsList = privateState[tabsId];
|
||||
return tabsList;
|
||||
},
|
||||
/**
|
||||
* Gets the index of the active tab element whether it
|
||||
* is a tab label or tab panel.
|
||||
*
|
||||
* @type {number|null}
|
||||
*/
|
||||
get tabIndex() {
|
||||
const { attributes } = getElement();
|
||||
const tabId = attributes?.id?.replace("tab__", "") || null;
|
||||
if (!tabId) {
|
||||
return null;
|
||||
}
|
||||
const { tabsList } = privateState;
|
||||
const tabIndex = tabsList.findIndex((t) => t.id === tabId);
|
||||
return tabIndex;
|
||||
},
|
||||
/**
|
||||
* Whether the tab panel or tab label is the active tab.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isActiveTab() {
|
||||
const { activeTabIndex } = getContext();
|
||||
const { tabIndex } = privateState;
|
||||
return activeTabIndex === tabIndex;
|
||||
},
|
||||
/**
|
||||
* The value of the tabindex attribute for tab buttons.
|
||||
* Only the active tab should be in the tab sequence.
|
||||
*
|
||||
* @type {number}
|
||||
*/
|
||||
get tabIndexAttribute() {
|
||||
return privateState.isActiveTab ? 0 : -1;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* Handles the keydown events for the tab label and tabs controller.
|
||||
*
|
||||
* @param {KeyboardEvent} event The keydown event.
|
||||
*/
|
||||
handleTabKeyDown: withSyncEvent((event) => {
|
||||
const context = getContext();
|
||||
const { isVertical } = context;
|
||||
const { tabIndex } = privateState;
|
||||
if (tabIndex === null) {
|
||||
return;
|
||||
}
|
||||
if (event.key === "ArrowRight" && !isVertical) {
|
||||
event.preventDefault();
|
||||
privateActions.moveFocus(tabIndex + 1);
|
||||
} else if (event.key === "ArrowLeft" && !isVertical) {
|
||||
event.preventDefault();
|
||||
privateActions.moveFocus(tabIndex - 1);
|
||||
} else if (event.key === "ArrowDown" && isVertical) {
|
||||
event.preventDefault();
|
||||
privateActions.moveFocus(tabIndex + 1);
|
||||
} else if (event.key === "ArrowUp" && isVertical) {
|
||||
event.preventDefault();
|
||||
privateActions.moveFocus(tabIndex - 1);
|
||||
}
|
||||
}),
|
||||
/**
|
||||
* Handles the click event for the tab label.
|
||||
*
|
||||
* @param {MouseEvent} event The click event.
|
||||
*/
|
||||
handleTabClick: withSyncEvent((event) => {
|
||||
event.preventDefault();
|
||||
const { tabIndex } = privateState;
|
||||
if (tabIndex !== null) {
|
||||
privateActions.setActiveTab(tabIndex);
|
||||
}
|
||||
}),
|
||||
/**
|
||||
* Moves focus to a specific tab without activating it.
|
||||
*
|
||||
* @param {number} tabIndex The index to move focus to.
|
||||
*/
|
||||
moveFocus: (tabIndex) => {
|
||||
const { tabsList } = privateState;
|
||||
if (!tabsList || tabsList.length === 0) {
|
||||
return;
|
||||
}
|
||||
let newIndex = tabIndex;
|
||||
if (newIndex < 0) {
|
||||
newIndex = tabsList.length - 1;
|
||||
} else if (newIndex >= tabsList.length) {
|
||||
newIndex = 0;
|
||||
}
|
||||
const tabId = tabsList[newIndex].id;
|
||||
const tabElement = document.getElementById("tab__" + tabId);
|
||||
if (tabElement) {
|
||||
tabElement.focus();
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Sets the active tab index (internal implementation).
|
||||
*
|
||||
* @param {number} tabIndex The index of the active tab.
|
||||
* @param {boolean} scrollToTab Whether to scroll to the tab element.
|
||||
*/
|
||||
setActiveTab: (tabIndex, scrollToTab = false) => {
|
||||
const { tabsList } = privateState;
|
||||
if (!tabsList || tabsList.length === 0) {
|
||||
return;
|
||||
}
|
||||
let newIndex = tabIndex;
|
||||
if (newIndex < 0) {
|
||||
newIndex = 0;
|
||||
} else if (newIndex >= tabsList.length) {
|
||||
newIndex = tabsList.length - 1;
|
||||
}
|
||||
const context = getContext();
|
||||
context.activeTabIndex = newIndex;
|
||||
if (scrollToTab) {
|
||||
const tabId = tabsList[newIndex].id;
|
||||
const tabElement = document.getElementById(tabId);
|
||||
if (tabElement) {
|
||||
setTimeout(() => {
|
||||
tabElement.scrollIntoView({ behavior: "smooth" });
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
callbacks: {
|
||||
/**
|
||||
* When the tabs are initialized, we need to check if there is a hash in the url and if so if it exists in the current tabsList, set the active tab to that index.
|
||||
*
|
||||
*/
|
||||
onTabsInit: () => {
|
||||
const { tabsList } = privateState;
|
||||
if (tabsList.length === 0) {
|
||||
return;
|
||||
}
|
||||
const { hash } = window.location;
|
||||
const tabId = hash.replace("#", "");
|
||||
const tabIndex = tabsList.findIndex((t) => t.id === tabId);
|
||||
if (tabIndex >= 0) {
|
||||
privateActions.setActiveTab(tabIndex, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
lock: true
|
||||
}
|
||||
);
|
||||
store("core/tabs", {
|
||||
state: {
|
||||
/**
|
||||
* Gets a contextually aware list of tabs for the current tabs block.
|
||||
* Public API for third-party access.
|
||||
*
|
||||
* @type {Array}
|
||||
*/
|
||||
get tabsList() {
|
||||
return createReadOnlyProxy(privateState.tabsList);
|
||||
},
|
||||
/**
|
||||
* Gets the index of the active tab element whether it
|
||||
* is a tab label or tab panel.
|
||||
*
|
||||
* @type {number|null}
|
||||
*/
|
||||
get tabIndex() {
|
||||
return privateState.tabIndex;
|
||||
},
|
||||
/**
|
||||
* Whether the tab panel or tab label is the active tab.
|
||||
*
|
||||
* @type {boolean}
|
||||
*/
|
||||
get isActiveTab() {
|
||||
return privateState.isActiveTab;
|
||||
}
|
||||
},
|
||||
actions: {
|
||||
/**
|
||||
* Sets the active tab index.
|
||||
* Public API for third-party programmatic tab activation.
|
||||
*
|
||||
* @param {number} tabIndex The index of the active tab.
|
||||
* @param {boolean} scrollToTab Whether to scroll to the tab element.
|
||||
*/
|
||||
setActiveTab: (tabIndex, scrollToTab = false) => {
|
||||
privateActions.setActiveTab(tabIndex, scrollToTab);
|
||||
}
|
||||
}
|
||||
});
|
||||
1
wp-includes/js/dist/script-modules/block-library/tabs/view.min.asset.php
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/tabs/view.min.asset.php
vendored
Normal file
@@ -0,0 +1 @@
|
||||
<?php return array('dependencies' => array(), 'module_dependencies' => array(array('id' => '@wordpress/interactivity', 'import' => 'static')), 'version' => '1f60dd5e3fa56c6b2e2e');
|
||||
1
wp-includes/js/dist/script-modules/block-library/tabs/view.min.js
vendored
Normal file
1
wp-includes/js/dist/script-modules/block-library/tabs/view.min.js
vendored
Normal file
@@ -0,0 +1 @@
|
||||
import{store as b,getContext as r,getElement as f,withSyncEvent as l}from"@wordpress/interactivity";function u(t){let e=new Set(["push","pop","shift","unshift","splice","sort","reverse","copyWithin","fill"]);return new Proxy(t,{get(n,s){if(Array.isArray(n)&&e.has(s))return()=>{};let a=n[s];return typeof a=="object"&&a!==null?u(a):a},set(){return!1},deleteProperty(){return!1}})}var{actions:o,state:i}=b("core/tabs/private",{state:{get tabsList(){let e=r()?.tabsId;return i[e]},get tabIndex(){let{attributes:t}=f(),e=t?.id?.replace("tab__","")||null;if(!e)return null;let{tabsList:n}=i;return n.findIndex(a=>a.id===e)},get isActiveTab(){let{activeTabIndex:t}=r(),{tabIndex:e}=i;return t===e},get tabIndexAttribute(){return i.isActiveTab?0:-1}},actions:{handleTabKeyDown:l(t=>{let e=r(),{isVertical:n}=e,{tabIndex:s}=i;s!==null&&(t.key==="ArrowRight"&&!n?(t.preventDefault(),o.moveFocus(s+1)):t.key==="ArrowLeft"&&!n?(t.preventDefault(),o.moveFocus(s-1)):t.key==="ArrowDown"&&n?(t.preventDefault(),o.moveFocus(s+1)):t.key==="ArrowUp"&&n&&(t.preventDefault(),o.moveFocus(s-1)))}),handleTabClick:l(t=>{t.preventDefault();let{tabIndex:e}=i;e!==null&&o.setActiveTab(e)}),moveFocus:t=>{let{tabsList:e}=i;if(!e||e.length===0)return;let n=t;n<0?n=e.length-1:n>=e.length&&(n=0);let s=e[n].id,a=document.getElementById("tab__"+s);a&&a.focus()},setActiveTab:(t,e=!1)=>{let{tabsList:n}=i;if(!n||n.length===0)return;let s=t;s<0?s=0:s>=n.length&&(s=n.length-1);let a=r();if(a.activeTabIndex=s,e){let d=n[s].id,c=document.getElementById(d);c&&setTimeout(()=>{c.scrollIntoView({behavior:"smooth"})},100)}}},callbacks:{onTabsInit:()=>{let{tabsList:t}=i;if(t.length===0)return;let{hash:e}=window.location,n=e.replace("#",""),s=t.findIndex(a=>a.id===n);s>=0&&o.setActiveTab(s,!0)}}},{lock:!0});b("core/tabs",{state:{get tabsList(){return u(i.tabsList)},get tabIndex(){return i.tabIndex},get isActiveTab(){return i.isActiveTab}},actions:{setActiveTab:(t,e=!1)=>{o.setActiveTab(t,e)}}});
|
||||
Reference in New Issue
Block a user