← All changes
|
assets/js/background-video-preview-handler.js
+11
-4
4.3.0-beta2
→
4.3.1
View file →
| @@ -16,13 +16,16 @@ | ||
| 16 | 16 | var require_editor_background_video_state = /* @__PURE__ */ __commonJSMin(((exports) => { |
| 17 | 17 | Object.defineProperty(exports, "__esModule", { value: true }); |
| 18 | 18 | exports.getEditorState = getEditorState; |
| 19 | 19 | exports.isEditorPreview = isEditorPreview; |
| 20 | + exports.resolveDesignTimeState = resolveDesignTimeState; | |
| 20 | 21 | exports.setEditorState = setEditorState; |
| 21 | 22 | var _alpinejs$2 = (globalThis.elementorV2.alpinejs); |
| 22 | 23 | var STORE_NAME = "editor-background-video-state"; |
| 24 | + var PLAYING_STATE = "playing"; | |
| 25 | + var PAUSED_STATE = "paused"; | |
| 23 | 26 | /** |
| 24 | - * @typedef {Record<string, 'playing' | 'paused'>} BackgroundVideoState | |
| 27 | + * @typedef {Record<string, 'playing' | 'paused' | ''>} BackgroundVideoState | |
| 25 | 28 | */ |
| 26 | 29 | function ensureStore() { |
| 27 | 30 | if (!_alpinejs$2.Alpine.store(STORE_NAME)) _alpinejs$2.Alpine.store( |
| 28 | 31 | STORE_NAME, |
| @@ -30,9 +33,13 @@ | ||
| 30 | 33 | {} |
| 31 | 34 | ); |
| 32 | 35 | return _alpinejs$2.Alpine.store(STORE_NAME); |
| 33 | 36 | } |
| 34 | - function getEditorState(elementId, fallback = "playing") { | |
| 37 | + function resolveDesignTimeState(state) { | |
| 38 | + if (PAUSED_STATE === state || "" === state) return state; | |
| 39 | + return PLAYING_STATE; | |
| 40 | + } | |
| 41 | + function getEditorState(elementId, fallback = PLAYING_STATE) { | |
| 35 | 42 | var _store$elementId; |
| 36 | 43 | return (_store$elementId = ensureStore()[elementId]) !== null && _store$elementId !== void 0 ? _store$elementId : fallback; |
| 37 | 44 | } |
| 38 | 45 | function setEditorState(elementId, state) { |
| @@ -95,9 +102,9 @@ | ||
| 95 | 102 | _alpinejs$1.Alpine.data(`eBackgroundVideo${elementId}`, () => ({ |
| 96 | 103 | isPlaying: video ? !video.paused : false, |
| 97 | 104 | isEditor: (0, _editorBackgroundVideoState.isEditorPreview)(), |
| 98 | 105 | get editorState() { |
| 99 | - return (0, _editorBackgroundVideoState.getEditorState)(elementId, settings.state || "playing"); | |
| 106 | + return (0, _editorBackgroundVideoState.getEditorState)(elementId, (0, _editorBackgroundVideoState.resolveDesignTimeState)(settings.state)); | |
| 100 | 107 | }, |
| 101 | 108 | get previewState() { |
| 102 | 109 | if (this.isEditor) return this.editorState; |
| 103 | 110 | return this.isPlaying ? "playing" : "paused"; |
| @@ -161,9 +168,9 @@ | ||
| 161 | 168 | elementType: "e-background-video", |
| 162 | 169 | id: "e-background-video-preview-handler", |
| 163 | 170 | callback: ({ element, settings, listenToChildren }) => { |
| 164 | 171 | const elementId = element.dataset.id; |
| 165 | - (0, _editorBackgroundVideoState.setEditorState)(elementId, settings.state || "playing"); | |
| 172 | + (0, _editorBackgroundVideoState.setEditorState)(elementId, (0, _editorBackgroundVideoState.resolveDesignTimeState)(settings.state)); | |
| 166 | 173 | (0, _alpinejs.refreshTree)(element); |
| 167 | 174 | listenToChildren([ |
| 168 | 175 | _backgroundVideoHandler.PLAY_ELEMENT_TYPE, |
| 169 | 176 | _backgroundVideoHandler.PAUSE_ELEMENT_TYPE, |