@wordpress/block-library 8.22.0 → 8.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +4 -0
- package/build/block/edit.js +11 -13
- package/build/block/edit.js.map +1 -1
- package/build/block/edit.native.js +3 -4
- package/build/block/edit.native.js.map +1 -1
- package/build/button/edit.js +61 -9
- package/build/button/edit.js.map +1 -1
- package/build/code/transforms.js +20 -7
- package/build/code/transforms.js.map +1 -1
- package/build/column/edit.js +1 -1
- package/build/column/edit.js.map +1 -1
- package/build/column/edit.native.js +1 -1
- package/build/column/edit.native.js.map +1 -1
- package/build/comments/edit/comments-inspector-controls.js +1 -0
- package/build/comments/edit/comments-inspector-controls.js.map +1 -1
- package/build/cover/edit/index.js +2 -1
- package/build/cover/edit/index.js.map +1 -1
- package/build/cover/edit/inspector-controls.js +1 -0
- package/build/cover/edit/inspector-controls.js.map +1 -1
- package/build/details/edit.js +1 -2
- package/build/details/edit.js.map +1 -1
- package/build/file/edit.js +8 -9
- package/build/file/edit.js.map +1 -1
- package/build/file/view.js +4 -6
- package/build/file/view.js.map +1 -1
- package/build/form/index.js +1 -1
- package/build/form/index.js.map +1 -1
- package/build/form-submit-button/edit.js +2 -1
- package/build/form-submit-button/edit.js.map +1 -1
- package/build/gallery/gap-styles.js +12 -7
- package/build/gallery/gap-styles.js.map +1 -1
- package/build/group/edit.js +4 -7
- package/build/group/edit.js.map +1 -1
- package/build/html/transforms.js +7 -2
- package/build/html/transforms.js.map +1 -1
- package/build/image/deprecated.js +8 -0
- package/build/image/deprecated.js.map +1 -1
- package/build/image/edit.js +17 -18
- package/build/image/edit.js.map +1 -1
- package/build/image/edit.native.js +22 -15
- package/build/image/edit.native.js.map +1 -1
- package/build/image/image.js +35 -27
- package/build/image/image.js.map +1 -1
- package/build/image/index.js +2 -3
- package/build/image/index.js.map +1 -1
- package/build/image/view.js +234 -266
- package/build/image/view.js.map +1 -1
- package/build/missing/index.js +1 -1
- package/build/navigation/edit/overlay-menu-preview.js +1 -1
- package/build/navigation/edit/overlay-menu-preview.js.map +1 -1
- package/build/navigation/use-template-part-area-label.js +2 -1
- package/build/navigation/use-template-part-area-label.js.map +1 -1
- package/build/navigation/view.js +153 -176
- package/build/navigation/view.js.map +1 -1
- package/build/navigation-link/edit.js +1 -1
- package/build/navigation-link/edit.js.map +1 -1
- package/build/navigation-link/index.js +2 -1
- package/build/navigation-link/index.js.map +1 -1
- package/build/pattern/edit.js +2 -4
- package/build/pattern/edit.js.map +1 -1
- package/build/post-author/edit.js +0 -1
- package/build/post-author/edit.js.map +1 -1
- package/build/post-featured-image/edit.js +21 -6
- package/build/post-featured-image/edit.js.map +1 -1
- package/build/post-template/edit.js +2 -8
- package/build/post-template/edit.js.map +1 -1
- package/build/post-template/index.js +1 -1
- package/build/post-terms/edit.js +0 -2
- package/build/post-terms/edit.js.map +1 -1
- package/build/preformatted/transforms.js +1 -4
- package/build/preformatted/transforms.js.map +1 -1
- package/build/query/edit/query-content.js +1 -0
- package/build/query/edit/query-content.js.map +1 -1
- package/build/query/view.js +52 -60
- package/build/query/view.js.map +1 -1
- package/build/quote/index.js +6 -0
- package/build/quote/index.js.map +1 -1
- package/build/search/view.js +66 -74
- package/build/search/view.js.map +1 -1
- package/build/template-part/edit/advanced-controls.js +1 -0
- package/build/template-part/edit/advanced-controls.js.map +1 -1
- package/build/template-part/edit/index.js +3 -7
- package/build/template-part/edit/index.js.map +1 -1
- package/build/template-part/index.js +6 -2
- package/build/template-part/index.js.map +1 -1
- package/build/template-part/variations.js +5 -1
- package/build/template-part/variations.js.map +1 -1
- package/build/utils/remove-anchor-tag.js +17 -0
- package/build/utils/remove-anchor-tag.js.map +1 -0
- package/build-module/block/edit.js +11 -13
- package/build-module/block/edit.js.map +1 -1
- package/build-module/block/edit.native.js +3 -4
- package/build-module/block/edit.native.js.map +1 -1
- package/build-module/button/edit.js +65 -13
- package/build-module/button/edit.js.map +1 -1
- package/build-module/code/transforms.js +20 -7
- package/build-module/code/transforms.js.map +1 -1
- package/build-module/column/edit.js +1 -1
- package/build-module/column/edit.js.map +1 -1
- package/build-module/column/edit.native.js +1 -1
- package/build-module/column/edit.native.js.map +1 -1
- package/build-module/comments/edit/comments-inspector-controls.js +1 -0
- package/build-module/comments/edit/comments-inspector-controls.js.map +1 -1
- package/build-module/cover/edit/index.js +2 -1
- package/build-module/cover/edit/index.js.map +1 -1
- package/build-module/cover/edit/inspector-controls.js +1 -0
- package/build-module/cover/edit/inspector-controls.js.map +1 -1
- package/build-module/details/edit.js +1 -2
- package/build-module/details/edit.js.map +1 -1
- package/build-module/file/edit.js +8 -9
- package/build-module/file/edit.js.map +1 -1
- package/build-module/file/view.js +5 -7
- package/build-module/file/view.js.map +1 -1
- package/build-module/form/index.js +1 -1
- package/build-module/form/index.js.map +1 -1
- package/build-module/form-submit-button/edit.js +2 -1
- package/build-module/form-submit-button/edit.js.map +1 -1
- package/build-module/gallery/gap-styles.js +13 -8
- package/build-module/gallery/gap-styles.js.map +1 -1
- package/build-module/group/edit.js +4 -7
- package/build-module/group/edit.js.map +1 -1
- package/build-module/html/transforms.js +7 -2
- package/build-module/html/transforms.js.map +1 -1
- package/build-module/image/deprecated.js +8 -0
- package/build-module/image/deprecated.js.map +1 -1
- package/build-module/image/edit.js +18 -19
- package/build-module/image/edit.js.map +1 -1
- package/build-module/image/edit.native.js +23 -16
- package/build-module/image/edit.native.js.map +1 -1
- package/build-module/image/image.js +36 -28
- package/build-module/image/image.js.map +1 -1
- package/build-module/image/index.js +2 -3
- package/build-module/image/index.js.map +1 -1
- package/build-module/image/view.js +235 -267
- package/build-module/image/view.js.map +1 -1
- package/build-module/missing/index.js +1 -1
- package/build-module/navigation/edit/overlay-menu-preview.js +1 -1
- package/build-module/navigation/edit/overlay-menu-preview.js.map +1 -1
- package/build-module/navigation/use-template-part-area-label.js +2 -1
- package/build-module/navigation/use-template-part-area-label.js.map +1 -1
- package/build-module/navigation/view.js +154 -177
- package/build-module/navigation/view.js.map +1 -1
- package/build-module/navigation-link/edit.js +2 -2
- package/build-module/navigation-link/edit.js.map +1 -1
- package/build-module/navigation-link/index.js +2 -1
- package/build-module/navigation-link/index.js.map +1 -1
- package/build-module/pattern/edit.js +2 -4
- package/build-module/pattern/edit.js.map +1 -1
- package/build-module/post-author/edit.js +0 -1
- package/build-module/post-author/edit.js.map +1 -1
- package/build-module/post-featured-image/edit.js +21 -6
- package/build-module/post-featured-image/edit.js.map +1 -1
- package/build-module/post-template/edit.js +2 -8
- package/build-module/post-template/edit.js.map +1 -1
- package/build-module/post-template/index.js +1 -1
- package/build-module/post-terms/edit.js +0 -2
- package/build-module/post-terms/edit.js.map +1 -1
- package/build-module/preformatted/transforms.js +1 -4
- package/build-module/preformatted/transforms.js.map +1 -1
- package/build-module/query/edit/query-content.js +1 -0
- package/build-module/query/edit/query-content.js.map +1 -1
- package/build-module/query/view.js +53 -61
- package/build-module/query/view.js.map +1 -1
- package/build-module/quote/index.js +6 -0
- package/build-module/quote/index.js.map +1 -1
- package/build-module/search/view.js +67 -75
- package/build-module/search/view.js.map +1 -1
- package/build-module/template-part/edit/advanced-controls.js +1 -0
- package/build-module/template-part/edit/advanced-controls.js.map +1 -1
- package/build-module/template-part/edit/index.js +5 -9
- package/build-module/template-part/edit/index.js.map +1 -1
- package/build-module/template-part/index.js +6 -2
- package/build-module/template-part/index.js.map +1 -1
- package/build-module/template-part/variations.js +5 -1
- package/build-module/template-part/variations.js.map +1 -1
- package/build-module/utils/remove-anchor-tag.js +11 -0
- package/build-module/utils/remove-anchor-tag.js.map +1 -0
- package/build-style/cover/style-rtl.css +14 -14
- package/build-style/cover/style.css +14 -14
- package/build-style/editor-rtl.css +15 -6
- package/build-style/editor.css +15 -6
- package/build-style/gallery/style-rtl.css +28 -0
- package/build-style/gallery/style.css +28 -0
- package/build-style/image/style-rtl.css +19 -13
- package/build-style/image/style.css +19 -13
- package/build-style/post-featured-image/editor-rtl.css +9 -0
- package/build-style/post-featured-image/editor.css +9 -0
- package/build-style/quote/style-rtl.css +3 -0
- package/build-style/quote/style.css +3 -0
- package/build-style/read-more/style-rtl.css +2 -2
- package/build-style/read-more/style.css +2 -2
- package/build-style/style-rtl.css +66 -29
- package/build-style/style.css +66 -29
- package/package.json +32 -32
- package/src/block/edit.js +20 -20
- package/src/block/edit.native.js +5 -13
- package/src/button/edit.js +76 -10
- package/src/buttons/test/__snapshots__/edit.native.js.snap +0 -6
- package/src/buttons/test/edit.native.js +0 -27
- package/src/code/transforms.js +14 -8
- package/src/column/edit.js +1 -1
- package/src/column/edit.native.js +1 -1
- package/src/comments/edit/comments-inspector-controls.js +1 -0
- package/src/cover/edit/index.js +1 -0
- package/src/cover/edit/inspector-controls.js +1 -0
- package/src/cover/style.scss +1 -1
- package/src/cover/test/edit.js +1 -1
- package/src/details/edit.js +0 -1
- package/src/editor.scss +6 -6
- package/src/file/edit.js +11 -10
- package/src/file/index.php +30 -11
- package/src/file/view.js +5 -7
- package/src/form/index.js +1 -1
- package/src/form-submit-button/edit.js +1 -0
- package/src/gallery/gap-styles.js +10 -9
- package/src/gallery/style.scss +1 -0
- package/src/group/edit.js +4 -11
- package/src/heading/test/__snapshots__/index.native.js.snap +6 -0
- package/src/heading/test/index.native.js +40 -0
- package/src/html/transforms.js +5 -2
- package/src/image/block.json +2 -3
- package/src/image/deprecated.js +8 -0
- package/src/image/edit.js +16 -21
- package/src/image/edit.native.js +17 -18
- package/src/image/image.js +48 -51
- package/src/image/index.php +57 -49
- package/src/image/style.scss +18 -13
- package/src/image/view.js +281 -324
- package/src/missing/block.json +1 -1
- package/src/navigation/edit/overlay-menu-preview.js +1 -1
- package/src/navigation/index.php +46 -402
- package/src/navigation/use-template-part-area-label.js +4 -2
- package/src/navigation/view.js +159 -192
- package/src/navigation-link/block.json +2 -1
- package/src/navigation-link/edit.js +2 -2
- package/src/navigation-link/index.php +57 -0
- package/src/paragraph/test/__snapshots__/transforms.native.js.snap +6 -0
- package/src/paragraph/test/edit.native.js +37 -1
- package/src/paragraph/test/transforms.native.js +1 -0
- package/src/pattern/edit.js +7 -4
- package/src/pattern/index.php +6 -1
- package/src/post-author/edit.js +0 -1
- package/src/post-featured-image/edit.js +38 -5
- package/src/post-featured-image/editor.scss +19 -0
- package/src/post-template/block.json +0 -1
- package/src/post-template/edit.js +1 -5
- package/src/post-terms/edit.js +0 -2
- package/src/preformatted/transforms.js +1 -4
- package/src/query/edit/query-content.js +1 -0
- package/src/query/index.php +42 -24
- package/src/query/view.js +58 -65
- package/src/query-pagination-next/index.php +3 -3
- package/src/query-pagination-numbers/index.php +1 -1
- package/src/query-pagination-previous/index.php +3 -3
- package/src/quote/block.json +6 -0
- package/src/quote/style.scss +4 -0
- package/src/read-more/style.scss +1 -1
- package/src/search/index.php +40 -40
- package/src/search/view.js +58 -63
- package/src/template-part/edit/advanced-controls.js +1 -0
- package/src/template-part/edit/index.js +7 -14
- package/src/template-part/index.js +4 -3
- package/src/template-part/index.php +4 -4
- package/src/template-part/variations.js +4 -2
- package/src/utils/remove-anchor-tag.js +10 -0
- package/tsconfig.json +1 -0
package/build/image/view.js
CHANGED
|
@@ -7,7 +7,7 @@ var _interactivity = require("@wordpress/interactivity");
|
|
|
7
7
|
|
|
8
8
|
const focusableSelectors = ['a[href]', 'area[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])', 'iframe', 'object', 'embed', '[contenteditable]', '[tabindex]:not([tabindex^="-"])'];
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
/**
|
|
11
11
|
* Stores a context-bound scroll handler.
|
|
12
12
|
*
|
|
13
13
|
* This callback could be defined inline inside of the store
|
|
@@ -22,7 +22,7 @@ const focusableSelectors = ['a[href]', 'area[href]', 'input:not([disabled]):not(
|
|
|
22
22
|
*/
|
|
23
23
|
let scrollCallback;
|
|
24
24
|
|
|
25
|
-
|
|
25
|
+
/**
|
|
26
26
|
* Tracks whether user is touching screen; used to
|
|
27
27
|
* differentiate behavior for touch and mouse input.
|
|
28
28
|
*
|
|
@@ -30,7 +30,7 @@ let scrollCallback;
|
|
|
30
30
|
*/
|
|
31
31
|
let isTouching = false;
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
/**
|
|
34
34
|
* Tracks the last time the screen was touched; used to
|
|
35
35
|
* differentiate behavior for touch and mouse input.
|
|
36
36
|
*
|
|
@@ -38,7 +38,7 @@ let isTouching = false;
|
|
|
38
38
|
*/
|
|
39
39
|
let lastTouchTime = 0;
|
|
40
40
|
|
|
41
|
-
|
|
41
|
+
/**
|
|
42
42
|
* Lightbox page-scroll handler: prevents scrolling.
|
|
43
43
|
*
|
|
44
44
|
* This handler is added to prevent scrolling behaviors that
|
|
@@ -54,302 +54,269 @@ let lastTouchTime = 0;
|
|
|
54
54
|
* instead to not rely on JavaScript, but this seems to be the best approach
|
|
55
55
|
* for now that provides the best visual experience.
|
|
56
56
|
*
|
|
57
|
-
* @param {Object}
|
|
57
|
+
* @param {Object} ctx Context object with the `core/image` namespace.
|
|
58
58
|
*/
|
|
59
|
-
function handleScroll(
|
|
59
|
+
function handleScroll(ctx) {
|
|
60
60
|
// We can't override the scroll behavior on mobile devices
|
|
61
61
|
// because doing so breaks the pinch to zoom functionality, and we
|
|
62
62
|
// want to allow users to zoom in further on the high-res image.
|
|
63
63
|
if (!isTouching && Date.now() - lastTouchTime > 450) {
|
|
64
64
|
// We are unable to use event.preventDefault() to prevent scrolling
|
|
65
65
|
// because the scroll event can't be canceled, so we reset the position instead.
|
|
66
|
-
window.scrollTo(
|
|
66
|
+
window.scrollTo(ctx.scrollLeftReset, ctx.scrollTopReset);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
|
-
|
|
69
|
+
const {
|
|
70
|
+
state,
|
|
71
|
+
actions,
|
|
72
|
+
callbacks
|
|
73
|
+
} = (0, _interactivity.store)('core/image', {
|
|
70
74
|
state: {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
+
windowWidth: window.innerWidth,
|
|
76
|
+
windowHeight: window.innerHeight,
|
|
77
|
+
get roleAttribute() {
|
|
78
|
+
const ctx = (0, _interactivity.getContext)();
|
|
79
|
+
return ctx.lightboxEnabled ? 'dialog' : null;
|
|
80
|
+
},
|
|
81
|
+
get ariaModal() {
|
|
82
|
+
const ctx = (0, _interactivity.getContext)();
|
|
83
|
+
return ctx.lightboxEnabled ? 'true' : null;
|
|
84
|
+
},
|
|
85
|
+
get dialogLabel() {
|
|
86
|
+
const ctx = (0, _interactivity.getContext)();
|
|
87
|
+
return ctx.lightboxEnabled ? ctx.dialogLabel : null;
|
|
88
|
+
},
|
|
89
|
+
get lightboxObjectFit() {
|
|
90
|
+
const ctx = (0, _interactivity.getContext)();
|
|
91
|
+
if (ctx.initialized) {
|
|
92
|
+
return 'cover';
|
|
75
93
|
}
|
|
94
|
+
},
|
|
95
|
+
get enlargedImgSrc() {
|
|
96
|
+
const ctx = (0, _interactivity.getContext)();
|
|
97
|
+
return ctx.initialized ? ctx.imageUploadedSrc : 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
|
|
76
98
|
}
|
|
77
99
|
},
|
|
78
100
|
actions: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
context.core.image.pointerType = event.pointerType;
|
|
94
|
-
context.core.image.lightboxEnabled = true;
|
|
95
|
-
setStyles(context, context.core.image.imageRef);
|
|
96
|
-
context.core.image.scrollTopReset = window.pageYOffset || document.documentElement.scrollTop;
|
|
101
|
+
showLightbox(event) {
|
|
102
|
+
const ctx = (0, _interactivity.getContext)();
|
|
103
|
+
// We can't initialize the lightbox until the reference
|
|
104
|
+
// image is loaded, otherwise the UX is broken.
|
|
105
|
+
if (!ctx.imageLoaded) {
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
ctx.initialized = true;
|
|
109
|
+
ctx.lastFocusedElement = window.document.activeElement;
|
|
110
|
+
ctx.scrollDelta = 0;
|
|
111
|
+
ctx.pointerType = event.pointerType;
|
|
112
|
+
ctx.lightboxEnabled = true;
|
|
113
|
+
setStyles(ctx, ctx.imageRef);
|
|
114
|
+
ctx.scrollTopReset = window.pageYOffset || document.documentElement.scrollTop;
|
|
97
115
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
116
|
+
// In most cases, this value will be 0, but this is included
|
|
117
|
+
// in case a user has created a page with horizontal scrolling.
|
|
118
|
+
ctx.scrollLeftReset = window.pageXOffset || document.documentElement.scrollLeft;
|
|
101
119
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
120
|
+
// We define and bind the scroll callback here so
|
|
121
|
+
// that we can pass the context and as an argument.
|
|
122
|
+
// We may be able to change this in the future if we
|
|
123
|
+
// define the scroll callback in the store instead, but
|
|
124
|
+
// this approach seems to tbe clearest for now.
|
|
125
|
+
scrollCallback = handleScroll.bind(null, ctx);
|
|
108
126
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
preventScroll: true
|
|
133
|
-
});
|
|
134
|
-
}, 450);
|
|
135
|
-
context.core.image.lightboxEnabled = false;
|
|
136
|
-
}
|
|
137
|
-
},
|
|
138
|
-
handleKeydown: ({
|
|
139
|
-
context,
|
|
140
|
-
actions,
|
|
141
|
-
event
|
|
142
|
-
}) => {
|
|
143
|
-
if (context.core.image.lightboxEnabled) {
|
|
144
|
-
if (event.key === 'Tab' || event.keyCode === 9) {
|
|
145
|
-
// If shift + tab it change the direction
|
|
146
|
-
if (event.shiftKey && window.document.activeElement === context.core.image.firstFocusableElement) {
|
|
147
|
-
event.preventDefault();
|
|
148
|
-
context.core.image.lastFocusableElement.focus();
|
|
149
|
-
} else if (!event.shiftKey && window.document.activeElement === context.core.image.lastFocusableElement) {
|
|
150
|
-
event.preventDefault();
|
|
151
|
-
context.core.image.firstFocusableElement.focus();
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
if (event.key === 'Escape' || event.keyCode === 27) {
|
|
155
|
-
actions.core.image.hideLightbox({
|
|
156
|
-
context,
|
|
157
|
-
event
|
|
158
|
-
});
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
// This is fired just by lazily loaded
|
|
163
|
-
// images on the page, not all images.
|
|
164
|
-
handleLoad: ({
|
|
165
|
-
context,
|
|
166
|
-
effects,
|
|
167
|
-
ref
|
|
168
|
-
}) => {
|
|
169
|
-
context.core.image.imageLoaded = true;
|
|
170
|
-
context.core.image.imageCurrentSrc = ref.currentSrc;
|
|
171
|
-
effects.core.image.setButtonStyles({
|
|
172
|
-
context,
|
|
173
|
-
ref
|
|
127
|
+
// We need to add a scroll event listener to the window
|
|
128
|
+
// here because we are unable to otherwise access it via
|
|
129
|
+
// the Interactivity API directives. If we add a native way
|
|
130
|
+
// to access the window, we can remove this.
|
|
131
|
+
window.addEventListener('scroll', scrollCallback, false);
|
|
132
|
+
},
|
|
133
|
+
hideLightbox() {
|
|
134
|
+
const ctx = (0, _interactivity.getContext)();
|
|
135
|
+
ctx.hideAnimationEnabled = true;
|
|
136
|
+
if (ctx.lightboxEnabled) {
|
|
137
|
+
// We want to wait until the close animation is completed
|
|
138
|
+
// before allowing a user to scroll again. The duration of this
|
|
139
|
+
// animation is defined in the styles.scss and depends on if the
|
|
140
|
+
// animation is 'zoom' or 'fade', but in any case we should wait
|
|
141
|
+
// a few milliseconds longer than the duration, otherwise a user
|
|
142
|
+
// may scroll too soon and cause the animation to look sloppy.
|
|
143
|
+
setTimeout(function () {
|
|
144
|
+
window.removeEventListener('scroll', scrollCallback);
|
|
145
|
+
// If we don't delay before changing the focus,
|
|
146
|
+
// the focus ring will appear on Firefox before
|
|
147
|
+
// the image has finished animating, which looks broken.
|
|
148
|
+
ctx.lightboxTriggerRef.focus({
|
|
149
|
+
preventScroll: true
|
|
174
150
|
});
|
|
175
|
-
},
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
//
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
// to override or reset the scroll position during swipe actions.
|
|
189
|
-
if (context.core.image.lightboxEnabled) {
|
|
151
|
+
}, 450);
|
|
152
|
+
ctx.lightboxEnabled = false;
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
handleKeydown(event) {
|
|
156
|
+
const ctx = (0, _interactivity.getContext)();
|
|
157
|
+
if (ctx.lightboxEnabled) {
|
|
158
|
+
if (event.key === 'Tab' || event.keyCode === 9) {
|
|
159
|
+
// If shift + tab it change the direction
|
|
160
|
+
if (event.shiftKey && window.document.activeElement === ctx.firstFocusableElement) {
|
|
161
|
+
event.preventDefault();
|
|
162
|
+
ctx.lastFocusableElement.focus();
|
|
163
|
+
} else if (!event.shiftKey && window.document.activeElement === ctx.lastFocusableElement) {
|
|
190
164
|
event.preventDefault();
|
|
165
|
+
ctx.firstFocusableElement.focus();
|
|
191
166
|
}
|
|
192
|
-
},
|
|
193
|
-
handleTouchEnd: () => {
|
|
194
|
-
// We need to wait a few milliseconds before resetting
|
|
195
|
-
// to ensure that pinch to zoom works consistently
|
|
196
|
-
// on mobile devices when the lightbox is open.
|
|
197
|
-
lastTouchTime = Date.now();
|
|
198
|
-
isTouching = false;
|
|
199
167
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
},
|
|
203
|
-
selectors: {
|
|
204
|
-
core: {
|
|
205
|
-
image: {
|
|
206
|
-
roleAttribute: ({
|
|
207
|
-
context
|
|
208
|
-
}) => {
|
|
209
|
-
return context.core.image.lightboxEnabled ? 'dialog' : null;
|
|
210
|
-
},
|
|
211
|
-
ariaModal: ({
|
|
212
|
-
context
|
|
213
|
-
}) => {
|
|
214
|
-
return context.core.image.lightboxEnabled ? 'true' : null;
|
|
215
|
-
},
|
|
216
|
-
dialogLabel: ({
|
|
217
|
-
context
|
|
218
|
-
}) => {
|
|
219
|
-
return context.core.image.lightboxEnabled ? context.core.image.dialogLabel : null;
|
|
220
|
-
},
|
|
221
|
-
lightboxObjectFit: ({
|
|
222
|
-
context
|
|
223
|
-
}) => {
|
|
224
|
-
if (context.core.image.initialized) {
|
|
225
|
-
return 'cover';
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
enlargedImgSrc: ({
|
|
229
|
-
context
|
|
230
|
-
}) => {
|
|
231
|
-
return context.core.image.initialized ? context.core.image.imageUploadedSrc : 'data:image/gif;base64,R0lGODlhAQABAAD/ACwAAAAAAQABAAACADs=';
|
|
168
|
+
if (event.key === 'Escape' || event.keyCode === 27) {
|
|
169
|
+
actions.hideLightbox(event);
|
|
232
170
|
}
|
|
233
171
|
}
|
|
172
|
+
},
|
|
173
|
+
// This is fired just by lazily loaded
|
|
174
|
+
// images on the page, not all images.
|
|
175
|
+
handleLoad() {
|
|
176
|
+
const ctx = (0, _interactivity.getContext)();
|
|
177
|
+
const {
|
|
178
|
+
ref
|
|
179
|
+
} = (0, _interactivity.getElement)();
|
|
180
|
+
ctx.imageLoaded = true;
|
|
181
|
+
ctx.imageCurrentSrc = ref.currentSrc;
|
|
182
|
+
callbacks.setButtonStyles();
|
|
183
|
+
},
|
|
184
|
+
handleTouchStart() {
|
|
185
|
+
isTouching = true;
|
|
186
|
+
},
|
|
187
|
+
handleTouchMove(event) {
|
|
188
|
+
const ctx = (0, _interactivity.getContext)();
|
|
189
|
+
// On mobile devices, we want to prevent triggering the
|
|
190
|
+
// scroll event because otherwise the page jumps around as
|
|
191
|
+
// we reset the scroll position. This also means that closing
|
|
192
|
+
// the lightbox requires that a user perform a simple tap. This
|
|
193
|
+
// may be changed in the future if we find a better alternative
|
|
194
|
+
// to override or reset the scroll position during swipe actions.
|
|
195
|
+
if (ctx.lightboxEnabled) {
|
|
196
|
+
event.preventDefault();
|
|
197
|
+
}
|
|
198
|
+
},
|
|
199
|
+
handleTouchEnd() {
|
|
200
|
+
// We need to wait a few milliseconds before resetting
|
|
201
|
+
// to ensure that pinch to zoom works consistently
|
|
202
|
+
// on mobile devices when the lightbox is open.
|
|
203
|
+
lastTouchTime = Date.now();
|
|
204
|
+
isTouching = false;
|
|
234
205
|
}
|
|
235
206
|
},
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
207
|
+
callbacks: {
|
|
208
|
+
initOriginImage() {
|
|
209
|
+
const ctx = (0, _interactivity.getContext)();
|
|
210
|
+
const {
|
|
211
|
+
ref
|
|
212
|
+
} = (0, _interactivity.getElement)();
|
|
213
|
+
ctx.imageRef = ref;
|
|
214
|
+
ctx.lightboxTriggerRef = ref.parentElement.querySelector('.lightbox-trigger');
|
|
215
|
+
if (ref.complete) {
|
|
216
|
+
ctx.imageLoaded = true;
|
|
217
|
+
ctx.imageCurrentSrc = ref.currentSrc;
|
|
218
|
+
}
|
|
219
|
+
},
|
|
220
|
+
initLightbox() {
|
|
221
|
+
const ctx = (0, _interactivity.getContext)();
|
|
222
|
+
const {
|
|
223
|
+
ref
|
|
224
|
+
} = (0, _interactivity.getElement)();
|
|
225
|
+
if (ctx.lightboxEnabled) {
|
|
226
|
+
const focusableElements = ref.querySelectorAll(focusableSelectors);
|
|
227
|
+
ctx.firstFocusableElement = focusableElements[0];
|
|
228
|
+
ctx.lastFocusableElement = focusableElements[focusableElements.length - 1];
|
|
258
229
|
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
230
|
+
// Move focus to the dialog when opening it.
|
|
231
|
+
ref.focus();
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
setButtonStyles() {
|
|
235
|
+
const {
|
|
236
|
+
ref
|
|
237
|
+
} = (0, _interactivity.getElement)();
|
|
238
|
+
const {
|
|
239
|
+
naturalWidth,
|
|
240
|
+
naturalHeight,
|
|
241
|
+
offsetWidth,
|
|
242
|
+
offsetHeight
|
|
243
|
+
} = ref;
|
|
273
244
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
245
|
+
// If the image isn't loaded yet, we can't
|
|
246
|
+
// calculate where the button should be.
|
|
247
|
+
if (naturalWidth === 0 || naturalHeight === 0) {
|
|
248
|
+
return;
|
|
249
|
+
}
|
|
250
|
+
const figure = ref.parentElement;
|
|
251
|
+
const figureWidth = ref.parentElement.clientWidth;
|
|
281
252
|
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
253
|
+
// We need special handling for the height because
|
|
254
|
+
// a caption will cause the figure to be taller than
|
|
255
|
+
// the image, which means we need to account for that
|
|
256
|
+
// when calculating the placement of the button in the
|
|
257
|
+
// top right corner of the image.
|
|
258
|
+
let figureHeight = ref.parentElement.clientHeight;
|
|
259
|
+
const caption = figure.querySelector('figcaption');
|
|
260
|
+
if (caption) {
|
|
261
|
+
const captionComputedStyle = window.getComputedStyle(caption);
|
|
262
|
+
if (!['absolute', 'fixed'].includes(captionComputedStyle.position)) {
|
|
263
|
+
figureHeight = figureHeight - caption.offsetHeight - parseFloat(captionComputedStyle.marginTop) - parseFloat(captionComputedStyle.marginBottom);
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
const buttonOffsetTop = figureHeight - offsetHeight;
|
|
267
|
+
const buttonOffsetRight = figureWidth - offsetWidth;
|
|
268
|
+
const ctx = (0, _interactivity.getContext)();
|
|
295
269
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
} else {
|
|
318
|
-
context.core.image.imageButtonTop = buttonOffsetTop + 10;
|
|
319
|
-
context.core.image.imageButtonRight = buttonOffsetRight + 10;
|
|
320
|
-
}
|
|
321
|
-
},
|
|
322
|
-
setStylesOnResize: ({
|
|
323
|
-
state,
|
|
324
|
-
context,
|
|
325
|
-
ref
|
|
326
|
-
}) => {
|
|
327
|
-
if (context.core.image.lightboxEnabled && (state.core.image.windowWidth || state.core.image.windowHeight)) {
|
|
328
|
-
setStyles(context, ref);
|
|
329
|
-
}
|
|
270
|
+
// In the case of an image with object-fit: contain, the
|
|
271
|
+
// size of the <img> element can be larger than the image itself,
|
|
272
|
+
// so we need to calculate where to place the button.
|
|
273
|
+
if (ctx.scaleAttr === 'contain') {
|
|
274
|
+
// Natural ratio of the image.
|
|
275
|
+
const naturalRatio = naturalWidth / naturalHeight;
|
|
276
|
+
// Offset ratio of the image.
|
|
277
|
+
const offsetRatio = offsetWidth / offsetHeight;
|
|
278
|
+
if (naturalRatio >= offsetRatio) {
|
|
279
|
+
// If it reaches the width first, keep
|
|
280
|
+
// the width and compute the height.
|
|
281
|
+
const referenceHeight = offsetWidth / naturalRatio;
|
|
282
|
+
ctx.imageButtonTop = (offsetHeight - referenceHeight) / 2 + buttonOffsetTop + 16;
|
|
283
|
+
ctx.imageButtonRight = buttonOffsetRight + 16;
|
|
284
|
+
} else {
|
|
285
|
+
// If it reaches the height first, keep
|
|
286
|
+
// the height and compute the width.
|
|
287
|
+
const referenceWidth = offsetHeight * naturalRatio;
|
|
288
|
+
ctx.imageButtonTop = buttonOffsetTop + 16;
|
|
289
|
+
ctx.imageButtonRight = (offsetWidth - referenceWidth) / 2 + buttonOffsetRight + 16;
|
|
330
290
|
}
|
|
291
|
+
} else {
|
|
292
|
+
ctx.imageButtonTop = buttonOffsetTop + 16;
|
|
293
|
+
ctx.imageButtonRight = buttonOffsetRight + 16;
|
|
294
|
+
}
|
|
295
|
+
},
|
|
296
|
+
setStylesOnResize() {
|
|
297
|
+
const ctx = (0, _interactivity.getContext)();
|
|
298
|
+
const {
|
|
299
|
+
ref
|
|
300
|
+
} = (0, _interactivity.getElement)();
|
|
301
|
+
if (ctx.lightboxEnabled && (state.windowWidth || state.windowHeight)) {
|
|
302
|
+
setStyles(ctx, ref);
|
|
331
303
|
}
|
|
332
304
|
}
|
|
333
305
|
}
|
|
334
|
-
}, {
|
|
335
|
-
afterLoad: ({
|
|
336
|
-
state
|
|
337
|
-
}) => {
|
|
338
|
-
window.addEventListener('resize', debounce(() => {
|
|
339
|
-
state.core.image.windowWidth = window.innerWidth;
|
|
340
|
-
state.core.image.windowHeight = window.innerHeight;
|
|
341
|
-
}));
|
|
342
|
-
}
|
|
343
306
|
});
|
|
307
|
+
window.addEventListener('resize', debounce(() => {
|
|
308
|
+
state.windowWidth = window.innerWidth;
|
|
309
|
+
state.windowHeight = window.innerHeight;
|
|
310
|
+
}));
|
|
344
311
|
|
|
345
|
-
|
|
312
|
+
/**
|
|
346
313
|
* Computes styles for the lightbox and adds them to the document.
|
|
347
314
|
*
|
|
348
315
|
* @function
|
|
349
|
-
* @param {Object}
|
|
350
|
-
* @param {Object}
|
|
316
|
+
* @param {Object} ctx - Context for the `core/image` namespace.
|
|
317
|
+
* @param {Object} ref - The element reference.
|
|
351
318
|
*/
|
|
352
|
-
function setStyles(
|
|
319
|
+
function setStyles(ctx, ref) {
|
|
353
320
|
// The reference img element lies adjacent
|
|
354
321
|
// to the event target button in the DOM.
|
|
355
322
|
let {
|
|
@@ -370,7 +337,7 @@ function setStyles(context, ref) {
|
|
|
370
337
|
|
|
371
338
|
// If it has object-fit: contain, recalculate the original sizes
|
|
372
339
|
// and the screen position without the blank spaces.
|
|
373
|
-
if (
|
|
340
|
+
if (ctx.scaleAttr === 'contain') {
|
|
374
341
|
if (naturalRatio > originalRatio) {
|
|
375
342
|
const heightWithoutSpace = originalWidth / naturalRatio;
|
|
376
343
|
// Recalculate screen position without the top space.
|
|
@@ -389,8 +356,8 @@ function setStyles(context, ref) {
|
|
|
389
356
|
// dimensions have not been set (i.e. an external image with only one size),
|
|
390
357
|
// the image's dimensions in the lightbox are the same
|
|
391
358
|
// as those of the image in the content.
|
|
392
|
-
let imgMaxWidth = parseFloat(
|
|
393
|
-
let imgMaxHeight = parseFloat(
|
|
359
|
+
let imgMaxWidth = parseFloat(ctx.targetWidth !== 'none' ? ctx.targetWidth : naturalWidth);
|
|
360
|
+
let imgMaxHeight = parseFloat(ctx.targetHeight !== 'none' ? ctx.targetHeight : naturalHeight);
|
|
394
361
|
|
|
395
362
|
// Ratio of the biggest image stored in the database.
|
|
396
363
|
let imgRatio = imgMaxWidth / imgMaxHeight;
|
|
@@ -496,16 +463,17 @@ function setStyles(context, ref) {
|
|
|
496
463
|
--wp--lightbox-image-width: ${lightboxImgWidth}px;
|
|
497
464
|
--wp--lightbox-image-height: ${lightboxImgHeight}px;
|
|
498
465
|
--wp--lightbox-scale: ${containerScale};
|
|
466
|
+
--wp--lightbox-scrollbar-width: ${window.innerWidth - document.documentElement.clientWidth}px;
|
|
499
467
|
}
|
|
500
468
|
`;
|
|
501
469
|
}
|
|
502
470
|
|
|
503
|
-
|
|
471
|
+
/**
|
|
504
472
|
* Debounces a function call.
|
|
505
473
|
*
|
|
506
474
|
* @function
|
|
507
475
|
* @param {Function} func - A function to be called
|
|
508
|
-
* @param {number}
|
|
476
|
+
* @param {number} wait - The time to wait before calling the function
|
|
509
477
|
*/
|
|
510
478
|
function debounce(func, wait = 50) {
|
|
511
479
|
let timeout;
|