Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 | 2x 2x 2x 2x 6x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 438x 438x 438x 438x 438x 438x 438x 438x 438x 438x 438x 438x 438x 2x 10x 10x 10x 10x 6x 6x 10x 6x 6x 6x 6x 6x 4x 4x 294x 286x 286x 286x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 10x 6x 6x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 30x 30x 30x 30x 30x 30x 30x 30x 32x 32x 32x 32x 32x 32x 32x 12x 32x 8x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 64x 18x 46x 44x 64x 128x 128x 64x 64x 64x 64x 64x 64x 64x 36x 36x 24x 24x 12x 12x 12x 64x 28x 28x 28x 16x 16x 12x 12x 32x 32x 32x 32x 32x 32x 32x 32x 32x 62x 62x 62x 178x 178x 178x 62x 32x 32x 32x 32x 20x 20x 20x 12x 12x 12x 12x 32x 32x 32x 32x 32x 32x 30x 16x 16x 16x 46x 16x 16x 16x 16x 30x 14x 14x 14x 40x 14x 14x 14x 14x 30x 30x 30x 32x 32x 64x 64x 64x 64x 32x 32x 32x 32x 12x 12x 12x 44x 44x 44x 44x 44x 44x 44x 44x 12x 12x 12x 2x 2x 2x 2x 12x 12x 12x 12x 12x 8x 8x 8x 2x 4x 8x 8x 8x 4x 4x 2x 2x 2x 2x 2x 2x 2x 32x 44x 44x 8x 8x 6x 6x 6x 6x 6x 6x 6x 2x 2x 2x 2x 2x 2x 2x 16x 16x 16x 16x 16x 16x 16x 28x 28x 16x 16x 16x 16x 16x 16x 32x 32x 32x 32x 32x 32x 28x 28x 28x 28x 32x 32x 32x 32x 32x 32x 32x 24x 24x 24x 24x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 16x 28x 16x 16x 14x 30x 14x 14x 14x 14x 14x 14x 16x 16x 16x 20x 20x 20x 20x 2x 2x 2x 6x 2x 2x 2x 258x 258x 258x 114x 114x 1178x 60x 1118x 822x 296x 1186x 1186x 118x 118x 40x 118x 40x 118x 24x 24x 94x 44x 44x 50x 50x 258x 258x 258x 258x 258x 258x 258x 258x 258x 258x 258x 258x 258x 40x 48x 18x 18x 18x 18x 18x 18x 14x 14x 14x 14x 14x 14x 4x 4x 4x 4x 4x 4x 4x 4x 1873x 1873x 1873x 1873x 1873x 1020x 1020x 30x 1822x 1802x 1822x 1822x 1822x 1822x 1822x 1822x 1822x 1166x 1166x 426x 426x 426x 426x 426x 426x 426x 22x 22x 426x 426x 54x 426x 1822x 718x 718x 414x 414x 78x 78x 72x 414x 14x 414x 414x 12x 414x 42x 1822x 828x 828x 828x 54x 54x 194x 194x 188x 258x 258x 258x 258x 258x 258x 258x 258x 136x 136x 104x 104x 104x 4x 4x 104x 104x 32x 32x 258x 122x 122x 90x 4x 90x 90x 1314x 1314x 1314x 72x 1314x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 6x 68x 68x 68x 68x 68x 68x 68x 68x 206x 206x 206x 206x 206x 206x 206x 206x 206x 554x 554x 554x 554x 554x 554x 554x 552x 552x 552x 450x 102x 102x 102x 552x 552x 552x 552x 450x 450x 102x 102x 102x 102x 102x 102x 102x 102x 4x 4x 30x 30x 30x 30x 30x 30x 28x 556x 556x 556x 482x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 74x 280x 220x 280x 280x 280x 74x 36x 72x 72x 72x 36x 36x 74x 74x 36x 133x 93x 93x 93x 40x 22x 22x 22x 18x 18x 18x 18x 36x 36x 36x 140x 140x 140x 36x 36x 140x 38x 30x 60x 60x 60x 30x 30x 64x 64x 30x 137x 92x 92x 92x 45x 16x 16x 16x 29x 22x 22x 22x 30x 28x 28x 104x 104x 104x 28x 30x 112x 8x 8x 8x 31x 8x 28x 28x 8x 74x 74x 2x 2x 2x 74x 36x 36x 36x 36x 36x 36x 36x 36x 36x 104x 36x 36x 36x 902x 902x 902x 902x 902x 902x 902x 902x 902x 902x 622x 134x 134x 134x 258x 228x 228x 133x 133x 124x 9x 9x 133x 124x 124x 42x 228x 228x 228x 228x 30x 30x 30x 30x 30x 30x 202x 202x 18x 202x 40x 202x 126x 126x 126x 126x 76x 648x 648x 12x 636x 636x 392x 200x 244x 8x 382x 148x 382x 382x 110x 340x 340x 340x 340x 1196x 1196x 1906x 1906x 1196x 4x 4x 4x 4x 4x 4x 4x 4x 4x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 802x 352x 292x 60x 60x 188x 150x 2x 2x 6x 6x 6x 6x 4x 4x 2x 2x 2x 473x 473x 473x 473x 2564x 2564x 161x 2403x 1932x 2403x 471x 471x 471x 473x 473x 473x 48x 48x 124x 473x 473x 473x 48x 48x 48x 48x 48x 48x 48x 48x 48x 48x 124x 124x 48x 48x 124x 92x 124x 119x 119x 119x 119x 119x 119x 119x 119x 119x 119x 119x 119x 119x 119x 124x 124x 48x 48x 48x 48x 48x 48x 48x 425x 509x 509x 4x 4x 4x 4x 8x 4x 4x 4x 4x 6x 6x 6x 6x 20x 20x 20x 27x 27x 27x 27x 1x 26x 26x 10x 10x 10x 10x 10x 10x 10x 4x 4x 4x 8x 8x 6x 1312x 1312x 12x 12x 6x 12x 12x 1312x 3052x 3052x 3052x 12x 6x 12x 6x 12x 12x 6x 6x 6x 6x 6x 12x 12x 588x 588x 586x 2x 588x 588x 8x 904x 904x 3928x 2325x 2325x 10x 3928x 1792x 1792x 10x 6x 10x 904x 1530x 4324x 1302x 1302x 870x 432x 432x 432x 432x 432x 432x 422x 432x 432x 432x 432x 432x 432x 432x 432x 432x 432x 432x 432x 10x 432x 432x 10x 432x 432x 432x 432x 432x 432x 1292x 556x 432x 432x 432x 432x 286x 286x 130x 260x 260x 256x 286x 158x 432x 432x 432x 432x 92x 92x 92x 56x 56x 432x 432x 432x 2x 432x 432x 432x 886x 432x 432x 410x 6982x 432x 432x 432x 4566x 442x 442x 442x 442x 1090x 432x 432x 2020x 432x 432x 434x 434x 434x 434x 434x 1560x 136x 136x 136x 136x 132x 306x 4x 10x 4x 4x 4x 136x 896x 34x 34x 34x 34x 68x 34x 394x 86x 86x 86x 86x 6x 6x 2x 4x 2x 2x 2x 2x 2x 2x 950x | /**
* Copyright 2019 Adobe. All rights reserved.
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. You may obtain a copy
* of the License at http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
* OF ANY KIND, either express or implied. See the License for the specific language
* governing permissions and limitations under the License.
*/
import {BaseComponent} from '../../../coral-base-component';
import {DragAction} from '../../../coral-dragaction';
import TableColumn from './TableColumn';
import TableCell from './TableCell';
import TableRow from './TableRow';
import TableHead from './TableHead';
import TableBody from './TableBody';
import TableFoot from './TableFoot';
import '../../../coral-component-button';
import {Checkbox} from '../../../coral-component-checkbox';
import base from '../templates/base';
import {SelectableCollection} from '../../../coral-collection';
import {Decorator} from '../../../coral-decorator';
import {
isTableHeaderCell,
isTableCell,
isTableRow,
isTableBody,
getCellByIndex,
getColumns,
getCells,
getContentCells,
getHeaderCells,
getRows,
getSiblingsOf,
getIndexOf,
divider
} from './TableUtil';
import {events, transform, validate, commons, i18n, Keys} from '../../../coral-utils';
const CLASSNAME = '_coral-Table-wrapper';
/**
Enumeration for {@link Table} variants
@typedef {Object} TableVariantEnum
@property {String} DEFAULT
A default table.
@property {String} QUIET
A quiet table with transparent borders and background.
@property {String} LIST
Not supported. Falls back to DEFAULT.
*/
const variant = {
DEFAULT: 'default',
QUIET: 'quiet',
LIST: 'list'
};
const ALL_VARIANT_CLASSES = [];
for (const variantValue in variant) {
ALL_VARIANT_CLASSES.push(`${CLASSNAME}--${variant[variantValue]}`);
}
const IS_DISABLED = 'is-disabled';
const IS_SORTED = 'is-sorted';
const IS_UNSELECTABLE = 'is-unselectable';
const IS_FIRST_ITEM_DRAGGED = 'is-draggedFirstItem';
const IS_LAST_ITEM_DRAGGED = 'is-draggedLastItem';
const IS_DRAGGING_CLASS = 'is-dragging';
const IS_BEFORE_CLASS = 'is-before';
const IS_AFTER_CLASS = 'is-after';
const IS_LAYOUTING = 'is-layouting';
const IS_READY = 'is-ready';
const KEY_SPACE = Keys.keyToCode('space');
/**
@class Coral.Table
@classdesc A Table component is a container component to display and manipulate data in two dimensions.
To define table actions on specific elements, handles can be used.
A handle is given a special attribute :
- <code>[coral-table-select]</code>. Select/unselect all table items.
- <code>[coral-table-rowselect]</code>. Select/unselect the table item.
- <code>[coral-table-roworder]</code>. Drag to order the table item.
- <code>[coral-table-rowlock]</code>. Lock/unlock the table item.
@htmltag coral-table
@htmlbasetag table
@extends {HTMLTableElement}
@extends {BaseComponent}
*/
const Table = Decorator(class extends BaseComponent(HTMLTableElement) {
/** @ignore */
constructor() {
super();
// Templates
this._elements = {
head: this.querySelector('thead[is="coral-table-head"]') || new TableHead(),
body: this.querySelector('tbody[is="coral-table-body"]') || new TableBody(),
foot: this.querySelector('tfoot[is="coral-table-foot"]') || new TableFoot(),
columns: this.querySelector('colgroup') || document.createElement('colgroup')
};
base.call(this._elements, {commons});
// Events
this._delegateEvents({
// Table specific
'global:coral-commons:_webfontactive': '_resetLayout',
'change [coral-table-select]': '_onSelectAll',
'capture:scroll [handle="container"]': '_onScroll',
// Head specific
'click thead[is="coral-table-head"] th[is="coral-table-headercell"]': '_onHeaderCellSort',
'coral-dragaction:dragstart thead[is="coral-table-head"] th[is="coral-table-headercell"]': '_onHeaderCellDragStart',
'coral-dragaction:drag thead[is="coral-table-head"] tr[is="coral-table-row"] > th[is="coral-table-headercell"]': '_onHeaderCellDrag',
'coral-dragaction:dragend thead[is="coral-table-head"] tr[is="coral-table-row"] > th[is="coral-table-headercell"]': '_onHeaderCellDragEnd',
// a11y
'key:enter th[is="coral-table-headercell"]': '_onHeaderCellSort',
'key:enter th[is="coral-table-headercell"] coral-table-headercell-content': '_onHeaderCellSort',
'key:space th[is="coral-table-headercell"]': '_onHeaderCellSort',
'key:space th[is="coral-table-headercell"] coral-table-headercell-content': '_onHeaderCellSort',
// Body specific
'click tbody[is="coral-table-body"] [coral-table-rowlock]': '_onRowLock',
'click tbody[is="coral-table-body"] [coral-table-rowselect]': '_onRowSelect',
'click tbody[is="coral-table-body"] tr[is="coral-table-row"][selectable] [coral-table-cellselect]': '_onCellSelect',
'capture:mousedown tbody[is="coral-table-body"] [coral-table-roworder]:not([disabled])': '_onRowOrder',
'capture:touchstart tbody[is="coral-table-body"] [coral-table-roworder]:not([disabled])': '_onRowOrder',
'coral-dragaction:dragstart tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragStart',
'coral-dragaction:drag tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDrag',
'coral-dragaction:dragover tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragOver',
'coral-dragaction:dragend tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragEnd',
// a11y dnd
'key:space tbody[is="coral-table-body"] [coral-table-roworder]:not([disabled])': '_onKeyboardDrag',
'click tbody[is="coral-table-body"] tr[is="coral-table-row"] [coral-table-roworder]:not([disabled])': '_onDragHandleClick',
'coral-dragaction:dragonkeyspace tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragOnKeySpace',
'coral-dragaction:dragoveronkeyarrowdown tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragOverOnKeyArrowDown',
'coral-dragaction:dragoveronkeyarrowup tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragOverOnKeyArrowUp',
'coral-dragaction:dragendonkey tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowDragOverOnKeyEnter',
// a11y
'mousedown tbody[is="coral-table-body"] [coral-table-rowselect]': '_onRowDown',
'key:enter tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowSelect',
'key:space tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onRowSelect',
'key:pageup tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusPreviousItem',
'key:pagedown tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusNextItem',
'key:left tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusPreviousItem',
'key:right tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusNextItem',
'key:up tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusPreviousItem',
'key:down tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusNextItem',
'key:home tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusFirstItem',
'key:end tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onFocusLastItem',
'key:shift+pageup tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onSelectPreviousItem',
'key:shift+pagedown tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onSelectNextItem',
'key:shift+left tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onSelectPreviousItem',
'key:shift+right tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onSelectNextItem',
'key:shift+up tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onSelectPreviousItem',
'key:shift+down tbody[is="coral-table-body"] tr[is="coral-table-row"]': '_onSelectNextItem',
// Private
'coral-table-row:_multiplechanged': '_onRowMultipleChanged',
'coral-table-row:_beforeselectedchanged': '_onBeforeRowSelectionChanged',
'coral-table-row:_selectedchanged': '_onRowSelectionChanged',
'coral-table-row:_lockedchanged': '_onRowLockedChanged',
'coral-table-row:_change': '_onRowChange',
'coral-table-row:_contentchanged': '_onRowContentChanged',
'coral-table-headercell:_contentchanged': '_resetLayout',
'coral-table-head:_contentchanged': '_onHeadContentChanged',
'coral-table-body:_contentchanged': '_onBodyContentChanged',
'coral-table-body:_empty': '_onBodyEmpty',
'coral-table-column:_alignmentchanged': '_onAlignmentChanged',
'coral-table-column:_fixedwidthchanged': '_onFixedWidthChanged',
'coral-table-column:_orderablechanged': '_onColumnOrderableChanged',
'coral-table-column:_sortablechanged': '_onColumnSortableChanged',
'coral-table-column:_sortabledirectionchanged': '_onColumnSortableDirectionChanged',
'coral-table-column:_hiddenchanged': '_onColumnHiddenChanged',
'coral-table-column:_beforecolumnsort': '_onBeforeColumnSort',
'coral-table-column:_sort': '_onColumnSort',
'coral-table-head:_stickychanged': '_onHeadStickyChanged'
});
// Required for coral-table:change event
this._oldSelection = [];
// References selected items in their selection order and is only used for keyboard selection
this._lastSelectedItems = {
items: [],
direction: null
};
// Don't sort by default
this._allowSorting = false;
// Debounce timer
this._timeout = null;
// Debounce wait in milliseconds
this._wait = 50;
// Used by resizing detector
this._resetLayout = this._resetLayout.bind(this);
// Init observer
this._toggleObserver(true);
}
/**
The head of the table.
@type {TableHead}
@contentzone
*/
get head() {
reEturn this._getContentZone(this._elements.head);
}
set heEad(value) {
this._setContentZone('head', value, {
handle: 'head',
tagName: 'thead',
insert: function (head) {
// Using the native table API allows to position the head element at the correct position.
this._elements.table.tHead = head;
// To init the head observer
head.setAttribute('_observe', 'on');
}
});
}
/**
The body of the table. Multiple bodies are not supported.
@type {TableBody}
@contentzone
*/
get body() {
return this._getContentZone(this._elements.body);
}
set body(value) {
this._setContentZone('body', value, {
handle: 'body',
tagName: 'tbody',
insert: function (body) {
this._elements.table.appendChild(body);
this.items._container = body;
// To init the body observer
body.setAttribute('_observe', 'on');
}
});
}
/**
The foot of the table.
@type {TableFoot}
@contentzone
*/I
get foot() {
return this._getContentZone(this._elements.foot);
}
set foot(value) {
this._setContentZone('foot', value, {
Ehandle: 'foot',
taIgName: 'tfoot',
insert: function (foot) {
// Using the native table API allows to position the foot element at the correct position.
this._elements.table.tFoot = foot;
}
});
}
/**
The columns of the table.
@type {TableColumn}
@contentzone
*/
get columns() {
return this._getContentZone(this._elements.columns);
}
E
set columns(value) {
this._setContentZone('columns', value, {
handle: 'columns',
tagName: 'colgroup',
insert: function (content) {
this._elements.table.appendChild(content);
}
});
}
/**
The table's variant. See {@link TableVariantEnum}.
@type {String}
@default TableVariantEnum.DEFAULT
@htmlattribute variant
@htmlattributereflected
*/
get variant() {
return this._variant || variant.DEFAULT;
}
set variant(value) {
value = transform.string(value).toLowerCase();
this._variant = validate.enumeration(variant)(value) && value || variant.DEFAULT;
this._reflectAttribute('variant', this._variant);
this.classList.remove(...ALL_VARIANT_CLASSES);
this.classList.add(`${CLASSNAME}--${this._variant}`);
}
I
/**
Whether the items are selectable.
@type {Boolean}
@default false
@htmlattribute selectable
@htmlattributereflected
*/
get selectable() {
return this._selectable || false;
}
set selectable(value) {
this._selectable = transform.booleanAttr(value);
this._reflectAttribute('selectable', this._selectable);
const rows = getRows([this.body]);
ifE (this._selectable) {
rows.forEach((row) => {
row.setAttribute('_selectable', '');
});
} elEse {
// Clear selection
rows.forEach((row) => {
row.removeAttribute('_selectable');
});
this.trigger('coral-table:change', {
selection: [],
oldSelection: this._oldSelection
});
// Sync used collection
this._oldSelection = [];
this._lastSelectedItems.items = [];
}
// a11y
this._toggleFocusable();
}
/**
Whether the table is orderable. If the table is sorted, ordering handles are hidden.
@type {Boolean}
@default false
@htmlattribute orderable
@htmlattributereflected
*/
get orderable() {
return this._orderable || false;
}
set orderable(value) {
this._orderable = transform.booleanAttr(value);
this._reflectAttribute('orderable', this._orderable);
getRows([this.body]).forEach((row) => {
row[this._orderable ? 'setAttribute' : 'removeAttribute']('_orderable', '');
});
// a11y
this._toggleFocusable();
}
/**
Whether multiple items can be selected.
@type {Boolean}
@default false
@htmlattribute multiple
@htmlattributereflected
*/
get multiple() {
return this._multiple || false;
}
set multiple(value) {
this._multiple = transform.booleanAttr(value);
this._reflectAttribute('multiple', this._multiple);
this._elements.table.setAttribute('aria-multiselectable', this._multiple);
// Deselect all except last
if (!this.multiple) {
const selection = this.selectedItems;
if (selection.length > 1) {
selection.forEach((row, i) => {
// Don't trigger too many events
row.set('selected', i === selection.length - 1, true);
});
// Synchronise the table select handle
const newSelection = this.selectedItems;
if (newSelection.length) {
this._setSelectAllHandleState('indeterminate');
} elEse {
this._setSelectAllHandleState('unchecked');
}
this.trigger('coral-table:change', {
selection: newSelection,
oldSelection: selection
});
// Sync used collection
this._oldSelection = newSelection;
this._lastSelectedItems.items = newSelection;
}
}
}
/**
Whether tEhe table rows can be locked/unlocked. If rows are locked, they float to the top of the table and aren't
affected by column sorting.
@type {Boolean}
@default false
@htmlattribute lockable
@htmlattributereflected
*/
get lockable() {
return this._lockable || false;
}
set lockable(value) {
this._lockable = transform.booleanAttr(value);
this._reflectAttribute('lockable', this._lockable);
getRows([this.body]).forEach((row) => {
row[this._lockable ? 'setAttribute' : 'removeAttribute']('_lockable', '');
});
// a11y
this._toggleFocusable();
}
/**
Specifies <code>aria-labelledby</code> value.
@type {?String}
@default null
@htmlattribute labelledby
*/
get labelledBy() {
return this._elements.table.getAttribute('aria-labelledby');
}
set labelledBy(value) {
value = transform.string(value);
this._elements.table[value ? 'setAttribute' : 'removeAttribute']('aria-labelledby', value);
}E
/**
Specifies <code>aria-label</code> value.
@type {String}
@default null
@htmlattribute labelled
*/
get labelled() {
return this._elements.table.getAttribute('aria-label');
}
set labelled(value) {
value = transform.string(value);
this._elements.table[value ? 'setAttribute' : 'removeAttribute']('aria-label', value);
}
/**
Returns an Array containing the selected items.
@type {Array.<HTMLElement>}
@readonly
*/
get EselectedItems() {
return this.items._getAllSelected();
}
/**
Returns the first selected item of the table. The value <code>null</code> is returned if no element is
selected.
@type {HTMLElement}
@readonly
*/
get selectedItem() {
return this.items._getFirstSelected();
}
/**
The Collection Interface that allows interacting with the items that the component contains.
@type {SelectableCollection}
@readonly
*/E
get items() {
// Construct the collection on first request
if (!this._items) {
this._items = new SelectableCollection({
host: this,
container: this.body,
itemBaseTagName: 'tr',
itemTagName: 'coral-table-row'
});
}
return this._items;
}
/** @private */
_onSelectAEll(event) {
if (this.selectable) {
let rows = this._getSelectableItems();
if (rows.length) {
if (this.multiple) {
const selected = event.target.checked;
Erows.forEach((row) => {
// Don't trigger too many events
row.set('selected', selected, true);
});
rows = selected ? rows : [];
// Synchronise the table select handle
this._setSelectAllHandleState(selected ? 'checked' : 'unchecked');
this.trigger('coral-table:change', {
selection: rows,
oldSelection: this._oldSelection
});
// Sync used collection
this._oldSelection = rows;
this._lastSelectedItems.items = rows;
} else {
// Only select last item
const lastItem = rows[rows.length - 1];
lastItem.selected = !lastItem.selected;
}
}
}
}
_triggerChangeEvent() {
if (!this._preventTriggeringEvents) {
const selectedItems = this.selectedItems;
this.trigger('coral-table:change', {
oldSelection: this._oldSelection,
selection: selectedItems
});
this._oldSelection = selectedItems;
}
}E
/** @private */
_onRowOrder(event) {
if (events.isVirtualEvent(event)) {
return;
}
const table = this;
const row = event.target.closest('tr[is="coral-table-row"]');
if (row && table.orderable) {
Eif (row.dragAction && row.dragAction.handle) {
this._unwrapDragHandle(row.dragAction.handle);
}I
const head = table.head;
const body = table.body;
const sticky = head && head.sticky;
const style = row.getAttribute('style');
const index = getIndexOf(row);
coEnst oldBefore = row.nextElementSibling;
const dragAction = new DragAction(row);
consIt items = getRows([body]);
const tableBoundingClientRect = table.getBoundingClientRect();
const rowBoundingClientRect = row.getBoundingClientRect();
if (row === items[0]) {
table.classList.add(IS_FIRST_ITEM_DRAGGED);
} else if (row === items[items.length - 1]) {
table.classList.add(IS_LAST_ITEM_DRAGGED);
}
dragAction.axis = 'vertical';
// HandlEe the scroll in table
dragAction.scroll = false;
// Specify selection handle directly on the row if none found
dragAction.handle = row.querySelector('[coral-table-roworder]');
// The row placeholder indicating where the dragged element will be dropped
const placeholder = row.cloneNode(true);
placehEolder.classList.add('_coral-Table-row--placeholder');
// Prepare the row position before inserting its placeholder
row.style.top = `${rowBoundingClientRect.top - tableBoundingClientRect.top}px`;
// Prevent change event from triggering if the cloned node is selected
table._preventTriggeringEvents = true;
body.insertBefore(placeholder, row.nextElementSibling);
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
});
// Store the data to avoid re-reading the layout on drag events
const dragData = {
placeholder: placeholder,
index: index,
oldBefore: oldBefore,
// Backup styles to restore them later
style: {
row: style
}
};
// Required to handle the scrolling of the sticky table on drag events
if (sticky) {
dragData.sticky = sticky;
dragData.tableTop = tableBoundingClientRect.top;
dragData.tableSize = tableBoundingClientRect.height;
dragData.headSize = parseFloat(table._elements.container.style.marginTop);
dragData.dragElementSize = rowBoundingClientRect.height;
}
row.dragAction._dragData = dragData;
}
}
/** @private */
_onHeaderCellSort(event) {
const table = this;
const matchedTarget = event.matchedTarget.closest('th');
// Don't sort if the column was dragged
if (!matchedTarget._isDragging) {
const column = table._getColumn(matchedTarget);
// Only sort if actually sortable and event not defaultPrevented
if (column && column.sortable) {
event.preventDefault();
column._sort();
// Restore focus on the header cell in any case
matchedTarget.focus();
}
}
}
/** @private */
_onHeaderCellDragStart(event) {
const table = this;
const matchedTarget = event.matchedTarget;
const dragElement = event.detail.dragElement;
const siblingHeaderCellSelector = matchedTarget === dragElement ? 'th[is="coral-table-headercell"]' : 'th[is="coral-table-headercell"] coral-table-headercell-content';
const tableBoundingClientRect = table.getBoundingClientRect();
// Store the data to be used on drag events
dragElement.dragAction._dragData = {
draggedColumnIndex: getIndexOf(matchedTarget),
tableLeft: tableBoundingClientRect.left,
tableSize: tableBoundingClientRect.width,
drEagElementSize: matchedTarget.getBoundingClientRect().width,
tableScrollWidth: table._elements.container.scrollWidth
};
getSiblingsOf(matchedTarget, siblingHeaderCellSelector, 'prevAll').forEach((item) => {
item.classList.add(IS_BEFORE_CLASS);
});
getSiblingsOf(matchedTarget, siblingHeaderCellSelector, 'nextAll').forEach((item) => {
item.classList.add(IS_AFTER_CLASS);
});
}
/** @private */
_onHeaderCellDrag(event) {
const table = this;
const container = table._elements.container;
const matchedTarget = event.matchedTarget;
coEnst dragElement = event.detail.dragElement;
const dragData = dragElement.dragAction._dragData;
const row = matchedTarget.parentElement;
const isHeaderCellDragged = matchedTarget === dragElement;
const containerScrollLeft = container.scrollLeft;
const documentScrollLeft = document.body.scrollLeft;
// Prevent sorting on header cell click if the header cell is being dragged
matchedTarget._isDragging = true;
// Scroll left/right if table edge is reached
const position = dragElement.getBoundingClientRect().left - dragData.tableLeft;
const leftScrollLimit = 0;
const rightScrollLimit = dragData.tableSize - dragData.dragElementSize;
const scrollOffset = 10;
if (position < leftScrollLimit) {
container.scrollLeft -= scrollOffset;
}
// 2nd condition is required to avoid increasing the container scroll width
else if (position > rightScrollLimit && containerScrollLeft + dragData.tableSize < dragData.tableScrollWidth) {
container.scrollLeft += scrollOffset;
}
// Position sibling header cells based on the dragged element
getHeaderCells(row).forEach((headerCell) => {
const draggedHeaderCell = isHeaderCellDragged ? headerCell : headerCell.content;
if (!draggedHeaderCell.classList.contains(IS_DRAGGING_CLASS)) {
const offsetLeft = draggedHeaderCell.getBoundingClientRect().left + documentScrollLeft;
const isAfter = event.detail.pageX < offsetLeft + draggedHeaderCell.offsetWidth / 3;
draggedHeaderCell.classList.toggle(IS_AFTER_CLASS, isAfter);
draggedHeaderCell.classList.toggle(IS_BEFORE_CLASS, !isAfter);
E
const columnIndex = getIndexOf(headerCell);
const dragElementIndex = getIndexOf(matchedTarget);
// Place headercell after
if (draggedHeaderCell.classList.contains(IS_AFTER_CLASS)) {
if (columnIndex < dragElementIndex) {
// Position the header cells based on their siblings position
if (isHeaderCellDragged) {
const nextHeaderCellWidth = draggedHeaderCell.clientWidth;
draggedHeaderCell.style.left = `${nextHeaderCellWidth}px`;
} else {
const nextHeaderCell = getSiblingsOf(headerCell, 'th[is="coral-table-headercell"]', 'next');
const nextHeaderCellLeftOffset = nextHeaderCell.getBoundingClientRect().left + documentScrollLeft;
draggedHeaderCell.style.left = `${nextHeaderCellLeftOffset + containerScrollLeft}px`;
}
} else {
draggedHeaderCell.style.left = '';
}
}
// Place headerCell before
if (draggedHeaderCell.classList.contains(IS_BEFORE_CLASS)) {
if (columnIndex > dragElementIndex) {
const prev = getSiblingsOf(headerCell, 'th[is="coral-table-headercell"]', 'prev');
// Position the header cells based on their siblings position
if (isHeaderCellDragged) {
const beforeHeaderCellWidth = prev.clientWidth;
draggedHeaderCell.style.left = `${-1 * (beforeHeaderCellWidth)}px`;
} else {
const beforeHeaderCellLeftOffset = prev.getBoundingClientRect().left + documentScrollLeft;
draggedHeaderCell.style.left = `${beforeHeaderCellLeftOffset + containerScrollLeft}px`;
I }
} else {
draggedHeaderCell.style.left = '';
}
}
}
});
}
/** @private */
_onHeaderCellDragEnd(event) {
const table = this;
const matchedTarget = event.matchedTarget;
const dragElement = event.detail.dragElement;
const dragData = dragElement.dragAction._dragData;
const column = table._getColumn(matchedTarget);
const headRows = getRows([table.head]);
const isHeaderCellDragged = matchedTarget === dragElement;
const row = matchedTarget.parentElement;
// Select all cells in table body and foot given the index
const getCellsByIndex = (cellIndex) => {
const cellElements = [];
const rows = getRows([table.body, table.foot]);
rows.forEach((rowElement) => {
const cell = getCellByIndex(rowElement, cellIndex);
if (cell) {
cellElements.push(cell);
}
});
return cellElements;
};
const cells = getCellsByIndex(getIndexOf(matchedTarget));
let before = null;
let after = null;
// Siblings are either header cell or header cell content based on the current sticky state
if (isHeaderCellDragged) {
before = row.querySelector(`th[is="coral-table-headercell"].${IS_AFTER_CLASS}`);
after = row.querySelectorAll(`th[is="coral-table-headercell"].${IS_BEFORE_CLASS}`);
after = after.length ? after[after.length - 1] : null;
} else {
before = row.querySelector(`th[is="coral-table-headercell"] > coral-table-headercell-content.${IS_AFTER_CLASS}`);
before = before ? before.parentNode : null;
after = row.querySelectorAll(`th[is="coral-table-headercell"] > coral-table-headercell-content.${IS_BEFORE_CLASS}`);
after = after.length ? after[after.length - 1].parentNode : null;
}
//E Did header cell order change ?
const swapped = !(before && before.previousElementSibling === matchedTarget || after && after.nextElementSibling === matchedTarget);
// Switch whole columns based on the new position of the dragged element
if (swapped) {
const beforeColumn = before ? table._getColumn(before) : null;
// Trigger the event on table
const beforeEvent = table.trigger('coral-table:beforecolumndrag', {
column: column,
before: beforeColumn
});
const oldBefore = column.nextElementSibling;
if (!beforeEvent.defaultPrevented) {
// Insert the headercell at the new position
if (before) {
const beforeIndex = getIndexOf(before);
const beforeCells = getCellsByIndex(beforeIndex);
cells.forEach((cell, i) => {
cell.parentNode.insertBefore(cell, beforeCells[i]);
E });
// Sync <coral-table-column> by reordering it too
const beforeCol = getColumns(table.columns)[beforeIndex];
if (beforeCol && column) {
table.columns.insertBefore(column, beforeCol);
}
row.insertBefore(matchedTarget, before);
}
if (after) {
const afterIndex = getIndexOf(after);
const afterCells = getCellsByIndex(afterIndex);
cells.forEach((cell, i) => {
cell.parentNode.insertBefore(cell, afterCells[i].nextElementSibling);
});
// Sync <coral-table-column> by reordering it too
const afterCol = getColumns(table.columns)[afterIndex];
if (afterCol && column) {
table.columns.insertBefore(column, afterCol.nextElementSibling);
}
row.insertBefore(matchedTarget, after.nextElementSibling);
}
// Trigger the order event if the column position changed
if (dragData.draggedColumnIndex !== getIndexOf(matchedTarget)) {
const newBefore = getColumns(table.columns)[getIndexOf(column) + 1];
table.trigger('coral-table:columndrag', {
column: column,
oldBefore: oldBefore,
before: newBefore || null
});
}
}
}
// Restoring default header cells styling
headRows.forEach((rowElement) => {
getHeaderCells(rowElement).forEach((headerCell) => {
headerCell = isHeaderCellDragged ? headerCell : headerCell.content;
headerCell.classList.remove(IS_AFTER_CLASS);
headerCell.classList.remove(IS_BEFORE_CLASS);
headerCell.style.left = '';
});
});
// Trigger a relayout
table._resetLayout();
window.requestAnimationFrame(() => {
// Allows sorting again after dragging completed
matchedTarget._isDragging = undefined;
// Refocus the dragged element manually
table._toggleElementTabIndex(dragElement, null, true);
});
}
/** @private */
_onCellSelect(event) {
const cell = event.target.closest('td[is="coral-table-cell"]');
if (cell) {
cell.selected = !cell.selected;
}
}
/** @private */
_onRowSelect(event) {
const table = this;
const row = event.target.closest('tr[is="coral-table-row"]');
if (row) {
// Ignore selection if the row is locked
if (table.lockable && row.locked) {
return;
}
// Restore text-selection
table.classList.remove(IS_UNSELECTABLE);
// Prevent row selection when it's the selection handle and the target is an input
if (table.selectable && (Keys.filterInputs(event) || !row.hasAttribute('coral-table-rowselect'))) {
// Pressing space scrolls the sticky table to the bottom if scrollable
if (event.keyCode === KEY_SPACE) {
event.preventDefault();
}
if (event.shiftKey) {
let lastSelectedItem = table._lastSelectedItems.items[table._lastSelectedItems.items.length - 1];
const lastSelectedDirection = table._lastSelectedItems.direction;
// If no selected items, by default set the first item as last selected item
if (!table.selectedItem) {
const rows = table._getSelectableItems();
if (rows.length) {
lastSelectedItem = rows[0];
lastSelectedItem.set('selected', true, true);
}
}
// Don't continue if table has no items or if the last selected item is the clicked item
if (lastSelectedItem && getIndexOf(row) !== getIndexOf(lastSelectedItem)) {
// Range selection direction
const before = getIndexOf(row) < getIndexOf(lastSelectedItem);
const rangeQuery = before ? 'prevUntil' : 'nextUntil';
// Store direction
table._lastSelectedItems.direction = before ? 'up' : 'down';
if (!row.selected) {
// Store selection range
const selectionRange = getSiblingsOf(lastSelectedItem, 'tr[is="coral-table-row"]:not([selected])', rangeQuery);
selectionRange[before ? 'push' : 'unshift'](lastSelectedItem);
// Direction change
if (!before && lastSelectedDirection === 'up' || before && lastSelectedDirection === 'down') {
selectionRange.forEach((item) => {
item.set('selected', false, true);
});
}
// Select item
const selectionRangeRow = selectionRange[before ? 0 : selectionRange.length - 1];
selectionRangeRow.set('selected', true, true);
getSiblingsOf(selectionRangeRow, row, rangeQuery).forEach((item) => {
item.set('selected', true, true);
});
} else {
const selection = getSiblingsOf(lastSelectedItem, row, rangeQuery);
// If some items are not selected
if (selection.some((item) => !item.hasAttribute('selected'))) {
// Select all items in between
selection.forEach((item) => {
item.set('selected', true, true);
});
// Deselect selected item right before/after the selection range
getSiblingsOf(row, 'tr[is="coral-table-row"]:not([selected])', rangeQuery).forEach((item) => {
item.set('selected', false, true);
});
} else {
// Deselect items
selection[before ? 'push' : 'unshift'](lastSelectedItem);
selection.forEach((item) => {
item.set('selected', false, true);
});
}
}
}
} else {
// Remove direction if simple click without shift key pressed
table._lastSelectedItems.direction = null;
}
// Select the row that was clicked and keep the row selected if shift key was pressed
row.selected = event.shiftKey ? true : !row.selected;
// Don't focus the row if the target isn't the row and focusable
table._focusItem(row, event.target === event.matchedTarget || event.target.tabIndex < 0);
}
}
}
/** @private */
_onRowLock(event) {
const table = this;
if (table.lockable) {
const row = event.target.closest('tr[is="coral-table-row"]');
if (row) {
event.preventDefault();
event.stopPropagation();
row.locked = !row.locked;
// Refocus the locked/unlocked item manually
window.requestAnimationFrame(() => {
table._focusItem(row, true);
});
}
}
}
/** @private */
_onRowDown(event) {
const table = this;
// Prevent text-selection
if (table.selectedItem && event.shiftKey) {
table.classList.add(IS_UNSELECTABLE);
// @polyfill IE
// Store text selection feature
const onSelectStart = document.onselectstart;
// Kill text selection feature
document.onselectstart = () => false;
// Restore text selection feature
window.requestAnimationFrame(() => {
document.onselectstart = onSelectStart;
});
}
}
/** @private */
_onRowDragStart(event) {
const table = this;
const head = table.head;
const body = table.body;
const dragElement = event.detail.dragElement;
const dragData = dragElement.dragAction._dragData;
dragData.style.cells = [];
getCells(dragElement).forEach((cell) => {
// Backup styles to restore them later
dragData.style.cells.push(cell.getAttribute('style'));
// Cells will shrink otherwise
cell.style.width = window.getComputedStyle(cell).width;
});
if (head && !head.sticky) {
// @polyfill ie11
// Element that scrolls the document.
const scrollingElement = document.scrollingElement || document.documentElement;
dragElement.style.top = `${dragElement.getBoundingClientRect().top + scrollingElement.scrollTop}px`;
}
dragElement.style.position = 'absolute';
// Setting drop zones allows to listen for coral-dragaction:dragover event
dragElement.dragAction.dropZone = body.querySelectorAll(`tr[is="coral-table-row"]:not(.${IS_DRAGGING_CLASS})`);
// We cannot rely on :focus since the row is being moved in the dom while dnd
dragElement.classList.add('is-focused');
}
/** @private */
_onRowDrag(event) {
const table = this;
const body = table.body;
const dragElement = event.detail.dragElement;
const dragData = dragElement.dragAction._dragData;
const firstRow = getRows([body])[0];
// Insert the placeholder at the top
if (dragElement.getBoundingClientRect().top <= firstRow.getBoundingClientRect().top) {
table._preventTriggeringEvents = true;
body.insertBefore(dragData.placeholder, firstRow);
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
});
}
// Scroll up/down if table edge is reached
if (dragData.sticky) {
const dragElementTop = dragElement.getBoundingClientRect().top;
const position = dragElementTop - dragData.tableTop - dragData.headSize;
const topScrollLimit = 0;
const bottomScrollLimit = dragData.tableSize - dragData.dragElementSize - dragData.headSize;
const scrollOffset = 10;
// Handle the scrollbar position based on the dragged element position.
// nextFrame is required else Chrome wouldn't take scrollTop changes in account when dragging the first row down
window.requestAnimationFrame(() => {
if (position < topScrollLimit) {
table._elements.container.scrollTop -= scrollOffset;
} else if (position > bottomScrollLimit) {
table._elements.container.scrollTop += scrollOffset;
}
});
}
}
/** @private */
_onRowDragOver(event) {
const table = this;
const body = table.body;
const dragElement = event.detail.dragElement;
const dropElement = event.detail.dropElement;
const dragData = dragElement.dragAction._dragData;
// Swap the placeholder
if (dragElement.getBoundingClientRect().top >= dropElement.getBoundingClientRect().top) {
table._preventTriggeringEvents = true;
body.insertBefore(dragData.placeholder, dropElement.nextElementSibling);
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
});
}
}
/** @private */
_onRowDragEnd(event) {
const table = this;
const body = table.body;
const dragElement = event.detail.dragElement;
const dragAction = event.detail.dragElement.dragAction;
const dragData = dragAction._dragData;
const before = dragData.placeholder ? dragData.placeholder.nextElementSibling : null;
// Clean up
table.classList.remove(IS_FIRST_ITEM_DRAGGED);
table.classList.remove(IS_LAST_ITEM_DRAGGED);
if (dragData.placeholder && dragData.placeholder.parentNode) {
dragData.placeholder.parentNode.removeChild(dragData.placeholder);
}
dragAction.destroy();
// Restore specific styling
dragElement.setAttribute('style', dragData.style.row || '');
getCells(dragElement).forEach((cell, i) => {
cell.setAttribute('style', dragData.style.cells[i] || '');
});
// Trigger the event on table
const beforeEvent = table.trigger('coral-table:beforeroworder', {
row: dragElement,
before: before
});
if (!beforeEvent.defaultPrevented) {
// Did row order change ?
const rows = getRows([body]).filter((item) => item !== dragElement);
if (dragData.index !== rows.indexOf(dragData.placeholder)) {
// Insert the row at the new position and prevent change event from triggering
table._preventTriggeringEvents = true;
body.insertBefore(dragElement, before);
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
});
// Trigger the order event if the row position changed
table.trigger('coral-table:roworder', {
row: dragElement,
oldBefore: dragData.oldBefore,
before: before
});
}
}
// Refocus the dragged element manually
window.requestAnimationFrame(() => {
dragElement.classList.remove('is-focused');
table._focusItem(dragElement, true);
});
}
/** @private */
_wrapDEragHandle(handle, callback = () => {}) {
if(!handle.closest('span[role="application"]')) {
const span = document.createElement('span');
span.setAttribute('role', 'application');
span.setAttribute('aria-label', i18n.get('reordering'));
handle.parentNode.insertBefore(span, handle);
span.appendChild(handle);
handle.selected = true;
handle.setAttribute('aria-pressed', 'true');
window.requestAnimationFrame(() => callback());
}
}
/** @private */
_unwrapDragHandle(handle, callback = () => {}) {
const span = handle && handle.closest('span[role="application"]');
E
if (handle) {
handle.selected = false;
handle.removeAttribute('aria-pressed');
handle.removeAttribute('aria-describedby');
}
window.requestAnimationFrame(() => {
if (span) {
span.parentNode.insertBefore(handle, span);
span.remove();
}
callback();
});
}
/** @private */
_onKeyboardDrag(event) {
const table = this;
coEnst row = event.target.closest('tr[is="coral-table-row"]');
if (row && table.orderable) {
event.preventDefault();
event.stopPropagation();
if (row.dragAction && row.dragAction.isKeyboardDragging) {
return;
}
const style = row.getAttribute('style');
const index = getIndexOf(row);
const oldBefore = row.nextElementSibling;
const dragAction = new DragAction(row);
dragAction.axis = 'vertical';
// Handle the scroll in table
dragAction.scroll = false;
// Specify selection handle directly on the row if none found
const handle = row.querySelector('[coral-table-roworder]');
dragAction.handle = handle;
// Wrap the drag handle button in a span with role="application",
// to force Windows screen readers into forms mode while dragging.
if (event.target === handle) {
this._wrapDragHandle(handle, () => handle.focus());
}
E
// The row placeholder indicating where the dragged element will be dropped
const placeholder = row.cloneNode(true);
placeholder.classList.add('_coral-Table-row--placeholder');
// Store the data to avoid re-reading the layout on drag events
const dragData = {
placeholder: placeholder,
index: index,
oldBefore: oldBefore,
// Backup styles to restore them later
style: {
row: style
}
};
row.dragAction._dragData = dragData;
}E
}
_onDragHanEdleClick(event) {
const row = event.target.closest('tr[is="coral-table-row"]');
if (!row.dragAction) {
this._onKeyboardDrag(event);
row.dragAction._isKeyboardDrag = true;
} else if (row.dragAction._isKeyboardDrag) {
row.dragAction._isKeyboardDrag = undefined;
}
}
/** @private */
_onRowDragOnKeySpace(event) {
event.preventDefault();
const dragElement = event.detail.dragElement;
const dragData = dragElement.dragAction._dragData;
if (dragElement.dragAction._isKeyboardDrag) {
return;
}
dragData.style.cells = [];
getCells(dragElement).forEach((cell) => {
// Backup styles to restore them later
dragData.style.cells.push(cell.getAttribute('style'));
// Cells will shrink otherwise
cell.style.width = window.getComputedStyle(cell).width;
});
}
/** @private */
_onRowDragOverOnKeyArrowDown(event) {
const table = this;
const body = table.body;
const dragElement = event.detail.dragElement;
const items = getRows([body]);
const index = getIndexOf(dragElement);
const dragData = dragElement.dragAction._dragData;
const handle = dragElement.dragAction.handle;
const rowHeader = dragElement.rowHeader;
event.preventDefault();
// We cannot rely on :focus since the row is being moved in the dom while dnd
dragElement.classList.add('is-focused');
if (dragElement === items[items.length - 1]) {
for (let position = 0; position < items.length - 1; position++) {
body.appendChild(items[position]);
}
body.insertBefore(items[0], items[items.length - 2].nextElementSibling);
} else {
body.insertBefore(items[index + 1], items[index]);
}
// Restore specific styling
dragElement.setAttribute('style', dragData.style.row || '');
getCells(dragElement).forEach((cell, i) => {
if (dragData.style.cells) {
cell.setAttribute('style', dragData.style.cells[i] || '');
}
});
if (handle) {
handle.focus();
this._announceLiveRegion((rowHeader ? rowHeader.textContent + ' ' : '') + i18n.get('reordered to row {0}', [getIndexOf(dragElement) + 1]), 'assertive');
}
dragElement.scrollIntoView({block: 'nearest'});
}
/** @private */
_onRowDragIOverOnKeyArrowUp(event) {
const table = this;
const body = table.body;
const dragElement = event.detail.dragElement;
const items = getRows([body]);
const index = getIndexOf(dragElement);
const dragData = dragElement.dragAction._dragData;
const handle = dragElement.dragAction.handle;
const IrowHeader = dragElement.rowHeader;
event.preventDefault();
// We cannot rely on :focus since the row is being moved in the dom while dnd
dragElement.classList.add('is-focused');
if (dragElement === items[0]) {
for (let position = 0; position < items.length - 2; position++) {
body.insertBefore(items[position + 1], items[0]);
}
body.insertBefore(items[items.length - 1], items[1]);
} else {
body.insertBefore(items[index - 1], items[index].nextElementSibling);
}
// Restore specific styling
dragElement.setAttribute('style', dragData.style.row || '');
getCells(dragElement).forEach((cell, i) => {
if (dragData.style.cells) {
cell.setAttribute('style', dragData.style.cells[i] || '');
}
});
if (handle) {
handle.focus();
this._announceLiveRegion((rowHeader ? rowHeader.textContent + ' ' : '') + i18n.get('reordered to row {0}', [getIndexOf(dragElement) + 1]), 'assertive');
}
dragElement.scrollIntoView({block: 'nearest'});
}
/** @private */
_onRowDragOverOnKeyEnter(event) {
const table = this;
const dragElement = event.detail.dragElement;
const dragAction = dragElement.dragAction;
const dragData = dragAction._dragData;
const handle = dragAction.handle;
if (dragAction._isKeyboardDrag) {
dragAction._isKeyboardDrag = undefined;
return;
}
// Trigger the event on table
const beforeEvent = table.trigger('coral-table:beforeroworder', {
row: dragElement,
before: dragData.oldBefore
});
if (!beforeEvent.defaultPrevented && dragData.oldBefore !== dragElement.nextElementSibling) {
// Trigger the order event if the row position changed
table.trigger('coral-table:roworder', {
row: dragElement,
oldBefore: dragData.oldBefore,
before: dragElement.nextElementSibling
});
}
dragAction.destroy();
const isFocusWithinDragElement = dragElement.contains(document.activeElement) || dragElement === document.activeElement;
const isFocusOnHandle = handle && handle === document.activeElement;
// Refocus the dragged element manually
const callback = () => {
dragElement.classList.remove('is-focused');
if (isFocusWithinDragElement) {
table._focusItem(dragElement, true);
}
if (isFocusOnHandle) {
handle.focus();
}
};
this._unwrapDragHandle(handle, callback);
}
/** @private */
_onRowMultipleChanged(event) {
event.stopImmediatePropagation();
const table = this;
const row = event.target;
// Deselect all except last
if (!row.multiple) {
const selectedItems = row.selectedItems;
table._preventTriggeringEvents = true;
selectedItems.forEach((cell, i) => {
cell.selected = i === selectedItems.length - 1;
});
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
table.trigger('coral-table:rowchange', {
oldSelection: selectedItems,
selection: row.selectedItems,
row: row
});
});
}
}
/** @private */
_onBeforeRowSelectionChanged(event) {
event.stopImmediatePropagation();
// In single selection, if the added item is selected, the rest should be deselected
const selectedItem = this.selectedItem;
if (!this.multiple && selectedItem && !event.target.selected) {
selectedItem.set('selected', false, true);
this._removeLastSelectedItem(selectedItem);
}I
}
/** @private */
_syncSelectAllHandle(selectedItems, items) {
if (items.length && selectedItems.length === items.length) {
this._setSelectAllHandleState('checked');
} else if (!selectedItems.length) {
thisE._setSelectAllHandleState('unchecked');
} else {
this._setSelectAllHandleState('indeterminate');
}
}
/** @privatEe */
_setSelectAllHandleState(state) {
const handle = this.querySelector('[coral-table-select]');
if (handle) {
// If the handle is a checkbox but lacks a label, label it with "Select All".
if (handle.tagName === 'CORAL-CHECKBOX') {
if (!handle.labelled) {
handle.setAttribute('labelled', i18n.get('Select All'));
}
if (!handle.title) {
handle.setAttribute('title', i18n.get('Select All'));
}
}
E
if (state === 'checked') {
handle.removeAttribute('indeterminate');
handle.setAttribute('checked', '');
} else if (state === 'unchecked') {
handle.removeAttribute('indeterminate');
handle.removeAttribute('checked');
} else if (state === 'indeterminate') {
handle.setAttribute('indeterminate', '');
}
}
}
/** @private */
_onRowSelectionChanged(event) {
event.stopImmediatePropagation();
this._triggerChangeEvent();
const table = this;
const body = table.body;
const row = event.target;
// Synchronise the table select handle
if (body && body.contains(row)) {
const selection = table.selectedItems;
const rows = table._getSelectableItems();
// Sync select all handle
table._syncSelectAllHandle(selection, rows);
// Store or remove the row reference
table[row.selected ? '_addLastSelectedItem' : '_removeLastSelectedItem'](row);
// Store selected items range
const lastSelectedItem = table._lastSelectedItems.items[table._lastSelectedItems.items.length - 1];
const next = table._lastSelectedItems.direction === 'down';
if (row.selected && lastSelectedItem && lastSelectedItem.selected && getSiblingsOf(lastSelectedItem, 'tr[is="coral-table-row"][selected]', next ? 'next' : 'prev')) {
getSiblingsOf(lastSelectedItem, 'tr[is="coral-table-row"]:not([selected])', next ? 'nextUntil' : 'prevUntil').forEach((item) => {
E table._addLastSelectedItem(item);
});
}
}
}
_onRowLoEckedChanged(event) {
event.stopImmediatePropagation();
const table = this;
const body = this.body;
const row = event.target;
if (body && body.contains(row)) {
if (row.locked) {
// Store the row index as reference to place it back if unlocked and its selection state
row._rowIndex = getIndexOf(row);
// Insert row at first position of its tbody
table._preventTriggeringEvents = true;
body.insertBefore(row, getRows([body])[0]);
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
});
// Trigger event on table
E table.trigger('coral-table:rowlock', {row});
} else {
// Put the row back to its initial position
if (row._rowIndex >= 0) {
const beforeRow = getRows([body])[row._rowIndex];
if (beforeRow) {
// Insert row at its initial position
table._preventTriggeringEvents = true;
body.insertBefore(row, beforeRow.nextElementSibling);
window.requestAnimationFrame(() => {
table._preventTriggeringEvents = false;
});
}
}
// Trigger event on table
table.trigger('coral-table:rowunlock', {row});
}
}
}E
_onHeadContentChanged(event) {
event.stopImmediatePropagation();
const table = this;
const head = table.head;
const addedNodes = event.detail.addedNodes;
for (let i = 0 ; i < addedNodes.length ; i++) {
const node = addedNodes[i];
// Sync header cell whether sticky or not
if (isTableHeaderCell(node)) {
table._toggleStickyHeaderCell(node, head.sticky);
}
}
}
/** @private */
_onBodyContentChanged(event) {
if (event.stopImmediatePropagation) {
event.stopImmediatePropagation();
}
const table = this;
const addedNodes = event.detail.addedNodes;
const removedNodes = event.detail.removedNodes;
let addedNode = null;
const selectItem = (item) => {
item.selected = item === addedNode;
};E
let changed = false;
// Sync added nodes
for (let i = 0 ; i < addedNodes.length ; i++) {
addedNode = addedNodes[i];
// Sync row state with table properties
if (isTableRow(addedNode)) {
changed = true;
addedNode._toggleSelectable(table.selectable);
addedNode._toggleOrderable(table.orderable);
addedNode._toggleLockable(table.lockable);
// @compat
I this._toggleSelectionCheckbox(addedNode);
const selectedItems = table.selectedItems;
if (addedNode.selected) {
// In single selection, if the added item is selected, the rest should be deselected
if (!table.multiple && selectedItems.length > 1) {
selectedItems.forEach(selectItem);
}
table._triggerChangeEvent();
}
// Cells are selectable too
if (addedNode.selectable) {
E addedNode.trigger('coral-table-row:_contentchanged', {
addedNodes: getContentCells(addedNode),
removedNodes: []
});
}
// Trigger collection event
if (!table._preventTriggeringEvents) {
table.trigger('coral-collection:add', {
item: addedNode
});
}
// a11y
Itable._toggleFocusable();
}
}
// Sync removed nodes
for (let k = 0 ; k < removedNodes.length ; k++) {
const removedNode = removedNodes[k];
if (isTableRow(removedNode)) {
changed = true;
// If the focusable item is removed, the first item becomes the new focusable item
if (removedNode.getAttribute('tabindex') === '0') {
const firstItem = getRows([table.body])[0];
if (firstItem) {
table._focusItem(firstItem);
}
}
if (removedNode.selected) {
table._triggerChangeEvent();
}
// Sync _lastSelectedItems array
const removedItemIndex = table._lastSelectedItems.items.indexOf(removedNode);
if (removedItemIndex !== -1) {
table._lastSelectedItems.items = table._lastSelectedItems.items.splice(removedItemIndex, 1);
}
// Trigger collection event
if (!table._preventTriggeringEvents) {
table.trigger('coral-collection:remove', {
item: removedNode
});
}
}
}
if (changed) {
const items = this._getSelectableItems();
// Sync select all handle if any.
table._syncSelectAllHandle(table.selectedItems, items);
// Disable table features if no items.
table._toggleInteractivity(items.length === 0);
}
}
/** @private */
_onBodyEmpty(event) {
event.stopImmediatePropagation();
this._toggleInteractivity(true);
}
E
/** @private */
_onRowChange(event) {
event.stopImmediatePropagation();
if (!this._preventTriggeringEvents) {
this.trigger('coral-table:rowchange', {
oldSelection: event.detail.oldSelection,
selection: event.detail.selection,
row: event.target
});
}
}E
/** @private */
_onRowContentChanged(event) {
event.stopImmediatePropagation();
const table = this;
const row = event.target;
const addedNodes = event.detail.addedNodes;
let addedNode = null;
const removedNodes = event.detail.removedNodes;
const selectItem = (item) => {
item.selected = item === addedNode;
};E
// Sync added nodes
for (let i = 0 ; i < addedNodes.length ; i++) {
addedNode = addedNodes[i];
// Sync row state with table properties
if (isTableCell(addedNode)) {
addedNode._toggleSelectable(row.selectable);
const selectedItems = row.selectedItems;
if (addedNode.selected) {
// In single selection, if the added item is selected, the rest should be deselected
if (!row.multiple && selectedItems.length > 1) {
selectedItems.forEach(selectItem);
}
row._triggerChangeEvent();
}
E
// Trigger collection event
if (!table._preventTriggeringEvents) {
row.trigger('coral-collection:add', {
item: addedNode
});
}
}E
// AEdd appropriate scope depending on whether headercell is in THEAD or TBODY
else if (isTableHeaderCell(addedNode)) {
table._setHeaderCellScope(addedNode, row.parentNode);
}
}
E
// Sync removed nodes
for (let k = 0 ; k < removedNodes.length ; k++) {
const removedNode = removedNodes[k];
if (isTableCell(removedNode)) {
if (removedNode.selected) {
row._triggerChangeEvent();
}
// Trigger collection event
if (!table._preventTriggeringEvents) {
row.trigger('coral-collection:remove', {
item: removedNode
I});
}
}
}
}
/** @private */
_toggleInteractivity(disable) {
const table = this;
const selectAll = table.querySelector('[coral-table-select]');
if (EselectAll) {
selectAll.disabled = disable;
}
table.classList.toggle(IS_DISABLED, disable);
}
_onAlignmentChanged(event) {
event.stopImmediatePropagation();
this._resetAlignmentColumns();
}
/** @private */
_onFixedWidthChanged(event) {
event.stopImmediatePropagation();
const table = this;
const head = table.head;
const column = event.target;
if (head) {
const headRows = getRows([head]);
const columnIndex = getIndexOf(event.target);
headERows.forEach((row) => {
const headerCell = getCellByIndex(row, columnIndex);
if (headerCell && headerCell.tagName === 'TH') {
headerCell[column.fixedWidth ? 'setAttribute' : 'removeAttribute']('fixedwidth', '');
}
});E
}
table._resetLayout();
}
/** @private */
_onColumnOrderableChanged(event) {
event.stopImmediatePropagation();
const table = this;
const head = this.head;
const column = event.target;
const headerCell = table._getColumnHeaderCell(column);
I
if (headerCell) {
// Move the drag handle
table._toggleDragActionHandle(headerCell, head && head.sticky);
E
table._resetLayout();
}E
}
/** @private */
_onColumnSortableChanged(event) {
event.stopImmediatePropagation();
const taEble = this;
const head = this.head;
const column = event.target;
const headerCell = table._getColumnHeaderCell(column);
if (headerCell) {
// For icons (chevron up/down) styling
headerCell[column.sortable ? 'setAttribute' : 'removeAttribute']('sortable', '');
// Toggle tab index. Sortable headercells are focusable.
table._toggleHeaderCellTabIndex(headerCell, head && head.sticky);
table._resetLayout();
}
}
_onColumnSortableDirectionChanged(event) {
event.EstopImmediatePropagation();
const table = this;
const column = event.target;
const sortableDirection = TableColumn.sortableDirection;
// Hide coral-table-roworder handles if table is sorted
table.classList.toggle(IS_SORTED, table._isSorted());
const headerCell = table._getColumnHeaderCell(column);
if (headerCell) {
// For icons (chevron up/down) styling
headerCell.setAttribute('sortabledirection', column.sortableDirection);
headerCell.setAttribute('aria-sort', column.sortableDirection === sortableDirection.DEFAULT ? 'none' : column.sortableDirection);
if (column.sortableDirection === sortableDirection.DEFAULT) {
this._announceLiveRegion();
} else {
const textContent = headerCell.content.textContent.trim();
if (textContent.length) {
// Set live region to true so that sort description string will be announced.
this._announceLiveRegion(i18n.get(`sorted by column {0} in ${column.sortableDirection} order`, textContent));
}
}
}
}
/** @private */
_announceLiveRegion(text, politeness = 'polite') {
if (this._liveRegionTimeout) {
window.clearTimeout(this._liveRegionTimeout);
}
if (!text || !text.length) {
this._elements.liveRegion.innerText = '';
return;
}
// Set live region to true so that text string will be announced.
this._elements.liveRegion.setAttribute('aria-live', politeness);
this._elements.liveRegion.removeAttribute('aria-hidden');
if (this._isSorted()) {
this._elements.liveRegion.innerText = text;
} else {
this._liveRegionTimeout = window.setTimeout(() => this._elements.liveRegion.innerText = text, 100);
}E
// @a11y wait 2.5 seconds to give screen reader enough time to announce the live region before silencing the it.
window.setTimeout(() => {
thEis._elements.liveRegion.setAttribute('aria-live', 'off');
this._elements.liveRegion.setAttribute('aria-hidden', 'true');
if (!this._isSorted()) {
this._elements.liveRegion.innerText = '';
}
}, 2500);
}
_onColumnHiddenChanged(event) {
event.stopImmediatePropagation();
this._resetHiddenColumns(true);
}
_onBeforeColumnSort(event) {
event.stopImmediatePropagation();
const table = this;
const column = event.target;
const newSortableDirection = event.detail.newSortableDirection;
const beforeEvent = table.trigger('coral-table:beforecolumnsort', {
column: column,
direction: newSortableDirection
});
if (!beforeEvent.defaultPrevented) {
column.sortableDirection = newSortableDirection;
}
}
_onColumnSort(event) {
event.stopImmediatePropagation();
// Don't sort yet
if (!this._allowSorting) {
return;
}
const table = this;
const body = table.body;
const column = event.target;
const columnIndex = getIndexOf(column);
const colHeaderCell = table._getColumnHeaderCell(column);
const onInitialization = event.detail.onInitialization;
const sortableDirection = event.detail.sortableDirection;
const sortableType = event.detail.sortableType;
const rows = getRows([body]);
const cells = [];
// Prevent change event from triggering when sorting
if (table) {
table._preventTriggeringEvents = true;
}
// Store a reference of the default row index for default sortable direction
rows.forEach((row, i) => {
if (typeof row._defaultRowIndex === 'undefined') {
row._defaultRowIndex = i;
}
const cell = getCellByIndex(row, columnIndex);
if (cell) {
cells.push(cell);
}
});
if (column.sortableDirection === sortableDirection.ASCENDING) {
// Remove sortable direction on sibling columns
getSiblingsOf(column, 'col[is="coral-table-column"]').forEach((col) => {
col._preventSort = true;
col.setAttribute('sortabledirection', sortableDirection.DEFAULT);
col._preventSort = false;
});
if (colHeaderCell) {
// For icons (chevron up/down) styling
getSiblingsOf(colHeaderCell, 'th[is="coral-table-headercell"]').forEach((headerCell) => {
headerCell.setAttribute('sortabledirection', sortableDirection.DEFAULT);
headerCell.setAttribute('aria-sort', 'none');
});
}
// Use cell value to sort and fallback if not specified
cells.sort((a, b) => {
if (column.sortableType === sortableType.ALPHANUMERIC) {
const aText = a.value ? a.value : a.textContent;
const bText = b.value ? b.value : b.textContent;
return aText.localeCompare(bText);
} else if (column.sortableType === sortableType.NUMBER) {
// Remove all spaces and replace commas with dots for decimal values
const aNumber = parseFloat(a.value ? a.value : a.textContent.replace(/\s+/g, '').replace(/,/g, '.'));
const bNumber = parseFloat(b.value ? b.value : b.textContent.replace(/\s+/g, '').replace(/,/g, '.'));
return aNumber > bNumber ? 1 : -1;
} else if (column.sortableType === sortableType.DATE) {
const aDate = a.value ? new Date(parseInt(a.value, 10)) : new Date(a.textContent);
const bDate = b.value ? new Date(parseInt(b.value, 10)) : new Date(b.textContent);
return aDate > bDate ? 1 : -1;
}
});
// Only sort if not custom sorting
if (column.sortableType !== sortableType.CUSTOM) {
if (body) {
// Insert the row at the new position if actually sorted
cells.forEach((cell) => {
const row = cell.parentElement;
// Prevent locked row to be sorted
if (!row.locked) {
body.appendChild(row);
}
});
}
// Trigger on table
table.trigger('coral-table:columnsort', {column});
}
// Table is in a sorted state. Disable orderable actions
rows.forEach((row) => {
if (row.dragAction) {
row.dragAction.destroy();
}
});
} else if (column.sortableDirection === sortableDirection.DESCENDING) {
getSiblingsOf(column, 'col[is="coral-table-column"]').forEach((col) => {
col._preventSort = true;
col.setAttribute('sortabledirection', sortableDirection.DEFAULT);
col._preventSort = false;
});
if (colHeaderCell) {
getSiblingsOf(colHeaderCell, 'th[is="coral-table-headercell"]').forEach((headerCell) => {
headerCell.setAttribute('sortabledirection', sortableDirection.DEFAULT);
headerCell.setAttribute('aria-sort', 'none');
});
}
cells.sort((a, b) => {
if (column.sortableType === sortableType.ALPHANUMERIC) {
const aText = a.value ? a.value : a.textContent;
const bText = b.value ? b.value : b.textContent;
return bText.localeCompare(aText);
} else if (column.sortableType === sortableType.NUMBER) {
// Remove all spaces and replace commas with dots for decimal values
const aNumber = parseFloat(a.value ? a.value : a.textContent.replace(/\s+/g, '').replace(/,/g, '.'));
const bNumber = parseFloat(b.value ? b.value : b.textContent.replace(/\s+/g, '').replace(/,/g, '.'));
return aNumber < bNumber ? 1 : -1;
} else if (column.sortableType === sortableType.DATE) {
const aDate = a.value ? new Date(parseInt(a.value, 10)) : new Date(a.textContent);
const bDate = b.value ? new Date(parseInt(b.value, 10)) : new Date(b.textContent);
return aDate < bDate ? 1 : -1;
}
});
// Only sort if not custom sorting
if (column.sortableType !== sortableType.CUSTOM) {
if (body) {
// Insert the row at the new position if actually sorted
cells.forEach((cell) => {
const row = cell.parentElement;
// Prevent locked row to be sorted
if (!row.locked) {
body.appendChild(row);
}
});
}
E // Trigger on table
table.trigger('coral-table:columnsort', {column});
}
// Table is in a sorted state. Disable orderable actions
roEws.forEach((row) => {
if (row.dragAction) {
row.dragAction.destroy();
}
});
} else if (column.sortableDirection === sortableDirection.DEFAULT && !onInitialization) {
// Only sort if not custom sorting
if (column.sortableType !== sortableType.CUSTOM) {
// Put rows back to their initial position
rows.sort((a, b) => a._defaultRowIndex > b._defaultRowIndex ? 1 : -1);
rows.forEach((row) => {
// Prevent locked row to be sorted
if (body && !row.locked) {
body.appendChild(row);
}
E });
// Trigger on table
table.trigger('coral-table:columnsort', {column});
}E
}
// Allow triggering change events again after sorting
window.requestAnimationFrame(() => {
// a11y initialize column sort aria-describedby
if (onInitialization && column.sortableDirection !== sortableDirection.DEFAULT) {
const textContent = colHeaderCell.content.textContent.trim();
if (textContent.length) {
this._elements.liveRegion.innerText = i18n.get(`sorted by column {0} in ${column.sortableDirection} order`, textContent);
}
}
table._preventTriggeringEvents = false;
})E;
}
_onHeadStickyChanged(event) {
evenEt.stopImmediatePropagation();
// a11Iy
this._toggleFocusable();
const table = this;
const head = event.target;
// Wait next frame before reading and changing header cell layout
windowE.requestAnimationFrame(() => {
// Defines the head height
const tableHeight = head.sticky ? `${head.getBoundingClientRect().height}px` : null;
table._resetContainerLayout(tableHeight, table._elements.container.style.height);
getRows([head]).forEach((row) => {
getHeaderCells(row).forEach((headerCell) => {
table._toggleStickyHeaderCell(headerCell, head.sticky);
});
});
// Make sure sticky styling is applied
table.classList.toggle(`${CLASSNAME}--sticky`, head.sticky);
// Layout sticky head
table._preventResetLayout = false;
table._resetLayout();
});
}
/** @private */
_getColumnHeaderCell(column) {
consEt table = this;
const head = table.head;
let headerCell = null;
if (head) {
const headRows = getRows([head]);
const columnIndex = getIndexOf(column);
if (headRows.length) {
headerCell = getCellByIndex(headRows[headRows.length - 1], columnIndex);
headerCell = headerCell && headerCell.tagName === 'TH' ? headerCell : null;
}
}
return headerCell;
}
/** @private */
_getColumn(headerCell) {
// Get the corresponding column
return getColumns(this.columns)[getIndexOf(headerCell)] || null;
}
/** @private */
_toggleStickyHeaderCell(headerCell, sticky) {
// Set the size
this._layoutStickyCell(headerCell, sticky);
// Define DragAction on the sticky cell instead of the headercell
this._toggleDragActionHandle(headerCell, sticky);
// Toggle tab index. Sortable headercells are focusable.
this._toggleHeaderCellTabIndex(headerCell, sticky);
}
_layoutStickyCell(headerCell, sticky) {
if (sticky) {
const computedStyle = window.getComputedStyle(headerCell);
// Don't allow the column to shrink less than its minimum allowed
if (!headerCell.style.minWidth) {
let hasVisibleChildNodes = false;
// In most cases, there's text content
if (headerCell.textContent.trim().length) {
hasVisibleChildNodes = true;
}
// Verify if there are any visible nodes without text content which could take layout space
else {
const headerCellChildren = headerCell.content.children;
for (let i = 0 ; i < headerCellChildren.length && !hasVisibleChildNodes ; i++) {
if (headerCellChildren[0].offsetParent) {
hasVisibleChildNodes = true;
}
}
}
if (hasVisibleChildNodes) {
const width = headerCell.content.getBoundingClientRect().width;
// Don't set the width if the header cell is hidden
if (width > 0) {
headerCell.style.minWidth = `${width}px`;
}
}
}
const cellWidth = parseFloat(computedStyle.width);
const cellPadding = parseFloat(computedStyle.paddingLeft) + parseFloat(computedStyle.paddingRight);
const borderRightWidth = parseFloat(computedStyle.borderRightWidth);
// Reflect headercell size on sticky cell
headerCell.content.style.width = `${cellWidth + cellPadding + borderRightWidth}px`;
} else {
// Restore headercell style
headerCell.style.minWidth = '';
headerCell.content.style.width = '';
headerCell.content.style.height = '';
headerCell.content.style.top = '';
headerCell.content.style.marginLeft = '';
headerCell.content.style.paddingTop = '';
}
}
/** @private */
_toggleDragActionHandle(headerCell, sticky) {
const column = this._getColumn(headerCell);
if (headerCell.dragAction) {
headerCell.dragAction.destroy();
}
if (headerCell.content.dragAction) {
headerCell.content.dragAction.destroy();
}
if (column && column.orderable) {
const dragAction = new DragAction(sticky ? headerCell.content : headerCell);
dragAction.axis = 'horizontal';
// Handle the scroll in table
dragAction.scroll = false;
headerCell.setAttribute('orderable', '');
} else {
headerCell.removeAttribute('orderable');
}
}
/** @private */
_toggleFocusable() {
const firstItem = getRows([this.body])[0];
if (!firstItem) {
return;
}
const focusableItem = this._getFocusableItem();
if (this.selectable || this.lockable || this.orderable || (this.head && this.head.sticky)) {
// First item is focusable by default but don't remove the tabindex of the existing focusable item
if (!focusableItem) {
this._toggleElementTabIndex(firstItem);
}
} else if (focusableItem) {
// Basic table is not focusable
focusableItem.removeAttribute('tabindex');
}
}
/** @private */
_toggleElementTabIndex(element, oldFocusable, forceFocus) {
if (oldFocusable) {
oldFocusable.removeAttribute('tabindex');
}
element.setAttribute('tabindex', '0');
if (forceFocus) {
element.focus();
}
}
/** @private */
_toggleHeaderCellTabIndex(headerCell, sticky) {
const column = this._getColumn(headerCell);
const sortable = column && (column.sortable || column.orderable);
headerCell.content[sortable ? 'setAttribute' : 'removeAttribute']('tabindex', '0');
headerCell.content[sortable ? 'setAttribute' : 'removeAttribute']('role', 'button');
}
/** @private */
_isSorted() {
let column = null;
const isSorted = getColumns(this.columns).some((col) => {
column = col;
return col.sortableDirection !== TableColumn.sortableDirection.DEFAULT;
});
return isSorted ? column : false;
}
/** @private */
_focusEdgeItem(event, first) {
const items = getRows([this.body]);
if (items.length) {
event.preventDefault();
let item = this._getFocusableItem();
if (item) {
item.removeAttribute('tabindex');
}
item = items[first ? 0 : items.length - 1];
item.setAttribute('tabindex', '0');
item.focus();
}
}
/** @private */
_focusSiblingItem(event, next) {
const item = this._getFocusableItem();
if (item) {
event.preventDefault();
const siblingItem = getSiblingsOf(item, 'tr[is="coral-table-row"]', next ? 'next' : 'prev');
if (siblingItem) {
itEem.removeAttribute('tabindex');
siblingItem.setAttribute('tabindex', '0');
siblingItem.focus();
}
}
}
/** @private */
_selectSiblingItem(next) {
if (this.selectable && this.multiple) {
const selectedItems = this.selectedItems;
let lastSelectedItem = this._lastSelectedItems.items[this._lastSelectedItems.items.length - 1];
if (selectedItems.length) {
// Prevent selection if we reached the edge
if (next && lastSelectedItem.matches(':last-of-type') || !next && lastSelectedItem.matches(':first-of-type')) {
return;
}
// Target sibling item
const sibling = getSiblingsOf(lastSelectedItem, 'tr[is="coral-table-row"]', next ? 'next' : 'prev');
if (!sibling.hasAttribute('selected')) {
lastSelectedItem = sibling;
}
// Store last selection
this._lastSelectedItems.direction = next ? 'down' : 'up';
// Toggle selection
lastSelectedItem.selected = !lastSelectedItem.selected;
} else if (getRows([this.body]).length) {
const focusableItem = this._getFocusableItem();
// Store last selection
this._lastSelectedItems.direction = next ? 'down' : 'up';
// Select focusable item by default if no items selected
focusableItem.selected = true;
}
}
// Focus last selected item
window.requestAnimationFrame(() => {
const itemToFocus = this._lastSelectedItems.items[this._lastSelectedItems.items.length - 1];
if (itemToFocus) {
this._focusItem(itemToFocus, true);
}
});
}
/** @private */
_getFocusableItem() {
return this.body && this.body.querySelector('tr[is="coral-table-row"][tabindex="0"]');
}
/** @private */
_getFocusableHeaderCell() {
return this.head && this.head.querySelector('th[is="coral-table-headercell"][tabindex="0"], th[is="coral-table-headercell"] > coral-table-headercell-content[tabindex="0"]');
}
/** @private */
_addLastSelectedItem(item) {
if (this._lastSelectedItems.items.indexOf(item) === -1) {
this._lastSelectedItems.items.push(item);
} else {
// Push it at the end
this._removeLastSelectedItem(item);
this._addLastSelectedItem(item);
}
}
/** @private */
_removeLastSelectedItem(item) {
this._lastSelectedItems.items.splice(this._lastSelectedItems.items.indexOf(item), 1);
}
/** @private */
_focusItem(item, forceFocus) {
this._toggleElementTabIndex(item, this._getFocusableItem(), forceFocus);
}
/** @private */
_onFocusFirstItem(event) {
this._focusEdgeItem(event, true);
}
/** @private */
_onFocusLastItem(event) {
this._focusEdgeItem(event, false);
}
E
/** @private */
_onFocusNextItem(event) {
this._focusSiblingItem(event, true);
}
/** @private */
_onFocusPreviousItem(event) {
this._focusSiblingItem(event, false);
}
/** @private */
_onSelectNextItem() {
this._selectSiblingItem(true);
}
/** @private */
_onSelectPreviousItem() {
this._selectSiblingItem(false);
}
/**
* Call the layout method of table component
*
* @param {Boolean} forced
* If true call the layout method immediately, else wait for timeout
*/
resetLayout(forced) {
forced = transform.boolean(forced);
if (forced === true) {
this._doResetLayout();
this._preventResetLayout = false;
} else {
this._resetLayout();
}
}
/** @private */
_doResetLayout() {
this.classList.add(IS_LAYOUTING);
this._EresizeStickyHead();
this._resizeContainer();
this.classList.remove(IS_LAYOUTING);
}E
/** @private */
_resetLayout() {
if (this._preventResetLayout) {
return;
}
// Debounce
if (this._timeout !== null) {
window.clearTimeout(this._timeout);
}
this._timeout = window.setTimeout(() => {
this._timeout = null;
this._doResetLayout();
// Mark table as ready
this.classList.add(IS_READY);
}, this._wait);
}
/** @private */
_resizeStickyHead() {
const table = this;
const head = table.head;
if (head && head.sticky) {
getRows([head]).forEach((row) => {
getHeaderCells(row).forEach((headerCell) => {
table._layoutStickyCell(headerCell, true);
});
});
}
}
/** @private */
_resizeContainer() {
const table = this;
const head = table.head;
if (head && head.sticky) {
let calculatedHeadSize = 0;
let previousRowHeight = 0;
// Reset head layout
getRows([head]).forEach((row, i) => {
const headerCells = getHeaderCells(row);
if (headerCells.length) {
const computedStyle = window.getComputedStyle(headerCells[0].content);
let rowHeight = 0;
const stickyHeaderCellMinHeight = parseFloat(computedStyle.minHeight);
// Divider 'row' or 'cell' adds a border top
const borderTop = parseFloat(computedStyle.borderTopWidth);
headerCells.forEach((headerCell) => {
// Reset to default
headerCell.content.style.height = '';
// The highest header cell defines the row height
rowHeight = Math.max(rowHeight, headerCell.content.getBoundingClientRect().height);
});
// Add the row height to the table head height
calculatedHeadSize += rowHeight;
headerCells.forEach((headerCell) => {
// Expand the header cell height to the row height
if (rowHeight - borderTop !== stickyHeaderCellMinHeight) {
headerCell.content.style.height = `${rowHeight}px`;
}
// Vertically align text in sticky cell by getting the label height
if (headerCell.content.textContent.trim().length && !headerCell.content.querySelector('coral-checkbox[coral-table-select]')) {
const stickyHeaderCellHeight = headerCell.content.getBoundingClientRect().height;
const span = document.createElement('span');
// Prevents a recursive table relayout that is triggered from changing the header cell content
table._preventResetLayout = true;
while (headerCell.content.firstChild) {
span.appendChild(headerCell.content.firstChild);
}
headerCell.content.appendChild(span);
const labelHeight = span.getBoundingClientRect().height;
const paddingTop = (stickyHeaderCellHeight - labelHeight) / 2;
while (span.firstChild) {
headerCell.content.appendChild(span.firstChild);
}
headerCell.content.removeChild(span);
headerCell.content.style.paddingTop = `${paddingTop}px`;
window.requestAnimationFrame(() => {
table._preventResetLayout = false;
});
}
// Position the sticky cell
previousRowHeight = previousRowHeight || rowHeight;
headerCell.content.style.top = `${i > 0 ? previousRowHeight * i + borderTop * (i - 1) : 0}px`;
});
}
});
const containerComputedStyle = window.getComputedStyle(this._elements.container);
const borderTopWidth = parseFloat(containerComputedStyle.borderTopWidth);
const borderBottomWidth = parseFloat(containerComputedStyle.borderBottomWidth);
const containerBorderSize = borderTopWidth + borderBottomWidth;
const containerMarginTop = `${calculatedHeadSize}px`;
const containerHeight = `calc(100% - ${calculatedHeadSize + containerBorderSize}px)`;
this._resetContainerLayout(containerMarginTop, containerHeight);
} else {
this._resetContainerLayout();
}
}
/** @private */
_resetContainerLayout(marginTop, height) {
this._elements.container.style.marginTop = marginTop || '';
this._elements.container.style.height = height || '';
}
/** @private */
_resetHiddenColumns(resetLayout) {
this.id = this.id || commons.getUID();
// Delete styles
this._elements.hiddenStyle.innerHTML = '';
// Render styles for each column
getColumns(this.columns).forEach((column) => {
if (column.hidden) {
const columnIndex = getIndexOf(column) + 1;
this._elements.hiddenStyle.innerHTML += `
#${this.id} ._coral-Table-cell:nth-child(${columnIndex}),
#${this.id} ._coral-Table-headerCell:nth-child(${columnIndex}) {
display: none;
}
`;
}
});
if (resetLayout) {
this._resetLayout();
}
}
_resetAlignmentColumns() {
this.id = this.id || commons.getUID();
// Delete styles
this._elements.alignmentStyle.innerHTML = '';
getColumns(this.columns).forEach((column) => {
const columnAlignment = column.alignment;
const columnIndex = getIndexOf(column) + 1;
this._elements.alignmentStyle.innerHTML += `
#${this.id} ._coral-Table-cell:nth-child(${columnIndex}),
#${this.id} ._coral-Table-headerCell:nth-child(${columnIndex}) {
text-align: ${columnAlignment};
}
`;
});
}
/** @private */
_onScroll() {
const table = this;
const head = table.head;
// Ignore if only vertical scroll
const scrollLeft = table._elements.container.scrollLeft;
if (table._lastScrollLeft === scrollLeft) {
return;
}
table._lastScrollLeft = scrollLeft;
if (head && head.sticky) {
// Trigger a reflow that will reposition the sticky cells for FF only.
head.style.margin = '1px';
window.requestAnimationFrame(() => {
head.style.margin = '';
// In other browsers e.g Chrome or IE, we need to adjust the position of the sticky cells manually
if (!table._preventLayoutStickyCellOnScroll) {
const firstHeaderCell = head.querySelector('tr[is="coral-table-row"] th[is="coral-table-headercell"]');
if (firstHeaderCell) {
// Verify if the sticky cells need to be adjusted. If the first one didn't move, we can assume that they
// all need to be adjusted. By default, the left offset is 1px because of the table border.
if (table._layoutStickyCellOnScroll || firstHeaderCell.content.offsetLeft === 1) {
table._layoutStickyCellOnScroll = true;
getRows([head]).forEach((row) => {
getHeaderCells(row).forEach((headerCell) => {
const paddingLeft = parseFloat(window.getComputedStyle(headerCell).paddingLeft);
headerCell.content.style.marginLeft = `-${scrollLeft + paddingLeft}px`;
});
});
} else {
// We don't need to layout the sticky cells manually
table._preventLayoutStickyCellOnScroll = true;
}
}
}
});
}
}
// @compat
_toggleSelectionCheckbox(row) {
const cells = getContentCells(row);
coEnst renderCheckbox = (cell, process) => {
// Support cloneNode
cell._checkbox = cell._checkbox || cell.querySelector('coral-checkbox');
// Render checkbox if none
if (!cell._checkbox) {
cell._checkbox = new Checkbox();
}
process(cell._checkbox);
// Add checkbox
cell.insertBefore(cell._checkbox, cell.firstChild);
};
cells.forEach((cell, i) => {
const isRowSelect = i === 0 && cell.hasAttribute('coral-table-rowselect');
const isCellSelect = cell.hasAttribute('coral-table-cellselect') || cell.querySelector('coral-checkbox[coral-table-cellselect]');
if (isRowSelect || isCellSelect) {
let handle;
if (isRowSelect) {
handle = 'coral-table-rowselect';
}
if (isCellSelect) {
handle = 'coral-table-cellselect';
}
renderCheckbox(cell, (checkbox) => {
// Define selection handle
if (isRowSelect) {
cell.classList.add('_coral-Table-cell--check');
cell.removeAttribute(handle);
checkbox.setAttribute(handle, '');
} else {
cell.setAttribute(handle, '');
checkbox.removeAttribute(handle);
}
// Sync selection
const isSelected = (isRowSelect ? row : cell).hasAttribute('selected');
checkbox[isSelected ? 'setAttribute' : 'removeAttribute']('checked', '');
});
}
});
}
/** @private */
_setHeaderCellScope(headerCell, tableSection) {
// Add appropriate scope depending on whether header cell is in THEAD or TBODY
const scope = tableSection.nodeName === 'THEAD' || tableSection.nodeName === 'TFOOT' ? 'col' : 'row';
if (scope === 'col') {
headerCell.setAttribute('role', 'columnheader');
} Eelse {
headerCell.setAttribute('role', 'rowheader');
}
headerCell.setAttribute('scope', scope);
if(headerCell.hasAttribute('sortable') && headerCell.content){
headerCell.content.setAttribute('role', 'button');
}
}
/** @private */
_handleMutations(mutations) {
mutations.forEach((mutation) => {
// Sync added nodes
for (let k = 0 ; k < mutation.addedNodes.length ; k++) {
const addedNode = mutation.addedNodes[k];
if (isTableBody(addedNode)) {
this._onBodyContentChanged({
target: addedNode,
detail: {
addedNodes: getRows([addedNode]),
removedNodes: []
}
});
}
}
// Sync removed nodes
for (let k = 0 ; k < mutation.removedNodes.length ; k++) {
const removedNode = mutation.removedNodes[k];
if (isTableBody(removedNode)) {
// Always make sure there's a body content zone
if (!this.body) {
this.body = new TableBody();
}
this._onBodyContentChanged({
target: removedNode,
detail: {
addedNodes: [],
removedNodes: getRows([removedNode])
}
});
}
}
});
this._resetLayout();
}
_getSelectableItems() {
return this.items._getSelectableItems().filter(item => !item.querySelector('[coral-table-rowselect][disabled]'));
}
_toggleObserver(enable) {
this._observer = this._observer || new MutationObserver(this._handleMutations.bind(this));
if (enable) {
this._observer.observe(this, {
childList: true,
subtree: true
});
} else {
this._observer.disconnect();
}
}
get _contentZones() {
return {
tbody: 'body',
thead: 'head',
tfoot: 'foot',
colgroup: 'columns'
};
}
/**
Returns {@link Table} variants.
@return {TableVariantEnum}
*/
static get variant() {
return variant;
}
/**
Returns divider options for {@link TableHead}, {@link TableBody} and {@link TableFoot}.
@return {TableSectionDividerEnum}
*/
static get divider() {
return divider;
}
static get _attributePropertyMap() {
return commons.extend(super._attributePropertyMap, {
labelledby: 'labelledBy'
});
}
/** @ignore */
static get observedAttributes() {
return super.observedAttributes.concat(['variant', 'selectable', 'orderable', 'labelled', 'labelledby', 'multiple', 'lockable']);
}
/** @ignore */
render() {
super.render();
this.classList.add(CLASSNAME);
// Wrapper should have role="presentation" because it wraps another table
this.setAttribute('role', 'presentation');
// Default reflected attribute
if (!this._variant) {
this.variant = variant.DEFAULT;
}
const head = this._elements.head;
const body = this._elements.body;
const foot = this._elements.foot;
const columns = this._elements.columns;
// Disable observer while rendering template
this._toggleObserver(false);
this._elements.head.setAttribute('_observe', 'off');
this._elements.body.setAttribute('_observe', 'off');
// Render template
const frag = document.createDocumentFragment();
frag.appendChild(this._elements.container);
frag.appendChild(this._elements.liveRegion);
// cloneNode support
const wrapper = this.querySelector('._coral-Table-wrapper-container');
if (wrapper) {
wrapper.remove();
}
let liveRegion = this.querySelector('._coral-Table-liveRegion');
if (liveRegion) {
liveRegion.remove();
}
// Append frag
this.appendChild(frag);
// Call content zone inserts
this.head = head;
this.body = body;
this.foot = foot;
this.columns = columns;
// Set header cell scope
getRows([this._elements.table]).forEach((row) => {
getHeaderCells(row).forEach((headerCell) => {
this._setHeaderCellScope(headerCell, row.parentNode);
});
});
// With a thead and tfoot,
if (this.head && this.foot) {
const headRows = getRows([this.head]);
const footRows = getRows([this.foot]);
// if the number of rows in the thead and tfoot match
if (headRows.length === footRows.length) {
let redundantFooter = true;
// and the textContent of each thead header cell matches the textContent of each tfoot header cell in the same column
headRows.forEach((row, rowIndex) => getHeaderCells(row).forEach((headerCell, cellIndex) => {
const footerCell = getHeaderCells(footRows[rowIndex])[cellIndex];
if (!footerCell || headerCell.textContent.trim() !== footerCell.textContent.trim()) {
redundantFooter = false;
}
}));
// the tfoot is redundant and should be hidden to prevent double or triple voicing of table headers.
if (redundantFooter) {
this.foot.setAttribute('aria-hidden', 'true');
}
}
}
// Detect table size changes
commons.addResizeListener(this, this._resetLayout);
// Disable table features if no items.
const items = this._getSelectableItems();
this._toggleInteractivity(items.length === 0);
// Sync selection state
if (this.selectable) {
const selectedItems = this.selectedItems;
// Sync select all handle if any
this._syncSelectAllHandle(selectedItems, items);
// Sync used collections
if (selectedItems.length) {
this._oldSelection = selectedItems;
this._lastSelectedItems.items = selectedItems;
}
}
// Sync sorted
this._allowSorting = true;
const column = this._isSorted();
if (column) {
column._doSort && column._doSort(true);
}
// @compat
if (this.body) {
const rows = getRows([this.body]);
// Use the first column as selection column
rows.forEach(row => this._toggleSelectionCheckbox(row));
}
// Enable observer again
this._toggleObserver(true);
// Mark table as ready
if (!this.head || this.head && !this.head.hasAttribute('sticky')) {
this.classList.add(IS_READY);
}
}
/**
Triggered before a {@link Table} column gets sorted by user interaction. Can be used to cancel column sorting and define
custom sorting.
@typedef {CustomEvent} coral-table:beforecolumnsort
@property {TableColumn} detail.column
The column to be sorted.
@property {String} detail.direction
The requested sorting direction for the column.
*/
/**
Triggered when a {@link Table} column is sorted.
@typedef {CustomEvent} coral-table:columnsort
@param {TableColumn} detail.column
The sorted column.
*/
/**
Triggered before a {@link Table} column is dragged. Can be used to cancel column dragging.
@typedef {CustomEvent} coral-table:beforecolumndrag
@property {TableColumn} detail.column
The dragged column.
@property {TableColumn} detail.before
The column will be inserted before this sibling column.
If <code>null</code>, the column is inserted at the end.
*/
/**
Triggered when a {@link Table} column is dragged.
@typedef {CustomEvent} coral-table:columndrag
@property {TableColumn} detail.column
The dragged column.
@property {TableColumn} detail.oldBefore
The column next sibling before the swap.
If <code>null</code>, the column was the last item.
@property {TableColumn} detail.before
The column is inserted before this sibling column.
If <code>null</code>, the column is inserted at the end.
*/
/**
Triggered before a {@link Table} row is ordered. Can be used to cancel row ordering.
@typedef {CustomEvent} coral-table:beforeroworder
@property {TableRow} detail.row
The row to be ordered.
@property {TableRow} detail.before
The row will be inserted before this sibling row.
If <code>null</code>, the row is inserted at the end.
*/
/**
Triggered when a {@link Table} row is ordered.
@typedef {CustomEvent} coral-table:roworder
@property {TableRow} detail.row
The ordered row.
@property {TableRow} detail.oldBefore
The row next sibling before the swap.
If <code>null</code>, the row was the last item.
@param {TableRow} detail.before
The row is inserted before this sibling row.
If <code>null</code>, the row is inserted at the end.
*/
/**
Triggered when a {@linked Table} row is locked.
@typedef {CustomEvent} coral-table:rowlock
@property {TableRow} detail.row
The locked row.
*/
/**
Triggered when {@link Table} a row is locked.
@typedef {CustomEvent} coral-table:rowunlock
@property {TableRow} detail.row
The unlocked row.
*/E
/**
Triggered when a {@link Table} row selection changed.
@typedef {CustomEvent} coral-table:rowchange
@property {Array.<TableCell>} detail.oldSelection
The old item selection. When {@link TableRow#multiple}, it includes an Array.
@property {Array.<TableCell>} detail.selection
The item selection. When {@link Coral.Table.Row#multiple}, it includes an Array.
@property {TableRow} detail.row
The targeted row.
*/
/**
Triggered when the {@link Table} selection changed.
@typedef {CustomEvent} coral-table:change
@property {Array.<TableRow>} detail.oldSelection
The old item selection. When {@link Table#multiple}, it includes an Array.
@property {Array.<TableRow>} detail.selection
The item selection. When {@link Table#multiple}, it includes an Array.
*/
});
export default Table;
|