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 | 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 24x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 65x 65x 65x 65x 65x 178x 178x 178x 178x 178x 65x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 15x 15x 15x 15x 15x 3x 3x 3x 3x 3x 15x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 39x 39x 39x 39x 39x 39x 173x 173x 173x 173x 173x 39x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 71x 71x 71x 71x 71x 82x 82x 82x 71x 71x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 71x 71x 71x 71x 71x 95x 95x 95x 95x 95x 95x 95x 95x 71x 71x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 71x 71x 71x 71x 71x 95x 95x 95x 95x 95x 95x 95x 95x 71x 71x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 72x 72x 72x 72x 72x 96x 96x 96x 96x 96x 96x 1x 1x 95x 95x 96x 72x 72x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 22x 22x 22x 22x 22x 22x 75x 75x 75x 22x 22x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 22x 22x 22x 22x 22x 22x 70x 70x 70x 22x 22x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 22x 22x 22x 22x 22x 22x 70x 70x 70x 22x 22x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 27x 27x 27x 27x 27x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 78x 27x 27x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 133x 133x 133x 133x 133x 157x 157x 133x 133x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 292x 292x 292x 292x 292x 368x 368x 292x 292x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 57x 57x 57x 57x 57x 89x 89x 89x 89x 89x 57x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 202x 202x 202x 202x 202x 208x 208x 2x 2x 208x 208x 208x 208x 208x 1x 1x 1x 1x 1x 205x 205x 208x 202x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 30x 30x 30x 30x 30x 38x 38x 2x 2x 36x 36x 43x 43x 36x 36x 38x 30x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 61x 61x 61x 61x 61x 78x 78x 2x 2x 78x 78x 78x 78x 78x 78x 78x 78x 61x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 149x 149x 149x 149x 149x 102x 102x 102x 102x 102x 74x 74x 100x 102x 149x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 90x 90x 90x 90x 90x 36x 36x 36x 36x 90x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 13x 13x 13x 13x 13x 3x 3x 3x 3x 13x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 13x 13x 13x 13x 13x 3x 3x 3x 3x 13x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 13x 13x 13x 13x 13x 3x 3x 3x 3x 13x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 24x 24x 24x 24x 24x 16x 16x 4x 4x 12x 16x 24x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 18x 18x 18x 18x 18x 7x 7x 7x 18x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 24x 24x 24x 24x 24x 19x 19x 19x 19x 59x 59x 59x 59x 59x 59x 19x 19x 19x 19x 19x 24x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 19x 19x 19x 19x 19x 19x 11x 11x 11x 19x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 16x 16x 16x 16x 16x 5x 5x 5x 16x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 16x 16x 16x 16x 16x 4x 4x 4x 4x 4x 16x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 21x 21x 21x 21x 21x 6x 6x 6x 2x 2x 6x 6x 6x 21x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 321x 321x 321x 321x 321x 476x 476x 1x 1x 476x 476x 375x 375x 100x 100x 100x 100x 100x 100x 100x 100x 142x 92x 476x 3x 3x 8x 5x 5x 476x 321x 321x 321x 321x 321x 321x 487x 487x 487x 487x 11x 11x 476x 476x 487x 3x 3x 3x 3x 473x 473x 473x 487x 7x 7x 7x 7x 7x 7x 7x 7x 7x 487x 487x 487x 487x 487x 321x 321x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 17x 17x 17x 17x 17x 5x 5x 2x 2x 5x 5x 17x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 18x 18x 18x 18x 18x 18x 6x 6x 2x 2x 4x 6x 3x 3x 1x 1x 2x 3x 1x 1x 1x 3x 3x 6x 18x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2596x 2596x 2596x 2596x 2596x 3987x 3987x 3987x 3987x 2596x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2021x 2021x 2021x 2021x 2021x 2021x 3421x 3421x 2021x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 36x 36x 36x 36x 36x 19x 19x 19x 19x 19x 36x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 41x 41x 41x 41x 41x 41x 63x 63x 63x 41x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 1360x 1360x 1360x 1360x 1360x 1360x 4372x 4372x 1918x 1918x 2454x 2454x 2454x 2454x 2454x 2454x 2454x 2454x 2454x 4372x 4372x 4372x 4372x 1360x 1360x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 437x 437x 437x 437x 437x 437x 1014x 1014x 1014x 4x 4x 1014x 494x 123x 487x 371x 371x 1014x 516x 516x 516x 516x 516x 1014x 437x 7x 7x 7x 7x 7x 7x 7x 7x 7x 82x 82x 82x 3x 3x 79x 79x 3541x 3462x 3462x 79x 79x 79x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 33x 33x 33x 33x 33x 99x 99x 18x 18x 18x 99x 99x 99x 99x 33x 33x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 117x 117x 117x 117x 117x 117x 147x 147x 147x 147x 147x 114x 114x 114x 70x 70x 114x 147x 147x 117x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 64x 64x 64x 64x 64x 64x 72x 72x 72x 72x 72x 58x 58x 58x 26x 26x 58x 72x 72x 64x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 286x 286x 286x 286x 286x 272x 272x 2x 2x 270x 270x 272x 286x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 156x 156x 156x 156x 156x 156x 80x 156x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 23x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 17x 17x 17x 17x 17x 17x 651x 651x 17x 17x 17x 17x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 197x 197x 197x 197x 197x 636x 197x 7x 7x 7x 7x 7x 7x 7x 7x 7x 17x 17x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 17x 17x 17x 17x 17x 5x 5x 1x 1x 4x 4x 4x 5x 2x 2x 2x 2x 4x 4x 5x 17x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 15x 15x 15x 15x 15x 3x 3x 3x 15x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 17x 17x 17x 17x 17x 17x 5x 2x 2x 3x 3x 5x 5x 5x 5x 17x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 43x 43x 43x 43x 43x 43x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 45x 10x 10x 11x 11x 10x 45x 45x 43x 43x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 75x 75x 75x 75x 75x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 111x 111x 111x 111x 111x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 424x 424x 424x 424x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 14x 7x 7x 7x 7x 7x 7x 7x 7x 7x 466x 466x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 11x 11x 11x 11x 11x 11x 11x 4x 4x 4x 4x 11x 3x 3x 3x 3x 7x 4x 4x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 10x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 1x 1x 4x 4x 4x 4x 4x 4x 4x 5x 10x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 3x 3x 3x 3x 3x 3x 3x 12x 12x 12x 3x 3x 3x 3x 3x 3x 3x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 3x 3x 3x 12x 3x 3x 3x 3x 3x 3x 3x 3x 12x 4x 4x 4x 4x 4x 12x 3x 3x 3x 3x 3x 3x 6x 2x 2x 6x 3x 3x 3x 3x 3x 4x 2x 2x 2x 2x 2x 4x 3x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 50x 50x 50x 107x 107x 107x 107x 50x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 14x 14x 14x 14x 29x 29x 29x 29x 29x 29x 29x 29x 29x 29x 14x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 470x 1x 1x 470x 470x 466x 466x 466x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 494x 494x 1x 1x 493x 493x 493x 493x 407x 493x 493x 493x 494x 467x 467x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 23x 23x 23x 23x 23x 23x 23x 23x 3x 23x 16x 20x 4x 4x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 13x 13x 13x 13x 13x 13x 12x 12x 12x 13x 13x 13x 13x 13x 13x 13x 8x 6x 6x 13x 13x 13x 13x 13x 13x 1x 1x 13x 13x 13x 13x 20x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 18x 13x 13x 13x 13x 13x 11x 11x 13x 13x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 3x 3x 3x 3x 3x 3x 3x 9x 6x 6x 3x 3x 6x 9x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 58x 1x 1x 57x 57x 57x 57x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 18x 18x 18x 43x 28x 28x 46x 46x 46x 46x 46x 46x 46x 46x 46x 46x 28x 28x 46x 46x 46x 46x 555x 46x 46x 46x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 15x 15x 15x 15x 15x 15x 52x 15x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 11x 11x 11x 2x 2x 9x 9x 11x 12x 12x 12x 12x 12x 12x 12x 12x 12x 12x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 15x 15x 1x 1x 15x 15x 15x 15x 15x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 12x 18x 18x 12x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 7x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 2x 7x 7x | /*! * WikiLambda Vue editor: ZOBject Vuex module * * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt * @license MIT */ const Constants = require( '../../Constants.js' ), factoryModule = require( './zobject/factory.js' ), currentPageModule = require( './zobject/currentPage.js' ), submissionModule = require( './zobject/submission.js' ), findKeyInArray = require( '../../mixins/typeUtils.js' ).methods.findKeyInArray, isTruthyOrEqual = require( '../../mixins/typeUtils.js' ).methods.isTruthyOrEqual, zobjectUtils = require( '../../mixins/zobjectUtils.js' ).methods, apiUtils = require( '../../mixins/api.js' ).methods, extractZIDs = require( '../../mixins/schemata.js' ).methods.extractZIDs, { extractWikidataLexemeIds } = require( '../../mixins/wikidataUtils.js' ).methods, hybridToCanonical = require( '../../mixins/schemata.js' ).methods.hybridToCanonical, getParameterByName = require( '../../mixins/urlUtils.js' ).methods.getParameterByName, Row = require( '../classes/Row.js' ); module.exports = exports = { modules: { currentPage: currentPageModule, factory: factoryModule, submission: submissionModule }, state: { zobject: [] }, getters: { /** * Returns the whole state zobject table object * * @param {Object} state * @return {Object} */ getZObjectTable: function ( state ) { return state.zobject; }, /** * Return a specific zObject key given its row ID or * undefined if the row ID doesn't exist * * @param {Object} state * @param {Object} getters * @return {Function} */ getZObjectKeyByRowId: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function fetchZObjectKey( rowId ) { const row = getters.getRowById( rowId ); return ( row !== undefined ) ? row.key : undefined; } return fetchZObjectKey; }, /** * Returns string with the value if the row exists and * is terminal, else returns undefined * * @param {Object} state * @param {Object} getters * @return {Function} */ getZObjectValueByRowId: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} terminal value */ function fetchZObjectValue( rowId ) { const row = getters.getRowById( rowId ); return ( ( row !== undefined ) && row.isTerminal() ) ? row.value : undefined; } return fetchZObjectValue; }, /** * Returns the depth (from 0 to n) of the zobject * represented by a given rowId * * @param {Object} state * @param {Object} getters * @return {Function} */ getDepthByRowId: function ( state, getters ) { /** * @param {number} rowId * @param {number} depth * @return {number} */ function findDepth( rowId, depth = 0 ) { const row = getters.getRowById( rowId ); return ( !row || ( row.parent === undefined ) ) ? depth : findDepth( row.parent, depth + 1 ); } return findDepth; }, /** * Returns the row Id where the persistent object value starts (Z2K2 key) * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentContentRowId: function ( _state, getters ) { /** * @param {number} rowId * @return {number | undefined} */ function findContent( rowId = 0 ) { const row = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_VALUE ], rowId ); return row ? row.id : undefined; } return findContent; }, /** * Returns an array of all the ZMonolingualString languages * available in the persistent object Name/Label key (Z2K3). * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentNameLangs: function ( _state, getters ) { /** * @param {number} rowId * @return {Array} */ function findName( rowId = 0 ) { const nameRow = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_LABEL, Constants.Z_MULTILINGUALSTRING_VALUE ], rowId ); return nameRow ? getters.getZMultilingualLanguageList( nameRow.id ) : []; } return findName; }, /** * Returns an array of all the ZMonolingualString languages * available in the persistent object Description key (Z2K5). * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentDescriptionLangs: function ( _state, getters ) { /** * @param {number} rowId * @return {Array} */ function findDescription( rowId = 0 ) { const descriptionRow = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_DESCRIPTION, Constants.Z_MULTILINGUALSTRING_VALUE ], rowId ); return descriptionRow ? getters.getZMultilingualLanguageList( descriptionRow.id ) : []; } return findDescription; }, /** * Returns an array of all the ZMonolingualStringSet objects * (their language and their rowId) that are available in * the persistent object Aliases key (Z2K4). * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentAliasLangs: function ( _state, getters ) { /** * @param {number} rowId * @return {Array} */ function findAliases( rowId = 0 ) { const aliasRow = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_ALIASES, Constants.Z_MULTILINGUALSTRINGSET_VALUE ], rowId ); // Return empty array if row does not exist if ( aliasRow === undefined ) { return []; } const allAlias = getters.getChildrenByParentRowId( aliasRow.id ).slice( 1 ); return allAlias.map( ( mono ) => getters.getZMonolingualStringsetLang( mono.id ) ); } return findAliases; }, /** * Returns the row of the monolingual string that contains the * name for the ZPersistent object for a given language Zid. * If there's no monolingual string for this language, returns * undefined. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentName: function ( _state, getters ) { /** * @param {string} langZid * @param {number} rowId * @return {Object|undefined} */ function findName( langZid, rowId = 0 ) { const name = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_LABEL ], rowId ); return name ? getters.getZMonolingualForLanguage( langZid, name.id ) : undefined; } return findName; }, /** * Returns the row of the monolingual string that contains the * description for the ZPersistent object for a given language Zid. * If there's no monolingual string for this language, returns * undefined. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentDescription: function ( _state, getters ) { /** * @param {string} langZid * @param {number} rowId * @return {Object|undefined} */ function findDescription( langZid, rowId = 0 ) { const description = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_DESCRIPTION ], rowId ); return description ? getters.getZMonolingualForLanguage( langZid, description.id ) : undefined; } return findDescription; }, /** * Returns the alias for the ZPersistent object for a given * lang Zid. If no alias exist for the given language, returns * an empty array. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZPersistentAlias: function ( _state, getters ) { /** * @param {string} langZid * @param {number} rowId * @return {Object|undefined} */ function findAlias( langZid, rowId = 0 ) { const aliases = getters.getRowByKeyPath( [ Constants.Z_PERSISTENTOBJECT_ALIASES ], rowId ); return aliases ? getters.getZMonolingualStringsetForLanguage( langZid, aliases.id ) : undefined; } return findAlias; }, /** * Returns a list of all the language Zids that are present in * the multilingual data collection (must have at least a name, * a description, a set of aliases and any input labels). * * @param {Object} _state * @param {Object} getters * @return {Function} */ getMultilingualDataLanguages: function ( _state, getters ) { /** * @param {number} rowId * @return {Array} */ function findAllLanguages( rowId = 0 ) { // Get languages available in name, description and alias fields const nameLangs = getters.getZPersistentNameLangs( rowId ); const descriptionLangs = getters.getZPersistentDescriptionLangs( rowId ); const aliasLangs = getters.getZPersistentAliasLangs( rowId ); // Get languages available in input labels if object is a function const inputLangs = getters.getZFunctionInputLangs( rowId ); // Combine all languages and return the array of unique languageZids const allLangs = nameLangs.concat( descriptionLangs, aliasLangs, ...inputLangs ); return [ ...new Set( allLangs ) ]; } return findAllLanguages; }, /** * Returns the terminal value of Z6K1/String value of a ZObject * assumed to be a string * * @param {Object} state * @param {Object} getters * @return {Function} */ getZStringTerminalValue: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findZStringTerminalValue( rowId ) { return getters.getZObjectTerminalValue( rowId, Constants.Z_STRING_VALUE ); } return findZStringTerminalValue; }, /** * Returns the terminal value of Z6K1/String value of a ZObject * assumed to be a string * * @param {Object} state * @param {Object} getters * @return {Function} */ getZReferenceTerminalValue: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findZReferenceTerminalValue( rowId ) { return getters.getZObjectTerminalValue( rowId, Constants.Z_REFERENCE_ID ); } return findZReferenceTerminalValue; }, /** * Returns the terminal value of Z11K2 * * @param {Object} state * @param {Object} getters * @return {Function} */ getZMonolingualTextValue: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findZMonolingualTextValue( rowId ) { const stringRow = getters.getRowByKeyPath( [ Constants.Z_MONOLINGUALSTRING_VALUE ], rowId ); return stringRow ? getters.getZStringTerminalValue( stringRow.id ) : undefined; } return findZMonolingualTextValue; }, /** * Returns the terminal value of Z11K1 * * @param {Object} state * @param {Object} getters * @return {Function} */ getZMonolingualLangValue: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} rowId */ function findZMonolingualLangValue( rowId ) { const langRow = getters.getRowByKeyPath( [ Constants.Z_MONOLINGUALSTRING_LANGUAGE ], rowId ); if ( !langRow ) { return undefined; } const zObjectType = getters.getZObjectTypeByRowId( langRow.id ); // If zobject language type is a natural language, return the // language code value if ( zObjectType === Constants.Z_NATURAL_LANGUAGE ) { return getters.getRowByKeyPath( [ Constants.Z_NATURAL_LANGUAGE_ISO_CODE, Constants.Z_STRING_VALUE ], langRow.id ).value; } return getters.getZReferenceTerminalValue( langRow.id ); } return findZMonolingualLangValue; }, /** * Returns the terminal value of Z31K2, which is an * array of strings. * * @param {Object} state * @param {Object} getters * @return {Function} */ getZMonolingualStringsetValues: function ( state, getters ) { /** * @param {number} rowId * @return {Array} */ function findZMonolingualStringsetValues( rowId ) { const listRow = getters.getRowByKeyPath( [ Constants.Z_MONOLINGUALSTRINGSET_VALUE ], rowId ); if ( listRow === undefined ) { return []; } const list = getters.getChildrenByParentRowId( listRow.id ).slice( 1 ); const strings = list.map( ( stringRow ) => ( { rowId: stringRow.id, value: getters.getZStringTerminalValue( stringRow.id ) } ) ); return strings; } return findZMonolingualStringsetValues; }, /** * Returns the terminal value of Z31K1 * * @param {Object} state * @param {Object} getters * @return {Function} */ getZMonolingualStringsetLang: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} rowId */ function findZMonolingualStringsetLang( rowId ) { const langRow = getters.getRowByKeyPath( [ Constants.Z_MONOLINGUALSTRINGSET_LANGUAGE ], rowId ); if ( langRow === undefined ) { return undefined; } const zObjectType = getters.getZObjectTypeByRowId( langRow.id ); // If zobject language type is a natural language, return the // language code value if ( zObjectType === Constants.Z_NATURAL_LANGUAGE ) { return getters.getRowByKeyPath( [ Constants.Z_NATURAL_LANGUAGE_ISO_CODE, Constants.Z_STRING_VALUE ], langRow.id ).value; } return getters.getZReferenceTerminalValue( langRow.id ); } return findZMonolingualStringsetLang; }, /** * Returns the zid of the function given the rowId of a function call * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZFunctionCallFunctionId: function ( _state, getters ) { /** * @param {string} rowId * @return {string | undefined} */ function findZFunctionId( rowId ) { const zFunction = getters.getRowByKeyPath( [ Constants.Z_FUNCTION_CALL_FUNCTION ], rowId ); if ( !zFunction ) { return undefined; } return getters.getZObjectTerminalValue( zFunction.id, Constants.Z_REFERENCE_ID ); } return findZFunctionId; }, /** * Returns the argument key-values of a function call given the * rowId of the function call object. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZFunctionCallArguments: function ( _state, getters ) { /** * @param {string} rowId * @return {Array} */ function findZFunctionCallArgs( rowId ) { const children = getters.getChildrenByParentRowId( rowId ); return children.filter( ( row ) => ( row.key !== Constants.Z_OBJECT_TYPE ) && ( row.key !== Constants.Z_FUNCTION_CALL_FUNCTION ) ); } return findZFunctionCallArgs; }, /** * Returns the row ID of the target function of a tester * given the tester rowId * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZTesterFunctionRowId: function ( _state, getters ) { /** * @param {number} rowId * @return {number | undefined} */ function findFunctionId( rowId ) { const functionRef = getters.getRowByKeyPath( [ Constants.Z_TESTER_FUNCTION ], rowId ); if ( functionRef === undefined ) { return undefined; } return functionRef.id; } return findFunctionId; }, /** * Returns the row ID of the call function call of a tester * given the tester rowId * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZTesterCallRowId: function ( _state, getters ) { /** * @param {number} rowId * @return {number | undefined} */ function findCall( rowId ) { const callRow = getters.getRowByKeyPath( [ Constants.Z_TESTER_CALL ], rowId ); if ( callRow === undefined ) { return undefined; } return callRow.id; } return findCall; }, /** * Returns the row ID of the validation function call of a tester * given the tester rowId * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZTesterValidationRowId: function ( _state, getters ) { /** * @param {number} rowId * @return {number | undefined} */ function findValidation( rowId ) { const validationRow = getters.getRowByKeyPath( [ Constants.Z_TESTER_VALIDATION ], rowId ); if ( validationRow === undefined ) { return undefined; } return validationRow.id; } return findValidation; }, /** * Returns the row ID of the target function of an implementation * given the implementation rowId * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZImplementationFunctionRowId: function ( _state, getters ) { /** * @param {number} rowId * @return {number | undefined} */ function findFunctionId( rowId ) { const functionRef = getters.getRowByKeyPath( [ Constants.Z_IMPLEMENTATION_FUNCTION ], rowId ); if ( functionRef === undefined ) { return undefined; } return functionRef.id; } return findFunctionId; }, /** * Returns the terminal function Zid of the target function of an implementation * given the implementation rowId * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZImplementationFunctionZid: function ( _state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findFunctionZid( rowId ) { const functionRowId = getters.getZImplementationFunctionRowId( rowId ); return functionRowId ? getters.getZReferenceTerminalValue( functionRowId ) : undefined; } return findFunctionZid; }, /** * Returns the type of implementation selected for a given * implmentation rowId. The type is what of all mutually exclusive * keys is present in the current implementation: Z14K2 (composition), * Z14K3 (code) or Z14K4 (builtin). * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZImplementationContentType: function ( _state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findImplementationType( rowId ) { const children = getters.getChildrenByParentRowId( rowId ); // get all child keys and remove Z1K1 and Z14K1 const childKeys = children .filter( ( child ) => { const allowedKeys = [ Constants.Z_IMPLEMENTATION_CODE, Constants.Z_IMPLEMENTATION_COMPOSITION, Constants.Z_IMPLEMENTATION_BUILT_IN ]; return ( allowedKeys.includes( child.key ) ) && ( child.value !== undefined ); } ) .map( ( child ) => child.key ); // childKeys should only have one element after the filtering return ( childKeys.length === 1 ) ? childKeys[ 0 ] : undefined; } return findImplementationType; }, /** * Returns the rowId for the implementation content given * an implementation rowId and the type of content defined * by its key (Z14K2 for composition and Z14K3 for code) * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZImplementationContentRowId: function ( _state, getters ) { /** * @param {number} rowId * @param {string} key * @return {number | undefined} */ function findImplementationContent( rowId, key ) { const row = getters.getRowByKeyPath( [ key ], rowId ); return row ? row.id : undefined; } return findImplementationContent; }, /** * Returns the terminal value of Z16K1 * * @param {Object} state * @param {Object} getters * @return {Function} */ getZCodeString: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findZCode( rowId ) { const codeRow = getters.getRowByKeyPath( [ Constants.Z_CODE_CODE ], rowId ); return codeRow ? getters.getZStringTerminalValue( codeRow.id ) : undefined; } return findZCode; }, /** * Returns the row of a Z16/Code programming language key (Z16K1) * * @param {Object} state * @param {Object} getters * @return {Function} */ getZCodeProgrammingLanguageRow: function ( state, getters ) { /** * @param {number} rowId * @return {Row | undefined} */ function findZCodeLanguage( rowId ) { const langRow = getters.getRowByKeyPath( [ Constants.Z_CODE_LANGUAGE ], rowId ); return langRow; } return findZCodeLanguage; }, /** * Returns the terminal reference Value of Z40K1 * * @param {Object} state * @param {Object} getters * @return {Function} */ getZBooleanValue: function ( state, getters ) { /** * @param {number} rowId * @return {string | undefined} */ function findZBooleanValue( rowId ) { const booleanRow = getters.getRowByKeyPath( [ Constants.Z_BOOLEAN_IDENTITY ], rowId ); if ( !booleanRow ) { return; } return getters.getZReferenceTerminalValue( booleanRow.id ); } return findZBooleanValue; }, /** * Returns the string or object representation for the type of the * ZObject represented in the rowId passed as parameter. Returns * undefined if no valid type is present. * * @param {Object} state * @param {Object} getters * @return {Function} */ getZObjectTypeByRowId: function ( state, getters ) { /** * @param {Row} typeRow * @return {string | Object | undefined} type */ function getTypeRepresentation( typeRow ) { // If undefined, return undefined if ( !typeRow ) { return undefined; } // If typeRow is Terminal, return its value if ( typeRow.isTerminal() ) { return typeRow.value; } // If typeRow is NOT Terminal, return the canonical representation // FIXME: I think we can do it better in here // If typeRow is not terminal, it can be: // * a reference -> can we get the reference terminal value? // * a literal type -> can we get the value of the type identity key? // * a function call -> we need the function call representation const type = getters.getZObjectTypeByRowId( typeRow.id ); if ( type === Constants.Z_REFERENCE ) { return getters.getZReferenceTerminalValue( typeRow.id ); } else if ( type === Constants.Z_TYPE ) { const typeIdRow = getters.getRowByKeyPath( [ Constants.Z_TYPE_IDENTITY ], typeRow.id ); return getTypeRepresentation( typeIdRow ); } else { return hybridToCanonical( getters.getZObjectAsJsonById( typeRow.id ) ); } } /** * @param {number} id * @return {string | Object | undefined} type */ function findZObjectTypeById( id ) { const row = getters.getRowById( id ); // 1. If rowId doesn't exist return undefined if ( !row || row.id === row.parent ) { return undefined; } // 2. If the row is TERMINAL it's either a string or reference value if ( row.isTerminal() ) { return ( row.key === Constants.Z_REFERENCE_ID ) ? Constants.Z_REFERENCE : Constants.Z_STRING; } // 3. If the row is an ARRAY, we return the full typed list function call let type; if ( row.isArray() ) { const itemTypeRow = getters.getRowByKeyPath( [ '0' ], row.id ); const itemType = getTypeRepresentation( itemTypeRow ); type = { [ Constants.Z_OBJECT_TYPE ]: Constants.Z_FUNCTION_CALL, [ Constants.Z_FUNCTION_CALL_FUNCTION ]: Constants.Z_TYPED_LIST, [ Constants.Z_TYPED_LIST_TYPE ]: itemType || '' }; return type; } // 4. If the row is an OBJECT we get its Z1K1 and return its representation const typeRow = getters.getRowByKeyPath( [ Constants.Z_OBJECT_TYPE ], id ); return getTypeRepresentation( typeRow ); } return findZObjectTypeById; }, /** * Returns the item type of a typed list given the parent * rowId of the list object * * @param {Object} state * @param {Object} getters * @return {Function} */ getTypedListItemType: function ( state, getters ) { /** * @param {number} parentRowId * @return {string|Object|undefined} */ function findTypedListItemType( parentRowId ) { const listType = getters.getZObjectTypeByRowId( parentRowId ); if ( !listType ) { return undefined; } return listType[ Constants.Z_TYPED_LIST_TYPE ]; } return findTypedListItemType; }, /** * Returns a particular key-value in the Metadata object given * the Metadata object rowId and a string key. Returns undefined * if nothing is found under the given key. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getMapValueByKey: function ( _state, getters ) { /** * @param {string} rowId * @param {string} key * @return {Row|undefined} */ function findMapValue( rowId, key ) { const listRow = getters.getRowByKeyPath( [ Constants.Z_TYPED_OBJECT_ELEMENT_1 ], rowId ); if ( !listRow ) { return undefined; } const pairs = getters.getChildrenByParentRowId( listRow.id ).slice( 1 ); for ( const pair of pairs ) { const keyRow = getters.getRowByKeyPath( [ Constants.Z_TYPED_OBJECT_ELEMENT_1 ], pair.id ); if ( !keyRow ) { continue; } const keyString = getters.getZStringTerminalValue( keyRow.id ); if ( keyString === key ) { const valueRow = getters.getRowByKeyPath( [ Constants.Z_TYPED_OBJECT_ELEMENT_2 ], pair.id ); return valueRow; } } return undefined; } return findMapValue; }, /** * Returns a row object given its row ID. Note that the row ID is its * parameter row.id and it is different than the indexx * * @param {Object} state * @param {Object} getters * @return {Function} */ getRowById: function ( state ) { /** * @param {number|undefined} rowId * @return {Row} row */ function fetchRowId( rowId ) { return ( rowId === undefined ) ? undefined : state.zobject.find( ( item ) => item.id === rowId ); } return fetchRowId; }, /** * Returns all the children rows given a parent rowId, else * returns an empty list. * * @param {Object} state * @param {Object} getters * @return {Function} */ getChildrenByParentRowId: function ( state ) { /** * @param {number} rowId * @param {Array} rows * @return {Array} */ function fetchChildrenRows( rowId ) { return state.zobject.filter( ( row ) => ( row.parent === rowId ) ); } return fetchChildrenRows; }, /** * Return the next available array key or index given an * array parent Id * * @param {Object} state * @param {Object} getters * @return {Function} */ getNextArrayIndex: function ( state, getters ) { /** * @param {number} parentRowId * @return {number} */ function fetchNextArrayIndexOfParentRowId( parentRowId ) { const children = getters.getChildrenByParentRowId( parentRowId ); // TODO: should we check that the sequence of children keys is // continuous and doesn't have any gaps? return children.length; } return fetchNextArrayIndexOfParentRowId; }, /** * Return the parent rowId of a given rowId * * @param {Object} state * @param {Object} getters * @return {Function} */ getParentRowId: function ( state, getters ) { /** * @param {number} rowId * @param {number} parent rowId * @return {number} */ function findParent( rowId ) { const row = getters.getRowById( rowId ); return row ? row.parent : undefined; } return findParent; }, /** * Given a starting rowId and an array of keys that form a path, * follow that path down and return the resulting row. * * @param {Object} state * @param {Object} getters * @return {Function} */ getRowByKeyPath: function ( state, getters ) { /** * @param {Array} path sequence of keys that specify a path to follow down the ZObject * @param {number} rowId starting row Id * @return {Row|undefined} resulting row or undefined if not found */ function followPath( path = [], rowId = 0 ) { // End condition, if the path is empty, return the row by rowId if ( path.length === 0 ) { return getters.getRowById( rowId ); } // Else, follow the sequence of keys by finding the child with // the head key and recourse const head = path[ 0 ]; const tail = path.slice( 1 ); const children = getters.getChildrenByParentRowId( rowId ); const child = children.find( ( row ) => ( row.key === head ) ); // Follow the path of keys parting from the child return ( child === undefined ) ? undefined : followPath( tail, child.id ); } return followPath; }, /** * Returns the terminal value of a Z9/Reference or a Z6/String * nested under a sequence of their keys. * * E.g. getZObjectTerminalValue( rowId, Z9K1 ) would return the * terminal value in objects like { Z9K1: { Z9K1: "value" }}, * { Z9K1: "value"} or "value" * * This is a generalized method to be called from the specific * methods getZStringTerminalValue or getZReferenceTerminalValue * * @param {Object} state * @param {Object} getters * @return {Function} */ getZObjectTerminalValue: function ( state, getters ) { /** * @param {number} rowId an integer representing an existing rowId * @param {string} terminalKey either string or reference terminal key * @return {string | undefined} */ function findTerminalValue( rowId, terminalKey ) { const row = getters.getRowById( rowId ); // Row not found is undefined if ( row === undefined ) { return undefined; } if ( row.isTerminal() ) { if ( terminalKey === Constants.Z_STRING_VALUE ) { return row.value; } else { return row.value ? row.value : undefined; } } else { const valueRow = getters.getRowByKeyPath( [ terminalKey ], row.id ); return valueRow ? findTerminalValue( valueRow.id, terminalKey ) : undefined; } } return findTerminalValue; }, /** * Returns the next available rowId * * @param {Object} state * @return {number} */ getNextRowId: function ( state ) { let highestObjectId = 0; if ( !state.zobject || state.zobject.length === 0 ) { return highestObjectId; } state.zobject.forEach( ( item ) => { if ( item.id > highestObjectId ) { highestObjectId = item.id; } } ); return highestObjectId + 1; }, /** * Returns whether the rowId is inside an implementation * composition (Z14K2), which will determine whether * we can use argument references in its type selectors. * * @param {Object} state * @param {Object} getters * @return {Function} */ isInsideComposition: function ( state, getters ) { /** * @param {number} rowId * @return {boolean} */ function findCompositionFromRowId( rowId ) { const row = getters.getRowById( rowId ); if ( !row ) { // Not found or reached the root, return false and end return false; } return ( row.key === Constants.Z_IMPLEMENTATION_COMPOSITION ) ? true : findCompositionFromRowId( row.parent ); } return findCompositionFromRowId; }, /** * Return the monolingual string object row belonging * to a given language and multilingual string rowId, * or undefined if there is no monolingual string for * this language. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZMonolingualForLanguage: function ( _state, getters ) { /** * @param {string} langZid * @param {number} rowId * @return {Object|undefined} */ function findMonolingual( langZid, rowId ) { const list = getters.getRowByKeyPath( [ Constants.Z_MULTILINGUALSTRING_VALUE ], rowId ); if ( !list ) { return undefined; } // get monolingual objects const children = getters.getChildrenByParentRowId( list.id ).slice( 1 ); for ( const child of children ) { const monoLangRow = getters.getRowByKeyPath( [ Constants.Z_MONOLINGUALSTRING_LANGUAGE ], child.id ); const monoLangZid = getters.getZReferenceTerminalValue( monoLangRow ? monoLangRow.id : undefined ); if ( langZid === monoLangZid ) { return child; } } return undefined; } return findMonolingual; }, /** * Return the monolingual stringset object row belonging * to a given language and multilingual stringset rowId, * or undefined if there is no monolingual stringset for * this language. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZMonolingualStringsetForLanguage: function ( _state, getters ) { /** * @param {string} langZid * @param {number} rowId * @return {Object|undefined} */ function findMonolingualStringset( langZid, rowId ) { const list = getters.getRowByKeyPath( [ Constants.Z_MULTILINGUALSTRINGSET_VALUE ], rowId ); if ( !list ) { return undefined; } // get monolingual objects const children = getters.getChildrenByParentRowId( list.id ).slice( 1 ); for ( const child of children ) { const row = getters.getRowByKeyPath( [ Constants.Z_MONOLINGUALSTRINGSET_LANGUAGE ], child.id ); const zid = getters.getZReferenceTerminalValue( row ? row.id : undefined ); if ( langZid === zid ) { return child; } } return undefined; } return findMonolingualStringset; }, /** * Returns the list of language zids represented in a given * ZMonolingualStrings (E.g. Name or Description) given the * rowId where the content of the ZMulilingualString Value/Z12K1 * starts. * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZMultilingualLanguageList: function ( _state, getters ) { /** * @param {number} rowId * @return {Array} */ function findBestMonolingual( rowId ) { const listRow = getters.getRowById( rowId ); if ( !listRow || !listRow.isArray() ) { return []; } const allMonolinguals = getters.getChildrenByParentRowId( rowId ).slice( 1 ); return allMonolinguals.map( ( mono ) => getters.getZMonolingualLangValue( mono.id ) ); } return findBestMonolingual; }, /** * Return the JSON representation of a specific zObject and its children * using the zObject id value within the zObject array * * @param {Object} state * @return {Function} */ getZObjectAsJsonById: function ( state ) { /** * @param {number} id * @param {boolean} isArray * @return {Array} zObjectJson */ return function ( id, isArray ) { return zobjectUtils.convertTableToJson( state.zobject, id, isArray ); }; }, /** * Return the complete zObject as a JSON * * @param {Object} state * @param {Object} getters * @return {Array} */ getZObjectAsJson: function ( state, getters ) { return getters.getZObjectAsJsonById( 0, state.zobject[ 0 ].isArray() ); }, /** * Return the next key of the root ZObject. So if the current object is a Z408 * and there are currently 2 keys, it will return Z408K3. * * @param {Object} state * @param {Object} getters * @return {string} nextKey */ getNextKey: function ( state, getters ) { const zid = getters.getCurrentZObjectId; const keyRegex = new RegExp( '^' + zid + 'K([0-9]+)$' ); const defaultKey = 0; const lastKey = Math.max( defaultKey, ...state.zobject.map( ( item ) => { const match = item.isTerminal() && item.value.match( keyRegex ); return match ? parseInt( match[ 1 ], 10 ) : -1; } ) ); const nextKey = lastKey + 1; return zid + 'K' + nextKey; }, /** * Return the index of a zObject by its row ID * for internal use. * * @param {Object} state * @return {Function} */ getRowIndexById: function ( state ) { /** * @param {number} id * @return {number} index */ return function ( id ) { return state.zobject.findIndex( ( item ) => item.id === id ); }; }, /** * Return a deep copy of the current zobject table * * @param {Object} state * @return {Object} */ getZObjectCopy: function ( state ) { // const copy = JSON.parse( JSON.stringify( context.state.zobject ) ); return state.zobject.map( ( row ) => new Row( row.id, row.key, row.value, row.parent ) ); }, /** * Returns whether the key has a Is identity/Z3K4 key set to true, * given the row ID of the key object * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZKeyIsIdentity: function ( _state, getters ) { /** * @param {string} zid * @return {boolean} */ function findZKeyIsIdentity( zid ) { const isIdentity = getters.getRowByKeyPath( [ Constants.Z_KEY_IS_IDENTITY ], zid ); if ( !isIdentity ) { return false; } let boolValue = ''; const type = getters.getZObjectTypeByRowId( isIdentity.id ); if ( type === Constants.Z_BOOLEAN ) { boolValue = getters.getZBooleanValue( isIdentity.id ); } else if ( type === Constants.Z_REFERENCE ) { boolValue = getters.getZReferenceTerminalValue( isIdentity.id ); } return boolValue === Constants.Z_BOOLEAN_TRUE; } return findZKeyIsIdentity; }, /** * Retuns the rowId of the key type field given the key rowId * * @param {Object} _state * @param {Object} getters * @return {Function} */ getZKeyTypeRowId: function ( _state, getters ) { /** * @param {string} rowId * @return {number | undefined} */ function findZKeyType( rowId ) { const keyType = getters.getRowByKeyPath( [ Constants.Z_KEY_TYPE ], rowId ); return keyType ? keyType.id : undefined; } return findZKeyType; }, /** * Retuns the value of the identity key of a converter object given the * rowId and the type of converter (Serialiser/Z64 or Deserialiser/Z46) * * @param {Object} _state * @param {Object} getters * @return {Function} */ getConverterIdentity: function ( _state, getters ) { /** * @param {number} rowId * @param {string} type * @return {string | undefined} */ function findIdentity( rowId, type ) { if ( type !== Constants.Z_DESERIALISER && type !== Constants.Z_SERIALISER ) { return undefined; } const identityKey = `${ type }K1`; const identityKeyRow = getters.getRowByKeyPath( [ identityKey ], rowId ); return identityKeyRow ? getters.getZReferenceTerminalValue( identityKeyRow.id ) : undefined; } return findIdentity; }, /** * Recursively waks a nested generic type and returns * the field IDs and whether they are valid or not. * * @param {Object} state * @param {Object} getters * @return {Function} */ validateGenericType: function ( state, getters ) { /** * @param {number} rowId * @param {Object} fields * @return {Object} fields */ function validate( rowId, fields = [] ) { // There's no need to convert to string as the // possible options will be either Z7 or Z9 const mode = getters.getZObjectTypeByRowId( rowId ); const value = ( mode === Constants.Z_REFERENCE ) ? getters.getZReferenceTerminalValue( rowId ) : getters.getZFunctionCallFunctionId( rowId ); fields.push( { rowId, isValid: !!value } ); if ( mode === Constants.Z_FUNCTION_CALL ) { const args = getters.getZFunctionCallArguments( rowId ); for ( const arg of args ) { getters.validateGenericType( arg.id, fields ); } } return fields; } return validate; } }, mutations: { /** * This is the most atomic setter. It sets the value * of a given row, given the rowIndex and the value. * * @param {Object} state * @param {Object} payload * @param {number} payload.index * @param {string|undefined} payload.value */ setValueByRowIndex: function ( state, payload ) { const item = state.zobject[ payload.index ]; item.value = payload.value; // Modification of an array item cannot be detected // so it's not reactive. That's why we must run splice state.zobject.splice( payload.index, 1, item ); }, /** * This is the most atomic setter. It sets the key of * a given row, given the rowIndex and the key value. * * @param {Object} state * @param {Object} payload * @param {number} payload.index * @param {string|undefined} payload.key */ setKeyByRowIndex: function ( state, payload ) { const item = state.zobject[ payload.index ]; item.key = payload.key; // Modification of an array item cannot be detected // so it's not reactive. That's why we must run splice state.zobject.splice( payload.index, 1, item ); }, /** * Push a row into the zobject state. The row already * has the necessary IDs and details set, so it is not * necessary to recalculate anything nor look at the * table indices, simply push. * * @param {Object} state * @param {Row} row */ pushRow: function ( state, row ) { // Make sure that all the rows pushed into the state are instances of Row if ( row instanceof Row ) { state.zobject.push( row ); } else { state.zobject.push( new Row( row.id, row.key, row.value, row.parent ) ); } }, /** * Set the whole state zobject with an array of Rows * It's used in the initial setup and to restore * the initial state of the object when attaching * or detaching implementations or testers fails. * It's important to always make sure that the * payload is an Array of Row objects. * * @param {Object} state * @param {Row[]} payload */ setZObject: function ( state, payload ) { state.zobject = payload; }, /** * Removes the Row at the given index of the state zobject * * @param {Object} state * @param {number} index */ removeRowByIndex: function ( state, index ) { state.zobject.splice( index, 1 ); } }, actions: { /** * Handles the initization of the pages given the wgWikiLambda config parameters. * The page can be: * 1. A Create New ZObject page, when the flag createNewPage is true- * 2. A Run Function page, when the flag runFunction is true or the * zid property is empty. * 3. A View or Edit page of a persisted ZObject given its zid. * * @param {Object} context * @return {Promise} */ initializeView: function ( context ) { const editingData = mw.config.get( 'wgWikiLambda' ), createNewPage = editingData.createNewPage, runFunction = editingData.runFunction, zId = editingData.zId; // If createNewPage is true, ignore runFunction and any specified ZID. if ( createNewPage ) { return context.dispatch( 'initializeCreateNewPage' ); // If runFunction is true, ignore any specified ZID. // If no ZID specified, assume runFunction is true. } else if ( runFunction || !zId ) { return context.dispatch( 'initializeEvaluateFunction' ); // Else, this is a view or edit page of an existing ZObject, so we // fetch the info and set the root ZObject with the persisted data. } else { return context.dispatch( 'initializeRootZObject', zId ); } }, /** * Initializes a Evaluate Function Call page, setting the root blank * function call object. * * @param {Object} context */ initializeEvaluateFunction: function ( context ) { // Reset state.zobject to initial state context.commit( 'setZObject', [] ); // Set current Zid to empty placeholder (Z0) context.commit( 'setCurrentZid', Constants.NEW_ZID_PLACEHOLDER ); // Create root row for the blank object const rootRow = new Row( 0, undefined, Constants.ROW_VALUE_OBJECT, undefined ); context.commit( 'pushRow', rootRow ); // Set the blank ZObject as a new ZFunctionCall context.dispatch( 'changeType', { id: 0, type: Constants.Z_FUNCTION_CALL } ); context.commit( 'setInitialized', true ); }, /** * Initializes a Create New ZObject page, setting the root blank * persistent object and setting the internal type to a given one, if * provided in the url Zid property. * * @param {Object} context * @return {Promise} */ initializeCreateNewPage: function ( context ) { // Reset state.zobject to initial state context.commit( 'setZObject', [] ); // Set createNewPage flag to true context.commit( 'setCreateNewPage', true ); // Set current Zid to empty placeholder (Z0) context.commit( 'setCurrentZid', Constants.NEW_ZID_PLACEHOLDER ); // Create root row for the blank object const rootRow = new Row( 0, undefined, Constants.ROW_VALUE_OBJECT, undefined ); context.commit( 'pushRow', rootRow ); // Set the blank ZObject as a new ZPersistentObject return context.dispatch( 'changeType', { id: 0, type: Constants.Z_PERSISTENTOBJECT } ).then( () => { // If `zid` url parameter is found, the new ZObject // will be of the given type. const defaultType = getParameterByName( 'zid' ); let defaultKeys; context.commit( 'setInitialized', true ); // No `zid` parameter, return. if ( !defaultType || !defaultType.match( /Z[1-9]\d*$/ ) ) { return Promise.resolve(); } // Else, fetch `zid` and make sure it's a type return context.dispatch( 'fetchZids', { zids: [ defaultType ] } ) .then( () => { const Z2K2 = findKeyInArray( Constants.Z_PERSISTENTOBJECT_VALUE, context.state.zobject ); defaultKeys = context.getters.getStoredObject( defaultType ); // If `zid` is not a type, return. if ( !defaultKeys || defaultKeys[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_OBJECT_TYPE ] !== Constants.Z_TYPE ) { return Promise.resolve(); } // If `zid` is a type, dispatch `changeType` action return context.dispatch( 'changeType', { id: Z2K2.id, type: defaultType, literal: true } ); } ); } ); }, /** * Initializes a view or edit page of a given zid from a persisted ZObject. * Calls to the wikilambdaload_zobjects API to fetch the root Zobject of the page * with all its unfiltered content (all language labels, etc). This call is done * only once and the method is separate from fetchZids because the logic to * treat the result is extremely different. * * @param {Object} context * @param {string} zId * @return {Promise} */ initializeRootZObject: function ( context, zId ) { // Reset state.zobject to initial state context.commit( 'setZObject', [] ); // Set current Zid context.commit( 'setCurrentZid', zId ); const revision = getParameterByName( 'oldid' ); // Calling the API without language parameter so that we get // the unfiltered multilingual object return apiUtils.fetchZObjects( { zids: zId, revisions: revision || undefined } ).then( ( response ) => { const zobject = response[ zId ].data; // Initialize optional aliases key if absent if ( !zobject[ Constants.Z_PERSISTENTOBJECT_ALIASES ] ) { zobject[ Constants.Z_PERSISTENTOBJECT_ALIASES ] = { Z1K1: Constants.Z_MULTILINGUALSTRINGSET, Z32K1: [ Constants.Z_MONOLINGUALSTRINGSET ] }; } // Initialize optional description key if absent if ( !zobject[ Constants.Z_PERSISTENTOBJECT_DESCRIPTION ] ) { zobject[ Constants.Z_PERSISTENTOBJECT_DESCRIPTION ] = { Z1K1: Constants.Z_MULTILINGUALSTRING, Z12K1: [ Constants.Z_MONOLINGUALSTRING ] }; } // If object is Type/Z4, on edit mode, and user has permission to edit types, // initialize falsy fields to allow users to change them. // // NOTE: This has the potential of adding unrelated edits to types, // e.g. if a user edits a label and the identity flag was missing (falsy), // the identity flag will be saved as false. This is why we need to restrict // this initialization only to users that have the right to edit types. if ( !context.getters.getViewMode && context.getters.userCanEditTypes && isTruthyOrEqual( zobject, [ Constants.Z_PERSISTENTOBJECT_VALUE, Constants.Z_OBJECT_TYPE ], Constants.Z_TYPE ) ) { // 1. Initialize type function keys (Z4K3, Z4K4, Z4K5 and Z4K6) const refs = [ Constants.Z_TYPE_VALIDATOR, Constants.Z_TYPE_EQUALITY, Constants.Z_TYPE_RENDERER, Constants.Z_TYPE_PARSER ]; for ( const key of refs ) { if ( !isTruthyOrEqual( zobject, [ Constants.Z_PERSISTENTOBJECT_VALUE, key ] ) ) { zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ key ] = { [ Constants.Z_OBJECT_TYPE ]: Constants.Z_REFERENCE, [ Constants.Z_REFERENCE_ID ]: '' }; } } // 2. Initialize the converters' lists (Z4K7, Z4K8) const lists = { [ Constants.Z_TYPE_DESERIALISERS ]: Constants.Z_DESERIALISER, [ Constants.Z_TYPE_SERIALISERS ]: Constants.Z_SERIALISER }; for ( const key in lists ) { if ( !isTruthyOrEqual( zobject, [ Constants.Z_PERSISTENTOBJECT_VALUE, key ] ) ) { zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ key ] = [ lists[ key ] ]; } } // 3. Initialize keys' Is identity (Z3K4) field const keys = zobject[ Constants.Z_PERSISTENTOBJECT_VALUE ][ Constants.Z_TYPE_KEYS ] // Skipping the initial value, the string 'Z3' (Benjamin list) .slice( 1 ); for ( const key of keys ) { if ( !isTruthyOrEqual( key, [ Constants.Z_KEY_IS_IDENTITY ] ) ) { key[ Constants.Z_KEY_IS_IDENTITY ] = { [ Constants.Z_OBJECT_TYPE ]: Constants.Z_BOOLEAN, [ Constants.Z_BOOLEAN_IDENTITY ]: Constants.Z_BOOLEAN_FALSE }; } } } // Save initial multilingual data values // so that About widget knows how to reset to original // state in the case of a publish cancelation action. context.commit( 'saveMultilingualDataCopy', zobject ); // Internal data fetch: // Get all ZObject Ids within the object const listOfZIdWithinObject = extractZIDs( zobject ); context.dispatch( 'fetchZids', { zids: listOfZIdWithinObject } ); // External data fetch: // Get all Wikidata Ids within the object (if any) const listOfLexemeIds = extractWikidataLexemeIds( zobject ); if ( listOfLexemeIds.length > 0 ) { context.dispatch( 'fetchLexemes', { ids: listOfLexemeIds } ); } // Convert to rows and set store: const zobjectRows = zobjectUtils.convertJsonToTable( zobject ); context.commit( 'setZObject', zobjectRows ); // Set initialized as done: context.commit( 'setInitialized', true ); } ); }, /** * Recalculate the internal keys of a ZList in its zobject table representation. * This should be used when an item is removed from a ZList. * * @param {Object} context * @param {number} listRowId */ recalculateTypedListKeys: function ( context, listRowId ) { const children = context.getters.getChildrenByParentRowId( listRowId ); children.forEach( ( itemRow, index ) => { context.commit( 'setKeyByRowIndex', { index: context.getters.getRowIndexById( itemRow.id ), key: `${ index }` } ); } ); }, /** * Recalculate the keys and key values of a ZArgument or ZKey List. * * @param {Object} context * @param {Object} payload * @param {number} payload.listRowId * @param {string} payload.key */ recalculateKeys: function ( context, payload ) { const { listRowId, key } = payload; const items = context.getters.getChildrenByParentRowId( listRowId ).slice( 1 ); items.forEach( ( itemRow, index ) => { const itemKeyRow = context.getters.getRowByKeyPath( [ key, Constants.Z_STRING_VALUE ], itemRow.id ); if ( itemKeyRow ) { context.commit( 'setValueByRowIndex', { index: context.getters.getRowIndexById( itemKeyRow.id ), value: `${ context.getters.getCurrentZObjectId }K${ index + 1 }` } ); } } ); }, /** * Remove a specific row given its rowId. This method does NOT remove * the children of the given row. * It also clears whatever errors are associated to this rowId. * * @param {Object} context * @param {number} rowId */ removeRow: function ( context, rowId ) { if ( rowId === null || rowId === undefined ) { return; } const rowIndex = context.getters.getRowIndexById( rowId ); if ( rowIndex > -1 ) { context.commit( 'removeRowByIndex', rowIndex ); context.commit( 'clearErrorsForId', rowId ); } }, /** * Remove a given row and all the descending rows. It also clears * whatever errors are associated to the children rowIds. * * @param {Object} context * @param {Object} payload * @param {string} payload.rowId * @param {boolean} payload.removeParent */ removeRowChildren: function ( context, payload ) { const { rowId, removeParent = false } = payload; if ( ( rowId === undefined ) || ( rowId === null ) ) { return; } // Remove children const childRows = context.getters.getChildrenByParentRowId( rowId ); childRows.forEach( ( child ) => { context.dispatch( 'removeRowChildren', { rowId: child.id, removeParent: true } ); } ); // Remove parent if ( removeParent ) { context.dispatch( 'removeRow', rowId ); } }, /** * Set the value of a key. * The value can be a terminal value (string) or it can be an array * or an object. Depending on the kind of value passed, this method will * handle all necessary changes: * 1. Walk down the path passed as payload.keyPath and find the rowId * from which the changes should be made. * 2. If the row is `undefined`, halt execution * 3. If the value is a terminal value (string), call the setValue action * 4. If the value is more complex, call the injectZObjectFromRowId action, * which will make sure that all the current children are deleted and * the necessary rows are inserted at non-colliding ids. * * @param {Object} context * @param {Object} payload * @param {number} payload.rowId * @param {Array} payload.keyPath * @param {Object|Array|string} payload.value * @return {Promise|void} */ setValueByRowIdAndPath: function ( context, payload ) { // assume this isn't an append unless explicitly stated const append = payload.append ? payload.append : false; // 1. Find the row that will be parent for the given payload.value const row = context.getters.getRowByKeyPath( payload.keyPath, payload.rowId ); // 2. If the row is `undefined`, halt execution // 3. Is the value a string? Call atomic action setValueByRowId // 4. Is the value an object or array? Call action inject if ( row === undefined ) { return; } else if ( typeof payload.value === 'string' ) { return context.dispatch( 'setValueByRowId', { rowId: row.id, value: payload.value } ); } else { return context.dispatch( 'injectZObjectFromRowId', { rowId: row.id, value: payload.value, append } ); } }, /** * Sets the argument keys to their initial blank values of a function call given * its rowId when the function ID (Z7K1) changes, and removes the arguments of the * old function id. * Exception: When the function call is the value of a tester result validation (Z20K3) * the first argument should not be added. * * @param {Object} context * @param {Object} payload * @param {string} payload.parentId * @param {string} payload.functionZid * @return {Promise} */ setZFunctionCallArguments: function ( context, payload ) { const allActions = []; let newArgs = []; let newKeys = []; // 1. Get new argument definitions from payload.functionZid if ( payload.functionZid ) { newArgs = context.getters.getInputsOfFunctionZid( payload.functionZid ); newKeys = newArgs.map( ( arg ) => arg[ Constants.Z_ARGUMENT_KEY ] ); } // 2. Get function call arguments from parentId const oldArgs = context.getters.getZFunctionCallArguments( payload.parentId ); const oldKeys = oldArgs.map( ( arg ) => arg.key ); // 3. For every key of parent: if it's not in new keys, remove it oldArgs.forEach( ( arg ) => { if ( !newKeys.includes( arg.key ) ) { allActions.push( context.dispatch( 'removeRowChildren', { rowId: arg.id, removeParent: true } ) ); } } ); // 4. For every key of new arguments: If parent doesn't have it, set it to blank object // 4.a. If parent key is a tester validation function, omit the first argument const parentRow = context.getters.getRowById( payload.parentId ); if ( parentRow.key === Constants.Z_TESTER_VALIDATION ) { newArgs.shift(); } // 4.b. Initialize all the new function call arguments let zids = []; newArgs.forEach( ( arg ) => { if ( !oldKeys.includes( arg[ Constants.Z_ARGUMENT_KEY ] ) ) { const key = arg[ Constants.Z_ARGUMENT_KEY ]; const value = context.getters.createObjectByType( { type: arg[ Constants.Z_ARGUMENT_TYPE ] } ); // Asynchronously fetch the necessary zids. We don't need to wait // to the fetch call because these will only be needed for labels. zids = zids.concat( extractZIDs( { [ key ]: value } ) ); allActions.push( context.dispatch( 'injectKeyValueFromRowId', { rowId: payload.parentId, key, value } ) ); } } ); // 4.c. Make sure that all the newly added referenced zids are fetched zids = [ ...new Set( zids ) ]; if ( zids.length > 0 ) { context.dispatch( 'fetchZids', { zids } ); } return Promise.all( allActions ); }, /** * Sets the new implementation key and removes the previous one when changing * an implementation content from code to composition or viceversa. These keys * need to be exclusive and the content for the new key needs to be correctly * initialized with either a ZCode/Z16 object or with a ZFunctionCall/Z7. * * @param {Object} context * @param {Object} payload * @param {number} payload.parentId * @param {string} payload.key */ setZImplementationContentType: function ( context, payload ) { const allKeys = [ Constants.Z_IMPLEMENTATION_CODE, Constants.Z_IMPLEMENTATION_COMPOSITION, Constants.Z_IMPLEMENTATION_BUILT_IN ]; // Remove unchecked implementation types for ( const key of allKeys ) { if ( key !== payload.key ) { const keyRow = context.getters.getRowByKeyPath( [ key ], payload.parentId ); if ( keyRow ) { context.dispatch( 'removeRowChildren', { rowId: keyRow.id, removeParent: true } ); } } } // Get new implementation content const blankType = ( payload.key === Constants.Z_IMPLEMENTATION_CODE ) ? Constants.Z_CODE : Constants.Z_FUNCTION_CALL; const blankObject = context.getters.createObjectByType( { type: blankType } ); // Add new key-value context.dispatch( 'injectKeyValueFromRowId', { rowId: payload.parentId, key: payload.key, value: blankObject } ); }, /** * Most atomic action to edit the state. Perform the atomic mutation (index, value) * * @param {Object} context * @param {Object} payload * @param {number} payload.rowId * @param {Object|Array|string} payload.value */ setValueByRowId: function ( context, payload ) { if ( payload.rowId === undefined || payload.rowId === null ) { return; } context.commit( 'setValueByRowIndex', { index: context.getters.getRowIndexById( payload.rowId ), value: payload.value } ); }, /** * Flattens an input ZObject into a table structure and inserts the rows * into the global state. This action makes sure of a few things: * 1. If it's called with a parent row, all the current children will * be removed, and the new children will be added with non-colliding IDs. * If the parent row is a list, the flag append will permit adding the new * value into the existing list items. * 2. If it's called with no parent row, the ZObject will be inserted fully, * including a root row with parent and key set to undefined. * * @param {Object} context * @param {Object} payload * @param {number|undefined} payload.rowId parent rowId or undefined if root * @param {Object|Array|string} payload.value ZObject to inject * @param {boolean | undefined} payload.append Flag to append the new object and not remove * children * @return {Promise} */ injectZObjectFromRowId: function ( context, payload ) { const hasParent = payload.rowId !== undefined; const allActions = []; let rows; if ( hasParent ) { let parentRow = context.getters.getRowById( payload.rowId ); const nextRowId = context.getters.getNextRowId; // Convert input payload.value into table rows with parent if ( payload.append ) { // If we append to a list, calculate the index from which we need to enter the value const index = context.getters.getNextArrayIndex( payload.rowId ); rows = zobjectUtils.convertJsonToTable( payload.value, parentRow, nextRowId, true, index ); } else { rows = zobjectUtils.convertJsonToTable( payload.value, parentRow, nextRowId ); } // Reset the parent value in case it's changed parentRow = rows.shift(); allActions.push( context.dispatch( 'setValueByRowId', { rowId: parentRow.id, value: parentRow.value } ) ); // Remove all necessary children that are dangling from this parent, if append is not set if ( !payload.append ) { allActions.push( context.dispatch( 'removeRowChildren', { rowId: parentRow.id } ) ); } } else { // Convert input payload.value into table rows with no parent rows = zobjectUtils.convertJsonToTable( payload.value ); } // Push all the rows, they already have their required IDs rows.forEach( ( row ) => { allActions.push( context.commit( 'pushRow', row ) ); } ); return Promise.all( allActions ); }, /** * Given a key and a JSON object value, transforms into rows and inserts it * under the given parent ID. This method is used to add new keys into an * existing parent object, generally used for function call. * Assumes that the key doesn't exist yet in the zobject table. * * @param {Object} context * @param {Object} payload * @param {number} payload.rowId * @param {string} payload.key * @param {Object} payload.value */ injectKeyValueFromRowId: function ( context, payload ) { const value = { [ payload.key ]: payload.value }; const parentRow = context.getters.getRowById( payload.rowId ); const nextRowId = context.getters.getNextRowId; const rows = zobjectUtils.convertJsonToTable( value, parentRow, nextRowId, false, 0, false ); rows.forEach( ( row ) => { context.commit( 'pushRow', row ); } ); }, /** * Pushes a list of values into an existing list parent rowId * * @param {Object} context * @param {Object} payload * @param {number} payload.rowId list rowId * @param {Array} payload.values array of values to insert into the array */ pushValuesToList: function ( context, payload ) { const parentRow = context.getters.getRowById( payload.rowId ); // rowId is not valid if ( !parentRow || parentRow.value !== Constants.ROW_VALUE_ARRAY ) { return; } let nextRowId = context.getters.getNextRowId; for ( const value of payload.values ) { const nextIndex = context.getters.getNextArrayIndex( parentRow.id ); const rows = zobjectUtils.convertJsonToTable( value, parentRow, nextRowId, true, nextIndex ); // Discard parentRow rows.shift(); // Push all the object rows rows.forEach( ( row ) => context.commit( 'pushRow', row ) ); // Calculate nextRowId const lastRow = rows[ rows.length - 1 ]; nextRowId = lastRow.id + 1; } }, /** * Removes an item from a ZTypedList * * @param {Object} context * @param {Object} payload * @param {number} payload.rowId row ID of the item to delete */ removeItemFromTypedList: function ( context, payload ) { const row = context.getters.getRowById( payload.rowId ); if ( !row ) { return; } const parentRowId = row.parent; // remove item context.dispatch( 'removeRowChildren', { rowId: payload.rowId, removeParent: true } ); // renumber children of parent starting from key context.dispatch( 'recalculateTypedListKeys', parentRowId ); }, /** * Removes all items from a ZTypedList * This should never be called directly, but is used before submitting a zobject * in which a typed list has changed type, rendering the items invalid * * @param {Object} context * @param {Object} payload * @param {number} payload.parentRowId * @param {Array} payload.listItems */ removeItemsFromTypedList: function ( context, payload ) { for ( const itemRowId of payload.listItems ) { context.dispatch( 'removeRowChildren', { rowId: itemRowId, removeParent: true } ); } context.dispatch( 'recalculateTypedListKeys', payload.parentRowId ); }, /** * Moves an item in a typed list to the given position * * @param {Object} context * @param {Object} payload * @param {number} payload.parentRowId * @param {string} payload.key * @param {number} payload.offset */ moveItemInTypedList: function ( context, payload ) { const items = context.getters.getChildrenByParentRowId( payload.parentRowId ); const movedItem = items.find( ( row ) => row.key === payload.key ); const newKey = String( parseInt( payload.key ) + payload.offset ); const displacedItem = items.find( ( row ) => row.key === newKey ); context.commit( 'setKeyByRowIndex', { index: context.getters.getRowIndexById( movedItem.id ), key: newKey } ); context.commit( 'setKeyByRowIndex', { index: context.getters.getRowIndexById( displacedItem.id ), key: payload.key } ); } } }; |