Naotoshi Fujita 2 gadi atpakaļ
vecāks
revīzija
9cdf587c53

+ 1 - 1
dist/js/splide-renderer.min.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 4.0.13
+ * Version  : 4.0.14
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */

+ 2 - 2
dist/js/splide.cjs.js

@@ -1,6 +1,6 @@
 /*!
  * Splide.js
- * Version  : 4.0.13
+ * Version  : 4.0.14
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */
@@ -1646,7 +1646,7 @@ function Controller(Splide2, Components2, options) {
   }
 
   function computeDestIndex(dest, from, snapPage) {
-    if (isEnough()) {
+    if (isEnough() || hasFocus()) {
       var end = getEnd();
       var index = computeMovableDestIndex(dest);
 

+ 2 - 2
dist/js/splide.esm.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 /*!
  * Splide.js
- * Version  : 4.0.13
+ * Version  : 4.0.14
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */
@@ -1641,7 +1641,7 @@ function Controller(Splide2, Components2, options) {
   }
 
   function computeDestIndex(dest, from, snapPage) {
-    if (isEnough()) {
+    if (isEnough() || hasFocus()) {
       var end = getEnd();
       var index = computeMovableDestIndex(dest);
 

+ 2 - 2
dist/js/splide.js

@@ -4,7 +4,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
 
 /*!
  * Splide.js
- * Version  : 4.0.13
+ * Version  : 4.0.14
  * License  : MIT
  * Copyright: 2022 Naotoshi Fujita
  */
@@ -1639,7 +1639,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
     }
 
     function computeDestIndex(dest, from, snapPage) {
-      if (isEnough()) {
+      if (isEnough() || hasFocus()) {
         var end = getEnd();
         var index = computeMovableDestIndex(dest);
 

Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 1 - 1
dist/js/splide.min.js


BIN
dist/js/splide.min.js.gz


Failā izmaiņas netiks attēlotas, jo tās ir par lielu
+ 0 - 0
dist/js/splide.min.js.map


+ 2 - 2
package-lock.json

@@ -1,12 +1,12 @@
 {
   "name": "@splidejs/splide",
-  "version": "4.0.12",
+  "version": "4.0.14",
   "lockfileVersion": 2,
   "requires": true,
   "packages": {
     "": {
       "name": "@splidejs/splide",
-      "version": "4.0.12",
+      "version": "4.0.14",
       "license": "MIT",
       "devDependencies": {
         "@babel/core": "^7.18.13",

+ 1 - 1
package.json

@@ -1,6 +1,6 @@
 {
   "name": "@splidejs/splide",
-  "version": "4.0.13",
+  "version": "4.0.14",
   "description": "Splide is a lightweight, flexible and accessible slider/carousel. No dependencies, no Lighthouse errors.",
   "author": "Naotoshi Fujita",
   "license": "MIT",

+ 5 - 4
src/js/components/Controller/Controller.ts

@@ -193,16 +193,17 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
    * - If the `move` option is `true`, finds the dest index whose position is different with the current one.
    * - This may return clone indices if the editor is the loop mode,
    *   or `-1` if there is no slide to go.
-   * - There are still slides where the slider can go if borders are between `from` and `dest`.
+   * - There are still slides where the carousel can go if borders are between `from` and `dest`.
+   * - If `focus` is available, needs to calculate the dest index even if there are enough number of slides.
    *
-   * @param dest     - The desired destination.
+   * @param dest     - The desired destination index.
    * @param from     - A base index.
    * @param snapPage - Optional. Whether to snap a page or not.
    *
    * @return A converted destination index, including clones.
    */
   function computeDestIndex( dest: number, from: number, snapPage?: boolean ): number {
-    if ( isEnough() ) {
+    if ( isEnough() || hasFocus() ) {
       const end   = getEnd();
       const index = computeMovableDestIndex( dest );
 
@@ -239,7 +240,7 @@ export function Controller( Splide: Splide, Components: Components, options: Opt
   }
 
   /**
-   * Finds the dest index whose position is different with the current one.
+   * Finds the dest index whose position is different with the current one for `trimSpace: 'move'`.
    * This can be negative or greater than `length - 1`.
    *
    * @param dest - A dest index.

+ 26 - 0
src/js/components/Controller/test/getAdjacent.test.ts

@@ -92,4 +92,30 @@ describe( 'Controller#getAdjacent()', () => {
     expect( Controller.getNext() ).toBe( 0 );
     expect( Controller.getPrev() ).toBe( splide.length - 2 );
   } );
+
+  test( 'should return -1 if there are not enough slides.', () => {
+    const splide = init( { perPage: 3 }, { length: 3 } );
+    const { Controller } = splide.Components;
+
+    expect( Controller.getNext() ).toBe( -1 );
+    expect( Controller.getPrev() ).toBe( -1 );
+
+    splide.go( 1 );
+
+    expect( Controller.getNext() ).toBe( -1 );
+    expect( Controller.getPrev() ).toBe( -1 );
+  } );
+
+  test( 'should return adjacent indices if there are not enough slides but `focus` is provided.', () => {
+    const splide = init( { perPage: 3, focus: 'center' }, { length: 3 } );
+    const { Controller } = splide.Components;
+
+    expect( Controller.getNext() ).toBe( 1 );
+    expect( Controller.getPrev() ).toBe( -1 );
+
+    splide.go( 1 );
+
+    expect( Controller.getNext() ).toBe( 2 );
+    expect( Controller.getPrev() ).toBe( 0 );
+  } );
 } );

+ 3 - 3
src/js/test/assets/css/styles.css

@@ -30,9 +30,9 @@ img {
   border: 2px solid darkgray;
 }
 
-/*.splide__slide.is-active {*/
-/*  border: 2px solid yellowgreen;*/
-/*}*/
+.splide__slide.is-active {
+  border: 2px solid yellowgreen;
+}
 
 /*.splide__slide:focus, .splide__arrow:focus, .splide__pagination__page:focus {*/
 /*  border: 2px solid tomato !important;*/

Daži faili netika attēloti, jo izmaiņu fails ir pārāk liels