|
1 | 1 | /** |
2 | | - * svelte-range-slider-pips ~ 1.8.0 |
| 2 | + * svelte-range-slider-pips ~ 1.8.1 |
3 | 3 | * Multi-Thumb, Accessible, Beautiful Range Slider with Pips |
4 | 4 | * © MPL-2.0 ~ Simon Goellner <[email protected]> ~ 24/7/2021 |
5 | 5 | */ |
|
1347 | 1347 |
|
1348 | 1348 | function get_each_context$1(ctx, list, i) { |
1349 | 1349 | const child_ctx = ctx.slice(); |
1350 | | - child_ctx[59] = list[i]; |
1351 | | - child_ctx[61] = i; |
| 1350 | + child_ctx[60] = list[i]; |
| 1351 | + child_ctx[62] = i; |
1352 | 1352 | return child_ctx; |
1353 | 1353 | } |
1354 | 1354 |
|
1355 | | - // (768:6) {#if float} |
| 1355 | + // (779:6) {#if float} |
1356 | 1356 | function create_if_block_2$1(ctx) { |
1357 | 1357 | let span; |
1358 | | - let t_value = /*handleFormatter*/ ctx[19](/*value*/ ctx[59], /*index*/ ctx[61]) + ""; |
| 1358 | + let t_value = /*handleFormatter*/ ctx[19](/*value*/ ctx[60], /*index*/ ctx[62]) + ""; |
1359 | 1359 | let t; |
1360 | 1360 | let if_block0 = /*prefix*/ ctx[16] && create_if_block_4$1(ctx); |
1361 | 1361 | let if_block1 = /*suffix*/ ctx[17] && create_if_block_3$1(ctx); |
|
1388 | 1388 | if_block0 = null; |
1389 | 1389 | } |
1390 | 1390 |
|
1391 | | - if (dirty[0] & /*handleFormatter, values*/ 524289 && t_value !== (t_value = /*handleFormatter*/ ctx[19](/*value*/ ctx[59], /*index*/ ctx[61]) + "")) set_data(t, t_value); |
| 1391 | + if (dirty[0] & /*handleFormatter, values*/ 524289 && t_value !== (t_value = /*handleFormatter*/ ctx[19](/*value*/ ctx[60], /*index*/ ctx[62]) + "")) set_data(t, t_value); |
1392 | 1392 |
|
1393 | 1393 | if (/*suffix*/ ctx[17]) { |
1394 | 1394 | if (if_block1) { |
|
1411 | 1411 | }; |
1412 | 1412 | } |
1413 | 1413 |
|
1414 | | - // (770:10) {#if prefix} |
| 1414 | + // (781:10) {#if prefix} |
1415 | 1415 | function create_if_block_4$1(ctx) { |
1416 | 1416 | let span; |
1417 | 1417 | let t; |
|
1435 | 1435 | }; |
1436 | 1436 | } |
1437 | 1437 |
|
1438 | | - // (770:104) {#if suffix} |
| 1438 | + // (781:104) {#if suffix} |
1439 | 1439 | function create_if_block_3$1(ctx) { |
1440 | 1440 | let span; |
1441 | 1441 | let t; |
|
1459 | 1459 | }; |
1460 | 1460 | } |
1461 | 1461 |
|
1462 | | - // (746:2) {#each values as value, index} |
| 1462 | + // (757:2) {#each values as value, index} |
1463 | 1463 | function create_each_block$1(ctx) { |
1464 | 1464 | let span1; |
1465 | 1465 | let span0; |
|
1483 | 1483 | t = space(); |
1484 | 1484 | if (if_block) if_block.c(); |
1485 | 1485 | attr(span0, "class", "rangeNub"); |
1486 | | - attr(span1, "style", span1_style_value = "" + ((/*vertical*/ ctx[5] ? "top" : "left") + ": " + /*$springPositions*/ ctx[26][/*index*/ ctx[61]] + "%; z-index: " + (/*activeHandle*/ ctx[23] === /*index*/ ctx[61] ? 3 : 2) + ";")); |
| 1486 | + attr(span1, "style", span1_style_value = "" + ((/*vertical*/ ctx[5] ? "top" : "left") + ": " + /*$springPositions*/ ctx[26][/*index*/ ctx[62]] + "%; z-index: " + (/*activeHandle*/ ctx[23] === /*index*/ ctx[62] ? 3 : 2) + ";")); |
1487 | 1487 | attr(span1, "role", "slider"); |
1488 | | - attr(span1, "data-handle", span1_data_handle_value = /*index*/ ctx[61]); |
| 1488 | + attr(span1, "data-handle", span1_data_handle_value = /*index*/ ctx[62]); |
1489 | 1489 | attr(span1, "class", "rangeHandle"); |
1490 | 1490 |
|
1491 | | - attr(span1, "aria-valuemin", span1_aria_valuemin_value = /*range*/ ctx[1] === true && /*index*/ ctx[61] === 1 |
| 1491 | + attr(span1, "aria-valuemin", span1_aria_valuemin_value = /*range*/ ctx[1] === true && /*index*/ ctx[62] === 1 |
1492 | 1492 | ? /*values*/ ctx[0][0] |
1493 | 1493 | : /*min*/ ctx[2]); |
1494 | 1494 |
|
1495 | | - attr(span1, "aria-valuemax", span1_aria_valuemax_value = /*range*/ ctx[1] === true && /*index*/ ctx[61] === 0 |
| 1495 | + attr(span1, "aria-valuemax", span1_aria_valuemax_value = /*range*/ ctx[1] === true && /*index*/ ctx[62] === 0 |
1496 | 1496 | ? /*values*/ ctx[0][1] |
1497 | 1497 | : /*max*/ ctx[3]); |
1498 | 1498 |
|
1499 | | - attr(span1, "aria-valuenow", span1_aria_valuenow_value = /*value*/ ctx[59]); |
1500 | | - attr(span1, "aria-valuetext", span1_aria_valuetext_value = "" + (/*prefix*/ ctx[16] + /*handleFormatter*/ ctx[19](/*value*/ ctx[59], /*index*/ ctx[61]) + /*suffix*/ ctx[17])); |
| 1499 | + attr(span1, "aria-valuenow", span1_aria_valuenow_value = /*value*/ ctx[60]); |
| 1500 | + attr(span1, "aria-valuetext", span1_aria_valuetext_value = "" + (/*prefix*/ ctx[16] + /*handleFormatter*/ ctx[19](/*value*/ ctx[60], /*index*/ ctx[62]) + /*suffix*/ ctx[17])); |
1501 | 1501 | attr(span1, "aria-orientation", span1_aria_orientation_value = /*vertical*/ ctx[5] ? "vertical" : "horizontal"); |
1502 | 1502 | attr(span1, "aria-disabled", /*disabled*/ ctx[8]); |
1503 | 1503 | attr(span1, "disabled", /*disabled*/ ctx[8]); |
1504 | 1504 | attr(span1, "tabindex", span1_tabindex_value = /*disabled*/ ctx[8] ? -1 : 0); |
1505 | 1505 | toggle_class(span1, "hoverable", /*hover*/ ctx[7] && !/*disabled*/ ctx[8]); |
1506 | | - toggle_class(span1, "active", /*focus*/ ctx[21] && /*activeHandle*/ ctx[23] === /*index*/ ctx[61]); |
1507 | | - toggle_class(span1, "press", /*handlePressed*/ ctx[22] && /*activeHandle*/ ctx[23] === /*index*/ ctx[61]); |
| 1506 | + toggle_class(span1, "active", /*focus*/ ctx[21] && /*activeHandle*/ ctx[23] === /*index*/ ctx[62]); |
| 1507 | + toggle_class(span1, "press", /*handlePressed*/ ctx[22] && /*activeHandle*/ ctx[23] === /*index*/ ctx[62]); |
1508 | 1508 | }, |
1509 | 1509 | m(target, anchor) { |
1510 | 1510 | insert(target, span1, anchor); |
|
1536 | 1536 | if_block = null; |
1537 | 1537 | } |
1538 | 1538 |
|
1539 | | - if (dirty[0] & /*vertical, $springPositions, activeHandle*/ 75497504 && span1_style_value !== (span1_style_value = "" + ((/*vertical*/ ctx[5] ? "top" : "left") + ": " + /*$springPositions*/ ctx[26][/*index*/ ctx[61]] + "%; z-index: " + (/*activeHandle*/ ctx[23] === /*index*/ ctx[61] ? 3 : 2) + ";"))) { |
| 1539 | + if (dirty[0] & /*vertical, $springPositions, activeHandle*/ 75497504 && span1_style_value !== (span1_style_value = "" + ((/*vertical*/ ctx[5] ? "top" : "left") + ": " + /*$springPositions*/ ctx[26][/*index*/ ctx[62]] + "%; z-index: " + (/*activeHandle*/ ctx[23] === /*index*/ ctx[62] ? 3 : 2) + ";"))) { |
1540 | 1540 | attr(span1, "style", span1_style_value); |
1541 | 1541 | } |
1542 | 1542 |
|
1543 | | - if (dirty[0] & /*range, values, min*/ 7 && span1_aria_valuemin_value !== (span1_aria_valuemin_value = /*range*/ ctx[1] === true && /*index*/ ctx[61] === 1 |
| 1543 | + if (dirty[0] & /*range, values, min*/ 7 && span1_aria_valuemin_value !== (span1_aria_valuemin_value = /*range*/ ctx[1] === true && /*index*/ ctx[62] === 1 |
1544 | 1544 | ? /*values*/ ctx[0][0] |
1545 | 1545 | : /*min*/ ctx[2])) { |
1546 | 1546 | attr(span1, "aria-valuemin", span1_aria_valuemin_value); |
1547 | 1547 | } |
1548 | 1548 |
|
1549 | | - if (dirty[0] & /*range, values, max*/ 11 && span1_aria_valuemax_value !== (span1_aria_valuemax_value = /*range*/ ctx[1] === true && /*index*/ ctx[61] === 0 |
| 1549 | + if (dirty[0] & /*range, values, max*/ 11 && span1_aria_valuemax_value !== (span1_aria_valuemax_value = /*range*/ ctx[1] === true && /*index*/ ctx[62] === 0 |
1550 | 1550 | ? /*values*/ ctx[0][1] |
1551 | 1551 | : /*max*/ ctx[3])) { |
1552 | 1552 | attr(span1, "aria-valuemax", span1_aria_valuemax_value); |
1553 | 1553 | } |
1554 | 1554 |
|
1555 | | - if (dirty[0] & /*values*/ 1 && span1_aria_valuenow_value !== (span1_aria_valuenow_value = /*value*/ ctx[59])) { |
| 1555 | + if (dirty[0] & /*values*/ 1 && span1_aria_valuenow_value !== (span1_aria_valuenow_value = /*value*/ ctx[60])) { |
1556 | 1556 | attr(span1, "aria-valuenow", span1_aria_valuenow_value); |
1557 | 1557 | } |
1558 | 1558 |
|
1559 | | - if (dirty[0] & /*prefix, handleFormatter, values, suffix*/ 720897 && span1_aria_valuetext_value !== (span1_aria_valuetext_value = "" + (/*prefix*/ ctx[16] + /*handleFormatter*/ ctx[19](/*value*/ ctx[59], /*index*/ ctx[61]) + /*suffix*/ ctx[17]))) { |
| 1559 | + if (dirty[0] & /*prefix, handleFormatter, values, suffix*/ 720897 && span1_aria_valuetext_value !== (span1_aria_valuetext_value = "" + (/*prefix*/ ctx[16] + /*handleFormatter*/ ctx[19](/*value*/ ctx[60], /*index*/ ctx[62]) + /*suffix*/ ctx[17]))) { |
1560 | 1560 | attr(span1, "aria-valuetext", span1_aria_valuetext_value); |
1561 | 1561 | } |
1562 | 1562 |
|
|
1581 | 1581 | } |
1582 | 1582 |
|
1583 | 1583 | if (dirty[0] & /*focus, activeHandle*/ 10485760) { |
1584 | | - toggle_class(span1, "active", /*focus*/ ctx[21] && /*activeHandle*/ ctx[23] === /*index*/ ctx[61]); |
| 1584 | + toggle_class(span1, "active", /*focus*/ ctx[21] && /*activeHandle*/ ctx[23] === /*index*/ ctx[62]); |
1585 | 1585 | } |
1586 | 1586 |
|
1587 | 1587 | if (dirty[0] & /*handlePressed, activeHandle*/ 12582912) { |
1588 | | - toggle_class(span1, "press", /*handlePressed*/ ctx[22] && /*activeHandle*/ ctx[23] === /*index*/ ctx[61]); |
| 1588 | + toggle_class(span1, "press", /*handlePressed*/ ctx[22] && /*activeHandle*/ ctx[23] === /*index*/ ctx[62]); |
1589 | 1589 | } |
1590 | 1590 | }, |
1591 | 1591 | d(detaching) { |
|
1597 | 1597 | }; |
1598 | 1598 | } |
1599 | 1599 |
|
1600 | | - // (775:2) {#if range} |
| 1600 | + // (786:2) {#if range} |
1601 | 1601 | function create_if_block_1$1(ctx) { |
1602 | 1602 | let span; |
1603 | 1603 | let span_style_value; |
|
1622 | 1622 | }; |
1623 | 1623 | } |
1624 | 1624 |
|
1625 | | - // (781:2) {#if pips} |
| 1625 | + // (792:2) {#if pips} |
1626 | 1626 | function create_if_block$1(ctx) { |
1627 | 1627 | let rangepips; |
1628 | 1628 | let current; |
|
1644 | 1644 | suffix: /*suffix*/ ctx[17], |
1645 | 1645 | formatter: /*formatter*/ ctx[18], |
1646 | 1646 | focus: /*focus*/ ctx[21], |
1647 | | - disabled: /*disabled*/ ctx[8], |
1648 | 1647 | percentOf: /*percentOf*/ ctx[25] |
1649 | 1648 | } |
1650 | 1649 | }); |
|
1674 | 1673 | if (dirty[0] & /*suffix*/ 131072) rangepips_changes.suffix = /*suffix*/ ctx[17]; |
1675 | 1674 | if (dirty[0] & /*formatter*/ 262144) rangepips_changes.formatter = /*formatter*/ ctx[18]; |
1676 | 1675 | if (dirty[0] & /*focus*/ 2097152) rangepips_changes.focus = /*focus*/ ctx[21]; |
1677 | | - if (dirty[0] & /*disabled*/ 256) rangepips_changes.disabled = /*disabled*/ ctx[8]; |
1678 | 1676 | if (dirty[0] & /*percentOf*/ 33554432) rangepips_changes.percentOf = /*percentOf*/ ctx[25]; |
1679 | 1677 | rangepips.$set(rangepips_changes); |
1680 | 1678 | }, |
|
1944 | 1942 | let slider; |
1945 | 1943 |
|
1946 | 1944 | // state management |
1947 | | - let focus = false; |
| 1945 | + let valueLength = 0; |
1948 | 1946 |
|
| 1947 | + let focus = false; |
1949 | 1948 | let handleActivated = false; |
1950 | 1949 | let handlePressed = false; |
1951 | 1950 | let keyboardActive = false; |
|
2409 | 2408 | * @param {number} val the value to clamp |
2410 | 2409 | * @return {number} the value after it's been clamped |
2411 | 2410 | **/ |
2412 | | - $$invalidate(48, clampValue = function (val) { |
| 2411 | + $$invalidate(49, clampValue = function (val) { |
2413 | 2412 | // return the min/max if outside of that range |
2414 | 2413 | return val <= min ? min : val >= max ? max : val; |
2415 | 2414 | }); |
2416 | 2415 | } |
2417 | 2416 |
|
2418 | | - if ($$self.$$.dirty[0] & /*min, max, step*/ 28 | $$self.$$.dirty[1] & /*clampValue, precision*/ 131584) { |
| 2417 | + if ($$self.$$.dirty[0] & /*min, max, step*/ 28 | $$self.$$.dirty[1] & /*clampValue, precision*/ 262656) { |
2419 | 2418 | /** |
2420 | 2419 | * align the value with the steps so that it |
2421 | 2420 | * always sits on the closest (above/below) step |
2422 | 2421 | * @param {number} val the value to align |
2423 | 2422 | * @return {number} the value after it's been aligned |
2424 | 2423 | **/ |
2425 | | - $$invalidate(47, alignValueToStep = function (val) { |
| 2424 | + $$invalidate(48, alignValueToStep = function (val) { |
2426 | 2425 | // sanity check for performance |
2427 | 2426 | if (val <= min) { |
2428 | 2427 | return min; |
|
2471 | 2470 | }); |
2472 | 2471 | } |
2473 | 2472 |
|
2474 | | - if ($$self.$$.dirty[0] & /*values, max, min, springPositions, percentOf*/ 50331661 | $$self.$$.dirty[1] & /*alignValueToStep, springValues*/ 66560) { |
| 2473 | + if ($$self.$$.dirty[0] & /*values, max, min, percentOf, springPositions*/ 50331661 | $$self.$$.dirty[1] & /*alignValueToStep, valueLength, springValues*/ 136192) { |
2475 | 2474 | { |
2476 | 2475 | // check that "values" is an array, or set it as array |
2477 | 2476 | // to prevent any errors in springs, or range trimming |
|
2480 | 2479 | console.error("'values' prop should be an Array (https://github.com/simeydotme/svelte-range-slider-pips#slider-props)"); |
2481 | 2480 | } |
2482 | 2481 |
|
2483 | | - // trim the range as needed |
2484 | | - $$invalidate(0, values = trimRange(values)); |
| 2482 | + // trim the range so it remains as a min/max (only 2 handles) |
| 2483 | + // and also align the handles to the steps |
| 2484 | + $$invalidate(0, values = trimRange(values.map(v => alignValueToStep(v)))); |
2485 | 2485 |
|
2486 | | - // clamp the values to the steps and boundaries set up in the slider |
2487 | | - $$invalidate(0, values = values.map(v => alignValueToStep(v))); |
2488 | | - |
2489 | | - // update the spring function so that movement can happen in the UI |
2490 | | - if (springPositions) { |
2491 | | - springPositions.set(values.map(v => percentOf(v))); |
2492 | | - } else { |
| 2486 | + // check if the valueLength (length of values[]) has changed, |
| 2487 | + // because if so we need to re-seed the spring function with the |
| 2488 | + // new values array. |
| 2489 | + if (valueLength !== values.length) { |
| 2490 | + // set the initial spring values when the slider initialises, |
| 2491 | + // or when values array length has changed |
2493 | 2492 | $$subscribe_springPositions($$invalidate(24, springPositions = spring(values.map(v => percentOf(v)), springValues))); |
| 2493 | + } else { |
| 2494 | + // update the value of the spring function for animated handles |
| 2495 | + // whenever the values has updated |
| 2496 | + springPositions.set(values.map(v => percentOf(v))); |
2494 | 2497 | } |
| 2498 | + |
| 2499 | + // set the valueLength for the next check |
| 2500 | + $$invalidate(43, valueLength = values.length); |
2495 | 2501 | } |
2496 | 2502 | } |
2497 | 2503 | }; |
|
2579 | 2585 | precision: 40, |
2580 | 2586 | springValues: 41 |
2581 | 2587 | }, |
2582 | | - [-1, -1] |
| 2588 | + [-1, -1, -1] |
2583 | 2589 | ); |
2584 | 2590 | } |
2585 | 2591 | } |
|
0 commit comments