Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit c1b855c

Browse files
committed
Merge branch 'trunk' into release/9.7.0
2 parents 4d86d86 + 0984663 commit c1b855c

36 files changed

+1562
-678
lines changed

assets/js/blocks/mini-cart/index.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const settings: BlockConfiguration = {
4545
example: {
4646
attributes: {
4747
isPreview: true,
48+
className: 'wc-block-mini-cart--preview',
4849
},
4950
},
5051
attributes: {

assets/js/blocks/mini-cart/style.scss

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
display: none;
2323
}
2424

25+
.wc-block-mini-cart--preview {
26+
.wc-block-mini-cart__amount {
27+
display: initial;
28+
}
29+
}
30+
2531
.wc-block-mini-cart__tax-label {
2632
margin-right: em($gap-smaller);
2733
}
@@ -71,7 +77,6 @@
7177
top: $gap-largest;
7278
right: $gap-smallest;
7379

74-
7580
button {
7681
margin: 0;
7782
right: 0;
@@ -114,7 +119,8 @@
114119
justify-content: space-between;
115120
}
116121

117-
.wp-block-woocommerce-empty-mini-cart-contents-block .wc-block-mini-cart__empty-cart-wrapper {
122+
.wp-block-woocommerce-empty-mini-cart-contents-block
123+
.wc-block-mini-cart__empty-cart-wrapper {
118124
overflow-y: auto;
119125
padding: $gap-largest $gap $gap;
120126
}
@@ -218,6 +224,9 @@ h2.wc-block-mini-cart__title {
218224
height: calc(100vh - 32px);
219225
}
220226

221-
.admin-bar .wc-block-components-drawer .components-modal__header .components-button {
227+
.admin-bar
228+
.wc-block-components-drawer
229+
.components-modal__header
230+
.components-button {
222231
top: 32px;
223232
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
export const cstMetaTagItemprop = 'woo-client-side-transitions';
1+
export const csnMetaTagItemprop = 'woo-client-side-navigation';
22
export const componentPrefix = 'woo-';
33
export const directivePrefix = 'data-woo-';

assets/js/interactivity/directives.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@ import { useContext, useMemo, useEffect } from 'preact/hooks';
22
import { useSignalEffect } from '@preact/signals';
33
import { deepSignal, peek } from 'deepsignal';
44
import { directive } from './hooks';
5-
import { prefetch, navigate, hasClientSideTransitions } from './router';
5+
import { prefetch, navigate, canDoClientSideNavigation } from './router';
66

77
// Until useSignalEffects is fixed:
88
// https://github.com/preactjs/signals/issues/228
99
const raf = window.requestAnimationFrame;
1010
const tick = () => new Promise( ( r ) => raf( () => raf( r ) ) );
1111

12-
// Check if current page has client-side transitions enabled.
13-
const clientSideTransitions = hasClientSideTransitions( document.head );
12+
// Check if current page can do client-side navigation.
13+
const clientSideNavigation = canDoClientSideNavigation( document.head );
1414

1515
const isObject = ( item ) =>
1616
item && typeof item === 'object' && ! Array.isArray( item );
@@ -91,19 +91,19 @@ export default () => {
9191
className: name,
9292
context: contextValue,
9393
} );
94+
const currentClass = element.props.class || '';
95+
const classFinder = new RegExp(
96+
`(^|\\s)${ name }(\\s|$)`,
97+
'g'
98+
);
9499
if ( ! result )
95-
element.props.class = element.props.class
96-
.replace(
97-
new RegExp( `(^|\\s)${ name }(\\s|$)`, 'g' ),
98-
' '
99-
)
100+
element.props.class = currentClass
101+
.replace( classFinder, ' ' )
100102
.trim();
101-
else if (
102-
! new RegExp( `(^|\\s)${ name }(\\s|$)` ).test(
103-
element.props.class
104-
)
105-
)
106-
element.props.class += ` ${ name }`;
103+
else if ( ! classFinder.test( currentClass ) )
104+
element.props.class = currentClass
105+
? `${ currentClass } ${ name }`
106+
: name;
107107

108108
useEffect( () => {
109109
// This seems necessary because Preact doesn't change the class names
@@ -146,13 +146,13 @@ export default () => {
146146
} ) => {
147147
useEffect( () => {
148148
// Prefetch the page if it is in the directive options.
149-
if ( clientSideTransitions && link?.prefetch ) {
149+
if ( clientSideNavigation && link?.prefetch ) {
150150
prefetch( href );
151151
}
152152
} );
153153

154154
// Don't do anything if it's falsy.
155-
if ( clientSideTransitions && link !== false ) {
155+
if ( clientSideNavigation && link !== false ) {
156156
element.props.onclick = async ( event ) => {
157157
event.preventDefault();
158158

assets/js/interactivity/hooks.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { h, options, createContext } from 'preact';
22
import { useRef } from 'preact/hooks';
3-
import { store } from './wpx';
3+
import { rawStore as store } from './store';
44
import { componentPrefix } from './constants';
55

66
// Main context.
@@ -18,7 +18,7 @@ export const component = ( name, Comp ) => {
1818
componentMap[ name ] = Comp;
1919
};
2020

21-
// Resolve the path to some property of the wpx object.
21+
// Resolve the path to some property of the store object.
2222
const resolve = ( path, context ) => {
2323
let current = { ...store, context };
2424
path.split( '.' ).forEach( ( p ) => ( current = current[ p ] ) );

assets/js/interactivity/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import registerDirectives from './directives';
22
import registerComponents from './components';
33
import { init } from './router';
4+
export { store } from './store';
45

56
/**
67
* Initialize the initial vDOM.

assets/js/interactivity/router.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { hydrate, render } from 'preact';
22
import { toVdom, hydratedIslands } from './vdom';
33
import { createRootFragment } from './utils';
4-
import { cstMetaTagItemprop, directivePrefix } from './constants';
4+
import { csnMetaTagItemprop, directivePrefix } from './constants';
55

66
// The root to render the vdom (document.body).
77
let rootFragment;
@@ -17,10 +17,10 @@ const cleanUrl = ( url ) => {
1717
return u.pathname + u.search;
1818
};
1919

20-
// Helper to check if a page has client-side transitions activated.
21-
export const hasClientSideTransitions = ( dom ) =>
20+
// Helper to check if a page can do client-side navigation.
21+
export const canDoClientSideNavigation = ( dom ) =>
2222
dom
23-
.querySelector( `meta[itemprop='${ cstMetaTagItemprop }']` )
23+
.querySelector( `meta[itemprop='${ csnMetaTagItemprop }']` )
2424
?.getAttribute( 'content' ) === 'active';
2525

2626
// Fetch styles of a new page.
@@ -55,7 +55,7 @@ const fetchHead = async ( head ) => {
5555
const fetchPage = async ( url ) => {
5656
const html = await window.fetch( url ).then( ( r ) => r.text() );
5757
const dom = new window.DOMParser().parseFromString( html, 'text/html' );
58-
if ( ! hasClientSideTransitions( dom.head ) ) return false;
58+
if ( ! canDoClientSideNavigation( dom.head ) ) return false;
5959
const head = await fetchHead( dom.head );
6060
return { head, body: toVdom( dom.body ) };
6161
};
@@ -98,7 +98,7 @@ window.addEventListener( 'popstate', async () => {
9898

9999
// Initialize the router with the initial DOM.
100100
export const init = async () => {
101-
if ( hasClientSideTransitions( document.head ) ) {
101+
if ( canDoClientSideNavigation( document.head ) ) {
102102
// Create the root fragment to hydrate everything.
103103
rootFragment = createRootFragment(
104104
document.documentElement,

assets/js/interactivity/store.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import { deepSignal } from 'deepsignal';
2+
3+
const isObject = ( item ) =>
4+
item && typeof item === 'object' && ! Array.isArray( item );
5+
6+
export const deepMerge = ( target, source ) => {
7+
if ( isObject( target ) && isObject( source ) ) {
8+
for ( const key in source ) {
9+
if ( isObject( source[ key ] ) ) {
10+
if ( ! target[ key ] ) Object.assign( target, { [ key ]: {} } );
11+
deepMerge( target[ key ], source[ key ] );
12+
} else {
13+
Object.assign( target, { [ key ]: source[ key ] } );
14+
}
15+
}
16+
}
17+
};
18+
19+
const getSerializedState = () => {
20+
const storeTag = document.querySelector(
21+
`script[type="application/json"]#store`
22+
);
23+
if ( ! storeTag ) return {};
24+
try {
25+
const { state } = JSON.parse( storeTag.textContent );
26+
if ( isObject( state ) ) return state;
27+
throw Error( 'Parsed state is not an object' );
28+
} catch ( e ) {
29+
console.log( e );
30+
}
31+
return {};
32+
};
33+
34+
const rawState = getSerializedState();
35+
export const rawStore = { state: deepSignal( rawState ) };
36+
37+
if ( typeof window !== 'undefined' ) window.store = rawStore;
38+
39+
export const store = ( { state, ...block } ) => {
40+
deepMerge( rawStore, block );
41+
deepMerge( rawState, state );
42+
};

assets/js/interactivity/wpx.js

Lines changed: 0 additions & 27 deletions
This file was deleted.

bin/hook-docs/data/actions.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,7 @@
10531053
},
10541054
{
10551055
"name": "{$hook}",
1056-
"file": "Templates/BlockTemplatesCompatibility.php",
1056+
"file": "Templates/AbstractTemplateCompatibility.php",
10571057
"type": "action",
10581058
"doc": {
10591059
"description": "Action to render the content of a hook.",

0 commit comments

Comments
 (0)